PR target/58115
[official-gcc.git] / gcc / ada / sem_ch13.adb
blob15862442175cbdf0af0c334f2b8197bd9d69a47d
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 ------------------------------------------------------------------------------
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_Case; use Sem_Case;
48 with Sem_Ch3; use Sem_Ch3;
49 with Sem_Ch6; use Sem_Ch6;
50 with Sem_Ch8; use Sem_Ch8;
51 with Sem_Ch9; use Sem_Ch9;
52 with Sem_Dim; use Sem_Dim;
53 with Sem_Disp; use Sem_Disp;
54 with Sem_Eval; use Sem_Eval;
55 with Sem_Prag; use Sem_Prag;
56 with Sem_Res; use Sem_Res;
57 with Sem_Type; use Sem_Type;
58 with Sem_Util; use Sem_Util;
59 with Sem_Warn; use Sem_Warn;
60 with Sinput; use Sinput;
61 with Snames; use Snames;
62 with Stand; use Stand;
63 with Sinfo; use Sinfo;
64 with Stringt; use Stringt;
65 with Targparm; use Targparm;
66 with Ttypes; use Ttypes;
67 with Tbuild; use Tbuild;
68 with Urealp; use Urealp;
69 with Warnsw; use Warnsw;
71 with GNAT.Heap_Sort_G;
73 package body Sem_Ch13 is
75 SSU : constant Pos := System_Storage_Unit;
76 -- Convenient short hand for commonly used constant
78 -----------------------
79 -- Local Subprograms --
80 -----------------------
82 procedure Alignment_Check_For_Size_Change (Typ : Entity_Id; Size : Uint);
83 -- This routine is called after setting one of the sizes of type entity
84 -- Typ to Size. The purpose is to deal with the situation of a derived
85 -- type whose inherited alignment is no longer appropriate for the new
86 -- size value. In this case, we reset the Alignment to unknown.
88 procedure Build_Predicate_Functions (Typ : Entity_Id; N : Node_Id);
89 -- If Typ has predicates (indicated by Has_Predicates being set for Typ,
90 -- then either there are pragma Predicate entries on the rep chain for the
91 -- type (note that Predicate aspects are converted to pragma Predicate), or
92 -- there are inherited aspects from a parent type, or ancestor subtypes.
93 -- This procedure builds the spec and body for the Predicate function that
94 -- tests these predicates. N is the freeze node for the type. The spec of
95 -- the function is inserted before the freeze node, and the body of the
96 -- function is inserted after the freeze node. If the predicate expression
97 -- has at least one Raise_Expression, then this procedure also builds the
98 -- M version of the predicate function for use in membership tests.
100 procedure Build_Static_Predicate
101 (Typ : Entity_Id;
102 Expr : Node_Id;
103 Nam : Name_Id);
104 -- Given a predicated type Typ, where Typ is a discrete static subtype,
105 -- whose predicate expression is Expr, tests if Expr is a static predicate,
106 -- and if so, builds the predicate range list. Nam is the name of the one
107 -- argument to the predicate function. Occurrences of the type name in the
108 -- predicate expression have been replaced by identifier references to this
109 -- name, which is unique, so any identifier with Chars matching Nam must be
110 -- a reference to the type. If the predicate is non-static, this procedure
111 -- returns doing nothing. If the predicate is static, then the predicate
112 -- list is stored in Static_Predicate (Typ), and the Expr is rewritten as
113 -- a canonicalized membership operation.
115 procedure Freeze_Entity_Checks (N : Node_Id);
116 -- Called from Analyze_Freeze_Entity and Analyze_Generic_Freeze Entity
117 -- to generate appropriate semantic checks that are delayed until this
118 -- point (they had to be delayed this long for cases of delayed aspects,
119 -- e.g. analysis of statically predicated subtypes in choices, for which
120 -- we have to be sure the subtypes in question are frozen before checking.
122 function Get_Alignment_Value (Expr : Node_Id) return Uint;
123 -- Given the expression for an alignment value, returns the corresponding
124 -- Uint value. If the value is inappropriate, then error messages are
125 -- posted as required, and a value of No_Uint is returned.
127 function Is_Operational_Item (N : Node_Id) return Boolean;
128 -- A specification for a stream attribute is allowed before the full type
129 -- is declared, as explained in AI-00137 and the corrigendum. Attributes
130 -- that do not specify a representation characteristic are operational
131 -- attributes.
133 procedure New_Stream_Subprogram
134 (N : Node_Id;
135 Ent : Entity_Id;
136 Subp : Entity_Id;
137 Nam : TSS_Name_Type);
138 -- Create a subprogram renaming of a given stream attribute to the
139 -- designated subprogram and then in the tagged case, provide this as a
140 -- primitive operation, or in the non-tagged case make an appropriate TSS
141 -- entry. This is more properly an expansion activity than just semantics,
142 -- but the presence of user-defined stream functions for limited types is a
143 -- legality check, which is why this takes place here rather than in
144 -- exp_ch13, where it was previously. Nam indicates the name of the TSS
145 -- function to be generated.
147 -- To avoid elaboration anomalies with freeze nodes, for untagged types
148 -- we generate both a subprogram declaration and a subprogram renaming
149 -- declaration, so that the attribute specification is handled as a
150 -- renaming_as_body. For tagged types, the specification is one of the
151 -- primitive specs.
153 generic
154 with procedure Replace_Type_Reference (N : Node_Id);
155 procedure Replace_Type_References_Generic (N : Node_Id; TName : Name_Id);
156 -- This is used to scan an expression for a predicate or invariant aspect
157 -- replacing occurrences of the name TName (the name of the subtype to
158 -- which the aspect applies) with appropriate references to the parameter
159 -- of the predicate function or invariant procedure. The procedure passed
160 -- as a generic parameter does the actual replacement of node N, which is
161 -- either a simple direct reference to TName, or a selected component that
162 -- represents an appropriately qualified occurrence of TName.
164 procedure Set_Biased
165 (E : Entity_Id;
166 N : Node_Id;
167 Msg : String;
168 Biased : Boolean := True);
169 -- If Biased is True, sets Has_Biased_Representation flag for E, and
170 -- outputs a warning message at node N if Warn_On_Biased_Representation is
171 -- is True. This warning inserts the string Msg to describe the construct
172 -- causing biasing.
174 ----------------------------------------------
175 -- Table for Validate_Unchecked_Conversions --
176 ----------------------------------------------
178 -- The following table collects unchecked conversions for validation.
179 -- Entries are made by Validate_Unchecked_Conversion and then the call
180 -- to Validate_Unchecked_Conversions does the actual error checking and
181 -- posting of warnings. The reason for this delayed processing is to take
182 -- advantage of back-annotations of size and alignment values performed by
183 -- the back end.
185 -- Note: the reason we store a Source_Ptr value instead of a Node_Id is
186 -- that by the time Validate_Unchecked_Conversions is called, Sprint will
187 -- already have modified all Sloc values if the -gnatD option is set.
189 type UC_Entry is record
190 Eloc : Source_Ptr; -- node used for posting warnings
191 Source : Entity_Id; -- source type for unchecked conversion
192 Target : Entity_Id; -- target type for unchecked conversion
193 end record;
195 package Unchecked_Conversions is new Table.Table (
196 Table_Component_Type => UC_Entry,
197 Table_Index_Type => Int,
198 Table_Low_Bound => 1,
199 Table_Initial => 50,
200 Table_Increment => 200,
201 Table_Name => "Unchecked_Conversions");
203 ----------------------------------------
204 -- Table for Validate_Address_Clauses --
205 ----------------------------------------
207 -- If an address clause has the form
209 -- for X'Address use Expr
211 -- where Expr is of the form Y'Address or recursively is a reference to a
212 -- constant of either of these forms, and X and Y are entities of objects,
213 -- then if Y has a smaller alignment than X, that merits a warning about
214 -- possible bad alignment. The following table collects address clauses of
215 -- this kind. We put these in a table so that they can be checked after the
216 -- back end has completed annotation of the alignments of objects, since we
217 -- can catch more cases that way.
219 type Address_Clause_Check_Record is record
220 N : Node_Id;
221 -- The address clause
223 X : Entity_Id;
224 -- The entity of the object overlaying Y
226 Y : Entity_Id;
227 -- The entity of the object being overlaid
229 Off : Boolean;
230 -- Whether the address is offset within Y
231 end record;
233 package Address_Clause_Checks is new Table.Table (
234 Table_Component_Type => Address_Clause_Check_Record,
235 Table_Index_Type => Int,
236 Table_Low_Bound => 1,
237 Table_Initial => 20,
238 Table_Increment => 200,
239 Table_Name => "Address_Clause_Checks");
241 -----------------------------------------
242 -- Adjust_Record_For_Reverse_Bit_Order --
243 -----------------------------------------
245 procedure Adjust_Record_For_Reverse_Bit_Order (R : Entity_Id) is
246 Comp : Node_Id;
247 CC : Node_Id;
249 begin
250 -- Processing depends on version of Ada
252 -- For Ada 95, we just renumber bits within a storage unit. We do the
253 -- same for Ada 83 mode, since we recognize the Bit_Order attribute in
254 -- Ada 83, and are free to add this extension.
256 if Ada_Version < Ada_2005 then
257 Comp := First_Component_Or_Discriminant (R);
258 while Present (Comp) loop
259 CC := Component_Clause (Comp);
261 -- If component clause is present, then deal with the non-default
262 -- bit order case for Ada 95 mode.
264 -- We only do this processing for the base type, and in fact that
265 -- is important, since otherwise if there are record subtypes, we
266 -- could reverse the bits once for each subtype, which is wrong.
268 if Present (CC) and then Ekind (R) = E_Record_Type then
269 declare
270 CFB : constant Uint := Component_Bit_Offset (Comp);
271 CSZ : constant Uint := Esize (Comp);
272 CLC : constant Node_Id := Component_Clause (Comp);
273 Pos : constant Node_Id := Position (CLC);
274 FB : constant Node_Id := First_Bit (CLC);
276 Storage_Unit_Offset : constant Uint :=
277 CFB / System_Storage_Unit;
279 Start_Bit : constant Uint :=
280 CFB mod System_Storage_Unit;
282 begin
283 -- Cases where field goes over storage unit boundary
285 if Start_Bit + CSZ > System_Storage_Unit then
287 -- Allow multi-byte field but generate warning
289 if Start_Bit mod System_Storage_Unit = 0
290 and then CSZ mod System_Storage_Unit = 0
291 then
292 Error_Msg_N
293 ("multi-byte field specified with non-standard"
294 & " Bit_Order??", CLC);
296 if Bytes_Big_Endian then
297 Error_Msg_N
298 ("bytes are not reversed "
299 & "(component is big-endian)??", CLC);
300 else
301 Error_Msg_N
302 ("bytes are not reversed "
303 & "(component is little-endian)??", CLC);
304 end if;
306 -- Do not allow non-contiguous field
308 else
309 Error_Msg_N
310 ("attempt to specify non-contiguous field "
311 & "not permitted", CLC);
312 Error_Msg_N
313 ("\caused by non-standard Bit_Order "
314 & "specified", CLC);
315 Error_Msg_N
316 ("\consider possibility of using "
317 & "Ada 2005 mode here", CLC);
318 end if;
320 -- Case where field fits in one storage unit
322 else
323 -- Give warning if suspicious component clause
325 if Intval (FB) >= System_Storage_Unit
326 and then Warn_On_Reverse_Bit_Order
327 then
328 Error_Msg_N
329 ("Bit_Order clause does not affect " &
330 "byte ordering?V?", Pos);
331 Error_Msg_Uint_1 :=
332 Intval (Pos) + Intval (FB) /
333 System_Storage_Unit;
334 Error_Msg_N
335 ("position normalized to ^ before bit " &
336 "order interpreted?V?", Pos);
337 end if;
339 -- Here is where we fix up the Component_Bit_Offset value
340 -- to account for the reverse bit order. Some examples of
341 -- what needs to be done are:
343 -- First_Bit .. Last_Bit Component_Bit_Offset
344 -- old new old new
346 -- 0 .. 0 7 .. 7 0 7
347 -- 0 .. 1 6 .. 7 0 6
348 -- 0 .. 2 5 .. 7 0 5
349 -- 0 .. 7 0 .. 7 0 4
351 -- 1 .. 1 6 .. 6 1 6
352 -- 1 .. 4 3 .. 6 1 3
353 -- 4 .. 7 0 .. 3 4 0
355 -- The rule is that the first bit is is obtained by
356 -- subtracting the old ending bit from storage_unit - 1.
358 Set_Component_Bit_Offset
359 (Comp,
360 (Storage_Unit_Offset * System_Storage_Unit) +
361 (System_Storage_Unit - 1) -
362 (Start_Bit + CSZ - 1));
364 Set_Normalized_First_Bit
365 (Comp,
366 Component_Bit_Offset (Comp) mod
367 System_Storage_Unit);
368 end if;
369 end;
370 end if;
372 Next_Component_Or_Discriminant (Comp);
373 end loop;
375 -- For Ada 2005, we do machine scalar processing, as fully described In
376 -- AI-133. This involves gathering all components which start at the
377 -- same byte offset and processing them together. Same approach is still
378 -- valid in later versions including Ada 2012.
380 else
381 declare
382 Max_Machine_Scalar_Size : constant Uint :=
383 UI_From_Int
384 (Standard_Long_Long_Integer_Size);
385 -- We use this as the maximum machine scalar size
387 Num_CC : Natural;
388 SSU : constant Uint := UI_From_Int (System_Storage_Unit);
390 begin
391 -- This first loop through components does two things. First it
392 -- deals with the case of components with component clauses whose
393 -- length is greater than the maximum machine scalar size (either
394 -- accepting them or rejecting as needed). Second, it counts the
395 -- number of components with component clauses whose length does
396 -- not exceed this maximum for later processing.
398 Num_CC := 0;
399 Comp := First_Component_Or_Discriminant (R);
400 while Present (Comp) loop
401 CC := Component_Clause (Comp);
403 if Present (CC) then
404 declare
405 Fbit : constant Uint := Static_Integer (First_Bit (CC));
406 Lbit : constant Uint := Static_Integer (Last_Bit (CC));
408 begin
409 -- Case of component with last bit >= max machine scalar
411 if Lbit >= Max_Machine_Scalar_Size then
413 -- This is allowed only if first bit is zero, and
414 -- last bit + 1 is a multiple of storage unit size.
416 if Fbit = 0 and then (Lbit + 1) mod SSU = 0 then
418 -- This is the case to give a warning if enabled
420 if Warn_On_Reverse_Bit_Order then
421 Error_Msg_N
422 ("multi-byte field specified with "
423 & " non-standard Bit_Order?V?", CC);
425 if Bytes_Big_Endian then
426 Error_Msg_N
427 ("\bytes are not reversed "
428 & "(component is big-endian)?V?", CC);
429 else
430 Error_Msg_N
431 ("\bytes are not reversed "
432 & "(component is little-endian)?V?", CC);
433 end if;
434 end if;
436 -- Give error message for RM 13.5.1(10) violation
438 else
439 Error_Msg_FE
440 ("machine scalar rules not followed for&",
441 First_Bit (CC), Comp);
443 Error_Msg_Uint_1 := Lbit;
444 Error_Msg_Uint_2 := Max_Machine_Scalar_Size;
445 Error_Msg_F
446 ("\last bit (^) exceeds maximum machine "
447 & "scalar size (^)",
448 First_Bit (CC));
450 if (Lbit + 1) mod SSU /= 0 then
451 Error_Msg_Uint_1 := SSU;
452 Error_Msg_F
453 ("\and is not a multiple of Storage_Unit (^) "
454 & "(RM 13.4.1(10))",
455 First_Bit (CC));
457 else
458 Error_Msg_Uint_1 := Fbit;
459 Error_Msg_F
460 ("\and first bit (^) is non-zero "
461 & "(RM 13.4.1(10))",
462 First_Bit (CC));
463 end if;
464 end if;
466 -- OK case of machine scalar related component clause,
467 -- For now, just count them.
469 else
470 Num_CC := Num_CC + 1;
471 end if;
472 end;
473 end if;
475 Next_Component_Or_Discriminant (Comp);
476 end loop;
478 -- We need to sort the component clauses on the basis of the
479 -- Position values in the clause, so we can group clauses with
480 -- the same Position. together to determine the relevant machine
481 -- scalar size.
483 Sort_CC : declare
484 Comps : array (0 .. Num_CC) of Entity_Id;
485 -- Array to collect component and discriminant entities. The
486 -- data starts at index 1, the 0'th entry is for the sort
487 -- routine.
489 function CP_Lt (Op1, Op2 : Natural) return Boolean;
490 -- Compare routine for Sort
492 procedure CP_Move (From : Natural; To : Natural);
493 -- Move routine for Sort
495 package Sorting is new GNAT.Heap_Sort_G (CP_Move, CP_Lt);
497 Start : Natural;
498 Stop : Natural;
499 -- Start and stop positions in the component list of the set of
500 -- components with the same starting position (that constitute
501 -- components in a single machine scalar).
503 MaxL : Uint;
504 -- Maximum last bit value of any component in this set
506 MSS : Uint;
507 -- Corresponding machine scalar size
509 -----------
510 -- CP_Lt --
511 -----------
513 function CP_Lt (Op1, Op2 : Natural) return Boolean is
514 begin
515 return Position (Component_Clause (Comps (Op1))) <
516 Position (Component_Clause (Comps (Op2)));
517 end CP_Lt;
519 -------------
520 -- CP_Move --
521 -------------
523 procedure CP_Move (From : Natural; To : Natural) is
524 begin
525 Comps (To) := Comps (From);
526 end CP_Move;
528 -- Start of processing for Sort_CC
530 begin
531 -- Collect the machine scalar relevant component clauses
533 Num_CC := 0;
534 Comp := First_Component_Or_Discriminant (R);
535 while Present (Comp) loop
536 declare
537 CC : constant Node_Id := Component_Clause (Comp);
539 begin
540 -- Collect only component clauses whose last bit is less
541 -- than machine scalar size. Any component clause whose
542 -- last bit exceeds this value does not take part in
543 -- machine scalar layout considerations. The test for
544 -- Error_Posted makes sure we exclude component clauses
545 -- for which we already posted an error.
547 if Present (CC)
548 and then not Error_Posted (Last_Bit (CC))
549 and then Static_Integer (Last_Bit (CC)) <
550 Max_Machine_Scalar_Size
551 then
552 Num_CC := Num_CC + 1;
553 Comps (Num_CC) := Comp;
554 end if;
555 end;
557 Next_Component_Or_Discriminant (Comp);
558 end loop;
560 -- Sort by ascending position number
562 Sorting.Sort (Num_CC);
564 -- We now have all the components whose size does not exceed
565 -- the max machine scalar value, sorted by starting position.
566 -- In this loop we gather groups of clauses starting at the
567 -- same position, to process them in accordance with AI-133.
569 Stop := 0;
570 while Stop < Num_CC loop
571 Start := Stop + 1;
572 Stop := Start;
573 MaxL :=
574 Static_Integer
575 (Last_Bit (Component_Clause (Comps (Start))));
576 while Stop < Num_CC loop
577 if Static_Integer
578 (Position (Component_Clause (Comps (Stop + 1)))) =
579 Static_Integer
580 (Position (Component_Clause (Comps (Stop))))
581 then
582 Stop := Stop + 1;
583 MaxL :=
584 UI_Max
585 (MaxL,
586 Static_Integer
587 (Last_Bit
588 (Component_Clause (Comps (Stop)))));
589 else
590 exit;
591 end if;
592 end loop;
594 -- Now we have a group of component clauses from Start to
595 -- Stop whose positions are identical, and MaxL is the
596 -- maximum last bit value of any of these components.
598 -- We need to determine the corresponding machine scalar
599 -- size. This loop assumes that machine scalar sizes are
600 -- even, and that each possible machine scalar has twice
601 -- as many bits as the next smaller one.
603 MSS := Max_Machine_Scalar_Size;
604 while MSS mod 2 = 0
605 and then (MSS / 2) >= SSU
606 and then (MSS / 2) > MaxL
607 loop
608 MSS := MSS / 2;
609 end loop;
611 -- Here is where we fix up the Component_Bit_Offset value
612 -- to account for the reverse bit order. Some examples of
613 -- what needs to be done for the case of a machine scalar
614 -- size of 8 are:
616 -- First_Bit .. Last_Bit Component_Bit_Offset
617 -- old new old new
619 -- 0 .. 0 7 .. 7 0 7
620 -- 0 .. 1 6 .. 7 0 6
621 -- 0 .. 2 5 .. 7 0 5
622 -- 0 .. 7 0 .. 7 0 4
624 -- 1 .. 1 6 .. 6 1 6
625 -- 1 .. 4 3 .. 6 1 3
626 -- 4 .. 7 0 .. 3 4 0
628 -- The rule is that the first bit is obtained by subtracting
629 -- the old ending bit from machine scalar size - 1.
631 for C in Start .. Stop loop
632 declare
633 Comp : constant Entity_Id := Comps (C);
634 CC : constant Node_Id := Component_Clause (Comp);
636 LB : constant Uint := Static_Integer (Last_Bit (CC));
637 NFB : constant Uint := MSS - Uint_1 - LB;
638 NLB : constant Uint := NFB + Esize (Comp) - 1;
639 Pos : constant Uint := Static_Integer (Position (CC));
641 begin
642 if Warn_On_Reverse_Bit_Order then
643 Error_Msg_Uint_1 := MSS;
644 Error_Msg_N
645 ("info: reverse bit order in machine " &
646 "scalar of length^?V?", First_Bit (CC));
647 Error_Msg_Uint_1 := NFB;
648 Error_Msg_Uint_2 := NLB;
650 if Bytes_Big_Endian then
651 Error_Msg_NE
652 ("\info: big-endian range for "
653 & "component & is ^ .. ^?V?",
654 First_Bit (CC), Comp);
655 else
656 Error_Msg_NE
657 ("\info: little-endian range "
658 & "for component & is ^ .. ^?V?",
659 First_Bit (CC), Comp);
660 end if;
661 end if;
663 Set_Component_Bit_Offset (Comp, Pos * SSU + NFB);
664 Set_Normalized_First_Bit (Comp, NFB mod SSU);
665 end;
666 end loop;
667 end loop;
668 end Sort_CC;
669 end;
670 end if;
671 end Adjust_Record_For_Reverse_Bit_Order;
673 -------------------------------------
674 -- Alignment_Check_For_Size_Change --
675 -------------------------------------
677 procedure Alignment_Check_For_Size_Change (Typ : Entity_Id; Size : Uint) is
678 begin
679 -- If the alignment is known, and not set by a rep clause, and is
680 -- inconsistent with the size being set, then reset it to unknown,
681 -- we assume in this case that the size overrides the inherited
682 -- alignment, and that the alignment must be recomputed.
684 if Known_Alignment (Typ)
685 and then not Has_Alignment_Clause (Typ)
686 and then Size mod (Alignment (Typ) * SSU) /= 0
687 then
688 Init_Alignment (Typ);
689 end if;
690 end Alignment_Check_For_Size_Change;
692 -------------------------------------
693 -- Analyze_Aspects_At_Freeze_Point --
694 -------------------------------------
696 procedure Analyze_Aspects_At_Freeze_Point (E : Entity_Id) is
697 ASN : Node_Id;
698 A_Id : Aspect_Id;
699 Ritem : Node_Id;
701 procedure Analyze_Aspect_Default_Value (ASN : Node_Id);
702 -- This routine analyzes an Aspect_Default_[Component_]Value denoted by
703 -- the aspect specification node ASN.
705 procedure Inherit_Delayed_Rep_Aspects (ASN : Node_Id);
706 -- As discussed in the spec of Aspects (see Aspect_Delay declaration),
707 -- a derived type can inherit aspects from its parent which have been
708 -- specified at the time of the derivation using an aspect, as in:
710 -- type A is range 1 .. 10
711 -- with Size => Not_Defined_Yet;
712 -- ..
713 -- type B is new A;
714 -- ..
715 -- Not_Defined_Yet : constant := 64;
717 -- In this example, the Size of A is considered to be specified prior
718 -- to the derivation, and thus inherited, even though the value is not
719 -- known at the time of derivation. To deal with this, we use two entity
720 -- flags. The flag Has_Derived_Rep_Aspects is set in the parent type (A
721 -- here), and then the flag May_Inherit_Delayed_Rep_Aspects is set in
722 -- the derived type (B here). If this flag is set when the derived type
723 -- is frozen, then this procedure is called to ensure proper inheritance
724 -- of all delayed aspects from the parent type. The derived type is E,
725 -- the argument to Analyze_Aspects_At_Freeze_Point. ASN is the first
726 -- aspect specification node in the Rep_Item chain for the parent type.
728 procedure Make_Pragma_From_Boolean_Aspect (ASN : Node_Id);
729 -- Given an aspect specification node ASN whose expression is an
730 -- optional Boolean, this routines creates the corresponding pragma
731 -- at the freezing point.
733 ----------------------------------
734 -- Analyze_Aspect_Default_Value --
735 ----------------------------------
737 procedure Analyze_Aspect_Default_Value (ASN : Node_Id) is
738 Ent : constant Entity_Id := Entity (ASN);
739 Expr : constant Node_Id := Expression (ASN);
740 Id : constant Node_Id := Identifier (ASN);
742 begin
743 Error_Msg_Name_1 := Chars (Id);
745 if not Is_Type (Ent) then
746 Error_Msg_N ("aspect% can only apply to a type", Id);
747 return;
749 elsif not Is_First_Subtype (Ent) then
750 Error_Msg_N ("aspect% cannot apply to subtype", Id);
751 return;
753 elsif A_Id = Aspect_Default_Value
754 and then not Is_Scalar_Type (Ent)
755 then
756 Error_Msg_N ("aspect% can only be applied to scalar type", Id);
757 return;
759 elsif A_Id = Aspect_Default_Component_Value then
760 if not Is_Array_Type (Ent) then
761 Error_Msg_N ("aspect% can only be applied to array type", Id);
762 return;
764 elsif not Is_Scalar_Type (Component_Type (Ent)) then
765 Error_Msg_N ("aspect% requires scalar components", Id);
766 return;
767 end if;
768 end if;
770 Set_Has_Default_Aspect (Base_Type (Ent));
772 if Is_Scalar_Type (Ent) then
773 Set_Default_Aspect_Value (Base_Type (Ent), Expr);
774 else
775 Set_Default_Aspect_Component_Value (Base_Type (Ent), Expr);
776 end if;
777 end Analyze_Aspect_Default_Value;
779 ---------------------------------
780 -- Inherit_Delayed_Rep_Aspects --
781 ---------------------------------
783 procedure Inherit_Delayed_Rep_Aspects (ASN : Node_Id) is
784 P : constant Entity_Id := Entity (ASN);
785 -- Entithy for parent type
787 N : Node_Id;
788 -- Item from Rep_Item chain
790 A : Aspect_Id;
792 begin
793 -- Loop through delayed aspects for the parent type
795 N := ASN;
796 while Present (N) loop
797 if Nkind (N) = N_Aspect_Specification then
798 exit when Entity (N) /= P;
800 if Is_Delayed_Aspect (N) then
801 A := Get_Aspect_Id (Chars (Identifier (N)));
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.
810 case A is
812 -- Alignment
814 when Aspect_Alignment =>
815 if not Has_Alignment_Clause (E) then
816 Set_Alignment (E, Alignment (P));
817 end if;
819 -- Atomic
821 when Aspect_Atomic =>
822 if Is_Atomic (P) then
823 Set_Is_Atomic (E);
824 end if;
826 -- Atomic_Components
828 when Aspect_Atomic_Components =>
829 if Has_Atomic_Components (P) then
830 Set_Has_Atomic_Components (Base_Type (E));
831 end if;
833 -- Bit_Order
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;
844 -- Component_Size
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;
854 -- Machine_Radix
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;
863 -- Object_Size (also Size which also sets Object_Size)
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;
874 -- Pack
876 when Aspect_Pack =>
877 if not Is_Packed (E) then
878 Set_Is_Packed (Base_Type (E));
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;
886 -- Scalar_Storage_Order
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;
897 -- Small
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;
906 -- Storage_Size
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;
916 -- Value_Size
918 when Aspect_Value_Size =>
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.
924 null;
926 -- Volatile
928 when Aspect_Volatile =>
929 if Is_Volatile (P) then
930 Set_Is_Volatile (E);
931 end if;
933 -- Volatile_Components
935 when Aspect_Volatile_Components =>
936 if Has_Volatile_Components (P) then
937 Set_Has_Volatile_Components (Base_Type (E));
938 end if;
940 -- That should be all the Rep Aspects
942 when others =>
943 pragma Assert (Aspect_Delay (A_Id) /= Rep_Aspect);
944 null;
946 end case;
947 end if;
948 end if;
950 N := Next_Rep_Item (N);
951 end loop;
952 end Inherit_Delayed_Rep_Aspects;
954 -------------------------------------
955 -- Make_Pragma_From_Boolean_Aspect --
956 -------------------------------------
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);
966 Prag : Node_Id;
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.
973 -----------------------------------------
974 -- Check_False_Aspect_For_Derived_Type --
975 -----------------------------------------
977 procedure Check_False_Aspect_For_Derived_Type is
978 Par : Node_Id;
980 begin
981 -- We are only checking derived types
983 if not Is_Derived_Type (E) then
984 return;
985 end if;
987 Par := Nearest_Ancestor (E);
989 case A_Id is
990 when Aspect_Atomic | Aspect_Shared =>
991 if not Is_Atomic (Par) then
992 return;
993 end if;
995 when Aspect_Atomic_Components =>
996 if not Has_Atomic_Components (Par) then
997 return;
998 end if;
1000 when Aspect_Discard_Names =>
1001 if not Discard_Names (Par) then
1002 return;
1003 end if;
1005 when Aspect_Pack =>
1006 if not Is_Packed (Par) then
1007 return;
1008 end if;
1010 when Aspect_Unchecked_Union =>
1011 if not Is_Unchecked_Union (Par) then
1012 return;
1013 end if;
1015 when Aspect_Volatile =>
1016 if not Is_Volatile (Par) then
1017 return;
1018 end if;
1020 when Aspect_Volatile_Components =>
1021 if not Has_Volatile_Components (Par) then
1022 return;
1023 end if;
1025 when others =>
1026 return;
1027 end case;
1029 -- Fall through means we are canceling an inherited aspect
1031 Error_Msg_Name_1 := A_Name;
1032 Error_Msg_NE
1033 ("derived type& inherits aspect%, cannot cancel", Expr, E);
1035 end Check_False_Aspect_For_Derived_Type;
1037 -- Start of processing for Make_Pragma_From_Boolean_Aspect
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.
1044 if Is_False (Static_Boolean (Expr)) then
1045 Check_False_Aspect_For_Derived_Type;
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)))),
1054 Pragma_Identifier =>
1055 Make_Identifier (Sloc (Ident), Chars (Ident)));
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;
1065 -- Start of processing for Analyze_Aspects_At_Freeze_Point
1067 begin
1068 -- Must be visible in current scope
1070 if not Scope_Within_Or_Same (Current_Scope, Scope (E)) then
1071 return;
1072 end if;
1074 -- Look for aspect specification entries for this entity
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;
1081 if Is_Delayed_Aspect (ASN) then
1082 A_Id := Get_Aspect_Id (ASN);
1084 case A_Id is
1086 -- For aspects whose expression is an optional Boolean, make
1087 -- the corresponding pragma at the freezing point.
1089 when Boolean_Aspects |
1090 Library_Unit_Aspects =>
1091 Make_Pragma_From_Boolean_Aspect (ASN);
1093 -- Special handling for aspects that don't correspond to
1094 -- pragmas/attributes.
1096 when Aspect_Default_Value |
1097 Aspect_Default_Component_Value =>
1098 Analyze_Aspect_Default_Value (ASN);
1100 -- Ditto for iterator aspects, because the corresponding
1101 -- attributes may not have been analyzed yet.
1103 when Aspect_Constant_Indexing |
1104 Aspect_Variable_Indexing |
1105 Aspect_Default_Iterator |
1106 Aspect_Iterator_Element =>
1107 Analyze (Expression (ASN));
1109 when others =>
1110 null;
1111 end case;
1113 Ritem := Aspect_Rep_Item (ASN);
1115 if Present (Ritem) then
1116 Analyze (Ritem);
1117 end if;
1118 end if;
1119 end if;
1121 Next_Rep_Item (ASN);
1122 end loop;
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.
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;
1134 -----------------------------------
1135 -- Analyze_Aspect_Specifications --
1136 -----------------------------------
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.
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.
1150 ----------------------------------------
1151 -- Decorate_Delayed_Aspect_And_Pragma --
1152 ----------------------------------------
1154 procedure Decorate_Delayed_Aspect_And_Pragma
1155 (Asp : Node_Id;
1156 Prag : Node_Id)
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;
1167 ---------------------------
1168 -- Insert_Delayed_Pragma --
1169 ---------------------------
1171 procedure Insert_Delayed_Pragma (Prag : Node_Id) is
1172 Aux : Node_Id;
1174 begin
1175 -- When the context is a library unit, the pragma is added to the
1176 -- Pragmas_After list.
1178 if Nkind (Parent (N)) = N_Compilation_Unit then
1179 Aux := Aux_Decls_Node (Parent (N));
1181 if No (Pragmas_After (Aux)) then
1182 Set_Pragmas_After (Aux, New_List);
1183 end if;
1185 Prepend (Prag, Pragmas_After (Aux));
1187 -- Pragmas associated with subprogram bodies are inserted in the
1188 -- declarative part.
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
1198 -- There may be several aspects associated with the body;
1199 -- preserve the ordering of the corresponding pragmas.
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;
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;
1216 -- Default
1218 else
1219 Insert_After (N, Prag);
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).
1225 if Nkind (N) = N_Subprogram_Body_Stub then
1226 Analyze (Prag);
1227 end if;
1228 end if;
1229 end Insert_Delayed_Pragma;
1231 -- Local variables
1233 Aspect : Node_Id;
1234 Aitem : Node_Id;
1235 Ent : Node_Id;
1237 L : constant List_Id := Aspect_Specifications (N);
1239 Ins_Node : Node_Id := N;
1240 -- Insert pragmas/attribute definition clause after this node when no
1241 -- delayed analysis is required.
1243 -- Start of processing for Analyze_Aspect_Specifications
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.
1255 -- Some special cases don't require delay analysis, thus the aspect is
1256 -- analyzed right now.
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.
1264 begin
1265 pragma Assert (Present (L));
1267 -- Loop through aspects
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;
1279 Delay_Required : Boolean;
1280 -- Set False if delay is not required
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.
1286 procedure Analyze_Aspect_External_Or_Link_Name;
1287 -- Perform analysis of the External_Name or Link_Name aspects
1289 procedure Analyze_Aspect_Implicit_Dereference;
1290 -- Perform analysis of the Implicit_Dereference aspects
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.
1304 ------------------------------------------
1305 -- Analyze_Aspect_External_Or_Link_Name --
1306 ------------------------------------------
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.
1315 declare
1316 A : Node_Id;
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;
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;
1334 -----------------------------------------
1335 -- Analyze_Aspect_Implicit_Dereference --
1336 -----------------------------------------
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);
1344 else
1345 declare
1346 Disc : Entity_Id;
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;
1360 Next_Discriminant (Disc);
1361 end loop;
1363 -- Error if no proper access discriminant.
1365 Error_Msg_NE
1366 ("not an access discriminant of&", Expr, E);
1367 end;
1368 end if;
1369 end Analyze_Aspect_Implicit_Dereference;
1371 -----------------------
1372 -- Make_Aitem_Pragma --
1373 -----------------------
1375 procedure Make_Aitem_Pragma
1376 (Pragma_Argument_Associations : List_Id;
1377 Pragma_Name : Name_Id)
1379 Args : List_Id := Pragma_Argument_Associations;
1381 begin
1382 -- We should never get here if aspect was disabled
1384 pragma Assert (not Is_Disabled (Aspect));
1386 -- Certain aspects allow for an optional name or expression. Do
1387 -- not generate a pragma with empty argument association list.
1389 if No (Args) or else No (Expression (First (Args))) then
1390 Args := No_List;
1391 end if;
1393 -- Build the pragma
1395 Aitem :=
1396 Make_Pragma (Loc,
1397 Pragma_Argument_Associations => Args,
1398 Pragma_Identifier =>
1399 Make_Identifier (Sloc (Id), Pragma_Name),
1400 Class_Present => Class_Present (Aspect),
1401 Split_PPC => Split_PPC (Aspect));
1403 -- Set additional semantic fields
1405 if Is_Ignored (Aspect) then
1406 Set_Is_Ignored (Aitem);
1407 elsif Is_Checked (Aspect) then
1408 Set_Is_Checked (Aitem);
1409 end if;
1411 Set_Corresponding_Aspect (Aitem, Aspect);
1412 Set_From_Aspect_Specification (Aitem, True);
1413 end Make_Aitem_Pragma;
1415 -- Start of processing for Analyze_One_Aspect
1417 begin
1418 -- Skip aspect if already analyzed (not clear if this is needed)
1420 if Analyzed (Aspect) then
1421 goto Continue;
1422 end if;
1424 -- Skip looking at aspect if it is totally disabled. Just mark it
1425 -- as such for later reference in the tree. This also sets the
1426 -- Is_Ignored and Is_Checked flags appropriately.
1428 Check_Applicable_Policy (Aspect);
1430 if Is_Disabled (Aspect) then
1431 goto Continue;
1432 end if;
1434 -- Set the source location of expression, used in the case of
1435 -- a failed precondition/postcondition or invariant. Note that
1436 -- the source location of the expression is not usually the best
1437 -- choice here. For example, it gets located on the last AND
1438 -- keyword in a chain of boolean expressiond AND'ed together.
1439 -- It is best to put the message on the first character of the
1440 -- assertion, which is the effect of the First_Node call here.
1442 if Present (Expr) then
1443 Eloc := Sloc (First_Node (Expr));
1444 end if;
1446 -- Check restriction No_Implementation_Aspect_Specifications
1448 if Implementation_Defined_Aspect (A_Id) then
1449 Check_Restriction
1450 (No_Implementation_Aspect_Specifications, Aspect);
1451 end if;
1453 -- Check restriction No_Specification_Of_Aspect
1455 Check_Restriction_No_Specification_Of_Aspect (Aspect);
1457 -- Analyze this aspect (actual analysis is delayed till later)
1459 Set_Analyzed (Aspect);
1460 Set_Entity (Aspect, E);
1461 Ent := New_Occurrence_Of (E, Sloc (Id));
1463 -- Check for duplicate aspect. Note that the Comes_From_Source
1464 -- test allows duplicate Pre/Post's that we generate internally
1465 -- to escape being flagged here.
1467 if No_Duplicates_Allowed (A_Id) then
1468 Anod := First (L);
1469 while Anod /= Aspect loop
1470 if Comes_From_Source (Aspect)
1471 and then Same_Aspect (A_Id, Get_Aspect_Id (Anod))
1472 then
1473 Error_Msg_Name_1 := Nam;
1474 Error_Msg_Sloc := Sloc (Anod);
1476 -- Case of same aspect specified twice
1478 if Class_Present (Anod) = Class_Present (Aspect) then
1479 if not Class_Present (Anod) then
1480 Error_Msg_NE
1481 ("aspect% for & previously given#",
1482 Id, E);
1483 else
1484 Error_Msg_NE
1485 ("aspect `%''Class` for & previously given#",
1486 Id, E);
1487 end if;
1488 end if;
1489 end if;
1491 Next (Anod);
1492 end loop;
1493 end if;
1495 -- Check some general restrictions on language defined aspects
1497 if not Implementation_Defined_Aspect (A_Id) then
1498 Error_Msg_Name_1 := Nam;
1500 -- Not allowed for renaming declarations
1502 if Nkind (N) in N_Renaming_Declaration then
1503 Error_Msg_N
1504 ("aspect % not allowed for renaming declaration",
1505 Aspect);
1506 end if;
1508 -- Not allowed for formal type declarations
1510 if Nkind (N) = N_Formal_Type_Declaration then
1511 Error_Msg_N
1512 ("aspect % not allowed for formal type declaration",
1513 Aspect);
1514 end if;
1515 end if;
1517 -- Copy expression for later processing by the procedures
1518 -- Check_Aspect_At_[Freeze_Point | End_Of_Declarations]
1520 Set_Entity (Id, New_Copy_Tree (Expr));
1522 -- Set Delay_Required as appropriate to aspect
1524 case Aspect_Delay (A_Id) is
1525 when Always_Delay =>
1526 Delay_Required := True;
1528 when Never_Delay =>
1529 Delay_Required := False;
1531 when Rep_Aspect =>
1533 -- If expression has the form of an integer literal, then
1534 -- do not delay, since we know the value cannot change.
1535 -- This optimization catches most rep clause cases.
1537 if (Present (Expr) and then Nkind (Expr) = N_Integer_Literal)
1538 or else (A_Id in Boolean_Aspects and then No (Expr))
1539 then
1540 Delay_Required := False;
1541 else
1542 Delay_Required := True;
1543 Set_Has_Delayed_Rep_Aspects (E);
1544 end if;
1545 end case;
1547 -- Processing based on specific aspect
1549 case A_Id is
1551 -- No_Aspect should be impossible
1553 when No_Aspect =>
1554 raise Program_Error;
1556 -- Case 1: Aspects corresponding to attribute definition
1557 -- clauses.
1559 when Aspect_Address |
1560 Aspect_Alignment |
1561 Aspect_Bit_Order |
1562 Aspect_Component_Size |
1563 Aspect_Constant_Indexing |
1564 Aspect_Default_Iterator |
1565 Aspect_Dispatching_Domain |
1566 Aspect_External_Tag |
1567 Aspect_Input |
1568 Aspect_Iterator_Element |
1569 Aspect_Machine_Radix |
1570 Aspect_Object_Size |
1571 Aspect_Output |
1572 Aspect_Read |
1573 Aspect_Scalar_Storage_Order |
1574 Aspect_Size |
1575 Aspect_Small |
1576 Aspect_Simple_Storage_Pool |
1577 Aspect_Storage_Pool |
1578 Aspect_Stream_Size |
1579 Aspect_Value_Size |
1580 Aspect_Variable_Indexing |
1581 Aspect_Write =>
1583 -- Indexing aspects apply only to tagged type
1585 if (A_Id = Aspect_Constant_Indexing
1586 or else
1587 A_Id = Aspect_Variable_Indexing)
1588 and then not (Is_Type (E)
1589 and then Is_Tagged_Type (E))
1590 then
1591 Error_Msg_N ("indexing applies to a tagged type", N);
1592 goto Continue;
1593 end if;
1595 -- For case of address aspect, we don't consider that we
1596 -- know the entity is never set in the source, since it is
1597 -- is likely aliasing is occurring.
1599 -- Note: one might think that the analysis of the resulting
1600 -- attribute definition clause would take care of that, but
1601 -- that's not the case since it won't be from source.
1603 if A_Id = Aspect_Address then
1604 Set_Never_Set_In_Source (E, False);
1605 end if;
1607 -- Construct the attribute definition clause
1609 Aitem :=
1610 Make_Attribute_Definition_Clause (Loc,
1611 Name => Ent,
1612 Chars => Chars (Id),
1613 Expression => Relocate_Node (Expr));
1615 -- If the address is specified, then we treat the entity as
1616 -- referenced, to avoid spurious warnings. This is analogous
1617 -- to what is done with an attribute definition clause, but
1618 -- here we don't want to generate a reference because this
1619 -- is the point of definition of the entity.
1621 if A_Id = Aspect_Address then
1622 Set_Referenced (E);
1623 end if;
1625 -- Case 2: Aspects corresponding to pragmas
1627 -- Case 2a: Aspects corresponding to pragmas with two
1628 -- arguments, where the first argument is a local name
1629 -- referring to the entity, and the second argument is the
1630 -- aspect definition expression.
1632 -- Suppress/Unsuppress
1634 when Aspect_Suppress |
1635 Aspect_Unsuppress =>
1637 Make_Aitem_Pragma
1638 (Pragma_Argument_Associations => New_List (
1639 Make_Pragma_Argument_Association (Loc,
1640 Expression => New_Occurrence_Of (E, Loc)),
1641 Make_Pragma_Argument_Association (Sloc (Expr),
1642 Expression => Relocate_Node (Expr))),
1643 Pragma_Name => Chars (Id));
1645 -- Synchronization
1647 -- Corresponds to pragma Implemented, construct the pragma
1649 when Aspect_Synchronization =>
1651 Make_Aitem_Pragma
1652 (Pragma_Argument_Associations => New_List (
1653 Make_Pragma_Argument_Association (Loc,
1654 Expression => New_Occurrence_Of (E, Loc)),
1655 Make_Pragma_Argument_Association (Sloc (Expr),
1656 Expression => Relocate_Node (Expr))),
1657 Pragma_Name => Name_Implemented);
1659 -- Attach Handler
1661 when Aspect_Attach_Handler =>
1662 Make_Aitem_Pragma
1663 (Pragma_Argument_Associations => New_List (
1664 Make_Pragma_Argument_Association (Sloc (Ent),
1665 Expression => Ent),
1666 Make_Pragma_Argument_Association (Sloc (Expr),
1667 Expression => Relocate_Node (Expr))),
1668 Pragma_Name => Name_Attach_Handler);
1670 -- Dynamic_Predicate, Predicate, Static_Predicate
1672 when Aspect_Dynamic_Predicate |
1673 Aspect_Predicate |
1674 Aspect_Static_Predicate =>
1676 -- Construct the pragma (always a pragma Predicate, with
1677 -- flags recording whether it is static/dynamic). We also
1678 -- set flags recording this in the type itself.
1680 Make_Aitem_Pragma
1681 (Pragma_Argument_Associations => New_List (
1682 Make_Pragma_Argument_Association (Sloc (Ent),
1683 Expression => Ent),
1684 Make_Pragma_Argument_Association (Sloc (Expr),
1685 Expression => Relocate_Node (Expr))),
1686 Pragma_Name => Name_Predicate);
1688 -- Mark type has predicates, and remember what kind of
1689 -- aspect lead to this predicate (we need this to access
1690 -- the right set of check policies later on).
1692 Set_Has_Predicates (E);
1694 if A_Id = Aspect_Dynamic_Predicate then
1695 Set_Has_Dynamic_Predicate_Aspect (E);
1696 elsif A_Id = Aspect_Static_Predicate then
1697 Set_Has_Static_Predicate_Aspect (E);
1698 end if;
1700 -- If the type is private, indicate that its completion
1701 -- has a freeze node, because that is the one that will be
1702 -- visible at freeze time.
1704 if Is_Private_Type (E) and then Present (Full_View (E)) then
1705 Set_Has_Predicates (Full_View (E));
1707 if A_Id = Aspect_Dynamic_Predicate then
1708 Set_Has_Dynamic_Predicate_Aspect (Full_View (E));
1709 elsif A_Id = Aspect_Static_Predicate then
1710 Set_Has_Static_Predicate_Aspect (Full_View (E));
1711 end if;
1713 Set_Has_Delayed_Aspects (Full_View (E));
1714 Ensure_Freeze_Node (Full_View (E));
1715 end if;
1717 -- Case 2b: Aspects corresponding to pragmas with two
1718 -- arguments, where the second argument is a local name
1719 -- referring to the entity, and the first argument is the
1720 -- aspect definition expression.
1722 -- Convention
1724 when Aspect_Convention =>
1726 -- The aspect may be part of the specification of an import
1727 -- or export pragma. Scan the aspect list to gather the
1728 -- other components, if any. The name of the generated
1729 -- pragma is one of Convention/Import/Export.
1731 declare
1732 P_Name : Name_Id;
1733 A_Name : Name_Id;
1734 A : Node_Id;
1735 Arg_List : List_Id;
1736 Found : Boolean;
1737 L_Assoc : Node_Id;
1738 E_Assoc : Node_Id;
1740 begin
1741 P_Name := Chars (Id);
1742 Found := False;
1743 Arg_List := New_List;
1744 L_Assoc := Empty;
1745 E_Assoc := Empty;
1747 A := First (L);
1748 while Present (A) loop
1749 A_Name := Chars (Identifier (A));
1751 if Nam_In (A_Name, Name_Import, Name_Export) then
1752 if Found then
1753 Error_Msg_N ("conflicting", A);
1754 else
1755 Found := True;
1756 end if;
1758 P_Name := A_Name;
1760 elsif A_Name = Name_Link_Name then
1761 L_Assoc :=
1762 Make_Pragma_Argument_Association (Loc,
1763 Chars => A_Name,
1764 Expression => Relocate_Node (Expression (A)));
1766 elsif A_Name = Name_External_Name then
1767 E_Assoc :=
1768 Make_Pragma_Argument_Association (Loc,
1769 Chars => A_Name,
1770 Expression => Relocate_Node (Expression (A)));
1771 end if;
1773 Next (A);
1774 end loop;
1776 Arg_List := New_List (
1777 Make_Pragma_Argument_Association (Sloc (Expr),
1778 Expression => Relocate_Node (Expr)),
1779 Make_Pragma_Argument_Association (Sloc (Ent),
1780 Expression => Ent));
1782 if Present (L_Assoc) then
1783 Append_To (Arg_List, L_Assoc);
1784 end if;
1786 if Present (E_Assoc) then
1787 Append_To (Arg_List, E_Assoc);
1788 end if;
1790 Make_Aitem_Pragma
1791 (Pragma_Argument_Associations => Arg_List,
1792 Pragma_Name => P_Name);
1793 end;
1795 -- CPU, Interrupt_Priority, Priority
1797 -- These three aspects can be specified for a subprogram spec
1798 -- or body, in which case we analyze the expression and export
1799 -- the value of the aspect.
1801 -- Previously, we generated an equivalent pragma for bodies
1802 -- (note that the specs cannot contain these pragmas). The
1803 -- pragma was inserted ahead of local declarations, rather than
1804 -- after the body. This leads to a certain duplication between
1805 -- the processing performed for the aspect and the pragma, but
1806 -- given the straightforward handling required it is simpler
1807 -- to duplicate than to translate the aspect in the spec into
1808 -- a pragma in the declarative part of the body.
1810 when Aspect_CPU |
1811 Aspect_Interrupt_Priority |
1812 Aspect_Priority =>
1814 if Nkind_In (N, N_Subprogram_Body,
1815 N_Subprogram_Declaration)
1816 then
1817 -- Analyze the aspect expression
1819 Analyze_And_Resolve (Expr, Standard_Integer);
1821 -- Interrupt_Priority aspect not allowed for main
1822 -- subprograms. ARM D.1 does not forbid this explicitly,
1823 -- but ARM J.15.11 (6/3) does not permit pragma
1824 -- Interrupt_Priority for subprograms.
1826 if A_Id = Aspect_Interrupt_Priority then
1827 Error_Msg_N
1828 ("Interrupt_Priority aspect cannot apply to "
1829 & "subprogram", Expr);
1831 -- The expression must be static
1833 elsif not Is_Static_Expression (Expr) then
1834 Flag_Non_Static_Expr
1835 ("aspect requires static expression!", Expr);
1837 -- Check whether this is the main subprogram. Issue a
1838 -- warning only if it is obviously not a main program
1839 -- (when it has parameters or when the subprogram is
1840 -- within a package).
1842 elsif Present (Parameter_Specifications
1843 (Specification (N)))
1844 or else not Is_Compilation_Unit (Defining_Entity (N))
1845 then
1846 -- See ARM D.1 (14/3) and D.16 (12/3)
1848 Error_Msg_N
1849 ("aspect applied to subprogram other than the "
1850 & "main subprogram has no effect??", Expr);
1852 -- Otherwise check in range and export the value
1854 -- For the CPU aspect
1856 elsif A_Id = Aspect_CPU then
1857 if Is_In_Range (Expr, RTE (RE_CPU_Range)) then
1859 -- Value is correct so we export the value to make
1860 -- it available at execution time.
1862 Set_Main_CPU
1863 (Main_Unit, UI_To_Int (Expr_Value (Expr)));
1865 else
1866 Error_Msg_N
1867 ("main subprogram CPU is out of range", Expr);
1868 end if;
1870 -- For the Priority aspect
1872 elsif A_Id = Aspect_Priority then
1873 if Is_In_Range (Expr, RTE (RE_Priority)) then
1875 -- Value is correct so we export the value to make
1876 -- it available at execution time.
1878 Set_Main_Priority
1879 (Main_Unit, UI_To_Int (Expr_Value (Expr)));
1881 else
1882 Error_Msg_N
1883 ("main subprogram priority is out of range",
1884 Expr);
1885 end if;
1886 end if;
1888 -- Load an arbitrary entity from System.Tasking.Stages
1889 -- or System.Tasking.Restricted.Stages (depending on
1890 -- the supported profile) to make sure that one of these
1891 -- packages is implicitly with'ed, since we need to have
1892 -- the tasking run time active for the pragma Priority to
1893 -- have any effect. Previously with with'ed the package
1894 -- System.Tasking, but this package does not trigger the
1895 -- required initialization of the run-time library.
1897 declare
1898 Discard : Entity_Id;
1899 pragma Warnings (Off, Discard);
1900 begin
1901 if Restricted_Profile then
1902 Discard := RTE (RE_Activate_Restricted_Tasks);
1903 else
1904 Discard := RTE (RE_Activate_Tasks);
1905 end if;
1906 end;
1908 -- Handling for these Aspects in subprograms is complete
1910 goto Continue;
1912 -- For tasks
1914 else
1915 -- Pass the aspect as an attribute
1917 Aitem :=
1918 Make_Attribute_Definition_Clause (Loc,
1919 Name => Ent,
1920 Chars => Chars (Id),
1921 Expression => Relocate_Node (Expr));
1922 end if;
1924 -- Warnings
1926 when Aspect_Warnings =>
1927 Make_Aitem_Pragma
1928 (Pragma_Argument_Associations => New_List (
1929 Make_Pragma_Argument_Association (Sloc (Expr),
1930 Expression => Relocate_Node (Expr)),
1931 Make_Pragma_Argument_Association (Loc,
1932 Expression => New_Occurrence_Of (E, Loc))),
1933 Pragma_Name => Chars (Id));
1935 -- Case 2c: Aspects corresponding to pragmas with three
1936 -- arguments.
1938 -- Invariant aspects have a first argument that references the
1939 -- entity, a second argument that is the expression and a third
1940 -- argument that is an appropriate message.
1942 -- Invariant, Type_Invariant
1944 when Aspect_Invariant |
1945 Aspect_Type_Invariant =>
1947 -- Analysis of the pragma will verify placement legality:
1948 -- an invariant must apply to a private type, or appear in
1949 -- the private part of a spec and apply to a completion.
1951 Make_Aitem_Pragma
1952 (Pragma_Argument_Associations => New_List (
1953 Make_Pragma_Argument_Association (Sloc (Ent),
1954 Expression => Ent),
1955 Make_Pragma_Argument_Association (Sloc (Expr),
1956 Expression => Relocate_Node (Expr))),
1957 Pragma_Name => Name_Invariant);
1959 -- Add message unless exception messages are suppressed
1961 if not Opt.Exception_Locations_Suppressed then
1962 Append_To (Pragma_Argument_Associations (Aitem),
1963 Make_Pragma_Argument_Association (Eloc,
1964 Chars => Name_Message,
1965 Expression =>
1966 Make_String_Literal (Eloc,
1967 Strval => "failed invariant from "
1968 & Build_Location_String (Eloc))));
1969 end if;
1971 -- For Invariant case, insert immediately after the entity
1972 -- declaration. We do not have to worry about delay issues
1973 -- since the pragma processing takes care of this.
1975 Delay_Required := False;
1977 -- Case 2d : Aspects that correspond to a pragma with one
1978 -- argument.
1980 -- Abstract_State
1982 -- Aspect Abstract_State introduces implicit declarations for
1983 -- all state abstraction entities it defines. To emulate this
1984 -- behavior, insert the pragma at the beginning of the visible
1985 -- declarations of the related package so that it is analyzed
1986 -- immediately.
1988 when Aspect_Abstract_State => Abstract_State : declare
1989 Decls : List_Id;
1991 begin
1992 if Nkind_In (N, N_Generic_Package_Declaration,
1993 N_Package_Declaration)
1994 then
1995 Decls := Visible_Declarations (Specification (N));
1997 Make_Aitem_Pragma
1998 (Pragma_Argument_Associations => New_List (
1999 Make_Pragma_Argument_Association (Loc,
2000 Expression => Relocate_Node (Expr))),
2001 Pragma_Name => Name_Abstract_State);
2002 Decorate_Delayed_Aspect_And_Pragma (Aspect, Aitem);
2004 if No (Decls) then
2005 Decls := New_List;
2006 Set_Visible_Declarations (N, Decls);
2007 end if;
2009 Prepend_To (Decls, Aitem);
2011 else
2012 Error_Msg_NE
2013 ("aspect & must apply to a package declaration",
2014 Aspect, Id);
2015 end if;
2017 goto Continue;
2018 end Abstract_State;
2020 -- Depends
2022 -- Aspect Depends must be delayed because it mentions names
2023 -- of inputs and output that are classified by aspect Global.
2024 -- The aspect and pragma are treated the same way as a post
2025 -- condition.
2027 when Aspect_Depends =>
2028 Make_Aitem_Pragma
2029 (Pragma_Argument_Associations => New_List (
2030 Make_Pragma_Argument_Association (Loc,
2031 Expression => Relocate_Node (Expr))),
2032 Pragma_Name => Name_Depends);
2034 Decorate_Delayed_Aspect_And_Pragma (Aspect, Aitem);
2035 Insert_Delayed_Pragma (Aitem);
2036 goto Continue;
2038 -- Global
2040 -- Aspect Global must be delayed because it can mention names
2041 -- and benefit from the forward visibility rules applicable to
2042 -- aspects of subprograms. The aspect and pragma are treated
2043 -- the same way as a post condition.
2045 when Aspect_Global =>
2046 Make_Aitem_Pragma
2047 (Pragma_Argument_Associations => New_List (
2048 Make_Pragma_Argument_Association (Loc,
2049 Expression => Relocate_Node (Expr))),
2050 Pragma_Name => Name_Global);
2052 Decorate_Delayed_Aspect_And_Pragma (Aspect, Aitem);
2053 Insert_Delayed_Pragma (Aitem);
2054 goto Continue;
2056 -- Initial_Condition
2058 -- Aspect Initial_Condition covers the visible declarations of
2059 -- a package and all hidden states through functions. As such,
2060 -- it must be evaluated at the end of the said declarations.
2062 when Aspect_Initial_Condition => Initial_Condition : declare
2063 Decls : List_Id;
2065 begin
2066 if Nkind_In (N, N_Generic_Package_Declaration,
2067 N_Package_Declaration)
2068 then
2069 Decls := Visible_Declarations (Specification (N));
2071 Make_Aitem_Pragma
2072 (Pragma_Argument_Associations => New_List (
2073 Make_Pragma_Argument_Association (Loc,
2074 Expression => Relocate_Node (Expr))),
2075 Pragma_Name =>
2076 Name_Initial_Condition);
2077 Decorate_Delayed_Aspect_And_Pragma (Aspect, Aitem);
2079 if No (Decls) then
2080 Decls := New_List;
2081 Set_Visible_Declarations (N, Decls);
2082 end if;
2084 Prepend_To (Decls, Aitem);
2086 else
2087 Error_Msg_NE
2088 ("aspect & must apply to a package declaration",
2089 Aspect, Id);
2090 end if;
2092 goto Continue;
2093 end Initial_Condition;
2095 -- Initializes
2097 -- Aspect Initializes coverts the visible declarations of a
2098 -- package. As such, it must be evaluated at the end of the
2099 -- said declarations.
2101 when Aspect_Initializes => Initializes : declare
2102 Decls : List_Id;
2104 begin
2105 if Nkind_In (N, N_Generic_Package_Declaration,
2106 N_Package_Declaration)
2107 then
2108 Decls := Visible_Declarations (Specification (N));
2110 Make_Aitem_Pragma
2111 (Pragma_Argument_Associations => New_List (
2112 Make_Pragma_Argument_Association (Loc,
2113 Expression => Relocate_Node (Expr))),
2114 Pragma_Name => Name_Initializes);
2115 Decorate_Delayed_Aspect_And_Pragma (Aspect, Aitem);
2117 if No (Decls) then
2118 Decls := New_List;
2119 Set_Visible_Declarations (N, Decls);
2120 end if;
2122 Prepend_To (Decls, Aitem);
2124 else
2125 Error_Msg_NE
2126 ("aspect & must apply to a package declaration",
2127 Aspect, Id);
2128 end if;
2130 goto Continue;
2131 end Initializes;
2133 -- SPARK_Mode
2135 when Aspect_SPARK_Mode =>
2136 Make_Aitem_Pragma
2137 (Pragma_Argument_Associations => New_List (
2138 Make_Pragma_Argument_Association (Loc,
2139 Expression => Relocate_Node (Expr))),
2140 Pragma_Name => Name_SPARK_Mode);
2142 -- Refined_Depends
2144 -- Aspect Refined_Depends must be delayed because it can
2145 -- mention state refinements introduced by aspect Refined_State
2146 -- and further classified by aspect Refined_Global. Since both
2147 -- those aspects are delayed, so is Refined_Depends.
2149 when Aspect_Refined_Depends =>
2150 Make_Aitem_Pragma
2151 (Pragma_Argument_Associations => New_List (
2152 Make_Pragma_Argument_Association (Loc,
2153 Expression => Relocate_Node (Expr))),
2154 Pragma_Name => Name_Refined_Depends);
2156 Decorate_Delayed_Aspect_And_Pragma (Aspect, Aitem);
2157 Insert_Delayed_Pragma (Aitem);
2158 goto Continue;
2160 -- Refined_Global
2162 -- Aspect Refined_Global must be delayed because it can mention
2163 -- state refinements introduced by aspect Refined_State. Since
2164 -- Refined_State is already delayed due to forward references,
2165 -- so is Refined_Global.
2167 when Aspect_Refined_Global =>
2168 Make_Aitem_Pragma
2169 (Pragma_Argument_Associations => New_List (
2170 Make_Pragma_Argument_Association (Loc,
2171 Expression => Relocate_Node (Expr))),
2172 Pragma_Name => Name_Refined_Global);
2174 Decorate_Delayed_Aspect_And_Pragma (Aspect, Aitem);
2175 Insert_Delayed_Pragma (Aitem);
2176 goto Continue;
2178 -- Refined_Post
2180 when Aspect_Refined_Post =>
2181 Make_Aitem_Pragma
2182 (Pragma_Argument_Associations => New_List (
2183 Make_Pragma_Argument_Association (Loc,
2184 Expression => Relocate_Node (Expr))),
2185 Pragma_Name => Name_Refined_Post);
2187 -- Refined_State
2189 when Aspect_Refined_State => Refined_State : declare
2190 Decls : List_Id;
2192 begin
2193 -- The corresponding pragma for Refined_State is inserted in
2194 -- the declarations of the related package body. This action
2195 -- synchronizes both the source and from-aspect versions of
2196 -- the pragma.
2198 if Nkind (N) = N_Package_Body then
2199 Decls := Declarations (N);
2201 Make_Aitem_Pragma
2202 (Pragma_Argument_Associations => New_List (
2203 Make_Pragma_Argument_Association (Loc,
2204 Expression => Relocate_Node (Expr))),
2205 Pragma_Name => Name_Refined_State);
2206 Decorate_Delayed_Aspect_And_Pragma (Aspect, Aitem);
2208 if No (Decls) then
2209 Decls := New_List;
2210 Set_Declarations (N, Decls);
2211 end if;
2213 Prepend_To (Decls, Aitem);
2215 else
2216 Error_Msg_NE
2217 ("aspect & must apply to a package body", Aspect, Id);
2218 end if;
2220 goto Continue;
2221 end Refined_State;
2223 -- Relative_Deadline
2225 when Aspect_Relative_Deadline =>
2226 Make_Aitem_Pragma
2227 (Pragma_Argument_Associations => New_List (
2228 Make_Pragma_Argument_Association (Loc,
2229 Expression => Relocate_Node (Expr))),
2230 Pragma_Name => Name_Relative_Deadline);
2232 -- If the aspect applies to a task, the corresponding pragma
2233 -- must appear within its declarations, not after.
2235 if Nkind (N) = N_Task_Type_Declaration then
2236 declare
2237 Def : Node_Id;
2238 V : List_Id;
2240 begin
2241 if No (Task_Definition (N)) then
2242 Set_Task_Definition (N,
2243 Make_Task_Definition (Loc,
2244 Visible_Declarations => New_List,
2245 End_Label => Empty));
2246 end if;
2248 Def := Task_Definition (N);
2249 V := Visible_Declarations (Def);
2250 if not Is_Empty_List (V) then
2251 Insert_Before (First (V), Aitem);
2253 else
2254 Set_Visible_Declarations (Def, New_List (Aitem));
2255 end if;
2257 goto Continue;
2258 end;
2259 end if;
2261 -- Case 3 : Aspects that don't correspond to pragma/attribute
2262 -- definition clause.
2264 -- Case 3a: The aspects listed below don't correspond to
2265 -- pragmas/attributes but do require delayed analysis.
2267 -- Default_Value, Default_Component_Value
2269 when Aspect_Default_Value |
2270 Aspect_Default_Component_Value =>
2271 Aitem := Empty;
2273 -- Case 3b: The aspects listed below don't correspond to
2274 -- pragmas/attributes and don't need delayed analysis.
2276 -- Implicit_Dereference
2278 -- For Implicit_Dereference, External_Name and Link_Name, only
2279 -- the legality checks are done during the analysis, thus no
2280 -- delay is required.
2282 when Aspect_Implicit_Dereference =>
2283 Analyze_Aspect_Implicit_Dereference;
2284 goto Continue;
2286 -- External_Name, Link_Name
2288 when Aspect_External_Name |
2289 Aspect_Link_Name =>
2290 Analyze_Aspect_External_Or_Link_Name;
2291 goto Continue;
2293 -- Dimension
2295 when Aspect_Dimension =>
2296 Analyze_Aspect_Dimension (N, Id, Expr);
2297 goto Continue;
2299 -- Dimension_System
2301 when Aspect_Dimension_System =>
2302 Analyze_Aspect_Dimension_System (N, Id, Expr);
2303 goto Continue;
2305 -- Case 4: Aspects requiring special handling
2307 -- Pre/Post/Test_Case/Contract_Cases whose corresponding
2308 -- pragmas take care of the delay.
2310 -- Pre/Post
2312 -- Aspects Pre/Post generate Precondition/Postcondition pragmas
2313 -- with a first argument that is the expression, and a second
2314 -- argument that is an informative message if the test fails.
2315 -- This is inserted right after the declaration, to get the
2316 -- required pragma placement. The processing for the pragmas
2317 -- takes care of the required delay.
2319 when Pre_Post_Aspects => Pre_Post : declare
2320 Pname : Name_Id;
2322 begin
2323 if A_Id = Aspect_Pre or else A_Id = Aspect_Precondition then
2324 Pname := Name_Precondition;
2325 else
2326 Pname := Name_Postcondition;
2327 end if;
2329 -- If the expressions is of the form A and then B, then
2330 -- we generate separate Pre/Post aspects for the separate
2331 -- clauses. Since we allow multiple pragmas, there is no
2332 -- problem in allowing multiple Pre/Post aspects internally.
2333 -- These should be treated in reverse order (B first and
2334 -- A second) since they are later inserted just after N in
2335 -- the order they are treated. This way, the pragma for A
2336 -- ends up preceding the pragma for B, which may have an
2337 -- importance for the error raised (either constraint error
2338 -- or precondition error).
2340 -- We do not do this for Pre'Class, since we have to put
2341 -- these conditions together in a complex OR expression
2343 -- We do not do this in ASIS mode, as ASIS relies on the
2344 -- original node representing the complete expression, when
2345 -- retrieving it through the source aspect table.
2347 if not ASIS_Mode
2348 and then (Pname = Name_Postcondition
2349 or else not Class_Present (Aspect))
2350 then
2351 while Nkind (Expr) = N_And_Then loop
2352 Insert_After (Aspect,
2353 Make_Aspect_Specification (Sloc (Left_Opnd (Expr)),
2354 Identifier => Identifier (Aspect),
2355 Expression => Relocate_Node (Left_Opnd (Expr)),
2356 Class_Present => Class_Present (Aspect),
2357 Split_PPC => True));
2358 Rewrite (Expr, Relocate_Node (Right_Opnd (Expr)));
2359 Eloc := Sloc (Expr);
2360 end loop;
2361 end if;
2363 -- Build the precondition/postcondition pragma
2365 -- Add note about why we do NOT need Copy_Tree here ???
2367 Make_Aitem_Pragma
2368 (Pragma_Argument_Associations => New_List (
2369 Make_Pragma_Argument_Association (Eloc,
2370 Chars => Name_Check,
2371 Expression => Relocate_Node (Expr))),
2372 Pragma_Name => Pname);
2374 -- Add message unless exception messages are suppressed
2376 if not Opt.Exception_Locations_Suppressed then
2377 Append_To (Pragma_Argument_Associations (Aitem),
2378 Make_Pragma_Argument_Association (Eloc,
2379 Chars => Name_Message,
2380 Expression =>
2381 Make_String_Literal (Eloc,
2382 Strval => "failed "
2383 & Get_Name_String (Pname)
2384 & " from "
2385 & Build_Location_String (Eloc))));
2386 end if;
2388 Set_Is_Delayed_Aspect (Aspect);
2390 -- For Pre/Post cases, insert immediately after the entity
2391 -- declaration, since that is the required pragma placement.
2392 -- Note that for these aspects, we do not have to worry
2393 -- about delay issues, since the pragmas themselves deal
2394 -- with delay of visibility for the expression analysis.
2396 Insert_Delayed_Pragma (Aitem);
2397 goto Continue;
2398 end Pre_Post;
2400 -- Test_Case
2402 when Aspect_Test_Case => Test_Case : declare
2403 Args : List_Id;
2404 Comp_Expr : Node_Id;
2405 Comp_Assn : Node_Id;
2406 New_Expr : Node_Id;
2408 begin
2409 Args := New_List;
2411 if Nkind (Parent (N)) = N_Compilation_Unit then
2412 Error_Msg_Name_1 := Nam;
2413 Error_Msg_N ("incorrect placement of aspect `%`", E);
2414 goto Continue;
2415 end if;
2417 if Nkind (Expr) /= N_Aggregate then
2418 Error_Msg_Name_1 := Nam;
2419 Error_Msg_NE
2420 ("wrong syntax for aspect `%` for &", Id, E);
2421 goto Continue;
2422 end if;
2424 -- Make pragma expressions refer to the original aspect
2425 -- expressions through the Original_Node link. This is
2426 -- used in semantic analysis for ASIS mode, so that the
2427 -- original expression also gets analyzed.
2429 Comp_Expr := First (Expressions (Expr));
2430 while Present (Comp_Expr) loop
2431 New_Expr := Relocate_Node (Comp_Expr);
2432 Set_Original_Node (New_Expr, Comp_Expr);
2433 Append_To (Args,
2434 Make_Pragma_Argument_Association (Sloc (Comp_Expr),
2435 Expression => New_Expr));
2436 Next (Comp_Expr);
2437 end loop;
2439 Comp_Assn := First (Component_Associations (Expr));
2440 while Present (Comp_Assn) loop
2441 if List_Length (Choices (Comp_Assn)) /= 1
2442 or else
2443 Nkind (First (Choices (Comp_Assn))) /= N_Identifier
2444 then
2445 Error_Msg_Name_1 := Nam;
2446 Error_Msg_NE
2447 ("wrong syntax for aspect `%` for &", Id, E);
2448 goto Continue;
2449 end if;
2451 New_Expr := Relocate_Node (Expression (Comp_Assn));
2452 Set_Original_Node (New_Expr, Expression (Comp_Assn));
2453 Append_To (Args,
2454 Make_Pragma_Argument_Association (Sloc (Comp_Assn),
2455 Chars => Chars (First (Choices (Comp_Assn))),
2456 Expression => New_Expr));
2457 Next (Comp_Assn);
2458 end loop;
2460 -- Build the test-case pragma
2462 Make_Aitem_Pragma
2463 (Pragma_Argument_Associations => Args,
2464 Pragma_Name => Nam);
2465 end Test_Case;
2467 -- Contract_Cases
2469 when Aspect_Contract_Cases =>
2470 Make_Aitem_Pragma
2471 (Pragma_Argument_Associations => New_List (
2472 Make_Pragma_Argument_Association (Loc,
2473 Expression => Relocate_Node (Expr))),
2474 Pragma_Name => Nam);
2476 Decorate_Delayed_Aspect_And_Pragma (Aspect, Aitem);
2477 Insert_Delayed_Pragma (Aitem);
2478 goto Continue;
2480 -- Case 5: Special handling for aspects with an optional
2481 -- boolean argument.
2483 -- In the general case, the corresponding pragma cannot be
2484 -- generated yet because the evaluation of the boolean needs
2485 -- to be delayed till the freeze point.
2487 when Boolean_Aspects |
2488 Library_Unit_Aspects =>
2490 Set_Is_Boolean_Aspect (Aspect);
2492 -- Lock_Free aspect only apply to protected objects
2494 if A_Id = Aspect_Lock_Free then
2495 if Ekind (E) /= E_Protected_Type then
2496 Error_Msg_Name_1 := Nam;
2497 Error_Msg_N
2498 ("aspect % only applies to a protected object",
2499 Aspect);
2501 else
2502 -- Set the Uses_Lock_Free flag to True if there is no
2503 -- expression or if the expression is True. The
2504 -- evaluation of this aspect should be delayed to the
2505 -- freeze point (why???)
2507 if No (Expr)
2508 or else Is_True (Static_Boolean (Expr))
2509 then
2510 Set_Uses_Lock_Free (E);
2511 end if;
2513 Record_Rep_Item (E, Aspect);
2514 end if;
2516 goto Continue;
2518 elsif A_Id = Aspect_Import or else A_Id = Aspect_Export then
2520 -- Verify that there is an aspect Convention that will
2521 -- incorporate the Import/Export aspect, and eventual
2522 -- Link/External names.
2524 declare
2525 A : Node_Id;
2527 begin
2528 A := First (L);
2529 while Present (A) loop
2530 exit when Chars (Identifier (A)) = Name_Convention;
2531 Next (A);
2532 end loop;
2534 -- It is legal to specify Import for a variable, in
2535 -- order to suppress initialization for it, without
2536 -- specifying explicitly its convention. However this
2537 -- is only legal if the convention of the object type
2538 -- is Ada or similar.
2540 if No (A) then
2541 if Ekind (E) = E_Variable
2542 and then A_Id = Aspect_Import
2543 then
2544 declare
2545 C : constant Convention_Id :=
2546 Convention (Etype (E));
2547 begin
2548 if C = Convention_Ada or else
2549 C = Convention_Ada_Pass_By_Copy or else
2550 C = Convention_Ada_Pass_By_Reference
2551 then
2552 goto Continue;
2553 end if;
2554 end;
2555 end if;
2557 -- Otherwise, Convention must be specified
2559 Error_Msg_N
2560 ("missing Convention aspect for Export/Import",
2561 Aspect);
2562 end if;
2563 end;
2565 goto Continue;
2566 end if;
2568 -- Library unit aspects require special handling in the case
2569 -- of a package declaration, the pragma needs to be inserted
2570 -- in the list of declarations for the associated package.
2571 -- There is no issue of visibility delay for these aspects.
2573 if A_Id in Library_Unit_Aspects
2574 and then
2575 Nkind_In (N, N_Package_Declaration,
2576 N_Generic_Package_Declaration)
2577 and then Nkind (Parent (N)) /= N_Compilation_Unit
2578 then
2579 Error_Msg_N
2580 ("incorrect context for library unit aspect&", Id);
2581 goto Continue;
2582 end if;
2584 -- Cases where we do not delay, includes all cases where
2585 -- the expression is missing other than the above cases.
2587 if not Delay_Required or else No (Expr) then
2588 Make_Aitem_Pragma
2589 (Pragma_Argument_Associations => New_List (
2590 Make_Pragma_Argument_Association (Sloc (Ent),
2591 Expression => Ent)),
2592 Pragma_Name => Chars (Id));
2593 Delay_Required := False;
2595 -- In general cases, the corresponding pragma/attribute
2596 -- definition clause will be inserted later at the freezing
2597 -- point, and we do not need to build it now
2599 else
2600 Aitem := Empty;
2601 end if;
2603 -- Storage_Size
2605 -- This is special because for access types we need to generate
2606 -- an attribute definition clause. This also works for single
2607 -- task declarations, but it does not work for task type
2608 -- declarations, because we have the case where the expression
2609 -- references a discriminant of the task type. That can't use
2610 -- an attribute definition clause because we would not have
2611 -- visibility on the discriminant. For that case we must
2612 -- generate a pragma in the task definition.
2614 when Aspect_Storage_Size =>
2616 -- Task type case
2618 if Ekind (E) = E_Task_Type then
2619 declare
2620 Decl : constant Node_Id := Declaration_Node (E);
2622 begin
2623 pragma Assert (Nkind (Decl) = N_Task_Type_Declaration);
2625 -- If no task definition, create one
2627 if No (Task_Definition (Decl)) then
2628 Set_Task_Definition (Decl,
2629 Make_Task_Definition (Loc,
2630 Visible_Declarations => Empty_List,
2631 End_Label => Empty));
2632 end if;
2634 -- Create a pragma and put it at the start of the
2635 -- task definition for the task type declaration.
2637 Make_Aitem_Pragma
2638 (Pragma_Argument_Associations => New_List (
2639 Make_Pragma_Argument_Association (Loc,
2640 Expression => Relocate_Node (Expr))),
2641 Pragma_Name => Name_Storage_Size);
2643 Prepend
2644 (Aitem,
2645 Visible_Declarations (Task_Definition (Decl)));
2646 goto Continue;
2647 end;
2649 -- All other cases, generate attribute definition
2651 else
2652 Aitem :=
2653 Make_Attribute_Definition_Clause (Loc,
2654 Name => Ent,
2655 Chars => Chars (Id),
2656 Expression => Relocate_Node (Expr));
2657 end if;
2658 end case;
2660 -- Attach the corresponding pragma/attribute definition clause to
2661 -- the aspect specification node.
2663 if Present (Aitem) then
2664 Set_From_Aspect_Specification (Aitem, True);
2665 end if;
2667 -- In the context of a compilation unit, we directly put the
2668 -- pragma in the Pragmas_After list of the N_Compilation_Unit_Aux
2669 -- node (no delay is required here) except for aspects on a
2670 -- subprogram body (see below) and a generic package, for which
2671 -- we need to introduce the pragma before building the generic
2672 -- copy (see sem_ch12), and for package instantiations, where
2673 -- the library unit pragmas are better handled early.
2675 if Nkind (Parent (N)) = N_Compilation_Unit
2676 and then (Present (Aitem) or else Is_Boolean_Aspect (Aspect))
2677 then
2678 declare
2679 Aux : constant Node_Id := Aux_Decls_Node (Parent (N));
2681 begin
2682 pragma Assert (Nkind (Aux) = N_Compilation_Unit_Aux);
2684 -- For a Boolean aspect, create the corresponding pragma if
2685 -- no expression or if the value is True.
2687 if Is_Boolean_Aspect (Aspect) and then No (Aitem) then
2688 if Is_True (Static_Boolean (Expr)) then
2689 Make_Aitem_Pragma
2690 (Pragma_Argument_Associations => New_List (
2691 Make_Pragma_Argument_Association (Sloc (Ent),
2692 Expression => Ent)),
2693 Pragma_Name => Chars (Id));
2695 Set_From_Aspect_Specification (Aitem, True);
2696 Set_Corresponding_Aspect (Aitem, Aspect);
2698 else
2699 goto Continue;
2700 end if;
2701 end if;
2703 -- If the aspect is on a subprogram body (relevant aspect
2704 -- is Inline), add the pragma in front of the declarations.
2706 if Nkind (N) = N_Subprogram_Body then
2707 if No (Declarations (N)) then
2708 Set_Declarations (N, New_List);
2709 end if;
2711 Prepend (Aitem, Declarations (N));
2713 elsif Nkind (N) = N_Generic_Package_Declaration then
2714 if No (Visible_Declarations (Specification (N))) then
2715 Set_Visible_Declarations (Specification (N), New_List);
2716 end if;
2718 Prepend (Aitem,
2719 Visible_Declarations (Specification (N)));
2721 elsif Nkind (N) = N_Package_Instantiation then
2722 declare
2723 Spec : constant Node_Id :=
2724 Specification (Instance_Spec (N));
2725 begin
2726 if No (Visible_Declarations (Spec)) then
2727 Set_Visible_Declarations (Spec, New_List);
2728 end if;
2730 Prepend (Aitem, Visible_Declarations (Spec));
2731 end;
2733 else
2734 if No (Pragmas_After (Aux)) then
2735 Set_Pragmas_After (Aux, New_List);
2736 end if;
2738 Append (Aitem, Pragmas_After (Aux));
2739 end if;
2741 goto Continue;
2742 end;
2743 end if;
2745 -- The evaluation of the aspect is delayed to the freezing point.
2746 -- The pragma or attribute clause if there is one is then attached
2747 -- to the aspect specification which is put in the rep item list.
2749 if Delay_Required then
2750 if Present (Aitem) then
2751 Set_Is_Delayed_Aspect (Aitem);
2752 Set_Aspect_Rep_Item (Aspect, Aitem);
2753 Set_Parent (Aitem, Aspect);
2754 end if;
2756 Set_Is_Delayed_Aspect (Aspect);
2758 -- In the case of Default_Value, link the aspect to base type
2759 -- as well, even though it appears on a first subtype. This is
2760 -- mandated by the semantics of the aspect. Do not establish
2761 -- the link when processing the base type itself as this leads
2762 -- to a rep item circularity. Verify that we are dealing with
2763 -- a scalar type to prevent cascaded errors.
2765 if A_Id = Aspect_Default_Value
2766 and then Is_Scalar_Type (E)
2767 and then Base_Type (E) /= E
2768 then
2769 Set_Has_Delayed_Aspects (Base_Type (E));
2770 Record_Rep_Item (Base_Type (E), Aspect);
2771 end if;
2773 Set_Has_Delayed_Aspects (E);
2774 Record_Rep_Item (E, Aspect);
2776 -- When delay is not required and the context is a package or a
2777 -- subprogram body, insert the pragma in the body declarations.
2779 elsif Nkind_In (N, N_Package_Body, N_Subprogram_Body) then
2780 if No (Declarations (N)) then
2781 Set_Declarations (N, New_List);
2782 end if;
2784 -- The pragma is added before source declarations
2786 Prepend_To (Declarations (N), Aitem);
2788 -- When delay is not required and the context is not a compilation
2789 -- unit, we simply insert the pragma/attribute definition clause
2790 -- in sequence.
2792 else
2793 Insert_After (Ins_Node, Aitem);
2794 Ins_Node := Aitem;
2795 end if;
2796 end Analyze_One_Aspect;
2798 <<Continue>>
2799 Next (Aspect);
2800 end loop Aspect_Loop;
2802 if Has_Delayed_Aspects (E) then
2803 Ensure_Freeze_Node (E);
2804 end if;
2805 end Analyze_Aspect_Specifications;
2807 -----------------------
2808 -- Analyze_At_Clause --
2809 -----------------------
2811 -- An at clause is replaced by the corresponding Address attribute
2812 -- definition clause that is the preferred approach in Ada 95.
2814 procedure Analyze_At_Clause (N : Node_Id) is
2815 CS : constant Boolean := Comes_From_Source (N);
2817 begin
2818 -- This is an obsolescent feature
2820 Check_Restriction (No_Obsolescent_Features, N);
2822 if Warn_On_Obsolescent_Feature then
2823 Error_Msg_N
2824 ("?j?at clause is an obsolescent feature (RM J.7(2))", N);
2825 Error_Msg_N
2826 ("\?j?use address attribute definition clause instead", N);
2827 end if;
2829 -- Rewrite as address clause
2831 Rewrite (N,
2832 Make_Attribute_Definition_Clause (Sloc (N),
2833 Name => Identifier (N),
2834 Chars => Name_Address,
2835 Expression => Expression (N)));
2837 -- We preserve Comes_From_Source, since logically the clause still comes
2838 -- from the source program even though it is changed in form.
2840 Set_Comes_From_Source (N, CS);
2842 -- Analyze rewritten clause
2844 Analyze_Attribute_Definition_Clause (N);
2845 end Analyze_At_Clause;
2847 -----------------------------------------
2848 -- Analyze_Attribute_Definition_Clause --
2849 -----------------------------------------
2851 procedure Analyze_Attribute_Definition_Clause (N : Node_Id) is
2852 Loc : constant Source_Ptr := Sloc (N);
2853 Nam : constant Node_Id := Name (N);
2854 Attr : constant Name_Id := Chars (N);
2855 Expr : constant Node_Id := Expression (N);
2856 Id : constant Attribute_Id := Get_Attribute_Id (Attr);
2858 Ent : Entity_Id;
2859 -- The entity of Nam after it is analyzed. In the case of an incomplete
2860 -- type, this is the underlying type.
2862 U_Ent : Entity_Id;
2863 -- The underlying entity to which the attribute applies. Generally this
2864 -- is the Underlying_Type of Ent, except in the case where the clause
2865 -- applies to full view of incomplete type or private type in which case
2866 -- U_Ent is just a copy of Ent.
2868 FOnly : Boolean := False;
2869 -- Reset to True for subtype specific attribute (Alignment, Size)
2870 -- and for stream attributes, i.e. those cases where in the call
2871 -- to Rep_Item_Too_Late, FOnly is set True so that only the freezing
2872 -- rules are checked. Note that the case of stream attributes is not
2873 -- clear from the RM, but see AI95-00137. Also, the RM seems to
2874 -- disallow Storage_Size for derived task types, but that is also
2875 -- clearly unintentional.
2877 procedure Analyze_Stream_TSS_Definition (TSS_Nam : TSS_Name_Type);
2878 -- Common processing for 'Read, 'Write, 'Input and 'Output attribute
2879 -- definition clauses.
2881 function Duplicate_Clause return Boolean;
2882 -- This routine checks if the aspect for U_Ent being given by attribute
2883 -- definition clause N is for an aspect that has already been specified,
2884 -- and if so gives an error message. If there is a duplicate, True is
2885 -- returned, otherwise if there is no error, False is returned.
2887 procedure Check_Indexing_Functions;
2888 -- Check that the function in Constant_Indexing or Variable_Indexing
2889 -- attribute has the proper type structure. If the name is overloaded,
2890 -- check that some interpretation is legal.
2892 procedure Check_Iterator_Functions;
2893 -- Check that there is a single function in Default_Iterator attribute
2894 -- has the proper type structure.
2896 function Check_Primitive_Function (Subp : Entity_Id) return Boolean;
2897 -- Common legality check for the previous two
2899 -----------------------------------
2900 -- Analyze_Stream_TSS_Definition --
2901 -----------------------------------
2903 procedure Analyze_Stream_TSS_Definition (TSS_Nam : TSS_Name_Type) is
2904 Subp : Entity_Id := Empty;
2905 I : Interp_Index;
2906 It : Interp;
2907 Pnam : Entity_Id;
2909 Is_Read : constant Boolean := (TSS_Nam = TSS_Stream_Read);
2910 -- True for Read attribute, false for other attributes
2912 function Has_Good_Profile (Subp : Entity_Id) return Boolean;
2913 -- Return true if the entity is a subprogram with an appropriate
2914 -- profile for the attribute being defined.
2916 ----------------------
2917 -- Has_Good_Profile --
2918 ----------------------
2920 function Has_Good_Profile (Subp : Entity_Id) return Boolean is
2921 F : Entity_Id;
2922 Is_Function : constant Boolean := (TSS_Nam = TSS_Stream_Input);
2923 Expected_Ekind : constant array (Boolean) of Entity_Kind :=
2924 (False => E_Procedure, True => E_Function);
2925 Typ : Entity_Id;
2927 begin
2928 if Ekind (Subp) /= Expected_Ekind (Is_Function) then
2929 return False;
2930 end if;
2932 F := First_Formal (Subp);
2934 if No (F)
2935 or else Ekind (Etype (F)) /= E_Anonymous_Access_Type
2936 or else Designated_Type (Etype (F)) /=
2937 Class_Wide_Type (RTE (RE_Root_Stream_Type))
2938 then
2939 return False;
2940 end if;
2942 if not Is_Function then
2943 Next_Formal (F);
2945 declare
2946 Expected_Mode : constant array (Boolean) of Entity_Kind :=
2947 (False => E_In_Parameter,
2948 True => E_Out_Parameter);
2949 begin
2950 if Parameter_Mode (F) /= Expected_Mode (Is_Read) then
2951 return False;
2952 end if;
2953 end;
2955 Typ := Etype (F);
2957 else
2958 Typ := Etype (Subp);
2959 end if;
2961 return Base_Type (Typ) = Base_Type (Ent)
2962 and then No (Next_Formal (F));
2963 end Has_Good_Profile;
2965 -- Start of processing for Analyze_Stream_TSS_Definition
2967 begin
2968 FOnly := True;
2970 if not Is_Type (U_Ent) then
2971 Error_Msg_N ("local name must be a subtype", Nam);
2972 return;
2973 end if;
2975 Pnam := TSS (Base_Type (U_Ent), TSS_Nam);
2977 -- If Pnam is present, it can be either inherited from an ancestor
2978 -- type (in which case it is legal to redefine it for this type), or
2979 -- be a previous definition of the attribute for the same type (in
2980 -- which case it is illegal).
2982 -- In the first case, it will have been analyzed already, and we
2983 -- can check that its profile does not match the expected profile
2984 -- for a stream attribute of U_Ent. In the second case, either Pnam
2985 -- has been analyzed (and has the expected profile), or it has not
2986 -- been analyzed yet (case of a type that has not been frozen yet
2987 -- and for which the stream attribute has been set using Set_TSS).
2989 if Present (Pnam)
2990 and then (No (First_Entity (Pnam)) or else Has_Good_Profile (Pnam))
2991 then
2992 Error_Msg_Sloc := Sloc (Pnam);
2993 Error_Msg_Name_1 := Attr;
2994 Error_Msg_N ("% attribute already defined #", Nam);
2995 return;
2996 end if;
2998 Analyze (Expr);
3000 if Is_Entity_Name (Expr) then
3001 if not Is_Overloaded (Expr) then
3002 if Has_Good_Profile (Entity (Expr)) then
3003 Subp := Entity (Expr);
3004 end if;
3006 else
3007 Get_First_Interp (Expr, I, It);
3008 while Present (It.Nam) loop
3009 if Has_Good_Profile (It.Nam) then
3010 Subp := It.Nam;
3011 exit;
3012 end if;
3014 Get_Next_Interp (I, It);
3015 end loop;
3016 end if;
3017 end if;
3019 if Present (Subp) then
3020 if Is_Abstract_Subprogram (Subp) then
3021 Error_Msg_N ("stream subprogram must not be abstract", Expr);
3022 return;
3023 end if;
3025 Set_Entity (Expr, Subp);
3026 Set_Etype (Expr, Etype (Subp));
3028 New_Stream_Subprogram (N, U_Ent, Subp, TSS_Nam);
3030 else
3031 Error_Msg_Name_1 := Attr;
3032 Error_Msg_N ("incorrect expression for% attribute", Expr);
3033 end if;
3034 end Analyze_Stream_TSS_Definition;
3036 ------------------------------
3037 -- Check_Indexing_Functions --
3038 ------------------------------
3040 procedure Check_Indexing_Functions is
3041 Indexing_Found : Boolean;
3043 procedure Check_One_Function (Subp : Entity_Id);
3044 -- Check one possible interpretation. Sets Indexing_Found True if an
3045 -- indexing function is found.
3047 ------------------------
3048 -- Check_One_Function --
3049 ------------------------
3051 procedure Check_One_Function (Subp : Entity_Id) is
3052 Default_Element : constant Node_Id :=
3053 Find_Value_Of_Aspect
3054 (Etype (First_Formal (Subp)),
3055 Aspect_Iterator_Element);
3057 begin
3058 if not Check_Primitive_Function (Subp)
3059 and then not Is_Overloaded (Expr)
3060 then
3061 Error_Msg_NE
3062 ("aspect Indexing requires a function that applies to type&",
3063 Subp, Ent);
3064 end if;
3066 -- An indexing function must return either the default element of
3067 -- the container, or a reference type. For variable indexing it
3068 -- must be the latter.
3070 if Present (Default_Element) then
3071 Analyze (Default_Element);
3073 if Is_Entity_Name (Default_Element)
3074 and then Covers (Entity (Default_Element), Etype (Subp))
3075 then
3076 Indexing_Found := True;
3077 return;
3078 end if;
3079 end if;
3081 -- For variable_indexing the return type must be a reference type
3083 if Attr = Name_Variable_Indexing
3084 and then not Has_Implicit_Dereference (Etype (Subp))
3085 then
3086 Error_Msg_N
3087 ("function for indexing must return a reference type", Subp);
3089 else
3090 Indexing_Found := True;
3091 end if;
3092 end Check_One_Function;
3094 -- Start of processing for Check_Indexing_Functions
3096 begin
3097 if In_Instance then
3098 return;
3099 end if;
3101 Analyze (Expr);
3103 if not Is_Overloaded (Expr) then
3104 Check_One_Function (Entity (Expr));
3106 else
3107 declare
3108 I : Interp_Index;
3109 It : Interp;
3111 begin
3112 Indexing_Found := False;
3113 Get_First_Interp (Expr, I, It);
3114 while Present (It.Nam) loop
3116 -- Note that analysis will have added the interpretation
3117 -- that corresponds to the dereference. We only check the
3118 -- subprogram itself.
3120 if Is_Overloadable (It.Nam) then
3121 Check_One_Function (It.Nam);
3122 end if;
3124 Get_Next_Interp (I, It);
3125 end loop;
3127 if not Indexing_Found then
3128 Error_Msg_NE
3129 ("aspect Indexing requires a function that "
3130 & "applies to type&", Expr, Ent);
3131 end if;
3132 end;
3133 end if;
3134 end Check_Indexing_Functions;
3136 ------------------------------
3137 -- Check_Iterator_Functions --
3138 ------------------------------
3140 procedure Check_Iterator_Functions is
3141 Default : Entity_Id;
3143 function Valid_Default_Iterator (Subp : Entity_Id) return Boolean;
3144 -- Check one possible interpretation for validity
3146 ----------------------------
3147 -- Valid_Default_Iterator --
3148 ----------------------------
3150 function Valid_Default_Iterator (Subp : Entity_Id) return Boolean is
3151 Formal : Entity_Id;
3153 begin
3154 if not Check_Primitive_Function (Subp) then
3155 return False;
3156 else
3157 Formal := First_Formal (Subp);
3158 end if;
3160 -- False if any subsequent formal has no default expression
3162 Formal := Next_Formal (Formal);
3163 while Present (Formal) loop
3164 if No (Expression (Parent (Formal))) then
3165 return False;
3166 end if;
3168 Next_Formal (Formal);
3169 end loop;
3171 -- True if all subsequent formals have default expressions
3173 return True;
3174 end Valid_Default_Iterator;
3176 -- Start of processing for Check_Iterator_Functions
3178 begin
3179 Analyze (Expr);
3181 if not Is_Entity_Name (Expr) then
3182 Error_Msg_N ("aspect Iterator must be a function name", Expr);
3183 end if;
3185 if not Is_Overloaded (Expr) then
3186 if not Check_Primitive_Function (Entity (Expr)) then
3187 Error_Msg_NE
3188 ("aspect Indexing requires a function that applies to type&",
3189 Entity (Expr), Ent);
3190 end if;
3192 if not Valid_Default_Iterator (Entity (Expr)) then
3193 Error_Msg_N ("improper function for default iterator", Expr);
3194 end if;
3196 else
3197 Default := Empty;
3198 declare
3199 I : Interp_Index;
3200 It : Interp;
3202 begin
3203 Get_First_Interp (Expr, I, It);
3204 while Present (It.Nam) loop
3205 if not Check_Primitive_Function (It.Nam)
3206 or else not Valid_Default_Iterator (It.Nam)
3207 then
3208 Remove_Interp (I);
3210 elsif Present (Default) then
3211 Error_Msg_N ("default iterator must be unique", Expr);
3213 else
3214 Default := It.Nam;
3215 end if;
3217 Get_Next_Interp (I, It);
3218 end loop;
3219 end;
3221 if Present (Default) then
3222 Set_Entity (Expr, Default);
3223 Set_Is_Overloaded (Expr, False);
3224 end if;
3225 end if;
3226 end Check_Iterator_Functions;
3228 -------------------------------
3229 -- Check_Primitive_Function --
3230 -------------------------------
3232 function Check_Primitive_Function (Subp : Entity_Id) return Boolean is
3233 Ctrl : Entity_Id;
3235 begin
3236 if Ekind (Subp) /= E_Function then
3237 return False;
3238 end if;
3240 if No (First_Formal (Subp)) then
3241 return False;
3242 else
3243 Ctrl := Etype (First_Formal (Subp));
3244 end if;
3246 if Ctrl = Ent
3247 or else Ctrl = Class_Wide_Type (Ent)
3248 or else
3249 (Ekind (Ctrl) = E_Anonymous_Access_Type
3250 and then
3251 (Designated_Type (Ctrl) = Ent
3252 or else Designated_Type (Ctrl) = Class_Wide_Type (Ent)))
3253 then
3254 null;
3256 else
3257 return False;
3258 end if;
3260 return True;
3261 end Check_Primitive_Function;
3263 ----------------------
3264 -- Duplicate_Clause --
3265 ----------------------
3267 function Duplicate_Clause return Boolean is
3268 A : Node_Id;
3270 begin
3271 -- Nothing to do if this attribute definition clause comes from
3272 -- an aspect specification, since we could not be duplicating an
3273 -- explicit clause, and we dealt with the case of duplicated aspects
3274 -- in Analyze_Aspect_Specifications.
3276 if From_Aspect_Specification (N) then
3277 return False;
3278 end if;
3280 -- Otherwise current clause may duplicate previous clause, or a
3281 -- previously given pragma or aspect specification for the same
3282 -- aspect.
3284 A := Get_Rep_Item (U_Ent, Chars (N), Check_Parents => False);
3286 if Present (A) then
3287 Error_Msg_Name_1 := Chars (N);
3288 Error_Msg_Sloc := Sloc (A);
3290 Error_Msg_NE ("aspect% for & previously given#", N, U_Ent);
3291 return True;
3292 end if;
3294 return False;
3295 end Duplicate_Clause;
3297 -- Start of processing for Analyze_Attribute_Definition_Clause
3299 begin
3300 -- The following code is a defense against recursion. Not clear that
3301 -- this can happen legitimately, but perhaps some error situations
3302 -- can cause it, and we did see this recursion during testing.
3304 if Analyzed (N) then
3305 return;
3306 else
3307 Set_Analyzed (N, True);
3308 end if;
3310 -- Ignore some selected attributes in CodePeer mode since they are not
3311 -- relevant in this context.
3313 if CodePeer_Mode then
3314 case Id is
3316 -- Ignore Component_Size in CodePeer mode, to avoid changing the
3317 -- internal representation of types by implicitly packing them.
3319 when Attribute_Component_Size =>
3320 Rewrite (N, Make_Null_Statement (Sloc (N)));
3321 return;
3323 when others =>
3324 null;
3325 end case;
3326 end if;
3328 -- Process Ignore_Rep_Clauses option
3330 if Ignore_Rep_Clauses then
3331 case Id is
3333 -- The following should be ignored. They do not affect legality
3334 -- and may be target dependent. The basic idea of -gnatI is to
3335 -- ignore any rep clauses that may be target dependent but do not
3336 -- affect legality (except possibly to be rejected because they
3337 -- are incompatible with the compilation target).
3339 when Attribute_Alignment |
3340 Attribute_Bit_Order |
3341 Attribute_Component_Size |
3342 Attribute_Machine_Radix |
3343 Attribute_Object_Size |
3344 Attribute_Size |
3345 Attribute_Stream_Size |
3346 Attribute_Value_Size =>
3347 Rewrite (N, Make_Null_Statement (Sloc (N)));
3348 return;
3350 -- Perhaps 'Small should not be ignored by Ignore_Rep_Clauses ???
3352 when Attribute_Small =>
3353 if Ignore_Rep_Clauses then
3354 Rewrite (N, Make_Null_Statement (Sloc (N)));
3355 return;
3356 end if;
3358 -- The following should not be ignored, because in the first place
3359 -- they are reasonably portable, and should not cause problems in
3360 -- compiling code from another target, and also they do affect
3361 -- legality, e.g. failing to provide a stream attribute for a
3362 -- type may make a program illegal.
3364 when Attribute_External_Tag |
3365 Attribute_Input |
3366 Attribute_Output |
3367 Attribute_Read |
3368 Attribute_Simple_Storage_Pool |
3369 Attribute_Storage_Pool |
3370 Attribute_Storage_Size |
3371 Attribute_Write =>
3372 null;
3374 -- Other cases are errors ("attribute& cannot be set with
3375 -- definition clause"), which will be caught below.
3377 when others =>
3378 null;
3379 end case;
3380 end if;
3382 Analyze (Nam);
3383 Ent := Entity (Nam);
3385 if Rep_Item_Too_Early (Ent, N) then
3386 return;
3387 end if;
3389 -- Rep clause applies to full view of incomplete type or private type if
3390 -- we have one (if not, this is a premature use of the type). However,
3391 -- certain semantic checks need to be done on the specified entity (i.e.
3392 -- the private view), so we save it in Ent.
3394 if Is_Private_Type (Ent)
3395 and then Is_Derived_Type (Ent)
3396 and then not Is_Tagged_Type (Ent)
3397 and then No (Full_View (Ent))
3398 then
3399 -- If this is a private type whose completion is a derivation from
3400 -- another private type, there is no full view, and the attribute
3401 -- belongs to the type itself, not its underlying parent.
3403 U_Ent := Ent;
3405 elsif Ekind (Ent) = E_Incomplete_Type then
3407 -- The attribute applies to the full view, set the entity of the
3408 -- attribute definition accordingly.
3410 Ent := Underlying_Type (Ent);
3411 U_Ent := Ent;
3412 Set_Entity (Nam, Ent);
3414 else
3415 U_Ent := Underlying_Type (Ent);
3416 end if;
3418 -- Avoid cascaded error
3420 if Etype (Nam) = Any_Type then
3421 return;
3423 -- Must be declared in current scope or in case of an aspect
3424 -- specification, must be visible in current scope.
3426 elsif Scope (Ent) /= Current_Scope
3427 and then
3428 not (From_Aspect_Specification (N)
3429 and then Scope_Within_Or_Same (Current_Scope, Scope (Ent)))
3430 then
3431 Error_Msg_N ("entity must be declared in this scope", Nam);
3432 return;
3434 -- Must not be a source renaming (we do have some cases where the
3435 -- expander generates a renaming, and those cases are OK, in such
3436 -- cases any attribute applies to the renamed object as well).
3438 elsif Is_Object (Ent)
3439 and then Present (Renamed_Object (Ent))
3440 then
3441 -- Case of renamed object from source, this is an error
3443 if Comes_From_Source (Renamed_Object (Ent)) then
3444 Get_Name_String (Chars (N));
3445 Error_Msg_Strlen := Name_Len;
3446 Error_Msg_String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len);
3447 Error_Msg_N
3448 ("~ clause not allowed for a renaming declaration "
3449 & "(RM 13.1(6))", Nam);
3450 return;
3452 -- For the case of a compiler generated renaming, the attribute
3453 -- definition clause applies to the renamed object created by the
3454 -- expander. The easiest general way to handle this is to create a
3455 -- copy of the attribute definition clause for this object.
3457 else
3458 Insert_Action (N,
3459 Make_Attribute_Definition_Clause (Loc,
3460 Name =>
3461 New_Occurrence_Of (Entity (Renamed_Object (Ent)), Loc),
3462 Chars => Chars (N),
3463 Expression => Duplicate_Subexpr (Expression (N))));
3464 end if;
3466 -- If no underlying entity, use entity itself, applies to some
3467 -- previously detected error cases ???
3469 elsif No (U_Ent) then
3470 U_Ent := Ent;
3472 -- Cannot specify for a subtype (exception Object/Value_Size)
3474 elsif Is_Type (U_Ent)
3475 and then not Is_First_Subtype (U_Ent)
3476 and then Id /= Attribute_Object_Size
3477 and then Id /= Attribute_Value_Size
3478 and then not From_At_Mod (N)
3479 then
3480 Error_Msg_N ("cannot specify attribute for subtype", Nam);
3481 return;
3482 end if;
3484 Set_Entity (N, U_Ent);
3485 Check_Restriction_No_Use_Of_Attribute (N);
3487 -- Switch on particular attribute
3489 case Id is
3491 -------------
3492 -- Address --
3493 -------------
3495 -- Address attribute definition clause
3497 when Attribute_Address => Address : begin
3499 -- A little error check, catch for X'Address use X'Address;
3501 if Nkind (Nam) = N_Identifier
3502 and then Nkind (Expr) = N_Attribute_Reference
3503 and then Attribute_Name (Expr) = Name_Address
3504 and then Nkind (Prefix (Expr)) = N_Identifier
3505 and then Chars (Nam) = Chars (Prefix (Expr))
3506 then
3507 Error_Msg_NE
3508 ("address for & is self-referencing", Prefix (Expr), Ent);
3509 return;
3510 end if;
3512 -- Not that special case, carry on with analysis of expression
3514 Analyze_And_Resolve (Expr, RTE (RE_Address));
3516 -- Even when ignoring rep clauses we need to indicate that the
3517 -- entity has an address clause and thus it is legal to declare
3518 -- it imported.
3520 if Ignore_Rep_Clauses then
3521 if Ekind_In (U_Ent, E_Variable, E_Constant) then
3522 Record_Rep_Item (U_Ent, N);
3523 end if;
3525 return;
3526 end if;
3528 if Duplicate_Clause then
3529 null;
3531 -- Case of address clause for subprogram
3533 elsif Is_Subprogram (U_Ent) then
3534 if Has_Homonym (U_Ent) then
3535 Error_Msg_N
3536 ("address clause cannot be given " &
3537 "for overloaded subprogram",
3538 Nam);
3539 return;
3540 end if;
3542 -- For subprograms, all address clauses are permitted, and we
3543 -- mark the subprogram as having a deferred freeze so that Gigi
3544 -- will not elaborate it too soon.
3546 -- Above needs more comments, what is too soon about???
3548 Set_Has_Delayed_Freeze (U_Ent);
3550 -- Case of address clause for entry
3552 elsif Ekind (U_Ent) = E_Entry then
3553 if Nkind (Parent (N)) = N_Task_Body then
3554 Error_Msg_N
3555 ("entry address must be specified in task spec", Nam);
3556 return;
3557 end if;
3559 -- For entries, we require a constant address
3561 Check_Constant_Address_Clause (Expr, U_Ent);
3563 -- Special checks for task types
3565 if Is_Task_Type (Scope (U_Ent))
3566 and then Comes_From_Source (Scope (U_Ent))
3567 then
3568 Error_Msg_N
3569 ("??entry address declared for entry in task type", N);
3570 Error_Msg_N
3571 ("\??only one task can be declared of this type", N);
3572 end if;
3574 -- Entry address clauses are obsolescent
3576 Check_Restriction (No_Obsolescent_Features, N);
3578 if Warn_On_Obsolescent_Feature then
3579 Error_Msg_N
3580 ("?j?attaching interrupt to task entry is an " &
3581 "obsolescent feature (RM J.7.1)", N);
3582 Error_Msg_N
3583 ("\?j?use interrupt procedure instead", N);
3584 end if;
3586 -- Case of an address clause for a controlled object which we
3587 -- consider to be erroneous.
3589 elsif Is_Controlled (Etype (U_Ent))
3590 or else Has_Controlled_Component (Etype (U_Ent))
3591 then
3592 Error_Msg_NE
3593 ("??controlled object& must not be overlaid", Nam, U_Ent);
3594 Error_Msg_N
3595 ("\??Program_Error will be raised at run time", Nam);
3596 Insert_Action (Declaration_Node (U_Ent),
3597 Make_Raise_Program_Error (Loc,
3598 Reason => PE_Overlaid_Controlled_Object));
3599 return;
3601 -- Case of address clause for a (non-controlled) object
3603 elsif
3604 Ekind (U_Ent) = E_Variable
3605 or else
3606 Ekind (U_Ent) = E_Constant
3607 then
3608 declare
3609 Expr : constant Node_Id := Expression (N);
3610 O_Ent : Entity_Id;
3611 Off : Boolean;
3613 begin
3614 -- Exported variables cannot have an address clause, because
3615 -- this cancels the effect of the pragma Export.
3617 if Is_Exported (U_Ent) then
3618 Error_Msg_N
3619 ("cannot export object with address clause", Nam);
3620 return;
3621 end if;
3623 Find_Overlaid_Entity (N, O_Ent, Off);
3625 -- Overlaying controlled objects is erroneous
3627 if Present (O_Ent)
3628 and then (Has_Controlled_Component (Etype (O_Ent))
3629 or else Is_Controlled (Etype (O_Ent)))
3630 then
3631 Error_Msg_N
3632 ("??cannot overlay with controlled object", Expr);
3633 Error_Msg_N
3634 ("\??Program_Error will be raised at run time", Expr);
3635 Insert_Action (Declaration_Node (U_Ent),
3636 Make_Raise_Program_Error (Loc,
3637 Reason => PE_Overlaid_Controlled_Object));
3638 return;
3640 elsif Present (O_Ent)
3641 and then Ekind (U_Ent) = E_Constant
3642 and then not Is_Constant_Object (O_Ent)
3643 then
3644 Error_Msg_N ("??constant overlays a variable", Expr);
3646 -- Imported variables can have an address clause, but then
3647 -- the import is pretty meaningless except to suppress
3648 -- initializations, so we do not need such variables to
3649 -- be statically allocated (and in fact it causes trouble
3650 -- if the address clause is a local value).
3652 elsif Is_Imported (U_Ent) then
3653 Set_Is_Statically_Allocated (U_Ent, False);
3654 end if;
3656 -- We mark a possible modification of a variable with an
3657 -- address clause, since it is likely aliasing is occurring.
3659 Note_Possible_Modification (Nam, Sure => False);
3661 -- Here we are checking for explicit overlap of one variable
3662 -- by another, and if we find this then mark the overlapped
3663 -- variable as also being volatile to prevent unwanted
3664 -- optimizations. This is a significant pessimization so
3665 -- avoid it when there is an offset, i.e. when the object
3666 -- is composite; they cannot be optimized easily anyway.
3668 if Present (O_Ent)
3669 and then Is_Object (O_Ent)
3670 and then not Off
3672 -- The following test is an expedient solution to what
3673 -- is really a problem in CodePeer. Suppressing the
3674 -- Set_Treat_As_Volatile call here prevents later
3675 -- generation (in some cases) of trees that CodePeer
3676 -- should, but currently does not, handle correctly.
3677 -- This test should probably be removed when CodePeer
3678 -- is improved, just because we want the tree CodePeer
3679 -- analyzes to match the tree for which we generate code
3680 -- as closely as is practical. ???
3682 and then not CodePeer_Mode
3683 then
3684 -- ??? O_Ent might not be in current unit
3686 Set_Treat_As_Volatile (O_Ent);
3687 end if;
3689 -- Legality checks on the address clause for initialized
3690 -- objects is deferred until the freeze point, because
3691 -- a subsequent pragma might indicate that the object
3692 -- is imported and thus not initialized. Also, the address
3693 -- clause might involve entities that have yet to be
3694 -- elaborated.
3696 Set_Has_Delayed_Freeze (U_Ent);
3698 -- If an initialization call has been generated for this
3699 -- object, it needs to be deferred to after the freeze node
3700 -- we have just now added, otherwise GIGI will see a
3701 -- reference to the variable (as actual to the IP call)
3702 -- before its definition.
3704 declare
3705 Init_Call : constant Node_Id :=
3706 Remove_Init_Call (U_Ent, N);
3708 begin
3709 if Present (Init_Call) then
3711 -- If the init call is an expression with actions with
3712 -- null expression, just extract the actions.
3714 if Nkind (Init_Call) = N_Expression_With_Actions
3715 and then
3716 Nkind (Expression (Init_Call)) = N_Null_Statement
3717 then
3718 Append_Freeze_Actions (U_Ent, Actions (Init_Call));
3720 -- General case: move Init_Call to freeze actions
3722 else
3723 Append_Freeze_Action (U_Ent, Init_Call);
3724 end if;
3725 end if;
3726 end;
3728 if Is_Exported (U_Ent) then
3729 Error_Msg_N
3730 ("& cannot be exported if an address clause is given",
3731 Nam);
3732 Error_Msg_N
3733 ("\define and export a variable "
3734 & "that holds its address instead", Nam);
3735 end if;
3737 -- Entity has delayed freeze, so we will generate an
3738 -- alignment check at the freeze point unless suppressed.
3740 if not Range_Checks_Suppressed (U_Ent)
3741 and then not Alignment_Checks_Suppressed (U_Ent)
3742 then
3743 Set_Check_Address_Alignment (N);
3744 end if;
3746 -- Kill the size check code, since we are not allocating
3747 -- the variable, it is somewhere else.
3749 Kill_Size_Check_Code (U_Ent);
3751 -- If the address clause is of the form:
3753 -- for Y'Address use X'Address
3755 -- or
3757 -- Const : constant Address := X'Address;
3758 -- ...
3759 -- for Y'Address use Const;
3761 -- then we make an entry in the table for checking the size
3762 -- and alignment of the overlaying variable. We defer this
3763 -- check till after code generation to take full advantage
3764 -- of the annotation done by the back end.
3766 -- If the entity has a generic type, the check will be
3767 -- performed in the instance if the actual type justifies
3768 -- it, and we do not insert the clause in the table to
3769 -- prevent spurious warnings.
3771 -- Note: we used to test Comes_From_Source and only give
3772 -- this warning for source entities, but we have removed
3773 -- this test. It really seems bogus to generate overlays
3774 -- that would trigger this warning in generated code.
3775 -- Furthermore, by removing the test, we handle the
3776 -- aspect case properly.
3778 if Address_Clause_Overlay_Warnings
3779 and then Present (O_Ent)
3780 and then Is_Object (O_Ent)
3781 then
3782 if not Is_Generic_Type (Etype (U_Ent)) then
3783 Address_Clause_Checks.Append ((N, U_Ent, O_Ent, Off));
3784 end if;
3786 -- If variable overlays a constant view, and we are
3787 -- warning on overlays, then mark the variable as
3788 -- overlaying a constant (we will give warnings later
3789 -- if this variable is assigned).
3791 if Is_Constant_Object (O_Ent)
3792 and then Ekind (U_Ent) = E_Variable
3793 then
3794 Set_Overlays_Constant (U_Ent);
3795 end if;
3796 end if;
3797 end;
3799 -- Not a valid entity for an address clause
3801 else
3802 Error_Msg_N ("address cannot be given for &", Nam);
3803 end if;
3804 end Address;
3806 ---------------
3807 -- Alignment --
3808 ---------------
3810 -- Alignment attribute definition clause
3812 when Attribute_Alignment => Alignment : declare
3813 Align : constant Uint := Get_Alignment_Value (Expr);
3814 Max_Align : constant Uint := UI_From_Int (Maximum_Alignment);
3816 begin
3817 FOnly := True;
3819 if not Is_Type (U_Ent)
3820 and then Ekind (U_Ent) /= E_Variable
3821 and then Ekind (U_Ent) /= E_Constant
3822 then
3823 Error_Msg_N ("alignment cannot be given for &", Nam);
3825 elsif Duplicate_Clause then
3826 null;
3828 elsif Align /= No_Uint then
3829 Set_Has_Alignment_Clause (U_Ent);
3831 -- Tagged type case, check for attempt to set alignment to a
3832 -- value greater than Max_Align, and reset if so.
3834 if Is_Tagged_Type (U_Ent) and then Align > Max_Align then
3835 Error_Msg_N
3836 ("alignment for & set to Maximum_Aligment??", Nam);
3837 Set_Alignment (U_Ent, Max_Align);
3839 -- All other cases
3841 else
3842 Set_Alignment (U_Ent, Align);
3843 end if;
3845 -- For an array type, U_Ent is the first subtype. In that case,
3846 -- also set the alignment of the anonymous base type so that
3847 -- other subtypes (such as the itypes for aggregates of the
3848 -- type) also receive the expected alignment.
3850 if Is_Array_Type (U_Ent) then
3851 Set_Alignment (Base_Type (U_Ent), Align);
3852 end if;
3853 end if;
3854 end Alignment;
3856 ---------------
3857 -- Bit_Order --
3858 ---------------
3860 -- Bit_Order attribute definition clause
3862 when Attribute_Bit_Order => Bit_Order : declare
3863 begin
3864 if not Is_Record_Type (U_Ent) then
3865 Error_Msg_N
3866 ("Bit_Order can only be defined for record type", Nam);
3868 elsif Duplicate_Clause then
3869 null;
3871 else
3872 Analyze_And_Resolve (Expr, RTE (RE_Bit_Order));
3874 if Etype (Expr) = Any_Type then
3875 return;
3877 elsif not Is_Static_Expression (Expr) then
3878 Flag_Non_Static_Expr
3879 ("Bit_Order requires static expression!", Expr);
3881 else
3882 if (Expr_Value (Expr) = 0) /= Bytes_Big_Endian then
3883 Set_Reverse_Bit_Order (U_Ent, True);
3884 end if;
3885 end if;
3886 end if;
3887 end Bit_Order;
3889 --------------------
3890 -- Component_Size --
3891 --------------------
3893 -- Component_Size attribute definition clause
3895 when Attribute_Component_Size => Component_Size_Case : declare
3896 Csize : constant Uint := Static_Integer (Expr);
3897 Ctyp : Entity_Id;
3898 Btype : Entity_Id;
3899 Biased : Boolean;
3900 New_Ctyp : Entity_Id;
3901 Decl : Node_Id;
3903 begin
3904 if not Is_Array_Type (U_Ent) then
3905 Error_Msg_N ("component size requires array type", Nam);
3906 return;
3907 end if;
3909 Btype := Base_Type (U_Ent);
3910 Ctyp := Component_Type (Btype);
3912 if Duplicate_Clause then
3913 null;
3915 elsif Rep_Item_Too_Early (Btype, N) then
3916 null;
3918 elsif Csize /= No_Uint then
3919 Check_Size (Expr, Ctyp, Csize, Biased);
3921 -- For the biased case, build a declaration for a subtype that
3922 -- will be used to represent the biased subtype that reflects
3923 -- the biased representation of components. We need the subtype
3924 -- to get proper conversions on referencing elements of the
3925 -- array. Note: component size clauses are ignored in VM mode.
3927 if VM_Target = No_VM then
3928 if Biased then
3929 New_Ctyp :=
3930 Make_Defining_Identifier (Loc,
3931 Chars =>
3932 New_External_Name (Chars (U_Ent), 'C', 0, 'T'));
3934 Decl :=
3935 Make_Subtype_Declaration (Loc,
3936 Defining_Identifier => New_Ctyp,
3937 Subtype_Indication =>
3938 New_Occurrence_Of (Component_Type (Btype), Loc));
3940 Set_Parent (Decl, N);
3941 Analyze (Decl, Suppress => All_Checks);
3943 Set_Has_Delayed_Freeze (New_Ctyp, False);
3944 Set_Esize (New_Ctyp, Csize);
3945 Set_RM_Size (New_Ctyp, Csize);
3946 Init_Alignment (New_Ctyp);
3947 Set_Is_Itype (New_Ctyp, True);
3948 Set_Associated_Node_For_Itype (New_Ctyp, U_Ent);
3950 Set_Component_Type (Btype, New_Ctyp);
3951 Set_Biased (New_Ctyp, N, "component size clause");
3952 end if;
3954 Set_Component_Size (Btype, Csize);
3956 -- For VM case, we ignore component size clauses
3958 else
3959 -- Give a warning unless we are in GNAT mode, in which case
3960 -- the warning is suppressed since it is not useful.
3962 if not GNAT_Mode then
3963 Error_Msg_N
3964 ("component size ignored in this configuration??", N);
3965 end if;
3966 end if;
3968 -- Deal with warning on overridden size
3970 if Warn_On_Overridden_Size
3971 and then Has_Size_Clause (Ctyp)
3972 and then RM_Size (Ctyp) /= Csize
3973 then
3974 Error_Msg_NE
3975 ("component size overrides size clause for&?S?", N, Ctyp);
3976 end if;
3978 Set_Has_Component_Size_Clause (Btype, True);
3979 Set_Has_Non_Standard_Rep (Btype, True);
3980 end if;
3981 end Component_Size_Case;
3983 -----------------------
3984 -- Constant_Indexing --
3985 -----------------------
3987 when Attribute_Constant_Indexing =>
3988 Check_Indexing_Functions;
3990 ---------
3991 -- CPU --
3992 ---------
3994 when Attribute_CPU => CPU :
3995 begin
3996 -- CPU attribute definition clause not allowed except from aspect
3997 -- specification.
3999 if From_Aspect_Specification (N) then
4000 if not Is_Task_Type (U_Ent) then
4001 Error_Msg_N ("CPU can only be defined for task", Nam);
4003 elsif Duplicate_Clause then
4004 null;
4006 else
4007 -- The expression must be analyzed in the special manner
4008 -- described in "Handling of Default and Per-Object
4009 -- Expressions" in sem.ads.
4011 -- The visibility to the discriminants must be restored
4013 Push_Scope_And_Install_Discriminants (U_Ent);
4014 Preanalyze_Spec_Expression (Expr, RTE (RE_CPU_Range));
4015 Uninstall_Discriminants_And_Pop_Scope (U_Ent);
4017 if not Is_Static_Expression (Expr) then
4018 Check_Restriction (Static_Priorities, Expr);
4019 end if;
4020 end if;
4022 else
4023 Error_Msg_N
4024 ("attribute& cannot be set with definition clause", N);
4025 end if;
4026 end CPU;
4028 ----------------------
4029 -- Default_Iterator --
4030 ----------------------
4032 when Attribute_Default_Iterator => Default_Iterator : declare
4033 Func : Entity_Id;
4035 begin
4036 if not Is_Tagged_Type (U_Ent) then
4037 Error_Msg_N
4038 ("aspect Default_Iterator applies to tagged type", Nam);
4039 end if;
4041 Check_Iterator_Functions;
4043 Analyze (Expr);
4045 if not Is_Entity_Name (Expr)
4046 or else Ekind (Entity (Expr)) /= E_Function
4047 then
4048 Error_Msg_N ("aspect Iterator must be a function", Expr);
4049 else
4050 Func := Entity (Expr);
4051 end if;
4053 if No (First_Formal (Func))
4054 or else Etype (First_Formal (Func)) /= U_Ent
4055 then
4056 Error_Msg_NE
4057 ("Default Iterator must be a primitive of&", Func, U_Ent);
4058 end if;
4059 end Default_Iterator;
4061 ------------------------
4062 -- Dispatching_Domain --
4063 ------------------------
4065 when Attribute_Dispatching_Domain => Dispatching_Domain :
4066 begin
4067 -- Dispatching_Domain attribute definition clause not allowed
4068 -- except from aspect specification.
4070 if From_Aspect_Specification (N) then
4071 if not Is_Task_Type (U_Ent) then
4072 Error_Msg_N ("Dispatching_Domain can only be defined" &
4073 "for task",
4074 Nam);
4076 elsif Duplicate_Clause then
4077 null;
4079 else
4080 -- The expression must be analyzed in the special manner
4081 -- described in "Handling of Default and Per-Object
4082 -- Expressions" in sem.ads.
4084 -- The visibility to the discriminants must be restored
4086 Push_Scope_And_Install_Discriminants (U_Ent);
4088 Preanalyze_Spec_Expression
4089 (Expr, RTE (RE_Dispatching_Domain));
4091 Uninstall_Discriminants_And_Pop_Scope (U_Ent);
4092 end if;
4094 else
4095 Error_Msg_N
4096 ("attribute& cannot be set with definition clause", N);
4097 end if;
4098 end Dispatching_Domain;
4100 ------------------
4101 -- External_Tag --
4102 ------------------
4104 when Attribute_External_Tag => External_Tag :
4105 begin
4106 if not Is_Tagged_Type (U_Ent) then
4107 Error_Msg_N ("should be a tagged type", Nam);
4108 end if;
4110 if Duplicate_Clause then
4111 null;
4113 else
4114 Analyze_And_Resolve (Expr, Standard_String);
4116 if not Is_Static_Expression (Expr) then
4117 Flag_Non_Static_Expr
4118 ("static string required for tag name!", Nam);
4119 end if;
4121 if VM_Target = No_VM then
4122 Set_Has_External_Tag_Rep_Clause (U_Ent);
4123 else
4124 Error_Msg_Name_1 := Attr;
4125 Error_Msg_N
4126 ("% attribute unsupported in this configuration", Nam);
4127 end if;
4129 if not Is_Library_Level_Entity (U_Ent) then
4130 Error_Msg_NE
4131 ("??non-unique external tag supplied for &", N, U_Ent);
4132 Error_Msg_N
4133 ("\??same external tag applies to all "
4134 & "subprogram calls", N);
4135 Error_Msg_N
4136 ("\??corresponding internal tag cannot be obtained", N);
4137 end if;
4138 end if;
4139 end External_Tag;
4141 --------------------------
4142 -- Implicit_Dereference --
4143 --------------------------
4145 when Attribute_Implicit_Dereference =>
4147 -- Legality checks already performed at the point of the type
4148 -- declaration, aspect is not delayed.
4150 null;
4152 -----------
4153 -- Input --
4154 -----------
4156 when Attribute_Input =>
4157 Analyze_Stream_TSS_Definition (TSS_Stream_Input);
4158 Set_Has_Specified_Stream_Input (Ent);
4160 ------------------------
4161 -- Interrupt_Priority --
4162 ------------------------
4164 when Attribute_Interrupt_Priority => Interrupt_Priority :
4165 begin
4166 -- Interrupt_Priority attribute definition clause not allowed
4167 -- except from aspect specification.
4169 if From_Aspect_Specification (N) then
4170 if not (Is_Protected_Type (U_Ent)
4171 or else Is_Task_Type (U_Ent))
4172 then
4173 Error_Msg_N
4174 ("Interrupt_Priority can only be defined for task" &
4175 "and protected object",
4176 Nam);
4178 elsif Duplicate_Clause then
4179 null;
4181 else
4182 -- The expression must be analyzed in the special manner
4183 -- described in "Handling of Default and Per-Object
4184 -- Expressions" in sem.ads.
4186 -- The visibility to the discriminants must be restored
4188 Push_Scope_And_Install_Discriminants (U_Ent);
4190 Preanalyze_Spec_Expression
4191 (Expr, RTE (RE_Interrupt_Priority));
4193 Uninstall_Discriminants_And_Pop_Scope (U_Ent);
4194 end if;
4196 else
4197 Error_Msg_N
4198 ("attribute& cannot be set with definition clause", N);
4199 end if;
4200 end Interrupt_Priority;
4202 ----------------------
4203 -- Iterator_Element --
4204 ----------------------
4206 when Attribute_Iterator_Element =>
4207 Analyze (Expr);
4209 if not Is_Entity_Name (Expr)
4210 or else not Is_Type (Entity (Expr))
4211 then
4212 Error_Msg_N ("aspect Iterator_Element must be a type", Expr);
4213 end if;
4215 -------------------
4216 -- Machine_Radix --
4217 -------------------
4219 -- Machine radix attribute definition clause
4221 when Attribute_Machine_Radix => Machine_Radix : declare
4222 Radix : constant Uint := Static_Integer (Expr);
4224 begin
4225 if not Is_Decimal_Fixed_Point_Type (U_Ent) then
4226 Error_Msg_N ("decimal fixed-point type expected for &", Nam);
4228 elsif Duplicate_Clause then
4229 null;
4231 elsif Radix /= No_Uint then
4232 Set_Has_Machine_Radix_Clause (U_Ent);
4233 Set_Has_Non_Standard_Rep (Base_Type (U_Ent));
4235 if Radix = 2 then
4236 null;
4237 elsif Radix = 10 then
4238 Set_Machine_Radix_10 (U_Ent);
4239 else
4240 Error_Msg_N ("machine radix value must be 2 or 10", Expr);
4241 end if;
4242 end if;
4243 end Machine_Radix;
4245 -----------------
4246 -- Object_Size --
4247 -----------------
4249 -- Object_Size attribute definition clause
4251 when Attribute_Object_Size => Object_Size : declare
4252 Size : constant Uint := Static_Integer (Expr);
4254 Biased : Boolean;
4255 pragma Warnings (Off, Biased);
4257 begin
4258 if not Is_Type (U_Ent) then
4259 Error_Msg_N ("Object_Size cannot be given for &", Nam);
4261 elsif Duplicate_Clause then
4262 null;
4264 else
4265 Check_Size (Expr, U_Ent, Size, Biased);
4267 if Size /= 8
4268 and then
4269 Size /= 16
4270 and then
4271 Size /= 32
4272 and then
4273 UI_Mod (Size, 64) /= 0
4274 then
4275 Error_Msg_N
4276 ("Object_Size must be 8, 16, 32, or multiple of 64",
4277 Expr);
4278 end if;
4280 Set_Esize (U_Ent, Size);
4281 Set_Has_Object_Size_Clause (U_Ent);
4282 Alignment_Check_For_Size_Change (U_Ent, Size);
4283 end if;
4284 end Object_Size;
4286 ------------
4287 -- Output --
4288 ------------
4290 when Attribute_Output =>
4291 Analyze_Stream_TSS_Definition (TSS_Stream_Output);
4292 Set_Has_Specified_Stream_Output (Ent);
4294 --------------
4295 -- Priority --
4296 --------------
4298 when Attribute_Priority => Priority :
4299 begin
4300 -- Priority attribute definition clause not allowed except from
4301 -- aspect specification.
4303 if From_Aspect_Specification (N) then
4304 if not (Is_Protected_Type (U_Ent)
4305 or else Is_Task_Type (U_Ent)
4306 or else Ekind (U_Ent) = E_Procedure)
4307 then
4308 Error_Msg_N
4309 ("Priority can only be defined for task and protected " &
4310 "object",
4311 Nam);
4313 elsif Duplicate_Clause then
4314 null;
4316 else
4317 -- The expression must be analyzed in the special manner
4318 -- described in "Handling of Default and Per-Object
4319 -- Expressions" in sem.ads.
4321 -- The visibility to the discriminants must be restored
4323 Push_Scope_And_Install_Discriminants (U_Ent);
4324 Preanalyze_Spec_Expression (Expr, Standard_Integer);
4325 Uninstall_Discriminants_And_Pop_Scope (U_Ent);
4327 if not Is_Static_Expression (Expr) then
4328 Check_Restriction (Static_Priorities, Expr);
4329 end if;
4330 end if;
4332 else
4333 Error_Msg_N
4334 ("attribute& cannot be set with definition clause", N);
4335 end if;
4336 end Priority;
4338 ----------
4339 -- Read --
4340 ----------
4342 when Attribute_Read =>
4343 Analyze_Stream_TSS_Definition (TSS_Stream_Read);
4344 Set_Has_Specified_Stream_Read (Ent);
4346 --------------------------
4347 -- Scalar_Storage_Order --
4348 --------------------------
4350 -- Scalar_Storage_Order attribute definition clause
4352 when Attribute_Scalar_Storage_Order => Scalar_Storage_Order : declare
4353 begin
4354 if not (Is_Record_Type (U_Ent) or else Is_Array_Type (U_Ent)) then
4355 Error_Msg_N
4356 ("Scalar_Storage_Order can only be defined for "
4357 & "record or array type", Nam);
4359 elsif Duplicate_Clause then
4360 null;
4362 else
4363 Analyze_And_Resolve (Expr, RTE (RE_Bit_Order));
4365 if Etype (Expr) = Any_Type then
4366 return;
4368 elsif not Is_Static_Expression (Expr) then
4369 Flag_Non_Static_Expr
4370 ("Scalar_Storage_Order requires static expression!", Expr);
4372 elsif (Expr_Value (Expr) = 0) /= Bytes_Big_Endian then
4374 -- Here for the case of a non-default (i.e. non-confirming)
4375 -- Scalar_Storage_Order attribute definition.
4377 if Support_Nondefault_SSO_On_Target then
4378 Set_Reverse_Storage_Order (Base_Type (U_Ent), True);
4379 else
4380 Error_Msg_N
4381 ("non-default Scalar_Storage_Order "
4382 & "not supported on target", Expr);
4383 end if;
4384 end if;
4385 end if;
4386 end Scalar_Storage_Order;
4388 ----------
4389 -- Size --
4390 ----------
4392 -- Size attribute definition clause
4394 when Attribute_Size => Size : declare
4395 Size : constant Uint := Static_Integer (Expr);
4396 Etyp : Entity_Id;
4397 Biased : Boolean;
4399 begin
4400 FOnly := True;
4402 if Duplicate_Clause then
4403 null;
4405 elsif not Is_Type (U_Ent)
4406 and then Ekind (U_Ent) /= E_Variable
4407 and then Ekind (U_Ent) /= E_Constant
4408 then
4409 Error_Msg_N ("size cannot be given for &", Nam);
4411 elsif Is_Array_Type (U_Ent)
4412 and then not Is_Constrained (U_Ent)
4413 then
4414 Error_Msg_N
4415 ("size cannot be given for unconstrained array", Nam);
4417 elsif Size /= No_Uint then
4418 if VM_Target /= No_VM and then not GNAT_Mode then
4420 -- Size clause is not handled properly on VM targets.
4421 -- Display a warning unless we are in GNAT mode, in which
4422 -- case this is useless.
4424 Error_Msg_N
4425 ("size clauses are ignored in this configuration??", N);
4426 end if;
4428 if Is_Type (U_Ent) then
4429 Etyp := U_Ent;
4430 else
4431 Etyp := Etype (U_Ent);
4432 end if;
4434 -- Check size, note that Gigi is in charge of checking that the
4435 -- size of an array or record type is OK. Also we do not check
4436 -- the size in the ordinary fixed-point case, since it is too
4437 -- early to do so (there may be subsequent small clause that
4438 -- affects the size). We can check the size if a small clause
4439 -- has already been given.
4441 if not Is_Ordinary_Fixed_Point_Type (U_Ent)
4442 or else Has_Small_Clause (U_Ent)
4443 then
4444 Check_Size (Expr, Etyp, Size, Biased);
4445 Set_Biased (U_Ent, N, "size clause", Biased);
4446 end if;
4448 -- For types set RM_Size and Esize if possible
4450 if Is_Type (U_Ent) then
4451 Set_RM_Size (U_Ent, Size);
4453 -- For elementary types, increase Object_Size to power of 2,
4454 -- but not less than a storage unit in any case (normally
4455 -- this means it will be byte addressable).
4457 -- For all other types, nothing else to do, we leave Esize
4458 -- (object size) unset, the back end will set it from the
4459 -- size and alignment in an appropriate manner.
4461 -- In both cases, we check whether the alignment must be
4462 -- reset in the wake of the size change.
4464 if Is_Elementary_Type (U_Ent) then
4465 if Size <= System_Storage_Unit then
4466 Init_Esize (U_Ent, System_Storage_Unit);
4467 elsif Size <= 16 then
4468 Init_Esize (U_Ent, 16);
4469 elsif Size <= 32 then
4470 Init_Esize (U_Ent, 32);
4471 else
4472 Set_Esize (U_Ent, (Size + 63) / 64 * 64);
4473 end if;
4475 Alignment_Check_For_Size_Change (U_Ent, Esize (U_Ent));
4476 else
4477 Alignment_Check_For_Size_Change (U_Ent, Size);
4478 end if;
4480 -- For objects, set Esize only
4482 else
4483 if Is_Elementary_Type (Etyp) then
4484 if Size /= System_Storage_Unit
4485 and then
4486 Size /= System_Storage_Unit * 2
4487 and then
4488 Size /= System_Storage_Unit * 4
4489 and then
4490 Size /= System_Storage_Unit * 8
4491 then
4492 Error_Msg_Uint_1 := UI_From_Int (System_Storage_Unit);
4493 Error_Msg_Uint_2 := Error_Msg_Uint_1 * 8;
4494 Error_Msg_N
4495 ("size for primitive object must be a power of 2"
4496 & " in the range ^-^", N);
4497 end if;
4498 end if;
4500 Set_Esize (U_Ent, Size);
4501 end if;
4503 Set_Has_Size_Clause (U_Ent);
4504 end if;
4505 end Size;
4507 -----------
4508 -- Small --
4509 -----------
4511 -- Small attribute definition clause
4513 when Attribute_Small => Small : declare
4514 Implicit_Base : constant Entity_Id := Base_Type (U_Ent);
4515 Small : Ureal;
4517 begin
4518 Analyze_And_Resolve (Expr, Any_Real);
4520 if Etype (Expr) = Any_Type then
4521 return;
4523 elsif not Is_Static_Expression (Expr) then
4524 Flag_Non_Static_Expr
4525 ("small requires static expression!", Expr);
4526 return;
4528 else
4529 Small := Expr_Value_R (Expr);
4531 if Small <= Ureal_0 then
4532 Error_Msg_N ("small value must be greater than zero", Expr);
4533 return;
4534 end if;
4536 end if;
4538 if not Is_Ordinary_Fixed_Point_Type (U_Ent) then
4539 Error_Msg_N
4540 ("small requires an ordinary fixed point type", Nam);
4542 elsif Has_Small_Clause (U_Ent) then
4543 Error_Msg_N ("small already given for &", Nam);
4545 elsif Small > Delta_Value (U_Ent) then
4546 Error_Msg_N
4547 ("small value must not be greater than delta value", Nam);
4549 else
4550 Set_Small_Value (U_Ent, Small);
4551 Set_Small_Value (Implicit_Base, Small);
4552 Set_Has_Small_Clause (U_Ent);
4553 Set_Has_Small_Clause (Implicit_Base);
4554 Set_Has_Non_Standard_Rep (Implicit_Base);
4555 end if;
4556 end Small;
4558 ------------------
4559 -- Storage_Pool --
4560 ------------------
4562 -- Storage_Pool attribute definition clause
4564 when Attribute_Storage_Pool | Attribute_Simple_Storage_Pool => declare
4565 Pool : Entity_Id;
4566 T : Entity_Id;
4568 begin
4569 if Ekind (U_Ent) = E_Access_Subprogram_Type then
4570 Error_Msg_N
4571 ("storage pool cannot be given for access-to-subprogram type",
4572 Nam);
4573 return;
4575 elsif not
4576 Ekind_In (U_Ent, E_Access_Type, E_General_Access_Type)
4577 then
4578 Error_Msg_N
4579 ("storage pool can only be given for access types", Nam);
4580 return;
4582 elsif Is_Derived_Type (U_Ent) then
4583 Error_Msg_N
4584 ("storage pool cannot be given for a derived access type",
4585 Nam);
4587 elsif Duplicate_Clause then
4588 return;
4590 elsif Present (Associated_Storage_Pool (U_Ent)) then
4591 Error_Msg_N ("storage pool already given for &", Nam);
4592 return;
4593 end if;
4595 if Id = Attribute_Storage_Pool then
4596 Analyze_And_Resolve
4597 (Expr, Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
4599 -- In the Simple_Storage_Pool case, we allow a variable of any
4600 -- simple storage pool type, so we Resolve without imposing an
4601 -- expected type.
4603 else
4604 Analyze_And_Resolve (Expr);
4606 if not Present (Get_Rep_Pragma
4607 (Etype (Expr), Name_Simple_Storage_Pool_Type))
4608 then
4609 Error_Msg_N
4610 ("expression must be of a simple storage pool type", Expr);
4611 end if;
4612 end if;
4614 if not Denotes_Variable (Expr) then
4615 Error_Msg_N ("storage pool must be a variable", Expr);
4616 return;
4617 end if;
4619 if Nkind (Expr) = N_Type_Conversion then
4620 T := Etype (Expression (Expr));
4621 else
4622 T := Etype (Expr);
4623 end if;
4625 -- The Stack_Bounded_Pool is used internally for implementing
4626 -- access types with a Storage_Size. Since it only work properly
4627 -- when used on one specific type, we need to check that it is not
4628 -- hijacked improperly:
4630 -- type T is access Integer;
4631 -- for T'Storage_Size use n;
4632 -- type Q is access Float;
4633 -- for Q'Storage_Size use T'Storage_Size; -- incorrect
4635 if RTE_Available (RE_Stack_Bounded_Pool)
4636 and then Base_Type (T) = RTE (RE_Stack_Bounded_Pool)
4637 then
4638 Error_Msg_N ("non-shareable internal Pool", Expr);
4639 return;
4640 end if;
4642 -- If the argument is a name that is not an entity name, then
4643 -- we construct a renaming operation to define an entity of
4644 -- type storage pool.
4646 if not Is_Entity_Name (Expr)
4647 and then Is_Object_Reference (Expr)
4648 then
4649 Pool := Make_Temporary (Loc, 'P', Expr);
4651 declare
4652 Rnode : constant Node_Id :=
4653 Make_Object_Renaming_Declaration (Loc,
4654 Defining_Identifier => Pool,
4655 Subtype_Mark =>
4656 New_Occurrence_Of (Etype (Expr), Loc),
4657 Name => Expr);
4659 begin
4660 -- If the attribute definition clause comes from an aspect
4661 -- clause, then insert the renaming before the associated
4662 -- entity's declaration, since the attribute clause has
4663 -- not yet been appended to the declaration list.
4665 if From_Aspect_Specification (N) then
4666 Insert_Before (Parent (Entity (N)), Rnode);
4667 else
4668 Insert_Before (N, Rnode);
4669 end if;
4671 Analyze (Rnode);
4672 Set_Associated_Storage_Pool (U_Ent, Pool);
4673 end;
4675 elsif Is_Entity_Name (Expr) then
4676 Pool := Entity (Expr);
4678 -- If pool is a renamed object, get original one. This can
4679 -- happen with an explicit renaming, and within instances.
4681 while Present (Renamed_Object (Pool))
4682 and then Is_Entity_Name (Renamed_Object (Pool))
4683 loop
4684 Pool := Entity (Renamed_Object (Pool));
4685 end loop;
4687 if Present (Renamed_Object (Pool))
4688 and then Nkind (Renamed_Object (Pool)) = N_Type_Conversion
4689 and then Is_Entity_Name (Expression (Renamed_Object (Pool)))
4690 then
4691 Pool := Entity (Expression (Renamed_Object (Pool)));
4692 end if;
4694 Set_Associated_Storage_Pool (U_Ent, Pool);
4696 elsif Nkind (Expr) = N_Type_Conversion
4697 and then Is_Entity_Name (Expression (Expr))
4698 and then Nkind (Original_Node (Expr)) = N_Attribute_Reference
4699 then
4700 Pool := Entity (Expression (Expr));
4701 Set_Associated_Storage_Pool (U_Ent, Pool);
4703 else
4704 Error_Msg_N ("incorrect reference to a Storage Pool", Expr);
4705 return;
4706 end if;
4707 end;
4709 ------------------
4710 -- Storage_Size --
4711 ------------------
4713 -- Storage_Size attribute definition clause
4715 when Attribute_Storage_Size => Storage_Size : declare
4716 Btype : constant Entity_Id := Base_Type (U_Ent);
4718 begin
4719 if Is_Task_Type (U_Ent) then
4721 -- Check obsolescent (but never obsolescent if from aspect!)
4723 if not From_Aspect_Specification (N) then
4724 Check_Restriction (No_Obsolescent_Features, N);
4726 if Warn_On_Obsolescent_Feature then
4727 Error_Msg_N
4728 ("?j?storage size clause for task is an " &
4729 "obsolescent feature (RM J.9)", N);
4730 Error_Msg_N ("\?j?use Storage_Size pragma instead", N);
4731 end if;
4732 end if;
4734 FOnly := True;
4735 end if;
4737 if not Is_Access_Type (U_Ent)
4738 and then Ekind (U_Ent) /= E_Task_Type
4739 then
4740 Error_Msg_N ("storage size cannot be given for &", Nam);
4742 elsif Is_Access_Type (U_Ent) and Is_Derived_Type (U_Ent) then
4743 Error_Msg_N
4744 ("storage size cannot be given for a derived access type",
4745 Nam);
4747 elsif Duplicate_Clause then
4748 null;
4750 else
4751 Analyze_And_Resolve (Expr, Any_Integer);
4753 if Is_Access_Type (U_Ent) then
4754 if Present (Associated_Storage_Pool (U_Ent)) then
4755 Error_Msg_N ("storage pool already given for &", Nam);
4756 return;
4757 end if;
4759 if Is_OK_Static_Expression (Expr)
4760 and then Expr_Value (Expr) = 0
4761 then
4762 Set_No_Pool_Assigned (Btype);
4763 end if;
4764 end if;
4766 Set_Has_Storage_Size_Clause (Btype);
4767 end if;
4768 end Storage_Size;
4770 -----------------
4771 -- Stream_Size --
4772 -----------------
4774 when Attribute_Stream_Size => Stream_Size : declare
4775 Size : constant Uint := Static_Integer (Expr);
4777 begin
4778 if Ada_Version <= Ada_95 then
4779 Check_Restriction (No_Implementation_Attributes, N);
4780 end if;
4782 if Duplicate_Clause then
4783 null;
4785 elsif Is_Elementary_Type (U_Ent) then
4786 if Size /= System_Storage_Unit
4787 and then
4788 Size /= System_Storage_Unit * 2
4789 and then
4790 Size /= System_Storage_Unit * 4
4791 and then
4792 Size /= System_Storage_Unit * 8
4793 then
4794 Error_Msg_Uint_1 := UI_From_Int (System_Storage_Unit);
4795 Error_Msg_N
4796 ("stream size for elementary type must be a"
4797 & " power of 2 and at least ^", N);
4799 elsif RM_Size (U_Ent) > Size then
4800 Error_Msg_Uint_1 := RM_Size (U_Ent);
4801 Error_Msg_N
4802 ("stream size for elementary type must be a"
4803 & " power of 2 and at least ^", N);
4804 end if;
4806 Set_Has_Stream_Size_Clause (U_Ent);
4808 else
4809 Error_Msg_N ("Stream_Size cannot be given for &", Nam);
4810 end if;
4811 end Stream_Size;
4813 ----------------
4814 -- Value_Size --
4815 ----------------
4817 -- Value_Size attribute definition clause
4819 when Attribute_Value_Size => Value_Size : declare
4820 Size : constant Uint := Static_Integer (Expr);
4821 Biased : Boolean;
4823 begin
4824 if not Is_Type (U_Ent) then
4825 Error_Msg_N ("Value_Size cannot be given for &", Nam);
4827 elsif Duplicate_Clause then
4828 null;
4830 elsif Is_Array_Type (U_Ent)
4831 and then not Is_Constrained (U_Ent)
4832 then
4833 Error_Msg_N
4834 ("Value_Size cannot be given for unconstrained array", Nam);
4836 else
4837 if Is_Elementary_Type (U_Ent) then
4838 Check_Size (Expr, U_Ent, Size, Biased);
4839 Set_Biased (U_Ent, N, "value size clause", Biased);
4840 end if;
4842 Set_RM_Size (U_Ent, Size);
4843 end if;
4844 end Value_Size;
4846 -----------------------
4847 -- Variable_Indexing --
4848 -----------------------
4850 when Attribute_Variable_Indexing =>
4851 Check_Indexing_Functions;
4853 -----------
4854 -- Write --
4855 -----------
4857 when Attribute_Write =>
4858 Analyze_Stream_TSS_Definition (TSS_Stream_Write);
4859 Set_Has_Specified_Stream_Write (Ent);
4861 -- All other attributes cannot be set
4863 when others =>
4864 Error_Msg_N
4865 ("attribute& cannot be set with definition clause", N);
4866 end case;
4868 -- The test for the type being frozen must be performed after any
4869 -- expression the clause has been analyzed since the expression itself
4870 -- might cause freezing that makes the clause illegal.
4872 if Rep_Item_Too_Late (U_Ent, N, FOnly) then
4873 return;
4874 end if;
4875 end Analyze_Attribute_Definition_Clause;
4877 ----------------------------
4878 -- Analyze_Code_Statement --
4879 ----------------------------
4881 procedure Analyze_Code_Statement (N : Node_Id) is
4882 HSS : constant Node_Id := Parent (N);
4883 SBody : constant Node_Id := Parent (HSS);
4884 Subp : constant Entity_Id := Current_Scope;
4885 Stmt : Node_Id;
4886 Decl : Node_Id;
4887 StmtO : Node_Id;
4888 DeclO : Node_Id;
4890 begin
4891 -- Analyze and check we get right type, note that this implements the
4892 -- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that
4893 -- is the only way that Asm_Insn could possibly be visible.
4895 Analyze_And_Resolve (Expression (N));
4897 if Etype (Expression (N)) = Any_Type then
4898 return;
4899 elsif Etype (Expression (N)) /= RTE (RE_Asm_Insn) then
4900 Error_Msg_N ("incorrect type for code statement", N);
4901 return;
4902 end if;
4904 Check_Code_Statement (N);
4906 -- Make sure we appear in the handled statement sequence of a
4907 -- subprogram (RM 13.8(3)).
4909 if Nkind (HSS) /= N_Handled_Sequence_Of_Statements
4910 or else Nkind (SBody) /= N_Subprogram_Body
4911 then
4912 Error_Msg_N
4913 ("code statement can only appear in body of subprogram", N);
4914 return;
4915 end if;
4917 -- Do remaining checks (RM 13.8(3)) if not already done
4919 if not Is_Machine_Code_Subprogram (Subp) then
4920 Set_Is_Machine_Code_Subprogram (Subp);
4922 -- No exception handlers allowed
4924 if Present (Exception_Handlers (HSS)) then
4925 Error_Msg_N
4926 ("exception handlers not permitted in machine code subprogram",
4927 First (Exception_Handlers (HSS)));
4928 end if;
4930 -- No declarations other than use clauses and pragmas (we allow
4931 -- certain internally generated declarations as well).
4933 Decl := First (Declarations (SBody));
4934 while Present (Decl) loop
4935 DeclO := Original_Node (Decl);
4936 if Comes_From_Source (DeclO)
4937 and not Nkind_In (DeclO, N_Pragma,
4938 N_Use_Package_Clause,
4939 N_Use_Type_Clause,
4940 N_Implicit_Label_Declaration)
4941 then
4942 Error_Msg_N
4943 ("this declaration not allowed in machine code subprogram",
4944 DeclO);
4945 end if;
4947 Next (Decl);
4948 end loop;
4950 -- No statements other than code statements, pragmas, and labels.
4951 -- Again we allow certain internally generated statements.
4953 -- In Ada 2012, qualified expressions are names, and the code
4954 -- statement is initially parsed as a procedure call.
4956 Stmt := First (Statements (HSS));
4957 while Present (Stmt) loop
4958 StmtO := Original_Node (Stmt);
4960 -- A procedure call transformed into a code statement is OK.
4962 if Ada_Version >= Ada_2012
4963 and then Nkind (StmtO) = N_Procedure_Call_Statement
4964 and then Nkind (Name (StmtO)) = N_Qualified_Expression
4965 then
4966 null;
4968 elsif Comes_From_Source (StmtO)
4969 and then not Nkind_In (StmtO, N_Pragma,
4970 N_Label,
4971 N_Code_Statement)
4972 then
4973 Error_Msg_N
4974 ("this statement is not allowed in machine code subprogram",
4975 StmtO);
4976 end if;
4978 Next (Stmt);
4979 end loop;
4980 end if;
4981 end Analyze_Code_Statement;
4983 -----------------------------------------------
4984 -- Analyze_Enumeration_Representation_Clause --
4985 -----------------------------------------------
4987 procedure Analyze_Enumeration_Representation_Clause (N : Node_Id) is
4988 Ident : constant Node_Id := Identifier (N);
4989 Aggr : constant Node_Id := Array_Aggregate (N);
4990 Enumtype : Entity_Id;
4991 Elit : Entity_Id;
4992 Expr : Node_Id;
4993 Assoc : Node_Id;
4994 Choice : Node_Id;
4995 Val : Uint;
4997 Err : Boolean := False;
4998 -- Set True to avoid cascade errors and crashes on incorrect source code
5000 Lo : constant Uint := Expr_Value (Type_Low_Bound (Universal_Integer));
5001 Hi : constant Uint := Expr_Value (Type_High_Bound (Universal_Integer));
5002 -- Allowed range of universal integer (= allowed range of enum lit vals)
5004 Min : Uint;
5005 Max : Uint;
5006 -- Minimum and maximum values of entries
5008 Max_Node : Node_Id;
5009 -- Pointer to node for literal providing max value
5011 begin
5012 if Ignore_Rep_Clauses then
5013 return;
5014 end if;
5016 -- Ignore enumeration rep clauses by default in CodePeer mode,
5017 -- unless -gnatd.I is specified, as a work around for potential false
5018 -- positive messages.
5020 if CodePeer_Mode and not Debug_Flag_Dot_II then
5021 return;
5022 end if;
5024 -- First some basic error checks
5026 Find_Type (Ident);
5027 Enumtype := Entity (Ident);
5029 if Enumtype = Any_Type
5030 or else Rep_Item_Too_Early (Enumtype, N)
5031 then
5032 return;
5033 else
5034 Enumtype := Underlying_Type (Enumtype);
5035 end if;
5037 if not Is_Enumeration_Type (Enumtype) then
5038 Error_Msg_NE
5039 ("enumeration type required, found}",
5040 Ident, First_Subtype (Enumtype));
5041 return;
5042 end if;
5044 -- Ignore rep clause on generic actual type. This will already have
5045 -- been flagged on the template as an error, and this is the safest
5046 -- way to ensure we don't get a junk cascaded message in the instance.
5048 if Is_Generic_Actual_Type (Enumtype) then
5049 return;
5051 -- Type must be in current scope
5053 elsif Scope (Enumtype) /= Current_Scope then
5054 Error_Msg_N ("type must be declared in this scope", Ident);
5055 return;
5057 -- Type must be a first subtype
5059 elsif not Is_First_Subtype (Enumtype) then
5060 Error_Msg_N ("cannot give enumeration rep clause for subtype", N);
5061 return;
5063 -- Ignore duplicate rep clause
5065 elsif Has_Enumeration_Rep_Clause (Enumtype) then
5066 Error_Msg_N ("duplicate enumeration rep clause ignored", N);
5067 return;
5069 -- Don't allow rep clause for standard [wide_[wide_]]character
5071 elsif Is_Standard_Character_Type (Enumtype) then
5072 Error_Msg_N ("enumeration rep clause not allowed for this type", N);
5073 return;
5075 -- Check that the expression is a proper aggregate (no parentheses)
5077 elsif Paren_Count (Aggr) /= 0 then
5078 Error_Msg
5079 ("extra parentheses surrounding aggregate not allowed",
5080 First_Sloc (Aggr));
5081 return;
5083 -- All tests passed, so set rep clause in place
5085 else
5086 Set_Has_Enumeration_Rep_Clause (Enumtype);
5087 Set_Has_Enumeration_Rep_Clause (Base_Type (Enumtype));
5088 end if;
5090 -- Now we process the aggregate. Note that we don't use the normal
5091 -- aggregate code for this purpose, because we don't want any of the
5092 -- normal expansion activities, and a number of special semantic
5093 -- rules apply (including the component type being any integer type)
5095 Elit := First_Literal (Enumtype);
5097 -- First the positional entries if any
5099 if Present (Expressions (Aggr)) then
5100 Expr := First (Expressions (Aggr));
5101 while Present (Expr) loop
5102 if No (Elit) then
5103 Error_Msg_N ("too many entries in aggregate", Expr);
5104 return;
5105 end if;
5107 Val := Static_Integer (Expr);
5109 -- Err signals that we found some incorrect entries processing
5110 -- the list. The final checks for completeness and ordering are
5111 -- skipped in this case.
5113 if Val = No_Uint then
5114 Err := True;
5115 elsif Val < Lo or else Hi < Val then
5116 Error_Msg_N ("value outside permitted range", Expr);
5117 Err := True;
5118 end if;
5120 Set_Enumeration_Rep (Elit, Val);
5121 Set_Enumeration_Rep_Expr (Elit, Expr);
5122 Next (Expr);
5123 Next (Elit);
5124 end loop;
5125 end if;
5127 -- Now process the named entries if present
5129 if Present (Component_Associations (Aggr)) then
5130 Assoc := First (Component_Associations (Aggr));
5131 while Present (Assoc) loop
5132 Choice := First (Choices (Assoc));
5134 if Present (Next (Choice)) then
5135 Error_Msg_N
5136 ("multiple choice not allowed here", Next (Choice));
5137 Err := True;
5138 end if;
5140 if Nkind (Choice) = N_Others_Choice then
5141 Error_Msg_N ("others choice not allowed here", Choice);
5142 Err := True;
5144 elsif Nkind (Choice) = N_Range then
5146 -- ??? should allow zero/one element range here
5148 Error_Msg_N ("range not allowed here", Choice);
5149 Err := True;
5151 else
5152 Analyze_And_Resolve (Choice, Enumtype);
5154 if Error_Posted (Choice) then
5155 Err := True;
5156 end if;
5158 if not Err then
5159 if Is_Entity_Name (Choice)
5160 and then Is_Type (Entity (Choice))
5161 then
5162 Error_Msg_N ("subtype name not allowed here", Choice);
5163 Err := True;
5165 -- ??? should allow static subtype with zero/one entry
5167 elsif Etype (Choice) = Base_Type (Enumtype) then
5168 if not Is_Static_Expression (Choice) then
5169 Flag_Non_Static_Expr
5170 ("non-static expression used for choice!", Choice);
5171 Err := True;
5173 else
5174 Elit := Expr_Value_E (Choice);
5176 if Present (Enumeration_Rep_Expr (Elit)) then
5177 Error_Msg_Sloc :=
5178 Sloc (Enumeration_Rep_Expr (Elit));
5179 Error_Msg_NE
5180 ("representation for& previously given#",
5181 Choice, Elit);
5182 Err := True;
5183 end if;
5185 Set_Enumeration_Rep_Expr (Elit, Expression (Assoc));
5187 Expr := Expression (Assoc);
5188 Val := Static_Integer (Expr);
5190 if Val = No_Uint then
5191 Err := True;
5193 elsif Val < Lo or else Hi < Val then
5194 Error_Msg_N ("value outside permitted range", Expr);
5195 Err := True;
5196 end if;
5198 Set_Enumeration_Rep (Elit, Val);
5199 end if;
5200 end if;
5201 end if;
5202 end if;
5204 Next (Assoc);
5205 end loop;
5206 end if;
5208 -- Aggregate is fully processed. Now we check that a full set of
5209 -- representations was given, and that they are in range and in order.
5210 -- These checks are only done if no other errors occurred.
5212 if not Err then
5213 Min := No_Uint;
5214 Max := No_Uint;
5216 Elit := First_Literal (Enumtype);
5217 while Present (Elit) loop
5218 if No (Enumeration_Rep_Expr (Elit)) then
5219 Error_Msg_NE ("missing representation for&!", N, Elit);
5221 else
5222 Val := Enumeration_Rep (Elit);
5224 if Min = No_Uint then
5225 Min := Val;
5226 end if;
5228 if Val /= No_Uint then
5229 if Max /= No_Uint and then Val <= Max then
5230 Error_Msg_NE
5231 ("enumeration value for& not ordered!",
5232 Enumeration_Rep_Expr (Elit), Elit);
5233 end if;
5235 Max_Node := Enumeration_Rep_Expr (Elit);
5236 Max := Val;
5237 end if;
5239 -- If there is at least one literal whose representation is not
5240 -- equal to the Pos value, then note that this enumeration type
5241 -- has a non-standard representation.
5243 if Val /= Enumeration_Pos (Elit) then
5244 Set_Has_Non_Standard_Rep (Base_Type (Enumtype));
5245 end if;
5246 end if;
5248 Next (Elit);
5249 end loop;
5251 -- Now set proper size information
5253 declare
5254 Minsize : Uint := UI_From_Int (Minimum_Size (Enumtype));
5256 begin
5257 if Has_Size_Clause (Enumtype) then
5259 -- All OK, if size is OK now
5261 if RM_Size (Enumtype) >= Minsize then
5262 null;
5264 else
5265 -- Try if we can get by with biasing
5267 Minsize :=
5268 UI_From_Int (Minimum_Size (Enumtype, Biased => True));
5270 -- Error message if even biasing does not work
5272 if RM_Size (Enumtype) < Minsize then
5273 Error_Msg_Uint_1 := RM_Size (Enumtype);
5274 Error_Msg_Uint_2 := Max;
5275 Error_Msg_N
5276 ("previously given size (^) is too small "
5277 & "for this value (^)", Max_Node);
5279 -- If biasing worked, indicate that we now have biased rep
5281 else
5282 Set_Biased
5283 (Enumtype, Size_Clause (Enumtype), "size clause");
5284 end if;
5285 end if;
5287 else
5288 Set_RM_Size (Enumtype, Minsize);
5289 Set_Enum_Esize (Enumtype);
5290 end if;
5292 Set_RM_Size (Base_Type (Enumtype), RM_Size (Enumtype));
5293 Set_Esize (Base_Type (Enumtype), Esize (Enumtype));
5294 Set_Alignment (Base_Type (Enumtype), Alignment (Enumtype));
5295 end;
5296 end if;
5298 -- We repeat the too late test in case it froze itself!
5300 if Rep_Item_Too_Late (Enumtype, N) then
5301 null;
5302 end if;
5303 end Analyze_Enumeration_Representation_Clause;
5305 ----------------------------
5306 -- Analyze_Free_Statement --
5307 ----------------------------
5309 procedure Analyze_Free_Statement (N : Node_Id) is
5310 begin
5311 Analyze (Expression (N));
5312 end Analyze_Free_Statement;
5314 ---------------------------
5315 -- Analyze_Freeze_Entity --
5316 ---------------------------
5318 procedure Analyze_Freeze_Entity (N : Node_Id) is
5319 begin
5320 Freeze_Entity_Checks (N);
5321 end Analyze_Freeze_Entity;
5323 -----------------------------------
5324 -- Analyze_Freeze_Generic_Entity --
5325 -----------------------------------
5327 procedure Analyze_Freeze_Generic_Entity (N : Node_Id) is
5328 begin
5329 Freeze_Entity_Checks (N);
5330 end Analyze_Freeze_Generic_Entity;
5332 ------------------------------------------
5333 -- Analyze_Record_Representation_Clause --
5334 ------------------------------------------
5336 -- Note: we check as much as we can here, but we can't do any checks
5337 -- based on the position values (e.g. overlap checks) until freeze time
5338 -- because especially in Ada 2005 (machine scalar mode), the processing
5339 -- for non-standard bit order can substantially change the positions.
5340 -- See procedure Check_Record_Representation_Clause (called from Freeze)
5341 -- for the remainder of this processing.
5343 procedure Analyze_Record_Representation_Clause (N : Node_Id) is
5344 Ident : constant Node_Id := Identifier (N);
5345 Biased : Boolean;
5346 CC : Node_Id;
5347 Comp : Entity_Id;
5348 Fbit : Uint;
5349 Hbit : Uint := Uint_0;
5350 Lbit : Uint;
5351 Ocomp : Entity_Id;
5352 Posit : Uint;
5353 Rectype : Entity_Id;
5354 Recdef : Node_Id;
5356 function Is_Inherited (Comp : Entity_Id) return Boolean;
5357 -- True if Comp is an inherited component in a record extension
5359 ------------------
5360 -- Is_Inherited --
5361 ------------------
5363 function Is_Inherited (Comp : Entity_Id) return Boolean is
5364 Comp_Base : Entity_Id;
5366 begin
5367 if Ekind (Rectype) = E_Record_Subtype then
5368 Comp_Base := Original_Record_Component (Comp);
5369 else
5370 Comp_Base := Comp;
5371 end if;
5373 return Comp_Base /= Original_Record_Component (Comp_Base);
5374 end Is_Inherited;
5376 -- Local variables
5378 Is_Record_Extension : Boolean;
5379 -- True if Rectype is a record extension
5381 CR_Pragma : Node_Id := Empty;
5382 -- Points to N_Pragma node if Complete_Representation pragma present
5384 -- Start of processing for Analyze_Record_Representation_Clause
5386 begin
5387 if Ignore_Rep_Clauses then
5388 return;
5389 end if;
5391 Find_Type (Ident);
5392 Rectype := Entity (Ident);
5394 if Rectype = Any_Type or else Rep_Item_Too_Early (Rectype, N) then
5395 return;
5396 else
5397 Rectype := Underlying_Type (Rectype);
5398 end if;
5400 -- First some basic error checks
5402 if not Is_Record_Type (Rectype) then
5403 Error_Msg_NE
5404 ("record type required, found}", Ident, First_Subtype (Rectype));
5405 return;
5407 elsif Scope (Rectype) /= Current_Scope then
5408 Error_Msg_N ("type must be declared in this scope", N);
5409 return;
5411 elsif not Is_First_Subtype (Rectype) then
5412 Error_Msg_N ("cannot give record rep clause for subtype", N);
5413 return;
5415 elsif Has_Record_Rep_Clause (Rectype) then
5416 Error_Msg_N ("duplicate record rep clause ignored", N);
5417 return;
5419 elsif Rep_Item_Too_Late (Rectype, N) then
5420 return;
5421 end if;
5423 -- We know we have a first subtype, now possibly go the the anonymous
5424 -- base type to determine whether Rectype is a record extension.
5426 Recdef := Type_Definition (Declaration_Node (Base_Type (Rectype)));
5427 Is_Record_Extension :=
5428 Nkind (Recdef) = N_Derived_Type_Definition
5429 and then Present (Record_Extension_Part (Recdef));
5431 if Present (Mod_Clause (N)) then
5432 declare
5433 Loc : constant Source_Ptr := Sloc (N);
5434 M : constant Node_Id := Mod_Clause (N);
5435 P : constant List_Id := Pragmas_Before (M);
5436 AtM_Nod : Node_Id;
5438 Mod_Val : Uint;
5439 pragma Warnings (Off, Mod_Val);
5441 begin
5442 Check_Restriction (No_Obsolescent_Features, Mod_Clause (N));
5444 if Warn_On_Obsolescent_Feature then
5445 Error_Msg_N
5446 ("?j?mod clause is an obsolescent feature (RM J.8)", N);
5447 Error_Msg_N
5448 ("\?j?use alignment attribute definition clause instead", N);
5449 end if;
5451 if Present (P) then
5452 Analyze_List (P);
5453 end if;
5455 -- In ASIS_Mode mode, expansion is disabled, but we must convert
5456 -- the Mod clause into an alignment clause anyway, so that the
5457 -- back-end can compute and back-annotate properly the size and
5458 -- alignment of types that may include this record.
5460 -- This seems dubious, this destroys the source tree in a manner
5461 -- not detectable by ASIS ???
5463 if Operating_Mode = Check_Semantics and then ASIS_Mode then
5464 AtM_Nod :=
5465 Make_Attribute_Definition_Clause (Loc,
5466 Name => New_Reference_To (Base_Type (Rectype), Loc),
5467 Chars => Name_Alignment,
5468 Expression => Relocate_Node (Expression (M)));
5470 Set_From_At_Mod (AtM_Nod);
5471 Insert_After (N, AtM_Nod);
5472 Mod_Val := Get_Alignment_Value (Expression (AtM_Nod));
5473 Set_Mod_Clause (N, Empty);
5475 else
5476 -- Get the alignment value to perform error checking
5478 Mod_Val := Get_Alignment_Value (Expression (M));
5479 end if;
5480 end;
5481 end if;
5483 -- For untagged types, clear any existing component clauses for the
5484 -- type. If the type is derived, this is what allows us to override
5485 -- a rep clause for the parent. For type extensions, the representation
5486 -- of the inherited components is inherited, so we want to keep previous
5487 -- component clauses for completeness.
5489 if not Is_Tagged_Type (Rectype) then
5490 Comp := First_Component_Or_Discriminant (Rectype);
5491 while Present (Comp) loop
5492 Set_Component_Clause (Comp, Empty);
5493 Next_Component_Or_Discriminant (Comp);
5494 end loop;
5495 end if;
5497 -- All done if no component clauses
5499 CC := First (Component_Clauses (N));
5501 if No (CC) then
5502 return;
5503 end if;
5505 -- A representation like this applies to the base type
5507 Set_Has_Record_Rep_Clause (Base_Type (Rectype));
5508 Set_Has_Non_Standard_Rep (Base_Type (Rectype));
5509 Set_Has_Specified_Layout (Base_Type (Rectype));
5511 -- Process the component clauses
5513 while Present (CC) loop
5515 -- Pragma
5517 if Nkind (CC) = N_Pragma then
5518 Analyze (CC);
5520 -- The only pragma of interest is Complete_Representation
5522 if Pragma_Name (CC) = Name_Complete_Representation then
5523 CR_Pragma := CC;
5524 end if;
5526 -- Processing for real component clause
5528 else
5529 Posit := Static_Integer (Position (CC));
5530 Fbit := Static_Integer (First_Bit (CC));
5531 Lbit := Static_Integer (Last_Bit (CC));
5533 if Posit /= No_Uint
5534 and then Fbit /= No_Uint
5535 and then Lbit /= No_Uint
5536 then
5537 if Posit < 0 then
5538 Error_Msg_N
5539 ("position cannot be negative", Position (CC));
5541 elsif Fbit < 0 then
5542 Error_Msg_N
5543 ("first bit cannot be negative", First_Bit (CC));
5545 -- The Last_Bit specified in a component clause must not be
5546 -- less than the First_Bit minus one (RM-13.5.1(10)).
5548 elsif Lbit < Fbit - 1 then
5549 Error_Msg_N
5550 ("last bit cannot be less than first bit minus one",
5551 Last_Bit (CC));
5553 -- Values look OK, so find the corresponding record component
5554 -- Even though the syntax allows an attribute reference for
5555 -- implementation-defined components, GNAT does not allow the
5556 -- tag to get an explicit position.
5558 elsif Nkind (Component_Name (CC)) = N_Attribute_Reference then
5559 if Attribute_Name (Component_Name (CC)) = Name_Tag then
5560 Error_Msg_N ("position of tag cannot be specified", CC);
5561 else
5562 Error_Msg_N ("illegal component name", CC);
5563 end if;
5565 else
5566 Comp := First_Entity (Rectype);
5567 while Present (Comp) loop
5568 exit when Chars (Comp) = Chars (Component_Name (CC));
5569 Next_Entity (Comp);
5570 end loop;
5572 if No (Comp) then
5574 -- Maybe component of base type that is absent from
5575 -- statically constrained first subtype.
5577 Comp := First_Entity (Base_Type (Rectype));
5578 while Present (Comp) loop
5579 exit when Chars (Comp) = Chars (Component_Name (CC));
5580 Next_Entity (Comp);
5581 end loop;
5582 end if;
5584 if No (Comp) then
5585 Error_Msg_N
5586 ("component clause is for non-existent field", CC);
5588 -- Ada 2012 (AI05-0026): Any name that denotes a
5589 -- discriminant of an object of an unchecked union type
5590 -- shall not occur within a record_representation_clause.
5592 -- The general restriction of using record rep clauses on
5593 -- Unchecked_Union types has now been lifted. Since it is
5594 -- possible to introduce a record rep clause which mentions
5595 -- the discriminant of an Unchecked_Union in non-Ada 2012
5596 -- code, this check is applied to all versions of the
5597 -- language.
5599 elsif Ekind (Comp) = E_Discriminant
5600 and then Is_Unchecked_Union (Rectype)
5601 then
5602 Error_Msg_N
5603 ("cannot reference discriminant of unchecked union",
5604 Component_Name (CC));
5606 elsif Is_Record_Extension and then Is_Inherited (Comp) then
5607 Error_Msg_NE
5608 ("component clause not allowed for inherited "
5609 & "component&", CC, Comp);
5611 elsif Present (Component_Clause (Comp)) then
5613 -- Diagnose duplicate rep clause, or check consistency
5614 -- if this is an inherited component. In a double fault,
5615 -- there may be a duplicate inconsistent clause for an
5616 -- inherited component.
5618 if Scope (Original_Record_Component (Comp)) = Rectype
5619 or else Parent (Component_Clause (Comp)) = N
5620 then
5621 Error_Msg_Sloc := Sloc (Component_Clause (Comp));
5622 Error_Msg_N ("component clause previously given#", CC);
5624 else
5625 declare
5626 Rep1 : constant Node_Id := Component_Clause (Comp);
5627 begin
5628 if Intval (Position (Rep1)) /=
5629 Intval (Position (CC))
5630 or else Intval (First_Bit (Rep1)) /=
5631 Intval (First_Bit (CC))
5632 or else Intval (Last_Bit (Rep1)) /=
5633 Intval (Last_Bit (CC))
5634 then
5635 Error_Msg_N
5636 ("component clause inconsistent "
5637 & "with representation of ancestor", CC);
5639 elsif Warn_On_Redundant_Constructs then
5640 Error_Msg_N
5641 ("?r?redundant confirming component clause "
5642 & "for component!", CC);
5643 end if;
5644 end;
5645 end if;
5647 -- Normal case where this is the first component clause we
5648 -- have seen for this entity, so set it up properly.
5650 else
5651 -- Make reference for field in record rep clause and set
5652 -- appropriate entity field in the field identifier.
5654 Generate_Reference
5655 (Comp, Component_Name (CC), Set_Ref => False);
5656 Set_Entity (Component_Name (CC), Comp);
5658 -- Update Fbit and Lbit to the actual bit number
5660 Fbit := Fbit + UI_From_Int (SSU) * Posit;
5661 Lbit := Lbit + UI_From_Int (SSU) * Posit;
5663 if Has_Size_Clause (Rectype)
5664 and then RM_Size (Rectype) <= Lbit
5665 then
5666 Error_Msg_N
5667 ("bit number out of range of specified size",
5668 Last_Bit (CC));
5669 else
5670 Set_Component_Clause (Comp, CC);
5671 Set_Component_Bit_Offset (Comp, Fbit);
5672 Set_Esize (Comp, 1 + (Lbit - Fbit));
5673 Set_Normalized_First_Bit (Comp, Fbit mod SSU);
5674 Set_Normalized_Position (Comp, Fbit / SSU);
5676 if Warn_On_Overridden_Size
5677 and then Has_Size_Clause (Etype (Comp))
5678 and then RM_Size (Etype (Comp)) /= Esize (Comp)
5679 then
5680 Error_Msg_NE
5681 ("?S?component size overrides size clause for&",
5682 Component_Name (CC), Etype (Comp));
5683 end if;
5685 -- This information is also set in the corresponding
5686 -- component of the base type, found by accessing the
5687 -- Original_Record_Component link if it is present.
5689 Ocomp := Original_Record_Component (Comp);
5691 if Hbit < Lbit then
5692 Hbit := Lbit;
5693 end if;
5695 Check_Size
5696 (Component_Name (CC),
5697 Etype (Comp),
5698 Esize (Comp),
5699 Biased);
5701 Set_Biased
5702 (Comp, First_Node (CC), "component clause", Biased);
5704 if Present (Ocomp) then
5705 Set_Component_Clause (Ocomp, CC);
5706 Set_Component_Bit_Offset (Ocomp, Fbit);
5707 Set_Normalized_First_Bit (Ocomp, Fbit mod SSU);
5708 Set_Normalized_Position (Ocomp, Fbit / SSU);
5709 Set_Esize (Ocomp, 1 + (Lbit - Fbit));
5711 Set_Normalized_Position_Max
5712 (Ocomp, Normalized_Position (Ocomp));
5714 -- Note: we don't use Set_Biased here, because we
5715 -- already gave a warning above if needed, and we
5716 -- would get a duplicate for the same name here.
5718 Set_Has_Biased_Representation
5719 (Ocomp, Has_Biased_Representation (Comp));
5720 end if;
5722 if Esize (Comp) < 0 then
5723 Error_Msg_N ("component size is negative", CC);
5724 end if;
5725 end if;
5726 end if;
5727 end if;
5728 end if;
5729 end if;
5731 Next (CC);
5732 end loop;
5734 -- Check missing components if Complete_Representation pragma appeared
5736 if Present (CR_Pragma) then
5737 Comp := First_Component_Or_Discriminant (Rectype);
5738 while Present (Comp) loop
5739 if No (Component_Clause (Comp)) then
5740 Error_Msg_NE
5741 ("missing component clause for &", CR_Pragma, Comp);
5742 end if;
5744 Next_Component_Or_Discriminant (Comp);
5745 end loop;
5747 -- Give missing components warning if required
5749 elsif Warn_On_Unrepped_Components then
5750 declare
5751 Num_Repped_Components : Nat := 0;
5752 Num_Unrepped_Components : Nat := 0;
5754 begin
5755 -- First count number of repped and unrepped components
5757 Comp := First_Component_Or_Discriminant (Rectype);
5758 while Present (Comp) loop
5759 if Present (Component_Clause (Comp)) then
5760 Num_Repped_Components := Num_Repped_Components + 1;
5761 else
5762 Num_Unrepped_Components := Num_Unrepped_Components + 1;
5763 end if;
5765 Next_Component_Or_Discriminant (Comp);
5766 end loop;
5768 -- We are only interested in the case where there is at least one
5769 -- unrepped component, and at least half the components have rep
5770 -- clauses. We figure that if less than half have them, then the
5771 -- partial rep clause is really intentional. If the component
5772 -- type has no underlying type set at this point (as for a generic
5773 -- formal type), we don't know enough to give a warning on the
5774 -- component.
5776 if Num_Unrepped_Components > 0
5777 and then Num_Unrepped_Components < Num_Repped_Components
5778 then
5779 Comp := First_Component_Or_Discriminant (Rectype);
5780 while Present (Comp) loop
5781 if No (Component_Clause (Comp))
5782 and then Comes_From_Source (Comp)
5783 and then Present (Underlying_Type (Etype (Comp)))
5784 and then (Is_Scalar_Type (Underlying_Type (Etype (Comp)))
5785 or else Size_Known_At_Compile_Time
5786 (Underlying_Type (Etype (Comp))))
5787 and then not Has_Warnings_Off (Rectype)
5788 then
5789 Error_Msg_Sloc := Sloc (Comp);
5790 Error_Msg_NE
5791 ("?C?no component clause given for & declared #",
5792 N, Comp);
5793 end if;
5795 Next_Component_Or_Discriminant (Comp);
5796 end loop;
5797 end if;
5798 end;
5799 end if;
5800 end Analyze_Record_Representation_Clause;
5802 -------------------------------------------
5803 -- Build_Invariant_Procedure_Declaration --
5804 -------------------------------------------
5806 function Build_Invariant_Procedure_Declaration
5807 (Typ : Entity_Id) return Node_Id
5809 Loc : constant Source_Ptr := Sloc (Typ);
5810 Object_Entity : constant Entity_Id :=
5811 Make_Defining_Identifier (Loc, New_Internal_Name ('I'));
5812 Spec : Node_Id;
5813 SId : Entity_Id;
5815 begin
5816 Set_Etype (Object_Entity, Typ);
5818 -- Check for duplicate definiations.
5820 if Has_Invariants (Typ) and then Present (Invariant_Procedure (Typ)) then
5821 return Empty;
5822 end if;
5824 SId :=
5825 Make_Defining_Identifier (Loc,
5826 Chars => New_External_Name (Chars (Typ), "Invariant"));
5827 Set_Has_Invariants (Typ);
5828 Set_Ekind (SId, E_Procedure);
5829 Set_Is_Invariant_Procedure (SId);
5830 Set_Invariant_Procedure (Typ, SId);
5832 Spec :=
5833 Make_Procedure_Specification (Loc,
5834 Defining_Unit_Name => SId,
5835 Parameter_Specifications => New_List (
5836 Make_Parameter_Specification (Loc,
5837 Defining_Identifier => Object_Entity,
5838 Parameter_Type => New_Occurrence_Of (Typ, Loc))));
5840 return Make_Subprogram_Declaration (Loc, Specification => Spec);
5841 end Build_Invariant_Procedure_Declaration;
5843 -------------------------------
5844 -- Build_Invariant_Procedure --
5845 -------------------------------
5847 -- The procedure that is constructed here has the form
5849 -- procedure typInvariant (Ixxx : typ) is
5850 -- begin
5851 -- pragma Check (Invariant, exp, "failed invariant from xxx");
5852 -- pragma Check (Invariant, exp, "failed invariant from xxx");
5853 -- ...
5854 -- pragma Check (Invariant, exp, "failed inherited invariant from xxx");
5855 -- ...
5856 -- end typInvariant;
5858 procedure Build_Invariant_Procedure (Typ : Entity_Id; N : Node_Id) is
5859 Loc : constant Source_Ptr := Sloc (Typ);
5860 Stmts : List_Id;
5861 Spec : Node_Id;
5862 SId : Entity_Id;
5863 PDecl : Node_Id;
5864 PBody : Node_Id;
5866 Visible_Decls : constant List_Id := Visible_Declarations (N);
5867 Private_Decls : constant List_Id := Private_Declarations (N);
5869 procedure Add_Invariants (T : Entity_Id; Inherit : Boolean);
5870 -- Appends statements to Stmts for any invariants in the rep item chain
5871 -- of the given type. If Inherit is False, then we only process entries
5872 -- on the chain for the type Typ. If Inherit is True, then we ignore any
5873 -- Invariant aspects, but we process all Invariant'Class aspects, adding
5874 -- "inherited" to the exception message and generating an informational
5875 -- message about the inheritance of an invariant.
5877 Object_Name : Name_Id;
5878 -- Name for argument of invariant procedure
5880 Object_Entity : Node_Id;
5881 -- The entity of the formal for the procedure
5883 --------------------
5884 -- Add_Invariants --
5885 --------------------
5887 procedure Add_Invariants (T : Entity_Id; Inherit : Boolean) is
5888 Ritem : Node_Id;
5889 Arg1 : Node_Id;
5890 Arg2 : Node_Id;
5891 Arg3 : Node_Id;
5892 Exp : Node_Id;
5893 Loc : Source_Ptr;
5894 Assoc : List_Id;
5895 Str : String_Id;
5897 procedure Replace_Type_Reference (N : Node_Id);
5898 -- Replace a single occurrence N of the subtype name with a reference
5899 -- to the formal of the predicate function. N can be an identifier
5900 -- referencing the subtype, or a selected component, representing an
5901 -- appropriately qualified occurrence of the subtype name.
5903 procedure Replace_Type_References is
5904 new Replace_Type_References_Generic (Replace_Type_Reference);
5905 -- Traverse an expression replacing all occurrences of the subtype
5906 -- name with appropriate references to the object that is the formal
5907 -- parameter of the predicate function. Note that we must ensure
5908 -- that the type and entity information is properly set in the
5909 -- replacement node, since we will do a Preanalyze call of this
5910 -- expression without proper visibility of the procedure argument.
5912 ----------------------------
5913 -- Replace_Type_Reference --
5914 ----------------------------
5916 -- Note: See comments in Add_Predicates.Replace_Type_Reference
5917 -- regarding handling of Sloc and Comes_From_Source.
5919 procedure Replace_Type_Reference (N : Node_Id) is
5920 begin
5921 -- Invariant'Class, replace with T'Class (obj)
5923 if Class_Present (Ritem) then
5924 Rewrite (N,
5925 Make_Type_Conversion (Sloc (N),
5926 Subtype_Mark =>
5927 Make_Attribute_Reference (Sloc (N),
5928 Prefix => New_Occurrence_Of (T, Sloc (N)),
5929 Attribute_Name => Name_Class),
5930 Expression => Make_Identifier (Sloc (N), Object_Name)));
5932 Set_Entity (Expression (N), Object_Entity);
5933 Set_Etype (Expression (N), Typ);
5935 -- Invariant, replace with obj
5937 else
5938 Rewrite (N, Make_Identifier (Sloc (N), Object_Name));
5939 Set_Entity (N, Object_Entity);
5940 Set_Etype (N, Typ);
5941 end if;
5943 Set_Comes_From_Source (N, True);
5944 end Replace_Type_Reference;
5946 -- Start of processing for Add_Invariants
5948 begin
5949 Ritem := First_Rep_Item (T);
5950 while Present (Ritem) loop
5951 if Nkind (Ritem) = N_Pragma
5952 and then Pragma_Name (Ritem) = Name_Invariant
5953 then
5954 Arg1 := First (Pragma_Argument_Associations (Ritem));
5955 Arg2 := Next (Arg1);
5956 Arg3 := Next (Arg2);
5958 Arg1 := Get_Pragma_Arg (Arg1);
5959 Arg2 := Get_Pragma_Arg (Arg2);
5961 -- For Inherit case, ignore Invariant, process only Class case
5963 if Inherit then
5964 if not Class_Present (Ritem) then
5965 goto Continue;
5966 end if;
5968 -- For Inherit false, process only item for right type
5970 else
5971 if Entity (Arg1) /= Typ then
5972 goto Continue;
5973 end if;
5974 end if;
5976 if No (Stmts) then
5977 Stmts := Empty_List;
5978 end if;
5980 Exp := New_Copy_Tree (Arg2);
5982 -- Preserve sloc of original pragma Invariant
5984 Loc := Sloc (Ritem);
5986 -- We need to replace any occurrences of the name of the type
5987 -- with references to the object, converted to type'Class in
5988 -- the case of Invariant'Class aspects.
5990 Replace_Type_References (Exp, Chars (T));
5992 -- If this invariant comes from an aspect, find the aspect
5993 -- specification, and replace the saved expression because
5994 -- we need the subtype references replaced for the calls to
5995 -- Preanalyze_Spec_Expressin in Check_Aspect_At_Freeze_Point
5996 -- and Check_Aspect_At_End_Of_Declarations.
5998 if From_Aspect_Specification (Ritem) then
5999 declare
6000 Aitem : Node_Id;
6002 begin
6003 -- Loop to find corresponding aspect, note that this
6004 -- must be present given the pragma is marked delayed.
6006 Aitem := Next_Rep_Item (Ritem);
6007 while Present (Aitem) loop
6008 if Nkind (Aitem) = N_Aspect_Specification
6009 and then Aspect_Rep_Item (Aitem) = Ritem
6010 then
6011 Set_Entity
6012 (Identifier (Aitem), New_Copy_Tree (Exp));
6013 exit;
6014 end if;
6016 Aitem := Next_Rep_Item (Aitem);
6017 end loop;
6018 end;
6019 end if;
6021 -- Now we need to preanalyze the expression to properly capture
6022 -- the visibility in the visible part. The expression will not
6023 -- be analyzed for real until the body is analyzed, but that is
6024 -- at the end of the private part and has the wrong visibility.
6026 Set_Parent (Exp, N);
6027 Preanalyze_Assert_Expression (Exp, Standard_Boolean);
6029 -- Build first two arguments for Check pragma
6031 Assoc := New_List (
6032 Make_Pragma_Argument_Association (Loc,
6033 Expression => Make_Identifier (Loc, Name_Invariant)),
6034 Make_Pragma_Argument_Association (Loc,
6035 Expression => Exp));
6037 -- Add message if present in Invariant pragma
6039 if Present (Arg3) then
6040 Str := Strval (Get_Pragma_Arg (Arg3));
6042 -- If inherited case, and message starts "failed invariant",
6043 -- change it to be "failed inherited invariant".
6045 if Inherit then
6046 String_To_Name_Buffer (Str);
6048 if Name_Buffer (1 .. 16) = "failed invariant" then
6049 Insert_Str_In_Name_Buffer ("inherited ", 8);
6050 Str := String_From_Name_Buffer;
6051 end if;
6052 end if;
6054 Append_To (Assoc,
6055 Make_Pragma_Argument_Association (Loc,
6056 Expression => Make_String_Literal (Loc, Str)));
6057 end if;
6059 -- Add Check pragma to list of statements
6061 Append_To (Stmts,
6062 Make_Pragma (Loc,
6063 Pragma_Identifier =>
6064 Make_Identifier (Loc, Name_Check),
6065 Pragma_Argument_Associations => Assoc));
6067 -- If Inherited case and option enabled, output info msg. Note
6068 -- that we know this is a case of Invariant'Class.
6070 if Inherit and Opt.List_Inherited_Aspects then
6071 Error_Msg_Sloc := Sloc (Ritem);
6072 Error_Msg_N
6073 ("?L?info: & inherits `Invariant''Class` aspect from #",
6074 Typ);
6075 end if;
6076 end if;
6078 <<Continue>>
6079 Next_Rep_Item (Ritem);
6080 end loop;
6081 end Add_Invariants;
6083 -- Start of processing for Build_Invariant_Procedure
6085 begin
6086 Stmts := No_List;
6087 PDecl := Empty;
6088 PBody := Empty;
6089 SId := Empty;
6091 -- If the aspect specification exists for some view of the type, the
6092 -- declaration for the procedure has been created.
6094 if Has_Invariants (Typ) then
6095 SId := Invariant_Procedure (Typ);
6096 end if;
6098 if Present (SId) then
6099 PDecl := Unit_Declaration_Node (SId);
6100 else
6101 PDecl := Build_Invariant_Procedure_Declaration (Typ);
6102 end if;
6104 -- Recover formal of procedure, for use in the calls to invariant
6105 -- functions (including inherited ones).
6107 Object_Entity :=
6108 Defining_Identifier
6109 (First (Parameter_Specifications (Specification (PDecl))));
6110 Object_Name := Chars (Object_Entity);
6112 -- Add invariants for the current type
6114 Add_Invariants (Typ, Inherit => False);
6116 -- Add invariants for parent types
6118 declare
6119 Current_Typ : Entity_Id;
6120 Parent_Typ : Entity_Id;
6122 begin
6123 Current_Typ := Typ;
6124 loop
6125 Parent_Typ := Etype (Current_Typ);
6127 if Is_Private_Type (Parent_Typ)
6128 and then Present (Full_View (Base_Type (Parent_Typ)))
6129 then
6130 Parent_Typ := Full_View (Base_Type (Parent_Typ));
6131 end if;
6133 exit when Parent_Typ = Current_Typ;
6135 Current_Typ := Parent_Typ;
6136 Add_Invariants (Current_Typ, Inherit => True);
6137 end loop;
6138 end;
6140 -- Build the procedure if we generated at least one Check pragma
6142 if Stmts /= No_List then
6143 Spec := Copy_Separate_Tree (Specification (PDecl));
6145 PBody :=
6146 Make_Subprogram_Body (Loc,
6147 Specification => Spec,
6148 Declarations => Empty_List,
6149 Handled_Statement_Sequence =>
6150 Make_Handled_Sequence_Of_Statements (Loc,
6151 Statements => Stmts));
6153 -- Insert procedure declaration and spec at the appropriate points.
6154 -- If declaration is already analyzed, it was processed by the
6155 -- generated pragma.
6157 if Present (Private_Decls) then
6159 -- The spec goes at the end of visible declarations, but they have
6160 -- already been analyzed, so we need to explicitly do the analyze.
6162 if not Analyzed (PDecl) then
6163 Append_To (Visible_Decls, PDecl);
6164 Analyze (PDecl);
6165 end if;
6167 -- The body goes at the end of the private declarations, which we
6168 -- have not analyzed yet, so we do not need to perform an explicit
6169 -- analyze call. We skip this if there are no private declarations
6170 -- (this is an error that will be caught elsewhere);
6172 Append_To (Private_Decls, PBody);
6174 -- If the invariant appears on the full view of a type, the
6175 -- analysis of the private part is complete, and we must
6176 -- analyze the new body explicitly.
6178 if In_Private_Part (Current_Scope) then
6179 Analyze (PBody);
6180 end if;
6182 -- If there are no private declarations this may be an error that
6183 -- will be diagnosed elsewhere. However, if this is a non-private
6184 -- type that inherits invariants, it needs no completion and there
6185 -- may be no private part. In this case insert invariant procedure
6186 -- at end of current declarative list, and analyze at once, given
6187 -- that the type is about to be frozen.
6189 elsif not Is_Private_Type (Typ) then
6190 Append_To (Visible_Decls, PDecl);
6191 Append_To (Visible_Decls, PBody);
6192 Analyze (PDecl);
6193 Analyze (PBody);
6194 end if;
6195 end if;
6196 end Build_Invariant_Procedure;
6198 -------------------------------
6199 -- Build_Predicate_Functions --
6200 -------------------------------
6202 -- The procedures that are constructed here have the form:
6204 -- function typPredicate (Ixxx : typ) return Boolean is
6205 -- begin
6206 -- return
6207 -- exp1 and then exp2 and then ...
6208 -- and then typ1Predicate (typ1 (Ixxx))
6209 -- and then typ2Predicate (typ2 (Ixxx))
6210 -- and then ...;
6211 -- end typPredicate;
6213 -- Here exp1, and exp2 are expressions from Predicate pragmas. Note that
6214 -- this is the point at which these expressions get analyzed, providing the
6215 -- required delay, and typ1, typ2, are entities from which predicates are
6216 -- inherited. Note that we do NOT generate Check pragmas, that's because we
6217 -- use this function even if checks are off, e.g. for membership tests.
6219 -- If the expression has at least one Raise_Expression, then we also build
6220 -- the typPredicateM version of the function, in which any occurrence of a
6221 -- Raise_Expression is converted to "return False".
6223 procedure Build_Predicate_Functions (Typ : Entity_Id; N : Node_Id) is
6224 Loc : constant Source_Ptr := Sloc (Typ);
6226 Expr : Node_Id;
6227 -- This is the expression for the result of the function. It is
6228 -- is build by connecting the component predicates with AND THEN.
6230 Expr_M : Node_Id;
6231 -- This is the corresponding return expression for the Predicate_M
6232 -- function. It differs in that raise expressions are marked for
6233 -- special expansion (see Process_REs).
6235 Object_Name : constant Name_Id := New_Internal_Name ('I');
6236 -- Name for argument of Predicate procedure. Note that we use the same
6237 -- name for both predicate procedure. That way the reference within the
6238 -- predicate expression is the same in both functions.
6240 Object_Entity : constant Entity_Id :=
6241 Make_Defining_Identifier (Loc, Chars => Object_Name);
6242 -- Entity for argument of Predicate procedure
6244 Object_Entity_M : constant Entity_Id :=
6245 Make_Defining_Identifier (Loc, Chars => Object_Name);
6246 -- Entity for argument of Predicate_M procedure
6248 Raise_Expression_Present : Boolean := False;
6249 -- Set True if Expr has at least one Raise_Expression
6251 Static_Predic : Node_Id := Empty;
6252 -- Set to N_Pragma node for a static predicate if one is encountered
6254 procedure Add_Call (T : Entity_Id);
6255 -- Includes a call to the predicate function for type T in Expr if T
6256 -- has predicates and Predicate_Function (T) is non-empty.
6258 procedure Add_Predicates;
6259 -- Appends expressions for any Predicate pragmas in the rep item chain
6260 -- Typ to Expr. Note that we look only at items for this exact entity.
6261 -- Inheritance of predicates for the parent type is done by calling the
6262 -- Predicate_Function of the parent type, using Add_Call above.
6264 function Test_RE (N : Node_Id) return Traverse_Result;
6265 -- Used in Test_REs, tests one node for being a raise expression, and if
6266 -- so sets Raise_Expression_Present True.
6268 procedure Test_REs is new Traverse_Proc (Test_RE);
6269 -- Tests to see if Expr contains any raise expressions
6271 function Process_RE (N : Node_Id) return Traverse_Result;
6272 -- Used in Process REs, tests if node N is a raise expression, and if
6273 -- so, marks it to be converted to return False.
6275 procedure Process_REs is new Traverse_Proc (Process_RE);
6276 -- Marks any raise expressions in Expr_M to return False
6278 --------------
6279 -- Add_Call --
6280 --------------
6282 procedure Add_Call (T : Entity_Id) is
6283 Exp : Node_Id;
6285 begin
6286 if Present (T) and then Present (Predicate_Function (T)) then
6287 Set_Has_Predicates (Typ);
6289 -- Build the call to the predicate function of T
6291 Exp :=
6292 Make_Predicate_Call
6293 (T, Convert_To (T, Make_Identifier (Loc, Object_Name)));
6295 -- Add call to evolving expression, using AND THEN if needed
6297 if No (Expr) then
6298 Expr := Exp;
6299 else
6300 Expr :=
6301 Make_And_Then (Loc,
6302 Left_Opnd => Relocate_Node (Expr),
6303 Right_Opnd => Exp);
6304 end if;
6306 -- Output info message on inheritance if required. Note we do not
6307 -- give this information for generic actual types, since it is
6308 -- unwelcome noise in that case in instantiations. We also
6309 -- generally suppress the message in instantiations, and also
6310 -- if it involves internal names.
6312 if Opt.List_Inherited_Aspects
6313 and then not Is_Generic_Actual_Type (Typ)
6314 and then Instantiation_Depth (Sloc (Typ)) = 0
6315 and then not Is_Internal_Name (Chars (T))
6316 and then not Is_Internal_Name (Chars (Typ))
6317 then
6318 Error_Msg_Sloc := Sloc (Predicate_Function (T));
6319 Error_Msg_Node_2 := T;
6320 Error_Msg_N ("info: & inherits predicate from & #?L?", Typ);
6321 end if;
6322 end if;
6323 end Add_Call;
6325 --------------------
6326 -- Add_Predicates --
6327 --------------------
6329 procedure Add_Predicates is
6330 Ritem : Node_Id;
6331 Arg1 : Node_Id;
6332 Arg2 : Node_Id;
6334 procedure Replace_Type_Reference (N : Node_Id);
6335 -- Replace a single occurrence N of the subtype name with a reference
6336 -- to the formal of the predicate function. N can be an identifier
6337 -- referencing the subtype, or a selected component, representing an
6338 -- appropriately qualified occurrence of the subtype name.
6340 procedure Replace_Type_References is
6341 new Replace_Type_References_Generic (Replace_Type_Reference);
6342 -- Traverse an expression changing every occurrence of an identifier
6343 -- whose name matches the name of the subtype with a reference to
6344 -- the formal parameter of the predicate function.
6346 ----------------------------
6347 -- Replace_Type_Reference --
6348 ----------------------------
6350 procedure Replace_Type_Reference (N : Node_Id) is
6351 begin
6352 Rewrite (N, Make_Identifier (Sloc (N), Object_Name));
6353 -- Use the Sloc of the usage name, not the defining name
6355 Set_Etype (N, Typ);
6356 Set_Entity (N, Object_Entity);
6358 -- We want to treat the node as if it comes from source, so that
6359 -- ASIS will not ignore it
6361 Set_Comes_From_Source (N, True);
6362 end Replace_Type_Reference;
6364 -- Start of processing for Add_Predicates
6366 begin
6367 Ritem := First_Rep_Item (Typ);
6368 while Present (Ritem) loop
6369 if Nkind (Ritem) = N_Pragma
6370 and then Pragma_Name (Ritem) = Name_Predicate
6371 then
6372 -- Save the static predicate of the type for diagnostics and
6373 -- error reporting purposes.
6375 if Present (Corresponding_Aspect (Ritem))
6376 and then Chars (Identifier (Corresponding_Aspect (Ritem))) =
6377 Name_Static_Predicate
6378 then
6379 Static_Predic := Ritem;
6380 end if;
6382 -- Acquire arguments
6384 Arg1 := First (Pragma_Argument_Associations (Ritem));
6385 Arg2 := Next (Arg1);
6387 Arg1 := Get_Pragma_Arg (Arg1);
6388 Arg2 := Get_Pragma_Arg (Arg2);
6390 -- See if this predicate pragma is for the current type or for
6391 -- its full view. A predicate on a private completion is placed
6392 -- on the partial view beause this is the visible entity that
6393 -- is frozen.
6395 if Entity (Arg1) = Typ
6396 or else Full_View (Entity (Arg1)) = Typ
6397 then
6398 -- We have a match, this entry is for our subtype
6400 -- We need to replace any occurrences of the name of the
6401 -- type with references to the object.
6403 Replace_Type_References (Arg2, Chars (Typ));
6405 -- If this predicate comes from an aspect, find the aspect
6406 -- specification, and replace the saved expression because
6407 -- we need the subtype references replaced for the calls to
6408 -- Preanalyze_Spec_Expressin in Check_Aspect_At_Freeze_Point
6409 -- and Check_Aspect_At_End_Of_Declarations.
6411 if From_Aspect_Specification (Ritem) then
6412 declare
6413 Aitem : Node_Id;
6415 begin
6416 -- Loop to find corresponding aspect, note that this
6417 -- must be present given the pragma is marked delayed.
6419 Aitem := Next_Rep_Item (Ritem);
6420 loop
6421 if Nkind (Aitem) = N_Aspect_Specification
6422 and then Aspect_Rep_Item (Aitem) = Ritem
6423 then
6424 Set_Entity
6425 (Identifier (Aitem), New_Copy_Tree (Arg2));
6426 exit;
6427 end if;
6429 Aitem := Next_Rep_Item (Aitem);
6430 end loop;
6431 end;
6432 end if;
6434 -- Now we can add the expression
6436 if No (Expr) then
6437 Expr := Relocate_Node (Arg2);
6439 -- There already was a predicate, so add to it
6441 else
6442 Expr :=
6443 Make_And_Then (Loc,
6444 Left_Opnd => Relocate_Node (Expr),
6445 Right_Opnd => Relocate_Node (Arg2));
6446 end if;
6447 end if;
6448 end if;
6450 Next_Rep_Item (Ritem);
6451 end loop;
6452 end Add_Predicates;
6454 ----------------
6455 -- Process_RE --
6456 ----------------
6458 function Process_RE (N : Node_Id) return Traverse_Result is
6459 begin
6460 if Nkind (N) = N_Raise_Expression then
6461 Set_Convert_To_Return_False (N);
6462 return Skip;
6463 else
6464 return OK;
6465 end if;
6466 end Process_RE;
6468 -------------
6469 -- Test_RE --
6470 -------------
6472 function Test_RE (N : Node_Id) return Traverse_Result is
6473 begin
6474 if Nkind (N) = N_Raise_Expression then
6475 Raise_Expression_Present := True;
6476 return Abandon;
6477 else
6478 return OK;
6479 end if;
6480 end Test_RE;
6482 -- Start of processing for Build_Predicate_Functions
6484 begin
6485 -- Return if already built or if type does not have predicates
6487 if not Has_Predicates (Typ)
6488 or else Present (Predicate_Function (Typ))
6489 then
6490 return;
6491 end if;
6493 -- Prepare to construct predicate expression
6495 Expr := Empty;
6497 -- Add Predicates for the current type
6499 Add_Predicates;
6501 -- Add predicates for ancestor if present
6503 declare
6504 Atyp : constant Entity_Id := Nearest_Ancestor (Typ);
6505 begin
6506 if Present (Atyp) then
6507 Add_Call (Atyp);
6508 end if;
6509 end;
6511 -- Case where predicates are present
6513 if Present (Expr) then
6515 -- Test for raise expression present
6517 Test_REs (Expr);
6519 -- If raise expression is present, capture a copy of Expr for use
6520 -- in building the predicateM function version later on. For this
6521 -- copy we replace references to Object_Entity by Object_Entity_M.
6523 if Raise_Expression_Present then
6524 declare
6525 Map : constant Elist_Id := New_Elmt_List;
6526 begin
6527 Append_Elmt (Object_Entity, Map);
6528 Append_Elmt (Object_Entity_M, Map);
6529 Expr_M := New_Copy_Tree (Expr, Map => Map);
6530 end;
6531 end if;
6533 -- Build the main predicate function
6535 declare
6536 SId : constant Entity_Id :=
6537 Make_Defining_Identifier (Loc,
6538 Chars => New_External_Name (Chars (Typ), "Predicate"));
6539 -- The entity for the the function spec
6541 SIdB : constant Entity_Id :=
6542 Make_Defining_Identifier (Loc,
6543 Chars => New_External_Name (Chars (Typ), "Predicate"));
6544 -- The entity for the function body
6546 Spec : Node_Id;
6547 FDecl : Node_Id;
6548 FBody : Node_Id;
6550 begin
6551 -- Build function declaration
6553 Set_Ekind (SId, E_Function);
6554 Set_Is_Predicate_Function (SId);
6555 Set_Predicate_Function (Typ, SId);
6557 -- The predicate function is shared between views of a type
6559 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
6560 Set_Predicate_Function (Full_View (Typ), SId);
6561 end if;
6563 Spec :=
6564 Make_Function_Specification (Loc,
6565 Defining_Unit_Name => SId,
6566 Parameter_Specifications => New_List (
6567 Make_Parameter_Specification (Loc,
6568 Defining_Identifier => Object_Entity,
6569 Parameter_Type => New_Occurrence_Of (Typ, Loc))),
6570 Result_Definition =>
6571 New_Occurrence_Of (Standard_Boolean, Loc));
6573 FDecl :=
6574 Make_Subprogram_Declaration (Loc,
6575 Specification => Spec);
6577 -- Build function body
6579 Spec :=
6580 Make_Function_Specification (Loc,
6581 Defining_Unit_Name => SIdB,
6582 Parameter_Specifications => New_List (
6583 Make_Parameter_Specification (Loc,
6584 Defining_Identifier =>
6585 Make_Defining_Identifier (Loc, Object_Name),
6586 Parameter_Type =>
6587 New_Occurrence_Of (Typ, Loc))),
6588 Result_Definition =>
6589 New_Occurrence_Of (Standard_Boolean, Loc));
6591 FBody :=
6592 Make_Subprogram_Body (Loc,
6593 Specification => Spec,
6594 Declarations => Empty_List,
6595 Handled_Statement_Sequence =>
6596 Make_Handled_Sequence_Of_Statements (Loc,
6597 Statements => New_List (
6598 Make_Simple_Return_Statement (Loc,
6599 Expression => Expr))));
6601 -- Insert declaration before freeze node and body after
6603 Insert_Before_And_Analyze (N, FDecl);
6604 Insert_After_And_Analyze (N, FBody);
6605 end;
6607 -- Test for raise expressions present and if so build M version
6609 if Raise_Expression_Present then
6610 declare
6611 SId : constant Entity_Id :=
6612 Make_Defining_Identifier (Loc,
6613 Chars => New_External_Name (Chars (Typ), "PredicateM"));
6614 -- The entity for the the function spec
6616 SIdB : constant Entity_Id :=
6617 Make_Defining_Identifier (Loc,
6618 Chars => New_External_Name (Chars (Typ), "PredicateM"));
6619 -- The entity for the function body
6621 Spec : Node_Id;
6622 FDecl : Node_Id;
6623 FBody : Node_Id;
6624 BTemp : Entity_Id;
6626 begin
6627 -- Mark any raise expressions for special expansion
6629 Process_REs (Expr_M);
6631 -- Build function declaration
6633 Set_Ekind (SId, E_Function);
6634 Set_Is_Predicate_Function_M (SId);
6635 Set_Predicate_Function_M (Typ, SId);
6637 -- The predicate function is shared between views of a type
6639 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
6640 Set_Predicate_Function_M (Full_View (Typ), SId);
6641 end if;
6643 Spec :=
6644 Make_Function_Specification (Loc,
6645 Defining_Unit_Name => SId,
6646 Parameter_Specifications => New_List (
6647 Make_Parameter_Specification (Loc,
6648 Defining_Identifier => Object_Entity_M,
6649 Parameter_Type => New_Occurrence_Of (Typ, Loc))),
6650 Result_Definition =>
6651 New_Occurrence_Of (Standard_Boolean, Loc));
6653 FDecl :=
6654 Make_Subprogram_Declaration (Loc,
6655 Specification => Spec);
6657 -- Build function body
6659 Spec :=
6660 Make_Function_Specification (Loc,
6661 Defining_Unit_Name => SIdB,
6662 Parameter_Specifications => New_List (
6663 Make_Parameter_Specification (Loc,
6664 Defining_Identifier =>
6665 Make_Defining_Identifier (Loc, Object_Name),
6666 Parameter_Type =>
6667 New_Occurrence_Of (Typ, Loc))),
6668 Result_Definition =>
6669 New_Occurrence_Of (Standard_Boolean, Loc));
6671 -- Build the body, we declare the boolean expression before
6672 -- doing the return, because we are not really confident of
6673 -- what happens if a return appears within a return!
6675 BTemp :=
6676 Make_Defining_Identifier (Loc,
6677 Chars => New_Internal_Name ('B'));
6679 FBody :=
6680 Make_Subprogram_Body (Loc,
6681 Specification => Spec,
6683 Declarations => New_List (
6684 Make_Object_Declaration (Loc,
6685 Defining_Identifier => BTemp,
6686 Constant_Present => True,
6687 Object_Definition =>
6688 New_Reference_To (Standard_Boolean, Loc),
6689 Expression => Expr_M)),
6691 Handled_Statement_Sequence =>
6692 Make_Handled_Sequence_Of_Statements (Loc,
6693 Statements => New_List (
6694 Make_Simple_Return_Statement (Loc,
6695 Expression => New_Reference_To (BTemp, Loc)))));
6697 -- Insert declaration before freeze node and body after
6699 Insert_Before_And_Analyze (N, FDecl);
6700 Insert_After_And_Analyze (N, FBody);
6701 end;
6702 end if;
6704 if Is_Scalar_Type (Typ) then
6706 -- Attempt to build a static predicate for a discrete or a real
6707 -- subtype. This action may fail because the actual expression may
6708 -- not be static. Note that the presence of an inherited or
6709 -- explicitly declared dynamic predicate is orthogonal to this
6710 -- check because we are only interested in the static predicate.
6712 if Ekind_In (Typ, E_Decimal_Fixed_Point_Subtype,
6713 E_Enumeration_Subtype,
6714 E_Floating_Point_Subtype,
6715 E_Modular_Integer_Subtype,
6716 E_Ordinary_Fixed_Point_Subtype,
6717 E_Signed_Integer_Subtype)
6718 then
6719 Build_Static_Predicate (Typ, Expr, Object_Name);
6721 -- Emit an error when the predicate is categorized as static
6722 -- but its expression is dynamic.
6724 if Present (Static_Predic)
6725 and then No (Static_Predicate (Typ))
6726 then
6727 Error_Msg_F
6728 ("expression does not have required form for "
6729 & "static predicate",
6730 Next (First (Pragma_Argument_Associations
6731 (Static_Predic))));
6732 end if;
6733 end if;
6735 -- If a static predicate applies on other types, that's an error:
6736 -- either the type is scalar but non-static, or it's not even a
6737 -- scalar type. We do not issue an error on generated types, as
6738 -- these may be duplicates of the same error on a source type.
6740 elsif Present (Static_Predic) and then Comes_From_Source (Typ) then
6741 if Is_Scalar_Type (Typ) then
6742 Error_Msg_FE
6743 ("static predicate not allowed for non-static type&",
6744 Typ, Typ);
6745 else
6746 Error_Msg_FE
6747 ("static predicate not allowed for non-scalar type&",
6748 Typ, Typ);
6749 end if;
6750 end if;
6751 end if;
6752 end Build_Predicate_Functions;
6754 ----------------------------
6755 -- Build_Static_Predicate --
6756 ----------------------------
6758 procedure Build_Static_Predicate
6759 (Typ : Entity_Id;
6760 Expr : Node_Id;
6761 Nam : Name_Id)
6763 Loc : constant Source_Ptr := Sloc (Expr);
6765 Non_Static : exception;
6766 -- Raised if something non-static is found
6768 Btyp : constant Entity_Id := Base_Type (Typ);
6770 BLo : constant Uint := Expr_Value (Type_Low_Bound (Btyp));
6771 BHi : constant Uint := Expr_Value (Type_High_Bound (Btyp));
6772 -- Low bound and high bound value of base type of Typ
6774 TLo : constant Uint := Expr_Value (Type_Low_Bound (Typ));
6775 THi : constant Uint := Expr_Value (Type_High_Bound (Typ));
6776 -- Low bound and high bound values of static subtype Typ
6778 type REnt is record
6779 Lo, Hi : Uint;
6780 end record;
6781 -- One entry in a Rlist value, a single REnt (range entry) value denotes
6782 -- one range from Lo to Hi. To represent a single value range Lo = Hi =
6783 -- value.
6785 type RList is array (Nat range <>) of REnt;
6786 -- A list of ranges. The ranges are sorted in increasing order, and are
6787 -- disjoint (there is a gap of at least one value between each range in
6788 -- the table). A value is in the set of ranges in Rlist if it lies
6789 -- within one of these ranges.
6791 False_Range : constant RList :=
6792 RList'(1 .. 0 => REnt'(No_Uint, No_Uint));
6793 -- An empty set of ranges represents a range list that can never be
6794 -- satisfied, since there are no ranges in which the value could lie,
6795 -- so it does not lie in any of them. False_Range is a canonical value
6796 -- for this empty set, but general processing should test for an Rlist
6797 -- with length zero (see Is_False predicate), since other null ranges
6798 -- may appear which must be treated as False.
6800 True_Range : constant RList := RList'(1 => REnt'(BLo, BHi));
6801 -- Range representing True, value must be in the base range
6803 function "and" (Left : RList; Right : RList) return RList;
6804 -- And's together two range lists, returning a range list. This is a set
6805 -- intersection operation.
6807 function "or" (Left : RList; Right : RList) return RList;
6808 -- Or's together two range lists, returning a range list. This is a set
6809 -- union operation.
6811 function "not" (Right : RList) return RList;
6812 -- Returns complement of a given range list, i.e. a range list
6813 -- representing all the values in TLo .. THi that are not in the input
6814 -- operand Right.
6816 function Build_Val (V : Uint) return Node_Id;
6817 -- Return an analyzed N_Identifier node referencing this value, suitable
6818 -- for use as an entry in the Static_Predicate list. This node is typed
6819 -- with the base type.
6821 function Build_Range (Lo : Uint; Hi : Uint) return Node_Id;
6822 -- Return an analyzed N_Range node referencing this range, suitable for
6823 -- use as an entry in the Static_Predicate list. This node is typed with
6824 -- the base type.
6826 function Get_RList (Exp : Node_Id) return RList;
6827 -- This is a recursive routine that converts the given expression into a
6828 -- list of ranges, suitable for use in building the static predicate.
6830 function Is_False (R : RList) return Boolean;
6831 pragma Inline (Is_False);
6832 -- Returns True if the given range list is empty, and thus represents a
6833 -- False list of ranges that can never be satisfied.
6835 function Is_True (R : RList) return Boolean;
6836 -- Returns True if R trivially represents the True predicate by having a
6837 -- single range from BLo to BHi.
6839 function Is_Type_Ref (N : Node_Id) return Boolean;
6840 pragma Inline (Is_Type_Ref);
6841 -- Returns if True if N is a reference to the type for the predicate in
6842 -- the expression (i.e. if it is an identifier whose Chars field matches
6843 -- the Nam given in the call).
6845 function Lo_Val (N : Node_Id) return Uint;
6846 -- Given static expression or static range from a Static_Predicate list,
6847 -- gets expression value or low bound of range.
6849 function Hi_Val (N : Node_Id) return Uint;
6850 -- Given static expression or static range from a Static_Predicate list,
6851 -- gets expression value of high bound of range.
6853 function Membership_Entry (N : Node_Id) return RList;
6854 -- Given a single membership entry (range, value, or subtype), returns
6855 -- the corresponding range list. Raises Static_Error if not static.
6857 function Membership_Entries (N : Node_Id) return RList;
6858 -- Given an element on an alternatives list of a membership operation,
6859 -- returns the range list corresponding to this entry and all following
6860 -- entries (i.e. returns the "or" of this list of values).
6862 function Stat_Pred (Typ : Entity_Id) return RList;
6863 -- Given a type, if it has a static predicate, then return the predicate
6864 -- as a range list, otherwise raise Non_Static.
6866 -----------
6867 -- "and" --
6868 -----------
6870 function "and" (Left : RList; Right : RList) return RList is
6871 FEnt : REnt;
6872 -- First range of result
6874 SLeft : Nat := Left'First;
6875 -- Start of rest of left entries
6877 SRight : Nat := Right'First;
6878 -- Start of rest of right entries
6880 begin
6881 -- If either range is True, return the other
6883 if Is_True (Left) then
6884 return Right;
6885 elsif Is_True (Right) then
6886 return Left;
6887 end if;
6889 -- If either range is False, return False
6891 if Is_False (Left) or else Is_False (Right) then
6892 return False_Range;
6893 end if;
6895 -- Loop to remove entries at start that are disjoint, and thus just
6896 -- get discarded from the result entirely.
6898 loop
6899 -- If no operands left in either operand, result is false
6901 if SLeft > Left'Last or else SRight > Right'Last then
6902 return False_Range;
6904 -- Discard first left operand entry if disjoint with right
6906 elsif Left (SLeft).Hi < Right (SRight).Lo then
6907 SLeft := SLeft + 1;
6909 -- Discard first right operand entry if disjoint with left
6911 elsif Right (SRight).Hi < Left (SLeft).Lo then
6912 SRight := SRight + 1;
6914 -- Otherwise we have an overlapping entry
6916 else
6917 exit;
6918 end if;
6919 end loop;
6921 -- Now we have two non-null operands, and first entries overlap. The
6922 -- first entry in the result will be the overlapping part of these
6923 -- two entries.
6925 FEnt := REnt'(Lo => UI_Max (Left (SLeft).Lo, Right (SRight).Lo),
6926 Hi => UI_Min (Left (SLeft).Hi, Right (SRight).Hi));
6928 -- Now we can remove the entry that ended at a lower value, since its
6929 -- contribution is entirely contained in Fent.
6931 if Left (SLeft).Hi <= Right (SRight).Hi then
6932 SLeft := SLeft + 1;
6933 else
6934 SRight := SRight + 1;
6935 end if;
6937 -- Compute result by concatenating this first entry with the "and" of
6938 -- the remaining parts of the left and right operands. Note that if
6939 -- either of these is empty, "and" will yield empty, so that we will
6940 -- end up with just Fent, which is what we want in that case.
6942 return
6943 FEnt & (Left (SLeft .. Left'Last) and Right (SRight .. Right'Last));
6944 end "and";
6946 -----------
6947 -- "not" --
6948 -----------
6950 function "not" (Right : RList) return RList is
6951 begin
6952 -- Return True if False range
6954 if Is_False (Right) then
6955 return True_Range;
6956 end if;
6958 -- Return False if True range
6960 if Is_True (Right) then
6961 return False_Range;
6962 end if;
6964 -- Here if not trivial case
6966 declare
6967 Result : RList (1 .. Right'Length + 1);
6968 -- May need one more entry for gap at beginning and end
6970 Count : Nat := 0;
6971 -- Number of entries stored in Result
6973 begin
6974 -- Gap at start
6976 if Right (Right'First).Lo > TLo then
6977 Count := Count + 1;
6978 Result (Count) := REnt'(TLo, Right (Right'First).Lo - 1);
6979 end if;
6981 -- Gaps between ranges
6983 for J in Right'First .. Right'Last - 1 loop
6984 Count := Count + 1;
6985 Result (Count) :=
6986 REnt'(Right (J).Hi + 1, Right (J + 1).Lo - 1);
6987 end loop;
6989 -- Gap at end
6991 if Right (Right'Last).Hi < THi then
6992 Count := Count + 1;
6993 Result (Count) := REnt'(Right (Right'Last).Hi + 1, THi);
6994 end if;
6996 return Result (1 .. Count);
6997 end;
6998 end "not";
7000 ----------
7001 -- "or" --
7002 ----------
7004 function "or" (Left : RList; Right : RList) return RList is
7005 FEnt : REnt;
7006 -- First range of result
7008 SLeft : Nat := Left'First;
7009 -- Start of rest of left entries
7011 SRight : Nat := Right'First;
7012 -- Start of rest of right entries
7014 begin
7015 -- If either range is True, return True
7017 if Is_True (Left) or else Is_True (Right) then
7018 return True_Range;
7019 end if;
7021 -- If either range is False (empty), return the other
7023 if Is_False (Left) then
7024 return Right;
7025 elsif Is_False (Right) then
7026 return Left;
7027 end if;
7029 -- Initialize result first entry from left or right operand depending
7030 -- on which starts with the lower range.
7032 if Left (SLeft).Lo < Right (SRight).Lo then
7033 FEnt := Left (SLeft);
7034 SLeft := SLeft + 1;
7035 else
7036 FEnt := Right (SRight);
7037 SRight := SRight + 1;
7038 end if;
7040 -- This loop eats ranges from left and right operands that are
7041 -- contiguous with the first range we are gathering.
7043 loop
7044 -- Eat first entry in left operand if contiguous or overlapped by
7045 -- gathered first operand of result.
7047 if SLeft <= Left'Last
7048 and then Left (SLeft).Lo <= FEnt.Hi + 1
7049 then
7050 FEnt.Hi := UI_Max (FEnt.Hi, Left (SLeft).Hi);
7051 SLeft := SLeft + 1;
7053 -- Eat first entry in right operand if contiguous or overlapped by
7054 -- gathered right operand of result.
7056 elsif SRight <= Right'Last
7057 and then Right (SRight).Lo <= FEnt.Hi + 1
7058 then
7059 FEnt.Hi := UI_Max (FEnt.Hi, Right (SRight).Hi);
7060 SRight := SRight + 1;
7062 -- All done if no more entries to eat
7064 else
7065 exit;
7066 end if;
7067 end loop;
7069 -- Obtain result as the first entry we just computed, concatenated
7070 -- to the "or" of the remaining results (if one operand is empty,
7071 -- this will just concatenate with the other
7073 return
7074 FEnt & (Left (SLeft .. Left'Last) or Right (SRight .. Right'Last));
7075 end "or";
7077 -----------------
7078 -- Build_Range --
7079 -----------------
7081 function Build_Range (Lo : Uint; Hi : Uint) return Node_Id is
7082 Result : Node_Id;
7084 begin
7085 Result :=
7086 Make_Range (Loc,
7087 Low_Bound => Build_Val (Lo),
7088 High_Bound => Build_Val (Hi));
7089 Set_Etype (Result, Btyp);
7090 Set_Analyzed (Result);
7092 return Result;
7093 end Build_Range;
7095 ---------------
7096 -- Build_Val --
7097 ---------------
7099 function Build_Val (V : Uint) return Node_Id is
7100 Result : Node_Id;
7102 begin
7103 if Is_Enumeration_Type (Typ) then
7104 Result := Get_Enum_Lit_From_Pos (Typ, V, Loc);
7105 else
7106 Result := Make_Integer_Literal (Loc, V);
7107 end if;
7109 Set_Etype (Result, Btyp);
7110 Set_Is_Static_Expression (Result);
7111 Set_Analyzed (Result);
7112 return Result;
7113 end Build_Val;
7115 ---------------
7116 -- Get_RList --
7117 ---------------
7119 function Get_RList (Exp : Node_Id) return RList is
7120 Op : Node_Kind;
7121 Val : Uint;
7123 begin
7124 -- Static expression can only be true or false
7126 if Is_OK_Static_Expression (Exp) then
7128 -- For False
7130 if Expr_Value (Exp) = 0 then
7131 return False_Range;
7132 else
7133 return True_Range;
7134 end if;
7135 end if;
7137 -- Otherwise test node type
7139 Op := Nkind (Exp);
7141 case Op is
7143 -- And
7145 when N_Op_And | N_And_Then =>
7146 return Get_RList (Left_Opnd (Exp))
7148 Get_RList (Right_Opnd (Exp));
7150 -- Or
7152 when N_Op_Or | N_Or_Else =>
7153 return Get_RList (Left_Opnd (Exp))
7155 Get_RList (Right_Opnd (Exp));
7157 -- Not
7159 when N_Op_Not =>
7160 return not Get_RList (Right_Opnd (Exp));
7162 -- Comparisons of type with static value
7164 when N_Op_Compare =>
7166 -- Type is left operand
7168 if Is_Type_Ref (Left_Opnd (Exp))
7169 and then Is_OK_Static_Expression (Right_Opnd (Exp))
7170 then
7171 Val := Expr_Value (Right_Opnd (Exp));
7173 -- Typ is right operand
7175 elsif Is_Type_Ref (Right_Opnd (Exp))
7176 and then Is_OK_Static_Expression (Left_Opnd (Exp))
7177 then
7178 Val := Expr_Value (Left_Opnd (Exp));
7180 -- Invert sense of comparison
7182 case Op is
7183 when N_Op_Gt => Op := N_Op_Lt;
7184 when N_Op_Lt => Op := N_Op_Gt;
7185 when N_Op_Ge => Op := N_Op_Le;
7186 when N_Op_Le => Op := N_Op_Ge;
7187 when others => null;
7188 end case;
7190 -- Other cases are non-static
7192 else
7193 raise Non_Static;
7194 end if;
7196 -- Construct range according to comparison operation
7198 case Op is
7199 when N_Op_Eq =>
7200 return RList'(1 => REnt'(Val, Val));
7202 when N_Op_Ge =>
7203 return RList'(1 => REnt'(Val, BHi));
7205 when N_Op_Gt =>
7206 return RList'(1 => REnt'(Val + 1, BHi));
7208 when N_Op_Le =>
7209 return RList'(1 => REnt'(BLo, Val));
7211 when N_Op_Lt =>
7212 return RList'(1 => REnt'(BLo, Val - 1));
7214 when N_Op_Ne =>
7215 return RList'(REnt'(BLo, Val - 1),
7216 REnt'(Val + 1, BHi));
7218 when others =>
7219 raise Program_Error;
7220 end case;
7222 -- Membership (IN)
7224 when N_In =>
7225 if not Is_Type_Ref (Left_Opnd (Exp)) then
7226 raise Non_Static;
7227 end if;
7229 if Present (Right_Opnd (Exp)) then
7230 return Membership_Entry (Right_Opnd (Exp));
7231 else
7232 return Membership_Entries (First (Alternatives (Exp)));
7233 end if;
7235 -- Negative membership (NOT IN)
7237 when N_Not_In =>
7238 if not Is_Type_Ref (Left_Opnd (Exp)) then
7239 raise Non_Static;
7240 end if;
7242 if Present (Right_Opnd (Exp)) then
7243 return not Membership_Entry (Right_Opnd (Exp));
7244 else
7245 return not Membership_Entries (First (Alternatives (Exp)));
7246 end if;
7248 -- Function call, may be call to static predicate
7250 when N_Function_Call =>
7251 if Is_Entity_Name (Name (Exp)) then
7252 declare
7253 Ent : constant Entity_Id := Entity (Name (Exp));
7254 begin
7255 if Is_Predicate_Function (Ent)
7256 or else
7257 Is_Predicate_Function_M (Ent)
7258 then
7259 return Stat_Pred (Etype (First_Formal (Ent)));
7260 end if;
7261 end;
7262 end if;
7264 -- Other function call cases are non-static
7266 raise Non_Static;
7268 -- Qualified expression, dig out the expression
7270 when N_Qualified_Expression =>
7271 return Get_RList (Expression (Exp));
7273 -- Expression with actions: if no actions, dig out expression
7275 when N_Expression_With_Actions =>
7276 if Is_Empty_List (Actions (Exp)) then
7277 return Get_RList (Expression (Exp));
7279 else
7280 raise Non_Static;
7281 end if;
7283 -- Xor operator
7285 when N_Op_Xor =>
7286 return (Get_RList (Left_Opnd (Exp))
7287 and not Get_RList (Right_Opnd (Exp)))
7288 or (Get_RList (Right_Opnd (Exp))
7289 and not Get_RList (Left_Opnd (Exp)));
7291 -- Any other node type is non-static
7293 when others =>
7294 raise Non_Static;
7295 end case;
7296 end Get_RList;
7298 ------------
7299 -- Hi_Val --
7300 ------------
7302 function Hi_Val (N : Node_Id) return Uint is
7303 begin
7304 if Is_Static_Expression (N) then
7305 return Expr_Value (N);
7306 else
7307 pragma Assert (Nkind (N) = N_Range);
7308 return Expr_Value (High_Bound (N));
7309 end if;
7310 end Hi_Val;
7312 --------------
7313 -- Is_False --
7314 --------------
7316 function Is_False (R : RList) return Boolean is
7317 begin
7318 return R'Length = 0;
7319 end Is_False;
7321 -------------
7322 -- Is_True --
7323 -------------
7325 function Is_True (R : RList) return Boolean is
7326 begin
7327 return R'Length = 1
7328 and then R (R'First).Lo = BLo
7329 and then R (R'First).Hi = BHi;
7330 end Is_True;
7332 -----------------
7333 -- Is_Type_Ref --
7334 -----------------
7336 function Is_Type_Ref (N : Node_Id) return Boolean is
7337 begin
7338 return Nkind (N) = N_Identifier and then Chars (N) = Nam;
7339 end Is_Type_Ref;
7341 ------------
7342 -- Lo_Val --
7343 ------------
7345 function Lo_Val (N : Node_Id) return Uint is
7346 begin
7347 if Is_Static_Expression (N) then
7348 return Expr_Value (N);
7349 else
7350 pragma Assert (Nkind (N) = N_Range);
7351 return Expr_Value (Low_Bound (N));
7352 end if;
7353 end Lo_Val;
7355 ------------------------
7356 -- Membership_Entries --
7357 ------------------------
7359 function Membership_Entries (N : Node_Id) return RList is
7360 begin
7361 if No (Next (N)) then
7362 return Membership_Entry (N);
7363 else
7364 return Membership_Entry (N) or Membership_Entries (Next (N));
7365 end if;
7366 end Membership_Entries;
7368 ----------------------
7369 -- Membership_Entry --
7370 ----------------------
7372 function Membership_Entry (N : Node_Id) return RList is
7373 Val : Uint;
7374 SLo : Uint;
7375 SHi : Uint;
7377 begin
7378 -- Range case
7380 if Nkind (N) = N_Range then
7381 if not Is_Static_Expression (Low_Bound (N))
7382 or else
7383 not Is_Static_Expression (High_Bound (N))
7384 then
7385 raise Non_Static;
7386 else
7387 SLo := Expr_Value (Low_Bound (N));
7388 SHi := Expr_Value (High_Bound (N));
7389 return RList'(1 => REnt'(SLo, SHi));
7390 end if;
7392 -- Static expression case
7394 elsif Is_Static_Expression (N) then
7395 Val := Expr_Value (N);
7396 return RList'(1 => REnt'(Val, Val));
7398 -- Identifier (other than static expression) case
7400 else pragma Assert (Nkind (N) = N_Identifier);
7402 -- Type case
7404 if Is_Type (Entity (N)) then
7406 -- If type has predicates, process them
7408 if Has_Predicates (Entity (N)) then
7409 return Stat_Pred (Entity (N));
7411 -- For static subtype without predicates, get range
7413 elsif Is_Static_Subtype (Entity (N)) then
7414 SLo := Expr_Value (Type_Low_Bound (Entity (N)));
7415 SHi := Expr_Value (Type_High_Bound (Entity (N)));
7416 return RList'(1 => REnt'(SLo, SHi));
7418 -- Any other type makes us non-static
7420 else
7421 raise Non_Static;
7422 end if;
7424 -- Any other kind of identifier in predicate (e.g. a non-static
7425 -- expression value) means this is not a static predicate.
7427 else
7428 raise Non_Static;
7429 end if;
7430 end if;
7431 end Membership_Entry;
7433 ---------------
7434 -- Stat_Pred --
7435 ---------------
7437 function Stat_Pred (Typ : Entity_Id) return RList is
7438 begin
7439 -- Not static if type does not have static predicates
7441 if not Has_Predicates (Typ) or else No (Static_Predicate (Typ)) then
7442 raise Non_Static;
7443 end if;
7445 -- Otherwise we convert the predicate list to a range list
7447 declare
7448 Result : RList (1 .. List_Length (Static_Predicate (Typ)));
7449 P : Node_Id;
7451 begin
7452 P := First (Static_Predicate (Typ));
7453 for J in Result'Range loop
7454 Result (J) := REnt'(Lo_Val (P), Hi_Val (P));
7455 Next (P);
7456 end loop;
7458 return Result;
7459 end;
7460 end Stat_Pred;
7462 -- Start of processing for Build_Static_Predicate
7464 begin
7465 -- Now analyze the expression to see if it is a static predicate
7467 declare
7468 Ranges : constant RList := Get_RList (Expr);
7469 -- Range list from expression if it is static
7471 Plist : List_Id;
7473 begin
7474 -- Convert range list into a form for the static predicate. In the
7475 -- Ranges array, we just have raw ranges, these must be converted
7476 -- to properly typed and analyzed static expressions or range nodes.
7478 -- Note: here we limit ranges to the ranges of the subtype, so that
7479 -- a predicate is always false for values outside the subtype. That
7480 -- seems fine, such values are invalid anyway, and considering them
7481 -- to fail the predicate seems allowed and friendly, and furthermore
7482 -- simplifies processing for case statements and loops.
7484 Plist := New_List;
7486 for J in Ranges'Range loop
7487 declare
7488 Lo : Uint := Ranges (J).Lo;
7489 Hi : Uint := Ranges (J).Hi;
7491 begin
7492 -- Ignore completely out of range entry
7494 if Hi < TLo or else Lo > THi then
7495 null;
7497 -- Otherwise process entry
7499 else
7500 -- Adjust out of range value to subtype range
7502 if Lo < TLo then
7503 Lo := TLo;
7504 end if;
7506 if Hi > THi then
7507 Hi := THi;
7508 end if;
7510 -- Convert range into required form
7512 Append_To (Plist, Build_Range (Lo, Hi));
7513 end if;
7514 end;
7515 end loop;
7517 -- Processing was successful and all entries were static, so now we
7518 -- can store the result as the predicate list.
7520 Set_Static_Predicate (Typ, Plist);
7522 -- The processing for static predicates put the expression into
7523 -- canonical form as a series of ranges. It also eliminated
7524 -- duplicates and collapsed and combined ranges. We might as well
7525 -- replace the alternatives list of the right operand of the
7526 -- membership test with the static predicate list, which will
7527 -- usually be more efficient.
7529 declare
7530 New_Alts : constant List_Id := New_List;
7531 Old_Node : Node_Id;
7532 New_Node : Node_Id;
7534 begin
7535 Old_Node := First (Plist);
7536 while Present (Old_Node) loop
7537 New_Node := New_Copy (Old_Node);
7539 if Nkind (New_Node) = N_Range then
7540 Set_Low_Bound (New_Node, New_Copy (Low_Bound (Old_Node)));
7541 Set_High_Bound (New_Node, New_Copy (High_Bound (Old_Node)));
7542 end if;
7544 Append_To (New_Alts, New_Node);
7545 Next (Old_Node);
7546 end loop;
7548 -- If empty list, replace by False
7550 if Is_Empty_List (New_Alts) then
7551 Rewrite (Expr, New_Occurrence_Of (Standard_False, Loc));
7553 -- Else replace by set membership test
7555 else
7556 Rewrite (Expr,
7557 Make_In (Loc,
7558 Left_Opnd => Make_Identifier (Loc, Nam),
7559 Right_Opnd => Empty,
7560 Alternatives => New_Alts));
7562 -- Resolve new expression in function context
7564 Install_Formals (Predicate_Function (Typ));
7565 Push_Scope (Predicate_Function (Typ));
7566 Analyze_And_Resolve (Expr, Standard_Boolean);
7567 Pop_Scope;
7568 end if;
7569 end;
7570 end;
7572 -- If non-static, return doing nothing
7574 exception
7575 when Non_Static =>
7576 return;
7577 end Build_Static_Predicate;
7579 -----------------------------------------
7580 -- Check_Aspect_At_End_Of_Declarations --
7581 -----------------------------------------
7583 procedure Check_Aspect_At_End_Of_Declarations (ASN : Node_Id) is
7584 Ent : constant Entity_Id := Entity (ASN);
7585 Ident : constant Node_Id := Identifier (ASN);
7586 A_Id : constant Aspect_Id := Get_Aspect_Id (Chars (Ident));
7588 End_Decl_Expr : constant Node_Id := Entity (Ident);
7589 -- Expression to be analyzed at end of declarations
7591 Freeze_Expr : constant Node_Id := Expression (ASN);
7592 -- Expression from call to Check_Aspect_At_Freeze_Point
7594 T : constant Entity_Id := Etype (Freeze_Expr);
7595 -- Type required for preanalyze call
7597 Err : Boolean;
7598 -- Set False if error
7600 -- On entry to this procedure, Entity (Ident) contains a copy of the
7601 -- original expression from the aspect, saved for this purpose, and
7602 -- but Expression (Ident) is a preanalyzed copy of the expression,
7603 -- preanalyzed just after the freeze point.
7605 procedure Check_Overloaded_Name;
7606 -- For aspects whose expression is simply a name, this routine checks if
7607 -- the name is overloaded or not. If so, it verifies there is an
7608 -- interpretation that matches the entity obtained at the freeze point,
7609 -- otherwise the compiler complains.
7611 ---------------------------
7612 -- Check_Overloaded_Name --
7613 ---------------------------
7615 procedure Check_Overloaded_Name is
7616 begin
7617 if not Is_Overloaded (End_Decl_Expr) then
7618 Err := Entity (End_Decl_Expr) /= Entity (Freeze_Expr);
7620 else
7621 Err := True;
7623 declare
7624 Index : Interp_Index;
7625 It : Interp;
7627 begin
7628 Get_First_Interp (End_Decl_Expr, Index, It);
7629 while Present (It.Typ) loop
7630 if It.Nam = Entity (Freeze_Expr) then
7631 Err := False;
7632 exit;
7633 end if;
7635 Get_Next_Interp (Index, It);
7636 end loop;
7637 end;
7638 end if;
7639 end Check_Overloaded_Name;
7641 -- Start of processing for Check_Aspect_At_End_Of_Declarations
7643 begin
7644 -- Case of aspects Dimension, Dimension_System and Synchronization
7646 if A_Id = Aspect_Synchronization then
7647 return;
7649 -- Case of stream attributes, just have to compare entities. However,
7650 -- the expression is just a name (possibly overloaded), and there may
7651 -- be stream operations declared for unrelated types, so we just need
7652 -- to verify that one of these interpretations is the one available at
7653 -- at the freeze point.
7655 elsif A_Id = Aspect_Input or else
7656 A_Id = Aspect_Output or else
7657 A_Id = Aspect_Read or else
7658 A_Id = Aspect_Write
7659 then
7660 Analyze (End_Decl_Expr);
7661 Check_Overloaded_Name;
7663 elsif A_Id = Aspect_Variable_Indexing or else
7664 A_Id = Aspect_Constant_Indexing or else
7665 A_Id = Aspect_Default_Iterator or else
7666 A_Id = Aspect_Iterator_Element
7667 then
7668 -- Make type unfrozen before analysis, to prevent spurious errors
7669 -- about late attributes.
7671 Set_Is_Frozen (Ent, False);
7672 Analyze (End_Decl_Expr);
7673 Set_Is_Frozen (Ent, True);
7675 -- If the end of declarations comes before any other freeze
7676 -- point, the Freeze_Expr is not analyzed: no check needed.
7678 if Analyzed (Freeze_Expr) and then not In_Instance then
7679 Check_Overloaded_Name;
7680 else
7681 Err := False;
7682 end if;
7684 -- All other cases
7686 else
7687 -- In a generic context the aspect expressions have not been
7688 -- preanalyzed, so do it now. There are no conformance checks
7689 -- to perform in this case.
7691 if No (T) then
7692 Check_Aspect_At_Freeze_Point (ASN);
7693 return;
7695 -- The default values attributes may be defined in the private part,
7696 -- and the analysis of the expression may take place when only the
7697 -- partial view is visible. The expression must be scalar, so use
7698 -- the full view to resolve.
7700 elsif (A_Id = Aspect_Default_Value
7701 or else
7702 A_Id = Aspect_Default_Component_Value)
7703 and then Is_Private_Type (T)
7704 then
7705 Preanalyze_Spec_Expression (End_Decl_Expr, Full_View (T));
7706 else
7707 Preanalyze_Spec_Expression (End_Decl_Expr, T);
7708 end if;
7710 Err := not Fully_Conformant_Expressions (End_Decl_Expr, Freeze_Expr);
7711 end if;
7713 -- Output error message if error
7715 if Err then
7716 Error_Msg_NE
7717 ("visibility of aspect for& changes after freeze point",
7718 ASN, Ent);
7719 Error_Msg_NE
7720 ("info: & is frozen here, aspects evaluated at this point??",
7721 Freeze_Node (Ent), Ent);
7722 end if;
7723 end Check_Aspect_At_End_Of_Declarations;
7725 ----------------------------------
7726 -- Check_Aspect_At_Freeze_Point --
7727 ----------------------------------
7729 procedure Check_Aspect_At_Freeze_Point (ASN : Node_Id) is
7730 Ident : constant Node_Id := Identifier (ASN);
7731 -- Identifier (use Entity field to save expression)
7733 A_Id : constant Aspect_Id := Get_Aspect_Id (Chars (Ident));
7735 T : Entity_Id := Empty;
7736 -- Type required for preanalyze call
7738 begin
7739 -- On entry to this procedure, Entity (Ident) contains a copy of the
7740 -- original expression from the aspect, saved for this purpose.
7742 -- On exit from this procedure Entity (Ident) is unchanged, still
7743 -- containing that copy, but Expression (Ident) is a preanalyzed copy
7744 -- of the expression, preanalyzed just after the freeze point.
7746 -- Make a copy of the expression to be preanalyzed
7748 Set_Expression (ASN, New_Copy_Tree (Entity (Ident)));
7750 -- Find type for preanalyze call
7752 case A_Id is
7754 -- No_Aspect should be impossible
7756 when No_Aspect =>
7757 raise Program_Error;
7759 -- Aspects taking an optional boolean argument
7761 when Boolean_Aspects |
7762 Library_Unit_Aspects =>
7764 T := Standard_Boolean;
7766 -- Aspects corresponding to attribute definition clauses
7768 when Aspect_Address =>
7769 T := RTE (RE_Address);
7771 when Aspect_Attach_Handler =>
7772 T := RTE (RE_Interrupt_ID);
7774 when Aspect_Bit_Order | Aspect_Scalar_Storage_Order =>
7775 T := RTE (RE_Bit_Order);
7777 when Aspect_Convention =>
7778 return;
7780 when Aspect_CPU =>
7781 T := RTE (RE_CPU_Range);
7783 -- Default_Component_Value is resolved with the component type
7785 when Aspect_Default_Component_Value =>
7786 T := Component_Type (Entity (ASN));
7788 -- Default_Value is resolved with the type entity in question
7790 when Aspect_Default_Value =>
7791 T := Entity (ASN);
7793 -- Depends is a delayed aspect because it mentiones names first
7794 -- introduced by aspect Global which is already delayed. There is
7795 -- no action to be taken with respect to the aspect itself as the
7796 -- analysis is done by the corresponding pragma.
7798 when Aspect_Depends =>
7799 return;
7801 when Aspect_Dispatching_Domain =>
7802 T := RTE (RE_Dispatching_Domain);
7804 when Aspect_External_Tag =>
7805 T := Standard_String;
7807 when Aspect_External_Name =>
7808 T := Standard_String;
7810 -- Global is a delayed aspect because it may reference names that
7811 -- have not been declared yet. There is no action to be taken with
7812 -- respect to the aspect itself as the reference checking is done
7813 -- on the corresponding pragma.
7815 when Aspect_Global =>
7816 return;
7818 when Aspect_Link_Name =>
7819 T := Standard_String;
7821 when Aspect_Priority | Aspect_Interrupt_Priority =>
7822 T := Standard_Integer;
7824 when Aspect_Relative_Deadline =>
7825 T := RTE (RE_Time_Span);
7827 when Aspect_Small =>
7828 T := Universal_Real;
7830 -- For a simple storage pool, we have to retrieve the type of the
7831 -- pool object associated with the aspect's corresponding attribute
7832 -- definition clause.
7834 when Aspect_Simple_Storage_Pool =>
7835 T := Etype (Expression (Aspect_Rep_Item (ASN)));
7837 when Aspect_Storage_Pool =>
7838 T := Class_Wide_Type (RTE (RE_Root_Storage_Pool));
7840 when Aspect_Alignment |
7841 Aspect_Component_Size |
7842 Aspect_Machine_Radix |
7843 Aspect_Object_Size |
7844 Aspect_Size |
7845 Aspect_Storage_Size |
7846 Aspect_Stream_Size |
7847 Aspect_Value_Size =>
7848 T := Any_Integer;
7850 when Aspect_Synchronization =>
7851 return;
7853 -- Special case, the expression of these aspects is just an entity
7854 -- that does not need any resolution, so just analyze.
7856 when Aspect_Input |
7857 Aspect_Output |
7858 Aspect_Read |
7859 Aspect_Suppress |
7860 Aspect_Unsuppress |
7861 Aspect_Warnings |
7862 Aspect_Write =>
7863 Analyze (Expression (ASN));
7864 return;
7866 -- Same for Iterator aspects, where the expression is a function
7867 -- name. Legality rules are checked separately.
7869 when Aspect_Constant_Indexing |
7870 Aspect_Default_Iterator |
7871 Aspect_Iterator_Element |
7872 Aspect_Variable_Indexing =>
7873 Analyze (Expression (ASN));
7874 return;
7876 -- Invariant/Predicate take boolean expressions
7878 when Aspect_Dynamic_Predicate |
7879 Aspect_Invariant |
7880 Aspect_Predicate |
7881 Aspect_Static_Predicate |
7882 Aspect_Type_Invariant =>
7883 T := Standard_Boolean;
7885 -- Here is the list of aspects that don't require delay analysis
7887 when Aspect_Abstract_State |
7888 Aspect_Contract_Cases |
7889 Aspect_Dimension |
7890 Aspect_Dimension_System |
7891 Aspect_Implicit_Dereference |
7892 Aspect_Initial_Condition |
7893 Aspect_Initializes |
7894 Aspect_Post |
7895 Aspect_Postcondition |
7896 Aspect_Pre |
7897 Aspect_Precondition |
7898 Aspect_Refined_Depends |
7899 Aspect_Refined_Global |
7900 Aspect_Refined_Post |
7901 Aspect_Refined_State |
7902 Aspect_SPARK_Mode |
7903 Aspect_Test_Case =>
7904 raise Program_Error;
7906 end case;
7908 -- Do the preanalyze call
7910 Preanalyze_Spec_Expression (Expression (ASN), T);
7911 end Check_Aspect_At_Freeze_Point;
7913 -----------------------------------
7914 -- Check_Constant_Address_Clause --
7915 -----------------------------------
7917 procedure Check_Constant_Address_Clause
7918 (Expr : Node_Id;
7919 U_Ent : Entity_Id)
7921 procedure Check_At_Constant_Address (Nod : Node_Id);
7922 -- Checks that the given node N represents a name whose 'Address is
7923 -- constant (in the same sense as OK_Constant_Address_Clause, i.e. the
7924 -- address value is the same at the point of declaration of U_Ent and at
7925 -- the time of elaboration of the address clause.
7927 procedure Check_Expr_Constants (Nod : Node_Id);
7928 -- Checks that Nod meets the requirements for a constant address clause
7929 -- in the sense of the enclosing procedure.
7931 procedure Check_List_Constants (Lst : List_Id);
7932 -- Check that all elements of list Lst meet the requirements for a
7933 -- constant address clause in the sense of the enclosing procedure.
7935 -------------------------------
7936 -- Check_At_Constant_Address --
7937 -------------------------------
7939 procedure Check_At_Constant_Address (Nod : Node_Id) is
7940 begin
7941 if Is_Entity_Name (Nod) then
7942 if Present (Address_Clause (Entity ((Nod)))) then
7943 Error_Msg_NE
7944 ("invalid address clause for initialized object &!",
7945 Nod, U_Ent);
7946 Error_Msg_NE
7947 ("address for& cannot" &
7948 " depend on another address clause! (RM 13.1(22))!",
7949 Nod, U_Ent);
7951 elsif In_Same_Source_Unit (Entity (Nod), U_Ent)
7952 and then Sloc (U_Ent) < Sloc (Entity (Nod))
7953 then
7954 Error_Msg_NE
7955 ("invalid address clause for initialized object &!",
7956 Nod, U_Ent);
7957 Error_Msg_Node_2 := U_Ent;
7958 Error_Msg_NE
7959 ("\& must be defined before & (RM 13.1(22))!",
7960 Nod, Entity (Nod));
7961 end if;
7963 elsif Nkind (Nod) = N_Selected_Component then
7964 declare
7965 T : constant Entity_Id := Etype (Prefix (Nod));
7967 begin
7968 if (Is_Record_Type (T)
7969 and then Has_Discriminants (T))
7970 or else
7971 (Is_Access_Type (T)
7972 and then Is_Record_Type (Designated_Type (T))
7973 and then Has_Discriminants (Designated_Type (T)))
7974 then
7975 Error_Msg_NE
7976 ("invalid address clause for initialized object &!",
7977 Nod, U_Ent);
7978 Error_Msg_N
7979 ("\address cannot depend on component" &
7980 " of discriminated record (RM 13.1(22))!",
7981 Nod);
7982 else
7983 Check_At_Constant_Address (Prefix (Nod));
7984 end if;
7985 end;
7987 elsif Nkind (Nod) = N_Indexed_Component then
7988 Check_At_Constant_Address (Prefix (Nod));
7989 Check_List_Constants (Expressions (Nod));
7991 else
7992 Check_Expr_Constants (Nod);
7993 end if;
7994 end Check_At_Constant_Address;
7996 --------------------------
7997 -- Check_Expr_Constants --
7998 --------------------------
8000 procedure Check_Expr_Constants (Nod : Node_Id) is
8001 Loc_U_Ent : constant Source_Ptr := Sloc (U_Ent);
8002 Ent : Entity_Id := Empty;
8004 begin
8005 if Nkind (Nod) in N_Has_Etype
8006 and then Etype (Nod) = Any_Type
8007 then
8008 return;
8009 end if;
8011 case Nkind (Nod) is
8012 when N_Empty | N_Error =>
8013 return;
8015 when N_Identifier | N_Expanded_Name =>
8016 Ent := Entity (Nod);
8018 -- We need to look at the original node if it is different
8019 -- from the node, since we may have rewritten things and
8020 -- substituted an identifier representing the rewrite.
8022 if Original_Node (Nod) /= Nod then
8023 Check_Expr_Constants (Original_Node (Nod));
8025 -- If the node is an object declaration without initial
8026 -- value, some code has been expanded, and the expression
8027 -- is not constant, even if the constituents might be
8028 -- acceptable, as in A'Address + offset.
8030 if Ekind (Ent) = E_Variable
8031 and then
8032 Nkind (Declaration_Node (Ent)) = N_Object_Declaration
8033 and then
8034 No (Expression (Declaration_Node (Ent)))
8035 then
8036 Error_Msg_NE
8037 ("invalid address clause for initialized object &!",
8038 Nod, U_Ent);
8040 -- If entity is constant, it may be the result of expanding
8041 -- a check. We must verify that its declaration appears
8042 -- before the object in question, else we also reject the
8043 -- address clause.
8045 elsif Ekind (Ent) = E_Constant
8046 and then In_Same_Source_Unit (Ent, U_Ent)
8047 and then Sloc (Ent) > Loc_U_Ent
8048 then
8049 Error_Msg_NE
8050 ("invalid address clause for initialized object &!",
8051 Nod, U_Ent);
8052 end if;
8054 return;
8055 end if;
8057 -- Otherwise look at the identifier and see if it is OK
8059 if Ekind_In (Ent, E_Named_Integer, E_Named_Real)
8060 or else Is_Type (Ent)
8061 then
8062 return;
8064 elsif
8065 Ekind (Ent) = E_Constant
8066 or else
8067 Ekind (Ent) = E_In_Parameter
8068 then
8069 -- This is the case where we must have Ent defined before
8070 -- U_Ent. Clearly if they are in different units this
8071 -- requirement is met since the unit containing Ent is
8072 -- already processed.
8074 if not In_Same_Source_Unit (Ent, U_Ent) then
8075 return;
8077 -- Otherwise location of Ent must be before the location
8078 -- of U_Ent, that's what prior defined means.
8080 elsif Sloc (Ent) < Loc_U_Ent then
8081 return;
8083 else
8084 Error_Msg_NE
8085 ("invalid address clause for initialized object &!",
8086 Nod, U_Ent);
8087 Error_Msg_Node_2 := U_Ent;
8088 Error_Msg_NE
8089 ("\& must be defined before & (RM 13.1(22))!",
8090 Nod, Ent);
8091 end if;
8093 elsif Nkind (Original_Node (Nod)) = N_Function_Call then
8094 Check_Expr_Constants (Original_Node (Nod));
8096 else
8097 Error_Msg_NE
8098 ("invalid address clause for initialized object &!",
8099 Nod, U_Ent);
8101 if Comes_From_Source (Ent) then
8102 Error_Msg_NE
8103 ("\reference to variable& not allowed"
8104 & " (RM 13.1(22))!", Nod, Ent);
8105 else
8106 Error_Msg_N
8107 ("non-static expression not allowed"
8108 & " (RM 13.1(22))!", Nod);
8109 end if;
8110 end if;
8112 when N_Integer_Literal =>
8114 -- If this is a rewritten unchecked conversion, in a system
8115 -- where Address is an integer type, always use the base type
8116 -- for a literal value. This is user-friendly and prevents
8117 -- order-of-elaboration issues with instances of unchecked
8118 -- conversion.
8120 if Nkind (Original_Node (Nod)) = N_Function_Call then
8121 Set_Etype (Nod, Base_Type (Etype (Nod)));
8122 end if;
8124 when N_Real_Literal |
8125 N_String_Literal |
8126 N_Character_Literal =>
8127 return;
8129 when N_Range =>
8130 Check_Expr_Constants (Low_Bound (Nod));
8131 Check_Expr_Constants (High_Bound (Nod));
8133 when N_Explicit_Dereference =>
8134 Check_Expr_Constants (Prefix (Nod));
8136 when N_Indexed_Component =>
8137 Check_Expr_Constants (Prefix (Nod));
8138 Check_List_Constants (Expressions (Nod));
8140 when N_Slice =>
8141 Check_Expr_Constants (Prefix (Nod));
8142 Check_Expr_Constants (Discrete_Range (Nod));
8144 when N_Selected_Component =>
8145 Check_Expr_Constants (Prefix (Nod));
8147 when N_Attribute_Reference =>
8148 if Nam_In (Attribute_Name (Nod), Name_Address,
8149 Name_Access,
8150 Name_Unchecked_Access,
8151 Name_Unrestricted_Access)
8152 then
8153 Check_At_Constant_Address (Prefix (Nod));
8155 else
8156 Check_Expr_Constants (Prefix (Nod));
8157 Check_List_Constants (Expressions (Nod));
8158 end if;
8160 when N_Aggregate =>
8161 Check_List_Constants (Component_Associations (Nod));
8162 Check_List_Constants (Expressions (Nod));
8164 when N_Component_Association =>
8165 Check_Expr_Constants (Expression (Nod));
8167 when N_Extension_Aggregate =>
8168 Check_Expr_Constants (Ancestor_Part (Nod));
8169 Check_List_Constants (Component_Associations (Nod));
8170 Check_List_Constants (Expressions (Nod));
8172 when N_Null =>
8173 return;
8175 when N_Binary_Op | N_Short_Circuit | N_Membership_Test =>
8176 Check_Expr_Constants (Left_Opnd (Nod));
8177 Check_Expr_Constants (Right_Opnd (Nod));
8179 when N_Unary_Op =>
8180 Check_Expr_Constants (Right_Opnd (Nod));
8182 when N_Type_Conversion |
8183 N_Qualified_Expression |
8184 N_Allocator |
8185 N_Unchecked_Type_Conversion =>
8186 Check_Expr_Constants (Expression (Nod));
8188 when N_Function_Call =>
8189 if not Is_Pure (Entity (Name (Nod))) then
8190 Error_Msg_NE
8191 ("invalid address clause for initialized object &!",
8192 Nod, U_Ent);
8194 Error_Msg_NE
8195 ("\function & is not pure (RM 13.1(22))!",
8196 Nod, Entity (Name (Nod)));
8198 else
8199 Check_List_Constants (Parameter_Associations (Nod));
8200 end if;
8202 when N_Parameter_Association =>
8203 Check_Expr_Constants (Explicit_Actual_Parameter (Nod));
8205 when others =>
8206 Error_Msg_NE
8207 ("invalid address clause for initialized object &!",
8208 Nod, U_Ent);
8209 Error_Msg_NE
8210 ("\must be constant defined before& (RM 13.1(22))!",
8211 Nod, U_Ent);
8212 end case;
8213 end Check_Expr_Constants;
8215 --------------------------
8216 -- Check_List_Constants --
8217 --------------------------
8219 procedure Check_List_Constants (Lst : List_Id) is
8220 Nod1 : Node_Id;
8222 begin
8223 if Present (Lst) then
8224 Nod1 := First (Lst);
8225 while Present (Nod1) loop
8226 Check_Expr_Constants (Nod1);
8227 Next (Nod1);
8228 end loop;
8229 end if;
8230 end Check_List_Constants;
8232 -- Start of processing for Check_Constant_Address_Clause
8234 begin
8235 -- If rep_clauses are to be ignored, no need for legality checks. In
8236 -- particular, no need to pester user about rep clauses that violate
8237 -- the rule on constant addresses, given that these clauses will be
8238 -- removed by Freeze before they reach the back end.
8240 if not Ignore_Rep_Clauses then
8241 Check_Expr_Constants (Expr);
8242 end if;
8243 end Check_Constant_Address_Clause;
8245 ----------------------------------------
8246 -- Check_Record_Representation_Clause --
8247 ----------------------------------------
8249 procedure Check_Record_Representation_Clause (N : Node_Id) is
8250 Loc : constant Source_Ptr := Sloc (N);
8251 Ident : constant Node_Id := Identifier (N);
8252 Rectype : Entity_Id;
8253 Fent : Entity_Id;
8254 CC : Node_Id;
8255 Fbit : Uint;
8256 Lbit : Uint;
8257 Hbit : Uint := Uint_0;
8258 Comp : Entity_Id;
8259 Pcomp : Entity_Id;
8261 Max_Bit_So_Far : Uint;
8262 -- Records the maximum bit position so far. If all field positions
8263 -- are monotonically increasing, then we can skip the circuit for
8264 -- checking for overlap, since no overlap is possible.
8266 Tagged_Parent : Entity_Id := Empty;
8267 -- This is set in the case of a derived tagged type for which we have
8268 -- Is_Fully_Repped_Tagged_Type True (indicating that all components are
8269 -- positioned by record representation clauses). In this case we must
8270 -- check for overlap between components of this tagged type, and the
8271 -- components of its parent. Tagged_Parent will point to this parent
8272 -- type. For all other cases Tagged_Parent is left set to Empty.
8274 Parent_Last_Bit : Uint;
8275 -- Relevant only if Tagged_Parent is set, Parent_Last_Bit indicates the
8276 -- last bit position for any field in the parent type. We only need to
8277 -- check overlap for fields starting below this point.
8279 Overlap_Check_Required : Boolean;
8280 -- Used to keep track of whether or not an overlap check is required
8282 Overlap_Detected : Boolean := False;
8283 -- Set True if an overlap is detected
8285 Ccount : Natural := 0;
8286 -- Number of component clauses in record rep clause
8288 procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id);
8289 -- Given two entities for record components or discriminants, checks
8290 -- if they have overlapping component clauses and issues errors if so.
8292 procedure Find_Component;
8293 -- Finds component entity corresponding to current component clause (in
8294 -- CC), and sets Comp to the entity, and Fbit/Lbit to the zero origin
8295 -- start/stop bits for the field. If there is no matching component or
8296 -- if the matching component does not have a component clause, then
8297 -- that's an error and Comp is set to Empty, but no error message is
8298 -- issued, since the message was already given. Comp is also set to
8299 -- Empty if the current "component clause" is in fact a pragma.
8301 -----------------------------
8302 -- Check_Component_Overlap --
8303 -----------------------------
8305 procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id) is
8306 CC1 : constant Node_Id := Component_Clause (C1_Ent);
8307 CC2 : constant Node_Id := Component_Clause (C2_Ent);
8309 begin
8310 if Present (CC1) and then Present (CC2) then
8312 -- Exclude odd case where we have two tag components in the same
8313 -- record, both at location zero. This seems a bit strange, but
8314 -- it seems to happen in some circumstances, perhaps on an error.
8316 if Nam_In (Chars (C1_Ent), Name_uTag, Name_uTag) then
8317 return;
8318 end if;
8320 -- Here we check if the two fields overlap
8322 declare
8323 S1 : constant Uint := Component_Bit_Offset (C1_Ent);
8324 S2 : constant Uint := Component_Bit_Offset (C2_Ent);
8325 E1 : constant Uint := S1 + Esize (C1_Ent);
8326 E2 : constant Uint := S2 + Esize (C2_Ent);
8328 begin
8329 if E2 <= S1 or else E1 <= S2 then
8330 null;
8331 else
8332 Error_Msg_Node_2 := Component_Name (CC2);
8333 Error_Msg_Sloc := Sloc (Error_Msg_Node_2);
8334 Error_Msg_Node_1 := Component_Name (CC1);
8335 Error_Msg_N
8336 ("component& overlaps & #", Component_Name (CC1));
8337 Overlap_Detected := True;
8338 end if;
8339 end;
8340 end if;
8341 end Check_Component_Overlap;
8343 --------------------
8344 -- Find_Component --
8345 --------------------
8347 procedure Find_Component is
8349 procedure Search_Component (R : Entity_Id);
8350 -- Search components of R for a match. If found, Comp is set
8352 ----------------------
8353 -- Search_Component --
8354 ----------------------
8356 procedure Search_Component (R : Entity_Id) is
8357 begin
8358 Comp := First_Component_Or_Discriminant (R);
8359 while Present (Comp) loop
8361 -- Ignore error of attribute name for component name (we
8362 -- already gave an error message for this, so no need to
8363 -- complain here)
8365 if Nkind (Component_Name (CC)) = N_Attribute_Reference then
8366 null;
8367 else
8368 exit when Chars (Comp) = Chars (Component_Name (CC));
8369 end if;
8371 Next_Component_Or_Discriminant (Comp);
8372 end loop;
8373 end Search_Component;
8375 -- Start of processing for Find_Component
8377 begin
8378 -- Return with Comp set to Empty if we have a pragma
8380 if Nkind (CC) = N_Pragma then
8381 Comp := Empty;
8382 return;
8383 end if;
8385 -- Search current record for matching component
8387 Search_Component (Rectype);
8389 -- If not found, maybe component of base type discriminant that is
8390 -- absent from statically constrained first subtype.
8392 if No (Comp) then
8393 Search_Component (Base_Type (Rectype));
8394 end if;
8396 -- If no component, or the component does not reference the component
8397 -- clause in question, then there was some previous error for which
8398 -- we already gave a message, so just return with Comp Empty.
8400 if No (Comp) or else Component_Clause (Comp) /= CC then
8401 Check_Error_Detected;
8402 Comp := Empty;
8404 -- Normal case where we have a component clause
8406 else
8407 Fbit := Component_Bit_Offset (Comp);
8408 Lbit := Fbit + Esize (Comp) - 1;
8409 end if;
8410 end Find_Component;
8412 -- Start of processing for Check_Record_Representation_Clause
8414 begin
8415 Find_Type (Ident);
8416 Rectype := Entity (Ident);
8418 if Rectype = Any_Type then
8419 return;
8420 else
8421 Rectype := Underlying_Type (Rectype);
8422 end if;
8424 -- See if we have a fully repped derived tagged type
8426 declare
8427 PS : constant Entity_Id := Parent_Subtype (Rectype);
8429 begin
8430 if Present (PS) and then Is_Fully_Repped_Tagged_Type (PS) then
8431 Tagged_Parent := PS;
8433 -- Find maximum bit of any component of the parent type
8435 Parent_Last_Bit := UI_From_Int (System_Address_Size - 1);
8436 Pcomp := First_Entity (Tagged_Parent);
8437 while Present (Pcomp) loop
8438 if Ekind_In (Pcomp, E_Discriminant, E_Component) then
8439 if Component_Bit_Offset (Pcomp) /= No_Uint
8440 and then Known_Static_Esize (Pcomp)
8441 then
8442 Parent_Last_Bit :=
8443 UI_Max
8444 (Parent_Last_Bit,
8445 Component_Bit_Offset (Pcomp) + Esize (Pcomp) - 1);
8446 end if;
8448 Next_Entity (Pcomp);
8449 end if;
8450 end loop;
8451 end if;
8452 end;
8454 -- All done if no component clauses
8456 CC := First (Component_Clauses (N));
8458 if No (CC) then
8459 return;
8460 end if;
8462 -- If a tag is present, then create a component clause that places it
8463 -- at the start of the record (otherwise gigi may place it after other
8464 -- fields that have rep clauses).
8466 Fent := First_Entity (Rectype);
8468 if Nkind (Fent) = N_Defining_Identifier
8469 and then Chars (Fent) = Name_uTag
8470 then
8471 Set_Component_Bit_Offset (Fent, Uint_0);
8472 Set_Normalized_Position (Fent, Uint_0);
8473 Set_Normalized_First_Bit (Fent, Uint_0);
8474 Set_Normalized_Position_Max (Fent, Uint_0);
8475 Init_Esize (Fent, System_Address_Size);
8477 Set_Component_Clause (Fent,
8478 Make_Component_Clause (Loc,
8479 Component_Name => Make_Identifier (Loc, Name_uTag),
8481 Position => Make_Integer_Literal (Loc, Uint_0),
8482 First_Bit => Make_Integer_Literal (Loc, Uint_0),
8483 Last_Bit =>
8484 Make_Integer_Literal (Loc,
8485 UI_From_Int (System_Address_Size))));
8487 Ccount := Ccount + 1;
8488 end if;
8490 Max_Bit_So_Far := Uint_Minus_1;
8491 Overlap_Check_Required := False;
8493 -- Process the component clauses
8495 while Present (CC) loop
8496 Find_Component;
8498 if Present (Comp) then
8499 Ccount := Ccount + 1;
8501 -- We need a full overlap check if record positions non-monotonic
8503 if Fbit <= Max_Bit_So_Far then
8504 Overlap_Check_Required := True;
8505 end if;
8507 Max_Bit_So_Far := Lbit;
8509 -- Check bit position out of range of specified size
8511 if Has_Size_Clause (Rectype)
8512 and then RM_Size (Rectype) <= Lbit
8513 then
8514 Error_Msg_N
8515 ("bit number out of range of specified size",
8516 Last_Bit (CC));
8518 -- Check for overlap with tag component
8520 else
8521 if Is_Tagged_Type (Rectype)
8522 and then Fbit < System_Address_Size
8523 then
8524 Error_Msg_NE
8525 ("component overlaps tag field of&",
8526 Component_Name (CC), Rectype);
8527 Overlap_Detected := True;
8528 end if;
8530 if Hbit < Lbit then
8531 Hbit := Lbit;
8532 end if;
8533 end if;
8535 -- Check parent overlap if component might overlap parent field
8537 if Present (Tagged_Parent) and then Fbit <= Parent_Last_Bit then
8538 Pcomp := First_Component_Or_Discriminant (Tagged_Parent);
8539 while Present (Pcomp) loop
8540 if not Is_Tag (Pcomp)
8541 and then Chars (Pcomp) /= Name_uParent
8542 then
8543 Check_Component_Overlap (Comp, Pcomp);
8544 end if;
8546 Next_Component_Or_Discriminant (Pcomp);
8547 end loop;
8548 end if;
8549 end if;
8551 Next (CC);
8552 end loop;
8554 -- Now that we have processed all the component clauses, check for
8555 -- overlap. We have to leave this till last, since the components can
8556 -- appear in any arbitrary order in the representation clause.
8558 -- We do not need this check if all specified ranges were monotonic,
8559 -- as recorded by Overlap_Check_Required being False at this stage.
8561 -- This first section checks if there are any overlapping entries at
8562 -- all. It does this by sorting all entries and then seeing if there are
8563 -- any overlaps. If there are none, then that is decisive, but if there
8564 -- are overlaps, they may still be OK (they may result from fields in
8565 -- different variants).
8567 if Overlap_Check_Required then
8568 Overlap_Check1 : declare
8570 OC_Fbit : array (0 .. Ccount) of Uint;
8571 -- First-bit values for component clauses, the value is the offset
8572 -- of the first bit of the field from start of record. The zero
8573 -- entry is for use in sorting.
8575 OC_Lbit : array (0 .. Ccount) of Uint;
8576 -- Last-bit values for component clauses, the value is the offset
8577 -- of the last bit of the field from start of record. The zero
8578 -- entry is for use in sorting.
8580 OC_Count : Natural := 0;
8581 -- Count of entries in OC_Fbit and OC_Lbit
8583 function OC_Lt (Op1, Op2 : Natural) return Boolean;
8584 -- Compare routine for Sort
8586 procedure OC_Move (From : Natural; To : Natural);
8587 -- Move routine for Sort
8589 package Sorting is new GNAT.Heap_Sort_G (OC_Move, OC_Lt);
8591 -----------
8592 -- OC_Lt --
8593 -----------
8595 function OC_Lt (Op1, Op2 : Natural) return Boolean is
8596 begin
8597 return OC_Fbit (Op1) < OC_Fbit (Op2);
8598 end OC_Lt;
8600 -------------
8601 -- OC_Move --
8602 -------------
8604 procedure OC_Move (From : Natural; To : Natural) is
8605 begin
8606 OC_Fbit (To) := OC_Fbit (From);
8607 OC_Lbit (To) := OC_Lbit (From);
8608 end OC_Move;
8610 -- Start of processing for Overlap_Check
8612 begin
8613 CC := First (Component_Clauses (N));
8614 while Present (CC) loop
8616 -- Exclude component clause already marked in error
8618 if not Error_Posted (CC) then
8619 Find_Component;
8621 if Present (Comp) then
8622 OC_Count := OC_Count + 1;
8623 OC_Fbit (OC_Count) := Fbit;
8624 OC_Lbit (OC_Count) := Lbit;
8625 end if;
8626 end if;
8628 Next (CC);
8629 end loop;
8631 Sorting.Sort (OC_Count);
8633 Overlap_Check_Required := False;
8634 for J in 1 .. OC_Count - 1 loop
8635 if OC_Lbit (J) >= OC_Fbit (J + 1) then
8636 Overlap_Check_Required := True;
8637 exit;
8638 end if;
8639 end loop;
8640 end Overlap_Check1;
8641 end if;
8643 -- If Overlap_Check_Required is still True, then we have to do the full
8644 -- scale overlap check, since we have at least two fields that do
8645 -- overlap, and we need to know if that is OK since they are in
8646 -- different variant, or whether we have a definite problem.
8648 if Overlap_Check_Required then
8649 Overlap_Check2 : declare
8650 C1_Ent, C2_Ent : Entity_Id;
8651 -- Entities of components being checked for overlap
8653 Clist : Node_Id;
8654 -- Component_List node whose Component_Items are being checked
8656 Citem : Node_Id;
8657 -- Component declaration for component being checked
8659 begin
8660 C1_Ent := First_Entity (Base_Type (Rectype));
8662 -- Loop through all components in record. For each component check
8663 -- for overlap with any of the preceding elements on the component
8664 -- list containing the component and also, if the component is in
8665 -- a variant, check against components outside the case structure.
8666 -- This latter test is repeated recursively up the variant tree.
8668 Main_Component_Loop : while Present (C1_Ent) loop
8669 if not Ekind_In (C1_Ent, E_Component, E_Discriminant) then
8670 goto Continue_Main_Component_Loop;
8671 end if;
8673 -- Skip overlap check if entity has no declaration node. This
8674 -- happens with discriminants in constrained derived types.
8675 -- Possibly we are missing some checks as a result, but that
8676 -- does not seem terribly serious.
8678 if No (Declaration_Node (C1_Ent)) then
8679 goto Continue_Main_Component_Loop;
8680 end if;
8682 Clist := Parent (List_Containing (Declaration_Node (C1_Ent)));
8684 -- Loop through component lists that need checking. Check the
8685 -- current component list and all lists in variants above us.
8687 Component_List_Loop : loop
8689 -- If derived type definition, go to full declaration
8690 -- If at outer level, check discriminants if there are any.
8692 if Nkind (Clist) = N_Derived_Type_Definition then
8693 Clist := Parent (Clist);
8694 end if;
8696 -- Outer level of record definition, check discriminants
8698 if Nkind_In (Clist, N_Full_Type_Declaration,
8699 N_Private_Type_Declaration)
8700 then
8701 if Has_Discriminants (Defining_Identifier (Clist)) then
8702 C2_Ent :=
8703 First_Discriminant (Defining_Identifier (Clist));
8704 while Present (C2_Ent) loop
8705 exit when C1_Ent = C2_Ent;
8706 Check_Component_Overlap (C1_Ent, C2_Ent);
8707 Next_Discriminant (C2_Ent);
8708 end loop;
8709 end if;
8711 -- Record extension case
8713 elsif Nkind (Clist) = N_Derived_Type_Definition then
8714 Clist := Empty;
8716 -- Otherwise check one component list
8718 else
8719 Citem := First (Component_Items (Clist));
8720 while Present (Citem) loop
8721 if Nkind (Citem) = N_Component_Declaration then
8722 C2_Ent := Defining_Identifier (Citem);
8723 exit when C1_Ent = C2_Ent;
8724 Check_Component_Overlap (C1_Ent, C2_Ent);
8725 end if;
8727 Next (Citem);
8728 end loop;
8729 end if;
8731 -- Check for variants above us (the parent of the Clist can
8732 -- be a variant, in which case its parent is a variant part,
8733 -- and the parent of the variant part is a component list
8734 -- whose components must all be checked against the current
8735 -- component for overlap).
8737 if Nkind (Parent (Clist)) = N_Variant then
8738 Clist := Parent (Parent (Parent (Clist)));
8740 -- Check for possible discriminant part in record, this
8741 -- is treated essentially as another level in the
8742 -- recursion. For this case the parent of the component
8743 -- list is the record definition, and its parent is the
8744 -- full type declaration containing the discriminant
8745 -- specifications.
8747 elsif Nkind (Parent (Clist)) = N_Record_Definition then
8748 Clist := Parent (Parent ((Clist)));
8750 -- If neither of these two cases, we are at the top of
8751 -- the tree.
8753 else
8754 exit Component_List_Loop;
8755 end if;
8756 end loop Component_List_Loop;
8758 <<Continue_Main_Component_Loop>>
8759 Next_Entity (C1_Ent);
8761 end loop Main_Component_Loop;
8762 end Overlap_Check2;
8763 end if;
8765 -- The following circuit deals with warning on record holes (gaps). We
8766 -- skip this check if overlap was detected, since it makes sense for the
8767 -- programmer to fix this illegality before worrying about warnings.
8769 if not Overlap_Detected and Warn_On_Record_Holes then
8770 Record_Hole_Check : declare
8771 Decl : constant Node_Id := Declaration_Node (Base_Type (Rectype));
8772 -- Full declaration of record type
8774 procedure Check_Component_List
8775 (CL : Node_Id;
8776 Sbit : Uint;
8777 DS : List_Id);
8778 -- Check component list CL for holes. The starting bit should be
8779 -- Sbit. which is zero for the main record component list and set
8780 -- appropriately for recursive calls for variants. DS is set to
8781 -- a list of discriminant specifications to be included in the
8782 -- consideration of components. It is No_List if none to consider.
8784 --------------------------
8785 -- Check_Component_List --
8786 --------------------------
8788 procedure Check_Component_List
8789 (CL : Node_Id;
8790 Sbit : Uint;
8791 DS : List_Id)
8793 Compl : Integer;
8795 begin
8796 Compl := Integer (List_Length (Component_Items (CL)));
8798 if DS /= No_List then
8799 Compl := Compl + Integer (List_Length (DS));
8800 end if;
8802 declare
8803 Comps : array (Natural range 0 .. Compl) of Entity_Id;
8804 -- Gather components (zero entry is for sort routine)
8806 Ncomps : Natural := 0;
8807 -- Number of entries stored in Comps (starting at Comps (1))
8809 Citem : Node_Id;
8810 -- One component item or discriminant specification
8812 Nbit : Uint;
8813 -- Starting bit for next component
8815 CEnt : Entity_Id;
8816 -- Component entity
8818 Variant : Node_Id;
8819 -- One variant
8821 function Lt (Op1, Op2 : Natural) return Boolean;
8822 -- Compare routine for Sort
8824 procedure Move (From : Natural; To : Natural);
8825 -- Move routine for Sort
8827 package Sorting is new GNAT.Heap_Sort_G (Move, Lt);
8829 --------
8830 -- Lt --
8831 --------
8833 function Lt (Op1, Op2 : Natural) return Boolean is
8834 begin
8835 return Component_Bit_Offset (Comps (Op1))
8837 Component_Bit_Offset (Comps (Op2));
8838 end Lt;
8840 ----------
8841 -- Move --
8842 ----------
8844 procedure Move (From : Natural; To : Natural) is
8845 begin
8846 Comps (To) := Comps (From);
8847 end Move;
8849 begin
8850 -- Gather discriminants into Comp
8852 if DS /= No_List then
8853 Citem := First (DS);
8854 while Present (Citem) loop
8855 if Nkind (Citem) = N_Discriminant_Specification then
8856 declare
8857 Ent : constant Entity_Id :=
8858 Defining_Identifier (Citem);
8859 begin
8860 if Ekind (Ent) = E_Discriminant then
8861 Ncomps := Ncomps + 1;
8862 Comps (Ncomps) := Ent;
8863 end if;
8864 end;
8865 end if;
8867 Next (Citem);
8868 end loop;
8869 end if;
8871 -- Gather component entities into Comp
8873 Citem := First (Component_Items (CL));
8874 while Present (Citem) loop
8875 if Nkind (Citem) = N_Component_Declaration then
8876 Ncomps := Ncomps + 1;
8877 Comps (Ncomps) := Defining_Identifier (Citem);
8878 end if;
8880 Next (Citem);
8881 end loop;
8883 -- Now sort the component entities based on the first bit.
8884 -- Note we already know there are no overlapping components.
8886 Sorting.Sort (Ncomps);
8888 -- Loop through entries checking for holes
8890 Nbit := Sbit;
8891 for J in 1 .. Ncomps loop
8892 CEnt := Comps (J);
8893 Error_Msg_Uint_1 := Component_Bit_Offset (CEnt) - Nbit;
8895 if Error_Msg_Uint_1 > 0 then
8896 Error_Msg_NE
8897 ("?H?^-bit gap before component&",
8898 Component_Name (Component_Clause (CEnt)), CEnt);
8899 end if;
8901 Nbit := Component_Bit_Offset (CEnt) + Esize (CEnt);
8902 end loop;
8904 -- Process variant parts recursively if present
8906 if Present (Variant_Part (CL)) then
8907 Variant := First (Variants (Variant_Part (CL)));
8908 while Present (Variant) loop
8909 Check_Component_List
8910 (Component_List (Variant), Nbit, No_List);
8911 Next (Variant);
8912 end loop;
8913 end if;
8914 end;
8915 end Check_Component_List;
8917 -- Start of processing for Record_Hole_Check
8919 begin
8920 declare
8921 Sbit : Uint;
8923 begin
8924 if Is_Tagged_Type (Rectype) then
8925 Sbit := UI_From_Int (System_Address_Size);
8926 else
8927 Sbit := Uint_0;
8928 end if;
8930 if Nkind (Decl) = N_Full_Type_Declaration
8931 and then Nkind (Type_Definition (Decl)) = N_Record_Definition
8932 then
8933 Check_Component_List
8934 (Component_List (Type_Definition (Decl)),
8935 Sbit,
8936 Discriminant_Specifications (Decl));
8937 end if;
8938 end;
8939 end Record_Hole_Check;
8940 end if;
8942 -- For records that have component clauses for all components, and whose
8943 -- size is less than or equal to 32, we need to know the size in the
8944 -- front end to activate possible packed array processing where the
8945 -- component type is a record.
8947 -- At this stage Hbit + 1 represents the first unused bit from all the
8948 -- component clauses processed, so if the component clauses are
8949 -- complete, then this is the length of the record.
8951 -- For records longer than System.Storage_Unit, and for those where not
8952 -- all components have component clauses, the back end determines the
8953 -- length (it may for example be appropriate to round up the size
8954 -- to some convenient boundary, based on alignment considerations, etc).
8956 if Unknown_RM_Size (Rectype) and then Hbit + 1 <= 32 then
8958 -- Nothing to do if at least one component has no component clause
8960 Comp := First_Component_Or_Discriminant (Rectype);
8961 while Present (Comp) loop
8962 exit when No (Component_Clause (Comp));
8963 Next_Component_Or_Discriminant (Comp);
8964 end loop;
8966 -- If we fall out of loop, all components have component clauses
8967 -- and so we can set the size to the maximum value.
8969 if No (Comp) then
8970 Set_RM_Size (Rectype, Hbit + 1);
8971 end if;
8972 end if;
8973 end Check_Record_Representation_Clause;
8975 ----------------
8976 -- Check_Size --
8977 ----------------
8979 procedure Check_Size
8980 (N : Node_Id;
8981 T : Entity_Id;
8982 Siz : Uint;
8983 Biased : out Boolean)
8985 UT : constant Entity_Id := Underlying_Type (T);
8986 M : Uint;
8988 begin
8989 Biased := False;
8991 -- Reject patently improper size values.
8993 if Is_Elementary_Type (T)
8994 and then Siz > UI_From_Int (Int'Last)
8995 then
8996 Error_Msg_N ("Size value too large for elementary type", N);
8998 if Nkind (Original_Node (N)) = N_Op_Expon then
8999 Error_Msg_N
9000 ("\maybe '* was meant, rather than '*'*", Original_Node (N));
9001 end if;
9002 end if;
9004 -- Dismiss generic types
9006 if Is_Generic_Type (T)
9007 or else
9008 Is_Generic_Type (UT)
9009 or else
9010 Is_Generic_Type (Root_Type (UT))
9011 then
9012 return;
9014 -- Guard against previous errors
9016 elsif No (UT) or else UT = Any_Type then
9017 Check_Error_Detected;
9018 return;
9020 -- Check case of bit packed array
9022 elsif Is_Array_Type (UT)
9023 and then Known_Static_Component_Size (UT)
9024 and then Is_Bit_Packed_Array (UT)
9025 then
9026 declare
9027 Asiz : Uint;
9028 Indx : Node_Id;
9029 Ityp : Entity_Id;
9031 begin
9032 Asiz := Component_Size (UT);
9033 Indx := First_Index (UT);
9034 loop
9035 Ityp := Etype (Indx);
9037 -- If non-static bound, then we are not in the business of
9038 -- trying to check the length, and indeed an error will be
9039 -- issued elsewhere, since sizes of non-static array types
9040 -- cannot be set implicitly or explicitly.
9042 if not Is_Static_Subtype (Ityp) then
9043 return;
9044 end if;
9046 -- Otherwise accumulate next dimension
9048 Asiz := Asiz * (Expr_Value (Type_High_Bound (Ityp)) -
9049 Expr_Value (Type_Low_Bound (Ityp)) +
9050 Uint_1);
9052 Next_Index (Indx);
9053 exit when No (Indx);
9054 end loop;
9056 if Asiz <= Siz then
9057 return;
9059 else
9060 Error_Msg_Uint_1 := Asiz;
9061 Error_Msg_NE
9062 ("size for& too small, minimum allowed is ^", N, T);
9063 Set_Esize (T, Asiz);
9064 Set_RM_Size (T, Asiz);
9065 end if;
9066 end;
9068 -- All other composite types are ignored
9070 elsif Is_Composite_Type (UT) then
9071 return;
9073 -- For fixed-point types, don't check minimum if type is not frozen,
9074 -- since we don't know all the characteristics of the type that can
9075 -- affect the size (e.g. a specified small) till freeze time.
9077 elsif Is_Fixed_Point_Type (UT)
9078 and then not Is_Frozen (UT)
9079 then
9080 null;
9082 -- Cases for which a minimum check is required
9084 else
9085 -- Ignore if specified size is correct for the type
9087 if Known_Esize (UT) and then Siz = Esize (UT) then
9088 return;
9089 end if;
9091 -- Otherwise get minimum size
9093 M := UI_From_Int (Minimum_Size (UT));
9095 if Siz < M then
9097 -- Size is less than minimum size, but one possibility remains
9098 -- that we can manage with the new size if we bias the type.
9100 M := UI_From_Int (Minimum_Size (UT, Biased => True));
9102 if Siz < M then
9103 Error_Msg_Uint_1 := M;
9104 Error_Msg_NE
9105 ("size for& too small, minimum allowed is ^", N, T);
9106 Set_Esize (T, M);
9107 Set_RM_Size (T, M);
9108 else
9109 Biased := True;
9110 end if;
9111 end if;
9112 end if;
9113 end Check_Size;
9115 --------------------------
9116 -- Freeze_Entity_Checks --
9117 --------------------------
9119 procedure Freeze_Entity_Checks (N : Node_Id) is
9120 E : constant Entity_Id := Entity (N);
9122 Non_Generic_Case : constant Boolean := Nkind (N) = N_Freeze_Entity;
9123 -- True in non-generic case. Some of the processing here is skipped
9124 -- for the generic case since it is not needed. Basically in the
9125 -- generic case, we only need to do stuff that might generate error
9126 -- messages or warnings.
9127 begin
9128 -- Remember that we are processing a freezing entity. Required to
9129 -- ensure correct decoration of internal entities associated with
9130 -- interfaces (see New_Overloaded_Entity).
9132 Inside_Freezing_Actions := Inside_Freezing_Actions + 1;
9134 -- For tagged types covering interfaces add internal entities that link
9135 -- the primitives of the interfaces with the primitives that cover them.
9136 -- Note: These entities were originally generated only when generating
9137 -- code because their main purpose was to provide support to initialize
9138 -- the secondary dispatch tables. They are now generated also when
9139 -- compiling with no code generation to provide ASIS the relationship
9140 -- between interface primitives and tagged type primitives. They are
9141 -- also used to locate primitives covering interfaces when processing
9142 -- generics (see Derive_Subprograms).
9144 -- This is not needed in the generic case
9146 if Ada_Version >= Ada_2005
9147 and then Non_Generic_Case
9148 and then Ekind (E) = E_Record_Type
9149 and then Is_Tagged_Type (E)
9150 and then not Is_Interface (E)
9151 and then Has_Interfaces (E)
9152 then
9153 -- This would be a good common place to call the routine that checks
9154 -- overriding of interface primitives (and thus factorize calls to
9155 -- Check_Abstract_Overriding located at different contexts in the
9156 -- compiler). However, this is not possible because it causes
9157 -- spurious errors in case of late overriding.
9159 Add_Internal_Interface_Entities (E);
9160 end if;
9162 -- Check CPP types
9164 if Ekind (E) = E_Record_Type
9165 and then Is_CPP_Class (E)
9166 and then Is_Tagged_Type (E)
9167 and then Tagged_Type_Expansion
9168 then
9169 if CPP_Num_Prims (E) = 0 then
9171 -- If the CPP type has user defined components then it must import
9172 -- primitives from C++. This is required because if the C++ class
9173 -- has no primitives then the C++ compiler does not added the _tag
9174 -- component to the type.
9176 if First_Entity (E) /= Last_Entity (E) then
9177 Error_Msg_N
9178 ("'C'P'P type must import at least one primitive from C++??",
9180 end if;
9181 end if;
9183 -- Check that all its primitives are abstract or imported from C++.
9184 -- Check also availability of the C++ constructor.
9186 declare
9187 Has_Constructors : constant Boolean := Has_CPP_Constructors (E);
9188 Elmt : Elmt_Id;
9189 Error_Reported : Boolean := False;
9190 Prim : Node_Id;
9192 begin
9193 Elmt := First_Elmt (Primitive_Operations (E));
9194 while Present (Elmt) loop
9195 Prim := Node (Elmt);
9197 if Comes_From_Source (Prim) then
9198 if Is_Abstract_Subprogram (Prim) then
9199 null;
9201 elsif not Is_Imported (Prim)
9202 or else Convention (Prim) /= Convention_CPP
9203 then
9204 Error_Msg_N
9205 ("primitives of 'C'P'P types must be imported from C++ "
9206 & "or abstract??", Prim);
9208 elsif not Has_Constructors
9209 and then not Error_Reported
9210 then
9211 Error_Msg_Name_1 := Chars (E);
9212 Error_Msg_N
9213 ("??'C'P'P constructor required for type %", Prim);
9214 Error_Reported := True;
9215 end if;
9216 end if;
9218 Next_Elmt (Elmt);
9219 end loop;
9220 end;
9221 end if;
9223 -- Check Ada derivation of CPP type
9225 if Expander_Active -- why? losing errors in -gnatc mode???
9226 and then Tagged_Type_Expansion
9227 and then Ekind (E) = E_Record_Type
9228 and then Etype (E) /= E
9229 and then Is_CPP_Class (Etype (E))
9230 and then CPP_Num_Prims (Etype (E)) > 0
9231 and then not Is_CPP_Class (E)
9232 and then not Has_CPP_Constructors (Etype (E))
9233 then
9234 -- If the parent has C++ primitives but it has no constructor then
9235 -- check that all the primitives are overridden in this derivation;
9236 -- otherwise the constructor of the parent is needed to build the
9237 -- dispatch table.
9239 declare
9240 Elmt : Elmt_Id;
9241 Prim : Node_Id;
9243 begin
9244 Elmt := First_Elmt (Primitive_Operations (E));
9245 while Present (Elmt) loop
9246 Prim := Node (Elmt);
9248 if not Is_Abstract_Subprogram (Prim)
9249 and then No (Interface_Alias (Prim))
9250 and then Find_Dispatching_Type (Ultimate_Alias (Prim)) /= E
9251 then
9252 Error_Msg_Name_1 := Chars (Etype (E));
9253 Error_Msg_N
9254 ("'C'P'P constructor required for parent type %", E);
9255 exit;
9256 end if;
9258 Next_Elmt (Elmt);
9259 end loop;
9260 end;
9261 end if;
9263 Inside_Freezing_Actions := Inside_Freezing_Actions - 1;
9265 -- If we have a type with predicates, build predicate function. This
9266 -- is not needed in the generic casee
9268 if Non_Generic_Case and then Is_Type (E) and then Has_Predicates (E) then
9269 Build_Predicate_Functions (E, N);
9270 end if;
9272 -- If type has delayed aspects, this is where we do the preanalysis at
9273 -- the freeze point, as part of the consistent visibility check. Note
9274 -- that this must be done after calling Build_Predicate_Functions or
9275 -- Build_Invariant_Procedure since these subprograms fix occurrences of
9276 -- the subtype name in the saved expression so that they will not cause
9277 -- trouble in the preanalysis.
9279 -- This is also not needed in the generic case
9281 if Non_Generic_Case
9282 and then Has_Delayed_Aspects (E)
9283 and then Scope (E) = Current_Scope
9284 then
9285 -- Retrieve the visibility to the discriminants in order to properly
9286 -- analyze the aspects.
9288 Push_Scope_And_Install_Discriminants (E);
9290 declare
9291 Ritem : Node_Id;
9293 begin
9294 -- Look for aspect specification entries for this entity
9296 Ritem := First_Rep_Item (E);
9297 while Present (Ritem) loop
9298 if Nkind (Ritem) = N_Aspect_Specification
9299 and then Entity (Ritem) = E
9300 and then Is_Delayed_Aspect (Ritem)
9301 then
9302 Check_Aspect_At_Freeze_Point (Ritem);
9303 end if;
9305 Next_Rep_Item (Ritem);
9306 end loop;
9307 end;
9309 Uninstall_Discriminants_And_Pop_Scope (E);
9310 end if;
9312 -- For a record type, deal with variant parts. This has to be delayed
9313 -- to this point, because of the issue of statically precicated
9314 -- subtypes, which we have to ensure are frozen before checking
9315 -- choices, since we need to have the static choice list set.
9317 if Is_Record_Type (E) then
9318 Check_Variant_Part : declare
9319 D : constant Node_Id := Declaration_Node (E);
9320 T : Node_Id;
9321 C : Node_Id;
9322 VP : Node_Id;
9324 Others_Present : Boolean;
9325 pragma Warnings (Off, Others_Present);
9326 -- Indicates others present, not used in this case
9328 procedure Non_Static_Choice_Error (Choice : Node_Id);
9329 -- Error routine invoked by the generic instantiation below when
9330 -- the variant part has a non static choice.
9332 procedure Process_Declarations (Variant : Node_Id);
9333 -- Processes declarations associated with a variant. We analyzed
9334 -- the declarations earlier (in Sem_Ch3.Analyze_Variant_Part),
9335 -- but we still need the recursive call to Check_Choices for any
9336 -- nested variant to get its choices properly processed. This is
9337 -- also where we expand out the choices if expansion is active.
9339 package Variant_Choices_Processing is new
9340 Generic_Check_Choices
9341 (Process_Empty_Choice => No_OP,
9342 Process_Non_Static_Choice => Non_Static_Choice_Error,
9343 Process_Associated_Node => Process_Declarations);
9344 use Variant_Choices_Processing;
9346 -----------------------------
9347 -- Non_Static_Choice_Error --
9348 -----------------------------
9350 procedure Non_Static_Choice_Error (Choice : Node_Id) is
9351 begin
9352 Flag_Non_Static_Expr
9353 ("choice given in variant part is not static!", Choice);
9354 end Non_Static_Choice_Error;
9356 --------------------------
9357 -- Process_Declarations --
9358 --------------------------
9360 procedure Process_Declarations (Variant : Node_Id) is
9361 CL : constant Node_Id := Component_List (Variant);
9362 VP : Node_Id;
9364 begin
9365 -- Check for static predicate present in this variant
9367 if Has_SP_Choice (Variant) then
9369 -- Here we expand. You might expect to find this call in
9370 -- Expand_N_Variant_Part, but that is called when we first
9371 -- see the variant part, and we cannot do this expansion
9372 -- earlier than the freeze point, since for statically
9373 -- predicated subtypes, the predicate is not known till
9374 -- the freeze point.
9376 -- Furthermore, we do this expansion even if the expander
9377 -- is not active, because other semantic processing, e.g.
9378 -- for aggregates, requires the expanded list of choices.
9380 -- If the expander is not active, then we can't just clobber
9381 -- the list since it would invalidate the ASIS -gnatct tree.
9382 -- So we have to rewrite the variant part with a Rewrite
9383 -- call that replaces it with a copy and clobber the copy.
9385 if not Expander_Active then
9386 declare
9387 NewV : constant Node_Id := New_Copy (Variant);
9388 begin
9389 Set_Discrete_Choices
9390 (NewV, New_Copy_List (Discrete_Choices (Variant)));
9391 Rewrite (Variant, NewV);
9392 end;
9393 end if;
9395 Expand_Static_Predicates_In_Choices (Variant);
9396 end if;
9398 -- We don't need to worry about the declarations in the variant
9399 -- (since they were analyzed by Analyze_Choices when we first
9400 -- encountered the variant), but we do need to take care of
9401 -- expansion of any nested variants.
9403 if not Null_Present (CL) then
9404 VP := Variant_Part (CL);
9406 if Present (VP) then
9407 Check_Choices
9408 (VP, Variants (VP), Etype (Name (VP)), Others_Present);
9409 end if;
9410 end if;
9411 end Process_Declarations;
9413 -- Start of processing for Check_Variant_Part
9415 begin
9416 -- Find component list
9418 C := Empty;
9420 if Nkind (D) = N_Full_Type_Declaration then
9421 T := Type_Definition (D);
9423 if Nkind (T) = N_Record_Definition then
9424 C := Component_List (T);
9426 elsif Nkind (T) = N_Derived_Type_Definition
9427 and then Present (Record_Extension_Part (T))
9428 then
9429 C := Component_List (Record_Extension_Part (T));
9430 end if;
9431 end if;
9433 -- Case of variant part present
9435 if Present (C) and then Present (Variant_Part (C)) then
9436 VP := Variant_Part (C);
9438 -- Check choices
9440 Check_Choices
9441 (VP, Variants (VP), Etype (Name (VP)), Others_Present);
9443 -- If the last variant does not contain the Others choice,
9444 -- replace it with an N_Others_Choice node since Gigi always
9445 -- wants an Others. Note that we do not bother to call Analyze
9446 -- on the modified variant part, since its only effect would be
9447 -- to compute the Others_Discrete_Choices node laboriously, and
9448 -- of course we already know the list of choices corresponding
9449 -- to the others choice (it's the list we're replacing!)
9451 -- We only want to do this if the expander is active, since
9452 -- we do not want to clobber the ASIS tree!
9454 if Expander_Active then
9455 declare
9456 Last_Var : constant Node_Id :=
9457 Last_Non_Pragma (Variants (VP));
9459 Others_Node : Node_Id;
9461 begin
9462 if Nkind (First (Discrete_Choices (Last_Var))) /=
9463 N_Others_Choice
9464 then
9465 Others_Node := Make_Others_Choice (Sloc (Last_Var));
9466 Set_Others_Discrete_Choices
9467 (Others_Node, Discrete_Choices (Last_Var));
9468 Set_Discrete_Choices
9469 (Last_Var, New_List (Others_Node));
9470 end if;
9471 end;
9472 end if;
9473 end if;
9474 end Check_Variant_Part;
9475 end if;
9476 end Freeze_Entity_Checks;
9478 -------------------------
9479 -- Get_Alignment_Value --
9480 -------------------------
9482 function Get_Alignment_Value (Expr : Node_Id) return Uint is
9483 Align : constant Uint := Static_Integer (Expr);
9485 begin
9486 if Align = No_Uint then
9487 return No_Uint;
9489 elsif Align <= 0 then
9490 Error_Msg_N ("alignment value must be positive", Expr);
9491 return No_Uint;
9493 else
9494 for J in Int range 0 .. 64 loop
9495 declare
9496 M : constant Uint := Uint_2 ** J;
9498 begin
9499 exit when M = Align;
9501 if M > Align then
9502 Error_Msg_N
9503 ("alignment value must be power of 2", Expr);
9504 return No_Uint;
9505 end if;
9506 end;
9507 end loop;
9509 return Align;
9510 end if;
9511 end Get_Alignment_Value;
9513 -------------------------------------
9514 -- Inherit_Aspects_At_Freeze_Point --
9515 -------------------------------------
9517 procedure Inherit_Aspects_At_Freeze_Point (Typ : Entity_Id) is
9519 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9520 (Rep_Item : Node_Id) return Boolean;
9521 -- This routine checks if Rep_Item is either a pragma or an aspect
9522 -- specification node whose correponding pragma (if any) is present in
9523 -- the Rep Item chain of the entity it has been specified to.
9525 --------------------------------------------------
9526 -- Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item --
9527 --------------------------------------------------
9529 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9530 (Rep_Item : Node_Id) return Boolean
9532 begin
9533 return Nkind (Rep_Item) = N_Pragma
9534 or else Present_In_Rep_Item
9535 (Entity (Rep_Item), Aspect_Rep_Item (Rep_Item));
9536 end Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item;
9538 -- Start of processing for Inherit_Aspects_At_Freeze_Point
9540 begin
9541 -- A representation item is either subtype-specific (Size and Alignment
9542 -- clauses) or type-related (all others). Subtype-specific aspects may
9543 -- differ for different subtypes of the same type (RM 13.1.8).
9545 -- A derived type inherits each type-related representation aspect of
9546 -- its parent type that was directly specified before the declaration of
9547 -- the derived type (RM 13.1.15).
9549 -- A derived subtype inherits each subtype-specific representation
9550 -- aspect of its parent subtype that was directly specified before the
9551 -- declaration of the derived type (RM 13.1.15).
9553 -- The general processing involves inheriting a representation aspect
9554 -- from a parent type whenever the first rep item (aspect specification,
9555 -- attribute definition clause, pragma) corresponding to the given
9556 -- representation aspect in the rep item chain of Typ, if any, isn't
9557 -- directly specified to Typ but to one of its parents.
9559 -- ??? Note that, for now, just a limited number of representation
9560 -- aspects have been inherited here so far. Many of them are
9561 -- still inherited in Sem_Ch3. This will be fixed soon. Here is
9562 -- a non- exhaustive list of aspects that likely also need to
9563 -- be moved to this routine: Alignment, Component_Alignment,
9564 -- Component_Size, Machine_Radix, Object_Size, Pack, Predicates,
9565 -- Preelaborable_Initialization, RM_Size and Small.
9567 if Nkind (Parent (Typ)) = N_Private_Extension_Declaration then
9568 return;
9569 end if;
9571 -- Ada_05/Ada_2005
9573 if not Has_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005, False)
9574 and then Has_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005)
9575 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9576 (Get_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005))
9577 then
9578 Set_Is_Ada_2005_Only (Typ);
9579 end if;
9581 -- Ada_12/Ada_2012
9583 if not Has_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012, False)
9584 and then Has_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012)
9585 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9586 (Get_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012))
9587 then
9588 Set_Is_Ada_2012_Only (Typ);
9589 end if;
9591 -- Atomic/Shared
9593 if not Has_Rep_Item (Typ, Name_Atomic, Name_Shared, False)
9594 and then Has_Rep_Pragma (Typ, Name_Atomic, Name_Shared)
9595 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9596 (Get_Rep_Item (Typ, Name_Atomic, Name_Shared))
9597 then
9598 Set_Is_Atomic (Typ);
9599 Set_Treat_As_Volatile (Typ);
9600 Set_Is_Volatile (Typ);
9601 end if;
9603 -- Default_Component_Value
9605 if Is_Array_Type (Typ)
9606 and then Is_Base_Type (Typ)
9607 and then Has_Rep_Item (Typ, Name_Default_Component_Value, False)
9608 and then Has_Rep_Item (Typ, Name_Default_Component_Value)
9609 then
9610 Set_Default_Aspect_Component_Value (Typ,
9611 Default_Aspect_Component_Value
9612 (Entity (Get_Rep_Item (Typ, Name_Default_Component_Value))));
9613 end if;
9615 -- Default_Value
9617 if Is_Scalar_Type (Typ)
9618 and then Is_Base_Type (Typ)
9619 and then Has_Rep_Item (Typ, Name_Default_Value, False)
9620 and then Has_Rep_Item (Typ, Name_Default_Value)
9621 then
9622 Set_Default_Aspect_Value (Typ,
9623 Default_Aspect_Value
9624 (Entity (Get_Rep_Item (Typ, Name_Default_Value))));
9625 end if;
9627 -- Discard_Names
9629 if not Has_Rep_Item (Typ, Name_Discard_Names, False)
9630 and then Has_Rep_Item (Typ, Name_Discard_Names)
9631 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9632 (Get_Rep_Item (Typ, Name_Discard_Names))
9633 then
9634 Set_Discard_Names (Typ);
9635 end if;
9637 -- Invariants
9639 if not Has_Rep_Item (Typ, Name_Invariant, False)
9640 and then Has_Rep_Item (Typ, Name_Invariant)
9641 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9642 (Get_Rep_Item (Typ, Name_Invariant))
9643 then
9644 Set_Has_Invariants (Typ);
9646 if Class_Present (Get_Rep_Item (Typ, Name_Invariant)) then
9647 Set_Has_Inheritable_Invariants (Typ);
9648 end if;
9649 end if;
9651 -- Volatile
9653 if not Has_Rep_Item (Typ, Name_Volatile, False)
9654 and then Has_Rep_Item (Typ, Name_Volatile)
9655 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9656 (Get_Rep_Item (Typ, Name_Volatile))
9657 then
9658 Set_Treat_As_Volatile (Typ);
9659 Set_Is_Volatile (Typ);
9660 end if;
9662 -- Inheritance for derived types only
9664 if Is_Derived_Type (Typ) then
9665 declare
9666 Bas_Typ : constant Entity_Id := Base_Type (Typ);
9667 Imp_Bas_Typ : constant Entity_Id := Implementation_Base_Type (Typ);
9669 begin
9670 -- Atomic_Components
9672 if not Has_Rep_Item (Typ, Name_Atomic_Components, False)
9673 and then Has_Rep_Item (Typ, Name_Atomic_Components)
9674 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9675 (Get_Rep_Item (Typ, Name_Atomic_Components))
9676 then
9677 Set_Has_Atomic_Components (Imp_Bas_Typ);
9678 end if;
9680 -- Volatile_Components
9682 if not Has_Rep_Item (Typ, Name_Volatile_Components, False)
9683 and then Has_Rep_Item (Typ, Name_Volatile_Components)
9684 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9685 (Get_Rep_Item (Typ, Name_Volatile_Components))
9686 then
9687 Set_Has_Volatile_Components (Imp_Bas_Typ);
9688 end if;
9690 -- Finalize_Storage_Only.
9692 if not Has_Rep_Pragma (Typ, Name_Finalize_Storage_Only, False)
9693 and then Has_Rep_Pragma (Typ, Name_Finalize_Storage_Only)
9694 then
9695 Set_Finalize_Storage_Only (Bas_Typ);
9696 end if;
9698 -- Universal_Aliasing
9700 if not Has_Rep_Item (Typ, Name_Universal_Aliasing, False)
9701 and then Has_Rep_Item (Typ, Name_Universal_Aliasing)
9702 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9703 (Get_Rep_Item (Typ, Name_Universal_Aliasing))
9704 then
9705 Set_Universal_Aliasing (Imp_Bas_Typ);
9706 end if;
9708 -- Record type specific aspects
9710 if Is_Record_Type (Typ) then
9712 -- Bit_Order
9714 if not Has_Rep_Item (Typ, Name_Bit_Order, False)
9715 and then Has_Rep_Item (Typ, Name_Bit_Order)
9716 then
9717 Set_Reverse_Bit_Order (Bas_Typ,
9718 Reverse_Bit_Order (Entity (Name
9719 (Get_Rep_Item (Typ, Name_Bit_Order)))));
9720 end if;
9722 -- Scalar_Storage_Order
9724 if not Has_Rep_Item (Typ, Name_Scalar_Storage_Order, False)
9725 and then Has_Rep_Item (Typ, Name_Scalar_Storage_Order)
9726 then
9727 Set_Reverse_Storage_Order (Bas_Typ,
9728 Reverse_Storage_Order (Entity (Name
9729 (Get_Rep_Item (Typ, Name_Scalar_Storage_Order)))));
9730 end if;
9731 end if;
9732 end;
9733 end if;
9734 end Inherit_Aspects_At_Freeze_Point;
9736 ----------------
9737 -- Initialize --
9738 ----------------
9740 procedure Initialize is
9741 begin
9742 Address_Clause_Checks.Init;
9743 Independence_Checks.Init;
9744 Unchecked_Conversions.Init;
9745 end Initialize;
9747 -------------------------
9748 -- Is_Operational_Item --
9749 -------------------------
9751 function Is_Operational_Item (N : Node_Id) return Boolean is
9752 begin
9753 if Nkind (N) /= N_Attribute_Definition_Clause then
9754 return False;
9756 else
9757 declare
9758 Id : constant Attribute_Id := Get_Attribute_Id (Chars (N));
9759 begin
9760 return Id = Attribute_Input
9761 or else Id = Attribute_Output
9762 or else Id = Attribute_Read
9763 or else Id = Attribute_Write
9764 or else Id = Attribute_External_Tag;
9765 end;
9766 end if;
9767 end Is_Operational_Item;
9769 ------------------
9770 -- Minimum_Size --
9771 ------------------
9773 function Minimum_Size
9774 (T : Entity_Id;
9775 Biased : Boolean := False) return Nat
9777 Lo : Uint := No_Uint;
9778 Hi : Uint := No_Uint;
9779 LoR : Ureal := No_Ureal;
9780 HiR : Ureal := No_Ureal;
9781 LoSet : Boolean := False;
9782 HiSet : Boolean := False;
9783 B : Uint;
9784 S : Nat;
9785 Ancest : Entity_Id;
9786 R_Typ : constant Entity_Id := Root_Type (T);
9788 begin
9789 -- If bad type, return 0
9791 if T = Any_Type then
9792 return 0;
9794 -- For generic types, just return zero. There cannot be any legitimate
9795 -- need to know such a size, but this routine may be called with a
9796 -- generic type as part of normal processing.
9798 elsif Is_Generic_Type (R_Typ)
9799 or else R_Typ = Any_Type
9800 then
9801 return 0;
9803 -- Access types. Normally an access type cannot have a size smaller
9804 -- than the size of System.Address. The exception is on VMS, where
9805 -- we have short and long addresses, and it is possible for an access
9806 -- type to have a short address size (and thus be less than the size
9807 -- of System.Address itself). We simply skip the check for VMS, and
9808 -- leave it to the back end to do the check.
9810 elsif Is_Access_Type (T) then
9811 if OpenVMS_On_Target then
9812 return 0;
9813 else
9814 return System_Address_Size;
9815 end if;
9817 -- Floating-point types
9819 elsif Is_Floating_Point_Type (T) then
9820 return UI_To_Int (Esize (R_Typ));
9822 -- Discrete types
9824 elsif Is_Discrete_Type (T) then
9826 -- The following loop is looking for the nearest compile time known
9827 -- bounds following the ancestor subtype chain. The idea is to find
9828 -- the most restrictive known bounds information.
9830 Ancest := T;
9831 loop
9832 if Ancest = Any_Type or else Etype (Ancest) = Any_Type then
9833 return 0;
9834 end if;
9836 if not LoSet then
9837 if Compile_Time_Known_Value (Type_Low_Bound (Ancest)) then
9838 Lo := Expr_Rep_Value (Type_Low_Bound (Ancest));
9839 LoSet := True;
9840 exit when HiSet;
9841 end if;
9842 end if;
9844 if not HiSet then
9845 if Compile_Time_Known_Value (Type_High_Bound (Ancest)) then
9846 Hi := Expr_Rep_Value (Type_High_Bound (Ancest));
9847 HiSet := True;
9848 exit when LoSet;
9849 end if;
9850 end if;
9852 Ancest := Ancestor_Subtype (Ancest);
9854 if No (Ancest) then
9855 Ancest := Base_Type (T);
9857 if Is_Generic_Type (Ancest) then
9858 return 0;
9859 end if;
9860 end if;
9861 end loop;
9863 -- Fixed-point types. We can't simply use Expr_Value to get the
9864 -- Corresponding_Integer_Value values of the bounds, since these do not
9865 -- get set till the type is frozen, and this routine can be called
9866 -- before the type is frozen. Similarly the test for bounds being static
9867 -- needs to include the case where we have unanalyzed real literals for
9868 -- the same reason.
9870 elsif Is_Fixed_Point_Type (T) then
9872 -- The following loop is looking for the nearest compile time known
9873 -- bounds following the ancestor subtype chain. The idea is to find
9874 -- the most restrictive known bounds information.
9876 Ancest := T;
9877 loop
9878 if Ancest = Any_Type or else Etype (Ancest) = Any_Type then
9879 return 0;
9880 end if;
9882 -- Note: In the following two tests for LoSet and HiSet, it may
9883 -- seem redundant to test for N_Real_Literal here since normally
9884 -- one would assume that the test for the value being known at
9885 -- compile time includes this case. However, there is a glitch.
9886 -- If the real literal comes from folding a non-static expression,
9887 -- then we don't consider any non- static expression to be known
9888 -- at compile time if we are in configurable run time mode (needed
9889 -- in some cases to give a clearer definition of what is and what
9890 -- is not accepted). So the test is indeed needed. Without it, we
9891 -- would set neither Lo_Set nor Hi_Set and get an infinite loop.
9893 if not LoSet then
9894 if Nkind (Type_Low_Bound (Ancest)) = N_Real_Literal
9895 or else Compile_Time_Known_Value (Type_Low_Bound (Ancest))
9896 then
9897 LoR := Expr_Value_R (Type_Low_Bound (Ancest));
9898 LoSet := True;
9899 exit when HiSet;
9900 end if;
9901 end if;
9903 if not HiSet then
9904 if Nkind (Type_High_Bound (Ancest)) = N_Real_Literal
9905 or else Compile_Time_Known_Value (Type_High_Bound (Ancest))
9906 then
9907 HiR := Expr_Value_R (Type_High_Bound (Ancest));
9908 HiSet := True;
9909 exit when LoSet;
9910 end if;
9911 end if;
9913 Ancest := Ancestor_Subtype (Ancest);
9915 if No (Ancest) then
9916 Ancest := Base_Type (T);
9918 if Is_Generic_Type (Ancest) then
9919 return 0;
9920 end if;
9921 end if;
9922 end loop;
9924 Lo := UR_To_Uint (LoR / Small_Value (T));
9925 Hi := UR_To_Uint (HiR / Small_Value (T));
9927 -- No other types allowed
9929 else
9930 raise Program_Error;
9931 end if;
9933 -- Fall through with Hi and Lo set. Deal with biased case
9935 if (Biased
9936 and then not Is_Fixed_Point_Type (T)
9937 and then not (Is_Enumeration_Type (T)
9938 and then Has_Non_Standard_Rep (T)))
9939 or else Has_Biased_Representation (T)
9940 then
9941 Hi := Hi - Lo;
9942 Lo := Uint_0;
9943 end if;
9945 -- Signed case. Note that we consider types like range 1 .. -1 to be
9946 -- signed for the purpose of computing the size, since the bounds have
9947 -- to be accommodated in the base type.
9949 if Lo < 0 or else Hi < 0 then
9950 S := 1;
9951 B := Uint_1;
9953 -- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1))
9954 -- Note that we accommodate the case where the bounds cross. This
9955 -- can happen either because of the way the bounds are declared
9956 -- or because of the algorithm in Freeze_Fixed_Point_Type.
9958 while Lo < -B
9959 or else Hi < -B
9960 or else Lo >= B
9961 or else Hi >= B
9962 loop
9963 B := Uint_2 ** S;
9964 S := S + 1;
9965 end loop;
9967 -- Unsigned case
9969 else
9970 -- If both bounds are positive, make sure that both are represen-
9971 -- table in the case where the bounds are crossed. This can happen
9972 -- either because of the way the bounds are declared, or because of
9973 -- the algorithm in Freeze_Fixed_Point_Type.
9975 if Lo > Hi then
9976 Hi := Lo;
9977 end if;
9979 -- S = size, (can accommodate 0 .. (2**size - 1))
9981 S := 0;
9982 while Hi >= Uint_2 ** S loop
9983 S := S + 1;
9984 end loop;
9985 end if;
9987 return S;
9988 end Minimum_Size;
9990 ---------------------------
9991 -- New_Stream_Subprogram --
9992 ---------------------------
9994 procedure New_Stream_Subprogram
9995 (N : Node_Id;
9996 Ent : Entity_Id;
9997 Subp : Entity_Id;
9998 Nam : TSS_Name_Type)
10000 Loc : constant Source_Ptr := Sloc (N);
10001 Sname : constant Name_Id := Make_TSS_Name (Base_Type (Ent), Nam);
10002 Subp_Id : Entity_Id;
10003 Subp_Decl : Node_Id;
10004 F : Entity_Id;
10005 Etyp : Entity_Id;
10007 Defer_Declaration : constant Boolean :=
10008 Is_Tagged_Type (Ent) or else Is_Private_Type (Ent);
10009 -- For a tagged type, there is a declaration for each stream attribute
10010 -- at the freeze point, and we must generate only a completion of this
10011 -- declaration. We do the same for private types, because the full view
10012 -- might be tagged. Otherwise we generate a declaration at the point of
10013 -- the attribute definition clause.
10015 function Build_Spec return Node_Id;
10016 -- Used for declaration and renaming declaration, so that this is
10017 -- treated as a renaming_as_body.
10019 ----------------
10020 -- Build_Spec --
10021 ----------------
10023 function Build_Spec return Node_Id is
10024 Out_P : constant Boolean := (Nam = TSS_Stream_Read);
10025 Formals : List_Id;
10026 Spec : Node_Id;
10027 T_Ref : constant Node_Id := New_Reference_To (Etyp, Loc);
10029 begin
10030 Subp_Id := Make_Defining_Identifier (Loc, Sname);
10032 -- S : access Root_Stream_Type'Class
10034 Formals := New_List (
10035 Make_Parameter_Specification (Loc,
10036 Defining_Identifier =>
10037 Make_Defining_Identifier (Loc, Name_S),
10038 Parameter_Type =>
10039 Make_Access_Definition (Loc,
10040 Subtype_Mark =>
10041 New_Reference_To (
10042 Designated_Type (Etype (F)), Loc))));
10044 if Nam = TSS_Stream_Input then
10045 Spec :=
10046 Make_Function_Specification (Loc,
10047 Defining_Unit_Name => Subp_Id,
10048 Parameter_Specifications => Formals,
10049 Result_Definition => T_Ref);
10050 else
10051 -- V : [out] T
10053 Append_To (Formals,
10054 Make_Parameter_Specification (Loc,
10055 Defining_Identifier => Make_Defining_Identifier (Loc, Name_V),
10056 Out_Present => Out_P,
10057 Parameter_Type => T_Ref));
10059 Spec :=
10060 Make_Procedure_Specification (Loc,
10061 Defining_Unit_Name => Subp_Id,
10062 Parameter_Specifications => Formals);
10063 end if;
10065 return Spec;
10066 end Build_Spec;
10068 -- Start of processing for New_Stream_Subprogram
10070 begin
10071 F := First_Formal (Subp);
10073 if Ekind (Subp) = E_Procedure then
10074 Etyp := Etype (Next_Formal (F));
10075 else
10076 Etyp := Etype (Subp);
10077 end if;
10079 -- Prepare subprogram declaration and insert it as an action on the
10080 -- clause node. The visibility for this entity is used to test for
10081 -- visibility of the attribute definition clause (in the sense of
10082 -- 8.3(23) as amended by AI-195).
10084 if not Defer_Declaration then
10085 Subp_Decl :=
10086 Make_Subprogram_Declaration (Loc,
10087 Specification => Build_Spec);
10089 -- For a tagged type, there is always a visible declaration for each
10090 -- stream TSS (it is a predefined primitive operation), and the
10091 -- completion of this declaration occurs at the freeze point, which is
10092 -- not always visible at places where the attribute definition clause is
10093 -- visible. So, we create a dummy entity here for the purpose of
10094 -- tracking the visibility of the attribute definition clause itself.
10096 else
10097 Subp_Id :=
10098 Make_Defining_Identifier (Loc, New_External_Name (Sname, 'V'));
10099 Subp_Decl :=
10100 Make_Object_Declaration (Loc,
10101 Defining_Identifier => Subp_Id,
10102 Object_Definition => New_Occurrence_Of (Standard_Boolean, Loc));
10103 end if;
10105 Insert_Action (N, Subp_Decl);
10106 Set_Entity (N, Subp_Id);
10108 Subp_Decl :=
10109 Make_Subprogram_Renaming_Declaration (Loc,
10110 Specification => Build_Spec,
10111 Name => New_Reference_To (Subp, Loc));
10113 if Defer_Declaration then
10114 Set_TSS (Base_Type (Ent), Subp_Id);
10115 else
10116 Insert_Action (N, Subp_Decl);
10117 Copy_TSS (Subp_Id, Base_Type (Ent));
10118 end if;
10119 end New_Stream_Subprogram;
10121 ------------------------
10122 -- Rep_Item_Too_Early --
10123 ------------------------
10125 function Rep_Item_Too_Early (T : Entity_Id; N : Node_Id) return Boolean is
10126 begin
10127 -- Cannot apply non-operational rep items to generic types
10129 if Is_Operational_Item (N) then
10130 return False;
10132 elsif Is_Type (T)
10133 and then Is_Generic_Type (Root_Type (T))
10134 then
10135 Error_Msg_N ("representation item not allowed for generic type", N);
10136 return True;
10137 end if;
10139 -- Otherwise check for incomplete type
10141 if Is_Incomplete_Or_Private_Type (T)
10142 and then No (Underlying_Type (T))
10143 and then
10144 (Nkind (N) /= N_Pragma
10145 or else Get_Pragma_Id (N) /= Pragma_Import)
10146 then
10147 Error_Msg_N
10148 ("representation item must be after full type declaration", N);
10149 return True;
10151 -- If the type has incomplete components, a representation clause is
10152 -- illegal but stream attributes and Convention pragmas are correct.
10154 elsif Has_Private_Component (T) then
10155 if Nkind (N) = N_Pragma then
10156 return False;
10158 else
10159 Error_Msg_N
10160 ("representation item must appear after type is fully defined",
10162 return True;
10163 end if;
10164 else
10165 return False;
10166 end if;
10167 end Rep_Item_Too_Early;
10169 -----------------------
10170 -- Rep_Item_Too_Late --
10171 -----------------------
10173 function Rep_Item_Too_Late
10174 (T : Entity_Id;
10175 N : Node_Id;
10176 FOnly : Boolean := False) return Boolean
10178 S : Entity_Id;
10179 Parent_Type : Entity_Id;
10181 procedure Too_Late;
10182 -- Output the too late message. Note that this is not considered a
10183 -- serious error, since the effect is simply that we ignore the
10184 -- representation clause in this case.
10186 --------------
10187 -- Too_Late --
10188 --------------
10190 procedure Too_Late is
10191 begin
10192 -- Other compilers seem more relaxed about rep items appearing too
10193 -- late. Since analysis tools typically don't care about rep items
10194 -- anyway, no reason to be too strict about this.
10196 if not Relaxed_RM_Semantics then
10197 Error_Msg_N ("|representation item appears too late!", N);
10198 end if;
10199 end Too_Late;
10201 -- Start of processing for Rep_Item_Too_Late
10203 begin
10204 -- First make sure entity is not frozen (RM 13.1(9))
10206 if Is_Frozen (T)
10208 -- Exclude imported types, which may be frozen if they appear in a
10209 -- representation clause for a local type.
10211 and then not From_Limited_With (T)
10213 -- Exclude generated entities (not coming from source). The common
10214 -- case is when we generate a renaming which prematurely freezes the
10215 -- renamed internal entity, but we still want to be able to set copies
10216 -- of attribute values such as Size/Alignment.
10218 and then Comes_From_Source (T)
10219 then
10220 Too_Late;
10221 S := First_Subtype (T);
10223 if Present (Freeze_Node (S)) then
10224 Error_Msg_NE
10225 ("??no more representation items for }", Freeze_Node (S), S);
10226 end if;
10228 return True;
10230 -- Check for case of non-tagged derived type whose parent either has
10231 -- primitive operations, or is a by reference type (RM 13.1(10)).
10233 elsif Is_Type (T)
10234 and then not FOnly
10235 and then Is_Derived_Type (T)
10236 and then not Is_Tagged_Type (T)
10237 then
10238 Parent_Type := Etype (Base_Type (T));
10240 if Has_Primitive_Operations (Parent_Type) then
10241 Too_Late;
10242 Error_Msg_NE
10243 ("primitive operations already defined for&!", N, Parent_Type);
10244 return True;
10246 elsif Is_By_Reference_Type (Parent_Type) then
10247 Too_Late;
10248 Error_Msg_NE
10249 ("parent type & is a by reference type!", N, Parent_Type);
10250 return True;
10251 end if;
10252 end if;
10254 -- No error, link item into head of chain of rep items for the entity,
10255 -- but avoid chaining if we have an overloadable entity, and the pragma
10256 -- is one that can apply to multiple overloaded entities.
10258 if Is_Overloadable (T) and then Nkind (N) = N_Pragma then
10259 declare
10260 Pname : constant Name_Id := Pragma_Name (N);
10261 begin
10262 if Nam_In (Pname, Name_Convention, Name_Import, Name_Export,
10263 Name_External, Name_Interface)
10264 then
10265 return False;
10266 end if;
10267 end;
10268 end if;
10270 Record_Rep_Item (T, N);
10271 return False;
10272 end Rep_Item_Too_Late;
10274 -------------------------------------
10275 -- Replace_Type_References_Generic --
10276 -------------------------------------
10278 procedure Replace_Type_References_Generic (N : Node_Id; TName : Name_Id) is
10280 function Replace_Node (N : Node_Id) return Traverse_Result;
10281 -- Processes a single node in the traversal procedure below, checking
10282 -- if node N should be replaced, and if so, doing the replacement.
10284 procedure Replace_Type_Refs is new Traverse_Proc (Replace_Node);
10285 -- This instantiation provides the body of Replace_Type_References
10287 ------------------
10288 -- Replace_Node --
10289 ------------------
10291 function Replace_Node (N : Node_Id) return Traverse_Result is
10292 S : Entity_Id;
10293 P : Node_Id;
10295 begin
10296 -- Case of identifier
10298 if Nkind (N) = N_Identifier then
10300 -- If not the type name, all done with this node
10302 if Chars (N) /= TName then
10303 return Skip;
10305 -- Otherwise do the replacement and we are done with this node
10307 else
10308 Replace_Type_Reference (N);
10309 return Skip;
10310 end if;
10312 -- Case of selected component (which is what a qualification
10313 -- looks like in the unanalyzed tree, which is what we have.
10315 elsif Nkind (N) = N_Selected_Component then
10317 -- If selector name is not our type, keeping going (we might
10318 -- still have an occurrence of the type in the prefix).
10320 if Nkind (Selector_Name (N)) /= N_Identifier
10321 or else Chars (Selector_Name (N)) /= TName
10322 then
10323 return OK;
10325 -- Selector name is our type, check qualification
10327 else
10328 -- Loop through scopes and prefixes, doing comparison
10330 S := Current_Scope;
10331 P := Prefix (N);
10332 loop
10333 -- Continue if no more scopes or scope with no name
10335 if No (S) or else Nkind (S) not in N_Has_Chars then
10336 return OK;
10337 end if;
10339 -- Do replace if prefix is an identifier matching the
10340 -- scope that we are currently looking at.
10342 if Nkind (P) = N_Identifier
10343 and then Chars (P) = Chars (S)
10344 then
10345 Replace_Type_Reference (N);
10346 return Skip;
10347 end if;
10349 -- Go check scope above us if prefix is itself of the
10350 -- form of a selected component, whose selector matches
10351 -- the scope we are currently looking at.
10353 if Nkind (P) = N_Selected_Component
10354 and then Nkind (Selector_Name (P)) = N_Identifier
10355 and then Chars (Selector_Name (P)) = Chars (S)
10356 then
10357 S := Scope (S);
10358 P := Prefix (P);
10360 -- For anything else, we don't have a match, so keep on
10361 -- going, there are still some weird cases where we may
10362 -- still have a replacement within the prefix.
10364 else
10365 return OK;
10366 end if;
10367 end loop;
10368 end if;
10370 -- Continue for any other node kind
10372 else
10373 return OK;
10374 end if;
10375 end Replace_Node;
10377 begin
10378 Replace_Type_Refs (N);
10379 end Replace_Type_References_Generic;
10381 -------------------------
10382 -- Same_Representation --
10383 -------------------------
10385 function Same_Representation (Typ1, Typ2 : Entity_Id) return Boolean is
10386 T1 : constant Entity_Id := Underlying_Type (Typ1);
10387 T2 : constant Entity_Id := Underlying_Type (Typ2);
10389 begin
10390 -- A quick check, if base types are the same, then we definitely have
10391 -- the same representation, because the subtype specific representation
10392 -- attributes (Size and Alignment) do not affect representation from
10393 -- the point of view of this test.
10395 if Base_Type (T1) = Base_Type (T2) then
10396 return True;
10398 elsif Is_Private_Type (Base_Type (T2))
10399 and then Base_Type (T1) = Full_View (Base_Type (T2))
10400 then
10401 return True;
10402 end if;
10404 -- Tagged types never have differing representations
10406 if Is_Tagged_Type (T1) then
10407 return True;
10408 end if;
10410 -- Representations are definitely different if conventions differ
10412 if Convention (T1) /= Convention (T2) then
10413 return False;
10414 end if;
10416 -- Representations are different if component alignments or scalar
10417 -- storage orders differ.
10419 if (Is_Record_Type (T1) or else Is_Array_Type (T1))
10420 and then
10421 (Is_Record_Type (T2) or else Is_Array_Type (T2))
10422 and then
10423 (Component_Alignment (T1) /= Component_Alignment (T2)
10424 or else
10425 Reverse_Storage_Order (T1) /= Reverse_Storage_Order (T2))
10426 then
10427 return False;
10428 end if;
10430 -- For arrays, the only real issue is component size. If we know the
10431 -- component size for both arrays, and it is the same, then that's
10432 -- good enough to know we don't have a change of representation.
10434 if Is_Array_Type (T1) then
10435 if Known_Component_Size (T1)
10436 and then Known_Component_Size (T2)
10437 and then Component_Size (T1) = Component_Size (T2)
10438 then
10439 if VM_Target = No_VM then
10440 return True;
10442 -- In VM targets the representation of arrays with aliased
10443 -- components differs from arrays with non-aliased components
10445 else
10446 return Has_Aliased_Components (Base_Type (T1))
10448 Has_Aliased_Components (Base_Type (T2));
10449 end if;
10450 end if;
10451 end if;
10453 -- Types definitely have same representation if neither has non-standard
10454 -- representation since default representations are always consistent.
10455 -- If only one has non-standard representation, and the other does not,
10456 -- then we consider that they do not have the same representation. They
10457 -- might, but there is no way of telling early enough.
10459 if Has_Non_Standard_Rep (T1) then
10460 if not Has_Non_Standard_Rep (T2) then
10461 return False;
10462 end if;
10463 else
10464 return not Has_Non_Standard_Rep (T2);
10465 end if;
10467 -- Here the two types both have non-standard representation, and we need
10468 -- to determine if they have the same non-standard representation.
10470 -- For arrays, we simply need to test if the component sizes are the
10471 -- same. Pragma Pack is reflected in modified component sizes, so this
10472 -- check also deals with pragma Pack.
10474 if Is_Array_Type (T1) then
10475 return Component_Size (T1) = Component_Size (T2);
10477 -- Tagged types always have the same representation, because it is not
10478 -- possible to specify different representations for common fields.
10480 elsif Is_Tagged_Type (T1) then
10481 return True;
10483 -- Case of record types
10485 elsif Is_Record_Type (T1) then
10487 -- Packed status must conform
10489 if Is_Packed (T1) /= Is_Packed (T2) then
10490 return False;
10492 -- Otherwise we must check components. Typ2 maybe a constrained
10493 -- subtype with fewer components, so we compare the components
10494 -- of the base types.
10496 else
10497 Record_Case : declare
10498 CD1, CD2 : Entity_Id;
10500 function Same_Rep return Boolean;
10501 -- CD1 and CD2 are either components or discriminants. This
10502 -- function tests whether they have the same representation.
10504 --------------
10505 -- Same_Rep --
10506 --------------
10508 function Same_Rep return Boolean is
10509 begin
10510 if No (Component_Clause (CD1)) then
10511 return No (Component_Clause (CD2));
10512 else
10513 -- Note: at this point, component clauses have been
10514 -- normalized to the default bit order, so that the
10515 -- comparison of Component_Bit_Offsets is meaningful.
10517 return
10518 Present (Component_Clause (CD2))
10519 and then
10520 Component_Bit_Offset (CD1) = Component_Bit_Offset (CD2)
10521 and then
10522 Esize (CD1) = Esize (CD2);
10523 end if;
10524 end Same_Rep;
10526 -- Start of processing for Record_Case
10528 begin
10529 if Has_Discriminants (T1) then
10531 -- The number of discriminants may be different if the
10532 -- derived type has fewer (constrained by values). The
10533 -- invisible discriminants retain the representation of
10534 -- the original, so the discrepancy does not per se
10535 -- indicate a different representation.
10537 CD1 := First_Discriminant (T1);
10538 CD2 := First_Discriminant (T2);
10539 while Present (CD1) and then Present (CD2) loop
10540 if not Same_Rep then
10541 return False;
10542 else
10543 Next_Discriminant (CD1);
10544 Next_Discriminant (CD2);
10545 end if;
10546 end loop;
10547 end if;
10549 CD1 := First_Component (Underlying_Type (Base_Type (T1)));
10550 CD2 := First_Component (Underlying_Type (Base_Type (T2)));
10551 while Present (CD1) loop
10552 if not Same_Rep then
10553 return False;
10554 else
10555 Next_Component (CD1);
10556 Next_Component (CD2);
10557 end if;
10558 end loop;
10560 return True;
10561 end Record_Case;
10562 end if;
10564 -- For enumeration types, we must check each literal to see if the
10565 -- representation is the same. Note that we do not permit enumeration
10566 -- representation clauses for Character and Wide_Character, so these
10567 -- cases were already dealt with.
10569 elsif Is_Enumeration_Type (T1) then
10570 Enumeration_Case : declare
10571 L1, L2 : Entity_Id;
10573 begin
10574 L1 := First_Literal (T1);
10575 L2 := First_Literal (T2);
10576 while Present (L1) loop
10577 if Enumeration_Rep (L1) /= Enumeration_Rep (L2) then
10578 return False;
10579 else
10580 Next_Literal (L1);
10581 Next_Literal (L2);
10582 end if;
10583 end loop;
10585 return True;
10586 end Enumeration_Case;
10588 -- Any other types have the same representation for these purposes
10590 else
10591 return True;
10592 end if;
10593 end Same_Representation;
10595 ----------------
10596 -- Set_Biased --
10597 ----------------
10599 procedure Set_Biased
10600 (E : Entity_Id;
10601 N : Node_Id;
10602 Msg : String;
10603 Biased : Boolean := True)
10605 begin
10606 if Biased then
10607 Set_Has_Biased_Representation (E);
10609 if Warn_On_Biased_Representation then
10610 Error_Msg_NE
10611 ("?B?" & Msg & " forces biased representation for&", N, E);
10612 end if;
10613 end if;
10614 end Set_Biased;
10616 --------------------
10617 -- Set_Enum_Esize --
10618 --------------------
10620 procedure Set_Enum_Esize (T : Entity_Id) is
10621 Lo : Uint;
10622 Hi : Uint;
10623 Sz : Nat;
10625 begin
10626 Init_Alignment (T);
10628 -- Find the minimum standard size (8,16,32,64) that fits
10630 Lo := Enumeration_Rep (Entity (Type_Low_Bound (T)));
10631 Hi := Enumeration_Rep (Entity (Type_High_Bound (T)));
10633 if Lo < 0 then
10634 if Lo >= -Uint_2**07 and then Hi < Uint_2**07 then
10635 Sz := Standard_Character_Size; -- May be > 8 on some targets
10637 elsif Lo >= -Uint_2**15 and then Hi < Uint_2**15 then
10638 Sz := 16;
10640 elsif Lo >= -Uint_2**31 and then Hi < Uint_2**31 then
10641 Sz := 32;
10643 else pragma Assert (Lo >= -Uint_2**63 and then Hi < Uint_2**63);
10644 Sz := 64;
10645 end if;
10647 else
10648 if Hi < Uint_2**08 then
10649 Sz := Standard_Character_Size; -- May be > 8 on some targets
10651 elsif Hi < Uint_2**16 then
10652 Sz := 16;
10654 elsif Hi < Uint_2**32 then
10655 Sz := 32;
10657 else pragma Assert (Hi < Uint_2**63);
10658 Sz := 64;
10659 end if;
10660 end if;
10662 -- That minimum is the proper size unless we have a foreign convention
10663 -- and the size required is 32 or less, in which case we bump the size
10664 -- up to 32. This is required for C and C++ and seems reasonable for
10665 -- all other foreign conventions.
10667 if Has_Foreign_Convention (T)
10668 and then Esize (T) < Standard_Integer_Size
10669 then
10670 Init_Esize (T, Standard_Integer_Size);
10671 else
10672 Init_Esize (T, Sz);
10673 end if;
10674 end Set_Enum_Esize;
10676 ------------------------------
10677 -- Validate_Address_Clauses --
10678 ------------------------------
10680 procedure Validate_Address_Clauses is
10681 begin
10682 for J in Address_Clause_Checks.First .. Address_Clause_Checks.Last loop
10683 declare
10684 ACCR : Address_Clause_Check_Record
10685 renames Address_Clause_Checks.Table (J);
10687 Expr : Node_Id;
10689 X_Alignment : Uint;
10690 Y_Alignment : Uint;
10692 X_Size : Uint;
10693 Y_Size : Uint;
10695 begin
10696 -- Skip processing of this entry if warning already posted
10698 if not Address_Warning_Posted (ACCR.N) then
10699 Expr := Original_Node (Expression (ACCR.N));
10701 -- Get alignments
10703 X_Alignment := Alignment (ACCR.X);
10704 Y_Alignment := Alignment (ACCR.Y);
10706 -- Similarly obtain sizes
10708 X_Size := Esize (ACCR.X);
10709 Y_Size := Esize (ACCR.Y);
10711 -- Check for large object overlaying smaller one
10713 if Y_Size > Uint_0
10714 and then X_Size > Uint_0
10715 and then X_Size > Y_Size
10716 then
10717 Error_Msg_NE
10718 ("?& overlays smaller object", ACCR.N, ACCR.X);
10719 Error_Msg_N
10720 ("\??program execution may be erroneous", ACCR.N);
10721 Error_Msg_Uint_1 := X_Size;
10722 Error_Msg_NE
10723 ("\??size of & is ^", ACCR.N, ACCR.X);
10724 Error_Msg_Uint_1 := Y_Size;
10725 Error_Msg_NE
10726 ("\??size of & is ^", ACCR.N, ACCR.Y);
10728 -- Check for inadequate alignment, both of the base object
10729 -- and of the offset, if any.
10731 -- Note: we do not check the alignment if we gave a size
10732 -- warning, since it would likely be redundant.
10734 elsif Y_Alignment /= Uint_0
10735 and then (Y_Alignment < X_Alignment
10736 or else (ACCR.Off
10737 and then
10738 Nkind (Expr) = N_Attribute_Reference
10739 and then
10740 Attribute_Name (Expr) = Name_Address
10741 and then
10742 Has_Compatible_Alignment
10743 (ACCR.X, Prefix (Expr))
10744 /= Known_Compatible))
10745 then
10746 Error_Msg_NE
10747 ("??specified address for& may be inconsistent "
10748 & "with alignment", ACCR.N, ACCR.X);
10749 Error_Msg_N
10750 ("\??program execution may be erroneous (RM 13.3(27))",
10751 ACCR.N);
10752 Error_Msg_Uint_1 := X_Alignment;
10753 Error_Msg_NE
10754 ("\??alignment of & is ^", ACCR.N, ACCR.X);
10755 Error_Msg_Uint_1 := Y_Alignment;
10756 Error_Msg_NE
10757 ("\??alignment of & is ^", ACCR.N, ACCR.Y);
10758 if Y_Alignment >= X_Alignment then
10759 Error_Msg_N
10760 ("\??but offset is not multiple of alignment", ACCR.N);
10761 end if;
10762 end if;
10763 end if;
10764 end;
10765 end loop;
10766 end Validate_Address_Clauses;
10768 ---------------------------
10769 -- Validate_Independence --
10770 ---------------------------
10772 procedure Validate_Independence is
10773 SU : constant Uint := UI_From_Int (System_Storage_Unit);
10774 N : Node_Id;
10775 E : Entity_Id;
10776 IC : Boolean;
10777 Comp : Entity_Id;
10778 Addr : Node_Id;
10779 P : Node_Id;
10781 procedure Check_Array_Type (Atyp : Entity_Id);
10782 -- Checks if the array type Atyp has independent components, and
10783 -- if not, outputs an appropriate set of error messages.
10785 procedure No_Independence;
10786 -- Output message that independence cannot be guaranteed
10788 function OK_Component (C : Entity_Id) return Boolean;
10789 -- Checks one component to see if it is independently accessible, and
10790 -- if so yields True, otherwise yields False if independent access
10791 -- cannot be guaranteed. This is a conservative routine, it only
10792 -- returns True if it knows for sure, it returns False if it knows
10793 -- there is a problem, or it cannot be sure there is no problem.
10795 procedure Reason_Bad_Component (C : Entity_Id);
10796 -- Outputs continuation message if a reason can be determined for
10797 -- the component C being bad.
10799 ----------------------
10800 -- Check_Array_Type --
10801 ----------------------
10803 procedure Check_Array_Type (Atyp : Entity_Id) is
10804 Ctyp : constant Entity_Id := Component_Type (Atyp);
10806 begin
10807 -- OK if no alignment clause, no pack, and no component size
10809 if not Has_Component_Size_Clause (Atyp)
10810 and then not Has_Alignment_Clause (Atyp)
10811 and then not Is_Packed (Atyp)
10812 then
10813 return;
10814 end if;
10816 -- Check actual component size
10818 if not Known_Component_Size (Atyp)
10819 or else not (Addressable (Component_Size (Atyp))
10820 and then Component_Size (Atyp) < 64)
10821 or else Component_Size (Atyp) mod Esize (Ctyp) /= 0
10822 then
10823 No_Independence;
10825 -- Bad component size, check reason
10827 if Has_Component_Size_Clause (Atyp) then
10828 P := Get_Attribute_Definition_Clause
10829 (Atyp, Attribute_Component_Size);
10831 if Present (P) then
10832 Error_Msg_Sloc := Sloc (P);
10833 Error_Msg_N ("\because of Component_Size clause#", N);
10834 return;
10835 end if;
10836 end if;
10838 if Is_Packed (Atyp) then
10839 P := Get_Rep_Pragma (Atyp, Name_Pack);
10841 if Present (P) then
10842 Error_Msg_Sloc := Sloc (P);
10843 Error_Msg_N ("\because of pragma Pack#", N);
10844 return;
10845 end if;
10846 end if;
10848 -- No reason found, just return
10850 return;
10851 end if;
10853 -- Array type is OK independence-wise
10855 return;
10856 end Check_Array_Type;
10858 ---------------------
10859 -- No_Independence --
10860 ---------------------
10862 procedure No_Independence is
10863 begin
10864 if Pragma_Name (N) = Name_Independent then
10865 Error_Msg_NE ("independence cannot be guaranteed for&", N, E);
10866 else
10867 Error_Msg_NE
10868 ("independent components cannot be guaranteed for&", N, E);
10869 end if;
10870 end No_Independence;
10872 ------------------
10873 -- OK_Component --
10874 ------------------
10876 function OK_Component (C : Entity_Id) return Boolean is
10877 Rec : constant Entity_Id := Scope (C);
10878 Ctyp : constant Entity_Id := Etype (C);
10880 begin
10881 -- OK if no component clause, no Pack, and no alignment clause
10883 if No (Component_Clause (C))
10884 and then not Is_Packed (Rec)
10885 and then not Has_Alignment_Clause (Rec)
10886 then
10887 return True;
10888 end if;
10890 -- Here we look at the actual component layout. A component is
10891 -- addressable if its size is a multiple of the Esize of the
10892 -- component type, and its starting position in the record has
10893 -- appropriate alignment, and the record itself has appropriate
10894 -- alignment to guarantee the component alignment.
10896 -- Make sure sizes are static, always assume the worst for any
10897 -- cases where we cannot check static values.
10899 if not (Known_Static_Esize (C)
10900 and then
10901 Known_Static_Esize (Ctyp))
10902 then
10903 return False;
10904 end if;
10906 -- Size of component must be addressable or greater than 64 bits
10907 -- and a multiple of bytes.
10909 if not Addressable (Esize (C)) and then Esize (C) < Uint_64 then
10910 return False;
10911 end if;
10913 -- Check size is proper multiple
10915 if Esize (C) mod Esize (Ctyp) /= 0 then
10916 return False;
10917 end if;
10919 -- Check alignment of component is OK
10921 if not Known_Component_Bit_Offset (C)
10922 or else Component_Bit_Offset (C) < Uint_0
10923 or else Component_Bit_Offset (C) mod Esize (Ctyp) /= 0
10924 then
10925 return False;
10926 end if;
10928 -- Check alignment of record type is OK
10930 if not Known_Alignment (Rec)
10931 or else (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0
10932 then
10933 return False;
10934 end if;
10936 -- All tests passed, component is addressable
10938 return True;
10939 end OK_Component;
10941 --------------------------
10942 -- Reason_Bad_Component --
10943 --------------------------
10945 procedure Reason_Bad_Component (C : Entity_Id) is
10946 Rec : constant Entity_Id := Scope (C);
10947 Ctyp : constant Entity_Id := Etype (C);
10949 begin
10950 -- If component clause present assume that's the problem
10952 if Present (Component_Clause (C)) then
10953 Error_Msg_Sloc := Sloc (Component_Clause (C));
10954 Error_Msg_N ("\because of Component_Clause#", N);
10955 return;
10956 end if;
10958 -- If pragma Pack clause present, assume that's the problem
10960 if Is_Packed (Rec) then
10961 P := Get_Rep_Pragma (Rec, Name_Pack);
10963 if Present (P) then
10964 Error_Msg_Sloc := Sloc (P);
10965 Error_Msg_N ("\because of pragma Pack#", N);
10966 return;
10967 end if;
10968 end if;
10970 -- See if record has bad alignment clause
10972 if Has_Alignment_Clause (Rec)
10973 and then Known_Alignment (Rec)
10974 and then (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0
10975 then
10976 P := Get_Attribute_Definition_Clause (Rec, Attribute_Alignment);
10978 if Present (P) then
10979 Error_Msg_Sloc := Sloc (P);
10980 Error_Msg_N ("\because of Alignment clause#", N);
10981 end if;
10982 end if;
10984 -- Couldn't find a reason, so return without a message
10986 return;
10987 end Reason_Bad_Component;
10989 -- Start of processing for Validate_Independence
10991 begin
10992 for J in Independence_Checks.First .. Independence_Checks.Last loop
10993 N := Independence_Checks.Table (J).N;
10994 E := Independence_Checks.Table (J).E;
10995 IC := Pragma_Name (N) = Name_Independent_Components;
10997 -- Deal with component case
10999 if Ekind (E) = E_Discriminant or else Ekind (E) = E_Component then
11000 if not OK_Component (E) then
11001 No_Independence;
11002 Reason_Bad_Component (E);
11003 goto Continue;
11004 end if;
11005 end if;
11007 -- Deal with record with Independent_Components
11009 if IC and then Is_Record_Type (E) then
11010 Comp := First_Component_Or_Discriminant (E);
11011 while Present (Comp) loop
11012 if not OK_Component (Comp) then
11013 No_Independence;
11014 Reason_Bad_Component (Comp);
11015 goto Continue;
11016 end if;
11018 Next_Component_Or_Discriminant (Comp);
11019 end loop;
11020 end if;
11022 -- Deal with address clause case
11024 if Is_Object (E) then
11025 Addr := Address_Clause (E);
11027 if Present (Addr) then
11028 No_Independence;
11029 Error_Msg_Sloc := Sloc (Addr);
11030 Error_Msg_N ("\because of Address clause#", N);
11031 goto Continue;
11032 end if;
11033 end if;
11035 -- Deal with independent components for array type
11037 if IC and then Is_Array_Type (E) then
11038 Check_Array_Type (E);
11039 end if;
11041 -- Deal with independent components for array object
11043 if IC and then Is_Object (E) and then Is_Array_Type (Etype (E)) then
11044 Check_Array_Type (Etype (E));
11045 end if;
11047 <<Continue>> null;
11048 end loop;
11049 end Validate_Independence;
11051 -----------------------------------
11052 -- Validate_Unchecked_Conversion --
11053 -----------------------------------
11055 procedure Validate_Unchecked_Conversion
11056 (N : Node_Id;
11057 Act_Unit : Entity_Id)
11059 Source : Entity_Id;
11060 Target : Entity_Id;
11061 Vnode : Node_Id;
11063 begin
11064 -- Obtain source and target types. Note that we call Ancestor_Subtype
11065 -- here because the processing for generic instantiation always makes
11066 -- subtypes, and we want the original frozen actual types.
11068 -- If we are dealing with private types, then do the check on their
11069 -- fully declared counterparts if the full declarations have been
11070 -- encountered (they don't have to be visible, but they must exist!)
11072 Source := Ancestor_Subtype (Etype (First_Formal (Act_Unit)));
11074 if Is_Private_Type (Source)
11075 and then Present (Underlying_Type (Source))
11076 then
11077 Source := Underlying_Type (Source);
11078 end if;
11080 Target := Ancestor_Subtype (Etype (Act_Unit));
11082 -- If either type is generic, the instantiation happens within a generic
11083 -- unit, and there is nothing to check. The proper check will happen
11084 -- when the enclosing generic is instantiated.
11086 if Is_Generic_Type (Source) or else Is_Generic_Type (Target) then
11087 return;
11088 end if;
11090 if Is_Private_Type (Target)
11091 and then Present (Underlying_Type (Target))
11092 then
11093 Target := Underlying_Type (Target);
11094 end if;
11096 -- Source may be unconstrained array, but not target
11098 if Is_Array_Type (Target) and then not Is_Constrained (Target) then
11099 Error_Msg_N
11100 ("unchecked conversion to unconstrained array not allowed", N);
11101 return;
11102 end if;
11104 -- Warn if conversion between two different convention pointers
11106 if Is_Access_Type (Target)
11107 and then Is_Access_Type (Source)
11108 and then Convention (Target) /= Convention (Source)
11109 and then Warn_On_Unchecked_Conversion
11110 then
11111 -- Give warnings for subprogram pointers only on most targets. The
11112 -- exception is VMS, where data pointers can have different lengths
11113 -- depending on the pointer convention.
11115 if Is_Access_Subprogram_Type (Target)
11116 or else Is_Access_Subprogram_Type (Source)
11117 or else OpenVMS_On_Target
11118 then
11119 Error_Msg_N
11120 ("?z?conversion between pointers with different conventions!",
11122 end if;
11123 end if;
11125 -- Warn if one of the operands is Ada.Calendar.Time. Do not emit a
11126 -- warning when compiling GNAT-related sources.
11128 if Warn_On_Unchecked_Conversion
11129 and then not In_Predefined_Unit (N)
11130 and then RTU_Loaded (Ada_Calendar)
11131 and then
11132 (Chars (Source) = Name_Time
11133 or else
11134 Chars (Target) = Name_Time)
11135 then
11136 -- If Ada.Calendar is loaded and the name of one of the operands is
11137 -- Time, there is a good chance that this is Ada.Calendar.Time.
11139 declare
11140 Calendar_Time : constant Entity_Id :=
11141 Full_View (RTE (RO_CA_Time));
11142 begin
11143 pragma Assert (Present (Calendar_Time));
11145 if Source = Calendar_Time or else Target = Calendar_Time then
11146 Error_Msg_N
11147 ("?z?representation of 'Time values may change between " &
11148 "'G'N'A'T versions", N);
11149 end if;
11150 end;
11151 end if;
11153 -- Make entry in unchecked conversion table for later processing by
11154 -- Validate_Unchecked_Conversions, which will check sizes and alignments
11155 -- (using values set by the back-end where possible). This is only done
11156 -- if the appropriate warning is active.
11158 if Warn_On_Unchecked_Conversion then
11159 Unchecked_Conversions.Append
11160 (New_Val => UC_Entry'(Eloc => Sloc (N),
11161 Source => Source,
11162 Target => Target));
11164 -- If both sizes are known statically now, then back end annotation
11165 -- is not required to do a proper check but if either size is not
11166 -- known statically, then we need the annotation.
11168 if Known_Static_RM_Size (Source)
11169 and then
11170 Known_Static_RM_Size (Target)
11171 then
11172 null;
11173 else
11174 Back_Annotate_Rep_Info := True;
11175 end if;
11176 end if;
11178 -- If unchecked conversion to access type, and access type is declared
11179 -- in the same unit as the unchecked conversion, then set the flag
11180 -- No_Strict_Aliasing (no strict aliasing is implicit here)
11182 if Is_Access_Type (Target) and then
11183 In_Same_Source_Unit (Target, N)
11184 then
11185 Set_No_Strict_Aliasing (Implementation_Base_Type (Target));
11186 end if;
11188 -- Generate N_Validate_Unchecked_Conversion node for back end in case
11189 -- the back end needs to perform special validation checks.
11191 -- Shouldn't this be in Exp_Ch13, since the check only gets done if we
11192 -- have full expansion and the back end is called ???
11194 Vnode :=
11195 Make_Validate_Unchecked_Conversion (Sloc (N));
11196 Set_Source_Type (Vnode, Source);
11197 Set_Target_Type (Vnode, Target);
11199 -- If the unchecked conversion node is in a list, just insert before it.
11200 -- If not we have some strange case, not worth bothering about.
11202 if Is_List_Member (N) then
11203 Insert_After (N, Vnode);
11204 end if;
11205 end Validate_Unchecked_Conversion;
11207 ------------------------------------
11208 -- Validate_Unchecked_Conversions --
11209 ------------------------------------
11211 procedure Validate_Unchecked_Conversions is
11212 begin
11213 for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop
11214 declare
11215 T : UC_Entry renames Unchecked_Conversions.Table (N);
11217 Eloc : constant Source_Ptr := T.Eloc;
11218 Source : constant Entity_Id := T.Source;
11219 Target : constant Entity_Id := T.Target;
11221 Source_Siz : Uint;
11222 Target_Siz : Uint;
11224 begin
11225 -- This validation check, which warns if we have unequal sizes for
11226 -- unchecked conversion, and thus potentially implementation
11227 -- dependent semantics, is one of the few occasions on which we
11228 -- use the official RM size instead of Esize. See description in
11229 -- Einfo "Handling of Type'Size Values" for details.
11231 if Serious_Errors_Detected = 0
11232 and then Known_Static_RM_Size (Source)
11233 and then Known_Static_RM_Size (Target)
11235 -- Don't do the check if warnings off for either type, note the
11236 -- deliberate use of OR here instead of OR ELSE to get the flag
11237 -- Warnings_Off_Used set for both types if appropriate.
11239 and then not (Has_Warnings_Off (Source)
11241 Has_Warnings_Off (Target))
11242 then
11243 Source_Siz := RM_Size (Source);
11244 Target_Siz := RM_Size (Target);
11246 if Source_Siz /= Target_Siz then
11247 Error_Msg
11248 ("?z?types for unchecked conversion have different sizes!",
11249 Eloc);
11251 if All_Errors_Mode then
11252 Error_Msg_Name_1 := Chars (Source);
11253 Error_Msg_Uint_1 := Source_Siz;
11254 Error_Msg_Name_2 := Chars (Target);
11255 Error_Msg_Uint_2 := Target_Siz;
11256 Error_Msg ("\size of % is ^, size of % is ^?z?", Eloc);
11258 Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz);
11260 if Is_Discrete_Type (Source)
11261 and then
11262 Is_Discrete_Type (Target)
11263 then
11264 if Source_Siz > Target_Siz then
11265 Error_Msg
11266 ("\?z?^ high order bits of source will "
11267 & "be ignored!", Eloc);
11269 elsif Is_Unsigned_Type (Source) then
11270 Error_Msg
11271 ("\?z?source will be extended with ^ high order "
11272 & "zero bits?!", Eloc);
11274 else
11275 Error_Msg
11276 ("\?z?source will be extended with ^ high order "
11277 & "sign bits!", Eloc);
11278 end if;
11280 elsif Source_Siz < Target_Siz then
11281 if Is_Discrete_Type (Target) then
11282 if Bytes_Big_Endian then
11283 Error_Msg
11284 ("\?z?target value will include ^ undefined "
11285 & "low order bits!", Eloc);
11286 else
11287 Error_Msg
11288 ("\?z?target value will include ^ undefined "
11289 & "high order bits!", Eloc);
11290 end if;
11292 else
11293 Error_Msg
11294 ("\?z?^ trailing bits of target value will be "
11295 & "undefined!", Eloc);
11296 end if;
11298 else pragma Assert (Source_Siz > Target_Siz);
11299 Error_Msg
11300 ("\?z?^ trailing bits of source will be ignored!",
11301 Eloc);
11302 end if;
11303 end if;
11304 end if;
11305 end if;
11307 -- If both types are access types, we need to check the alignment.
11308 -- If the alignment of both is specified, we can do it here.
11310 if Serious_Errors_Detected = 0
11311 and then Ekind (Source) in Access_Kind
11312 and then Ekind (Target) in Access_Kind
11313 and then Target_Strict_Alignment
11314 and then Present (Designated_Type (Source))
11315 and then Present (Designated_Type (Target))
11316 then
11317 declare
11318 D_Source : constant Entity_Id := Designated_Type (Source);
11319 D_Target : constant Entity_Id := Designated_Type (Target);
11321 begin
11322 if Known_Alignment (D_Source)
11323 and then
11324 Known_Alignment (D_Target)
11325 then
11326 declare
11327 Source_Align : constant Uint := Alignment (D_Source);
11328 Target_Align : constant Uint := Alignment (D_Target);
11330 begin
11331 if Source_Align < Target_Align
11332 and then not Is_Tagged_Type (D_Source)
11334 -- Suppress warning if warnings suppressed on either
11335 -- type or either designated type. Note the use of
11336 -- OR here instead of OR ELSE. That is intentional,
11337 -- we would like to set flag Warnings_Off_Used in
11338 -- all types for which warnings are suppressed.
11340 and then not (Has_Warnings_Off (D_Source)
11342 Has_Warnings_Off (D_Target)
11344 Has_Warnings_Off (Source)
11346 Has_Warnings_Off (Target))
11347 then
11348 Error_Msg_Uint_1 := Target_Align;
11349 Error_Msg_Uint_2 := Source_Align;
11350 Error_Msg_Node_1 := D_Target;
11351 Error_Msg_Node_2 := D_Source;
11352 Error_Msg
11353 ("?z?alignment of & (^) is stricter than "
11354 & "alignment of & (^)!", Eloc);
11355 Error_Msg
11356 ("\?z?resulting access value may have invalid "
11357 & "alignment!", Eloc);
11358 end if;
11359 end;
11360 end if;
11361 end;
11362 end if;
11363 end;
11364 end loop;
11365 end Validate_Unchecked_Conversions;
11367 end Sem_Ch13;