1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2014, Free Software Foundation, Inc. --
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. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
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;
37 with Lib.Xref; use Lib.Xref;
38 with Namet; use Namet;
39 with Nlists; use Nlists;
40 with Nmake; use Nmake;
42 with Restrict; use Restrict;
43 with Rident; use Rident;
44 with Rtsfind; use Rtsfind;
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_Dim; use Sem_Dim;
52 with Sem_Disp; use Sem_Disp;
53 with Sem_Eval; use Sem_Eval;
54 with Sem_Prag; use Sem_Prag;
55 with Sem_Res; use Sem_Res;
56 with Sem_Type; use Sem_Type;
57 with Sem_Util; use Sem_Util;
58 with Sem_Warn; use Sem_Warn;
59 with Sinput; use Sinput;
60 with Snames; use Snames;
61 with Stand; use Stand;
62 with Sinfo; use Sinfo;
63 with Stringt; use Stringt;
64 with Targparm; use Targparm;
65 with Ttypes; use Ttypes;
66 with Tbuild; use Tbuild;
67 with Urealp; use Urealp;
68 with Warnsw; use Warnsw;
70 with GNAT.Heap_Sort_G;
72 package body Sem_Ch13 is
74 SSU : constant Pos := System_Storage_Unit;
75 -- Convenient short hand for commonly used constant
77 -----------------------
78 -- Local Subprograms --
79 -----------------------
81 procedure Alignment_Check_For_Size_Change (Typ : Entity_Id; Size : Uint);
82 -- This routine is called after setting one of the sizes of type entity
83 -- Typ to Size. The purpose is to deal with the situation of a derived
84 -- type whose inherited alignment is no longer appropriate for the new
85 -- size value. In this case, we reset the Alignment to unknown.
87 procedure Build_Predicate_Functions (Typ : Entity_Id; N : Node_Id);
88 -- If Typ has predicates (indicated by Has_Predicates being set for Typ),
89 -- then either there are pragma Predicate entries on the rep chain for the
90 -- type (note that Predicate aspects are converted to pragma Predicate), or
91 -- there are inherited aspects from a parent type, or ancestor subtypes.
92 -- This procedure builds the spec and body for the Predicate function that
93 -- tests these predicates. N is the freeze node for the type. The spec of
94 -- the function is inserted before the freeze node, and the body of the
95 -- function is inserted after the freeze node. If the predicate expression
96 -- has at least one Raise_Expression, then this procedure also builds the
97 -- M version of the predicate function for use in membership tests.
99 procedure Build_Static_Predicate
103 -- Given a predicated type Typ, where Typ is a discrete static subtype,
104 -- whose predicate expression is Expr, tests if Expr is a static predicate,
105 -- and if so, builds the predicate range list. Nam is the name of the one
106 -- argument to the predicate function. Occurrences of the type name in the
107 -- predicate expression have been replaced by identifier references to this
108 -- name, which is unique, so any identifier with Chars matching Nam must be
109 -- a reference to the type. If the predicate is non-static, this procedure
110 -- returns doing nothing. If the predicate is static, then the predicate
111 -- list is stored in Static_Predicate (Typ), and the Expr is rewritten as
112 -- a canonicalized membership operation.
114 procedure Check_Pool_Size_Clash (Ent : Entity_Id; SP, SS : Node_Id);
115 -- Called if both Storage_Pool and Storage_Size attribute definition
116 -- clauses (SP and SS) are present for entity Ent. Issue error message.
118 procedure Freeze_Entity_Checks (N : Node_Id);
119 -- Called from Analyze_Freeze_Entity and Analyze_Generic_Freeze Entity
120 -- to generate appropriate semantic checks that are delayed until this
121 -- point (they had to be delayed this long for cases of delayed aspects,
122 -- e.g. analysis of statically predicated subtypes in choices, for which
123 -- we have to be sure the subtypes in question are frozen before checking.
125 function Get_Alignment_Value (Expr : Node_Id) return Uint;
126 -- Given the expression for an alignment value, returns the corresponding
127 -- Uint value. If the value is inappropriate, then error messages are
128 -- posted as required, and a value of No_Uint is returned.
130 function Is_Operational_Item (N : Node_Id) return Boolean;
131 -- A specification for a stream attribute is allowed before the full type
132 -- is declared, as explained in AI-00137 and the corrigendum. Attributes
133 -- that do not specify a representation characteristic are operational
136 procedure New_Stream_Subprogram
140 Nam : TSS_Name_Type);
141 -- Create a subprogram renaming of a given stream attribute to the
142 -- designated subprogram and then in the tagged case, provide this as a
143 -- primitive operation, or in the non-tagged case make an appropriate TSS
144 -- entry. This is more properly an expansion activity than just semantics,
145 -- but the presence of user-defined stream functions for limited types is a
146 -- legality check, which is why this takes place here rather than in
147 -- exp_ch13, where it was previously. Nam indicates the name of the TSS
148 -- function to be generated.
150 -- To avoid elaboration anomalies with freeze nodes, for untagged types
151 -- we generate both a subprogram declaration and a subprogram renaming
152 -- declaration, so that the attribute specification is handled as a
153 -- renaming_as_body. For tagged types, the specification is one of the
157 with procedure Replace_Type_Reference (N : Node_Id);
158 procedure Replace_Type_References_Generic (N : Node_Id; TName : Name_Id);
159 -- This is used to scan an expression for a predicate or invariant aspect
160 -- replacing occurrences of the name TName (the name of the subtype to
161 -- which the aspect applies) with appropriate references to the parameter
162 -- of the predicate function or invariant procedure. The procedure passed
163 -- as a generic parameter does the actual replacement of node N, which is
164 -- either a simple direct reference to TName, or a selected component that
165 -- represents an appropriately qualified occurrence of TName.
167 procedure Resolve_Iterable_Operation
172 -- If the name of a primitive operation for an Iterable aspect is
173 -- overloaded, resolve according to required signature.
179 Biased : Boolean := True);
180 -- If Biased is True, sets Has_Biased_Representation flag for E, and
181 -- outputs a warning message at node N if Warn_On_Biased_Representation is
182 -- is True. This warning inserts the string Msg to describe the construct
185 ----------------------------------------------
186 -- Table for Validate_Unchecked_Conversions --
187 ----------------------------------------------
189 -- The following table collects unchecked conversions for validation.
190 -- Entries are made by Validate_Unchecked_Conversion and then the call
191 -- to Validate_Unchecked_Conversions does the actual error checking and
192 -- posting of warnings. The reason for this delayed processing is to take
193 -- advantage of back-annotations of size and alignment values performed by
196 -- Note: the reason we store a Source_Ptr value instead of a Node_Id is
197 -- that by the time Validate_Unchecked_Conversions is called, Sprint will
198 -- already have modified all Sloc values if the -gnatD option is set.
200 type UC_Entry is record
201 Eloc : Source_Ptr; -- node used for posting warnings
202 Source : Entity_Id; -- source type for unchecked conversion
203 Target : Entity_Id; -- target type for unchecked conversion
204 Act_Unit : Entity_Id; -- actual function instantiated
207 package Unchecked_Conversions is new Table.Table (
208 Table_Component_Type => UC_Entry,
209 Table_Index_Type => Int,
210 Table_Low_Bound => 1,
212 Table_Increment => 200,
213 Table_Name => "Unchecked_Conversions");
215 ----------------------------------------
216 -- Table for Validate_Address_Clauses --
217 ----------------------------------------
219 -- If an address clause has the form
221 -- for X'Address use Expr
223 -- where Expr is of the form Y'Address or recursively is a reference to a
224 -- constant of either of these forms, and X and Y are entities of objects,
225 -- then if Y has a smaller alignment than X, that merits a warning about
226 -- possible bad alignment. The following table collects address clauses of
227 -- this kind. We put these in a table so that they can be checked after the
228 -- back end has completed annotation of the alignments of objects, since we
229 -- can catch more cases that way.
231 type Address_Clause_Check_Record is record
233 -- The address clause
236 -- The entity of the object overlaying Y
239 -- The entity of the object being overlaid
242 -- Whether the address is offset within Y
245 package Address_Clause_Checks is new Table.Table (
246 Table_Component_Type => Address_Clause_Check_Record,
247 Table_Index_Type => Int,
248 Table_Low_Bound => 1,
250 Table_Increment => 200,
251 Table_Name => "Address_Clause_Checks");
253 -----------------------------------------
254 -- Adjust_Record_For_Reverse_Bit_Order --
255 -----------------------------------------
257 procedure Adjust_Record_For_Reverse_Bit_Order (R : Entity_Id) is
262 -- Processing depends on version of Ada
264 -- For Ada 95, we just renumber bits within a storage unit. We do the
265 -- same for Ada 83 mode, since we recognize the Bit_Order attribute in
266 -- Ada 83, and are free to add this extension.
268 if Ada_Version < Ada_2005 then
269 Comp := First_Component_Or_Discriminant (R);
270 while Present (Comp) loop
271 CC := Component_Clause (Comp);
273 -- If component clause is present, then deal with the non-default
274 -- bit order case for Ada 95 mode.
276 -- We only do this processing for the base type, and in fact that
277 -- is important, since otherwise if there are record subtypes, we
278 -- could reverse the bits once for each subtype, which is wrong.
280 if Present (CC) and then Ekind (R) = E_Record_Type then
282 CFB : constant Uint := Component_Bit_Offset (Comp);
283 CSZ : constant Uint := Esize (Comp);
284 CLC : constant Node_Id := Component_Clause (Comp);
285 Pos : constant Node_Id := Position (CLC);
286 FB : constant Node_Id := First_Bit (CLC);
288 Storage_Unit_Offset : constant Uint :=
289 CFB / System_Storage_Unit;
291 Start_Bit : constant Uint :=
292 CFB mod System_Storage_Unit;
295 -- Cases where field goes over storage unit boundary
297 if Start_Bit + CSZ > System_Storage_Unit then
299 -- Allow multi-byte field but generate warning
301 if Start_Bit mod System_Storage_Unit = 0
302 and then CSZ mod System_Storage_Unit = 0
305 ("multi-byte field specified with non-standard"
306 & " Bit_Order??", CLC);
308 if Bytes_Big_Endian then
310 ("bytes are not reversed "
311 & "(component is big-endian)??", CLC);
314 ("bytes are not reversed "
315 & "(component is little-endian)??", CLC);
318 -- Do not allow non-contiguous field
322 ("attempt to specify non-contiguous field "
323 & "not permitted", CLC);
325 ("\caused by non-standard Bit_Order "
328 ("\consider possibility of using "
329 & "Ada 2005 mode here", CLC);
332 -- Case where field fits in one storage unit
335 -- Give warning if suspicious component clause
337 if Intval (FB) >= System_Storage_Unit
338 and then Warn_On_Reverse_Bit_Order
341 ("Bit_Order clause does not affect " &
342 "byte ordering?V?", Pos);
344 Intval (Pos) + Intval (FB) /
347 ("position normalized to ^ before bit " &
348 "order interpreted?V?", Pos);
351 -- Here is where we fix up the Component_Bit_Offset value
352 -- to account for the reverse bit order. Some examples of
353 -- what needs to be done are:
355 -- First_Bit .. Last_Bit Component_Bit_Offset
367 -- The rule is that the first bit is is obtained by
368 -- subtracting the old ending bit from storage_unit - 1.
370 Set_Component_Bit_Offset
372 (Storage_Unit_Offset * System_Storage_Unit) +
373 (System_Storage_Unit - 1) -
374 (Start_Bit + CSZ - 1));
376 Set_Normalized_First_Bit
378 Component_Bit_Offset (Comp) mod
379 System_Storage_Unit);
384 Next_Component_Or_Discriminant (Comp);
387 -- For Ada 2005, we do machine scalar processing, as fully described In
388 -- AI-133. This involves gathering all components which start at the
389 -- same byte offset and processing them together. Same approach is still
390 -- valid in later versions including Ada 2012.
394 Max_Machine_Scalar_Size : constant Uint :=
396 (Standard_Long_Long_Integer_Size);
397 -- We use this as the maximum machine scalar size
400 SSU : constant Uint := UI_From_Int (System_Storage_Unit);
403 -- This first loop through components does two things. First it
404 -- deals with the case of components with component clauses whose
405 -- length is greater than the maximum machine scalar size (either
406 -- accepting them or rejecting as needed). Second, it counts the
407 -- number of components with component clauses whose length does
408 -- not exceed this maximum for later processing.
411 Comp := First_Component_Or_Discriminant (R);
412 while Present (Comp) loop
413 CC := Component_Clause (Comp);
417 Fbit : constant Uint := Static_Integer (First_Bit (CC));
418 Lbit : constant Uint := Static_Integer (Last_Bit (CC));
421 -- Case of component with last bit >= max machine scalar
423 if Lbit >= Max_Machine_Scalar_Size then
425 -- This is allowed only if first bit is zero, and
426 -- last bit + 1 is a multiple of storage unit size.
428 if Fbit = 0 and then (Lbit + 1) mod SSU = 0 then
430 -- This is the case to give a warning if enabled
432 if Warn_On_Reverse_Bit_Order then
434 ("multi-byte field specified with "
435 & " non-standard Bit_Order?V?", CC);
437 if Bytes_Big_Endian then
439 ("\bytes are not reversed "
440 & "(component is big-endian)?V?", CC);
443 ("\bytes are not reversed "
444 & "(component is little-endian)?V?", CC);
448 -- Give error message for RM 13.5.1(10) violation
452 ("machine scalar rules not followed for&",
453 First_Bit (CC), Comp);
455 Error_Msg_Uint_1 := Lbit;
456 Error_Msg_Uint_2 := Max_Machine_Scalar_Size;
458 ("\last bit (^) exceeds maximum machine "
462 if (Lbit + 1) mod SSU /= 0 then
463 Error_Msg_Uint_1 := SSU;
465 ("\and is not a multiple of Storage_Unit (^) "
470 Error_Msg_Uint_1 := Fbit;
472 ("\and first bit (^) is non-zero "
478 -- OK case of machine scalar related component clause,
479 -- For now, just count them.
482 Num_CC := Num_CC + 1;
487 Next_Component_Or_Discriminant (Comp);
490 -- We need to sort the component clauses on the basis of the
491 -- Position values in the clause, so we can group clauses with
492 -- the same Position together to determine the relevant machine
496 Comps : array (0 .. Num_CC) of Entity_Id;
497 -- Array to collect component and discriminant entities. The
498 -- data starts at index 1, the 0'th entry is for the sort
501 function CP_Lt (Op1, Op2 : Natural) return Boolean;
502 -- Compare routine for Sort
504 procedure CP_Move (From : Natural; To : Natural);
505 -- Move routine for Sort
507 package Sorting is new GNAT.Heap_Sort_G (CP_Move, CP_Lt);
511 -- Start and stop positions in the component list of the set of
512 -- components with the same starting position (that constitute
513 -- components in a single machine scalar).
516 -- Maximum last bit value of any component in this set
519 -- Corresponding machine scalar size
525 function CP_Lt (Op1, Op2 : Natural) return Boolean is
527 return Position (Component_Clause (Comps (Op1))) <
528 Position (Component_Clause (Comps (Op2)));
535 procedure CP_Move (From : Natural; To : Natural) is
537 Comps (To) := Comps (From);
540 -- Start of processing for Sort_CC
543 -- Collect the machine scalar relevant component clauses
546 Comp := First_Component_Or_Discriminant (R);
547 while Present (Comp) loop
549 CC : constant Node_Id := Component_Clause (Comp);
552 -- Collect only component clauses whose last bit is less
553 -- than machine scalar size. Any component clause whose
554 -- last bit exceeds this value does not take part in
555 -- machine scalar layout considerations. The test for
556 -- Error_Posted makes sure we exclude component clauses
557 -- for which we already posted an error.
560 and then not Error_Posted (Last_Bit (CC))
561 and then Static_Integer (Last_Bit (CC)) <
562 Max_Machine_Scalar_Size
564 Num_CC := Num_CC + 1;
565 Comps (Num_CC) := Comp;
569 Next_Component_Or_Discriminant (Comp);
572 -- Sort by ascending position number
574 Sorting.Sort (Num_CC);
576 -- We now have all the components whose size does not exceed
577 -- the max machine scalar value, sorted by starting position.
578 -- In this loop we gather groups of clauses starting at the
579 -- same position, to process them in accordance with AI-133.
582 while Stop < Num_CC loop
587 (Last_Bit (Component_Clause (Comps (Start))));
588 while Stop < Num_CC loop
590 (Position (Component_Clause (Comps (Stop + 1)))) =
592 (Position (Component_Clause (Comps (Stop))))
600 (Component_Clause (Comps (Stop)))));
606 -- Now we have a group of component clauses from Start to
607 -- Stop whose positions are identical, and MaxL is the
608 -- maximum last bit value of any of these components.
610 -- We need to determine the corresponding machine scalar
611 -- size. This loop assumes that machine scalar sizes are
612 -- even, and that each possible machine scalar has twice
613 -- as many bits as the next smaller one.
615 MSS := Max_Machine_Scalar_Size;
617 and then (MSS / 2) >= SSU
618 and then (MSS / 2) > MaxL
623 -- Here is where we fix up the Component_Bit_Offset value
624 -- to account for the reverse bit order. Some examples of
625 -- what needs to be done for the case of a machine scalar
628 -- First_Bit .. Last_Bit Component_Bit_Offset
640 -- The rule is that the first bit is obtained by subtracting
641 -- the old ending bit from machine scalar size - 1.
643 for C in Start .. Stop loop
645 Comp : constant Entity_Id := Comps (C);
646 CC : constant Node_Id := Component_Clause (Comp);
648 LB : constant Uint := Static_Integer (Last_Bit (CC));
649 NFB : constant Uint := MSS - Uint_1 - LB;
650 NLB : constant Uint := NFB + Esize (Comp) - 1;
651 Pos : constant Uint := Static_Integer (Position (CC));
654 if Warn_On_Reverse_Bit_Order then
655 Error_Msg_Uint_1 := MSS;
657 ("info: reverse bit order in machine " &
658 "scalar of length^?V?", First_Bit (CC));
659 Error_Msg_Uint_1 := NFB;
660 Error_Msg_Uint_2 := NLB;
662 if Bytes_Big_Endian then
664 ("\big-endian range for "
665 & "component & is ^ .. ^?V?",
666 First_Bit (CC), Comp);
669 ("\little-endian range "
670 & "for component & is ^ .. ^?V?",
671 First_Bit (CC), Comp);
675 Set_Component_Bit_Offset (Comp, Pos * SSU + NFB);
676 Set_Normalized_First_Bit (Comp, NFB mod SSU);
683 end Adjust_Record_For_Reverse_Bit_Order;
685 -------------------------------------
686 -- Alignment_Check_For_Size_Change --
687 -------------------------------------
689 procedure Alignment_Check_For_Size_Change (Typ : Entity_Id; Size : Uint) is
691 -- If the alignment is known, and not set by a rep clause, and is
692 -- inconsistent with the size being set, then reset it to unknown,
693 -- we assume in this case that the size overrides the inherited
694 -- alignment, and that the alignment must be recomputed.
696 if Known_Alignment (Typ)
697 and then not Has_Alignment_Clause (Typ)
698 and then Size mod (Alignment (Typ) * SSU) /= 0
700 Init_Alignment (Typ);
702 end Alignment_Check_For_Size_Change;
704 -------------------------------------
705 -- Analyze_Aspects_At_Freeze_Point --
706 -------------------------------------
708 procedure Analyze_Aspects_At_Freeze_Point (E : Entity_Id) is
713 procedure Analyze_Aspect_Default_Value (ASN : Node_Id);
714 -- This routine analyzes an Aspect_Default_[Component_]Value denoted by
715 -- the aspect specification node ASN.
717 procedure Inherit_Delayed_Rep_Aspects (ASN : Node_Id);
718 -- As discussed in the spec of Aspects (see Aspect_Delay declaration),
719 -- a derived type can inherit aspects from its parent which have been
720 -- specified at the time of the derivation using an aspect, as in:
722 -- type A is range 1 .. 10
723 -- with Size => Not_Defined_Yet;
727 -- Not_Defined_Yet : constant := 64;
729 -- In this example, the Size of A is considered to be specified prior
730 -- to the derivation, and thus inherited, even though the value is not
731 -- known at the time of derivation. To deal with this, we use two entity
732 -- flags. The flag Has_Derived_Rep_Aspects is set in the parent type (A
733 -- here), and then the flag May_Inherit_Delayed_Rep_Aspects is set in
734 -- the derived type (B here). If this flag is set when the derived type
735 -- is frozen, then this procedure is called to ensure proper inheritance
736 -- of all delayed aspects from the parent type. The derived type is E,
737 -- the argument to Analyze_Aspects_At_Freeze_Point. ASN is the first
738 -- aspect specification node in the Rep_Item chain for the parent type.
740 procedure Make_Pragma_From_Boolean_Aspect (ASN : Node_Id);
741 -- Given an aspect specification node ASN whose expression is an
742 -- optional Boolean, this routines creates the corresponding pragma
743 -- at the freezing point.
745 ----------------------------------
746 -- Analyze_Aspect_Default_Value --
747 ----------------------------------
749 procedure Analyze_Aspect_Default_Value (ASN : Node_Id) is
750 Ent : constant Entity_Id := Entity (ASN);
751 Expr : constant Node_Id := Expression (ASN);
752 Id : constant Node_Id := Identifier (ASN);
755 Error_Msg_Name_1 := Chars (Id);
757 if not Is_Type (Ent) then
758 Error_Msg_N ("aspect% can only apply to a type", Id);
761 elsif not Is_First_Subtype (Ent) then
762 Error_Msg_N ("aspect% cannot apply to subtype", Id);
765 elsif A_Id = Aspect_Default_Value
766 and then not Is_Scalar_Type (Ent)
768 Error_Msg_N ("aspect% can only be applied to scalar type", Id);
771 elsif A_Id = Aspect_Default_Component_Value then
772 if not Is_Array_Type (Ent) then
773 Error_Msg_N ("aspect% can only be applied to array type", Id);
776 elsif not Is_Scalar_Type (Component_Type (Ent)) then
777 Error_Msg_N ("aspect% requires scalar components", Id);
782 Set_Has_Default_Aspect (Base_Type (Ent));
784 if Is_Scalar_Type (Ent) then
785 Set_Default_Aspect_Value (Base_Type (Ent), Expr);
787 Set_Default_Aspect_Component_Value (Base_Type (Ent), Expr);
789 end Analyze_Aspect_Default_Value;
791 ---------------------------------
792 -- Inherit_Delayed_Rep_Aspects --
793 ---------------------------------
795 procedure Inherit_Delayed_Rep_Aspects (ASN : Node_Id) is
796 P : constant Entity_Id := Entity (ASN);
797 -- Entithy for parent type
800 -- Item from Rep_Item chain
805 -- Loop through delayed aspects for the parent type
808 while Present (N) loop
809 if Nkind (N) = N_Aspect_Specification then
810 exit when Entity (N) /= P;
812 if Is_Delayed_Aspect (N) then
813 A := Get_Aspect_Id (Chars (Identifier (N)));
815 -- Process delayed rep aspect. For Boolean attributes it is
816 -- not possible to cancel an attribute once set (the attempt
817 -- to use an aspect with xxx => False is an error) for a
818 -- derived type. So for those cases, we do not have to check
819 -- if a clause has been given for the derived type, since it
820 -- is harmless to set it again if it is already set.
826 when Aspect_Alignment =>
827 if not Has_Alignment_Clause (E) then
828 Set_Alignment (E, Alignment (P));
833 when Aspect_Atomic =>
834 if Is_Atomic (P) then
840 when Aspect_Atomic_Components =>
841 if Has_Atomic_Components (P) then
842 Set_Has_Atomic_Components (Base_Type (E));
847 when Aspect_Bit_Order =>
848 if Is_Record_Type (E)
849 and then No (Get_Attribute_Definition_Clause
850 (E, Attribute_Bit_Order))
851 and then Reverse_Bit_Order (P)
853 Set_Reverse_Bit_Order (Base_Type (E));
858 when Aspect_Component_Size =>
860 and then not Has_Component_Size_Clause (E)
863 (Base_Type (E), Component_Size (P));
868 when Aspect_Machine_Radix =>
869 if Is_Decimal_Fixed_Point_Type (E)
870 and then not Has_Machine_Radix_Clause (E)
872 Set_Machine_Radix_10 (E, Machine_Radix_10 (P));
875 -- Object_Size (also Size which also sets Object_Size)
877 when Aspect_Object_Size | Aspect_Size =>
878 if not Has_Size_Clause (E)
880 No (Get_Attribute_Definition_Clause
881 (E, Attribute_Object_Size))
883 Set_Esize (E, Esize (P));
889 if not Is_Packed (E) then
890 Set_Is_Packed (Base_Type (E));
892 if Is_Bit_Packed_Array (P) then
893 Set_Is_Bit_Packed_Array (Base_Type (E));
894 Set_Packed_Array_Type (E, Packed_Array_Type (P));
898 -- Scalar_Storage_Order
900 when Aspect_Scalar_Storage_Order =>
901 if (Is_Record_Type (E) or else Is_Array_Type (E))
902 and then No (Get_Attribute_Definition_Clause
903 (E, Attribute_Scalar_Storage_Order))
904 and then Reverse_Storage_Order (P)
906 Set_Reverse_Storage_Order (Base_Type (E));
912 if Is_Fixed_Point_Type (E)
913 and then not Has_Small_Clause (E)
915 Set_Small_Value (E, Small_Value (P));
920 when Aspect_Storage_Size =>
921 if (Is_Access_Type (E) or else Is_Task_Type (E))
922 and then not Has_Storage_Size_Clause (E)
924 Set_Storage_Size_Variable
925 (Base_Type (E), Storage_Size_Variable (P));
930 when Aspect_Value_Size =>
932 -- Value_Size is never inherited, it is either set by
933 -- default, or it is explicitly set for the derived
934 -- type. So nothing to do here.
940 when Aspect_Volatile =>
941 if Is_Volatile (P) then
945 -- Volatile_Components
947 when Aspect_Volatile_Components =>
948 if Has_Volatile_Components (P) then
949 Set_Has_Volatile_Components (Base_Type (E));
952 -- That should be all the Rep Aspects
955 pragma Assert (Aspect_Delay (A_Id) /= Rep_Aspect);
962 N := Next_Rep_Item (N);
964 end Inherit_Delayed_Rep_Aspects;
966 -------------------------------------
967 -- Make_Pragma_From_Boolean_Aspect --
968 -------------------------------------
970 procedure Make_Pragma_From_Boolean_Aspect (ASN : Node_Id) is
971 Ident : constant Node_Id := Identifier (ASN);
972 A_Name : constant Name_Id := Chars (Ident);
973 A_Id : constant Aspect_Id := Get_Aspect_Id (A_Name);
974 Ent : constant Entity_Id := Entity (ASN);
975 Expr : constant Node_Id := Expression (ASN);
976 Loc : constant Source_Ptr := Sloc (ASN);
980 procedure Check_False_Aspect_For_Derived_Type;
981 -- This procedure checks for the case of a false aspect for a derived
982 -- type, which improperly tries to cancel an aspect inherited from
985 -----------------------------------------
986 -- Check_False_Aspect_For_Derived_Type --
987 -----------------------------------------
989 procedure Check_False_Aspect_For_Derived_Type is
993 -- We are only checking derived types
995 if not Is_Derived_Type (E) then
999 Par := Nearest_Ancestor (E);
1002 when Aspect_Atomic | Aspect_Shared =>
1003 if not Is_Atomic (Par) then
1007 when Aspect_Atomic_Components =>
1008 if not Has_Atomic_Components (Par) then
1012 when Aspect_Discard_Names =>
1013 if not Discard_Names (Par) then
1018 if not Is_Packed (Par) then
1022 when Aspect_Unchecked_Union =>
1023 if not Is_Unchecked_Union (Par) then
1027 when Aspect_Volatile =>
1028 if not Is_Volatile (Par) then
1032 when Aspect_Volatile_Components =>
1033 if not Has_Volatile_Components (Par) then
1041 -- Fall through means we are canceling an inherited aspect
1043 Error_Msg_Name_1 := A_Name;
1045 ("derived type& inherits aspect%, cannot cancel", Expr, E);
1047 end Check_False_Aspect_For_Derived_Type;
1049 -- Start of processing for Make_Pragma_From_Boolean_Aspect
1052 -- Note that we know Expr is present, because for a missing Expr
1053 -- argument, we knew it was True and did not need to delay the
1054 -- evaluation to the freeze point.
1056 if Is_False (Static_Boolean (Expr)) then
1057 Check_False_Aspect_For_Derived_Type;
1062 Pragma_Argument_Associations => New_List (
1063 Make_Pragma_Argument_Association (Sloc (Ident),
1064 Expression => New_Occurrence_Of (Ent, Sloc (Ident)))),
1066 Pragma_Identifier =>
1067 Make_Identifier (Sloc (Ident), Chars (Ident)));
1069 Set_From_Aspect_Specification (Prag, True);
1070 Set_Corresponding_Aspect (Prag, ASN);
1071 Set_Aspect_Rep_Item (ASN, Prag);
1072 Set_Is_Delayed_Aspect (Prag);
1073 Set_Parent (Prag, ASN);
1075 end Make_Pragma_From_Boolean_Aspect;
1077 -- Start of processing for Analyze_Aspects_At_Freeze_Point
1080 -- Must be visible in current scope
1082 if not Scope_Within_Or_Same (Current_Scope, Scope (E)) then
1086 -- Look for aspect specification entries for this entity
1088 ASN := First_Rep_Item (E);
1089 while Present (ASN) loop
1090 if Nkind (ASN) = N_Aspect_Specification then
1091 exit when Entity (ASN) /= E;
1093 if Is_Delayed_Aspect (ASN) then
1094 A_Id := Get_Aspect_Id (ASN);
1098 -- For aspects whose expression is an optional Boolean, make
1099 -- the corresponding pragma at the freezing point.
1101 when Boolean_Aspects |
1102 Library_Unit_Aspects =>
1103 Make_Pragma_From_Boolean_Aspect (ASN);
1105 -- Special handling for aspects that don't correspond to
1106 -- pragmas/attributes.
1108 when Aspect_Default_Value |
1109 Aspect_Default_Component_Value =>
1110 Analyze_Aspect_Default_Value (ASN);
1112 -- Ditto for iterator aspects, because the corresponding
1113 -- attributes may not have been analyzed yet.
1115 when Aspect_Constant_Indexing |
1116 Aspect_Variable_Indexing |
1117 Aspect_Default_Iterator |
1118 Aspect_Iterator_Element =>
1119 Analyze (Expression (ASN));
1121 when Aspect_Iterable =>
1122 Validate_Iterable_Aspect (E, ASN);
1128 Ritem := Aspect_Rep_Item (ASN);
1130 if Present (Ritem) then
1136 Next_Rep_Item (ASN);
1139 -- This is where we inherit delayed rep aspects from our parent. Note
1140 -- that if we fell out of the above loop with ASN non-empty, it means
1141 -- we hit an aspect for an entity other than E, and it must be the
1142 -- type from which we were derived.
1144 if May_Inherit_Delayed_Rep_Aspects (E) then
1145 Inherit_Delayed_Rep_Aspects (ASN);
1147 end Analyze_Aspects_At_Freeze_Point;
1149 -----------------------------------
1150 -- Analyze_Aspect_Specifications --
1151 -----------------------------------
1153 procedure Analyze_Aspect_Specifications (N : Node_Id; E : Entity_Id) is
1154 procedure Decorate_Aspect_And_Pragma
1157 Delayed : Boolean := False);
1158 -- Establish the linkages between an aspect and its corresponding
1159 -- pragma. Flag Delayed should be set when both constructs are delayed.
1161 procedure Insert_Delayed_Pragma (Prag : Node_Id);
1162 -- Insert a postcondition-like pragma into the tree depending on the
1163 -- context. Prag must denote one of the following: Pre, Post, Depends,
1164 -- Global or Contract_Cases. This procedure is also used for the case
1165 -- of Attach_Handler which has similar requirements for placement.
1167 --------------------------------
1168 -- Decorate_Aspect_And_Pragma --
1169 --------------------------------
1171 procedure Decorate_Aspect_And_Pragma
1174 Delayed : Boolean := False)
1177 Set_Aspect_Rep_Item (Asp, Prag);
1178 Set_Corresponding_Aspect (Prag, Asp);
1179 Set_From_Aspect_Specification (Prag);
1180 Set_Is_Delayed_Aspect (Prag, Delayed);
1181 Set_Is_Delayed_Aspect (Asp, Delayed);
1182 Set_Parent (Prag, Asp);
1183 end Decorate_Aspect_And_Pragma;
1185 ---------------------------
1186 -- Insert_Delayed_Pragma --
1187 ---------------------------
1189 procedure Insert_Delayed_Pragma (Prag : Node_Id) is
1193 -- When the context is a library unit, the pragma is added to the
1194 -- Pragmas_After list.
1196 if Nkind (Parent (N)) = N_Compilation_Unit then
1197 Aux := Aux_Decls_Node (Parent (N));
1199 if No (Pragmas_After (Aux)) then
1200 Set_Pragmas_After (Aux, New_List);
1203 Prepend (Prag, Pragmas_After (Aux));
1205 -- Pragmas associated with subprogram bodies are inserted in the
1206 -- declarative part.
1208 elsif Nkind (N) = N_Subprogram_Body then
1209 if No (Declarations (N)) then
1210 Set_Declarations (N, New_List (Prag));
1216 -- There may be several aspects associated with the body;
1217 -- preserve the ordering of the corresponding pragmas.
1219 D := First (Declarations (N));
1220 while Present (D) loop
1221 exit when Nkind (D) /= N_Pragma
1222 or else not From_Aspect_Specification (D);
1227 Append (Prag, Declarations (N));
1229 Insert_Before (D, Prag);
1237 Insert_After (N, Prag);
1239 end Insert_Delayed_Pragma;
1247 L : constant List_Id := Aspect_Specifications (N);
1249 Ins_Node : Node_Id := N;
1250 -- Insert pragmas/attribute definition clause after this node when no
1251 -- delayed analysis is required.
1253 -- Start of processing for Analyze_Aspect_Specifications
1255 -- The general processing involves building an attribute definition
1256 -- clause or a pragma node that corresponds to the aspect. Then in order
1257 -- to delay the evaluation of this aspect to the freeze point, we attach
1258 -- the corresponding pragma/attribute definition clause to the aspect
1259 -- specification node, which is then placed in the Rep Item chain. In
1260 -- this case we mark the entity by setting the flag Has_Delayed_Aspects
1261 -- and we evaluate the rep item at the freeze point. When the aspect
1262 -- doesn't have a corresponding pragma/attribute definition clause, then
1263 -- its analysis is simply delayed at the freeze point.
1265 -- Some special cases don't require delay analysis, thus the aspect is
1266 -- analyzed right now.
1268 -- Note that there is a special handling for Pre, Post, Test_Case,
1269 -- Contract_Cases aspects. In these cases, we do not have to worry
1270 -- about delay issues, since the pragmas themselves deal with delay
1271 -- of visibility for the expression analysis. Thus, we just insert
1272 -- the pragma after the node N.
1275 pragma Assert (Present (L));
1277 -- Loop through aspects
1279 Aspect := First (L);
1280 Aspect_Loop : while Present (Aspect) loop
1281 Analyze_One_Aspect : declare
1282 Expr : constant Node_Id := Expression (Aspect);
1283 Id : constant Node_Id := Identifier (Aspect);
1284 Loc : constant Source_Ptr := Sloc (Aspect);
1285 Nam : constant Name_Id := Chars (Id);
1286 A_Id : constant Aspect_Id := Get_Aspect_Id (Nam);
1289 Delay_Required : Boolean;
1290 -- Set False if delay is not required
1292 Eloc : Source_Ptr := No_Location;
1293 -- Source location of expression, modified when we split PPC's. It
1294 -- is set below when Expr is present.
1296 procedure Analyze_Aspect_External_Or_Link_Name;
1297 -- Perform analysis of the External_Name or Link_Name aspects
1299 procedure Analyze_Aspect_Implicit_Dereference;
1300 -- Perform analysis of the Implicit_Dereference aspects
1302 procedure Make_Aitem_Pragma
1303 (Pragma_Argument_Associations : List_Id;
1304 Pragma_Name : Name_Id);
1305 -- This is a wrapper for Make_Pragma used for converting aspects
1306 -- to pragmas. It takes care of Sloc (set from Loc) and building
1307 -- the pragma identifier from the given name. In addition the
1308 -- flags Class_Present and Split_PPC are set from the aspect
1309 -- node, as well as Is_Ignored. This routine also sets the
1310 -- From_Aspect_Specification in the resulting pragma node to
1311 -- True, and sets Corresponding_Aspect to point to the aspect.
1312 -- The resulting pragma is assigned to Aitem.
1314 ------------------------------------------
1315 -- Analyze_Aspect_External_Or_Link_Name --
1316 ------------------------------------------
1318 procedure Analyze_Aspect_External_Or_Link_Name is
1320 -- Verify that there is an Import/Export aspect defined for the
1321 -- entity. The processing of that aspect in turn checks that
1322 -- there is a Convention aspect declared. The pragma is
1323 -- constructed when processing the Convention aspect.
1330 while Present (A) loop
1331 exit when Nam_In (Chars (Identifier (A)), Name_Export,
1338 ("missing Import/Export for Link/External name",
1342 end Analyze_Aspect_External_Or_Link_Name;
1344 -----------------------------------------
1345 -- Analyze_Aspect_Implicit_Dereference --
1346 -----------------------------------------
1348 procedure Analyze_Aspect_Implicit_Dereference is
1350 if not Is_Type (E) or else not Has_Discriminants (E) then
1352 ("aspect must apply to a type with discriminants", N);
1359 Disc := First_Discriminant (E);
1360 while Present (Disc) loop
1361 if Chars (Expr) = Chars (Disc)
1362 and then Ekind (Etype (Disc)) =
1363 E_Anonymous_Access_Type
1365 Set_Has_Implicit_Dereference (E);
1366 Set_Has_Implicit_Dereference (Disc);
1370 Next_Discriminant (Disc);
1373 -- Error if no proper access discriminant.
1376 ("not an access discriminant of&", Expr, E);
1379 end Analyze_Aspect_Implicit_Dereference;
1381 -----------------------
1382 -- Make_Aitem_Pragma --
1383 -----------------------
1385 procedure Make_Aitem_Pragma
1386 (Pragma_Argument_Associations : List_Id;
1387 Pragma_Name : Name_Id)
1389 Args : List_Id := Pragma_Argument_Associations;
1392 -- We should never get here if aspect was disabled
1394 pragma Assert (not Is_Disabled (Aspect));
1396 -- Certain aspects allow for an optional name or expression. Do
1397 -- not generate a pragma with empty argument association list.
1399 if No (Args) or else No (Expression (First (Args))) then
1407 Pragma_Argument_Associations => Args,
1408 Pragma_Identifier =>
1409 Make_Identifier (Sloc (Id), Pragma_Name),
1410 Class_Present => Class_Present (Aspect),
1411 Split_PPC => Split_PPC (Aspect));
1413 -- Set additional semantic fields
1415 if Is_Ignored (Aspect) then
1416 Set_Is_Ignored (Aitem);
1417 elsif Is_Checked (Aspect) then
1418 Set_Is_Checked (Aitem);
1421 Set_Corresponding_Aspect (Aitem, Aspect);
1422 Set_From_Aspect_Specification (Aitem, True);
1423 end Make_Aitem_Pragma;
1425 -- Start of processing for Analyze_One_Aspect
1428 -- Skip aspect if already analyzed (not clear if this is needed)
1430 if Analyzed (Aspect) then
1434 -- Skip looking at aspect if it is totally disabled. Just mark it
1435 -- as such for later reference in the tree. This also sets the
1436 -- Is_Ignored and Is_Checked flags appropriately.
1438 Check_Applicable_Policy (Aspect);
1440 if Is_Disabled (Aspect) then
1444 -- Set the source location of expression, used in the case of
1445 -- a failed precondition/postcondition or invariant. Note that
1446 -- the source location of the expression is not usually the best
1447 -- choice here. For example, it gets located on the last AND
1448 -- keyword in a chain of boolean expressiond AND'ed together.
1449 -- It is best to put the message on the first character of the
1450 -- assertion, which is the effect of the First_Node call here.
1452 if Present (Expr) then
1453 Eloc := Sloc (First_Node (Expr));
1456 -- Check restriction No_Implementation_Aspect_Specifications
1458 if Implementation_Defined_Aspect (A_Id) then
1460 (No_Implementation_Aspect_Specifications, Aspect);
1463 -- Check restriction No_Specification_Of_Aspect
1465 Check_Restriction_No_Specification_Of_Aspect (Aspect);
1467 -- Mark aspect analyzed (actual analysis is delayed till later)
1469 Set_Analyzed (Aspect);
1470 Set_Entity (Aspect, E);
1471 Ent := New_Occurrence_Of (E, Sloc (Id));
1473 -- Check for duplicate aspect. Note that the Comes_From_Source
1474 -- test allows duplicate Pre/Post's that we generate internally
1475 -- to escape being flagged here.
1477 if No_Duplicates_Allowed (A_Id) then
1479 while Anod /= Aspect loop
1480 if Comes_From_Source (Aspect)
1481 and then Same_Aspect (A_Id, Get_Aspect_Id (Anod))
1483 Error_Msg_Name_1 := Nam;
1484 Error_Msg_Sloc := Sloc (Anod);
1486 -- Case of same aspect specified twice
1488 if Class_Present (Anod) = Class_Present (Aspect) then
1489 if not Class_Present (Anod) then
1491 ("aspect% for & previously given#",
1495 ("aspect `%''Class` for & previously given#",
1505 -- Check some general restrictions on language defined aspects
1507 if not Implementation_Defined_Aspect (A_Id) then
1508 Error_Msg_Name_1 := Nam;
1510 -- Not allowed for renaming declarations
1512 if Nkind (N) in N_Renaming_Declaration then
1514 ("aspect % not allowed for renaming declaration",
1518 -- Not allowed for formal type declarations
1520 if Nkind (N) = N_Formal_Type_Declaration then
1522 ("aspect % not allowed for formal type declaration",
1527 -- Copy expression for later processing by the procedures
1528 -- Check_Aspect_At_[Freeze_Point | End_Of_Declarations]
1530 Set_Entity (Id, New_Copy_Tree (Expr));
1532 -- Set Delay_Required as appropriate to aspect
1534 case Aspect_Delay (A_Id) is
1535 when Always_Delay =>
1536 Delay_Required := True;
1539 Delay_Required := False;
1543 -- If expression has the form of an integer literal, then
1544 -- do not delay, since we know the value cannot change.
1545 -- This optimization catches most rep clause cases.
1547 if (Present (Expr) and then Nkind (Expr) = N_Integer_Literal)
1548 or else (A_Id in Boolean_Aspects and then No (Expr))
1550 Delay_Required := False;
1552 Delay_Required := True;
1553 Set_Has_Delayed_Rep_Aspects (E);
1557 -- Processing based on specific aspect
1561 -- No_Aspect should be impossible
1564 raise Program_Error;
1566 -- Case 1: Aspects corresponding to attribute definition
1569 when Aspect_Address |
1572 Aspect_Component_Size |
1573 Aspect_Constant_Indexing |
1574 Aspect_Default_Iterator |
1575 Aspect_Dispatching_Domain |
1576 Aspect_External_Tag |
1579 Aspect_Iterator_Element |
1580 Aspect_Machine_Radix |
1581 Aspect_Object_Size |
1584 Aspect_Scalar_Storage_Order |
1587 Aspect_Simple_Storage_Pool |
1588 Aspect_Storage_Pool |
1589 Aspect_Stream_Size |
1591 Aspect_Variable_Indexing |
1594 -- Indexing aspects apply only to tagged type
1596 if (A_Id = Aspect_Constant_Indexing
1598 A_Id = Aspect_Variable_Indexing)
1599 and then not (Is_Type (E)
1600 and then Is_Tagged_Type (E))
1602 Error_Msg_N ("indexing applies to a tagged type", N);
1606 -- For case of address aspect, we don't consider that we
1607 -- know the entity is never set in the source, since it is
1608 -- is likely aliasing is occurring.
1610 -- Note: one might think that the analysis of the resulting
1611 -- attribute definition clause would take care of that, but
1612 -- that's not the case since it won't be from source.
1614 if A_Id = Aspect_Address then
1615 Set_Never_Set_In_Source (E, False);
1618 -- Construct the attribute definition clause
1621 Make_Attribute_Definition_Clause (Loc,
1623 Chars => Chars (Id),
1624 Expression => Relocate_Node (Expr));
1626 -- If the address is specified, then we treat the entity as
1627 -- referenced, to avoid spurious warnings. This is analogous
1628 -- to what is done with an attribute definition clause, but
1629 -- here we don't want to generate a reference because this
1630 -- is the point of definition of the entity.
1632 if A_Id = Aspect_Address then
1636 -- Case 2: Aspects corresponding to pragmas
1638 -- Case 2a: Aspects corresponding to pragmas with two
1639 -- arguments, where the first argument is a local name
1640 -- referring to the entity, and the second argument is the
1641 -- aspect definition expression.
1643 -- Linker_Section/Suppress/Unsuppress
1645 when Aspect_Linker_Section |
1647 Aspect_Unsuppress =>
1650 (Pragma_Argument_Associations => New_List (
1651 Make_Pragma_Argument_Association (Loc,
1652 Expression => New_Occurrence_Of (E, Loc)),
1653 Make_Pragma_Argument_Association (Sloc (Expr),
1654 Expression => Relocate_Node (Expr))),
1655 Pragma_Name => Chars (Id));
1659 -- Corresponds to pragma Implemented, construct the pragma
1661 when Aspect_Synchronization =>
1664 (Pragma_Argument_Associations => New_List (
1665 Make_Pragma_Argument_Association (Loc,
1666 Expression => New_Occurrence_Of (E, Loc)),
1667 Make_Pragma_Argument_Association (Sloc (Expr),
1668 Expression => Relocate_Node (Expr))),
1669 Pragma_Name => Name_Implemented);
1673 when Aspect_Attach_Handler =>
1675 (Pragma_Argument_Associations => New_List (
1676 Make_Pragma_Argument_Association (Sloc (Ent),
1678 Make_Pragma_Argument_Association (Sloc (Expr),
1679 Expression => Relocate_Node (Expr))),
1680 Pragma_Name => Name_Attach_Handler);
1682 -- We need to insert this pragma into the tree to get proper
1683 -- processing and to look valid from a placement viewpoint.
1685 Insert_Delayed_Pragma (Aitem);
1688 -- Dynamic_Predicate, Predicate, Static_Predicate
1690 when Aspect_Dynamic_Predicate |
1692 Aspect_Static_Predicate =>
1694 -- Construct the pragma (always a pragma Predicate, with
1695 -- flags recording whether it is static/dynamic). We also
1696 -- set flags recording this in the type itself.
1699 (Pragma_Argument_Associations => New_List (
1700 Make_Pragma_Argument_Association (Sloc (Ent),
1702 Make_Pragma_Argument_Association (Sloc (Expr),
1703 Expression => Relocate_Node (Expr))),
1704 Pragma_Name => Name_Predicate);
1706 -- Mark type has predicates, and remember what kind of
1707 -- aspect lead to this predicate (we need this to access
1708 -- the right set of check policies later on).
1710 Set_Has_Predicates (E);
1712 if A_Id = Aspect_Dynamic_Predicate then
1713 Set_Has_Dynamic_Predicate_Aspect (E);
1714 elsif A_Id = Aspect_Static_Predicate then
1715 Set_Has_Static_Predicate_Aspect (E);
1718 -- If the type is private, indicate that its completion
1719 -- has a freeze node, because that is the one that will
1720 -- be visible at freeze time.
1722 if Is_Private_Type (E) and then Present (Full_View (E)) then
1723 Set_Has_Predicates (Full_View (E));
1725 if A_Id = Aspect_Dynamic_Predicate then
1726 Set_Has_Dynamic_Predicate_Aspect (Full_View (E));
1727 elsif A_Id = Aspect_Static_Predicate then
1728 Set_Has_Static_Predicate_Aspect (Full_View (E));
1731 Set_Has_Delayed_Aspects (Full_View (E));
1732 Ensure_Freeze_Node (Full_View (E));
1735 -- Case 2b: Aspects corresponding to pragmas with two
1736 -- arguments, where the second argument is a local name
1737 -- referring to the entity, and the first argument is the
1738 -- aspect definition expression.
1742 when Aspect_Convention =>
1744 -- The aspect may be part of the specification of an import
1745 -- or export pragma. Scan the aspect list to gather the
1746 -- other components, if any. The name of the generated
1747 -- pragma is one of Convention/Import/Export.
1759 P_Name := Chars (Id);
1761 Arg_List := New_List;
1766 while Present (A) loop
1767 A_Name := Chars (Identifier (A));
1769 if Nam_In (A_Name, Name_Import, Name_Export) then
1771 Error_Msg_N ("conflicting", A);
1778 elsif A_Name = Name_Link_Name then
1780 Make_Pragma_Argument_Association (Loc,
1782 Expression => Relocate_Node (Expression (A)));
1784 elsif A_Name = Name_External_Name then
1786 Make_Pragma_Argument_Association (Loc,
1788 Expression => Relocate_Node (Expression (A)));
1794 Arg_List := New_List (
1795 Make_Pragma_Argument_Association (Sloc (Expr),
1796 Expression => Relocate_Node (Expr)),
1797 Make_Pragma_Argument_Association (Sloc (Ent),
1798 Expression => Ent));
1800 if Present (L_Assoc) then
1801 Append_To (Arg_List, L_Assoc);
1804 if Present (E_Assoc) then
1805 Append_To (Arg_List, E_Assoc);
1809 (Pragma_Argument_Associations => Arg_List,
1810 Pragma_Name => P_Name);
1813 -- CPU, Interrupt_Priority, Priority
1815 -- These three aspects can be specified for a subprogram spec
1816 -- or body, in which case we analyze the expression and export
1817 -- the value of the aspect.
1819 -- Previously, we generated an equivalent pragma for bodies
1820 -- (note that the specs cannot contain these pragmas). The
1821 -- pragma was inserted ahead of local declarations, rather than
1822 -- after the body. This leads to a certain duplication between
1823 -- the processing performed for the aspect and the pragma, but
1824 -- given the straightforward handling required it is simpler
1825 -- to duplicate than to translate the aspect in the spec into
1826 -- a pragma in the declarative part of the body.
1829 Aspect_Interrupt_Priority |
1832 if Nkind_In (N, N_Subprogram_Body,
1833 N_Subprogram_Declaration)
1835 -- Analyze the aspect expression
1837 Analyze_And_Resolve (Expr, Standard_Integer);
1839 -- Interrupt_Priority aspect not allowed for main
1840 -- subprograms. ARM D.1 does not forbid this explicitly,
1841 -- but ARM J.15.11 (6/3) does not permit pragma
1842 -- Interrupt_Priority for subprograms.
1844 if A_Id = Aspect_Interrupt_Priority then
1846 ("Interrupt_Priority aspect cannot apply to "
1847 & "subprogram", Expr);
1849 -- The expression must be static
1851 elsif not Is_Static_Expression (Expr) then
1852 Flag_Non_Static_Expr
1853 ("aspect requires static expression!", Expr);
1855 -- Check whether this is the main subprogram. Issue a
1856 -- warning only if it is obviously not a main program
1857 -- (when it has parameters or when the subprogram is
1858 -- within a package).
1860 elsif Present (Parameter_Specifications
1861 (Specification (N)))
1862 or else not Is_Compilation_Unit (Defining_Entity (N))
1864 -- See ARM D.1 (14/3) and D.16 (12/3)
1867 ("aspect applied to subprogram other than the "
1868 & "main subprogram has no effect??", Expr);
1870 -- Otherwise check in range and export the value
1872 -- For the CPU aspect
1874 elsif A_Id = Aspect_CPU then
1875 if Is_In_Range (Expr, RTE (RE_CPU_Range)) then
1877 -- Value is correct so we export the value to make
1878 -- it available at execution time.
1881 (Main_Unit, UI_To_Int (Expr_Value (Expr)));
1885 ("main subprogram CPU is out of range", Expr);
1888 -- For the Priority aspect
1890 elsif A_Id = Aspect_Priority then
1891 if Is_In_Range (Expr, RTE (RE_Priority)) then
1893 -- Value is correct so we export the value to make
1894 -- it available at execution time.
1897 (Main_Unit, UI_To_Int (Expr_Value (Expr)));
1899 -- Ignore pragma if Relaxed_RM_Semantics to support
1900 -- other targets/non GNAT compilers.
1902 elsif not Relaxed_RM_Semantics then
1904 ("main subprogram priority is out of range",
1909 -- Load an arbitrary entity from System.Tasking.Stages
1910 -- or System.Tasking.Restricted.Stages (depending on
1911 -- the supported profile) to make sure that one of these
1912 -- packages is implicitly with'ed, since we need to have
1913 -- the tasking run time active for the pragma Priority to
1914 -- have any effect. Previously with with'ed the package
1915 -- System.Tasking, but this package does not trigger the
1916 -- required initialization of the run-time library.
1919 Discard : Entity_Id;
1920 pragma Warnings (Off, Discard);
1922 if Restricted_Profile then
1923 Discard := RTE (RE_Activate_Restricted_Tasks);
1925 Discard := RTE (RE_Activate_Tasks);
1929 -- Handling for these Aspects in subprograms is complete
1936 -- Pass the aspect as an attribute
1939 Make_Attribute_Definition_Clause (Loc,
1941 Chars => Chars (Id),
1942 Expression => Relocate_Node (Expr));
1947 when Aspect_Warnings =>
1949 (Pragma_Argument_Associations => New_List (
1950 Make_Pragma_Argument_Association (Sloc (Expr),
1951 Expression => Relocate_Node (Expr)),
1952 Make_Pragma_Argument_Association (Loc,
1953 Expression => New_Occurrence_Of (E, Loc))),
1954 Pragma_Name => Chars (Id));
1956 -- Case 2c: Aspects corresponding to pragmas with three
1959 -- Invariant aspects have a first argument that references the
1960 -- entity, a second argument that is the expression and a third
1961 -- argument that is an appropriate message.
1963 -- Invariant, Type_Invariant
1965 when Aspect_Invariant |
1966 Aspect_Type_Invariant =>
1968 -- Analysis of the pragma will verify placement legality:
1969 -- an invariant must apply to a private type, or appear in
1970 -- the private part of a spec and apply to a completion.
1973 (Pragma_Argument_Associations => New_List (
1974 Make_Pragma_Argument_Association (Sloc (Ent),
1976 Make_Pragma_Argument_Association (Sloc (Expr),
1977 Expression => Relocate_Node (Expr))),
1978 Pragma_Name => Name_Invariant);
1980 -- Add message unless exception messages are suppressed
1982 if not Opt.Exception_Locations_Suppressed then
1983 Append_To (Pragma_Argument_Associations (Aitem),
1984 Make_Pragma_Argument_Association (Eloc,
1985 Chars => Name_Message,
1987 Make_String_Literal (Eloc,
1988 Strval => "failed invariant from "
1989 & Build_Location_String (Eloc))));
1992 -- For Invariant case, insert immediately after the entity
1993 -- declaration. We do not have to worry about delay issues
1994 -- since the pragma processing takes care of this.
1996 Delay_Required := False;
1998 -- Case 2d : Aspects that correspond to a pragma with one
2003 -- Aspect Abstract_State introduces implicit declarations for
2004 -- all state abstraction entities it defines. To emulate this
2005 -- behavior, insert the pragma at the beginning of the visible
2006 -- declarations of the related package so that it is analyzed
2009 when Aspect_Abstract_State => Abstract_State : declare
2010 Context : Node_Id := N;
2015 -- When aspect Abstract_State appears on a generic package,
2016 -- it is propageted to the package instance. The context in
2017 -- this case is the instance spec.
2019 if Nkind (Context) = N_Package_Instantiation then
2020 Context := Instance_Spec (Context);
2023 if Nkind_In (Context, N_Generic_Package_Declaration,
2024 N_Package_Declaration)
2027 (Pragma_Argument_Associations => New_List (
2028 Make_Pragma_Argument_Association (Loc,
2029 Expression => Relocate_Node (Expr))),
2030 Pragma_Name => Name_Abstract_State);
2031 Decorate_Aspect_And_Pragma (Aspect, Aitem);
2033 Decls := Visible_Declarations (Specification (Context));
2035 -- In general pragma Abstract_State must be at the top
2036 -- of the existing visible declarations to emulate its
2037 -- source counterpart. The only exception to this is a
2038 -- generic instance in which case the pragma must be
2039 -- inserted after the association renamings.
2041 if Present (Decls) then
2043 -- The visible declarations of a generic instance have
2044 -- the following structure:
2046 -- <renamings of generic formals>
2047 -- <renamings of internally-generated spec and body>
2048 -- <first source declaration>
2050 -- The pragma must be inserted before the first source
2053 if Is_Generic_Instance (Defining_Entity (Context)) then
2055 -- Skip the instance "header"
2057 Decl := First (Decls);
2058 while Present (Decl)
2059 and then not Comes_From_Source (Decl)
2061 Decl := Next (Decl);
2064 if Present (Decl) then
2065 Insert_Before (Decl, Aitem);
2067 Append_To (Decls, Aitem);
2070 -- The related package is not a generic instance, the
2071 -- corresponding pragma must be the first declaration.
2074 Prepend_To (Decls, Aitem);
2077 -- Otherwise the pragma forms a new declarative list
2080 Set_Visible_Declarations
2081 (Specification (Context), New_List (Aitem));
2086 ("aspect & must apply to a package declaration",
2095 -- Aspect Depends must be delayed because it mentions names
2096 -- of inputs and output that are classified by aspect Global.
2097 -- The aspect and pragma are treated the same way as a post
2100 when Aspect_Depends =>
2102 (Pragma_Argument_Associations => New_List (
2103 Make_Pragma_Argument_Association (Loc,
2104 Expression => Relocate_Node (Expr))),
2105 Pragma_Name => Name_Depends);
2107 Decorate_Aspect_And_Pragma
2108 (Aspect, Aitem, Delayed => True);
2109 Insert_Delayed_Pragma (Aitem);
2114 -- Aspect Global must be delayed because it can mention names
2115 -- and benefit from the forward visibility rules applicable to
2116 -- aspects of subprograms. The aspect and pragma are treated
2117 -- the same way as a post condition.
2119 when Aspect_Global =>
2121 (Pragma_Argument_Associations => New_List (
2122 Make_Pragma_Argument_Association (Loc,
2123 Expression => Relocate_Node (Expr))),
2124 Pragma_Name => Name_Global);
2126 Decorate_Aspect_And_Pragma
2127 (Aspect, Aitem, Delayed => True);
2128 Insert_Delayed_Pragma (Aitem);
2131 -- Initial_Condition
2133 -- Aspect Initial_Condition covers the visible declarations of
2134 -- a package and all hidden states through functions. As such,
2135 -- it must be evaluated at the end of the said declarations.
2137 when Aspect_Initial_Condition => Initial_Condition : declare
2138 Context : Node_Id := N;
2142 -- When aspect Abstract_State appears on a generic package,
2143 -- it is propageted to the package instance. The context in
2144 -- this case is the instance spec.
2146 if Nkind (Context) = N_Package_Instantiation then
2147 Context := Instance_Spec (Context);
2150 if Nkind_In (Context, N_Generic_Package_Declaration,
2151 N_Package_Declaration)
2153 Decls := Visible_Declarations (Specification (Context));
2156 (Pragma_Argument_Associations => New_List (
2157 Make_Pragma_Argument_Association (Loc,
2158 Expression => Relocate_Node (Expr))),
2160 Name_Initial_Condition);
2162 Decorate_Aspect_And_Pragma
2163 (Aspect, Aitem, Delayed => True);
2167 Set_Visible_Declarations (Context, Decls);
2170 Prepend_To (Decls, Aitem);
2174 ("aspect & must apply to a package declaration",
2179 end Initial_Condition;
2183 -- Aspect Initializes coverts the visible declarations of a
2184 -- package. As such, it must be evaluated at the end of the
2185 -- said declarations.
2187 when Aspect_Initializes => Initializes : declare
2188 Context : Node_Id := N;
2192 -- When aspect Abstract_State appears on a generic package,
2193 -- it is propageted to the package instance. The context in
2194 -- this case is the instance spec.
2196 if Nkind (Context) = N_Package_Instantiation then
2197 Context := Instance_Spec (Context);
2200 if Nkind_In (Context, N_Generic_Package_Declaration,
2201 N_Package_Declaration)
2203 Decls := Visible_Declarations (Specification (Context));
2206 (Pragma_Argument_Associations => New_List (
2207 Make_Pragma_Argument_Association (Loc,
2208 Expression => Relocate_Node (Expr))),
2209 Pragma_Name => Name_Initializes);
2211 Decorate_Aspect_And_Pragma
2212 (Aspect, Aitem, Delayed => True);
2216 Set_Visible_Declarations (Context, Decls);
2219 Prepend_To (Decls, Aitem);
2223 ("aspect & must apply to a package declaration",
2232 when Aspect_Part_Of =>
2233 if Nkind_In (N, N_Object_Declaration,
2234 N_Package_Instantiation)
2237 (Pragma_Argument_Associations => New_List (
2238 Make_Pragma_Argument_Association (Loc,
2239 Expression => Relocate_Node (Expr))),
2240 Pragma_Name => Name_Part_Of);
2244 ("aspect & must apply to a variable or package "
2245 & "instantiation", Aspect, Id);
2250 when Aspect_SPARK_Mode => SPARK_Mode : declare
2255 (Pragma_Argument_Associations => New_List (
2256 Make_Pragma_Argument_Association (Loc,
2257 Expression => Relocate_Node (Expr))),
2258 Pragma_Name => Name_SPARK_Mode);
2260 -- When the aspect appears on a package body, insert the
2261 -- generated pragma at the top of the body declarations to
2262 -- emulate the behavior of a source pragma.
2264 if Nkind (N) = N_Package_Body then
2265 Decorate_Aspect_And_Pragma (Aspect, Aitem);
2267 Decls := Declarations (N);
2271 Set_Declarations (N, Decls);
2274 Prepend_To (Decls, Aitem);
2277 -- When the aspect is associated with package declaration,
2278 -- insert the generated pragma at the top of the visible
2279 -- declarations to emulate the behavior of a source pragma.
2281 elsif Nkind (N) = N_Package_Declaration then
2282 Decorate_Aspect_And_Pragma (Aspect, Aitem);
2284 Decls := Visible_Declarations (Specification (N));
2288 Set_Visible_Declarations (Specification (N), Decls);
2291 Prepend_To (Decls, Aitem);
2298 -- Aspect Refined_Depends must be delayed because it can
2299 -- mention state refinements introduced by aspect Refined_State
2300 -- and further classified by aspect Refined_Global. Since both
2301 -- those aspects are delayed, so is Refined_Depends.
2303 when Aspect_Refined_Depends =>
2305 (Pragma_Argument_Associations => New_List (
2306 Make_Pragma_Argument_Association (Loc,
2307 Expression => Relocate_Node (Expr))),
2308 Pragma_Name => Name_Refined_Depends);
2310 Decorate_Aspect_And_Pragma
2311 (Aspect, Aitem, Delayed => True);
2312 Insert_Delayed_Pragma (Aitem);
2317 -- Aspect Refined_Global must be delayed because it can mention
2318 -- state refinements introduced by aspect Refined_State. Since
2319 -- Refined_State is already delayed due to forward references,
2320 -- so is Refined_Global.
2322 when Aspect_Refined_Global =>
2324 (Pragma_Argument_Associations => New_List (
2325 Make_Pragma_Argument_Association (Loc,
2326 Expression => Relocate_Node (Expr))),
2327 Pragma_Name => Name_Refined_Global);
2329 Decorate_Aspect_And_Pragma (Aspect, Aitem, Delayed => True);
2330 Insert_Delayed_Pragma (Aitem);
2335 when Aspect_Refined_Post =>
2337 (Pragma_Argument_Associations => New_List (
2338 Make_Pragma_Argument_Association (Loc,
2339 Expression => Relocate_Node (Expr))),
2340 Pragma_Name => Name_Refined_Post);
2344 when Aspect_Refined_State => Refined_State : declare
2349 -- The corresponding pragma for Refined_State is inserted in
2350 -- the declarations of the related package body. This action
2351 -- synchronizes both the source and from-aspect versions of
2354 if Nkind (N) = N_Package_Body then
2356 (Pragma_Argument_Associations => New_List (
2357 Make_Pragma_Argument_Association (Loc,
2358 Expression => Relocate_Node (Expr))),
2359 Pragma_Name => Name_Refined_State);
2360 Decorate_Aspect_And_Pragma (Aspect, Aitem);
2362 Decls := Declarations (N);
2364 -- When the package body is subject to pragma SPARK_Mode,
2365 -- insert pragma Refined_State after SPARK_Mode.
2367 if Present (Decls) then
2368 Decl := First (Decls);
2370 if Nkind (Decl) = N_Pragma
2371 and then Pragma_Name (Decl) = Name_SPARK_Mode
2373 Insert_After (Decl, Aitem);
2375 -- The related package body lacks SPARK_Mode, the
2376 -- corresponding pragma must be the first declaration.
2379 Prepend_To (Decls, Aitem);
2382 -- Otherwise the pragma forms a new declarative list
2385 Set_Declarations (N, New_List (Aitem));
2390 ("aspect & must apply to a package body", Aspect, Id);
2396 -- Relative_Deadline
2398 when Aspect_Relative_Deadline =>
2400 (Pragma_Argument_Associations => New_List (
2401 Make_Pragma_Argument_Association (Loc,
2402 Expression => Relocate_Node (Expr))),
2403 Pragma_Name => Name_Relative_Deadline);
2405 -- If the aspect applies to a task, the corresponding pragma
2406 -- must appear within its declarations, not after.
2408 if Nkind (N) = N_Task_Type_Declaration then
2414 if No (Task_Definition (N)) then
2415 Set_Task_Definition (N,
2416 Make_Task_Definition (Loc,
2417 Visible_Declarations => New_List,
2418 End_Label => Empty));
2421 Def := Task_Definition (N);
2422 V := Visible_Declarations (Def);
2423 if not Is_Empty_List (V) then
2424 Insert_Before (First (V), Aitem);
2427 Set_Visible_Declarations (Def, New_List (Aitem));
2434 -- Case 3 : Aspects that don't correspond to pragma/attribute
2435 -- definition clause.
2437 -- Case 3a: The aspects listed below don't correspond to
2438 -- pragmas/attributes but do require delayed analysis.
2440 -- Default_Value, Default_Component_Value
2442 when Aspect_Default_Value |
2443 Aspect_Default_Component_Value =>
2446 -- Case 3b: The aspects listed below don't correspond to
2447 -- pragmas/attributes and don't need delayed analysis.
2449 -- Implicit_Dereference
2451 -- For Implicit_Dereference, External_Name and Link_Name, only
2452 -- the legality checks are done during the analysis, thus no
2453 -- delay is required.
2455 when Aspect_Implicit_Dereference =>
2456 Analyze_Aspect_Implicit_Dereference;
2459 -- External_Name, Link_Name
2461 when Aspect_External_Name |
2463 Analyze_Aspect_External_Or_Link_Name;
2468 when Aspect_Dimension =>
2469 Analyze_Aspect_Dimension (N, Id, Expr);
2474 when Aspect_Dimension_System =>
2475 Analyze_Aspect_Dimension_System (N, Id, Expr);
2478 -- Case 4: Aspects requiring special handling
2480 -- Pre/Post/Test_Case/Contract_Cases whose corresponding
2481 -- pragmas take care of the delay.
2485 -- Aspects Pre/Post generate Precondition/Postcondition pragmas
2486 -- with a first argument that is the expression, and a second
2487 -- argument that is an informative message if the test fails.
2488 -- This is inserted right after the declaration, to get the
2489 -- required pragma placement. The processing for the pragmas
2490 -- takes care of the required delay.
2492 when Pre_Post_Aspects => Pre_Post : declare
2496 if A_Id = Aspect_Pre or else A_Id = Aspect_Precondition then
2497 Pname := Name_Precondition;
2499 Pname := Name_Postcondition;
2502 -- If the expressions is of the form A and then B, then
2503 -- we generate separate Pre/Post aspects for the separate
2504 -- clauses. Since we allow multiple pragmas, there is no
2505 -- problem in allowing multiple Pre/Post aspects internally.
2506 -- These should be treated in reverse order (B first and
2507 -- A second) since they are later inserted just after N in
2508 -- the order they are treated. This way, the pragma for A
2509 -- ends up preceding the pragma for B, which may have an
2510 -- importance for the error raised (either constraint error
2511 -- or precondition error).
2513 -- We do not do this for Pre'Class, since we have to put
2514 -- these conditions together in a complex OR expression
2516 -- We do not do this in ASIS mode, as ASIS relies on the
2517 -- original node representing the complete expression, when
2518 -- retrieving it through the source aspect table.
2521 and then (Pname = Name_Postcondition
2522 or else not Class_Present (Aspect))
2524 while Nkind (Expr) = N_And_Then loop
2525 Insert_After (Aspect,
2526 Make_Aspect_Specification (Sloc (Left_Opnd (Expr)),
2527 Identifier => Identifier (Aspect),
2528 Expression => Relocate_Node (Left_Opnd (Expr)),
2529 Class_Present => Class_Present (Aspect),
2530 Split_PPC => True));
2531 Rewrite (Expr, Relocate_Node (Right_Opnd (Expr)));
2532 Eloc := Sloc (Expr);
2536 -- Build the precondition/postcondition pragma
2538 -- Add note about why we do NOT need Copy_Tree here ???
2541 (Pragma_Argument_Associations => New_List (
2542 Make_Pragma_Argument_Association (Eloc,
2543 Chars => Name_Check,
2544 Expression => Relocate_Node (Expr))),
2545 Pragma_Name => Pname);
2547 -- Add message unless exception messages are suppressed
2549 if not Opt.Exception_Locations_Suppressed then
2550 Append_To (Pragma_Argument_Associations (Aitem),
2551 Make_Pragma_Argument_Association (Eloc,
2552 Chars => Name_Message,
2554 Make_String_Literal (Eloc,
2556 & Get_Name_String (Pname)
2558 & Build_Location_String (Eloc))));
2561 Set_Is_Delayed_Aspect (Aspect);
2563 -- For Pre/Post cases, insert immediately after the entity
2564 -- declaration, since that is the required pragma placement.
2565 -- Note that for these aspects, we do not have to worry
2566 -- about delay issues, since the pragmas themselves deal
2567 -- with delay of visibility for the expression analysis.
2569 Insert_Delayed_Pragma (Aitem);
2575 when Aspect_Test_Case => Test_Case : declare
2577 Comp_Expr : Node_Id;
2578 Comp_Assn : Node_Id;
2584 if Nkind (Parent (N)) = N_Compilation_Unit then
2585 Error_Msg_Name_1 := Nam;
2586 Error_Msg_N ("incorrect placement of aspect `%`", E);
2590 if Nkind (Expr) /= N_Aggregate then
2591 Error_Msg_Name_1 := Nam;
2593 ("wrong syntax for aspect `%` for &", Id, E);
2597 -- Make pragma expressions refer to the original aspect
2598 -- expressions through the Original_Node link. This is
2599 -- used in semantic analysis for ASIS mode, so that the
2600 -- original expression also gets analyzed.
2602 Comp_Expr := First (Expressions (Expr));
2603 while Present (Comp_Expr) loop
2604 New_Expr := Relocate_Node (Comp_Expr);
2605 Set_Original_Node (New_Expr, Comp_Expr);
2607 Make_Pragma_Argument_Association (Sloc (Comp_Expr),
2608 Expression => New_Expr));
2612 Comp_Assn := First (Component_Associations (Expr));
2613 while Present (Comp_Assn) loop
2614 if List_Length (Choices (Comp_Assn)) /= 1
2616 Nkind (First (Choices (Comp_Assn))) /= N_Identifier
2618 Error_Msg_Name_1 := Nam;
2620 ("wrong syntax for aspect `%` for &", Id, E);
2624 New_Expr := Relocate_Node (Expression (Comp_Assn));
2625 Set_Original_Node (New_Expr, Expression (Comp_Assn));
2627 Make_Pragma_Argument_Association (Sloc (Comp_Assn),
2628 Chars => Chars (First (Choices (Comp_Assn))),
2629 Expression => New_Expr));
2633 -- Build the test-case pragma
2636 (Pragma_Argument_Associations => Args,
2637 Pragma_Name => Nam);
2642 when Aspect_Contract_Cases =>
2644 (Pragma_Argument_Associations => New_List (
2645 Make_Pragma_Argument_Association (Loc,
2646 Expression => Relocate_Node (Expr))),
2647 Pragma_Name => Nam);
2649 Decorate_Aspect_And_Pragma
2650 (Aspect, Aitem, Delayed => True);
2651 Insert_Delayed_Pragma (Aitem);
2654 -- Case 5: Special handling for aspects with an optional
2655 -- boolean argument.
2657 -- In the general case, the corresponding pragma cannot be
2658 -- generated yet because the evaluation of the boolean needs
2659 -- to be delayed till the freeze point.
2661 when Boolean_Aspects |
2662 Library_Unit_Aspects =>
2664 Set_Is_Boolean_Aspect (Aspect);
2666 -- Lock_Free aspect only apply to protected objects
2668 if A_Id = Aspect_Lock_Free then
2669 if Ekind (E) /= E_Protected_Type then
2670 Error_Msg_Name_1 := Nam;
2672 ("aspect % only applies to a protected object",
2676 -- Set the Uses_Lock_Free flag to True if there is no
2677 -- expression or if the expression is True. The
2678 -- evaluation of this aspect should be delayed to the
2679 -- freeze point (why???)
2682 or else Is_True (Static_Boolean (Expr))
2684 Set_Uses_Lock_Free (E);
2687 Record_Rep_Item (E, Aspect);
2692 elsif A_Id = Aspect_Import or else A_Id = Aspect_Export then
2694 -- Verify that there is an aspect Convention that will
2695 -- incorporate the Import/Export aspect, and eventual
2696 -- Link/External names.
2703 while Present (A) loop
2704 exit when Chars (Identifier (A)) = Name_Convention;
2708 -- It is legal to specify Import for a variable, in
2709 -- order to suppress initialization for it, without
2710 -- specifying explicitly its convention. However this
2711 -- is only legal if the convention of the object type
2712 -- is Ada or similar.
2715 if Ekind (E) = E_Variable
2716 and then A_Id = Aspect_Import
2719 C : constant Convention_Id :=
2720 Convention (Etype (E));
2722 if C = Convention_Ada or else
2723 C = Convention_Ada_Pass_By_Copy or else
2724 C = Convention_Ada_Pass_By_Reference
2731 -- Otherwise, Convention must be specified
2734 ("missing Convention aspect for Export/Import",
2742 -- Library unit aspects require special handling in the case
2743 -- of a package declaration, the pragma needs to be inserted
2744 -- in the list of declarations for the associated package.
2745 -- There is no issue of visibility delay for these aspects.
2747 if A_Id in Library_Unit_Aspects
2749 Nkind_In (N, N_Package_Declaration,
2750 N_Generic_Package_Declaration)
2751 and then Nkind (Parent (N)) /= N_Compilation_Unit
2754 ("incorrect context for library unit aspect&", Id);
2758 -- Cases where we do not delay, includes all cases where
2759 -- the expression is missing other than the above cases.
2761 if not Delay_Required or else No (Expr) then
2763 (Pragma_Argument_Associations => New_List (
2764 Make_Pragma_Argument_Association (Sloc (Ent),
2765 Expression => Ent)),
2766 Pragma_Name => Chars (Id));
2767 Delay_Required := False;
2769 -- In general cases, the corresponding pragma/attribute
2770 -- definition clause will be inserted later at the freezing
2771 -- point, and we do not need to build it now
2779 -- This is special because for access types we need to generate
2780 -- an attribute definition clause. This also works for single
2781 -- task declarations, but it does not work for task type
2782 -- declarations, because we have the case where the expression
2783 -- references a discriminant of the task type. That can't use
2784 -- an attribute definition clause because we would not have
2785 -- visibility on the discriminant. For that case we must
2786 -- generate a pragma in the task definition.
2788 when Aspect_Storage_Size =>
2792 if Ekind (E) = E_Task_Type then
2794 Decl : constant Node_Id := Declaration_Node (E);
2797 pragma Assert (Nkind (Decl) = N_Task_Type_Declaration);
2799 -- If no task definition, create one
2801 if No (Task_Definition (Decl)) then
2802 Set_Task_Definition (Decl,
2803 Make_Task_Definition (Loc,
2804 Visible_Declarations => Empty_List,
2805 End_Label => Empty));
2808 -- Create a pragma and put it at the start of the
2809 -- task definition for the task type declaration.
2812 (Pragma_Argument_Associations => New_List (
2813 Make_Pragma_Argument_Association (Loc,
2814 Expression => Relocate_Node (Expr))),
2815 Pragma_Name => Name_Storage_Size);
2819 Visible_Declarations (Task_Definition (Decl)));
2823 -- All other cases, generate attribute definition
2827 Make_Attribute_Definition_Clause (Loc,
2829 Chars => Chars (Id),
2830 Expression => Relocate_Node (Expr));
2834 -- Attach the corresponding pragma/attribute definition clause to
2835 -- the aspect specification node.
2837 if Present (Aitem) then
2838 Set_From_Aspect_Specification (Aitem, True);
2841 -- In the context of a compilation unit, we directly put the
2842 -- pragma in the Pragmas_After list of the N_Compilation_Unit_Aux
2843 -- node (no delay is required here) except for aspects on a
2844 -- subprogram body (see below) and a generic package, for which
2845 -- we need to introduce the pragma before building the generic
2846 -- copy (see sem_ch12), and for package instantiations, where
2847 -- the library unit pragmas are better handled early.
2849 if Nkind (Parent (N)) = N_Compilation_Unit
2850 and then (Present (Aitem) or else Is_Boolean_Aspect (Aspect))
2853 Aux : constant Node_Id := Aux_Decls_Node (Parent (N));
2856 pragma Assert (Nkind (Aux) = N_Compilation_Unit_Aux);
2858 -- For a Boolean aspect, create the corresponding pragma if
2859 -- no expression or if the value is True.
2861 if Is_Boolean_Aspect (Aspect) and then No (Aitem) then
2862 if Is_True (Static_Boolean (Expr)) then
2864 (Pragma_Argument_Associations => New_List (
2865 Make_Pragma_Argument_Association (Sloc (Ent),
2866 Expression => Ent)),
2867 Pragma_Name => Chars (Id));
2869 Set_From_Aspect_Specification (Aitem, True);
2870 Set_Corresponding_Aspect (Aitem, Aspect);
2877 -- If the aspect is on a subprogram body (relevant aspect
2878 -- is Inline), add the pragma in front of the declarations.
2880 if Nkind (N) = N_Subprogram_Body then
2881 if No (Declarations (N)) then
2882 Set_Declarations (N, New_List);
2885 Prepend (Aitem, Declarations (N));
2887 elsif Nkind (N) = N_Generic_Package_Declaration then
2888 if No (Visible_Declarations (Specification (N))) then
2889 Set_Visible_Declarations (Specification (N), New_List);
2893 Visible_Declarations (Specification (N)));
2895 elsif Nkind (N) = N_Package_Instantiation then
2897 Spec : constant Node_Id :=
2898 Specification (Instance_Spec (N));
2900 if No (Visible_Declarations (Spec)) then
2901 Set_Visible_Declarations (Spec, New_List);
2904 Prepend (Aitem, Visible_Declarations (Spec));
2908 if No (Pragmas_After (Aux)) then
2909 Set_Pragmas_After (Aux, New_List);
2912 Append (Aitem, Pragmas_After (Aux));
2919 -- The evaluation of the aspect is delayed to the freezing point.
2920 -- The pragma or attribute clause if there is one is then attached
2921 -- to the aspect specification which is put in the rep item list.
2923 if Delay_Required then
2924 if Present (Aitem) then
2925 Set_Is_Delayed_Aspect (Aitem);
2926 Set_Aspect_Rep_Item (Aspect, Aitem);
2927 Set_Parent (Aitem, Aspect);
2930 Set_Is_Delayed_Aspect (Aspect);
2932 -- In the case of Default_Value, link the aspect to base type
2933 -- as well, even though it appears on a first subtype. This is
2934 -- mandated by the semantics of the aspect. Do not establish
2935 -- the link when processing the base type itself as this leads
2936 -- to a rep item circularity. Verify that we are dealing with
2937 -- a scalar type to prevent cascaded errors.
2939 if A_Id = Aspect_Default_Value
2940 and then Is_Scalar_Type (E)
2941 and then Base_Type (E) /= E
2943 Set_Has_Delayed_Aspects (Base_Type (E));
2944 Record_Rep_Item (Base_Type (E), Aspect);
2947 Set_Has_Delayed_Aspects (E);
2948 Record_Rep_Item (E, Aspect);
2950 -- When delay is not required and the context is a package or a
2951 -- subprogram body, insert the pragma in the body declarations.
2953 elsif Nkind_In (N, N_Package_Body, N_Subprogram_Body) then
2954 if No (Declarations (N)) then
2955 Set_Declarations (N, New_List);
2958 -- The pragma is added before source declarations
2960 Prepend_To (Declarations (N), Aitem);
2962 -- When delay is not required and the context is not a compilation
2963 -- unit, we simply insert the pragma/attribute definition clause
2967 Insert_After (Ins_Node, Aitem);
2970 end Analyze_One_Aspect;
2974 end loop Aspect_Loop;
2976 if Has_Delayed_Aspects (E) then
2977 Ensure_Freeze_Node (E);
2979 end Analyze_Aspect_Specifications;
2981 -----------------------
2982 -- Analyze_At_Clause --
2983 -----------------------
2985 -- An at clause is replaced by the corresponding Address attribute
2986 -- definition clause that is the preferred approach in Ada 95.
2988 procedure Analyze_At_Clause (N : Node_Id) is
2989 CS : constant Boolean := Comes_From_Source (N);
2992 -- This is an obsolescent feature
2994 Check_Restriction (No_Obsolescent_Features, N);
2996 if Warn_On_Obsolescent_Feature then
2998 ("?j?at clause is an obsolescent feature (RM J.7(2))", N);
3000 ("\?j?use address attribute definition clause instead", N);
3003 -- Rewrite as address clause
3006 Make_Attribute_Definition_Clause (Sloc (N),
3007 Name => Identifier (N),
3008 Chars => Name_Address,
3009 Expression => Expression (N)));
3011 -- We preserve Comes_From_Source, since logically the clause still comes
3012 -- from the source program even though it is changed in form.
3014 Set_Comes_From_Source (N, CS);
3016 -- Analyze rewritten clause
3018 Analyze_Attribute_Definition_Clause (N);
3019 end Analyze_At_Clause;
3021 -----------------------------------------
3022 -- Analyze_Attribute_Definition_Clause --
3023 -----------------------------------------
3025 procedure Analyze_Attribute_Definition_Clause (N : Node_Id) is
3026 Loc : constant Source_Ptr := Sloc (N);
3027 Nam : constant Node_Id := Name (N);
3028 Attr : constant Name_Id := Chars (N);
3029 Expr : constant Node_Id := Expression (N);
3030 Id : constant Attribute_Id := Get_Attribute_Id (Attr);
3033 -- The entity of Nam after it is analyzed. In the case of an incomplete
3034 -- type, this is the underlying type.
3037 -- The underlying entity to which the attribute applies. Generally this
3038 -- is the Underlying_Type of Ent, except in the case where the clause
3039 -- applies to full view of incomplete type or private type in which case
3040 -- U_Ent is just a copy of Ent.
3042 FOnly : Boolean := False;
3043 -- Reset to True for subtype specific attribute (Alignment, Size)
3044 -- and for stream attributes, i.e. those cases where in the call
3045 -- to Rep_Item_Too_Late, FOnly is set True so that only the freezing
3046 -- rules are checked. Note that the case of stream attributes is not
3047 -- clear from the RM, but see AI95-00137. Also, the RM seems to
3048 -- disallow Storage_Size for derived task types, but that is also
3049 -- clearly unintentional.
3051 procedure Analyze_Stream_TSS_Definition (TSS_Nam : TSS_Name_Type);
3052 -- Common processing for 'Read, 'Write, 'Input and 'Output attribute
3053 -- definition clauses.
3055 function Duplicate_Clause return Boolean;
3056 -- This routine checks if the aspect for U_Ent being given by attribute
3057 -- definition clause N is for an aspect that has already been specified,
3058 -- and if so gives an error message. If there is a duplicate, True is
3059 -- returned, otherwise if there is no error, False is returned.
3061 procedure Check_Indexing_Functions;
3062 -- Check that the function in Constant_Indexing or Variable_Indexing
3063 -- attribute has the proper type structure. If the name is overloaded,
3064 -- check that some interpretation is legal.
3066 procedure Check_Iterator_Functions;
3067 -- Check that there is a single function in Default_Iterator attribute
3068 -- has the proper type structure.
3070 function Check_Primitive_Function (Subp : Entity_Id) return Boolean;
3071 -- Common legality check for the previous two
3073 -----------------------------------
3074 -- Analyze_Stream_TSS_Definition --
3075 -----------------------------------
3077 procedure Analyze_Stream_TSS_Definition (TSS_Nam : TSS_Name_Type) is
3078 Subp : Entity_Id := Empty;
3083 Is_Read : constant Boolean := (TSS_Nam = TSS_Stream_Read);
3084 -- True for Read attribute, false for other attributes
3086 function Has_Good_Profile (Subp : Entity_Id) return Boolean;
3087 -- Return true if the entity is a subprogram with an appropriate
3088 -- profile for the attribute being defined.
3090 ----------------------
3091 -- Has_Good_Profile --
3092 ----------------------
3094 function Has_Good_Profile (Subp : Entity_Id) return Boolean is
3096 Is_Function : constant Boolean := (TSS_Nam = TSS_Stream_Input);
3097 Expected_Ekind : constant array (Boolean) of Entity_Kind :=
3098 (False => E_Procedure, True => E_Function);
3102 if Ekind (Subp) /= Expected_Ekind (Is_Function) then
3106 F := First_Formal (Subp);
3109 or else Ekind (Etype (F)) /= E_Anonymous_Access_Type
3110 or else Designated_Type (Etype (F)) /=
3111 Class_Wide_Type (RTE (RE_Root_Stream_Type))
3116 if not Is_Function then
3120 Expected_Mode : constant array (Boolean) of Entity_Kind :=
3121 (False => E_In_Parameter,
3122 True => E_Out_Parameter);
3124 if Parameter_Mode (F) /= Expected_Mode (Is_Read) then
3132 Typ := Etype (Subp);
3135 return Base_Type (Typ) = Base_Type (Ent)
3136 and then No (Next_Formal (F));
3137 end Has_Good_Profile;
3139 -- Start of processing for Analyze_Stream_TSS_Definition
3144 if not Is_Type (U_Ent) then
3145 Error_Msg_N ("local name must be a subtype", Nam);
3149 Pnam := TSS (Base_Type (U_Ent), TSS_Nam);
3151 -- If Pnam is present, it can be either inherited from an ancestor
3152 -- type (in which case it is legal to redefine it for this type), or
3153 -- be a previous definition of the attribute for the same type (in
3154 -- which case it is illegal).
3156 -- In the first case, it will have been analyzed already, and we
3157 -- can check that its profile does not match the expected profile
3158 -- for a stream attribute of U_Ent. In the second case, either Pnam
3159 -- has been analyzed (and has the expected profile), or it has not
3160 -- been analyzed yet (case of a type that has not been frozen yet
3161 -- and for which the stream attribute has been set using Set_TSS).
3164 and then (No (First_Entity (Pnam)) or else Has_Good_Profile (Pnam))
3166 Error_Msg_Sloc := Sloc (Pnam);
3167 Error_Msg_Name_1 := Attr;
3168 Error_Msg_N ("% attribute already defined #", Nam);
3174 if Is_Entity_Name (Expr) then
3175 if not Is_Overloaded (Expr) then
3176 if Has_Good_Profile (Entity (Expr)) then
3177 Subp := Entity (Expr);
3181 Get_First_Interp (Expr, I, It);
3182 while Present (It.Nam) loop
3183 if Has_Good_Profile (It.Nam) then
3188 Get_Next_Interp (I, It);
3193 if Present (Subp) then
3194 if Is_Abstract_Subprogram (Subp) then
3195 Error_Msg_N ("stream subprogram must not be abstract", Expr);
3199 Set_Entity (Expr, Subp);
3200 Set_Etype (Expr, Etype (Subp));
3202 New_Stream_Subprogram (N, U_Ent, Subp, TSS_Nam);
3205 Error_Msg_Name_1 := Attr;
3206 Error_Msg_N ("incorrect expression for% attribute", Expr);
3208 end Analyze_Stream_TSS_Definition;
3210 ------------------------------
3211 -- Check_Indexing_Functions --
3212 ------------------------------
3214 procedure Check_Indexing_Functions is
3215 Indexing_Found : Boolean;
3217 procedure Check_One_Function (Subp : Entity_Id);
3218 -- Check one possible interpretation. Sets Indexing_Found True if an
3219 -- indexing function is found.
3221 ------------------------
3222 -- Check_One_Function --
3223 ------------------------
3225 procedure Check_One_Function (Subp : Entity_Id) is
3226 Default_Element : constant Node_Id :=
3227 Find_Value_Of_Aspect
3228 (Etype (First_Formal (Subp)),
3229 Aspect_Iterator_Element);
3232 if not Check_Primitive_Function (Subp)
3233 and then not Is_Overloaded (Expr)
3236 ("aspect Indexing requires a function that applies to type&",
3240 -- An indexing function must return either the default element of
3241 -- the container, or a reference type. For variable indexing it
3242 -- must be the latter.
3244 if Present (Default_Element) then
3245 Analyze (Default_Element);
3247 if Is_Entity_Name (Default_Element)
3248 and then Covers (Entity (Default_Element), Etype (Subp))
3250 Indexing_Found := True;
3255 -- For variable_indexing the return type must be a reference type
3257 if Attr = Name_Variable_Indexing
3258 and then not Has_Implicit_Dereference (Etype (Subp))
3261 ("function for indexing must return a reference type", Subp);
3264 Indexing_Found := True;
3266 end Check_One_Function;
3268 -- Start of processing for Check_Indexing_Functions
3277 if not Is_Overloaded (Expr) then
3278 Check_One_Function (Entity (Expr));
3286 Indexing_Found := False;
3287 Get_First_Interp (Expr, I, It);
3288 while Present (It.Nam) loop
3290 -- Note that analysis will have added the interpretation
3291 -- that corresponds to the dereference. We only check the
3292 -- subprogram itself.
3294 if Is_Overloadable (It.Nam) then
3295 Check_One_Function (It.Nam);
3298 Get_Next_Interp (I, It);
3301 if not Indexing_Found then
3303 ("aspect Indexing requires a function that "
3304 & "applies to type&", Expr, Ent);
3308 end Check_Indexing_Functions;
3310 ------------------------------
3311 -- Check_Iterator_Functions --
3312 ------------------------------
3314 procedure Check_Iterator_Functions is
3315 Default : Entity_Id;
3317 function Valid_Default_Iterator (Subp : Entity_Id) return Boolean;
3318 -- Check one possible interpretation for validity
3320 ----------------------------
3321 -- Valid_Default_Iterator --
3322 ----------------------------
3324 function Valid_Default_Iterator (Subp : Entity_Id) return Boolean is
3328 if not Check_Primitive_Function (Subp) then
3331 Formal := First_Formal (Subp);
3334 -- False if any subsequent formal has no default expression
3336 Formal := Next_Formal (Formal);
3337 while Present (Formal) loop
3338 if No (Expression (Parent (Formal))) then
3342 Next_Formal (Formal);
3345 -- True if all subsequent formals have default expressions
3348 end Valid_Default_Iterator;
3350 -- Start of processing for Check_Iterator_Functions
3355 if not Is_Entity_Name (Expr) then
3356 Error_Msg_N ("aspect Iterator must be a function name", Expr);
3359 if not Is_Overloaded (Expr) then
3360 if not Check_Primitive_Function (Entity (Expr)) then
3362 ("aspect Indexing requires a function that applies to type&",
3363 Entity (Expr), Ent);
3366 if not Valid_Default_Iterator (Entity (Expr)) then
3367 Error_Msg_N ("improper function for default iterator", Expr);
3377 Get_First_Interp (Expr, I, It);
3378 while Present (It.Nam) loop
3379 if not Check_Primitive_Function (It.Nam)
3380 or else not Valid_Default_Iterator (It.Nam)
3384 elsif Present (Default) then
3385 Error_Msg_N ("default iterator must be unique", Expr);
3391 Get_Next_Interp (I, It);
3395 if Present (Default) then
3396 Set_Entity (Expr, Default);
3397 Set_Is_Overloaded (Expr, False);
3400 end Check_Iterator_Functions;
3402 -------------------------------
3403 -- Check_Primitive_Function --
3404 -------------------------------
3406 function Check_Primitive_Function (Subp : Entity_Id) return Boolean is
3410 if Ekind (Subp) /= E_Function then
3414 if No (First_Formal (Subp)) then
3417 Ctrl := Etype (First_Formal (Subp));
3421 or else Ctrl = Class_Wide_Type (Ent)
3423 (Ekind (Ctrl) = E_Anonymous_Access_Type
3425 (Designated_Type (Ctrl) = Ent
3426 or else Designated_Type (Ctrl) = Class_Wide_Type (Ent)))
3435 end Check_Primitive_Function;
3437 ----------------------
3438 -- Duplicate_Clause --
3439 ----------------------
3441 function Duplicate_Clause return Boolean is
3445 -- Nothing to do if this attribute definition clause comes from
3446 -- an aspect specification, since we could not be duplicating an
3447 -- explicit clause, and we dealt with the case of duplicated aspects
3448 -- in Analyze_Aspect_Specifications.
3450 if From_Aspect_Specification (N) then
3454 -- Otherwise current clause may duplicate previous clause, or a
3455 -- previously given pragma or aspect specification for the same
3458 A := Get_Rep_Item (U_Ent, Chars (N), Check_Parents => False);
3461 Error_Msg_Name_1 := Chars (N);
3462 Error_Msg_Sloc := Sloc (A);
3464 Error_Msg_NE ("aspect% for & previously given#", N, U_Ent);
3469 end Duplicate_Clause;
3471 -- Start of processing for Analyze_Attribute_Definition_Clause
3474 -- The following code is a defense against recursion. Not clear that
3475 -- this can happen legitimately, but perhaps some error situations
3476 -- can cause it, and we did see this recursion during testing.
3478 if Analyzed (N) then
3481 Set_Analyzed (N, True);
3484 -- Ignore some selected attributes in CodePeer mode since they are not
3485 -- relevant in this context.
3487 if CodePeer_Mode then
3490 -- Ignore Component_Size in CodePeer mode, to avoid changing the
3491 -- internal representation of types by implicitly packing them.
3493 when Attribute_Component_Size =>
3494 Rewrite (N, Make_Null_Statement (Sloc (N)));
3502 -- Process Ignore_Rep_Clauses option
3504 if Ignore_Rep_Clauses then
3507 -- The following should be ignored. They do not affect legality
3508 -- and may be target dependent. The basic idea of -gnatI is to
3509 -- ignore any rep clauses that may be target dependent but do not
3510 -- affect legality (except possibly to be rejected because they
3511 -- are incompatible with the compilation target).
3513 when Attribute_Alignment |
3514 Attribute_Bit_Order |
3515 Attribute_Component_Size |
3516 Attribute_Machine_Radix |
3517 Attribute_Object_Size |
3519 Attribute_Stream_Size |
3520 Attribute_Value_Size =>
3521 Rewrite (N, Make_Null_Statement (Sloc (N)));
3524 -- Perhaps 'Small should not be ignored by Ignore_Rep_Clauses ???
3526 when Attribute_Small =>
3527 if Ignore_Rep_Clauses then
3528 Rewrite (N, Make_Null_Statement (Sloc (N)));
3532 -- The following should not be ignored, because in the first place
3533 -- they are reasonably portable, and should not cause problems in
3534 -- compiling code from another target, and also they do affect
3535 -- legality, e.g. failing to provide a stream attribute for a
3536 -- type may make a program illegal.
3538 when Attribute_External_Tag |
3542 Attribute_Simple_Storage_Pool |
3543 Attribute_Storage_Pool |
3544 Attribute_Storage_Size |
3548 -- Other cases are errors ("attribute& cannot be set with
3549 -- definition clause"), which will be caught below.
3557 Ent := Entity (Nam);
3559 if Rep_Item_Too_Early (Ent, N) then
3563 -- Rep clause applies to full view of incomplete type or private type if
3564 -- we have one (if not, this is a premature use of the type). However,
3565 -- certain semantic checks need to be done on the specified entity (i.e.
3566 -- the private view), so we save it in Ent.
3568 if Is_Private_Type (Ent)
3569 and then Is_Derived_Type (Ent)
3570 and then not Is_Tagged_Type (Ent)
3571 and then No (Full_View (Ent))
3573 -- If this is a private type whose completion is a derivation from
3574 -- another private type, there is no full view, and the attribute
3575 -- belongs to the type itself, not its underlying parent.
3579 elsif Ekind (Ent) = E_Incomplete_Type then
3581 -- The attribute applies to the full view, set the entity of the
3582 -- attribute definition accordingly.
3584 Ent := Underlying_Type (Ent);
3586 Set_Entity (Nam, Ent);
3589 U_Ent := Underlying_Type (Ent);
3592 -- Avoid cascaded error
3594 if Etype (Nam) = Any_Type then
3597 -- Must be declared in current scope or in case of an aspect
3598 -- specification, must be visible in current scope.
3600 elsif Scope (Ent) /= Current_Scope
3602 not (From_Aspect_Specification (N)
3603 and then Scope_Within_Or_Same (Current_Scope, Scope (Ent)))
3605 Error_Msg_N ("entity must be declared in this scope", Nam);
3608 -- Must not be a source renaming (we do have some cases where the
3609 -- expander generates a renaming, and those cases are OK, in such
3610 -- cases any attribute applies to the renamed object as well).
3612 elsif Is_Object (Ent)
3613 and then Present (Renamed_Object (Ent))
3615 -- Case of renamed object from source, this is an error
3617 if Comes_From_Source (Renamed_Object (Ent)) then
3618 Get_Name_String (Chars (N));
3619 Error_Msg_Strlen := Name_Len;
3620 Error_Msg_String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len);
3622 ("~ clause not allowed for a renaming declaration "
3623 & "(RM 13.1(6))", Nam);
3626 -- For the case of a compiler generated renaming, the attribute
3627 -- definition clause applies to the renamed object created by the
3628 -- expander. The easiest general way to handle this is to create a
3629 -- copy of the attribute definition clause for this object.
3631 elsif Is_Entity_Name (Renamed_Object (Ent)) then
3633 Make_Attribute_Definition_Clause (Loc,
3635 New_Occurrence_Of (Entity (Renamed_Object (Ent)), Loc),
3637 Expression => Duplicate_Subexpr (Expression (N))));
3639 -- If the renamed object is not an entity, it must be a dereference
3640 -- of an unconstrained function call, and we must introduce a new
3641 -- declaration to capture the expression. This is needed in the case
3642 -- of 'Alignment, where the original declaration must be rewritten.
3646 (Nkind (Renamed_Object (Ent)) = N_Explicit_Dereference);
3650 -- If no underlying entity, use entity itself, applies to some
3651 -- previously detected error cases ???
3653 elsif No (U_Ent) then
3656 -- Cannot specify for a subtype (exception Object/Value_Size)
3658 elsif Is_Type (U_Ent)
3659 and then not Is_First_Subtype (U_Ent)
3660 and then Id /= Attribute_Object_Size
3661 and then Id /= Attribute_Value_Size
3662 and then not From_At_Mod (N)
3664 Error_Msg_N ("cannot specify attribute for subtype", Nam);
3668 Set_Entity (N, U_Ent);
3669 Check_Restriction_No_Use_Of_Attribute (N);
3671 -- Switch on particular attribute
3679 -- Address attribute definition clause
3681 when Attribute_Address => Address : begin
3683 -- A little error check, catch for X'Address use X'Address;
3685 if Nkind (Nam) = N_Identifier
3686 and then Nkind (Expr) = N_Attribute_Reference
3687 and then Attribute_Name (Expr) = Name_Address
3688 and then Nkind (Prefix (Expr)) = N_Identifier
3689 and then Chars (Nam) = Chars (Prefix (Expr))
3692 ("address for & is self-referencing", Prefix (Expr), Ent);
3696 -- Not that special case, carry on with analysis of expression
3698 Analyze_And_Resolve (Expr, RTE (RE_Address));
3700 -- Even when ignoring rep clauses we need to indicate that the
3701 -- entity has an address clause and thus it is legal to declare
3704 if Ignore_Rep_Clauses then
3705 if Ekind_In (U_Ent, E_Variable, E_Constant) then
3706 Record_Rep_Item (U_Ent, N);
3712 if Duplicate_Clause then
3715 -- Case of address clause for subprogram
3717 elsif Is_Subprogram (U_Ent) then
3718 if Has_Homonym (U_Ent) then
3720 ("address clause cannot be given " &
3721 "for overloaded subprogram",
3726 -- For subprograms, all address clauses are permitted, and we
3727 -- mark the subprogram as having a deferred freeze so that Gigi
3728 -- will not elaborate it too soon.
3730 -- Above needs more comments, what is too soon about???
3732 Set_Has_Delayed_Freeze (U_Ent);
3734 -- Case of address clause for entry
3736 elsif Ekind (U_Ent) = E_Entry then
3737 if Nkind (Parent (N)) = N_Task_Body then
3739 ("entry address must be specified in task spec", Nam);
3743 -- For entries, we require a constant address
3745 Check_Constant_Address_Clause (Expr, U_Ent);
3747 -- Special checks for task types
3749 if Is_Task_Type (Scope (U_Ent))
3750 and then Comes_From_Source (Scope (U_Ent))
3753 ("??entry address declared for entry in task type", N);
3755 ("\??only one task can be declared of this type", N);
3758 -- Entry address clauses are obsolescent
3760 Check_Restriction (No_Obsolescent_Features, N);
3762 if Warn_On_Obsolescent_Feature then
3764 ("?j?attaching interrupt to task entry is an " &
3765 "obsolescent feature (RM J.7.1)", N);
3767 ("\?j?use interrupt procedure instead", N);
3770 -- Case of an address clause for a controlled object which we
3771 -- consider to be erroneous.
3773 elsif Is_Controlled (Etype (U_Ent))
3774 or else Has_Controlled_Component (Etype (U_Ent))
3777 ("??controlled object& must not be overlaid", Nam, U_Ent);
3779 ("\??Program_Error will be raised at run time", Nam);
3780 Insert_Action (Declaration_Node (U_Ent),
3781 Make_Raise_Program_Error (Loc,
3782 Reason => PE_Overlaid_Controlled_Object));
3785 -- Case of address clause for a (non-controlled) object
3788 Ekind (U_Ent) = E_Variable
3790 Ekind (U_Ent) = E_Constant
3793 Expr : constant Node_Id := Expression (N);
3798 -- Exported variables cannot have an address clause, because
3799 -- this cancels the effect of the pragma Export.
3801 if Is_Exported (U_Ent) then
3803 ("cannot export object with address clause", Nam);
3807 Find_Overlaid_Entity (N, O_Ent, Off);
3809 -- Overlaying controlled objects is erroneous
3812 and then (Has_Controlled_Component (Etype (O_Ent))
3813 or else Is_Controlled (Etype (O_Ent)))
3816 ("??cannot overlay with controlled object", Expr);
3818 ("\??Program_Error will be raised at run time", Expr);
3819 Insert_Action (Declaration_Node (U_Ent),
3820 Make_Raise_Program_Error (Loc,
3821 Reason => PE_Overlaid_Controlled_Object));
3824 elsif Present (O_Ent)
3825 and then Ekind (U_Ent) = E_Constant
3826 and then not Is_Constant_Object (O_Ent)
3828 Error_Msg_N ("??constant overlays a variable", Expr);
3830 -- Imported variables can have an address clause, but then
3831 -- the import is pretty meaningless except to suppress
3832 -- initializations, so we do not need such variables to
3833 -- be statically allocated (and in fact it causes trouble
3834 -- if the address clause is a local value).
3836 elsif Is_Imported (U_Ent) then
3837 Set_Is_Statically_Allocated (U_Ent, False);
3840 -- We mark a possible modification of a variable with an
3841 -- address clause, since it is likely aliasing is occurring.
3843 Note_Possible_Modification (Nam, Sure => False);
3845 -- Here we are checking for explicit overlap of one variable
3846 -- by another, and if we find this then mark the overlapped
3847 -- variable as also being volatile to prevent unwanted
3848 -- optimizations. This is a significant pessimization so
3849 -- avoid it when there is an offset, i.e. when the object
3850 -- is composite; they cannot be optimized easily anyway.
3853 and then Is_Object (O_Ent)
3856 -- The following test is an expedient solution to what
3857 -- is really a problem in CodePeer. Suppressing the
3858 -- Set_Treat_As_Volatile call here prevents later
3859 -- generation (in some cases) of trees that CodePeer
3860 -- should, but currently does not, handle correctly.
3861 -- This test should probably be removed when CodePeer
3862 -- is improved, just because we want the tree CodePeer
3863 -- analyzes to match the tree for which we generate code
3864 -- as closely as is practical. ???
3866 and then not CodePeer_Mode
3868 -- ??? O_Ent might not be in current unit
3870 Set_Treat_As_Volatile (O_Ent);
3873 -- Legality checks on the address clause for initialized
3874 -- objects is deferred until the freeze point, because
3875 -- a subsequent pragma might indicate that the object
3876 -- is imported and thus not initialized. Also, the address
3877 -- clause might involve entities that have yet to be
3880 Set_Has_Delayed_Freeze (U_Ent);
3882 -- If an initialization call has been generated for this
3883 -- object, it needs to be deferred to after the freeze node
3884 -- we have just now added, otherwise GIGI will see a
3885 -- reference to the variable (as actual to the IP call)
3886 -- before its definition.
3889 Init_Call : constant Node_Id :=
3890 Remove_Init_Call (U_Ent, N);
3893 if Present (Init_Call) then
3894 Append_Freeze_Action (U_Ent, Init_Call);
3896 -- Reset Initialization_Statements pointer so that
3897 -- if there is a pragma Import further down, it can
3898 -- clear any default initialization.
3900 Set_Initialization_Statements (U_Ent, Init_Call);
3904 if Is_Exported (U_Ent) then
3906 ("& cannot be exported if an address clause is given",
3909 ("\define and export a variable "
3910 & "that holds its address instead", Nam);
3913 -- Entity has delayed freeze, so we will generate an
3914 -- alignment check at the freeze point unless suppressed.
3916 if not Range_Checks_Suppressed (U_Ent)
3917 and then not Alignment_Checks_Suppressed (U_Ent)
3919 Set_Check_Address_Alignment (N);
3922 -- Kill the size check code, since we are not allocating
3923 -- the variable, it is somewhere else.
3925 Kill_Size_Check_Code (U_Ent);
3927 -- If the address clause is of the form:
3929 -- for Y'Address use X'Address
3933 -- Const : constant Address := X'Address;
3935 -- for Y'Address use Const;
3937 -- then we make an entry in the table for checking the size
3938 -- and alignment of the overlaying variable. We defer this
3939 -- check till after code generation to take full advantage
3940 -- of the annotation done by the back end.
3942 -- If the entity has a generic type, the check will be
3943 -- performed in the instance if the actual type justifies
3944 -- it, and we do not insert the clause in the table to
3945 -- prevent spurious warnings.
3947 -- Note: we used to test Comes_From_Source and only give
3948 -- this warning for source entities, but we have removed
3949 -- this test. It really seems bogus to generate overlays
3950 -- that would trigger this warning in generated code.
3951 -- Furthermore, by removing the test, we handle the
3952 -- aspect case properly.
3954 if Address_Clause_Overlay_Warnings
3955 and then Present (O_Ent)
3956 and then Is_Object (O_Ent)
3958 if not Is_Generic_Type (Etype (U_Ent)) then
3959 Address_Clause_Checks.Append ((N, U_Ent, O_Ent, Off));
3962 -- If variable overlays a constant view, and we are
3963 -- warning on overlays, then mark the variable as
3964 -- overlaying a constant (we will give warnings later
3965 -- if this variable is assigned).
3967 if Is_Constant_Object (O_Ent)
3968 and then Ekind (U_Ent) = E_Variable
3970 Set_Overlays_Constant (U_Ent);
3975 -- Not a valid entity for an address clause
3978 Error_Msg_N ("address cannot be given for &", Nam);
3986 -- Alignment attribute definition clause
3988 when Attribute_Alignment => Alignment : declare
3989 Align : constant Uint := Get_Alignment_Value (Expr);
3990 Max_Align : constant Uint := UI_From_Int (Maximum_Alignment);
3995 if not Is_Type (U_Ent)
3996 and then Ekind (U_Ent) /= E_Variable
3997 and then Ekind (U_Ent) /= E_Constant
3999 Error_Msg_N ("alignment cannot be given for &", Nam);
4001 elsif Duplicate_Clause then
4004 elsif Align /= No_Uint then
4005 Set_Has_Alignment_Clause (U_Ent);
4007 -- Tagged type case, check for attempt to set alignment to a
4008 -- value greater than Max_Align, and reset if so.
4010 if Is_Tagged_Type (U_Ent) and then Align > Max_Align then
4012 ("alignment for & set to Maximum_Aligment??", Nam);
4013 Set_Alignment (U_Ent, Max_Align);
4018 Set_Alignment (U_Ent, Align);
4021 -- For an array type, U_Ent is the first subtype. In that case,
4022 -- also set the alignment of the anonymous base type so that
4023 -- other subtypes (such as the itypes for aggregates of the
4024 -- type) also receive the expected alignment.
4026 if Is_Array_Type (U_Ent) then
4027 Set_Alignment (Base_Type (U_Ent), Align);
4036 -- Bit_Order attribute definition clause
4038 when Attribute_Bit_Order => Bit_Order : declare
4040 if not Is_Record_Type (U_Ent) then
4042 ("Bit_Order can only be defined for record type", Nam);
4044 elsif Duplicate_Clause then
4048 Analyze_And_Resolve (Expr, RTE (RE_Bit_Order));
4050 if Etype (Expr) = Any_Type then
4053 elsif not Is_Static_Expression (Expr) then
4054 Flag_Non_Static_Expr
4055 ("Bit_Order requires static expression!", Expr);
4058 if (Expr_Value (Expr) = 0) /= Bytes_Big_Endian then
4059 Set_Reverse_Bit_Order (U_Ent, True);
4065 --------------------
4066 -- Component_Size --
4067 --------------------
4069 -- Component_Size attribute definition clause
4071 when Attribute_Component_Size => Component_Size_Case : declare
4072 Csize : constant Uint := Static_Integer (Expr);
4076 New_Ctyp : Entity_Id;
4080 if not Is_Array_Type (U_Ent) then
4081 Error_Msg_N ("component size requires array type", Nam);
4085 Btype := Base_Type (U_Ent);
4086 Ctyp := Component_Type (Btype);
4088 if Duplicate_Clause then
4091 elsif Rep_Item_Too_Early (Btype, N) then
4094 elsif Csize /= No_Uint then
4095 Check_Size (Expr, Ctyp, Csize, Biased);
4097 -- For the biased case, build a declaration for a subtype that
4098 -- will be used to represent the biased subtype that reflects
4099 -- the biased representation of components. We need the subtype
4100 -- to get proper conversions on referencing elements of the
4101 -- array. Note: component size clauses are ignored in VM mode.
4103 if VM_Target = No_VM then
4106 Make_Defining_Identifier (Loc,
4108 New_External_Name (Chars (U_Ent), 'C', 0, 'T'));
4111 Make_Subtype_Declaration (Loc,
4112 Defining_Identifier => New_Ctyp,
4113 Subtype_Indication =>
4114 New_Occurrence_Of (Component_Type (Btype), Loc));
4116 Set_Parent (Decl, N);
4117 Analyze (Decl, Suppress => All_Checks);
4119 Set_Has_Delayed_Freeze (New_Ctyp, False);
4120 Set_Esize (New_Ctyp, Csize);
4121 Set_RM_Size (New_Ctyp, Csize);
4122 Init_Alignment (New_Ctyp);
4123 Set_Is_Itype (New_Ctyp, True);
4124 Set_Associated_Node_For_Itype (New_Ctyp, U_Ent);
4126 Set_Component_Type (Btype, New_Ctyp);
4127 Set_Biased (New_Ctyp, N, "component size clause");
4130 Set_Component_Size (Btype, Csize);
4132 -- For VM case, we ignore component size clauses
4135 -- Give a warning unless we are in GNAT mode, in which case
4136 -- the warning is suppressed since it is not useful.
4138 if not GNAT_Mode then
4140 ("component size ignored in this configuration??", N);
4144 -- Deal with warning on overridden size
4146 if Warn_On_Overridden_Size
4147 and then Has_Size_Clause (Ctyp)
4148 and then RM_Size (Ctyp) /= Csize
4151 ("component size overrides size clause for&?S?", N, Ctyp);
4154 Set_Has_Component_Size_Clause (Btype, True);
4155 Set_Has_Non_Standard_Rep (Btype, True);
4157 end Component_Size_Case;
4159 -----------------------
4160 -- Constant_Indexing --
4161 -----------------------
4163 when Attribute_Constant_Indexing =>
4164 Check_Indexing_Functions;
4170 when Attribute_CPU => CPU :
4172 -- CPU attribute definition clause not allowed except from aspect
4175 if From_Aspect_Specification (N) then
4176 if not Is_Task_Type (U_Ent) then
4177 Error_Msg_N ("CPU can only be defined for task", Nam);
4179 elsif Duplicate_Clause then
4183 -- The expression must be analyzed in the special manner
4184 -- described in "Handling of Default and Per-Object
4185 -- Expressions" in sem.ads.
4187 -- The visibility to the discriminants must be restored
4189 Push_Scope_And_Install_Discriminants (U_Ent);
4190 Preanalyze_Spec_Expression (Expr, RTE (RE_CPU_Range));
4191 Uninstall_Discriminants_And_Pop_Scope (U_Ent);
4193 if not Is_Static_Expression (Expr) then
4194 Check_Restriction (Static_Priorities, Expr);
4200 ("attribute& cannot be set with definition clause", N);
4204 ----------------------
4205 -- Default_Iterator --
4206 ----------------------
4208 when Attribute_Default_Iterator => Default_Iterator : declare
4212 if not Is_Tagged_Type (U_Ent) then
4214 ("aspect Default_Iterator applies to tagged type", Nam);
4217 Check_Iterator_Functions;
4221 if not Is_Entity_Name (Expr)
4222 or else Ekind (Entity (Expr)) /= E_Function
4224 Error_Msg_N ("aspect Iterator must be a function", Expr);
4226 Func := Entity (Expr);
4229 if No (First_Formal (Func))
4230 or else Etype (First_Formal (Func)) /= U_Ent
4233 ("Default Iterator must be a primitive of&", Func, U_Ent);
4235 end Default_Iterator;
4237 ------------------------
4238 -- Dispatching_Domain --
4239 ------------------------
4241 when Attribute_Dispatching_Domain => Dispatching_Domain :
4243 -- Dispatching_Domain attribute definition clause not allowed
4244 -- except from aspect specification.
4246 if From_Aspect_Specification (N) then
4247 if not Is_Task_Type (U_Ent) then
4248 Error_Msg_N ("Dispatching_Domain can only be defined" &
4252 elsif Duplicate_Clause then
4256 -- The expression must be analyzed in the special manner
4257 -- described in "Handling of Default and Per-Object
4258 -- Expressions" in sem.ads.
4260 -- The visibility to the discriminants must be restored
4262 Push_Scope_And_Install_Discriminants (U_Ent);
4264 Preanalyze_Spec_Expression
4265 (Expr, RTE (RE_Dispatching_Domain));
4267 Uninstall_Discriminants_And_Pop_Scope (U_Ent);
4272 ("attribute& cannot be set with definition clause", N);
4274 end Dispatching_Domain;
4280 when Attribute_External_Tag => External_Tag :
4282 if not Is_Tagged_Type (U_Ent) then
4283 Error_Msg_N ("should be a tagged type", Nam);
4286 if Duplicate_Clause then
4290 Analyze_And_Resolve (Expr, Standard_String);
4292 if not Is_Static_Expression (Expr) then
4293 Flag_Non_Static_Expr
4294 ("static string required for tag name!", Nam);
4297 if VM_Target = No_VM then
4298 Set_Has_External_Tag_Rep_Clause (U_Ent);
4300 Error_Msg_Name_1 := Attr;
4302 ("% attribute unsupported in this configuration", Nam);
4305 if not Is_Library_Level_Entity (U_Ent) then
4307 ("??non-unique external tag supplied for &", N, U_Ent);
4309 ("\??same external tag applies to all "
4310 & "subprogram calls", N);
4312 ("\??corresponding internal tag cannot be obtained", N);
4317 --------------------------
4318 -- Implicit_Dereference --
4319 --------------------------
4321 when Attribute_Implicit_Dereference =>
4323 -- Legality checks already performed at the point of the type
4324 -- declaration, aspect is not delayed.
4332 when Attribute_Input =>
4333 Analyze_Stream_TSS_Definition (TSS_Stream_Input);
4334 Set_Has_Specified_Stream_Input (Ent);
4336 ------------------------
4337 -- Interrupt_Priority --
4338 ------------------------
4340 when Attribute_Interrupt_Priority => Interrupt_Priority :
4342 -- Interrupt_Priority attribute definition clause not allowed
4343 -- except from aspect specification.
4345 if From_Aspect_Specification (N) then
4346 if not (Is_Protected_Type (U_Ent)
4347 or else Is_Task_Type (U_Ent))
4350 ("Interrupt_Priority can only be defined for task" &
4351 "and protected object",
4354 elsif Duplicate_Clause then
4358 -- The expression must be analyzed in the special manner
4359 -- described in "Handling of Default and Per-Object
4360 -- Expressions" in sem.ads.
4362 -- The visibility to the discriminants must be restored
4364 Push_Scope_And_Install_Discriminants (U_Ent);
4366 Preanalyze_Spec_Expression
4367 (Expr, RTE (RE_Interrupt_Priority));
4369 Uninstall_Discriminants_And_Pop_Scope (U_Ent);
4374 ("attribute& cannot be set with definition clause", N);
4376 end Interrupt_Priority;
4382 when Attribute_Iterable =>
4385 if Nkind (Expr) /= N_Aggregate then
4386 Error_Msg_N ("aspect Iterable must be an aggregate", Expr);
4393 Assoc := First (Component_Associations (Expr));
4394 while Present (Assoc) loop
4395 if not Is_Entity_Name (Expression (Assoc)) then
4396 Error_Msg_N ("value must be a function", Assoc);
4403 ----------------------
4404 -- Iterator_Element --
4405 ----------------------
4407 when Attribute_Iterator_Element =>
4410 if not Is_Entity_Name (Expr)
4411 or else not Is_Type (Entity (Expr))
4413 Error_Msg_N ("aspect Iterator_Element must be a type", Expr);
4420 -- Machine radix attribute definition clause
4422 when Attribute_Machine_Radix => Machine_Radix : declare
4423 Radix : constant Uint := Static_Integer (Expr);
4426 if not Is_Decimal_Fixed_Point_Type (U_Ent) then
4427 Error_Msg_N ("decimal fixed-point type expected for &", Nam);
4429 elsif Duplicate_Clause then
4432 elsif Radix /= No_Uint then
4433 Set_Has_Machine_Radix_Clause (U_Ent);
4434 Set_Has_Non_Standard_Rep (Base_Type (U_Ent));
4438 elsif Radix = 10 then
4439 Set_Machine_Radix_10 (U_Ent);
4441 Error_Msg_N ("machine radix value must be 2 or 10", Expr);
4450 -- Object_Size attribute definition clause
4452 when Attribute_Object_Size => Object_Size : declare
4453 Size : constant Uint := Static_Integer (Expr);
4456 pragma Warnings (Off, Biased);
4459 if not Is_Type (U_Ent) then
4460 Error_Msg_N ("Object_Size cannot be given for &", Nam);
4462 elsif Duplicate_Clause then
4466 Check_Size (Expr, U_Ent, Size, Biased);
4468 if Is_Scalar_Type (U_Ent) then
4469 if Size /= 8 and then Size /= 16 and then Size /= 32
4470 and then UI_Mod (Size, 64) /= 0
4473 ("Object_Size must be 8, 16, 32, or multiple of 64",
4477 elsif Size mod 8 /= 0 then
4478 Error_Msg_N ("Object_Size must be a multiple of 8", Expr);
4481 Set_Esize (U_Ent, Size);
4482 Set_Has_Object_Size_Clause (U_Ent);
4483 Alignment_Check_For_Size_Change (U_Ent, Size);
4491 when Attribute_Output =>
4492 Analyze_Stream_TSS_Definition (TSS_Stream_Output);
4493 Set_Has_Specified_Stream_Output (Ent);
4499 when Attribute_Priority => Priority :
4501 -- Priority attribute definition clause not allowed except from
4502 -- aspect specification.
4504 if From_Aspect_Specification (N) then
4505 if not (Is_Protected_Type (U_Ent)
4506 or else Is_Task_Type (U_Ent)
4507 or else Ekind (U_Ent) = E_Procedure)
4510 ("Priority can only be defined for task and protected " &
4514 elsif Duplicate_Clause then
4518 -- The expression must be analyzed in the special manner
4519 -- described in "Handling of Default and Per-Object
4520 -- Expressions" in sem.ads.
4522 -- The visibility to the discriminants must be restored
4524 Push_Scope_And_Install_Discriminants (U_Ent);
4525 Preanalyze_Spec_Expression (Expr, Standard_Integer);
4526 Uninstall_Discriminants_And_Pop_Scope (U_Ent);
4528 if not Is_Static_Expression (Expr) then
4529 Check_Restriction (Static_Priorities, Expr);
4535 ("attribute& cannot be set with definition clause", N);
4543 when Attribute_Read =>
4544 Analyze_Stream_TSS_Definition (TSS_Stream_Read);
4545 Set_Has_Specified_Stream_Read (Ent);
4547 --------------------------
4548 -- Scalar_Storage_Order --
4549 --------------------------
4551 -- Scalar_Storage_Order attribute definition clause
4553 when Attribute_Scalar_Storage_Order => Scalar_Storage_Order : declare
4555 if not (Is_Record_Type (U_Ent) or else Is_Array_Type (U_Ent)) then
4557 ("Scalar_Storage_Order can only be defined for "
4558 & "record or array type", Nam);
4560 elsif Duplicate_Clause then
4564 Analyze_And_Resolve (Expr, RTE (RE_Bit_Order));
4566 if Etype (Expr) = Any_Type then
4569 elsif not Is_Static_Expression (Expr) then
4570 Flag_Non_Static_Expr
4571 ("Scalar_Storage_Order requires static expression!", Expr);
4573 elsif (Expr_Value (Expr) = 0) /= Bytes_Big_Endian then
4575 -- Here for the case of a non-default (i.e. non-confirming)
4576 -- Scalar_Storage_Order attribute definition.
4578 if Support_Nondefault_SSO_On_Target then
4579 Set_Reverse_Storage_Order (Base_Type (U_Ent), True);
4582 ("non-default Scalar_Storage_Order "
4583 & "not supported on target", Expr);
4587 end Scalar_Storage_Order;
4593 -- Size attribute definition clause
4595 when Attribute_Size => Size : declare
4596 Size : constant Uint := Static_Integer (Expr);
4603 if Duplicate_Clause then
4606 elsif not Is_Type (U_Ent)
4607 and then Ekind (U_Ent) /= E_Variable
4608 and then Ekind (U_Ent) /= E_Constant
4610 Error_Msg_N ("size cannot be given for &", Nam);
4612 elsif Is_Array_Type (U_Ent)
4613 and then not Is_Constrained (U_Ent)
4616 ("size cannot be given for unconstrained array", Nam);
4618 elsif Size /= No_Uint then
4619 if VM_Target /= No_VM and then not GNAT_Mode then
4621 -- Size clause is not handled properly on VM targets.
4622 -- Display a warning unless we are in GNAT mode, in which
4623 -- case this is useless.
4626 ("size clauses are ignored in this configuration??", N);
4629 if Is_Type (U_Ent) then
4632 Etyp := Etype (U_Ent);
4635 -- Check size, note that Gigi is in charge of checking that the
4636 -- size of an array or record type is OK. Also we do not check
4637 -- the size in the ordinary fixed-point case, since it is too
4638 -- early to do so (there may be subsequent small clause that
4639 -- affects the size). We can check the size if a small clause
4640 -- has already been given.
4642 if not Is_Ordinary_Fixed_Point_Type (U_Ent)
4643 or else Has_Small_Clause (U_Ent)
4645 Check_Size (Expr, Etyp, Size, Biased);
4646 Set_Biased (U_Ent, N, "size clause", Biased);
4649 -- For types set RM_Size and Esize if possible
4651 if Is_Type (U_Ent) then
4652 Set_RM_Size (U_Ent, Size);
4654 -- For elementary types, increase Object_Size to power of 2,
4655 -- but not less than a storage unit in any case (normally
4656 -- this means it will be byte addressable).
4658 -- For all other types, nothing else to do, we leave Esize
4659 -- (object size) unset, the back end will set it from the
4660 -- size and alignment in an appropriate manner.
4662 -- In both cases, we check whether the alignment must be
4663 -- reset in the wake of the size change.
4665 if Is_Elementary_Type (U_Ent) then
4666 if Size <= System_Storage_Unit then
4667 Init_Esize (U_Ent, System_Storage_Unit);
4668 elsif Size <= 16 then
4669 Init_Esize (U_Ent, 16);
4670 elsif Size <= 32 then
4671 Init_Esize (U_Ent, 32);
4673 Set_Esize (U_Ent, (Size + 63) / 64 * 64);
4676 Alignment_Check_For_Size_Change (U_Ent, Esize (U_Ent));
4678 Alignment_Check_For_Size_Change (U_Ent, Size);
4681 -- For objects, set Esize only
4684 if Is_Elementary_Type (Etyp) then
4685 if Size /= System_Storage_Unit
4687 Size /= System_Storage_Unit * 2
4689 Size /= System_Storage_Unit * 4
4691 Size /= System_Storage_Unit * 8
4693 Error_Msg_Uint_1 := UI_From_Int (System_Storage_Unit);
4694 Error_Msg_Uint_2 := Error_Msg_Uint_1 * 8;
4696 ("size for primitive object must be a power of 2"
4697 & " in the range ^-^", N);
4701 Set_Esize (U_Ent, Size);
4704 Set_Has_Size_Clause (U_Ent);
4712 -- Small attribute definition clause
4714 when Attribute_Small => Small : declare
4715 Implicit_Base : constant Entity_Id := Base_Type (U_Ent);
4719 Analyze_And_Resolve (Expr, Any_Real);
4721 if Etype (Expr) = Any_Type then
4724 elsif not Is_Static_Expression (Expr) then
4725 Flag_Non_Static_Expr
4726 ("small requires static expression!", Expr);
4730 Small := Expr_Value_R (Expr);
4732 if Small <= Ureal_0 then
4733 Error_Msg_N ("small value must be greater than zero", Expr);
4739 if not Is_Ordinary_Fixed_Point_Type (U_Ent) then
4741 ("small requires an ordinary fixed point type", Nam);
4743 elsif Has_Small_Clause (U_Ent) then
4744 Error_Msg_N ("small already given for &", Nam);
4746 elsif Small > Delta_Value (U_Ent) then
4748 ("small value must not be greater than delta value", Nam);
4751 Set_Small_Value (U_Ent, Small);
4752 Set_Small_Value (Implicit_Base, Small);
4753 Set_Has_Small_Clause (U_Ent);
4754 Set_Has_Small_Clause (Implicit_Base);
4755 Set_Has_Non_Standard_Rep (Implicit_Base);
4763 -- Storage_Pool attribute definition clause
4765 when Attribute_Storage_Pool | Attribute_Simple_Storage_Pool => declare
4770 if Ekind (U_Ent) = E_Access_Subprogram_Type then
4772 ("storage pool cannot be given for access-to-subprogram type",
4777 Ekind_In (U_Ent, E_Access_Type, E_General_Access_Type)
4780 ("storage pool can only be given for access types", Nam);
4783 elsif Is_Derived_Type (U_Ent) then
4785 ("storage pool cannot be given for a derived access type",
4788 elsif Duplicate_Clause then
4791 elsif Present (Associated_Storage_Pool (U_Ent)) then
4792 Error_Msg_N ("storage pool already given for &", Nam);
4796 -- Check for Storage_Size previously given
4799 SS : constant Node_Id :=
4800 Get_Attribute_Definition_Clause
4801 (U_Ent, Attribute_Storage_Size);
4803 if Present (SS) then
4804 Check_Pool_Size_Clash (U_Ent, N, SS);
4808 -- Storage_Pool case
4810 if Id = Attribute_Storage_Pool then
4812 (Expr, Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
4814 -- In the Simple_Storage_Pool case, we allow a variable of any
4815 -- simple storage pool type, so we Resolve without imposing an
4819 Analyze_And_Resolve (Expr);
4821 if not Present (Get_Rep_Pragma
4822 (Etype (Expr), Name_Simple_Storage_Pool_Type))
4825 ("expression must be of a simple storage pool type", Expr);
4829 if not Denotes_Variable (Expr) then
4830 Error_Msg_N ("storage pool must be a variable", Expr);
4834 if Nkind (Expr) = N_Type_Conversion then
4835 T := Etype (Expression (Expr));
4840 -- The Stack_Bounded_Pool is used internally for implementing
4841 -- access types with a Storage_Size. Since it only work properly
4842 -- when used on one specific type, we need to check that it is not
4843 -- hijacked improperly:
4845 -- type T is access Integer;
4846 -- for T'Storage_Size use n;
4847 -- type Q is access Float;
4848 -- for Q'Storage_Size use T'Storage_Size; -- incorrect
4850 if RTE_Available (RE_Stack_Bounded_Pool)
4851 and then Base_Type (T) = RTE (RE_Stack_Bounded_Pool)
4853 Error_Msg_N ("non-shareable internal Pool", Expr);
4857 -- If the argument is a name that is not an entity name, then
4858 -- we construct a renaming operation to define an entity of
4859 -- type storage pool.
4861 if not Is_Entity_Name (Expr)
4862 and then Is_Object_Reference (Expr)
4864 Pool := Make_Temporary (Loc, 'P', Expr);
4867 Rnode : constant Node_Id :=
4868 Make_Object_Renaming_Declaration (Loc,
4869 Defining_Identifier => Pool,
4871 New_Occurrence_Of (Etype (Expr), Loc),
4875 -- If the attribute definition clause comes from an aspect
4876 -- clause, then insert the renaming before the associated
4877 -- entity's declaration, since the attribute clause has
4878 -- not yet been appended to the declaration list.
4880 if From_Aspect_Specification (N) then
4881 Insert_Before (Parent (Entity (N)), Rnode);
4883 Insert_Before (N, Rnode);
4887 Set_Associated_Storage_Pool (U_Ent, Pool);
4890 elsif Is_Entity_Name (Expr) then
4891 Pool := Entity (Expr);
4893 -- If pool is a renamed object, get original one. This can
4894 -- happen with an explicit renaming, and within instances.
4896 while Present (Renamed_Object (Pool))
4897 and then Is_Entity_Name (Renamed_Object (Pool))
4899 Pool := Entity (Renamed_Object (Pool));
4902 if Present (Renamed_Object (Pool))
4903 and then Nkind (Renamed_Object (Pool)) = N_Type_Conversion
4904 and then Is_Entity_Name (Expression (Renamed_Object (Pool)))
4906 Pool := Entity (Expression (Renamed_Object (Pool)));
4909 Set_Associated_Storage_Pool (U_Ent, Pool);
4911 elsif Nkind (Expr) = N_Type_Conversion
4912 and then Is_Entity_Name (Expression (Expr))
4913 and then Nkind (Original_Node (Expr)) = N_Attribute_Reference
4915 Pool := Entity (Expression (Expr));
4916 Set_Associated_Storage_Pool (U_Ent, Pool);
4919 Error_Msg_N ("incorrect reference to a Storage Pool", Expr);
4928 -- Storage_Size attribute definition clause
4930 when Attribute_Storage_Size => Storage_Size : declare
4931 Btype : constant Entity_Id := Base_Type (U_Ent);
4934 if Is_Task_Type (U_Ent) then
4936 -- Check obsolescent (but never obsolescent if from aspect)
4938 if not From_Aspect_Specification (N) then
4939 Check_Restriction (No_Obsolescent_Features, N);
4941 if Warn_On_Obsolescent_Feature then
4943 ("?j?storage size clause for task is an " &
4944 "obsolescent feature (RM J.9)", N);
4945 Error_Msg_N ("\?j?use Storage_Size pragma instead", N);
4952 if not Is_Access_Type (U_Ent)
4953 and then Ekind (U_Ent) /= E_Task_Type
4955 Error_Msg_N ("storage size cannot be given for &", Nam);
4957 elsif Is_Access_Type (U_Ent) and Is_Derived_Type (U_Ent) then
4959 ("storage size cannot be given for a derived access type",
4962 elsif Duplicate_Clause then
4966 Analyze_And_Resolve (Expr, Any_Integer);
4968 if Is_Access_Type (U_Ent) then
4970 -- Check for Storage_Pool previously given
4973 SP : constant Node_Id :=
4974 Get_Attribute_Definition_Clause
4975 (U_Ent, Attribute_Storage_Pool);
4978 if Present (SP) then
4979 Check_Pool_Size_Clash (U_Ent, SP, N);
4983 -- Special case of for x'Storage_Size use 0
4985 if Is_OK_Static_Expression (Expr)
4986 and then Expr_Value (Expr) = 0
4988 Set_No_Pool_Assigned (Btype);
4992 Set_Has_Storage_Size_Clause (Btype);
5000 when Attribute_Stream_Size => Stream_Size : declare
5001 Size : constant Uint := Static_Integer (Expr);
5004 if Ada_Version <= Ada_95 then
5005 Check_Restriction (No_Implementation_Attributes, N);
5008 if Duplicate_Clause then
5011 elsif Is_Elementary_Type (U_Ent) then
5012 if Size /= System_Storage_Unit
5014 Size /= System_Storage_Unit * 2
5016 Size /= System_Storage_Unit * 4
5018 Size /= System_Storage_Unit * 8
5020 Error_Msg_Uint_1 := UI_From_Int (System_Storage_Unit);
5022 ("stream size for elementary type must be a"
5023 & " power of 2 and at least ^", N);
5025 elsif RM_Size (U_Ent) > Size then
5026 Error_Msg_Uint_1 := RM_Size (U_Ent);
5028 ("stream size for elementary type must be a"
5029 & " power of 2 and at least ^", N);
5032 Set_Has_Stream_Size_Clause (U_Ent);
5035 Error_Msg_N ("Stream_Size cannot be given for &", Nam);
5043 -- Value_Size attribute definition clause
5045 when Attribute_Value_Size => Value_Size : declare
5046 Size : constant Uint := Static_Integer (Expr);
5050 if not Is_Type (U_Ent) then
5051 Error_Msg_N ("Value_Size cannot be given for &", Nam);
5053 elsif Duplicate_Clause then
5056 elsif Is_Array_Type (U_Ent)
5057 and then not Is_Constrained (U_Ent)
5060 ("Value_Size cannot be given for unconstrained array", Nam);
5063 if Is_Elementary_Type (U_Ent) then
5064 Check_Size (Expr, U_Ent, Size, Biased);
5065 Set_Biased (U_Ent, N, "value size clause", Biased);
5068 Set_RM_Size (U_Ent, Size);
5072 -----------------------
5073 -- Variable_Indexing --
5074 -----------------------
5076 when Attribute_Variable_Indexing =>
5077 Check_Indexing_Functions;
5083 when Attribute_Write =>
5084 Analyze_Stream_TSS_Definition (TSS_Stream_Write);
5085 Set_Has_Specified_Stream_Write (Ent);
5087 -- All other attributes cannot be set
5091 ("attribute& cannot be set with definition clause", N);
5094 -- The test for the type being frozen must be performed after any
5095 -- expression the clause has been analyzed since the expression itself
5096 -- might cause freezing that makes the clause illegal.
5098 if Rep_Item_Too_Late (U_Ent, N, FOnly) then
5101 end Analyze_Attribute_Definition_Clause;
5103 ----------------------------
5104 -- Analyze_Code_Statement --
5105 ----------------------------
5107 procedure Analyze_Code_Statement (N : Node_Id) is
5108 HSS : constant Node_Id := Parent (N);
5109 SBody : constant Node_Id := Parent (HSS);
5110 Subp : constant Entity_Id := Current_Scope;
5117 -- Analyze and check we get right type, note that this implements the
5118 -- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that
5119 -- is the only way that Asm_Insn could possibly be visible.
5121 Analyze_And_Resolve (Expression (N));
5123 if Etype (Expression (N)) = Any_Type then
5125 elsif Etype (Expression (N)) /= RTE (RE_Asm_Insn) then
5126 Error_Msg_N ("incorrect type for code statement", N);
5130 Check_Code_Statement (N);
5132 -- Make sure we appear in the handled statement sequence of a
5133 -- subprogram (RM 13.8(3)).
5135 if Nkind (HSS) /= N_Handled_Sequence_Of_Statements
5136 or else Nkind (SBody) /= N_Subprogram_Body
5139 ("code statement can only appear in body of subprogram", N);
5143 -- Do remaining checks (RM 13.8(3)) if not already done
5145 if not Is_Machine_Code_Subprogram (Subp) then
5146 Set_Is_Machine_Code_Subprogram (Subp);
5148 -- No exception handlers allowed
5150 if Present (Exception_Handlers (HSS)) then
5152 ("exception handlers not permitted in machine code subprogram",
5153 First (Exception_Handlers (HSS)));
5156 -- No declarations other than use clauses and pragmas (we allow
5157 -- certain internally generated declarations as well).
5159 Decl := First (Declarations (SBody));
5160 while Present (Decl) loop
5161 DeclO := Original_Node (Decl);
5162 if Comes_From_Source (DeclO)
5163 and not Nkind_In (DeclO, N_Pragma,
5164 N_Use_Package_Clause,
5166 N_Implicit_Label_Declaration)
5169 ("this declaration not allowed in machine code subprogram",
5176 -- No statements other than code statements, pragmas, and labels.
5177 -- Again we allow certain internally generated statements.
5179 -- In Ada 2012, qualified expressions are names, and the code
5180 -- statement is initially parsed as a procedure call.
5182 Stmt := First (Statements (HSS));
5183 while Present (Stmt) loop
5184 StmtO := Original_Node (Stmt);
5186 -- A procedure call transformed into a code statement is OK.
5188 if Ada_Version >= Ada_2012
5189 and then Nkind (StmtO) = N_Procedure_Call_Statement
5190 and then Nkind (Name (StmtO)) = N_Qualified_Expression
5194 elsif Comes_From_Source (StmtO)
5195 and then not Nkind_In (StmtO, N_Pragma,
5200 ("this statement is not allowed in machine code subprogram",
5207 end Analyze_Code_Statement;
5209 -----------------------------------------------
5210 -- Analyze_Enumeration_Representation_Clause --
5211 -----------------------------------------------
5213 procedure Analyze_Enumeration_Representation_Clause (N : Node_Id) is
5214 Ident : constant Node_Id := Identifier (N);
5215 Aggr : constant Node_Id := Array_Aggregate (N);
5216 Enumtype : Entity_Id;
5223 Err : Boolean := False;
5224 -- Set True to avoid cascade errors and crashes on incorrect source code
5226 Lo : constant Uint := Expr_Value (Type_Low_Bound (Universal_Integer));
5227 Hi : constant Uint := Expr_Value (Type_High_Bound (Universal_Integer));
5228 -- Allowed range of universal integer (= allowed range of enum lit vals)
5232 -- Minimum and maximum values of entries
5235 -- Pointer to node for literal providing max value
5238 if Ignore_Rep_Clauses then
5242 -- Ignore enumeration rep clauses by default in CodePeer mode,
5243 -- unless -gnatd.I is specified, as a work around for potential false
5244 -- positive messages.
5246 if CodePeer_Mode and not Debug_Flag_Dot_II then
5250 -- First some basic error checks
5253 Enumtype := Entity (Ident);
5255 if Enumtype = Any_Type
5256 or else Rep_Item_Too_Early (Enumtype, N)
5260 Enumtype := Underlying_Type (Enumtype);
5263 if not Is_Enumeration_Type (Enumtype) then
5265 ("enumeration type required, found}",
5266 Ident, First_Subtype (Enumtype));
5270 -- Ignore rep clause on generic actual type. This will already have
5271 -- been flagged on the template as an error, and this is the safest
5272 -- way to ensure we don't get a junk cascaded message in the instance.
5274 if Is_Generic_Actual_Type (Enumtype) then
5277 -- Type must be in current scope
5279 elsif Scope (Enumtype) /= Current_Scope then
5280 Error_Msg_N ("type must be declared in this scope", Ident);
5283 -- Type must be a first subtype
5285 elsif not Is_First_Subtype (Enumtype) then
5286 Error_Msg_N ("cannot give enumeration rep clause for subtype", N);
5289 -- Ignore duplicate rep clause
5291 elsif Has_Enumeration_Rep_Clause (Enumtype) then
5292 Error_Msg_N ("duplicate enumeration rep clause ignored", N);
5295 -- Don't allow rep clause for standard [wide_[wide_]]character
5297 elsif Is_Standard_Character_Type (Enumtype) then
5298 Error_Msg_N ("enumeration rep clause not allowed for this type", N);
5301 -- Check that the expression is a proper aggregate (no parentheses)
5303 elsif Paren_Count (Aggr) /= 0 then
5305 ("extra parentheses surrounding aggregate not allowed",
5309 -- All tests passed, so set rep clause in place
5312 Set_Has_Enumeration_Rep_Clause (Enumtype);
5313 Set_Has_Enumeration_Rep_Clause (Base_Type (Enumtype));
5316 -- Now we process the aggregate. Note that we don't use the normal
5317 -- aggregate code for this purpose, because we don't want any of the
5318 -- normal expansion activities, and a number of special semantic
5319 -- rules apply (including the component type being any integer type)
5321 Elit := First_Literal (Enumtype);
5323 -- First the positional entries if any
5325 if Present (Expressions (Aggr)) then
5326 Expr := First (Expressions (Aggr));
5327 while Present (Expr) loop
5329 Error_Msg_N ("too many entries in aggregate", Expr);
5333 Val := Static_Integer (Expr);
5335 -- Err signals that we found some incorrect entries processing
5336 -- the list. The final checks for completeness and ordering are
5337 -- skipped in this case.
5339 if Val = No_Uint then
5341 elsif Val < Lo or else Hi < Val then
5342 Error_Msg_N ("value outside permitted range", Expr);
5346 Set_Enumeration_Rep (Elit, Val);
5347 Set_Enumeration_Rep_Expr (Elit, Expr);
5353 -- Now process the named entries if present
5355 if Present (Component_Associations (Aggr)) then
5356 Assoc := First (Component_Associations (Aggr));
5357 while Present (Assoc) loop
5358 Choice := First (Choices (Assoc));
5360 if Present (Next (Choice)) then
5362 ("multiple choice not allowed here", Next (Choice));
5366 if Nkind (Choice) = N_Others_Choice then
5367 Error_Msg_N ("others choice not allowed here", Choice);
5370 elsif Nkind (Choice) = N_Range then
5372 -- ??? should allow zero/one element range here
5374 Error_Msg_N ("range not allowed here", Choice);
5378 Analyze_And_Resolve (Choice, Enumtype);
5380 if Error_Posted (Choice) then
5385 if Is_Entity_Name (Choice)
5386 and then Is_Type (Entity (Choice))
5388 Error_Msg_N ("subtype name not allowed here", Choice);
5391 -- ??? should allow static subtype with zero/one entry
5393 elsif Etype (Choice) = Base_Type (Enumtype) then
5394 if not Is_Static_Expression (Choice) then
5395 Flag_Non_Static_Expr
5396 ("non-static expression used for choice!", Choice);
5400 Elit := Expr_Value_E (Choice);
5402 if Present (Enumeration_Rep_Expr (Elit)) then
5404 Sloc (Enumeration_Rep_Expr (Elit));
5406 ("representation for& previously given#",
5411 Set_Enumeration_Rep_Expr (Elit, Expression (Assoc));
5413 Expr := Expression (Assoc);
5414 Val := Static_Integer (Expr);
5416 if Val = No_Uint then
5419 elsif Val < Lo or else Hi < Val then
5420 Error_Msg_N ("value outside permitted range", Expr);
5424 Set_Enumeration_Rep (Elit, Val);
5434 -- Aggregate is fully processed. Now we check that a full set of
5435 -- representations was given, and that they are in range and in order.
5436 -- These checks are only done if no other errors occurred.
5442 Elit := First_Literal (Enumtype);
5443 while Present (Elit) loop
5444 if No (Enumeration_Rep_Expr (Elit)) then
5445 Error_Msg_NE ("missing representation for&!", N, Elit);
5448 Val := Enumeration_Rep (Elit);
5450 if Min = No_Uint then
5454 if Val /= No_Uint then
5455 if Max /= No_Uint and then Val <= Max then
5457 ("enumeration value for& not ordered!",
5458 Enumeration_Rep_Expr (Elit), Elit);
5461 Max_Node := Enumeration_Rep_Expr (Elit);
5465 -- If there is at least one literal whose representation is not
5466 -- equal to the Pos value, then note that this enumeration type
5467 -- has a non-standard representation.
5469 if Val /= Enumeration_Pos (Elit) then
5470 Set_Has_Non_Standard_Rep (Base_Type (Enumtype));
5477 -- Now set proper size information
5480 Minsize : Uint := UI_From_Int (Minimum_Size (Enumtype));
5483 if Has_Size_Clause (Enumtype) then
5485 -- All OK, if size is OK now
5487 if RM_Size (Enumtype) >= Minsize then
5491 -- Try if we can get by with biasing
5494 UI_From_Int (Minimum_Size (Enumtype, Biased => True));
5496 -- Error message if even biasing does not work
5498 if RM_Size (Enumtype) < Minsize then
5499 Error_Msg_Uint_1 := RM_Size (Enumtype);
5500 Error_Msg_Uint_2 := Max;
5502 ("previously given size (^) is too small "
5503 & "for this value (^)", Max_Node);
5505 -- If biasing worked, indicate that we now have biased rep
5509 (Enumtype, Size_Clause (Enumtype), "size clause");
5514 Set_RM_Size (Enumtype, Minsize);
5515 Set_Enum_Esize (Enumtype);
5518 Set_RM_Size (Base_Type (Enumtype), RM_Size (Enumtype));
5519 Set_Esize (Base_Type (Enumtype), Esize (Enumtype));
5520 Set_Alignment (Base_Type (Enumtype), Alignment (Enumtype));
5524 -- We repeat the too late test in case it froze itself
5526 if Rep_Item_Too_Late (Enumtype, N) then
5529 end Analyze_Enumeration_Representation_Clause;
5531 ----------------------------
5532 -- Analyze_Free_Statement --
5533 ----------------------------
5535 procedure Analyze_Free_Statement (N : Node_Id) is
5537 Analyze (Expression (N));
5538 end Analyze_Free_Statement;
5540 ---------------------------
5541 -- Analyze_Freeze_Entity --
5542 ---------------------------
5544 procedure Analyze_Freeze_Entity (N : Node_Id) is
5546 Freeze_Entity_Checks (N);
5547 end Analyze_Freeze_Entity;
5549 -----------------------------------
5550 -- Analyze_Freeze_Generic_Entity --
5551 -----------------------------------
5553 procedure Analyze_Freeze_Generic_Entity (N : Node_Id) is
5555 Freeze_Entity_Checks (N);
5556 end Analyze_Freeze_Generic_Entity;
5558 ------------------------------------------
5559 -- Analyze_Record_Representation_Clause --
5560 ------------------------------------------
5562 -- Note: we check as much as we can here, but we can't do any checks
5563 -- based on the position values (e.g. overlap checks) until freeze time
5564 -- because especially in Ada 2005 (machine scalar mode), the processing
5565 -- for non-standard bit order can substantially change the positions.
5566 -- See procedure Check_Record_Representation_Clause (called from Freeze)
5567 -- for the remainder of this processing.
5569 procedure Analyze_Record_Representation_Clause (N : Node_Id) is
5570 Ident : constant Node_Id := Identifier (N);
5575 Hbit : Uint := Uint_0;
5579 Rectype : Entity_Id;
5582 function Is_Inherited (Comp : Entity_Id) return Boolean;
5583 -- True if Comp is an inherited component in a record extension
5589 function Is_Inherited (Comp : Entity_Id) return Boolean is
5590 Comp_Base : Entity_Id;
5593 if Ekind (Rectype) = E_Record_Subtype then
5594 Comp_Base := Original_Record_Component (Comp);
5599 return Comp_Base /= Original_Record_Component (Comp_Base);
5604 Is_Record_Extension : Boolean;
5605 -- True if Rectype is a record extension
5607 CR_Pragma : Node_Id := Empty;
5608 -- Points to N_Pragma node if Complete_Representation pragma present
5610 -- Start of processing for Analyze_Record_Representation_Clause
5613 if Ignore_Rep_Clauses then
5618 Rectype := Entity (Ident);
5620 if Rectype = Any_Type or else Rep_Item_Too_Early (Rectype, N) then
5623 Rectype := Underlying_Type (Rectype);
5626 -- First some basic error checks
5628 if not Is_Record_Type (Rectype) then
5630 ("record type required, found}", Ident, First_Subtype (Rectype));
5633 elsif Scope (Rectype) /= Current_Scope then
5634 Error_Msg_N ("type must be declared in this scope", N);
5637 elsif not Is_First_Subtype (Rectype) then
5638 Error_Msg_N ("cannot give record rep clause for subtype", N);
5641 elsif Has_Record_Rep_Clause (Rectype) then
5642 Error_Msg_N ("duplicate record rep clause ignored", N);
5645 elsif Rep_Item_Too_Late (Rectype, N) then
5649 -- We know we have a first subtype, now possibly go the the anonymous
5650 -- base type to determine whether Rectype is a record extension.
5652 Recdef := Type_Definition (Declaration_Node (Base_Type (Rectype)));
5653 Is_Record_Extension :=
5654 Nkind (Recdef) = N_Derived_Type_Definition
5655 and then Present (Record_Extension_Part (Recdef));
5657 if Present (Mod_Clause (N)) then
5659 Loc : constant Source_Ptr := Sloc (N);
5660 M : constant Node_Id := Mod_Clause (N);
5661 P : constant List_Id := Pragmas_Before (M);
5665 pragma Warnings (Off, Mod_Val);
5668 Check_Restriction (No_Obsolescent_Features, Mod_Clause (N));
5670 if Warn_On_Obsolescent_Feature then
5672 ("?j?mod clause is an obsolescent feature (RM J.8)", N);
5674 ("\?j?use alignment attribute definition clause instead", N);
5681 -- In ASIS_Mode mode, expansion is disabled, but we must convert
5682 -- the Mod clause into an alignment clause anyway, so that the
5683 -- back-end can compute and back-annotate properly the size and
5684 -- alignment of types that may include this record.
5686 -- This seems dubious, this destroys the source tree in a manner
5687 -- not detectable by ASIS ???
5689 if Operating_Mode = Check_Semantics and then ASIS_Mode then
5691 Make_Attribute_Definition_Clause (Loc,
5692 Name => New_Occurrence_Of (Base_Type (Rectype), Loc),
5693 Chars => Name_Alignment,
5694 Expression => Relocate_Node (Expression (M)));
5696 Set_From_At_Mod (AtM_Nod);
5697 Insert_After (N, AtM_Nod);
5698 Mod_Val := Get_Alignment_Value (Expression (AtM_Nod));
5699 Set_Mod_Clause (N, Empty);
5702 -- Get the alignment value to perform error checking
5704 Mod_Val := Get_Alignment_Value (Expression (M));
5709 -- For untagged types, clear any existing component clauses for the
5710 -- type. If the type is derived, this is what allows us to override
5711 -- a rep clause for the parent. For type extensions, the representation
5712 -- of the inherited components is inherited, so we want to keep previous
5713 -- component clauses for completeness.
5715 if not Is_Tagged_Type (Rectype) then
5716 Comp := First_Component_Or_Discriminant (Rectype);
5717 while Present (Comp) loop
5718 Set_Component_Clause (Comp, Empty);
5719 Next_Component_Or_Discriminant (Comp);
5723 -- All done if no component clauses
5725 CC := First (Component_Clauses (N));
5731 -- A representation like this applies to the base type
5733 Set_Has_Record_Rep_Clause (Base_Type (Rectype));
5734 Set_Has_Non_Standard_Rep (Base_Type (Rectype));
5735 Set_Has_Specified_Layout (Base_Type (Rectype));
5737 -- Process the component clauses
5739 while Present (CC) loop
5743 if Nkind (CC) = N_Pragma then
5746 -- The only pragma of interest is Complete_Representation
5748 if Pragma_Name (CC) = Name_Complete_Representation then
5752 -- Processing for real component clause
5755 Posit := Static_Integer (Position (CC));
5756 Fbit := Static_Integer (First_Bit (CC));
5757 Lbit := Static_Integer (Last_Bit (CC));
5760 and then Fbit /= No_Uint
5761 and then Lbit /= No_Uint
5765 ("position cannot be negative", Position (CC));
5769 ("first bit cannot be negative", First_Bit (CC));
5771 -- The Last_Bit specified in a component clause must not be
5772 -- less than the First_Bit minus one (RM-13.5.1(10)).
5774 elsif Lbit < Fbit - 1 then
5776 ("last bit cannot be less than first bit minus one",
5779 -- Values look OK, so find the corresponding record component
5780 -- Even though the syntax allows an attribute reference for
5781 -- implementation-defined components, GNAT does not allow the
5782 -- tag to get an explicit position.
5784 elsif Nkind (Component_Name (CC)) = N_Attribute_Reference then
5785 if Attribute_Name (Component_Name (CC)) = Name_Tag then
5786 Error_Msg_N ("position of tag cannot be specified", CC);
5788 Error_Msg_N ("illegal component name", CC);
5792 Comp := First_Entity (Rectype);
5793 while Present (Comp) loop
5794 exit when Chars (Comp) = Chars (Component_Name (CC));
5800 -- Maybe component of base type that is absent from
5801 -- statically constrained first subtype.
5803 Comp := First_Entity (Base_Type (Rectype));
5804 while Present (Comp) loop
5805 exit when Chars (Comp) = Chars (Component_Name (CC));
5812 ("component clause is for non-existent field", CC);
5814 -- Ada 2012 (AI05-0026): Any name that denotes a
5815 -- discriminant of an object of an unchecked union type
5816 -- shall not occur within a record_representation_clause.
5818 -- The general restriction of using record rep clauses on
5819 -- Unchecked_Union types has now been lifted. Since it is
5820 -- possible to introduce a record rep clause which mentions
5821 -- the discriminant of an Unchecked_Union in non-Ada 2012
5822 -- code, this check is applied to all versions of the
5825 elsif Ekind (Comp) = E_Discriminant
5826 and then Is_Unchecked_Union (Rectype)
5829 ("cannot reference discriminant of unchecked union",
5830 Component_Name (CC));
5832 elsif Is_Record_Extension and then Is_Inherited (Comp) then
5834 ("component clause not allowed for inherited "
5835 & "component&", CC, Comp);
5837 elsif Present (Component_Clause (Comp)) then
5839 -- Diagnose duplicate rep clause, or check consistency
5840 -- if this is an inherited component. In a double fault,
5841 -- there may be a duplicate inconsistent clause for an
5842 -- inherited component.
5844 if Scope (Original_Record_Component (Comp)) = Rectype
5845 or else Parent (Component_Clause (Comp)) = N
5847 Error_Msg_Sloc := Sloc (Component_Clause (Comp));
5848 Error_Msg_N ("component clause previously given#", CC);
5852 Rep1 : constant Node_Id := Component_Clause (Comp);
5854 if Intval (Position (Rep1)) /=
5855 Intval (Position (CC))
5856 or else Intval (First_Bit (Rep1)) /=
5857 Intval (First_Bit (CC))
5858 or else Intval (Last_Bit (Rep1)) /=
5859 Intval (Last_Bit (CC))
5862 ("component clause inconsistent "
5863 & "with representation of ancestor", CC);
5865 elsif Warn_On_Redundant_Constructs then
5867 ("?r?redundant confirming component clause "
5868 & "for component!", CC);
5873 -- Normal case where this is the first component clause we
5874 -- have seen for this entity, so set it up properly.
5877 -- Make reference for field in record rep clause and set
5878 -- appropriate entity field in the field identifier.
5881 (Comp, Component_Name (CC), Set_Ref => False);
5882 Set_Entity (Component_Name (CC), Comp);
5884 -- Update Fbit and Lbit to the actual bit number
5886 Fbit := Fbit + UI_From_Int (SSU) * Posit;
5887 Lbit := Lbit + UI_From_Int (SSU) * Posit;
5889 if Has_Size_Clause (Rectype)
5890 and then RM_Size (Rectype) <= Lbit
5893 ("bit number out of range of specified size",
5896 Set_Component_Clause (Comp, CC);
5897 Set_Component_Bit_Offset (Comp, Fbit);
5898 Set_Esize (Comp, 1 + (Lbit - Fbit));
5899 Set_Normalized_First_Bit (Comp, Fbit mod SSU);
5900 Set_Normalized_Position (Comp, Fbit / SSU);
5902 if Warn_On_Overridden_Size
5903 and then Has_Size_Clause (Etype (Comp))
5904 and then RM_Size (Etype (Comp)) /= Esize (Comp)
5907 ("?S?component size overrides size clause for&",
5908 Component_Name (CC), Etype (Comp));
5911 -- This information is also set in the corresponding
5912 -- component of the base type, found by accessing the
5913 -- Original_Record_Component link if it is present.
5915 Ocomp := Original_Record_Component (Comp);
5922 (Component_Name (CC),
5928 (Comp, First_Node (CC), "component clause", Biased);
5930 if Present (Ocomp) then
5931 Set_Component_Clause (Ocomp, CC);
5932 Set_Component_Bit_Offset (Ocomp, Fbit);
5933 Set_Normalized_First_Bit (Ocomp, Fbit mod SSU);
5934 Set_Normalized_Position (Ocomp, Fbit / SSU);
5935 Set_Esize (Ocomp, 1 + (Lbit - Fbit));
5937 Set_Normalized_Position_Max
5938 (Ocomp, Normalized_Position (Ocomp));
5940 -- Note: we don't use Set_Biased here, because we
5941 -- already gave a warning above if needed, and we
5942 -- would get a duplicate for the same name here.
5944 Set_Has_Biased_Representation
5945 (Ocomp, Has_Biased_Representation (Comp));
5948 if Esize (Comp) < 0 then
5949 Error_Msg_N ("component size is negative", CC);
5960 -- Check missing components if Complete_Representation pragma appeared
5962 if Present (CR_Pragma) then
5963 Comp := First_Component_Or_Discriminant (Rectype);
5964 while Present (Comp) loop
5965 if No (Component_Clause (Comp)) then
5967 ("missing component clause for &", CR_Pragma, Comp);
5970 Next_Component_Or_Discriminant (Comp);
5973 -- Give missing components warning if required
5975 elsif Warn_On_Unrepped_Components then
5977 Num_Repped_Components : Nat := 0;
5978 Num_Unrepped_Components : Nat := 0;
5981 -- First count number of repped and unrepped components
5983 Comp := First_Component_Or_Discriminant (Rectype);
5984 while Present (Comp) loop
5985 if Present (Component_Clause (Comp)) then
5986 Num_Repped_Components := Num_Repped_Components + 1;
5988 Num_Unrepped_Components := Num_Unrepped_Components + 1;
5991 Next_Component_Or_Discriminant (Comp);
5994 -- We are only interested in the case where there is at least one
5995 -- unrepped component, and at least half the components have rep
5996 -- clauses. We figure that if less than half have them, then the
5997 -- partial rep clause is really intentional. If the component
5998 -- type has no underlying type set at this point (as for a generic
5999 -- formal type), we don't know enough to give a warning on the
6002 if Num_Unrepped_Components > 0
6003 and then Num_Unrepped_Components < Num_Repped_Components
6005 Comp := First_Component_Or_Discriminant (Rectype);
6006 while Present (Comp) loop
6007 if No (Component_Clause (Comp))
6008 and then Comes_From_Source (Comp)
6009 and then Present (Underlying_Type (Etype (Comp)))
6010 and then (Is_Scalar_Type (Underlying_Type (Etype (Comp)))
6011 or else Size_Known_At_Compile_Time
6012 (Underlying_Type (Etype (Comp))))
6013 and then not Has_Warnings_Off (Rectype)
6015 Error_Msg_Sloc := Sloc (Comp);
6017 ("?C?no component clause given for & declared #",
6021 Next_Component_Or_Discriminant (Comp);
6026 end Analyze_Record_Representation_Clause;
6028 -------------------------------------------
6029 -- Build_Invariant_Procedure_Declaration --
6030 -------------------------------------------
6032 function Build_Invariant_Procedure_Declaration
6033 (Typ : Entity_Id) return Node_Id
6035 Loc : constant Source_Ptr := Sloc (Typ);
6036 Object_Entity : constant Entity_Id :=
6037 Make_Defining_Identifier (Loc, New_Internal_Name ('I'));
6042 Set_Etype (Object_Entity, Typ);
6044 -- Check for duplicate definiations.
6046 if Has_Invariants (Typ) and then Present (Invariant_Procedure (Typ)) then
6051 Make_Defining_Identifier (Loc,
6052 Chars => New_External_Name (Chars (Typ), "Invariant"));
6053 Set_Has_Invariants (Typ);
6054 Set_Ekind (SId, E_Procedure);
6055 Set_Is_Invariant_Procedure (SId);
6056 Set_Invariant_Procedure (Typ, SId);
6059 Make_Procedure_Specification (Loc,
6060 Defining_Unit_Name => SId,
6061 Parameter_Specifications => New_List (
6062 Make_Parameter_Specification (Loc,
6063 Defining_Identifier => Object_Entity,
6064 Parameter_Type => New_Occurrence_Of (Typ, Loc))));
6066 return Make_Subprogram_Declaration (Loc, Specification => Spec);
6067 end Build_Invariant_Procedure_Declaration;
6069 -------------------------------
6070 -- Build_Invariant_Procedure --
6071 -------------------------------
6073 -- The procedure that is constructed here has the form
6075 -- procedure typInvariant (Ixxx : typ) is
6077 -- pragma Check (Invariant, exp, "failed invariant from xxx");
6078 -- pragma Check (Invariant, exp, "failed invariant from xxx");
6080 -- pragma Check (Invariant, exp, "failed inherited invariant from xxx");
6082 -- end typInvariant;
6084 procedure Build_Invariant_Procedure (Typ : Entity_Id; N : Node_Id) is
6085 Loc : constant Source_Ptr := Sloc (Typ);
6092 Visible_Decls : constant List_Id := Visible_Declarations (N);
6093 Private_Decls : constant List_Id := Private_Declarations (N);
6095 procedure Add_Invariants (T : Entity_Id; Inherit : Boolean);
6096 -- Appends statements to Stmts for any invariants in the rep item chain
6097 -- of the given type. If Inherit is False, then we only process entries
6098 -- on the chain for the type Typ. If Inherit is True, then we ignore any
6099 -- Invariant aspects, but we process all Invariant'Class aspects, adding
6100 -- "inherited" to the exception message and generating an informational
6101 -- message about the inheritance of an invariant.
6103 Object_Name : Name_Id;
6104 -- Name for argument of invariant procedure
6106 Object_Entity : Node_Id;
6107 -- The entity of the formal for the procedure
6109 --------------------
6110 -- Add_Invariants --
6111 --------------------
6113 procedure Add_Invariants (T : Entity_Id; Inherit : Boolean) is
6123 procedure Replace_Type_Reference (N : Node_Id);
6124 -- Replace a single occurrence N of the subtype name with a reference
6125 -- to the formal of the predicate function. N can be an identifier
6126 -- referencing the subtype, or a selected component, representing an
6127 -- appropriately qualified occurrence of the subtype name.
6129 procedure Replace_Type_References is
6130 new Replace_Type_References_Generic (Replace_Type_Reference);
6131 -- Traverse an expression replacing all occurrences of the subtype
6132 -- name with appropriate references to the object that is the formal
6133 -- parameter of the predicate function. Note that we must ensure
6134 -- that the type and entity information is properly set in the
6135 -- replacement node, since we will do a Preanalyze call of this
6136 -- expression without proper visibility of the procedure argument.
6138 ----------------------------
6139 -- Replace_Type_Reference --
6140 ----------------------------
6142 -- Note: See comments in Add_Predicates.Replace_Type_Reference
6143 -- regarding handling of Sloc and Comes_From_Source.
6145 procedure Replace_Type_Reference (N : Node_Id) is
6148 -- Add semantic information to node to be rewritten, for ASIS
6149 -- navigation needs.
6151 if Nkind (N) = N_Identifier then
6155 elsif Nkind (N) = N_Selected_Component then
6156 Analyze (Prefix (N));
6157 Set_Entity (Selector_Name (N), T);
6158 Set_Etype (Selector_Name (N), T);
6161 -- Invariant'Class, replace with T'Class (obj)
6163 if Class_Present (Ritem) then
6165 Make_Type_Conversion (Sloc (N),
6167 Make_Attribute_Reference (Sloc (N),
6168 Prefix => New_Occurrence_Of (T, Sloc (N)),
6169 Attribute_Name => Name_Class),
6170 Expression => Make_Identifier (Sloc (N), Object_Name)));
6172 Set_Entity (Expression (N), Object_Entity);
6173 Set_Etype (Expression (N), Typ);
6175 -- Invariant, replace with obj
6178 Rewrite (N, Make_Identifier (Sloc (N), Object_Name));
6179 Set_Entity (N, Object_Entity);
6183 Set_Comes_From_Source (N, True);
6184 end Replace_Type_Reference;
6186 -- Start of processing for Add_Invariants
6189 Ritem := First_Rep_Item (T);
6190 while Present (Ritem) loop
6191 if Nkind (Ritem) = N_Pragma
6192 and then Pragma_Name (Ritem) = Name_Invariant
6194 Arg1 := First (Pragma_Argument_Associations (Ritem));
6195 Arg2 := Next (Arg1);
6196 Arg3 := Next (Arg2);
6198 Arg1 := Get_Pragma_Arg (Arg1);
6199 Arg2 := Get_Pragma_Arg (Arg2);
6201 -- For Inherit case, ignore Invariant, process only Class case
6204 if not Class_Present (Ritem) then
6208 -- For Inherit false, process only item for right type
6211 if Entity (Arg1) /= Typ then
6217 Stmts := Empty_List;
6220 Exp := New_Copy_Tree (Arg2);
6222 -- Preserve sloc of original pragma Invariant
6224 Loc := Sloc (Ritem);
6226 -- We need to replace any occurrences of the name of the type
6227 -- with references to the object, converted to type'Class in
6228 -- the case of Invariant'Class aspects.
6230 Replace_Type_References (Exp, Chars (T));
6232 -- If this invariant comes from an aspect, find the aspect
6233 -- specification, and replace the saved expression because
6234 -- we need the subtype references replaced for the calls to
6235 -- Preanalyze_Spec_Expressin in Check_Aspect_At_Freeze_Point
6236 -- and Check_Aspect_At_End_Of_Declarations.
6238 if From_Aspect_Specification (Ritem) then
6243 -- Loop to find corresponding aspect, note that this
6244 -- must be present given the pragma is marked delayed.
6246 Aitem := Next_Rep_Item (Ritem);
6247 while Present (Aitem) loop
6248 if Nkind (Aitem) = N_Aspect_Specification
6249 and then Aspect_Rep_Item (Aitem) = Ritem
6252 (Identifier (Aitem), New_Copy_Tree (Exp));
6256 Aitem := Next_Rep_Item (Aitem);
6261 -- Now we need to preanalyze the expression to properly capture
6262 -- the visibility in the visible part. The expression will not
6263 -- be analyzed for real until the body is analyzed, but that is
6264 -- at the end of the private part and has the wrong visibility.
6266 Set_Parent (Exp, N);
6267 Preanalyze_Assert_Expression (Exp, Standard_Boolean);
6269 -- In ASIS mode, even if assertions are not enabled, we must
6270 -- analyze the original expression in the aspect specification
6271 -- because it is part of the original tree.
6275 Inv : constant Node_Id :=
6276 Expression (Corresponding_Aspect (Ritem));
6278 Replace_Type_References (Inv, Chars (T));
6279 Preanalyze_Assert_Expression (Inv, Standard_Boolean);
6283 -- Build first two arguments for Check pragma
6286 Make_Pragma_Argument_Association (Loc,
6287 Expression => Make_Identifier (Loc, Name_Invariant)),
6288 Make_Pragma_Argument_Association (Loc,
6289 Expression => Exp));
6291 -- Add message if present in Invariant pragma
6293 if Present (Arg3) then
6294 Str := Strval (Get_Pragma_Arg (Arg3));
6296 -- If inherited case, and message starts "failed invariant",
6297 -- change it to be "failed inherited invariant".
6300 String_To_Name_Buffer (Str);
6302 if Name_Buffer (1 .. 16) = "failed invariant" then
6303 Insert_Str_In_Name_Buffer ("inherited ", 8);
6304 Str := String_From_Name_Buffer;
6309 Make_Pragma_Argument_Association (Loc,
6310 Expression => Make_String_Literal (Loc, Str)));
6313 -- Add Check pragma to list of statements
6317 Pragma_Identifier =>
6318 Make_Identifier (Loc, Name_Check),
6319 Pragma_Argument_Associations => Assoc));
6321 -- If Inherited case and option enabled, output info msg. Note
6322 -- that we know this is a case of Invariant'Class.
6324 if Inherit and Opt.List_Inherited_Aspects then
6325 Error_Msg_Sloc := Sloc (Ritem);
6327 ("info: & inherits `Invariant''Class` aspect from #?L?",
6333 Next_Rep_Item (Ritem);
6337 -- Start of processing for Build_Invariant_Procedure
6345 -- If the aspect specification exists for some view of the type, the
6346 -- declaration for the procedure has been created.
6348 if Has_Invariants (Typ) then
6349 SId := Invariant_Procedure (Typ);
6352 if Present (SId) then
6353 PDecl := Unit_Declaration_Node (SId);
6355 PDecl := Build_Invariant_Procedure_Declaration (Typ);
6358 -- Recover formal of procedure, for use in the calls to invariant
6359 -- functions (including inherited ones).
6363 (First (Parameter_Specifications (Specification (PDecl))));
6364 Object_Name := Chars (Object_Entity);
6366 -- Add invariants for the current type
6368 Add_Invariants (Typ, Inherit => False);
6370 -- Add invariants for parent types
6373 Current_Typ : Entity_Id;
6374 Parent_Typ : Entity_Id;
6379 Parent_Typ := Etype (Current_Typ);
6381 if Is_Private_Type (Parent_Typ)
6382 and then Present (Full_View (Base_Type (Parent_Typ)))
6384 Parent_Typ := Full_View (Base_Type (Parent_Typ));
6387 exit when Parent_Typ = Current_Typ;
6389 Current_Typ := Parent_Typ;
6390 Add_Invariants (Current_Typ, Inherit => True);
6394 -- Build the procedure if we generated at least one Check pragma
6396 if Stmts /= No_List then
6397 Spec := Copy_Separate_Tree (Specification (PDecl));
6400 Make_Subprogram_Body (Loc,
6401 Specification => Spec,
6402 Declarations => Empty_List,
6403 Handled_Statement_Sequence =>
6404 Make_Handled_Sequence_Of_Statements (Loc,
6405 Statements => Stmts));
6407 -- Insert procedure declaration and spec at the appropriate points.
6408 -- If declaration is already analyzed, it was processed by the
6409 -- generated pragma.
6411 if Present (Private_Decls) then
6413 -- The spec goes at the end of visible declarations, but they have
6414 -- already been analyzed, so we need to explicitly do the analyze.
6416 if not Analyzed (PDecl) then
6417 Append_To (Visible_Decls, PDecl);
6421 -- The body goes at the end of the private declarations, which we
6422 -- have not analyzed yet, so we do not need to perform an explicit
6423 -- analyze call. We skip this if there are no private declarations
6424 -- (this is an error that will be caught elsewhere);
6426 Append_To (Private_Decls, PBody);
6428 -- If the invariant appears on the full view of a type, the
6429 -- analysis of the private part is complete, and we must
6430 -- analyze the new body explicitly.
6432 if In_Private_Part (Current_Scope) then
6436 -- If there are no private declarations this may be an error that
6437 -- will be diagnosed elsewhere. However, if this is a non-private
6438 -- type that inherits invariants, it needs no completion and there
6439 -- may be no private part. In this case insert invariant procedure
6440 -- at end of current declarative list, and analyze at once, given
6441 -- that the type is about to be frozen.
6443 elsif not Is_Private_Type (Typ) then
6444 Append_To (Visible_Decls, PDecl);
6445 Append_To (Visible_Decls, PBody);
6450 end Build_Invariant_Procedure;
6452 -------------------------------
6453 -- Build_Predicate_Functions --
6454 -------------------------------
6456 -- The procedures that are constructed here have the form:
6458 -- function typPredicate (Ixxx : typ) return Boolean is
6461 -- exp1 and then exp2 and then ...
6462 -- and then typ1Predicate (typ1 (Ixxx))
6463 -- and then typ2Predicate (typ2 (Ixxx))
6465 -- end typPredicate;
6467 -- Here exp1, and exp2 are expressions from Predicate pragmas. Note that
6468 -- this is the point at which these expressions get analyzed, providing the
6469 -- required delay, and typ1, typ2, are entities from which predicates are
6470 -- inherited. Note that we do NOT generate Check pragmas, that's because we
6471 -- use this function even if checks are off, e.g. for membership tests.
6473 -- If the expression has at least one Raise_Expression, then we also build
6474 -- the typPredicateM version of the function, in which any occurrence of a
6475 -- Raise_Expression is converted to "return False".
6477 procedure Build_Predicate_Functions (Typ : Entity_Id; N : Node_Id) is
6478 Loc : constant Source_Ptr := Sloc (Typ);
6481 -- This is the expression for the result of the function. It is
6482 -- is build by connecting the component predicates with AND THEN.
6485 -- This is the corresponding return expression for the Predicate_M
6486 -- function. It differs in that raise expressions are marked for
6487 -- special expansion (see Process_REs).
6489 Object_Name : constant Name_Id := New_Internal_Name ('I');
6490 -- Name for argument of Predicate procedure. Note that we use the same
6491 -- name for both predicate procedure. That way the reference within the
6492 -- predicate expression is the same in both functions.
6494 Object_Entity : constant Entity_Id :=
6495 Make_Defining_Identifier (Loc, Chars => Object_Name);
6496 -- Entity for argument of Predicate procedure
6498 Object_Entity_M : constant Entity_Id :=
6499 Make_Defining_Identifier (Loc, Chars => Object_Name);
6500 -- Entity for argument of Predicate_M procedure
6502 Raise_Expression_Present : Boolean := False;
6503 -- Set True if Expr has at least one Raise_Expression
6505 Static_Predic : Node_Id := Empty;
6506 -- Set to N_Pragma node for a static predicate if one is encountered
6508 procedure Add_Call (T : Entity_Id);
6509 -- Includes a call to the predicate function for type T in Expr if T
6510 -- has predicates and Predicate_Function (T) is non-empty.
6512 procedure Add_Predicates;
6513 -- Appends expressions for any Predicate pragmas in the rep item chain
6514 -- Typ to Expr. Note that we look only at items for this exact entity.
6515 -- Inheritance of predicates for the parent type is done by calling the
6516 -- Predicate_Function of the parent type, using Add_Call above.
6518 function Test_RE (N : Node_Id) return Traverse_Result;
6519 -- Used in Test_REs, tests one node for being a raise expression, and if
6520 -- so sets Raise_Expression_Present True.
6522 procedure Test_REs is new Traverse_Proc (Test_RE);
6523 -- Tests to see if Expr contains any raise expressions
6525 function Process_RE (N : Node_Id) return Traverse_Result;
6526 -- Used in Process REs, tests if node N is a raise expression, and if
6527 -- so, marks it to be converted to return False.
6529 procedure Process_REs is new Traverse_Proc (Process_RE);
6530 -- Marks any raise expressions in Expr_M to return False
6536 procedure Add_Call (T : Entity_Id) is
6540 if Present (T) and then Present (Predicate_Function (T)) then
6541 Set_Has_Predicates (Typ);
6543 -- Build the call to the predicate function of T
6547 (T, Convert_To (T, Make_Identifier (Loc, Object_Name)));
6549 -- Add call to evolving expression, using AND THEN if needed
6556 Left_Opnd => Relocate_Node (Expr),
6560 -- Output info message on inheritance if required. Note we do not
6561 -- give this information for generic actual types, since it is
6562 -- unwelcome noise in that case in instantiations. We also
6563 -- generally suppress the message in instantiations, and also
6564 -- if it involves internal names.
6566 if Opt.List_Inherited_Aspects
6567 and then not Is_Generic_Actual_Type (Typ)
6568 and then Instantiation_Depth (Sloc (Typ)) = 0
6569 and then not Is_Internal_Name (Chars (T))
6570 and then not Is_Internal_Name (Chars (Typ))
6572 Error_Msg_Sloc := Sloc (Predicate_Function (T));
6573 Error_Msg_Node_2 := T;
6574 Error_Msg_N ("info: & inherits predicate from & #?L?", Typ);
6579 --------------------
6580 -- Add_Predicates --
6581 --------------------
6583 procedure Add_Predicates is
6588 procedure Replace_Type_Reference (N : Node_Id);
6589 -- Replace a single occurrence N of the subtype name with a reference
6590 -- to the formal of the predicate function. N can be an identifier
6591 -- referencing the subtype, or a selected component, representing an
6592 -- appropriately qualified occurrence of the subtype name.
6594 procedure Replace_Type_References is
6595 new Replace_Type_References_Generic (Replace_Type_Reference);
6596 -- Traverse an expression changing every occurrence of an identifier
6597 -- whose name matches the name of the subtype with a reference to
6598 -- the formal parameter of the predicate function.
6600 ----------------------------
6601 -- Replace_Type_Reference --
6602 ----------------------------
6604 procedure Replace_Type_Reference (N : Node_Id) is
6606 Rewrite (N, Make_Identifier (Sloc (N), Object_Name));
6607 -- Use the Sloc of the usage name, not the defining name
6610 Set_Entity (N, Object_Entity);
6612 -- We want to treat the node as if it comes from source, so that
6613 -- ASIS will not ignore it
6615 Set_Comes_From_Source (N, True);
6616 end Replace_Type_Reference;
6618 -- Start of processing for Add_Predicates
6621 Ritem := First_Rep_Item (Typ);
6622 while Present (Ritem) loop
6623 if Nkind (Ritem) = N_Pragma
6624 and then Pragma_Name (Ritem) = Name_Predicate
6626 -- Save the static predicate of the type for diagnostics and
6627 -- error reporting purposes.
6629 if Present (Corresponding_Aspect (Ritem))
6630 and then Chars (Identifier (Corresponding_Aspect (Ritem))) =
6631 Name_Static_Predicate
6633 Static_Predic := Ritem;
6636 -- Acquire arguments
6638 Arg1 := First (Pragma_Argument_Associations (Ritem));
6639 Arg2 := Next (Arg1);
6641 Arg1 := Get_Pragma_Arg (Arg1);
6642 Arg2 := Get_Pragma_Arg (Arg2);
6644 -- See if this predicate pragma is for the current type or for
6645 -- its full view. A predicate on a private completion is placed
6646 -- on the partial view beause this is the visible entity that
6649 if Entity (Arg1) = Typ
6650 or else Full_View (Entity (Arg1)) = Typ
6652 -- We have a match, this entry is for our subtype
6654 -- We need to replace any occurrences of the name of the
6655 -- type with references to the object.
6657 Replace_Type_References (Arg2, Chars (Typ));
6659 -- If this predicate comes from an aspect, find the aspect
6660 -- specification, and replace the saved expression because
6661 -- we need the subtype references replaced for the calls to
6662 -- Preanalyze_Spec_Expressin in Check_Aspect_At_Freeze_Point
6663 -- and Check_Aspect_At_End_Of_Declarations.
6665 if From_Aspect_Specification (Ritem) then
6670 -- Loop to find corresponding aspect, note that this
6671 -- must be present given the pragma is marked delayed.
6673 Aitem := Next_Rep_Item (Ritem);
6675 if Nkind (Aitem) = N_Aspect_Specification
6676 and then Aspect_Rep_Item (Aitem) = Ritem
6679 (Identifier (Aitem), New_Copy_Tree (Arg2));
6683 Aitem := Next_Rep_Item (Aitem);
6688 -- Now we can add the expression
6691 Expr := Relocate_Node (Arg2);
6693 -- There already was a predicate, so add to it
6698 Left_Opnd => Relocate_Node (Expr),
6699 Right_Opnd => Relocate_Node (Arg2));
6704 Next_Rep_Item (Ritem);
6712 function Process_RE (N : Node_Id) return Traverse_Result is
6714 if Nkind (N) = N_Raise_Expression then
6715 Set_Convert_To_Return_False (N);
6726 function Test_RE (N : Node_Id) return Traverse_Result is
6728 if Nkind (N) = N_Raise_Expression then
6729 Raise_Expression_Present := True;
6736 -- Start of processing for Build_Predicate_Functions
6739 -- Return if already built or if type does not have predicates
6741 if not Has_Predicates (Typ)
6742 or else Present (Predicate_Function (Typ))
6747 -- Prepare to construct predicate expression
6751 -- Add Predicates for the current type
6755 -- Add predicates for ancestor if present
6758 Atyp : constant Entity_Id := Nearest_Ancestor (Typ);
6760 if Present (Atyp) then
6765 -- Case where predicates are present
6767 if Present (Expr) then
6769 -- Test for raise expression present
6773 -- If raise expression is present, capture a copy of Expr for use
6774 -- in building the predicateM function version later on. For this
6775 -- copy we replace references to Object_Entity by Object_Entity_M.
6777 if Raise_Expression_Present then
6779 Map : constant Elist_Id := New_Elmt_List;
6781 Append_Elmt (Object_Entity, Map);
6782 Append_Elmt (Object_Entity_M, Map);
6783 Expr_M := New_Copy_Tree (Expr, Map => Map);
6787 -- Build the main predicate function
6790 SId : constant Entity_Id :=
6791 Make_Defining_Identifier (Loc,
6792 Chars => New_External_Name (Chars (Typ), "Predicate"));
6793 -- The entity for the the function spec
6795 SIdB : constant Entity_Id :=
6796 Make_Defining_Identifier (Loc,
6797 Chars => New_External_Name (Chars (Typ), "Predicate"));
6798 -- The entity for the function body
6805 -- Build function declaration
6807 Set_Ekind (SId, E_Function);
6808 Set_Is_Internal (SId);
6809 Set_Is_Predicate_Function (SId);
6810 Set_Predicate_Function (Typ, SId);
6812 -- The predicate function is shared between views of a type
6814 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
6815 Set_Predicate_Function (Full_View (Typ), SId);
6819 Make_Function_Specification (Loc,
6820 Defining_Unit_Name => SId,
6821 Parameter_Specifications => New_List (
6822 Make_Parameter_Specification (Loc,
6823 Defining_Identifier => Object_Entity,
6824 Parameter_Type => New_Occurrence_Of (Typ, Loc))),
6825 Result_Definition =>
6826 New_Occurrence_Of (Standard_Boolean, Loc));
6829 Make_Subprogram_Declaration (Loc,
6830 Specification => Spec);
6832 -- Build function body
6835 Make_Function_Specification (Loc,
6836 Defining_Unit_Name => SIdB,
6837 Parameter_Specifications => New_List (
6838 Make_Parameter_Specification (Loc,
6839 Defining_Identifier =>
6840 Make_Defining_Identifier (Loc, Object_Name),
6842 New_Occurrence_Of (Typ, Loc))),
6843 Result_Definition =>
6844 New_Occurrence_Of (Standard_Boolean, Loc));
6847 Make_Subprogram_Body (Loc,
6848 Specification => Spec,
6849 Declarations => Empty_List,
6850 Handled_Statement_Sequence =>
6851 Make_Handled_Sequence_Of_Statements (Loc,
6852 Statements => New_List (
6853 Make_Simple_Return_Statement (Loc,
6854 Expression => Expr))));
6856 -- Insert declaration before freeze node and body after
6858 Insert_Before_And_Analyze (N, FDecl);
6859 Insert_After_And_Analyze (N, FBody);
6862 -- Test for raise expressions present and if so build M version
6864 if Raise_Expression_Present then
6866 SId : constant Entity_Id :=
6867 Make_Defining_Identifier (Loc,
6868 Chars => New_External_Name (Chars (Typ), "PredicateM"));
6869 -- The entity for the the function spec
6871 SIdB : constant Entity_Id :=
6872 Make_Defining_Identifier (Loc,
6873 Chars => New_External_Name (Chars (Typ), "PredicateM"));
6874 -- The entity for the function body
6882 -- Mark any raise expressions for special expansion
6884 Process_REs (Expr_M);
6886 -- Build function declaration
6888 Set_Ekind (SId, E_Function);
6889 Set_Is_Predicate_Function_M (SId);
6890 Set_Predicate_Function_M (Typ, SId);
6892 -- The predicate function is shared between views of a type
6894 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
6895 Set_Predicate_Function_M (Full_View (Typ), SId);
6899 Make_Function_Specification (Loc,
6900 Defining_Unit_Name => SId,
6901 Parameter_Specifications => New_List (
6902 Make_Parameter_Specification (Loc,
6903 Defining_Identifier => Object_Entity_M,
6904 Parameter_Type => New_Occurrence_Of (Typ, Loc))),
6905 Result_Definition =>
6906 New_Occurrence_Of (Standard_Boolean, Loc));
6909 Make_Subprogram_Declaration (Loc,
6910 Specification => Spec);
6912 -- Build function body
6915 Make_Function_Specification (Loc,
6916 Defining_Unit_Name => SIdB,
6917 Parameter_Specifications => New_List (
6918 Make_Parameter_Specification (Loc,
6919 Defining_Identifier =>
6920 Make_Defining_Identifier (Loc, Object_Name),
6922 New_Occurrence_Of (Typ, Loc))),
6923 Result_Definition =>
6924 New_Occurrence_Of (Standard_Boolean, Loc));
6926 -- Build the body, we declare the boolean expression before
6927 -- doing the return, because we are not really confident of
6928 -- what happens if a return appears within a return.
6931 Make_Defining_Identifier (Loc,
6932 Chars => New_Internal_Name ('B'));
6935 Make_Subprogram_Body (Loc,
6936 Specification => Spec,
6938 Declarations => New_List (
6939 Make_Object_Declaration (Loc,
6940 Defining_Identifier => BTemp,
6941 Constant_Present => True,
6942 Object_Definition =>
6943 New_Occurrence_Of (Standard_Boolean, Loc),
6944 Expression => Expr_M)),
6946 Handled_Statement_Sequence =>
6947 Make_Handled_Sequence_Of_Statements (Loc,
6948 Statements => New_List (
6949 Make_Simple_Return_Statement (Loc,
6950 Expression => New_Occurrence_Of (BTemp, Loc)))));
6952 -- Insert declaration before freeze node and body after
6954 Insert_Before_And_Analyze (N, FDecl);
6955 Insert_After_And_Analyze (N, FBody);
6959 if Is_Scalar_Type (Typ) then
6961 -- Attempt to build a static predicate for a discrete or a real
6962 -- subtype. This action may fail because the actual expression may
6963 -- not be static. Note that the presence of an inherited or
6964 -- explicitly declared dynamic predicate is orthogonal to this
6965 -- check because we are only interested in the static predicate.
6967 if Ekind_In (Typ, E_Decimal_Fixed_Point_Subtype,
6968 E_Enumeration_Subtype,
6969 E_Floating_Point_Subtype,
6970 E_Modular_Integer_Subtype,
6971 E_Ordinary_Fixed_Point_Subtype,
6972 E_Signed_Integer_Subtype)
6974 Build_Static_Predicate (Typ, Expr, Object_Name);
6976 -- Emit an error when the predicate is categorized as static
6977 -- but its expression is dynamic.
6979 if Present (Static_Predic)
6980 and then No (Static_Predicate (Typ))
6983 ("expression does not have required form for "
6984 & "static predicate",
6985 Next (First (Pragma_Argument_Associations
6990 -- If a static predicate applies on other types, that's an error:
6991 -- either the type is scalar but non-static, or it's not even a
6992 -- scalar type. We do not issue an error on generated types, as
6993 -- these may be duplicates of the same error on a source type.
6995 elsif Present (Static_Predic) and then Comes_From_Source (Typ) then
6996 if Is_Scalar_Type (Typ) then
6998 ("static predicate not allowed for non-static type&",
7002 ("static predicate not allowed for non-scalar type&",
7007 end Build_Predicate_Functions;
7009 ----------------------------
7010 -- Build_Static_Predicate --
7011 ----------------------------
7013 procedure Build_Static_Predicate
7018 Loc : constant Source_Ptr := Sloc (Expr);
7020 Non_Static : exception;
7021 -- Raised if something non-static is found
7023 Btyp : constant Entity_Id := Base_Type (Typ);
7025 BLo : constant Uint := Expr_Value (Type_Low_Bound (Btyp));
7026 BHi : constant Uint := Expr_Value (Type_High_Bound (Btyp));
7027 -- Low bound and high bound value of base type of Typ
7029 TLo : constant Uint := Expr_Value (Type_Low_Bound (Typ));
7030 THi : constant Uint := Expr_Value (Type_High_Bound (Typ));
7031 -- Low bound and high bound values of static subtype Typ
7036 -- One entry in a Rlist value, a single REnt (range entry) value denotes
7037 -- one range from Lo to Hi. To represent a single value range Lo = Hi =
7040 type RList is array (Nat range <>) of REnt;
7041 -- A list of ranges. The ranges are sorted in increasing order, and are
7042 -- disjoint (there is a gap of at least one value between each range in
7043 -- the table). A value is in the set of ranges in Rlist if it lies
7044 -- within one of these ranges.
7046 False_Range : constant RList :=
7047 RList'(1 .. 0 => REnt'(No_Uint, No_Uint));
7048 -- An empty set of ranges represents a range list that can never be
7049 -- satisfied, since there are no ranges in which the value could lie,
7050 -- so it does not lie in any of them. False_Range is a canonical value
7051 -- for this empty set, but general processing should test for an Rlist
7052 -- with length zero (see Is_False predicate), since other null ranges
7053 -- may appear which must be treated as False.
7055 True_Range : constant RList := RList'(1 => REnt'(BLo, BHi));
7056 -- Range representing True, value must be in the base range
7058 function "and" (Left : RList; Right : RList) return RList;
7059 -- And's together two range lists, returning a range list. This is a set
7060 -- intersection operation.
7062 function "or" (Left : RList; Right : RList) return RList;
7063 -- Or's together two range lists, returning a range list. This is a set
7066 function "not" (Right : RList) return RList;
7067 -- Returns complement of a given range list, i.e. a range list
7068 -- representing all the values in TLo .. THi that are not in the input
7071 function Build_Val (V : Uint) return Node_Id;
7072 -- Return an analyzed N_Identifier node referencing this value, suitable
7073 -- for use as an entry in the Static_Predicate list. This node is typed
7074 -- with the base type.
7076 function Build_Range (Lo : Uint; Hi : Uint) return Node_Id;
7077 -- Return an analyzed N_Range node referencing this range, suitable for
7078 -- use as an entry in the Static_Predicate list. This node is typed with
7081 function Get_RList (Exp : Node_Id) return RList;
7082 -- This is a recursive routine that converts the given expression into a
7083 -- list of ranges, suitable for use in building the static predicate.
7085 function Is_False (R : RList) return Boolean;
7086 pragma Inline (Is_False);
7087 -- Returns True if the given range list is empty, and thus represents a
7088 -- False list of ranges that can never be satisfied.
7090 function Is_True (R : RList) return Boolean;
7091 -- Returns True if R trivially represents the True predicate by having a
7092 -- single range from BLo to BHi.
7094 function Is_Type_Ref (N : Node_Id) return Boolean;
7095 pragma Inline (Is_Type_Ref);
7096 -- Returns if True if N is a reference to the type for the predicate in
7097 -- the expression (i.e. if it is an identifier whose Chars field matches
7098 -- the Nam given in the call).
7100 function Lo_Val (N : Node_Id) return Uint;
7101 -- Given static expression or static range from a Static_Predicate list,
7102 -- gets expression value or low bound of range.
7104 function Hi_Val (N : Node_Id) return Uint;
7105 -- Given static expression or static range from a Static_Predicate list,
7106 -- gets expression value of high bound of range.
7108 function Membership_Entry (N : Node_Id) return RList;
7109 -- Given a single membership entry (range, value, or subtype), returns
7110 -- the corresponding range list. Raises Static_Error if not static.
7112 function Membership_Entries (N : Node_Id) return RList;
7113 -- Given an element on an alternatives list of a membership operation,
7114 -- returns the range list corresponding to this entry and all following
7115 -- entries (i.e. returns the "or" of this list of values).
7117 function Stat_Pred (Typ : Entity_Id) return RList;
7118 -- Given a type, if it has a static predicate, then return the predicate
7119 -- as a range list, otherwise raise Non_Static.
7125 function "and" (Left : RList; Right : RList) return RList is
7127 -- First range of result
7129 SLeft : Nat := Left'First;
7130 -- Start of rest of left entries
7132 SRight : Nat := Right'First;
7133 -- Start of rest of right entries
7136 -- If either range is True, return the other
7138 if Is_True (Left) then
7140 elsif Is_True (Right) then
7144 -- If either range is False, return False
7146 if Is_False (Left) or else Is_False (Right) then
7150 -- Loop to remove entries at start that are disjoint, and thus just
7151 -- get discarded from the result entirely.
7154 -- If no operands left in either operand, result is false
7156 if SLeft > Left'Last or else SRight > Right'Last then
7159 -- Discard first left operand entry if disjoint with right
7161 elsif Left (SLeft).Hi < Right (SRight).Lo then
7164 -- Discard first right operand entry if disjoint with left
7166 elsif Right (SRight).Hi < Left (SLeft).Lo then
7167 SRight := SRight + 1;
7169 -- Otherwise we have an overlapping entry
7176 -- Now we have two non-null operands, and first entries overlap. The
7177 -- first entry in the result will be the overlapping part of these
7180 FEnt := REnt'(Lo => UI_Max (Left (SLeft).Lo, Right (SRight).Lo),
7181 Hi => UI_Min (Left (SLeft).Hi, Right (SRight).Hi));
7183 -- Now we can remove the entry that ended at a lower value, since its
7184 -- contribution is entirely contained in Fent.
7186 if Left (SLeft).Hi <= Right (SRight).Hi then
7189 SRight := SRight + 1;
7192 -- Compute result by concatenating this first entry with the "and" of
7193 -- the remaining parts of the left and right operands. Note that if
7194 -- either of these is empty, "and" will yield empty, so that we will
7195 -- end up with just Fent, which is what we want in that case.
7198 FEnt & (Left (SLeft .. Left'Last) and Right (SRight .. Right'Last));
7205 function "not" (Right : RList) return RList is
7207 -- Return True if False range
7209 if Is_False (Right) then
7213 -- Return False if True range
7215 if Is_True (Right) then
7219 -- Here if not trivial case
7222 Result : RList (1 .. Right'Length + 1);
7223 -- May need one more entry for gap at beginning and end
7226 -- Number of entries stored in Result
7231 if Right (Right'First).Lo > TLo then
7233 Result (Count) := REnt'(TLo, Right (Right'First).Lo - 1);
7236 -- Gaps between ranges
7238 for J in Right'First .. Right'Last - 1 loop
7241 REnt'(Right (J).Hi + 1, Right (J + 1).Lo - 1);
7246 if Right (Right'Last).Hi < THi then
7248 Result (Count) := REnt'(Right (Right'Last).Hi + 1, THi);
7251 return Result (1 .. Count);
7259 function "or" (Left : RList; Right : RList) return RList is
7261 -- First range of result
7263 SLeft : Nat := Left'First;
7264 -- Start of rest of left entries
7266 SRight : Nat := Right'First;
7267 -- Start of rest of right entries
7270 -- If either range is True, return True
7272 if Is_True (Left) or else Is_True (Right) then
7276 -- If either range is False (empty), return the other
7278 if Is_False (Left) then
7280 elsif Is_False (Right) then
7284 -- Initialize result first entry from left or right operand depending
7285 -- on which starts with the lower range.
7287 if Left (SLeft).Lo < Right (SRight).Lo then
7288 FEnt := Left (SLeft);
7291 FEnt := Right (SRight);
7292 SRight := SRight + 1;
7295 -- This loop eats ranges from left and right operands that are
7296 -- contiguous with the first range we are gathering.
7299 -- Eat first entry in left operand if contiguous or overlapped by
7300 -- gathered first operand of result.
7302 if SLeft <= Left'Last
7303 and then Left (SLeft).Lo <= FEnt.Hi + 1
7305 FEnt.Hi := UI_Max (FEnt.Hi, Left (SLeft).Hi);
7308 -- Eat first entry in right operand if contiguous or overlapped by
7309 -- gathered right operand of result.
7311 elsif SRight <= Right'Last
7312 and then Right (SRight).Lo <= FEnt.Hi + 1
7314 FEnt.Hi := UI_Max (FEnt.Hi, Right (SRight).Hi);
7315 SRight := SRight + 1;
7317 -- All done if no more entries to eat
7324 -- Obtain result as the first entry we just computed, concatenated
7325 -- to the "or" of the remaining results (if one operand is empty,
7326 -- this will just concatenate with the other
7329 FEnt & (Left (SLeft .. Left'Last) or Right (SRight .. Right'Last));
7336 function Build_Range (Lo : Uint; Hi : Uint) return Node_Id is
7342 Low_Bound => Build_Val (Lo),
7343 High_Bound => Build_Val (Hi));
7344 Set_Etype (Result, Btyp);
7345 Set_Analyzed (Result);
7354 function Build_Val (V : Uint) return Node_Id is
7358 if Is_Enumeration_Type (Typ) then
7359 Result := Get_Enum_Lit_From_Pos (Typ, V, Loc);
7361 Result := Make_Integer_Literal (Loc, V);
7364 Set_Etype (Result, Btyp);
7365 Set_Is_Static_Expression (Result);
7366 Set_Analyzed (Result);
7374 function Get_RList (Exp : Node_Id) return RList is
7379 -- Static expression can only be true or false
7381 if Is_OK_Static_Expression (Exp) then
7385 if Expr_Value (Exp) = 0 then
7392 -- Otherwise test node type
7400 when N_Op_And | N_And_Then =>
7401 return Get_RList (Left_Opnd (Exp))
7403 Get_RList (Right_Opnd (Exp));
7407 when N_Op_Or | N_Or_Else =>
7408 return Get_RList (Left_Opnd (Exp))
7410 Get_RList (Right_Opnd (Exp));
7415 return not Get_RList (Right_Opnd (Exp));
7417 -- Comparisons of type with static value
7419 when N_Op_Compare =>
7421 -- Type is left operand
7423 if Is_Type_Ref (Left_Opnd (Exp))
7424 and then Is_OK_Static_Expression (Right_Opnd (Exp))
7426 Val := Expr_Value (Right_Opnd (Exp));
7428 -- Typ is right operand
7430 elsif Is_Type_Ref (Right_Opnd (Exp))
7431 and then Is_OK_Static_Expression (Left_Opnd (Exp))
7433 Val := Expr_Value (Left_Opnd (Exp));
7435 -- Invert sense of comparison
7438 when N_Op_Gt => Op := N_Op_Lt;
7439 when N_Op_Lt => Op := N_Op_Gt;
7440 when N_Op_Ge => Op := N_Op_Le;
7441 when N_Op_Le => Op := N_Op_Ge;
7442 when others => null;
7445 -- Other cases are non-static
7451 -- Construct range according to comparison operation
7455 return RList'(1 => REnt'(Val, Val));
7458 return RList'(1 => REnt'(Val, BHi));
7461 return RList'(1 => REnt'(Val + 1, BHi));
7464 return RList'(1 => REnt'(BLo, Val));
7467 return RList'(1 => REnt'(BLo, Val - 1));
7470 return RList'(REnt'(BLo, Val - 1),
7471 REnt'(Val + 1, BHi));
7474 raise Program_Error;
7480 if not Is_Type_Ref (Left_Opnd (Exp)) then
7484 if Present (Right_Opnd (Exp)) then
7485 return Membership_Entry (Right_Opnd (Exp));
7487 return Membership_Entries (First (Alternatives (Exp)));
7490 -- Negative membership (NOT IN)
7493 if not Is_Type_Ref (Left_Opnd (Exp)) then
7497 if Present (Right_Opnd (Exp)) then
7498 return not Membership_Entry (Right_Opnd (Exp));
7500 return not Membership_Entries (First (Alternatives (Exp)));
7503 -- Function call, may be call to static predicate
7505 when N_Function_Call =>
7506 if Is_Entity_Name (Name (Exp)) then
7508 Ent : constant Entity_Id := Entity (Name (Exp));
7510 if Is_Predicate_Function (Ent)
7512 Is_Predicate_Function_M (Ent)
7514 return Stat_Pred (Etype (First_Formal (Ent)));
7519 -- Other function call cases are non-static
7523 -- Qualified expression, dig out the expression
7525 when N_Qualified_Expression =>
7526 return Get_RList (Expression (Exp));
7528 -- Expression with actions: if no actions, dig out expression
7530 when N_Expression_With_Actions =>
7531 if Is_Empty_List (Actions (Exp)) then
7532 return Get_RList (Expression (Exp));
7541 return (Get_RList (Left_Opnd (Exp))
7542 and not Get_RList (Right_Opnd (Exp)))
7543 or (Get_RList (Right_Opnd (Exp))
7544 and not Get_RList (Left_Opnd (Exp)));
7546 -- Any other node type is non-static
7557 function Hi_Val (N : Node_Id) return Uint is
7559 if Is_Static_Expression (N) then
7560 return Expr_Value (N);
7562 pragma Assert (Nkind (N) = N_Range);
7563 return Expr_Value (High_Bound (N));
7571 function Is_False (R : RList) return Boolean is
7573 return R'Length = 0;
7580 function Is_True (R : RList) return Boolean is
7583 and then R (R'First).Lo = BLo
7584 and then R (R'First).Hi = BHi;
7591 function Is_Type_Ref (N : Node_Id) return Boolean is
7593 return Nkind (N) = N_Identifier and then Chars (N) = Nam;
7600 function Lo_Val (N : Node_Id) return Uint is
7602 if Is_Static_Expression (N) then
7603 return Expr_Value (N);
7605 pragma Assert (Nkind (N) = N_Range);
7606 return Expr_Value (Low_Bound (N));
7610 ------------------------
7611 -- Membership_Entries --
7612 ------------------------
7614 function Membership_Entries (N : Node_Id) return RList is
7616 if No (Next (N)) then
7617 return Membership_Entry (N);
7619 return Membership_Entry (N) or Membership_Entries (Next (N));
7621 end Membership_Entries;
7623 ----------------------
7624 -- Membership_Entry --
7625 ----------------------
7627 function Membership_Entry (N : Node_Id) return RList is
7635 if Nkind (N) = N_Range then
7636 if not Is_Static_Expression (Low_Bound (N))
7638 not Is_Static_Expression (High_Bound (N))
7642 SLo := Expr_Value (Low_Bound (N));
7643 SHi := Expr_Value (High_Bound (N));
7644 return RList'(1 => REnt'(SLo, SHi));
7647 -- Static expression case
7649 elsif Is_Static_Expression (N) then
7650 Val := Expr_Value (N);
7651 return RList'(1 => REnt'(Val, Val));
7653 -- Identifier (other than static expression) case
7655 else pragma Assert (Nkind (N) = N_Identifier);
7659 if Is_Type (Entity (N)) then
7661 -- If type has predicates, process them
7663 if Has_Predicates (Entity (N)) then
7664 return Stat_Pred (Entity (N));
7666 -- For static subtype without predicates, get range
7668 elsif Is_Static_Subtype (Entity (N)) then
7669 SLo := Expr_Value (Type_Low_Bound (Entity (N)));
7670 SHi := Expr_Value (Type_High_Bound (Entity (N)));
7671 return RList'(1 => REnt'(SLo, SHi));
7673 -- Any other type makes us non-static
7679 -- Any other kind of identifier in predicate (e.g. a non-static
7680 -- expression value) means this is not a static predicate.
7686 end Membership_Entry;
7692 function Stat_Pred (Typ : Entity_Id) return RList is
7694 -- Not static if type does not have static predicates
7696 if not Has_Predicates (Typ) or else No (Static_Predicate (Typ)) then
7700 -- Otherwise we convert the predicate list to a range list
7703 Result : RList (1 .. List_Length (Static_Predicate (Typ)));
7707 P := First (Static_Predicate (Typ));
7708 for J in Result'Range loop
7709 Result (J) := REnt'(Lo_Val (P), Hi_Val (P));
7717 -- Start of processing for Build_Static_Predicate
7720 -- Now analyze the expression to see if it is a static predicate
7723 Ranges : constant RList := Get_RList (Expr);
7724 -- Range list from expression if it is static
7729 -- Convert range list into a form for the static predicate. In the
7730 -- Ranges array, we just have raw ranges, these must be converted
7731 -- to properly typed and analyzed static expressions or range nodes.
7733 -- Note: here we limit ranges to the ranges of the subtype, so that
7734 -- a predicate is always false for values outside the subtype. That
7735 -- seems fine, such values are invalid anyway, and considering them
7736 -- to fail the predicate seems allowed and friendly, and furthermore
7737 -- simplifies processing for case statements and loops.
7741 for J in Ranges'Range loop
7743 Lo : Uint := Ranges (J).Lo;
7744 Hi : Uint := Ranges (J).Hi;
7747 -- Ignore completely out of range entry
7749 if Hi < TLo or else Lo > THi then
7752 -- Otherwise process entry
7755 -- Adjust out of range value to subtype range
7765 -- Convert range into required form
7767 Append_To (Plist, Build_Range (Lo, Hi));
7772 -- Processing was successful and all entries were static, so now we
7773 -- can store the result as the predicate list.
7775 Set_Static_Predicate (Typ, Plist);
7777 -- The processing for static predicates put the expression into
7778 -- canonical form as a series of ranges. It also eliminated
7779 -- duplicates and collapsed and combined ranges. We might as well
7780 -- replace the alternatives list of the right operand of the
7781 -- membership test with the static predicate list, which will
7782 -- usually be more efficient.
7785 New_Alts : constant List_Id := New_List;
7790 Old_Node := First (Plist);
7791 while Present (Old_Node) loop
7792 New_Node := New_Copy (Old_Node);
7794 if Nkind (New_Node) = N_Range then
7795 Set_Low_Bound (New_Node, New_Copy (Low_Bound (Old_Node)));
7796 Set_High_Bound (New_Node, New_Copy (High_Bound (Old_Node)));
7799 Append_To (New_Alts, New_Node);
7803 -- If empty list, replace by False
7805 if Is_Empty_List (New_Alts) then
7806 Rewrite (Expr, New_Occurrence_Of (Standard_False, Loc));
7808 -- Else replace by set membership test
7813 Left_Opnd => Make_Identifier (Loc, Nam),
7814 Right_Opnd => Empty,
7815 Alternatives => New_Alts));
7817 -- Resolve new expression in function context
7819 Install_Formals (Predicate_Function (Typ));
7820 Push_Scope (Predicate_Function (Typ));
7821 Analyze_And_Resolve (Expr, Standard_Boolean);
7827 -- If non-static, return doing nothing
7832 end Build_Static_Predicate;
7834 -----------------------------------------
7835 -- Check_Aspect_At_End_Of_Declarations --
7836 -----------------------------------------
7838 procedure Check_Aspect_At_End_Of_Declarations (ASN : Node_Id) is
7839 Ent : constant Entity_Id := Entity (ASN);
7840 Ident : constant Node_Id := Identifier (ASN);
7841 A_Id : constant Aspect_Id := Get_Aspect_Id (Chars (Ident));
7843 End_Decl_Expr : constant Node_Id := Entity (Ident);
7844 -- Expression to be analyzed at end of declarations
7846 Freeze_Expr : constant Node_Id := Expression (ASN);
7847 -- Expression from call to Check_Aspect_At_Freeze_Point
7849 T : constant Entity_Id := Etype (Freeze_Expr);
7850 -- Type required for preanalyze call
7853 -- Set False if error
7855 -- On entry to this procedure, Entity (Ident) contains a copy of the
7856 -- original expression from the aspect, saved for this purpose, and
7857 -- but Expression (Ident) is a preanalyzed copy of the expression,
7858 -- preanalyzed just after the freeze point.
7860 procedure Check_Overloaded_Name;
7861 -- For aspects whose expression is simply a name, this routine checks if
7862 -- the name is overloaded or not. If so, it verifies there is an
7863 -- interpretation that matches the entity obtained at the freeze point,
7864 -- otherwise the compiler complains.
7866 ---------------------------
7867 -- Check_Overloaded_Name --
7868 ---------------------------
7870 procedure Check_Overloaded_Name is
7872 if not Is_Overloaded (End_Decl_Expr) then
7873 Err := Entity (End_Decl_Expr) /= Entity (Freeze_Expr);
7879 Index : Interp_Index;
7883 Get_First_Interp (End_Decl_Expr, Index, It);
7884 while Present (It.Typ) loop
7885 if It.Nam = Entity (Freeze_Expr) then
7890 Get_Next_Interp (Index, It);
7894 end Check_Overloaded_Name;
7896 -- Start of processing for Check_Aspect_At_End_Of_Declarations
7899 -- Case of aspects Dimension, Dimension_System and Synchronization
7901 if A_Id = Aspect_Synchronization then
7904 -- Case of stream attributes, just have to compare entities. However,
7905 -- the expression is just a name (possibly overloaded), and there may
7906 -- be stream operations declared for unrelated types, so we just need
7907 -- to verify that one of these interpretations is the one available at
7908 -- at the freeze point.
7910 elsif A_Id = Aspect_Input or else
7911 A_Id = Aspect_Output or else
7912 A_Id = Aspect_Read or else
7915 Analyze (End_Decl_Expr);
7916 Check_Overloaded_Name;
7918 elsif A_Id = Aspect_Variable_Indexing or else
7919 A_Id = Aspect_Constant_Indexing or else
7920 A_Id = Aspect_Default_Iterator or else
7921 A_Id = Aspect_Iterator_Element
7923 -- Make type unfrozen before analysis, to prevent spurious errors
7924 -- about late attributes.
7926 Set_Is_Frozen (Ent, False);
7927 Analyze (End_Decl_Expr);
7928 Set_Is_Frozen (Ent, True);
7930 -- If the end of declarations comes before any other freeze
7931 -- point, the Freeze_Expr is not analyzed: no check needed.
7933 if Analyzed (Freeze_Expr) and then not In_Instance then
7934 Check_Overloaded_Name;
7942 -- In a generic context the aspect expressions have not been
7943 -- preanalyzed, so do it now. There are no conformance checks
7944 -- to perform in this case.
7947 Check_Aspect_At_Freeze_Point (ASN);
7950 -- The default values attributes may be defined in the private part,
7951 -- and the analysis of the expression may take place when only the
7952 -- partial view is visible. The expression must be scalar, so use
7953 -- the full view to resolve.
7955 elsif (A_Id = Aspect_Default_Value
7957 A_Id = Aspect_Default_Component_Value)
7958 and then Is_Private_Type (T)
7960 Preanalyze_Spec_Expression (End_Decl_Expr, Full_View (T));
7962 Preanalyze_Spec_Expression (End_Decl_Expr, T);
7965 Err := not Fully_Conformant_Expressions (End_Decl_Expr, Freeze_Expr);
7968 -- Output error message if error
7972 ("visibility of aspect for& changes after freeze point",
7975 ("info: & is frozen here, aspects evaluated at this point??",
7976 Freeze_Node (Ent), Ent);
7978 end Check_Aspect_At_End_Of_Declarations;
7980 ----------------------------------
7981 -- Check_Aspect_At_Freeze_Point --
7982 ----------------------------------
7984 procedure Check_Aspect_At_Freeze_Point (ASN : Node_Id) is
7985 Ident : constant Node_Id := Identifier (ASN);
7986 -- Identifier (use Entity field to save expression)
7988 A_Id : constant Aspect_Id := Get_Aspect_Id (Chars (Ident));
7990 T : Entity_Id := Empty;
7991 -- Type required for preanalyze call
7994 -- On entry to this procedure, Entity (Ident) contains a copy of the
7995 -- original expression from the aspect, saved for this purpose.
7997 -- On exit from this procedure Entity (Ident) is unchanged, still
7998 -- containing that copy, but Expression (Ident) is a preanalyzed copy
7999 -- of the expression, preanalyzed just after the freeze point.
8001 -- Make a copy of the expression to be preanalyzed
8003 Set_Expression (ASN, New_Copy_Tree (Entity (Ident)));
8005 -- Find type for preanalyze call
8009 -- No_Aspect should be impossible
8012 raise Program_Error;
8014 -- Aspects taking an optional boolean argument
8016 when Boolean_Aspects |
8017 Library_Unit_Aspects =>
8019 T := Standard_Boolean;
8021 -- Aspects corresponding to attribute definition clauses
8023 when Aspect_Address =>
8024 T := RTE (RE_Address);
8026 when Aspect_Attach_Handler =>
8027 T := RTE (RE_Interrupt_ID);
8029 when Aspect_Bit_Order | Aspect_Scalar_Storage_Order =>
8030 T := RTE (RE_Bit_Order);
8032 when Aspect_Convention =>
8036 T := RTE (RE_CPU_Range);
8038 -- Default_Component_Value is resolved with the component type
8040 when Aspect_Default_Component_Value =>
8041 T := Component_Type (Entity (ASN));
8043 -- Default_Value is resolved with the type entity in question
8045 when Aspect_Default_Value =>
8048 -- Depends is a delayed aspect because it mentiones names first
8049 -- introduced by aspect Global which is already delayed. There is
8050 -- no action to be taken with respect to the aspect itself as the
8051 -- analysis is done by the corresponding pragma.
8053 when Aspect_Depends =>
8056 when Aspect_Dispatching_Domain =>
8057 T := RTE (RE_Dispatching_Domain);
8059 when Aspect_External_Tag =>
8060 T := Standard_String;
8062 when Aspect_External_Name =>
8063 T := Standard_String;
8065 -- Global is a delayed aspect because it may reference names that
8066 -- have not been declared yet. There is no action to be taken with
8067 -- respect to the aspect itself as the reference checking is done
8068 -- on the corresponding pragma.
8070 when Aspect_Global =>
8073 when Aspect_Link_Name =>
8074 T := Standard_String;
8076 when Aspect_Priority | Aspect_Interrupt_Priority =>
8077 T := Standard_Integer;
8079 when Aspect_Relative_Deadline =>
8080 T := RTE (RE_Time_Span);
8082 when Aspect_Small =>
8083 T := Universal_Real;
8085 -- For a simple storage pool, we have to retrieve the type of the
8086 -- pool object associated with the aspect's corresponding attribute
8087 -- definition clause.
8089 when Aspect_Simple_Storage_Pool =>
8090 T := Etype (Expression (Aspect_Rep_Item (ASN)));
8092 when Aspect_Storage_Pool =>
8093 T := Class_Wide_Type (RTE (RE_Root_Storage_Pool));
8095 when Aspect_Alignment |
8096 Aspect_Component_Size |
8097 Aspect_Machine_Radix |
8098 Aspect_Object_Size |
8100 Aspect_Storage_Size |
8101 Aspect_Stream_Size |
8102 Aspect_Value_Size =>
8105 when Aspect_Linker_Section =>
8106 T := Standard_String;
8108 when Aspect_Synchronization =>
8111 -- Special case, the expression of these aspects is just an entity
8112 -- that does not need any resolution, so just analyze.
8121 Analyze (Expression (ASN));
8124 -- Same for Iterator aspects, where the expression is a function
8125 -- name. Legality rules are checked separately.
8127 when Aspect_Constant_Indexing |
8128 Aspect_Default_Iterator |
8129 Aspect_Iterator_Element |
8130 Aspect_Variable_Indexing =>
8131 Analyze (Expression (ASN));
8134 -- Ditto for Iterable, legality checks in Validate_Iterable_Aspect.
8136 when Aspect_Iterable =>
8140 Cursor : constant Entity_Id := Get_Cursor_Type (ASN, T);
8145 if Cursor = Any_Type then
8149 Assoc := First (Component_Associations (Expression (ASN)));
8150 while Present (Assoc) loop
8151 Expr := Expression (Assoc);
8154 if not Error_Posted (Expr) then
8155 Resolve_Iterable_Operation
8156 (Expr, Cursor, T, Chars (First (Choices (Assoc))));
8165 -- Invariant/Predicate take boolean expressions
8167 when Aspect_Dynamic_Predicate |
8170 Aspect_Static_Predicate |
8171 Aspect_Type_Invariant =>
8172 T := Standard_Boolean;
8174 -- Here is the list of aspects that don't require delay analysis
8176 when Aspect_Abstract_State |
8177 Aspect_Contract_Cases |
8179 Aspect_Dimension_System |
8180 Aspect_Implicit_Dereference |
8181 Aspect_Initial_Condition |
8182 Aspect_Initializes |
8185 Aspect_Postcondition |
8187 Aspect_Precondition |
8188 Aspect_Refined_Depends |
8189 Aspect_Refined_Global |
8190 Aspect_Refined_Post |
8191 Aspect_Refined_State |
8194 raise Program_Error;
8198 -- Do the preanalyze call
8200 Preanalyze_Spec_Expression (Expression (ASN), T);
8201 end Check_Aspect_At_Freeze_Point;
8203 -----------------------------------
8204 -- Check_Constant_Address_Clause --
8205 -----------------------------------
8207 procedure Check_Constant_Address_Clause
8211 procedure Check_At_Constant_Address (Nod : Node_Id);
8212 -- Checks that the given node N represents a name whose 'Address is
8213 -- constant (in the same sense as OK_Constant_Address_Clause, i.e. the
8214 -- address value is the same at the point of declaration of U_Ent and at
8215 -- the time of elaboration of the address clause.
8217 procedure Check_Expr_Constants (Nod : Node_Id);
8218 -- Checks that Nod meets the requirements for a constant address clause
8219 -- in the sense of the enclosing procedure.
8221 procedure Check_List_Constants (Lst : List_Id);
8222 -- Check that all elements of list Lst meet the requirements for a
8223 -- constant address clause in the sense of the enclosing procedure.
8225 -------------------------------
8226 -- Check_At_Constant_Address --
8227 -------------------------------
8229 procedure Check_At_Constant_Address (Nod : Node_Id) is
8231 if Is_Entity_Name (Nod) then
8232 if Present (Address_Clause (Entity ((Nod)))) then
8234 ("invalid address clause for initialized object &!",
8237 ("address for& cannot" &
8238 " depend on another address clause! (RM 13.1(22))!",
8241 elsif In_Same_Source_Unit (Entity (Nod), U_Ent)
8242 and then Sloc (U_Ent) < Sloc (Entity (Nod))
8245 ("invalid address clause for initialized object &!",
8247 Error_Msg_Node_2 := U_Ent;
8249 ("\& must be defined before & (RM 13.1(22))!",
8253 elsif Nkind (Nod) = N_Selected_Component then
8255 T : constant Entity_Id := Etype (Prefix (Nod));
8258 if (Is_Record_Type (T)
8259 and then Has_Discriminants (T))
8262 and then Is_Record_Type (Designated_Type (T))
8263 and then Has_Discriminants (Designated_Type (T)))
8266 ("invalid address clause for initialized object &!",
8269 ("\address cannot depend on component" &
8270 " of discriminated record (RM 13.1(22))!",
8273 Check_At_Constant_Address (Prefix (Nod));
8277 elsif Nkind (Nod) = N_Indexed_Component then
8278 Check_At_Constant_Address (Prefix (Nod));
8279 Check_List_Constants (Expressions (Nod));
8282 Check_Expr_Constants (Nod);
8284 end Check_At_Constant_Address;
8286 --------------------------
8287 -- Check_Expr_Constants --
8288 --------------------------
8290 procedure Check_Expr_Constants (Nod : Node_Id) is
8291 Loc_U_Ent : constant Source_Ptr := Sloc (U_Ent);
8292 Ent : Entity_Id := Empty;
8295 if Nkind (Nod) in N_Has_Etype
8296 and then Etype (Nod) = Any_Type
8302 when N_Empty | N_Error =>
8305 when N_Identifier | N_Expanded_Name =>
8306 Ent := Entity (Nod);
8308 -- We need to look at the original node if it is different
8309 -- from the node, since we may have rewritten things and
8310 -- substituted an identifier representing the rewrite.
8312 if Original_Node (Nod) /= Nod then
8313 Check_Expr_Constants (Original_Node (Nod));
8315 -- If the node is an object declaration without initial
8316 -- value, some code has been expanded, and the expression
8317 -- is not constant, even if the constituents might be
8318 -- acceptable, as in A'Address + offset.
8320 if Ekind (Ent) = E_Variable
8322 Nkind (Declaration_Node (Ent)) = N_Object_Declaration
8324 No (Expression (Declaration_Node (Ent)))
8327 ("invalid address clause for initialized object &!",
8330 -- If entity is constant, it may be the result of expanding
8331 -- a check. We must verify that its declaration appears
8332 -- before the object in question, else we also reject the
8335 elsif Ekind (Ent) = E_Constant
8336 and then In_Same_Source_Unit (Ent, U_Ent)
8337 and then Sloc (Ent) > Loc_U_Ent
8340 ("invalid address clause for initialized object &!",
8347 -- Otherwise look at the identifier and see if it is OK
8349 if Ekind_In (Ent, E_Named_Integer, E_Named_Real)
8350 or else Is_Type (Ent)
8355 Ekind (Ent) = E_Constant
8357 Ekind (Ent) = E_In_Parameter
8359 -- This is the case where we must have Ent defined before
8360 -- U_Ent. Clearly if they are in different units this
8361 -- requirement is met since the unit containing Ent is
8362 -- already processed.
8364 if not In_Same_Source_Unit (Ent, U_Ent) then
8367 -- Otherwise location of Ent must be before the location
8368 -- of U_Ent, that's what prior defined means.
8370 elsif Sloc (Ent) < Loc_U_Ent then
8375 ("invalid address clause for initialized object &!",
8377 Error_Msg_Node_2 := U_Ent;
8379 ("\& must be defined before & (RM 13.1(22))!",
8383 elsif Nkind (Original_Node (Nod)) = N_Function_Call then
8384 Check_Expr_Constants (Original_Node (Nod));
8388 ("invalid address clause for initialized object &!",
8391 if Comes_From_Source (Ent) then
8393 ("\reference to variable& not allowed"
8394 & " (RM 13.1(22))!", Nod, Ent);
8397 ("non-static expression not allowed"
8398 & " (RM 13.1(22))!", Nod);
8402 when N_Integer_Literal =>
8404 -- If this is a rewritten unchecked conversion, in a system
8405 -- where Address is an integer type, always use the base type
8406 -- for a literal value. This is user-friendly and prevents
8407 -- order-of-elaboration issues with instances of unchecked
8410 if Nkind (Original_Node (Nod)) = N_Function_Call then
8411 Set_Etype (Nod, Base_Type (Etype (Nod)));
8414 when N_Real_Literal |
8416 N_Character_Literal =>
8420 Check_Expr_Constants (Low_Bound (Nod));
8421 Check_Expr_Constants (High_Bound (Nod));
8423 when N_Explicit_Dereference =>
8424 Check_Expr_Constants (Prefix (Nod));
8426 when N_Indexed_Component =>
8427 Check_Expr_Constants (Prefix (Nod));
8428 Check_List_Constants (Expressions (Nod));
8431 Check_Expr_Constants (Prefix (Nod));
8432 Check_Expr_Constants (Discrete_Range (Nod));
8434 when N_Selected_Component =>
8435 Check_Expr_Constants (Prefix (Nod));
8437 when N_Attribute_Reference =>
8438 if Nam_In (Attribute_Name (Nod), Name_Address,
8440 Name_Unchecked_Access,
8441 Name_Unrestricted_Access)
8443 Check_At_Constant_Address (Prefix (Nod));
8446 Check_Expr_Constants (Prefix (Nod));
8447 Check_List_Constants (Expressions (Nod));
8451 Check_List_Constants (Component_Associations (Nod));
8452 Check_List_Constants (Expressions (Nod));
8454 when N_Component_Association =>
8455 Check_Expr_Constants (Expression (Nod));
8457 when N_Extension_Aggregate =>
8458 Check_Expr_Constants (Ancestor_Part (Nod));
8459 Check_List_Constants (Component_Associations (Nod));
8460 Check_List_Constants (Expressions (Nod));
8465 when N_Binary_Op | N_Short_Circuit | N_Membership_Test =>
8466 Check_Expr_Constants (Left_Opnd (Nod));
8467 Check_Expr_Constants (Right_Opnd (Nod));
8470 Check_Expr_Constants (Right_Opnd (Nod));
8472 when N_Type_Conversion |
8473 N_Qualified_Expression |
8475 N_Unchecked_Type_Conversion =>
8476 Check_Expr_Constants (Expression (Nod));
8478 when N_Function_Call =>
8479 if not Is_Pure (Entity (Name (Nod))) then
8481 ("invalid address clause for initialized object &!",
8485 ("\function & is not pure (RM 13.1(22))!",
8486 Nod, Entity (Name (Nod)));
8489 Check_List_Constants (Parameter_Associations (Nod));
8492 when N_Parameter_Association =>
8493 Check_Expr_Constants (Explicit_Actual_Parameter (Nod));
8497 ("invalid address clause for initialized object &!",
8500 ("\must be constant defined before& (RM 13.1(22))!",
8503 end Check_Expr_Constants;
8505 --------------------------
8506 -- Check_List_Constants --
8507 --------------------------
8509 procedure Check_List_Constants (Lst : List_Id) is
8513 if Present (Lst) then
8514 Nod1 := First (Lst);
8515 while Present (Nod1) loop
8516 Check_Expr_Constants (Nod1);
8520 end Check_List_Constants;
8522 -- Start of processing for Check_Constant_Address_Clause
8525 -- If rep_clauses are to be ignored, no need for legality checks. In
8526 -- particular, no need to pester user about rep clauses that violate
8527 -- the rule on constant addresses, given that these clauses will be
8528 -- removed by Freeze before they reach the back end.
8530 if not Ignore_Rep_Clauses then
8531 Check_Expr_Constants (Expr);
8533 end Check_Constant_Address_Clause;
8535 ---------------------------
8536 -- Check_Pool_Size_Clash --
8537 ---------------------------
8539 procedure Check_Pool_Size_Clash (Ent : Entity_Id; SP, SS : Node_Id) is
8543 -- We need to find out which one came first. Note that in the case of
8544 -- aspects mixed with pragmas there are cases where the processing order
8545 -- is reversed, which is why we do the check here.
8547 if Sloc (SP) < Sloc (SS) then
8548 Error_Msg_Sloc := Sloc (SP);
8550 Error_Msg_NE ("Storage_Pool previously given for&#", Post, Ent);
8553 Error_Msg_Sloc := Sloc (SS);
8555 Error_Msg_NE ("Storage_Size previously given for&#", Post, Ent);
8559 ("\cannot have Storage_Size and Storage_Pool (RM 13.11(3))", Post);
8560 end Check_Pool_Size_Clash;
8562 ----------------------------------------
8563 -- Check_Record_Representation_Clause --
8564 ----------------------------------------
8566 procedure Check_Record_Representation_Clause (N : Node_Id) is
8567 Loc : constant Source_Ptr := Sloc (N);
8568 Ident : constant Node_Id := Identifier (N);
8569 Rectype : Entity_Id;
8574 Hbit : Uint := Uint_0;
8578 Max_Bit_So_Far : Uint;
8579 -- Records the maximum bit position so far. If all field positions
8580 -- are monotonically increasing, then we can skip the circuit for
8581 -- checking for overlap, since no overlap is possible.
8583 Tagged_Parent : Entity_Id := Empty;
8584 -- This is set in the case of a derived tagged type for which we have
8585 -- Is_Fully_Repped_Tagged_Type True (indicating that all components are
8586 -- positioned by record representation clauses). In this case we must
8587 -- check for overlap between components of this tagged type, and the
8588 -- components of its parent. Tagged_Parent will point to this parent
8589 -- type. For all other cases Tagged_Parent is left set to Empty.
8591 Parent_Last_Bit : Uint;
8592 -- Relevant only if Tagged_Parent is set, Parent_Last_Bit indicates the
8593 -- last bit position for any field in the parent type. We only need to
8594 -- check overlap for fields starting below this point.
8596 Overlap_Check_Required : Boolean;
8597 -- Used to keep track of whether or not an overlap check is required
8599 Overlap_Detected : Boolean := False;
8600 -- Set True if an overlap is detected
8602 Ccount : Natural := 0;
8603 -- Number of component clauses in record rep clause
8605 procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id);
8606 -- Given two entities for record components or discriminants, checks
8607 -- if they have overlapping component clauses and issues errors if so.
8609 procedure Find_Component;
8610 -- Finds component entity corresponding to current component clause (in
8611 -- CC), and sets Comp to the entity, and Fbit/Lbit to the zero origin
8612 -- start/stop bits for the field. If there is no matching component or
8613 -- if the matching component does not have a component clause, then
8614 -- that's an error and Comp is set to Empty, but no error message is
8615 -- issued, since the message was already given. Comp is also set to
8616 -- Empty if the current "component clause" is in fact a pragma.
8618 -----------------------------
8619 -- Check_Component_Overlap --
8620 -----------------------------
8622 procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id) is
8623 CC1 : constant Node_Id := Component_Clause (C1_Ent);
8624 CC2 : constant Node_Id := Component_Clause (C2_Ent);
8627 if Present (CC1) and then Present (CC2) then
8629 -- Exclude odd case where we have two tag components in the same
8630 -- record, both at location zero. This seems a bit strange, but
8631 -- it seems to happen in some circumstances, perhaps on an error.
8633 if Nam_In (Chars (C1_Ent), Name_uTag, Name_uTag) then
8637 -- Here we check if the two fields overlap
8640 S1 : constant Uint := Component_Bit_Offset (C1_Ent);
8641 S2 : constant Uint := Component_Bit_Offset (C2_Ent);
8642 E1 : constant Uint := S1 + Esize (C1_Ent);
8643 E2 : constant Uint := S2 + Esize (C2_Ent);
8646 if E2 <= S1 or else E1 <= S2 then
8649 Error_Msg_Node_2 := Component_Name (CC2);
8650 Error_Msg_Sloc := Sloc (Error_Msg_Node_2);
8651 Error_Msg_Node_1 := Component_Name (CC1);
8653 ("component& overlaps & #", Component_Name (CC1));
8654 Overlap_Detected := True;
8658 end Check_Component_Overlap;
8660 --------------------
8661 -- Find_Component --
8662 --------------------
8664 procedure Find_Component is
8666 procedure Search_Component (R : Entity_Id);
8667 -- Search components of R for a match. If found, Comp is set
8669 ----------------------
8670 -- Search_Component --
8671 ----------------------
8673 procedure Search_Component (R : Entity_Id) is
8675 Comp := First_Component_Or_Discriminant (R);
8676 while Present (Comp) loop
8678 -- Ignore error of attribute name for component name (we
8679 -- already gave an error message for this, so no need to
8682 if Nkind (Component_Name (CC)) = N_Attribute_Reference then
8685 exit when Chars (Comp) = Chars (Component_Name (CC));
8688 Next_Component_Or_Discriminant (Comp);
8690 end Search_Component;
8692 -- Start of processing for Find_Component
8695 -- Return with Comp set to Empty if we have a pragma
8697 if Nkind (CC) = N_Pragma then
8702 -- Search current record for matching component
8704 Search_Component (Rectype);
8706 -- If not found, maybe component of base type discriminant that is
8707 -- absent from statically constrained first subtype.
8710 Search_Component (Base_Type (Rectype));
8713 -- If no component, or the component does not reference the component
8714 -- clause in question, then there was some previous error for which
8715 -- we already gave a message, so just return with Comp Empty.
8717 if No (Comp) or else Component_Clause (Comp) /= CC then
8718 Check_Error_Detected;
8721 -- Normal case where we have a component clause
8724 Fbit := Component_Bit_Offset (Comp);
8725 Lbit := Fbit + Esize (Comp) - 1;
8729 -- Start of processing for Check_Record_Representation_Clause
8733 Rectype := Entity (Ident);
8735 if Rectype = Any_Type then
8738 Rectype := Underlying_Type (Rectype);
8741 -- See if we have a fully repped derived tagged type
8744 PS : constant Entity_Id := Parent_Subtype (Rectype);
8747 if Present (PS) and then Is_Fully_Repped_Tagged_Type (PS) then
8748 Tagged_Parent := PS;
8750 -- Find maximum bit of any component of the parent type
8752 Parent_Last_Bit := UI_From_Int (System_Address_Size - 1);
8753 Pcomp := First_Entity (Tagged_Parent);
8754 while Present (Pcomp) loop
8755 if Ekind_In (Pcomp, E_Discriminant, E_Component) then
8756 if Component_Bit_Offset (Pcomp) /= No_Uint
8757 and then Known_Static_Esize (Pcomp)
8762 Component_Bit_Offset (Pcomp) + Esize (Pcomp) - 1);
8765 Next_Entity (Pcomp);
8771 -- All done if no component clauses
8773 CC := First (Component_Clauses (N));
8779 -- If a tag is present, then create a component clause that places it
8780 -- at the start of the record (otherwise gigi may place it after other
8781 -- fields that have rep clauses).
8783 Fent := First_Entity (Rectype);
8785 if Nkind (Fent) = N_Defining_Identifier
8786 and then Chars (Fent) = Name_uTag
8788 Set_Component_Bit_Offset (Fent, Uint_0);
8789 Set_Normalized_Position (Fent, Uint_0);
8790 Set_Normalized_First_Bit (Fent, Uint_0);
8791 Set_Normalized_Position_Max (Fent, Uint_0);
8792 Init_Esize (Fent, System_Address_Size);
8794 Set_Component_Clause (Fent,
8795 Make_Component_Clause (Loc,
8796 Component_Name => Make_Identifier (Loc, Name_uTag),
8798 Position => Make_Integer_Literal (Loc, Uint_0),
8799 First_Bit => Make_Integer_Literal (Loc, Uint_0),
8801 Make_Integer_Literal (Loc,
8802 UI_From_Int (System_Address_Size))));
8804 Ccount := Ccount + 1;
8807 Max_Bit_So_Far := Uint_Minus_1;
8808 Overlap_Check_Required := False;
8810 -- Process the component clauses
8812 while Present (CC) loop
8815 if Present (Comp) then
8816 Ccount := Ccount + 1;
8818 -- We need a full overlap check if record positions non-monotonic
8820 if Fbit <= Max_Bit_So_Far then
8821 Overlap_Check_Required := True;
8824 Max_Bit_So_Far := Lbit;
8826 -- Check bit position out of range of specified size
8828 if Has_Size_Clause (Rectype)
8829 and then RM_Size (Rectype) <= Lbit
8832 ("bit number out of range of specified size",
8835 -- Check for overlap with tag component
8838 if Is_Tagged_Type (Rectype)
8839 and then Fbit < System_Address_Size
8842 ("component overlaps tag field of&",
8843 Component_Name (CC), Rectype);
8844 Overlap_Detected := True;
8852 -- Check parent overlap if component might overlap parent field
8854 if Present (Tagged_Parent) and then Fbit <= Parent_Last_Bit then
8855 Pcomp := First_Component_Or_Discriminant (Tagged_Parent);
8856 while Present (Pcomp) loop
8857 if not Is_Tag (Pcomp)
8858 and then Chars (Pcomp) /= Name_uParent
8860 Check_Component_Overlap (Comp, Pcomp);
8863 Next_Component_Or_Discriminant (Pcomp);
8871 -- Now that we have processed all the component clauses, check for
8872 -- overlap. We have to leave this till last, since the components can
8873 -- appear in any arbitrary order in the representation clause.
8875 -- We do not need this check if all specified ranges were monotonic,
8876 -- as recorded by Overlap_Check_Required being False at this stage.
8878 -- This first section checks if there are any overlapping entries at
8879 -- all. It does this by sorting all entries and then seeing if there are
8880 -- any overlaps. If there are none, then that is decisive, but if there
8881 -- are overlaps, they may still be OK (they may result from fields in
8882 -- different variants).
8884 if Overlap_Check_Required then
8885 Overlap_Check1 : declare
8887 OC_Fbit : array (0 .. Ccount) of Uint;
8888 -- First-bit values for component clauses, the value is the offset
8889 -- of the first bit of the field from start of record. The zero
8890 -- entry is for use in sorting.
8892 OC_Lbit : array (0 .. Ccount) of Uint;
8893 -- Last-bit values for component clauses, the value is the offset
8894 -- of the last bit of the field from start of record. The zero
8895 -- entry is for use in sorting.
8897 OC_Count : Natural := 0;
8898 -- Count of entries in OC_Fbit and OC_Lbit
8900 function OC_Lt (Op1, Op2 : Natural) return Boolean;
8901 -- Compare routine for Sort
8903 procedure OC_Move (From : Natural; To : Natural);
8904 -- Move routine for Sort
8906 package Sorting is new GNAT.Heap_Sort_G (OC_Move, OC_Lt);
8912 function OC_Lt (Op1, Op2 : Natural) return Boolean is
8914 return OC_Fbit (Op1) < OC_Fbit (Op2);
8921 procedure OC_Move (From : Natural; To : Natural) is
8923 OC_Fbit (To) := OC_Fbit (From);
8924 OC_Lbit (To) := OC_Lbit (From);
8927 -- Start of processing for Overlap_Check
8930 CC := First (Component_Clauses (N));
8931 while Present (CC) loop
8933 -- Exclude component clause already marked in error
8935 if not Error_Posted (CC) then
8938 if Present (Comp) then
8939 OC_Count := OC_Count + 1;
8940 OC_Fbit (OC_Count) := Fbit;
8941 OC_Lbit (OC_Count) := Lbit;
8948 Sorting.Sort (OC_Count);
8950 Overlap_Check_Required := False;
8951 for J in 1 .. OC_Count - 1 loop
8952 if OC_Lbit (J) >= OC_Fbit (J + 1) then
8953 Overlap_Check_Required := True;
8960 -- If Overlap_Check_Required is still True, then we have to do the full
8961 -- scale overlap check, since we have at least two fields that do
8962 -- overlap, and we need to know if that is OK since they are in
8963 -- different variant, or whether we have a definite problem.
8965 if Overlap_Check_Required then
8966 Overlap_Check2 : declare
8967 C1_Ent, C2_Ent : Entity_Id;
8968 -- Entities of components being checked for overlap
8971 -- Component_List node whose Component_Items are being checked
8974 -- Component declaration for component being checked
8977 C1_Ent := First_Entity (Base_Type (Rectype));
8979 -- Loop through all components in record. For each component check
8980 -- for overlap with any of the preceding elements on the component
8981 -- list containing the component and also, if the component is in
8982 -- a variant, check against components outside the case structure.
8983 -- This latter test is repeated recursively up the variant tree.
8985 Main_Component_Loop : while Present (C1_Ent) loop
8986 if not Ekind_In (C1_Ent, E_Component, E_Discriminant) then
8987 goto Continue_Main_Component_Loop;
8990 -- Skip overlap check if entity has no declaration node. This
8991 -- happens with discriminants in constrained derived types.
8992 -- Possibly we are missing some checks as a result, but that
8993 -- does not seem terribly serious.
8995 if No (Declaration_Node (C1_Ent)) then
8996 goto Continue_Main_Component_Loop;
8999 Clist := Parent (List_Containing (Declaration_Node (C1_Ent)));
9001 -- Loop through component lists that need checking. Check the
9002 -- current component list and all lists in variants above us.
9004 Component_List_Loop : loop
9006 -- If derived type definition, go to full declaration
9007 -- If at outer level, check discriminants if there are any.
9009 if Nkind (Clist) = N_Derived_Type_Definition then
9010 Clist := Parent (Clist);
9013 -- Outer level of record definition, check discriminants
9015 if Nkind_In (Clist, N_Full_Type_Declaration,
9016 N_Private_Type_Declaration)
9018 if Has_Discriminants (Defining_Identifier (Clist)) then
9020 First_Discriminant (Defining_Identifier (Clist));
9021 while Present (C2_Ent) loop
9022 exit when C1_Ent = C2_Ent;
9023 Check_Component_Overlap (C1_Ent, C2_Ent);
9024 Next_Discriminant (C2_Ent);
9028 -- Record extension case
9030 elsif Nkind (Clist) = N_Derived_Type_Definition then
9033 -- Otherwise check one component list
9036 Citem := First (Component_Items (Clist));
9037 while Present (Citem) loop
9038 if Nkind (Citem) = N_Component_Declaration then
9039 C2_Ent := Defining_Identifier (Citem);
9040 exit when C1_Ent = C2_Ent;
9041 Check_Component_Overlap (C1_Ent, C2_Ent);
9048 -- Check for variants above us (the parent of the Clist can
9049 -- be a variant, in which case its parent is a variant part,
9050 -- and the parent of the variant part is a component list
9051 -- whose components must all be checked against the current
9052 -- component for overlap).
9054 if Nkind (Parent (Clist)) = N_Variant then
9055 Clist := Parent (Parent (Parent (Clist)));
9057 -- Check for possible discriminant part in record, this
9058 -- is treated essentially as another level in the
9059 -- recursion. For this case the parent of the component
9060 -- list is the record definition, and its parent is the
9061 -- full type declaration containing the discriminant
9064 elsif Nkind (Parent (Clist)) = N_Record_Definition then
9065 Clist := Parent (Parent ((Clist)));
9067 -- If neither of these two cases, we are at the top of
9071 exit Component_List_Loop;
9073 end loop Component_List_Loop;
9075 <<Continue_Main_Component_Loop>>
9076 Next_Entity (C1_Ent);
9078 end loop Main_Component_Loop;
9082 -- The following circuit deals with warning on record holes (gaps). We
9083 -- skip this check if overlap was detected, since it makes sense for the
9084 -- programmer to fix this illegality before worrying about warnings.
9086 if not Overlap_Detected and Warn_On_Record_Holes then
9087 Record_Hole_Check : declare
9088 Decl : constant Node_Id := Declaration_Node (Base_Type (Rectype));
9089 -- Full declaration of record type
9091 procedure Check_Component_List
9095 -- Check component list CL for holes. The starting bit should be
9096 -- Sbit. which is zero for the main record component list and set
9097 -- appropriately for recursive calls for variants. DS is set to
9098 -- a list of discriminant specifications to be included in the
9099 -- consideration of components. It is No_List if none to consider.
9101 --------------------------
9102 -- Check_Component_List --
9103 --------------------------
9105 procedure Check_Component_List
9113 Compl := Integer (List_Length (Component_Items (CL)));
9115 if DS /= No_List then
9116 Compl := Compl + Integer (List_Length (DS));
9120 Comps : array (Natural range 0 .. Compl) of Entity_Id;
9121 -- Gather components (zero entry is for sort routine)
9123 Ncomps : Natural := 0;
9124 -- Number of entries stored in Comps (starting at Comps (1))
9127 -- One component item or discriminant specification
9130 -- Starting bit for next component
9138 function Lt (Op1, Op2 : Natural) return Boolean;
9139 -- Compare routine for Sort
9141 procedure Move (From : Natural; To : Natural);
9142 -- Move routine for Sort
9144 package Sorting is new GNAT.Heap_Sort_G (Move, Lt);
9150 function Lt (Op1, Op2 : Natural) return Boolean is
9152 return Component_Bit_Offset (Comps (Op1))
9154 Component_Bit_Offset (Comps (Op2));
9161 procedure Move (From : Natural; To : Natural) is
9163 Comps (To) := Comps (From);
9167 -- Gather discriminants into Comp
9169 if DS /= No_List then
9170 Citem := First (DS);
9171 while Present (Citem) loop
9172 if Nkind (Citem) = N_Discriminant_Specification then
9174 Ent : constant Entity_Id :=
9175 Defining_Identifier (Citem);
9177 if Ekind (Ent) = E_Discriminant then
9178 Ncomps := Ncomps + 1;
9179 Comps (Ncomps) := Ent;
9188 -- Gather component entities into Comp
9190 Citem := First (Component_Items (CL));
9191 while Present (Citem) loop
9192 if Nkind (Citem) = N_Component_Declaration then
9193 Ncomps := Ncomps + 1;
9194 Comps (Ncomps) := Defining_Identifier (Citem);
9200 -- Now sort the component entities based on the first bit.
9201 -- Note we already know there are no overlapping components.
9203 Sorting.Sort (Ncomps);
9205 -- Loop through entries checking for holes
9208 for J in 1 .. Ncomps loop
9210 Error_Msg_Uint_1 := Component_Bit_Offset (CEnt) - Nbit;
9212 if Error_Msg_Uint_1 > 0 then
9214 ("?H?^-bit gap before component&",
9215 Component_Name (Component_Clause (CEnt)), CEnt);
9218 Nbit := Component_Bit_Offset (CEnt) + Esize (CEnt);
9221 -- Process variant parts recursively if present
9223 if Present (Variant_Part (CL)) then
9224 Variant := First (Variants (Variant_Part (CL)));
9225 while Present (Variant) loop
9226 Check_Component_List
9227 (Component_List (Variant), Nbit, No_List);
9232 end Check_Component_List;
9234 -- Start of processing for Record_Hole_Check
9241 if Is_Tagged_Type (Rectype) then
9242 Sbit := UI_From_Int (System_Address_Size);
9247 if Nkind (Decl) = N_Full_Type_Declaration
9248 and then Nkind (Type_Definition (Decl)) = N_Record_Definition
9250 Check_Component_List
9251 (Component_List (Type_Definition (Decl)),
9253 Discriminant_Specifications (Decl));
9256 end Record_Hole_Check;
9259 -- For records that have component clauses for all components, and whose
9260 -- size is less than or equal to 32, we need to know the size in the
9261 -- front end to activate possible packed array processing where the
9262 -- component type is a record.
9264 -- At this stage Hbit + 1 represents the first unused bit from all the
9265 -- component clauses processed, so if the component clauses are
9266 -- complete, then this is the length of the record.
9268 -- For records longer than System.Storage_Unit, and for those where not
9269 -- all components have component clauses, the back end determines the
9270 -- length (it may for example be appropriate to round up the size
9271 -- to some convenient boundary, based on alignment considerations, etc).
9273 if Unknown_RM_Size (Rectype) and then Hbit + 1 <= 32 then
9275 -- Nothing to do if at least one component has no component clause
9277 Comp := First_Component_Or_Discriminant (Rectype);
9278 while Present (Comp) loop
9279 exit when No (Component_Clause (Comp));
9280 Next_Component_Or_Discriminant (Comp);
9283 -- If we fall out of loop, all components have component clauses
9284 -- and so we can set the size to the maximum value.
9287 Set_RM_Size (Rectype, Hbit + 1);
9290 end Check_Record_Representation_Clause;
9296 procedure Check_Size
9300 Biased : out Boolean)
9302 UT : constant Entity_Id := Underlying_Type (T);
9308 -- Reject patently improper size values.
9310 if Is_Elementary_Type (T)
9311 and then Siz > UI_From_Int (Int'Last)
9313 Error_Msg_N ("Size value too large for elementary type", N);
9315 if Nkind (Original_Node (N)) = N_Op_Expon then
9317 ("\maybe '* was meant, rather than '*'*", Original_Node (N));
9321 -- Dismiss generic types
9323 if Is_Generic_Type (T)
9325 Is_Generic_Type (UT)
9327 Is_Generic_Type (Root_Type (UT))
9331 -- Guard against previous errors
9333 elsif No (UT) or else UT = Any_Type then
9334 Check_Error_Detected;
9337 -- Check case of bit packed array
9339 elsif Is_Array_Type (UT)
9340 and then Known_Static_Component_Size (UT)
9341 and then Is_Bit_Packed_Array (UT)
9349 Asiz := Component_Size (UT);
9350 Indx := First_Index (UT);
9352 Ityp := Etype (Indx);
9354 -- If non-static bound, then we are not in the business of
9355 -- trying to check the length, and indeed an error will be
9356 -- issued elsewhere, since sizes of non-static array types
9357 -- cannot be set implicitly or explicitly.
9359 if not Is_Static_Subtype (Ityp) then
9363 -- Otherwise accumulate next dimension
9365 Asiz := Asiz * (Expr_Value (Type_High_Bound (Ityp)) -
9366 Expr_Value (Type_Low_Bound (Ityp)) +
9370 exit when No (Indx);
9377 Error_Msg_Uint_1 := Asiz;
9379 ("size for& too small, minimum allowed is ^", N, T);
9380 Set_Esize (T, Asiz);
9381 Set_RM_Size (T, Asiz);
9385 -- All other composite types are ignored
9387 elsif Is_Composite_Type (UT) then
9390 -- For fixed-point types, don't check minimum if type is not frozen,
9391 -- since we don't know all the characteristics of the type that can
9392 -- affect the size (e.g. a specified small) till freeze time.
9394 elsif Is_Fixed_Point_Type (UT)
9395 and then not Is_Frozen (UT)
9399 -- Cases for which a minimum check is required
9402 -- Ignore if specified size is correct for the type
9404 if Known_Esize (UT) and then Siz = Esize (UT) then
9408 -- Otherwise get minimum size
9410 M := UI_From_Int (Minimum_Size (UT));
9414 -- Size is less than minimum size, but one possibility remains
9415 -- that we can manage with the new size if we bias the type.
9417 M := UI_From_Int (Minimum_Size (UT, Biased => True));
9420 Error_Msg_Uint_1 := M;
9422 ("size for& too small, minimum allowed is ^", N, T);
9432 --------------------------
9433 -- Freeze_Entity_Checks --
9434 --------------------------
9436 procedure Freeze_Entity_Checks (N : Node_Id) is
9437 E : constant Entity_Id := Entity (N);
9439 Non_Generic_Case : constant Boolean := Nkind (N) = N_Freeze_Entity;
9440 -- True in non-generic case. Some of the processing here is skipped
9441 -- for the generic case since it is not needed. Basically in the
9442 -- generic case, we only need to do stuff that might generate error
9443 -- messages or warnings.
9445 -- Remember that we are processing a freezing entity. Required to
9446 -- ensure correct decoration of internal entities associated with
9447 -- interfaces (see New_Overloaded_Entity).
9449 Inside_Freezing_Actions := Inside_Freezing_Actions + 1;
9451 -- For tagged types covering interfaces add internal entities that link
9452 -- the primitives of the interfaces with the primitives that cover them.
9453 -- Note: These entities were originally generated only when generating
9454 -- code because their main purpose was to provide support to initialize
9455 -- the secondary dispatch tables. They are now generated also when
9456 -- compiling with no code generation to provide ASIS the relationship
9457 -- between interface primitives and tagged type primitives. They are
9458 -- also used to locate primitives covering interfaces when processing
9459 -- generics (see Derive_Subprograms).
9461 -- This is not needed in the generic case
9463 if Ada_Version >= Ada_2005
9464 and then Non_Generic_Case
9465 and then Ekind (E) = E_Record_Type
9466 and then Is_Tagged_Type (E)
9467 and then not Is_Interface (E)
9468 and then Has_Interfaces (E)
9470 -- This would be a good common place to call the routine that checks
9471 -- overriding of interface primitives (and thus factorize calls to
9472 -- Check_Abstract_Overriding located at different contexts in the
9473 -- compiler). However, this is not possible because it causes
9474 -- spurious errors in case of late overriding.
9476 Add_Internal_Interface_Entities (E);
9481 if Ekind (E) = E_Record_Type
9482 and then Is_CPP_Class (E)
9483 and then Is_Tagged_Type (E)
9484 and then Tagged_Type_Expansion
9486 if CPP_Num_Prims (E) = 0 then
9488 -- If the CPP type has user defined components then it must import
9489 -- primitives from C++. This is required because if the C++ class
9490 -- has no primitives then the C++ compiler does not added the _tag
9491 -- component to the type.
9493 if First_Entity (E) /= Last_Entity (E) then
9495 ("'C'P'P type must import at least one primitive from C++??",
9500 -- Check that all its primitives are abstract or imported from C++.
9501 -- Check also availability of the C++ constructor.
9504 Has_Constructors : constant Boolean := Has_CPP_Constructors (E);
9506 Error_Reported : Boolean := False;
9510 Elmt := First_Elmt (Primitive_Operations (E));
9511 while Present (Elmt) loop
9512 Prim := Node (Elmt);
9514 if Comes_From_Source (Prim) then
9515 if Is_Abstract_Subprogram (Prim) then
9518 elsif not Is_Imported (Prim)
9519 or else Convention (Prim) /= Convention_CPP
9522 ("primitives of 'C'P'P types must be imported from C++ "
9523 & "or abstract??", Prim);
9525 elsif not Has_Constructors
9526 and then not Error_Reported
9528 Error_Msg_Name_1 := Chars (E);
9530 ("??'C'P'P constructor required for type %", Prim);
9531 Error_Reported := True;
9540 -- Check Ada derivation of CPP type
9542 if Expander_Active -- why? losing errors in -gnatc mode???
9543 and then Tagged_Type_Expansion
9544 and then Ekind (E) = E_Record_Type
9545 and then Etype (E) /= E
9546 and then Is_CPP_Class (Etype (E))
9547 and then CPP_Num_Prims (Etype (E)) > 0
9548 and then not Is_CPP_Class (E)
9549 and then not Has_CPP_Constructors (Etype (E))
9551 -- If the parent has C++ primitives but it has no constructor then
9552 -- check that all the primitives are overridden in this derivation;
9553 -- otherwise the constructor of the parent is needed to build the
9561 Elmt := First_Elmt (Primitive_Operations (E));
9562 while Present (Elmt) loop
9563 Prim := Node (Elmt);
9565 if not Is_Abstract_Subprogram (Prim)
9566 and then No (Interface_Alias (Prim))
9567 and then Find_Dispatching_Type (Ultimate_Alias (Prim)) /= E
9569 Error_Msg_Name_1 := Chars (Etype (E));
9571 ("'C'P'P constructor required for parent type %", E);
9580 Inside_Freezing_Actions := Inside_Freezing_Actions - 1;
9582 -- If we have a type with predicates, build predicate function. This
9583 -- is not needed in the generic case, and is not needed within TSS
9584 -- subprograms and other predefined primitives.
9587 and then Is_Type (E)
9588 and then Has_Predicates (E)
9589 and then not Within_Internal_Subprogram
9591 Build_Predicate_Functions (E, N);
9594 -- If type has delayed aspects, this is where we do the preanalysis at
9595 -- the freeze point, as part of the consistent visibility check. Note
9596 -- that this must be done after calling Build_Predicate_Functions or
9597 -- Build_Invariant_Procedure since these subprograms fix occurrences of
9598 -- the subtype name in the saved expression so that they will not cause
9599 -- trouble in the preanalysis.
9601 -- This is also not needed in the generic case
9604 and then Has_Delayed_Aspects (E)
9605 and then Scope (E) = Current_Scope
9607 -- Retrieve the visibility to the discriminants in order to properly
9608 -- analyze the aspects.
9610 Push_Scope_And_Install_Discriminants (E);
9616 -- Look for aspect specification entries for this entity
9618 Ritem := First_Rep_Item (E);
9619 while Present (Ritem) loop
9620 if Nkind (Ritem) = N_Aspect_Specification
9621 and then Entity (Ritem) = E
9622 and then Is_Delayed_Aspect (Ritem)
9624 Check_Aspect_At_Freeze_Point (Ritem);
9627 Next_Rep_Item (Ritem);
9631 Uninstall_Discriminants_And_Pop_Scope (E);
9634 -- For a record type, deal with variant parts. This has to be delayed
9635 -- to this point, because of the issue of statically precicated
9636 -- subtypes, which we have to ensure are frozen before checking
9637 -- choices, since we need to have the static choice list set.
9639 if Is_Record_Type (E) then
9640 Check_Variant_Part : declare
9641 D : constant Node_Id := Declaration_Node (E);
9646 Others_Present : Boolean;
9647 pragma Warnings (Off, Others_Present);
9648 -- Indicates others present, not used in this case
9650 procedure Non_Static_Choice_Error (Choice : Node_Id);
9651 -- Error routine invoked by the generic instantiation below when
9652 -- the variant part has a non static choice.
9654 procedure Process_Declarations (Variant : Node_Id);
9655 -- Processes declarations associated with a variant. We analyzed
9656 -- the declarations earlier (in Sem_Ch3.Analyze_Variant_Part),
9657 -- but we still need the recursive call to Check_Choices for any
9658 -- nested variant to get its choices properly processed. This is
9659 -- also where we expand out the choices if expansion is active.
9661 package Variant_Choices_Processing is new
9662 Generic_Check_Choices
9663 (Process_Empty_Choice => No_OP,
9664 Process_Non_Static_Choice => Non_Static_Choice_Error,
9665 Process_Associated_Node => Process_Declarations);
9666 use Variant_Choices_Processing;
9668 -----------------------------
9669 -- Non_Static_Choice_Error --
9670 -----------------------------
9672 procedure Non_Static_Choice_Error (Choice : Node_Id) is
9674 Flag_Non_Static_Expr
9675 ("choice given in variant part is not static!", Choice);
9676 end Non_Static_Choice_Error;
9678 --------------------------
9679 -- Process_Declarations --
9680 --------------------------
9682 procedure Process_Declarations (Variant : Node_Id) is
9683 CL : constant Node_Id := Component_List (Variant);
9687 -- Check for static predicate present in this variant
9689 if Has_SP_Choice (Variant) then
9691 -- Here we expand. You might expect to find this call in
9692 -- Expand_N_Variant_Part, but that is called when we first
9693 -- see the variant part, and we cannot do this expansion
9694 -- earlier than the freeze point, since for statically
9695 -- predicated subtypes, the predicate is not known till
9696 -- the freeze point.
9698 -- Furthermore, we do this expansion even if the expander
9699 -- is not active, because other semantic processing, e.g.
9700 -- for aggregates, requires the expanded list of choices.
9702 -- If the expander is not active, then we can't just clobber
9703 -- the list since it would invalidate the ASIS -gnatct tree.
9704 -- So we have to rewrite the variant part with a Rewrite
9705 -- call that replaces it with a copy and clobber the copy.
9707 if not Expander_Active then
9709 NewV : constant Node_Id := New_Copy (Variant);
9711 Set_Discrete_Choices
9712 (NewV, New_Copy_List (Discrete_Choices (Variant)));
9713 Rewrite (Variant, NewV);
9717 Expand_Static_Predicates_In_Choices (Variant);
9720 -- We don't need to worry about the declarations in the variant
9721 -- (since they were analyzed by Analyze_Choices when we first
9722 -- encountered the variant), but we do need to take care of
9723 -- expansion of any nested variants.
9725 if not Null_Present (CL) then
9726 VP := Variant_Part (CL);
9728 if Present (VP) then
9730 (VP, Variants (VP), Etype (Name (VP)), Others_Present);
9733 end Process_Declarations;
9735 -- Start of processing for Check_Variant_Part
9738 -- Find component list
9742 if Nkind (D) = N_Full_Type_Declaration then
9743 T := Type_Definition (D);
9745 if Nkind (T) = N_Record_Definition then
9746 C := Component_List (T);
9748 elsif Nkind (T) = N_Derived_Type_Definition
9749 and then Present (Record_Extension_Part (T))
9751 C := Component_List (Record_Extension_Part (T));
9755 -- Case of variant part present
9757 if Present (C) and then Present (Variant_Part (C)) then
9758 VP := Variant_Part (C);
9763 (VP, Variants (VP), Etype (Name (VP)), Others_Present);
9765 -- If the last variant does not contain the Others choice,
9766 -- replace it with an N_Others_Choice node since Gigi always
9767 -- wants an Others. Note that we do not bother to call Analyze
9768 -- on the modified variant part, since its only effect would be
9769 -- to compute the Others_Discrete_Choices node laboriously, and
9770 -- of course we already know the list of choices corresponding
9771 -- to the others choice (it's the list we're replacing).
9773 -- We only want to do this if the expander is active, since
9774 -- we do not want to clobber the ASIS tree.
9776 if Expander_Active then
9778 Last_Var : constant Node_Id :=
9779 Last_Non_Pragma (Variants (VP));
9781 Others_Node : Node_Id;
9784 if Nkind (First (Discrete_Choices (Last_Var))) /=
9787 Others_Node := Make_Others_Choice (Sloc (Last_Var));
9788 Set_Others_Discrete_Choices
9789 (Others_Node, Discrete_Choices (Last_Var));
9790 Set_Discrete_Choices
9791 (Last_Var, New_List (Others_Node));
9796 end Check_Variant_Part;
9798 end Freeze_Entity_Checks;
9800 -------------------------
9801 -- Get_Alignment_Value --
9802 -------------------------
9804 function Get_Alignment_Value (Expr : Node_Id) return Uint is
9805 Align : constant Uint := Static_Integer (Expr);
9808 if Align = No_Uint then
9811 elsif Align <= 0 then
9812 Error_Msg_N ("alignment value must be positive", Expr);
9816 for J in Int range 0 .. 64 loop
9818 M : constant Uint := Uint_2 ** J;
9821 exit when M = Align;
9825 ("alignment value must be power of 2", Expr);
9833 end Get_Alignment_Value;
9835 -------------------------------------
9836 -- Inherit_Aspects_At_Freeze_Point --
9837 -------------------------------------
9839 procedure Inherit_Aspects_At_Freeze_Point (Typ : Entity_Id) is
9840 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9841 (Rep_Item : Node_Id) return Boolean;
9842 -- This routine checks if Rep_Item is either a pragma or an aspect
9843 -- specification node whose correponding pragma (if any) is present in
9844 -- the Rep Item chain of the entity it has been specified to.
9846 --------------------------------------------------
9847 -- Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item --
9848 --------------------------------------------------
9850 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9851 (Rep_Item : Node_Id) return Boolean
9854 return Nkind (Rep_Item) = N_Pragma
9855 or else Present_In_Rep_Item
9856 (Entity (Rep_Item), Aspect_Rep_Item (Rep_Item));
9857 end Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item;
9859 -- Start of processing for Inherit_Aspects_At_Freeze_Point
9862 -- A representation item is either subtype-specific (Size and Alignment
9863 -- clauses) or type-related (all others). Subtype-specific aspects may
9864 -- differ for different subtypes of the same type (RM 13.1.8).
9866 -- A derived type inherits each type-related representation aspect of
9867 -- its parent type that was directly specified before the declaration of
9868 -- the derived type (RM 13.1.15).
9870 -- A derived subtype inherits each subtype-specific representation
9871 -- aspect of its parent subtype that was directly specified before the
9872 -- declaration of the derived type (RM 13.1.15).
9874 -- The general processing involves inheriting a representation aspect
9875 -- from a parent type whenever the first rep item (aspect specification,
9876 -- attribute definition clause, pragma) corresponding to the given
9877 -- representation aspect in the rep item chain of Typ, if any, isn't
9878 -- directly specified to Typ but to one of its parents.
9880 -- ??? Note that, for now, just a limited number of representation
9881 -- aspects have been inherited here so far. Many of them are
9882 -- still inherited in Sem_Ch3. This will be fixed soon. Here is
9883 -- a non- exhaustive list of aspects that likely also need to
9884 -- be moved to this routine: Alignment, Component_Alignment,
9885 -- Component_Size, Machine_Radix, Object_Size, Pack, Predicates,
9886 -- Preelaborable_Initialization, RM_Size and Small.
9888 if Nkind (Parent (Typ)) = N_Private_Extension_Declaration then
9894 if not Has_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005, False)
9895 and then Has_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005)
9896 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9897 (Get_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005))
9899 Set_Is_Ada_2005_Only (Typ);
9904 if not Has_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012, False)
9905 and then Has_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012)
9906 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9907 (Get_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012))
9909 Set_Is_Ada_2012_Only (Typ);
9914 if not Has_Rep_Item (Typ, Name_Atomic, Name_Shared, False)
9915 and then Has_Rep_Pragma (Typ, Name_Atomic, Name_Shared)
9916 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9917 (Get_Rep_Item (Typ, Name_Atomic, Name_Shared))
9919 Set_Is_Atomic (Typ);
9920 Set_Treat_As_Volatile (Typ);
9921 Set_Is_Volatile (Typ);
9924 -- Default_Component_Value
9926 if Is_Array_Type (Typ)
9927 and then Is_Base_Type (Typ)
9928 and then Has_Rep_Item (Typ, Name_Default_Component_Value, False)
9929 and then Has_Rep_Item (Typ, Name_Default_Component_Value)
9931 Set_Default_Aspect_Component_Value (Typ,
9932 Default_Aspect_Component_Value
9933 (Entity (Get_Rep_Item (Typ, Name_Default_Component_Value))));
9938 if Is_Scalar_Type (Typ)
9939 and then Is_Base_Type (Typ)
9940 and then Has_Rep_Item (Typ, Name_Default_Value, False)
9941 and then Has_Rep_Item (Typ, Name_Default_Value)
9943 Set_Default_Aspect_Value (Typ,
9944 Default_Aspect_Value
9945 (Entity (Get_Rep_Item (Typ, Name_Default_Value))));
9950 if not Has_Rep_Item (Typ, Name_Discard_Names, False)
9951 and then Has_Rep_Item (Typ, Name_Discard_Names)
9952 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9953 (Get_Rep_Item (Typ, Name_Discard_Names))
9955 Set_Discard_Names (Typ);
9960 if not Has_Rep_Item (Typ, Name_Invariant, False)
9961 and then Has_Rep_Item (Typ, Name_Invariant)
9962 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9963 (Get_Rep_Item (Typ, Name_Invariant))
9965 Set_Has_Invariants (Typ);
9967 if Class_Present (Get_Rep_Item (Typ, Name_Invariant)) then
9968 Set_Has_Inheritable_Invariants (Typ);
9974 if not Has_Rep_Item (Typ, Name_Volatile, False)
9975 and then Has_Rep_Item (Typ, Name_Volatile)
9976 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9977 (Get_Rep_Item (Typ, Name_Volatile))
9979 Set_Treat_As_Volatile (Typ);
9980 Set_Is_Volatile (Typ);
9983 -- Inheritance for derived types only
9985 if Is_Derived_Type (Typ) then
9987 Bas_Typ : constant Entity_Id := Base_Type (Typ);
9988 Imp_Bas_Typ : constant Entity_Id := Implementation_Base_Type (Typ);
9991 -- Atomic_Components
9993 if not Has_Rep_Item (Typ, Name_Atomic_Components, False)
9994 and then Has_Rep_Item (Typ, Name_Atomic_Components)
9995 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9996 (Get_Rep_Item (Typ, Name_Atomic_Components))
9998 Set_Has_Atomic_Components (Imp_Bas_Typ);
10001 -- Volatile_Components
10003 if not Has_Rep_Item (Typ, Name_Volatile_Components, False)
10004 and then Has_Rep_Item (Typ, Name_Volatile_Components)
10005 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
10006 (Get_Rep_Item (Typ, Name_Volatile_Components))
10008 Set_Has_Volatile_Components (Imp_Bas_Typ);
10011 -- Finalize_Storage_Only.
10013 if not Has_Rep_Pragma (Typ, Name_Finalize_Storage_Only, False)
10014 and then Has_Rep_Pragma (Typ, Name_Finalize_Storage_Only)
10016 Set_Finalize_Storage_Only (Bas_Typ);
10019 -- Universal_Aliasing
10021 if not Has_Rep_Item (Typ, Name_Universal_Aliasing, False)
10022 and then Has_Rep_Item (Typ, Name_Universal_Aliasing)
10023 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
10024 (Get_Rep_Item (Typ, Name_Universal_Aliasing))
10026 Set_Universal_Aliasing (Imp_Bas_Typ);
10029 -- Record type specific aspects
10031 if Is_Record_Type (Typ) then
10035 if not Has_Rep_Item (Typ, Name_Bit_Order, False)
10036 and then Has_Rep_Item (Typ, Name_Bit_Order)
10038 Set_Reverse_Bit_Order (Bas_Typ,
10039 Reverse_Bit_Order (Entity (Name
10040 (Get_Rep_Item (Typ, Name_Bit_Order)))));
10043 -- Scalar_Storage_Order
10045 if not Has_Rep_Item (Typ, Name_Scalar_Storage_Order, False)
10046 and then Has_Rep_Item (Typ, Name_Scalar_Storage_Order)
10048 Set_Reverse_Storage_Order (Bas_Typ,
10049 Reverse_Storage_Order (Entity (Name
10050 (Get_Rep_Item (Typ, Name_Scalar_Storage_Order)))));
10055 end Inherit_Aspects_At_Freeze_Point;
10061 procedure Initialize is
10063 Address_Clause_Checks.Init;
10064 Independence_Checks.Init;
10065 Unchecked_Conversions.Init;
10068 ---------------------------
10069 -- Install_Discriminants --
10070 ---------------------------
10072 procedure Install_Discriminants (E : Entity_Id) is
10076 Disc := First_Discriminant (E);
10077 while Present (Disc) loop
10078 Prev := Current_Entity (Disc);
10079 Set_Current_Entity (Disc);
10080 Set_Is_Immediately_Visible (Disc);
10081 Set_Homonym (Disc, Prev);
10082 Next_Discriminant (Disc);
10084 end Install_Discriminants;
10086 -------------------------
10087 -- Is_Operational_Item --
10088 -------------------------
10090 function Is_Operational_Item (N : Node_Id) return Boolean is
10092 if Nkind (N) /= N_Attribute_Definition_Clause then
10097 Id : constant Attribute_Id := Get_Attribute_Id (Chars (N));
10099 return Id = Attribute_Input
10100 or else Id = Attribute_Output
10101 or else Id = Attribute_Read
10102 or else Id = Attribute_Write
10103 or else Id = Attribute_External_Tag;
10106 end Is_Operational_Item;
10112 function Minimum_Size
10114 Biased : Boolean := False) return Nat
10116 Lo : Uint := No_Uint;
10117 Hi : Uint := No_Uint;
10118 LoR : Ureal := No_Ureal;
10119 HiR : Ureal := No_Ureal;
10120 LoSet : Boolean := False;
10121 HiSet : Boolean := False;
10124 Ancest : Entity_Id;
10125 R_Typ : constant Entity_Id := Root_Type (T);
10128 -- If bad type, return 0
10130 if T = Any_Type then
10133 -- For generic types, just return zero. There cannot be any legitimate
10134 -- need to know such a size, but this routine may be called with a
10135 -- generic type as part of normal processing.
10137 elsif Is_Generic_Type (R_Typ)
10138 or else R_Typ = Any_Type
10142 -- Access types. Normally an access type cannot have a size smaller
10143 -- than the size of System.Address. The exception is on VMS, where
10144 -- we have short and long addresses, and it is possible for an access
10145 -- type to have a short address size (and thus be less than the size
10146 -- of System.Address itself). We simply skip the check for VMS, and
10147 -- leave it to the back end to do the check.
10149 elsif Is_Access_Type (T) then
10150 if OpenVMS_On_Target then
10153 return System_Address_Size;
10156 -- Floating-point types
10158 elsif Is_Floating_Point_Type (T) then
10159 return UI_To_Int (Esize (R_Typ));
10163 elsif Is_Discrete_Type (T) then
10165 -- The following loop is looking for the nearest compile time known
10166 -- bounds following the ancestor subtype chain. The idea is to find
10167 -- the most restrictive known bounds information.
10171 if Ancest = Any_Type or else Etype (Ancest) = Any_Type then
10176 if Compile_Time_Known_Value (Type_Low_Bound (Ancest)) then
10177 Lo := Expr_Rep_Value (Type_Low_Bound (Ancest));
10184 if Compile_Time_Known_Value (Type_High_Bound (Ancest)) then
10185 Hi := Expr_Rep_Value (Type_High_Bound (Ancest));
10191 Ancest := Ancestor_Subtype (Ancest);
10193 if No (Ancest) then
10194 Ancest := Base_Type (T);
10196 if Is_Generic_Type (Ancest) then
10202 -- Fixed-point types. We can't simply use Expr_Value to get the
10203 -- Corresponding_Integer_Value values of the bounds, since these do not
10204 -- get set till the type is frozen, and this routine can be called
10205 -- before the type is frozen. Similarly the test for bounds being static
10206 -- needs to include the case where we have unanalyzed real literals for
10207 -- the same reason.
10209 elsif Is_Fixed_Point_Type (T) then
10211 -- The following loop is looking for the nearest compile time known
10212 -- bounds following the ancestor subtype chain. The idea is to find
10213 -- the most restrictive known bounds information.
10217 if Ancest = Any_Type or else Etype (Ancest) = Any_Type then
10221 -- Note: In the following two tests for LoSet and HiSet, it may
10222 -- seem redundant to test for N_Real_Literal here since normally
10223 -- one would assume that the test for the value being known at
10224 -- compile time includes this case. However, there is a glitch.
10225 -- If the real literal comes from folding a non-static expression,
10226 -- then we don't consider any non- static expression to be known
10227 -- at compile time if we are in configurable run time mode (needed
10228 -- in some cases to give a clearer definition of what is and what
10229 -- is not accepted). So the test is indeed needed. Without it, we
10230 -- would set neither Lo_Set nor Hi_Set and get an infinite loop.
10233 if Nkind (Type_Low_Bound (Ancest)) = N_Real_Literal
10234 or else Compile_Time_Known_Value (Type_Low_Bound (Ancest))
10236 LoR := Expr_Value_R (Type_Low_Bound (Ancest));
10243 if Nkind (Type_High_Bound (Ancest)) = N_Real_Literal
10244 or else Compile_Time_Known_Value (Type_High_Bound (Ancest))
10246 HiR := Expr_Value_R (Type_High_Bound (Ancest));
10252 Ancest := Ancestor_Subtype (Ancest);
10254 if No (Ancest) then
10255 Ancest := Base_Type (T);
10257 if Is_Generic_Type (Ancest) then
10263 Lo := UR_To_Uint (LoR / Small_Value (T));
10264 Hi := UR_To_Uint (HiR / Small_Value (T));
10266 -- No other types allowed
10269 raise Program_Error;
10272 -- Fall through with Hi and Lo set. Deal with biased case
10275 and then not Is_Fixed_Point_Type (T)
10276 and then not (Is_Enumeration_Type (T)
10277 and then Has_Non_Standard_Rep (T)))
10278 or else Has_Biased_Representation (T)
10284 -- Signed case. Note that we consider types like range 1 .. -1 to be
10285 -- signed for the purpose of computing the size, since the bounds have
10286 -- to be accommodated in the base type.
10288 if Lo < 0 or else Hi < 0 then
10292 -- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1))
10293 -- Note that we accommodate the case where the bounds cross. This
10294 -- can happen either because of the way the bounds are declared
10295 -- or because of the algorithm in Freeze_Fixed_Point_Type.
10309 -- If both bounds are positive, make sure that both are represen-
10310 -- table in the case where the bounds are crossed. This can happen
10311 -- either because of the way the bounds are declared, or because of
10312 -- the algorithm in Freeze_Fixed_Point_Type.
10318 -- S = size, (can accommodate 0 .. (2**size - 1))
10321 while Hi >= Uint_2 ** S loop
10329 ---------------------------
10330 -- New_Stream_Subprogram --
10331 ---------------------------
10333 procedure New_Stream_Subprogram
10337 Nam : TSS_Name_Type)
10339 Loc : constant Source_Ptr := Sloc (N);
10340 Sname : constant Name_Id := Make_TSS_Name (Base_Type (Ent), Nam);
10341 Subp_Id : Entity_Id;
10342 Subp_Decl : Node_Id;
10346 Defer_Declaration : constant Boolean :=
10347 Is_Tagged_Type (Ent) or else Is_Private_Type (Ent);
10348 -- For a tagged type, there is a declaration for each stream attribute
10349 -- at the freeze point, and we must generate only a completion of this
10350 -- declaration. We do the same for private types, because the full view
10351 -- might be tagged. Otherwise we generate a declaration at the point of
10352 -- the attribute definition clause.
10354 function Build_Spec return Node_Id;
10355 -- Used for declaration and renaming declaration, so that this is
10356 -- treated as a renaming_as_body.
10362 function Build_Spec return Node_Id is
10363 Out_P : constant Boolean := (Nam = TSS_Stream_Read);
10366 T_Ref : constant Node_Id := New_Occurrence_Of (Etyp, Loc);
10369 Subp_Id := Make_Defining_Identifier (Loc, Sname);
10371 -- S : access Root_Stream_Type'Class
10373 Formals := New_List (
10374 Make_Parameter_Specification (Loc,
10375 Defining_Identifier =>
10376 Make_Defining_Identifier (Loc, Name_S),
10378 Make_Access_Definition (Loc,
10380 New_Occurrence_Of (
10381 Designated_Type (Etype (F)), Loc))));
10383 if Nam = TSS_Stream_Input then
10385 Make_Function_Specification (Loc,
10386 Defining_Unit_Name => Subp_Id,
10387 Parameter_Specifications => Formals,
10388 Result_Definition => T_Ref);
10392 Append_To (Formals,
10393 Make_Parameter_Specification (Loc,
10394 Defining_Identifier => Make_Defining_Identifier (Loc, Name_V),
10395 Out_Present => Out_P,
10396 Parameter_Type => T_Ref));
10399 Make_Procedure_Specification (Loc,
10400 Defining_Unit_Name => Subp_Id,
10401 Parameter_Specifications => Formals);
10407 -- Start of processing for New_Stream_Subprogram
10410 F := First_Formal (Subp);
10412 if Ekind (Subp) = E_Procedure then
10413 Etyp := Etype (Next_Formal (F));
10415 Etyp := Etype (Subp);
10418 -- Prepare subprogram declaration and insert it as an action on the
10419 -- clause node. The visibility for this entity is used to test for
10420 -- visibility of the attribute definition clause (in the sense of
10421 -- 8.3(23) as amended by AI-195).
10423 if not Defer_Declaration then
10425 Make_Subprogram_Declaration (Loc,
10426 Specification => Build_Spec);
10428 -- For a tagged type, there is always a visible declaration for each
10429 -- stream TSS (it is a predefined primitive operation), and the
10430 -- completion of this declaration occurs at the freeze point, which is
10431 -- not always visible at places where the attribute definition clause is
10432 -- visible. So, we create a dummy entity here for the purpose of
10433 -- tracking the visibility of the attribute definition clause itself.
10437 Make_Defining_Identifier (Loc, New_External_Name (Sname, 'V'));
10439 Make_Object_Declaration (Loc,
10440 Defining_Identifier => Subp_Id,
10441 Object_Definition => New_Occurrence_Of (Standard_Boolean, Loc));
10444 Insert_Action (N, Subp_Decl);
10445 Set_Entity (N, Subp_Id);
10448 Make_Subprogram_Renaming_Declaration (Loc,
10449 Specification => Build_Spec,
10450 Name => New_Occurrence_Of (Subp, Loc));
10452 if Defer_Declaration then
10453 Set_TSS (Base_Type (Ent), Subp_Id);
10455 Insert_Action (N, Subp_Decl);
10456 Copy_TSS (Subp_Id, Base_Type (Ent));
10458 end New_Stream_Subprogram;
10460 ------------------------------------------
10461 -- Push_Scope_And_Install_Discriminants --
10462 ------------------------------------------
10464 procedure Push_Scope_And_Install_Discriminants (E : Entity_Id) is
10466 if Has_Discriminants (E) then
10469 -- Make discriminants visible for type declarations and protected
10470 -- type declarations, not for subtype declarations (RM 13.1.1 (12/3))
10472 if Nkind (Parent (E)) /= N_Subtype_Declaration then
10473 Install_Discriminants (E);
10476 end Push_Scope_And_Install_Discriminants;
10478 ------------------------
10479 -- Rep_Item_Too_Early --
10480 ------------------------
10482 function Rep_Item_Too_Early (T : Entity_Id; N : Node_Id) return Boolean is
10484 -- Cannot apply non-operational rep items to generic types
10486 if Is_Operational_Item (N) then
10490 and then Is_Generic_Type (Root_Type (T))
10492 Error_Msg_N ("representation item not allowed for generic type", N);
10496 -- Otherwise check for incomplete type
10498 if Is_Incomplete_Or_Private_Type (T)
10499 and then No (Underlying_Type (T))
10501 (Nkind (N) /= N_Pragma
10502 or else Get_Pragma_Id (N) /= Pragma_Import)
10505 ("representation item must be after full type declaration", N);
10508 -- If the type has incomplete components, a representation clause is
10509 -- illegal but stream attributes and Convention pragmas are correct.
10511 elsif Has_Private_Component (T) then
10512 if Nkind (N) = N_Pragma then
10517 ("representation item must appear after type is fully defined",
10524 end Rep_Item_Too_Early;
10526 -----------------------
10527 -- Rep_Item_Too_Late --
10528 -----------------------
10530 function Rep_Item_Too_Late
10533 FOnly : Boolean := False) return Boolean
10536 Parent_Type : Entity_Id;
10538 procedure Too_Late;
10539 -- Output the too late message. Note that this is not considered a
10540 -- serious error, since the effect is simply that we ignore the
10541 -- representation clause in this case.
10547 procedure Too_Late is
10549 -- Other compilers seem more relaxed about rep items appearing too
10550 -- late. Since analysis tools typically don't care about rep items
10551 -- anyway, no reason to be too strict about this.
10553 if not Relaxed_RM_Semantics then
10554 Error_Msg_N ("|representation item appears too late!", N);
10558 -- Start of processing for Rep_Item_Too_Late
10561 -- First make sure entity is not frozen (RM 13.1(9))
10565 -- Exclude imported types, which may be frozen if they appear in a
10566 -- representation clause for a local type.
10568 and then not From_Limited_With (T)
10570 -- Exclude generated entities (not coming from source). The common
10571 -- case is when we generate a renaming which prematurely freezes the
10572 -- renamed internal entity, but we still want to be able to set copies
10573 -- of attribute values such as Size/Alignment.
10575 and then Comes_From_Source (T)
10578 S := First_Subtype (T);
10580 if Present (Freeze_Node (S)) then
10582 ("??no more representation items for }", Freeze_Node (S), S);
10587 -- Check for case of non-tagged derived type whose parent either has
10588 -- primitive operations, or is a by reference type (RM 13.1(10)).
10592 and then Is_Derived_Type (T)
10593 and then not Is_Tagged_Type (T)
10595 Parent_Type := Etype (Base_Type (T));
10597 if Has_Primitive_Operations (Parent_Type) then
10600 ("primitive operations already defined for&!", N, Parent_Type);
10603 elsif Is_By_Reference_Type (Parent_Type) then
10606 ("parent type & is a by reference type!", N, Parent_Type);
10611 -- No error, link item into head of chain of rep items for the entity,
10612 -- but avoid chaining if we have an overloadable entity, and the pragma
10613 -- is one that can apply to multiple overloaded entities.
10615 if Is_Overloadable (T) and then Nkind (N) = N_Pragma then
10617 Pname : constant Name_Id := Pragma_Name (N);
10619 if Nam_In (Pname, Name_Convention, Name_Import, Name_Export,
10620 Name_External, Name_Interface)
10627 Record_Rep_Item (T, N);
10629 end Rep_Item_Too_Late;
10631 -------------------------------------
10632 -- Replace_Type_References_Generic --
10633 -------------------------------------
10635 procedure Replace_Type_References_Generic (N : Node_Id; TName : Name_Id) is
10637 function Replace_Node (N : Node_Id) return Traverse_Result;
10638 -- Processes a single node in the traversal procedure below, checking
10639 -- if node N should be replaced, and if so, doing the replacement.
10641 procedure Replace_Type_Refs is new Traverse_Proc (Replace_Node);
10642 -- This instantiation provides the body of Replace_Type_References
10648 function Replace_Node (N : Node_Id) return Traverse_Result is
10653 -- Case of identifier
10655 if Nkind (N) = N_Identifier then
10657 -- If not the type name, all done with this node
10659 if Chars (N) /= TName then
10662 -- Otherwise do the replacement and we are done with this node
10665 Replace_Type_Reference (N);
10669 -- Case of selected component (which is what a qualification
10670 -- looks like in the unanalyzed tree, which is what we have.
10672 elsif Nkind (N) = N_Selected_Component then
10674 -- If selector name is not our type, keeping going (we might
10675 -- still have an occurrence of the type in the prefix).
10677 if Nkind (Selector_Name (N)) /= N_Identifier
10678 or else Chars (Selector_Name (N)) /= TName
10682 -- Selector name is our type, check qualification
10685 -- Loop through scopes and prefixes, doing comparison
10687 S := Current_Scope;
10690 -- Continue if no more scopes or scope with no name
10692 if No (S) or else Nkind (S) not in N_Has_Chars then
10696 -- Do replace if prefix is an identifier matching the
10697 -- scope that we are currently looking at.
10699 if Nkind (P) = N_Identifier
10700 and then Chars (P) = Chars (S)
10702 Replace_Type_Reference (N);
10706 -- Go check scope above us if prefix is itself of the
10707 -- form of a selected component, whose selector matches
10708 -- the scope we are currently looking at.
10710 if Nkind (P) = N_Selected_Component
10711 and then Nkind (Selector_Name (P)) = N_Identifier
10712 and then Chars (Selector_Name (P)) = Chars (S)
10717 -- For anything else, we don't have a match, so keep on
10718 -- going, there are still some weird cases where we may
10719 -- still have a replacement within the prefix.
10727 -- Continue for any other node kind
10735 Replace_Type_Refs (N);
10736 end Replace_Type_References_Generic;
10738 -------------------------
10739 -- Same_Representation --
10740 -------------------------
10742 function Same_Representation (Typ1, Typ2 : Entity_Id) return Boolean is
10743 T1 : constant Entity_Id := Underlying_Type (Typ1);
10744 T2 : constant Entity_Id := Underlying_Type (Typ2);
10747 -- A quick check, if base types are the same, then we definitely have
10748 -- the same representation, because the subtype specific representation
10749 -- attributes (Size and Alignment) do not affect representation from
10750 -- the point of view of this test.
10752 if Base_Type (T1) = Base_Type (T2) then
10755 elsif Is_Private_Type (Base_Type (T2))
10756 and then Base_Type (T1) = Full_View (Base_Type (T2))
10761 -- Tagged types never have differing representations
10763 if Is_Tagged_Type (T1) then
10767 -- Representations are definitely different if conventions differ
10769 if Convention (T1) /= Convention (T2) then
10773 -- Representations are different if component alignments or scalar
10774 -- storage orders differ.
10776 if (Is_Record_Type (T1) or else Is_Array_Type (T1))
10778 (Is_Record_Type (T2) or else Is_Array_Type (T2))
10780 (Component_Alignment (T1) /= Component_Alignment (T2)
10782 Reverse_Storage_Order (T1) /= Reverse_Storage_Order (T2))
10787 -- For arrays, the only real issue is component size. If we know the
10788 -- component size for both arrays, and it is the same, then that's
10789 -- good enough to know we don't have a change of representation.
10791 if Is_Array_Type (T1) then
10792 if Known_Component_Size (T1)
10793 and then Known_Component_Size (T2)
10794 and then Component_Size (T1) = Component_Size (T2)
10796 if VM_Target = No_VM then
10799 -- In VM targets the representation of arrays with aliased
10800 -- components differs from arrays with non-aliased components
10803 return Has_Aliased_Components (Base_Type (T1))
10805 Has_Aliased_Components (Base_Type (T2));
10810 -- Types definitely have same representation if neither has non-standard
10811 -- representation since default representations are always consistent.
10812 -- If only one has non-standard representation, and the other does not,
10813 -- then we consider that they do not have the same representation. They
10814 -- might, but there is no way of telling early enough.
10816 if Has_Non_Standard_Rep (T1) then
10817 if not Has_Non_Standard_Rep (T2) then
10821 return not Has_Non_Standard_Rep (T2);
10824 -- Here the two types both have non-standard representation, and we need
10825 -- to determine if they have the same non-standard representation.
10827 -- For arrays, we simply need to test if the component sizes are the
10828 -- same. Pragma Pack is reflected in modified component sizes, so this
10829 -- check also deals with pragma Pack.
10831 if Is_Array_Type (T1) then
10832 return Component_Size (T1) = Component_Size (T2);
10834 -- Tagged types always have the same representation, because it is not
10835 -- possible to specify different representations for common fields.
10837 elsif Is_Tagged_Type (T1) then
10840 -- Case of record types
10842 elsif Is_Record_Type (T1) then
10844 -- Packed status must conform
10846 if Is_Packed (T1) /= Is_Packed (T2) then
10849 -- Otherwise we must check components. Typ2 maybe a constrained
10850 -- subtype with fewer components, so we compare the components
10851 -- of the base types.
10854 Record_Case : declare
10855 CD1, CD2 : Entity_Id;
10857 function Same_Rep return Boolean;
10858 -- CD1 and CD2 are either components or discriminants. This
10859 -- function tests whether they have the same representation.
10865 function Same_Rep return Boolean is
10867 if No (Component_Clause (CD1)) then
10868 return No (Component_Clause (CD2));
10870 -- Note: at this point, component clauses have been
10871 -- normalized to the default bit order, so that the
10872 -- comparison of Component_Bit_Offsets is meaningful.
10875 Present (Component_Clause (CD2))
10877 Component_Bit_Offset (CD1) = Component_Bit_Offset (CD2)
10879 Esize (CD1) = Esize (CD2);
10883 -- Start of processing for Record_Case
10886 if Has_Discriminants (T1) then
10888 -- The number of discriminants may be different if the
10889 -- derived type has fewer (constrained by values). The
10890 -- invisible discriminants retain the representation of
10891 -- the original, so the discrepancy does not per se
10892 -- indicate a different representation.
10894 CD1 := First_Discriminant (T1);
10895 CD2 := First_Discriminant (T2);
10896 while Present (CD1) and then Present (CD2) loop
10897 if not Same_Rep then
10900 Next_Discriminant (CD1);
10901 Next_Discriminant (CD2);
10906 CD1 := First_Component (Underlying_Type (Base_Type (T1)));
10907 CD2 := First_Component (Underlying_Type (Base_Type (T2)));
10908 while Present (CD1) loop
10909 if not Same_Rep then
10912 Next_Component (CD1);
10913 Next_Component (CD2);
10921 -- For enumeration types, we must check each literal to see if the
10922 -- representation is the same. Note that we do not permit enumeration
10923 -- representation clauses for Character and Wide_Character, so these
10924 -- cases were already dealt with.
10926 elsif Is_Enumeration_Type (T1) then
10927 Enumeration_Case : declare
10928 L1, L2 : Entity_Id;
10931 L1 := First_Literal (T1);
10932 L2 := First_Literal (T2);
10933 while Present (L1) loop
10934 if Enumeration_Rep (L1) /= Enumeration_Rep (L2) then
10943 end Enumeration_Case;
10945 -- Any other types have the same representation for these purposes
10950 end Same_Representation;
10952 --------------------------------
10953 -- Resolve_Iterable_Operation --
10954 --------------------------------
10956 procedure Resolve_Iterable_Operation
10958 Cursor : Entity_Id;
10967 if not Is_Overloaded (N) then
10968 if not Is_Entity_Name (N)
10969 or else Ekind (Entity (N)) /= E_Function
10970 or else Scope (Entity (N)) /= Scope (Typ)
10971 or else No (First_Formal (Entity (N)))
10972 or else Etype (First_Formal (Entity (N))) /= Typ
10974 Error_Msg_N ("iterable primitive must be local function name "
10975 & "whose first formal is an iterable type", N);
10980 F1 := First_Formal (Ent);
10981 if Nam = Name_First then
10983 -- First (Container) => Cursor
10985 if Etype (Ent) /= Cursor then
10986 Error_Msg_N ("primitive for First must yield a curosr", N);
10989 elsif Nam = Name_Next then
10991 -- Next (Container, Cursor) => Cursor
10993 F2 := Next_Formal (F1);
10995 if Etype (F2) /= Cursor
10996 or else Etype (Ent) /= Cursor
10997 or else Present (Next_Formal (F2))
10999 Error_Msg_N ("no match for Next iterable primitive", N);
11002 elsif Nam = Name_Has_Element then
11004 -- Has_Element (Container, Cursor) => Boolean
11006 F2 := Next_Formal (F1);
11007 if Etype (F2) /= Cursor
11008 or else Etype (Ent) /= Standard_Boolean
11009 or else Present (Next_Formal (F2))
11011 Error_Msg_N ("no match for Has_Element iterable primitive", N);
11014 elsif Nam = Name_Element then
11015 F2 := Next_Formal (F1);
11018 or else Etype (F2) /= Cursor
11019 or else Present (Next_Formal (F2))
11021 Error_Msg_N ("no match for Element iterable primitive", N);
11026 raise Program_Error;
11030 -- Overloaded case: find subprogram with proper signature.
11031 -- Caller will report error if no match is found.
11038 Get_First_Interp (N, I, It);
11039 while Present (It.Typ) loop
11040 if Ekind (It.Nam) = E_Function
11041 and then Scope (It.Nam) = Scope (Typ)
11042 and then Etype (First_Formal (It.Nam)) = Typ
11044 F1 := First_Formal (It.Nam);
11046 if Nam = Name_First then
11047 if Etype (It.Nam) = Cursor
11048 and then No (Next_Formal (F1))
11050 Set_Entity (N, It.Nam);
11054 elsif Nam = Name_Next then
11055 F2 := Next_Formal (F1);
11058 and then No (Next_Formal (F2))
11059 and then Etype (F2) = Cursor
11060 and then Etype (It.Nam) = Cursor
11062 Set_Entity (N, It.Nam);
11066 elsif Nam = Name_Has_Element then
11067 F2 := Next_Formal (F1);
11070 and then No (Next_Formal (F2))
11071 and then Etype (F2) = Cursor
11072 and then Etype (It.Nam) = Standard_Boolean
11074 Set_Entity (N, It.Nam);
11075 F2 := Next_Formal (F1);
11079 elsif Nam = Name_Element then
11080 F2 := Next_Formal (F1);
11083 and then No (Next_Formal (F2))
11084 and then Etype (F2) = Cursor
11086 Set_Entity (N, It.Nam);
11092 Get_Next_Interp (I, It);
11096 end Resolve_Iterable_Operation;
11102 procedure Set_Biased
11106 Biased : Boolean := True)
11110 Set_Has_Biased_Representation (E);
11112 if Warn_On_Biased_Representation then
11114 ("?B?" & Msg & " forces biased representation for&", N, E);
11119 --------------------
11120 -- Set_Enum_Esize --
11121 --------------------
11123 procedure Set_Enum_Esize (T : Entity_Id) is
11129 Init_Alignment (T);
11131 -- Find the minimum standard size (8,16,32,64) that fits
11133 Lo := Enumeration_Rep (Entity (Type_Low_Bound (T)));
11134 Hi := Enumeration_Rep (Entity (Type_High_Bound (T)));
11137 if Lo >= -Uint_2**07 and then Hi < Uint_2**07 then
11138 Sz := Standard_Character_Size; -- May be > 8 on some targets
11140 elsif Lo >= -Uint_2**15 and then Hi < Uint_2**15 then
11143 elsif Lo >= -Uint_2**31 and then Hi < Uint_2**31 then
11146 else pragma Assert (Lo >= -Uint_2**63 and then Hi < Uint_2**63);
11151 if Hi < Uint_2**08 then
11152 Sz := Standard_Character_Size; -- May be > 8 on some targets
11154 elsif Hi < Uint_2**16 then
11157 elsif Hi < Uint_2**32 then
11160 else pragma Assert (Hi < Uint_2**63);
11165 -- That minimum is the proper size unless we have a foreign convention
11166 -- and the size required is 32 or less, in which case we bump the size
11167 -- up to 32. This is required for C and C++ and seems reasonable for
11168 -- all other foreign conventions.
11170 if Has_Foreign_Convention (T)
11171 and then Esize (T) < Standard_Integer_Size
11173 -- Don't do this if Short_Enums on target
11175 and then not Target_Short_Enums
11177 Init_Esize (T, Standard_Integer_Size);
11179 Init_Esize (T, Sz);
11181 end Set_Enum_Esize;
11183 -----------------------------
11184 -- Uninstall_Discriminants --
11185 -----------------------------
11187 procedure Uninstall_Discriminants (E : Entity_Id) is
11193 -- Discriminants have been made visible for type declarations and
11194 -- protected type declarations, not for subtype declarations.
11196 if Nkind (Parent (E)) /= N_Subtype_Declaration then
11197 Disc := First_Discriminant (E);
11198 while Present (Disc) loop
11199 if Disc /= Current_Entity (Disc) then
11200 Prev := Current_Entity (Disc);
11201 while Present (Prev)
11202 and then Present (Homonym (Prev))
11203 and then Homonym (Prev) /= Disc
11205 Prev := Homonym (Prev);
11211 Set_Is_Immediately_Visible (Disc, False);
11213 Outer := Homonym (Disc);
11214 while Present (Outer) and then Scope (Outer) = E loop
11215 Outer := Homonym (Outer);
11218 -- Reset homonym link of other entities, but do not modify link
11219 -- between entities in current scope, so that the back-end can
11220 -- have a proper count of local overloadings.
11223 Set_Name_Entity_Id (Chars (Disc), Outer);
11225 elsif Scope (Prev) /= Scope (Disc) then
11226 Set_Homonym (Prev, Outer);
11229 Next_Discriminant (Disc);
11232 end Uninstall_Discriminants;
11234 -------------------------------------------
11235 -- Uninstall_Discriminants_And_Pop_Scope --
11236 -------------------------------------------
11238 procedure Uninstall_Discriminants_And_Pop_Scope (E : Entity_Id) is
11240 if Has_Discriminants (E) then
11241 Uninstall_Discriminants (E);
11244 end Uninstall_Discriminants_And_Pop_Scope;
11246 ------------------------------
11247 -- Validate_Address_Clauses --
11248 ------------------------------
11250 procedure Validate_Address_Clauses is
11252 for J in Address_Clause_Checks.First .. Address_Clause_Checks.Last loop
11254 ACCR : Address_Clause_Check_Record
11255 renames Address_Clause_Checks.Table (J);
11259 X_Alignment : Uint;
11260 Y_Alignment : Uint;
11266 -- Skip processing of this entry if warning already posted
11268 if not Address_Warning_Posted (ACCR.N) then
11269 Expr := Original_Node (Expression (ACCR.N));
11273 X_Alignment := Alignment (ACCR.X);
11274 Y_Alignment := Alignment (ACCR.Y);
11276 -- Similarly obtain sizes
11278 X_Size := Esize (ACCR.X);
11279 Y_Size := Esize (ACCR.Y);
11281 -- Check for large object overlaying smaller one
11284 and then X_Size > Uint_0
11285 and then X_Size > Y_Size
11288 ("??& overlays smaller object", ACCR.N, ACCR.X);
11290 ("\??program execution may be erroneous", ACCR.N);
11291 Error_Msg_Uint_1 := X_Size;
11293 ("\??size of & is ^", ACCR.N, ACCR.X);
11294 Error_Msg_Uint_1 := Y_Size;
11296 ("\??size of & is ^", ACCR.N, ACCR.Y);
11298 -- Check for inadequate alignment, both of the base object
11299 -- and of the offset, if any.
11301 -- Note: we do not check the alignment if we gave a size
11302 -- warning, since it would likely be redundant.
11304 elsif Y_Alignment /= Uint_0
11305 and then (Y_Alignment < X_Alignment
11308 Nkind (Expr) = N_Attribute_Reference
11310 Attribute_Name (Expr) = Name_Address
11312 Has_Compatible_Alignment
11313 (ACCR.X, Prefix (Expr))
11314 /= Known_Compatible))
11317 ("??specified address for& may be inconsistent "
11318 & "with alignment", ACCR.N, ACCR.X);
11320 ("\??program execution may be erroneous (RM 13.3(27))",
11322 Error_Msg_Uint_1 := X_Alignment;
11324 ("\??alignment of & is ^", ACCR.N, ACCR.X);
11325 Error_Msg_Uint_1 := Y_Alignment;
11327 ("\??alignment of & is ^", ACCR.N, ACCR.Y);
11328 if Y_Alignment >= X_Alignment then
11330 ("\??but offset is not multiple of alignment", ACCR.N);
11336 end Validate_Address_Clauses;
11338 ---------------------------
11339 -- Validate_Independence --
11340 ---------------------------
11342 procedure Validate_Independence is
11343 SU : constant Uint := UI_From_Int (System_Storage_Unit);
11351 procedure Check_Array_Type (Atyp : Entity_Id);
11352 -- Checks if the array type Atyp has independent components, and
11353 -- if not, outputs an appropriate set of error messages.
11355 procedure No_Independence;
11356 -- Output message that independence cannot be guaranteed
11358 function OK_Component (C : Entity_Id) return Boolean;
11359 -- Checks one component to see if it is independently accessible, and
11360 -- if so yields True, otherwise yields False if independent access
11361 -- cannot be guaranteed. This is a conservative routine, it only
11362 -- returns True if it knows for sure, it returns False if it knows
11363 -- there is a problem, or it cannot be sure there is no problem.
11365 procedure Reason_Bad_Component (C : Entity_Id);
11366 -- Outputs continuation message if a reason can be determined for
11367 -- the component C being bad.
11369 ----------------------
11370 -- Check_Array_Type --
11371 ----------------------
11373 procedure Check_Array_Type (Atyp : Entity_Id) is
11374 Ctyp : constant Entity_Id := Component_Type (Atyp);
11377 -- OK if no alignment clause, no pack, and no component size
11379 if not Has_Component_Size_Clause (Atyp)
11380 and then not Has_Alignment_Clause (Atyp)
11381 and then not Is_Packed (Atyp)
11386 -- Check actual component size
11388 if not Known_Component_Size (Atyp)
11389 or else not (Addressable (Component_Size (Atyp))
11390 and then Component_Size (Atyp) < 64)
11391 or else Component_Size (Atyp) mod Esize (Ctyp) /= 0
11395 -- Bad component size, check reason
11397 if Has_Component_Size_Clause (Atyp) then
11398 P := Get_Attribute_Definition_Clause
11399 (Atyp, Attribute_Component_Size);
11401 if Present (P) then
11402 Error_Msg_Sloc := Sloc (P);
11403 Error_Msg_N ("\because of Component_Size clause#", N);
11408 if Is_Packed (Atyp) then
11409 P := Get_Rep_Pragma (Atyp, Name_Pack);
11411 if Present (P) then
11412 Error_Msg_Sloc := Sloc (P);
11413 Error_Msg_N ("\because of pragma Pack#", N);
11418 -- No reason found, just return
11423 -- Array type is OK independence-wise
11426 end Check_Array_Type;
11428 ---------------------
11429 -- No_Independence --
11430 ---------------------
11432 procedure No_Independence is
11434 if Pragma_Name (N) = Name_Independent then
11435 Error_Msg_NE ("independence cannot be guaranteed for&", N, E);
11438 ("independent components cannot be guaranteed for&", N, E);
11440 end No_Independence;
11446 function OK_Component (C : Entity_Id) return Boolean is
11447 Rec : constant Entity_Id := Scope (C);
11448 Ctyp : constant Entity_Id := Etype (C);
11451 -- OK if no component clause, no Pack, and no alignment clause
11453 if No (Component_Clause (C))
11454 and then not Is_Packed (Rec)
11455 and then not Has_Alignment_Clause (Rec)
11460 -- Here we look at the actual component layout. A component is
11461 -- addressable if its size is a multiple of the Esize of the
11462 -- component type, and its starting position in the record has
11463 -- appropriate alignment, and the record itself has appropriate
11464 -- alignment to guarantee the component alignment.
11466 -- Make sure sizes are static, always assume the worst for any
11467 -- cases where we cannot check static values.
11469 if not (Known_Static_Esize (C)
11471 Known_Static_Esize (Ctyp))
11476 -- Size of component must be addressable or greater than 64 bits
11477 -- and a multiple of bytes.
11479 if not Addressable (Esize (C)) and then Esize (C) < Uint_64 then
11483 -- Check size is proper multiple
11485 if Esize (C) mod Esize (Ctyp) /= 0 then
11489 -- Check alignment of component is OK
11491 if not Known_Component_Bit_Offset (C)
11492 or else Component_Bit_Offset (C) < Uint_0
11493 or else Component_Bit_Offset (C) mod Esize (Ctyp) /= 0
11498 -- Check alignment of record type is OK
11500 if not Known_Alignment (Rec)
11501 or else (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0
11506 -- All tests passed, component is addressable
11511 --------------------------
11512 -- Reason_Bad_Component --
11513 --------------------------
11515 procedure Reason_Bad_Component (C : Entity_Id) is
11516 Rec : constant Entity_Id := Scope (C);
11517 Ctyp : constant Entity_Id := Etype (C);
11520 -- If component clause present assume that's the problem
11522 if Present (Component_Clause (C)) then
11523 Error_Msg_Sloc := Sloc (Component_Clause (C));
11524 Error_Msg_N ("\because of Component_Clause#", N);
11528 -- If pragma Pack clause present, assume that's the problem
11530 if Is_Packed (Rec) then
11531 P := Get_Rep_Pragma (Rec, Name_Pack);
11533 if Present (P) then
11534 Error_Msg_Sloc := Sloc (P);
11535 Error_Msg_N ("\because of pragma Pack#", N);
11540 -- See if record has bad alignment clause
11542 if Has_Alignment_Clause (Rec)
11543 and then Known_Alignment (Rec)
11544 and then (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0
11546 P := Get_Attribute_Definition_Clause (Rec, Attribute_Alignment);
11548 if Present (P) then
11549 Error_Msg_Sloc := Sloc (P);
11550 Error_Msg_N ("\because of Alignment clause#", N);
11554 -- Couldn't find a reason, so return without a message
11557 end Reason_Bad_Component;
11559 -- Start of processing for Validate_Independence
11562 for J in Independence_Checks.First .. Independence_Checks.Last loop
11563 N := Independence_Checks.Table (J).N;
11564 E := Independence_Checks.Table (J).E;
11565 IC := Pragma_Name (N) = Name_Independent_Components;
11567 -- Deal with component case
11569 if Ekind (E) = E_Discriminant or else Ekind (E) = E_Component then
11570 if not OK_Component (E) then
11572 Reason_Bad_Component (E);
11577 -- Deal with record with Independent_Components
11579 if IC and then Is_Record_Type (E) then
11580 Comp := First_Component_Or_Discriminant (E);
11581 while Present (Comp) loop
11582 if not OK_Component (Comp) then
11584 Reason_Bad_Component (Comp);
11588 Next_Component_Or_Discriminant (Comp);
11592 -- Deal with address clause case
11594 if Is_Object (E) then
11595 Addr := Address_Clause (E);
11597 if Present (Addr) then
11599 Error_Msg_Sloc := Sloc (Addr);
11600 Error_Msg_N ("\because of Address clause#", N);
11605 -- Deal with independent components for array type
11607 if IC and then Is_Array_Type (E) then
11608 Check_Array_Type (E);
11611 -- Deal with independent components for array object
11613 if IC and then Is_Object (E) and then Is_Array_Type (Etype (E)) then
11614 Check_Array_Type (Etype (E));
11619 end Validate_Independence;
11621 ------------------------------
11622 -- Validate_Iterable_Aspect --
11623 ------------------------------
11625 procedure Validate_Iterable_Aspect (Typ : Entity_Id; ASN : Node_Id) is
11630 Cursor : constant Entity_Id := Get_Cursor_Type (ASN, Typ);
11632 First_Id : Entity_Id;
11633 Next_Id : Entity_Id;
11634 Has_Element_Id : Entity_Id;
11635 Element_Id : Entity_Id;
11638 -- If previous error aspect is unusable
11640 if Cursor = Any_Type then
11646 Has_Element_Id := Empty;
11647 Element_Id := Empty;
11649 -- Each expression must resolve to a function with the proper signature
11651 Assoc := First (Component_Associations (Expression (ASN)));
11652 while Present (Assoc) loop
11653 Expr := Expression (Assoc);
11656 Prim := First (Choices (Assoc));
11658 if Nkind (Prim) /= N_Identifier
11659 or else Present (Next (Prim))
11661 Error_Msg_N ("illegal name in association", Prim);
11663 elsif Chars (Prim) = Name_First then
11664 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_First);
11665 First_Id := Entity (Expr);
11667 elsif Chars (Prim) = Name_Next then
11668 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Next);
11669 Next_Id := Entity (Expr);
11671 elsif Chars (Prim) = Name_Has_Element then
11672 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Has_Element);
11673 Has_Element_Id := Entity (Expr);
11675 elsif Chars (Prim) = Name_Element then
11676 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Element);
11677 Element_Id := Entity (Expr);
11680 Error_Msg_N ("invalid name for iterable function", Prim);
11686 if No (First_Id) then
11687 Error_Msg_N ("match for First primitive not found", ASN);
11689 elsif No (Next_Id) then
11690 Error_Msg_N ("match for Next primitive not found", ASN);
11692 elsif No (Has_Element_Id) then
11693 Error_Msg_N ("match for Has_Element primitive not found", ASN);
11695 elsif No (Element_Id) then
11698 end Validate_Iterable_Aspect;
11700 -----------------------------------
11701 -- Validate_Unchecked_Conversion --
11702 -----------------------------------
11704 procedure Validate_Unchecked_Conversion
11706 Act_Unit : Entity_Id)
11708 Source : Entity_Id;
11709 Target : Entity_Id;
11713 -- Obtain source and target types. Note that we call Ancestor_Subtype
11714 -- here because the processing for generic instantiation always makes
11715 -- subtypes, and we want the original frozen actual types.
11717 -- If we are dealing with private types, then do the check on their
11718 -- fully declared counterparts if the full declarations have been
11719 -- encountered (they don't have to be visible, but they must exist).
11721 Source := Ancestor_Subtype (Etype (First_Formal (Act_Unit)));
11723 if Is_Private_Type (Source)
11724 and then Present (Underlying_Type (Source))
11726 Source := Underlying_Type (Source);
11729 Target := Ancestor_Subtype (Etype (Act_Unit));
11731 -- If either type is generic, the instantiation happens within a generic
11732 -- unit, and there is nothing to check. The proper check will happen
11733 -- when the enclosing generic is instantiated.
11735 if Is_Generic_Type (Source) or else Is_Generic_Type (Target) then
11739 if Is_Private_Type (Target)
11740 and then Present (Underlying_Type (Target))
11742 Target := Underlying_Type (Target);
11745 -- Source may be unconstrained array, but not target
11747 if Is_Array_Type (Target) and then not Is_Constrained (Target) then
11749 ("unchecked conversion to unconstrained array not allowed", N);
11753 -- Warn if conversion between two different convention pointers
11755 if Is_Access_Type (Target)
11756 and then Is_Access_Type (Source)
11757 and then Convention (Target) /= Convention (Source)
11758 and then Warn_On_Unchecked_Conversion
11760 -- Give warnings for subprogram pointers only on most targets. The
11761 -- exception is VMS, where data pointers can have different lengths
11762 -- depending on the pointer convention.
11764 if Is_Access_Subprogram_Type (Target)
11765 or else Is_Access_Subprogram_Type (Source)
11766 or else OpenVMS_On_Target
11769 ("?z?conversion between pointers with different conventions!",
11774 -- Warn if one of the operands is Ada.Calendar.Time. Do not emit a
11775 -- warning when compiling GNAT-related sources.
11777 if Warn_On_Unchecked_Conversion
11778 and then not In_Predefined_Unit (N)
11779 and then RTU_Loaded (Ada_Calendar)
11781 (Chars (Source) = Name_Time
11783 Chars (Target) = Name_Time)
11785 -- If Ada.Calendar is loaded and the name of one of the operands is
11786 -- Time, there is a good chance that this is Ada.Calendar.Time.
11789 Calendar_Time : constant Entity_Id :=
11790 Full_View (RTE (RO_CA_Time));
11792 pragma Assert (Present (Calendar_Time));
11794 if Source = Calendar_Time or else Target = Calendar_Time then
11796 ("?z?representation of 'Time values may change between " &
11797 "'G'N'A'T versions", N);
11802 -- Make entry in unchecked conversion table for later processing by
11803 -- Validate_Unchecked_Conversions, which will check sizes and alignments
11804 -- (using values set by the back-end where possible). This is only done
11805 -- if the appropriate warning is active.
11807 if Warn_On_Unchecked_Conversion then
11808 Unchecked_Conversions.Append
11809 (New_Val => UC_Entry'(Eloc => Sloc (N),
11812 Act_Unit => Act_Unit));
11814 -- If both sizes are known statically now, then back end annotation
11815 -- is not required to do a proper check but if either size is not
11816 -- known statically, then we need the annotation.
11818 if Known_Static_RM_Size (Source)
11820 Known_Static_RM_Size (Target)
11824 Back_Annotate_Rep_Info := True;
11828 -- If unchecked conversion to access type, and access type is declared
11829 -- in the same unit as the unchecked conversion, then set the flag
11830 -- No_Strict_Aliasing (no strict aliasing is implicit here)
11832 if Is_Access_Type (Target) and then
11833 In_Same_Source_Unit (Target, N)
11835 Set_No_Strict_Aliasing (Implementation_Base_Type (Target));
11838 -- Generate N_Validate_Unchecked_Conversion node for back end in case
11839 -- the back end needs to perform special validation checks.
11841 -- Shouldn't this be in Exp_Ch13, since the check only gets done if we
11842 -- have full expansion and the back end is called ???
11845 Make_Validate_Unchecked_Conversion (Sloc (N));
11846 Set_Source_Type (Vnode, Source);
11847 Set_Target_Type (Vnode, Target);
11849 -- If the unchecked conversion node is in a list, just insert before it.
11850 -- If not we have some strange case, not worth bothering about.
11852 if Is_List_Member (N) then
11853 Insert_After (N, Vnode);
11855 end Validate_Unchecked_Conversion;
11857 ------------------------------------
11858 -- Validate_Unchecked_Conversions --
11859 ------------------------------------
11861 procedure Validate_Unchecked_Conversions is
11863 for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop
11865 T : UC_Entry renames Unchecked_Conversions.Table (N);
11867 Eloc : constant Source_Ptr := T.Eloc;
11868 Source : constant Entity_Id := T.Source;
11869 Target : constant Entity_Id := T.Target;
11870 Act_Unit : constant Entity_Id := T.Act_Unit;
11876 -- Skip if function marked as warnings off
11878 if Warnings_Off (Act_Unit) then
11882 -- This validation check, which warns if we have unequal sizes for
11883 -- unchecked conversion, and thus potentially implementation
11884 -- dependent semantics, is one of the few occasions on which we
11885 -- use the official RM size instead of Esize. See description in
11886 -- Einfo "Handling of Type'Size Values" for details.
11888 if Serious_Errors_Detected = 0
11889 and then Known_Static_RM_Size (Source)
11890 and then Known_Static_RM_Size (Target)
11892 -- Don't do the check if warnings off for either type, note the
11893 -- deliberate use of OR here instead of OR ELSE to get the flag
11894 -- Warnings_Off_Used set for both types if appropriate.
11896 and then not (Has_Warnings_Off (Source)
11898 Has_Warnings_Off (Target))
11900 Source_Siz := RM_Size (Source);
11901 Target_Siz := RM_Size (Target);
11903 if Source_Siz /= Target_Siz then
11905 ("?z?types for unchecked conversion have different sizes!",
11908 if All_Errors_Mode then
11909 Error_Msg_Name_1 := Chars (Source);
11910 Error_Msg_Uint_1 := Source_Siz;
11911 Error_Msg_Name_2 := Chars (Target);
11912 Error_Msg_Uint_2 := Target_Siz;
11913 Error_Msg ("\size of % is ^, size of % is ^?z?", Eloc);
11915 Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz);
11917 if Is_Discrete_Type (Source)
11919 Is_Discrete_Type (Target)
11921 if Source_Siz > Target_Siz then
11923 ("\?z?^ high order bits of source will "
11924 & "be ignored!", Eloc);
11926 elsif Is_Unsigned_Type (Source) then
11928 ("\?z?source will be extended with ^ high order "
11929 & "zero bits!", Eloc);
11933 ("\?z?source will be extended with ^ high order "
11934 & "sign bits!", Eloc);
11937 elsif Source_Siz < Target_Siz then
11938 if Is_Discrete_Type (Target) then
11939 if Bytes_Big_Endian then
11941 ("\?z?target value will include ^ undefined "
11942 & "low order bits!", Eloc);
11945 ("\?z?target value will include ^ undefined "
11946 & "high order bits!", Eloc);
11951 ("\?z?^ trailing bits of target value will be "
11952 & "undefined!", Eloc);
11955 else pragma Assert (Source_Siz > Target_Siz);
11957 ("\?z?^ trailing bits of source will be ignored!",
11964 -- If both types are access types, we need to check the alignment.
11965 -- If the alignment of both is specified, we can do it here.
11967 if Serious_Errors_Detected = 0
11968 and then Ekind (Source) in Access_Kind
11969 and then Ekind (Target) in Access_Kind
11970 and then Target_Strict_Alignment
11971 and then Present (Designated_Type (Source))
11972 and then Present (Designated_Type (Target))
11975 D_Source : constant Entity_Id := Designated_Type (Source);
11976 D_Target : constant Entity_Id := Designated_Type (Target);
11979 if Known_Alignment (D_Source)
11981 Known_Alignment (D_Target)
11984 Source_Align : constant Uint := Alignment (D_Source);
11985 Target_Align : constant Uint := Alignment (D_Target);
11988 if Source_Align < Target_Align
11989 and then not Is_Tagged_Type (D_Source)
11991 -- Suppress warning if warnings suppressed on either
11992 -- type or either designated type. Note the use of
11993 -- OR here instead of OR ELSE. That is intentional,
11994 -- we would like to set flag Warnings_Off_Used in
11995 -- all types for which warnings are suppressed.
11997 and then not (Has_Warnings_Off (D_Source)
11999 Has_Warnings_Off (D_Target)
12001 Has_Warnings_Off (Source)
12003 Has_Warnings_Off (Target))
12005 Error_Msg_Uint_1 := Target_Align;
12006 Error_Msg_Uint_2 := Source_Align;
12007 Error_Msg_Node_1 := D_Target;
12008 Error_Msg_Node_2 := D_Source;
12010 ("?z?alignment of & (^) is stricter than "
12011 & "alignment of & (^)!", Eloc);
12013 ("\?z?resulting access value may have invalid "
12014 & "alignment!", Eloc);
12025 end Validate_Unchecked_Conversions;