1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2015, 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;
36 with Freeze; use Freeze;
37 with Ghost; use Ghost;
39 with Lib.Xref; use Lib.Xref;
40 with Namet; use Namet;
41 with Nlists; use Nlists;
42 with Nmake; use Nmake;
44 with Restrict; use Restrict;
45 with Rident; use Rident;
46 with Rtsfind; use Rtsfind;
48 with Sem_Aux; use Sem_Aux;
49 with Sem_Case; use Sem_Case;
50 with Sem_Ch3; use Sem_Ch3;
51 with Sem_Ch6; use Sem_Ch6;
52 with Sem_Ch8; use Sem_Ch8;
53 with Sem_Dim; use Sem_Dim;
54 with Sem_Disp; use Sem_Disp;
55 with Sem_Eval; use Sem_Eval;
56 with Sem_Prag; use Sem_Prag;
57 with Sem_Res; use Sem_Res;
58 with Sem_Type; use Sem_Type;
59 with Sem_Util; use Sem_Util;
60 with Sem_Warn; use Sem_Warn;
61 with Sinput; use Sinput;
62 with Snames; use Snames;
63 with Stand; use Stand;
64 with Sinfo; use Sinfo;
65 with Stringt; use Stringt;
66 with Targparm; use Targparm;
67 with Ttypes; use Ttypes;
68 with Tbuild; use Tbuild;
69 with Urealp; use Urealp;
70 with Warnsw; use Warnsw;
72 with GNAT.Heap_Sort_G;
74 package body Sem_Ch13 is
76 SSU : constant Pos := System_Storage_Unit;
77 -- Convenient short hand for commonly used constant
79 -----------------------
80 -- Local Subprograms --
81 -----------------------
83 procedure Alignment_Check_For_Size_Change (Typ : Entity_Id; Size : Uint);
84 -- This routine is called after setting one of the sizes of type entity
85 -- Typ to Size. The purpose is to deal with the situation of a derived
86 -- type whose inherited alignment is no longer appropriate for the new
87 -- size value. In this case, we reset the Alignment to unknown.
89 procedure Build_Discrete_Static_Predicate
93 -- Given a predicated type Typ, where Typ is a discrete static subtype,
94 -- whose predicate expression is Expr, tests if Expr is a static predicate,
95 -- and if so, builds the predicate range list. Nam is the name of the one
96 -- argument to the predicate function. Occurrences of the type name in the
97 -- predicate expression have been replaced by identifier references to this
98 -- name, which is unique, so any identifier with Chars matching Nam must be
99 -- a reference to the type. If the predicate is non-static, this procedure
100 -- returns doing nothing. If the predicate is static, then the predicate
101 -- list is stored in Static_Discrete_Predicate (Typ), and the Expr is
102 -- rewritten as a canonicalized membership operation.
104 procedure Build_Predicate_Functions (Typ : Entity_Id; N : Node_Id);
105 -- If Typ has predicates (indicated by Has_Predicates being set for Typ),
106 -- then either there are pragma Predicate entries on the rep chain for the
107 -- type (note that Predicate aspects are converted to pragma Predicate), or
108 -- there are inherited aspects from a parent type, or ancestor subtypes.
109 -- This procedure builds the spec and body for the Predicate function that
110 -- tests these predicates. N is the freeze node for the type. The spec of
111 -- the function is inserted before the freeze node, and the body of the
112 -- function is inserted after the freeze node. If the predicate expression
113 -- has at least one Raise_Expression, then this procedure also builds the
114 -- M version of the predicate function for use in membership tests.
116 procedure Check_Pool_Size_Clash (Ent : Entity_Id; SP, SS : Node_Id);
117 -- Called if both Storage_Pool and Storage_Size attribute definition
118 -- clauses (SP and SS) are present for entity Ent. Issue error message.
120 procedure Freeze_Entity_Checks (N : Node_Id);
121 -- Called from Analyze_Freeze_Entity and Analyze_Generic_Freeze Entity
122 -- to generate appropriate semantic checks that are delayed until this
123 -- point (they had to be delayed this long for cases of delayed aspects,
124 -- e.g. analysis of statically predicated subtypes in choices, for which
125 -- we have to be sure the subtypes in question are frozen before checking.
127 function Get_Alignment_Value (Expr : Node_Id) return Uint;
128 -- Given the expression for an alignment value, returns the corresponding
129 -- Uint value. If the value is inappropriate, then error messages are
130 -- posted as required, and a value of No_Uint is returned.
132 function Is_Operational_Item (N : Node_Id) return Boolean;
133 -- A specification for a stream attribute is allowed before the full type
134 -- is declared, as explained in AI-00137 and the corrigendum. Attributes
135 -- that do not specify a representation characteristic are operational
138 function Is_Predicate_Static
140 Nam : Name_Id) return Boolean;
141 -- Given predicate expression Expr, tests if Expr is predicate-static in
142 -- the sense of the rules in (RM 3.2.4 (15-24)). Occurrences of the type
143 -- name in the predicate expression have been replaced by references to
144 -- an identifier whose Chars field is Nam. This name is unique, so any
145 -- identifier with Chars matching Nam must be a reference to the type.
146 -- Returns True if the expression is predicate-static and False otherwise,
147 -- but is not in the business of setting flags or issuing error messages.
149 -- Only scalar types can have static predicates, so False is always
150 -- returned for non-scalar types.
152 -- Note: the RM seems to suggest that string types can also have static
153 -- predicates. But that really makes lttle sense as very few useful
154 -- predicates can be constructed for strings. Remember that:
158 -- is not a static expression. So even though the clearly faulty RM wording
159 -- allows the following:
161 -- subtype S is String with Static_Predicate => S < "DEF"
163 -- We can't allow this, otherwise we have predicate-static applying to a
164 -- larger class than static expressions, which was never intended.
166 procedure New_Stream_Subprogram
170 Nam : TSS_Name_Type);
171 -- Create a subprogram renaming of a given stream attribute to the
172 -- designated subprogram and then in the tagged case, provide this as a
173 -- primitive operation, or in the untagged case make an appropriate TSS
174 -- entry. This is more properly an expansion activity than just semantics,
175 -- but the presence of user-defined stream functions for limited types
176 -- is a legality check, which is why this takes place here rather than in
177 -- exp_ch13, where it was previously. Nam indicates the name of the TSS
178 -- function to be generated.
180 -- To avoid elaboration anomalies with freeze nodes, for untagged types
181 -- we generate both a subprogram declaration and a subprogram renaming
182 -- declaration, so that the attribute specification is handled as a
183 -- renaming_as_body. For tagged types, the specification is one of the
186 procedure Resolve_Iterable_Operation
191 -- If the name of a primitive operation for an Iterable aspect is
192 -- overloaded, resolve according to required signature.
198 Biased : Boolean := True);
199 -- If Biased is True, sets Has_Biased_Representation flag for E, and
200 -- outputs a warning message at node N if Warn_On_Biased_Representation is
201 -- is True. This warning inserts the string Msg to describe the construct
204 ----------------------------------------------
205 -- Table for Validate_Unchecked_Conversions --
206 ----------------------------------------------
208 -- The following table collects unchecked conversions for validation.
209 -- Entries are made by Validate_Unchecked_Conversion and then the call
210 -- to Validate_Unchecked_Conversions does the actual error checking and
211 -- posting of warnings. The reason for this delayed processing is to take
212 -- advantage of back-annotations of size and alignment values performed by
215 -- Note: the reason we store a Source_Ptr value instead of a Node_Id is
216 -- that by the time Validate_Unchecked_Conversions is called, Sprint will
217 -- already have modified all Sloc values if the -gnatD option is set.
219 type UC_Entry is record
220 Eloc : Source_Ptr; -- node used for posting warnings
221 Source : Entity_Id; -- source type for unchecked conversion
222 Target : Entity_Id; -- target type for unchecked conversion
223 Act_Unit : Entity_Id; -- actual function instantiated
226 package Unchecked_Conversions is new Table.Table (
227 Table_Component_Type => UC_Entry,
228 Table_Index_Type => Int,
229 Table_Low_Bound => 1,
231 Table_Increment => 200,
232 Table_Name => "Unchecked_Conversions");
234 ----------------------------------------
235 -- Table for Validate_Address_Clauses --
236 ----------------------------------------
238 -- If an address clause has the form
240 -- for X'Address use Expr
242 -- where Expr is of the form Y'Address or recursively is a reference to a
243 -- constant of either of these forms, and X and Y are entities of objects,
244 -- then if Y has a smaller alignment than X, that merits a warning about
245 -- possible bad alignment. The following table collects address clauses of
246 -- this kind. We put these in a table so that they can be checked after the
247 -- back end has completed annotation of the alignments of objects, since we
248 -- can catch more cases that way.
250 type Address_Clause_Check_Record is record
252 -- The address clause
255 -- The entity of the object overlaying Y
258 -- The entity of the object being overlaid
261 -- Whether the address is offset within Y
264 package Address_Clause_Checks is new Table.Table (
265 Table_Component_Type => Address_Clause_Check_Record,
266 Table_Index_Type => Int,
267 Table_Low_Bound => 1,
269 Table_Increment => 200,
270 Table_Name => "Address_Clause_Checks");
272 -----------------------------------------
273 -- Adjust_Record_For_Reverse_Bit_Order --
274 -----------------------------------------
276 procedure Adjust_Record_For_Reverse_Bit_Order (R : Entity_Id) is
281 -- Processing depends on version of Ada
283 -- For Ada 95, we just renumber bits within a storage unit. We do the
284 -- same for Ada 83 mode, since we recognize the Bit_Order attribute in
285 -- Ada 83, and are free to add this extension.
287 if Ada_Version < Ada_2005 then
288 Comp := First_Component_Or_Discriminant (R);
289 while Present (Comp) loop
290 CC := Component_Clause (Comp);
292 -- If component clause is present, then deal with the non-default
293 -- bit order case for Ada 95 mode.
295 -- We only do this processing for the base type, and in fact that
296 -- is important, since otherwise if there are record subtypes, we
297 -- could reverse the bits once for each subtype, which is wrong.
299 if Present (CC) and then Ekind (R) = E_Record_Type then
301 CFB : constant Uint := Component_Bit_Offset (Comp);
302 CSZ : constant Uint := Esize (Comp);
303 CLC : constant Node_Id := Component_Clause (Comp);
304 Pos : constant Node_Id := Position (CLC);
305 FB : constant Node_Id := First_Bit (CLC);
307 Storage_Unit_Offset : constant Uint :=
308 CFB / System_Storage_Unit;
310 Start_Bit : constant Uint :=
311 CFB mod System_Storage_Unit;
314 -- Cases where field goes over storage unit boundary
316 if Start_Bit + CSZ > System_Storage_Unit then
318 -- Allow multi-byte field but generate warning
320 if Start_Bit mod System_Storage_Unit = 0
321 and then CSZ mod System_Storage_Unit = 0
324 ("info: multi-byte field specified with "
325 & "non-standard Bit_Order?V?", CLC);
327 if Bytes_Big_Endian then
329 ("\bytes are not reversed "
330 & "(component is big-endian)?V?", CLC);
333 ("\bytes are not reversed "
334 & "(component is little-endian)?V?", CLC);
337 -- Do not allow non-contiguous field
341 ("attempt to specify non-contiguous field "
342 & "not permitted", CLC);
344 ("\caused by non-standard Bit_Order "
347 ("\consider possibility of using "
348 & "Ada 2005 mode here", CLC);
351 -- Case where field fits in one storage unit
354 -- Give warning if suspicious component clause
356 if Intval (FB) >= System_Storage_Unit
357 and then Warn_On_Reverse_Bit_Order
360 ("info: Bit_Order clause does not affect " &
361 "byte ordering?V?", Pos);
363 Intval (Pos) + Intval (FB) /
366 ("info: position normalized to ^ before bit " &
367 "order interpreted?V?", Pos);
370 -- Here is where we fix up the Component_Bit_Offset value
371 -- to account for the reverse bit order. Some examples of
372 -- what needs to be done are:
374 -- First_Bit .. Last_Bit Component_Bit_Offset
386 -- The rule is that the first bit is is obtained by
387 -- subtracting the old ending bit from storage_unit - 1.
389 Set_Component_Bit_Offset
391 (Storage_Unit_Offset * System_Storage_Unit) +
392 (System_Storage_Unit - 1) -
393 (Start_Bit + CSZ - 1));
395 Set_Normalized_First_Bit
397 Component_Bit_Offset (Comp) mod
398 System_Storage_Unit);
403 Next_Component_Or_Discriminant (Comp);
406 -- For Ada 2005, we do machine scalar processing, as fully described In
407 -- AI-133. This involves gathering all components which start at the
408 -- same byte offset and processing them together. Same approach is still
409 -- valid in later versions including Ada 2012.
413 Max_Machine_Scalar_Size : constant Uint :=
415 (Standard_Long_Long_Integer_Size);
416 -- We use this as the maximum machine scalar size
419 SSU : constant Uint := UI_From_Int (System_Storage_Unit);
422 -- This first loop through components does two things. First it
423 -- deals with the case of components with component clauses whose
424 -- length is greater than the maximum machine scalar size (either
425 -- accepting them or rejecting as needed). Second, it counts the
426 -- number of components with component clauses whose length does
427 -- not exceed this maximum for later processing.
430 Comp := First_Component_Or_Discriminant (R);
431 while Present (Comp) loop
432 CC := Component_Clause (Comp);
436 Fbit : constant Uint := Static_Integer (First_Bit (CC));
437 Lbit : constant Uint := Static_Integer (Last_Bit (CC));
440 -- Case of component with last bit >= max machine scalar
442 if Lbit >= Max_Machine_Scalar_Size then
444 -- This is allowed only if first bit is zero, and
445 -- last bit + 1 is a multiple of storage unit size.
447 if Fbit = 0 and then (Lbit + 1) mod SSU = 0 then
449 -- This is the case to give a warning if enabled
451 if Warn_On_Reverse_Bit_Order then
453 ("info: multi-byte field specified with "
454 & " non-standard Bit_Order?V?", CC);
456 if Bytes_Big_Endian then
458 ("\bytes are not reversed "
459 & "(component is big-endian)?V?", CC);
462 ("\bytes are not reversed "
463 & "(component is little-endian)?V?", CC);
467 -- Give error message for RM 13.5.1(10) violation
471 ("machine scalar rules not followed for&",
472 First_Bit (CC), Comp);
474 Error_Msg_Uint_1 := Lbit;
475 Error_Msg_Uint_2 := Max_Machine_Scalar_Size;
477 ("\last bit (^) exceeds maximum machine "
481 if (Lbit + 1) mod SSU /= 0 then
482 Error_Msg_Uint_1 := SSU;
484 ("\and is not a multiple of Storage_Unit (^) "
489 Error_Msg_Uint_1 := Fbit;
491 ("\and first bit (^) is non-zero "
497 -- OK case of machine scalar related component clause,
498 -- For now, just count them.
501 Num_CC := Num_CC + 1;
506 Next_Component_Or_Discriminant (Comp);
509 -- We need to sort the component clauses on the basis of the
510 -- Position values in the clause, so we can group clauses with
511 -- the same Position together to determine the relevant machine
515 Comps : array (0 .. Num_CC) of Entity_Id;
516 -- Array to collect component and discriminant entities. The
517 -- data starts at index 1, the 0'th entry is for the sort
520 function CP_Lt (Op1, Op2 : Natural) return Boolean;
521 -- Compare routine for Sort
523 procedure CP_Move (From : Natural; To : Natural);
524 -- Move routine for Sort
526 package Sorting is new GNAT.Heap_Sort_G (CP_Move, CP_Lt);
530 -- Start and stop positions in the component list of the set of
531 -- components with the same starting position (that constitute
532 -- components in a single machine scalar).
535 -- Maximum last bit value of any component in this set
538 -- Corresponding machine scalar size
544 function CP_Lt (Op1, Op2 : Natural) return Boolean is
546 return Position (Component_Clause (Comps (Op1))) <
547 Position (Component_Clause (Comps (Op2)));
554 procedure CP_Move (From : Natural; To : Natural) is
556 Comps (To) := Comps (From);
559 -- Start of processing for Sort_CC
562 -- Collect the machine scalar relevant component clauses
565 Comp := First_Component_Or_Discriminant (R);
566 while Present (Comp) loop
568 CC : constant Node_Id := Component_Clause (Comp);
571 -- Collect only component clauses whose last bit is less
572 -- than machine scalar size. Any component clause whose
573 -- last bit exceeds this value does not take part in
574 -- machine scalar layout considerations. The test for
575 -- Error_Posted makes sure we exclude component clauses
576 -- for which we already posted an error.
579 and then not Error_Posted (Last_Bit (CC))
580 and then Static_Integer (Last_Bit (CC)) <
581 Max_Machine_Scalar_Size
583 Num_CC := Num_CC + 1;
584 Comps (Num_CC) := Comp;
588 Next_Component_Or_Discriminant (Comp);
591 -- Sort by ascending position number
593 Sorting.Sort (Num_CC);
595 -- We now have all the components whose size does not exceed
596 -- the max machine scalar value, sorted by starting position.
597 -- In this loop we gather groups of clauses starting at the
598 -- same position, to process them in accordance with AI-133.
601 while Stop < Num_CC loop
606 (Last_Bit (Component_Clause (Comps (Start))));
607 while Stop < Num_CC loop
609 (Position (Component_Clause (Comps (Stop + 1)))) =
611 (Position (Component_Clause (Comps (Stop))))
619 (Component_Clause (Comps (Stop)))));
625 -- Now we have a group of component clauses from Start to
626 -- Stop whose positions are identical, and MaxL is the
627 -- maximum last bit value of any of these components.
629 -- We need to determine the corresponding machine scalar
630 -- size. This loop assumes that machine scalar sizes are
631 -- even, and that each possible machine scalar has twice
632 -- as many bits as the next smaller one.
634 MSS := Max_Machine_Scalar_Size;
636 and then (MSS / 2) >= SSU
637 and then (MSS / 2) > MaxL
642 -- Here is where we fix up the Component_Bit_Offset value
643 -- to account for the reverse bit order. Some examples of
644 -- what needs to be done for the case of a machine scalar
647 -- First_Bit .. Last_Bit Component_Bit_Offset
659 -- The rule is that the first bit is obtained by subtracting
660 -- the old ending bit from machine scalar size - 1.
662 for C in Start .. Stop loop
664 Comp : constant Entity_Id := Comps (C);
665 CC : constant Node_Id := Component_Clause (Comp);
667 LB : constant Uint := Static_Integer (Last_Bit (CC));
668 NFB : constant Uint := MSS - Uint_1 - LB;
669 NLB : constant Uint := NFB + Esize (Comp) - 1;
670 Pos : constant Uint := Static_Integer (Position (CC));
673 if Warn_On_Reverse_Bit_Order then
674 Error_Msg_Uint_1 := MSS;
676 ("info: reverse bit order in machine " &
677 "scalar of length^?V?", First_Bit (CC));
678 Error_Msg_Uint_1 := NFB;
679 Error_Msg_Uint_2 := NLB;
681 if Bytes_Big_Endian then
683 ("\big-endian range for component "
684 & "& is ^ .. ^?V?", First_Bit (CC), Comp);
687 ("\little-endian range for component"
688 & "& is ^ .. ^?V?", First_Bit (CC), Comp);
692 Set_Component_Bit_Offset (Comp, Pos * SSU + NFB);
693 Set_Normalized_First_Bit (Comp, NFB mod SSU);
700 end Adjust_Record_For_Reverse_Bit_Order;
702 -------------------------------------
703 -- Alignment_Check_For_Size_Change --
704 -------------------------------------
706 procedure Alignment_Check_For_Size_Change (Typ : Entity_Id; Size : Uint) is
708 -- If the alignment is known, and not set by a rep clause, and is
709 -- inconsistent with the size being set, then reset it to unknown,
710 -- we assume in this case that the size overrides the inherited
711 -- alignment, and that the alignment must be recomputed.
713 if Known_Alignment (Typ)
714 and then not Has_Alignment_Clause (Typ)
715 and then Size mod (Alignment (Typ) * SSU) /= 0
717 Init_Alignment (Typ);
719 end Alignment_Check_For_Size_Change;
721 -------------------------------------
722 -- Analyze_Aspects_At_Freeze_Point --
723 -------------------------------------
725 procedure Analyze_Aspects_At_Freeze_Point (E : Entity_Id) is
730 procedure Analyze_Aspect_Default_Value (ASN : Node_Id);
731 -- This routine analyzes an Aspect_Default_[Component_]Value denoted by
732 -- the aspect specification node ASN.
734 procedure Inherit_Delayed_Rep_Aspects (ASN : Node_Id);
735 -- As discussed in the spec of Aspects (see Aspect_Delay declaration),
736 -- a derived type can inherit aspects from its parent which have been
737 -- specified at the time of the derivation using an aspect, as in:
739 -- type A is range 1 .. 10
740 -- with Size => Not_Defined_Yet;
744 -- Not_Defined_Yet : constant := 64;
746 -- In this example, the Size of A is considered to be specified prior
747 -- to the derivation, and thus inherited, even though the value is not
748 -- known at the time of derivation. To deal with this, we use two entity
749 -- flags. The flag Has_Derived_Rep_Aspects is set in the parent type (A
750 -- here), and then the flag May_Inherit_Delayed_Rep_Aspects is set in
751 -- the derived type (B here). If this flag is set when the derived type
752 -- is frozen, then this procedure is called to ensure proper inheritance
753 -- of all delayed aspects from the parent type. The derived type is E,
754 -- the argument to Analyze_Aspects_At_Freeze_Point. ASN is the first
755 -- aspect specification node in the Rep_Item chain for the parent type.
757 procedure Make_Pragma_From_Boolean_Aspect (ASN : Node_Id);
758 -- Given an aspect specification node ASN whose expression is an
759 -- optional Boolean, this routines creates the corresponding pragma
760 -- at the freezing point.
762 ----------------------------------
763 -- Analyze_Aspect_Default_Value --
764 ----------------------------------
766 procedure Analyze_Aspect_Default_Value (ASN : Node_Id) is
767 Ent : constant Entity_Id := Entity (ASN);
768 Expr : constant Node_Id := Expression (ASN);
769 Id : constant Node_Id := Identifier (ASN);
772 Error_Msg_Name_1 := Chars (Id);
774 if not Is_Type (Ent) then
775 Error_Msg_N ("aspect% can only apply to a type", Id);
778 elsif not Is_First_Subtype (Ent) then
779 Error_Msg_N ("aspect% cannot apply to subtype", Id);
782 elsif A_Id = Aspect_Default_Value
783 and then not Is_Scalar_Type (Ent)
785 Error_Msg_N ("aspect% can only be applied to scalar type", Id);
788 elsif A_Id = Aspect_Default_Component_Value then
789 if not Is_Array_Type (Ent) then
790 Error_Msg_N ("aspect% can only be applied to array type", Id);
793 elsif not Is_Scalar_Type (Component_Type (Ent)) then
794 Error_Msg_N ("aspect% requires scalar components", Id);
799 Set_Has_Default_Aspect (Base_Type (Ent));
801 if Is_Scalar_Type (Ent) then
802 Set_Default_Aspect_Value (Base_Type (Ent), Expr);
804 Set_Default_Aspect_Component_Value (Base_Type (Ent), Expr);
806 end Analyze_Aspect_Default_Value;
808 ---------------------------------
809 -- Inherit_Delayed_Rep_Aspects --
810 ---------------------------------
812 procedure Inherit_Delayed_Rep_Aspects (ASN : Node_Id) is
813 P : constant Entity_Id := Entity (ASN);
814 -- Entithy for parent type
817 -- Item from Rep_Item chain
822 -- Loop through delayed aspects for the parent type
825 while Present (N) loop
826 if Nkind (N) = N_Aspect_Specification then
827 exit when Entity (N) /= P;
829 if Is_Delayed_Aspect (N) then
830 A := Get_Aspect_Id (Chars (Identifier (N)));
832 -- Process delayed rep aspect. For Boolean attributes it is
833 -- not possible to cancel an attribute once set (the attempt
834 -- to use an aspect with xxx => False is an error) for a
835 -- derived type. So for those cases, we do not have to check
836 -- if a clause has been given for the derived type, since it
837 -- is harmless to set it again if it is already set.
843 when Aspect_Alignment =>
844 if not Has_Alignment_Clause (E) then
845 Set_Alignment (E, Alignment (P));
850 when Aspect_Atomic =>
851 if Is_Atomic (P) then
857 when Aspect_Atomic_Components =>
858 if Has_Atomic_Components (P) then
859 Set_Has_Atomic_Components (Base_Type (E));
864 when Aspect_Bit_Order =>
865 if Is_Record_Type (E)
866 and then No (Get_Attribute_Definition_Clause
867 (E, Attribute_Bit_Order))
868 and then Reverse_Bit_Order (P)
870 Set_Reverse_Bit_Order (Base_Type (E));
875 when Aspect_Component_Size =>
877 and then not Has_Component_Size_Clause (E)
880 (Base_Type (E), Component_Size (P));
885 when Aspect_Machine_Radix =>
886 if Is_Decimal_Fixed_Point_Type (E)
887 and then not Has_Machine_Radix_Clause (E)
889 Set_Machine_Radix_10 (E, Machine_Radix_10 (P));
892 -- Object_Size (also Size which also sets Object_Size)
894 when Aspect_Object_Size | Aspect_Size =>
895 if not Has_Size_Clause (E)
897 No (Get_Attribute_Definition_Clause
898 (E, Attribute_Object_Size))
900 Set_Esize (E, Esize (P));
906 if not Is_Packed (E) then
907 Set_Is_Packed (Base_Type (E));
909 if Is_Bit_Packed_Array (P) then
910 Set_Is_Bit_Packed_Array (Base_Type (E));
911 Set_Packed_Array_Impl_Type
912 (E, Packed_Array_Impl_Type (P));
916 -- Scalar_Storage_Order
918 when Aspect_Scalar_Storage_Order =>
919 if (Is_Record_Type (E) or else Is_Array_Type (E))
920 and then No (Get_Attribute_Definition_Clause
921 (E, Attribute_Scalar_Storage_Order))
922 and then Reverse_Storage_Order (P)
924 Set_Reverse_Storage_Order (Base_Type (E));
926 -- Clear default SSO indications, since the aspect
927 -- overrides the default.
929 Set_SSO_Set_Low_By_Default (Base_Type (E), False);
930 Set_SSO_Set_High_By_Default (Base_Type (E), False);
936 if Is_Fixed_Point_Type (E)
937 and then not Has_Small_Clause (E)
939 Set_Small_Value (E, Small_Value (P));
944 when Aspect_Storage_Size =>
945 if (Is_Access_Type (E) or else Is_Task_Type (E))
946 and then not Has_Storage_Size_Clause (E)
948 Set_Storage_Size_Variable
949 (Base_Type (E), Storage_Size_Variable (P));
954 when Aspect_Value_Size =>
956 -- Value_Size is never inherited, it is either set by
957 -- default, or it is explicitly set for the derived
958 -- type. So nothing to do here.
964 when Aspect_Volatile =>
965 if Is_Volatile (P) then
969 -- Volatile_Full_Access
971 when Aspect_Volatile_Full_Access =>
972 if Is_Volatile_Full_Access (P) then
973 Set_Is_Volatile_Full_Access (E);
976 -- Volatile_Components
978 when Aspect_Volatile_Components =>
979 if Has_Volatile_Components (P) then
980 Set_Has_Volatile_Components (Base_Type (E));
983 -- That should be all the Rep Aspects
986 pragma Assert (Aspect_Delay (A_Id) /= Rep_Aspect);
993 N := Next_Rep_Item (N);
995 end Inherit_Delayed_Rep_Aspects;
997 -------------------------------------
998 -- Make_Pragma_From_Boolean_Aspect --
999 -------------------------------------
1001 procedure Make_Pragma_From_Boolean_Aspect (ASN : Node_Id) is
1002 Ident : constant Node_Id := Identifier (ASN);
1003 A_Name : constant Name_Id := Chars (Ident);
1004 A_Id : constant Aspect_Id := Get_Aspect_Id (A_Name);
1005 Ent : constant Entity_Id := Entity (ASN);
1006 Expr : constant Node_Id := Expression (ASN);
1007 Loc : constant Source_Ptr := Sloc (ASN);
1011 procedure Check_False_Aspect_For_Derived_Type;
1012 -- This procedure checks for the case of a false aspect for a derived
1013 -- type, which improperly tries to cancel an aspect inherited from
1016 -----------------------------------------
1017 -- Check_False_Aspect_For_Derived_Type --
1018 -----------------------------------------
1020 procedure Check_False_Aspect_For_Derived_Type is
1024 -- We are only checking derived types
1026 if not Is_Derived_Type (E) then
1030 Par := Nearest_Ancestor (E);
1033 when Aspect_Atomic | Aspect_Shared =>
1034 if not Is_Atomic (Par) then
1038 when Aspect_Atomic_Components =>
1039 if not Has_Atomic_Components (Par) then
1043 when Aspect_Discard_Names =>
1044 if not Discard_Names (Par) then
1049 if not Is_Packed (Par) then
1053 when Aspect_Unchecked_Union =>
1054 if not Is_Unchecked_Union (Par) then
1058 when Aspect_Volatile =>
1059 if not Is_Volatile (Par) then
1063 when Aspect_Volatile_Components =>
1064 if not Has_Volatile_Components (Par) then
1068 when Aspect_Volatile_Full_Access =>
1069 if not Is_Volatile_Full_Access (Par) then
1077 -- Fall through means we are canceling an inherited aspect
1079 Error_Msg_Name_1 := A_Name;
1081 ("derived type& inherits aspect%, cannot cancel", Expr, E);
1082 end Check_False_Aspect_For_Derived_Type;
1084 -- Start of processing for Make_Pragma_From_Boolean_Aspect
1087 -- Note that we know Expr is present, because for a missing Expr
1088 -- argument, we knew it was True and did not need to delay the
1089 -- evaluation to the freeze point.
1091 if Is_False (Static_Boolean (Expr)) then
1092 Check_False_Aspect_For_Derived_Type;
1097 Pragma_Argument_Associations => New_List (
1098 Make_Pragma_Argument_Association (Sloc (Ident),
1099 Expression => New_Occurrence_Of (Ent, Sloc (Ident)))),
1101 Pragma_Identifier =>
1102 Make_Identifier (Sloc (Ident), Chars (Ident)));
1104 Set_From_Aspect_Specification (Prag, True);
1105 Set_Corresponding_Aspect (Prag, ASN);
1106 Set_Aspect_Rep_Item (ASN, Prag);
1107 Set_Is_Delayed_Aspect (Prag);
1108 Set_Parent (Prag, ASN);
1110 end Make_Pragma_From_Boolean_Aspect;
1112 -- Start of processing for Analyze_Aspects_At_Freeze_Point
1115 -- Must be visible in current scope
1117 if not Scope_Within_Or_Same (Current_Scope, Scope (E)) then
1121 -- Look for aspect specification entries for this entity
1123 ASN := First_Rep_Item (E);
1124 while Present (ASN) loop
1125 if Nkind (ASN) = N_Aspect_Specification then
1126 exit when Entity (ASN) /= E;
1128 if Is_Delayed_Aspect (ASN) then
1129 A_Id := Get_Aspect_Id (ASN);
1133 -- For aspects whose expression is an optional Boolean, make
1134 -- the corresponding pragma at the freeze point.
1136 when Boolean_Aspects |
1137 Library_Unit_Aspects =>
1138 Make_Pragma_From_Boolean_Aspect (ASN);
1140 -- Special handling for aspects that don't correspond to
1141 -- pragmas/attributes.
1143 when Aspect_Default_Value |
1144 Aspect_Default_Component_Value =>
1146 -- Do not inherit aspect for anonymous base type of a
1147 -- scalar or array type, because they apply to the first
1148 -- subtype of the type, and will be processed when that
1149 -- first subtype is frozen.
1151 if Is_Derived_Type (E)
1152 and then not Comes_From_Source (E)
1153 and then E /= First_Subtype (E)
1157 Analyze_Aspect_Default_Value (ASN);
1160 -- Ditto for iterator aspects, because the corresponding
1161 -- attributes may not have been analyzed yet.
1163 when Aspect_Constant_Indexing |
1164 Aspect_Variable_Indexing |
1165 Aspect_Default_Iterator |
1166 Aspect_Iterator_Element =>
1167 Analyze (Expression (ASN));
1169 if Etype (Expression (ASN)) = Any_Type then
1171 ("\aspect must be fully defined before & is frozen",
1175 when Aspect_Iterable =>
1176 Validate_Iterable_Aspect (E, ASN);
1182 Ritem := Aspect_Rep_Item (ASN);
1184 if Present (Ritem) then
1190 Next_Rep_Item (ASN);
1193 -- This is where we inherit delayed rep aspects from our parent. Note
1194 -- that if we fell out of the above loop with ASN non-empty, it means
1195 -- we hit an aspect for an entity other than E, and it must be the
1196 -- type from which we were derived.
1198 if May_Inherit_Delayed_Rep_Aspects (E) then
1199 Inherit_Delayed_Rep_Aspects (ASN);
1201 end Analyze_Aspects_At_Freeze_Point;
1203 -----------------------------------
1204 -- Analyze_Aspect_Specifications --
1205 -----------------------------------
1207 procedure Analyze_Aspect_Specifications (N : Node_Id; E : Entity_Id) is
1208 procedure Decorate (Asp : Node_Id; Prag : Node_Id);
1209 -- Establish linkages between an aspect and its corresponding pragma
1211 procedure Insert_After_SPARK_Mode
1215 -- Subsidiary to the analysis of aspects Abstract_State, Ghost,
1216 -- Initializes, Initial_Condition and Refined_State. Insert node Prag
1217 -- before node Ins_Nod. If Ins_Nod is for pragma SPARK_Mode, then skip
1218 -- SPARK_Mode. Decls is the associated declarative list where Prag is to
1221 procedure Insert_Pragma (Prag : Node_Id);
1222 -- Subsidiary to the analysis of aspects Attach_Handler, Contract_Cases,
1223 -- Depends, Global, Post, Pre, Refined_Depends and Refined_Global.
1224 -- Insert pragma Prag such that it mimics the placement of a source
1225 -- pragma of the same kind.
1227 -- procedure Proc (Formal : ...) with Global => ...;
1229 -- procedure Proc (Formal : ...);
1230 -- pragma Global (...);
1236 procedure Decorate (Asp : Node_Id; Prag : Node_Id) is
1238 Set_Aspect_Rep_Item (Asp, Prag);
1239 Set_Corresponding_Aspect (Prag, Asp);
1240 Set_From_Aspect_Specification (Prag);
1241 Set_Parent (Prag, Asp);
1244 -----------------------------
1245 -- Insert_After_SPARK_Mode --
1246 -----------------------------
1248 procedure Insert_After_SPARK_Mode
1253 Decl : Node_Id := Ins_Nod;
1259 and then Nkind (Decl) = N_Pragma
1260 and then Pragma_Name (Decl) = Name_SPARK_Mode
1262 Decl := Next (Decl);
1265 if Present (Decl) then
1266 Insert_Before (Decl, Prag);
1268 -- Aitem acts as the last declaration
1271 Append_To (Decls, Prag);
1273 end Insert_After_SPARK_Mode;
1279 procedure Insert_Pragma (Prag : Node_Id) is
1284 if Nkind (N) = N_Subprogram_Body then
1285 if Present (Declarations (N)) then
1287 -- Skip other internally generated pragmas from aspects to find
1288 -- the proper insertion point. As a result the order of pragmas
1289 -- is the same as the order of aspects.
1291 -- As precondition pragmas generated from conjuncts in the
1292 -- precondition aspect are presented in reverse order to
1293 -- Insert_Pragma, insert them in the correct order here by not
1294 -- skipping previously inserted precondition pragmas when the
1295 -- current pragma is a precondition.
1297 Decl := First (Declarations (N));
1298 while Present (Decl) loop
1299 if Nkind (Decl) = N_Pragma
1300 and then From_Aspect_Specification (Decl)
1301 and then not (Get_Pragma_Id (Decl) = Pragma_Precondition
1303 Get_Pragma_Id (Prag) = Pragma_Precondition)
1311 if Present (Decl) then
1312 Insert_Before (Decl, Prag);
1314 Append (Prag, Declarations (N));
1317 Set_Declarations (N, New_List (Prag));
1320 -- When the context is a library unit, the pragma is added to the
1321 -- Pragmas_After list.
1323 elsif Nkind (Parent (N)) = N_Compilation_Unit then
1324 Aux := Aux_Decls_Node (Parent (N));
1326 if No (Pragmas_After (Aux)) then
1327 Set_Pragmas_After (Aux, New_List);
1330 Prepend (Prag, Pragmas_After (Aux));
1335 Insert_After (N, Prag);
1345 L : constant List_Id := Aspect_Specifications (N);
1347 Ins_Node : Node_Id := N;
1348 -- Insert pragmas/attribute definition clause after this node when no
1349 -- delayed analysis is required.
1351 -- Start of processing for Analyze_Aspect_Specifications
1353 -- The general processing involves building an attribute definition
1354 -- clause or a pragma node that corresponds to the aspect. Then in order
1355 -- to delay the evaluation of this aspect to the freeze point, we attach
1356 -- the corresponding pragma/attribute definition clause to the aspect
1357 -- specification node, which is then placed in the Rep Item chain. In
1358 -- this case we mark the entity by setting the flag Has_Delayed_Aspects
1359 -- and we evaluate the rep item at the freeze point. When the aspect
1360 -- doesn't have a corresponding pragma/attribute definition clause, then
1361 -- its analysis is simply delayed at the freeze point.
1363 -- Some special cases don't require delay analysis, thus the aspect is
1364 -- analyzed right now.
1366 -- Note that there is a special handling for Pre, Post, Test_Case,
1367 -- Contract_Cases aspects. In these cases, we do not have to worry
1368 -- about delay issues, since the pragmas themselves deal with delay
1369 -- of visibility for the expression analysis. Thus, we just insert
1370 -- the pragma after the node N.
1373 pragma Assert (Present (L));
1375 -- Loop through aspects
1377 Aspect := First (L);
1378 Aspect_Loop : while Present (Aspect) loop
1379 Analyze_One_Aspect : declare
1380 Expr : constant Node_Id := Expression (Aspect);
1381 Id : constant Node_Id := Identifier (Aspect);
1382 Loc : constant Source_Ptr := Sloc (Aspect);
1383 Nam : constant Name_Id := Chars (Id);
1384 A_Id : constant Aspect_Id := Get_Aspect_Id (Nam);
1387 Delay_Required : Boolean;
1388 -- Set False if delay is not required
1390 Eloc : Source_Ptr := No_Location;
1391 -- Source location of expression, modified when we split PPC's. It
1392 -- is set below when Expr is present.
1394 procedure Analyze_Aspect_External_Or_Link_Name;
1395 -- Perform analysis of the External_Name or Link_Name aspects
1397 procedure Analyze_Aspect_Implicit_Dereference;
1398 -- Perform analysis of the Implicit_Dereference aspects
1400 procedure Make_Aitem_Pragma
1401 (Pragma_Argument_Associations : List_Id;
1402 Pragma_Name : Name_Id);
1403 -- This is a wrapper for Make_Pragma used for converting aspects
1404 -- to pragmas. It takes care of Sloc (set from Loc) and building
1405 -- the pragma identifier from the given name. In addition the
1406 -- flags Class_Present and Split_PPC are set from the aspect
1407 -- node, as well as Is_Ignored. This routine also sets the
1408 -- From_Aspect_Specification in the resulting pragma node to
1409 -- True, and sets Corresponding_Aspect to point to the aspect.
1410 -- The resulting pragma is assigned to Aitem.
1412 ------------------------------------------
1413 -- Analyze_Aspect_External_Or_Link_Name --
1414 ------------------------------------------
1416 procedure Analyze_Aspect_External_Or_Link_Name is
1418 -- Verify that there is an Import/Export aspect defined for the
1419 -- entity. The processing of that aspect in turn checks that
1420 -- there is a Convention aspect declared. The pragma is
1421 -- constructed when processing the Convention aspect.
1428 while Present (A) loop
1429 exit when Nam_In (Chars (Identifier (A)), Name_Export,
1436 ("missing Import/Export for Link/External name",
1440 end Analyze_Aspect_External_Or_Link_Name;
1442 -----------------------------------------
1443 -- Analyze_Aspect_Implicit_Dereference --
1444 -----------------------------------------
1446 procedure Analyze_Aspect_Implicit_Dereference is
1448 if not Is_Type (E) or else not Has_Discriminants (E) then
1450 ("aspect must apply to a type with discriminants", N);
1457 Disc := First_Discriminant (E);
1458 while Present (Disc) loop
1459 if Chars (Expr) = Chars (Disc)
1460 and then Ekind (Etype (Disc)) =
1461 E_Anonymous_Access_Type
1463 Set_Has_Implicit_Dereference (E);
1464 Set_Has_Implicit_Dereference (Disc);
1468 Next_Discriminant (Disc);
1471 -- Error if no proper access discriminant.
1474 ("not an access discriminant of&", Expr, E);
1477 end Analyze_Aspect_Implicit_Dereference;
1479 -----------------------
1480 -- Make_Aitem_Pragma --
1481 -----------------------
1483 procedure Make_Aitem_Pragma
1484 (Pragma_Argument_Associations : List_Id;
1485 Pragma_Name : Name_Id)
1487 Args : List_Id := Pragma_Argument_Associations;
1490 -- We should never get here if aspect was disabled
1492 pragma Assert (not Is_Disabled (Aspect));
1494 -- Certain aspects allow for an optional name or expression. Do
1495 -- not generate a pragma with empty argument association list.
1497 if No (Args) or else No (Expression (First (Args))) then
1505 Pragma_Argument_Associations => Args,
1506 Pragma_Identifier =>
1507 Make_Identifier (Sloc (Id), Pragma_Name),
1508 Class_Present => Class_Present (Aspect),
1509 Split_PPC => Split_PPC (Aspect));
1511 -- Set additional semantic fields
1513 if Is_Ignored (Aspect) then
1514 Set_Is_Ignored (Aitem);
1515 elsif Is_Checked (Aspect) then
1516 Set_Is_Checked (Aitem);
1519 Set_Corresponding_Aspect (Aitem, Aspect);
1520 Set_From_Aspect_Specification (Aitem, True);
1521 end Make_Aitem_Pragma;
1523 -- Start of processing for Analyze_One_Aspect
1526 -- Skip aspect if already analyzed, to avoid looping in some cases
1528 if Analyzed (Aspect) then
1532 -- Skip looking at aspect if it is totally disabled. Just mark it
1533 -- as such for later reference in the tree. This also sets the
1534 -- Is_Ignored and Is_Checked flags appropriately.
1536 Check_Applicable_Policy (Aspect);
1538 if Is_Disabled (Aspect) then
1542 -- Set the source location of expression, used in the case of
1543 -- a failed precondition/postcondition or invariant. Note that
1544 -- the source location of the expression is not usually the best
1545 -- choice here. For example, it gets located on the last AND
1546 -- keyword in a chain of boolean expressiond AND'ed together.
1547 -- It is best to put the message on the first character of the
1548 -- assertion, which is the effect of the First_Node call here.
1550 if Present (Expr) then
1551 Eloc := Sloc (First_Node (Expr));
1554 -- Check restriction No_Implementation_Aspect_Specifications
1556 if Implementation_Defined_Aspect (A_Id) then
1558 (No_Implementation_Aspect_Specifications, Aspect);
1561 -- Check restriction No_Specification_Of_Aspect
1563 Check_Restriction_No_Specification_Of_Aspect (Aspect);
1565 -- Mark aspect analyzed (actual analysis is delayed till later)
1567 Set_Analyzed (Aspect);
1568 Set_Entity (Aspect, E);
1569 Ent := New_Occurrence_Of (E, Sloc (Id));
1571 -- Check for duplicate aspect. Note that the Comes_From_Source
1572 -- test allows duplicate Pre/Post's that we generate internally
1573 -- to escape being flagged here.
1575 if No_Duplicates_Allowed (A_Id) then
1577 while Anod /= Aspect loop
1578 if Comes_From_Source (Aspect)
1579 and then Same_Aspect (A_Id, Get_Aspect_Id (Anod))
1581 Error_Msg_Name_1 := Nam;
1582 Error_Msg_Sloc := Sloc (Anod);
1584 -- Case of same aspect specified twice
1586 if Class_Present (Anod) = Class_Present (Aspect) then
1587 if not Class_Present (Anod) then
1589 ("aspect% for & previously given#",
1593 ("aspect `%''Class` for & previously given#",
1603 -- Check some general restrictions on language defined aspects
1605 if not Implementation_Defined_Aspect (A_Id) then
1606 Error_Msg_Name_1 := Nam;
1608 -- Not allowed for renaming declarations
1610 if Nkind (N) in N_Renaming_Declaration then
1612 ("aspect % not allowed for renaming declaration",
1616 -- Not allowed for formal type declarations
1618 if Nkind (N) = N_Formal_Type_Declaration then
1620 ("aspect % not allowed for formal type declaration",
1625 -- Copy expression for later processing by the procedures
1626 -- Check_Aspect_At_[Freeze_Point | End_Of_Declarations]
1628 Set_Entity (Id, New_Copy_Tree (Expr));
1630 -- Set Delay_Required as appropriate to aspect
1632 case Aspect_Delay (A_Id) is
1633 when Always_Delay =>
1634 Delay_Required := True;
1637 Delay_Required := False;
1641 -- If expression has the form of an integer literal, then
1642 -- do not delay, since we know the value cannot change.
1643 -- This optimization catches most rep clause cases.
1645 -- For Boolean aspects, don't delay if no expression
1647 if A_Id in Boolean_Aspects and then No (Expr) then
1648 Delay_Required := False;
1650 -- For non-Boolean aspects, don't delay if integer literal
1652 elsif A_Id not in Boolean_Aspects
1653 and then Present (Expr)
1654 and then Nkind (Expr) = N_Integer_Literal
1656 Delay_Required := False;
1658 -- All other cases are delayed
1661 Delay_Required := True;
1662 Set_Has_Delayed_Rep_Aspects (E);
1666 -- Processing based on specific aspect
1669 when Aspect_Unimplemented =>
1670 null; -- ??? temp for now
1672 -- No_Aspect should be impossible
1675 raise Program_Error;
1677 -- Case 1: Aspects corresponding to attribute definition
1680 when Aspect_Address |
1683 Aspect_Component_Size |
1684 Aspect_Constant_Indexing |
1685 Aspect_Default_Iterator |
1686 Aspect_Dispatching_Domain |
1687 Aspect_External_Tag |
1690 Aspect_Iterator_Element |
1691 Aspect_Machine_Radix |
1692 Aspect_Object_Size |
1695 Aspect_Scalar_Storage_Order |
1698 Aspect_Simple_Storage_Pool |
1699 Aspect_Storage_Pool |
1700 Aspect_Stream_Size |
1702 Aspect_Variable_Indexing |
1705 -- Indexing aspects apply only to tagged type
1707 if (A_Id = Aspect_Constant_Indexing
1709 A_Id = Aspect_Variable_Indexing)
1710 and then not (Is_Type (E)
1711 and then Is_Tagged_Type (E))
1714 ("indexing aspect can only apply to a tagged type",
1719 -- For the case of aspect Address, we don't consider that we
1720 -- know the entity is never set in the source, since it is
1721 -- is likely aliasing is occurring.
1723 -- Note: one might think that the analysis of the resulting
1724 -- attribute definition clause would take care of that, but
1725 -- that's not the case since it won't be from source.
1727 if A_Id = Aspect_Address then
1728 Set_Never_Set_In_Source (E, False);
1731 -- Correctness of the profile of a stream operation is
1732 -- verified at the freeze point, but we must detect the
1733 -- illegal specification of this aspect for a subtype now,
1734 -- to prevent malformed rep_item chains.
1736 if A_Id = Aspect_Input or else
1737 A_Id = Aspect_Output or else
1738 A_Id = Aspect_Read or else
1741 if not Is_First_Subtype (E) then
1743 ("local name must be a first subtype", Aspect);
1746 -- If stream aspect applies to the class-wide type,
1747 -- the generated attribute definition applies to the
1748 -- class-wide type as well.
1750 elsif Class_Present (Aspect) then
1752 Make_Attribute_Reference (Loc,
1754 Attribute_Name => Name_Class);
1758 -- Construct the attribute definition clause
1761 Make_Attribute_Definition_Clause (Loc,
1763 Chars => Chars (Id),
1764 Expression => Relocate_Node (Expr));
1766 -- If the address is specified, then we treat the entity as
1767 -- referenced, to avoid spurious warnings. This is analogous
1768 -- to what is done with an attribute definition clause, but
1769 -- here we don't want to generate a reference because this
1770 -- is the point of definition of the entity.
1772 if A_Id = Aspect_Address then
1776 -- Case 2: Aspects corresponding to pragmas
1778 -- Case 2a: Aspects corresponding to pragmas with two
1779 -- arguments, where the first argument is a local name
1780 -- referring to the entity, and the second argument is the
1781 -- aspect definition expression.
1783 -- Linker_Section/Suppress/Unsuppress
1785 when Aspect_Linker_Section |
1787 Aspect_Unsuppress =>
1790 (Pragma_Argument_Associations => New_List (
1791 Make_Pragma_Argument_Association (Loc,
1792 Expression => New_Occurrence_Of (E, Loc)),
1793 Make_Pragma_Argument_Association (Sloc (Expr),
1794 Expression => Relocate_Node (Expr))),
1795 Pragma_Name => Chars (Id));
1799 -- Corresponds to pragma Implemented, construct the pragma
1801 when Aspect_Synchronization =>
1803 (Pragma_Argument_Associations => New_List (
1804 Make_Pragma_Argument_Association (Loc,
1805 Expression => New_Occurrence_Of (E, Loc)),
1806 Make_Pragma_Argument_Association (Sloc (Expr),
1807 Expression => Relocate_Node (Expr))),
1808 Pragma_Name => Name_Implemented);
1812 when Aspect_Attach_Handler =>
1814 (Pragma_Argument_Associations => New_List (
1815 Make_Pragma_Argument_Association (Sloc (Ent),
1817 Make_Pragma_Argument_Association (Sloc (Expr),
1818 Expression => Relocate_Node (Expr))),
1819 Pragma_Name => Name_Attach_Handler);
1821 -- We need to insert this pragma into the tree to get proper
1822 -- processing and to look valid from a placement viewpoint.
1824 Insert_Pragma (Aitem);
1827 -- Dynamic_Predicate, Predicate, Static_Predicate
1829 when Aspect_Dynamic_Predicate |
1831 Aspect_Static_Predicate =>
1833 -- These aspects apply only to subtypes
1835 if not Is_Type (E) then
1837 ("predicate can only be specified for a subtype",
1841 elsif Is_Incomplete_Type (E) then
1843 ("predicate cannot apply to incomplete view", Aspect);
1847 -- Construct the pragma (always a pragma Predicate, with
1848 -- flags recording whether it is static/dynamic). We also
1849 -- set flags recording this in the type itself.
1852 (Pragma_Argument_Associations => New_List (
1853 Make_Pragma_Argument_Association (Sloc (Ent),
1855 Make_Pragma_Argument_Association (Sloc (Expr),
1856 Expression => Relocate_Node (Expr))),
1857 Pragma_Name => Name_Predicate);
1859 -- Mark type has predicates, and remember what kind of
1860 -- aspect lead to this predicate (we need this to access
1861 -- the right set of check policies later on).
1863 Set_Has_Predicates (E);
1865 if A_Id = Aspect_Dynamic_Predicate then
1866 Set_Has_Dynamic_Predicate_Aspect (E);
1867 elsif A_Id = Aspect_Static_Predicate then
1868 Set_Has_Static_Predicate_Aspect (E);
1871 -- If the type is private, indicate that its completion
1872 -- has a freeze node, because that is the one that will
1873 -- be visible at freeze time.
1875 if Is_Private_Type (E) and then Present (Full_View (E)) then
1876 Set_Has_Predicates (Full_View (E));
1878 if A_Id = Aspect_Dynamic_Predicate then
1879 Set_Has_Dynamic_Predicate_Aspect (Full_View (E));
1880 elsif A_Id = Aspect_Static_Predicate then
1881 Set_Has_Static_Predicate_Aspect (Full_View (E));
1884 Set_Has_Delayed_Aspects (Full_View (E));
1885 Ensure_Freeze_Node (Full_View (E));
1888 -- Case 2b: Aspects corresponding to pragmas with two
1889 -- arguments, where the second argument is a local name
1890 -- referring to the entity, and the first argument is the
1891 -- aspect definition expression.
1895 when Aspect_Convention =>
1897 -- The aspect may be part of the specification of an import
1898 -- or export pragma. Scan the aspect list to gather the
1899 -- other components, if any. The name of the generated
1900 -- pragma is one of Convention/Import/Export.
1903 Args : constant List_Id := New_List (
1904 Make_Pragma_Argument_Association (Sloc (Expr),
1905 Expression => Relocate_Node (Expr)),
1906 Make_Pragma_Argument_Association (Sloc (Ent),
1907 Expression => Ent));
1909 Imp_Exp_Seen : Boolean := False;
1910 -- Flag set when aspect Import or Export has been seen
1912 Imp_Seen : Boolean := False;
1913 -- Flag set when aspect Import has been seen
1917 Extern_Arg : Node_Id;
1922 Extern_Arg := Empty;
1924 Prag_Nam := Chars (Id);
1927 while Present (Asp) loop
1928 Asp_Nam := Chars (Identifier (Asp));
1930 -- Aspects Import and Export take precedence over
1931 -- aspect Convention. As a result the generated pragma
1932 -- must carry the proper interfacing aspect's name.
1934 if Nam_In (Asp_Nam, Name_Import, Name_Export) then
1935 if Imp_Exp_Seen then
1936 Error_Msg_N ("conflicting", Asp);
1938 Imp_Exp_Seen := True;
1940 if Asp_Nam = Name_Import then
1945 Prag_Nam := Asp_Nam;
1947 -- Aspect External_Name adds an extra argument to the
1948 -- generated pragma.
1950 elsif Asp_Nam = Name_External_Name then
1952 Make_Pragma_Argument_Association (Loc,
1954 Expression => Relocate_Node (Expression (Asp)));
1956 -- Aspect Link_Name adds an extra argument to the
1957 -- generated pragma.
1959 elsif Asp_Nam = Name_Link_Name then
1961 Make_Pragma_Argument_Association (Loc,
1963 Expression => Relocate_Node (Expression (Asp)));
1969 -- Assemble the full argument list
1971 if Present (Extern_Arg) then
1972 Append_To (Args, Extern_Arg);
1975 if Present (Link_Arg) then
1976 Append_To (Args, Link_Arg);
1980 (Pragma_Argument_Associations => Args,
1981 Pragma_Name => Prag_Nam);
1983 -- Store the generated pragma Import in the related
1986 if Imp_Seen and then Is_Subprogram (E) then
1987 Set_Import_Pragma (E, Aitem);
1991 -- CPU, Interrupt_Priority, Priority
1993 -- These three aspects can be specified for a subprogram spec
1994 -- or body, in which case we analyze the expression and export
1995 -- the value of the aspect.
1997 -- Previously, we generated an equivalent pragma for bodies
1998 -- (note that the specs cannot contain these pragmas). The
1999 -- pragma was inserted ahead of local declarations, rather than
2000 -- after the body. This leads to a certain duplication between
2001 -- the processing performed for the aspect and the pragma, but
2002 -- given the straightforward handling required it is simpler
2003 -- to duplicate than to translate the aspect in the spec into
2004 -- a pragma in the declarative part of the body.
2007 Aspect_Interrupt_Priority |
2010 if Nkind_In (N, N_Subprogram_Body,
2011 N_Subprogram_Declaration)
2013 -- Analyze the aspect expression
2015 Analyze_And_Resolve (Expr, Standard_Integer);
2017 -- Interrupt_Priority aspect not allowed for main
2018 -- subprograms. ARM D.1 does not forbid this explicitly,
2019 -- but ARM J.15.11 (6/3) does not permit pragma
2020 -- Interrupt_Priority for subprograms.
2022 if A_Id = Aspect_Interrupt_Priority then
2024 ("Interrupt_Priority aspect cannot apply to "
2025 & "subprogram", Expr);
2027 -- The expression must be static
2029 elsif not Is_OK_Static_Expression (Expr) then
2030 Flag_Non_Static_Expr
2031 ("aspect requires static expression!", Expr);
2033 -- Check whether this is the main subprogram. Issue a
2034 -- warning only if it is obviously not a main program
2035 -- (when it has parameters or when the subprogram is
2036 -- within a package).
2038 elsif Present (Parameter_Specifications
2039 (Specification (N)))
2040 or else not Is_Compilation_Unit (Defining_Entity (N))
2042 -- See ARM D.1 (14/3) and D.16 (12/3)
2045 ("aspect applied to subprogram other than the "
2046 & "main subprogram has no effect??", Expr);
2048 -- Otherwise check in range and export the value
2050 -- For the CPU aspect
2052 elsif A_Id = Aspect_CPU then
2053 if Is_In_Range (Expr, RTE (RE_CPU_Range)) then
2055 -- Value is correct so we export the value to make
2056 -- it available at execution time.
2059 (Main_Unit, UI_To_Int (Expr_Value (Expr)));
2063 ("main subprogram CPU is out of range", Expr);
2066 -- For the Priority aspect
2068 elsif A_Id = Aspect_Priority then
2069 if Is_In_Range (Expr, RTE (RE_Priority)) then
2071 -- Value is correct so we export the value to make
2072 -- it available at execution time.
2075 (Main_Unit, UI_To_Int (Expr_Value (Expr)));
2077 -- Ignore pragma if Relaxed_RM_Semantics to support
2078 -- other targets/non GNAT compilers.
2080 elsif not Relaxed_RM_Semantics then
2082 ("main subprogram priority is out of range",
2087 -- Load an arbitrary entity from System.Tasking.Stages
2088 -- or System.Tasking.Restricted.Stages (depending on
2089 -- the supported profile) to make sure that one of these
2090 -- packages is implicitly with'ed, since we need to have
2091 -- the tasking run time active for the pragma Priority to
2092 -- have any effect. Previously we with'ed the package
2093 -- System.Tasking, but this package does not trigger the
2094 -- required initialization of the run-time library.
2097 Discard : Entity_Id;
2099 if Restricted_Profile then
2100 Discard := RTE (RE_Activate_Restricted_Tasks);
2102 Discard := RTE (RE_Activate_Tasks);
2106 -- Handling for these Aspects in subprograms is complete
2113 -- Pass the aspect as an attribute
2116 Make_Attribute_Definition_Clause (Loc,
2118 Chars => Chars (Id),
2119 Expression => Relocate_Node (Expr));
2124 when Aspect_Warnings =>
2126 (Pragma_Argument_Associations => New_List (
2127 Make_Pragma_Argument_Association (Sloc (Expr),
2128 Expression => Relocate_Node (Expr)),
2129 Make_Pragma_Argument_Association (Loc,
2130 Expression => New_Occurrence_Of (E, Loc))),
2131 Pragma_Name => Chars (Id));
2133 -- Case 2c: Aspects corresponding to pragmas with three
2136 -- Invariant aspects have a first argument that references the
2137 -- entity, a second argument that is the expression and a third
2138 -- argument that is an appropriate message.
2140 -- Invariant, Type_Invariant
2142 when Aspect_Invariant |
2143 Aspect_Type_Invariant =>
2145 -- Analysis of the pragma will verify placement legality:
2146 -- an invariant must apply to a private type, or appear in
2147 -- the private part of a spec and apply to a completion.
2150 (Pragma_Argument_Associations => New_List (
2151 Make_Pragma_Argument_Association (Sloc (Ent),
2153 Make_Pragma_Argument_Association (Sloc (Expr),
2154 Expression => Relocate_Node (Expr))),
2155 Pragma_Name => Name_Invariant);
2157 -- Add message unless exception messages are suppressed
2159 if not Opt.Exception_Locations_Suppressed then
2160 Append_To (Pragma_Argument_Associations (Aitem),
2161 Make_Pragma_Argument_Association (Eloc,
2162 Chars => Name_Message,
2164 Make_String_Literal (Eloc,
2165 Strval => "failed invariant from "
2166 & Build_Location_String (Eloc))));
2169 -- For Invariant case, insert immediately after the entity
2170 -- declaration. We do not have to worry about delay issues
2171 -- since the pragma processing takes care of this.
2173 Delay_Required := False;
2175 -- Case 2d : Aspects that correspond to a pragma with one
2180 -- Aspect Abstract_State introduces implicit declarations for
2181 -- all state abstraction entities it defines. To emulate this
2182 -- behavior, insert the pragma at the beginning of the visible
2183 -- declarations of the related package so that it is analyzed
2186 when Aspect_Abstract_State => Abstract_State : declare
2187 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)
2204 (Pragma_Argument_Associations => New_List (
2205 Make_Pragma_Argument_Association (Loc,
2206 Expression => Relocate_Node (Expr))),
2207 Pragma_Name => Name_Abstract_State);
2208 Decorate (Aspect, Aitem);
2210 Decls := Visible_Declarations (Specification (Context));
2212 -- In general pragma Abstract_State must be at the top
2213 -- of the existing visible declarations to emulate its
2214 -- source counterpart. The only exception to this is a
2215 -- generic instance in which case the pragma must be
2216 -- inserted after the association renamings.
2218 if Present (Decls) then
2219 Decl := First (Decls);
2221 -- The visible declarations of a generic instance have
2222 -- the following structure:
2224 -- <renamings of generic formals>
2225 -- <renamings of internally-generated spec and body>
2226 -- <first source declaration>
2228 -- The pragma must be inserted before the first source
2229 -- declaration, skip the instance "header".
2231 if Is_Generic_Instance (Defining_Entity (Context)) then
2232 while Present (Decl)
2233 and then not Comes_From_Source (Decl)
2235 Decl := Next (Decl);
2239 -- When aspects Abstract_State, Ghost,
2240 -- Initial_Condition and Initializes are out of order,
2241 -- ensure that pragma SPARK_Mode is always at the top
2242 -- of the declarations to properly enabled/suppress
2245 Insert_After_SPARK_Mode
2250 -- Otherwise the pragma forms a new declarative list
2253 Set_Visible_Declarations
2254 (Specification (Context), New_List (Aitem));
2259 ("aspect & must apply to a package declaration",
2266 -- Aspect Default_Internal_Condition is never delayed because
2267 -- it is equivalent to a source pragma which appears after the
2268 -- related private type. To deal with forward references, the
2269 -- generated pragma is stored in the rep chain of the related
2270 -- private type as types do not carry contracts. The pragma is
2271 -- wrapped inside of a procedure at the freeze point of the
2272 -- private type's full view.
2274 when Aspect_Default_Initial_Condition =>
2276 (Pragma_Argument_Associations => New_List (
2277 Make_Pragma_Argument_Association (Loc,
2278 Expression => Relocate_Node (Expr))),
2280 Name_Default_Initial_Condition);
2282 Decorate (Aspect, Aitem);
2283 Insert_Pragma (Aitem);
2286 -- Default_Storage_Pool
2288 when Aspect_Default_Storage_Pool =>
2290 (Pragma_Argument_Associations => New_List (
2291 Make_Pragma_Argument_Association (Loc,
2292 Expression => Relocate_Node (Expr))),
2294 Name_Default_Storage_Pool);
2296 Decorate (Aspect, Aitem);
2297 Insert_Pragma (Aitem);
2302 -- Aspect Depends is never delayed because it is equivalent to
2303 -- a source pragma which appears after the related subprogram.
2304 -- To deal with forward references, the generated pragma is
2305 -- stored in the contract of the related subprogram and later
2306 -- analyzed at the end of the declarative region. See routine
2307 -- Analyze_Depends_In_Decl_Part for details.
2309 when Aspect_Depends =>
2311 (Pragma_Argument_Associations => New_List (
2312 Make_Pragma_Argument_Association (Loc,
2313 Expression => Relocate_Node (Expr))),
2314 Pragma_Name => Name_Depends);
2316 Decorate (Aspect, Aitem);
2317 Insert_Pragma (Aitem);
2320 -- Aspect Extensions_Visible is never delayed because it is
2321 -- equivalent to a source pragma which appears after the
2322 -- related subprogram.
2324 when Aspect_Extensions_Visible =>
2326 (Pragma_Argument_Associations => New_List (
2327 Make_Pragma_Argument_Association (Loc,
2328 Expression => Relocate_Node (Expr))),
2329 Pragma_Name => Name_Extensions_Visible);
2331 Decorate (Aspect, Aitem);
2332 Insert_Pragma (Aitem);
2335 -- Aspect Ghost is never delayed because it is equivalent to a
2336 -- source pragma which appears at the top of [generic] package
2337 -- declarations or after an object, a [generic] subprogram, or
2338 -- a type declaration.
2340 when Aspect_Ghost => Ghost : declare
2345 (Pragma_Argument_Associations => New_List (
2346 Make_Pragma_Argument_Association (Loc,
2347 Expression => Relocate_Node (Expr))),
2348 Pragma_Name => Name_Ghost);
2350 Decorate (Aspect, Aitem);
2352 -- When the aspect applies to a [generic] package, insert
2353 -- the pragma at the top of the visible declarations. This
2354 -- emulates the placement of a source pragma.
2356 if Nkind_In (N, N_Generic_Package_Declaration,
2357 N_Package_Declaration)
2359 Decls := Visible_Declarations (Specification (N));
2363 Set_Visible_Declarations (N, Decls);
2366 -- When aspects Abstract_State, Ghost, Initial_Condition
2367 -- and Initializes are out of order, ensure that pragma
2368 -- SPARK_Mode is always at the top of the declarations to
2369 -- properly enabled/suppress errors.
2371 Insert_After_SPARK_Mode
2373 Ins_Nod => First (Decls),
2376 -- Otherwise the context is an object, [generic] subprogram
2377 -- or type declaration.
2380 Insert_Pragma (Aitem);
2388 -- Aspect Global is never delayed because it is equivalent to
2389 -- a source pragma which appears after the related subprogram.
2390 -- To deal with forward references, the generated pragma is
2391 -- stored in the contract of the related subprogram and later
2392 -- analyzed at the end of the declarative region. See routine
2393 -- Analyze_Global_In_Decl_Part for details.
2395 when Aspect_Global =>
2397 (Pragma_Argument_Associations => New_List (
2398 Make_Pragma_Argument_Association (Loc,
2399 Expression => Relocate_Node (Expr))),
2400 Pragma_Name => Name_Global);
2402 Decorate (Aspect, Aitem);
2403 Insert_Pragma (Aitem);
2406 -- Initial_Condition
2408 -- Aspect Initial_Condition is never delayed because it is
2409 -- equivalent to a source pragma which appears after the
2410 -- related package. To deal with forward references, the
2411 -- generated pragma is stored in the contract of the related
2412 -- package and later analyzed at the end of the declarative
2413 -- region. See routine Analyze_Initial_Condition_In_Decl_Part
2416 when Aspect_Initial_Condition => Initial_Condition : declare
2417 Context : Node_Id := N;
2421 -- When aspect Initial_Condition appears on a generic
2422 -- package, it is propageted to the package instance. The
2423 -- context in this case is the instance spec.
2425 if Nkind (Context) = N_Package_Instantiation then
2426 Context := Instance_Spec (Context);
2429 if Nkind_In (Context, N_Generic_Package_Declaration,
2430 N_Package_Declaration)
2432 Decls := Visible_Declarations (Specification (Context));
2435 (Pragma_Argument_Associations => New_List (
2436 Make_Pragma_Argument_Association (Loc,
2437 Expression => Relocate_Node (Expr))),
2439 Name_Initial_Condition);
2440 Decorate (Aspect, Aitem);
2444 Set_Visible_Declarations (Context, Decls);
2447 -- When aspects Abstract_State, Ghost, Initial_Condition
2448 -- and Initializes are out of order, ensure that pragma
2449 -- SPARK_Mode is always at the top of the declarations to
2450 -- properly enabled/suppress errors.
2452 Insert_After_SPARK_Mode
2454 Ins_Nod => First (Decls),
2459 ("aspect & must apply to a package declaration",
2464 end Initial_Condition;
2468 -- Aspect Initializes is never delayed because it is equivalent
2469 -- to a source pragma appearing after the related package. To
2470 -- deal with forward references, the generated pragma is stored
2471 -- in the contract of the related package and later analyzed at
2472 -- the end of the declarative region. For details, see routine
2473 -- Analyze_Initializes_In_Decl_Part.
2475 when Aspect_Initializes => Initializes : declare
2476 Context : Node_Id := N;
2480 -- When aspect Initializes appears on a generic package,
2481 -- it is propageted to the package instance. The context
2482 -- in this case is the instance spec.
2484 if Nkind (Context) = N_Package_Instantiation then
2485 Context := Instance_Spec (Context);
2488 if Nkind_In (Context, N_Generic_Package_Declaration,
2489 N_Package_Declaration)
2491 Decls := Visible_Declarations (Specification (Context));
2494 (Pragma_Argument_Associations => New_List (
2495 Make_Pragma_Argument_Association (Loc,
2496 Expression => Relocate_Node (Expr))),
2497 Pragma_Name => Name_Initializes);
2498 Decorate (Aspect, Aitem);
2502 Set_Visible_Declarations (Context, Decls);
2505 -- When aspects Abstract_State, Ghost, Initial_Condition
2506 -- and Initializes are out of order, ensure that pragma
2507 -- SPARK_Mode is always at the top of the declarations to
2508 -- properly enabled/suppress errors.
2510 Insert_After_SPARK_Mode
2512 Ins_Nod => First (Decls),
2517 ("aspect & must apply to a package declaration",
2526 when Aspect_Obsolescent => declare
2534 Make_Pragma_Argument_Association (Sloc (Expr),
2535 Expression => Relocate_Node (Expr)));
2539 (Pragma_Argument_Associations => Args,
2540 Pragma_Name => Chars (Id));
2545 when Aspect_Part_Of =>
2546 if Nkind_In (N, N_Object_Declaration,
2547 N_Package_Instantiation)
2550 (Pragma_Argument_Associations => New_List (
2551 Make_Pragma_Argument_Association (Loc,
2552 Expression => Relocate_Node (Expr))),
2553 Pragma_Name => Name_Part_Of);
2557 ("aspect & must apply to a variable or package "
2558 & "instantiation", Aspect, Id);
2563 when Aspect_SPARK_Mode => SPARK_Mode : declare
2568 (Pragma_Argument_Associations => New_List (
2569 Make_Pragma_Argument_Association (Loc,
2570 Expression => Relocate_Node (Expr))),
2571 Pragma_Name => Name_SPARK_Mode);
2573 -- When the aspect appears on a package or a subprogram
2574 -- body, insert the generated pragma at the top of the body
2575 -- declarations to emulate the behavior of a source pragma.
2577 if Nkind_In (N, N_Package_Body, N_Subprogram_Body) then
2578 Decorate (Aspect, Aitem);
2580 Decls := Declarations (N);
2584 Set_Declarations (N, Decls);
2587 Prepend_To (Decls, Aitem);
2590 -- When the aspect is associated with a [generic] package
2591 -- declaration, insert the generated pragma at the top of
2592 -- the visible declarations to emulate the behavior of a
2595 elsif Nkind_In (N, N_Generic_Package_Declaration,
2596 N_Package_Declaration)
2598 Decorate (Aspect, Aitem);
2600 Decls := Visible_Declarations (Specification (N));
2604 Set_Visible_Declarations (Specification (N), Decls);
2607 Prepend_To (Decls, Aitem);
2614 -- Aspect Refined_Depends is never delayed because it is
2615 -- equivalent to a source pragma which appears in the
2616 -- declarations of the related subprogram body. To deal with
2617 -- forward references, the generated pragma is stored in the
2618 -- contract of the related subprogram body and later analyzed
2619 -- at the end of the declarative region. For details, see
2620 -- routine Analyze_Refined_Depends_In_Decl_Part.
2622 when Aspect_Refined_Depends =>
2624 (Pragma_Argument_Associations => New_List (
2625 Make_Pragma_Argument_Association (Loc,
2626 Expression => Relocate_Node (Expr))),
2627 Pragma_Name => Name_Refined_Depends);
2629 Decorate (Aspect, Aitem);
2630 Insert_Pragma (Aitem);
2635 -- Aspect Refined_Global is never delayed because it is
2636 -- equivalent to a source pragma which appears in the
2637 -- declarations of the related subprogram body. To deal with
2638 -- forward references, the generated pragma is stored in the
2639 -- contract of the related subprogram body and later analyzed
2640 -- at the end of the declarative region. For details, see
2641 -- routine Analyze_Refined_Global_In_Decl_Part.
2643 when Aspect_Refined_Global =>
2645 (Pragma_Argument_Associations => New_List (
2646 Make_Pragma_Argument_Association (Loc,
2647 Expression => Relocate_Node (Expr))),
2648 Pragma_Name => Name_Refined_Global);
2650 Decorate (Aspect, Aitem);
2651 Insert_Pragma (Aitem);
2656 when Aspect_Refined_Post =>
2658 (Pragma_Argument_Associations => New_List (
2659 Make_Pragma_Argument_Association (Loc,
2660 Expression => Relocate_Node (Expr))),
2661 Pragma_Name => Name_Refined_Post);
2665 when Aspect_Refined_State => Refined_State : declare
2669 -- The corresponding pragma for Refined_State is inserted in
2670 -- the declarations of the related package body. This action
2671 -- synchronizes both the source and from-aspect versions of
2674 if Nkind (N) = N_Package_Body then
2675 Decls := Declarations (N);
2678 (Pragma_Argument_Associations => New_List (
2679 Make_Pragma_Argument_Association (Loc,
2680 Expression => Relocate_Node (Expr))),
2681 Pragma_Name => Name_Refined_State);
2682 Decorate (Aspect, Aitem);
2686 Set_Declarations (N, Decls);
2689 -- Pragma Refined_State must be inserted after pragma
2690 -- SPARK_Mode in the tree. This ensures that any error
2691 -- messages dependent on SPARK_Mode will be properly
2692 -- enabled/suppressed.
2694 Insert_After_SPARK_Mode
2696 Ins_Nod => First (Decls),
2701 ("aspect & must apply to a package body", Aspect, Id);
2707 -- Relative_Deadline
2709 when Aspect_Relative_Deadline =>
2711 (Pragma_Argument_Associations => New_List (
2712 Make_Pragma_Argument_Association (Loc,
2713 Expression => Relocate_Node (Expr))),
2714 Pragma_Name => Name_Relative_Deadline);
2716 -- If the aspect applies to a task, the corresponding pragma
2717 -- must appear within its declarations, not after.
2719 if Nkind (N) = N_Task_Type_Declaration then
2725 if No (Task_Definition (N)) then
2726 Set_Task_Definition (N,
2727 Make_Task_Definition (Loc,
2728 Visible_Declarations => New_List,
2729 End_Label => Empty));
2732 Def := Task_Definition (N);
2733 V := Visible_Declarations (Def);
2734 if not Is_Empty_List (V) then
2735 Insert_Before (First (V), Aitem);
2738 Set_Visible_Declarations (Def, New_List (Aitem));
2745 -- Case 2e: Annotate aspect
2747 when Aspect_Annotate =>
2754 -- The argument can be a single identifier
2756 if Nkind (Expr) = N_Identifier then
2758 -- One level of parens is allowed
2760 if Paren_Count (Expr) > 1 then
2761 Error_Msg_F ("extra parentheses ignored", Expr);
2764 Set_Paren_Count (Expr, 0);
2766 -- Add the single item to the list
2768 Args := New_List (Expr);
2770 -- Otherwise we must have an aggregate
2772 elsif Nkind (Expr) = N_Aggregate then
2774 -- Must be positional
2776 if Present (Component_Associations (Expr)) then
2778 ("purely positional aggregate required", Expr);
2782 -- Must not be parenthesized
2784 if Paren_Count (Expr) /= 0 then
2785 Error_Msg_F ("extra parentheses ignored", Expr);
2788 -- List of arguments is list of aggregate expressions
2790 Args := Expressions (Expr);
2792 -- Anything else is illegal
2795 Error_Msg_F ("wrong form for Annotate aspect", Expr);
2799 -- Prepare pragma arguments
2802 Arg := First (Args);
2803 while Present (Arg) loop
2805 Make_Pragma_Argument_Association (Sloc (Arg),
2806 Expression => Relocate_Node (Arg)));
2811 Make_Pragma_Argument_Association (Sloc (Ent),
2812 Chars => Name_Entity,
2813 Expression => Ent));
2816 (Pragma_Argument_Associations => Pargs,
2817 Pragma_Name => Name_Annotate);
2820 -- Case 3 : Aspects that don't correspond to pragma/attribute
2821 -- definition clause.
2823 -- Case 3a: The aspects listed below don't correspond to
2824 -- pragmas/attributes but do require delayed analysis.
2826 -- Default_Value can only apply to a scalar type
2828 when Aspect_Default_Value =>
2829 if not Is_Scalar_Type (E) then
2831 ("aspect Default_Value must apply to a scalar type", N);
2836 -- Default_Component_Value can only apply to an array type
2837 -- with scalar components.
2839 when Aspect_Default_Component_Value =>
2840 if not (Is_Array_Type (E)
2841 and then Is_Scalar_Type (Component_Type (E)))
2843 Error_Msg_N ("aspect Default_Component_Value can only "
2844 & "apply to an array of scalar components", N);
2849 -- Case 3b: The aspects listed below don't correspond to
2850 -- pragmas/attributes and don't need delayed analysis.
2852 -- Implicit_Dereference
2854 -- For Implicit_Dereference, External_Name and Link_Name, only
2855 -- the legality checks are done during the analysis, thus no
2856 -- delay is required.
2858 when Aspect_Implicit_Dereference =>
2859 Analyze_Aspect_Implicit_Dereference;
2862 -- External_Name, Link_Name
2864 when Aspect_External_Name |
2866 Analyze_Aspect_External_Or_Link_Name;
2871 when Aspect_Dimension =>
2872 Analyze_Aspect_Dimension (N, Id, Expr);
2877 when Aspect_Dimension_System =>
2878 Analyze_Aspect_Dimension_System (N, Id, Expr);
2881 -- Case 4: Aspects requiring special handling
2883 -- Pre/Post/Test_Case/Contract_Cases whose corresponding
2884 -- pragmas take care of the delay.
2888 -- Aspects Pre/Post generate Precondition/Postcondition pragmas
2889 -- with a first argument that is the expression, and a second
2890 -- argument that is an informative message if the test fails.
2891 -- This is inserted right after the declaration, to get the
2892 -- required pragma placement. The processing for the pragmas
2893 -- takes care of the required delay.
2895 when Pre_Post_Aspects => Pre_Post : declare
2899 if A_Id = Aspect_Pre or else A_Id = Aspect_Precondition then
2900 Pname := Name_Precondition;
2902 Pname := Name_Postcondition;
2905 -- If the expressions is of the form A and then B, then
2906 -- we generate separate Pre/Post aspects for the separate
2907 -- clauses. Since we allow multiple pragmas, there is no
2908 -- problem in allowing multiple Pre/Post aspects internally.
2909 -- These should be treated in reverse order (B first and
2910 -- A second) since they are later inserted just after N in
2911 -- the order they are treated. This way, the pragma for A
2912 -- ends up preceding the pragma for B, which may have an
2913 -- importance for the error raised (either constraint error
2914 -- or precondition error).
2916 -- We do not do this for Pre'Class, since we have to put
2917 -- these conditions together in a complex OR expression.
2919 -- We do not do this in ASIS mode, as ASIS relies on the
2920 -- original node representing the complete expression, when
2921 -- retrieving it through the source aspect table.
2924 and then (Pname = Name_Postcondition
2925 or else not Class_Present (Aspect))
2927 while Nkind (Expr) = N_And_Then loop
2928 Insert_After (Aspect,
2929 Make_Aspect_Specification (Sloc (Left_Opnd (Expr)),
2930 Identifier => Identifier (Aspect),
2931 Expression => Relocate_Node (Left_Opnd (Expr)),
2932 Class_Present => Class_Present (Aspect),
2933 Split_PPC => True));
2934 Rewrite (Expr, Relocate_Node (Right_Opnd (Expr)));
2935 Eloc := Sloc (Expr);
2939 -- Build the precondition/postcondition pragma
2941 -- Add note about why we do NOT need Copy_Tree here???
2944 (Pragma_Argument_Associations => New_List (
2945 Make_Pragma_Argument_Association (Eloc,
2946 Chars => Name_Check,
2947 Expression => Relocate_Node (Expr))),
2948 Pragma_Name => Pname);
2950 -- Add message unless exception messages are suppressed
2952 if not Opt.Exception_Locations_Suppressed then
2953 Append_To (Pragma_Argument_Associations (Aitem),
2954 Make_Pragma_Argument_Association (Eloc,
2955 Chars => Name_Message,
2957 Make_String_Literal (Eloc,
2959 & Get_Name_String (Pname)
2961 & Build_Location_String (Eloc))));
2964 Set_Is_Delayed_Aspect (Aspect);
2966 -- For Pre/Post cases, insert immediately after the entity
2967 -- declaration, since that is the required pragma placement.
2968 -- Note that for these aspects, we do not have to worry
2969 -- about delay issues, since the pragmas themselves deal
2970 -- with delay of visibility for the expression analysis.
2972 Insert_Pragma (Aitem);
2979 when Aspect_Test_Case => Test_Case : declare
2981 Comp_Expr : Node_Id;
2982 Comp_Assn : Node_Id;
2988 if Nkind (Parent (N)) = N_Compilation_Unit then
2989 Error_Msg_Name_1 := Nam;
2990 Error_Msg_N ("incorrect placement of aspect `%`", E);
2994 if Nkind (Expr) /= N_Aggregate then
2995 Error_Msg_Name_1 := Nam;
2997 ("wrong syntax for aspect `%` for &", Id, E);
3001 -- Make pragma expressions refer to the original aspect
3002 -- expressions through the Original_Node link. This is used
3003 -- in semantic analysis for ASIS mode, so that the original
3004 -- expression also gets analyzed.
3006 Comp_Expr := First (Expressions (Expr));
3007 while Present (Comp_Expr) loop
3008 New_Expr := Relocate_Node (Comp_Expr);
3010 Make_Pragma_Argument_Association (Sloc (Comp_Expr),
3011 Expression => New_Expr));
3015 Comp_Assn := First (Component_Associations (Expr));
3016 while Present (Comp_Assn) loop
3017 if List_Length (Choices (Comp_Assn)) /= 1
3019 Nkind (First (Choices (Comp_Assn))) /= N_Identifier
3021 Error_Msg_Name_1 := Nam;
3023 ("wrong syntax for aspect `%` for &", Id, E);
3028 Make_Pragma_Argument_Association (Sloc (Comp_Assn),
3029 Chars => Chars (First (Choices (Comp_Assn))),
3031 Relocate_Node (Expression (Comp_Assn))));
3035 -- Build the test-case pragma
3038 (Pragma_Argument_Associations => Args,
3039 Pragma_Name => Nam);
3044 when Aspect_Contract_Cases =>
3046 (Pragma_Argument_Associations => New_List (
3047 Make_Pragma_Argument_Association (Loc,
3048 Expression => Relocate_Node (Expr))),
3049 Pragma_Name => Nam);
3051 Decorate (Aspect, Aitem);
3052 Insert_Pragma (Aitem);
3055 -- Case 5: Special handling for aspects with an optional
3056 -- boolean argument.
3058 -- In the delayed case, the corresponding pragma cannot be
3059 -- generated yet because the evaluation of the boolean needs
3060 -- to be delayed till the freeze point.
3062 when Boolean_Aspects |
3063 Library_Unit_Aspects =>
3065 Set_Is_Boolean_Aspect (Aspect);
3067 -- Lock_Free aspect only apply to protected objects
3069 if A_Id = Aspect_Lock_Free then
3070 if Ekind (E) /= E_Protected_Type then
3071 Error_Msg_Name_1 := Nam;
3073 ("aspect % only applies to a protected object",
3077 -- Set the Uses_Lock_Free flag to True if there is no
3078 -- expression or if the expression is True. The
3079 -- evaluation of this aspect should be delayed to the
3080 -- freeze point (why???)
3083 or else Is_True (Static_Boolean (Expr))
3085 Set_Uses_Lock_Free (E);
3088 Record_Rep_Item (E, Aspect);
3093 elsif A_Id = Aspect_Import or else A_Id = Aspect_Export then
3095 -- For the case of aspects Import and Export, we don't
3096 -- consider that we know the entity is never set in the
3097 -- source, since it is is likely modified outside the
3100 -- Note: one might think that the analysis of the
3101 -- resulting pragma would take care of that, but
3102 -- that's not the case since it won't be from source.
3104 if Ekind (E) = E_Variable then
3105 Set_Never_Set_In_Source (E, False);
3108 -- In older versions of Ada the corresponding pragmas
3109 -- specified a Convention. In Ada 2012 the convention is
3110 -- specified as a separate aspect, and it is optional,
3111 -- given that it defaults to Convention_Ada. The code
3112 -- that verifed that there was a matching convention
3115 -- Resolve the expression of an Import or Export here,
3116 -- and require it to be of type Boolean and static. This
3117 -- is not quite right, because in general this should be
3118 -- delayed, but that seems tricky for these, because
3119 -- normally Boolean aspects are replaced with pragmas at
3120 -- the freeze point (in Make_Pragma_From_Boolean_Aspect),
3121 -- but in the case of these aspects we can't generate
3122 -- a simple pragma with just the entity name. ???
3124 if not Present (Expr)
3125 or else Is_True (Static_Boolean (Expr))
3127 if A_Id = Aspect_Import then
3128 Set_Is_Imported (E);
3129 Set_Has_Completion (E);
3131 -- An imported entity cannot have an explicit
3134 if Nkind (N) = N_Object_Declaration
3135 and then Present (Expression (N))
3138 ("imported entities cannot be initialized "
3139 & "(RM B.1(24))", Expression (N));
3142 elsif A_Id = Aspect_Export then
3143 Set_Is_Exported (E);
3149 -- Disable_Controlled
3151 elsif A_Id = Aspect_Disable_Controlled then
3152 if Ekind (E) /= E_Record_Type
3153 or else not Is_Controlled (E)
3156 ("aspect % requires controlled record type", Aspect);
3160 Analyze_And_Resolve (Expr, Standard_Boolean);
3162 -- If we're in a generic template, we don't want to try
3163 -- to disable controlled types, because typical usage is
3164 -- "Disable_Controlled => not <some_check>'Enabled", and
3165 -- the value of Enabled is not known until we see a
3166 -- particular instance.
3168 if Expander_Active then
3169 if not Present (Expr)
3170 or else Is_True (Static_Boolean (Expr))
3172 Set_Disable_Controlled (E);
3179 -- Library unit aspects require special handling in the case
3180 -- of a package declaration, the pragma needs to be inserted
3181 -- in the list of declarations for the associated package.
3182 -- There is no issue of visibility delay for these aspects.
3184 if A_Id in Library_Unit_Aspects
3186 Nkind_In (N, N_Package_Declaration,
3187 N_Generic_Package_Declaration)
3188 and then Nkind (Parent (N)) /= N_Compilation_Unit
3190 -- Aspect is legal on a local instantiation of a library-
3191 -- level generic unit.
3193 and then not Is_Generic_Instance (Defining_Entity (N))
3196 ("incorrect context for library unit aspect&", Id);
3200 -- External property aspects are Boolean by nature, but
3201 -- their pragmas must contain two arguments, the second
3202 -- being the optional Boolean expression.
3204 if A_Id = Aspect_Async_Readers or else
3205 A_Id = Aspect_Async_Writers or else
3206 A_Id = Aspect_Effective_Reads or else
3207 A_Id = Aspect_Effective_Writes
3213 -- The first argument of the external property pragma
3214 -- is the related object.
3218 Make_Pragma_Argument_Association (Sloc (Ent),
3219 Expression => Ent));
3221 -- The second argument is the optional Boolean
3222 -- expression which must be propagated even if it
3223 -- evaluates to False as this has special semantic
3226 if Present (Expr) then
3228 Make_Pragma_Argument_Association (Loc,
3229 Expression => Relocate_Node (Expr)));
3233 (Pragma_Argument_Associations => Args,
3234 Pragma_Name => Nam);
3237 -- Cases where we do not delay, includes all cases where the
3238 -- expression is missing other than the above cases.
3240 elsif not Delay_Required or else No (Expr) then
3242 (Pragma_Argument_Associations => New_List (
3243 Make_Pragma_Argument_Association (Sloc (Ent),
3244 Expression => Ent)),
3245 Pragma_Name => Chars (Id));
3246 Delay_Required := False;
3248 -- In general cases, the corresponding pragma/attribute
3249 -- definition clause will be inserted later at the freezing
3250 -- point, and we do not need to build it now.
3258 -- This is special because for access types we need to generate
3259 -- an attribute definition clause. This also works for single
3260 -- task declarations, but it does not work for task type
3261 -- declarations, because we have the case where the expression
3262 -- references a discriminant of the task type. That can't use
3263 -- an attribute definition clause because we would not have
3264 -- visibility on the discriminant. For that case we must
3265 -- generate a pragma in the task definition.
3267 when Aspect_Storage_Size =>
3271 if Ekind (E) = E_Task_Type then
3273 Decl : constant Node_Id := Declaration_Node (E);
3276 pragma Assert (Nkind (Decl) = N_Task_Type_Declaration);
3278 -- If no task definition, create one
3280 if No (Task_Definition (Decl)) then
3281 Set_Task_Definition (Decl,
3282 Make_Task_Definition (Loc,
3283 Visible_Declarations => Empty_List,
3284 End_Label => Empty));
3287 -- Create a pragma and put it at the start of the task
3288 -- definition for the task type declaration.
3291 (Pragma_Argument_Associations => New_List (
3292 Make_Pragma_Argument_Association (Loc,
3293 Expression => Relocate_Node (Expr))),
3294 Pragma_Name => Name_Storage_Size);
3298 Visible_Declarations (Task_Definition (Decl)));
3302 -- All other cases, generate attribute definition
3306 Make_Attribute_Definition_Clause (Loc,
3308 Chars => Chars (Id),
3309 Expression => Relocate_Node (Expr));
3313 -- Attach the corresponding pragma/attribute definition clause to
3314 -- the aspect specification node.
3316 if Present (Aitem) then
3317 Set_From_Aspect_Specification (Aitem);
3320 -- In the context of a compilation unit, we directly put the
3321 -- pragma in the Pragmas_After list of the N_Compilation_Unit_Aux
3322 -- node (no delay is required here) except for aspects on a
3323 -- subprogram body (see below) and a generic package, for which we
3324 -- need to introduce the pragma before building the generic copy
3325 -- (see sem_ch12), and for package instantiations, where the
3326 -- library unit pragmas are better handled early.
3328 if Nkind (Parent (N)) = N_Compilation_Unit
3329 and then (Present (Aitem) or else Is_Boolean_Aspect (Aspect))
3332 Aux : constant Node_Id := Aux_Decls_Node (Parent (N));
3335 pragma Assert (Nkind (Aux) = N_Compilation_Unit_Aux);
3337 -- For a Boolean aspect, create the corresponding pragma if
3338 -- no expression or if the value is True.
3340 if Is_Boolean_Aspect (Aspect) and then No (Aitem) then
3341 if Is_True (Static_Boolean (Expr)) then
3343 (Pragma_Argument_Associations => New_List (
3344 Make_Pragma_Argument_Association (Sloc (Ent),
3345 Expression => Ent)),
3346 Pragma_Name => Chars (Id));
3348 Set_From_Aspect_Specification (Aitem, True);
3349 Set_Corresponding_Aspect (Aitem, Aspect);
3356 -- If the aspect is on a subprogram body (relevant aspect
3357 -- is Inline), add the pragma in front of the declarations.
3359 if Nkind (N) = N_Subprogram_Body then
3360 if No (Declarations (N)) then
3361 Set_Declarations (N, New_List);
3364 Prepend (Aitem, Declarations (N));
3366 elsif Nkind (N) = N_Generic_Package_Declaration then
3367 if No (Visible_Declarations (Specification (N))) then
3368 Set_Visible_Declarations (Specification (N), New_List);
3372 Visible_Declarations (Specification (N)));
3374 elsif Nkind (N) = N_Package_Instantiation then
3376 Spec : constant Node_Id :=
3377 Specification (Instance_Spec (N));
3379 if No (Visible_Declarations (Spec)) then
3380 Set_Visible_Declarations (Spec, New_List);
3383 Prepend (Aitem, Visible_Declarations (Spec));
3387 if No (Pragmas_After (Aux)) then
3388 Set_Pragmas_After (Aux, New_List);
3391 Append (Aitem, Pragmas_After (Aux));
3398 -- The evaluation of the aspect is delayed to the freezing point.
3399 -- The pragma or attribute clause if there is one is then attached
3400 -- to the aspect specification which is put in the rep item list.
3402 if Delay_Required then
3403 if Present (Aitem) then
3404 Set_Is_Delayed_Aspect (Aitem);
3405 Set_Aspect_Rep_Item (Aspect, Aitem);
3406 Set_Parent (Aitem, Aspect);
3409 Set_Is_Delayed_Aspect (Aspect);
3411 -- In the case of Default_Value, link the aspect to base type
3412 -- as well, even though it appears on a first subtype. This is
3413 -- mandated by the semantics of the aspect. Do not establish
3414 -- the link when processing the base type itself as this leads
3415 -- to a rep item circularity. Verify that we are dealing with
3416 -- a scalar type to prevent cascaded errors.
3418 if A_Id = Aspect_Default_Value
3419 and then Is_Scalar_Type (E)
3420 and then Base_Type (E) /= E
3422 Set_Has_Delayed_Aspects (Base_Type (E));
3423 Record_Rep_Item (Base_Type (E), Aspect);
3426 Set_Has_Delayed_Aspects (E);
3427 Record_Rep_Item (E, Aspect);
3429 -- When delay is not required and the context is a package or a
3430 -- subprogram body, insert the pragma in the body declarations.
3432 elsif Nkind_In (N, N_Package_Body, N_Subprogram_Body) then
3433 if No (Declarations (N)) then
3434 Set_Declarations (N, New_List);
3437 -- The pragma is added before source declarations
3439 Prepend_To (Declarations (N), Aitem);
3441 -- When delay is not required and the context is not a compilation
3442 -- unit, we simply insert the pragma/attribute definition clause
3446 Insert_After (Ins_Node, Aitem);
3449 end Analyze_One_Aspect;
3453 end loop Aspect_Loop;
3455 if Has_Delayed_Aspects (E) then
3456 Ensure_Freeze_Node (E);
3458 end Analyze_Aspect_Specifications;
3460 ---------------------------------------------------
3461 -- Analyze_Aspect_Specifications_On_Body_Or_Stub --
3462 ---------------------------------------------------
3464 procedure Analyze_Aspect_Specifications_On_Body_Or_Stub (N : Node_Id) is
3465 Body_Id : constant Entity_Id := Defining_Entity (N);
3467 procedure Diagnose_Misplaced_Aspects (Spec_Id : Entity_Id);
3468 -- Subprogram body [stub] N has aspects, but they are not properly
3469 -- placed. Emit an error message depending on the aspects involved.
3470 -- Spec_Id is the entity of the corresponding spec.
3472 --------------------------------
3473 -- Diagnose_Misplaced_Aspects --
3474 --------------------------------
3476 procedure Diagnose_Misplaced_Aspects (Spec_Id : Entity_Id) is
3477 procedure Misplaced_Aspect_Error
3480 -- Emit an error message concerning misplaced aspect Asp. Ref_Nam is
3481 -- the name of the refined version of the aspect.
3483 ----------------------------
3484 -- Misplaced_Aspect_Error --
3485 ----------------------------
3487 procedure Misplaced_Aspect_Error
3491 Asp_Nam : constant Name_Id := Chars (Identifier (Asp));
3492 Asp_Id : constant Aspect_Id := Get_Aspect_Id (Asp_Nam);
3495 -- The corresponding spec already contains the aspect in question
3496 -- and the one appearing on the body must be the refined form:
3498 -- procedure P with Global ...;
3499 -- procedure P with Global ... is ... end P;
3503 if Has_Aspect (Spec_Id, Asp_Id) then
3504 Error_Msg_Name_1 := Asp_Nam;
3506 -- Subunits cannot carry aspects that apply to a subprogram
3509 if Nkind (Parent (N)) = N_Subunit then
3510 Error_Msg_N ("aspect % cannot apply to a subunit", Asp);
3512 -- Otherwise suggest the refined form
3515 Error_Msg_Name_2 := Ref_Nam;
3516 Error_Msg_N ("aspect % should be %", Asp);
3519 -- Otherwise the aspect must appear on the spec, not on the body
3522 -- procedure P with Global ... is ... end P;
3526 ("aspect specification must appear in subprogram declaration",
3529 end Misplaced_Aspect_Error;
3536 -- Start of processing for Diagnose_Misplaced_Aspects
3539 -- Iterate over the aspect specifications and emit specific errors
3540 -- where applicable.
3542 Asp := First (Aspect_Specifications (N));
3543 while Present (Asp) loop
3544 Asp_Nam := Chars (Identifier (Asp));
3546 -- Do not emit errors on aspects that can appear on a subprogram
3547 -- body. This scenario occurs when the aspect specification list
3548 -- contains both misplaced and properly placed aspects.
3550 if Aspect_On_Body_Or_Stub_OK (Get_Aspect_Id (Asp_Nam)) then
3553 -- Special diagnostics for SPARK aspects
3555 elsif Asp_Nam = Name_Depends then
3556 Misplaced_Aspect_Error (Asp, Name_Refined_Depends);
3558 elsif Asp_Nam = Name_Global then
3559 Misplaced_Aspect_Error (Asp, Name_Refined_Global);
3561 elsif Asp_Nam = Name_Post then
3562 Misplaced_Aspect_Error (Asp, Name_Refined_Post);
3564 -- Otherwise a language-defined aspect is misplaced
3568 ("aspect specification must appear in subprogram declaration",
3574 end Diagnose_Misplaced_Aspects;
3578 Spec_Id : Entity_Id;
3580 -- Start of processing for Analyze_Aspects_On_Body_Or_Stub
3583 if Nkind (N) = N_Subprogram_Body_Stub then
3584 Spec_Id := Corresponding_Spec_Of_Stub (N);
3586 Spec_Id := Corresponding_Spec (N);
3589 -- Language-defined aspects cannot be associated with a subprogram body
3590 -- [stub] if the subprogram has a spec. Certain implementation defined
3591 -- aspects are allowed to break this rule (for all applicable cases, see
3592 -- table Aspects.Aspect_On_Body_Or_Stub_OK).
3594 if Present (Spec_Id) and then not Aspects_On_Body_Or_Stub_OK (N) then
3595 Diagnose_Misplaced_Aspects (Spec_Id);
3597 Analyze_Aspect_Specifications (N, Body_Id);
3599 end Analyze_Aspect_Specifications_On_Body_Or_Stub;
3601 -----------------------
3602 -- Analyze_At_Clause --
3603 -----------------------
3605 -- An at clause is replaced by the corresponding Address attribute
3606 -- definition clause that is the preferred approach in Ada 95.
3608 procedure Analyze_At_Clause (N : Node_Id) is
3609 CS : constant Boolean := Comes_From_Source (N);
3612 -- This is an obsolescent feature
3614 Check_Restriction (No_Obsolescent_Features, N);
3616 if Warn_On_Obsolescent_Feature then
3618 ("?j?at clause is an obsolescent feature (RM J.7(2))", N);
3620 ("\?j?use address attribute definition clause instead", N);
3623 -- Rewrite as address clause
3626 Make_Attribute_Definition_Clause (Sloc (N),
3627 Name => Identifier (N),
3628 Chars => Name_Address,
3629 Expression => Expression (N)));
3631 -- We preserve Comes_From_Source, since logically the clause still comes
3632 -- from the source program even though it is changed in form.
3634 Set_Comes_From_Source (N, CS);
3636 -- Analyze rewritten clause
3638 Analyze_Attribute_Definition_Clause (N);
3639 end Analyze_At_Clause;
3641 -----------------------------------------
3642 -- Analyze_Attribute_Definition_Clause --
3643 -----------------------------------------
3645 procedure Analyze_Attribute_Definition_Clause (N : Node_Id) is
3646 Loc : constant Source_Ptr := Sloc (N);
3647 Nam : constant Node_Id := Name (N);
3648 Attr : constant Name_Id := Chars (N);
3649 Expr : constant Node_Id := Expression (N);
3650 Id : constant Attribute_Id := Get_Attribute_Id (Attr);
3653 -- The entity of Nam after it is analyzed. In the case of an incomplete
3654 -- type, this is the underlying type.
3657 -- The underlying entity to which the attribute applies. Generally this
3658 -- is the Underlying_Type of Ent, except in the case where the clause
3659 -- applies to full view of incomplete type or private type in which case
3660 -- U_Ent is just a copy of Ent.
3662 FOnly : Boolean := False;
3663 -- Reset to True for subtype specific attribute (Alignment, Size)
3664 -- and for stream attributes, i.e. those cases where in the call to
3665 -- Rep_Item_Too_Late, FOnly is set True so that only the freezing rules
3666 -- are checked. Note that the case of stream attributes is not clear
3667 -- from the RM, but see AI95-00137. Also, the RM seems to disallow
3668 -- Storage_Size for derived task types, but that is also clearly
3671 procedure Analyze_Stream_TSS_Definition (TSS_Nam : TSS_Name_Type);
3672 -- Common processing for 'Read, 'Write, 'Input and 'Output attribute
3673 -- definition clauses.
3675 function Duplicate_Clause return Boolean;
3676 -- This routine checks if the aspect for U_Ent being given by attribute
3677 -- definition clause N is for an aspect that has already been specified,
3678 -- and if so gives an error message. If there is a duplicate, True is
3679 -- returned, otherwise if there is no error, False is returned.
3681 procedure Check_Indexing_Functions;
3682 -- Check that the function in Constant_Indexing or Variable_Indexing
3683 -- attribute has the proper type structure. If the name is overloaded,
3684 -- check that some interpretation is legal.
3686 procedure Check_Iterator_Functions;
3687 -- Check that there is a single function in Default_Iterator attribute
3688 -- has the proper type structure.
3690 function Check_Primitive_Function (Subp : Entity_Id) return Boolean;
3691 -- Common legality check for the previous two
3693 -----------------------------------
3694 -- Analyze_Stream_TSS_Definition --
3695 -----------------------------------
3697 procedure Analyze_Stream_TSS_Definition (TSS_Nam : TSS_Name_Type) is
3698 Subp : Entity_Id := Empty;
3703 Is_Read : constant Boolean := (TSS_Nam = TSS_Stream_Read);
3704 -- True for Read attribute, false for other attributes
3706 function Has_Good_Profile (Subp : Entity_Id) return Boolean;
3707 -- Return true if the entity is a subprogram with an appropriate
3708 -- profile for the attribute being defined.
3710 ----------------------
3711 -- Has_Good_Profile --
3712 ----------------------
3714 function Has_Good_Profile (Subp : Entity_Id) return Boolean is
3716 Is_Function : constant Boolean := (TSS_Nam = TSS_Stream_Input);
3717 Expected_Ekind : constant array (Boolean) of Entity_Kind :=
3718 (False => E_Procedure, True => E_Function);
3722 if Ekind (Subp) /= Expected_Ekind (Is_Function) then
3726 F := First_Formal (Subp);
3729 or else Ekind (Etype (F)) /= E_Anonymous_Access_Type
3730 or else Designated_Type (Etype (F)) /=
3731 Class_Wide_Type (RTE (RE_Root_Stream_Type))
3736 if not Is_Function then
3740 Expected_Mode : constant array (Boolean) of Entity_Kind :=
3741 (False => E_In_Parameter,
3742 True => E_Out_Parameter);
3744 if Parameter_Mode (F) /= Expected_Mode (Is_Read) then
3751 -- If the attribute specification comes from an aspect
3752 -- specification for a class-wide stream, the parameter must be
3753 -- a class-wide type of the entity to which the aspect applies.
3755 if From_Aspect_Specification (N)
3756 and then Class_Present (Parent (N))
3757 and then Is_Class_Wide_Type (Typ)
3763 Typ := Etype (Subp);
3766 -- Verify that the prefix of the attribute and the local name for
3767 -- the type of the formal match, or one is the class-wide of the
3768 -- other, in the case of a class-wide stream operation.
3770 if Base_Type (Typ) = Base_Type (Ent)
3771 or else (Is_Class_Wide_Type (Typ)
3772 and then Typ = Class_Wide_Type (Base_Type (Ent)))
3773 or else (Is_Class_Wide_Type (Ent)
3774 and then Ent = Class_Wide_Type (Base_Type (Typ)))
3781 if Present ((Next_Formal (F)))
3785 elsif not Is_Scalar_Type (Typ)
3786 and then not Is_First_Subtype (Typ)
3787 and then not Is_Class_Wide_Type (Typ)
3794 end Has_Good_Profile;
3796 -- Start of processing for Analyze_Stream_TSS_Definition
3801 if not Is_Type (U_Ent) then
3802 Error_Msg_N ("local name must be a subtype", Nam);
3805 elsif not Is_First_Subtype (U_Ent) then
3806 Error_Msg_N ("local name must be a first subtype", Nam);
3810 Pnam := TSS (Base_Type (U_Ent), TSS_Nam);
3812 -- If Pnam is present, it can be either inherited from an ancestor
3813 -- type (in which case it is legal to redefine it for this type), or
3814 -- be a previous definition of the attribute for the same type (in
3815 -- which case it is illegal).
3817 -- In the first case, it will have been analyzed already, and we
3818 -- can check that its profile does not match the expected profile
3819 -- for a stream attribute of U_Ent. In the second case, either Pnam
3820 -- has been analyzed (and has the expected profile), or it has not
3821 -- been analyzed yet (case of a type that has not been frozen yet
3822 -- and for which the stream attribute has been set using Set_TSS).
3825 and then (No (First_Entity (Pnam)) or else Has_Good_Profile (Pnam))
3827 Error_Msg_Sloc := Sloc (Pnam);
3828 Error_Msg_Name_1 := Attr;
3829 Error_Msg_N ("% attribute already defined #", Nam);
3835 if Is_Entity_Name (Expr) then
3836 if not Is_Overloaded (Expr) then
3837 if Has_Good_Profile (Entity (Expr)) then
3838 Subp := Entity (Expr);
3842 Get_First_Interp (Expr, I, It);
3843 while Present (It.Nam) loop
3844 if Has_Good_Profile (It.Nam) then
3849 Get_Next_Interp (I, It);
3854 if Present (Subp) then
3855 if Is_Abstract_Subprogram (Subp) then
3856 Error_Msg_N ("stream subprogram must not be abstract", Expr);
3859 -- A stream subprogram for an interface type must be a null
3860 -- procedure (RM 13.13.2 (38/3)).
3862 elsif Is_Interface (U_Ent)
3863 and then not Is_Class_Wide_Type (U_Ent)
3864 and then not Inside_A_Generic
3866 (Ekind (Subp) = E_Function
3870 (Unit_Declaration_Node (Ultimate_Alias (Subp)))))
3873 ("stream subprogram for interface type "
3874 & "must be null procedure", Expr);
3877 Set_Entity (Expr, Subp);
3878 Set_Etype (Expr, Etype (Subp));
3880 New_Stream_Subprogram (N, U_Ent, Subp, TSS_Nam);
3883 Error_Msg_Name_1 := Attr;
3884 Error_Msg_N ("incorrect expression for% attribute", Expr);
3886 end Analyze_Stream_TSS_Definition;
3888 ------------------------------
3889 -- Check_Indexing_Functions --
3890 ------------------------------
3892 procedure Check_Indexing_Functions is
3893 Indexing_Found : Boolean := False;
3895 procedure Check_One_Function (Subp : Entity_Id);
3896 -- Check one possible interpretation. Sets Indexing_Found True if a
3897 -- legal indexing function is found.
3899 procedure Illegal_Indexing (Msg : String);
3900 -- Diagnose illegal indexing function if not overloaded. In the
3901 -- overloaded case indicate that no legal interpretation exists.
3903 ------------------------
3904 -- Check_One_Function --
3905 ------------------------
3907 procedure Check_One_Function (Subp : Entity_Id) is
3908 Default_Element : Node_Id;
3909 Ret_Type : constant Entity_Id := Etype (Subp);
3912 if not Is_Overloadable (Subp) then
3913 Illegal_Indexing ("illegal indexing function for type&");
3916 elsif Scope (Subp) /= Scope (Ent) then
3917 if Nkind (Expr) = N_Expanded_Name then
3919 -- Indexing function can't be declared elsewhere
3922 ("indexing function must be declared in scope of type&");
3927 elsif No (First_Formal (Subp)) then
3929 ("Indexing requires a function that applies to type&");
3932 elsif No (Next_Formal (First_Formal (Subp))) then
3934 ("indexing function must have at least two parameters");
3937 -- For a derived type, check that no indexing aspect is specified
3938 -- for the type if it is also inherited
3940 elsif Is_Derived_Type (Ent) then
3942 Inherited : Node_Id;
3945 if Attr = Name_Constant_Indexing then
3947 Find_Aspect (Etype (Ent), Aspect_Constant_Indexing);
3948 else pragma Assert (Attr = Name_Variable_Indexing);
3950 Find_Aspect (Etype (Ent), Aspect_Variable_Indexing);
3953 if Present (Inherited) then
3954 if Debug_Flag_Dot_XX then
3957 -- Indicate the operation that must be overridden, rather
3958 -- than redefining the indexing aspect
3962 ("indexing function already inherited "
3963 & "from parent type");
3965 ("!override & instead",
3966 N, Entity (Expression (Inherited)));
3973 if not Check_Primitive_Function (Subp) then
3975 ("Indexing aspect requires a function that applies to type&");
3979 -- If partial declaration exists, verify that it is not tagged.
3981 if Ekind (Current_Scope) = E_Package
3982 and then Has_Private_Declaration (Ent)
3983 and then From_Aspect_Specification (N)
3985 List_Containing (Parent (Ent)) =
3986 Private_Declarations
3987 (Specification (Unit_Declaration_Node (Current_Scope)))
3988 and then Nkind (N) = N_Attribute_Definition_Clause
3995 First (Visible_Declarations
3997 (Unit_Declaration_Node (Current_Scope))));
3999 while Present (Decl) loop
4000 if Nkind (Decl) = N_Private_Type_Declaration
4001 and then Ent = Full_View (Defining_Identifier (Decl))
4002 and then Tagged_Present (Decl)
4003 and then No (Aspect_Specifications (Decl))
4006 ("Indexing aspect cannot be specified on full view "
4007 & "if partial view is tagged");
4016 -- An indexing function must return either the default element of
4017 -- the container, or a reference type. For variable indexing it
4018 -- must be the latter.
4021 Find_Value_Of_Aspect
4022 (Etype (First_Formal (Subp)), Aspect_Iterator_Element);
4024 if Present (Default_Element) then
4025 Analyze (Default_Element);
4027 if Is_Entity_Name (Default_Element)
4028 and then not Covers (Entity (Default_Element), Ret_Type)
4032 ("wrong return type for indexing function");
4037 -- For variable_indexing the return type must be a reference type
4039 if Attr = Name_Variable_Indexing then
4040 if not Has_Implicit_Dereference (Ret_Type) then
4042 ("variable indexing must return a reference type");
4045 elsif Is_Access_Constant
4046 (Etype (First_Discriminant (Ret_Type)))
4049 ("variable indexing must return an access to variable");
4054 if Has_Implicit_Dereference (Ret_Type)
4056 Is_Access_Constant (Etype (First_Discriminant (Ret_Type)))
4059 ("constant indexing must return an access to constant");
4062 elsif Is_Access_Type (Etype (First_Formal (Subp)))
4063 and then not Is_Access_Constant (Etype (First_Formal (Subp)))
4066 ("constant indexing must apply to an access to constant");
4071 -- All checks succeeded.
4073 Indexing_Found := True;
4074 end Check_One_Function;
4076 -----------------------
4077 -- Illegal_Indexing --
4078 -----------------------
4080 procedure Illegal_Indexing (Msg : String) is
4082 Error_Msg_NE (Msg, N, Ent);
4083 end Illegal_Indexing;
4085 -- Start of processing for Check_Indexing_Functions
4094 if not Is_Overloaded (Expr) then
4095 Check_One_Function (Entity (Expr));
4103 Indexing_Found := False;
4104 Get_First_Interp (Expr, I, It);
4105 while Present (It.Nam) loop
4107 -- Note that analysis will have added the interpretation
4108 -- that corresponds to the dereference. We only check the
4109 -- subprogram itself.
4111 if Is_Overloadable (It.Nam) then
4112 Check_One_Function (It.Nam);
4115 Get_Next_Interp (I, It);
4120 if not Indexing_Found and then not Error_Posted (N) then
4122 ("aspect Indexing requires a local function that "
4123 & "applies to type&", Expr, Ent);
4125 end Check_Indexing_Functions;
4127 ------------------------------
4128 -- Check_Iterator_Functions --
4129 ------------------------------
4131 procedure Check_Iterator_Functions is
4132 Default : Entity_Id;
4134 function Valid_Default_Iterator (Subp : Entity_Id) return Boolean;
4135 -- Check one possible interpretation for validity
4137 ----------------------------
4138 -- Valid_Default_Iterator --
4139 ----------------------------
4141 function Valid_Default_Iterator (Subp : Entity_Id) return Boolean is
4145 if not Check_Primitive_Function (Subp) then
4148 Formal := First_Formal (Subp);
4151 -- False if any subsequent formal has no default expression
4153 Formal := Next_Formal (Formal);
4154 while Present (Formal) loop
4155 if No (Expression (Parent (Formal))) then
4159 Next_Formal (Formal);
4162 -- True if all subsequent formals have default expressions
4165 end Valid_Default_Iterator;
4167 -- Start of processing for Check_Iterator_Functions
4172 if not Is_Entity_Name (Expr) then
4173 Error_Msg_N ("aspect Iterator must be a function name", Expr);
4176 if not Is_Overloaded (Expr) then
4177 if not Check_Primitive_Function (Entity (Expr)) then
4179 ("aspect Indexing requires a function that applies to type&",
4180 Entity (Expr), Ent);
4183 -- Flag the default_iterator as well as the denoted function.
4185 if not Valid_Default_Iterator (Entity (Expr)) then
4186 Error_Msg_N ("improper function for default iterator!", Expr);
4196 Get_First_Interp (Expr, I, It);
4197 while Present (It.Nam) loop
4198 if not Check_Primitive_Function (It.Nam)
4199 or else not Valid_Default_Iterator (It.Nam)
4203 elsif Present (Default) then
4204 Error_Msg_N ("default iterator must be unique", Expr);
4210 Get_Next_Interp (I, It);
4214 if Present (Default) then
4215 Set_Entity (Expr, Default);
4216 Set_Is_Overloaded (Expr, False);
4219 end Check_Iterator_Functions;
4221 -------------------------------
4222 -- Check_Primitive_Function --
4223 -------------------------------
4225 function Check_Primitive_Function (Subp : Entity_Id) return Boolean is
4229 if Ekind (Subp) /= E_Function then
4233 if No (First_Formal (Subp)) then
4236 Ctrl := Etype (First_Formal (Subp));
4239 -- To be a primitive operation subprogram has to be in same scope.
4241 if Scope (Ctrl) /= Scope (Subp) then
4245 -- Type of formal may be the class-wide type, an access to such,
4246 -- or an incomplete view.
4249 or else Ctrl = Class_Wide_Type (Ent)
4251 (Ekind (Ctrl) = E_Anonymous_Access_Type
4252 and then (Designated_Type (Ctrl) = Ent
4254 Designated_Type (Ctrl) = Class_Wide_Type (Ent)))
4256 (Ekind (Ctrl) = E_Incomplete_Type
4257 and then Full_View (Ctrl) = Ent)
4265 end Check_Primitive_Function;
4267 ----------------------
4268 -- Duplicate_Clause --
4269 ----------------------
4271 function Duplicate_Clause return Boolean is
4275 -- Nothing to do if this attribute definition clause comes from
4276 -- an aspect specification, since we could not be duplicating an
4277 -- explicit clause, and we dealt with the case of duplicated aspects
4278 -- in Analyze_Aspect_Specifications.
4280 if From_Aspect_Specification (N) then
4284 -- Otherwise current clause may duplicate previous clause, or a
4285 -- previously given pragma or aspect specification for the same
4288 A := Get_Rep_Item (U_Ent, Chars (N), Check_Parents => False);
4291 Error_Msg_Name_1 := Chars (N);
4292 Error_Msg_Sloc := Sloc (A);
4294 Error_Msg_NE ("aspect% for & previously given#", N, U_Ent);
4299 end Duplicate_Clause;
4301 -- Start of processing for Analyze_Attribute_Definition_Clause
4304 -- The following code is a defense against recursion. Not clear that
4305 -- this can happen legitimately, but perhaps some error situations can
4306 -- cause it, and we did see this recursion during testing.
4308 if Analyzed (N) then
4311 Set_Analyzed (N, True);
4314 -- Ignore some selected attributes in CodePeer mode since they are not
4315 -- relevant in this context.
4317 if CodePeer_Mode then
4320 -- Ignore Component_Size in CodePeer mode, to avoid changing the
4321 -- internal representation of types by implicitly packing them.
4323 when Attribute_Component_Size =>
4324 Rewrite (N, Make_Null_Statement (Sloc (N)));
4332 -- Process Ignore_Rep_Clauses option
4334 if Ignore_Rep_Clauses then
4337 -- The following should be ignored. They do not affect legality
4338 -- and may be target dependent. The basic idea of -gnatI is to
4339 -- ignore any rep clauses that may be target dependent but do not
4340 -- affect legality (except possibly to be rejected because they
4341 -- are incompatible with the compilation target).
4343 when Attribute_Alignment |
4344 Attribute_Bit_Order |
4345 Attribute_Component_Size |
4346 Attribute_Machine_Radix |
4347 Attribute_Object_Size |
4350 Attribute_Stream_Size |
4351 Attribute_Value_Size =>
4352 Kill_Rep_Clause (N);
4355 -- The following should not be ignored, because in the first place
4356 -- they are reasonably portable, and should not cause problems
4357 -- in compiling code from another target, and also they do affect
4358 -- legality, e.g. failing to provide a stream attribute for a type
4359 -- may make a program illegal.
4361 when Attribute_External_Tag |
4365 Attribute_Simple_Storage_Pool |
4366 Attribute_Storage_Pool |
4367 Attribute_Storage_Size |
4371 -- We do not do anything here with address clauses, they will be
4372 -- removed by Freeze later on, but for now, it works better to
4373 -- keep then in the tree.
4375 when Attribute_Address =>
4378 -- Other cases are errors ("attribute& cannot be set with
4379 -- definition clause"), which will be caught below.
4387 Ent := Entity (Nam);
4389 if Rep_Item_Too_Early (Ent, N) then
4393 -- Rep clause applies to full view of incomplete type or private type if
4394 -- we have one (if not, this is a premature use of the type). However,
4395 -- certain semantic checks need to be done on the specified entity (i.e.
4396 -- the private view), so we save it in Ent.
4398 if Is_Private_Type (Ent)
4399 and then Is_Derived_Type (Ent)
4400 and then not Is_Tagged_Type (Ent)
4401 and then No (Full_View (Ent))
4403 -- If this is a private type whose completion is a derivation from
4404 -- another private type, there is no full view, and the attribute
4405 -- belongs to the type itself, not its underlying parent.
4409 elsif Ekind (Ent) = E_Incomplete_Type then
4411 -- The attribute applies to the full view, set the entity of the
4412 -- attribute definition accordingly.
4414 Ent := Underlying_Type (Ent);
4416 Set_Entity (Nam, Ent);
4419 U_Ent := Underlying_Type (Ent);
4422 -- Avoid cascaded error
4424 if Etype (Nam) = Any_Type then
4427 -- Must be declared in current scope or in case of an aspect
4428 -- specification, must be visible in current scope.
4430 elsif Scope (Ent) /= Current_Scope
4432 not (From_Aspect_Specification (N)
4433 and then Scope_Within_Or_Same (Current_Scope, Scope (Ent)))
4435 Error_Msg_N ("entity must be declared in this scope", Nam);
4438 -- Must not be a source renaming (we do have some cases where the
4439 -- expander generates a renaming, and those cases are OK, in such
4440 -- cases any attribute applies to the renamed object as well).
4442 elsif Is_Object (Ent)
4443 and then Present (Renamed_Object (Ent))
4445 -- Case of renamed object from source, this is an error
4447 if Comes_From_Source (Renamed_Object (Ent)) then
4448 Get_Name_String (Chars (N));
4449 Error_Msg_Strlen := Name_Len;
4450 Error_Msg_String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len);
4452 ("~ clause not allowed for a renaming declaration "
4453 & "(RM 13.1(6))", Nam);
4456 -- For the case of a compiler generated renaming, the attribute
4457 -- definition clause applies to the renamed object created by the
4458 -- expander. The easiest general way to handle this is to create a
4459 -- copy of the attribute definition clause for this object.
4461 elsif Is_Entity_Name (Renamed_Object (Ent)) then
4463 Make_Attribute_Definition_Clause (Loc,
4465 New_Occurrence_Of (Entity (Renamed_Object (Ent)), Loc),
4467 Expression => Duplicate_Subexpr (Expression (N))));
4469 -- If the renamed object is not an entity, it must be a dereference
4470 -- of an unconstrained function call, and we must introduce a new
4471 -- declaration to capture the expression. This is needed in the case
4472 -- of 'Alignment, where the original declaration must be rewritten.
4476 (Nkind (Renamed_Object (Ent)) = N_Explicit_Dereference);
4480 -- If no underlying entity, use entity itself, applies to some
4481 -- previously detected error cases ???
4483 elsif No (U_Ent) then
4486 -- Cannot specify for a subtype (exception Object/Value_Size)
4488 elsif Is_Type (U_Ent)
4489 and then not Is_First_Subtype (U_Ent)
4490 and then Id /= Attribute_Object_Size
4491 and then Id /= Attribute_Value_Size
4492 and then not From_At_Mod (N)
4494 Error_Msg_N ("cannot specify attribute for subtype", Nam);
4498 Set_Entity (N, U_Ent);
4499 Check_Restriction_No_Use_Of_Attribute (N);
4501 -- Switch on particular attribute
4509 -- Address attribute definition clause
4511 when Attribute_Address => Address : begin
4513 -- A little error check, catch for X'Address use X'Address;
4515 if Nkind (Nam) = N_Identifier
4516 and then Nkind (Expr) = N_Attribute_Reference
4517 and then Attribute_Name (Expr) = Name_Address
4518 and then Nkind (Prefix (Expr)) = N_Identifier
4519 and then Chars (Nam) = Chars (Prefix (Expr))
4522 ("address for & is self-referencing", Prefix (Expr), Ent);
4526 -- Not that special case, carry on with analysis of expression
4528 Analyze_And_Resolve (Expr, RTE (RE_Address));
4530 -- Even when ignoring rep clauses we need to indicate that the
4531 -- entity has an address clause and thus it is legal to declare
4532 -- it imported. Freeze will get rid of the address clause later.
4534 if Ignore_Rep_Clauses then
4535 if Ekind_In (U_Ent, E_Variable, E_Constant) then
4536 Record_Rep_Item (U_Ent, N);
4542 if Duplicate_Clause then
4545 -- Case of address clause for subprogram
4547 elsif Is_Subprogram (U_Ent) then
4548 if Has_Homonym (U_Ent) then
4550 ("address clause cannot be given " &
4551 "for overloaded subprogram",
4556 -- For subprograms, all address clauses are permitted, and we
4557 -- mark the subprogram as having a deferred freeze so that Gigi
4558 -- will not elaborate it too soon.
4560 -- Above needs more comments, what is too soon about???
4562 Set_Has_Delayed_Freeze (U_Ent);
4564 -- Case of address clause for entry
4566 elsif Ekind (U_Ent) = E_Entry then
4567 if Nkind (Parent (N)) = N_Task_Body then
4569 ("entry address must be specified in task spec", Nam);
4573 -- For entries, we require a constant address
4575 Check_Constant_Address_Clause (Expr, U_Ent);
4577 -- Special checks for task types
4579 if Is_Task_Type (Scope (U_Ent))
4580 and then Comes_From_Source (Scope (U_Ent))
4583 ("??entry address declared for entry in task type", N);
4585 ("\??only one task can be declared of this type", N);
4588 -- Entry address clauses are obsolescent
4590 Check_Restriction (No_Obsolescent_Features, N);
4592 if Warn_On_Obsolescent_Feature then
4594 ("?j?attaching interrupt to task entry is an " &
4595 "obsolescent feature (RM J.7.1)", N);
4597 ("\?j?use interrupt procedure instead", N);
4600 -- Case of an address clause for a controlled object which we
4601 -- consider to be erroneous.
4603 elsif Is_Controlled (Etype (U_Ent))
4604 or else Has_Controlled_Component (Etype (U_Ent))
4607 ("??controlled object& must not be overlaid", Nam, U_Ent);
4609 ("\??Program_Error will be raised at run time", Nam);
4610 Insert_Action (Declaration_Node (U_Ent),
4611 Make_Raise_Program_Error (Loc,
4612 Reason => PE_Overlaid_Controlled_Object));
4615 -- Case of address clause for a (non-controlled) object
4617 elsif Ekind_In (U_Ent, E_Variable, E_Constant) then
4619 Expr : constant Node_Id := Expression (N);
4624 -- Exported variables cannot have an address clause, because
4625 -- this cancels the effect of the pragma Export.
4627 if Is_Exported (U_Ent) then
4629 ("cannot export object with address clause", Nam);
4633 Find_Overlaid_Entity (N, O_Ent, Off);
4635 -- Overlaying controlled objects is erroneous
4638 and then (Has_Controlled_Component (Etype (O_Ent))
4639 or else Is_Controlled (Etype (O_Ent)))
4642 ("??cannot overlay with controlled object", Expr);
4644 ("\??Program_Error will be raised at run time", Expr);
4645 Insert_Action (Declaration_Node (U_Ent),
4646 Make_Raise_Program_Error (Loc,
4647 Reason => PE_Overlaid_Controlled_Object));
4650 elsif Present (O_Ent)
4651 and then Ekind (U_Ent) = E_Constant
4652 and then not Is_Constant_Object (O_Ent)
4654 Error_Msg_N ("??constant overlays a variable", Expr);
4656 -- Imported variables can have an address clause, but then
4657 -- the import is pretty meaningless except to suppress
4658 -- initializations, so we do not need such variables to
4659 -- be statically allocated (and in fact it causes trouble
4660 -- if the address clause is a local value).
4662 elsif Is_Imported (U_Ent) then
4663 Set_Is_Statically_Allocated (U_Ent, False);
4666 -- We mark a possible modification of a variable with an
4667 -- address clause, since it is likely aliasing is occurring.
4669 Note_Possible_Modification (Nam, Sure => False);
4671 -- Here we are checking for explicit overlap of one variable
4672 -- by another, and if we find this then mark the overlapped
4673 -- variable as also being volatile to prevent unwanted
4674 -- optimizations. This is a significant pessimization so
4675 -- avoid it when there is an offset, i.e. when the object
4676 -- is composite; they cannot be optimized easily anyway.
4679 and then Is_Object (O_Ent)
4682 -- The following test is an expedient solution to what
4683 -- is really a problem in CodePeer. Suppressing the
4684 -- Set_Treat_As_Volatile call here prevents later
4685 -- generation (in some cases) of trees that CodePeer
4686 -- should, but currently does not, handle correctly.
4687 -- This test should probably be removed when CodePeer
4688 -- is improved, just because we want the tree CodePeer
4689 -- analyzes to match the tree for which we generate code
4690 -- as closely as is practical. ???
4692 and then not CodePeer_Mode
4694 -- ??? O_Ent might not be in current unit
4696 Set_Treat_As_Volatile (O_Ent);
4699 -- Legality checks on the address clause for initialized
4700 -- objects is deferred until the freeze point, because
4701 -- a subsequent pragma might indicate that the object
4702 -- is imported and thus not initialized. Also, the address
4703 -- clause might involve entities that have yet to be
4706 Set_Has_Delayed_Freeze (U_Ent);
4708 -- If an initialization call has been generated for this
4709 -- object, it needs to be deferred to after the freeze node
4710 -- we have just now added, otherwise GIGI will see a
4711 -- reference to the variable (as actual to the IP call)
4712 -- before its definition.
4715 Init_Call : constant Node_Id :=
4716 Remove_Init_Call (U_Ent, N);
4719 if Present (Init_Call) then
4720 Append_Freeze_Action (U_Ent, Init_Call);
4722 -- Reset Initialization_Statements pointer so that
4723 -- if there is a pragma Import further down, it can
4724 -- clear any default initialization.
4726 Set_Initialization_Statements (U_Ent, Init_Call);
4730 if Is_Exported (U_Ent) then
4732 ("& cannot be exported if an address clause is given",
4735 ("\define and export a variable "
4736 & "that holds its address instead", Nam);
4739 -- Entity has delayed freeze, so we will generate an
4740 -- alignment check at the freeze point unless suppressed.
4742 if not Range_Checks_Suppressed (U_Ent)
4743 and then not Alignment_Checks_Suppressed (U_Ent)
4745 Set_Check_Address_Alignment (N);
4748 -- Kill the size check code, since we are not allocating
4749 -- the variable, it is somewhere else.
4751 Kill_Size_Check_Code (U_Ent);
4753 -- If the address clause is of the form:
4755 -- for Y'Address use X'Address
4759 -- Const : constant Address := X'Address;
4761 -- for Y'Address use Const;
4763 -- then we make an entry in the table for checking the size
4764 -- and alignment of the overlaying variable. We defer this
4765 -- check till after code generation to take full advantage
4766 -- of the annotation done by the back end.
4768 -- If the entity has a generic type, the check will be
4769 -- performed in the instance if the actual type justifies
4770 -- it, and we do not insert the clause in the table to
4771 -- prevent spurious warnings.
4773 -- Note: we used to test Comes_From_Source and only give
4774 -- this warning for source entities, but we have removed
4775 -- this test. It really seems bogus to generate overlays
4776 -- that would trigger this warning in generated code.
4777 -- Furthermore, by removing the test, we handle the
4778 -- aspect case properly.
4780 if Address_Clause_Overlay_Warnings
4781 and then Present (O_Ent)
4782 and then Is_Object (O_Ent)
4784 if not Is_Generic_Type (Etype (U_Ent)) then
4785 Address_Clause_Checks.Append ((N, U_Ent, O_Ent, Off));
4788 -- If variable overlays a constant view, and we are
4789 -- warning on overlays, then mark the variable as
4790 -- overlaying a constant (we will give warnings later
4791 -- if this variable is assigned).
4793 if Is_Constant_Object (O_Ent)
4794 and then Ekind (U_Ent) = E_Variable
4796 Set_Overlays_Constant (U_Ent);
4801 -- Not a valid entity for an address clause
4804 Error_Msg_N ("address cannot be given for &", Nam);
4812 -- Alignment attribute definition clause
4814 when Attribute_Alignment => Alignment : declare
4815 Align : constant Uint := Get_Alignment_Value (Expr);
4816 Max_Align : constant Uint := UI_From_Int (Maximum_Alignment);
4821 if not Is_Type (U_Ent)
4822 and then Ekind (U_Ent) /= E_Variable
4823 and then Ekind (U_Ent) /= E_Constant
4825 Error_Msg_N ("alignment cannot be given for &", Nam);
4827 elsif Duplicate_Clause then
4830 elsif Align /= No_Uint then
4831 Set_Has_Alignment_Clause (U_Ent);
4833 -- Tagged type case, check for attempt to set alignment to a
4834 -- value greater than Max_Align, and reset if so.
4836 if Is_Tagged_Type (U_Ent) and then Align > Max_Align then
4838 ("alignment for & set to Maximum_Aligment??", Nam);
4839 Set_Alignment (U_Ent, Max_Align);
4844 Set_Alignment (U_Ent, Align);
4847 -- For an array type, U_Ent is the first subtype. In that case,
4848 -- also set the alignment of the anonymous base type so that
4849 -- other subtypes (such as the itypes for aggregates of the
4850 -- type) also receive the expected alignment.
4852 if Is_Array_Type (U_Ent) then
4853 Set_Alignment (Base_Type (U_Ent), Align);
4862 -- Bit_Order attribute definition clause
4864 when Attribute_Bit_Order => Bit_Order : declare
4866 if not Is_Record_Type (U_Ent) then
4868 ("Bit_Order can only be defined for record type", Nam);
4870 elsif Duplicate_Clause then
4874 Analyze_And_Resolve (Expr, RTE (RE_Bit_Order));
4876 if Etype (Expr) = Any_Type then
4879 elsif not Is_OK_Static_Expression (Expr) then
4880 Flag_Non_Static_Expr
4881 ("Bit_Order requires static expression!", Expr);
4884 if (Expr_Value (Expr) = 0) /= Bytes_Big_Endian then
4885 Set_Reverse_Bit_Order (Base_Type (U_Ent), True);
4891 --------------------
4892 -- Component_Size --
4893 --------------------
4895 -- Component_Size attribute definition clause
4897 when Attribute_Component_Size => Component_Size_Case : declare
4898 Csize : constant Uint := Static_Integer (Expr);
4902 New_Ctyp : Entity_Id;
4906 if not Is_Array_Type (U_Ent) then
4907 Error_Msg_N ("component size requires array type", Nam);
4911 Btype := Base_Type (U_Ent);
4912 Ctyp := Component_Type (Btype);
4914 if Duplicate_Clause then
4917 elsif Rep_Item_Too_Early (Btype, N) then
4920 elsif Csize /= No_Uint then
4921 Check_Size (Expr, Ctyp, Csize, Biased);
4923 -- For the biased case, build a declaration for a subtype that
4924 -- will be used to represent the biased subtype that reflects
4925 -- the biased representation of components. We need the subtype
4926 -- to get proper conversions on referencing elements of the
4927 -- array. Note: component size clauses are ignored in VM mode.
4929 if VM_Target = No_VM then
4932 Make_Defining_Identifier (Loc,
4934 New_External_Name (Chars (U_Ent), 'C', 0, 'T'));
4937 Make_Subtype_Declaration (Loc,
4938 Defining_Identifier => New_Ctyp,
4939 Subtype_Indication =>
4940 New_Occurrence_Of (Component_Type (Btype), Loc));
4942 Set_Parent (Decl, N);
4943 Analyze (Decl, Suppress => All_Checks);
4945 Set_Has_Delayed_Freeze (New_Ctyp, False);
4946 Set_Esize (New_Ctyp, Csize);
4947 Set_RM_Size (New_Ctyp, Csize);
4948 Init_Alignment (New_Ctyp);
4949 Set_Is_Itype (New_Ctyp, True);
4950 Set_Associated_Node_For_Itype (New_Ctyp, U_Ent);
4952 Set_Component_Type (Btype, New_Ctyp);
4953 Set_Biased (New_Ctyp, N, "component size clause");
4956 Set_Component_Size (Btype, Csize);
4958 -- For VM case, we ignore component size clauses
4961 -- Give a warning unless we are in GNAT mode, in which case
4962 -- the warning is suppressed since it is not useful.
4964 if not GNAT_Mode then
4966 ("component size ignored in this configuration??", N);
4970 -- Deal with warning on overridden size
4972 if Warn_On_Overridden_Size
4973 and then Has_Size_Clause (Ctyp)
4974 and then RM_Size (Ctyp) /= Csize
4977 ("component size overrides size clause for&?S?", N, Ctyp);
4980 Set_Has_Component_Size_Clause (Btype, True);
4981 Set_Has_Non_Standard_Rep (Btype, True);
4983 end Component_Size_Case;
4985 -----------------------
4986 -- Constant_Indexing --
4987 -----------------------
4989 when Attribute_Constant_Indexing =>
4990 Check_Indexing_Functions;
4996 when Attribute_CPU => CPU :
4998 -- CPU attribute definition clause not allowed except from aspect
5001 if From_Aspect_Specification (N) then
5002 if not Is_Task_Type (U_Ent) then
5003 Error_Msg_N ("CPU can only be defined for task", Nam);
5005 elsif Duplicate_Clause then
5009 -- The expression must be analyzed in the special manner
5010 -- described in "Handling of Default and Per-Object
5011 -- Expressions" in sem.ads.
5013 -- The visibility to the discriminants must be restored
5015 Push_Scope_And_Install_Discriminants (U_Ent);
5016 Preanalyze_Spec_Expression (Expr, RTE (RE_CPU_Range));
5017 Uninstall_Discriminants_And_Pop_Scope (U_Ent);
5019 if not Is_OK_Static_Expression (Expr) then
5020 Check_Restriction (Static_Priorities, Expr);
5026 ("attribute& cannot be set with definition clause", N);
5030 ----------------------
5031 -- Default_Iterator --
5032 ----------------------
5034 when Attribute_Default_Iterator => Default_Iterator : declare
5039 -- If target type is untagged, further checks are irrelevant
5041 if not Is_Tagged_Type (U_Ent) then
5043 ("aspect Default_Iterator applies to tagged type", Nam);
5047 Check_Iterator_Functions;
5051 if not Is_Entity_Name (Expr)
5052 or else Ekind (Entity (Expr)) /= E_Function
5054 Error_Msg_N ("aspect Iterator must be a function", Expr);
5057 Func := Entity (Expr);
5060 -- The type of the first parameter must be T, T'class, or a
5061 -- corresponding access type (5.5.1 (8/3). If function is
5062 -- parameterless label type accordingly.
5064 if No (First_Formal (Func)) then
5067 Typ := Etype (First_Formal (Func));
5071 or else Typ = Class_Wide_Type (U_Ent)
5072 or else (Is_Access_Type (Typ)
5073 and then Designated_Type (Typ) = U_Ent)
5074 or else (Is_Access_Type (Typ)
5075 and then Designated_Type (Typ) =
5076 Class_Wide_Type (U_Ent))
5082 ("Default Iterator must be a primitive of&", Func, U_Ent);
5084 end Default_Iterator;
5086 ------------------------
5087 -- Dispatching_Domain --
5088 ------------------------
5090 when Attribute_Dispatching_Domain => Dispatching_Domain :
5092 -- Dispatching_Domain attribute definition clause not allowed
5093 -- except from aspect specification.
5095 if From_Aspect_Specification (N) then
5096 if not Is_Task_Type (U_Ent) then
5098 ("Dispatching_Domain can only be defined for task", Nam);
5100 elsif Duplicate_Clause then
5104 -- The expression must be analyzed in the special manner
5105 -- described in "Handling of Default and Per-Object
5106 -- Expressions" in sem.ads.
5108 -- The visibility to the discriminants must be restored
5110 Push_Scope_And_Install_Discriminants (U_Ent);
5112 Preanalyze_Spec_Expression
5113 (Expr, RTE (RE_Dispatching_Domain));
5115 Uninstall_Discriminants_And_Pop_Scope (U_Ent);
5120 ("attribute& cannot be set with definition clause", N);
5122 end Dispatching_Domain;
5128 when Attribute_External_Tag => External_Tag :
5130 if not Is_Tagged_Type (U_Ent) then
5131 Error_Msg_N ("should be a tagged type", Nam);
5134 if Duplicate_Clause then
5138 Analyze_And_Resolve (Expr, Standard_String);
5140 if not Is_OK_Static_Expression (Expr) then
5141 Flag_Non_Static_Expr
5142 ("static string required for tag name!", Nam);
5145 if VM_Target /= No_VM then
5146 Error_Msg_Name_1 := Attr;
5148 ("% attribute unsupported in this configuration", Nam);
5151 if not Is_Library_Level_Entity (U_Ent) then
5153 ("??non-unique external tag supplied for &", N, U_Ent);
5155 ("\??same external tag applies to all "
5156 & "subprogram calls", N);
5158 ("\??corresponding internal tag cannot be obtained", N);
5163 --------------------------
5164 -- Implicit_Dereference --
5165 --------------------------
5167 when Attribute_Implicit_Dereference =>
5169 -- Legality checks already performed at the point of the type
5170 -- declaration, aspect is not delayed.
5178 when Attribute_Input =>
5179 Analyze_Stream_TSS_Definition (TSS_Stream_Input);
5180 Set_Has_Specified_Stream_Input (Ent);
5182 ------------------------
5183 -- Interrupt_Priority --
5184 ------------------------
5186 when Attribute_Interrupt_Priority => Interrupt_Priority :
5188 -- Interrupt_Priority attribute definition clause not allowed
5189 -- except from aspect specification.
5191 if From_Aspect_Specification (N) then
5192 if not Is_Concurrent_Type (U_Ent) then
5194 ("Interrupt_Priority can only be defined for task "
5195 & "and protected object", Nam);
5197 elsif Duplicate_Clause then
5201 -- The expression must be analyzed in the special manner
5202 -- described in "Handling of Default and Per-Object
5203 -- Expressions" in sem.ads.
5205 -- The visibility to the discriminants must be restored
5207 Push_Scope_And_Install_Discriminants (U_Ent);
5209 Preanalyze_Spec_Expression
5210 (Expr, RTE (RE_Interrupt_Priority));
5212 Uninstall_Discriminants_And_Pop_Scope (U_Ent);
5217 ("attribute& cannot be set with definition clause", N);
5219 end Interrupt_Priority;
5225 when Attribute_Iterable =>
5228 if Nkind (Expr) /= N_Aggregate then
5229 Error_Msg_N ("aspect Iterable must be an aggregate", Expr);
5236 Assoc := First (Component_Associations (Expr));
5237 while Present (Assoc) loop
5238 if not Is_Entity_Name (Expression (Assoc)) then
5239 Error_Msg_N ("value must be a function", Assoc);
5246 ----------------------
5247 -- Iterator_Element --
5248 ----------------------
5250 when Attribute_Iterator_Element =>
5253 if not Is_Entity_Name (Expr)
5254 or else not Is_Type (Entity (Expr))
5256 Error_Msg_N ("aspect Iterator_Element must be a type", Expr);
5263 -- Machine radix attribute definition clause
5265 when Attribute_Machine_Radix => Machine_Radix : declare
5266 Radix : constant Uint := Static_Integer (Expr);
5269 if not Is_Decimal_Fixed_Point_Type (U_Ent) then
5270 Error_Msg_N ("decimal fixed-point type expected for &", Nam);
5272 elsif Duplicate_Clause then
5275 elsif Radix /= No_Uint then
5276 Set_Has_Machine_Radix_Clause (U_Ent);
5277 Set_Has_Non_Standard_Rep (Base_Type (U_Ent));
5281 elsif Radix = 10 then
5282 Set_Machine_Radix_10 (U_Ent);
5284 Error_Msg_N ("machine radix value must be 2 or 10", Expr);
5293 -- Object_Size attribute definition clause
5295 when Attribute_Object_Size => Object_Size : declare
5296 Size : constant Uint := Static_Integer (Expr);
5299 pragma Warnings (Off, Biased);
5302 if not Is_Type (U_Ent) then
5303 Error_Msg_N ("Object_Size cannot be given for &", Nam);
5305 elsif Duplicate_Clause then
5309 Check_Size (Expr, U_Ent, Size, Biased);
5311 if Is_Scalar_Type (U_Ent) then
5312 if Size /= 8 and then Size /= 16 and then Size /= 32
5313 and then UI_Mod (Size, 64) /= 0
5316 ("Object_Size must be 8, 16, 32, or multiple of 64",
5320 elsif Size mod 8 /= 0 then
5321 Error_Msg_N ("Object_Size must be a multiple of 8", Expr);
5324 Set_Esize (U_Ent, Size);
5325 Set_Has_Object_Size_Clause (U_Ent);
5326 Alignment_Check_For_Size_Change (U_Ent, Size);
5334 when Attribute_Output =>
5335 Analyze_Stream_TSS_Definition (TSS_Stream_Output);
5336 Set_Has_Specified_Stream_Output (Ent);
5342 when Attribute_Priority => Priority :
5344 -- Priority attribute definition clause not allowed except from
5345 -- aspect specification.
5347 if From_Aspect_Specification (N) then
5348 if not (Is_Concurrent_Type (U_Ent)
5349 or else Ekind (U_Ent) = E_Procedure)
5352 ("Priority can only be defined for task and protected "
5355 elsif Duplicate_Clause then
5359 -- The expression must be analyzed in the special manner
5360 -- described in "Handling of Default and Per-Object
5361 -- Expressions" in sem.ads.
5363 -- The visibility to the discriminants must be restored
5365 Push_Scope_And_Install_Discriminants (U_Ent);
5366 Preanalyze_Spec_Expression (Expr, Standard_Integer);
5367 Uninstall_Discriminants_And_Pop_Scope (U_Ent);
5369 if not Is_OK_Static_Expression (Expr) then
5370 Check_Restriction (Static_Priorities, Expr);
5376 ("attribute& cannot be set with definition clause", N);
5384 when Attribute_Read =>
5385 Analyze_Stream_TSS_Definition (TSS_Stream_Read);
5386 Set_Has_Specified_Stream_Read (Ent);
5388 --------------------------
5389 -- Scalar_Storage_Order --
5390 --------------------------
5392 -- Scalar_Storage_Order attribute definition clause
5394 when Attribute_Scalar_Storage_Order => Scalar_Storage_Order : declare
5396 if not (Is_Record_Type (U_Ent) or else Is_Array_Type (U_Ent)) then
5398 ("Scalar_Storage_Order can only be defined for "
5399 & "record or array type", Nam);
5401 elsif Duplicate_Clause then
5405 Analyze_And_Resolve (Expr, RTE (RE_Bit_Order));
5407 if Etype (Expr) = Any_Type then
5410 elsif not Is_OK_Static_Expression (Expr) then
5411 Flag_Non_Static_Expr
5412 ("Scalar_Storage_Order requires static expression!", Expr);
5414 elsif (Expr_Value (Expr) = 0) /= Bytes_Big_Endian then
5416 -- Here for the case of a non-default (i.e. non-confirming)
5417 -- Scalar_Storage_Order attribute definition.
5419 if Support_Nondefault_SSO_On_Target then
5420 Set_Reverse_Storage_Order (Base_Type (U_Ent), True);
5423 ("non-default Scalar_Storage_Order "
5424 & "not supported on target", Expr);
5428 -- Clear SSO default indications since explicit setting of the
5429 -- order overrides the defaults.
5431 Set_SSO_Set_Low_By_Default (Base_Type (U_Ent), False);
5432 Set_SSO_Set_High_By_Default (Base_Type (U_Ent), False);
5434 end Scalar_Storage_Order;
5440 -- Size attribute definition clause
5442 when Attribute_Size => Size : declare
5443 Size : constant Uint := Static_Integer (Expr);
5450 if Duplicate_Clause then
5453 elsif not Is_Type (U_Ent)
5454 and then Ekind (U_Ent) /= E_Variable
5455 and then Ekind (U_Ent) /= E_Constant
5457 Error_Msg_N ("size cannot be given for &", Nam);
5459 elsif Is_Array_Type (U_Ent)
5460 and then not Is_Constrained (U_Ent)
5463 ("size cannot be given for unconstrained array", Nam);
5465 elsif Size /= No_Uint then
5466 if VM_Target /= No_VM and then not GNAT_Mode then
5468 -- Size clause is not handled properly on VM targets.
5469 -- Display a warning unless we are in GNAT mode, in which
5470 -- case this is useless.
5473 ("size clauses are ignored in this configuration??", N);
5476 if Is_Type (U_Ent) then
5479 Etyp := Etype (U_Ent);
5482 -- Check size, note that Gigi is in charge of checking that the
5483 -- size of an array or record type is OK. Also we do not check
5484 -- the size in the ordinary fixed-point case, since it is too
5485 -- early to do so (there may be subsequent small clause that
5486 -- affects the size). We can check the size if a small clause
5487 -- has already been given.
5489 if not Is_Ordinary_Fixed_Point_Type (U_Ent)
5490 or else Has_Small_Clause (U_Ent)
5492 Check_Size (Expr, Etyp, Size, Biased);
5493 Set_Biased (U_Ent, N, "size clause", Biased);
5496 -- For types set RM_Size and Esize if possible
5498 if Is_Type (U_Ent) then
5499 Set_RM_Size (U_Ent, Size);
5501 -- For elementary types, increase Object_Size to power of 2,
5502 -- but not less than a storage unit in any case (normally
5503 -- this means it will be byte addressable).
5505 -- For all other types, nothing else to do, we leave Esize
5506 -- (object size) unset, the back end will set it from the
5507 -- size and alignment in an appropriate manner.
5509 -- In both cases, we check whether the alignment must be
5510 -- reset in the wake of the size change.
5512 if Is_Elementary_Type (U_Ent) then
5513 if Size <= System_Storage_Unit then
5514 Init_Esize (U_Ent, System_Storage_Unit);
5515 elsif Size <= 16 then
5516 Init_Esize (U_Ent, 16);
5517 elsif Size <= 32 then
5518 Init_Esize (U_Ent, 32);
5520 Set_Esize (U_Ent, (Size + 63) / 64 * 64);
5523 Alignment_Check_For_Size_Change (U_Ent, Esize (U_Ent));
5525 Alignment_Check_For_Size_Change (U_Ent, Size);
5528 -- For objects, set Esize only
5531 if Is_Elementary_Type (Etyp) then
5532 if Size /= System_Storage_Unit
5534 Size /= System_Storage_Unit * 2
5536 Size /= System_Storage_Unit * 4
5538 Size /= System_Storage_Unit * 8
5540 Error_Msg_Uint_1 := UI_From_Int (System_Storage_Unit);
5541 Error_Msg_Uint_2 := Error_Msg_Uint_1 * 8;
5543 ("size for primitive object must be a power of 2"
5544 & " in the range ^-^", N);
5548 Set_Esize (U_Ent, Size);
5551 Set_Has_Size_Clause (U_Ent);
5559 -- Small attribute definition clause
5561 when Attribute_Small => Small : declare
5562 Implicit_Base : constant Entity_Id := Base_Type (U_Ent);
5566 Analyze_And_Resolve (Expr, Any_Real);
5568 if Etype (Expr) = Any_Type then
5571 elsif not Is_OK_Static_Expression (Expr) then
5572 Flag_Non_Static_Expr
5573 ("small requires static expression!", Expr);
5577 Small := Expr_Value_R (Expr);
5579 if Small <= Ureal_0 then
5580 Error_Msg_N ("small value must be greater than zero", Expr);
5586 if not Is_Ordinary_Fixed_Point_Type (U_Ent) then
5588 ("small requires an ordinary fixed point type", Nam);
5590 elsif Has_Small_Clause (U_Ent) then
5591 Error_Msg_N ("small already given for &", Nam);
5593 elsif Small > Delta_Value (U_Ent) then
5595 ("small value must not be greater than delta value", Nam);
5598 Set_Small_Value (U_Ent, Small);
5599 Set_Small_Value (Implicit_Base, Small);
5600 Set_Has_Small_Clause (U_Ent);
5601 Set_Has_Small_Clause (Implicit_Base);
5602 Set_Has_Non_Standard_Rep (Implicit_Base);
5610 -- Storage_Pool attribute definition clause
5612 when Attribute_Storage_Pool | Attribute_Simple_Storage_Pool => declare
5617 if Ekind (U_Ent) = E_Access_Subprogram_Type then
5619 ("storage pool cannot be given for access-to-subprogram type",
5624 Ekind_In (U_Ent, E_Access_Type, E_General_Access_Type)
5627 ("storage pool can only be given for access types", Nam);
5630 elsif Is_Derived_Type (U_Ent) then
5632 ("storage pool cannot be given for a derived access type",
5635 elsif Duplicate_Clause then
5638 elsif Present (Associated_Storage_Pool (U_Ent)) then
5639 Error_Msg_N ("storage pool already given for &", Nam);
5643 -- Check for Storage_Size previously given
5646 SS : constant Node_Id :=
5647 Get_Attribute_Definition_Clause
5648 (U_Ent, Attribute_Storage_Size);
5650 if Present (SS) then
5651 Check_Pool_Size_Clash (U_Ent, N, SS);
5655 -- Storage_Pool case
5657 if Id = Attribute_Storage_Pool then
5659 (Expr, Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
5661 -- In the Simple_Storage_Pool case, we allow a variable of any
5662 -- simple storage pool type, so we Resolve without imposing an
5666 Analyze_And_Resolve (Expr);
5668 if not Present (Get_Rep_Pragma
5669 (Etype (Expr), Name_Simple_Storage_Pool_Type))
5672 ("expression must be of a simple storage pool type", Expr);
5676 if not Denotes_Variable (Expr) then
5677 Error_Msg_N ("storage pool must be a variable", Expr);
5681 if Nkind (Expr) = N_Type_Conversion then
5682 T := Etype (Expression (Expr));
5687 -- The Stack_Bounded_Pool is used internally for implementing
5688 -- access types with a Storage_Size. Since it only work properly
5689 -- when used on one specific type, we need to check that it is not
5690 -- hijacked improperly:
5692 -- type T is access Integer;
5693 -- for T'Storage_Size use n;
5694 -- type Q is access Float;
5695 -- for Q'Storage_Size use T'Storage_Size; -- incorrect
5697 if RTE_Available (RE_Stack_Bounded_Pool)
5698 and then Base_Type (T) = RTE (RE_Stack_Bounded_Pool)
5700 Error_Msg_N ("non-shareable internal Pool", Expr);
5704 -- If the argument is a name that is not an entity name, then
5705 -- we construct a renaming operation to define an entity of
5706 -- type storage pool.
5708 if not Is_Entity_Name (Expr)
5709 and then Is_Object_Reference (Expr)
5711 Pool := Make_Temporary (Loc, 'P', Expr);
5714 Rnode : constant Node_Id :=
5715 Make_Object_Renaming_Declaration (Loc,
5716 Defining_Identifier => Pool,
5718 New_Occurrence_Of (Etype (Expr), Loc),
5722 -- If the attribute definition clause comes from an aspect
5723 -- clause, then insert the renaming before the associated
5724 -- entity's declaration, since the attribute clause has
5725 -- not yet been appended to the declaration list.
5727 if From_Aspect_Specification (N) then
5728 Insert_Before (Parent (Entity (N)), Rnode);
5730 Insert_Before (N, Rnode);
5734 Set_Associated_Storage_Pool (U_Ent, Pool);
5737 elsif Is_Entity_Name (Expr) then
5738 Pool := Entity (Expr);
5740 -- If pool is a renamed object, get original one. This can
5741 -- happen with an explicit renaming, and within instances.
5743 while Present (Renamed_Object (Pool))
5744 and then Is_Entity_Name (Renamed_Object (Pool))
5746 Pool := Entity (Renamed_Object (Pool));
5749 if Present (Renamed_Object (Pool))
5750 and then Nkind (Renamed_Object (Pool)) = N_Type_Conversion
5751 and then Is_Entity_Name (Expression (Renamed_Object (Pool)))
5753 Pool := Entity (Expression (Renamed_Object (Pool)));
5756 Set_Associated_Storage_Pool (U_Ent, Pool);
5758 elsif Nkind (Expr) = N_Type_Conversion
5759 and then Is_Entity_Name (Expression (Expr))
5760 and then Nkind (Original_Node (Expr)) = N_Attribute_Reference
5762 Pool := Entity (Expression (Expr));
5763 Set_Associated_Storage_Pool (U_Ent, Pool);
5766 Error_Msg_N ("incorrect reference to a Storage Pool", Expr);
5775 -- Storage_Size attribute definition clause
5777 when Attribute_Storage_Size => Storage_Size : declare
5778 Btype : constant Entity_Id := Base_Type (U_Ent);
5781 if Is_Task_Type (U_Ent) then
5783 -- Check obsolescent (but never obsolescent if from aspect)
5785 if not From_Aspect_Specification (N) then
5786 Check_Restriction (No_Obsolescent_Features, N);
5788 if Warn_On_Obsolescent_Feature then
5790 ("?j?storage size clause for task is an " &
5791 "obsolescent feature (RM J.9)", N);
5792 Error_Msg_N ("\?j?use Storage_Size pragma instead", N);
5799 if not Is_Access_Type (U_Ent)
5800 and then Ekind (U_Ent) /= E_Task_Type
5802 Error_Msg_N ("storage size cannot be given for &", Nam);
5804 elsif Is_Access_Type (U_Ent) and Is_Derived_Type (U_Ent) then
5806 ("storage size cannot be given for a derived access type",
5809 elsif Duplicate_Clause then
5813 Analyze_And_Resolve (Expr, Any_Integer);
5815 if Is_Access_Type (U_Ent) then
5817 -- Check for Storage_Pool previously given
5820 SP : constant Node_Id :=
5821 Get_Attribute_Definition_Clause
5822 (U_Ent, Attribute_Storage_Pool);
5825 if Present (SP) then
5826 Check_Pool_Size_Clash (U_Ent, SP, N);
5830 -- Special case of for x'Storage_Size use 0
5832 if Is_OK_Static_Expression (Expr)
5833 and then Expr_Value (Expr) = 0
5835 Set_No_Pool_Assigned (Btype);
5839 Set_Has_Storage_Size_Clause (Btype);
5847 when Attribute_Stream_Size => Stream_Size : declare
5848 Size : constant Uint := Static_Integer (Expr);
5851 if Ada_Version <= Ada_95 then
5852 Check_Restriction (No_Implementation_Attributes, N);
5855 if Duplicate_Clause then
5858 elsif Is_Elementary_Type (U_Ent) then
5859 if Size /= System_Storage_Unit
5861 Size /= System_Storage_Unit * 2
5863 Size /= System_Storage_Unit * 4
5865 Size /= System_Storage_Unit * 8
5867 Error_Msg_Uint_1 := UI_From_Int (System_Storage_Unit);
5869 ("stream size for elementary type must be a"
5870 & " power of 2 and at least ^", N);
5872 elsif RM_Size (U_Ent) > Size then
5873 Error_Msg_Uint_1 := RM_Size (U_Ent);
5875 ("stream size for elementary type must be a"
5876 & " power of 2 and at least ^", N);
5879 Set_Has_Stream_Size_Clause (U_Ent);
5882 Error_Msg_N ("Stream_Size cannot be given for &", Nam);
5890 -- Value_Size attribute definition clause
5892 when Attribute_Value_Size => Value_Size : declare
5893 Size : constant Uint := Static_Integer (Expr);
5897 if not Is_Type (U_Ent) then
5898 Error_Msg_N ("Value_Size cannot be given for &", Nam);
5900 elsif Duplicate_Clause then
5903 elsif Is_Array_Type (U_Ent)
5904 and then not Is_Constrained (U_Ent)
5907 ("Value_Size cannot be given for unconstrained array", Nam);
5910 if Is_Elementary_Type (U_Ent) then
5911 Check_Size (Expr, U_Ent, Size, Biased);
5912 Set_Biased (U_Ent, N, "value size clause", Biased);
5915 Set_RM_Size (U_Ent, Size);
5919 -----------------------
5920 -- Variable_Indexing --
5921 -----------------------
5923 when Attribute_Variable_Indexing =>
5924 Check_Indexing_Functions;
5930 when Attribute_Write =>
5931 Analyze_Stream_TSS_Definition (TSS_Stream_Write);
5932 Set_Has_Specified_Stream_Write (Ent);
5934 -- All other attributes cannot be set
5938 ("attribute& cannot be set with definition clause", N);
5941 -- The test for the type being frozen must be performed after any
5942 -- expression the clause has been analyzed since the expression itself
5943 -- might cause freezing that makes the clause illegal.
5945 if Rep_Item_Too_Late (U_Ent, N, FOnly) then
5948 end Analyze_Attribute_Definition_Clause;
5950 ----------------------------
5951 -- Analyze_Code_Statement --
5952 ----------------------------
5954 procedure Analyze_Code_Statement (N : Node_Id) is
5955 HSS : constant Node_Id := Parent (N);
5956 SBody : constant Node_Id := Parent (HSS);
5957 Subp : constant Entity_Id := Current_Scope;
5964 -- Analyze and check we get right type, note that this implements the
5965 -- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that
5966 -- is the only way that Asm_Insn could possibly be visible.
5968 Analyze_And_Resolve (Expression (N));
5970 if Etype (Expression (N)) = Any_Type then
5972 elsif Etype (Expression (N)) /= RTE (RE_Asm_Insn) then
5973 Error_Msg_N ("incorrect type for code statement", N);
5977 Check_Code_Statement (N);
5979 -- Make sure we appear in the handled statement sequence of a
5980 -- subprogram (RM 13.8(3)).
5982 if Nkind (HSS) /= N_Handled_Sequence_Of_Statements
5983 or else Nkind (SBody) /= N_Subprogram_Body
5986 ("code statement can only appear in body of subprogram", N);
5990 -- Do remaining checks (RM 13.8(3)) if not already done
5992 if not Is_Machine_Code_Subprogram (Subp) then
5993 Set_Is_Machine_Code_Subprogram (Subp);
5995 -- No exception handlers allowed
5997 if Present (Exception_Handlers (HSS)) then
5999 ("exception handlers not permitted in machine code subprogram",
6000 First (Exception_Handlers (HSS)));
6003 -- No declarations other than use clauses and pragmas (we allow
6004 -- certain internally generated declarations as well).
6006 Decl := First (Declarations (SBody));
6007 while Present (Decl) loop
6008 DeclO := Original_Node (Decl);
6009 if Comes_From_Source (DeclO)
6010 and not Nkind_In (DeclO, N_Pragma,
6011 N_Use_Package_Clause,
6013 N_Implicit_Label_Declaration)
6016 ("this declaration not allowed in machine code subprogram",
6023 -- No statements other than code statements, pragmas, and labels.
6024 -- Again we allow certain internally generated statements.
6026 -- In Ada 2012, qualified expressions are names, and the code
6027 -- statement is initially parsed as a procedure call.
6029 Stmt := First (Statements (HSS));
6030 while Present (Stmt) loop
6031 StmtO := Original_Node (Stmt);
6033 -- A procedure call transformed into a code statement is OK.
6035 if Ada_Version >= Ada_2012
6036 and then Nkind (StmtO) = N_Procedure_Call_Statement
6037 and then Nkind (Name (StmtO)) = N_Qualified_Expression
6041 elsif Comes_From_Source (StmtO)
6042 and then not Nkind_In (StmtO, N_Pragma,
6047 ("this statement is not allowed in machine code subprogram",
6054 end Analyze_Code_Statement;
6056 -----------------------------------------------
6057 -- Analyze_Enumeration_Representation_Clause --
6058 -----------------------------------------------
6060 procedure Analyze_Enumeration_Representation_Clause (N : Node_Id) is
6061 Ident : constant Node_Id := Identifier (N);
6062 Aggr : constant Node_Id := Array_Aggregate (N);
6063 Enumtype : Entity_Id;
6070 Err : Boolean := False;
6071 -- Set True to avoid cascade errors and crashes on incorrect source code
6073 Lo : constant Uint := Expr_Value (Type_Low_Bound (Universal_Integer));
6074 Hi : constant Uint := Expr_Value (Type_High_Bound (Universal_Integer));
6075 -- Allowed range of universal integer (= allowed range of enum lit vals)
6079 -- Minimum and maximum values of entries
6082 -- Pointer to node for literal providing max value
6085 if Ignore_Rep_Clauses then
6086 Kill_Rep_Clause (N);
6090 -- Ignore enumeration rep clauses by default in CodePeer mode,
6091 -- unless -gnatd.I is specified, as a work around for potential false
6092 -- positive messages.
6094 if CodePeer_Mode and not Debug_Flag_Dot_II then
6098 -- First some basic error checks
6101 Enumtype := Entity (Ident);
6103 if Enumtype = Any_Type
6104 or else Rep_Item_Too_Early (Enumtype, N)
6108 Enumtype := Underlying_Type (Enumtype);
6111 if not Is_Enumeration_Type (Enumtype) then
6113 ("enumeration type required, found}",
6114 Ident, First_Subtype (Enumtype));
6118 -- Ignore rep clause on generic actual type. This will already have
6119 -- been flagged on the template as an error, and this is the safest
6120 -- way to ensure we don't get a junk cascaded message in the instance.
6122 if Is_Generic_Actual_Type (Enumtype) then
6125 -- Type must be in current scope
6127 elsif Scope (Enumtype) /= Current_Scope then
6128 Error_Msg_N ("type must be declared in this scope", Ident);
6131 -- Type must be a first subtype
6133 elsif not Is_First_Subtype (Enumtype) then
6134 Error_Msg_N ("cannot give enumeration rep clause for subtype", N);
6137 -- Ignore duplicate rep clause
6139 elsif Has_Enumeration_Rep_Clause (Enumtype) then
6140 Error_Msg_N ("duplicate enumeration rep clause ignored", N);
6143 -- Don't allow rep clause for standard [wide_[wide_]]character
6145 elsif Is_Standard_Character_Type (Enumtype) then
6146 Error_Msg_N ("enumeration rep clause not allowed for this type", N);
6149 -- Check that the expression is a proper aggregate (no parentheses)
6151 elsif Paren_Count (Aggr) /= 0 then
6153 ("extra parentheses surrounding aggregate not allowed",
6157 -- All tests passed, so set rep clause in place
6160 Set_Has_Enumeration_Rep_Clause (Enumtype);
6161 Set_Has_Enumeration_Rep_Clause (Base_Type (Enumtype));
6164 -- Now we process the aggregate. Note that we don't use the normal
6165 -- aggregate code for this purpose, because we don't want any of the
6166 -- normal expansion activities, and a number of special semantic
6167 -- rules apply (including the component type being any integer type)
6169 Elit := First_Literal (Enumtype);
6171 -- First the positional entries if any
6173 if Present (Expressions (Aggr)) then
6174 Expr := First (Expressions (Aggr));
6175 while Present (Expr) loop
6177 Error_Msg_N ("too many entries in aggregate", Expr);
6181 Val := Static_Integer (Expr);
6183 -- Err signals that we found some incorrect entries processing
6184 -- the list. The final checks for completeness and ordering are
6185 -- skipped in this case.
6187 if Val = No_Uint then
6190 elsif Val < Lo or else Hi < Val then
6191 Error_Msg_N ("value outside permitted range", Expr);
6195 Set_Enumeration_Rep (Elit, Val);
6196 Set_Enumeration_Rep_Expr (Elit, Expr);
6202 -- Now process the named entries if present
6204 if Present (Component_Associations (Aggr)) then
6205 Assoc := First (Component_Associations (Aggr));
6206 while Present (Assoc) loop
6207 Choice := First (Choices (Assoc));
6209 if Present (Next (Choice)) then
6211 ("multiple choice not allowed here", Next (Choice));
6215 if Nkind (Choice) = N_Others_Choice then
6216 Error_Msg_N ("others choice not allowed here", Choice);
6219 elsif Nkind (Choice) = N_Range then
6221 -- ??? should allow zero/one element range here
6223 Error_Msg_N ("range not allowed here", Choice);
6227 Analyze_And_Resolve (Choice, Enumtype);
6229 if Error_Posted (Choice) then
6234 if Is_Entity_Name (Choice)
6235 and then Is_Type (Entity (Choice))
6237 Error_Msg_N ("subtype name not allowed here", Choice);
6240 -- ??? should allow static subtype with zero/one entry
6242 elsif Etype (Choice) = Base_Type (Enumtype) then
6243 if not Is_OK_Static_Expression (Choice) then
6244 Flag_Non_Static_Expr
6245 ("non-static expression used for choice!", Choice);
6249 Elit := Expr_Value_E (Choice);
6251 if Present (Enumeration_Rep_Expr (Elit)) then
6253 Sloc (Enumeration_Rep_Expr (Elit));
6255 ("representation for& previously given#",
6260 Set_Enumeration_Rep_Expr (Elit, Expression (Assoc));
6262 Expr := Expression (Assoc);
6263 Val := Static_Integer (Expr);
6265 if Val = No_Uint then
6268 elsif Val < Lo or else Hi < Val then
6269 Error_Msg_N ("value outside permitted range", Expr);
6273 Set_Enumeration_Rep (Elit, Val);
6283 -- Aggregate is fully processed. Now we check that a full set of
6284 -- representations was given, and that they are in range and in order.
6285 -- These checks are only done if no other errors occurred.
6291 Elit := First_Literal (Enumtype);
6292 while Present (Elit) loop
6293 if No (Enumeration_Rep_Expr (Elit)) then
6294 Error_Msg_NE ("missing representation for&!", N, Elit);
6297 Val := Enumeration_Rep (Elit);
6299 if Min = No_Uint then
6303 if Val /= No_Uint then
6304 if Max /= No_Uint and then Val <= Max then
6306 ("enumeration value for& not ordered!",
6307 Enumeration_Rep_Expr (Elit), Elit);
6310 Max_Node := Enumeration_Rep_Expr (Elit);
6314 -- If there is at least one literal whose representation is not
6315 -- equal to the Pos value, then note that this enumeration type
6316 -- has a non-standard representation.
6318 if Val /= Enumeration_Pos (Elit) then
6319 Set_Has_Non_Standard_Rep (Base_Type (Enumtype));
6326 -- Now set proper size information
6329 Minsize : Uint := UI_From_Int (Minimum_Size (Enumtype));
6332 if Has_Size_Clause (Enumtype) then
6334 -- All OK, if size is OK now
6336 if RM_Size (Enumtype) >= Minsize then
6340 -- Try if we can get by with biasing
6343 UI_From_Int (Minimum_Size (Enumtype, Biased => True));
6345 -- Error message if even biasing does not work
6347 if RM_Size (Enumtype) < Minsize then
6348 Error_Msg_Uint_1 := RM_Size (Enumtype);
6349 Error_Msg_Uint_2 := Max;
6351 ("previously given size (^) is too small "
6352 & "for this value (^)", Max_Node);
6354 -- If biasing worked, indicate that we now have biased rep
6358 (Enumtype, Size_Clause (Enumtype), "size clause");
6363 Set_RM_Size (Enumtype, Minsize);
6364 Set_Enum_Esize (Enumtype);
6367 Set_RM_Size (Base_Type (Enumtype), RM_Size (Enumtype));
6368 Set_Esize (Base_Type (Enumtype), Esize (Enumtype));
6369 Set_Alignment (Base_Type (Enumtype), Alignment (Enumtype));
6373 -- We repeat the too late test in case it froze itself
6375 if Rep_Item_Too_Late (Enumtype, N) then
6378 end Analyze_Enumeration_Representation_Clause;
6380 ----------------------------
6381 -- Analyze_Free_Statement --
6382 ----------------------------
6384 procedure Analyze_Free_Statement (N : Node_Id) is
6386 Analyze (Expression (N));
6387 end Analyze_Free_Statement;
6389 ---------------------------
6390 -- Analyze_Freeze_Entity --
6391 ---------------------------
6393 procedure Analyze_Freeze_Entity (N : Node_Id) is
6395 Freeze_Entity_Checks (N);
6396 end Analyze_Freeze_Entity;
6398 -----------------------------------
6399 -- Analyze_Freeze_Generic_Entity --
6400 -----------------------------------
6402 procedure Analyze_Freeze_Generic_Entity (N : Node_Id) is
6404 Freeze_Entity_Checks (N);
6405 end Analyze_Freeze_Generic_Entity;
6407 ------------------------------------------
6408 -- Analyze_Record_Representation_Clause --
6409 ------------------------------------------
6411 -- Note: we check as much as we can here, but we can't do any checks
6412 -- based on the position values (e.g. overlap checks) until freeze time
6413 -- because especially in Ada 2005 (machine scalar mode), the processing
6414 -- for non-standard bit order can substantially change the positions.
6415 -- See procedure Check_Record_Representation_Clause (called from Freeze)
6416 -- for the remainder of this processing.
6418 procedure Analyze_Record_Representation_Clause (N : Node_Id) is
6419 Ident : constant Node_Id := Identifier (N);
6424 Hbit : Uint := Uint_0;
6428 Rectype : Entity_Id;
6431 function Is_Inherited (Comp : Entity_Id) return Boolean;
6432 -- True if Comp is an inherited component in a record extension
6438 function Is_Inherited (Comp : Entity_Id) return Boolean is
6439 Comp_Base : Entity_Id;
6442 if Ekind (Rectype) = E_Record_Subtype then
6443 Comp_Base := Original_Record_Component (Comp);
6448 return Comp_Base /= Original_Record_Component (Comp_Base);
6453 Is_Record_Extension : Boolean;
6454 -- True if Rectype is a record extension
6456 CR_Pragma : Node_Id := Empty;
6457 -- Points to N_Pragma node if Complete_Representation pragma present
6459 -- Start of processing for Analyze_Record_Representation_Clause
6462 if Ignore_Rep_Clauses then
6463 Kill_Rep_Clause (N);
6468 Rectype := Entity (Ident);
6470 if Rectype = Any_Type or else Rep_Item_Too_Early (Rectype, N) then
6473 Rectype := Underlying_Type (Rectype);
6476 -- First some basic error checks
6478 if not Is_Record_Type (Rectype) then
6480 ("record type required, found}", Ident, First_Subtype (Rectype));
6483 elsif Scope (Rectype) /= Current_Scope then
6484 Error_Msg_N ("type must be declared in this scope", N);
6487 elsif not Is_First_Subtype (Rectype) then
6488 Error_Msg_N ("cannot give record rep clause for subtype", N);
6491 elsif Has_Record_Rep_Clause (Rectype) then
6492 Error_Msg_N ("duplicate record rep clause ignored", N);
6495 elsif Rep_Item_Too_Late (Rectype, N) then
6499 -- We know we have a first subtype, now possibly go the the anonymous
6500 -- base type to determine whether Rectype is a record extension.
6502 Recdef := Type_Definition (Declaration_Node (Base_Type (Rectype)));
6503 Is_Record_Extension :=
6504 Nkind (Recdef) = N_Derived_Type_Definition
6505 and then Present (Record_Extension_Part (Recdef));
6507 if Present (Mod_Clause (N)) then
6509 Loc : constant Source_Ptr := Sloc (N);
6510 M : constant Node_Id := Mod_Clause (N);
6511 P : constant List_Id := Pragmas_Before (M);
6515 pragma Warnings (Off, Mod_Val);
6518 Check_Restriction (No_Obsolescent_Features, Mod_Clause (N));
6520 if Warn_On_Obsolescent_Feature then
6522 ("?j?mod clause is an obsolescent feature (RM J.8)", N);
6524 ("\?j?use alignment attribute definition clause instead", N);
6531 -- In ASIS_Mode mode, expansion is disabled, but we must convert
6532 -- the Mod clause into an alignment clause anyway, so that the
6533 -- back-end can compute and back-annotate properly the size and
6534 -- alignment of types that may include this record.
6536 -- This seems dubious, this destroys the source tree in a manner
6537 -- not detectable by ASIS ???
6539 if Operating_Mode = Check_Semantics and then ASIS_Mode then
6541 Make_Attribute_Definition_Clause (Loc,
6542 Name => New_Occurrence_Of (Base_Type (Rectype), Loc),
6543 Chars => Name_Alignment,
6544 Expression => Relocate_Node (Expression (M)));
6546 Set_From_At_Mod (AtM_Nod);
6547 Insert_After (N, AtM_Nod);
6548 Mod_Val := Get_Alignment_Value (Expression (AtM_Nod));
6549 Set_Mod_Clause (N, Empty);
6552 -- Get the alignment value to perform error checking
6554 Mod_Val := Get_Alignment_Value (Expression (M));
6559 -- For untagged types, clear any existing component clauses for the
6560 -- type. If the type is derived, this is what allows us to override
6561 -- a rep clause for the parent. For type extensions, the representation
6562 -- of the inherited components is inherited, so we want to keep previous
6563 -- component clauses for completeness.
6565 if not Is_Tagged_Type (Rectype) then
6566 Comp := First_Component_Or_Discriminant (Rectype);
6567 while Present (Comp) loop
6568 Set_Component_Clause (Comp, Empty);
6569 Next_Component_Or_Discriminant (Comp);
6573 -- All done if no component clauses
6575 CC := First (Component_Clauses (N));
6581 -- A representation like this applies to the base type
6583 Set_Has_Record_Rep_Clause (Base_Type (Rectype));
6584 Set_Has_Non_Standard_Rep (Base_Type (Rectype));
6585 Set_Has_Specified_Layout (Base_Type (Rectype));
6587 -- Process the component clauses
6589 while Present (CC) loop
6593 if Nkind (CC) = N_Pragma then
6596 -- The only pragma of interest is Complete_Representation
6598 if Pragma_Name (CC) = Name_Complete_Representation then
6602 -- Processing for real component clause
6605 Posit := Static_Integer (Position (CC));
6606 Fbit := Static_Integer (First_Bit (CC));
6607 Lbit := Static_Integer (Last_Bit (CC));
6610 and then Fbit /= No_Uint
6611 and then Lbit /= No_Uint
6615 ("position cannot be negative", Position (CC));
6619 ("first bit cannot be negative", First_Bit (CC));
6621 -- The Last_Bit specified in a component clause must not be
6622 -- less than the First_Bit minus one (RM-13.5.1(10)).
6624 elsif Lbit < Fbit - 1 then
6626 ("last bit cannot be less than first bit minus one",
6629 -- Values look OK, so find the corresponding record component
6630 -- Even though the syntax allows an attribute reference for
6631 -- implementation-defined components, GNAT does not allow the
6632 -- tag to get an explicit position.
6634 elsif Nkind (Component_Name (CC)) = N_Attribute_Reference then
6635 if Attribute_Name (Component_Name (CC)) = Name_Tag then
6636 Error_Msg_N ("position of tag cannot be specified", CC);
6638 Error_Msg_N ("illegal component name", CC);
6642 Comp := First_Entity (Rectype);
6643 while Present (Comp) loop
6644 exit when Chars (Comp) = Chars (Component_Name (CC));
6650 -- Maybe component of base type that is absent from
6651 -- statically constrained first subtype.
6653 Comp := First_Entity (Base_Type (Rectype));
6654 while Present (Comp) loop
6655 exit when Chars (Comp) = Chars (Component_Name (CC));
6662 ("component clause is for non-existent field", CC);
6664 -- Ada 2012 (AI05-0026): Any name that denotes a
6665 -- discriminant of an object of an unchecked union type
6666 -- shall not occur within a record_representation_clause.
6668 -- The general restriction of using record rep clauses on
6669 -- Unchecked_Union types has now been lifted. Since it is
6670 -- possible to introduce a record rep clause which mentions
6671 -- the discriminant of an Unchecked_Union in non-Ada 2012
6672 -- code, this check is applied to all versions of the
6675 elsif Ekind (Comp) = E_Discriminant
6676 and then Is_Unchecked_Union (Rectype)
6679 ("cannot reference discriminant of unchecked union",
6680 Component_Name (CC));
6682 elsif Is_Record_Extension and then Is_Inherited (Comp) then
6684 ("component clause not allowed for inherited "
6685 & "component&", CC, Comp);
6687 elsif Present (Component_Clause (Comp)) then
6689 -- Diagnose duplicate rep clause, or check consistency
6690 -- if this is an inherited component. In a double fault,
6691 -- there may be a duplicate inconsistent clause for an
6692 -- inherited component.
6694 if Scope (Original_Record_Component (Comp)) = Rectype
6695 or else Parent (Component_Clause (Comp)) = N
6697 Error_Msg_Sloc := Sloc (Component_Clause (Comp));
6698 Error_Msg_N ("component clause previously given#", CC);
6702 Rep1 : constant Node_Id := Component_Clause (Comp);
6704 if Intval (Position (Rep1)) /=
6705 Intval (Position (CC))
6706 or else Intval (First_Bit (Rep1)) /=
6707 Intval (First_Bit (CC))
6708 or else Intval (Last_Bit (Rep1)) /=
6709 Intval (Last_Bit (CC))
6712 ("component clause inconsistent "
6713 & "with representation of ancestor", CC);
6715 elsif Warn_On_Redundant_Constructs then
6717 ("?r?redundant confirming component clause "
6718 & "for component!", CC);
6723 -- Normal case where this is the first component clause we
6724 -- have seen for this entity, so set it up properly.
6727 -- Make reference for field in record rep clause and set
6728 -- appropriate entity field in the field identifier.
6731 (Comp, Component_Name (CC), Set_Ref => False);
6732 Set_Entity (Component_Name (CC), Comp);
6734 -- Update Fbit and Lbit to the actual bit number
6736 Fbit := Fbit + UI_From_Int (SSU) * Posit;
6737 Lbit := Lbit + UI_From_Int (SSU) * Posit;
6739 if Has_Size_Clause (Rectype)
6740 and then RM_Size (Rectype) <= Lbit
6743 ("bit number out of range of specified size",
6746 Set_Component_Clause (Comp, CC);
6747 Set_Component_Bit_Offset (Comp, Fbit);
6748 Set_Esize (Comp, 1 + (Lbit - Fbit));
6749 Set_Normalized_First_Bit (Comp, Fbit mod SSU);
6750 Set_Normalized_Position (Comp, Fbit / SSU);
6752 if Warn_On_Overridden_Size
6753 and then Has_Size_Clause (Etype (Comp))
6754 and then RM_Size (Etype (Comp)) /= Esize (Comp)
6757 ("?S?component size overrides size clause for&",
6758 Component_Name (CC), Etype (Comp));
6761 -- This information is also set in the corresponding
6762 -- component of the base type, found by accessing the
6763 -- Original_Record_Component link if it is present.
6765 Ocomp := Original_Record_Component (Comp);
6772 (Component_Name (CC),
6778 (Comp, First_Node (CC), "component clause", Biased);
6780 if Present (Ocomp) then
6781 Set_Component_Clause (Ocomp, CC);
6782 Set_Component_Bit_Offset (Ocomp, Fbit);
6783 Set_Normalized_First_Bit (Ocomp, Fbit mod SSU);
6784 Set_Normalized_Position (Ocomp, Fbit / SSU);
6785 Set_Esize (Ocomp, 1 + (Lbit - Fbit));
6787 Set_Normalized_Position_Max
6788 (Ocomp, Normalized_Position (Ocomp));
6790 -- Note: we don't use Set_Biased here, because we
6791 -- already gave a warning above if needed, and we
6792 -- would get a duplicate for the same name here.
6794 Set_Has_Biased_Representation
6795 (Ocomp, Has_Biased_Representation (Comp));
6798 if Esize (Comp) < 0 then
6799 Error_Msg_N ("component size is negative", CC);
6810 -- Check missing components if Complete_Representation pragma appeared
6812 if Present (CR_Pragma) then
6813 Comp := First_Component_Or_Discriminant (Rectype);
6814 while Present (Comp) loop
6815 if No (Component_Clause (Comp)) then
6817 ("missing component clause for &", CR_Pragma, Comp);
6820 Next_Component_Or_Discriminant (Comp);
6823 -- Give missing components warning if required
6825 elsif Warn_On_Unrepped_Components then
6827 Num_Repped_Components : Nat := 0;
6828 Num_Unrepped_Components : Nat := 0;
6831 -- First count number of repped and unrepped components
6833 Comp := First_Component_Or_Discriminant (Rectype);
6834 while Present (Comp) loop
6835 if Present (Component_Clause (Comp)) then
6836 Num_Repped_Components := Num_Repped_Components + 1;
6838 Num_Unrepped_Components := Num_Unrepped_Components + 1;
6841 Next_Component_Or_Discriminant (Comp);
6844 -- We are only interested in the case where there is at least one
6845 -- unrepped component, and at least half the components have rep
6846 -- clauses. We figure that if less than half have them, then the
6847 -- partial rep clause is really intentional. If the component
6848 -- type has no underlying type set at this point (as for a generic
6849 -- formal type), we don't know enough to give a warning on the
6852 if Num_Unrepped_Components > 0
6853 and then Num_Unrepped_Components < Num_Repped_Components
6855 Comp := First_Component_Or_Discriminant (Rectype);
6856 while Present (Comp) loop
6857 if No (Component_Clause (Comp))
6858 and then Comes_From_Source (Comp)
6859 and then Present (Underlying_Type (Etype (Comp)))
6860 and then (Is_Scalar_Type (Underlying_Type (Etype (Comp)))
6861 or else Size_Known_At_Compile_Time
6862 (Underlying_Type (Etype (Comp))))
6863 and then not Has_Warnings_Off (Rectype)
6865 -- Ignore discriminant in unchecked union, since it is
6866 -- not there, and cannot have a component clause.
6868 and then (not Is_Unchecked_Union (Rectype)
6869 or else Ekind (Comp) /= E_Discriminant)
6871 Error_Msg_Sloc := Sloc (Comp);
6873 ("?C?no component clause given for & declared #",
6877 Next_Component_Or_Discriminant (Comp);
6882 end Analyze_Record_Representation_Clause;
6884 -------------------------------------
6885 -- Build_Discrete_Static_Predicate --
6886 -------------------------------------
6888 procedure Build_Discrete_Static_Predicate
6893 Loc : constant Source_Ptr := Sloc (Expr);
6895 Non_Static : exception;
6896 -- Raised if something non-static is found
6898 Btyp : constant Entity_Id := Base_Type (Typ);
6900 BLo : constant Uint := Expr_Value (Type_Low_Bound (Btyp));
6901 BHi : constant Uint := Expr_Value (Type_High_Bound (Btyp));
6902 -- Low bound and high bound value of base type of Typ
6906 -- Bounds for constructing the static predicate. We use the bound of the
6907 -- subtype if it is static, otherwise the corresponding base type bound.
6908 -- Note: a non-static subtype can have a static predicate.
6913 -- One entry in a Rlist value, a single REnt (range entry) value denotes
6914 -- one range from Lo to Hi. To represent a single value range Lo = Hi =
6917 type RList is array (Nat range <>) of REnt;
6918 -- A list of ranges. The ranges are sorted in increasing order, and are
6919 -- disjoint (there is a gap of at least one value between each range in
6920 -- the table). A value is in the set of ranges in Rlist if it lies
6921 -- within one of these ranges.
6923 False_Range : constant RList :=
6924 RList'(1 .. 0 => REnt'(No_Uint, No_Uint));
6925 -- An empty set of ranges represents a range list that can never be
6926 -- satisfied, since there are no ranges in which the value could lie,
6927 -- so it does not lie in any of them. False_Range is a canonical value
6928 -- for this empty set, but general processing should test for an Rlist
6929 -- with length zero (see Is_False predicate), since other null ranges
6930 -- may appear which must be treated as False.
6932 True_Range : constant RList := RList'(1 => REnt'(BLo, BHi));
6933 -- Range representing True, value must be in the base range
6935 function "and" (Left : RList; Right : RList) return RList;
6936 -- And's together two range lists, returning a range list. This is a set
6937 -- intersection operation.
6939 function "or" (Left : RList; Right : RList) return RList;
6940 -- Or's together two range lists, returning a range list. This is a set
6943 function "not" (Right : RList) return RList;
6944 -- Returns complement of a given range list, i.e. a range list
6945 -- representing all the values in TLo .. THi that are not in the input
6948 function Build_Val (V : Uint) return Node_Id;
6949 -- Return an analyzed N_Identifier node referencing this value, suitable
6950 -- for use as an entry in the Static_Discrte_Predicate list. This node
6951 -- is typed with the base type.
6953 function Build_Range (Lo : Uint; Hi : Uint) return Node_Id;
6954 -- Return an analyzed N_Range node referencing this range, suitable for
6955 -- use as an entry in the Static_Discrete_Predicate list. This node is
6956 -- typed with the base type.
6958 function Get_RList (Exp : Node_Id) return RList;
6959 -- This is a recursive routine that converts the given expression into a
6960 -- list of ranges, suitable for use in building the static predicate.
6962 function Is_False (R : RList) return Boolean;
6963 pragma Inline (Is_False);
6964 -- Returns True if the given range list is empty, and thus represents a
6965 -- False list of ranges that can never be satisfied.
6967 function Is_True (R : RList) return Boolean;
6968 -- Returns True if R trivially represents the True predicate by having a
6969 -- single range from BLo to BHi.
6971 function Is_Type_Ref (N : Node_Id) return Boolean;
6972 pragma Inline (Is_Type_Ref);
6973 -- Returns if True if N is a reference to the type for the predicate in
6974 -- the expression (i.e. if it is an identifier whose Chars field matches
6975 -- the Nam given in the call). N must not be parenthesized, if the type
6976 -- name appears in parens, this routine will return False.
6978 function Lo_Val (N : Node_Id) return Uint;
6979 -- Given an entry from a Static_Discrete_Predicate list that is either
6980 -- a static expression or static range, gets either the expression value
6981 -- or the low bound of the range.
6983 function Hi_Val (N : Node_Id) return Uint;
6984 -- Given an entry from a Static_Discrete_Predicate list that is either
6985 -- a static expression or static range, gets either the expression value
6986 -- or the high bound of the range.
6988 function Membership_Entry (N : Node_Id) return RList;
6989 -- Given a single membership entry (range, value, or subtype), returns
6990 -- the corresponding range list. Raises Static_Error if not static.
6992 function Membership_Entries (N : Node_Id) return RList;
6993 -- Given an element on an alternatives list of a membership operation,
6994 -- returns the range list corresponding to this entry and all following
6995 -- entries (i.e. returns the "or" of this list of values).
6997 function Stat_Pred (Typ : Entity_Id) return RList;
6998 -- Given a type, if it has a static predicate, then return the predicate
6999 -- as a range list, otherwise raise Non_Static.
7005 function "and" (Left : RList; Right : RList) return RList is
7007 -- First range of result
7009 SLeft : Nat := Left'First;
7010 -- Start of rest of left entries
7012 SRight : Nat := Right'First;
7013 -- Start of rest of right entries
7016 -- If either range is True, return the other
7018 if Is_True (Left) then
7020 elsif Is_True (Right) then
7024 -- If either range is False, return False
7026 if Is_False (Left) or else Is_False (Right) then
7030 -- Loop to remove entries at start that are disjoint, and thus just
7031 -- get discarded from the result entirely.
7034 -- If no operands left in either operand, result is false
7036 if SLeft > Left'Last or else SRight > Right'Last then
7039 -- Discard first left operand entry if disjoint with right
7041 elsif Left (SLeft).Hi < Right (SRight).Lo then
7044 -- Discard first right operand entry if disjoint with left
7046 elsif Right (SRight).Hi < Left (SLeft).Lo then
7047 SRight := SRight + 1;
7049 -- Otherwise we have an overlapping entry
7056 -- Now we have two non-null operands, and first entries overlap. The
7057 -- first entry in the result will be the overlapping part of these
7060 FEnt := REnt'(Lo => UI_Max (Left (SLeft).Lo, Right (SRight).Lo),
7061 Hi => UI_Min (Left (SLeft).Hi, Right (SRight).Hi));
7063 -- Now we can remove the entry that ended at a lower value, since its
7064 -- contribution is entirely contained in Fent.
7066 if Left (SLeft).Hi <= Right (SRight).Hi then
7069 SRight := SRight + 1;
7072 -- Compute result by concatenating this first entry with the "and" of
7073 -- the remaining parts of the left and right operands. Note that if
7074 -- either of these is empty, "and" will yield empty, so that we will
7075 -- end up with just Fent, which is what we want in that case.
7078 FEnt & (Left (SLeft .. Left'Last) and Right (SRight .. Right'Last));
7085 function "not" (Right : RList) return RList is
7087 -- Return True if False range
7089 if Is_False (Right) then
7093 -- Return False if True range
7095 if Is_True (Right) then
7099 -- Here if not trivial case
7102 Result : RList (1 .. Right'Length + 1);
7103 -- May need one more entry for gap at beginning and end
7106 -- Number of entries stored in Result
7111 if Right (Right'First).Lo > TLo then
7113 Result (Count) := REnt'(TLo, Right (Right'First).Lo - 1);
7116 -- Gaps between ranges
7118 for J in Right'First .. Right'Last - 1 loop
7120 Result (Count) := REnt'(Right (J).Hi + 1, Right (J + 1).Lo - 1);
7125 if Right (Right'Last).Hi < THi then
7127 Result (Count) := REnt'(Right (Right'Last).Hi + 1, THi);
7130 return Result (1 .. Count);
7138 function "or" (Left : RList; Right : RList) return RList is
7140 -- First range of result
7142 SLeft : Nat := Left'First;
7143 -- Start of rest of left entries
7145 SRight : Nat := Right'First;
7146 -- Start of rest of right entries
7149 -- If either range is True, return True
7151 if Is_True (Left) or else Is_True (Right) then
7155 -- If either range is False (empty), return the other
7157 if Is_False (Left) then
7159 elsif Is_False (Right) then
7163 -- Initialize result first entry from left or right operand depending
7164 -- on which starts with the lower range.
7166 if Left (SLeft).Lo < Right (SRight).Lo then
7167 FEnt := Left (SLeft);
7170 FEnt := Right (SRight);
7171 SRight := SRight + 1;
7174 -- This loop eats ranges from left and right operands that are
7175 -- contiguous with the first range we are gathering.
7178 -- Eat first entry in left operand if contiguous or overlapped by
7179 -- gathered first operand of result.
7181 if SLeft <= Left'Last
7182 and then Left (SLeft).Lo <= FEnt.Hi + 1
7184 FEnt.Hi := UI_Max (FEnt.Hi, Left (SLeft).Hi);
7187 -- Eat first entry in right operand if contiguous or overlapped by
7188 -- gathered right operand of result.
7190 elsif SRight <= Right'Last
7191 and then Right (SRight).Lo <= FEnt.Hi + 1
7193 FEnt.Hi := UI_Max (FEnt.Hi, Right (SRight).Hi);
7194 SRight := SRight + 1;
7196 -- All done if no more entries to eat
7203 -- Obtain result as the first entry we just computed, concatenated
7204 -- to the "or" of the remaining results (if one operand is empty,
7205 -- this will just concatenate with the other
7208 FEnt & (Left (SLeft .. Left'Last) or Right (SRight .. Right'Last));
7215 function Build_Range (Lo : Uint; Hi : Uint) return Node_Id is
7220 Low_Bound => Build_Val (Lo),
7221 High_Bound => Build_Val (Hi));
7222 Set_Etype (Result, Btyp);
7223 Set_Analyzed (Result);
7231 function Build_Val (V : Uint) return Node_Id is
7235 if Is_Enumeration_Type (Typ) then
7236 Result := Get_Enum_Lit_From_Pos (Typ, V, Loc);
7238 Result := Make_Integer_Literal (Loc, V);
7241 Set_Etype (Result, Btyp);
7242 Set_Is_Static_Expression (Result);
7243 Set_Analyzed (Result);
7251 function Get_RList (Exp : Node_Id) return RList is
7256 -- Static expression can only be true or false
7258 if Is_OK_Static_Expression (Exp) then
7259 if Expr_Value (Exp) = 0 then
7266 -- Otherwise test node type
7274 when N_Op_And | N_And_Then =>
7275 return Get_RList (Left_Opnd (Exp))
7277 Get_RList (Right_Opnd (Exp));
7281 when N_Op_Or | N_Or_Else =>
7282 return Get_RList (Left_Opnd (Exp))
7284 Get_RList (Right_Opnd (Exp));
7289 return not Get_RList (Right_Opnd (Exp));
7291 -- Comparisons of type with static value
7293 when N_Op_Compare =>
7295 -- Type is left operand
7297 if Is_Type_Ref (Left_Opnd (Exp))
7298 and then Is_OK_Static_Expression (Right_Opnd (Exp))
7300 Val := Expr_Value (Right_Opnd (Exp));
7302 -- Typ is right operand
7304 elsif Is_Type_Ref (Right_Opnd (Exp))
7305 and then Is_OK_Static_Expression (Left_Opnd (Exp))
7307 Val := Expr_Value (Left_Opnd (Exp));
7309 -- Invert sense of comparison
7312 when N_Op_Gt => Op := N_Op_Lt;
7313 when N_Op_Lt => Op := N_Op_Gt;
7314 when N_Op_Ge => Op := N_Op_Le;
7315 when N_Op_Le => Op := N_Op_Ge;
7316 when others => null;
7319 -- Other cases are non-static
7325 -- Construct range according to comparison operation
7329 return RList'(1 => REnt'(Val, Val));
7332 return RList'(1 => REnt'(Val, BHi));
7335 return RList'(1 => REnt'(Val + 1, BHi));
7338 return RList'(1 => REnt'(BLo, Val));
7341 return RList'(1 => REnt'(BLo, Val - 1));
7344 return RList'(REnt'(BLo, Val - 1), REnt'(Val + 1, BHi));
7347 raise Program_Error;
7353 if not Is_Type_Ref (Left_Opnd (Exp)) then
7357 if Present (Right_Opnd (Exp)) then
7358 return Membership_Entry (Right_Opnd (Exp));
7360 return Membership_Entries (First (Alternatives (Exp)));
7363 -- Negative membership (NOT IN)
7366 if not Is_Type_Ref (Left_Opnd (Exp)) then
7370 if Present (Right_Opnd (Exp)) then
7371 return not Membership_Entry (Right_Opnd (Exp));
7373 return not Membership_Entries (First (Alternatives (Exp)));
7376 -- Function call, may be call to static predicate
7378 when N_Function_Call =>
7379 if Is_Entity_Name (Name (Exp)) then
7381 Ent : constant Entity_Id := Entity (Name (Exp));
7383 if Is_Predicate_Function (Ent)
7385 Is_Predicate_Function_M (Ent)
7387 return Stat_Pred (Etype (First_Formal (Ent)));
7392 -- Other function call cases are non-static
7396 -- Qualified expression, dig out the expression
7398 when N_Qualified_Expression =>
7399 return Get_RList (Expression (Exp));
7401 when N_Case_Expression =>
7408 if not Is_Entity_Name (Expression (Expr))
7409 or else Etype (Expression (Expr)) /= Typ
7412 ("expression must denaote subtype", Expression (Expr));
7416 -- Collect discrete choices in all True alternatives
7418 Choices := New_List;
7419 Alt := First (Alternatives (Exp));
7420 while Present (Alt) loop
7421 Dep := Expression (Alt);
7423 if not Is_OK_Static_Expression (Dep) then
7426 elsif Is_True (Expr_Value (Dep)) then
7427 Append_List_To (Choices,
7428 New_Copy_List (Discrete_Choices (Alt)));
7434 return Membership_Entries (First (Choices));
7437 -- Expression with actions: if no actions, dig out expression
7439 when N_Expression_With_Actions =>
7440 if Is_Empty_List (Actions (Exp)) then
7441 return Get_RList (Expression (Exp));
7449 return (Get_RList (Left_Opnd (Exp))
7450 and not Get_RList (Right_Opnd (Exp)))
7451 or (Get_RList (Right_Opnd (Exp))
7452 and not Get_RList (Left_Opnd (Exp)));
7454 -- Any other node type is non-static
7465 function Hi_Val (N : Node_Id) return Uint is
7467 if Is_OK_Static_Expression (N) then
7468 return Expr_Value (N);
7470 pragma Assert (Nkind (N) = N_Range);
7471 return Expr_Value (High_Bound (N));
7479 function Is_False (R : RList) return Boolean is
7481 return R'Length = 0;
7488 function Is_True (R : RList) return Boolean is
7491 and then R (R'First).Lo = BLo
7492 and then R (R'First).Hi = BHi;
7499 function Is_Type_Ref (N : Node_Id) return Boolean is
7501 return Nkind (N) = N_Identifier
7502 and then Chars (N) = Nam
7503 and then Paren_Count (N) = 0;
7510 function Lo_Val (N : Node_Id) return Uint is
7512 if Is_OK_Static_Expression (N) then
7513 return Expr_Value (N);
7515 pragma Assert (Nkind (N) = N_Range);
7516 return Expr_Value (Low_Bound (N));
7520 ------------------------
7521 -- Membership_Entries --
7522 ------------------------
7524 function Membership_Entries (N : Node_Id) return RList is
7526 if No (Next (N)) then
7527 return Membership_Entry (N);
7529 return Membership_Entry (N) or Membership_Entries (Next (N));
7531 end Membership_Entries;
7533 ----------------------
7534 -- Membership_Entry --
7535 ----------------------
7537 function Membership_Entry (N : Node_Id) return RList is
7545 if Nkind (N) = N_Range then
7546 if not Is_OK_Static_Expression (Low_Bound (N))
7548 not Is_OK_Static_Expression (High_Bound (N))
7552 SLo := Expr_Value (Low_Bound (N));
7553 SHi := Expr_Value (High_Bound (N));
7554 return RList'(1 => REnt'(SLo, SHi));
7557 -- Static expression case
7559 elsif Is_OK_Static_Expression (N) then
7560 Val := Expr_Value (N);
7561 return RList'(1 => REnt'(Val, Val));
7563 -- Identifier (other than static expression) case
7565 else pragma Assert (Nkind (N) = N_Identifier);
7569 if Is_Type (Entity (N)) then
7571 -- If type has predicates, process them
7573 if Has_Predicates (Entity (N)) then
7574 return Stat_Pred (Entity (N));
7576 -- For static subtype without predicates, get range
7578 elsif Is_OK_Static_Subtype (Entity (N)) then
7579 SLo := Expr_Value (Type_Low_Bound (Entity (N)));
7580 SHi := Expr_Value (Type_High_Bound (Entity (N)));
7581 return RList'(1 => REnt'(SLo, SHi));
7583 -- Any other type makes us non-static
7589 -- Any other kind of identifier in predicate (e.g. a non-static
7590 -- expression value) means this is not a static predicate.
7596 end Membership_Entry;
7602 function Stat_Pred (Typ : Entity_Id) return RList is
7604 -- Not static if type does not have static predicates
7606 if not Has_Static_Predicate (Typ) then
7610 -- Otherwise we convert the predicate list to a range list
7613 Spred : constant List_Id := Static_Discrete_Predicate (Typ);
7614 Result : RList (1 .. List_Length (Spred));
7618 P := First (Static_Discrete_Predicate (Typ));
7619 for J in Result'Range loop
7620 Result (J) := REnt'(Lo_Val (P), Hi_Val (P));
7628 -- Start of processing for Build_Discrete_Static_Predicate
7631 -- Establish bounds for the predicate
7633 if Compile_Time_Known_Value (Type_Low_Bound (Typ)) then
7634 TLo := Expr_Value (Type_Low_Bound (Typ));
7639 if Compile_Time_Known_Value (Type_High_Bound (Typ)) then
7640 THi := Expr_Value (Type_High_Bound (Typ));
7645 -- Analyze the expression to see if it is a static predicate
7648 Ranges : constant RList := Get_RList (Expr);
7649 -- Range list from expression if it is static
7654 -- Convert range list into a form for the static predicate. In the
7655 -- Ranges array, we just have raw ranges, these must be converted
7656 -- to properly typed and analyzed static expressions or range nodes.
7658 -- Note: here we limit ranges to the ranges of the subtype, so that
7659 -- a predicate is always false for values outside the subtype. That
7660 -- seems fine, such values are invalid anyway, and considering them
7661 -- to fail the predicate seems allowed and friendly, and furthermore
7662 -- simplifies processing for case statements and loops.
7666 for J in Ranges'Range loop
7668 Lo : Uint := Ranges (J).Lo;
7669 Hi : Uint := Ranges (J).Hi;
7672 -- Ignore completely out of range entry
7674 if Hi < TLo or else Lo > THi then
7677 -- Otherwise process entry
7680 -- Adjust out of range value to subtype range
7690 -- Convert range into required form
7692 Append_To (Plist, Build_Range (Lo, Hi));
7697 -- Processing was successful and all entries were static, so now we
7698 -- can store the result as the predicate list.
7700 Set_Static_Discrete_Predicate (Typ, Plist);
7702 -- The processing for static predicates put the expression into
7703 -- canonical form as a series of ranges. It also eliminated
7704 -- duplicates and collapsed and combined ranges. We might as well
7705 -- replace the alternatives list of the right operand of the
7706 -- membership test with the static predicate list, which will
7707 -- usually be more efficient.
7710 New_Alts : constant List_Id := New_List;
7715 Old_Node := First (Plist);
7716 while Present (Old_Node) loop
7717 New_Node := New_Copy (Old_Node);
7719 if Nkind (New_Node) = N_Range then
7720 Set_Low_Bound (New_Node, New_Copy (Low_Bound (Old_Node)));
7721 Set_High_Bound (New_Node, New_Copy (High_Bound (Old_Node)));
7724 Append_To (New_Alts, New_Node);
7728 -- If empty list, replace by False
7730 if Is_Empty_List (New_Alts) then
7731 Rewrite (Expr, New_Occurrence_Of (Standard_False, Loc));
7733 -- Else replace by set membership test
7738 Left_Opnd => Make_Identifier (Loc, Nam),
7739 Right_Opnd => Empty,
7740 Alternatives => New_Alts));
7742 -- Resolve new expression in function context
7744 Install_Formals (Predicate_Function (Typ));
7745 Push_Scope (Predicate_Function (Typ));
7746 Analyze_And_Resolve (Expr, Standard_Boolean);
7752 -- If non-static, return doing nothing
7757 end Build_Discrete_Static_Predicate;
7759 -------------------------------------------
7760 -- Build_Invariant_Procedure_Declaration --
7761 -------------------------------------------
7763 function Build_Invariant_Procedure_Declaration
7764 (Typ : Entity_Id) return Node_Id
7766 GM : constant Ghost_Mode_Type := Ghost_Mode;
7767 Loc : constant Source_Ptr := Sloc (Typ);
7773 -- Check for duplicate definiations
7775 if Has_Invariants (Typ) and then Present (Invariant_Procedure (Typ)) then
7779 -- The related type may be subject to pragma Ghost with policy Ignore.
7780 -- Set the mode now to ensure that the predicate functions are properly
7781 -- flagged as ignored Ghost.
7783 Set_Ghost_Mode_From_Entity (Typ);
7786 Make_Defining_Identifier (Loc,
7787 Chars => New_External_Name (Chars (Typ), "Invariant"));
7788 Set_Has_Invariants (Typ);
7789 Set_Ekind (SId, E_Procedure);
7790 Set_Etype (SId, Standard_Void_Type);
7791 Set_Is_Invariant_Procedure (SId);
7792 Set_Invariant_Procedure (Typ, SId);
7794 -- Mark the invariant procedure explicitly as Ghost because it does not
7795 -- come from source.
7797 if Ghost_Mode > None then
7798 Set_Is_Ghost_Entity (SId);
7801 Obj_Id := Make_Defining_Identifier (Loc, New_Internal_Name ('I'));
7802 Set_Etype (Obj_Id, Typ);
7805 Make_Subprogram_Declaration (Loc,
7806 Make_Procedure_Specification (Loc,
7807 Defining_Unit_Name => SId,
7808 Parameter_Specifications => New_List (
7809 Make_Parameter_Specification (Loc,
7810 Defining_Identifier => Obj_Id,
7811 Parameter_Type => New_Occurrence_Of (Typ, Loc)))));
7813 -- Restore the original Ghost mode once analysis and expansion have
7819 end Build_Invariant_Procedure_Declaration;
7821 -------------------------------
7822 -- Build_Invariant_Procedure --
7823 -------------------------------
7825 -- The procedure that is constructed here has the form
7827 -- procedure typInvariant (Ixxx : typ) is
7829 -- pragma Check (Invariant, exp, "failed invariant from xxx");
7830 -- pragma Check (Invariant, exp, "failed invariant from xxx");
7832 -- pragma Check (Invariant, exp, "failed inherited invariant from xxx");
7834 -- end typInvariant;
7836 procedure Build_Invariant_Procedure (Typ : Entity_Id; N : Node_Id) is
7837 Priv_Decls : constant List_Id := Private_Declarations (N);
7838 Vis_Decls : constant List_Id := Visible_Declarations (N);
7840 Loc : constant Source_Ptr := Sloc (Typ);
7847 Object_Entity : Node_Id;
7848 -- The entity of the formal for the procedure
7850 Object_Name : Name_Id;
7851 -- Name for argument of invariant procedure
7853 procedure Add_Invariants (T : Entity_Id; Inherit : Boolean);
7854 -- Appends statements to Stmts for any invariants in the rep item chain
7855 -- of the given type. If Inherit is False, then we only process entries
7856 -- on the chain for the type Typ. If Inherit is True, then we ignore any
7857 -- Invariant aspects, but we process all Invariant'Class aspects, adding
7858 -- "inherited" to the exception message and generating an informational
7859 -- message about the inheritance of an invariant.
7861 --------------------
7862 -- Add_Invariants --
7863 --------------------
7865 procedure Add_Invariants (T : Entity_Id; Inherit : Boolean) is
7866 procedure Add_Invariant (Prag : Node_Id);
7867 -- Create a runtime check to verify the exression of invariant pragma
7868 -- Prag. All generated code is added to list Stmts.
7874 procedure Add_Invariant (Prag : Node_Id) is
7875 procedure Replace_Type_Reference (N : Node_Id);
7876 -- Replace a single occurrence N of the subtype name with a
7877 -- reference to the formal of the predicate function. N can be an
7878 -- identifier referencing the subtype, or a selected component,
7879 -- representing an appropriately qualified occurrence of the
7882 procedure Replace_Type_References is
7883 new Replace_Type_References_Generic (Replace_Type_Reference);
7884 -- Traverse an expression replacing all occurrences of the subtype
7885 -- name with appropriate references to the formal of the predicate
7886 -- function. Note that we must ensure that the type and entity
7887 -- information is properly set in the replacement node, since we
7888 -- will do a Preanalyze call of this expression without proper
7889 -- visibility of the procedure argument.
7891 ----------------------------
7892 -- Replace_Type_Reference --
7893 ----------------------------
7895 -- Note: See comments in Add_Predicates.Replace_Type_Reference
7896 -- regarding handling of Sloc and Comes_From_Source.
7898 procedure Replace_Type_Reference (N : Node_Id) is
7899 Nloc : constant Source_Ptr := Sloc (N);
7902 -- Add semantic information to node to be rewritten, for ASIS
7903 -- navigation needs.
7905 if Nkind (N) = N_Identifier then
7909 elsif Nkind (N) = N_Selected_Component then
7910 Analyze (Prefix (N));
7911 Set_Entity (Selector_Name (N), T);
7912 Set_Etype (Selector_Name (N), T);
7915 -- Invariant'Class, replace with T'Class (obj)
7917 if Class_Present (Prag) then
7919 -- In ASIS mode, an inherited item is already analyzed,
7920 -- and the replacement has been done, so do not repeat
7921 -- the transformation to prevent a malformed tree.
7924 and then Nkind (Parent (N)) = N_Attribute_Reference
7925 and then Attribute_Name (Parent (N)) = Name_Class
7931 Make_Type_Conversion (Nloc,
7933 Make_Attribute_Reference (Nloc,
7934 Prefix => New_Occurrence_Of (T, Nloc),
7935 Attribute_Name => Name_Class),
7936 Expression => Make_Identifier (Nloc, Object_Name)));
7938 Set_Entity (Expression (N), Object_Entity);
7939 Set_Etype (Expression (N), Typ);
7942 -- Invariant, replace with obj
7945 Rewrite (N, Make_Identifier (Nloc, Object_Name));
7946 Set_Entity (N, Object_Entity);
7950 Set_Comes_From_Source (N, True);
7951 end Replace_Type_Reference;
7955 Asp : constant Node_Id := Corresponding_Aspect (Prag);
7956 Nam : constant Name_Id := Original_Aspect_Pragma_Name (Prag);
7957 Ploc : constant Source_Ptr := Sloc (Prag);
7965 -- Start of processing for Add_Invariant
7968 -- Extract the arguments of the invariant pragma
7970 Arg1 := First (Pragma_Argument_Associations (Prag));
7971 Arg2 := Next (Arg1);
7972 Arg3 := Next (Arg2);
7974 Arg1 := Get_Pragma_Arg (Arg1);
7975 Arg2 := Get_Pragma_Arg (Arg2);
7977 -- The caller requests processing of all Invariant'Class pragmas,
7978 -- but the current pragma does not fall in this category. Return
7979 -- as there is nothing left to do.
7982 if not Class_Present (Prag) then
7986 -- Otherwise the pragma must apply to the current type
7988 elsif Entity (Arg1) /= T then
7992 Expr := New_Copy_Tree (Arg2);
7994 -- Replace all occurrences of the type's name with references to
7995 -- the formal parameter of the invariant procedure.
7997 Replace_Type_References (Expr, T);
7999 -- If the invariant pragma comes from an aspect, replace the saved
8000 -- expression because we need the subtype references replaced for
8001 -- the calls to Preanalyze_Spec_Expression in Check_Aspect_At_xxx
8004 if Present (Asp) then
8005 Set_Entity (Identifier (Asp), New_Copy_Tree (Expr));
8008 -- Preanalyze the invariant expression to capture the visibility
8009 -- of the proper package part. In general the expression is not
8010 -- fully analyzed until the body of the invariant procedure is
8011 -- analyzed at the end of the private part, but that yields the
8012 -- wrong visibility.
8014 -- Historic note: we used to set N as the parent, but a package
8015 -- specification as the parent of an expression is bizarre.
8017 Set_Parent (Expr, Parent (Arg2));
8018 Preanalyze_Assert_Expression (Expr, Any_Boolean);
8020 -- A class-wide invariant may be inherited in a separate unit,
8021 -- where the corresponding expression cannot be resolved by
8022 -- visibility, because it refers to a local function. Propagate
8023 -- semantic information to the original representation item, to
8024 -- be used when an invariant procedure for a derived type is
8027 -- ??? Unclear how to handle class-wide invariants that are not
8031 and then Class_Present (Prag)
8032 and then Nkind (Expr) = N_Function_Call
8033 and then Nkind (Arg2) = N_Indexed_Component
8036 Make_Function_Call (Ploc,
8038 New_Occurrence_Of (Entity (Name (Expr)), Ploc),
8039 Parameter_Associations =>
8040 New_Copy_List (Expressions (Arg2))));
8043 -- In ASIS mode, even if assertions are not enabled, we must
8044 -- analyze the original expression in the aspect specification
8045 -- because it is part of the original tree.
8047 if ASIS_Mode and then Present (Asp) then
8049 Orig_Expr : constant Node_Id := Expression (Asp);
8051 Replace_Type_References (Orig_Expr, T);
8052 Preanalyze_Assert_Expression (Orig_Expr, Any_Boolean);
8056 -- An ignored invariant must not generate a runtime check. Add a
8057 -- null statement to ensure that the invariant procedure does get
8058 -- a completing body.
8061 Stmts := Empty_List;
8064 if Is_Ignored (Prag) then
8065 Append_To (Stmts, Make_Null_Statement (Ploc));
8067 -- Otherwise the invariant is checked. Build a Check pragma to
8068 -- verify the expression at runtime.
8072 Make_Pragma_Argument_Association (Ploc,
8073 Expression => Make_Identifier (Ploc, Nam)),
8074 Make_Pragma_Argument_Association (Ploc,
8075 Expression => Expr));
8077 -- Handle the String argument (if any)
8079 if Present (Arg3) then
8080 Str := Strval (Get_Pragma_Arg (Arg3));
8082 -- When inheriting an invariant, modify the message from
8083 -- "failed invariant" to "failed inherited invariant".
8086 String_To_Name_Buffer (Str);
8088 if Name_Buffer (1 .. 16) = "failed invariant" then
8089 Insert_Str_In_Name_Buffer ("inherited ", 8);
8090 Str := String_From_Name_Buffer;
8095 Make_Pragma_Argument_Association (Ploc,
8096 Expression => Make_String_Literal (Ploc, Str)));
8100 -- pragma Check (Nam, Expr, Str);
8104 Pragma_Identifier =>
8105 Make_Identifier (Ploc, Name_Check),
8106 Pragma_Argument_Associations => Assoc));
8109 -- Output an info message when inheriting an invariant and the
8110 -- listing option is enabled.
8112 if Inherit and Opt.List_Inherited_Aspects then
8113 Error_Msg_Sloc := Sloc (Prag);
8115 ("info: & inherits `Invariant''Class` aspect from #?L?", Typ);
8123 -- Start of processing for Add_Invariants
8126 Ritem := First_Rep_Item (T);
8127 while Present (Ritem) loop
8128 if Nkind (Ritem) = N_Pragma
8129 and then Pragma_Name (Ritem) = Name_Invariant
8131 Add_Invariant (Ritem);
8134 Next_Rep_Item (Ritem);
8138 -- Start of processing for Build_Invariant_Procedure
8146 -- If the aspect specification exists for some view of the type, the
8147 -- declaration for the procedure has been created.
8149 if Has_Invariants (Typ) then
8150 SId := Invariant_Procedure (Typ);
8153 -- If the body is already present, nothing to do. This will occur when
8154 -- the type is already frozen, which is the case when the invariant
8155 -- appears in a private part, and the freezing takes place before the
8156 -- final pass over full declarations.
8158 -- See Exp_Ch3.Insert_Component_Invariant_Checks for details.
8160 if Present (SId) then
8161 PDecl := Unit_Declaration_Node (SId);
8164 and then Nkind (PDecl) = N_Subprogram_Declaration
8165 and then Present (Corresponding_Body (PDecl))
8171 PDecl := Build_Invariant_Procedure_Declaration (Typ);
8174 -- Recover formal of procedure, for use in the calls to invariant
8175 -- functions (including inherited ones).
8179 (First (Parameter_Specifications (Specification (PDecl))));
8180 Object_Name := Chars (Object_Entity);
8182 -- Add invariants for the current type
8184 Add_Invariants (Typ, Inherit => False);
8186 -- Add invariants for parent types
8189 Current_Typ : Entity_Id;
8190 Parent_Typ : Entity_Id;
8195 Parent_Typ := Etype (Current_Typ);
8197 if Is_Private_Type (Parent_Typ)
8198 and then Present (Full_View (Base_Type (Parent_Typ)))
8200 Parent_Typ := Full_View (Base_Type (Parent_Typ));
8203 exit when Parent_Typ = Current_Typ;
8205 Current_Typ := Parent_Typ;
8206 Add_Invariants (Current_Typ, Inherit => True);
8210 -- Add invariants of progenitors
8212 if Is_Tagged_Type (Typ) and then not Is_Interface (Typ) then
8214 Ifaces_List : Elist_Id;
8219 Collect_Interfaces (Typ, Ifaces_List);
8221 AI := First_Elmt (Ifaces_List);
8222 while Present (AI) loop
8225 if not Is_Ancestor (Iface, Typ, Use_Full_View => True) then
8226 Add_Invariants (Iface, Inherit => True);
8234 -- Build the procedure if we generated at least one Check pragma
8236 if Stmts /= No_List then
8237 Spec := Copy_Separate_Tree (Specification (PDecl));
8240 Make_Subprogram_Body (Loc,
8241 Specification => Spec,
8242 Declarations => Empty_List,
8243 Handled_Statement_Sequence =>
8244 Make_Handled_Sequence_Of_Statements (Loc,
8245 Statements => Stmts));
8247 -- Insert procedure declaration and spec at the appropriate points.
8248 -- If declaration is already analyzed, it was processed by the
8249 -- generated pragma.
8251 if Present (Priv_Decls) then
8253 -- The spec goes at the end of visible declarations, but they have
8254 -- already been analyzed, so we need to explicitly do the analyze.
8256 if not Analyzed (PDecl) then
8257 Append_To (Vis_Decls, PDecl);
8261 -- The body goes at the end of the private declarations, which we
8262 -- have not analyzed yet, so we do not need to perform an explicit
8263 -- analyze call. We skip this if there are no private declarations
8264 -- (this is an error that will be caught elsewhere);
8266 Append_To (Priv_Decls, PBody);
8268 -- If the invariant appears on the full view of a type, the
8269 -- analysis of the private part is complete, and we must
8270 -- analyze the new body explicitly.
8272 if In_Private_Part (Current_Scope) then
8276 -- If there are no private declarations this may be an error that
8277 -- will be diagnosed elsewhere. However, if this is a non-private
8278 -- type that inherits invariants, it needs no completion and there
8279 -- may be no private part. In this case insert invariant procedure
8280 -- at end of current declarative list, and analyze at once, given
8281 -- that the type is about to be frozen.
8283 elsif not Is_Private_Type (Typ) then
8284 Append_To (Vis_Decls, PDecl);
8285 Append_To (Vis_Decls, PBody);
8290 end Build_Invariant_Procedure;
8292 -------------------------------
8293 -- Build_Predicate_Functions --
8294 -------------------------------
8296 -- The procedures that are constructed here have the form:
8298 -- function typPredicate (Ixxx : typ) return Boolean is
8301 -- exp1 and then exp2 and then ...
8302 -- and then typ1Predicate (typ1 (Ixxx))
8303 -- and then typ2Predicate (typ2 (Ixxx))
8305 -- end typPredicate;
8307 -- Here exp1, and exp2 are expressions from Predicate pragmas. Note that
8308 -- this is the point at which these expressions get analyzed, providing the
8309 -- required delay, and typ1, typ2, are entities from which predicates are
8310 -- inherited. Note that we do NOT generate Check pragmas, that's because we
8311 -- use this function even if checks are off, e.g. for membership tests.
8313 -- If the expression has at least one Raise_Expression, then we also build
8314 -- the typPredicateM version of the function, in which any occurrence of a
8315 -- Raise_Expression is converted to "return False".
8317 procedure Build_Predicate_Functions (Typ : Entity_Id; N : Node_Id) is
8318 Loc : constant Source_Ptr := Sloc (Typ);
8321 -- This is the expression for the result of the function. It is
8322 -- is build by connecting the component predicates with AND THEN.
8325 -- This is the corresponding return expression for the Predicate_M
8326 -- function. It differs in that raise expressions are marked for
8327 -- special expansion (see Process_REs).
8329 Object_Name : constant Name_Id := New_Internal_Name ('I');
8330 -- Name for argument of Predicate procedure. Note that we use the same
8331 -- name for both predicate functions. That way the reference within the
8332 -- predicate expression is the same in both functions.
8334 Object_Entity : constant Entity_Id :=
8335 Make_Defining_Identifier (Loc, Chars => Object_Name);
8336 -- Entity for argument of Predicate procedure
8338 Object_Entity_M : constant Entity_Id :=
8339 Make_Defining_Identifier (Loc, Chars => Object_Name);
8340 -- Entity for argument of Predicate_M procedure
8342 Raise_Expression_Present : Boolean := False;
8343 -- Set True if Expr has at least one Raise_Expression
8345 procedure Add_Call (T : Entity_Id);
8346 -- Includes a call to the predicate function for type T in Expr if T
8347 -- has predicates and Predicate_Function (T) is non-empty.
8349 procedure Add_Predicates;
8350 -- Appends expressions for any Predicate pragmas in the rep item chain
8351 -- Typ to Expr. Note that we look only at items for this exact entity.
8352 -- Inheritance of predicates for the parent type is done by calling the
8353 -- Predicate_Function of the parent type, using Add_Call above.
8355 function Process_RE (N : Node_Id) return Traverse_Result;
8356 -- Used in Process REs, tests if node N is a raise expression, and if
8357 -- so, marks it to be converted to return False.
8359 procedure Process_REs is new Traverse_Proc (Process_RE);
8360 -- Marks any raise expressions in Expr_M to return False
8362 function Test_RE (N : Node_Id) return Traverse_Result;
8363 -- Used in Test_REs, tests one node for being a raise expression, and if
8364 -- so sets Raise_Expression_Present True.
8366 procedure Test_REs is new Traverse_Proc (Test_RE);
8367 -- Tests to see if Expr contains any raise expressions
8373 procedure Add_Call (T : Entity_Id) is
8377 if Present (T) and then Present (Predicate_Function (T)) then
8378 Set_Has_Predicates (Typ);
8380 -- Build the call to the predicate function of T
8384 (T, Convert_To (T, Make_Identifier (Loc, Object_Name)));
8386 -- Add call to evolving expression, using AND THEN if needed
8393 Make_And_Then (Sloc (Expr),
8394 Left_Opnd => Relocate_Node (Expr),
8398 -- Output info message on inheritance if required. Note we do not
8399 -- give this information for generic actual types, since it is
8400 -- unwelcome noise in that case in instantiations. We also
8401 -- generally suppress the message in instantiations, and also
8402 -- if it involves internal names.
8404 if Opt.List_Inherited_Aspects
8405 and then not Is_Generic_Actual_Type (Typ)
8406 and then Instantiation_Depth (Sloc (Typ)) = 0
8407 and then not Is_Internal_Name (Chars (T))
8408 and then not Is_Internal_Name (Chars (Typ))
8410 Error_Msg_Sloc := Sloc (Predicate_Function (T));
8411 Error_Msg_Node_2 := T;
8412 Error_Msg_N ("info: & inherits predicate from & #?L?", Typ);
8417 --------------------
8418 -- Add_Predicates --
8419 --------------------
8421 procedure Add_Predicates is
8422 procedure Add_Predicate (Prag : Node_Id);
8423 -- Concatenate the expression of predicate pragma Prag to Expr by
8424 -- using a short circuit "and then" operator.
8430 procedure Add_Predicate (Prag : Node_Id) is
8431 procedure Replace_Type_Reference (N : Node_Id);
8432 -- Replace a single occurrence N of the subtype name with a
8433 -- reference to the formal of the predicate function. N can be an
8434 -- identifier referencing the subtype, or a selected component,
8435 -- representing an appropriately qualified occurrence of the
8438 procedure Replace_Type_References is
8439 new Replace_Type_References_Generic (Replace_Type_Reference);
8440 -- Traverse an expression changing every occurrence of an
8441 -- identifier whose name matches the name of the subtype with a
8442 -- reference to the formal parameter of the predicate function.
8444 ----------------------------
8445 -- Replace_Type_Reference --
8446 ----------------------------
8448 procedure Replace_Type_Reference (N : Node_Id) is
8450 Rewrite (N, Make_Identifier (Sloc (N), Object_Name));
8451 -- Use the Sloc of the usage name, not the defining name
8454 Set_Entity (N, Object_Entity);
8456 -- We want to treat the node as if it comes from source, so
8457 -- that ASIS will not ignore it.
8459 Set_Comes_From_Source (N, True);
8460 end Replace_Type_Reference;
8464 Asp : constant Node_Id := Corresponding_Aspect (Prag);
8468 -- Start of processing for Add_Predicate
8471 -- Extract the arguments of the pragma. The expression itself
8472 -- is copied for use in the predicate function, to preserve the
8473 -- original version for ASIS use.
8475 Arg1 := First (Pragma_Argument_Associations (Prag));
8476 Arg2 := Next (Arg1);
8478 Arg1 := Get_Pragma_Arg (Arg1);
8479 Arg2 := New_Copy_Tree (Get_Pragma_Arg (Arg2));
8481 -- When the predicate pragma applies to the current type or its
8482 -- full view, replace all occurrences of the subtype name with
8483 -- references to the formal parameter of the predicate function.
8485 if Entity (Arg1) = Typ
8486 or else Full_View (Entity (Arg1)) = Typ
8488 Replace_Type_References (Arg2, Typ);
8490 -- If the predicate pragma comes from an aspect, replace the
8491 -- saved expression because we need the subtype references
8492 -- replaced for the calls to Preanalyze_Spec_Expression in
8493 -- Check_Aspect_At_xxx routines.
8495 if Present (Asp) then
8497 -- For ASIS use, perform semantic analysis of the original
8498 -- predicate expression, which is otherwise not utilized.
8501 Preanalyze_And_Resolve (Expression (Asp));
8504 Set_Entity (Identifier (Asp), New_Copy_Tree (Arg2));
8507 -- Concatenate to the existing predicate expressions by using
8510 if Present (Expr) then
8513 Left_Opnd => Relocate_Node (Expr),
8514 Right_Opnd => Relocate_Node (Arg2));
8516 -- Otherwise this is the first predicate expression
8519 Expr := Relocate_Node (Arg2);
8528 -- Start of processing for Add_Predicates
8531 Ritem := First_Rep_Item (Typ);
8532 while Present (Ritem) loop
8533 if Nkind (Ritem) = N_Pragma
8534 and then Pragma_Name (Ritem) = Name_Predicate
8536 Add_Predicate (Ritem);
8539 Next_Rep_Item (Ritem);
8547 function Process_RE (N : Node_Id) return Traverse_Result is
8549 if Nkind (N) = N_Raise_Expression then
8550 Set_Convert_To_Return_False (N);
8561 function Test_RE (N : Node_Id) return Traverse_Result is
8563 if Nkind (N) = N_Raise_Expression then
8564 Raise_Expression_Present := True;
8573 GM : constant Ghost_Mode_Type := Ghost_Mode;
8575 -- Start of processing for Build_Predicate_Functions
8578 -- Return if already built or if type does not have predicates
8580 if not Has_Predicates (Typ)
8581 or else Present (Predicate_Function (Typ))
8586 -- The related type may be subject to pragma Ghost with policy Ignore.
8587 -- Set the mode now to ensure that the predicate functions are properly
8588 -- flagged as ignored Ghost.
8590 Set_Ghost_Mode_From_Entity (Typ);
8592 -- Prepare to construct predicate expression
8596 -- Add Predicates for the current type
8600 -- Add predicates for ancestor if present
8603 Atyp : constant Entity_Id := Nearest_Ancestor (Typ);
8605 if Present (Atyp) then
8610 -- Case where predicates are present
8612 if Present (Expr) then
8614 -- Test for raise expression present
8618 -- If raise expression is present, capture a copy of Expr for use
8619 -- in building the predicateM function version later on. For this
8620 -- copy we replace references to Object_Entity by Object_Entity_M.
8622 if Raise_Expression_Present then
8624 Map : constant Elist_Id := New_Elmt_List;
8625 New_V : Entity_Id := Empty;
8627 -- The unanalyzed expression will be copied and appear in
8628 -- both functions. Normally expressions do not declare new
8629 -- entities, but quantified expressions do, so we need to
8630 -- create new entities for their bound variables, to prevent
8631 -- multiple definitions in gigi.
8633 function Reset_Loop_Variable (N : Node_Id)
8634 return Traverse_Result;
8636 procedure Collect_Loop_Variables is
8637 new Traverse_Proc (Reset_Loop_Variable);
8639 ------------------------
8640 -- Reset_Loop_Variable --
8641 ------------------------
8643 function Reset_Loop_Variable (N : Node_Id)
8644 return Traverse_Result
8647 if Nkind (N) = N_Iterator_Specification then
8648 New_V := Make_Defining_Identifier
8649 (Sloc (N), Chars (Defining_Identifier (N)));
8651 Set_Defining_Identifier (N, New_V);
8655 end Reset_Loop_Variable;
8658 Append_Elmt (Object_Entity, Map);
8659 Append_Elmt (Object_Entity_M, Map);
8660 Expr_M := New_Copy_Tree (Expr, Map => Map);
8661 Collect_Loop_Variables (Expr_M);
8665 -- Build the main predicate function
8668 SId : constant Entity_Id :=
8669 Make_Defining_Identifier (Loc,
8670 Chars => New_External_Name (Chars (Typ), "Predicate"));
8671 -- The entity for the the function spec
8673 SIdB : constant Entity_Id :=
8674 Make_Defining_Identifier (Loc,
8675 Chars => New_External_Name (Chars (Typ), "Predicate"));
8676 -- The entity for the function body
8683 -- Build function declaration
8685 Set_Ekind (SId, E_Function);
8686 Set_Is_Internal (SId);
8687 Set_Is_Predicate_Function (SId);
8688 Set_Predicate_Function (Typ, SId);
8690 -- The predicate function is shared between views of a type
8692 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
8693 Set_Predicate_Function (Full_View (Typ), SId);
8696 -- Mark the predicate function explicitly as Ghost because it does
8697 -- not come from source.
8699 if Ghost_Mode > None then
8700 Set_Is_Ghost_Entity (SId);
8704 Make_Function_Specification (Loc,
8705 Defining_Unit_Name => SId,
8706 Parameter_Specifications => New_List (
8707 Make_Parameter_Specification (Loc,
8708 Defining_Identifier => Object_Entity,
8709 Parameter_Type => New_Occurrence_Of (Typ, Loc))),
8710 Result_Definition =>
8711 New_Occurrence_Of (Standard_Boolean, Loc));
8714 Make_Subprogram_Declaration (Loc,
8715 Specification => Spec);
8717 -- Build function body
8720 Make_Function_Specification (Loc,
8721 Defining_Unit_Name => SIdB,
8722 Parameter_Specifications => New_List (
8723 Make_Parameter_Specification (Loc,
8724 Defining_Identifier =>
8725 Make_Defining_Identifier (Loc, Object_Name),
8727 New_Occurrence_Of (Typ, Loc))),
8728 Result_Definition =>
8729 New_Occurrence_Of (Standard_Boolean, Loc));
8732 Make_Subprogram_Body (Loc,
8733 Specification => Spec,
8734 Declarations => Empty_List,
8735 Handled_Statement_Sequence =>
8736 Make_Handled_Sequence_Of_Statements (Loc,
8737 Statements => New_List (
8738 Make_Simple_Return_Statement (Loc,
8739 Expression => Expr))));
8741 -- Insert declaration before freeze node and body after
8743 Insert_Before_And_Analyze (N, FDecl);
8744 Insert_After_And_Analyze (N, FBody);
8747 -- Test for raise expressions present and if so build M version
8749 if Raise_Expression_Present then
8751 SId : constant Entity_Id :=
8752 Make_Defining_Identifier (Loc,
8753 Chars => New_External_Name (Chars (Typ), "PredicateM"));
8754 -- The entity for the the function spec
8756 SIdB : constant Entity_Id :=
8757 Make_Defining_Identifier (Loc,
8758 Chars => New_External_Name (Chars (Typ), "PredicateM"));
8759 -- The entity for the function body
8767 -- Mark any raise expressions for special expansion
8769 Process_REs (Expr_M);
8771 -- Build function declaration
8773 Set_Ekind (SId, E_Function);
8774 Set_Is_Predicate_Function_M (SId);
8775 Set_Predicate_Function_M (Typ, SId);
8777 -- The predicate function is shared between views of a type
8779 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
8780 Set_Predicate_Function_M (Full_View (Typ), SId);
8783 -- Mark the predicate function explicitly as Ghost because it
8784 -- does not come from source.
8786 if Ghost_Mode > None then
8787 Set_Is_Ghost_Entity (SId);
8791 Make_Function_Specification (Loc,
8792 Defining_Unit_Name => SId,
8793 Parameter_Specifications => New_List (
8794 Make_Parameter_Specification (Loc,
8795 Defining_Identifier => Object_Entity_M,
8796 Parameter_Type => New_Occurrence_Of (Typ, Loc))),
8797 Result_Definition =>
8798 New_Occurrence_Of (Standard_Boolean, Loc));
8801 Make_Subprogram_Declaration (Loc,
8802 Specification => Spec);
8804 -- Build function body
8807 Make_Function_Specification (Loc,
8808 Defining_Unit_Name => SIdB,
8809 Parameter_Specifications => New_List (
8810 Make_Parameter_Specification (Loc,
8811 Defining_Identifier =>
8812 Make_Defining_Identifier (Loc, Object_Name),
8814 New_Occurrence_Of (Typ, Loc))),
8815 Result_Definition =>
8816 New_Occurrence_Of (Standard_Boolean, Loc));
8818 -- Build the body, we declare the boolean expression before
8819 -- doing the return, because we are not really confident of
8820 -- what happens if a return appears within a return.
8823 Make_Defining_Identifier (Loc,
8824 Chars => New_Internal_Name ('B'));
8827 Make_Subprogram_Body (Loc,
8828 Specification => Spec,
8830 Declarations => New_List (
8831 Make_Object_Declaration (Loc,
8832 Defining_Identifier => BTemp,
8833 Constant_Present => True,
8834 Object_Definition =>
8835 New_Occurrence_Of (Standard_Boolean, Loc),
8836 Expression => Expr_M)),
8838 Handled_Statement_Sequence =>
8839 Make_Handled_Sequence_Of_Statements (Loc,
8840 Statements => New_List (
8841 Make_Simple_Return_Statement (Loc,
8842 Expression => New_Occurrence_Of (BTemp, Loc)))));
8844 -- Insert declaration before freeze node and body after
8846 Insert_Before_And_Analyze (N, FDecl);
8847 Insert_After_And_Analyze (N, FBody);
8851 -- See if we have a static predicate. Note that the answer may be
8852 -- yes even if we have an explicit Dynamic_Predicate present.
8859 if not Is_Scalar_Type (Typ) and then not Is_String_Type (Typ) then
8862 PS := Is_Predicate_Static (Expr, Object_Name);
8865 -- Case where we have a predicate-static aspect
8869 -- We don't set Has_Static_Predicate_Aspect, since we can have
8870 -- any of the three cases (Predicate, Dynamic_Predicate, or
8871 -- Static_Predicate) generating a predicate with an expression
8872 -- that is predicate-static. We just indicate that we have a
8873 -- predicate that can be treated as static.
8875 Set_Has_Static_Predicate (Typ);
8877 -- For discrete subtype, build the static predicate list
8879 if Is_Discrete_Type (Typ) then
8880 Build_Discrete_Static_Predicate (Typ, Expr, Object_Name);
8882 -- If we don't get a static predicate list, it means that we
8883 -- have a case where this is not possible, most typically in
8884 -- the case where we inherit a dynamic predicate. We do not
8885 -- consider this an error, we just leave the predicate as
8886 -- dynamic. But if we do succeed in building the list, then
8887 -- we mark the predicate as static.
8889 if No (Static_Discrete_Predicate (Typ)) then
8890 Set_Has_Static_Predicate (Typ, False);
8893 -- For real or string subtype, save predicate expression
8895 elsif Is_Real_Type (Typ) or else Is_String_Type (Typ) then
8896 Set_Static_Real_Or_String_Predicate (Typ, Expr);
8899 -- Case of dynamic predicate (expression is not predicate-static)
8902 -- Again, we don't set Has_Dynamic_Predicate_Aspect, since that
8903 -- is only set if we have an explicit Dynamic_Predicate aspect
8904 -- given. Here we may simply have a Predicate aspect where the
8905 -- expression happens not to be predicate-static.
8907 -- Emit an error when the predicate is categorized as static
8908 -- but its expression is not predicate-static.
8910 -- First a little fiddling to get a nice location for the
8911 -- message. If the expression is of the form (A and then B),
8912 -- then use the left operand for the Sloc. This avoids getting
8913 -- confused by a call to a higher-level predicate with a less
8914 -- convenient source location.
8917 while Nkind (EN) = N_And_Then loop
8918 EN := Left_Opnd (EN);
8921 -- Now post appropriate message
8923 if Has_Static_Predicate_Aspect (Typ) then
8924 if Is_Scalar_Type (Typ) or else Is_String_Type (Typ) then
8926 ("expression is not predicate-static (RM 3.2.4(16-22))",
8930 ("static predicate requires scalar or string type", EN);
8937 -- Restore the original Ghost mode once analysis and expansion have
8941 end Build_Predicate_Functions;
8943 -----------------------------------------
8944 -- Check_Aspect_At_End_Of_Declarations --
8945 -----------------------------------------
8947 procedure Check_Aspect_At_End_Of_Declarations (ASN : Node_Id) is
8948 Ent : constant Entity_Id := Entity (ASN);
8949 Ident : constant Node_Id := Identifier (ASN);
8950 A_Id : constant Aspect_Id := Get_Aspect_Id (Chars (Ident));
8952 End_Decl_Expr : constant Node_Id := Entity (Ident);
8953 -- Expression to be analyzed at end of declarations
8955 Freeze_Expr : constant Node_Id := Expression (ASN);
8956 -- Expression from call to Check_Aspect_At_Freeze_Point
8958 T : constant Entity_Id := Etype (Freeze_Expr);
8959 -- Type required for preanalyze call
8962 -- Set False if error
8964 -- On entry to this procedure, Entity (Ident) contains a copy of the
8965 -- original expression from the aspect, saved for this purpose, and
8966 -- but Expression (Ident) is a preanalyzed copy of the expression,
8967 -- preanalyzed just after the freeze point.
8969 procedure Check_Overloaded_Name;
8970 -- For aspects whose expression is simply a name, this routine checks if
8971 -- the name is overloaded or not. If so, it verifies there is an
8972 -- interpretation that matches the entity obtained at the freeze point,
8973 -- otherwise the compiler complains.
8975 ---------------------------
8976 -- Check_Overloaded_Name --
8977 ---------------------------
8979 procedure Check_Overloaded_Name is
8981 if not Is_Overloaded (End_Decl_Expr) then
8982 Err := not Is_Entity_Name (End_Decl_Expr)
8983 or else Entity (End_Decl_Expr) /= Entity (Freeze_Expr);
8989 Index : Interp_Index;
8993 Get_First_Interp (End_Decl_Expr, Index, It);
8994 while Present (It.Typ) loop
8995 if It.Nam = Entity (Freeze_Expr) then
9000 Get_Next_Interp (Index, It);
9004 end Check_Overloaded_Name;
9006 -- Start of processing for Check_Aspect_At_End_Of_Declarations
9009 -- Case of aspects Dimension, Dimension_System and Synchronization
9011 if A_Id = Aspect_Synchronization then
9014 -- Case of stream attributes, just have to compare entities. However,
9015 -- the expression is just a name (possibly overloaded), and there may
9016 -- be stream operations declared for unrelated types, so we just need
9017 -- to verify that one of these interpretations is the one available at
9018 -- at the freeze point.
9020 elsif A_Id = Aspect_Input or else
9021 A_Id = Aspect_Output or else
9022 A_Id = Aspect_Read or else
9025 Analyze (End_Decl_Expr);
9026 Check_Overloaded_Name;
9028 elsif A_Id = Aspect_Variable_Indexing or else
9029 A_Id = Aspect_Constant_Indexing or else
9030 A_Id = Aspect_Default_Iterator or else
9031 A_Id = Aspect_Iterator_Element
9033 -- Make type unfrozen before analysis, to prevent spurious errors
9034 -- about late attributes.
9036 Set_Is_Frozen (Ent, False);
9037 Analyze (End_Decl_Expr);
9038 Set_Is_Frozen (Ent, True);
9040 -- If the end of declarations comes before any other freeze
9041 -- point, the Freeze_Expr is not analyzed: no check needed.
9043 if Analyzed (Freeze_Expr) and then not In_Instance then
9044 Check_Overloaded_Name;
9052 -- Indicate that the expression comes from an aspect specification,
9053 -- which is used in subsequent analysis even if expansion is off.
9055 Set_Parent (End_Decl_Expr, ASN);
9057 -- In a generic context the aspect expressions have not been
9058 -- preanalyzed, so do it now. There are no conformance checks
9059 -- to perform in this case.
9062 Check_Aspect_At_Freeze_Point (ASN);
9065 -- The default values attributes may be defined in the private part,
9066 -- and the analysis of the expression may take place when only the
9067 -- partial view is visible. The expression must be scalar, so use
9068 -- the full view to resolve.
9070 elsif (A_Id = Aspect_Default_Value
9072 A_Id = Aspect_Default_Component_Value)
9073 and then Is_Private_Type (T)
9075 Preanalyze_Spec_Expression (End_Decl_Expr, Full_View (T));
9078 Preanalyze_Spec_Expression (End_Decl_Expr, T);
9081 Err := not Fully_Conformant_Expressions (End_Decl_Expr, Freeze_Expr);
9084 -- Output error message if error. Force error on aspect specification
9085 -- even if there is an error on the expression itself.
9089 ("!visibility of aspect for& changes after freeze point",
9092 ("info: & is frozen here, aspects evaluated at this point??",
9093 Freeze_Node (Ent), Ent);
9095 end Check_Aspect_At_End_Of_Declarations;
9097 ----------------------------------
9098 -- Check_Aspect_At_Freeze_Point --
9099 ----------------------------------
9101 procedure Check_Aspect_At_Freeze_Point (ASN : Node_Id) is
9102 Ident : constant Node_Id := Identifier (ASN);
9103 -- Identifier (use Entity field to save expression)
9105 A_Id : constant Aspect_Id := Get_Aspect_Id (Chars (Ident));
9107 T : Entity_Id := Empty;
9108 -- Type required for preanalyze call
9111 -- On entry to this procedure, Entity (Ident) contains a copy of the
9112 -- original expression from the aspect, saved for this purpose.
9114 -- On exit from this procedure Entity (Ident) is unchanged, still
9115 -- containing that copy, but Expression (Ident) is a preanalyzed copy
9116 -- of the expression, preanalyzed just after the freeze point.
9118 -- Make a copy of the expression to be preanalyzed
9120 Set_Expression (ASN, New_Copy_Tree (Entity (Ident)));
9122 -- Find type for preanalyze call
9126 -- No_Aspect should be impossible
9129 raise Program_Error;
9131 -- Aspects taking an optional boolean argument
9133 when Boolean_Aspects |
9134 Library_Unit_Aspects =>
9136 T := Standard_Boolean;
9138 -- Aspects corresponding to attribute definition clauses
9140 when Aspect_Address =>
9141 T := RTE (RE_Address);
9143 when Aspect_Attach_Handler =>
9144 T := RTE (RE_Interrupt_ID);
9146 when Aspect_Bit_Order | Aspect_Scalar_Storage_Order =>
9147 T := RTE (RE_Bit_Order);
9149 when Aspect_Convention =>
9153 T := RTE (RE_CPU_Range);
9155 -- Default_Component_Value is resolved with the component type
9157 when Aspect_Default_Component_Value =>
9158 T := Component_Type (Entity (ASN));
9160 when Aspect_Default_Storage_Pool =>
9161 T := Class_Wide_Type (RTE (RE_Root_Storage_Pool));
9163 -- Default_Value is resolved with the type entity in question
9165 when Aspect_Default_Value =>
9168 when Aspect_Dispatching_Domain =>
9169 T := RTE (RE_Dispatching_Domain);
9171 when Aspect_External_Tag =>
9172 T := Standard_String;
9174 when Aspect_External_Name =>
9175 T := Standard_String;
9177 when Aspect_Link_Name =>
9178 T := Standard_String;
9180 when Aspect_Priority | Aspect_Interrupt_Priority =>
9181 T := Standard_Integer;
9183 when Aspect_Relative_Deadline =>
9184 T := RTE (RE_Time_Span);
9186 when Aspect_Small =>
9187 T := Universal_Real;
9189 -- For a simple storage pool, we have to retrieve the type of the
9190 -- pool object associated with the aspect's corresponding attribute
9191 -- definition clause.
9193 when Aspect_Simple_Storage_Pool =>
9194 T := Etype (Expression (Aspect_Rep_Item (ASN)));
9196 when Aspect_Storage_Pool =>
9197 T := Class_Wide_Type (RTE (RE_Root_Storage_Pool));
9199 when Aspect_Alignment |
9200 Aspect_Component_Size |
9201 Aspect_Machine_Radix |
9202 Aspect_Object_Size |
9204 Aspect_Storage_Size |
9205 Aspect_Stream_Size |
9206 Aspect_Value_Size =>
9209 when Aspect_Linker_Section =>
9210 T := Standard_String;
9212 when Aspect_Synchronization =>
9215 -- Special case, the expression of these aspects is just an entity
9216 -- that does not need any resolution, so just analyze.
9225 Analyze (Expression (ASN));
9228 -- Same for Iterator aspects, where the expression is a function
9229 -- name. Legality rules are checked separately.
9231 when Aspect_Constant_Indexing |
9232 Aspect_Default_Iterator |
9233 Aspect_Iterator_Element |
9234 Aspect_Variable_Indexing =>
9235 Analyze (Expression (ASN));
9238 -- Ditto for Iterable, legality checks in Validate_Iterable_Aspect.
9240 when Aspect_Iterable =>
9244 Cursor : constant Entity_Id := Get_Cursor_Type (ASN, T);
9249 if Cursor = Any_Type then
9253 Assoc := First (Component_Associations (Expression (ASN)));
9254 while Present (Assoc) loop
9255 Expr := Expression (Assoc);
9258 if not Error_Posted (Expr) then
9259 Resolve_Iterable_Operation
9260 (Expr, Cursor, T, Chars (First (Choices (Assoc))));
9269 -- Invariant/Predicate take boolean expressions
9271 when Aspect_Dynamic_Predicate |
9274 Aspect_Static_Predicate |
9275 Aspect_Type_Invariant =>
9276 T := Standard_Boolean;
9278 -- Here is the list of aspects that don't require delay analysis
9280 when Aspect_Abstract_State |
9282 Aspect_Contract_Cases |
9283 Aspect_Default_Initial_Condition |
9286 Aspect_Dimension_System |
9287 Aspect_Extensions_Visible |
9290 Aspect_Implicit_Dereference |
9291 Aspect_Initial_Condition |
9292 Aspect_Initializes |
9293 Aspect_Obsolescent |
9296 Aspect_Postcondition |
9298 Aspect_Precondition |
9299 Aspect_Refined_Depends |
9300 Aspect_Refined_Global |
9301 Aspect_Refined_Post |
9302 Aspect_Refined_State |
9305 Aspect_Unimplemented =>
9306 raise Program_Error;
9310 -- Do the preanalyze call
9312 Preanalyze_Spec_Expression (Expression (ASN), T);
9313 end Check_Aspect_At_Freeze_Point;
9315 -----------------------------------
9316 -- Check_Constant_Address_Clause --
9317 -----------------------------------
9319 procedure Check_Constant_Address_Clause
9323 procedure Check_At_Constant_Address (Nod : Node_Id);
9324 -- Checks that the given node N represents a name whose 'Address is
9325 -- constant (in the same sense as OK_Constant_Address_Clause, i.e. the
9326 -- address value is the same at the point of declaration of U_Ent and at
9327 -- the time of elaboration of the address clause.
9329 procedure Check_Expr_Constants (Nod : Node_Id);
9330 -- Checks that Nod meets the requirements for a constant address clause
9331 -- in the sense of the enclosing procedure.
9333 procedure Check_List_Constants (Lst : List_Id);
9334 -- Check that all elements of list Lst meet the requirements for a
9335 -- constant address clause in the sense of the enclosing procedure.
9337 -------------------------------
9338 -- Check_At_Constant_Address --
9339 -------------------------------
9341 procedure Check_At_Constant_Address (Nod : Node_Id) is
9343 if Is_Entity_Name (Nod) then
9344 if Present (Address_Clause (Entity ((Nod)))) then
9346 ("invalid address clause for initialized object &!",
9349 ("address for& cannot" &
9350 " depend on another address clause! (RM 13.1(22))!",
9353 elsif In_Same_Source_Unit (Entity (Nod), U_Ent)
9354 and then Sloc (U_Ent) < Sloc (Entity (Nod))
9357 ("invalid address clause for initialized object &!",
9359 Error_Msg_Node_2 := U_Ent;
9361 ("\& must be defined before & (RM 13.1(22))!",
9365 elsif Nkind (Nod) = N_Selected_Component then
9367 T : constant Entity_Id := Etype (Prefix (Nod));
9370 if (Is_Record_Type (T)
9371 and then Has_Discriminants (T))
9374 and then Is_Record_Type (Designated_Type (T))
9375 and then Has_Discriminants (Designated_Type (T)))
9378 ("invalid address clause for initialized object &!",
9381 ("\address cannot depend on component" &
9382 " of discriminated record (RM 13.1(22))!",
9385 Check_At_Constant_Address (Prefix (Nod));
9389 elsif Nkind (Nod) = N_Indexed_Component then
9390 Check_At_Constant_Address (Prefix (Nod));
9391 Check_List_Constants (Expressions (Nod));
9394 Check_Expr_Constants (Nod);
9396 end Check_At_Constant_Address;
9398 --------------------------
9399 -- Check_Expr_Constants --
9400 --------------------------
9402 procedure Check_Expr_Constants (Nod : Node_Id) is
9403 Loc_U_Ent : constant Source_Ptr := Sloc (U_Ent);
9404 Ent : Entity_Id := Empty;
9407 if Nkind (Nod) in N_Has_Etype
9408 and then Etype (Nod) = Any_Type
9414 when N_Empty | N_Error =>
9417 when N_Identifier | N_Expanded_Name =>
9418 Ent := Entity (Nod);
9420 -- We need to look at the original node if it is different
9421 -- from the node, since we may have rewritten things and
9422 -- substituted an identifier representing the rewrite.
9424 if Original_Node (Nod) /= Nod then
9425 Check_Expr_Constants (Original_Node (Nod));
9427 -- If the node is an object declaration without initial
9428 -- value, some code has been expanded, and the expression
9429 -- is not constant, even if the constituents might be
9430 -- acceptable, as in A'Address + offset.
9432 if Ekind (Ent) = E_Variable
9434 Nkind (Declaration_Node (Ent)) = N_Object_Declaration
9436 No (Expression (Declaration_Node (Ent)))
9439 ("invalid address clause for initialized object &!",
9442 -- If entity is constant, it may be the result of expanding
9443 -- a check. We must verify that its declaration appears
9444 -- before the object in question, else we also reject the
9447 elsif Ekind (Ent) = E_Constant
9448 and then In_Same_Source_Unit (Ent, U_Ent)
9449 and then Sloc (Ent) > Loc_U_Ent
9452 ("invalid address clause for initialized object &!",
9459 -- Otherwise look at the identifier and see if it is OK
9461 if Ekind_In (Ent, E_Named_Integer, E_Named_Real)
9462 or else Is_Type (Ent)
9466 elsif Ekind_In (Ent, E_Constant, E_In_Parameter) then
9468 -- This is the case where we must have Ent defined before
9469 -- U_Ent. Clearly if they are in different units this
9470 -- requirement is met since the unit containing Ent is
9471 -- already processed.
9473 if not In_Same_Source_Unit (Ent, U_Ent) then
9476 -- Otherwise location of Ent must be before the location
9477 -- of U_Ent, that's what prior defined means.
9479 elsif Sloc (Ent) < Loc_U_Ent then
9484 ("invalid address clause for initialized object &!",
9486 Error_Msg_Node_2 := U_Ent;
9488 ("\& must be defined before & (RM 13.1(22))!",
9492 elsif Nkind (Original_Node (Nod)) = N_Function_Call then
9493 Check_Expr_Constants (Original_Node (Nod));
9497 ("invalid address clause for initialized object &!",
9500 if Comes_From_Source (Ent) then
9502 ("\reference to variable& not allowed"
9503 & " (RM 13.1(22))!", Nod, Ent);
9506 ("non-static expression not allowed"
9507 & " (RM 13.1(22))!", Nod);
9511 when N_Integer_Literal =>
9513 -- If this is a rewritten unchecked conversion, in a system
9514 -- where Address is an integer type, always use the base type
9515 -- for a literal value. This is user-friendly and prevents
9516 -- order-of-elaboration issues with instances of unchecked
9519 if Nkind (Original_Node (Nod)) = N_Function_Call then
9520 Set_Etype (Nod, Base_Type (Etype (Nod)));
9523 when N_Real_Literal |
9525 N_Character_Literal =>
9529 Check_Expr_Constants (Low_Bound (Nod));
9530 Check_Expr_Constants (High_Bound (Nod));
9532 when N_Explicit_Dereference =>
9533 Check_Expr_Constants (Prefix (Nod));
9535 when N_Indexed_Component =>
9536 Check_Expr_Constants (Prefix (Nod));
9537 Check_List_Constants (Expressions (Nod));
9540 Check_Expr_Constants (Prefix (Nod));
9541 Check_Expr_Constants (Discrete_Range (Nod));
9543 when N_Selected_Component =>
9544 Check_Expr_Constants (Prefix (Nod));
9546 when N_Attribute_Reference =>
9547 if Nam_In (Attribute_Name (Nod), Name_Address,
9549 Name_Unchecked_Access,
9550 Name_Unrestricted_Access)
9552 Check_At_Constant_Address (Prefix (Nod));
9555 Check_Expr_Constants (Prefix (Nod));
9556 Check_List_Constants (Expressions (Nod));
9560 Check_List_Constants (Component_Associations (Nod));
9561 Check_List_Constants (Expressions (Nod));
9563 when N_Component_Association =>
9564 Check_Expr_Constants (Expression (Nod));
9566 when N_Extension_Aggregate =>
9567 Check_Expr_Constants (Ancestor_Part (Nod));
9568 Check_List_Constants (Component_Associations (Nod));
9569 Check_List_Constants (Expressions (Nod));
9574 when N_Binary_Op | N_Short_Circuit | N_Membership_Test =>
9575 Check_Expr_Constants (Left_Opnd (Nod));
9576 Check_Expr_Constants (Right_Opnd (Nod));
9579 Check_Expr_Constants (Right_Opnd (Nod));
9581 when N_Type_Conversion |
9582 N_Qualified_Expression |
9584 N_Unchecked_Type_Conversion =>
9585 Check_Expr_Constants (Expression (Nod));
9587 when N_Function_Call =>
9588 if not Is_Pure (Entity (Name (Nod))) then
9590 ("invalid address clause for initialized object &!",
9594 ("\function & is not pure (RM 13.1(22))!",
9595 Nod, Entity (Name (Nod)));
9598 Check_List_Constants (Parameter_Associations (Nod));
9601 when N_Parameter_Association =>
9602 Check_Expr_Constants (Explicit_Actual_Parameter (Nod));
9606 ("invalid address clause for initialized object &!",
9609 ("\must be constant defined before& (RM 13.1(22))!",
9612 end Check_Expr_Constants;
9614 --------------------------
9615 -- Check_List_Constants --
9616 --------------------------
9618 procedure Check_List_Constants (Lst : List_Id) is
9622 if Present (Lst) then
9623 Nod1 := First (Lst);
9624 while Present (Nod1) loop
9625 Check_Expr_Constants (Nod1);
9629 end Check_List_Constants;
9631 -- Start of processing for Check_Constant_Address_Clause
9634 -- If rep_clauses are to be ignored, no need for legality checks. In
9635 -- particular, no need to pester user about rep clauses that violate the
9636 -- rule on constant addresses, given that these clauses will be removed
9637 -- by Freeze before they reach the back end. Similarly in CodePeer mode,
9638 -- we want to relax these checks.
9640 if not Ignore_Rep_Clauses and not CodePeer_Mode then
9641 Check_Expr_Constants (Expr);
9643 end Check_Constant_Address_Clause;
9645 ---------------------------
9646 -- Check_Pool_Size_Clash --
9647 ---------------------------
9649 procedure Check_Pool_Size_Clash (Ent : Entity_Id; SP, SS : Node_Id) is
9653 -- We need to find out which one came first. Note that in the case of
9654 -- aspects mixed with pragmas there are cases where the processing order
9655 -- is reversed, which is why we do the check here.
9657 if Sloc (SP) < Sloc (SS) then
9658 Error_Msg_Sloc := Sloc (SP);
9660 Error_Msg_NE ("Storage_Pool previously given for&#", Post, Ent);
9663 Error_Msg_Sloc := Sloc (SS);
9665 Error_Msg_NE ("Storage_Size previously given for&#", Post, Ent);
9669 ("\cannot have Storage_Size and Storage_Pool (RM 13.11(3))", Post);
9670 end Check_Pool_Size_Clash;
9672 ----------------------------------------
9673 -- Check_Record_Representation_Clause --
9674 ----------------------------------------
9676 procedure Check_Record_Representation_Clause (N : Node_Id) is
9677 Loc : constant Source_Ptr := Sloc (N);
9678 Ident : constant Node_Id := Identifier (N);
9679 Rectype : Entity_Id;
9684 Hbit : Uint := Uint_0;
9688 Max_Bit_So_Far : Uint;
9689 -- Records the maximum bit position so far. If all field positions
9690 -- are monotonically increasing, then we can skip the circuit for
9691 -- checking for overlap, since no overlap is possible.
9693 Tagged_Parent : Entity_Id := Empty;
9694 -- This is set in the case of a derived tagged type for which we have
9695 -- Is_Fully_Repped_Tagged_Type True (indicating that all components are
9696 -- positioned by record representation clauses). In this case we must
9697 -- check for overlap between components of this tagged type, and the
9698 -- components of its parent. Tagged_Parent will point to this parent
9699 -- type. For all other cases Tagged_Parent is left set to Empty.
9701 Parent_Last_Bit : Uint;
9702 -- Relevant only if Tagged_Parent is set, Parent_Last_Bit indicates the
9703 -- last bit position for any field in the parent type. We only need to
9704 -- check overlap for fields starting below this point.
9706 Overlap_Check_Required : Boolean;
9707 -- Used to keep track of whether or not an overlap check is required
9709 Overlap_Detected : Boolean := False;
9710 -- Set True if an overlap is detected
9712 Ccount : Natural := 0;
9713 -- Number of component clauses in record rep clause
9715 procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id);
9716 -- Given two entities for record components or discriminants, checks
9717 -- if they have overlapping component clauses and issues errors if so.
9719 procedure Find_Component;
9720 -- Finds component entity corresponding to current component clause (in
9721 -- CC), and sets Comp to the entity, and Fbit/Lbit to the zero origin
9722 -- start/stop bits for the field. If there is no matching component or
9723 -- if the matching component does not have a component clause, then
9724 -- that's an error and Comp is set to Empty, but no error message is
9725 -- issued, since the message was already given. Comp is also set to
9726 -- Empty if the current "component clause" is in fact a pragma.
9728 -----------------------------
9729 -- Check_Component_Overlap --
9730 -----------------------------
9732 procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id) is
9733 CC1 : constant Node_Id := Component_Clause (C1_Ent);
9734 CC2 : constant Node_Id := Component_Clause (C2_Ent);
9737 if Present (CC1) and then Present (CC2) then
9739 -- Exclude odd case where we have two tag components in the same
9740 -- record, both at location zero. This seems a bit strange, but
9741 -- it seems to happen in some circumstances, perhaps on an error.
9743 if Nam_In (Chars (C1_Ent), Name_uTag, Name_uTag) then
9747 -- Here we check if the two fields overlap
9750 S1 : constant Uint := Component_Bit_Offset (C1_Ent);
9751 S2 : constant Uint := Component_Bit_Offset (C2_Ent);
9752 E1 : constant Uint := S1 + Esize (C1_Ent);
9753 E2 : constant Uint := S2 + Esize (C2_Ent);
9756 if E2 <= S1 or else E1 <= S2 then
9759 Error_Msg_Node_2 := Component_Name (CC2);
9760 Error_Msg_Sloc := Sloc (Error_Msg_Node_2);
9761 Error_Msg_Node_1 := Component_Name (CC1);
9763 ("component& overlaps & #", Component_Name (CC1));
9764 Overlap_Detected := True;
9768 end Check_Component_Overlap;
9770 --------------------
9771 -- Find_Component --
9772 --------------------
9774 procedure Find_Component is
9776 procedure Search_Component (R : Entity_Id);
9777 -- Search components of R for a match. If found, Comp is set
9779 ----------------------
9780 -- Search_Component --
9781 ----------------------
9783 procedure Search_Component (R : Entity_Id) is
9785 Comp := First_Component_Or_Discriminant (R);
9786 while Present (Comp) loop
9788 -- Ignore error of attribute name for component name (we
9789 -- already gave an error message for this, so no need to
9792 if Nkind (Component_Name (CC)) = N_Attribute_Reference then
9795 exit when Chars (Comp) = Chars (Component_Name (CC));
9798 Next_Component_Or_Discriminant (Comp);
9800 end Search_Component;
9802 -- Start of processing for Find_Component
9805 -- Return with Comp set to Empty if we have a pragma
9807 if Nkind (CC) = N_Pragma then
9812 -- Search current record for matching component
9814 Search_Component (Rectype);
9816 -- If not found, maybe component of base type discriminant that is
9817 -- absent from statically constrained first subtype.
9820 Search_Component (Base_Type (Rectype));
9823 -- If no component, or the component does not reference the component
9824 -- clause in question, then there was some previous error for which
9825 -- we already gave a message, so just return with Comp Empty.
9827 if No (Comp) or else Component_Clause (Comp) /= CC then
9828 Check_Error_Detected;
9831 -- Normal case where we have a component clause
9834 Fbit := Component_Bit_Offset (Comp);
9835 Lbit := Fbit + Esize (Comp) - 1;
9839 -- Start of processing for Check_Record_Representation_Clause
9843 Rectype := Entity (Ident);
9845 if Rectype = Any_Type then
9848 Rectype := Underlying_Type (Rectype);
9851 -- See if we have a fully repped derived tagged type
9854 PS : constant Entity_Id := Parent_Subtype (Rectype);
9857 if Present (PS) and then Is_Fully_Repped_Tagged_Type (PS) then
9858 Tagged_Parent := PS;
9860 -- Find maximum bit of any component of the parent type
9862 Parent_Last_Bit := UI_From_Int (System_Address_Size - 1);
9863 Pcomp := First_Entity (Tagged_Parent);
9864 while Present (Pcomp) loop
9865 if Ekind_In (Pcomp, E_Discriminant, E_Component) then
9866 if Component_Bit_Offset (Pcomp) /= No_Uint
9867 and then Known_Static_Esize (Pcomp)
9872 Component_Bit_Offset (Pcomp) + Esize (Pcomp) - 1);
9875 Next_Entity (Pcomp);
9881 -- All done if no component clauses
9883 CC := First (Component_Clauses (N));
9889 -- If a tag is present, then create a component clause that places it
9890 -- at the start of the record (otherwise gigi may place it after other
9891 -- fields that have rep clauses).
9893 Fent := First_Entity (Rectype);
9895 if Nkind (Fent) = N_Defining_Identifier
9896 and then Chars (Fent) = Name_uTag
9898 Set_Component_Bit_Offset (Fent, Uint_0);
9899 Set_Normalized_Position (Fent, Uint_0);
9900 Set_Normalized_First_Bit (Fent, Uint_0);
9901 Set_Normalized_Position_Max (Fent, Uint_0);
9902 Init_Esize (Fent, System_Address_Size);
9904 Set_Component_Clause (Fent,
9905 Make_Component_Clause (Loc,
9906 Component_Name => Make_Identifier (Loc, Name_uTag),
9908 Position => Make_Integer_Literal (Loc, Uint_0),
9909 First_Bit => Make_Integer_Literal (Loc, Uint_0),
9911 Make_Integer_Literal (Loc,
9912 UI_From_Int (System_Address_Size))));
9914 Ccount := Ccount + 1;
9917 Max_Bit_So_Far := Uint_Minus_1;
9918 Overlap_Check_Required := False;
9920 -- Process the component clauses
9922 while Present (CC) loop
9925 if Present (Comp) then
9926 Ccount := Ccount + 1;
9928 -- We need a full overlap check if record positions non-monotonic
9930 if Fbit <= Max_Bit_So_Far then
9931 Overlap_Check_Required := True;
9934 Max_Bit_So_Far := Lbit;
9936 -- Check bit position out of range of specified size
9938 if Has_Size_Clause (Rectype)
9939 and then RM_Size (Rectype) <= Lbit
9942 ("bit number out of range of specified size",
9945 -- Check for overlap with tag component
9948 if Is_Tagged_Type (Rectype)
9949 and then Fbit < System_Address_Size
9952 ("component overlaps tag field of&",
9953 Component_Name (CC), Rectype);
9954 Overlap_Detected := True;
9962 -- Check parent overlap if component might overlap parent field
9964 if Present (Tagged_Parent) and then Fbit <= Parent_Last_Bit then
9965 Pcomp := First_Component_Or_Discriminant (Tagged_Parent);
9966 while Present (Pcomp) loop
9967 if not Is_Tag (Pcomp)
9968 and then Chars (Pcomp) /= Name_uParent
9970 Check_Component_Overlap (Comp, Pcomp);
9973 Next_Component_Or_Discriminant (Pcomp);
9981 -- Now that we have processed all the component clauses, check for
9982 -- overlap. We have to leave this till last, since the components can
9983 -- appear in any arbitrary order in the representation clause.
9985 -- We do not need this check if all specified ranges were monotonic,
9986 -- as recorded by Overlap_Check_Required being False at this stage.
9988 -- This first section checks if there are any overlapping entries at
9989 -- all. It does this by sorting all entries and then seeing if there are
9990 -- any overlaps. If there are none, then that is decisive, but if there
9991 -- are overlaps, they may still be OK (they may result from fields in
9992 -- different variants).
9994 if Overlap_Check_Required then
9995 Overlap_Check1 : declare
9997 OC_Fbit : array (0 .. Ccount) of Uint;
9998 -- First-bit values for component clauses, the value is the offset
9999 -- of the first bit of the field from start of record. The zero
10000 -- entry is for use in sorting.
10002 OC_Lbit : array (0 .. Ccount) of Uint;
10003 -- Last-bit values for component clauses, the value is the offset
10004 -- of the last bit of the field from start of record. The zero
10005 -- entry is for use in sorting.
10007 OC_Count : Natural := 0;
10008 -- Count of entries in OC_Fbit and OC_Lbit
10010 function OC_Lt (Op1, Op2 : Natural) return Boolean;
10011 -- Compare routine for Sort
10013 procedure OC_Move (From : Natural; To : Natural);
10014 -- Move routine for Sort
10016 package Sorting is new GNAT.Heap_Sort_G (OC_Move, OC_Lt);
10022 function OC_Lt (Op1, Op2 : Natural) return Boolean is
10024 return OC_Fbit (Op1) < OC_Fbit (Op2);
10031 procedure OC_Move (From : Natural; To : Natural) is
10033 OC_Fbit (To) := OC_Fbit (From);
10034 OC_Lbit (To) := OC_Lbit (From);
10037 -- Start of processing for Overlap_Check
10040 CC := First (Component_Clauses (N));
10041 while Present (CC) loop
10043 -- Exclude component clause already marked in error
10045 if not Error_Posted (CC) then
10048 if Present (Comp) then
10049 OC_Count := OC_Count + 1;
10050 OC_Fbit (OC_Count) := Fbit;
10051 OC_Lbit (OC_Count) := Lbit;
10058 Sorting.Sort (OC_Count);
10060 Overlap_Check_Required := False;
10061 for J in 1 .. OC_Count - 1 loop
10062 if OC_Lbit (J) >= OC_Fbit (J + 1) then
10063 Overlap_Check_Required := True;
10067 end Overlap_Check1;
10070 -- If Overlap_Check_Required is still True, then we have to do the full
10071 -- scale overlap check, since we have at least two fields that do
10072 -- overlap, and we need to know if that is OK since they are in
10073 -- different variant, or whether we have a definite problem.
10075 if Overlap_Check_Required then
10076 Overlap_Check2 : declare
10077 C1_Ent, C2_Ent : Entity_Id;
10078 -- Entities of components being checked for overlap
10081 -- Component_List node whose Component_Items are being checked
10084 -- Component declaration for component being checked
10087 C1_Ent := First_Entity (Base_Type (Rectype));
10089 -- Loop through all components in record. For each component check
10090 -- for overlap with any of the preceding elements on the component
10091 -- list containing the component and also, if the component is in
10092 -- a variant, check against components outside the case structure.
10093 -- This latter test is repeated recursively up the variant tree.
10095 Main_Component_Loop : while Present (C1_Ent) loop
10096 if not Ekind_In (C1_Ent, E_Component, E_Discriminant) then
10097 goto Continue_Main_Component_Loop;
10100 -- Skip overlap check if entity has no declaration node. This
10101 -- happens with discriminants in constrained derived types.
10102 -- Possibly we are missing some checks as a result, but that
10103 -- does not seem terribly serious.
10105 if No (Declaration_Node (C1_Ent)) then
10106 goto Continue_Main_Component_Loop;
10109 Clist := Parent (List_Containing (Declaration_Node (C1_Ent)));
10111 -- Loop through component lists that need checking. Check the
10112 -- current component list and all lists in variants above us.
10114 Component_List_Loop : loop
10116 -- If derived type definition, go to full declaration
10117 -- If at outer level, check discriminants if there are any.
10119 if Nkind (Clist) = N_Derived_Type_Definition then
10120 Clist := Parent (Clist);
10123 -- Outer level of record definition, check discriminants
10125 if Nkind_In (Clist, N_Full_Type_Declaration,
10126 N_Private_Type_Declaration)
10128 if Has_Discriminants (Defining_Identifier (Clist)) then
10130 First_Discriminant (Defining_Identifier (Clist));
10131 while Present (C2_Ent) loop
10132 exit when C1_Ent = C2_Ent;
10133 Check_Component_Overlap (C1_Ent, C2_Ent);
10134 Next_Discriminant (C2_Ent);
10138 -- Record extension case
10140 elsif Nkind (Clist) = N_Derived_Type_Definition then
10143 -- Otherwise check one component list
10146 Citem := First (Component_Items (Clist));
10147 while Present (Citem) loop
10148 if Nkind (Citem) = N_Component_Declaration then
10149 C2_Ent := Defining_Identifier (Citem);
10150 exit when C1_Ent = C2_Ent;
10151 Check_Component_Overlap (C1_Ent, C2_Ent);
10158 -- Check for variants above us (the parent of the Clist can
10159 -- be a variant, in which case its parent is a variant part,
10160 -- and the parent of the variant part is a component list
10161 -- whose components must all be checked against the current
10162 -- component for overlap).
10164 if Nkind (Parent (Clist)) = N_Variant then
10165 Clist := Parent (Parent (Parent (Clist)));
10167 -- Check for possible discriminant part in record, this
10168 -- is treated essentially as another level in the
10169 -- recursion. For this case the parent of the component
10170 -- list is the record definition, and its parent is the
10171 -- full type declaration containing the discriminant
10174 elsif Nkind (Parent (Clist)) = N_Record_Definition then
10175 Clist := Parent (Parent ((Clist)));
10177 -- If neither of these two cases, we are at the top of
10181 exit Component_List_Loop;
10183 end loop Component_List_Loop;
10185 <<Continue_Main_Component_Loop>>
10186 Next_Entity (C1_Ent);
10188 end loop Main_Component_Loop;
10189 end Overlap_Check2;
10192 -- The following circuit deals with warning on record holes (gaps). We
10193 -- skip this check if overlap was detected, since it makes sense for the
10194 -- programmer to fix this illegality before worrying about warnings.
10196 if not Overlap_Detected and Warn_On_Record_Holes then
10197 Record_Hole_Check : declare
10198 Decl : constant Node_Id := Declaration_Node (Base_Type (Rectype));
10199 -- Full declaration of record type
10201 procedure Check_Component_List
10205 -- Check component list CL for holes. The starting bit should be
10206 -- Sbit. which is zero for the main record component list and set
10207 -- appropriately for recursive calls for variants. DS is set to
10208 -- a list of discriminant specifications to be included in the
10209 -- consideration of components. It is No_List if none to consider.
10211 --------------------------
10212 -- Check_Component_List --
10213 --------------------------
10215 procedure Check_Component_List
10223 Compl := Integer (List_Length (Component_Items (CL)));
10225 if DS /= No_List then
10226 Compl := Compl + Integer (List_Length (DS));
10230 Comps : array (Natural range 0 .. Compl) of Entity_Id;
10231 -- Gather components (zero entry is for sort routine)
10233 Ncomps : Natural := 0;
10234 -- Number of entries stored in Comps (starting at Comps (1))
10237 -- One component item or discriminant specification
10240 -- Starting bit for next component
10243 -- Component entity
10248 function Lt (Op1, Op2 : Natural) return Boolean;
10249 -- Compare routine for Sort
10251 procedure Move (From : Natural; To : Natural);
10252 -- Move routine for Sort
10254 package Sorting is new GNAT.Heap_Sort_G (Move, Lt);
10260 function Lt (Op1, Op2 : Natural) return Boolean is
10262 return Component_Bit_Offset (Comps (Op1))
10264 Component_Bit_Offset (Comps (Op2));
10271 procedure Move (From : Natural; To : Natural) is
10273 Comps (To) := Comps (From);
10277 -- Gather discriminants into Comp
10279 if DS /= No_List then
10280 Citem := First (DS);
10281 while Present (Citem) loop
10282 if Nkind (Citem) = N_Discriminant_Specification then
10284 Ent : constant Entity_Id :=
10285 Defining_Identifier (Citem);
10287 if Ekind (Ent) = E_Discriminant then
10288 Ncomps := Ncomps + 1;
10289 Comps (Ncomps) := Ent;
10298 -- Gather component entities into Comp
10300 Citem := First (Component_Items (CL));
10301 while Present (Citem) loop
10302 if Nkind (Citem) = N_Component_Declaration then
10303 Ncomps := Ncomps + 1;
10304 Comps (Ncomps) := Defining_Identifier (Citem);
10310 -- Now sort the component entities based on the first bit.
10311 -- Note we already know there are no overlapping components.
10313 Sorting.Sort (Ncomps);
10315 -- Loop through entries checking for holes
10318 for J in 1 .. Ncomps loop
10320 Error_Msg_Uint_1 := Component_Bit_Offset (CEnt) - Nbit;
10322 if Error_Msg_Uint_1 > 0 then
10324 ("?H?^-bit gap before component&",
10325 Component_Name (Component_Clause (CEnt)), CEnt);
10328 Nbit := Component_Bit_Offset (CEnt) + Esize (CEnt);
10331 -- Process variant parts recursively if present
10333 if Present (Variant_Part (CL)) then
10334 Variant := First (Variants (Variant_Part (CL)));
10335 while Present (Variant) loop
10336 Check_Component_List
10337 (Component_List (Variant), Nbit, No_List);
10342 end Check_Component_List;
10344 -- Start of processing for Record_Hole_Check
10351 if Is_Tagged_Type (Rectype) then
10352 Sbit := UI_From_Int (System_Address_Size);
10357 if Nkind (Decl) = N_Full_Type_Declaration
10358 and then Nkind (Type_Definition (Decl)) = N_Record_Definition
10360 Check_Component_List
10361 (Component_List (Type_Definition (Decl)),
10363 Discriminant_Specifications (Decl));
10366 end Record_Hole_Check;
10369 -- For records that have component clauses for all components, and whose
10370 -- size is less than or equal to 32, we need to know the size in the
10371 -- front end to activate possible packed array processing where the
10372 -- component type is a record.
10374 -- At this stage Hbit + 1 represents the first unused bit from all the
10375 -- component clauses processed, so if the component clauses are
10376 -- complete, then this is the length of the record.
10378 -- For records longer than System.Storage_Unit, and for those where not
10379 -- all components have component clauses, the back end determines the
10380 -- length (it may for example be appropriate to round up the size
10381 -- to some convenient boundary, based on alignment considerations, etc).
10383 if Unknown_RM_Size (Rectype) and then Hbit + 1 <= 32 then
10385 -- Nothing to do if at least one component has no component clause
10387 Comp := First_Component_Or_Discriminant (Rectype);
10388 while Present (Comp) loop
10389 exit when No (Component_Clause (Comp));
10390 Next_Component_Or_Discriminant (Comp);
10393 -- If we fall out of loop, all components have component clauses
10394 -- and so we can set the size to the maximum value.
10397 Set_RM_Size (Rectype, Hbit + 1);
10400 end Check_Record_Representation_Clause;
10406 procedure Check_Size
10410 Biased : out Boolean)
10412 UT : constant Entity_Id := Underlying_Type (T);
10418 -- Reject patently improper size values.
10420 if Is_Elementary_Type (T)
10421 and then Siz > UI_From_Int (Int'Last)
10423 Error_Msg_N ("Size value too large for elementary type", N);
10425 if Nkind (Original_Node (N)) = N_Op_Expon then
10427 ("\maybe '* was meant, rather than '*'*", Original_Node (N));
10431 -- Dismiss generic types
10433 if Is_Generic_Type (T)
10435 Is_Generic_Type (UT)
10437 Is_Generic_Type (Root_Type (UT))
10441 -- Guard against previous errors
10443 elsif No (UT) or else UT = Any_Type then
10444 Check_Error_Detected;
10447 -- Check case of bit packed array
10449 elsif Is_Array_Type (UT)
10450 and then Known_Static_Component_Size (UT)
10451 and then Is_Bit_Packed_Array (UT)
10459 Asiz := Component_Size (UT);
10460 Indx := First_Index (UT);
10462 Ityp := Etype (Indx);
10464 -- If non-static bound, then we are not in the business of
10465 -- trying to check the length, and indeed an error will be
10466 -- issued elsewhere, since sizes of non-static array types
10467 -- cannot be set implicitly or explicitly.
10469 if not Is_OK_Static_Subtype (Ityp) then
10473 -- Otherwise accumulate next dimension
10475 Asiz := Asiz * (Expr_Value (Type_High_Bound (Ityp)) -
10476 Expr_Value (Type_Low_Bound (Ityp)) +
10480 exit when No (Indx);
10483 if Asiz <= Siz then
10487 Error_Msg_Uint_1 := Asiz;
10489 ("size for& too small, minimum allowed is ^", N, T);
10490 Set_Esize (T, Asiz);
10491 Set_RM_Size (T, Asiz);
10495 -- All other composite types are ignored
10497 elsif Is_Composite_Type (UT) then
10500 -- For fixed-point types, don't check minimum if type is not frozen,
10501 -- since we don't know all the characteristics of the type that can
10502 -- affect the size (e.g. a specified small) till freeze time.
10504 elsif Is_Fixed_Point_Type (UT)
10505 and then not Is_Frozen (UT)
10509 -- Cases for which a minimum check is required
10512 -- Ignore if specified size is correct for the type
10514 if Known_Esize (UT) and then Siz = Esize (UT) then
10518 -- Otherwise get minimum size
10520 M := UI_From_Int (Minimum_Size (UT));
10524 -- Size is less than minimum size, but one possibility remains
10525 -- that we can manage with the new size if we bias the type.
10527 M := UI_From_Int (Minimum_Size (UT, Biased => True));
10530 Error_Msg_Uint_1 := M;
10532 ("size for& too small, minimum allowed is ^", N, T);
10534 Set_RM_Size (T, M);
10542 --------------------------
10543 -- Freeze_Entity_Checks --
10544 --------------------------
10546 procedure Freeze_Entity_Checks (N : Node_Id) is
10547 procedure Hide_Non_Overridden_Subprograms (Typ : Entity_Id);
10548 -- Inspect the primitive operations of type Typ and hide all pairs of
10549 -- implicitly declared non-overridden non-fully conformant homographs
10550 -- (Ada RM 8.3 12.3/2).
10552 -------------------------------------
10553 -- Hide_Non_Overridden_Subprograms --
10554 -------------------------------------
10556 procedure Hide_Non_Overridden_Subprograms (Typ : Entity_Id) is
10557 procedure Hide_Matching_Homographs
10558 (Subp_Id : Entity_Id;
10559 Start_Elmt : Elmt_Id);
10560 -- Inspect a list of primitive operations starting with Start_Elmt
10561 -- and find matching implicitly declared non-overridden non-fully
10562 -- conformant homographs of Subp_Id. If found, all matches along
10563 -- with Subp_Id are hidden from all visibility.
10565 function Is_Non_Overridden_Or_Null_Procedure
10566 (Subp_Id : Entity_Id) return Boolean;
10567 -- Determine whether subprogram Subp_Id is implicitly declared non-
10568 -- overridden subprogram or an implicitly declared null procedure.
10570 ------------------------------
10571 -- Hide_Matching_Homographs --
10572 ------------------------------
10574 procedure Hide_Matching_Homographs
10575 (Subp_Id : Entity_Id;
10576 Start_Elmt : Elmt_Id)
10579 Prim_Elmt : Elmt_Id;
10582 Prim_Elmt := Start_Elmt;
10583 while Present (Prim_Elmt) loop
10584 Prim := Node (Prim_Elmt);
10586 -- The current primitive is implicitly declared non-overridden
10587 -- non-fully conformant homograph of Subp_Id. Both subprograms
10588 -- must be hidden from visibility.
10590 if Chars (Prim) = Chars (Subp_Id)
10591 and then Is_Non_Overridden_Or_Null_Procedure (Prim)
10592 and then not Fully_Conformant (Prim, Subp_Id)
10594 Set_Is_Hidden_Non_Overridden_Subpgm (Prim);
10595 Set_Is_Immediately_Visible (Prim, False);
10596 Set_Is_Potentially_Use_Visible (Prim, False);
10598 Set_Is_Hidden_Non_Overridden_Subpgm (Subp_Id);
10599 Set_Is_Immediately_Visible (Subp_Id, False);
10600 Set_Is_Potentially_Use_Visible (Subp_Id, False);
10603 Next_Elmt (Prim_Elmt);
10605 end Hide_Matching_Homographs;
10607 -----------------------------------------
10608 -- Is_Non_Overridden_Or_Null_Procedure --
10609 -----------------------------------------
10611 function Is_Non_Overridden_Or_Null_Procedure
10612 (Subp_Id : Entity_Id) return Boolean
10614 Alias_Id : Entity_Id;
10617 -- The subprogram is inherited (implicitly declared), it does not
10618 -- override and does not cover a primitive of an interface.
10620 if Ekind_In (Subp_Id, E_Function, E_Procedure)
10621 and then Present (Alias (Subp_Id))
10622 and then No (Interface_Alias (Subp_Id))
10623 and then No (Overridden_Operation (Subp_Id))
10625 Alias_Id := Alias (Subp_Id);
10627 if Requires_Overriding (Alias_Id) then
10630 elsif Nkind (Parent (Alias_Id)) = N_Procedure_Specification
10631 and then Null_Present (Parent (Alias_Id))
10638 end Is_Non_Overridden_Or_Null_Procedure;
10642 Prim_Ops : constant Elist_Id := Direct_Primitive_Operations (Typ);
10644 Prim_Elmt : Elmt_Id;
10646 -- Start of processing for Hide_Non_Overridden_Subprograms
10649 -- Inspect the list of primitives looking for non-overridden
10652 if Present (Prim_Ops) then
10653 Prim_Elmt := First_Elmt (Prim_Ops);
10654 while Present (Prim_Elmt) loop
10655 Prim := Node (Prim_Elmt);
10656 Next_Elmt (Prim_Elmt);
10658 if Is_Non_Overridden_Or_Null_Procedure (Prim) then
10659 Hide_Matching_Homographs
10661 Start_Elmt => Prim_Elmt);
10665 end Hide_Non_Overridden_Subprograms;
10667 ---------------------
10668 -- Local variables --
10669 ---------------------
10671 E : constant Entity_Id := Entity (N);
10673 Non_Generic_Case : constant Boolean := Nkind (N) = N_Freeze_Entity;
10674 -- True in non-generic case. Some of the processing here is skipped
10675 -- for the generic case since it is not needed. Basically in the
10676 -- generic case, we only need to do stuff that might generate error
10677 -- messages or warnings.
10679 -- Start of processing for Freeze_Entity_Checks
10682 -- Remember that we are processing a freezing entity. Required to
10683 -- ensure correct decoration of internal entities associated with
10684 -- interfaces (see New_Overloaded_Entity).
10686 Inside_Freezing_Actions := Inside_Freezing_Actions + 1;
10688 -- For tagged types covering interfaces add internal entities that link
10689 -- the primitives of the interfaces with the primitives that cover them.
10690 -- Note: These entities were originally generated only when generating
10691 -- code because their main purpose was to provide support to initialize
10692 -- the secondary dispatch tables. They are now generated also when
10693 -- compiling with no code generation to provide ASIS the relationship
10694 -- between interface primitives and tagged type primitives. They are
10695 -- also used to locate primitives covering interfaces when processing
10696 -- generics (see Derive_Subprograms).
10698 -- This is not needed in the generic case
10700 if Ada_Version >= Ada_2005
10701 and then Non_Generic_Case
10702 and then Ekind (E) = E_Record_Type
10703 and then Is_Tagged_Type (E)
10704 and then not Is_Interface (E)
10705 and then Has_Interfaces (E)
10707 -- This would be a good common place to call the routine that checks
10708 -- overriding of interface primitives (and thus factorize calls to
10709 -- Check_Abstract_Overriding located at different contexts in the
10710 -- compiler). However, this is not possible because it causes
10711 -- spurious errors in case of late overriding.
10713 Add_Internal_Interface_Entities (E);
10716 -- After all forms of overriding have been resolved, a tagged type may
10717 -- be left with a set of implicitly declared and possibly erroneous
10718 -- abstract subprograms, null procedures and subprograms that require
10719 -- overriding. If this set contains fully conformat homographs, then one
10720 -- is chosen arbitrarily (already done during resolution), otherwise all
10721 -- remaining non-fully conformant homographs are hidden from visibility
10722 -- (Ada RM 8.3 12.3/2).
10724 if Is_Tagged_Type (E) then
10725 Hide_Non_Overridden_Subprograms (E);
10730 if Ekind (E) = E_Record_Type
10731 and then Is_CPP_Class (E)
10732 and then Is_Tagged_Type (E)
10733 and then Tagged_Type_Expansion
10735 if CPP_Num_Prims (E) = 0 then
10737 -- If the CPP type has user defined components then it must import
10738 -- primitives from C++. This is required because if the C++ class
10739 -- has no primitives then the C++ compiler does not added the _tag
10740 -- component to the type.
10742 if First_Entity (E) /= Last_Entity (E) then
10744 ("'C'P'P type must import at least one primitive from C++??",
10749 -- Check that all its primitives are abstract or imported from C++.
10750 -- Check also availability of the C++ constructor.
10753 Has_Constructors : constant Boolean := Has_CPP_Constructors (E);
10755 Error_Reported : Boolean := False;
10759 Elmt := First_Elmt (Primitive_Operations (E));
10760 while Present (Elmt) loop
10761 Prim := Node (Elmt);
10763 if Comes_From_Source (Prim) then
10764 if Is_Abstract_Subprogram (Prim) then
10767 elsif not Is_Imported (Prim)
10768 or else Convention (Prim) /= Convention_CPP
10771 ("primitives of 'C'P'P types must be imported from C++ "
10772 & "or abstract??", Prim);
10774 elsif not Has_Constructors
10775 and then not Error_Reported
10777 Error_Msg_Name_1 := Chars (E);
10779 ("??'C'P'P constructor required for type %", Prim);
10780 Error_Reported := True;
10789 -- Check Ada derivation of CPP type
10791 if Expander_Active -- why? losing errors in -gnatc mode???
10792 and then Present (Etype (E)) -- defend against errors
10793 and then Tagged_Type_Expansion
10794 and then Ekind (E) = E_Record_Type
10795 and then Etype (E) /= E
10796 and then Is_CPP_Class (Etype (E))
10797 and then CPP_Num_Prims (Etype (E)) > 0
10798 and then not Is_CPP_Class (E)
10799 and then not Has_CPP_Constructors (Etype (E))
10801 -- If the parent has C++ primitives but it has no constructor then
10802 -- check that all the primitives are overridden in this derivation;
10803 -- otherwise the constructor of the parent is needed to build the
10811 Elmt := First_Elmt (Primitive_Operations (E));
10812 while Present (Elmt) loop
10813 Prim := Node (Elmt);
10815 if not Is_Abstract_Subprogram (Prim)
10816 and then No (Interface_Alias (Prim))
10817 and then Find_Dispatching_Type (Ultimate_Alias (Prim)) /= E
10819 Error_Msg_Name_1 := Chars (Etype (E));
10821 ("'C'P'P constructor required for parent type %", E);
10830 Inside_Freezing_Actions := Inside_Freezing_Actions - 1;
10832 -- If we have a type with predicates, build predicate function. This
10833 -- is not needed in the generic case, and is not needed within TSS
10834 -- subprograms and other predefined primitives.
10836 if Non_Generic_Case
10837 and then Is_Type (E)
10838 and then Has_Predicates (E)
10839 and then not Within_Internal_Subprogram
10841 Build_Predicate_Functions (E, N);
10844 -- If type has delayed aspects, this is where we do the preanalysis at
10845 -- the freeze point, as part of the consistent visibility check. Note
10846 -- that this must be done after calling Build_Predicate_Functions or
10847 -- Build_Invariant_Procedure since these subprograms fix occurrences of
10848 -- the subtype name in the saved expression so that they will not cause
10849 -- trouble in the preanalysis.
10851 -- This is also not needed in the generic case
10853 if Non_Generic_Case
10854 and then Has_Delayed_Aspects (E)
10855 and then Scope (E) = Current_Scope
10857 -- Retrieve the visibility to the discriminants in order to properly
10858 -- analyze the aspects.
10860 Push_Scope_And_Install_Discriminants (E);
10866 -- Look for aspect specification entries for this entity
10868 Ritem := First_Rep_Item (E);
10869 while Present (Ritem) loop
10870 if Nkind (Ritem) = N_Aspect_Specification
10871 and then Entity (Ritem) = E
10872 and then Is_Delayed_Aspect (Ritem)
10874 Check_Aspect_At_Freeze_Point (Ritem);
10877 Next_Rep_Item (Ritem);
10881 Uninstall_Discriminants_And_Pop_Scope (E);
10884 -- For a record type, deal with variant parts. This has to be delayed
10885 -- to this point, because of the issue of statically predicated
10886 -- subtypes, which we have to ensure are frozen before checking
10887 -- choices, since we need to have the static choice list set.
10889 if Is_Record_Type (E) then
10890 Check_Variant_Part : declare
10891 D : constant Node_Id := Declaration_Node (E);
10896 Others_Present : Boolean;
10897 pragma Warnings (Off, Others_Present);
10898 -- Indicates others present, not used in this case
10900 procedure Non_Static_Choice_Error (Choice : Node_Id);
10901 -- Error routine invoked by the generic instantiation below when
10902 -- the variant part has a non static choice.
10904 procedure Process_Declarations (Variant : Node_Id);
10905 -- Processes declarations associated with a variant. We analyzed
10906 -- the declarations earlier (in Sem_Ch3.Analyze_Variant_Part),
10907 -- but we still need the recursive call to Check_Choices for any
10908 -- nested variant to get its choices properly processed. This is
10909 -- also where we expand out the choices if expansion is active.
10911 package Variant_Choices_Processing is new
10912 Generic_Check_Choices
10913 (Process_Empty_Choice => No_OP,
10914 Process_Non_Static_Choice => Non_Static_Choice_Error,
10915 Process_Associated_Node => Process_Declarations);
10916 use Variant_Choices_Processing;
10918 -----------------------------
10919 -- Non_Static_Choice_Error --
10920 -----------------------------
10922 procedure Non_Static_Choice_Error (Choice : Node_Id) is
10924 Flag_Non_Static_Expr
10925 ("choice given in variant part is not static!", Choice);
10926 end Non_Static_Choice_Error;
10928 --------------------------
10929 -- Process_Declarations --
10930 --------------------------
10932 procedure Process_Declarations (Variant : Node_Id) is
10933 CL : constant Node_Id := Component_List (Variant);
10937 -- Check for static predicate present in this variant
10939 if Has_SP_Choice (Variant) then
10941 -- Here we expand. You might expect to find this call in
10942 -- Expand_N_Variant_Part, but that is called when we first
10943 -- see the variant part, and we cannot do this expansion
10944 -- earlier than the freeze point, since for statically
10945 -- predicated subtypes, the predicate is not known till
10946 -- the freeze point.
10948 -- Furthermore, we do this expansion even if the expander
10949 -- is not active, because other semantic processing, e.g.
10950 -- for aggregates, requires the expanded list of choices.
10952 -- If the expander is not active, then we can't just clobber
10953 -- the list since it would invalidate the ASIS -gnatct tree.
10954 -- So we have to rewrite the variant part with a Rewrite
10955 -- call that replaces it with a copy and clobber the copy.
10957 if not Expander_Active then
10959 NewV : constant Node_Id := New_Copy (Variant);
10961 Set_Discrete_Choices
10962 (NewV, New_Copy_List (Discrete_Choices (Variant)));
10963 Rewrite (Variant, NewV);
10967 Expand_Static_Predicates_In_Choices (Variant);
10970 -- We don't need to worry about the declarations in the variant
10971 -- (since they were analyzed by Analyze_Choices when we first
10972 -- encountered the variant), but we do need to take care of
10973 -- expansion of any nested variants.
10975 if not Null_Present (CL) then
10976 VP := Variant_Part (CL);
10978 if Present (VP) then
10980 (VP, Variants (VP), Etype (Name (VP)), Others_Present);
10983 end Process_Declarations;
10985 -- Start of processing for Check_Variant_Part
10988 -- Find component list
10992 if Nkind (D) = N_Full_Type_Declaration then
10993 T := Type_Definition (D);
10995 if Nkind (T) = N_Record_Definition then
10996 C := Component_List (T);
10998 elsif Nkind (T) = N_Derived_Type_Definition
10999 and then Present (Record_Extension_Part (T))
11001 C := Component_List (Record_Extension_Part (T));
11005 -- Case of variant part present
11007 if Present (C) and then Present (Variant_Part (C)) then
11008 VP := Variant_Part (C);
11013 (VP, Variants (VP), Etype (Name (VP)), Others_Present);
11015 -- If the last variant does not contain the Others choice,
11016 -- replace it with an N_Others_Choice node since Gigi always
11017 -- wants an Others. Note that we do not bother to call Analyze
11018 -- on the modified variant part, since its only effect would be
11019 -- to compute the Others_Discrete_Choices node laboriously, and
11020 -- of course we already know the list of choices corresponding
11021 -- to the others choice (it's the list we're replacing).
11023 -- We only want to do this if the expander is active, since
11024 -- we do not want to clobber the ASIS tree.
11026 if Expander_Active then
11028 Last_Var : constant Node_Id :=
11029 Last_Non_Pragma (Variants (VP));
11031 Others_Node : Node_Id;
11034 if Nkind (First (Discrete_Choices (Last_Var))) /=
11037 Others_Node := Make_Others_Choice (Sloc (Last_Var));
11038 Set_Others_Discrete_Choices
11039 (Others_Node, Discrete_Choices (Last_Var));
11040 Set_Discrete_Choices
11041 (Last_Var, New_List (Others_Node));
11046 end Check_Variant_Part;
11048 end Freeze_Entity_Checks;
11050 -------------------------
11051 -- Get_Alignment_Value --
11052 -------------------------
11054 function Get_Alignment_Value (Expr : Node_Id) return Uint is
11055 Align : constant Uint := Static_Integer (Expr);
11058 if Align = No_Uint then
11061 elsif Align <= 0 then
11062 Error_Msg_N ("alignment value must be positive", Expr);
11066 for J in Int range 0 .. 64 loop
11068 M : constant Uint := Uint_2 ** J;
11071 exit when M = Align;
11075 ("alignment value must be power of 2", Expr);
11083 end Get_Alignment_Value;
11085 -------------------------------------
11086 -- Inherit_Aspects_At_Freeze_Point --
11087 -------------------------------------
11089 procedure Inherit_Aspects_At_Freeze_Point (Typ : Entity_Id) is
11090 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11091 (Rep_Item : Node_Id) return Boolean;
11092 -- This routine checks if Rep_Item is either a pragma or an aspect
11093 -- specification node whose correponding pragma (if any) is present in
11094 -- the Rep Item chain of the entity it has been specified to.
11096 --------------------------------------------------
11097 -- Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item --
11098 --------------------------------------------------
11100 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11101 (Rep_Item : Node_Id) return Boolean
11105 Nkind (Rep_Item) = N_Pragma
11106 or else Present_In_Rep_Item
11107 (Entity (Rep_Item), Aspect_Rep_Item (Rep_Item));
11108 end Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item;
11110 -- Start of processing for Inherit_Aspects_At_Freeze_Point
11113 -- A representation item is either subtype-specific (Size and Alignment
11114 -- clauses) or type-related (all others). Subtype-specific aspects may
11115 -- differ for different subtypes of the same type (RM 13.1.8).
11117 -- A derived type inherits each type-related representation aspect of
11118 -- its parent type that was directly specified before the declaration of
11119 -- the derived type (RM 13.1.15).
11121 -- A derived subtype inherits each subtype-specific representation
11122 -- aspect of its parent subtype that was directly specified before the
11123 -- declaration of the derived type (RM 13.1.15).
11125 -- The general processing involves inheriting a representation aspect
11126 -- from a parent type whenever the first rep item (aspect specification,
11127 -- attribute definition clause, pragma) corresponding to the given
11128 -- representation aspect in the rep item chain of Typ, if any, isn't
11129 -- directly specified to Typ but to one of its parents.
11131 -- ??? Note that, for now, just a limited number of representation
11132 -- aspects have been inherited here so far. Many of them are
11133 -- still inherited in Sem_Ch3. This will be fixed soon. Here is
11134 -- a non- exhaustive list of aspects that likely also need to
11135 -- be moved to this routine: Alignment, Component_Alignment,
11136 -- Component_Size, Machine_Radix, Object_Size, Pack, Predicates,
11137 -- Preelaborable_Initialization, RM_Size and Small.
11139 -- In addition, Convention must be propagated from base type to subtype,
11140 -- because the subtype may have been declared on an incomplete view.
11142 if Nkind (Parent (Typ)) = N_Private_Extension_Declaration then
11148 if not Has_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005, False)
11149 and then Has_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005)
11150 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11151 (Get_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005))
11153 Set_Is_Ada_2005_Only (Typ);
11158 if not Has_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012, False)
11159 and then Has_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012)
11160 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11161 (Get_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012))
11163 Set_Is_Ada_2012_Only (Typ);
11168 if not Has_Rep_Item (Typ, Name_Atomic, Name_Shared, False)
11169 and then Has_Rep_Pragma (Typ, Name_Atomic, Name_Shared)
11170 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11171 (Get_Rep_Item (Typ, Name_Atomic, Name_Shared))
11173 Set_Is_Atomic (Typ);
11174 Set_Is_Volatile (Typ);
11175 Set_Treat_As_Volatile (Typ);
11180 if Is_Record_Type (Typ)
11181 and then Typ /= Base_Type (Typ) and then Is_Frozen (Base_Type (Typ))
11183 Set_Convention (Typ, Convention (Base_Type (Typ)));
11186 -- Default_Component_Value
11188 -- Verify that there is no rep_item declared for the type, and there
11189 -- is one coming from an ancestor.
11191 if Is_Array_Type (Typ)
11192 and then Is_Base_Type (Typ)
11193 and then not Has_Rep_Item (Typ, Name_Default_Component_Value, False)
11194 and then Has_Rep_Item (Typ, Name_Default_Component_Value)
11196 Set_Default_Aspect_Component_Value (Typ,
11197 Default_Aspect_Component_Value
11198 (Entity (Get_Rep_Item (Typ, Name_Default_Component_Value))));
11203 if Is_Scalar_Type (Typ)
11204 and then Is_Base_Type (Typ)
11205 and then not Has_Rep_Item (Typ, Name_Default_Value, False)
11206 and then Has_Rep_Item (Typ, Name_Default_Value)
11208 Set_Has_Default_Aspect (Typ);
11209 Set_Default_Aspect_Value (Typ,
11210 Default_Aspect_Value
11211 (Entity (Get_Rep_Item (Typ, Name_Default_Value))));
11216 if not Has_Rep_Item (Typ, Name_Discard_Names, False)
11217 and then Has_Rep_Item (Typ, Name_Discard_Names)
11218 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11219 (Get_Rep_Item (Typ, Name_Discard_Names))
11221 Set_Discard_Names (Typ);
11226 if not Has_Rep_Item (Typ, Name_Invariant, False)
11227 and then Has_Rep_Item (Typ, Name_Invariant)
11228 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11229 (Get_Rep_Item (Typ, Name_Invariant))
11231 Set_Has_Invariants (Typ);
11233 if Class_Present (Get_Rep_Item (Typ, Name_Invariant)) then
11234 Set_Has_Inheritable_Invariants (Typ);
11237 -- If we have a subtype with invariants, whose base type does not have
11238 -- invariants, copy these invariants to the base type. This happens for
11239 -- the case of implicit base types created for scalar and array types.
11241 elsif Has_Invariants (Typ)
11242 and then not Has_Invariants (Base_Type (Typ))
11244 Set_Has_Invariants (Base_Type (Typ));
11245 Set_Invariant_Procedure (Base_Type (Typ), Invariant_Procedure (Typ));
11250 if not Has_Rep_Item (Typ, Name_Volatile, False)
11251 and then Has_Rep_Item (Typ, Name_Volatile)
11252 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11253 (Get_Rep_Item (Typ, Name_Volatile))
11255 Set_Is_Volatile (Typ);
11256 Set_Treat_As_Volatile (Typ);
11259 -- Volatile_Full_Access
11261 if not Has_Rep_Item (Typ, Name_Volatile_Full_Access, False)
11262 and then Has_Rep_Pragma (Typ, Name_Volatile_Full_Access)
11263 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11264 (Get_Rep_Item (Typ, Name_Volatile_Full_Access))
11266 Set_Is_Volatile_Full_Access (Typ);
11267 Set_Is_Volatile (Typ);
11268 Set_Treat_As_Volatile (Typ);
11271 -- Inheritance for derived types only
11273 if Is_Derived_Type (Typ) then
11275 Bas_Typ : constant Entity_Id := Base_Type (Typ);
11276 Imp_Bas_Typ : constant Entity_Id := Implementation_Base_Type (Typ);
11279 -- Atomic_Components
11281 if not Has_Rep_Item (Typ, Name_Atomic_Components, False)
11282 and then Has_Rep_Item (Typ, Name_Atomic_Components)
11283 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11284 (Get_Rep_Item (Typ, Name_Atomic_Components))
11286 Set_Has_Atomic_Components (Imp_Bas_Typ);
11289 -- Volatile_Components
11291 if not Has_Rep_Item (Typ, Name_Volatile_Components, False)
11292 and then Has_Rep_Item (Typ, Name_Volatile_Components)
11293 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11294 (Get_Rep_Item (Typ, Name_Volatile_Components))
11296 Set_Has_Volatile_Components (Imp_Bas_Typ);
11299 -- Finalize_Storage_Only
11301 if not Has_Rep_Pragma (Typ, Name_Finalize_Storage_Only, False)
11302 and then Has_Rep_Pragma (Typ, Name_Finalize_Storage_Only)
11304 Set_Finalize_Storage_Only (Bas_Typ);
11307 -- Universal_Aliasing
11309 if not Has_Rep_Item (Typ, Name_Universal_Aliasing, False)
11310 and then Has_Rep_Item (Typ, Name_Universal_Aliasing)
11311 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11312 (Get_Rep_Item (Typ, Name_Universal_Aliasing))
11314 Set_Universal_Aliasing (Imp_Bas_Typ);
11319 if Is_Record_Type (Typ) then
11320 if not Has_Rep_Item (Typ, Name_Bit_Order, False)
11321 and then Has_Rep_Item (Typ, Name_Bit_Order)
11323 Set_Reverse_Bit_Order (Bas_Typ,
11324 Reverse_Bit_Order (Entity (Name
11325 (Get_Rep_Item (Typ, Name_Bit_Order)))));
11329 -- Scalar_Storage_Order
11331 -- Note: the aspect is specified on a first subtype, but recorded
11332 -- in a flag of the base type!
11334 if (Is_Record_Type (Typ) or else Is_Array_Type (Typ))
11335 and then Typ = Bas_Typ
11337 -- For a type extension, always inherit from parent; otherwise
11338 -- inherit if no default applies. Note: we do not check for
11339 -- an explicit rep item on the parent type when inheriting,
11340 -- because the parent SSO may itself have been set by default.
11342 if not Has_Rep_Item (First_Subtype (Typ),
11343 Name_Scalar_Storage_Order, False)
11344 and then (Is_Tagged_Type (Bas_Typ)
11345 or else not (SSO_Set_Low_By_Default (Bas_Typ)
11347 SSO_Set_High_By_Default (Bas_Typ)))
11349 Set_Reverse_Storage_Order (Bas_Typ,
11350 Reverse_Storage_Order
11351 (Implementation_Base_Type (Etype (Bas_Typ))));
11353 -- Clear default SSO indications, since the inherited aspect
11354 -- which was set explicitly overrides the default.
11356 Set_SSO_Set_Low_By_Default (Bas_Typ, False);
11357 Set_SSO_Set_High_By_Default (Bas_Typ, False);
11362 end Inherit_Aspects_At_Freeze_Point;
11368 procedure Initialize is
11370 Address_Clause_Checks.Init;
11371 Unchecked_Conversions.Init;
11373 if VM_Target /= No_VM or else AAMP_On_Target then
11374 Independence_Checks.Init;
11378 ---------------------------
11379 -- Install_Discriminants --
11380 ---------------------------
11382 procedure Install_Discriminants (E : Entity_Id) is
11386 Disc := First_Discriminant (E);
11387 while Present (Disc) loop
11388 Prev := Current_Entity (Disc);
11389 Set_Current_Entity (Disc);
11390 Set_Is_Immediately_Visible (Disc);
11391 Set_Homonym (Disc, Prev);
11392 Next_Discriminant (Disc);
11394 end Install_Discriminants;
11396 -------------------------
11397 -- Is_Operational_Item --
11398 -------------------------
11400 function Is_Operational_Item (N : Node_Id) return Boolean is
11402 if Nkind (N) /= N_Attribute_Definition_Clause then
11407 Id : constant Attribute_Id := Get_Attribute_Id (Chars (N));
11409 return Id = Attribute_Input
11410 or else Id = Attribute_Output
11411 or else Id = Attribute_Read
11412 or else Id = Attribute_Write
11413 or else Id = Attribute_External_Tag;
11416 end Is_Operational_Item;
11418 -------------------------
11419 -- Is_Predicate_Static --
11420 -------------------------
11422 -- Note: the basic legality of the expression has already been checked, so
11423 -- we don't need to worry about cases or ranges on strings for example.
11425 function Is_Predicate_Static
11427 Nam : Name_Id) return Boolean
11429 function All_Static_Case_Alternatives (L : List_Id) return Boolean;
11430 -- Given a list of case expression alternatives, returns True if all
11431 -- the alternatives are static (have all static choices, and a static
11434 function All_Static_Choices (L : List_Id) return Boolean;
11435 -- Returns true if all elements of the list are OK static choices
11436 -- as defined below for Is_Static_Choice. Used for case expression
11437 -- alternatives and for the right operand of a membership test. An
11438 -- others_choice is static if the corresponding expression is static.
11439 -- The staticness of the bounds is checked separately.
11441 function Is_Static_Choice (N : Node_Id) return Boolean;
11442 -- Returns True if N represents a static choice (static subtype, or
11443 -- static subtype indication, or static expression, or static range).
11445 -- Note that this is a bit more inclusive than we actually need
11446 -- (in particular membership tests do not allow the use of subtype
11447 -- indications). But that doesn't matter, we have already checked
11448 -- that the construct is legal to get this far.
11450 function Is_Type_Ref (N : Node_Id) return Boolean;
11451 pragma Inline (Is_Type_Ref);
11452 -- Returns True if N is a reference to the type for the predicate in the
11453 -- expression (i.e. if it is an identifier whose Chars field matches the
11454 -- Nam given in the call). N must not be parenthesized, if the type name
11455 -- appears in parens, this routine will return False.
11457 ----------------------------------
11458 -- All_Static_Case_Alternatives --
11459 ----------------------------------
11461 function All_Static_Case_Alternatives (L : List_Id) return Boolean is
11466 while Present (N) loop
11467 if not (All_Static_Choices (Discrete_Choices (N))
11468 and then Is_OK_Static_Expression (Expression (N)))
11477 end All_Static_Case_Alternatives;
11479 ------------------------
11480 -- All_Static_Choices --
11481 ------------------------
11483 function All_Static_Choices (L : List_Id) return Boolean is
11488 while Present (N) loop
11489 if not Is_Static_Choice (N) then
11497 end All_Static_Choices;
11499 ----------------------
11500 -- Is_Static_Choice --
11501 ----------------------
11503 function Is_Static_Choice (N : Node_Id) return Boolean is
11505 return Nkind (N) = N_Others_Choice
11506 or else Is_OK_Static_Expression (N)
11507 or else (Is_Entity_Name (N) and then Is_Type (Entity (N))
11508 and then Is_OK_Static_Subtype (Entity (N)))
11509 or else (Nkind (N) = N_Subtype_Indication
11510 and then Is_OK_Static_Subtype (Entity (N)))
11511 or else (Nkind (N) = N_Range and then Is_OK_Static_Range (N));
11512 end Is_Static_Choice;
11518 function Is_Type_Ref (N : Node_Id) return Boolean is
11520 return Nkind (N) = N_Identifier
11521 and then Chars (N) = Nam
11522 and then Paren_Count (N) = 0;
11525 -- Start of processing for Is_Predicate_Static
11528 -- Predicate_Static means one of the following holds. Numbers are the
11529 -- corresponding paragraph numbers in (RM 3.2.4(16-22)).
11531 -- 16: A static expression
11533 if Is_OK_Static_Expression (Expr) then
11536 -- 17: A membership test whose simple_expression is the current
11537 -- instance, and whose membership_choice_list meets the requirements
11538 -- for a static membership test.
11540 elsif Nkind (Expr) in N_Membership_Test
11541 and then ((Present (Right_Opnd (Expr))
11542 and then Is_Static_Choice (Right_Opnd (Expr)))
11544 (Present (Alternatives (Expr))
11545 and then All_Static_Choices (Alternatives (Expr))))
11549 -- 18. A case_expression whose selecting_expression is the current
11550 -- instance, and whose dependent expressions are static expressions.
11552 elsif Nkind (Expr) = N_Case_Expression
11553 and then Is_Type_Ref (Expression (Expr))
11554 and then All_Static_Case_Alternatives (Alternatives (Expr))
11558 -- 19. A call to a predefined equality or ordering operator, where one
11559 -- operand is the current instance, and the other is a static
11562 -- Note: the RM is clearly wrong here in not excluding string types.
11563 -- Without this exclusion, we would allow expressions like X > "ABC"
11564 -- to be considered as predicate-static, which is clearly not intended,
11565 -- since the idea is for predicate-static to be a subset of normal
11566 -- static expressions (and "DEF" > "ABC" is not a static expression).
11568 -- However, we do allow internally generated (not from source) equality
11569 -- and inequality operations to be valid on strings (this helps deal
11570 -- with cases where we transform A in "ABC" to A = "ABC).
11572 elsif Nkind (Expr) in N_Op_Compare
11573 and then ((not Is_String_Type (Etype (Left_Opnd (Expr))))
11574 or else (Nkind_In (Expr, N_Op_Eq, N_Op_Ne)
11575 and then not Comes_From_Source (Expr)))
11576 and then ((Is_Type_Ref (Left_Opnd (Expr))
11577 and then Is_OK_Static_Expression (Right_Opnd (Expr)))
11579 (Is_Type_Ref (Right_Opnd (Expr))
11580 and then Is_OK_Static_Expression (Left_Opnd (Expr))))
11584 -- 20. A call to a predefined boolean logical operator, where each
11585 -- operand is predicate-static.
11587 elsif (Nkind_In (Expr, N_Op_And, N_Op_Or, N_Op_Xor)
11588 and then Is_Predicate_Static (Left_Opnd (Expr), Nam)
11589 and then Is_Predicate_Static (Right_Opnd (Expr), Nam))
11591 (Nkind (Expr) = N_Op_Not
11592 and then Is_Predicate_Static (Right_Opnd (Expr), Nam))
11596 -- 21. A short-circuit control form where both operands are
11597 -- predicate-static.
11599 elsif Nkind (Expr) in N_Short_Circuit
11600 and then Is_Predicate_Static (Left_Opnd (Expr), Nam)
11601 and then Is_Predicate_Static (Right_Opnd (Expr), Nam)
11605 -- 22. A parenthesized predicate-static expression. This does not
11606 -- require any special test, since we just ignore paren levels in
11607 -- all the cases above.
11609 -- One more test that is an implementation artifact caused by the fact
11610 -- that we are analyzing not the original expression, but the generated
11611 -- expression in the body of the predicate function. This can include
11612 -- references to inherited predicates, so that the expression we are
11613 -- processing looks like:
11615 -- expression and then xxPredicate (typ (Inns))
11617 -- Where the call is to a Predicate function for an inherited predicate.
11618 -- We simply ignore such a call, which could be to either a dynamic or
11619 -- a static predicate. Note that if the parent predicate is dynamic then
11620 -- eventually this type will be marked as dynamic, but you are allowed
11621 -- to specify a static predicate for a subtype which is inheriting a
11622 -- dynamic predicate, so the static predicate validation here ignores
11623 -- the inherited predicate even if it is dynamic.
11625 elsif Nkind (Expr) = N_Function_Call
11626 and then Is_Predicate_Function (Entity (Name (Expr)))
11630 -- That's an exhaustive list of tests, all other cases are not
11631 -- predicate-static, so we return False.
11636 end Is_Predicate_Static;
11638 ---------------------
11639 -- Kill_Rep_Clause --
11640 ---------------------
11642 procedure Kill_Rep_Clause (N : Node_Id) is
11644 pragma Assert (Ignore_Rep_Clauses);
11646 -- Note: we use Replace rather than Rewrite, because we don't want
11647 -- ASIS to be able to use Original_Node to dig out the (undecorated)
11648 -- rep clause that is being replaced.
11650 Replace (N, Make_Null_Statement (Sloc (N)));
11652 -- The null statement must be marked as not coming from source. This is
11653 -- so that ASIS ignores it, and also the back end does not expect bogus
11654 -- "from source" null statements in weird places (e.g. in declarative
11655 -- regions where such null statements are not allowed).
11657 Set_Comes_From_Source (N, False);
11658 end Kill_Rep_Clause;
11664 function Minimum_Size
11666 Biased : Boolean := False) return Nat
11668 Lo : Uint := No_Uint;
11669 Hi : Uint := No_Uint;
11670 LoR : Ureal := No_Ureal;
11671 HiR : Ureal := No_Ureal;
11672 LoSet : Boolean := False;
11673 HiSet : Boolean := False;
11676 Ancest : Entity_Id;
11677 R_Typ : constant Entity_Id := Root_Type (T);
11680 -- If bad type, return 0
11682 if T = Any_Type then
11685 -- For generic types, just return zero. There cannot be any legitimate
11686 -- need to know such a size, but this routine may be called with a
11687 -- generic type as part of normal processing.
11689 elsif Is_Generic_Type (R_Typ) or else R_Typ = Any_Type then
11692 -- Access types (cannot have size smaller than System.Address)
11694 elsif Is_Access_Type (T) then
11695 return System_Address_Size;
11697 -- Floating-point types
11699 elsif Is_Floating_Point_Type (T) then
11700 return UI_To_Int (Esize (R_Typ));
11704 elsif Is_Discrete_Type (T) then
11706 -- The following loop is looking for the nearest compile time known
11707 -- bounds following the ancestor subtype chain. The idea is to find
11708 -- the most restrictive known bounds information.
11712 if Ancest = Any_Type or else Etype (Ancest) = Any_Type then
11717 if Compile_Time_Known_Value (Type_Low_Bound (Ancest)) then
11718 Lo := Expr_Rep_Value (Type_Low_Bound (Ancest));
11725 if Compile_Time_Known_Value (Type_High_Bound (Ancest)) then
11726 Hi := Expr_Rep_Value (Type_High_Bound (Ancest));
11732 Ancest := Ancestor_Subtype (Ancest);
11734 if No (Ancest) then
11735 Ancest := Base_Type (T);
11737 if Is_Generic_Type (Ancest) then
11743 -- Fixed-point types. We can't simply use Expr_Value to get the
11744 -- Corresponding_Integer_Value values of the bounds, since these do not
11745 -- get set till the type is frozen, and this routine can be called
11746 -- before the type is frozen. Similarly the test for bounds being static
11747 -- needs to include the case where we have unanalyzed real literals for
11748 -- the same reason.
11750 elsif Is_Fixed_Point_Type (T) then
11752 -- The following loop is looking for the nearest compile time known
11753 -- bounds following the ancestor subtype chain. The idea is to find
11754 -- the most restrictive known bounds information.
11758 if Ancest = Any_Type or else Etype (Ancest) = Any_Type then
11762 -- Note: In the following two tests for LoSet and HiSet, it may
11763 -- seem redundant to test for N_Real_Literal here since normally
11764 -- one would assume that the test for the value being known at
11765 -- compile time includes this case. However, there is a glitch.
11766 -- If the real literal comes from folding a non-static expression,
11767 -- then we don't consider any non- static expression to be known
11768 -- at compile time if we are in configurable run time mode (needed
11769 -- in some cases to give a clearer definition of what is and what
11770 -- is not accepted). So the test is indeed needed. Without it, we
11771 -- would set neither Lo_Set nor Hi_Set and get an infinite loop.
11774 if Nkind (Type_Low_Bound (Ancest)) = N_Real_Literal
11775 or else Compile_Time_Known_Value (Type_Low_Bound (Ancest))
11777 LoR := Expr_Value_R (Type_Low_Bound (Ancest));
11784 if Nkind (Type_High_Bound (Ancest)) = N_Real_Literal
11785 or else Compile_Time_Known_Value (Type_High_Bound (Ancest))
11787 HiR := Expr_Value_R (Type_High_Bound (Ancest));
11793 Ancest := Ancestor_Subtype (Ancest);
11795 if No (Ancest) then
11796 Ancest := Base_Type (T);
11798 if Is_Generic_Type (Ancest) then
11804 Lo := UR_To_Uint (LoR / Small_Value (T));
11805 Hi := UR_To_Uint (HiR / Small_Value (T));
11807 -- No other types allowed
11810 raise Program_Error;
11813 -- Fall through with Hi and Lo set. Deal with biased case
11816 and then not Is_Fixed_Point_Type (T)
11817 and then not (Is_Enumeration_Type (T)
11818 and then Has_Non_Standard_Rep (T)))
11819 or else Has_Biased_Representation (T)
11825 -- Null range case, size is always zero. We only do this in the discrete
11826 -- type case, since that's the odd case that came up. Probably we should
11827 -- also do this in the fixed-point case, but doing so causes peculiar
11828 -- gigi failures, and it is not worth worrying about this incredibly
11829 -- marginal case (explicit null-range fixed-point type declarations)???
11831 if Lo > Hi and then Is_Discrete_Type (T) then
11834 -- Signed case. Note that we consider types like range 1 .. -1 to be
11835 -- signed for the purpose of computing the size, since the bounds have
11836 -- to be accommodated in the base type.
11838 elsif Lo < 0 or else Hi < 0 then
11842 -- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1))
11843 -- Note that we accommodate the case where the bounds cross. This
11844 -- can happen either because of the way the bounds are declared
11845 -- or because of the algorithm in Freeze_Fixed_Point_Type.
11859 -- If both bounds are positive, make sure that both are represen-
11860 -- table in the case where the bounds are crossed. This can happen
11861 -- either because of the way the bounds are declared, or because of
11862 -- the algorithm in Freeze_Fixed_Point_Type.
11868 -- S = size, (can accommodate 0 .. (2**size - 1))
11871 while Hi >= Uint_2 ** S loop
11879 ---------------------------
11880 -- New_Stream_Subprogram --
11881 ---------------------------
11883 procedure New_Stream_Subprogram
11887 Nam : TSS_Name_Type)
11889 Loc : constant Source_Ptr := Sloc (N);
11890 Sname : constant Name_Id := Make_TSS_Name (Base_Type (Ent), Nam);
11891 Subp_Id : Entity_Id;
11892 Subp_Decl : Node_Id;
11896 Defer_Declaration : constant Boolean :=
11897 Is_Tagged_Type (Ent) or else Is_Private_Type (Ent);
11898 -- For a tagged type, there is a declaration for each stream attribute
11899 -- at the freeze point, and we must generate only a completion of this
11900 -- declaration. We do the same for private types, because the full view
11901 -- might be tagged. Otherwise we generate a declaration at the point of
11902 -- the attribute definition clause.
11904 function Build_Spec return Node_Id;
11905 -- Used for declaration and renaming declaration, so that this is
11906 -- treated as a renaming_as_body.
11912 function Build_Spec return Node_Id is
11913 Out_P : constant Boolean := (Nam = TSS_Stream_Read);
11916 T_Ref : constant Node_Id := New_Occurrence_Of (Etyp, Loc);
11919 Subp_Id := Make_Defining_Identifier (Loc, Sname);
11921 -- S : access Root_Stream_Type'Class
11923 Formals := New_List (
11924 Make_Parameter_Specification (Loc,
11925 Defining_Identifier =>
11926 Make_Defining_Identifier (Loc, Name_S),
11928 Make_Access_Definition (Loc,
11930 New_Occurrence_Of (
11931 Designated_Type (Etype (F)), Loc))));
11933 if Nam = TSS_Stream_Input then
11935 Make_Function_Specification (Loc,
11936 Defining_Unit_Name => Subp_Id,
11937 Parameter_Specifications => Formals,
11938 Result_Definition => T_Ref);
11942 Append_To (Formals,
11943 Make_Parameter_Specification (Loc,
11944 Defining_Identifier => Make_Defining_Identifier (Loc, Name_V),
11945 Out_Present => Out_P,
11946 Parameter_Type => T_Ref));
11949 Make_Procedure_Specification (Loc,
11950 Defining_Unit_Name => Subp_Id,
11951 Parameter_Specifications => Formals);
11957 -- Start of processing for New_Stream_Subprogram
11960 F := First_Formal (Subp);
11962 if Ekind (Subp) = E_Procedure then
11963 Etyp := Etype (Next_Formal (F));
11965 Etyp := Etype (Subp);
11968 -- Prepare subprogram declaration and insert it as an action on the
11969 -- clause node. The visibility for this entity is used to test for
11970 -- visibility of the attribute definition clause (in the sense of
11971 -- 8.3(23) as amended by AI-195).
11973 if not Defer_Declaration then
11975 Make_Subprogram_Declaration (Loc,
11976 Specification => Build_Spec);
11978 -- For a tagged type, there is always a visible declaration for each
11979 -- stream TSS (it is a predefined primitive operation), and the
11980 -- completion of this declaration occurs at the freeze point, which is
11981 -- not always visible at places where the attribute definition clause is
11982 -- visible. So, we create a dummy entity here for the purpose of
11983 -- tracking the visibility of the attribute definition clause itself.
11987 Make_Defining_Identifier (Loc, New_External_Name (Sname, 'V'));
11989 Make_Object_Declaration (Loc,
11990 Defining_Identifier => Subp_Id,
11991 Object_Definition => New_Occurrence_Of (Standard_Boolean, Loc));
11994 Insert_Action (N, Subp_Decl);
11995 Set_Entity (N, Subp_Id);
11998 Make_Subprogram_Renaming_Declaration (Loc,
11999 Specification => Build_Spec,
12000 Name => New_Occurrence_Of (Subp, Loc));
12002 if Defer_Declaration then
12003 Set_TSS (Base_Type (Ent), Subp_Id);
12005 Insert_Action (N, Subp_Decl);
12006 Copy_TSS (Subp_Id, Base_Type (Ent));
12008 end New_Stream_Subprogram;
12010 ------------------------------------------
12011 -- Push_Scope_And_Install_Discriminants --
12012 ------------------------------------------
12014 procedure Push_Scope_And_Install_Discriminants (E : Entity_Id) is
12016 if Has_Discriminants (E) then
12019 -- Make discriminants visible for type declarations and protected
12020 -- type declarations, not for subtype declarations (RM 13.1.1 (12/3))
12022 if Nkind (Parent (E)) /= N_Subtype_Declaration then
12023 Install_Discriminants (E);
12026 end Push_Scope_And_Install_Discriminants;
12028 ------------------------
12029 -- Rep_Item_Too_Early --
12030 ------------------------
12032 function Rep_Item_Too_Early (T : Entity_Id; N : Node_Id) return Boolean is
12034 -- Cannot apply non-operational rep items to generic types
12036 if Is_Operational_Item (N) then
12040 and then Is_Generic_Type (Root_Type (T))
12041 and then (Nkind (N) /= N_Pragma
12042 or else Get_Pragma_Id (N) /= Pragma_Convention)
12044 Error_Msg_N ("representation item not allowed for generic type", N);
12048 -- Otherwise check for incomplete type
12050 if Is_Incomplete_Or_Private_Type (T)
12051 and then No (Underlying_Type (T))
12053 (Nkind (N) /= N_Pragma
12054 or else Get_Pragma_Id (N) /= Pragma_Import)
12057 ("representation item must be after full type declaration", N);
12060 -- If the type has incomplete components, a representation clause is
12061 -- illegal but stream attributes and Convention pragmas are correct.
12063 elsif Has_Private_Component (T) then
12064 if Nkind (N) = N_Pragma then
12069 ("representation item must appear after type is fully defined",
12076 end Rep_Item_Too_Early;
12078 -----------------------
12079 -- Rep_Item_Too_Late --
12080 -----------------------
12082 function Rep_Item_Too_Late
12085 FOnly : Boolean := False) return Boolean
12088 Parent_Type : Entity_Id;
12090 procedure No_Type_Rep_Item;
12091 -- Output message indicating that no type-related aspects can be
12092 -- specified due to some property of the parent type.
12094 procedure Too_Late;
12095 -- Output message for an aspect being specified too late
12097 -- Note that neither of the above errors is considered a serious one,
12098 -- since the effect is simply that we ignore the representation clause
12100 -- Is this really true? In any case if we make this change we must
12101 -- document the requirement in the spec of Rep_Item_Too_Late that
12102 -- if True is returned, then the rep item must be completely ignored???
12104 ----------------------
12105 -- No_Type_Rep_Item --
12106 ----------------------
12108 procedure No_Type_Rep_Item is
12110 Error_Msg_N ("|type-related representation item not permitted!", N);
12111 end No_Type_Rep_Item;
12117 procedure Too_Late is
12119 -- Other compilers seem more relaxed about rep items appearing too
12120 -- late. Since analysis tools typically don't care about rep items
12121 -- anyway, no reason to be too strict about this.
12123 if not Relaxed_RM_Semantics then
12124 Error_Msg_N ("|representation item appears too late!", N);
12128 -- Start of processing for Rep_Item_Too_Late
12131 -- First make sure entity is not frozen (RM 13.1(9))
12135 -- Exclude imported types, which may be frozen if they appear in a
12136 -- representation clause for a local type.
12138 and then not From_Limited_With (T)
12140 -- Exclude generated entities (not coming from source). The common
12141 -- case is when we generate a renaming which prematurely freezes the
12142 -- renamed internal entity, but we still want to be able to set copies
12143 -- of attribute values such as Size/Alignment.
12145 and then Comes_From_Source (T)
12148 S := First_Subtype (T);
12150 if Present (Freeze_Node (S)) then
12151 if not Relaxed_RM_Semantics then
12153 ("??no more representation items for }", Freeze_Node (S), S);
12159 -- Check for case of untagged derived type whose parent either has
12160 -- primitive operations, or is a by reference type (RM 13.1(10)). In
12161 -- this case we do not output a Too_Late message, since there is no
12162 -- earlier point where the rep item could be placed to make it legal.
12166 and then Is_Derived_Type (T)
12167 and then not Is_Tagged_Type (T)
12169 Parent_Type := Etype (Base_Type (T));
12171 if Has_Primitive_Operations (Parent_Type) then
12174 if not Relaxed_RM_Semantics then
12176 ("\parent type & has primitive operations!", N, Parent_Type);
12181 elsif Is_By_Reference_Type (Parent_Type) then
12184 if not Relaxed_RM_Semantics then
12186 ("\parent type & is a by reference type!", N, Parent_Type);
12193 -- No error, but one more warning to consider. The RM (surprisingly)
12194 -- allows this pattern:
12197 -- primitive operations for S
12198 -- type R is new S;
12199 -- rep clause for S
12201 -- Meaning that calls on the primitive operations of S for values of
12202 -- type R may require possibly expensive implicit conversion operations.
12203 -- This is not an error, but is worth a warning.
12205 if not Relaxed_RM_Semantics and then Is_Type (T) then
12207 DTL : constant Entity_Id := Derived_Type_Link (Base_Type (T));
12211 and then Has_Primitive_Operations (Base_Type (T))
12213 -- For now, do not generate this warning for the case of aspect
12214 -- specification using Ada 2012 syntax, since we get wrong
12215 -- messages we do not understand. The whole business of derived
12216 -- types and rep items seems a bit confused when aspects are
12217 -- used, since the aspects are not evaluated till freeze time.
12219 and then not From_Aspect_Specification (N)
12221 Error_Msg_Sloc := Sloc (DTL);
12223 ("representation item for& appears after derived type "
12224 & "declaration#??", N);
12226 ("\may result in implicit conversions for primitive "
12227 & "operations of&??", N, T);
12229 ("\to change representations when called with arguments "
12230 & "of type&??", N, DTL);
12235 -- No error, link item into head of chain of rep items for the entity,
12236 -- but avoid chaining if we have an overloadable entity, and the pragma
12237 -- is one that can apply to multiple overloaded entities.
12239 if Is_Overloadable (T) and then Nkind (N) = N_Pragma then
12241 Pname : constant Name_Id := Pragma_Name (N);
12243 if Nam_In (Pname, Name_Convention, Name_Import, Name_Export,
12244 Name_External, Name_Interface)
12251 Record_Rep_Item (T, N);
12253 end Rep_Item_Too_Late;
12255 -------------------------------------
12256 -- Replace_Type_References_Generic --
12257 -------------------------------------
12259 procedure Replace_Type_References_Generic (N : Node_Id; T : Entity_Id) is
12260 TName : constant Name_Id := Chars (T);
12262 function Replace_Node (N : Node_Id) return Traverse_Result;
12263 -- Processes a single node in the traversal procedure below, checking
12264 -- if node N should be replaced, and if so, doing the replacement.
12266 procedure Replace_Type_Refs is new Traverse_Proc (Replace_Node);
12267 -- This instantiation provides the body of Replace_Type_References
12273 function Replace_Node (N : Node_Id) return Traverse_Result is
12278 -- Case of identifier
12280 if Nkind (N) = N_Identifier then
12282 -- If not the type name, check whether it is a reference to
12283 -- some other type, which must be frozen before the predicate
12284 -- function is analyzed, i.e. before the freeze node of the
12285 -- type to which the predicate applies.
12287 if Chars (N) /= TName then
12288 if Present (Current_Entity (N))
12289 and then Is_Type (Current_Entity (N))
12291 Freeze_Before (Freeze_Node (T), Current_Entity (N));
12296 -- Otherwise do the replacement and we are done with this node
12299 Replace_Type_Reference (N);
12303 -- Case of selected component (which is what a qualification
12304 -- looks like in the unanalyzed tree, which is what we have.
12306 elsif Nkind (N) = N_Selected_Component then
12308 -- If selector name is not our type, keeping going (we might
12309 -- still have an occurrence of the type in the prefix).
12311 if Nkind (Selector_Name (N)) /= N_Identifier
12312 or else Chars (Selector_Name (N)) /= TName
12316 -- Selector name is our type, check qualification
12319 -- Loop through scopes and prefixes, doing comparison
12321 S := Current_Scope;
12324 -- Continue if no more scopes or scope with no name
12326 if No (S) or else Nkind (S) not in N_Has_Chars then
12330 -- Do replace if prefix is an identifier matching the
12331 -- scope that we are currently looking at.
12333 if Nkind (P) = N_Identifier
12334 and then Chars (P) = Chars (S)
12336 Replace_Type_Reference (N);
12340 -- Go check scope above us if prefix is itself of the
12341 -- form of a selected component, whose selector matches
12342 -- the scope we are currently looking at.
12344 if Nkind (P) = N_Selected_Component
12345 and then Nkind (Selector_Name (P)) = N_Identifier
12346 and then Chars (Selector_Name (P)) = Chars (S)
12351 -- For anything else, we don't have a match, so keep on
12352 -- going, there are still some weird cases where we may
12353 -- still have a replacement within the prefix.
12361 -- Continue for any other node kind
12369 Replace_Type_Refs (N);
12370 end Replace_Type_References_Generic;
12372 -------------------------
12373 -- Same_Representation --
12374 -------------------------
12376 function Same_Representation (Typ1, Typ2 : Entity_Id) return Boolean is
12377 T1 : constant Entity_Id := Underlying_Type (Typ1);
12378 T2 : constant Entity_Id := Underlying_Type (Typ2);
12381 -- A quick check, if base types are the same, then we definitely have
12382 -- the same representation, because the subtype specific representation
12383 -- attributes (Size and Alignment) do not affect representation from
12384 -- the point of view of this test.
12386 if Base_Type (T1) = Base_Type (T2) then
12389 elsif Is_Private_Type (Base_Type (T2))
12390 and then Base_Type (T1) = Full_View (Base_Type (T2))
12395 -- Tagged types never have differing representations
12397 if Is_Tagged_Type (T1) then
12401 -- Representations are definitely different if conventions differ
12403 if Convention (T1) /= Convention (T2) then
12407 -- Representations are different if component alignments or scalar
12408 -- storage orders differ.
12410 if (Is_Record_Type (T1) or else Is_Array_Type (T1))
12412 (Is_Record_Type (T2) or else Is_Array_Type (T2))
12414 (Component_Alignment (T1) /= Component_Alignment (T2)
12415 or else Reverse_Storage_Order (T1) /= Reverse_Storage_Order (T2))
12420 -- For arrays, the only real issue is component size. If we know the
12421 -- component size for both arrays, and it is the same, then that's
12422 -- good enough to know we don't have a change of representation.
12424 if Is_Array_Type (T1) then
12425 if Known_Component_Size (T1)
12426 and then Known_Component_Size (T2)
12427 and then Component_Size (T1) = Component_Size (T2)
12429 if VM_Target = No_VM then
12432 -- In VM targets the representation of arrays with aliased
12433 -- components differs from arrays with non-aliased components
12436 return Has_Aliased_Components (Base_Type (T1))
12438 Has_Aliased_Components (Base_Type (T2));
12443 -- Types definitely have same representation if neither has non-standard
12444 -- representation since default representations are always consistent.
12445 -- If only one has non-standard representation, and the other does not,
12446 -- then we consider that they do not have the same representation. They
12447 -- might, but there is no way of telling early enough.
12449 if Has_Non_Standard_Rep (T1) then
12450 if not Has_Non_Standard_Rep (T2) then
12454 return not Has_Non_Standard_Rep (T2);
12457 -- Here the two types both have non-standard representation, and we need
12458 -- to determine if they have the same non-standard representation.
12460 -- For arrays, we simply need to test if the component sizes are the
12461 -- same. Pragma Pack is reflected in modified component sizes, so this
12462 -- check also deals with pragma Pack.
12464 if Is_Array_Type (T1) then
12465 return Component_Size (T1) = Component_Size (T2);
12467 -- Tagged types always have the same representation, because it is not
12468 -- possible to specify different representations for common fields.
12470 elsif Is_Tagged_Type (T1) then
12473 -- Case of record types
12475 elsif Is_Record_Type (T1) then
12477 -- Packed status must conform
12479 if Is_Packed (T1) /= Is_Packed (T2) then
12482 -- Otherwise we must check components. Typ2 maybe a constrained
12483 -- subtype with fewer components, so we compare the components
12484 -- of the base types.
12487 Record_Case : declare
12488 CD1, CD2 : Entity_Id;
12490 function Same_Rep return Boolean;
12491 -- CD1 and CD2 are either components or discriminants. This
12492 -- function tests whether they have the same representation.
12498 function Same_Rep return Boolean is
12500 if No (Component_Clause (CD1)) then
12501 return No (Component_Clause (CD2));
12503 -- Note: at this point, component clauses have been
12504 -- normalized to the default bit order, so that the
12505 -- comparison of Component_Bit_Offsets is meaningful.
12508 Present (Component_Clause (CD2))
12510 Component_Bit_Offset (CD1) = Component_Bit_Offset (CD2)
12512 Esize (CD1) = Esize (CD2);
12516 -- Start of processing for Record_Case
12519 if Has_Discriminants (T1) then
12521 -- The number of discriminants may be different if the
12522 -- derived type has fewer (constrained by values). The
12523 -- invisible discriminants retain the representation of
12524 -- the original, so the discrepancy does not per se
12525 -- indicate a different representation.
12527 CD1 := First_Discriminant (T1);
12528 CD2 := First_Discriminant (T2);
12529 while Present (CD1) and then Present (CD2) loop
12530 if not Same_Rep then
12533 Next_Discriminant (CD1);
12534 Next_Discriminant (CD2);
12539 CD1 := First_Component (Underlying_Type (Base_Type (T1)));
12540 CD2 := First_Component (Underlying_Type (Base_Type (T2)));
12541 while Present (CD1) loop
12542 if not Same_Rep then
12545 Next_Component (CD1);
12546 Next_Component (CD2);
12554 -- For enumeration types, we must check each literal to see if the
12555 -- representation is the same. Note that we do not permit enumeration
12556 -- representation clauses for Character and Wide_Character, so these
12557 -- cases were already dealt with.
12559 elsif Is_Enumeration_Type (T1) then
12560 Enumeration_Case : declare
12561 L1, L2 : Entity_Id;
12564 L1 := First_Literal (T1);
12565 L2 := First_Literal (T2);
12566 while Present (L1) loop
12567 if Enumeration_Rep (L1) /= Enumeration_Rep (L2) then
12576 end Enumeration_Case;
12578 -- Any other types have the same representation for these purposes
12583 end Same_Representation;
12585 --------------------------------
12586 -- Resolve_Iterable_Operation --
12587 --------------------------------
12589 procedure Resolve_Iterable_Operation
12591 Cursor : Entity_Id;
12600 if not Is_Overloaded (N) then
12601 if not Is_Entity_Name (N)
12602 or else Ekind (Entity (N)) /= E_Function
12603 or else Scope (Entity (N)) /= Scope (Typ)
12604 or else No (First_Formal (Entity (N)))
12605 or else Etype (First_Formal (Entity (N))) /= Typ
12607 Error_Msg_N ("iterable primitive must be local function name "
12608 & "whose first formal is an iterable type", N);
12613 F1 := First_Formal (Ent);
12614 if Nam = Name_First then
12616 -- First (Container) => Cursor
12618 if Etype (Ent) /= Cursor then
12619 Error_Msg_N ("primitive for First must yield a curosr", N);
12622 elsif Nam = Name_Next then
12624 -- Next (Container, Cursor) => Cursor
12626 F2 := Next_Formal (F1);
12628 if Etype (F2) /= Cursor
12629 or else Etype (Ent) /= Cursor
12630 or else Present (Next_Formal (F2))
12632 Error_Msg_N ("no match for Next iterable primitive", N);
12635 elsif Nam = Name_Has_Element then
12637 -- Has_Element (Container, Cursor) => Boolean
12639 F2 := Next_Formal (F1);
12640 if Etype (F2) /= Cursor
12641 or else Etype (Ent) /= Standard_Boolean
12642 or else Present (Next_Formal (F2))
12644 Error_Msg_N ("no match for Has_Element iterable primitive", N);
12647 elsif Nam = Name_Element then
12648 F2 := Next_Formal (F1);
12651 or else Etype (F2) /= Cursor
12652 or else Present (Next_Formal (F2))
12654 Error_Msg_N ("no match for Element iterable primitive", N);
12659 raise Program_Error;
12663 -- Overloaded case: find subprogram with proper signature.
12664 -- Caller will report error if no match is found.
12671 Get_First_Interp (N, I, It);
12672 while Present (It.Typ) loop
12673 if Ekind (It.Nam) = E_Function
12674 and then Scope (It.Nam) = Scope (Typ)
12675 and then Etype (First_Formal (It.Nam)) = Typ
12677 F1 := First_Formal (It.Nam);
12679 if Nam = Name_First then
12680 if Etype (It.Nam) = Cursor
12681 and then No (Next_Formal (F1))
12683 Set_Entity (N, It.Nam);
12687 elsif Nam = Name_Next then
12688 F2 := Next_Formal (F1);
12691 and then No (Next_Formal (F2))
12692 and then Etype (F2) = Cursor
12693 and then Etype (It.Nam) = Cursor
12695 Set_Entity (N, It.Nam);
12699 elsif Nam = Name_Has_Element then
12700 F2 := Next_Formal (F1);
12703 and then No (Next_Formal (F2))
12704 and then Etype (F2) = Cursor
12705 and then Etype (It.Nam) = Standard_Boolean
12707 Set_Entity (N, It.Nam);
12708 F2 := Next_Formal (F1);
12712 elsif Nam = Name_Element then
12713 F2 := Next_Formal (F1);
12716 and then No (Next_Formal (F2))
12717 and then Etype (F2) = Cursor
12719 Set_Entity (N, It.Nam);
12725 Get_Next_Interp (I, It);
12729 end Resolve_Iterable_Operation;
12735 procedure Set_Biased
12739 Biased : Boolean := True)
12743 Set_Has_Biased_Representation (E);
12745 if Warn_On_Biased_Representation then
12747 ("?B?" & Msg & " forces biased representation for&", N, E);
12752 --------------------
12753 -- Set_Enum_Esize --
12754 --------------------
12756 procedure Set_Enum_Esize (T : Entity_Id) is
12762 Init_Alignment (T);
12764 -- Find the minimum standard size (8,16,32,64) that fits
12766 Lo := Enumeration_Rep (Entity (Type_Low_Bound (T)));
12767 Hi := Enumeration_Rep (Entity (Type_High_Bound (T)));
12770 if Lo >= -Uint_2**07 and then Hi < Uint_2**07 then
12771 Sz := Standard_Character_Size; -- May be > 8 on some targets
12773 elsif Lo >= -Uint_2**15 and then Hi < Uint_2**15 then
12776 elsif Lo >= -Uint_2**31 and then Hi < Uint_2**31 then
12779 else pragma Assert (Lo >= -Uint_2**63 and then Hi < Uint_2**63);
12784 if Hi < Uint_2**08 then
12785 Sz := Standard_Character_Size; -- May be > 8 on some targets
12787 elsif Hi < Uint_2**16 then
12790 elsif Hi < Uint_2**32 then
12793 else pragma Assert (Hi < Uint_2**63);
12798 -- That minimum is the proper size unless we have a foreign convention
12799 -- and the size required is 32 or less, in which case we bump the size
12800 -- up to 32. This is required for C and C++ and seems reasonable for
12801 -- all other foreign conventions.
12803 if Has_Foreign_Convention (T)
12804 and then Esize (T) < Standard_Integer_Size
12806 -- Don't do this if Short_Enums on target
12808 and then not Target_Short_Enums
12810 Init_Esize (T, Standard_Integer_Size);
12812 Init_Esize (T, Sz);
12814 end Set_Enum_Esize;
12816 -----------------------------
12817 -- Uninstall_Discriminants --
12818 -----------------------------
12820 procedure Uninstall_Discriminants (E : Entity_Id) is
12826 -- Discriminants have been made visible for type declarations and
12827 -- protected type declarations, not for subtype declarations.
12829 if Nkind (Parent (E)) /= N_Subtype_Declaration then
12830 Disc := First_Discriminant (E);
12831 while Present (Disc) loop
12832 if Disc /= Current_Entity (Disc) then
12833 Prev := Current_Entity (Disc);
12834 while Present (Prev)
12835 and then Present (Homonym (Prev))
12836 and then Homonym (Prev) /= Disc
12838 Prev := Homonym (Prev);
12844 Set_Is_Immediately_Visible (Disc, False);
12846 Outer := Homonym (Disc);
12847 while Present (Outer) and then Scope (Outer) = E loop
12848 Outer := Homonym (Outer);
12851 -- Reset homonym link of other entities, but do not modify link
12852 -- between entities in current scope, so that the back-end can
12853 -- have a proper count of local overloadings.
12856 Set_Name_Entity_Id (Chars (Disc), Outer);
12858 elsif Scope (Prev) /= Scope (Disc) then
12859 Set_Homonym (Prev, Outer);
12862 Next_Discriminant (Disc);
12865 end Uninstall_Discriminants;
12867 -------------------------------------------
12868 -- Uninstall_Discriminants_And_Pop_Scope --
12869 -------------------------------------------
12871 procedure Uninstall_Discriminants_And_Pop_Scope (E : Entity_Id) is
12873 if Has_Discriminants (E) then
12874 Uninstall_Discriminants (E);
12877 end Uninstall_Discriminants_And_Pop_Scope;
12879 ------------------------------
12880 -- Validate_Address_Clauses --
12881 ------------------------------
12883 procedure Validate_Address_Clauses is
12885 for J in Address_Clause_Checks.First .. Address_Clause_Checks.Last loop
12887 ACCR : Address_Clause_Check_Record
12888 renames Address_Clause_Checks.Table (J);
12892 X_Alignment : Uint;
12893 Y_Alignment : Uint;
12899 -- Skip processing of this entry if warning already posted
12901 if not Address_Warning_Posted (ACCR.N) then
12902 Expr := Original_Node (Expression (ACCR.N));
12906 X_Alignment := Alignment (ACCR.X);
12907 Y_Alignment := Alignment (ACCR.Y);
12909 -- Similarly obtain sizes
12911 X_Size := Esize (ACCR.X);
12912 Y_Size := Esize (ACCR.Y);
12914 -- Check for large object overlaying smaller one
12917 and then X_Size > Uint_0
12918 and then X_Size > Y_Size
12921 ("??& overlays smaller object", ACCR.N, ACCR.X);
12923 ("\??program execution may be erroneous", ACCR.N);
12924 Error_Msg_Uint_1 := X_Size;
12926 ("\??size of & is ^", ACCR.N, ACCR.X);
12927 Error_Msg_Uint_1 := Y_Size;
12929 ("\??size of & is ^", ACCR.N, ACCR.Y);
12931 -- Check for inadequate alignment, both of the base object
12932 -- and of the offset, if any. We only do this check if the
12933 -- run-time Alignment_Check is active. No point in warning
12934 -- if this check has been suppressed (or is suppressed by
12935 -- default in the non-strict alignment machine case).
12937 -- Note: we do not check the alignment if we gave a size
12938 -- warning, since it would likely be redundant.
12940 elsif not Alignment_Checks_Suppressed (ACCR.Y)
12941 and then Y_Alignment /= Uint_0
12942 and then (Y_Alignment < X_Alignment
12945 Nkind (Expr) = N_Attribute_Reference
12947 Attribute_Name (Expr) = Name_Address
12949 Has_Compatible_Alignment
12950 (ACCR.X, Prefix (Expr))
12951 /= Known_Compatible))
12954 ("??specified address for& may be inconsistent "
12955 & "with alignment", ACCR.N, ACCR.X);
12957 ("\??program execution may be erroneous (RM 13.3(27))",
12959 Error_Msg_Uint_1 := X_Alignment;
12961 ("\??alignment of & is ^", ACCR.N, ACCR.X);
12962 Error_Msg_Uint_1 := Y_Alignment;
12964 ("\??alignment of & is ^", ACCR.N, ACCR.Y);
12965 if Y_Alignment >= X_Alignment then
12967 ("\??but offset is not multiple of alignment", ACCR.N);
12973 end Validate_Address_Clauses;
12975 ---------------------------
12976 -- Validate_Independence --
12977 ---------------------------
12979 procedure Validate_Independence is
12980 SU : constant Uint := UI_From_Int (System_Storage_Unit);
12988 procedure Check_Array_Type (Atyp : Entity_Id);
12989 -- Checks if the array type Atyp has independent components, and
12990 -- if not, outputs an appropriate set of error messages.
12992 procedure No_Independence;
12993 -- Output message that independence cannot be guaranteed
12995 function OK_Component (C : Entity_Id) return Boolean;
12996 -- Checks one component to see if it is independently accessible, and
12997 -- if so yields True, otherwise yields False if independent access
12998 -- cannot be guaranteed. This is a conservative routine, it only
12999 -- returns True if it knows for sure, it returns False if it knows
13000 -- there is a problem, or it cannot be sure there is no problem.
13002 procedure Reason_Bad_Component (C : Entity_Id);
13003 -- Outputs continuation message if a reason can be determined for
13004 -- the component C being bad.
13006 ----------------------
13007 -- Check_Array_Type --
13008 ----------------------
13010 procedure Check_Array_Type (Atyp : Entity_Id) is
13011 Ctyp : constant Entity_Id := Component_Type (Atyp);
13014 -- OK if no alignment clause, no pack, and no component size
13016 if not Has_Component_Size_Clause (Atyp)
13017 and then not Has_Alignment_Clause (Atyp)
13018 and then not Is_Packed (Atyp)
13023 -- Case of component size is greater than or equal to 64 and the
13024 -- alignment of the array is at least as large as the alignment
13025 -- of the component. We are definitely OK in this situation.
13027 if Known_Component_Size (Atyp)
13028 and then Component_Size (Atyp) >= 64
13029 and then Known_Alignment (Atyp)
13030 and then Known_Alignment (Ctyp)
13031 and then Alignment (Atyp) >= Alignment (Ctyp)
13036 -- Check actual component size
13038 if not Known_Component_Size (Atyp)
13039 or else not (Addressable (Component_Size (Atyp))
13040 and then Component_Size (Atyp) < 64)
13041 or else Component_Size (Atyp) mod Esize (Ctyp) /= 0
13045 -- Bad component size, check reason
13047 if Has_Component_Size_Clause (Atyp) then
13048 P := Get_Attribute_Definition_Clause
13049 (Atyp, Attribute_Component_Size);
13051 if Present (P) then
13052 Error_Msg_Sloc := Sloc (P);
13053 Error_Msg_N ("\because of Component_Size clause#", N);
13058 if Is_Packed (Atyp) then
13059 P := Get_Rep_Pragma (Atyp, Name_Pack);
13061 if Present (P) then
13062 Error_Msg_Sloc := Sloc (P);
13063 Error_Msg_N ("\because of pragma Pack#", N);
13068 -- No reason found, just return
13073 -- Array type is OK independence-wise
13076 end Check_Array_Type;
13078 ---------------------
13079 -- No_Independence --
13080 ---------------------
13082 procedure No_Independence is
13084 if Pragma_Name (N) = Name_Independent then
13085 Error_Msg_NE ("independence cannot be guaranteed for&", N, E);
13088 ("independent components cannot be guaranteed for&", N, E);
13090 end No_Independence;
13096 function OK_Component (C : Entity_Id) return Boolean is
13097 Rec : constant Entity_Id := Scope (C);
13098 Ctyp : constant Entity_Id := Etype (C);
13101 -- OK if no component clause, no Pack, and no alignment clause
13103 if No (Component_Clause (C))
13104 and then not Is_Packed (Rec)
13105 and then not Has_Alignment_Clause (Rec)
13110 -- Here we look at the actual component layout. A component is
13111 -- addressable if its size is a multiple of the Esize of the
13112 -- component type, and its starting position in the record has
13113 -- appropriate alignment, and the record itself has appropriate
13114 -- alignment to guarantee the component alignment.
13116 -- Make sure sizes are static, always assume the worst for any
13117 -- cases where we cannot check static values.
13119 if not (Known_Static_Esize (C)
13121 Known_Static_Esize (Ctyp))
13126 -- Size of component must be addressable or greater than 64 bits
13127 -- and a multiple of bytes.
13129 if not Addressable (Esize (C)) and then Esize (C) < Uint_64 then
13133 -- Check size is proper multiple
13135 if Esize (C) mod Esize (Ctyp) /= 0 then
13139 -- Check alignment of component is OK
13141 if not Known_Component_Bit_Offset (C)
13142 or else Component_Bit_Offset (C) < Uint_0
13143 or else Component_Bit_Offset (C) mod Esize (Ctyp) /= 0
13148 -- Check alignment of record type is OK
13150 if not Known_Alignment (Rec)
13151 or else (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0
13156 -- All tests passed, component is addressable
13161 --------------------------
13162 -- Reason_Bad_Component --
13163 --------------------------
13165 procedure Reason_Bad_Component (C : Entity_Id) is
13166 Rec : constant Entity_Id := Scope (C);
13167 Ctyp : constant Entity_Id := Etype (C);
13170 -- If component clause present assume that's the problem
13172 if Present (Component_Clause (C)) then
13173 Error_Msg_Sloc := Sloc (Component_Clause (C));
13174 Error_Msg_N ("\because of Component_Clause#", N);
13178 -- If pragma Pack clause present, assume that's the problem
13180 if Is_Packed (Rec) then
13181 P := Get_Rep_Pragma (Rec, Name_Pack);
13183 if Present (P) then
13184 Error_Msg_Sloc := Sloc (P);
13185 Error_Msg_N ("\because of pragma Pack#", N);
13190 -- See if record has bad alignment clause
13192 if Has_Alignment_Clause (Rec)
13193 and then Known_Alignment (Rec)
13194 and then (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0
13196 P := Get_Attribute_Definition_Clause (Rec, Attribute_Alignment);
13198 if Present (P) then
13199 Error_Msg_Sloc := Sloc (P);
13200 Error_Msg_N ("\because of Alignment clause#", N);
13204 -- Couldn't find a reason, so return without a message
13207 end Reason_Bad_Component;
13209 -- Start of processing for Validate_Independence
13212 for J in Independence_Checks.First .. Independence_Checks.Last loop
13213 N := Independence_Checks.Table (J).N;
13214 E := Independence_Checks.Table (J).E;
13215 IC := Pragma_Name (N) = Name_Independent_Components;
13217 -- Deal with component case
13219 if Ekind (E) = E_Discriminant or else Ekind (E) = E_Component then
13220 if not OK_Component (E) then
13222 Reason_Bad_Component (E);
13227 -- Deal with record with Independent_Components
13229 if IC and then Is_Record_Type (E) then
13230 Comp := First_Component_Or_Discriminant (E);
13231 while Present (Comp) loop
13232 if not OK_Component (Comp) then
13234 Reason_Bad_Component (Comp);
13238 Next_Component_Or_Discriminant (Comp);
13242 -- Deal with address clause case
13244 if Is_Object (E) then
13245 Addr := Address_Clause (E);
13247 if Present (Addr) then
13249 Error_Msg_Sloc := Sloc (Addr);
13250 Error_Msg_N ("\because of Address clause#", N);
13255 -- Deal with independent components for array type
13257 if IC and then Is_Array_Type (E) then
13258 Check_Array_Type (E);
13261 -- Deal with independent components for array object
13263 if IC and then Is_Object (E) and then Is_Array_Type (Etype (E)) then
13264 Check_Array_Type (Etype (E));
13269 end Validate_Independence;
13271 ------------------------------
13272 -- Validate_Iterable_Aspect --
13273 ------------------------------
13275 procedure Validate_Iterable_Aspect (Typ : Entity_Id; ASN : Node_Id) is
13280 Cursor : constant Entity_Id := Get_Cursor_Type (ASN, Typ);
13282 First_Id : Entity_Id;
13283 Next_Id : Entity_Id;
13284 Has_Element_Id : Entity_Id;
13285 Element_Id : Entity_Id;
13288 -- If previous error aspect is unusable
13290 if Cursor = Any_Type then
13296 Has_Element_Id := Empty;
13297 Element_Id := Empty;
13299 -- Each expression must resolve to a function with the proper signature
13301 Assoc := First (Component_Associations (Expression (ASN)));
13302 while Present (Assoc) loop
13303 Expr := Expression (Assoc);
13306 Prim := First (Choices (Assoc));
13308 if Nkind (Prim) /= N_Identifier or else Present (Next (Prim)) then
13309 Error_Msg_N ("illegal name in association", Prim);
13311 elsif Chars (Prim) = Name_First then
13312 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_First);
13313 First_Id := Entity (Expr);
13315 elsif Chars (Prim) = Name_Next then
13316 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Next);
13317 Next_Id := Entity (Expr);
13319 elsif Chars (Prim) = Name_Has_Element then
13320 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Has_Element);
13321 Has_Element_Id := Entity (Expr);
13323 elsif Chars (Prim) = Name_Element then
13324 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Element);
13325 Element_Id := Entity (Expr);
13328 Error_Msg_N ("invalid name for iterable function", Prim);
13334 if No (First_Id) then
13335 Error_Msg_N ("match for First primitive not found", ASN);
13337 elsif No (Next_Id) then
13338 Error_Msg_N ("match for Next primitive not found", ASN);
13340 elsif No (Has_Element_Id) then
13341 Error_Msg_N ("match for Has_Element primitive not found", ASN);
13343 elsif No (Element_Id) then
13346 end Validate_Iterable_Aspect;
13348 -----------------------------------
13349 -- Validate_Unchecked_Conversion --
13350 -----------------------------------
13352 procedure Validate_Unchecked_Conversion
13354 Act_Unit : Entity_Id)
13356 Source : Entity_Id;
13357 Target : Entity_Id;
13361 -- Obtain source and target types. Note that we call Ancestor_Subtype
13362 -- here because the processing for generic instantiation always makes
13363 -- subtypes, and we want the original frozen actual types.
13365 -- If we are dealing with private types, then do the check on their
13366 -- fully declared counterparts if the full declarations have been
13367 -- encountered (they don't have to be visible, but they must exist).
13369 Source := Ancestor_Subtype (Etype (First_Formal (Act_Unit)));
13371 if Is_Private_Type (Source)
13372 and then Present (Underlying_Type (Source))
13374 Source := Underlying_Type (Source);
13377 Target := Ancestor_Subtype (Etype (Act_Unit));
13379 -- If either type is generic, the instantiation happens within a generic
13380 -- unit, and there is nothing to check. The proper check will happen
13381 -- when the enclosing generic is instantiated.
13383 if Is_Generic_Type (Source) or else Is_Generic_Type (Target) then
13387 if Is_Private_Type (Target)
13388 and then Present (Underlying_Type (Target))
13390 Target := Underlying_Type (Target);
13393 -- Source may be unconstrained array, but not target
13395 if Is_Array_Type (Target) and then not Is_Constrained (Target) then
13397 ("unchecked conversion to unconstrained array not allowed", N);
13401 -- Warn if conversion between two different convention pointers
13403 if Is_Access_Type (Target)
13404 and then Is_Access_Type (Source)
13405 and then Convention (Target) /= Convention (Source)
13406 and then Warn_On_Unchecked_Conversion
13408 -- Give warnings for subprogram pointers only on most targets
13410 if Is_Access_Subprogram_Type (Target)
13411 or else Is_Access_Subprogram_Type (Source)
13414 ("?z?conversion between pointers with different conventions!",
13419 -- Warn if one of the operands is Ada.Calendar.Time. Do not emit a
13420 -- warning when compiling GNAT-related sources.
13422 if Warn_On_Unchecked_Conversion
13423 and then not In_Predefined_Unit (N)
13424 and then RTU_Loaded (Ada_Calendar)
13425 and then (Chars (Source) = Name_Time
13427 Chars (Target) = Name_Time)
13429 -- If Ada.Calendar is loaded and the name of one of the operands is
13430 -- Time, there is a good chance that this is Ada.Calendar.Time.
13433 Calendar_Time : constant Entity_Id := Full_View (RTE (RO_CA_Time));
13435 pragma Assert (Present (Calendar_Time));
13437 if Source = Calendar_Time or else Target = Calendar_Time then
13439 ("?z?representation of 'Time values may change between "
13440 & "'G'N'A'T versions", N);
13445 -- Make entry in unchecked conversion table for later processing by
13446 -- Validate_Unchecked_Conversions, which will check sizes and alignments
13447 -- (using values set by the back-end where possible). This is only done
13448 -- if the appropriate warning is active.
13450 if Warn_On_Unchecked_Conversion then
13451 Unchecked_Conversions.Append
13452 (New_Val => UC_Entry'(Eloc => Sloc (N),
13455 Act_Unit => Act_Unit));
13457 -- If both sizes are known statically now, then back end annotation
13458 -- is not required to do a proper check but if either size is not
13459 -- known statically, then we need the annotation.
13461 if Known_Static_RM_Size (Source)
13463 Known_Static_RM_Size (Target)
13467 Back_Annotate_Rep_Info := True;
13471 -- If unchecked conversion to access type, and access type is declared
13472 -- in the same unit as the unchecked conversion, then set the flag
13473 -- No_Strict_Aliasing (no strict aliasing is implicit here)
13475 if Is_Access_Type (Target) and then
13476 In_Same_Source_Unit (Target, N)
13478 Set_No_Strict_Aliasing (Implementation_Base_Type (Target));
13481 -- Generate N_Validate_Unchecked_Conversion node for back end in case
13482 -- the back end needs to perform special validation checks.
13484 -- Shouldn't this be in Exp_Ch13, since the check only gets done if we
13485 -- have full expansion and the back end is called ???
13488 Make_Validate_Unchecked_Conversion (Sloc (N));
13489 Set_Source_Type (Vnode, Source);
13490 Set_Target_Type (Vnode, Target);
13492 -- If the unchecked conversion node is in a list, just insert before it.
13493 -- If not we have some strange case, not worth bothering about.
13495 if Is_List_Member (N) then
13496 Insert_After (N, Vnode);
13498 end Validate_Unchecked_Conversion;
13500 ------------------------------------
13501 -- Validate_Unchecked_Conversions --
13502 ------------------------------------
13504 procedure Validate_Unchecked_Conversions is
13506 for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop
13508 T : UC_Entry renames Unchecked_Conversions.Table (N);
13510 Eloc : constant Source_Ptr := T.Eloc;
13511 Source : constant Entity_Id := T.Source;
13512 Target : constant Entity_Id := T.Target;
13513 Act_Unit : constant Entity_Id := T.Act_Unit;
13519 -- Skip if function marked as warnings off
13521 if Warnings_Off (Act_Unit) then
13525 -- This validation check, which warns if we have unequal sizes for
13526 -- unchecked conversion, and thus potentially implementation
13527 -- dependent semantics, is one of the few occasions on which we
13528 -- use the official RM size instead of Esize. See description in
13529 -- Einfo "Handling of Type'Size Values" for details.
13531 if Serious_Errors_Detected = 0
13532 and then Known_Static_RM_Size (Source)
13533 and then Known_Static_RM_Size (Target)
13535 -- Don't do the check if warnings off for either type, note the
13536 -- deliberate use of OR here instead of OR ELSE to get the flag
13537 -- Warnings_Off_Used set for both types if appropriate.
13539 and then not (Has_Warnings_Off (Source)
13541 Has_Warnings_Off (Target))
13543 Source_Siz := RM_Size (Source);
13544 Target_Siz := RM_Size (Target);
13546 if Source_Siz /= Target_Siz then
13548 ("?z?types for unchecked conversion have different sizes!",
13551 if All_Errors_Mode then
13552 Error_Msg_Name_1 := Chars (Source);
13553 Error_Msg_Uint_1 := Source_Siz;
13554 Error_Msg_Name_2 := Chars (Target);
13555 Error_Msg_Uint_2 := Target_Siz;
13556 Error_Msg ("\size of % is ^, size of % is ^?z?", Eloc);
13558 Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz);
13560 if Is_Discrete_Type (Source)
13562 Is_Discrete_Type (Target)
13564 if Source_Siz > Target_Siz then
13566 ("\?z?^ high order bits of source will "
13567 & "be ignored!", Eloc);
13569 elsif Is_Unsigned_Type (Source) then
13571 ("\?z?source will be extended with ^ high order "
13572 & "zero bits!", Eloc);
13576 ("\?z?source will be extended with ^ high order "
13577 & "sign bits!", Eloc);
13580 elsif Source_Siz < Target_Siz then
13581 if Is_Discrete_Type (Target) then
13582 if Bytes_Big_Endian then
13584 ("\?z?target value will include ^ undefined "
13585 & "low order bits!", Eloc);
13588 ("\?z?target value will include ^ undefined "
13589 & "high order bits!", Eloc);
13594 ("\?z?^ trailing bits of target value will be "
13595 & "undefined!", Eloc);
13598 else pragma Assert (Source_Siz > Target_Siz);
13599 if Is_Discrete_Type (Source) then
13600 if Bytes_Big_Endian then
13602 ("\?z?^ low order bits of source will be "
13603 & "ignored!", Eloc);
13606 ("\?z?^ high order bits of source will be "
13607 & "ignored!", Eloc);
13612 ("\?z?^ trailing bits of source will be "
13613 & "ignored!", Eloc);
13620 -- If both types are access types, we need to check the alignment.
13621 -- If the alignment of both is specified, we can do it here.
13623 if Serious_Errors_Detected = 0
13624 and then Is_Access_Type (Source)
13625 and then Is_Access_Type (Target)
13626 and then Target_Strict_Alignment
13627 and then Present (Designated_Type (Source))
13628 and then Present (Designated_Type (Target))
13631 D_Source : constant Entity_Id := Designated_Type (Source);
13632 D_Target : constant Entity_Id := Designated_Type (Target);
13635 if Known_Alignment (D_Source)
13637 Known_Alignment (D_Target)
13640 Source_Align : constant Uint := Alignment (D_Source);
13641 Target_Align : constant Uint := Alignment (D_Target);
13644 if Source_Align < Target_Align
13645 and then not Is_Tagged_Type (D_Source)
13647 -- Suppress warning if warnings suppressed on either
13648 -- type or either designated type. Note the use of
13649 -- OR here instead of OR ELSE. That is intentional,
13650 -- we would like to set flag Warnings_Off_Used in
13651 -- all types for which warnings are suppressed.
13653 and then not (Has_Warnings_Off (D_Source)
13655 Has_Warnings_Off (D_Target)
13657 Has_Warnings_Off (Source)
13659 Has_Warnings_Off (Target))
13661 Error_Msg_Uint_1 := Target_Align;
13662 Error_Msg_Uint_2 := Source_Align;
13663 Error_Msg_Node_1 := D_Target;
13664 Error_Msg_Node_2 := D_Source;
13666 ("?z?alignment of & (^) is stricter than "
13667 & "alignment of & (^)!", Eloc);
13669 ("\?z?resulting access value may have invalid "
13670 & "alignment!", Eloc);
13681 end Validate_Unchecked_Conversions;