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 -- Verify that the prefix of the attribute and the local name
3136 -- for the type of the formal match.
3138 if Base_Type (Typ) /= Base_Type (Ent)
3139 or else Present ((Next_Formal (F)))
3143 elsif not Is_Scalar_Type (Typ)
3144 and then not Is_First_Subtype (Typ)
3145 and then not Is_Class_Wide_Type (Typ)
3152 end Has_Good_Profile;
3154 -- Start of processing for Analyze_Stream_TSS_Definition
3159 if not Is_Type (U_Ent) then
3160 Error_Msg_N ("local name must be a subtype", Nam);
3163 elsif not Is_First_Subtype (U_Ent) then
3164 Error_Msg_N ("local name must be a first subtype", Nam);
3168 Pnam := TSS (Base_Type (U_Ent), TSS_Nam);
3170 -- If Pnam is present, it can be either inherited from an ancestor
3171 -- type (in which case it is legal to redefine it for this type), or
3172 -- be a previous definition of the attribute for the same type (in
3173 -- which case it is illegal).
3175 -- In the first case, it will have been analyzed already, and we
3176 -- can check that its profile does not match the expected profile
3177 -- for a stream attribute of U_Ent. In the second case, either Pnam
3178 -- has been analyzed (and has the expected profile), or it has not
3179 -- been analyzed yet (case of a type that has not been frozen yet
3180 -- and for which the stream attribute has been set using Set_TSS).
3183 and then (No (First_Entity (Pnam)) or else Has_Good_Profile (Pnam))
3185 Error_Msg_Sloc := Sloc (Pnam);
3186 Error_Msg_Name_1 := Attr;
3187 Error_Msg_N ("% attribute already defined #", Nam);
3193 if Is_Entity_Name (Expr) then
3194 if not Is_Overloaded (Expr) then
3195 if Has_Good_Profile (Entity (Expr)) then
3196 Subp := Entity (Expr);
3200 Get_First_Interp (Expr, I, It);
3201 while Present (It.Nam) loop
3202 if Has_Good_Profile (It.Nam) then
3207 Get_Next_Interp (I, It);
3212 if Present (Subp) then
3213 if Is_Abstract_Subprogram (Subp) then
3214 Error_Msg_N ("stream subprogram must not be abstract", Expr);
3218 Set_Entity (Expr, Subp);
3219 Set_Etype (Expr, Etype (Subp));
3221 New_Stream_Subprogram (N, U_Ent, Subp, TSS_Nam);
3224 Error_Msg_Name_1 := Attr;
3225 Error_Msg_N ("incorrect expression for% attribute", Expr);
3227 end Analyze_Stream_TSS_Definition;
3229 ------------------------------
3230 -- Check_Indexing_Functions --
3231 ------------------------------
3233 procedure Check_Indexing_Functions is
3234 Indexing_Found : Boolean;
3236 procedure Check_One_Function (Subp : Entity_Id);
3237 -- Check one possible interpretation. Sets Indexing_Found True if an
3238 -- indexing function is found.
3240 ------------------------
3241 -- Check_One_Function --
3242 ------------------------
3244 procedure Check_One_Function (Subp : Entity_Id) is
3245 Default_Element : constant Node_Id :=
3246 Find_Value_Of_Aspect
3247 (Etype (First_Formal (Subp)),
3248 Aspect_Iterator_Element);
3251 if not Check_Primitive_Function (Subp)
3252 and then not Is_Overloaded (Expr)
3255 ("aspect Indexing requires a function that applies to type&",
3259 -- An indexing function must return either the default element of
3260 -- the container, or a reference type. For variable indexing it
3261 -- must be the latter.
3263 if Present (Default_Element) then
3264 Analyze (Default_Element);
3266 if Is_Entity_Name (Default_Element)
3267 and then Covers (Entity (Default_Element), Etype (Subp))
3269 Indexing_Found := True;
3274 -- For variable_indexing the return type must be a reference type
3276 if Attr = Name_Variable_Indexing
3277 and then not Has_Implicit_Dereference (Etype (Subp))
3280 ("function for indexing must return a reference type", Subp);
3283 Indexing_Found := True;
3285 end Check_One_Function;
3287 -- Start of processing for Check_Indexing_Functions
3296 if not Is_Overloaded (Expr) then
3297 Check_One_Function (Entity (Expr));
3305 Indexing_Found := False;
3306 Get_First_Interp (Expr, I, It);
3307 while Present (It.Nam) loop
3309 -- Note that analysis will have added the interpretation
3310 -- that corresponds to the dereference. We only check the
3311 -- subprogram itself.
3313 if Is_Overloadable (It.Nam) then
3314 Check_One_Function (It.Nam);
3317 Get_Next_Interp (I, It);
3320 if not Indexing_Found then
3322 ("aspect Indexing requires a function that "
3323 & "applies to type&", Expr, Ent);
3327 end Check_Indexing_Functions;
3329 ------------------------------
3330 -- Check_Iterator_Functions --
3331 ------------------------------
3333 procedure Check_Iterator_Functions is
3334 Default : Entity_Id;
3336 function Valid_Default_Iterator (Subp : Entity_Id) return Boolean;
3337 -- Check one possible interpretation for validity
3339 ----------------------------
3340 -- Valid_Default_Iterator --
3341 ----------------------------
3343 function Valid_Default_Iterator (Subp : Entity_Id) return Boolean is
3347 if not Check_Primitive_Function (Subp) then
3350 Formal := First_Formal (Subp);
3353 -- False if any subsequent formal has no default expression
3355 Formal := Next_Formal (Formal);
3356 while Present (Formal) loop
3357 if No (Expression (Parent (Formal))) then
3361 Next_Formal (Formal);
3364 -- True if all subsequent formals have default expressions
3367 end Valid_Default_Iterator;
3369 -- Start of processing for Check_Iterator_Functions
3374 if not Is_Entity_Name (Expr) then
3375 Error_Msg_N ("aspect Iterator must be a function name", Expr);
3378 if not Is_Overloaded (Expr) then
3379 if not Check_Primitive_Function (Entity (Expr)) then
3381 ("aspect Indexing requires a function that applies to type&",
3382 Entity (Expr), Ent);
3385 if not Valid_Default_Iterator (Entity (Expr)) then
3386 Error_Msg_N ("improper function for default iterator", Expr);
3396 Get_First_Interp (Expr, I, It);
3397 while Present (It.Nam) loop
3398 if not Check_Primitive_Function (It.Nam)
3399 or else not Valid_Default_Iterator (It.Nam)
3403 elsif Present (Default) then
3404 Error_Msg_N ("default iterator must be unique", Expr);
3410 Get_Next_Interp (I, It);
3414 if Present (Default) then
3415 Set_Entity (Expr, Default);
3416 Set_Is_Overloaded (Expr, False);
3419 end Check_Iterator_Functions;
3421 -------------------------------
3422 -- Check_Primitive_Function --
3423 -------------------------------
3425 function Check_Primitive_Function (Subp : Entity_Id) return Boolean is
3429 if Ekind (Subp) /= E_Function then
3433 if No (First_Formal (Subp)) then
3436 Ctrl := Etype (First_Formal (Subp));
3440 or else Ctrl = Class_Wide_Type (Ent)
3442 (Ekind (Ctrl) = E_Anonymous_Access_Type
3444 (Designated_Type (Ctrl) = Ent
3445 or else Designated_Type (Ctrl) = Class_Wide_Type (Ent)))
3454 end Check_Primitive_Function;
3456 ----------------------
3457 -- Duplicate_Clause --
3458 ----------------------
3460 function Duplicate_Clause return Boolean is
3464 -- Nothing to do if this attribute definition clause comes from
3465 -- an aspect specification, since we could not be duplicating an
3466 -- explicit clause, and we dealt with the case of duplicated aspects
3467 -- in Analyze_Aspect_Specifications.
3469 if From_Aspect_Specification (N) then
3473 -- Otherwise current clause may duplicate previous clause, or a
3474 -- previously given pragma or aspect specification for the same
3477 A := Get_Rep_Item (U_Ent, Chars (N), Check_Parents => False);
3480 Error_Msg_Name_1 := Chars (N);
3481 Error_Msg_Sloc := Sloc (A);
3483 Error_Msg_NE ("aspect% for & previously given#", N, U_Ent);
3488 end Duplicate_Clause;
3490 -- Start of processing for Analyze_Attribute_Definition_Clause
3493 -- The following code is a defense against recursion. Not clear that
3494 -- this can happen legitimately, but perhaps some error situations
3495 -- can cause it, and we did see this recursion during testing.
3497 if Analyzed (N) then
3500 Set_Analyzed (N, True);
3503 -- Ignore some selected attributes in CodePeer mode since they are not
3504 -- relevant in this context.
3506 if CodePeer_Mode then
3509 -- Ignore Component_Size in CodePeer mode, to avoid changing the
3510 -- internal representation of types by implicitly packing them.
3512 when Attribute_Component_Size =>
3513 Rewrite (N, Make_Null_Statement (Sloc (N)));
3521 -- Process Ignore_Rep_Clauses option
3523 if Ignore_Rep_Clauses then
3526 -- The following should be ignored. They do not affect legality
3527 -- and may be target dependent. The basic idea of -gnatI is to
3528 -- ignore any rep clauses that may be target dependent but do not
3529 -- affect legality (except possibly to be rejected because they
3530 -- are incompatible with the compilation target).
3532 when Attribute_Alignment |
3533 Attribute_Bit_Order |
3534 Attribute_Component_Size |
3535 Attribute_Machine_Radix |
3536 Attribute_Object_Size |
3538 Attribute_Stream_Size |
3539 Attribute_Value_Size =>
3540 Rewrite (N, Make_Null_Statement (Sloc (N)));
3543 -- Perhaps 'Small should not be ignored by Ignore_Rep_Clauses ???
3545 when Attribute_Small =>
3546 if Ignore_Rep_Clauses then
3547 Rewrite (N, Make_Null_Statement (Sloc (N)));
3551 -- The following should not be ignored, because in the first place
3552 -- they are reasonably portable, and should not cause problems in
3553 -- compiling code from another target, and also they do affect
3554 -- legality, e.g. failing to provide a stream attribute for a
3555 -- type may make a program illegal.
3557 when Attribute_External_Tag |
3561 Attribute_Simple_Storage_Pool |
3562 Attribute_Storage_Pool |
3563 Attribute_Storage_Size |
3567 -- Other cases are errors ("attribute& cannot be set with
3568 -- definition clause"), which will be caught below.
3576 Ent := Entity (Nam);
3578 if Rep_Item_Too_Early (Ent, N) then
3582 -- Rep clause applies to full view of incomplete type or private type if
3583 -- we have one (if not, this is a premature use of the type). However,
3584 -- certain semantic checks need to be done on the specified entity (i.e.
3585 -- the private view), so we save it in Ent.
3587 if Is_Private_Type (Ent)
3588 and then Is_Derived_Type (Ent)
3589 and then not Is_Tagged_Type (Ent)
3590 and then No (Full_View (Ent))
3592 -- If this is a private type whose completion is a derivation from
3593 -- another private type, there is no full view, and the attribute
3594 -- belongs to the type itself, not its underlying parent.
3598 elsif Ekind (Ent) = E_Incomplete_Type then
3600 -- The attribute applies to the full view, set the entity of the
3601 -- attribute definition accordingly.
3603 Ent := Underlying_Type (Ent);
3605 Set_Entity (Nam, Ent);
3608 U_Ent := Underlying_Type (Ent);
3611 -- Avoid cascaded error
3613 if Etype (Nam) = Any_Type then
3616 -- Must be declared in current scope or in case of an aspect
3617 -- specification, must be visible in current scope.
3619 elsif Scope (Ent) /= Current_Scope
3621 not (From_Aspect_Specification (N)
3622 and then Scope_Within_Or_Same (Current_Scope, Scope (Ent)))
3624 Error_Msg_N ("entity must be declared in this scope", Nam);
3627 -- Must not be a source renaming (we do have some cases where the
3628 -- expander generates a renaming, and those cases are OK, in such
3629 -- cases any attribute applies to the renamed object as well).
3631 elsif Is_Object (Ent)
3632 and then Present (Renamed_Object (Ent))
3634 -- Case of renamed object from source, this is an error
3636 if Comes_From_Source (Renamed_Object (Ent)) then
3637 Get_Name_String (Chars (N));
3638 Error_Msg_Strlen := Name_Len;
3639 Error_Msg_String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len);
3641 ("~ clause not allowed for a renaming declaration "
3642 & "(RM 13.1(6))", Nam);
3645 -- For the case of a compiler generated renaming, the attribute
3646 -- definition clause applies to the renamed object created by the
3647 -- expander. The easiest general way to handle this is to create a
3648 -- copy of the attribute definition clause for this object.
3650 elsif Is_Entity_Name (Renamed_Object (Ent)) then
3652 Make_Attribute_Definition_Clause (Loc,
3654 New_Occurrence_Of (Entity (Renamed_Object (Ent)), Loc),
3656 Expression => Duplicate_Subexpr (Expression (N))));
3658 -- If the renamed object is not an entity, it must be a dereference
3659 -- of an unconstrained function call, and we must introduce a new
3660 -- declaration to capture the expression. This is needed in the case
3661 -- of 'Alignment, where the original declaration must be rewritten.
3665 (Nkind (Renamed_Object (Ent)) = N_Explicit_Dereference);
3669 -- If no underlying entity, use entity itself, applies to some
3670 -- previously detected error cases ???
3672 elsif No (U_Ent) then
3675 -- Cannot specify for a subtype (exception Object/Value_Size)
3677 elsif Is_Type (U_Ent)
3678 and then not Is_First_Subtype (U_Ent)
3679 and then Id /= Attribute_Object_Size
3680 and then Id /= Attribute_Value_Size
3681 and then not From_At_Mod (N)
3683 Error_Msg_N ("cannot specify attribute for subtype", Nam);
3687 Set_Entity (N, U_Ent);
3688 Check_Restriction_No_Use_Of_Attribute (N);
3690 -- Switch on particular attribute
3698 -- Address attribute definition clause
3700 when Attribute_Address => Address : begin
3702 -- A little error check, catch for X'Address use X'Address;
3704 if Nkind (Nam) = N_Identifier
3705 and then Nkind (Expr) = N_Attribute_Reference
3706 and then Attribute_Name (Expr) = Name_Address
3707 and then Nkind (Prefix (Expr)) = N_Identifier
3708 and then Chars (Nam) = Chars (Prefix (Expr))
3711 ("address for & is self-referencing", Prefix (Expr), Ent);
3715 -- Not that special case, carry on with analysis of expression
3717 Analyze_And_Resolve (Expr, RTE (RE_Address));
3719 -- Even when ignoring rep clauses we need to indicate that the
3720 -- entity has an address clause and thus it is legal to declare
3723 if Ignore_Rep_Clauses then
3724 if Ekind_In (U_Ent, E_Variable, E_Constant) then
3725 Record_Rep_Item (U_Ent, N);
3731 if Duplicate_Clause then
3734 -- Case of address clause for subprogram
3736 elsif Is_Subprogram (U_Ent) then
3737 if Has_Homonym (U_Ent) then
3739 ("address clause cannot be given " &
3740 "for overloaded subprogram",
3745 -- For subprograms, all address clauses are permitted, and we
3746 -- mark the subprogram as having a deferred freeze so that Gigi
3747 -- will not elaborate it too soon.
3749 -- Above needs more comments, what is too soon about???
3751 Set_Has_Delayed_Freeze (U_Ent);
3753 -- Case of address clause for entry
3755 elsif Ekind (U_Ent) = E_Entry then
3756 if Nkind (Parent (N)) = N_Task_Body then
3758 ("entry address must be specified in task spec", Nam);
3762 -- For entries, we require a constant address
3764 Check_Constant_Address_Clause (Expr, U_Ent);
3766 -- Special checks for task types
3768 if Is_Task_Type (Scope (U_Ent))
3769 and then Comes_From_Source (Scope (U_Ent))
3772 ("??entry address declared for entry in task type", N);
3774 ("\??only one task can be declared of this type", N);
3777 -- Entry address clauses are obsolescent
3779 Check_Restriction (No_Obsolescent_Features, N);
3781 if Warn_On_Obsolescent_Feature then
3783 ("?j?attaching interrupt to task entry is an " &
3784 "obsolescent feature (RM J.7.1)", N);
3786 ("\?j?use interrupt procedure instead", N);
3789 -- Case of an address clause for a controlled object which we
3790 -- consider to be erroneous.
3792 elsif Is_Controlled (Etype (U_Ent))
3793 or else Has_Controlled_Component (Etype (U_Ent))
3796 ("??controlled object& must not be overlaid", Nam, U_Ent);
3798 ("\??Program_Error will be raised at run time", Nam);
3799 Insert_Action (Declaration_Node (U_Ent),
3800 Make_Raise_Program_Error (Loc,
3801 Reason => PE_Overlaid_Controlled_Object));
3804 -- Case of address clause for a (non-controlled) object
3807 Ekind (U_Ent) = E_Variable
3809 Ekind (U_Ent) = E_Constant
3812 Expr : constant Node_Id := Expression (N);
3817 -- Exported variables cannot have an address clause, because
3818 -- this cancels the effect of the pragma Export.
3820 if Is_Exported (U_Ent) then
3822 ("cannot export object with address clause", Nam);
3826 Find_Overlaid_Entity (N, O_Ent, Off);
3828 -- Overlaying controlled objects is erroneous
3831 and then (Has_Controlled_Component (Etype (O_Ent))
3832 or else Is_Controlled (Etype (O_Ent)))
3835 ("??cannot overlay with controlled object", Expr);
3837 ("\??Program_Error will be raised at run time", Expr);
3838 Insert_Action (Declaration_Node (U_Ent),
3839 Make_Raise_Program_Error (Loc,
3840 Reason => PE_Overlaid_Controlled_Object));
3843 elsif Present (O_Ent)
3844 and then Ekind (U_Ent) = E_Constant
3845 and then not Is_Constant_Object (O_Ent)
3847 Error_Msg_N ("??constant overlays a variable", Expr);
3849 -- Imported variables can have an address clause, but then
3850 -- the import is pretty meaningless except to suppress
3851 -- initializations, so we do not need such variables to
3852 -- be statically allocated (and in fact it causes trouble
3853 -- if the address clause is a local value).
3855 elsif Is_Imported (U_Ent) then
3856 Set_Is_Statically_Allocated (U_Ent, False);
3859 -- We mark a possible modification of a variable with an
3860 -- address clause, since it is likely aliasing is occurring.
3862 Note_Possible_Modification (Nam, Sure => False);
3864 -- Here we are checking for explicit overlap of one variable
3865 -- by another, and if we find this then mark the overlapped
3866 -- variable as also being volatile to prevent unwanted
3867 -- optimizations. This is a significant pessimization so
3868 -- avoid it when there is an offset, i.e. when the object
3869 -- is composite; they cannot be optimized easily anyway.
3872 and then Is_Object (O_Ent)
3875 -- The following test is an expedient solution to what
3876 -- is really a problem in CodePeer. Suppressing the
3877 -- Set_Treat_As_Volatile call here prevents later
3878 -- generation (in some cases) of trees that CodePeer
3879 -- should, but currently does not, handle correctly.
3880 -- This test should probably be removed when CodePeer
3881 -- is improved, just because we want the tree CodePeer
3882 -- analyzes to match the tree for which we generate code
3883 -- as closely as is practical. ???
3885 and then not CodePeer_Mode
3887 -- ??? O_Ent might not be in current unit
3889 Set_Treat_As_Volatile (O_Ent);
3892 -- Legality checks on the address clause for initialized
3893 -- objects is deferred until the freeze point, because
3894 -- a subsequent pragma might indicate that the object
3895 -- is imported and thus not initialized. Also, the address
3896 -- clause might involve entities that have yet to be
3899 Set_Has_Delayed_Freeze (U_Ent);
3901 -- If an initialization call has been generated for this
3902 -- object, it needs to be deferred to after the freeze node
3903 -- we have just now added, otherwise GIGI will see a
3904 -- reference to the variable (as actual to the IP call)
3905 -- before its definition.
3908 Init_Call : constant Node_Id :=
3909 Remove_Init_Call (U_Ent, N);
3912 if Present (Init_Call) then
3913 Append_Freeze_Action (U_Ent, Init_Call);
3915 -- Reset Initialization_Statements pointer so that
3916 -- if there is a pragma Import further down, it can
3917 -- clear any default initialization.
3919 Set_Initialization_Statements (U_Ent, Init_Call);
3923 if Is_Exported (U_Ent) then
3925 ("& cannot be exported if an address clause is given",
3928 ("\define and export a variable "
3929 & "that holds its address instead", Nam);
3932 -- Entity has delayed freeze, so we will generate an
3933 -- alignment check at the freeze point unless suppressed.
3935 if not Range_Checks_Suppressed (U_Ent)
3936 and then not Alignment_Checks_Suppressed (U_Ent)
3938 Set_Check_Address_Alignment (N);
3941 -- Kill the size check code, since we are not allocating
3942 -- the variable, it is somewhere else.
3944 Kill_Size_Check_Code (U_Ent);
3946 -- If the address clause is of the form:
3948 -- for Y'Address use X'Address
3952 -- Const : constant Address := X'Address;
3954 -- for Y'Address use Const;
3956 -- then we make an entry in the table for checking the size
3957 -- and alignment of the overlaying variable. We defer this
3958 -- check till after code generation to take full advantage
3959 -- of the annotation done by the back end.
3961 -- If the entity has a generic type, the check will be
3962 -- performed in the instance if the actual type justifies
3963 -- it, and we do not insert the clause in the table to
3964 -- prevent spurious warnings.
3966 -- Note: we used to test Comes_From_Source and only give
3967 -- this warning for source entities, but we have removed
3968 -- this test. It really seems bogus to generate overlays
3969 -- that would trigger this warning in generated code.
3970 -- Furthermore, by removing the test, we handle the
3971 -- aspect case properly.
3973 if Address_Clause_Overlay_Warnings
3974 and then Present (O_Ent)
3975 and then Is_Object (O_Ent)
3977 if not Is_Generic_Type (Etype (U_Ent)) then
3978 Address_Clause_Checks.Append ((N, U_Ent, O_Ent, Off));
3981 -- If variable overlays a constant view, and we are
3982 -- warning on overlays, then mark the variable as
3983 -- overlaying a constant (we will give warnings later
3984 -- if this variable is assigned).
3986 if Is_Constant_Object (O_Ent)
3987 and then Ekind (U_Ent) = E_Variable
3989 Set_Overlays_Constant (U_Ent);
3994 -- Not a valid entity for an address clause
3997 Error_Msg_N ("address cannot be given for &", Nam);
4005 -- Alignment attribute definition clause
4007 when Attribute_Alignment => Alignment : declare
4008 Align : constant Uint := Get_Alignment_Value (Expr);
4009 Max_Align : constant Uint := UI_From_Int (Maximum_Alignment);
4014 if not Is_Type (U_Ent)
4015 and then Ekind (U_Ent) /= E_Variable
4016 and then Ekind (U_Ent) /= E_Constant
4018 Error_Msg_N ("alignment cannot be given for &", Nam);
4020 elsif Duplicate_Clause then
4023 elsif Align /= No_Uint then
4024 Set_Has_Alignment_Clause (U_Ent);
4026 -- Tagged type case, check for attempt to set alignment to a
4027 -- value greater than Max_Align, and reset if so.
4029 if Is_Tagged_Type (U_Ent) and then Align > Max_Align then
4031 ("alignment for & set to Maximum_Aligment??", Nam);
4032 Set_Alignment (U_Ent, Max_Align);
4037 Set_Alignment (U_Ent, Align);
4040 -- For an array type, U_Ent is the first subtype. In that case,
4041 -- also set the alignment of the anonymous base type so that
4042 -- other subtypes (such as the itypes for aggregates of the
4043 -- type) also receive the expected alignment.
4045 if Is_Array_Type (U_Ent) then
4046 Set_Alignment (Base_Type (U_Ent), Align);
4055 -- Bit_Order attribute definition clause
4057 when Attribute_Bit_Order => Bit_Order : declare
4059 if not Is_Record_Type (U_Ent) then
4061 ("Bit_Order can only be defined for record type", Nam);
4063 elsif Duplicate_Clause then
4067 Analyze_And_Resolve (Expr, RTE (RE_Bit_Order));
4069 if Etype (Expr) = Any_Type then
4072 elsif not Is_Static_Expression (Expr) then
4073 Flag_Non_Static_Expr
4074 ("Bit_Order requires static expression!", Expr);
4077 if (Expr_Value (Expr) = 0) /= Bytes_Big_Endian then
4078 Set_Reverse_Bit_Order (U_Ent, True);
4084 --------------------
4085 -- Component_Size --
4086 --------------------
4088 -- Component_Size attribute definition clause
4090 when Attribute_Component_Size => Component_Size_Case : declare
4091 Csize : constant Uint := Static_Integer (Expr);
4095 New_Ctyp : Entity_Id;
4099 if not Is_Array_Type (U_Ent) then
4100 Error_Msg_N ("component size requires array type", Nam);
4104 Btype := Base_Type (U_Ent);
4105 Ctyp := Component_Type (Btype);
4107 if Duplicate_Clause then
4110 elsif Rep_Item_Too_Early (Btype, N) then
4113 elsif Csize /= No_Uint then
4114 Check_Size (Expr, Ctyp, Csize, Biased);
4116 -- For the biased case, build a declaration for a subtype that
4117 -- will be used to represent the biased subtype that reflects
4118 -- the biased representation of components. We need the subtype
4119 -- to get proper conversions on referencing elements of the
4120 -- array. Note: component size clauses are ignored in VM mode.
4122 if VM_Target = No_VM then
4125 Make_Defining_Identifier (Loc,
4127 New_External_Name (Chars (U_Ent), 'C', 0, 'T'));
4130 Make_Subtype_Declaration (Loc,
4131 Defining_Identifier => New_Ctyp,
4132 Subtype_Indication =>
4133 New_Occurrence_Of (Component_Type (Btype), Loc));
4135 Set_Parent (Decl, N);
4136 Analyze (Decl, Suppress => All_Checks);
4138 Set_Has_Delayed_Freeze (New_Ctyp, False);
4139 Set_Esize (New_Ctyp, Csize);
4140 Set_RM_Size (New_Ctyp, Csize);
4141 Init_Alignment (New_Ctyp);
4142 Set_Is_Itype (New_Ctyp, True);
4143 Set_Associated_Node_For_Itype (New_Ctyp, U_Ent);
4145 Set_Component_Type (Btype, New_Ctyp);
4146 Set_Biased (New_Ctyp, N, "component size clause");
4149 Set_Component_Size (Btype, Csize);
4151 -- For VM case, we ignore component size clauses
4154 -- Give a warning unless we are in GNAT mode, in which case
4155 -- the warning is suppressed since it is not useful.
4157 if not GNAT_Mode then
4159 ("component size ignored in this configuration??", N);
4163 -- Deal with warning on overridden size
4165 if Warn_On_Overridden_Size
4166 and then Has_Size_Clause (Ctyp)
4167 and then RM_Size (Ctyp) /= Csize
4170 ("component size overrides size clause for&?S?", N, Ctyp);
4173 Set_Has_Component_Size_Clause (Btype, True);
4174 Set_Has_Non_Standard_Rep (Btype, True);
4176 end Component_Size_Case;
4178 -----------------------
4179 -- Constant_Indexing --
4180 -----------------------
4182 when Attribute_Constant_Indexing =>
4183 Check_Indexing_Functions;
4189 when Attribute_CPU => CPU :
4191 -- CPU attribute definition clause not allowed except from aspect
4194 if From_Aspect_Specification (N) then
4195 if not Is_Task_Type (U_Ent) then
4196 Error_Msg_N ("CPU can only be defined for task", Nam);
4198 elsif Duplicate_Clause then
4202 -- The expression must be analyzed in the special manner
4203 -- described in "Handling of Default and Per-Object
4204 -- Expressions" in sem.ads.
4206 -- The visibility to the discriminants must be restored
4208 Push_Scope_And_Install_Discriminants (U_Ent);
4209 Preanalyze_Spec_Expression (Expr, RTE (RE_CPU_Range));
4210 Uninstall_Discriminants_And_Pop_Scope (U_Ent);
4212 if not Is_Static_Expression (Expr) then
4213 Check_Restriction (Static_Priorities, Expr);
4219 ("attribute& cannot be set with definition clause", N);
4223 ----------------------
4224 -- Default_Iterator --
4225 ----------------------
4227 when Attribute_Default_Iterator => Default_Iterator : declare
4231 if not Is_Tagged_Type (U_Ent) then
4233 ("aspect Default_Iterator applies to tagged type", Nam);
4236 Check_Iterator_Functions;
4240 if not Is_Entity_Name (Expr)
4241 or else Ekind (Entity (Expr)) /= E_Function
4243 Error_Msg_N ("aspect Iterator must be a function", Expr);
4245 Func := Entity (Expr);
4248 if No (First_Formal (Func))
4249 or else Etype (First_Formal (Func)) /= U_Ent
4252 ("Default Iterator must be a primitive of&", Func, U_Ent);
4254 end Default_Iterator;
4256 ------------------------
4257 -- Dispatching_Domain --
4258 ------------------------
4260 when Attribute_Dispatching_Domain => Dispatching_Domain :
4262 -- Dispatching_Domain attribute definition clause not allowed
4263 -- except from aspect specification.
4265 if From_Aspect_Specification (N) then
4266 if not Is_Task_Type (U_Ent) then
4267 Error_Msg_N ("Dispatching_Domain can only be defined" &
4271 elsif Duplicate_Clause then
4275 -- The expression must be analyzed in the special manner
4276 -- described in "Handling of Default and Per-Object
4277 -- Expressions" in sem.ads.
4279 -- The visibility to the discriminants must be restored
4281 Push_Scope_And_Install_Discriminants (U_Ent);
4283 Preanalyze_Spec_Expression
4284 (Expr, RTE (RE_Dispatching_Domain));
4286 Uninstall_Discriminants_And_Pop_Scope (U_Ent);
4291 ("attribute& cannot be set with definition clause", N);
4293 end Dispatching_Domain;
4299 when Attribute_External_Tag => External_Tag :
4301 if not Is_Tagged_Type (U_Ent) then
4302 Error_Msg_N ("should be a tagged type", Nam);
4305 if Duplicate_Clause then
4309 Analyze_And_Resolve (Expr, Standard_String);
4311 if not Is_Static_Expression (Expr) then
4312 Flag_Non_Static_Expr
4313 ("static string required for tag name!", Nam);
4316 if VM_Target = No_VM then
4317 Set_Has_External_Tag_Rep_Clause (U_Ent);
4319 Error_Msg_Name_1 := Attr;
4321 ("% attribute unsupported in this configuration", Nam);
4324 if not Is_Library_Level_Entity (U_Ent) then
4326 ("??non-unique external tag supplied for &", N, U_Ent);
4328 ("\??same external tag applies to all "
4329 & "subprogram calls", N);
4331 ("\??corresponding internal tag cannot be obtained", N);
4336 --------------------------
4337 -- Implicit_Dereference --
4338 --------------------------
4340 when Attribute_Implicit_Dereference =>
4342 -- Legality checks already performed at the point of the type
4343 -- declaration, aspect is not delayed.
4351 when Attribute_Input =>
4352 Analyze_Stream_TSS_Definition (TSS_Stream_Input);
4353 Set_Has_Specified_Stream_Input (Ent);
4355 ------------------------
4356 -- Interrupt_Priority --
4357 ------------------------
4359 when Attribute_Interrupt_Priority => Interrupt_Priority :
4361 -- Interrupt_Priority attribute definition clause not allowed
4362 -- except from aspect specification.
4364 if From_Aspect_Specification (N) then
4365 if not (Is_Protected_Type (U_Ent)
4366 or else Is_Task_Type (U_Ent))
4369 ("Interrupt_Priority can only be defined for task" &
4370 "and protected object",
4373 elsif Duplicate_Clause then
4377 -- The expression must be analyzed in the special manner
4378 -- described in "Handling of Default and Per-Object
4379 -- Expressions" in sem.ads.
4381 -- The visibility to the discriminants must be restored
4383 Push_Scope_And_Install_Discriminants (U_Ent);
4385 Preanalyze_Spec_Expression
4386 (Expr, RTE (RE_Interrupt_Priority));
4388 Uninstall_Discriminants_And_Pop_Scope (U_Ent);
4393 ("attribute& cannot be set with definition clause", N);
4395 end Interrupt_Priority;
4401 when Attribute_Iterable =>
4404 if Nkind (Expr) /= N_Aggregate then
4405 Error_Msg_N ("aspect Iterable must be an aggregate", Expr);
4412 Assoc := First (Component_Associations (Expr));
4413 while Present (Assoc) loop
4414 if not Is_Entity_Name (Expression (Assoc)) then
4415 Error_Msg_N ("value must be a function", Assoc);
4422 ----------------------
4423 -- Iterator_Element --
4424 ----------------------
4426 when Attribute_Iterator_Element =>
4429 if not Is_Entity_Name (Expr)
4430 or else not Is_Type (Entity (Expr))
4432 Error_Msg_N ("aspect Iterator_Element must be a type", Expr);
4439 -- Machine radix attribute definition clause
4441 when Attribute_Machine_Radix => Machine_Radix : declare
4442 Radix : constant Uint := Static_Integer (Expr);
4445 if not Is_Decimal_Fixed_Point_Type (U_Ent) then
4446 Error_Msg_N ("decimal fixed-point type expected for &", Nam);
4448 elsif Duplicate_Clause then
4451 elsif Radix /= No_Uint then
4452 Set_Has_Machine_Radix_Clause (U_Ent);
4453 Set_Has_Non_Standard_Rep (Base_Type (U_Ent));
4457 elsif Radix = 10 then
4458 Set_Machine_Radix_10 (U_Ent);
4460 Error_Msg_N ("machine radix value must be 2 or 10", Expr);
4469 -- Object_Size attribute definition clause
4471 when Attribute_Object_Size => Object_Size : declare
4472 Size : constant Uint := Static_Integer (Expr);
4475 pragma Warnings (Off, Biased);
4478 if not Is_Type (U_Ent) then
4479 Error_Msg_N ("Object_Size cannot be given for &", Nam);
4481 elsif Duplicate_Clause then
4485 Check_Size (Expr, U_Ent, Size, Biased);
4487 if Is_Scalar_Type (U_Ent) then
4488 if Size /= 8 and then Size /= 16 and then Size /= 32
4489 and then UI_Mod (Size, 64) /= 0
4492 ("Object_Size must be 8, 16, 32, or multiple of 64",
4496 elsif Size mod 8 /= 0 then
4497 Error_Msg_N ("Object_Size must be a multiple of 8", Expr);
4500 Set_Esize (U_Ent, Size);
4501 Set_Has_Object_Size_Clause (U_Ent);
4502 Alignment_Check_For_Size_Change (U_Ent, Size);
4510 when Attribute_Output =>
4511 Analyze_Stream_TSS_Definition (TSS_Stream_Output);
4512 Set_Has_Specified_Stream_Output (Ent);
4518 when Attribute_Priority => Priority :
4520 -- Priority attribute definition clause not allowed except from
4521 -- aspect specification.
4523 if From_Aspect_Specification (N) then
4524 if not (Is_Protected_Type (U_Ent)
4525 or else Is_Task_Type (U_Ent)
4526 or else Ekind (U_Ent) = E_Procedure)
4529 ("Priority can only be defined for task and protected " &
4533 elsif Duplicate_Clause then
4537 -- The expression must be analyzed in the special manner
4538 -- described in "Handling of Default and Per-Object
4539 -- Expressions" in sem.ads.
4541 -- The visibility to the discriminants must be restored
4543 Push_Scope_And_Install_Discriminants (U_Ent);
4544 Preanalyze_Spec_Expression (Expr, Standard_Integer);
4545 Uninstall_Discriminants_And_Pop_Scope (U_Ent);
4547 if not Is_Static_Expression (Expr) then
4548 Check_Restriction (Static_Priorities, Expr);
4554 ("attribute& cannot be set with definition clause", N);
4562 when Attribute_Read =>
4563 Analyze_Stream_TSS_Definition (TSS_Stream_Read);
4564 Set_Has_Specified_Stream_Read (Ent);
4566 --------------------------
4567 -- Scalar_Storage_Order --
4568 --------------------------
4570 -- Scalar_Storage_Order attribute definition clause
4572 when Attribute_Scalar_Storage_Order => Scalar_Storage_Order : declare
4574 if not (Is_Record_Type (U_Ent) or else Is_Array_Type (U_Ent)) then
4576 ("Scalar_Storage_Order can only be defined for "
4577 & "record or array type", Nam);
4579 elsif Duplicate_Clause then
4583 Analyze_And_Resolve (Expr, RTE (RE_Bit_Order));
4585 if Etype (Expr) = Any_Type then
4588 elsif not Is_Static_Expression (Expr) then
4589 Flag_Non_Static_Expr
4590 ("Scalar_Storage_Order requires static expression!", Expr);
4592 elsif (Expr_Value (Expr) = 0) /= Bytes_Big_Endian then
4594 -- Here for the case of a non-default (i.e. non-confirming)
4595 -- Scalar_Storage_Order attribute definition.
4597 if Support_Nondefault_SSO_On_Target then
4598 Set_Reverse_Storage_Order (Base_Type (U_Ent), True);
4601 ("non-default Scalar_Storage_Order "
4602 & "not supported on target", Expr);
4606 end Scalar_Storage_Order;
4612 -- Size attribute definition clause
4614 when Attribute_Size => Size : declare
4615 Size : constant Uint := Static_Integer (Expr);
4622 if Duplicate_Clause then
4625 elsif not Is_Type (U_Ent)
4626 and then Ekind (U_Ent) /= E_Variable
4627 and then Ekind (U_Ent) /= E_Constant
4629 Error_Msg_N ("size cannot be given for &", Nam);
4631 elsif Is_Array_Type (U_Ent)
4632 and then not Is_Constrained (U_Ent)
4635 ("size cannot be given for unconstrained array", Nam);
4637 elsif Size /= No_Uint then
4638 if VM_Target /= No_VM and then not GNAT_Mode then
4640 -- Size clause is not handled properly on VM targets.
4641 -- Display a warning unless we are in GNAT mode, in which
4642 -- case this is useless.
4645 ("size clauses are ignored in this configuration??", N);
4648 if Is_Type (U_Ent) then
4651 Etyp := Etype (U_Ent);
4654 -- Check size, note that Gigi is in charge of checking that the
4655 -- size of an array or record type is OK. Also we do not check
4656 -- the size in the ordinary fixed-point case, since it is too
4657 -- early to do so (there may be subsequent small clause that
4658 -- affects the size). We can check the size if a small clause
4659 -- has already been given.
4661 if not Is_Ordinary_Fixed_Point_Type (U_Ent)
4662 or else Has_Small_Clause (U_Ent)
4664 Check_Size (Expr, Etyp, Size, Biased);
4665 Set_Biased (U_Ent, N, "size clause", Biased);
4668 -- For types set RM_Size and Esize if possible
4670 if Is_Type (U_Ent) then
4671 Set_RM_Size (U_Ent, Size);
4673 -- For elementary types, increase Object_Size to power of 2,
4674 -- but not less than a storage unit in any case (normally
4675 -- this means it will be byte addressable).
4677 -- For all other types, nothing else to do, we leave Esize
4678 -- (object size) unset, the back end will set it from the
4679 -- size and alignment in an appropriate manner.
4681 -- In both cases, we check whether the alignment must be
4682 -- reset in the wake of the size change.
4684 if Is_Elementary_Type (U_Ent) then
4685 if Size <= System_Storage_Unit then
4686 Init_Esize (U_Ent, System_Storage_Unit);
4687 elsif Size <= 16 then
4688 Init_Esize (U_Ent, 16);
4689 elsif Size <= 32 then
4690 Init_Esize (U_Ent, 32);
4692 Set_Esize (U_Ent, (Size + 63) / 64 * 64);
4695 Alignment_Check_For_Size_Change (U_Ent, Esize (U_Ent));
4697 Alignment_Check_For_Size_Change (U_Ent, Size);
4700 -- For objects, set Esize only
4703 if Is_Elementary_Type (Etyp) then
4704 if Size /= System_Storage_Unit
4706 Size /= System_Storage_Unit * 2
4708 Size /= System_Storage_Unit * 4
4710 Size /= System_Storage_Unit * 8
4712 Error_Msg_Uint_1 := UI_From_Int (System_Storage_Unit);
4713 Error_Msg_Uint_2 := Error_Msg_Uint_1 * 8;
4715 ("size for primitive object must be a power of 2"
4716 & " in the range ^-^", N);
4720 Set_Esize (U_Ent, Size);
4723 Set_Has_Size_Clause (U_Ent);
4731 -- Small attribute definition clause
4733 when Attribute_Small => Small : declare
4734 Implicit_Base : constant Entity_Id := Base_Type (U_Ent);
4738 Analyze_And_Resolve (Expr, Any_Real);
4740 if Etype (Expr) = Any_Type then
4743 elsif not Is_Static_Expression (Expr) then
4744 Flag_Non_Static_Expr
4745 ("small requires static expression!", Expr);
4749 Small := Expr_Value_R (Expr);
4751 if Small <= Ureal_0 then
4752 Error_Msg_N ("small value must be greater than zero", Expr);
4758 if not Is_Ordinary_Fixed_Point_Type (U_Ent) then
4760 ("small requires an ordinary fixed point type", Nam);
4762 elsif Has_Small_Clause (U_Ent) then
4763 Error_Msg_N ("small already given for &", Nam);
4765 elsif Small > Delta_Value (U_Ent) then
4767 ("small value must not be greater than delta value", Nam);
4770 Set_Small_Value (U_Ent, Small);
4771 Set_Small_Value (Implicit_Base, Small);
4772 Set_Has_Small_Clause (U_Ent);
4773 Set_Has_Small_Clause (Implicit_Base);
4774 Set_Has_Non_Standard_Rep (Implicit_Base);
4782 -- Storage_Pool attribute definition clause
4784 when Attribute_Storage_Pool | Attribute_Simple_Storage_Pool => declare
4789 if Ekind (U_Ent) = E_Access_Subprogram_Type then
4791 ("storage pool cannot be given for access-to-subprogram type",
4796 Ekind_In (U_Ent, E_Access_Type, E_General_Access_Type)
4799 ("storage pool can only be given for access types", Nam);
4802 elsif Is_Derived_Type (U_Ent) then
4804 ("storage pool cannot be given for a derived access type",
4807 elsif Duplicate_Clause then
4810 elsif Present (Associated_Storage_Pool (U_Ent)) then
4811 Error_Msg_N ("storage pool already given for &", Nam);
4815 -- Check for Storage_Size previously given
4818 SS : constant Node_Id :=
4819 Get_Attribute_Definition_Clause
4820 (U_Ent, Attribute_Storage_Size);
4822 if Present (SS) then
4823 Check_Pool_Size_Clash (U_Ent, N, SS);
4827 -- Storage_Pool case
4829 if Id = Attribute_Storage_Pool then
4831 (Expr, Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
4833 -- In the Simple_Storage_Pool case, we allow a variable of any
4834 -- simple storage pool type, so we Resolve without imposing an
4838 Analyze_And_Resolve (Expr);
4840 if not Present (Get_Rep_Pragma
4841 (Etype (Expr), Name_Simple_Storage_Pool_Type))
4844 ("expression must be of a simple storage pool type", Expr);
4848 if not Denotes_Variable (Expr) then
4849 Error_Msg_N ("storage pool must be a variable", Expr);
4853 if Nkind (Expr) = N_Type_Conversion then
4854 T := Etype (Expression (Expr));
4859 -- The Stack_Bounded_Pool is used internally for implementing
4860 -- access types with a Storage_Size. Since it only work properly
4861 -- when used on one specific type, we need to check that it is not
4862 -- hijacked improperly:
4864 -- type T is access Integer;
4865 -- for T'Storage_Size use n;
4866 -- type Q is access Float;
4867 -- for Q'Storage_Size use T'Storage_Size; -- incorrect
4869 if RTE_Available (RE_Stack_Bounded_Pool)
4870 and then Base_Type (T) = RTE (RE_Stack_Bounded_Pool)
4872 Error_Msg_N ("non-shareable internal Pool", Expr);
4876 -- If the argument is a name that is not an entity name, then
4877 -- we construct a renaming operation to define an entity of
4878 -- type storage pool.
4880 if not Is_Entity_Name (Expr)
4881 and then Is_Object_Reference (Expr)
4883 Pool := Make_Temporary (Loc, 'P', Expr);
4886 Rnode : constant Node_Id :=
4887 Make_Object_Renaming_Declaration (Loc,
4888 Defining_Identifier => Pool,
4890 New_Occurrence_Of (Etype (Expr), Loc),
4894 -- If the attribute definition clause comes from an aspect
4895 -- clause, then insert the renaming before the associated
4896 -- entity's declaration, since the attribute clause has
4897 -- not yet been appended to the declaration list.
4899 if From_Aspect_Specification (N) then
4900 Insert_Before (Parent (Entity (N)), Rnode);
4902 Insert_Before (N, Rnode);
4906 Set_Associated_Storage_Pool (U_Ent, Pool);
4909 elsif Is_Entity_Name (Expr) then
4910 Pool := Entity (Expr);
4912 -- If pool is a renamed object, get original one. This can
4913 -- happen with an explicit renaming, and within instances.
4915 while Present (Renamed_Object (Pool))
4916 and then Is_Entity_Name (Renamed_Object (Pool))
4918 Pool := Entity (Renamed_Object (Pool));
4921 if Present (Renamed_Object (Pool))
4922 and then Nkind (Renamed_Object (Pool)) = N_Type_Conversion
4923 and then Is_Entity_Name (Expression (Renamed_Object (Pool)))
4925 Pool := Entity (Expression (Renamed_Object (Pool)));
4928 Set_Associated_Storage_Pool (U_Ent, Pool);
4930 elsif Nkind (Expr) = N_Type_Conversion
4931 and then Is_Entity_Name (Expression (Expr))
4932 and then Nkind (Original_Node (Expr)) = N_Attribute_Reference
4934 Pool := Entity (Expression (Expr));
4935 Set_Associated_Storage_Pool (U_Ent, Pool);
4938 Error_Msg_N ("incorrect reference to a Storage Pool", Expr);
4947 -- Storage_Size attribute definition clause
4949 when Attribute_Storage_Size => Storage_Size : declare
4950 Btype : constant Entity_Id := Base_Type (U_Ent);
4953 if Is_Task_Type (U_Ent) then
4955 -- Check obsolescent (but never obsolescent if from aspect)
4957 if not From_Aspect_Specification (N) then
4958 Check_Restriction (No_Obsolescent_Features, N);
4960 if Warn_On_Obsolescent_Feature then
4962 ("?j?storage size clause for task is an " &
4963 "obsolescent feature (RM J.9)", N);
4964 Error_Msg_N ("\?j?use Storage_Size pragma instead", N);
4971 if not Is_Access_Type (U_Ent)
4972 and then Ekind (U_Ent) /= E_Task_Type
4974 Error_Msg_N ("storage size cannot be given for &", Nam);
4976 elsif Is_Access_Type (U_Ent) and Is_Derived_Type (U_Ent) then
4978 ("storage size cannot be given for a derived access type",
4981 elsif Duplicate_Clause then
4985 Analyze_And_Resolve (Expr, Any_Integer);
4987 if Is_Access_Type (U_Ent) then
4989 -- Check for Storage_Pool previously given
4992 SP : constant Node_Id :=
4993 Get_Attribute_Definition_Clause
4994 (U_Ent, Attribute_Storage_Pool);
4997 if Present (SP) then
4998 Check_Pool_Size_Clash (U_Ent, SP, N);
5002 -- Special case of for x'Storage_Size use 0
5004 if Is_OK_Static_Expression (Expr)
5005 and then Expr_Value (Expr) = 0
5007 Set_No_Pool_Assigned (Btype);
5011 Set_Has_Storage_Size_Clause (Btype);
5019 when Attribute_Stream_Size => Stream_Size : declare
5020 Size : constant Uint := Static_Integer (Expr);
5023 if Ada_Version <= Ada_95 then
5024 Check_Restriction (No_Implementation_Attributes, N);
5027 if Duplicate_Clause then
5030 elsif Is_Elementary_Type (U_Ent) then
5031 if Size /= System_Storage_Unit
5033 Size /= System_Storage_Unit * 2
5035 Size /= System_Storage_Unit * 4
5037 Size /= System_Storage_Unit * 8
5039 Error_Msg_Uint_1 := UI_From_Int (System_Storage_Unit);
5041 ("stream size for elementary type must be a"
5042 & " power of 2 and at least ^", N);
5044 elsif RM_Size (U_Ent) > Size then
5045 Error_Msg_Uint_1 := RM_Size (U_Ent);
5047 ("stream size for elementary type must be a"
5048 & " power of 2 and at least ^", N);
5051 Set_Has_Stream_Size_Clause (U_Ent);
5054 Error_Msg_N ("Stream_Size cannot be given for &", Nam);
5062 -- Value_Size attribute definition clause
5064 when Attribute_Value_Size => Value_Size : declare
5065 Size : constant Uint := Static_Integer (Expr);
5069 if not Is_Type (U_Ent) then
5070 Error_Msg_N ("Value_Size cannot be given for &", Nam);
5072 elsif Duplicate_Clause then
5075 elsif Is_Array_Type (U_Ent)
5076 and then not Is_Constrained (U_Ent)
5079 ("Value_Size cannot be given for unconstrained array", Nam);
5082 if Is_Elementary_Type (U_Ent) then
5083 Check_Size (Expr, U_Ent, Size, Biased);
5084 Set_Biased (U_Ent, N, "value size clause", Biased);
5087 Set_RM_Size (U_Ent, Size);
5091 -----------------------
5092 -- Variable_Indexing --
5093 -----------------------
5095 when Attribute_Variable_Indexing =>
5096 Check_Indexing_Functions;
5102 when Attribute_Write =>
5103 Analyze_Stream_TSS_Definition (TSS_Stream_Write);
5104 Set_Has_Specified_Stream_Write (Ent);
5106 -- All other attributes cannot be set
5110 ("attribute& cannot be set with definition clause", N);
5113 -- The test for the type being frozen must be performed after any
5114 -- expression the clause has been analyzed since the expression itself
5115 -- might cause freezing that makes the clause illegal.
5117 if Rep_Item_Too_Late (U_Ent, N, FOnly) then
5120 end Analyze_Attribute_Definition_Clause;
5122 ----------------------------
5123 -- Analyze_Code_Statement --
5124 ----------------------------
5126 procedure Analyze_Code_Statement (N : Node_Id) is
5127 HSS : constant Node_Id := Parent (N);
5128 SBody : constant Node_Id := Parent (HSS);
5129 Subp : constant Entity_Id := Current_Scope;
5136 -- Analyze and check we get right type, note that this implements the
5137 -- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that
5138 -- is the only way that Asm_Insn could possibly be visible.
5140 Analyze_And_Resolve (Expression (N));
5142 if Etype (Expression (N)) = Any_Type then
5144 elsif Etype (Expression (N)) /= RTE (RE_Asm_Insn) then
5145 Error_Msg_N ("incorrect type for code statement", N);
5149 Check_Code_Statement (N);
5151 -- Make sure we appear in the handled statement sequence of a
5152 -- subprogram (RM 13.8(3)).
5154 if Nkind (HSS) /= N_Handled_Sequence_Of_Statements
5155 or else Nkind (SBody) /= N_Subprogram_Body
5158 ("code statement can only appear in body of subprogram", N);
5162 -- Do remaining checks (RM 13.8(3)) if not already done
5164 if not Is_Machine_Code_Subprogram (Subp) then
5165 Set_Is_Machine_Code_Subprogram (Subp);
5167 -- No exception handlers allowed
5169 if Present (Exception_Handlers (HSS)) then
5171 ("exception handlers not permitted in machine code subprogram",
5172 First (Exception_Handlers (HSS)));
5175 -- No declarations other than use clauses and pragmas (we allow
5176 -- certain internally generated declarations as well).
5178 Decl := First (Declarations (SBody));
5179 while Present (Decl) loop
5180 DeclO := Original_Node (Decl);
5181 if Comes_From_Source (DeclO)
5182 and not Nkind_In (DeclO, N_Pragma,
5183 N_Use_Package_Clause,
5185 N_Implicit_Label_Declaration)
5188 ("this declaration not allowed in machine code subprogram",
5195 -- No statements other than code statements, pragmas, and labels.
5196 -- Again we allow certain internally generated statements.
5198 -- In Ada 2012, qualified expressions are names, and the code
5199 -- statement is initially parsed as a procedure call.
5201 Stmt := First (Statements (HSS));
5202 while Present (Stmt) loop
5203 StmtO := Original_Node (Stmt);
5205 -- A procedure call transformed into a code statement is OK.
5207 if Ada_Version >= Ada_2012
5208 and then Nkind (StmtO) = N_Procedure_Call_Statement
5209 and then Nkind (Name (StmtO)) = N_Qualified_Expression
5213 elsif Comes_From_Source (StmtO)
5214 and then not Nkind_In (StmtO, N_Pragma,
5219 ("this statement is not allowed in machine code subprogram",
5226 end Analyze_Code_Statement;
5228 -----------------------------------------------
5229 -- Analyze_Enumeration_Representation_Clause --
5230 -----------------------------------------------
5232 procedure Analyze_Enumeration_Representation_Clause (N : Node_Id) is
5233 Ident : constant Node_Id := Identifier (N);
5234 Aggr : constant Node_Id := Array_Aggregate (N);
5235 Enumtype : Entity_Id;
5242 Err : Boolean := False;
5243 -- Set True to avoid cascade errors and crashes on incorrect source code
5245 Lo : constant Uint := Expr_Value (Type_Low_Bound (Universal_Integer));
5246 Hi : constant Uint := Expr_Value (Type_High_Bound (Universal_Integer));
5247 -- Allowed range of universal integer (= allowed range of enum lit vals)
5251 -- Minimum and maximum values of entries
5254 -- Pointer to node for literal providing max value
5257 if Ignore_Rep_Clauses then
5261 -- Ignore enumeration rep clauses by default in CodePeer mode,
5262 -- unless -gnatd.I is specified, as a work around for potential false
5263 -- positive messages.
5265 if CodePeer_Mode and not Debug_Flag_Dot_II then
5269 -- First some basic error checks
5272 Enumtype := Entity (Ident);
5274 if Enumtype = Any_Type
5275 or else Rep_Item_Too_Early (Enumtype, N)
5279 Enumtype := Underlying_Type (Enumtype);
5282 if not Is_Enumeration_Type (Enumtype) then
5284 ("enumeration type required, found}",
5285 Ident, First_Subtype (Enumtype));
5289 -- Ignore rep clause on generic actual type. This will already have
5290 -- been flagged on the template as an error, and this is the safest
5291 -- way to ensure we don't get a junk cascaded message in the instance.
5293 if Is_Generic_Actual_Type (Enumtype) then
5296 -- Type must be in current scope
5298 elsif Scope (Enumtype) /= Current_Scope then
5299 Error_Msg_N ("type must be declared in this scope", Ident);
5302 -- Type must be a first subtype
5304 elsif not Is_First_Subtype (Enumtype) then
5305 Error_Msg_N ("cannot give enumeration rep clause for subtype", N);
5308 -- Ignore duplicate rep clause
5310 elsif Has_Enumeration_Rep_Clause (Enumtype) then
5311 Error_Msg_N ("duplicate enumeration rep clause ignored", N);
5314 -- Don't allow rep clause for standard [wide_[wide_]]character
5316 elsif Is_Standard_Character_Type (Enumtype) then
5317 Error_Msg_N ("enumeration rep clause not allowed for this type", N);
5320 -- Check that the expression is a proper aggregate (no parentheses)
5322 elsif Paren_Count (Aggr) /= 0 then
5324 ("extra parentheses surrounding aggregate not allowed",
5328 -- All tests passed, so set rep clause in place
5331 Set_Has_Enumeration_Rep_Clause (Enumtype);
5332 Set_Has_Enumeration_Rep_Clause (Base_Type (Enumtype));
5335 -- Now we process the aggregate. Note that we don't use the normal
5336 -- aggregate code for this purpose, because we don't want any of the
5337 -- normal expansion activities, and a number of special semantic
5338 -- rules apply (including the component type being any integer type)
5340 Elit := First_Literal (Enumtype);
5342 -- First the positional entries if any
5344 if Present (Expressions (Aggr)) then
5345 Expr := First (Expressions (Aggr));
5346 while Present (Expr) loop
5348 Error_Msg_N ("too many entries in aggregate", Expr);
5352 Val := Static_Integer (Expr);
5354 -- Err signals that we found some incorrect entries processing
5355 -- the list. The final checks for completeness and ordering are
5356 -- skipped in this case.
5358 if Val = No_Uint then
5360 elsif Val < Lo or else Hi < Val then
5361 Error_Msg_N ("value outside permitted range", Expr);
5365 Set_Enumeration_Rep (Elit, Val);
5366 Set_Enumeration_Rep_Expr (Elit, Expr);
5372 -- Now process the named entries if present
5374 if Present (Component_Associations (Aggr)) then
5375 Assoc := First (Component_Associations (Aggr));
5376 while Present (Assoc) loop
5377 Choice := First (Choices (Assoc));
5379 if Present (Next (Choice)) then
5381 ("multiple choice not allowed here", Next (Choice));
5385 if Nkind (Choice) = N_Others_Choice then
5386 Error_Msg_N ("others choice not allowed here", Choice);
5389 elsif Nkind (Choice) = N_Range then
5391 -- ??? should allow zero/one element range here
5393 Error_Msg_N ("range not allowed here", Choice);
5397 Analyze_And_Resolve (Choice, Enumtype);
5399 if Error_Posted (Choice) then
5404 if Is_Entity_Name (Choice)
5405 and then Is_Type (Entity (Choice))
5407 Error_Msg_N ("subtype name not allowed here", Choice);
5410 -- ??? should allow static subtype with zero/one entry
5412 elsif Etype (Choice) = Base_Type (Enumtype) then
5413 if not Is_Static_Expression (Choice) then
5414 Flag_Non_Static_Expr
5415 ("non-static expression used for choice!", Choice);
5419 Elit := Expr_Value_E (Choice);
5421 if Present (Enumeration_Rep_Expr (Elit)) then
5423 Sloc (Enumeration_Rep_Expr (Elit));
5425 ("representation for& previously given#",
5430 Set_Enumeration_Rep_Expr (Elit, Expression (Assoc));
5432 Expr := Expression (Assoc);
5433 Val := Static_Integer (Expr);
5435 if Val = No_Uint then
5438 elsif Val < Lo or else Hi < Val then
5439 Error_Msg_N ("value outside permitted range", Expr);
5443 Set_Enumeration_Rep (Elit, Val);
5453 -- Aggregate is fully processed. Now we check that a full set of
5454 -- representations was given, and that they are in range and in order.
5455 -- These checks are only done if no other errors occurred.
5461 Elit := First_Literal (Enumtype);
5462 while Present (Elit) loop
5463 if No (Enumeration_Rep_Expr (Elit)) then
5464 Error_Msg_NE ("missing representation for&!", N, Elit);
5467 Val := Enumeration_Rep (Elit);
5469 if Min = No_Uint then
5473 if Val /= No_Uint then
5474 if Max /= No_Uint and then Val <= Max then
5476 ("enumeration value for& not ordered!",
5477 Enumeration_Rep_Expr (Elit), Elit);
5480 Max_Node := Enumeration_Rep_Expr (Elit);
5484 -- If there is at least one literal whose representation is not
5485 -- equal to the Pos value, then note that this enumeration type
5486 -- has a non-standard representation.
5488 if Val /= Enumeration_Pos (Elit) then
5489 Set_Has_Non_Standard_Rep (Base_Type (Enumtype));
5496 -- Now set proper size information
5499 Minsize : Uint := UI_From_Int (Minimum_Size (Enumtype));
5502 if Has_Size_Clause (Enumtype) then
5504 -- All OK, if size is OK now
5506 if RM_Size (Enumtype) >= Minsize then
5510 -- Try if we can get by with biasing
5513 UI_From_Int (Minimum_Size (Enumtype, Biased => True));
5515 -- Error message if even biasing does not work
5517 if RM_Size (Enumtype) < Minsize then
5518 Error_Msg_Uint_1 := RM_Size (Enumtype);
5519 Error_Msg_Uint_2 := Max;
5521 ("previously given size (^) is too small "
5522 & "for this value (^)", Max_Node);
5524 -- If biasing worked, indicate that we now have biased rep
5528 (Enumtype, Size_Clause (Enumtype), "size clause");
5533 Set_RM_Size (Enumtype, Minsize);
5534 Set_Enum_Esize (Enumtype);
5537 Set_RM_Size (Base_Type (Enumtype), RM_Size (Enumtype));
5538 Set_Esize (Base_Type (Enumtype), Esize (Enumtype));
5539 Set_Alignment (Base_Type (Enumtype), Alignment (Enumtype));
5543 -- We repeat the too late test in case it froze itself
5545 if Rep_Item_Too_Late (Enumtype, N) then
5548 end Analyze_Enumeration_Representation_Clause;
5550 ----------------------------
5551 -- Analyze_Free_Statement --
5552 ----------------------------
5554 procedure Analyze_Free_Statement (N : Node_Id) is
5556 Analyze (Expression (N));
5557 end Analyze_Free_Statement;
5559 ---------------------------
5560 -- Analyze_Freeze_Entity --
5561 ---------------------------
5563 procedure Analyze_Freeze_Entity (N : Node_Id) is
5565 Freeze_Entity_Checks (N);
5566 end Analyze_Freeze_Entity;
5568 -----------------------------------
5569 -- Analyze_Freeze_Generic_Entity --
5570 -----------------------------------
5572 procedure Analyze_Freeze_Generic_Entity (N : Node_Id) is
5574 Freeze_Entity_Checks (N);
5575 end Analyze_Freeze_Generic_Entity;
5577 ------------------------------------------
5578 -- Analyze_Record_Representation_Clause --
5579 ------------------------------------------
5581 -- Note: we check as much as we can here, but we can't do any checks
5582 -- based on the position values (e.g. overlap checks) until freeze time
5583 -- because especially in Ada 2005 (machine scalar mode), the processing
5584 -- for non-standard bit order can substantially change the positions.
5585 -- See procedure Check_Record_Representation_Clause (called from Freeze)
5586 -- for the remainder of this processing.
5588 procedure Analyze_Record_Representation_Clause (N : Node_Id) is
5589 Ident : constant Node_Id := Identifier (N);
5594 Hbit : Uint := Uint_0;
5598 Rectype : Entity_Id;
5601 function Is_Inherited (Comp : Entity_Id) return Boolean;
5602 -- True if Comp is an inherited component in a record extension
5608 function Is_Inherited (Comp : Entity_Id) return Boolean is
5609 Comp_Base : Entity_Id;
5612 if Ekind (Rectype) = E_Record_Subtype then
5613 Comp_Base := Original_Record_Component (Comp);
5618 return Comp_Base /= Original_Record_Component (Comp_Base);
5623 Is_Record_Extension : Boolean;
5624 -- True if Rectype is a record extension
5626 CR_Pragma : Node_Id := Empty;
5627 -- Points to N_Pragma node if Complete_Representation pragma present
5629 -- Start of processing for Analyze_Record_Representation_Clause
5632 if Ignore_Rep_Clauses then
5637 Rectype := Entity (Ident);
5639 if Rectype = Any_Type or else Rep_Item_Too_Early (Rectype, N) then
5642 Rectype := Underlying_Type (Rectype);
5645 -- First some basic error checks
5647 if not Is_Record_Type (Rectype) then
5649 ("record type required, found}", Ident, First_Subtype (Rectype));
5652 elsif Scope (Rectype) /= Current_Scope then
5653 Error_Msg_N ("type must be declared in this scope", N);
5656 elsif not Is_First_Subtype (Rectype) then
5657 Error_Msg_N ("cannot give record rep clause for subtype", N);
5660 elsif Has_Record_Rep_Clause (Rectype) then
5661 Error_Msg_N ("duplicate record rep clause ignored", N);
5664 elsif Rep_Item_Too_Late (Rectype, N) then
5668 -- We know we have a first subtype, now possibly go the the anonymous
5669 -- base type to determine whether Rectype is a record extension.
5671 Recdef := Type_Definition (Declaration_Node (Base_Type (Rectype)));
5672 Is_Record_Extension :=
5673 Nkind (Recdef) = N_Derived_Type_Definition
5674 and then Present (Record_Extension_Part (Recdef));
5676 if Present (Mod_Clause (N)) then
5678 Loc : constant Source_Ptr := Sloc (N);
5679 M : constant Node_Id := Mod_Clause (N);
5680 P : constant List_Id := Pragmas_Before (M);
5684 pragma Warnings (Off, Mod_Val);
5687 Check_Restriction (No_Obsolescent_Features, Mod_Clause (N));
5689 if Warn_On_Obsolescent_Feature then
5691 ("?j?mod clause is an obsolescent feature (RM J.8)", N);
5693 ("\?j?use alignment attribute definition clause instead", N);
5700 -- In ASIS_Mode mode, expansion is disabled, but we must convert
5701 -- the Mod clause into an alignment clause anyway, so that the
5702 -- back-end can compute and back-annotate properly the size and
5703 -- alignment of types that may include this record.
5705 -- This seems dubious, this destroys the source tree in a manner
5706 -- not detectable by ASIS ???
5708 if Operating_Mode = Check_Semantics and then ASIS_Mode then
5710 Make_Attribute_Definition_Clause (Loc,
5711 Name => New_Occurrence_Of (Base_Type (Rectype), Loc),
5712 Chars => Name_Alignment,
5713 Expression => Relocate_Node (Expression (M)));
5715 Set_From_At_Mod (AtM_Nod);
5716 Insert_After (N, AtM_Nod);
5717 Mod_Val := Get_Alignment_Value (Expression (AtM_Nod));
5718 Set_Mod_Clause (N, Empty);
5721 -- Get the alignment value to perform error checking
5723 Mod_Val := Get_Alignment_Value (Expression (M));
5728 -- For untagged types, clear any existing component clauses for the
5729 -- type. If the type is derived, this is what allows us to override
5730 -- a rep clause for the parent. For type extensions, the representation
5731 -- of the inherited components is inherited, so we want to keep previous
5732 -- component clauses for completeness.
5734 if not Is_Tagged_Type (Rectype) then
5735 Comp := First_Component_Or_Discriminant (Rectype);
5736 while Present (Comp) loop
5737 Set_Component_Clause (Comp, Empty);
5738 Next_Component_Or_Discriminant (Comp);
5742 -- All done if no component clauses
5744 CC := First (Component_Clauses (N));
5750 -- A representation like this applies to the base type
5752 Set_Has_Record_Rep_Clause (Base_Type (Rectype));
5753 Set_Has_Non_Standard_Rep (Base_Type (Rectype));
5754 Set_Has_Specified_Layout (Base_Type (Rectype));
5756 -- Process the component clauses
5758 while Present (CC) loop
5762 if Nkind (CC) = N_Pragma then
5765 -- The only pragma of interest is Complete_Representation
5767 if Pragma_Name (CC) = Name_Complete_Representation then
5771 -- Processing for real component clause
5774 Posit := Static_Integer (Position (CC));
5775 Fbit := Static_Integer (First_Bit (CC));
5776 Lbit := Static_Integer (Last_Bit (CC));
5779 and then Fbit /= No_Uint
5780 and then Lbit /= No_Uint
5784 ("position cannot be negative", Position (CC));
5788 ("first bit cannot be negative", First_Bit (CC));
5790 -- The Last_Bit specified in a component clause must not be
5791 -- less than the First_Bit minus one (RM-13.5.1(10)).
5793 elsif Lbit < Fbit - 1 then
5795 ("last bit cannot be less than first bit minus one",
5798 -- Values look OK, so find the corresponding record component
5799 -- Even though the syntax allows an attribute reference for
5800 -- implementation-defined components, GNAT does not allow the
5801 -- tag to get an explicit position.
5803 elsif Nkind (Component_Name (CC)) = N_Attribute_Reference then
5804 if Attribute_Name (Component_Name (CC)) = Name_Tag then
5805 Error_Msg_N ("position of tag cannot be specified", CC);
5807 Error_Msg_N ("illegal component name", CC);
5811 Comp := First_Entity (Rectype);
5812 while Present (Comp) loop
5813 exit when Chars (Comp) = Chars (Component_Name (CC));
5819 -- Maybe component of base type that is absent from
5820 -- statically constrained first subtype.
5822 Comp := First_Entity (Base_Type (Rectype));
5823 while Present (Comp) loop
5824 exit when Chars (Comp) = Chars (Component_Name (CC));
5831 ("component clause is for non-existent field", CC);
5833 -- Ada 2012 (AI05-0026): Any name that denotes a
5834 -- discriminant of an object of an unchecked union type
5835 -- shall not occur within a record_representation_clause.
5837 -- The general restriction of using record rep clauses on
5838 -- Unchecked_Union types has now been lifted. Since it is
5839 -- possible to introduce a record rep clause which mentions
5840 -- the discriminant of an Unchecked_Union in non-Ada 2012
5841 -- code, this check is applied to all versions of the
5844 elsif Ekind (Comp) = E_Discriminant
5845 and then Is_Unchecked_Union (Rectype)
5848 ("cannot reference discriminant of unchecked union",
5849 Component_Name (CC));
5851 elsif Is_Record_Extension and then Is_Inherited (Comp) then
5853 ("component clause not allowed for inherited "
5854 & "component&", CC, Comp);
5856 elsif Present (Component_Clause (Comp)) then
5858 -- Diagnose duplicate rep clause, or check consistency
5859 -- if this is an inherited component. In a double fault,
5860 -- there may be a duplicate inconsistent clause for an
5861 -- inherited component.
5863 if Scope (Original_Record_Component (Comp)) = Rectype
5864 or else Parent (Component_Clause (Comp)) = N
5866 Error_Msg_Sloc := Sloc (Component_Clause (Comp));
5867 Error_Msg_N ("component clause previously given#", CC);
5871 Rep1 : constant Node_Id := Component_Clause (Comp);
5873 if Intval (Position (Rep1)) /=
5874 Intval (Position (CC))
5875 or else Intval (First_Bit (Rep1)) /=
5876 Intval (First_Bit (CC))
5877 or else Intval (Last_Bit (Rep1)) /=
5878 Intval (Last_Bit (CC))
5881 ("component clause inconsistent "
5882 & "with representation of ancestor", CC);
5884 elsif Warn_On_Redundant_Constructs then
5886 ("?r?redundant confirming component clause "
5887 & "for component!", CC);
5892 -- Normal case where this is the first component clause we
5893 -- have seen for this entity, so set it up properly.
5896 -- Make reference for field in record rep clause and set
5897 -- appropriate entity field in the field identifier.
5900 (Comp, Component_Name (CC), Set_Ref => False);
5901 Set_Entity (Component_Name (CC), Comp);
5903 -- Update Fbit and Lbit to the actual bit number
5905 Fbit := Fbit + UI_From_Int (SSU) * Posit;
5906 Lbit := Lbit + UI_From_Int (SSU) * Posit;
5908 if Has_Size_Clause (Rectype)
5909 and then RM_Size (Rectype) <= Lbit
5912 ("bit number out of range of specified size",
5915 Set_Component_Clause (Comp, CC);
5916 Set_Component_Bit_Offset (Comp, Fbit);
5917 Set_Esize (Comp, 1 + (Lbit - Fbit));
5918 Set_Normalized_First_Bit (Comp, Fbit mod SSU);
5919 Set_Normalized_Position (Comp, Fbit / SSU);
5921 if Warn_On_Overridden_Size
5922 and then Has_Size_Clause (Etype (Comp))
5923 and then RM_Size (Etype (Comp)) /= Esize (Comp)
5926 ("?S?component size overrides size clause for&",
5927 Component_Name (CC), Etype (Comp));
5930 -- This information is also set in the corresponding
5931 -- component of the base type, found by accessing the
5932 -- Original_Record_Component link if it is present.
5934 Ocomp := Original_Record_Component (Comp);
5941 (Component_Name (CC),
5947 (Comp, First_Node (CC), "component clause", Biased);
5949 if Present (Ocomp) then
5950 Set_Component_Clause (Ocomp, CC);
5951 Set_Component_Bit_Offset (Ocomp, Fbit);
5952 Set_Normalized_First_Bit (Ocomp, Fbit mod SSU);
5953 Set_Normalized_Position (Ocomp, Fbit / SSU);
5954 Set_Esize (Ocomp, 1 + (Lbit - Fbit));
5956 Set_Normalized_Position_Max
5957 (Ocomp, Normalized_Position (Ocomp));
5959 -- Note: we don't use Set_Biased here, because we
5960 -- already gave a warning above if needed, and we
5961 -- would get a duplicate for the same name here.
5963 Set_Has_Biased_Representation
5964 (Ocomp, Has_Biased_Representation (Comp));
5967 if Esize (Comp) < 0 then
5968 Error_Msg_N ("component size is negative", CC);
5979 -- Check missing components if Complete_Representation pragma appeared
5981 if Present (CR_Pragma) then
5982 Comp := First_Component_Or_Discriminant (Rectype);
5983 while Present (Comp) loop
5984 if No (Component_Clause (Comp)) then
5986 ("missing component clause for &", CR_Pragma, Comp);
5989 Next_Component_Or_Discriminant (Comp);
5992 -- Give missing components warning if required
5994 elsif Warn_On_Unrepped_Components then
5996 Num_Repped_Components : Nat := 0;
5997 Num_Unrepped_Components : Nat := 0;
6000 -- First count number of repped and unrepped components
6002 Comp := First_Component_Or_Discriminant (Rectype);
6003 while Present (Comp) loop
6004 if Present (Component_Clause (Comp)) then
6005 Num_Repped_Components := Num_Repped_Components + 1;
6007 Num_Unrepped_Components := Num_Unrepped_Components + 1;
6010 Next_Component_Or_Discriminant (Comp);
6013 -- We are only interested in the case where there is at least one
6014 -- unrepped component, and at least half the components have rep
6015 -- clauses. We figure that if less than half have them, then the
6016 -- partial rep clause is really intentional. If the component
6017 -- type has no underlying type set at this point (as for a generic
6018 -- formal type), we don't know enough to give a warning on the
6021 if Num_Unrepped_Components > 0
6022 and then Num_Unrepped_Components < Num_Repped_Components
6024 Comp := First_Component_Or_Discriminant (Rectype);
6025 while Present (Comp) loop
6026 if No (Component_Clause (Comp))
6027 and then Comes_From_Source (Comp)
6028 and then Present (Underlying_Type (Etype (Comp)))
6029 and then (Is_Scalar_Type (Underlying_Type (Etype (Comp)))
6030 or else Size_Known_At_Compile_Time
6031 (Underlying_Type (Etype (Comp))))
6032 and then not Has_Warnings_Off (Rectype)
6034 Error_Msg_Sloc := Sloc (Comp);
6036 ("?C?no component clause given for & declared #",
6040 Next_Component_Or_Discriminant (Comp);
6045 end Analyze_Record_Representation_Clause;
6047 -------------------------------------------
6048 -- Build_Invariant_Procedure_Declaration --
6049 -------------------------------------------
6051 function Build_Invariant_Procedure_Declaration
6052 (Typ : Entity_Id) return Node_Id
6054 Loc : constant Source_Ptr := Sloc (Typ);
6055 Object_Entity : constant Entity_Id :=
6056 Make_Defining_Identifier (Loc, New_Internal_Name ('I'));
6061 Set_Etype (Object_Entity, Typ);
6063 -- Check for duplicate definiations.
6065 if Has_Invariants (Typ) and then Present (Invariant_Procedure (Typ)) then
6070 Make_Defining_Identifier (Loc,
6071 Chars => New_External_Name (Chars (Typ), "Invariant"));
6072 Set_Has_Invariants (Typ);
6073 Set_Ekind (SId, E_Procedure);
6074 Set_Is_Invariant_Procedure (SId);
6075 Set_Invariant_Procedure (Typ, SId);
6078 Make_Procedure_Specification (Loc,
6079 Defining_Unit_Name => SId,
6080 Parameter_Specifications => New_List (
6081 Make_Parameter_Specification (Loc,
6082 Defining_Identifier => Object_Entity,
6083 Parameter_Type => New_Occurrence_Of (Typ, Loc))));
6085 return Make_Subprogram_Declaration (Loc, Specification => Spec);
6086 end Build_Invariant_Procedure_Declaration;
6088 -------------------------------
6089 -- Build_Invariant_Procedure --
6090 -------------------------------
6092 -- The procedure that is constructed here has the form
6094 -- procedure typInvariant (Ixxx : typ) is
6096 -- pragma Check (Invariant, exp, "failed invariant from xxx");
6097 -- pragma Check (Invariant, exp, "failed invariant from xxx");
6099 -- pragma Check (Invariant, exp, "failed inherited invariant from xxx");
6101 -- end typInvariant;
6103 procedure Build_Invariant_Procedure (Typ : Entity_Id; N : Node_Id) is
6104 Loc : constant Source_Ptr := Sloc (Typ);
6111 Visible_Decls : constant List_Id := Visible_Declarations (N);
6112 Private_Decls : constant List_Id := Private_Declarations (N);
6114 procedure Add_Invariants (T : Entity_Id; Inherit : Boolean);
6115 -- Appends statements to Stmts for any invariants in the rep item chain
6116 -- of the given type. If Inherit is False, then we only process entries
6117 -- on the chain for the type Typ. If Inherit is True, then we ignore any
6118 -- Invariant aspects, but we process all Invariant'Class aspects, adding
6119 -- "inherited" to the exception message and generating an informational
6120 -- message about the inheritance of an invariant.
6122 Object_Name : Name_Id;
6123 -- Name for argument of invariant procedure
6125 Object_Entity : Node_Id;
6126 -- The entity of the formal for the procedure
6128 --------------------
6129 -- Add_Invariants --
6130 --------------------
6132 procedure Add_Invariants (T : Entity_Id; Inherit : Boolean) is
6142 procedure Replace_Type_Reference (N : Node_Id);
6143 -- Replace a single occurrence N of the subtype name with a reference
6144 -- to the formal of the predicate function. N can be an identifier
6145 -- referencing the subtype, or a selected component, representing an
6146 -- appropriately qualified occurrence of the subtype name.
6148 procedure Replace_Type_References is
6149 new Replace_Type_References_Generic (Replace_Type_Reference);
6150 -- Traverse an expression replacing all occurrences of the subtype
6151 -- name with appropriate references to the object that is the formal
6152 -- parameter of the predicate function. Note that we must ensure
6153 -- that the type and entity information is properly set in the
6154 -- replacement node, since we will do a Preanalyze call of this
6155 -- expression without proper visibility of the procedure argument.
6157 ----------------------------
6158 -- Replace_Type_Reference --
6159 ----------------------------
6161 -- Note: See comments in Add_Predicates.Replace_Type_Reference
6162 -- regarding handling of Sloc and Comes_From_Source.
6164 procedure Replace_Type_Reference (N : Node_Id) is
6167 -- Add semantic information to node to be rewritten, for ASIS
6168 -- navigation needs.
6170 if Nkind (N) = N_Identifier then
6174 elsif Nkind (N) = N_Selected_Component then
6175 Analyze (Prefix (N));
6176 Set_Entity (Selector_Name (N), T);
6177 Set_Etype (Selector_Name (N), T);
6180 -- Invariant'Class, replace with T'Class (obj)
6182 if Class_Present (Ritem) then
6184 Make_Type_Conversion (Sloc (N),
6186 Make_Attribute_Reference (Sloc (N),
6187 Prefix => New_Occurrence_Of (T, Sloc (N)),
6188 Attribute_Name => Name_Class),
6189 Expression => Make_Identifier (Sloc (N), Object_Name)));
6191 Set_Entity (Expression (N), Object_Entity);
6192 Set_Etype (Expression (N), Typ);
6194 -- Invariant, replace with obj
6197 Rewrite (N, Make_Identifier (Sloc (N), Object_Name));
6198 Set_Entity (N, Object_Entity);
6202 Set_Comes_From_Source (N, True);
6203 end Replace_Type_Reference;
6205 -- Start of processing for Add_Invariants
6208 Ritem := First_Rep_Item (T);
6209 while Present (Ritem) loop
6210 if Nkind (Ritem) = N_Pragma
6211 and then Pragma_Name (Ritem) = Name_Invariant
6213 Arg1 := First (Pragma_Argument_Associations (Ritem));
6214 Arg2 := Next (Arg1);
6215 Arg3 := Next (Arg2);
6217 Arg1 := Get_Pragma_Arg (Arg1);
6218 Arg2 := Get_Pragma_Arg (Arg2);
6220 -- For Inherit case, ignore Invariant, process only Class case
6223 if not Class_Present (Ritem) then
6227 -- For Inherit false, process only item for right type
6230 if Entity (Arg1) /= Typ then
6236 Stmts := Empty_List;
6239 Exp := New_Copy_Tree (Arg2);
6241 -- Preserve sloc of original pragma Invariant
6243 Loc := Sloc (Ritem);
6245 -- We need to replace any occurrences of the name of the type
6246 -- with references to the object, converted to type'Class in
6247 -- the case of Invariant'Class aspects.
6249 Replace_Type_References (Exp, Chars (T));
6251 -- If this invariant comes from an aspect, find the aspect
6252 -- specification, and replace the saved expression because
6253 -- we need the subtype references replaced for the calls to
6254 -- Preanalyze_Spec_Expressin in Check_Aspect_At_Freeze_Point
6255 -- and Check_Aspect_At_End_Of_Declarations.
6257 if From_Aspect_Specification (Ritem) then
6262 -- Loop to find corresponding aspect, note that this
6263 -- must be present given the pragma is marked delayed.
6265 Aitem := Next_Rep_Item (Ritem);
6266 while Present (Aitem) loop
6267 if Nkind (Aitem) = N_Aspect_Specification
6268 and then Aspect_Rep_Item (Aitem) = Ritem
6271 (Identifier (Aitem), New_Copy_Tree (Exp));
6275 Aitem := Next_Rep_Item (Aitem);
6280 -- Now we need to preanalyze the expression to properly capture
6281 -- the visibility in the visible part. The expression will not
6282 -- be analyzed for real until the body is analyzed, but that is
6283 -- at the end of the private part and has the wrong visibility.
6285 Set_Parent (Exp, N);
6286 Preanalyze_Assert_Expression (Exp, Standard_Boolean);
6288 -- In ASIS mode, even if assertions are not enabled, we must
6289 -- analyze the original expression in the aspect specification
6290 -- because it is part of the original tree.
6294 Inv : constant Node_Id :=
6295 Expression (Corresponding_Aspect (Ritem));
6297 Replace_Type_References (Inv, Chars (T));
6298 Preanalyze_Assert_Expression (Inv, Standard_Boolean);
6302 -- Build first two arguments for Check pragma
6305 Make_Pragma_Argument_Association (Loc,
6306 Expression => Make_Identifier (Loc, Name_Invariant)),
6307 Make_Pragma_Argument_Association (Loc,
6308 Expression => Exp));
6310 -- Add message if present in Invariant pragma
6312 if Present (Arg3) then
6313 Str := Strval (Get_Pragma_Arg (Arg3));
6315 -- If inherited case, and message starts "failed invariant",
6316 -- change it to be "failed inherited invariant".
6319 String_To_Name_Buffer (Str);
6321 if Name_Buffer (1 .. 16) = "failed invariant" then
6322 Insert_Str_In_Name_Buffer ("inherited ", 8);
6323 Str := String_From_Name_Buffer;
6328 Make_Pragma_Argument_Association (Loc,
6329 Expression => Make_String_Literal (Loc, Str)));
6332 -- Add Check pragma to list of statements
6336 Pragma_Identifier =>
6337 Make_Identifier (Loc, Name_Check),
6338 Pragma_Argument_Associations => Assoc));
6340 -- If Inherited case and option enabled, output info msg. Note
6341 -- that we know this is a case of Invariant'Class.
6343 if Inherit and Opt.List_Inherited_Aspects then
6344 Error_Msg_Sloc := Sloc (Ritem);
6346 ("info: & inherits `Invariant''Class` aspect from #?L?",
6352 Next_Rep_Item (Ritem);
6356 -- Start of processing for Build_Invariant_Procedure
6364 -- If the aspect specification exists for some view of the type, the
6365 -- declaration for the procedure has been created.
6367 if Has_Invariants (Typ) then
6368 SId := Invariant_Procedure (Typ);
6371 if Present (SId) then
6372 PDecl := Unit_Declaration_Node (SId);
6374 PDecl := Build_Invariant_Procedure_Declaration (Typ);
6377 -- Recover formal of procedure, for use in the calls to invariant
6378 -- functions (including inherited ones).
6382 (First (Parameter_Specifications (Specification (PDecl))));
6383 Object_Name := Chars (Object_Entity);
6385 -- Add invariants for the current type
6387 Add_Invariants (Typ, Inherit => False);
6389 -- Add invariants for parent types
6392 Current_Typ : Entity_Id;
6393 Parent_Typ : Entity_Id;
6398 Parent_Typ := Etype (Current_Typ);
6400 if Is_Private_Type (Parent_Typ)
6401 and then Present (Full_View (Base_Type (Parent_Typ)))
6403 Parent_Typ := Full_View (Base_Type (Parent_Typ));
6406 exit when Parent_Typ = Current_Typ;
6408 Current_Typ := Parent_Typ;
6409 Add_Invariants (Current_Typ, Inherit => True);
6413 -- Build the procedure if we generated at least one Check pragma
6415 if Stmts /= No_List then
6416 Spec := Copy_Separate_Tree (Specification (PDecl));
6419 Make_Subprogram_Body (Loc,
6420 Specification => Spec,
6421 Declarations => Empty_List,
6422 Handled_Statement_Sequence =>
6423 Make_Handled_Sequence_Of_Statements (Loc,
6424 Statements => Stmts));
6426 -- Insert procedure declaration and spec at the appropriate points.
6427 -- If declaration is already analyzed, it was processed by the
6428 -- generated pragma.
6430 if Present (Private_Decls) then
6432 -- The spec goes at the end of visible declarations, but they have
6433 -- already been analyzed, so we need to explicitly do the analyze.
6435 if not Analyzed (PDecl) then
6436 Append_To (Visible_Decls, PDecl);
6440 -- The body goes at the end of the private declarations, which we
6441 -- have not analyzed yet, so we do not need to perform an explicit
6442 -- analyze call. We skip this if there are no private declarations
6443 -- (this is an error that will be caught elsewhere);
6445 Append_To (Private_Decls, PBody);
6447 -- If the invariant appears on the full view of a type, the
6448 -- analysis of the private part is complete, and we must
6449 -- analyze the new body explicitly.
6451 if In_Private_Part (Current_Scope) then
6455 -- If there are no private declarations this may be an error that
6456 -- will be diagnosed elsewhere. However, if this is a non-private
6457 -- type that inherits invariants, it needs no completion and there
6458 -- may be no private part. In this case insert invariant procedure
6459 -- at end of current declarative list, and analyze at once, given
6460 -- that the type is about to be frozen.
6462 elsif not Is_Private_Type (Typ) then
6463 Append_To (Visible_Decls, PDecl);
6464 Append_To (Visible_Decls, PBody);
6469 end Build_Invariant_Procedure;
6471 -------------------------------
6472 -- Build_Predicate_Functions --
6473 -------------------------------
6475 -- The procedures that are constructed here have the form:
6477 -- function typPredicate (Ixxx : typ) return Boolean is
6480 -- exp1 and then exp2 and then ...
6481 -- and then typ1Predicate (typ1 (Ixxx))
6482 -- and then typ2Predicate (typ2 (Ixxx))
6484 -- end typPredicate;
6486 -- Here exp1, and exp2 are expressions from Predicate pragmas. Note that
6487 -- this is the point at which these expressions get analyzed, providing the
6488 -- required delay, and typ1, typ2, are entities from which predicates are
6489 -- inherited. Note that we do NOT generate Check pragmas, that's because we
6490 -- use this function even if checks are off, e.g. for membership tests.
6492 -- If the expression has at least one Raise_Expression, then we also build
6493 -- the typPredicateM version of the function, in which any occurrence of a
6494 -- Raise_Expression is converted to "return False".
6496 procedure Build_Predicate_Functions (Typ : Entity_Id; N : Node_Id) is
6497 Loc : constant Source_Ptr := Sloc (Typ);
6500 -- This is the expression for the result of the function. It is
6501 -- is build by connecting the component predicates with AND THEN.
6504 -- This is the corresponding return expression for the Predicate_M
6505 -- function. It differs in that raise expressions are marked for
6506 -- special expansion (see Process_REs).
6508 Object_Name : constant Name_Id := New_Internal_Name ('I');
6509 -- Name for argument of Predicate procedure. Note that we use the same
6510 -- name for both predicate procedure. That way the reference within the
6511 -- predicate expression is the same in both functions.
6513 Object_Entity : constant Entity_Id :=
6514 Make_Defining_Identifier (Loc, Chars => Object_Name);
6515 -- Entity for argument of Predicate procedure
6517 Object_Entity_M : constant Entity_Id :=
6518 Make_Defining_Identifier (Loc, Chars => Object_Name);
6519 -- Entity for argument of Predicate_M procedure
6521 Raise_Expression_Present : Boolean := False;
6522 -- Set True if Expr has at least one Raise_Expression
6524 Static_Predic : Node_Id := Empty;
6525 -- Set to N_Pragma node for a static predicate if one is encountered
6527 procedure Add_Call (T : Entity_Id);
6528 -- Includes a call to the predicate function for type T in Expr if T
6529 -- has predicates and Predicate_Function (T) is non-empty.
6531 procedure Add_Predicates;
6532 -- Appends expressions for any Predicate pragmas in the rep item chain
6533 -- Typ to Expr. Note that we look only at items for this exact entity.
6534 -- Inheritance of predicates for the parent type is done by calling the
6535 -- Predicate_Function of the parent type, using Add_Call above.
6537 function Test_RE (N : Node_Id) return Traverse_Result;
6538 -- Used in Test_REs, tests one node for being a raise expression, and if
6539 -- so sets Raise_Expression_Present True.
6541 procedure Test_REs is new Traverse_Proc (Test_RE);
6542 -- Tests to see if Expr contains any raise expressions
6544 function Process_RE (N : Node_Id) return Traverse_Result;
6545 -- Used in Process REs, tests if node N is a raise expression, and if
6546 -- so, marks it to be converted to return False.
6548 procedure Process_REs is new Traverse_Proc (Process_RE);
6549 -- Marks any raise expressions in Expr_M to return False
6555 procedure Add_Call (T : Entity_Id) is
6559 if Present (T) and then Present (Predicate_Function (T)) then
6560 Set_Has_Predicates (Typ);
6562 -- Build the call to the predicate function of T
6566 (T, Convert_To (T, Make_Identifier (Loc, Object_Name)));
6568 -- Add call to evolving expression, using AND THEN if needed
6575 Left_Opnd => Relocate_Node (Expr),
6579 -- Output info message on inheritance if required. Note we do not
6580 -- give this information for generic actual types, since it is
6581 -- unwelcome noise in that case in instantiations. We also
6582 -- generally suppress the message in instantiations, and also
6583 -- if it involves internal names.
6585 if Opt.List_Inherited_Aspects
6586 and then not Is_Generic_Actual_Type (Typ)
6587 and then Instantiation_Depth (Sloc (Typ)) = 0
6588 and then not Is_Internal_Name (Chars (T))
6589 and then not Is_Internal_Name (Chars (Typ))
6591 Error_Msg_Sloc := Sloc (Predicate_Function (T));
6592 Error_Msg_Node_2 := T;
6593 Error_Msg_N ("info: & inherits predicate from & #?L?", Typ);
6598 --------------------
6599 -- Add_Predicates --
6600 --------------------
6602 procedure Add_Predicates is
6607 procedure Replace_Type_Reference (N : Node_Id);
6608 -- Replace a single occurrence N of the subtype name with a reference
6609 -- to the formal of the predicate function. N can be an identifier
6610 -- referencing the subtype, or a selected component, representing an
6611 -- appropriately qualified occurrence of the subtype name.
6613 procedure Replace_Type_References is
6614 new Replace_Type_References_Generic (Replace_Type_Reference);
6615 -- Traverse an expression changing every occurrence of an identifier
6616 -- whose name matches the name of the subtype with a reference to
6617 -- the formal parameter of the predicate function.
6619 ----------------------------
6620 -- Replace_Type_Reference --
6621 ----------------------------
6623 procedure Replace_Type_Reference (N : Node_Id) is
6625 Rewrite (N, Make_Identifier (Sloc (N), Object_Name));
6626 -- Use the Sloc of the usage name, not the defining name
6629 Set_Entity (N, Object_Entity);
6631 -- We want to treat the node as if it comes from source, so that
6632 -- ASIS will not ignore it
6634 Set_Comes_From_Source (N, True);
6635 end Replace_Type_Reference;
6637 -- Start of processing for Add_Predicates
6640 Ritem := First_Rep_Item (Typ);
6641 while Present (Ritem) loop
6642 if Nkind (Ritem) = N_Pragma
6643 and then Pragma_Name (Ritem) = Name_Predicate
6645 -- Save the static predicate of the type for diagnostics and
6646 -- error reporting purposes.
6648 if Present (Corresponding_Aspect (Ritem))
6649 and then Chars (Identifier (Corresponding_Aspect (Ritem))) =
6650 Name_Static_Predicate
6652 Static_Predic := Ritem;
6655 -- Acquire arguments
6657 Arg1 := First (Pragma_Argument_Associations (Ritem));
6658 Arg2 := Next (Arg1);
6660 Arg1 := Get_Pragma_Arg (Arg1);
6661 Arg2 := Get_Pragma_Arg (Arg2);
6663 -- See if this predicate pragma is for the current type or for
6664 -- its full view. A predicate on a private completion is placed
6665 -- on the partial view beause this is the visible entity that
6668 if Entity (Arg1) = Typ
6669 or else Full_View (Entity (Arg1)) = Typ
6671 -- We have a match, this entry is for our subtype
6673 -- We need to replace any occurrences of the name of the
6674 -- type with references to the object.
6676 Replace_Type_References (Arg2, Chars (Typ));
6678 -- If this predicate comes from an aspect, find the aspect
6679 -- specification, and replace the saved expression because
6680 -- we need the subtype references replaced for the calls to
6681 -- Preanalyze_Spec_Expressin in Check_Aspect_At_Freeze_Point
6682 -- and Check_Aspect_At_End_Of_Declarations.
6684 if From_Aspect_Specification (Ritem) then
6689 -- Loop to find corresponding aspect, note that this
6690 -- must be present given the pragma is marked delayed.
6692 Aitem := Next_Rep_Item (Ritem);
6694 if Nkind (Aitem) = N_Aspect_Specification
6695 and then Aspect_Rep_Item (Aitem) = Ritem
6698 (Identifier (Aitem), New_Copy_Tree (Arg2));
6702 Aitem := Next_Rep_Item (Aitem);
6707 -- Now we can add the expression
6710 Expr := Relocate_Node (Arg2);
6712 -- There already was a predicate, so add to it
6717 Left_Opnd => Relocate_Node (Expr),
6718 Right_Opnd => Relocate_Node (Arg2));
6723 Next_Rep_Item (Ritem);
6731 function Process_RE (N : Node_Id) return Traverse_Result is
6733 if Nkind (N) = N_Raise_Expression then
6734 Set_Convert_To_Return_False (N);
6745 function Test_RE (N : Node_Id) return Traverse_Result is
6747 if Nkind (N) = N_Raise_Expression then
6748 Raise_Expression_Present := True;
6755 -- Start of processing for Build_Predicate_Functions
6758 -- Return if already built or if type does not have predicates
6760 if not Has_Predicates (Typ)
6761 or else Present (Predicate_Function (Typ))
6766 -- Prepare to construct predicate expression
6770 -- Add Predicates for the current type
6774 -- Add predicates for ancestor if present
6777 Atyp : constant Entity_Id := Nearest_Ancestor (Typ);
6779 if Present (Atyp) then
6784 -- Case where predicates are present
6786 if Present (Expr) then
6788 -- Test for raise expression present
6792 -- If raise expression is present, capture a copy of Expr for use
6793 -- in building the predicateM function version later on. For this
6794 -- copy we replace references to Object_Entity by Object_Entity_M.
6796 if Raise_Expression_Present then
6798 Map : constant Elist_Id := New_Elmt_List;
6800 Append_Elmt (Object_Entity, Map);
6801 Append_Elmt (Object_Entity_M, Map);
6802 Expr_M := New_Copy_Tree (Expr, Map => Map);
6806 -- Build the main predicate function
6809 SId : constant Entity_Id :=
6810 Make_Defining_Identifier (Loc,
6811 Chars => New_External_Name (Chars (Typ), "Predicate"));
6812 -- The entity for the the function spec
6814 SIdB : constant Entity_Id :=
6815 Make_Defining_Identifier (Loc,
6816 Chars => New_External_Name (Chars (Typ), "Predicate"));
6817 -- The entity for the function body
6824 -- Build function declaration
6826 Set_Ekind (SId, E_Function);
6827 Set_Is_Internal (SId);
6828 Set_Is_Predicate_Function (SId);
6829 Set_Predicate_Function (Typ, SId);
6831 -- The predicate function is shared between views of a type
6833 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
6834 Set_Predicate_Function (Full_View (Typ), SId);
6838 Make_Function_Specification (Loc,
6839 Defining_Unit_Name => SId,
6840 Parameter_Specifications => New_List (
6841 Make_Parameter_Specification (Loc,
6842 Defining_Identifier => Object_Entity,
6843 Parameter_Type => New_Occurrence_Of (Typ, Loc))),
6844 Result_Definition =>
6845 New_Occurrence_Of (Standard_Boolean, Loc));
6848 Make_Subprogram_Declaration (Loc,
6849 Specification => Spec);
6851 -- Build function body
6854 Make_Function_Specification (Loc,
6855 Defining_Unit_Name => SIdB,
6856 Parameter_Specifications => New_List (
6857 Make_Parameter_Specification (Loc,
6858 Defining_Identifier =>
6859 Make_Defining_Identifier (Loc, Object_Name),
6861 New_Occurrence_Of (Typ, Loc))),
6862 Result_Definition =>
6863 New_Occurrence_Of (Standard_Boolean, Loc));
6866 Make_Subprogram_Body (Loc,
6867 Specification => Spec,
6868 Declarations => Empty_List,
6869 Handled_Statement_Sequence =>
6870 Make_Handled_Sequence_Of_Statements (Loc,
6871 Statements => New_List (
6872 Make_Simple_Return_Statement (Loc,
6873 Expression => Expr))));
6875 -- Insert declaration before freeze node and body after
6877 Insert_Before_And_Analyze (N, FDecl);
6878 Insert_After_And_Analyze (N, FBody);
6881 -- Test for raise expressions present and if so build M version
6883 if Raise_Expression_Present then
6885 SId : constant Entity_Id :=
6886 Make_Defining_Identifier (Loc,
6887 Chars => New_External_Name (Chars (Typ), "PredicateM"));
6888 -- The entity for the the function spec
6890 SIdB : constant Entity_Id :=
6891 Make_Defining_Identifier (Loc,
6892 Chars => New_External_Name (Chars (Typ), "PredicateM"));
6893 -- The entity for the function body
6901 -- Mark any raise expressions for special expansion
6903 Process_REs (Expr_M);
6905 -- Build function declaration
6907 Set_Ekind (SId, E_Function);
6908 Set_Is_Predicate_Function_M (SId);
6909 Set_Predicate_Function_M (Typ, SId);
6911 -- The predicate function is shared between views of a type
6913 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
6914 Set_Predicate_Function_M (Full_View (Typ), SId);
6918 Make_Function_Specification (Loc,
6919 Defining_Unit_Name => SId,
6920 Parameter_Specifications => New_List (
6921 Make_Parameter_Specification (Loc,
6922 Defining_Identifier => Object_Entity_M,
6923 Parameter_Type => New_Occurrence_Of (Typ, Loc))),
6924 Result_Definition =>
6925 New_Occurrence_Of (Standard_Boolean, Loc));
6928 Make_Subprogram_Declaration (Loc,
6929 Specification => Spec);
6931 -- Build function body
6934 Make_Function_Specification (Loc,
6935 Defining_Unit_Name => SIdB,
6936 Parameter_Specifications => New_List (
6937 Make_Parameter_Specification (Loc,
6938 Defining_Identifier =>
6939 Make_Defining_Identifier (Loc, Object_Name),
6941 New_Occurrence_Of (Typ, Loc))),
6942 Result_Definition =>
6943 New_Occurrence_Of (Standard_Boolean, Loc));
6945 -- Build the body, we declare the boolean expression before
6946 -- doing the return, because we are not really confident of
6947 -- what happens if a return appears within a return.
6950 Make_Defining_Identifier (Loc,
6951 Chars => New_Internal_Name ('B'));
6954 Make_Subprogram_Body (Loc,
6955 Specification => Spec,
6957 Declarations => New_List (
6958 Make_Object_Declaration (Loc,
6959 Defining_Identifier => BTemp,
6960 Constant_Present => True,
6961 Object_Definition =>
6962 New_Occurrence_Of (Standard_Boolean, Loc),
6963 Expression => Expr_M)),
6965 Handled_Statement_Sequence =>
6966 Make_Handled_Sequence_Of_Statements (Loc,
6967 Statements => New_List (
6968 Make_Simple_Return_Statement (Loc,
6969 Expression => New_Occurrence_Of (BTemp, Loc)))));
6971 -- Insert declaration before freeze node and body after
6973 Insert_Before_And_Analyze (N, FDecl);
6974 Insert_After_And_Analyze (N, FBody);
6978 if Is_Scalar_Type (Typ) then
6980 -- Attempt to build a static predicate for a discrete or a real
6981 -- subtype. This action may fail because the actual expression may
6982 -- not be static. Note that the presence of an inherited or
6983 -- explicitly declared dynamic predicate is orthogonal to this
6984 -- check because we are only interested in the static predicate.
6986 if Ekind_In (Typ, E_Decimal_Fixed_Point_Subtype,
6987 E_Enumeration_Subtype,
6988 E_Floating_Point_Subtype,
6989 E_Modular_Integer_Subtype,
6990 E_Ordinary_Fixed_Point_Subtype,
6991 E_Signed_Integer_Subtype)
6993 Build_Static_Predicate (Typ, Expr, Object_Name);
6995 -- Emit an error when the predicate is categorized as static
6996 -- but its expression is dynamic.
6998 if Present (Static_Predic)
6999 and then No (Static_Predicate (Typ))
7002 ("expression does not have required form for "
7003 & "static predicate",
7004 Next (First (Pragma_Argument_Associations
7009 -- If a static predicate applies on other types, that's an error:
7010 -- either the type is scalar but non-static, or it's not even a
7011 -- scalar type. We do not issue an error on generated types, as
7012 -- these may be duplicates of the same error on a source type.
7014 elsif Present (Static_Predic) and then Comes_From_Source (Typ) then
7015 if Is_Scalar_Type (Typ) then
7017 ("static predicate not allowed for non-static type&",
7021 ("static predicate not allowed for non-scalar type&",
7026 end Build_Predicate_Functions;
7028 ----------------------------
7029 -- Build_Static_Predicate --
7030 ----------------------------
7032 procedure Build_Static_Predicate
7037 Loc : constant Source_Ptr := Sloc (Expr);
7039 Non_Static : exception;
7040 -- Raised if something non-static is found
7042 Btyp : constant Entity_Id := Base_Type (Typ);
7044 BLo : constant Uint := Expr_Value (Type_Low_Bound (Btyp));
7045 BHi : constant Uint := Expr_Value (Type_High_Bound (Btyp));
7046 -- Low bound and high bound value of base type of Typ
7048 TLo : constant Uint := Expr_Value (Type_Low_Bound (Typ));
7049 THi : constant Uint := Expr_Value (Type_High_Bound (Typ));
7050 -- Low bound and high bound values of static subtype Typ
7055 -- One entry in a Rlist value, a single REnt (range entry) value denotes
7056 -- one range from Lo to Hi. To represent a single value range Lo = Hi =
7059 type RList is array (Nat range <>) of REnt;
7060 -- A list of ranges. The ranges are sorted in increasing order, and are
7061 -- disjoint (there is a gap of at least one value between each range in
7062 -- the table). A value is in the set of ranges in Rlist if it lies
7063 -- within one of these ranges.
7065 False_Range : constant RList :=
7066 RList'(1 .. 0 => REnt'(No_Uint, No_Uint));
7067 -- An empty set of ranges represents a range list that can never be
7068 -- satisfied, since there are no ranges in which the value could lie,
7069 -- so it does not lie in any of them. False_Range is a canonical value
7070 -- for this empty set, but general processing should test for an Rlist
7071 -- with length zero (see Is_False predicate), since other null ranges
7072 -- may appear which must be treated as False.
7074 True_Range : constant RList := RList'(1 => REnt'(BLo, BHi));
7075 -- Range representing True, value must be in the base range
7077 function "and" (Left : RList; Right : RList) return RList;
7078 -- And's together two range lists, returning a range list. This is a set
7079 -- intersection operation.
7081 function "or" (Left : RList; Right : RList) return RList;
7082 -- Or's together two range lists, returning a range list. This is a set
7085 function "not" (Right : RList) return RList;
7086 -- Returns complement of a given range list, i.e. a range list
7087 -- representing all the values in TLo .. THi that are not in the input
7090 function Build_Val (V : Uint) return Node_Id;
7091 -- Return an analyzed N_Identifier node referencing this value, suitable
7092 -- for use as an entry in the Static_Predicate list. This node is typed
7093 -- with the base type.
7095 function Build_Range (Lo : Uint; Hi : Uint) return Node_Id;
7096 -- Return an analyzed N_Range node referencing this range, suitable for
7097 -- use as an entry in the Static_Predicate list. This node is typed with
7100 function Get_RList (Exp : Node_Id) return RList;
7101 -- This is a recursive routine that converts the given expression into a
7102 -- list of ranges, suitable for use in building the static predicate.
7104 function Is_False (R : RList) return Boolean;
7105 pragma Inline (Is_False);
7106 -- Returns True if the given range list is empty, and thus represents a
7107 -- False list of ranges that can never be satisfied.
7109 function Is_True (R : RList) return Boolean;
7110 -- Returns True if R trivially represents the True predicate by having a
7111 -- single range from BLo to BHi.
7113 function Is_Type_Ref (N : Node_Id) return Boolean;
7114 pragma Inline (Is_Type_Ref);
7115 -- Returns if True if N is a reference to the type for the predicate in
7116 -- the expression (i.e. if it is an identifier whose Chars field matches
7117 -- the Nam given in the call).
7119 function Lo_Val (N : Node_Id) return Uint;
7120 -- Given static expression or static range from a Static_Predicate list,
7121 -- gets expression value or low bound of range.
7123 function Hi_Val (N : Node_Id) return Uint;
7124 -- Given static expression or static range from a Static_Predicate list,
7125 -- gets expression value of high bound of range.
7127 function Membership_Entry (N : Node_Id) return RList;
7128 -- Given a single membership entry (range, value, or subtype), returns
7129 -- the corresponding range list. Raises Static_Error if not static.
7131 function Membership_Entries (N : Node_Id) return RList;
7132 -- Given an element on an alternatives list of a membership operation,
7133 -- returns the range list corresponding to this entry and all following
7134 -- entries (i.e. returns the "or" of this list of values).
7136 function Stat_Pred (Typ : Entity_Id) return RList;
7137 -- Given a type, if it has a static predicate, then return the predicate
7138 -- as a range list, otherwise raise Non_Static.
7144 function "and" (Left : RList; Right : RList) return RList is
7146 -- First range of result
7148 SLeft : Nat := Left'First;
7149 -- Start of rest of left entries
7151 SRight : Nat := Right'First;
7152 -- Start of rest of right entries
7155 -- If either range is True, return the other
7157 if Is_True (Left) then
7159 elsif Is_True (Right) then
7163 -- If either range is False, return False
7165 if Is_False (Left) or else Is_False (Right) then
7169 -- Loop to remove entries at start that are disjoint, and thus just
7170 -- get discarded from the result entirely.
7173 -- If no operands left in either operand, result is false
7175 if SLeft > Left'Last or else SRight > Right'Last then
7178 -- Discard first left operand entry if disjoint with right
7180 elsif Left (SLeft).Hi < Right (SRight).Lo then
7183 -- Discard first right operand entry if disjoint with left
7185 elsif Right (SRight).Hi < Left (SLeft).Lo then
7186 SRight := SRight + 1;
7188 -- Otherwise we have an overlapping entry
7195 -- Now we have two non-null operands, and first entries overlap. The
7196 -- first entry in the result will be the overlapping part of these
7199 FEnt := REnt'(Lo => UI_Max (Left (SLeft).Lo, Right (SRight).Lo),
7200 Hi => UI_Min (Left (SLeft).Hi, Right (SRight).Hi));
7202 -- Now we can remove the entry that ended at a lower value, since its
7203 -- contribution is entirely contained in Fent.
7205 if Left (SLeft).Hi <= Right (SRight).Hi then
7208 SRight := SRight + 1;
7211 -- Compute result by concatenating this first entry with the "and" of
7212 -- the remaining parts of the left and right operands. Note that if
7213 -- either of these is empty, "and" will yield empty, so that we will
7214 -- end up with just Fent, which is what we want in that case.
7217 FEnt & (Left (SLeft .. Left'Last) and Right (SRight .. Right'Last));
7224 function "not" (Right : RList) return RList is
7226 -- Return True if False range
7228 if Is_False (Right) then
7232 -- Return False if True range
7234 if Is_True (Right) then
7238 -- Here if not trivial case
7241 Result : RList (1 .. Right'Length + 1);
7242 -- May need one more entry for gap at beginning and end
7245 -- Number of entries stored in Result
7250 if Right (Right'First).Lo > TLo then
7252 Result (Count) := REnt'(TLo, Right (Right'First).Lo - 1);
7255 -- Gaps between ranges
7257 for J in Right'First .. Right'Last - 1 loop
7260 REnt'(Right (J).Hi + 1, Right (J + 1).Lo - 1);
7265 if Right (Right'Last).Hi < THi then
7267 Result (Count) := REnt'(Right (Right'Last).Hi + 1, THi);
7270 return Result (1 .. Count);
7278 function "or" (Left : RList; Right : RList) return RList is
7280 -- First range of result
7282 SLeft : Nat := Left'First;
7283 -- Start of rest of left entries
7285 SRight : Nat := Right'First;
7286 -- Start of rest of right entries
7289 -- If either range is True, return True
7291 if Is_True (Left) or else Is_True (Right) then
7295 -- If either range is False (empty), return the other
7297 if Is_False (Left) then
7299 elsif Is_False (Right) then
7303 -- Initialize result first entry from left or right operand depending
7304 -- on which starts with the lower range.
7306 if Left (SLeft).Lo < Right (SRight).Lo then
7307 FEnt := Left (SLeft);
7310 FEnt := Right (SRight);
7311 SRight := SRight + 1;
7314 -- This loop eats ranges from left and right operands that are
7315 -- contiguous with the first range we are gathering.
7318 -- Eat first entry in left operand if contiguous or overlapped by
7319 -- gathered first operand of result.
7321 if SLeft <= Left'Last
7322 and then Left (SLeft).Lo <= FEnt.Hi + 1
7324 FEnt.Hi := UI_Max (FEnt.Hi, Left (SLeft).Hi);
7327 -- Eat first entry in right operand if contiguous or overlapped by
7328 -- gathered right operand of result.
7330 elsif SRight <= Right'Last
7331 and then Right (SRight).Lo <= FEnt.Hi + 1
7333 FEnt.Hi := UI_Max (FEnt.Hi, Right (SRight).Hi);
7334 SRight := SRight + 1;
7336 -- All done if no more entries to eat
7343 -- Obtain result as the first entry we just computed, concatenated
7344 -- to the "or" of the remaining results (if one operand is empty,
7345 -- this will just concatenate with the other
7348 FEnt & (Left (SLeft .. Left'Last) or Right (SRight .. Right'Last));
7355 function Build_Range (Lo : Uint; Hi : Uint) return Node_Id is
7361 Low_Bound => Build_Val (Lo),
7362 High_Bound => Build_Val (Hi));
7363 Set_Etype (Result, Btyp);
7364 Set_Analyzed (Result);
7373 function Build_Val (V : Uint) return Node_Id is
7377 if Is_Enumeration_Type (Typ) then
7378 Result := Get_Enum_Lit_From_Pos (Typ, V, Loc);
7380 Result := Make_Integer_Literal (Loc, V);
7383 Set_Etype (Result, Btyp);
7384 Set_Is_Static_Expression (Result);
7385 Set_Analyzed (Result);
7393 function Get_RList (Exp : Node_Id) return RList is
7398 -- Static expression can only be true or false
7400 if Is_OK_Static_Expression (Exp) then
7404 if Expr_Value (Exp) = 0 then
7411 -- Otherwise test node type
7419 when N_Op_And | N_And_Then =>
7420 return Get_RList (Left_Opnd (Exp))
7422 Get_RList (Right_Opnd (Exp));
7426 when N_Op_Or | N_Or_Else =>
7427 return Get_RList (Left_Opnd (Exp))
7429 Get_RList (Right_Opnd (Exp));
7434 return not Get_RList (Right_Opnd (Exp));
7436 -- Comparisons of type with static value
7438 when N_Op_Compare =>
7440 -- Type is left operand
7442 if Is_Type_Ref (Left_Opnd (Exp))
7443 and then Is_OK_Static_Expression (Right_Opnd (Exp))
7445 Val := Expr_Value (Right_Opnd (Exp));
7447 -- Typ is right operand
7449 elsif Is_Type_Ref (Right_Opnd (Exp))
7450 and then Is_OK_Static_Expression (Left_Opnd (Exp))
7452 Val := Expr_Value (Left_Opnd (Exp));
7454 -- Invert sense of comparison
7457 when N_Op_Gt => Op := N_Op_Lt;
7458 when N_Op_Lt => Op := N_Op_Gt;
7459 when N_Op_Ge => Op := N_Op_Le;
7460 when N_Op_Le => Op := N_Op_Ge;
7461 when others => null;
7464 -- Other cases are non-static
7470 -- Construct range according to comparison operation
7474 return RList'(1 => REnt'(Val, Val));
7477 return RList'(1 => REnt'(Val, BHi));
7480 return RList'(1 => REnt'(Val + 1, BHi));
7483 return RList'(1 => REnt'(BLo, Val));
7486 return RList'(1 => REnt'(BLo, Val - 1));
7489 return RList'(REnt'(BLo, Val - 1),
7490 REnt'(Val + 1, BHi));
7493 raise Program_Error;
7499 if not Is_Type_Ref (Left_Opnd (Exp)) then
7503 if Present (Right_Opnd (Exp)) then
7504 return Membership_Entry (Right_Opnd (Exp));
7506 return Membership_Entries (First (Alternatives (Exp)));
7509 -- Negative membership (NOT IN)
7512 if not Is_Type_Ref (Left_Opnd (Exp)) then
7516 if Present (Right_Opnd (Exp)) then
7517 return not Membership_Entry (Right_Opnd (Exp));
7519 return not Membership_Entries (First (Alternatives (Exp)));
7522 -- Function call, may be call to static predicate
7524 when N_Function_Call =>
7525 if Is_Entity_Name (Name (Exp)) then
7527 Ent : constant Entity_Id := Entity (Name (Exp));
7529 if Is_Predicate_Function (Ent)
7531 Is_Predicate_Function_M (Ent)
7533 return Stat_Pred (Etype (First_Formal (Ent)));
7538 -- Other function call cases are non-static
7542 -- Qualified expression, dig out the expression
7544 when N_Qualified_Expression =>
7545 return Get_RList (Expression (Exp));
7547 -- Expression with actions: if no actions, dig out expression
7549 when N_Expression_With_Actions =>
7550 if Is_Empty_List (Actions (Exp)) then
7551 return Get_RList (Expression (Exp));
7560 return (Get_RList (Left_Opnd (Exp))
7561 and not Get_RList (Right_Opnd (Exp)))
7562 or (Get_RList (Right_Opnd (Exp))
7563 and not Get_RList (Left_Opnd (Exp)));
7565 -- Any other node type is non-static
7576 function Hi_Val (N : Node_Id) return Uint is
7578 if Is_Static_Expression (N) then
7579 return Expr_Value (N);
7581 pragma Assert (Nkind (N) = N_Range);
7582 return Expr_Value (High_Bound (N));
7590 function Is_False (R : RList) return Boolean is
7592 return R'Length = 0;
7599 function Is_True (R : RList) return Boolean is
7602 and then R (R'First).Lo = BLo
7603 and then R (R'First).Hi = BHi;
7610 function Is_Type_Ref (N : Node_Id) return Boolean is
7612 return Nkind (N) = N_Identifier and then Chars (N) = Nam;
7619 function Lo_Val (N : Node_Id) return Uint is
7621 if Is_Static_Expression (N) then
7622 return Expr_Value (N);
7624 pragma Assert (Nkind (N) = N_Range);
7625 return Expr_Value (Low_Bound (N));
7629 ------------------------
7630 -- Membership_Entries --
7631 ------------------------
7633 function Membership_Entries (N : Node_Id) return RList is
7635 if No (Next (N)) then
7636 return Membership_Entry (N);
7638 return Membership_Entry (N) or Membership_Entries (Next (N));
7640 end Membership_Entries;
7642 ----------------------
7643 -- Membership_Entry --
7644 ----------------------
7646 function Membership_Entry (N : Node_Id) return RList is
7654 if Nkind (N) = N_Range then
7655 if not Is_Static_Expression (Low_Bound (N))
7657 not Is_Static_Expression (High_Bound (N))
7661 SLo := Expr_Value (Low_Bound (N));
7662 SHi := Expr_Value (High_Bound (N));
7663 return RList'(1 => REnt'(SLo, SHi));
7666 -- Static expression case
7668 elsif Is_Static_Expression (N) then
7669 Val := Expr_Value (N);
7670 return RList'(1 => REnt'(Val, Val));
7672 -- Identifier (other than static expression) case
7674 else pragma Assert (Nkind (N) = N_Identifier);
7678 if Is_Type (Entity (N)) then
7680 -- If type has predicates, process them
7682 if Has_Predicates (Entity (N)) then
7683 return Stat_Pred (Entity (N));
7685 -- For static subtype without predicates, get range
7687 elsif Is_Static_Subtype (Entity (N)) then
7688 SLo := Expr_Value (Type_Low_Bound (Entity (N)));
7689 SHi := Expr_Value (Type_High_Bound (Entity (N)));
7690 return RList'(1 => REnt'(SLo, SHi));
7692 -- Any other type makes us non-static
7698 -- Any other kind of identifier in predicate (e.g. a non-static
7699 -- expression value) means this is not a static predicate.
7705 end Membership_Entry;
7711 function Stat_Pred (Typ : Entity_Id) return RList is
7713 -- Not static if type does not have static predicates
7715 if not Has_Predicates (Typ) or else No (Static_Predicate (Typ)) then
7719 -- Otherwise we convert the predicate list to a range list
7722 Result : RList (1 .. List_Length (Static_Predicate (Typ)));
7726 P := First (Static_Predicate (Typ));
7727 for J in Result'Range loop
7728 Result (J) := REnt'(Lo_Val (P), Hi_Val (P));
7736 -- Start of processing for Build_Static_Predicate
7739 -- Now analyze the expression to see if it is a static predicate
7742 Ranges : constant RList := Get_RList (Expr);
7743 -- Range list from expression if it is static
7748 -- Convert range list into a form for the static predicate. In the
7749 -- Ranges array, we just have raw ranges, these must be converted
7750 -- to properly typed and analyzed static expressions or range nodes.
7752 -- Note: here we limit ranges to the ranges of the subtype, so that
7753 -- a predicate is always false for values outside the subtype. That
7754 -- seems fine, such values are invalid anyway, and considering them
7755 -- to fail the predicate seems allowed and friendly, and furthermore
7756 -- simplifies processing for case statements and loops.
7760 for J in Ranges'Range loop
7762 Lo : Uint := Ranges (J).Lo;
7763 Hi : Uint := Ranges (J).Hi;
7766 -- Ignore completely out of range entry
7768 if Hi < TLo or else Lo > THi then
7771 -- Otherwise process entry
7774 -- Adjust out of range value to subtype range
7784 -- Convert range into required form
7786 Append_To (Plist, Build_Range (Lo, Hi));
7791 -- Processing was successful and all entries were static, so now we
7792 -- can store the result as the predicate list.
7794 Set_Static_Predicate (Typ, Plist);
7796 -- The processing for static predicates put the expression into
7797 -- canonical form as a series of ranges. It also eliminated
7798 -- duplicates and collapsed and combined ranges. We might as well
7799 -- replace the alternatives list of the right operand of the
7800 -- membership test with the static predicate list, which will
7801 -- usually be more efficient.
7804 New_Alts : constant List_Id := New_List;
7809 Old_Node := First (Plist);
7810 while Present (Old_Node) loop
7811 New_Node := New_Copy (Old_Node);
7813 if Nkind (New_Node) = N_Range then
7814 Set_Low_Bound (New_Node, New_Copy (Low_Bound (Old_Node)));
7815 Set_High_Bound (New_Node, New_Copy (High_Bound (Old_Node)));
7818 Append_To (New_Alts, New_Node);
7822 -- If empty list, replace by False
7824 if Is_Empty_List (New_Alts) then
7825 Rewrite (Expr, New_Occurrence_Of (Standard_False, Loc));
7827 -- Else replace by set membership test
7832 Left_Opnd => Make_Identifier (Loc, Nam),
7833 Right_Opnd => Empty,
7834 Alternatives => New_Alts));
7836 -- Resolve new expression in function context
7838 Install_Formals (Predicate_Function (Typ));
7839 Push_Scope (Predicate_Function (Typ));
7840 Analyze_And_Resolve (Expr, Standard_Boolean);
7846 -- If non-static, return doing nothing
7851 end Build_Static_Predicate;
7853 -----------------------------------------
7854 -- Check_Aspect_At_End_Of_Declarations --
7855 -----------------------------------------
7857 procedure Check_Aspect_At_End_Of_Declarations (ASN : Node_Id) is
7858 Ent : constant Entity_Id := Entity (ASN);
7859 Ident : constant Node_Id := Identifier (ASN);
7860 A_Id : constant Aspect_Id := Get_Aspect_Id (Chars (Ident));
7862 End_Decl_Expr : constant Node_Id := Entity (Ident);
7863 -- Expression to be analyzed at end of declarations
7865 Freeze_Expr : constant Node_Id := Expression (ASN);
7866 -- Expression from call to Check_Aspect_At_Freeze_Point
7868 T : constant Entity_Id := Etype (Freeze_Expr);
7869 -- Type required for preanalyze call
7872 -- Set False if error
7874 -- On entry to this procedure, Entity (Ident) contains a copy of the
7875 -- original expression from the aspect, saved for this purpose, and
7876 -- but Expression (Ident) is a preanalyzed copy of the expression,
7877 -- preanalyzed just after the freeze point.
7879 procedure Check_Overloaded_Name;
7880 -- For aspects whose expression is simply a name, this routine checks if
7881 -- the name is overloaded or not. If so, it verifies there is an
7882 -- interpretation that matches the entity obtained at the freeze point,
7883 -- otherwise the compiler complains.
7885 ---------------------------
7886 -- Check_Overloaded_Name --
7887 ---------------------------
7889 procedure Check_Overloaded_Name is
7891 if not Is_Overloaded (End_Decl_Expr) then
7892 Err := Entity (End_Decl_Expr) /= Entity (Freeze_Expr);
7898 Index : Interp_Index;
7902 Get_First_Interp (End_Decl_Expr, Index, It);
7903 while Present (It.Typ) loop
7904 if It.Nam = Entity (Freeze_Expr) then
7909 Get_Next_Interp (Index, It);
7913 end Check_Overloaded_Name;
7915 -- Start of processing for Check_Aspect_At_End_Of_Declarations
7918 -- Case of aspects Dimension, Dimension_System and Synchronization
7920 if A_Id = Aspect_Synchronization then
7923 -- Case of stream attributes, just have to compare entities. However,
7924 -- the expression is just a name (possibly overloaded), and there may
7925 -- be stream operations declared for unrelated types, so we just need
7926 -- to verify that one of these interpretations is the one available at
7927 -- at the freeze point.
7929 elsif A_Id = Aspect_Input or else
7930 A_Id = Aspect_Output or else
7931 A_Id = Aspect_Read or else
7934 Analyze (End_Decl_Expr);
7935 Check_Overloaded_Name;
7937 elsif A_Id = Aspect_Variable_Indexing or else
7938 A_Id = Aspect_Constant_Indexing or else
7939 A_Id = Aspect_Default_Iterator or else
7940 A_Id = Aspect_Iterator_Element
7942 -- Make type unfrozen before analysis, to prevent spurious errors
7943 -- about late attributes.
7945 Set_Is_Frozen (Ent, False);
7946 Analyze (End_Decl_Expr);
7947 Set_Is_Frozen (Ent, True);
7949 -- If the end of declarations comes before any other freeze
7950 -- point, the Freeze_Expr is not analyzed: no check needed.
7952 if Analyzed (Freeze_Expr) and then not In_Instance then
7953 Check_Overloaded_Name;
7961 -- In a generic context the aspect expressions have not been
7962 -- preanalyzed, so do it now. There are no conformance checks
7963 -- to perform in this case.
7966 Check_Aspect_At_Freeze_Point (ASN);
7969 -- The default values attributes may be defined in the private part,
7970 -- and the analysis of the expression may take place when only the
7971 -- partial view is visible. The expression must be scalar, so use
7972 -- the full view to resolve.
7974 elsif (A_Id = Aspect_Default_Value
7976 A_Id = Aspect_Default_Component_Value)
7977 and then Is_Private_Type (T)
7979 Preanalyze_Spec_Expression (End_Decl_Expr, Full_View (T));
7981 Preanalyze_Spec_Expression (End_Decl_Expr, T);
7984 Err := not Fully_Conformant_Expressions (End_Decl_Expr, Freeze_Expr);
7987 -- Output error message if error
7991 ("visibility of aspect for& changes after freeze point",
7994 ("info: & is frozen here, aspects evaluated at this point??",
7995 Freeze_Node (Ent), Ent);
7997 end Check_Aspect_At_End_Of_Declarations;
7999 ----------------------------------
8000 -- Check_Aspect_At_Freeze_Point --
8001 ----------------------------------
8003 procedure Check_Aspect_At_Freeze_Point (ASN : Node_Id) is
8004 Ident : constant Node_Id := Identifier (ASN);
8005 -- Identifier (use Entity field to save expression)
8007 A_Id : constant Aspect_Id := Get_Aspect_Id (Chars (Ident));
8009 T : Entity_Id := Empty;
8010 -- Type required for preanalyze call
8013 -- On entry to this procedure, Entity (Ident) contains a copy of the
8014 -- original expression from the aspect, saved for this purpose.
8016 -- On exit from this procedure Entity (Ident) is unchanged, still
8017 -- containing that copy, but Expression (Ident) is a preanalyzed copy
8018 -- of the expression, preanalyzed just after the freeze point.
8020 -- Make a copy of the expression to be preanalyzed
8022 Set_Expression (ASN, New_Copy_Tree (Entity (Ident)));
8024 -- Find type for preanalyze call
8028 -- No_Aspect should be impossible
8031 raise Program_Error;
8033 -- Aspects taking an optional boolean argument
8035 when Boolean_Aspects |
8036 Library_Unit_Aspects =>
8038 T := Standard_Boolean;
8040 -- Aspects corresponding to attribute definition clauses
8042 when Aspect_Address =>
8043 T := RTE (RE_Address);
8045 when Aspect_Attach_Handler =>
8046 T := RTE (RE_Interrupt_ID);
8048 when Aspect_Bit_Order | Aspect_Scalar_Storage_Order =>
8049 T := RTE (RE_Bit_Order);
8051 when Aspect_Convention =>
8055 T := RTE (RE_CPU_Range);
8057 -- Default_Component_Value is resolved with the component type
8059 when Aspect_Default_Component_Value =>
8060 T := Component_Type (Entity (ASN));
8062 -- Default_Value is resolved with the type entity in question
8064 when Aspect_Default_Value =>
8067 -- Depends is a delayed aspect because it mentiones names first
8068 -- introduced by aspect Global which is already delayed. There is
8069 -- no action to be taken with respect to the aspect itself as the
8070 -- analysis is done by the corresponding pragma.
8072 when Aspect_Depends =>
8075 when Aspect_Dispatching_Domain =>
8076 T := RTE (RE_Dispatching_Domain);
8078 when Aspect_External_Tag =>
8079 T := Standard_String;
8081 when Aspect_External_Name =>
8082 T := Standard_String;
8084 -- Global is a delayed aspect because it may reference names that
8085 -- have not been declared yet. There is no action to be taken with
8086 -- respect to the aspect itself as the reference checking is done
8087 -- on the corresponding pragma.
8089 when Aspect_Global =>
8092 when Aspect_Link_Name =>
8093 T := Standard_String;
8095 when Aspect_Priority | Aspect_Interrupt_Priority =>
8096 T := Standard_Integer;
8098 when Aspect_Relative_Deadline =>
8099 T := RTE (RE_Time_Span);
8101 when Aspect_Small =>
8102 T := Universal_Real;
8104 -- For a simple storage pool, we have to retrieve the type of the
8105 -- pool object associated with the aspect's corresponding attribute
8106 -- definition clause.
8108 when Aspect_Simple_Storage_Pool =>
8109 T := Etype (Expression (Aspect_Rep_Item (ASN)));
8111 when Aspect_Storage_Pool =>
8112 T := Class_Wide_Type (RTE (RE_Root_Storage_Pool));
8114 when Aspect_Alignment |
8115 Aspect_Component_Size |
8116 Aspect_Machine_Radix |
8117 Aspect_Object_Size |
8119 Aspect_Storage_Size |
8120 Aspect_Stream_Size |
8121 Aspect_Value_Size =>
8124 when Aspect_Linker_Section =>
8125 T := Standard_String;
8127 when Aspect_Synchronization =>
8130 -- Special case, the expression of these aspects is just an entity
8131 -- that does not need any resolution, so just analyze.
8140 Analyze (Expression (ASN));
8143 -- Same for Iterator aspects, where the expression is a function
8144 -- name. Legality rules are checked separately.
8146 when Aspect_Constant_Indexing |
8147 Aspect_Default_Iterator |
8148 Aspect_Iterator_Element |
8149 Aspect_Variable_Indexing =>
8150 Analyze (Expression (ASN));
8153 -- Ditto for Iterable, legality checks in Validate_Iterable_Aspect.
8155 when Aspect_Iterable =>
8159 Cursor : constant Entity_Id := Get_Cursor_Type (ASN, T);
8164 if Cursor = Any_Type then
8168 Assoc := First (Component_Associations (Expression (ASN)));
8169 while Present (Assoc) loop
8170 Expr := Expression (Assoc);
8173 if not Error_Posted (Expr) then
8174 Resolve_Iterable_Operation
8175 (Expr, Cursor, T, Chars (First (Choices (Assoc))));
8184 -- Invariant/Predicate take boolean expressions
8186 when Aspect_Dynamic_Predicate |
8189 Aspect_Static_Predicate |
8190 Aspect_Type_Invariant =>
8191 T := Standard_Boolean;
8193 -- Here is the list of aspects that don't require delay analysis
8195 when Aspect_Abstract_State |
8196 Aspect_Contract_Cases |
8198 Aspect_Dimension_System |
8199 Aspect_Implicit_Dereference |
8200 Aspect_Initial_Condition |
8201 Aspect_Initializes |
8204 Aspect_Postcondition |
8206 Aspect_Precondition |
8207 Aspect_Refined_Depends |
8208 Aspect_Refined_Global |
8209 Aspect_Refined_Post |
8210 Aspect_Refined_State |
8213 raise Program_Error;
8217 -- Do the preanalyze call
8219 Preanalyze_Spec_Expression (Expression (ASN), T);
8220 end Check_Aspect_At_Freeze_Point;
8222 -----------------------------------
8223 -- Check_Constant_Address_Clause --
8224 -----------------------------------
8226 procedure Check_Constant_Address_Clause
8230 procedure Check_At_Constant_Address (Nod : Node_Id);
8231 -- Checks that the given node N represents a name whose 'Address is
8232 -- constant (in the same sense as OK_Constant_Address_Clause, i.e. the
8233 -- address value is the same at the point of declaration of U_Ent and at
8234 -- the time of elaboration of the address clause.
8236 procedure Check_Expr_Constants (Nod : Node_Id);
8237 -- Checks that Nod meets the requirements for a constant address clause
8238 -- in the sense of the enclosing procedure.
8240 procedure Check_List_Constants (Lst : List_Id);
8241 -- Check that all elements of list Lst meet the requirements for a
8242 -- constant address clause in the sense of the enclosing procedure.
8244 -------------------------------
8245 -- Check_At_Constant_Address --
8246 -------------------------------
8248 procedure Check_At_Constant_Address (Nod : Node_Id) is
8250 if Is_Entity_Name (Nod) then
8251 if Present (Address_Clause (Entity ((Nod)))) then
8253 ("invalid address clause for initialized object &!",
8256 ("address for& cannot" &
8257 " depend on another address clause! (RM 13.1(22))!",
8260 elsif In_Same_Source_Unit (Entity (Nod), U_Ent)
8261 and then Sloc (U_Ent) < Sloc (Entity (Nod))
8264 ("invalid address clause for initialized object &!",
8266 Error_Msg_Node_2 := U_Ent;
8268 ("\& must be defined before & (RM 13.1(22))!",
8272 elsif Nkind (Nod) = N_Selected_Component then
8274 T : constant Entity_Id := Etype (Prefix (Nod));
8277 if (Is_Record_Type (T)
8278 and then Has_Discriminants (T))
8281 and then Is_Record_Type (Designated_Type (T))
8282 and then Has_Discriminants (Designated_Type (T)))
8285 ("invalid address clause for initialized object &!",
8288 ("\address cannot depend on component" &
8289 " of discriminated record (RM 13.1(22))!",
8292 Check_At_Constant_Address (Prefix (Nod));
8296 elsif Nkind (Nod) = N_Indexed_Component then
8297 Check_At_Constant_Address (Prefix (Nod));
8298 Check_List_Constants (Expressions (Nod));
8301 Check_Expr_Constants (Nod);
8303 end Check_At_Constant_Address;
8305 --------------------------
8306 -- Check_Expr_Constants --
8307 --------------------------
8309 procedure Check_Expr_Constants (Nod : Node_Id) is
8310 Loc_U_Ent : constant Source_Ptr := Sloc (U_Ent);
8311 Ent : Entity_Id := Empty;
8314 if Nkind (Nod) in N_Has_Etype
8315 and then Etype (Nod) = Any_Type
8321 when N_Empty | N_Error =>
8324 when N_Identifier | N_Expanded_Name =>
8325 Ent := Entity (Nod);
8327 -- We need to look at the original node if it is different
8328 -- from the node, since we may have rewritten things and
8329 -- substituted an identifier representing the rewrite.
8331 if Original_Node (Nod) /= Nod then
8332 Check_Expr_Constants (Original_Node (Nod));
8334 -- If the node is an object declaration without initial
8335 -- value, some code has been expanded, and the expression
8336 -- is not constant, even if the constituents might be
8337 -- acceptable, as in A'Address + offset.
8339 if Ekind (Ent) = E_Variable
8341 Nkind (Declaration_Node (Ent)) = N_Object_Declaration
8343 No (Expression (Declaration_Node (Ent)))
8346 ("invalid address clause for initialized object &!",
8349 -- If entity is constant, it may be the result of expanding
8350 -- a check. We must verify that its declaration appears
8351 -- before the object in question, else we also reject the
8354 elsif Ekind (Ent) = E_Constant
8355 and then In_Same_Source_Unit (Ent, U_Ent)
8356 and then Sloc (Ent) > Loc_U_Ent
8359 ("invalid address clause for initialized object &!",
8366 -- Otherwise look at the identifier and see if it is OK
8368 if Ekind_In (Ent, E_Named_Integer, E_Named_Real)
8369 or else Is_Type (Ent)
8374 Ekind (Ent) = E_Constant
8376 Ekind (Ent) = E_In_Parameter
8378 -- This is the case where we must have Ent defined before
8379 -- U_Ent. Clearly if they are in different units this
8380 -- requirement is met since the unit containing Ent is
8381 -- already processed.
8383 if not In_Same_Source_Unit (Ent, U_Ent) then
8386 -- Otherwise location of Ent must be before the location
8387 -- of U_Ent, that's what prior defined means.
8389 elsif Sloc (Ent) < Loc_U_Ent then
8394 ("invalid address clause for initialized object &!",
8396 Error_Msg_Node_2 := U_Ent;
8398 ("\& must be defined before & (RM 13.1(22))!",
8402 elsif Nkind (Original_Node (Nod)) = N_Function_Call then
8403 Check_Expr_Constants (Original_Node (Nod));
8407 ("invalid address clause for initialized object &!",
8410 if Comes_From_Source (Ent) then
8412 ("\reference to variable& not allowed"
8413 & " (RM 13.1(22))!", Nod, Ent);
8416 ("non-static expression not allowed"
8417 & " (RM 13.1(22))!", Nod);
8421 when N_Integer_Literal =>
8423 -- If this is a rewritten unchecked conversion, in a system
8424 -- where Address is an integer type, always use the base type
8425 -- for a literal value. This is user-friendly and prevents
8426 -- order-of-elaboration issues with instances of unchecked
8429 if Nkind (Original_Node (Nod)) = N_Function_Call then
8430 Set_Etype (Nod, Base_Type (Etype (Nod)));
8433 when N_Real_Literal |
8435 N_Character_Literal =>
8439 Check_Expr_Constants (Low_Bound (Nod));
8440 Check_Expr_Constants (High_Bound (Nod));
8442 when N_Explicit_Dereference =>
8443 Check_Expr_Constants (Prefix (Nod));
8445 when N_Indexed_Component =>
8446 Check_Expr_Constants (Prefix (Nod));
8447 Check_List_Constants (Expressions (Nod));
8450 Check_Expr_Constants (Prefix (Nod));
8451 Check_Expr_Constants (Discrete_Range (Nod));
8453 when N_Selected_Component =>
8454 Check_Expr_Constants (Prefix (Nod));
8456 when N_Attribute_Reference =>
8457 if Nam_In (Attribute_Name (Nod), Name_Address,
8459 Name_Unchecked_Access,
8460 Name_Unrestricted_Access)
8462 Check_At_Constant_Address (Prefix (Nod));
8465 Check_Expr_Constants (Prefix (Nod));
8466 Check_List_Constants (Expressions (Nod));
8470 Check_List_Constants (Component_Associations (Nod));
8471 Check_List_Constants (Expressions (Nod));
8473 when N_Component_Association =>
8474 Check_Expr_Constants (Expression (Nod));
8476 when N_Extension_Aggregate =>
8477 Check_Expr_Constants (Ancestor_Part (Nod));
8478 Check_List_Constants (Component_Associations (Nod));
8479 Check_List_Constants (Expressions (Nod));
8484 when N_Binary_Op | N_Short_Circuit | N_Membership_Test =>
8485 Check_Expr_Constants (Left_Opnd (Nod));
8486 Check_Expr_Constants (Right_Opnd (Nod));
8489 Check_Expr_Constants (Right_Opnd (Nod));
8491 when N_Type_Conversion |
8492 N_Qualified_Expression |
8494 N_Unchecked_Type_Conversion =>
8495 Check_Expr_Constants (Expression (Nod));
8497 when N_Function_Call =>
8498 if not Is_Pure (Entity (Name (Nod))) then
8500 ("invalid address clause for initialized object &!",
8504 ("\function & is not pure (RM 13.1(22))!",
8505 Nod, Entity (Name (Nod)));
8508 Check_List_Constants (Parameter_Associations (Nod));
8511 when N_Parameter_Association =>
8512 Check_Expr_Constants (Explicit_Actual_Parameter (Nod));
8516 ("invalid address clause for initialized object &!",
8519 ("\must be constant defined before& (RM 13.1(22))!",
8522 end Check_Expr_Constants;
8524 --------------------------
8525 -- Check_List_Constants --
8526 --------------------------
8528 procedure Check_List_Constants (Lst : List_Id) is
8532 if Present (Lst) then
8533 Nod1 := First (Lst);
8534 while Present (Nod1) loop
8535 Check_Expr_Constants (Nod1);
8539 end Check_List_Constants;
8541 -- Start of processing for Check_Constant_Address_Clause
8544 -- If rep_clauses are to be ignored, no need for legality checks. In
8545 -- particular, no need to pester user about rep clauses that violate
8546 -- the rule on constant addresses, given that these clauses will be
8547 -- removed by Freeze before they reach the back end.
8549 if not Ignore_Rep_Clauses then
8550 Check_Expr_Constants (Expr);
8552 end Check_Constant_Address_Clause;
8554 ---------------------------
8555 -- Check_Pool_Size_Clash --
8556 ---------------------------
8558 procedure Check_Pool_Size_Clash (Ent : Entity_Id; SP, SS : Node_Id) is
8562 -- We need to find out which one came first. Note that in the case of
8563 -- aspects mixed with pragmas there are cases where the processing order
8564 -- is reversed, which is why we do the check here.
8566 if Sloc (SP) < Sloc (SS) then
8567 Error_Msg_Sloc := Sloc (SP);
8569 Error_Msg_NE ("Storage_Pool previously given for&#", Post, Ent);
8572 Error_Msg_Sloc := Sloc (SS);
8574 Error_Msg_NE ("Storage_Size previously given for&#", Post, Ent);
8578 ("\cannot have Storage_Size and Storage_Pool (RM 13.11(3))", Post);
8579 end Check_Pool_Size_Clash;
8581 ----------------------------------------
8582 -- Check_Record_Representation_Clause --
8583 ----------------------------------------
8585 procedure Check_Record_Representation_Clause (N : Node_Id) is
8586 Loc : constant Source_Ptr := Sloc (N);
8587 Ident : constant Node_Id := Identifier (N);
8588 Rectype : Entity_Id;
8593 Hbit : Uint := Uint_0;
8597 Max_Bit_So_Far : Uint;
8598 -- Records the maximum bit position so far. If all field positions
8599 -- are monotonically increasing, then we can skip the circuit for
8600 -- checking for overlap, since no overlap is possible.
8602 Tagged_Parent : Entity_Id := Empty;
8603 -- This is set in the case of a derived tagged type for which we have
8604 -- Is_Fully_Repped_Tagged_Type True (indicating that all components are
8605 -- positioned by record representation clauses). In this case we must
8606 -- check for overlap between components of this tagged type, and the
8607 -- components of its parent. Tagged_Parent will point to this parent
8608 -- type. For all other cases Tagged_Parent is left set to Empty.
8610 Parent_Last_Bit : Uint;
8611 -- Relevant only if Tagged_Parent is set, Parent_Last_Bit indicates the
8612 -- last bit position for any field in the parent type. We only need to
8613 -- check overlap for fields starting below this point.
8615 Overlap_Check_Required : Boolean;
8616 -- Used to keep track of whether or not an overlap check is required
8618 Overlap_Detected : Boolean := False;
8619 -- Set True if an overlap is detected
8621 Ccount : Natural := 0;
8622 -- Number of component clauses in record rep clause
8624 procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id);
8625 -- Given two entities for record components or discriminants, checks
8626 -- if they have overlapping component clauses and issues errors if so.
8628 procedure Find_Component;
8629 -- Finds component entity corresponding to current component clause (in
8630 -- CC), and sets Comp to the entity, and Fbit/Lbit to the zero origin
8631 -- start/stop bits for the field. If there is no matching component or
8632 -- if the matching component does not have a component clause, then
8633 -- that's an error and Comp is set to Empty, but no error message is
8634 -- issued, since the message was already given. Comp is also set to
8635 -- Empty if the current "component clause" is in fact a pragma.
8637 -----------------------------
8638 -- Check_Component_Overlap --
8639 -----------------------------
8641 procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id) is
8642 CC1 : constant Node_Id := Component_Clause (C1_Ent);
8643 CC2 : constant Node_Id := Component_Clause (C2_Ent);
8646 if Present (CC1) and then Present (CC2) then
8648 -- Exclude odd case where we have two tag components in the same
8649 -- record, both at location zero. This seems a bit strange, but
8650 -- it seems to happen in some circumstances, perhaps on an error.
8652 if Nam_In (Chars (C1_Ent), Name_uTag, Name_uTag) then
8656 -- Here we check if the two fields overlap
8659 S1 : constant Uint := Component_Bit_Offset (C1_Ent);
8660 S2 : constant Uint := Component_Bit_Offset (C2_Ent);
8661 E1 : constant Uint := S1 + Esize (C1_Ent);
8662 E2 : constant Uint := S2 + Esize (C2_Ent);
8665 if E2 <= S1 or else E1 <= S2 then
8668 Error_Msg_Node_2 := Component_Name (CC2);
8669 Error_Msg_Sloc := Sloc (Error_Msg_Node_2);
8670 Error_Msg_Node_1 := Component_Name (CC1);
8672 ("component& overlaps & #", Component_Name (CC1));
8673 Overlap_Detected := True;
8677 end Check_Component_Overlap;
8679 --------------------
8680 -- Find_Component --
8681 --------------------
8683 procedure Find_Component is
8685 procedure Search_Component (R : Entity_Id);
8686 -- Search components of R for a match. If found, Comp is set
8688 ----------------------
8689 -- Search_Component --
8690 ----------------------
8692 procedure Search_Component (R : Entity_Id) is
8694 Comp := First_Component_Or_Discriminant (R);
8695 while Present (Comp) loop
8697 -- Ignore error of attribute name for component name (we
8698 -- already gave an error message for this, so no need to
8701 if Nkind (Component_Name (CC)) = N_Attribute_Reference then
8704 exit when Chars (Comp) = Chars (Component_Name (CC));
8707 Next_Component_Or_Discriminant (Comp);
8709 end Search_Component;
8711 -- Start of processing for Find_Component
8714 -- Return with Comp set to Empty if we have a pragma
8716 if Nkind (CC) = N_Pragma then
8721 -- Search current record for matching component
8723 Search_Component (Rectype);
8725 -- If not found, maybe component of base type discriminant that is
8726 -- absent from statically constrained first subtype.
8729 Search_Component (Base_Type (Rectype));
8732 -- If no component, or the component does not reference the component
8733 -- clause in question, then there was some previous error for which
8734 -- we already gave a message, so just return with Comp Empty.
8736 if No (Comp) or else Component_Clause (Comp) /= CC then
8737 Check_Error_Detected;
8740 -- Normal case where we have a component clause
8743 Fbit := Component_Bit_Offset (Comp);
8744 Lbit := Fbit + Esize (Comp) - 1;
8748 -- Start of processing for Check_Record_Representation_Clause
8752 Rectype := Entity (Ident);
8754 if Rectype = Any_Type then
8757 Rectype := Underlying_Type (Rectype);
8760 -- See if we have a fully repped derived tagged type
8763 PS : constant Entity_Id := Parent_Subtype (Rectype);
8766 if Present (PS) and then Is_Fully_Repped_Tagged_Type (PS) then
8767 Tagged_Parent := PS;
8769 -- Find maximum bit of any component of the parent type
8771 Parent_Last_Bit := UI_From_Int (System_Address_Size - 1);
8772 Pcomp := First_Entity (Tagged_Parent);
8773 while Present (Pcomp) loop
8774 if Ekind_In (Pcomp, E_Discriminant, E_Component) then
8775 if Component_Bit_Offset (Pcomp) /= No_Uint
8776 and then Known_Static_Esize (Pcomp)
8781 Component_Bit_Offset (Pcomp) + Esize (Pcomp) - 1);
8784 Next_Entity (Pcomp);
8790 -- All done if no component clauses
8792 CC := First (Component_Clauses (N));
8798 -- If a tag is present, then create a component clause that places it
8799 -- at the start of the record (otherwise gigi may place it after other
8800 -- fields that have rep clauses).
8802 Fent := First_Entity (Rectype);
8804 if Nkind (Fent) = N_Defining_Identifier
8805 and then Chars (Fent) = Name_uTag
8807 Set_Component_Bit_Offset (Fent, Uint_0);
8808 Set_Normalized_Position (Fent, Uint_0);
8809 Set_Normalized_First_Bit (Fent, Uint_0);
8810 Set_Normalized_Position_Max (Fent, Uint_0);
8811 Init_Esize (Fent, System_Address_Size);
8813 Set_Component_Clause (Fent,
8814 Make_Component_Clause (Loc,
8815 Component_Name => Make_Identifier (Loc, Name_uTag),
8817 Position => Make_Integer_Literal (Loc, Uint_0),
8818 First_Bit => Make_Integer_Literal (Loc, Uint_0),
8820 Make_Integer_Literal (Loc,
8821 UI_From_Int (System_Address_Size))));
8823 Ccount := Ccount + 1;
8826 Max_Bit_So_Far := Uint_Minus_1;
8827 Overlap_Check_Required := False;
8829 -- Process the component clauses
8831 while Present (CC) loop
8834 if Present (Comp) then
8835 Ccount := Ccount + 1;
8837 -- We need a full overlap check if record positions non-monotonic
8839 if Fbit <= Max_Bit_So_Far then
8840 Overlap_Check_Required := True;
8843 Max_Bit_So_Far := Lbit;
8845 -- Check bit position out of range of specified size
8847 if Has_Size_Clause (Rectype)
8848 and then RM_Size (Rectype) <= Lbit
8851 ("bit number out of range of specified size",
8854 -- Check for overlap with tag component
8857 if Is_Tagged_Type (Rectype)
8858 and then Fbit < System_Address_Size
8861 ("component overlaps tag field of&",
8862 Component_Name (CC), Rectype);
8863 Overlap_Detected := True;
8871 -- Check parent overlap if component might overlap parent field
8873 if Present (Tagged_Parent) and then Fbit <= Parent_Last_Bit then
8874 Pcomp := First_Component_Or_Discriminant (Tagged_Parent);
8875 while Present (Pcomp) loop
8876 if not Is_Tag (Pcomp)
8877 and then Chars (Pcomp) /= Name_uParent
8879 Check_Component_Overlap (Comp, Pcomp);
8882 Next_Component_Or_Discriminant (Pcomp);
8890 -- Now that we have processed all the component clauses, check for
8891 -- overlap. We have to leave this till last, since the components can
8892 -- appear in any arbitrary order in the representation clause.
8894 -- We do not need this check if all specified ranges were monotonic,
8895 -- as recorded by Overlap_Check_Required being False at this stage.
8897 -- This first section checks if there are any overlapping entries at
8898 -- all. It does this by sorting all entries and then seeing if there are
8899 -- any overlaps. If there are none, then that is decisive, but if there
8900 -- are overlaps, they may still be OK (they may result from fields in
8901 -- different variants).
8903 if Overlap_Check_Required then
8904 Overlap_Check1 : declare
8906 OC_Fbit : array (0 .. Ccount) of Uint;
8907 -- First-bit values for component clauses, the value is the offset
8908 -- of the first bit of the field from start of record. The zero
8909 -- entry is for use in sorting.
8911 OC_Lbit : array (0 .. Ccount) of Uint;
8912 -- Last-bit values for component clauses, the value is the offset
8913 -- of the last bit of the field from start of record. The zero
8914 -- entry is for use in sorting.
8916 OC_Count : Natural := 0;
8917 -- Count of entries in OC_Fbit and OC_Lbit
8919 function OC_Lt (Op1, Op2 : Natural) return Boolean;
8920 -- Compare routine for Sort
8922 procedure OC_Move (From : Natural; To : Natural);
8923 -- Move routine for Sort
8925 package Sorting is new GNAT.Heap_Sort_G (OC_Move, OC_Lt);
8931 function OC_Lt (Op1, Op2 : Natural) return Boolean is
8933 return OC_Fbit (Op1) < OC_Fbit (Op2);
8940 procedure OC_Move (From : Natural; To : Natural) is
8942 OC_Fbit (To) := OC_Fbit (From);
8943 OC_Lbit (To) := OC_Lbit (From);
8946 -- Start of processing for Overlap_Check
8949 CC := First (Component_Clauses (N));
8950 while Present (CC) loop
8952 -- Exclude component clause already marked in error
8954 if not Error_Posted (CC) then
8957 if Present (Comp) then
8958 OC_Count := OC_Count + 1;
8959 OC_Fbit (OC_Count) := Fbit;
8960 OC_Lbit (OC_Count) := Lbit;
8967 Sorting.Sort (OC_Count);
8969 Overlap_Check_Required := False;
8970 for J in 1 .. OC_Count - 1 loop
8971 if OC_Lbit (J) >= OC_Fbit (J + 1) then
8972 Overlap_Check_Required := True;
8979 -- If Overlap_Check_Required is still True, then we have to do the full
8980 -- scale overlap check, since we have at least two fields that do
8981 -- overlap, and we need to know if that is OK since they are in
8982 -- different variant, or whether we have a definite problem.
8984 if Overlap_Check_Required then
8985 Overlap_Check2 : declare
8986 C1_Ent, C2_Ent : Entity_Id;
8987 -- Entities of components being checked for overlap
8990 -- Component_List node whose Component_Items are being checked
8993 -- Component declaration for component being checked
8996 C1_Ent := First_Entity (Base_Type (Rectype));
8998 -- Loop through all components in record. For each component check
8999 -- for overlap with any of the preceding elements on the component
9000 -- list containing the component and also, if the component is in
9001 -- a variant, check against components outside the case structure.
9002 -- This latter test is repeated recursively up the variant tree.
9004 Main_Component_Loop : while Present (C1_Ent) loop
9005 if not Ekind_In (C1_Ent, E_Component, E_Discriminant) then
9006 goto Continue_Main_Component_Loop;
9009 -- Skip overlap check if entity has no declaration node. This
9010 -- happens with discriminants in constrained derived types.
9011 -- Possibly we are missing some checks as a result, but that
9012 -- does not seem terribly serious.
9014 if No (Declaration_Node (C1_Ent)) then
9015 goto Continue_Main_Component_Loop;
9018 Clist := Parent (List_Containing (Declaration_Node (C1_Ent)));
9020 -- Loop through component lists that need checking. Check the
9021 -- current component list and all lists in variants above us.
9023 Component_List_Loop : loop
9025 -- If derived type definition, go to full declaration
9026 -- If at outer level, check discriminants if there are any.
9028 if Nkind (Clist) = N_Derived_Type_Definition then
9029 Clist := Parent (Clist);
9032 -- Outer level of record definition, check discriminants
9034 if Nkind_In (Clist, N_Full_Type_Declaration,
9035 N_Private_Type_Declaration)
9037 if Has_Discriminants (Defining_Identifier (Clist)) then
9039 First_Discriminant (Defining_Identifier (Clist));
9040 while Present (C2_Ent) loop
9041 exit when C1_Ent = C2_Ent;
9042 Check_Component_Overlap (C1_Ent, C2_Ent);
9043 Next_Discriminant (C2_Ent);
9047 -- Record extension case
9049 elsif Nkind (Clist) = N_Derived_Type_Definition then
9052 -- Otherwise check one component list
9055 Citem := First (Component_Items (Clist));
9056 while Present (Citem) loop
9057 if Nkind (Citem) = N_Component_Declaration then
9058 C2_Ent := Defining_Identifier (Citem);
9059 exit when C1_Ent = C2_Ent;
9060 Check_Component_Overlap (C1_Ent, C2_Ent);
9067 -- Check for variants above us (the parent of the Clist can
9068 -- be a variant, in which case its parent is a variant part,
9069 -- and the parent of the variant part is a component list
9070 -- whose components must all be checked against the current
9071 -- component for overlap).
9073 if Nkind (Parent (Clist)) = N_Variant then
9074 Clist := Parent (Parent (Parent (Clist)));
9076 -- Check for possible discriminant part in record, this
9077 -- is treated essentially as another level in the
9078 -- recursion. For this case the parent of the component
9079 -- list is the record definition, and its parent is the
9080 -- full type declaration containing the discriminant
9083 elsif Nkind (Parent (Clist)) = N_Record_Definition then
9084 Clist := Parent (Parent ((Clist)));
9086 -- If neither of these two cases, we are at the top of
9090 exit Component_List_Loop;
9092 end loop Component_List_Loop;
9094 <<Continue_Main_Component_Loop>>
9095 Next_Entity (C1_Ent);
9097 end loop Main_Component_Loop;
9101 -- The following circuit deals with warning on record holes (gaps). We
9102 -- skip this check if overlap was detected, since it makes sense for the
9103 -- programmer to fix this illegality before worrying about warnings.
9105 if not Overlap_Detected and Warn_On_Record_Holes then
9106 Record_Hole_Check : declare
9107 Decl : constant Node_Id := Declaration_Node (Base_Type (Rectype));
9108 -- Full declaration of record type
9110 procedure Check_Component_List
9114 -- Check component list CL for holes. The starting bit should be
9115 -- Sbit. which is zero for the main record component list and set
9116 -- appropriately for recursive calls for variants. DS is set to
9117 -- a list of discriminant specifications to be included in the
9118 -- consideration of components. It is No_List if none to consider.
9120 --------------------------
9121 -- Check_Component_List --
9122 --------------------------
9124 procedure Check_Component_List
9132 Compl := Integer (List_Length (Component_Items (CL)));
9134 if DS /= No_List then
9135 Compl := Compl + Integer (List_Length (DS));
9139 Comps : array (Natural range 0 .. Compl) of Entity_Id;
9140 -- Gather components (zero entry is for sort routine)
9142 Ncomps : Natural := 0;
9143 -- Number of entries stored in Comps (starting at Comps (1))
9146 -- One component item or discriminant specification
9149 -- Starting bit for next component
9157 function Lt (Op1, Op2 : Natural) return Boolean;
9158 -- Compare routine for Sort
9160 procedure Move (From : Natural; To : Natural);
9161 -- Move routine for Sort
9163 package Sorting is new GNAT.Heap_Sort_G (Move, Lt);
9169 function Lt (Op1, Op2 : Natural) return Boolean is
9171 return Component_Bit_Offset (Comps (Op1))
9173 Component_Bit_Offset (Comps (Op2));
9180 procedure Move (From : Natural; To : Natural) is
9182 Comps (To) := Comps (From);
9186 -- Gather discriminants into Comp
9188 if DS /= No_List then
9189 Citem := First (DS);
9190 while Present (Citem) loop
9191 if Nkind (Citem) = N_Discriminant_Specification then
9193 Ent : constant Entity_Id :=
9194 Defining_Identifier (Citem);
9196 if Ekind (Ent) = E_Discriminant then
9197 Ncomps := Ncomps + 1;
9198 Comps (Ncomps) := Ent;
9207 -- Gather component entities into Comp
9209 Citem := First (Component_Items (CL));
9210 while Present (Citem) loop
9211 if Nkind (Citem) = N_Component_Declaration then
9212 Ncomps := Ncomps + 1;
9213 Comps (Ncomps) := Defining_Identifier (Citem);
9219 -- Now sort the component entities based on the first bit.
9220 -- Note we already know there are no overlapping components.
9222 Sorting.Sort (Ncomps);
9224 -- Loop through entries checking for holes
9227 for J in 1 .. Ncomps loop
9229 Error_Msg_Uint_1 := Component_Bit_Offset (CEnt) - Nbit;
9231 if Error_Msg_Uint_1 > 0 then
9233 ("?H?^-bit gap before component&",
9234 Component_Name (Component_Clause (CEnt)), CEnt);
9237 Nbit := Component_Bit_Offset (CEnt) + Esize (CEnt);
9240 -- Process variant parts recursively if present
9242 if Present (Variant_Part (CL)) then
9243 Variant := First (Variants (Variant_Part (CL)));
9244 while Present (Variant) loop
9245 Check_Component_List
9246 (Component_List (Variant), Nbit, No_List);
9251 end Check_Component_List;
9253 -- Start of processing for Record_Hole_Check
9260 if Is_Tagged_Type (Rectype) then
9261 Sbit := UI_From_Int (System_Address_Size);
9266 if Nkind (Decl) = N_Full_Type_Declaration
9267 and then Nkind (Type_Definition (Decl)) = N_Record_Definition
9269 Check_Component_List
9270 (Component_List (Type_Definition (Decl)),
9272 Discriminant_Specifications (Decl));
9275 end Record_Hole_Check;
9278 -- For records that have component clauses for all components, and whose
9279 -- size is less than or equal to 32, we need to know the size in the
9280 -- front end to activate possible packed array processing where the
9281 -- component type is a record.
9283 -- At this stage Hbit + 1 represents the first unused bit from all the
9284 -- component clauses processed, so if the component clauses are
9285 -- complete, then this is the length of the record.
9287 -- For records longer than System.Storage_Unit, and for those where not
9288 -- all components have component clauses, the back end determines the
9289 -- length (it may for example be appropriate to round up the size
9290 -- to some convenient boundary, based on alignment considerations, etc).
9292 if Unknown_RM_Size (Rectype) and then Hbit + 1 <= 32 then
9294 -- Nothing to do if at least one component has no component clause
9296 Comp := First_Component_Or_Discriminant (Rectype);
9297 while Present (Comp) loop
9298 exit when No (Component_Clause (Comp));
9299 Next_Component_Or_Discriminant (Comp);
9302 -- If we fall out of loop, all components have component clauses
9303 -- and so we can set the size to the maximum value.
9306 Set_RM_Size (Rectype, Hbit + 1);
9309 end Check_Record_Representation_Clause;
9315 procedure Check_Size
9319 Biased : out Boolean)
9321 UT : constant Entity_Id := Underlying_Type (T);
9327 -- Reject patently improper size values.
9329 if Is_Elementary_Type (T)
9330 and then Siz > UI_From_Int (Int'Last)
9332 Error_Msg_N ("Size value too large for elementary type", N);
9334 if Nkind (Original_Node (N)) = N_Op_Expon then
9336 ("\maybe '* was meant, rather than '*'*", Original_Node (N));
9340 -- Dismiss generic types
9342 if Is_Generic_Type (T)
9344 Is_Generic_Type (UT)
9346 Is_Generic_Type (Root_Type (UT))
9350 -- Guard against previous errors
9352 elsif No (UT) or else UT = Any_Type then
9353 Check_Error_Detected;
9356 -- Check case of bit packed array
9358 elsif Is_Array_Type (UT)
9359 and then Known_Static_Component_Size (UT)
9360 and then Is_Bit_Packed_Array (UT)
9368 Asiz := Component_Size (UT);
9369 Indx := First_Index (UT);
9371 Ityp := Etype (Indx);
9373 -- If non-static bound, then we are not in the business of
9374 -- trying to check the length, and indeed an error will be
9375 -- issued elsewhere, since sizes of non-static array types
9376 -- cannot be set implicitly or explicitly.
9378 if not Is_Static_Subtype (Ityp) then
9382 -- Otherwise accumulate next dimension
9384 Asiz := Asiz * (Expr_Value (Type_High_Bound (Ityp)) -
9385 Expr_Value (Type_Low_Bound (Ityp)) +
9389 exit when No (Indx);
9396 Error_Msg_Uint_1 := Asiz;
9398 ("size for& too small, minimum allowed is ^", N, T);
9399 Set_Esize (T, Asiz);
9400 Set_RM_Size (T, Asiz);
9404 -- All other composite types are ignored
9406 elsif Is_Composite_Type (UT) then
9409 -- For fixed-point types, don't check minimum if type is not frozen,
9410 -- since we don't know all the characteristics of the type that can
9411 -- affect the size (e.g. a specified small) till freeze time.
9413 elsif Is_Fixed_Point_Type (UT)
9414 and then not Is_Frozen (UT)
9418 -- Cases for which a minimum check is required
9421 -- Ignore if specified size is correct for the type
9423 if Known_Esize (UT) and then Siz = Esize (UT) then
9427 -- Otherwise get minimum size
9429 M := UI_From_Int (Minimum_Size (UT));
9433 -- Size is less than minimum size, but one possibility remains
9434 -- that we can manage with the new size if we bias the type.
9436 M := UI_From_Int (Minimum_Size (UT, Biased => True));
9439 Error_Msg_Uint_1 := M;
9441 ("size for& too small, minimum allowed is ^", N, T);
9451 --------------------------
9452 -- Freeze_Entity_Checks --
9453 --------------------------
9455 procedure Freeze_Entity_Checks (N : Node_Id) is
9456 E : constant Entity_Id := Entity (N);
9458 Non_Generic_Case : constant Boolean := Nkind (N) = N_Freeze_Entity;
9459 -- True in non-generic case. Some of the processing here is skipped
9460 -- for the generic case since it is not needed. Basically in the
9461 -- generic case, we only need to do stuff that might generate error
9462 -- messages or warnings.
9464 -- Remember that we are processing a freezing entity. Required to
9465 -- ensure correct decoration of internal entities associated with
9466 -- interfaces (see New_Overloaded_Entity).
9468 Inside_Freezing_Actions := Inside_Freezing_Actions + 1;
9470 -- For tagged types covering interfaces add internal entities that link
9471 -- the primitives of the interfaces with the primitives that cover them.
9472 -- Note: These entities were originally generated only when generating
9473 -- code because their main purpose was to provide support to initialize
9474 -- the secondary dispatch tables. They are now generated also when
9475 -- compiling with no code generation to provide ASIS the relationship
9476 -- between interface primitives and tagged type primitives. They are
9477 -- also used to locate primitives covering interfaces when processing
9478 -- generics (see Derive_Subprograms).
9480 -- This is not needed in the generic case
9482 if Ada_Version >= Ada_2005
9483 and then Non_Generic_Case
9484 and then Ekind (E) = E_Record_Type
9485 and then Is_Tagged_Type (E)
9486 and then not Is_Interface (E)
9487 and then Has_Interfaces (E)
9489 -- This would be a good common place to call the routine that checks
9490 -- overriding of interface primitives (and thus factorize calls to
9491 -- Check_Abstract_Overriding located at different contexts in the
9492 -- compiler). However, this is not possible because it causes
9493 -- spurious errors in case of late overriding.
9495 Add_Internal_Interface_Entities (E);
9500 if Ekind (E) = E_Record_Type
9501 and then Is_CPP_Class (E)
9502 and then Is_Tagged_Type (E)
9503 and then Tagged_Type_Expansion
9505 if CPP_Num_Prims (E) = 0 then
9507 -- If the CPP type has user defined components then it must import
9508 -- primitives from C++. This is required because if the C++ class
9509 -- has no primitives then the C++ compiler does not added the _tag
9510 -- component to the type.
9512 if First_Entity (E) /= Last_Entity (E) then
9514 ("'C'P'P type must import at least one primitive from C++??",
9519 -- Check that all its primitives are abstract or imported from C++.
9520 -- Check also availability of the C++ constructor.
9523 Has_Constructors : constant Boolean := Has_CPP_Constructors (E);
9525 Error_Reported : Boolean := False;
9529 Elmt := First_Elmt (Primitive_Operations (E));
9530 while Present (Elmt) loop
9531 Prim := Node (Elmt);
9533 if Comes_From_Source (Prim) then
9534 if Is_Abstract_Subprogram (Prim) then
9537 elsif not Is_Imported (Prim)
9538 or else Convention (Prim) /= Convention_CPP
9541 ("primitives of 'C'P'P types must be imported from C++ "
9542 & "or abstract??", Prim);
9544 elsif not Has_Constructors
9545 and then not Error_Reported
9547 Error_Msg_Name_1 := Chars (E);
9549 ("??'C'P'P constructor required for type %", Prim);
9550 Error_Reported := True;
9559 -- Check Ada derivation of CPP type
9561 if Expander_Active -- why? losing errors in -gnatc mode???
9562 and then Tagged_Type_Expansion
9563 and then Ekind (E) = E_Record_Type
9564 and then Etype (E) /= E
9565 and then Is_CPP_Class (Etype (E))
9566 and then CPP_Num_Prims (Etype (E)) > 0
9567 and then not Is_CPP_Class (E)
9568 and then not Has_CPP_Constructors (Etype (E))
9570 -- If the parent has C++ primitives but it has no constructor then
9571 -- check that all the primitives are overridden in this derivation;
9572 -- otherwise the constructor of the parent is needed to build the
9580 Elmt := First_Elmt (Primitive_Operations (E));
9581 while Present (Elmt) loop
9582 Prim := Node (Elmt);
9584 if not Is_Abstract_Subprogram (Prim)
9585 and then No (Interface_Alias (Prim))
9586 and then Find_Dispatching_Type (Ultimate_Alias (Prim)) /= E
9588 Error_Msg_Name_1 := Chars (Etype (E));
9590 ("'C'P'P constructor required for parent type %", E);
9599 Inside_Freezing_Actions := Inside_Freezing_Actions - 1;
9601 -- If we have a type with predicates, build predicate function. This
9602 -- is not needed in the generic case, and is not needed within TSS
9603 -- subprograms and other predefined primitives.
9606 and then Is_Type (E)
9607 and then Has_Predicates (E)
9608 and then not Within_Internal_Subprogram
9610 Build_Predicate_Functions (E, N);
9613 -- If type has delayed aspects, this is where we do the preanalysis at
9614 -- the freeze point, as part of the consistent visibility check. Note
9615 -- that this must be done after calling Build_Predicate_Functions or
9616 -- Build_Invariant_Procedure since these subprograms fix occurrences of
9617 -- the subtype name in the saved expression so that they will not cause
9618 -- trouble in the preanalysis.
9620 -- This is also not needed in the generic case
9623 and then Has_Delayed_Aspects (E)
9624 and then Scope (E) = Current_Scope
9626 -- Retrieve the visibility to the discriminants in order to properly
9627 -- analyze the aspects.
9629 Push_Scope_And_Install_Discriminants (E);
9635 -- Look for aspect specification entries for this entity
9637 Ritem := First_Rep_Item (E);
9638 while Present (Ritem) loop
9639 if Nkind (Ritem) = N_Aspect_Specification
9640 and then Entity (Ritem) = E
9641 and then Is_Delayed_Aspect (Ritem)
9643 Check_Aspect_At_Freeze_Point (Ritem);
9646 Next_Rep_Item (Ritem);
9650 Uninstall_Discriminants_And_Pop_Scope (E);
9653 -- For a record type, deal with variant parts. This has to be delayed
9654 -- to this point, because of the issue of statically precicated
9655 -- subtypes, which we have to ensure are frozen before checking
9656 -- choices, since we need to have the static choice list set.
9658 if Is_Record_Type (E) then
9659 Check_Variant_Part : declare
9660 D : constant Node_Id := Declaration_Node (E);
9665 Others_Present : Boolean;
9666 pragma Warnings (Off, Others_Present);
9667 -- Indicates others present, not used in this case
9669 procedure Non_Static_Choice_Error (Choice : Node_Id);
9670 -- Error routine invoked by the generic instantiation below when
9671 -- the variant part has a non static choice.
9673 procedure Process_Declarations (Variant : Node_Id);
9674 -- Processes declarations associated with a variant. We analyzed
9675 -- the declarations earlier (in Sem_Ch3.Analyze_Variant_Part),
9676 -- but we still need the recursive call to Check_Choices for any
9677 -- nested variant to get its choices properly processed. This is
9678 -- also where we expand out the choices if expansion is active.
9680 package Variant_Choices_Processing is new
9681 Generic_Check_Choices
9682 (Process_Empty_Choice => No_OP,
9683 Process_Non_Static_Choice => Non_Static_Choice_Error,
9684 Process_Associated_Node => Process_Declarations);
9685 use Variant_Choices_Processing;
9687 -----------------------------
9688 -- Non_Static_Choice_Error --
9689 -----------------------------
9691 procedure Non_Static_Choice_Error (Choice : Node_Id) is
9693 Flag_Non_Static_Expr
9694 ("choice given in variant part is not static!", Choice);
9695 end Non_Static_Choice_Error;
9697 --------------------------
9698 -- Process_Declarations --
9699 --------------------------
9701 procedure Process_Declarations (Variant : Node_Id) is
9702 CL : constant Node_Id := Component_List (Variant);
9706 -- Check for static predicate present in this variant
9708 if Has_SP_Choice (Variant) then
9710 -- Here we expand. You might expect to find this call in
9711 -- Expand_N_Variant_Part, but that is called when we first
9712 -- see the variant part, and we cannot do this expansion
9713 -- earlier than the freeze point, since for statically
9714 -- predicated subtypes, the predicate is not known till
9715 -- the freeze point.
9717 -- Furthermore, we do this expansion even if the expander
9718 -- is not active, because other semantic processing, e.g.
9719 -- for aggregates, requires the expanded list of choices.
9721 -- If the expander is not active, then we can't just clobber
9722 -- the list since it would invalidate the ASIS -gnatct tree.
9723 -- So we have to rewrite the variant part with a Rewrite
9724 -- call that replaces it with a copy and clobber the copy.
9726 if not Expander_Active then
9728 NewV : constant Node_Id := New_Copy (Variant);
9730 Set_Discrete_Choices
9731 (NewV, New_Copy_List (Discrete_Choices (Variant)));
9732 Rewrite (Variant, NewV);
9736 Expand_Static_Predicates_In_Choices (Variant);
9739 -- We don't need to worry about the declarations in the variant
9740 -- (since they were analyzed by Analyze_Choices when we first
9741 -- encountered the variant), but we do need to take care of
9742 -- expansion of any nested variants.
9744 if not Null_Present (CL) then
9745 VP := Variant_Part (CL);
9747 if Present (VP) then
9749 (VP, Variants (VP), Etype (Name (VP)), Others_Present);
9752 end Process_Declarations;
9754 -- Start of processing for Check_Variant_Part
9757 -- Find component list
9761 if Nkind (D) = N_Full_Type_Declaration then
9762 T := Type_Definition (D);
9764 if Nkind (T) = N_Record_Definition then
9765 C := Component_List (T);
9767 elsif Nkind (T) = N_Derived_Type_Definition
9768 and then Present (Record_Extension_Part (T))
9770 C := Component_List (Record_Extension_Part (T));
9774 -- Case of variant part present
9776 if Present (C) and then Present (Variant_Part (C)) then
9777 VP := Variant_Part (C);
9782 (VP, Variants (VP), Etype (Name (VP)), Others_Present);
9784 -- If the last variant does not contain the Others choice,
9785 -- replace it with an N_Others_Choice node since Gigi always
9786 -- wants an Others. Note that we do not bother to call Analyze
9787 -- on the modified variant part, since its only effect would be
9788 -- to compute the Others_Discrete_Choices node laboriously, and
9789 -- of course we already know the list of choices corresponding
9790 -- to the others choice (it's the list we're replacing).
9792 -- We only want to do this if the expander is active, since
9793 -- we do not want to clobber the ASIS tree.
9795 if Expander_Active then
9797 Last_Var : constant Node_Id :=
9798 Last_Non_Pragma (Variants (VP));
9800 Others_Node : Node_Id;
9803 if Nkind (First (Discrete_Choices (Last_Var))) /=
9806 Others_Node := Make_Others_Choice (Sloc (Last_Var));
9807 Set_Others_Discrete_Choices
9808 (Others_Node, Discrete_Choices (Last_Var));
9809 Set_Discrete_Choices
9810 (Last_Var, New_List (Others_Node));
9815 end Check_Variant_Part;
9817 end Freeze_Entity_Checks;
9819 -------------------------
9820 -- Get_Alignment_Value --
9821 -------------------------
9823 function Get_Alignment_Value (Expr : Node_Id) return Uint is
9824 Align : constant Uint := Static_Integer (Expr);
9827 if Align = No_Uint then
9830 elsif Align <= 0 then
9831 Error_Msg_N ("alignment value must be positive", Expr);
9835 for J in Int range 0 .. 64 loop
9837 M : constant Uint := Uint_2 ** J;
9840 exit when M = Align;
9844 ("alignment value must be power of 2", Expr);
9852 end Get_Alignment_Value;
9854 -------------------------------------
9855 -- Inherit_Aspects_At_Freeze_Point --
9856 -------------------------------------
9858 procedure Inherit_Aspects_At_Freeze_Point (Typ : Entity_Id) is
9859 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9860 (Rep_Item : Node_Id) return Boolean;
9861 -- This routine checks if Rep_Item is either a pragma or an aspect
9862 -- specification node whose correponding pragma (if any) is present in
9863 -- the Rep Item chain of the entity it has been specified to.
9865 --------------------------------------------------
9866 -- Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item --
9867 --------------------------------------------------
9869 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9870 (Rep_Item : Node_Id) return Boolean
9873 return Nkind (Rep_Item) = N_Pragma
9874 or else Present_In_Rep_Item
9875 (Entity (Rep_Item), Aspect_Rep_Item (Rep_Item));
9876 end Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item;
9878 -- Start of processing for Inherit_Aspects_At_Freeze_Point
9881 -- A representation item is either subtype-specific (Size and Alignment
9882 -- clauses) or type-related (all others). Subtype-specific aspects may
9883 -- differ for different subtypes of the same type (RM 13.1.8).
9885 -- A derived type inherits each type-related representation aspect of
9886 -- its parent type that was directly specified before the declaration of
9887 -- the derived type (RM 13.1.15).
9889 -- A derived subtype inherits each subtype-specific representation
9890 -- aspect of its parent subtype that was directly specified before the
9891 -- declaration of the derived type (RM 13.1.15).
9893 -- The general processing involves inheriting a representation aspect
9894 -- from a parent type whenever the first rep item (aspect specification,
9895 -- attribute definition clause, pragma) corresponding to the given
9896 -- representation aspect in the rep item chain of Typ, if any, isn't
9897 -- directly specified to Typ but to one of its parents.
9899 -- ??? Note that, for now, just a limited number of representation
9900 -- aspects have been inherited here so far. Many of them are
9901 -- still inherited in Sem_Ch3. This will be fixed soon. Here is
9902 -- a non- exhaustive list of aspects that likely also need to
9903 -- be moved to this routine: Alignment, Component_Alignment,
9904 -- Component_Size, Machine_Radix, Object_Size, Pack, Predicates,
9905 -- Preelaborable_Initialization, RM_Size and Small.
9907 if Nkind (Parent (Typ)) = N_Private_Extension_Declaration then
9913 if not Has_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005, False)
9914 and then Has_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005)
9915 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9916 (Get_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005))
9918 Set_Is_Ada_2005_Only (Typ);
9923 if not Has_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012, False)
9924 and then Has_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012)
9925 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9926 (Get_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012))
9928 Set_Is_Ada_2012_Only (Typ);
9933 if not Has_Rep_Item (Typ, Name_Atomic, Name_Shared, False)
9934 and then Has_Rep_Pragma (Typ, Name_Atomic, Name_Shared)
9935 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9936 (Get_Rep_Item (Typ, Name_Atomic, Name_Shared))
9938 Set_Is_Atomic (Typ);
9939 Set_Treat_As_Volatile (Typ);
9940 Set_Is_Volatile (Typ);
9943 -- Default_Component_Value
9945 if Is_Array_Type (Typ)
9946 and then Is_Base_Type (Typ)
9947 and then Has_Rep_Item (Typ, Name_Default_Component_Value, False)
9948 and then Has_Rep_Item (Typ, Name_Default_Component_Value)
9950 Set_Default_Aspect_Component_Value (Typ,
9951 Default_Aspect_Component_Value
9952 (Entity (Get_Rep_Item (Typ, Name_Default_Component_Value))));
9957 if Is_Scalar_Type (Typ)
9958 and then Is_Base_Type (Typ)
9959 and then Has_Rep_Item (Typ, Name_Default_Value, False)
9960 and then Has_Rep_Item (Typ, Name_Default_Value)
9962 Set_Default_Aspect_Value (Typ,
9963 Default_Aspect_Value
9964 (Entity (Get_Rep_Item (Typ, Name_Default_Value))));
9969 if not Has_Rep_Item (Typ, Name_Discard_Names, False)
9970 and then Has_Rep_Item (Typ, Name_Discard_Names)
9971 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9972 (Get_Rep_Item (Typ, Name_Discard_Names))
9974 Set_Discard_Names (Typ);
9979 if not Has_Rep_Item (Typ, Name_Invariant, False)
9980 and then Has_Rep_Item (Typ, Name_Invariant)
9981 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9982 (Get_Rep_Item (Typ, Name_Invariant))
9984 Set_Has_Invariants (Typ);
9986 if Class_Present (Get_Rep_Item (Typ, Name_Invariant)) then
9987 Set_Has_Inheritable_Invariants (Typ);
9993 if not Has_Rep_Item (Typ, Name_Volatile, False)
9994 and then Has_Rep_Item (Typ, Name_Volatile)
9995 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9996 (Get_Rep_Item (Typ, Name_Volatile))
9998 Set_Treat_As_Volatile (Typ);
9999 Set_Is_Volatile (Typ);
10002 -- Inheritance for derived types only
10004 if Is_Derived_Type (Typ) then
10006 Bas_Typ : constant Entity_Id := Base_Type (Typ);
10007 Imp_Bas_Typ : constant Entity_Id := Implementation_Base_Type (Typ);
10010 -- Atomic_Components
10012 if not Has_Rep_Item (Typ, Name_Atomic_Components, False)
10013 and then Has_Rep_Item (Typ, Name_Atomic_Components)
10014 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
10015 (Get_Rep_Item (Typ, Name_Atomic_Components))
10017 Set_Has_Atomic_Components (Imp_Bas_Typ);
10020 -- Volatile_Components
10022 if not Has_Rep_Item (Typ, Name_Volatile_Components, False)
10023 and then Has_Rep_Item (Typ, Name_Volatile_Components)
10024 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
10025 (Get_Rep_Item (Typ, Name_Volatile_Components))
10027 Set_Has_Volatile_Components (Imp_Bas_Typ);
10030 -- Finalize_Storage_Only.
10032 if not Has_Rep_Pragma (Typ, Name_Finalize_Storage_Only, False)
10033 and then Has_Rep_Pragma (Typ, Name_Finalize_Storage_Only)
10035 Set_Finalize_Storage_Only (Bas_Typ);
10038 -- Universal_Aliasing
10040 if not Has_Rep_Item (Typ, Name_Universal_Aliasing, False)
10041 and then Has_Rep_Item (Typ, Name_Universal_Aliasing)
10042 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
10043 (Get_Rep_Item (Typ, Name_Universal_Aliasing))
10045 Set_Universal_Aliasing (Imp_Bas_Typ);
10048 -- Record type specific aspects
10050 if Is_Record_Type (Typ) then
10054 if not Has_Rep_Item (Typ, Name_Bit_Order, False)
10055 and then Has_Rep_Item (Typ, Name_Bit_Order)
10057 Set_Reverse_Bit_Order (Bas_Typ,
10058 Reverse_Bit_Order (Entity (Name
10059 (Get_Rep_Item (Typ, Name_Bit_Order)))));
10062 -- Scalar_Storage_Order
10064 if not Has_Rep_Item (Typ, Name_Scalar_Storage_Order, False)
10065 and then Has_Rep_Item (Typ, Name_Scalar_Storage_Order)
10067 Set_Reverse_Storage_Order (Bas_Typ,
10068 Reverse_Storage_Order (Entity (Name
10069 (Get_Rep_Item (Typ, Name_Scalar_Storage_Order)))));
10074 end Inherit_Aspects_At_Freeze_Point;
10080 procedure Initialize is
10082 Address_Clause_Checks.Init;
10083 Independence_Checks.Init;
10084 Unchecked_Conversions.Init;
10087 ---------------------------
10088 -- Install_Discriminants --
10089 ---------------------------
10091 procedure Install_Discriminants (E : Entity_Id) is
10095 Disc := First_Discriminant (E);
10096 while Present (Disc) loop
10097 Prev := Current_Entity (Disc);
10098 Set_Current_Entity (Disc);
10099 Set_Is_Immediately_Visible (Disc);
10100 Set_Homonym (Disc, Prev);
10101 Next_Discriminant (Disc);
10103 end Install_Discriminants;
10105 -------------------------
10106 -- Is_Operational_Item --
10107 -------------------------
10109 function Is_Operational_Item (N : Node_Id) return Boolean is
10111 if Nkind (N) /= N_Attribute_Definition_Clause then
10116 Id : constant Attribute_Id := Get_Attribute_Id (Chars (N));
10118 return Id = Attribute_Input
10119 or else Id = Attribute_Output
10120 or else Id = Attribute_Read
10121 or else Id = Attribute_Write
10122 or else Id = Attribute_External_Tag;
10125 end Is_Operational_Item;
10131 function Minimum_Size
10133 Biased : Boolean := False) return Nat
10135 Lo : Uint := No_Uint;
10136 Hi : Uint := No_Uint;
10137 LoR : Ureal := No_Ureal;
10138 HiR : Ureal := No_Ureal;
10139 LoSet : Boolean := False;
10140 HiSet : Boolean := False;
10143 Ancest : Entity_Id;
10144 R_Typ : constant Entity_Id := Root_Type (T);
10147 -- If bad type, return 0
10149 if T = Any_Type then
10152 -- For generic types, just return zero. There cannot be any legitimate
10153 -- need to know such a size, but this routine may be called with a
10154 -- generic type as part of normal processing.
10156 elsif Is_Generic_Type (R_Typ)
10157 or else R_Typ = Any_Type
10161 -- Access types. Normally an access type cannot have a size smaller
10162 -- than the size of System.Address. The exception is on VMS, where
10163 -- we have short and long addresses, and it is possible for an access
10164 -- type to have a short address size (and thus be less than the size
10165 -- of System.Address itself). We simply skip the check for VMS, and
10166 -- leave it to the back end to do the check.
10168 elsif Is_Access_Type (T) then
10169 if OpenVMS_On_Target then
10172 return System_Address_Size;
10175 -- Floating-point types
10177 elsif Is_Floating_Point_Type (T) then
10178 return UI_To_Int (Esize (R_Typ));
10182 elsif Is_Discrete_Type (T) then
10184 -- The following loop is looking for the nearest compile time known
10185 -- bounds following the ancestor subtype chain. The idea is to find
10186 -- the most restrictive known bounds information.
10190 if Ancest = Any_Type or else Etype (Ancest) = Any_Type then
10195 if Compile_Time_Known_Value (Type_Low_Bound (Ancest)) then
10196 Lo := Expr_Rep_Value (Type_Low_Bound (Ancest));
10203 if Compile_Time_Known_Value (Type_High_Bound (Ancest)) then
10204 Hi := Expr_Rep_Value (Type_High_Bound (Ancest));
10210 Ancest := Ancestor_Subtype (Ancest);
10212 if No (Ancest) then
10213 Ancest := Base_Type (T);
10215 if Is_Generic_Type (Ancest) then
10221 -- Fixed-point types. We can't simply use Expr_Value to get the
10222 -- Corresponding_Integer_Value values of the bounds, since these do not
10223 -- get set till the type is frozen, and this routine can be called
10224 -- before the type is frozen. Similarly the test for bounds being static
10225 -- needs to include the case where we have unanalyzed real literals for
10226 -- the same reason.
10228 elsif Is_Fixed_Point_Type (T) then
10230 -- The following loop is looking for the nearest compile time known
10231 -- bounds following the ancestor subtype chain. The idea is to find
10232 -- the most restrictive known bounds information.
10236 if Ancest = Any_Type or else Etype (Ancest) = Any_Type then
10240 -- Note: In the following two tests for LoSet and HiSet, it may
10241 -- seem redundant to test for N_Real_Literal here since normally
10242 -- one would assume that the test for the value being known at
10243 -- compile time includes this case. However, there is a glitch.
10244 -- If the real literal comes from folding a non-static expression,
10245 -- then we don't consider any non- static expression to be known
10246 -- at compile time if we are in configurable run time mode (needed
10247 -- in some cases to give a clearer definition of what is and what
10248 -- is not accepted). So the test is indeed needed. Without it, we
10249 -- would set neither Lo_Set nor Hi_Set and get an infinite loop.
10252 if Nkind (Type_Low_Bound (Ancest)) = N_Real_Literal
10253 or else Compile_Time_Known_Value (Type_Low_Bound (Ancest))
10255 LoR := Expr_Value_R (Type_Low_Bound (Ancest));
10262 if Nkind (Type_High_Bound (Ancest)) = N_Real_Literal
10263 or else Compile_Time_Known_Value (Type_High_Bound (Ancest))
10265 HiR := Expr_Value_R (Type_High_Bound (Ancest));
10271 Ancest := Ancestor_Subtype (Ancest);
10273 if No (Ancest) then
10274 Ancest := Base_Type (T);
10276 if Is_Generic_Type (Ancest) then
10282 Lo := UR_To_Uint (LoR / Small_Value (T));
10283 Hi := UR_To_Uint (HiR / Small_Value (T));
10285 -- No other types allowed
10288 raise Program_Error;
10291 -- Fall through with Hi and Lo set. Deal with biased case
10294 and then not Is_Fixed_Point_Type (T)
10295 and then not (Is_Enumeration_Type (T)
10296 and then Has_Non_Standard_Rep (T)))
10297 or else Has_Biased_Representation (T)
10303 -- Signed case. Note that we consider types like range 1 .. -1 to be
10304 -- signed for the purpose of computing the size, since the bounds have
10305 -- to be accommodated in the base type.
10307 if Lo < 0 or else Hi < 0 then
10311 -- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1))
10312 -- Note that we accommodate the case where the bounds cross. This
10313 -- can happen either because of the way the bounds are declared
10314 -- or because of the algorithm in Freeze_Fixed_Point_Type.
10328 -- If both bounds are positive, make sure that both are represen-
10329 -- table in the case where the bounds are crossed. This can happen
10330 -- either because of the way the bounds are declared, or because of
10331 -- the algorithm in Freeze_Fixed_Point_Type.
10337 -- S = size, (can accommodate 0 .. (2**size - 1))
10340 while Hi >= Uint_2 ** S loop
10348 ---------------------------
10349 -- New_Stream_Subprogram --
10350 ---------------------------
10352 procedure New_Stream_Subprogram
10356 Nam : TSS_Name_Type)
10358 Loc : constant Source_Ptr := Sloc (N);
10359 Sname : constant Name_Id := Make_TSS_Name (Base_Type (Ent), Nam);
10360 Subp_Id : Entity_Id;
10361 Subp_Decl : Node_Id;
10365 Defer_Declaration : constant Boolean :=
10366 Is_Tagged_Type (Ent) or else Is_Private_Type (Ent);
10367 -- For a tagged type, there is a declaration for each stream attribute
10368 -- at the freeze point, and we must generate only a completion of this
10369 -- declaration. We do the same for private types, because the full view
10370 -- might be tagged. Otherwise we generate a declaration at the point of
10371 -- the attribute definition clause.
10373 function Build_Spec return Node_Id;
10374 -- Used for declaration and renaming declaration, so that this is
10375 -- treated as a renaming_as_body.
10381 function Build_Spec return Node_Id is
10382 Out_P : constant Boolean := (Nam = TSS_Stream_Read);
10385 T_Ref : constant Node_Id := New_Occurrence_Of (Etyp, Loc);
10388 Subp_Id := Make_Defining_Identifier (Loc, Sname);
10390 -- S : access Root_Stream_Type'Class
10392 Formals := New_List (
10393 Make_Parameter_Specification (Loc,
10394 Defining_Identifier =>
10395 Make_Defining_Identifier (Loc, Name_S),
10397 Make_Access_Definition (Loc,
10399 New_Occurrence_Of (
10400 Designated_Type (Etype (F)), Loc))));
10402 if Nam = TSS_Stream_Input then
10404 Make_Function_Specification (Loc,
10405 Defining_Unit_Name => Subp_Id,
10406 Parameter_Specifications => Formals,
10407 Result_Definition => T_Ref);
10411 Append_To (Formals,
10412 Make_Parameter_Specification (Loc,
10413 Defining_Identifier => Make_Defining_Identifier (Loc, Name_V),
10414 Out_Present => Out_P,
10415 Parameter_Type => T_Ref));
10418 Make_Procedure_Specification (Loc,
10419 Defining_Unit_Name => Subp_Id,
10420 Parameter_Specifications => Formals);
10426 -- Start of processing for New_Stream_Subprogram
10429 F := First_Formal (Subp);
10431 if Ekind (Subp) = E_Procedure then
10432 Etyp := Etype (Next_Formal (F));
10434 Etyp := Etype (Subp);
10437 -- Prepare subprogram declaration and insert it as an action on the
10438 -- clause node. The visibility for this entity is used to test for
10439 -- visibility of the attribute definition clause (in the sense of
10440 -- 8.3(23) as amended by AI-195).
10442 if not Defer_Declaration then
10444 Make_Subprogram_Declaration (Loc,
10445 Specification => Build_Spec);
10447 -- For a tagged type, there is always a visible declaration for each
10448 -- stream TSS (it is a predefined primitive operation), and the
10449 -- completion of this declaration occurs at the freeze point, which is
10450 -- not always visible at places where the attribute definition clause is
10451 -- visible. So, we create a dummy entity here for the purpose of
10452 -- tracking the visibility of the attribute definition clause itself.
10456 Make_Defining_Identifier (Loc, New_External_Name (Sname, 'V'));
10458 Make_Object_Declaration (Loc,
10459 Defining_Identifier => Subp_Id,
10460 Object_Definition => New_Occurrence_Of (Standard_Boolean, Loc));
10463 Insert_Action (N, Subp_Decl);
10464 Set_Entity (N, Subp_Id);
10467 Make_Subprogram_Renaming_Declaration (Loc,
10468 Specification => Build_Spec,
10469 Name => New_Occurrence_Of (Subp, Loc));
10471 if Defer_Declaration then
10472 Set_TSS (Base_Type (Ent), Subp_Id);
10474 Insert_Action (N, Subp_Decl);
10475 Copy_TSS (Subp_Id, Base_Type (Ent));
10477 end New_Stream_Subprogram;
10479 ------------------------------------------
10480 -- Push_Scope_And_Install_Discriminants --
10481 ------------------------------------------
10483 procedure Push_Scope_And_Install_Discriminants (E : Entity_Id) is
10485 if Has_Discriminants (E) then
10488 -- Make discriminants visible for type declarations and protected
10489 -- type declarations, not for subtype declarations (RM 13.1.1 (12/3))
10491 if Nkind (Parent (E)) /= N_Subtype_Declaration then
10492 Install_Discriminants (E);
10495 end Push_Scope_And_Install_Discriminants;
10497 ------------------------
10498 -- Rep_Item_Too_Early --
10499 ------------------------
10501 function Rep_Item_Too_Early (T : Entity_Id; N : Node_Id) return Boolean is
10503 -- Cannot apply non-operational rep items to generic types
10505 if Is_Operational_Item (N) then
10509 and then Is_Generic_Type (Root_Type (T))
10511 Error_Msg_N ("representation item not allowed for generic type", N);
10515 -- Otherwise check for incomplete type
10517 if Is_Incomplete_Or_Private_Type (T)
10518 and then No (Underlying_Type (T))
10520 (Nkind (N) /= N_Pragma
10521 or else Get_Pragma_Id (N) /= Pragma_Import)
10524 ("representation item must be after full type declaration", N);
10527 -- If the type has incomplete components, a representation clause is
10528 -- illegal but stream attributes and Convention pragmas are correct.
10530 elsif Has_Private_Component (T) then
10531 if Nkind (N) = N_Pragma then
10536 ("representation item must appear after type is fully defined",
10543 end Rep_Item_Too_Early;
10545 -----------------------
10546 -- Rep_Item_Too_Late --
10547 -----------------------
10549 function Rep_Item_Too_Late
10552 FOnly : Boolean := False) return Boolean
10555 Parent_Type : Entity_Id;
10557 procedure Too_Late;
10558 -- Output the too late message. Note that this is not considered a
10559 -- serious error, since the effect is simply that we ignore the
10560 -- representation clause in this case.
10566 procedure Too_Late is
10568 -- Other compilers seem more relaxed about rep items appearing too
10569 -- late. Since analysis tools typically don't care about rep items
10570 -- anyway, no reason to be too strict about this.
10572 if not Relaxed_RM_Semantics then
10573 Error_Msg_N ("|representation item appears too late!", N);
10577 -- Start of processing for Rep_Item_Too_Late
10580 -- First make sure entity is not frozen (RM 13.1(9))
10584 -- Exclude imported types, which may be frozen if they appear in a
10585 -- representation clause for a local type.
10587 and then not From_Limited_With (T)
10589 -- Exclude generated entities (not coming from source). The common
10590 -- case is when we generate a renaming which prematurely freezes the
10591 -- renamed internal entity, but we still want to be able to set copies
10592 -- of attribute values such as Size/Alignment.
10594 and then Comes_From_Source (T)
10597 S := First_Subtype (T);
10599 if Present (Freeze_Node (S)) then
10601 ("??no more representation items for }", Freeze_Node (S), S);
10606 -- Check for case of non-tagged derived type whose parent either has
10607 -- primitive operations, or is a by reference type (RM 13.1(10)).
10611 and then Is_Derived_Type (T)
10612 and then not Is_Tagged_Type (T)
10614 Parent_Type := Etype (Base_Type (T));
10616 if Has_Primitive_Operations (Parent_Type) then
10619 ("primitive operations already defined for&!", N, Parent_Type);
10622 elsif Is_By_Reference_Type (Parent_Type) then
10625 ("parent type & is a by reference type!", N, Parent_Type);
10630 -- No error, link item into head of chain of rep items for the entity,
10631 -- but avoid chaining if we have an overloadable entity, and the pragma
10632 -- is one that can apply to multiple overloaded entities.
10634 if Is_Overloadable (T) and then Nkind (N) = N_Pragma then
10636 Pname : constant Name_Id := Pragma_Name (N);
10638 if Nam_In (Pname, Name_Convention, Name_Import, Name_Export,
10639 Name_External, Name_Interface)
10646 Record_Rep_Item (T, N);
10648 end Rep_Item_Too_Late;
10650 -------------------------------------
10651 -- Replace_Type_References_Generic --
10652 -------------------------------------
10654 procedure Replace_Type_References_Generic (N : Node_Id; TName : Name_Id) is
10656 function Replace_Node (N : Node_Id) return Traverse_Result;
10657 -- Processes a single node in the traversal procedure below, checking
10658 -- if node N should be replaced, and if so, doing the replacement.
10660 procedure Replace_Type_Refs is new Traverse_Proc (Replace_Node);
10661 -- This instantiation provides the body of Replace_Type_References
10667 function Replace_Node (N : Node_Id) return Traverse_Result is
10672 -- Case of identifier
10674 if Nkind (N) = N_Identifier then
10676 -- If not the type name, all done with this node
10678 if Chars (N) /= TName then
10681 -- Otherwise do the replacement and we are done with this node
10684 Replace_Type_Reference (N);
10688 -- Case of selected component (which is what a qualification
10689 -- looks like in the unanalyzed tree, which is what we have.
10691 elsif Nkind (N) = N_Selected_Component then
10693 -- If selector name is not our type, keeping going (we might
10694 -- still have an occurrence of the type in the prefix).
10696 if Nkind (Selector_Name (N)) /= N_Identifier
10697 or else Chars (Selector_Name (N)) /= TName
10701 -- Selector name is our type, check qualification
10704 -- Loop through scopes and prefixes, doing comparison
10706 S := Current_Scope;
10709 -- Continue if no more scopes or scope with no name
10711 if No (S) or else Nkind (S) not in N_Has_Chars then
10715 -- Do replace if prefix is an identifier matching the
10716 -- scope that we are currently looking at.
10718 if Nkind (P) = N_Identifier
10719 and then Chars (P) = Chars (S)
10721 Replace_Type_Reference (N);
10725 -- Go check scope above us if prefix is itself of the
10726 -- form of a selected component, whose selector matches
10727 -- the scope we are currently looking at.
10729 if Nkind (P) = N_Selected_Component
10730 and then Nkind (Selector_Name (P)) = N_Identifier
10731 and then Chars (Selector_Name (P)) = Chars (S)
10736 -- For anything else, we don't have a match, so keep on
10737 -- going, there are still some weird cases where we may
10738 -- still have a replacement within the prefix.
10746 -- Continue for any other node kind
10754 Replace_Type_Refs (N);
10755 end Replace_Type_References_Generic;
10757 -------------------------
10758 -- Same_Representation --
10759 -------------------------
10761 function Same_Representation (Typ1, Typ2 : Entity_Id) return Boolean is
10762 T1 : constant Entity_Id := Underlying_Type (Typ1);
10763 T2 : constant Entity_Id := Underlying_Type (Typ2);
10766 -- A quick check, if base types are the same, then we definitely have
10767 -- the same representation, because the subtype specific representation
10768 -- attributes (Size and Alignment) do not affect representation from
10769 -- the point of view of this test.
10771 if Base_Type (T1) = Base_Type (T2) then
10774 elsif Is_Private_Type (Base_Type (T2))
10775 and then Base_Type (T1) = Full_View (Base_Type (T2))
10780 -- Tagged types never have differing representations
10782 if Is_Tagged_Type (T1) then
10786 -- Representations are definitely different if conventions differ
10788 if Convention (T1) /= Convention (T2) then
10792 -- Representations are different if component alignments or scalar
10793 -- storage orders differ.
10795 if (Is_Record_Type (T1) or else Is_Array_Type (T1))
10797 (Is_Record_Type (T2) or else Is_Array_Type (T2))
10799 (Component_Alignment (T1) /= Component_Alignment (T2)
10801 Reverse_Storage_Order (T1) /= Reverse_Storage_Order (T2))
10806 -- For arrays, the only real issue is component size. If we know the
10807 -- component size for both arrays, and it is the same, then that's
10808 -- good enough to know we don't have a change of representation.
10810 if Is_Array_Type (T1) then
10811 if Known_Component_Size (T1)
10812 and then Known_Component_Size (T2)
10813 and then Component_Size (T1) = Component_Size (T2)
10815 if VM_Target = No_VM then
10818 -- In VM targets the representation of arrays with aliased
10819 -- components differs from arrays with non-aliased components
10822 return Has_Aliased_Components (Base_Type (T1))
10824 Has_Aliased_Components (Base_Type (T2));
10829 -- Types definitely have same representation if neither has non-standard
10830 -- representation since default representations are always consistent.
10831 -- If only one has non-standard representation, and the other does not,
10832 -- then we consider that they do not have the same representation. They
10833 -- might, but there is no way of telling early enough.
10835 if Has_Non_Standard_Rep (T1) then
10836 if not Has_Non_Standard_Rep (T2) then
10840 return not Has_Non_Standard_Rep (T2);
10843 -- Here the two types both have non-standard representation, and we need
10844 -- to determine if they have the same non-standard representation.
10846 -- For arrays, we simply need to test if the component sizes are the
10847 -- same. Pragma Pack is reflected in modified component sizes, so this
10848 -- check also deals with pragma Pack.
10850 if Is_Array_Type (T1) then
10851 return Component_Size (T1) = Component_Size (T2);
10853 -- Tagged types always have the same representation, because it is not
10854 -- possible to specify different representations for common fields.
10856 elsif Is_Tagged_Type (T1) then
10859 -- Case of record types
10861 elsif Is_Record_Type (T1) then
10863 -- Packed status must conform
10865 if Is_Packed (T1) /= Is_Packed (T2) then
10868 -- Otherwise we must check components. Typ2 maybe a constrained
10869 -- subtype with fewer components, so we compare the components
10870 -- of the base types.
10873 Record_Case : declare
10874 CD1, CD2 : Entity_Id;
10876 function Same_Rep return Boolean;
10877 -- CD1 and CD2 are either components or discriminants. This
10878 -- function tests whether they have the same representation.
10884 function Same_Rep return Boolean is
10886 if No (Component_Clause (CD1)) then
10887 return No (Component_Clause (CD2));
10889 -- Note: at this point, component clauses have been
10890 -- normalized to the default bit order, so that the
10891 -- comparison of Component_Bit_Offsets is meaningful.
10894 Present (Component_Clause (CD2))
10896 Component_Bit_Offset (CD1) = Component_Bit_Offset (CD2)
10898 Esize (CD1) = Esize (CD2);
10902 -- Start of processing for Record_Case
10905 if Has_Discriminants (T1) then
10907 -- The number of discriminants may be different if the
10908 -- derived type has fewer (constrained by values). The
10909 -- invisible discriminants retain the representation of
10910 -- the original, so the discrepancy does not per se
10911 -- indicate a different representation.
10913 CD1 := First_Discriminant (T1);
10914 CD2 := First_Discriminant (T2);
10915 while Present (CD1) and then Present (CD2) loop
10916 if not Same_Rep then
10919 Next_Discriminant (CD1);
10920 Next_Discriminant (CD2);
10925 CD1 := First_Component (Underlying_Type (Base_Type (T1)));
10926 CD2 := First_Component (Underlying_Type (Base_Type (T2)));
10927 while Present (CD1) loop
10928 if not Same_Rep then
10931 Next_Component (CD1);
10932 Next_Component (CD2);
10940 -- For enumeration types, we must check each literal to see if the
10941 -- representation is the same. Note that we do not permit enumeration
10942 -- representation clauses for Character and Wide_Character, so these
10943 -- cases were already dealt with.
10945 elsif Is_Enumeration_Type (T1) then
10946 Enumeration_Case : declare
10947 L1, L2 : Entity_Id;
10950 L1 := First_Literal (T1);
10951 L2 := First_Literal (T2);
10952 while Present (L1) loop
10953 if Enumeration_Rep (L1) /= Enumeration_Rep (L2) then
10962 end Enumeration_Case;
10964 -- Any other types have the same representation for these purposes
10969 end Same_Representation;
10971 --------------------------------
10972 -- Resolve_Iterable_Operation --
10973 --------------------------------
10975 procedure Resolve_Iterable_Operation
10977 Cursor : Entity_Id;
10986 if not Is_Overloaded (N) then
10987 if not Is_Entity_Name (N)
10988 or else Ekind (Entity (N)) /= E_Function
10989 or else Scope (Entity (N)) /= Scope (Typ)
10990 or else No (First_Formal (Entity (N)))
10991 or else Etype (First_Formal (Entity (N))) /= Typ
10993 Error_Msg_N ("iterable primitive must be local function name "
10994 & "whose first formal is an iterable type", N);
10999 F1 := First_Formal (Ent);
11000 if Nam = Name_First then
11002 -- First (Container) => Cursor
11004 if Etype (Ent) /= Cursor then
11005 Error_Msg_N ("primitive for First must yield a curosr", N);
11008 elsif Nam = Name_Next then
11010 -- Next (Container, Cursor) => Cursor
11012 F2 := Next_Formal (F1);
11014 if Etype (F2) /= Cursor
11015 or else Etype (Ent) /= Cursor
11016 or else Present (Next_Formal (F2))
11018 Error_Msg_N ("no match for Next iterable primitive", N);
11021 elsif Nam = Name_Has_Element then
11023 -- Has_Element (Container, Cursor) => Boolean
11025 F2 := Next_Formal (F1);
11026 if Etype (F2) /= Cursor
11027 or else Etype (Ent) /= Standard_Boolean
11028 or else Present (Next_Formal (F2))
11030 Error_Msg_N ("no match for Has_Element iterable primitive", N);
11033 elsif Nam = Name_Element then
11034 F2 := Next_Formal (F1);
11037 or else Etype (F2) /= Cursor
11038 or else Present (Next_Formal (F2))
11040 Error_Msg_N ("no match for Element iterable primitive", N);
11045 raise Program_Error;
11049 -- Overloaded case: find subprogram with proper signature.
11050 -- Caller will report error if no match is found.
11057 Get_First_Interp (N, I, It);
11058 while Present (It.Typ) loop
11059 if Ekind (It.Nam) = E_Function
11060 and then Scope (It.Nam) = Scope (Typ)
11061 and then Etype (First_Formal (It.Nam)) = Typ
11063 F1 := First_Formal (It.Nam);
11065 if Nam = Name_First then
11066 if Etype (It.Nam) = Cursor
11067 and then No (Next_Formal (F1))
11069 Set_Entity (N, It.Nam);
11073 elsif Nam = Name_Next then
11074 F2 := Next_Formal (F1);
11077 and then No (Next_Formal (F2))
11078 and then Etype (F2) = Cursor
11079 and then Etype (It.Nam) = Cursor
11081 Set_Entity (N, It.Nam);
11085 elsif Nam = Name_Has_Element then
11086 F2 := Next_Formal (F1);
11089 and then No (Next_Formal (F2))
11090 and then Etype (F2) = Cursor
11091 and then Etype (It.Nam) = Standard_Boolean
11093 Set_Entity (N, It.Nam);
11094 F2 := Next_Formal (F1);
11098 elsif Nam = Name_Element then
11099 F2 := Next_Formal (F1);
11102 and then No (Next_Formal (F2))
11103 and then Etype (F2) = Cursor
11105 Set_Entity (N, It.Nam);
11111 Get_Next_Interp (I, It);
11115 end Resolve_Iterable_Operation;
11121 procedure Set_Biased
11125 Biased : Boolean := True)
11129 Set_Has_Biased_Representation (E);
11131 if Warn_On_Biased_Representation then
11133 ("?B?" & Msg & " forces biased representation for&", N, E);
11138 --------------------
11139 -- Set_Enum_Esize --
11140 --------------------
11142 procedure Set_Enum_Esize (T : Entity_Id) is
11148 Init_Alignment (T);
11150 -- Find the minimum standard size (8,16,32,64) that fits
11152 Lo := Enumeration_Rep (Entity (Type_Low_Bound (T)));
11153 Hi := Enumeration_Rep (Entity (Type_High_Bound (T)));
11156 if Lo >= -Uint_2**07 and then Hi < Uint_2**07 then
11157 Sz := Standard_Character_Size; -- May be > 8 on some targets
11159 elsif Lo >= -Uint_2**15 and then Hi < Uint_2**15 then
11162 elsif Lo >= -Uint_2**31 and then Hi < Uint_2**31 then
11165 else pragma Assert (Lo >= -Uint_2**63 and then Hi < Uint_2**63);
11170 if Hi < Uint_2**08 then
11171 Sz := Standard_Character_Size; -- May be > 8 on some targets
11173 elsif Hi < Uint_2**16 then
11176 elsif Hi < Uint_2**32 then
11179 else pragma Assert (Hi < Uint_2**63);
11184 -- That minimum is the proper size unless we have a foreign convention
11185 -- and the size required is 32 or less, in which case we bump the size
11186 -- up to 32. This is required for C and C++ and seems reasonable for
11187 -- all other foreign conventions.
11189 if Has_Foreign_Convention (T)
11190 and then Esize (T) < Standard_Integer_Size
11192 -- Don't do this if Short_Enums on target
11194 and then not Target_Short_Enums
11196 Init_Esize (T, Standard_Integer_Size);
11198 Init_Esize (T, Sz);
11200 end Set_Enum_Esize;
11202 -----------------------------
11203 -- Uninstall_Discriminants --
11204 -----------------------------
11206 procedure Uninstall_Discriminants (E : Entity_Id) is
11212 -- Discriminants have been made visible for type declarations and
11213 -- protected type declarations, not for subtype declarations.
11215 if Nkind (Parent (E)) /= N_Subtype_Declaration then
11216 Disc := First_Discriminant (E);
11217 while Present (Disc) loop
11218 if Disc /= Current_Entity (Disc) then
11219 Prev := Current_Entity (Disc);
11220 while Present (Prev)
11221 and then Present (Homonym (Prev))
11222 and then Homonym (Prev) /= Disc
11224 Prev := Homonym (Prev);
11230 Set_Is_Immediately_Visible (Disc, False);
11232 Outer := Homonym (Disc);
11233 while Present (Outer) and then Scope (Outer) = E loop
11234 Outer := Homonym (Outer);
11237 -- Reset homonym link of other entities, but do not modify link
11238 -- between entities in current scope, so that the back-end can
11239 -- have a proper count of local overloadings.
11242 Set_Name_Entity_Id (Chars (Disc), Outer);
11244 elsif Scope (Prev) /= Scope (Disc) then
11245 Set_Homonym (Prev, Outer);
11248 Next_Discriminant (Disc);
11251 end Uninstall_Discriminants;
11253 -------------------------------------------
11254 -- Uninstall_Discriminants_And_Pop_Scope --
11255 -------------------------------------------
11257 procedure Uninstall_Discriminants_And_Pop_Scope (E : Entity_Id) is
11259 if Has_Discriminants (E) then
11260 Uninstall_Discriminants (E);
11263 end Uninstall_Discriminants_And_Pop_Scope;
11265 ------------------------------
11266 -- Validate_Address_Clauses --
11267 ------------------------------
11269 procedure Validate_Address_Clauses is
11271 for J in Address_Clause_Checks.First .. Address_Clause_Checks.Last loop
11273 ACCR : Address_Clause_Check_Record
11274 renames Address_Clause_Checks.Table (J);
11278 X_Alignment : Uint;
11279 Y_Alignment : Uint;
11285 -- Skip processing of this entry if warning already posted
11287 if not Address_Warning_Posted (ACCR.N) then
11288 Expr := Original_Node (Expression (ACCR.N));
11292 X_Alignment := Alignment (ACCR.X);
11293 Y_Alignment := Alignment (ACCR.Y);
11295 -- Similarly obtain sizes
11297 X_Size := Esize (ACCR.X);
11298 Y_Size := Esize (ACCR.Y);
11300 -- Check for large object overlaying smaller one
11303 and then X_Size > Uint_0
11304 and then X_Size > Y_Size
11307 ("??& overlays smaller object", ACCR.N, ACCR.X);
11309 ("\??program execution may be erroneous", ACCR.N);
11310 Error_Msg_Uint_1 := X_Size;
11312 ("\??size of & is ^", ACCR.N, ACCR.X);
11313 Error_Msg_Uint_1 := Y_Size;
11315 ("\??size of & is ^", ACCR.N, ACCR.Y);
11317 -- Check for inadequate alignment, both of the base object
11318 -- and of the offset, if any.
11320 -- Note: we do not check the alignment if we gave a size
11321 -- warning, since it would likely be redundant.
11323 elsif Y_Alignment /= Uint_0
11324 and then (Y_Alignment < X_Alignment
11327 Nkind (Expr) = N_Attribute_Reference
11329 Attribute_Name (Expr) = Name_Address
11331 Has_Compatible_Alignment
11332 (ACCR.X, Prefix (Expr))
11333 /= Known_Compatible))
11336 ("??specified address for& may be inconsistent "
11337 & "with alignment", ACCR.N, ACCR.X);
11339 ("\??program execution may be erroneous (RM 13.3(27))",
11341 Error_Msg_Uint_1 := X_Alignment;
11343 ("\??alignment of & is ^", ACCR.N, ACCR.X);
11344 Error_Msg_Uint_1 := Y_Alignment;
11346 ("\??alignment of & is ^", ACCR.N, ACCR.Y);
11347 if Y_Alignment >= X_Alignment then
11349 ("\??but offset is not multiple of alignment", ACCR.N);
11355 end Validate_Address_Clauses;
11357 ---------------------------
11358 -- Validate_Independence --
11359 ---------------------------
11361 procedure Validate_Independence is
11362 SU : constant Uint := UI_From_Int (System_Storage_Unit);
11370 procedure Check_Array_Type (Atyp : Entity_Id);
11371 -- Checks if the array type Atyp has independent components, and
11372 -- if not, outputs an appropriate set of error messages.
11374 procedure No_Independence;
11375 -- Output message that independence cannot be guaranteed
11377 function OK_Component (C : Entity_Id) return Boolean;
11378 -- Checks one component to see if it is independently accessible, and
11379 -- if so yields True, otherwise yields False if independent access
11380 -- cannot be guaranteed. This is a conservative routine, it only
11381 -- returns True if it knows for sure, it returns False if it knows
11382 -- there is a problem, or it cannot be sure there is no problem.
11384 procedure Reason_Bad_Component (C : Entity_Id);
11385 -- Outputs continuation message if a reason can be determined for
11386 -- the component C being bad.
11388 ----------------------
11389 -- Check_Array_Type --
11390 ----------------------
11392 procedure Check_Array_Type (Atyp : Entity_Id) is
11393 Ctyp : constant Entity_Id := Component_Type (Atyp);
11396 -- OK if no alignment clause, no pack, and no component size
11398 if not Has_Component_Size_Clause (Atyp)
11399 and then not Has_Alignment_Clause (Atyp)
11400 and then not Is_Packed (Atyp)
11405 -- Check actual component size
11407 if not Known_Component_Size (Atyp)
11408 or else not (Addressable (Component_Size (Atyp))
11409 and then Component_Size (Atyp) < 64)
11410 or else Component_Size (Atyp) mod Esize (Ctyp) /= 0
11414 -- Bad component size, check reason
11416 if Has_Component_Size_Clause (Atyp) then
11417 P := Get_Attribute_Definition_Clause
11418 (Atyp, Attribute_Component_Size);
11420 if Present (P) then
11421 Error_Msg_Sloc := Sloc (P);
11422 Error_Msg_N ("\because of Component_Size clause#", N);
11427 if Is_Packed (Atyp) then
11428 P := Get_Rep_Pragma (Atyp, Name_Pack);
11430 if Present (P) then
11431 Error_Msg_Sloc := Sloc (P);
11432 Error_Msg_N ("\because of pragma Pack#", N);
11437 -- No reason found, just return
11442 -- Array type is OK independence-wise
11445 end Check_Array_Type;
11447 ---------------------
11448 -- No_Independence --
11449 ---------------------
11451 procedure No_Independence is
11453 if Pragma_Name (N) = Name_Independent then
11454 Error_Msg_NE ("independence cannot be guaranteed for&", N, E);
11457 ("independent components cannot be guaranteed for&", N, E);
11459 end No_Independence;
11465 function OK_Component (C : Entity_Id) return Boolean is
11466 Rec : constant Entity_Id := Scope (C);
11467 Ctyp : constant Entity_Id := Etype (C);
11470 -- OK if no component clause, no Pack, and no alignment clause
11472 if No (Component_Clause (C))
11473 and then not Is_Packed (Rec)
11474 and then not Has_Alignment_Clause (Rec)
11479 -- Here we look at the actual component layout. A component is
11480 -- addressable if its size is a multiple of the Esize of the
11481 -- component type, and its starting position in the record has
11482 -- appropriate alignment, and the record itself has appropriate
11483 -- alignment to guarantee the component alignment.
11485 -- Make sure sizes are static, always assume the worst for any
11486 -- cases where we cannot check static values.
11488 if not (Known_Static_Esize (C)
11490 Known_Static_Esize (Ctyp))
11495 -- Size of component must be addressable or greater than 64 bits
11496 -- and a multiple of bytes.
11498 if not Addressable (Esize (C)) and then Esize (C) < Uint_64 then
11502 -- Check size is proper multiple
11504 if Esize (C) mod Esize (Ctyp) /= 0 then
11508 -- Check alignment of component is OK
11510 if not Known_Component_Bit_Offset (C)
11511 or else Component_Bit_Offset (C) < Uint_0
11512 or else Component_Bit_Offset (C) mod Esize (Ctyp) /= 0
11517 -- Check alignment of record type is OK
11519 if not Known_Alignment (Rec)
11520 or else (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0
11525 -- All tests passed, component is addressable
11530 --------------------------
11531 -- Reason_Bad_Component --
11532 --------------------------
11534 procedure Reason_Bad_Component (C : Entity_Id) is
11535 Rec : constant Entity_Id := Scope (C);
11536 Ctyp : constant Entity_Id := Etype (C);
11539 -- If component clause present assume that's the problem
11541 if Present (Component_Clause (C)) then
11542 Error_Msg_Sloc := Sloc (Component_Clause (C));
11543 Error_Msg_N ("\because of Component_Clause#", N);
11547 -- If pragma Pack clause present, assume that's the problem
11549 if Is_Packed (Rec) then
11550 P := Get_Rep_Pragma (Rec, Name_Pack);
11552 if Present (P) then
11553 Error_Msg_Sloc := Sloc (P);
11554 Error_Msg_N ("\because of pragma Pack#", N);
11559 -- See if record has bad alignment clause
11561 if Has_Alignment_Clause (Rec)
11562 and then Known_Alignment (Rec)
11563 and then (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0
11565 P := Get_Attribute_Definition_Clause (Rec, Attribute_Alignment);
11567 if Present (P) then
11568 Error_Msg_Sloc := Sloc (P);
11569 Error_Msg_N ("\because of Alignment clause#", N);
11573 -- Couldn't find a reason, so return without a message
11576 end Reason_Bad_Component;
11578 -- Start of processing for Validate_Independence
11581 for J in Independence_Checks.First .. Independence_Checks.Last loop
11582 N := Independence_Checks.Table (J).N;
11583 E := Independence_Checks.Table (J).E;
11584 IC := Pragma_Name (N) = Name_Independent_Components;
11586 -- Deal with component case
11588 if Ekind (E) = E_Discriminant or else Ekind (E) = E_Component then
11589 if not OK_Component (E) then
11591 Reason_Bad_Component (E);
11596 -- Deal with record with Independent_Components
11598 if IC and then Is_Record_Type (E) then
11599 Comp := First_Component_Or_Discriminant (E);
11600 while Present (Comp) loop
11601 if not OK_Component (Comp) then
11603 Reason_Bad_Component (Comp);
11607 Next_Component_Or_Discriminant (Comp);
11611 -- Deal with address clause case
11613 if Is_Object (E) then
11614 Addr := Address_Clause (E);
11616 if Present (Addr) then
11618 Error_Msg_Sloc := Sloc (Addr);
11619 Error_Msg_N ("\because of Address clause#", N);
11624 -- Deal with independent components for array type
11626 if IC and then Is_Array_Type (E) then
11627 Check_Array_Type (E);
11630 -- Deal with independent components for array object
11632 if IC and then Is_Object (E) and then Is_Array_Type (Etype (E)) then
11633 Check_Array_Type (Etype (E));
11638 end Validate_Independence;
11640 ------------------------------
11641 -- Validate_Iterable_Aspect --
11642 ------------------------------
11644 procedure Validate_Iterable_Aspect (Typ : Entity_Id; ASN : Node_Id) is
11649 Cursor : constant Entity_Id := Get_Cursor_Type (ASN, Typ);
11651 First_Id : Entity_Id;
11652 Next_Id : Entity_Id;
11653 Has_Element_Id : Entity_Id;
11654 Element_Id : Entity_Id;
11657 -- If previous error aspect is unusable
11659 if Cursor = Any_Type then
11665 Has_Element_Id := Empty;
11666 Element_Id := Empty;
11668 -- Each expression must resolve to a function with the proper signature
11670 Assoc := First (Component_Associations (Expression (ASN)));
11671 while Present (Assoc) loop
11672 Expr := Expression (Assoc);
11675 Prim := First (Choices (Assoc));
11677 if Nkind (Prim) /= N_Identifier
11678 or else Present (Next (Prim))
11680 Error_Msg_N ("illegal name in association", Prim);
11682 elsif Chars (Prim) = Name_First then
11683 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_First);
11684 First_Id := Entity (Expr);
11686 elsif Chars (Prim) = Name_Next then
11687 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Next);
11688 Next_Id := Entity (Expr);
11690 elsif Chars (Prim) = Name_Has_Element then
11691 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Has_Element);
11692 Has_Element_Id := Entity (Expr);
11694 elsif Chars (Prim) = Name_Element then
11695 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Element);
11696 Element_Id := Entity (Expr);
11699 Error_Msg_N ("invalid name for iterable function", Prim);
11705 if No (First_Id) then
11706 Error_Msg_N ("match for First primitive not found", ASN);
11708 elsif No (Next_Id) then
11709 Error_Msg_N ("match for Next primitive not found", ASN);
11711 elsif No (Has_Element_Id) then
11712 Error_Msg_N ("match for Has_Element primitive not found", ASN);
11714 elsif No (Element_Id) then
11717 end Validate_Iterable_Aspect;
11719 -----------------------------------
11720 -- Validate_Unchecked_Conversion --
11721 -----------------------------------
11723 procedure Validate_Unchecked_Conversion
11725 Act_Unit : Entity_Id)
11727 Source : Entity_Id;
11728 Target : Entity_Id;
11732 -- Obtain source and target types. Note that we call Ancestor_Subtype
11733 -- here because the processing for generic instantiation always makes
11734 -- subtypes, and we want the original frozen actual types.
11736 -- If we are dealing with private types, then do the check on their
11737 -- fully declared counterparts if the full declarations have been
11738 -- encountered (they don't have to be visible, but they must exist).
11740 Source := Ancestor_Subtype (Etype (First_Formal (Act_Unit)));
11742 if Is_Private_Type (Source)
11743 and then Present (Underlying_Type (Source))
11745 Source := Underlying_Type (Source);
11748 Target := Ancestor_Subtype (Etype (Act_Unit));
11750 -- If either type is generic, the instantiation happens within a generic
11751 -- unit, and there is nothing to check. The proper check will happen
11752 -- when the enclosing generic is instantiated.
11754 if Is_Generic_Type (Source) or else Is_Generic_Type (Target) then
11758 if Is_Private_Type (Target)
11759 and then Present (Underlying_Type (Target))
11761 Target := Underlying_Type (Target);
11764 -- Source may be unconstrained array, but not target
11766 if Is_Array_Type (Target) and then not Is_Constrained (Target) then
11768 ("unchecked conversion to unconstrained array not allowed", N);
11772 -- Warn if conversion between two different convention pointers
11774 if Is_Access_Type (Target)
11775 and then Is_Access_Type (Source)
11776 and then Convention (Target) /= Convention (Source)
11777 and then Warn_On_Unchecked_Conversion
11779 -- Give warnings for subprogram pointers only on most targets. The
11780 -- exception is VMS, where data pointers can have different lengths
11781 -- depending on the pointer convention.
11783 if Is_Access_Subprogram_Type (Target)
11784 or else Is_Access_Subprogram_Type (Source)
11785 or else OpenVMS_On_Target
11788 ("?z?conversion between pointers with different conventions!",
11793 -- Warn if one of the operands is Ada.Calendar.Time. Do not emit a
11794 -- warning when compiling GNAT-related sources.
11796 if Warn_On_Unchecked_Conversion
11797 and then not In_Predefined_Unit (N)
11798 and then RTU_Loaded (Ada_Calendar)
11800 (Chars (Source) = Name_Time
11802 Chars (Target) = Name_Time)
11804 -- If Ada.Calendar is loaded and the name of one of the operands is
11805 -- Time, there is a good chance that this is Ada.Calendar.Time.
11808 Calendar_Time : constant Entity_Id :=
11809 Full_View (RTE (RO_CA_Time));
11811 pragma Assert (Present (Calendar_Time));
11813 if Source = Calendar_Time or else Target = Calendar_Time then
11815 ("?z?representation of 'Time values may change between " &
11816 "'G'N'A'T versions", N);
11821 -- Make entry in unchecked conversion table for later processing by
11822 -- Validate_Unchecked_Conversions, which will check sizes and alignments
11823 -- (using values set by the back-end where possible). This is only done
11824 -- if the appropriate warning is active.
11826 if Warn_On_Unchecked_Conversion then
11827 Unchecked_Conversions.Append
11828 (New_Val => UC_Entry'(Eloc => Sloc (N),
11831 Act_Unit => Act_Unit));
11833 -- If both sizes are known statically now, then back end annotation
11834 -- is not required to do a proper check but if either size is not
11835 -- known statically, then we need the annotation.
11837 if Known_Static_RM_Size (Source)
11839 Known_Static_RM_Size (Target)
11843 Back_Annotate_Rep_Info := True;
11847 -- If unchecked conversion to access type, and access type is declared
11848 -- in the same unit as the unchecked conversion, then set the flag
11849 -- No_Strict_Aliasing (no strict aliasing is implicit here)
11851 if Is_Access_Type (Target) and then
11852 In_Same_Source_Unit (Target, N)
11854 Set_No_Strict_Aliasing (Implementation_Base_Type (Target));
11857 -- Generate N_Validate_Unchecked_Conversion node for back end in case
11858 -- the back end needs to perform special validation checks.
11860 -- Shouldn't this be in Exp_Ch13, since the check only gets done if we
11861 -- have full expansion and the back end is called ???
11864 Make_Validate_Unchecked_Conversion (Sloc (N));
11865 Set_Source_Type (Vnode, Source);
11866 Set_Target_Type (Vnode, Target);
11868 -- If the unchecked conversion node is in a list, just insert before it.
11869 -- If not we have some strange case, not worth bothering about.
11871 if Is_List_Member (N) then
11872 Insert_After (N, Vnode);
11874 end Validate_Unchecked_Conversion;
11876 ------------------------------------
11877 -- Validate_Unchecked_Conversions --
11878 ------------------------------------
11880 procedure Validate_Unchecked_Conversions is
11882 for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop
11884 T : UC_Entry renames Unchecked_Conversions.Table (N);
11886 Eloc : constant Source_Ptr := T.Eloc;
11887 Source : constant Entity_Id := T.Source;
11888 Target : constant Entity_Id := T.Target;
11889 Act_Unit : constant Entity_Id := T.Act_Unit;
11895 -- Skip if function marked as warnings off
11897 if Warnings_Off (Act_Unit) then
11901 -- This validation check, which warns if we have unequal sizes for
11902 -- unchecked conversion, and thus potentially implementation
11903 -- dependent semantics, is one of the few occasions on which we
11904 -- use the official RM size instead of Esize. See description in
11905 -- Einfo "Handling of Type'Size Values" for details.
11907 if Serious_Errors_Detected = 0
11908 and then Known_Static_RM_Size (Source)
11909 and then Known_Static_RM_Size (Target)
11911 -- Don't do the check if warnings off for either type, note the
11912 -- deliberate use of OR here instead of OR ELSE to get the flag
11913 -- Warnings_Off_Used set for both types if appropriate.
11915 and then not (Has_Warnings_Off (Source)
11917 Has_Warnings_Off (Target))
11919 Source_Siz := RM_Size (Source);
11920 Target_Siz := RM_Size (Target);
11922 if Source_Siz /= Target_Siz then
11924 ("?z?types for unchecked conversion have different sizes!",
11927 if All_Errors_Mode then
11928 Error_Msg_Name_1 := Chars (Source);
11929 Error_Msg_Uint_1 := Source_Siz;
11930 Error_Msg_Name_2 := Chars (Target);
11931 Error_Msg_Uint_2 := Target_Siz;
11932 Error_Msg ("\size of % is ^, size of % is ^?z?", Eloc);
11934 Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz);
11936 if Is_Discrete_Type (Source)
11938 Is_Discrete_Type (Target)
11940 if Source_Siz > Target_Siz then
11942 ("\?z?^ high order bits of source will "
11943 & "be ignored!", Eloc);
11945 elsif Is_Unsigned_Type (Source) then
11947 ("\?z?source will be extended with ^ high order "
11948 & "zero bits!", Eloc);
11952 ("\?z?source will be extended with ^ high order "
11953 & "sign bits!", Eloc);
11956 elsif Source_Siz < Target_Siz then
11957 if Is_Discrete_Type (Target) then
11958 if Bytes_Big_Endian then
11960 ("\?z?target value will include ^ undefined "
11961 & "low order bits!", Eloc);
11964 ("\?z?target value will include ^ undefined "
11965 & "high order bits!", Eloc);
11970 ("\?z?^ trailing bits of target value will be "
11971 & "undefined!", Eloc);
11974 else pragma Assert (Source_Siz > Target_Siz);
11976 ("\?z?^ trailing bits of source will be ignored!",
11983 -- If both types are access types, we need to check the alignment.
11984 -- If the alignment of both is specified, we can do it here.
11986 if Serious_Errors_Detected = 0
11987 and then Ekind (Source) in Access_Kind
11988 and then Ekind (Target) in Access_Kind
11989 and then Target_Strict_Alignment
11990 and then Present (Designated_Type (Source))
11991 and then Present (Designated_Type (Target))
11994 D_Source : constant Entity_Id := Designated_Type (Source);
11995 D_Target : constant Entity_Id := Designated_Type (Target);
11998 if Known_Alignment (D_Source)
12000 Known_Alignment (D_Target)
12003 Source_Align : constant Uint := Alignment (D_Source);
12004 Target_Align : constant Uint := Alignment (D_Target);
12007 if Source_Align < Target_Align
12008 and then not Is_Tagged_Type (D_Source)
12010 -- Suppress warning if warnings suppressed on either
12011 -- type or either designated type. Note the use of
12012 -- OR here instead of OR ELSE. That is intentional,
12013 -- we would like to set flag Warnings_Off_Used in
12014 -- all types for which warnings are suppressed.
12016 and then not (Has_Warnings_Off (D_Source)
12018 Has_Warnings_Off (D_Target)
12020 Has_Warnings_Off (Source)
12022 Has_Warnings_Off (Target))
12024 Error_Msg_Uint_1 := Target_Align;
12025 Error_Msg_Uint_2 := Source_Align;
12026 Error_Msg_Node_1 := D_Target;
12027 Error_Msg_Node_2 := D_Source;
12029 ("?z?alignment of & (^) is stricter than "
12030 & "alignment of & (^)!", Eloc);
12032 ("\?z?resulting access value may have invalid "
12033 & "alignment!", Eloc);
12044 end Validate_Unchecked_Conversions;