[multiple changes]
[gcc.git] / gcc / ada / sem_ch13.adb
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S E M _ C H 1 3 --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2013, Free Software Foundation, Inc. --
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- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
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 --
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. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
25
26 with Aspects; use Aspects;
27 with Atree; use Atree;
28 with Checks; use Checks;
29 with Debug; use Debug;
30 with Einfo; use Einfo;
31 with Elists; use Elists;
32 with Errout; use Errout;
33 with Exp_Disp; use Exp_Disp;
34 with Exp_Tss; use Exp_Tss;
35 with Exp_Util; use Exp_Util;
36 with Lib; use Lib;
37 with Lib.Xref; use Lib.Xref;
38 with Namet; use Namet;
39 with Nlists; use Nlists;
40 with Nmake; use Nmake;
41 with Opt; use Opt;
42 with Restrict; use Restrict;
43 with Rident; use Rident;
44 with Rtsfind; use Rtsfind;
45 with Sem; use Sem;
46 with Sem_Aux; use Sem_Aux;
47 with Sem_Ch3; use Sem_Ch3;
48 with Sem_Ch6; use Sem_Ch6;
49 with Sem_Ch8; use Sem_Ch8;
50 with Sem_Ch9; use Sem_Ch9;
51 with Sem_Dim; use Sem_Dim;
52 with Sem_Disp; use Sem_Disp;
53 with Sem_Eval; use Sem_Eval;
54 with Sem_Prag; use Sem_Prag;
55 with Sem_Res; use Sem_Res;
56 with Sem_Type; use Sem_Type;
57 with Sem_Util; use Sem_Util;
58 with Sem_Warn; use Sem_Warn;
59 with Sinput; use Sinput;
60 with Snames; use Snames;
61 with Stand; use Stand;
62 with Sinfo; use Sinfo;
63 with Stringt; use Stringt;
64 with Targparm; use Targparm;
65 with Ttypes; use Ttypes;
66 with Tbuild; use Tbuild;
67 with Urealp; use Urealp;
68 with Warnsw; use Warnsw;
69
70 with GNAT.Heap_Sort_G;
71
72 package body Sem_Ch13 is
73
74 SSU : constant Pos := System_Storage_Unit;
75 -- Convenient short hand for commonly used constant
76
77 -----------------------
78 -- Local Subprograms --
79 -----------------------
80
81 procedure Alignment_Check_For_Size_Change (Typ : Entity_Id; Size : Uint);
82 -- This routine is called after setting one of the sizes of type entity
83 -- Typ to Size. The purpose is to deal with the situation of a derived
84 -- type whose inherited alignment is no longer appropriate for the new
85 -- size value. In this case, we reset the Alignment to unknown.
86
87 procedure Build_Predicate_Functions (Typ : Entity_Id; N : Node_Id);
88 -- If Typ has predicates (indicated by Has_Predicates being set for Typ,
89 -- then either there are pragma Predicate entries on the rep chain for the
90 -- type (note that Predicate aspects are converted to pragma Predicate), or
91 -- there are inherited aspects from a parent type, or ancestor subtypes.
92 -- This procedure builds the spec and body for the Predicate function that
93 -- tests these predicates. N is the freeze node for the type. The spec of
94 -- the function is inserted before the freeze node, and the body of the
95 -- function is inserted after the freeze node. If the predicate expression
96 -- has at least one Raise_Expression, then this procedure also builds the
97 -- M version of the predicate function for use in membership tests.
98
99 procedure Build_Static_Predicate
100 (Typ : Entity_Id;
101 Expr : Node_Id;
102 Nam : Name_Id);
103 -- Given a predicated type Typ, where Typ is a discrete static subtype,
104 -- whose predicate expression is Expr, tests if Expr is a static predicate,
105 -- and if so, builds the predicate range list. Nam is the name of the one
106 -- argument to the predicate function. Occurrences of the type name in the
107 -- predicate expression have been replaced by identifier references to this
108 -- name, which is unique, so any identifier with Chars matching Nam must be
109 -- a reference to the type. If the predicate is non-static, this procedure
110 -- returns doing nothing. If the predicate is static, then the predicate
111 -- list is stored in Static_Predicate (Typ), and the Expr is rewritten as
112 -- a canonicalized membership operation.
113
114 function Get_Alignment_Value (Expr : Node_Id) return Uint;
115 -- Given the expression for an alignment value, returns the corresponding
116 -- Uint value. If the value is inappropriate, then error messages are
117 -- posted as required, and a value of No_Uint is returned.
118
119 function Is_Operational_Item (N : Node_Id) return Boolean;
120 -- A specification for a stream attribute is allowed before the full type
121 -- is declared, as explained in AI-00137 and the corrigendum. Attributes
122 -- that do not specify a representation characteristic are operational
123 -- attributes.
124
125 procedure New_Stream_Subprogram
126 (N : Node_Id;
127 Ent : Entity_Id;
128 Subp : Entity_Id;
129 Nam : TSS_Name_Type);
130 -- Create a subprogram renaming of a given stream attribute to the
131 -- designated subprogram and then in the tagged case, provide this as a
132 -- primitive operation, or in the non-tagged case make an appropriate TSS
133 -- entry. This is more properly an expansion activity than just semantics,
134 -- but the presence of user-defined stream functions for limited types is a
135 -- legality check, which is why this takes place here rather than in
136 -- exp_ch13, where it was previously. Nam indicates the name of the TSS
137 -- function to be generated.
138 --
139 -- To avoid elaboration anomalies with freeze nodes, for untagged types
140 -- we generate both a subprogram declaration and a subprogram renaming
141 -- declaration, so that the attribute specification is handled as a
142 -- renaming_as_body. For tagged types, the specification is one of the
143 -- primitive specs.
144
145 generic
146 with procedure Replace_Type_Reference (N : Node_Id);
147 procedure Replace_Type_References_Generic (N : Node_Id; TName : Name_Id);
148 -- This is used to scan an expression for a predicate or invariant aspect
149 -- replacing occurrences of the name TName (the name of the subtype to
150 -- which the aspect applies) with appropriate references to the parameter
151 -- of the predicate function or invariant procedure. The procedure passed
152 -- as a generic parameter does the actual replacement of node N, which is
153 -- either a simple direct reference to TName, or a selected component that
154 -- represents an appropriately qualified occurrence of TName.
155
156 procedure Set_Biased
157 (E : Entity_Id;
158 N : Node_Id;
159 Msg : String;
160 Biased : Boolean := True);
161 -- If Biased is True, sets Has_Biased_Representation flag for E, and
162 -- outputs a warning message at node N if Warn_On_Biased_Representation is
163 -- is True. This warning inserts the string Msg to describe the construct
164 -- causing biasing.
165
166 ----------------------------------------------
167 -- Table for Validate_Unchecked_Conversions --
168 ----------------------------------------------
169
170 -- The following table collects unchecked conversions for validation.
171 -- Entries are made by Validate_Unchecked_Conversion and then the call
172 -- to Validate_Unchecked_Conversions does the actual error checking and
173 -- posting of warnings. The reason for this delayed processing is to take
174 -- advantage of back-annotations of size and alignment values performed by
175 -- the back end.
176
177 -- Note: the reason we store a Source_Ptr value instead of a Node_Id is
178 -- that by the time Validate_Unchecked_Conversions is called, Sprint will
179 -- already have modified all Sloc values if the -gnatD option is set.
180
181 type UC_Entry is record
182 Eloc : Source_Ptr; -- node used for posting warnings
183 Source : Entity_Id; -- source type for unchecked conversion
184 Target : Entity_Id; -- target type for unchecked conversion
185 end record;
186
187 package Unchecked_Conversions is new Table.Table (
188 Table_Component_Type => UC_Entry,
189 Table_Index_Type => Int,
190 Table_Low_Bound => 1,
191 Table_Initial => 50,
192 Table_Increment => 200,
193 Table_Name => "Unchecked_Conversions");
194
195 ----------------------------------------
196 -- Table for Validate_Address_Clauses --
197 ----------------------------------------
198
199 -- If an address clause has the form
200
201 -- for X'Address use Expr
202
203 -- where Expr is of the form Y'Address or recursively is a reference to a
204 -- constant of either of these forms, and X and Y are entities of objects,
205 -- then if Y has a smaller alignment than X, that merits a warning about
206 -- possible bad alignment. The following table collects address clauses of
207 -- this kind. We put these in a table so that they can be checked after the
208 -- back end has completed annotation of the alignments of objects, since we
209 -- can catch more cases that way.
210
211 type Address_Clause_Check_Record is record
212 N : Node_Id;
213 -- The address clause
214
215 X : Entity_Id;
216 -- The entity of the object overlaying Y
217
218 Y : Entity_Id;
219 -- The entity of the object being overlaid
220
221 Off : Boolean;
222 -- Whether the address is offset within Y
223 end record;
224
225 package Address_Clause_Checks is new Table.Table (
226 Table_Component_Type => Address_Clause_Check_Record,
227 Table_Index_Type => Int,
228 Table_Low_Bound => 1,
229 Table_Initial => 20,
230 Table_Increment => 200,
231 Table_Name => "Address_Clause_Checks");
232
233 -----------------------------------------
234 -- Adjust_Record_For_Reverse_Bit_Order --
235 -----------------------------------------
236
237 procedure Adjust_Record_For_Reverse_Bit_Order (R : Entity_Id) is
238 Comp : Node_Id;
239 CC : Node_Id;
240
241 begin
242 -- Processing depends on version of Ada
243
244 -- For Ada 95, we just renumber bits within a storage unit. We do the
245 -- same for Ada 83 mode, since we recognize the Bit_Order attribute in
246 -- Ada 83, and are free to add this extension.
247
248 if Ada_Version < Ada_2005 then
249 Comp := First_Component_Or_Discriminant (R);
250 while Present (Comp) loop
251 CC := Component_Clause (Comp);
252
253 -- If component clause is present, then deal with the non-default
254 -- bit order case for Ada 95 mode.
255
256 -- We only do this processing for the base type, and in fact that
257 -- is important, since otherwise if there are record subtypes, we
258 -- could reverse the bits once for each subtype, which is wrong.
259
260 if Present (CC) and then Ekind (R) = E_Record_Type then
261 declare
262 CFB : constant Uint := Component_Bit_Offset (Comp);
263 CSZ : constant Uint := Esize (Comp);
264 CLC : constant Node_Id := Component_Clause (Comp);
265 Pos : constant Node_Id := Position (CLC);
266 FB : constant Node_Id := First_Bit (CLC);
267
268 Storage_Unit_Offset : constant Uint :=
269 CFB / System_Storage_Unit;
270
271 Start_Bit : constant Uint :=
272 CFB mod System_Storage_Unit;
273
274 begin
275 -- Cases where field goes over storage unit boundary
276
277 if Start_Bit + CSZ > System_Storage_Unit then
278
279 -- Allow multi-byte field but generate warning
280
281 if Start_Bit mod System_Storage_Unit = 0
282 and then CSZ mod System_Storage_Unit = 0
283 then
284 Error_Msg_N
285 ("multi-byte field specified with non-standard"
286 & " Bit_Order??", CLC);
287
288 if Bytes_Big_Endian then
289 Error_Msg_N
290 ("bytes are not reversed "
291 & "(component is big-endian)??", CLC);
292 else
293 Error_Msg_N
294 ("bytes are not reversed "
295 & "(component is little-endian)??", CLC);
296 end if;
297
298 -- Do not allow non-contiguous field
299
300 else
301 Error_Msg_N
302 ("attempt to specify non-contiguous field "
303 & "not permitted", CLC);
304 Error_Msg_N
305 ("\caused by non-standard Bit_Order "
306 & "specified", CLC);
307 Error_Msg_N
308 ("\consider possibility of using "
309 & "Ada 2005 mode here", CLC);
310 end if;
311
312 -- Case where field fits in one storage unit
313
314 else
315 -- Give warning if suspicious component clause
316
317 if Intval (FB) >= System_Storage_Unit
318 and then Warn_On_Reverse_Bit_Order
319 then
320 Error_Msg_N
321 ("Bit_Order clause does not affect " &
322 "byte ordering?V?", Pos);
323 Error_Msg_Uint_1 :=
324 Intval (Pos) + Intval (FB) /
325 System_Storage_Unit;
326 Error_Msg_N
327 ("position normalized to ^ before bit " &
328 "order interpreted?V?", Pos);
329 end if;
330
331 -- Here is where we fix up the Component_Bit_Offset value
332 -- to account for the reverse bit order. Some examples of
333 -- what needs to be done are:
334
335 -- First_Bit .. Last_Bit Component_Bit_Offset
336 -- old new old new
337
338 -- 0 .. 0 7 .. 7 0 7
339 -- 0 .. 1 6 .. 7 0 6
340 -- 0 .. 2 5 .. 7 0 5
341 -- 0 .. 7 0 .. 7 0 4
342
343 -- 1 .. 1 6 .. 6 1 6
344 -- 1 .. 4 3 .. 6 1 3
345 -- 4 .. 7 0 .. 3 4 0
346
347 -- The rule is that the first bit is is obtained by
348 -- subtracting the old ending bit from storage_unit - 1.
349
350 Set_Component_Bit_Offset
351 (Comp,
352 (Storage_Unit_Offset * System_Storage_Unit) +
353 (System_Storage_Unit - 1) -
354 (Start_Bit + CSZ - 1));
355
356 Set_Normalized_First_Bit
357 (Comp,
358 Component_Bit_Offset (Comp) mod
359 System_Storage_Unit);
360 end if;
361 end;
362 end if;
363
364 Next_Component_Or_Discriminant (Comp);
365 end loop;
366
367 -- For Ada 2005, we do machine scalar processing, as fully described In
368 -- AI-133. This involves gathering all components which start at the
369 -- same byte offset and processing them together. Same approach is still
370 -- valid in later versions including Ada 2012.
371
372 else
373 declare
374 Max_Machine_Scalar_Size : constant Uint :=
375 UI_From_Int
376 (Standard_Long_Long_Integer_Size);
377 -- We use this as the maximum machine scalar size
378
379 Num_CC : Natural;
380 SSU : constant Uint := UI_From_Int (System_Storage_Unit);
381
382 begin
383 -- This first loop through components does two things. First it
384 -- deals with the case of components with component clauses whose
385 -- length is greater than the maximum machine scalar size (either
386 -- accepting them or rejecting as needed). Second, it counts the
387 -- number of components with component clauses whose length does
388 -- not exceed this maximum for later processing.
389
390 Num_CC := 0;
391 Comp := First_Component_Or_Discriminant (R);
392 while Present (Comp) loop
393 CC := Component_Clause (Comp);
394
395 if Present (CC) then
396 declare
397 Fbit : constant Uint := Static_Integer (First_Bit (CC));
398 Lbit : constant Uint := Static_Integer (Last_Bit (CC));
399
400 begin
401 -- Case of component with last bit >= max machine scalar
402
403 if Lbit >= Max_Machine_Scalar_Size then
404
405 -- This is allowed only if first bit is zero, and
406 -- last bit + 1 is a multiple of storage unit size.
407
408 if Fbit = 0 and then (Lbit + 1) mod SSU = 0 then
409
410 -- This is the case to give a warning if enabled
411
412 if Warn_On_Reverse_Bit_Order then
413 Error_Msg_N
414 ("multi-byte field specified with "
415 & " non-standard Bit_Order?V?", CC);
416
417 if Bytes_Big_Endian then
418 Error_Msg_N
419 ("\bytes are not reversed "
420 & "(component is big-endian)?V?", CC);
421 else
422 Error_Msg_N
423 ("\bytes are not reversed "
424 & "(component is little-endian)?V?", CC);
425 end if;
426 end if;
427
428 -- Give error message for RM 13.5.1(10) violation
429
430 else
431 Error_Msg_FE
432 ("machine scalar rules not followed for&",
433 First_Bit (CC), Comp);
434
435 Error_Msg_Uint_1 := Lbit;
436 Error_Msg_Uint_2 := Max_Machine_Scalar_Size;
437 Error_Msg_F
438 ("\last bit (^) exceeds maximum machine "
439 & "scalar size (^)",
440 First_Bit (CC));
441
442 if (Lbit + 1) mod SSU /= 0 then
443 Error_Msg_Uint_1 := SSU;
444 Error_Msg_F
445 ("\and is not a multiple of Storage_Unit (^) "
446 & "(RM 13.4.1(10))",
447 First_Bit (CC));
448
449 else
450 Error_Msg_Uint_1 := Fbit;
451 Error_Msg_F
452 ("\and first bit (^) is non-zero "
453 & "(RM 13.4.1(10))",
454 First_Bit (CC));
455 end if;
456 end if;
457
458 -- OK case of machine scalar related component clause,
459 -- For now, just count them.
460
461 else
462 Num_CC := Num_CC + 1;
463 end if;
464 end;
465 end if;
466
467 Next_Component_Or_Discriminant (Comp);
468 end loop;
469
470 -- We need to sort the component clauses on the basis of the
471 -- Position values in the clause, so we can group clauses with
472 -- the same Position. together to determine the relevant machine
473 -- scalar size.
474
475 Sort_CC : declare
476 Comps : array (0 .. Num_CC) of Entity_Id;
477 -- Array to collect component and discriminant entities. The
478 -- data starts at index 1, the 0'th entry is for the sort
479 -- routine.
480
481 function CP_Lt (Op1, Op2 : Natural) return Boolean;
482 -- Compare routine for Sort
483
484 procedure CP_Move (From : Natural; To : Natural);
485 -- Move routine for Sort
486
487 package Sorting is new GNAT.Heap_Sort_G (CP_Move, CP_Lt);
488
489 Start : Natural;
490 Stop : Natural;
491 -- Start and stop positions in the component list of the set of
492 -- components with the same starting position (that constitute
493 -- components in a single machine scalar).
494
495 MaxL : Uint;
496 -- Maximum last bit value of any component in this set
497
498 MSS : Uint;
499 -- Corresponding machine scalar size
500
501 -----------
502 -- CP_Lt --
503 -----------
504
505 function CP_Lt (Op1, Op2 : Natural) return Boolean is
506 begin
507 return Position (Component_Clause (Comps (Op1))) <
508 Position (Component_Clause (Comps (Op2)));
509 end CP_Lt;
510
511 -------------
512 -- CP_Move --
513 -------------
514
515 procedure CP_Move (From : Natural; To : Natural) is
516 begin
517 Comps (To) := Comps (From);
518 end CP_Move;
519
520 -- Start of processing for Sort_CC
521
522 begin
523 -- Collect the machine scalar relevant component clauses
524
525 Num_CC := 0;
526 Comp := First_Component_Or_Discriminant (R);
527 while Present (Comp) loop
528 declare
529 CC : constant Node_Id := Component_Clause (Comp);
530
531 begin
532 -- Collect only component clauses whose last bit is less
533 -- than machine scalar size. Any component clause whose
534 -- last bit exceeds this value does not take part in
535 -- machine scalar layout considerations. The test for
536 -- Error_Posted makes sure we exclude component clauses
537 -- for which we already posted an error.
538
539 if Present (CC)
540 and then not Error_Posted (Last_Bit (CC))
541 and then Static_Integer (Last_Bit (CC)) <
542 Max_Machine_Scalar_Size
543 then
544 Num_CC := Num_CC + 1;
545 Comps (Num_CC) := Comp;
546 end if;
547 end;
548
549 Next_Component_Or_Discriminant (Comp);
550 end loop;
551
552 -- Sort by ascending position number
553
554 Sorting.Sort (Num_CC);
555
556 -- We now have all the components whose size does not exceed
557 -- the max machine scalar value, sorted by starting position.
558 -- In this loop we gather groups of clauses starting at the
559 -- same position, to process them in accordance with AI-133.
560
561 Stop := 0;
562 while Stop < Num_CC loop
563 Start := Stop + 1;
564 Stop := Start;
565 MaxL :=
566 Static_Integer
567 (Last_Bit (Component_Clause (Comps (Start))));
568 while Stop < Num_CC loop
569 if Static_Integer
570 (Position (Component_Clause (Comps (Stop + 1)))) =
571 Static_Integer
572 (Position (Component_Clause (Comps (Stop))))
573 then
574 Stop := Stop + 1;
575 MaxL :=
576 UI_Max
577 (MaxL,
578 Static_Integer
579 (Last_Bit
580 (Component_Clause (Comps (Stop)))));
581 else
582 exit;
583 end if;
584 end loop;
585
586 -- Now we have a group of component clauses from Start to
587 -- Stop whose positions are identical, and MaxL is the
588 -- maximum last bit value of any of these components.
589
590 -- We need to determine the corresponding machine scalar
591 -- size. This loop assumes that machine scalar sizes are
592 -- even, and that each possible machine scalar has twice
593 -- as many bits as the next smaller one.
594
595 MSS := Max_Machine_Scalar_Size;
596 while MSS mod 2 = 0
597 and then (MSS / 2) >= SSU
598 and then (MSS / 2) > MaxL
599 loop
600 MSS := MSS / 2;
601 end loop;
602
603 -- Here is where we fix up the Component_Bit_Offset value
604 -- to account for the reverse bit order. Some examples of
605 -- what needs to be done for the case of a machine scalar
606 -- size of 8 are:
607
608 -- First_Bit .. Last_Bit Component_Bit_Offset
609 -- old new old new
610
611 -- 0 .. 0 7 .. 7 0 7
612 -- 0 .. 1 6 .. 7 0 6
613 -- 0 .. 2 5 .. 7 0 5
614 -- 0 .. 7 0 .. 7 0 4
615
616 -- 1 .. 1 6 .. 6 1 6
617 -- 1 .. 4 3 .. 6 1 3
618 -- 4 .. 7 0 .. 3 4 0
619
620 -- The rule is that the first bit is obtained by subtracting
621 -- the old ending bit from machine scalar size - 1.
622
623 for C in Start .. Stop loop
624 declare
625 Comp : constant Entity_Id := Comps (C);
626 CC : constant Node_Id := Component_Clause (Comp);
627
628 LB : constant Uint := Static_Integer (Last_Bit (CC));
629 NFB : constant Uint := MSS - Uint_1 - LB;
630 NLB : constant Uint := NFB + Esize (Comp) - 1;
631 Pos : constant Uint := Static_Integer (Position (CC));
632
633 begin
634 if Warn_On_Reverse_Bit_Order then
635 Error_Msg_Uint_1 := MSS;
636 Error_Msg_N
637 ("info: reverse bit order in machine " &
638 "scalar of length^?V?", First_Bit (CC));
639 Error_Msg_Uint_1 := NFB;
640 Error_Msg_Uint_2 := NLB;
641
642 if Bytes_Big_Endian then
643 Error_Msg_NE
644 ("\info: big-endian range for "
645 & "component & is ^ .. ^?V?",
646 First_Bit (CC), Comp);
647 else
648 Error_Msg_NE
649 ("\info: little-endian range "
650 & "for component & is ^ .. ^?V?",
651 First_Bit (CC), Comp);
652 end if;
653 end if;
654
655 Set_Component_Bit_Offset (Comp, Pos * SSU + NFB);
656 Set_Normalized_First_Bit (Comp, NFB mod SSU);
657 end;
658 end loop;
659 end loop;
660 end Sort_CC;
661 end;
662 end if;
663 end Adjust_Record_For_Reverse_Bit_Order;
664
665 -------------------------------------
666 -- Alignment_Check_For_Size_Change --
667 -------------------------------------
668
669 procedure Alignment_Check_For_Size_Change (Typ : Entity_Id; Size : Uint) is
670 begin
671 -- If the alignment is known, and not set by a rep clause, and is
672 -- inconsistent with the size being set, then reset it to unknown,
673 -- we assume in this case that the size overrides the inherited
674 -- alignment, and that the alignment must be recomputed.
675
676 if Known_Alignment (Typ)
677 and then not Has_Alignment_Clause (Typ)
678 and then Size mod (Alignment (Typ) * SSU) /= 0
679 then
680 Init_Alignment (Typ);
681 end if;
682 end Alignment_Check_For_Size_Change;
683
684 -------------------------------------
685 -- Analyze_Aspects_At_Freeze_Point --
686 -------------------------------------
687
688 procedure Analyze_Aspects_At_Freeze_Point (E : Entity_Id) is
689 ASN : Node_Id;
690 A_Id : Aspect_Id;
691 Ritem : Node_Id;
692
693 procedure Analyze_Aspect_Default_Value (ASN : Node_Id);
694 -- This routine analyzes an Aspect_Default_[Component_]Value denoted by
695 -- the aspect specification node ASN.
696
697 procedure Inherit_Delayed_Rep_Aspects (ASN : Node_Id);
698 -- As discussed in the spec of Aspects (see Aspect_Delay declaration),
699 -- a derived type can inherit aspects from its parent which have been
700 -- specified at the time of the derivation using an aspect, as in:
701 --
702 -- type A is range 1 .. 10
703 -- with Size => Not_Defined_Yet;
704 -- ..
705 -- type B is new A;
706 -- ..
707 -- Not_Defined_Yet : constant := 64;
708 --
709 -- In this example, the Size of A is considered to be specified prior
710 -- to the derivation, and thus inherited, even though the value is not
711 -- known at the time of derivation. To deal with this, we use two entity
712 -- flags. The flag Has_Derived_Rep_Aspects is set in the parent type (A
713 -- here), and then the flag May_Inherit_Delayed_Rep_Aspects is set in
714 -- the derived type (B here). If this flag is set when the derived type
715 -- is frozen, then this procedure is called to ensure proper inheritance
716 -- of all delayed aspects from the parent type. The derived type is E,
717 -- the argument to Analyze_Aspects_At_Freeze_Point. ASN is the first
718 -- aspect specification node in the Rep_Item chain for the parent type.
719
720 procedure Make_Pragma_From_Boolean_Aspect (ASN : Node_Id);
721 -- Given an aspect specification node ASN whose expression is an
722 -- optional Boolean, this routines creates the corresponding pragma
723 -- at the freezing point.
724
725 ----------------------------------
726 -- Analyze_Aspect_Default_Value --
727 ----------------------------------
728
729 procedure Analyze_Aspect_Default_Value (ASN : Node_Id) is
730 Ent : constant Entity_Id := Entity (ASN);
731 Expr : constant Node_Id := Expression (ASN);
732 Id : constant Node_Id := Identifier (ASN);
733
734 begin
735 Error_Msg_Name_1 := Chars (Id);
736
737 if not Is_Type (Ent) then
738 Error_Msg_N ("aspect% can only apply to a type", Id);
739 return;
740
741 elsif not Is_First_Subtype (Ent) then
742 Error_Msg_N ("aspect% cannot apply to subtype", Id);
743 return;
744
745 elsif A_Id = Aspect_Default_Value
746 and then not Is_Scalar_Type (Ent)
747 then
748 Error_Msg_N ("aspect% can only be applied to scalar type", Id);
749 return;
750
751 elsif A_Id = Aspect_Default_Component_Value then
752 if not Is_Array_Type (Ent) then
753 Error_Msg_N ("aspect% can only be applied to array type", Id);
754 return;
755
756 elsif not Is_Scalar_Type (Component_Type (Ent)) then
757 Error_Msg_N ("aspect% requires scalar components", Id);
758 return;
759 end if;
760 end if;
761
762 Set_Has_Default_Aspect (Base_Type (Ent));
763
764 if Is_Scalar_Type (Ent) then
765 Set_Default_Aspect_Value (Ent, Expr);
766
767 -- Place default value of base type as well, because that is
768 -- the semantics of the aspect. It is convenient to link the
769 -- aspect to both the (possibly anonymous) base type and to
770 -- the given first subtype.
771
772 Set_Default_Aspect_Value (Base_Type (Ent), Expr);
773
774 else
775 Set_Default_Aspect_Component_Value (Ent, Expr);
776 end if;
777 end Analyze_Aspect_Default_Value;
778
779 ---------------------------------
780 -- Inherit_Delayed_Rep_Aspects --
781 ---------------------------------
782
783 procedure Inherit_Delayed_Rep_Aspects (ASN : Node_Id) is
784 P : constant Entity_Id := Entity (ASN);
785 -- Entithy for parent type
786
787 N : Node_Id;
788 -- Item from Rep_Item chain
789
790 A : Aspect_Id;
791
792 begin
793 -- Loop through delayed aspects for the parent type
794
795 N := ASN;
796 while Present (N) loop
797 if Nkind (N) = N_Aspect_Specification then
798 exit when Entity (N) /= P;
799
800 if Is_Delayed_Aspect (N) then
801 A := Get_Aspect_Id (Chars (Identifier (N)));
802
803 -- Process delayed rep aspect. For Boolean attributes it is
804 -- not possible to cancel an attribute once set (the attempt
805 -- to use an aspect with xxx => False is an error) for a
806 -- derived type. So for those cases, we do not have to check
807 -- if a clause has been given for the derived type, since it
808 -- is harmless to set it again if it is already set.
809
810 case A is
811
812 -- Alignment
813
814 when Aspect_Alignment =>
815 if not Has_Alignment_Clause (E) then
816 Set_Alignment (E, Alignment (P));
817 end if;
818
819 -- Atomic
820
821 when Aspect_Atomic =>
822 if Is_Atomic (P) then
823 Set_Is_Atomic (E);
824 end if;
825
826 -- Atomic_Components
827
828 when Aspect_Atomic_Components =>
829 if Has_Atomic_Components (P) then
830 Set_Has_Atomic_Components (Base_Type (E));
831 end if;
832
833 -- Bit_Order
834
835 when Aspect_Bit_Order =>
836 if Is_Record_Type (E)
837 and then No (Get_Attribute_Definition_Clause
838 (E, Attribute_Bit_Order))
839 and then Reverse_Bit_Order (P)
840 then
841 Set_Reverse_Bit_Order (Base_Type (E));
842 end if;
843
844 -- Component_Size
845
846 when Aspect_Component_Size =>
847 if Is_Array_Type (E)
848 and then not Has_Component_Size_Clause (E)
849 then
850 Set_Component_Size
851 (Base_Type (E), Component_Size (P));
852 end if;
853
854 -- Machine_Radix
855
856 when Aspect_Machine_Radix =>
857 if Is_Decimal_Fixed_Point_Type (E)
858 and then not Has_Machine_Radix_Clause (E)
859 then
860 Set_Machine_Radix_10 (E, Machine_Radix_10 (P));
861 end if;
862
863 -- Object_Size (also Size which also sets Object_Size)
864
865 when Aspect_Object_Size | Aspect_Size =>
866 if not Has_Size_Clause (E)
867 and then
868 No (Get_Attribute_Definition_Clause
869 (E, Attribute_Object_Size))
870 then
871 Set_Esize (E, Esize (P));
872 end if;
873
874 -- Pack
875
876 when Aspect_Pack =>
877 if not Is_Packed (E) then
878 Set_Is_Packed (Base_Type (E));
879
880 if Is_Bit_Packed_Array (P) then
881 Set_Is_Bit_Packed_Array (Base_Type (E));
882 Set_Packed_Array_Type (E, Packed_Array_Type (P));
883 end if;
884 end if;
885
886 -- Scalar_Storage_Order
887
888 when Aspect_Scalar_Storage_Order =>
889 if (Is_Record_Type (E) or else Is_Array_Type (E))
890 and then No (Get_Attribute_Definition_Clause
891 (E, Attribute_Scalar_Storage_Order))
892 and then Reverse_Storage_Order (P)
893 then
894 Set_Reverse_Storage_Order (Base_Type (E));
895 end if;
896
897 -- Small
898
899 when Aspect_Small =>
900 if Is_Fixed_Point_Type (E)
901 and then not Has_Small_Clause (E)
902 then
903 Set_Small_Value (E, Small_Value (P));
904 end if;
905
906 -- Storage_Size
907
908 when Aspect_Storage_Size =>
909 if (Is_Access_Type (E) or else Is_Task_Type (E))
910 and then not Has_Storage_Size_Clause (E)
911 then
912 Set_Storage_Size_Variable
913 (Base_Type (E), Storage_Size_Variable (P));
914 end if;
915
916 -- Value_Size
917
918 when Aspect_Value_Size =>
919
920 -- Value_Size is never inherited, it is either set by
921 -- default, or it is explicitly set for the derived
922 -- type. So nothing to do here.
923
924 null;
925
926 -- Volatile
927
928 when Aspect_Volatile =>
929 if Is_Volatile (P) then
930 Set_Is_Volatile (E);
931 end if;
932
933 -- Volatile_Components
934
935 when Aspect_Volatile_Components =>
936 if Has_Volatile_Components (P) then
937 Set_Has_Volatile_Components (Base_Type (E));
938 end if;
939
940 -- That should be all the Rep Aspects
941
942 when others =>
943 pragma Assert (Aspect_Delay (A_Id) /= Rep_Aspect);
944 null;
945
946 end case;
947 end if;
948 end if;
949
950 N := Next_Rep_Item (N);
951 end loop;
952 end Inherit_Delayed_Rep_Aspects;
953
954 -------------------------------------
955 -- Make_Pragma_From_Boolean_Aspect --
956 -------------------------------------
957
958 procedure Make_Pragma_From_Boolean_Aspect (ASN : Node_Id) is
959 Ident : constant Node_Id := Identifier (ASN);
960 A_Name : constant Name_Id := Chars (Ident);
961 A_Id : constant Aspect_Id := Get_Aspect_Id (A_Name);
962 Ent : constant Entity_Id := Entity (ASN);
963 Expr : constant Node_Id := Expression (ASN);
964 Loc : constant Source_Ptr := Sloc (ASN);
965
966 Prag : Node_Id;
967
968 procedure Check_False_Aspect_For_Derived_Type;
969 -- This procedure checks for the case of a false aspect for a derived
970 -- type, which improperly tries to cancel an aspect inherited from
971 -- the parent.
972
973 -----------------------------------------
974 -- Check_False_Aspect_For_Derived_Type --
975 -----------------------------------------
976
977 procedure Check_False_Aspect_For_Derived_Type is
978 Par : Node_Id;
979
980 begin
981 -- We are only checking derived types
982
983 if not Is_Derived_Type (E) then
984 return;
985 end if;
986
987 Par := Nearest_Ancestor (E);
988
989 case A_Id is
990 when Aspect_Atomic | Aspect_Shared =>
991 if not Is_Atomic (Par) then
992 return;
993 end if;
994
995 when Aspect_Atomic_Components =>
996 if not Has_Atomic_Components (Par) then
997 return;
998 end if;
999
1000 when Aspect_Discard_Names =>
1001 if not Discard_Names (Par) then
1002 return;
1003 end if;
1004
1005 when Aspect_Pack =>
1006 if not Is_Packed (Par) then
1007 return;
1008 end if;
1009
1010 when Aspect_Unchecked_Union =>
1011 if not Is_Unchecked_Union (Par) then
1012 return;
1013 end if;
1014
1015 when Aspect_Volatile =>
1016 if not Is_Volatile (Par) then
1017 return;
1018 end if;
1019
1020 when Aspect_Volatile_Components =>
1021 if not Has_Volatile_Components (Par) then
1022 return;
1023 end if;
1024
1025 when others =>
1026 return;
1027 end case;
1028
1029 -- Fall through means we are canceling an inherited aspect
1030
1031 Error_Msg_Name_1 := A_Name;
1032 Error_Msg_NE
1033 ("derived type& inherits aspect%, cannot cancel", Expr, E);
1034
1035 end Check_False_Aspect_For_Derived_Type;
1036
1037 -- Start of processing for Make_Pragma_From_Boolean_Aspect
1038
1039 begin
1040 -- Note that we know Expr is present, because for a missing Expr
1041 -- argument, we knew it was True and did not need to delay the
1042 -- evaluation to the freeze point.
1043
1044 if Is_False (Static_Boolean (Expr)) then
1045 Check_False_Aspect_For_Derived_Type;
1046
1047 else
1048 Prag :=
1049 Make_Pragma (Loc,
1050 Pragma_Argument_Associations => New_List (
1051 Make_Pragma_Argument_Association (Sloc (Ident),
1052 Expression => New_Occurrence_Of (Ent, Sloc (Ident)))),
1053
1054 Pragma_Identifier =>
1055 Make_Identifier (Sloc (Ident), Chars (Ident)));
1056
1057 Set_From_Aspect_Specification (Prag, True);
1058 Set_Corresponding_Aspect (Prag, ASN);
1059 Set_Aspect_Rep_Item (ASN, Prag);
1060 Set_Is_Delayed_Aspect (Prag);
1061 Set_Parent (Prag, ASN);
1062 end if;
1063 end Make_Pragma_From_Boolean_Aspect;
1064
1065 -- Start of processing for Analyze_Aspects_At_Freeze_Point
1066
1067 begin
1068 -- Must be visible in current scope
1069
1070 if not Scope_Within_Or_Same (Current_Scope, Scope (E)) then
1071 return;
1072 end if;
1073
1074 -- Look for aspect specification entries for this entity
1075
1076 ASN := First_Rep_Item (E);
1077 while Present (ASN) loop
1078 if Nkind (ASN) = N_Aspect_Specification then
1079 exit when Entity (ASN) /= E;
1080
1081 if Is_Delayed_Aspect (ASN) then
1082 A_Id := Get_Aspect_Id (ASN);
1083
1084 case A_Id is
1085
1086 -- For aspects whose expression is an optional Boolean, make
1087 -- the corresponding pragma at the freezing point.
1088
1089 when Boolean_Aspects |
1090 Library_Unit_Aspects =>
1091 Make_Pragma_From_Boolean_Aspect (ASN);
1092
1093 -- Special handling for aspects that don't correspond to
1094 -- pragmas/attributes.
1095
1096 when Aspect_Default_Value |
1097 Aspect_Default_Component_Value =>
1098 Analyze_Aspect_Default_Value (ASN);
1099
1100 -- Ditto for iterator aspects, because the corresponding
1101 -- attributes may not have been analyzed yet.
1102
1103 when Aspect_Constant_Indexing |
1104 Aspect_Variable_Indexing |
1105 Aspect_Default_Iterator |
1106 Aspect_Iterator_Element =>
1107 Analyze (Expression (ASN));
1108
1109 when others =>
1110 null;
1111 end case;
1112
1113 Ritem := Aspect_Rep_Item (ASN);
1114
1115 if Present (Ritem) then
1116 Analyze (Ritem);
1117 end if;
1118 end if;
1119 end if;
1120
1121 Next_Rep_Item (ASN);
1122 end loop;
1123
1124 -- This is where we inherit delayed rep aspects from our parent. Note
1125 -- that if we fell out of the above loop with ASN non-empty, it means
1126 -- we hit an aspect for an entity other than E, and it must be the
1127 -- type from which we were derived.
1128
1129 if May_Inherit_Delayed_Rep_Aspects (E) then
1130 Inherit_Delayed_Rep_Aspects (ASN);
1131 end if;
1132 end Analyze_Aspects_At_Freeze_Point;
1133
1134 -----------------------------------
1135 -- Analyze_Aspect_Specifications --
1136 -----------------------------------
1137
1138 procedure Analyze_Aspect_Specifications (N : Node_Id; E : Entity_Id) is
1139 procedure Decorate_Delayed_Aspect_And_Pragma
1140 (Asp : Node_Id;
1141 Prag : Node_Id);
1142 -- Establish the linkages between a delayed aspect and its corresponding
1143 -- pragma. Set all delay-related flags on both constructs.
1144
1145 procedure Insert_Delayed_Pragma (Prag : Node_Id);
1146 -- Insert a postcondition-like pragma into the tree depending on the
1147 -- context. Prag must denote one of the following: Pre, Post, Depends,
1148 -- Global or Contract_Cases.
1149
1150 ----------------------------------------
1151 -- Decorate_Delayed_Aspect_And_Pragma --
1152 ----------------------------------------
1153
1154 procedure Decorate_Delayed_Aspect_And_Pragma
1155 (Asp : Node_Id;
1156 Prag : Node_Id)
1157 is
1158 begin
1159 Set_Aspect_Rep_Item (Asp, Prag);
1160 Set_Corresponding_Aspect (Prag, Asp);
1161 Set_From_Aspect_Specification (Prag);
1162 Set_Is_Delayed_Aspect (Prag);
1163 Set_Is_Delayed_Aspect (Asp);
1164 Set_Parent (Prag, Asp);
1165 end Decorate_Delayed_Aspect_And_Pragma;
1166
1167 ---------------------------
1168 -- Insert_Delayed_Pragma --
1169 ---------------------------
1170
1171 procedure Insert_Delayed_Pragma (Prag : Node_Id) is
1172 Aux : Node_Id;
1173
1174 begin
1175 -- When the context is a library unit, the pragma is added to the
1176 -- Pragmas_After list.
1177
1178 if Nkind (Parent (N)) = N_Compilation_Unit then
1179 Aux := Aux_Decls_Node (Parent (N));
1180
1181 if No (Pragmas_After (Aux)) then
1182 Set_Pragmas_After (Aux, New_List);
1183 end if;
1184
1185 Prepend (Prag, Pragmas_After (Aux));
1186
1187 -- Pragmas associated with subprogram bodies are inserted in the
1188 -- declarative part.
1189
1190 elsif Nkind (N) = N_Subprogram_Body then
1191 if No (Declarations (N)) then
1192 Set_Declarations (N, New_List (Prag));
1193 else
1194 declare
1195 D : Node_Id;
1196 begin
1197
1198 -- There may be several aspects associated with the body;
1199 -- preserve the ordering of the corresponding pragmas.
1200
1201 D := First (Declarations (N));
1202 while Present (D) loop
1203 exit when Nkind (D) /= N_Pragma
1204 or else not From_Aspect_Specification (D);
1205 Next (D);
1206 end loop;
1207
1208 if No (D) then
1209 Append (Prag, Declarations (N));
1210 else
1211 Insert_Before (D, Prag);
1212 end if;
1213 end;
1214 end if;
1215
1216 -- Default
1217
1218 else
1219 Insert_After (N, Prag);
1220
1221 -- Analyze the pragma before analyzing the proper body of a stub.
1222 -- This ensures that the pragma will appear on the proper contract
1223 -- list (see N_Contract).
1224
1225 if Nkind (N) = N_Subprogram_Body_Stub then
1226 Analyze (Prag);
1227 end if;
1228 end if;
1229 end Insert_Delayed_Pragma;
1230
1231 -- Local variables
1232
1233 Aspect : Node_Id;
1234 Aitem : Node_Id;
1235 Ent : Node_Id;
1236
1237 L : constant List_Id := Aspect_Specifications (N);
1238
1239 Ins_Node : Node_Id := N;
1240 -- Insert pragmas/attribute definition clause after this node when no
1241 -- delayed analysis is required.
1242
1243 -- Start of processing for Analyze_Aspect_Specifications
1244
1245 -- The general processing involves building an attribute definition
1246 -- clause or a pragma node that corresponds to the aspect. Then in order
1247 -- to delay the evaluation of this aspect to the freeze point, we attach
1248 -- the corresponding pragma/attribute definition clause to the aspect
1249 -- specification node, which is then placed in the Rep Item chain. In
1250 -- this case we mark the entity by setting the flag Has_Delayed_Aspects
1251 -- and we evaluate the rep item at the freeze point. When the aspect
1252 -- doesn't have a corresponding pragma/attribute definition clause, then
1253 -- its analysis is simply delayed at the freeze point.
1254
1255 -- Some special cases don't require delay analysis, thus the aspect is
1256 -- analyzed right now.
1257
1258 -- Note that there is a special handling for Pre, Post, Test_Case,
1259 -- Contract_Cases aspects. In these cases, we do not have to worry
1260 -- about delay issues, since the pragmas themselves deal with delay
1261 -- of visibility for the expression analysis. Thus, we just insert
1262 -- the pragma after the node N.
1263
1264 begin
1265 pragma Assert (Present (L));
1266
1267 -- Loop through aspects
1268
1269 Aspect := First (L);
1270 Aspect_Loop : while Present (Aspect) loop
1271 Analyze_One_Aspect : declare
1272 Expr : constant Node_Id := Expression (Aspect);
1273 Id : constant Node_Id := Identifier (Aspect);
1274 Loc : constant Source_Ptr := Sloc (Aspect);
1275 Nam : constant Name_Id := Chars (Id);
1276 A_Id : constant Aspect_Id := Get_Aspect_Id (Nam);
1277 Anod : Node_Id;
1278
1279 Delay_Required : Boolean;
1280 -- Set False if delay is not required
1281
1282 Eloc : Source_Ptr := No_Location;
1283 -- Source location of expression, modified when we split PPC's. It
1284 -- is set below when Expr is present.
1285
1286 procedure Analyze_Aspect_External_Or_Link_Name;
1287 -- Perform analysis of the External_Name or Link_Name aspects
1288
1289 procedure Analyze_Aspect_Implicit_Dereference;
1290 -- Perform analysis of the Implicit_Dereference aspects
1291
1292 procedure Make_Aitem_Pragma
1293 (Pragma_Argument_Associations : List_Id;
1294 Pragma_Name : Name_Id);
1295 -- This is a wrapper for Make_Pragma used for converting aspects
1296 -- to pragmas. It takes care of Sloc (set from Loc) and building
1297 -- the pragma identifier from the given name. In addition the
1298 -- flags Class_Present and Split_PPC are set from the aspect
1299 -- node, as well as Is_Ignored. This routine also sets the
1300 -- From_Aspect_Specification in the resulting pragma node to
1301 -- True, and sets Corresponding_Aspect to point to the aspect.
1302 -- The resulting pragma is assigned to Aitem.
1303
1304 ------------------------------------------
1305 -- Analyze_Aspect_External_Or_Link_Name --
1306 ------------------------------------------
1307
1308 procedure Analyze_Aspect_External_Or_Link_Name is
1309 begin
1310 -- Verify that there is an Import/Export aspect defined for the
1311 -- entity. The processing of that aspect in turn checks that
1312 -- there is a Convention aspect declared. The pragma is
1313 -- constructed when processing the Convention aspect.
1314
1315 declare
1316 A : Node_Id;
1317
1318 begin
1319 A := First (L);
1320 while Present (A) loop
1321 exit when Nam_In (Chars (Identifier (A)), Name_Export,
1322 Name_Import);
1323 Next (A);
1324 end loop;
1325
1326 if No (A) then
1327 Error_Msg_N
1328 ("missing Import/Export for Link/External name",
1329 Aspect);
1330 end if;
1331 end;
1332 end Analyze_Aspect_External_Or_Link_Name;
1333
1334 -----------------------------------------
1335 -- Analyze_Aspect_Implicit_Dereference --
1336 -----------------------------------------
1337
1338 procedure Analyze_Aspect_Implicit_Dereference is
1339 begin
1340 if not Is_Type (E) or else not Has_Discriminants (E) then
1341 Error_Msg_N
1342 ("aspect must apply to a type with discriminants", N);
1343
1344 else
1345 declare
1346 Disc : Entity_Id;
1347
1348 begin
1349 Disc := First_Discriminant (E);
1350 while Present (Disc) loop
1351 if Chars (Expr) = Chars (Disc)
1352 and then Ekind (Etype (Disc)) =
1353 E_Anonymous_Access_Type
1354 then
1355 Set_Has_Implicit_Dereference (E);
1356 Set_Has_Implicit_Dereference (Disc);
1357 return;
1358 end if;
1359
1360 Next_Discriminant (Disc);
1361 end loop;
1362
1363 -- Error if no proper access discriminant.
1364
1365 Error_Msg_NE
1366 ("not an access discriminant of&", Expr, E);
1367 end;
1368 end if;
1369 end Analyze_Aspect_Implicit_Dereference;
1370
1371 -----------------------
1372 -- Make_Aitem_Pragma --
1373 -----------------------
1374
1375 procedure Make_Aitem_Pragma
1376 (Pragma_Argument_Associations : List_Id;
1377 Pragma_Name : Name_Id)
1378 is
1379 Args : List_Id := Pragma_Argument_Associations;
1380
1381 begin
1382 -- We should never get here if aspect was disabled
1383
1384 pragma Assert (not Is_Disabled (Aspect));
1385
1386 -- Certan aspects allow for an optional name or expression. Do
1387 -- not generate a pragma with an empty argument association
1388 -- list.
1389
1390 if No (Args) or else No (Expression (First (Args))) then
1391 Args := No_List;
1392 end if;
1393
1394 -- Build the pragma
1395
1396 Aitem :=
1397 Make_Pragma (Loc,
1398 Pragma_Argument_Associations => Args,
1399 Pragma_Identifier =>
1400 Make_Identifier (Sloc (Id), Pragma_Name),
1401 Class_Present => Class_Present (Aspect),
1402 Split_PPC => Split_PPC (Aspect));
1403
1404 -- Set additional semantic fields
1405
1406 if Is_Ignored (Aspect) then
1407 Set_Is_Ignored (Aitem);
1408 elsif Is_Checked (Aspect) then
1409 Set_Is_Checked (Aitem);
1410 end if;
1411
1412 Set_Corresponding_Aspect (Aitem, Aspect);
1413 Set_From_Aspect_Specification (Aitem, True);
1414 end Make_Aitem_Pragma;
1415
1416 -- Start of processing for Analyze_One_Aspect
1417
1418 begin
1419 -- Skip aspect if already analyzed (not clear if this is needed)
1420
1421 if Analyzed (Aspect) then
1422 goto Continue;
1423 end if;
1424
1425 -- Skip looking at aspect if it is totally disabled. Just mark
1426 -- it as such for later reference in the tree. This also sets
1427 -- the Is_Ignored and Is_Checked flags appropriately.
1428
1429 Check_Applicable_Policy (Aspect);
1430
1431 if Is_Disabled (Aspect) then
1432 goto Continue;
1433 end if;
1434
1435 -- Set the source location of expression, used in the case of
1436 -- a failed precondition/postcondition or invariant. Note that
1437 -- the source location of the expression is not usually the best
1438 -- choice here. For example, it gets located on the last AND
1439 -- keyword in a chain of boolean expressiond AND'ed together.
1440 -- It is best to put the message on the first character of the
1441 -- assertion, which is the effect of the First_Node call here.
1442
1443 if Present (Expr) then
1444 Eloc := Sloc (First_Node (Expr));
1445 end if;
1446
1447 -- Check restriction No_Implementation_Aspect_Specifications
1448
1449 if Implementation_Defined_Aspect (A_Id) then
1450 Check_Restriction
1451 (No_Implementation_Aspect_Specifications, Aspect);
1452 end if;
1453
1454 -- Check restriction No_Specification_Of_Aspect
1455
1456 Check_Restriction_No_Specification_Of_Aspect (Aspect);
1457
1458 -- Analyze this aspect (actual analysis is delayed till later)
1459
1460 Set_Analyzed (Aspect);
1461 Set_Entity (Aspect, E);
1462 Ent := New_Occurrence_Of (E, Sloc (Id));
1463
1464 -- Check for duplicate aspect. Note that the Comes_From_Source
1465 -- test allows duplicate Pre/Post's that we generate internally
1466 -- to escape being flagged here.
1467
1468 if No_Duplicates_Allowed (A_Id) then
1469 Anod := First (L);
1470 while Anod /= Aspect loop
1471 if Comes_From_Source (Aspect)
1472 and then Same_Aspect (A_Id, Get_Aspect_Id (Anod))
1473 then
1474 Error_Msg_Name_1 := Nam;
1475 Error_Msg_Sloc := Sloc (Anod);
1476
1477 -- Case of same aspect specified twice
1478
1479 if Class_Present (Anod) = Class_Present (Aspect) then
1480 if not Class_Present (Anod) then
1481 Error_Msg_NE
1482 ("aspect% for & previously given#",
1483 Id, E);
1484 else
1485 Error_Msg_NE
1486 ("aspect `%''Class` for & previously given#",
1487 Id, E);
1488 end if;
1489 end if;
1490 end if;
1491
1492 Next (Anod);
1493 end loop;
1494 end if;
1495
1496 -- Check some general restrictions on language defined aspects
1497
1498 if not Implementation_Defined_Aspect (A_Id) then
1499 Error_Msg_Name_1 := Nam;
1500
1501 -- Not allowed for renaming declarations
1502
1503 if Nkind (N) in N_Renaming_Declaration then
1504 Error_Msg_N
1505 ("aspect % not allowed for renaming declaration",
1506 Aspect);
1507 end if;
1508
1509 -- Not allowed for formal type declarations
1510
1511 if Nkind (N) = N_Formal_Type_Declaration then
1512 Error_Msg_N
1513 ("aspect % not allowed for formal type declaration",
1514 Aspect);
1515 end if;
1516 end if;
1517
1518 -- Copy expression for later processing by the procedures
1519 -- Check_Aspect_At_[Freeze_Point | End_Of_Declarations]
1520
1521 Set_Entity (Id, New_Copy_Tree (Expr));
1522
1523 -- Set Delay_Required as appropriate to aspect
1524
1525 case Aspect_Delay (A_Id) is
1526 when Always_Delay =>
1527 Delay_Required := True;
1528
1529 when Never_Delay =>
1530 Delay_Required := False;
1531
1532 when Rep_Aspect =>
1533
1534 -- If expression has the form of an integer literal, then
1535 -- do not delay, since we know the value cannot change.
1536 -- This optimization catches most rep clause cases.
1537
1538 if (Present (Expr) and then Nkind (Expr) = N_Integer_Literal)
1539 or else (A_Id in Boolean_Aspects and then No (Expr))
1540 then
1541 Delay_Required := False;
1542 else
1543 Delay_Required := True;
1544 Set_Has_Delayed_Rep_Aspects (E);
1545 end if;
1546 end case;
1547
1548 -- Processing based on specific aspect
1549
1550 case A_Id is
1551
1552 -- No_Aspect should be impossible
1553
1554 when No_Aspect =>
1555 raise Program_Error;
1556
1557 -- Case 1: Aspects corresponding to attribute definition
1558 -- clauses.
1559
1560 when Aspect_Address |
1561 Aspect_Alignment |
1562 Aspect_Bit_Order |
1563 Aspect_Component_Size |
1564 Aspect_Constant_Indexing |
1565 Aspect_Default_Iterator |
1566 Aspect_Dispatching_Domain |
1567 Aspect_External_Tag |
1568 Aspect_Input |
1569 Aspect_Iterator_Element |
1570 Aspect_Machine_Radix |
1571 Aspect_Object_Size |
1572 Aspect_Output |
1573 Aspect_Read |
1574 Aspect_Scalar_Storage_Order |
1575 Aspect_Size |
1576 Aspect_Small |
1577 Aspect_Simple_Storage_Pool |
1578 Aspect_Storage_Pool |
1579 Aspect_Stream_Size |
1580 Aspect_Value_Size |
1581 Aspect_Variable_Indexing |
1582 Aspect_Write =>
1583
1584 -- Indexing aspects apply only to tagged type
1585
1586 if (A_Id = Aspect_Constant_Indexing
1587 or else
1588 A_Id = Aspect_Variable_Indexing)
1589 and then not (Is_Type (E)
1590 and then Is_Tagged_Type (E))
1591 then
1592 Error_Msg_N ("indexing applies to a tagged type", N);
1593 goto Continue;
1594 end if;
1595
1596 -- For case of address aspect, we don't consider that we
1597 -- know the entity is never set in the source, since it is
1598 -- is likely aliasing is occurring.
1599
1600 -- Note: one might think that the analysis of the resulting
1601 -- attribute definition clause would take care of that, but
1602 -- that's not the case since it won't be from source.
1603
1604 if A_Id = Aspect_Address then
1605 Set_Never_Set_In_Source (E, False);
1606 end if;
1607
1608 -- Construct the attribute definition clause
1609
1610 Aitem :=
1611 Make_Attribute_Definition_Clause (Loc,
1612 Name => Ent,
1613 Chars => Chars (Id),
1614 Expression => Relocate_Node (Expr));
1615
1616 -- If the address is specified, then we treat the entity as
1617 -- referenced, to avoid spurious warnings. This is analogous
1618 -- to what is done with an attribute definition clause, but
1619 -- here we don't want to generate a reference because this
1620 -- is the point of definition of the entity.
1621
1622 if A_Id = Aspect_Address then
1623 Set_Referenced (E);
1624 end if;
1625
1626 -- Case 2: Aspects corresponding to pragmas
1627
1628 -- Case 2a: Aspects corresponding to pragmas with two
1629 -- arguments, where the first argument is a local name
1630 -- referring to the entity, and the second argument is the
1631 -- aspect definition expression.
1632
1633 -- Suppress/Unsuppress
1634
1635 when Aspect_Suppress |
1636 Aspect_Unsuppress =>
1637
1638 Make_Aitem_Pragma
1639 (Pragma_Argument_Associations => New_List (
1640 Make_Pragma_Argument_Association (Loc,
1641 Expression => New_Occurrence_Of (E, Loc)),
1642 Make_Pragma_Argument_Association (Sloc (Expr),
1643 Expression => Relocate_Node (Expr))),
1644 Pragma_Name => Chars (Id));
1645
1646 -- Synchronization
1647
1648 -- Corresponds to pragma Implemented, construct the pragma
1649
1650 when Aspect_Synchronization =>
1651
1652 Make_Aitem_Pragma
1653 (Pragma_Argument_Associations => New_List (
1654 Make_Pragma_Argument_Association (Loc,
1655 Expression => New_Occurrence_Of (E, Loc)),
1656 Make_Pragma_Argument_Association (Sloc (Expr),
1657 Expression => Relocate_Node (Expr))),
1658 Pragma_Name => Name_Implemented);
1659
1660 -- Attach Handler
1661
1662 when Aspect_Attach_Handler =>
1663 Make_Aitem_Pragma
1664 (Pragma_Argument_Associations => New_List (
1665 Make_Pragma_Argument_Association (Sloc (Ent),
1666 Expression => Ent),
1667 Make_Pragma_Argument_Association (Sloc (Expr),
1668 Expression => Relocate_Node (Expr))),
1669 Pragma_Name => Name_Attach_Handler);
1670
1671 -- Dynamic_Predicate, Predicate, Static_Predicate
1672
1673 when Aspect_Dynamic_Predicate |
1674 Aspect_Predicate |
1675 Aspect_Static_Predicate =>
1676
1677 -- Construct the pragma (always a pragma Predicate, with
1678 -- flags recording whether it is static/dynamic). We also
1679 -- set flags recording this in the type itself.
1680
1681 Make_Aitem_Pragma
1682 (Pragma_Argument_Associations => New_List (
1683 Make_Pragma_Argument_Association (Sloc (Ent),
1684 Expression => Ent),
1685 Make_Pragma_Argument_Association (Sloc (Expr),
1686 Expression => Relocate_Node (Expr))),
1687 Pragma_Name => Name_Predicate);
1688
1689 -- Mark type has predicates, and remember what kind of
1690 -- aspect lead to this predicate (we need this to access
1691 -- the right set of check policies later on).
1692
1693 Set_Has_Predicates (E);
1694
1695 if A_Id = Aspect_Dynamic_Predicate then
1696 Set_Has_Dynamic_Predicate_Aspect (E);
1697 elsif A_Id = Aspect_Static_Predicate then
1698 Set_Has_Static_Predicate_Aspect (E);
1699 end if;
1700
1701 -- If the type is private, indicate that its completion
1702 -- has a freeze node, because that is the one that will be
1703 -- visible at freeze time.
1704
1705 if Is_Private_Type (E) and then Present (Full_View (E)) then
1706 Set_Has_Predicates (Full_View (E));
1707
1708 if A_Id = Aspect_Dynamic_Predicate then
1709 Set_Has_Dynamic_Predicate_Aspect (Full_View (E));
1710 elsif A_Id = Aspect_Static_Predicate then
1711 Set_Has_Static_Predicate_Aspect (Full_View (E));
1712 end if;
1713
1714 Set_Has_Delayed_Aspects (Full_View (E));
1715 Ensure_Freeze_Node (Full_View (E));
1716 end if;
1717
1718 -- Case 2b: Aspects corresponding to pragmas with two
1719 -- arguments, where the second argument is a local name
1720 -- referring to the entity, and the first argument is the
1721 -- aspect definition expression.
1722
1723 -- Convention
1724
1725 when Aspect_Convention =>
1726
1727 -- The aspect may be part of the specification of an import
1728 -- or export pragma. Scan the aspect list to gather the
1729 -- other components, if any. The name of the generated
1730 -- pragma is one of Convention/Import/Export.
1731
1732 declare
1733 P_Name : Name_Id;
1734 A_Name : Name_Id;
1735 A : Node_Id;
1736 Arg_List : List_Id;
1737 Found : Boolean;
1738 L_Assoc : Node_Id;
1739 E_Assoc : Node_Id;
1740
1741 begin
1742 P_Name := Chars (Id);
1743 Found := False;
1744 Arg_List := New_List;
1745 L_Assoc := Empty;
1746 E_Assoc := Empty;
1747
1748 A := First (L);
1749 while Present (A) loop
1750 A_Name := Chars (Identifier (A));
1751
1752 if Nam_In (A_Name, Name_Import, Name_Export) then
1753 if Found then
1754 Error_Msg_N ("conflicting", A);
1755 else
1756 Found := True;
1757 end if;
1758
1759 P_Name := A_Name;
1760
1761 elsif A_Name = Name_Link_Name then
1762 L_Assoc :=
1763 Make_Pragma_Argument_Association (Loc,
1764 Chars => A_Name,
1765 Expression => Relocate_Node (Expression (A)));
1766
1767 elsif A_Name = Name_External_Name then
1768 E_Assoc :=
1769 Make_Pragma_Argument_Association (Loc,
1770 Chars => A_Name,
1771 Expression => Relocate_Node (Expression (A)));
1772 end if;
1773
1774 Next (A);
1775 end loop;
1776
1777 Arg_List := New_List (
1778 Make_Pragma_Argument_Association (Sloc (Expr),
1779 Expression => Relocate_Node (Expr)),
1780 Make_Pragma_Argument_Association (Sloc (Ent),
1781 Expression => Ent));
1782
1783 if Present (L_Assoc) then
1784 Append_To (Arg_List, L_Assoc);
1785 end if;
1786
1787 if Present (E_Assoc) then
1788 Append_To (Arg_List, E_Assoc);
1789 end if;
1790
1791 Make_Aitem_Pragma
1792 (Pragma_Argument_Associations => Arg_List,
1793 Pragma_Name => P_Name);
1794 end;
1795
1796 -- CPU, Interrupt_Priority, Priority
1797
1798 -- These three aspects can be specified for a subprogram body,
1799 -- in which case we generate pragmas for them and insert them
1800 -- ahead of local declarations, rather than after the body.
1801
1802 when Aspect_CPU |
1803 Aspect_Interrupt_Priority |
1804 Aspect_Priority =>
1805
1806 if Nkind (N) = N_Subprogram_Body then
1807 Make_Aitem_Pragma
1808 (Pragma_Argument_Associations => New_List (
1809 Make_Pragma_Argument_Association (Sloc (Expr),
1810 Expression => Relocate_Node (Expr))),
1811 Pragma_Name => Chars (Id));
1812
1813 else
1814 Aitem :=
1815 Make_Attribute_Definition_Clause (Loc,
1816 Name => Ent,
1817 Chars => Chars (Id),
1818 Expression => Relocate_Node (Expr));
1819 end if;
1820
1821 -- Warnings
1822
1823 when Aspect_Warnings =>
1824 Make_Aitem_Pragma
1825 (Pragma_Argument_Associations => New_List (
1826 Make_Pragma_Argument_Association (Sloc (Expr),
1827 Expression => Relocate_Node (Expr)),
1828 Make_Pragma_Argument_Association (Loc,
1829 Expression => New_Occurrence_Of (E, Loc))),
1830 Pragma_Name => Chars (Id));
1831
1832 -- Case 2c: Aspects corresponding to pragmas with three
1833 -- arguments.
1834
1835 -- Invariant aspects have a first argument that references the
1836 -- entity, a second argument that is the expression and a third
1837 -- argument that is an appropriate message.
1838
1839 -- Invariant, Type_Invariant
1840
1841 when Aspect_Invariant |
1842 Aspect_Type_Invariant =>
1843
1844 -- Analysis of the pragma will verify placement legality:
1845 -- an invariant must apply to a private type, or appear in
1846 -- the private part of a spec and apply to a completion.
1847
1848 Make_Aitem_Pragma
1849 (Pragma_Argument_Associations => New_List (
1850 Make_Pragma_Argument_Association (Sloc (Ent),
1851 Expression => Ent),
1852 Make_Pragma_Argument_Association (Sloc (Expr),
1853 Expression => Relocate_Node (Expr))),
1854 Pragma_Name => Name_Invariant);
1855
1856 -- Add message unless exception messages are suppressed
1857
1858 if not Opt.Exception_Locations_Suppressed then
1859 Append_To (Pragma_Argument_Associations (Aitem),
1860 Make_Pragma_Argument_Association (Eloc,
1861 Chars => Name_Message,
1862 Expression =>
1863 Make_String_Literal (Eloc,
1864 Strval => "failed invariant from "
1865 & Build_Location_String (Eloc))));
1866 end if;
1867
1868 -- For Invariant case, insert immediately after the entity
1869 -- declaration. We do not have to worry about delay issues
1870 -- since the pragma processing takes care of this.
1871
1872 Delay_Required := False;
1873
1874 -- Case 2d : Aspects that correspond to a pragma with one
1875 -- argument.
1876
1877 -- Abstract_State
1878
1879 when Aspect_Abstract_State =>
1880 Make_Aitem_Pragma
1881 (Pragma_Argument_Associations => New_List (
1882 Make_Pragma_Argument_Association (Loc,
1883 Expression => Relocate_Node (Expr))),
1884 Pragma_Name => Name_Abstract_State);
1885
1886 -- Depends
1887
1888 -- Aspect Depends must be delayed because it mentions names
1889 -- of inputs and output that are classified by aspect Global.
1890 -- The aspect and pragma are treated the same way as a post
1891 -- condition.
1892
1893 when Aspect_Depends =>
1894 Make_Aitem_Pragma
1895 (Pragma_Argument_Associations => New_List (
1896 Make_Pragma_Argument_Association (Loc,
1897 Expression => Relocate_Node (Expr))),
1898 Pragma_Name => Name_Depends);
1899
1900 Decorate_Delayed_Aspect_And_Pragma (Aspect, Aitem);
1901 Insert_Delayed_Pragma (Aitem);
1902 goto Continue;
1903
1904 -- Global
1905
1906 -- Aspect Global must be delayed because it can mention names
1907 -- and benefit from the forward visibility rules applicable to
1908 -- aspects of subprograms. The aspect and pragma are treated
1909 -- the same way as a post condition.
1910
1911 when Aspect_Global =>
1912 Make_Aitem_Pragma
1913 (Pragma_Argument_Associations => New_List (
1914 Make_Pragma_Argument_Association (Loc,
1915 Expression => Relocate_Node (Expr))),
1916 Pragma_Name => Name_Global);
1917
1918 Decorate_Delayed_Aspect_And_Pragma (Aspect, Aitem);
1919 Insert_Delayed_Pragma (Aitem);
1920 goto Continue;
1921
1922 -- SPARK_Mode
1923
1924 when Aspect_SPARK_Mode =>
1925 Make_Aitem_Pragma
1926 (Pragma_Argument_Associations => New_List (
1927 Make_Pragma_Argument_Association (Loc,
1928 Expression => Relocate_Node (Expr))),
1929 Pragma_Name => Name_SPARK_Mode);
1930
1931 -- Relative_Deadline
1932
1933 when Aspect_Relative_Deadline =>
1934 Make_Aitem_Pragma
1935 (Pragma_Argument_Associations => New_List (
1936 Make_Pragma_Argument_Association (Loc,
1937 Expression => Relocate_Node (Expr))),
1938 Pragma_Name => Name_Relative_Deadline);
1939
1940 -- If the aspect applies to a task, the corresponding pragma
1941 -- must appear within its declarations, not after.
1942
1943 if Nkind (N) = N_Task_Type_Declaration then
1944 declare
1945 Def : Node_Id;
1946 V : List_Id;
1947
1948 begin
1949 if No (Task_Definition (N)) then
1950 Set_Task_Definition (N,
1951 Make_Task_Definition (Loc,
1952 Visible_Declarations => New_List,
1953 End_Label => Empty));
1954 end if;
1955
1956 Def := Task_Definition (N);
1957 V := Visible_Declarations (Def);
1958 if not Is_Empty_List (V) then
1959 Insert_Before (First (V), Aitem);
1960
1961 else
1962 Set_Visible_Declarations (Def, New_List (Aitem));
1963 end if;
1964
1965 goto Continue;
1966 end;
1967 end if;
1968
1969 -- Case 3 : Aspects that don't correspond to pragma/attribute
1970 -- definition clause.
1971
1972 -- Case 3a: The aspects listed below don't correspond to
1973 -- pragmas/attributes but do require delayed analysis.
1974
1975 -- Default_Value, Default_Component_Value
1976
1977 when Aspect_Default_Value |
1978 Aspect_Default_Component_Value =>
1979 Aitem := Empty;
1980
1981 -- Case 3b: The aspects listed below don't correspond to
1982 -- pragmas/attributes and don't need delayed analysis.
1983
1984 -- Implicit_Dereference
1985
1986 -- For Implicit_Dereference, External_Name and Link_Name, only
1987 -- the legality checks are done during the analysis, thus no
1988 -- delay is required.
1989
1990 when Aspect_Implicit_Dereference =>
1991 Analyze_Aspect_Implicit_Dereference;
1992 goto Continue;
1993
1994 -- External_Name, Link_Name
1995
1996 when Aspect_External_Name |
1997 Aspect_Link_Name =>
1998 Analyze_Aspect_External_Or_Link_Name;
1999 goto Continue;
2000
2001 -- Dimension
2002
2003 when Aspect_Dimension =>
2004 Analyze_Aspect_Dimension (N, Id, Expr);
2005 goto Continue;
2006
2007 -- Dimension_System
2008
2009 when Aspect_Dimension_System =>
2010 Analyze_Aspect_Dimension_System (N, Id, Expr);
2011 goto Continue;
2012
2013 -- Case 4: Aspects requiring special handling
2014
2015 -- Pre/Post/Test_Case/Contract_Cases whose corresponding
2016 -- pragmas take care of the delay.
2017
2018 -- Pre/Post
2019
2020 -- Aspects Pre/Post generate Precondition/Postcondition pragmas
2021 -- with a first argument that is the expression, and a second
2022 -- argument that is an informative message if the test fails.
2023 -- This is inserted right after the declaration, to get the
2024 -- required pragma placement. The processing for the pragmas
2025 -- takes care of the required delay.
2026
2027 when Pre_Post_Aspects => Pre_Post : declare
2028 Pname : Name_Id;
2029
2030 begin
2031 if A_Id = Aspect_Pre or else A_Id = Aspect_Precondition then
2032 Pname := Name_Precondition;
2033 else
2034 Pname := Name_Postcondition;
2035 end if;
2036
2037 -- If the expressions is of the form A and then B, then
2038 -- we generate separate Pre/Post aspects for the separate
2039 -- clauses. Since we allow multiple pragmas, there is no
2040 -- problem in allowing multiple Pre/Post aspects internally.
2041 -- These should be treated in reverse order (B first and
2042 -- A second) since they are later inserted just after N in
2043 -- the order they are treated. This way, the pragma for A
2044 -- ends up preceding the pragma for B, which may have an
2045 -- importance for the error raised (either constraint error
2046 -- or precondition error).
2047
2048 -- We do not do this for Pre'Class, since we have to put
2049 -- these conditions together in a complex OR expression
2050
2051 -- We do not do this in ASIS mode, as ASIS relies on the
2052 -- original node representing the complete expression, when
2053 -- retrieving it through the source aspect table.
2054
2055 if not ASIS_Mode
2056 and then (Pname = Name_Postcondition
2057 or else not Class_Present (Aspect))
2058 then
2059 while Nkind (Expr) = N_And_Then loop
2060 Insert_After (Aspect,
2061 Make_Aspect_Specification (Sloc (Left_Opnd (Expr)),
2062 Identifier => Identifier (Aspect),
2063 Expression => Relocate_Node (Left_Opnd (Expr)),
2064 Class_Present => Class_Present (Aspect),
2065 Split_PPC => True));
2066 Rewrite (Expr, Relocate_Node (Right_Opnd (Expr)));
2067 Eloc := Sloc (Expr);
2068 end loop;
2069 end if;
2070
2071 -- Build the precondition/postcondition pragma
2072
2073 -- Add note about why we do NOT need Copy_Tree here ???
2074
2075 Make_Aitem_Pragma
2076 (Pragma_Argument_Associations => New_List (
2077 Make_Pragma_Argument_Association (Eloc,
2078 Chars => Name_Check,
2079 Expression => Relocate_Node (Expr))),
2080 Pragma_Name => Pname);
2081
2082 -- Add message unless exception messages are suppressed
2083
2084 if not Opt.Exception_Locations_Suppressed then
2085 Append_To (Pragma_Argument_Associations (Aitem),
2086 Make_Pragma_Argument_Association (Eloc,
2087 Chars => Name_Message,
2088 Expression =>
2089 Make_String_Literal (Eloc,
2090 Strval => "failed "
2091 & Get_Name_String (Pname)
2092 & " from "
2093 & Build_Location_String (Eloc))));
2094 end if;
2095
2096 Set_Is_Delayed_Aspect (Aspect);
2097
2098 -- For Pre/Post cases, insert immediately after the entity
2099 -- declaration, since that is the required pragma placement.
2100 -- Note that for these aspects, we do not have to worry
2101 -- about delay issues, since the pragmas themselves deal
2102 -- with delay of visibility for the expression analysis.
2103
2104 Insert_Delayed_Pragma (Aitem);
2105 goto Continue;
2106 end Pre_Post;
2107
2108 -- Test_Case
2109
2110 when Aspect_Test_Case => Test_Case : declare
2111 Args : List_Id;
2112 Comp_Expr : Node_Id;
2113 Comp_Assn : Node_Id;
2114 New_Expr : Node_Id;
2115
2116 begin
2117 Args := New_List;
2118
2119 if Nkind (Parent (N)) = N_Compilation_Unit then
2120 Error_Msg_Name_1 := Nam;
2121 Error_Msg_N ("incorrect placement of aspect `%`", E);
2122 goto Continue;
2123 end if;
2124
2125 if Nkind (Expr) /= N_Aggregate then
2126 Error_Msg_Name_1 := Nam;
2127 Error_Msg_NE
2128 ("wrong syntax for aspect `%` for &", Id, E);
2129 goto Continue;
2130 end if;
2131
2132 -- Make pragma expressions refer to the original aspect
2133 -- expressions through the Original_Node link. This is
2134 -- used in semantic analysis for ASIS mode, so that the
2135 -- original expression also gets analyzed.
2136
2137 Comp_Expr := First (Expressions (Expr));
2138 while Present (Comp_Expr) loop
2139 New_Expr := Relocate_Node (Comp_Expr);
2140 Set_Original_Node (New_Expr, Comp_Expr);
2141 Append_To (Args,
2142 Make_Pragma_Argument_Association (Sloc (Comp_Expr),
2143 Expression => New_Expr));
2144 Next (Comp_Expr);
2145 end loop;
2146
2147 Comp_Assn := First (Component_Associations (Expr));
2148 while Present (Comp_Assn) loop
2149 if List_Length (Choices (Comp_Assn)) /= 1
2150 or else
2151 Nkind (First (Choices (Comp_Assn))) /= N_Identifier
2152 then
2153 Error_Msg_Name_1 := Nam;
2154 Error_Msg_NE
2155 ("wrong syntax for aspect `%` for &", Id, E);
2156 goto Continue;
2157 end if;
2158
2159 New_Expr := Relocate_Node (Expression (Comp_Assn));
2160 Set_Original_Node (New_Expr, Expression (Comp_Assn));
2161 Append_To (Args,
2162 Make_Pragma_Argument_Association (Sloc (Comp_Assn),
2163 Chars => Chars (First (Choices (Comp_Assn))),
2164 Expression => New_Expr));
2165 Next (Comp_Assn);
2166 end loop;
2167
2168 -- Build the test-case pragma
2169
2170 Make_Aitem_Pragma
2171 (Pragma_Argument_Associations => Args,
2172 Pragma_Name => Nam);
2173 end Test_Case;
2174
2175 -- Contract_Cases
2176
2177 when Aspect_Contract_Cases =>
2178 Make_Aitem_Pragma
2179 (Pragma_Argument_Associations => New_List (
2180 Make_Pragma_Argument_Association (Loc,
2181 Expression => Relocate_Node (Expr))),
2182 Pragma_Name => Nam);
2183
2184 Decorate_Delayed_Aspect_And_Pragma (Aspect, Aitem);
2185 Insert_Delayed_Pragma (Aitem);
2186 goto Continue;
2187
2188 -- Case 5: Special handling for aspects with an optional
2189 -- boolean argument.
2190
2191 -- In the general case, the corresponding pragma cannot be
2192 -- generated yet because the evaluation of the boolean needs
2193 -- to be delayed till the freeze point.
2194
2195 when Boolean_Aspects |
2196 Library_Unit_Aspects =>
2197
2198 Set_Is_Boolean_Aspect (Aspect);
2199
2200 -- Lock_Free aspect only apply to protected objects
2201
2202 if A_Id = Aspect_Lock_Free then
2203 if Ekind (E) /= E_Protected_Type then
2204 Error_Msg_Name_1 := Nam;
2205 Error_Msg_N
2206 ("aspect % only applies to a protected object",
2207 Aspect);
2208
2209 else
2210 -- Set the Uses_Lock_Free flag to True if there is no
2211 -- expression or if the expression is True. The
2212 -- evaluation of this aspect should be delayed to the
2213 -- freeze point (why???)
2214
2215 if No (Expr)
2216 or else Is_True (Static_Boolean (Expr))
2217 then
2218 Set_Uses_Lock_Free (E);
2219 end if;
2220
2221 Record_Rep_Item (E, Aspect);
2222 end if;
2223
2224 goto Continue;
2225
2226 elsif A_Id = Aspect_Import or else A_Id = Aspect_Export then
2227
2228 -- Verify that there is an aspect Convention that will
2229 -- incorporate the Import/Export aspect, and eventual
2230 -- Link/External names.
2231
2232 declare
2233 A : Node_Id;
2234
2235 begin
2236 A := First (L);
2237 while Present (A) loop
2238 exit when Chars (Identifier (A)) = Name_Convention;
2239 Next (A);
2240 end loop;
2241
2242 -- It is legal to specify Import for a variable, in
2243 -- order to suppress initialization for it, without
2244 -- specifying explicitly its convention. However this
2245 -- is only legal if the convention of the object type
2246 -- is Ada or similar.
2247
2248 if No (A) then
2249 if Ekind (E) = E_Variable
2250 and then A_Id = Aspect_Import
2251 then
2252 declare
2253 C : constant Convention_Id :=
2254 Convention (Etype (E));
2255 begin
2256 if C = Convention_Ada or else
2257 C = Convention_Ada_Pass_By_Copy or else
2258 C = Convention_Ada_Pass_By_Reference
2259 then
2260 goto Continue;
2261 end if;
2262 end;
2263 end if;
2264
2265 -- Otherwise, Convention must be specified
2266
2267 Error_Msg_N
2268 ("missing Convention aspect for Export/Import",
2269 Aspect);
2270 end if;
2271 end;
2272
2273 goto Continue;
2274 end if;
2275
2276 -- Library unit aspects require special handling in the case
2277 -- of a package declaration, the pragma needs to be inserted
2278 -- in the list of declarations for the associated package.
2279 -- There is no issue of visibility delay for these aspects.
2280
2281 if A_Id in Library_Unit_Aspects
2282 and then
2283 Nkind_In (N, N_Package_Declaration,
2284 N_Generic_Package_Declaration)
2285 and then Nkind (Parent (N)) /= N_Compilation_Unit
2286 then
2287 Error_Msg_N
2288 ("incorrect context for library unit aspect&", Id);
2289 goto Continue;
2290 end if;
2291
2292 -- Cases where we do not delay, includes all cases where
2293 -- the expression is missing other than the above cases.
2294
2295 if not Delay_Required or else No (Expr) then
2296 Make_Aitem_Pragma
2297 (Pragma_Argument_Associations => New_List (
2298 Make_Pragma_Argument_Association (Sloc (Ent),
2299 Expression => Ent)),
2300 Pragma_Name => Chars (Id));
2301 Delay_Required := False;
2302
2303 -- In general cases, the corresponding pragma/attribute
2304 -- definition clause will be inserted later at the freezing
2305 -- point, and we do not need to build it now
2306
2307 else
2308 Aitem := Empty;
2309 end if;
2310
2311 -- Storage_Size
2312
2313 -- This is special because for access types we need to generate
2314 -- an attribute definition clause. This also works for single
2315 -- task declarations, but it does not work for task type
2316 -- declarations, because we have the case where the expression
2317 -- references a discriminant of the task type. That can't use
2318 -- an attribute definition clause because we would not have
2319 -- visibility on the discriminant. For that case we must
2320 -- generate a pragma in the task definition.
2321
2322 when Aspect_Storage_Size =>
2323
2324 -- Task type case
2325
2326 if Ekind (E) = E_Task_Type then
2327 declare
2328 Decl : constant Node_Id := Declaration_Node (E);
2329
2330 begin
2331 pragma Assert (Nkind (Decl) = N_Task_Type_Declaration);
2332
2333 -- If no task definition, create one
2334
2335 if No (Task_Definition (Decl)) then
2336 Set_Task_Definition (Decl,
2337 Make_Task_Definition (Loc,
2338 Visible_Declarations => Empty_List,
2339 End_Label => Empty));
2340 end if;
2341
2342 -- Create a pragma and put it at the start of the
2343 -- task definition for the task type declaration.
2344
2345 Make_Aitem_Pragma
2346 (Pragma_Argument_Associations => New_List (
2347 Make_Pragma_Argument_Association (Loc,
2348 Expression => Relocate_Node (Expr))),
2349 Pragma_Name => Name_Storage_Size);
2350
2351 Prepend
2352 (Aitem,
2353 Visible_Declarations (Task_Definition (Decl)));
2354 goto Continue;
2355 end;
2356
2357 -- All other cases, generate attribute definition
2358
2359 else
2360 Aitem :=
2361 Make_Attribute_Definition_Clause (Loc,
2362 Name => Ent,
2363 Chars => Chars (Id),
2364 Expression => Relocate_Node (Expr));
2365 end if;
2366 end case;
2367
2368 -- Attach the corresponding pragma/attribute definition clause to
2369 -- the aspect specification node.
2370
2371 if Present (Aitem) then
2372 Set_From_Aspect_Specification (Aitem, True);
2373 end if;
2374
2375 -- Aspect Abstract_State introduces implicit declarations for all
2376 -- state abstraction entities it defines. To emulate this behavior
2377 -- insert the pragma at the start of the visible declarations of
2378 -- the related package.
2379
2380 if Nam = Name_Abstract_State
2381 and then Nkind (N) = N_Package_Declaration
2382 then
2383 if No (Visible_Declarations (Specification (N))) then
2384 Set_Visible_Declarations (Specification (N), New_List);
2385 end if;
2386
2387 Prepend (Aitem, Visible_Declarations (Specification (N)));
2388 goto Continue;
2389
2390 -- In the context of a compilation unit, we directly put the
2391 -- pragma in the Pragmas_After list of the N_Compilation_Unit_Aux
2392 -- node (no delay is required here) except for aspects on a
2393 -- subprogram body (see below) and a generic package, for which
2394 -- we need to introduce the pragma before building the generic
2395 -- copy (see sem_ch12), and for package instantiations, where
2396 -- the library unit pragmas are better handled early.
2397
2398 elsif Nkind (Parent (N)) = N_Compilation_Unit
2399 and then (Present (Aitem) or else Is_Boolean_Aspect (Aspect))
2400 then
2401 declare
2402 Aux : constant Node_Id := Aux_Decls_Node (Parent (N));
2403
2404 begin
2405 pragma Assert (Nkind (Aux) = N_Compilation_Unit_Aux);
2406
2407 -- For a Boolean aspect, create the corresponding pragma if
2408 -- no expression or if the value is True.
2409
2410 if Is_Boolean_Aspect (Aspect) and then No (Aitem) then
2411 if Is_True (Static_Boolean (Expr)) then
2412 Make_Aitem_Pragma
2413 (Pragma_Argument_Associations => New_List (
2414 Make_Pragma_Argument_Association (Sloc (Ent),
2415 Expression => Ent)),
2416 Pragma_Name => Chars (Id));
2417
2418 Set_From_Aspect_Specification (Aitem, True);
2419 Set_Corresponding_Aspect (Aitem, Aspect);
2420
2421 else
2422 goto Continue;
2423 end if;
2424 end if;
2425
2426 -- If the aspect is on a subprogram body (relevant aspects
2427 -- are Inline and Priority), add the pragma in front of
2428 -- the declarations.
2429
2430 if Nkind (N) = N_Subprogram_Body then
2431 if No (Declarations (N)) then
2432 Set_Declarations (N, New_List);
2433 end if;
2434
2435 Prepend (Aitem, Declarations (N));
2436
2437 elsif Nkind (N) = N_Generic_Package_Declaration then
2438 if No (Visible_Declarations (Specification (N))) then
2439 Set_Visible_Declarations (Specification (N), New_List);
2440 end if;
2441
2442 Prepend (Aitem,
2443 Visible_Declarations (Specification (N)));
2444
2445 elsif Nkind (N) = N_Package_Instantiation then
2446 declare
2447 Spec : constant Node_Id :=
2448 Specification (Instance_Spec (N));
2449 begin
2450 if No (Visible_Declarations (Spec)) then
2451 Set_Visible_Declarations (Spec, New_List);
2452 end if;
2453
2454 Prepend (Aitem, Visible_Declarations (Spec));
2455 end;
2456
2457 else
2458 if No (Pragmas_After (Aux)) then
2459 Set_Pragmas_After (Aux, New_List);
2460 end if;
2461
2462 Append (Aitem, Pragmas_After (Aux));
2463 end if;
2464
2465 goto Continue;
2466 end;
2467 end if;
2468
2469 -- The evaluation of the aspect is delayed to the freezing point.
2470 -- The pragma or attribute clause if there is one is then attached
2471 -- to the aspect specification which is put in the rep item list.
2472
2473 if Delay_Required then
2474 if Present (Aitem) then
2475 Set_Is_Delayed_Aspect (Aitem);
2476 Set_Aspect_Rep_Item (Aspect, Aitem);
2477 Set_Parent (Aitem, Aspect);
2478 end if;
2479
2480 Set_Is_Delayed_Aspect (Aspect);
2481
2482 -- In the case of Default_Value, link the aspect to base type
2483 -- as well, even though it appears on a first subtype. This is
2484 -- mandated by the semantics of the aspect. Do not establish
2485 -- the link when processing the base type itself as this leads
2486 -- to a rep item circularity. Verify that we are dealing with
2487 -- a scalar type to prevent cascaded errors.
2488
2489 if A_Id = Aspect_Default_Value
2490 and then Is_Scalar_Type (E)
2491 and then Base_Type (E) /= E
2492 then
2493 Set_Has_Delayed_Aspects (Base_Type (E));
2494 Record_Rep_Item (Base_Type (E), Aspect);
2495 end if;
2496
2497 Set_Has_Delayed_Aspects (E);
2498 Record_Rep_Item (E, Aspect);
2499
2500 -- When delay is not required and the context is a package or a
2501 -- subprogram body, insert the pragma in the body declarations.
2502
2503 elsif Nkind_In (N, N_Package_Body, N_Subprogram_Body) then
2504 if No (Declarations (N)) then
2505 Set_Declarations (N, New_List);
2506 end if;
2507
2508 -- The pragma is added before source declarations
2509
2510 Prepend_To (Declarations (N), Aitem);
2511
2512 -- When delay is not required and the context is not a compilation
2513 -- unit, we simply insert the pragma/attribute definition clause
2514 -- in sequence.
2515
2516 else
2517 Insert_After (Ins_Node, Aitem);
2518 Ins_Node := Aitem;
2519 end if;
2520 end Analyze_One_Aspect;
2521
2522 <<Continue>>
2523 Next (Aspect);
2524 end loop Aspect_Loop;
2525
2526 if Has_Delayed_Aspects (E) then
2527 Ensure_Freeze_Node (E);
2528 end if;
2529 end Analyze_Aspect_Specifications;
2530
2531 -----------------------
2532 -- Analyze_At_Clause --
2533 -----------------------
2534
2535 -- An at clause is replaced by the corresponding Address attribute
2536 -- definition clause that is the preferred approach in Ada 95.
2537
2538 procedure Analyze_At_Clause (N : Node_Id) is
2539 CS : constant Boolean := Comes_From_Source (N);
2540
2541 begin
2542 -- This is an obsolescent feature
2543
2544 Check_Restriction (No_Obsolescent_Features, N);
2545
2546 if Warn_On_Obsolescent_Feature then
2547 Error_Msg_N
2548 ("?j?at clause is an obsolescent feature (RM J.7(2))", N);
2549 Error_Msg_N
2550 ("\?j?use address attribute definition clause instead", N);
2551 end if;
2552
2553 -- Rewrite as address clause
2554
2555 Rewrite (N,
2556 Make_Attribute_Definition_Clause (Sloc (N),
2557 Name => Identifier (N),
2558 Chars => Name_Address,
2559 Expression => Expression (N)));
2560
2561 -- We preserve Comes_From_Source, since logically the clause still comes
2562 -- from the source program even though it is changed in form.
2563
2564 Set_Comes_From_Source (N, CS);
2565
2566 -- Analyze rewritten clause
2567
2568 Analyze_Attribute_Definition_Clause (N);
2569 end Analyze_At_Clause;
2570
2571 -----------------------------------------
2572 -- Analyze_Attribute_Definition_Clause --
2573 -----------------------------------------
2574
2575 procedure Analyze_Attribute_Definition_Clause (N : Node_Id) is
2576 Loc : constant Source_Ptr := Sloc (N);
2577 Nam : constant Node_Id := Name (N);
2578 Attr : constant Name_Id := Chars (N);
2579 Expr : constant Node_Id := Expression (N);
2580 Id : constant Attribute_Id := Get_Attribute_Id (Attr);
2581
2582 Ent : Entity_Id;
2583 -- The entity of Nam after it is analyzed. In the case of an incomplete
2584 -- type, this is the underlying type.
2585
2586 U_Ent : Entity_Id;
2587 -- The underlying entity to which the attribute applies. Generally this
2588 -- is the Underlying_Type of Ent, except in the case where the clause
2589 -- applies to full view of incomplete type or private type in which case
2590 -- U_Ent is just a copy of Ent.
2591
2592 FOnly : Boolean := False;
2593 -- Reset to True for subtype specific attribute (Alignment, Size)
2594 -- and for stream attributes, i.e. those cases where in the call
2595 -- to Rep_Item_Too_Late, FOnly is set True so that only the freezing
2596 -- rules are checked. Note that the case of stream attributes is not
2597 -- clear from the RM, but see AI95-00137. Also, the RM seems to
2598 -- disallow Storage_Size for derived task types, but that is also
2599 -- clearly unintentional.
2600
2601 procedure Analyze_Stream_TSS_Definition (TSS_Nam : TSS_Name_Type);
2602 -- Common processing for 'Read, 'Write, 'Input and 'Output attribute
2603 -- definition clauses.
2604
2605 function Duplicate_Clause return Boolean;
2606 -- This routine checks if the aspect for U_Ent being given by attribute
2607 -- definition clause N is for an aspect that has already been specified,
2608 -- and if so gives an error message. If there is a duplicate, True is
2609 -- returned, otherwise if there is no error, False is returned.
2610
2611 procedure Check_Indexing_Functions;
2612 -- Check that the function in Constant_Indexing or Variable_Indexing
2613 -- attribute has the proper type structure. If the name is overloaded,
2614 -- check that some interpretation is legal.
2615
2616 procedure Check_Iterator_Functions;
2617 -- Check that there is a single function in Default_Iterator attribute
2618 -- has the proper type structure.
2619
2620 function Check_Primitive_Function (Subp : Entity_Id) return Boolean;
2621 -- Common legality check for the previous two
2622
2623 -----------------------------------
2624 -- Analyze_Stream_TSS_Definition --
2625 -----------------------------------
2626
2627 procedure Analyze_Stream_TSS_Definition (TSS_Nam : TSS_Name_Type) is
2628 Subp : Entity_Id := Empty;
2629 I : Interp_Index;
2630 It : Interp;
2631 Pnam : Entity_Id;
2632
2633 Is_Read : constant Boolean := (TSS_Nam = TSS_Stream_Read);
2634 -- True for Read attribute, false for other attributes
2635
2636 function Has_Good_Profile (Subp : Entity_Id) return Boolean;
2637 -- Return true if the entity is a subprogram with an appropriate
2638 -- profile for the attribute being defined.
2639
2640 ----------------------
2641 -- Has_Good_Profile --
2642 ----------------------
2643
2644 function Has_Good_Profile (Subp : Entity_Id) return Boolean is
2645 F : Entity_Id;
2646 Is_Function : constant Boolean := (TSS_Nam = TSS_Stream_Input);
2647 Expected_Ekind : constant array (Boolean) of Entity_Kind :=
2648 (False => E_Procedure, True => E_Function);
2649 Typ : Entity_Id;
2650
2651 begin
2652 if Ekind (Subp) /= Expected_Ekind (Is_Function) then
2653 return False;
2654 end if;
2655
2656 F := First_Formal (Subp);
2657
2658 if No (F)
2659 or else Ekind (Etype (F)) /= E_Anonymous_Access_Type
2660 or else Designated_Type (Etype (F)) /=
2661 Class_Wide_Type (RTE (RE_Root_Stream_Type))
2662 then
2663 return False;
2664 end if;
2665
2666 if not Is_Function then
2667 Next_Formal (F);
2668
2669 declare
2670 Expected_Mode : constant array (Boolean) of Entity_Kind :=
2671 (False => E_In_Parameter,
2672 True => E_Out_Parameter);
2673 begin
2674 if Parameter_Mode (F) /= Expected_Mode (Is_Read) then
2675 return False;
2676 end if;
2677 end;
2678
2679 Typ := Etype (F);
2680
2681 else
2682 Typ := Etype (Subp);
2683 end if;
2684
2685 return Base_Type (Typ) = Base_Type (Ent)
2686 and then No (Next_Formal (F));
2687 end Has_Good_Profile;
2688
2689 -- Start of processing for Analyze_Stream_TSS_Definition
2690
2691 begin
2692 FOnly := True;
2693
2694 if not Is_Type (U_Ent) then
2695 Error_Msg_N ("local name must be a subtype", Nam);
2696 return;
2697 end if;
2698
2699 Pnam := TSS (Base_Type (U_Ent), TSS_Nam);
2700
2701 -- If Pnam is present, it can be either inherited from an ancestor
2702 -- type (in which case it is legal to redefine it for this type), or
2703 -- be a previous definition of the attribute for the same type (in
2704 -- which case it is illegal).
2705
2706 -- In the first case, it will have been analyzed already, and we
2707 -- can check that its profile does not match the expected profile
2708 -- for a stream attribute of U_Ent. In the second case, either Pnam
2709 -- has been analyzed (and has the expected profile), or it has not
2710 -- been analyzed yet (case of a type that has not been frozen yet
2711 -- and for which the stream attribute has been set using Set_TSS).
2712
2713 if Present (Pnam)
2714 and then (No (First_Entity (Pnam)) or else Has_Good_Profile (Pnam))
2715 then
2716 Error_Msg_Sloc := Sloc (Pnam);
2717 Error_Msg_Name_1 := Attr;
2718 Error_Msg_N ("% attribute already defined #", Nam);
2719 return;
2720 end if;
2721
2722 Analyze (Expr);
2723
2724 if Is_Entity_Name (Expr) then
2725 if not Is_Overloaded (Expr) then
2726 if Has_Good_Profile (Entity (Expr)) then
2727 Subp := Entity (Expr);
2728 end if;
2729
2730 else
2731 Get_First_Interp (Expr, I, It);
2732 while Present (It.Nam) loop
2733 if Has_Good_Profile (It.Nam) then
2734 Subp := It.Nam;
2735 exit;
2736 end if;
2737
2738 Get_Next_Interp (I, It);
2739 end loop;
2740 end if;
2741 end if;
2742
2743 if Present (Subp) then
2744 if Is_Abstract_Subprogram (Subp) then
2745 Error_Msg_N ("stream subprogram must not be abstract", Expr);
2746 return;
2747 end if;
2748
2749 Set_Entity (Expr, Subp);
2750 Set_Etype (Expr, Etype (Subp));
2751
2752 New_Stream_Subprogram (N, U_Ent, Subp, TSS_Nam);
2753
2754 else
2755 Error_Msg_Name_1 := Attr;
2756 Error_Msg_N ("incorrect expression for% attribute", Expr);
2757 end if;
2758 end Analyze_Stream_TSS_Definition;
2759
2760 ------------------------------
2761 -- Check_Indexing_Functions --
2762 ------------------------------
2763
2764 procedure Check_Indexing_Functions is
2765 Indexing_Found : Boolean;
2766
2767 procedure Check_One_Function (Subp : Entity_Id);
2768 -- Check one possible interpretation. Sets Indexing_Found True if an
2769 -- indexing function is found.
2770
2771 ------------------------
2772 -- Check_One_Function --
2773 ------------------------
2774
2775 procedure Check_One_Function (Subp : Entity_Id) is
2776 Default_Element : constant Node_Id :=
2777 Find_Value_Of_Aspect
2778 (Etype (First_Formal (Subp)),
2779 Aspect_Iterator_Element);
2780
2781 begin
2782 if not Check_Primitive_Function (Subp)
2783 and then not Is_Overloaded (Expr)
2784 then
2785 Error_Msg_NE
2786 ("aspect Indexing requires a function that applies to type&",
2787 Subp, Ent);
2788 end if;
2789
2790 -- An indexing function must return either the default element of
2791 -- the container, or a reference type. For variable indexing it
2792 -- must be the latter.
2793
2794 if Present (Default_Element) then
2795 Analyze (Default_Element);
2796
2797 if Is_Entity_Name (Default_Element)
2798 and then Covers (Entity (Default_Element), Etype (Subp))
2799 then
2800 Indexing_Found := True;
2801 return;
2802 end if;
2803 end if;
2804
2805 -- For variable_indexing the return type must be a reference type
2806
2807 if Attr = Name_Variable_Indexing
2808 and then not Has_Implicit_Dereference (Etype (Subp))
2809 then
2810 Error_Msg_N
2811 ("function for indexing must return a reference type", Subp);
2812
2813 else
2814 Indexing_Found := True;
2815 end if;
2816 end Check_One_Function;
2817
2818 -- Start of processing for Check_Indexing_Functions
2819
2820 begin
2821 if In_Instance then
2822 return;
2823 end if;
2824
2825 Analyze (Expr);
2826
2827 if not Is_Overloaded (Expr) then
2828 Check_One_Function (Entity (Expr));
2829
2830 else
2831 declare
2832 I : Interp_Index;
2833 It : Interp;
2834
2835 begin
2836 Indexing_Found := False;
2837 Get_First_Interp (Expr, I, It);
2838 while Present (It.Nam) loop
2839
2840 -- Note that analysis will have added the interpretation
2841 -- that corresponds to the dereference. We only check the
2842 -- subprogram itself.
2843
2844 if Is_Overloadable (It.Nam) then
2845 Check_One_Function (It.Nam);
2846 end if;
2847
2848 Get_Next_Interp (I, It);
2849 end loop;
2850
2851 if not Indexing_Found then
2852 Error_Msg_NE
2853 ("aspect Indexing requires a function that "
2854 & "applies to type&", Expr, Ent);
2855 end if;
2856 end;
2857 end if;
2858 end Check_Indexing_Functions;
2859
2860 ------------------------------
2861 -- Check_Iterator_Functions --
2862 ------------------------------
2863
2864 procedure Check_Iterator_Functions is
2865 Default : Entity_Id;
2866
2867 function Valid_Default_Iterator (Subp : Entity_Id) return Boolean;
2868 -- Check one possible interpretation for validity
2869
2870 ----------------------------
2871 -- Valid_Default_Iterator --
2872 ----------------------------
2873
2874 function Valid_Default_Iterator (Subp : Entity_Id) return Boolean is
2875 Formal : Entity_Id;
2876
2877 begin
2878 if not Check_Primitive_Function (Subp) then
2879 return False;
2880 else
2881 Formal := First_Formal (Subp);
2882 end if;
2883
2884 -- False if any subsequent formal has no default expression
2885
2886 Formal := Next_Formal (Formal);
2887 while Present (Formal) loop
2888 if No (Expression (Parent (Formal))) then
2889 return False;
2890 end if;
2891
2892 Next_Formal (Formal);
2893 end loop;
2894
2895 -- True if all subsequent formals have default expressions
2896
2897 return True;
2898 end Valid_Default_Iterator;
2899
2900 -- Start of processing for Check_Iterator_Functions
2901
2902 begin
2903 Analyze (Expr);
2904
2905 if not Is_Entity_Name (Expr) then
2906 Error_Msg_N ("aspect Iterator must be a function name", Expr);
2907 end if;
2908
2909 if not Is_Overloaded (Expr) then
2910 if not Check_Primitive_Function (Entity (Expr)) then
2911 Error_Msg_NE
2912 ("aspect Indexing requires a function that applies to type&",
2913 Entity (Expr), Ent);
2914 end if;
2915
2916 if not Valid_Default_Iterator (Entity (Expr)) then
2917 Error_Msg_N ("improper function for default iterator", Expr);
2918 end if;
2919
2920 else
2921 Default := Empty;
2922 declare
2923 I : Interp_Index;
2924 It : Interp;
2925
2926 begin
2927 Get_First_Interp (Expr, I, It);
2928 while Present (It.Nam) loop
2929 if not Check_Primitive_Function (It.Nam)
2930 or else not Valid_Default_Iterator (It.Nam)
2931 then
2932 Remove_Interp (I);
2933
2934 elsif Present (Default) then
2935 Error_Msg_N ("default iterator must be unique", Expr);
2936
2937 else
2938 Default := It.Nam;
2939 end if;
2940
2941 Get_Next_Interp (I, It);
2942 end loop;
2943 end;
2944
2945 if Present (Default) then
2946 Set_Entity (Expr, Default);
2947 Set_Is_Overloaded (Expr, False);
2948 end if;
2949 end if;
2950 end Check_Iterator_Functions;
2951
2952 -------------------------------
2953 -- Check_Primitive_Function --
2954 -------------------------------
2955
2956 function Check_Primitive_Function (Subp : Entity_Id) return Boolean is
2957 Ctrl : Entity_Id;
2958
2959 begin
2960 if Ekind (Subp) /= E_Function then
2961 return False;
2962 end if;
2963
2964 if No (First_Formal (Subp)) then
2965 return False;
2966 else
2967 Ctrl := Etype (First_Formal (Subp));
2968 end if;
2969
2970 if Ctrl = Ent
2971 or else Ctrl = Class_Wide_Type (Ent)
2972 or else
2973 (Ekind (Ctrl) = E_Anonymous_Access_Type
2974 and then
2975 (Designated_Type (Ctrl) = Ent
2976 or else Designated_Type (Ctrl) = Class_Wide_Type (Ent)))
2977 then
2978 null;
2979
2980 else
2981 return False;
2982 end if;
2983
2984 return True;
2985 end Check_Primitive_Function;
2986
2987 ----------------------
2988 -- Duplicate_Clause --
2989 ----------------------
2990
2991 function Duplicate_Clause return Boolean is
2992 A : Node_Id;
2993
2994 begin
2995 -- Nothing to do if this attribute definition clause comes from
2996 -- an aspect specification, since we could not be duplicating an
2997 -- explicit clause, and we dealt with the case of duplicated aspects
2998 -- in Analyze_Aspect_Specifications.
2999
3000 if From_Aspect_Specification (N) then
3001 return False;
3002 end if;
3003
3004 -- Otherwise current clause may duplicate previous clause, or a
3005 -- previously given pragma or aspect specification for the same
3006 -- aspect.
3007
3008 A := Get_Rep_Item (U_Ent, Chars (N), Check_Parents => False);
3009
3010 if Present (A) then
3011 Error_Msg_Name_1 := Chars (N);
3012 Error_Msg_Sloc := Sloc (A);
3013
3014 Error_Msg_NE ("aspect% for & previously given#", N, U_Ent);
3015 return True;
3016 end if;
3017
3018 return False;
3019 end Duplicate_Clause;
3020
3021 -- Start of processing for Analyze_Attribute_Definition_Clause
3022
3023 begin
3024 -- The following code is a defense against recursion. Not clear that
3025 -- this can happen legitimately, but perhaps some error situations
3026 -- can cause it, and we did see this recursion during testing.
3027
3028 if Analyzed (N) then
3029 return;
3030 else
3031 Set_Analyzed (N, True);
3032 end if;
3033
3034 -- Ignore some selected attributes in CodePeer mode since they are not
3035 -- relevant in this context.
3036
3037 if CodePeer_Mode then
3038 case Id is
3039
3040 -- Ignore Component_Size in CodePeer mode, to avoid changing the
3041 -- internal representation of types by implicitly packing them.
3042
3043 when Attribute_Component_Size =>
3044 Rewrite (N, Make_Null_Statement (Sloc (N)));
3045 return;
3046
3047 when others =>
3048 null;
3049 end case;
3050 end if;
3051
3052 -- Process Ignore_Rep_Clauses option
3053
3054 if Ignore_Rep_Clauses then
3055 case Id is
3056
3057 -- The following should be ignored. They do not affect legality
3058 -- and may be target dependent. The basic idea of -gnatI is to
3059 -- ignore any rep clauses that may be target dependent but do not
3060 -- affect legality (except possibly to be rejected because they
3061 -- are incompatible with the compilation target).
3062
3063 when Attribute_Alignment |
3064 Attribute_Bit_Order |
3065 Attribute_Component_Size |
3066 Attribute_Machine_Radix |
3067 Attribute_Object_Size |
3068 Attribute_Size |
3069 Attribute_Stream_Size |
3070 Attribute_Value_Size =>
3071 Rewrite (N, Make_Null_Statement (Sloc (N)));
3072 return;
3073
3074 -- Perhaps 'Small should not be ignored by Ignore_Rep_Clauses ???
3075
3076 when Attribute_Small =>
3077 if Ignore_Rep_Clauses then
3078 Rewrite (N, Make_Null_Statement (Sloc (N)));
3079 return;
3080 end if;
3081
3082 -- The following should not be ignored, because in the first place
3083 -- they are reasonably portable, and should not cause problems in
3084 -- compiling code from another target, and also they do affect
3085 -- legality, e.g. failing to provide a stream attribute for a
3086 -- type may make a program illegal.
3087
3088 when Attribute_External_Tag |
3089 Attribute_Input |
3090 Attribute_Output |
3091 Attribute_Read |
3092 Attribute_Simple_Storage_Pool |
3093 Attribute_Storage_Pool |
3094 Attribute_Storage_Size |
3095 Attribute_Write =>
3096 null;
3097
3098 -- Other cases are errors ("attribute& cannot be set with
3099 -- definition clause"), which will be caught below.
3100
3101 when others =>
3102 null;
3103 end case;
3104 end if;
3105
3106 Analyze (Nam);
3107 Ent := Entity (Nam);
3108
3109 if Rep_Item_Too_Early (Ent, N) then
3110 return;
3111 end if;
3112
3113 -- Rep clause applies to full view of incomplete type or private type if
3114 -- we have one (if not, this is a premature use of the type). However,
3115 -- certain semantic checks need to be done on the specified entity (i.e.
3116 -- the private view), so we save it in Ent.
3117
3118 if Is_Private_Type (Ent)
3119 and then Is_Derived_Type (Ent)
3120 and then not Is_Tagged_Type (Ent)
3121 and then No (Full_View (Ent))
3122 then
3123 -- If this is a private type whose completion is a derivation from
3124 -- another private type, there is no full view, and the attribute
3125 -- belongs to the type itself, not its underlying parent.
3126
3127 U_Ent := Ent;
3128
3129 elsif Ekind (Ent) = E_Incomplete_Type then
3130
3131 -- The attribute applies to the full view, set the entity of the
3132 -- attribute definition accordingly.
3133
3134 Ent := Underlying_Type (Ent);
3135 U_Ent := Ent;
3136 Set_Entity (Nam, Ent);
3137
3138 else
3139 U_Ent := Underlying_Type (Ent);
3140 end if;
3141
3142 -- Avoid cascaded error
3143
3144 if Etype (Nam) = Any_Type then
3145 return;
3146
3147 -- Must be declared in current scope or in case of an aspect
3148 -- specification, must be visible in current scope.
3149
3150 elsif Scope (Ent) /= Current_Scope
3151 and then
3152 not (From_Aspect_Specification (N)
3153 and then Scope_Within_Or_Same (Current_Scope, Scope (Ent)))
3154 then
3155 Error_Msg_N ("entity must be declared in this scope", Nam);
3156 return;
3157
3158 -- Must not be a source renaming (we do have some cases where the
3159 -- expander generates a renaming, and those cases are OK, in such
3160 -- cases any attribute applies to the renamed object as well).
3161
3162 elsif Is_Object (Ent)
3163 and then Present (Renamed_Object (Ent))
3164 then
3165 -- Case of renamed object from source, this is an error
3166
3167 if Comes_From_Source (Renamed_Object (Ent)) then
3168 Get_Name_String (Chars (N));
3169 Error_Msg_Strlen := Name_Len;
3170 Error_Msg_String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len);
3171 Error_Msg_N
3172 ("~ clause not allowed for a renaming declaration "
3173 & "(RM 13.1(6))", Nam);
3174 return;
3175
3176 -- For the case of a compiler generated renaming, the attribute
3177 -- definition clause applies to the renamed object created by the
3178 -- expander. The easiest general way to handle this is to create a
3179 -- copy of the attribute definition clause for this object.
3180
3181 else
3182 Insert_Action (N,
3183 Make_Attribute_Definition_Clause (Loc,
3184 Name =>
3185 New_Occurrence_Of (Entity (Renamed_Object (Ent)), Loc),
3186 Chars => Chars (N),
3187 Expression => Duplicate_Subexpr (Expression (N))));
3188 end if;
3189
3190 -- If no underlying entity, use entity itself, applies to some
3191 -- previously detected error cases ???
3192
3193 elsif No (U_Ent) then
3194 U_Ent := Ent;
3195
3196 -- Cannot specify for a subtype (exception Object/Value_Size)
3197
3198 elsif Is_Type (U_Ent)
3199 and then not Is_First_Subtype (U_Ent)
3200 and then Id /= Attribute_Object_Size
3201 and then Id /= Attribute_Value_Size
3202 and then not From_At_Mod (N)
3203 then
3204 Error_Msg_N ("cannot specify attribute for subtype", Nam);
3205 return;
3206 end if;
3207
3208 Set_Entity (N, U_Ent);
3209 Check_Restriction_No_Use_Of_Attribute (N);
3210
3211 -- Switch on particular attribute
3212
3213 case Id is
3214
3215 -------------
3216 -- Address --
3217 -------------
3218
3219 -- Address attribute definition clause
3220
3221 when Attribute_Address => Address : begin
3222
3223 -- A little error check, catch for X'Address use X'Address;
3224
3225 if Nkind (Nam) = N_Identifier
3226 and then Nkind (Expr) = N_Attribute_Reference
3227 and then Attribute_Name (Expr) = Name_Address
3228 and then Nkind (Prefix (Expr)) = N_Identifier
3229 and then Chars (Nam) = Chars (Prefix (Expr))
3230 then
3231 Error_Msg_NE
3232 ("address for & is self-referencing", Prefix (Expr), Ent);
3233 return;
3234 end if;
3235
3236 -- Not that special case, carry on with analysis of expression
3237
3238 Analyze_And_Resolve (Expr, RTE (RE_Address));
3239
3240 -- Even when ignoring rep clauses we need to indicate that the
3241 -- entity has an address clause and thus it is legal to declare
3242 -- it imported.
3243
3244 if Ignore_Rep_Clauses then
3245 if Ekind_In (U_Ent, E_Variable, E_Constant) then
3246 Record_Rep_Item (U_Ent, N);
3247 end if;
3248
3249 return;
3250 end if;
3251
3252 if Duplicate_Clause then
3253 null;
3254
3255 -- Case of address clause for subprogram
3256
3257 elsif Is_Subprogram (U_Ent) then
3258 if Has_Homonym (U_Ent) then
3259 Error_Msg_N
3260 ("address clause cannot be given " &
3261 "for overloaded subprogram",
3262 Nam);
3263 return;
3264 end if;
3265
3266 -- For subprograms, all address clauses are permitted, and we
3267 -- mark the subprogram as having a deferred freeze so that Gigi
3268 -- will not elaborate it too soon.
3269
3270 -- Above needs more comments, what is too soon about???
3271
3272 Set_Has_Delayed_Freeze (U_Ent);
3273
3274 -- Case of address clause for entry
3275
3276 elsif Ekind (U_Ent) = E_Entry then
3277 if Nkind (Parent (N)) = N_Task_Body then
3278 Error_Msg_N
3279 ("entry address must be specified in task spec", Nam);
3280 return;
3281 end if;
3282
3283 -- For entries, we require a constant address
3284
3285 Check_Constant_Address_Clause (Expr, U_Ent);
3286
3287 -- Special checks for task types
3288
3289 if Is_Task_Type (Scope (U_Ent))
3290 and then Comes_From_Source (Scope (U_Ent))
3291 then
3292 Error_Msg_N
3293 ("??entry address declared for entry in task type", N);
3294 Error_Msg_N
3295 ("\??only one task can be declared of this type", N);
3296 end if;
3297
3298 -- Entry address clauses are obsolescent
3299
3300 Check_Restriction (No_Obsolescent_Features, N);
3301
3302 if Warn_On_Obsolescent_Feature then
3303 Error_Msg_N
3304 ("?j?attaching interrupt to task entry is an " &
3305 "obsolescent feature (RM J.7.1)", N);
3306 Error_Msg_N
3307 ("\?j?use interrupt procedure instead", N);
3308 end if;
3309
3310 -- Case of an address clause for a controlled object which we
3311 -- consider to be erroneous.
3312
3313 elsif Is_Controlled (Etype (U_Ent))
3314 or else Has_Controlled_Component (Etype (U_Ent))
3315 then
3316 Error_Msg_NE
3317 ("??controlled object& must not be overlaid", Nam, U_Ent);
3318 Error_Msg_N
3319 ("\??Program_Error will be raised at run time", Nam);
3320 Insert_Action (Declaration_Node (U_Ent),
3321 Make_Raise_Program_Error (Loc,
3322 Reason => PE_Overlaid_Controlled_Object));
3323 return;
3324
3325 -- Case of address clause for a (non-controlled) object
3326
3327 elsif
3328 Ekind (U_Ent) = E_Variable
3329 or else
3330 Ekind (U_Ent) = E_Constant
3331 then
3332 declare
3333 Expr : constant Node_Id := Expression (N);
3334 O_Ent : Entity_Id;
3335 Off : Boolean;
3336
3337 begin
3338 -- Exported variables cannot have an address clause, because
3339 -- this cancels the effect of the pragma Export.
3340
3341 if Is_Exported (U_Ent) then
3342 Error_Msg_N
3343 ("cannot export object with address clause", Nam);
3344 return;
3345 end if;
3346
3347 Find_Overlaid_Entity (N, O_Ent, Off);
3348
3349 -- Overlaying controlled objects is erroneous
3350
3351 if Present (O_Ent)
3352 and then (Has_Controlled_Component (Etype (O_Ent))
3353 or else Is_Controlled (Etype (O_Ent)))
3354 then
3355 Error_Msg_N
3356 ("??cannot overlay with controlled object", Expr);
3357 Error_Msg_N
3358 ("\??Program_Error will be raised at run time", Expr);
3359 Insert_Action (Declaration_Node (U_Ent),
3360 Make_Raise_Program_Error (Loc,
3361 Reason => PE_Overlaid_Controlled_Object));
3362 return;
3363
3364 elsif Present (O_Ent)
3365 and then Ekind (U_Ent) = E_Constant
3366 and then not Is_Constant_Object (O_Ent)
3367 then
3368 Error_Msg_N ("??constant overlays a variable", Expr);
3369
3370 -- Imported variables can have an address clause, but then
3371 -- the import is pretty meaningless except to suppress
3372 -- initializations, so we do not need such variables to
3373 -- be statically allocated (and in fact it causes trouble
3374 -- if the address clause is a local value).
3375
3376 elsif Is_Imported (U_Ent) then
3377 Set_Is_Statically_Allocated (U_Ent, False);
3378 end if;
3379
3380 -- We mark a possible modification of a variable with an
3381 -- address clause, since it is likely aliasing is occurring.
3382
3383 Note_Possible_Modification (Nam, Sure => False);
3384
3385 -- Here we are checking for explicit overlap of one variable
3386 -- by another, and if we find this then mark the overlapped
3387 -- variable as also being volatile to prevent unwanted
3388 -- optimizations. This is a significant pessimization so
3389 -- avoid it when there is an offset, i.e. when the object
3390 -- is composite; they cannot be optimized easily anyway.
3391
3392 if Present (O_Ent)
3393 and then Is_Object (O_Ent)
3394 and then not Off
3395
3396 -- The following test is an expedient solution to what
3397 -- is really a problem in CodePeer. Suppressing the
3398 -- Set_Treat_As_Volatile call here prevents later
3399 -- generation (in some cases) of trees that CodePeer
3400 -- should, but currently does not, handle correctly.
3401 -- This test should probably be removed when CodePeer
3402 -- is improved, just because we want the tree CodePeer
3403 -- analyzes to match the tree for which we generate code
3404 -- as closely as is practical. ???
3405
3406 and then not CodePeer_Mode
3407 then
3408 -- ??? O_Ent might not be in current unit
3409
3410 Set_Treat_As_Volatile (O_Ent);
3411 end if;
3412
3413 -- Legality checks on the address clause for initialized
3414 -- objects is deferred until the freeze point, because
3415 -- a subsequent pragma might indicate that the object
3416 -- is imported and thus not initialized. Also, the address
3417 -- clause might involve entities that have yet to be
3418 -- elaborated.
3419
3420 Set_Has_Delayed_Freeze (U_Ent);
3421
3422 -- If an initialization call has been generated for this
3423 -- object, it needs to be deferred to after the freeze node
3424 -- we have just now added, otherwise GIGI will see a
3425 -- reference to the variable (as actual to the IP call)
3426 -- before its definition.
3427
3428 declare
3429 Init_Call : constant Node_Id :=
3430 Remove_Init_Call (U_Ent, N);
3431
3432 begin
3433 if Present (Init_Call) then
3434
3435 -- If the init call is an expression with actions with
3436 -- null expression, just extract the actions.
3437
3438 if Nkind (Init_Call) = N_Expression_With_Actions
3439 and then
3440 Nkind (Expression (Init_Call)) = N_Null_Statement
3441 then
3442 Append_Freeze_Actions (U_Ent, Actions (Init_Call));
3443
3444 -- General case: move Init_Call to freeze actions
3445
3446 else
3447 Append_Freeze_Action (U_Ent, Init_Call);
3448 end if;
3449 end if;
3450 end;
3451
3452 if Is_Exported (U_Ent) then
3453 Error_Msg_N
3454 ("& cannot be exported if an address clause is given",
3455 Nam);
3456 Error_Msg_N
3457 ("\define and export a variable "
3458 & "that holds its address instead", Nam);
3459 end if;
3460
3461 -- Entity has delayed freeze, so we will generate an
3462 -- alignment check at the freeze point unless suppressed.
3463
3464 if not Range_Checks_Suppressed (U_Ent)
3465 and then not Alignment_Checks_Suppressed (U_Ent)
3466 then
3467 Set_Check_Address_Alignment (N);
3468 end if;
3469
3470 -- Kill the size check code, since we are not allocating
3471 -- the variable, it is somewhere else.
3472
3473 Kill_Size_Check_Code (U_Ent);
3474
3475 -- If the address clause is of the form:
3476
3477 -- for Y'Address use X'Address
3478
3479 -- or
3480
3481 -- Const : constant Address := X'Address;
3482 -- ...
3483 -- for Y'Address use Const;
3484
3485 -- then we make an entry in the table for checking the size
3486 -- and alignment of the overlaying variable. We defer this
3487 -- check till after code generation to take full advantage
3488 -- of the annotation done by the back end. This entry is
3489 -- only made if the address clause comes from source or
3490 -- from an aspect clause (which is still from source).
3491
3492 -- If the entity has a generic type, the check will be
3493 -- performed in the instance if the actual type justifies
3494 -- it, and we do not insert the clause in the table to
3495 -- prevent spurious warnings.
3496
3497 if Address_Clause_Overlay_Warnings
3498 and then (Comes_From_Source (N)
3499 or else From_Aspect_Specification (N))
3500 and then Present (O_Ent)
3501 and then Is_Object (O_Ent)
3502 then
3503 if not Is_Generic_Type (Etype (U_Ent)) then
3504 Address_Clause_Checks.Append ((N, U_Ent, O_Ent, Off));
3505 end if;
3506
3507 -- If variable overlays a constant view, and we are
3508 -- warning on overlays, then mark the variable as
3509 -- overlaying a constant (we will give warnings later
3510 -- if this variable is assigned).
3511
3512 if Is_Constant_Object (O_Ent)
3513 and then Ekind (U_Ent) = E_Variable
3514 then
3515 Set_Overlays_Constant (U_Ent);
3516 end if;
3517 end if;
3518 end;
3519
3520 -- Not a valid entity for an address clause
3521
3522 else
3523 Error_Msg_N ("address cannot be given for &", Nam);
3524 end if;
3525 end Address;
3526
3527 ---------------
3528 -- Alignment --
3529 ---------------
3530
3531 -- Alignment attribute definition clause
3532
3533 when Attribute_Alignment => Alignment : declare
3534 Align : constant Uint := Get_Alignment_Value (Expr);
3535 Max_Align : constant Uint := UI_From_Int (Maximum_Alignment);
3536
3537 begin
3538 FOnly := True;
3539
3540 if not Is_Type (U_Ent)
3541 and then Ekind (U_Ent) /= E_Variable
3542 and then Ekind (U_Ent) /= E_Constant
3543 then
3544 Error_Msg_N ("alignment cannot be given for &", Nam);
3545
3546 elsif Duplicate_Clause then
3547 null;
3548
3549 elsif Align /= No_Uint then
3550 Set_Has_Alignment_Clause (U_Ent);
3551
3552 -- Tagged type case, check for attempt to set alignment to a
3553 -- value greater than Max_Align, and reset if so.
3554
3555 if Is_Tagged_Type (U_Ent) and then Align > Max_Align then
3556 Error_Msg_N
3557 ("alignment for & set to Maximum_Aligment??", Nam);
3558 Set_Alignment (U_Ent, Max_Align);
3559
3560 -- All other cases
3561
3562 else
3563 Set_Alignment (U_Ent, Align);
3564 end if;
3565
3566 -- For an array type, U_Ent is the first subtype. In that case,
3567 -- also set the alignment of the anonymous base type so that
3568 -- other subtypes (such as the itypes for aggregates of the
3569 -- type) also receive the expected alignment.
3570
3571 if Is_Array_Type (U_Ent) then
3572 Set_Alignment (Base_Type (U_Ent), Align);
3573 end if;
3574 end if;
3575 end Alignment;
3576
3577 ---------------
3578 -- Bit_Order --
3579 ---------------
3580
3581 -- Bit_Order attribute definition clause
3582
3583 when Attribute_Bit_Order => Bit_Order : declare
3584 begin
3585 if not Is_Record_Type (U_Ent) then
3586 Error_Msg_N
3587 ("Bit_Order can only be defined for record type", Nam);
3588
3589 elsif Duplicate_Clause then
3590 null;
3591
3592 else
3593 Analyze_And_Resolve (Expr, RTE (RE_Bit_Order));
3594
3595 if Etype (Expr) = Any_Type then
3596 return;
3597
3598 elsif not Is_Static_Expression (Expr) then
3599 Flag_Non_Static_Expr
3600 ("Bit_Order requires static expression!", Expr);
3601
3602 else
3603 if (Expr_Value (Expr) = 0) /= Bytes_Big_Endian then
3604 Set_Reverse_Bit_Order (U_Ent, True);
3605 end if;
3606 end if;
3607 end if;
3608 end Bit_Order;
3609
3610 --------------------
3611 -- Component_Size --
3612 --------------------
3613
3614 -- Component_Size attribute definition clause
3615
3616 when Attribute_Component_Size => Component_Size_Case : declare
3617 Csize : constant Uint := Static_Integer (Expr);
3618 Ctyp : Entity_Id;
3619 Btype : Entity_Id;
3620 Biased : Boolean;
3621 New_Ctyp : Entity_Id;
3622 Decl : Node_Id;
3623
3624 begin
3625 if not Is_Array_Type (U_Ent) then
3626 Error_Msg_N ("component size requires array type", Nam);
3627 return;
3628 end if;
3629
3630 Btype := Base_Type (U_Ent);
3631 Ctyp := Component_Type (Btype);
3632
3633 if Duplicate_Clause then
3634 null;
3635
3636 elsif Rep_Item_Too_Early (Btype, N) then
3637 null;
3638
3639 elsif Csize /= No_Uint then
3640 Check_Size (Expr, Ctyp, Csize, Biased);
3641
3642 -- For the biased case, build a declaration for a subtype that
3643 -- will be used to represent the biased subtype that reflects
3644 -- the biased representation of components. We need the subtype
3645 -- to get proper conversions on referencing elements of the
3646 -- array. Note: component size clauses are ignored in VM mode.
3647
3648 if VM_Target = No_VM then
3649 if Biased then
3650 New_Ctyp :=
3651 Make_Defining_Identifier (Loc,
3652 Chars =>
3653 New_External_Name (Chars (U_Ent), 'C', 0, 'T'));
3654
3655 Decl :=
3656 Make_Subtype_Declaration (Loc,
3657 Defining_Identifier => New_Ctyp,
3658 Subtype_Indication =>
3659 New_Occurrence_Of (Component_Type (Btype), Loc));
3660
3661 Set_Parent (Decl, N);
3662 Analyze (Decl, Suppress => All_Checks);
3663
3664 Set_Has_Delayed_Freeze (New_Ctyp, False);
3665 Set_Esize (New_Ctyp, Csize);
3666 Set_RM_Size (New_Ctyp, Csize);
3667 Init_Alignment (New_Ctyp);
3668 Set_Is_Itype (New_Ctyp, True);
3669 Set_Associated_Node_For_Itype (New_Ctyp, U_Ent);
3670
3671 Set_Component_Type (Btype, New_Ctyp);
3672 Set_Biased (New_Ctyp, N, "component size clause");
3673 end if;
3674
3675 Set_Component_Size (Btype, Csize);
3676
3677 -- For VM case, we ignore component size clauses
3678
3679 else
3680 -- Give a warning unless we are in GNAT mode, in which case
3681 -- the warning is suppressed since it is not useful.
3682
3683 if not GNAT_Mode then
3684 Error_Msg_N
3685 ("component size ignored in this configuration??", N);
3686 end if;
3687 end if;
3688
3689 -- Deal with warning on overridden size
3690
3691 if Warn_On_Overridden_Size
3692 and then Has_Size_Clause (Ctyp)
3693 and then RM_Size (Ctyp) /= Csize
3694 then
3695 Error_Msg_NE
3696 ("component size overrides size clause for&?S?", N, Ctyp);
3697 end if;
3698
3699 Set_Has_Component_Size_Clause (Btype, True);
3700 Set_Has_Non_Standard_Rep (Btype, True);
3701 end if;
3702 end Component_Size_Case;
3703
3704 -----------------------
3705 -- Constant_Indexing --
3706 -----------------------
3707
3708 when Attribute_Constant_Indexing =>
3709 Check_Indexing_Functions;
3710
3711 ---------
3712 -- CPU --
3713 ---------
3714
3715 when Attribute_CPU => CPU :
3716 begin
3717 -- CPU attribute definition clause not allowed except from aspect
3718 -- specification.
3719
3720 if From_Aspect_Specification (N) then
3721 if not Is_Task_Type (U_Ent) then
3722 Error_Msg_N ("CPU can only be defined for task", Nam);
3723
3724 elsif Duplicate_Clause then
3725 null;
3726
3727 else
3728 -- The expression must be analyzed in the special manner
3729 -- described in "Handling of Default and Per-Object
3730 -- Expressions" in sem.ads.
3731
3732 -- The visibility to the discriminants must be restored
3733
3734 Push_Scope_And_Install_Discriminants (U_Ent);
3735 Preanalyze_Spec_Expression (Expr, RTE (RE_CPU_Range));
3736 Uninstall_Discriminants_And_Pop_Scope (U_Ent);
3737
3738 if not Is_Static_Expression (Expr) then
3739 Check_Restriction (Static_Priorities, Expr);
3740 end if;
3741 end if;
3742
3743 else
3744 Error_Msg_N
3745 ("attribute& cannot be set with definition clause", N);
3746 end if;
3747 end CPU;
3748
3749 ----------------------
3750 -- Default_Iterator --
3751 ----------------------
3752
3753 when Attribute_Default_Iterator => Default_Iterator : declare
3754 Func : Entity_Id;
3755
3756 begin
3757 if not Is_Tagged_Type (U_Ent) then
3758 Error_Msg_N
3759 ("aspect Default_Iterator applies to tagged type", Nam);
3760 end if;
3761
3762 Check_Iterator_Functions;
3763
3764 Analyze (Expr);
3765
3766 if not Is_Entity_Name (Expr)
3767 or else Ekind (Entity (Expr)) /= E_Function
3768 then
3769 Error_Msg_N ("aspect Iterator must be a function", Expr);
3770 else
3771 Func := Entity (Expr);
3772 end if;
3773
3774 if No (First_Formal (Func))
3775 or else Etype (First_Formal (Func)) /= U_Ent
3776 then
3777 Error_Msg_NE
3778 ("Default Iterator must be a primitive of&", Func, U_Ent);
3779 end if;
3780 end Default_Iterator;
3781
3782 ------------------------
3783 -- Dispatching_Domain --
3784 ------------------------
3785
3786 when Attribute_Dispatching_Domain => Dispatching_Domain :
3787 begin
3788 -- Dispatching_Domain attribute definition clause not allowed
3789 -- except from aspect specification.
3790
3791 if From_Aspect_Specification (N) then
3792 if not Is_Task_Type (U_Ent) then
3793 Error_Msg_N ("Dispatching_Domain can only be defined" &
3794 "for task",
3795 Nam);
3796
3797 elsif Duplicate_Clause then
3798 null;
3799
3800 else
3801 -- The expression must be analyzed in the special manner
3802 -- described in "Handling of Default and Per-Object
3803 -- Expressions" in sem.ads.
3804
3805 -- The visibility to the discriminants must be restored
3806
3807 Push_Scope_And_Install_Discriminants (U_Ent);
3808
3809 Preanalyze_Spec_Expression
3810 (Expr, RTE (RE_Dispatching_Domain));
3811
3812 Uninstall_Discriminants_And_Pop_Scope (U_Ent);
3813 end if;
3814
3815 else
3816 Error_Msg_N
3817 ("attribute& cannot be set with definition clause", N);
3818 end if;
3819 end Dispatching_Domain;
3820
3821 ------------------
3822 -- External_Tag --
3823 ------------------
3824
3825 when Attribute_External_Tag => External_Tag :
3826 begin
3827 if not Is_Tagged_Type (U_Ent) then
3828 Error_Msg_N ("should be a tagged type", Nam);
3829 end if;
3830
3831 if Duplicate_Clause then
3832 null;
3833
3834 else
3835 Analyze_And_Resolve (Expr, Standard_String);
3836
3837 if not Is_Static_Expression (Expr) then
3838 Flag_Non_Static_Expr
3839 ("static string required for tag name!", Nam);
3840 end if;
3841
3842 if VM_Target = No_VM then
3843 Set_Has_External_Tag_Rep_Clause (U_Ent);
3844 else
3845 Error_Msg_Name_1 := Attr;
3846 Error_Msg_N
3847 ("% attribute unsupported in this configuration", Nam);
3848 end if;
3849
3850 if not Is_Library_Level_Entity (U_Ent) then
3851 Error_Msg_NE
3852 ("??non-unique external tag supplied for &", N, U_Ent);
3853 Error_Msg_N
3854 ("\??same external tag applies to all "
3855 & "subprogram calls", N);
3856 Error_Msg_N
3857 ("\??corresponding internal tag cannot be obtained", N);
3858 end if;
3859 end if;
3860 end External_Tag;
3861
3862 --------------------------
3863 -- Implicit_Dereference --
3864 --------------------------
3865
3866 when Attribute_Implicit_Dereference =>
3867
3868 -- Legality checks already performed at the point of the type
3869 -- declaration, aspect is not delayed.
3870
3871 null;
3872
3873 -----------
3874 -- Input --
3875 -----------
3876
3877 when Attribute_Input =>
3878 Analyze_Stream_TSS_Definition (TSS_Stream_Input);
3879 Set_Has_Specified_Stream_Input (Ent);
3880
3881 ------------------------
3882 -- Interrupt_Priority --
3883 ------------------------
3884
3885 when Attribute_Interrupt_Priority => Interrupt_Priority :
3886 begin
3887 -- Interrupt_Priority attribute definition clause not allowed
3888 -- except from aspect specification.
3889
3890 if From_Aspect_Specification (N) then
3891 if not (Is_Protected_Type (U_Ent)
3892 or else Is_Task_Type (U_Ent))
3893 then
3894 Error_Msg_N
3895 ("Interrupt_Priority can only be defined for task" &
3896 "and protected object",
3897 Nam);
3898
3899 elsif Duplicate_Clause then
3900 null;
3901
3902 else
3903 -- The expression must be analyzed in the special manner
3904 -- described in "Handling of Default and Per-Object
3905 -- Expressions" in sem.ads.
3906
3907 -- The visibility to the discriminants must be restored
3908
3909 Push_Scope_And_Install_Discriminants (U_Ent);
3910
3911 Preanalyze_Spec_Expression
3912 (Expr, RTE (RE_Interrupt_Priority));
3913
3914 Uninstall_Discriminants_And_Pop_Scope (U_Ent);
3915 end if;
3916
3917 else
3918 Error_Msg_N
3919 ("attribute& cannot be set with definition clause", N);
3920 end if;
3921 end Interrupt_Priority;
3922
3923 ----------------------
3924 -- Iterator_Element --
3925 ----------------------
3926
3927 when Attribute_Iterator_Element =>
3928 Analyze (Expr);
3929
3930 if not Is_Entity_Name (Expr)
3931 or else not Is_Type (Entity (Expr))
3932 then
3933 Error_Msg_N ("aspect Iterator_Element must be a type", Expr);
3934 end if;
3935
3936 -------------------
3937 -- Machine_Radix --
3938 -------------------
3939
3940 -- Machine radix attribute definition clause
3941
3942 when Attribute_Machine_Radix => Machine_Radix : declare
3943 Radix : constant Uint := Static_Integer (Expr);
3944
3945 begin
3946 if not Is_Decimal_Fixed_Point_Type (U_Ent) then
3947 Error_Msg_N ("decimal fixed-point type expected for &", Nam);
3948
3949 elsif Duplicate_Clause then
3950 null;
3951
3952 elsif Radix /= No_Uint then
3953 Set_Has_Machine_Radix_Clause (U_Ent);
3954 Set_Has_Non_Standard_Rep (Base_Type (U_Ent));
3955
3956 if Radix = 2 then
3957 null;
3958 elsif Radix = 10 then
3959 Set_Machine_Radix_10 (U_Ent);
3960 else
3961 Error_Msg_N ("machine radix value must be 2 or 10", Expr);
3962 end if;
3963 end if;
3964 end Machine_Radix;
3965
3966 -----------------
3967 -- Object_Size --
3968 -----------------
3969
3970 -- Object_Size attribute definition clause
3971
3972 when Attribute_Object_Size => Object_Size : declare
3973 Size : constant Uint := Static_Integer (Expr);
3974
3975 Biased : Boolean;
3976 pragma Warnings (Off, Biased);
3977
3978 begin
3979 if not Is_Type (U_Ent) then
3980 Error_Msg_N ("Object_Size cannot be given for &", Nam);
3981
3982 elsif Duplicate_Clause then
3983 null;
3984
3985 else
3986 Check_Size (Expr, U_Ent, Size, Biased);
3987
3988 if Size /= 8
3989 and then
3990 Size /= 16
3991 and then
3992 Size /= 32
3993 and then
3994 UI_Mod (Size, 64) /= 0
3995 then
3996 Error_Msg_N
3997 ("Object_Size must be 8, 16, 32, or multiple of 64",
3998 Expr);
3999 end if;
4000
4001 Set_Esize (U_Ent, Size);
4002 Set_Has_Object_Size_Clause (U_Ent);
4003 Alignment_Check_For_Size_Change (U_Ent, Size);
4004 end if;
4005 end Object_Size;
4006
4007 ------------
4008 -- Output --
4009 ------------
4010
4011 when Attribute_Output =>
4012 Analyze_Stream_TSS_Definition (TSS_Stream_Output);
4013 Set_Has_Specified_Stream_Output (Ent);
4014
4015 --------------
4016 -- Priority --
4017 --------------
4018
4019 when Attribute_Priority => Priority :
4020 begin
4021 -- Priority attribute definition clause not allowed except from
4022 -- aspect specification.
4023
4024 if From_Aspect_Specification (N) then
4025 if not (Is_Protected_Type (U_Ent)
4026 or else Is_Task_Type (U_Ent)
4027 or else Ekind (U_Ent) = E_Procedure)
4028 then
4029 Error_Msg_N
4030 ("Priority can only be defined for task and protected " &
4031 "object",
4032 Nam);
4033
4034 elsif Duplicate_Clause then
4035 null;
4036
4037 else
4038 -- The expression must be analyzed in the special manner
4039 -- described in "Handling of Default and Per-Object
4040 -- Expressions" in sem.ads.
4041
4042 -- The visibility to the discriminants must be restored
4043
4044 Push_Scope_And_Install_Discriminants (U_Ent);
4045 Preanalyze_Spec_Expression (Expr, Standard_Integer);
4046 Uninstall_Discriminants_And_Pop_Scope (U_Ent);
4047
4048 if not Is_Static_Expression (Expr) then
4049 Check_Restriction (Static_Priorities, Expr);
4050 end if;
4051 end if;
4052
4053 else
4054 Error_Msg_N
4055 ("attribute& cannot be set with definition clause", N);
4056 end if;
4057 end Priority;
4058
4059 ----------
4060 -- Read --
4061 ----------
4062
4063 when Attribute_Read =>
4064 Analyze_Stream_TSS_Definition (TSS_Stream_Read);
4065 Set_Has_Specified_Stream_Read (Ent);
4066
4067 --------------------------
4068 -- Scalar_Storage_Order --
4069 --------------------------
4070
4071 -- Scalar_Storage_Order attribute definition clause
4072
4073 when Attribute_Scalar_Storage_Order => Scalar_Storage_Order : declare
4074 begin
4075 if not (Is_Record_Type (U_Ent) or else Is_Array_Type (U_Ent)) then
4076 Error_Msg_N
4077 ("Scalar_Storage_Order can only be defined for "
4078 & "record or array type", Nam);
4079
4080 elsif Duplicate_Clause then
4081 null;
4082
4083 else
4084 Analyze_And_Resolve (Expr, RTE (RE_Bit_Order));
4085
4086 if Etype (Expr) = Any_Type then
4087 return;
4088
4089 elsif not Is_Static_Expression (Expr) then
4090 Flag_Non_Static_Expr
4091 ("Scalar_Storage_Order requires static expression!", Expr);
4092
4093 elsif (Expr_Value (Expr) = 0) /= Bytes_Big_Endian then
4094
4095 -- Here for the case of a non-default (i.e. non-confirming)
4096 -- Scalar_Storage_Order attribute definition.
4097
4098 if Support_Nondefault_SSO_On_Target then
4099 Set_Reverse_Storage_Order (Base_Type (U_Ent), True);
4100 else
4101 Error_Msg_N
4102 ("non-default Scalar_Storage_Order "
4103 & "not supported on target", Expr);
4104 end if;
4105 end if;
4106 end if;
4107 end Scalar_Storage_Order;
4108
4109 ----------
4110 -- Size --
4111 ----------
4112
4113 -- Size attribute definition clause
4114
4115 when Attribute_Size => Size : declare
4116 Size : constant Uint := Static_Integer (Expr);
4117 Etyp : Entity_Id;
4118 Biased : Boolean;
4119
4120 begin
4121 FOnly := True;
4122
4123 if Duplicate_Clause then
4124 null;
4125
4126 elsif not Is_Type (U_Ent)
4127 and then Ekind (U_Ent) /= E_Variable
4128 and then Ekind (U_Ent) /= E_Constant
4129 then
4130 Error_Msg_N ("size cannot be given for &", Nam);
4131
4132 elsif Is_Array_Type (U_Ent)
4133 and then not Is_Constrained (U_Ent)
4134 then
4135 Error_Msg_N
4136 ("size cannot be given for unconstrained array", Nam);
4137
4138 elsif Size /= No_Uint then
4139 if VM_Target /= No_VM and then not GNAT_Mode then
4140
4141 -- Size clause is not handled properly on VM targets.
4142 -- Display a warning unless we are in GNAT mode, in which
4143 -- case this is useless.
4144
4145 Error_Msg_N
4146 ("size clauses are ignored in this configuration??", N);
4147 end if;
4148
4149 if Is_Type (U_Ent) then
4150 Etyp := U_Ent;
4151 else
4152 Etyp := Etype (U_Ent);
4153 end if;
4154
4155 -- Check size, note that Gigi is in charge of checking that the
4156 -- size of an array or record type is OK. Also we do not check
4157 -- the size in the ordinary fixed-point case, since it is too
4158 -- early to do so (there may be subsequent small clause that
4159 -- affects the size). We can check the size if a small clause
4160 -- has already been given.
4161
4162 if not Is_Ordinary_Fixed_Point_Type (U_Ent)
4163 or else Has_Small_Clause (U_Ent)
4164 then
4165 Check_Size (Expr, Etyp, Size, Biased);
4166 Set_Biased (U_Ent, N, "size clause", Biased);
4167 end if;
4168
4169 -- For types set RM_Size and Esize if possible
4170
4171 if Is_Type (U_Ent) then
4172 Set_RM_Size (U_Ent, Size);
4173
4174 -- For elementary types, increase Object_Size to power of 2,
4175 -- but not less than a storage unit in any case (normally
4176 -- this means it will be byte addressable).
4177
4178 -- For all other types, nothing else to do, we leave Esize
4179 -- (object size) unset, the back end will set it from the
4180 -- size and alignment in an appropriate manner.
4181
4182 -- In both cases, we check whether the alignment must be
4183 -- reset in the wake of the size change.
4184
4185 if Is_Elementary_Type (U_Ent) then
4186 if Size <= System_Storage_Unit then
4187 Init_Esize (U_Ent, System_Storage_Unit);
4188 elsif Size <= 16 then
4189 Init_Esize (U_Ent, 16);
4190 elsif Size <= 32 then
4191 Init_Esize (U_Ent, 32);
4192 else
4193 Set_Esize (U_Ent, (Size + 63) / 64 * 64);
4194 end if;
4195
4196 Alignment_Check_For_Size_Change (U_Ent, Esize (U_Ent));
4197 else
4198 Alignment_Check_For_Size_Change (U_Ent, Size);
4199 end if;
4200
4201 -- For objects, set Esize only
4202
4203 else
4204 if Is_Elementary_Type (Etyp) then
4205 if Size /= System_Storage_Unit
4206 and then
4207 Size /= System_Storage_Unit * 2
4208 and then
4209 Size /= System_Storage_Unit * 4
4210 and then
4211 Size /= System_Storage_Unit * 8
4212 then
4213 Error_Msg_Uint_1 := UI_From_Int (System_Storage_Unit);
4214 Error_Msg_Uint_2 := Error_Msg_Uint_1 * 8;
4215 Error_Msg_N
4216 ("size for primitive object must be a power of 2"
4217 & " in the range ^-^", N);
4218 end if;
4219 end if;
4220
4221 Set_Esize (U_Ent, Size);
4222 end if;
4223
4224 Set_Has_Size_Clause (U_Ent);
4225 end if;
4226 end Size;
4227
4228 -----------
4229 -- Small --
4230 -----------
4231
4232 -- Small attribute definition clause
4233
4234 when Attribute_Small => Small : declare
4235 Implicit_Base : constant Entity_Id := Base_Type (U_Ent);
4236 Small : Ureal;
4237
4238 begin
4239 Analyze_And_Resolve (Expr, Any_Real);
4240
4241 if Etype (Expr) = Any_Type then
4242 return;
4243
4244 elsif not Is_Static_Expression (Expr) then
4245 Flag_Non_Static_Expr
4246 ("small requires static expression!", Expr);
4247 return;
4248
4249 else
4250 Small := Expr_Value_R (Expr);
4251
4252 if Small <= Ureal_0 then
4253 Error_Msg_N ("small value must be greater than zero", Expr);
4254 return;
4255 end if;
4256
4257 end if;
4258
4259 if not Is_Ordinary_Fixed_Point_Type (U_Ent) then
4260 Error_Msg_N
4261 ("small requires an ordinary fixed point type", Nam);
4262
4263 elsif Has_Small_Clause (U_Ent) then
4264 Error_Msg_N ("small already given for &", Nam);
4265
4266 elsif Small > Delta_Value (U_Ent) then
4267 Error_Msg_N
4268 ("small value must not be greater than delta value", Nam);
4269
4270 else
4271 Set_Small_Value (U_Ent, Small);
4272 Set_Small_Value (Implicit_Base, Small);
4273 Set_Has_Small_Clause (U_Ent);
4274 Set_Has_Small_Clause (Implicit_Base);
4275 Set_Has_Non_Standard_Rep (Implicit_Base);
4276 end if;
4277 end Small;
4278
4279 ------------------
4280 -- Storage_Pool --
4281 ------------------
4282
4283 -- Storage_Pool attribute definition clause
4284
4285 when Attribute_Storage_Pool | Attribute_Simple_Storage_Pool => declare
4286 Pool : Entity_Id;
4287 T : Entity_Id;
4288
4289 begin
4290 if Ekind (U_Ent) = E_Access_Subprogram_Type then
4291 Error_Msg_N
4292 ("storage pool cannot be given for access-to-subprogram type",
4293 Nam);
4294 return;
4295
4296 elsif not
4297 Ekind_In (U_Ent, E_Access_Type, E_General_Access_Type)
4298 then
4299 Error_Msg_N
4300 ("storage pool can only be given for access types", Nam);
4301 return;
4302
4303 elsif Is_Derived_Type (U_Ent) then
4304 Error_Msg_N
4305 ("storage pool cannot be given for a derived access type",
4306 Nam);
4307
4308 elsif Duplicate_Clause then
4309 return;
4310
4311 elsif Present (Associated_Storage_Pool (U_Ent)) then
4312 Error_Msg_N ("storage pool already given for &", Nam);
4313 return;
4314 end if;
4315
4316 if Id = Attribute_Storage_Pool then
4317 Analyze_And_Resolve
4318 (Expr, Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
4319
4320 -- In the Simple_Storage_Pool case, we allow a variable of any
4321 -- simple storage pool type, so we Resolve without imposing an
4322 -- expected type.
4323
4324 else
4325 Analyze_And_Resolve (Expr);
4326
4327 if not Present (Get_Rep_Pragma
4328 (Etype (Expr), Name_Simple_Storage_Pool_Type))
4329 then
4330 Error_Msg_N
4331 ("expression must be of a simple storage pool type", Expr);
4332 end if;
4333 end if;
4334
4335 if not Denotes_Variable (Expr) then
4336 Error_Msg_N ("storage pool must be a variable", Expr);
4337 return;
4338 end if;
4339
4340 if Nkind (Expr) = N_Type_Conversion then
4341 T := Etype (Expression (Expr));
4342 else
4343 T := Etype (Expr);
4344 end if;
4345
4346 -- The Stack_Bounded_Pool is used internally for implementing
4347 -- access types with a Storage_Size. Since it only work properly
4348 -- when used on one specific type, we need to check that it is not
4349 -- hijacked improperly:
4350
4351 -- type T is access Integer;
4352 -- for T'Storage_Size use n;
4353 -- type Q is access Float;
4354 -- for Q'Storage_Size use T'Storage_Size; -- incorrect
4355
4356 if RTE_Available (RE_Stack_Bounded_Pool)
4357 and then Base_Type (T) = RTE (RE_Stack_Bounded_Pool)
4358 then
4359 Error_Msg_N ("non-shareable internal Pool", Expr);
4360 return;
4361 end if;
4362
4363 -- If the argument is a name that is not an entity name, then
4364 -- we construct a renaming operation to define an entity of
4365 -- type storage pool.
4366
4367 if not Is_Entity_Name (Expr)
4368 and then Is_Object_Reference (Expr)
4369 then
4370 Pool := Make_Temporary (Loc, 'P', Expr);
4371
4372 declare
4373 Rnode : constant Node_Id :=
4374 Make_Object_Renaming_Declaration (Loc,
4375 Defining_Identifier => Pool,
4376 Subtype_Mark =>
4377 New_Occurrence_Of (Etype (Expr), Loc),
4378 Name => Expr);
4379
4380 begin
4381 Insert_Before (N, Rnode);
4382 Analyze (Rnode);
4383 Set_Associated_Storage_Pool (U_Ent, Pool);
4384 end;
4385
4386 elsif Is_Entity_Name (Expr) then
4387 Pool := Entity (Expr);
4388
4389 -- If pool is a renamed object, get original one. This can
4390 -- happen with an explicit renaming, and within instances.
4391
4392 while Present (Renamed_Object (Pool))
4393 and then Is_Entity_Name (Renamed_Object (Pool))
4394 loop
4395 Pool := Entity (Renamed_Object (Pool));
4396 end loop;
4397
4398 if Present (Renamed_Object (Pool))
4399 and then Nkind (Renamed_Object (Pool)) = N_Type_Conversion
4400 and then Is_Entity_Name (Expression (Renamed_Object (Pool)))
4401 then
4402 Pool := Entity (Expression (Renamed_Object (Pool)));
4403 end if;
4404
4405 Set_Associated_Storage_Pool (U_Ent, Pool);
4406
4407 elsif Nkind (Expr) = N_Type_Conversion
4408 and then Is_Entity_Name (Expression (Expr))
4409 and then Nkind (Original_Node (Expr)) = N_Attribute_Reference
4410 then
4411 Pool := Entity (Expression (Expr));
4412 Set_Associated_Storage_Pool (U_Ent, Pool);
4413
4414 else
4415 Error_Msg_N ("incorrect reference to a Storage Pool", Expr);
4416 return;
4417 end if;
4418 end;
4419
4420 ------------------
4421 -- Storage_Size --
4422 ------------------
4423
4424 -- Storage_Size attribute definition clause
4425
4426 when Attribute_Storage_Size => Storage_Size : declare
4427 Btype : constant Entity_Id := Base_Type (U_Ent);
4428
4429 begin
4430 if Is_Task_Type (U_Ent) then
4431
4432 -- Check obsolescent (but never obsolescent if from aspect!)
4433
4434 if not From_Aspect_Specification (N) then
4435 Check_Restriction (No_Obsolescent_Features, N);
4436
4437 if Warn_On_Obsolescent_Feature then
4438 Error_Msg_N
4439 ("?j?storage size clause for task is an " &
4440 "obsolescent feature (RM J.9)", N);
4441 Error_Msg_N ("\?j?use Storage_Size pragma instead", N);
4442 end if;
4443 end if;
4444
4445 FOnly := True;
4446 end if;
4447
4448 if not Is_Access_Type (U_Ent)
4449 and then Ekind (U_Ent) /= E_Task_Type
4450 then
4451 Error_Msg_N ("storage size cannot be given for &", Nam);
4452
4453 elsif Is_Access_Type (U_Ent) and Is_Derived_Type (U_Ent) then
4454 Error_Msg_N
4455 ("storage size cannot be given for a derived access type",
4456 Nam);
4457
4458 elsif Duplicate_Clause then
4459 null;
4460
4461 else
4462 Analyze_And_Resolve (Expr, Any_Integer);
4463
4464 if Is_Access_Type (U_Ent) then
4465 if Present (Associated_Storage_Pool (U_Ent)) then
4466 Error_Msg_N ("storage pool already given for &", Nam);
4467 return;
4468 end if;
4469
4470 if Is_OK_Static_Expression (Expr)
4471 and then Expr_Value (Expr) = 0
4472 then
4473 Set_No_Pool_Assigned (Btype);
4474 end if;
4475 end if;
4476
4477 Set_Has_Storage_Size_Clause (Btype);
4478 end if;
4479 end Storage_Size;
4480
4481 -----------------
4482 -- Stream_Size --
4483 -----------------
4484
4485 when Attribute_Stream_Size => Stream_Size : declare
4486 Size : constant Uint := Static_Integer (Expr);
4487
4488 begin
4489 if Ada_Version <= Ada_95 then
4490 Check_Restriction (No_Implementation_Attributes, N);
4491 end if;
4492
4493 if Duplicate_Clause then
4494 null;
4495
4496 elsif Is_Elementary_Type (U_Ent) then
4497 if Size /= System_Storage_Unit
4498 and then
4499 Size /= System_Storage_Unit * 2
4500 and then
4501 Size /= System_Storage_Unit * 4
4502 and then
4503 Size /= System_Storage_Unit * 8
4504 then
4505 Error_Msg_Uint_1 := UI_From_Int (System_Storage_Unit);
4506 Error_Msg_N
4507 ("stream size for elementary type must be a"
4508 & " power of 2 and at least ^", N);
4509
4510 elsif RM_Size (U_Ent) > Size then
4511 Error_Msg_Uint_1 := RM_Size (U_Ent);
4512 Error_Msg_N
4513 ("stream size for elementary type must be a"
4514 & " power of 2 and at least ^", N);
4515 end if;
4516
4517 Set_Has_Stream_Size_Clause (U_Ent);
4518
4519 else
4520 Error_Msg_N ("Stream_Size cannot be given for &", Nam);
4521 end if;
4522 end Stream_Size;
4523
4524 ----------------
4525 -- Value_Size --
4526 ----------------
4527
4528 -- Value_Size attribute definition clause
4529
4530 when Attribute_Value_Size => Value_Size : declare
4531 Size : constant Uint := Static_Integer (Expr);
4532 Biased : Boolean;
4533
4534 begin
4535 if not Is_Type (U_Ent) then
4536 Error_Msg_N ("Value_Size cannot be given for &", Nam);
4537
4538 elsif Duplicate_Clause then
4539 null;
4540
4541 elsif Is_Array_Type (U_Ent)
4542 and then not Is_Constrained (U_Ent)
4543 then
4544 Error_Msg_N
4545 ("Value_Size cannot be given for unconstrained array", Nam);
4546
4547 else
4548 if Is_Elementary_Type (U_Ent) then
4549 Check_Size (Expr, U_Ent, Size, Biased);
4550 Set_Biased (U_Ent, N, "value size clause", Biased);
4551 end if;
4552
4553 Set_RM_Size (U_Ent, Size);
4554 end if;
4555 end Value_Size;
4556
4557 -----------------------
4558 -- Variable_Indexing --
4559 -----------------------
4560
4561 when Attribute_Variable_Indexing =>
4562 Check_Indexing_Functions;
4563
4564 -----------
4565 -- Write --
4566 -----------
4567
4568 when Attribute_Write =>
4569 Analyze_Stream_TSS_Definition (TSS_Stream_Write);
4570 Set_Has_Specified_Stream_Write (Ent);
4571
4572 -- All other attributes cannot be set
4573
4574 when others =>
4575 Error_Msg_N
4576 ("attribute& cannot be set with definition clause", N);
4577 end case;
4578
4579 -- The test for the type being frozen must be performed after any
4580 -- expression the clause has been analyzed since the expression itself
4581 -- might cause freezing that makes the clause illegal.
4582
4583 if Rep_Item_Too_Late (U_Ent, N, FOnly) then
4584 return;
4585 end if;
4586 end Analyze_Attribute_Definition_Clause;
4587
4588 ----------------------------
4589 -- Analyze_Code_Statement --
4590 ----------------------------
4591
4592 procedure Analyze_Code_Statement (N : Node_Id) is
4593 HSS : constant Node_Id := Parent (N);
4594 SBody : constant Node_Id := Parent (HSS);
4595 Subp : constant Entity_Id := Current_Scope;
4596 Stmt : Node_Id;
4597 Decl : Node_Id;
4598 StmtO : Node_Id;
4599 DeclO : Node_Id;
4600
4601 begin
4602 -- Analyze and check we get right type, note that this implements the
4603 -- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that
4604 -- is the only way that Asm_Insn could possibly be visible.
4605
4606 Analyze_And_Resolve (Expression (N));
4607
4608 if Etype (Expression (N)) = Any_Type then
4609 return;
4610 elsif Etype (Expression (N)) /= RTE (RE_Asm_Insn) then
4611 Error_Msg_N ("incorrect type for code statement", N);
4612 return;
4613 end if;
4614
4615 Check_Code_Statement (N);
4616
4617 -- Make sure we appear in the handled statement sequence of a
4618 -- subprogram (RM 13.8(3)).
4619
4620 if Nkind (HSS) /= N_Handled_Sequence_Of_Statements
4621 or else Nkind (SBody) /= N_Subprogram_Body
4622 then
4623 Error_Msg_N
4624 ("code statement can only appear in body of subprogram", N);
4625 return;
4626 end if;
4627
4628 -- Do remaining checks (RM 13.8(3)) if not already done
4629
4630 if not Is_Machine_Code_Subprogram (Subp) then
4631 Set_Is_Machine_Code_Subprogram (Subp);
4632
4633 -- No exception handlers allowed
4634
4635 if Present (Exception_Handlers (HSS)) then
4636 Error_Msg_N
4637 ("exception handlers not permitted in machine code subprogram",
4638 First (Exception_Handlers (HSS)));
4639 end if;
4640
4641 -- No declarations other than use clauses and pragmas (we allow
4642 -- certain internally generated declarations as well).
4643
4644 Decl := First (Declarations (SBody));
4645 while Present (Decl) loop
4646 DeclO := Original_Node (Decl);
4647 if Comes_From_Source (DeclO)
4648 and not Nkind_In (DeclO, N_Pragma,
4649 N_Use_Package_Clause,
4650 N_Use_Type_Clause,
4651 N_Implicit_Label_Declaration)
4652 then
4653 Error_Msg_N
4654 ("this declaration not allowed in machine code subprogram",
4655 DeclO);
4656 end if;
4657
4658 Next (Decl);
4659 end loop;
4660
4661 -- No statements other than code statements, pragmas, and labels.
4662 -- Again we allow certain internally generated statements.
4663
4664 -- In Ada 2012, qualified expressions are names, and the code
4665 -- statement is initially parsed as a procedure call.
4666
4667 Stmt := First (Statements (HSS));
4668 while Present (Stmt) loop
4669 StmtO := Original_Node (Stmt);
4670
4671 -- A procedure call transformed into a code statement is OK.
4672
4673 if Ada_Version >= Ada_2012
4674 and then Nkind (StmtO) = N_Procedure_Call_Statement
4675 and then Nkind (Name (StmtO)) = N_Qualified_Expression
4676 then
4677 null;
4678
4679 elsif Comes_From_Source (StmtO)
4680 and then not Nkind_In (StmtO, N_Pragma,
4681 N_Label,
4682 N_Code_Statement)
4683 then
4684 Error_Msg_N
4685 ("this statement is not allowed in machine code subprogram",
4686 StmtO);
4687 end if;
4688
4689 Next (Stmt);
4690 end loop;
4691 end if;
4692 end Analyze_Code_Statement;
4693
4694 -----------------------------------------------
4695 -- Analyze_Enumeration_Representation_Clause --
4696 -----------------------------------------------
4697
4698 procedure Analyze_Enumeration_Representation_Clause (N : Node_Id) is
4699 Ident : constant Node_Id := Identifier (N);
4700 Aggr : constant Node_Id := Array_Aggregate (N);
4701 Enumtype : Entity_Id;
4702 Elit : Entity_Id;
4703 Expr : Node_Id;
4704 Assoc : Node_Id;
4705 Choice : Node_Id;
4706 Val : Uint;
4707
4708 Err : Boolean := False;
4709 -- Set True to avoid cascade errors and crashes on incorrect source code
4710
4711 Lo : constant Uint := Expr_Value (Type_Low_Bound (Universal_Integer));
4712 Hi : constant Uint := Expr_Value (Type_High_Bound (Universal_Integer));
4713 -- Allowed range of universal integer (= allowed range of enum lit vals)
4714
4715 Min : Uint;
4716 Max : Uint;
4717 -- Minimum and maximum values of entries
4718
4719 Max_Node : Node_Id;
4720 -- Pointer to node for literal providing max value
4721
4722 begin
4723 if Ignore_Rep_Clauses then
4724 return;
4725 end if;
4726
4727 -- Ignore enumeration rep clauses by default in CodePeer mode,
4728 -- unless -gnatd.I is specified, as a work around for potential false
4729 -- positive messages.
4730
4731 if CodePeer_Mode and not Debug_Flag_Dot_II then
4732 return;
4733 end if;
4734
4735 -- First some basic error checks
4736
4737 Find_Type (Ident);
4738 Enumtype := Entity (Ident);
4739
4740 if Enumtype = Any_Type
4741 or else Rep_Item_Too_Early (Enumtype, N)
4742 then
4743 return;
4744 else
4745 Enumtype := Underlying_Type (Enumtype);
4746 end if;
4747
4748 if not Is_Enumeration_Type (Enumtype) then
4749 Error_Msg_NE
4750 ("enumeration type required, found}",
4751 Ident, First_Subtype (Enumtype));
4752 return;
4753 end if;
4754
4755 -- Ignore rep clause on generic actual type. This will already have
4756 -- been flagged on the template as an error, and this is the safest
4757 -- way to ensure we don't get a junk cascaded message in the instance.
4758
4759 if Is_Generic_Actual_Type (Enumtype) then
4760 return;
4761
4762 -- Type must be in current scope
4763
4764 elsif Scope (Enumtype) /= Current_Scope then
4765 Error_Msg_N ("type must be declared in this scope", Ident);
4766 return;
4767
4768 -- Type must be a first subtype
4769
4770 elsif not Is_First_Subtype (Enumtype) then
4771 Error_Msg_N ("cannot give enumeration rep clause for subtype", N);
4772 return;
4773
4774 -- Ignore duplicate rep clause
4775
4776 elsif Has_Enumeration_Rep_Clause (Enumtype) then
4777 Error_Msg_N ("duplicate enumeration rep clause ignored", N);
4778 return;
4779
4780 -- Don't allow rep clause for standard [wide_[wide_]]character
4781
4782 elsif Is_Standard_Character_Type (Enumtype) then
4783 Error_Msg_N ("enumeration rep clause not allowed for this type", N);
4784 return;
4785
4786 -- Check that the expression is a proper aggregate (no parentheses)
4787
4788 elsif Paren_Count (Aggr) /= 0 then
4789 Error_Msg
4790 ("extra parentheses surrounding aggregate not allowed",
4791 First_Sloc (Aggr));
4792 return;
4793
4794 -- All tests passed, so set rep clause in place
4795
4796 else
4797 Set_Has_Enumeration_Rep_Clause (Enumtype);
4798 Set_Has_Enumeration_Rep_Clause (Base_Type (Enumtype));
4799 end if;
4800
4801 -- Now we process the aggregate. Note that we don't use the normal
4802 -- aggregate code for this purpose, because we don't want any of the
4803 -- normal expansion activities, and a number of special semantic
4804 -- rules apply (including the component type being any integer type)
4805
4806 Elit := First_Literal (Enumtype);
4807
4808 -- First the positional entries if any
4809
4810 if Present (Expressions (Aggr)) then
4811 Expr := First (Expressions (Aggr));
4812 while Present (Expr) loop
4813 if No (Elit) then
4814 Error_Msg_N ("too many entries in aggregate", Expr);
4815 return;
4816 end if;
4817
4818 Val := Static_Integer (Expr);
4819
4820 -- Err signals that we found some incorrect entries processing
4821 -- the list. The final checks for completeness and ordering are
4822 -- skipped in this case.
4823
4824 if Val = No_Uint then
4825 Err := True;
4826 elsif Val < Lo or else Hi < Val then
4827 Error_Msg_N ("value outside permitted range", Expr);
4828 Err := True;
4829 end if;
4830
4831 Set_Enumeration_Rep (Elit, Val);
4832 Set_Enumeration_Rep_Expr (Elit, Expr);
4833 Next (Expr);
4834 Next (Elit);
4835 end loop;
4836 end if;
4837
4838 -- Now process the named entries if present
4839
4840 if Present (Component_Associations (Aggr)) then
4841 Assoc := First (Component_Associations (Aggr));
4842 while Present (Assoc) loop
4843 Choice := First (Choices (Assoc));
4844
4845 if Present (Next (Choice)) then
4846 Error_Msg_N
4847 ("multiple choice not allowed here", Next (Choice));
4848 Err := True;
4849 end if;
4850
4851 if Nkind (Choice) = N_Others_Choice then
4852 Error_Msg_N ("others choice not allowed here", Choice);
4853 Err := True;
4854
4855 elsif Nkind (Choice) = N_Range then
4856
4857 -- ??? should allow zero/one element range here
4858
4859 Error_Msg_N ("range not allowed here", Choice);
4860 Err := True;
4861
4862 else
4863 Analyze_And_Resolve (Choice, Enumtype);
4864
4865 if Error_Posted (Choice) then
4866 Err := True;
4867 end if;
4868
4869 if not Err then
4870 if Is_Entity_Name (Choice)
4871 and then Is_Type (Entity (Choice))
4872 then
4873 Error_Msg_N ("subtype name not allowed here", Choice);
4874 Err := True;
4875
4876 -- ??? should allow static subtype with zero/one entry
4877
4878 elsif Etype (Choice) = Base_Type (Enumtype) then
4879 if not Is_Static_Expression (Choice) then
4880 Flag_Non_Static_Expr
4881 ("non-static expression used for choice!", Choice);
4882 Err := True;
4883
4884 else
4885 Elit := Expr_Value_E (Choice);
4886
4887 if Present (Enumeration_Rep_Expr (Elit)) then
4888 Error_Msg_Sloc :=
4889 Sloc (Enumeration_Rep_Expr (Elit));
4890 Error_Msg_NE
4891 ("representation for& previously given#",
4892 Choice, Elit);
4893 Err := True;
4894 end if;
4895
4896 Set_Enumeration_Rep_Expr (Elit, Expression (Assoc));
4897
4898 Expr := Expression (Assoc);
4899 Val := Static_Integer (Expr);
4900
4901 if Val = No_Uint then
4902 Err := True;
4903
4904 elsif Val < Lo or else Hi < Val then
4905 Error_Msg_N ("value outside permitted range", Expr);
4906 Err := True;
4907 end if;
4908
4909 Set_Enumeration_Rep (Elit, Val);
4910 end if;
4911 end if;
4912 end if;
4913 end if;
4914
4915 Next (Assoc);
4916 end loop;
4917 end if;
4918
4919 -- Aggregate is fully processed. Now we check that a full set of
4920 -- representations was given, and that they are in range and in order.
4921 -- These checks are only done if no other errors occurred.
4922
4923 if not Err then
4924 Min := No_Uint;
4925 Max := No_Uint;
4926
4927 Elit := First_Literal (Enumtype);
4928 while Present (Elit) loop
4929 if No (Enumeration_Rep_Expr (Elit)) then
4930 Error_Msg_NE ("missing representation for&!", N, Elit);
4931
4932 else
4933 Val := Enumeration_Rep (Elit);
4934
4935 if Min = No_Uint then
4936 Min := Val;
4937 end if;
4938
4939 if Val /= No_Uint then
4940 if Max /= No_Uint and then Val <= Max then
4941 Error_Msg_NE
4942 ("enumeration value for& not ordered!",
4943 Enumeration_Rep_Expr (Elit), Elit);
4944 end if;
4945
4946 Max_Node := Enumeration_Rep_Expr (Elit);
4947 Max := Val;
4948 end if;
4949
4950 -- If there is at least one literal whose representation is not
4951 -- equal to the Pos value, then note that this enumeration type
4952 -- has a non-standard representation.
4953
4954 if Val /= Enumeration_Pos (Elit) then
4955 Set_Has_Non_Standard_Rep (Base_Type (Enumtype));
4956 end if;
4957 end if;
4958
4959 Next (Elit);
4960 end loop;
4961
4962 -- Now set proper size information
4963
4964 declare
4965 Minsize : Uint := UI_From_Int (Minimum_Size (Enumtype));
4966
4967 begin
4968 if Has_Size_Clause (Enumtype) then
4969
4970 -- All OK, if size is OK now
4971
4972 if RM_Size (Enumtype) >= Minsize then
4973 null;
4974
4975 else
4976 -- Try if we can get by with biasing
4977
4978 Minsize :=
4979 UI_From_Int (Minimum_Size (Enumtype, Biased => True));
4980
4981 -- Error message if even biasing does not work
4982
4983 if RM_Size (Enumtype) < Minsize then
4984 Error_Msg_Uint_1 := RM_Size (Enumtype);
4985 Error_Msg_Uint_2 := Max;
4986 Error_Msg_N
4987 ("previously given size (^) is too small "
4988 & "for this value (^)", Max_Node);
4989
4990 -- If biasing worked, indicate that we now have biased rep
4991
4992 else
4993 Set_Biased
4994 (Enumtype, Size_Clause (Enumtype), "size clause");
4995 end if;
4996 end if;
4997
4998 else
4999 Set_RM_Size (Enumtype, Minsize);
5000 Set_Enum_Esize (Enumtype);
5001 end if;
5002
5003 Set_RM_Size (Base_Type (Enumtype), RM_Size (Enumtype));
5004 Set_Esize (Base_Type (Enumtype), Esize (Enumtype));
5005 Set_Alignment (Base_Type (Enumtype), Alignment (Enumtype));
5006 end;
5007 end if;
5008
5009 -- We repeat the too late test in case it froze itself!
5010
5011 if Rep_Item_Too_Late (Enumtype, N) then
5012 null;
5013 end if;
5014 end Analyze_Enumeration_Representation_Clause;
5015
5016 ----------------------------
5017 -- Analyze_Free_Statement --
5018 ----------------------------
5019
5020 procedure Analyze_Free_Statement (N : Node_Id) is
5021 begin
5022 Analyze (Expression (N));
5023 end Analyze_Free_Statement;
5024
5025 ---------------------------
5026 -- Analyze_Freeze_Entity --
5027 ---------------------------
5028
5029 procedure Analyze_Freeze_Entity (N : Node_Id) is
5030 E : constant Entity_Id := Entity (N);
5031
5032 begin
5033 -- Remember that we are processing a freezing entity. Required to
5034 -- ensure correct decoration of internal entities associated with
5035 -- interfaces (see New_Overloaded_Entity).
5036
5037 Inside_Freezing_Actions := Inside_Freezing_Actions + 1;
5038
5039 -- For tagged types covering interfaces add internal entities that link
5040 -- the primitives of the interfaces with the primitives that cover them.
5041 -- Note: These entities were originally generated only when generating
5042 -- code because their main purpose was to provide support to initialize
5043 -- the secondary dispatch tables. They are now generated also when
5044 -- compiling with no code generation to provide ASIS the relationship
5045 -- between interface primitives and tagged type primitives. They are
5046 -- also used to locate primitives covering interfaces when processing
5047 -- generics (see Derive_Subprograms).
5048
5049 if Ada_Version >= Ada_2005
5050 and then Ekind (E) = E_Record_Type
5051 and then Is_Tagged_Type (E)
5052 and then not Is_Interface (E)
5053 and then Has_Interfaces (E)
5054 then
5055 -- This would be a good common place to call the routine that checks
5056 -- overriding of interface primitives (and thus factorize calls to
5057 -- Check_Abstract_Overriding located at different contexts in the
5058 -- compiler). However, this is not possible because it causes
5059 -- spurious errors in case of late overriding.
5060
5061 Add_Internal_Interface_Entities (E);
5062 end if;
5063
5064 -- Check CPP types
5065
5066 if Ekind (E) = E_Record_Type
5067 and then Is_CPP_Class (E)
5068 and then Is_Tagged_Type (E)
5069 and then Tagged_Type_Expansion
5070 and then Expander_Active
5071 then
5072 if CPP_Num_Prims (E) = 0 then
5073
5074 -- If the CPP type has user defined components then it must import
5075 -- primitives from C++. This is required because if the C++ class
5076 -- has no primitives then the C++ compiler does not added the _tag
5077 -- component to the type.
5078
5079 pragma Assert (Chars (First_Entity (E)) = Name_uTag);
5080
5081 if First_Entity (E) /= Last_Entity (E) then
5082 Error_Msg_N
5083 ("'C'P'P type must import at least one primitive from C++??",
5084 E);
5085 end if;
5086 end if;
5087
5088 -- Check that all its primitives are abstract or imported from C++.
5089 -- Check also availability of the C++ constructor.
5090
5091 declare
5092 Has_Constructors : constant Boolean := Has_CPP_Constructors (E);
5093 Elmt : Elmt_Id;
5094 Error_Reported : Boolean := False;
5095 Prim : Node_Id;
5096
5097 begin
5098 Elmt := First_Elmt (Primitive_Operations (E));
5099 while Present (Elmt) loop
5100 Prim := Node (Elmt);
5101
5102 if Comes_From_Source (Prim) then
5103 if Is_Abstract_Subprogram (Prim) then
5104 null;
5105
5106 elsif not Is_Imported (Prim)
5107 or else Convention (Prim) /= Convention_CPP
5108 then
5109 Error_Msg_N
5110 ("primitives of 'C'P'P types must be imported from C++ "
5111 & "or abstract??", Prim);
5112
5113 elsif not Has_Constructors
5114 and then not Error_Reported
5115 then
5116 Error_Msg_Name_1 := Chars (E);
5117 Error_Msg_N
5118 ("??'C'P'P constructor required for type %", Prim);
5119 Error_Reported := True;
5120 end if;
5121 end if;
5122
5123 Next_Elmt (Elmt);
5124 end loop;
5125 end;
5126 end if;
5127
5128 -- Check Ada derivation of CPP type
5129
5130 if Expander_Active
5131 and then Tagged_Type_Expansion
5132 and then Ekind (E) = E_Record_Type
5133 and then Etype (E) /= E
5134 and then Is_CPP_Class (Etype (E))
5135 and then CPP_Num_Prims (Etype (E)) > 0
5136 and then not Is_CPP_Class (E)
5137 and then not Has_CPP_Constructors (Etype (E))
5138 then
5139 -- If the parent has C++ primitives but it has no constructor then
5140 -- check that all the primitives are overridden in this derivation;
5141 -- otherwise the constructor of the parent is needed to build the
5142 -- dispatch table.
5143
5144 declare
5145 Elmt : Elmt_Id;
5146 Prim : Node_Id;
5147
5148 begin
5149 Elmt := First_Elmt (Primitive_Operations (E));
5150 while Present (Elmt) loop
5151 Prim := Node (Elmt);
5152
5153 if not Is_Abstract_Subprogram (Prim)
5154 and then No (Interface_Alias (Prim))
5155 and then Find_Dispatching_Type (Ultimate_Alias (Prim)) /= E
5156 then
5157 Error_Msg_Name_1 := Chars (Etype (E));
5158 Error_Msg_N
5159 ("'C'P'P constructor required for parent type %", E);
5160 exit;
5161 end if;
5162
5163 Next_Elmt (Elmt);
5164 end loop;
5165 end;
5166 end if;
5167
5168 Inside_Freezing_Actions := Inside_Freezing_Actions - 1;
5169
5170 -- If we have a type with predicates, build predicate function
5171
5172 if Is_Type (E) and then Has_Predicates (E) then
5173 Build_Predicate_Functions (E, N);
5174 end if;
5175
5176 -- If type has delayed aspects, this is where we do the preanalysis at
5177 -- the freeze point, as part of the consistent visibility check. Note
5178 -- that this must be done after calling Build_Predicate_Functions or
5179 -- Build_Invariant_Procedure since these subprograms fix occurrences of
5180 -- the subtype name in the saved expression so that they will not cause
5181 -- trouble in the preanalysis.
5182
5183 if Has_Delayed_Aspects (E)
5184 and then Scope (E) = Current_Scope
5185 then
5186 -- Retrieve the visibility to the discriminants in order to properly
5187 -- analyze the aspects.
5188
5189 Push_Scope_And_Install_Discriminants (E);
5190
5191 declare
5192 Ritem : Node_Id;
5193
5194 begin
5195 -- Look for aspect specification entries for this entity
5196
5197 Ritem := First_Rep_Item (E);
5198 while Present (Ritem) loop
5199 if Nkind (Ritem) = N_Aspect_Specification
5200 and then Entity (Ritem) = E
5201 and then Is_Delayed_Aspect (Ritem)
5202 then
5203 Check_Aspect_At_Freeze_Point (Ritem);
5204 end if;
5205
5206 Next_Rep_Item (Ritem);
5207 end loop;
5208 end;
5209
5210 Uninstall_Discriminants_And_Pop_Scope (E);
5211 end if;
5212 end Analyze_Freeze_Entity;
5213
5214 ------------------------------------------
5215 -- Analyze_Record_Representation_Clause --
5216 ------------------------------------------
5217
5218 -- Note: we check as much as we can here, but we can't do any checks
5219 -- based on the position values (e.g. overlap checks) until freeze time
5220 -- because especially in Ada 2005 (machine scalar mode), the processing
5221 -- for non-standard bit order can substantially change the positions.
5222 -- See procedure Check_Record_Representation_Clause (called from Freeze)
5223 -- for the remainder of this processing.
5224
5225 procedure Analyze_Record_Representation_Clause (N : Node_Id) is
5226 Ident : constant Node_Id := Identifier (N);
5227 Biased : Boolean;
5228 CC : Node_Id;
5229 Comp : Entity_Id;
5230 Fbit : Uint;
5231 Hbit : Uint := Uint_0;
5232 Lbit : Uint;
5233 Ocomp : Entity_Id;
5234 Posit : Uint;
5235 Rectype : Entity_Id;
5236 Recdef : Node_Id;
5237
5238 function Is_Inherited (Comp : Entity_Id) return Boolean;
5239 -- True if Comp is an inherited component in a record extension
5240
5241 ------------------
5242 -- Is_Inherited --
5243 ------------------
5244
5245 function Is_Inherited (Comp : Entity_Id) return Boolean is
5246 Comp_Base : Entity_Id;
5247
5248 begin
5249 if Ekind (Rectype) = E_Record_Subtype then
5250 Comp_Base := Original_Record_Component (Comp);
5251 else
5252 Comp_Base := Comp;
5253 end if;
5254
5255 return Comp_Base /= Original_Record_Component (Comp_Base);
5256 end Is_Inherited;
5257
5258 -- Local variables
5259
5260 Is_Record_Extension : Boolean;
5261 -- True if Rectype is a record extension
5262
5263 CR_Pragma : Node_Id := Empty;
5264 -- Points to N_Pragma node if Complete_Representation pragma present
5265
5266 -- Start of processing for Analyze_Record_Representation_Clause
5267
5268 begin
5269 if Ignore_Rep_Clauses then
5270 return;
5271 end if;
5272
5273 Find_Type (Ident);
5274 Rectype := Entity (Ident);
5275
5276 if Rectype = Any_Type or else Rep_Item_Too_Early (Rectype, N) then
5277 return;
5278 else
5279 Rectype := Underlying_Type (Rectype);
5280 end if;
5281
5282 -- First some basic error checks
5283
5284 if not Is_Record_Type (Rectype) then
5285 Error_Msg_NE
5286 ("record type required, found}", Ident, First_Subtype (Rectype));
5287 return;
5288
5289 elsif Scope (Rectype) /= Current_Scope then
5290 Error_Msg_N ("type must be declared in this scope", N);
5291 return;
5292
5293 elsif not Is_First_Subtype (Rectype) then
5294 Error_Msg_N ("cannot give record rep clause for subtype", N);
5295 return;
5296
5297 elsif Has_Record_Rep_Clause (Rectype) then
5298 Error_Msg_N ("duplicate record rep clause ignored", N);
5299 return;
5300
5301 elsif Rep_Item_Too_Late (Rectype, N) then
5302 return;
5303 end if;
5304
5305 -- We know we have a first subtype, now possibly go the the anonymous
5306 -- base type to determine whether Rectype is a record extension.
5307
5308 Recdef := Type_Definition (Declaration_Node (Base_Type (Rectype)));
5309 Is_Record_Extension :=
5310 Nkind (Recdef) = N_Derived_Type_Definition
5311 and then Present (Record_Extension_Part (Recdef));
5312
5313 if Present (Mod_Clause (N)) then
5314 declare
5315 Loc : constant Source_Ptr := Sloc (N);
5316 M : constant Node_Id := Mod_Clause (N);
5317 P : constant List_Id := Pragmas_Before (M);
5318 AtM_Nod : Node_Id;
5319
5320 Mod_Val : Uint;
5321 pragma Warnings (Off, Mod_Val);
5322
5323 begin
5324 Check_Restriction (No_Obsolescent_Features, Mod_Clause (N));
5325
5326 if Warn_On_Obsolescent_Feature then
5327 Error_Msg_N
5328 ("?j?mod clause is an obsolescent feature (RM J.8)", N);
5329 Error_Msg_N
5330 ("\?j?use alignment attribute definition clause instead", N);
5331 end if;
5332
5333 if Present (P) then
5334 Analyze_List (P);
5335 end if;
5336
5337 -- In ASIS_Mode mode, expansion is disabled, but we must convert
5338 -- the Mod clause into an alignment clause anyway, so that the
5339 -- back-end can compute and back-annotate properly the size and
5340 -- alignment of types that may include this record.
5341
5342 -- This seems dubious, this destroys the source tree in a manner
5343 -- not detectable by ASIS ???
5344
5345 if Operating_Mode = Check_Semantics and then ASIS_Mode then
5346 AtM_Nod :=
5347 Make_Attribute_Definition_Clause (Loc,
5348 Name => New_Reference_To (Base_Type (Rectype), Loc),
5349 Chars => Name_Alignment,
5350 Expression => Relocate_Node (Expression (M)));
5351
5352 Set_From_At_Mod (AtM_Nod);
5353 Insert_After (N, AtM_Nod);
5354 Mod_Val := Get_Alignment_Value (Expression (AtM_Nod));
5355 Set_Mod_Clause (N, Empty);
5356
5357 else
5358 -- Get the alignment value to perform error checking
5359
5360 Mod_Val := Get_Alignment_Value (Expression (M));
5361 end if;
5362 end;
5363 end if;
5364
5365 -- For untagged types, clear any existing component clauses for the
5366 -- type. If the type is derived, this is what allows us to override
5367 -- a rep clause for the parent. For type extensions, the representation
5368 -- of the inherited components is inherited, so we want to keep previous
5369 -- component clauses for completeness.
5370
5371 if not Is_Tagged_Type (Rectype) then
5372 Comp := First_Component_Or_Discriminant (Rectype);
5373 while Present (Comp) loop
5374 Set_Component_Clause (Comp, Empty);
5375 Next_Component_Or_Discriminant (Comp);
5376 end loop;
5377 end if;
5378
5379 -- All done if no component clauses
5380
5381 CC := First (Component_Clauses (N));
5382
5383 if No (CC) then
5384 return;
5385 end if;
5386
5387 -- A representation like this applies to the base type
5388
5389 Set_Has_Record_Rep_Clause (Base_Type (Rectype));
5390 Set_Has_Non_Standard_Rep (Base_Type (Rectype));
5391 Set_Has_Specified_Layout (Base_Type (Rectype));
5392
5393 -- Process the component clauses
5394
5395 while Present (CC) loop
5396
5397 -- Pragma
5398
5399 if Nkind (CC) = N_Pragma then
5400 Analyze (CC);
5401
5402 -- The only pragma of interest is Complete_Representation
5403
5404 if Pragma_Name (CC) = Name_Complete_Representation then
5405 CR_Pragma := CC;
5406 end if;
5407
5408 -- Processing for real component clause
5409
5410 else
5411 Posit := Static_Integer (Position (CC));
5412 Fbit := Static_Integer (First_Bit (CC));
5413 Lbit := Static_Integer (Last_Bit (CC));
5414
5415 if Posit /= No_Uint
5416 and then Fbit /= No_Uint
5417 and then Lbit /= No_Uint
5418 then
5419 if Posit < 0 then
5420 Error_Msg_N
5421 ("position cannot be negative", Position (CC));
5422
5423 elsif Fbit < 0 then
5424 Error_Msg_N
5425 ("first bit cannot be negative", First_Bit (CC));
5426
5427 -- The Last_Bit specified in a component clause must not be
5428 -- less than the First_Bit minus one (RM-13.5.1(10)).
5429
5430 elsif Lbit < Fbit - 1 then
5431 Error_Msg_N
5432 ("last bit cannot be less than first bit minus one",
5433 Last_Bit (CC));
5434
5435 -- Values look OK, so find the corresponding record component
5436 -- Even though the syntax allows an attribute reference for
5437 -- implementation-defined components, GNAT does not allow the
5438 -- tag to get an explicit position.
5439
5440 elsif Nkind (Component_Name (CC)) = N_Attribute_Reference then
5441 if Attribute_Name (Component_Name (CC)) = Name_Tag then
5442 Error_Msg_N ("position of tag cannot be specified", CC);
5443 else
5444 Error_Msg_N ("illegal component name", CC);
5445 end if;
5446
5447 else
5448 Comp := First_Entity (Rectype);
5449 while Present (Comp) loop
5450 exit when Chars (Comp) = Chars (Component_Name (CC));
5451 Next_Entity (Comp);
5452 end loop;
5453
5454 if No (Comp) then
5455
5456 -- Maybe component of base type that is absent from
5457 -- statically constrained first subtype.
5458
5459 Comp := First_Entity (Base_Type (Rectype));
5460 while Present (Comp) loop
5461 exit when Chars (Comp) = Chars (Component_Name (CC));
5462 Next_Entity (Comp);
5463 end loop;
5464 end if;
5465
5466 if No (Comp) then
5467 Error_Msg_N
5468 ("component clause is for non-existent field", CC);
5469
5470 -- Ada 2012 (AI05-0026): Any name that denotes a
5471 -- discriminant of an object of an unchecked union type
5472 -- shall not occur within a record_representation_clause.
5473
5474 -- The general restriction of using record rep clauses on
5475 -- Unchecked_Union types has now been lifted. Since it is
5476 -- possible to introduce a record rep clause which mentions
5477 -- the discriminant of an Unchecked_Union in non-Ada 2012
5478 -- code, this check is applied to all versions of the
5479 -- language.
5480
5481 elsif Ekind (Comp) = E_Discriminant
5482 and then Is_Unchecked_Union (Rectype)
5483 then
5484 Error_Msg_N
5485 ("cannot reference discriminant of unchecked union",
5486 Component_Name (CC));
5487
5488 elsif Is_Record_Extension and then Is_Inherited (Comp) then
5489 Error_Msg_NE
5490 ("component clause not allowed for inherited "
5491 & "component&", CC, Comp);
5492
5493 elsif Present (Component_Clause (Comp)) then
5494
5495 -- Diagnose duplicate rep clause, or check consistency
5496 -- if this is an inherited component. In a double fault,
5497 -- there may be a duplicate inconsistent clause for an
5498 -- inherited component.
5499
5500 if Scope (Original_Record_Component (Comp)) = Rectype
5501 or else Parent (Component_Clause (Comp)) = N
5502 then
5503 Error_Msg_Sloc := Sloc (Component_Clause (Comp));
5504 Error_Msg_N ("component clause previously given#", CC);
5505
5506 else
5507 declare
5508 Rep1 : constant Node_Id := Component_Clause (Comp);
5509 begin
5510 if Intval (Position (Rep1)) /=
5511 Intval (Position (CC))
5512 or else Intval (First_Bit (Rep1)) /=
5513 Intval (First_Bit (CC))
5514 or else Intval (Last_Bit (Rep1)) /=
5515 Intval (Last_Bit (CC))
5516 then
5517 Error_Msg_N
5518 ("component clause inconsistent "
5519 & "with representation of ancestor", CC);
5520
5521 elsif Warn_On_Redundant_Constructs then
5522 Error_Msg_N
5523 ("?r?redundant confirming component clause "
5524 & "for component!", CC);
5525 end if;
5526 end;
5527 end if;
5528
5529 -- Normal case where this is the first component clause we
5530 -- have seen for this entity, so set it up properly.
5531
5532 else
5533 -- Make reference for field in record rep clause and set
5534 -- appropriate entity field in the field identifier.
5535
5536 Generate_Reference
5537 (Comp, Component_Name (CC), Set_Ref => False);
5538 Set_Entity (Component_Name (CC), Comp);
5539
5540 -- Update Fbit and Lbit to the actual bit number
5541
5542 Fbit := Fbit + UI_From_Int (SSU) * Posit;
5543 Lbit := Lbit + UI_From_Int (SSU) * Posit;
5544
5545 if Has_Size_Clause (Rectype)
5546 and then RM_Size (Rectype) <= Lbit
5547 then
5548 Error_Msg_N
5549 ("bit number out of range of specified size",
5550 Last_Bit (CC));
5551 else
5552 Set_Component_Clause (Comp, CC);
5553 Set_Component_Bit_Offset (Comp, Fbit);
5554 Set_Esize (Comp, 1 + (Lbit - Fbit));
5555 Set_Normalized_First_Bit (Comp, Fbit mod SSU);
5556 Set_Normalized_Position (Comp, Fbit / SSU);
5557
5558 if Warn_On_Overridden_Size
5559 and then Has_Size_Clause (Etype (Comp))
5560 and then RM_Size (Etype (Comp)) /= Esize (Comp)
5561 then
5562 Error_Msg_NE
5563 ("?S?component size overrides size clause for&",
5564 Component_Name (CC), Etype (Comp));
5565 end if;
5566
5567 -- This information is also set in the corresponding
5568 -- component of the base type, found by accessing the
5569 -- Original_Record_Component link if it is present.
5570
5571 Ocomp := Original_Record_Component (Comp);
5572
5573 if Hbit < Lbit then
5574 Hbit := Lbit;
5575 end if;
5576
5577 Check_Size
5578 (Component_Name (CC),
5579 Etype (Comp),
5580 Esize (Comp),
5581 Biased);
5582
5583 Set_Biased
5584 (Comp, First_Node (CC), "component clause", Biased);
5585
5586 if Present (Ocomp) then
5587 Set_Component_Clause (Ocomp, CC);
5588 Set_Component_Bit_Offset (Ocomp, Fbit);
5589 Set_Normalized_First_Bit (Ocomp, Fbit mod SSU);
5590 Set_Normalized_Position (Ocomp, Fbit / SSU);
5591 Set_Esize (Ocomp, 1 + (Lbit - Fbit));
5592
5593 Set_Normalized_Position_Max
5594 (Ocomp, Normalized_Position (Ocomp));
5595
5596 -- Note: we don't use Set_Biased here, because we
5597 -- already gave a warning above if needed, and we
5598 -- would get a duplicate for the same name here.
5599
5600 Set_Has_Biased_Representation
5601 (Ocomp, Has_Biased_Representation (Comp));
5602 end if;
5603
5604 if Esize (Comp) < 0 then
5605 Error_Msg_N ("component size is negative", CC);
5606 end if;
5607 end if;
5608 end if;
5609 end if;
5610 end if;
5611 end if;
5612
5613 Next (CC);
5614 end loop;
5615
5616 -- Check missing components if Complete_Representation pragma appeared
5617
5618 if Present (CR_Pragma) then
5619 Comp := First_Component_Or_Discriminant (Rectype);
5620 while Present (Comp) loop
5621 if No (Component_Clause (Comp)) then
5622 Error_Msg_NE
5623 ("missing component clause for &", CR_Pragma, Comp);
5624 end if;
5625
5626 Next_Component_Or_Discriminant (Comp);
5627 end loop;
5628
5629 -- Give missing components warning if required
5630
5631 elsif Warn_On_Unrepped_Components then
5632 declare
5633 Num_Repped_Components : Nat := 0;
5634 Num_Unrepped_Components : Nat := 0;
5635
5636 begin
5637 -- First count number of repped and unrepped components
5638
5639 Comp := First_Component_Or_Discriminant (Rectype);
5640 while Present (Comp) loop
5641 if Present (Component_Clause (Comp)) then
5642 Num_Repped_Components := Num_Repped_Components + 1;
5643 else
5644 Num_Unrepped_Components := Num_Unrepped_Components + 1;
5645 end if;
5646
5647 Next_Component_Or_Discriminant (Comp);
5648 end loop;
5649
5650 -- We are only interested in the case where there is at least one
5651 -- unrepped component, and at least half the components have rep
5652 -- clauses. We figure that if less than half have them, then the
5653 -- partial rep clause is really intentional. If the component
5654 -- type has no underlying type set at this point (as for a generic
5655 -- formal type), we don't know enough to give a warning on the
5656 -- component.
5657
5658 if Num_Unrepped_Components > 0
5659 and then Num_Unrepped_Components < Num_Repped_Components
5660 then
5661 Comp := First_Component_Or_Discriminant (Rectype);
5662 while Present (Comp) loop
5663 if No (Component_Clause (Comp))
5664 and then Comes_From_Source (Comp)
5665 and then Present (Underlying_Type (Etype (Comp)))
5666 and then (Is_Scalar_Type (Underlying_Type (Etype (Comp)))
5667 or else Size_Known_At_Compile_Time
5668 (Underlying_Type (Etype (Comp))))
5669 and then not Has_Warnings_Off (Rectype)
5670 then
5671 Error_Msg_Sloc := Sloc (Comp);
5672 Error_Msg_NE
5673 ("?C?no component clause given for & declared #",
5674 N, Comp);
5675 end if;
5676
5677 Next_Component_Or_Discriminant (Comp);
5678 end loop;
5679 end if;
5680 end;
5681 end if;
5682 end Analyze_Record_Representation_Clause;
5683
5684 -------------------------------------------
5685 -- Build_Invariant_Procedure_Declaration --
5686 -------------------------------------------
5687
5688 function Build_Invariant_Procedure_Declaration
5689 (Typ : Entity_Id) return Node_Id
5690 is
5691 Loc : constant Source_Ptr := Sloc (Typ);
5692 Object_Entity : constant Entity_Id :=
5693 Make_Defining_Identifier (Loc, New_Internal_Name ('I'));
5694 Spec : Node_Id;
5695 SId : Entity_Id;
5696
5697 begin
5698 Set_Etype (Object_Entity, Typ);
5699
5700 -- Check for duplicate definiations.
5701
5702 if Has_Invariants (Typ) and then Present (Invariant_Procedure (Typ)) then
5703 return Empty;
5704 end if;
5705
5706 SId :=
5707 Make_Defining_Identifier (Loc,
5708 Chars => New_External_Name (Chars (Typ), "Invariant"));
5709 Set_Has_Invariants (Typ);
5710 Set_Ekind (SId, E_Procedure);
5711 Set_Is_Invariant_Procedure (SId);
5712 Set_Invariant_Procedure (Typ, SId);
5713
5714 Spec :=
5715 Make_Procedure_Specification (Loc,
5716 Defining_Unit_Name => SId,
5717 Parameter_Specifications => New_List (
5718 Make_Parameter_Specification (Loc,
5719 Defining_Identifier => Object_Entity,
5720 Parameter_Type => New_Occurrence_Of (Typ, Loc))));
5721
5722 return Make_Subprogram_Declaration (Loc, Specification => Spec);
5723 end Build_Invariant_Procedure_Declaration;
5724
5725 -------------------------------
5726 -- Build_Invariant_Procedure --
5727 -------------------------------
5728
5729 -- The procedure that is constructed here has the form
5730
5731 -- procedure typInvariant (Ixxx : typ) is
5732 -- begin
5733 -- pragma Check (Invariant, exp, "failed invariant from xxx");
5734 -- pragma Check (Invariant, exp, "failed invariant from xxx");
5735 -- ...
5736 -- pragma Check (Invariant, exp, "failed inherited invariant from xxx");
5737 -- ...
5738 -- end typInvariant;
5739
5740 procedure Build_Invariant_Procedure (Typ : Entity_Id; N : Node_Id) is
5741 Loc : constant Source_Ptr := Sloc (Typ);
5742 Stmts : List_Id;
5743 Spec : Node_Id;
5744 SId : Entity_Id;
5745 PDecl : Node_Id;
5746 PBody : Node_Id;
5747
5748 Visible_Decls : constant List_Id := Visible_Declarations (N);
5749 Private_Decls : constant List_Id := Private_Declarations (N);
5750
5751 procedure Add_Invariants (T : Entity_Id; Inherit : Boolean);
5752 -- Appends statements to Stmts for any invariants in the rep item chain
5753 -- of the given type. If Inherit is False, then we only process entries
5754 -- on the chain for the type Typ. If Inherit is True, then we ignore any
5755 -- Invariant aspects, but we process all Invariant'Class aspects, adding
5756 -- "inherited" to the exception message and generating an informational
5757 -- message about the inheritance of an invariant.
5758
5759 Object_Name : Name_Id;
5760 -- Name for argument of invariant procedure
5761
5762 Object_Entity : Node_Id;
5763 -- The entity of the formal for the procedure
5764
5765 --------------------
5766 -- Add_Invariants --
5767 --------------------
5768
5769 procedure Add_Invariants (T : Entity_Id; Inherit : Boolean) is
5770 Ritem : Node_Id;
5771 Arg1 : Node_Id;
5772 Arg2 : Node_Id;
5773 Arg3 : Node_Id;
5774 Exp : Node_Id;
5775 Loc : Source_Ptr;
5776 Assoc : List_Id;
5777 Str : String_Id;
5778
5779 procedure Replace_Type_Reference (N : Node_Id);
5780 -- Replace a single occurrence N of the subtype name with a reference
5781 -- to the formal of the predicate function. N can be an identifier
5782 -- referencing the subtype, or a selected component, representing an
5783 -- appropriately qualified occurrence of the subtype name.
5784
5785 procedure Replace_Type_References is
5786 new Replace_Type_References_Generic (Replace_Type_Reference);
5787 -- Traverse an expression replacing all occurrences of the subtype
5788 -- name with appropriate references to the object that is the formal
5789 -- parameter of the predicate function. Note that we must ensure
5790 -- that the type and entity information is properly set in the
5791 -- replacement node, since we will do a Preanalyze call of this
5792 -- expression without proper visibility of the procedure argument.
5793
5794 ----------------------------
5795 -- Replace_Type_Reference --
5796 ----------------------------
5797
5798 -- Note: See comments in Add_Predicates.Replace_Type_Reference
5799 -- regarding handling of Sloc and Comes_From_Source.
5800
5801 procedure Replace_Type_Reference (N : Node_Id) is
5802 begin
5803 -- Invariant'Class, replace with T'Class (obj)
5804
5805 if Class_Present (Ritem) then
5806 Rewrite (N,
5807 Make_Type_Conversion (Sloc (N),
5808 Subtype_Mark =>
5809 Make_Attribute_Reference (Sloc (N),
5810 Prefix => New_Occurrence_Of (T, Sloc (N)),
5811 Attribute_Name => Name_Class),
5812 Expression => Make_Identifier (Sloc (N), Object_Name)));
5813
5814 Set_Entity (Expression (N), Object_Entity);
5815 Set_Etype (Expression (N), Typ);
5816
5817 -- Invariant, replace with obj
5818
5819 else
5820 Rewrite (N, Make_Identifier (Sloc (N), Object_Name));
5821 Set_Entity (N, Object_Entity);
5822 Set_Etype (N, Typ);
5823 end if;
5824
5825 Set_Comes_From_Source (N, True);
5826 end Replace_Type_Reference;
5827
5828 -- Start of processing for Add_Invariants
5829
5830 begin
5831 Ritem := First_Rep_Item (T);
5832 while Present (Ritem) loop
5833 if Nkind (Ritem) = N_Pragma
5834 and then Pragma_Name (Ritem) = Name_Invariant
5835 then
5836 Arg1 := First (Pragma_Argument_Associations (Ritem));
5837 Arg2 := Next (Arg1);
5838 Arg3 := Next (Arg2);
5839
5840 Arg1 := Get_Pragma_Arg (Arg1);
5841 Arg2 := Get_Pragma_Arg (Arg2);
5842
5843 -- For Inherit case, ignore Invariant, process only Class case
5844
5845 if Inherit then
5846 if not Class_Present (Ritem) then
5847 goto Continue;
5848 end if;
5849
5850 -- For Inherit false, process only item for right type
5851
5852 else
5853 if Entity (Arg1) /= Typ then
5854 goto Continue;
5855 end if;
5856 end if;
5857
5858 if No (Stmts) then
5859 Stmts := Empty_List;
5860 end if;
5861
5862 Exp := New_Copy_Tree (Arg2);
5863
5864 -- Preserve sloc of original pragma Invariant
5865
5866 Loc := Sloc (Ritem);
5867
5868 -- We need to replace any occurrences of the name of the type
5869 -- with references to the object, converted to type'Class in
5870 -- the case of Invariant'Class aspects.
5871
5872 Replace_Type_References (Exp, Chars (T));
5873
5874 -- If this invariant comes from an aspect, find the aspect
5875 -- specification, and replace the saved expression because
5876 -- we need the subtype references replaced for the calls to
5877 -- Preanalyze_Spec_Expressin in Check_Aspect_At_Freeze_Point
5878 -- and Check_Aspect_At_End_Of_Declarations.
5879
5880 if From_Aspect_Specification (Ritem) then
5881 declare
5882 Aitem : Node_Id;
5883
5884 begin
5885 -- Loop to find corresponding aspect, note that this
5886 -- must be present given the pragma is marked delayed.
5887
5888 Aitem := Next_Rep_Item (Ritem);
5889 while Present (Aitem) loop
5890 if Nkind (Aitem) = N_Aspect_Specification
5891 and then Aspect_Rep_Item (Aitem) = Ritem
5892 then
5893 Set_Entity
5894 (Identifier (Aitem), New_Copy_Tree (Exp));
5895 exit;
5896 end if;
5897
5898 Aitem := Next_Rep_Item (Aitem);
5899 end loop;
5900 end;
5901 end if;
5902
5903 -- Now we need to preanalyze the expression to properly capture
5904 -- the visibility in the visible part. The expression will not
5905 -- be analyzed for real until the body is analyzed, but that is
5906 -- at the end of the private part and has the wrong visibility.
5907
5908 Set_Parent (Exp, N);
5909 Preanalyze_Assert_Expression (Exp, Standard_Boolean);
5910
5911 -- Build first two arguments for Check pragma
5912
5913 Assoc := New_List (
5914 Make_Pragma_Argument_Association (Loc,
5915 Expression => Make_Identifier (Loc, Name_Invariant)),
5916 Make_Pragma_Argument_Association (Loc,
5917 Expression => Exp));
5918
5919 -- Add message if present in Invariant pragma
5920
5921 if Present (Arg3) then
5922 Str := Strval (Get_Pragma_Arg (Arg3));
5923
5924 -- If inherited case, and message starts "failed invariant",
5925 -- change it to be "failed inherited invariant".
5926
5927 if Inherit then
5928 String_To_Name_Buffer (Str);
5929
5930 if Name_Buffer (1 .. 16) = "failed invariant" then
5931 Insert_Str_In_Name_Buffer ("inherited ", 8);
5932 Str := String_From_Name_Buffer;
5933 end if;
5934 end if;
5935
5936 Append_To (Assoc,
5937 Make_Pragma_Argument_Association (Loc,
5938 Expression => Make_String_Literal (Loc, Str)));
5939 end if;
5940
5941 -- Add Check pragma to list of statements
5942
5943 Append_To (Stmts,
5944 Make_Pragma (Loc,
5945 Pragma_Identifier =>
5946 Make_Identifier (Loc, Name_Check),
5947 Pragma_Argument_Associations => Assoc));
5948
5949 -- If Inherited case and option enabled, output info msg. Note
5950 -- that we know this is a case of Invariant'Class.
5951
5952 if Inherit and Opt.List_Inherited_Aspects then
5953 Error_Msg_Sloc := Sloc (Ritem);
5954 Error_Msg_N
5955 ("?L?info: & inherits `Invariant''Class` aspect from #",
5956 Typ);
5957 end if;
5958 end if;
5959
5960 <<Continue>>
5961 Next_Rep_Item (Ritem);
5962 end loop;
5963 end Add_Invariants;
5964
5965 -- Start of processing for Build_Invariant_Procedure
5966
5967 begin
5968 Stmts := No_List;
5969 PDecl := Empty;
5970 PBody := Empty;
5971 SId := Empty;
5972
5973 -- If the aspect specification exists for some view of the type, the
5974 -- declaration for the procedure has been created.
5975
5976 if Has_Invariants (Typ) then
5977 SId := Invariant_Procedure (Typ);
5978 end if;
5979
5980 if Present (SId) then
5981 PDecl := Unit_Declaration_Node (SId);
5982
5983 else
5984 PDecl := Build_Invariant_Procedure_Declaration (Typ);
5985 end if;
5986
5987 -- Recover formal of procedure, for use in the calls to invariant
5988 -- functions (including inherited ones).
5989
5990 Object_Entity :=
5991 Defining_Identifier
5992 (First (Parameter_Specifications (Specification (PDecl))));
5993 Object_Name := Chars (Object_Entity);
5994
5995 -- Add invariants for the current type
5996
5997 Add_Invariants (Typ, Inherit => False);
5998
5999 -- Add invariants for parent types
6000
6001 declare
6002 Current_Typ : Entity_Id;
6003 Parent_Typ : Entity_Id;
6004
6005 begin
6006 Current_Typ := Typ;
6007 loop
6008 Parent_Typ := Etype (Current_Typ);
6009
6010 if Is_Private_Type (Parent_Typ)
6011 and then Present (Full_View (Base_Type (Parent_Typ)))
6012 then
6013 Parent_Typ := Full_View (Base_Type (Parent_Typ));
6014 end if;
6015
6016 exit when Parent_Typ = Current_Typ;
6017
6018 Current_Typ := Parent_Typ;
6019 Add_Invariants (Current_Typ, Inherit => True);
6020 end loop;
6021 end;
6022
6023 -- Build the procedure if we generated at least one Check pragma
6024
6025 if Stmts /= No_List then
6026 Spec := Copy_Separate_Tree (Specification (PDecl));
6027
6028 PBody :=
6029 Make_Subprogram_Body (Loc,
6030 Specification => Spec,
6031 Declarations => Empty_List,
6032 Handled_Statement_Sequence =>
6033 Make_Handled_Sequence_Of_Statements (Loc,
6034 Statements => Stmts));
6035
6036 -- Insert procedure declaration and spec at the appropriate points.
6037 -- If declaration is already analyzed, it was processed by the
6038 -- generated pragma.
6039
6040 if Present (Private_Decls) then
6041
6042 -- The spec goes at the end of visible declarations, but they have
6043 -- already been analyzed, so we need to explicitly do the analyze.
6044
6045 if not Analyzed (PDecl) then
6046 Append_To (Visible_Decls, PDecl);
6047 Analyze (PDecl);
6048 end if;
6049
6050 -- The body goes at the end of the private declarations, which we
6051 -- have not analyzed yet, so we do not need to perform an explicit
6052 -- analyze call. We skip this if there are no private declarations
6053 -- (this is an error that will be caught elsewhere);
6054
6055 Append_To (Private_Decls, PBody);
6056
6057 -- If the invariant appears on the full view of a type, the
6058 -- analysis of the private part is complete, and we must
6059 -- analyze the new body explicitly.
6060
6061 if In_Private_Part (Current_Scope) then
6062 Analyze (PBody);
6063 end if;
6064
6065 -- If there are no private declarations this may be an error that
6066 -- will be diagnosed elsewhere. However, if this is a non-private
6067 -- type that inherits invariants, it needs no completion and there
6068 -- may be no private part. In this case insert invariant procedure
6069 -- at end of current declarative list, and analyze at once, given
6070 -- that the type is about to be frozen.
6071
6072 elsif not Is_Private_Type (Typ) then
6073 Append_To (Visible_Decls, PDecl);
6074 Append_To (Visible_Decls, PBody);
6075 Analyze (PDecl);
6076 Analyze (PBody);
6077 end if;
6078 end if;
6079 end Build_Invariant_Procedure;
6080
6081 -------------------------------
6082 -- Build_Predicate_Functions --
6083 -------------------------------
6084
6085 -- The procedures that are constructed here have the form:
6086
6087 -- function typPredicate (Ixxx : typ) return Boolean is
6088 -- begin
6089 -- return
6090 -- exp1 and then exp2 and then ...
6091 -- and then typ1Predicate (typ1 (Ixxx))
6092 -- and then typ2Predicate (typ2 (Ixxx))
6093 -- and then ...;
6094 -- end typPredicate;
6095
6096 -- Here exp1, and exp2 are expressions from Predicate pragmas. Note that
6097 -- this is the point at which these expressions get analyzed, providing the
6098 -- required delay, and typ1, typ2, are entities from which predicates are
6099 -- inherited. Note that we do NOT generate Check pragmas, that's because we
6100 -- use this function even if checks are off, e.g. for membership tests.
6101
6102 -- If the expression has at least one Raise_Expression, then we also build
6103 -- the typPredicateM version of the function, in which any occurrence of a
6104 -- Raise_Expression is converted to "return False".
6105
6106 procedure Build_Predicate_Functions (Typ : Entity_Id; N : Node_Id) is
6107 Loc : constant Source_Ptr := Sloc (Typ);
6108
6109 Expr : Node_Id;
6110 -- This is the expression for the result of the function. It is
6111 -- is build by connecting the component predicates with AND THEN.
6112
6113 Expr_M : Node_Id;
6114 -- This is the corresponding return expression for the Predicate_M
6115 -- function. It differs in that raise expressions are marked for
6116 -- special expansion (see Process_REs).
6117
6118 Object_Name : constant Name_Id := New_Internal_Name ('I');
6119 -- Name for argument of Predicate procedure. Note that we use the same
6120 -- name for both predicate procedure. That way the reference within the
6121 -- predicate expression is the same in both functions.
6122
6123 Object_Entity : constant Entity_Id :=
6124 Make_Defining_Identifier (Loc, Chars => Object_Name);
6125 -- Entity for argument of Predicate procedure
6126
6127 Object_Entity_M : constant Entity_Id :=
6128 Make_Defining_Identifier (Loc, Chars => Object_Name);
6129 -- Entity for argument of Predicate_M procedure
6130
6131 Raise_Expression_Present : Boolean := False;
6132 -- Set True if Expr has at least one Raise_Expression
6133
6134 Static_Predic : Node_Id := Empty;
6135 -- Set to N_Pragma node for a static predicate if one is encountered
6136
6137 procedure Add_Call (T : Entity_Id);
6138 -- Includes a call to the predicate function for type T in Expr if T
6139 -- has predicates and Predicate_Function (T) is non-empty.
6140
6141 procedure Add_Predicates;
6142 -- Appends expressions for any Predicate pragmas in the rep item chain
6143 -- Typ to Expr. Note that we look only at items for this exact entity.
6144 -- Inheritance of predicates for the parent type is done by calling the
6145 -- Predicate_Function of the parent type, using Add_Call above.
6146
6147 function Test_RE (N : Node_Id) return Traverse_Result;
6148 -- Used in Test_REs, tests one node for being a raise expression, and if
6149 -- so sets Raise_Expression_Present True.
6150
6151 procedure Test_REs is new Traverse_Proc (Test_RE);
6152 -- Tests to see if Expr contains any raise expressions
6153
6154 function Process_RE (N : Node_Id) return Traverse_Result;
6155 -- Used in Process REs, tests if node N is a raise expression, and if
6156 -- so, marks it to be converted to return False.
6157
6158 procedure Process_REs is new Traverse_Proc (Process_RE);
6159 -- Marks any raise expressions in Expr_M to return False
6160
6161 --------------
6162 -- Add_Call --
6163 --------------
6164
6165 procedure Add_Call (T : Entity_Id) is
6166 Exp : Node_Id;
6167
6168 begin
6169 if Present (T) and then Present (Predicate_Function (T)) then
6170 Set_Has_Predicates (Typ);
6171
6172 -- Build the call to the predicate function of T
6173
6174 Exp :=
6175 Make_Predicate_Call
6176 (T, Convert_To (T, Make_Identifier (Loc, Object_Name)));
6177
6178 -- Add call to evolving expression, using AND THEN if needed
6179
6180 if No (Expr) then
6181 Expr := Exp;
6182 else
6183 Expr :=
6184 Make_And_Then (Loc,
6185 Left_Opnd => Relocate_Node (Expr),
6186 Right_Opnd => Exp);
6187 end if;
6188
6189 -- Output info message on inheritance if required. Note we do not
6190 -- give this information for generic actual types, since it is
6191 -- unwelcome noise in that case in instantiations. We also
6192 -- generally suppress the message in instantiations, and also
6193 -- if it involves internal names.
6194
6195 if Opt.List_Inherited_Aspects
6196 and then not Is_Generic_Actual_Type (Typ)
6197 and then Instantiation_Depth (Sloc (Typ)) = 0
6198 and then not Is_Internal_Name (Chars (T))
6199 and then not Is_Internal_Name (Chars (Typ))
6200 then
6201 Error_Msg_Sloc := Sloc (Predicate_Function (T));
6202 Error_Msg_Node_2 := T;
6203 Error_Msg_N ("info: & inherits predicate from & #?L?", Typ);
6204 end if;
6205 end if;
6206 end Add_Call;
6207
6208 --------------------
6209 -- Add_Predicates --
6210 --------------------
6211
6212 procedure Add_Predicates is
6213 Ritem : Node_Id;
6214 Arg1 : Node_Id;
6215 Arg2 : Node_Id;
6216
6217 procedure Replace_Type_Reference (N : Node_Id);
6218 -- Replace a single occurrence N of the subtype name with a reference
6219 -- to the formal of the predicate function. N can be an identifier
6220 -- referencing the subtype, or a selected component, representing an
6221 -- appropriately qualified occurrence of the subtype name.
6222
6223 procedure Replace_Type_References is
6224 new Replace_Type_References_Generic (Replace_Type_Reference);
6225 -- Traverse an expression changing every occurrence of an identifier
6226 -- whose name matches the name of the subtype with a reference to
6227 -- the formal parameter of the predicate function.
6228
6229 ----------------------------
6230 -- Replace_Type_Reference --
6231 ----------------------------
6232
6233 procedure Replace_Type_Reference (N : Node_Id) is
6234 begin
6235 Rewrite (N, Make_Identifier (Sloc (N), Object_Name));
6236 -- Use the Sloc of the usage name, not the defining name
6237
6238 Set_Etype (N, Typ);
6239 Set_Entity (N, Object_Entity);
6240
6241 -- We want to treat the node as if it comes from source, so that
6242 -- ASIS will not ignore it
6243
6244 Set_Comes_From_Source (N, True);
6245 end Replace_Type_Reference;
6246
6247 -- Start of processing for Add_Predicates
6248
6249 begin
6250 Ritem := First_Rep_Item (Typ);
6251 while Present (Ritem) loop
6252 if Nkind (Ritem) = N_Pragma
6253 and then Pragma_Name (Ritem) = Name_Predicate
6254 then
6255 -- Save the static predicate of the type for diagnostics and
6256 -- error reporting purposes.
6257
6258 if Present (Corresponding_Aspect (Ritem))
6259 and then Chars (Identifier (Corresponding_Aspect (Ritem))) =
6260 Name_Static_Predicate
6261 then
6262 Static_Predic := Ritem;
6263 end if;
6264
6265 -- Acquire arguments
6266
6267 Arg1 := First (Pragma_Argument_Associations (Ritem));
6268 Arg2 := Next (Arg1);
6269
6270 Arg1 := Get_Pragma_Arg (Arg1);
6271 Arg2 := Get_Pragma_Arg (Arg2);
6272
6273 -- See if this predicate pragma is for the current type or for
6274 -- its full view. A predicate on a private completion is placed
6275 -- on the partial view beause this is the visible entity that
6276 -- is frozen.
6277
6278 if Entity (Arg1) = Typ
6279 or else Full_View (Entity (Arg1)) = Typ
6280 then
6281 -- We have a match, this entry is for our subtype
6282
6283 -- We need to replace any occurrences of the name of the
6284 -- type with references to the object.
6285
6286 Replace_Type_References (Arg2, Chars (Typ));
6287
6288 -- If this predicate comes from an aspect, find the aspect
6289 -- specification, and replace the saved expression because
6290 -- we need the subtype references replaced for the calls to
6291 -- Preanalyze_Spec_Expressin in Check_Aspect_At_Freeze_Point
6292 -- and Check_Aspect_At_End_Of_Declarations.
6293
6294 if From_Aspect_Specification (Ritem) then
6295 declare
6296 Aitem : Node_Id;
6297
6298 begin
6299 -- Loop to find corresponding aspect, note that this
6300 -- must be present given the pragma is marked delayed.
6301
6302 Aitem := Next_Rep_Item (Ritem);
6303 loop
6304 if Nkind (Aitem) = N_Aspect_Specification
6305 and then Aspect_Rep_Item (Aitem) = Ritem
6306 then
6307 Set_Entity
6308 (Identifier (Aitem), New_Copy_Tree (Arg2));
6309 exit;
6310 end if;
6311
6312 Aitem := Next_Rep_Item (Aitem);
6313 end loop;
6314 end;
6315 end if;
6316
6317 -- Now we can add the expression
6318
6319 if No (Expr) then
6320 Expr := Relocate_Node (Arg2);
6321
6322 -- There already was a predicate, so add to it
6323
6324 else
6325 Expr :=
6326 Make_And_Then (Loc,
6327 Left_Opnd => Relocate_Node (Expr),
6328 Right_Opnd => Relocate_Node (Arg2));
6329 end if;
6330 end if;
6331 end if;
6332
6333 Next_Rep_Item (Ritem);
6334 end loop;
6335 end Add_Predicates;
6336
6337 ----------------
6338 -- Process_RE --
6339 ----------------
6340
6341 function Process_RE (N : Node_Id) return Traverse_Result is
6342 begin
6343 if Nkind (N) = N_Raise_Expression then
6344 Set_Convert_To_Return_False (N);
6345 return Skip;
6346 else
6347 return OK;
6348 end if;
6349 end Process_RE;
6350
6351 -------------
6352 -- Test_RE --
6353 -------------
6354
6355 function Test_RE (N : Node_Id) return Traverse_Result is
6356 begin
6357 if Nkind (N) = N_Raise_Expression then
6358 Raise_Expression_Present := True;
6359 return Abandon;
6360 else
6361 return OK;
6362 end if;
6363 end Test_RE;
6364
6365 -- Start of processing for Build_Predicate_Functions
6366
6367 begin
6368 -- Return if already built or if type does not have predicates
6369
6370 if not Has_Predicates (Typ)
6371 or else Present (Predicate_Function (Typ))
6372 then
6373 return;
6374 end if;
6375
6376 -- Prepare to construct predicate expression
6377
6378 Expr := Empty;
6379
6380 -- Add Predicates for the current type
6381
6382 Add_Predicates;
6383
6384 -- Add predicates for ancestor if present
6385
6386 declare
6387 Atyp : constant Entity_Id := Nearest_Ancestor (Typ);
6388 begin
6389 if Present (Atyp) then
6390 Add_Call (Atyp);
6391 end if;
6392 end;
6393
6394 -- Case where predicates are present
6395
6396 if Present (Expr) then
6397
6398 -- Test for raise expression present
6399
6400 Test_REs (Expr);
6401
6402 -- If raise expression is present, capture a copy of Expr for use
6403 -- in building the predicateM function version later on. For this
6404 -- copy we replace references to Object_Entity by Object_Entity_M.
6405
6406 if Raise_Expression_Present then
6407 declare
6408 Map : constant Elist_Id := New_Elmt_List;
6409 begin
6410 Append_Elmt (Object_Entity, Map);
6411 Append_Elmt (Object_Entity_M, Map);
6412 Expr_M := New_Copy_Tree (Expr, Map => Map);
6413 end;
6414 end if;
6415
6416 -- Build the main predicate function
6417
6418 declare
6419 SId : constant Entity_Id :=
6420 Make_Defining_Identifier (Loc,
6421 Chars => New_External_Name (Chars (Typ), "Predicate"));
6422 -- The entity for the the function spec
6423
6424 SIdB : constant Entity_Id :=
6425 Make_Defining_Identifier (Loc,
6426 Chars => New_External_Name (Chars (Typ), "Predicate"));
6427 -- The entity for the function body
6428
6429 Spec : Node_Id;
6430 FDecl : Node_Id;
6431 FBody : Node_Id;
6432
6433 begin
6434 -- Build function declaration
6435
6436 Set_Ekind (SId, E_Function);
6437 Set_Is_Predicate_Function (SId);
6438 Set_Predicate_Function (Typ, SId);
6439
6440 -- The predicate function is shared between views of a type
6441
6442 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
6443 Set_Predicate_Function (Full_View (Typ), SId);
6444 end if;
6445
6446 Spec :=
6447 Make_Function_Specification (Loc,
6448 Defining_Unit_Name => SId,
6449 Parameter_Specifications => New_List (
6450 Make_Parameter_Specification (Loc,
6451 Defining_Identifier => Object_Entity,
6452 Parameter_Type => New_Occurrence_Of (Typ, Loc))),
6453 Result_Definition =>
6454 New_Occurrence_Of (Standard_Boolean, Loc));
6455
6456 FDecl :=
6457 Make_Subprogram_Declaration (Loc,
6458 Specification => Spec);
6459
6460 -- Build function body
6461
6462 Spec :=
6463 Make_Function_Specification (Loc,
6464 Defining_Unit_Name => SIdB,
6465 Parameter_Specifications => New_List (
6466 Make_Parameter_Specification (Loc,
6467 Defining_Identifier =>
6468 Make_Defining_Identifier (Loc, Object_Name),
6469 Parameter_Type =>
6470 New_Occurrence_Of (Typ, Loc))),
6471 Result_Definition =>
6472 New_Occurrence_Of (Standard_Boolean, Loc));
6473
6474 FBody :=
6475 Make_Subprogram_Body (Loc,
6476 Specification => Spec,
6477 Declarations => Empty_List,
6478 Handled_Statement_Sequence =>
6479 Make_Handled_Sequence_Of_Statements (Loc,
6480 Statements => New_List (
6481 Make_Simple_Return_Statement (Loc,
6482 Expression => Expr))));
6483
6484 -- Insert declaration before freeze node and body after
6485
6486 Insert_Before_And_Analyze (N, FDecl);
6487 Insert_After_And_Analyze (N, FBody);
6488 end;
6489
6490 -- Test for raise expressions present and if so build M version
6491
6492 if Raise_Expression_Present then
6493 declare
6494 SId : constant Entity_Id :=
6495 Make_Defining_Identifier (Loc,
6496 Chars => New_External_Name (Chars (Typ), "PredicateM"));
6497 -- The entity for the the function spec
6498
6499 SIdB : constant Entity_Id :=
6500 Make_Defining_Identifier (Loc,
6501 Chars => New_External_Name (Chars (Typ), "PredicateM"));
6502 -- The entity for the function body
6503
6504 Spec : Node_Id;
6505 FDecl : Node_Id;
6506 FBody : Node_Id;
6507 BTemp : Entity_Id;
6508
6509 begin
6510 -- Mark any raise expressions for special expansion
6511
6512 Process_REs (Expr_M);
6513
6514 -- Build function declaration
6515
6516 Set_Ekind (SId, E_Function);
6517 Set_Is_Predicate_Function_M (SId);
6518 Set_Predicate_Function_M (Typ, SId);
6519
6520 -- The predicate function is shared between views of a type
6521
6522 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
6523 Set_Predicate_Function_M (Full_View (Typ), SId);
6524 end if;
6525
6526 Spec :=
6527 Make_Function_Specification (Loc,
6528 Defining_Unit_Name => SId,
6529 Parameter_Specifications => New_List (
6530 Make_Parameter_Specification (Loc,
6531 Defining_Identifier => Object_Entity_M,
6532 Parameter_Type => New_Occurrence_Of (Typ, Loc))),
6533 Result_Definition =>
6534 New_Occurrence_Of (Standard_Boolean, Loc));
6535
6536 FDecl :=
6537 Make_Subprogram_Declaration (Loc,
6538 Specification => Spec);
6539
6540 -- Build function body
6541
6542 Spec :=
6543 Make_Function_Specification (Loc,
6544 Defining_Unit_Name => SIdB,
6545 Parameter_Specifications => New_List (
6546 Make_Parameter_Specification (Loc,
6547 Defining_Identifier =>
6548 Make_Defining_Identifier (Loc, Object_Name),
6549 Parameter_Type =>
6550 New_Occurrence_Of (Typ, Loc))),
6551 Result_Definition =>
6552 New_Occurrence_Of (Standard_Boolean, Loc));
6553
6554 -- Build the body, we declare the boolean expression before
6555 -- doing the return, because we are not really confident of
6556 -- what happens if a return appears within a return!
6557
6558 BTemp :=
6559 Make_Defining_Identifier (Loc,
6560 Chars => New_Internal_Name ('B'));
6561
6562 FBody :=
6563 Make_Subprogram_Body (Loc,
6564 Specification => Spec,
6565
6566 Declarations => New_List (
6567 Make_Object_Declaration (Loc,
6568 Defining_Identifier => BTemp,
6569 Constant_Present => True,
6570 Object_Definition =>
6571 New_Reference_To (Standard_Boolean, Loc),
6572 Expression => Expr_M)),
6573
6574 Handled_Statement_Sequence =>
6575 Make_Handled_Sequence_Of_Statements (Loc,
6576 Statements => New_List (
6577 Make_Simple_Return_Statement (Loc,
6578 Expression => New_Reference_To (BTemp, Loc)))));
6579
6580 -- Insert declaration before freeze node and body after
6581
6582 Insert_Before_And_Analyze (N, FDecl);
6583 Insert_After_And_Analyze (N, FBody);
6584 end;
6585 end if;
6586
6587 if Is_Scalar_Type (Typ) then
6588
6589 -- Attempt to build a static predicate for a discrete or a real
6590 -- subtype. This action may fail because the actual expression may
6591 -- not be static. Note that the presence of an inherited or
6592 -- explicitly declared dynamic predicate is orthogonal to this
6593 -- check because we are only interested in the static predicate.
6594
6595 if Ekind_In (Typ, E_Decimal_Fixed_Point_Subtype,
6596 E_Enumeration_Subtype,
6597 E_Floating_Point_Subtype,
6598 E_Modular_Integer_Subtype,
6599 E_Ordinary_Fixed_Point_Subtype,
6600 E_Signed_Integer_Subtype)
6601 then
6602 Build_Static_Predicate (Typ, Expr, Object_Name);
6603
6604 -- Emit an error when the predicate is categorized as static
6605 -- but its expression is dynamic.
6606
6607 if Present (Static_Predic)
6608 and then No (Static_Predicate (Typ))
6609 then
6610 Error_Msg_F
6611 ("expression does not have required form for "
6612 & "static predicate",
6613 Next (First (Pragma_Argument_Associations
6614 (Static_Predic))));
6615 end if;
6616 end if;
6617
6618 -- If a static predicate applies on other types, that's an error:
6619 -- either the type is scalar but non-static, or it's not even a
6620 -- scalar type. We do not issue an error on generated types, as
6621 -- these may be duplicates of the same error on a source type.
6622
6623 elsif Present (Static_Predic) and then Comes_From_Source (Typ) then
6624 if Is_Scalar_Type (Typ) then
6625 Error_Msg_FE
6626 ("static predicate not allowed for non-static type&",
6627 Typ, Typ);
6628 else
6629 Error_Msg_FE
6630 ("static predicate not allowed for non-scalar type&",
6631 Typ, Typ);
6632 end if;
6633 end if;
6634 end if;
6635 end Build_Predicate_Functions;
6636
6637 ----------------------------
6638 -- Build_Static_Predicate --
6639 ----------------------------
6640
6641 procedure Build_Static_Predicate
6642 (Typ : Entity_Id;
6643 Expr : Node_Id;
6644 Nam : Name_Id)
6645 is
6646 Loc : constant Source_Ptr := Sloc (Expr);
6647
6648 Non_Static : exception;
6649 -- Raised if something non-static is found
6650
6651 Btyp : constant Entity_Id := Base_Type (Typ);
6652
6653 BLo : constant Uint := Expr_Value (Type_Low_Bound (Btyp));
6654 BHi : constant Uint := Expr_Value (Type_High_Bound (Btyp));
6655 -- Low bound and high bound value of base type of Typ
6656
6657 TLo : constant Uint := Expr_Value (Type_Low_Bound (Typ));
6658 THi : constant Uint := Expr_Value (Type_High_Bound (Typ));
6659 -- Low bound and high bound values of static subtype Typ
6660
6661 type REnt is record
6662 Lo, Hi : Uint;
6663 end record;
6664 -- One entry in a Rlist value, a single REnt (range entry) value denotes
6665 -- one range from Lo to Hi. To represent a single value range Lo = Hi =
6666 -- value.
6667
6668 type RList is array (Nat range <>) of REnt;
6669 -- A list of ranges. The ranges are sorted in increasing order, and are
6670 -- disjoint (there is a gap of at least one value between each range in
6671 -- the table). A value is in the set of ranges in Rlist if it lies
6672 -- within one of these ranges.
6673
6674 False_Range : constant RList :=
6675 RList'(1 .. 0 => REnt'(No_Uint, No_Uint));
6676 -- An empty set of ranges represents a range list that can never be
6677 -- satisfied, since there are no ranges in which the value could lie,
6678 -- so it does not lie in any of them. False_Range is a canonical value
6679 -- for this empty set, but general processing should test for an Rlist
6680 -- with length zero (see Is_False predicate), since other null ranges
6681 -- may appear which must be treated as False.
6682
6683 True_Range : constant RList := RList'(1 => REnt'(BLo, BHi));
6684 -- Range representing True, value must be in the base range
6685
6686 function "and" (Left : RList; Right : RList) return RList;
6687 -- And's together two range lists, returning a range list. This is a set
6688 -- intersection operation.
6689
6690 function "or" (Left : RList; Right : RList) return RList;
6691 -- Or's together two range lists, returning a range list. This is a set
6692 -- union operation.
6693
6694 function "not" (Right : RList) return RList;
6695 -- Returns complement of a given range list, i.e. a range list
6696 -- representing all the values in TLo .. THi that are not in the input
6697 -- operand Right.
6698
6699 function Build_Val (V : Uint) return Node_Id;
6700 -- Return an analyzed N_Identifier node referencing this value, suitable
6701 -- for use as an entry in the Static_Predicate list. This node is typed
6702 -- with the base type.
6703
6704 function Build_Range (Lo : Uint; Hi : Uint) return Node_Id;
6705 -- Return an analyzed N_Range node referencing this range, suitable for
6706 -- use as an entry in the Static_Predicate list. This node is typed with
6707 -- the base type.
6708
6709 function Get_RList (Exp : Node_Id) return RList;
6710 -- This is a recursive routine that converts the given expression into a
6711 -- list of ranges, suitable for use in building the static predicate.
6712
6713 function Is_False (R : RList) return Boolean;
6714 pragma Inline (Is_False);
6715 -- Returns True if the given range list is empty, and thus represents a
6716 -- False list of ranges that can never be satisfied.
6717
6718 function Is_True (R : RList) return Boolean;
6719 -- Returns True if R trivially represents the True predicate by having a
6720 -- single range from BLo to BHi.
6721
6722 function Is_Type_Ref (N : Node_Id) return Boolean;
6723 pragma Inline (Is_Type_Ref);
6724 -- Returns if True if N is a reference to the type for the predicate in
6725 -- the expression (i.e. if it is an identifier whose Chars field matches
6726 -- the Nam given in the call).
6727
6728 function Lo_Val (N : Node_Id) return Uint;
6729 -- Given static expression or static range from a Static_Predicate list,
6730 -- gets expression value or low bound of range.
6731
6732 function Hi_Val (N : Node_Id) return Uint;
6733 -- Given static expression or static range from a Static_Predicate list,
6734 -- gets expression value of high bound of range.
6735
6736 function Membership_Entry (N : Node_Id) return RList;
6737 -- Given a single membership entry (range, value, or subtype), returns
6738 -- the corresponding range list. Raises Static_Error if not static.
6739
6740 function Membership_Entries (N : Node_Id) return RList;
6741 -- Given an element on an alternatives list of a membership operation,
6742 -- returns the range list corresponding to this entry and all following
6743 -- entries (i.e. returns the "or" of this list of values).
6744
6745 function Stat_Pred (Typ : Entity_Id) return RList;
6746 -- Given a type, if it has a static predicate, then return the predicate
6747 -- as a range list, otherwise raise Non_Static.
6748
6749 -----------
6750 -- "and" --
6751 -----------
6752
6753 function "and" (Left : RList; Right : RList) return RList is
6754 FEnt : REnt;
6755 -- First range of result
6756
6757 SLeft : Nat := Left'First;
6758 -- Start of rest of left entries
6759
6760 SRight : Nat := Right'First;
6761 -- Start of rest of right entries
6762
6763 begin
6764 -- If either range is True, return the other
6765
6766 if Is_True (Left) then
6767 return Right;
6768 elsif Is_True (Right) then
6769 return Left;
6770 end if;
6771
6772 -- If either range is False, return False
6773
6774 if Is_False (Left) or else Is_False (Right) then
6775 return False_Range;
6776 end if;
6777
6778 -- Loop to remove entries at start that are disjoint, and thus just
6779 -- get discarded from the result entirely.
6780
6781 loop
6782 -- If no operands left in either operand, result is false
6783
6784 if SLeft > Left'Last or else SRight > Right'Last then
6785 return False_Range;
6786
6787 -- Discard first left operand entry if disjoint with right
6788
6789 elsif Left (SLeft).Hi < Right (SRight).Lo then
6790 SLeft := SLeft + 1;
6791
6792 -- Discard first right operand entry if disjoint with left
6793
6794 elsif Right (SRight).Hi < Left (SLeft).Lo then
6795 SRight := SRight + 1;
6796
6797 -- Otherwise we have an overlapping entry
6798
6799 else
6800 exit;
6801 end if;
6802 end loop;
6803
6804 -- Now we have two non-null operands, and first entries overlap. The
6805 -- first entry in the result will be the overlapping part of these
6806 -- two entries.
6807
6808 FEnt := REnt'(Lo => UI_Max (Left (SLeft).Lo, Right (SRight).Lo),
6809 Hi => UI_Min (Left (SLeft).Hi, Right (SRight).Hi));
6810
6811 -- Now we can remove the entry that ended at a lower value, since its
6812 -- contribution is entirely contained in Fent.
6813
6814 if Left (SLeft).Hi <= Right (SRight).Hi then
6815 SLeft := SLeft + 1;
6816 else
6817 SRight := SRight + 1;
6818 end if;
6819
6820 -- Compute result by concatenating this first entry with the "and" of
6821 -- the remaining parts of the left and right operands. Note that if
6822 -- either of these is empty, "and" will yield empty, so that we will
6823 -- end up with just Fent, which is what we want in that case.
6824
6825 return
6826 FEnt & (Left (SLeft .. Left'Last) and Right (SRight .. Right'Last));
6827 end "and";
6828
6829 -----------
6830 -- "not" --
6831 -----------
6832
6833 function "not" (Right : RList) return RList is
6834 begin
6835 -- Return True if False range
6836
6837 if Is_False (Right) then
6838 return True_Range;
6839 end if;
6840
6841 -- Return False if True range
6842
6843 if Is_True (Right) then
6844 return False_Range;
6845 end if;
6846
6847 -- Here if not trivial case
6848
6849 declare
6850 Result : RList (1 .. Right'Length + 1);
6851 -- May need one more entry for gap at beginning and end
6852
6853 Count : Nat := 0;
6854 -- Number of entries stored in Result
6855
6856 begin
6857 -- Gap at start
6858
6859 if Right (Right'First).Lo > TLo then
6860 Count := Count + 1;
6861 Result (Count) := REnt'(TLo, Right (Right'First).Lo - 1);
6862 end if;
6863
6864 -- Gaps between ranges
6865
6866 for J in Right'First .. Right'Last - 1 loop
6867 Count := Count + 1;
6868 Result (Count) :=
6869 REnt'(Right (J).Hi + 1, Right (J + 1).Lo - 1);
6870 end loop;
6871
6872 -- Gap at end
6873
6874 if Right (Right'Last).Hi < THi then
6875 Count := Count + 1;
6876 Result (Count) := REnt'(Right (Right'Last).Hi + 1, THi);
6877 end if;
6878
6879 return Result (1 .. Count);
6880 end;
6881 end "not";
6882
6883 ----------
6884 -- "or" --
6885 ----------
6886
6887 function "or" (Left : RList; Right : RList) return RList is
6888 FEnt : REnt;
6889 -- First range of result
6890
6891 SLeft : Nat := Left'First;
6892 -- Start of rest of left entries
6893
6894 SRight : Nat := Right'First;
6895 -- Start of rest of right entries
6896
6897 begin
6898 -- If either range is True, return True
6899
6900 if Is_True (Left) or else Is_True (Right) then
6901 return True_Range;
6902 end if;
6903
6904 -- If either range is False (empty), return the other
6905
6906 if Is_False (Left) then
6907 return Right;
6908 elsif Is_False (Right) then
6909 return Left;
6910 end if;
6911
6912 -- Initialize result first entry from left or right operand depending
6913 -- on which starts with the lower range.
6914
6915 if Left (SLeft).Lo < Right (SRight).Lo then
6916 FEnt := Left (SLeft);
6917 SLeft := SLeft + 1;
6918 else
6919 FEnt := Right (SRight);
6920 SRight := SRight + 1;
6921 end if;
6922
6923 -- This loop eats ranges from left and right operands that are
6924 -- contiguous with the first range we are gathering.
6925
6926 loop
6927 -- Eat first entry in left operand if contiguous or overlapped by
6928 -- gathered first operand of result.
6929
6930 if SLeft <= Left'Last
6931 and then Left (SLeft).Lo <= FEnt.Hi + 1
6932 then
6933 FEnt.Hi := UI_Max (FEnt.Hi, Left (SLeft).Hi);
6934 SLeft := SLeft + 1;
6935
6936 -- Eat first entry in right operand if contiguous or overlapped by
6937 -- gathered right operand of result.
6938
6939 elsif SRight <= Right'Last
6940 and then Right (SRight).Lo <= FEnt.Hi + 1
6941 then
6942 FEnt.Hi := UI_Max (FEnt.Hi, Right (SRight).Hi);
6943 SRight := SRight + 1;
6944
6945 -- All done if no more entries to eat
6946
6947 else
6948 exit;
6949 end if;
6950 end loop;
6951
6952 -- Obtain result as the first entry we just computed, concatenated
6953 -- to the "or" of the remaining results (if one operand is empty,
6954 -- this will just concatenate with the other
6955
6956 return
6957 FEnt & (Left (SLeft .. Left'Last) or Right (SRight .. Right'Last));
6958 end "or";
6959
6960 -----------------
6961 -- Build_Range --
6962 -----------------
6963
6964 function Build_Range (Lo : Uint; Hi : Uint) return Node_Id is
6965 Result : Node_Id;
6966
6967 begin
6968 Result :=
6969 Make_Range (Loc,
6970 Low_Bound => Build_Val (Lo),
6971 High_Bound => Build_Val (Hi));
6972 Set_Etype (Result, Btyp);
6973 Set_Analyzed (Result);
6974
6975 return Result;
6976 end Build_Range;
6977
6978 ---------------
6979 -- Build_Val --
6980 ---------------
6981
6982 function Build_Val (V : Uint) return Node_Id is
6983 Result : Node_Id;
6984
6985 begin
6986 if Is_Enumeration_Type (Typ) then
6987 Result := Get_Enum_Lit_From_Pos (Typ, V, Loc);
6988 else
6989 Result := Make_Integer_Literal (Loc, V);
6990 end if;
6991
6992 Set_Etype (Result, Btyp);
6993 Set_Is_Static_Expression (Result);
6994 Set_Analyzed (Result);
6995 return Result;
6996 end Build_Val;
6997
6998 ---------------
6999 -- Get_RList --
7000 ---------------
7001
7002 function Get_RList (Exp : Node_Id) return RList is
7003 Op : Node_Kind;
7004 Val : Uint;
7005
7006 begin
7007 -- Static expression can only be true or false
7008
7009 if Is_OK_Static_Expression (Exp) then
7010
7011 -- For False
7012
7013 if Expr_Value (Exp) = 0 then
7014 return False_Range;
7015 else
7016 return True_Range;
7017 end if;
7018 end if;
7019
7020 -- Otherwise test node type
7021
7022 Op := Nkind (Exp);
7023
7024 case Op is
7025
7026 -- And
7027
7028 when N_Op_And | N_And_Then =>
7029 return Get_RList (Left_Opnd (Exp))
7030 and
7031 Get_RList (Right_Opnd (Exp));
7032
7033 -- Or
7034
7035 when N_Op_Or | N_Or_Else =>
7036 return Get_RList (Left_Opnd (Exp))
7037 or
7038 Get_RList (Right_Opnd (Exp));
7039
7040 -- Not
7041
7042 when N_Op_Not =>
7043 return not Get_RList (Right_Opnd (Exp));
7044
7045 -- Comparisons of type with static value
7046
7047 when N_Op_Compare =>
7048
7049 -- Type is left operand
7050
7051 if Is_Type_Ref (Left_Opnd (Exp))
7052 and then Is_OK_Static_Expression (Right_Opnd (Exp))
7053 then
7054 Val := Expr_Value (Right_Opnd (Exp));
7055
7056 -- Typ is right operand
7057
7058 elsif Is_Type_Ref (Right_Opnd (Exp))
7059 and then Is_OK_Static_Expression (Left_Opnd (Exp))
7060 then
7061 Val := Expr_Value (Left_Opnd (Exp));
7062
7063 -- Invert sense of comparison
7064
7065 case Op is
7066 when N_Op_Gt => Op := N_Op_Lt;
7067 when N_Op_Lt => Op := N_Op_Gt;
7068 when N_Op_Ge => Op := N_Op_Le;
7069 when N_Op_Le => Op := N_Op_Ge;
7070 when others => null;
7071 end case;
7072
7073 -- Other cases are non-static
7074
7075 else
7076 raise Non_Static;
7077 end if;
7078
7079 -- Construct range according to comparison operation
7080
7081 case Op is
7082 when N_Op_Eq =>
7083 return RList'(1 => REnt'(Val, Val));
7084
7085 when N_Op_Ge =>
7086 return RList'(1 => REnt'(Val, BHi));
7087
7088 when N_Op_Gt =>
7089 return RList'(1 => REnt'(Val + 1, BHi));
7090
7091 when N_Op_Le =>
7092 return RList'(1 => REnt'(BLo, Val));
7093
7094 when N_Op_Lt =>
7095 return RList'(1 => REnt'(BLo, Val - 1));
7096
7097 when N_Op_Ne =>
7098 return RList'(REnt'(BLo, Val - 1),
7099 REnt'(Val + 1, BHi));
7100
7101 when others =>
7102 raise Program_Error;
7103 end case;
7104
7105 -- Membership (IN)
7106
7107 when N_In =>
7108 if not Is_Type_Ref (Left_Opnd (Exp)) then
7109 raise Non_Static;
7110 end if;
7111
7112 if Present (Right_Opnd (Exp)) then
7113 return Membership_Entry (Right_Opnd (Exp));
7114 else
7115 return Membership_Entries (First (Alternatives (Exp)));
7116 end if;
7117
7118 -- Negative membership (NOT IN)
7119
7120 when N_Not_In =>
7121 if not Is_Type_Ref (Left_Opnd (Exp)) then
7122 raise Non_Static;
7123 end if;
7124
7125 if Present (Right_Opnd (Exp)) then
7126 return not Membership_Entry (Right_Opnd (Exp));
7127 else
7128 return not Membership_Entries (First (Alternatives (Exp)));
7129 end if;
7130
7131 -- Function call, may be call to static predicate
7132
7133 when N_Function_Call =>
7134 if Is_Entity_Name (Name (Exp)) then
7135 declare
7136 Ent : constant Entity_Id := Entity (Name (Exp));
7137 begin
7138 if Is_Predicate_Function (Ent)
7139 or else
7140 Is_Predicate_Function_M (Ent)
7141 then
7142 return Stat_Pred (Etype (First_Formal (Ent)));
7143 end if;
7144 end;
7145 end if;
7146
7147 -- Other function call cases are non-static
7148
7149 raise Non_Static;
7150
7151 -- Qualified expression, dig out the expression
7152
7153 when N_Qualified_Expression =>
7154 return Get_RList (Expression (Exp));
7155
7156 -- Xor operator
7157
7158 when N_Op_Xor =>
7159 return (Get_RList (Left_Opnd (Exp))
7160 and not Get_RList (Right_Opnd (Exp)))
7161 or (Get_RList (Right_Opnd (Exp))
7162 and not Get_RList (Left_Opnd (Exp)));
7163
7164 -- Any other node type is non-static
7165
7166 when others =>
7167 raise Non_Static;
7168 end case;
7169 end Get_RList;
7170
7171 ------------
7172 -- Hi_Val --
7173 ------------
7174
7175 function Hi_Val (N : Node_Id) return Uint is
7176 begin
7177 if Is_Static_Expression (N) then
7178 return Expr_Value (N);
7179 else
7180 pragma Assert (Nkind (N) = N_Range);
7181 return Expr_Value (High_Bound (N));
7182 end if;
7183 end Hi_Val;
7184
7185 --------------
7186 -- Is_False --
7187 --------------
7188
7189 function Is_False (R : RList) return Boolean is
7190 begin
7191 return R'Length = 0;
7192 end Is_False;
7193
7194 -------------
7195 -- Is_True --
7196 -------------
7197
7198 function Is_True (R : RList) return Boolean is
7199 begin
7200 return R'Length = 1
7201 and then R (R'First).Lo = BLo
7202 and then R (R'First).Hi = BHi;
7203 end Is_True;
7204
7205 -----------------
7206 -- Is_Type_Ref --
7207 -----------------
7208
7209 function Is_Type_Ref (N : Node_Id) return Boolean is
7210 begin
7211 return Nkind (N) = N_Identifier and then Chars (N) = Nam;
7212 end Is_Type_Ref;
7213
7214 ------------
7215 -- Lo_Val --
7216 ------------
7217
7218 function Lo_Val (N : Node_Id) return Uint is
7219 begin
7220 if Is_Static_Expression (N) then
7221 return Expr_Value (N);
7222 else
7223 pragma Assert (Nkind (N) = N_Range);
7224 return Expr_Value (Low_Bound (N));
7225 end if;
7226 end Lo_Val;
7227
7228 ------------------------
7229 -- Membership_Entries --
7230 ------------------------
7231
7232 function Membership_Entries (N : Node_Id) return RList is
7233 begin
7234 if No (Next (N)) then
7235 return Membership_Entry (N);
7236 else
7237 return Membership_Entry (N) or Membership_Entries (Next (N));
7238 end if;
7239 end Membership_Entries;
7240
7241 ----------------------
7242 -- Membership_Entry --
7243 ----------------------
7244
7245 function Membership_Entry (N : Node_Id) return RList is
7246 Val : Uint;
7247 SLo : Uint;
7248 SHi : Uint;
7249
7250 begin
7251 -- Range case
7252
7253 if Nkind (N) = N_Range then
7254 if not Is_Static_Expression (Low_Bound (N))
7255 or else
7256 not Is_Static_Expression (High_Bound (N))
7257 then
7258 raise Non_Static;
7259 else
7260 SLo := Expr_Value (Low_Bound (N));
7261 SHi := Expr_Value (High_Bound (N));
7262 return RList'(1 => REnt'(SLo, SHi));
7263 end if;
7264
7265 -- Static expression case
7266
7267 elsif Is_Static_Expression (N) then
7268 Val := Expr_Value (N);
7269 return RList'(1 => REnt'(Val, Val));
7270
7271 -- Identifier (other than static expression) case
7272
7273 else pragma Assert (Nkind (N) = N_Identifier);
7274
7275 -- Type case
7276
7277 if Is_Type (Entity (N)) then
7278
7279 -- If type has predicates, process them
7280
7281 if Has_Predicates (Entity (N)) then
7282 return Stat_Pred (Entity (N));
7283
7284 -- For static subtype without predicates, get range
7285
7286 elsif Is_Static_Subtype (Entity (N)) then
7287 SLo := Expr_Value (Type_Low_Bound (Entity (N)));
7288 SHi := Expr_Value (Type_High_Bound (Entity (N)));
7289 return RList'(1 => REnt'(SLo, SHi));
7290
7291 -- Any other type makes us non-static
7292
7293 else
7294 raise Non_Static;
7295 end if;
7296
7297 -- Any other kind of identifier in predicate (e.g. a non-static
7298 -- expression value) means this is not a static predicate.
7299
7300 else
7301 raise Non_Static;
7302 end if;
7303 end if;
7304 end Membership_Entry;
7305
7306 ---------------
7307 -- Stat_Pred --
7308 ---------------
7309
7310 function Stat_Pred (Typ : Entity_Id) return RList is
7311 begin
7312 -- Not static if type does not have static predicates
7313
7314 if not Has_Predicates (Typ) or else No (Static_Predicate (Typ)) then
7315 raise Non_Static;
7316 end if;
7317
7318 -- Otherwise we convert the predicate list to a range list
7319
7320 declare
7321 Result : RList (1 .. List_Length (Static_Predicate (Typ)));
7322 P : Node_Id;
7323
7324 begin
7325 P := First (Static_Predicate (Typ));
7326 for J in Result'Range loop
7327 Result (J) := REnt'(Lo_Val (P), Hi_Val (P));
7328 Next (P);
7329 end loop;
7330
7331 return Result;
7332 end;
7333 end Stat_Pred;
7334
7335 -- Start of processing for Build_Static_Predicate
7336
7337 begin
7338 -- Now analyze the expression to see if it is a static predicate
7339
7340 declare
7341 Ranges : constant RList := Get_RList (Expr);
7342 -- Range list from expression if it is static
7343
7344 Plist : List_Id;
7345
7346 begin
7347 -- Convert range list into a form for the static predicate. In the
7348 -- Ranges array, we just have raw ranges, these must be converted
7349 -- to properly typed and analyzed static expressions or range nodes.
7350
7351 -- Note: here we limit ranges to the ranges of the subtype, so that
7352 -- a predicate is always false for values outside the subtype. That
7353 -- seems fine, such values are invalid anyway, and considering them
7354 -- to fail the predicate seems allowed and friendly, and furthermore
7355 -- simplifies processing for case statements and loops.
7356
7357 Plist := New_List;
7358
7359 for J in Ranges'Range loop
7360 declare
7361 Lo : Uint := Ranges (J).Lo;
7362 Hi : Uint := Ranges (J).Hi;
7363
7364 begin
7365 -- Ignore completely out of range entry
7366
7367 if Hi < TLo or else Lo > THi then
7368 null;
7369
7370 -- Otherwise process entry
7371
7372 else
7373 -- Adjust out of range value to subtype range
7374
7375 if Lo < TLo then
7376 Lo := TLo;
7377 end if;
7378
7379 if Hi > THi then
7380 Hi := THi;
7381 end if;
7382
7383 -- Convert range into required form
7384
7385 Append_To (Plist, Build_Range (Lo, Hi));
7386 end if;
7387 end;
7388 end loop;
7389
7390 -- Processing was successful and all entries were static, so now we
7391 -- can store the result as the predicate list.
7392
7393 Set_Static_Predicate (Typ, Plist);
7394
7395 -- The processing for static predicates put the expression into
7396 -- canonical form as a series of ranges. It also eliminated
7397 -- duplicates and collapsed and combined ranges. We might as well
7398 -- replace the alternatives list of the right operand of the
7399 -- membership test with the static predicate list, which will
7400 -- usually be more efficient.
7401
7402 declare
7403 New_Alts : constant List_Id := New_List;
7404 Old_Node : Node_Id;
7405 New_Node : Node_Id;
7406
7407 begin
7408 Old_Node := First (Plist);
7409 while Present (Old_Node) loop
7410 New_Node := New_Copy (Old_Node);
7411
7412 if Nkind (New_Node) = N_Range then
7413 Set_Low_Bound (New_Node, New_Copy (Low_Bound (Old_Node)));
7414 Set_High_Bound (New_Node, New_Copy (High_Bound (Old_Node)));
7415 end if;
7416
7417 Append_To (New_Alts, New_Node);
7418 Next (Old_Node);
7419 end loop;
7420
7421 -- If empty list, replace by False
7422
7423 if Is_Empty_List (New_Alts) then
7424 Rewrite (Expr, New_Occurrence_Of (Standard_False, Loc));
7425
7426 -- Else replace by set membership test
7427
7428 else
7429 Rewrite (Expr,
7430 Make_In (Loc,
7431 Left_Opnd => Make_Identifier (Loc, Nam),
7432 Right_Opnd => Empty,
7433 Alternatives => New_Alts));
7434
7435 -- Resolve new expression in function context
7436
7437 Install_Formals (Predicate_Function (Typ));
7438 Push_Scope (Predicate_Function (Typ));
7439 Analyze_And_Resolve (Expr, Standard_Boolean);
7440 Pop_Scope;
7441 end if;
7442 end;
7443 end;
7444
7445 -- If non-static, return doing nothing
7446
7447 exception
7448 when Non_Static =>
7449 return;
7450 end Build_Static_Predicate;
7451
7452 -----------------------------------------
7453 -- Check_Aspect_At_End_Of_Declarations --
7454 -----------------------------------------
7455
7456 procedure Check_Aspect_At_End_Of_Declarations (ASN : Node_Id) is
7457 Ent : constant Entity_Id := Entity (ASN);
7458 Ident : constant Node_Id := Identifier (ASN);
7459 A_Id : constant Aspect_Id := Get_Aspect_Id (Chars (Ident));
7460
7461 End_Decl_Expr : constant Node_Id := Entity (Ident);
7462 -- Expression to be analyzed at end of declarations
7463
7464 Freeze_Expr : constant Node_Id := Expression (ASN);
7465 -- Expression from call to Check_Aspect_At_Freeze_Point
7466
7467 T : constant Entity_Id := Etype (Freeze_Expr);
7468 -- Type required for preanalyze call
7469
7470 Err : Boolean;
7471 -- Set False if error
7472
7473 -- On entry to this procedure, Entity (Ident) contains a copy of the
7474 -- original expression from the aspect, saved for this purpose, and
7475 -- but Expression (Ident) is a preanalyzed copy of the expression,
7476 -- preanalyzed just after the freeze point.
7477
7478 procedure Check_Overloaded_Name;
7479 -- For aspects whose expression is simply a name, this routine checks if
7480 -- the name is overloaded or not. If so, it verifies there is an
7481 -- interpretation that matches the entity obtained at the freeze point,
7482 -- otherwise the compiler complains.
7483
7484 ---------------------------
7485 -- Check_Overloaded_Name --
7486 ---------------------------
7487
7488 procedure Check_Overloaded_Name is
7489 begin
7490 if not Is_Overloaded (End_Decl_Expr) then
7491 Err := Entity (End_Decl_Expr) /= Entity (Freeze_Expr);
7492
7493 else
7494 Err := True;
7495
7496 declare
7497 Index : Interp_Index;
7498 It : Interp;
7499
7500 begin
7501 Get_First_Interp (End_Decl_Expr, Index, It);
7502 while Present (It.Typ) loop
7503 if It.Nam = Entity (Freeze_Expr) then
7504 Err := False;
7505 exit;
7506 end if;
7507
7508 Get_Next_Interp (Index, It);
7509 end loop;
7510 end;
7511 end if;
7512 end Check_Overloaded_Name;
7513
7514 -- Start of processing for Check_Aspect_At_End_Of_Declarations
7515
7516 begin
7517 -- Case of aspects Dimension, Dimension_System and Synchronization
7518
7519 if A_Id = Aspect_Synchronization then
7520 return;
7521
7522 -- Case of stream attributes, just have to compare entities. However,
7523 -- the expression is just a name (possibly overloaded), and there may
7524 -- be stream operations declared for unrelated types, so we just need
7525 -- to verify that one of these interpretations is the one available at
7526 -- at the freeze point.
7527
7528 elsif A_Id = Aspect_Input or else
7529 A_Id = Aspect_Output or else
7530 A_Id = Aspect_Read or else
7531 A_Id = Aspect_Write
7532 then
7533 Analyze (End_Decl_Expr);
7534 Check_Overloaded_Name;
7535
7536 elsif A_Id = Aspect_Variable_Indexing or else
7537 A_Id = Aspect_Constant_Indexing or else
7538 A_Id = Aspect_Default_Iterator or else
7539 A_Id = Aspect_Iterator_Element
7540 then
7541 -- Make type unfrozen before analysis, to prevent spurious errors
7542 -- about late attributes.
7543
7544 Set_Is_Frozen (Ent, False);
7545 Analyze (End_Decl_Expr);
7546 Set_Is_Frozen (Ent, True);
7547
7548 -- If the end of declarations comes before any other freeze
7549 -- point, the Freeze_Expr is not analyzed: no check needed.
7550
7551 if Analyzed (Freeze_Expr) and then not In_Instance then
7552 Check_Overloaded_Name;
7553 else
7554 Err := False;
7555 end if;
7556
7557 -- All other cases
7558
7559 else
7560 -- In a generic context the aspect expressions have not been
7561 -- preanalyzed, so do it now. There are no conformance checks
7562 -- to perform in this case.
7563
7564 if No (T) then
7565 Check_Aspect_At_Freeze_Point (ASN);
7566 return;
7567
7568 -- The default values attributes may be defined in the private part,
7569 -- and the analysis of the expression may take place when only the
7570 -- partial view is visible. The expression must be scalar, so use
7571 -- the full view to resolve.
7572
7573 elsif (A_Id = Aspect_Default_Value
7574 or else
7575 A_Id = Aspect_Default_Component_Value)
7576 and then Is_Private_Type (T)
7577 then
7578 Preanalyze_Spec_Expression (End_Decl_Expr, Full_View (T));
7579 else
7580 Preanalyze_Spec_Expression (End_Decl_Expr, T);
7581 end if;
7582
7583 Err := not Fully_Conformant_Expressions (End_Decl_Expr, Freeze_Expr);
7584 end if;
7585
7586 -- Output error message if error
7587
7588 if Err then
7589 Error_Msg_NE
7590 ("visibility of aspect for& changes after freeze point",
7591 ASN, Ent);
7592 Error_Msg_NE
7593 ("info: & is frozen here, aspects evaluated at this point??",
7594 Freeze_Node (Ent), Ent);
7595 end if;
7596 end Check_Aspect_At_End_Of_Declarations;
7597
7598 ----------------------------------
7599 -- Check_Aspect_At_Freeze_Point --
7600 ----------------------------------
7601
7602 procedure Check_Aspect_At_Freeze_Point (ASN : Node_Id) is
7603 Ident : constant Node_Id := Identifier (ASN);
7604 -- Identifier (use Entity field to save expression)
7605
7606 A_Id : constant Aspect_Id := Get_Aspect_Id (Chars (Ident));
7607
7608 T : Entity_Id := Empty;
7609 -- Type required for preanalyze call
7610
7611 begin
7612 -- On entry to this procedure, Entity (Ident) contains a copy of the
7613 -- original expression from the aspect, saved for this purpose.
7614
7615 -- On exit from this procedure Entity (Ident) is unchanged, still
7616 -- containing that copy, but Expression (Ident) is a preanalyzed copy
7617 -- of the expression, preanalyzed just after the freeze point.
7618
7619 -- Make a copy of the expression to be preanalyzed
7620
7621 Set_Expression (ASN, New_Copy_Tree (Entity (Ident)));
7622
7623 -- Find type for preanalyze call
7624
7625 case A_Id is
7626
7627 -- No_Aspect should be impossible
7628
7629 when No_Aspect =>
7630 raise Program_Error;
7631
7632 -- Aspects taking an optional boolean argument
7633
7634 when Boolean_Aspects |
7635 Library_Unit_Aspects =>
7636
7637 T := Standard_Boolean;
7638
7639 -- Aspects corresponding to attribute definition clauses
7640
7641 when Aspect_Address =>
7642 T := RTE (RE_Address);
7643
7644 when Aspect_Attach_Handler =>
7645 T := RTE (RE_Interrupt_ID);
7646
7647 when Aspect_Bit_Order | Aspect_Scalar_Storage_Order =>
7648 T := RTE (RE_Bit_Order);
7649
7650 when Aspect_Convention =>
7651 return;
7652
7653 when Aspect_CPU =>
7654 T := RTE (RE_CPU_Range);
7655
7656 -- Default_Component_Value is resolved with the component type
7657
7658 when Aspect_Default_Component_Value =>
7659 T := Component_Type (Entity (ASN));
7660
7661 -- Default_Value is resolved with the type entity in question
7662
7663 when Aspect_Default_Value =>
7664 T := Entity (ASN);
7665
7666 -- Depends is a delayed aspect because it mentiones names first
7667 -- introduced by aspect Global which is already delayed. There is
7668 -- no action to be taken with respect to the aspect itself as the
7669 -- analysis is done by the corresponding pragma.
7670
7671 when Aspect_Depends =>
7672 return;
7673
7674 when Aspect_Dispatching_Domain =>
7675 T := RTE (RE_Dispatching_Domain);
7676
7677 when Aspect_External_Tag =>
7678 T := Standard_String;
7679
7680 when Aspect_External_Name =>
7681 T := Standard_String;
7682
7683 -- Global is a delayed aspect because it may reference names that
7684 -- have not been declared yet. There is no action to be taken with
7685 -- respect to the aspect itself as the reference checking is done
7686 -- on the corresponding pragma.
7687
7688 when Aspect_Global =>
7689 return;
7690
7691 when Aspect_Link_Name =>
7692 T := Standard_String;
7693
7694 when Aspect_Priority | Aspect_Interrupt_Priority =>
7695 T := Standard_Integer;
7696
7697 when Aspect_Relative_Deadline =>
7698 T := RTE (RE_Time_Span);
7699
7700 when Aspect_Small =>
7701 T := Universal_Real;
7702
7703 -- For a simple storage pool, we have to retrieve the type of the
7704 -- pool object associated with the aspect's corresponding attribute
7705 -- definition clause.
7706
7707 when Aspect_Simple_Storage_Pool =>
7708 T := Etype (Expression (Aspect_Rep_Item (ASN)));
7709
7710 when Aspect_Storage_Pool =>
7711 T := Class_Wide_Type (RTE (RE_Root_Storage_Pool));
7712
7713 when Aspect_Alignment |
7714 Aspect_Component_Size |
7715 Aspect_Machine_Radix |
7716 Aspect_Object_Size |
7717 Aspect_Size |
7718 Aspect_Storage_Size |
7719 Aspect_Stream_Size |
7720 Aspect_Value_Size =>
7721 T := Any_Integer;
7722
7723 when Aspect_Synchronization =>
7724 return;
7725
7726 -- Special case, the expression of these aspects is just an entity
7727 -- that does not need any resolution, so just analyze.
7728
7729 when Aspect_Input |
7730 Aspect_Output |
7731 Aspect_Read |
7732 Aspect_Suppress |
7733 Aspect_Unsuppress |
7734 Aspect_Warnings |
7735 Aspect_Write =>
7736 Analyze (Expression (ASN));
7737 return;
7738
7739 -- Same for Iterator aspects, where the expression is a function
7740 -- name. Legality rules are checked separately.
7741
7742 when Aspect_Constant_Indexing |
7743 Aspect_Default_Iterator |
7744 Aspect_Iterator_Element |
7745 Aspect_Variable_Indexing =>
7746 Analyze (Expression (ASN));
7747 return;
7748
7749 -- Invariant/Predicate take boolean expressions
7750
7751 when Aspect_Dynamic_Predicate |
7752 Aspect_Invariant |
7753 Aspect_Predicate |
7754 Aspect_Static_Predicate |
7755 Aspect_Type_Invariant =>
7756 T := Standard_Boolean;
7757
7758 -- Here is the list of aspects that don't require delay analysis
7759
7760 when Aspect_Abstract_State |
7761 Aspect_Contract_Cases |
7762 Aspect_Dimension |
7763 Aspect_Dimension_System |
7764 Aspect_Implicit_Dereference |
7765 Aspect_Post |
7766 Aspect_Postcondition |
7767 Aspect_Pre |
7768 Aspect_Precondition |
7769 Aspect_SPARK_Mode |
7770 Aspect_Test_Case =>
7771 raise Program_Error;
7772
7773 end case;
7774
7775 -- Do the preanalyze call
7776
7777 Preanalyze_Spec_Expression (Expression (ASN), T);
7778 end Check_Aspect_At_Freeze_Point;
7779
7780 -----------------------------------
7781 -- Check_Constant_Address_Clause --
7782 -----------------------------------
7783
7784 procedure Check_Constant_Address_Clause
7785 (Expr : Node_Id;
7786 U_Ent : Entity_Id)
7787 is
7788 procedure Check_At_Constant_Address (Nod : Node_Id);
7789 -- Checks that the given node N represents a name whose 'Address is
7790 -- constant (in the same sense as OK_Constant_Address_Clause, i.e. the
7791 -- address value is the same at the point of declaration of U_Ent and at
7792 -- the time of elaboration of the address clause.
7793
7794 procedure Check_Expr_Constants (Nod : Node_Id);
7795 -- Checks that Nod meets the requirements for a constant address clause
7796 -- in the sense of the enclosing procedure.
7797
7798 procedure Check_List_Constants (Lst : List_Id);
7799 -- Check that all elements of list Lst meet the requirements for a
7800 -- constant address clause in the sense of the enclosing procedure.
7801
7802 -------------------------------
7803 -- Check_At_Constant_Address --
7804 -------------------------------
7805
7806 procedure Check_At_Constant_Address (Nod : Node_Id) is
7807 begin
7808 if Is_Entity_Name (Nod) then
7809 if Present (Address_Clause (Entity ((Nod)))) then
7810 Error_Msg_NE
7811 ("invalid address clause for initialized object &!",
7812 Nod, U_Ent);
7813 Error_Msg_NE
7814 ("address for& cannot" &
7815 " depend on another address clause! (RM 13.1(22))!",
7816 Nod, U_Ent);
7817
7818 elsif In_Same_Source_Unit (Entity (Nod), U_Ent)
7819 and then Sloc (U_Ent) < Sloc (Entity (Nod))
7820 then
7821 Error_Msg_NE
7822 ("invalid address clause for initialized object &!",
7823 Nod, U_Ent);
7824 Error_Msg_Node_2 := U_Ent;
7825 Error_Msg_NE
7826 ("\& must be defined before & (RM 13.1(22))!",
7827 Nod, Entity (Nod));
7828 end if;
7829
7830 elsif Nkind (Nod) = N_Selected_Component then
7831 declare
7832 T : constant Entity_Id := Etype (Prefix (Nod));
7833
7834 begin
7835 if (Is_Record_Type (T)
7836 and then Has_Discriminants (T))
7837 or else
7838 (Is_Access_Type (T)
7839 and then Is_Record_Type (Designated_Type (T))
7840 and then Has_Discriminants (Designated_Type (T)))
7841 then
7842 Error_Msg_NE
7843 ("invalid address clause for initialized object &!",
7844 Nod, U_Ent);
7845 Error_Msg_N
7846 ("\address cannot depend on component" &
7847 " of discriminated record (RM 13.1(22))!",
7848 Nod);
7849 else
7850 Check_At_Constant_Address (Prefix (Nod));
7851 end if;
7852 end;
7853
7854 elsif Nkind (Nod) = N_Indexed_Component then
7855 Check_At_Constant_Address (Prefix (Nod));
7856 Check_List_Constants (Expressions (Nod));
7857
7858 else
7859 Check_Expr_Constants (Nod);
7860 end if;
7861 end Check_At_Constant_Address;
7862
7863 --------------------------
7864 -- Check_Expr_Constants --
7865 --------------------------
7866
7867 procedure Check_Expr_Constants (Nod : Node_Id) is
7868 Loc_U_Ent : constant Source_Ptr := Sloc (U_Ent);
7869 Ent : Entity_Id := Empty;
7870
7871 begin
7872 if Nkind (Nod) in N_Has_Etype
7873 and then Etype (Nod) = Any_Type
7874 then
7875 return;
7876 end if;
7877
7878 case Nkind (Nod) is
7879 when N_Empty | N_Error =>
7880 return;
7881
7882 when N_Identifier | N_Expanded_Name =>
7883 Ent := Entity (Nod);
7884
7885 -- We need to look at the original node if it is different
7886 -- from the node, since we may have rewritten things and
7887 -- substituted an identifier representing the rewrite.
7888
7889 if Original_Node (Nod) /= Nod then
7890 Check_Expr_Constants (Original_Node (Nod));
7891
7892 -- If the node is an object declaration without initial
7893 -- value, some code has been expanded, and the expression
7894 -- is not constant, even if the constituents might be
7895 -- acceptable, as in A'Address + offset.
7896
7897 if Ekind (Ent) = E_Variable
7898 and then
7899 Nkind (Declaration_Node (Ent)) = N_Object_Declaration
7900 and then
7901 No (Expression (Declaration_Node (Ent)))
7902 then
7903 Error_Msg_NE
7904 ("invalid address clause for initialized object &!",
7905 Nod, U_Ent);
7906
7907 -- If entity is constant, it may be the result of expanding
7908 -- a check. We must verify that its declaration appears
7909 -- before the object in question, else we also reject the
7910 -- address clause.
7911
7912 elsif Ekind (Ent) = E_Constant
7913 and then In_Same_Source_Unit (Ent, U_Ent)
7914 and then Sloc (Ent) > Loc_U_Ent
7915 then
7916 Error_Msg_NE
7917 ("invalid address clause for initialized object &!",
7918 Nod, U_Ent);
7919 end if;
7920
7921 return;
7922 end if;
7923
7924 -- Otherwise look at the identifier and see if it is OK
7925
7926 if Ekind_In (Ent, E_Named_Integer, E_Named_Real)
7927 or else Is_Type (Ent)
7928 then
7929 return;
7930
7931 elsif
7932 Ekind (Ent) = E_Constant
7933 or else
7934 Ekind (Ent) = E_In_Parameter
7935 then
7936 -- This is the case where we must have Ent defined before
7937 -- U_Ent. Clearly if they are in different units this
7938 -- requirement is met since the unit containing Ent is
7939 -- already processed.
7940
7941 if not In_Same_Source_Unit (Ent, U_Ent) then
7942 return;
7943
7944 -- Otherwise location of Ent must be before the location
7945 -- of U_Ent, that's what prior defined means.
7946
7947 elsif Sloc (Ent) < Loc_U_Ent then
7948 return;
7949
7950 else
7951 Error_Msg_NE
7952 ("invalid address clause for initialized object &!",
7953 Nod, U_Ent);
7954 Error_Msg_Node_2 := U_Ent;
7955 Error_Msg_NE
7956 ("\& must be defined before & (RM 13.1(22))!",
7957 Nod, Ent);
7958 end if;
7959
7960 elsif Nkind (Original_Node (Nod)) = N_Function_Call then
7961 Check_Expr_Constants (Original_Node (Nod));
7962
7963 else
7964 Error_Msg_NE
7965 ("invalid address clause for initialized object &!",
7966 Nod, U_Ent);
7967
7968 if Comes_From_Source (Ent) then
7969 Error_Msg_NE
7970 ("\reference to variable& not allowed"
7971 & " (RM 13.1(22))!", Nod, Ent);
7972 else
7973 Error_Msg_N
7974 ("non-static expression not allowed"
7975 & " (RM 13.1(22))!", Nod);
7976 end if;
7977 end if;
7978
7979 when N_Integer_Literal =>
7980
7981 -- If this is a rewritten unchecked conversion, in a system
7982 -- where Address is an integer type, always use the base type
7983 -- for a literal value. This is user-friendly and prevents
7984 -- order-of-elaboration issues with instances of unchecked
7985 -- conversion.
7986
7987 if Nkind (Original_Node (Nod)) = N_Function_Call then
7988 Set_Etype (Nod, Base_Type (Etype (Nod)));
7989 end if;
7990
7991 when N_Real_Literal |
7992 N_String_Literal |
7993 N_Character_Literal =>
7994 return;
7995
7996 when N_Range =>
7997 Check_Expr_Constants (Low_Bound (Nod));
7998 Check_Expr_Constants (High_Bound (Nod));
7999
8000 when N_Explicit_Dereference =>
8001 Check_Expr_Constants (Prefix (Nod));
8002
8003 when N_Indexed_Component =>
8004 Check_Expr_Constants (Prefix (Nod));
8005 Check_List_Constants (Expressions (Nod));
8006
8007 when N_Slice =>
8008 Check_Expr_Constants (Prefix (Nod));
8009 Check_Expr_Constants (Discrete_Range (Nod));
8010
8011 when N_Selected_Component =>
8012 Check_Expr_Constants (Prefix (Nod));
8013
8014 when N_Attribute_Reference =>
8015 if Nam_In (Attribute_Name (Nod), Name_Address,
8016 Name_Access,
8017 Name_Unchecked_Access,
8018 Name_Unrestricted_Access)
8019 then
8020 Check_At_Constant_Address (Prefix (Nod));
8021
8022 else
8023 Check_Expr_Constants (Prefix (Nod));
8024 Check_List_Constants (Expressions (Nod));
8025 end if;
8026
8027 when N_Aggregate =>
8028 Check_List_Constants (Component_Associations (Nod));
8029 Check_List_Constants (Expressions (Nod));
8030
8031 when N_Component_Association =>
8032 Check_Expr_Constants (Expression (Nod));
8033
8034 when N_Extension_Aggregate =>
8035 Check_Expr_Constants (Ancestor_Part (Nod));
8036 Check_List_Constants (Component_Associations (Nod));
8037 Check_List_Constants (Expressions (Nod));
8038
8039 when N_Null =>
8040 return;
8041
8042 when N_Binary_Op | N_Short_Circuit | N_Membership_Test =>
8043 Check_Expr_Constants (Left_Opnd (Nod));
8044 Check_Expr_Constants (Right_Opnd (Nod));
8045
8046 when N_Unary_Op =>
8047 Check_Expr_Constants (Right_Opnd (Nod));
8048
8049 when N_Type_Conversion |
8050 N_Qualified_Expression |
8051 N_Allocator |
8052 N_Unchecked_Type_Conversion =>
8053 Check_Expr_Constants (Expression (Nod));
8054
8055 when N_Function_Call =>
8056 if not Is_Pure (Entity (Name (Nod))) then
8057 Error_Msg_NE
8058 ("invalid address clause for initialized object &!",
8059 Nod, U_Ent);
8060
8061 Error_Msg_NE
8062 ("\function & is not pure (RM 13.1(22))!",
8063 Nod, Entity (Name (Nod)));
8064
8065 else
8066 Check_List_Constants (Parameter_Associations (Nod));
8067 end if;
8068
8069 when N_Parameter_Association =>
8070 Check_Expr_Constants (Explicit_Actual_Parameter (Nod));
8071
8072 when others =>
8073 Error_Msg_NE
8074 ("invalid address clause for initialized object &!",
8075 Nod, U_Ent);
8076 Error_Msg_NE
8077 ("\must be constant defined before& (RM 13.1(22))!",
8078 Nod, U_Ent);
8079 end case;
8080 end Check_Expr_Constants;
8081
8082 --------------------------
8083 -- Check_List_Constants --
8084 --------------------------
8085
8086 procedure Check_List_Constants (Lst : List_Id) is
8087 Nod1 : Node_Id;
8088
8089 begin
8090 if Present (Lst) then
8091 Nod1 := First (Lst);
8092 while Present (Nod1) loop
8093 Check_Expr_Constants (Nod1);
8094 Next (Nod1);
8095 end loop;
8096 end if;
8097 end Check_List_Constants;
8098
8099 -- Start of processing for Check_Constant_Address_Clause
8100
8101 begin
8102 -- If rep_clauses are to be ignored, no need for legality checks. In
8103 -- particular, no need to pester user about rep clauses that violate
8104 -- the rule on constant addresses, given that these clauses will be
8105 -- removed by Freeze before they reach the back end.
8106
8107 if not Ignore_Rep_Clauses then
8108 Check_Expr_Constants (Expr);
8109 end if;
8110 end Check_Constant_Address_Clause;
8111
8112 ----------------------------------------
8113 -- Check_Record_Representation_Clause --
8114 ----------------------------------------
8115
8116 procedure Check_Record_Representation_Clause (N : Node_Id) is
8117 Loc : constant Source_Ptr := Sloc (N);
8118 Ident : constant Node_Id := Identifier (N);
8119 Rectype : Entity_Id;
8120 Fent : Entity_Id;
8121 CC : Node_Id;
8122 Fbit : Uint;
8123 Lbit : Uint;
8124 Hbit : Uint := Uint_0;
8125 Comp : Entity_Id;
8126 Pcomp : Entity_Id;
8127
8128 Max_Bit_So_Far : Uint;
8129 -- Records the maximum bit position so far. If all field positions
8130 -- are monotonically increasing, then we can skip the circuit for
8131 -- checking for overlap, since no overlap is possible.
8132
8133 Tagged_Parent : Entity_Id := Empty;
8134 -- This is set in the case of a derived tagged type for which we have
8135 -- Is_Fully_Repped_Tagged_Type True (indicating that all components are
8136 -- positioned by record representation clauses). In this case we must
8137 -- check for overlap between components of this tagged type, and the
8138 -- components of its parent. Tagged_Parent will point to this parent
8139 -- type. For all other cases Tagged_Parent is left set to Empty.
8140
8141 Parent_Last_Bit : Uint;
8142 -- Relevant only if Tagged_Parent is set, Parent_Last_Bit indicates the
8143 -- last bit position for any field in the parent type. We only need to
8144 -- check overlap for fields starting below this point.
8145
8146 Overlap_Check_Required : Boolean;
8147 -- Used to keep track of whether or not an overlap check is required
8148
8149 Overlap_Detected : Boolean := False;
8150 -- Set True if an overlap is detected
8151
8152 Ccount : Natural := 0;
8153 -- Number of component clauses in record rep clause
8154
8155 procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id);
8156 -- Given two entities for record components or discriminants, checks
8157 -- if they have overlapping component clauses and issues errors if so.
8158
8159 procedure Find_Component;
8160 -- Finds component entity corresponding to current component clause (in
8161 -- CC), and sets Comp to the entity, and Fbit/Lbit to the zero origin
8162 -- start/stop bits for the field. If there is no matching component or
8163 -- if the matching component does not have a component clause, then
8164 -- that's an error and Comp is set to Empty, but no error message is
8165 -- issued, since the message was already given. Comp is also set to
8166 -- Empty if the current "component clause" is in fact a pragma.
8167
8168 -----------------------------
8169 -- Check_Component_Overlap --
8170 -----------------------------
8171
8172 procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id) is
8173 CC1 : constant Node_Id := Component_Clause (C1_Ent);
8174 CC2 : constant Node_Id := Component_Clause (C2_Ent);
8175
8176 begin
8177 if Present (CC1) and then Present (CC2) then
8178
8179 -- Exclude odd case where we have two tag components in the same
8180 -- record, both at location zero. This seems a bit strange, but
8181 -- it seems to happen in some circumstances, perhaps on an error.
8182
8183 if Nam_In (Chars (C1_Ent), Name_uTag, Name_uTag) then
8184 return;
8185 end if;
8186
8187 -- Here we check if the two fields overlap
8188
8189 declare
8190 S1 : constant Uint := Component_Bit_Offset (C1_Ent);
8191 S2 : constant Uint := Component_Bit_Offset (C2_Ent);
8192 E1 : constant Uint := S1 + Esize (C1_Ent);
8193 E2 : constant Uint := S2 + Esize (C2_Ent);
8194
8195 begin
8196 if E2 <= S1 or else E1 <= S2 then
8197 null;
8198 else
8199 Error_Msg_Node_2 := Component_Name (CC2);
8200 Error_Msg_Sloc := Sloc (Error_Msg_Node_2);
8201 Error_Msg_Node_1 := Component_Name (CC1);
8202 Error_Msg_N
8203 ("component& overlaps & #", Component_Name (CC1));
8204 Overlap_Detected := True;
8205 end if;
8206 end;
8207 end if;
8208 end Check_Component_Overlap;
8209
8210 --------------------
8211 -- Find_Component --
8212 --------------------
8213
8214 procedure Find_Component is
8215
8216 procedure Search_Component (R : Entity_Id);
8217 -- Search components of R for a match. If found, Comp is set
8218
8219 ----------------------
8220 -- Search_Component --
8221 ----------------------
8222
8223 procedure Search_Component (R : Entity_Id) is
8224 begin
8225 Comp := First_Component_Or_Discriminant (R);
8226 while Present (Comp) loop
8227
8228 -- Ignore error of attribute name for component name (we
8229 -- already gave an error message for this, so no need to
8230 -- complain here)
8231
8232 if Nkind (Component_Name (CC)) = N_Attribute_Reference then
8233 null;
8234 else
8235 exit when Chars (Comp) = Chars (Component_Name (CC));
8236 end if;
8237
8238 Next_Component_Or_Discriminant (Comp);
8239 end loop;
8240 end Search_Component;
8241
8242 -- Start of processing for Find_Component
8243
8244 begin
8245 -- Return with Comp set to Empty if we have a pragma
8246
8247 if Nkind (CC) = N_Pragma then
8248 Comp := Empty;
8249 return;
8250 end if;
8251
8252 -- Search current record for matching component
8253
8254 Search_Component (Rectype);
8255
8256 -- If not found, maybe component of base type discriminant that is
8257 -- absent from statically constrained first subtype.
8258
8259 if No (Comp) then
8260 Search_Component (Base_Type (Rectype));
8261 end if;
8262
8263 -- If no component, or the component does not reference the component
8264 -- clause in question, then there was some previous error for which
8265 -- we already gave a message, so just return with Comp Empty.
8266
8267 if No (Comp) or else Component_Clause (Comp) /= CC then
8268 Check_Error_Detected;
8269 Comp := Empty;
8270
8271 -- Normal case where we have a component clause
8272
8273 else
8274 Fbit := Component_Bit_Offset (Comp);
8275 Lbit := Fbit + Esize (Comp) - 1;
8276 end if;
8277 end Find_Component;
8278
8279 -- Start of processing for Check_Record_Representation_Clause
8280
8281 begin
8282 Find_Type (Ident);
8283 Rectype := Entity (Ident);
8284
8285 if Rectype = Any_Type then
8286 return;
8287 else
8288 Rectype := Underlying_Type (Rectype);
8289 end if;
8290
8291 -- See if we have a fully repped derived tagged type
8292
8293 declare
8294 PS : constant Entity_Id := Parent_Subtype (Rectype);
8295
8296 begin
8297 if Present (PS) and then Is_Fully_Repped_Tagged_Type (PS) then
8298 Tagged_Parent := PS;
8299
8300 -- Find maximum bit of any component of the parent type
8301
8302 Parent_Last_Bit := UI_From_Int (System_Address_Size - 1);
8303 Pcomp := First_Entity (Tagged_Parent);
8304 while Present (Pcomp) loop
8305 if Ekind_In (Pcomp, E_Discriminant, E_Component) then
8306 if Component_Bit_Offset (Pcomp) /= No_Uint
8307 and then Known_Static_Esize (Pcomp)
8308 then
8309 Parent_Last_Bit :=
8310 UI_Max
8311 (Parent_Last_Bit,
8312 Component_Bit_Offset (Pcomp) + Esize (Pcomp) - 1);
8313 end if;
8314
8315 Next_Entity (Pcomp);
8316 end if;
8317 end loop;
8318 end if;
8319 end;
8320
8321 -- All done if no component clauses
8322
8323 CC := First (Component_Clauses (N));
8324
8325 if No (CC) then
8326 return;
8327 end if;
8328
8329 -- If a tag is present, then create a component clause that places it
8330 -- at the start of the record (otherwise gigi may place it after other
8331 -- fields that have rep clauses).
8332
8333 Fent := First_Entity (Rectype);
8334
8335 if Nkind (Fent) = N_Defining_Identifier
8336 and then Chars (Fent) = Name_uTag
8337 then
8338 Set_Component_Bit_Offset (Fent, Uint_0);
8339 Set_Normalized_Position (Fent, Uint_0);
8340 Set_Normalized_First_Bit (Fent, Uint_0);
8341 Set_Normalized_Position_Max (Fent, Uint_0);
8342 Init_Esize (Fent, System_Address_Size);
8343
8344 Set_Component_Clause (Fent,
8345 Make_Component_Clause (Loc,
8346 Component_Name => Make_Identifier (Loc, Name_uTag),
8347
8348 Position => Make_Integer_Literal (Loc, Uint_0),
8349 First_Bit => Make_Integer_Literal (Loc, Uint_0),
8350 Last_Bit =>
8351 Make_Integer_Literal (Loc,
8352 UI_From_Int (System_Address_Size))));
8353
8354 Ccount := Ccount + 1;
8355 end if;
8356
8357 Max_Bit_So_Far := Uint_Minus_1;
8358 Overlap_Check_Required := False;
8359
8360 -- Process the component clauses
8361
8362 while Present (CC) loop
8363 Find_Component;
8364
8365 if Present (Comp) then
8366 Ccount := Ccount + 1;
8367
8368 -- We need a full overlap check if record positions non-monotonic
8369
8370 if Fbit <= Max_Bit_So_Far then
8371 Overlap_Check_Required := True;
8372 end if;
8373
8374 Max_Bit_So_Far := Lbit;
8375
8376 -- Check bit position out of range of specified size
8377
8378 if Has_Size_Clause (Rectype)
8379 and then RM_Size (Rectype) <= Lbit
8380 then
8381 Error_Msg_N
8382 ("bit number out of range of specified size",
8383 Last_Bit (CC));
8384
8385 -- Check for overlap with tag component
8386
8387 else
8388 if Is_Tagged_Type (Rectype)
8389 and then Fbit < System_Address_Size
8390 then
8391 Error_Msg_NE
8392 ("component overlaps tag field of&",
8393 Component_Name (CC), Rectype);
8394 Overlap_Detected := True;
8395 end if;
8396
8397 if Hbit < Lbit then
8398 Hbit := Lbit;
8399 end if;
8400 end if;
8401
8402 -- Check parent overlap if component might overlap parent field
8403
8404 if Present (Tagged_Parent) and then Fbit <= Parent_Last_Bit then
8405 Pcomp := First_Component_Or_Discriminant (Tagged_Parent);
8406 while Present (Pcomp) loop
8407 if not Is_Tag (Pcomp)
8408 and then Chars (Pcomp) /= Name_uParent
8409 then
8410 Check_Component_Overlap (Comp, Pcomp);
8411 end if;
8412
8413 Next_Component_Or_Discriminant (Pcomp);
8414 end loop;
8415 end if;
8416 end if;
8417
8418 Next (CC);
8419 end loop;
8420
8421 -- Now that we have processed all the component clauses, check for
8422 -- overlap. We have to leave this till last, since the components can
8423 -- appear in any arbitrary order in the representation clause.
8424
8425 -- We do not need this check if all specified ranges were monotonic,
8426 -- as recorded by Overlap_Check_Required being False at this stage.
8427
8428 -- This first section checks if there are any overlapping entries at
8429 -- all. It does this by sorting all entries and then seeing if there are
8430 -- any overlaps. If there are none, then that is decisive, but if there
8431 -- are overlaps, they may still be OK (they may result from fields in
8432 -- different variants).
8433
8434 if Overlap_Check_Required then
8435 Overlap_Check1 : declare
8436
8437 OC_Fbit : array (0 .. Ccount) of Uint;
8438 -- First-bit values for component clauses, the value is the offset
8439 -- of the first bit of the field from start of record. The zero
8440 -- entry is for use in sorting.
8441
8442 OC_Lbit : array (0 .. Ccount) of Uint;
8443 -- Last-bit values for component clauses, the value is the offset
8444 -- of the last bit of the field from start of record. The zero
8445 -- entry is for use in sorting.
8446
8447 OC_Count : Natural := 0;
8448 -- Count of entries in OC_Fbit and OC_Lbit
8449
8450 function OC_Lt (Op1, Op2 : Natural) return Boolean;
8451 -- Compare routine for Sort
8452
8453 procedure OC_Move (From : Natural; To : Natural);
8454 -- Move routine for Sort
8455
8456 package Sorting is new GNAT.Heap_Sort_G (OC_Move, OC_Lt);
8457
8458 -----------
8459 -- OC_Lt --
8460 -----------
8461
8462 function OC_Lt (Op1, Op2 : Natural) return Boolean is
8463 begin
8464 return OC_Fbit (Op1) < OC_Fbit (Op2);
8465 end OC_Lt;
8466
8467 -------------
8468 -- OC_Move --
8469 -------------
8470
8471 procedure OC_Move (From : Natural; To : Natural) is
8472 begin
8473 OC_Fbit (To) := OC_Fbit (From);
8474 OC_Lbit (To) := OC_Lbit (From);
8475 end OC_Move;
8476
8477 -- Start of processing for Overlap_Check
8478
8479 begin
8480 CC := First (Component_Clauses (N));
8481 while Present (CC) loop
8482
8483 -- Exclude component clause already marked in error
8484
8485 if not Error_Posted (CC) then
8486 Find_Component;
8487
8488 if Present (Comp) then
8489 OC_Count := OC_Count + 1;
8490 OC_Fbit (OC_Count) := Fbit;
8491 OC_Lbit (OC_Count) := Lbit;
8492 end if;
8493 end if;
8494
8495 Next (CC);
8496 end loop;
8497
8498 Sorting.Sort (OC_Count);
8499
8500 Overlap_Check_Required := False;
8501 for J in 1 .. OC_Count - 1 loop
8502 if OC_Lbit (J) >= OC_Fbit (J + 1) then
8503 Overlap_Check_Required := True;
8504 exit;
8505 end if;
8506 end loop;
8507 end Overlap_Check1;
8508 end if;
8509
8510 -- If Overlap_Check_Required is still True, then we have to do the full
8511 -- scale overlap check, since we have at least two fields that do
8512 -- overlap, and we need to know if that is OK since they are in
8513 -- different variant, or whether we have a definite problem.
8514
8515 if Overlap_Check_Required then
8516 Overlap_Check2 : declare
8517 C1_Ent, C2_Ent : Entity_Id;
8518 -- Entities of components being checked for overlap
8519
8520 Clist : Node_Id;
8521 -- Component_List node whose Component_Items are being checked
8522
8523 Citem : Node_Id;
8524 -- Component declaration for component being checked
8525
8526 begin
8527 C1_Ent := First_Entity (Base_Type (Rectype));
8528
8529 -- Loop through all components in record. For each component check
8530 -- for overlap with any of the preceding elements on the component
8531 -- list containing the component and also, if the component is in
8532 -- a variant, check against components outside the case structure.
8533 -- This latter test is repeated recursively up the variant tree.
8534
8535 Main_Component_Loop : while Present (C1_Ent) loop
8536 if not Ekind_In (C1_Ent, E_Component, E_Discriminant) then
8537 goto Continue_Main_Component_Loop;
8538 end if;
8539
8540 -- Skip overlap check if entity has no declaration node. This
8541 -- happens with discriminants in constrained derived types.
8542 -- Possibly we are missing some checks as a result, but that
8543 -- does not seem terribly serious.
8544
8545 if No (Declaration_Node (C1_Ent)) then
8546 goto Continue_Main_Component_Loop;
8547 end if;
8548
8549 Clist := Parent (List_Containing (Declaration_Node (C1_Ent)));
8550
8551 -- Loop through component lists that need checking. Check the
8552 -- current component list and all lists in variants above us.
8553
8554 Component_List_Loop : loop
8555
8556 -- If derived type definition, go to full declaration
8557 -- If at outer level, check discriminants if there are any.
8558
8559 if Nkind (Clist) = N_Derived_Type_Definition then
8560 Clist := Parent (Clist);
8561 end if;
8562
8563 -- Outer level of record definition, check discriminants
8564
8565 if Nkind_In (Clist, N_Full_Type_Declaration,
8566 N_Private_Type_Declaration)
8567 then
8568 if Has_Discriminants (Defining_Identifier (Clist)) then
8569 C2_Ent :=
8570 First_Discriminant (Defining_Identifier (Clist));
8571 while Present (C2_Ent) loop
8572 exit when C1_Ent = C2_Ent;
8573 Check_Component_Overlap (C1_Ent, C2_Ent);
8574 Next_Discriminant (C2_Ent);
8575 end loop;
8576 end if;
8577
8578 -- Record extension case
8579
8580 elsif Nkind (Clist) = N_Derived_Type_Definition then
8581 Clist := Empty;
8582
8583 -- Otherwise check one component list
8584
8585 else
8586 Citem := First (Component_Items (Clist));
8587 while Present (Citem) loop
8588 if Nkind (Citem) = N_Component_Declaration then
8589 C2_Ent := Defining_Identifier (Citem);
8590 exit when C1_Ent = C2_Ent;
8591 Check_Component_Overlap (C1_Ent, C2_Ent);
8592 end if;
8593
8594 Next (Citem);
8595 end loop;
8596 end if;
8597
8598 -- Check for variants above us (the parent of the Clist can
8599 -- be a variant, in which case its parent is a variant part,
8600 -- and the parent of the variant part is a component list
8601 -- whose components must all be checked against the current
8602 -- component for overlap).
8603
8604 if Nkind (Parent (Clist)) = N_Variant then
8605 Clist := Parent (Parent (Parent (Clist)));
8606
8607 -- Check for possible discriminant part in record, this
8608 -- is treated essentially as another level in the
8609 -- recursion. For this case the parent of the component
8610 -- list is the record definition, and its parent is the
8611 -- full type declaration containing the discriminant
8612 -- specifications.
8613
8614 elsif Nkind (Parent (Clist)) = N_Record_Definition then
8615 Clist := Parent (Parent ((Clist)));
8616
8617 -- If neither of these two cases, we are at the top of
8618 -- the tree.
8619
8620 else
8621 exit Component_List_Loop;
8622 end if;
8623 end loop Component_List_Loop;
8624
8625 <<Continue_Main_Component_Loop>>
8626 Next_Entity (C1_Ent);
8627
8628 end loop Main_Component_Loop;
8629 end Overlap_Check2;
8630 end if;
8631
8632 -- The following circuit deals with warning on record holes (gaps). We
8633 -- skip this check if overlap was detected, since it makes sense for the
8634 -- programmer to fix this illegality before worrying about warnings.
8635
8636 if not Overlap_Detected and Warn_On_Record_Holes then
8637 Record_Hole_Check : declare
8638 Decl : constant Node_Id := Declaration_Node (Base_Type (Rectype));
8639 -- Full declaration of record type
8640
8641 procedure Check_Component_List
8642 (CL : Node_Id;
8643 Sbit : Uint;
8644 DS : List_Id);
8645 -- Check component list CL for holes. The starting bit should be
8646 -- Sbit. which is zero for the main record component list and set
8647 -- appropriately for recursive calls for variants. DS is set to
8648 -- a list of discriminant specifications to be included in the
8649 -- consideration of components. It is No_List if none to consider.
8650
8651 --------------------------
8652 -- Check_Component_List --
8653 --------------------------
8654
8655 procedure Check_Component_List
8656 (CL : Node_Id;
8657 Sbit : Uint;
8658 DS : List_Id)
8659 is
8660 Compl : Integer;
8661
8662 begin
8663 Compl := Integer (List_Length (Component_Items (CL)));
8664
8665 if DS /= No_List then
8666 Compl := Compl + Integer (List_Length (DS));
8667 end if;
8668
8669 declare
8670 Comps : array (Natural range 0 .. Compl) of Entity_Id;
8671 -- Gather components (zero entry is for sort routine)
8672
8673 Ncomps : Natural := 0;
8674 -- Number of entries stored in Comps (starting at Comps (1))
8675
8676 Citem : Node_Id;
8677 -- One component item or discriminant specification
8678
8679 Nbit : Uint;
8680 -- Starting bit for next component
8681
8682 CEnt : Entity_Id;
8683 -- Component entity
8684
8685 Variant : Node_Id;
8686 -- One variant
8687
8688 function Lt (Op1, Op2 : Natural) return Boolean;
8689 -- Compare routine for Sort
8690
8691 procedure Move (From : Natural; To : Natural);
8692 -- Move routine for Sort
8693
8694 package Sorting is new GNAT.Heap_Sort_G (Move, Lt);
8695
8696 --------
8697 -- Lt --
8698 --------
8699
8700 function Lt (Op1, Op2 : Natural) return Boolean is
8701 begin
8702 return Component_Bit_Offset (Comps (Op1))
8703 <
8704 Component_Bit_Offset (Comps (Op2));
8705 end Lt;
8706
8707 ----------
8708 -- Move --
8709 ----------
8710
8711 procedure Move (From : Natural; To : Natural) is
8712 begin
8713 Comps (To) := Comps (From);
8714 end Move;
8715
8716 begin
8717 -- Gather discriminants into Comp
8718
8719 if DS /= No_List then
8720 Citem := First (DS);
8721 while Present (Citem) loop
8722 if Nkind (Citem) = N_Discriminant_Specification then
8723 declare
8724 Ent : constant Entity_Id :=
8725 Defining_Identifier (Citem);
8726 begin
8727 if Ekind (Ent) = E_Discriminant then
8728 Ncomps := Ncomps + 1;
8729 Comps (Ncomps) := Ent;
8730 end if;
8731 end;
8732 end if;
8733
8734 Next (Citem);
8735 end loop;
8736 end if;
8737
8738 -- Gather component entities into Comp
8739
8740 Citem := First (Component_Items (CL));
8741 while Present (Citem) loop
8742 if Nkind (Citem) = N_Component_Declaration then
8743 Ncomps := Ncomps + 1;
8744 Comps (Ncomps) := Defining_Identifier (Citem);
8745 end if;
8746
8747 Next (Citem);
8748 end loop;
8749
8750 -- Now sort the component entities based on the first bit.
8751 -- Note we already know there are no overlapping components.
8752
8753 Sorting.Sort (Ncomps);
8754
8755 -- Loop through entries checking for holes
8756
8757 Nbit := Sbit;
8758 for J in 1 .. Ncomps loop
8759 CEnt := Comps (J);
8760 Error_Msg_Uint_1 := Component_Bit_Offset (CEnt) - Nbit;
8761
8762 if Error_Msg_Uint_1 > 0 then
8763 Error_Msg_NE
8764 ("?H?^-bit gap before component&",
8765 Component_Name (Component_Clause (CEnt)), CEnt);
8766 end if;
8767
8768 Nbit := Component_Bit_Offset (CEnt) + Esize (CEnt);
8769 end loop;
8770
8771 -- Process variant parts recursively if present
8772
8773 if Present (Variant_Part (CL)) then
8774 Variant := First (Variants (Variant_Part (CL)));
8775 while Present (Variant) loop
8776 Check_Component_List
8777 (Component_List (Variant), Nbit, No_List);
8778 Next (Variant);
8779 end loop;
8780 end if;
8781 end;
8782 end Check_Component_List;
8783
8784 -- Start of processing for Record_Hole_Check
8785
8786 begin
8787 declare
8788 Sbit : Uint;
8789
8790 begin
8791 if Is_Tagged_Type (Rectype) then
8792 Sbit := UI_From_Int (System_Address_Size);
8793 else
8794 Sbit := Uint_0;
8795 end if;
8796
8797 if Nkind (Decl) = N_Full_Type_Declaration
8798 and then Nkind (Type_Definition (Decl)) = N_Record_Definition
8799 then
8800 Check_Component_List
8801 (Component_List (Type_Definition (Decl)),
8802 Sbit,
8803 Discriminant_Specifications (Decl));
8804 end if;
8805 end;
8806 end Record_Hole_Check;
8807 end if;
8808
8809 -- For records that have component clauses for all components, and whose
8810 -- size is less than or equal to 32, we need to know the size in the
8811 -- front end to activate possible packed array processing where the
8812 -- component type is a record.
8813
8814 -- At this stage Hbit + 1 represents the first unused bit from all the
8815 -- component clauses processed, so if the component clauses are
8816 -- complete, then this is the length of the record.
8817
8818 -- For records longer than System.Storage_Unit, and for those where not
8819 -- all components have component clauses, the back end determines the
8820 -- length (it may for example be appropriate to round up the size
8821 -- to some convenient boundary, based on alignment considerations, etc).
8822
8823 if Unknown_RM_Size (Rectype) and then Hbit + 1 <= 32 then
8824
8825 -- Nothing to do if at least one component has no component clause
8826
8827 Comp := First_Component_Or_Discriminant (Rectype);
8828 while Present (Comp) loop
8829 exit when No (Component_Clause (Comp));
8830 Next_Component_Or_Discriminant (Comp);
8831 end loop;
8832
8833 -- If we fall out of loop, all components have component clauses
8834 -- and so we can set the size to the maximum value.
8835
8836 if No (Comp) then
8837 Set_RM_Size (Rectype, Hbit + 1);
8838 end if;
8839 end if;
8840 end Check_Record_Representation_Clause;
8841
8842 ----------------
8843 -- Check_Size --
8844 ----------------
8845
8846 procedure Check_Size
8847 (N : Node_Id;
8848 T : Entity_Id;
8849 Siz : Uint;
8850 Biased : out Boolean)
8851 is
8852 UT : constant Entity_Id := Underlying_Type (T);
8853 M : Uint;
8854
8855 begin
8856 Biased := False;
8857
8858 -- Reject patently improper size values.
8859
8860 if Is_Elementary_Type (T)
8861 and then Siz > UI_From_Int (Int'Last)
8862 then
8863 Error_Msg_N ("Size value too large for elementary type", N);
8864
8865 if Nkind (Original_Node (N)) = N_Op_Expon then
8866 Error_Msg_N
8867 ("\maybe '* was meant, rather than '*'*", Original_Node (N));
8868 end if;
8869 end if;
8870
8871 -- Dismiss generic types
8872
8873 if Is_Generic_Type (T)
8874 or else
8875 Is_Generic_Type (UT)
8876 or else
8877 Is_Generic_Type (Root_Type (UT))
8878 then
8879 return;
8880
8881 -- Guard against previous errors
8882
8883 elsif No (UT) or else UT = Any_Type then
8884 Check_Error_Detected;
8885 return;
8886
8887 -- Check case of bit packed array
8888
8889 elsif Is_Array_Type (UT)
8890 and then Known_Static_Component_Size (UT)
8891 and then Is_Bit_Packed_Array (UT)
8892 then
8893 declare
8894 Asiz : Uint;
8895 Indx : Node_Id;
8896 Ityp : Entity_Id;
8897
8898 begin
8899 Asiz := Component_Size (UT);
8900 Indx := First_Index (UT);
8901 loop
8902 Ityp := Etype (Indx);
8903
8904 -- If non-static bound, then we are not in the business of
8905 -- trying to check the length, and indeed an error will be
8906 -- issued elsewhere, since sizes of non-static array types
8907 -- cannot be set implicitly or explicitly.
8908
8909 if not Is_Static_Subtype (Ityp) then
8910 return;
8911 end if;
8912
8913 -- Otherwise accumulate next dimension
8914
8915 Asiz := Asiz * (Expr_Value (Type_High_Bound (Ityp)) -
8916 Expr_Value (Type_Low_Bound (Ityp)) +
8917 Uint_1);
8918
8919 Next_Index (Indx);
8920 exit when No (Indx);
8921 end loop;
8922
8923 if Asiz <= Siz then
8924 return;
8925
8926 else
8927 Error_Msg_Uint_1 := Asiz;
8928 Error_Msg_NE
8929 ("size for& too small, minimum allowed is ^", N, T);
8930 Set_Esize (T, Asiz);
8931 Set_RM_Size (T, Asiz);
8932 end if;
8933 end;
8934
8935 -- All other composite types are ignored
8936
8937 elsif Is_Composite_Type (UT) then
8938 return;
8939
8940 -- For fixed-point types, don't check minimum if type is not frozen,
8941 -- since we don't know all the characteristics of the type that can
8942 -- affect the size (e.g. a specified small) till freeze time.
8943
8944 elsif Is_Fixed_Point_Type (UT)
8945 and then not Is_Frozen (UT)
8946 then
8947 null;
8948
8949 -- Cases for which a minimum check is required
8950
8951 else
8952 -- Ignore if specified size is correct for the type
8953
8954 if Known_Esize (UT) and then Siz = Esize (UT) then
8955 return;
8956 end if;
8957
8958 -- Otherwise get minimum size
8959
8960 M := UI_From_Int (Minimum_Size (UT));
8961
8962 if Siz < M then
8963
8964 -- Size is less than minimum size, but one possibility remains
8965 -- that we can manage with the new size if we bias the type.
8966
8967 M := UI_From_Int (Minimum_Size (UT, Biased => True));
8968
8969 if Siz < M then
8970 Error_Msg_Uint_1 := M;
8971 Error_Msg_NE
8972 ("size for& too small, minimum allowed is ^", N, T);
8973 Set_Esize (T, M);
8974 Set_RM_Size (T, M);
8975 else
8976 Biased := True;
8977 end if;
8978 end if;
8979 end if;
8980 end Check_Size;
8981
8982 -------------------------
8983 -- Get_Alignment_Value --
8984 -------------------------
8985
8986 function Get_Alignment_Value (Expr : Node_Id) return Uint is
8987 Align : constant Uint := Static_Integer (Expr);
8988
8989 begin
8990 if Align = No_Uint then
8991 return No_Uint;
8992
8993 elsif Align <= 0 then
8994 Error_Msg_N ("alignment value must be positive", Expr);
8995 return No_Uint;
8996
8997 else
8998 for J in Int range 0 .. 64 loop
8999 declare
9000 M : constant Uint := Uint_2 ** J;
9001
9002 begin
9003 exit when M = Align;
9004
9005 if M > Align then
9006 Error_Msg_N
9007 ("alignment value must be power of 2", Expr);
9008 return No_Uint;
9009 end if;
9010 end;
9011 end loop;
9012
9013 return Align;
9014 end if;
9015 end Get_Alignment_Value;
9016
9017 -------------------------------------
9018 -- Inherit_Aspects_At_Freeze_Point --
9019 -------------------------------------
9020
9021 procedure Inherit_Aspects_At_Freeze_Point (Typ : Entity_Id) is
9022
9023 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9024 (Rep_Item : Node_Id) return Boolean;
9025 -- This routine checks if Rep_Item is either a pragma or an aspect
9026 -- specification node whose correponding pragma (if any) is present in
9027 -- the Rep Item chain of the entity it has been specified to.
9028
9029 --------------------------------------------------
9030 -- Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item --
9031 --------------------------------------------------
9032
9033 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9034 (Rep_Item : Node_Id) return Boolean
9035 is
9036 begin
9037 return Nkind (Rep_Item) = N_Pragma
9038 or else Present_In_Rep_Item
9039 (Entity (Rep_Item), Aspect_Rep_Item (Rep_Item));
9040 end Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item;
9041
9042 -- Start of processing for Inherit_Aspects_At_Freeze_Point
9043
9044 begin
9045 -- A representation item is either subtype-specific (Size and Alignment
9046 -- clauses) or type-related (all others). Subtype-specific aspects may
9047 -- differ for different subtypes of the same type (RM 13.1.8).
9048
9049 -- A derived type inherits each type-related representation aspect of
9050 -- its parent type that was directly specified before the declaration of
9051 -- the derived type (RM 13.1.15).
9052
9053 -- A derived subtype inherits each subtype-specific representation
9054 -- aspect of its parent subtype that was directly specified before the
9055 -- declaration of the derived type (RM 13.1.15).
9056
9057 -- The general processing involves inheriting a representation aspect
9058 -- from a parent type whenever the first rep item (aspect specification,
9059 -- attribute definition clause, pragma) corresponding to the given
9060 -- representation aspect in the rep item chain of Typ, if any, isn't
9061 -- directly specified to Typ but to one of its parents.
9062
9063 -- ??? Note that, for now, just a limited number of representation
9064 -- aspects have been inherited here so far. Many of them are
9065 -- still inherited in Sem_Ch3. This will be fixed soon. Here is
9066 -- a non- exhaustive list of aspects that likely also need to
9067 -- be moved to this routine: Alignment, Component_Alignment,
9068 -- Component_Size, Machine_Radix, Object_Size, Pack, Predicates,
9069 -- Preelaborable_Initialization, RM_Size and Small.
9070
9071 if Nkind (Parent (Typ)) = N_Private_Extension_Declaration then
9072 return;
9073 end if;
9074
9075 -- Ada_05/Ada_2005
9076
9077 if not Has_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005, False)
9078 and then Has_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005)
9079 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9080 (Get_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005))
9081 then
9082 Set_Is_Ada_2005_Only (Typ);
9083 end if;
9084
9085 -- Ada_12/Ada_2012
9086
9087 if not Has_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012, False)
9088 and then Has_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012)
9089 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9090 (Get_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012))
9091 then
9092 Set_Is_Ada_2012_Only (Typ);
9093 end if;
9094
9095 -- Atomic/Shared
9096
9097 if not Has_Rep_Item (Typ, Name_Atomic, Name_Shared, False)
9098 and then Has_Rep_Pragma (Typ, Name_Atomic, Name_Shared)
9099 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9100 (Get_Rep_Item (Typ, Name_Atomic, Name_Shared))
9101 then
9102 Set_Is_Atomic (Typ);
9103 Set_Treat_As_Volatile (Typ);
9104 Set_Is_Volatile (Typ);
9105 end if;
9106
9107 -- Default_Component_Value
9108
9109 if Is_Array_Type (Typ)
9110 and then Has_Rep_Item (Typ, Name_Default_Component_Value, False)
9111 and then Has_Rep_Item (Typ, Name_Default_Component_Value)
9112 then
9113 Set_Default_Aspect_Component_Value (Typ,
9114 Default_Aspect_Component_Value
9115 (Entity (Get_Rep_Item (Typ, Name_Default_Component_Value))));
9116 end if;
9117
9118 -- Default_Value
9119
9120 if Is_Scalar_Type (Typ)
9121 and then Has_Rep_Item (Typ, Name_Default_Value, False)
9122 and then Has_Rep_Item (Typ, Name_Default_Value)
9123 then
9124 Set_Default_Aspect_Value (Typ,
9125 Default_Aspect_Value
9126 (Entity (Get_Rep_Item (Typ, Name_Default_Value))));
9127 end if;
9128
9129 -- Discard_Names
9130
9131 if not Has_Rep_Item (Typ, Name_Discard_Names, False)
9132 and then Has_Rep_Item (Typ, Name_Discard_Names)
9133 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9134 (Get_Rep_Item (Typ, Name_Discard_Names))
9135 then
9136 Set_Discard_Names (Typ);
9137 end if;
9138
9139 -- Invariants
9140
9141 if not Has_Rep_Item (Typ, Name_Invariant, False)
9142 and then Has_Rep_Item (Typ, Name_Invariant)
9143 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9144 (Get_Rep_Item (Typ, Name_Invariant))
9145 then
9146 Set_Has_Invariants (Typ);
9147
9148 if Class_Present (Get_Rep_Item (Typ, Name_Invariant)) then
9149 Set_Has_Inheritable_Invariants (Typ);
9150 end if;
9151 end if;
9152
9153 -- Volatile
9154
9155 if not Has_Rep_Item (Typ, Name_Volatile, False)
9156 and then Has_Rep_Item (Typ, Name_Volatile)
9157 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9158 (Get_Rep_Item (Typ, Name_Volatile))
9159 then
9160 Set_Treat_As_Volatile (Typ);
9161 Set_Is_Volatile (Typ);
9162 end if;
9163
9164 -- Inheritance for derived types only
9165
9166 if Is_Derived_Type (Typ) then
9167 declare
9168 Bas_Typ : constant Entity_Id := Base_Type (Typ);
9169 Imp_Bas_Typ : constant Entity_Id := Implementation_Base_Type (Typ);
9170
9171 begin
9172 -- Atomic_Components
9173
9174 if not Has_Rep_Item (Typ, Name_Atomic_Components, False)
9175 and then Has_Rep_Item (Typ, Name_Atomic_Components)
9176 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9177 (Get_Rep_Item (Typ, Name_Atomic_Components))
9178 then
9179 Set_Has_Atomic_Components (Imp_Bas_Typ);
9180 end if;
9181
9182 -- Volatile_Components
9183
9184 if not Has_Rep_Item (Typ, Name_Volatile_Components, False)
9185 and then Has_Rep_Item (Typ, Name_Volatile_Components)
9186 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9187 (Get_Rep_Item (Typ, Name_Volatile_Components))
9188 then
9189 Set_Has_Volatile_Components (Imp_Bas_Typ);
9190 end if;
9191
9192 -- Finalize_Storage_Only.
9193
9194 if not Has_Rep_Pragma (Typ, Name_Finalize_Storage_Only, False)
9195 and then Has_Rep_Pragma (Typ, Name_Finalize_Storage_Only)
9196 then
9197 Set_Finalize_Storage_Only (Bas_Typ);
9198 end if;
9199
9200 -- Universal_Aliasing
9201
9202 if not Has_Rep_Item (Typ, Name_Universal_Aliasing, False)
9203 and then Has_Rep_Item (Typ, Name_Universal_Aliasing)
9204 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9205 (Get_Rep_Item (Typ, Name_Universal_Aliasing))
9206 then
9207 Set_Universal_Aliasing (Imp_Bas_Typ);
9208 end if;
9209
9210 -- Record type specific aspects
9211
9212 if Is_Record_Type (Typ) then
9213
9214 -- Bit_Order
9215
9216 if not Has_Rep_Item (Typ, Name_Bit_Order, False)
9217 and then Has_Rep_Item (Typ, Name_Bit_Order)
9218 then
9219 Set_Reverse_Bit_Order (Bas_Typ,
9220 Reverse_Bit_Order (Entity (Name
9221 (Get_Rep_Item (Typ, Name_Bit_Order)))));
9222 end if;
9223
9224 -- Scalar_Storage_Order
9225
9226 if not Has_Rep_Item (Typ, Name_Scalar_Storage_Order, False)
9227 and then Has_Rep_Item (Typ, Name_Scalar_Storage_Order)
9228 then
9229 Set_Reverse_Storage_Order (Bas_Typ,
9230 Reverse_Storage_Order (Entity (Name
9231 (Get_Rep_Item (Typ, Name_Scalar_Storage_Order)))));
9232 end if;
9233 end if;
9234 end;
9235 end if;
9236 end Inherit_Aspects_At_Freeze_Point;
9237
9238 ----------------
9239 -- Initialize --
9240 ----------------
9241
9242 procedure Initialize is
9243 begin
9244 Address_Clause_Checks.Init;
9245 Independence_Checks.Init;
9246 Unchecked_Conversions.Init;
9247 end Initialize;
9248
9249 -------------------------
9250 -- Is_Operational_Item --
9251 -------------------------
9252
9253 function Is_Operational_Item (N : Node_Id) return Boolean is
9254 begin
9255 if Nkind (N) /= N_Attribute_Definition_Clause then
9256 return False;
9257
9258 else
9259 declare
9260 Id : constant Attribute_Id := Get_Attribute_Id (Chars (N));
9261 begin
9262 return Id = Attribute_Input
9263 or else Id = Attribute_Output
9264 or else Id = Attribute_Read
9265 or else Id = Attribute_Write
9266 or else Id = Attribute_External_Tag;
9267 end;
9268 end if;
9269 end Is_Operational_Item;
9270
9271 ------------------
9272 -- Minimum_Size --
9273 ------------------
9274
9275 function Minimum_Size
9276 (T : Entity_Id;
9277 Biased : Boolean := False) return Nat
9278 is
9279 Lo : Uint := No_Uint;
9280 Hi : Uint := No_Uint;
9281 LoR : Ureal := No_Ureal;
9282 HiR : Ureal := No_Ureal;
9283 LoSet : Boolean := False;
9284 HiSet : Boolean := False;
9285 B : Uint;
9286 S : Nat;
9287 Ancest : Entity_Id;
9288 R_Typ : constant Entity_Id := Root_Type (T);
9289
9290 begin
9291 -- If bad type, return 0
9292
9293 if T = Any_Type then
9294 return 0;
9295
9296 -- For generic types, just return zero. There cannot be any legitimate
9297 -- need to know such a size, but this routine may be called with a
9298 -- generic type as part of normal processing.
9299
9300 elsif Is_Generic_Type (R_Typ)
9301 or else R_Typ = Any_Type
9302 then
9303 return 0;
9304
9305 -- Access types. Normally an access type cannot have a size smaller
9306 -- than the size of System.Address. The exception is on VMS, where
9307 -- we have short and long addresses, and it is possible for an access
9308 -- type to have a short address size (and thus be less than the size
9309 -- of System.Address itself). We simply skip the check for VMS, and
9310 -- leave it to the back end to do the check.
9311
9312 elsif Is_Access_Type (T) then
9313 if OpenVMS_On_Target then
9314 return 0;
9315 else
9316 return System_Address_Size;
9317 end if;
9318
9319 -- Floating-point types
9320
9321 elsif Is_Floating_Point_Type (T) then
9322 return UI_To_Int (Esize (R_Typ));
9323
9324 -- Discrete types
9325
9326 elsif Is_Discrete_Type (T) then
9327
9328 -- The following loop is looking for the nearest compile time known
9329 -- bounds following the ancestor subtype chain. The idea is to find
9330 -- the most restrictive known bounds information.
9331
9332 Ancest := T;
9333 loop
9334 if Ancest = Any_Type or else Etype (Ancest) = Any_Type then
9335 return 0;
9336 end if;
9337
9338 if not LoSet then
9339 if Compile_Time_Known_Value (Type_Low_Bound (Ancest)) then
9340 Lo := Expr_Rep_Value (Type_Low_Bound (Ancest));
9341 LoSet := True;
9342 exit when HiSet;
9343 end if;
9344 end if;
9345
9346 if not HiSet then
9347 if Compile_Time_Known_Value (Type_High_Bound (Ancest)) then
9348 Hi := Expr_Rep_Value (Type_High_Bound (Ancest));
9349 HiSet := True;
9350 exit when LoSet;
9351 end if;
9352 end if;
9353
9354 Ancest := Ancestor_Subtype (Ancest);
9355
9356 if No (Ancest) then
9357 Ancest := Base_Type (T);
9358
9359 if Is_Generic_Type (Ancest) then
9360 return 0;
9361 end if;
9362 end if;
9363 end loop;
9364
9365 -- Fixed-point types. We can't simply use Expr_Value to get the
9366 -- Corresponding_Integer_Value values of the bounds, since these do not
9367 -- get set till the type is frozen, and this routine can be called
9368 -- before the type is frozen. Similarly the test for bounds being static
9369 -- needs to include the case where we have unanalyzed real literals for
9370 -- the same reason.
9371
9372 elsif Is_Fixed_Point_Type (T) then
9373
9374 -- The following loop is looking for the nearest compile time known
9375 -- bounds following the ancestor subtype chain. The idea is to find
9376 -- the most restrictive known bounds information.
9377
9378 Ancest := T;
9379 loop
9380 if Ancest = Any_Type or else Etype (Ancest) = Any_Type then
9381 return 0;
9382 end if;
9383
9384 -- Note: In the following two tests for LoSet and HiSet, it may
9385 -- seem redundant to test for N_Real_Literal here since normally
9386 -- one would assume that the test for the value being known at
9387 -- compile time includes this case. However, there is a glitch.
9388 -- If the real literal comes from folding a non-static expression,
9389 -- then we don't consider any non- static expression to be known
9390 -- at compile time if we are in configurable run time mode (needed
9391 -- in some cases to give a clearer definition of what is and what
9392 -- is not accepted). So the test is indeed needed. Without it, we
9393 -- would set neither Lo_Set nor Hi_Set and get an infinite loop.
9394
9395 if not LoSet then
9396 if Nkind (Type_Low_Bound (Ancest)) = N_Real_Literal
9397 or else Compile_Time_Known_Value (Type_Low_Bound (Ancest))
9398 then
9399 LoR := Expr_Value_R (Type_Low_Bound (Ancest));
9400 LoSet := True;
9401 exit when HiSet;
9402 end if;
9403 end if;
9404
9405 if not HiSet then
9406 if Nkind (Type_High_Bound (Ancest)) = N_Real_Literal
9407 or else Compile_Time_Known_Value (Type_High_Bound (Ancest))
9408 then
9409 HiR := Expr_Value_R (Type_High_Bound (Ancest));
9410 HiSet := True;
9411 exit when LoSet;
9412 end if;
9413 end if;
9414
9415 Ancest := Ancestor_Subtype (Ancest);
9416
9417 if No (Ancest) then
9418 Ancest := Base_Type (T);
9419
9420 if Is_Generic_Type (Ancest) then
9421 return 0;
9422 end if;
9423 end if;
9424 end loop;
9425
9426 Lo := UR_To_Uint (LoR / Small_Value (T));
9427 Hi := UR_To_Uint (HiR / Small_Value (T));
9428
9429 -- No other types allowed
9430
9431 else
9432 raise Program_Error;
9433 end if;
9434
9435 -- Fall through with Hi and Lo set. Deal with biased case
9436
9437 if (Biased
9438 and then not Is_Fixed_Point_Type (T)
9439 and then not (Is_Enumeration_Type (T)
9440 and then Has_Non_Standard_Rep (T)))
9441 or else Has_Biased_Representation (T)
9442 then
9443 Hi := Hi - Lo;
9444 Lo := Uint_0;
9445 end if;
9446
9447 -- Signed case. Note that we consider types like range 1 .. -1 to be
9448 -- signed for the purpose of computing the size, since the bounds have
9449 -- to be accommodated in the base type.
9450
9451 if Lo < 0 or else Hi < 0 then
9452 S := 1;
9453 B := Uint_1;
9454
9455 -- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1))
9456 -- Note that we accommodate the case where the bounds cross. This
9457 -- can happen either because of the way the bounds are declared
9458 -- or because of the algorithm in Freeze_Fixed_Point_Type.
9459
9460 while Lo < -B
9461 or else Hi < -B
9462 or else Lo >= B
9463 or else Hi >= B
9464 loop
9465 B := Uint_2 ** S;
9466 S := S + 1;
9467 end loop;
9468
9469 -- Unsigned case
9470
9471 else
9472 -- If both bounds are positive, make sure that both are represen-
9473 -- table in the case where the bounds are crossed. This can happen
9474 -- either because of the way the bounds are declared, or because of
9475 -- the algorithm in Freeze_Fixed_Point_Type.
9476
9477 if Lo > Hi then
9478 Hi := Lo;
9479 end if;
9480
9481 -- S = size, (can accommodate 0 .. (2**size - 1))
9482
9483 S := 0;
9484 while Hi >= Uint_2 ** S loop
9485 S := S + 1;
9486 end loop;
9487 end if;
9488
9489 return S;
9490 end Minimum_Size;
9491
9492 ---------------------------
9493 -- New_Stream_Subprogram --
9494 ---------------------------
9495
9496 procedure New_Stream_Subprogram
9497 (N : Node_Id;
9498 Ent : Entity_Id;
9499 Subp : Entity_Id;
9500 Nam : TSS_Name_Type)
9501 is
9502 Loc : constant Source_Ptr := Sloc (N);
9503 Sname : constant Name_Id := Make_TSS_Name (Base_Type (Ent), Nam);
9504 Subp_Id : Entity_Id;
9505 Subp_Decl : Node_Id;
9506 F : Entity_Id;
9507 Etyp : Entity_Id;
9508
9509 Defer_Declaration : constant Boolean :=
9510 Is_Tagged_Type (Ent) or else Is_Private_Type (Ent);
9511 -- For a tagged type, there is a declaration for each stream attribute
9512 -- at the freeze point, and we must generate only a completion of this
9513 -- declaration. We do the same for private types, because the full view
9514 -- might be tagged. Otherwise we generate a declaration at the point of
9515 -- the attribute definition clause.
9516
9517 function Build_Spec return Node_Id;
9518 -- Used for declaration and renaming declaration, so that this is
9519 -- treated as a renaming_as_body.
9520
9521 ----------------
9522 -- Build_Spec --
9523 ----------------
9524
9525 function Build_Spec return Node_Id is
9526 Out_P : constant Boolean := (Nam = TSS_Stream_Read);
9527 Formals : List_Id;
9528 Spec : Node_Id;
9529 T_Ref : constant Node_Id := New_Reference_To (Etyp, Loc);
9530
9531 begin
9532 Subp_Id := Make_Defining_Identifier (Loc, Sname);
9533
9534 -- S : access Root_Stream_Type'Class
9535
9536 Formals := New_List (
9537 Make_Parameter_Specification (Loc,
9538 Defining_Identifier =>
9539 Make_Defining_Identifier (Loc, Name_S),
9540 Parameter_Type =>
9541 Make_Access_Definition (Loc,
9542 Subtype_Mark =>
9543 New_Reference_To (
9544 Designated_Type (Etype (F)), Loc))));
9545
9546 if Nam = TSS_Stream_Input then
9547 Spec :=
9548 Make_Function_Specification (Loc,
9549 Defining_Unit_Name => Subp_Id,
9550 Parameter_Specifications => Formals,
9551 Result_Definition => T_Ref);
9552 else
9553 -- V : [out] T
9554
9555 Append_To (Formals,
9556 Make_Parameter_Specification (Loc,
9557 Defining_Identifier => Make_Defining_Identifier (Loc, Name_V),
9558 Out_Present => Out_P,
9559 Parameter_Type => T_Ref));
9560
9561 Spec :=
9562 Make_Procedure_Specification (Loc,
9563 Defining_Unit_Name => Subp_Id,
9564 Parameter_Specifications => Formals);
9565 end if;
9566
9567 return Spec;
9568 end Build_Spec;
9569
9570 -- Start of processing for New_Stream_Subprogram
9571
9572 begin
9573 F := First_Formal (Subp);
9574
9575 if Ekind (Subp) = E_Procedure then
9576 Etyp := Etype (Next_Formal (F));
9577 else
9578 Etyp := Etype (Subp);
9579 end if;
9580
9581 -- Prepare subprogram declaration and insert it as an action on the
9582 -- clause node. The visibility for this entity is used to test for
9583 -- visibility of the attribute definition clause (in the sense of
9584 -- 8.3(23) as amended by AI-195).
9585
9586 if not Defer_Declaration then
9587 Subp_Decl :=
9588 Make_Subprogram_Declaration (Loc,
9589 Specification => Build_Spec);
9590
9591 -- For a tagged type, there is always a visible declaration for each
9592 -- stream TSS (it is a predefined primitive operation), and the
9593 -- completion of this declaration occurs at the freeze point, which is
9594 -- not always visible at places where the attribute definition clause is
9595 -- visible. So, we create a dummy entity here for the purpose of
9596 -- tracking the visibility of the attribute definition clause itself.
9597
9598 else
9599 Subp_Id :=
9600 Make_Defining_Identifier (Loc, New_External_Name (Sname, 'V'));
9601 Subp_Decl :=
9602 Make_Object_Declaration (Loc,
9603 Defining_Identifier => Subp_Id,
9604 Object_Definition => New_Occurrence_Of (Standard_Boolean, Loc));
9605 end if;
9606
9607 Insert_Action (N, Subp_Decl);
9608 Set_Entity (N, Subp_Id);
9609
9610 Subp_Decl :=
9611 Make_Subprogram_Renaming_Declaration (Loc,
9612 Specification => Build_Spec,
9613 Name => New_Reference_To (Subp, Loc));
9614
9615 if Defer_Declaration then
9616 Set_TSS (Base_Type (Ent), Subp_Id);
9617 else
9618 Insert_Action (N, Subp_Decl);
9619 Copy_TSS (Subp_Id, Base_Type (Ent));
9620 end if;
9621 end New_Stream_Subprogram;
9622
9623 ------------------------
9624 -- Rep_Item_Too_Early --
9625 ------------------------
9626
9627 function Rep_Item_Too_Early (T : Entity_Id; N : Node_Id) return Boolean is
9628 begin
9629 -- Cannot apply non-operational rep items to generic types
9630
9631 if Is_Operational_Item (N) then
9632 return False;
9633
9634 elsif Is_Type (T)
9635 and then Is_Generic_Type (Root_Type (T))
9636 then
9637 Error_Msg_N ("representation item not allowed for generic type", N);
9638 return True;
9639 end if;
9640
9641 -- Otherwise check for incomplete type
9642
9643 if Is_Incomplete_Or_Private_Type (T)
9644 and then No (Underlying_Type (T))
9645 and then
9646 (Nkind (N) /= N_Pragma
9647 or else Get_Pragma_Id (N) /= Pragma_Import)
9648 then
9649 Error_Msg_N
9650 ("representation item must be after full type declaration", N);
9651 return True;
9652
9653 -- If the type has incomplete components, a representation clause is
9654 -- illegal but stream attributes and Convention pragmas are correct.
9655
9656 elsif Has_Private_Component (T) then
9657 if Nkind (N) = N_Pragma then
9658 return False;
9659
9660 else
9661 Error_Msg_N
9662 ("representation item must appear after type is fully defined",
9663 N);
9664 return True;
9665 end if;
9666 else
9667 return False;
9668 end if;
9669 end Rep_Item_Too_Early;
9670
9671 -----------------------
9672 -- Rep_Item_Too_Late --
9673 -----------------------
9674
9675 function Rep_Item_Too_Late
9676 (T : Entity_Id;
9677 N : Node_Id;
9678 FOnly : Boolean := False) return Boolean
9679 is
9680 S : Entity_Id;
9681 Parent_Type : Entity_Id;
9682
9683 procedure Too_Late;
9684 -- Output the too late message. Note that this is not considered a
9685 -- serious error, since the effect is simply that we ignore the
9686 -- representation clause in this case.
9687
9688 --------------
9689 -- Too_Late --
9690 --------------
9691
9692 procedure Too_Late is
9693 begin
9694 -- Other compilers seem more relaxed about rep items appearing too
9695 -- late. Since analysis tools typically don't care about rep items
9696 -- anyway, no reason to be too strict about this.
9697
9698 if not Relaxed_RM_Semantics then
9699 Error_Msg_N ("|representation item appears too late!", N);
9700 end if;
9701 end Too_Late;
9702
9703 -- Start of processing for Rep_Item_Too_Late
9704
9705 begin
9706 -- First make sure entity is not frozen (RM 13.1(9))
9707
9708 if Is_Frozen (T)
9709
9710 -- Exclude imported types, which may be frozen if they appear in a
9711 -- representation clause for a local type.
9712
9713 and then not From_With_Type (T)
9714
9715 -- Exclude generated entities (not coming from source). The common
9716 -- case is when we generate a renaming which prematurely freezes the
9717 -- renamed internal entity, but we still want to be able to set copies
9718 -- of attribute values such as Size/Alignment.
9719
9720 and then Comes_From_Source (T)
9721 then
9722 Too_Late;
9723 S := First_Subtype (T);
9724
9725 if Present (Freeze_Node (S)) then
9726 Error_Msg_NE
9727 ("??no more representation items for }", Freeze_Node (S), S);
9728 end if;
9729
9730 return True;
9731
9732 -- Check for case of non-tagged derived type whose parent either has
9733 -- primitive operations, or is a by reference type (RM 13.1(10)).
9734
9735 elsif Is_Type (T)
9736 and then not FOnly
9737 and then Is_Derived_Type (T)
9738 and then not Is_Tagged_Type (T)
9739 then
9740 Parent_Type := Etype (Base_Type (T));
9741
9742 if Has_Primitive_Operations (Parent_Type) then
9743 Too_Late;
9744 Error_Msg_NE
9745 ("primitive operations already defined for&!", N, Parent_Type);
9746 return True;
9747
9748 elsif Is_By_Reference_Type (Parent_Type) then
9749 Too_Late;
9750 Error_Msg_NE
9751 ("parent type & is a by reference type!", N, Parent_Type);
9752 return True;
9753 end if;
9754 end if;
9755
9756 -- No error, link item into head of chain of rep items for the entity,
9757 -- but avoid chaining if we have an overloadable entity, and the pragma
9758 -- is one that can apply to multiple overloaded entities.
9759
9760 if Is_Overloadable (T) and then Nkind (N) = N_Pragma then
9761 declare
9762 Pname : constant Name_Id := Pragma_Name (N);
9763 begin
9764 if Nam_In (Pname, Name_Convention, Name_Import, Name_Export,
9765 Name_External, Name_Interface)
9766 then
9767 return False;
9768 end if;
9769 end;
9770 end if;
9771
9772 Record_Rep_Item (T, N);
9773 return False;
9774 end Rep_Item_Too_Late;
9775
9776 -------------------------------------
9777 -- Replace_Type_References_Generic --
9778 -------------------------------------
9779
9780 procedure Replace_Type_References_Generic (N : Node_Id; TName : Name_Id) is
9781
9782 function Replace_Node (N : Node_Id) return Traverse_Result;
9783 -- Processes a single node in the traversal procedure below, checking
9784 -- if node N should be replaced, and if so, doing the replacement.
9785
9786 procedure Replace_Type_Refs is new Traverse_Proc (Replace_Node);
9787 -- This instantiation provides the body of Replace_Type_References
9788
9789 ------------------
9790 -- Replace_Node --
9791 ------------------
9792
9793 function Replace_Node (N : Node_Id) return Traverse_Result is
9794 S : Entity_Id;
9795 P : Node_Id;
9796
9797 begin
9798 -- Case of identifier
9799
9800 if Nkind (N) = N_Identifier then
9801
9802 -- If not the type name, all done with this node
9803
9804 if Chars (N) /= TName then
9805 return Skip;
9806
9807 -- Otherwise do the replacement and we are done with this node
9808
9809 else
9810 Replace_Type_Reference (N);
9811 return Skip;
9812 end if;
9813
9814 -- Case of selected component (which is what a qualification
9815 -- looks like in the unanalyzed tree, which is what we have.
9816
9817 elsif Nkind (N) = N_Selected_Component then
9818
9819 -- If selector name is not our type, keeping going (we might
9820 -- still have an occurrence of the type in the prefix).
9821
9822 if Nkind (Selector_Name (N)) /= N_Identifier
9823 or else Chars (Selector_Name (N)) /= TName
9824 then
9825 return OK;
9826
9827 -- Selector name is our type, check qualification
9828
9829 else
9830 -- Loop through scopes and prefixes, doing comparison
9831
9832 S := Current_Scope;
9833 P := Prefix (N);
9834 loop
9835 -- Continue if no more scopes or scope with no name
9836
9837 if No (S) or else Nkind (S) not in N_Has_Chars then
9838 return OK;
9839 end if;
9840
9841 -- Do replace if prefix is an identifier matching the
9842 -- scope that we are currently looking at.
9843
9844 if Nkind (P) = N_Identifier
9845 and then Chars (P) = Chars (S)
9846 then
9847 Replace_Type_Reference (N);
9848 return Skip;
9849 end if;
9850
9851 -- Go check scope above us if prefix is itself of the
9852 -- form of a selected component, whose selector matches
9853 -- the scope we are currently looking at.
9854
9855 if Nkind (P) = N_Selected_Component
9856 and then Nkind (Selector_Name (P)) = N_Identifier
9857 and then Chars (Selector_Name (P)) = Chars (S)
9858 then
9859 S := Scope (S);
9860 P := Prefix (P);
9861
9862 -- For anything else, we don't have a match, so keep on
9863 -- going, there are still some weird cases where we may
9864 -- still have a replacement within the prefix.
9865
9866 else
9867 return OK;
9868 end if;
9869 end loop;
9870 end if;
9871
9872 -- Continue for any other node kind
9873
9874 else
9875 return OK;
9876 end if;
9877 end Replace_Node;
9878
9879 begin
9880 Replace_Type_Refs (N);
9881 end Replace_Type_References_Generic;
9882
9883 -------------------------
9884 -- Same_Representation --
9885 -------------------------
9886
9887 function Same_Representation (Typ1, Typ2 : Entity_Id) return Boolean is
9888 T1 : constant Entity_Id := Underlying_Type (Typ1);
9889 T2 : constant Entity_Id := Underlying_Type (Typ2);
9890
9891 begin
9892 -- A quick check, if base types are the same, then we definitely have
9893 -- the same representation, because the subtype specific representation
9894 -- attributes (Size and Alignment) do not affect representation from
9895 -- the point of view of this test.
9896
9897 if Base_Type (T1) = Base_Type (T2) then
9898 return True;
9899
9900 elsif Is_Private_Type (Base_Type (T2))
9901 and then Base_Type (T1) = Full_View (Base_Type (T2))
9902 then
9903 return True;
9904 end if;
9905
9906 -- Tagged types never have differing representations
9907
9908 if Is_Tagged_Type (T1) then
9909 return True;
9910 end if;
9911
9912 -- Representations are definitely different if conventions differ
9913
9914 if Convention (T1) /= Convention (T2) then
9915 return False;
9916 end if;
9917
9918 -- Representations are different if component alignments or scalar
9919 -- storage orders differ.
9920
9921 if (Is_Record_Type (T1) or else Is_Array_Type (T1))
9922 and then
9923 (Is_Record_Type (T2) or else Is_Array_Type (T2))
9924 and then
9925 (Component_Alignment (T1) /= Component_Alignment (T2)
9926 or else
9927 Reverse_Storage_Order (T1) /= Reverse_Storage_Order (T2))
9928 then
9929 return False;
9930 end if;
9931
9932 -- For arrays, the only real issue is component size. If we know the
9933 -- component size for both arrays, and it is the same, then that's
9934 -- good enough to know we don't have a change of representation.
9935
9936 if Is_Array_Type (T1) then
9937 if Known_Component_Size (T1)
9938 and then Known_Component_Size (T2)
9939 and then Component_Size (T1) = Component_Size (T2)
9940 then
9941 if VM_Target = No_VM then
9942 return True;
9943
9944 -- In VM targets the representation of arrays with aliased
9945 -- components differs from arrays with non-aliased components
9946
9947 else
9948 return Has_Aliased_Components (Base_Type (T1))
9949 =
9950 Has_Aliased_Components (Base_Type (T2));
9951 end if;
9952 end if;
9953 end if;
9954
9955 -- Types definitely have same representation if neither has non-standard
9956 -- representation since default representations are always consistent.
9957 -- If only one has non-standard representation, and the other does not,
9958 -- then we consider that they do not have the same representation. They
9959 -- might, but there is no way of telling early enough.
9960
9961 if Has_Non_Standard_Rep (T1) then
9962 if not Has_Non_Standard_Rep (T2) then
9963 return False;
9964 end if;
9965 else
9966 return not Has_Non_Standard_Rep (T2);
9967 end if;
9968
9969 -- Here the two types both have non-standard representation, and we need
9970 -- to determine if they have the same non-standard representation.
9971
9972 -- For arrays, we simply need to test if the component sizes are the
9973 -- same. Pragma Pack is reflected in modified component sizes, so this
9974 -- check also deals with pragma Pack.
9975
9976 if Is_Array_Type (T1) then
9977 return Component_Size (T1) = Component_Size (T2);
9978
9979 -- Tagged types always have the same representation, because it is not
9980 -- possible to specify different representations for common fields.
9981
9982 elsif Is_Tagged_Type (T1) then
9983 return True;
9984
9985 -- Case of record types
9986
9987 elsif Is_Record_Type (T1) then
9988
9989 -- Packed status must conform
9990
9991 if Is_Packed (T1) /= Is_Packed (T2) then
9992 return False;
9993
9994 -- Otherwise we must check components. Typ2 maybe a constrained
9995 -- subtype with fewer components, so we compare the components
9996 -- of the base types.
9997
9998 else
9999 Record_Case : declare
10000 CD1, CD2 : Entity_Id;
10001
10002 function Same_Rep return Boolean;
10003 -- CD1 and CD2 are either components or discriminants. This
10004 -- function tests whether they have the same representation.
10005
10006 --------------
10007 -- Same_Rep --
10008 --------------
10009
10010 function Same_Rep return Boolean is
10011 begin
10012 if No (Component_Clause (CD1)) then
10013 return No (Component_Clause (CD2));
10014 else
10015 -- Note: at this point, component clauses have been
10016 -- normalized to the default bit order, so that the
10017 -- comparison of Component_Bit_Offsets is meaningful.
10018
10019 return
10020 Present (Component_Clause (CD2))
10021 and then
10022 Component_Bit_Offset (CD1) = Component_Bit_Offset (CD2)
10023 and then
10024 Esize (CD1) = Esize (CD2);
10025 end if;
10026 end Same_Rep;
10027
10028 -- Start of processing for Record_Case
10029
10030 begin
10031 if Has_Discriminants (T1) then
10032
10033 -- The number of discriminants may be different if the
10034 -- derived type has fewer (constrained by values). The
10035 -- invisible discriminants retain the representation of
10036 -- the original, so the discrepancy does not per se
10037 -- indicate a different representation.
10038
10039 CD1 := First_Discriminant (T1);
10040 CD2 := First_Discriminant (T2);
10041 while Present (CD1) and then Present (CD2) loop
10042 if not Same_Rep then
10043 return False;
10044 else
10045 Next_Discriminant (CD1);
10046 Next_Discriminant (CD2);
10047 end if;
10048 end loop;
10049 end if;
10050
10051 CD1 := First_Component (Underlying_Type (Base_Type (T1)));
10052 CD2 := First_Component (Underlying_Type (Base_Type (T2)));
10053 while Present (CD1) loop
10054 if not Same_Rep then
10055 return False;
10056 else
10057 Next_Component (CD1);
10058 Next_Component (CD2);
10059 end if;
10060 end loop;
10061
10062 return True;
10063 end Record_Case;
10064 end if;
10065
10066 -- For enumeration types, we must check each literal to see if the
10067 -- representation is the same. Note that we do not permit enumeration
10068 -- representation clauses for Character and Wide_Character, so these
10069 -- cases were already dealt with.
10070
10071 elsif Is_Enumeration_Type (T1) then
10072 Enumeration_Case : declare
10073 L1, L2 : Entity_Id;
10074
10075 begin
10076 L1 := First_Literal (T1);
10077 L2 := First_Literal (T2);
10078 while Present (L1) loop
10079 if Enumeration_Rep (L1) /= Enumeration_Rep (L2) then
10080 return False;
10081 else
10082 Next_Literal (L1);
10083 Next_Literal (L2);
10084 end if;
10085 end loop;
10086
10087 return True;
10088 end Enumeration_Case;
10089
10090 -- Any other types have the same representation for these purposes
10091
10092 else
10093 return True;
10094 end if;
10095 end Same_Representation;
10096
10097 ----------------
10098 -- Set_Biased --
10099 ----------------
10100
10101 procedure Set_Biased
10102 (E : Entity_Id;
10103 N : Node_Id;
10104 Msg : String;
10105 Biased : Boolean := True)
10106 is
10107 begin
10108 if Biased then
10109 Set_Has_Biased_Representation (E);
10110
10111 if Warn_On_Biased_Representation then
10112 Error_Msg_NE
10113 ("?B?" & Msg & " forces biased representation for&", N, E);
10114 end if;
10115 end if;
10116 end Set_Biased;
10117
10118 --------------------
10119 -- Set_Enum_Esize --
10120 --------------------
10121
10122 procedure Set_Enum_Esize (T : Entity_Id) is
10123 Lo : Uint;
10124 Hi : Uint;
10125 Sz : Nat;
10126
10127 begin
10128 Init_Alignment (T);
10129
10130 -- Find the minimum standard size (8,16,32,64) that fits
10131
10132 Lo := Enumeration_Rep (Entity (Type_Low_Bound (T)));
10133 Hi := Enumeration_Rep (Entity (Type_High_Bound (T)));
10134
10135 if Lo < 0 then
10136 if Lo >= -Uint_2**07 and then Hi < Uint_2**07 then
10137 Sz := Standard_Character_Size; -- May be > 8 on some targets
10138
10139 elsif Lo >= -Uint_2**15 and then Hi < Uint_2**15 then
10140 Sz := 16;
10141
10142 elsif Lo >= -Uint_2**31 and then Hi < Uint_2**31 then
10143 Sz := 32;
10144
10145 else pragma Assert (Lo >= -Uint_2**63 and then Hi < Uint_2**63);
10146 Sz := 64;
10147 end if;
10148
10149 else
10150 if Hi < Uint_2**08 then
10151 Sz := Standard_Character_Size; -- May be > 8 on some targets
10152
10153 elsif Hi < Uint_2**16 then
10154 Sz := 16;
10155
10156 elsif Hi < Uint_2**32 then
10157 Sz := 32;
10158
10159 else pragma Assert (Hi < Uint_2**63);
10160 Sz := 64;
10161 end if;
10162 end if;
10163
10164 -- That minimum is the proper size unless we have a foreign convention
10165 -- and the size required is 32 or less, in which case we bump the size
10166 -- up to 32. This is required for C and C++ and seems reasonable for
10167 -- all other foreign conventions.
10168
10169 if Has_Foreign_Convention (T)
10170 and then Esize (T) < Standard_Integer_Size
10171 then
10172 Init_Esize (T, Standard_Integer_Size);
10173 else
10174 Init_Esize (T, Sz);
10175 end if;
10176 end Set_Enum_Esize;
10177
10178 ------------------------------
10179 -- Validate_Address_Clauses --
10180 ------------------------------
10181
10182 procedure Validate_Address_Clauses is
10183 begin
10184 for J in Address_Clause_Checks.First .. Address_Clause_Checks.Last loop
10185 declare
10186 ACCR : Address_Clause_Check_Record
10187 renames Address_Clause_Checks.Table (J);
10188
10189 Expr : Node_Id;
10190
10191 X_Alignment : Uint;
10192 Y_Alignment : Uint;
10193
10194 X_Size : Uint;
10195 Y_Size : Uint;
10196
10197 begin
10198 -- Skip processing of this entry if warning already posted
10199
10200 if not Address_Warning_Posted (ACCR.N) then
10201 Expr := Original_Node (Expression (ACCR.N));
10202
10203 -- Get alignments
10204
10205 X_Alignment := Alignment (ACCR.X);
10206 Y_Alignment := Alignment (ACCR.Y);
10207
10208 -- Similarly obtain sizes
10209
10210 X_Size := Esize (ACCR.X);
10211 Y_Size := Esize (ACCR.Y);
10212
10213 -- Check for large object overlaying smaller one
10214
10215 if Y_Size > Uint_0
10216 and then X_Size > Uint_0
10217 and then X_Size > Y_Size
10218 then
10219 Error_Msg_NE
10220 ("?& overlays smaller object", ACCR.N, ACCR.X);
10221 Error_Msg_N
10222 ("\??program execution may be erroneous", ACCR.N);
10223 Error_Msg_Uint_1 := X_Size;
10224 Error_Msg_NE
10225 ("\??size of & is ^", ACCR.N, ACCR.X);
10226 Error_Msg_Uint_1 := Y_Size;
10227 Error_Msg_NE
10228 ("\??size of & is ^", ACCR.N, ACCR.Y);
10229
10230 -- Check for inadequate alignment, both of the base object
10231 -- and of the offset, if any.
10232
10233 -- Note: we do not check the alignment if we gave a size
10234 -- warning, since it would likely be redundant.
10235
10236 elsif Y_Alignment /= Uint_0
10237 and then (Y_Alignment < X_Alignment
10238 or else (ACCR.Off
10239 and then
10240 Nkind (Expr) = N_Attribute_Reference
10241 and then
10242 Attribute_Name (Expr) = Name_Address
10243 and then
10244 Has_Compatible_Alignment
10245 (ACCR.X, Prefix (Expr))
10246 /= Known_Compatible))
10247 then
10248 Error_Msg_NE
10249 ("??specified address for& may be inconsistent "
10250 & "with alignment", ACCR.N, ACCR.X);
10251 Error_Msg_N
10252 ("\??program execution may be erroneous (RM 13.3(27))",
10253 ACCR.N);
10254 Error_Msg_Uint_1 := X_Alignment;
10255 Error_Msg_NE
10256 ("\??alignment of & is ^", ACCR.N, ACCR.X);
10257 Error_Msg_Uint_1 := Y_Alignment;
10258 Error_Msg_NE
10259 ("\??alignment of & is ^", ACCR.N, ACCR.Y);
10260 if Y_Alignment >= X_Alignment then
10261 Error_Msg_N
10262 ("\??but offset is not multiple of alignment", ACCR.N);
10263 end if;
10264 end if;
10265 end if;
10266 end;
10267 end loop;
10268 end Validate_Address_Clauses;
10269
10270 ---------------------------
10271 -- Validate_Independence --
10272 ---------------------------
10273
10274 procedure Validate_Independence is
10275 SU : constant Uint := UI_From_Int (System_Storage_Unit);
10276 N : Node_Id;
10277 E : Entity_Id;
10278 IC : Boolean;
10279 Comp : Entity_Id;
10280 Addr : Node_Id;
10281 P : Node_Id;
10282
10283 procedure Check_Array_Type (Atyp : Entity_Id);
10284 -- Checks if the array type Atyp has independent components, and
10285 -- if not, outputs an appropriate set of error messages.
10286
10287 procedure No_Independence;
10288 -- Output message that independence cannot be guaranteed
10289
10290 function OK_Component (C : Entity_Id) return Boolean;
10291 -- Checks one component to see if it is independently accessible, and
10292 -- if so yields True, otherwise yields False if independent access
10293 -- cannot be guaranteed. This is a conservative routine, it only
10294 -- returns True if it knows for sure, it returns False if it knows
10295 -- there is a problem, or it cannot be sure there is no problem.
10296
10297 procedure Reason_Bad_Component (C : Entity_Id);
10298 -- Outputs continuation message if a reason can be determined for
10299 -- the component C being bad.
10300
10301 ----------------------
10302 -- Check_Array_Type --
10303 ----------------------
10304
10305 procedure Check_Array_Type (Atyp : Entity_Id) is
10306 Ctyp : constant Entity_Id := Component_Type (Atyp);
10307
10308 begin
10309 -- OK if no alignment clause, no pack, and no component size
10310
10311 if not Has_Component_Size_Clause (Atyp)
10312 and then not Has_Alignment_Clause (Atyp)
10313 and then not Is_Packed (Atyp)
10314 then
10315 return;
10316 end if;
10317
10318 -- Check actual component size
10319
10320 if not Known_Component_Size (Atyp)
10321 or else not (Addressable (Component_Size (Atyp))
10322 and then Component_Size (Atyp) < 64)
10323 or else Component_Size (Atyp) mod Esize (Ctyp) /= 0
10324 then
10325 No_Independence;
10326
10327 -- Bad component size, check reason
10328
10329 if Has_Component_Size_Clause (Atyp) then
10330 P := Get_Attribute_Definition_Clause
10331 (Atyp, Attribute_Component_Size);
10332
10333 if Present (P) then
10334 Error_Msg_Sloc := Sloc (P);
10335 Error_Msg_N ("\because of Component_Size clause#", N);
10336 return;
10337 end if;
10338 end if;
10339
10340 if Is_Packed (Atyp) then
10341 P := Get_Rep_Pragma (Atyp, Name_Pack);
10342
10343 if Present (P) then
10344 Error_Msg_Sloc := Sloc (P);
10345 Error_Msg_N ("\because of pragma Pack#", N);
10346 return;
10347 end if;
10348 end if;
10349
10350 -- No reason found, just return
10351
10352 return;
10353 end if;
10354
10355 -- Array type is OK independence-wise
10356
10357 return;
10358 end Check_Array_Type;
10359
10360 ---------------------
10361 -- No_Independence --
10362 ---------------------
10363
10364 procedure No_Independence is
10365 begin
10366 if Pragma_Name (N) = Name_Independent then
10367 Error_Msg_NE ("independence cannot be guaranteed for&", N, E);
10368 else
10369 Error_Msg_NE
10370 ("independent components cannot be guaranteed for&", N, E);
10371 end if;
10372 end No_Independence;
10373
10374 ------------------
10375 -- OK_Component --
10376 ------------------
10377
10378 function OK_Component (C : Entity_Id) return Boolean is
10379 Rec : constant Entity_Id := Scope (C);
10380 Ctyp : constant Entity_Id := Etype (C);
10381
10382 begin
10383 -- OK if no component clause, no Pack, and no alignment clause
10384
10385 if No (Component_Clause (C))
10386 and then not Is_Packed (Rec)
10387 and then not Has_Alignment_Clause (Rec)
10388 then
10389 return True;
10390 end if;
10391
10392 -- Here we look at the actual component layout. A component is
10393 -- addressable if its size is a multiple of the Esize of the
10394 -- component type, and its starting position in the record has
10395 -- appropriate alignment, and the record itself has appropriate
10396 -- alignment to guarantee the component alignment.
10397
10398 -- Make sure sizes are static, always assume the worst for any
10399 -- cases where we cannot check static values.
10400
10401 if not (Known_Static_Esize (C)
10402 and then
10403 Known_Static_Esize (Ctyp))
10404 then
10405 return False;
10406 end if;
10407
10408 -- Size of component must be addressable or greater than 64 bits
10409 -- and a multiple of bytes.
10410
10411 if not Addressable (Esize (C)) and then Esize (C) < Uint_64 then
10412 return False;
10413 end if;
10414
10415 -- Check size is proper multiple
10416
10417 if Esize (C) mod Esize (Ctyp) /= 0 then
10418 return False;
10419 end if;
10420
10421 -- Check alignment of component is OK
10422
10423 if not Known_Component_Bit_Offset (C)
10424 or else Component_Bit_Offset (C) < Uint_0
10425 or else Component_Bit_Offset (C) mod Esize (Ctyp) /= 0
10426 then
10427 return False;
10428 end if;
10429
10430 -- Check alignment of record type is OK
10431
10432 if not Known_Alignment (Rec)
10433 or else (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0
10434 then
10435 return False;
10436 end if;
10437
10438 -- All tests passed, component is addressable
10439
10440 return True;
10441 end OK_Component;
10442
10443 --------------------------
10444 -- Reason_Bad_Component --
10445 --------------------------
10446
10447 procedure Reason_Bad_Component (C : Entity_Id) is
10448 Rec : constant Entity_Id := Scope (C);
10449 Ctyp : constant Entity_Id := Etype (C);
10450
10451 begin
10452 -- If component clause present assume that's the problem
10453
10454 if Present (Component_Clause (C)) then
10455 Error_Msg_Sloc := Sloc (Component_Clause (C));
10456 Error_Msg_N ("\because of Component_Clause#", N);
10457 return;
10458 end if;
10459
10460 -- If pragma Pack clause present, assume that's the problem
10461
10462 if Is_Packed (Rec) then
10463 P := Get_Rep_Pragma (Rec, Name_Pack);
10464
10465 if Present (P) then
10466 Error_Msg_Sloc := Sloc (P);
10467 Error_Msg_N ("\because of pragma Pack#", N);
10468 return;
10469 end if;
10470 end if;
10471
10472 -- See if record has bad alignment clause
10473
10474 if Has_Alignment_Clause (Rec)
10475 and then Known_Alignment (Rec)
10476 and then (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0
10477 then
10478 P := Get_Attribute_Definition_Clause (Rec, Attribute_Alignment);
10479
10480 if Present (P) then
10481 Error_Msg_Sloc := Sloc (P);
10482 Error_Msg_N ("\because of Alignment clause#", N);
10483 end if;
10484 end if;
10485
10486 -- Couldn't find a reason, so return without a message
10487
10488 return;
10489 end Reason_Bad_Component;
10490
10491 -- Start of processing for Validate_Independence
10492
10493 begin
10494 for J in Independence_Checks.First .. Independence_Checks.Last loop
10495 N := Independence_Checks.Table (J).N;
10496 E := Independence_Checks.Table (J).E;
10497 IC := Pragma_Name (N) = Name_Independent_Components;
10498
10499 -- Deal with component case
10500
10501 if Ekind (E) = E_Discriminant or else Ekind (E) = E_Component then
10502 if not OK_Component (E) then
10503 No_Independence;
10504 Reason_Bad_Component (E);
10505 goto Continue;
10506 end if;
10507 end if;
10508
10509 -- Deal with record with Independent_Components
10510
10511 if IC and then Is_Record_Type (E) then
10512 Comp := First_Component_Or_Discriminant (E);
10513 while Present (Comp) loop
10514 if not OK_Component (Comp) then
10515 No_Independence;
10516 Reason_Bad_Component (Comp);
10517 goto Continue;
10518 end if;
10519
10520 Next_Component_Or_Discriminant (Comp);
10521 end loop;
10522 end if;
10523
10524 -- Deal with address clause case
10525
10526 if Is_Object (E) then
10527 Addr := Address_Clause (E);
10528
10529 if Present (Addr) then
10530 No_Independence;
10531 Error_Msg_Sloc := Sloc (Addr);
10532 Error_Msg_N ("\because of Address clause#", N);
10533 goto Continue;
10534 end if;
10535 end if;
10536
10537 -- Deal with independent components for array type
10538
10539 if IC and then Is_Array_Type (E) then
10540 Check_Array_Type (E);
10541 end if;
10542
10543 -- Deal with independent components for array object
10544
10545 if IC and then Is_Object (E) and then Is_Array_Type (Etype (E)) then
10546 Check_Array_Type (Etype (E));
10547 end if;
10548
10549 <<Continue>> null;
10550 end loop;
10551 end Validate_Independence;
10552
10553 -----------------------------------
10554 -- Validate_Unchecked_Conversion --
10555 -----------------------------------
10556
10557 procedure Validate_Unchecked_Conversion
10558 (N : Node_Id;
10559 Act_Unit : Entity_Id)
10560 is
10561 Source : Entity_Id;
10562 Target : Entity_Id;
10563 Vnode : Node_Id;
10564
10565 begin
10566 -- Obtain source and target types. Note that we call Ancestor_Subtype
10567 -- here because the processing for generic instantiation always makes
10568 -- subtypes, and we want the original frozen actual types.
10569
10570 -- If we are dealing with private types, then do the check on their
10571 -- fully declared counterparts if the full declarations have been
10572 -- encountered (they don't have to be visible, but they must exist!)
10573
10574 Source := Ancestor_Subtype (Etype (First_Formal (Act_Unit)));
10575
10576 if Is_Private_Type (Source)
10577 and then Present (Underlying_Type (Source))
10578 then
10579 Source := Underlying_Type (Source);
10580 end if;
10581
10582 Target := Ancestor_Subtype (Etype (Act_Unit));
10583
10584 -- If either type is generic, the instantiation happens within a generic
10585 -- unit, and there is nothing to check. The proper check will happen
10586 -- when the enclosing generic is instantiated.
10587
10588 if Is_Generic_Type (Source) or else Is_Generic_Type (Target) then
10589 return;
10590 end if;
10591
10592 if Is_Private_Type (Target)
10593 and then Present (Underlying_Type (Target))
10594 then
10595 Target := Underlying_Type (Target);
10596 end if;
10597
10598 -- Source may be unconstrained array, but not target
10599
10600 if Is_Array_Type (Target) and then not Is_Constrained (Target) then
10601 Error_Msg_N
10602 ("unchecked conversion to unconstrained array not allowed", N);
10603 return;
10604 end if;
10605
10606 -- Warn if conversion between two different convention pointers
10607
10608 if Is_Access_Type (Target)
10609 and then Is_Access_Type (Source)
10610 and then Convention (Target) /= Convention (Source)
10611 and then Warn_On_Unchecked_Conversion
10612 then
10613 -- Give warnings for subprogram pointers only on most targets. The
10614 -- exception is VMS, where data pointers can have different lengths
10615 -- depending on the pointer convention.
10616
10617 if Is_Access_Subprogram_Type (Target)
10618 or else Is_Access_Subprogram_Type (Source)
10619 or else OpenVMS_On_Target
10620 then
10621 Error_Msg_N
10622 ("?z?conversion between pointers with different conventions!",
10623 N);
10624 end if;
10625 end if;
10626
10627 -- Warn if one of the operands is Ada.Calendar.Time. Do not emit a
10628 -- warning when compiling GNAT-related sources.
10629
10630 if Warn_On_Unchecked_Conversion
10631 and then not In_Predefined_Unit (N)
10632 and then RTU_Loaded (Ada_Calendar)
10633 and then
10634 (Chars (Source) = Name_Time
10635 or else
10636 Chars (Target) = Name_Time)
10637 then
10638 -- If Ada.Calendar is loaded and the name of one of the operands is
10639 -- Time, there is a good chance that this is Ada.Calendar.Time.
10640
10641 declare
10642 Calendar_Time : constant Entity_Id :=
10643 Full_View (RTE (RO_CA_Time));
10644 begin
10645 pragma Assert (Present (Calendar_Time));
10646
10647 if Source = Calendar_Time or else Target = Calendar_Time then
10648 Error_Msg_N
10649 ("?z?representation of 'Time values may change between " &
10650 "'G'N'A'T versions", N);
10651 end if;
10652 end;
10653 end if;
10654
10655 -- Make entry in unchecked conversion table for later processing by
10656 -- Validate_Unchecked_Conversions, which will check sizes and alignments
10657 -- (using values set by the back-end where possible). This is only done
10658 -- if the appropriate warning is active.
10659
10660 if Warn_On_Unchecked_Conversion then
10661 Unchecked_Conversions.Append
10662 (New_Val => UC_Entry'(Eloc => Sloc (N),
10663 Source => Source,
10664 Target => Target));
10665
10666 -- If both sizes are known statically now, then back end annotation
10667 -- is not required to do a proper check but if either size is not
10668 -- known statically, then we need the annotation.
10669
10670 if Known_Static_RM_Size (Source)
10671 and then
10672 Known_Static_RM_Size (Target)
10673 then
10674 null;
10675 else
10676 Back_Annotate_Rep_Info := True;
10677 end if;
10678 end if;
10679
10680 -- If unchecked conversion to access type, and access type is declared
10681 -- in the same unit as the unchecked conversion, then set the flag
10682 -- No_Strict_Aliasing (no strict aliasing is implicit here)
10683
10684 if Is_Access_Type (Target) and then
10685 In_Same_Source_Unit (Target, N)
10686 then
10687 Set_No_Strict_Aliasing (Implementation_Base_Type (Target));
10688 end if;
10689
10690 -- Generate N_Validate_Unchecked_Conversion node for back end in case
10691 -- the back end needs to perform special validation checks.
10692
10693 -- Shouldn't this be in Exp_Ch13, since the check only gets done if we
10694 -- have full expansion and the back end is called ???
10695
10696 Vnode :=
10697 Make_Validate_Unchecked_Conversion (Sloc (N));
10698 Set_Source_Type (Vnode, Source);
10699 Set_Target_Type (Vnode, Target);
10700
10701 -- If the unchecked conversion node is in a list, just insert before it.
10702 -- If not we have some strange case, not worth bothering about.
10703
10704 if Is_List_Member (N) then
10705 Insert_After (N, Vnode);
10706 end if;
10707 end Validate_Unchecked_Conversion;
10708
10709 ------------------------------------
10710 -- Validate_Unchecked_Conversions --
10711 ------------------------------------
10712
10713 procedure Validate_Unchecked_Conversions is
10714 begin
10715 for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop
10716 declare
10717 T : UC_Entry renames Unchecked_Conversions.Table (N);
10718
10719 Eloc : constant Source_Ptr := T.Eloc;
10720 Source : constant Entity_Id := T.Source;
10721 Target : constant Entity_Id := T.Target;
10722
10723 Source_Siz : Uint;
10724 Target_Siz : Uint;
10725
10726 begin
10727 -- This validation check, which warns if we have unequal sizes for
10728 -- unchecked conversion, and thus potentially implementation
10729 -- dependent semantics, is one of the few occasions on which we
10730 -- use the official RM size instead of Esize. See description in
10731 -- Einfo "Handling of Type'Size Values" for details.
10732
10733 if Serious_Errors_Detected = 0
10734 and then Known_Static_RM_Size (Source)
10735 and then Known_Static_RM_Size (Target)
10736
10737 -- Don't do the check if warnings off for either type, note the
10738 -- deliberate use of OR here instead of OR ELSE to get the flag
10739 -- Warnings_Off_Used set for both types if appropriate.
10740
10741 and then not (Has_Warnings_Off (Source)
10742 or
10743 Has_Warnings_Off (Target))
10744 then
10745 Source_Siz := RM_Size (Source);
10746 Target_Siz := RM_Size (Target);
10747
10748 if Source_Siz /= Target_Siz then
10749 Error_Msg
10750 ("?z?types for unchecked conversion have different sizes!",
10751 Eloc);
10752
10753 if All_Errors_Mode then
10754 Error_Msg_Name_1 := Chars (Source);
10755 Error_Msg_Uint_1 := Source_Siz;
10756 Error_Msg_Name_2 := Chars (Target);
10757 Error_Msg_Uint_2 := Target_Siz;
10758 Error_Msg ("\size of % is ^, size of % is ^?z?", Eloc);
10759
10760 Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz);
10761
10762 if Is_Discrete_Type (Source)
10763 and then
10764 Is_Discrete_Type (Target)
10765 then
10766 if Source_Siz > Target_Siz then
10767 Error_Msg
10768 ("\?z?^ high order bits of source will "
10769 & "be ignored!", Eloc);
10770
10771 elsif Is_Unsigned_Type (Source) then
10772 Error_Msg
10773 ("\?z?source will be extended with ^ high order "
10774 & "zero bits?!", Eloc);
10775
10776 else
10777 Error_Msg
10778 ("\?z?source will be extended with ^ high order "
10779 & "sign bits!", Eloc);
10780 end if;
10781
10782 elsif Source_Siz < Target_Siz then
10783 if Is_Discrete_Type (Target) then
10784 if Bytes_Big_Endian then
10785 Error_Msg
10786 ("\?z?target value will include ^ undefined "
10787 & "low order bits!", Eloc);
10788 else
10789 Error_Msg
10790 ("\?z?target value will include ^ undefined "
10791 & "high order bits!", Eloc);
10792 end if;
10793
10794 else
10795 Error_Msg
10796 ("\?z?^ trailing bits of target value will be "
10797 & "undefined!", Eloc);
10798 end if;
10799
10800 else pragma Assert (Source_Siz > Target_Siz);
10801 Error_Msg
10802 ("\?z?^ trailing bits of source will be ignored!",
10803 Eloc);
10804 end if;
10805 end if;
10806 end if;
10807 end if;
10808
10809 -- If both types are access types, we need to check the alignment.
10810 -- If the alignment of both is specified, we can do it here.
10811
10812 if Serious_Errors_Detected = 0
10813 and then Ekind (Source) in Access_Kind
10814 and then Ekind (Target) in Access_Kind
10815 and then Target_Strict_Alignment
10816 and then Present (Designated_Type (Source))
10817 and then Present (Designated_Type (Target))
10818 then
10819 declare
10820 D_Source : constant Entity_Id := Designated_Type (Source);
10821 D_Target : constant Entity_Id := Designated_Type (Target);
10822
10823 begin
10824 if Known_Alignment (D_Source)
10825 and then
10826 Known_Alignment (D_Target)
10827 then
10828 declare
10829 Source_Align : constant Uint := Alignment (D_Source);
10830 Target_Align : constant Uint := Alignment (D_Target);
10831
10832 begin
10833 if Source_Align < Target_Align
10834 and then not Is_Tagged_Type (D_Source)
10835
10836 -- Suppress warning if warnings suppressed on either
10837 -- type or either designated type. Note the use of
10838 -- OR here instead of OR ELSE. That is intentional,
10839 -- we would like to set flag Warnings_Off_Used in
10840 -- all types for which warnings are suppressed.
10841
10842 and then not (Has_Warnings_Off (D_Source)
10843 or
10844 Has_Warnings_Off (D_Target)
10845 or
10846 Has_Warnings_Off (Source)
10847 or
10848 Has_Warnings_Off (Target))
10849 then
10850 Error_Msg_Uint_1 := Target_Align;
10851 Error_Msg_Uint_2 := Source_Align;
10852 Error_Msg_Node_1 := D_Target;
10853 Error_Msg_Node_2 := D_Source;
10854 Error_Msg
10855 ("?z?alignment of & (^) is stricter than "
10856 & "alignment of & (^)!", Eloc);
10857 Error_Msg
10858 ("\?z?resulting access value may have invalid "
10859 & "alignment!", Eloc);
10860 end if;
10861 end;
10862 end if;
10863 end;
10864 end if;
10865 end;
10866 end loop;
10867 end Validate_Unchecked_Conversions;
10868
10869 end Sem_Ch13;