1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2013, 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 Einfo; use Einfo;
30 with Elists; use Elists;
31 with Errout; use Errout;
32 with Exp_Disp; use Exp_Disp;
33 with Exp_Tss; use Exp_Tss;
34 with Exp_Util; use Exp_Util;
36 with Lib.Xref; use Lib.Xref;
37 with Namet; use Namet;
38 with Nlists; use Nlists;
39 with Nmake; use Nmake;
41 with Restrict; use Restrict;
42 with Rident; use Rident;
43 with Rtsfind; use Rtsfind;
45 with Sem_Aux; use Sem_Aux;
46 with Sem_Ch3; use Sem_Ch3;
47 with Sem_Ch6; use Sem_Ch6;
48 with Sem_Ch8; use Sem_Ch8;
49 with Sem_Ch9; use Sem_Ch9;
50 with Sem_Dim; use Sem_Dim;
51 with Sem_Disp; use Sem_Disp;
52 with Sem_Eval; use Sem_Eval;
53 with Sem_Res; use Sem_Res;
54 with Sem_Type; use Sem_Type;
55 with Sem_Util; use Sem_Util;
56 with Sem_Warn; use Sem_Warn;
57 with Sinput; use Sinput;
58 with Snames; use Snames;
59 with Stand; use Stand;
60 with Sinfo; use Sinfo;
61 with Stringt; use Stringt;
62 with Targparm; use Targparm;
63 with Ttypes; use Ttypes;
64 with Tbuild; use Tbuild;
65 with Urealp; use Urealp;
66 with Warnsw; use Warnsw;
68 with GNAT.Heap_Sort_G;
70 package body Sem_Ch13 is
72 SSU : constant Pos := System_Storage_Unit;
73 -- Convenient short hand for commonly used constant
75 -----------------------
76 -- Local Subprograms --
77 -----------------------
79 procedure Alignment_Check_For_Size_Change (Typ : Entity_Id; Size : Uint);
80 -- This routine is called after setting one of the sizes of type entity
81 -- Typ to Size. The purpose is to deal with the situation of a derived
82 -- type whose inherited alignment is no longer appropriate for the new
83 -- size value. In this case, we reset the Alignment to unknown.
85 procedure Build_Predicate_Functions (Typ : Entity_Id; N : Node_Id);
86 -- If Typ has predicates (indicated by Has_Predicates being set for Typ,
87 -- then either there are pragma Predicate entries on the rep chain for the
88 -- type (note that Predicate aspects are converted to pragma Predicate), or
89 -- there are inherited aspects from a parent type, or ancestor subtypes.
90 -- This procedure builds the spec and body for the Predicate function that
91 -- tests these predicates. N is the freeze node for the type. The spec of
92 -- the function is inserted before the freeze node, and the body of the
93 -- function is inserted after the freeze node. If the predicate expression
94 -- has at least one Raise_Expression, then this procedure also builds the
95 -- M version of the predicate function for ue in membership tests.
97 procedure Build_Static_Predicate
101 -- Given a predicated type Typ, where Typ is a discrete static subtype,
102 -- whose predicate expression is Expr, tests if Expr is a static predicate,
103 -- and if so, builds the predicate range list. Nam is the name of the one
104 -- argument to the predicate function. Occurrences of the type name in the
105 -- predicate expression have been replaced by identifier references to this
106 -- name, which is unique, so any identifier with Chars matching Nam must be
107 -- a reference to the type. If the predicate is non-static, this procedure
108 -- returns doing nothing. If the predicate is static, then the predicate
109 -- list is stored in Static_Predicate (Typ), and the Expr is rewritten as
110 -- a canonicalized membership operation.
112 function Get_Alignment_Value (Expr : Node_Id) return Uint;
113 -- Given the expression for an alignment value, returns the corresponding
114 -- Uint value. If the value is inappropriate, then error messages are
115 -- posted as required, and a value of No_Uint is returned.
117 function Is_Operational_Item (N : Node_Id) return Boolean;
118 -- A specification for a stream attribute is allowed before the full type
119 -- is declared, as explained in AI-00137 and the corrigendum. Attributes
120 -- that do not specify a representation characteristic are operational
123 procedure New_Stream_Subprogram
127 Nam : TSS_Name_Type);
128 -- Create a subprogram renaming of a given stream attribute to the
129 -- designated subprogram and then in the tagged case, provide this as a
130 -- primitive operation, or in the non-tagged case make an appropriate TSS
131 -- entry. This is more properly an expansion activity than just semantics,
132 -- but the presence of user-defined stream functions for limited types is a
133 -- legality check, which is why this takes place here rather than in
134 -- exp_ch13, where it was previously. Nam indicates the name of the TSS
135 -- function to be generated.
137 -- To avoid elaboration anomalies with freeze nodes, for untagged types
138 -- we generate both a subprogram declaration and a subprogram renaming
139 -- declaration, so that the attribute specification is handled as a
140 -- renaming_as_body. For tagged types, the specification is one of the
144 with procedure Replace_Type_Reference (N : Node_Id);
145 procedure Replace_Type_References_Generic (N : Node_Id; TName : Name_Id);
146 -- This is used to scan an expression for a predicate or invariant aspect
147 -- replacing occurrences of the name TName (the name of the subtype to
148 -- which the aspect applies) with appropriate references to the parameter
149 -- of the predicate function or invariant procedure. The procedure passed
150 -- as a generic parameter does the actual replacement of node N, which is
151 -- either a simple direct reference to TName, or a selected component that
152 -- represents an appropriately qualified occurrence of TName.
158 Biased : Boolean := True);
159 -- If Biased is True, sets Has_Biased_Representation flag for E, and
160 -- outputs a warning message at node N if Warn_On_Biased_Representation is
161 -- is True. This warning inserts the string Msg to describe the construct
164 ----------------------------------------------
165 -- Table for Validate_Unchecked_Conversions --
166 ----------------------------------------------
168 -- The following table collects unchecked conversions for validation.
169 -- Entries are made by Validate_Unchecked_Conversion and then the call
170 -- to Validate_Unchecked_Conversions does the actual error checking and
171 -- posting of warnings. The reason for this delayed processing is to take
172 -- advantage of back-annotations of size and alignment values performed by
175 -- Note: the reason we store a Source_Ptr value instead of a Node_Id is
176 -- that by the time Validate_Unchecked_Conversions is called, Sprint will
177 -- already have modified all Sloc values if the -gnatD option is set.
179 type UC_Entry is record
180 Eloc : Source_Ptr; -- node used for posting warnings
181 Source : Entity_Id; -- source type for unchecked conversion
182 Target : Entity_Id; -- target type for unchecked conversion
185 package Unchecked_Conversions is new Table.Table (
186 Table_Component_Type => UC_Entry,
187 Table_Index_Type => Int,
188 Table_Low_Bound => 1,
190 Table_Increment => 200,
191 Table_Name => "Unchecked_Conversions");
193 ----------------------------------------
194 -- Table for Validate_Address_Clauses --
195 ----------------------------------------
197 -- If an address clause has the form
199 -- for X'Address use Expr
201 -- where Expr is of the form Y'Address or recursively is a reference to a
202 -- constant of either of these forms, and X and Y are entities of objects,
203 -- then if Y has a smaller alignment than X, that merits a warning about
204 -- possible bad alignment. The following table collects address clauses of
205 -- this kind. We put these in a table so that they can be checked after the
206 -- back end has completed annotation of the alignments of objects, since we
207 -- can catch more cases that way.
209 type Address_Clause_Check_Record is record
211 -- The address clause
214 -- The entity of the object overlaying Y
217 -- The entity of the object being overlaid
220 -- Whether the address is offset within Y
223 package Address_Clause_Checks is new Table.Table (
224 Table_Component_Type => Address_Clause_Check_Record,
225 Table_Index_Type => Int,
226 Table_Low_Bound => 1,
228 Table_Increment => 200,
229 Table_Name => "Address_Clause_Checks");
231 -----------------------------------------
232 -- Adjust_Record_For_Reverse_Bit_Order --
233 -----------------------------------------
235 procedure Adjust_Record_For_Reverse_Bit_Order (R : Entity_Id) is
240 -- Processing depends on version of Ada
242 -- For Ada 95, we just renumber bits within a storage unit. We do the
243 -- same for Ada 83 mode, since we recognize the Bit_Order attribute in
244 -- Ada 83, and are free to add this extension.
246 if Ada_Version < Ada_2005 then
247 Comp := First_Component_Or_Discriminant (R);
248 while Present (Comp) loop
249 CC := Component_Clause (Comp);
251 -- If component clause is present, then deal with the non-default
252 -- bit order case for Ada 95 mode.
254 -- We only do this processing for the base type, and in fact that
255 -- is important, since otherwise if there are record subtypes, we
256 -- could reverse the bits once for each subtype, which is wrong.
258 if Present (CC) and then Ekind (R) = E_Record_Type then
260 CFB : constant Uint := Component_Bit_Offset (Comp);
261 CSZ : constant Uint := Esize (Comp);
262 CLC : constant Node_Id := Component_Clause (Comp);
263 Pos : constant Node_Id := Position (CLC);
264 FB : constant Node_Id := First_Bit (CLC);
266 Storage_Unit_Offset : constant Uint :=
267 CFB / System_Storage_Unit;
269 Start_Bit : constant Uint :=
270 CFB mod System_Storage_Unit;
273 -- Cases where field goes over storage unit boundary
275 if Start_Bit + CSZ > System_Storage_Unit then
277 -- Allow multi-byte field but generate warning
279 if Start_Bit mod System_Storage_Unit = 0
280 and then CSZ mod System_Storage_Unit = 0
283 ("multi-byte field specified with non-standard"
284 & " Bit_Order??", CLC);
286 if Bytes_Big_Endian then
288 ("bytes are not reversed "
289 & "(component is big-endian)??", CLC);
292 ("bytes are not reversed "
293 & "(component is little-endian)??", CLC);
296 -- Do not allow non-contiguous field
300 ("attempt to specify non-contiguous field "
301 & "not permitted", CLC);
303 ("\caused by non-standard Bit_Order "
306 ("\consider possibility of using "
307 & "Ada 2005 mode here", CLC);
310 -- Case where field fits in one storage unit
313 -- Give warning if suspicious component clause
315 if Intval (FB) >= System_Storage_Unit
316 and then Warn_On_Reverse_Bit_Order
319 ("Bit_Order clause does not affect " &
320 "byte ordering?V?", Pos);
322 Intval (Pos) + Intval (FB) /
325 ("position normalized to ^ before bit " &
326 "order interpreted?V?", Pos);
329 -- Here is where we fix up the Component_Bit_Offset value
330 -- to account for the reverse bit order. Some examples of
331 -- what needs to be done are:
333 -- First_Bit .. Last_Bit Component_Bit_Offset
345 -- The rule is that the first bit is is obtained by
346 -- subtracting the old ending bit from storage_unit - 1.
348 Set_Component_Bit_Offset
350 (Storage_Unit_Offset * System_Storage_Unit) +
351 (System_Storage_Unit - 1) -
352 (Start_Bit + CSZ - 1));
354 Set_Normalized_First_Bit
356 Component_Bit_Offset (Comp) mod
357 System_Storage_Unit);
362 Next_Component_Or_Discriminant (Comp);
365 -- For Ada 2005, we do machine scalar processing, as fully described In
366 -- AI-133. This involves gathering all components which start at the
367 -- same byte offset and processing them together. Same approach is still
368 -- valid in later versions including Ada 2012.
372 Max_Machine_Scalar_Size : constant Uint :=
374 (Standard_Long_Long_Integer_Size);
375 -- We use this as the maximum machine scalar size
378 SSU : constant Uint := UI_From_Int (System_Storage_Unit);
381 -- This first loop through components does two things. First it
382 -- deals with the case of components with component clauses whose
383 -- length is greater than the maximum machine scalar size (either
384 -- accepting them or rejecting as needed). Second, it counts the
385 -- number of components with component clauses whose length does
386 -- not exceed this maximum for later processing.
389 Comp := First_Component_Or_Discriminant (R);
390 while Present (Comp) loop
391 CC := Component_Clause (Comp);
395 Fbit : constant Uint := Static_Integer (First_Bit (CC));
396 Lbit : constant Uint := Static_Integer (Last_Bit (CC));
399 -- Case of component with last bit >= max machine scalar
401 if Lbit >= Max_Machine_Scalar_Size then
403 -- This is allowed only if first bit is zero, and
404 -- last bit + 1 is a multiple of storage unit size.
406 if Fbit = 0 and then (Lbit + 1) mod SSU = 0 then
408 -- This is the case to give a warning if enabled
410 if Warn_On_Reverse_Bit_Order then
412 ("multi-byte field specified with "
413 & " non-standard Bit_Order?V?", CC);
415 if Bytes_Big_Endian then
417 ("\bytes are not reversed "
418 & "(component is big-endian)?V?", CC);
421 ("\bytes are not reversed "
422 & "(component is little-endian)?V?", CC);
426 -- Give error message for RM 13.5.1(10) violation
430 ("machine scalar rules not followed for&",
431 First_Bit (CC), Comp);
433 Error_Msg_Uint_1 := Lbit;
434 Error_Msg_Uint_2 := Max_Machine_Scalar_Size;
436 ("\last bit (^) exceeds maximum machine "
440 if (Lbit + 1) mod SSU /= 0 then
441 Error_Msg_Uint_1 := SSU;
443 ("\and is not a multiple of Storage_Unit (^) "
448 Error_Msg_Uint_1 := Fbit;
450 ("\and first bit (^) is non-zero "
456 -- OK case of machine scalar related component clause,
457 -- For now, just count them.
460 Num_CC := Num_CC + 1;
465 Next_Component_Or_Discriminant (Comp);
468 -- We need to sort the component clauses on the basis of the
469 -- Position values in the clause, so we can group clauses with
470 -- the same Position. together to determine the relevant machine
474 Comps : array (0 .. Num_CC) of Entity_Id;
475 -- Array to collect component and discriminant entities. The
476 -- data starts at index 1, the 0'th entry is for the sort
479 function CP_Lt (Op1, Op2 : Natural) return Boolean;
480 -- Compare routine for Sort
482 procedure CP_Move (From : Natural; To : Natural);
483 -- Move routine for Sort
485 package Sorting is new GNAT.Heap_Sort_G (CP_Move, CP_Lt);
489 -- Start and stop positions in the component list of the set of
490 -- components with the same starting position (that constitute
491 -- components in a single machine scalar).
494 -- Maximum last bit value of any component in this set
497 -- Corresponding machine scalar size
503 function CP_Lt (Op1, Op2 : Natural) return Boolean is
505 return Position (Component_Clause (Comps (Op1))) <
506 Position (Component_Clause (Comps (Op2)));
513 procedure CP_Move (From : Natural; To : Natural) is
515 Comps (To) := Comps (From);
518 -- Start of processing for Sort_CC
521 -- Collect the machine scalar relevant component clauses
524 Comp := First_Component_Or_Discriminant (R);
525 while Present (Comp) loop
527 CC : constant Node_Id := Component_Clause (Comp);
530 -- Collect only component clauses whose last bit is less
531 -- than machine scalar size. Any component clause whose
532 -- last bit exceeds this value does not take part in
533 -- machine scalar layout considerations. The test for
534 -- Error_Posted makes sure we exclude component clauses
535 -- for which we already posted an error.
538 and then not Error_Posted (Last_Bit (CC))
539 and then Static_Integer (Last_Bit (CC)) <
540 Max_Machine_Scalar_Size
542 Num_CC := Num_CC + 1;
543 Comps (Num_CC) := Comp;
547 Next_Component_Or_Discriminant (Comp);
550 -- Sort by ascending position number
552 Sorting.Sort (Num_CC);
554 -- We now have all the components whose size does not exceed
555 -- the max machine scalar value, sorted by starting position.
556 -- In this loop we gather groups of clauses starting at the
557 -- same position, to process them in accordance with AI-133.
560 while Stop < Num_CC loop
565 (Last_Bit (Component_Clause (Comps (Start))));
566 while Stop < Num_CC loop
568 (Position (Component_Clause (Comps (Stop + 1)))) =
570 (Position (Component_Clause (Comps (Stop))))
578 (Component_Clause (Comps (Stop)))));
584 -- Now we have a group of component clauses from Start to
585 -- Stop whose positions are identical, and MaxL is the
586 -- maximum last bit value of any of these components.
588 -- We need to determine the corresponding machine scalar
589 -- size. This loop assumes that machine scalar sizes are
590 -- even, and that each possible machine scalar has twice
591 -- as many bits as the next smaller one.
593 MSS := Max_Machine_Scalar_Size;
595 and then (MSS / 2) >= SSU
596 and then (MSS / 2) > MaxL
601 -- Here is where we fix up the Component_Bit_Offset value
602 -- to account for the reverse bit order. Some examples of
603 -- what needs to be done for the case of a machine scalar
606 -- First_Bit .. Last_Bit Component_Bit_Offset
618 -- The rule is that the first bit is obtained by subtracting
619 -- the old ending bit from machine scalar size - 1.
621 for C in Start .. Stop loop
623 Comp : constant Entity_Id := Comps (C);
624 CC : constant Node_Id := Component_Clause (Comp);
626 LB : constant Uint := Static_Integer (Last_Bit (CC));
627 NFB : constant Uint := MSS - Uint_1 - LB;
628 NLB : constant Uint := NFB + Esize (Comp) - 1;
629 Pos : constant Uint := Static_Integer (Position (CC));
632 if Warn_On_Reverse_Bit_Order then
633 Error_Msg_Uint_1 := MSS;
635 ("info: reverse bit order in machine " &
636 "scalar of length^?V?", First_Bit (CC));
637 Error_Msg_Uint_1 := NFB;
638 Error_Msg_Uint_2 := NLB;
640 if Bytes_Big_Endian then
642 ("\info: big-endian range for "
643 & "component & is ^ .. ^?V?",
644 First_Bit (CC), Comp);
647 ("\info: little-endian range "
648 & "for component & is ^ .. ^?V?",
649 First_Bit (CC), Comp);
653 Set_Component_Bit_Offset (Comp, Pos * SSU + NFB);
654 Set_Normalized_First_Bit (Comp, NFB mod SSU);
661 end Adjust_Record_For_Reverse_Bit_Order;
663 -------------------------------------
664 -- Alignment_Check_For_Size_Change --
665 -------------------------------------
667 procedure Alignment_Check_For_Size_Change (Typ : Entity_Id; Size : Uint) is
669 -- If the alignment is known, and not set by a rep clause, and is
670 -- inconsistent with the size being set, then reset it to unknown,
671 -- we assume in this case that the size overrides the inherited
672 -- alignment, and that the alignment must be recomputed.
674 if Known_Alignment (Typ)
675 and then not Has_Alignment_Clause (Typ)
676 and then Size mod (Alignment (Typ) * SSU) /= 0
678 Init_Alignment (Typ);
680 end Alignment_Check_For_Size_Change;
682 -------------------------------------
683 -- Analyze_Aspects_At_Freeze_Point --
684 -------------------------------------
686 procedure Analyze_Aspects_At_Freeze_Point (E : Entity_Id) is
691 procedure Analyze_Aspect_Default_Value (ASN : Node_Id);
692 -- This routine analyzes an Aspect_Default_[Component_]Value denoted by
693 -- the aspect specification node ASN.
695 procedure Make_Pragma_From_Boolean_Aspect (ASN : Node_Id);
696 -- Given an aspect specification node ASN whose expression is an
697 -- optional Boolean, this routines creates the corresponding pragma
698 -- at the freezing point.
700 ----------------------------------
701 -- Analyze_Aspect_Default_Value --
702 ----------------------------------
704 procedure Analyze_Aspect_Default_Value (ASN : Node_Id) is
705 Ent : constant Entity_Id := Entity (ASN);
706 Expr : constant Node_Id := Expression (ASN);
707 Id : constant Node_Id := Identifier (ASN);
710 Error_Msg_Name_1 := Chars (Id);
712 if not Is_Type (Ent) then
713 Error_Msg_N ("aspect% can only apply to a type", Id);
716 elsif not Is_First_Subtype (Ent) then
717 Error_Msg_N ("aspect% cannot apply to subtype", Id);
720 elsif A_Id = Aspect_Default_Value
721 and then not Is_Scalar_Type (Ent)
723 Error_Msg_N ("aspect% can only be applied to scalar type", Id);
726 elsif A_Id = Aspect_Default_Component_Value then
727 if not Is_Array_Type (Ent) then
728 Error_Msg_N ("aspect% can only be applied to array type", Id);
731 elsif not Is_Scalar_Type (Component_Type (Ent)) then
732 Error_Msg_N ("aspect% requires scalar components", Id);
737 Set_Has_Default_Aspect (Base_Type (Ent));
739 if Is_Scalar_Type (Ent) then
740 Set_Default_Aspect_Value (Ent, Expr);
742 -- Place default value of base type as well, because that is
743 -- the semantics of the aspect. It is convenient to link the
744 -- aspect to both the (possibly anonymous) base type and to
745 -- the given first subtype.
747 Set_Default_Aspect_Value (Base_Type (Ent), Expr);
750 Set_Default_Aspect_Component_Value (Ent, Expr);
752 end Analyze_Aspect_Default_Value;
754 -------------------------------------
755 -- Make_Pragma_From_Boolean_Aspect --
756 -------------------------------------
758 procedure Make_Pragma_From_Boolean_Aspect (ASN : Node_Id) is
759 Ident : constant Node_Id := Identifier (ASN);
760 A_Name : constant Name_Id := Chars (Ident);
761 A_Id : constant Aspect_Id := Get_Aspect_Id (A_Name);
762 Ent : constant Entity_Id := Entity (ASN);
763 Expr : constant Node_Id := Expression (ASN);
764 Loc : constant Source_Ptr := Sloc (ASN);
768 procedure Check_False_Aspect_For_Derived_Type;
769 -- This procedure checks for the case of a false aspect for a derived
770 -- type, which improperly tries to cancel an aspect inherited from
773 -----------------------------------------
774 -- Check_False_Aspect_For_Derived_Type --
775 -----------------------------------------
777 procedure Check_False_Aspect_For_Derived_Type is
781 -- We are only checking derived types
783 if not Is_Derived_Type (E) then
787 Par := Nearest_Ancestor (E);
790 when Aspect_Atomic | Aspect_Shared =>
791 if not Is_Atomic (Par) then
795 when Aspect_Atomic_Components =>
796 if not Has_Atomic_Components (Par) then
800 when Aspect_Discard_Names =>
801 if not Discard_Names (Par) then
806 if not Is_Packed (Par) then
810 when Aspect_Unchecked_Union =>
811 if not Is_Unchecked_Union (Par) then
815 when Aspect_Volatile =>
816 if not Is_Volatile (Par) then
820 when Aspect_Volatile_Components =>
821 if not Has_Volatile_Components (Par) then
829 -- Fall through means we are canceling an inherited aspect
831 Error_Msg_Name_1 := A_Name;
832 Error_Msg_NE ("derived type& inherits aspect%, cannot cancel",
836 end Check_False_Aspect_For_Derived_Type;
838 -- Start of processing for Make_Pragma_From_Boolean_Aspect
841 if Is_False (Static_Boolean (Expr)) then
842 Check_False_Aspect_For_Derived_Type;
847 Pragma_Argument_Associations => New_List (
848 Make_Pragma_Argument_Association (Sloc (Ident),
849 Expression => New_Occurrence_Of (Ent, Sloc (Ident)))),
852 Make_Identifier (Sloc (Ident), Chars (Ident)));
854 Set_From_Aspect_Specification (Prag, True);
855 Set_Corresponding_Aspect (Prag, ASN);
856 Set_Aspect_Rep_Item (ASN, Prag);
857 Set_Is_Delayed_Aspect (Prag);
858 Set_Parent (Prag, ASN);
860 end Make_Pragma_From_Boolean_Aspect;
862 -- Start of processing for Analyze_Aspects_At_Freeze_Point
865 -- Must be visible in current scope
867 if not Scope_Within_Or_Same (Current_Scope, Scope (E)) then
871 -- Look for aspect specification entries for this entity
873 ASN := First_Rep_Item (E);
874 while Present (ASN) loop
875 if Nkind (ASN) = N_Aspect_Specification
876 and then Entity (ASN) = E
877 and then Is_Delayed_Aspect (ASN)
879 A_Id := Get_Aspect_Id (Chars (Identifier (ASN)));
883 -- For aspects whose expression is an optional Boolean, make
884 -- the corresponding pragma at the freezing point.
886 when Boolean_Aspects |
887 Library_Unit_Aspects =>
888 Make_Pragma_From_Boolean_Aspect (ASN);
890 -- Special handling for aspects that don't correspond to
891 -- pragmas/attributes.
893 when Aspect_Default_Value |
894 Aspect_Default_Component_Value =>
895 Analyze_Aspect_Default_Value (ASN);
897 -- Ditto for iterator aspects, because the corresponding
898 -- attributes may not have been analyzed yet.
900 when Aspect_Constant_Indexing |
901 Aspect_Variable_Indexing |
902 Aspect_Default_Iterator |
903 Aspect_Iterator_Element =>
904 Analyze (Expression (ASN));
910 Ritem := Aspect_Rep_Item (ASN);
912 if Present (Ritem) then
919 end Analyze_Aspects_At_Freeze_Point;
921 -----------------------------------
922 -- Analyze_Aspect_Specifications --
923 -----------------------------------
925 procedure Analyze_Aspect_Specifications (N : Node_Id; E : Entity_Id) is
930 L : constant List_Id := Aspect_Specifications (N);
932 Ins_Node : Node_Id := N;
933 -- Insert pragmas/attribute definition clause after this node when no
934 -- delayed analysis is required.
936 -- The general processing involves building an attribute definition
937 -- clause or a pragma node that corresponds to the aspect. Then in order
938 -- to delay the evaluation of this aspect to the freeze point, we attach
939 -- the corresponding pragma/attribute definition clause to the aspect
940 -- specification node, which is then placed in the Rep Item chain. In
941 -- this case we mark the entity by setting the flag Has_Delayed_Aspects
942 -- and we evaluate the rep item at the freeze point. When the aspect
943 -- doesn't have a corresponding pragma/attribute definition clause, then
944 -- its analysis is simply delayed at the freeze point.
946 -- Some special cases don't require delay analysis, thus the aspect is
947 -- analyzed right now.
949 -- Note that there is a special handling for
950 -- Pre/Post/Test_Case/Contract_Case aspects. In this case, we do not
951 -- have to worry about delay issues, since the pragmas themselves deal
952 -- with delay of visibility for the expression analysis. Thus, we just
953 -- insert the pragma after the node N.
956 pragma Assert (Present (L));
958 -- Loop through aspects
961 Aspect_Loop : while Present (Aspect) loop
963 Expr : constant Node_Id := Expression (Aspect);
964 Id : constant Node_Id := Identifier (Aspect);
965 Loc : constant Source_Ptr := Sloc (Aspect);
966 Nam : constant Name_Id := Chars (Id);
967 A_Id : constant Aspect_Id := Get_Aspect_Id (Nam);
970 Delay_Required : Boolean := True;
971 -- Set False if delay is not required
973 Eloc : Source_Ptr := No_Location;
974 -- Source location of expression, modified when we split PPC's. It
975 -- is set below when Expr is present.
977 procedure Analyze_Aspect_External_Or_Link_Name;
978 -- This routine performs the analysis of the External_Name or
979 -- Link_Name aspects.
981 procedure Analyze_Aspect_Implicit_Dereference;
982 -- This routine performs the analysis of the Implicit_Dereference
985 ------------------------------------------
986 -- Analyze_Aspect_External_Or_Link_Name --
987 ------------------------------------------
989 procedure Analyze_Aspect_External_Or_Link_Name is
991 -- Verify that there is an Import/Export aspect defined for the
992 -- entity. The processing of that aspect in turn checks that
993 -- there is a Convention aspect declared. The pragma is
994 -- constructed when processing the Convention aspect.
1001 while Present (A) loop
1002 exit when Chars (Identifier (A)) = Name_Export
1003 or else Chars (Identifier (A)) = Name_Import;
1009 ("Missing Import/Export for Link/External name",
1013 end Analyze_Aspect_External_Or_Link_Name;
1015 -----------------------------------------
1016 -- Analyze_Aspect_Implicit_Dereference --
1017 -----------------------------------------
1019 procedure Analyze_Aspect_Implicit_Dereference is
1021 if not Is_Type (E) or else not Has_Discriminants (E) then
1023 ("Aspect must apply to a type with discriminants", N);
1030 Disc := First_Discriminant (E);
1031 while Present (Disc) loop
1032 if Chars (Expr) = Chars (Disc)
1033 and then Ekind (Etype (Disc)) =
1034 E_Anonymous_Access_Type
1036 Set_Has_Implicit_Dereference (E);
1037 Set_Has_Implicit_Dereference (Disc);
1041 Next_Discriminant (Disc);
1044 -- Error if no proper access discriminant.
1047 ("not an access discriminant of&", Expr, E);
1050 end Analyze_Aspect_Implicit_Dereference;
1053 -- Skip aspect if already analyzed (not clear if this is needed)
1055 if Analyzed (Aspect) then
1059 -- Set the source location of expression, used in the case of
1060 -- a failed precondition/postcondition or invariant. Note that
1061 -- the source location of the expression is not usually the best
1062 -- choice here. For example, it gets located on the last AND
1063 -- keyword in a chain of boolean expressiond AND'ed together.
1064 -- It is best to put the message on the first character of the
1065 -- assertion, which is the effect of the First_Node call here.
1067 if Present (Expr) then
1068 Eloc := Sloc (First_Node (Expr));
1071 -- Check restriction No_Implementation_Aspect_Specifications
1073 if Impl_Defined_Aspects (A_Id) then
1075 (No_Implementation_Aspect_Specifications, Aspect);
1078 -- Check restriction No_Specification_Of_Aspect
1080 Check_Restriction_No_Specification_Of_Aspect (Aspect);
1082 -- Analyze this aspect
1084 Set_Analyzed (Aspect);
1085 Set_Entity (Aspect, E);
1086 Ent := New_Occurrence_Of (E, Sloc (Id));
1088 -- Check for duplicate aspect. Note that the Comes_From_Source
1089 -- test allows duplicate Pre/Post's that we generate internally
1090 -- to escape being flagged here.
1092 if No_Duplicates_Allowed (A_Id) then
1094 while Anod /= Aspect loop
1096 (A_Id, Get_Aspect_Id (Chars (Identifier (Anod))))
1097 and then Comes_From_Source (Aspect)
1099 Error_Msg_Name_1 := Nam;
1100 Error_Msg_Sloc := Sloc (Anod);
1102 -- Case of same aspect specified twice
1104 if Class_Present (Anod) = Class_Present (Aspect) then
1105 if not Class_Present (Anod) then
1107 ("aspect% for & previously given#",
1111 ("aspect `%''Class` for & previously given#",
1121 -- Check some general restrictions on language defined aspects
1123 if not Impl_Defined_Aspects (A_Id) then
1124 Error_Msg_Name_1 := Nam;
1126 -- Not allowed for renaming declarations
1128 if Nkind (N) in N_Renaming_Declaration then
1130 ("aspect % not allowed for renaming declaration",
1134 -- Not allowed for formal type declarations
1136 if Nkind (N) = N_Formal_Type_Declaration then
1138 ("aspect % not allowed for formal type declaration",
1143 -- Copy expression for later processing by the procedures
1144 -- Check_Aspect_At_[Freeze_Point | End_Of_Declarations]
1146 Set_Entity (Id, New_Copy_Tree (Expr));
1148 -- Processing based on specific aspect
1152 -- No_Aspect should be impossible
1155 raise Program_Error;
1157 -- Case 1: Aspects corresponding to attribute definition
1160 when Aspect_Address |
1163 Aspect_Component_Size |
1164 Aspect_Constant_Indexing |
1165 Aspect_Default_Iterator |
1166 Aspect_Dispatching_Domain |
1167 Aspect_External_Tag |
1169 Aspect_Iterator_Element |
1170 Aspect_Machine_Radix |
1171 Aspect_Object_Size |
1174 Aspect_Scalar_Storage_Order |
1177 Aspect_Simple_Storage_Pool |
1178 Aspect_Storage_Pool |
1179 Aspect_Storage_Size |
1180 Aspect_Stream_Size |
1182 Aspect_Variable_Indexing |
1185 -- Indexing aspects apply only to tagged type
1187 if (A_Id = Aspect_Constant_Indexing
1188 or else A_Id = Aspect_Variable_Indexing)
1189 and then not (Is_Type (E)
1190 and then Is_Tagged_Type (E))
1192 Error_Msg_N ("indexing applies to a tagged type", N);
1196 -- Construct the attribute definition clause
1199 Make_Attribute_Definition_Clause (Loc,
1201 Chars => Chars (Id),
1202 Expression => Relocate_Node (Expr));
1204 -- Case 2: Aspects cooresponding to pragmas
1206 -- Case 2a: Aspects corresponding to pragmas with two
1207 -- arguments, where the first argument is a local name
1208 -- referring to the entity, and the second argument is the
1209 -- aspect definition expression.
1211 when Aspect_Suppress |
1212 Aspect_Unsuppress =>
1214 -- Construct the pragma
1218 Pragma_Argument_Associations => New_List (
1219 Make_Pragma_Argument_Association (Loc,
1220 Expression => New_Occurrence_Of (E, Loc)),
1222 Make_Pragma_Argument_Association (Sloc (Expr),
1223 Expression => Relocate_Node (Expr))),
1225 Pragma_Identifier =>
1226 Make_Identifier (Sloc (Id), Chars (Id)));
1228 when Aspect_Synchronization =>
1230 -- The aspect corresponds to pragma Implemented.
1231 -- Construct the pragma.
1235 Pragma_Argument_Associations => New_List (
1236 Make_Pragma_Argument_Association (Loc,
1237 Expression => New_Occurrence_Of (E, Loc)),
1239 Make_Pragma_Argument_Association (Sloc (Expr),
1240 Expression => Relocate_Node (Expr))),
1242 Pragma_Identifier =>
1243 Make_Identifier (Sloc (Id), Name_Implemented));
1245 -- No delay is required since the only values are: By_Entry
1246 -- | By_Protected_Procedure | By_Any | Optional which don't
1247 -- get analyzed anyway.
1249 Delay_Required := False;
1251 when Aspect_Attach_Handler =>
1254 Pragma_Identifier =>
1255 Make_Identifier (Sloc (Id), Name_Attach_Handler),
1256 Pragma_Argument_Associations => New_List (
1257 Make_Pragma_Argument_Association (Sloc (Ent),
1259 Make_Pragma_Argument_Association (Sloc (Expr),
1260 Expression => Relocate_Node (Expr))));
1262 when Aspect_Dynamic_Predicate |
1264 Aspect_Static_Predicate =>
1266 -- Construct the pragma (always a pragma Predicate, with
1267 -- flags recording whether it is static/dynamic).
1271 Pragma_Argument_Associations => New_List (
1272 Make_Pragma_Argument_Association (Sloc (Ent),
1274 Make_Pragma_Argument_Association (Sloc (Expr),
1275 Expression => Relocate_Node (Expr))),
1276 Class_Present => Class_Present (Aspect),
1277 Pragma_Identifier =>
1278 Make_Identifier (Sloc (Id), Name_Predicate));
1280 -- If the type is private, indicate that its completion
1281 -- has a freeze node, because that is the one that will be
1282 -- visible at freeze time.
1284 Set_Has_Predicates (E);
1286 if Is_Private_Type (E)
1287 and then Present (Full_View (E))
1289 Set_Has_Predicates (Full_View (E));
1290 Set_Has_Delayed_Aspects (Full_View (E));
1291 Ensure_Freeze_Node (Full_View (E));
1294 -- Case 2b: Aspects corresponding to pragmas with two
1295 -- arguments, where the second argument is a local name
1296 -- referring to the entity, and the first argument is the
1297 -- aspect definition expression.
1299 when Aspect_Convention =>
1301 -- The aspect may be part of the specification of an import
1302 -- or export pragma. Scan the aspect list to gather the
1303 -- other components, if any. The name of the generated
1304 -- pragma is one of Convention/Import/Export.
1316 P_Name := Chars (Id);
1318 Arg_List := New_List;
1323 while Present (A) loop
1324 A_Name := Chars (Identifier (A));
1326 if A_Name = Name_Import or else
1327 A_Name = Name_Export
1330 Error_Msg_N ("conflicting", A);
1337 elsif A_Name = Name_Link_Name then
1339 Make_Pragma_Argument_Association (Loc,
1341 Expression => Relocate_Node (Expression (A)));
1343 elsif A_Name = Name_External_Name then
1345 Make_Pragma_Argument_Association (Loc,
1347 Expression => Relocate_Node (Expression (A)));
1353 Arg_List := New_List (
1354 Make_Pragma_Argument_Association (Sloc (Expr),
1355 Expression => Relocate_Node (Expr)),
1356 Make_Pragma_Argument_Association (Sloc (Ent),
1357 Expression => Ent));
1359 if Present (L_Assoc) then
1360 Append_To (Arg_List, L_Assoc);
1363 if Present (E_Assoc) then
1364 Append_To (Arg_List, E_Assoc);
1369 Pragma_Argument_Associations => Arg_List,
1370 Pragma_Identifier =>
1371 Make_Identifier (Loc, P_Name));
1374 -- The following three aspects can be specified for a
1375 -- subprogram body, in which case we generate pragmas for them
1376 -- and insert them ahead of local declarations, rather than
1380 Aspect_Interrupt_Priority |
1382 if Nkind (N) = N_Subprogram_Body then
1385 Pragma_Argument_Associations => New_List (
1386 Make_Pragma_Argument_Association (Sloc (Expr),
1387 Expression => Relocate_Node (Expr))),
1388 Pragma_Identifier =>
1389 Make_Identifier (Sloc (Id), Chars (Id)));
1392 Make_Attribute_Definition_Clause (Loc,
1394 Chars => Chars (Id),
1395 Expression => Relocate_Node (Expr));
1398 when Aspect_Warnings =>
1400 -- Construct the pragma
1404 Pragma_Argument_Associations => New_List (
1405 Make_Pragma_Argument_Association (Sloc (Expr),
1406 Expression => Relocate_Node (Expr)),
1407 Make_Pragma_Argument_Association (Loc,
1408 Expression => New_Occurrence_Of (E, Loc))),
1409 Pragma_Identifier =>
1410 Make_Identifier (Sloc (Id), Chars (Id)),
1411 Class_Present => Class_Present (Aspect));
1413 -- We don't have to play the delay game here, since the only
1414 -- values are ON/OFF which don't get analyzed anyway.
1416 Delay_Required := False;
1418 -- Case 2c: Aspects corresponding to pragmas with three
1421 -- Invariant aspects have a first argument that references the
1422 -- entity, a second argument that is the expression and a third
1423 -- argument that is an appropriate message.
1425 when Aspect_Invariant |
1426 Aspect_Type_Invariant =>
1428 -- Analysis of the pragma will verify placement legality:
1429 -- an invariant must apply to a private type, or appear in
1430 -- the private part of a spec and apply to a completion.
1432 -- Construct the pragma
1436 Pragma_Argument_Associations => New_List (
1437 Make_Pragma_Argument_Association (Sloc (Ent),
1439 Make_Pragma_Argument_Association (Sloc (Expr),
1440 Expression => Relocate_Node (Expr))),
1441 Class_Present => Class_Present (Aspect),
1442 Pragma_Identifier =>
1443 Make_Identifier (Sloc (Id), Name_Invariant));
1445 -- Add message unless exception messages are suppressed
1447 if not Opt.Exception_Locations_Suppressed then
1448 Append_To (Pragma_Argument_Associations (Aitem),
1449 Make_Pragma_Argument_Association (Eloc,
1450 Chars => Name_Message,
1452 Make_String_Literal (Eloc,
1453 Strval => "failed invariant from "
1454 & Build_Location_String (Eloc))));
1457 -- For Invariant case, insert immediately after the entity
1458 -- declaration. We do not have to worry about delay issues
1459 -- since the pragma processing takes care of this.
1461 Delay_Required := False;
1463 -- Case 2d : Aspects that correspond to a pragma with one
1466 when Aspect_Abstract_State =>
1469 Pragma_Identifier =>
1470 Make_Identifier (Sloc (Id), Name_Abstract_State),
1471 Pragma_Argument_Associations => New_List (
1472 Make_Pragma_Argument_Association (Loc,
1473 Expression => Relocate_Node (Expr))));
1475 Delay_Required := False;
1477 -- Aspect Global must be delayed because it can mention names
1478 -- and benefit from the forward visibility rules applicable to
1479 -- aspects of subprograms.
1481 when Aspect_Global =>
1484 Pragma_Identifier =>
1485 Make_Identifier (Sloc (Id), Name_Global),
1486 Pragma_Argument_Associations => New_List (
1487 Make_Pragma_Argument_Association (Loc,
1488 Expression => Relocate_Node (Expr))));
1490 when Aspect_Relative_Deadline =>
1493 Pragma_Argument_Associations => New_List (
1494 Make_Pragma_Argument_Association (Loc,
1495 Expression => Relocate_Node (Expr))),
1496 Pragma_Identifier =>
1497 Make_Identifier (Sloc (Id), Name_Relative_Deadline));
1499 -- If the aspect applies to a task, the corresponding pragma
1500 -- must appear within its declarations, not after.
1502 if Nkind (N) = N_Task_Type_Declaration then
1508 if No (Task_Definition (N)) then
1509 Set_Task_Definition (N,
1510 Make_Task_Definition (Loc,
1511 Visible_Declarations => New_List,
1512 End_Label => Empty));
1515 Def := Task_Definition (N);
1516 V := Visible_Declarations (Def);
1517 if not Is_Empty_List (V) then
1518 Insert_Before (First (V), Aitem);
1521 Set_Visible_Declarations (Def, New_List (Aitem));
1528 -- Case 3 : Aspects that don't correspond to pragma/attribute
1529 -- definition clause.
1531 -- Case 3a: The aspects listed below don't correspond to
1532 -- pragmas/attributes but do require delayed analysis.
1534 when Aspect_Default_Value |
1535 Aspect_Default_Component_Value =>
1538 -- Case 3b: The aspects listed below don't correspond to
1539 -- pragmas/attributes and don't need delayed analysis.
1541 -- For Implicit_Dereference, External_Name and Link_Name, only
1542 -- the legality checks are done during the analysis, thus no
1543 -- delay is required.
1545 when Aspect_Implicit_Dereference =>
1546 Analyze_Aspect_Implicit_Dereference;
1549 when Aspect_External_Name |
1551 Analyze_Aspect_External_Or_Link_Name;
1554 when Aspect_Dimension =>
1555 Analyze_Aspect_Dimension (N, Id, Expr);
1558 when Aspect_Dimension_System =>
1559 Analyze_Aspect_Dimension_System (N, Id, Expr);
1562 -- Case 4: Special handling for aspects
1563 -- Pre/Post/Test_Case/Contract_Case whose corresponding pragmas
1564 -- take care of the delay.
1566 -- Aspects Pre/Post generate Precondition/Postcondition pragmas
1567 -- with a first argument that is the expression, and a second
1568 -- argument that is an informative message if the test fails.
1569 -- This is inserted right after the declaration, to get the
1570 -- required pragma placement. The processing for the pragmas
1571 -- takes care of the required delay.
1573 when Pre_Post_Aspects => declare
1577 if A_Id = Aspect_Pre or else A_Id = Aspect_Precondition then
1578 Pname := Name_Precondition;
1580 Pname := Name_Postcondition;
1583 -- If the expressions is of the form A and then B, then
1584 -- we generate separate Pre/Post aspects for the separate
1585 -- clauses. Since we allow multiple pragmas, there is no
1586 -- problem in allowing multiple Pre/Post aspects internally.
1587 -- These should be treated in reverse order (B first and
1588 -- A second) since they are later inserted just after N in
1589 -- the order they are treated. This way, the pragma for A
1590 -- ends up preceding the pragma for B, which may have an
1591 -- importance for the error raised (either constraint error
1592 -- or precondition error).
1594 -- We do not do this for Pre'Class, since we have to put
1595 -- these conditions together in a complex OR expression
1597 -- We do not do this in ASIS mode, as ASIS relies on the
1598 -- original node representing the complete expression, when
1599 -- retrieving it through the source aspect table.
1602 and then (Pname = Name_Postcondition
1603 or else not Class_Present (Aspect))
1605 while Nkind (Expr) = N_And_Then loop
1606 Insert_After (Aspect,
1607 Make_Aspect_Specification (Sloc (Left_Opnd (Expr)),
1608 Identifier => Identifier (Aspect),
1609 Expression => Relocate_Node (Left_Opnd (Expr)),
1610 Class_Present => Class_Present (Aspect),
1611 Split_PPC => True));
1612 Rewrite (Expr, Relocate_Node (Right_Opnd (Expr)));
1613 Eloc := Sloc (Expr);
1617 -- Build the precondition/postcondition pragma
1621 Pragma_Identifier =>
1622 Make_Identifier (Sloc (Id), Pname),
1623 Class_Present => Class_Present (Aspect),
1624 Split_PPC => Split_PPC (Aspect),
1625 Pragma_Argument_Associations => New_List (
1626 Make_Pragma_Argument_Association (Eloc,
1627 Chars => Name_Check,
1628 Expression => Relocate_Node (Expr))));
1630 -- Add message unless exception messages are suppressed
1632 if not Opt.Exception_Locations_Suppressed then
1633 Append_To (Pragma_Argument_Associations (Aitem),
1634 Make_Pragma_Argument_Association (Eloc,
1635 Chars => Name_Message,
1637 Make_String_Literal (Eloc,
1639 & Get_Name_String (Pname)
1641 & Build_Location_String (Eloc))));
1644 Set_From_Aspect_Specification (Aitem, True);
1645 Set_Corresponding_Aspect (Aitem, Aspect);
1646 Set_Is_Delayed_Aspect (Aspect);
1648 -- For Pre/Post cases, insert immediately after the entity
1649 -- declaration, since that is the required pragma placement.
1650 -- Note that for these aspects, we do not have to worry
1651 -- about delay issues, since the pragmas themselves deal
1652 -- with delay of visibility for the expression analysis.
1654 -- If the entity is a library-level subprogram, the pre/
1655 -- postconditions must be treated as late pragmas. Note
1656 -- that they must be prepended, not appended, to the list,
1657 -- so that split AND THEN sections are processed in the
1660 if Nkind (Parent (N)) = N_Compilation_Unit then
1662 Aux : constant Node_Id := Aux_Decls_Node (Parent (N));
1665 if No (Pragmas_After (Aux)) then
1666 Set_Pragmas_After (Aux, New_List);
1669 Prepend (Aitem, Pragmas_After (Aux));
1672 -- If it is a subprogram body, add pragmas to list of
1673 -- declarations in body.
1675 elsif Nkind (N) = N_Subprogram_Body then
1676 if No (Declarations (N)) then
1677 Set_Declarations (N, New_List);
1680 Append (Aitem, Declarations (N));
1683 Insert_After (N, Aitem);
1689 when Aspect_Contract_Case |
1694 Comp_Expr : Node_Id;
1695 Comp_Assn : Node_Id;
1701 if Nkind (Parent (N)) = N_Compilation_Unit then
1702 Error_Msg_Name_1 := Nam;
1703 Error_Msg_N ("incorrect placement of aspect `%`", E);
1707 if Nkind (Expr) /= N_Aggregate then
1708 Error_Msg_Name_1 := Nam;
1710 ("wrong syntax for aspect `%` for &", Id, E);
1714 -- Make pragma expressions refer to the original aspect
1715 -- expressions through the Original_Node link. This is
1716 -- used in semantic analysis for ASIS mode, so that the
1717 -- original expression also gets analyzed.
1719 Comp_Expr := First (Expressions (Expr));
1720 while Present (Comp_Expr) loop
1721 New_Expr := Relocate_Node (Comp_Expr);
1722 Set_Original_Node (New_Expr, Comp_Expr);
1724 Make_Pragma_Argument_Association (Sloc (Comp_Expr),
1725 Expression => New_Expr));
1729 Comp_Assn := First (Component_Associations (Expr));
1730 while Present (Comp_Assn) loop
1731 if List_Length (Choices (Comp_Assn)) /= 1
1733 Nkind (First (Choices (Comp_Assn))) /= N_Identifier
1735 Error_Msg_Name_1 := Nam;
1737 ("wrong syntax for aspect `%` for &", Id, E);
1741 New_Expr := Relocate_Node (Expression (Comp_Assn));
1742 Set_Original_Node (New_Expr, Expression (Comp_Assn));
1744 Make_Pragma_Argument_Association (Sloc (Comp_Assn),
1745 Chars => Chars (First (Choices (Comp_Assn))),
1746 Expression => New_Expr));
1750 -- Build the contract-case or test-case pragma
1754 Pragma_Identifier =>
1755 Make_Identifier (Sloc (Id), Nam),
1756 Pragma_Argument_Associations => Args);
1758 Delay_Required := False;
1761 when Aspect_Contract_Cases => Contract_Cases : declare
1762 Case_Guard : Node_Id;
1764 Others_Seen : Boolean := False;
1765 Post_Case : Node_Id;
1768 if Nkind (Parent (N)) = N_Compilation_Unit then
1769 Error_Msg_Name_1 := Nam;
1770 Error_Msg_N ("incorrect placement of aspect `%`", E);
1774 if Nkind (Expr) /= N_Aggregate then
1775 Error_Msg_Name_1 := Nam;
1777 ("wrong syntax for aspect `%` for &", Id, E);
1781 -- Verify the legality of individual post cases
1783 Post_Case := First (Component_Associations (Expr));
1784 while Present (Post_Case) loop
1785 if Nkind (Post_Case) /= N_Component_Association then
1786 Error_Msg_N ("wrong syntax in post case", Post_Case);
1790 -- Each post case must have exactly one case guard
1792 Case_Guard := First (Choices (Post_Case));
1793 Extra := Next (Case_Guard);
1795 if Present (Extra) then
1797 ("post case may have only one case guard", Extra);
1801 -- Check the placement of "others" (if available)
1803 if Nkind (Case_Guard) = N_Others_Choice then
1805 Error_Msg_Name_1 := Nam;
1807 ("only one others choice allowed in aspect %",
1811 Others_Seen := True;
1814 elsif Others_Seen then
1815 Error_Msg_Name_1 := Nam;
1817 ("others must be the last choice in aspect %", N);
1824 -- Transform the aspect into a pragma
1828 Pragma_Identifier =>
1829 Make_Identifier (Loc, Nam),
1830 Pragma_Argument_Associations => New_List (
1831 Make_Pragma_Argument_Association (Loc,
1832 Expression => Relocate_Node (Expr))));
1834 Delay_Required := False;
1837 -- Case 5: Special handling for aspects with an optional
1838 -- boolean argument.
1840 -- In the general case, the corresponding pragma cannot be
1841 -- generated yet because the evaluation of the boolean needs to
1842 -- be delayed til the freeze point.
1844 when Boolean_Aspects |
1845 Library_Unit_Aspects =>
1847 Set_Is_Boolean_Aspect (Aspect);
1849 -- Lock_Free aspect only apply to protected objects
1851 if A_Id = Aspect_Lock_Free then
1852 if Ekind (E) /= E_Protected_Type then
1853 Error_Msg_Name_1 := Nam;
1855 ("aspect % only applies to a protected object",
1859 -- Set the Uses_Lock_Free flag to True if there is no
1860 -- expression or if the expression is True. ??? The
1861 -- evaluation of this aspect should be delayed to the
1865 or else Is_True (Static_Boolean (Expr))
1867 Set_Uses_Lock_Free (E);
1870 Record_Rep_Item (E, Aspect);
1875 elsif A_Id = Aspect_Import or else A_Id = Aspect_Export then
1877 -- Verify that there is an aspect Convention that will
1878 -- incorporate the Import/Export aspect, and eventual
1879 -- Link/External names.
1886 while Present (A) loop
1887 exit when Chars (Identifier (A)) = Name_Convention;
1893 ("missing Convention aspect for Export/Import",
1901 -- This requires special handling in the case of a package
1902 -- declaration, the pragma needs to be inserted in the list
1903 -- of declarations for the associated package. There is no
1904 -- issue of visibility delay for these aspects.
1906 if A_Id in Library_Unit_Aspects
1907 and then Nkind (N) = N_Package_Declaration
1908 and then Nkind (Parent (N)) /= N_Compilation_Unit
1911 ("incorrect context for library unit aspect&", Id);
1915 -- Special handling when the aspect has no expression. In
1916 -- this case the value is considered to be True. Thus, we
1917 -- simply insert the pragma, no delay is required.
1922 Pragma_Argument_Associations => New_List (
1923 Make_Pragma_Argument_Association (Sloc (Ent),
1924 Expression => Ent)),
1925 Pragma_Identifier =>
1926 Make_Identifier (Sloc (Id), Chars (Id)));
1928 Delay_Required := False;
1930 -- In general cases, the corresponding pragma/attribute
1931 -- definition clause will be inserted later at the freezing
1939 -- Attach the corresponding pragma/attribute definition clause to
1940 -- the aspect specification node.
1942 if Present (Aitem) then
1943 Set_From_Aspect_Specification (Aitem, True);
1945 if Nkind (Aitem) = N_Pragma then
1946 Set_Corresponding_Aspect (Aitem, Aspect);
1950 -- In the context of a compilation unit, we directly put the
1951 -- pragma in the Pragmas_After list of the
1952 -- N_Compilation_Unit_Aux node (no delay is required here)
1953 -- except for aspects on a subprogram body (see below).
1955 if Nkind (Parent (N)) = N_Compilation_Unit
1956 and then (Present (Aitem) or else Is_Boolean_Aspect (Aspect))
1959 Aux : constant Node_Id := Aux_Decls_Node (Parent (N));
1962 pragma Assert (Nkind (Aux) = N_Compilation_Unit_Aux);
1964 -- For a Boolean aspect, create the corresponding pragma if
1965 -- no expression or if the value is True.
1967 if Is_Boolean_Aspect (Aspect) and then No (Aitem) then
1968 if Is_True (Static_Boolean (Expr)) then
1971 Pragma_Argument_Associations => New_List (
1972 Make_Pragma_Argument_Association (Sloc (Ent),
1973 Expression => Ent)),
1974 Pragma_Identifier =>
1975 Make_Identifier (Sloc (Id), Chars (Id)));
1977 Set_From_Aspect_Specification (Aitem, True);
1978 Set_Corresponding_Aspect (Aitem, Aspect);
1985 -- If the aspect is on a subprogram body (relevant aspects
1986 -- are Inline and Priority), add the pragma in front of
1987 -- the declarations.
1989 if Nkind (N) = N_Subprogram_Body then
1990 if No (Declarations (N)) then
1991 Set_Declarations (N, New_List);
1994 Prepend (Aitem, Declarations (N));
1996 -- Aspect Abstract_State produces implicit declarations for
1997 -- all state abstraction entities it defines. To emulate
1998 -- this behavior, insert the pragma at the start of the
1999 -- visible declarations of the related package.
2001 elsif Nam = Name_Abstract_State
2002 and then Nkind (N) = N_Package_Declaration
2004 if No (Visible_Declarations (Specification (N))) then
2005 Set_Visible_Declarations (Specification (N), New_List);
2008 Prepend (Aitem, Visible_Declarations (Specification (N)));
2011 if No (Pragmas_After (Aux)) then
2012 Set_Pragmas_After (Aux, New_List);
2015 Append (Aitem, Pragmas_After (Aux));
2022 -- The evaluation of the aspect is delayed to the freezing point.
2023 -- The pragma or attribute clause if there is one is then attached
2024 -- to the aspect specification which is placed in the rep item
2027 if Delay_Required then
2028 if Present (Aitem) then
2029 Set_Is_Delayed_Aspect (Aitem);
2030 Set_Aspect_Rep_Item (Aspect, Aitem);
2031 Set_Parent (Aitem, Aspect);
2034 Set_Is_Delayed_Aspect (Aspect);
2036 -- In the case of Default_Value, link aspect to base type
2037 -- as well, even though it appears on a first subtype. This
2038 -- is mandated by the semantics of the aspect. Verify that
2039 -- this a scalar type, to prevent cascaded errors.
2041 if A_Id = Aspect_Default_Value and then Is_Scalar_Type (E) then
2042 Set_Has_Delayed_Aspects (Base_Type (E));
2043 Record_Rep_Item (Base_Type (E), Aspect);
2046 Set_Has_Delayed_Aspects (E);
2047 Record_Rep_Item (E, Aspect);
2049 -- When delay is not required and the context is not a compilation
2050 -- unit, we simply insert the pragma/attribute definition clause
2054 Insert_After (Ins_Node, Aitem);
2061 end loop Aspect_Loop;
2063 if Has_Delayed_Aspects (E) then
2064 Ensure_Freeze_Node (E);
2066 end Analyze_Aspect_Specifications;
2068 -----------------------
2069 -- Analyze_At_Clause --
2070 -----------------------
2072 -- An at clause is replaced by the corresponding Address attribute
2073 -- definition clause that is the preferred approach in Ada 95.
2075 procedure Analyze_At_Clause (N : Node_Id) is
2076 CS : constant Boolean := Comes_From_Source (N);
2079 -- This is an obsolescent feature
2081 Check_Restriction (No_Obsolescent_Features, N);
2083 if Warn_On_Obsolescent_Feature then
2085 ("?j?at clause is an obsolescent feature (RM J.7(2))", N);
2087 ("\?j?use address attribute definition clause instead", N);
2090 -- Rewrite as address clause
2093 Make_Attribute_Definition_Clause (Sloc (N),
2094 Name => Identifier (N),
2095 Chars => Name_Address,
2096 Expression => Expression (N)));
2098 -- We preserve Comes_From_Source, since logically the clause still comes
2099 -- from the source program even though it is changed in form.
2101 Set_Comes_From_Source (N, CS);
2103 -- Analyze rewritten clause
2105 Analyze_Attribute_Definition_Clause (N);
2106 end Analyze_At_Clause;
2108 -----------------------------------------
2109 -- Analyze_Attribute_Definition_Clause --
2110 -----------------------------------------
2112 procedure Analyze_Attribute_Definition_Clause (N : Node_Id) is
2113 Loc : constant Source_Ptr := Sloc (N);
2114 Nam : constant Node_Id := Name (N);
2115 Attr : constant Name_Id := Chars (N);
2116 Expr : constant Node_Id := Expression (N);
2117 Id : constant Attribute_Id := Get_Attribute_Id (Attr);
2120 -- The entity of Nam after it is analyzed. In the case of an incomplete
2121 -- type, this is the underlying type.
2124 -- The underlying entity to which the attribute applies. Generally this
2125 -- is the Underlying_Type of Ent, except in the case where the clause
2126 -- applies to full view of incomplete type or private type in which case
2127 -- U_Ent is just a copy of Ent.
2129 FOnly : Boolean := False;
2130 -- Reset to True for subtype specific attribute (Alignment, Size)
2131 -- and for stream attributes, i.e. those cases where in the call
2132 -- to Rep_Item_Too_Late, FOnly is set True so that only the freezing
2133 -- rules are checked. Note that the case of stream attributes is not
2134 -- clear from the RM, but see AI95-00137. Also, the RM seems to
2135 -- disallow Storage_Size for derived task types, but that is also
2136 -- clearly unintentional.
2138 procedure Analyze_Stream_TSS_Definition (TSS_Nam : TSS_Name_Type);
2139 -- Common processing for 'Read, 'Write, 'Input and 'Output attribute
2140 -- definition clauses.
2142 function Duplicate_Clause return Boolean;
2143 -- This routine checks if the aspect for U_Ent being given by attribute
2144 -- definition clause N is for an aspect that has already been specified,
2145 -- and if so gives an error message. If there is a duplicate, True is
2146 -- returned, otherwise if there is no error, False is returned.
2148 procedure Check_Indexing_Functions;
2149 -- Check that the function in Constant_Indexing or Variable_Indexing
2150 -- attribute has the proper type structure. If the name is overloaded,
2151 -- check that some interpretation is legal.
2153 procedure Check_Iterator_Functions;
2154 -- Check that there is a single function in Default_Iterator attribute
2155 -- has the proper type structure.
2157 function Check_Primitive_Function (Subp : Entity_Id) return Boolean;
2158 -- Common legality check for the previous two
2160 -----------------------------------
2161 -- Analyze_Stream_TSS_Definition --
2162 -----------------------------------
2164 procedure Analyze_Stream_TSS_Definition (TSS_Nam : TSS_Name_Type) is
2165 Subp : Entity_Id := Empty;
2170 Is_Read : constant Boolean := (TSS_Nam = TSS_Stream_Read);
2171 -- True for Read attribute, false for other attributes
2173 function Has_Good_Profile (Subp : Entity_Id) return Boolean;
2174 -- Return true if the entity is a subprogram with an appropriate
2175 -- profile for the attribute being defined.
2177 ----------------------
2178 -- Has_Good_Profile --
2179 ----------------------
2181 function Has_Good_Profile (Subp : Entity_Id) return Boolean is
2183 Is_Function : constant Boolean := (TSS_Nam = TSS_Stream_Input);
2184 Expected_Ekind : constant array (Boolean) of Entity_Kind :=
2185 (False => E_Procedure, True => E_Function);
2189 if Ekind (Subp) /= Expected_Ekind (Is_Function) then
2193 F := First_Formal (Subp);
2196 or else Ekind (Etype (F)) /= E_Anonymous_Access_Type
2197 or else Designated_Type (Etype (F)) /=
2198 Class_Wide_Type (RTE (RE_Root_Stream_Type))
2203 if not Is_Function then
2207 Expected_Mode : constant array (Boolean) of Entity_Kind :=
2208 (False => E_In_Parameter,
2209 True => E_Out_Parameter);
2211 if Parameter_Mode (F) /= Expected_Mode (Is_Read) then
2219 Typ := Etype (Subp);
2222 return Base_Type (Typ) = Base_Type (Ent)
2223 and then No (Next_Formal (F));
2224 end Has_Good_Profile;
2226 -- Start of processing for Analyze_Stream_TSS_Definition
2231 if not Is_Type (U_Ent) then
2232 Error_Msg_N ("local name must be a subtype", Nam);
2236 Pnam := TSS (Base_Type (U_Ent), TSS_Nam);
2238 -- If Pnam is present, it can be either inherited from an ancestor
2239 -- type (in which case it is legal to redefine it for this type), or
2240 -- be a previous definition of the attribute for the same type (in
2241 -- which case it is illegal).
2243 -- In the first case, it will have been analyzed already, and we
2244 -- can check that its profile does not match the expected profile
2245 -- for a stream attribute of U_Ent. In the second case, either Pnam
2246 -- has been analyzed (and has the expected profile), or it has not
2247 -- been analyzed yet (case of a type that has not been frozen yet
2248 -- and for which the stream attribute has been set using Set_TSS).
2251 and then (No (First_Entity (Pnam)) or else Has_Good_Profile (Pnam))
2253 Error_Msg_Sloc := Sloc (Pnam);
2254 Error_Msg_Name_1 := Attr;
2255 Error_Msg_N ("% attribute already defined #", Nam);
2261 if Is_Entity_Name (Expr) then
2262 if not Is_Overloaded (Expr) then
2263 if Has_Good_Profile (Entity (Expr)) then
2264 Subp := Entity (Expr);
2268 Get_First_Interp (Expr, I, It);
2269 while Present (It.Nam) loop
2270 if Has_Good_Profile (It.Nam) then
2275 Get_Next_Interp (I, It);
2280 if Present (Subp) then
2281 if Is_Abstract_Subprogram (Subp) then
2282 Error_Msg_N ("stream subprogram must not be abstract", Expr);
2286 Set_Entity (Expr, Subp);
2287 Set_Etype (Expr, Etype (Subp));
2289 New_Stream_Subprogram (N, U_Ent, Subp, TSS_Nam);
2292 Error_Msg_Name_1 := Attr;
2293 Error_Msg_N ("incorrect expression for% attribute", Expr);
2295 end Analyze_Stream_TSS_Definition;
2297 ------------------------------
2298 -- Check_Indexing_Functions --
2299 ------------------------------
2301 procedure Check_Indexing_Functions is
2302 Indexing_Found : Boolean;
2304 procedure Check_One_Function (Subp : Entity_Id);
2305 -- Check one possible interpretation. Sets Indexing_Found True if an
2306 -- indexing function is found.
2308 ------------------------
2309 -- Check_One_Function --
2310 ------------------------
2312 procedure Check_One_Function (Subp : Entity_Id) is
2313 Default_Element : constant Node_Id :=
2315 (Etype (First_Formal (Subp)),
2316 Aspect_Iterator_Element);
2319 if not Check_Primitive_Function (Subp)
2320 and then not Is_Overloaded (Expr)
2323 ("aspect Indexing requires a function that applies to type&",
2327 -- An indexing function must return either the default element of
2328 -- the container, or a reference type. For variable indexing it
2329 -- must be the latter.
2331 if Present (Default_Element) then
2332 Analyze (Default_Element);
2334 if Is_Entity_Name (Default_Element)
2335 and then Covers (Entity (Default_Element), Etype (Subp))
2337 Indexing_Found := True;
2342 -- For variable_indexing the return type must be a reference type
2344 if Attr = Name_Variable_Indexing
2345 and then not Has_Implicit_Dereference (Etype (Subp))
2348 ("function for indexing must return a reference type", Subp);
2351 Indexing_Found := True;
2353 end Check_One_Function;
2355 -- Start of processing for Check_Indexing_Functions
2364 if not Is_Overloaded (Expr) then
2365 Check_One_Function (Entity (Expr));
2373 Indexing_Found := False;
2374 Get_First_Interp (Expr, I, It);
2375 while Present (It.Nam) loop
2377 -- Note that analysis will have added the interpretation
2378 -- that corresponds to the dereference. We only check the
2379 -- subprogram itself.
2381 if Is_Overloadable (It.Nam) then
2382 Check_One_Function (It.Nam);
2385 Get_Next_Interp (I, It);
2388 if not Indexing_Found then
2390 ("aspect Indexing requires a function that "
2391 & "applies to type&", Expr, Ent);
2395 end Check_Indexing_Functions;
2397 ------------------------------
2398 -- Check_Iterator_Functions --
2399 ------------------------------
2401 procedure Check_Iterator_Functions is
2402 Default : Entity_Id;
2404 function Valid_Default_Iterator (Subp : Entity_Id) return Boolean;
2405 -- Check one possible interpretation for validity
2407 ----------------------------
2408 -- Valid_Default_Iterator --
2409 ----------------------------
2411 function Valid_Default_Iterator (Subp : Entity_Id) return Boolean is
2415 if not Check_Primitive_Function (Subp) then
2418 Formal := First_Formal (Subp);
2421 -- False if any subsequent formal has no default expression
2423 Formal := Next_Formal (Formal);
2424 while Present (Formal) loop
2425 if No (Expression (Parent (Formal))) then
2429 Next_Formal (Formal);
2432 -- True if all subsequent formals have default expressions
2435 end Valid_Default_Iterator;
2437 -- Start of processing for Check_Iterator_Functions
2442 if not Is_Entity_Name (Expr) then
2443 Error_Msg_N ("aspect Iterator must be a function name", Expr);
2446 if not Is_Overloaded (Expr) then
2447 if not Check_Primitive_Function (Entity (Expr)) then
2449 ("aspect Indexing requires a function that applies to type&",
2450 Entity (Expr), Ent);
2453 if not Valid_Default_Iterator (Entity (Expr)) then
2454 Error_Msg_N ("improper function for default iterator", Expr);
2464 Get_First_Interp (Expr, I, It);
2465 while Present (It.Nam) loop
2466 if not Check_Primitive_Function (It.Nam)
2467 or else not Valid_Default_Iterator (It.Nam)
2471 elsif Present (Default) then
2472 Error_Msg_N ("default iterator must be unique", Expr);
2478 Get_Next_Interp (I, It);
2482 if Present (Default) then
2483 Set_Entity (Expr, Default);
2484 Set_Is_Overloaded (Expr, False);
2487 end Check_Iterator_Functions;
2489 -------------------------------
2490 -- Check_Primitive_Function --
2491 -------------------------------
2493 function Check_Primitive_Function (Subp : Entity_Id) return Boolean is
2497 if Ekind (Subp) /= E_Function then
2501 if No (First_Formal (Subp)) then
2504 Ctrl := Etype (First_Formal (Subp));
2508 or else Ctrl = Class_Wide_Type (Ent)
2510 (Ekind (Ctrl) = E_Anonymous_Access_Type
2512 (Designated_Type (Ctrl) = Ent
2513 or else Designated_Type (Ctrl) = Class_Wide_Type (Ent)))
2522 end Check_Primitive_Function;
2524 ----------------------
2525 -- Duplicate_Clause --
2526 ----------------------
2528 function Duplicate_Clause return Boolean is
2532 -- Nothing to do if this attribute definition clause comes from
2533 -- an aspect specification, since we could not be duplicating an
2534 -- explicit clause, and we dealt with the case of duplicated aspects
2535 -- in Analyze_Aspect_Specifications.
2537 if From_Aspect_Specification (N) then
2541 -- Otherwise current clause may duplicate previous clause, or a
2542 -- previously given pragma or aspect specification for the same
2545 A := Get_Rep_Item (U_Ent, Chars (N), Check_Parents => False);
2548 Error_Msg_Name_1 := Chars (N);
2549 Error_Msg_Sloc := Sloc (A);
2551 Error_Msg_NE ("aspect% for & previously given#", N, U_Ent);
2556 end Duplicate_Clause;
2558 -- Start of processing for Analyze_Attribute_Definition_Clause
2561 -- The following code is a defense against recursion. Not clear that
2562 -- this can happen legitimately, but perhaps some error situations
2563 -- can cause it, and we did see this recursion during testing.
2565 if Analyzed (N) then
2568 Set_Analyzed (N, True);
2571 -- Ignore some selected attributes in CodePeer mode since they are not
2572 -- relevant in this context.
2574 if CodePeer_Mode then
2577 -- Ignore Component_Size in CodePeer mode, to avoid changing the
2578 -- internal representation of types by implicitly packing them.
2580 when Attribute_Component_Size =>
2581 Rewrite (N, Make_Null_Statement (Sloc (N)));
2589 -- Process Ignore_Rep_Clauses option
2591 if Ignore_Rep_Clauses then
2594 -- The following should be ignored. They do not affect legality
2595 -- and may be target dependent. The basic idea of -gnatI is to
2596 -- ignore any rep clauses that may be target dependent but do not
2597 -- affect legality (except possibly to be rejected because they
2598 -- are incompatible with the compilation target).
2600 when Attribute_Alignment |
2601 Attribute_Bit_Order |
2602 Attribute_Component_Size |
2603 Attribute_Machine_Radix |
2604 Attribute_Object_Size |
2606 Attribute_Stream_Size |
2607 Attribute_Value_Size =>
2608 Rewrite (N, Make_Null_Statement (Sloc (N)));
2611 -- Perhaps 'Small should not be ignored by Ignore_Rep_Clauses ???
2613 when Attribute_Small =>
2614 if Ignore_Rep_Clauses then
2615 Rewrite (N, Make_Null_Statement (Sloc (N)));
2619 -- The following should not be ignored, because in the first place
2620 -- they are reasonably portable, and should not cause problems in
2621 -- compiling code from another target, and also they do affect
2622 -- legality, e.g. failing to provide a stream attribute for a
2623 -- type may make a program illegal.
2625 when Attribute_External_Tag |
2629 Attribute_Simple_Storage_Pool |
2630 Attribute_Storage_Pool |
2631 Attribute_Storage_Size |
2635 -- Other cases are errors ("attribute& cannot be set with
2636 -- definition clause"), which will be caught below.
2644 Ent := Entity (Nam);
2646 if Rep_Item_Too_Early (Ent, N) then
2650 -- Rep clause applies to full view of incomplete type or private type if
2651 -- we have one (if not, this is a premature use of the type). However,
2652 -- certain semantic checks need to be done on the specified entity (i.e.
2653 -- the private view), so we save it in Ent.
2655 if Is_Private_Type (Ent)
2656 and then Is_Derived_Type (Ent)
2657 and then not Is_Tagged_Type (Ent)
2658 and then No (Full_View (Ent))
2660 -- If this is a private type whose completion is a derivation from
2661 -- another private type, there is no full view, and the attribute
2662 -- belongs to the type itself, not its underlying parent.
2666 elsif Ekind (Ent) = E_Incomplete_Type then
2668 -- The attribute applies to the full view, set the entity of the
2669 -- attribute definition accordingly.
2671 Ent := Underlying_Type (Ent);
2673 Set_Entity (Nam, Ent);
2676 U_Ent := Underlying_Type (Ent);
2679 -- Avoid cascaded error
2681 if Etype (Nam) = Any_Type then
2684 -- Must be declared in current scope or in case of an aspect
2685 -- specification, must be visible in current scope.
2687 elsif Scope (Ent) /= Current_Scope
2689 not (From_Aspect_Specification (N)
2690 and then Scope_Within_Or_Same (Current_Scope, Scope (Ent)))
2692 Error_Msg_N ("entity must be declared in this scope", Nam);
2695 -- Must not be a source renaming (we do have some cases where the
2696 -- expander generates a renaming, and those cases are OK, in such
2697 -- cases any attribute applies to the renamed object as well).
2699 elsif Is_Object (Ent)
2700 and then Present (Renamed_Object (Ent))
2702 -- Case of renamed object from source, this is an error
2704 if Comes_From_Source (Renamed_Object (Ent)) then
2705 Get_Name_String (Chars (N));
2706 Error_Msg_Strlen := Name_Len;
2707 Error_Msg_String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len);
2709 ("~ clause not allowed for a renaming declaration "
2710 & "(RM 13.1(6))", Nam);
2713 -- For the case of a compiler generated renaming, the attribute
2714 -- definition clause applies to the renamed object created by the
2715 -- expander. The easiest general way to handle this is to create a
2716 -- copy of the attribute definition clause for this object.
2720 Make_Attribute_Definition_Clause (Loc,
2722 New_Occurrence_Of (Entity (Renamed_Object (Ent)), Loc),
2724 Expression => Duplicate_Subexpr (Expression (N))));
2727 -- If no underlying entity, use entity itself, applies to some
2728 -- previously detected error cases ???
2730 elsif No (U_Ent) then
2733 -- Cannot specify for a subtype (exception Object/Value_Size)
2735 elsif Is_Type (U_Ent)
2736 and then not Is_First_Subtype (U_Ent)
2737 and then Id /= Attribute_Object_Size
2738 and then Id /= Attribute_Value_Size
2739 and then not From_At_Mod (N)
2741 Error_Msg_N ("cannot specify attribute for subtype", Nam);
2745 Set_Entity (N, U_Ent);
2747 -- Switch on particular attribute
2755 -- Address attribute definition clause
2757 when Attribute_Address => Address : begin
2759 -- A little error check, catch for X'Address use X'Address;
2761 if Nkind (Nam) = N_Identifier
2762 and then Nkind (Expr) = N_Attribute_Reference
2763 and then Attribute_Name (Expr) = Name_Address
2764 and then Nkind (Prefix (Expr)) = N_Identifier
2765 and then Chars (Nam) = Chars (Prefix (Expr))
2768 ("address for & is self-referencing", Prefix (Expr), Ent);
2772 -- Not that special case, carry on with analysis of expression
2774 Analyze_And_Resolve (Expr, RTE (RE_Address));
2776 -- Even when ignoring rep clauses we need to indicate that the
2777 -- entity has an address clause and thus it is legal to declare
2780 if Ignore_Rep_Clauses then
2781 if Ekind_In (U_Ent, E_Variable, E_Constant) then
2782 Record_Rep_Item (U_Ent, N);
2788 if Duplicate_Clause then
2791 -- Case of address clause for subprogram
2793 elsif Is_Subprogram (U_Ent) then
2794 if Has_Homonym (U_Ent) then
2796 ("address clause cannot be given " &
2797 "for overloaded subprogram",
2802 -- For subprograms, all address clauses are permitted, and we
2803 -- mark the subprogram as having a deferred freeze so that Gigi
2804 -- will not elaborate it too soon.
2806 -- Above needs more comments, what is too soon about???
2808 Set_Has_Delayed_Freeze (U_Ent);
2810 -- Case of address clause for entry
2812 elsif Ekind (U_Ent) = E_Entry then
2813 if Nkind (Parent (N)) = N_Task_Body then
2815 ("entry address must be specified in task spec", Nam);
2819 -- For entries, we require a constant address
2821 Check_Constant_Address_Clause (Expr, U_Ent);
2823 -- Special checks for task types
2825 if Is_Task_Type (Scope (U_Ent))
2826 and then Comes_From_Source (Scope (U_Ent))
2829 ("??entry address declared for entry in task type", N);
2831 ("\??only one task can be declared of this type", N);
2834 -- Entry address clauses are obsolescent
2836 Check_Restriction (No_Obsolescent_Features, N);
2838 if Warn_On_Obsolescent_Feature then
2840 ("?j?attaching interrupt to task entry is an " &
2841 "obsolescent feature (RM J.7.1)", N);
2843 ("\?j?use interrupt procedure instead", N);
2846 -- Case of an address clause for a controlled object which we
2847 -- consider to be erroneous.
2849 elsif Is_Controlled (Etype (U_Ent))
2850 or else Has_Controlled_Component (Etype (U_Ent))
2853 ("??controlled object& must not be overlaid", Nam, U_Ent);
2855 ("\??Program_Error will be raised at run time", Nam);
2856 Insert_Action (Declaration_Node (U_Ent),
2857 Make_Raise_Program_Error (Loc,
2858 Reason => PE_Overlaid_Controlled_Object));
2861 -- Case of address clause for a (non-controlled) object
2864 Ekind (U_Ent) = E_Variable
2866 Ekind (U_Ent) = E_Constant
2869 Expr : constant Node_Id := Expression (N);
2874 -- Exported variables cannot have an address clause, because
2875 -- this cancels the effect of the pragma Export.
2877 if Is_Exported (U_Ent) then
2879 ("cannot export object with address clause", Nam);
2883 Find_Overlaid_Entity (N, O_Ent, Off);
2885 -- Overlaying controlled objects is erroneous
2888 and then (Has_Controlled_Component (Etype (O_Ent))
2889 or else Is_Controlled (Etype (O_Ent)))
2892 ("??cannot overlay with controlled object", Expr);
2894 ("\??Program_Error will be raised at run time", Expr);
2895 Insert_Action (Declaration_Node (U_Ent),
2896 Make_Raise_Program_Error (Loc,
2897 Reason => PE_Overlaid_Controlled_Object));
2900 elsif Present (O_Ent)
2901 and then Ekind (U_Ent) = E_Constant
2902 and then not Is_Constant_Object (O_Ent)
2904 Error_Msg_N ("??constant overlays a variable", Expr);
2906 -- Imported variables can have an address clause, but then
2907 -- the import is pretty meaningless except to suppress
2908 -- initializations, so we do not need such variables to
2909 -- be statically allocated (and in fact it causes trouble
2910 -- if the address clause is a local value).
2912 elsif Is_Imported (U_Ent) then
2913 Set_Is_Statically_Allocated (U_Ent, False);
2916 -- We mark a possible modification of a variable with an
2917 -- address clause, since it is likely aliasing is occurring.
2919 Note_Possible_Modification (Nam, Sure => False);
2921 -- Here we are checking for explicit overlap of one variable
2922 -- by another, and if we find this then mark the overlapped
2923 -- variable as also being volatile to prevent unwanted
2924 -- optimizations. This is a significant pessimization so
2925 -- avoid it when there is an offset, i.e. when the object
2926 -- is composite; they cannot be optimized easily anyway.
2929 and then Is_Object (O_Ent)
2932 -- The following test is an expedient solution to what
2933 -- is really a problem in CodePeer. Suppressing the
2934 -- Set_Treat_As_Volatile call here prevents later
2935 -- generation (in some cases) of trees that CodePeer
2936 -- should, but currently does not, handle correctly.
2937 -- This test should probably be removed when CodePeer
2938 -- is improved, just because we want the tree CodePeer
2939 -- analyzes to match the tree for which we generate code
2940 -- as closely as is practical. ???
2942 and then not CodePeer_Mode
2944 -- ??? O_Ent might not be in current unit
2946 Set_Treat_As_Volatile (O_Ent);
2949 -- Legality checks on the address clause for initialized
2950 -- objects is deferred until the freeze point, because
2951 -- a subsequent pragma might indicate that the object
2952 -- is imported and thus not initialized. Also, the address
2953 -- clause might involve entities that have yet to be
2956 Set_Has_Delayed_Freeze (U_Ent);
2958 -- If an initialization call has been generated for this
2959 -- object, it needs to be deferred to after the freeze node
2960 -- we have just now added, otherwise GIGI will see a
2961 -- reference to the variable (as actual to the IP call)
2962 -- before its definition.
2965 Init_Call : constant Node_Id :=
2966 Remove_Init_Call (U_Ent, N);
2969 if Present (Init_Call) then
2971 -- If the init call is an expression with actions with
2972 -- null expression, just extract the actions.
2974 if Nkind (Init_Call) = N_Expression_With_Actions
2976 Nkind (Expression (Init_Call)) = N_Null_Statement
2978 Append_Freeze_Actions (U_Ent, Actions (Init_Call));
2980 -- General case: move Init_Call to freeze actions
2983 Append_Freeze_Action (U_Ent, Init_Call);
2988 if Is_Exported (U_Ent) then
2990 ("& cannot be exported if an address clause is given",
2993 ("\define and export a variable "
2994 & "that holds its address instead", Nam);
2997 -- Entity has delayed freeze, so we will generate an
2998 -- alignment check at the freeze point unless suppressed.
3000 if not Range_Checks_Suppressed (U_Ent)
3001 and then not Alignment_Checks_Suppressed (U_Ent)
3003 Set_Check_Address_Alignment (N);
3006 -- Kill the size check code, since we are not allocating
3007 -- the variable, it is somewhere else.
3009 Kill_Size_Check_Code (U_Ent);
3011 -- If the address clause is of the form:
3013 -- for Y'Address use X'Address
3017 -- Const : constant Address := X'Address;
3019 -- for Y'Address use Const;
3021 -- then we make an entry in the table for checking the size
3022 -- and alignment of the overlaying variable. We defer this
3023 -- check till after code generation to take full advantage
3024 -- of the annotation done by the back end. This entry is
3025 -- only made if the address clause comes from source.
3027 -- If the entity has a generic type, the check will be
3028 -- performed in the instance if the actual type justifies
3029 -- it, and we do not insert the clause in the table to
3030 -- prevent spurious warnings.
3032 if Address_Clause_Overlay_Warnings
3033 and then Comes_From_Source (N)
3034 and then Present (O_Ent)
3035 and then Is_Object (O_Ent)
3037 if not Is_Generic_Type (Etype (U_Ent)) then
3038 Address_Clause_Checks.Append ((N, U_Ent, O_Ent, Off));
3041 -- If variable overlays a constant view, and we are
3042 -- warning on overlays, then mark the variable as
3043 -- overlaying a constant (we will give warnings later
3044 -- if this variable is assigned).
3046 if Is_Constant_Object (O_Ent)
3047 and then Ekind (U_Ent) = E_Variable
3049 Set_Overlays_Constant (U_Ent);
3054 -- Not a valid entity for an address clause
3057 Error_Msg_N ("address cannot be given for &", Nam);
3065 -- Alignment attribute definition clause
3067 when Attribute_Alignment => Alignment : declare
3068 Align : constant Uint := Get_Alignment_Value (Expr);
3069 Max_Align : constant Uint := UI_From_Int (Maximum_Alignment);
3074 if not Is_Type (U_Ent)
3075 and then Ekind (U_Ent) /= E_Variable
3076 and then Ekind (U_Ent) /= E_Constant
3078 Error_Msg_N ("alignment cannot be given for &", Nam);
3080 elsif Duplicate_Clause then
3083 elsif Align /= No_Uint then
3084 Set_Has_Alignment_Clause (U_Ent);
3086 -- Tagged type case, check for attempt to set alignment to a
3087 -- value greater than Max_Align, and reset if so.
3089 if Is_Tagged_Type (U_Ent) and then Align > Max_Align then
3091 ("alignment for & set to Maximum_Aligment??", Nam);
3092 Set_Alignment (U_Ent, Max_Align);
3097 Set_Alignment (U_Ent, Align);
3100 -- For an array type, U_Ent is the first subtype. In that case,
3101 -- also set the alignment of the anonymous base type so that
3102 -- other subtypes (such as the itypes for aggregates of the
3103 -- type) also receive the expected alignment.
3105 if Is_Array_Type (U_Ent) then
3106 Set_Alignment (Base_Type (U_Ent), Align);
3115 -- Bit_Order attribute definition clause
3117 when Attribute_Bit_Order => Bit_Order : declare
3119 if not Is_Record_Type (U_Ent) then
3121 ("Bit_Order can only be defined for record type", Nam);
3123 elsif Duplicate_Clause then
3127 Analyze_And_Resolve (Expr, RTE (RE_Bit_Order));
3129 if Etype (Expr) = Any_Type then
3132 elsif not Is_Static_Expression (Expr) then
3133 Flag_Non_Static_Expr
3134 ("Bit_Order requires static expression!", Expr);
3137 if (Expr_Value (Expr) = 0) /= Bytes_Big_Endian then
3138 Set_Reverse_Bit_Order (U_Ent, True);
3144 --------------------
3145 -- Component_Size --
3146 --------------------
3148 -- Component_Size attribute definition clause
3150 when Attribute_Component_Size => Component_Size_Case : declare
3151 Csize : constant Uint := Static_Integer (Expr);
3155 New_Ctyp : Entity_Id;
3159 if not Is_Array_Type (U_Ent) then
3160 Error_Msg_N ("component size requires array type", Nam);
3164 Btype := Base_Type (U_Ent);
3165 Ctyp := Component_Type (Btype);
3167 if Duplicate_Clause then
3170 elsif Rep_Item_Too_Early (Btype, N) then
3173 elsif Csize /= No_Uint then
3174 Check_Size (Expr, Ctyp, Csize, Biased);
3176 -- For the biased case, build a declaration for a subtype that
3177 -- will be used to represent the biased subtype that reflects
3178 -- the biased representation of components. We need the subtype
3179 -- to get proper conversions on referencing elements of the
3180 -- array. Note: component size clauses are ignored in VM mode.
3182 if VM_Target = No_VM then
3185 Make_Defining_Identifier (Loc,
3187 New_External_Name (Chars (U_Ent), 'C', 0, 'T'));
3190 Make_Subtype_Declaration (Loc,
3191 Defining_Identifier => New_Ctyp,
3192 Subtype_Indication =>
3193 New_Occurrence_Of (Component_Type (Btype), Loc));
3195 Set_Parent (Decl, N);
3196 Analyze (Decl, Suppress => All_Checks);
3198 Set_Has_Delayed_Freeze (New_Ctyp, False);
3199 Set_Esize (New_Ctyp, Csize);
3200 Set_RM_Size (New_Ctyp, Csize);
3201 Init_Alignment (New_Ctyp);
3202 Set_Is_Itype (New_Ctyp, True);
3203 Set_Associated_Node_For_Itype (New_Ctyp, U_Ent);
3205 Set_Component_Type (Btype, New_Ctyp);
3206 Set_Biased (New_Ctyp, N, "component size clause");
3209 Set_Component_Size (Btype, Csize);
3211 -- For VM case, we ignore component size clauses
3214 -- Give a warning unless we are in GNAT mode, in which case
3215 -- the warning is suppressed since it is not useful.
3217 if not GNAT_Mode then
3219 ("component size ignored in this configuration??", N);
3223 -- Deal with warning on overridden size
3225 if Warn_On_Overridden_Size
3226 and then Has_Size_Clause (Ctyp)
3227 and then RM_Size (Ctyp) /= Csize
3230 ("component size overrides size clause for&?S?", N, Ctyp);
3233 Set_Has_Component_Size_Clause (Btype, True);
3234 Set_Has_Non_Standard_Rep (Btype, True);
3236 end Component_Size_Case;
3238 -----------------------
3239 -- Constant_Indexing --
3240 -----------------------
3242 when Attribute_Constant_Indexing =>
3243 Check_Indexing_Functions;
3249 when Attribute_CPU => CPU :
3251 -- CPU attribute definition clause not allowed except from aspect
3254 if From_Aspect_Specification (N) then
3255 if not Is_Task_Type (U_Ent) then
3256 Error_Msg_N ("CPU can only be defined for task", Nam);
3258 elsif Duplicate_Clause then
3262 -- The expression must be analyzed in the special manner
3263 -- described in "Handling of Default and Per-Object
3264 -- Expressions" in sem.ads.
3266 -- The visibility to the discriminants must be restored
3268 Push_Scope_And_Install_Discriminants (U_Ent);
3269 Preanalyze_Spec_Expression (Expr, RTE (RE_CPU_Range));
3270 Uninstall_Discriminants_And_Pop_Scope (U_Ent);
3272 if not Is_Static_Expression (Expr) then
3273 Check_Restriction (Static_Priorities, Expr);
3279 ("attribute& cannot be set with definition clause", N);
3283 ----------------------
3284 -- Default_Iterator --
3285 ----------------------
3287 when Attribute_Default_Iterator => Default_Iterator : declare
3291 if not Is_Tagged_Type (U_Ent) then
3293 ("aspect Default_Iterator applies to tagged type", Nam);
3296 Check_Iterator_Functions;
3300 if not Is_Entity_Name (Expr)
3301 or else Ekind (Entity (Expr)) /= E_Function
3303 Error_Msg_N ("aspect Iterator must be a function", Expr);
3305 Func := Entity (Expr);
3308 if No (First_Formal (Func))
3309 or else Etype (First_Formal (Func)) /= U_Ent
3312 ("Default Iterator must be a primitive of&", Func, U_Ent);
3314 end Default_Iterator;
3316 ------------------------
3317 -- Dispatching_Domain --
3318 ------------------------
3320 when Attribute_Dispatching_Domain => Dispatching_Domain :
3322 -- Dispatching_Domain attribute definition clause not allowed
3323 -- except from aspect specification.
3325 if From_Aspect_Specification (N) then
3326 if not Is_Task_Type (U_Ent) then
3327 Error_Msg_N ("Dispatching_Domain can only be defined" &
3331 elsif Duplicate_Clause then
3335 -- The expression must be analyzed in the special manner
3336 -- described in "Handling of Default and Per-Object
3337 -- Expressions" in sem.ads.
3339 -- The visibility to the discriminants must be restored
3341 Push_Scope_And_Install_Discriminants (U_Ent);
3343 Preanalyze_Spec_Expression
3344 (Expr, RTE (RE_Dispatching_Domain));
3346 Uninstall_Discriminants_And_Pop_Scope (U_Ent);
3351 ("attribute& cannot be set with definition clause", N);
3353 end Dispatching_Domain;
3359 when Attribute_External_Tag => External_Tag :
3361 if not Is_Tagged_Type (U_Ent) then
3362 Error_Msg_N ("should be a tagged type", Nam);
3365 if Duplicate_Clause then
3369 Analyze_And_Resolve (Expr, Standard_String);
3371 if not Is_Static_Expression (Expr) then
3372 Flag_Non_Static_Expr
3373 ("static string required for tag name!", Nam);
3376 if VM_Target = No_VM then
3377 Set_Has_External_Tag_Rep_Clause (U_Ent);
3379 Error_Msg_Name_1 := Attr;
3381 ("% attribute unsupported in this configuration", Nam);
3384 if not Is_Library_Level_Entity (U_Ent) then
3386 ("??non-unique external tag supplied for &", N, U_Ent);
3388 ("\??same external tag applies to all "
3389 & "subprogram calls", N);
3391 ("\??corresponding internal tag cannot be obtained", N);
3396 --------------------------
3397 -- Implicit_Dereference --
3398 --------------------------
3400 when Attribute_Implicit_Dereference =>
3402 -- Legality checks already performed at the point of the type
3403 -- declaration, aspect is not delayed.
3411 when Attribute_Input =>
3412 Analyze_Stream_TSS_Definition (TSS_Stream_Input);
3413 Set_Has_Specified_Stream_Input (Ent);
3415 ------------------------
3416 -- Interrupt_Priority --
3417 ------------------------
3419 when Attribute_Interrupt_Priority => Interrupt_Priority :
3421 -- Interrupt_Priority attribute definition clause not allowed
3422 -- except from aspect specification.
3424 if From_Aspect_Specification (N) then
3425 if not (Is_Protected_Type (U_Ent)
3426 or else Is_Task_Type (U_Ent))
3429 ("Interrupt_Priority can only be defined for task" &
3430 "and protected object",
3433 elsif Duplicate_Clause then
3437 -- The expression must be analyzed in the special manner
3438 -- described in "Handling of Default and Per-Object
3439 -- Expressions" in sem.ads.
3441 -- The visibility to the discriminants must be restored
3443 Push_Scope_And_Install_Discriminants (U_Ent);
3445 Preanalyze_Spec_Expression
3446 (Expr, RTE (RE_Interrupt_Priority));
3448 Uninstall_Discriminants_And_Pop_Scope (U_Ent);
3453 ("attribute& cannot be set with definition clause", N);
3455 end Interrupt_Priority;
3457 ----------------------
3458 -- Iterator_Element --
3459 ----------------------
3461 when Attribute_Iterator_Element =>
3464 if not Is_Entity_Name (Expr)
3465 or else not Is_Type (Entity (Expr))
3467 Error_Msg_N ("aspect Iterator_Element must be a type", Expr);
3474 -- Machine radix attribute definition clause
3476 when Attribute_Machine_Radix => Machine_Radix : declare
3477 Radix : constant Uint := Static_Integer (Expr);
3480 if not Is_Decimal_Fixed_Point_Type (U_Ent) then
3481 Error_Msg_N ("decimal fixed-point type expected for &", Nam);
3483 elsif Duplicate_Clause then
3486 elsif Radix /= No_Uint then
3487 Set_Has_Machine_Radix_Clause (U_Ent);
3488 Set_Has_Non_Standard_Rep (Base_Type (U_Ent));
3492 elsif Radix = 10 then
3493 Set_Machine_Radix_10 (U_Ent);
3495 Error_Msg_N ("machine radix value must be 2 or 10", Expr);
3504 -- Object_Size attribute definition clause
3506 when Attribute_Object_Size => Object_Size : declare
3507 Size : constant Uint := Static_Integer (Expr);
3510 pragma Warnings (Off, Biased);
3513 if not Is_Type (U_Ent) then
3514 Error_Msg_N ("Object_Size cannot be given for &", Nam);
3516 elsif Duplicate_Clause then
3520 Check_Size (Expr, U_Ent, Size, Biased);
3528 UI_Mod (Size, 64) /= 0
3531 ("Object_Size must be 8, 16, 32, or multiple of 64",
3535 Set_Esize (U_Ent, Size);
3536 Set_Has_Object_Size_Clause (U_Ent);
3537 Alignment_Check_For_Size_Change (U_Ent, Size);
3545 when Attribute_Output =>
3546 Analyze_Stream_TSS_Definition (TSS_Stream_Output);
3547 Set_Has_Specified_Stream_Output (Ent);
3553 when Attribute_Priority => Priority :
3555 -- Priority attribute definition clause not allowed except from
3556 -- aspect specification.
3558 if From_Aspect_Specification (N) then
3559 if not (Is_Protected_Type (U_Ent)
3560 or else Is_Task_Type (U_Ent)
3561 or else Ekind (U_Ent) = E_Procedure)
3564 ("Priority can only be defined for task and protected " &
3568 elsif Duplicate_Clause then
3572 -- The expression must be analyzed in the special manner
3573 -- described in "Handling of Default and Per-Object
3574 -- Expressions" in sem.ads.
3576 -- The visibility to the discriminants must be restored
3578 Push_Scope_And_Install_Discriminants (U_Ent);
3579 Preanalyze_Spec_Expression (Expr, Standard_Integer);
3580 Uninstall_Discriminants_And_Pop_Scope (U_Ent);
3582 if not Is_Static_Expression (Expr) then
3583 Check_Restriction (Static_Priorities, Expr);
3589 ("attribute& cannot be set with definition clause", N);
3597 when Attribute_Read =>
3598 Analyze_Stream_TSS_Definition (TSS_Stream_Read);
3599 Set_Has_Specified_Stream_Read (Ent);
3601 --------------------------
3602 -- Scalar_Storage_Order --
3603 --------------------------
3605 -- Scalar_Storage_Order attribute definition clause
3607 when Attribute_Scalar_Storage_Order => Scalar_Storage_Order : declare
3609 if not (Is_Record_Type (U_Ent) or else Is_Array_Type (U_Ent)) then
3611 ("Scalar_Storage_Order can only be defined for "
3612 & "record or array type", Nam);
3614 elsif Duplicate_Clause then
3618 Analyze_And_Resolve (Expr, RTE (RE_Bit_Order));
3620 if Etype (Expr) = Any_Type then
3623 elsif not Is_Static_Expression (Expr) then
3624 Flag_Non_Static_Expr
3625 ("Scalar_Storage_Order requires static expression!", Expr);
3627 elsif (Expr_Value (Expr) = 0) /= Bytes_Big_Endian then
3629 -- Here for the case of a non-default (i.e. non-confirming)
3630 -- Scalar_Storage_Order attribute definition.
3632 if Support_Nondefault_SSO_On_Target then
3633 Set_Reverse_Storage_Order (Base_Type (U_Ent), True);
3636 ("non-default Scalar_Storage_Order "
3637 & "not supported on target", Expr);
3641 end Scalar_Storage_Order;
3647 -- Size attribute definition clause
3649 when Attribute_Size => Size : declare
3650 Size : constant Uint := Static_Integer (Expr);
3657 if Duplicate_Clause then
3660 elsif not Is_Type (U_Ent)
3661 and then Ekind (U_Ent) /= E_Variable
3662 and then Ekind (U_Ent) /= E_Constant
3664 Error_Msg_N ("size cannot be given for &", Nam);
3666 elsif Is_Array_Type (U_Ent)
3667 and then not Is_Constrained (U_Ent)
3670 ("size cannot be given for unconstrained array", Nam);
3672 elsif Size /= No_Uint then
3673 if VM_Target /= No_VM and then not GNAT_Mode then
3675 -- Size clause is not handled properly on VM targets.
3676 -- Display a warning unless we are in GNAT mode, in which
3677 -- case this is useless.
3680 ("size clauses are ignored in this configuration??", N);
3683 if Is_Type (U_Ent) then
3686 Etyp := Etype (U_Ent);
3689 -- Check size, note that Gigi is in charge of checking that the
3690 -- size of an array or record type is OK. Also we do not check
3691 -- the size in the ordinary fixed-point case, since it is too
3692 -- early to do so (there may be subsequent small clause that
3693 -- affects the size). We can check the size if a small clause
3694 -- has already been given.
3696 if not Is_Ordinary_Fixed_Point_Type (U_Ent)
3697 or else Has_Small_Clause (U_Ent)
3699 Check_Size (Expr, Etyp, Size, Biased);
3700 Set_Biased (U_Ent, N, "size clause", Biased);
3703 -- For types set RM_Size and Esize if possible
3705 if Is_Type (U_Ent) then
3706 Set_RM_Size (U_Ent, Size);
3708 -- For elementary types, increase Object_Size to power of 2,
3709 -- but not less than a storage unit in any case (normally
3710 -- this means it will be byte addressable).
3712 -- For all other types, nothing else to do, we leave Esize
3713 -- (object size) unset, the back end will set it from the
3714 -- size and alignment in an appropriate manner.
3716 -- In both cases, we check whether the alignment must be
3717 -- reset in the wake of the size change.
3719 if Is_Elementary_Type (U_Ent) then
3720 if Size <= System_Storage_Unit then
3721 Init_Esize (U_Ent, System_Storage_Unit);
3722 elsif Size <= 16 then
3723 Init_Esize (U_Ent, 16);
3724 elsif Size <= 32 then
3725 Init_Esize (U_Ent, 32);
3727 Set_Esize (U_Ent, (Size + 63) / 64 * 64);
3730 Alignment_Check_For_Size_Change (U_Ent, Esize (U_Ent));
3732 Alignment_Check_For_Size_Change (U_Ent, Size);
3735 -- For objects, set Esize only
3738 if Is_Elementary_Type (Etyp) then
3739 if Size /= System_Storage_Unit
3741 Size /= System_Storage_Unit * 2
3743 Size /= System_Storage_Unit * 4
3745 Size /= System_Storage_Unit * 8
3747 Error_Msg_Uint_1 := UI_From_Int (System_Storage_Unit);
3748 Error_Msg_Uint_2 := Error_Msg_Uint_1 * 8;
3750 ("size for primitive object must be a power of 2"
3751 & " in the range ^-^", N);
3755 Set_Esize (U_Ent, Size);
3758 Set_Has_Size_Clause (U_Ent);
3766 -- Small attribute definition clause
3768 when Attribute_Small => Small : declare
3769 Implicit_Base : constant Entity_Id := Base_Type (U_Ent);
3773 Analyze_And_Resolve (Expr, Any_Real);
3775 if Etype (Expr) = Any_Type then
3778 elsif not Is_Static_Expression (Expr) then
3779 Flag_Non_Static_Expr
3780 ("small requires static expression!", Expr);
3784 Small := Expr_Value_R (Expr);
3786 if Small <= Ureal_0 then
3787 Error_Msg_N ("small value must be greater than zero", Expr);
3793 if not Is_Ordinary_Fixed_Point_Type (U_Ent) then
3795 ("small requires an ordinary fixed point type", Nam);
3797 elsif Has_Small_Clause (U_Ent) then
3798 Error_Msg_N ("small already given for &", Nam);
3800 elsif Small > Delta_Value (U_Ent) then
3802 ("small value must not be greater than delta value", Nam);
3805 Set_Small_Value (U_Ent, Small);
3806 Set_Small_Value (Implicit_Base, Small);
3807 Set_Has_Small_Clause (U_Ent);
3808 Set_Has_Small_Clause (Implicit_Base);
3809 Set_Has_Non_Standard_Rep (Implicit_Base);
3817 -- Storage_Pool attribute definition clause
3819 when Attribute_Storage_Pool | Attribute_Simple_Storage_Pool => declare
3824 if Ekind (U_Ent) = E_Access_Subprogram_Type then
3826 ("storage pool cannot be given for access-to-subprogram type",
3831 Ekind_In (U_Ent, E_Access_Type, E_General_Access_Type)
3834 ("storage pool can only be given for access types", Nam);
3837 elsif Is_Derived_Type (U_Ent) then
3839 ("storage pool cannot be given for a derived access type",
3842 elsif Duplicate_Clause then
3845 elsif Present (Associated_Storage_Pool (U_Ent)) then
3846 Error_Msg_N ("storage pool already given for &", Nam);
3850 if Id = Attribute_Storage_Pool then
3852 (Expr, Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
3854 -- In the Simple_Storage_Pool case, we allow a variable of any
3855 -- simple storage pool type, so we Resolve without imposing an
3859 Analyze_And_Resolve (Expr);
3861 if not Present (Get_Rep_Pragma
3862 (Etype (Expr), Name_Simple_Storage_Pool_Type))
3865 ("expression must be of a simple storage pool type", Expr);
3869 if not Denotes_Variable (Expr) then
3870 Error_Msg_N ("storage pool must be a variable", Expr);
3874 if Nkind (Expr) = N_Type_Conversion then
3875 T := Etype (Expression (Expr));
3880 -- The Stack_Bounded_Pool is used internally for implementing
3881 -- access types with a Storage_Size. Since it only work properly
3882 -- when used on one specific type, we need to check that it is not
3883 -- hijacked improperly:
3885 -- type T is access Integer;
3886 -- for T'Storage_Size use n;
3887 -- type Q is access Float;
3888 -- for Q'Storage_Size use T'Storage_Size; -- incorrect
3890 if RTE_Available (RE_Stack_Bounded_Pool)
3891 and then Base_Type (T) = RTE (RE_Stack_Bounded_Pool)
3893 Error_Msg_N ("non-shareable internal Pool", Expr);
3897 -- If the argument is a name that is not an entity name, then
3898 -- we construct a renaming operation to define an entity of
3899 -- type storage pool.
3901 if not Is_Entity_Name (Expr)
3902 and then Is_Object_Reference (Expr)
3904 Pool := Make_Temporary (Loc, 'P', Expr);
3907 Rnode : constant Node_Id :=
3908 Make_Object_Renaming_Declaration (Loc,
3909 Defining_Identifier => Pool,
3911 New_Occurrence_Of (Etype (Expr), Loc),
3915 Insert_Before (N, Rnode);
3917 Set_Associated_Storage_Pool (U_Ent, Pool);
3920 elsif Is_Entity_Name (Expr) then
3921 Pool := Entity (Expr);
3923 -- If pool is a renamed object, get original one. This can
3924 -- happen with an explicit renaming, and within instances.
3926 while Present (Renamed_Object (Pool))
3927 and then Is_Entity_Name (Renamed_Object (Pool))
3929 Pool := Entity (Renamed_Object (Pool));
3932 if Present (Renamed_Object (Pool))
3933 and then Nkind (Renamed_Object (Pool)) = N_Type_Conversion
3934 and then Is_Entity_Name (Expression (Renamed_Object (Pool)))
3936 Pool := Entity (Expression (Renamed_Object (Pool)));
3939 Set_Associated_Storage_Pool (U_Ent, Pool);
3941 elsif Nkind (Expr) = N_Type_Conversion
3942 and then Is_Entity_Name (Expression (Expr))
3943 and then Nkind (Original_Node (Expr)) = N_Attribute_Reference
3945 Pool := Entity (Expression (Expr));
3946 Set_Associated_Storage_Pool (U_Ent, Pool);
3949 Error_Msg_N ("incorrect reference to a Storage Pool", Expr);
3958 -- Storage_Size attribute definition clause
3960 when Attribute_Storage_Size => Storage_Size : declare
3961 Btype : constant Entity_Id := Base_Type (U_Ent);
3964 if Is_Task_Type (U_Ent) then
3965 Check_Restriction (No_Obsolescent_Features, N);
3967 if Warn_On_Obsolescent_Feature then
3969 ("?j?storage size clause for task is an " &
3970 "obsolescent feature (RM J.9)", N);
3971 Error_Msg_N ("\?j?use Storage_Size pragma instead", N);
3977 if not Is_Access_Type (U_Ent)
3978 and then Ekind (U_Ent) /= E_Task_Type
3980 Error_Msg_N ("storage size cannot be given for &", Nam);
3982 elsif Is_Access_Type (U_Ent) and Is_Derived_Type (U_Ent) then
3984 ("storage size cannot be given for a derived access type",
3987 elsif Duplicate_Clause then
3991 Analyze_And_Resolve (Expr, Any_Integer);
3993 if Is_Access_Type (U_Ent) then
3994 if Present (Associated_Storage_Pool (U_Ent)) then
3995 Error_Msg_N ("storage pool already given for &", Nam);
3999 if Is_OK_Static_Expression (Expr)
4000 and then Expr_Value (Expr) = 0
4002 Set_No_Pool_Assigned (Btype);
4006 Set_Has_Storage_Size_Clause (Btype);
4014 when Attribute_Stream_Size => Stream_Size : declare
4015 Size : constant Uint := Static_Integer (Expr);
4018 if Ada_Version <= Ada_95 then
4019 Check_Restriction (No_Implementation_Attributes, N);
4022 if Duplicate_Clause then
4025 elsif Is_Elementary_Type (U_Ent) then
4026 if Size /= System_Storage_Unit
4028 Size /= System_Storage_Unit * 2
4030 Size /= System_Storage_Unit * 4
4032 Size /= System_Storage_Unit * 8
4034 Error_Msg_Uint_1 := UI_From_Int (System_Storage_Unit);
4036 ("stream size for elementary type must be a"
4037 & " power of 2 and at least ^", N);
4039 elsif RM_Size (U_Ent) > Size then
4040 Error_Msg_Uint_1 := RM_Size (U_Ent);
4042 ("stream size for elementary type must be a"
4043 & " power of 2 and at least ^", N);
4046 Set_Has_Stream_Size_Clause (U_Ent);
4049 Error_Msg_N ("Stream_Size cannot be given for &", Nam);
4057 -- Value_Size attribute definition clause
4059 when Attribute_Value_Size => Value_Size : declare
4060 Size : constant Uint := Static_Integer (Expr);
4064 if not Is_Type (U_Ent) then
4065 Error_Msg_N ("Value_Size cannot be given for &", Nam);
4067 elsif Duplicate_Clause then
4070 elsif Is_Array_Type (U_Ent)
4071 and then not Is_Constrained (U_Ent)
4074 ("Value_Size cannot be given for unconstrained array", Nam);
4077 if Is_Elementary_Type (U_Ent) then
4078 Check_Size (Expr, U_Ent, Size, Biased);
4079 Set_Biased (U_Ent, N, "value size clause", Biased);
4082 Set_RM_Size (U_Ent, Size);
4086 -----------------------
4087 -- Variable_Indexing --
4088 -----------------------
4090 when Attribute_Variable_Indexing =>
4091 Check_Indexing_Functions;
4097 when Attribute_Write =>
4098 Analyze_Stream_TSS_Definition (TSS_Stream_Write);
4099 Set_Has_Specified_Stream_Write (Ent);
4101 -- All other attributes cannot be set
4105 ("attribute& cannot be set with definition clause", N);
4108 -- The test for the type being frozen must be performed after any
4109 -- expression the clause has been analyzed since the expression itself
4110 -- might cause freezing that makes the clause illegal.
4112 if Rep_Item_Too_Late (U_Ent, N, FOnly) then
4115 end Analyze_Attribute_Definition_Clause;
4117 ----------------------------
4118 -- Analyze_Code_Statement --
4119 ----------------------------
4121 procedure Analyze_Code_Statement (N : Node_Id) is
4122 HSS : constant Node_Id := Parent (N);
4123 SBody : constant Node_Id := Parent (HSS);
4124 Subp : constant Entity_Id := Current_Scope;
4131 -- Analyze and check we get right type, note that this implements the
4132 -- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that
4133 -- is the only way that Asm_Insn could possibly be visible.
4135 Analyze_And_Resolve (Expression (N));
4137 if Etype (Expression (N)) = Any_Type then
4139 elsif Etype (Expression (N)) /= RTE (RE_Asm_Insn) then
4140 Error_Msg_N ("incorrect type for code statement", N);
4144 Check_Code_Statement (N);
4146 -- Make sure we appear in the handled statement sequence of a
4147 -- subprogram (RM 13.8(3)).
4149 if Nkind (HSS) /= N_Handled_Sequence_Of_Statements
4150 or else Nkind (SBody) /= N_Subprogram_Body
4153 ("code statement can only appear in body of subprogram", N);
4157 -- Do remaining checks (RM 13.8(3)) if not already done
4159 if not Is_Machine_Code_Subprogram (Subp) then
4160 Set_Is_Machine_Code_Subprogram (Subp);
4162 -- No exception handlers allowed
4164 if Present (Exception_Handlers (HSS)) then
4166 ("exception handlers not permitted in machine code subprogram",
4167 First (Exception_Handlers (HSS)));
4170 -- No declarations other than use clauses and pragmas (we allow
4171 -- certain internally generated declarations as well).
4173 Decl := First (Declarations (SBody));
4174 while Present (Decl) loop
4175 DeclO := Original_Node (Decl);
4176 if Comes_From_Source (DeclO)
4177 and not Nkind_In (DeclO, N_Pragma,
4178 N_Use_Package_Clause,
4180 N_Implicit_Label_Declaration)
4183 ("this declaration not allowed in machine code subprogram",
4190 -- No statements other than code statements, pragmas, and labels.
4191 -- Again we allow certain internally generated statements.
4193 -- In Ada 2012, qualified expressions are names, and the code
4194 -- statement is initially parsed as a procedure call.
4196 Stmt := First (Statements (HSS));
4197 while Present (Stmt) loop
4198 StmtO := Original_Node (Stmt);
4200 -- A procedure call transformed into a code statement is OK.
4202 if Ada_Version >= Ada_2012
4203 and then Nkind (StmtO) = N_Procedure_Call_Statement
4204 and then Nkind (Name (StmtO)) = N_Qualified_Expression
4208 elsif Comes_From_Source (StmtO)
4209 and then not Nkind_In (StmtO, N_Pragma,
4214 ("this statement is not allowed in machine code subprogram",
4221 end Analyze_Code_Statement;
4223 -----------------------------------------------
4224 -- Analyze_Enumeration_Representation_Clause --
4225 -----------------------------------------------
4227 procedure Analyze_Enumeration_Representation_Clause (N : Node_Id) is
4228 Ident : constant Node_Id := Identifier (N);
4229 Aggr : constant Node_Id := Array_Aggregate (N);
4230 Enumtype : Entity_Id;
4237 Err : Boolean := False;
4238 -- Set True to avoid cascade errors and crashes on incorrect source code
4240 Lo : constant Uint := Expr_Value (Type_Low_Bound (Universal_Integer));
4241 Hi : constant Uint := Expr_Value (Type_High_Bound (Universal_Integer));
4242 -- Allowed range of universal integer (= allowed range of enum lit vals)
4246 -- Minimum and maximum values of entries
4249 -- Pointer to node for literal providing max value
4252 if Ignore_Rep_Clauses then
4256 -- First some basic error checks
4259 Enumtype := Entity (Ident);
4261 if Enumtype = Any_Type
4262 or else Rep_Item_Too_Early (Enumtype, N)
4266 Enumtype := Underlying_Type (Enumtype);
4269 if not Is_Enumeration_Type (Enumtype) then
4271 ("enumeration type required, found}",
4272 Ident, First_Subtype (Enumtype));
4276 -- Ignore rep clause on generic actual type. This will already have
4277 -- been flagged on the template as an error, and this is the safest
4278 -- way to ensure we don't get a junk cascaded message in the instance.
4280 if Is_Generic_Actual_Type (Enumtype) then
4283 -- Type must be in current scope
4285 elsif Scope (Enumtype) /= Current_Scope then
4286 Error_Msg_N ("type must be declared in this scope", Ident);
4289 -- Type must be a first subtype
4291 elsif not Is_First_Subtype (Enumtype) then
4292 Error_Msg_N ("cannot give enumeration rep clause for subtype", N);
4295 -- Ignore duplicate rep clause
4297 elsif Has_Enumeration_Rep_Clause (Enumtype) then
4298 Error_Msg_N ("duplicate enumeration rep clause ignored", N);
4301 -- Don't allow rep clause for standard [wide_[wide_]]character
4303 elsif Is_Standard_Character_Type (Enumtype) then
4304 Error_Msg_N ("enumeration rep clause not allowed for this type", N);
4307 -- Check that the expression is a proper aggregate (no parentheses)
4309 elsif Paren_Count (Aggr) /= 0 then
4311 ("extra parentheses surrounding aggregate not allowed",
4315 -- All tests passed, so set rep clause in place
4318 Set_Has_Enumeration_Rep_Clause (Enumtype);
4319 Set_Has_Enumeration_Rep_Clause (Base_Type (Enumtype));
4322 -- Now we process the aggregate. Note that we don't use the normal
4323 -- aggregate code for this purpose, because we don't want any of the
4324 -- normal expansion activities, and a number of special semantic
4325 -- rules apply (including the component type being any integer type)
4327 Elit := First_Literal (Enumtype);
4329 -- First the positional entries if any
4331 if Present (Expressions (Aggr)) then
4332 Expr := First (Expressions (Aggr));
4333 while Present (Expr) loop
4335 Error_Msg_N ("too many entries in aggregate", Expr);
4339 Val := Static_Integer (Expr);
4341 -- Err signals that we found some incorrect entries processing
4342 -- the list. The final checks for completeness and ordering are
4343 -- skipped in this case.
4345 if Val = No_Uint then
4347 elsif Val < Lo or else Hi < Val then
4348 Error_Msg_N ("value outside permitted range", Expr);
4352 Set_Enumeration_Rep (Elit, Val);
4353 Set_Enumeration_Rep_Expr (Elit, Expr);
4359 -- Now process the named entries if present
4361 if Present (Component_Associations (Aggr)) then
4362 Assoc := First (Component_Associations (Aggr));
4363 while Present (Assoc) loop
4364 Choice := First (Choices (Assoc));
4366 if Present (Next (Choice)) then
4368 ("multiple choice not allowed here", Next (Choice));
4372 if Nkind (Choice) = N_Others_Choice then
4373 Error_Msg_N ("others choice not allowed here", Choice);
4376 elsif Nkind (Choice) = N_Range then
4378 -- ??? should allow zero/one element range here
4380 Error_Msg_N ("range not allowed here", Choice);
4384 Analyze_And_Resolve (Choice, Enumtype);
4386 if Error_Posted (Choice) then
4391 if Is_Entity_Name (Choice)
4392 and then Is_Type (Entity (Choice))
4394 Error_Msg_N ("subtype name not allowed here", Choice);
4397 -- ??? should allow static subtype with zero/one entry
4399 elsif Etype (Choice) = Base_Type (Enumtype) then
4400 if not Is_Static_Expression (Choice) then
4401 Flag_Non_Static_Expr
4402 ("non-static expression used for choice!", Choice);
4406 Elit := Expr_Value_E (Choice);
4408 if Present (Enumeration_Rep_Expr (Elit)) then
4410 Sloc (Enumeration_Rep_Expr (Elit));
4412 ("representation for& previously given#",
4417 Set_Enumeration_Rep_Expr (Elit, Expression (Assoc));
4419 Expr := Expression (Assoc);
4420 Val := Static_Integer (Expr);
4422 if Val = No_Uint then
4425 elsif Val < Lo or else Hi < Val then
4426 Error_Msg_N ("value outside permitted range", Expr);
4430 Set_Enumeration_Rep (Elit, Val);
4440 -- Aggregate is fully processed. Now we check that a full set of
4441 -- representations was given, and that they are in range and in order.
4442 -- These checks are only done if no other errors occurred.
4448 Elit := First_Literal (Enumtype);
4449 while Present (Elit) loop
4450 if No (Enumeration_Rep_Expr (Elit)) then
4451 Error_Msg_NE ("missing representation for&!", N, Elit);
4454 Val := Enumeration_Rep (Elit);
4456 if Min = No_Uint then
4460 if Val /= No_Uint then
4461 if Max /= No_Uint and then Val <= Max then
4463 ("enumeration value for& not ordered!",
4464 Enumeration_Rep_Expr (Elit), Elit);
4467 Max_Node := Enumeration_Rep_Expr (Elit);
4471 -- If there is at least one literal whose representation is not
4472 -- equal to the Pos value, then note that this enumeration type
4473 -- has a non-standard representation.
4475 if Val /= Enumeration_Pos (Elit) then
4476 Set_Has_Non_Standard_Rep (Base_Type (Enumtype));
4483 -- Now set proper size information
4486 Minsize : Uint := UI_From_Int (Minimum_Size (Enumtype));
4489 if Has_Size_Clause (Enumtype) then
4491 -- All OK, if size is OK now
4493 if RM_Size (Enumtype) >= Minsize then
4497 -- Try if we can get by with biasing
4500 UI_From_Int (Minimum_Size (Enumtype, Biased => True));
4502 -- Error message if even biasing does not work
4504 if RM_Size (Enumtype) < Minsize then
4505 Error_Msg_Uint_1 := RM_Size (Enumtype);
4506 Error_Msg_Uint_2 := Max;
4508 ("previously given size (^) is too small "
4509 & "for this value (^)", Max_Node);
4511 -- If biasing worked, indicate that we now have biased rep
4515 (Enumtype, Size_Clause (Enumtype), "size clause");
4520 Set_RM_Size (Enumtype, Minsize);
4521 Set_Enum_Esize (Enumtype);
4524 Set_RM_Size (Base_Type (Enumtype), RM_Size (Enumtype));
4525 Set_Esize (Base_Type (Enumtype), Esize (Enumtype));
4526 Set_Alignment (Base_Type (Enumtype), Alignment (Enumtype));
4530 -- We repeat the too late test in case it froze itself!
4532 if Rep_Item_Too_Late (Enumtype, N) then
4535 end Analyze_Enumeration_Representation_Clause;
4537 ----------------------------
4538 -- Analyze_Free_Statement --
4539 ----------------------------
4541 procedure Analyze_Free_Statement (N : Node_Id) is
4543 Analyze (Expression (N));
4544 end Analyze_Free_Statement;
4546 ---------------------------
4547 -- Analyze_Freeze_Entity --
4548 ---------------------------
4550 procedure Analyze_Freeze_Entity (N : Node_Id) is
4551 E : constant Entity_Id := Entity (N);
4554 -- Remember that we are processing a freezing entity. Required to
4555 -- ensure correct decoration of internal entities associated with
4556 -- interfaces (see New_Overloaded_Entity).
4558 Inside_Freezing_Actions := Inside_Freezing_Actions + 1;
4560 -- For tagged types covering interfaces add internal entities that link
4561 -- the primitives of the interfaces with the primitives that cover them.
4562 -- Note: These entities were originally generated only when generating
4563 -- code because their main purpose was to provide support to initialize
4564 -- the secondary dispatch tables. They are now generated also when
4565 -- compiling with no code generation to provide ASIS the relationship
4566 -- between interface primitives and tagged type primitives. They are
4567 -- also used to locate primitives covering interfaces when processing
4568 -- generics (see Derive_Subprograms).
4570 if Ada_Version >= Ada_2005
4571 and then Ekind (E) = E_Record_Type
4572 and then Is_Tagged_Type (E)
4573 and then not Is_Interface (E)
4574 and then Has_Interfaces (E)
4576 -- This would be a good common place to call the routine that checks
4577 -- overriding of interface primitives (and thus factorize calls to
4578 -- Check_Abstract_Overriding located at different contexts in the
4579 -- compiler). However, this is not possible because it causes
4580 -- spurious errors in case of late overriding.
4582 Add_Internal_Interface_Entities (E);
4587 if Ekind (E) = E_Record_Type
4588 and then Is_CPP_Class (E)
4589 and then Is_Tagged_Type (E)
4590 and then Tagged_Type_Expansion
4591 and then Expander_Active
4593 if CPP_Num_Prims (E) = 0 then
4595 -- If the CPP type has user defined components then it must import
4596 -- primitives from C++. This is required because if the C++ class
4597 -- has no primitives then the C++ compiler does not added the _tag
4598 -- component to the type.
4600 pragma Assert (Chars (First_Entity (E)) = Name_uTag);
4602 if First_Entity (E) /= Last_Entity (E) then
4604 ("'C'P'P type must import at least one primitive from C++??",
4609 -- Check that all its primitives are abstract or imported from C++.
4610 -- Check also availability of the C++ constructor.
4613 Has_Constructors : constant Boolean := Has_CPP_Constructors (E);
4615 Error_Reported : Boolean := False;
4619 Elmt := First_Elmt (Primitive_Operations (E));
4620 while Present (Elmt) loop
4621 Prim := Node (Elmt);
4623 if Comes_From_Source (Prim) then
4624 if Is_Abstract_Subprogram (Prim) then
4627 elsif not Is_Imported (Prim)
4628 or else Convention (Prim) /= Convention_CPP
4631 ("primitives of 'C'P'P types must be imported from C++ "
4632 & "or abstract??", Prim);
4634 elsif not Has_Constructors
4635 and then not Error_Reported
4637 Error_Msg_Name_1 := Chars (E);
4639 ("??'C'P'P constructor required for type %", Prim);
4640 Error_Reported := True;
4649 -- Check Ada derivation of CPP type
4652 and then Tagged_Type_Expansion
4653 and then Ekind (E) = E_Record_Type
4654 and then Etype (E) /= E
4655 and then Is_CPP_Class (Etype (E))
4656 and then CPP_Num_Prims (Etype (E)) > 0
4657 and then not Is_CPP_Class (E)
4658 and then not Has_CPP_Constructors (Etype (E))
4660 -- If the parent has C++ primitives but it has no constructor then
4661 -- check that all the primitives are overridden in this derivation;
4662 -- otherwise the constructor of the parent is needed to build the
4670 Elmt := First_Elmt (Primitive_Operations (E));
4671 while Present (Elmt) loop
4672 Prim := Node (Elmt);
4674 if not Is_Abstract_Subprogram (Prim)
4675 and then No (Interface_Alias (Prim))
4676 and then Find_Dispatching_Type (Ultimate_Alias (Prim)) /= E
4678 Error_Msg_Name_1 := Chars (Etype (E));
4680 ("'C'P'P constructor required for parent type %", E);
4689 Inside_Freezing_Actions := Inside_Freezing_Actions - 1;
4691 -- If we have a type with predicates, build predicate function
4693 if Is_Type (E) and then Has_Predicates (E) then
4694 Build_Predicate_Functions (E, N);
4697 -- If type has delayed aspects, this is where we do the preanalysis at
4698 -- the freeze point, as part of the consistent visibility check. Note
4699 -- that this must be done after calling Build_Predicate_Functions or
4700 -- Build_Invariant_Procedure since these subprograms fix occurrences of
4701 -- the subtype name in the saved expression so that they will not cause
4702 -- trouble in the preanalysis.
4704 if Has_Delayed_Aspects (E)
4705 and then Scope (E) = Current_Scope
4707 -- Retrieve the visibility to the discriminants in order to properly
4708 -- analyze the aspects.
4710 Push_Scope_And_Install_Discriminants (E);
4716 -- Look for aspect specification entries for this entity
4718 Ritem := First_Rep_Item (E);
4719 while Present (Ritem) loop
4720 if Nkind (Ritem) = N_Aspect_Specification
4721 and then Entity (Ritem) = E
4722 and then Is_Delayed_Aspect (Ritem)
4724 Check_Aspect_At_Freeze_Point (Ritem);
4727 Next_Rep_Item (Ritem);
4731 Uninstall_Discriminants_And_Pop_Scope (E);
4733 end Analyze_Freeze_Entity;
4735 ------------------------------------------
4736 -- Analyze_Record_Representation_Clause --
4737 ------------------------------------------
4739 -- Note: we check as much as we can here, but we can't do any checks
4740 -- based on the position values (e.g. overlap checks) until freeze time
4741 -- because especially in Ada 2005 (machine scalar mode), the processing
4742 -- for non-standard bit order can substantially change the positions.
4743 -- See procedure Check_Record_Representation_Clause (called from Freeze)
4744 -- for the remainder of this processing.
4746 procedure Analyze_Record_Representation_Clause (N : Node_Id) is
4747 Ident : constant Node_Id := Identifier (N);
4752 Hbit : Uint := Uint_0;
4756 Rectype : Entity_Id;
4759 function Is_Inherited (Comp : Entity_Id) return Boolean;
4760 -- True if Comp is an inherited component in a record extension
4766 function Is_Inherited (Comp : Entity_Id) return Boolean is
4767 Comp_Base : Entity_Id;
4770 if Ekind (Rectype) = E_Record_Subtype then
4771 Comp_Base := Original_Record_Component (Comp);
4776 return Comp_Base /= Original_Record_Component (Comp_Base);
4781 Is_Record_Extension : Boolean;
4782 -- True if Rectype is a record extension
4784 CR_Pragma : Node_Id := Empty;
4785 -- Points to N_Pragma node if Complete_Representation pragma present
4787 -- Start of processing for Analyze_Record_Representation_Clause
4790 if Ignore_Rep_Clauses then
4795 Rectype := Entity (Ident);
4797 if Rectype = Any_Type or else Rep_Item_Too_Early (Rectype, N) then
4800 Rectype := Underlying_Type (Rectype);
4803 -- First some basic error checks
4805 if not Is_Record_Type (Rectype) then
4807 ("record type required, found}", Ident, First_Subtype (Rectype));
4810 elsif Scope (Rectype) /= Current_Scope then
4811 Error_Msg_N ("type must be declared in this scope", N);
4814 elsif not Is_First_Subtype (Rectype) then
4815 Error_Msg_N ("cannot give record rep clause for subtype", N);
4818 elsif Has_Record_Rep_Clause (Rectype) then
4819 Error_Msg_N ("duplicate record rep clause ignored", N);
4822 elsif Rep_Item_Too_Late (Rectype, N) then
4826 -- We know we have a first subtype, now possibly go the the anonymous
4827 -- base type to determine whether Rectype is a record extension.
4829 Recdef := Type_Definition (Declaration_Node (Base_Type (Rectype)));
4830 Is_Record_Extension :=
4831 Nkind (Recdef) = N_Derived_Type_Definition
4832 and then Present (Record_Extension_Part (Recdef));
4834 if Present (Mod_Clause (N)) then
4836 Loc : constant Source_Ptr := Sloc (N);
4837 M : constant Node_Id := Mod_Clause (N);
4838 P : constant List_Id := Pragmas_Before (M);
4842 pragma Warnings (Off, Mod_Val);
4845 Check_Restriction (No_Obsolescent_Features, Mod_Clause (N));
4847 if Warn_On_Obsolescent_Feature then
4849 ("?j?mod clause is an obsolescent feature (RM J.8)", N);
4851 ("\?j?use alignment attribute definition clause instead", N);
4858 -- In ASIS_Mode mode, expansion is disabled, but we must convert
4859 -- the Mod clause into an alignment clause anyway, so that the
4860 -- back-end can compute and back-annotate properly the size and
4861 -- alignment of types that may include this record.
4863 -- This seems dubious, this destroys the source tree in a manner
4864 -- not detectable by ASIS ???
4866 if Operating_Mode = Check_Semantics and then ASIS_Mode then
4868 Make_Attribute_Definition_Clause (Loc,
4869 Name => New_Reference_To (Base_Type (Rectype), Loc),
4870 Chars => Name_Alignment,
4871 Expression => Relocate_Node (Expression (M)));
4873 Set_From_At_Mod (AtM_Nod);
4874 Insert_After (N, AtM_Nod);
4875 Mod_Val := Get_Alignment_Value (Expression (AtM_Nod));
4876 Set_Mod_Clause (N, Empty);
4879 -- Get the alignment value to perform error checking
4881 Mod_Val := Get_Alignment_Value (Expression (M));
4886 -- For untagged types, clear any existing component clauses for the
4887 -- type. If the type is derived, this is what allows us to override
4888 -- a rep clause for the parent. For type extensions, the representation
4889 -- of the inherited components is inherited, so we want to keep previous
4890 -- component clauses for completeness.
4892 if not Is_Tagged_Type (Rectype) then
4893 Comp := First_Component_Or_Discriminant (Rectype);
4894 while Present (Comp) loop
4895 Set_Component_Clause (Comp, Empty);
4896 Next_Component_Or_Discriminant (Comp);
4900 -- All done if no component clauses
4902 CC := First (Component_Clauses (N));
4908 -- A representation like this applies to the base type
4910 Set_Has_Record_Rep_Clause (Base_Type (Rectype));
4911 Set_Has_Non_Standard_Rep (Base_Type (Rectype));
4912 Set_Has_Specified_Layout (Base_Type (Rectype));
4914 -- Process the component clauses
4916 while Present (CC) loop
4920 if Nkind (CC) = N_Pragma then
4923 -- The only pragma of interest is Complete_Representation
4925 if Pragma_Name (CC) = Name_Complete_Representation then
4929 -- Processing for real component clause
4932 Posit := Static_Integer (Position (CC));
4933 Fbit := Static_Integer (First_Bit (CC));
4934 Lbit := Static_Integer (Last_Bit (CC));
4937 and then Fbit /= No_Uint
4938 and then Lbit /= No_Uint
4942 ("position cannot be negative", Position (CC));
4946 ("first bit cannot be negative", First_Bit (CC));
4948 -- The Last_Bit specified in a component clause must not be
4949 -- less than the First_Bit minus one (RM-13.5.1(10)).
4951 elsif Lbit < Fbit - 1 then
4953 ("last bit cannot be less than first bit minus one",
4956 -- Values look OK, so find the corresponding record component
4957 -- Even though the syntax allows an attribute reference for
4958 -- implementation-defined components, GNAT does not allow the
4959 -- tag to get an explicit position.
4961 elsif Nkind (Component_Name (CC)) = N_Attribute_Reference then
4962 if Attribute_Name (Component_Name (CC)) = Name_Tag then
4963 Error_Msg_N ("position of tag cannot be specified", CC);
4965 Error_Msg_N ("illegal component name", CC);
4969 Comp := First_Entity (Rectype);
4970 while Present (Comp) loop
4971 exit when Chars (Comp) = Chars (Component_Name (CC));
4977 -- Maybe component of base type that is absent from
4978 -- statically constrained first subtype.
4980 Comp := First_Entity (Base_Type (Rectype));
4981 while Present (Comp) loop
4982 exit when Chars (Comp) = Chars (Component_Name (CC));
4989 ("component clause is for non-existent field", CC);
4991 -- Ada 2012 (AI05-0026): Any name that denotes a
4992 -- discriminant of an object of an unchecked union type
4993 -- shall not occur within a record_representation_clause.
4995 -- The general restriction of using record rep clauses on
4996 -- Unchecked_Union types has now been lifted. Since it is
4997 -- possible to introduce a record rep clause which mentions
4998 -- the discriminant of an Unchecked_Union in non-Ada 2012
4999 -- code, this check is applied to all versions of the
5002 elsif Ekind (Comp) = E_Discriminant
5003 and then Is_Unchecked_Union (Rectype)
5006 ("cannot reference discriminant of unchecked union",
5007 Component_Name (CC));
5009 elsif Is_Record_Extension and then Is_Inherited (Comp) then
5011 ("component clause not allowed for inherited "
5012 & "component&", CC, Comp);
5014 elsif Present (Component_Clause (Comp)) then
5016 -- Diagnose duplicate rep clause, or check consistency
5017 -- if this is an inherited component. In a double fault,
5018 -- there may be a duplicate inconsistent clause for an
5019 -- inherited component.
5021 if Scope (Original_Record_Component (Comp)) = Rectype
5022 or else Parent (Component_Clause (Comp)) = N
5024 Error_Msg_Sloc := Sloc (Component_Clause (Comp));
5025 Error_Msg_N ("component clause previously given#", CC);
5029 Rep1 : constant Node_Id := Component_Clause (Comp);
5031 if Intval (Position (Rep1)) /=
5032 Intval (Position (CC))
5033 or else Intval (First_Bit (Rep1)) /=
5034 Intval (First_Bit (CC))
5035 or else Intval (Last_Bit (Rep1)) /=
5036 Intval (Last_Bit (CC))
5039 ("component clause inconsistent "
5040 & "with representation of ancestor", CC);
5042 elsif Warn_On_Redundant_Constructs then
5044 ("?r?redundant confirming component clause "
5045 & "for component!", CC);
5050 -- Normal case where this is the first component clause we
5051 -- have seen for this entity, so set it up properly.
5054 -- Make reference for field in record rep clause and set
5055 -- appropriate entity field in the field identifier.
5058 (Comp, Component_Name (CC), Set_Ref => False);
5059 Set_Entity (Component_Name (CC), Comp);
5061 -- Update Fbit and Lbit to the actual bit number
5063 Fbit := Fbit + UI_From_Int (SSU) * Posit;
5064 Lbit := Lbit + UI_From_Int (SSU) * Posit;
5066 if Has_Size_Clause (Rectype)
5067 and then RM_Size (Rectype) <= Lbit
5070 ("bit number out of range of specified size",
5073 Set_Component_Clause (Comp, CC);
5074 Set_Component_Bit_Offset (Comp, Fbit);
5075 Set_Esize (Comp, 1 + (Lbit - Fbit));
5076 Set_Normalized_First_Bit (Comp, Fbit mod SSU);
5077 Set_Normalized_Position (Comp, Fbit / SSU);
5079 if Warn_On_Overridden_Size
5080 and then Has_Size_Clause (Etype (Comp))
5081 and then RM_Size (Etype (Comp)) /= Esize (Comp)
5084 ("?S?component size overrides size clause for&",
5085 Component_Name (CC), Etype (Comp));
5088 -- This information is also set in the corresponding
5089 -- component of the base type, found by accessing the
5090 -- Original_Record_Component link if it is present.
5092 Ocomp := Original_Record_Component (Comp);
5099 (Component_Name (CC),
5105 (Comp, First_Node (CC), "component clause", Biased);
5107 if Present (Ocomp) then
5108 Set_Component_Clause (Ocomp, CC);
5109 Set_Component_Bit_Offset (Ocomp, Fbit);
5110 Set_Normalized_First_Bit (Ocomp, Fbit mod SSU);
5111 Set_Normalized_Position (Ocomp, Fbit / SSU);
5112 Set_Esize (Ocomp, 1 + (Lbit - Fbit));
5114 Set_Normalized_Position_Max
5115 (Ocomp, Normalized_Position (Ocomp));
5117 -- Note: we don't use Set_Biased here, because we
5118 -- already gave a warning above if needed, and we
5119 -- would get a duplicate for the same name here.
5121 Set_Has_Biased_Representation
5122 (Ocomp, Has_Biased_Representation (Comp));
5125 if Esize (Comp) < 0 then
5126 Error_Msg_N ("component size is negative", CC);
5137 -- Check missing components if Complete_Representation pragma appeared
5139 if Present (CR_Pragma) then
5140 Comp := First_Component_Or_Discriminant (Rectype);
5141 while Present (Comp) loop
5142 if No (Component_Clause (Comp)) then
5144 ("missing component clause for &", CR_Pragma, Comp);
5147 Next_Component_Or_Discriminant (Comp);
5150 -- Give missing components warning if required
5152 elsif Warn_On_Unrepped_Components then
5154 Num_Repped_Components : Nat := 0;
5155 Num_Unrepped_Components : Nat := 0;
5158 -- First count number of repped and unrepped components
5160 Comp := First_Component_Or_Discriminant (Rectype);
5161 while Present (Comp) loop
5162 if Present (Component_Clause (Comp)) then
5163 Num_Repped_Components := Num_Repped_Components + 1;
5165 Num_Unrepped_Components := Num_Unrepped_Components + 1;
5168 Next_Component_Or_Discriminant (Comp);
5171 -- We are only interested in the case where there is at least one
5172 -- unrepped component, and at least half the components have rep
5173 -- clauses. We figure that if less than half have them, then the
5174 -- partial rep clause is really intentional. If the component
5175 -- type has no underlying type set at this point (as for a generic
5176 -- formal type), we don't know enough to give a warning on the
5179 if Num_Unrepped_Components > 0
5180 and then Num_Unrepped_Components < Num_Repped_Components
5182 Comp := First_Component_Or_Discriminant (Rectype);
5183 while Present (Comp) loop
5184 if No (Component_Clause (Comp))
5185 and then Comes_From_Source (Comp)
5186 and then Present (Underlying_Type (Etype (Comp)))
5187 and then (Is_Scalar_Type (Underlying_Type (Etype (Comp)))
5188 or else Size_Known_At_Compile_Time
5189 (Underlying_Type (Etype (Comp))))
5190 and then not Has_Warnings_Off (Rectype)
5192 Error_Msg_Sloc := Sloc (Comp);
5194 ("?C?no component clause given for & declared #",
5198 Next_Component_Or_Discriminant (Comp);
5203 end Analyze_Record_Representation_Clause;
5205 -------------------------------------------
5206 -- Build_Invariant_Procedure_Declaration --
5207 -------------------------------------------
5209 function Build_Invariant_Procedure_Declaration
5210 (Typ : Entity_Id) return Node_Id
5212 Loc : constant Source_Ptr := Sloc (Typ);
5213 Object_Entity : constant Entity_Id :=
5214 Make_Defining_Identifier (Loc, New_Internal_Name ('I'));
5219 Set_Etype (Object_Entity, Typ);
5221 -- Check for duplicate definiations.
5223 if Has_Invariants (Typ) and then Present (Invariant_Procedure (Typ)) then
5228 Make_Defining_Identifier (Loc,
5229 Chars => New_External_Name (Chars (Typ), "Invariant"));
5230 Set_Has_Invariants (Typ);
5231 Set_Ekind (SId, E_Procedure);
5232 Set_Is_Invariant_Procedure (SId);
5233 Set_Invariant_Procedure (Typ, SId);
5236 Make_Procedure_Specification (Loc,
5237 Defining_Unit_Name => SId,
5238 Parameter_Specifications => New_List (
5239 Make_Parameter_Specification (Loc,
5240 Defining_Identifier => Object_Entity,
5241 Parameter_Type => New_Occurrence_Of (Typ, Loc))));
5243 return Make_Subprogram_Declaration (Loc, Specification => Spec);
5244 end Build_Invariant_Procedure_Declaration;
5246 -------------------------------
5247 -- Build_Invariant_Procedure --
5248 -------------------------------
5250 -- The procedure that is constructed here has the form
5252 -- procedure typInvariant (Ixxx : typ) is
5254 -- pragma Check (Invariant, exp, "failed invariant from xxx");
5255 -- pragma Check (Invariant, exp, "failed invariant from xxx");
5257 -- pragma Check (Invariant, exp, "failed inherited invariant from xxx");
5259 -- end typInvariant;
5261 procedure Build_Invariant_Procedure (Typ : Entity_Id; N : Node_Id) is
5262 Loc : constant Source_Ptr := Sloc (Typ);
5269 Visible_Decls : constant List_Id := Visible_Declarations (N);
5270 Private_Decls : constant List_Id := Private_Declarations (N);
5272 procedure Add_Invariants (T : Entity_Id; Inherit : Boolean);
5273 -- Appends statements to Stmts for any invariants in the rep item chain
5274 -- of the given type. If Inherit is False, then we only process entries
5275 -- on the chain for the type Typ. If Inherit is True, then we ignore any
5276 -- Invariant aspects, but we process all Invariant'Class aspects, adding
5277 -- "inherited" to the exception message and generating an informational
5278 -- message about the inheritance of an invariant.
5280 Object_Name : Name_Id;
5281 -- Name for argument of invariant procedure
5283 Object_Entity : Node_Id;
5284 -- The entity of the formal for the procedure
5286 --------------------
5287 -- Add_Invariants --
5288 --------------------
5290 procedure Add_Invariants (T : Entity_Id; Inherit : Boolean) is
5300 procedure Replace_Type_Reference (N : Node_Id);
5301 -- Replace a single occurrence N of the subtype name with a reference
5302 -- to the formal of the predicate function. N can be an identifier
5303 -- referencing the subtype, or a selected component, representing an
5304 -- appropriately qualified occurrence of the subtype name.
5306 procedure Replace_Type_References is
5307 new Replace_Type_References_Generic (Replace_Type_Reference);
5308 -- Traverse an expression replacing all occurrences of the subtype
5309 -- name with appropriate references to the object that is the formal
5310 -- parameter of the predicate function. Note that we must ensure
5311 -- that the type and entity information is properly set in the
5312 -- replacement node, since we will do a Preanalyze call of this
5313 -- expression without proper visibility of the procedure argument.
5315 ----------------------------
5316 -- Replace_Type_Reference --
5317 ----------------------------
5319 -- Note: See comments in Add_Predicates.Replace_Type_Reference
5320 -- regarding handling of Sloc and Comes_From_Source.
5322 procedure Replace_Type_Reference (N : Node_Id) is
5324 -- Invariant'Class, replace with T'Class (obj)
5326 if Class_Present (Ritem) then
5328 Make_Type_Conversion (Sloc (N),
5330 Make_Attribute_Reference (Sloc (N),
5331 Prefix => New_Occurrence_Of (T, Sloc (N)),
5332 Attribute_Name => Name_Class),
5333 Expression => Make_Identifier (Sloc (N), Object_Name)));
5335 Set_Entity (Expression (N), Object_Entity);
5336 Set_Etype (Expression (N), Typ);
5338 -- Invariant, replace with obj
5341 Rewrite (N, Make_Identifier (Sloc (N), Object_Name));
5342 Set_Entity (N, Object_Entity);
5346 Set_Comes_From_Source (N, True);
5347 end Replace_Type_Reference;
5349 -- Start of processing for Add_Invariants
5352 Ritem := First_Rep_Item (T);
5353 while Present (Ritem) loop
5354 if Nkind (Ritem) = N_Pragma
5355 and then Pragma_Name (Ritem) = Name_Invariant
5357 Arg1 := First (Pragma_Argument_Associations (Ritem));
5358 Arg2 := Next (Arg1);
5359 Arg3 := Next (Arg2);
5361 Arg1 := Get_Pragma_Arg (Arg1);
5362 Arg2 := Get_Pragma_Arg (Arg2);
5364 -- For Inherit case, ignore Invariant, process only Class case
5367 if not Class_Present (Ritem) then
5371 -- For Inherit false, process only item for right type
5374 if Entity (Arg1) /= Typ then
5380 Stmts := Empty_List;
5383 Exp := New_Copy_Tree (Arg2);
5385 -- Preserve sloc of original pragma Invariant
5387 Loc := Sloc (Ritem);
5389 -- We need to replace any occurrences of the name of the type
5390 -- with references to the object, converted to type'Class in
5391 -- the case of Invariant'Class aspects.
5393 Replace_Type_References (Exp, Chars (T));
5395 -- If this invariant comes from an aspect, find the aspect
5396 -- specification, and replace the saved expression because
5397 -- we need the subtype references replaced for the calls to
5398 -- Preanalyze_Spec_Expressin in Check_Aspect_At_Freeze_Point
5399 -- and Check_Aspect_At_End_Of_Declarations.
5401 if From_Aspect_Specification (Ritem) then
5406 -- Loop to find corresponding aspect, note that this
5407 -- must be present given the pragma is marked delayed.
5409 Aitem := Next_Rep_Item (Ritem);
5410 while Present (Aitem) loop
5411 if Nkind (Aitem) = N_Aspect_Specification
5412 and then Aspect_Rep_Item (Aitem) = Ritem
5415 (Identifier (Aitem), New_Copy_Tree (Exp));
5419 Aitem := Next_Rep_Item (Aitem);
5424 -- Now we need to preanalyze the expression to properly capture
5425 -- the visibility in the visible part. The expression will not
5426 -- be analyzed for real until the body is analyzed, but that is
5427 -- at the end of the private part and has the wrong visibility.
5429 Set_Parent (Exp, N);
5430 Preanalyze_Assert_Expression (Exp, Standard_Boolean);
5432 -- Build first two arguments for Check pragma
5435 Make_Pragma_Argument_Association (Loc,
5436 Expression => Make_Identifier (Loc, Name_Invariant)),
5437 Make_Pragma_Argument_Association (Loc,
5438 Expression => Exp));
5440 -- Add message if present in Invariant pragma
5442 if Present (Arg3) then
5443 Str := Strval (Get_Pragma_Arg (Arg3));
5445 -- If inherited case, and message starts "failed invariant",
5446 -- change it to be "failed inherited invariant".
5449 String_To_Name_Buffer (Str);
5451 if Name_Buffer (1 .. 16) = "failed invariant" then
5452 Insert_Str_In_Name_Buffer ("inherited ", 8);
5453 Str := String_From_Name_Buffer;
5458 Make_Pragma_Argument_Association (Loc,
5459 Expression => Make_String_Literal (Loc, Str)));
5462 -- Add Check pragma to list of statements
5466 Pragma_Identifier =>
5467 Make_Identifier (Loc, Name_Check),
5468 Pragma_Argument_Associations => Assoc));
5470 -- If Inherited case and option enabled, output info msg. Note
5471 -- that we know this is a case of Invariant'Class.
5473 if Inherit and Opt.List_Inherited_Aspects then
5474 Error_Msg_Sloc := Sloc (Ritem);
5476 ("?L?info: & inherits `Invariant''Class` aspect from #",
5482 Next_Rep_Item (Ritem);
5486 -- Start of processing for Build_Invariant_Procedure
5494 -- If the aspect specification exists for some view of the type, the
5495 -- declaration for the procedure has been created.
5497 if Has_Invariants (Typ) then
5498 SId := Invariant_Procedure (Typ);
5501 if Present (SId) then
5502 PDecl := Unit_Declaration_Node (SId);
5505 PDecl := Build_Invariant_Procedure_Declaration (Typ);
5508 -- Recover formal of procedure, for use in the calls to invariant
5509 -- functions (including inherited ones).
5513 (First (Parameter_Specifications (Specification (PDecl))));
5514 Object_Name := Chars (Object_Entity);
5516 -- Add invariants for the current type
5518 Add_Invariants (Typ, Inherit => False);
5520 -- Add invariants for parent types
5523 Current_Typ : Entity_Id;
5524 Parent_Typ : Entity_Id;
5529 Parent_Typ := Etype (Current_Typ);
5531 if Is_Private_Type (Parent_Typ)
5532 and then Present (Full_View (Base_Type (Parent_Typ)))
5534 Parent_Typ := Full_View (Base_Type (Parent_Typ));
5537 exit when Parent_Typ = Current_Typ;
5539 Current_Typ := Parent_Typ;
5540 Add_Invariants (Current_Typ, Inherit => True);
5544 -- Build the procedure if we generated at least one Check pragma
5546 if Stmts /= No_List then
5547 Spec := Copy_Separate_Tree (Specification (PDecl));
5550 Make_Subprogram_Body (Loc,
5551 Specification => Spec,
5552 Declarations => Empty_List,
5553 Handled_Statement_Sequence =>
5554 Make_Handled_Sequence_Of_Statements (Loc,
5555 Statements => Stmts));
5557 -- Insert procedure declaration and spec at the appropriate points.
5558 -- If declaration is already analyzed, it was processed by the
5559 -- generated pragma.
5561 if Present (Private_Decls) then
5563 -- The spec goes at the end of visible declarations, but they have
5564 -- already been analyzed, so we need to explicitly do the analyze.
5566 if not Analyzed (PDecl) then
5567 Append_To (Visible_Decls, PDecl);
5571 -- The body goes at the end of the private declarations, which we
5572 -- have not analyzed yet, so we do not need to perform an explicit
5573 -- analyze call. We skip this if there are no private declarations
5574 -- (this is an error that will be caught elsewhere);
5576 Append_To (Private_Decls, PBody);
5578 -- If the invariant appears on the full view of a type, the
5579 -- analysis of the private part is complete, and we must
5580 -- analyze the new body explicitly.
5582 if In_Private_Part (Current_Scope) then
5586 -- If there are no private declarations this may be an error that
5587 -- will be diagnosed elsewhere. However, if this is a non-private
5588 -- type that inherits invariants, it needs no completion and there
5589 -- may be no private part. In this case insert invariant procedure
5590 -- at end of current declarative list, and analyze at once, given
5591 -- that the type is about to be frozen.
5593 elsif not Is_Private_Type (Typ) then
5594 Append_To (Visible_Decls, PDecl);
5595 Append_To (Visible_Decls, PBody);
5600 end Build_Invariant_Procedure;
5602 -------------------------------
5603 -- Build_Predicate_Functions --
5604 -------------------------------
5606 -- The procedures that are constructed here has the form:
5608 -- function typPredicate (Ixxx : typ) return Boolean is
5611 -- exp1 and then exp2 and then ...
5612 -- and then typ1Predicate (typ1 (Ixxx))
5613 -- and then typ2Predicate (typ2 (Ixxx))
5615 -- end typPredicate;
5617 -- Here exp1, and exp2 are expressions from Predicate pragmas. Note that
5618 -- this is the point at which these expressions get analyzed, providing the
5619 -- required delay, and typ1, typ2, are entities from which predicates are
5620 -- inherited. Note that we do NOT generate Check pragmas, that's because we
5621 -- use this function even if checks are off, e.g. for membership tests.
5623 -- If the expression has at least one Raise_Expression, then we also build
5624 -- the typPredicateM version of the function, in which any occurence of a
5625 -- Raise_Expressioon is converted to "return False".
5627 procedure Build_Predicate_Functions (Typ : Entity_Id; N : Node_Id) is
5628 Loc : constant Source_Ptr := Sloc (Typ);
5631 -- This is the expression for the result of the function. It is
5632 -- is build by connecting the component predicates with AND THEN.
5635 -- This is the corresponding return expression for the Predicate_M
5636 -- function. It differs in that raise expressions are marked for
5637 -- special expansion (see Process_REs).
5639 Object_Name : constant Name_Id := New_Internal_Name ('I');
5640 -- Name for argument of Predicate procedure. Note that we use the same
5641 -- name for both predicate procedure. That way the reference within the
5642 -- predicate expression is the same in both functions.
5644 Object_Entity : constant Entity_Id :=
5645 Make_Defining_Identifier (Loc, Chars => Object_Name);
5646 -- Entity for argument of Predicate procedure
5648 Object_Entity_M : constant Entity_Id :=
5649 Make_Defining_Identifier (Loc, Chars => Object_Name);
5650 -- Entity for argument of Predicate_M procedure
5652 Raise_Expression_Present : Boolean := False;
5653 -- Set True if Expr has at least one Raise_Expression
5655 procedure Add_Call (T : Entity_Id);
5656 -- Includes a call to the predicate function for type T in Expr if T
5657 -- has predicates and Predicate_Function (T) is non-empty.
5659 procedure Add_Predicates;
5660 -- Appends expressions for any Predicate pragmas in the rep item chain
5661 -- Typ to Expr. Note that we look only at items for this exact entity.
5662 -- Inheritance of predicates for the parent type is done by calling the
5663 -- Predicate_Function of the parent type, using Add_Call above.
5665 function Test_RE (N : Node_Id) return Traverse_Result;
5666 -- Used in Test_REs, tests one node for being a raise expression, and if
5667 -- so sets Raise_Expression_Present True.
5669 procedure Test_REs is new Traverse_Proc (Test_RE);
5670 -- Tests to see if Expr contains any raise expressions
5672 function Process_RE (N : Node_Id) return Traverse_Result;
5673 -- Used in Process REs, tests if node N is a raise expression, and if
5674 -- so, marks it to be converted to return False.
5676 procedure Process_REs is new Traverse_Proc (Process_RE);
5677 -- Marks any raise expressions in Expr_M to return False
5679 Dynamic_Predicate_Present : Boolean := False;
5680 -- Set True if a dynamic predicate is present, results in the entire
5681 -- predicate being considered dynamic even if it looks static
5683 Static_Predicate_Present : Node_Id := Empty;
5684 -- Set to N_Pragma node for a static predicate if one is encountered.
5690 procedure Add_Call (T : Entity_Id) is
5694 if Present (T) and then Present (Predicate_Function (T)) then
5695 Set_Has_Predicates (Typ);
5697 -- Build the call to the predicate function of T
5701 (T, Convert_To (T, Make_Identifier (Loc, Object_Name)));
5703 -- Add call to evolving expression, using AND THEN if needed
5710 Left_Opnd => Relocate_Node (Expr),
5714 -- Output info message on inheritance if required. Note we do not
5715 -- give this information for generic actual types, since it is
5716 -- unwelcome noise in that case in instantiations. We also
5717 -- generally suppress the message in instantiations, and also
5718 -- if it involves internal names.
5720 if Opt.List_Inherited_Aspects
5721 and then not Is_Generic_Actual_Type (Typ)
5722 and then Instantiation_Depth (Sloc (Typ)) = 0
5723 and then not Is_Internal_Name (Chars (T))
5724 and then not Is_Internal_Name (Chars (Typ))
5726 Error_Msg_Sloc := Sloc (Predicate_Function (T));
5727 Error_Msg_Node_2 := T;
5728 Error_Msg_N ("info: & inherits predicate from & #?L?", Typ);
5733 --------------------
5734 -- Add_Predicates --
5735 --------------------
5737 procedure Add_Predicates is
5742 procedure Replace_Type_Reference (N : Node_Id);
5743 -- Replace a single occurrence N of the subtype name with a reference
5744 -- to the formal of the predicate function. N can be an identifier
5745 -- referencing the subtype, or a selected component, representing an
5746 -- appropriately qualified occurrence of the subtype name.
5748 procedure Replace_Type_References is
5749 new Replace_Type_References_Generic (Replace_Type_Reference);
5750 -- Traverse an expression changing every occurrence of an identifier
5751 -- whose name matches the name of the subtype with a reference to
5752 -- the formal parameter of the predicate function.
5754 ----------------------------
5755 -- Replace_Type_Reference --
5756 ----------------------------
5758 procedure Replace_Type_Reference (N : Node_Id) is
5760 Rewrite (N, Make_Identifier (Sloc (N), Object_Name));
5761 -- Use the Sloc of the usage name, not the defining name
5764 Set_Entity (N, Object_Entity);
5766 -- We want to treat the node as if it comes from source, so that
5767 -- ASIS will not ignore it
5769 Set_Comes_From_Source (N, True);
5770 end Replace_Type_Reference;
5772 -- Start of processing for Add_Predicates
5775 Ritem := First_Rep_Item (Typ);
5776 while Present (Ritem) loop
5777 if Nkind (Ritem) = N_Pragma
5778 and then Pragma_Name (Ritem) = Name_Predicate
5780 if Present (Corresponding_Aspect (Ritem)) then
5781 case Chars (Identifier (Corresponding_Aspect (Ritem))) is
5782 when Name_Dynamic_Predicate =>
5783 Dynamic_Predicate_Present := True;
5784 when Name_Static_Predicate =>
5785 Static_Predicate_Present := Ritem;
5791 -- Acquire arguments
5793 Arg1 := First (Pragma_Argument_Associations (Ritem));
5794 Arg2 := Next (Arg1);
5796 Arg1 := Get_Pragma_Arg (Arg1);
5797 Arg2 := Get_Pragma_Arg (Arg2);
5799 -- See if this predicate pragma is for the current type or for
5800 -- its full view. A predicate on a private completion is placed
5801 -- on the partial view beause this is the visible entity that
5804 if Entity (Arg1) = Typ
5805 or else Full_View (Entity (Arg1)) = Typ
5807 -- We have a match, this entry is for our subtype
5809 -- We need to replace any occurrences of the name of the
5810 -- type with references to the object.
5812 Replace_Type_References (Arg2, Chars (Typ));
5814 -- If this predicate comes from an aspect, find the aspect
5815 -- specification, and replace the saved expression because
5816 -- we need the subtype references replaced for the calls to
5817 -- Preanalyze_Spec_Expressin in Check_Aspect_At_Freeze_Point
5818 -- and Check_Aspect_At_End_Of_Declarations.
5820 if From_Aspect_Specification (Ritem) then
5825 -- Loop to find corresponding aspect, note that this
5826 -- must be present given the pragma is marked delayed.
5828 Aitem := Next_Rep_Item (Ritem);
5830 if Nkind (Aitem) = N_Aspect_Specification
5831 and then Aspect_Rep_Item (Aitem) = Ritem
5834 (Identifier (Aitem), New_Copy_Tree (Arg2));
5838 Aitem := Next_Rep_Item (Aitem);
5843 -- Now we can add the expression
5846 Expr := Relocate_Node (Arg2);
5848 -- There already was a predicate, so add to it
5853 Left_Opnd => Relocate_Node (Expr),
5854 Right_Opnd => Relocate_Node (Arg2));
5859 Next_Rep_Item (Ritem);
5867 function Process_RE (N : Node_Id) return Traverse_Result is
5869 if Nkind (N) = N_Raise_Expression then
5870 Set_Convert_To_Return_False (N);
5881 function Test_RE (N : Node_Id) return Traverse_Result is
5883 if Nkind (N) = N_Raise_Expression then
5884 Raise_Expression_Present := True;
5891 -- Start of processing for Build_Predicate_Functions
5894 -- Return if already built or if type does not have predicates
5896 if not Has_Predicates (Typ)
5897 or else Present (Predicate_Function (Typ))
5902 -- Prepare to construct predicate expression
5906 -- Add Predicates for the current type
5910 -- Add predicates for ancestor if present
5913 Atyp : constant Entity_Id := Nearest_Ancestor (Typ);
5915 if Present (Atyp) then
5920 -- Case where predicates are present
5922 if Present (Expr) then
5924 -- Test for raise expression present
5928 -- If raise expression is present, capture a copy of Expr for use
5929 -- in building the predicateM function version later on. For this
5930 -- copy we replace references to Object_Entity by Object_Entity_M.
5932 if Raise_Expression_Present then
5934 Map : constant Elist_Id := New_Elmt_List;
5936 Append_Elmt (Object_Entity, Map);
5937 Append_Elmt (Object_Entity_M, Map);
5938 Expr_M := New_Copy_Tree (Expr, Map => Map);
5942 -- Build the main predicate function
5945 SId : constant Entity_Id :=
5946 Make_Defining_Identifier (Loc,
5947 Chars => New_External_Name (Chars (Typ), "Predicate"));
5948 -- The entity for the the function spec
5950 SIdB : constant Entity_Id :=
5951 Make_Defining_Identifier (Loc,
5952 Chars => New_External_Name (Chars (Typ), "Predicate"));
5953 -- The entity for the function body
5960 -- Build function declaration
5962 Set_Ekind (SId, E_Function);
5963 Set_Is_Predicate_Function (SId);
5964 Set_Predicate_Function (Typ, SId);
5966 -- The predicate function is shared between views of a type
5968 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
5969 Set_Predicate_Function (Full_View (Typ), SId);
5973 Make_Function_Specification (Loc,
5974 Defining_Unit_Name => SId,
5975 Parameter_Specifications => New_List (
5976 Make_Parameter_Specification (Loc,
5977 Defining_Identifier => Object_Entity,
5978 Parameter_Type => New_Occurrence_Of (Typ, Loc))),
5979 Result_Definition =>
5980 New_Occurrence_Of (Standard_Boolean, Loc));
5983 Make_Subprogram_Declaration (Loc,
5984 Specification => Spec);
5986 -- Build function body
5989 Make_Function_Specification (Loc,
5990 Defining_Unit_Name => SIdB,
5991 Parameter_Specifications => New_List (
5992 Make_Parameter_Specification (Loc,
5993 Defining_Identifier =>
5994 Make_Defining_Identifier (Loc, Object_Name),
5996 New_Occurrence_Of (Typ, Loc))),
5997 Result_Definition =>
5998 New_Occurrence_Of (Standard_Boolean, Loc));
6001 Make_Subprogram_Body (Loc,
6002 Specification => Spec,
6003 Declarations => Empty_List,
6004 Handled_Statement_Sequence =>
6005 Make_Handled_Sequence_Of_Statements (Loc,
6006 Statements => New_List (
6007 Make_Simple_Return_Statement (Loc,
6008 Expression => Expr))));
6010 -- Insert declaration before freeze node and body after
6012 Insert_Before_And_Analyze (N, FDecl);
6013 Insert_After_And_Analyze (N, FBody);
6016 -- Test for raise expressions present and if so build M version
6018 if Raise_Expression_Present then
6020 SId : constant Entity_Id :=
6021 Make_Defining_Identifier (Loc,
6022 Chars => New_External_Name (Chars (Typ), "PredicateM"));
6023 -- The entity for the the function spec
6025 SIdB : constant Entity_Id :=
6026 Make_Defining_Identifier (Loc,
6027 Chars => New_External_Name (Chars (Typ), "PredicateM"));
6028 -- The entity for the function body
6036 -- Mark any raise expressions for special expansion
6038 Process_REs (Expr_M);
6040 -- Build function declaration
6042 Set_Ekind (SId, E_Function);
6043 Set_Is_Predicate_Function_M (SId);
6044 Set_Predicate_Function_M (Typ, SId);
6046 -- The predicate function is shared between views of a type
6048 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
6049 Set_Predicate_Function_M (Full_View (Typ), SId);
6053 Make_Function_Specification (Loc,
6054 Defining_Unit_Name => SId,
6055 Parameter_Specifications => New_List (
6056 Make_Parameter_Specification (Loc,
6057 Defining_Identifier => Object_Entity_M,
6058 Parameter_Type => New_Occurrence_Of (Typ, Loc))),
6059 Result_Definition =>
6060 New_Occurrence_Of (Standard_Boolean, Loc));
6063 Make_Subprogram_Declaration (Loc,
6064 Specification => Spec);
6066 -- Build function body
6069 Make_Function_Specification (Loc,
6070 Defining_Unit_Name => SIdB,
6071 Parameter_Specifications => New_List (
6072 Make_Parameter_Specification (Loc,
6073 Defining_Identifier =>
6074 Make_Defining_Identifier (Loc, Object_Name),
6076 New_Occurrence_Of (Typ, Loc))),
6077 Result_Definition =>
6078 New_Occurrence_Of (Standard_Boolean, Loc));
6080 -- Build the body, we declare the boolean expression before
6081 -- doing the return, because we are not really confident of
6082 -- what happens if a return appears within a return!
6085 Make_Defining_Identifier (Loc,
6086 Chars => New_Internal_Name ('B'));
6089 Make_Subprogram_Body (Loc,
6090 Specification => Spec,
6092 Declarations => New_List (
6093 Make_Object_Declaration (Loc,
6094 Defining_Identifier => BTemp,
6095 Constant_Present => True,
6096 Object_Definition =>
6097 New_Reference_To (Standard_Boolean, Loc),
6098 Expression => Expr_M)),
6100 Handled_Statement_Sequence =>
6101 Make_Handled_Sequence_Of_Statements (Loc,
6102 Statements => New_List (
6103 Make_Simple_Return_Statement (Loc,
6104 Expression => New_Reference_To (BTemp, Loc)))));
6106 -- Insert declaration before freeze node and body after
6108 Insert_Before_And_Analyze (N, FDecl);
6109 Insert_After_And_Analyze (N, FBody);
6113 -- Deal with static predicate case
6115 if Ekind_In (Typ, E_Enumeration_Subtype,
6116 E_Modular_Integer_Subtype,
6117 E_Signed_Integer_Subtype)
6118 and then Is_Static_Subtype (Typ)
6119 and then not Dynamic_Predicate_Present
6121 Build_Static_Predicate (Typ, Expr, Object_Name);
6123 if Present (Static_Predicate_Present)
6124 and No (Static_Predicate (Typ))
6127 ("expression does not have required form for "
6128 & "static predicate",
6129 Next (First (Pragma_Argument_Associations
6130 (Static_Predicate_Present))));
6134 end Build_Predicate_Functions;
6136 ----------------------------
6137 -- Build_Static_Predicate --
6138 ----------------------------
6140 procedure Build_Static_Predicate
6145 Loc : constant Source_Ptr := Sloc (Expr);
6147 Non_Static : exception;
6148 -- Raised if something non-static is found
6150 Btyp : constant Entity_Id := Base_Type (Typ);
6152 BLo : constant Uint := Expr_Value (Type_Low_Bound (Btyp));
6153 BHi : constant Uint := Expr_Value (Type_High_Bound (Btyp));
6154 -- Low bound and high bound value of base type of Typ
6156 TLo : constant Uint := Expr_Value (Type_Low_Bound (Typ));
6157 THi : constant Uint := Expr_Value (Type_High_Bound (Typ));
6158 -- Low bound and high bound values of static subtype Typ
6163 -- One entry in a Rlist value, a single REnt (range entry) value
6164 -- denotes one range from Lo to Hi. To represent a single value
6165 -- range Lo = Hi = value.
6167 type RList is array (Nat range <>) of REnt;
6168 -- A list of ranges. The ranges are sorted in increasing order,
6169 -- and are disjoint (there is a gap of at least one value between
6170 -- each range in the table). A value is in the set of ranges in
6171 -- Rlist if it lies within one of these ranges
6173 False_Range : constant RList :=
6174 RList'(1 .. 0 => REnt'(No_Uint, No_Uint));
6175 -- An empty set of ranges represents a range list that can never be
6176 -- satisfied, since there are no ranges in which the value could lie,
6177 -- so it does not lie in any of them. False_Range is a canonical value
6178 -- for this empty set, but general processing should test for an Rlist
6179 -- with length zero (see Is_False predicate), since other null ranges
6180 -- may appear which must be treated as False.
6182 True_Range : constant RList := RList'(1 => REnt'(BLo, BHi));
6183 -- Range representing True, value must be in the base range
6185 function "and" (Left, Right : RList) return RList;
6186 -- And's together two range lists, returning a range list. This is
6187 -- a set intersection operation.
6189 function "or" (Left, Right : RList) return RList;
6190 -- Or's together two range lists, returning a range list. This is a
6191 -- set union operation.
6193 function "not" (Right : RList) return RList;
6194 -- Returns complement of a given range list, i.e. a range list
6195 -- representing all the values in TLo .. THi that are not in the
6196 -- input operand Right.
6198 function Build_Val (V : Uint) return Node_Id;
6199 -- Return an analyzed N_Identifier node referencing this value, suitable
6200 -- for use as an entry in the Static_Predicate list. This node is typed
6201 -- with the base type.
6203 function Build_Range (Lo, Hi : Uint) return Node_Id;
6204 -- Return an analyzed N_Range node referencing this range, suitable
6205 -- for use as an entry in the Static_Predicate list. This node is typed
6206 -- with the base type.
6208 function Get_RList (Exp : Node_Id) return RList;
6209 -- This is a recursive routine that converts the given expression into
6210 -- a list of ranges, suitable for use in building the static predicate.
6212 function Is_False (R : RList) return Boolean;
6213 pragma Inline (Is_False);
6214 -- Returns True if the given range list is empty, and thus represents
6215 -- a False list of ranges that can never be satisfied.
6217 function Is_True (R : RList) return Boolean;
6218 -- Returns True if R trivially represents the True predicate by having
6219 -- a single range from BLo to BHi.
6221 function Is_Type_Ref (N : Node_Id) return Boolean;
6222 pragma Inline (Is_Type_Ref);
6223 -- Returns if True if N is a reference to the type for the predicate in
6224 -- the expression (i.e. if it is an identifier whose Chars field matches
6225 -- the Nam given in the call).
6227 function Lo_Val (N : Node_Id) return Uint;
6228 -- Given static expression or static range from a Static_Predicate list,
6229 -- gets expression value or low bound of range.
6231 function Hi_Val (N : Node_Id) return Uint;
6232 -- Given static expression or static range from a Static_Predicate list,
6233 -- gets expression value of high bound of range.
6235 function Membership_Entry (N : Node_Id) return RList;
6236 -- Given a single membership entry (range, value, or subtype), returns
6237 -- the corresponding range list. Raises Static_Error if not static.
6239 function Membership_Entries (N : Node_Id) return RList;
6240 -- Given an element on an alternatives list of a membership operation,
6241 -- returns the range list corresponding to this entry and all following
6242 -- entries (i.e. returns the "or" of this list of values).
6244 function Stat_Pred (Typ : Entity_Id) return RList;
6245 -- Given a type, if it has a static predicate, then return the predicate
6246 -- as a range list, otherwise raise Non_Static.
6252 function "and" (Left, Right : RList) return RList is
6254 -- First range of result
6256 SLeft : Nat := Left'First;
6257 -- Start of rest of left entries
6259 SRight : Nat := Right'First;
6260 -- Start of rest of right entries
6263 -- If either range is True, return the other
6265 if Is_True (Left) then
6267 elsif Is_True (Right) then
6271 -- If either range is False, return False
6273 if Is_False (Left) or else Is_False (Right) then
6277 -- Loop to remove entries at start that are disjoint, and thus
6278 -- just get discarded from the result entirely.
6281 -- If no operands left in either operand, result is false
6283 if SLeft > Left'Last or else SRight > Right'Last then
6286 -- Discard first left operand entry if disjoint with right
6288 elsif Left (SLeft).Hi < Right (SRight).Lo then
6291 -- Discard first right operand entry if disjoint with left
6293 elsif Right (SRight).Hi < Left (SLeft).Lo then
6294 SRight := SRight + 1;
6296 -- Otherwise we have an overlapping entry
6303 -- Now we have two non-null operands, and first entries overlap.
6304 -- The first entry in the result will be the overlapping part of
6305 -- these two entries.
6307 FEnt := REnt'(Lo => UI_Max (Left (SLeft).Lo, Right (SRight).Lo),
6308 Hi => UI_Min (Left (SLeft).Hi, Right (SRight).Hi));
6310 -- Now we can remove the entry that ended at a lower value, since
6311 -- its contribution is entirely contained in Fent.
6313 if Left (SLeft).Hi <= Right (SRight).Hi then
6316 SRight := SRight + 1;
6319 -- Compute result by concatenating this first entry with the "and"
6320 -- of the remaining parts of the left and right operands. Note that
6321 -- if either of these is empty, "and" will yield empty, so that we
6322 -- will end up with just Fent, which is what we want in that case.
6325 FEnt & (Left (SLeft .. Left'Last) and Right (SRight .. Right'Last));
6332 function "not" (Right : RList) return RList is
6334 -- Return True if False range
6336 if Is_False (Right) then
6340 -- Return False if True range
6342 if Is_True (Right) then
6346 -- Here if not trivial case
6349 Result : RList (1 .. Right'Length + 1);
6350 -- May need one more entry for gap at beginning and end
6353 -- Number of entries stored in Result
6358 if Right (Right'First).Lo > TLo then
6360 Result (Count) := REnt'(TLo, Right (Right'First).Lo - 1);
6363 -- Gaps between ranges
6365 for J in Right'First .. Right'Last - 1 loop
6368 REnt'(Right (J).Hi + 1, Right (J + 1).Lo - 1);
6373 if Right (Right'Last).Hi < THi then
6375 Result (Count) := REnt'(Right (Right'Last).Hi + 1, THi);
6378 return Result (1 .. Count);
6386 function "or" (Left, Right : RList) return RList is
6388 -- First range of result
6390 SLeft : Nat := Left'First;
6391 -- Start of rest of left entries
6393 SRight : Nat := Right'First;
6394 -- Start of rest of right entries
6397 -- If either range is True, return True
6399 if Is_True (Left) or else Is_True (Right) then
6403 -- If either range is False (empty), return the other
6405 if Is_False (Left) then
6407 elsif Is_False (Right) then
6411 -- Initialize result first entry from left or right operand
6412 -- depending on which starts with the lower range.
6414 if Left (SLeft).Lo < Right (SRight).Lo then
6415 FEnt := Left (SLeft);
6418 FEnt := Right (SRight);
6419 SRight := SRight + 1;
6422 -- This loop eats ranges from left and right operands that
6423 -- are contiguous with the first range we are gathering.
6426 -- Eat first entry in left operand if contiguous or
6427 -- overlapped by gathered first operand of result.
6429 if SLeft <= Left'Last
6430 and then Left (SLeft).Lo <= FEnt.Hi + 1
6432 FEnt.Hi := UI_Max (FEnt.Hi, Left (SLeft).Hi);
6435 -- Eat first entry in right operand if contiguous or
6436 -- overlapped by gathered right operand of result.
6438 elsif SRight <= Right'Last
6439 and then Right (SRight).Lo <= FEnt.Hi + 1
6441 FEnt.Hi := UI_Max (FEnt.Hi, Right (SRight).Hi);
6442 SRight := SRight + 1;
6444 -- All done if no more entries to eat!
6451 -- Obtain result as the first entry we just computed, concatenated
6452 -- to the "or" of the remaining results (if one operand is empty,
6453 -- this will just concatenate with the other
6456 FEnt & (Left (SLeft .. Left'Last) or Right (SRight .. Right'Last));
6463 function Build_Range (Lo, Hi : Uint) return Node_Id is
6467 return Build_Val (Hi);
6471 Low_Bound => Build_Val (Lo),
6472 High_Bound => Build_Val (Hi));
6473 Set_Etype (Result, Btyp);
6474 Set_Analyzed (Result);
6483 function Build_Val (V : Uint) return Node_Id is
6487 if Is_Enumeration_Type (Typ) then
6488 Result := Get_Enum_Lit_From_Pos (Typ, V, Loc);
6490 Result := Make_Integer_Literal (Loc, V);
6493 Set_Etype (Result, Btyp);
6494 Set_Is_Static_Expression (Result);
6495 Set_Analyzed (Result);
6503 function Get_RList (Exp : Node_Id) return RList is
6508 -- Static expression can only be true or false
6510 if Is_OK_Static_Expression (Exp) then
6514 if Expr_Value (Exp) = 0 then
6521 -- Otherwise test node type
6529 when N_Op_And | N_And_Then =>
6530 return Get_RList (Left_Opnd (Exp))
6532 Get_RList (Right_Opnd (Exp));
6536 when N_Op_Or | N_Or_Else =>
6537 return Get_RList (Left_Opnd (Exp))
6539 Get_RList (Right_Opnd (Exp));
6544 return not Get_RList (Right_Opnd (Exp));
6546 -- Comparisons of type with static value
6548 when N_Op_Compare =>
6550 -- Type is left operand
6552 if Is_Type_Ref (Left_Opnd (Exp))
6553 and then Is_OK_Static_Expression (Right_Opnd (Exp))
6555 Val := Expr_Value (Right_Opnd (Exp));
6557 -- Typ is right operand
6559 elsif Is_Type_Ref (Right_Opnd (Exp))
6560 and then Is_OK_Static_Expression (Left_Opnd (Exp))
6562 Val := Expr_Value (Left_Opnd (Exp));
6564 -- Invert sense of comparison
6567 when N_Op_Gt => Op := N_Op_Lt;
6568 when N_Op_Lt => Op := N_Op_Gt;
6569 when N_Op_Ge => Op := N_Op_Le;
6570 when N_Op_Le => Op := N_Op_Ge;
6571 when others => null;
6574 -- Other cases are non-static
6580 -- Construct range according to comparison operation
6584 return RList'(1 => REnt'(Val, Val));
6587 return RList'(1 => REnt'(Val, BHi));
6590 return RList'(1 => REnt'(Val + 1, BHi));
6593 return RList'(1 => REnt'(BLo, Val));
6596 return RList'(1 => REnt'(BLo, Val - 1));
6599 return RList'(REnt'(BLo, Val - 1),
6600 REnt'(Val + 1, BHi));
6603 raise Program_Error;
6609 if not Is_Type_Ref (Left_Opnd (Exp)) then
6613 if Present (Right_Opnd (Exp)) then
6614 return Membership_Entry (Right_Opnd (Exp));
6616 return Membership_Entries (First (Alternatives (Exp)));
6619 -- Negative membership (NOT IN)
6622 if not Is_Type_Ref (Left_Opnd (Exp)) then
6626 if Present (Right_Opnd (Exp)) then
6627 return not Membership_Entry (Right_Opnd (Exp));
6629 return not Membership_Entries (First (Alternatives (Exp)));
6632 -- Function call, may be call to static predicate
6634 when N_Function_Call =>
6635 if Is_Entity_Name (Name (Exp)) then
6637 Ent : constant Entity_Id := Entity (Name (Exp));
6639 if Is_Predicate_Function (Ent)
6641 Is_Predicate_Function_M (Ent)
6643 return Stat_Pred (Etype (First_Formal (Ent)));
6648 -- Other function call cases are non-static
6652 -- Qualified expression, dig out the expression
6654 when N_Qualified_Expression =>
6655 return Get_RList (Expression (Exp));
6660 return (Get_RList (Left_Opnd (Exp))
6661 and not Get_RList (Right_Opnd (Exp)))
6662 or (Get_RList (Right_Opnd (Exp))
6663 and not Get_RList (Left_Opnd (Exp)));
6665 -- Any other node type is non-static
6676 function Hi_Val (N : Node_Id) return Uint is
6678 if Is_Static_Expression (N) then
6679 return Expr_Value (N);
6681 pragma Assert (Nkind (N) = N_Range);
6682 return Expr_Value (High_Bound (N));
6690 function Is_False (R : RList) return Boolean is
6692 return R'Length = 0;
6699 function Is_True (R : RList) return Boolean is
6702 and then R (R'First).Lo = BLo
6703 and then R (R'First).Hi = BHi;
6710 function Is_Type_Ref (N : Node_Id) return Boolean is
6712 return Nkind (N) = N_Identifier and then Chars (N) = Nam;
6719 function Lo_Val (N : Node_Id) return Uint is
6721 if Is_Static_Expression (N) then
6722 return Expr_Value (N);
6724 pragma Assert (Nkind (N) = N_Range);
6725 return Expr_Value (Low_Bound (N));
6729 ------------------------
6730 -- Membership_Entries --
6731 ------------------------
6733 function Membership_Entries (N : Node_Id) return RList is
6735 if No (Next (N)) then
6736 return Membership_Entry (N);
6738 return Membership_Entry (N) or Membership_Entries (Next (N));
6740 end Membership_Entries;
6742 ----------------------
6743 -- Membership_Entry --
6744 ----------------------
6746 function Membership_Entry (N : Node_Id) return RList is
6754 if Nkind (N) = N_Range then
6755 if not Is_Static_Expression (Low_Bound (N))
6757 not Is_Static_Expression (High_Bound (N))
6761 SLo := Expr_Value (Low_Bound (N));
6762 SHi := Expr_Value (High_Bound (N));
6763 return RList'(1 => REnt'(SLo, SHi));
6766 -- Static expression case
6768 elsif Is_Static_Expression (N) then
6769 Val := Expr_Value (N);
6770 return RList'(1 => REnt'(Val, Val));
6772 -- Identifier (other than static expression) case
6774 else pragma Assert (Nkind (N) = N_Identifier);
6778 if Is_Type (Entity (N)) then
6780 -- If type has predicates, process them
6782 if Has_Predicates (Entity (N)) then
6783 return Stat_Pred (Entity (N));
6785 -- For static subtype without predicates, get range
6787 elsif Is_Static_Subtype (Entity (N)) then
6788 SLo := Expr_Value (Type_Low_Bound (Entity (N)));
6789 SHi := Expr_Value (Type_High_Bound (Entity (N)));
6790 return RList'(1 => REnt'(SLo, SHi));
6792 -- Any other type makes us non-static
6798 -- Any other kind of identifier in predicate (e.g. a non-static
6799 -- expression value) means this is not a static predicate.
6805 end Membership_Entry;
6811 function Stat_Pred (Typ : Entity_Id) return RList is
6813 -- Not static if type does not have static predicates
6815 if not Has_Predicates (Typ) or else No (Static_Predicate (Typ)) then
6819 -- Otherwise we convert the predicate list to a range list
6822 Result : RList (1 .. List_Length (Static_Predicate (Typ)));
6826 P := First (Static_Predicate (Typ));
6827 for J in Result'Range loop
6828 Result (J) := REnt'(Lo_Val (P), Hi_Val (P));
6836 -- Start of processing for Build_Static_Predicate
6839 -- Now analyze the expression to see if it is a static predicate
6842 Ranges : constant RList := Get_RList (Expr);
6843 -- Range list from expression if it is static
6848 -- Convert range list into a form for the static predicate. In the
6849 -- Ranges array, we just have raw ranges, these must be converted
6850 -- to properly typed and analyzed static expressions or range nodes.
6852 -- Note: here we limit ranges to the ranges of the subtype, so that
6853 -- a predicate is always false for values outside the subtype. That
6854 -- seems fine, such values are invalid anyway, and considering them
6855 -- to fail the predicate seems allowed and friendly, and furthermore
6856 -- simplifies processing for case statements and loops.
6860 for J in Ranges'Range loop
6862 Lo : Uint := Ranges (J).Lo;
6863 Hi : Uint := Ranges (J).Hi;
6866 -- Ignore completely out of range entry
6868 if Hi < TLo or else Lo > THi then
6871 -- Otherwise process entry
6874 -- Adjust out of range value to subtype range
6884 -- Convert range into required form
6887 Append_To (Plist, Build_Val (Lo));
6889 Append_To (Plist, Build_Range (Lo, Hi));
6895 -- Processing was successful and all entries were static, so now we
6896 -- can store the result as the predicate list.
6898 Set_Static_Predicate (Typ, Plist);
6900 -- The processing for static predicates put the expression into
6901 -- canonical form as a series of ranges. It also eliminated
6902 -- duplicates and collapsed and combined ranges. We might as well
6903 -- replace the alternatives list of the right operand of the
6904 -- membership test with the static predicate list, which will
6905 -- usually be more efficient.
6908 New_Alts : constant List_Id := New_List;
6913 Old_Node := First (Plist);
6914 while Present (Old_Node) loop
6915 New_Node := New_Copy (Old_Node);
6917 if Nkind (New_Node) = N_Range then
6918 Set_Low_Bound (New_Node, New_Copy (Low_Bound (Old_Node)));
6919 Set_High_Bound (New_Node, New_Copy (High_Bound (Old_Node)));
6922 Append_To (New_Alts, New_Node);
6926 -- If empty list, replace by False
6928 if Is_Empty_List (New_Alts) then
6929 Rewrite (Expr, New_Occurrence_Of (Standard_False, Loc));
6931 -- Else replace by set membership test
6936 Left_Opnd => Make_Identifier (Loc, Nam),
6937 Right_Opnd => Empty,
6938 Alternatives => New_Alts));
6940 -- Resolve new expression in function context
6942 Install_Formals (Predicate_Function (Typ));
6943 Push_Scope (Predicate_Function (Typ));
6944 Analyze_And_Resolve (Expr, Standard_Boolean);
6950 -- If non-static, return doing nothing
6955 end Build_Static_Predicate;
6957 -----------------------------------------
6958 -- Check_Aspect_At_End_Of_Declarations --
6959 -----------------------------------------
6961 procedure Check_Aspect_At_End_Of_Declarations (ASN : Node_Id) is
6962 Ent : constant Entity_Id := Entity (ASN);
6963 Ident : constant Node_Id := Identifier (ASN);
6964 A_Id : constant Aspect_Id := Get_Aspect_Id (Chars (Ident));
6966 End_Decl_Expr : constant Node_Id := Entity (Ident);
6967 -- Expression to be analyzed at end of declarations
6969 Freeze_Expr : constant Node_Id := Expression (ASN);
6970 -- Expression from call to Check_Aspect_At_Freeze_Point
6972 T : constant Entity_Id := Etype (Freeze_Expr);
6973 -- Type required for preanalyze call
6976 -- Set False if error
6978 -- On entry to this procedure, Entity (Ident) contains a copy of the
6979 -- original expression from the aspect, saved for this purpose, and
6980 -- but Expression (Ident) is a preanalyzed copy of the expression,
6981 -- preanalyzed just after the freeze point.
6983 procedure Check_Overloaded_Name;
6984 -- For aspects whose expression is simply a name, this routine checks if
6985 -- the name is overloaded or not. If so, it verifies there is an
6986 -- interpretation that matches the entity obtained at the freeze point,
6987 -- otherwise the compiler complains.
6989 ---------------------------
6990 -- Check_Overloaded_Name --
6991 ---------------------------
6993 procedure Check_Overloaded_Name is
6995 if not Is_Overloaded (End_Decl_Expr) then
6996 Err := Entity (End_Decl_Expr) /= Entity (Freeze_Expr);
7002 Index : Interp_Index;
7006 Get_First_Interp (End_Decl_Expr, Index, It);
7007 while Present (It.Typ) loop
7008 if It.Nam = Entity (Freeze_Expr) then
7013 Get_Next_Interp (Index, It);
7017 end Check_Overloaded_Name;
7019 -- Start of processing for Check_Aspect_At_End_Of_Declarations
7022 -- Case of aspects Dimension, Dimension_System and Synchronization
7024 if A_Id = Aspect_Synchronization then
7027 -- Case of stream attributes, just have to compare entities. However,
7028 -- the expression is just a name (possibly overloaded), and there may
7029 -- be stream operations declared for unrelated types, so we just need
7030 -- to verify that one of these interpretations is the one available at
7031 -- at the freeze point.
7033 elsif A_Id = Aspect_Input or else
7034 A_Id = Aspect_Output or else
7035 A_Id = Aspect_Read or else
7038 Analyze (End_Decl_Expr);
7039 Check_Overloaded_Name;
7041 elsif A_Id = Aspect_Variable_Indexing or else
7042 A_Id = Aspect_Constant_Indexing or else
7043 A_Id = Aspect_Default_Iterator or else
7044 A_Id = Aspect_Iterator_Element
7046 -- Make type unfrozen before analysis, to prevent spurious errors
7047 -- about late attributes.
7049 Set_Is_Frozen (Ent, False);
7050 Analyze (End_Decl_Expr);
7051 Set_Is_Frozen (Ent, True);
7053 -- If the end of declarations comes before any other freeze
7054 -- point, the Freeze_Expr is not analyzed: no check needed.
7056 if Analyzed (Freeze_Expr) and then not In_Instance then
7057 Check_Overloaded_Name;
7065 -- In a generic context the aspect expressions have not been
7066 -- preanalyzed, so do it now. There are no conformance checks
7067 -- to perform in this case.
7070 Check_Aspect_At_Freeze_Point (ASN);
7073 -- The default values attributes may be defined in the private part,
7074 -- and the analysis of the expression may take place when only the
7075 -- partial view is visible. The expression must be scalar, so use
7076 -- the full view to resolve.
7078 elsif (A_Id = Aspect_Default_Value
7080 A_Id = Aspect_Default_Component_Value)
7081 and then Is_Private_Type (T)
7083 Preanalyze_Spec_Expression (End_Decl_Expr, Full_View (T));
7085 Preanalyze_Spec_Expression (End_Decl_Expr, T);
7088 Err := not Fully_Conformant_Expressions (End_Decl_Expr, Freeze_Expr);
7091 -- Output error message if error
7095 ("visibility of aspect for& changes after freeze point",
7098 ("info: & is frozen here, aspects evaluated at this point??",
7099 Freeze_Node (Ent), Ent);
7101 end Check_Aspect_At_End_Of_Declarations;
7103 ----------------------------------
7104 -- Check_Aspect_At_Freeze_Point --
7105 ----------------------------------
7107 procedure Check_Aspect_At_Freeze_Point (ASN : Node_Id) is
7108 Ident : constant Node_Id := Identifier (ASN);
7109 -- Identifier (use Entity field to save expression)
7111 A_Id : constant Aspect_Id := Get_Aspect_Id (Chars (Ident));
7113 T : Entity_Id := Empty;
7114 -- Type required for preanalyze call
7117 -- On entry to this procedure, Entity (Ident) contains a copy of the
7118 -- original expression from the aspect, saved for this purpose.
7120 -- On exit from this procedure Entity (Ident) is unchanged, still
7121 -- containing that copy, but Expression (Ident) is a preanalyzed copy
7122 -- of the expression, preanalyzed just after the freeze point.
7124 -- Make a copy of the expression to be preanalyzed
7126 Set_Expression (ASN, New_Copy_Tree (Entity (Ident)));
7128 -- Find type for preanalyze call
7132 -- No_Aspect should be impossible
7135 raise Program_Error;
7137 -- Aspects taking an optional boolean argument
7139 when Boolean_Aspects |
7140 Library_Unit_Aspects =>
7141 T := Standard_Boolean;
7143 -- Aspects corresponding to attribute definition clauses
7145 when Aspect_Address =>
7146 T := RTE (RE_Address);
7148 when Aspect_Attach_Handler =>
7149 T := RTE (RE_Interrupt_ID);
7151 when Aspect_Bit_Order | Aspect_Scalar_Storage_Order =>
7152 T := RTE (RE_Bit_Order);
7154 when Aspect_Convention =>
7158 T := RTE (RE_CPU_Range);
7160 -- Default_Component_Value is resolved with the component type
7162 when Aspect_Default_Component_Value =>
7163 T := Component_Type (Entity (ASN));
7165 -- Default_Value is resolved with the type entity in question
7167 when Aspect_Default_Value =>
7170 when Aspect_Dispatching_Domain =>
7171 T := RTE (RE_Dispatching_Domain);
7173 when Aspect_External_Tag =>
7174 T := Standard_String;
7176 when Aspect_External_Name =>
7177 T := Standard_String;
7179 -- Global is a delayed aspect because it may reference names that
7180 -- have not been declared yet. There is no action to be taken with
7181 -- respect to the aspect itself as the reference checking is done on
7182 -- the corresponding pragma.
7184 when Aspect_Global =>
7187 when Aspect_Link_Name =>
7188 T := Standard_String;
7190 when Aspect_Priority | Aspect_Interrupt_Priority =>
7191 T := Standard_Integer;
7193 when Aspect_Relative_Deadline =>
7194 T := RTE (RE_Time_Span);
7196 when Aspect_Small =>
7197 T := Universal_Real;
7199 -- For a simple storage pool, we have to retrieve the type of the
7200 -- pool object associated with the aspect's corresponding attribute
7201 -- definition clause.
7203 when Aspect_Simple_Storage_Pool =>
7204 T := Etype (Expression (Aspect_Rep_Item (ASN)));
7206 when Aspect_Storage_Pool =>
7207 T := Class_Wide_Type (RTE (RE_Root_Storage_Pool));
7209 when Aspect_Alignment |
7210 Aspect_Component_Size |
7211 Aspect_Machine_Radix |
7212 Aspect_Object_Size |
7214 Aspect_Storage_Size |
7215 Aspect_Stream_Size |
7216 Aspect_Value_Size =>
7219 when Aspect_Synchronization =>
7222 -- Special case, the expression of these aspects is just an entity
7223 -- that does not need any resolution, so just analyze.
7232 Analyze (Expression (ASN));
7235 -- Same for Iterator aspects, where the expression is a function
7236 -- name. Legality rules are checked separately.
7238 when Aspect_Constant_Indexing |
7239 Aspect_Default_Iterator |
7240 Aspect_Iterator_Element |
7241 Aspect_Variable_Indexing =>
7242 Analyze (Expression (ASN));
7245 -- Invariant/Predicate take boolean expressions
7247 when Aspect_Dynamic_Predicate |
7250 Aspect_Static_Predicate |
7251 Aspect_Type_Invariant =>
7252 T := Standard_Boolean;
7254 -- Here is the list of aspects that don't require delay analysis
7256 when Aspect_Abstract_State |
7257 Aspect_Contract_Case |
7258 Aspect_Contract_Cases |
7260 Aspect_Dimension_System |
7261 Aspect_Implicit_Dereference |
7263 Aspect_Postcondition |
7265 Aspect_Precondition |
7267 raise Program_Error;
7271 -- Do the preanalyze call
7273 Preanalyze_Spec_Expression (Expression (ASN), T);
7274 end Check_Aspect_At_Freeze_Point;
7276 -----------------------------------
7277 -- Check_Constant_Address_Clause --
7278 -----------------------------------
7280 procedure Check_Constant_Address_Clause
7284 procedure Check_At_Constant_Address (Nod : Node_Id);
7285 -- Checks that the given node N represents a name whose 'Address is
7286 -- constant (in the same sense as OK_Constant_Address_Clause, i.e. the
7287 -- address value is the same at the point of declaration of U_Ent and at
7288 -- the time of elaboration of the address clause.
7290 procedure Check_Expr_Constants (Nod : Node_Id);
7291 -- Checks that Nod meets the requirements for a constant address clause
7292 -- in the sense of the enclosing procedure.
7294 procedure Check_List_Constants (Lst : List_Id);
7295 -- Check that all elements of list Lst meet the requirements for a
7296 -- constant address clause in the sense of the enclosing procedure.
7298 -------------------------------
7299 -- Check_At_Constant_Address --
7300 -------------------------------
7302 procedure Check_At_Constant_Address (Nod : Node_Id) is
7304 if Is_Entity_Name (Nod) then
7305 if Present (Address_Clause (Entity ((Nod)))) then
7307 ("invalid address clause for initialized object &!",
7310 ("address for& cannot" &
7311 " depend on another address clause! (RM 13.1(22))!",
7314 elsif In_Same_Source_Unit (Entity (Nod), U_Ent)
7315 and then Sloc (U_Ent) < Sloc (Entity (Nod))
7318 ("invalid address clause for initialized object &!",
7320 Error_Msg_Node_2 := U_Ent;
7322 ("\& must be defined before & (RM 13.1(22))!",
7326 elsif Nkind (Nod) = N_Selected_Component then
7328 T : constant Entity_Id := Etype (Prefix (Nod));
7331 if (Is_Record_Type (T)
7332 and then Has_Discriminants (T))
7335 and then Is_Record_Type (Designated_Type (T))
7336 and then Has_Discriminants (Designated_Type (T)))
7339 ("invalid address clause for initialized object &!",
7342 ("\address cannot depend on component" &
7343 " of discriminated record (RM 13.1(22))!",
7346 Check_At_Constant_Address (Prefix (Nod));
7350 elsif Nkind (Nod) = N_Indexed_Component then
7351 Check_At_Constant_Address (Prefix (Nod));
7352 Check_List_Constants (Expressions (Nod));
7355 Check_Expr_Constants (Nod);
7357 end Check_At_Constant_Address;
7359 --------------------------
7360 -- Check_Expr_Constants --
7361 --------------------------
7363 procedure Check_Expr_Constants (Nod : Node_Id) is
7364 Loc_U_Ent : constant Source_Ptr := Sloc (U_Ent);
7365 Ent : Entity_Id := Empty;
7368 if Nkind (Nod) in N_Has_Etype
7369 and then Etype (Nod) = Any_Type
7375 when N_Empty | N_Error =>
7378 when N_Identifier | N_Expanded_Name =>
7379 Ent := Entity (Nod);
7381 -- We need to look at the original node if it is different
7382 -- from the node, since we may have rewritten things and
7383 -- substituted an identifier representing the rewrite.
7385 if Original_Node (Nod) /= Nod then
7386 Check_Expr_Constants (Original_Node (Nod));
7388 -- If the node is an object declaration without initial
7389 -- value, some code has been expanded, and the expression
7390 -- is not constant, even if the constituents might be
7391 -- acceptable, as in A'Address + offset.
7393 if Ekind (Ent) = E_Variable
7395 Nkind (Declaration_Node (Ent)) = N_Object_Declaration
7397 No (Expression (Declaration_Node (Ent)))
7400 ("invalid address clause for initialized object &!",
7403 -- If entity is constant, it may be the result of expanding
7404 -- a check. We must verify that its declaration appears
7405 -- before the object in question, else we also reject the
7408 elsif Ekind (Ent) = E_Constant
7409 and then In_Same_Source_Unit (Ent, U_Ent)
7410 and then Sloc (Ent) > Loc_U_Ent
7413 ("invalid address clause for initialized object &!",
7420 -- Otherwise look at the identifier and see if it is OK
7422 if Ekind_In (Ent, E_Named_Integer, E_Named_Real)
7423 or else Is_Type (Ent)
7428 Ekind (Ent) = E_Constant
7430 Ekind (Ent) = E_In_Parameter
7432 -- This is the case where we must have Ent defined before
7433 -- U_Ent. Clearly if they are in different units this
7434 -- requirement is met since the unit containing Ent is
7435 -- already processed.
7437 if not In_Same_Source_Unit (Ent, U_Ent) then
7440 -- Otherwise location of Ent must be before the location
7441 -- of U_Ent, that's what prior defined means.
7443 elsif Sloc (Ent) < Loc_U_Ent then
7448 ("invalid address clause for initialized object &!",
7450 Error_Msg_Node_2 := U_Ent;
7452 ("\& must be defined before & (RM 13.1(22))!",
7456 elsif Nkind (Original_Node (Nod)) = N_Function_Call then
7457 Check_Expr_Constants (Original_Node (Nod));
7461 ("invalid address clause for initialized object &!",
7464 if Comes_From_Source (Ent) then
7466 ("\reference to variable& not allowed"
7467 & " (RM 13.1(22))!", Nod, Ent);
7470 ("non-static expression not allowed"
7471 & " (RM 13.1(22))!", Nod);
7475 when N_Integer_Literal =>
7477 -- If this is a rewritten unchecked conversion, in a system
7478 -- where Address is an integer type, always use the base type
7479 -- for a literal value. This is user-friendly and prevents
7480 -- order-of-elaboration issues with instances of unchecked
7483 if Nkind (Original_Node (Nod)) = N_Function_Call then
7484 Set_Etype (Nod, Base_Type (Etype (Nod)));
7487 when N_Real_Literal |
7489 N_Character_Literal =>
7493 Check_Expr_Constants (Low_Bound (Nod));
7494 Check_Expr_Constants (High_Bound (Nod));
7496 when N_Explicit_Dereference =>
7497 Check_Expr_Constants (Prefix (Nod));
7499 when N_Indexed_Component =>
7500 Check_Expr_Constants (Prefix (Nod));
7501 Check_List_Constants (Expressions (Nod));
7504 Check_Expr_Constants (Prefix (Nod));
7505 Check_Expr_Constants (Discrete_Range (Nod));
7507 when N_Selected_Component =>
7508 Check_Expr_Constants (Prefix (Nod));
7510 when N_Attribute_Reference =>
7511 if Attribute_Name (Nod) = Name_Address
7513 Attribute_Name (Nod) = Name_Access
7515 Attribute_Name (Nod) = Name_Unchecked_Access
7517 Attribute_Name (Nod) = Name_Unrestricted_Access
7519 Check_At_Constant_Address (Prefix (Nod));
7522 Check_Expr_Constants (Prefix (Nod));
7523 Check_List_Constants (Expressions (Nod));
7527 Check_List_Constants (Component_Associations (Nod));
7528 Check_List_Constants (Expressions (Nod));
7530 when N_Component_Association =>
7531 Check_Expr_Constants (Expression (Nod));
7533 when N_Extension_Aggregate =>
7534 Check_Expr_Constants (Ancestor_Part (Nod));
7535 Check_List_Constants (Component_Associations (Nod));
7536 Check_List_Constants (Expressions (Nod));
7541 when N_Binary_Op | N_Short_Circuit | N_Membership_Test =>
7542 Check_Expr_Constants (Left_Opnd (Nod));
7543 Check_Expr_Constants (Right_Opnd (Nod));
7546 Check_Expr_Constants (Right_Opnd (Nod));
7548 when N_Type_Conversion |
7549 N_Qualified_Expression |
7551 N_Unchecked_Type_Conversion =>
7552 Check_Expr_Constants (Expression (Nod));
7554 when N_Function_Call =>
7555 if not Is_Pure (Entity (Name (Nod))) then
7557 ("invalid address clause for initialized object &!",
7561 ("\function & is not pure (RM 13.1(22))!",
7562 Nod, Entity (Name (Nod)));
7565 Check_List_Constants (Parameter_Associations (Nod));
7568 when N_Parameter_Association =>
7569 Check_Expr_Constants (Explicit_Actual_Parameter (Nod));
7573 ("invalid address clause for initialized object &!",
7576 ("\must be constant defined before& (RM 13.1(22))!",
7579 end Check_Expr_Constants;
7581 --------------------------
7582 -- Check_List_Constants --
7583 --------------------------
7585 procedure Check_List_Constants (Lst : List_Id) is
7589 if Present (Lst) then
7590 Nod1 := First (Lst);
7591 while Present (Nod1) loop
7592 Check_Expr_Constants (Nod1);
7596 end Check_List_Constants;
7598 -- Start of processing for Check_Constant_Address_Clause
7601 -- If rep_clauses are to be ignored, no need for legality checks. In
7602 -- particular, no need to pester user about rep clauses that violate
7603 -- the rule on constant addresses, given that these clauses will be
7604 -- removed by Freeze before they reach the back end.
7606 if not Ignore_Rep_Clauses then
7607 Check_Expr_Constants (Expr);
7609 end Check_Constant_Address_Clause;
7611 ----------------------------------------
7612 -- Check_Record_Representation_Clause --
7613 ----------------------------------------
7615 procedure Check_Record_Representation_Clause (N : Node_Id) is
7616 Loc : constant Source_Ptr := Sloc (N);
7617 Ident : constant Node_Id := Identifier (N);
7618 Rectype : Entity_Id;
7623 Hbit : Uint := Uint_0;
7627 Max_Bit_So_Far : Uint;
7628 -- Records the maximum bit position so far. If all field positions
7629 -- are monotonically increasing, then we can skip the circuit for
7630 -- checking for overlap, since no overlap is possible.
7632 Tagged_Parent : Entity_Id := Empty;
7633 -- This is set in the case of a derived tagged type for which we have
7634 -- Is_Fully_Repped_Tagged_Type True (indicating that all components are
7635 -- positioned by record representation clauses). In this case we must
7636 -- check for overlap between components of this tagged type, and the
7637 -- components of its parent. Tagged_Parent will point to this parent
7638 -- type. For all other cases Tagged_Parent is left set to Empty.
7640 Parent_Last_Bit : Uint;
7641 -- Relevant only if Tagged_Parent is set, Parent_Last_Bit indicates the
7642 -- last bit position for any field in the parent type. We only need to
7643 -- check overlap for fields starting below this point.
7645 Overlap_Check_Required : Boolean;
7646 -- Used to keep track of whether or not an overlap check is required
7648 Overlap_Detected : Boolean := False;
7649 -- Set True if an overlap is detected
7651 Ccount : Natural := 0;
7652 -- Number of component clauses in record rep clause
7654 procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id);
7655 -- Given two entities for record components or discriminants, checks
7656 -- if they have overlapping component clauses and issues errors if so.
7658 procedure Find_Component;
7659 -- Finds component entity corresponding to current component clause (in
7660 -- CC), and sets Comp to the entity, and Fbit/Lbit to the zero origin
7661 -- start/stop bits for the field. If there is no matching component or
7662 -- if the matching component does not have a component clause, then
7663 -- that's an error and Comp is set to Empty, but no error message is
7664 -- issued, since the message was already given. Comp is also set to
7665 -- Empty if the current "component clause" is in fact a pragma.
7667 -----------------------------
7668 -- Check_Component_Overlap --
7669 -----------------------------
7671 procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id) is
7672 CC1 : constant Node_Id := Component_Clause (C1_Ent);
7673 CC2 : constant Node_Id := Component_Clause (C2_Ent);
7676 if Present (CC1) and then Present (CC2) then
7678 -- Exclude odd case where we have two tag components in the same
7679 -- record, both at location zero. This seems a bit strange, but
7680 -- it seems to happen in some circumstances, perhaps on an error.
7682 if Chars (C1_Ent) = Name_uTag
7684 Chars (C2_Ent) = Name_uTag
7689 -- Here we check if the two fields overlap
7692 S1 : constant Uint := Component_Bit_Offset (C1_Ent);
7693 S2 : constant Uint := Component_Bit_Offset (C2_Ent);
7694 E1 : constant Uint := S1 + Esize (C1_Ent);
7695 E2 : constant Uint := S2 + Esize (C2_Ent);
7698 if E2 <= S1 or else E1 <= S2 then
7701 Error_Msg_Node_2 := Component_Name (CC2);
7702 Error_Msg_Sloc := Sloc (Error_Msg_Node_2);
7703 Error_Msg_Node_1 := Component_Name (CC1);
7705 ("component& overlaps & #", Component_Name (CC1));
7706 Overlap_Detected := True;
7710 end Check_Component_Overlap;
7712 --------------------
7713 -- Find_Component --
7714 --------------------
7716 procedure Find_Component is
7718 procedure Search_Component (R : Entity_Id);
7719 -- Search components of R for a match. If found, Comp is set
7721 ----------------------
7722 -- Search_Component --
7723 ----------------------
7725 procedure Search_Component (R : Entity_Id) is
7727 Comp := First_Component_Or_Discriminant (R);
7728 while Present (Comp) loop
7730 -- Ignore error of attribute name for component name (we
7731 -- already gave an error message for this, so no need to
7734 if Nkind (Component_Name (CC)) = N_Attribute_Reference then
7737 exit when Chars (Comp) = Chars (Component_Name (CC));
7740 Next_Component_Or_Discriminant (Comp);
7742 end Search_Component;
7744 -- Start of processing for Find_Component
7747 -- Return with Comp set to Empty if we have a pragma
7749 if Nkind (CC) = N_Pragma then
7754 -- Search current record for matching component
7756 Search_Component (Rectype);
7758 -- If not found, maybe component of base type discriminant that is
7759 -- absent from statically constrained first subtype.
7762 Search_Component (Base_Type (Rectype));
7765 -- If no component, or the component does not reference the component
7766 -- clause in question, then there was some previous error for which
7767 -- we already gave a message, so just return with Comp Empty.
7769 if No (Comp) or else Component_Clause (Comp) /= CC then
7770 Check_Error_Detected;
7773 -- Normal case where we have a component clause
7776 Fbit := Component_Bit_Offset (Comp);
7777 Lbit := Fbit + Esize (Comp) - 1;
7781 -- Start of processing for Check_Record_Representation_Clause
7785 Rectype := Entity (Ident);
7787 if Rectype = Any_Type then
7790 Rectype := Underlying_Type (Rectype);
7793 -- See if we have a fully repped derived tagged type
7796 PS : constant Entity_Id := Parent_Subtype (Rectype);
7799 if Present (PS) and then Is_Fully_Repped_Tagged_Type (PS) then
7800 Tagged_Parent := PS;
7802 -- Find maximum bit of any component of the parent type
7804 Parent_Last_Bit := UI_From_Int (System_Address_Size - 1);
7805 Pcomp := First_Entity (Tagged_Parent);
7806 while Present (Pcomp) loop
7807 if Ekind_In (Pcomp, E_Discriminant, E_Component) then
7808 if Component_Bit_Offset (Pcomp) /= No_Uint
7809 and then Known_Static_Esize (Pcomp)
7814 Component_Bit_Offset (Pcomp) + Esize (Pcomp) - 1);
7817 Next_Entity (Pcomp);
7823 -- All done if no component clauses
7825 CC := First (Component_Clauses (N));
7831 -- If a tag is present, then create a component clause that places it
7832 -- at the start of the record (otherwise gigi may place it after other
7833 -- fields that have rep clauses).
7835 Fent := First_Entity (Rectype);
7837 if Nkind (Fent) = N_Defining_Identifier
7838 and then Chars (Fent) = Name_uTag
7840 Set_Component_Bit_Offset (Fent, Uint_0);
7841 Set_Normalized_Position (Fent, Uint_0);
7842 Set_Normalized_First_Bit (Fent, Uint_0);
7843 Set_Normalized_Position_Max (Fent, Uint_0);
7844 Init_Esize (Fent, System_Address_Size);
7846 Set_Component_Clause (Fent,
7847 Make_Component_Clause (Loc,
7848 Component_Name => Make_Identifier (Loc, Name_uTag),
7850 Position => Make_Integer_Literal (Loc, Uint_0),
7851 First_Bit => Make_Integer_Literal (Loc, Uint_0),
7853 Make_Integer_Literal (Loc,
7854 UI_From_Int (System_Address_Size))));
7856 Ccount := Ccount + 1;
7859 Max_Bit_So_Far := Uint_Minus_1;
7860 Overlap_Check_Required := False;
7862 -- Process the component clauses
7864 while Present (CC) loop
7867 if Present (Comp) then
7868 Ccount := Ccount + 1;
7870 -- We need a full overlap check if record positions non-monotonic
7872 if Fbit <= Max_Bit_So_Far then
7873 Overlap_Check_Required := True;
7876 Max_Bit_So_Far := Lbit;
7878 -- Check bit position out of range of specified size
7880 if Has_Size_Clause (Rectype)
7881 and then RM_Size (Rectype) <= Lbit
7884 ("bit number out of range of specified size",
7887 -- Check for overlap with tag component
7890 if Is_Tagged_Type (Rectype)
7891 and then Fbit < System_Address_Size
7894 ("component overlaps tag field of&",
7895 Component_Name (CC), Rectype);
7896 Overlap_Detected := True;
7904 -- Check parent overlap if component might overlap parent field
7906 if Present (Tagged_Parent) and then Fbit <= Parent_Last_Bit then
7907 Pcomp := First_Component_Or_Discriminant (Tagged_Parent);
7908 while Present (Pcomp) loop
7909 if not Is_Tag (Pcomp)
7910 and then Chars (Pcomp) /= Name_uParent
7912 Check_Component_Overlap (Comp, Pcomp);
7915 Next_Component_Or_Discriminant (Pcomp);
7923 -- Now that we have processed all the component clauses, check for
7924 -- overlap. We have to leave this till last, since the components can
7925 -- appear in any arbitrary order in the representation clause.
7927 -- We do not need this check if all specified ranges were monotonic,
7928 -- as recorded by Overlap_Check_Required being False at this stage.
7930 -- This first section checks if there are any overlapping entries at
7931 -- all. It does this by sorting all entries and then seeing if there are
7932 -- any overlaps. If there are none, then that is decisive, but if there
7933 -- are overlaps, they may still be OK (they may result from fields in
7934 -- different variants).
7936 if Overlap_Check_Required then
7937 Overlap_Check1 : declare
7939 OC_Fbit : array (0 .. Ccount) of Uint;
7940 -- First-bit values for component clauses, the value is the offset
7941 -- of the first bit of the field from start of record. The zero
7942 -- entry is for use in sorting.
7944 OC_Lbit : array (0 .. Ccount) of Uint;
7945 -- Last-bit values for component clauses, the value is the offset
7946 -- of the last bit of the field from start of record. The zero
7947 -- entry is for use in sorting.
7949 OC_Count : Natural := 0;
7950 -- Count of entries in OC_Fbit and OC_Lbit
7952 function OC_Lt (Op1, Op2 : Natural) return Boolean;
7953 -- Compare routine for Sort
7955 procedure OC_Move (From : Natural; To : Natural);
7956 -- Move routine for Sort
7958 package Sorting is new GNAT.Heap_Sort_G (OC_Move, OC_Lt);
7964 function OC_Lt (Op1, Op2 : Natural) return Boolean is
7966 return OC_Fbit (Op1) < OC_Fbit (Op2);
7973 procedure OC_Move (From : Natural; To : Natural) is
7975 OC_Fbit (To) := OC_Fbit (From);
7976 OC_Lbit (To) := OC_Lbit (From);
7979 -- Start of processing for Overlap_Check
7982 CC := First (Component_Clauses (N));
7983 while Present (CC) loop
7985 -- Exclude component clause already marked in error
7987 if not Error_Posted (CC) then
7990 if Present (Comp) then
7991 OC_Count := OC_Count + 1;
7992 OC_Fbit (OC_Count) := Fbit;
7993 OC_Lbit (OC_Count) := Lbit;
8000 Sorting.Sort (OC_Count);
8002 Overlap_Check_Required := False;
8003 for J in 1 .. OC_Count - 1 loop
8004 if OC_Lbit (J) >= OC_Fbit (J + 1) then
8005 Overlap_Check_Required := True;
8012 -- If Overlap_Check_Required is still True, then we have to do the full
8013 -- scale overlap check, since we have at least two fields that do
8014 -- overlap, and we need to know if that is OK since they are in
8015 -- different variant, or whether we have a definite problem.
8017 if Overlap_Check_Required then
8018 Overlap_Check2 : declare
8019 C1_Ent, C2_Ent : Entity_Id;
8020 -- Entities of components being checked for overlap
8023 -- Component_List node whose Component_Items are being checked
8026 -- Component declaration for component being checked
8029 C1_Ent := First_Entity (Base_Type (Rectype));
8031 -- Loop through all components in record. For each component check
8032 -- for overlap with any of the preceding elements on the component
8033 -- list containing the component and also, if the component is in
8034 -- a variant, check against components outside the case structure.
8035 -- This latter test is repeated recursively up the variant tree.
8037 Main_Component_Loop : while Present (C1_Ent) loop
8038 if not Ekind_In (C1_Ent, E_Component, E_Discriminant) then
8039 goto Continue_Main_Component_Loop;
8042 -- Skip overlap check if entity has no declaration node. This
8043 -- happens with discriminants in constrained derived types.
8044 -- Possibly we are missing some checks as a result, but that
8045 -- does not seem terribly serious.
8047 if No (Declaration_Node (C1_Ent)) then
8048 goto Continue_Main_Component_Loop;
8051 Clist := Parent (List_Containing (Declaration_Node (C1_Ent)));
8053 -- Loop through component lists that need checking. Check the
8054 -- current component list and all lists in variants above us.
8056 Component_List_Loop : loop
8058 -- If derived type definition, go to full declaration
8059 -- If at outer level, check discriminants if there are any.
8061 if Nkind (Clist) = N_Derived_Type_Definition then
8062 Clist := Parent (Clist);
8065 -- Outer level of record definition, check discriminants
8067 if Nkind_In (Clist, N_Full_Type_Declaration,
8068 N_Private_Type_Declaration)
8070 if Has_Discriminants (Defining_Identifier (Clist)) then
8072 First_Discriminant (Defining_Identifier (Clist));
8073 while Present (C2_Ent) loop
8074 exit when C1_Ent = C2_Ent;
8075 Check_Component_Overlap (C1_Ent, C2_Ent);
8076 Next_Discriminant (C2_Ent);
8080 -- Record extension case
8082 elsif Nkind (Clist) = N_Derived_Type_Definition then
8085 -- Otherwise check one component list
8088 Citem := First (Component_Items (Clist));
8089 while Present (Citem) loop
8090 if Nkind (Citem) = N_Component_Declaration then
8091 C2_Ent := Defining_Identifier (Citem);
8092 exit when C1_Ent = C2_Ent;
8093 Check_Component_Overlap (C1_Ent, C2_Ent);
8100 -- Check for variants above us (the parent of the Clist can
8101 -- be a variant, in which case its parent is a variant part,
8102 -- and the parent of the variant part is a component list
8103 -- whose components must all be checked against the current
8104 -- component for overlap).
8106 if Nkind (Parent (Clist)) = N_Variant then
8107 Clist := Parent (Parent (Parent (Clist)));
8109 -- Check for possible discriminant part in record, this
8110 -- is treated essentially as another level in the
8111 -- recursion. For this case the parent of the component
8112 -- list is the record definition, and its parent is the
8113 -- full type declaration containing the discriminant
8116 elsif Nkind (Parent (Clist)) = N_Record_Definition then
8117 Clist := Parent (Parent ((Clist)));
8119 -- If neither of these two cases, we are at the top of
8123 exit Component_List_Loop;
8125 end loop Component_List_Loop;
8127 <<Continue_Main_Component_Loop>>
8128 Next_Entity (C1_Ent);
8130 end loop Main_Component_Loop;
8134 -- The following circuit deals with warning on record holes (gaps). We
8135 -- skip this check if overlap was detected, since it makes sense for the
8136 -- programmer to fix this illegality before worrying about warnings.
8138 if not Overlap_Detected and Warn_On_Record_Holes then
8139 Record_Hole_Check : declare
8140 Decl : constant Node_Id := Declaration_Node (Base_Type (Rectype));
8141 -- Full declaration of record type
8143 procedure Check_Component_List
8147 -- Check component list CL for holes. The starting bit should be
8148 -- Sbit. which is zero for the main record component list and set
8149 -- appropriately for recursive calls for variants. DS is set to
8150 -- a list of discriminant specifications to be included in the
8151 -- consideration of components. It is No_List if none to consider.
8153 --------------------------
8154 -- Check_Component_List --
8155 --------------------------
8157 procedure Check_Component_List
8165 Compl := Integer (List_Length (Component_Items (CL)));
8167 if DS /= No_List then
8168 Compl := Compl + Integer (List_Length (DS));
8172 Comps : array (Natural range 0 .. Compl) of Entity_Id;
8173 -- Gather components (zero entry is for sort routine)
8175 Ncomps : Natural := 0;
8176 -- Number of entries stored in Comps (starting at Comps (1))
8179 -- One component item or discriminant specification
8182 -- Starting bit for next component
8190 function Lt (Op1, Op2 : Natural) return Boolean;
8191 -- Compare routine for Sort
8193 procedure Move (From : Natural; To : Natural);
8194 -- Move routine for Sort
8196 package Sorting is new GNAT.Heap_Sort_G (Move, Lt);
8202 function Lt (Op1, Op2 : Natural) return Boolean is
8204 return Component_Bit_Offset (Comps (Op1))
8206 Component_Bit_Offset (Comps (Op2));
8213 procedure Move (From : Natural; To : Natural) is
8215 Comps (To) := Comps (From);
8219 -- Gather discriminants into Comp
8221 if DS /= No_List then
8222 Citem := First (DS);
8223 while Present (Citem) loop
8224 if Nkind (Citem) = N_Discriminant_Specification then
8226 Ent : constant Entity_Id :=
8227 Defining_Identifier (Citem);
8229 if Ekind (Ent) = E_Discriminant then
8230 Ncomps := Ncomps + 1;
8231 Comps (Ncomps) := Ent;
8240 -- Gather component entities into Comp
8242 Citem := First (Component_Items (CL));
8243 while Present (Citem) loop
8244 if Nkind (Citem) = N_Component_Declaration then
8245 Ncomps := Ncomps + 1;
8246 Comps (Ncomps) := Defining_Identifier (Citem);
8252 -- Now sort the component entities based on the first bit.
8253 -- Note we already know there are no overlapping components.
8255 Sorting.Sort (Ncomps);
8257 -- Loop through entries checking for holes
8260 for J in 1 .. Ncomps loop
8262 Error_Msg_Uint_1 := Component_Bit_Offset (CEnt) - Nbit;
8264 if Error_Msg_Uint_1 > 0 then
8266 ("?H?^-bit gap before component&",
8267 Component_Name (Component_Clause (CEnt)), CEnt);
8270 Nbit := Component_Bit_Offset (CEnt) + Esize (CEnt);
8273 -- Process variant parts recursively if present
8275 if Present (Variant_Part (CL)) then
8276 Variant := First (Variants (Variant_Part (CL)));
8277 while Present (Variant) loop
8278 Check_Component_List
8279 (Component_List (Variant), Nbit, No_List);
8284 end Check_Component_List;
8286 -- Start of processing for Record_Hole_Check
8293 if Is_Tagged_Type (Rectype) then
8294 Sbit := UI_From_Int (System_Address_Size);
8299 if Nkind (Decl) = N_Full_Type_Declaration
8300 and then Nkind (Type_Definition (Decl)) = N_Record_Definition
8302 Check_Component_List
8303 (Component_List (Type_Definition (Decl)),
8305 Discriminant_Specifications (Decl));
8308 end Record_Hole_Check;
8311 -- For records that have component clauses for all components, and whose
8312 -- size is less than or equal to 32, we need to know the size in the
8313 -- front end to activate possible packed array processing where the
8314 -- component type is a record.
8316 -- At this stage Hbit + 1 represents the first unused bit from all the
8317 -- component clauses processed, so if the component clauses are
8318 -- complete, then this is the length of the record.
8320 -- For records longer than System.Storage_Unit, and for those where not
8321 -- all components have component clauses, the back end determines the
8322 -- length (it may for example be appropriate to round up the size
8323 -- to some convenient boundary, based on alignment considerations, etc).
8325 if Unknown_RM_Size (Rectype) and then Hbit + 1 <= 32 then
8327 -- Nothing to do if at least one component has no component clause
8329 Comp := First_Component_Or_Discriminant (Rectype);
8330 while Present (Comp) loop
8331 exit when No (Component_Clause (Comp));
8332 Next_Component_Or_Discriminant (Comp);
8335 -- If we fall out of loop, all components have component clauses
8336 -- and so we can set the size to the maximum value.
8339 Set_RM_Size (Rectype, Hbit + 1);
8342 end Check_Record_Representation_Clause;
8348 procedure Check_Size
8352 Biased : out Boolean)
8354 UT : constant Entity_Id := Underlying_Type (T);
8360 -- Reject patently improper size values.
8362 if Is_Elementary_Type (T)
8363 and then Siz > UI_From_Int (Int'Last)
8365 Error_Msg_N ("Size value too large for elementary type", N);
8367 if Nkind (Original_Node (N)) = N_Op_Expon then
8369 ("\maybe '* was meant, rather than '*'*", Original_Node (N));
8373 -- Dismiss generic types
8375 if Is_Generic_Type (T)
8377 Is_Generic_Type (UT)
8379 Is_Generic_Type (Root_Type (UT))
8383 -- Guard against previous errors
8385 elsif No (UT) or else UT = Any_Type then
8386 Check_Error_Detected;
8389 -- Check case of bit packed array
8391 elsif Is_Array_Type (UT)
8392 and then Known_Static_Component_Size (UT)
8393 and then Is_Bit_Packed_Array (UT)
8401 Asiz := Component_Size (UT);
8402 Indx := First_Index (UT);
8404 Ityp := Etype (Indx);
8406 -- If non-static bound, then we are not in the business of
8407 -- trying to check the length, and indeed an error will be
8408 -- issued elsewhere, since sizes of non-static array types
8409 -- cannot be set implicitly or explicitly.
8411 if not Is_Static_Subtype (Ityp) then
8415 -- Otherwise accumulate next dimension
8417 Asiz := Asiz * (Expr_Value (Type_High_Bound (Ityp)) -
8418 Expr_Value (Type_Low_Bound (Ityp)) +
8422 exit when No (Indx);
8429 Error_Msg_Uint_1 := Asiz;
8431 ("size for& too small, minimum allowed is ^", N, T);
8432 Set_Esize (T, Asiz);
8433 Set_RM_Size (T, Asiz);
8437 -- All other composite types are ignored
8439 elsif Is_Composite_Type (UT) then
8442 -- For fixed-point types, don't check minimum if type is not frozen,
8443 -- since we don't know all the characteristics of the type that can
8444 -- affect the size (e.g. a specified small) till freeze time.
8446 elsif Is_Fixed_Point_Type (UT)
8447 and then not Is_Frozen (UT)
8451 -- Cases for which a minimum check is required
8454 -- Ignore if specified size is correct for the type
8456 if Known_Esize (UT) and then Siz = Esize (UT) then
8460 -- Otherwise get minimum size
8462 M := UI_From_Int (Minimum_Size (UT));
8466 -- Size is less than minimum size, but one possibility remains
8467 -- that we can manage with the new size if we bias the type.
8469 M := UI_From_Int (Minimum_Size (UT, Biased => True));
8472 Error_Msg_Uint_1 := M;
8474 ("size for& too small, minimum allowed is ^", N, T);
8484 -------------------------
8485 -- Get_Alignment_Value --
8486 -------------------------
8488 function Get_Alignment_Value (Expr : Node_Id) return Uint is
8489 Align : constant Uint := Static_Integer (Expr);
8492 if Align = No_Uint then
8495 elsif Align <= 0 then
8496 Error_Msg_N ("alignment value must be positive", Expr);
8500 for J in Int range 0 .. 64 loop
8502 M : constant Uint := Uint_2 ** J;
8505 exit when M = Align;
8509 ("alignment value must be power of 2", Expr);
8517 end Get_Alignment_Value;
8519 -------------------------------------
8520 -- Inherit_Aspects_At_Freeze_Point --
8521 -------------------------------------
8523 procedure Inherit_Aspects_At_Freeze_Point (Typ : Entity_Id) is
8524 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
8525 (Rep_Item : Node_Id) return Boolean;
8526 -- This routine checks if Rep_Item is either a pragma or an aspect
8527 -- specification node whose correponding pragma (if any) is present in
8528 -- the Rep Item chain of the entity it has been specified to.
8530 --------------------------------------------------
8531 -- Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item --
8532 --------------------------------------------------
8534 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
8535 (Rep_Item : Node_Id) return Boolean
8538 return Nkind (Rep_Item) = N_Pragma
8539 or else Present_In_Rep_Item
8540 (Entity (Rep_Item), Aspect_Rep_Item (Rep_Item));
8541 end Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item;
8543 -- Start of processing for Inherit_Aspects_At_Freeze_Point
8546 -- A representation item is either subtype-specific (Size and Alignment
8547 -- clauses) or type-related (all others). Subtype-specific aspects may
8548 -- differ for different subtypes of the same type (RM 13.1.8).
8550 -- A derived type inherits each type-related representation aspect of
8551 -- its parent type that was directly specified before the declaration of
8552 -- the derived type (RM 13.1.15).
8554 -- A derived subtype inherits each subtype-specific representation
8555 -- aspect of its parent subtype that was directly specified before the
8556 -- declaration of the derived type (RM 13.1.15).
8558 -- The general processing involves inheriting a representation aspect
8559 -- from a parent type whenever the first rep item (aspect specification,
8560 -- attribute definition clause, pragma) corresponding to the given
8561 -- representation aspect in the rep item chain of Typ, if any, isn't
8562 -- directly specified to Typ but to one of its parents.
8564 -- ??? Note that, for now, just a limited number of representation
8565 -- aspects have been inherited here so far. Many of them are
8566 -- still inherited in Sem_Ch3. This will be fixed soon. Here is
8567 -- a non- exhaustive list of aspects that likely also need to
8568 -- be moved to this routine: Alignment, Component_Alignment,
8569 -- Component_Size, Machine_Radix, Object_Size, Pack, Predicates,
8570 -- Preelaborable_Initialization, RM_Size and Small.
8572 if Nkind (Parent (Typ)) = N_Private_Extension_Declaration then
8578 if not Has_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005, False)
8579 and then Has_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005)
8580 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
8581 (Get_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005))
8583 Set_Is_Ada_2005_Only (Typ);
8588 if not Has_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012, False)
8589 and then Has_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012)
8590 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
8591 (Get_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012))
8593 Set_Is_Ada_2012_Only (Typ);
8598 if not Has_Rep_Item (Typ, Name_Atomic, Name_Shared, False)
8599 and then Has_Rep_Pragma (Typ, Name_Atomic, Name_Shared)
8600 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
8601 (Get_Rep_Item (Typ, Name_Atomic, Name_Shared))
8603 Set_Is_Atomic (Typ);
8604 Set_Treat_As_Volatile (Typ);
8605 Set_Is_Volatile (Typ);
8608 -- Default_Component_Value
8610 if Is_Array_Type (Typ)
8611 and then Has_Rep_Item (Typ, Name_Default_Component_Value, False)
8612 and then Has_Rep_Item (Typ, Name_Default_Component_Value)
8614 Set_Default_Aspect_Component_Value (Typ,
8615 Default_Aspect_Component_Value
8616 (Entity (Get_Rep_Item (Typ, Name_Default_Component_Value))));
8621 if Is_Scalar_Type (Typ)
8622 and then Has_Rep_Item (Typ, Name_Default_Value, False)
8623 and then Has_Rep_Item (Typ, Name_Default_Value)
8625 Set_Default_Aspect_Value (Typ,
8626 Default_Aspect_Value
8627 (Entity (Get_Rep_Item (Typ, Name_Default_Value))));
8632 if not Has_Rep_Item (Typ, Name_Discard_Names, False)
8633 and then Has_Rep_Item (Typ, Name_Discard_Names)
8634 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
8635 (Get_Rep_Item (Typ, Name_Discard_Names))
8637 Set_Discard_Names (Typ);
8642 if not Has_Rep_Item (Typ, Name_Invariant, False)
8643 and then Has_Rep_Item (Typ, Name_Invariant)
8644 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
8645 (Get_Rep_Item (Typ, Name_Invariant))
8647 Set_Has_Invariants (Typ);
8649 if Class_Present (Get_Rep_Item (Typ, Name_Invariant)) then
8650 Set_Has_Inheritable_Invariants (Typ);
8656 if not Has_Rep_Item (Typ, Name_Volatile, False)
8657 and then Has_Rep_Item (Typ, Name_Volatile)
8658 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
8659 (Get_Rep_Item (Typ, Name_Volatile))
8661 Set_Treat_As_Volatile (Typ);
8662 Set_Is_Volatile (Typ);
8665 -- Inheritance for derived types only
8667 if Is_Derived_Type (Typ) then
8669 Bas_Typ : constant Entity_Id := Base_Type (Typ);
8670 Imp_Bas_Typ : constant Entity_Id := Implementation_Base_Type (Typ);
8673 -- Atomic_Components
8675 if not Has_Rep_Item (Typ, Name_Atomic_Components, False)
8676 and then Has_Rep_Item (Typ, Name_Atomic_Components)
8677 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
8678 (Get_Rep_Item (Typ, Name_Atomic_Components))
8680 Set_Has_Atomic_Components (Imp_Bas_Typ);
8683 -- Volatile_Components
8685 if not Has_Rep_Item (Typ, Name_Volatile_Components, False)
8686 and then Has_Rep_Item (Typ, Name_Volatile_Components)
8687 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
8688 (Get_Rep_Item (Typ, Name_Volatile_Components))
8690 Set_Has_Volatile_Components (Imp_Bas_Typ);
8693 -- Finalize_Storage_Only.
8695 if not Has_Rep_Pragma (Typ, Name_Finalize_Storage_Only, False)
8696 and then Has_Rep_Pragma (Typ, Name_Finalize_Storage_Only)
8698 Set_Finalize_Storage_Only (Bas_Typ);
8701 -- Universal_Aliasing
8703 if not Has_Rep_Item (Typ, Name_Universal_Aliasing, False)
8704 and then Has_Rep_Item (Typ, Name_Universal_Aliasing)
8705 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
8706 (Get_Rep_Item (Typ, Name_Universal_Aliasing))
8708 Set_Universal_Aliasing (Imp_Bas_Typ);
8711 -- Record type specific aspects
8713 if Is_Record_Type (Typ) then
8717 if not Has_Rep_Item (Typ, Name_Bit_Order, False)
8718 and then Has_Rep_Item (Typ, Name_Bit_Order)
8720 Set_Reverse_Bit_Order (Bas_Typ,
8721 Reverse_Bit_Order (Entity (Name
8722 (Get_Rep_Item (Typ, Name_Bit_Order)))));
8725 -- Scalar_Storage_Order
8727 if not Has_Rep_Item (Typ, Name_Scalar_Storage_Order, False)
8728 and then Has_Rep_Item (Typ, Name_Scalar_Storage_Order)
8730 Set_Reverse_Storage_Order (Bas_Typ,
8731 Reverse_Storage_Order (Entity (Name
8732 (Get_Rep_Item (Typ, Name_Scalar_Storage_Order)))));
8737 end Inherit_Aspects_At_Freeze_Point;
8743 procedure Initialize is
8745 Address_Clause_Checks.Init;
8746 Independence_Checks.Init;
8747 Unchecked_Conversions.Init;
8750 -------------------------
8751 -- Is_Operational_Item --
8752 -------------------------
8754 function Is_Operational_Item (N : Node_Id) return Boolean is
8756 if Nkind (N) /= N_Attribute_Definition_Clause then
8761 Id : constant Attribute_Id := Get_Attribute_Id (Chars (N));
8763 return Id = Attribute_Input
8764 or else Id = Attribute_Output
8765 or else Id = Attribute_Read
8766 or else Id = Attribute_Write
8767 or else Id = Attribute_External_Tag;
8770 end Is_Operational_Item;
8776 function Minimum_Size
8778 Biased : Boolean := False) return Nat
8780 Lo : Uint := No_Uint;
8781 Hi : Uint := No_Uint;
8782 LoR : Ureal := No_Ureal;
8783 HiR : Ureal := No_Ureal;
8784 LoSet : Boolean := False;
8785 HiSet : Boolean := False;
8789 R_Typ : constant Entity_Id := Root_Type (T);
8792 -- If bad type, return 0
8794 if T = Any_Type then
8797 -- For generic types, just return zero. There cannot be any legitimate
8798 -- need to know such a size, but this routine may be called with a
8799 -- generic type as part of normal processing.
8801 elsif Is_Generic_Type (R_Typ)
8802 or else R_Typ = Any_Type
8806 -- Access types. Normally an access type cannot have a size smaller
8807 -- than the size of System.Address. The exception is on VMS, where
8808 -- we have short and long addresses, and it is possible for an access
8809 -- type to have a short address size (and thus be less than the size
8810 -- of System.Address itself). We simply skip the check for VMS, and
8811 -- leave it to the back end to do the check.
8813 elsif Is_Access_Type (T) then
8814 if OpenVMS_On_Target then
8817 return System_Address_Size;
8820 -- Floating-point types
8822 elsif Is_Floating_Point_Type (T) then
8823 return UI_To_Int (Esize (R_Typ));
8827 elsif Is_Discrete_Type (T) then
8829 -- The following loop is looking for the nearest compile time known
8830 -- bounds following the ancestor subtype chain. The idea is to find
8831 -- the most restrictive known bounds information.
8835 if Ancest = Any_Type or else Etype (Ancest) = Any_Type then
8840 if Compile_Time_Known_Value (Type_Low_Bound (Ancest)) then
8841 Lo := Expr_Rep_Value (Type_Low_Bound (Ancest));
8848 if Compile_Time_Known_Value (Type_High_Bound (Ancest)) then
8849 Hi := Expr_Rep_Value (Type_High_Bound (Ancest));
8855 Ancest := Ancestor_Subtype (Ancest);
8858 Ancest := Base_Type (T);
8860 if Is_Generic_Type (Ancest) then
8866 -- Fixed-point types. We can't simply use Expr_Value to get the
8867 -- Corresponding_Integer_Value values of the bounds, since these do not
8868 -- get set till the type is frozen, and this routine can be called
8869 -- before the type is frozen. Similarly the test for bounds being static
8870 -- needs to include the case where we have unanalyzed real literals for
8873 elsif Is_Fixed_Point_Type (T) then
8875 -- The following loop is looking for the nearest compile time known
8876 -- bounds following the ancestor subtype chain. The idea is to find
8877 -- the most restrictive known bounds information.
8881 if Ancest = Any_Type or else Etype (Ancest) = Any_Type then
8885 -- Note: In the following two tests for LoSet and HiSet, it may
8886 -- seem redundant to test for N_Real_Literal here since normally
8887 -- one would assume that the test for the value being known at
8888 -- compile time includes this case. However, there is a glitch.
8889 -- If the real literal comes from folding a non-static expression,
8890 -- then we don't consider any non- static expression to be known
8891 -- at compile time if we are in configurable run time mode (needed
8892 -- in some cases to give a clearer definition of what is and what
8893 -- is not accepted). So the test is indeed needed. Without it, we
8894 -- would set neither Lo_Set nor Hi_Set and get an infinite loop.
8897 if Nkind (Type_Low_Bound (Ancest)) = N_Real_Literal
8898 or else Compile_Time_Known_Value (Type_Low_Bound (Ancest))
8900 LoR := Expr_Value_R (Type_Low_Bound (Ancest));
8907 if Nkind (Type_High_Bound (Ancest)) = N_Real_Literal
8908 or else Compile_Time_Known_Value (Type_High_Bound (Ancest))
8910 HiR := Expr_Value_R (Type_High_Bound (Ancest));
8916 Ancest := Ancestor_Subtype (Ancest);
8919 Ancest := Base_Type (T);
8921 if Is_Generic_Type (Ancest) then
8927 Lo := UR_To_Uint (LoR / Small_Value (T));
8928 Hi := UR_To_Uint (HiR / Small_Value (T));
8930 -- No other types allowed
8933 raise Program_Error;
8936 -- Fall through with Hi and Lo set. Deal with biased case
8939 and then not Is_Fixed_Point_Type (T)
8940 and then not (Is_Enumeration_Type (T)
8941 and then Has_Non_Standard_Rep (T)))
8942 or else Has_Biased_Representation (T)
8948 -- Signed case. Note that we consider types like range 1 .. -1 to be
8949 -- signed for the purpose of computing the size, since the bounds have
8950 -- to be accommodated in the base type.
8952 if Lo < 0 or else Hi < 0 then
8956 -- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1))
8957 -- Note that we accommodate the case where the bounds cross. This
8958 -- can happen either because of the way the bounds are declared
8959 -- or because of the algorithm in Freeze_Fixed_Point_Type.
8973 -- If both bounds are positive, make sure that both are represen-
8974 -- table in the case where the bounds are crossed. This can happen
8975 -- either because of the way the bounds are declared, or because of
8976 -- the algorithm in Freeze_Fixed_Point_Type.
8982 -- S = size, (can accommodate 0 .. (2**size - 1))
8985 while Hi >= Uint_2 ** S loop
8993 ---------------------------
8994 -- New_Stream_Subprogram --
8995 ---------------------------
8997 procedure New_Stream_Subprogram
9001 Nam : TSS_Name_Type)
9003 Loc : constant Source_Ptr := Sloc (N);
9004 Sname : constant Name_Id := Make_TSS_Name (Base_Type (Ent), Nam);
9005 Subp_Id : Entity_Id;
9006 Subp_Decl : Node_Id;
9010 Defer_Declaration : constant Boolean :=
9011 Is_Tagged_Type (Ent) or else Is_Private_Type (Ent);
9012 -- For a tagged type, there is a declaration for each stream attribute
9013 -- at the freeze point, and we must generate only a completion of this
9014 -- declaration. We do the same for private types, because the full view
9015 -- might be tagged. Otherwise we generate a declaration at the point of
9016 -- the attribute definition clause.
9018 function Build_Spec return Node_Id;
9019 -- Used for declaration and renaming declaration, so that this is
9020 -- treated as a renaming_as_body.
9026 function Build_Spec return Node_Id is
9027 Out_P : constant Boolean := (Nam = TSS_Stream_Read);
9030 T_Ref : constant Node_Id := New_Reference_To (Etyp, Loc);
9033 Subp_Id := Make_Defining_Identifier (Loc, Sname);
9035 -- S : access Root_Stream_Type'Class
9037 Formals := New_List (
9038 Make_Parameter_Specification (Loc,
9039 Defining_Identifier =>
9040 Make_Defining_Identifier (Loc, Name_S),
9042 Make_Access_Definition (Loc,
9045 Designated_Type (Etype (F)), Loc))));
9047 if Nam = TSS_Stream_Input then
9049 Make_Function_Specification (Loc,
9050 Defining_Unit_Name => Subp_Id,
9051 Parameter_Specifications => Formals,
9052 Result_Definition => T_Ref);
9057 Make_Parameter_Specification (Loc,
9058 Defining_Identifier => Make_Defining_Identifier (Loc, Name_V),
9059 Out_Present => Out_P,
9060 Parameter_Type => T_Ref));
9063 Make_Procedure_Specification (Loc,
9064 Defining_Unit_Name => Subp_Id,
9065 Parameter_Specifications => Formals);
9071 -- Start of processing for New_Stream_Subprogram
9074 F := First_Formal (Subp);
9076 if Ekind (Subp) = E_Procedure then
9077 Etyp := Etype (Next_Formal (F));
9079 Etyp := Etype (Subp);
9082 -- Prepare subprogram declaration and insert it as an action on the
9083 -- clause node. The visibility for this entity is used to test for
9084 -- visibility of the attribute definition clause (in the sense of
9085 -- 8.3(23) as amended by AI-195).
9087 if not Defer_Declaration then
9089 Make_Subprogram_Declaration (Loc,
9090 Specification => Build_Spec);
9092 -- For a tagged type, there is always a visible declaration for each
9093 -- stream TSS (it is a predefined primitive operation), and the
9094 -- completion of this declaration occurs at the freeze point, which is
9095 -- not always visible at places where the attribute definition clause is
9096 -- visible. So, we create a dummy entity here for the purpose of
9097 -- tracking the visibility of the attribute definition clause itself.
9101 Make_Defining_Identifier (Loc, New_External_Name (Sname, 'V'));
9103 Make_Object_Declaration (Loc,
9104 Defining_Identifier => Subp_Id,
9105 Object_Definition => New_Occurrence_Of (Standard_Boolean, Loc));
9108 Insert_Action (N, Subp_Decl);
9109 Set_Entity (N, Subp_Id);
9112 Make_Subprogram_Renaming_Declaration (Loc,
9113 Specification => Build_Spec,
9114 Name => New_Reference_To (Subp, Loc));
9116 if Defer_Declaration then
9117 Set_TSS (Base_Type (Ent), Subp_Id);
9119 Insert_Action (N, Subp_Decl);
9120 Copy_TSS (Subp_Id, Base_Type (Ent));
9122 end New_Stream_Subprogram;
9124 ------------------------
9125 -- Rep_Item_Too_Early --
9126 ------------------------
9128 function Rep_Item_Too_Early (T : Entity_Id; N : Node_Id) return Boolean is
9130 -- Cannot apply non-operational rep items to generic types
9132 if Is_Operational_Item (N) then
9136 and then Is_Generic_Type (Root_Type (T))
9138 Error_Msg_N ("representation item not allowed for generic type", N);
9142 -- Otherwise check for incomplete type
9144 if Is_Incomplete_Or_Private_Type (T)
9145 and then No (Underlying_Type (T))
9147 (Nkind (N) /= N_Pragma
9148 or else Get_Pragma_Id (N) /= Pragma_Import)
9151 ("representation item must be after full type declaration", N);
9154 -- If the type has incomplete components, a representation clause is
9155 -- illegal but stream attributes and Convention pragmas are correct.
9157 elsif Has_Private_Component (T) then
9158 if Nkind (N) = N_Pragma then
9163 ("representation item must appear after type is fully defined",
9170 end Rep_Item_Too_Early;
9172 -----------------------
9173 -- Rep_Item_Too_Late --
9174 -----------------------
9176 function Rep_Item_Too_Late
9179 FOnly : Boolean := False) return Boolean
9182 Parent_Type : Entity_Id;
9185 -- Output the too late message. Note that this is not considered a
9186 -- serious error, since the effect is simply that we ignore the
9187 -- representation clause in this case.
9193 procedure Too_Late is
9195 -- Other compilers seem more relaxed about rep items appearing too
9196 -- late. Since analysis tools typically don't care about rep items
9197 -- anyway, no reason to be too strict about this.
9199 if not Relaxed_RM_Semantics then
9200 Error_Msg_N ("|representation item appears too late!", N);
9204 -- Start of processing for Rep_Item_Too_Late
9207 -- First make sure entity is not frozen (RM 13.1(9))
9211 -- Exclude imported types, which may be frozen if they appear in a
9212 -- representation clause for a local type.
9214 and then not From_With_Type (T)
9216 -- Exclude generated entities (not coming from source). The common
9217 -- case is when we generate a renaming which prematurely freezes the
9218 -- renamed internal entity, but we still want to be able to set copies
9219 -- of attribute values such as Size/Alignment.
9221 and then Comes_From_Source (T)
9224 S := First_Subtype (T);
9226 if Present (Freeze_Node (S)) then
9228 ("??no more representation items for }", Freeze_Node (S), S);
9233 -- Check for case of non-tagged derived type whose parent either has
9234 -- primitive operations, or is a by reference type (RM 13.1(10)).
9238 and then Is_Derived_Type (T)
9239 and then not Is_Tagged_Type (T)
9241 Parent_Type := Etype (Base_Type (T));
9243 if Has_Primitive_Operations (Parent_Type) then
9246 ("primitive operations already defined for&!", N, Parent_Type);
9249 elsif Is_By_Reference_Type (Parent_Type) then
9252 ("parent type & is a by reference type!", N, Parent_Type);
9257 -- No error, link item into head of chain of rep items for the entity,
9258 -- but avoid chaining if we have an overloadable entity, and the pragma
9259 -- is one that can apply to multiple overloaded entities.
9261 if Is_Overloadable (T) and then Nkind (N) = N_Pragma then
9263 Pname : constant Name_Id := Pragma_Name (N);
9265 if Pname = Name_Convention or else
9266 Pname = Name_Import or else
9267 Pname = Name_Export or else
9268 Pname = Name_External or else
9269 Pname = Name_Interface
9276 Record_Rep_Item (T, N);
9278 end Rep_Item_Too_Late;
9280 -------------------------------------
9281 -- Replace_Type_References_Generic --
9282 -------------------------------------
9284 procedure Replace_Type_References_Generic (N : Node_Id; TName : Name_Id) is
9286 function Replace_Node (N : Node_Id) return Traverse_Result;
9287 -- Processes a single node in the traversal procedure below, checking
9288 -- if node N should be replaced, and if so, doing the replacement.
9290 procedure Replace_Type_Refs is new Traverse_Proc (Replace_Node);
9291 -- This instantiation provides the body of Replace_Type_References
9297 function Replace_Node (N : Node_Id) return Traverse_Result is
9302 -- Case of identifier
9304 if Nkind (N) = N_Identifier then
9306 -- If not the type name, all done with this node
9308 if Chars (N) /= TName then
9311 -- Otherwise do the replacement and we are done with this node
9314 Replace_Type_Reference (N);
9318 -- Case of selected component (which is what a qualification
9319 -- looks like in the unanalyzed tree, which is what we have.
9321 elsif Nkind (N) = N_Selected_Component then
9323 -- If selector name is not our type, keeping going (we might
9324 -- still have an occurrence of the type in the prefix).
9326 if Nkind (Selector_Name (N)) /= N_Identifier
9327 or else Chars (Selector_Name (N)) /= TName
9331 -- Selector name is our type, check qualification
9334 -- Loop through scopes and prefixes, doing comparison
9339 -- Continue if no more scopes or scope with no name
9341 if No (S) or else Nkind (S) not in N_Has_Chars then
9345 -- Do replace if prefix is an identifier matching the
9346 -- scope that we are currently looking at.
9348 if Nkind (P) = N_Identifier
9349 and then Chars (P) = Chars (S)
9351 Replace_Type_Reference (N);
9355 -- Go check scope above us if prefix is itself of the
9356 -- form of a selected component, whose selector matches
9357 -- the scope we are currently looking at.
9359 if Nkind (P) = N_Selected_Component
9360 and then Nkind (Selector_Name (P)) = N_Identifier
9361 and then Chars (Selector_Name (P)) = Chars (S)
9366 -- For anything else, we don't have a match, so keep on
9367 -- going, there are still some weird cases where we may
9368 -- still have a replacement within the prefix.
9376 -- Continue for any other node kind
9384 Replace_Type_Refs (N);
9385 end Replace_Type_References_Generic;
9387 -------------------------
9388 -- Same_Representation --
9389 -------------------------
9391 function Same_Representation (Typ1, Typ2 : Entity_Id) return Boolean is
9392 T1 : constant Entity_Id := Underlying_Type (Typ1);
9393 T2 : constant Entity_Id := Underlying_Type (Typ2);
9396 -- A quick check, if base types are the same, then we definitely have
9397 -- the same representation, because the subtype specific representation
9398 -- attributes (Size and Alignment) do not affect representation from
9399 -- the point of view of this test.
9401 if Base_Type (T1) = Base_Type (T2) then
9404 elsif Is_Private_Type (Base_Type (T2))
9405 and then Base_Type (T1) = Full_View (Base_Type (T2))
9410 -- Tagged types never have differing representations
9412 if Is_Tagged_Type (T1) then
9416 -- Representations are definitely different if conventions differ
9418 if Convention (T1) /= Convention (T2) then
9422 -- Representations are different if component alignments differ
9424 if (Is_Record_Type (T1) or else Is_Array_Type (T1))
9426 (Is_Record_Type (T2) or else Is_Array_Type (T2))
9427 and then Component_Alignment (T1) /= Component_Alignment (T2)
9432 -- For arrays, the only real issue is component size. If we know the
9433 -- component size for both arrays, and it is the same, then that's
9434 -- good enough to know we don't have a change of representation.
9436 if Is_Array_Type (T1) then
9437 if Known_Component_Size (T1)
9438 and then Known_Component_Size (T2)
9439 and then Component_Size (T1) = Component_Size (T2)
9441 if VM_Target = No_VM then
9444 -- In VM targets the representation of arrays with aliased
9445 -- components differs from arrays with non-aliased components
9448 return Has_Aliased_Components (Base_Type (T1))
9450 Has_Aliased_Components (Base_Type (T2));
9455 -- Types definitely have same representation if neither has non-standard
9456 -- representation since default representations are always consistent.
9457 -- If only one has non-standard representation, and the other does not,
9458 -- then we consider that they do not have the same representation. They
9459 -- might, but there is no way of telling early enough.
9461 if Has_Non_Standard_Rep (T1) then
9462 if not Has_Non_Standard_Rep (T2) then
9466 return not Has_Non_Standard_Rep (T2);
9469 -- Here the two types both have non-standard representation, and we need
9470 -- to determine if they have the same non-standard representation.
9472 -- For arrays, we simply need to test if the component sizes are the
9473 -- same. Pragma Pack is reflected in modified component sizes, so this
9474 -- check also deals with pragma Pack.
9476 if Is_Array_Type (T1) then
9477 return Component_Size (T1) = Component_Size (T2);
9479 -- Tagged types always have the same representation, because it is not
9480 -- possible to specify different representations for common fields.
9482 elsif Is_Tagged_Type (T1) then
9485 -- Case of record types
9487 elsif Is_Record_Type (T1) then
9489 -- Packed status must conform
9491 if Is_Packed (T1) /= Is_Packed (T2) then
9494 -- Otherwise we must check components. Typ2 maybe a constrained
9495 -- subtype with fewer components, so we compare the components
9496 -- of the base types.
9499 Record_Case : declare
9500 CD1, CD2 : Entity_Id;
9502 function Same_Rep return Boolean;
9503 -- CD1 and CD2 are either components or discriminants. This
9504 -- function tests whether the two have the same representation
9510 function Same_Rep return Boolean is
9512 if No (Component_Clause (CD1)) then
9513 return No (Component_Clause (CD2));
9517 Present (Component_Clause (CD2))
9519 Component_Bit_Offset (CD1) = Component_Bit_Offset (CD2)
9521 Esize (CD1) = Esize (CD2);
9525 -- Start of processing for Record_Case
9528 if Has_Discriminants (T1) then
9530 -- The number of discriminants may be different if the
9531 -- derived type has fewer (constrained by values). The
9532 -- invisible discriminants retain the representation of
9533 -- the original, so the discrepancy does not per se
9534 -- indicate a different representation.
9536 CD1 := First_Discriminant (T1);
9537 CD2 := First_Discriminant (T2);
9538 while Present (CD1) and then Present (CD2) loop
9539 if not Same_Rep then
9542 Next_Discriminant (CD1);
9543 Next_Discriminant (CD2);
9548 CD1 := First_Component (Underlying_Type (Base_Type (T1)));
9549 CD2 := First_Component (Underlying_Type (Base_Type (T2)));
9550 while Present (CD1) loop
9551 if not Same_Rep then
9554 Next_Component (CD1);
9555 Next_Component (CD2);
9563 -- For enumeration types, we must check each literal to see if the
9564 -- representation is the same. Note that we do not permit enumeration
9565 -- representation clauses for Character and Wide_Character, so these
9566 -- cases were already dealt with.
9568 elsif Is_Enumeration_Type (T1) then
9569 Enumeration_Case : declare
9573 L1 := First_Literal (T1);
9574 L2 := First_Literal (T2);
9575 while Present (L1) loop
9576 if Enumeration_Rep (L1) /= Enumeration_Rep (L2) then
9585 end Enumeration_Case;
9587 -- Any other types have the same representation for these purposes
9592 end Same_Representation;
9598 procedure Set_Biased
9602 Biased : Boolean := True)
9606 Set_Has_Biased_Representation (E);
9608 if Warn_On_Biased_Representation then
9610 ("?B?" & Msg & " forces biased representation for&", N, E);
9615 --------------------
9616 -- Set_Enum_Esize --
9617 --------------------
9619 procedure Set_Enum_Esize (T : Entity_Id) is
9627 -- Find the minimum standard size (8,16,32,64) that fits
9629 Lo := Enumeration_Rep (Entity (Type_Low_Bound (T)));
9630 Hi := Enumeration_Rep (Entity (Type_High_Bound (T)));
9633 if Lo >= -Uint_2**07 and then Hi < Uint_2**07 then
9634 Sz := Standard_Character_Size; -- May be > 8 on some targets
9636 elsif Lo >= -Uint_2**15 and then Hi < Uint_2**15 then
9639 elsif Lo >= -Uint_2**31 and then Hi < Uint_2**31 then
9642 else pragma Assert (Lo >= -Uint_2**63 and then Hi < Uint_2**63);
9647 if Hi < Uint_2**08 then
9648 Sz := Standard_Character_Size; -- May be > 8 on some targets
9650 elsif Hi < Uint_2**16 then
9653 elsif Hi < Uint_2**32 then
9656 else pragma Assert (Hi < Uint_2**63);
9661 -- That minimum is the proper size unless we have a foreign convention
9662 -- and the size required is 32 or less, in which case we bump the size
9663 -- up to 32. This is required for C and C++ and seems reasonable for
9664 -- all other foreign conventions.
9666 if Has_Foreign_Convention (T)
9667 and then Esize (T) < Standard_Integer_Size
9669 Init_Esize (T, Standard_Integer_Size);
9675 ------------------------------
9676 -- Validate_Address_Clauses --
9677 ------------------------------
9679 procedure Validate_Address_Clauses is
9681 for J in Address_Clause_Checks.First .. Address_Clause_Checks.Last loop
9683 ACCR : Address_Clause_Check_Record
9684 renames Address_Clause_Checks.Table (J);
9695 -- Skip processing of this entry if warning already posted
9697 if not Address_Warning_Posted (ACCR.N) then
9698 Expr := Original_Node (Expression (ACCR.N));
9702 X_Alignment := Alignment (ACCR.X);
9703 Y_Alignment := Alignment (ACCR.Y);
9705 -- Similarly obtain sizes
9707 X_Size := Esize (ACCR.X);
9708 Y_Size := Esize (ACCR.Y);
9710 -- Check for large object overlaying smaller one
9713 and then X_Size > Uint_0
9714 and then X_Size > Y_Size
9717 ("?& overlays smaller object", ACCR.N, ACCR.X);
9719 ("\??program execution may be erroneous", ACCR.N);
9720 Error_Msg_Uint_1 := X_Size;
9722 ("\??size of & is ^", ACCR.N, ACCR.X);
9723 Error_Msg_Uint_1 := Y_Size;
9725 ("\??size of & is ^", ACCR.N, ACCR.Y);
9727 -- Check for inadequate alignment, both of the base object
9728 -- and of the offset, if any.
9730 -- Note: we do not check the alignment if we gave a size
9731 -- warning, since it would likely be redundant.
9733 elsif Y_Alignment /= Uint_0
9734 and then (Y_Alignment < X_Alignment
9737 Nkind (Expr) = N_Attribute_Reference
9739 Attribute_Name (Expr) = Name_Address
9741 Has_Compatible_Alignment
9742 (ACCR.X, Prefix (Expr))
9743 /= Known_Compatible))
9746 ("??specified address for& may be inconsistent "
9747 & "with alignment", ACCR.N, ACCR.X);
9749 ("\??program execution may be erroneous (RM 13.3(27))",
9751 Error_Msg_Uint_1 := X_Alignment;
9753 ("\??alignment of & is ^", ACCR.N, ACCR.X);
9754 Error_Msg_Uint_1 := Y_Alignment;
9756 ("\??alignment of & is ^", ACCR.N, ACCR.Y);
9757 if Y_Alignment >= X_Alignment then
9759 ("\??but offset is not multiple of alignment", ACCR.N);
9765 end Validate_Address_Clauses;
9767 ---------------------------
9768 -- Validate_Independence --
9769 ---------------------------
9771 procedure Validate_Independence is
9772 SU : constant Uint := UI_From_Int (System_Storage_Unit);
9780 procedure Check_Array_Type (Atyp : Entity_Id);
9781 -- Checks if the array type Atyp has independent components, and
9782 -- if not, outputs an appropriate set of error messages.
9784 procedure No_Independence;
9785 -- Output message that independence cannot be guaranteed
9787 function OK_Component (C : Entity_Id) return Boolean;
9788 -- Checks one component to see if it is independently accessible, and
9789 -- if so yields True, otherwise yields False if independent access
9790 -- cannot be guaranteed. This is a conservative routine, it only
9791 -- returns True if it knows for sure, it returns False if it knows
9792 -- there is a problem, or it cannot be sure there is no problem.
9794 procedure Reason_Bad_Component (C : Entity_Id);
9795 -- Outputs continuation message if a reason can be determined for
9796 -- the component C being bad.
9798 ----------------------
9799 -- Check_Array_Type --
9800 ----------------------
9802 procedure Check_Array_Type (Atyp : Entity_Id) is
9803 Ctyp : constant Entity_Id := Component_Type (Atyp);
9806 -- OK if no alignment clause, no pack, and no component size
9808 if not Has_Component_Size_Clause (Atyp)
9809 and then not Has_Alignment_Clause (Atyp)
9810 and then not Is_Packed (Atyp)
9815 -- Check actual component size
9817 if not Known_Component_Size (Atyp)
9818 or else not (Addressable (Component_Size (Atyp))
9819 and then Component_Size (Atyp) < 64)
9820 or else Component_Size (Atyp) mod Esize (Ctyp) /= 0
9824 -- Bad component size, check reason
9826 if Has_Component_Size_Clause (Atyp) then
9827 P := Get_Attribute_Definition_Clause
9828 (Atyp, Attribute_Component_Size);
9831 Error_Msg_Sloc := Sloc (P);
9832 Error_Msg_N ("\because of Component_Size clause#", N);
9837 if Is_Packed (Atyp) then
9838 P := Get_Rep_Pragma (Atyp, Name_Pack);
9841 Error_Msg_Sloc := Sloc (P);
9842 Error_Msg_N ("\because of pragma Pack#", N);
9847 -- No reason found, just return
9852 -- Array type is OK independence-wise
9855 end Check_Array_Type;
9857 ---------------------
9858 -- No_Independence --
9859 ---------------------
9861 procedure No_Independence is
9863 if Pragma_Name (N) = Name_Independent then
9865 ("independence cannot be guaranteed for&", N, E);
9868 ("independent components cannot be guaranteed for&", N, E);
9870 end No_Independence;
9876 function OK_Component (C : Entity_Id) return Boolean is
9877 Rec : constant Entity_Id := Scope (C);
9878 Ctyp : constant Entity_Id := Etype (C);
9881 -- OK if no component clause, no Pack, and no alignment clause
9883 if No (Component_Clause (C))
9884 and then not Is_Packed (Rec)
9885 and then not Has_Alignment_Clause (Rec)
9890 -- Here we look at the actual component layout. A component is
9891 -- addressable if its size is a multiple of the Esize of the
9892 -- component type, and its starting position in the record has
9893 -- appropriate alignment, and the record itself has appropriate
9894 -- alignment to guarantee the component alignment.
9896 -- Make sure sizes are static, always assume the worst for any
9897 -- cases where we cannot check static values.
9899 if not (Known_Static_Esize (C)
9901 Known_Static_Esize (Ctyp))
9906 -- Size of component must be addressable or greater than 64 bits
9907 -- and a multiple of bytes.
9909 if not Addressable (Esize (C)) and then Esize (C) < Uint_64 then
9913 -- Check size is proper multiple
9915 if Esize (C) mod Esize (Ctyp) /= 0 then
9919 -- Check alignment of component is OK
9921 if not Known_Component_Bit_Offset (C)
9922 or else Component_Bit_Offset (C) < Uint_0
9923 or else Component_Bit_Offset (C) mod Esize (Ctyp) /= 0
9928 -- Check alignment of record type is OK
9930 if not Known_Alignment (Rec)
9931 or else (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0
9936 -- All tests passed, component is addressable
9941 --------------------------
9942 -- Reason_Bad_Component --
9943 --------------------------
9945 procedure Reason_Bad_Component (C : Entity_Id) is
9946 Rec : constant Entity_Id := Scope (C);
9947 Ctyp : constant Entity_Id := Etype (C);
9950 -- If component clause present assume that's the problem
9952 if Present (Component_Clause (C)) then
9953 Error_Msg_Sloc := Sloc (Component_Clause (C));
9954 Error_Msg_N ("\because of Component_Clause#", N);
9958 -- If pragma Pack clause present, assume that's the problem
9960 if Is_Packed (Rec) then
9961 P := Get_Rep_Pragma (Rec, Name_Pack);
9964 Error_Msg_Sloc := Sloc (P);
9965 Error_Msg_N ("\because of pragma Pack#", N);
9970 -- See if record has bad alignment clause
9972 if Has_Alignment_Clause (Rec)
9973 and then Known_Alignment (Rec)
9974 and then (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0
9976 P := Get_Attribute_Definition_Clause (Rec, Attribute_Alignment);
9979 Error_Msg_Sloc := Sloc (P);
9980 Error_Msg_N ("\because of Alignment clause#", N);
9984 -- Couldn't find a reason, so return without a message
9987 end Reason_Bad_Component;
9989 -- Start of processing for Validate_Independence
9992 for J in Independence_Checks.First .. Independence_Checks.Last loop
9993 N := Independence_Checks.Table (J).N;
9994 E := Independence_Checks.Table (J).E;
9995 IC := Pragma_Name (N) = Name_Independent_Components;
9997 -- Deal with component case
9999 if Ekind (E) = E_Discriminant or else Ekind (E) = E_Component then
10000 if not OK_Component (E) then
10002 Reason_Bad_Component (E);
10007 -- Deal with record with Independent_Components
10009 if IC and then Is_Record_Type (E) then
10010 Comp := First_Component_Or_Discriminant (E);
10011 while Present (Comp) loop
10012 if not OK_Component (Comp) then
10014 Reason_Bad_Component (Comp);
10018 Next_Component_Or_Discriminant (Comp);
10022 -- Deal with address clause case
10024 if Is_Object (E) then
10025 Addr := Address_Clause (E);
10027 if Present (Addr) then
10029 Error_Msg_Sloc := Sloc (Addr);
10030 Error_Msg_N ("\because of Address clause#", N);
10035 -- Deal with independent components for array type
10037 if IC and then Is_Array_Type (E) then
10038 Check_Array_Type (E);
10041 -- Deal with independent components for array object
10043 if IC and then Is_Object (E) and then Is_Array_Type (Etype (E)) then
10044 Check_Array_Type (Etype (E));
10049 end Validate_Independence;
10051 -----------------------------------
10052 -- Validate_Unchecked_Conversion --
10053 -----------------------------------
10055 procedure Validate_Unchecked_Conversion
10057 Act_Unit : Entity_Id)
10059 Source : Entity_Id;
10060 Target : Entity_Id;
10064 -- Obtain source and target types. Note that we call Ancestor_Subtype
10065 -- here because the processing for generic instantiation always makes
10066 -- subtypes, and we want the original frozen actual types.
10068 -- If we are dealing with private types, then do the check on their
10069 -- fully declared counterparts if the full declarations have been
10070 -- encountered (they don't have to be visible, but they must exist!)
10072 Source := Ancestor_Subtype (Etype (First_Formal (Act_Unit)));
10074 if Is_Private_Type (Source)
10075 and then Present (Underlying_Type (Source))
10077 Source := Underlying_Type (Source);
10080 Target := Ancestor_Subtype (Etype (Act_Unit));
10082 -- If either type is generic, the instantiation happens within a generic
10083 -- unit, and there is nothing to check. The proper check will happen
10084 -- when the enclosing generic is instantiated.
10086 if Is_Generic_Type (Source) or else Is_Generic_Type (Target) then
10090 if Is_Private_Type (Target)
10091 and then Present (Underlying_Type (Target))
10093 Target := Underlying_Type (Target);
10096 -- Source may be unconstrained array, but not target
10098 if Is_Array_Type (Target) and then not Is_Constrained (Target) then
10100 ("unchecked conversion to unconstrained array not allowed", N);
10104 -- Warn if conversion between two different convention pointers
10106 if Is_Access_Type (Target)
10107 and then Is_Access_Type (Source)
10108 and then Convention (Target) /= Convention (Source)
10109 and then Warn_On_Unchecked_Conversion
10111 -- Give warnings for subprogram pointers only on most targets. The
10112 -- exception is VMS, where data pointers can have different lengths
10113 -- depending on the pointer convention.
10115 if Is_Access_Subprogram_Type (Target)
10116 or else Is_Access_Subprogram_Type (Source)
10117 or else OpenVMS_On_Target
10120 ("?z?conversion between pointers with different conventions!",
10125 -- Warn if one of the operands is Ada.Calendar.Time. Do not emit a
10126 -- warning when compiling GNAT-related sources.
10128 if Warn_On_Unchecked_Conversion
10129 and then not In_Predefined_Unit (N)
10130 and then RTU_Loaded (Ada_Calendar)
10132 (Chars (Source) = Name_Time
10134 Chars (Target) = Name_Time)
10136 -- If Ada.Calendar is loaded and the name of one of the operands is
10137 -- Time, there is a good chance that this is Ada.Calendar.Time.
10140 Calendar_Time : constant Entity_Id :=
10141 Full_View (RTE (RO_CA_Time));
10143 pragma Assert (Present (Calendar_Time));
10145 if Source = Calendar_Time or else Target = Calendar_Time then
10147 ("?z?representation of 'Time values may change between " &
10148 "'G'N'A'T versions", N);
10153 -- Make entry in unchecked conversion table for later processing by
10154 -- Validate_Unchecked_Conversions, which will check sizes and alignments
10155 -- (using values set by the back-end where possible). This is only done
10156 -- if the appropriate warning is active.
10158 if Warn_On_Unchecked_Conversion then
10159 Unchecked_Conversions.Append
10160 (New_Val => UC_Entry'(Eloc => Sloc (N),
10162 Target => Target));
10164 -- If both sizes are known statically now, then back end annotation
10165 -- is not required to do a proper check but if either size is not
10166 -- known statically, then we need the annotation.
10168 if Known_Static_RM_Size (Source)
10170 Known_Static_RM_Size (Target)
10174 Back_Annotate_Rep_Info := True;
10178 -- If unchecked conversion to access type, and access type is declared
10179 -- in the same unit as the unchecked conversion, then set the flag
10180 -- No_Strict_Aliasing (no strict aliasing is implicit here)
10182 if Is_Access_Type (Target) and then
10183 In_Same_Source_Unit (Target, N)
10185 Set_No_Strict_Aliasing (Implementation_Base_Type (Target));
10188 -- Generate N_Validate_Unchecked_Conversion node for back end in case
10189 -- the back end needs to perform special validation checks.
10191 -- Shouldn't this be in Exp_Ch13, since the check only gets done if we
10192 -- have full expansion and the back end is called ???
10195 Make_Validate_Unchecked_Conversion (Sloc (N));
10196 Set_Source_Type (Vnode, Source);
10197 Set_Target_Type (Vnode, Target);
10199 -- If the unchecked conversion node is in a list, just insert before it.
10200 -- If not we have some strange case, not worth bothering about.
10202 if Is_List_Member (N) then
10203 Insert_After (N, Vnode);
10205 end Validate_Unchecked_Conversion;
10207 ------------------------------------
10208 -- Validate_Unchecked_Conversions --
10209 ------------------------------------
10211 procedure Validate_Unchecked_Conversions is
10213 for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop
10215 T : UC_Entry renames Unchecked_Conversions.Table (N);
10217 Eloc : constant Source_Ptr := T.Eloc;
10218 Source : constant Entity_Id := T.Source;
10219 Target : constant Entity_Id := T.Target;
10225 -- This validation check, which warns if we have unequal sizes for
10226 -- unchecked conversion, and thus potentially implementation
10227 -- dependent semantics, is one of the few occasions on which we
10228 -- use the official RM size instead of Esize. See description in
10229 -- Einfo "Handling of Type'Size Values" for details.
10231 if Serious_Errors_Detected = 0
10232 and then Known_Static_RM_Size (Source)
10233 and then Known_Static_RM_Size (Target)
10235 -- Don't do the check if warnings off for either type, note the
10236 -- deliberate use of OR here instead of OR ELSE to get the flag
10237 -- Warnings_Off_Used set for both types if appropriate.
10239 and then not (Has_Warnings_Off (Source)
10241 Has_Warnings_Off (Target))
10243 Source_Siz := RM_Size (Source);
10244 Target_Siz := RM_Size (Target);
10246 if Source_Siz /= Target_Siz then
10248 ("?z?types for unchecked conversion have different sizes!",
10251 if All_Errors_Mode then
10252 Error_Msg_Name_1 := Chars (Source);
10253 Error_Msg_Uint_1 := Source_Siz;
10254 Error_Msg_Name_2 := Chars (Target);
10255 Error_Msg_Uint_2 := Target_Siz;
10256 Error_Msg ("\size of % is ^, size of % is ^?z?", Eloc);
10258 Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz);
10260 if Is_Discrete_Type (Source)
10262 Is_Discrete_Type (Target)
10264 if Source_Siz > Target_Siz then
10266 ("\?z?^ high order bits of source will "
10267 & "be ignored!", Eloc);
10269 elsif Is_Unsigned_Type (Source) then
10271 ("\?z?source will be extended with ^ high order "
10272 & "zero bits?!", Eloc);
10276 ("\?z?source will be extended with ^ high order "
10277 & "sign bits!", Eloc);
10280 elsif Source_Siz < Target_Siz then
10281 if Is_Discrete_Type (Target) then
10282 if Bytes_Big_Endian then
10284 ("\?z?target value will include ^ undefined "
10285 & "low order bits!", Eloc);
10288 ("\?z?target value will include ^ undefined "
10289 & "high order bits!", Eloc);
10294 ("\?z?^ trailing bits of target value will be "
10295 & "undefined!", Eloc);
10298 else pragma Assert (Source_Siz > Target_Siz);
10300 ("\?z?^ trailing bits of source will be ignored!",
10307 -- If both types are access types, we need to check the alignment.
10308 -- If the alignment of both is specified, we can do it here.
10310 if Serious_Errors_Detected = 0
10311 and then Ekind (Source) in Access_Kind
10312 and then Ekind (Target) in Access_Kind
10313 and then Target_Strict_Alignment
10314 and then Present (Designated_Type (Source))
10315 and then Present (Designated_Type (Target))
10318 D_Source : constant Entity_Id := Designated_Type (Source);
10319 D_Target : constant Entity_Id := Designated_Type (Target);
10322 if Known_Alignment (D_Source)
10324 Known_Alignment (D_Target)
10327 Source_Align : constant Uint := Alignment (D_Source);
10328 Target_Align : constant Uint := Alignment (D_Target);
10331 if Source_Align < Target_Align
10332 and then not Is_Tagged_Type (D_Source)
10334 -- Suppress warning if warnings suppressed on either
10335 -- type or either designated type. Note the use of
10336 -- OR here instead of OR ELSE. That is intentional,
10337 -- we would like to set flag Warnings_Off_Used in
10338 -- all types for which warnings are suppressed.
10340 and then not (Has_Warnings_Off (D_Source)
10342 Has_Warnings_Off (D_Target)
10344 Has_Warnings_Off (Source)
10346 Has_Warnings_Off (Target))
10348 Error_Msg_Uint_1 := Target_Align;
10349 Error_Msg_Uint_2 := Source_Align;
10350 Error_Msg_Node_1 := D_Target;
10351 Error_Msg_Node_2 := D_Source;
10353 ("?z?alignment of & (^) is stricter than "
10354 & "alignment of & (^)!", Eloc);
10356 ("\?z?resulting access value may have invalid "
10357 & "alignment!", Eloc);
10365 end Validate_Unchecked_Conversions;