]>
Commit | Line | Data |
---|---|---|
996ae0b0 | 1 | ------------------------------------------------------------------------------ |
82c80734 | 2 | -- -- |
996ae0b0 RK |
3 | -- GNAT COMPILER COMPONENTS -- |
4 | -- -- | |
5 | -- S E M _ C H 1 3 -- | |
6 | -- -- | |
7 | -- B o d y -- | |
8 | -- -- | |
1d005acc | 9 | -- Copyright (C) 1992-2019, Free Software Foundation, Inc. -- |
996ae0b0 RK |
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- -- | |
b5c84c3c | 13 | -- ware Foundation; either version 3, or (at your option) any later ver- -- |
996ae0b0 RK |
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 -- | |
b5c84c3c RD |
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. -- | |
996ae0b0 RK |
20 | -- -- |
21 | -- GNAT was originally developed by the GNAT team at New York University. -- | |
71ff80dc | 22 | -- Extensive contributions were provided by Ada Core Technologies Inc. -- |
996ae0b0 RK |
23 | -- -- |
24 | ------------------------------------------------------------------------------ | |
25 | ||
0f1a6a0b | 26 | with Aspects; use Aspects; |
996ae0b0 | 27 | with Atree; use Atree; |
d087cd96 | 28 | with Checks; use Checks; |
8bfbd380 | 29 | with Debug; use Debug; |
996ae0b0 | 30 | with Einfo; use Einfo; |
cefce34c | 31 | with Elists; use Elists; |
996ae0b0 | 32 | with Errout; use Errout; |
cefce34c | 33 | with Exp_Disp; use Exp_Disp; |
996ae0b0 RK |
34 | with Exp_Tss; use Exp_Tss; |
35 | with Exp_Util; use Exp_Util; | |
8b034336 | 36 | with Freeze; use Freeze; |
241ebe89 | 37 | with Ghost; use Ghost; |
996ae0b0 | 38 | with Lib; use Lib; |
2642f998 | 39 | with Lib.Xref; use Lib.Xref; |
8f7770f9 | 40 | with Namet; use Namet; |
996ae0b0 RK |
41 | with Nlists; use Nlists; |
42 | with Nmake; use Nmake; | |
43 | with Opt; use Opt; | |
62807842 | 44 | with Par_SCO; use Par_SCO; |
5f3ab6fb AC |
45 | with Restrict; use Restrict; |
46 | with Rident; use Rident; | |
996ae0b0 RK |
47 | with Rtsfind; use Rtsfind; |
48 | with Sem; use Sem; | |
a4100e55 | 49 | with Sem_Aux; use Sem_Aux; |
c76bf0bf | 50 | with Sem_Case; use Sem_Case; |
3ff38f33 | 51 | with Sem_Ch3; use Sem_Ch3; |
f2acf80c | 52 | with Sem_Ch6; use Sem_Ch6; |
57f6e00c | 53 | with Sem_Ch7; use Sem_Ch7; |
996ae0b0 | 54 | with Sem_Ch8; use Sem_Ch8; |
dec6faf1 | 55 | with Sem_Dim; use Sem_Dim; |
70805b88 | 56 | with Sem_Disp; use Sem_Disp; |
996ae0b0 | 57 | with Sem_Eval; use Sem_Eval; |
aab45d22 | 58 | with Sem_Prag; use Sem_Prag; |
996ae0b0 RK |
59 | with Sem_Res; use Sem_Res; |
60 | with Sem_Type; use Sem_Type; | |
61 | with Sem_Util; use Sem_Util; | |
affbee12 | 62 | with Sem_Warn; use Sem_Warn; |
ca0eb951 | 63 | with Sinfo; use Sinfo; |
c775c209 | 64 | with Sinput; use Sinput; |
fbf5a39b | 65 | with Snames; use Snames; |
996ae0b0 | 66 | with Stand; use Stand; |
9f4fd324 | 67 | with Targparm; use Targparm; |
996ae0b0 RK |
68 | with Ttypes; use Ttypes; |
69 | with Tbuild; use Tbuild; | |
70 | with Urealp; use Urealp; | |
499769ec | 71 | with Warnsw; use Warnsw; |
996ae0b0 | 72 | |
d4731b80 | 73 | with GNAT.Heap_Sort_G; |
996ae0b0 RK |
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 | ||
52b70b1b | 84 | procedure Adjust_Record_For_Reverse_Bit_Order_Ada_95 (R : Entity_Id); |
0f83b044 | 85 | -- Helper routine providing the original (pre-AI95-0133) behavior for |
52b70b1b TQ |
86 | -- Adjust_Record_For_Reverse_Bit_Order. |
87 | ||
76af4137 AC |
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. | |
996ae0b0 | 93 | |
baa571ab | 94 | procedure Build_Discrete_Static_Predicate |
1e194575 AC |
95 | (Typ : Entity_Id; |
96 | Expr : Node_Id; | |
97 | Nam : Name_Id); | |
f6b5dc8e AC |
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 | |
308e6f3a | 102 | -- predicate expression have been replaced by identifier references to this |
f6b5dc8e AC |
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 | |
60f908dd RD |
106 | -- list is stored in Static_Discrete_Predicate (Typ), and the Expr is |
107 | -- rewritten as a canonicalized membership operation. | |
1e194575 | 108 | |
2e885a6f AC |
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 | ||
6905a049 AC |
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 | |
812e6118 | 121 | -- preanalyzed at this point, to catch visibility errors. |
6905a049 | 122 | |
baa571ab AC |
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. | |
6905a049 AC |
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. | |
baa571ab | 134 | |
113a62d9 RD |
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 | ||
5a8a6763 RD |
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 | |
e1e307d9 | 144 | -- we have to be sure the subtypes in question are frozen before checking). |
5a8a6763 | 145 | |
996ae0b0 RK |
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; | |
c775c209 AC |
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. | |
996ae0b0 | 156 | |
ee4eee0a AC |
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 | ||
affbee12 | 185 | procedure New_Stream_Subprogram |
996ae0b0 RK |
186 | (N : Node_Id; |
187 | Ent : Entity_Id; | |
188 | Subp : Entity_Id; | |
fbf5a39b | 189 | Nam : TSS_Name_Type); |
affbee12 RD |
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 | |
1fb63e89 | 192 | -- primitive operation, or in the untagged case make an appropriate TSS |
affbee12 | 193 | -- entry. This is more properly an expansion activity than just semantics, |
1fb63e89 RD |
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 | |
affbee12 RD |
196 | -- exp_ch13, where it was previously. Nam indicates the name of the TSS |
197 | -- function to be generated. | |
fbf5a39b | 198 | -- |
07fc65c4 GB |
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 | ||
5067f3a0 PMR |
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 | ||
b4f149c2 AC |
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 | ||
a3f2babd AC |
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 | ||
5f531fef ES |
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 | ||
996ae0b0 RK |
249 | ---------------------------------------------- |
250 | -- Table for Validate_Unchecked_Conversions -- | |
251 | ---------------------------------------------- | |
252 | ||
253 | -- The following table collects unchecked conversions for validation. | |
a1092b48 AC |
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. | |
996ae0b0 | 259 | |
a1092b48 AC |
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. | |
f66d46ec | 263 | |
996ae0b0 | 264 | type UC_Entry is record |
4c51ff88 AC |
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 | |
996ae0b0 RK |
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 | ||
2642f998 RD |
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 | ||
f26a3587 AC |
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 | |
a1092b48 AC |
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. | |
2642f998 RD |
295 | |
296 | type Address_Clause_Check_Record is record | |
297 | N : Node_Id; | |
298 | -- The address clause | |
299 | ||
300 | X : Entity_Id; | |
f26a3587 AC |
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 | |
2642f998 RD |
305 | |
306 | Y : Entity_Id; | |
f26a3587 | 307 | -- The entity of the object being overlaid in the second case |
f4cd2542 EB |
308 | |
309 | Off : Boolean; | |
f26a3587 | 310 | -- Whether the address is offset within Y in the second case |
5067f3a0 PMR |
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. | |
2642f998 RD |
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 | ||
5067f3a0 PMR |
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 | ||
a9a5b8ac RD |
346 | ----------------------------------------- |
347 | -- Adjust_Record_For_Reverse_Bit_Order -- | |
348 | ----------------------------------------- | |
349 | ||
350 | procedure Adjust_Record_For_Reverse_Bit_Order (R : Entity_Id) is | |
52b70b1b TQ |
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 | |
a9a5b8ac | 355 | |
d43584ca AC |
356 | SSU : constant Uint := UI_From_Int (System_Storage_Unit); |
357 | ||
358 | CC : Node_Id; | |
359 | Comp : Node_Id; | |
52b70b1b | 360 | Num_CC : Natural; |
498d1b80 | 361 | |
52b70b1b | 362 | begin |
0f83b044 | 363 | -- Processing here used to depend on Ada version: the behavior was |
52b70b1b | 364 | -- changed by AI95-0133. However this AI is a Binding interpretation, |
0f83b044 | 365 | -- so we now implement it even in Ada 95 mode. The original behavior |
52b70b1b TQ |
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. | |
498d1b80 | 378 | |
d43584ca AC |
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. | |
498d1b80 | 385 | |
52b70b1b TQ |
386 | Num_CC := 0; |
387 | Comp := First_Component_Or_Discriminant (R); | |
388 | while Present (Comp) loop | |
389 | CC := Component_Clause (Comp); | |
498d1b80 | 390 | |
52b70b1b TQ |
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)); | |
498d1b80 | 395 | |
52b70b1b TQ |
396 | begin |
397 | -- Case of component with last bit >= max machine scalar | |
498d1b80 | 398 | |
52b70b1b | 399 | if Lbit >= Max_Machine_Scalar_Size then |
a9a5b8ac | 400 | |
d43584ca AC |
401 | -- This is allowed only if first bit is zero, and last bit |
402 | -- + 1 is a multiple of storage unit size. | |
a9a5b8ac | 403 | |
52b70b1b | 404 | if Fbit = 0 and then (Lbit + 1) mod SSU = 0 then |
a9a5b8ac | 405 | |
52b70b1b | 406 | -- This is the case to give a warning if enabled |
a9a5b8ac | 407 | |
52b70b1b | 408 | if Warn_On_Reverse_Bit_Order then |
498d1b80 | 409 | Error_Msg_N |
ee10c0ec | 410 | ("info: multi-byte field specified with " |
52b70b1b | 411 | & "non-standard Bit_Order?V?", CC); |
5e5dc75a | 412 | |
498d1b80 | 413 | if Bytes_Big_Endian then |
5e5dc75a | 414 | Error_Msg_N |
ee10c0ec | 415 | ("\bytes are not reversed " |
52b70b1b | 416 | & "(component is big-endian)?V?", CC); |
5e5dc75a RD |
417 | else |
418 | Error_Msg_N | |
ee10c0ec | 419 | ("\bytes are not reversed " |
52b70b1b | 420 | & "(component is little-endian)?V?", CC); |
5e5dc75a | 421 | end if; |
52b70b1b | 422 | end if; |
a9a5b8ac | 423 | |
52b70b1b TQ |
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 | |
d43584ca AC |
434 | ("\last bit + 1 (^) exceeds maximum machine scalar " |
435 | & "size (^)", First_Bit (CC)); | |
52b70b1b TQ |
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 (^) " | |
d43584ca | 441 | & "(RM 13.5.1(10))", First_Bit (CC)); |
a9a5b8ac | 442 | |
8a95f4e8 | 443 | else |
52b70b1b TQ |
444 | Error_Msg_Uint_1 := Fbit; |
445 | Error_Msg_F | |
446 | ("\and first bit (^) is non-zero " | |
d43584ca | 447 | & "(RM 13.4.1(10))", First_Bit (CC)); |
498d1b80 | 448 | end if; |
52b70b1b | 449 | end if; |
a9a5b8ac | 450 | |
d43584ca AC |
451 | -- OK case of machine scalar related component clause. For now, |
452 | -- just count them. | |
a9a5b8ac | 453 | |
52b70b1b TQ |
454 | else |
455 | Num_CC := Num_CC + 1; | |
456 | end if; | |
457 | end; | |
458 | end if; | |
a9a5b8ac | 459 | |
52b70b1b TQ |
460 | Next_Component_Or_Discriminant (Comp); |
461 | end loop; | |
a9a5b8ac | 462 | |
d43584ca AC |
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. | |
d4731b80 | 466 | |
52b70b1b TQ |
467 | Sort_CC : declare |
468 | Comps : array (0 .. Num_CC) of Entity_Id; | |
d43584ca AC |
469 | -- Array to collect component and discriminant entities. The data |
470 | -- starts at index 1, the 0'th entry is for the sort routine. | |
a9a5b8ac | 471 | |
52b70b1b TQ |
472 | function CP_Lt (Op1, Op2 : Natural) return Boolean; |
473 | -- Compare routine for Sort | |
a9a5b8ac | 474 | |
52b70b1b TQ |
475 | procedure CP_Move (From : Natural; To : Natural); |
476 | -- Move routine for Sort | |
a9a5b8ac | 477 | |
52b70b1b | 478 | package Sorting is new GNAT.Heap_Sort_G (CP_Move, CP_Lt); |
a9a5b8ac | 479 | |
d43584ca AC |
480 | MaxL : Uint; |
481 | -- Maximum last bit value of any component in this set | |
482 | ||
483 | MSS : Uint; | |
484 | -- Corresponding machine scalar size | |
485 | ||
52b70b1b TQ |
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). | |
a9a5b8ac | 491 | |
52b70b1b TQ |
492 | ----------- |
493 | -- CP_Lt -- | |
494 | ----------- | |
498d1b80 | 495 | |
52b70b1b TQ |
496 | function CP_Lt (Op1, Op2 : Natural) return Boolean is |
497 | begin | |
d43584ca AC |
498 | return |
499 | Position (Component_Clause (Comps (Op1))) < | |
52b70b1b TQ |
500 | Position (Component_Clause (Comps (Op2))); |
501 | end CP_Lt; | |
a9a5b8ac | 502 | |
52b70b1b TQ |
503 | ------------- |
504 | -- CP_Move -- | |
505 | ------------- | |
a9a5b8ac | 506 | |
52b70b1b | 507 | procedure CP_Move (From : Natural; To : Natural) is |
498d1b80 | 508 | begin |
52b70b1b TQ |
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 | |
8a95f4e8 | 516 | |
52b70b1b TQ |
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); | |
8a95f4e8 | 522 | |
52b70b1b | 523 | begin |
d43584ca AC |
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. | |
52b70b1b TQ |
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; | |
8a95f4e8 | 540 | |
52b70b1b TQ |
541 | Next_Component_Or_Discriminant (Comp); |
542 | end loop; | |
8a95f4e8 | 543 | |
52b70b1b TQ |
544 | -- Sort by ascending position number |
545 | ||
546 | Sorting.Sort (Num_CC); | |
547 | ||
d43584ca AC |
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. | |
52b70b1b TQ |
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; | |
8a95f4e8 | 577 | |
d43584ca AC |
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. | |
52b70b1b | 581 | |
d43584ca AC |
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. | |
52b70b1b TQ |
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; | |
8a95f4e8 | 594 | |
d43584ca AC |
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: | |
8a95f4e8 | 598 | |
52b70b1b TQ |
599 | -- First_Bit .. Last_Bit Component_Bit_Offset |
600 | -- old new old new | |
8a95f4e8 | 601 | |
52b70b1b TQ |
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 | |
038140ed | 606 | |
52b70b1b TQ |
607 | -- 1 .. 1 6 .. 6 1 6 |
608 | -- 1 .. 4 3 .. 6 1 3 | |
609 | -- 4 .. 7 0 .. 3 4 0 | |
8a95f4e8 | 610 | |
d43584ca AC |
611 | -- The rule is that the first bit is obtained by subtracting the |
612 | -- old ending bit from machine scalar size - 1. | |
8a95f4e8 | 613 | |
52b70b1b TQ |
614 | for C in Start .. Stop loop |
615 | declare | |
616 | Comp : constant Entity_Id := Comps (C); | |
617 | CC : constant Node_Id := Component_Clause (Comp); | |
a9a5b8ac | 618 | |
52b70b1b TQ |
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)); | |
a9a5b8ac | 623 | |
52b70b1b TQ |
624 | begin |
625 | if Warn_On_Reverse_Bit_Order then | |
626 | Error_Msg_Uint_1 := MSS; | |
627 | Error_Msg_N | |
d43584ca AC |
628 | ("info: reverse bit order in machine scalar of " |
629 | & "length^?V?", First_Bit (CC)); | |
52b70b1b TQ |
630 | Error_Msg_Uint_1 := NFB; |
631 | Error_Msg_Uint_2 := NLB; | |
632 | ||
633 | if Bytes_Big_Endian then | |
634 | Error_Msg_NE | |
d43584ca AC |
635 | ("\big-endian range for component & is ^ .. ^?V?", |
636 | First_Bit (CC), Comp); | |
498d1b80 | 637 | else |
52b70b1b | 638 | Error_Msg_NE |
d43584ca AC |
639 | ("\little-endian range for component & is ^ .. ^?V?", |
640 | First_Bit (CC), Comp); | |
498d1b80 | 641 | end if; |
52b70b1b | 642 | end if; |
a9a5b8ac | 643 | |
52b70b1b | 644 | Set_Component_Bit_Offset (Comp, Pos * SSU + NFB); |
74a78a4f | 645 | Set_Normalized_Position (Comp, Pos + NFB / SSU); |
52b70b1b TQ |
646 | Set_Normalized_First_Bit (Comp, NFB mod SSU); |
647 | end; | |
498d1b80 | 648 | end loop; |
52b70b1b TQ |
649 | end loop; |
650 | end Sort_CC; | |
651 | end Adjust_Record_For_Reverse_Bit_Order; | |
a9a5b8ac | 652 | |
52b70b1b TQ |
653 | ------------------------------------------------ |
654 | -- Adjust_Record_For_Reverse_Bit_Order_Ada_95 -- | |
655 | ------------------------------------------------ | |
a9a5b8ac | 656 | |
52b70b1b | 657 | procedure Adjust_Record_For_Reverse_Bit_Order_Ada_95 (R : Entity_Id) is |
52b70b1b | 658 | CC : Node_Id; |
d43584ca | 659 | Comp : Node_Id; |
a9a5b8ac | 660 | |
52b70b1b TQ |
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. | |
a9a5b8ac | 665 | |
52b70b1b TQ |
666 | Comp := First_Component_Or_Discriminant (R); |
667 | while Present (Comp) loop | |
668 | CC := Component_Clause (Comp); | |
a9a5b8ac | 669 | |
52b70b1b TQ |
670 | -- If component clause is present, then deal with the non-default |
671 | -- bit order case for Ada 95 mode. | |
a9a5b8ac | 672 | |
52b70b1b TQ |
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. | |
a9a5b8ac | 676 | |
52b70b1b TQ |
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); | |
a9a5b8ac | 684 | |
52b70b1b TQ |
685 | Storage_Unit_Offset : constant Uint := |
686 | CFB / System_Storage_Unit; | |
8a95f4e8 | 687 | |
52b70b1b TQ |
688 | Start_Bit : constant Uint := |
689 | CFB mod System_Storage_Unit; | |
8a95f4e8 | 690 | |
52b70b1b TQ |
691 | begin |
692 | -- Cases where field goes over storage unit boundary | |
8a95f4e8 | 693 | |
52b70b1b | 694 | if Start_Bit + CSZ > System_Storage_Unit then |
8a95f4e8 | 695 | |
52b70b1b | 696 | -- Allow multi-byte field but generate warning |
8a95f4e8 | 697 | |
52b70b1b TQ |
698 | if Start_Bit mod System_Storage_Unit = 0 |
699 | and then CSZ mod System_Storage_Unit = 0 | |
700 | then | |
701 | Error_Msg_N | |
d43584ca AC |
702 | ("info: multi-byte field specified with non-standard " |
703 | & "Bit_Order?V?", CLC); | |
a9a5b8ac | 704 | |
52b70b1b TQ |
705 | if Bytes_Big_Endian then |
706 | Error_Msg_N | |
707 | ("\bytes are not reversed " | |
708 | & "(component is big-endian)?V?", CLC); | |
498d1b80 | 709 | else |
52b70b1b TQ |
710 | Error_Msg_N |
711 | ("\bytes are not reversed " | |
712 | & "(component is little-endian)?V?", CLC); | |
498d1b80 | 713 | end if; |
8a95f4e8 | 714 | |
52b70b1b | 715 | -- Do not allow non-contiguous field |
498d1b80 | 716 | |
52b70b1b TQ |
717 | else |
718 | Error_Msg_N | |
d43584ca AC |
719 | ("attempt to specify non-contiguous field not " |
720 | & "permitted", CLC); | |
52b70b1b | 721 | Error_Msg_N |
d43584ca AC |
722 | ("\caused by non-standard Bit_Order specified in " |
723 | & "legacy Ada 95 mode", CLC); | |
52b70b1b | 724 | end if; |
498d1b80 | 725 | |
52b70b1b TQ |
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 | |
d43584ca AC |
735 | ("info: Bit_Order clause does not affect byte " |
736 | & "ordering?V?", Pos); | |
52b70b1b TQ |
737 | Error_Msg_Uint_1 := |
738 | Intval (Pos) + Intval (FB) / | |
739 | System_Storage_Unit; | |
740 | Error_Msg_N | |
d43584ca AC |
741 | ("info: position normalized to ^ before bit order " |
742 | & "interpreted?V?", Pos); | |
52b70b1b | 743 | end if; |
8a95f4e8 | 744 | |
498d1b80 AC |
745 | -- Here is where we fix up the Component_Bit_Offset value |
746 | -- to account for the reverse bit order. Some examples of | |
52b70b1b | 747 | -- what needs to be done are: |
8a95f4e8 | 748 | |
498d1b80 AC |
749 | -- First_Bit .. Last_Bit Component_Bit_Offset |
750 | -- old new old new | |
8a95f4e8 | 751 | |
498d1b80 AC |
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 | |
8a95f4e8 | 756 | |
498d1b80 AC |
757 | -- 1 .. 1 6 .. 6 1 6 |
758 | -- 1 .. 4 3 .. 6 1 3 | |
759 | -- 4 .. 7 0 .. 3 4 0 | |
8a95f4e8 | 760 | |
52b70b1b TQ |
761 | -- The rule is that the first bit is is obtained by |
762 | -- subtracting the old ending bit from storage_unit - 1. | |
8a95f4e8 | 763 | |
d43584ca AC |
764 | Set_Component_Bit_Offset (Comp, |
765 | (Storage_Unit_Offset * System_Storage_Unit) + | |
766 | (System_Storage_Unit - 1) - | |
767 | (Start_Bit + CSZ - 1)); | |
616547fa | 768 | |
74a78a4f AC |
769 | Set_Normalized_Position (Comp, |
770 | Component_Bit_Offset (Comp) / System_Storage_Unit); | |
771 | ||
d43584ca AC |
772 | Set_Normalized_First_Bit (Comp, |
773 | Component_Bit_Offset (Comp) mod System_Storage_Unit); | |
52b70b1b TQ |
774 | end if; |
775 | end; | |
776 | end if; | |
8a95f4e8 | 777 | |
52b70b1b TQ |
778 | Next_Component_Or_Discriminant (Comp); |
779 | end loop; | |
780 | end Adjust_Record_For_Reverse_Bit_Order_Ada_95; | |
a9a5b8ac | 781 | |
76af4137 AC |
782 | ------------------------------------- |
783 | -- Alignment_Check_For_Size_Change -- | |
784 | ------------------------------------- | |
996ae0b0 | 785 | |
76af4137 | 786 | procedure Alignment_Check_For_Size_Change (Typ : Entity_Id; Size : Uint) is |
996ae0b0 RK |
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) | |
76af4137 | 795 | and then Size mod (Alignment (Typ) * SSU) /= 0 |
996ae0b0 RK |
796 | then |
797 | Init_Alignment (Typ); | |
798 | end if; | |
76af4137 | 799 | end Alignment_Check_For_Size_Change; |
996ae0b0 | 800 | |
8a0320ad AC |
801 | ------------------------------------- |
802 | -- Analyze_Aspects_At_Freeze_Point -- | |
803 | ------------------------------------- | |
804 | ||
805 | procedure Analyze_Aspects_At_Freeze_Point (E : Entity_Id) is | |
8a0320ad AC |
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 | ||
15e934bf AC |
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 | |
860917b6 | 829 | -- of all delayed aspects from the parent type. The derived type is E, |
15e934bf AC |
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 | ||
8a0320ad AC |
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 | |
2e885a6f | 843 | A_Id : constant Aspect_Id := Get_Aspect_Id (ASN); |
8a0320ad AC |
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 | |
7b55fea6 | 879 | Set_Default_Aspect_Value (Base_Type (Ent), Expr); |
8a0320ad | 880 | else |
688a9b51 | 881 | Set_Default_Aspect_Component_Value (Base_Type (Ent), Expr); |
8a0320ad AC |
882 | end if; |
883 | end Analyze_Aspect_Default_Value; | |
884 | ||
15e934bf AC |
885 | --------------------------------- |
886 | -- Inherit_Delayed_Rep_Aspects -- | |
887 | --------------------------------- | |
888 | ||
889 | procedure Inherit_Delayed_Rep_Aspects (ASN : Node_Id) is | |
2e885a6f AC |
890 | A_Id : constant Aspect_Id := Get_Aspect_Id (ASN); |
891 | P : constant Entity_Id := Entity (ASN); | |
15e934bf AC |
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 | ||
d8f43ee6 HK |
972 | when Aspect_Object_Size |
973 | | Aspect_Size | |
974 | => | |
15e934bf AC |
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)); | |
8ca597af RD |
991 | Set_Packed_Array_Impl_Type |
992 | (E, Packed_Array_Impl_Type (P)); | |
15e934bf AC |
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 | |
c1645ac8 | 1001 | (E, Attribute_Scalar_Storage_Order)) |
15e934bf AC |
1002 | and then Reverse_Storage_Order (P) |
1003 | then | |
1004 | Set_Reverse_Storage_Order (Base_Type (E)); | |
220d1fd9 AC |
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); | |
15e934bf AC |
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 | ||
f280dd8f RD |
1049 | -- Volatile_Full_Access |
1050 | ||
1051 | when Aspect_Volatile_Full_Access => | |
57abdadd EB |
1052 | if Is_Volatile_Full_Access (P) then |
1053 | Set_Is_Volatile_Full_Access (E); | |
f280dd8f RD |
1054 | end if; |
1055 | ||
15e934bf AC |
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; | |
15e934bf AC |
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 | ||
8a0320ad AC |
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 | ||
8a0320ad AC |
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 | |
d8f43ee6 HK |
1110 | when Aspect_Atomic |
1111 | | Aspect_Shared | |
1112 | => | |
8a0320ad AC |
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 | ||
f280dd8f | 1147 | when Aspect_Volatile_Full_Access => |
57abdadd | 1148 | if not Is_Volatile_Full_Access (Par) then |
f280dd8f RD |
1149 | return; |
1150 | end if; | |
1151 | ||
8a0320ad AC |
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; | |
15e934bf AC |
1159 | Error_Msg_NE |
1160 | ("derived type& inherits aspect%, cannot cancel", Expr, E); | |
8a0320ad AC |
1161 | end Check_False_Aspect_For_Derived_Type; |
1162 | ||
2e885a6f AC |
1163 | -- Local variables |
1164 | ||
1165 | Prag : Node_Id; | |
1166 | ||
8a0320ad AC |
1167 | -- Start of processing for Make_Pragma_From_Boolean_Aspect |
1168 | ||
1169 | begin | |
15e934bf AC |
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 | ||
8a0320ad AC |
1174 | if Is_False (Static_Boolean (Expr)) then |
1175 | Check_False_Aspect_For_Derived_Type; | |
1176 | ||
1177 | else | |
1178 | Prag := | |
1179 | Make_Pragma (Loc, | |
2e885a6f AC |
1180 | Pragma_Identifier => |
1181 | Make_Identifier (Sloc (Ident), Chars (Ident)), | |
8a0320ad | 1182 | Pragma_Argument_Associations => New_List ( |
3860d469 | 1183 | Make_Pragma_Argument_Association (Sloc (Ident), |
2e885a6f | 1184 | Expression => New_Occurrence_Of (Ent, Sloc (Ident))))); |
8a0320ad AC |
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; | |
8a0320ad AC |
1192 | end Make_Pragma_From_Boolean_Aspect; |
1193 | ||
2e885a6f AC |
1194 | -- Local variables |
1195 | ||
1196 | A_Id : Aspect_Id; | |
1197 | ASN : Node_Id; | |
1198 | Ritem : Node_Id; | |
1199 | ||
8a0320ad AC |
1200 | -- Start of processing for Analyze_Aspects_At_Freeze_Point |
1201 | ||
1202 | begin | |
0f168ccc AC |
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. | |
8a0320ad | 1208 | |
5eeeed5e | 1209 | if not Scope_Within_Or_Same (Current_Scope, Scope (E)) then |
e1691d7e | 1210 | if Is_Type (E) and then From_Nested_Package (E) then |
57f6e00c AC |
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); | |
e1691d7e | 1227 | return; |
57f6e00c AC |
1228 | end; |
1229 | ||
0f168ccc AC |
1230 | -- Aspects from other entities in different contexts are analyzed |
1231 | -- elsewhere. | |
57f6e00c | 1232 | |
0f168ccc | 1233 | else |
57f6e00c AC |
1234 | return; |
1235 | end if; | |
8a0320ad AC |
1236 | end if; |
1237 | ||
1238 | -- Look for aspect specification entries for this entity | |
1239 | ||
1240 | ASN := First_Rep_Item (E); | |
8a0320ad | 1241 | while Present (ASN) loop |
15e934bf AC |
1242 | if Nkind (ASN) = N_Aspect_Specification then |
1243 | exit when Entity (ASN) /= E; | |
8a0320ad | 1244 | |
15e934bf AC |
1245 | if Is_Delayed_Aspect (ASN) then |
1246 | A_Id := Get_Aspect_Id (ASN); | |
1247 | ||
1248 | case A_Id is | |
21791d97 | 1249 | |
15e934bf | 1250 | -- For aspects whose expression is an optional Boolean, make |
3e1862b1 | 1251 | -- the corresponding pragma at the freeze point. |
8a0320ad | 1252 | |
d8f43ee6 HK |
1253 | when Boolean_Aspects |
1254 | | Library_Unit_Aspects | |
1255 | => | |
2e885a6f AC |
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; | |
8a0320ad | 1274 | |
15e934bf AC |
1275 | -- Special handling for aspects that don't correspond to |
1276 | -- pragmas/attributes. | |
8a0320ad | 1277 | |
d8f43ee6 HK |
1278 | when Aspect_Default_Value |
1279 | | Aspect_Default_Component_Value | |
1280 | => | |
731261c3 AC |
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; | |
8a0320ad | 1294 | |
15e934bf AC |
1295 | -- Ditto for iterator aspects, because the corresponding |
1296 | -- attributes may not have been analyzed yet. | |
7640ef8a | 1297 | |
d8f43ee6 HK |
1298 | when Aspect_Constant_Indexing |
1299 | | Aspect_Default_Iterator | |
1300 | | Aspect_Iterator_Element | |
1301 | | Aspect_Variable_Indexing | |
1302 | => | |
3e1862b1 | 1303 | Analyze (Expression (ASN)); |
7640ef8a | 1304 | |
3e1862b1 ES |
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; | |
dd2bf554 | 1310 | |
3e1862b1 ES |
1311 | when Aspect_Iterable => |
1312 | Validate_Iterable_Aspect (E, ASN); | |
1313 | ||
1314 | when others => | |
1315 | null; | |
15e934bf | 1316 | end case; |
8a0320ad | 1317 | |
15e934bf | 1318 | Ritem := Aspect_Rep_Item (ASN); |
8a0320ad | 1319 | |
15e934bf AC |
1320 | if Present (Ritem) then |
1321 | Analyze (Ritem); | |
1322 | end if; | |
8a0320ad AC |
1323 | end if; |
1324 | end if; | |
1325 | ||
1326 | Next_Rep_Item (ASN); | |
1327 | end loop; | |
15e934bf AC |
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; | |
5f531fef ES |
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; | |
8a0320ad AC |
1344 | end Analyze_Aspects_At_Freeze_Point; |
1345 | ||
0f1a6a0b AC |
1346 | ----------------------------------- |
1347 | -- Analyze_Aspect_Specifications -- | |
1348 | ----------------------------------- | |
1349 | ||
eaba57fb | 1350 | procedure Analyze_Aspect_Specifications (N : Node_Id; E : Entity_Id) is |
5612989e PMR |
1351 | pragma Assert (Present (E)); |
1352 | ||
4e6768ab | 1353 | procedure Decorate (Asp : Node_Id; Prag : Node_Id); |
c8593453 | 1354 | -- Establish linkages between an aspect and its corresponding pragma |
5afe5d2d | 1355 | |
21d7ef70 AC |
1356 | procedure Insert_Pragma |
1357 | (Prag : Node_Id; | |
1358 | Is_Instance : Boolean := False); | |
877a5a12 AC |
1359 | -- Subsidiary to the analysis of aspects |
1360 | -- Abstract_State | |
877a5a12 AC |
1361 | -- Attach_Handler |
1362 | -- Contract_Cases | |
1363 | -- Depends | |
21d7ef70 | 1364 | -- Ghost |
877a5a12 | 1365 | -- Global |
21d7ef70 AC |
1366 | -- Initial_Condition |
1367 | -- Initializes | |
877a5a12 AC |
1368 | -- Post |
1369 | -- Pre | |
1370 | -- Refined_Depends | |
1371 | -- Refined_Global | |
21d7ef70 | 1372 | -- Refined_State |
877a5a12 AC |
1373 | -- SPARK_Mode |
1374 | -- Warnings | |
4e6768ab | 1375 | -- Insert pragma Prag such that it mimics the placement of a source |
21d7ef70 AC |
1376 | -- pragma of the same kind. Flag Is_Generic should be set when the |
1377 | -- context denotes a generic instance. | |
4e6768ab AC |
1378 | |
1379 | -------------- | |
1380 | -- Decorate -- | |
1381 | -------------- | |
1382 | ||
1383 | procedure Decorate (Asp : Node_Id; Prag : Node_Id) is | |
5afe5d2d | 1384 | begin |
c8593453 | 1385 | Set_Aspect_Rep_Item (Asp, Prag); |
5afe5d2d HK |
1386 | Set_Corresponding_Aspect (Prag, Asp); |
1387 | Set_From_Aspect_Specification (Prag); | |
5afe5d2d | 1388 | Set_Parent (Prag, Asp); |
4e6768ab | 1389 | end Decorate; |
dba44dbe | 1390 | |
4e6768ab AC |
1391 | ------------------- |
1392 | -- Insert_Pragma -- | |
1393 | ------------------- | |
d6095153 | 1394 | |
21d7ef70 AC |
1395 | procedure Insert_Pragma |
1396 | (Prag : Node_Id; | |
1397 | Is_Instance : Boolean := False) | |
1398 | is | |
8a0183fd HK |
1399 | Aux : Node_Id; |
1400 | Decl : Node_Id; | |
1401 | Decls : List_Id; | |
1402 | Def : Node_Id; | |
1403 | Inserted : Boolean := False; | |
d6095153 AC |
1404 | |
1405 | begin | |
8a0183fd HK |
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. | |
877a5a12 AC |
1410 | |
1411 | -- package body Pack with Aspect is | |
1412 | ||
1413 | -- package body Pack is | |
1414 | -- pragma Prag; | |
1415 | ||
8a0183fd HK |
1416 | if Nkind_In (N, N_Entry_Body, |
1417 | N_Package_Body, | |
877a5a12 AC |
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; | |
4e6768ab | 1428 | |
8a0183fd | 1429 | Prepend_To (Decls, Prag); |
877a5a12 AC |
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 | ||
21d7ef70 AC |
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 | |
8a0183fd HK |
1458 | -- skipping the instance "header" to ensure proper visibility of |
1459 | -- all formals. | |
21d7ef70 AC |
1460 | |
1461 | if Is_Instance then | |
1462 | Decl := First (Decls); | |
8a0183fd HK |
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; | |
21d7ef70 AC |
1471 | end loop; |
1472 | ||
8a0183fd | 1473 | -- The pragma is placed after the instance "header" |
21d7ef70 | 1474 | |
8a0183fd | 1475 | if not Inserted then |
21d7ef70 AC |
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; | |
877a5a12 AC |
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 | |
75b87c16 AC |
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); | |
877a5a12 AC |
1507 | |
1508 | if No (Decls) then | |
1509 | Decls := New_List; | |
75b87c16 | 1510 | Set_Visible_Declarations (Def, Decls); |
877a5a12 AC |
1511 | end if; |
1512 | ||
1513 | Prepend_To (Decls, Prag); | |
1514 | ||
75b87c16 AC |
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. | |
877a5a12 AC |
1518 | |
1519 | -- task [type] Prot with Aspect is | |
1520 | ||
1521 | -- task [type] Prot is | |
1522 | -- pragma Prag; | |
1523 | ||
75b87c16 AC |
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); | |
877a5a12 AC |
1537 | |
1538 | if No (Decls) then | |
1539 | Decls := New_List; | |
75b87c16 | 1540 | Set_Visible_Declarations (Def, Decls); |
2fc07285 | 1541 | end if; |
d6095153 | 1542 | |
877a5a12 AC |
1543 | Prepend_To (Decls, Prag); |
1544 | ||
c9d70ab1 AC |
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 | ||
877a5a12 | 1557 | -- Default, the pragma is inserted after the context |
d6095153 AC |
1558 | |
1559 | else | |
1560 | Insert_After (N, Prag); | |
d6095153 | 1561 | end if; |
4e6768ab | 1562 | end Insert_Pragma; |
d6095153 AC |
1563 | |
1564 | -- Local variables | |
1565 | ||
0f1a6a0b | 1566 | Aspect : Node_Id; |
c159409f | 1567 | Aitem : Node_Id; |
0f1a6a0b | 1568 | Ent : Node_Id; |
0f1a6a0b | 1569 | |
eaba57fb | 1570 | L : constant List_Id := Aspect_Specifications (N); |
5612989e | 1571 | pragma Assert (Present (L)); |
eaba57fb | 1572 | |
0f1a6a0b | 1573 | Ins_Node : Node_Id := N; |
b98e2969 AC |
1574 | -- Insert pragmas/attribute definition clause after this node when no |
1575 | -- delayed analysis is required. | |
c159409f | 1576 | |
2e885a6f | 1577 | -- Start of processing for Analyze_Aspect_Specifications |
dba44dbe | 1578 | |
2e885a6f | 1579 | begin |
c159409f | 1580 | -- The general processing involves building an attribute definition |
b98e2969 AC |
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 | ||
aab45d22 | 1593 | -- Note that there is a special handling for Pre, Post, Test_Case, |
541fb4d9 | 1594 | -- Contract_Cases aspects. In these cases, we do not have to worry |
aab45d22 AC |
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. | |
0f1a6a0b | 1598 | |
308e6f3a | 1599 | -- Loop through aspects |
2d4e0553 | 1600 | |
0f1a6a0b | 1601 | Aspect := First (L); |
eaba57fb | 1602 | Aspect_Loop : while Present (Aspect) loop |
9d5598bf | 1603 | Analyze_One_Aspect : declare |
811ef5ba | 1604 | Expr : constant Node_Id := Expression (Aspect); |
b98e2969 AC |
1605 | Id : constant Node_Id := Identifier (Aspect); |
1606 | Loc : constant Source_Ptr := Sloc (Aspect); | |
811ef5ba RD |
1607 | Nam : constant Name_Id := Chars (Id); |
1608 | A_Id : constant Aspect_Id := Get_Aspect_Id (Nam); | |
0f1a6a0b AC |
1609 | Anod : Node_Id; |
1610 | ||
15e934bf | 1611 | Delay_Required : Boolean; |
b98e2969 AC |
1612 | -- Set False if delay is not required |
1613 | ||
95160516 AC |
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. | |
beacce02 | 1617 | |
2e885a6f AC |
1618 | procedure Analyze_Aspect_Convention; |
1619 | -- Perform analysis of aspect Convention | |
1620 | ||
0cb81445 PMR |
1621 | procedure Analyze_Aspect_Disable_Controlled; |
1622 | -- Perform analysis of aspect Disable_Controlled | |
1623 | ||
2e885a6f AC |
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 | |
eaba57fb | 1629 | |
b98e2969 | 1630 | procedure Analyze_Aspect_Implicit_Dereference; |
3b1d4d82 | 1631 | -- Perform analysis of the Implicit_Dereference aspects |
9d5598bf AC |
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. | |
eaba57fb | 1644 | |
2e885a6f AC |
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; | |
b98e2969 | 1656 | |
eaba57fb | 1657 | begin |
2e885a6f AC |
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; | |
eaba57fb | 1676 | |
2e885a6f | 1677 | -- Otherwise Convention appears by itself |
eaba57fb | 1678 | |
2e885a6f AC |
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 | ||
0cb81445 PMR |
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 | ||
2e885a6f AC |
1761 | ---------------------------------- |
1762 | -- Analyze_Aspect_Export_Import -- | |
1763 | ---------------------------------- | |
eaba57fb | 1764 | |
2e885a6f AC |
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 | |
f2a54683 | 1798 | -- the optimistic approach to avoid spurious errors. |
2e885a6f AC |
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); | |
c7518e6f AC |
1837 | |
1838 | -- Otherwise the expression is either False or erroneous. There | |
1839 | -- is no corresponding pragma. | |
1840 | ||
1841 | else | |
1842 | Aitem := Empty; | |
2e885a6f AC |
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 | |
b98e2969 | 1875 | Error_Msg_N |
2e885a6f AC |
1876 | ("aspect `External_Name` requires aspect `Import` or " |
1877 | & "`Export`", Aspect); | |
b98e2969 | 1878 | end if; |
2e885a6f AC |
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; | |
eaba57fb | 1892 | |
b98e2969 AC |
1893 | ----------------------------------------- |
1894 | -- Analyze_Aspect_Implicit_Dereference -- | |
1895 | ----------------------------------------- | |
eaba57fb | 1896 | |
b98e2969 AC |
1897 | procedure Analyze_Aspect_Implicit_Dereference is |
1898 | begin | |
616547fa | 1899 | if not Is_Type (E) or else not Has_Discriminants (E) then |
b98e2969 | 1900 | Error_Msg_N |
b8a18216 | 1901 | ("aspect must apply to a type with discriminants", Expr); |
eaba57fb | 1902 | |
b8a18216 ES |
1903 | elsif not Is_Entity_Name (Expr) then |
1904 | Error_Msg_N | |
1905 | ("aspect must name a discriminant of current type", Expr); | |
eaba57fb | 1906 | |
b8a18216 | 1907 | else |
f4ef7b06 AC |
1908 | -- Discriminant type be an anonymous access type or an |
1909 | -- anonymous access to subprogram. | |
4f324de2 | 1910 | |
f4ef7b06 AC |
1911 | -- Missing synchronized types??? |
1912 | ||
5612989e PMR |
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; | |
eaba57fb | 1927 | |
5612989e PMR |
1928 | Next_Discriminant (Disc); |
1929 | end loop; | |
eaba57fb | 1930 | |
5612989e | 1931 | -- Error if no proper access discriminant |
b8a18216 | 1932 | |
5612989e PMR |
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. | |
40417de8 | 1937 | |
5612989e PMR |
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; | |
b8a18216 | 1955 | |
5612989e PMR |
1956 | else |
1957 | Error_Msg_NE | |
1958 | ("not an access discriminant of&", Expr, E); | |
1959 | end if; | |
1960 | end; | |
b98e2969 | 1961 | end if; |
5612989e | 1962 | |
b98e2969 | 1963 | end Analyze_Aspect_Implicit_Dereference; |
eaba57fb | 1964 | |
9d5598bf AC |
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 | |
80e59506 AC |
1973 | Args : List_Id := Pragma_Argument_Associations; |
1974 | ||
9d5598bf AC |
1975 | begin |
1976 | -- We should never get here if aspect was disabled | |
1977 | ||
1978 | pragma Assert (not Is_Disabled (Aspect)); | |
1979 | ||
4169c2d2 AC |
1980 | -- Certain aspects allow for an optional name or expression. Do |
1981 | -- not generate a pragma with empty argument association list. | |
80e59506 AC |
1982 | |
1983 | if No (Args) or else No (Expression (First (Args))) then | |
1984 | Args := No_List; | |
1985 | end if; | |
1986 | ||
9d5598bf AC |
1987 | -- Build the pragma |
1988 | ||
1989 | Aitem := | |
1990 | Make_Pragma (Loc, | |
80e59506 | 1991 | Pragma_Argument_Associations => Args, |
9d5598bf AC |
1992 | Pragma_Identifier => |
1993 | Make_Identifier (Sloc (Id), Pragma_Name), | |
3b1d4d82 AC |
1994 | Class_Present => Class_Present (Aspect), |
1995 | Split_PPC => Split_PPC (Aspect)); | |
9d5598bf AC |
1996 | |
1997 | -- Set additional semantic fields | |
1998 | ||
1999 | if Is_Ignored (Aspect) then | |
2000 | Set_Is_Ignored (Aitem); | |
7fe6c026 | 2001 | elsif Is_Checked (Aspect) then |
3699edc4 | 2002 | Set_Is_Checked (Aitem); |
9d5598bf AC |
2003 | end if; |
2004 | ||
2005 | Set_Corresponding_Aspect (Aitem, Aspect); | |
a2c314c7 | 2006 | Set_From_Aspect_Specification (Aitem); |
9d5598bf AC |
2007 | end Make_Aitem_Pragma; |
2008 | ||
ca0eb951 | 2009 | -- Start of processing for Analyze_One_Aspect |
9d5598bf | 2010 | |
0f1a6a0b | 2011 | begin |
2178830b | 2012 | -- Skip aspect if already analyzed, to avoid looping in some cases |
bd949ee2 RD |
2013 | |
2014 | if Analyzed (Aspect) then | |
2015 | goto Continue; | |
2016 | end if; | |
2017 | ||
882eadaf RD |
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. | |
aab45d22 AC |
2021 | |
2022 | Check_Applicable_Policy (Aspect); | |
2023 | ||
2024 | if Is_Disabled (Aspect) then | |
2025 | goto Continue; | |
2026 | end if; | |
2027 | ||
95160516 AC |
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 | ||
e7fceebc AC |
2040 | -- Check restriction No_Implementation_Aspect_Specifications |
2041 | ||
9a7049fd | 2042 | if Implementation_Defined_Aspect (A_Id) then |
e7fceebc AC |
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 | ||
0df5ae93 | 2051 | -- Mark aspect analyzed (actual analysis is delayed till later) |
e7fceebc | 2052 | |
bd949ee2 | 2053 | Set_Analyzed (Aspect); |
c159409f | 2054 | Set_Entity (Aspect, E); |
ca0eb951 AC |
2055 | |
2056 | -- Build the reference to E that will be used in the built pragmas | |
2057 | ||
c159409f AC |
2058 | Ent := New_Occurrence_Of (E, Sloc (Id)); |
2059 | ||
ca0eb951 AC |
2060 | if A_Id = Aspect_Attach_Handler |
2061 | or else A_Id = Aspect_Interrupt_Handler | |
2062 | then | |
ca0eb951 | 2063 | |
85be939e AC |
2064 | -- Treat the specification as a reference to the protected |
2065 | -- operation, which might otherwise appear unreferenced and | |
2066 | -- generate spurious warnings. | |
ca0eb951 | 2067 | |
85be939e | 2068 | Generate_Reference (E, Id); |
ca0eb951 AC |
2069 | end if; |
2070 | ||
c775c209 AC |
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. | |
0f1a6a0b | 2074 | |
dac3bede YM |
2075 | if No_Duplicates_Allowed (A_Id) then |
2076 | Anod := First (L); | |
2077 | while Anod /= Aspect loop | |
9a7049fd AC |
2078 | if Comes_From_Source (Aspect) |
2079 | and then Same_Aspect (A_Id, Get_Aspect_Id (Anod)) | |
dac3bede YM |
2080 | then |
2081 | Error_Msg_Name_1 := Nam; | |
2082 | Error_Msg_Sloc := Sloc (Anod); | |
beacce02 | 2083 | |
dac3bede | 2084 | -- Case of same aspect specified twice |
beacce02 | 2085 | |
dac3bede YM |
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; | |
beacce02 | 2096 | end if; |
dac3bede | 2097 | end if; |
0f1a6a0b | 2098 | |
dac3bede YM |
2099 | Next (Anod); |
2100 | end loop; | |
2101 | end if; | |
0f1a6a0b | 2102 | |
dd91386d AC |
2103 | -- Check some general restrictions on language defined aspects |
2104 | ||
9a7049fd | 2105 | if not Implementation_Defined_Aspect (A_Id) then |
dd91386d AC |
2106 | Error_Msg_Name_1 := Nam; |
2107 | ||
75e4e36d | 2108 | -- Not allowed for renaming declarations. Examine the original |
0c3f76ba AC |
2109 | -- node because a subprogram renaming may have been rewritten |
2110 | -- as a body. | |
dd91386d | 2111 | |
0c3f76ba | 2112 | if Nkind (Original_Node (N)) in N_Renaming_Declaration then |
dd91386d AC |
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 | ||
47e11d08 AC |
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 | ||
15e934bf AC |
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 | ||
07a64c02 AC |
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 | ||
be42aa71 AC |
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. | |
07a64c02 AC |
2155 | |
2156 | elsif A_Id not in Boolean_Aspects | |
be42aa71 | 2157 | and then A_Id /= Aspect_Alignment |
07a64c02 AC |
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; | |
15e934bf AC |
2169 | end case; |
2170 | ||
0f1a6a0b AC |
2171 | -- Processing based on specific aspect |
2172 | ||
c159409f | 2173 | case A_Id is |
d3ef4bd6 AC |
2174 | when Aspect_Unimplemented => |
2175 | null; -- ??? temp for now | |
0f1a6a0b AC |
2176 | |
2177 | -- No_Aspect should be impossible | |
2178 | ||
2179 | when No_Aspect => | |
2180 | raise Program_Error; | |
2181 | ||
b98e2969 AC |
2182 | -- Case 1: Aspects corresponding to attribute definition |
2183 | -- clauses. | |
0f1a6a0b | 2184 | |
d8f43ee6 HK |
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 | |
d8f43ee6 HK |
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 | => | |
b98e2969 AC |
2210 | -- Indexing aspects apply only to tagged type |
2211 | ||
2212 | if (A_Id = Aspect_Constant_Indexing | |
15e934bf AC |
2213 | or else |
2214 | A_Id = Aspect_Variable_Indexing) | |
b98e2969 AC |
2215 | and then not (Is_Type (E) |
2216 | and then Is_Tagged_Type (E)) | |
2217 | then | |
f3296dd3 AC |
2218 | Error_Msg_N |
2219 | ("indexing aspect can only apply to a tagged type", | |
adc876a8 | 2220 | Aspect); |
b98e2969 AC |
2221 | goto Continue; |
2222 | end if; | |
2223 | ||
7f2c8954 | 2224 | -- For the case of aspect Address, we don't consider that we |
27a8f150 AC |
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 | ||
c74afd84 AC |
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 | ||
72eaa365 AC |
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 | |
c74afd84 | 2245 | then |
72eaa365 AC |
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; | |
c74afd84 AC |
2261 | end if; |
2262 | ||
851e9f19 PMR |
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; | |
0f1a6a0b | 2286 | |
dd3b3672 | 2287 | -- If the address is specified, then we treat the entity as |
b5bdffcc AC |
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 | ||
aab45d22 | 2297 | -- Case 2: Aspects corresponding to pragmas |
c159409f | 2298 | |
b98e2969 AC |
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. | |
0f1a6a0b | 2303 | |
19992053 | 2304 | -- Linker_Section/Suppress/Unsuppress |
9d5598bf | 2305 | |
d8f43ee6 HK |
2306 | when Aspect_Linker_Section |
2307 | | Aspect_Suppress | |
2308 | | Aspect_Unsuppress | |
2309 | => | |
9d5598bf AC |
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)); | |
3860d469 | 2317 | |
eb0f297f AC |
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 | ||
9d5598bf | 2332 | -- Synchronization |
c159409f | 2333 | |
9d5598bf | 2334 | -- Corresponds to pragma Implemented, construct the pragma |
6cbab959 | 2335 | |
d62520f3 | 2336 | when Aspect_Synchronization => |
9d5598bf AC |
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); | |
6cbab959 | 2344 | |
4e6768ab | 2345 | -- Attach_Handler |
9d5598bf | 2346 | |
b98e2969 | 2347 | when Aspect_Attach_Handler => |
9d5598bf AC |
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 | ||
0df5ae93 AC |
2356 | -- We need to insert this pragma into the tree to get proper |
2357 | -- processing and to look valid from a placement viewpoint. | |
2358 | ||
4e6768ab | 2359 | Insert_Pragma (Aitem); |
0df5ae93 AC |
2360 | goto Continue; |
2361 | ||
9d5598bf | 2362 | -- Dynamic_Predicate, Predicate, Static_Predicate |
b98e2969 | 2363 | |
d8f43ee6 HK |
2364 | when Aspect_Dynamic_Predicate |
2365 | | Aspect_Predicate | |
2366 | | Aspect_Static_Predicate | |
2367 | => | |
ac072cb2 AC |
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; | |
fd7215d7 AC |
2375 | |
2376 | elsif Is_Incomplete_Type (E) then | |
2377 | Error_Msg_N | |
2378 | ("predicate cannot apply to incomplete view", Aspect); | |
40c21e91 PMR |
2379 | |
2380 | elsif Is_Generic_Type (E) then | |
2381 | Error_Msg_N | |
2382 | ("predicate cannot apply to formal type", Aspect); | |
fd7215d7 | 2383 | goto Continue; |
ac072cb2 AC |
2384 | end if; |
2385 | ||
b98e2969 | 2386 | -- Construct the pragma (always a pragma Predicate, with |
aab45d22 AC |
2387 | -- flags recording whether it is static/dynamic). We also |
2388 | -- set flags recording this in the type itself. | |
b98e2969 | 2389 | |
9d5598bf AC |
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))), | |
a2c314c7 | 2396 | Pragma_Name => Name_Predicate); |
b98e2969 | 2397 | |
aab45d22 AC |
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); | |
89a53f83 AC |
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 | ||
aab45d22 AC |
2413 | elsif A_Id = Aspect_Static_Predicate then |
2414 | Set_Has_Static_Predicate_Aspect (E); | |
2415 | end if; | |
2416 | ||
b98e2969 | 2417 | -- If the type is private, indicate that its completion |
113a62d9 RD |
2418 | -- has a freeze node, because that is the one that will |
2419 | -- be visible at freeze time. | |
b98e2969 | 2420 | |
9d5598bf | 2421 | if Is_Private_Type (E) and then Present (Full_View (E)) then |
b98e2969 | 2422 | Set_Has_Predicates (Full_View (E)); |
aab45d22 AC |
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 | ||
b98e2969 AC |
2430 | Set_Has_Delayed_Aspects (Full_View (E)); |
2431 | Ensure_Freeze_Node (Full_View (E)); | |
2432 | end if; | |
2433 | ||
a2c314c7 AC |
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 | ||
b98e2969 AC |
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. | |
0f1a6a0b | 2478 | |
9d5598bf AC |
2479 | -- Convention |
2480 | ||
2e885a6f AC |
2481 | when Aspect_Convention => |
2482 | Analyze_Aspect_Convention; | |
2483 | goto Continue; | |
41d8ee1d | 2484 | |
2e885a6f | 2485 | -- External_Name, Link_Name |
41d8ee1d | 2486 | |
d8f43ee6 HK |
2487 | when Aspect_External_Name |
2488 | | Aspect_Link_Name | |
2489 | => | |
2e885a6f AC |
2490 | Analyze_Aspect_External_Link_Name; |
2491 | goto Continue; | |
4169b895 | 2492 | |
9d5598bf AC |
2493 | -- CPU, Interrupt_Priority, Priority |
2494 | ||
cf3b97ef AC |
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. | |
473e20df | 2507 | |
d8f43ee6 HK |
2508 | when Aspect_CPU |
2509 | | Aspect_Interrupt_Priority | |
2510 | | Aspect_Priority | |
2511 | => | |
cf3b97ef AC |
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 | |
e9f97e79 AC |
2520 | -- subprograms. RM D.1 does not forbid this explicitly, |
2521 | -- but RM J.15.11(6/3) does not permit pragma | |
cf3b97ef AC |
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 | ||
edab6088 | 2531 | elsif not Is_OK_Static_Expression (Expr) then |
cf3b97ef AC |
2532 | Flag_Non_Static_Expr |
2533 | ("aspect requires static expression!", Expr); | |
2534 | ||
5644b7e8 AC |
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)) | |
cf3b97ef | 2543 | then |
e9f97e79 | 2544 | -- See RM D.1(14/3) and D.16(12/3) |
cf3b97ef AC |
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 | ||
53f697ee AC |
2579 | -- Ignore pragma if Relaxed_RM_Semantics to support |
2580 | -- other targets/non GNAT compilers. | |
2581 | ||
2582 | elsif not Relaxed_RM_Semantics then | |
cf3b97ef AC |
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 | |
6be44a9a | 2594 | -- have any effect. Previously we with'ed the package |
cf3b97ef AC |
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; | |
cf3b97ef AC |
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 | ||
eacfa9bc | 2608 | -- Handling for these aspects in subprograms is complete |
cf3b97ef AC |
2609 | |
2610 | goto Continue; | |
2611 | ||
634a926b AC |
2612 | -- For task and protected types pass the aspect as an |
2613 | -- attribute. | |
9d5598bf | 2614 | |
473e20df AC |
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 | ||
9d5598bf AC |
2623 | -- Warnings |
2624 | ||
0f1a6a0b | 2625 | when Aspect_Warnings => |
9d5598bf AC |
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)); | |
0f1a6a0b | 2633 | |
877a5a12 AC |
2634 | Decorate (Aspect, Aitem); |
2635 | Insert_Pragma (Aitem); | |
2636 | goto Continue; | |
2637 | ||
b98e2969 AC |
2638 | -- Case 2c: Aspects corresponding to pragmas with three |
2639 | -- arguments. | |
a01b9df6 | 2640 | |
b98e2969 AC |
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. | |
a01b9df6 | 2644 | |
9d5598bf AC |
2645 | -- Invariant, Type_Invariant |
2646 | ||
d8f43ee6 HK |
2647 | when Aspect_Invariant |
2648 | | Aspect_Type_Invariant | |
2649 | => | |
b98e2969 AC |
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. | |
a01b9df6 | 2653 | |
9d5598bf AC |
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); | |
b98e2969 AC |
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)))); | |
a01b9df6 AC |
2672 | end if; |
2673 | ||
b98e2969 AC |
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 | ||
b98e2969 | 2678 | Delay_Required := False; |
a01b9df6 | 2679 | |
c116143c ES |
2680 | -- Case 2d : Aspects that correspond to a pragma with one |
2681 | -- argument. | |
2682 | ||
9d5598bf | 2683 | -- Abstract_State |
cf6956bb | 2684 | |
54e28df2 HK |
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 | ||
39af2bac | 2691 | when Aspect_Abstract_State => Abstract_State : declare |
c0cdbd39 | 2692 | Context : Node_Id := N; |
39af2bac AC |
2693 | |
2694 | begin | |
c0cdbd39 AC |
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) | |
39af2bac | 2705 | then |
39af2bac AC |
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); | |
ebb6b0bd | 2711 | |
21d7ef70 AC |
2712 | Decorate (Aspect, Aitem); |
2713 | Insert_Pragma | |
2714 | (Prag => Aitem, | |
2715 | Is_Instance => | |
2716 | Is_Generic_Instance (Defining_Entity (Context))); | |
39af2bac AC |
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; | |
cf6956bb | 2726 | |
847d950d HK |
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 | ||
1df7c326 AC |
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 | ||
e477d718 AC |
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 | ||
2ef05128 AC |
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 | ||
9d5598bf AC |
2807 | -- Depends |
2808 | ||
4e6768ab AC |
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. | |
fd8b4053 | 2815 | |
fe96ecb9 | 2816 | when Aspect_Depends => |
9d5598bf AC |
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 | ||
4e6768ab AC |
2823 | Decorate (Aspect, Aitem); |
2824 | Insert_Pragma (Aitem); | |
d6095153 AC |
2825 | goto Continue; |
2826 | ||
847d950d HK |
2827 | -- Aspect Effecitve_Reads is never delayed because it is |
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 | ||
039538bc AC |
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 | ||
c5cec2fe AC |
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 | ||
21d7ef70 | 2877 | when Aspect_Ghost => |
c5cec2fe AC |
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); | |
21d7ef70 | 2885 | Insert_Pragma (Aitem); |
c5cec2fe | 2886 | goto Continue; |
c5cec2fe | 2887 | |
9d5598bf | 2888 | -- Global |
fe96ecb9 | 2889 | |
4e6768ab AC |
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. | |
7a1f1775 AC |
2896 | |
2897 | when Aspect_Global => | |
9d5598bf AC |
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 | ||
4e6768ab AC |
2904 | Decorate (Aspect, Aitem); |
2905 | Insert_Pragma (Aitem); | |
d6095153 AC |
2906 | goto Continue; |
2907 | ||
9b2451e5 AC |
2908 | -- Initial_Condition |
2909 | ||
4e6768ab AC |
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. | |
9b2451e5 AC |
2917 | |
2918 | when Aspect_Initial_Condition => Initial_Condition : declare | |
c0cdbd39 | 2919 | Context : Node_Id := N; |
9b2451e5 AC |
2920 | |
2921 | begin | |
4e6768ab AC |
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. | |
c0cdbd39 AC |
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) | |
9b2451e5 | 2932 | then |
9b2451e5 AC |
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); | |
9b2451e5 | 2939 | |
21d7ef70 AC |
2940 | Decorate (Aspect, Aitem); |
2941 | Insert_Pragma | |
2942 | (Prag => Aitem, | |
2943 | Is_Instance => | |
2944 | Is_Generic_Instance (Defining_Entity (Context))); | |
e59243fa | 2945 | |
21d7ef70 | 2946 | -- Otherwise the context is illegal |
9b2451e5 AC |
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 | ||
54e28df2 HK |
2957 | -- Initializes |
2958 | ||
4e6768ab AC |
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. | |
54e28df2 HK |
2965 | |
2966 | when Aspect_Initializes => Initializes : declare | |
c0cdbd39 | 2967 | Context : Node_Id := N; |
54e28df2 HK |
2968 | |
2969 | begin | |
e59243fa AC |
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. | |
c0cdbd39 AC |
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) | |
54e28df2 | 2980 | then |
54e28df2 HK |
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); | |
54e28df2 | 2986 | |
21d7ef70 AC |
2987 | Decorate (Aspect, Aitem); |
2988 | Insert_Pragma | |
2989 | (Prag => Aitem, | |
2990 | Is_Instance => | |
2991 | Is_Generic_Instance (Defining_Entity (Context))); | |
e59243fa | 2992 | |
21d7ef70 | 2993 | -- Otherwise the context is illegal |
54e28df2 HK |
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 | ||
656d1fba JS |
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 | ||
442d1abb AC |
3017 | -- Max_Queue_Length |
3018 | ||
3019 | when Aspect_Max_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_Queue_Length); | |
3025 | ||
3026 | Decorate (Aspect, Aitem); | |
3027 | Insert_Pragma (Aitem); | |
3028 | goto Continue; | |
3029 | ||
c2a2dbcc RD |
3030 | -- Obsolescent |
3031 | ||
3032 | when Aspect_Obsolescent => declare | |
3033 | Args : List_Id; | |
3034 | ||
3035 | begin | |
3036 | if No (Expr) then | |
3037 | Args := No_List; | |
3038 | else | |
3039 | Args := New_List ( | |
3040 | Make_Pragma_Argument_Association (Sloc (Expr), | |
3041 | Expression => Relocate_Node (Expr))); | |
3042 | end if; | |
3043 | ||
3044 | Make_Aitem_Pragma | |
3045 | (Pragma_Argument_Associations => Args, | |
3046 | Pragma_Name => Chars (Id)); | |
3047 | end; | |
3048 | ||
d7af5ea5 HK |
3049 | -- Part_Of |
3050 | ||
3051 | when Aspect_Part_Of => | |
3052 | if Nkind_In (N, N_Object_Declaration, | |
3053 | N_Package_Instantiation) | |
75b87c16 | 3054 | or else Is_Single_Concurrent_Type_Declaration (N) |
d7af5ea5 HK |
3055 | then |
3056 | Make_Aitem_Pragma | |
3057 | (Pragma_Argument_Associations => New_List ( | |
3058 | Make_Pragma_Argument_Association (Loc, | |
3059 | Expression => Relocate_Node (Expr))), | |
3060 | Pragma_Name => Name_Part_Of); | |
3061 | ||
75b87c16 AC |
3062 | Decorate (Aspect, Aitem); |
3063 | Insert_Pragma (Aitem); | |
75b87c16 | 3064 | |
d7af5ea5 HK |
3065 | else |
3066 | Error_Msg_NE | |
75b87c16 AC |
3067 | ("aspect & must apply to package instantiation, " |
3068 | & "object, single protected type or single task type", | |
3069 | Aspect, Id); | |
d7af5ea5 HK |
3070 | end if; |
3071 | ||
90b510e4 AC |
3072 | goto Continue; |
3073 | ||
1c6269d3 HK |
3074 | -- SPARK_Mode |
3075 | ||
877a5a12 | 3076 | when Aspect_SPARK_Mode => |
1c6269d3 HK |
3077 | Make_Aitem_Pragma |
3078 | (Pragma_Argument_Associations => New_List ( | |
3079 | Make_Pragma_Argument_Association (Loc, | |
3080 | Expression => Relocate_Node (Expr))), | |
3081 | Pragma_Name => Name_SPARK_Mode); | |
1c6269d3 | 3082 | |
877a5a12 AC |
3083 | Decorate (Aspect, Aitem); |
3084 | Insert_Pragma (Aitem); | |
3085 | goto Continue; | |
5ff90f08 | 3086 | |
ea3c0651 AC |
3087 | -- Refined_Depends |
3088 | ||
4e6768ab AC |
3089 | -- Aspect Refined_Depends is never delayed because it is |
3090 | -- equivalent to a source pragma which appears in the | |
3091 | -- declarations of the related subprogram body. To deal with | |
3092 | -- forward references, the generated pragma is stored in the | |
3093 | -- contract of the related subprogram body and later analyzed | |
3094 | -- at the end of the declarative region. For details, see | |
3095 | -- routine Analyze_Refined_Depends_In_Decl_Part. | |
ea3c0651 AC |
3096 | |
3097 | when Aspect_Refined_Depends => | |
39d3009f AC |
3098 | Make_Aitem_Pragma |
3099 | (Pragma_Argument_Associations => New_List ( | |
3100 | Make_Pragma_Argument_Association (Loc, | |
3101 | Expression => Relocate_Node (Expr))), | |
3102 | Pragma_Name => Name_Refined_Depends); | |
3103 | ||
4e6768ab AC |
3104 | Decorate (Aspect, Aitem); |
3105 | Insert_Pragma (Aitem); | |
39d3009f | 3106 | goto Continue; |
ea3c0651 AC |
3107 | |
3108 | -- Refined_Global | |
3109 | ||
4e6768ab AC |
3110 | -- Aspect Refined_Global is never delayed because it is |
3111 | -- equivalent to a source pragma which appears in the | |
3112 | -- declarations of the related subprogram body. To deal with | |
3113 | -- forward references, the generated pragma is stored in the | |
3114 | -- contract of the related subprogram body and later analyzed | |
3115 | -- at the end of the declarative region. For details, see | |
3116 | -- routine Analyze_Refined_Global_In_Decl_Part. | |
ea3c0651 AC |
3117 | |
3118 | when Aspect_Refined_Global => | |
ab8843fa HK |
3119 | Make_Aitem_Pragma |
3120 | (Pragma_Argument_Associations => New_List ( | |
3121 | Make_Pragma_Argument_Association (Loc, | |
3122 | Expression => Relocate_Node (Expr))), | |
3123 | Pragma_Name => Name_Refined_Global); | |
3124 | ||
4e6768ab AC |
3125 | Decorate (Aspect, Aitem); |
3126 | Insert_Pragma (Aitem); | |
ab8843fa | 3127 | goto Continue; |
ea3c0651 | 3128 | |
e7f23f06 AC |
3129 | -- Refined_Post |
3130 | ||
3131 | when Aspect_Refined_Post => | |
3132 | Make_Aitem_Pragma | |
3133 | (Pragma_Argument_Associations => New_List ( | |
3134 | Make_Pragma_Argument_Association (Loc, | |
3135 | Expression => Relocate_Node (Expr))), | |
3136 | Pragma_Name => Name_Refined_Post); | |
3137 | ||
8a0183fd HK |
3138 | Decorate (Aspect, Aitem); |
3139 | Insert_Pragma (Aitem); | |
3140 | goto Continue; | |
3141 | ||
39af2bac AC |
3142 | -- Refined_State |
3143 | ||
21d7ef70 | 3144 | when Aspect_Refined_State => |
39af2bac | 3145 | |
39af2bac AC |
3146 | -- The corresponding pragma for Refined_State is inserted in |
3147 | -- the declarations of the related package body. This action | |
3148 | -- synchronizes both the source and from-aspect versions of | |
3149 | -- the pragma. | |
3150 | ||
3151 | if Nkind (N) = N_Package_Body then | |
39af2bac AC |
3152 | Make_Aitem_Pragma |
3153 | (Pragma_Argument_Associations => New_List ( | |
3154 | Make_Pragma_Argument_Association (Loc, | |
3155 | Expression => Relocate_Node (Expr))), | |
3156 | Pragma_Name => Name_Refined_State); | |
2dade097 | 3157 | |
21d7ef70 AC |
3158 | Decorate (Aspect, Aitem); |
3159 | Insert_Pragma (Aitem); | |
2dade097 | 3160 | |
21d7ef70 | 3161 | -- Otherwise the context is illegal |
39af2bac AC |
3162 | |
3163 | else | |
3164 | Error_Msg_NE | |
3165 | ("aspect & must apply to a package body", Aspect, Id); | |
3166 | end if; | |
3167 | ||
3168 | goto Continue; | |
39af2bac | 3169 | |
9d5598bf | 3170 | -- Relative_Deadline |
7a1f1775 AC |
3171 | |
3172 | when Aspect_Relative_Deadline => | |
9d5598bf AC |
3173 | Make_Aitem_Pragma |
3174 | (Pragma_Argument_Associations => New_List ( | |
3175 | Make_Pragma_Argument_Association (Loc, | |
3176 | Expression => Relocate_Node (Expr))), | |
3177 | Pragma_Name => Name_Relative_Deadline); | |
c116143c ES |
3178 | |
3179 | -- If the aspect applies to a task, the corresponding pragma | |
3180 | -- must appear within its declarations, not after. | |
3181 | ||
3182 | if Nkind (N) = N_Task_Type_Declaration then | |
3183 | declare | |
3184 | Def : Node_Id; | |
3185 | V : List_Id; | |
3186 | ||
3187 | begin | |
3188 | if No (Task_Definition (N)) then | |
3189 | Set_Task_Definition (N, | |
3190 | Make_Task_Definition (Loc, | |
3191 | Visible_Declarations => New_List, | |
3192 | End_Label => Empty)); | |
3193 | end if; | |
3194 | ||
3195 | Def := Task_Definition (N); | |
3196 | V := Visible_Declarations (Def); | |
3197 | if not Is_Empty_List (V) then | |
3198 | Insert_Before (First (V), Aitem); | |
3199 | ||
3200 | else | |
3201 | Set_Visible_Declarations (Def, New_List (Aitem)); | |
3202 | end if; | |
3203 | ||
3204 | goto Continue; | |
3205 | end; | |
3206 | end if; | |
3207 | ||
a40d9947 PB |
3208 | -- Secondary_Stack_Size |
3209 | ||
3210 | -- Aspect Secondary_Stack_Size needs to be converted into a | |
3211 | -- pragma for two reasons: the attribute is not analyzed until | |
3212 | -- after the expansion of the task type declaration and the | |
3213 | -- attribute does not have visibility on the discriminant. | |
3214 | ||
3215 | when Aspect_Secondary_Stack_Size => | |
3216 | Make_Aitem_Pragma | |
3217 | (Pragma_Argument_Associations => New_List ( | |
3218 | Make_Pragma_Argument_Association (Loc, | |
3219 | Expression => Relocate_Node (Expr))), | |
3220 | Pragma_Name => | |
3221 | Name_Secondary_Stack_Size); | |
3222 | ||
3223 | Decorate (Aspect, Aitem); | |
3224 | Insert_Pragma (Aitem); | |
3225 | goto Continue; | |
3226 | ||
3227 | -- Volatile_Function | |
3228 | ||
847d950d HK |
3229 | -- Aspect Volatile_Function is never delayed because it is |
3230 | -- equivalent to a source pragma which appears after the | |
3231 | -- related subprogram. | |
3232 | ||
3233 | when Aspect_Volatile_Function => | |
3234 | Make_Aitem_Pragma | |
3235 | (Pragma_Argument_Associations => New_List ( | |
3236 | Make_Pragma_Argument_Association (Loc, | |
3237 | Expression => Relocate_Node (Expr))), | |
3238 | Pragma_Name => Name_Volatile_Function); | |
3239 | ||
3240 | Decorate (Aspect, Aitem); | |
3241 | Insert_Pragma (Aitem); | |
3242 | goto Continue; | |
3243 | ||
52d9ba4d AC |
3244 | -- Case 2e: Annotate aspect |
3245 | ||
3246 | when Aspect_Annotate => | |
3247 | declare | |
3248 | Args : List_Id; | |
3249 | Pargs : List_Id; | |
3250 | Arg : Node_Id; | |
3251 | ||
3252 | begin | |
3253 | -- The argument can be a single identifier | |
3254 | ||
3255 | if Nkind (Expr) = N_Identifier then | |
3256 | ||
3257 | -- One level of parens is allowed | |
3258 | ||
3259 | if Paren_Count (Expr) > 1 then | |
3260 | Error_Msg_F ("extra parentheses ignored", Expr); | |
3261 | end if; | |
3262 | ||
3263 | Set_Paren_Count (Expr, 0); | |
3264 | ||
3265 | -- Add the single item to the list | |
3266 | ||
3267 | Args := New_List (Expr); | |
3268 | ||
3269 | -- Otherwise we must have an aggregate | |
3270 | ||
3271 | elsif Nkind (Expr) = N_Aggregate then | |
3272 | ||
3273 | -- Must be positional | |
3274 | ||
3275 | if Present (Component_Associations (Expr)) then | |
3276 | Error_Msg_F | |
3277 | ("purely positional aggregate required", Expr); | |
3278 | goto Continue; | |
3279 | end if; | |
3280 | ||
3281 | -- Must not be parenthesized | |
3282 | ||
3283 | if Paren_Count (Expr) /= 0 then | |
3284 | Error_Msg_F ("extra parentheses ignored", Expr); | |
3285 | end if; | |
3286 | ||
3287 | -- List of arguments is list of aggregate expressions | |
3288 | ||
3289 | Args := Expressions (Expr); | |
3290 | ||
3291 | -- Anything else is illegal | |
3292 | ||
3293 | else | |
3294 | Error_Msg_F ("wrong form for Annotate aspect", Expr); | |
3295 | goto Continue; | |
3296 | end if; | |
3297 | ||
3298 | -- Prepare pragma arguments | |
3299 | ||
3300 | Pargs := New_List; | |
3301 | Arg := First (Args); | |
3302 | while Present (Arg) loop | |
3303 | Append_To (Pargs, | |
3304 | Make_Pragma_Argument_Association (Sloc (Arg), | |
3305 | Expression => Relocate_Node (Arg))); | |
3306 | Next (Arg); | |
3307 | end loop; | |
3308 | ||
3309 | Append_To (Pargs, | |
3310 | Make_Pragma_Argument_Association (Sloc (Ent), | |
3311 | Chars => Name_Entity, | |
3312 | Expression => Ent)); | |
3313 | ||
3314 | Make_Aitem_Pragma | |
3315 | (Pragma_Argument_Associations => Pargs, | |
3316 | Pragma_Name => Name_Annotate); | |
3317 | end; | |
3318 | ||
b98e2969 AC |
3319 | -- Case 3 : Aspects that don't correspond to pragma/attribute |
3320 | -- definition clause. | |
6d9e03cb | 3321 | |
b98e2969 AC |
3322 | -- Case 3a: The aspects listed below don't correspond to |
3323 | -- pragmas/attributes but do require delayed analysis. | |
2ef48385 | 3324 | |
33c9f9af AC |
3325 | -- Default_Value can only apply to a scalar type |
3326 | ||
3327 | when Aspect_Default_Value => | |
3328 | if not Is_Scalar_Type (E) then | |
3329 | Error_Msg_N | |
ad075b50 | 3330 | ("aspect Default_Value must apply to a scalar type", N); |
33c9f9af AC |
3331 | end if; |
3332 | ||
3333 | Aitem := Empty; | |
3334 | ||
3335 | -- Default_Component_Value can only apply to an array type | |
3336 | -- with scalar components. | |
3337 | ||
3338 | when Aspect_Default_Component_Value => | |
3339 | if not (Is_Array_Type (E) | |
adc876a8 | 3340 | and then Is_Scalar_Type (Component_Type (E))) |
33c9f9af | 3341 | then |
2e885a6f AC |
3342 | Error_Msg_N |
3343 | ("aspect Default_Component_Value can only apply to an " | |
3344 | & "array of scalar components", N); | |
33c9f9af | 3345 | end if; |
9d5598bf | 3346 | |
b98e2969 | 3347 | Aitem := Empty; |
2ef48385 | 3348 | |
b98e2969 AC |
3349 | -- Case 3b: The aspects listed below don't correspond to |
3350 | -- pragmas/attributes and don't need delayed analysis. | |
ddf67a1d | 3351 | |
9d5598bf AC |
3352 | -- Implicit_Dereference |
3353 | ||
b98e2969 AC |
3354 | -- For Implicit_Dereference, External_Name and Link_Name, only |
3355 | -- the legality checks are done during the analysis, thus no | |
3356 | -- delay is required. | |
fecbd779 | 3357 | |
b98e2969 AC |
3358 | when Aspect_Implicit_Dereference => |
3359 | Analyze_Aspect_Implicit_Dereference; | |
3360 | goto Continue; | |
2ef48385 | 3361 | |
9d5598bf AC |
3362 | -- Dimension |
3363 | ||
b98e2969 AC |
3364 | when Aspect_Dimension => |
3365 | Analyze_Aspect_Dimension (N, Id, Expr); | |
3366 | goto Continue; | |
516f608f | 3367 | |
9d5598bf AC |
3368 | -- Dimension_System |
3369 | ||
b98e2969 AC |
3370 | when Aspect_Dimension_System => |
3371 | Analyze_Aspect_Dimension_System (N, Id, Expr); | |
3372 | goto Continue; | |
2ef48385 | 3373 | |
2cbac6c6 | 3374 | -- Case 4: Aspects requiring special handling |
aab45d22 | 3375 | |
541fb4d9 YM |
3376 | -- Pre/Post/Test_Case/Contract_Cases whose corresponding |
3377 | -- pragmas take care of the delay. | |
2ef48385 | 3378 | |
9d5598bf AC |
3379 | -- Pre/Post |
3380 | ||
c775c209 AC |
3381 | -- Aspects Pre/Post generate Precondition/Postcondition pragmas |
3382 | -- with a first argument that is the expression, and a second | |
3383 | -- argument that is an informative message if the test fails. | |
3384 | -- This is inserted right after the declaration, to get the | |
e606088a AC |
3385 | -- required pragma placement. The processing for the pragmas |
3386 | -- takes care of the required delay. | |
0f1a6a0b | 3387 | |
5afe5d2d | 3388 | when Pre_Post_Aspects => Pre_Post : declare |
c775c209 | 3389 | Pname : Name_Id; |
0f1a6a0b | 3390 | |
c775c209 | 3391 | begin |
857ade1b | 3392 | if A_Id = Aspect_Pre or else A_Id = Aspect_Precondition then |
c775c209 AC |
3393 | Pname := Name_Precondition; |
3394 | else | |
3395 | Pname := Name_Postcondition; | |
3396 | end if; | |
c159409f | 3397 | |
57323d5b | 3398 | -- Check that the class-wide predicate cannot be applied to |
f2a54683 AC |
3399 | -- an operation of a synchronized type. AI12-0182 forbids |
3400 | -- these altogether, while earlier language semantics made | |
3401 | -- them legal on tagged synchronized types. | |
3402 | ||
3403 | -- Other legality checks are performed when analyzing the | |
3404 | -- contract of the operation. | |
57323d5b AC |
3405 | |
3406 | if Class_Present (Aspect) | |
3407 | and then Is_Concurrent_Type (Current_Scope) | |
57323d5b AC |
3408 | and then Ekind_In (E, E_Entry, E_Function, E_Procedure) |
3409 | then | |
3410 | Error_Msg_Name_1 := Original_Aspect_Pragma_Name (Aspect); | |
3411 | Error_Msg_N | |
3412 | ("aspect % can only be specified for a primitive " | |
3413 | & "operation of a tagged type", Aspect); | |
3414 | ||
3415 | goto Continue; | |
3416 | end if; | |
3417 | ||
c775c209 AC |
3418 | -- If the expressions is of the form A and then B, then |
3419 | -- we generate separate Pre/Post aspects for the separate | |
3420 | -- clauses. Since we allow multiple pragmas, there is no | |
3421 | -- problem in allowing multiple Pre/Post aspects internally. | |
2d395256 AC |
3422 | -- These should be treated in reverse order (B first and |
3423 | -- A second) since they are later inserted just after N in | |
3424 | -- the order they are treated. This way, the pragma for A | |
3425 | -- ends up preceding the pragma for B, which may have an | |
3426 | -- importance for the error raised (either constraint error | |
3427 | -- or precondition error). | |
c775c209 | 3428 | |
beacce02 | 3429 | -- We do not do this for Pre'Class, since we have to put |
33c9f9af | 3430 | -- these conditions together in a complex OR expression. |
0f1a6a0b | 3431 | |
8c18a165 AC |
3432 | -- We do not do this in ASIS mode, as ASIS relies on the |
3433 | -- original node representing the complete expression, when | |
270c6b4d PT |
3434 | -- retrieving it through the source aspect table. Also, we |
3435 | -- don't do this in GNATprove mode, because it brings no | |
3436 | -- benefit for proof and causes annoynace for flow analysis, | |
3437 | -- which prefers to be as close to the original source code | |
3438 | -- as possible. | |
8c18a165 | 3439 | |
270c6b4d | 3440 | if not (ASIS_Mode or GNATprove_Mode) |
8c18a165 AC |
3441 | and then (Pname = Name_Postcondition |
3442 | or else not Class_Present (Aspect)) | |
beacce02 AC |
3443 | then |
3444 | while Nkind (Expr) = N_And_Then loop | |
3445 | Insert_After (Aspect, | |
2d395256 | 3446 | Make_Aspect_Specification (Sloc (Left_Opnd (Expr)), |
beacce02 | 3447 | Identifier => Identifier (Aspect), |
2d395256 | 3448 | Expression => Relocate_Node (Left_Opnd (Expr)), |
beacce02 AC |
3449 | Class_Present => Class_Present (Aspect), |
3450 | Split_PPC => True)); | |
2d395256 | 3451 | Rewrite (Expr, Relocate_Node (Right_Opnd (Expr))); |
beacce02 AC |
3452 | Eloc := Sloc (Expr); |
3453 | end loop; | |
3454 | end if; | |
0f1a6a0b | 3455 | |
a9e892d0 AC |
3456 | -- Build the precondition/postcondition pragma |
3457 | ||
e87f67eb ES |
3458 | -- We use Relocate_Node here rather than New_Copy_Tree |
3459 | -- because subsequent visibility analysis of the aspect | |
3460 | -- depends on this sharing. This should be cleaned up??? | |
c159409f | 3461 | |
5291985c ES |
3462 | -- If the context is generic or involves ASIS, we want |
3463 | -- to preserve the original tree, and simply share it | |
3464 | -- between aspect and generated attribute. This parallels | |
3465 | -- what is done in sem_prag.adb (see Get_Argument). | |
3466 | ||
3467 | declare | |
3468 | New_Expr : Node_Id; | |
3469 | ||
3470 | begin | |
3471 | if ASIS_Mode or else Inside_A_Generic then | |
3472 | New_Expr := Expr; | |
3473 | else | |
3474 | New_Expr := Relocate_Node (Expr); | |
3475 | end if; | |
3476 | ||
3477 | Make_Aitem_Pragma | |
3478 | (Pragma_Argument_Associations => New_List ( | |
3479 | Make_Pragma_Argument_Association (Eloc, | |
3480 | Chars => Name_Check, | |
3481 | Expression => New_Expr)), | |
3482 | Pragma_Name => Pname); | |
3483 | end; | |
beacce02 AC |
3484 | |
3485 | -- Add message unless exception messages are suppressed | |
3486 | ||
3487 | if not Opt.Exception_Locations_Suppressed then | |
3488 | Append_To (Pragma_Argument_Associations (Aitem), | |
3489 | Make_Pragma_Argument_Association (Eloc, | |
c9d70ab1 | 3490 | Chars => Name_Message, |
beacce02 AC |
3491 | Expression => |
3492 | Make_String_Literal (Eloc, | |
3493 | Strval => "failed " | |
3494 | & Get_Name_String (Pname) | |
3495 | & " from " | |
3496 | & Build_Location_String (Eloc)))); | |
3497 | end if; | |
c159409f | 3498 | |
47e11d08 | 3499 | Set_Is_Delayed_Aspect (Aspect); |
c159409f | 3500 | |
c775c209 AC |
3501 | -- For Pre/Post cases, insert immediately after the entity |
3502 | -- declaration, since that is the required pragma placement. | |
3503 | -- Note that for these aspects, we do not have to worry | |
3504 | -- about delay issues, since the pragmas themselves deal | |
3505 | -- with delay of visibility for the expression analysis. | |
3506 | ||
4e6768ab | 3507 | Insert_Pragma (Aitem); |
5c5e108f | 3508 | |
c775c209 | 3509 | goto Continue; |
5afe5d2d | 3510 | end Pre_Post; |
0f1a6a0b | 3511 | |
9d5598bf AC |
3512 | -- Test_Case |
3513 | ||
541fb4d9 YM |
3514 | when Aspect_Test_Case => Test_Case : declare |
3515 | Args : List_Id; | |
3516 | Comp_Expr : Node_Id; | |
3517 | Comp_Assn : Node_Id; | |
3518 | New_Expr : Node_Id; | |
3860d469 | 3519 | |
541fb4d9 YM |
3520 | begin |
3521 | Args := New_List; | |
5accd7b6 | 3522 | |
541fb4d9 YM |
3523 | if Nkind (Parent (N)) = N_Compilation_Unit then |
3524 | Error_Msg_Name_1 := Nam; | |
3525 | Error_Msg_N ("incorrect placement of aspect `%`", E); | |
3526 | goto Continue; | |
3527 | end if; | |
dac3bede | 3528 | |
541fb4d9 YM |
3529 | if Nkind (Expr) /= N_Aggregate then |
3530 | Error_Msg_Name_1 := Nam; | |
3531 | Error_Msg_NE | |
3532 | ("wrong syntax for aspect `%` for &", Id, E); | |
3533 | goto Continue; | |
3534 | end if; | |
dac3bede | 3535 | |
541fb4d9 | 3536 | -- Make pragma expressions refer to the original aspect |
33c9f9af AC |
3537 | -- expressions through the Original_Node link. This is used |
3538 | -- in semantic analysis for ASIS mode, so that the original | |
3539 | -- expression also gets analyzed. | |
541fb4d9 YM |
3540 | |
3541 | Comp_Expr := First (Expressions (Expr)); | |
3542 | while Present (Comp_Expr) loop | |
3543 | New_Expr := Relocate_Node (Comp_Expr); | |
541fb4d9 YM |
3544 | Append_To (Args, |
3545 | Make_Pragma_Argument_Association (Sloc (Comp_Expr), | |
3546 | Expression => New_Expr)); | |
3547 | Next (Comp_Expr); | |
3548 | end loop; | |
3549 | ||
3550 | Comp_Assn := First (Component_Associations (Expr)); | |
3551 | while Present (Comp_Assn) loop | |
3552 | if List_Length (Choices (Comp_Assn)) /= 1 | |
3553 | or else | |
3554 | Nkind (First (Choices (Comp_Assn))) /= N_Identifier | |
3555 | then | |
90e85233 | 3556 | Error_Msg_Name_1 := Nam; |
dac3bede | 3557 | Error_Msg_NE |
90e85233 | 3558 | ("wrong syntax for aspect `%` for &", Id, E); |
dac3bede YM |
3559 | goto Continue; |
3560 | end if; | |
3561 | ||
541fb4d9 YM |
3562 | Append_To (Args, |
3563 | Make_Pragma_Argument_Association (Sloc (Comp_Assn), | |
c9d70ab1 AC |
3564 | Chars => Chars (First (Choices (Comp_Assn))), |
3565 | Expression => | |
3566 | Relocate_Node (Expression (Comp_Assn)))); | |
541fb4d9 YM |
3567 | Next (Comp_Assn); |
3568 | end loop; | |
dac3bede | 3569 | |
541fb4d9 | 3570 | -- Build the test-case pragma |
dac3bede | 3571 | |
9d5598bf AC |
3572 | Make_Aitem_Pragma |
3573 | (Pragma_Argument_Associations => Args, | |
3574 | Pragma_Name => Nam); | |
541fb4d9 | 3575 | end Test_Case; |
dec6faf1 | 3576 | |
9d5598bf AC |
3577 | -- Contract_Cases |
3578 | ||
5afe5d2d | 3579 | when Aspect_Contract_Cases => |
9d5598bf AC |
3580 | Make_Aitem_Pragma |
3581 | (Pragma_Argument_Associations => New_List ( | |
3582 | Make_Pragma_Argument_Association (Loc, | |
3583 | Expression => Relocate_Node (Expr))), | |
3584 | Pragma_Name => Nam); | |
570104df | 3585 | |
4e6768ab AC |
3586 | Decorate (Aspect, Aitem); |
3587 | Insert_Pragma (Aitem); | |
5afe5d2d | 3588 | goto Continue; |
570104df | 3589 | |
b98e2969 AC |
3590 | -- Case 5: Special handling for aspects with an optional |
3591 | -- boolean argument. | |
dec6faf1 | 3592 | |
c8593453 | 3593 | -- In the delayed case, the corresponding pragma cannot be |
9d5598bf AC |
3594 | -- generated yet because the evaluation of the boolean needs |
3595 | -- to be delayed till the freeze point. | |
3596 | ||
d8f43ee6 HK |
3597 | when Boolean_Aspects |
3598 | | Library_Unit_Aspects | |
3599 | => | |
b98e2969 | 3600 | Set_Is_Boolean_Aspect (Aspect); |
9d6e4157 | 3601 | |
b98e2969 | 3602 | -- Lock_Free aspect only apply to protected objects |
4169b895 | 3603 | |
b98e2969 AC |
3604 | if A_Id = Aspect_Lock_Free then |
3605 | if Ekind (E) /= E_Protected_Type then | |
dc3af7e2 | 3606 | Error_Msg_Name_1 := Nam; |
9d6e4157 | 3607 | Error_Msg_N |
b98e2969 AC |
3608 | ("aspect % only applies to a protected object", |
3609 | Aspect); | |
3610 | ||
3611 | else | |
3612 | -- Set the Uses_Lock_Free flag to True if there is no | |
15e934bf | 3613 | -- expression or if the expression is True. The |
b98e2969 | 3614 | -- evaluation of this aspect should be delayed to the |
15e934bf | 3615 | -- freeze point (why???) |
b98e2969 | 3616 | |
eefd2467 AC |
3617 | if No (Expr) |
3618 | or else Is_True (Static_Boolean (Expr)) | |
b98e2969 AC |
3619 | then |
3620 | Set_Uses_Lock_Free (E); | |
3621 | end if; | |
2a290fec AC |
3622 | |
3623 | Record_Rep_Item (E, Aspect); | |
9d6e4157 | 3624 | end if; |
4169b895 | 3625 | |
b98e2969 | 3626 | goto Continue; |
0f1a6a0b | 3627 | |
2e885a6f AC |
3628 | elsif A_Id = Aspect_Export or else A_Id = Aspect_Import then |
3629 | Analyze_Aspect_Export_Import; | |
c8593453 AC |
3630 | |
3631 | -- Disable_Controlled | |
3632 | ||
3633 | elsif A_Id = Aspect_Disable_Controlled then | |
0cb81445 | 3634 | Analyze_Aspect_Disable_Controlled; |
b98e2969 AC |
3635 | goto Continue; |
3636 | end if; | |
c159409f | 3637 | |
15e934bf AC |
3638 | -- Library unit aspects require special handling in the case |
3639 | -- of a package declaration, the pragma needs to be inserted | |
3640 | -- in the list of declarations for the associated package. | |
3641 | -- There is no issue of visibility delay for these aspects. | |
a01b9df6 | 3642 | |
b98e2969 | 3643 | if A_Id in Library_Unit_Aspects |
7271429c AC |
3644 | and then |
3645 | Nkind_In (N, N_Package_Declaration, | |
3646 | N_Generic_Package_Declaration) | |
b98e2969 | 3647 | and then Nkind (Parent (N)) /= N_Compilation_Unit |
4d1429b2 AC |
3648 | |
3649 | -- Aspect is legal on a local instantiation of a library- | |
3650 | -- level generic unit. | |
3651 | ||
c9f95e4c | 3652 | and then not Is_Generic_Instance (Defining_Entity (N)) |
b98e2969 AC |
3653 | then |
3654 | Error_Msg_N | |
8894aa20 | 3655 | ("incorrect context for library unit aspect&", Id); |
b98e2969 AC |
3656 | goto Continue; |
3657 | end if; | |
ba759acd | 3658 | |
33c9f9af AC |
3659 | -- Cases where we do not delay, includes all cases where the |
3660 | -- expression is missing other than the above cases. | |
c159409f | 3661 | |
847d950d | 3662 | if not Delay_Required or else No (Expr) then |
2e885a6f AC |
3663 | |
3664 | -- Exclude aspects Export and Import because their pragma | |
3665 | -- syntax does not map directly to a Boolean aspect. | |
3666 | ||
3667 | if A_Id /= Aspect_Export | |
3668 | and then A_Id /= Aspect_Import | |
3669 | then | |
3670 | Make_Aitem_Pragma | |
3671 | (Pragma_Argument_Associations => New_List ( | |
3672 | Make_Pragma_Argument_Association (Sloc (Ent), | |
3673 | Expression => Ent)), | |
3674 | Pragma_Name => Chars (Id)); | |
3675 | end if; | |
3676 | ||
b98e2969 | 3677 | Delay_Required := False; |
1c54829e | 3678 | |
b98e2969 AC |
3679 | -- In general cases, the corresponding pragma/attribute |
3680 | -- definition clause will be inserted later at the freezing | |
2f6f8285 | 3681 | -- point, and we do not need to build it now. |
1c54829e | 3682 | |
b98e2969 AC |
3683 | else |
3684 | Aitem := Empty; | |
3685 | end if; | |
2cbac6c6 AC |
3686 | |
3687 | -- Storage_Size | |
3688 | ||
3689 | -- This is special because for access types we need to generate | |
3690 | -- an attribute definition clause. This also works for single | |
3691 | -- task declarations, but it does not work for task type | |
3692 | -- declarations, because we have the case where the expression | |
3693 | -- references a discriminant of the task type. That can't use | |
3694 | -- an attribute definition clause because we would not have | |
3695 | -- visibility on the discriminant. For that case we must | |
3696 | -- generate a pragma in the task definition. | |
3697 | ||
3698 | when Aspect_Storage_Size => | |
3699 | ||
3700 | -- Task type case | |
3701 | ||
3702 | if Ekind (E) = E_Task_Type then | |
3703 | declare | |
3704 | Decl : constant Node_Id := Declaration_Node (E); | |
3705 | ||
3706 | begin | |
3707 | pragma Assert (Nkind (Decl) = N_Task_Type_Declaration); | |
3708 | ||
3709 | -- If no task definition, create one | |
3710 | ||
3711 | if No (Task_Definition (Decl)) then | |
3712 | Set_Task_Definition (Decl, | |
3713 | Make_Task_Definition (Loc, | |
3714 | Visible_Declarations => Empty_List, | |
3715 | End_Label => Empty)); | |
3716 | end if; | |
3717 | ||
33c9f9af AC |
3718 | -- Create a pragma and put it at the start of the task |
3719 | -- definition for the task type declaration. | |
2cbac6c6 AC |
3720 | |
3721 | Make_Aitem_Pragma | |
3722 | (Pragma_Argument_Associations => New_List ( | |
3723 | Make_Pragma_Argument_Association (Loc, | |
3724 | Expression => Relocate_Node (Expr))), | |
3725 | Pragma_Name => Name_Storage_Size); | |
3726 | ||
3727 | Prepend | |
3728 | (Aitem, | |
3729 | Visible_Declarations (Task_Definition (Decl))); | |
3730 | goto Continue; | |
3731 | end; | |
3732 | ||
3733 | -- All other cases, generate attribute definition | |
3734 | ||
3735 | else | |
3736 | Aitem := | |
3737 | Make_Attribute_Definition_Clause (Loc, | |
3738 | Name => Ent, | |
3739 | Chars => Chars (Id), | |
3740 | Expression => Relocate_Node (Expr)); | |
3741 | end if; | |
b98e2969 | 3742 | end case; |
1c54829e | 3743 | |
b98e2969 AC |
3744 | -- Attach the corresponding pragma/attribute definition clause to |
3745 | -- the aspect specification node. | |
c159409f | 3746 | |
b98e2969 | 3747 | if Present (Aitem) then |
4e6768ab | 3748 | Set_From_Aspect_Specification (Aitem); |
b98e2969 | 3749 | end if; |
ca5af305 | 3750 | |
b98e2969 | 3751 | -- In the context of a compilation unit, we directly put the |
9d5598bf AC |
3752 | -- pragma in the Pragmas_After list of the N_Compilation_Unit_Aux |
3753 | -- node (no delay is required here) except for aspects on a | |
33c9f9af AC |
3754 | -- subprogram body (see below) and a generic package, for which we |
3755 | -- need to introduce the pragma before building the generic copy | |
3756 | -- (see sem_ch12), and for package instantiations, where the | |
3757 | -- library unit pragmas are better handled early. | |
1c54829e | 3758 | |
39af2bac | 3759 | if Nkind (Parent (N)) = N_Compilation_Unit |
b98e2969 AC |
3760 | and then (Present (Aitem) or else Is_Boolean_Aspect (Aspect)) |
3761 | then | |
3762 | declare | |
3763 | Aux : constant Node_Id := Aux_Decls_Node (Parent (N)); | |
2ef48385 | 3764 | |
b98e2969 AC |
3765 | begin |
3766 | pragma Assert (Nkind (Aux) = N_Compilation_Unit_Aux); | |
2ef48385 | 3767 | |
b98e2969 AC |
3768 | -- For a Boolean aspect, create the corresponding pragma if |
3769 | -- no expression or if the value is True. | |
2ef48385 | 3770 | |
616547fa | 3771 | if Is_Boolean_Aspect (Aspect) and then No (Aitem) then |
b98e2969 | 3772 | if Is_True (Static_Boolean (Expr)) then |
9d5598bf AC |
3773 | Make_Aitem_Pragma |
3774 | (Pragma_Argument_Associations => New_List ( | |
3775 | Make_Pragma_Argument_Association (Sloc (Ent), | |
3776 | Expression => Ent)), | |
3777 | Pragma_Name => Chars (Id)); | |
2ef48385 | 3778 | |
b98e2969 AC |
3779 | Set_From_Aspect_Specification (Aitem, True); |
3780 | Set_Corresponding_Aspect (Aitem, Aspect); | |
3781 | ||
3782 | else | |
3783 | goto Continue; | |
3784 | end if; | |
3785 | end if; | |
2ef48385 | 3786 | |
cf3b97ef AC |
3787 | -- If the aspect is on a subprogram body (relevant aspect |
3788 | -- is Inline), add the pragma in front of the declarations. | |
473e20df AC |
3789 | |
3790 | if Nkind (N) = N_Subprogram_Body then | |
3791 | if No (Declarations (N)) then | |
3792 | Set_Declarations (N, New_List); | |
3793 | end if; | |
3794 | ||
3795 | Prepend (Aitem, Declarations (N)); | |
3796 | ||
7271429c AC |
3797 | elsif Nkind (N) = N_Generic_Package_Declaration then |
3798 | if No (Visible_Declarations (Specification (N))) then | |
3799 | Set_Visible_Declarations (Specification (N), New_List); | |
3800 | end if; | |
3801 | ||
3802 | Prepend (Aitem, | |
3803 | Visible_Declarations (Specification (N))); | |
3804 | ||
f5da7a97 | 3805 | elsif Nkind (N) = N_Package_Instantiation then |
31dd3f4b ES |
3806 | declare |
3807 | Spec : constant Node_Id := | |
3808 | Specification (Instance_Spec (N)); | |
3809 | begin | |
3810 | if No (Visible_Declarations (Spec)) then | |
3811 | Set_Visible_Declarations (Spec, New_List); | |
3812 | end if; | |
3813 | ||
3814 | Prepend (Aitem, Visible_Declarations (Spec)); | |
3815 | end; | |
3816 | ||
473e20df AC |
3817 | else |
3818 | if No (Pragmas_After (Aux)) then | |
6a04272a | 3819 | Set_Pragmas_After (Aux, New_List); |
473e20df AC |
3820 | end if; |
3821 | ||
3822 | Append (Aitem, Pragmas_After (Aux)); | |
b98e2969 | 3823 | end if; |
2ef48385 | 3824 | |
b98e2969 AC |
3825 | goto Continue; |
3826 | end; | |
3827 | end if; | |
2ef48385 | 3828 | |
b98e2969 AC |
3829 | -- The evaluation of the aspect is delayed to the freezing point. |
3830 | -- The pragma or attribute clause if there is one is then attached | |
15e934bf | 3831 | -- to the aspect specification which is put in the rep item list. |
b8789727 | 3832 | |
b98e2969 AC |
3833 | if Delay_Required then |
3834 | if Present (Aitem) then | |
3835 | Set_Is_Delayed_Aspect (Aitem); | |
3836 | Set_Aspect_Rep_Item (Aspect, Aitem); | |
3837 | Set_Parent (Aitem, Aspect); | |
3838 | end if; | |
b8789727 | 3839 | |
b98e2969 | 3840 | Set_Is_Delayed_Aspect (Aspect); |
7b55fea6 | 3841 | |
289a994b AC |
3842 | -- In the case of Default_Value, link the aspect to base type |
3843 | -- as well, even though it appears on a first subtype. This is | |
3844 | -- mandated by the semantics of the aspect. Do not establish | |
3845 | -- the link when processing the base type itself as this leads | |
3846 | -- to a rep item circularity. Verify that we are dealing with | |
3847 | -- a scalar type to prevent cascaded errors. | |
3848 | ||
3849 | if A_Id = Aspect_Default_Value | |
3850 | and then Is_Scalar_Type (E) | |
3851 | and then Base_Type (E) /= E | |
3852 | then | |
7b55fea6 AC |
3853 | Set_Has_Delayed_Aspects (Base_Type (E)); |
3854 | Record_Rep_Item (Base_Type (E), Aspect); | |
3855 | end if; | |
3856 | ||
b98e2969 AC |
3857 | Set_Has_Delayed_Aspects (E); |
3858 | Record_Rep_Item (E, Aspect); | |
1c54829e | 3859 | |
80e59506 AC |
3860 | -- When delay is not required and the context is a package or a |
3861 | -- subprogram body, insert the pragma in the body declarations. | |
cdcf1c7a | 3862 | |
80e59506 | 3863 | elsif Nkind_In (N, N_Package_Body, N_Subprogram_Body) then |
cdcf1c7a AC |
3864 | if No (Declarations (N)) then |
3865 | Set_Declarations (N, New_List); | |
3866 | end if; | |
3867 | ||
3868 | -- The pragma is added before source declarations | |
3869 | ||
3870 | Prepend_To (Declarations (N), Aitem); | |
3871 | ||
b98e2969 AC |
3872 | -- When delay is not required and the context is not a compilation |
3873 | -- unit, we simply insert the pragma/attribute definition clause | |
3874 | -- in sequence. | |
1c54829e | 3875 | |
2e885a6f | 3876 | elsif Present (Aitem) then |
b98e2969 AC |
3877 | Insert_After (Ins_Node, Aitem); |
3878 | Ins_Node := Aitem; | |
c159409f | 3879 | end if; |
9d5598bf | 3880 | end Analyze_One_Aspect; |
0f1a6a0b | 3881 | |
a01b9df6 AC |
3882 | <<Continue>> |
3883 | Next (Aspect); | |
eaba57fb | 3884 | end loop Aspect_Loop; |
b98e2969 AC |
3885 | |
3886 | if Has_Delayed_Aspects (E) then | |
3887 | Ensure_Freeze_Node (E); | |
3888 | end if; | |
eaba57fb | 3889 | end Analyze_Aspect_Specifications; |
0f1a6a0b | 3890 | |
e9d08fd7 HK |
3891 | ------------------------------------------------ |
3892 | -- Analyze_Aspects_On_Subprogram_Body_Or_Stub -- | |
3893 | ------------------------------------------------ | |
caf07df9 | 3894 | |
e9d08fd7 | 3895 | procedure Analyze_Aspects_On_Subprogram_Body_Or_Stub (N : Node_Id) is |
caf07df9 AC |
3896 | Body_Id : constant Entity_Id := Defining_Entity (N); |
3897 | ||
3898 | procedure Diagnose_Misplaced_Aspects (Spec_Id : Entity_Id); | |
f99ff327 AC |
3899 | -- Body [stub] N has aspects, but they are not properly placed. Emit an |
3900 | -- error message depending on the aspects involved. Spec_Id denotes the | |
3901 | -- entity of the corresponding spec. | |
caf07df9 AC |
3902 | |
3903 | -------------------------------- | |
3904 | -- Diagnose_Misplaced_Aspects -- | |
3905 | -------------------------------- | |
3906 | ||
3907 | procedure Diagnose_Misplaced_Aspects (Spec_Id : Entity_Id) is | |
3908 | procedure Misplaced_Aspect_Error | |
3909 | (Asp : Node_Id; | |
3910 | Ref_Nam : Name_Id); | |
3911 | -- Emit an error message concerning misplaced aspect Asp. Ref_Nam is | |
3912 | -- the name of the refined version of the aspect. | |
3913 | ||
3914 | ---------------------------- | |
3915 | -- Misplaced_Aspect_Error -- | |
3916 | ---------------------------- | |
3917 | ||
3918 | procedure Misplaced_Aspect_Error | |
3919 | (Asp : Node_Id; | |
3920 | Ref_Nam : Name_Id) | |
3921 | is | |
3922 | Asp_Nam : constant Name_Id := Chars (Identifier (Asp)); | |
3923 | Asp_Id : constant Aspect_Id := Get_Aspect_Id (Asp_Nam); | |
3924 | ||
3925 | begin | |
3926 | -- The corresponding spec already contains the aspect in question | |
3927 | -- and the one appearing on the body must be the refined form: | |
3928 | ||
3929 | -- procedure P with Global ...; | |
3930 | -- procedure P with Global ... is ... end P; | |
3931 | -- ^ | |
3932 | -- Refined_Global | |
3933 | ||
3934 | if Has_Aspect (Spec_Id, Asp_Id) then | |
3935 | Error_Msg_Name_1 := Asp_Nam; | |
3936 | ||
3937 | -- Subunits cannot carry aspects that apply to a subprogram | |
3938 | -- declaration. | |
3939 | ||
3940 | if Nkind (Parent (N)) = N_Subunit then | |
3941 | Error_Msg_N ("aspect % cannot apply to a subunit", Asp); | |
3942 | ||
3943 | -- Otherwise suggest the refined form | |
3944 | ||
3945 | else | |
3946 | Error_Msg_Name_2 := Ref_Nam; | |
3947 | Error_Msg_N ("aspect % should be %", Asp); | |
3948 | end if; | |
3949 | ||
3950 | -- Otherwise the aspect must appear on the spec, not on the body | |
3951 | ||
3952 | -- procedure P; | |
3953 | -- procedure P with Global ... is ... end P; | |
3954 | ||
3955 | else | |
3956 | Error_Msg_N | |
f99ff327 | 3957 | ("aspect specification must appear on initial declaration", |
caf07df9 AC |
3958 | Asp); |
3959 | end if; | |
3960 | end Misplaced_Aspect_Error; | |
3961 | ||
3962 | -- Local variables | |
3963 | ||
3964 | Asp : Node_Id; | |
3965 | Asp_Nam : Name_Id; | |
3966 | ||
3967 | -- Start of processing for Diagnose_Misplaced_Aspects | |
3968 | ||
3969 | begin | |
3970 | -- Iterate over the aspect specifications and emit specific errors | |
3971 | -- where applicable. | |
3972 | ||
3973 | Asp := First (Aspect_Specifications (N)); | |
3974 | while Present (Asp) loop | |
3975 | Asp_Nam := Chars (Identifier (Asp)); | |
3976 | ||
3977 | -- Do not emit errors on aspects that can appear on a subprogram | |
3978 | -- body. This scenario occurs when the aspect specification list | |
3979 | -- contains both misplaced and properly placed aspects. | |
3980 | ||
3981 | if Aspect_On_Body_Or_Stub_OK (Get_Aspect_Id (Asp_Nam)) then | |
3982 | null; | |
3983 | ||
3984 | -- Special diagnostics for SPARK aspects | |
3985 | ||
3986 | elsif Asp_Nam = Name_Depends then | |
3987 | Misplaced_Aspect_Error (Asp, Name_Refined_Depends); | |
3988 | ||
3989 | elsif Asp_Nam = Name_Global then | |
3990 | Misplaced_Aspect_Error (Asp, Name_Refined_Global); | |
3991 | ||
3992 | elsif Asp_Nam = Name_Post then | |
3993 | Misplaced_Aspect_Error (Asp, Name_Refined_Post); | |
3994 | ||
3995 | -- Otherwise a language-defined aspect is misplaced | |
3996 | ||
3997 | else | |
3998 | Error_Msg_N | |
f99ff327 | 3999 | ("aspect specification must appear on initial declaration", |
caf07df9 AC |
4000 | Asp); |
4001 | end if; | |
4002 | ||
4003 | Next (Asp); | |
4004 | end loop; | |
4005 | end Diagnose_Misplaced_Aspects; | |
4006 | ||
4007 | -- Local variables | |
4008 | ||
f99ff327 | 4009 | Spec_Id : constant Entity_Id := Unique_Defining_Entity (N); |
caf07df9 | 4010 | |
e9d08fd7 | 4011 | -- Start of processing for Analyze_Aspects_On_Subprogram_Body_Or_Stub |
caf07df9 AC |
4012 | |
4013 | begin | |
caf07df9 AC |
4014 | -- Language-defined aspects cannot be associated with a subprogram body |
4015 | -- [stub] if the subprogram has a spec. Certain implementation defined | |
4016 | -- aspects are allowed to break this rule (for all applicable cases, see | |
4017 | -- table Aspects.Aspect_On_Body_Or_Stub_OK). | |
4018 | ||
f99ff327 | 4019 | if Spec_Id /= Body_Id and then not Aspects_On_Body_Or_Stub_OK (N) then |
caf07df9 AC |
4020 | Diagnose_Misplaced_Aspects (Spec_Id); |
4021 | else | |
4022 | Analyze_Aspect_Specifications (N, Body_Id); | |
4023 | end if; | |
e9d08fd7 | 4024 | end Analyze_Aspects_On_Subprogram_Body_Or_Stub; |
caf07df9 | 4025 | |
996ae0b0 RK |
4026 | ----------------------- |
4027 | -- Analyze_At_Clause -- | |
4028 | ----------------------- | |
4029 | ||
4030 | -- An at clause is replaced by the corresponding Address attribute | |
4031 | -- definition clause that is the preferred approach in Ada 95. | |
4032 | ||
4033 | procedure Analyze_At_Clause (N : Node_Id) is | |
45fc7ddb HK |
4034 | CS : constant Boolean := Comes_From_Source (N); |
4035 | ||
996ae0b0 | 4036 | begin |
45fc7ddb HK |
4037 | -- This is an obsolescent feature |
4038 | ||
5f3ab6fb AC |
4039 | Check_Restriction (No_Obsolescent_Features, N); |
4040 | ||
fbf5a39b AC |
4041 | if Warn_On_Obsolescent_Feature then |
4042 | Error_Msg_N | |
a3633438 | 4043 | ("?j?at clause is an obsolescent feature (RM J.7(2))", N); |
fbf5a39b | 4044 | Error_Msg_N |
a3633438 | 4045 | ("\?j?use address attribute definition clause instead", N); |
fbf5a39b AC |
4046 | end if; |
4047 | ||
45fc7ddb HK |
4048 | -- Rewrite as address clause |
4049 | ||
996ae0b0 RK |
4050 | Rewrite (N, |
4051 | Make_Attribute_Definition_Clause (Sloc (N), | |
c5d00db0 AC |
4052 | Name => Identifier (N), |
4053 | Chars => Name_Address, | |
996ae0b0 | 4054 | Expression => Expression (N))); |
45fc7ddb | 4055 | |
29ba9f52 RD |
4056 | -- We preserve Comes_From_Source, since logically the clause still comes |
4057 | -- from the source program even though it is changed in form. | |
45fc7ddb HK |
4058 | |
4059 | Set_Comes_From_Source (N, CS); | |
4060 | ||
4061 | -- Analyze rewritten clause | |
4062 | ||
996ae0b0 RK |
4063 | Analyze_Attribute_Definition_Clause (N); |
4064 | end Analyze_At_Clause; | |
4065 | ||
4066 | ----------------------------------------- | |
4067 | -- Analyze_Attribute_Definition_Clause -- | |
4068 | ----------------------------------------- | |
4069 | ||
4070 | procedure Analyze_Attribute_Definition_Clause (N : Node_Id) is | |
4071 | Loc : constant Source_Ptr := Sloc (N); | |
4072 | Nam : constant Node_Id := Name (N); | |
4073 | Attr : constant Name_Id := Chars (N); | |
4074 | Expr : constant Node_Id := Expression (N); | |
4075 | Id : constant Attribute_Id := Get_Attribute_Id (Attr); | |
a01b9df6 AC |
4076 | |
4077 | Ent : Entity_Id; | |
4078 | -- The entity of Nam after it is analyzed. In the case of an incomplete | |
4079 | -- type, this is the underlying type. | |
4080 | ||
996ae0b0 | 4081 | U_Ent : Entity_Id; |
a01b9df6 AC |
4082 | -- The underlying entity to which the attribute applies. Generally this |
4083 | -- is the Underlying_Type of Ent, except in the case where the clause | |
0e77949e AC |
4084 | -- applies to the full view of an incomplete or private type, in which |
4085 | -- case U_Ent is just a copy of Ent. | |
996ae0b0 RK |
4086 | |
4087 | FOnly : Boolean := False; | |
4088 | -- Reset to True for subtype specific attribute (Alignment, Size) | |
33c9f9af AC |
4089 | -- and for stream attributes, i.e. those cases where in the call to |
4090 | -- Rep_Item_Too_Late, FOnly is set True so that only the freezing rules | |
4091 | -- are checked. Note that the case of stream attributes is not clear | |
4092 | -- from the RM, but see AI95-00137. Also, the RM seems to disallow | |
4093 | -- Storage_Size for derived task types, but that is also clearly | |
4094 | -- unintentional. | |
996ae0b0 | 4095 | |
edd63e9b ES |
4096 | procedure Analyze_Stream_TSS_Definition (TSS_Nam : TSS_Name_Type); |
4097 | -- Common processing for 'Read, 'Write, 'Input and 'Output attribute | |
4098 | -- definition clauses. | |
4099 | ||
0f1a6a0b AC |
4100 | function Duplicate_Clause return Boolean; |
4101 | -- This routine checks if the aspect for U_Ent being given by attribute | |
4102 | -- definition clause N is for an aspect that has already been specified, | |
4103 | -- and if so gives an error message. If there is a duplicate, True is | |
4104 | -- returned, otherwise if there is no error, False is returned. | |
4105 | ||
d50f4827 AC |
4106 | procedure Check_Indexing_Functions; |
4107 | -- Check that the function in Constant_Indexing or Variable_Indexing | |
4108 | -- attribute has the proper type structure. If the name is overloaded, | |
2a7b8e18 | 4109 | -- check that some interpretation is legal. |
d50f4827 | 4110 | |
d941cee6 AC |
4111 | procedure Check_Iterator_Functions; |
4112 | -- Check that there is a single function in Default_Iterator attribute | |
b2c3160c | 4113 | -- that has the proper type structure. |
d941cee6 AC |
4114 | |
4115 | function Check_Primitive_Function (Subp : Entity_Id) return Boolean; | |
cb25faf8 | 4116 | -- Common legality check for the previous two |
d941cee6 | 4117 | |
45fc7ddb HK |
4118 | ----------------------------------- |
4119 | -- Analyze_Stream_TSS_Definition -- | |
4120 | ----------------------------------- | |
4121 | ||
edd63e9b ES |
4122 | procedure Analyze_Stream_TSS_Definition (TSS_Nam : TSS_Name_Type) is |
4123 | Subp : Entity_Id := Empty; | |
4124 | I : Interp_Index; | |
4125 | It : Interp; | |
4126 | Pnam : Entity_Id; | |
4127 | ||
4128 | Is_Read : constant Boolean := (TSS_Nam = TSS_Stream_Read); | |
876f1624 | 4129 | -- True for Read attribute, False for other attributes |
edd63e9b | 4130 | |
87feba05 AC |
4131 | function Has_Good_Profile |
4132 | (Subp : Entity_Id; | |
4133 | Report : Boolean := False) return Boolean; | |
edd63e9b | 4134 | -- Return true if the entity is a subprogram with an appropriate |
876f1624 AC |
4135 | -- profile for the attribute being defined. If result is False and |
4136 | -- Report is True, function emits appropriate error. | |
edd63e9b ES |
4137 | |
4138 | ---------------------- | |
4139 | -- Has_Good_Profile -- | |
4140 | ---------------------- | |
4141 | ||
87feba05 AC |
4142 | function Has_Good_Profile |
4143 | (Subp : Entity_Id; | |
4144 | Report : Boolean := False) return Boolean | |
4145 | is | |
edd63e9b ES |
4146 | Expected_Ekind : constant array (Boolean) of Entity_Kind := |
4147 | (False => E_Procedure, True => E_Function); | |
77039fe2 AC |
4148 | Is_Function : constant Boolean := (TSS_Nam = TSS_Stream_Input); |
4149 | F : Entity_Id; | |
edd63e9b ES |
4150 | Typ : Entity_Id; |
4151 | ||
4152 | begin | |
4153 | if Ekind (Subp) /= Expected_Ekind (Is_Function) then | |
4154 | return False; | |
4155 | end if; | |
4156 | ||
4157 | F := First_Formal (Subp); | |
4158 | ||
4159 | if No (F) | |
4160 | or else Ekind (Etype (F)) /= E_Anonymous_Access_Type | |
4161 | or else Designated_Type (Etype (F)) /= | |
77039fe2 | 4162 | Class_Wide_Type (RTE (RE_Root_Stream_Type)) |
edd63e9b ES |
4163 | then |
4164 | return False; | |
4165 | end if; | |
4166 | ||
4167 | if not Is_Function then | |
4168 | Next_Formal (F); | |
4169 | ||
4170 | declare | |
4171 | Expected_Mode : constant array (Boolean) of Entity_Kind := | |
4172 | (False => E_In_Parameter, | |
4173 | True => E_Out_Parameter); | |
4174 | begin | |
4175 | if Parameter_Mode (F) /= Expected_Mode (Is_Read) then | |
4176 | return False; | |
4177 | end if; | |
4178 | end; | |
4179 | ||
4180 | Typ := Etype (F); | |
4181 | ||
220d1fd9 | 4182 | -- If the attribute specification comes from an aspect |
33c9f9af AC |
4183 | -- specification for a class-wide stream, the parameter must be |
4184 | -- a class-wide type of the entity to which the aspect applies. | |
220d1fd9 AC |
4185 | |
4186 | if From_Aspect_Specification (N) | |
4187 | and then Class_Present (Parent (N)) | |
4188 | and then Is_Class_Wide_Type (Typ) | |
4189 | then | |
4190 | Typ := Etype (Typ); | |
4191 | end if; | |
4192 | ||
edd63e9b ES |
4193 | else |
4194 | Typ := Etype (Subp); | |
4195 | end if; | |
4196 | ||
33c9f9af | 4197 | -- Verify that the prefix of the attribute and the local name for |
d18b1548 AC |
4198 | -- the type of the formal match, or one is the class-wide of the |
4199 | -- other, in the case of a class-wide stream operation. | |
dda38714 | 4200 | |
9fe696a3 | 4201 | if Base_Type (Typ) = Base_Type (Ent) |
d18b1548 | 4202 | or else (Is_Class_Wide_Type (Typ) |
3fbbbd1e | 4203 | and then Typ = Class_Wide_Type (Base_Type (Ent))) |
72eaa365 AC |
4204 | or else (Is_Class_Wide_Type (Ent) |
4205 | and then Ent = Class_Wide_Type (Base_Type (Typ))) | |
d18b1548 AC |
4206 | then |
4207 | null; | |
4208 | else | |
4209 | return False; | |
4210 | end if; | |
4211 | ||
77039fe2 | 4212 | if Present (Next_Formal (F)) then |
dda38714 AC |
4213 | return False; |
4214 | ||
4215 | elsif not Is_Scalar_Type (Typ) | |
4216 | and then not Is_First_Subtype (Typ) | |
4217 | and then not Is_Class_Wide_Type (Typ) | |
4218 | then | |
87feba05 AC |
4219 | if Report and not Is_First_Subtype (Typ) then |
4220 | Error_Msg_N | |
876f1624 AC |
4221 | ("subtype of formal in stream operation must be a first " |
4222 | & "subtype", Parameter_Type (Parent (F))); | |
87feba05 AC |
4223 | end if; |
4224 | ||
dda38714 AC |
4225 | return False; |
4226 | ||
4227 | else | |
4228 | return True; | |
4229 | end if; | |
edd63e9b ES |
4230 | end Has_Good_Profile; |
4231 | ||
4232 | -- Start of processing for Analyze_Stream_TSS_Definition | |
4233 | ||
4234 | begin | |
4235 | FOnly := True; | |
4236 | ||
4237 | if not Is_Type (U_Ent) then | |
4238 | Error_Msg_N ("local name must be a subtype", Nam); | |
4239 | return; | |
dda38714 AC |
4240 | |
4241 | elsif not Is_First_Subtype (U_Ent) then | |
4242 | Error_Msg_N ("local name must be a first subtype", Nam); | |
4243 | return; | |
edd63e9b ES |
4244 | end if; |
4245 | ||
4246 | Pnam := TSS (Base_Type (U_Ent), TSS_Nam); | |
4247 | ||
affbee12 RD |
4248 | -- If Pnam is present, it can be either inherited from an ancestor |
4249 | -- type (in which case it is legal to redefine it for this type), or | |
4250 | -- be a previous definition of the attribute for the same type (in | |
4251 | -- which case it is illegal). | |
4252 | ||
4253 | -- In the first case, it will have been analyzed already, and we | |
4254 | -- can check that its profile does not match the expected profile | |
4255 | -- for a stream attribute of U_Ent. In the second case, either Pnam | |
4256 | -- has been analyzed (and has the expected profile), or it has not | |
4257 | -- been analyzed yet (case of a type that has not been frozen yet | |
4258 | -- and for which the stream attribute has been set using Set_TSS). | |
4259 | ||
4260 | if Present (Pnam) | |
4261 | and then (No (First_Entity (Pnam)) or else Has_Good_Profile (Pnam)) | |
4262 | then | |
edd63e9b ES |
4263 | Error_Msg_Sloc := Sloc (Pnam); |
4264 | Error_Msg_Name_1 := Attr; | |
4265 | Error_Msg_N ("% attribute already defined #", Nam); | |
4266 | return; | |
4267 | end if; | |
4268 | ||
4269 | Analyze (Expr); | |
4270 | ||
4271 | if Is_Entity_Name (Expr) then | |
4272 | if not Is_Overloaded (Expr) then | |
87feba05 | 4273 | if Has_Good_Profile (Entity (Expr), Report => True) then |
edd63e9b ES |
4274 | Subp := Entity (Expr); |
4275 | end if; | |
4276 | ||
4277 | else | |
4278 | Get_First_Interp (Expr, I, It); | |
edd63e9b ES |
4279 | while Present (It.Nam) loop |
4280 | if Has_Good_Profile (It.Nam) then | |
4281 | Subp := It.Nam; | |
4282 | exit; | |
4283 | end if; | |
4284 | ||
4285 | Get_Next_Interp (I, It); | |
4286 | end loop; | |
4287 | end if; | |
4288 | end if; | |
4289 | ||
4290 | if Present (Subp) then | |
a9a5b8ac | 4291 | if Is_Abstract_Subprogram (Subp) then |
edd63e9b ES |
4292 | Error_Msg_N ("stream subprogram must not be abstract", Expr); |
4293 | return; | |
3e65bfab | 4294 | |
5c5e108f | 4295 | -- A stream subprogram for an interface type must be a null |
6dc87f5f AC |
4296 | -- procedure (RM 13.13.2 (38/3)). Note that the class-wide type |
4297 | -- of an interface is not an interface type (3.9.4 (6.b/2)). | |
3e65bfab AC |
4298 | |
4299 | elsif Is_Interface (U_Ent) | |
d18b1548 | 4300 | and then not Is_Class_Wide_Type (U_Ent) |
3e65bfab | 4301 | and then not Inside_A_Generic |
3e65bfab | 4302 | and then |
d18b1548 AC |
4303 | (Ekind (Subp) = E_Function |
4304 | or else | |
4305 | not Null_Present | |
3fbbbd1e AC |
4306 | (Specification |
4307 | (Unit_Declaration_Node (Ultimate_Alias (Subp))))) | |
3e65bfab AC |
4308 | then |
4309 | Error_Msg_N | |
77039fe2 AC |
4310 | ("stream subprogram for interface type must be null " |
4311 | & "procedure", Expr); | |
edd63e9b ES |
4312 | end if; |
4313 | ||
4314 | Set_Entity (Expr, Subp); | |
4315 | Set_Etype (Expr, Etype (Subp)); | |
4316 | ||
affbee12 | 4317 | New_Stream_Subprogram (N, U_Ent, Subp, TSS_Nam); |
edd63e9b ES |
4318 | |
4319 | else | |
4320 | Error_Msg_Name_1 := Attr; | |
4321 | Error_Msg_N ("incorrect expression for% attribute", Expr); | |
4322 | end if; | |
4323 | end Analyze_Stream_TSS_Definition; | |
4324 | ||
d50f4827 AC |
4325 | ------------------------------ |
4326 | -- Check_Indexing_Functions -- | |
4327 | ------------------------------ | |
4328 | ||
4329 | procedure Check_Indexing_Functions is | |
7b536495 | 4330 | Indexing_Found : Boolean := False; |
d986066d | 4331 | |
8c14315a ES |
4332 | procedure Check_Inherited_Indexing; |
4333 | -- For a derived type, check that no indexing aspect is specified | |
4334 | -- for the type if it is also inherited | |
4335 | ||
d50f4827 | 4336 | procedure Check_One_Function (Subp : Entity_Id); |
d7a93e45 AC |
4337 | -- Check one possible interpretation. Sets Indexing_Found True if a |
4338 | -- legal indexing function is found. | |
d50f4827 | 4339 | |
f3296dd3 AC |
4340 | procedure Illegal_Indexing (Msg : String); |
4341 | -- Diagnose illegal indexing function if not overloaded. In the | |
4342 | -- overloaded case indicate that no legal interpretation exists. | |
4343 | ||
8c14315a ES |
4344 | ------------------------------ |
4345 | -- Check_Inherited_Indexing -- | |
4346 | ------------------------------ | |
4347 | ||
4348 | procedure Check_Inherited_Indexing is | |
4349 | Inherited : Node_Id; | |
4350 | ||
4351 | begin | |
4352 | if Attr = Name_Constant_Indexing then | |
4353 | Inherited := | |
4354 | Find_Aspect (Etype (Ent), Aspect_Constant_Indexing); | |
4355 | else pragma Assert (Attr = Name_Variable_Indexing); | |
4356 | Inherited := | |
4357 | Find_Aspect (Etype (Ent), Aspect_Variable_Indexing); | |
4358 | end if; | |
4359 | ||
4360 | if Present (Inherited) then | |
4361 | if Debug_Flag_Dot_XX then | |
4362 | null; | |
4363 | ||
078b1a5f AC |
4364 | -- OK if current attribute_definition_clause is expansion of |
4365 | -- inherited aspect. | |
8c14315a ES |
4366 | |
4367 | elsif Aspect_Rep_Item (Inherited) = N then | |
4368 | null; | |
4369 | ||
078b1a5f AC |
4370 | -- Indicate the operation that must be overridden, rather than |
4371 | -- redefining the indexing aspect. | |
8c14315a ES |
4372 | |
4373 | else | |
4374 | Illegal_Indexing | |
a9fdbccb | 4375 | ("indexing function already inherited from parent type"); |
8c14315a ES |
4376 | Error_Msg_NE |
4377 | ("!override & instead", | |
4378 | N, Entity (Expression (Inherited))); | |
4379 | end if; | |
4380 | end if; | |
4381 | end Check_Inherited_Indexing; | |
4382 | ||
d50f4827 AC |
4383 | ------------------------ |
4384 | -- Check_One_Function -- | |
4385 | ------------------------ | |
4386 | ||
4387 | procedure Check_One_Function (Subp : Entity_Id) is | |
f3296dd3 AC |
4388 | Default_Element : Node_Id; |
4389 | Ret_Type : constant Entity_Id := Etype (Subp); | |
76d49f49 | 4390 | |
d50f4827 | 4391 | begin |
f3296dd3 AC |
4392 | if not Is_Overloadable (Subp) then |
4393 | Illegal_Indexing ("illegal indexing function for type&"); | |
4394 | return; | |
4395 | ||
d7a93e45 AC |
4396 | elsif Scope (Subp) /= Scope (Ent) then |
4397 | if Nkind (Expr) = N_Expanded_Name then | |
4398 | ||
4399 | -- Indexing function can't be declared elsewhere | |
4400 | ||
4401 | Illegal_Indexing | |
4402 | ("indexing function must be declared in scope of type&"); | |
4403 | end if; | |
4404 | ||
f3296dd3 AC |
4405 | return; |
4406 | ||
4407 | elsif No (First_Formal (Subp)) then | |
4408 | Illegal_Indexing | |
4409 | ("Indexing requires a function that applies to type&"); | |
4410 | return; | |
4411 | ||
4412 | elsif No (Next_Formal (First_Formal (Subp))) then | |
4413 | Illegal_Indexing | |
eb9008b7 | 4414 | ("indexing function must have at least two parameters"); |
f3296dd3 AC |
4415 | return; |
4416 | ||
4417 | elsif Is_Derived_Type (Ent) then | |
8c14315a | 4418 | Check_Inherited_Indexing; |
f3296dd3 AC |
4419 | end if; |
4420 | ||
eefd2467 | 4421 | if not Check_Primitive_Function (Subp) then |
f3296dd3 AC |
4422 | Illegal_Indexing |
4423 | ("Indexing aspect requires a function that applies to type&"); | |
4424 | return; | |
d50f4827 AC |
4425 | end if; |
4426 | ||
d7a93e45 AC |
4427 | -- If partial declaration exists, verify that it is not tagged. |
4428 | ||
4429 | if Ekind (Current_Scope) = E_Package | |
4430 | and then Has_Private_Declaration (Ent) | |
4431 | and then From_Aspect_Specification (N) | |
fd7215d7 AC |
4432 | and then |
4433 | List_Containing (Parent (Ent)) = | |
4434 | Private_Declarations | |
d7a93e45 AC |
4435 | (Specification (Unit_Declaration_Node (Current_Scope))) |
4436 | and then Nkind (N) = N_Attribute_Definition_Clause | |
4437 | then | |
4438 | declare | |
4439 | Decl : Node_Id; | |
4440 | ||
4441 | begin | |
4442 | Decl := | |
4443 | First (Visible_Declarations | |
fd7215d7 AC |
4444 | (Specification |
4445 | (Unit_Declaration_Node (Current_Scope)))); | |
d7a93e45 AC |
4446 | |
4447 | while Present (Decl) loop | |
4448 | if Nkind (Decl) = N_Private_Type_Declaration | |
4449 | and then Ent = Full_View (Defining_Identifier (Decl)) | |
4450 | and then Tagged_Present (Decl) | |
4451 | and then No (Aspect_Specifications (Decl)) | |
4452 | then | |
4453 | Illegal_Indexing | |
4454 | ("Indexing aspect cannot be specified on full view " | |
fd7215d7 | 4455 | & "if partial view is tagged"); |
d7a93e45 AC |
4456 | return; |
4457 | end if; | |
4458 | ||
4459 | Next (Decl); | |
4460 | end loop; | |
4461 | end; | |
4462 | end if; | |
4463 | ||
76d49f49 | 4464 | -- An indexing function must return either the default element of |
2a7b8e18 | 4465 | -- the container, or a reference type. For variable indexing it |
9a6dc470 | 4466 | -- must be the latter. |
76d49f49 | 4467 | |
f3296dd3 AC |
4468 | Default_Element := |
4469 | Find_Value_Of_Aspect | |
4470 | (Etype (First_Formal (Subp)), Aspect_Iterator_Element); | |
4471 | ||
76d49f49 ES |
4472 | if Present (Default_Element) then |
4473 | Analyze (Default_Element); | |
76d49f49 ES |
4474 | end if; |
4475 | ||
9a6dc470 | 4476 | -- For variable_indexing the return type must be a reference type |
76d49f49 | 4477 | |
f3296dd3 AC |
4478 | if Attr = Name_Variable_Indexing then |
4479 | if not Has_Implicit_Dereference (Ret_Type) then | |
4480 | Illegal_Indexing | |
4481 | ("variable indexing must return a reference type"); | |
4482 | return; | |
4483 | ||
35e7063a AC |
4484 | elsif Is_Access_Constant |
4485 | (Etype (First_Discriminant (Ret_Type))) | |
f3296dd3 AC |
4486 | then |
4487 | Illegal_Indexing | |
4488 | ("variable indexing must return an access to variable"); | |
4489 | return; | |
4490 | end if; | |
2a7b8e18 AC |
4491 | |
4492 | else | |
f3296dd3 AC |
4493 | if Has_Implicit_Dereference (Ret_Type) |
4494 | and then not | |
4495 | Is_Access_Constant (Etype (First_Discriminant (Ret_Type))) | |
4496 | then | |
4497 | Illegal_Indexing | |
4498 | ("constant indexing must return an access to constant"); | |
4499 | return; | |
4500 | ||
4501 | elsif Is_Access_Type (Etype (First_Formal (Subp))) | |
4502 | and then not Is_Access_Constant (Etype (First_Formal (Subp))) | |
4503 | then | |
4504 | Illegal_Indexing | |
4505 | ("constant indexing must apply to an access to constant"); | |
4506 | return; | |
4507 | end if; | |
d50f4827 | 4508 | end if; |
f3296dd3 AC |
4509 | |
4510 | -- All checks succeeded. | |
4511 | ||
4512 | Indexing_Found := True; | |
d50f4827 AC |
4513 | end Check_One_Function; |
4514 | ||
f3296dd3 AC |
4515 | ----------------------- |
4516 | -- Illegal_Indexing -- | |
4517 | ----------------------- | |
4518 | ||
4519 | procedure Illegal_Indexing (Msg : String) is | |
4520 | begin | |
d7a93e45 | 4521 | Error_Msg_NE (Msg, N, Ent); |
f3296dd3 AC |
4522 | end Illegal_Indexing; |
4523 | ||
d50f4827 AC |
4524 | -- Start of processing for Check_Indexing_Functions |
4525 | ||
4526 | begin | |
d941cee6 | 4527 | if In_Instance then |
8c14315a | 4528 | Check_Inherited_Indexing; |
d941cee6 AC |
4529 | end if; |
4530 | ||
d50f4827 AC |
4531 | Analyze (Expr); |
4532 | ||
4533 | if not Is_Overloaded (Expr) then | |
4534 | Check_One_Function (Entity (Expr)); | |
4535 | ||
4536 | else | |
4537 | declare | |
b26f70a0 | 4538 | I : Interp_Index; |
d50f4827 AC |
4539 | It : Interp; |
4540 | ||
4541 | begin | |
2a7b8e18 | 4542 | Indexing_Found := False; |
d50f4827 AC |
4543 | Get_First_Interp (Expr, I, It); |
4544 | while Present (It.Nam) loop | |
4545 | ||
4546 | -- Note that analysis will have added the interpretation | |
4547 | -- that corresponds to the dereference. We only check the | |
a267d8cc AC |
4548 | -- subprogram itself. Ignore homonyms that may come from |
4549 | -- derived types in the context. | |
d50f4827 | 4550 | |
a267d8cc AC |
4551 | if Is_Overloadable (It.Nam) |
4552 | and then Comes_From_Source (It.Nam) | |
4553 | then | |
4554 | Check_One_Function (It.Nam); | |
d50f4827 AC |
4555 | end if; |
4556 | ||
4557 | Get_Next_Interp (I, It); | |
4558 | end loop; | |
4559 | end; | |
4560 | end if; | |
d7a93e45 | 4561 | |
fd7215d7 | 4562 | if not Indexing_Found and then not Error_Posted (N) then |
d7a93e45 | 4563 | Error_Msg_NE |
a267d8cc AC |
4564 | ("aspect Indexing requires a local function that applies to " |
4565 | & "type&", Expr, Ent); | |
d7a93e45 | 4566 | end if; |
d50f4827 AC |
4567 | end Check_Indexing_Functions; |
4568 | ||
d941cee6 AC |
4569 | ------------------------------ |
4570 | -- Check_Iterator_Functions -- | |
4571 | ------------------------------ | |
4572 | ||
4573 | procedure Check_Iterator_Functions is | |
d941cee6 | 4574 | function Valid_Default_Iterator (Subp : Entity_Id) return Boolean; |
d986066d | 4575 | -- Check one possible interpretation for validity |
d941cee6 AC |
4576 | |
4577 | ---------------------------- | |
4578 | -- Valid_Default_Iterator -- | |
4579 | ---------------------------- | |
4580 | ||
4581 | function Valid_Default_Iterator (Subp : Entity_Id) return Boolean is | |
437244c7 | 4582 | Root_T : constant Entity_Id := Root_Type (Etype (Etype (Subp))); |
3702225c | 4583 | Formal : Entity_Id; |
d941cee6 AC |
4584 | |
4585 | begin | |
4586 | if not Check_Primitive_Function (Subp) then | |
4587 | return False; | |
437244c7 AC |
4588 | |
4589 | -- The return type must be derived from a type in an instance | |
4590 | -- of Iterator.Interfaces, and thus its root type must have a | |
4591 | -- predefined name. | |
4592 | ||
4593 | elsif Chars (Root_T) /= Name_Forward_Iterator | |
4594 | and then Chars (Root_T) /= Name_Reversible_Iterator | |
4595 | then | |
4596 | return False; | |
4597 | ||
d941cee6 AC |
4598 | else |
4599 | Formal := First_Formal (Subp); | |
4600 | end if; | |
4601 | ||
d986066d | 4602 | -- False if any subsequent formal has no default expression |
d941cee6 | 4603 | |
d986066d AC |
4604 | Formal := Next_Formal (Formal); |
4605 | while Present (Formal) loop | |
4606 | if No (Expression (Parent (Formal))) then | |
4607 | return False; | |
4608 | end if; | |
d941cee6 | 4609 | |
d986066d AC |
4610 | Next_Formal (Formal); |
4611 | end loop; | |
d941cee6 | 4612 | |
d986066d | 4613 | -- True if all subsequent formals have default expressions |
d941cee6 AC |
4614 | |
4615 | return True; | |
4616 | end Valid_Default_Iterator; | |
4617 | ||
4618 | -- Start of processing for Check_Iterator_Functions | |
4619 | ||
4620 | begin | |
4621 | Analyze (Expr); | |
4622 | ||
4623 | if not Is_Entity_Name (Expr) then | |
4624 | Error_Msg_N ("aspect Iterator must be a function name", Expr); | |
4625 | end if; | |
4626 | ||
4627 | if not Is_Overloaded (Expr) then | |
4628 | if not Check_Primitive_Function (Entity (Expr)) then | |
4629 | Error_Msg_NE | |
4630 | ("aspect Indexing requires a function that applies to type&", | |
4631 | Entity (Expr), Ent); | |
4632 | end if; | |
4633 | ||
4f2cae4a ES |
4634 | -- Flag the default_iterator as well as the denoted function. |
4635 | ||
d941cee6 | 4636 | if not Valid_Default_Iterator (Entity (Expr)) then |
4f2cae4a | 4637 | Error_Msg_N ("improper function for default iterator!", Expr); |
d941cee6 AC |
4638 | end if; |
4639 | ||
4640 | else | |
d941cee6 | 4641 | declare |
02886c2e | 4642 | Default : Entity_Id := Empty; |
77237288 AC |
4643 | I : Interp_Index; |
4644 | It : Interp; | |
d941cee6 AC |
4645 | |
4646 | begin | |
4647 | Get_First_Interp (Expr, I, It); | |
4648 | while Present (It.Nam) loop | |
4649 | if not Check_Primitive_Function (It.Nam) | |
57a8057a | 4650 | or else not Valid_Default_Iterator (It.Nam) |
d941cee6 AC |
4651 | then |
4652 | Remove_Interp (I); | |
4653 | ||
4654 | elsif Present (Default) then | |
d941cee6 | 4655 | |
77237288 AC |
4656 | -- An explicit one should override an implicit one |
4657 | ||
4658 | if Comes_From_Source (Default) = | |
4659 | Comes_From_Source (It.Nam) | |
4660 | then | |
4661 | Error_Msg_N ("default iterator must be unique", Expr); | |
4662 | Error_Msg_Sloc := Sloc (Default); | |
4663 | Error_Msg_N ("\\possible interpretation#", Expr); | |
4664 | Error_Msg_Sloc := Sloc (It.Nam); | |
4665 | Error_Msg_N ("\\possible interpretation#", Expr); | |
4666 | ||
4667 | elsif Comes_From_Source (It.Nam) then | |
4668 | Default := It.Nam; | |
4669 | end if; | |
d941cee6 AC |
4670 | else |
4671 | Default := It.Nam; | |
4672 | end if; | |
4673 | ||
4674 | Get_Next_Interp (I, It); | |
4675 | end loop; | |
d941cee6 | 4676 | |
02886c2e AC |
4677 | if Present (Default) then |
4678 | Set_Entity (Expr, Default); | |
4679 | Set_Is_Overloaded (Expr, False); | |
437244c7 AC |
4680 | else |
4681 | Error_Msg_N | |
3702225c | 4682 | ("no interpretation is a valid default iterator!", Expr); |
02886c2e AC |
4683 | end if; |
4684 | end; | |
d941cee6 AC |
4685 | end if; |
4686 | end Check_Iterator_Functions; | |
4687 | ||
4688 | ------------------------------- | |
4689 | -- Check_Primitive_Function -- | |
4690 | ------------------------------- | |
4691 | ||
4692 | function Check_Primitive_Function (Subp : Entity_Id) return Boolean is | |
4693 | Ctrl : Entity_Id; | |
4694 | ||
4695 | begin | |
4696 | if Ekind (Subp) /= E_Function then | |
4697 | return False; | |
4698 | end if; | |
4699 | ||
4700 | if No (First_Formal (Subp)) then | |
4701 | return False; | |
4702 | else | |
4703 | Ctrl := Etype (First_Formal (Subp)); | |
4704 | end if; | |
4705 | ||
4f2cae4a ES |
4706 | -- To be a primitive operation subprogram has to be in same scope. |
4707 | ||
4708 | if Scope (Ctrl) /= Scope (Subp) then | |
4709 | return False; | |
4710 | end if; | |
4711 | ||
3e1862b1 ES |
4712 | -- Type of formal may be the class-wide type, an access to such, |
4713 | -- or an incomplete view. | |
4714 | ||
d941cee6 AC |
4715 | if Ctrl = Ent |
4716 | or else Ctrl = Class_Wide_Type (Ent) | |
4717 | or else | |
4718 | (Ekind (Ctrl) = E_Anonymous_Access_Type | |
2e215573 RD |
4719 | and then (Designated_Type (Ctrl) = Ent |
4720 | or else | |
4721 | Designated_Type (Ctrl) = Class_Wide_Type (Ent))) | |
3e1862b1 ES |
4722 | or else |
4723 | (Ekind (Ctrl) = E_Incomplete_Type | |
4724 | and then Full_View (Ctrl) = Ent) | |
d941cee6 AC |
4725 | then |
4726 | null; | |
d941cee6 AC |
4727 | else |
4728 | return False; | |
4729 | end if; | |
4730 | ||
4731 | return True; | |
4732 | end Check_Primitive_Function; | |
4733 | ||
0f1a6a0b AC |
4734 | ---------------------- |
4735 | -- Duplicate_Clause -- | |
4736 | ---------------------- | |
4737 | ||
4738 | function Duplicate_Clause return Boolean is | |
c159409f | 4739 | A : Node_Id; |
0f1a6a0b AC |
4740 | |
4741 | begin | |
1928f450 AC |
4742 | -- Nothing to do if this attribute definition clause comes from |
4743 | -- an aspect specification, since we could not be duplicating an | |
0f1a6a0b AC |
4744 | -- explicit clause, and we dealt with the case of duplicated aspects |
4745 | -- in Analyze_Aspect_Specifications. | |
4746 | ||
4747 | if From_Aspect_Specification (N) then | |
4748 | return False; | |
4749 | end if; | |
4750 | ||
b98e2969 AC |
4751 | -- Otherwise current clause may duplicate previous clause, or a |
4752 | -- previously given pragma or aspect specification for the same | |
4753 | -- aspect. | |
c159409f | 4754 | |
34f3a701 | 4755 | A := Get_Rep_Item (U_Ent, Chars (N), Check_Parents => False); |
0f1a6a0b AC |
4756 | |
4757 | if Present (A) then | |
b98e2969 AC |
4758 | Error_Msg_Name_1 := Chars (N); |
4759 | Error_Msg_Sloc := Sloc (A); | |
4760 | ||
34f3a701 | 4761 | Error_Msg_NE ("aspect% for & previously given#", N, U_Ent); |
b98e2969 | 4762 | return True; |
0f1a6a0b AC |
4763 | end if; |
4764 | ||
4765 | return False; | |
4766 | end Duplicate_Clause; | |
4767 | ||
edd63e9b ES |
4768 | -- Start of processing for Analyze_Attribute_Definition_Clause |
4769 | ||
996ae0b0 | 4770 | begin |
a01b9df6 | 4771 | -- The following code is a defense against recursion. Not clear that |
33c9f9af AC |
4772 | -- this can happen legitimately, but perhaps some error situations can |
4773 | -- cause it, and we did see this recursion during testing. | |
a01b9df6 AC |
4774 | |
4775 | if Analyzed (N) then | |
4776 | return; | |
4777 | else | |
4778 | Set_Analyzed (N, True); | |
4779 | end if; | |
4780 | ||
58ba2415 HK |
4781 | Check_Restriction_No_Use_Of_Attribute (N); |
4782 | ||
5ebfaacf AC |
4783 | -- Ignore some selected attributes in CodePeer mode since they are not |
4784 | -- relevant in this context. | |
4785 | ||
4786 | if CodePeer_Mode then | |
4787 | case Id is | |
4788 | ||
4789 | -- Ignore Component_Size in CodePeer mode, to avoid changing the | |
4790 | -- internal representation of types by implicitly packing them. | |
4791 | ||
4792 | when Attribute_Component_Size => | |
4793 | Rewrite (N, Make_Null_Statement (Sloc (N))); | |
4794 | return; | |
4795 | ||
4796 | when others => | |
4797 | null; | |
4798 | end case; | |
4799 | end if; | |
4800 | ||
1c163178 | 4801 | -- Process Ignore_Rep_Clauses option |
55c078ac | 4802 | |
1c163178 | 4803 | if Ignore_Rep_Clauses then |
70b70ce8 AC |
4804 | case Id is |
4805 | ||
55c078ac AC |
4806 | -- The following should be ignored. They do not affect legality |
4807 | -- and may be target dependent. The basic idea of -gnatI is to | |
4808 | -- ignore any rep clauses that may be target dependent but do not | |
4809 | -- affect legality (except possibly to be rejected because they | |
4810 | -- are incompatible with the compilation target). | |
70b70ce8 | 4811 | |
d8f43ee6 HK |
4812 | when Attribute_Alignment |
4813 | | Attribute_Bit_Order | |
4814 | | Attribute_Component_Size | |
7a71a7c4 | 4815 | | Attribute_Default_Scalar_Storage_Order |
d8f43ee6 HK |
4816 | | Attribute_Machine_Radix |
4817 | | Attribute_Object_Size | |
7a71a7c4 | 4818 | | Attribute_Scalar_Storage_Order |
d8f43ee6 HK |
4819 | | Attribute_Size |
4820 | | Attribute_Small | |
4821 | | Attribute_Stream_Size | |
4822 | | Attribute_Value_Size | |
4823 | => | |
cf28c974 | 4824 | Kill_Rep_Clause (N); |
70b70ce8 AC |
4825 | return; |
4826 | ||
55c078ac | 4827 | -- The following should not be ignored, because in the first place |
33c9f9af AC |
4828 | -- they are reasonably portable, and should not cause problems |
4829 | -- in compiling code from another target, and also they do affect | |
4830 | -- legality, e.g. failing to provide a stream attribute for a type | |
4831 | -- may make a program illegal. | |
70b70ce8 | 4832 | |
d8f43ee6 HK |
4833 | when Attribute_External_Tag |
4834 | | Attribute_Input | |
4835 | | Attribute_Output | |
4836 | | Attribute_Read | |
4837 | | Attribute_Simple_Storage_Pool | |
4838 | | Attribute_Storage_Pool | |
4839 | | Attribute_Storage_Size | |
4840 | | Attribute_Write | |
4841 | => | |
70b70ce8 AC |
4842 | null; |
4843 | ||
cf28c974 RD |
4844 | -- We do not do anything here with address clauses, they will be |
4845 | -- removed by Freeze later on, but for now, it works better to | |
c1025b4e | 4846 | -- keep them in the tree. |
cf28c974 RD |
4847 | |
4848 | when Attribute_Address => | |
4849 | null; | |
4850 | ||
b91fccb3 BD |
4851 | -- Other cases are errors ("attribute& cannot be set with |
4852 | -- definition clause"), which will be caught below. | |
70b70ce8 AC |
4853 | |
4854 | when others => | |
4855 | null; | |
4856 | end case; | |
c690a2ec RD |
4857 | end if; |
4858 | ||
996ae0b0 RK |
4859 | Analyze (Nam); |
4860 | Ent := Entity (Nam); | |
4861 | ||
4862 | if Rep_Item_Too_Early (Ent, N) then | |
4863 | return; | |
4864 | end if; | |
4865 | ||
edd63e9b ES |
4866 | -- Rep clause applies to full view of incomplete type or private type if |
4867 | -- we have one (if not, this is a premature use of the type). However, | |
4868 | -- certain semantic checks need to be done on the specified entity (i.e. | |
4869 | -- the private view), so we save it in Ent. | |
996ae0b0 RK |
4870 | |
4871 | if Is_Private_Type (Ent) | |
4872 | and then Is_Derived_Type (Ent) | |
4873 | and then not Is_Tagged_Type (Ent) | |
4874 | and then No (Full_View (Ent)) | |
4875 | then | |
edd63e9b ES |
4876 | -- If this is a private type whose completion is a derivation from |
4877 | -- another private type, there is no full view, and the attribute | |
4878 | -- belongs to the type itself, not its underlying parent. | |
996ae0b0 RK |
4879 | |
4880 | U_Ent := Ent; | |
4881 | ||
4882 | elsif Ekind (Ent) = E_Incomplete_Type then | |
b7e429ab | 4883 | |
edd63e9b ES |
4884 | -- The attribute applies to the full view, set the entity of the |
4885 | -- attribute definition accordingly. | |
b7e429ab | 4886 | |
996ae0b0 RK |
4887 | Ent := Underlying_Type (Ent); |
4888 | U_Ent := Ent; | |
b7e429ab AC |
4889 | Set_Entity (Nam, Ent); |
4890 | ||
996ae0b0 RK |
4891 | else |
4892 | U_Ent := Underlying_Type (Ent); | |
4893 | end if; | |
4894 | ||
54c04d6c | 4895 | -- Avoid cascaded error |
996ae0b0 RK |
4896 | |
4897 | if Etype (Nam) = Any_Type then | |
4898 | return; | |
4899 | ||
b98e2969 | 4900 | -- Must be declared in current scope or in case of an aspect |
5eeeed5e | 4901 | -- specification, must be visible in current scope. |
54c04d6c | 4902 | |
b98e2969 | 4903 | elsif Scope (Ent) /= Current_Scope |
5eeeed5e AC |
4904 | and then |
4905 | not (From_Aspect_Specification (N) | |
4906 | and then Scope_Within_Or_Same (Current_Scope, Scope (Ent))) | |
b98e2969 | 4907 | then |
996ae0b0 RK |
4908 | Error_Msg_N ("entity must be declared in this scope", Nam); |
4909 | return; | |
4910 | ||
54c04d6c AC |
4911 | -- Must not be a source renaming (we do have some cases where the |
4912 | -- expander generates a renaming, and those cases are OK, in such | |
51e641f8 | 4913 | -- cases any attribute applies to the renamed object as well). |
54c04d6c AC |
4914 | |
4915 | elsif Is_Object (Ent) | |
4916 | and then Present (Renamed_Object (Ent)) | |
54c04d6c | 4917 | then |
866000e7 GD |
4918 | -- In the case of a renamed object from source, this is an error |
4919 | -- unless the object is an aggregate and the renaming is created | |
4920 | -- for an object declaration. | |
51e641f8 | 4921 | |
8334176a ES |
4922 | if Comes_From_Source (Renamed_Object (Ent)) |
4923 | and then Nkind (Renamed_Object (Ent)) /= N_Aggregate | |
4924 | then | |
51e641f8 AC |
4925 | Get_Name_String (Chars (N)); |
4926 | Error_Msg_Strlen := Name_Len; | |
4927 | Error_Msg_String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len); | |
4928 | Error_Msg_N | |
4929 | ("~ clause not allowed for a renaming declaration " | |
4930 | & "(RM 13.1(6))", Nam); | |
4931 | return; | |
4932 | ||
4933 | -- For the case of a compiler generated renaming, the attribute | |
4934 | -- definition clause applies to the renamed object created by the | |
4935 | -- expander. The easiest general way to handle this is to create a | |
4936 | -- copy of the attribute definition clause for this object. | |
4937 | ||
81bd8c90 | 4938 | elsif Is_Entity_Name (Renamed_Object (Ent)) then |
51e641f8 AC |
4939 | Insert_Action (N, |
4940 | Make_Attribute_Definition_Clause (Loc, | |
4941 | Name => | |
4942 | New_Occurrence_Of (Entity (Renamed_Object (Ent)), Loc), | |
4943 | Chars => Chars (N), | |
4944 | Expression => Duplicate_Subexpr (Expression (N)))); | |
81bd8c90 AC |
4945 | |
4946 | -- If the renamed object is not an entity, it must be a dereference | |
4947 | -- of an unconstrained function call, and we must introduce a new | |
4948 | -- declaration to capture the expression. This is needed in the case | |
4949 | -- of 'Alignment, where the original declaration must be rewritten. | |
4950 | ||
4951 | else | |
4952 | pragma Assert | |
4953 | (Nkind (Renamed_Object (Ent)) = N_Explicit_Dereference); | |
4954 | null; | |
51e641f8 | 4955 | end if; |
54c04d6c AC |
4956 | |
4957 | -- If no underlying entity, use entity itself, applies to some | |
4958 | -- previously detected error cases ??? | |
4959 | ||
07fc65c4 GB |
4960 | elsif No (U_Ent) then |
4961 | U_Ent := Ent; | |
4962 | ||
54c04d6c AC |
4963 | -- Cannot specify for a subtype (exception Object/Value_Size) |
4964 | ||
996ae0b0 RK |
4965 | elsif Is_Type (U_Ent) |
4966 | and then not Is_First_Subtype (U_Ent) | |
4967 | and then Id /= Attribute_Object_Size | |
4968 | and then Id /= Attribute_Value_Size | |
4969 | and then not From_At_Mod (N) | |
4970 | then | |
4971 | Error_Msg_N ("cannot specify attribute for subtype", Nam); | |
4972 | return; | |
996ae0b0 RK |
4973 | end if; |
4974 | ||
0f1a6a0b AC |
4975 | Set_Entity (N, U_Ent); |
4976 | ||
996ae0b0 RK |
4977 | -- Switch on particular attribute |
4978 | ||
4979 | case Id is | |
4980 | ||
4981 | ------------- | |
4982 | -- Address -- | |
4983 | ------------- | |
4984 | ||
4985 | -- Address attribute definition clause | |
4986 | ||
4987 | when Attribute_Address => Address : begin | |
45fc7ddb HK |
4988 | |
4989 | -- A little error check, catch for X'Address use X'Address; | |
4990 | ||
4991 | if Nkind (Nam) = N_Identifier | |
4992 | and then Nkind (Expr) = N_Attribute_Reference | |
4993 | and then Attribute_Name (Expr) = Name_Address | |
4994 | and then Nkind (Prefix (Expr)) = N_Identifier | |
4995 | and then Chars (Nam) = Chars (Prefix (Expr)) | |
4996 | then | |
4997 | Error_Msg_NE | |
4998 | ("address for & is self-referencing", Prefix (Expr), Ent); | |
4999 | return; | |
5000 | end if; | |
5001 | ||
5002 | -- Not that special case, carry on with analysis of expression | |
5003 | ||
996ae0b0 RK |
5004 | Analyze_And_Resolve (Expr, RTE (RE_Address)); |
5005 | ||
9d0c3761 AC |
5006 | -- Even when ignoring rep clauses we need to indicate that the |
5007 | -- entity has an address clause and thus it is legal to declare | |
cf28c974 | 5008 | -- it imported. Freeze will get rid of the address clause later. |
c1025b4e AC |
5009 | -- Also call Set_Address_Taken to indicate that an address clause |
5010 | -- was present, even if we are about to remove it. | |
9d0c3761 AC |
5011 | |
5012 | if Ignore_Rep_Clauses then | |
c1025b4e AC |
5013 | Set_Address_Taken (U_Ent); |
5014 | ||
bce79204 | 5015 | if Ekind_In (U_Ent, E_Variable, E_Constant) then |
9d0c3761 AC |
5016 | Record_Rep_Item (U_Ent, N); |
5017 | end if; | |
5018 | ||
5019 | return; | |
5020 | end if; | |
5021 | ||
0f1a6a0b AC |
5022 | if Duplicate_Clause then |
5023 | null; | |
996ae0b0 RK |
5024 | |
5025 | -- Case of address clause for subprogram | |
5026 | ||
5027 | elsif Is_Subprogram (U_Ent) then | |
996ae0b0 RK |
5028 | if Has_Homonym (U_Ent) then |
5029 | Error_Msg_N | |
32b794c8 AC |
5030 | ("address clause cannot be given for overloaded " |
5031 | & "subprogram", Nam); | |
2642f998 | 5032 | return; |
996ae0b0 RK |
5033 | end if; |
5034 | ||
2642f998 RD |
5035 | -- For subprograms, all address clauses are permitted, and we |
5036 | -- mark the subprogram as having a deferred freeze so that Gigi | |
5037 | -- will not elaborate it too soon. | |
996ae0b0 RK |
5038 | |
5039 | -- Above needs more comments, what is too soon about??? | |
5040 | ||
5041 | Set_Has_Delayed_Freeze (U_Ent); | |
5042 | ||
5043 | -- Case of address clause for entry | |
5044 | ||
5045 | elsif Ekind (U_Ent) = E_Entry then | |
996ae0b0 RK |
5046 | if Nkind (Parent (N)) = N_Task_Body then |
5047 | Error_Msg_N | |
5048 | ("entry address must be specified in task spec", Nam); | |
2642f998 | 5049 | return; |
996ae0b0 RK |
5050 | end if; |
5051 | ||
5052 | -- For entries, we require a constant address | |
5053 | ||
5054 | Check_Constant_Address_Clause (Expr, U_Ent); | |
5055 | ||
2642f998 RD |
5056 | -- Special checks for task types |
5057 | ||
07fc65c4 GB |
5058 | if Is_Task_Type (Scope (U_Ent)) |
5059 | and then Comes_From_Source (Scope (U_Ent)) | |
5060 | then | |
5061 | Error_Msg_N | |
dbfeb4fa | 5062 | ("??entry address declared for entry in task type", N); |
07fc65c4 | 5063 | Error_Msg_N |
dbfeb4fa | 5064 | ("\??only one task can be declared of this type", N); |
07fc65c4 GB |
5065 | end if; |
5066 | ||
2642f998 RD |
5067 | -- Entry address clauses are obsolescent |
5068 | ||
5f3ab6fb AC |
5069 | Check_Restriction (No_Obsolescent_Features, N); |
5070 | ||
fbf5a39b AC |
5071 | if Warn_On_Obsolescent_Feature then |
5072 | Error_Msg_N | |
32b794c8 AC |
5073 | ("?j?attaching interrupt to task entry is an obsolescent " |
5074 | & "feature (RM J.7.1)", N); | |
fbf5a39b | 5075 | Error_Msg_N |
dbfeb4fa | 5076 | ("\?j?use interrupt procedure instead", N); |
fbf5a39b AC |
5077 | end if; |
5078 | ||
42f9f0fc | 5079 | -- Case of an address clause for a class-wide object, which is |
a51368fa AC |
5080 | -- considered erroneous. |
5081 | ||
5082 | elsif Is_Class_Wide_Type (Etype (U_Ent)) then | |
5083 | Error_Msg_NE | |
5084 | ("??class-wide object & must not be overlaid", Nam, U_Ent); | |
fbf5a39b | 5085 | Error_Msg_N |
dbfeb4fa | 5086 | ("\??Program_Error will be raised at run time", Nam); |
fbf5a39b AC |
5087 | Insert_Action (Declaration_Node (U_Ent), |
5088 | Make_Raise_Program_Error (Loc, | |
5089 | Reason => PE_Overlaid_Controlled_Object)); | |
2642f998 | 5090 | return; |
fbf5a39b | 5091 | |
d9049849 | 5092 | -- Case of address clause for an object |
996ae0b0 | 5093 | |
d9049849 | 5094 | elsif Ekind_In (U_Ent, E_Constant, E_Variable) then |
996ae0b0 | 5095 | declare |
f4cd2542 EB |
5096 | Expr : constant Node_Id := Expression (N); |
5097 | O_Ent : Entity_Id; | |
5098 | Off : Boolean; | |
996ae0b0 RK |
5099 | |
5100 | begin | |
5132708f RD |
5101 | -- Exported variables cannot have an address clause, because |
5102 | -- this cancels the effect of the pragma Export. | |
996ae0b0 RK |
5103 | |
5104 | if Is_Exported (U_Ent) then | |
5105 | Error_Msg_N | |
5106 | ("cannot export object with address clause", Nam); | |
2642f998 | 5107 | return; |
f4cd2542 EB |
5108 | end if; |
5109 | ||
5110 | Find_Overlaid_Entity (N, O_Ent, Off); | |
996ae0b0 | 5111 | |
b3b5c6a2 | 5112 | if Present (O_Ent) then |
d6dffa66 | 5113 | |
b3b5c6a2 | 5114 | -- If the object overlays a constant object, mark it so |
c31b57af | 5115 | |
b3b5c6a2 EB |
5116 | if Is_Constant_Object (O_Ent) then |
5117 | Set_Overlays_Constant (U_Ent); | |
5118 | end if; | |
d6dffa66 | 5119 | |
f26a3587 AC |
5120 | -- If the address clause is of the form: |
5121 | ||
5122 | -- for X'Address use Y'Address; | |
5123 | ||
5124 | -- or | |
5125 | ||
5126 | -- C : constant Address := Y'Address; | |
5127 | -- ... | |
5128 | -- for X'Address use C; | |
5129 | ||
5130 | -- then we make an entry in the table to check the size | |
5131 | -- and alignment of the overlaying variable. But we defer | |
5132 | -- this check till after code generation to take full | |
5133 | -- advantage of the annotation done by the back end. | |
5134 | ||
5135 | -- If the entity has a generic type, the check will be | |
5136 | -- performed in the instance if the actual type justifies | |
5137 | -- it, and we do not insert the clause in the table to | |
5138 | -- prevent spurious warnings. | |
5139 | ||
5140 | -- Note: we used to test Comes_From_Source and only give | |
5141 | -- this warning for source entities, but we have removed | |
5142 | -- this test. It really seems bogus to generate overlays | |
5143 | -- that would trigger this warning in generated code. | |
5144 | -- Furthermore, by removing the test, we handle the | |
5145 | -- aspect case properly. | |
5146 | ||
5147 | if Is_Object (O_Ent) | |
570d5bbc | 5148 | and then not Is_Generic_Formal (O_Ent) |
f26a3587 AC |
5149 | and then not Is_Generic_Type (Etype (U_Ent)) |
5150 | and then Address_Clause_Overlay_Warnings | |
5151 | then | |
5067f3a0 PMR |
5152 | Register_Address_Clause_Check |
5153 | (N, U_Ent, No_Uint, O_Ent, Off); | |
f26a3587 | 5154 | end if; |
845af9e6 PMR |
5155 | |
5156 | -- If the overlay changes the storage order, mark the | |
5157 | -- entity as being volatile to block any optimization | |
5158 | -- for it since the construct is not really supported | |
5159 | -- by the back end. | |
5160 | ||
5161 | if (Is_Record_Type (Etype (U_Ent)) | |
5162 | or else Is_Array_Type (Etype (U_Ent))) | |
5163 | and then (Is_Record_Type (Etype (O_Ent)) | |
5164 | or else Is_Array_Type (Etype (O_Ent))) | |
aa11d1dd PMR |
5165 | and then Reverse_Storage_Order (Etype (U_Ent)) /= |
5166 | Reverse_Storage_Order (Etype (O_Ent)) | |
845af9e6 PMR |
5167 | then |
5168 | Set_Treat_As_Volatile (U_Ent); | |
5169 | end if; | |
5170 | ||
b3b5c6a2 EB |
5171 | else |
5172 | -- If this is not an overlay, mark a variable as being | |
5173 | -- volatile to prevent unwanted optimizations. It's a | |
5174 | -- conservative interpretation of RM 13.3(19) for the | |
5175 | -- cases where the compiler cannot detect potential | |
5176 | -- aliasing issues easily and it also covers the case | |
5177 | -- of an absolute address where the volatile aspect is | |
5178 | -- kind of implicit. | |
5179 | ||
5180 | if Ekind (U_Ent) = E_Variable then | |
5181 | Set_Treat_As_Volatile (U_Ent); | |
5182 | end if; | |
f26a3587 AC |
5183 | |
5184 | -- Make an entry in the table for an absolute address as | |
5185 | -- above to check that the value is compatible with the | |
5186 | -- alignment of the object. | |
5187 | ||
5188 | declare | |
5189 | Addr : constant Node_Id := Address_Value (Expr); | |
5190 | begin | |
5191 | if Compile_Time_Known_Value (Addr) | |
5192 | and then Address_Clause_Overlay_Warnings | |
5193 | then | |
5067f3a0 PMR |
5194 | Register_Address_Clause_Check |
5195 | (N, U_Ent, Expr_Value (Addr), Empty, False); | |
f26a3587 AC |
5196 | end if; |
5197 | end; | |
c31b57af EB |
5198 | end if; |
5199 | ||
ed11bbfe AC |
5200 | -- Issue an unconditional warning for a constant overlaying |
5201 | -- a variable. For the reverse case, we will issue it only | |
c31b57af | 5202 | -- if the variable is modified. |
ed11bbfe | 5203 | |
d9049849 | 5204 | if Ekind (U_Ent) = E_Constant |
ed11bbfe | 5205 | and then Present (O_Ent) |
c31b57af EB |
5206 | and then not Overlays_Constant (U_Ent) |
5207 | and then Address_Clause_Overlay_Warnings | |
fbf5a39b | 5208 | then |
dbfeb4fa | 5209 | Error_Msg_N ("??constant overlays a variable", Expr); |
fbf5a39b | 5210 | |
996ae0b0 RK |
5211 | -- Imported variables can have an address clause, but then |
5212 | -- the import is pretty meaningless except to suppress | |
5213 | -- initializations, so we do not need such variables to | |
5214 | -- be statically allocated (and in fact it causes trouble | |
5215 | -- if the address clause is a local value). | |
5216 | ||
5217 | elsif Is_Imported (U_Ent) then | |
5218 | Set_Is_Statically_Allocated (U_Ent, False); | |
5219 | end if; | |
5220 | ||
5221 | -- We mark a possible modification of a variable with an | |
5222 | -- address clause, since it is likely aliasing is occurring. | |
5223 | ||
45fc7ddb | 5224 | Note_Possible_Modification (Nam, Sure => False); |
996ae0b0 | 5225 | |
fbf5a39b AC |
5226 | -- Legality checks on the address clause for initialized |
5227 | -- objects is deferred until the freeze point, because | |
29ba9f52 | 5228 | -- a subsequent pragma might indicate that the object |
02217452 AC |
5229 | -- is imported and thus not initialized. Also, the address |
5230 | -- clause might involve entities that have yet to be | |
5231 | -- elaborated. | |
fbf5a39b AC |
5232 | |
5233 | Set_Has_Delayed_Freeze (U_Ent); | |
5234 | ||
f3b57ab0 AC |
5235 | -- If an initialization call has been generated for this |
5236 | -- object, it needs to be deferred to after the freeze node | |
5237 | -- we have just now added, otherwise GIGI will see a | |
5238 | -- reference to the variable (as actual to the IP call) | |
5239 | -- before its definition. | |
5240 | ||
5241 | declare | |
3a3af4c3 AC |
5242 | Init_Call : constant Node_Id := |
5243 | Remove_Init_Call (U_Ent, N); | |
ae05cdd6 | 5244 | |
f3b57ab0 AC |
5245 | begin |
5246 | if Present (Init_Call) then | |
c6d2191a | 5247 | Append_Freeze_Action (U_Ent, Init_Call); |
3a3af4c3 | 5248 | |
c6d2191a AC |
5249 | -- Reset Initialization_Statements pointer so that |
5250 | -- if there is a pragma Import further down, it can | |
5251 | -- clear any default initialization. | |
3a3af4c3 | 5252 | |
c6d2191a | 5253 | Set_Initialization_Statements (U_Ent, Init_Call); |
f3b57ab0 AC |
5254 | end if; |
5255 | end; | |
5256 | ||
affbee12 RD |
5257 | -- Entity has delayed freeze, so we will generate an |
5258 | -- alignment check at the freeze point unless suppressed. | |
996ae0b0 | 5259 | |
affbee12 RD |
5260 | if not Range_Checks_Suppressed (U_Ent) |
5261 | and then not Alignment_Checks_Suppressed (U_Ent) | |
5262 | then | |
5263 | Set_Check_Address_Alignment (N); | |
5264 | end if; | |
996ae0b0 RK |
5265 | |
5266 | -- Kill the size check code, since we are not allocating | |
5267 | -- the variable, it is somewhere else. | |
5268 | ||
5269 | Kill_Size_Check_Code (U_Ent); | |
f4cd2542 | 5270 | end; |
2642f998 | 5271 | |
996ae0b0 RK |
5272 | -- Not a valid entity for an address clause |
5273 | ||
5274 | else | |
5275 | Error_Msg_N ("address cannot be given for &", Nam); | |
5276 | end if; | |
5277 | end Address; | |
5278 | ||
5279 | --------------- | |
5280 | -- Alignment -- | |
5281 | --------------- | |
5282 | ||
5283 | -- Alignment attribute definition clause | |
5284 | ||
f8c6086b | 5285 | when Attribute_Alignment => Alignment : declare |
6bed26b5 AC |
5286 | Align : constant Uint := Get_Alignment_Value (Expr); |
5287 | Max_Align : constant Uint := UI_From_Int (Maximum_Alignment); | |
033eaf85 | 5288 | |
996ae0b0 RK |
5289 | begin |
5290 | FOnly := True; | |
5291 | ||
5292 | if not Is_Type (U_Ent) | |
5293 | and then Ekind (U_Ent) /= E_Variable | |
5294 | and then Ekind (U_Ent) /= E_Constant | |
5295 | then | |
5296 | Error_Msg_N ("alignment cannot be given for &", Nam); | |
5297 | ||
0f1a6a0b AC |
5298 | elsif Duplicate_Clause then |
5299 | null; | |
996ae0b0 RK |
5300 | |
5301 | elsif Align /= No_Uint then | |
5302 | Set_Has_Alignment_Clause (U_Ent); | |
6bed26b5 | 5303 | |
54c04d6c | 5304 | -- Tagged type case, check for attempt to set alignment to a |
32b794c8 AC |
5305 | -- value greater than Max_Align, and reset if so. This error |
5306 | -- is suppressed in ASIS mode to allow for different ASIS | |
2cc2e964 | 5307 | -- back ends or ASIS-based tools to query the illegal clause. |
54c04d6c | 5308 | |
32b794c8 AC |
5309 | if Is_Tagged_Type (U_Ent) |
5310 | and then Align > Max_Align | |
5311 | and then not ASIS_Mode | |
5312 | then | |
6bed26b5 | 5313 | Error_Msg_N |
dbfeb4fa | 5314 | ("alignment for & set to Maximum_Aligment??", Nam); |
32b794c8 | 5315 | Set_Alignment (U_Ent, Max_Align); |
54c04d6c AC |
5316 | |
5317 | -- All other cases | |
5318 | ||
6bed26b5 AC |
5319 | else |
5320 | Set_Alignment (U_Ent, Align); | |
5321 | end if; | |
f8c6086b AC |
5322 | |
5323 | -- For an array type, U_Ent is the first subtype. In that case, | |
5324 | -- also set the alignment of the anonymous base type so that | |
5325 | -- other subtypes (such as the itypes for aggregates of the | |
5326 | -- type) also receive the expected alignment. | |
5327 | ||
5328 | if Is_Array_Type (U_Ent) then | |
5329 | Set_Alignment (Base_Type (U_Ent), Align); | |
5330 | end if; | |
996ae0b0 | 5331 | end if; |
f8c6086b | 5332 | end Alignment; |
996ae0b0 RK |
5333 | |
5334 | --------------- | |
5335 | -- Bit_Order -- | |
5336 | --------------- | |
5337 | ||
5338 | -- Bit_Order attribute definition clause | |
5339 | ||
d8f43ee6 | 5340 | when Attribute_Bit_Order => |
996ae0b0 RK |
5341 | if not Is_Record_Type (U_Ent) then |
5342 | Error_Msg_N | |
5343 | ("Bit_Order can only be defined for record type", Nam); | |
5344 | ||
400ad4e9 | 5345 | elsif Is_Tagged_Type (U_Ent) and then Is_Derived_Type (U_Ent) then |
2588c36c JM |
5346 | Error_Msg_N |
5347 | ("Bit_Order cannot be defined for record extensions", Nam); | |
5348 | ||
0f1a6a0b AC |
5349 | elsif Duplicate_Clause then |
5350 | null; | |
5351 | ||
996ae0b0 RK |
5352 | else |
5353 | Analyze_And_Resolve (Expr, RTE (RE_Bit_Order)); | |
5354 | ||
5355 | if Etype (Expr) = Any_Type then | |
5356 | return; | |
5357 | ||
edab6088 | 5358 | elsif not Is_OK_Static_Expression (Expr) then |
fbf5a39b AC |
5359 | Flag_Non_Static_Expr |
5360 | ("Bit_Order requires static expression!", Expr); | |
996ae0b0 | 5361 | |
400ad4e9 HK |
5362 | elsif (Expr_Value (Expr) = 0) /= Bytes_Big_Endian then |
5363 | Set_Reverse_Bit_Order (Base_Type (U_Ent), True); | |
996ae0b0 RK |
5364 | end if; |
5365 | end if; | |
996ae0b0 RK |
5366 | |
5367 | -------------------- | |
5368 | -- Component_Size -- | |
5369 | -------------------- | |
5370 | ||
5371 | -- Component_Size attribute definition clause | |
5372 | ||
5373 | when Attribute_Component_Size => Component_Size_Case : declare | |
5374 | Csize : constant Uint := Static_Integer (Expr); | |
b3f48fd4 | 5375 | Ctyp : Entity_Id; |
996ae0b0 RK |
5376 | Btype : Entity_Id; |
5377 | Biased : Boolean; | |
5378 | New_Ctyp : Entity_Id; | |
5379 | Decl : Node_Id; | |
5380 | ||
5381 | begin | |
5382 | if not Is_Array_Type (U_Ent) then | |
5383 | Error_Msg_N ("component size requires array type", Nam); | |
5384 | return; | |
5385 | end if; | |
5386 | ||
5387 | Btype := Base_Type (U_Ent); | |
32b794c8 | 5388 | Ctyp := Component_Type (Btype); |
996ae0b0 | 5389 | |
0f1a6a0b AC |
5390 | if Duplicate_Clause then |
5391 | null; | |
996ae0b0 | 5392 | |
094cefda AC |
5393 | elsif Rep_Item_Too_Early (Btype, N) then |
5394 | null; | |
5395 | ||
996ae0b0 | 5396 | elsif Csize /= No_Uint then |
b3f48fd4 | 5397 | Check_Size (Expr, Ctyp, Csize, Biased); |
996ae0b0 | 5398 | |
c159409f AC |
5399 | -- For the biased case, build a declaration for a subtype that |
5400 | -- will be used to represent the biased subtype that reflects | |
5401 | -- the biased representation of components. We need the subtype | |
5402 | -- to get proper conversions on referencing elements of the | |
535a8637 | 5403 | -- array. |
800621e0 | 5404 | |
535a8637 AC |
5405 | if Biased then |
5406 | New_Ctyp := | |
5407 | Make_Defining_Identifier (Loc, | |
5408 | Chars => | |
5409 | New_External_Name (Chars (U_Ent), 'C', 0, 'T')); | |
800621e0 | 5410 | |
535a8637 AC |
5411 | Decl := |
5412 | Make_Subtype_Declaration (Loc, | |
5413 | Defining_Identifier => New_Ctyp, | |
5414 | Subtype_Indication => | |
5415 | New_Occurrence_Of (Component_Type (Btype), Loc)); | |
5416 | ||
5417 | Set_Parent (Decl, N); | |
5418 | Analyze (Decl, Suppress => All_Checks); | |
5419 | ||
5420 | Set_Has_Delayed_Freeze (New_Ctyp, False); | |
5421 | Set_Esize (New_Ctyp, Csize); | |
5422 | Set_RM_Size (New_Ctyp, Csize); | |
5423 | Init_Alignment (New_Ctyp); | |
5424 | Set_Is_Itype (New_Ctyp, True); | |
5425 | Set_Associated_Node_For_Itype (New_Ctyp, U_Ent); | |
5426 | ||
5427 | Set_Component_Type (Btype, New_Ctyp); | |
5428 | Set_Biased (New_Ctyp, N, "component size clause"); | |
996ae0b0 RK |
5429 | end if; |
5430 | ||
535a8637 AC |
5431 | Set_Component_Size (Btype, Csize); |
5432 | ||
b3f48fd4 AC |
5433 | -- Deal with warning on overridden size |
5434 | ||
5435 | if Warn_On_Overridden_Size | |
5436 | and then Has_Size_Clause (Ctyp) | |
5437 | and then RM_Size (Ctyp) /= Csize | |
5438 | then | |
5439 | Error_Msg_NE | |
dbfeb4fa | 5440 | ("component size overrides size clause for&?S?", N, Ctyp); |
b3f48fd4 AC |
5441 | end if; |
5442 | ||
996ae0b0 | 5443 | Set_Has_Component_Size_Clause (Btype, True); |
094cefda | 5444 | Set_Has_Non_Standard_Rep (Btype, True); |
996ae0b0 RK |
5445 | end if; |
5446 | end Component_Size_Case; | |
5447 | ||
d50f4827 AC |
5448 | ----------------------- |
5449 | -- Constant_Indexing -- | |
5450 | ----------------------- | |
5451 | ||
5452 | when Attribute_Constant_Indexing => | |
5453 | Check_Indexing_Functions; | |
5454 | ||
b98e2969 AC |
5455 | --------- |
5456 | -- CPU -- | |
5457 | --------- | |
5458 | ||
d8f43ee6 HK |
5459 | when Attribute_CPU => |
5460 | ||
b98e2969 AC |
5461 | -- CPU attribute definition clause not allowed except from aspect |
5462 | -- specification. | |
5463 | ||
5464 | if From_Aspect_Specification (N) then | |
5465 | if not Is_Task_Type (U_Ent) then | |
5466 | Error_Msg_N ("CPU can only be defined for task", Nam); | |
5467 | ||
5468 | elsif Duplicate_Clause then | |
5469 | null; | |
5470 | ||
5471 | else | |
5472 | -- The expression must be analyzed in the special manner | |
5473 | -- described in "Handling of Default and Per-Object | |
5474 | -- Expressions" in sem.ads. | |
5475 | ||
5f531fef ES |
5476 | -- The visibility to the components must be established |
5477 | -- and restored before and after analysis. | |
b98e2969 | 5478 | |
5f531fef | 5479 | Push_Type (U_Ent); |
b98e2969 | 5480 | Preanalyze_Spec_Expression (Expr, RTE (RE_CPU_Range)); |
5f531fef | 5481 | Pop_Type (U_Ent); |
b98e2969 | 5482 | |
edab6088 | 5483 | if not Is_OK_Static_Expression (Expr) then |
b98e2969 AC |
5484 | Check_Restriction (Static_Priorities, Expr); |
5485 | end if; | |
5486 | end if; | |
5487 | ||
5488 | else | |
5489 | Error_Msg_N | |
5490 | ("attribute& cannot be set with definition clause", N); | |
5491 | end if; | |
b98e2969 | 5492 | |
d941cee6 AC |
5493 | ---------------------- |
5494 | -- Default_Iterator -- | |
5495 | ---------------------- | |
5496 | ||
eedc5882 | 5497 | when Attribute_Default_Iterator => Default_Iterator : declare |
d941cee6 | 5498 | Func : Entity_Id; |
72eaa365 | 5499 | Typ : Entity_Id; |
d941cee6 AC |
5500 | |
5501 | begin | |
4f2cae4a ES |
5502 | -- If target type is untagged, further checks are irrelevant |
5503 | ||
d941cee6 AC |
5504 | if not Is_Tagged_Type (U_Ent) then |
5505 | Error_Msg_N | |
4f2cae4a ES |
5506 | ("aspect Default_Iterator applies to tagged type", Nam); |
5507 | return; | |
d941cee6 AC |
5508 | end if; |
5509 | ||
5510 | Check_Iterator_Functions; | |
5511 | ||
5512 | Analyze (Expr); | |
5513 | ||
5514 | if not Is_Entity_Name (Expr) | |
5515 | or else Ekind (Entity (Expr)) /= E_Function | |
5516 | then | |
5517 | Error_Msg_N ("aspect Iterator must be a function", Expr); | |
4f2cae4a | 5518 | return; |
d941cee6 AC |
5519 | else |
5520 | Func := Entity (Expr); | |
5521 | end if; | |
5522 | ||
72eaa365 | 5523 | -- The type of the first parameter must be T, T'class, or a |
4f2cae4a ES |
5524 | -- corresponding access type (5.5.1 (8/3). If function is |
5525 | -- parameterless label type accordingly. | |
72eaa365 AC |
5526 | |
5527 | if No (First_Formal (Func)) then | |
4f2cae4a | 5528 | Typ := Any_Type; |
72eaa365 AC |
5529 | else |
5530 | Typ := Etype (First_Formal (Func)); | |
5531 | end if; | |
5532 | ||
5533 | if Typ = U_Ent | |
5534 | or else Typ = Class_Wide_Type (U_Ent) | |
5535 | or else (Is_Access_Type (Typ) | |
5536 | and then Designated_Type (Typ) = U_Ent) | |
5537 | or else (Is_Access_Type (Typ) | |
5538 | and then Designated_Type (Typ) = | |
5539 | Class_Wide_Type (U_Ent)) | |
d941cee6 | 5540 | then |
72eaa365 AC |
5541 | null; |
5542 | ||
5543 | else | |
d941cee6 AC |
5544 | Error_Msg_NE |
5545 | ("Default Iterator must be a primitive of&", Func, U_Ent); | |
5546 | end if; | |
5547 | end Default_Iterator; | |
5548 | ||
b98e2969 AC |
5549 | ------------------------ |
5550 | -- Dispatching_Domain -- | |
5551 | ------------------------ | |
5552 | ||
d8f43ee6 HK |
5553 | when Attribute_Dispatching_Domain => |
5554 | ||
b98e2969 AC |
5555 | -- Dispatching_Domain attribute definition clause not allowed |
5556 | -- except from aspect specification. | |
5557 | ||
5558 | if From_Aspect_Specification (N) then | |
5559 | if not Is_Task_Type (U_Ent) then | |
72eaa365 AC |
5560 | Error_Msg_N |
5561 | ("Dispatching_Domain can only be defined for task", Nam); | |
b98e2969 AC |
5562 | |
5563 | elsif Duplicate_Clause then | |
5564 | null; | |
5565 | ||
5566 | else | |
5567 | -- The expression must be analyzed in the special manner | |
5568 | -- described in "Handling of Default and Per-Object | |
5569 | -- Expressions" in sem.ads. | |
5570 | ||
5f531fef | 5571 | -- The visibility to the components must be restored |
b98e2969 | 5572 | |
5f531fef | 5573 | Push_Type (U_Ent); |
b98e2969 AC |
5574 | |
5575 | Preanalyze_Spec_Expression | |
5576 | (Expr, RTE (RE_Dispatching_Domain)); | |
5577 | ||
5f531fef | 5578 | Pop_Type (U_Ent); |
b98e2969 AC |
5579 | end if; |
5580 | ||
5581 | else | |
5582 | Error_Msg_N | |
5583 | ("attribute& cannot be set with definition clause", N); | |
5584 | end if; | |
b98e2969 | 5585 | |
996ae0b0 RK |
5586 | ------------------ |
5587 | -- External_Tag -- | |
5588 | ------------------ | |
5589 | ||
d8f43ee6 | 5590 | when Attribute_External_Tag => |
996ae0b0 RK |
5591 | if not Is_Tagged_Type (U_Ent) then |
5592 | Error_Msg_N ("should be a tagged type", Nam); | |
5593 | end if; | |
5594 | ||
0f1a6a0b AC |
5595 | if Duplicate_Clause then |
5596 | null; | |
996ae0b0 | 5597 | |
76efd572 | 5598 | else |
0f1a6a0b | 5599 | Analyze_And_Resolve (Expr, Standard_String); |
c690a2ec | 5600 | |
edab6088 | 5601 | if not Is_OK_Static_Expression (Expr) then |
0f1a6a0b AC |
5602 | Flag_Non_Static_Expr |
5603 | ("static string required for tag name!", Nam); | |
5604 | end if; | |
5605 | ||
0f1a6a0b AC |
5606 | if not Is_Library_Level_Entity (U_Ent) then |
5607 | Error_Msg_NE | |
dbfeb4fa | 5608 | ("??non-unique external tag supplied for &", N, U_Ent); |
0f1a6a0b | 5609 | Error_Msg_N |
32b794c8 AC |
5610 | ("\??same external tag applies to all subprogram calls", |
5611 | N); | |
0f1a6a0b | 5612 | Error_Msg_N |
dbfeb4fa | 5613 | ("\??corresponding internal tag cannot be obtained", N); |
0f1a6a0b | 5614 | end if; |
c690a2ec | 5615 | end if; |
996ae0b0 | 5616 | |
0da80d7d AC |
5617 | -------------------------- |
5618 | -- Implicit_Dereference -- | |
5619 | -------------------------- | |
bb3c784c | 5620 | |
0da80d7d | 5621 | when Attribute_Implicit_Dereference => |
bb3c784c | 5622 | |
29ba9f52 RD |
5623 | -- Legality checks already performed at the point of the type |
5624 | -- declaration, aspect is not delayed. | |
bb3c784c | 5625 | |
d941cee6 | 5626 | null; |
0da80d7d | 5627 | |
996ae0b0 RK |
5628 | ----------- |
5629 | -- Input -- | |
5630 | ----------- | |
5631 | ||
edd63e9b ES |
5632 | when Attribute_Input => |
5633 | Analyze_Stream_TSS_Definition (TSS_Stream_Input); | |
5634 | Set_Has_Specified_Stream_Input (Ent); | |
996ae0b0 | 5635 | |
b98e2969 AC |
5636 | ------------------------ |
5637 | -- Interrupt_Priority -- | |
5638 | ------------------------ | |
5639 | ||
d8f43ee6 HK |
5640 | when Attribute_Interrupt_Priority => |
5641 | ||
b98e2969 AC |
5642 | -- Interrupt_Priority attribute definition clause not allowed |
5643 | -- except from aspect specification. | |
5644 | ||
5645 | if From_Aspect_Specification (N) then | |
dc06dd83 | 5646 | if not Is_Concurrent_Type (U_Ent) then |
b98e2969 | 5647 | Error_Msg_N |
32b794c8 AC |
5648 | ("Interrupt_Priority can only be defined for task and " |
5649 | & "protected object", Nam); | |
b98e2969 AC |
5650 | |
5651 | elsif Duplicate_Clause then | |
5652 | null; | |
5653 | ||
5654 | else | |
5655 | -- The expression must be analyzed in the special manner | |
5656 | -- described in "Handling of Default and Per-Object | |
5657 | -- Expressions" in sem.ads. | |
5658 | ||
5f531fef | 5659 | -- The visibility to the components must be restored |
b98e2969 | 5660 | |
5f531fef | 5661 | Push_Type (U_Ent); |
b98e2969 AC |
5662 | |
5663 | Preanalyze_Spec_Expression | |
5664 | (Expr, RTE (RE_Interrupt_Priority)); | |
5665 | ||
5f531fef | 5666 | Pop_Type (U_Ent); |
6bf8c157 TG |
5667 | |
5668 | -- Check the No_Task_At_Interrupt_Priority restriction | |
5669 | ||
5670 | if Is_Task_Type (U_Ent) then | |
5671 | Check_Restriction (No_Task_At_Interrupt_Priority, N); | |
5672 | end if; | |
b98e2969 AC |
5673 | end if; |
5674 | ||
5675 | else | |
5676 | Error_Msg_N | |
5677 | ("attribute& cannot be set with definition clause", N); | |
5678 | end if; | |
b98e2969 | 5679 | |
dd2bf554 ES |
5680 | -------------- |
5681 | -- Iterable -- | |
5682 | -------------- | |
5683 | ||
5684 | when Attribute_Iterable => | |
5685 | Analyze (Expr); | |
82d4f390 | 5686 | |
dd2bf554 ES |
5687 | if Nkind (Expr) /= N_Aggregate then |
5688 | Error_Msg_N ("aspect Iterable must be an aggregate", Expr); | |
5689 | end if; | |
5690 | ||
5691 | declare | |
5692 | Assoc : Node_Id; | |
5693 | ||
5694 | begin | |
5695 | Assoc := First (Component_Associations (Expr)); | |
5696 | while Present (Assoc) loop | |
5f531fef | 5697 | Analyze (Expression (Assoc)); |
2401c98f | 5698 | |
dd2bf554 ES |
5699 | if not Is_Entity_Name (Expression (Assoc)) then |
5700 | Error_Msg_N ("value must be a function", Assoc); | |
5701 | end if; | |
82d4f390 | 5702 | |
dd2bf554 ES |
5703 | Next (Assoc); |
5704 | end loop; | |
5705 | end; | |
5706 | ||
d941cee6 AC |
5707 | ---------------------- |
5708 | -- Iterator_Element -- | |
5709 | ---------------------- | |
5710 | ||
5711 | when Attribute_Iterator_Element => | |
5712 | Analyze (Expr); | |
5713 | ||
5714 | if not Is_Entity_Name (Expr) | |
5715 | or else not Is_Type (Entity (Expr)) | |
5716 | then | |
5717 | Error_Msg_N ("aspect Iterator_Element must be a type", Expr); | |
5718 | end if; | |
5719 | ||
996ae0b0 RK |
5720 | ------------------- |
5721 | -- Machine_Radix -- | |
5722 | ------------------- | |
5723 | ||
5724 | -- Machine radix attribute definition clause | |
5725 | ||
5726 | when Attribute_Machine_Radix => Machine_Radix : declare | |
5727 | Radix : constant Uint := Static_Integer (Expr); | |
5728 | ||
5729 | begin | |
5730 | if not Is_Decimal_Fixed_Point_Type (U_Ent) then | |
5731 | Error_Msg_N ("decimal fixed-point type expected for &", Nam); | |
5732 | ||
0f1a6a0b AC |
5733 | elsif Duplicate_Clause then |
5734 | null; | |
996ae0b0 RK |
5735 | |
5736 | elsif Radix /= No_Uint then | |
5737 | Set_Has_Machine_Radix_Clause (U_Ent); | |
5738 | Set_Has_Non_Standard_Rep (Base_Type (U_Ent)); | |
5739 | ||
5740 | if Radix = 2 then | |
5741 | null; | |
32b794c8 | 5742 | |
996ae0b0 RK |
5743 | elsif Radix = 10 then |
5744 | Set_Machine_Radix_10 (U_Ent); | |
32b794c8 AC |
5745 | |
5746 | -- The following error is suppressed in ASIS mode to allow for | |
2cc2e964 | 5747 | -- different ASIS back ends or ASIS-based tools to query the |
32b794c8 AC |
5748 | -- illegal clause. |
5749 | ||
5750 | elsif not ASIS_Mode then | |
996ae0b0 RK |
5751 | Error_Msg_N ("machine radix value must be 2 or 10", Expr); |
5752 | end if; | |
5753 | end if; | |
5754 | end Machine_Radix; | |
5755 | ||
5756 | ----------------- | |
5757 | -- Object_Size -- | |
5758 | ----------------- | |
5759 | ||
5760 | -- Object_Size attribute definition clause | |
5761 | ||
5762 | when Attribute_Object_Size => Object_Size : declare | |
d4731b80 BD |
5763 | Size : constant Uint := Static_Integer (Expr); |
5764 | ||
996ae0b0 | 5765 | Biased : Boolean; |
d4731b80 | 5766 | pragma Warnings (Off, Biased); |
996ae0b0 RK |
5767 | |
5768 | begin | |
5769 | if not Is_Type (U_Ent) then | |
5770 | Error_Msg_N ("Object_Size cannot be given for &", Nam); | |
5771 | ||
0f1a6a0b AC |
5772 | elsif Duplicate_Clause then |
5773 | null; | |
996ae0b0 RK |
5774 | |
5775 | else | |
5776 | Check_Size (Expr, U_Ent, Size, Biased); | |
5777 | ||
32b794c8 | 5778 | -- The following errors are suppressed in ASIS mode to allow |
2cc2e964 | 5779 | -- for different ASIS back ends or ASIS-based tools to query |
32b794c8 AC |
5780 | -- the illegal clause. |
5781 | ||
5782 | if ASIS_Mode then | |
5783 | null; | |
5784 | ||
5785 | elsif Is_Scalar_Type (U_Ent) then | |
3e586e10 AC |
5786 | if Size /= 8 and then Size /= 16 and then Size /= 32 |
5787 | and then UI_Mod (Size, 64) /= 0 | |
5788 | then | |
5789 | Error_Msg_N | |
5790 | ("Object_Size must be 8, 16, 32, or multiple of 64", | |
5791 | Expr); | |
5792 | end if; | |
5793 | ||
5794 | elsif Size mod 8 /= 0 then | |
5795 | Error_Msg_N ("Object_Size must be a multiple of 8", Expr); | |
996ae0b0 RK |
5796 | end if; |
5797 | ||
5798 | Set_Esize (U_Ent, Size); | |
5799 | Set_Has_Object_Size_Clause (U_Ent); | |
76af4137 | 5800 | Alignment_Check_For_Size_Change (U_Ent, Size); |
996ae0b0 RK |
5801 | end if; |
5802 | end Object_Size; | |
5803 | ||
5804 | ------------ | |
5805 | -- Output -- | |
5806 | ------------ | |
5807 | ||
edd63e9b ES |
5808 | when Attribute_Output => |
5809 | Analyze_Stream_TSS_Definition (TSS_Stream_Output); | |
5810 | Set_Has_Specified_Stream_Output (Ent); | |
996ae0b0 | 5811 | |
b98e2969 AC |
5812 | -------------- |
5813 | -- Priority -- | |
5814 | -------------- | |
5815 | ||
d8f43ee6 HK |
5816 | when Attribute_Priority => |
5817 | ||
b98e2969 AC |
5818 | -- Priority attribute definition clause not allowed except from |
5819 | -- aspect specification. | |
5820 | ||
5821 | if From_Aspect_Specification (N) then | |
dc06dd83 | 5822 | if not (Is_Concurrent_Type (U_Ent) |
473e20df | 5823 | or else Ekind (U_Ent) = E_Procedure) |
b98e2969 AC |
5824 | then |
5825 | Error_Msg_N | |
dc06dd83 AC |
5826 | ("Priority can only be defined for task and protected " |
5827 | & "object", Nam); | |
b98e2969 AC |
5828 | |
5829 | elsif Duplicate_Clause then | |
5830 | null; | |
5831 | ||
5832 | else | |
5833 | -- The expression must be analyzed in the special manner | |
5834 | -- described in "Handling of Default and Per-Object | |
5835 | -- Expressions" in sem.ads. | |
5836 | ||
5f531fef | 5837 | -- The visibility to the components must be restored |
b98e2969 | 5838 | |
5f531fef | 5839 | Push_Type (U_Ent); |
b98e2969 | 5840 | Preanalyze_Spec_Expression (Expr, Standard_Integer); |
5f531fef | 5841 | Pop_Type (U_Ent); |
b98e2969 | 5842 | |
edab6088 | 5843 | if not Is_OK_Static_Expression (Expr) then |
b98e2969 AC |
5844 | Check_Restriction (Static_Priorities, Expr); |
5845 | end if; | |
5846 | end if; | |
5847 | ||
5848 | else | |
5849 | Error_Msg_N | |
5850 | ("attribute& cannot be set with definition clause", N); | |
5851 | end if; | |
b98e2969 | 5852 | |
996ae0b0 RK |
5853 | ---------- |
5854 | -- Read -- | |
5855 | ---------- | |
5856 | ||
edd63e9b ES |
5857 | when Attribute_Read => |
5858 | Analyze_Stream_TSS_Definition (TSS_Stream_Read); | |
5859 | Set_Has_Specified_Stream_Read (Ent); | |
996ae0b0 | 5860 | |
f91510fc AC |
5861 | -------------------------- |
5862 | -- Scalar_Storage_Order -- | |
5863 | -------------------------- | |
5864 | ||
5865 | -- Scalar_Storage_Order attribute definition clause | |
5866 | ||
d8f43ee6 | 5867 | when Attribute_Scalar_Storage_Order => |
a2c1791d | 5868 | if not (Is_Record_Type (U_Ent) or else Is_Array_Type (U_Ent)) then |
f91510fc | 5869 | Error_Msg_N |
32b794c8 AC |
5870 | ("Scalar_Storage_Order can only be defined for record or " |
5871 | & "array type", Nam); | |
f91510fc AC |
5872 | |
5873 | elsif Duplicate_Clause then | |
5874 | null; | |
5875 | ||
5876 | else | |
5877 | Analyze_And_Resolve (Expr, RTE (RE_Bit_Order)); | |
5878 | ||
5879 | if Etype (Expr) = Any_Type then | |
5880 | return; | |
5881 | ||
edab6088 | 5882 | elsif not Is_OK_Static_Expression (Expr) then |
f91510fc AC |
5883 | Flag_Non_Static_Expr |
5884 | ("Scalar_Storage_Order requires static expression!", Expr); | |
5885 | ||
d7761b2d AC |
5886 | elsif (Expr_Value (Expr) = 0) /= Bytes_Big_Endian then |
5887 | ||
5888 | -- Here for the case of a non-default (i.e. non-confirming) | |
5889 | -- Scalar_Storage_Order attribute definition. | |
5890 | ||
5891 | if Support_Nondefault_SSO_On_Target then | |
1e4b91fc | 5892 | Set_Reverse_Storage_Order (Base_Type (U_Ent), True); |
d7761b2d AC |
5893 | else |
5894 | Error_Msg_N | |
32b794c8 AC |
5895 | ("non-default Scalar_Storage_Order not supported on " |
5896 | & "target", Expr); | |
f91510fc AC |
5897 | end if; |
5898 | end if; | |
220d1fd9 AC |
5899 | |
5900 | -- Clear SSO default indications since explicit setting of the | |
5901 | -- order overrides the defaults. | |
5902 | ||
5903 | Set_SSO_Set_Low_By_Default (Base_Type (U_Ent), False); | |
5904 | Set_SSO_Set_High_By_Default (Base_Type (U_Ent), False); | |
f91510fc | 5905 | end if; |
f91510fc | 5906 | |
996ae0b0 RK |
5907 | ---------- |
5908 | -- Size -- | |
5909 | ---------- | |
5910 | ||
5911 | -- Size attribute definition clause | |
5912 | ||
5913 | when Attribute_Size => Size : declare | |
5914 | Size : constant Uint := Static_Integer (Expr); | |
5915 | Etyp : Entity_Id; | |
5916 | Biased : Boolean; | |
5917 | ||
5918 | begin | |
5919 | FOnly := True; | |
5920 | ||
0f1a6a0b AC |
5921 | if Duplicate_Clause then |
5922 | null; | |
996ae0b0 RK |
5923 | |
5924 | elsif not Is_Type (U_Ent) | |
5925 | and then Ekind (U_Ent) /= E_Variable | |
5926 | and then Ekind (U_Ent) /= E_Constant | |
5927 | then | |
5928 | Error_Msg_N ("size cannot be given for &", Nam); | |
5929 | ||
5930 | elsif Is_Array_Type (U_Ent) | |
5931 | and then not Is_Constrained (U_Ent) | |
5932 | then | |
5933 | Error_Msg_N | |
5934 | ("size cannot be given for unconstrained array", Nam); | |
5935 | ||
f4b049db | 5936 | elsif Size /= No_Uint then |
996ae0b0 RK |
5937 | if Is_Type (U_Ent) then |
5938 | Etyp := U_Ent; | |
5939 | else | |
5940 | Etyp := Etype (U_Ent); | |
5941 | end if; | |
5942 | ||
a9a5b8ac RD |
5943 | -- Check size, note that Gigi is in charge of checking that the |
5944 | -- size of an array or record type is OK. Also we do not check | |
5945 | -- the size in the ordinary fixed-point case, since it is too | |
5946 | -- early to do so (there may be subsequent small clause that | |
5947 | -- affects the size). We can check the size if a small clause | |
5948 | -- has already been given. | |
996ae0b0 RK |
5949 | |
5950 | if not Is_Ordinary_Fixed_Point_Type (U_Ent) | |
5951 | or else Has_Small_Clause (U_Ent) | |
5952 | then | |
5953 | Check_Size (Expr, Etyp, Size, Biased); | |
a3f2babd | 5954 | Set_Biased (U_Ent, N, "size clause", Biased); |
996ae0b0 RK |
5955 | end if; |
5956 | ||
5957 | -- For types set RM_Size and Esize if possible | |
5958 | ||
5959 | if Is_Type (U_Ent) then | |
5960 | Set_RM_Size (U_Ent, Size); | |
5961 | ||
fc893455 AC |
5962 | -- For elementary types, increase Object_Size to power of 2, |
5963 | -- but not less than a storage unit in any case (normally | |
a9a5b8ac | 5964 | -- this means it will be byte addressable). |
996ae0b0 | 5965 | |
fc893455 AC |
5966 | -- For all other types, nothing else to do, we leave Esize |
5967 | -- (object size) unset, the back end will set it from the | |
5968 | -- size and alignment in an appropriate manner. | |
5969 | ||
76af4137 AC |
5970 | -- In both cases, we check whether the alignment must be |
5971 | -- reset in the wake of the size change. | |
5972 | ||
fc893455 | 5973 | if Is_Elementary_Type (U_Ent) then |
07fc65c4 GB |
5974 | if Size <= System_Storage_Unit then |
5975 | Init_Esize (U_Ent, System_Storage_Unit); | |
996ae0b0 RK |
5976 | elsif Size <= 16 then |
5977 | Init_Esize (U_Ent, 16); | |
5978 | elsif Size <= 32 then | |
5979 | Init_Esize (U_Ent, 32); | |
5980 | else | |
5981 | Set_Esize (U_Ent, (Size + 63) / 64 * 64); | |
5982 | end if; | |
5983 | ||
76af4137 AC |
5984 | Alignment_Check_For_Size_Change (U_Ent, Esize (U_Ent)); |
5985 | else | |
5986 | Alignment_Check_For_Size_Change (U_Ent, Size); | |
996ae0b0 RK |
5987 | end if; |
5988 | ||
996ae0b0 RK |
5989 | -- For objects, set Esize only |
5990 | ||
5991 | else | |
32b794c8 | 5992 | -- The following error is suppressed in ASIS mode to allow |
2cc2e964 | 5993 | -- for different ASIS back ends or ASIS-based tools to query |
32b794c8 AC |
5994 | -- the illegal clause. |
5995 | ||
5996 | if Is_Elementary_Type (Etyp) | |
5997 | and then Size /= System_Storage_Unit | |
5998 | and then Size /= System_Storage_Unit * 2 | |
5999 | and then Size /= System_Storage_Unit * 4 | |
6000 | and then Size /= System_Storage_Unit * 8 | |
6001 | and then not ASIS_Mode | |
6002 | then | |
6003 | Error_Msg_Uint_1 := UI_From_Int (System_Storage_Unit); | |
6004 | Error_Msg_Uint_2 := Error_Msg_Uint_1 * 8; | |
6005 | Error_Msg_N | |
6006 | ("size for primitive object must be a power of 2 in " | |
6007 | & "the range ^-^", N); | |
fbf5a39b AC |
6008 | end if; |
6009 | ||
996ae0b0 RK |
6010 | Set_Esize (U_Ent, Size); |
6011 | end if; | |
6012 | ||
6013 | Set_Has_Size_Clause (U_Ent); | |
6014 | end if; | |
6015 | end Size; | |
6016 | ||
6017 | ----------- | |
6018 | -- Small -- | |
6019 | ----------- | |
6020 | ||
6021 | -- Small attribute definition clause | |
6022 | ||
6023 | when Attribute_Small => Small : declare | |
6024 | Implicit_Base : constant Entity_Id := Base_Type (U_Ent); | |
6025 | Small : Ureal; | |
6026 | ||
6027 | begin | |
6028 | Analyze_And_Resolve (Expr, Any_Real); | |
6029 | ||
6030 | if Etype (Expr) = Any_Type then | |
6031 | return; | |
6032 | ||
edab6088 | 6033 | elsif not Is_OK_Static_Expression (Expr) then |
fbf5a39b AC |
6034 | Flag_Non_Static_Expr |
6035 | ("small requires static expression!", Expr); | |
996ae0b0 RK |
6036 | return; |
6037 | ||
6038 | else | |
6039 | Small := Expr_Value_R (Expr); | |
6040 | ||
6041 | if Small <= Ureal_0 then | |
6042 | Error_Msg_N ("small value must be greater than zero", Expr); | |
6043 | return; | |
6044 | end if; | |
6045 | ||
6046 | end if; | |
6047 | ||
6048 | if not Is_Ordinary_Fixed_Point_Type (U_Ent) then | |
6049 | Error_Msg_N | |
6050 | ("small requires an ordinary fixed point type", Nam); | |
6051 | ||
6052 | elsif Has_Small_Clause (U_Ent) then | |
6053 | Error_Msg_N ("small already given for &", Nam); | |
6054 | ||
6055 | elsif Small > Delta_Value (U_Ent) then | |
6056 | Error_Msg_N | |
d99ff0f4 | 6057 | ("small value must not be greater than delta value", Nam); |
996ae0b0 RK |
6058 | |
6059 | else | |
6060 | Set_Small_Value (U_Ent, Small); | |
6061 | Set_Small_Value (Implicit_Base, Small); | |
6062 | Set_Has_Small_Clause (U_Ent); | |
6063 | Set_Has_Small_Clause (Implicit_Base); | |
6064 | Set_Has_Non_Standard_Rep (Implicit_Base); | |
6065 | end if; | |
6066 | end Small; | |
6067 | ||
996ae0b0 RK |
6068 | ------------------ |
6069 | -- Storage_Pool -- | |
6070 | ------------------ | |
6071 | ||
6072 | -- Storage_Pool attribute definition clause | |
6073 | ||
d8f43ee6 HK |
6074 | when Attribute_Simple_Storage_Pool |
6075 | | Attribute_Storage_Pool | |
6076 | => | |
6077 | Storage_Pool : declare | |
996ae0b0 | 6078 | Pool : Entity_Id; |
fe98a6aa | 6079 | T : Entity_Id; |
996ae0b0 RK |
6080 | |
6081 | begin | |
affbee12 RD |
6082 | if Ekind (U_Ent) = E_Access_Subprogram_Type then |
6083 | Error_Msg_N | |
6084 | ("storage pool cannot be given for access-to-subprogram type", | |
6085 | Nam); | |
6086 | return; | |
6087 | ||
d8f43ee6 | 6088 | elsif not Ekind_In (U_Ent, E_Access_Type, E_General_Access_Type) |
996ae0b0 | 6089 | then |
affbee12 RD |
6090 | Error_Msg_N |
6091 | ("storage pool can only be given for access types", Nam); | |
996ae0b0 RK |
6092 | return; |
6093 | ||
6094 | elsif Is_Derived_Type (U_Ent) then | |
6095 | Error_Msg_N | |
6096 | ("storage pool cannot be given for a derived access type", | |
6097 | Nam); | |
6098 | ||
0f1a6a0b | 6099 | elsif Duplicate_Clause then |
996ae0b0 RK |
6100 | return; |
6101 | ||
6102 | elsif Present (Associated_Storage_Pool (U_Ent)) then | |
6103 | Error_Msg_N ("storage pool already given for &", Nam); | |
6104 | return; | |
6105 | end if; | |
6106 | ||
113a62d9 RD |
6107 | -- Check for Storage_Size previously given |
6108 | ||
6109 | declare | |
6110 | SS : constant Node_Id := | |
6111 | Get_Attribute_Definition_Clause | |
6112 | (U_Ent, Attribute_Storage_Size); | |
6113 | begin | |
6114 | if Present (SS) then | |
6115 | Check_Pool_Size_Clash (U_Ent, N, SS); | |
6116 | end if; | |
6117 | end; | |
6118 | ||
6119 | -- Storage_Pool case | |
6120 | ||
a8551b5f AC |
6121 | if Id = Attribute_Storage_Pool then |
6122 | Analyze_And_Resolve | |
6123 | (Expr, Class_Wide_Type (RTE (RE_Root_Storage_Pool))); | |
6124 | ||
6125 | -- In the Simple_Storage_Pool case, we allow a variable of any | |
f6205414 | 6126 | -- simple storage pool type, so we Resolve without imposing an |
a8551b5f AC |
6127 | -- expected type. |
6128 | ||
6129 | else | |
6130 | Analyze_And_Resolve (Expr); | |
6131 | ||
6132 | if not Present (Get_Rep_Pragma | |
f6205414 | 6133 | (Etype (Expr), Name_Simple_Storage_Pool_Type)) |
a8551b5f AC |
6134 | then |
6135 | Error_Msg_N | |
6136 | ("expression must be of a simple storage pool type", Expr); | |
6137 | end if; | |
6138 | end if; | |
996ae0b0 | 6139 | |
cb572b75 ST |
6140 | if not Denotes_Variable (Expr) then |
6141 | Error_Msg_N ("storage pool must be a variable", Expr); | |
6142 | return; | |
6143 | end if; | |
6144 | ||
fe98a6aa CC |
6145 | if Nkind (Expr) = N_Type_Conversion then |
6146 | T := Etype (Expression (Expr)); | |
6147 | else | |
6148 | T := Etype (Expr); | |
6149 | end if; | |
6150 | ||
6151 | -- The Stack_Bounded_Pool is used internally for implementing | |
a01b9df6 AC |
6152 | -- access types with a Storage_Size. Since it only work properly |
6153 | -- when used on one specific type, we need to check that it is not | |
6154 | -- hijacked improperly: | |
6155 | ||
fe98a6aa CC |
6156 | -- type T is access Integer; |
6157 | -- for T'Storage_Size use n; | |
6158 | -- type Q is access Float; | |
6159 | -- for Q'Storage_Size use T'Storage_Size; -- incorrect | |
6160 | ||
8f7770f9 RD |
6161 | if RTE_Available (RE_Stack_Bounded_Pool) |
6162 | and then Base_Type (T) = RTE (RE_Stack_Bounded_Pool) | |
6163 | then | |
6164 | Error_Msg_N ("non-shareable internal Pool", Expr); | |
fe98a6aa CC |
6165 | return; |
6166 | end if; | |
6167 | ||
996ae0b0 RK |
6168 | -- If the argument is a name that is not an entity name, then |
6169 | -- we construct a renaming operation to define an entity of | |
6170 | -- type storage pool. | |
6171 | ||
6172 | if not Is_Entity_Name (Expr) | |
6173 | and then Is_Object_Reference (Expr) | |
6174 | then | |
092ef350 | 6175 | Pool := Make_Temporary (Loc, 'P', Expr); |
996ae0b0 RK |
6176 | |
6177 | declare | |
6178 | Rnode : constant Node_Id := | |
6179 | Make_Object_Renaming_Declaration (Loc, | |
6180 | Defining_Identifier => Pool, | |
6181 | Subtype_Mark => | |
6182 | New_Occurrence_Of (Etype (Expr), Loc), | |
092ef350 | 6183 | Name => Expr); |
996ae0b0 RK |
6184 | |
6185 | begin | |
9e92ad49 AC |
6186 | -- If the attribute definition clause comes from an aspect |
6187 | -- clause, then insert the renaming before the associated | |
6188 | -- entity's declaration, since the attribute clause has | |
6189 | -- not yet been appended to the declaration list. | |
6190 | ||
6191 | if From_Aspect_Specification (N) then | |
6192 | Insert_Before (Parent (Entity (N)), Rnode); | |
6193 | else | |
6194 | Insert_Before (N, Rnode); | |
6195 | end if; | |
6196 | ||
996ae0b0 RK |
6197 | Analyze (Rnode); |
6198 | Set_Associated_Storage_Pool (U_Ent, Pool); | |
6199 | end; | |
6200 | ||
6201 | elsif Is_Entity_Name (Expr) then | |
6202 | Pool := Entity (Expr); | |
6203 | ||
6204 | -- If pool is a renamed object, get original one. This can | |
6205 | -- happen with an explicit renaming, and within instances. | |
6206 | ||
6207 | while Present (Renamed_Object (Pool)) | |
6208 | and then Is_Entity_Name (Renamed_Object (Pool)) | |
6209 | loop | |
6210 | Pool := Entity (Renamed_Object (Pool)); | |
6211 | end loop; | |
6212 | ||
6213 | if Present (Renamed_Object (Pool)) | |
6214 | and then Nkind (Renamed_Object (Pool)) = N_Type_Conversion | |
6215 | and then Is_Entity_Name (Expression (Renamed_Object (Pool))) | |
6216 | then | |
6217 | Pool := Entity (Expression (Renamed_Object (Pool))); | |
6218 | end if; | |
6219 | ||
fe98a6aa | 6220 | Set_Associated_Storage_Pool (U_Ent, Pool); |
996ae0b0 RK |
6221 | |
6222 | elsif Nkind (Expr) = N_Type_Conversion | |
6223 | and then Is_Entity_Name (Expression (Expr)) | |
6224 | and then Nkind (Original_Node (Expr)) = N_Attribute_Reference | |
6225 | then | |
6226 | Pool := Entity (Expression (Expr)); | |
fe98a6aa | 6227 | Set_Associated_Storage_Pool (U_Ent, Pool); |
996ae0b0 RK |
6228 | |
6229 | else | |
6230 | Error_Msg_N ("incorrect reference to a Storage Pool", Expr); | |
6231 | return; | |
6232 | end if; | |
d8f43ee6 | 6233 | end Storage_Pool; |
996ae0b0 | 6234 | |
affbee12 RD |
6235 | ------------------ |
6236 | -- Storage_Size -- | |
6237 | ------------------ | |
6238 | ||
6239 | -- Storage_Size attribute definition clause | |
6240 | ||
6241 | when Attribute_Storage_Size => Storage_Size : declare | |
6242 | Btype : constant Entity_Id := Base_Type (U_Ent); | |
affbee12 RD |
6243 | |
6244 | begin | |
6245 | if Is_Task_Type (U_Ent) then | |
affbee12 | 6246 | |
a90bd866 | 6247 | -- Check obsolescent (but never obsolescent if from aspect) |
2cbac6c6 AC |
6248 | |
6249 | if not From_Aspect_Specification (N) then | |
6250 | Check_Restriction (No_Obsolescent_Features, N); | |
6251 | ||
6252 | if Warn_On_Obsolescent_Feature then | |
6253 | Error_Msg_N | |
32b794c8 AC |
6254 | ("?j?storage size clause for task is an obsolescent " |
6255 | & "feature (RM J.9)", N); | |
2cbac6c6 AC |
6256 | Error_Msg_N ("\?j?use Storage_Size pragma instead", N); |
6257 | end if; | |
affbee12 RD |
6258 | end if; |
6259 | ||
6260 | FOnly := True; | |
6261 | end if; | |
6262 | ||
6263 | if not Is_Access_Type (U_Ent) | |
6264 | and then Ekind (U_Ent) /= E_Task_Type | |
6265 | then | |
6266 | Error_Msg_N ("storage size cannot be given for &", Nam); | |
6267 | ||
6268 | elsif Is_Access_Type (U_Ent) and Is_Derived_Type (U_Ent) then | |
6269 | Error_Msg_N | |
6270 | ("storage size cannot be given for a derived access type", | |
6271 | Nam); | |
6272 | ||
0f1a6a0b AC |
6273 | elsif Duplicate_Clause then |
6274 | null; | |
affbee12 RD |
6275 | |
6276 | else | |
6277 | Analyze_And_Resolve (Expr, Any_Integer); | |
6278 | ||
6279 | if Is_Access_Type (U_Ent) then | |
113a62d9 RD |
6280 | |
6281 | -- Check for Storage_Pool previously given | |
6282 | ||
6283 | declare | |
6284 | SP : constant Node_Id := | |
6285 | Get_Attribute_Definition_Clause | |
6286 | (U_Ent, Attribute_Storage_Pool); | |
6287 | ||
6288 | begin | |
6289 | if Present (SP) then | |
6290 | Check_Pool_Size_Clash (U_Ent, SP, N); | |
6291 | end if; | |
6292 | end; | |
6293 | ||
6294 | -- Special case of for x'Storage_Size use 0 | |
affbee12 | 6295 | |
8da337c5 | 6296 | if Is_OK_Static_Expression (Expr) |
affbee12 RD |
6297 | and then Expr_Value (Expr) = 0 |
6298 | then | |
6299 | Set_No_Pool_Assigned (Btype); | |
6300 | end if; | |
affbee12 RD |
6301 | end if; |
6302 | ||
6303 | Set_Has_Storage_Size_Clause (Btype); | |
6304 | end if; | |
6305 | end Storage_Size; | |
6306 | ||
82c80734 RD |
6307 | ----------------- |
6308 | -- Stream_Size -- | |
6309 | ----------------- | |
6310 | ||
6311 | when Attribute_Stream_Size => Stream_Size : declare | |
6312 | Size : constant Uint := Static_Integer (Expr); | |
6313 | ||
6314 | begin | |
8f7770f9 RD |
6315 | if Ada_Version <= Ada_95 then |
6316 | Check_Restriction (No_Implementation_Attributes, N); | |
6317 | end if; | |
6318 | ||
0f1a6a0b AC |
6319 | if Duplicate_Clause then |
6320 | null; | |
82c80734 RD |
6321 | |
6322 | elsif Is_Elementary_Type (U_Ent) then | |
32b794c8 AC |
6323 | |
6324 | -- The following errors are suppressed in ASIS mode to allow | |
2cc2e964 | 6325 | -- for different ASIS back ends or ASIS-based tools to query |
32b794c8 AC |
6326 | -- the illegal clause. |
6327 | ||
6328 | if ASIS_Mode then | |
6329 | null; | |
6330 | ||
6331 | elsif Size /= System_Storage_Unit | |
6332 | and then Size /= System_Storage_Unit * 2 | |
6333 | and then Size /= System_Storage_Unit * 4 | |
6334 | and then Size /= System_Storage_Unit * 8 | |
82c80734 RD |
6335 | then |
6336 | Error_Msg_Uint_1 := UI_From_Int (System_Storage_Unit); | |
6337 | Error_Msg_N | |
32b794c8 AC |
6338 | ("stream size for elementary type must be a power of 2 " |
6339 | & "and at least ^", N); | |
82c80734 RD |
6340 | |
6341 | elsif RM_Size (U_Ent) > Size then | |
6342 | Error_Msg_Uint_1 := RM_Size (U_Ent); | |
6343 | Error_Msg_N | |
32b794c8 AC |
6344 | ("stream size for elementary type must be a power of 2 " |
6345 | & "and at least ^", N); | |
82c80734 RD |
6346 | end if; |
6347 | ||
6348 | Set_Has_Stream_Size_Clause (U_Ent); | |
6349 | ||
6350 | else | |
6351 | Error_Msg_N ("Stream_Size cannot be given for &", Nam); | |
6352 | end if; | |
6353 | end Stream_Size; | |
6354 | ||
996ae0b0 RK |
6355 | ---------------- |
6356 | -- Value_Size -- | |
6357 | ---------------- | |
6358 | ||
6359 | -- Value_Size attribute definition clause | |
6360 | ||
6361 | when Attribute_Value_Size => Value_Size : declare | |
6362 | Size : constant Uint := Static_Integer (Expr); | |
6363 | Biased : Boolean; | |
6364 | ||
6365 | begin | |
6366 | if not Is_Type (U_Ent) then | |
6367 | Error_Msg_N ("Value_Size cannot be given for &", Nam); | |
6368 | ||
0f1a6a0b AC |
6369 | elsif Duplicate_Clause then |
6370 | null; | |
996ae0b0 | 6371 | |
a9a5b8ac RD |
6372 | elsif Is_Array_Type (U_Ent) |
6373 | and then not Is_Constrained (U_Ent) | |
6374 | then | |
6375 | Error_Msg_N | |
6376 | ("Value_Size cannot be given for unconstrained array", Nam); | |
6377 | ||
996ae0b0 RK |
6378 | else |
6379 | if Is_Elementary_Type (U_Ent) then | |
6380 | Check_Size (Expr, U_Ent, Size, Biased); | |
a3f2babd | 6381 | Set_Biased (U_Ent, N, "value size clause", Biased); |
996ae0b0 RK |
6382 | end if; |
6383 | ||
6384 | Set_RM_Size (U_Ent, Size); | |
6385 | end if; | |
6386 | end Value_Size; | |
6387 | ||
d50f4827 AC |
6388 | ----------------------- |
6389 | -- Variable_Indexing -- | |
6390 | ----------------------- | |
6391 | ||
6392 | when Attribute_Variable_Indexing => | |
6393 | Check_Indexing_Functions; | |
6394 | ||
996ae0b0 RK |
6395 | ----------- |
6396 | -- Write -- | |
6397 | ----------- | |
6398 | ||
edd63e9b ES |
6399 | when Attribute_Write => |
6400 | Analyze_Stream_TSS_Definition (TSS_Stream_Write); | |
6401 | Set_Has_Specified_Stream_Write (Ent); | |
996ae0b0 RK |
6402 | |
6403 | -- All other attributes cannot be set | |
6404 | ||
6405 | when others => | |
6406 | Error_Msg_N | |
6407 | ("attribute& cannot be set with definition clause", N); | |
996ae0b0 RK |
6408 | end case; |
6409 | ||
a01b9df6 AC |
6410 | -- The test for the type being frozen must be performed after any |
6411 | -- expression the clause has been analyzed since the expression itself | |
6412 | -- might cause freezing that makes the clause illegal. | |
996ae0b0 RK |
6413 | |
6414 | if Rep_Item_Too_Late (U_Ent, N, FOnly) then | |
6415 | return; | |
6416 | end if; | |
6417 | end Analyze_Attribute_Definition_Clause; | |
6418 | ||
6419 | ---------------------------- | |
6420 | -- Analyze_Code_Statement -- | |
6421 | ---------------------------- | |
6422 | ||
6423 | procedure Analyze_Code_Statement (N : Node_Id) is | |
6424 | HSS : constant Node_Id := Parent (N); | |
6425 | SBody : constant Node_Id := Parent (HSS); | |
6426 | Subp : constant Entity_Id := Current_Scope; | |
6427 | Stmt : Node_Id; | |
6428 | Decl : Node_Id; | |
6429 | StmtO : Node_Id; | |
6430 | DeclO : Node_Id; | |
6431 | ||
6432 | begin | |
0fe797c5 SB |
6433 | -- Accept foreign code statements for CodePeer. The analysis is skipped |
6434 | -- to avoid rejecting unrecognized constructs. | |
6435 | ||
6436 | if CodePeer_Mode then | |
6437 | Set_Analyzed (N); | |
6438 | return; | |
6439 | end if; | |
6440 | ||
996ae0b0 | 6441 | -- Analyze and check we get right type, note that this implements the |
0fe797c5 SB |
6442 | -- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that is |
6443 | -- the only way that Asm_Insn could possibly be visible. | |
996ae0b0 RK |
6444 | |
6445 | Analyze_And_Resolve (Expression (N)); | |
6446 | ||
6447 | if Etype (Expression (N)) = Any_Type then | |
6448 | return; | |
6449 | elsif Etype (Expression (N)) /= RTE (RE_Asm_Insn) then | |
6450 | Error_Msg_N ("incorrect type for code statement", N); | |
6451 | return; | |
6452 | end if; | |
6453 | ||
affbee12 RD |
6454 | Check_Code_Statement (N); |
6455 | ||
0fe797c5 SB |
6456 | -- Make sure we appear in the handled statement sequence of a subprogram |
6457 | -- (RM 13.8(3)). | |
996ae0b0 RK |
6458 | |
6459 | if Nkind (HSS) /= N_Handled_Sequence_Of_Statements | |
6460 | or else Nkind (SBody) /= N_Subprogram_Body | |
6461 | then | |
6462 | Error_Msg_N | |
6463 | ("code statement can only appear in body of subprogram", N); | |
6464 | return; | |
6465 | end if; | |
6466 | ||
6467 | -- Do remaining checks (RM 13.8(3)) if not already done | |
6468 | ||
6469 | if not Is_Machine_Code_Subprogram (Subp) then | |
6470 | Set_Is_Machine_Code_Subprogram (Subp); | |
6471 | ||
6472 | -- No exception handlers allowed | |
6473 | ||
6474 | if Present (Exception_Handlers (HSS)) then | |
6475 | Error_Msg_N | |
6476 | ("exception handlers not permitted in machine code subprogram", | |
6477 | First (Exception_Handlers (HSS))); | |
6478 | end if; | |
6479 | ||
6480 | -- No declarations other than use clauses and pragmas (we allow | |
6481 | -- certain internally generated declarations as well). | |
6482 | ||
6483 | Decl := First (Declarations (SBody)); | |
6484 | while Present (Decl) loop | |
6485 | DeclO := Original_Node (Decl); | |
6486 | if Comes_From_Source (DeclO) | |
0503c53a RD |
6487 | and not Nkind_In (DeclO, N_Pragma, |
6488 | N_Use_Package_Clause, | |
6489 | N_Use_Type_Clause, | |
6490 | N_Implicit_Label_Declaration) | |
996ae0b0 RK |
6491 | then |
6492 | Error_Msg_N | |
6493 | ("this declaration not allowed in machine code subprogram", | |
6494 | DeclO); | |
6495 | end if; | |
6496 | ||
6497 | Next (Decl); | |
6498 | end loop; | |
6499 | ||
6500 | -- No statements other than code statements, pragmas, and labels. | |
6501 | -- Again we allow certain internally generated statements. | |
3e7302c3 | 6502 | |
9f8d1e5c AC |
6503 | -- In Ada 2012, qualified expressions are names, and the code |
6504 | -- statement is initially parsed as a procedure call. | |
996ae0b0 RK |
6505 | |
6506 | Stmt := First (Statements (HSS)); | |
6507 | while Present (Stmt) loop | |
6508 | StmtO := Original_Node (Stmt); | |
9f8d1e5c | 6509 | |
0fe797c5 | 6510 | -- A procedure call transformed into a code statement is OK |
af89615f | 6511 | |
9f8d1e5c AC |
6512 | if Ada_Version >= Ada_2012 |
6513 | and then Nkind (StmtO) = N_Procedure_Call_Statement | |
af89615f | 6514 | and then Nkind (Name (StmtO)) = N_Qualified_Expression |
9f8d1e5c AC |
6515 | then |
6516 | null; | |
6517 | ||
6518 | elsif Comes_From_Source (StmtO) | |
0503c53a RD |
6519 | and then not Nkind_In (StmtO, N_Pragma, |
6520 | N_Label, | |
6521 | N_Code_Statement) | |
996ae0b0 RK |
6522 | then |
6523 | Error_Msg_N | |
6524 | ("this statement is not allowed in machine code subprogram", | |
6525 | StmtO); | |
6526 | end if; | |
6527 | ||
6528 | Next (Stmt); | |
6529 | end loop; | |
6530 | end if; | |
996ae0b0 RK |
6531 | end Analyze_Code_Statement; |
6532 | ||
6533 | ----------------------------------------------- | |
6534 | -- Analyze_Enumeration_Representation_Clause -- | |
6535 | ----------------------------------------------- | |
6536 | ||
6537 | procedure Analyze_Enumeration_Representation_Clause (N : Node_Id) is | |
ac566cbe AC |
6538 | Ident : constant Node_Id := Identifier (N); |
6539 | Aggr : constant Node_Id := Array_Aggregate (N); | |
996ae0b0 RK |
6540 | Enumtype : Entity_Id; |
6541 | Elit : Entity_Id; | |
6542 | Expr : Node_Id; | |
6543 | Assoc : Node_Id; | |
6544 | Choice : Node_Id; | |
6545 | Val : Uint; | |
2c1b72d7 AC |
6546 | |
6547 | Err : Boolean := False; | |
686d0984 | 6548 | -- Set True to avoid cascade errors and crashes on incorrect source code |
996ae0b0 | 6549 | |
d69cf005 AC |
6550 | Lo : constant Uint := Expr_Value (Type_Low_Bound (Universal_Integer)); |
6551 | Hi : constant Uint := Expr_Value (Type_High_Bound (Universal_Integer)); | |
6552 | -- Allowed range of universal integer (= allowed range of enum lit vals) | |
6553 | ||
996ae0b0 RK |
6554 | Min : Uint; |
6555 | Max : Uint; | |
d69cf005 AC |
6556 | -- Minimum and maximum values of entries |
6557 | ||
5612989e | 6558 | Max_Node : Node_Id := Empty; -- init to avoid warning |
d69cf005 | 6559 | -- Pointer to node for literal providing max value |
996ae0b0 RK |
6560 | |
6561 | begin | |
f5afb270 | 6562 | if Ignore_Rep_Clauses then |
cf28c974 | 6563 | Kill_Rep_Clause (N); |
c690a2ec RD |
6564 | return; |
6565 | end if; | |
6566 | ||
8bfbd380 AC |
6567 | -- Ignore enumeration rep clauses by default in CodePeer mode, |
6568 | -- unless -gnatd.I is specified, as a work around for potential false | |
6569 | -- positive messages. | |
6570 | ||
6571 | if CodePeer_Mode and not Debug_Flag_Dot_II then | |
6572 | return; | |
6573 | end if; | |
6574 | ||
996ae0b0 RK |
6575 | -- First some basic error checks |
6576 | ||
6577 | Find_Type (Ident); | |
6578 | Enumtype := Entity (Ident); | |
6579 | ||
6580 | if Enumtype = Any_Type | |
6581 | or else Rep_Item_Too_Early (Enumtype, N) | |
6582 | then | |
6583 | return; | |
6584 | else | |
6585 | Enumtype := Underlying_Type (Enumtype); | |
6586 | end if; | |
6587 | ||
6588 | if not Is_Enumeration_Type (Enumtype) then | |
6589 | Error_Msg_NE | |
6590 | ("enumeration type required, found}", | |
6591 | Ident, First_Subtype (Enumtype)); | |
6592 | return; | |
6593 | end if; | |
6594 | ||
fbf5a39b AC |
6595 | -- Ignore rep clause on generic actual type. This will already have |
6596 | -- been flagged on the template as an error, and this is the safest | |
6597 | -- way to ensure we don't get a junk cascaded message in the instance. | |
6598 | ||
6599 | if Is_Generic_Actual_Type (Enumtype) then | |
6600 | return; | |
6601 | ||
6602 | -- Type must be in current scope | |
6603 | ||
6604 | elsif Scope (Enumtype) /= Current_Scope then | |
996ae0b0 RK |
6605 | Error_Msg_N ("type must be declared in this scope", Ident); |
6606 | return; | |
6607 | ||
fbf5a39b AC |
6608 | -- Type must be a first subtype |
6609 | ||
996ae0b0 RK |
6610 | elsif not Is_First_Subtype (Enumtype) then |
6611 | Error_Msg_N ("cannot give enumeration rep clause for subtype", N); | |
6612 | return; | |
6613 | ||
fbf5a39b AC |
6614 | -- Ignore duplicate rep clause |
6615 | ||
996ae0b0 RK |
6616 | elsif Has_Enumeration_Rep_Clause (Enumtype) then |
6617 | Error_Msg_N ("duplicate enumeration rep clause ignored", N); | |
6618 | return; | |
6619 | ||
82c80734 | 6620 | -- Don't allow rep clause for standard [wide_[wide_]]character |
fbf5a39b | 6621 | |
45fc7ddb | 6622 | elsif Is_Standard_Character_Type (Enumtype) then |
996ae0b0 | 6623 | Error_Msg_N ("enumeration rep clause not allowed for this type", N); |
fbf5a39b AC |
6624 | return; |
6625 | ||
27e6455d TQ |
6626 | -- Check that the expression is a proper aggregate (no parentheses) |
6627 | ||
6628 | elsif Paren_Count (Aggr) /= 0 then | |
6629 | Error_Msg | |
6630 | ("extra parentheses surrounding aggregate not allowed", | |
6631 | First_Sloc (Aggr)); | |
6632 | return; | |
6633 | ||
fbf5a39b | 6634 | -- All tests passed, so set rep clause in place |
996ae0b0 RK |
6635 | |
6636 | else | |
6637 | Set_Has_Enumeration_Rep_Clause (Enumtype); | |
6638 | Set_Has_Enumeration_Rep_Clause (Base_Type (Enumtype)); | |
6639 | end if; | |
6640 | ||
6641 | -- Now we process the aggregate. Note that we don't use the normal | |
6642 | -- aggregate code for this purpose, because we don't want any of the | |
6643 | -- normal expansion activities, and a number of special semantic | |
6644 | -- rules apply (including the component type being any integer type) | |
6645 | ||
996ae0b0 RK |
6646 | Elit := First_Literal (Enumtype); |
6647 | ||
6648 | -- First the positional entries if any | |
6649 | ||
6650 | if Present (Expressions (Aggr)) then | |
6651 | Expr := First (Expressions (Aggr)); | |
6652 | while Present (Expr) loop | |
6653 | if No (Elit) then | |
6654 | Error_Msg_N ("too many entries in aggregate", Expr); | |
6655 | return; | |
6656 | end if; | |
6657 | ||
6658 | Val := Static_Integer (Expr); | |
6659 | ||
27e6455d TQ |
6660 | -- Err signals that we found some incorrect entries processing |
6661 | -- the list. The final checks for completeness and ordering are | |
6662 | -- skipped in this case. | |
6663 | ||
996ae0b0 RK |
6664 | if Val = No_Uint then |
6665 | Err := True; | |
dc06dd83 | 6666 | |
996ae0b0 RK |
6667 | elsif Val < Lo or else Hi < Val then |
6668 | Error_Msg_N ("value outside permitted range", Expr); | |
6669 | Err := True; | |
6670 | end if; | |
6671 | ||
6672 | Set_Enumeration_Rep (Elit, Val); | |
6673 | Set_Enumeration_Rep_Expr (Elit, Expr); | |
6674 | Next (Expr); | |
6675 | Next (Elit); | |
6676 | end loop; | |
6677 | end if; | |
6678 | ||
6679 | -- Now process the named entries if present | |
6680 | ||
6681 | if Present (Component_Associations (Aggr)) then | |
6682 | Assoc := First (Component_Associations (Aggr)); | |
6683 | while Present (Assoc) loop | |
6684 | Choice := First (Choices (Assoc)); | |
6685 | ||
6686 | if Present (Next (Choice)) then | |
6687 | Error_Msg_N | |
6688 | ("multiple choice not allowed here", Next (Choice)); | |
6689 | Err := True; | |
6690 | end if; | |
6691 | ||
6692 | if Nkind (Choice) = N_Others_Choice then | |
6693 | Error_Msg_N ("others choice not allowed here", Choice); | |
6694 | Err := True; | |
6695 | ||
6696 | elsif Nkind (Choice) = N_Range then | |
2c1b72d7 | 6697 | |
996ae0b0 | 6698 | -- ??? should allow zero/one element range here |
2c1b72d7 | 6699 | |
996ae0b0 RK |
6700 | Error_Msg_N ("range not allowed here", Choice); |
6701 | Err := True; | |
6702 | ||
6703 | else | |
6704 | Analyze_And_Resolve (Choice, Enumtype); | |
2c1b72d7 | 6705 | |
686d0984 | 6706 | if Error_Posted (Choice) then |
996ae0b0 | 6707 | Err := True; |
686d0984 | 6708 | end if; |
996ae0b0 | 6709 | |
686d0984 AC |
6710 | if not Err then |
6711 | if Is_Entity_Name (Choice) | |
6712 | and then Is_Type (Entity (Choice)) | |
6713 | then | |
6714 | Error_Msg_N ("subtype name not allowed here", Choice); | |
996ae0b0 | 6715 | Err := True; |
2c1b72d7 | 6716 | |
686d0984 | 6717 | -- ??? should allow static subtype with zero/one entry |
996ae0b0 | 6718 | |
686d0984 | 6719 | elsif Etype (Choice) = Base_Type (Enumtype) then |
edab6088 | 6720 | if not Is_OK_Static_Expression (Choice) then |
686d0984 AC |
6721 | Flag_Non_Static_Expr |
6722 | ("non-static expression used for choice!", Choice); | |
996ae0b0 | 6723 | Err := True; |
996ae0b0 | 6724 | |
686d0984 AC |
6725 | else |
6726 | Elit := Expr_Value_E (Choice); | |
6727 | ||
6728 | if Present (Enumeration_Rep_Expr (Elit)) then | |
6729 | Error_Msg_Sloc := | |
6730 | Sloc (Enumeration_Rep_Expr (Elit)); | |
6731 | Error_Msg_NE | |
6732 | ("representation for& previously given#", | |
6733 | Choice, Elit); | |
6734 | Err := True; | |
6735 | end if; | |
996ae0b0 | 6736 | |
686d0984 | 6737 | Set_Enumeration_Rep_Expr (Elit, Expression (Assoc)); |
996ae0b0 | 6738 | |
686d0984 AC |
6739 | Expr := Expression (Assoc); |
6740 | Val := Static_Integer (Expr); | |
996ae0b0 | 6741 | |
686d0984 AC |
6742 | if Val = No_Uint then |
6743 | Err := True; | |
6744 | ||
6745 | elsif Val < Lo or else Hi < Val then | |
6746 | Error_Msg_N ("value outside permitted range", Expr); | |
6747 | Err := True; | |
6748 | end if; | |
996ae0b0 | 6749 | |
686d0984 AC |
6750 | Set_Enumeration_Rep (Elit, Val); |
6751 | end if; | |
996ae0b0 RK |
6752 | end if; |
6753 | end if; | |
6754 | end if; | |
6755 | ||
6756 | Next (Assoc); | |
6757 | end loop; | |
6758 | end if; | |
6759 | ||
6760 | -- Aggregate is fully processed. Now we check that a full set of | |
6761 | -- representations was given, and that they are in range and in order. | |
6762 | -- These checks are only done if no other errors occurred. | |
6763 | ||
6764 | if not Err then | |
6765 | Min := No_Uint; | |
6766 | Max := No_Uint; | |
6767 | ||
6768 | Elit := First_Literal (Enumtype); | |
6769 | while Present (Elit) loop | |
6770 | if No (Enumeration_Rep_Expr (Elit)) then | |
6771 | Error_Msg_NE ("missing representation for&!", N, Elit); | |
6772 | ||
6773 | else | |
6774 | Val := Enumeration_Rep (Elit); | |
6775 | ||
6776 | if Min = No_Uint then | |
6777 | Min := Val; | |
6778 | end if; | |
6779 | ||
6780 | if Val /= No_Uint then | |
6781 | if Max /= No_Uint and then Val <= Max then | |
6782 | Error_Msg_NE | |
6783 | ("enumeration value for& not ordered!", | |
d69cf005 | 6784 | Enumeration_Rep_Expr (Elit), Elit); |
996ae0b0 RK |
6785 | end if; |
6786 | ||
d69cf005 | 6787 | Max_Node := Enumeration_Rep_Expr (Elit); |
996ae0b0 RK |
6788 | Max := Val; |
6789 | end if; | |
6790 | ||
d69cf005 AC |
6791 | -- If there is at least one literal whose representation is not |
6792 | -- equal to the Pos value, then note that this enumeration type | |
6793 | -- has a non-standard representation. | |
996ae0b0 RK |
6794 | |
6795 | if Val /= Enumeration_Pos (Elit) then | |
6796 | Set_Has_Non_Standard_Rep (Base_Type (Enumtype)); | |
6797 | end if; | |
6798 | end if; | |
6799 | ||
6800 | Next (Elit); | |
6801 | end loop; | |
6802 | ||
6803 | -- Now set proper size information | |
6804 | ||
6805 | declare | |
6806 | Minsize : Uint := UI_From_Int (Minimum_Size (Enumtype)); | |
6807 | ||
6808 | begin | |
6809 | if Has_Size_Clause (Enumtype) then | |
d69cf005 AC |
6810 | |
6811 | -- All OK, if size is OK now | |
6812 | ||
6813 | if RM_Size (Enumtype) >= Minsize then | |
996ae0b0 RK |
6814 | null; |
6815 | ||
6816 | else | |
d69cf005 AC |
6817 | -- Try if we can get by with biasing |
6818 | ||
996ae0b0 RK |
6819 | Minsize := |
6820 | UI_From_Int (Minimum_Size (Enumtype, Biased => True)); | |
6821 | ||
d69cf005 AC |
6822 | -- Error message if even biasing does not work |
6823 | ||
6824 | if RM_Size (Enumtype) < Minsize then | |
6825 | Error_Msg_Uint_1 := RM_Size (Enumtype); | |
6826 | Error_Msg_Uint_2 := Max; | |
6827 | Error_Msg_N | |
6828 | ("previously given size (^) is too small " | |
6829 | & "for this value (^)", Max_Node); | |
6830 | ||
6831 | -- If biasing worked, indicate that we now have biased rep | |
996ae0b0 RK |
6832 | |
6833 | else | |
a3f2babd AC |
6834 | Set_Biased |
6835 | (Enumtype, Size_Clause (Enumtype), "size clause"); | |
996ae0b0 RK |
6836 | end if; |
6837 | end if; | |
6838 | ||
6839 | else | |
6840 | Set_RM_Size (Enumtype, Minsize); | |
6841 | Set_Enum_Esize (Enumtype); | |
6842 | end if; | |
6843 | ||
6844 | Set_RM_Size (Base_Type (Enumtype), RM_Size (Enumtype)); | |
6845 | Set_Esize (Base_Type (Enumtype), Esize (Enumtype)); | |
6846 | Set_Alignment (Base_Type (Enumtype), Alignment (Enumtype)); | |
6847 | end; | |
6848 | end if; | |
6849 | ||
a90bd866 | 6850 | -- We repeat the too late test in case it froze itself |
996ae0b0 RK |
6851 | |
6852 | if Rep_Item_Too_Late (Enumtype, N) then | |
6853 | null; | |
6854 | end if; | |
996ae0b0 RK |
6855 | end Analyze_Enumeration_Representation_Clause; |
6856 | ||
6857 | ---------------------------- | |
6858 | -- Analyze_Free_Statement -- | |
6859 | ---------------------------- | |
6860 | ||
6861 | procedure Analyze_Free_Statement (N : Node_Id) is | |
6862 | begin | |
6863 | Analyze (Expression (N)); | |
6864 | end Analyze_Free_Statement; | |
6865 | ||
3ff38f33 JM |
6866 | --------------------------- |
6867 | -- Analyze_Freeze_Entity -- | |
6868 | --------------------------- | |
6869 | ||
6870 | procedure Analyze_Freeze_Entity (N : Node_Id) is | |
3ff38f33 | 6871 | begin |
5a8a6763 RD |
6872 | Freeze_Entity_Checks (N); |
6873 | end Analyze_Freeze_Entity; | |
947430d5 | 6874 | |
5a8a6763 RD |
6875 | ----------------------------------- |
6876 | -- Analyze_Freeze_Generic_Entity -- | |
6877 | ----------------------------------- | |
947430d5 | 6878 | |
5a8a6763 | 6879 | procedure Analyze_Freeze_Generic_Entity (N : Node_Id) is |
d030f3a4 AC |
6880 | E : constant Entity_Id := Entity (N); |
6881 | ||
5a8a6763 | 6882 | begin |
d030f3a4 AC |
6883 | if not Is_Frozen (E) and then Has_Delayed_Aspects (E) then |
6884 | Analyze_Aspects_At_Freeze_Point (E); | |
6885 | end if; | |
6886 | ||
5a8a6763 RD |
6887 | Freeze_Entity_Checks (N); |
6888 | end Analyze_Freeze_Generic_Entity; | |
3ff38f33 | 6889 | |
5a8a6763 RD |
6890 | ------------------------------------------ |
6891 | -- Analyze_Record_Representation_Clause -- | |
6892 | ------------------------------------------ | |
b4d7b435 | 6893 | |
5a8a6763 RD |
6894 | -- Note: we check as much as we can here, but we can't do any checks |
6895 | -- based on the position values (e.g. overlap checks) until freeze time | |
6896 | -- because especially in Ada 2005 (machine scalar mode), the processing | |
6897 | -- for non-standard bit order can substantially change the positions. | |
6898 | -- See procedure Check_Record_Representation_Clause (called from Freeze) | |
6899 | -- for the remainder of this processing. | |
cefce34c | 6900 | |
5a8a6763 RD |
6901 | procedure Analyze_Record_Representation_Clause (N : Node_Id) is |
6902 | Ident : constant Node_Id := Identifier (N); | |
6903 | Biased : Boolean; | |
6904 | CC : Node_Id; | |
6905 | Comp : Entity_Id; | |
6906 | Fbit : Uint; | |
6907 | Hbit : Uint := Uint_0; | |
6908 | Lbit : Uint; | |
6909 | Ocomp : Entity_Id; | |
6910 | Posit : Uint; | |
6911 | Rectype : Entity_Id; | |
6912 | Recdef : Node_Id; | |
cefce34c | 6913 | |
5a8a6763 RD |
6914 | function Is_Inherited (Comp : Entity_Id) return Boolean; |
6915 | -- True if Comp is an inherited component in a record extension | |
cefce34c | 6916 | |
5a8a6763 RD |
6917 | ------------------ |
6918 | -- Is_Inherited -- | |
6919 | ------------------ | |
cefce34c | 6920 | |
5a8a6763 RD |
6921 | function Is_Inherited (Comp : Entity_Id) return Boolean is |
6922 | Comp_Base : Entity_Id; | |
cefce34c | 6923 | |
5a8a6763 RD |
6924 | begin |
6925 | if Ekind (Rectype) = E_Record_Subtype then | |
6926 | Comp_Base := Original_Record_Component (Comp); | |
6927 | else | |
6928 | Comp_Base := Comp; | |
cefce34c JM |
6929 | end if; |
6930 | ||
5a8a6763 RD |
6931 | return Comp_Base /= Original_Record_Component (Comp_Base); |
6932 | end Is_Inherited; | |
cefce34c | 6933 | |
5a8a6763 | 6934 | -- Local variables |
cefce34c | 6935 | |
5a8a6763 RD |
6936 | Is_Record_Extension : Boolean; |
6937 | -- True if Rectype is a record extension | |
cefce34c | 6938 | |
5a8a6763 RD |
6939 | CR_Pragma : Node_Id := Empty; |
6940 | -- Points to N_Pragma node if Complete_Representation pragma present | |
cefce34c | 6941 | |
5a8a6763 | 6942 | -- Start of processing for Analyze_Record_Representation_Clause |
cefce34c | 6943 | |
5a8a6763 RD |
6944 | begin |
6945 | if Ignore_Rep_Clauses then | |
cf28c974 | 6946 | Kill_Rep_Clause (N); |
5a8a6763 | 6947 | return; |
cefce34c | 6948 | end if; |
947430d5 | 6949 | |
5a8a6763 RD |
6950 | Find_Type (Ident); |
6951 | Rectype := Entity (Ident); | |
70805b88 | 6952 | |
5a8a6763 RD |
6953 | if Rectype = Any_Type or else Rep_Item_Too_Early (Rectype, N) then |
6954 | return; | |
6955 | else | |
6956 | Rectype := Underlying_Type (Rectype); | |
6957 | end if; | |
70805b88 | 6958 | |
5a8a6763 | 6959 | -- First some basic error checks |
70805b88 | 6960 | |
5a8a6763 RD |
6961 | if not Is_Record_Type (Rectype) then |
6962 | Error_Msg_NE | |
6963 | ("record type required, found}", Ident, First_Subtype (Rectype)); | |
6964 | return; | |
70805b88 | 6965 | |
5a8a6763 RD |
6966 | elsif Scope (Rectype) /= Current_Scope then |
6967 | Error_Msg_N ("type must be declared in this scope", N); | |
6968 | return; | |
70805b88 | 6969 | |
5a8a6763 RD |
6970 | elsif not Is_First_Subtype (Rectype) then |
6971 | Error_Msg_N ("cannot give record rep clause for subtype", N); | |
6972 | return; | |
86200f66 | 6973 | |
5a8a6763 RD |
6974 | elsif Has_Record_Rep_Clause (Rectype) then |
6975 | Error_Msg_N ("duplicate record rep clause ignored", N); | |
6976 | return; | |
86200f66 | 6977 | |
5a8a6763 RD |
6978 | elsif Rep_Item_Too_Late (Rectype, N) then |
6979 | return; | |
86200f66 | 6980 | end if; |
bd949ee2 | 6981 | |
7d9880c9 | 6982 | -- We know we have a first subtype, now possibly go to the anonymous |
5a8a6763 | 6983 | -- base type to determine whether Rectype is a record extension. |
b98e2969 | 6984 | |
5a8a6763 RD |
6985 | Recdef := Type_Definition (Declaration_Node (Base_Type (Rectype))); |
6986 | Is_Record_Extension := | |
6987 | Nkind (Recdef) = N_Derived_Type_Definition | |
6988 | and then Present (Record_Extension_Part (Recdef)); | |
b98e2969 | 6989 | |
5a8a6763 | 6990 | if Present (Mod_Clause (N)) then |
bd949ee2 | 6991 | declare |
5a8a6763 RD |
6992 | Loc : constant Source_Ptr := Sloc (N); |
6993 | M : constant Node_Id := Mod_Clause (N); | |
6994 | P : constant List_Id := Pragmas_Before (M); | |
6995 | AtM_Nod : Node_Id; | |
6996 | ||
6997 | Mod_Val : Uint; | |
6998 | pragma Warnings (Off, Mod_Val); | |
bd949ee2 RD |
6999 | |
7000 | begin | |
5a8a6763 | 7001 | Check_Restriction (No_Obsolescent_Features, Mod_Clause (N)); |
bd949ee2 | 7002 | |
5a8a6763 RD |
7003 | if Warn_On_Obsolescent_Feature then |
7004 | Error_Msg_N | |
7005 | ("?j?mod clause is an obsolescent feature (RM J.8)", N); | |
7006 | Error_Msg_N | |
7007 | ("\?j?use alignment attribute definition clause instead", N); | |
7008 | end if; | |
bd949ee2 | 7009 | |
5a8a6763 RD |
7010 | if Present (P) then |
7011 | Analyze_List (P); | |
7012 | end if; | |
b98e2969 | 7013 | |
5a8a6763 RD |
7014 | -- In ASIS_Mode mode, expansion is disabled, but we must convert |
7015 | -- the Mod clause into an alignment clause anyway, so that the | |
8a0183fd | 7016 | -- back end can compute and back-annotate properly the size and |
5a8a6763 | 7017 | -- alignment of types that may include this record. |
c76bf0bf | 7018 | |
5a8a6763 RD |
7019 | -- This seems dubious, this destroys the source tree in a manner |
7020 | -- not detectable by ASIS ??? | |
c76bf0bf | 7021 | |
5a8a6763 RD |
7022 | if Operating_Mode = Check_Semantics and then ASIS_Mode then |
7023 | AtM_Nod := | |
7024 | Make_Attribute_Definition_Clause (Loc, | |
e4494292 | 7025 | Name => New_Occurrence_Of (Base_Type (Rectype), Loc), |
5a8a6763 RD |
7026 | Chars => Name_Alignment, |
7027 | Expression => Relocate_Node (Expression (M))); | |
c76bf0bf | 7028 | |
5a8a6763 RD |
7029 | Set_From_At_Mod (AtM_Nod); |
7030 | Insert_After (N, AtM_Nod); | |
7031 | Mod_Val := Get_Alignment_Value (Expression (AtM_Nod)); | |
7032 | Set_Mod_Clause (N, Empty); | |
c76bf0bf | 7033 | |
5a8a6763 RD |
7034 | else |
7035 | -- Get the alignment value to perform error checking | |
c76bf0bf | 7036 | |
5a8a6763 RD |
7037 | Mod_Val := Get_Alignment_Value (Expression (M)); |
7038 | end if; | |
7039 | end; | |
7040 | end if; | |
c76bf0bf | 7041 | |
5a8a6763 RD |
7042 | -- For untagged types, clear any existing component clauses for the |
7043 | -- type. If the type is derived, this is what allows us to override | |
7044 | -- a rep clause for the parent. For type extensions, the representation | |
7045 | -- of the inherited components is inherited, so we want to keep previous | |
7046 | -- component clauses for completeness. | |
c76bf0bf | 7047 | |
5a8a6763 RD |
7048 | if not Is_Tagged_Type (Rectype) then |
7049 | Comp := First_Component_Or_Discriminant (Rectype); | |
7050 | while Present (Comp) loop | |
7051 | Set_Component_Clause (Comp, Empty); | |
7052 | Next_Component_Or_Discriminant (Comp); | |
7053 | end loop; | |
7054 | end if; | |
c76bf0bf | 7055 | |
5a8a6763 | 7056 | -- All done if no component clauses |
c76bf0bf | 7057 | |
5a8a6763 | 7058 | CC := First (Component_Clauses (N)); |
c76bf0bf | 7059 | |
5a8a6763 RD |
7060 | if No (CC) then |
7061 | return; | |
7062 | end if; | |
c76bf0bf | 7063 | |
5a8a6763 | 7064 | -- A representation like this applies to the base type |
c76bf0bf | 7065 | |
5a8a6763 RD |
7066 | Set_Has_Record_Rep_Clause (Base_Type (Rectype)); |
7067 | Set_Has_Non_Standard_Rep (Base_Type (Rectype)); | |
7068 | Set_Has_Specified_Layout (Base_Type (Rectype)); | |
c76bf0bf | 7069 | |
5a8a6763 | 7070 | -- Process the component clauses |
c76bf0bf | 7071 | |
5a8a6763 | 7072 | while Present (CC) loop |
c76bf0bf | 7073 | |
5a8a6763 | 7074 | -- Pragma |
c76bf0bf | 7075 | |
5a8a6763 RD |
7076 | if Nkind (CC) = N_Pragma then |
7077 | Analyze (CC); | |
c76bf0bf | 7078 | |
5a8a6763 | 7079 | -- The only pragma of interest is Complete_Representation |
c76bf0bf | 7080 | |
6e759c2a | 7081 | if Pragma_Name (CC) = Name_Complete_Representation then |
5a8a6763 RD |
7082 | CR_Pragma := CC; |
7083 | end if; | |
c76bf0bf | 7084 | |
5a8a6763 | 7085 | -- Processing for real component clause |
c76bf0bf | 7086 | |
5a8a6763 RD |
7087 | else |
7088 | Posit := Static_Integer (Position (CC)); | |
7089 | Fbit := Static_Integer (First_Bit (CC)); | |
7090 | Lbit := Static_Integer (Last_Bit (CC)); | |
c76bf0bf | 7091 | |
5a8a6763 RD |
7092 | if Posit /= No_Uint |
7093 | and then Fbit /= No_Uint | |
7094 | and then Lbit /= No_Uint | |
7095 | then | |
7096 | if Posit < 0 then | |
32b794c8 | 7097 | Error_Msg_N ("position cannot be negative", Position (CC)); |
c76bf0bf | 7098 | |
5a8a6763 | 7099 | elsif Fbit < 0 then |
32b794c8 | 7100 | Error_Msg_N ("first bit cannot be negative", First_Bit (CC)); |
c76bf0bf | 7101 | |
5a8a6763 RD |
7102 | -- The Last_Bit specified in a component clause must not be |
7103 | -- less than the First_Bit minus one (RM-13.5.1(10)). | |
c76bf0bf | 7104 | |
5a8a6763 RD |
7105 | elsif Lbit < Fbit - 1 then |
7106 | Error_Msg_N | |
7107 | ("last bit cannot be less than first bit minus one", | |
7108 | Last_Bit (CC)); | |
c76bf0bf | 7109 | |
5a8a6763 RD |
7110 | -- Values look OK, so find the corresponding record component |
7111 | -- Even though the syntax allows an attribute reference for | |
7112 | -- implementation-defined components, GNAT does not allow the | |
7113 | -- tag to get an explicit position. | |
c76bf0bf | 7114 | |
5a8a6763 RD |
7115 | elsif Nkind (Component_Name (CC)) = N_Attribute_Reference then |
7116 | if Attribute_Name (Component_Name (CC)) = Name_Tag then | |
7117 | Error_Msg_N ("position of tag cannot be specified", CC); | |
7118 | else | |
7119 | Error_Msg_N ("illegal component name", CC); | |
7120 | end if; | |
c76bf0bf | 7121 | |
5a8a6763 RD |
7122 | else |
7123 | Comp := First_Entity (Rectype); | |
7124 | while Present (Comp) loop | |
7125 | exit when Chars (Comp) = Chars (Component_Name (CC)); | |
7126 | Next_Entity (Comp); | |
7127 | end loop; | |
c76bf0bf | 7128 | |
5a8a6763 | 7129 | if No (Comp) then |
c76bf0bf | 7130 | |
5a8a6763 RD |
7131 | -- Maybe component of base type that is absent from |
7132 | -- statically constrained first subtype. | |
c76bf0bf | 7133 | |
5a8a6763 RD |
7134 | Comp := First_Entity (Base_Type (Rectype)); |
7135 | while Present (Comp) loop | |
7136 | exit when Chars (Comp) = Chars (Component_Name (CC)); | |
7137 | Next_Entity (Comp); | |
7138 | end loop; | |
7139 | end if; | |
c76bf0bf | 7140 | |
5a8a6763 RD |
7141 | if No (Comp) then |
7142 | Error_Msg_N | |
7143 | ("component clause is for non-existent field", CC); | |
c76bf0bf | 7144 | |
5a8a6763 RD |
7145 | -- Ada 2012 (AI05-0026): Any name that denotes a |
7146 | -- discriminant of an object of an unchecked union type | |
7147 | -- shall not occur within a record_representation_clause. | |
c76bf0bf | 7148 | |
5a8a6763 RD |
7149 | -- The general restriction of using record rep clauses on |
7150 | -- Unchecked_Union types has now been lifted. Since it is | |
7151 | -- possible to introduce a record rep clause which mentions | |
7152 | -- the discriminant of an Unchecked_Union in non-Ada 2012 | |
7153 | -- code, this check is applied to all versions of the | |
7154 | -- language. | |
c76bf0bf | 7155 | |
5a8a6763 RD |
7156 | elsif Ekind (Comp) = E_Discriminant |
7157 | and then Is_Unchecked_Union (Rectype) | |
7158 | then | |
7159 | Error_Msg_N | |
7160 | ("cannot reference discriminant of unchecked union", | |
7161 | Component_Name (CC)); | |
c76bf0bf | 7162 | |
5a8a6763 RD |
7163 | elsif Is_Record_Extension and then Is_Inherited (Comp) then |
7164 | Error_Msg_NE | |
7165 | ("component clause not allowed for inherited " | |
7166 | & "component&", CC, Comp); | |
3ff38f33 | 7167 | |
5a8a6763 | 7168 | elsif Present (Component_Clause (Comp)) then |
3cd4a210 | 7169 | |
5a8a6763 RD |
7170 | -- Diagnose duplicate rep clause, or check consistency |
7171 | -- if this is an inherited component. In a double fault, | |
7172 | -- there may be a duplicate inconsistent clause for an | |
7173 | -- inherited component. | |
3cd4a210 | 7174 | |
5a8a6763 RD |
7175 | if Scope (Original_Record_Component (Comp)) = Rectype |
7176 | or else Parent (Component_Clause (Comp)) = N | |
7177 | then | |
7178 | Error_Msg_Sloc := Sloc (Component_Clause (Comp)); | |
7179 | Error_Msg_N ("component clause previously given#", CC); | |
800621e0 RD |
7180 | |
7181 | else | |
7182 | declare | |
7183 | Rep1 : constant Node_Id := Component_Clause (Comp); | |
800621e0 RD |
7184 | begin |
7185 | if Intval (Position (Rep1)) /= | |
7186 | Intval (Position (CC)) | |
7187 | or else Intval (First_Bit (Rep1)) /= | |
7188 | Intval (First_Bit (CC)) | |
7189 | or else Intval (Last_Bit (Rep1)) /= | |
7190 | Intval (Last_Bit (CC)) | |
7191 | then | |
616547fa | 7192 | Error_Msg_N |
32b794c8 AC |
7193 | ("component clause inconsistent with " |
7194 | & "representation of ancestor", CC); | |
8190087e | 7195 | |
800621e0 | 7196 | elsif Warn_On_Redundant_Constructs then |
616547fa | 7197 | Error_Msg_N |
8190087e AC |
7198 | ("?r?redundant confirming component clause " |
7199 | & "for component!", CC); | |
800621e0 RD |
7200 | end if; |
7201 | end; | |
7202 | end if; | |
996ae0b0 | 7203 | |
6fb4cdde AC |
7204 | -- Normal case where this is the first component clause we |
7205 | -- have seen for this entity, so set it up properly. | |
7206 | ||
996ae0b0 | 7207 | else |
2642f998 RD |
7208 | -- Make reference for field in record rep clause and set |
7209 | -- appropriate entity field in the field identifier. | |
7210 | ||
7211 | Generate_Reference | |
7212 | (Comp, Component_Name (CC), Set_Ref => False); | |
7213 | Set_Entity (Component_Name (CC), Comp); | |
7214 | ||
a5b62485 | 7215 | -- Update Fbit and Lbit to the actual bit number |
996ae0b0 RK |
7216 | |
7217 | Fbit := Fbit + UI_From_Int (SSU) * Posit; | |
7218 | Lbit := Lbit + UI_From_Int (SSU) * Posit; | |
7219 | ||
996ae0b0 | 7220 | if Has_Size_Clause (Rectype) |
fc893455 | 7221 | and then RM_Size (Rectype) <= Lbit |
996ae0b0 RK |
7222 | then |
7223 | Error_Msg_N | |
7224 | ("bit number out of range of specified size", | |
7225 | Last_Bit (CC)); | |
7226 | else | |
7227 | Set_Component_Clause (Comp, CC); | |
7228 | Set_Component_Bit_Offset (Comp, Fbit); | |
7229 | Set_Esize (Comp, 1 + (Lbit - Fbit)); | |
7230 | Set_Normalized_First_Bit (Comp, Fbit mod SSU); | |
7231 | Set_Normalized_Position (Comp, Fbit / SSU); | |
7232 | ||
b3f48fd4 AC |
7233 | if Warn_On_Overridden_Size |
7234 | and then Has_Size_Clause (Etype (Comp)) | |
7235 | and then RM_Size (Etype (Comp)) /= Esize (Comp) | |
7236 | then | |
7237 | Error_Msg_NE | |
dbfeb4fa | 7238 | ("?S?component size overrides size clause for&", |
b3f48fd4 AC |
7239 | Component_Name (CC), Etype (Comp)); |
7240 | end if; | |
7241 | ||
d05ef0ab AC |
7242 | -- This information is also set in the corresponding |
7243 | -- component of the base type, found by accessing the | |
7244 | -- Original_Record_Component link if it is present. | |
996ae0b0 RK |
7245 | |
7246 | Ocomp := Original_Record_Component (Comp); | |
7247 | ||
7248 | if Hbit < Lbit then | |
7249 | Hbit := Lbit; | |
7250 | end if; | |
7251 | ||
7252 | Check_Size | |
7253 | (Component_Name (CC), | |
7254 | Etype (Comp), | |
7255 | Esize (Comp), | |
7256 | Biased); | |
7257 | ||
a3f2babd AC |
7258 | Set_Biased |
7259 | (Comp, First_Node (CC), "component clause", Biased); | |
4ae23b62 | 7260 | |
996ae0b0 RK |
7261 | if Present (Ocomp) then |
7262 | Set_Component_Clause (Ocomp, CC); | |
7263 | Set_Component_Bit_Offset (Ocomp, Fbit); | |
7264 | Set_Normalized_First_Bit (Ocomp, Fbit mod SSU); | |
7265 | Set_Normalized_Position (Ocomp, Fbit / SSU); | |
7266 | Set_Esize (Ocomp, 1 + (Lbit - Fbit)); | |
7267 | ||
7268 | Set_Normalized_Position_Max | |
7269 | (Ocomp, Normalized_Position (Ocomp)); | |
7270 | ||
a3f2babd AC |
7271 | -- Note: we don't use Set_Biased here, because we |
7272 | -- already gave a warning above if needed, and we | |
7273 | -- would get a duplicate for the same name here. | |
7274 | ||
996ae0b0 RK |
7275 | Set_Has_Biased_Representation |
7276 | (Ocomp, Has_Biased_Representation (Comp)); | |
7277 | end if; | |
7278 | ||
7279 | if Esize (Comp) < 0 then | |
7280 | Error_Msg_N ("component size is negative", CC); | |
7281 | end if; | |
7282 | end if; | |
7283 | end if; | |
7284 | end if; | |
7285 | end if; | |
7286 | end if; | |
7287 | ||
7288 | Next (CC); | |
7289 | end loop; | |
7290 | ||
8a95f4e8 | 7291 | -- Check missing components if Complete_Representation pragma appeared |
996ae0b0 | 7292 | |
8a95f4e8 RD |
7293 | if Present (CR_Pragma) then |
7294 | Comp := First_Component_Or_Discriminant (Rectype); | |
7295 | while Present (Comp) loop | |
7296 | if No (Component_Clause (Comp)) then | |
7297 | Error_Msg_NE | |
7298 | ("missing component clause for &", CR_Pragma, Comp); | |
7299 | end if; | |
996ae0b0 | 7300 | |
8a95f4e8 RD |
7301 | Next_Component_Or_Discriminant (Comp); |
7302 | end loop; | |
996ae0b0 | 7303 | |
dbfeb4fa | 7304 | -- Give missing components warning if required |
8f7770f9 | 7305 | |
0503c53a | 7306 | elsif Warn_On_Unrepped_Components then |
8f7770f9 RD |
7307 | declare |
7308 | Num_Repped_Components : Nat := 0; | |
7309 | Num_Unrepped_Components : Nat := 0; | |
7310 | ||
7311 | begin | |
7312 | -- First count number of repped and unrepped components | |
7313 | ||
7314 | Comp := First_Component_Or_Discriminant (Rectype); | |
7315 | while Present (Comp) loop | |
7316 | if Present (Component_Clause (Comp)) then | |
7317 | Num_Repped_Components := Num_Repped_Components + 1; | |
7318 | else | |
7319 | Num_Unrepped_Components := Num_Unrepped_Components + 1; | |
7320 | end if; | |
7321 | ||
7322 | Next_Component_Or_Discriminant (Comp); | |
7323 | end loop; | |
7324 | ||
7325 | -- We are only interested in the case where there is at least one | |
7326 | -- unrepped component, and at least half the components have rep | |
7327 | -- clauses. We figure that if less than half have them, then the | |
f5c064ab ST |
7328 | -- partial rep clause is really intentional. If the component |
7329 | -- type has no underlying type set at this point (as for a generic | |
7330 | -- formal type), we don't know enough to give a warning on the | |
7331 | -- component. | |
8f7770f9 RD |
7332 | |
7333 | if Num_Unrepped_Components > 0 | |
7334 | and then Num_Unrepped_Components < Num_Repped_Components | |
7335 | then | |
7336 | Comp := First_Component_Or_Discriminant (Rectype); | |
7337 | while Present (Comp) loop | |
2642f998 | 7338 | if No (Component_Clause (Comp)) |
800621e0 | 7339 | and then Comes_From_Source (Comp) |
f5c064ab | 7340 | and then Present (Underlying_Type (Etype (Comp))) |
2642f998 | 7341 | and then (Is_Scalar_Type (Underlying_Type (Etype (Comp))) |
8a95f4e8 RD |
7342 | or else Size_Known_At_Compile_Time |
7343 | (Underlying_Type (Etype (Comp)))) | |
0503c53a | 7344 | and then not Has_Warnings_Off (Rectype) |
3fbbbd1e AC |
7345 | |
7346 | -- Ignore discriminant in unchecked union, since it is | |
7347 | -- not there, and cannot have a component clause. | |
7348 | ||
7349 | and then (not Is_Unchecked_Union (Rectype) | |
7350 | or else Ekind (Comp) /= E_Discriminant) | |
2642f998 | 7351 | then |
8f7770f9 RD |
7352 | Error_Msg_Sloc := Sloc (Comp); |
7353 | Error_Msg_NE | |
dbfeb4fa | 7354 | ("?C?no component clause given for & declared #", |
8f7770f9 RD |
7355 | N, Comp); |
7356 | end if; | |
7357 | ||
7358 | Next_Component_Or_Discriminant (Comp); | |
7359 | end loop; | |
7360 | end if; | |
7361 | end; | |
996ae0b0 | 7362 | end if; |
996ae0b0 RK |
7363 | end Analyze_Record_Representation_Clause; |
7364 | ||
baa571ab AC |
7365 | ------------------------------------- |
7366 | -- Build_Discrete_Static_Predicate -- | |
7367 | ------------------------------------- | |
95081e99 | 7368 | |
baa571ab AC |
7369 | procedure Build_Discrete_Static_Predicate |
7370 | (Typ : Entity_Id; | |
7371 | Expr : Node_Id; | |
7372 | Nam : Name_Id) | |
95081e99 | 7373 | is |
baa571ab | 7374 | Loc : constant Source_Ptr := Sloc (Expr); |
95081e99 | 7375 | |
baa571ab AC |
7376 | Non_Static : exception; |
7377 | -- Raised if something non-static is found | |
95081e99 | 7378 | |
baa571ab | 7379 | Btyp : constant Entity_Id := Base_Type (Typ); |
95081e99 | 7380 | |
baa571ab AC |
7381 | BLo : constant Uint := Expr_Value (Type_Low_Bound (Btyp)); |
7382 | BHi : constant Uint := Expr_Value (Type_High_Bound (Btyp)); | |
7383 | -- Low bound and high bound value of base type of Typ | |
95081e99 | 7384 | |
67c0e662 RD |
7385 | TLo : Uint; |
7386 | THi : Uint; | |
7387 | -- Bounds for constructing the static predicate. We use the bound of the | |
7388 | -- subtype if it is static, otherwise the corresponding base type bound. | |
7389 | -- Note: a non-static subtype can have a static predicate. | |
95081e99 | 7390 | |
baa571ab AC |
7391 | type REnt is record |
7392 | Lo, Hi : Uint; | |
7393 | end record; | |
7394 | -- One entry in a Rlist value, a single REnt (range entry) value denotes | |
7395 | -- one range from Lo to Hi. To represent a single value range Lo = Hi = | |
7396 | -- value. | |
95081e99 | 7397 | |
baa571ab AC |
7398 | type RList is array (Nat range <>) of REnt; |
7399 | -- A list of ranges. The ranges are sorted in increasing order, and are | |
7400 | -- disjoint (there is a gap of at least one value between each range in | |
7401 | -- the table). A value is in the set of ranges in Rlist if it lies | |
7402 | -- within one of these ranges. | |
95081e99 | 7403 | |
baa571ab AC |
7404 | False_Range : constant RList := |
7405 | RList'(1 .. 0 => REnt'(No_Uint, No_Uint)); | |
7406 | -- An empty set of ranges represents a range list that can never be | |
7407 | -- satisfied, since there are no ranges in which the value could lie, | |
7408 | -- so it does not lie in any of them. False_Range is a canonical value | |
7409 | -- for this empty set, but general processing should test for an Rlist | |
7410 | -- with length zero (see Is_False predicate), since other null ranges | |
7411 | -- may appear which must be treated as False. | |
e606088a | 7412 | |
baa571ab AC |
7413 | True_Range : constant RList := RList'(1 => REnt'(BLo, BHi)); |
7414 | -- Range representing True, value must be in the base range | |
e606088a | 7415 | |
baa571ab AC |
7416 | function "and" (Left : RList; Right : RList) return RList; |
7417 | -- And's together two range lists, returning a range list. This is a set | |
7418 | -- intersection operation. | |
e606088a | 7419 | |
baa571ab AC |
7420 | function "or" (Left : RList; Right : RList) return RList; |
7421 | -- Or's together two range lists, returning a range list. This is a set | |
7422 | -- union operation. | |
f2264ac2 | 7423 | |
baa571ab AC |
7424 | function "not" (Right : RList) return RList; |
7425 | -- Returns complement of a given range list, i.e. a range list | |
7426 | -- representing all the values in TLo .. THi that are not in the input | |
7427 | -- operand Right. | |
6ccdd977 | 7428 | |
baa571ab AC |
7429 | function Build_Val (V : Uint) return Node_Id; |
7430 | -- Return an analyzed N_Identifier node referencing this value, suitable | |
60f908dd RD |
7431 | -- for use as an entry in the Static_Discrte_Predicate list. This node |
7432 | -- is typed with the base type. | |
e606088a | 7433 | |
baa571ab AC |
7434 | function Build_Range (Lo : Uint; Hi : Uint) return Node_Id; |
7435 | -- Return an analyzed N_Range node referencing this range, suitable for | |
60f908dd RD |
7436 | -- use as an entry in the Static_Discrete_Predicate list. This node is |
7437 | -- typed with the base type. | |
e606088a | 7438 | |
baa571ab AC |
7439 | function Get_RList (Exp : Node_Id) return RList; |
7440 | -- This is a recursive routine that converts the given expression into a | |
7441 | -- list of ranges, suitable for use in building the static predicate. | |
e606088a | 7442 | |
baa571ab AC |
7443 | function Is_False (R : RList) return Boolean; |
7444 | pragma Inline (Is_False); | |
7445 | -- Returns True if the given range list is empty, and thus represents a | |
7446 | -- False list of ranges that can never be satisfied. | |
f2264ac2 | 7447 | |
baa571ab AC |
7448 | function Is_True (R : RList) return Boolean; |
7449 | -- Returns True if R trivially represents the True predicate by having a | |
7450 | -- single range from BLo to BHi. | |
e606088a | 7451 | |
baa571ab AC |
7452 | function Is_Type_Ref (N : Node_Id) return Boolean; |
7453 | pragma Inline (Is_Type_Ref); | |
7454 | -- Returns if True if N is a reference to the type for the predicate in | |
7455 | -- the expression (i.e. if it is an identifier whose Chars field matches | |
623267dc AC |
7456 | -- the Nam given in the call). N must not be parenthesized, if the type |
7457 | -- name appears in parens, this routine will return False. | |
e606088a | 7458 | |
baa571ab | 7459 | function Lo_Val (N : Node_Id) return Uint; |
60f908dd RD |
7460 | -- Given an entry from a Static_Discrete_Predicate list that is either |
7461 | -- a static expression or static range, gets either the expression value | |
7462 | -- or the low bound of the range. | |
e606088a | 7463 | |
baa571ab | 7464 | function Hi_Val (N : Node_Id) return Uint; |
60f908dd RD |
7465 | -- Given an entry from a Static_Discrete_Predicate list that is either |
7466 | -- a static expression or static range, gets either the expression value | |
7467 | -- or the high bound of the range. | |
e606088a | 7468 | |
baa571ab AC |
7469 | function Membership_Entry (N : Node_Id) return RList; |
7470 | -- Given a single membership entry (range, value, or subtype), returns | |
7471 | -- the corresponding range list. Raises Static_Error if not static. | |
e606088a | 7472 | |
baa571ab AC |
7473 | function Membership_Entries (N : Node_Id) return RList; |
7474 | -- Given an element on an alternatives list of a membership operation, | |
7475 | -- returns the range list corresponding to this entry and all following | |
7476 | -- entries (i.e. returns the "or" of this list of values). | |
616547fa | 7477 | |
baa571ab AC |
7478 | function Stat_Pred (Typ : Entity_Id) return RList; |
7479 | -- Given a type, if it has a static predicate, then return the predicate | |
7480 | -- as a range list, otherwise raise Non_Static. | |
43417b90 | 7481 | |
baa571ab AC |
7482 | ----------- |
7483 | -- "and" -- | |
7484 | ----------- | |
43417b90 | 7485 | |
baa571ab AC |
7486 | function "and" (Left : RList; Right : RList) return RList is |
7487 | FEnt : REnt; | |
7488 | -- First range of result | |
43417b90 | 7489 | |
baa571ab AC |
7490 | SLeft : Nat := Left'First; |
7491 | -- Start of rest of left entries | |
43417b90 | 7492 | |
baa571ab AC |
7493 | SRight : Nat := Right'First; |
7494 | -- Start of rest of right entries | |
3b097d11 | 7495 | |
baa571ab AC |
7496 | begin |
7497 | -- If either range is True, return the other | |
e606088a | 7498 | |
baa571ab AC |
7499 | if Is_True (Left) then |
7500 | return Right; | |
7501 | elsif Is_True (Right) then | |
7502 | return Left; | |
7503 | end if; | |
f2264ac2 | 7504 | |
baa571ab | 7505 | -- If either range is False, return False |
e606088a | 7506 | |
baa571ab AC |
7507 | if Is_False (Left) or else Is_False (Right) then |
7508 | return False_Range; | |
7509 | end if; | |
30ebb114 | 7510 | |
baa571ab AC |
7511 | -- Loop to remove entries at start that are disjoint, and thus just |
7512 | -- get discarded from the result entirely. | |
e606088a | 7513 | |
baa571ab AC |
7514 | loop |
7515 | -- If no operands left in either operand, result is false | |
e606088a | 7516 | |
baa571ab AC |
7517 | if SLeft > Left'Last or else SRight > Right'Last then |
7518 | return False_Range; | |
e606088a | 7519 | |
baa571ab | 7520 | -- Discard first left operand entry if disjoint with right |
e606088a | 7521 | |
baa571ab AC |
7522 | elsif Left (SLeft).Hi < Right (SRight).Lo then |
7523 | SLeft := SLeft + 1; | |
e606088a | 7524 | |
baa571ab | 7525 | -- Discard first right operand entry if disjoint with left |
e606088a | 7526 | |
baa571ab AC |
7527 | elsif Right (SRight).Hi < Left (SLeft).Lo then |
7528 | SRight := SRight + 1; | |
e606088a | 7529 | |
baa571ab | 7530 | -- Otherwise we have an overlapping entry |
e606088a | 7531 | |
baa571ab AC |
7532 | else |
7533 | exit; | |
7534 | end if; | |
7535 | end loop; | |
e606088a | 7536 | |
baa571ab AC |
7537 | -- Now we have two non-null operands, and first entries overlap. The |
7538 | -- first entry in the result will be the overlapping part of these | |
7539 | -- two entries. | |
c116143c | 7540 | |
baa571ab AC |
7541 | FEnt := REnt'(Lo => UI_Max (Left (SLeft).Lo, Right (SRight).Lo), |
7542 | Hi => UI_Min (Left (SLeft).Hi, Right (SRight).Hi)); | |
c116143c | 7543 | |
baa571ab AC |
7544 | -- Now we can remove the entry that ended at a lower value, since its |
7545 | -- contribution is entirely contained in Fent. | |
e606088a | 7546 | |
baa571ab AC |
7547 | if Left (SLeft).Hi <= Right (SRight).Hi then |
7548 | SLeft := SLeft + 1; | |
7549 | else | |
7550 | SRight := SRight + 1; | |
7551 | end if; | |
e606088a | 7552 | |
baa571ab AC |
7553 | -- Compute result by concatenating this first entry with the "and" of |
7554 | -- the remaining parts of the left and right operands. Note that if | |
7555 | -- either of these is empty, "and" will yield empty, so that we will | |
7556 | -- end up with just Fent, which is what we want in that case. | |
e606088a | 7557 | |
baa571ab AC |
7558 | return |
7559 | FEnt & (Left (SLeft .. Left'Last) and Right (SRight .. Right'Last)); | |
7560 | end "and"; | |
bd949ee2 | 7561 | |
baa571ab AC |
7562 | ----------- |
7563 | -- "not" -- | |
7564 | ----------- | |
bd949ee2 | 7565 | |
baa571ab AC |
7566 | function "not" (Right : RList) return RList is |
7567 | begin | |
7568 | -- Return True if False range | |
bd949ee2 | 7569 | |
baa571ab AC |
7570 | if Is_False (Right) then |
7571 | return True_Range; | |
7572 | end if; | |
6ccdd977 | 7573 | |
baa571ab | 7574 | -- Return False if True range |
bd949ee2 | 7575 | |
baa571ab AC |
7576 | if Is_True (Right) then |
7577 | return False_Range; | |
7578 | end if; | |
bd949ee2 | 7579 | |
baa571ab | 7580 | -- Here if not trivial case |
f2264ac2 | 7581 | |
baa571ab AC |
7582 | declare |
7583 | Result : RList (1 .. Right'Length + 1); | |
7584 | -- May need one more entry for gap at beginning and end | |
f2264ac2 | 7585 | |
baa571ab AC |
7586 | Count : Nat := 0; |
7587 | -- Number of entries stored in Result | |
4a28b181 | 7588 | |
baa571ab AC |
7589 | begin |
7590 | -- Gap at start | |
4a28b181 | 7591 | |
baa571ab AC |
7592 | if Right (Right'First).Lo > TLo then |
7593 | Count := Count + 1; | |
7594 | Result (Count) := REnt'(TLo, Right (Right'First).Lo - 1); | |
7595 | end if; | |
6ccdd977 | 7596 | |
baa571ab | 7597 | -- Gaps between ranges |
6ccdd977 | 7598 | |
baa571ab AC |
7599 | for J in Right'First .. Right'Last - 1 loop |
7600 | Count := Count + 1; | |
7601 | Result (Count) := REnt'(Right (J).Hi + 1, Right (J + 1).Lo - 1); | |
7602 | end loop; | |
e606088a | 7603 | |
baa571ab | 7604 | -- Gap at end |
e606088a | 7605 | |
baa571ab AC |
7606 | if Right (Right'Last).Hi < THi then |
7607 | Count := Count + 1; | |
7608 | Result (Count) := REnt'(Right (Right'Last).Hi + 1, THi); | |
7609 | end if; | |
e606088a | 7610 | |
baa571ab AC |
7611 | return Result (1 .. Count); |
7612 | end; | |
7613 | end "not"; | |
e606088a | 7614 | |
baa571ab AC |
7615 | ---------- |
7616 | -- "or" -- | |
7617 | ---------- | |
e606088a | 7618 | |
baa571ab AC |
7619 | function "or" (Left : RList; Right : RList) return RList is |
7620 | FEnt : REnt; | |
7621 | -- First range of result | |
e606088a | 7622 | |
baa571ab AC |
7623 | SLeft : Nat := Left'First; |
7624 | -- Start of rest of left entries | |
e606088a | 7625 | |
baa571ab AC |
7626 | SRight : Nat := Right'First; |
7627 | -- Start of rest of right entries | |
e606088a | 7628 | |
baa571ab AC |
7629 | begin |
7630 | -- If either range is True, return True | |
e606088a | 7631 | |
baa571ab AC |
7632 | if Is_True (Left) or else Is_True (Right) then |
7633 | return True_Range; | |
7634 | end if; | |
e606088a | 7635 | |
baa571ab | 7636 | -- If either range is False (empty), return the other |
e606088a | 7637 | |
baa571ab AC |
7638 | if Is_False (Left) then |
7639 | return Right; | |
7640 | elsif Is_False (Right) then | |
7641 | return Left; | |
7642 | end if; | |
e606088a | 7643 | |
baa571ab AC |
7644 | -- Initialize result first entry from left or right operand depending |
7645 | -- on which starts with the lower range. | |
e606088a | 7646 | |
baa571ab AC |
7647 | if Left (SLeft).Lo < Right (SRight).Lo then |
7648 | FEnt := Left (SLeft); | |
7649 | SLeft := SLeft + 1; | |
7650 | else | |
7651 | FEnt := Right (SRight); | |
7652 | SRight := SRight + 1; | |
7653 | end if; | |
e606088a | 7654 | |
baa571ab AC |
7655 | -- This loop eats ranges from left and right operands that are |
7656 | -- contiguous with the first range we are gathering. | |
95081e99 | 7657 | |
baa571ab AC |
7658 | loop |
7659 | -- Eat first entry in left operand if contiguous or overlapped by | |
7660 | -- gathered first operand of result. | |
95081e99 | 7661 | |
baa571ab AC |
7662 | if SLeft <= Left'Last |
7663 | and then Left (SLeft).Lo <= FEnt.Hi + 1 | |
7664 | then | |
7665 | FEnt.Hi := UI_Max (FEnt.Hi, Left (SLeft).Hi); | |
7666 | SLeft := SLeft + 1; | |
95081e99 | 7667 | |
baa571ab AC |
7668 | -- Eat first entry in right operand if contiguous or overlapped by |
7669 | -- gathered right operand of result. | |
95081e99 | 7670 | |
baa571ab AC |
7671 | elsif SRight <= Right'Last |
7672 | and then Right (SRight).Lo <= FEnt.Hi + 1 | |
7673 | then | |
7674 | FEnt.Hi := UI_Max (FEnt.Hi, Right (SRight).Hi); | |
7675 | SRight := SRight + 1; | |
95081e99 | 7676 | |
baa571ab | 7677 | -- All done if no more entries to eat |
e606088a | 7678 | |
baa571ab AC |
7679 | else |
7680 | exit; | |
7681 | end if; | |
7682 | end loop; | |
e606088a | 7683 | |
baa571ab AC |
7684 | -- Obtain result as the first entry we just computed, concatenated |
7685 | -- to the "or" of the remaining results (if one operand is empty, | |
7686 | -- this will just concatenate with the other | |
e606088a | 7687 | |
baa571ab AC |
7688 | return |
7689 | FEnt & (Left (SLeft .. Left'Last) or Right (SRight .. Right'Last)); | |
7690 | end "or"; | |
e606088a | 7691 | |
baa571ab AC |
7692 | ----------------- |
7693 | -- Build_Range -- | |
7694 | ----------------- | |
e606088a | 7695 | |
baa571ab AC |
7696 | function Build_Range (Lo : Uint; Hi : Uint) return Node_Id is |
7697 | Result : Node_Id; | |
e606088a | 7698 | begin |
baa571ab AC |
7699 | Result := |
7700 | Make_Range (Loc, | |
7701 | Low_Bound => Build_Val (Lo), | |
7702 | High_Bound => Build_Val (Hi)); | |
7703 | Set_Etype (Result, Btyp); | |
7704 | Set_Analyzed (Result); | |
7705 | return Result; | |
7706 | end Build_Range; | |
e606088a | 7707 | |
baa571ab AC |
7708 | --------------- |
7709 | -- Build_Val -- | |
7710 | --------------- | |
e606088a | 7711 | |
baa571ab AC |
7712 | function Build_Val (V : Uint) return Node_Id is |
7713 | Result : Node_Id; | |
e606088a | 7714 | |
baa571ab AC |
7715 | begin |
7716 | if Is_Enumeration_Type (Typ) then | |
7717 | Result := Get_Enum_Lit_From_Pos (Typ, V, Loc); | |
7718 | else | |
7719 | Result := Make_Integer_Literal (Loc, V); | |
7720 | end if; | |
e606088a | 7721 | |
baa571ab AC |
7722 | Set_Etype (Result, Btyp); |
7723 | Set_Is_Static_Expression (Result); | |
7724 | Set_Analyzed (Result); | |
7725 | return Result; | |
7726 | end Build_Val; | |
f2264ac2 | 7727 | |
baa571ab AC |
7728 | --------------- |
7729 | -- Get_RList -- | |
7730 | --------------- | |
f2264ac2 | 7731 | |
baa571ab AC |
7732 | function Get_RList (Exp : Node_Id) return RList is |
7733 | Op : Node_Kind; | |
7734 | Val : Uint; | |
f2264ac2 | 7735 | |
baa571ab AC |
7736 | begin |
7737 | -- Static expression can only be true or false | |
f2264ac2 | 7738 | |
baa571ab AC |
7739 | if Is_OK_Static_Expression (Exp) then |
7740 | if Expr_Value (Exp) = 0 then | |
7741 | return False_Range; | |
7742 | else | |
7743 | return True_Range; | |
95081e99 | 7744 | end if; |
baa571ab | 7745 | end if; |
f2264ac2 | 7746 | |
baa571ab | 7747 | -- Otherwise test node type |
4172a8e3 | 7748 | |
baa571ab | 7749 | Op := Nkind (Exp); |
4172a8e3 | 7750 | |
baa571ab | 7751 | case Op is |
9e1902a9 | 7752 | |
baa571ab | 7753 | -- And |
9e1902a9 | 7754 | |
d8f43ee6 HK |
7755 | when N_And_Then |
7756 | | N_Op_And | |
7757 | => | |
baa571ab AC |
7758 | return Get_RList (Left_Opnd (Exp)) |
7759 | and | |
7760 | Get_RList (Right_Opnd (Exp)); | |
e606088a | 7761 | |
baa571ab | 7762 | -- Or |
86200f66 | 7763 | |
d8f43ee6 HK |
7764 | when N_Op_Or |
7765 | | N_Or_Else | |
7766 | => | |
baa571ab AC |
7767 | return Get_RList (Left_Opnd (Exp)) |
7768 | or | |
7769 | Get_RList (Right_Opnd (Exp)); | |
c5a26133 | 7770 | |
baa571ab | 7771 | -- Not |
86200f66 | 7772 | |
baa571ab AC |
7773 | when N_Op_Not => |
7774 | return not Get_RList (Right_Opnd (Exp)); | |
86200f66 | 7775 | |
baa571ab | 7776 | -- Comparisons of type with static value |
fc142f63 | 7777 | |
baa571ab | 7778 | when N_Op_Compare => |
f2acf80c | 7779 | |
baa571ab | 7780 | -- Type is left operand |
86200f66 | 7781 | |
baa571ab AC |
7782 | if Is_Type_Ref (Left_Opnd (Exp)) |
7783 | and then Is_OK_Static_Expression (Right_Opnd (Exp)) | |
7784 | then | |
7785 | Val := Expr_Value (Right_Opnd (Exp)); | |
fc142f63 | 7786 | |
baa571ab | 7787 | -- Typ is right operand |
fc142f63 | 7788 | |
baa571ab AC |
7789 | elsif Is_Type_Ref (Right_Opnd (Exp)) |
7790 | and then Is_OK_Static_Expression (Left_Opnd (Exp)) | |
7791 | then | |
7792 | Val := Expr_Value (Left_Opnd (Exp)); | |
fc142f63 | 7793 | |
baa571ab | 7794 | -- Invert sense of comparison |
fc142f63 | 7795 | |
baa571ab AC |
7796 | case Op is |
7797 | when N_Op_Gt => Op := N_Op_Lt; | |
7798 | when N_Op_Lt => Op := N_Op_Gt; | |
7799 | when N_Op_Ge => Op := N_Op_Le; | |
7800 | when N_Op_Le => Op := N_Op_Ge; | |
7801 | when others => null; | |
7802 | end case; | |
fc142f63 | 7803 | |
baa571ab | 7804 | -- Other cases are non-static |
42fdc85b | 7805 | |
baa571ab AC |
7806 | else |
7807 | raise Non_Static; | |
7808 | end if; | |
86200f66 | 7809 | |
baa571ab | 7810 | -- Construct range according to comparison operation |
86200f66 | 7811 | |
baa571ab AC |
7812 | case Op is |
7813 | when N_Op_Eq => | |
7814 | return RList'(1 => REnt'(Val, Val)); | |
86200f66 | 7815 | |
baa571ab AC |
7816 | when N_Op_Ge => |
7817 | return RList'(1 => REnt'(Val, BHi)); | |
fc142f63 | 7818 | |
baa571ab AC |
7819 | when N_Op_Gt => |
7820 | return RList'(1 => REnt'(Val + 1, BHi)); | |
fc142f63 | 7821 | |
baa571ab AC |
7822 | when N_Op_Le => |
7823 | return RList'(1 => REnt'(BLo, Val)); | |
bd949ee2 | 7824 | |
baa571ab AC |
7825 | when N_Op_Lt => |
7826 | return RList'(1 => REnt'(BLo, Val - 1)); | |
86200f66 | 7827 | |
baa571ab AC |
7828 | when N_Op_Ne => |
7829 | return RList'(REnt'(BLo, Val - 1), REnt'(Val + 1, BHi)); | |
86200f66 | 7830 | |
baa571ab AC |
7831 | when others => |
7832 | raise Program_Error; | |
7833 | end case; | |
86200f66 | 7834 | |
baa571ab | 7835 | -- Membership (IN) |
86200f66 | 7836 | |
baa571ab AC |
7837 | when N_In => |
7838 | if not Is_Type_Ref (Left_Opnd (Exp)) then | |
7839 | raise Non_Static; | |
7840 | end if; | |
86200f66 | 7841 | |
baa571ab AC |
7842 | if Present (Right_Opnd (Exp)) then |
7843 | return Membership_Entry (Right_Opnd (Exp)); | |
7844 | else | |
7845 | return Membership_Entries (First (Alternatives (Exp))); | |
7846 | end if; | |
86200f66 | 7847 | |
baa571ab | 7848 | -- Negative membership (NOT IN) |
86200f66 | 7849 | |
baa571ab AC |
7850 | when N_Not_In => |
7851 | if not Is_Type_Ref (Left_Opnd (Exp)) then | |
7852 | raise Non_Static; | |
7853 | end if; | |
86200f66 | 7854 | |
baa571ab AC |
7855 | if Present (Right_Opnd (Exp)) then |
7856 | return not Membership_Entry (Right_Opnd (Exp)); | |
7857 | else | |
7858 | return not Membership_Entries (First (Alternatives (Exp))); | |
7859 | end if; | |
86200f66 | 7860 | |
baa571ab | 7861 | -- Function call, may be call to static predicate |
86200f66 | 7862 | |
baa571ab AC |
7863 | when N_Function_Call => |
7864 | if Is_Entity_Name (Name (Exp)) then | |
7865 | declare | |
7866 | Ent : constant Entity_Id := Entity (Name (Exp)); | |
7867 | begin | |
7868 | if Is_Predicate_Function (Ent) | |
7869 | or else | |
7870 | Is_Predicate_Function_M (Ent) | |
7871 | then | |
7872 | return Stat_Pred (Etype (First_Formal (Ent))); | |
7873 | end if; | |
7874 | end; | |
7875 | end if; | |
86200f66 | 7876 | |
baa571ab | 7877 | -- Other function call cases are non-static |
86200f66 | 7878 | |
baa571ab | 7879 | raise Non_Static; |
f2acf80c | 7880 | |
baa571ab | 7881 | -- Qualified expression, dig out the expression |
415450ea | 7882 | |
baa571ab AC |
7883 | when N_Qualified_Expression => |
7884 | return Get_RList (Expression (Exp)); | |
30ebb114 | 7885 | |
baa571ab AC |
7886 | when N_Case_Expression => |
7887 | declare | |
7888 | Alt : Node_Id; | |
7889 | Choices : List_Id; | |
7890 | Dep : Node_Id; | |
30ebb114 | 7891 | |
baa571ab AC |
7892 | begin |
7893 | if not Is_Entity_Name (Expression (Expr)) | |
7894 | or else Etype (Expression (Expr)) /= Typ | |
7895 | then | |
7896 | Error_Msg_N | |
7897 | ("expression must denaote subtype", Expression (Expr)); | |
7898 | return False_Range; | |
7899 | end if; | |
86200f66 | 7900 | |
baa571ab | 7901 | -- Collect discrete choices in all True alternatives |
86200f66 | 7902 | |
baa571ab AC |
7903 | Choices := New_List; |
7904 | Alt := First (Alternatives (Exp)); | |
7905 | while Present (Alt) loop | |
7906 | Dep := Expression (Alt); | |
42fdc85b | 7907 | |
edab6088 | 7908 | if not Is_OK_Static_Expression (Dep) then |
baa571ab | 7909 | raise Non_Static; |
f1c952af | 7910 | |
baa571ab AC |
7911 | elsif Is_True (Expr_Value (Dep)) then |
7912 | Append_List_To (Choices, | |
7913 | New_Copy_List (Discrete_Choices (Alt))); | |
7914 | end if; | |
bd949ee2 | 7915 | |
baa571ab AC |
7916 | Next (Alt); |
7917 | end loop; | |
86200f66 | 7918 | |
baa571ab AC |
7919 | return Membership_Entries (First (Choices)); |
7920 | end; | |
86200f66 | 7921 | |
baa571ab | 7922 | -- Expression with actions: if no actions, dig out expression |
86200f66 | 7923 | |
baa571ab AC |
7924 | when N_Expression_With_Actions => |
7925 | if Is_Empty_List (Actions (Exp)) then | |
7926 | return Get_RList (Expression (Exp)); | |
7927 | else | |
7928 | raise Non_Static; | |
7929 | end if; | |
86200f66 | 7930 | |
baa571ab | 7931 | -- Xor operator |
f2acf80c | 7932 | |
baa571ab AC |
7933 | when N_Op_Xor => |
7934 | return (Get_RList (Left_Opnd (Exp)) | |
7935 | and not Get_RList (Right_Opnd (Exp))) | |
7936 | or (Get_RList (Right_Opnd (Exp)) | |
7937 | and not Get_RList (Left_Opnd (Exp))); | |
86200f66 | 7938 | |
baa571ab | 7939 | -- Any other node type is non-static |
bd949ee2 | 7940 | |
baa571ab AC |
7941 | when others => |
7942 | raise Non_Static; | |
7943 | end case; | |
7944 | end Get_RList; | |
bd949ee2 | 7945 | |
baa571ab AC |
7946 | ------------ |
7947 | -- Hi_Val -- | |
7948 | ------------ | |
bd949ee2 | 7949 | |
baa571ab AC |
7950 | function Hi_Val (N : Node_Id) return Uint is |
7951 | begin | |
edab6088 | 7952 | if Is_OK_Static_Expression (N) then |
baa571ab AC |
7953 | return Expr_Value (N); |
7954 | else | |
7955 | pragma Assert (Nkind (N) = N_Range); | |
7956 | return Expr_Value (High_Bound (N)); | |
7957 | end if; | |
7958 | end Hi_Val; | |
bd949ee2 | 7959 | |
baa571ab AC |
7960 | -------------- |
7961 | -- Is_False -- | |
7962 | -------------- | |
bd949ee2 | 7963 | |
baa571ab AC |
7964 | function Is_False (R : RList) return Boolean is |
7965 | begin | |
7966 | return R'Length = 0; | |
7967 | end Is_False; | |
86200f66 | 7968 | |
baa571ab AC |
7969 | ------------- |
7970 | -- Is_True -- | |
7971 | ------------- | |
86200f66 | 7972 | |
baa571ab AC |
7973 | function Is_True (R : RList) return Boolean is |
7974 | begin | |
7975 | return R'Length = 1 | |
7976 | and then R (R'First).Lo = BLo | |
7977 | and then R (R'First).Hi = BHi; | |
7978 | end Is_True; | |
86200f66 | 7979 | |
baa571ab AC |
7980 | ----------------- |
7981 | -- Is_Type_Ref -- | |
7982 | ----------------- | |
86200f66 | 7983 | |
baa571ab AC |
7984 | function Is_Type_Ref (N : Node_Id) return Boolean is |
7985 | begin | |
623267dc AC |
7986 | return Nkind (N) = N_Identifier |
7987 | and then Chars (N) = Nam | |
7988 | and then Paren_Count (N) = 0; | |
baa571ab | 7989 | end Is_Type_Ref; |
86200f66 | 7990 | |
baa571ab AC |
7991 | ------------ |
7992 | -- Lo_Val -- | |
7993 | ------------ | |
86200f66 | 7994 | |
baa571ab | 7995 | function Lo_Val (N : Node_Id) return Uint is |
fc142f63 | 7996 | begin |
edab6088 | 7997 | if Is_OK_Static_Expression (N) then |
baa571ab | 7998 | return Expr_Value (N); |
fc142f63 | 7999 | else |
baa571ab AC |
8000 | pragma Assert (Nkind (N) = N_Range); |
8001 | return Expr_Value (Low_Bound (N)); | |
fc142f63 | 8002 | end if; |
baa571ab | 8003 | end Lo_Val; |
1e194575 | 8004 | |
baa571ab AC |
8005 | ------------------------ |
8006 | -- Membership_Entries -- | |
8007 | ------------------------ | |
1e194575 | 8008 | |
baa571ab | 8009 | function Membership_Entries (N : Node_Id) return RList is |
fc142f63 | 8010 | begin |
baa571ab AC |
8011 | if No (Next (N)) then |
8012 | return Membership_Entry (N); | |
fc142f63 | 8013 | else |
baa571ab | 8014 | return Membership_Entry (N) or Membership_Entries (Next (N)); |
fc142f63 | 8015 | end if; |
baa571ab | 8016 | end Membership_Entries; |
fc142f63 | 8017 | |
baa571ab AC |
8018 | ---------------------- |
8019 | -- Membership_Entry -- | |
8020 | ---------------------- | |
fc142f63 | 8021 | |
baa571ab AC |
8022 | function Membership_Entry (N : Node_Id) return RList is |
8023 | Val : Uint; | |
8024 | SLo : Uint; | |
8025 | SHi : Uint; | |
1e194575 | 8026 | |
baa571ab AC |
8027 | begin |
8028 | -- Range case | |
1e194575 | 8029 | |
baa571ab | 8030 | if Nkind (N) = N_Range then |
edab6088 | 8031 | if not Is_OK_Static_Expression (Low_Bound (N)) |
baa571ab | 8032 | or else |
edab6088 | 8033 | not Is_OK_Static_Expression (High_Bound (N)) |
baa571ab AC |
8034 | then |
8035 | raise Non_Static; | |
8036 | else | |
8037 | SLo := Expr_Value (Low_Bound (N)); | |
8038 | SHi := Expr_Value (High_Bound (N)); | |
8039 | return RList'(1 => REnt'(SLo, SHi)); | |
8040 | end if; | |
fc142f63 | 8041 | |
baa571ab | 8042 | -- Static expression case |
fc142f63 | 8043 | |
edab6088 | 8044 | elsif Is_OK_Static_Expression (N) then |
baa571ab AC |
8045 | Val := Expr_Value (N); |
8046 | return RList'(1 => REnt'(Val, Val)); | |
1e194575 | 8047 | |
baa571ab | 8048 | -- Identifier (other than static expression) case |
1e194575 | 8049 | |
baa571ab | 8050 | else pragma Assert (Nkind (N) = N_Identifier); |
1e194575 | 8051 | |
baa571ab | 8052 | -- Type case |
1e194575 | 8053 | |
baa571ab | 8054 | if Is_Type (Entity (N)) then |
1e194575 | 8055 | |
baa571ab | 8056 | -- If type has predicates, process them |
1e194575 | 8057 | |
baa571ab AC |
8058 | if Has_Predicates (Entity (N)) then |
8059 | return Stat_Pred (Entity (N)); | |
1e194575 | 8060 | |
baa571ab | 8061 | -- For static subtype without predicates, get range |
86200f66 | 8062 | |
edab6088 | 8063 | elsif Is_OK_Static_Subtype (Entity (N)) then |
baa571ab AC |
8064 | SLo := Expr_Value (Type_Low_Bound (Entity (N))); |
8065 | SHi := Expr_Value (Type_High_Bound (Entity (N))); | |
8066 | return RList'(1 => REnt'(SLo, SHi)); | |
de6e4fc4 | 8067 | |
baa571ab | 8068 | -- Any other type makes us non-static |
de6e4fc4 | 8069 | |
baa571ab AC |
8070 | else |
8071 | raise Non_Static; | |
8072 | end if; | |
fc142f63 | 8073 | |
baa571ab AC |
8074 | -- Any other kind of identifier in predicate (e.g. a non-static |
8075 | -- expression value) means this is not a static predicate. | |
fc142f63 | 8076 | |
baa571ab AC |
8077 | else |
8078 | raise Non_Static; | |
8079 | end if; | |
8080 | end if; | |
8081 | end Membership_Entry; | |
fc142f63 | 8082 | |
baa571ab AC |
8083 | --------------- |
8084 | -- Stat_Pred -- | |
8085 | --------------- | |
fc142f63 | 8086 | |
baa571ab AC |
8087 | function Stat_Pred (Typ : Entity_Id) return RList is |
8088 | begin | |
8089 | -- Not static if type does not have static predicates | |
fc142f63 | 8090 | |
60f908dd | 8091 | if not Has_Static_Predicate (Typ) then |
baa571ab AC |
8092 | raise Non_Static; |
8093 | end if; | |
fc142f63 | 8094 | |
baa571ab | 8095 | -- Otherwise we convert the predicate list to a range list |
fc142f63 | 8096 | |
baa571ab | 8097 | declare |
60f908dd RD |
8098 | Spred : constant List_Id := Static_Discrete_Predicate (Typ); |
8099 | Result : RList (1 .. List_Length (Spred)); | |
baa571ab | 8100 | P : Node_Id; |
fc142f63 | 8101 | |
baa571ab | 8102 | begin |
60f908dd | 8103 | P := First (Static_Discrete_Predicate (Typ)); |
baa571ab AC |
8104 | for J in Result'Range loop |
8105 | Result (J) := REnt'(Lo_Val (P), Hi_Val (P)); | |
8106 | Next (P); | |
8107 | end loop; | |
fc142f63 | 8108 | |
baa571ab AC |
8109 | return Result; |
8110 | end; | |
8111 | end Stat_Pred; | |
fc142f63 | 8112 | |
baa571ab | 8113 | -- Start of processing for Build_Discrete_Static_Predicate |
fc142f63 | 8114 | |
baa571ab | 8115 | begin |
a2c314c7 | 8116 | -- Establish bounds for the predicate |
67c0e662 RD |
8117 | |
8118 | if Compile_Time_Known_Value (Type_Low_Bound (Typ)) then | |
8119 | TLo := Expr_Value (Type_Low_Bound (Typ)); | |
8120 | else | |
8121 | TLo := BLo; | |
8122 | end if; | |
8123 | ||
8124 | if Compile_Time_Known_Value (Type_High_Bound (Typ)) then | |
8125 | THi := Expr_Value (Type_High_Bound (Typ)); | |
8126 | else | |
8127 | THi := BHi; | |
8128 | end if; | |
8129 | ||
baa571ab | 8130 | -- Analyze the expression to see if it is a static predicate |
fc142f63 | 8131 | |
baa571ab AC |
8132 | declare |
8133 | Ranges : constant RList := Get_RList (Expr); | |
8134 | -- Range list from expression if it is static | |
fc142f63 | 8135 | |
baa571ab | 8136 | Plist : List_Id; |
fc142f63 | 8137 | |
baa571ab AC |
8138 | begin |
8139 | -- Convert range list into a form for the static predicate. In the | |
8140 | -- Ranges array, we just have raw ranges, these must be converted | |
8141 | -- to properly typed and analyzed static expressions or range nodes. | |
fc142f63 | 8142 | |
baa571ab AC |
8143 | -- Note: here we limit ranges to the ranges of the subtype, so that |
8144 | -- a predicate is always false for values outside the subtype. That | |
8145 | -- seems fine, such values are invalid anyway, and considering them | |
8146 | -- to fail the predicate seems allowed and friendly, and furthermore | |
8147 | -- simplifies processing for case statements and loops. | |
fc142f63 | 8148 | |
baa571ab AC |
8149 | Plist := New_List; |
8150 | ||
8151 | for J in Ranges'Range loop | |
fc142f63 | 8152 | declare |
baa571ab AC |
8153 | Lo : Uint := Ranges (J).Lo; |
8154 | Hi : Uint := Ranges (J).Hi; | |
fc142f63 | 8155 | |
baa571ab AC |
8156 | begin |
8157 | -- Ignore completely out of range entry | |
fc142f63 | 8158 | |
baa571ab AC |
8159 | if Hi < TLo or else Lo > THi then |
8160 | null; | |
fc142f63 | 8161 | |
baa571ab | 8162 | -- Otherwise process entry |
fc142f63 | 8163 | |
baa571ab AC |
8164 | else |
8165 | -- Adjust out of range value to subtype range | |
f2acf80c | 8166 | |
baa571ab AC |
8167 | if Lo < TLo then |
8168 | Lo := TLo; | |
8169 | end if; | |
f2acf80c | 8170 | |
baa571ab AC |
8171 | if Hi > THi then |
8172 | Hi := THi; | |
8173 | end if; | |
fc142f63 | 8174 | |
baa571ab | 8175 | -- Convert range into required form |
fc142f63 | 8176 | |
baa571ab | 8177 | Append_To (Plist, Build_Range (Lo, Hi)); |
fc142f63 | 8178 | end if; |
baa571ab AC |
8179 | end; |
8180 | end loop; | |
fc142f63 | 8181 | |
baa571ab AC |
8182 | -- Processing was successful and all entries were static, so now we |
8183 | -- can store the result as the predicate list. | |
fc142f63 | 8184 | |
60f908dd | 8185 | Set_Static_Discrete_Predicate (Typ, Plist); |
fc142f63 | 8186 | |
558241c0 ES |
8187 | -- Within a generic the predicate functions themselves need not |
8188 | -- be constructed. | |
8189 | ||
8190 | if Inside_A_Generic then | |
8191 | return; | |
8192 | end if; | |
8193 | ||
baa571ab AC |
8194 | -- The processing for static predicates put the expression into |
8195 | -- canonical form as a series of ranges. It also eliminated | |
8196 | -- duplicates and collapsed and combined ranges. We might as well | |
8197 | -- replace the alternatives list of the right operand of the | |
8198 | -- membership test with the static predicate list, which will | |
8199 | -- usually be more efficient. | |
fc142f63 | 8200 | |
baa571ab AC |
8201 | declare |
8202 | New_Alts : constant List_Id := New_List; | |
8203 | Old_Node : Node_Id; | |
8204 | New_Node : Node_Id; | |
fc142f63 | 8205 | |
baa571ab AC |
8206 | begin |
8207 | Old_Node := First (Plist); | |
8208 | while Present (Old_Node) loop | |
8209 | New_Node := New_Copy (Old_Node); | |
fc142f63 | 8210 | |
baa571ab AC |
8211 | if Nkind (New_Node) = N_Range then |
8212 | Set_Low_Bound (New_Node, New_Copy (Low_Bound (Old_Node))); | |
8213 | Set_High_Bound (New_Node, New_Copy (High_Bound (Old_Node))); | |
8214 | end if; | |
fc142f63 | 8215 | |
baa571ab AC |
8216 | Append_To (New_Alts, New_Node); |
8217 | Next (Old_Node); | |
8218 | end loop; | |
fc142f63 | 8219 | |
baa571ab | 8220 | -- If empty list, replace by False |
fc142f63 | 8221 | |
baa571ab AC |
8222 | if Is_Empty_List (New_Alts) then |
8223 | Rewrite (Expr, New_Occurrence_Of (Standard_False, Loc)); | |
fc142f63 | 8224 | |
baa571ab | 8225 | -- Else replace by set membership test |
fc142f63 | 8226 | |
baa571ab AC |
8227 | else |
8228 | Rewrite (Expr, | |
8229 | Make_In (Loc, | |
8230 | Left_Opnd => Make_Identifier (Loc, Nam), | |
8231 | Right_Opnd => Empty, | |
8232 | Alternatives => New_Alts)); | |
f2acf80c | 8233 | |
baa571ab | 8234 | -- Resolve new expression in function context |
f2acf80c | 8235 | |
baa571ab AC |
8236 | Install_Formals (Predicate_Function (Typ)); |
8237 | Push_Scope (Predicate_Function (Typ)); | |
8238 | Analyze_And_Resolve (Expr, Standard_Boolean); | |
8239 | Pop_Scope; | |
8240 | end if; | |
8241 | end; | |
8242 | end; | |
3b1d4d82 | 8243 | |
baa571ab | 8244 | -- If non-static, return doing nothing |
3b1d4d82 | 8245 | |
baa571ab AC |
8246 | exception |
8247 | when Non_Static => | |
8248 | return; | |
8249 | end Build_Discrete_Static_Predicate; | |
0d5fbf52 | 8250 | |
2e885a6f AC |
8251 | -------------------------------- |
8252 | -- Build_Export_Import_Pragma -- | |
8253 | -------------------------------- | |
8254 | ||
8255 | function Build_Export_Import_Pragma | |
8256 | (Asp : Node_Id; | |
8257 | Id : Entity_Id) return Node_Id | |
8258 | is | |
8259 | Asp_Id : constant Aspect_Id := Get_Aspect_Id (Asp); | |
8260 | Expr : constant Node_Id := Expression (Asp); | |
8261 | Loc : constant Source_Ptr := Sloc (Asp); | |
8262 | ||
8263 | Args : List_Id; | |
8264 | Conv : Node_Id; | |
8265 | Conv_Arg : Node_Id; | |
8266 | Dummy_1 : Node_Id; | |
8267 | Dummy_2 : Node_Id; | |
8268 | EN : Node_Id; | |
8269 | LN : Node_Id; | |
8270 | Prag : Node_Id; | |
8271 | ||
8272 | Create_Pragma : Boolean := False; | |
8273 | -- This flag is set when the aspect form is such that it warrants the | |
8274 | -- creation of a corresponding pragma. | |
8275 | ||
8276 | begin | |
8277 | if Present (Expr) then | |
8278 | if Error_Posted (Expr) then | |
8279 | null; | |
8280 | ||
8281 | elsif Is_True (Expr_Value (Expr)) then | |
8282 | Create_Pragma := True; | |
8283 | end if; | |
8284 | ||
8285 | -- Otherwise the aspect defaults to True | |
8286 | ||
8287 | else | |
8288 | Create_Pragma := True; | |
8289 | end if; | |
8290 | ||
8291 | -- Nothing to do when the expression is False or is erroneous | |
8292 | ||
8293 | if not Create_Pragma then | |
8294 | return Empty; | |
8295 | end if; | |
8296 | ||
8297 | -- Obtain all interfacing aspects that apply to the related entity | |
8298 | ||
8299 | Get_Interfacing_Aspects | |
8300 | (Iface_Asp => Asp, | |
8301 | Conv_Asp => Conv, | |
8302 | EN_Asp => EN, | |
8303 | Expo_Asp => Dummy_1, | |
8304 | Imp_Asp => Dummy_2, | |
8305 | LN_Asp => LN); | |
8306 | ||
8307 | Args := New_List; | |
8308 | ||
8309 | -- Handle the convention argument | |
8310 | ||
8311 | if Present (Conv) then | |
8312 | Conv_Arg := New_Copy_Tree (Expression (Conv)); | |
8313 | ||
8314 | -- Assume convention "Ada' when aspect Convention is missing | |
8315 | ||
8316 | else | |
8317 | Conv_Arg := Make_Identifier (Loc, Name_Ada); | |
8318 | end if; | |
8319 | ||
8320 | Append_To (Args, | |
8321 | Make_Pragma_Argument_Association (Loc, | |
8322 | Chars => Name_Convention, | |
8323 | Expression => Conv_Arg)); | |
8324 | ||
8325 | -- Handle the entity argument | |
8326 | ||
8327 | Append_To (Args, | |
8328 | Make_Pragma_Argument_Association (Loc, | |
8329 | Chars => Name_Entity, | |
8330 | Expression => New_Occurrence_Of (Id, Loc))); | |
8331 | ||
8332 | -- Handle the External_Name argument | |
8333 | ||
8334 | if Present (EN) then | |
8335 | Append_To (Args, | |
8336 | Make_Pragma_Argument_Association (Loc, | |
8337 | Chars => Name_External_Name, | |
8338 | Expression => New_Copy_Tree (Expression (EN)))); | |
8339 | end if; | |
8340 | ||
8341 | -- Handle the Link_Name argument | |
8342 | ||
8343 | if Present (LN) then | |
8344 | Append_To (Args, | |
8345 | Make_Pragma_Argument_Association (Loc, | |
8346 | Chars => Name_Link_Name, | |
8347 | Expression => New_Copy_Tree (Expression (LN)))); | |
8348 | end if; | |
8349 | ||
8350 | -- Generate: | |
8351 | -- pragma Export/Import | |
8352 | -- (Convention => <Conv>/Ada, | |
8353 | -- Entity => <Id>, | |
8354 | -- [External_Name => <EN>,] | |
8355 | -- [Link_Name => <LN>]); | |
8356 | ||
8357 | Prag := | |
8358 | Make_Pragma (Loc, | |
8359 | Pragma_Identifier => | |
8360 | Make_Identifier (Loc, Chars (Identifier (Asp))), | |
8361 | Pragma_Argument_Associations => Args); | |
8362 | ||
8363 | -- Decorate the relevant aspect and the pragma | |
8364 | ||
8365 | Set_Aspect_Rep_Item (Asp, Prag); | |
8366 | ||
8367 | Set_Corresponding_Aspect (Prag, Asp); | |
8368 | Set_From_Aspect_Specification (Prag); | |
8369 | Set_Parent (Prag, Asp); | |
8370 | ||
8371 | if Asp_Id = Aspect_Import and then Is_Subprogram (Id) then | |
8372 | Set_Import_Pragma (Id, Prag); | |
8373 | end if; | |
8374 | ||
8375 | return Prag; | |
8376 | end Build_Export_Import_Pragma; | |
8377 | ||
baa571ab AC |
8378 | ------------------------------- |
8379 | -- Build_Predicate_Functions -- | |
8380 | ------------------------------- | |
5a8a6763 | 8381 | |
593e3172 | 8382 | -- The functions that are constructed here have the form: |
5a8a6763 | 8383 | |
baa571ab AC |
8384 | -- function typPredicate (Ixxx : typ) return Boolean is |
8385 | -- begin | |
8386 | -- return | |
9bdc432a | 8387 | -- typ1Predicate (typ1 (Ixxx)) |
baa571ab | 8388 | -- and then typ2Predicate (typ2 (Ixxx)) |
593e3172 PT |
8389 | -- and then ... |
8390 | -- and then exp1 and then exp2 and then ...; | |
baa571ab | 8391 | -- end typPredicate; |
5a8a6763 | 8392 | |
baa571ab AC |
8393 | -- Here exp1, and exp2 are expressions from Predicate pragmas. Note that |
8394 | -- this is the point at which these expressions get analyzed, providing the | |
8395 | -- required delay, and typ1, typ2, are entities from which predicates are | |
8396 | -- inherited. Note that we do NOT generate Check pragmas, that's because we | |
8397 | -- use this function even if checks are off, e.g. for membership tests. | |
5a8a6763 | 8398 | |
9bdc432a AC |
8399 | -- Note that the inherited predicates are evaluated first, as required by |
8400 | -- AI12-0071-1. | |
8401 | ||
8402 | -- Note that Sem_Eval.Real_Or_String_Static_Predicate_Matches depends on | |
8403 | -- the form of this return expression. | |
8404 | ||
baa571ab AC |
8405 | -- If the expression has at least one Raise_Expression, then we also build |
8406 | -- the typPredicateM version of the function, in which any occurrence of a | |
8407 | -- Raise_Expression is converted to "return False". | |
5a8a6763 | 8408 | |
b0bf18ad AC |
8409 | -- WARNING: This routine manages Ghost regions. Return statements must be |
8410 | -- replaced by gotos which jump to the end of the routine and restore the | |
8411 | -- Ghost mode. | |
8412 | ||
baa571ab AC |
8413 | procedure Build_Predicate_Functions (Typ : Entity_Id; N : Node_Id) is |
8414 | Loc : constant Source_Ptr := Sloc (Typ); | |
5a8a6763 | 8415 | |
baa571ab AC |
8416 | Expr : Node_Id; |
8417 | -- This is the expression for the result of the function. It is | |
8418 | -- is build by connecting the component predicates with AND THEN. | |
5a8a6763 | 8419 | |
5612989e | 8420 | Expr_M : Node_Id := Empty; -- init to avoid warning |
baa571ab AC |
8421 | -- This is the corresponding return expression for the Predicate_M |
8422 | -- function. It differs in that raise expressions are marked for | |
8423 | -- special expansion (see Process_REs). | |
5a8a6763 | 8424 | |
6905a049 | 8425 | Object_Name : Name_Id; |
baa571ab | 8426 | -- Name for argument of Predicate procedure. Note that we use the same |
87e69720 | 8427 | -- name for both predicate functions. That way the reference within the |
baa571ab | 8428 | -- predicate expression is the same in both functions. |
5a8a6763 | 8429 | |
6905a049 | 8430 | Object_Entity : Entity_Id; |
baa571ab | 8431 | -- Entity for argument of Predicate procedure |
5a8a6763 | 8432 | |
6905a049 AC |
8433 | Object_Entity_M : Entity_Id; |
8434 | -- Entity for argument of separate Predicate procedure when exceptions | |
8435 | -- are present in expression. | |
8436 | ||
2cc7967f AC |
8437 | FDecl : Node_Id; |
8438 | -- The function declaration | |
6905a049 | 8439 | |
2cc7967f AC |
8440 | SId : Entity_Id; |
8441 | -- Its entity | |
5a8a6763 | 8442 | |
baa571ab AC |
8443 | Raise_Expression_Present : Boolean := False; |
8444 | -- Set True if Expr has at least one Raise_Expression | |
5a8a6763 | 8445 | |
9bdc432a AC |
8446 | procedure Add_Condition (Cond : Node_Id); |
8447 | -- Append Cond to Expr using "and then" (or just copy Cond to Expr if | |
8448 | -- Expr is empty). | |
5a8a6763 | 8449 | |
baa571ab AC |
8450 | procedure Add_Predicates; |
8451 | -- Appends expressions for any Predicate pragmas in the rep item chain | |
8452 | -- Typ to Expr. Note that we look only at items for this exact entity. | |
8453 | -- Inheritance of predicates for the parent type is done by calling the | |
8454 | -- Predicate_Function of the parent type, using Add_Call above. | |
5a8a6763 | 8455 | |
9bdc432a AC |
8456 | procedure Add_Call (T : Entity_Id); |
8457 | -- Includes a call to the predicate function for type T in Expr if T | |
8458 | -- has predicates and Predicate_Function (T) is non-empty. | |
8459 | ||
baa571ab AC |
8460 | function Process_RE (N : Node_Id) return Traverse_Result; |
8461 | -- Used in Process REs, tests if node N is a raise expression, and if | |
8462 | -- so, marks it to be converted to return False. | |
5a8a6763 | 8463 | |
baa571ab AC |
8464 | procedure Process_REs is new Traverse_Proc (Process_RE); |
8465 | -- Marks any raise expressions in Expr_M to return False | |
5a8a6763 | 8466 | |
241ebe89 HK |
8467 | function Test_RE (N : Node_Id) return Traverse_Result; |
8468 | -- Used in Test_REs, tests one node for being a raise expression, and if | |
8469 | -- so sets Raise_Expression_Present True. | |
8470 | ||
8471 | procedure Test_REs is new Traverse_Proc (Test_RE); | |
8472 | -- Tests to see if Expr contains any raise expressions | |
8473 | ||
baa571ab AC |
8474 | -------------- |
8475 | -- Add_Call -- | |
8476 | -------------- | |
5a8a6763 | 8477 | |
baa571ab AC |
8478 | procedure Add_Call (T : Entity_Id) is |
8479 | Exp : Node_Id; | |
5a8a6763 | 8480 | |
baa571ab AC |
8481 | begin |
8482 | if Present (T) and then Present (Predicate_Function (T)) then | |
8483 | Set_Has_Predicates (Typ); | |
5a8a6763 | 8484 | |
e7c25229 AC |
8485 | -- Build the call to the predicate function of T. The type may be |
8486 | -- derived, so use an unchecked conversion for the actual. | |
5a8a6763 | 8487 | |
baa571ab AC |
8488 | Exp := |
8489 | Make_Predicate_Call | |
e7c25229 AC |
8490 | (Typ => T, |
8491 | Expr => | |
8492 | Unchecked_Convert_To (T, | |
8493 | Make_Identifier (Loc, Object_Name))); | |
5a8a6763 | 8494 | |
9bdc432a | 8495 | -- "and"-in the call to evolving expression |
5a8a6763 | 8496 | |
9bdc432a | 8497 | Add_Condition (Exp); |
5a8a6763 | 8498 | |
baa571ab AC |
8499 | -- Output info message on inheritance if required. Note we do not |
8500 | -- give this information for generic actual types, since it is | |
8501 | -- unwelcome noise in that case in instantiations. We also | |
8502 | -- generally suppress the message in instantiations, and also | |
8503 | -- if it involves internal names. | |
5a8a6763 | 8504 | |
baa571ab AC |
8505 | if Opt.List_Inherited_Aspects |
8506 | and then not Is_Generic_Actual_Type (Typ) | |
8507 | and then Instantiation_Depth (Sloc (Typ)) = 0 | |
8508 | and then not Is_Internal_Name (Chars (T)) | |
8509 | and then not Is_Internal_Name (Chars (Typ)) | |
8510 | then | |
8511 | Error_Msg_Sloc := Sloc (Predicate_Function (T)); | |
8512 | Error_Msg_Node_2 := T; | |
8513 | Error_Msg_N ("info: & inherits predicate from & #?L?", Typ); | |
8514 | end if; | |
8515 | end if; | |
8516 | end Add_Call; | |
5a8a6763 | 8517 | |
9bdc432a AC |
8518 | ------------------- |
8519 | -- Add_Condition -- | |
8520 | ------------------- | |
8521 | ||
8522 | procedure Add_Condition (Cond : Node_Id) is | |
8523 | begin | |
8524 | -- This is the first predicate expression | |
8525 | ||
8526 | if No (Expr) then | |
8527 | Expr := Cond; | |
8528 | ||
8529 | -- Otherwise concatenate to the existing predicate expressions by | |
8530 | -- using "and then". | |
8531 | ||
8532 | else | |
8533 | Expr := | |
8534 | Make_And_Then (Loc, | |
8535 | Left_Opnd => Relocate_Node (Expr), | |
8536 | Right_Opnd => Cond); | |
8537 | end if; | |
8538 | end Add_Condition; | |
8539 | ||
baa571ab AC |
8540 | -------------------- |
8541 | -- Add_Predicates -- | |
8542 | -------------------- | |
5a8a6763 | 8543 | |
baa571ab | 8544 | procedure Add_Predicates is |
241ebe89 HK |
8545 | procedure Add_Predicate (Prag : Node_Id); |
8546 | -- Concatenate the expression of predicate pragma Prag to Expr by | |
8547 | -- using a short circuit "and then" operator. | |
5a8a6763 | 8548 | |
241ebe89 HK |
8549 | ------------------- |
8550 | -- Add_Predicate -- | |
8551 | ------------------- | |
5a8a6763 | 8552 | |
241ebe89 HK |
8553 | procedure Add_Predicate (Prag : Node_Id) is |
8554 | procedure Replace_Type_Reference (N : Node_Id); | |
8555 | -- Replace a single occurrence N of the subtype name with a | |
8556 | -- reference to the formal of the predicate function. N can be an | |
8557 | -- identifier referencing the subtype, or a selected component, | |
8558 | -- representing an appropriately qualified occurrence of the | |
8559 | -- subtype name. | |
8560 | ||
8561 | procedure Replace_Type_References is | |
8562 | new Replace_Type_References_Generic (Replace_Type_Reference); | |
8563 | -- Traverse an expression changing every occurrence of an | |
8564 | -- identifier whose name matches the name of the subtype with a | |
8565 | -- reference to the formal parameter of the predicate function. | |
8566 | ||
8567 | ---------------------------- | |
8568 | -- Replace_Type_Reference -- | |
8569 | ---------------------------- | |
8570 | ||
8571 | procedure Replace_Type_Reference (N : Node_Id) is | |
8572 | begin | |
8573 | Rewrite (N, Make_Identifier (Sloc (N), Object_Name)); | |
8574 | -- Use the Sloc of the usage name, not the defining name | |
5a8a6763 | 8575 | |
241ebe89 HK |
8576 | Set_Etype (N, Typ); |
8577 | Set_Entity (N, Object_Entity); | |
1e194575 | 8578 | |
241ebe89 HK |
8579 | -- We want to treat the node as if it comes from source, so |
8580 | -- that ASIS will not ignore it. | |
1e194575 | 8581 | |
241ebe89 HK |
8582 | Set_Comes_From_Source (N, True); |
8583 | end Replace_Type_Reference; | |
1e194575 | 8584 | |
241ebe89 | 8585 | -- Local variables |
1e194575 | 8586 | |
241ebe89 HK |
8587 | Asp : constant Node_Id := Corresponding_Aspect (Prag); |
8588 | Arg1 : Node_Id; | |
8589 | Arg2 : Node_Id; | |
1e194575 | 8590 | |
241ebe89 | 8591 | -- Start of processing for Add_Predicate |
596b25f9 | 8592 | |
241ebe89 | 8593 | begin |
62807842 AC |
8594 | -- Mark corresponding SCO as enabled |
8595 | ||
8596 | Set_SCO_Pragma_Enabled (Sloc (Prag)); | |
8597 | ||
241ebe89 HK |
8598 | -- Extract the arguments of the pragma. The expression itself |
8599 | -- is copied for use in the predicate function, to preserve the | |
8600 | -- original version for ASIS use. | |
1e194575 | 8601 | |
241ebe89 HK |
8602 | Arg1 := First (Pragma_Argument_Associations (Prag)); |
8603 | Arg2 := Next (Arg1); | |
1e194575 | 8604 | |
241ebe89 HK |
8605 | Arg1 := Get_Pragma_Arg (Arg1); |
8606 | Arg2 := New_Copy_Tree (Get_Pragma_Arg (Arg2)); | |
1e194575 | 8607 | |
241ebe89 HK |
8608 | -- When the predicate pragma applies to the current type or its |
8609 | -- full view, replace all occurrences of the subtype name with | |
8610 | -- references to the formal parameter of the predicate function. | |
ff1f1705 | 8611 | |
241ebe89 HK |
8612 | if Entity (Arg1) = Typ |
8613 | or else Full_View (Entity (Arg1)) = Typ | |
8614 | then | |
8615 | Replace_Type_References (Arg2, Typ); | |
ff1f1705 | 8616 | |
241ebe89 HK |
8617 | -- If the predicate pragma comes from an aspect, replace the |
8618 | -- saved expression because we need the subtype references | |
8619 | -- replaced for the calls to Preanalyze_Spec_Expression in | |
8620 | -- Check_Aspect_At_xxx routines. | |
ff1f1705 | 8621 | |
241ebe89 | 8622 | if Present (Asp) then |
241ebe89 HK |
8623 | Set_Entity (Identifier (Asp), New_Copy_Tree (Arg2)); |
8624 | end if; | |
596b25f9 | 8625 | |
9bdc432a | 8626 | -- "and"-in the Arg2 condition to evolving expression |
ff1f1705 | 8627 | |
9bdc432a | 8628 | Add_Condition (Relocate_Node (Arg2)); |
241ebe89 HK |
8629 | end if; |
8630 | end Add_Predicate; | |
064f4527 | 8631 | |
241ebe89 | 8632 | -- Local variables |
064f4527 | 8633 | |
241ebe89 | 8634 | Ritem : Node_Id; |
1e194575 | 8635 | |
241ebe89 | 8636 | -- Start of processing for Add_Predicates |
1e194575 | 8637 | |
241ebe89 HK |
8638 | begin |
8639 | Ritem := First_Rep_Item (Typ); | |
e7c25229 AC |
8640 | |
8641 | -- If the type is private, check whether full view has inherited | |
8642 | -- predicates. | |
8643 | ||
8644 | if Is_Private_Type (Typ) and then No (Ritem) then | |
8645 | Ritem := First_Rep_Item (Full_View (Typ)); | |
8646 | end if; | |
8647 | ||
241ebe89 HK |
8648 | while Present (Ritem) loop |
8649 | if Nkind (Ritem) = N_Pragma | |
6e759c2a | 8650 | and then Pragma_Name (Ritem) = Name_Predicate |
241ebe89 HK |
8651 | then |
8652 | Add_Predicate (Ritem); | |
22a4f9d5 AC |
8653 | |
8654 | -- If the type is declared in an inner package it may be frozen | |
8655 | -- outside of the package, and the generated pragma has not been | |
8656 | -- analyzed yet, so capture the expression for the predicate | |
8657 | -- function at this point. | |
8658 | ||
8659 | elsif Nkind (Ritem) = N_Aspect_Specification | |
f76647c2 AC |
8660 | and then Present (Aspect_Rep_Item (Ritem)) |
8661 | and then Scope (Typ) /= Current_Scope | |
22a4f9d5 AC |
8662 | then |
8663 | declare | |
8664 | Prag : constant Node_Id := Aspect_Rep_Item (Ritem); | |
8665 | ||
8666 | begin | |
8667 | if Nkind (Prag) = N_Pragma | |
6e759c2a | 8668 | and then Pragma_Name (Prag) = Name_Predicate |
22a4f9d5 AC |
8669 | then |
8670 | Add_Predicate (Prag); | |
8671 | end if; | |
8672 | end; | |
baa571ab | 8673 | end if; |
1e194575 | 8674 | |
baa571ab AC |
8675 | Next_Rep_Item (Ritem); |
8676 | end loop; | |
8677 | end Add_Predicates; | |
1e194575 | 8678 | |
baa571ab AC |
8679 | ---------------- |
8680 | -- Process_RE -- | |
8681 | ---------------- | |
1e194575 | 8682 | |
baa571ab | 8683 | function Process_RE (N : Node_Id) return Traverse_Result is |
5a8a6763 | 8684 | begin |
baa571ab AC |
8685 | if Nkind (N) = N_Raise_Expression then |
8686 | Set_Convert_To_Return_False (N); | |
8687 | return Skip; | |
5a8a6763 | 8688 | else |
baa571ab | 8689 | return OK; |
5a8a6763 | 8690 | end if; |
baa571ab | 8691 | end Process_RE; |
f6b5dc8e | 8692 | |
5a8a6763 | 8693 | ------------- |
baa571ab | 8694 | -- Test_RE -- |
5a8a6763 | 8695 | ------------- |
f6b5dc8e | 8696 | |
baa571ab | 8697 | function Test_RE (N : Node_Id) return Traverse_Result is |
1e194575 | 8698 | begin |
baa571ab AC |
8699 | if Nkind (N) = N_Raise_Expression then |
8700 | Raise_Expression_Present := True; | |
8701 | return Abandon; | |
8702 | else | |
8703 | return OK; | |
8704 | end if; | |
8705 | end Test_RE; | |
1e194575 | 8706 | |
241ebe89 HK |
8707 | -- Local variables |
8708 | ||
9057bd6a HK |
8709 | Saved_GM : constant Ghost_Mode_Type := Ghost_Mode; |
8710 | Saved_IGR : constant Node_Id := Ignored_Ghost_Region; | |
8711 | -- Save the Ghost-related attributes to restore on exit | |
241ebe89 | 8712 | |
baa571ab | 8713 | -- Start of processing for Build_Predicate_Functions |
1e194575 | 8714 | |
baa571ab AC |
8715 | begin |
8716 | -- Return if already built or if type does not have predicates | |
86200f66 | 8717 | |
6905a049 | 8718 | SId := Predicate_Function (Typ); |
baa571ab | 8719 | if not Has_Predicates (Typ) |
6905a049 | 8720 | or else (Present (SId) and then Has_Completion (SId)) |
baa571ab AC |
8721 | then |
8722 | return; | |
5f531fef ES |
8723 | |
8724 | -- Do not generate predicate bodies within a generic unit. The | |
8725 | -- expressions have been analyzed already, and the bodies play | |
558241c0 ES |
8726 | -- no role if not within an executable unit. However, if a statc |
8727 | -- predicate is present it must be processed for legality checks | |
8728 | -- such as case coverage in an expression. | |
5f531fef | 8729 | |
558241c0 ES |
8730 | elsif Inside_A_Generic |
8731 | and then not Has_Static_Predicate_Aspect (Typ) | |
8732 | then | |
5f531fef | 8733 | return; |
baa571ab | 8734 | end if; |
5a8a6763 | 8735 | |
1af4455a HK |
8736 | -- The related type may be subject to pragma Ghost. Set the mode now to |
8737 | -- ensure that the predicate functions are properly marked as Ghost. | |
241ebe89 | 8738 | |
f9a8f910 | 8739 | Set_Ghost_Mode (Typ); |
241ebe89 | 8740 | |
baa571ab | 8741 | -- Prepare to construct predicate expression |
1e194575 | 8742 | |
baa571ab | 8743 | Expr := Empty; |
1e194575 | 8744 | |
6905a049 AC |
8745 | if Present (SId) then |
8746 | FDecl := Unit_Declaration_Node (SId); | |
8747 | ||
8748 | else | |
8749 | FDecl := Build_Predicate_Function_Declaration (Typ); | |
8750 | SId := Defining_Entity (FDecl); | |
8751 | end if; | |
8752 | ||
8753 | -- Recover name of formal parameter of function that replaces references | |
8754 | -- to the type in predicate expressions. | |
8755 | ||
8756 | Object_Entity := | |
8757 | Defining_Identifier | |
8758 | (First (Parameter_Specifications (Specification (FDecl)))); | |
8759 | ||
8760 | Object_Name := Chars (Object_Entity); | |
8761 | Object_Entity_M := Make_Defining_Identifier (Loc, Chars => Object_Name); | |
8762 | ||
9bdc432a AC |
8763 | -- Add predicates for ancestor if present. These must come before the |
8764 | -- ones for the current type, as required by AI12-0071-1. | |
1e194575 | 8765 | |
baa571ab | 8766 | declare |
e7c25229 | 8767 | Atyp : Entity_Id; |
5a8a6763 | 8768 | begin |
e7c25229 AC |
8769 | Atyp := Nearest_Ancestor (Typ); |
8770 | ||
8771 | -- The type may be private but the full view may inherit predicates | |
8772 | ||
8773 | if No (Atyp) and then Is_Private_Type (Typ) then | |
8774 | Atyp := Nearest_Ancestor (Full_View (Typ)); | |
8775 | end if; | |
8776 | ||
baa571ab AC |
8777 | if Present (Atyp) then |
8778 | Add_Call (Atyp); | |
8779 | end if; | |
8780 | end; | |
2cc7967f | 8781 | |
9bdc432a AC |
8782 | -- Add Predicates for the current type |
8783 | ||
8784 | Add_Predicates; | |
8785 | ||
baa571ab | 8786 | -- Case where predicates are present |
86200f66 | 8787 | |
baa571ab | 8788 | if Present (Expr) then |
92a68a04 | 8789 | |
baa571ab | 8790 | -- Test for raise expression present |
752b81d9 | 8791 | |
baa571ab | 8792 | Test_REs (Expr); |
86200f66 | 8793 | |
baa571ab AC |
8794 | -- If raise expression is present, capture a copy of Expr for use |
8795 | -- in building the predicateM function version later on. For this | |
8796 | -- copy we replace references to Object_Entity by Object_Entity_M. | |
86200f66 | 8797 | |
baa571ab AC |
8798 | if Raise_Expression_Present then |
8799 | declare | |
92a68a04 HK |
8800 | function Reset_Loop_Variable |
8801 | (N : Node_Id) return Traverse_Result; | |
5c5e108f | 8802 | |
92a68a04 | 8803 | procedure Reset_Loop_Variables is |
5c5e108f AC |
8804 | new Traverse_Proc (Reset_Loop_Variable); |
8805 | ||
8806 | ------------------------ | |
8807 | -- Reset_Loop_Variable -- | |
8808 | ------------------------ | |
8809 | ||
92a68a04 HK |
8810 | function Reset_Loop_Variable |
8811 | (N : Node_Id) return Traverse_Result | |
5c5e108f AC |
8812 | is |
8813 | begin | |
8814 | if Nkind (N) = N_Iterator_Specification then | |
92a68a04 HK |
8815 | Set_Defining_Identifier (N, |
8816 | Make_Defining_Identifier | |
8817 | (Sloc (N), Chars (Defining_Identifier (N)))); | |
5c5e108f AC |
8818 | end if; |
8819 | ||
8820 | return OK; | |
8821 | end Reset_Loop_Variable; | |
8822 | ||
92a68a04 HK |
8823 | -- Local variables |
8824 | ||
8825 | Map : constant Elist_Id := New_Elmt_List; | |
8826 | ||
baa571ab AC |
8827 | begin |
8828 | Append_Elmt (Object_Entity, Map); | |
8829 | Append_Elmt (Object_Entity_M, Map); | |
8830 | Expr_M := New_Copy_Tree (Expr, Map => Map); | |
92a68a04 HK |
8831 | |
8832 | -- The unanalyzed expression will be copied and appear in | |
8833 | -- both functions. Normally expressions do not declare new | |
8834 | -- entities, but quantified expressions do, so we need to | |
8835 | -- create new entities for their bound variables, to prevent | |
8836 | -- multiple definitions in gigi. | |
8837 | ||
8838 | Reset_Loop_Variables (Expr_M); | |
baa571ab AC |
8839 | end; |
8840 | end if; | |
1e194575 | 8841 | |
baa571ab | 8842 | -- Build the main predicate function |
86200f66 | 8843 | |
baa571ab | 8844 | declare |
baa571ab AC |
8845 | SIdB : constant Entity_Id := |
8846 | Make_Defining_Identifier (Loc, | |
8847 | Chars => New_External_Name (Chars (Typ), "Predicate")); | |
8848 | -- The entity for the function body | |
86200f66 | 8849 | |
baa571ab | 8850 | Spec : Node_Id; |
baa571ab | 8851 | FBody : Node_Id; |
86200f66 | 8852 | |
baa571ab | 8853 | begin |
0691ed6b AC |
8854 | Set_Ekind (SIdB, E_Function); |
8855 | Set_Is_Predicate_Function (SIdB); | |
8856 | ||
baa571ab | 8857 | -- The predicate function is shared between views of a type |
1e194575 | 8858 | |
baa571ab AC |
8859 | if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then |
8860 | Set_Predicate_Function (Full_View (Typ), SId); | |
1e194575 | 8861 | end if; |
1e194575 | 8862 | |
baa571ab | 8863 | -- Build function body |
1e194575 | 8864 | |
baa571ab AC |
8865 | Spec := |
8866 | Make_Function_Specification (Loc, | |
8867 | Defining_Unit_Name => SIdB, | |
8868 | Parameter_Specifications => New_List ( | |
8869 | Make_Parameter_Specification (Loc, | |
8870 | Defining_Identifier => | |
8871 | Make_Defining_Identifier (Loc, Object_Name), | |
8872 | Parameter_Type => | |
8873 | New_Occurrence_Of (Typ, Loc))), | |
8874 | Result_Definition => | |
8875 | New_Occurrence_Of (Standard_Boolean, Loc)); | |
1e194575 | 8876 | |
baa571ab AC |
8877 | FBody := |
8878 | Make_Subprogram_Body (Loc, | |
8879 | Specification => Spec, | |
8880 | Declarations => Empty_List, | |
8881 | Handled_Statement_Sequence => | |
8882 | Make_Handled_Sequence_Of_Statements (Loc, | |
8883 | Statements => New_List ( | |
8884 | Make_Simple_Return_Statement (Loc, | |
8885 | Expression => Expr)))); | |
86200f66 | 8886 | |
8218cfde | 8887 | -- The declaration has been analyzed when created, and placed |
c365eb26 ES |
8888 | -- after type declaration. Insert body itself after freeze node, |
8889 | -- unless subprogram declaration is already there, in which case | |
8890 | -- body better be placed afterwards. | |
1e194575 | 8891 | |
c365eb26 ES |
8892 | if FDecl = Next (N) then |
8893 | Insert_After_And_Analyze (FDecl, FBody); | |
8894 | else | |
8895 | Insert_After_And_Analyze (N, FBody); | |
8896 | end if; | |
e3d9f448 | 8897 | |
6989a2bb ES |
8898 | -- The defining identifier of a quantified expression carries the |
8899 | -- scope in which the type appears, but when unnesting we need | |
8900 | -- to indicate that its proper scope is the constructed predicate | |
8901 | -- function. The quantified expressions have been converted into | |
8902 | -- loops during analysis and expansion. | |
8903 | ||
8904 | declare | |
92a68a04 HK |
8905 | function Reset_Quantified_Variable_Scope |
8906 | (N : Node_Id) return Traverse_Result; | |
6989a2bb ES |
8907 | |
8908 | procedure Reset_Quantified_Variables_Scope is | |
8909 | new Traverse_Proc (Reset_Quantified_Variable_Scope); | |
8910 | ||
8911 | ------------------------------------- | |
8912 | -- Reset_Quantified_Variable_Scope -- | |
8913 | ------------------------------------- | |
8914 | ||
92a68a04 HK |
8915 | function Reset_Quantified_Variable_Scope |
8916 | (N : Node_Id) return Traverse_Result | |
6989a2bb ES |
8917 | is |
8918 | begin | |
8919 | if Nkind_In (N, N_Iterator_Specification, | |
8920 | N_Loop_Parameter_Specification) | |
8921 | then | |
8922 | Set_Scope (Defining_Identifier (N), | |
8923 | Predicate_Function (Typ)); | |
8924 | end if; | |
92a68a04 | 8925 | |
6989a2bb ES |
8926 | return OK; |
8927 | end Reset_Quantified_Variable_Scope; | |
8928 | ||
8929 | begin | |
8930 | if Unnest_Subprogram_Mode then | |
8931 | Reset_Quantified_Variables_Scope (Expr); | |
8932 | end if; | |
8933 | end; | |
8934 | ||
8218cfde ES |
8935 | -- within a generic unit, prevent a double analysis of the body |
8936 | -- which will not be marked analyzed yet. This will happen when | |
812e6118 | 8937 | -- the freeze node is created during the preanalysis of an |
8218cfde ES |
8938 | -- expression function. |
8939 | ||
8940 | if Inside_A_Generic then | |
8941 | Set_Analyzed (FBody); | |
8942 | end if; | |
8943 | ||
e3d9f448 AC |
8944 | -- Static predicate functions are always side-effect free, and |
8945 | -- in most cases dynamic predicate functions are as well. Mark | |
8946 | -- them as such whenever possible, so redundant predicate checks | |
33398e3c AC |
8947 | -- can be optimized. If there is a variable reference within the |
8948 | -- expression, the function is not pure. | |
00c93ba2 | 8949 | |
e3d9f448 | 8950 | if Expander_Active then |
33398e3c AC |
8951 | Set_Is_Pure (SId, |
8952 | Side_Effect_Free (Expr, Variable_Ref => True)); | |
e3d9f448 AC |
8953 | Set_Is_Inlined (SId); |
8954 | end if; | |
5a8a6763 | 8955 | end; |
1e194575 | 8956 | |
baa571ab | 8957 | -- Test for raise expressions present and if so build M version |
1e194575 | 8958 | |
baa571ab AC |
8959 | if Raise_Expression_Present then |
8960 | declare | |
8961 | SId : constant Entity_Id := | |
8962 | Make_Defining_Identifier (Loc, | |
8963 | Chars => New_External_Name (Chars (Typ), "PredicateM")); | |
50ef946c | 8964 | -- The entity for the function spec |
1e194575 | 8965 | |
baa571ab AC |
8966 | SIdB : constant Entity_Id := |
8967 | Make_Defining_Identifier (Loc, | |
8968 | Chars => New_External_Name (Chars (Typ), "PredicateM")); | |
8969 | -- The entity for the function body | |
616547fa | 8970 | |
baa571ab | 8971 | Spec : Node_Id; |
baa571ab | 8972 | FBody : Node_Id; |
6905a049 | 8973 | FDecl : Node_Id; |
baa571ab | 8974 | BTemp : Entity_Id; |
1e194575 | 8975 | |
baa571ab AC |
8976 | begin |
8977 | -- Mark any raise expressions for special expansion | |
1e194575 | 8978 | |
baa571ab | 8979 | Process_REs (Expr_M); |
1e194575 | 8980 | |
baa571ab | 8981 | -- Build function declaration |
1e194575 | 8982 | |
baa571ab AC |
8983 | Set_Ekind (SId, E_Function); |
8984 | Set_Is_Predicate_Function_M (SId); | |
8985 | Set_Predicate_Function_M (Typ, SId); | |
1e194575 | 8986 | |
baa571ab | 8987 | -- The predicate function is shared between views of a type |
1e194575 | 8988 | |
baa571ab AC |
8989 | if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then |
8990 | Set_Predicate_Function_M (Full_View (Typ), SId); | |
8991 | end if; | |
86200f66 | 8992 | |
baa571ab AC |
8993 | Spec := |
8994 | Make_Function_Specification (Loc, | |
8995 | Defining_Unit_Name => SId, | |
8996 | Parameter_Specifications => New_List ( | |
8997 | Make_Parameter_Specification (Loc, | |
8998 | Defining_Identifier => Object_Entity_M, | |
8999 | Parameter_Type => New_Occurrence_Of (Typ, Loc))), | |
9000 | Result_Definition => | |
9001 | New_Occurrence_Of (Standard_Boolean, Loc)); | |
86200f66 | 9002 | |
baa571ab AC |
9003 | FDecl := |
9004 | Make_Subprogram_Declaration (Loc, | |
9005 | Specification => Spec); | |
86200f66 | 9006 | |
baa571ab | 9007 | -- Build function body |
86200f66 | 9008 | |
baa571ab AC |
9009 | Spec := |
9010 | Make_Function_Specification (Loc, | |
9011 | Defining_Unit_Name => SIdB, | |
9012 | Parameter_Specifications => New_List ( | |
9013 | Make_Parameter_Specification (Loc, | |
9014 | Defining_Identifier => | |
9015 | Make_Defining_Identifier (Loc, Object_Name), | |
9016 | Parameter_Type => | |
9017 | New_Occurrence_Of (Typ, Loc))), | |
9018 | Result_Definition => | |
9019 | New_Occurrence_Of (Standard_Boolean, Loc)); | |
86200f66 | 9020 | |
baa571ab AC |
9021 | -- Build the body, we declare the boolean expression before |
9022 | -- doing the return, because we are not really confident of | |
9023 | -- what happens if a return appears within a return. | |
86200f66 | 9024 | |
baa571ab AC |
9025 | BTemp := |
9026 | Make_Defining_Identifier (Loc, | |
9027 | Chars => New_Internal_Name ('B')); | |
86200f66 | 9028 | |
baa571ab AC |
9029 | FBody := |
9030 | Make_Subprogram_Body (Loc, | |
9031 | Specification => Spec, | |
86200f66 | 9032 | |
baa571ab AC |
9033 | Declarations => New_List ( |
9034 | Make_Object_Declaration (Loc, | |
9035 | Defining_Identifier => BTemp, | |
9036 | Constant_Present => True, | |
9037 | Object_Definition => | |
9038 | New_Occurrence_Of (Standard_Boolean, Loc), | |
9039 | Expression => Expr_M)), | |
1e194575 | 9040 | |
baa571ab AC |
9041 | Handled_Statement_Sequence => |
9042 | Make_Handled_Sequence_Of_Statements (Loc, | |
9043 | Statements => New_List ( | |
9044 | Make_Simple_Return_Statement (Loc, | |
9045 | Expression => New_Occurrence_Of (BTemp, Loc))))); | |
1e194575 | 9046 | |
baa571ab | 9047 | -- Insert declaration before freeze node and body after |
1e194575 | 9048 | |
baa571ab AC |
9049 | Insert_Before_And_Analyze (N, FDecl); |
9050 | Insert_After_And_Analyze (N, FBody); | |
6989a2bb ES |
9051 | |
9052 | -- Should quantified expressions be handled here as well ??? | |
baa571ab AC |
9053 | end; |
9054 | end if; | |
86200f66 | 9055 | |
ee4eee0a AC |
9056 | -- See if we have a static predicate. Note that the answer may be |
9057 | -- yes even if we have an explicit Dynamic_Predicate present. | |
86200f66 | 9058 | |
ee4eee0a | 9059 | declare |
fc3a3f3b | 9060 | PS : Boolean; |
ee4eee0a | 9061 | EN : Node_Id; |
86200f66 | 9062 | |
ee4eee0a | 9063 | begin |
fc3a3f3b RD |
9064 | if not Is_Scalar_Type (Typ) and then not Is_String_Type (Typ) then |
9065 | PS := False; | |
9066 | else | |
9067 | PS := Is_Predicate_Static (Expr, Object_Name); | |
9068 | end if; | |
9069 | ||
c624298a | 9070 | -- Case where we have a predicate-static aspect |
86200f66 | 9071 | |
ee4eee0a | 9072 | if PS then |
86200f66 | 9073 | |
ee4eee0a AC |
9074 | -- We don't set Has_Static_Predicate_Aspect, since we can have |
9075 | -- any of the three cases (Predicate, Dynamic_Predicate, or | |
9076 | -- Static_Predicate) generating a predicate with an expression | |
c624298a | 9077 | -- that is predicate-static. We just indicate that we have a |
ee4eee0a | 9078 | -- predicate that can be treated as static. |
f6b5dc8e | 9079 | |
ee4eee0a | 9080 | Set_Has_Static_Predicate (Typ); |
f6b5dc8e | 9081 | |
ee4eee0a | 9082 | -- For discrete subtype, build the static predicate list |
86200f66 | 9083 | |
ee4eee0a AC |
9084 | if Is_Discrete_Type (Typ) then |
9085 | Build_Discrete_Static_Predicate (Typ, Expr, Object_Name); | |
9086 | ||
9087 | -- If we don't get a static predicate list, it means that we | |
9088 | -- have a case where this is not possible, most typically in | |
9089 | -- the case where we inherit a dynamic predicate. We do not | |
9090 | -- consider this an error, we just leave the predicate as | |
9091 | -- dynamic. But if we do succeed in building the list, then | |
9092 | -- we mark the predicate as static. | |
9093 | ||
60f908dd | 9094 | if No (Static_Discrete_Predicate (Typ)) then |
ee4eee0a AC |
9095 | Set_Has_Static_Predicate (Typ, False); |
9096 | end if; | |
fc3a3f3b RD |
9097 | |
9098 | -- For real or string subtype, save predicate expression | |
9099 | ||
9100 | elsif Is_Real_Type (Typ) or else Is_String_Type (Typ) then | |
9101 | Set_Static_Real_Or_String_Predicate (Typ, Expr); | |
ee4eee0a AC |
9102 | end if; |
9103 | ||
9104 | -- Case of dynamic predicate (expression is not predicate-static) | |
86200f66 | 9105 | |
baa571ab | 9106 | else |
ee4eee0a AC |
9107 | -- Again, we don't set Has_Dynamic_Predicate_Aspect, since that |
9108 | -- is only set if we have an explicit Dynamic_Predicate aspect | |
9109 | -- given. Here we may simply have a Predicate aspect where the | |
9110 | -- expression happens not to be predicate-static. | |
9111 | ||
9112 | -- Emit an error when the predicate is categorized as static | |
9113 | -- but its expression is not predicate-static. | |
9114 | ||
9115 | -- First a little fiddling to get a nice location for the | |
9116 | -- message. If the expression is of the form (A and then B), | |
9bdc432a AC |
9117 | -- where A is an inherited predicate, then use the right |
9118 | -- operand for the Sloc. This avoids getting confused by a call | |
9119 | -- to an inherited predicate with a less convenient source | |
9120 | -- location. | |
ee4eee0a AC |
9121 | |
9122 | EN := Expr; | |
9bdc432a AC |
9123 | while Nkind (EN) = N_And_Then |
9124 | and then Nkind (Left_Opnd (EN)) = N_Function_Call | |
9125 | and then Is_Predicate_Function | |
9126 | (Entity (Name (Left_Opnd (EN)))) | |
9127 | loop | |
9128 | EN := Right_Opnd (EN); | |
ee4eee0a AC |
9129 | end loop; |
9130 | ||
9131 | -- Now post appropriate message | |
9132 | ||
9133 | if Has_Static_Predicate_Aspect (Typ) then | |
fc3a3f3b | 9134 | if Is_Scalar_Type (Typ) or else Is_String_Type (Typ) then |
ee4eee0a | 9135 | Error_Msg_F |
28e18b4f | 9136 | ("expression is not predicate-static (RM 3.2.4(16-22))", |
ee4eee0a AC |
9137 | EN); |
9138 | else | |
fc3a3f3b RD |
9139 | Error_Msg_F |
9140 | ("static predicate requires scalar or string type", EN); | |
ee4eee0a AC |
9141 | end if; |
9142 | end if; | |
baa571ab | 9143 | end if; |
ee4eee0a | 9144 | end; |
baa571ab | 9145 | end if; |
241ebe89 | 9146 | |
9057bd6a | 9147 | Restore_Ghost_Region (Saved_GM, Saved_IGR); |
baa571ab | 9148 | end Build_Predicate_Functions; |
86200f66 | 9149 | |
6905a049 AC |
9150 | ------------------------------------------ |
9151 | -- Build_Predicate_Function_Declaration -- | |
9152 | ------------------------------------------ | |
9153 | ||
b0bf18ad AC |
9154 | -- WARNING: This routine manages Ghost regions. Return statements must be |
9155 | -- replaced by gotos which jump to the end of the routine and restore the | |
9156 | -- Ghost mode. | |
9157 | ||
6905a049 AC |
9158 | function Build_Predicate_Function_Declaration |
9159 | (Typ : Entity_Id) return Node_Id | |
9160 | is | |
9161 | Loc : constant Source_Ptr := Sloc (Typ); | |
9162 | ||
9057bd6a HK |
9163 | Saved_GM : constant Ghost_Mode_Type := Ghost_Mode; |
9164 | Saved_IGR : constant Node_Id := Ignored_Ghost_Region; | |
9165 | -- Save the Ghost-related attributes to restore on exit | |
f9a8f910 | 9166 | |
d65a80fd HK |
9167 | Func_Decl : Node_Id; |
9168 | Func_Id : Entity_Id; | |
d65a80fd | 9169 | Spec : Node_Id; |
6905a049 | 9170 | |
d65a80fd HK |
9171 | begin |
9172 | -- The related type may be subject to pragma Ghost. Set the mode now to | |
9173 | -- ensure that the predicate functions are properly marked as Ghost. | |
6905a049 | 9174 | |
f9a8f910 | 9175 | Set_Ghost_Mode (Typ); |
6905a049 | 9176 | |
d65a80fd HK |
9177 | Func_Id := |
9178 | Make_Defining_Identifier (Loc, | |
9179 | Chars => New_External_Name (Chars (Typ), "Predicate")); | |
6905a049 | 9180 | |
cccb761b AC |
9181 | -- The predicate function requires debug info when the predicates are |
9182 | -- subject to Source Coverage Obligations. | |
9183 | ||
9184 | if Opt.Generate_SCO then | |
9185 | Set_Debug_Info_Needed (Func_Id); | |
9186 | end if; | |
9187 | ||
6905a049 AC |
9188 | Spec := |
9189 | Make_Function_Specification (Loc, | |
d65a80fd | 9190 | Defining_Unit_Name => Func_Id, |
6905a049 AC |
9191 | Parameter_Specifications => New_List ( |
9192 | Make_Parameter_Specification (Loc, | |
d65a80fd | 9193 | Defining_Identifier => Make_Temporary (Loc, 'I'), |
6905a049 AC |
9194 | Parameter_Type => New_Occurrence_Of (Typ, Loc))), |
9195 | Result_Definition => | |
9196 | New_Occurrence_Of (Standard_Boolean, Loc)); | |
9197 | ||
d65a80fd | 9198 | Func_Decl := Make_Subprogram_Declaration (Loc, Specification => Spec); |
6905a049 | 9199 | |
d65a80fd HK |
9200 | Set_Ekind (Func_Id, E_Function); |
9201 | Set_Etype (Func_Id, Standard_Boolean); | |
9202 | Set_Is_Internal (Func_Id); | |
9203 | Set_Is_Predicate_Function (Func_Id); | |
9204 | Set_Predicate_Function (Typ, Func_Id); | |
6905a049 | 9205 | |
d65a80fd HK |
9206 | Insert_After (Parent (Typ), Func_Decl); |
9207 | Analyze (Func_Decl); | |
6905a049 | 9208 | |
9057bd6a | 9209 | Restore_Ghost_Region (Saved_GM, Saved_IGR); |
6905a049 | 9210 | |
d65a80fd | 9211 | return Func_Decl; |
6905a049 AC |
9212 | end Build_Predicate_Function_Declaration; |
9213 | ||
5a8a6763 RD |
9214 | ----------------------------------------- |
9215 | -- Check_Aspect_At_End_Of_Declarations -- | |
9216 | ----------------------------------------- | |
86200f66 | 9217 | |
5a8a6763 RD |
9218 | procedure Check_Aspect_At_End_Of_Declarations (ASN : Node_Id) is |
9219 | Ent : constant Entity_Id := Entity (ASN); | |
9220 | Ident : constant Node_Id := Identifier (ASN); | |
9221 | A_Id : constant Aspect_Id := Get_Aspect_Id (Chars (Ident)); | |
f6b5dc8e | 9222 | |
5a8a6763 RD |
9223 | End_Decl_Expr : constant Node_Id := Entity (Ident); |
9224 | -- Expression to be analyzed at end of declarations | |
f6b5dc8e | 9225 | |
5a8a6763 | 9226 | Freeze_Expr : constant Node_Id := Expression (ASN); |
ef74daea | 9227 | -- Expression from call to Check_Aspect_At_Freeze_Point. |
f6b5dc8e | 9228 | |
da9683f4 | 9229 | T : constant Entity_Id := Etype (Original_Node (Freeze_Expr)); |
ef74daea AC |
9230 | -- Type required for preanalyze call. We use the original expression to |
9231 | -- get the proper type, to prevent cascaded errors when the expression | |
9232 | -- is constant-folded. | |
f6b5dc8e | 9233 | |
5a8a6763 RD |
9234 | Err : Boolean; |
9235 | -- Set False if error | |
86200f66 | 9236 | |
5a8a6763 RD |
9237 | -- On entry to this procedure, Entity (Ident) contains a copy of the |
9238 | -- original expression from the aspect, saved for this purpose, and | |
9239 | -- but Expression (Ident) is a preanalyzed copy of the expression, | |
9240 | -- preanalyzed just after the freeze point. | |
86200f66 | 9241 | |
5a8a6763 RD |
9242 | procedure Check_Overloaded_Name; |
9243 | -- For aspects whose expression is simply a name, this routine checks if | |
9244 | -- the name is overloaded or not. If so, it verifies there is an | |
9245 | -- interpretation that matches the entity obtained at the freeze point, | |
9246 | -- otherwise the compiler complains. | |
86200f66 | 9247 | |
5a8a6763 RD |
9248 | --------------------------- |
9249 | -- Check_Overloaded_Name -- | |
9250 | --------------------------- | |
9251 | ||
9252 | procedure Check_Overloaded_Name is | |
1e194575 | 9253 | begin |
5a8a6763 | 9254 | if not Is_Overloaded (End_Decl_Expr) then |
c74afd84 AC |
9255 | Err := not Is_Entity_Name (End_Decl_Expr) |
9256 | or else Entity (End_Decl_Expr) /= Entity (Freeze_Expr); | |
5a8a6763 | 9257 | |
1e194575 | 9258 | else |
5a8a6763 | 9259 | Err := True; |
86200f66 | 9260 | |
5a8a6763 RD |
9261 | declare |
9262 | Index : Interp_Index; | |
9263 | It : Interp; | |
86200f66 | 9264 | |
5a8a6763 RD |
9265 | begin |
9266 | Get_First_Interp (End_Decl_Expr, Index, It); | |
9267 | while Present (It.Typ) loop | |
9268 | if It.Nam = Entity (Freeze_Expr) then | |
9269 | Err := False; | |
9270 | exit; | |
9271 | end if; | |
9272 | ||
9273 | Get_Next_Interp (Index, It); | |
9274 | end loop; | |
9275 | end; | |
86200f66 | 9276 | end if; |
5a8a6763 | 9277 | end Check_Overloaded_Name; |
86200f66 | 9278 | |
5a8a6763 | 9279 | -- Start of processing for Check_Aspect_At_End_Of_Declarations |
86200f66 | 9280 | |
5a8a6763 | 9281 | begin |
e96b7045 AC |
9282 | -- In an instance we do not perform the consistency check between freeze |
9283 | -- point and end of declarations, because it was done already in the | |
9284 | -- analysis of the generic. Furthermore, the delayed analysis of an | |
9285 | -- aspect of the instance may produce spurious errors when the generic | |
9286 | -- is a child unit that references entities in the parent (which might | |
9287 | -- not be in scope at the freeze point of the instance). | |
9288 | ||
9289 | if In_Instance then | |
9290 | return; | |
9291 | ||
62c7d441 AC |
9292 | -- The enclosing scope may have been rewritten during expansion (.e.g. a |
9293 | -- task body is rewritten as a procedure) after this conformance check | |
9294 | -- has been performed, so do not perform it again (it may not easily be | |
9295 | -- done if full visibility of local entities is not available). | |
522aa6ee AC |
9296 | |
9297 | elsif not Comes_From_Source (Current_Scope) then | |
9298 | return; | |
9299 | ||
5a8a6763 | 9300 | -- Case of aspects Dimension, Dimension_System and Synchronization |
86200f66 | 9301 | |
e96b7045 | 9302 | elsif A_Id = Aspect_Synchronization then |
5a8a6763 | 9303 | return; |
1e194575 | 9304 | |
5a8a6763 RD |
9305 | -- Case of stream attributes, just have to compare entities. However, |
9306 | -- the expression is just a name (possibly overloaded), and there may | |
9307 | -- be stream operations declared for unrelated types, so we just need | |
9308 | -- to verify that one of these interpretations is the one available at | |
9309 | -- at the freeze point. | |
86200f66 | 9310 | |
5a8a6763 | 9311 | elsif A_Id = Aspect_Input or else |
dc06dd83 AC |
9312 | A_Id = Aspect_Output or else |
9313 | A_Id = Aspect_Read or else | |
9314 | A_Id = Aspect_Write | |
5a8a6763 RD |
9315 | then |
9316 | Analyze (End_Decl_Expr); | |
9317 | Check_Overloaded_Name; | |
86200f66 | 9318 | |
5a8a6763 RD |
9319 | elsif A_Id = Aspect_Variable_Indexing or else |
9320 | A_Id = Aspect_Constant_Indexing or else | |
9321 | A_Id = Aspect_Default_Iterator or else | |
9322 | A_Id = Aspect_Iterator_Element | |
9323 | then | |
9324 | -- Make type unfrozen before analysis, to prevent spurious errors | |
9325 | -- about late attributes. | |
86200f66 | 9326 | |
5a8a6763 RD |
9327 | Set_Is_Frozen (Ent, False); |
9328 | Analyze (End_Decl_Expr); | |
9329 | Set_Is_Frozen (Ent, True); | |
86200f66 | 9330 | |
b5c8da6b HK |
9331 | -- If the end of declarations comes before any other freeze point, |
9332 | -- the Freeze_Expr is not analyzed: no check needed. | |
86200f66 | 9333 | |
5a8a6763 RD |
9334 | if Analyzed (Freeze_Expr) and then not In_Instance then |
9335 | Check_Overloaded_Name; | |
9336 | else | |
9337 | Err := False; | |
9338 | end if; | |
c7532b2d | 9339 | |
5a8a6763 | 9340 | -- All other cases |
c7532b2d | 9341 | |
5a8a6763 | 9342 | else |
b5c8da6b | 9343 | -- In a generic context freeze nodes are not always generated, so |
e87f67eb ES |
9344 | -- analyze the expression now. If the aspect is for a type, this |
9345 | -- makes its potential components accessible. | |
8334176a | 9346 | |
b5c8da6b | 9347 | if not Analyzed (Freeze_Expr) and then Inside_A_Generic then |
e87f67eb ES |
9348 | if A_Id = Aspect_Dynamic_Predicate |
9349 | or else A_Id = Aspect_Predicate | |
9350 | or else A_Id = Aspect_Priority | |
9351 | then | |
9352 | Push_Type (Ent); | |
9353 | Preanalyze (Freeze_Expr); | |
9354 | Pop_Type (Ent); | |
9355 | else | |
9356 | Preanalyze (Freeze_Expr); | |
9357 | end if; | |
8334176a ES |
9358 | end if; |
9359 | ||
d2d8b2a7 AC |
9360 | -- Indicate that the expression comes from an aspect specification, |
9361 | -- which is used in subsequent analysis even if expansion is off. | |
9362 | ||
9363 | Set_Parent (End_Decl_Expr, ASN); | |
9364 | ||
5a8a6763 RD |
9365 | -- In a generic context the aspect expressions have not been |
9366 | -- preanalyzed, so do it now. There are no conformance checks | |
9367 | -- to perform in this case. | |
c7532b2d | 9368 | |
5a8a6763 RD |
9369 | if No (T) then |
9370 | Check_Aspect_At_Freeze_Point (ASN); | |
9371 | return; | |
c7532b2d | 9372 | |
5a8a6763 RD |
9373 | -- The default values attributes may be defined in the private part, |
9374 | -- and the analysis of the expression may take place when only the | |
9375 | -- partial view is visible. The expression must be scalar, so use | |
9376 | -- the full view to resolve. | |
c7532b2d | 9377 | |
5a8a6763 RD |
9378 | elsif (A_Id = Aspect_Default_Value |
9379 | or else | |
9380 | A_Id = Aspect_Default_Component_Value) | |
9381 | and then Is_Private_Type (T) | |
9382 | then | |
9383 | Preanalyze_Spec_Expression (End_Decl_Expr, Full_View (T)); | |
d2d8b2a7 | 9384 | |
5f531fef ES |
9385 | -- The following aspect expressions may contain references to |
9386 | -- components and discriminants of the type. | |
9387 | ||
2401c98f | 9388 | elsif A_Id = Aspect_Dynamic_Predicate |
f5d4b6ab | 9389 | or else A_Id = Aspect_Predicate |
5f531fef ES |
9390 | or else A_Id = Aspect_Priority |
9391 | then | |
9392 | Push_Type (Ent); | |
9393 | Preanalyze_Spec_Expression (End_Decl_Expr, T); | |
9394 | Pop_Type (Ent); | |
9395 | ||
5a8a6763 RD |
9396 | else |
9397 | Preanalyze_Spec_Expression (End_Decl_Expr, T); | |
9398 | end if; | |
1e194575 | 9399 | |
2401c98f HK |
9400 | Err := |
9401 | not Fully_Conformant_Expressions | |
5f531fef | 9402 | (End_Decl_Expr, Freeze_Expr, Report => True); |
5a8a6763 | 9403 | end if; |
c7532b2d | 9404 | |
d2d8b2a7 AC |
9405 | -- Output error message if error. Force error on aspect specification |
9406 | -- even if there is an error on the expression itself. | |
c7532b2d | 9407 | |
5a8a6763 RD |
9408 | if Err then |
9409 | Error_Msg_NE | |
d2d8b2a7 | 9410 | ("!visibility of aspect for& changes after freeze point", |
5a8a6763 RD |
9411 | ASN, Ent); |
9412 | Error_Msg_NE | |
5f531fef | 9413 | ("info: & is frozen here, (RM 13.1.1 (13/3))??", |
5a8a6763 RD |
9414 | Freeze_Node (Ent), Ent); |
9415 | end if; | |
9416 | end Check_Aspect_At_End_Of_Declarations; | |
c7532b2d | 9417 | |
5a8a6763 RD |
9418 | ---------------------------------- |
9419 | -- Check_Aspect_At_Freeze_Point -- | |
9420 | ---------------------------------- | |
86200f66 | 9421 | |
5a8a6763 RD |
9422 | procedure Check_Aspect_At_Freeze_Point (ASN : Node_Id) is |
9423 | Ident : constant Node_Id := Identifier (ASN); | |
9424 | -- Identifier (use Entity field to save expression) | |
86200f66 | 9425 | |
5a8a6763 | 9426 | A_Id : constant Aspect_Id := Get_Aspect_Id (Chars (Ident)); |
86200f66 | 9427 | |
5a8a6763 RD |
9428 | T : Entity_Id := Empty; |
9429 | -- Type required for preanalyze call | |
86200f66 | 9430 | |
5a8a6763 RD |
9431 | begin |
9432 | -- On entry to this procedure, Entity (Ident) contains a copy of the | |
9433 | -- original expression from the aspect, saved for this purpose. | |
86200f66 | 9434 | |
5a8a6763 RD |
9435 | -- On exit from this procedure Entity (Ident) is unchanged, still |
9436 | -- containing that copy, but Expression (Ident) is a preanalyzed copy | |
9437 | -- of the expression, preanalyzed just after the freeze point. | |
1e194575 | 9438 | |
5a8a6763 | 9439 | -- Make a copy of the expression to be preanalyzed |
1e194575 | 9440 | |
5a8a6763 | 9441 | Set_Expression (ASN, New_Copy_Tree (Entity (Ident))); |
1e194575 | 9442 | |
5a8a6763 | 9443 | -- Find type for preanalyze call |
1e194575 | 9444 | |
5a8a6763 | 9445 | case A_Id is |
86200f66 | 9446 | |
5a8a6763 | 9447 | -- No_Aspect should be impossible |
1e194575 | 9448 | |
5a8a6763 RD |
9449 | when No_Aspect => |
9450 | raise Program_Error; | |
9451 | ||
9452 | -- Aspects taking an optional boolean argument | |
1e194575 | 9453 | |
d8f43ee6 HK |
9454 | when Boolean_Aspects |
9455 | | Library_Unit_Aspects | |
9456 | => | |
5a8a6763 | 9457 | T := Standard_Boolean; |
f6b5dc8e | 9458 | |
5a8a6763 | 9459 | -- Aspects corresponding to attribute definition clauses |
86200f66 | 9460 | |
5a8a6763 RD |
9461 | when Aspect_Address => |
9462 | T := RTE (RE_Address); | |
86200f66 | 9463 | |
5a8a6763 RD |
9464 | when Aspect_Attach_Handler => |
9465 | T := RTE (RE_Interrupt_ID); | |
f6b5dc8e | 9466 | |
d8f43ee6 HK |
9467 | when Aspect_Bit_Order |
9468 | | Aspect_Scalar_Storage_Order | |
9469 | => | |
5a8a6763 | 9470 | T := RTE (RE_Bit_Order); |
f6b5dc8e | 9471 | |
5a8a6763 RD |
9472 | when Aspect_Convention => |
9473 | return; | |
f6b5dc8e | 9474 | |
5a8a6763 RD |
9475 | when Aspect_CPU => |
9476 | T := RTE (RE_CPU_Range); | |
f6b5dc8e | 9477 | |
5a8a6763 | 9478 | -- Default_Component_Value is resolved with the component type |
f6b5dc8e | 9479 | |
5a8a6763 RD |
9480 | when Aspect_Default_Component_Value => |
9481 | T := Component_Type (Entity (ASN)); | |
f6b5dc8e | 9482 | |
2ef05128 AC |
9483 | when Aspect_Default_Storage_Pool => |
9484 | T := Class_Wide_Type (RTE (RE_Root_Storage_Pool)); | |
9485 | ||
5a8a6763 | 9486 | -- Default_Value is resolved with the type entity in question |
f6b5dc8e | 9487 | |
5a8a6763 RD |
9488 | when Aspect_Default_Value => |
9489 | T := Entity (ASN); | |
86200f66 | 9490 | |
5a8a6763 RD |
9491 | when Aspect_Dispatching_Domain => |
9492 | T := RTE (RE_Dispatching_Domain); | |
86200f66 | 9493 | |
5a8a6763 RD |
9494 | when Aspect_External_Tag => |
9495 | T := Standard_String; | |
86200f66 | 9496 | |
5a8a6763 RD |
9497 | when Aspect_External_Name => |
9498 | T := Standard_String; | |
86200f66 | 9499 | |
5a8a6763 RD |
9500 | when Aspect_Link_Name => |
9501 | T := Standard_String; | |
86200f66 | 9502 | |
d8f43ee6 HK |
9503 | when Aspect_Interrupt_Priority |
9504 | | Aspect_Priority | |
9505 | => | |
5a8a6763 | 9506 | T := Standard_Integer; |
1e194575 | 9507 | |
5a8a6763 RD |
9508 | when Aspect_Relative_Deadline => |
9509 | T := RTE (RE_Time_Span); | |
1e194575 | 9510 | |
eacfa9bc AC |
9511 | when Aspect_Secondary_Stack_Size => |
9512 | T := Standard_Integer; | |
9513 | ||
5a8a6763 | 9514 | when Aspect_Small => |
ed323421 AC |
9515 | |
9516 | -- Note that the expression can be of any real type (not just a | |
9517 | -- real universal literal) as long as it is a static constant. | |
83b77c5c AC |
9518 | |
9519 | T := Any_Real; | |
f2acf80c | 9520 | |
5a8a6763 RD |
9521 | -- For a simple storage pool, we have to retrieve the type of the |
9522 | -- pool object associated with the aspect's corresponding attribute | |
9523 | -- definition clause. | |
f2acf80c | 9524 | |
5a8a6763 RD |
9525 | when Aspect_Simple_Storage_Pool => |
9526 | T := Etype (Expression (Aspect_Rep_Item (ASN))); | |
1e194575 | 9527 | |
5a8a6763 RD |
9528 | when Aspect_Storage_Pool => |
9529 | T := Class_Wide_Type (RTE (RE_Root_Storage_Pool)); | |
1e194575 | 9530 | |
d8f43ee6 HK |
9531 | when Aspect_Alignment |
9532 | | Aspect_Component_Size | |
9533 | | Aspect_Machine_Radix | |
9534 | | Aspect_Object_Size | |
9535 | | Aspect_Size | |
9536 | | Aspect_Storage_Size | |
9537 | | Aspect_Stream_Size | |
9538 | | Aspect_Value_Size | |
9539 | => | |
5a8a6763 | 9540 | T := Any_Integer; |
86200f66 | 9541 | |
19992053 AC |
9542 | when Aspect_Linker_Section => |
9543 | T := Standard_String; | |
9544 | ||
5a8a6763 RD |
9545 | when Aspect_Synchronization => |
9546 | return; | |
47e11d08 | 9547 | |
5a8a6763 RD |
9548 | -- Special case, the expression of these aspects is just an entity |
9549 | -- that does not need any resolution, so just analyze. | |
47e11d08 | 9550 | |
d8f43ee6 HK |
9551 | when Aspect_Input |
9552 | | Aspect_Output | |
9553 | | Aspect_Read | |
9554 | | Aspect_Suppress | |
9555 | | Aspect_Unsuppress | |
9556 | | Aspect_Warnings | |
9557 | | Aspect_Write | |
9558 | => | |
5a8a6763 RD |
9559 | Analyze (Expression (ASN)); |
9560 | return; | |
47e11d08 | 9561 | |
5a8a6763 RD |
9562 | -- Same for Iterator aspects, where the expression is a function |
9563 | -- name. Legality rules are checked separately. | |
b98e2969 | 9564 | |
d8f43ee6 HK |
9565 | when Aspect_Constant_Indexing |
9566 | | Aspect_Default_Iterator | |
9567 | | Aspect_Iterator_Element | |
9568 | | Aspect_Variable_Indexing | |
9569 | => | |
5a8a6763 RD |
9570 | Analyze (Expression (ASN)); |
9571 | return; | |
47e11d08 | 9572 | |
dd2bf554 ES |
9573 | -- Ditto for Iterable, legality checks in Validate_Iterable_Aspect. |
9574 | ||
9575 | when Aspect_Iterable => | |
b4f149c2 AC |
9576 | T := Entity (ASN); |
9577 | ||
dd2bf554 | 9578 | declare |
a6ce7e76 | 9579 | Cursor : constant Entity_Id := Get_Cursor_Type (ASN, T); |
b4f149c2 AC |
9580 | Assoc : Node_Id; |
9581 | Expr : Node_Id; | |
a6ce7e76 | 9582 | |
dd2bf554 | 9583 | begin |
a6ce7e76 AC |
9584 | if Cursor = Any_Type then |
9585 | return; | |
9586 | end if; | |
9587 | ||
dd2bf554 ES |
9588 | Assoc := First (Component_Associations (Expression (ASN))); |
9589 | while Present (Assoc) loop | |
b4f149c2 AC |
9590 | Expr := Expression (Assoc); |
9591 | Analyze (Expr); | |
a6ce7e76 AC |
9592 | |
9593 | if not Error_Posted (Expr) then | |
9594 | Resolve_Iterable_Operation | |
9595 | (Expr, Cursor, T, Chars (First (Choices (Assoc)))); | |
9596 | end if; | |
9597 | ||
dd2bf554 ES |
9598 | Next (Assoc); |
9599 | end loop; | |
9600 | end; | |
b4f149c2 | 9601 | |
dd2bf554 ES |
9602 | return; |
9603 | ||
5a8a6763 | 9604 | -- Invariant/Predicate take boolean expressions |
47e11d08 | 9605 | |
d8f43ee6 HK |
9606 | when Aspect_Dynamic_Predicate |
9607 | | Aspect_Invariant | |
9608 | | Aspect_Predicate | |
9609 | | Aspect_Static_Predicate | |
9610 | | Aspect_Type_Invariant | |
9611 | => | |
5a8a6763 | 9612 | T := Standard_Boolean; |
47e11d08 | 9613 | |
a2c314c7 AC |
9614 | when Aspect_Predicate_Failure => |
9615 | T := Standard_String; | |
9616 | ||
5a8a6763 | 9617 | -- Here is the list of aspects that don't require delay analysis |
b98e2969 | 9618 | |
d8f43ee6 HK |
9619 | when Aspect_Abstract_State |
9620 | | Aspect_Annotate | |
9621 | | Aspect_Async_Readers | |
9622 | | Aspect_Async_Writers | |
9623 | | Aspect_Constant_After_Elaboration | |
9624 | | Aspect_Contract_Cases | |
9625 | | Aspect_Default_Initial_Condition | |
9626 | | Aspect_Depends | |
9627 | | Aspect_Dimension | |
9628 | | Aspect_Dimension_System | |
9629 | | Aspect_Effective_Reads | |
9630 | | Aspect_Effective_Writes | |
9631 | | Aspect_Extensions_Visible | |
9632 | | Aspect_Ghost | |
9633 | | Aspect_Global | |
9634 | | Aspect_Implicit_Dereference | |
9635 | | Aspect_Initial_Condition | |
9636 | | Aspect_Initializes | |
656d1fba | 9637 | | Aspect_Max_Entry_Queue_Depth |
d8f43ee6 HK |
9638 | | Aspect_Max_Queue_Length |
9639 | | Aspect_Obsolescent | |
9640 | | Aspect_Part_Of | |
9641 | | Aspect_Post | |
9642 | | Aspect_Postcondition | |
9643 | | Aspect_Pre | |
9644 | | Aspect_Precondition | |
9645 | | Aspect_Refined_Depends | |
9646 | | Aspect_Refined_Global | |
9647 | | Aspect_Refined_Post | |
9648 | | Aspect_Refined_State | |
9649 | | Aspect_SPARK_Mode | |
9650 | | Aspect_Test_Case | |
9651 | | Aspect_Unimplemented | |
9652 | | Aspect_Volatile_Function | |
9653 | => | |
5a8a6763 | 9654 | raise Program_Error; |
df378148 | 9655 | |
5a8a6763 | 9656 | end case; |
df378148 | 9657 | |
5a8a6763 | 9658 | -- Do the preanalyze call |
df378148 | 9659 | |
5a8a6763 RD |
9660 | Preanalyze_Spec_Expression (Expression (ASN), T); |
9661 | end Check_Aspect_At_Freeze_Point; | |
df378148 | 9662 | |
5a8a6763 RD |
9663 | ----------------------------------- |
9664 | -- Check_Constant_Address_Clause -- | |
9665 | ----------------------------------- | |
df378148 | 9666 | |
5a8a6763 RD |
9667 | procedure Check_Constant_Address_Clause |
9668 | (Expr : Node_Id; | |
9669 | U_Ent : Entity_Id) | |
9670 | is | |
9671 | procedure Check_At_Constant_Address (Nod : Node_Id); | |
9672 | -- Checks that the given node N represents a name whose 'Address is | |
9673 | -- constant (in the same sense as OK_Constant_Address_Clause, i.e. the | |
9674 | -- address value is the same at the point of declaration of U_Ent and at | |
9675 | -- the time of elaboration of the address clause. | |
b3f532ce | 9676 | |
5a8a6763 RD |
9677 | procedure Check_Expr_Constants (Nod : Node_Id); |
9678 | -- Checks that Nod meets the requirements for a constant address clause | |
9679 | -- in the sense of the enclosing procedure. | |
b3f532ce | 9680 | |
5a8a6763 RD |
9681 | procedure Check_List_Constants (Lst : List_Id); |
9682 | -- Check that all elements of list Lst meet the requirements for a | |
9683 | -- constant address clause in the sense of the enclosing procedure. | |
b3f532ce | 9684 | |
5a8a6763 RD |
9685 | ------------------------------- |
9686 | -- Check_At_Constant_Address -- | |
9687 | ------------------------------- | |
b3f532ce | 9688 | |
5a8a6763 RD |
9689 | procedure Check_At_Constant_Address (Nod : Node_Id) is |
9690 | begin | |
9691 | if Is_Entity_Name (Nod) then | |
9692 | if Present (Address_Clause (Entity ((Nod)))) then | |
9693 | Error_Msg_NE | |
9694 | ("invalid address clause for initialized object &!", | |
5a8a6763 | 9695 | Nod, U_Ent); |
d8f43ee6 HK |
9696 | Error_Msg_NE |
9697 | ("address for& cannot depend on another address clause! " | |
9698 | & "(RM 13.1(22))!", Nod, U_Ent); | |
b3f532ce | 9699 | |
5a8a6763 RD |
9700 | elsif In_Same_Source_Unit (Entity (Nod), U_Ent) |
9701 | and then Sloc (U_Ent) < Sloc (Entity (Nod)) | |
9702 | then | |
9703 | Error_Msg_NE | |
9704 | ("invalid address clause for initialized object &!", | |
9705 | Nod, U_Ent); | |
9706 | Error_Msg_Node_2 := U_Ent; | |
9707 | Error_Msg_NE | |
9708 | ("\& must be defined before & (RM 13.1(22))!", | |
9709 | Nod, Entity (Nod)); | |
9710 | end if; | |
47e11d08 | 9711 | |
5a8a6763 RD |
9712 | elsif Nkind (Nod) = N_Selected_Component then |
9713 | declare | |
9714 | T : constant Entity_Id := Etype (Prefix (Nod)); | |
57a8057a | 9715 | |
5a8a6763 RD |
9716 | begin |
9717 | if (Is_Record_Type (T) | |
9718 | and then Has_Discriminants (T)) | |
9719 | or else | |
9720 | (Is_Access_Type (T) | |
dc06dd83 AC |
9721 | and then Is_Record_Type (Designated_Type (T)) |
9722 | and then Has_Discriminants (Designated_Type (T))) | |
5a8a6763 RD |
9723 | then |
9724 | Error_Msg_NE | |
9725 | ("invalid address clause for initialized object &!", | |
9726 | Nod, U_Ent); | |
9727 | Error_Msg_N | |
d8f43ee6 HK |
9728 | ("\address cannot depend on component of discriminated " |
9729 | & "record (RM 13.1(22))!", Nod); | |
5a8a6763 RD |
9730 | else |
9731 | Check_At_Constant_Address (Prefix (Nod)); | |
9732 | end if; | |
9733 | end; | |
d941cee6 | 9734 | |
5a8a6763 RD |
9735 | elsif Nkind (Nod) = N_Indexed_Component then |
9736 | Check_At_Constant_Address (Prefix (Nod)); | |
9737 | Check_List_Constants (Expressions (Nod)); | |
d941cee6 | 9738 | |
b3f532ce | 9739 | else |
5a8a6763 | 9740 | Check_Expr_Constants (Nod); |
b3f532ce | 9741 | end if; |
5a8a6763 | 9742 | end Check_At_Constant_Address; |
d50f4827 | 9743 | |
5a8a6763 RD |
9744 | -------------------------- |
9745 | -- Check_Expr_Constants -- | |
9746 | -------------------------- | |
6d9e03cb | 9747 | |
5a8a6763 RD |
9748 | procedure Check_Expr_Constants (Nod : Node_Id) is |
9749 | Loc_U_Ent : constant Source_Ptr := Sloc (U_Ent); | |
9750 | Ent : Entity_Id := Empty; | |
6d9e03cb | 9751 | |
5a8a6763 RD |
9752 | begin |
9753 | if Nkind (Nod) in N_Has_Etype | |
9754 | and then Etype (Nod) = Any_Type | |
6d9e03cb | 9755 | then |
5a8a6763 | 9756 | return; |
e8bd500e AC |
9757 | end if; |
9758 | ||
5a8a6763 | 9759 | case Nkind (Nod) is |
d8f43ee6 HK |
9760 | when N_Empty |
9761 | | N_Error | |
9762 | => | |
5a8a6763 | 9763 | return; |
47e11d08 | 9764 | |
d8f43ee6 HK |
9765 | when N_Expanded_Name |
9766 | | N_Identifier | |
9767 | => | |
5a8a6763 | 9768 | Ent := Entity (Nod); |
47e11d08 | 9769 | |
5a8a6763 RD |
9770 | -- We need to look at the original node if it is different |
9771 | -- from the node, since we may have rewritten things and | |
9772 | -- substituted an identifier representing the rewrite. | |
47e11d08 | 9773 | |
dc67cfea | 9774 | if Is_Rewrite_Substitution (Nod) then |
5a8a6763 | 9775 | Check_Expr_Constants (Original_Node (Nod)); |
47e11d08 | 9776 | |
5a8a6763 RD |
9777 | -- If the node is an object declaration without initial |
9778 | -- value, some code has been expanded, and the expression | |
9779 | -- is not constant, even if the constituents might be | |
9780 | -- acceptable, as in A'Address + offset. | |
47e11d08 | 9781 | |
5a8a6763 RD |
9782 | if Ekind (Ent) = E_Variable |
9783 | and then | |
9784 | Nkind (Declaration_Node (Ent)) = N_Object_Declaration | |
9785 | and then | |
9786 | No (Expression (Declaration_Node (Ent))) | |
9787 | then | |
9788 | Error_Msg_NE | |
9789 | ("invalid address clause for initialized object &!", | |
9790 | Nod, U_Ent); | |
b98e2969 | 9791 | |
5a8a6763 RD |
9792 | -- If entity is constant, it may be the result of expanding |
9793 | -- a check. We must verify that its declaration appears | |
9794 | -- before the object in question, else we also reject the | |
9795 | -- address clause. | |
47e11d08 | 9796 | |
5a8a6763 RD |
9797 | elsif Ekind (Ent) = E_Constant |
9798 | and then In_Same_Source_Unit (Ent, U_Ent) | |
9799 | and then Sloc (Ent) > Loc_U_Ent | |
9800 | then | |
9801 | Error_Msg_NE | |
9802 | ("invalid address clause for initialized object &!", | |
9803 | Nod, U_Ent); | |
9804 | end if; | |
47e11d08 | 9805 | |
5a8a6763 RD |
9806 | return; |
9807 | end if; | |
47e11d08 | 9808 | |
5a8a6763 | 9809 | -- Otherwise look at the identifier and see if it is OK |
47e11d08 | 9810 | |
5a8a6763 RD |
9811 | if Ekind_In (Ent, E_Named_Integer, E_Named_Real) |
9812 | or else Is_Type (Ent) | |
9813 | then | |
9814 | return; | |
47e11d08 | 9815 | |
dc06dd83 AC |
9816 | elsif Ekind_In (Ent, E_Constant, E_In_Parameter) then |
9817 | ||
5a8a6763 RD |
9818 | -- This is the case where we must have Ent defined before |
9819 | -- U_Ent. Clearly if they are in different units this | |
9820 | -- requirement is met since the unit containing Ent is | |
9821 | -- already processed. | |
47e11d08 | 9822 | |
5a8a6763 RD |
9823 | if not In_Same_Source_Unit (Ent, U_Ent) then |
9824 | return; | |
47e11d08 | 9825 | |
5a8a6763 RD |
9826 | -- Otherwise location of Ent must be before the location |
9827 | -- of U_Ent, that's what prior defined means. | |
47e11d08 | 9828 | |
5a8a6763 RD |
9829 | elsif Sloc (Ent) < Loc_U_Ent then |
9830 | return; | |
dac3bede | 9831 | |
5a8a6763 RD |
9832 | else |
9833 | Error_Msg_NE | |
9834 | ("invalid address clause for initialized object &!", | |
9835 | Nod, U_Ent); | |
9836 | Error_Msg_Node_2 := U_Ent; | |
9837 | Error_Msg_NE | |
9838 | ("\& must be defined before & (RM 13.1(22))!", | |
9839 | Nod, Ent); | |
9840 | end if; | |
15e934bf | 9841 | |
5a8a6763 RD |
9842 | elsif Nkind (Original_Node (Nod)) = N_Function_Call then |
9843 | Check_Expr_Constants (Original_Node (Nod)); | |
dac3bede | 9844 | |
5a8a6763 RD |
9845 | else |
9846 | Error_Msg_NE | |
9847 | ("invalid address clause for initialized object &!", | |
9848 | Nod, U_Ent); | |
7a1f1775 | 9849 | |
5a8a6763 RD |
9850 | if Comes_From_Source (Ent) then |
9851 | Error_Msg_NE | |
9852 | ("\reference to variable& not allowed" | |
9853 | & " (RM 13.1(22))!", Nod, Ent); | |
9854 | else | |
9855 | Error_Msg_N | |
9856 | ("non-static expression not allowed" | |
9857 | & " (RM 13.1(22))!", Nod); | |
9858 | end if; | |
9859 | end if; | |
7a1f1775 | 9860 | |
5a8a6763 | 9861 | when N_Integer_Literal => |
2ef48385 | 9862 | |
5a8a6763 RD |
9863 | -- If this is a rewritten unchecked conversion, in a system |
9864 | -- where Address is an integer type, always use the base type | |
9865 | -- for a literal value. This is user-friendly and prevents | |
9866 | -- order-of-elaboration issues with instances of unchecked | |
9867 | -- conversion. | |
7a1f1775 | 9868 | |
5a8a6763 RD |
9869 | if Nkind (Original_Node (Nod)) = N_Function_Call then |
9870 | Set_Etype (Nod, Base_Type (Etype (Nod))); | |
9871 | end if; | |
4169b895 | 9872 | |
d8f43ee6 HK |
9873 | when N_Character_Literal |
9874 | | N_Real_Literal | |
9875 | | N_String_Literal | |
9876 | => | |
5a8a6763 | 9877 | return; |
47e11d08 | 9878 | |
5a8a6763 RD |
9879 | when N_Range => |
9880 | Check_Expr_Constants (Low_Bound (Nod)); | |
9881 | Check_Expr_Constants (High_Bound (Nod)); | |
d8b962d8 | 9882 | |
5a8a6763 RD |
9883 | when N_Explicit_Dereference => |
9884 | Check_Expr_Constants (Prefix (Nod)); | |
d8b962d8 | 9885 | |
5a8a6763 RD |
9886 | when N_Indexed_Component => |
9887 | Check_Expr_Constants (Prefix (Nod)); | |
9888 | Check_List_Constants (Expressions (Nod)); | |
47e11d08 | 9889 | |
5a8a6763 RD |
9890 | when N_Slice => |
9891 | Check_Expr_Constants (Prefix (Nod)); | |
9892 | Check_Expr_Constants (Discrete_Range (Nod)); | |
516f608f | 9893 | |
5a8a6763 RD |
9894 | when N_Selected_Component => |
9895 | Check_Expr_Constants (Prefix (Nod)); | |
fd8b4053 | 9896 | |
5a8a6763 RD |
9897 | when N_Attribute_Reference => |
9898 | if Nam_In (Attribute_Name (Nod), Name_Address, | |
9899 | Name_Access, | |
9900 | Name_Unchecked_Access, | |
9901 | Name_Unrestricted_Access) | |
9902 | then | |
9903 | Check_At_Constant_Address (Prefix (Nod)); | |
fd8b4053 | 9904 | |
403bc026 PMR |
9905 | -- Normally, System'To_Address will have been transformed into |
9906 | -- an Unchecked_Conversion, but in -gnatc mode, it will not, | |
9907 | -- and we don't want to give an error, because the whole point | |
9908 | -- of 'To_Address is that it is static. | |
9909 | ||
9910 | elsif Attribute_Name (Nod) = Name_To_Address then | |
9911 | pragma Assert (Operating_Mode = Check_Semantics); | |
9912 | null; | |
9913 | ||
5a8a6763 RD |
9914 | else |
9915 | Check_Expr_Constants (Prefix (Nod)); | |
9916 | Check_List_Constants (Expressions (Nod)); | |
9917 | end if; | |
67645bde | 9918 | |
5a8a6763 RD |
9919 | when N_Aggregate => |
9920 | Check_List_Constants (Component_Associations (Nod)); | |
9921 | Check_List_Constants (Expressions (Nod)); | |
47e11d08 | 9922 | |
5a8a6763 RD |
9923 | when N_Component_Association => |
9924 | Check_Expr_Constants (Expression (Nod)); | |
4169b895 | 9925 | |
5a8a6763 RD |
9926 | when N_Extension_Aggregate => |
9927 | Check_Expr_Constants (Ancestor_Part (Nod)); | |
9928 | Check_List_Constants (Component_Associations (Nod)); | |
9929 | Check_List_Constants (Expressions (Nod)); | |
7a1f1775 | 9930 | |
5a8a6763 RD |
9931 | when N_Null => |
9932 | return; | |
7a1f1775 | 9933 | |
d8f43ee6 HK |
9934 | when N_Binary_Op |
9935 | | N_Membership_Test | |
9936 | | N_Short_Circuit | |
9937 | => | |
5a8a6763 RD |
9938 | Check_Expr_Constants (Left_Opnd (Nod)); |
9939 | Check_Expr_Constants (Right_Opnd (Nod)); | |
4169b895 | 9940 | |
5a8a6763 RD |
9941 | when N_Unary_Op => |
9942 | Check_Expr_Constants (Right_Opnd (Nod)); | |
2ef48385 | 9943 | |
d8f43ee6 HK |
9944 | when N_Allocator |
9945 | | N_Qualified_Expression | |
9946 | | N_Type_Conversion | |
9947 | | N_Unchecked_Type_Conversion | |
9948 | => | |
5a8a6763 | 9949 | Check_Expr_Constants (Expression (Nod)); |
c116143c | 9950 | |
5a8a6763 RD |
9951 | when N_Function_Call => |
9952 | if not Is_Pure (Entity (Name (Nod))) then | |
9953 | Error_Msg_NE | |
9954 | ("invalid address clause for initialized object &!", | |
9955 | Nod, U_Ent); | |
2ef48385 | 9956 | |
5a8a6763 RD |
9957 | Error_Msg_NE |
9958 | ("\function & is not pure (RM 13.1(22))!", | |
9959 | Nod, Entity (Name (Nod))); | |
a8551b5f | 9960 | |
5a8a6763 RD |
9961 | else |
9962 | Check_List_Constants (Parameter_Associations (Nod)); | |
9963 | end if; | |
a8551b5f | 9964 | |
5a8a6763 RD |
9965 | when N_Parameter_Association => |
9966 | Check_Expr_Constants (Explicit_Actual_Parameter (Nod)); | |
47e11d08 | 9967 | |
5a8a6763 RD |
9968 | when others => |
9969 | Error_Msg_NE | |
9970 | ("invalid address clause for initialized object &!", | |
9971 | Nod, U_Ent); | |
9972 | Error_Msg_NE | |
9973 | ("\must be constant defined before& (RM 13.1(22))!", | |
9974 | Nod, U_Ent); | |
9975 | end case; | |
9976 | end Check_Expr_Constants; | |
47e11d08 | 9977 | |
5a8a6763 RD |
9978 | -------------------------- |
9979 | -- Check_List_Constants -- | |
9980 | -------------------------- | |
b98e2969 | 9981 | |
5a8a6763 RD |
9982 | procedure Check_List_Constants (Lst : List_Id) is |
9983 | Nod1 : Node_Id; | |
47e11d08 | 9984 | |
5a8a6763 RD |
9985 | begin |
9986 | if Present (Lst) then | |
9987 | Nod1 := First (Lst); | |
9988 | while Present (Nod1) loop | |
9989 | Check_Expr_Constants (Nod1); | |
9990 | Next (Nod1); | |
9991 | end loop; | |
9992 | end if; | |
9993 | end Check_List_Constants; | |
d50f4827 | 9994 | |
5a8a6763 | 9995 | -- Start of processing for Check_Constant_Address_Clause |
d50f4827 | 9996 | |
5a8a6763 RD |
9997 | begin |
9998 | -- If rep_clauses are to be ignored, no need for legality checks. In | |
3c756b76 AC |
9999 | -- particular, no need to pester user about rep clauses that violate the |
10000 | -- rule on constant addresses, given that these clauses will be removed | |
10001 | -- by Freeze before they reach the back end. Similarly in CodePeer mode, | |
10002 | -- we want to relax these checks. | |
47e11d08 | 10003 | |
d99565f8 | 10004 | if not Ignore_Rep_Clauses and not CodePeer_Mode then |
5a8a6763 RD |
10005 | Check_Expr_Constants (Expr); |
10006 | end if; | |
10007 | end Check_Constant_Address_Clause; | |
47e11d08 | 10008 | |
113a62d9 RD |
10009 | --------------------------- |
10010 | -- Check_Pool_Size_Clash -- | |
10011 | --------------------------- | |
10012 | ||
10013 | procedure Check_Pool_Size_Clash (Ent : Entity_Id; SP, SS : Node_Id) is | |
10014 | Post : Node_Id; | |
10015 | ||
10016 | begin | |
10017 | -- We need to find out which one came first. Note that in the case of | |
10018 | -- aspects mixed with pragmas there are cases where the processing order | |
10019 | -- is reversed, which is why we do the check here. | |
10020 | ||
10021 | if Sloc (SP) < Sloc (SS) then | |
10022 | Error_Msg_Sloc := Sloc (SP); | |
10023 | Post := SS; | |
10024 | Error_Msg_NE ("Storage_Pool previously given for&#", Post, Ent); | |
10025 | ||
10026 | else | |
10027 | Error_Msg_Sloc := Sloc (SS); | |
10028 | Post := SP; | |
10029 | Error_Msg_NE ("Storage_Size previously given for&#", Post, Ent); | |
10030 | end if; | |
10031 | ||
10032 | Error_Msg_N | |
10033 | ("\cannot have Storage_Size and Storage_Pool (RM 13.11(3))", Post); | |
10034 | end Check_Pool_Size_Clash; | |
10035 | ||
5a8a6763 RD |
10036 | ---------------------------------------- |
10037 | -- Check_Record_Representation_Clause -- | |
10038 | ---------------------------------------- | |
dec6faf1 | 10039 | |
5a8a6763 RD |
10040 | procedure Check_Record_Representation_Clause (N : Node_Id) is |
10041 | Loc : constant Source_Ptr := Sloc (N); | |
10042 | Ident : constant Node_Id := Identifier (N); | |
10043 | Rectype : Entity_Id; | |
10044 | Fent : Entity_Id; | |
10045 | CC : Node_Id; | |
10046 | Fbit : Uint; | |
10047 | Lbit : Uint; | |
10048 | Hbit : Uint := Uint_0; | |
10049 | Comp : Entity_Id; | |
10050 | Pcomp : Entity_Id; | |
b98e2969 | 10051 | |
5a8a6763 RD |
10052 | Max_Bit_So_Far : Uint; |
10053 | -- Records the maximum bit position so far. If all field positions | |
10054 | -- are monotonically increasing, then we can skip the circuit for | |
10055 | -- checking for overlap, since no overlap is possible. | |
dec6faf1 | 10056 | |
5a8a6763 | 10057 | Tagged_Parent : Entity_Id := Empty; |
315f0c42 AC |
10058 | -- This is set in the case of an extension for which we have either a |
10059 | -- size clause or Is_Fully_Repped_Tagged_Type True (indicating that all | |
10060 | -- components are positioned by record representation clauses) on the | |
10061 | -- parent type. In this case we check for overlap between components of | |
10062 | -- this tagged type and the parent component. Tagged_Parent will point | |
10063 | -- to this parent type. For all other cases, Tagged_Parent is Empty. | |
47e11d08 | 10064 | |
5612989e | 10065 | Parent_Last_Bit : Uint := No_Uint; -- init to avoid warning |
5a8a6763 RD |
10066 | -- Relevant only if Tagged_Parent is set, Parent_Last_Bit indicates the |
10067 | -- last bit position for any field in the parent type. We only need to | |
10068 | -- check overlap for fields starting below this point. | |
47e11d08 | 10069 | |
5a8a6763 RD |
10070 | Overlap_Check_Required : Boolean; |
10071 | -- Used to keep track of whether or not an overlap check is required | |
47e11d08 | 10072 | |
5a8a6763 RD |
10073 | Overlap_Detected : Boolean := False; |
10074 | -- Set True if an overlap is detected | |
996ae0b0 | 10075 | |
5a8a6763 RD |
10076 | Ccount : Natural := 0; |
10077 | -- Number of component clauses in record rep clause | |
996ae0b0 | 10078 | |
5a8a6763 RD |
10079 | procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id); |
10080 | -- Given two entities for record components or discriminants, checks | |
10081 | -- if they have overlapping component clauses and issues errors if so. | |
996ae0b0 | 10082 | |
5a8a6763 RD |
10083 | procedure Find_Component; |
10084 | -- Finds component entity corresponding to current component clause (in | |
10085 | -- CC), and sets Comp to the entity, and Fbit/Lbit to the zero origin | |
10086 | -- start/stop bits for the field. If there is no matching component or | |
10087 | -- if the matching component does not have a component clause, then | |
10088 | -- that's an error and Comp is set to Empty, but no error message is | |
10089 | -- issued, since the message was already given. Comp is also set to | |
10090 | -- Empty if the current "component clause" is in fact a pragma. | |
996ae0b0 | 10091 | |
5a8a6763 RD |
10092 | ----------------------------- |
10093 | -- Check_Component_Overlap -- | |
10094 | ----------------------------- | |
10095 | ||
10096 | procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id) is | |
10097 | CC1 : constant Node_Id := Component_Clause (C1_Ent); | |
10098 | CC2 : constant Node_Id := Component_Clause (C2_Ent); | |
996ae0b0 | 10099 | |
996ae0b0 | 10100 | begin |
5a8a6763 | 10101 | if Present (CC1) and then Present (CC2) then |
996ae0b0 | 10102 | |
5a8a6763 RD |
10103 | -- Exclude odd case where we have two tag components in the same |
10104 | -- record, both at location zero. This seems a bit strange, but | |
10105 | -- it seems to happen in some circumstances, perhaps on an error. | |
10106 | ||
10107 | if Nam_In (Chars (C1_Ent), Name_uTag, Name_uTag) then | |
10108 | return; | |
996ae0b0 RK |
10109 | end if; |
10110 | ||
5a8a6763 RD |
10111 | -- Here we check if the two fields overlap |
10112 | ||
996ae0b0 | 10113 | declare |
5a8a6763 RD |
10114 | S1 : constant Uint := Component_Bit_Offset (C1_Ent); |
10115 | S2 : constant Uint := Component_Bit_Offset (C2_Ent); | |
10116 | E1 : constant Uint := S1 + Esize (C1_Ent); | |
10117 | E2 : constant Uint := S2 + Esize (C2_Ent); | |
996ae0b0 RK |
10118 | |
10119 | begin | |
5a8a6763 RD |
10120 | if E2 <= S1 or else E1 <= S2 then |
10121 | null; | |
996ae0b0 | 10122 | else |
5a8a6763 RD |
10123 | Error_Msg_Node_2 := Component_Name (CC2); |
10124 | Error_Msg_Sloc := Sloc (Error_Msg_Node_2); | |
10125 | Error_Msg_Node_1 := Component_Name (CC1); | |
10126 | Error_Msg_N | |
10127 | ("component& overlaps & #", Component_Name (CC1)); | |
10128 | Overlap_Detected := True; | |
996ae0b0 RK |
10129 | end if; |
10130 | end; | |
996ae0b0 | 10131 | end if; |
5a8a6763 | 10132 | end Check_Component_Overlap; |
996ae0b0 | 10133 | |
5a8a6763 RD |
10134 | -------------------- |
10135 | -- Find_Component -- | |
10136 | -------------------- | |
fbf5a39b | 10137 | |
5a8a6763 | 10138 | procedure Find_Component is |
fbf5a39b | 10139 | |
5a8a6763 RD |
10140 | procedure Search_Component (R : Entity_Id); |
10141 | -- Search components of R for a match. If found, Comp is set | |
fbf5a39b | 10142 | |
5a8a6763 RD |
10143 | ---------------------- |
10144 | -- Search_Component -- | |
10145 | ---------------------- | |
9596236a | 10146 | |
5a8a6763 RD |
10147 | procedure Search_Component (R : Entity_Id) is |
10148 | begin | |
10149 | Comp := First_Component_Or_Discriminant (R); | |
10150 | while Present (Comp) loop | |
9596236a | 10151 | |
5a8a6763 RD |
10152 | -- Ignore error of attribute name for component name (we |
10153 | -- already gave an error message for this, so no need to | |
10154 | -- complain here) | |
9596236a | 10155 | |
5a8a6763 RD |
10156 | if Nkind (Component_Name (CC)) = N_Attribute_Reference then |
10157 | null; | |
10158 | else | |
10159 | exit when Chars (Comp) = Chars (Component_Name (CC)); | |
fbf5a39b AC |
10160 | end if; |
10161 | ||
5a8a6763 RD |
10162 | Next_Component_Or_Discriminant (Comp); |
10163 | end loop; | |
10164 | end Search_Component; | |
996ae0b0 | 10165 | |
5a8a6763 | 10166 | -- Start of processing for Find_Component |
996ae0b0 | 10167 | |
5a8a6763 RD |
10168 | begin |
10169 | -- Return with Comp set to Empty if we have a pragma | |
996ae0b0 | 10170 | |
5a8a6763 RD |
10171 | if Nkind (CC) = N_Pragma then |
10172 | Comp := Empty; | |
10173 | return; | |
10174 | end if; | |
996ae0b0 | 10175 | |
5a8a6763 | 10176 | -- Search current record for matching component |
996ae0b0 | 10177 | |
5a8a6763 | 10178 | Search_Component (Rectype); |
fbf5a39b | 10179 | |
5a8a6763 RD |
10180 | -- If not found, maybe component of base type discriminant that is |
10181 | -- absent from statically constrained first subtype. | |
9596236a | 10182 | |
5a8a6763 RD |
10183 | if No (Comp) then |
10184 | Search_Component (Base_Type (Rectype)); | |
10185 | end if; | |
9596236a | 10186 | |
5a8a6763 RD |
10187 | -- If no component, or the component does not reference the component |
10188 | -- clause in question, then there was some previous error for which | |
10189 | -- we already gave a message, so just return with Comp Empty. | |
996ae0b0 | 10190 | |
5a8a6763 RD |
10191 | if No (Comp) or else Component_Clause (Comp) /= CC then |
10192 | Check_Error_Detected; | |
10193 | Comp := Empty; | |
9f4fd324 | 10194 | |
5a8a6763 | 10195 | -- Normal case where we have a component clause |
9f4fd324 | 10196 | |
5a8a6763 RD |
10197 | else |
10198 | Fbit := Component_Bit_Offset (Comp); | |
10199 | Lbit := Fbit + Esize (Comp) - 1; | |
10200 | end if; | |
10201 | end Find_Component; | |
9f4fd324 | 10202 | |
5a8a6763 | 10203 | -- Start of processing for Check_Record_Representation_Clause |
996ae0b0 | 10204 | |
5a8a6763 RD |
10205 | begin |
10206 | Find_Type (Ident); | |
10207 | Rectype := Entity (Ident); | |
996ae0b0 | 10208 | |
5a8a6763 RD |
10209 | if Rectype = Any_Type then |
10210 | return; | |
5a8a6763 | 10211 | end if; |
996ae0b0 | 10212 | |
315f0c42 AC |
10213 | Rectype := Underlying_Type (Rectype); |
10214 | ||
5a8a6763 | 10215 | -- See if we have a fully repped derived tagged type |
996ae0b0 | 10216 | |
5a8a6763 RD |
10217 | declare |
10218 | PS : constant Entity_Id := Parent_Subtype (Rectype); | |
996ae0b0 | 10219 | |
5a8a6763 | 10220 | begin |
315f0c42 AC |
10221 | if Present (PS) and then Known_Static_RM_Size (PS) then |
10222 | Tagged_Parent := PS; | |
10223 | Parent_Last_Bit := RM_Size (PS) - 1; | |
10224 | ||
10225 | elsif Present (PS) and then Is_Fully_Repped_Tagged_Type (PS) then | |
5a8a6763 | 10226 | Tagged_Parent := PS; |
996ae0b0 | 10227 | |
5a8a6763 | 10228 | -- Find maximum bit of any component of the parent type |
996ae0b0 | 10229 | |
5a8a6763 RD |
10230 | Parent_Last_Bit := UI_From_Int (System_Address_Size - 1); |
10231 | Pcomp := First_Entity (Tagged_Parent); | |
10232 | while Present (Pcomp) loop | |
10233 | if Ekind_In (Pcomp, E_Discriminant, E_Component) then | |
10234 | if Component_Bit_Offset (Pcomp) /= No_Uint | |
10235 | and then Known_Static_Esize (Pcomp) | |
10236 | then | |
10237 | Parent_Last_Bit := | |
10238 | UI_Max | |
10239 | (Parent_Last_Bit, | |
10240 | Component_Bit_Offset (Pcomp) + Esize (Pcomp) - 1); | |
10241 | end if; | |
2a738b34 AC |
10242 | else |
10243 | ||
10244 | -- Skip anonymous types generated for constrained array | |
10245 | -- or record components. | |
5a8a6763 | 10246 | |
2a738b34 | 10247 | null; |
996ae0b0 | 10248 | end if; |
2a738b34 AC |
10249 | |
10250 | Next_Entity (Pcomp); | |
5a8a6763 RD |
10251 | end loop; |
10252 | end if; | |
10253 | end; | |
996ae0b0 | 10254 | |
5a8a6763 | 10255 | -- All done if no component clauses |
996ae0b0 | 10256 | |
5a8a6763 | 10257 | CC := First (Component_Clauses (N)); |
996ae0b0 | 10258 | |
5a8a6763 RD |
10259 | if No (CC) then |
10260 | return; | |
10261 | end if; | |
996ae0b0 | 10262 | |
5a8a6763 RD |
10263 | -- If a tag is present, then create a component clause that places it |
10264 | -- at the start of the record (otherwise gigi may place it after other | |
10265 | -- fields that have rep clauses). | |
996ae0b0 | 10266 | |
5a8a6763 | 10267 | Fent := First_Entity (Rectype); |
996ae0b0 | 10268 | |
5a8a6763 RD |
10269 | if Nkind (Fent) = N_Defining_Identifier |
10270 | and then Chars (Fent) = Name_uTag | |
10271 | then | |
10272 | Set_Component_Bit_Offset (Fent, Uint_0); | |
10273 | Set_Normalized_Position (Fent, Uint_0); | |
10274 | Set_Normalized_First_Bit (Fent, Uint_0); | |
10275 | Set_Normalized_Position_Max (Fent, Uint_0); | |
10276 | Init_Esize (Fent, System_Address_Size); | |
996ae0b0 | 10277 | |
5a8a6763 RD |
10278 | Set_Component_Clause (Fent, |
10279 | Make_Component_Clause (Loc, | |
10280 | Component_Name => Make_Identifier (Loc, Name_uTag), | |
996ae0b0 | 10281 | |
5a8a6763 RD |
10282 | Position => Make_Integer_Literal (Loc, Uint_0), |
10283 | First_Bit => Make_Integer_Literal (Loc, Uint_0), | |
10284 | Last_Bit => | |
10285 | Make_Integer_Literal (Loc, | |
10286 | UI_From_Int (System_Address_Size)))); | |
996ae0b0 | 10287 | |
5a8a6763 RD |
10288 | Ccount := Ccount + 1; |
10289 | end if; | |
996ae0b0 | 10290 | |
5a8a6763 RD |
10291 | Max_Bit_So_Far := Uint_Minus_1; |
10292 | Overlap_Check_Required := False; | |
996ae0b0 | 10293 | |
5a8a6763 | 10294 | -- Process the component clauses |
996ae0b0 | 10295 | |
5a8a6763 RD |
10296 | while Present (CC) loop |
10297 | Find_Component; | |
996ae0b0 | 10298 | |
5a8a6763 RD |
10299 | if Present (Comp) then |
10300 | Ccount := Ccount + 1; | |
996ae0b0 | 10301 | |
5a8a6763 | 10302 | -- We need a full overlap check if record positions non-monotonic |
996ae0b0 | 10303 | |
5a8a6763 RD |
10304 | if Fbit <= Max_Bit_So_Far then |
10305 | Overlap_Check_Required := True; | |
10306 | end if; | |
996ae0b0 | 10307 | |
5a8a6763 | 10308 | Max_Bit_So_Far := Lbit; |
996ae0b0 | 10309 | |
5a8a6763 | 10310 | -- Check bit position out of range of specified size |
1d57c04f | 10311 | |
5a8a6763 RD |
10312 | if Has_Size_Clause (Rectype) |
10313 | and then RM_Size (Rectype) <= Lbit | |
10314 | then | |
10315 | Error_Msg_N | |
10316 | ("bit number out of range of specified size", | |
10317 | Last_Bit (CC)); | |
996ae0b0 | 10318 | |
315f0c42 | 10319 | -- Check for overlap with tag or parent component |
8a95f4e8 | 10320 | |
5a8a6763 RD |
10321 | else |
10322 | if Is_Tagged_Type (Rectype) | |
10323 | and then Fbit < System_Address_Size | |
10324 | then | |
10325 | Error_Msg_NE | |
10326 | ("component overlaps tag field of&", | |
10327 | Component_Name (CC), Rectype); | |
10328 | Overlap_Detected := True; | |
315f0c42 AC |
10329 | |
10330 | elsif Present (Tagged_Parent) | |
10331 | and then Fbit <= Parent_Last_Bit | |
10332 | then | |
10333 | Error_Msg_NE | |
10334 | ("component overlaps parent field of&", | |
10335 | Component_Name (CC), Rectype); | |
10336 | Overlap_Detected := True; | |
5a8a6763 | 10337 | end if; |
8a95f4e8 | 10338 | |
5a8a6763 RD |
10339 | if Hbit < Lbit then |
10340 | Hbit := Lbit; | |
10341 | end if; | |
10342 | end if; | |
5a8a6763 | 10343 | end if; |
8a95f4e8 | 10344 | |
5a8a6763 RD |
10345 | Next (CC); |
10346 | end loop; | |
9a1bc6d5 | 10347 | |
5a8a6763 RD |
10348 | -- Now that we have processed all the component clauses, check for |
10349 | -- overlap. We have to leave this till last, since the components can | |
10350 | -- appear in any arbitrary order in the representation clause. | |
8a95f4e8 | 10351 | |
5a8a6763 RD |
10352 | -- We do not need this check if all specified ranges were monotonic, |
10353 | -- as recorded by Overlap_Check_Required being False at this stage. | |
8a95f4e8 | 10354 | |
5a8a6763 RD |
10355 | -- This first section checks if there are any overlapping entries at |
10356 | -- all. It does this by sorting all entries and then seeing if there are | |
10357 | -- any overlaps. If there are none, then that is decisive, but if there | |
10358 | -- are overlaps, they may still be OK (they may result from fields in | |
10359 | -- different variants). | |
8a95f4e8 | 10360 | |
5a8a6763 RD |
10361 | if Overlap_Check_Required then |
10362 | Overlap_Check1 : declare | |
8a95f4e8 | 10363 | |
5a8a6763 RD |
10364 | OC_Fbit : array (0 .. Ccount) of Uint; |
10365 | -- First-bit values for component clauses, the value is the offset | |
10366 | -- of the first bit of the field from start of record. The zero | |
10367 | -- entry is for use in sorting. | |
9a1bc6d5 | 10368 | |
5a8a6763 RD |
10369 | OC_Lbit : array (0 .. Ccount) of Uint; |
10370 | -- Last-bit values for component clauses, the value is the offset | |
10371 | -- of the last bit of the field from start of record. The zero | |
10372 | -- entry is for use in sorting. | |
10373 | ||
10374 | OC_Count : Natural := 0; | |
10375 | -- Count of entries in OC_Fbit and OC_Lbit | |
8a95f4e8 | 10376 | |
5a8a6763 RD |
10377 | function OC_Lt (Op1, Op2 : Natural) return Boolean; |
10378 | -- Compare routine for Sort | |
8a95f4e8 | 10379 | |
5a8a6763 RD |
10380 | procedure OC_Move (From : Natural; To : Natural); |
10381 | -- Move routine for Sort | |
8a95f4e8 | 10382 | |
5a8a6763 | 10383 | package Sorting is new GNAT.Heap_Sort_G (OC_Move, OC_Lt); |
8a95f4e8 | 10384 | |
5a8a6763 RD |
10385 | ----------- |
10386 | -- OC_Lt -- | |
10387 | ----------- | |
8a95f4e8 | 10388 | |
5a8a6763 | 10389 | function OC_Lt (Op1, Op2 : Natural) return Boolean is |
8a95f4e8 | 10390 | begin |
5a8a6763 RD |
10391 | return OC_Fbit (Op1) < OC_Fbit (Op2); |
10392 | end OC_Lt; | |
8a95f4e8 | 10393 | |
5a8a6763 RD |
10394 | ------------- |
10395 | -- OC_Move -- | |
10396 | ------------- | |
8a95f4e8 | 10397 | |
5a8a6763 RD |
10398 | procedure OC_Move (From : Natural; To : Natural) is |
10399 | begin | |
10400 | OC_Fbit (To) := OC_Fbit (From); | |
10401 | OC_Lbit (To) := OC_Lbit (From); | |
10402 | end OC_Move; | |
8a95f4e8 | 10403 | |
5a8a6763 | 10404 | -- Start of processing for Overlap_Check |
8a95f4e8 | 10405 | |
8a95f4e8 | 10406 | begin |
5a8a6763 RD |
10407 | CC := First (Component_Clauses (N)); |
10408 | while Present (CC) loop | |
8a95f4e8 | 10409 | |
5a8a6763 | 10410 | -- Exclude component clause already marked in error |
8a95f4e8 | 10411 | |
5a8a6763 RD |
10412 | if not Error_Posted (CC) then |
10413 | Find_Component; | |
10414 | ||
10415 | if Present (Comp) then | |
10416 | OC_Count := OC_Count + 1; | |
10417 | OC_Fbit (OC_Count) := Fbit; | |
10418 | OC_Lbit (OC_Count) := Lbit; | |
10419 | end if; | |
8a95f4e8 RD |
10420 | end if; |
10421 | ||
5a8a6763 | 10422 | Next (CC); |
8a95f4e8 | 10423 | end loop; |
8a95f4e8 | 10424 | |
5a8a6763 | 10425 | Sorting.Sort (OC_Count); |
8a95f4e8 | 10426 | |
5a8a6763 RD |
10427 | Overlap_Check_Required := False; |
10428 | for J in 1 .. OC_Count - 1 loop | |
10429 | if OC_Lbit (J) >= OC_Fbit (J + 1) then | |
10430 | Overlap_Check_Required := True; | |
10431 | exit; | |
10432 | end if; | |
10433 | end loop; | |
10434 | end Overlap_Check1; | |
10435 | end if; | |
8a95f4e8 | 10436 | |
5a8a6763 RD |
10437 | -- If Overlap_Check_Required is still True, then we have to do the full |
10438 | -- scale overlap check, since we have at least two fields that do | |
10439 | -- overlap, and we need to know if that is OK since they are in | |
10440 | -- different variant, or whether we have a definite problem. | |
8a95f4e8 | 10441 | |
5a8a6763 RD |
10442 | if Overlap_Check_Required then |
10443 | Overlap_Check2 : declare | |
10444 | C1_Ent, C2_Ent : Entity_Id; | |
10445 | -- Entities of components being checked for overlap | |
8a95f4e8 | 10446 | |
5a8a6763 RD |
10447 | Clist : Node_Id; |
10448 | -- Component_List node whose Component_Items are being checked | |
8a95f4e8 | 10449 | |
5a8a6763 RD |
10450 | Citem : Node_Id; |
10451 | -- Component declaration for component being checked | |
8a95f4e8 | 10452 | |
5a8a6763 RD |
10453 | begin |
10454 | C1_Ent := First_Entity (Base_Type (Rectype)); | |
8a95f4e8 | 10455 | |
5a8a6763 RD |
10456 | -- Loop through all components in record. For each component check |
10457 | -- for overlap with any of the preceding elements on the component | |
10458 | -- list containing the component and also, if the component is in | |
10459 | -- a variant, check against components outside the case structure. | |
10460 | -- This latter test is repeated recursively up the variant tree. | |
8a95f4e8 | 10461 | |
5a8a6763 RD |
10462 | Main_Component_Loop : while Present (C1_Ent) loop |
10463 | if not Ekind_In (C1_Ent, E_Component, E_Discriminant) then | |
10464 | goto Continue_Main_Component_Loop; | |
10465 | end if; | |
8a95f4e8 | 10466 | |
5a8a6763 RD |
10467 | -- Skip overlap check if entity has no declaration node. This |
10468 | -- happens with discriminants in constrained derived types. | |
10469 | -- Possibly we are missing some checks as a result, but that | |
10470 | -- does not seem terribly serious. | |
8a95f4e8 | 10471 | |
5a8a6763 RD |
10472 | if No (Declaration_Node (C1_Ent)) then |
10473 | goto Continue_Main_Component_Loop; | |
10474 | end if; | |
8a95f4e8 | 10475 | |
5a8a6763 | 10476 | Clist := Parent (List_Containing (Declaration_Node (C1_Ent))); |
8a95f4e8 | 10477 | |
5a8a6763 RD |
10478 | -- Loop through component lists that need checking. Check the |
10479 | -- current component list and all lists in variants above us. | |
8a95f4e8 | 10480 | |
5a8a6763 | 10481 | Component_List_Loop : loop |
8a95f4e8 | 10482 | |
5a8a6763 RD |
10483 | -- If derived type definition, go to full declaration |
10484 | -- If at outer level, check discriminants if there are any. | |
8a95f4e8 | 10485 | |
5a8a6763 RD |
10486 | if Nkind (Clist) = N_Derived_Type_Definition then |
10487 | Clist := Parent (Clist); | |
10488 | end if; | |
8a95f4e8 | 10489 | |
5a8a6763 | 10490 | -- Outer level of record definition, check discriminants |
8a95f4e8 | 10491 | |
5a8a6763 RD |
10492 | if Nkind_In (Clist, N_Full_Type_Declaration, |
10493 | N_Private_Type_Declaration) | |
8a95f4e8 | 10494 | then |
5a8a6763 RD |
10495 | if Has_Discriminants (Defining_Identifier (Clist)) then |
10496 | C2_Ent := | |
10497 | First_Discriminant (Defining_Identifier (Clist)); | |
10498 | while Present (C2_Ent) loop | |
10499 | exit when C1_Ent = C2_Ent; | |
10500 | Check_Component_Overlap (C1_Ent, C2_Ent); | |
10501 | Next_Discriminant (C2_Ent); | |
10502 | end loop; | |
10503 | end if; | |
8a95f4e8 | 10504 | |
5a8a6763 | 10505 | -- Record extension case |
8a95f4e8 | 10506 | |
5a8a6763 RD |
10507 | elsif Nkind (Clist) = N_Derived_Type_Definition then |
10508 | Clist := Empty; | |
8a95f4e8 | 10509 | |
5a8a6763 | 10510 | -- Otherwise check one component list |
8a95f4e8 | 10511 | |
5a8a6763 RD |
10512 | else |
10513 | Citem := First (Component_Items (Clist)); | |
10514 | while Present (Citem) loop | |
10515 | if Nkind (Citem) = N_Component_Declaration then | |
10516 | C2_Ent := Defining_Identifier (Citem); | |
10517 | exit when C1_Ent = C2_Ent; | |
10518 | Check_Component_Overlap (C1_Ent, C2_Ent); | |
10519 | end if; | |
8a95f4e8 | 10520 | |
5a8a6763 RD |
10521 | Next (Citem); |
10522 | end loop; | |
10523 | end if; | |
8a95f4e8 | 10524 | |
5a8a6763 RD |
10525 | -- Check for variants above us (the parent of the Clist can |
10526 | -- be a variant, in which case its parent is a variant part, | |
10527 | -- and the parent of the variant part is a component list | |
10528 | -- whose components must all be checked against the current | |
10529 | -- component for overlap). | |
8a95f4e8 | 10530 | |
5a8a6763 RD |
10531 | if Nkind (Parent (Clist)) = N_Variant then |
10532 | Clist := Parent (Parent (Parent (Clist))); | |
8a95f4e8 | 10533 | |
5a8a6763 RD |
10534 | -- Check for possible discriminant part in record, this |
10535 | -- is treated essentially as another level in the | |
10536 | -- recursion. For this case the parent of the component | |
10537 | -- list is the record definition, and its parent is the | |
10538 | -- full type declaration containing the discriminant | |
10539 | -- specifications. | |
10540 | ||
10541 | elsif Nkind (Parent (Clist)) = N_Record_Definition then | |
10542 | Clist := Parent (Parent ((Clist))); | |
10543 | ||
10544 | -- If neither of these two cases, we are at the top of | |
10545 | -- the tree. | |
10546 | ||
10547 | else | |
10548 | exit Component_List_Loop; | |
10549 | end if; | |
10550 | end loop Component_List_Loop; | |
8a95f4e8 | 10551 | |
5a8a6763 RD |
10552 | <<Continue_Main_Component_Loop>> |
10553 | Next_Entity (C1_Ent); | |
8a95f4e8 | 10554 | |
5a8a6763 RD |
10555 | end loop Main_Component_Loop; |
10556 | end Overlap_Check2; | |
8a95f4e8 RD |
10557 | end if; |
10558 | ||
5a8a6763 RD |
10559 | -- The following circuit deals with warning on record holes (gaps). We |
10560 | -- skip this check if overlap was detected, since it makes sense for the | |
10561 | -- programmer to fix this illegality before worrying about warnings. | |
8a95f4e8 | 10562 | |
5a8a6763 RD |
10563 | if not Overlap_Detected and Warn_On_Record_Holes then |
10564 | Record_Hole_Check : declare | |
10565 | Decl : constant Node_Id := Declaration_Node (Base_Type (Rectype)); | |
10566 | -- Full declaration of record type | |
8a95f4e8 | 10567 | |
5a8a6763 RD |
10568 | procedure Check_Component_List |
10569 | (CL : Node_Id; | |
10570 | Sbit : Uint; | |
10571 | DS : List_Id); | |
10572 | -- Check component list CL for holes. The starting bit should be | |
10573 | -- Sbit. which is zero for the main record component list and set | |
10574 | -- appropriately for recursive calls for variants. DS is set to | |
10575 | -- a list of discriminant specifications to be included in the | |
10576 | -- consideration of components. It is No_List if none to consider. | |
8a95f4e8 | 10577 | |
5a8a6763 RD |
10578 | -------------------------- |
10579 | -- Check_Component_List -- | |
10580 | -------------------------- | |
9a1bc6d5 | 10581 | |
5a8a6763 RD |
10582 | procedure Check_Component_List |
10583 | (CL : Node_Id; | |
10584 | Sbit : Uint; | |
10585 | DS : List_Id) | |
10586 | is | |
10587 | Compl : Integer; | |
8a95f4e8 | 10588 | |
5a8a6763 RD |
10589 | begin |
10590 | Compl := Integer (List_Length (Component_Items (CL))); | |
9a1bc6d5 | 10591 | |
5a8a6763 RD |
10592 | if DS /= No_List then |
10593 | Compl := Compl + Integer (List_Length (DS)); | |
10594 | end if; | |
8a95f4e8 | 10595 | |
5a8a6763 RD |
10596 | declare |
10597 | Comps : array (Natural range 0 .. Compl) of Entity_Id; | |
10598 | -- Gather components (zero entry is for sort routine) | |
8a95f4e8 | 10599 | |
5a8a6763 RD |
10600 | Ncomps : Natural := 0; |
10601 | -- Number of entries stored in Comps (starting at Comps (1)) | |
8a95f4e8 | 10602 | |
5a8a6763 RD |
10603 | Citem : Node_Id; |
10604 | -- One component item or discriminant specification | |
8a95f4e8 | 10605 | |
5a8a6763 RD |
10606 | Nbit : Uint; |
10607 | -- Starting bit for next component | |
8a95f4e8 | 10608 | |
5a8a6763 RD |
10609 | CEnt : Entity_Id; |
10610 | -- Component entity | |
8a95f4e8 | 10611 | |
5a8a6763 RD |
10612 | Variant : Node_Id; |
10613 | -- One variant | |
8a95f4e8 | 10614 | |
5a8a6763 RD |
10615 | function Lt (Op1, Op2 : Natural) return Boolean; |
10616 | -- Compare routine for Sort | |
8a95f4e8 | 10617 | |
5a8a6763 RD |
10618 | procedure Move (From : Natural; To : Natural); |
10619 | -- Move routine for Sort | |
8a95f4e8 | 10620 | |
5a8a6763 | 10621 | package Sorting is new GNAT.Heap_Sort_G (Move, Lt); |
8a95f4e8 | 10622 | |
5a8a6763 RD |
10623 | -------- |
10624 | -- Lt -- | |
10625 | -------- | |
8a95f4e8 | 10626 | |
5a8a6763 RD |
10627 | function Lt (Op1, Op2 : Natural) return Boolean is |
10628 | begin | |
10629 | return Component_Bit_Offset (Comps (Op1)) | |
10630 | < | |
10631 | Component_Bit_Offset (Comps (Op2)); | |
10632 | end Lt; | |
8a95f4e8 | 10633 | |
5a8a6763 RD |
10634 | ---------- |
10635 | -- Move -- | |
10636 | ---------- | |
8a95f4e8 | 10637 | |
5a8a6763 RD |
10638 | procedure Move (From : Natural; To : Natural) is |
10639 | begin | |
10640 | Comps (To) := Comps (From); | |
10641 | end Move; | |
8a95f4e8 | 10642 | |
5a8a6763 RD |
10643 | begin |
10644 | -- Gather discriminants into Comp | |
8a95f4e8 | 10645 | |
5a8a6763 RD |
10646 | if DS /= No_List then |
10647 | Citem := First (DS); | |
10648 | while Present (Citem) loop | |
10649 | if Nkind (Citem) = N_Discriminant_Specification then | |
10650 | declare | |
10651 | Ent : constant Entity_Id := | |
10652 | Defining_Identifier (Citem); | |
10653 | begin | |
10654 | if Ekind (Ent) = E_Discriminant then | |
10655 | Ncomps := Ncomps + 1; | |
10656 | Comps (Ncomps) := Ent; | |
10657 | end if; | |
10658 | end; | |
10659 | end if; | |
8a95f4e8 | 10660 | |
5a8a6763 RD |
10661 | Next (Citem); |
10662 | end loop; | |
10663 | end if; | |
8a95f4e8 | 10664 | |
5a8a6763 | 10665 | -- Gather component entities into Comp |
8a95f4e8 | 10666 | |
5a8a6763 RD |
10667 | Citem := First (Component_Items (CL)); |
10668 | while Present (Citem) loop | |
10669 | if Nkind (Citem) = N_Component_Declaration then | |
10670 | Ncomps := Ncomps + 1; | |
10671 | Comps (Ncomps) := Defining_Identifier (Citem); | |
10672 | end if; | |
8a95f4e8 | 10673 | |
5a8a6763 RD |
10674 | Next (Citem); |
10675 | end loop; | |
8a95f4e8 | 10676 | |
5a8a6763 RD |
10677 | -- Now sort the component entities based on the first bit. |
10678 | -- Note we already know there are no overlapping components. | |
8a95f4e8 | 10679 | |
5a8a6763 | 10680 | Sorting.Sort (Ncomps); |
8a95f4e8 | 10681 | |
5a8a6763 | 10682 | -- Loop through entries checking for holes |
8a95f4e8 | 10683 | |
5a8a6763 RD |
10684 | Nbit := Sbit; |
10685 | for J in 1 .. Ncomps loop | |
10686 | CEnt := Comps (J); | |
8a95f4e8 | 10687 | |
354ae449 AC |
10688 | declare |
10689 | CBO : constant Uint := Component_Bit_Offset (CEnt); | |
10690 | ||
10691 | begin | |
10692 | -- Skip components with unknown offsets | |
10693 | ||
10694 | if CBO /= No_Uint and then CBO >= 0 then | |
10695 | Error_Msg_Uint_1 := CBO - Nbit; | |
8a95f4e8 | 10696 | |
354ae449 AC |
10697 | if Error_Msg_Uint_1 > 0 then |
10698 | Error_Msg_NE | |
10699 | ("?H?^-bit gap before component&", | |
10700 | Component_Name (Component_Clause (CEnt)), | |
10701 | CEnt); | |
10702 | end if; | |
10703 | ||
10704 | Nbit := CBO + Esize (CEnt); | |
10705 | end if; | |
10706 | end; | |
5a8a6763 | 10707 | end loop; |
8a95f4e8 | 10708 | |
5a8a6763 | 10709 | -- Process variant parts recursively if present |
8a95f4e8 | 10710 | |
5a8a6763 RD |
10711 | if Present (Variant_Part (CL)) then |
10712 | Variant := First (Variants (Variant_Part (CL))); | |
10713 | while Present (Variant) loop | |
10714 | Check_Component_List | |
10715 | (Component_List (Variant), Nbit, No_List); | |
10716 | Next (Variant); | |
10717 | end loop; | |
8a95f4e8 | 10718 | end if; |
5a8a6763 RD |
10719 | end; |
10720 | end Check_Component_List; | |
8a95f4e8 | 10721 | |
5a8a6763 | 10722 | -- Start of processing for Record_Hole_Check |
8a95f4e8 | 10723 | |
5a8a6763 RD |
10724 | begin |
10725 | declare | |
10726 | Sbit : Uint; | |
8a95f4e8 | 10727 | |
5a8a6763 RD |
10728 | begin |
10729 | if Is_Tagged_Type (Rectype) then | |
10730 | Sbit := UI_From_Int (System_Address_Size); | |
10731 | else | |
10732 | Sbit := Uint_0; | |
10733 | end if; | |
10734 | ||
10735 | if Nkind (Decl) = N_Full_Type_Declaration | |
10736 | and then Nkind (Type_Definition (Decl)) = N_Record_Definition | |
10737 | then | |
10738 | Check_Component_List | |
10739 | (Component_List (Type_Definition (Decl)), | |
10740 | Sbit, | |
10741 | Discriminant_Specifications (Decl)); | |
8a95f4e8 | 10742 | end if; |
5a8a6763 RD |
10743 | end; |
10744 | end Record_Hole_Check; | |
8a95f4e8 RD |
10745 | end if; |
10746 | ||
5a8a6763 RD |
10747 | -- For records that have component clauses for all components, and whose |
10748 | -- size is less than or equal to 32, we need to know the size in the | |
10749 | -- front end to activate possible packed array processing where the | |
10750 | -- component type is a record. | |
8a95f4e8 | 10751 | |
5a8a6763 RD |
10752 | -- At this stage Hbit + 1 represents the first unused bit from all the |
10753 | -- component clauses processed, so if the component clauses are | |
10754 | -- complete, then this is the length of the record. | |
8a95f4e8 | 10755 | |
5a8a6763 RD |
10756 | -- For records longer than System.Storage_Unit, and for those where not |
10757 | -- all components have component clauses, the back end determines the | |
10758 | -- length (it may for example be appropriate to round up the size | |
10759 | -- to some convenient boundary, based on alignment considerations, etc). | |
8a95f4e8 | 10760 | |
5a8a6763 | 10761 | if Unknown_RM_Size (Rectype) and then Hbit + 1 <= 32 then |
8a95f4e8 | 10762 | |
5a8a6763 | 10763 | -- Nothing to do if at least one component has no component clause |
8a95f4e8 | 10764 | |
5a8a6763 RD |
10765 | Comp := First_Component_Or_Discriminant (Rectype); |
10766 | while Present (Comp) loop | |
10767 | exit when No (Component_Clause (Comp)); | |
10768 | Next_Component_Or_Discriminant (Comp); | |
10769 | end loop; | |
8a95f4e8 | 10770 | |
5a8a6763 RD |
10771 | -- If we fall out of loop, all components have component clauses |
10772 | -- and so we can set the size to the maximum value. | |
8a95f4e8 | 10773 | |
5a8a6763 RD |
10774 | if No (Comp) then |
10775 | Set_RM_Size (Rectype, Hbit + 1); | |
10776 | end if; | |
10777 | end if; | |
10778 | end Check_Record_Representation_Clause; | |
8a95f4e8 | 10779 | |
5a8a6763 RD |
10780 | ---------------- |
10781 | -- Check_Size -- | |
10782 | ---------------- | |
8a95f4e8 | 10783 | |
5a8a6763 RD |
10784 | procedure Check_Size |
10785 | (N : Node_Id; | |
10786 | T : Entity_Id; | |
10787 | Siz : Uint; | |
10788 | Biased : out Boolean) | |
10789 | is | |
32b794c8 AC |
10790 | procedure Size_Too_Small_Error (Min_Siz : Uint); |
10791 | -- Emit an error concerning illegal size Siz. Min_Siz denotes the | |
10792 | -- minimum size. | |
10793 | ||
10794 | -------------------------- | |
10795 | -- Size_Too_Small_Error -- | |
10796 | -------------------------- | |
10797 | ||
10798 | procedure Size_Too_Small_Error (Min_Siz : Uint) is | |
10799 | begin | |
10800 | -- This error is suppressed in ASIS mode to allow for different ASIS | |
2cc2e964 | 10801 | -- back ends or ASIS-based tools to query the illegal clause. |
32b794c8 AC |
10802 | |
10803 | if not ASIS_Mode then | |
10804 | Error_Msg_Uint_1 := Min_Siz; | |
331e5015 | 10805 | Error_Msg_NE ("size for& too small, minimum allowed is ^", N, T); |
32b794c8 AC |
10806 | end if; |
10807 | end Size_Too_Small_Error; | |
10808 | ||
10809 | -- Local variables | |
10810 | ||
5a8a6763 RD |
10811 | UT : constant Entity_Id := Underlying_Type (T); |
10812 | M : Uint; | |
8a95f4e8 | 10813 | |
32b794c8 AC |
10814 | -- Start of processing for Check_Size |
10815 | ||
5a8a6763 RD |
10816 | begin |
10817 | Biased := False; | |
8a95f4e8 | 10818 | |
32b794c8 | 10819 | -- Reject patently improper size values |
8a95f4e8 | 10820 | |
5a8a6763 RD |
10821 | if Is_Elementary_Type (T) |
10822 | and then Siz > UI_From_Int (Int'Last) | |
10823 | then | |
10824 | Error_Msg_N ("Size value too large for elementary type", N); | |
8a95f4e8 | 10825 | |
5a8a6763 RD |
10826 | if Nkind (Original_Node (N)) = N_Op_Expon then |
10827 | Error_Msg_N | |
10828 | ("\maybe '* was meant, rather than '*'*", Original_Node (N)); | |
10829 | end if; | |
10830 | end if; | |
8a95f4e8 | 10831 | |
5a8a6763 | 10832 | -- Dismiss generic types |
8a95f4e8 | 10833 | |
5a8a6763 RD |
10834 | if Is_Generic_Type (T) |
10835 | or else | |
10836 | Is_Generic_Type (UT) | |
10837 | or else | |
10838 | Is_Generic_Type (Root_Type (UT)) | |
10839 | then | |
10840 | return; | |
8a95f4e8 | 10841 | |
5a8a6763 | 10842 | -- Guard against previous errors |
8a95f4e8 | 10843 | |
5a8a6763 RD |
10844 | elsif No (UT) or else UT = Any_Type then |
10845 | Check_Error_Detected; | |
10846 | return; | |
8a95f4e8 | 10847 | |
5a8a6763 | 10848 | -- Check case of bit packed array |
8a95f4e8 | 10849 | |
5a8a6763 RD |
10850 | elsif Is_Array_Type (UT) |
10851 | and then Known_Static_Component_Size (UT) | |
10852 | and then Is_Bit_Packed_Array (UT) | |
10853 | then | |
10854 | declare | |
10855 | Asiz : Uint; | |
10856 | Indx : Node_Id; | |
10857 | Ityp : Entity_Id; | |
8a95f4e8 | 10858 | |
5a8a6763 RD |
10859 | begin |
10860 | Asiz := Component_Size (UT); | |
10861 | Indx := First_Index (UT); | |
10862 | loop | |
10863 | Ityp := Etype (Indx); | |
8a95f4e8 | 10864 | |
5a8a6763 RD |
10865 | -- If non-static bound, then we are not in the business of |
10866 | -- trying to check the length, and indeed an error will be | |
10867 | -- issued elsewhere, since sizes of non-static array types | |
10868 | -- cannot be set implicitly or explicitly. | |
8a95f4e8 | 10869 | |
edab6088 | 10870 | if not Is_OK_Static_Subtype (Ityp) then |
5a8a6763 RD |
10871 | return; |
10872 | end if; | |
8a95f4e8 | 10873 | |
5a8a6763 | 10874 | -- Otherwise accumulate next dimension |
8a95f4e8 | 10875 | |
5a8a6763 RD |
10876 | Asiz := Asiz * (Expr_Value (Type_High_Bound (Ityp)) - |
10877 | Expr_Value (Type_Low_Bound (Ityp)) + | |
10878 | Uint_1); | |
8a95f4e8 | 10879 | |
5a8a6763 RD |
10880 | Next_Index (Indx); |
10881 | exit when No (Indx); | |
10882 | end loop; | |
8a95f4e8 | 10883 | |
5a8a6763 RD |
10884 | if Asiz <= Siz then |
10885 | return; | |
8a95f4e8 | 10886 | |
5a8a6763 | 10887 | else |
32b794c8 | 10888 | Size_Too_Small_Error (Asiz); |
5a8a6763 RD |
10889 | Set_Esize (T, Asiz); |
10890 | Set_RM_Size (T, Asiz); | |
10891 | end if; | |
10892 | end; | |
8a95f4e8 | 10893 | |
5a8a6763 | 10894 | -- All other composite types are ignored |
8a95f4e8 | 10895 | |
5a8a6763 RD |
10896 | elsif Is_Composite_Type (UT) then |
10897 | return; | |
9a1bc6d5 | 10898 | |
5a8a6763 RD |
10899 | -- For fixed-point types, don't check minimum if type is not frozen, |
10900 | -- since we don't know all the characteristics of the type that can | |
10901 | -- affect the size (e.g. a specified small) till freeze time. | |
9a1bc6d5 | 10902 | |
32b794c8 | 10903 | elsif Is_Fixed_Point_Type (UT) and then not Is_Frozen (UT) then |
5a8a6763 | 10904 | null; |
9a1bc6d5 | 10905 | |
5a8a6763 | 10906 | -- Cases for which a minimum check is required |
9a1bc6d5 | 10907 | |
5a8a6763 RD |
10908 | else |
10909 | -- Ignore if specified size is correct for the type | |
9a1bc6d5 | 10910 | |
5a8a6763 RD |
10911 | if Known_Esize (UT) and then Siz = Esize (UT) then |
10912 | return; | |
10913 | end if; | |
9a1bc6d5 | 10914 | |
5a8a6763 | 10915 | -- Otherwise get minimum size |
9a1bc6d5 | 10916 | |
5a8a6763 | 10917 | M := UI_From_Int (Minimum_Size (UT)); |
9a1bc6d5 | 10918 | |
5a8a6763 | 10919 | if Siz < M then |
9a1bc6d5 | 10920 | |
5a8a6763 RD |
10921 | -- Size is less than minimum size, but one possibility remains |
10922 | -- that we can manage with the new size if we bias the type. | |
9a1bc6d5 | 10923 | |
5a8a6763 | 10924 | M := UI_From_Int (Minimum_Size (UT, Biased => True)); |
9a1bc6d5 | 10925 | |
5a8a6763 | 10926 | if Siz < M then |
32b794c8 AC |
10927 | Size_Too_Small_Error (M); |
10928 | Set_Esize (T, M); | |
5a8a6763 RD |
10929 | Set_RM_Size (T, M); |
10930 | else | |
10931 | Biased := True; | |
10932 | end if; | |
10933 | end if; | |
10934 | end if; | |
10935 | end Check_Size; | |
9a1bc6d5 | 10936 | |
5a8a6763 RD |
10937 | -------------------------- |
10938 | -- Freeze_Entity_Checks -- | |
10939 | -------------------------- | |
9a1bc6d5 | 10940 | |
5a8a6763 | 10941 | procedure Freeze_Entity_Checks (N : Node_Id) is |
09c954dc AC |
10942 | procedure Hide_Non_Overridden_Subprograms (Typ : Entity_Id); |
10943 | -- Inspect the primitive operations of type Typ and hide all pairs of | |
79859568 AC |
10944 | -- implicitly declared non-overridden non-fully conformant homographs |
10945 | -- (Ada RM 8.3 12.3/2). | |
09c954dc AC |
10946 | |
10947 | ------------------------------------- | |
10948 | -- Hide_Non_Overridden_Subprograms -- | |
10949 | ------------------------------------- | |
10950 | ||
10951 | procedure Hide_Non_Overridden_Subprograms (Typ : Entity_Id) is | |
10952 | procedure Hide_Matching_Homographs | |
10953 | (Subp_Id : Entity_Id; | |
10954 | Start_Elmt : Elmt_Id); | |
10955 | -- Inspect a list of primitive operations starting with Start_Elmt | |
79859568 AC |
10956 | -- and find matching implicitly declared non-overridden non-fully |
10957 | -- conformant homographs of Subp_Id. If found, all matches along | |
10958 | -- with Subp_Id are hidden from all visibility. | |
09c954dc AC |
10959 | |
10960 | function Is_Non_Overridden_Or_Null_Procedure | |
10961 | (Subp_Id : Entity_Id) return Boolean; | |
10962 | -- Determine whether subprogram Subp_Id is implicitly declared non- | |
10963 | -- overridden subprogram or an implicitly declared null procedure. | |
10964 | ||
10965 | ------------------------------ | |
10966 | -- Hide_Matching_Homographs -- | |
10967 | ------------------------------ | |
10968 | ||
10969 | procedure Hide_Matching_Homographs | |
10970 | (Subp_Id : Entity_Id; | |
10971 | Start_Elmt : Elmt_Id) | |
10972 | is | |
10973 | Prim : Entity_Id; | |
10974 | Prim_Elmt : Elmt_Id; | |
10975 | ||
10976 | begin | |
10977 | Prim_Elmt := Start_Elmt; | |
10978 | while Present (Prim_Elmt) loop | |
10979 | Prim := Node (Prim_Elmt); | |
10980 | ||
10981 | -- The current primitive is implicitly declared non-overridden | |
79859568 AC |
10982 | -- non-fully conformant homograph of Subp_Id. Both subprograms |
10983 | -- must be hidden from visibility. | |
09c954dc AC |
10984 | |
10985 | if Chars (Prim) = Chars (Subp_Id) | |
09c954dc | 10986 | and then Is_Non_Overridden_Or_Null_Procedure (Prim) |
79859568 | 10987 | and then not Fully_Conformant (Prim, Subp_Id) |
09c954dc | 10988 | then |
7b4ebba5 AC |
10989 | Set_Is_Hidden_Non_Overridden_Subpgm (Prim); |
10990 | Set_Is_Immediately_Visible (Prim, False); | |
10991 | Set_Is_Potentially_Use_Visible (Prim, False); | |
09c954dc | 10992 | |
7b4ebba5 AC |
10993 | Set_Is_Hidden_Non_Overridden_Subpgm (Subp_Id); |
10994 | Set_Is_Immediately_Visible (Subp_Id, False); | |
10995 | Set_Is_Potentially_Use_Visible (Subp_Id, False); | |
09c954dc AC |
10996 | end if; |
10997 | ||
10998 | Next_Elmt (Prim_Elmt); | |
10999 | end loop; | |
11000 | end Hide_Matching_Homographs; | |
11001 | ||
11002 | ----------------------------------------- | |
11003 | -- Is_Non_Overridden_Or_Null_Procedure -- | |
11004 | ----------------------------------------- | |
11005 | ||
11006 | function Is_Non_Overridden_Or_Null_Procedure | |
11007 | (Subp_Id : Entity_Id) return Boolean | |
11008 | is | |
11009 | Alias_Id : Entity_Id; | |
11010 | ||
11011 | begin | |
11012 | -- The subprogram is inherited (implicitly declared), it does not | |
11013 | -- override and does not cover a primitive of an interface. | |
11014 | ||
11015 | if Ekind_In (Subp_Id, E_Function, E_Procedure) | |
11016 | and then Present (Alias (Subp_Id)) | |
11017 | and then No (Interface_Alias (Subp_Id)) | |
11018 | and then No (Overridden_Operation (Subp_Id)) | |
11019 | then | |
11020 | Alias_Id := Alias (Subp_Id); | |
11021 | ||
11022 | if Requires_Overriding (Alias_Id) then | |
11023 | return True; | |
11024 | ||
11025 | elsif Nkind (Parent (Alias_Id)) = N_Procedure_Specification | |
11026 | and then Null_Present (Parent (Alias_Id)) | |
11027 | then | |
11028 | return True; | |
11029 | end if; | |
11030 | end if; | |
11031 | ||
11032 | return False; | |
11033 | end Is_Non_Overridden_Or_Null_Procedure; | |
11034 | ||
11035 | -- Local variables | |
11036 | ||
11037 | Prim_Ops : constant Elist_Id := Direct_Primitive_Operations (Typ); | |
11038 | Prim : Entity_Id; | |
11039 | Prim_Elmt : Elmt_Id; | |
11040 | ||
11041 | -- Start of processing for Hide_Non_Overridden_Subprograms | |
11042 | ||
11043 | begin | |
79859568 AC |
11044 | -- Inspect the list of primitives looking for non-overridden |
11045 | -- subprograms. | |
09c954dc AC |
11046 | |
11047 | if Present (Prim_Ops) then | |
11048 | Prim_Elmt := First_Elmt (Prim_Ops); | |
11049 | while Present (Prim_Elmt) loop | |
11050 | Prim := Node (Prim_Elmt); | |
11051 | Next_Elmt (Prim_Elmt); | |
11052 | ||
11053 | if Is_Non_Overridden_Or_Null_Procedure (Prim) then | |
11054 | Hide_Matching_Homographs | |
11055 | (Subp_Id => Prim, | |
11056 | Start_Elmt => Prim_Elmt); | |
11057 | end if; | |
11058 | end loop; | |
11059 | end if; | |
11060 | end Hide_Non_Overridden_Subprograms; | |
11061 | ||
3ddfabe3 | 11062 | -- Local variables |
09c954dc | 11063 | |
5a8a6763 | 11064 | E : constant Entity_Id := Entity (N); |
9a1bc6d5 | 11065 | |
0cb81445 PMR |
11066 | Nongeneric_Case : constant Boolean := Nkind (N) = N_Freeze_Entity; |
11067 | -- True in nongeneric case. Some of the processing here is skipped | |
5a8a6763 RD |
11068 | -- for the generic case since it is not needed. Basically in the |
11069 | -- generic case, we only need to do stuff that might generate error | |
11070 | -- messages or warnings. | |
09c954dc AC |
11071 | |
11072 | -- Start of processing for Freeze_Entity_Checks | |
11073 | ||
5a8a6763 RD |
11074 | begin |
11075 | -- Remember that we are processing a freezing entity. Required to | |
11076 | -- ensure correct decoration of internal entities associated with | |
11077 | -- interfaces (see New_Overloaded_Entity). | |
9a1bc6d5 | 11078 | |
5a8a6763 | 11079 | Inside_Freezing_Actions := Inside_Freezing_Actions + 1; |
9a1bc6d5 | 11080 | |
5a8a6763 RD |
11081 | -- For tagged types covering interfaces add internal entities that link |
11082 | -- the primitives of the interfaces with the primitives that cover them. | |
11083 | -- Note: These entities were originally generated only when generating | |
11084 | -- code because their main purpose was to provide support to initialize | |
11085 | -- the secondary dispatch tables. They are now generated also when | |
11086 | -- compiling with no code generation to provide ASIS the relationship | |
11087 | -- between interface primitives and tagged type primitives. They are | |
11088 | -- also used to locate primitives covering interfaces when processing | |
11089 | -- generics (see Derive_Subprograms). | |
9a1bc6d5 | 11090 | |
5a8a6763 | 11091 | -- This is not needed in the generic case |
9a1bc6d5 | 11092 | |
5a8a6763 | 11093 | if Ada_Version >= Ada_2005 |
0cb81445 | 11094 | and then Nongeneric_Case |
5a8a6763 RD |
11095 | and then Ekind (E) = E_Record_Type |
11096 | and then Is_Tagged_Type (E) | |
11097 | and then not Is_Interface (E) | |
11098 | and then Has_Interfaces (E) | |
11099 | then | |
11100 | -- This would be a good common place to call the routine that checks | |
11101 | -- overriding of interface primitives (and thus factorize calls to | |
11102 | -- Check_Abstract_Overriding located at different contexts in the | |
11103 | -- compiler). However, this is not possible because it causes | |
11104 | -- spurious errors in case of late overriding. | |
9a1bc6d5 | 11105 | |
5a8a6763 RD |
11106 | Add_Internal_Interface_Entities (E); |
11107 | end if; | |
9a1bc6d5 | 11108 | |
09c954dc AC |
11109 | -- After all forms of overriding have been resolved, a tagged type may |
11110 | -- be left with a set of implicitly declared and possibly erroneous | |
11111 | -- abstract subprograms, null procedures and subprograms that require | |
75a957f5 AC |
11112 | -- overriding. If this set contains fully conformant homographs, then |
11113 | -- one is chosen arbitrarily (already done during resolution), otherwise | |
11114 | -- all remaining non-fully conformant homographs are hidden from | |
11115 | -- visibility (Ada RM 8.3 12.3/2). | |
09c954dc AC |
11116 | |
11117 | if Is_Tagged_Type (E) then | |
11118 | Hide_Non_Overridden_Subprograms (E); | |
11119 | end if; | |
11120 | ||
5a8a6763 | 11121 | -- Check CPP types |
9a1bc6d5 | 11122 | |
5a8a6763 RD |
11123 | if Ekind (E) = E_Record_Type |
11124 | and then Is_CPP_Class (E) | |
11125 | and then Is_Tagged_Type (E) | |
11126 | and then Tagged_Type_Expansion | |
5a8a6763 RD |
11127 | then |
11128 | if CPP_Num_Prims (E) = 0 then | |
9a1bc6d5 | 11129 | |
5a8a6763 RD |
11130 | -- If the CPP type has user defined components then it must import |
11131 | -- primitives from C++. This is required because if the C++ class | |
11132 | -- has no primitives then the C++ compiler does not added the _tag | |
11133 | -- component to the type. | |
9a1bc6d5 | 11134 | |
5a8a6763 RD |
11135 | if First_Entity (E) /= Last_Entity (E) then |
11136 | Error_Msg_N | |
11137 | ("'C'P'P type must import at least one primitive from C++??", | |
11138 | E); | |
11139 | end if; | |
11140 | end if; | |
9a1bc6d5 | 11141 | |
5a8a6763 RD |
11142 | -- Check that all its primitives are abstract or imported from C++. |
11143 | -- Check also availability of the C++ constructor. | |
9a1bc6d5 | 11144 | |
5a8a6763 RD |
11145 | declare |
11146 | Has_Constructors : constant Boolean := Has_CPP_Constructors (E); | |
11147 | Elmt : Elmt_Id; | |
11148 | Error_Reported : Boolean := False; | |
11149 | Prim : Node_Id; | |
9a1bc6d5 | 11150 | |
5a8a6763 RD |
11151 | begin |
11152 | Elmt := First_Elmt (Primitive_Operations (E)); | |
11153 | while Present (Elmt) loop | |
11154 | Prim := Node (Elmt); | |
9a1bc6d5 | 11155 | |
5a8a6763 RD |
11156 | if Comes_From_Source (Prim) then |
11157 | if Is_Abstract_Subprogram (Prim) then | |
11158 | null; | |
9a1bc6d5 | 11159 | |
5a8a6763 RD |
11160 | elsif not Is_Imported (Prim) |
11161 | or else Convention (Prim) /= Convention_CPP | |
11162 | then | |
11163 | Error_Msg_N | |
11164 | ("primitives of 'C'P'P types must be imported from C++ " | |
11165 | & "or abstract??", Prim); | |
9a1bc6d5 | 11166 | |
5a8a6763 RD |
11167 | elsif not Has_Constructors |
11168 | and then not Error_Reported | |
11169 | then | |
11170 | Error_Msg_Name_1 := Chars (E); | |
11171 | Error_Msg_N | |
11172 | ("??'C'P'P constructor required for type %", Prim); | |
11173 | Error_Reported := True; | |
11174 | end if; | |
11175 | end if; | |
9a1bc6d5 | 11176 | |
5a8a6763 RD |
11177 | Next_Elmt (Elmt); |
11178 | end loop; | |
11179 | end; | |
11180 | end if; | |
9a1bc6d5 | 11181 | |
5a8a6763 | 11182 | -- Check Ada derivation of CPP type |
9a1bc6d5 | 11183 | |
43c58950 AC |
11184 | if Expander_Active -- why? losing errors in -gnatc mode??? |
11185 | and then Present (Etype (E)) -- defend against errors | |
5a8a6763 RD |
11186 | and then Tagged_Type_Expansion |
11187 | and then Ekind (E) = E_Record_Type | |
11188 | and then Etype (E) /= E | |
11189 | and then Is_CPP_Class (Etype (E)) | |
11190 | and then CPP_Num_Prims (Etype (E)) > 0 | |
11191 | and then not Is_CPP_Class (E) | |
11192 | and then not Has_CPP_Constructors (Etype (E)) | |
11193 | then | |
11194 | -- If the parent has C++ primitives but it has no constructor then | |
11195 | -- check that all the primitives are overridden in this derivation; | |
11196 | -- otherwise the constructor of the parent is needed to build the | |
11197 | -- dispatch table. | |
9a1bc6d5 | 11198 | |
5a8a6763 RD |
11199 | declare |
11200 | Elmt : Elmt_Id; | |
11201 | Prim : Node_Id; | |
9a1bc6d5 AC |
11202 | |
11203 | begin | |
5a8a6763 RD |
11204 | Elmt := First_Elmt (Primitive_Operations (E)); |
11205 | while Present (Elmt) loop | |
11206 | Prim := Node (Elmt); | |
9a1bc6d5 | 11207 | |
5a8a6763 RD |
11208 | if not Is_Abstract_Subprogram (Prim) |
11209 | and then No (Interface_Alias (Prim)) | |
11210 | and then Find_Dispatching_Type (Ultimate_Alias (Prim)) /= E | |
9a1bc6d5 | 11211 | then |
5a8a6763 RD |
11212 | Error_Msg_Name_1 := Chars (Etype (E)); |
11213 | Error_Msg_N | |
11214 | ("'C'P'P constructor required for parent type %", E); | |
11215 | exit; | |
9a1bc6d5 | 11216 | end if; |
5a8a6763 RD |
11217 | |
11218 | Next_Elmt (Elmt); | |
11219 | end loop; | |
11220 | end; | |
9a1bc6d5 AC |
11221 | end if; |
11222 | ||
5a8a6763 | 11223 | Inside_Freezing_Actions := Inside_Freezing_Actions - 1; |
8a95f4e8 | 11224 | |
3ddfabe3 AC |
11225 | -- If we have a type with predicates, build predicate function. This is |
11226 | -- not needed in the generic case, nor within TSS subprograms and other | |
20643f50 ES |
11227 | -- predefined primitives. For a derived type, ensure that the parent |
11228 | -- type is already frozen so that its predicate function has been | |
11229 | -- constructed already. This is necessary if the parent is declared | |
11230 | -- in a nested package and its own freeze point has not been reached. | |
8a95f4e8 | 11231 | |
3ddfabe3 | 11232 | if Is_Type (E) |
0cb81445 | 11233 | and then Nongeneric_Case |
8e1e62e3 | 11234 | and then not Within_Internal_Subprogram |
3ddfabe3 | 11235 | and then Has_Predicates (E) |
8e1e62e3 | 11236 | then |
20643f50 ES |
11237 | declare |
11238 | Atyp : constant Entity_Id := Nearest_Ancestor (E); | |
11239 | begin | |
11240 | if Present (Atyp) | |
11241 | and then Has_Predicates (Atyp) | |
11242 | and then not Is_Frozen (Atyp) | |
11243 | then | |
11244 | Freeze_Before (N, Atyp); | |
11245 | end if; | |
11246 | end; | |
11247 | ||
5a8a6763 RD |
11248 | Build_Predicate_Functions (E, N); |
11249 | end if; | |
8a95f4e8 | 11250 | |
5a8a6763 RD |
11251 | -- If type has delayed aspects, this is where we do the preanalysis at |
11252 | -- the freeze point, as part of the consistent visibility check. Note | |
11253 | -- that this must be done after calling Build_Predicate_Functions or | |
11254 | -- Build_Invariant_Procedure since these subprograms fix occurrences of | |
11255 | -- the subtype name in the saved expression so that they will not cause | |
11256 | -- trouble in the preanalysis. | |
8a95f4e8 | 11257 | |
d030f3a4 | 11258 | -- This is also not needed in the generic case |
5a8a6763 | 11259 | |
0cb81445 | 11260 | if Nongeneric_Case |
d030f3a4 | 11261 | and then Has_Delayed_Aspects (E) |
5a8a6763 RD |
11262 | and then Scope (E) = Current_Scope |
11263 | then | |
5a8a6763 | 11264 | declare |
2401c98f | 11265 | A_Id : Aspect_Id; |
5a8a6763 RD |
11266 | Ritem : Node_Id; |
11267 | ||
11268 | begin | |
11269 | -- Look for aspect specification entries for this entity | |
8a95f4e8 | 11270 | |
5a8a6763 RD |
11271 | Ritem := First_Rep_Item (E); |
11272 | while Present (Ritem) loop | |
11273 | if Nkind (Ritem) = N_Aspect_Specification | |
11274 | and then Entity (Ritem) = E | |
11275 | and then Is_Delayed_Aspect (Ritem) | |
11276 | then | |
5f531fef | 11277 | A_Id := Get_Aspect_Id (Ritem); |
2401c98f | 11278 | |
5f531fef | 11279 | if A_Id = Aspect_Dynamic_Predicate |
f5d4b6ab | 11280 | or else A_Id = Aspect_Predicate |
5f531fef ES |
11281 | or else A_Id = Aspect_Priority |
11282 | then | |
11283 | -- Retrieve the visibility to components and discriminants | |
11284 | -- in order to properly analyze the aspects. | |
11285 | ||
11286 | Push_Type (E); | |
11287 | Check_Aspect_At_Freeze_Point (Ritem); | |
11288 | Pop_Type (E); | |
11289 | ||
11290 | else | |
11291 | Check_Aspect_At_Freeze_Point (Ritem); | |
11292 | end if; | |
5a8a6763 | 11293 | end if; |
8a95f4e8 | 11294 | |
5a8a6763 RD |
11295 | Next_Rep_Item (Ritem); |
11296 | end loop; | |
11297 | end; | |
8a95f4e8 | 11298 | |
8a95f4e8 | 11299 | end if; |
8a95f4e8 | 11300 | |
2401c98f HK |
11301 | -- For a record type, deal with variant parts. This has to be delayed to |
11302 | -- this point, because of the issue of statically predicated subtypes, | |
11303 | -- which we have to ensure are frozen before checking choices, since we | |
11304 | -- need to have the static choice list set. | |
996ae0b0 | 11305 | |
5a8a6763 RD |
11306 | if Is_Record_Type (E) then |
11307 | Check_Variant_Part : declare | |
11308 | D : constant Node_Id := Declaration_Node (E); | |
11309 | T : Node_Id; | |
11310 | C : Node_Id; | |
11311 | VP : Node_Id; | |
996ae0b0 | 11312 | |
5a8a6763 RD |
11313 | Others_Present : Boolean; |
11314 | pragma Warnings (Off, Others_Present); | |
11315 | -- Indicates others present, not used in this case | |
996ae0b0 | 11316 | |
5a8a6763 RD |
11317 | procedure Non_Static_Choice_Error (Choice : Node_Id); |
11318 | -- Error routine invoked by the generic instantiation below when | |
11319 | -- the variant part has a non static choice. | |
22a83cea | 11320 | |
5a8a6763 RD |
11321 | procedure Process_Declarations (Variant : Node_Id); |
11322 | -- Processes declarations associated with a variant. We analyzed | |
11323 | -- the declarations earlier (in Sem_Ch3.Analyze_Variant_Part), | |
11324 | -- but we still need the recursive call to Check_Choices for any | |
11325 | -- nested variant to get its choices properly processed. This is | |
11326 | -- also where we expand out the choices if expansion is active. | |
d27f3ff4 | 11327 | |
5a8a6763 RD |
11328 | package Variant_Choices_Processing is new |
11329 | Generic_Check_Choices | |
11330 | (Process_Empty_Choice => No_OP, | |
11331 | Process_Non_Static_Choice => Non_Static_Choice_Error, | |
11332 | Process_Associated_Node => Process_Declarations); | |
11333 | use Variant_Choices_Processing; | |
22a83cea | 11334 | |
5a8a6763 RD |
11335 | ----------------------------- |
11336 | -- Non_Static_Choice_Error -- | |
11337 | ----------------------------- | |
996ae0b0 | 11338 | |
5a8a6763 RD |
11339 | procedure Non_Static_Choice_Error (Choice : Node_Id) is |
11340 | begin | |
11341 | Flag_Non_Static_Expr | |
11342 | ("choice given in variant part is not static!", Choice); | |
11343 | end Non_Static_Choice_Error; | |
996ae0b0 | 11344 | |
5a8a6763 RD |
11345 | -------------------------- |
11346 | -- Process_Declarations -- | |
11347 | -------------------------- | |
ee2ba856 | 11348 | |
5a8a6763 RD |
11349 | procedure Process_Declarations (Variant : Node_Id) is |
11350 | CL : constant Node_Id := Component_List (Variant); | |
11351 | VP : Node_Id; | |
ee2ba856 | 11352 | |
5a8a6763 RD |
11353 | begin |
11354 | -- Check for static predicate present in this variant | |
d05ef0ab | 11355 | |
5a8a6763 | 11356 | if Has_SP_Choice (Variant) then |
d05ef0ab | 11357 | |
5a8a6763 RD |
11358 | -- Here we expand. You might expect to find this call in |
11359 | -- Expand_N_Variant_Part, but that is called when we first | |
11360 | -- see the variant part, and we cannot do this expansion | |
11361 | -- earlier than the freeze point, since for statically | |
11362 | -- predicated subtypes, the predicate is not known till | |
11363 | -- the freeze point. | |
d05ef0ab | 11364 | |
5a8a6763 RD |
11365 | -- Furthermore, we do this expansion even if the expander |
11366 | -- is not active, because other semantic processing, e.g. | |
11367 | -- for aggregates, requires the expanded list of choices. | |
d05ef0ab | 11368 | |
5a8a6763 RD |
11369 | -- If the expander is not active, then we can't just clobber |
11370 | -- the list since it would invalidate the ASIS -gnatct tree. | |
11371 | -- So we have to rewrite the variant part with a Rewrite | |
11372 | -- call that replaces it with a copy and clobber the copy. | |
11373 | ||
11374 | if not Expander_Active then | |
11375 | declare | |
11376 | NewV : constant Node_Id := New_Copy (Variant); | |
11377 | begin | |
11378 | Set_Discrete_Choices | |
11379 | (NewV, New_Copy_List (Discrete_Choices (Variant))); | |
11380 | Rewrite (Variant, NewV); | |
11381 | end; | |
11382 | end if; | |
11383 | ||
11384 | Expand_Static_Predicates_In_Choices (Variant); | |
d05ef0ab AC |
11385 | end if; |
11386 | ||
5a8a6763 RD |
11387 | -- We don't need to worry about the declarations in the variant |
11388 | -- (since they were analyzed by Analyze_Choices when we first | |
11389 | -- encountered the variant), but we do need to take care of | |
11390 | -- expansion of any nested variants. | |
d05ef0ab | 11391 | |
5a8a6763 RD |
11392 | if not Null_Present (CL) then |
11393 | VP := Variant_Part (CL); | |
d05ef0ab | 11394 | |
5a8a6763 RD |
11395 | if Present (VP) then |
11396 | Check_Choices | |
11397 | (VP, Variants (VP), Etype (Name (VP)), Others_Present); | |
11398 | end if; | |
11399 | end if; | |
11400 | end Process_Declarations; | |
d05ef0ab | 11401 | |
5a8a6763 | 11402 | -- Start of processing for Check_Variant_Part |
616547fa | 11403 | |
5a8a6763 RD |
11404 | begin |
11405 | -- Find component list | |
d05ef0ab | 11406 | |
5a8a6763 | 11407 | C := Empty; |
d05ef0ab | 11408 | |
5a8a6763 RD |
11409 | if Nkind (D) = N_Full_Type_Declaration then |
11410 | T := Type_Definition (D); | |
d05ef0ab | 11411 | |
5a8a6763 RD |
11412 | if Nkind (T) = N_Record_Definition then |
11413 | C := Component_List (T); | |
996ae0b0 | 11414 | |
5a8a6763 RD |
11415 | elsif Nkind (T) = N_Derived_Type_Definition |
11416 | and then Present (Record_Extension_Part (T)) | |
11417 | then | |
11418 | C := Component_List (Record_Extension_Part (T)); | |
11419 | end if; | |
11420 | end if; | |
996ae0b0 | 11421 | |
5a8a6763 | 11422 | -- Case of variant part present |
996ae0b0 | 11423 | |
5a8a6763 RD |
11424 | if Present (C) and then Present (Variant_Part (C)) then |
11425 | VP := Variant_Part (C); | |
d05ef0ab | 11426 | |
5a8a6763 | 11427 | -- Check choices |
d05ef0ab | 11428 | |
5a8a6763 RD |
11429 | Check_Choices |
11430 | (VP, Variants (VP), Etype (Name (VP)), Others_Present); | |
d05ef0ab | 11431 | |
5a8a6763 RD |
11432 | -- If the last variant does not contain the Others choice, |
11433 | -- replace it with an N_Others_Choice node since Gigi always | |
11434 | -- wants an Others. Note that we do not bother to call Analyze | |
11435 | -- on the modified variant part, since its only effect would be | |
11436 | -- to compute the Others_Discrete_Choices node laboriously, and | |
11437 | -- of course we already know the list of choices corresponding | |
a90bd866 | 11438 | -- to the others choice (it's the list we're replacing). |
996ae0b0 | 11439 | |
5a8a6763 | 11440 | -- We only want to do this if the expander is active, since |
a90bd866 | 11441 | -- we do not want to clobber the ASIS tree. |
996ae0b0 | 11442 | |
5a8a6763 RD |
11443 | if Expander_Active then |
11444 | declare | |
11445 | Last_Var : constant Node_Id := | |
11446 | Last_Non_Pragma (Variants (VP)); | |
996ae0b0 | 11447 | |
5a8a6763 | 11448 | Others_Node : Node_Id; |
996ae0b0 | 11449 | |
5a8a6763 RD |
11450 | begin |
11451 | if Nkind (First (Discrete_Choices (Last_Var))) /= | |
11452 | N_Others_Choice | |
11453 | then | |
11454 | Others_Node := Make_Others_Choice (Sloc (Last_Var)); | |
11455 | Set_Others_Discrete_Choices | |
11456 | (Others_Node, Discrete_Choices (Last_Var)); | |
11457 | Set_Discrete_Choices | |
11458 | (Last_Var, New_List (Others_Node)); | |
11459 | end if; | |
11460 | end; | |
11461 | end if; | |
996ae0b0 | 11462 | end if; |
5a8a6763 | 11463 | end Check_Variant_Part; |
996ae0b0 | 11464 | end if; |
5a8a6763 | 11465 | end Freeze_Entity_Checks; |
996ae0b0 RK |
11466 | |
11467 | ------------------------- | |
11468 | -- Get_Alignment_Value -- | |
11469 | ------------------------- | |
11470 | ||
11471 | function Get_Alignment_Value (Expr : Node_Id) return Uint is | |
51122913 | 11472 | Align : constant Uint := Static_Integer (Expr); |
32b794c8 | 11473 | |
51122913 HK |
11474 | begin |
11475 | if Align = No_Uint then | |
11476 | return No_Uint; | |
11477 | ||
11478 | elsif Align <= 0 then | |
32b794c8 | 11479 | |
32b794c8 | 11480 | -- This error is suppressed in ASIS mode to allow for different ASIS |
2cc2e964 | 11481 | -- back ends or ASIS-based tools to query the illegal clause. |
32b794c8 AC |
11482 | |
11483 | if not ASIS_Mode then | |
11484 | Error_Msg_N ("alignment value must be positive", Expr); | |
11485 | end if; | |
32b794c8 | 11486 | |
996ae0b0 RK |
11487 | return No_Uint; |
11488 | ||
11489 | else | |
11490 | for J in Int range 0 .. 64 loop | |
11491 | declare | |
11492 | M : constant Uint := Uint_2 ** J; | |
11493 | ||
11494 | begin | |
11495 | exit when M = Align; | |
11496 | ||
11497 | if M > Align then | |
51122913 HK |
11498 | |
11499 | -- This error is suppressed in ASIS mode to allow for | |
2cc2e964 | 11500 | -- different ASIS back ends or ASIS-based tools to query the |
51122913 HK |
11501 | -- illegal clause. |
11502 | ||
11503 | if not ASIS_Mode then | |
11504 | Error_Msg_N ("alignment value must be power of 2", Expr); | |
11505 | end if; | |
11506 | ||
996ae0b0 RK |
11507 | return No_Uint; |
11508 | end if; | |
11509 | end; | |
11510 | end loop; | |
11511 | ||
11512 | return Align; | |
11513 | end if; | |
11514 | end Get_Alignment_Value; | |
11515 | ||
dc3af7e2 AC |
11516 | ------------------------------------- |
11517 | -- Inherit_Aspects_At_Freeze_Point -- | |
11518 | ------------------------------------- | |
11519 | ||
11520 | procedure Inherit_Aspects_At_Freeze_Point (Typ : Entity_Id) is | |
11521 | function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11522 | (Rep_Item : Node_Id) return Boolean; | |
11523 | -- This routine checks if Rep_Item is either a pragma or an aspect | |
11524 | -- specification node whose correponding pragma (if any) is present in | |
11525 | -- the Rep Item chain of the entity it has been specified to. | |
11526 | ||
def15641 TQ |
11527 | function Rep_Item_Entity (Rep_Item : Node_Id) return Entity_Id; |
11528 | -- Return the entity for which Rep_Item is specified | |
11529 | ||
c7862167 HK |
11530 | -------------------------------------------------- |
11531 | -- Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item -- | |
11532 | -------------------------------------------------- | |
11533 | ||
11534 | function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11535 | (Rep_Item : Node_Id) return Boolean | |
11536 | is | |
11537 | begin | |
11538 | return | |
11539 | Nkind (Rep_Item) = N_Pragma | |
11540 | or else Present_In_Rep_Item | |
11541 | (Entity (Rep_Item), Aspect_Rep_Item (Rep_Item)); | |
11542 | end Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item; | |
11543 | ||
def15641 TQ |
11544 | --------------------- |
11545 | -- Rep_Item_Entity -- | |
11546 | --------------------- | |
11547 | ||
11548 | function Rep_Item_Entity (Rep_Item : Node_Id) return Entity_Id is | |
11549 | begin | |
11550 | if Nkind (Rep_Item) = N_Aspect_Specification then | |
11551 | return Entity (Rep_Item); | |
11552 | ||
11553 | else | |
11554 | pragma Assert (Nkind_In (Rep_Item, | |
c7862167 HK |
11555 | N_Attribute_Definition_Clause, |
11556 | N_Pragma)); | |
def15641 TQ |
11557 | return Entity (Name (Rep_Item)); |
11558 | end if; | |
11559 | end Rep_Item_Entity; | |
11560 | ||
2791be24 AC |
11561 | -- Start of processing for Inherit_Aspects_At_Freeze_Point |
11562 | ||
dc3af7e2 AC |
11563 | begin |
11564 | -- A representation item is either subtype-specific (Size and Alignment | |
11565 | -- clauses) or type-related (all others). Subtype-specific aspects may | |
2791be24 | 11566 | -- differ for different subtypes of the same type (RM 13.1.8). |
dc3af7e2 AC |
11567 | |
11568 | -- A derived type inherits each type-related representation aspect of | |
11569 | -- its parent type that was directly specified before the declaration of | |
2791be24 | 11570 | -- the derived type (RM 13.1.15). |
dc3af7e2 AC |
11571 | |
11572 | -- A derived subtype inherits each subtype-specific representation | |
11573 | -- aspect of its parent subtype that was directly specified before the | |
2791be24 | 11574 | -- declaration of the derived type (RM 13.1.15). |
dc3af7e2 AC |
11575 | |
11576 | -- The general processing involves inheriting a representation aspect | |
11577 | -- from a parent type whenever the first rep item (aspect specification, | |
11578 | -- attribute definition clause, pragma) corresponding to the given | |
11579 | -- representation aspect in the rep item chain of Typ, if any, isn't | |
11580 | -- directly specified to Typ but to one of its parents. | |
11581 | ||
11582 | -- ??? Note that, for now, just a limited number of representation | |
2791be24 AC |
11583 | -- aspects have been inherited here so far. Many of them are |
11584 | -- still inherited in Sem_Ch3. This will be fixed soon. Here is | |
11585 | -- a non- exhaustive list of aspects that likely also need to | |
11586 | -- be moved to this routine: Alignment, Component_Alignment, | |
11587 | -- Component_Size, Machine_Radix, Object_Size, Pack, Predicates, | |
dc3af7e2 AC |
11588 | -- Preelaborable_Initialization, RM_Size and Small. |
11589 | ||
dbb4cfef AC |
11590 | -- In addition, Convention must be propagated from base type to subtype, |
11591 | -- because the subtype may have been declared on an incomplete view. | |
11592 | ||
dc3af7e2 AC |
11593 | if Nkind (Parent (Typ)) = N_Private_Extension_Declaration then |
11594 | return; | |
11595 | end if; | |
11596 | ||
11597 | -- Ada_05/Ada_2005 | |
11598 | ||
11599 | if not Has_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005, False) | |
11600 | and then Has_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005) | |
11601 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11602 | (Get_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005)) | |
11603 | then | |
11604 | Set_Is_Ada_2005_Only (Typ); | |
11605 | end if; | |
11606 | ||
11607 | -- Ada_12/Ada_2012 | |
11608 | ||
11609 | if not Has_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012, False) | |
11610 | and then Has_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012) | |
11611 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11612 | (Get_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012)) | |
11613 | then | |
11614 | Set_Is_Ada_2012_Only (Typ); | |
11615 | end if; | |
11616 | ||
11617 | -- Atomic/Shared | |
11618 | ||
11619 | if not Has_Rep_Item (Typ, Name_Atomic, Name_Shared, False) | |
11620 | and then Has_Rep_Pragma (Typ, Name_Atomic, Name_Shared) | |
11621 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11622 | (Get_Rep_Item (Typ, Name_Atomic, Name_Shared)) | |
11623 | then | |
11624 | Set_Is_Atomic (Typ); | |
dc3af7e2 | 11625 | Set_Is_Volatile (Typ); |
57abdadd | 11626 | Set_Treat_As_Volatile (Typ); |
dc3af7e2 AC |
11627 | end if; |
11628 | ||
dbb4cfef AC |
11629 | -- Convention |
11630 | ||
64dbfdec AC |
11631 | if Is_Record_Type (Typ) |
11632 | and then Typ /= Base_Type (Typ) and then Is_Frozen (Base_Type (Typ)) | |
11633 | then | |
dbb4cfef AC |
11634 | Set_Convention (Typ, Convention (Base_Type (Typ))); |
11635 | end if; | |
11636 | ||
2791be24 | 11637 | -- Default_Component_Value |
dc3af7e2 | 11638 | |
731261c3 AC |
11639 | -- Verify that there is no rep_item declared for the type, and there |
11640 | -- is one coming from an ancestor. | |
11641 | ||
dc3af7e2 | 11642 | if Is_Array_Type (Typ) |
688a9b51 | 11643 | and then Is_Base_Type (Typ) |
731261c3 | 11644 | and then not Has_Rep_Item (Typ, Name_Default_Component_Value, False) |
dc3af7e2 AC |
11645 | and then Has_Rep_Item (Typ, Name_Default_Component_Value) |
11646 | then | |
11647 | Set_Default_Aspect_Component_Value (Typ, | |
11648 | Default_Aspect_Component_Value | |
11649 | (Entity (Get_Rep_Item (Typ, Name_Default_Component_Value)))); | |
11650 | end if; | |
11651 | ||
2791be24 | 11652 | -- Default_Value |
dc3af7e2 AC |
11653 | |
11654 | if Is_Scalar_Type (Typ) | |
688a9b51 | 11655 | and then Is_Base_Type (Typ) |
731261c3 | 11656 | and then not Has_Rep_Item (Typ, Name_Default_Value, False) |
dc3af7e2 AC |
11657 | and then Has_Rep_Item (Typ, Name_Default_Value) |
11658 | then | |
731261c3 | 11659 | Set_Has_Default_Aspect (Typ); |
dc3af7e2 AC |
11660 | Set_Default_Aspect_Value (Typ, |
11661 | Default_Aspect_Value | |
11662 | (Entity (Get_Rep_Item (Typ, Name_Default_Value)))); | |
11663 | end if; | |
11664 | ||
11665 | -- Discard_Names | |
11666 | ||
11667 | if not Has_Rep_Item (Typ, Name_Discard_Names, False) | |
11668 | and then Has_Rep_Item (Typ, Name_Discard_Names) | |
11669 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11670 | (Get_Rep_Item (Typ, Name_Discard_Names)) | |
11671 | then | |
11672 | Set_Discard_Names (Typ); | |
11673 | end if; | |
11674 | ||
dc3af7e2 AC |
11675 | -- Volatile |
11676 | ||
11677 | if not Has_Rep_Item (Typ, Name_Volatile, False) | |
11678 | and then Has_Rep_Item (Typ, Name_Volatile) | |
11679 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11680 | (Get_Rep_Item (Typ, Name_Volatile)) | |
11681 | then | |
dc3af7e2 | 11682 | Set_Is_Volatile (Typ); |
57abdadd | 11683 | Set_Treat_As_Volatile (Typ); |
dc3af7e2 AC |
11684 | end if; |
11685 | ||
f280dd8f RD |
11686 | -- Volatile_Full_Access |
11687 | ||
11688 | if not Has_Rep_Item (Typ, Name_Volatile_Full_Access, False) | |
11689 | and then Has_Rep_Pragma (Typ, Name_Volatile_Full_Access) | |
11690 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11691 | (Get_Rep_Item (Typ, Name_Volatile_Full_Access)) | |
11692 | then | |
57abdadd | 11693 | Set_Is_Volatile_Full_Access (Typ); |
f280dd8f | 11694 | Set_Is_Volatile (Typ); |
57abdadd | 11695 | Set_Treat_As_Volatile (Typ); |
f280dd8f RD |
11696 | end if; |
11697 | ||
dc3af7e2 AC |
11698 | -- Inheritance for derived types only |
11699 | ||
11700 | if Is_Derived_Type (Typ) then | |
11701 | declare | |
11702 | Bas_Typ : constant Entity_Id := Base_Type (Typ); | |
11703 | Imp_Bas_Typ : constant Entity_Id := Implementation_Base_Type (Typ); | |
11704 | ||
11705 | begin | |
11706 | -- Atomic_Components | |
11707 | ||
11708 | if not Has_Rep_Item (Typ, Name_Atomic_Components, False) | |
11709 | and then Has_Rep_Item (Typ, Name_Atomic_Components) | |
11710 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11711 | (Get_Rep_Item (Typ, Name_Atomic_Components)) | |
11712 | then | |
11713 | Set_Has_Atomic_Components (Imp_Bas_Typ); | |
11714 | end if; | |
11715 | ||
11716 | -- Volatile_Components | |
11717 | ||
11718 | if not Has_Rep_Item (Typ, Name_Volatile_Components, False) | |
11719 | and then Has_Rep_Item (Typ, Name_Volatile_Components) | |
11720 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11721 | (Get_Rep_Item (Typ, Name_Volatile_Components)) | |
11722 | then | |
11723 | Set_Has_Volatile_Components (Imp_Bas_Typ); | |
11724 | end if; | |
11725 | ||
eefd2467 | 11726 | -- Finalize_Storage_Only |
dc3af7e2 AC |
11727 | |
11728 | if not Has_Rep_Pragma (Typ, Name_Finalize_Storage_Only, False) | |
11729 | and then Has_Rep_Pragma (Typ, Name_Finalize_Storage_Only) | |
11730 | then | |
11731 | Set_Finalize_Storage_Only (Bas_Typ); | |
11732 | end if; | |
11733 | ||
11734 | -- Universal_Aliasing | |
11735 | ||
11736 | if not Has_Rep_Item (Typ, Name_Universal_Aliasing, False) | |
11737 | and then Has_Rep_Item (Typ, Name_Universal_Aliasing) | |
11738 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11739 | (Get_Rep_Item (Typ, Name_Universal_Aliasing)) | |
11740 | then | |
11741 | Set_Universal_Aliasing (Imp_Bas_Typ); | |
11742 | end if; | |
11743 | ||
eefd2467 | 11744 | -- Bit_Order |
dc3af7e2 AC |
11745 | |
11746 | if Is_Record_Type (Typ) then | |
dc3af7e2 AC |
11747 | if not Has_Rep_Item (Typ, Name_Bit_Order, False) |
11748 | and then Has_Rep_Item (Typ, Name_Bit_Order) | |
11749 | then | |
11750 | Set_Reverse_Bit_Order (Bas_Typ, | |
def15641 TQ |
11751 | Reverse_Bit_Order (Rep_Item_Entity |
11752 | (Get_Rep_Item (Typ, Name_Bit_Order)))); | |
dc3af7e2 | 11753 | end if; |
eefd2467 AC |
11754 | end if; |
11755 | ||
8b64ed4c TQ |
11756 | -- Scalar_Storage_Order |
11757 | ||
11758 | -- Note: the aspect is specified on a first subtype, but recorded | |
11759 | -- in a flag of the base type! | |
eefd2467 AC |
11760 | |
11761 | if (Is_Record_Type (Typ) or else Is_Array_Type (Typ)) | |
bcdb6b04 | 11762 | and then Typ = Bas_Typ |
eefd2467 | 11763 | then |
eefd2467 AC |
11764 | -- For a type extension, always inherit from parent; otherwise |
11765 | -- inherit if no default applies. Note: we do not check for | |
11766 | -- an explicit rep item on the parent type when inheriting, | |
11767 | -- because the parent SSO may itself have been set by default. | |
dc3af7e2 | 11768 | |
8b64ed4c TQ |
11769 | if not Has_Rep_Item (First_Subtype (Typ), |
11770 | Name_Scalar_Storage_Order, False) | |
eefd2467 | 11771 | and then (Is_Tagged_Type (Bas_Typ) |
bcdb6b04 AC |
11772 | or else not (SSO_Set_Low_By_Default (Bas_Typ) |
11773 | or else | |
11774 | SSO_Set_High_By_Default (Bas_Typ))) | |
dc3af7e2 AC |
11775 | then |
11776 | Set_Reverse_Storage_Order (Bas_Typ, | |
35e7063a AC |
11777 | Reverse_Storage_Order |
11778 | (Implementation_Base_Type (Etype (Bas_Typ)))); | |
220d1fd9 AC |
11779 | |
11780 | -- Clear default SSO indications, since the inherited aspect | |
11781 | -- which was set explicitly overrides the default. | |
11782 | ||
11783 | Set_SSO_Set_Low_By_Default (Bas_Typ, False); | |
11784 | Set_SSO_Set_High_By_Default (Bas_Typ, False); | |
dc3af7e2 AC |
11785 | end if; |
11786 | end if; | |
11787 | end; | |
11788 | end if; | |
11789 | end Inherit_Aspects_At_Freeze_Point; | |
11790 | ||
996ae0b0 RK |
11791 | ---------------- |
11792 | -- Initialize -- | |
11793 | ---------------- | |
11794 | ||
11795 | procedure Initialize is | |
11796 | begin | |
105b5e65 | 11797 | Address_Clause_Checks.Init; |
996ae0b0 | 11798 | Unchecked_Conversions.Init; |
07aff4e3 | 11799 | |
f8f50235 AC |
11800 | -- ??? Might be needed in the future for some non GCC back-ends |
11801 | -- if AAMP_On_Target then | |
11802 | -- Independence_Checks.Init; | |
11803 | -- end if; | |
996ae0b0 RK |
11804 | end Initialize; |
11805 | ||
77a40ec1 AC |
11806 | --------------------------- |
11807 | -- Install_Discriminants -- | |
11808 | --------------------------- | |
11809 | ||
11810 | procedure Install_Discriminants (E : Entity_Id) is | |
11811 | Disc : Entity_Id; | |
11812 | Prev : Entity_Id; | |
11813 | begin | |
11814 | Disc := First_Discriminant (E); | |
11815 | while Present (Disc) loop | |
11816 | Prev := Current_Entity (Disc); | |
11817 | Set_Current_Entity (Disc); | |
11818 | Set_Is_Immediately_Visible (Disc); | |
11819 | Set_Homonym (Disc, Prev); | |
11820 | Next_Discriminant (Disc); | |
11821 | end loop; | |
11822 | end Install_Discriminants; | |
11823 | ||
996ae0b0 RK |
11824 | ------------------------- |
11825 | -- Is_Operational_Item -- | |
11826 | ------------------------- | |
11827 | ||
11828 | function Is_Operational_Item (N : Node_Id) return Boolean is | |
11829 | begin | |
11830 | if Nkind (N) /= N_Attribute_Definition_Clause then | |
11831 | return False; | |
616547fa | 11832 | |
996ae0b0 RK |
11833 | else |
11834 | declare | |
616547fa | 11835 | Id : constant Attribute_Id := Get_Attribute_Id (Chars (N)); |
996ae0b0 | 11836 | begin |
e9f97e79 | 11837 | |
47b79f78 | 11838 | -- List of operational items is given in AARM 13.1(8.mm/1). |
e9f97e79 AC |
11839 | -- It is clearly incomplete, as it does not include iterator |
11840 | -- aspects, among others. | |
11841 | ||
11842 | return Id = Attribute_Constant_Indexing | |
11843 | or else Id = Attribute_Default_Iterator | |
11844 | or else Id = Attribute_Implicit_Dereference | |
11845 | or else Id = Attribute_Input | |
11846 | or else Id = Attribute_Iterator_Element | |
11847 | or else Id = Attribute_Iterable | |
996ae0b0 RK |
11848 | or else Id = Attribute_Output |
11849 | or else Id = Attribute_Read | |
e9f97e79 | 11850 | or else Id = Attribute_Variable_Indexing |
07fc65c4 GB |
11851 | or else Id = Attribute_Write |
11852 | or else Id = Attribute_External_Tag; | |
996ae0b0 RK |
11853 | end; |
11854 | end if; | |
11855 | end Is_Operational_Item; | |
11856 | ||
ee4eee0a AC |
11857 | ------------------------- |
11858 | -- Is_Predicate_Static -- | |
11859 | ------------------------- | |
11860 | ||
fc3a3f3b RD |
11861 | -- Note: the basic legality of the expression has already been checked, so |
11862 | -- we don't need to worry about cases or ranges on strings for example. | |
11863 | ||
ee4eee0a AC |
11864 | function Is_Predicate_Static |
11865 | (Expr : Node_Id; | |
11866 | Nam : Name_Id) return Boolean | |
11867 | is | |
11868 | function All_Static_Case_Alternatives (L : List_Id) return Boolean; | |
f9648959 AC |
11869 | -- Given a list of case expression alternatives, returns True if all |
11870 | -- the alternatives are static (have all static choices, and a static | |
11871 | -- expression). | |
ee4eee0a AC |
11872 | |
11873 | function All_Static_Choices (L : List_Id) return Boolean; | |
c624298a | 11874 | -- Returns true if all elements of the list are OK static choices |
ee4eee0a | 11875 | -- as defined below for Is_Static_Choice. Used for case expression |
f9648959 AC |
11876 | -- alternatives and for the right operand of a membership test. An |
11877 | -- others_choice is static if the corresponding expression is static. | |
fd7215d7 | 11878 | -- The staticness of the bounds is checked separately. |
ee4eee0a AC |
11879 | |
11880 | function Is_Static_Choice (N : Node_Id) return Boolean; | |
11881 | -- Returns True if N represents a static choice (static subtype, or | |
c624298a | 11882 | -- static subtype indication, or static expression, or static range). |
ee4eee0a AC |
11883 | -- |
11884 | -- Note that this is a bit more inclusive than we actually need | |
11885 | -- (in particular membership tests do not allow the use of subtype | |
c624298a | 11886 | -- indications). But that doesn't matter, we have already checked |
ee4eee0a AC |
11887 | -- that the construct is legal to get this far. |
11888 | ||
11889 | function Is_Type_Ref (N : Node_Id) return Boolean; | |
11890 | pragma Inline (Is_Type_Ref); | |
f9648959 AC |
11891 | -- Returns True if N is a reference to the type for the predicate in the |
11892 | -- expression (i.e. if it is an identifier whose Chars field matches the | |
11893 | -- Nam given in the call). N must not be parenthesized, if the type name | |
11894 | -- appears in parens, this routine will return False. | |
582dbb53 | 11895 | -- |
e4d04166 AC |
11896 | -- The routine also returns True for function calls generated during the |
11897 | -- expansion of comparison operators on strings, which are intended to | |
11898 | -- be legal in static predicates, and are converted into calls to array | |
11899 | -- comparison routines in the body of the corresponding predicate | |
11900 | -- function. | |
11901 | ||
ee4eee0a AC |
11902 | ---------------------------------- |
11903 | -- All_Static_Case_Alternatives -- | |
11904 | ---------------------------------- | |
11905 | ||
11906 | function All_Static_Case_Alternatives (L : List_Id) return Boolean is | |
11907 | N : Node_Id; | |
11908 | ||
11909 | begin | |
11910 | N := First (L); | |
11911 | while Present (N) loop | |
11912 | if not (All_Static_Choices (Discrete_Choices (N)) | |
11913 | and then Is_OK_Static_Expression (Expression (N))) | |
11914 | then | |
11915 | return False; | |
11916 | end if; | |
11917 | ||
11918 | Next (N); | |
11919 | end loop; | |
11920 | ||
11921 | return True; | |
11922 | end All_Static_Case_Alternatives; | |
11923 | ||
11924 | ------------------------ | |
11925 | -- All_Static_Choices -- | |
11926 | ------------------------ | |
11927 | ||
11928 | function All_Static_Choices (L : List_Id) return Boolean is | |
11929 | N : Node_Id; | |
11930 | ||
11931 | begin | |
11932 | N := First (L); | |
11933 | while Present (N) loop | |
11934 | if not Is_Static_Choice (N) then | |
11935 | return False; | |
11936 | end if; | |
11937 | ||
11938 | Next (N); | |
11939 | end loop; | |
11940 | ||
11941 | return True; | |
11942 | end All_Static_Choices; | |
11943 | ||
11944 | ---------------------- | |
11945 | -- Is_Static_Choice -- | |
11946 | ---------------------- | |
11947 | ||
11948 | function Is_Static_Choice (N : Node_Id) return Boolean is | |
11949 | begin | |
fd7215d7 AC |
11950 | return Nkind (N) = N_Others_Choice |
11951 | or else Is_OK_Static_Expression (N) | |
ee4eee0a AC |
11952 | or else (Is_Entity_Name (N) and then Is_Type (Entity (N)) |
11953 | and then Is_OK_Static_Subtype (Entity (N))) | |
11954 | or else (Nkind (N) = N_Subtype_Indication | |
11955 | and then Is_OK_Static_Subtype (Entity (N))) | |
11956 | or else (Nkind (N) = N_Range and then Is_OK_Static_Range (N)); | |
11957 | end Is_Static_Choice; | |
11958 | ||
11959 | ----------------- | |
11960 | -- Is_Type_Ref -- | |
11961 | ----------------- | |
11962 | ||
11963 | function Is_Type_Ref (N : Node_Id) return Boolean is | |
11964 | begin | |
e4d04166 AC |
11965 | return (Nkind (N) = N_Identifier |
11966 | and then Chars (N) = Nam | |
11967 | and then Paren_Count (N) = 0) | |
11968 | or else Nkind (N) = N_Function_Call; | |
ee4eee0a AC |
11969 | end Is_Type_Ref; |
11970 | ||
11971 | -- Start of processing for Is_Predicate_Static | |
11972 | ||
11973 | begin | |
ee4eee0a AC |
11974 | -- Predicate_Static means one of the following holds. Numbers are the |
11975 | -- corresponding paragraph numbers in (RM 3.2.4(16-22)). | |
11976 | ||
11977 | -- 16: A static expression | |
11978 | ||
11979 | if Is_OK_Static_Expression (Expr) then | |
11980 | return True; | |
11981 | ||
11982 | -- 17: A membership test whose simple_expression is the current | |
11983 | -- instance, and whose membership_choice_list meets the requirements | |
11984 | -- for a static membership test. | |
11985 | ||
11986 | elsif Nkind (Expr) in N_Membership_Test | |
11987 | and then ((Present (Right_Opnd (Expr)) | |
11988 | and then Is_Static_Choice (Right_Opnd (Expr))) | |
11989 | or else | |
11990 | (Present (Alternatives (Expr)) | |
11991 | and then All_Static_Choices (Alternatives (Expr)))) | |
11992 | then | |
11993 | return True; | |
11994 | ||
11995 | -- 18. A case_expression whose selecting_expression is the current | |
11996 | -- instance, and whose dependent expressions are static expressions. | |
11997 | ||
11998 | elsif Nkind (Expr) = N_Case_Expression | |
11999 | and then Is_Type_Ref (Expression (Expr)) | |
12000 | and then All_Static_Case_Alternatives (Alternatives (Expr)) | |
12001 | then | |
12002 | return True; | |
12003 | ||
12004 | -- 19. A call to a predefined equality or ordering operator, where one | |
12005 | -- operand is the current instance, and the other is a static | |
12006 | -- expression. | |
12007 | ||
fc3a3f3b RD |
12008 | -- Note: the RM is clearly wrong here in not excluding string types. |
12009 | -- Without this exclusion, we would allow expressions like X > "ABC" | |
12010 | -- to be considered as predicate-static, which is clearly not intended, | |
12011 | -- since the idea is for predicate-static to be a subset of normal | |
12012 | -- static expressions (and "DEF" > "ABC" is not a static expression). | |
12013 | ||
12014 | -- However, we do allow internally generated (not from source) equality | |
12015 | -- and inequality operations to be valid on strings (this helps deal | |
12016 | -- with cases where we transform A in "ABC" to A = "ABC). | |
12017 | ||
e4d04166 AC |
12018 | -- In fact, it appears that the intent of the ARG is to extend static |
12019 | -- predicates to strings, and that the extension should probably apply | |
12020 | -- to static expressions themselves. The code below accepts comparison | |
12021 | -- operators that apply to static strings. | |
12022 | ||
ee4eee0a AC |
12023 | elsif Nkind (Expr) in N_Op_Compare |
12024 | and then ((Is_Type_Ref (Left_Opnd (Expr)) | |
12025 | and then Is_OK_Static_Expression (Right_Opnd (Expr))) | |
12026 | or else | |
12027 | (Is_Type_Ref (Right_Opnd (Expr)) | |
12028 | and then Is_OK_Static_Expression (Left_Opnd (Expr)))) | |
12029 | then | |
12030 | return True; | |
12031 | ||
12032 | -- 20. A call to a predefined boolean logical operator, where each | |
12033 | -- operand is predicate-static. | |
12034 | ||
12035 | elsif (Nkind_In (Expr, N_Op_And, N_Op_Or, N_Op_Xor) | |
12036 | and then Is_Predicate_Static (Left_Opnd (Expr), Nam) | |
12037 | and then Is_Predicate_Static (Right_Opnd (Expr), Nam)) | |
12038 | or else | |
12039 | (Nkind (Expr) = N_Op_Not | |
12040 | and then Is_Predicate_Static (Right_Opnd (Expr), Nam)) | |
12041 | then | |
12042 | return True; | |
12043 | ||
12044 | -- 21. A short-circuit control form where both operands are | |
12045 | -- predicate-static. | |
12046 | ||
12047 | elsif Nkind (Expr) in N_Short_Circuit | |
12048 | and then Is_Predicate_Static (Left_Opnd (Expr), Nam) | |
12049 | and then Is_Predicate_Static (Right_Opnd (Expr), Nam) | |
12050 | then | |
12051 | return True; | |
12052 | ||
12053 | -- 22. A parenthesized predicate-static expression. This does not | |
12054 | -- require any special test, since we just ignore paren levels in | |
12055 | -- all the cases above. | |
12056 | ||
12057 | -- One more test that is an implementation artifact caused by the fact | |
87e69720 | 12058 | -- that we are analyzing not the original expression, but the generated |
ee4eee0a | 12059 | -- expression in the body of the predicate function. This can include |
c624298a | 12060 | -- references to inherited predicates, so that the expression we are |
ee4eee0a AC |
12061 | -- processing looks like: |
12062 | ||
9bdc432a | 12063 | -- xxPredicate (typ (Inns)) and then expression |
ee4eee0a AC |
12064 | |
12065 | -- Where the call is to a Predicate function for an inherited predicate. | |
622599c6 RD |
12066 | -- We simply ignore such a call, which could be to either a dynamic or |
12067 | -- a static predicate. Note that if the parent predicate is dynamic then | |
12068 | -- eventually this type will be marked as dynamic, but you are allowed | |
12069 | -- to specify a static predicate for a subtype which is inheriting a | |
12070 | -- dynamic predicate, so the static predicate validation here ignores | |
12071 | -- the inherited predicate even if it is dynamic. | |
f24ea912 | 12072 | -- In all cases, a static predicate can only apply to a scalar type. |
ee4eee0a AC |
12073 | |
12074 | elsif Nkind (Expr) = N_Function_Call | |
12075 | and then Is_Predicate_Function (Entity (Name (Expr))) | |
f24ea912 | 12076 | and then Is_Scalar_Type (Etype (First_Entity (Entity (Name (Expr))))) |
ee4eee0a AC |
12077 | then |
12078 | return True; | |
12079 | ||
5b85ad7d PMR |
12080 | elsif Is_Entity_Name (Expr) |
12081 | and then Entity (Expr) = Standard_True | |
12082 | then | |
12083 | Error_Msg_N ("predicate is redundant (always True)?", Expr); | |
12084 | return True; | |
12085 | ||
ee4eee0a | 12086 | -- That's an exhaustive list of tests, all other cases are not |
c624298a | 12087 | -- predicate-static, so we return False. |
ee4eee0a AC |
12088 | |
12089 | else | |
12090 | return False; | |
12091 | end if; | |
12092 | end Is_Predicate_Static; | |
12093 | ||
cf28c974 RD |
12094 | --------------------- |
12095 | -- Kill_Rep_Clause -- | |
12096 | --------------------- | |
12097 | ||
12098 | procedure Kill_Rep_Clause (N : Node_Id) is | |
12099 | begin | |
12100 | pragma Assert (Ignore_Rep_Clauses); | |
783d035b AC |
12101 | |
12102 | -- Note: we use Replace rather than Rewrite, because we don't want | |
12103 | -- ASIS to be able to use Original_Node to dig out the (undecorated) | |
12104 | -- rep clause that is being replaced. | |
12105 | ||
39678b1c | 12106 | Replace (N, Make_Null_Statement (Sloc (N))); |
783d035b AC |
12107 | |
12108 | -- The null statement must be marked as not coming from source. This is | |
8b034336 | 12109 | -- so that ASIS ignores it, and also the back end does not expect bogus |
783d035b AC |
12110 | -- "from source" null statements in weird places (e.g. in declarative |
12111 | -- regions where such null statements are not allowed). | |
12112 | ||
12113 | Set_Comes_From_Source (N, False); | |
cf28c974 RD |
12114 | end Kill_Rep_Clause; |
12115 | ||
996ae0b0 RK |
12116 | ------------------ |
12117 | -- Minimum_Size -- | |
12118 | ------------------ | |
12119 | ||
12120 | function Minimum_Size | |
12121 | (T : Entity_Id; | |
b7e429ab | 12122 | Biased : Boolean := False) return Nat |
996ae0b0 RK |
12123 | is |
12124 | Lo : Uint := No_Uint; | |
12125 | Hi : Uint := No_Uint; | |
12126 | LoR : Ureal := No_Ureal; | |
12127 | HiR : Ureal := No_Ureal; | |
12128 | LoSet : Boolean := False; | |
12129 | HiSet : Boolean := False; | |
12130 | B : Uint; | |
12131 | S : Nat; | |
12132 | Ancest : Entity_Id; | |
07fc65c4 | 12133 | R_Typ : constant Entity_Id := Root_Type (T); |
996ae0b0 RK |
12134 | |
12135 | begin | |
12136 | -- If bad type, return 0 | |
12137 | ||
12138 | if T = Any_Type then | |
12139 | return 0; | |
12140 | ||
12141 | -- For generic types, just return zero. There cannot be any legitimate | |
12142 | -- need to know such a size, but this routine may be called with a | |
12143 | -- generic type as part of normal processing. | |
12144 | ||
dc06dd83 | 12145 | elsif Is_Generic_Type (R_Typ) or else R_Typ = Any_Type then |
996ae0b0 RK |
12146 | return 0; |
12147 | ||
ba0c6e47 | 12148 | -- Access types (cannot have size smaller than System.Address) |
996ae0b0 RK |
12149 | |
12150 | elsif Is_Access_Type (T) then | |
ba0c6e47 | 12151 | return System_Address_Size; |
996ae0b0 RK |
12152 | |
12153 | -- Floating-point types | |
12154 | ||
12155 | elsif Is_Floating_Point_Type (T) then | |
07fc65c4 | 12156 | return UI_To_Int (Esize (R_Typ)); |
996ae0b0 RK |
12157 | |
12158 | -- Discrete types | |
12159 | ||
12160 | elsif Is_Discrete_Type (T) then | |
12161 | ||
0503c53a RD |
12162 | -- The following loop is looking for the nearest compile time known |
12163 | -- bounds following the ancestor subtype chain. The idea is to find | |
12164 | -- the most restrictive known bounds information. | |
996ae0b0 RK |
12165 | |
12166 | Ancest := T; | |
12167 | loop | |
12168 | if Ancest = Any_Type or else Etype (Ancest) = Any_Type then | |
12169 | return 0; | |
12170 | end if; | |
12171 | ||
12172 | if not LoSet then | |
12173 | if Compile_Time_Known_Value (Type_Low_Bound (Ancest)) then | |
12174 | Lo := Expr_Rep_Value (Type_Low_Bound (Ancest)); | |
12175 | LoSet := True; | |
12176 | exit when HiSet; | |
12177 | end if; | |
12178 | end if; | |
12179 | ||
12180 | if not HiSet then | |
12181 | if Compile_Time_Known_Value (Type_High_Bound (Ancest)) then | |
12182 | Hi := Expr_Rep_Value (Type_High_Bound (Ancest)); | |
12183 | HiSet := True; | |
12184 | exit when LoSet; | |
12185 | end if; | |
12186 | end if; | |
12187 | ||
12188 | Ancest := Ancestor_Subtype (Ancest); | |
12189 | ||
12190 | if No (Ancest) then | |
12191 | Ancest := Base_Type (T); | |
12192 | ||
12193 | if Is_Generic_Type (Ancest) then | |
12194 | return 0; | |
12195 | end if; | |
12196 | end if; | |
12197 | end loop; | |
12198 | ||
12199 | -- Fixed-point types. We can't simply use Expr_Value to get the | |
0503c53a RD |
12200 | -- Corresponding_Integer_Value values of the bounds, since these do not |
12201 | -- get set till the type is frozen, and this routine can be called | |
12202 | -- before the type is frozen. Similarly the test for bounds being static | |
12203 | -- needs to include the case where we have unanalyzed real literals for | |
12204 | -- the same reason. | |
996ae0b0 RK |
12205 | |
12206 | elsif Is_Fixed_Point_Type (T) then | |
12207 | ||
0503c53a RD |
12208 | -- The following loop is looking for the nearest compile time known |
12209 | -- bounds following the ancestor subtype chain. The idea is to find | |
12210 | -- the most restrictive known bounds information. | |
996ae0b0 RK |
12211 | |
12212 | Ancest := T; | |
12213 | loop | |
12214 | if Ancest = Any_Type or else Etype (Ancest) = Any_Type then | |
12215 | return 0; | |
12216 | end if; | |
12217 | ||
800621e0 RD |
12218 | -- Note: In the following two tests for LoSet and HiSet, it may |
12219 | -- seem redundant to test for N_Real_Literal here since normally | |
12220 | -- one would assume that the test for the value being known at | |
12221 | -- compile time includes this case. However, there is a glitch. | |
12222 | -- If the real literal comes from folding a non-static expression, | |
12223 | -- then we don't consider any non- static expression to be known | |
12224 | -- at compile time if we are in configurable run time mode (needed | |
12225 | -- in some cases to give a clearer definition of what is and what | |
12226 | -- is not accepted). So the test is indeed needed. Without it, we | |
12227 | -- would set neither Lo_Set nor Hi_Set and get an infinite loop. | |
12228 | ||
996ae0b0 RK |
12229 | if not LoSet then |
12230 | if Nkind (Type_Low_Bound (Ancest)) = N_Real_Literal | |
12231 | or else Compile_Time_Known_Value (Type_Low_Bound (Ancest)) | |
12232 | then | |
12233 | LoR := Expr_Value_R (Type_Low_Bound (Ancest)); | |
12234 | LoSet := True; | |
12235 | exit when HiSet; | |
12236 | end if; | |
12237 | end if; | |
12238 | ||
12239 | if not HiSet then | |
12240 | if Nkind (Type_High_Bound (Ancest)) = N_Real_Literal | |
12241 | or else Compile_Time_Known_Value (Type_High_Bound (Ancest)) | |
12242 | then | |
12243 | HiR := Expr_Value_R (Type_High_Bound (Ancest)); | |
12244 | HiSet := True; | |
12245 | exit when LoSet; | |
12246 | end if; | |
12247 | end if; | |
12248 | ||
12249 | Ancest := Ancestor_Subtype (Ancest); | |
12250 | ||
12251 | if No (Ancest) then | |
12252 | Ancest := Base_Type (T); | |
12253 | ||
12254 | if Is_Generic_Type (Ancest) then | |
12255 | return 0; | |
12256 | end if; | |
12257 | end if; | |
12258 | end loop; | |
12259 | ||
12260 | Lo := UR_To_Uint (LoR / Small_Value (T)); | |
12261 | Hi := UR_To_Uint (HiR / Small_Value (T)); | |
12262 | ||
12263 | -- No other types allowed | |
12264 | ||
12265 | else | |
12266 | raise Program_Error; | |
12267 | end if; | |
12268 | ||
a5b62485 | 12269 | -- Fall through with Hi and Lo set. Deal with biased case |
996ae0b0 | 12270 | |
4ae23b62 AC |
12271 | if (Biased |
12272 | and then not Is_Fixed_Point_Type (T) | |
12273 | and then not (Is_Enumeration_Type (T) | |
12274 | and then Has_Non_Standard_Rep (T))) | |
996ae0b0 RK |
12275 | or else Has_Biased_Representation (T) |
12276 | then | |
12277 | Hi := Hi - Lo; | |
12278 | Lo := Uint_0; | |
12279 | end if; | |
12280 | ||
57d22af2 AC |
12281 | -- Null range case, size is always zero. We only do this in the discrete |
12282 | -- type case, since that's the odd case that came up. Probably we should | |
12283 | -- also do this in the fixed-point case, but doing so causes peculiar | |
12284 | -- gigi failures, and it is not worth worrying about this incredibly | |
12285 | -- marginal case (explicit null-range fixed-point type declarations)??? | |
12286 | ||
12287 | if Lo > Hi and then Is_Discrete_Type (T) then | |
12288 | S := 0; | |
12289 | ||
996ae0b0 | 12290 | -- Signed case. Note that we consider types like range 1 .. -1 to be |
0503c53a | 12291 | -- signed for the purpose of computing the size, since the bounds have |
f3d57416 | 12292 | -- to be accommodated in the base type. |
996ae0b0 | 12293 | |
57d22af2 | 12294 | elsif Lo < 0 or else Hi < 0 then |
996ae0b0 RK |
12295 | S := 1; |
12296 | B := Uint_1; | |
12297 | ||
638e383e JM |
12298 | -- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1)) |
12299 | -- Note that we accommodate the case where the bounds cross. This | |
996ae0b0 RK |
12300 | -- can happen either because of the way the bounds are declared |
12301 | -- or because of the algorithm in Freeze_Fixed_Point_Type. | |
12302 | ||
12303 | while Lo < -B | |
12304 | or else Hi < -B | |
12305 | or else Lo >= B | |
12306 | or else Hi >= B | |
12307 | loop | |
12308 | B := Uint_2 ** S; | |
12309 | S := S + 1; | |
12310 | end loop; | |
12311 | ||
12312 | -- Unsigned case | |
12313 | ||
12314 | else | |
12315 | -- If both bounds are positive, make sure that both are represen- | |
12316 | -- table in the case where the bounds are crossed. This can happen | |
12317 | -- either because of the way the bounds are declared, or because of | |
12318 | -- the algorithm in Freeze_Fixed_Point_Type. | |
12319 | ||
12320 | if Lo > Hi then | |
12321 | Hi := Lo; | |
12322 | end if; | |
12323 | ||
638e383e | 12324 | -- S = size, (can accommodate 0 .. (2**size - 1)) |
996ae0b0 RK |
12325 | |
12326 | S := 0; | |
12327 | while Hi >= Uint_2 ** S loop | |
12328 | S := S + 1; | |
12329 | end loop; | |
12330 | end if; | |
12331 | ||
12332 | return S; | |
12333 | end Minimum_Size; | |
12334 | ||
affbee12 RD |
12335 | --------------------------- |
12336 | -- New_Stream_Subprogram -- | |
12337 | --------------------------- | |
996ae0b0 | 12338 | |
affbee12 RD |
12339 | procedure New_Stream_Subprogram |
12340 | (N : Node_Id; | |
12341 | Ent : Entity_Id; | |
12342 | Subp : Entity_Id; | |
12343 | Nam : TSS_Name_Type) | |
996ae0b0 RK |
12344 | is |
12345 | Loc : constant Source_Ptr := Sloc (N); | |
fbf5a39b | 12346 | Sname : constant Name_Id := Make_TSS_Name (Base_Type (Ent), Nam); |
07fc65c4 | 12347 | Subp_Id : Entity_Id; |
996ae0b0 RK |
12348 | Subp_Decl : Node_Id; |
12349 | F : Entity_Id; | |
12350 | Etyp : Entity_Id; | |
12351 | ||
affbee12 RD |
12352 | Defer_Declaration : constant Boolean := |
12353 | Is_Tagged_Type (Ent) or else Is_Private_Type (Ent); | |
12354 | -- For a tagged type, there is a declaration for each stream attribute | |
12355 | -- at the freeze point, and we must generate only a completion of this | |
12356 | -- declaration. We do the same for private types, because the full view | |
12357 | -- might be tagged. Otherwise we generate a declaration at the point of | |
d4b56371 AC |
12358 | -- the attribute definition clause. If the attribute definition comes |
12359 | -- from an aspect specification the declaration is part of the freeze | |
12360 | -- actions of the type. | |
affbee12 | 12361 | |
07fc65c4 GB |
12362 | function Build_Spec return Node_Id; |
12363 | -- Used for declaration and renaming declaration, so that this is | |
12364 | -- treated as a renaming_as_body. | |
12365 | ||
12366 | ---------------- | |
12367 | -- Build_Spec -- | |
12368 | ---------------- | |
12369 | ||
b7e429ab | 12370 | function Build_Spec return Node_Id is |
affbee12 RD |
12371 | Out_P : constant Boolean := (Nam = TSS_Stream_Read); |
12372 | Formals : List_Id; | |
12373 | Spec : Node_Id; | |
e4494292 | 12374 | T_Ref : constant Node_Id := New_Occurrence_Of (Etyp, Loc); |
affbee12 | 12375 | |
07fc65c4 | 12376 | begin |
fbf5a39b | 12377 | Subp_Id := Make_Defining_Identifier (Loc, Sname); |
07fc65c4 | 12378 | |
affbee12 RD |
12379 | -- S : access Root_Stream_Type'Class |
12380 | ||
12381 | Formals := New_List ( | |
12382 | Make_Parameter_Specification (Loc, | |
12383 | Defining_Identifier => | |
12384 | Make_Defining_Identifier (Loc, Name_S), | |
12385 | Parameter_Type => | |
12386 | Make_Access_Definition (Loc, | |
12387 | Subtype_Mark => | |
e4494292 | 12388 | New_Occurrence_Of ( |
affbee12 RD |
12389 | Designated_Type (Etype (F)), Loc)))); |
12390 | ||
12391 | if Nam = TSS_Stream_Input then | |
ae05cdd6 RD |
12392 | Spec := |
12393 | Make_Function_Specification (Loc, | |
12394 | Defining_Unit_Name => Subp_Id, | |
12395 | Parameter_Specifications => Formals, | |
12396 | Result_Definition => T_Ref); | |
affbee12 RD |
12397 | else |
12398 | -- V : [out] T | |
07fc65c4 | 12399 | |
affbee12 RD |
12400 | Append_To (Formals, |
12401 | Make_Parameter_Specification (Loc, | |
12402 | Defining_Identifier => Make_Defining_Identifier (Loc, Name_V), | |
12403 | Out_Present => Out_P, | |
12404 | Parameter_Type => T_Ref)); | |
07fc65c4 | 12405 | |
bce79204 AC |
12406 | Spec := |
12407 | Make_Procedure_Specification (Loc, | |
12408 | Defining_Unit_Name => Subp_Id, | |
12409 | Parameter_Specifications => Formals); | |
affbee12 | 12410 | end if; |
07fc65c4 | 12411 | |
affbee12 RD |
12412 | return Spec; |
12413 | end Build_Spec; | |
996ae0b0 | 12414 | |
affbee12 | 12415 | -- Start of processing for New_Stream_Subprogram |
996ae0b0 | 12416 | |
affbee12 RD |
12417 | begin |
12418 | F := First_Formal (Subp); | |
12419 | ||
12420 | if Ekind (Subp) = E_Procedure then | |
12421 | Etyp := Etype (Next_Formal (F)); | |
996ae0b0 | 12422 | else |
affbee12 | 12423 | Etyp := Etype (Subp); |
996ae0b0 | 12424 | end if; |
07fc65c4 | 12425 | |
affbee12 RD |
12426 | -- Prepare subprogram declaration and insert it as an action on the |
12427 | -- clause node. The visibility for this entity is used to test for | |
12428 | -- visibility of the attribute definition clause (in the sense of | |
12429 | -- 8.3(23) as amended by AI-195). | |
fbf5a39b | 12430 | |
affbee12 | 12431 | if not Defer_Declaration then |
07fc65c4 GB |
12432 | Subp_Decl := |
12433 | Make_Subprogram_Declaration (Loc, | |
12434 | Specification => Build_Spec); | |
affbee12 RD |
12435 | |
12436 | -- For a tagged type, there is always a visible declaration for each | |
8f7770f9 | 12437 | -- stream TSS (it is a predefined primitive operation), and the |
affbee12 RD |
12438 | -- completion of this declaration occurs at the freeze point, which is |
12439 | -- not always visible at places where the attribute definition clause is | |
12440 | -- visible. So, we create a dummy entity here for the purpose of | |
12441 | -- tracking the visibility of the attribute definition clause itself. | |
12442 | ||
12443 | else | |
12444 | Subp_Id := | |
7675ad4f | 12445 | Make_Defining_Identifier (Loc, New_External_Name (Sname, 'V')); |
affbee12 RD |
12446 | Subp_Decl := |
12447 | Make_Object_Declaration (Loc, | |
12448 | Defining_Identifier => Subp_Id, | |
12449 | Object_Definition => New_Occurrence_Of (Standard_Boolean, Loc)); | |
07fc65c4 GB |
12450 | end if; |
12451 | ||
d4b56371 AC |
12452 | if not Defer_Declaration |
12453 | and then From_Aspect_Specification (N) | |
12454 | and then Has_Delayed_Freeze (Ent) | |
12455 | then | |
12456 | Append_Freeze_Action (Ent, Subp_Decl); | |
12457 | ||
12458 | else | |
12459 | Insert_Action (N, Subp_Decl); | |
12460 | Set_Entity (N, Subp_Id); | |
12461 | end if; | |
affbee12 | 12462 | |
996ae0b0 RK |
12463 | Subp_Decl := |
12464 | Make_Subprogram_Renaming_Declaration (Loc, | |
07fc65c4 | 12465 | Specification => Build_Spec, |
c70cf4f8 | 12466 | Name => New_Occurrence_Of (Subp, Loc)); |
996ae0b0 | 12467 | |
affbee12 | 12468 | if Defer_Declaration then |
996ae0b0 | 12469 | Set_TSS (Base_Type (Ent), Subp_Id); |
d4b56371 | 12470 | |
996ae0b0 | 12471 | else |
d4b56371 AC |
12472 | if From_Aspect_Specification (N) then |
12473 | Append_Freeze_Action (Ent, Subp_Decl); | |
d4b56371 AC |
12474 | else |
12475 | Insert_Action (N, Subp_Decl); | |
12476 | end if; | |
12477 | ||
996ae0b0 RK |
12478 | Copy_TSS (Subp_Id, Base_Type (Ent)); |
12479 | end if; | |
affbee12 | 12480 | end New_Stream_Subprogram; |
996ae0b0 | 12481 | |
2401c98f HK |
12482 | -------------- |
12483 | -- Pop_Type -- | |
12484 | -------------- | |
12485 | ||
12486 | procedure Pop_Type (E : Entity_Id) is | |
12487 | begin | |
12488 | if Ekind (E) = E_Record_Type and then E = Current_Scope then | |
12489 | End_Scope; | |
12490 | ||
12491 | elsif Is_Type (E) | |
12492 | and then Has_Discriminants (E) | |
12493 | and then Nkind (Parent (E)) /= N_Subtype_Declaration | |
12494 | then | |
12495 | Uninstall_Discriminants (E); | |
12496 | Pop_Scope; | |
12497 | end if; | |
12498 | end Pop_Type; | |
12499 | ||
5f531fef ES |
12500 | --------------- |
12501 | -- Push_Type -- | |
12502 | --------------- | |
77a40ec1 | 12503 | |
5f531fef ES |
12504 | procedure Push_Type (E : Entity_Id) is |
12505 | Comp : Entity_Id; | |
2401c98f | 12506 | |
77a40ec1 | 12507 | begin |
5f531fef | 12508 | if Ekind (E) = E_Record_Type then |
77a40ec1 | 12509 | Push_Scope (E); |
2401c98f | 12510 | |
5f531fef ES |
12511 | Comp := First_Component (E); |
12512 | while Present (Comp) loop | |
12513 | Install_Entity (Comp); | |
12514 | Next_Component (Comp); | |
12515 | end loop; | |
77a40ec1 | 12516 | |
5f531fef | 12517 | if Has_Discriminants (E) then |
77a40ec1 AC |
12518 | Install_Discriminants (E); |
12519 | end if; | |
5f531fef ES |
12520 | |
12521 | elsif Is_Type (E) | |
2401c98f HK |
12522 | and then Has_Discriminants (E) |
12523 | and then Nkind (Parent (E)) /= N_Subtype_Declaration | |
5f531fef ES |
12524 | then |
12525 | Push_Scope (E); | |
12526 | Install_Discriminants (E); | |
77a40ec1 | 12527 | end if; |
5f531fef | 12528 | end Push_Type; |
77a40ec1 | 12529 | |
5067f3a0 PMR |
12530 | ----------------------------------- |
12531 | -- Register_Address_Clause_Check -- | |
12532 | ----------------------------------- | |
12533 | ||
12534 | procedure Register_Address_Clause_Check | |
12535 | (N : Node_Id; | |
12536 | X : Entity_Id; | |
12537 | A : Uint; | |
12538 | Y : Entity_Id; | |
12539 | Off : Boolean) | |
12540 | is | |
12541 | ACS : constant Boolean := Scope_Suppress.Suppress (Alignment_Check); | |
12542 | begin | |
12543 | Address_Clause_Checks.Append ((N, X, A, Y, Off, ACS)); | |
12544 | end Register_Address_Clause_Check; | |
12545 | ||
996ae0b0 RK |
12546 | ------------------------ |
12547 | -- Rep_Item_Too_Early -- | |
12548 | ------------------------ | |
12549 | ||
0da2c8ac | 12550 | function Rep_Item_Too_Early (T : Entity_Id; N : Node_Id) return Boolean is |
c7854dbd JM |
12551 | function Has_Generic_Parent (E : Entity_Id) return Boolean; |
12552 | -- Return True if any ancestor is a generic type | |
12553 | ||
12554 | function Has_Generic_Parent (E : Entity_Id) return Boolean is | |
12555 | Ancestor_Type : Entity_Id := Etype (E); | |
12556 | ||
12557 | begin | |
12558 | while Present (Ancestor_Type) | |
12559 | and then not Is_Generic_Type (Ancestor_Type) | |
12560 | and then Etype (Ancestor_Type) /= Ancestor_Type | |
12561 | loop | |
12562 | Ancestor_Type := Etype (Ancestor_Type); | |
12563 | end loop; | |
12564 | ||
12565 | return Present (Ancestor_Type) | |
12566 | and then Is_Generic_Type (Ancestor_Type); | |
12567 | end Has_Generic_Parent; | |
12568 | ||
996ae0b0 | 12569 | begin |
affbee12 | 12570 | -- Cannot apply non-operational rep items to generic types |
996ae0b0 | 12571 | |
07fc65c4 GB |
12572 | if Is_Operational_Item (N) then |
12573 | return False; | |
12574 | ||
12575 | elsif Is_Type (T) | |
c7854dbd | 12576 | and then Has_Generic_Parent (T) |
5f6061af AC |
12577 | and then (Nkind (N) /= N_Pragma |
12578 | or else Get_Pragma_Id (N) /= Pragma_Convention) | |
996ae0b0 | 12579 | then |
ed2233dc | 12580 | Error_Msg_N ("representation item not allowed for generic type", N); |
996ae0b0 RK |
12581 | return True; |
12582 | end if; | |
12583 | ||
0503c53a | 12584 | -- Otherwise check for incomplete type |
996ae0b0 RK |
12585 | |
12586 | if Is_Incomplete_Or_Private_Type (T) | |
12587 | and then No (Underlying_Type (T)) | |
a01b9df6 AC |
12588 | and then |
12589 | (Nkind (N) /= N_Pragma | |
d2d9cc22 | 12590 | or else Get_Pragma_Id (N) /= Pragma_Import) |
996ae0b0 RK |
12591 | then |
12592 | Error_Msg_N | |
12593 | ("representation item must be after full type declaration", N); | |
12594 | return True; | |
12595 | ||
f3d57416 | 12596 | -- If the type has incomplete components, a representation clause is |
996ae0b0 RK |
12597 | -- illegal but stream attributes and Convention pragmas are correct. |
12598 | ||
12599 | elsif Has_Private_Component (T) then | |
07fc65c4 | 12600 | if Nkind (N) = N_Pragma then |
996ae0b0 | 12601 | return False; |
616547fa | 12602 | |
996ae0b0 RK |
12603 | else |
12604 | Error_Msg_N | |
12605 | ("representation item must appear after type is fully defined", | |
12606 | N); | |
12607 | return True; | |
12608 | end if; | |
12609 | else | |
12610 | return False; | |
12611 | end if; | |
12612 | end Rep_Item_Too_Early; | |
12613 | ||
12614 | ----------------------- | |
12615 | -- Rep_Item_Too_Late -- | |
12616 | ----------------------- | |
12617 | ||
12618 | function Rep_Item_Too_Late | |
12619 | (T : Entity_Id; | |
12620 | N : Node_Id; | |
b7e429ab | 12621 | FOnly : Boolean := False) return Boolean |
996ae0b0 | 12622 | is |
5f531fef ES |
12623 | function Is_Derived_Type_With_Constraint return Boolean; |
12624 | -- Check whether T is a derived type with an explicit constraint, in | |
12625 | -- which case the constraint has frozen the type and the item is too | |
12626 | -- late. This compensates for the fact that for derived scalar types | |
12627 | -- we freeze the base type unconditionally on account of a long-standing | |
12628 | -- issue in gigi. | |
12629 | ||
84c0a895 AC |
12630 | procedure No_Type_Rep_Item; |
12631 | -- Output message indicating that no type-related aspects can be | |
12632 | -- specified due to some property of the parent type. | |
12633 | ||
996ae0b0 | 12634 | procedure Too_Late; |
84c0a895 AC |
12635 | -- Output message for an aspect being specified too late |
12636 | ||
12637 | -- Note that neither of the above errors is considered a serious one, | |
12638 | -- since the effect is simply that we ignore the representation clause | |
12639 | -- in these cases. | |
ab01e614 AC |
12640 | -- Is this really true? In any case if we make this change we must |
12641 | -- document the requirement in the spec of Rep_Item_Too_Late that | |
12642 | -- if True is returned, then the rep item must be completely ignored??? | |
84c0a895 | 12643 | |
5f531fef ES |
12644 | -------------------------------------- |
12645 | -- Is_Derived_Type_With_Constraint -- | |
12646 | -------------------------------------- | |
12647 | ||
12648 | function Is_Derived_Type_With_Constraint return Boolean is | |
12649 | Decl : constant Node_Id := Declaration_Node (T); | |
2401c98f | 12650 | |
5f531fef ES |
12651 | begin |
12652 | return Is_Derived_Type (T) | |
12653 | and then Is_Frozen (Base_Type (T)) | |
12654 | and then Is_Enumeration_Type (T) | |
12655 | and then False | |
12656 | and then Nkind (N) = N_Enumeration_Representation_Clause | |
12657 | and then Nkind (Decl) = N_Subtype_Declaration | |
12658 | and then not Is_Entity_Name (Subtype_Indication (Decl)); | |
12659 | end Is_Derived_Type_With_Constraint; | |
12660 | ||
84c0a895 AC |
12661 | ---------------------- |
12662 | -- No_Type_Rep_Item -- | |
12663 | ---------------------- | |
12664 | ||
12665 | procedure No_Type_Rep_Item is | |
12666 | begin | |
12667 | Error_Msg_N ("|type-related representation item not permitted!", N); | |
12668 | end No_Type_Rep_Item; | |
1c6c6771 ES |
12669 | |
12670 | -------------- | |
12671 | -- Too_Late -- | |
12672 | -------------- | |
996ae0b0 RK |
12673 | |
12674 | procedure Too_Late is | |
12675 | begin | |
5b75bf57 AC |
12676 | -- Other compilers seem more relaxed about rep items appearing too |
12677 | -- late. Since analysis tools typically don't care about rep items | |
12678 | -- anyway, no reason to be too strict about this. | |
12679 | ||
303fbb20 AC |
12680 | if not Relaxed_RM_Semantics then |
12681 | Error_Msg_N ("|representation item appears too late!", N); | |
12682 | end if; | |
996ae0b0 RK |
12683 | end Too_Late; |
12684 | ||
2401c98f HK |
12685 | -- Local variables |
12686 | ||
12687 | Parent_Type : Entity_Id; | |
12688 | S : Entity_Id; | |
12689 | ||
996ae0b0 RK |
12690 | -- Start of processing for Rep_Item_Too_Late |
12691 | ||
12692 | begin | |
51e641f8 | 12693 | -- First make sure entity is not frozen (RM 13.1(9)) |
996ae0b0 | 12694 | |
5f531fef | 12695 | if (Is_Frozen (T) |
2401c98f HK |
12696 | or else (Is_Type (T) |
12697 | and then Is_Derived_Type_With_Constraint)) | |
51e641f8 AC |
12698 | |
12699 | -- Exclude imported types, which may be frozen if they appear in a | |
12700 | -- representation clause for a local type. | |
12701 | ||
7b56a91b | 12702 | and then not From_Limited_With (T) |
51e641f8 | 12703 | |
303fbb20 | 12704 | -- Exclude generated entities (not coming from source). The common |
51e641f8 AC |
12705 | -- case is when we generate a renaming which prematurely freezes the |
12706 | -- renamed internal entity, but we still want to be able to set copies | |
12707 | -- of attribute values such as Size/Alignment. | |
12708 | ||
12709 | and then Comes_From_Source (T) | |
996ae0b0 | 12710 | then |
7e22a38c AC |
12711 | -- A self-referential aspect is illegal if it forces freezing the |
12712 | -- entity before the corresponding pragma has been analyzed. | |
12713 | ||
12714 | if Nkind_In (N, N_Attribute_Definition_Clause, N_Pragma) | |
12715 | and then From_Aspect_Specification (N) | |
12716 | then | |
12717 | Error_Msg_NE | |
e4d04166 | 12718 | ("aspect specification causes premature freezing of&", N, T); |
7e22a38c AC |
12719 | Set_Has_Delayed_Freeze (T, False); |
12720 | return True; | |
12721 | end if; | |
12722 | ||
996ae0b0 RK |
12723 | Too_Late; |
12724 | S := First_Subtype (T); | |
12725 | ||
12726 | if Present (Freeze_Node (S)) then | |
ab01e614 AC |
12727 | if not Relaxed_RM_Semantics then |
12728 | Error_Msg_NE | |
12729 | ("??no more representation items for }", Freeze_Node (S), S); | |
12730 | end if; | |
996ae0b0 RK |
12731 | end if; |
12732 | ||
12733 | return True; | |
12734 | ||
1fb63e89 | 12735 | -- Check for case of untagged derived type whose parent either has |
84c0a895 AC |
12736 | -- primitive operations, or is a by reference type (RM 13.1(10)). In |
12737 | -- this case we do not output a Too_Late message, since there is no | |
12738 | -- earlier point where the rep item could be placed to make it legal. | |
996ae0b0 RK |
12739 | |
12740 | elsif Is_Type (T) | |
12741 | and then not FOnly | |
12742 | and then Is_Derived_Type (T) | |
12743 | and then not Is_Tagged_Type (T) | |
12744 | then | |
12745 | Parent_Type := Etype (Base_Type (T)); | |
12746 | ||
12747 | if Has_Primitive_Operations (Parent_Type) then | |
84c0a895 | 12748 | No_Type_Rep_Item; |
ab01e614 AC |
12749 | |
12750 | if not Relaxed_RM_Semantics then | |
12751 | Error_Msg_NE | |
12752 | ("\parent type & has primitive operations!", N, Parent_Type); | |
12753 | end if; | |
12754 | ||
996ae0b0 RK |
12755 | return True; |
12756 | ||
12757 | elsif Is_By_Reference_Type (Parent_Type) then | |
84c0a895 | 12758 | No_Type_Rep_Item; |
ab01e614 AC |
12759 | |
12760 | if not Relaxed_RM_Semantics then | |
12761 | Error_Msg_NE | |
12762 | ("\parent type & is a by reference type!", N, Parent_Type); | |
12763 | end if; | |
12764 | ||
996ae0b0 RK |
12765 | return True; |
12766 | end if; | |
12767 | end if; | |
12768 | ||
ab01e614 AC |
12769 | -- No error, but one more warning to consider. The RM (surprisingly) |
12770 | -- allows this pattern: | |
12771 | ||
12772 | -- type S is ... | |
12773 | -- primitive operations for S | |
12774 | -- type R is new S; | |
12775 | -- rep clause for S | |
12776 | ||
12777 | -- Meaning that calls on the primitive operations of S for values of | |
12778 | -- type R may require possibly expensive implicit conversion operations. | |
12779 | -- This is not an error, but is worth a warning. | |
12780 | ||
12781 | if not Relaxed_RM_Semantics and then Is_Type (T) then | |
12782 | declare | |
12783 | DTL : constant Entity_Id := Derived_Type_Link (Base_Type (T)); | |
12784 | ||
12785 | begin | |
12786 | if Present (DTL) | |
12787 | and then Has_Primitive_Operations (Base_Type (T)) | |
12788 | ||
12789 | -- For now, do not generate this warning for the case of aspect | |
12790 | -- specification using Ada 2012 syntax, since we get wrong | |
12791 | -- messages we do not understand. The whole business of derived | |
12792 | -- types and rep items seems a bit confused when aspects are | |
12793 | -- used, since the aspects are not evaluated till freeze time. | |
12794 | ||
12795 | and then not From_Aspect_Specification (N) | |
12796 | then | |
12797 | Error_Msg_Sloc := Sloc (DTL); | |
12798 | Error_Msg_N | |
12799 | ("representation item for& appears after derived type " | |
12800 | & "declaration#??", N); | |
12801 | Error_Msg_NE | |
12802 | ("\may result in implicit conversions for primitive " | |
12803 | & "operations of&??", N, T); | |
12804 | Error_Msg_NE | |
12805 | ("\to change representations when called with arguments " | |
12806 | & "of type&??", N, DTL); | |
12807 | end if; | |
12808 | end; | |
12809 | end if; | |
12810 | ||
800621e0 RD |
12811 | -- No error, link item into head of chain of rep items for the entity, |
12812 | -- but avoid chaining if we have an overloadable entity, and the pragma | |
12813 | -- is one that can apply to multiple overloaded entities. | |
12814 | ||
616547fa | 12815 | if Is_Overloadable (T) and then Nkind (N) = N_Pragma then |
0503c53a | 12816 | declare |
6e759c2a | 12817 | Pname : constant Name_Id := Pragma_Name (N); |
0503c53a | 12818 | begin |
b69cd36a AC |
12819 | if Nam_In (Pname, Name_Convention, Name_Import, Name_Export, |
12820 | Name_External, Name_Interface) | |
0503c53a RD |
12821 | then |
12822 | return False; | |
12823 | end if; | |
12824 | end; | |
800621e0 RD |
12825 | end if; |
12826 | ||
0503c53a | 12827 | Record_Rep_Item (T, N); |
996ae0b0 RK |
12828 | return False; |
12829 | end Rep_Item_Too_Late; | |
12830 | ||
3b097d11 AC |
12831 | ------------------------------------- |
12832 | -- Replace_Type_References_Generic -- | |
12833 | ------------------------------------- | |
12834 | ||
8b034336 AC |
12835 | procedure Replace_Type_References_Generic (N : Node_Id; T : Entity_Id) is |
12836 | TName : constant Name_Id := Chars (T); | |
3b097d11 | 12837 | |
3ddfabe3 | 12838 | function Replace_Type_Ref (N : Node_Id) return Traverse_Result; |
3b097d11 AC |
12839 | -- Processes a single node in the traversal procedure below, checking |
12840 | -- if node N should be replaced, and if so, doing the replacement. | |
12841 | ||
9e3be36e ES |
12842 | function Visible_Component (Comp : Name_Id) return Entity_Id; |
12843 | -- Given an identifier in the expression, check whether there is a | |
12844 | -- discriminant or component of the type that is directy visible, and | |
12845 | -- rewrite it as the corresponding selected component of the formal of | |
12846 | -- the subprogram. The entity is located by a sequential search, which | |
12847 | -- seems acceptable given the typical size of component lists and check | |
12848 | -- expressions. Possible optimization ??? | |
12849 | ||
3ddfabe3 AC |
12850 | ---------------------- |
12851 | -- Replace_Type_Ref -- | |
12852 | ---------------------- | |
3b097d11 | 12853 | |
3ddfabe3 | 12854 | function Replace_Type_Ref (N : Node_Id) return Traverse_Result is |
9e3be36e | 12855 | Loc : constant Source_Ptr := Sloc (N); |
3b097d11 | 12856 | |
9e3be36e | 12857 | procedure Add_Prefix (Ref : Node_Id; Comp : Entity_Id); |
20250fb8 AC |
12858 | -- Add the proper prefix to a reference to a component of the type |
12859 | -- when it is not already a selected component. | |
9e3be36e ES |
12860 | |
12861 | ---------------- | |
12862 | -- Add_Prefix -- | |
12863 | ---------------- | |
3b097d11 | 12864 | |
9e3be36e ES |
12865 | procedure Add_Prefix (Ref : Node_Id; Comp : Entity_Id) is |
12866 | begin | |
12867 | Rewrite (Ref, | |
12868 | Make_Selected_Component (Loc, | |
20250fb8 | 12869 | Prefix => New_Occurrence_Of (T, Loc), |
9e3be36e ES |
12870 | Selector_Name => New_Occurrence_Of (Comp, Loc))); |
12871 | Replace_Type_Reference (Prefix (Ref)); | |
12872 | end Add_Prefix; | |
12873 | ||
20250fb8 AC |
12874 | -- Local variables |
12875 | ||
12876 | Comp : Entity_Id; | |
12877 | Pref : Node_Id; | |
12878 | Scop : Entity_Id; | |
12879 | ||
9e3be36e ES |
12880 | -- Start of processing for Replace_Type_Ref |
12881 | ||
12882 | begin | |
3b097d11 AC |
12883 | if Nkind (N) = N_Identifier then |
12884 | ||
3ddfabe3 AC |
12885 | -- If not the type name, check whether it is a reference to some |
12886 | -- other type, which must be frozen before the predicate function | |
12887 | -- is analyzed, i.e. before the freeze node of the type to which | |
12888 | -- the predicate applies. | |
3b097d11 AC |
12889 | |
12890 | if Chars (N) /= TName then | |
8b034336 | 12891 | if Present (Current_Entity (N)) |
497a660d | 12892 | and then Is_Type (Current_Entity (N)) |
8b034336 AC |
12893 | then |
12894 | Freeze_Before (Freeze_Node (T), Current_Entity (N)); | |
12895 | end if; | |
12896 | ||
9e3be36e ES |
12897 | -- The components of the type are directly visible and can |
12898 | -- be referenced without a prefix. | |
12899 | ||
12900 | if Nkind (Parent (N)) = N_Selected_Component then | |
12901 | null; | |
12902 | ||
12903 | -- In expression C (I), C may be a directly visible function | |
12904 | -- or a visible component that has an array type. Disambiguate | |
12905 | -- by examining the component type. | |
12906 | ||
12907 | elsif Nkind (Parent (N)) = N_Indexed_Component | |
12908 | and then N = Prefix (Parent (N)) | |
12909 | then | |
20250fb8 | 12910 | Comp := Visible_Component (Chars (N)); |
9e3be36e | 12911 | |
20250fb8 AC |
12912 | if Present (Comp) and then Is_Array_Type (Etype (Comp)) then |
12913 | Add_Prefix (N, Comp); | |
9e3be36e ES |
12914 | end if; |
12915 | ||
12916 | else | |
20250fb8 | 12917 | Comp := Visible_Component (Chars (N)); |
9e3be36e | 12918 | |
20250fb8 AC |
12919 | if Present (Comp) then |
12920 | Add_Prefix (N, Comp); | |
9e3be36e ES |
12921 | end if; |
12922 | end if; | |
12923 | ||
3b097d11 AC |
12924 | return Skip; |
12925 | ||
98b779ae PMR |
12926 | -- Otherwise do the replacement if this is not a qualified |
12927 | -- reference to a homograph of the type itself. Note that the | |
12928 | -- current instance could not appear in such a context, e.g. | |
12929 | -- the prefix of a type conversion. | |
3b097d11 AC |
12930 | |
12931 | else | |
98b779ae PMR |
12932 | if Nkind (Parent (N)) /= N_Selected_Component |
12933 | or else N /= Selector_Name (Parent (N)) | |
12934 | then | |
12935 | Replace_Type_Reference (N); | |
12936 | end if; | |
12937 | ||
3b097d11 AC |
12938 | return Skip; |
12939 | end if; | |
12940 | ||
a2fd4f0e ES |
12941 | -- Case of selected component, which may be a subcomponent of the |
12942 | -- current instance, or an expanded name which is still unanalyzed. | |
3b097d11 AC |
12943 | |
12944 | elsif Nkind (N) = N_Selected_Component then | |
12945 | ||
98b779ae | 12946 | -- If selector name is not our type, keep going (we might still |
27d357ca HK |
12947 | -- have an occurrence of the type in the prefix). If it is a |
12948 | -- subcomponent of the current entity, add prefix. | |
3b097d11 AC |
12949 | |
12950 | if Nkind (Selector_Name (N)) /= N_Identifier | |
12951 | or else Chars (Selector_Name (N)) /= TName | |
12952 | then | |
a2fd4f0e ES |
12953 | if Nkind (Prefix (N)) = N_Identifier then |
12954 | Comp := Visible_Component (Chars (Prefix (N))); | |
12955 | ||
12956 | if Present (Comp) then | |
12957 | Add_Prefix (Prefix (N), Comp); | |
12958 | end if; | |
12959 | end if; | |
12960 | ||
3b097d11 AC |
12961 | return OK; |
12962 | ||
12963 | -- Selector name is our type, check qualification | |
12964 | ||
12965 | else | |
12966 | -- Loop through scopes and prefixes, doing comparison | |
12967 | ||
20250fb8 AC |
12968 | Scop := Current_Scope; |
12969 | Pref := Prefix (N); | |
3b097d11 AC |
12970 | loop |
12971 | -- Continue if no more scopes or scope with no name | |
12972 | ||
20250fb8 | 12973 | if No (Scop) or else Nkind (Scop) not in N_Has_Chars then |
3b097d11 AC |
12974 | return OK; |
12975 | end if; | |
12976 | ||
3ddfabe3 AC |
12977 | -- Do replace if prefix is an identifier matching the scope |
12978 | -- that we are currently looking at. | |
3b097d11 | 12979 | |
20250fb8 AC |
12980 | if Nkind (Pref) = N_Identifier |
12981 | and then Chars (Pref) = Chars (Scop) | |
3b097d11 AC |
12982 | then |
12983 | Replace_Type_Reference (N); | |
12984 | return Skip; | |
12985 | end if; | |
12986 | ||
3ddfabe3 AC |
12987 | -- Go check scope above us if prefix is itself of the form |
12988 | -- of a selected component, whose selector matches the scope | |
12989 | -- we are currently looking at. | |
3b097d11 | 12990 | |
20250fb8 AC |
12991 | if Nkind (Pref) = N_Selected_Component |
12992 | and then Nkind (Selector_Name (Pref)) = N_Identifier | |
12993 | and then Chars (Selector_Name (Pref)) = Chars (Scop) | |
3b097d11 | 12994 | then |
20250fb8 AC |
12995 | Scop := Scope (Scop); |
12996 | Pref := Prefix (Pref); | |
3b097d11 AC |
12997 | |
12998 | -- For anything else, we don't have a match, so keep on | |
12999 | -- going, there are still some weird cases where we may | |
13000 | -- still have a replacement within the prefix. | |
13001 | ||
13002 | else | |
13003 | return OK; | |
13004 | end if; | |
13005 | end loop; | |
13006 | end if; | |
13007 | ||
e477d718 | 13008 | -- Continue for any other node kind |
3b097d11 AC |
13009 | |
13010 | else | |
13011 | return OK; | |
13012 | end if; | |
3ddfabe3 AC |
13013 | end Replace_Type_Ref; |
13014 | ||
20250fb8 AC |
13015 | procedure Replace_Type_Refs is new Traverse_Proc (Replace_Type_Ref); |
13016 | ||
9e3be36e ES |
13017 | ----------------------- |
13018 | -- Visible_Component -- | |
13019 | ----------------------- | |
13020 | ||
13021 | function Visible_Component (Comp : Name_Id) return Entity_Id is | |
13022 | E : Entity_Id; | |
20250fb8 | 13023 | |
9e3be36e | 13024 | begin |
d268147d ES |
13025 | -- Types with nameable components are records and discriminated |
13026 | -- private types. | |
13027 | ||
13028 | if Ekind (T) = E_Record_Type | |
13029 | or else (Is_Private_Type (T) and then Has_Discriminants (T)) | |
13030 | then | |
9e3be36e ES |
13031 | E := First_Entity (T); |
13032 | while Present (E) loop | |
20250fb8 | 13033 | if Comes_From_Source (E) and then Chars (E) = Comp then |
9e3be36e ES |
13034 | return E; |
13035 | end if; | |
13036 | ||
13037 | Next_Entity (E); | |
13038 | end loop; | |
9e3be36e | 13039 | end if; |
d268147d | 13040 | |
611d5e3c | 13041 | -- Nothing by that name, or the type has no components |
d268147d ES |
13042 | |
13043 | return Empty; | |
9e3be36e ES |
13044 | end Visible_Component; |
13045 | ||
20250fb8 | 13046 | -- Start of processing for Replace_Type_References_Generic |
3b097d11 AC |
13047 | |
13048 | begin | |
13049 | Replace_Type_Refs (N); | |
13050 | end Replace_Type_References_Generic; | |
13051 | ||
f06f5f6b AC |
13052 | -------------------------------- |
13053 | -- Resolve_Aspect_Expressions -- | |
13054 | -------------------------------- | |
13055 | ||
13056 | procedure Resolve_Aspect_Expressions (E : Entity_Id) is | |
6905a049 AC |
13057 | function Resolve_Name (N : Node_Id) return Traverse_Result; |
13058 | -- Verify that all identifiers in the expression, with the exception | |
13059 | -- of references to the current entity, denote visible entities. This | |
13060 | -- is done only to detect visibility errors, as the expression will be | |
13061 | -- properly analyzed/expanded during analysis of the predicate function | |
d74716b3 AC |
13062 | -- body. We omit quantified expressions from this test, given that they |
13063 | -- introduce a local identifier that would require proper expansion to | |
13064 | -- handle properly. | |
6905a049 | 13065 | |
da9683f4 AC |
13066 | -- In ASIS_Mode we preserve the entity in the source because there is |
13067 | -- no subsequent expansion to decorate the tree. | |
13068 | ||
6905a049 AC |
13069 | ------------------ |
13070 | -- Resolve_Name -- | |
13071 | ------------------ | |
13072 | ||
13073 | function Resolve_Name (N : Node_Id) return Traverse_Result is | |
0691ed6b | 13074 | Dummy : Traverse_Result; |
1155ae01 | 13075 | |
6905a049 AC |
13076 | begin |
13077 | if Nkind (N) = N_Selected_Component then | |
13078 | if Nkind (Prefix (N)) = N_Identifier | |
13079 | and then Chars (Prefix (N)) /= Chars (E) | |
13080 | then | |
a14bbbb4 | 13081 | Find_Selected_Component (N); |
6905a049 | 13082 | end if; |
2cc7967f | 13083 | |
6905a049 AC |
13084 | return Skip; |
13085 | ||
e98cd75f PMR |
13086 | -- Resolve identifiers that are not selectors in parameter |
13087 | -- associations (these are never resolved by visibility). | |
13088 | ||
13089 | elsif Nkind (N) = N_Identifier | |
13090 | and then Chars (N) /= Chars (E) | |
13091 | and then (Nkind (Parent (N)) /= N_Parameter_Association | |
13092 | or else N /= Selector_Name (Parent (N))) | |
13093 | then | |
6905a049 | 13094 | Find_Direct_Name (N); |
da9683f4 | 13095 | |
ae5115dd AC |
13096 | -- In ASIS mode we must analyze overloaded identifiers to ensure |
13097 | -- their correct decoration because expansion is disabled (and | |
13098 | -- the expansion of freeze nodes takes care of resolving aspect | |
13099 | -- expressions). | |
13100 | ||
13101 | if ASIS_Mode then | |
13102 | if Is_Overloaded (N) then | |
13103 | Analyze (Parent (N)); | |
13104 | end if; | |
13105 | else | |
da9683f4 AC |
13106 | Set_Entity (N, Empty); |
13107 | end if; | |
d74716b3 | 13108 | |
0691ed6b AC |
13109 | -- The name is component association needs no resolution. |
13110 | ||
13111 | elsif Nkind (N) = N_Component_Association then | |
13112 | Dummy := Resolve_Name (Expression (N)); | |
13113 | return Skip; | |
13114 | ||
d74716b3 AC |
13115 | elsif Nkind (N) = N_Quantified_Expression then |
13116 | return Skip; | |
6905a049 AC |
13117 | end if; |
13118 | ||
13119 | return OK; | |
13120 | end Resolve_Name; | |
13121 | ||
13122 | procedure Resolve_Aspect_Expression is new Traverse_Proc (Resolve_Name); | |
13123 | ||
1155ae01 AC |
13124 | -- Local variables |
13125 | ||
66f95f60 AC |
13126 | ASN : Node_Id := First_Rep_Item (E); |
13127 | ||
2cc7967f AC |
13128 | -- Start of processing for Resolve_Aspect_Expressions |
13129 | ||
f06f5f6b | 13130 | begin |
5f531fef ES |
13131 | if No (ASN) then |
13132 | return; | |
13133 | end if; | |
3ddfabe3 | 13134 | |
66f95f60 AC |
13135 | while Present (ASN) loop |
13136 | if Nkind (ASN) = N_Aspect_Specification and then Entity (ASN) = E then | |
13137 | declare | |
13138 | A_Id : constant Aspect_Id := Get_Aspect_Id (ASN); | |
13139 | Expr : constant Node_Id := Expression (ASN); | |
643827e9 | 13140 | |
66f95f60 AC |
13141 | begin |
13142 | case A_Id is | |
643827e9 | 13143 | |
66f95f60 AC |
13144 | -- For now we only deal with aspects that do not generate |
13145 | -- subprograms, or that may mention current instances of | |
13146 | -- types. These will require special handling (???TBD). | |
f06f5f6b | 13147 | |
66f95f60 AC |
13148 | when Aspect_Invariant |
13149 | | Aspect_Predicate | |
13150 | | Aspect_Predicate_Failure | |
13151 | => | |
13152 | null; | |
f06f5f6b | 13153 | |
66f95f60 AC |
13154 | when Aspect_Dynamic_Predicate |
13155 | | Aspect_Static_Predicate | |
13156 | => | |
13157 | -- Build predicate function specification and preanalyze | |
0691ed6b AC |
13158 | -- expression after type replacement. The function |
13159 | -- declaration must be analyzed in the scope of the | |
5f531fef ES |
13160 | -- type, but the the expression can reference components |
13161 | -- and discriminants of the type. | |
6905a049 | 13162 | |
66f95f60 AC |
13163 | if No (Predicate_Function (E)) then |
13164 | declare | |
13165 | FDecl : constant Node_Id := | |
13166 | Build_Predicate_Function_Declaration (E); | |
13167 | pragma Unreferenced (FDecl); | |
0691ed6b | 13168 | |
66f95f60 | 13169 | begin |
5f531fef | 13170 | Push_Type (E); |
66f95f60 | 13171 | Resolve_Aspect_Expression (Expr); |
5f531fef | 13172 | Pop_Type (E); |
66f95f60 AC |
13173 | end; |
13174 | end if; | |
6905a049 | 13175 | |
66f95f60 AC |
13176 | when Pre_Post_Aspects => |
13177 | null; | |
f06f5f6b | 13178 | |
66f95f60 AC |
13179 | when Aspect_Iterable => |
13180 | if Nkind (Expr) = N_Aggregate then | |
13181 | declare | |
13182 | Assoc : Node_Id; | |
f06f5f6b | 13183 | |
66f95f60 AC |
13184 | begin |
13185 | Assoc := First (Component_Associations (Expr)); | |
13186 | while Present (Assoc) loop | |
13187 | Find_Direct_Name (Expression (Assoc)); | |
13188 | Next (Assoc); | |
13189 | end loop; | |
13190 | end; | |
13191 | end if; | |
f06f5f6b | 13192 | |
683af98c AC |
13193 | -- The expression for Default_Value is a static expression |
13194 | -- of the type, but this expression does not freeze the | |
13195 | -- type, so it can still appear in a representation clause | |
13196 | -- before the actual freeze point. | |
13197 | ||
13198 | when Aspect_Default_Value => | |
13199 | Set_Must_Not_Freeze (Expr); | |
13200 | Preanalyze_Spec_Expression (Expr, E); | |
13201 | ||
5f531fef ES |
13202 | when Aspect_Priority => |
13203 | Push_Type (E); | |
13204 | Preanalyze_Spec_Expression (Expr, Any_Integer); | |
13205 | Pop_Type (E); | |
13206 | ||
f71b4cd4 PMR |
13207 | -- Ditto for Storage_Size. Any other aspects that carry |
13208 | -- expressions that should not freeze ??? This is only | |
13209 | -- relevant to the misuse of deferred constants. | |
13210 | ||
13211 | when Aspect_Storage_Size => | |
13212 | Set_Must_Not_Freeze (Expr); | |
13213 | Preanalyze_Spec_Expression (Expr, Any_Integer); | |
13214 | ||
66f95f60 AC |
13215 | when others => |
13216 | if Present (Expr) then | |
13217 | case Aspect_Argument (A_Id) is | |
13218 | when Expression | |
13219 | | Optional_Expression | |
13220 | => | |
13221 | Analyze_And_Resolve (Expr); | |
13222 | ||
13223 | when Name | |
13224 | | Optional_Name | |
13225 | => | |
13226 | if Nkind (Expr) = N_Identifier then | |
13227 | Find_Direct_Name (Expr); | |
13228 | ||
13229 | elsif Nkind (Expr) = N_Selected_Component then | |
13230 | Find_Selected_Component (Expr); | |
13231 | end if; | |
13232 | end case; | |
13233 | end if; | |
13234 | end case; | |
13235 | end; | |
f06f5f6b AC |
13236 | end if; |
13237 | ||
b7737d1d | 13238 | ASN := Next_Rep_Item (ASN); |
f06f5f6b AC |
13239 | end loop; |
13240 | end Resolve_Aspect_Expressions; | |
13241 | ||
996ae0b0 RK |
13242 | ------------------------- |
13243 | -- Same_Representation -- | |
13244 | ------------------------- | |
13245 | ||
13246 | function Same_Representation (Typ1, Typ2 : Entity_Id) return Boolean is | |
13247 | T1 : constant Entity_Id := Underlying_Type (Typ1); | |
13248 | T2 : constant Entity_Id := Underlying_Type (Typ2); | |
13249 | ||
13250 | begin | |
13251 | -- A quick check, if base types are the same, then we definitely have | |
13252 | -- the same representation, because the subtype specific representation | |
13253 | -- attributes (Size and Alignment) do not affect representation from | |
13254 | -- the point of view of this test. | |
13255 | ||
13256 | if Base_Type (T1) = Base_Type (T2) then | |
13257 | return True; | |
13258 | ||
13259 | elsif Is_Private_Type (Base_Type (T2)) | |
13260 | and then Base_Type (T1) = Full_View (Base_Type (T2)) | |
13261 | then | |
13262 | return True; | |
13263 | end if; | |
13264 | ||
8489c295 AC |
13265 | -- Tagged types always have the same representation, because it is not |
13266 | -- possible to specify different representations for common fields. | |
996ae0b0 RK |
13267 | |
13268 | if Is_Tagged_Type (T1) then | |
13269 | return True; | |
13270 | end if; | |
13271 | ||
13272 | -- Representations are definitely different if conventions differ | |
13273 | ||
13274 | if Convention (T1) /= Convention (T2) then | |
13275 | return False; | |
13276 | end if; | |
13277 | ||
03eb6036 AC |
13278 | -- Representations are different if component alignments or scalar |
13279 | -- storage orders differ. | |
996ae0b0 RK |
13280 | |
13281 | if (Is_Record_Type (T1) or else Is_Array_Type (T1)) | |
752b81d9 | 13282 | and then |
996ae0b0 | 13283 | (Is_Record_Type (T2) or else Is_Array_Type (T2)) |
03eb6036 AC |
13284 | and then |
13285 | (Component_Alignment (T1) /= Component_Alignment (T2) | |
dc06dd83 | 13286 | or else Reverse_Storage_Order (T1) /= Reverse_Storage_Order (T2)) |
996ae0b0 RK |
13287 | then |
13288 | return False; | |
13289 | end if; | |
13290 | ||
13291 | -- For arrays, the only real issue is component size. If we know the | |
13292 | -- component size for both arrays, and it is the same, then that's | |
13293 | -- good enough to know we don't have a change of representation. | |
13294 | ||
13295 | if Is_Array_Type (T1) then | |
13296 | if Known_Component_Size (T1) | |
13297 | and then Known_Component_Size (T2) | |
13298 | and then Component_Size (T1) = Component_Size (T2) | |
13299 | then | |
535a8637 | 13300 | return True; |
996ae0b0 RK |
13301 | end if; |
13302 | end if; | |
13303 | ||
8489c295 AC |
13304 | -- For records, representations are different if reorderings differ |
13305 | ||
13306 | if Is_Record_Type (T1) | |
13307 | and then Is_Record_Type (T2) | |
13308 | and then No_Reordering (T1) /= No_Reordering (T2) | |
13309 | then | |
13310 | return False; | |
13311 | end if; | |
13312 | ||
996ae0b0 RK |
13313 | -- Types definitely have same representation if neither has non-standard |
13314 | -- representation since default representations are always consistent. | |
13315 | -- If only one has non-standard representation, and the other does not, | |
13316 | -- then we consider that they do not have the same representation. They | |
13317 | -- might, but there is no way of telling early enough. | |
13318 | ||
13319 | if Has_Non_Standard_Rep (T1) then | |
13320 | if not Has_Non_Standard_Rep (T2) then | |
13321 | return False; | |
13322 | end if; | |
13323 | else | |
13324 | return not Has_Non_Standard_Rep (T2); | |
13325 | end if; | |
13326 | ||
0503c53a RD |
13327 | -- Here the two types both have non-standard representation, and we need |
13328 | -- to determine if they have the same non-standard representation. | |
996ae0b0 RK |
13329 | |
13330 | -- For arrays, we simply need to test if the component sizes are the | |
13331 | -- same. Pragma Pack is reflected in modified component sizes, so this | |
13332 | -- check also deals with pragma Pack. | |
13333 | ||
13334 | if Is_Array_Type (T1) then | |
13335 | return Component_Size (T1) = Component_Size (T2); | |
13336 | ||
996ae0b0 RK |
13337 | -- Case of record types |
13338 | ||
13339 | elsif Is_Record_Type (T1) then | |
13340 | ||
13341 | -- Packed status must conform | |
13342 | ||
13343 | if Is_Packed (T1) /= Is_Packed (T2) then | |
13344 | return False; | |
13345 | ||
13346 | -- Otherwise we must check components. Typ2 maybe a constrained | |
13347 | -- subtype with fewer components, so we compare the components | |
13348 | -- of the base types. | |
13349 | ||
13350 | else | |
13351 | Record_Case : declare | |
13352 | CD1, CD2 : Entity_Id; | |
13353 | ||
13354 | function Same_Rep return Boolean; | |
13355 | -- CD1 and CD2 are either components or discriminants. This | |
03eb6036 | 13356 | -- function tests whether they have the same representation. |
996ae0b0 | 13357 | |
0da2c8ac AC |
13358 | -------------- |
13359 | -- Same_Rep -- | |
13360 | -------------- | |
13361 | ||
996ae0b0 RK |
13362 | function Same_Rep return Boolean is |
13363 | begin | |
13364 | if No (Component_Clause (CD1)) then | |
13365 | return No (Component_Clause (CD2)); | |
996ae0b0 | 13366 | else |
03eb6036 AC |
13367 | -- Note: at this point, component clauses have been |
13368 | -- normalized to the default bit order, so that the | |
13369 | -- comparison of Component_Bit_Offsets is meaningful. | |
13370 | ||
996ae0b0 RK |
13371 | return |
13372 | Present (Component_Clause (CD2)) | |
13373 | and then | |
13374 | Component_Bit_Offset (CD1) = Component_Bit_Offset (CD2) | |
13375 | and then | |
13376 | Esize (CD1) = Esize (CD2); | |
13377 | end if; | |
13378 | end Same_Rep; | |
13379 | ||
d8221f45 | 13380 | -- Start of processing for Record_Case |
996ae0b0 RK |
13381 | |
13382 | begin | |
13383 | if Has_Discriminants (T1) then | |
996ae0b0 | 13384 | |
fbf5a39b AC |
13385 | -- The number of discriminants may be different if the |
13386 | -- derived type has fewer (constrained by values). The | |
13387 | -- invisible discriminants retain the representation of | |
13388 | -- the original, so the discrepancy does not per se | |
13389 | -- indicate a different representation. | |
13390 | ||
616547fa AC |
13391 | CD1 := First_Discriminant (T1); |
13392 | CD2 := First_Discriminant (T2); | |
13393 | while Present (CD1) and then Present (CD2) loop | |
996ae0b0 RK |
13394 | if not Same_Rep then |
13395 | return False; | |
13396 | else | |
13397 | Next_Discriminant (CD1); | |
13398 | Next_Discriminant (CD2); | |
13399 | end if; | |
13400 | end loop; | |
13401 | end if; | |
13402 | ||
13403 | CD1 := First_Component (Underlying_Type (Base_Type (T1))); | |
13404 | CD2 := First_Component (Underlying_Type (Base_Type (T2))); | |
996ae0b0 RK |
13405 | while Present (CD1) loop |
13406 | if not Same_Rep then | |
13407 | return False; | |
13408 | else | |
13409 | Next_Component (CD1); | |
13410 | Next_Component (CD2); | |
13411 | end if; | |
13412 | end loop; | |
13413 | ||
13414 | return True; | |
13415 | end Record_Case; | |
13416 | end if; | |
13417 | ||
13418 | -- For enumeration types, we must check each literal to see if the | |
13419 | -- representation is the same. Note that we do not permit enumeration | |
f3d57416 | 13420 | -- representation clauses for Character and Wide_Character, so these |
996ae0b0 RK |
13421 | -- cases were already dealt with. |
13422 | ||
13423 | elsif Is_Enumeration_Type (T1) then | |
996ae0b0 RK |
13424 | Enumeration_Case : declare |
13425 | L1, L2 : Entity_Id; | |
13426 | ||
13427 | begin | |
13428 | L1 := First_Literal (T1); | |
13429 | L2 := First_Literal (T2); | |
996ae0b0 RK |
13430 | while Present (L1) loop |
13431 | if Enumeration_Rep (L1) /= Enumeration_Rep (L2) then | |
13432 | return False; | |
13433 | else | |
13434 | Next_Literal (L1); | |
13435 | Next_Literal (L2); | |
13436 | end if; | |
13437 | end loop; | |
13438 | ||
13439 | return True; | |
996ae0b0 RK |
13440 | end Enumeration_Case; |
13441 | ||
13442 | -- Any other types have the same representation for these purposes | |
13443 | ||
13444 | else | |
13445 | return True; | |
13446 | end if; | |
996ae0b0 RK |
13447 | end Same_Representation; |
13448 | ||
b4f149c2 AC |
13449 | -------------------------------- |
13450 | -- Resolve_Iterable_Operation -- | |
13451 | -------------------------------- | |
13452 | ||
13453 | procedure Resolve_Iterable_Operation | |
13454 | (N : Node_Id; | |
13455 | Cursor : Entity_Id; | |
13456 | Typ : Entity_Id; | |
13457 | Nam : Name_Id) | |
13458 | is | |
13459 | Ent : Entity_Id; | |
13460 | F1 : Entity_Id; | |
13461 | F2 : Entity_Id; | |
13462 | ||
13463 | begin | |
13464 | if not Is_Overloaded (N) then | |
13465 | if not Is_Entity_Name (N) | |
13466 | or else Ekind (Entity (N)) /= E_Function | |
13467 | or else Scope (Entity (N)) /= Scope (Typ) | |
13468 | or else No (First_Formal (Entity (N))) | |
13469 | or else Etype (First_Formal (Entity (N))) /= Typ | |
13470 | then | |
3fc40cd7 PMR |
13471 | Error_Msg_N |
13472 | ("iterable primitive must be local function name whose first " | |
13473 | & "formal is an iterable type", N); | |
a6ce7e76 | 13474 | return; |
b4f149c2 AC |
13475 | end if; |
13476 | ||
13477 | Ent := Entity (N); | |
3fc40cd7 | 13478 | F1 := First_Formal (Ent); |
b4f149c2 | 13479 | |
3fc40cd7 | 13480 | if Nam = Name_First or else Nam = Name_Last then |
367601d1 PMR |
13481 | |
13482 | -- First or Last (Container) => Cursor | |
b4f149c2 AC |
13483 | |
13484 | if Etype (Ent) /= Cursor then | |
13485 | Error_Msg_N ("primitive for First must yield a curosr", N); | |
13486 | end if; | |
13487 | ||
13488 | elsif Nam = Name_Next then | |
13489 | ||
13490 | -- Next (Container, Cursor) => Cursor | |
13491 | ||
13492 | F2 := Next_Formal (F1); | |
13493 | ||
13494 | if Etype (F2) /= Cursor | |
13495 | or else Etype (Ent) /= Cursor | |
13496 | or else Present (Next_Formal (F2)) | |
13497 | then | |
13498 | Error_Msg_N ("no match for Next iterable primitive", N); | |
13499 | end if; | |
13500 | ||
367601d1 PMR |
13501 | elsif Nam = Name_Previous then |
13502 | ||
13503 | -- Previous (Container, Cursor) => Cursor | |
13504 | ||
13505 | F2 := Next_Formal (F1); | |
13506 | ||
13507 | if Etype (F2) /= Cursor | |
13508 | or else Etype (Ent) /= Cursor | |
13509 | or else Present (Next_Formal (F2)) | |
13510 | then | |
13511 | Error_Msg_N ("no match for Previous iterable primitive", N); | |
13512 | end if; | |
13513 | ||
b4f149c2 AC |
13514 | elsif Nam = Name_Has_Element then |
13515 | ||
13516 | -- Has_Element (Container, Cursor) => Boolean | |
13517 | ||
13518 | F2 := Next_Formal (F1); | |
3fc40cd7 | 13519 | |
b4f149c2 AC |
13520 | if Etype (F2) /= Cursor |
13521 | or else Etype (Ent) /= Standard_Boolean | |
13522 | or else Present (Next_Formal (F2)) | |
13523 | then | |
13524 | Error_Msg_N ("no match for Has_Element iterable primitive", N); | |
13525 | end if; | |
13526 | ||
13527 | elsif Nam = Name_Element then | |
ffdeb702 AC |
13528 | F2 := Next_Formal (F1); |
13529 | ||
13530 | if No (F2) | |
13531 | or else Etype (F2) /= Cursor | |
13532 | or else Present (Next_Formal (F2)) | |
13533 | then | |
13534 | Error_Msg_N ("no match for Element iterable primitive", N); | |
13535 | end if; | |
b4f149c2 AC |
13536 | |
13537 | else | |
13538 | raise Program_Error; | |
13539 | end if; | |
13540 | ||
13541 | else | |
3fc40cd7 PMR |
13542 | -- Overloaded case: find subprogram with proper signature. Caller |
13543 | -- will report error if no match is found. | |
b4f149c2 AC |
13544 | |
13545 | declare | |
13546 | I : Interp_Index; | |
13547 | It : Interp; | |
13548 | ||
13549 | begin | |
13550 | Get_First_Interp (N, I, It); | |
13551 | while Present (It.Typ) loop | |
13552 | if Ekind (It.Nam) = E_Function | |
ffdeb702 | 13553 | and then Scope (It.Nam) = Scope (Typ) |
b4f149c2 AC |
13554 | and then Etype (First_Formal (It.Nam)) = Typ |
13555 | then | |
13556 | F1 := First_Formal (It.Nam); | |
13557 | ||
13558 | if Nam = Name_First then | |
13559 | if Etype (It.Nam) = Cursor | |
13560 | and then No (Next_Formal (F1)) | |
13561 | then | |
13562 | Set_Entity (N, It.Nam); | |
13563 | exit; | |
13564 | end if; | |
13565 | ||
13566 | elsif Nam = Name_Next then | |
13567 | F2 := Next_Formal (F1); | |
13568 | ||
13569 | if Present (F2) | |
13570 | and then No (Next_Formal (F2)) | |
13571 | and then Etype (F2) = Cursor | |
13572 | and then Etype (It.Nam) = Cursor | |
13573 | then | |
13574 | Set_Entity (N, It.Nam); | |
13575 | exit; | |
13576 | end if; | |
13577 | ||
13578 | elsif Nam = Name_Has_Element then | |
13579 | F2 := Next_Formal (F1); | |
13580 | ||
13581 | if Present (F2) | |
13582 | and then No (Next_Formal (F2)) | |
13583 | and then Etype (F2) = Cursor | |
13584 | and then Etype (It.Nam) = Standard_Boolean | |
13585 | then | |
13586 | Set_Entity (N, It.Nam); | |
13587 | F2 := Next_Formal (F1); | |
13588 | exit; | |
13589 | end if; | |
13590 | ||
13591 | elsif Nam = Name_Element then | |
ffdeb702 AC |
13592 | F2 := Next_Formal (F1); |
13593 | ||
b4f149c2 AC |
13594 | if Present (F2) |
13595 | and then No (Next_Formal (F2)) | |
13596 | and then Etype (F2) = Cursor | |
13597 | then | |
13598 | Set_Entity (N, It.Nam); | |
13599 | exit; | |
13600 | end if; | |
13601 | end if; | |
13602 | end if; | |
13603 | ||
13604 | Get_Next_Interp (I, It); | |
13605 | end loop; | |
13606 | end; | |
13607 | end if; | |
13608 | end Resolve_Iterable_Operation; | |
13609 | ||
a3f2babd AC |
13610 | ---------------- |
13611 | -- Set_Biased -- | |
13612 | ---------------- | |
13613 | ||
13614 | procedure Set_Biased | |
13615 | (E : Entity_Id; | |
13616 | N : Node_Id; | |
13617 | Msg : String; | |
13618 | Biased : Boolean := True) | |
13619 | is | |
13620 | begin | |
13621 | if Biased then | |
13622 | Set_Has_Biased_Representation (E); | |
13623 | ||
13624 | if Warn_On_Biased_Representation then | |
13625 | Error_Msg_NE | |
dbfeb4fa | 13626 | ("?B?" & Msg & " forces biased representation for&", N, E); |
a3f2babd AC |
13627 | end if; |
13628 | end if; | |
13629 | end Set_Biased; | |
13630 | ||
996ae0b0 RK |
13631 | -------------------- |
13632 | -- Set_Enum_Esize -- | |
13633 | -------------------- | |
13634 | ||
13635 | procedure Set_Enum_Esize (T : Entity_Id) is | |
13636 | Lo : Uint; | |
13637 | Hi : Uint; | |
13638 | Sz : Nat; | |
13639 | ||
13640 | begin | |
13641 | Init_Alignment (T); | |
13642 | ||
13643 | -- Find the minimum standard size (8,16,32,64) that fits | |
13644 | ||
13645 | Lo := Enumeration_Rep (Entity (Type_Low_Bound (T))); | |
13646 | Hi := Enumeration_Rep (Entity (Type_High_Bound (T))); | |
13647 | ||
13648 | if Lo < 0 then | |
13649 | if Lo >= -Uint_2**07 and then Hi < Uint_2**07 then | |
07fc65c4 | 13650 | Sz := Standard_Character_Size; -- May be > 8 on some targets |
996ae0b0 RK |
13651 | |
13652 | elsif Lo >= -Uint_2**15 and then Hi < Uint_2**15 then | |
13653 | Sz := 16; | |
13654 | ||
13655 | elsif Lo >= -Uint_2**31 and then Hi < Uint_2**31 then | |
13656 | Sz := 32; | |
13657 | ||
13658 | else pragma Assert (Lo >= -Uint_2**63 and then Hi < Uint_2**63); | |
13659 | Sz := 64; | |
13660 | end if; | |
13661 | ||
13662 | else | |
13663 | if Hi < Uint_2**08 then | |
07fc65c4 | 13664 | Sz := Standard_Character_Size; -- May be > 8 on some targets |
996ae0b0 RK |
13665 | |
13666 | elsif Hi < Uint_2**16 then | |
13667 | Sz := 16; | |
13668 | ||
13669 | elsif Hi < Uint_2**32 then | |
13670 | Sz := 32; | |
13671 | ||
13672 | else pragma Assert (Hi < Uint_2**63); | |
13673 | Sz := 64; | |
13674 | end if; | |
13675 | end if; | |
13676 | ||
13677 | -- That minimum is the proper size unless we have a foreign convention | |
13678 | -- and the size required is 32 or less, in which case we bump the size | |
13679 | -- up to 32. This is required for C and C++ and seems reasonable for | |
13680 | -- all other foreign conventions. | |
13681 | ||
13682 | if Has_Foreign_Convention (T) | |
13683 | and then Esize (T) < Standard_Integer_Size | |
d0ef7921 AC |
13684 | |
13685 | -- Don't do this if Short_Enums on target | |
13686 | ||
f27ad2b2 | 13687 | and then not Target_Short_Enums |
996ae0b0 RK |
13688 | then |
13689 | Init_Esize (T, Standard_Integer_Size); | |
996ae0b0 RK |
13690 | else |
13691 | Init_Esize (T, Sz); | |
13692 | end if; | |
996ae0b0 RK |
13693 | end Set_Enum_Esize; |
13694 | ||
77a40ec1 AC |
13695 | ----------------------------- |
13696 | -- Uninstall_Discriminants -- | |
13697 | ----------------------------- | |
13698 | ||
13699 | procedure Uninstall_Discriminants (E : Entity_Id) is | |
13700 | Disc : Entity_Id; | |
13701 | Prev : Entity_Id; | |
13702 | Outer : Entity_Id; | |
13703 | ||
13704 | begin | |
13705 | -- Discriminants have been made visible for type declarations and | |
13706 | -- protected type declarations, not for subtype declarations. | |
13707 | ||
13708 | if Nkind (Parent (E)) /= N_Subtype_Declaration then | |
13709 | Disc := First_Discriminant (E); | |
13710 | while Present (Disc) loop | |
13711 | if Disc /= Current_Entity (Disc) then | |
13712 | Prev := Current_Entity (Disc); | |
13713 | while Present (Prev) | |
13714 | and then Present (Homonym (Prev)) | |
13715 | and then Homonym (Prev) /= Disc | |
13716 | loop | |
13717 | Prev := Homonym (Prev); | |
13718 | end loop; | |
13719 | else | |
13720 | Prev := Empty; | |
13721 | end if; | |
13722 | ||
13723 | Set_Is_Immediately_Visible (Disc, False); | |
13724 | ||
13725 | Outer := Homonym (Disc); | |
13726 | while Present (Outer) and then Scope (Outer) = E loop | |
13727 | Outer := Homonym (Outer); | |
13728 | end loop; | |
13729 | ||
13730 | -- Reset homonym link of other entities, but do not modify link | |
8a0183fd | 13731 | -- between entities in current scope, so that the back end can |
77a40ec1 AC |
13732 | -- have a proper count of local overloadings. |
13733 | ||
13734 | if No (Prev) then | |
13735 | Set_Name_Entity_Id (Chars (Disc), Outer); | |
13736 | ||
13737 | elsif Scope (Prev) /= Scope (Disc) then | |
13738 | Set_Homonym (Prev, Outer); | |
13739 | end if; | |
13740 | ||
13741 | Next_Discriminant (Disc); | |
13742 | end loop; | |
13743 | end if; | |
13744 | end Uninstall_Discriminants; | |
13745 | ||
2642f998 RD |
13746 | ------------------------------ |
13747 | -- Validate_Address_Clauses -- | |
13748 | ------------------------------ | |
13749 | ||
13750 | procedure Validate_Address_Clauses is | |
36d3d5d3 EB |
13751 | function Offset_Value (Expr : Node_Id) return Uint; |
13752 | -- Given an Address attribute reference, return the value in bits of its | |
13753 | -- offset from the first bit of the underlying entity, or 0 if it is not | |
13754 | -- known at compile time. | |
13755 | ||
13756 | ------------------ | |
13757 | -- Offset_Value -- | |
13758 | ------------------ | |
13759 | ||
13760 | function Offset_Value (Expr : Node_Id) return Uint is | |
13761 | N : Node_Id := Prefix (Expr); | |
13762 | Off : Uint; | |
13763 | Val : Uint := Uint_0; | |
13764 | ||
13765 | begin | |
13766 | -- Climb the prefix chain and compute the cumulative offset | |
13767 | ||
13768 | loop | |
13769 | if Is_Entity_Name (N) then | |
13770 | return Val; | |
13771 | ||
13772 | elsif Nkind (N) = N_Selected_Component then | |
13773 | Off := Component_Bit_Offset (Entity (Selector_Name (N))); | |
13774 | if Off /= No_Uint and then Off >= Uint_0 then | |
13775 | Val := Val + Off; | |
13776 | N := Prefix (N); | |
13777 | else | |
13778 | return Uint_0; | |
13779 | end if; | |
13780 | ||
13781 | elsif Nkind (N) = N_Indexed_Component then | |
13782 | Off := Indexed_Component_Bit_Offset (N); | |
13783 | if Off /= No_Uint then | |
13784 | Val := Val + Off; | |
13785 | N := Prefix (N); | |
13786 | else | |
13787 | return Uint_0; | |
13788 | end if; | |
13789 | ||
13790 | else | |
13791 | return Uint_0; | |
13792 | end if; | |
13793 | end loop; | |
13794 | end Offset_Value; | |
13795 | ||
13796 | -- Start of processing for Validate_Address_Clauses | |
13797 | ||
2642f998 RD |
13798 | begin |
13799 | for J in Address_Clause_Checks.First .. Address_Clause_Checks.Last loop | |
13800 | declare | |
13801 | ACCR : Address_Clause_Check_Record | |
13802 | renames Address_Clause_Checks.Table (J); | |
13803 | ||
f4cd2542 EB |
13804 | Expr : Node_Id; |
13805 | ||
2642f998 | 13806 | X_Alignment : Uint; |
66c19cd4 | 13807 | Y_Alignment : Uint := Uint_0; |
2642f998 RD |
13808 | |
13809 | X_Size : Uint; | |
66c19cd4 | 13810 | Y_Size : Uint := Uint_0; |
2642f998 | 13811 | |
36d3d5d3 EB |
13812 | X_Offs : Uint; |
13813 | ||
2642f998 RD |
13814 | begin |
13815 | -- Skip processing of this entry if warning already posted | |
13816 | ||
13817 | if not Address_Warning_Posted (ACCR.N) then | |
f4cd2542 | 13818 | Expr := Original_Node (Expression (ACCR.N)); |
2642f998 | 13819 | |
f26a3587 | 13820 | -- Get alignments, sizes and offset, if any |
2642f998 | 13821 | |
f4cd2542 | 13822 | X_Alignment := Alignment (ACCR.X); |
80007176 | 13823 | X_Size := Esize (ACCR.X); |
f26a3587 AC |
13824 | |
13825 | if Present (ACCR.Y) then | |
13826 | Y_Alignment := Alignment (ACCR.Y); | |
80007176 | 13827 | Y_Size := Esize (ACCR.Y); |
f26a3587 | 13828 | end if; |
2642f998 | 13829 | |
36d3d5d3 EB |
13830 | if ACCR.Off |
13831 | and then Nkind (Expr) = N_Attribute_Reference | |
13832 | and then Attribute_Name (Expr) = Name_Address | |
13833 | then | |
13834 | X_Offs := Offset_Value (Expr); | |
13835 | else | |
13836 | X_Offs := Uint_0; | |
13837 | end if; | |
13838 | ||
f26a3587 AC |
13839 | -- Check for known value not multiple of alignment |
13840 | ||
13841 | if No (ACCR.Y) then | |
5067f3a0 | 13842 | if not Alignment_Checks_Suppressed (ACCR) |
f26a3587 AC |
13843 | and then X_Alignment /= 0 |
13844 | and then ACCR.A mod X_Alignment /= 0 | |
13845 | then | |
13846 | Error_Msg_NE | |
13847 | ("??specified address for& is inconsistent with " | |
13848 | & "alignment", ACCR.N, ACCR.X); | |
13849 | Error_Msg_N | |
13850 | ("\??program execution may be erroneous (RM 13.3(27))", | |
13851 | ACCR.N); | |
13852 | ||
13853 | Error_Msg_Uint_1 := X_Alignment; | |
13854 | Error_Msg_NE ("\??alignment of & is ^", ACCR.N, ACCR.X); | |
13855 | end if; | |
13856 | ||
2642f998 RD |
13857 | -- Check for large object overlaying smaller one |
13858 | ||
f26a3587 | 13859 | elsif Y_Size > Uint_0 |
2642f998 | 13860 | and then X_Size > Uint_0 |
36d3d5d3 | 13861 | and then X_Offs + X_Size > Y_Size |
2642f998 | 13862 | then |
e9c12b91 | 13863 | Error_Msg_NE ("??& overlays smaller object", ACCR.N, ACCR.X); |
2642f998 | 13864 | Error_Msg_N |
dbfeb4fa | 13865 | ("\??program execution may be erroneous", ACCR.N); |
e9c12b91 | 13866 | |
2642f998 | 13867 | Error_Msg_Uint_1 := X_Size; |
e9c12b91 AC |
13868 | Error_Msg_NE ("\??size of & is ^", ACCR.N, ACCR.X); |
13869 | ||
2642f998 | 13870 | Error_Msg_Uint_1 := Y_Size; |
e9c12b91 | 13871 | Error_Msg_NE ("\??size of & is ^", ACCR.N, ACCR.Y); |
2642f998 | 13872 | |
73170f9e | 13873 | if Y_Size >= X_Size then |
36d3d5d3 | 13874 | Error_Msg_Uint_1 := X_Offs; |
73170f9e | 13875 | Error_Msg_NE ("\??but offset of & is ^", ACCR.N, ACCR.X); |
36d3d5d3 EB |
13876 | end if; |
13877 | ||
f4cd2542 | 13878 | -- Check for inadequate alignment, both of the base object |
c944345b RD |
13879 | -- and of the offset, if any. We only do this check if the |
13880 | -- run-time Alignment_Check is active. No point in warning | |
13881 | -- if this check has been suppressed (or is suppressed by | |
13882 | -- default in the non-strict alignment machine case). | |
2642f998 | 13883 | |
f4cd2542 EB |
13884 | -- Note: we do not check the alignment if we gave a size |
13885 | -- warning, since it would likely be redundant. | |
2642f998 | 13886 | |
5067f3a0 | 13887 | elsif not Alignment_Checks_Suppressed (ACCR) |
c944345b | 13888 | and then Y_Alignment /= Uint_0 |
e9c12b91 AC |
13889 | and then |
13890 | (Y_Alignment < X_Alignment | |
13891 | or else | |
13892 | (ACCR.Off | |
13893 | and then Nkind (Expr) = N_Attribute_Reference | |
13894 | and then Attribute_Name (Expr) = Name_Address | |
13895 | and then Has_Compatible_Alignment | |
13896 | (ACCR.X, Prefix (Expr), True) /= | |
13897 | Known_Compatible)) | |
2642f998 RD |
13898 | then |
13899 | Error_Msg_NE | |
e9c12b91 AC |
13900 | ("??specified address for& may be inconsistent with " |
13901 | & "alignment", ACCR.N, ACCR.X); | |
2642f998 | 13902 | Error_Msg_N |
dbfeb4fa | 13903 | ("\??program execution may be erroneous (RM 13.3(27))", |
2642f998 | 13904 | ACCR.N); |
e9c12b91 | 13905 | |
2642f998 | 13906 | Error_Msg_Uint_1 := X_Alignment; |
e9c12b91 AC |
13907 | Error_Msg_NE ("\??alignment of & is ^", ACCR.N, ACCR.X); |
13908 | ||
2642f998 | 13909 | Error_Msg_Uint_1 := Y_Alignment; |
e9c12b91 AC |
13910 | Error_Msg_NE ("\??alignment of & is ^", ACCR.N, ACCR.Y); |
13911 | ||
f4cd2542 EB |
13912 | if Y_Alignment >= X_Alignment then |
13913 | Error_Msg_N | |
e9c12b91 | 13914 | ("\??but offset is not multiple of alignment", ACCR.N); |
f4cd2542 | 13915 | end if; |
2642f998 RD |
13916 | end if; |
13917 | end if; | |
13918 | end; | |
13919 | end loop; | |
13920 | end Validate_Address_Clauses; | |
13921 | ||
105b5e65 AC |
13922 | --------------------------- |
13923 | -- Validate_Independence -- | |
13924 | --------------------------- | |
13925 | ||
13926 | procedure Validate_Independence is | |
13927 | SU : constant Uint := UI_From_Int (System_Storage_Unit); | |
13928 | N : Node_Id; | |
13929 | E : Entity_Id; | |
13930 | IC : Boolean; | |
13931 | Comp : Entity_Id; | |
13932 | Addr : Node_Id; | |
13933 | P : Node_Id; | |
13934 | ||
13935 | procedure Check_Array_Type (Atyp : Entity_Id); | |
13936 | -- Checks if the array type Atyp has independent components, and | |
13937 | -- if not, outputs an appropriate set of error messages. | |
13938 | ||
13939 | procedure No_Independence; | |
13940 | -- Output message that independence cannot be guaranteed | |
13941 | ||
13942 | function OK_Component (C : Entity_Id) return Boolean; | |
13943 | -- Checks one component to see if it is independently accessible, and | |
13944 | -- if so yields True, otherwise yields False if independent access | |
13945 | -- cannot be guaranteed. This is a conservative routine, it only | |
13946 | -- returns True if it knows for sure, it returns False if it knows | |
13947 | -- there is a problem, or it cannot be sure there is no problem. | |
13948 | ||
13949 | procedure Reason_Bad_Component (C : Entity_Id); | |
13950 | -- Outputs continuation message if a reason can be determined for | |
13951 | -- the component C being bad. | |
13952 | ||
13953 | ---------------------- | |
13954 | -- Check_Array_Type -- | |
13955 | ---------------------- | |
13956 | ||
13957 | procedure Check_Array_Type (Atyp : Entity_Id) is | |
13958 | Ctyp : constant Entity_Id := Component_Type (Atyp); | |
13959 | ||
13960 | begin | |
13961 | -- OK if no alignment clause, no pack, and no component size | |
13962 | ||
13963 | if not Has_Component_Size_Clause (Atyp) | |
13964 | and then not Has_Alignment_Clause (Atyp) | |
13965 | and then not Is_Packed (Atyp) | |
13966 | then | |
13967 | return; | |
13968 | end if; | |
13969 | ||
9d2a2071 AC |
13970 | -- Case of component size is greater than or equal to 64 and the |
13971 | -- alignment of the array is at least as large as the alignment | |
13972 | -- of the component. We are definitely OK in this situation. | |
13973 | ||
13974 | if Known_Component_Size (Atyp) | |
13975 | and then Component_Size (Atyp) >= 64 | |
13976 | and then Known_Alignment (Atyp) | |
13977 | and then Known_Alignment (Ctyp) | |
13978 | and then Alignment (Atyp) >= Alignment (Ctyp) | |
13979 | then | |
13980 | return; | |
13981 | end if; | |
13982 | ||
105b5e65 AC |
13983 | -- Check actual component size |
13984 | ||
13985 | if not Known_Component_Size (Atyp) | |
13986 | or else not (Addressable (Component_Size (Atyp)) | |
9d2a2071 | 13987 | and then Component_Size (Atyp) < 64) |
105b5e65 AC |
13988 | or else Component_Size (Atyp) mod Esize (Ctyp) /= 0 |
13989 | then | |
13990 | No_Independence; | |
13991 | ||
13992 | -- Bad component size, check reason | |
13993 | ||
13994 | if Has_Component_Size_Clause (Atyp) then | |
616547fa AC |
13995 | P := Get_Attribute_Definition_Clause |
13996 | (Atyp, Attribute_Component_Size); | |
105b5e65 AC |
13997 | |
13998 | if Present (P) then | |
13999 | Error_Msg_Sloc := Sloc (P); | |
14000 | Error_Msg_N ("\because of Component_Size clause#", N); | |
14001 | return; | |
14002 | end if; | |
14003 | end if; | |
14004 | ||
14005 | if Is_Packed (Atyp) then | |
14006 | P := Get_Rep_Pragma (Atyp, Name_Pack); | |
14007 | ||
14008 | if Present (P) then | |
14009 | Error_Msg_Sloc := Sloc (P); | |
14010 | Error_Msg_N ("\because of pragma Pack#", N); | |
14011 | return; | |
14012 | end if; | |
14013 | end if; | |
14014 | ||
14015 | -- No reason found, just return | |
14016 | ||
14017 | return; | |
14018 | end if; | |
14019 | ||
14020 | -- Array type is OK independence-wise | |
14021 | ||
14022 | return; | |
14023 | end Check_Array_Type; | |
14024 | ||
14025 | --------------------- | |
14026 | -- No_Independence -- | |
14027 | --------------------- | |
14028 | ||
14029 | procedure No_Independence is | |
14030 | begin | |
6e759c2a | 14031 | if Pragma_Name (N) = Name_Independent then |
b69cd36a | 14032 | Error_Msg_NE ("independence cannot be guaranteed for&", N, E); |
105b5e65 AC |
14033 | else |
14034 | Error_Msg_NE | |
14035 | ("independent components cannot be guaranteed for&", N, E); | |
14036 | end if; | |
14037 | end No_Independence; | |
14038 | ||
14039 | ------------------ | |
14040 | -- OK_Component -- | |
14041 | ------------------ | |
14042 | ||
14043 | function OK_Component (C : Entity_Id) return Boolean is | |
14044 | Rec : constant Entity_Id := Scope (C); | |
14045 | Ctyp : constant Entity_Id := Etype (C); | |
14046 | ||
14047 | begin | |
14048 | -- OK if no component clause, no Pack, and no alignment clause | |
14049 | ||
14050 | if No (Component_Clause (C)) | |
14051 | and then not Is_Packed (Rec) | |
14052 | and then not Has_Alignment_Clause (Rec) | |
14053 | then | |
14054 | return True; | |
14055 | end if; | |
14056 | ||
14057 | -- Here we look at the actual component layout. A component is | |
14058 | -- addressable if its size is a multiple of the Esize of the | |
14059 | -- component type, and its starting position in the record has | |
14060 | -- appropriate alignment, and the record itself has appropriate | |
14061 | -- alignment to guarantee the component alignment. | |
14062 | ||
14063 | -- Make sure sizes are static, always assume the worst for any | |
14064 | -- cases where we cannot check static values. | |
14065 | ||
14066 | if not (Known_Static_Esize (C) | |
616547fa AC |
14067 | and then |
14068 | Known_Static_Esize (Ctyp)) | |
105b5e65 AC |
14069 | then |
14070 | return False; | |
14071 | end if; | |
14072 | ||
14073 | -- Size of component must be addressable or greater than 64 bits | |
14074 | -- and a multiple of bytes. | |
14075 | ||
616547fa | 14076 | if not Addressable (Esize (C)) and then Esize (C) < Uint_64 then |
105b5e65 AC |
14077 | return False; |
14078 | end if; | |
14079 | ||
14080 | -- Check size is proper multiple | |
14081 | ||
14082 | if Esize (C) mod Esize (Ctyp) /= 0 then | |
14083 | return False; | |
14084 | end if; | |
14085 | ||
14086 | -- Check alignment of component is OK | |
14087 | ||
14088 | if not Known_Component_Bit_Offset (C) | |
14089 | or else Component_Bit_Offset (C) < Uint_0 | |
14090 | or else Component_Bit_Offset (C) mod Esize (Ctyp) /= 0 | |
14091 | then | |
14092 | return False; | |
14093 | end if; | |
14094 | ||
14095 | -- Check alignment of record type is OK | |
14096 | ||
14097 | if not Known_Alignment (Rec) | |
14098 | or else (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0 | |
14099 | then | |
14100 | return False; | |
14101 | end if; | |
14102 | ||
14103 | -- All tests passed, component is addressable | |
14104 | ||
14105 | return True; | |
14106 | end OK_Component; | |
14107 | ||
14108 | -------------------------- | |
14109 | -- Reason_Bad_Component -- | |
14110 | -------------------------- | |
14111 | ||
14112 | procedure Reason_Bad_Component (C : Entity_Id) is | |
14113 | Rec : constant Entity_Id := Scope (C); | |
14114 | Ctyp : constant Entity_Id := Etype (C); | |
14115 | ||
14116 | begin | |
14117 | -- If component clause present assume that's the problem | |
14118 | ||
14119 | if Present (Component_Clause (C)) then | |
14120 | Error_Msg_Sloc := Sloc (Component_Clause (C)); | |
14121 | Error_Msg_N ("\because of Component_Clause#", N); | |
14122 | return; | |
14123 | end if; | |
14124 | ||
14125 | -- If pragma Pack clause present, assume that's the problem | |
14126 | ||
14127 | if Is_Packed (Rec) then | |
14128 | P := Get_Rep_Pragma (Rec, Name_Pack); | |
14129 | ||
14130 | if Present (P) then | |
14131 | Error_Msg_Sloc := Sloc (P); | |
14132 | Error_Msg_N ("\because of pragma Pack#", N); | |
14133 | return; | |
14134 | end if; | |
14135 | end if; | |
14136 | ||
14137 | -- See if record has bad alignment clause | |
14138 | ||
14139 | if Has_Alignment_Clause (Rec) | |
14140 | and then Known_Alignment (Rec) | |
14141 | and then (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0 | |
14142 | then | |
14143 | P := Get_Attribute_Definition_Clause (Rec, Attribute_Alignment); | |
14144 | ||
14145 | if Present (P) then | |
14146 | Error_Msg_Sloc := Sloc (P); | |
14147 | Error_Msg_N ("\because of Alignment clause#", N); | |
14148 | end if; | |
14149 | end if; | |
14150 | ||
14151 | -- Couldn't find a reason, so return without a message | |
14152 | ||
14153 | return; | |
14154 | end Reason_Bad_Component; | |
14155 | ||
14156 | -- Start of processing for Validate_Independence | |
14157 | ||
14158 | begin | |
14159 | for J in Independence_Checks.First .. Independence_Checks.Last loop | |
14160 | N := Independence_Checks.Table (J).N; | |
14161 | E := Independence_Checks.Table (J).E; | |
6e759c2a | 14162 | IC := Pragma_Name (N) = Name_Independent_Components; |
105b5e65 AC |
14163 | |
14164 | -- Deal with component case | |
14165 | ||
14166 | if Ekind (E) = E_Discriminant or else Ekind (E) = E_Component then | |
14167 | if not OK_Component (E) then | |
14168 | No_Independence; | |
14169 | Reason_Bad_Component (E); | |
14170 | goto Continue; | |
14171 | end if; | |
14172 | end if; | |
14173 | ||
14174 | -- Deal with record with Independent_Components | |
14175 | ||
14176 | if IC and then Is_Record_Type (E) then | |
14177 | Comp := First_Component_Or_Discriminant (E); | |
14178 | while Present (Comp) loop | |
14179 | if not OK_Component (Comp) then | |
14180 | No_Independence; | |
14181 | Reason_Bad_Component (Comp); | |
14182 | goto Continue; | |
14183 | end if; | |
14184 | ||
14185 | Next_Component_Or_Discriminant (Comp); | |
14186 | end loop; | |
14187 | end if; | |
14188 | ||
14189 | -- Deal with address clause case | |
14190 | ||
14191 | if Is_Object (E) then | |
14192 | Addr := Address_Clause (E); | |
14193 | ||
14194 | if Present (Addr) then | |
14195 | No_Independence; | |
14196 | Error_Msg_Sloc := Sloc (Addr); | |
14197 | Error_Msg_N ("\because of Address clause#", N); | |
14198 | goto Continue; | |
14199 | end if; | |
14200 | end if; | |
14201 | ||
14202 | -- Deal with independent components for array type | |
14203 | ||
14204 | if IC and then Is_Array_Type (E) then | |
14205 | Check_Array_Type (E); | |
14206 | end if; | |
14207 | ||
14208 | -- Deal with independent components for array object | |
14209 | ||
14210 | if IC and then Is_Object (E) and then Is_Array_Type (Etype (E)) then | |
14211 | Check_Array_Type (Etype (E)); | |
14212 | end if; | |
14213 | ||
14214 | <<Continue>> null; | |
14215 | end loop; | |
14216 | end Validate_Independence; | |
14217 | ||
dd2bf554 ES |
14218 | ------------------------------ |
14219 | -- Validate_Iterable_Aspect -- | |
14220 | ------------------------------ | |
14221 | ||
14222 | procedure Validate_Iterable_Aspect (Typ : Entity_Id; ASN : Node_Id) is | |
b4f149c2 AC |
14223 | Assoc : Node_Id; |
14224 | Expr : Node_Id; | |
dd2bf554 | 14225 | |
82d4f390 | 14226 | Prim : Node_Id; |
a6ce7e76 | 14227 | Cursor : constant Entity_Id := Get_Cursor_Type (ASN, Typ); |
dd2bf554 ES |
14228 | |
14229 | First_Id : Entity_Id; | |
367601d1 | 14230 | Last_Id : Entity_Id; |
dd2bf554 ES |
14231 | Next_Id : Entity_Id; |
14232 | Has_Element_Id : Entity_Id; | |
14233 | Element_Id : Entity_Id; | |
14234 | ||
dd2bf554 | 14235 | begin |
edbd98c4 | 14236 | -- If previous error aspect is unusable |
a6ce7e76 AC |
14237 | |
14238 | if Cursor = Any_Type then | |
b4f149c2 AC |
14239 | return; |
14240 | end if; | |
dd2bf554 ES |
14241 | |
14242 | First_Id := Empty; | |
367601d1 | 14243 | Last_Id := Empty; |
dd2bf554 ES |
14244 | Next_Id := Empty; |
14245 | Has_Element_Id := Empty; | |
0f361206 | 14246 | Element_Id := Empty; |
dd2bf554 ES |
14247 | |
14248 | -- Each expression must resolve to a function with the proper signature | |
14249 | ||
14250 | Assoc := First (Component_Associations (Expression (ASN))); | |
14251 | while Present (Assoc) loop | |
14252 | Expr := Expression (Assoc); | |
14253 | Analyze (Expr); | |
14254 | ||
dd2bf554 | 14255 | Prim := First (Choices (Assoc)); |
82d4f390 | 14256 | |
dc06dd83 | 14257 | if Nkind (Prim) /= N_Identifier or else Present (Next (Prim)) then |
dd2bf554 ES |
14258 | Error_Msg_N ("illegal name in association", Prim); |
14259 | ||
14260 | elsif Chars (Prim) = Name_First then | |
b4f149c2 | 14261 | Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_First); |
dd2bf554 | 14262 | First_Id := Entity (Expr); |
dd2bf554 | 14263 | |
367601d1 PMR |
14264 | elsif Chars (Prim) = Name_Last then |
14265 | Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Last); | |
14266 | Last_Id := Entity (Expr); | |
14267 | ||
14268 | elsif Chars (Prim) = Name_Previous then | |
14269 | Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Previous); | |
14270 | Last_Id := Entity (Expr); | |
14271 | ||
dd2bf554 | 14272 | elsif Chars (Prim) = Name_Next then |
b4f149c2 | 14273 | Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Next); |
dd2bf554 | 14274 | Next_Id := Entity (Expr); |
dd2bf554 ES |
14275 | |
14276 | elsif Chars (Prim) = Name_Has_Element then | |
b4f149c2 | 14277 | Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Has_Element); |
dd2bf554 | 14278 | Has_Element_Id := Entity (Expr); |
82d4f390 | 14279 | |
dd2bf554 | 14280 | elsif Chars (Prim) = Name_Element then |
b4f149c2 | 14281 | Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Element); |
dd2bf554 | 14282 | Element_Id := Entity (Expr); |
dd2bf554 ES |
14283 | |
14284 | else | |
14285 | Error_Msg_N ("invalid name for iterable function", Prim); | |
14286 | end if; | |
14287 | ||
14288 | Next (Assoc); | |
14289 | end loop; | |
14290 | ||
14291 | if No (First_Id) then | |
b4f149c2 | 14292 | Error_Msg_N ("match for First primitive not found", ASN); |
dd2bf554 ES |
14293 | |
14294 | elsif No (Next_Id) then | |
b4f149c2 | 14295 | Error_Msg_N ("match for Next primitive not found", ASN); |
dd2bf554 ES |
14296 | |
14297 | elsif No (Has_Element_Id) then | |
b4f149c2 AC |
14298 | Error_Msg_N ("match for Has_Element primitive not found", ASN); |
14299 | ||
3fc40cd7 PMR |
14300 | elsif No (Element_Id) or else No (Last_Id) then |
14301 | null; -- optional | |
dd2bf554 ES |
14302 | end if; |
14303 | end Validate_Iterable_Aspect; | |
14304 | ||
996ae0b0 RK |
14305 | ----------------------------------- |
14306 | -- Validate_Unchecked_Conversion -- | |
14307 | ----------------------------------- | |
14308 | ||
14309 | procedure Validate_Unchecked_Conversion | |
14310 | (N : Node_Id; | |
14311 | Act_Unit : Entity_Id) | |
14312 | is | |
14313 | Source : Entity_Id; | |
14314 | Target : Entity_Id; | |
14315 | Vnode : Node_Id; | |
14316 | ||
14317 | begin | |
14318 | -- Obtain source and target types. Note that we call Ancestor_Subtype | |
14319 | -- here because the processing for generic instantiation always makes | |
14320 | -- subtypes, and we want the original frozen actual types. | |
14321 | ||
14322 | -- If we are dealing with private types, then do the check on their | |
14323 | -- fully declared counterparts if the full declarations have been | |
a90bd866 | 14324 | -- encountered (they don't have to be visible, but they must exist). |
996ae0b0 RK |
14325 | |
14326 | Source := Ancestor_Subtype (Etype (First_Formal (Act_Unit))); | |
14327 | ||
14328 | if Is_Private_Type (Source) | |
14329 | and then Present (Underlying_Type (Source)) | |
14330 | then | |
14331 | Source := Underlying_Type (Source); | |
14332 | end if; | |
14333 | ||
14334 | Target := Ancestor_Subtype (Etype (Act_Unit)); | |
14335 | ||
0503c53a | 14336 | -- If either type is generic, the instantiation happens within a generic |
a1092b48 AC |
14337 | -- unit, and there is nothing to check. The proper check will happen |
14338 | -- when the enclosing generic is instantiated. | |
996ae0b0 RK |
14339 | |
14340 | if Is_Generic_Type (Source) or else Is_Generic_Type (Target) then | |
14341 | return; | |
14342 | end if; | |
14343 | ||
14344 | if Is_Private_Type (Target) | |
14345 | and then Present (Underlying_Type (Target)) | |
14346 | then | |
14347 | Target := Underlying_Type (Target); | |
14348 | end if; | |
14349 | ||
5a99fda7 AC |
14350 | -- Source may be unconstrained array, but not target, except in relaxed |
14351 | -- semantics mode. | |
996ae0b0 | 14352 | |
5a99fda7 AC |
14353 | if Is_Array_Type (Target) |
14354 | and then not Is_Constrained (Target) | |
14355 | and then not Relaxed_RM_Semantics | |
14356 | then | |
996ae0b0 RK |
14357 | Error_Msg_N |
14358 | ("unchecked conversion to unconstrained array not allowed", N); | |
14359 | return; | |
14360 | end if; | |
14361 | ||
c690a2ec RD |
14362 | -- Warn if conversion between two different convention pointers |
14363 | ||
14364 | if Is_Access_Type (Target) | |
14365 | and then Is_Access_Type (Source) | |
14366 | and then Convention (Target) /= Convention (Source) | |
14367 | and then Warn_On_Unchecked_Conversion | |
14368 | then | |
ba0c6e47 | 14369 | -- Give warnings for subprogram pointers only on most targets |
0503c53a RD |
14370 | |
14371 | if Is_Access_Subprogram_Type (Target) | |
14372 | or else Is_Access_Subprogram_Type (Source) | |
0503c53a RD |
14373 | then |
14374 | Error_Msg_N | |
685bc70f | 14375 | ("?z?conversion between pointers with different conventions!", |
dbfeb4fa | 14376 | N); |
0503c53a | 14377 | end if; |
c690a2ec RD |
14378 | end if; |
14379 | ||
800621e0 RD |
14380 | -- Warn if one of the operands is Ada.Calendar.Time. Do not emit a |
14381 | -- warning when compiling GNAT-related sources. | |
14382 | ||
14383 | if Warn_On_Unchecked_Conversion | |
14384 | and then not In_Predefined_Unit (N) | |
14385 | and then RTU_Loaded (Ada_Calendar) | |
dc06dd83 AC |
14386 | and then (Chars (Source) = Name_Time |
14387 | or else | |
14388 | Chars (Target) = Name_Time) | |
800621e0 RD |
14389 | then |
14390 | -- If Ada.Calendar is loaded and the name of one of the operands is | |
14391 | -- Time, there is a good chance that this is Ada.Calendar.Time. | |
14392 | ||
14393 | declare | |
dc06dd83 | 14394 | Calendar_Time : constant Entity_Id := Full_View (RTE (RO_CA_Time)); |
800621e0 RD |
14395 | begin |
14396 | pragma Assert (Present (Calendar_Time)); | |
14397 | ||
616547fa | 14398 | if Source = Calendar_Time or else Target = Calendar_Time then |
800621e0 | 14399 | Error_Msg_N |
dc06dd83 AC |
14400 | ("?z?representation of 'Time values may change between " |
14401 | & "'G'N'A'T versions", N); | |
800621e0 RD |
14402 | end if; |
14403 | end; | |
14404 | end if; | |
14405 | ||
0503c53a RD |
14406 | -- Make entry in unchecked conversion table for later processing by |
14407 | -- Validate_Unchecked_Conversions, which will check sizes and alignments | |
8a0183fd | 14408 | -- (using values set by the back end where possible). This is only done |
0503c53a | 14409 | -- if the appropriate warning is active. |
996ae0b0 | 14410 | |
fbf5a39b AC |
14411 | if Warn_On_Unchecked_Conversion then |
14412 | Unchecked_Conversions.Append | |
4c51ff88 AC |
14413 | (New_Val => UC_Entry'(Eloc => Sloc (N), |
14414 | Source => Source, | |
14415 | Target => Target, | |
14416 | Act_Unit => Act_Unit)); | |
fbf5a39b | 14417 | |
2cc2e964 | 14418 | -- If both sizes are known statically now, then back-end annotation |
fbf5a39b AC |
14419 | -- is not required to do a proper check but if either size is not |
14420 | -- known statically, then we need the annotation. | |
14421 | ||
14422 | if Known_Static_RM_Size (Source) | |
dbfeb4fa RD |
14423 | and then |
14424 | Known_Static_RM_Size (Target) | |
fbf5a39b AC |
14425 | then |
14426 | null; | |
14427 | else | |
14428 | Back_Annotate_Rep_Info := True; | |
14429 | end if; | |
14430 | end if; | |
996ae0b0 | 14431 | |
0503c53a | 14432 | -- If unchecked conversion to access type, and access type is declared |
a1092b48 AC |
14433 | -- in the same unit as the unchecked conversion, then set the flag |
14434 | -- No_Strict_Aliasing (no strict aliasing is implicit here) | |
e6f69614 AC |
14435 | |
14436 | if Is_Access_Type (Target) and then | |
14437 | In_Same_Source_Unit (Target, N) | |
14438 | then | |
14439 | Set_No_Strict_Aliasing (Implementation_Base_Type (Target)); | |
14440 | end if; | |
8a6a52dc | 14441 | |
a1092b48 AC |
14442 | -- Generate N_Validate_Unchecked_Conversion node for back end in case |
14443 | -- the back end needs to perform special validation checks. | |
8a6a52dc | 14444 | |
a1092b48 AC |
14445 | -- Shouldn't this be in Exp_Ch13, since the check only gets done if we |
14446 | -- have full expansion and the back end is called ??? | |
8a6a52dc AC |
14447 | |
14448 | Vnode := | |
14449 | Make_Validate_Unchecked_Conversion (Sloc (N)); | |
14450 | Set_Source_Type (Vnode, Source); | |
14451 | Set_Target_Type (Vnode, Target); | |
14452 | ||
0503c53a RD |
14453 | -- If the unchecked conversion node is in a list, just insert before it. |
14454 | -- If not we have some strange case, not worth bothering about. | |
8a6a52dc AC |
14455 | |
14456 | if Is_List_Member (N) then | |
996ae0b0 RK |
14457 | Insert_After (N, Vnode); |
14458 | end if; | |
14459 | end Validate_Unchecked_Conversion; | |
14460 | ||
14461 | ------------------------------------ | |
14462 | -- Validate_Unchecked_Conversions -- | |
14463 | ------------------------------------ | |
14464 | ||
14465 | procedure Validate_Unchecked_Conversions is | |
14466 | begin | |
14467 | for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop | |
14468 | declare | |
14469 | T : UC_Entry renames Unchecked_Conversions.Table (N); | |
14470 | ||
2f8d7dfe | 14471 | Act_Unit : constant Entity_Id := T.Act_Unit; |
4c51ff88 AC |
14472 | Eloc : constant Source_Ptr := T.Eloc; |
14473 | Source : constant Entity_Id := T.Source; | |
14474 | Target : constant Entity_Id := T.Target; | |
996ae0b0 | 14475 | |
54c04d6c AC |
14476 | Source_Siz : Uint; |
14477 | Target_Siz : Uint; | |
996ae0b0 RK |
14478 | |
14479 | begin | |
4c51ff88 AC |
14480 | -- Skip if function marked as warnings off |
14481 | ||
14482 | if Warnings_Off (Act_Unit) then | |
14483 | goto Continue; | |
14484 | end if; | |
14485 | ||
0503c53a RD |
14486 | -- This validation check, which warns if we have unequal sizes for |
14487 | -- unchecked conversion, and thus potentially implementation | |
996ae0b0 | 14488 | -- dependent semantics, is one of the few occasions on which we |
0503c53a RD |
14489 | -- use the official RM size instead of Esize. See description in |
14490 | -- Einfo "Handling of Type'Size Values" for details. | |
996ae0b0 | 14491 | |
07fc65c4 | 14492 | if Serious_Errors_Detected = 0 |
996ae0b0 RK |
14493 | and then Known_Static_RM_Size (Source) |
14494 | and then Known_Static_RM_Size (Target) | |
9fcf2a0b AC |
14495 | |
14496 | -- Don't do the check if warnings off for either type, note the | |
14497 | -- deliberate use of OR here instead of OR ELSE to get the flag | |
14498 | -- Warnings_Off_Used set for both types if appropriate. | |
14499 | ||
14500 | and then not (Has_Warnings_Off (Source) | |
14501 | or | |
14502 | Has_Warnings_Off (Target)) | |
996ae0b0 RK |
14503 | then |
14504 | Source_Siz := RM_Size (Source); | |
14505 | Target_Siz := RM_Size (Target); | |
14506 | ||
14507 | if Source_Siz /= Target_Siz then | |
f66d46ec | 14508 | Error_Msg |
685bc70f | 14509 | ("?z?types for unchecked conversion have different sizes!", |
e5148da0 | 14510 | Eloc, Act_Unit); |
996ae0b0 RK |
14511 | |
14512 | if All_Errors_Mode then | |
14513 | Error_Msg_Name_1 := Chars (Source); | |
14514 | Error_Msg_Uint_1 := Source_Siz; | |
14515 | Error_Msg_Name_2 := Chars (Target); | |
14516 | Error_Msg_Uint_2 := Target_Siz; | |
685bc70f | 14517 | Error_Msg ("\size of % is ^, size of % is ^?z?", Eloc); |
996ae0b0 RK |
14518 | |
14519 | Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz); | |
14520 | ||
14521 | if Is_Discrete_Type (Source) | |
616547fa AC |
14522 | and then |
14523 | Is_Discrete_Type (Target) | |
996ae0b0 RK |
14524 | then |
14525 | if Source_Siz > Target_Siz then | |
f66d46ec | 14526 | Error_Msg |
685bc70f | 14527 | ("\?z?^ high order bits of source will " |
dbfeb4fa | 14528 | & "be ignored!", Eloc); |
996ae0b0 | 14529 | |
fbf5a39b | 14530 | elsif Is_Unsigned_Type (Source) then |
f66d46ec | 14531 | Error_Msg |
685bc70f | 14532 | ("\?z?source will be extended with ^ high order " |
b785e0b8 | 14533 | & "zero bits!", Eloc); |
996ae0b0 RK |
14534 | |
14535 | else | |
f66d46ec | 14536 | Error_Msg |
685bc70f | 14537 | ("\?z?source will be extended with ^ high order " |
dbfeb4fa | 14538 | & "sign bits!", Eloc); |
996ae0b0 RK |
14539 | end if; |
14540 | ||
14541 | elsif Source_Siz < Target_Siz then | |
14542 | if Is_Discrete_Type (Target) then | |
14543 | if Bytes_Big_Endian then | |
f66d46ec | 14544 | Error_Msg |
685bc70f | 14545 | ("\?z?target value will include ^ undefined " |
e5148da0 | 14546 | & "low order bits!", Eloc, Act_Unit); |
996ae0b0 | 14547 | else |
f66d46ec | 14548 | Error_Msg |
685bc70f | 14549 | ("\?z?target value will include ^ undefined " |
e5148da0 | 14550 | & "high order bits!", Eloc, Act_Unit); |
996ae0b0 RK |
14551 | end if; |
14552 | ||
14553 | else | |
f66d46ec | 14554 | Error_Msg |
685bc70f | 14555 | ("\?z?^ trailing bits of target value will be " |
e5148da0 | 14556 | & "undefined!", Eloc, Act_Unit); |
996ae0b0 RK |
14557 | end if; |
14558 | ||
14559 | else pragma Assert (Source_Siz > Target_Siz); | |
ccd6f414 AC |
14560 | if Is_Discrete_Type (Source) then |
14561 | if Bytes_Big_Endian then | |
14562 | Error_Msg | |
14563 | ("\?z?^ low order bits of source will be " | |
e5148da0 | 14564 | & "ignored!", Eloc, Act_Unit); |
ccd6f414 AC |
14565 | else |
14566 | Error_Msg | |
14567 | ("\?z?^ high order bits of source will be " | |
e5148da0 | 14568 | & "ignored!", Eloc, Act_Unit); |
ccd6f414 AC |
14569 | end if; |
14570 | ||
14571 | else | |
14572 | Error_Msg | |
14573 | ("\?z?^ trailing bits of source will be " | |
e5148da0 | 14574 | & "ignored!", Eloc, Act_Unit); |
ccd6f414 | 14575 | end if; |
996ae0b0 RK |
14576 | end if; |
14577 | end if; | |
996ae0b0 RK |
14578 | end if; |
14579 | end if; | |
14580 | ||
14581 | -- If both types are access types, we need to check the alignment. | |
14582 | -- If the alignment of both is specified, we can do it here. | |
14583 | ||
07fc65c4 | 14584 | if Serious_Errors_Detected = 0 |
3f1bc2cf AC |
14585 | and then Is_Access_Type (Source) |
14586 | and then Is_Access_Type (Target) | |
996ae0b0 RK |
14587 | and then Target_Strict_Alignment |
14588 | and then Present (Designated_Type (Source)) | |
14589 | and then Present (Designated_Type (Target)) | |
14590 | then | |
14591 | declare | |
14592 | D_Source : constant Entity_Id := Designated_Type (Source); | |
14593 | D_Target : constant Entity_Id := Designated_Type (Target); | |
14594 | ||
14595 | begin | |
14596 | if Known_Alignment (D_Source) | |
616547fa AC |
14597 | and then |
14598 | Known_Alignment (D_Target) | |
996ae0b0 RK |
14599 | then |
14600 | declare | |
14601 | Source_Align : constant Uint := Alignment (D_Source); | |
14602 | Target_Align : constant Uint := Alignment (D_Target); | |
14603 | ||
14604 | begin | |
14605 | if Source_Align < Target_Align | |
14606 | and then not Is_Tagged_Type (D_Source) | |
9fcf2a0b AC |
14607 | |
14608 | -- Suppress warning if warnings suppressed on either | |
14609 | -- type or either designated type. Note the use of | |
14610 | -- OR here instead of OR ELSE. That is intentional, | |
14611 | -- we would like to set flag Warnings_Off_Used in | |
14612 | -- all types for which warnings are suppressed. | |
14613 | ||
14614 | and then not (Has_Warnings_Off (D_Source) | |
14615 | or | |
14616 | Has_Warnings_Off (D_Target) | |
14617 | or | |
14618 | Has_Warnings_Off (Source) | |
14619 | or | |
14620 | Has_Warnings_Off (Target)) | |
996ae0b0 | 14621 | then |
996ae0b0 RK |
14622 | Error_Msg_Uint_1 := Target_Align; |
14623 | Error_Msg_Uint_2 := Source_Align; | |
f66d46ec | 14624 | Error_Msg_Node_1 := D_Target; |
996ae0b0 | 14625 | Error_Msg_Node_2 := D_Source; |
f66d46ec | 14626 | Error_Msg |
685bc70f | 14627 | ("?z?alignment of & (^) is stricter than " |
e5148da0 | 14628 | & "alignment of & (^)!", Eloc, Act_Unit); |
9fcf2a0b | 14629 | Error_Msg |
685bc70f | 14630 | ("\?z?resulting access value may have invalid " |
e5148da0 | 14631 | & "alignment!", Eloc, Act_Unit); |
996ae0b0 RK |
14632 | end if; |
14633 | end; | |
14634 | end if; | |
14635 | end; | |
14636 | end if; | |
14637 | end; | |
4c51ff88 AC |
14638 | |
14639 | <<Continue>> | |
14640 | null; | |
996ae0b0 RK |
14641 | end loop; |
14642 | end Validate_Unchecked_Conversions; | |
14643 | ||
996ae0b0 | 14644 | end Sem_Ch13; |