1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2016, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Aspects; use Aspects;
27 with Atree; use Atree;
28 with Checks; use Checks;
29 with Debug; use Debug;
30 with Einfo; use Einfo;
31 with Elists; use Elists;
32 with Errout; use Errout;
33 with Exp_Disp; use Exp_Disp;
34 with Exp_Tss; use Exp_Tss;
35 with Exp_Util; use Exp_Util;
36 with Freeze; use Freeze;
37 with Ghost; use Ghost;
39 with Lib.Xref; use Lib.Xref;
40 with Namet; use Namet;
41 with Nlists; use Nlists;
42 with Nmake; use Nmake;
44 with Restrict; use Restrict;
45 with Rident; use Rident;
46 with Rtsfind; use Rtsfind;
48 with Sem_Aux; use Sem_Aux;
49 with Sem_Case; use Sem_Case;
50 with Sem_Ch3; use Sem_Ch3;
51 with Sem_Ch6; use Sem_Ch6;
52 with Sem_Ch8; use Sem_Ch8;
53 with Sem_Dim; use Sem_Dim;
54 with Sem_Disp; use Sem_Disp;
55 with Sem_Eval; use Sem_Eval;
56 with Sem_Prag; use Sem_Prag;
57 with Sem_Res; use Sem_Res;
58 with Sem_Type; use Sem_Type;
59 with Sem_Util; use Sem_Util;
60 with Sem_Warn; use Sem_Warn;
61 with Sinput; use Sinput;
62 with Snames; use Snames;
63 with Stand; use Stand;
64 with Sinfo; use Sinfo;
65 with Targparm; use Targparm;
66 with Ttypes; use Ttypes;
67 with Tbuild; use Tbuild;
68 with Urealp; use Urealp;
69 with Warnsw; use Warnsw;
71 with GNAT.Heap_Sort_G;
73 package body Sem_Ch13 is
75 SSU : constant Pos := System_Storage_Unit;
76 -- Convenient short hand for commonly used constant
78 -----------------------
79 -- Local Subprograms --
80 -----------------------
82 procedure Alignment_Check_For_Size_Change (Typ : Entity_Id; Size : Uint);
83 -- This routine is called after setting one of the sizes of type entity
84 -- Typ to Size. The purpose is to deal with the situation of a derived
85 -- type whose inherited alignment is no longer appropriate for the new
86 -- size value. In this case, we reset the Alignment to unknown.
88 procedure Build_Discrete_Static_Predicate
92 -- Given a predicated type Typ, where Typ is a discrete static subtype,
93 -- whose predicate expression is Expr, tests if Expr is a static predicate,
94 -- and if so, builds the predicate range list. Nam is the name of the one
95 -- argument to the predicate function. Occurrences of the type name in the
96 -- predicate expression have been replaced by identifier references to this
97 -- name, which is unique, so any identifier with Chars matching Nam must be
98 -- a reference to the type. If the predicate is non-static, this procedure
99 -- returns doing nothing. If the predicate is static, then the predicate
100 -- list is stored in Static_Discrete_Predicate (Typ), and the Expr is
101 -- rewritten as a canonicalized membership operation.
103 function Build_Export_Import_Pragma
105 Id : Entity_Id) return Node_Id;
106 -- Create the corresponding pragma for aspect Export or Import denoted by
107 -- Asp. Id is the related entity subject to the aspect. Return Empty when
108 -- the expression of aspect Asp evaluates to False or is erroneous.
110 function Build_Predicate_Function_Declaration
111 (Typ : Entity_Id) return Node_Id;
112 -- Build the declaration for a predicate function. The declaration is built
113 -- at the end of the declarative part containing the type definition, which
114 -- may be before the freeze point of the type. The predicate expression is
115 -- pre-analyzed at this point, to catch visibility errors.
117 procedure Build_Predicate_Functions (Typ : Entity_Id; N : Node_Id);
118 -- If Typ has predicates (indicated by Has_Predicates being set for Typ),
119 -- then either there are pragma Predicate entries on the rep chain for the
120 -- type (note that Predicate aspects are converted to pragma Predicate), or
121 -- there are inherited aspects from a parent type, or ancestor subtypes.
122 -- This procedure builds body for the Predicate function that tests these
123 -- predicates. N is the freeze node for the type. The spec of the function
124 -- is inserted before the freeze node, and the body of the function is
125 -- inserted after the freeze node. If the predicate expression has a least
126 -- one Raise_Expression, then this procedure also builds the M version of
127 -- the predicate function for use in membership tests.
129 procedure Check_Pool_Size_Clash (Ent : Entity_Id; SP, SS : Node_Id);
130 -- Called if both Storage_Pool and Storage_Size attribute definition
131 -- clauses (SP and SS) are present for entity Ent. Issue error message.
133 procedure Freeze_Entity_Checks (N : Node_Id);
134 -- Called from Analyze_Freeze_Entity and Analyze_Generic_Freeze Entity
135 -- to generate appropriate semantic checks that are delayed until this
136 -- point (they had to be delayed this long for cases of delayed aspects,
137 -- e.g. analysis of statically predicated subtypes in choices, for which
138 -- we have to be sure the subtypes in question are frozen before checking).
140 function Get_Alignment_Value (Expr : Node_Id) return Uint;
141 -- Given the expression for an alignment value, returns the corresponding
142 -- Uint value. If the value is inappropriate, then error messages are
143 -- posted as required, and a value of No_Uint is returned.
145 procedure Get_Interfacing_Aspects
146 (Iface_Asp : Node_Id;
147 Conv_Asp : out Node_Id;
148 EN_Asp : out Node_Id;
149 Expo_Asp : out Node_Id;
150 Imp_Asp : out Node_Id;
151 LN_Asp : out Node_Id;
152 Do_Checks : Boolean := False);
153 -- Given a single interfacing aspect Iface_Asp, retrieve other interfacing
154 -- aspects that apply to the same related entity. The aspects considered by
155 -- this routine are as follows:
157 -- Conv_Asp - aspect Convention
158 -- EN_Asp - aspect External_Name
159 -- Expo_Asp - aspect Export
160 -- Imp_Asp - aspect Import
161 -- LN_Asp - aspect Link_Name
163 -- When flag Do_Checks is set, this routine will flag duplicate uses of
166 function Is_Operational_Item (N : Node_Id) return Boolean;
167 -- A specification for a stream attribute is allowed before the full type
168 -- is declared, as explained in AI-00137 and the corrigendum. Attributes
169 -- that do not specify a representation characteristic are operational
172 function Is_Predicate_Static
174 Nam : Name_Id) return Boolean;
175 -- Given predicate expression Expr, tests if Expr is predicate-static in
176 -- the sense of the rules in (RM 3.2.4 (15-24)). Occurrences of the type
177 -- name in the predicate expression have been replaced by references to
178 -- an identifier whose Chars field is Nam. This name is unique, so any
179 -- identifier with Chars matching Nam must be a reference to the type.
180 -- Returns True if the expression is predicate-static and False otherwise,
181 -- but is not in the business of setting flags or issuing error messages.
183 -- Only scalar types can have static predicates, so False is always
184 -- returned for non-scalar types.
186 -- Note: the RM seems to suggest that string types can also have static
187 -- predicates. But that really makes lttle sense as very few useful
188 -- predicates can be constructed for strings. Remember that:
192 -- is not a static expression. So even though the clearly faulty RM wording
193 -- allows the following:
195 -- subtype S is String with Static_Predicate => S < "DEF"
197 -- We can't allow this, otherwise we have predicate-static applying to a
198 -- larger class than static expressions, which was never intended.
200 procedure New_Stream_Subprogram
204 Nam : TSS_Name_Type);
205 -- Create a subprogram renaming of a given stream attribute to the
206 -- designated subprogram and then in the tagged case, provide this as a
207 -- primitive operation, or in the untagged case make an appropriate TSS
208 -- entry. This is more properly an expansion activity than just semantics,
209 -- but the presence of user-defined stream functions for limited types
210 -- is a legality check, which is why this takes place here rather than in
211 -- exp_ch13, where it was previously. Nam indicates the name of the TSS
212 -- function to be generated.
214 -- To avoid elaboration anomalies with freeze nodes, for untagged types
215 -- we generate both a subprogram declaration and a subprogram renaming
216 -- declaration, so that the attribute specification is handled as a
217 -- renaming_as_body. For tagged types, the specification is one of the
220 procedure Resolve_Iterable_Operation
225 -- If the name of a primitive operation for an Iterable aspect is
226 -- overloaded, resolve according to required signature.
232 Biased : Boolean := True);
233 -- If Biased is True, sets Has_Biased_Representation flag for E, and
234 -- outputs a warning message at node N if Warn_On_Biased_Representation is
235 -- is True. This warning inserts the string Msg to describe the construct
238 ----------------------------------------------
239 -- Table for Validate_Unchecked_Conversions --
240 ----------------------------------------------
242 -- The following table collects unchecked conversions for validation.
243 -- Entries are made by Validate_Unchecked_Conversion and then the call
244 -- to Validate_Unchecked_Conversions does the actual error checking and
245 -- posting of warnings. The reason for this delayed processing is to take
246 -- advantage of back-annotations of size and alignment values performed by
249 -- Note: the reason we store a Source_Ptr value instead of a Node_Id is
250 -- that by the time Validate_Unchecked_Conversions is called, Sprint will
251 -- already have modified all Sloc values if the -gnatD option is set.
253 type UC_Entry is record
254 Eloc : Source_Ptr; -- node used for posting warnings
255 Source : Entity_Id; -- source type for unchecked conversion
256 Target : Entity_Id; -- target type for unchecked conversion
257 Act_Unit : Entity_Id; -- actual function instantiated
260 package Unchecked_Conversions is new Table.Table (
261 Table_Component_Type => UC_Entry,
262 Table_Index_Type => Int,
263 Table_Low_Bound => 1,
265 Table_Increment => 200,
266 Table_Name => "Unchecked_Conversions");
268 ----------------------------------------
269 -- Table for Validate_Address_Clauses --
270 ----------------------------------------
272 -- If an address clause has the form
274 -- for X'Address use Expr
276 -- where Expr is of the form Y'Address or recursively is a reference to a
277 -- constant of either of these forms, and X and Y are entities of objects,
278 -- then if Y has a smaller alignment than X, that merits a warning about
279 -- possible bad alignment. The following table collects address clauses of
280 -- this kind. We put these in a table so that they can be checked after the
281 -- back end has completed annotation of the alignments of objects, since we
282 -- can catch more cases that way.
284 type Address_Clause_Check_Record is record
286 -- The address clause
289 -- The entity of the object overlaying Y
292 -- The entity of the object being overlaid
295 -- Whether the address is offset within Y
298 package Address_Clause_Checks is new Table.Table (
299 Table_Component_Type => Address_Clause_Check_Record,
300 Table_Index_Type => Int,
301 Table_Low_Bound => 1,
303 Table_Increment => 200,
304 Table_Name => "Address_Clause_Checks");
306 -----------------------------------------
307 -- Adjust_Record_For_Reverse_Bit_Order --
308 -----------------------------------------
310 procedure Adjust_Record_For_Reverse_Bit_Order (R : Entity_Id) is
315 -- Processing depends on version of Ada
317 -- For Ada 95, we just renumber bits within a storage unit. We do the
318 -- same for Ada 83 mode, since we recognize the Bit_Order attribute in
319 -- Ada 83, and are free to add this extension.
321 if Ada_Version < Ada_2005 then
322 Comp := First_Component_Or_Discriminant (R);
323 while Present (Comp) loop
324 CC := Component_Clause (Comp);
326 -- If component clause is present, then deal with the non-default
327 -- bit order case for Ada 95 mode.
329 -- We only do this processing for the base type, and in fact that
330 -- is important, since otherwise if there are record subtypes, we
331 -- could reverse the bits once for each subtype, which is wrong.
333 if Present (CC) and then Ekind (R) = E_Record_Type then
335 CFB : constant Uint := Component_Bit_Offset (Comp);
336 CSZ : constant Uint := Esize (Comp);
337 CLC : constant Node_Id := Component_Clause (Comp);
338 Pos : constant Node_Id := Position (CLC);
339 FB : constant Node_Id := First_Bit (CLC);
341 Storage_Unit_Offset : constant Uint :=
342 CFB / System_Storage_Unit;
344 Start_Bit : constant Uint :=
345 CFB mod System_Storage_Unit;
348 -- Cases where field goes over storage unit boundary
350 if Start_Bit + CSZ > System_Storage_Unit then
352 -- Allow multi-byte field but generate warning
354 if Start_Bit mod System_Storage_Unit = 0
355 and then CSZ mod System_Storage_Unit = 0
358 ("info: multi-byte field specified with "
359 & "non-standard Bit_Order?V?", CLC);
361 if Bytes_Big_Endian then
363 ("\bytes are not reversed "
364 & "(component is big-endian)?V?", CLC);
367 ("\bytes are not reversed "
368 & "(component is little-endian)?V?", CLC);
371 -- Do not allow non-contiguous field
375 ("attempt to specify non-contiguous field "
376 & "not permitted", CLC);
378 ("\caused by non-standard Bit_Order "
381 ("\consider possibility of using "
382 & "Ada 2005 mode here", CLC);
385 -- Case where field fits in one storage unit
388 -- Give warning if suspicious component clause
390 if Intval (FB) >= System_Storage_Unit
391 and then Warn_On_Reverse_Bit_Order
394 ("info: Bit_Order clause does not affect " &
395 "byte ordering?V?", Pos);
397 Intval (Pos) + Intval (FB) /
400 ("info: position normalized to ^ before bit " &
401 "order interpreted?V?", Pos);
404 -- Here is where we fix up the Component_Bit_Offset value
405 -- to account for the reverse bit order. Some examples of
406 -- what needs to be done are:
408 -- First_Bit .. Last_Bit Component_Bit_Offset
420 -- The rule is that the first bit is is obtained by
421 -- subtracting the old ending bit from storage_unit - 1.
423 Set_Component_Bit_Offset
425 (Storage_Unit_Offset * System_Storage_Unit) +
426 (System_Storage_Unit - 1) -
427 (Start_Bit + CSZ - 1));
429 Set_Normalized_First_Bit
431 Component_Bit_Offset (Comp) mod
432 System_Storage_Unit);
437 Next_Component_Or_Discriminant (Comp);
440 -- For Ada 2005, we do machine scalar processing, as fully described In
441 -- AI-133. This involves gathering all components which start at the
442 -- same byte offset and processing them together. Same approach is still
443 -- valid in later versions including Ada 2012.
447 Max_Machine_Scalar_Size : constant Uint :=
449 (Standard_Long_Long_Integer_Size);
450 -- We use this as the maximum machine scalar size
453 SSU : constant Uint := UI_From_Int (System_Storage_Unit);
456 -- This first loop through components does two things. First it
457 -- deals with the case of components with component clauses whose
458 -- length is greater than the maximum machine scalar size (either
459 -- accepting them or rejecting as needed). Second, it counts the
460 -- number of components with component clauses whose length does
461 -- not exceed this maximum for later processing.
464 Comp := First_Component_Or_Discriminant (R);
465 while Present (Comp) loop
466 CC := Component_Clause (Comp);
470 Fbit : constant Uint := Static_Integer (First_Bit (CC));
471 Lbit : constant Uint := Static_Integer (Last_Bit (CC));
474 -- Case of component with last bit >= max machine scalar
476 if Lbit >= Max_Machine_Scalar_Size then
478 -- This is allowed only if first bit is zero, and
479 -- last bit + 1 is a multiple of storage unit size.
481 if Fbit = 0 and then (Lbit + 1) mod SSU = 0 then
483 -- This is the case to give a warning if enabled
485 if Warn_On_Reverse_Bit_Order then
487 ("info: multi-byte field specified with "
488 & "non-standard Bit_Order?V?", CC);
490 if Bytes_Big_Endian then
492 ("\bytes are not reversed "
493 & "(component is big-endian)?V?", CC);
496 ("\bytes are not reversed "
497 & "(component is little-endian)?V?", CC);
501 -- Give error message for RM 13.5.1(10) violation
505 ("machine scalar rules not followed for&",
506 First_Bit (CC), Comp);
508 Error_Msg_Uint_1 := Lbit + 1;
509 Error_Msg_Uint_2 := Max_Machine_Scalar_Size;
511 ("\last bit + 1 (^) exceeds maximum machine "
515 if (Lbit + 1) mod SSU /= 0 then
516 Error_Msg_Uint_1 := SSU;
518 ("\and is not a multiple of Storage_Unit (^) "
523 Error_Msg_Uint_1 := Fbit;
525 ("\and first bit (^) is non-zero "
531 -- OK case of machine scalar related component clause,
532 -- For now, just count them.
535 Num_CC := Num_CC + 1;
540 Next_Component_Or_Discriminant (Comp);
543 -- We need to sort the component clauses on the basis of the
544 -- Position values in the clause, so we can group clauses with
545 -- the same Position together to determine the relevant machine
549 Comps : array (0 .. Num_CC) of Entity_Id;
550 -- Array to collect component and discriminant entities. The
551 -- data starts at index 1, the 0'th entry is for the sort
554 function CP_Lt (Op1, Op2 : Natural) return Boolean;
555 -- Compare routine for Sort
557 procedure CP_Move (From : Natural; To : Natural);
558 -- Move routine for Sort
560 package Sorting is new GNAT.Heap_Sort_G (CP_Move, CP_Lt);
564 -- Start and stop positions in the component list of the set of
565 -- components with the same starting position (that constitute
566 -- components in a single machine scalar).
569 -- Maximum last bit value of any component in this set
572 -- Corresponding machine scalar size
578 function CP_Lt (Op1, Op2 : Natural) return Boolean is
580 return Position (Component_Clause (Comps (Op1))) <
581 Position (Component_Clause (Comps (Op2)));
588 procedure CP_Move (From : Natural; To : Natural) is
590 Comps (To) := Comps (From);
593 -- Start of processing for Sort_CC
596 -- Collect the machine scalar relevant component clauses
599 Comp := First_Component_Or_Discriminant (R);
600 while Present (Comp) loop
602 CC : constant Node_Id := Component_Clause (Comp);
605 -- Collect only component clauses whose last bit is less
606 -- than machine scalar size. Any component clause whose
607 -- last bit exceeds this value does not take part in
608 -- machine scalar layout considerations. The test for
609 -- Error_Posted makes sure we exclude component clauses
610 -- for which we already posted an error.
613 and then not Error_Posted (Last_Bit (CC))
614 and then Static_Integer (Last_Bit (CC)) <
615 Max_Machine_Scalar_Size
617 Num_CC := Num_CC + 1;
618 Comps (Num_CC) := Comp;
622 Next_Component_Or_Discriminant (Comp);
625 -- Sort by ascending position number
627 Sorting.Sort (Num_CC);
629 -- We now have all the components whose size does not exceed
630 -- the max machine scalar value, sorted by starting position.
631 -- In this loop we gather groups of clauses starting at the
632 -- same position, to process them in accordance with AI-133.
635 while Stop < Num_CC loop
640 (Last_Bit (Component_Clause (Comps (Start))));
641 while Stop < Num_CC loop
643 (Position (Component_Clause (Comps (Stop + 1)))) =
645 (Position (Component_Clause (Comps (Stop))))
653 (Component_Clause (Comps (Stop)))));
659 -- Now we have a group of component clauses from Start to
660 -- Stop whose positions are identical, and MaxL is the
661 -- maximum last bit value of any of these components.
663 -- We need to determine the corresponding machine scalar
664 -- size. This loop assumes that machine scalar sizes are
665 -- even, and that each possible machine scalar has twice
666 -- as many bits as the next smaller one.
668 MSS := Max_Machine_Scalar_Size;
670 and then (MSS / 2) >= SSU
671 and then (MSS / 2) > MaxL
676 -- Here is where we fix up the Component_Bit_Offset value
677 -- to account for the reverse bit order. Some examples of
678 -- what needs to be done for the case of a machine scalar
681 -- First_Bit .. Last_Bit Component_Bit_Offset
693 -- The rule is that the first bit is obtained by subtracting
694 -- the old ending bit from machine scalar size - 1.
696 for C in Start .. Stop loop
698 Comp : constant Entity_Id := Comps (C);
699 CC : constant Node_Id := Component_Clause (Comp);
701 LB : constant Uint := Static_Integer (Last_Bit (CC));
702 NFB : constant Uint := MSS - Uint_1 - LB;
703 NLB : constant Uint := NFB + Esize (Comp) - 1;
704 Pos : constant Uint := Static_Integer (Position (CC));
707 if Warn_On_Reverse_Bit_Order then
708 Error_Msg_Uint_1 := MSS;
710 ("info: reverse bit order in machine " &
711 "scalar of length^?V?", First_Bit (CC));
712 Error_Msg_Uint_1 := NFB;
713 Error_Msg_Uint_2 := NLB;
715 if Bytes_Big_Endian then
717 ("\big-endian range for component "
718 & "& is ^ .. ^?V?", First_Bit (CC), Comp);
721 ("\little-endian range for component"
722 & "& is ^ .. ^?V?", First_Bit (CC), Comp);
726 Set_Component_Bit_Offset (Comp, Pos * SSU + NFB);
727 Set_Normalized_First_Bit (Comp, NFB mod SSU);
734 end Adjust_Record_For_Reverse_Bit_Order;
736 -------------------------------------
737 -- Alignment_Check_For_Size_Change --
738 -------------------------------------
740 procedure Alignment_Check_For_Size_Change (Typ : Entity_Id; Size : Uint) is
742 -- If the alignment is known, and not set by a rep clause, and is
743 -- inconsistent with the size being set, then reset it to unknown,
744 -- we assume in this case that the size overrides the inherited
745 -- alignment, and that the alignment must be recomputed.
747 if Known_Alignment (Typ)
748 and then not Has_Alignment_Clause (Typ)
749 and then Size mod (Alignment (Typ) * SSU) /= 0
751 Init_Alignment (Typ);
753 end Alignment_Check_For_Size_Change;
755 -------------------------------------
756 -- Analyze_Aspects_At_Freeze_Point --
757 -------------------------------------
759 procedure Analyze_Aspects_At_Freeze_Point (E : Entity_Id) is
760 procedure Analyze_Aspect_Default_Value (ASN : Node_Id);
761 -- This routine analyzes an Aspect_Default_[Component_]Value denoted by
762 -- the aspect specification node ASN.
764 procedure Inherit_Delayed_Rep_Aspects (ASN : Node_Id);
765 -- As discussed in the spec of Aspects (see Aspect_Delay declaration),
766 -- a derived type can inherit aspects from its parent which have been
767 -- specified at the time of the derivation using an aspect, as in:
769 -- type A is range 1 .. 10
770 -- with Size => Not_Defined_Yet;
774 -- Not_Defined_Yet : constant := 64;
776 -- In this example, the Size of A is considered to be specified prior
777 -- to the derivation, and thus inherited, even though the value is not
778 -- known at the time of derivation. To deal with this, we use two entity
779 -- flags. The flag Has_Derived_Rep_Aspects is set in the parent type (A
780 -- here), and then the flag May_Inherit_Delayed_Rep_Aspects is set in
781 -- the derived type (B here). If this flag is set when the derived type
782 -- is frozen, then this procedure is called to ensure proper inheritance
783 -- of all delayed aspects from the parent type. The derived type is E,
784 -- the argument to Analyze_Aspects_At_Freeze_Point. ASN is the first
785 -- aspect specification node in the Rep_Item chain for the parent type.
787 procedure Make_Pragma_From_Boolean_Aspect (ASN : Node_Id);
788 -- Given an aspect specification node ASN whose expression is an
789 -- optional Boolean, this routines creates the corresponding pragma
790 -- at the freezing point.
792 ----------------------------------
793 -- Analyze_Aspect_Default_Value --
794 ----------------------------------
796 procedure Analyze_Aspect_Default_Value (ASN : Node_Id) is
797 A_Id : constant Aspect_Id := Get_Aspect_Id (ASN);
798 Ent : constant Entity_Id := Entity (ASN);
799 Expr : constant Node_Id := Expression (ASN);
800 Id : constant Node_Id := Identifier (ASN);
803 Error_Msg_Name_1 := Chars (Id);
805 if not Is_Type (Ent) then
806 Error_Msg_N ("aspect% can only apply to a type", Id);
809 elsif not Is_First_Subtype (Ent) then
810 Error_Msg_N ("aspect% cannot apply to subtype", Id);
813 elsif A_Id = Aspect_Default_Value
814 and then not Is_Scalar_Type (Ent)
816 Error_Msg_N ("aspect% can only be applied to scalar type", Id);
819 elsif A_Id = Aspect_Default_Component_Value then
820 if not Is_Array_Type (Ent) then
821 Error_Msg_N ("aspect% can only be applied to array type", Id);
824 elsif not Is_Scalar_Type (Component_Type (Ent)) then
825 Error_Msg_N ("aspect% requires scalar components", Id);
830 Set_Has_Default_Aspect (Base_Type (Ent));
832 if Is_Scalar_Type (Ent) then
833 Set_Default_Aspect_Value (Base_Type (Ent), Expr);
835 Set_Default_Aspect_Component_Value (Base_Type (Ent), Expr);
837 end Analyze_Aspect_Default_Value;
839 ---------------------------------
840 -- Inherit_Delayed_Rep_Aspects --
841 ---------------------------------
843 procedure Inherit_Delayed_Rep_Aspects (ASN : Node_Id) is
844 A_Id : constant Aspect_Id := Get_Aspect_Id (ASN);
845 P : constant Entity_Id := Entity (ASN);
846 -- Entithy for parent type
849 -- Item from Rep_Item chain
854 -- Loop through delayed aspects for the parent type
857 while Present (N) loop
858 if Nkind (N) = N_Aspect_Specification then
859 exit when Entity (N) /= P;
861 if Is_Delayed_Aspect (N) then
862 A := Get_Aspect_Id (Chars (Identifier (N)));
864 -- Process delayed rep aspect. For Boolean attributes it is
865 -- not possible to cancel an attribute once set (the attempt
866 -- to use an aspect with xxx => False is an error) for a
867 -- derived type. So for those cases, we do not have to check
868 -- if a clause has been given for the derived type, since it
869 -- is harmless to set it again if it is already set.
875 when Aspect_Alignment =>
876 if not Has_Alignment_Clause (E) then
877 Set_Alignment (E, Alignment (P));
882 when Aspect_Atomic =>
883 if Is_Atomic (P) then
889 when Aspect_Atomic_Components =>
890 if Has_Atomic_Components (P) then
891 Set_Has_Atomic_Components (Base_Type (E));
896 when Aspect_Bit_Order =>
897 if Is_Record_Type (E)
898 and then No (Get_Attribute_Definition_Clause
899 (E, Attribute_Bit_Order))
900 and then Reverse_Bit_Order (P)
902 Set_Reverse_Bit_Order (Base_Type (E));
907 when Aspect_Component_Size =>
909 and then not Has_Component_Size_Clause (E)
912 (Base_Type (E), Component_Size (P));
917 when Aspect_Machine_Radix =>
918 if Is_Decimal_Fixed_Point_Type (E)
919 and then not Has_Machine_Radix_Clause (E)
921 Set_Machine_Radix_10 (E, Machine_Radix_10 (P));
924 -- Object_Size (also Size which also sets Object_Size)
926 when Aspect_Object_Size | Aspect_Size =>
927 if not Has_Size_Clause (E)
929 No (Get_Attribute_Definition_Clause
930 (E, Attribute_Object_Size))
932 Set_Esize (E, Esize (P));
938 if not Is_Packed (E) then
939 Set_Is_Packed (Base_Type (E));
941 if Is_Bit_Packed_Array (P) then
942 Set_Is_Bit_Packed_Array (Base_Type (E));
943 Set_Packed_Array_Impl_Type
944 (E, Packed_Array_Impl_Type (P));
948 -- Scalar_Storage_Order
950 when Aspect_Scalar_Storage_Order =>
951 if (Is_Record_Type (E) or else Is_Array_Type (E))
952 and then No (Get_Attribute_Definition_Clause
953 (E, Attribute_Scalar_Storage_Order))
954 and then Reverse_Storage_Order (P)
956 Set_Reverse_Storage_Order (Base_Type (E));
958 -- Clear default SSO indications, since the aspect
959 -- overrides the default.
961 Set_SSO_Set_Low_By_Default (Base_Type (E), False);
962 Set_SSO_Set_High_By_Default (Base_Type (E), False);
968 if Is_Fixed_Point_Type (E)
969 and then not Has_Small_Clause (E)
971 Set_Small_Value (E, Small_Value (P));
976 when Aspect_Storage_Size =>
977 if (Is_Access_Type (E) or else Is_Task_Type (E))
978 and then not Has_Storage_Size_Clause (E)
980 Set_Storage_Size_Variable
981 (Base_Type (E), Storage_Size_Variable (P));
986 when Aspect_Value_Size =>
988 -- Value_Size is never inherited, it is either set by
989 -- default, or it is explicitly set for the derived
990 -- type. So nothing to do here.
996 when Aspect_Volatile =>
997 if Is_Volatile (P) then
1001 -- Volatile_Full_Access
1003 when Aspect_Volatile_Full_Access =>
1004 if Is_Volatile_Full_Access (P) then
1005 Set_Is_Volatile_Full_Access (E);
1008 -- Volatile_Components
1010 when Aspect_Volatile_Components =>
1011 if Has_Volatile_Components (P) then
1012 Set_Has_Volatile_Components (Base_Type (E));
1015 -- That should be all the Rep Aspects
1018 pragma Assert (Aspect_Delay (A_Id) /= Rep_Aspect);
1025 N := Next_Rep_Item (N);
1027 end Inherit_Delayed_Rep_Aspects;
1029 -------------------------------------
1030 -- Make_Pragma_From_Boolean_Aspect --
1031 -------------------------------------
1033 procedure Make_Pragma_From_Boolean_Aspect (ASN : Node_Id) is
1034 Ident : constant Node_Id := Identifier (ASN);
1035 A_Name : constant Name_Id := Chars (Ident);
1036 A_Id : constant Aspect_Id := Get_Aspect_Id (A_Name);
1037 Ent : constant Entity_Id := Entity (ASN);
1038 Expr : constant Node_Id := Expression (ASN);
1039 Loc : constant Source_Ptr := Sloc (ASN);
1041 procedure Check_False_Aspect_For_Derived_Type;
1042 -- This procedure checks for the case of a false aspect for a derived
1043 -- type, which improperly tries to cancel an aspect inherited from
1046 -----------------------------------------
1047 -- Check_False_Aspect_For_Derived_Type --
1048 -----------------------------------------
1050 procedure Check_False_Aspect_For_Derived_Type is
1054 -- We are only checking derived types
1056 if not Is_Derived_Type (E) then
1060 Par := Nearest_Ancestor (E);
1063 when Aspect_Atomic | Aspect_Shared =>
1064 if not Is_Atomic (Par) then
1068 when Aspect_Atomic_Components =>
1069 if not Has_Atomic_Components (Par) then
1073 when Aspect_Discard_Names =>
1074 if not Discard_Names (Par) then
1079 if not Is_Packed (Par) then
1083 when Aspect_Unchecked_Union =>
1084 if not Is_Unchecked_Union (Par) then
1088 when Aspect_Volatile =>
1089 if not Is_Volatile (Par) then
1093 when Aspect_Volatile_Components =>
1094 if not Has_Volatile_Components (Par) then
1098 when Aspect_Volatile_Full_Access =>
1099 if not Is_Volatile_Full_Access (Par) then
1107 -- Fall through means we are canceling an inherited aspect
1109 Error_Msg_Name_1 := A_Name;
1111 ("derived type& inherits aspect%, cannot cancel", Expr, E);
1112 end Check_False_Aspect_For_Derived_Type;
1118 -- Start of processing for Make_Pragma_From_Boolean_Aspect
1121 -- Note that we know Expr is present, because for a missing Expr
1122 -- argument, we knew it was True and did not need to delay the
1123 -- evaluation to the freeze point.
1125 if Is_False (Static_Boolean (Expr)) then
1126 Check_False_Aspect_For_Derived_Type;
1131 Pragma_Identifier =>
1132 Make_Identifier (Sloc (Ident), Chars (Ident)),
1133 Pragma_Argument_Associations => New_List (
1134 Make_Pragma_Argument_Association (Sloc (Ident),
1135 Expression => New_Occurrence_Of (Ent, Sloc (Ident)))));
1137 Set_From_Aspect_Specification (Prag, True);
1138 Set_Corresponding_Aspect (Prag, ASN);
1139 Set_Aspect_Rep_Item (ASN, Prag);
1140 Set_Is_Delayed_Aspect (Prag);
1141 Set_Parent (Prag, ASN);
1143 end Make_Pragma_From_Boolean_Aspect;
1151 -- Start of processing for Analyze_Aspects_At_Freeze_Point
1154 -- Must be visible in current scope
1156 if not Scope_Within_Or_Same (Current_Scope, Scope (E)) then
1160 -- Look for aspect specification entries for this entity
1162 ASN := First_Rep_Item (E);
1163 while Present (ASN) loop
1164 if Nkind (ASN) = N_Aspect_Specification then
1165 exit when Entity (ASN) /= E;
1167 if Is_Delayed_Aspect (ASN) then
1168 A_Id := Get_Aspect_Id (ASN);
1172 -- For aspects whose expression is an optional Boolean, make
1173 -- the corresponding pragma at the freeze point.
1175 when Boolean_Aspects |
1176 Library_Unit_Aspects =>
1178 -- Aspects Export and Import require special handling.
1179 -- Both are by definition Boolean and may benefit from
1180 -- forward references, however their expressions are
1181 -- treated as static. In addition, the syntax of their
1182 -- corresponding pragmas requires extra "pieces" which
1183 -- may also contain forward references. To account for
1184 -- all of this, the corresponding pragma is created by
1185 -- Analyze_Aspect_Export_Import, but is not analyzed as
1186 -- the complete analysis must happen now.
1188 if A_Id = Aspect_Export or else A_Id = Aspect_Import then
1191 -- Otherwise create a corresponding pragma
1194 Make_Pragma_From_Boolean_Aspect (ASN);
1197 -- Special handling for aspects that don't correspond to
1198 -- pragmas/attributes.
1200 when Aspect_Default_Value |
1201 Aspect_Default_Component_Value =>
1203 -- Do not inherit aspect for anonymous base type of a
1204 -- scalar or array type, because they apply to the first
1205 -- subtype of the type, and will be processed when that
1206 -- first subtype is frozen.
1208 if Is_Derived_Type (E)
1209 and then not Comes_From_Source (E)
1210 and then E /= First_Subtype (E)
1214 Analyze_Aspect_Default_Value (ASN);
1217 -- Ditto for iterator aspects, because the corresponding
1218 -- attributes may not have been analyzed yet.
1220 when Aspect_Constant_Indexing |
1221 Aspect_Variable_Indexing |
1222 Aspect_Default_Iterator |
1223 Aspect_Iterator_Element =>
1224 Analyze (Expression (ASN));
1226 if Etype (Expression (ASN)) = Any_Type then
1228 ("\aspect must be fully defined before & is frozen",
1232 when Aspect_Iterable =>
1233 Validate_Iterable_Aspect (E, ASN);
1239 Ritem := Aspect_Rep_Item (ASN);
1241 if Present (Ritem) then
1247 Next_Rep_Item (ASN);
1250 -- This is where we inherit delayed rep aspects from our parent. Note
1251 -- that if we fell out of the above loop with ASN non-empty, it means
1252 -- we hit an aspect for an entity other than E, and it must be the
1253 -- type from which we were derived.
1255 if May_Inherit_Delayed_Rep_Aspects (E) then
1256 Inherit_Delayed_Rep_Aspects (ASN);
1258 end Analyze_Aspects_At_Freeze_Point;
1260 -----------------------------------
1261 -- Analyze_Aspect_Specifications --
1262 -----------------------------------
1264 procedure Analyze_Aspect_Specifications (N : Node_Id; E : Entity_Id) is
1265 procedure Decorate (Asp : Node_Id; Prag : Node_Id);
1266 -- Establish linkages between an aspect and its corresponding pragma
1268 procedure Insert_Pragma
1270 Is_Instance : Boolean := False);
1271 -- Subsidiary to the analysis of aspects
1278 -- Initial_Condition
1287 -- Insert pragma Prag such that it mimics the placement of a source
1288 -- pragma of the same kind. Flag Is_Generic should be set when the
1289 -- context denotes a generic instance.
1295 procedure Decorate (Asp : Node_Id; Prag : Node_Id) is
1297 Set_Aspect_Rep_Item (Asp, Prag);
1298 Set_Corresponding_Aspect (Prag, Asp);
1299 Set_From_Aspect_Specification (Prag);
1300 Set_Parent (Prag, Asp);
1307 procedure Insert_Pragma
1309 Is_Instance : Boolean := False)
1315 Inserted : Boolean := False;
1318 -- When the aspect appears on an entry, package, protected unit,
1319 -- subprogram, or task unit body, insert the generated pragma at the
1320 -- top of the body declarations to emulate the behavior of a source
1323 -- package body Pack with Aspect is
1325 -- package body Pack is
1328 if Nkind_In (N, N_Entry_Body,
1334 Decls := Declarations (N);
1338 Set_Declarations (N, Decls);
1341 Prepend_To (Decls, Prag);
1343 -- When the aspect is associated with a [generic] package declaration
1344 -- insert the generated pragma at the top of the visible declarations
1345 -- to emulate the behavior of a source pragma.
1347 -- package Pack with Aspect is
1352 elsif Nkind_In (N, N_Generic_Package_Declaration,
1353 N_Package_Declaration)
1355 Decls := Visible_Declarations (Specification (N));
1359 Set_Visible_Declarations (Specification (N), Decls);
1362 -- The visible declarations of a generic instance have the
1363 -- following structure:
1365 -- <renamings of generic formals>
1366 -- <renamings of internally-generated spec and body>
1367 -- <first source declaration>
1369 -- Insert the pragma before the first source declaration by
1370 -- skipping the instance "header" to ensure proper visibility of
1374 Decl := First (Decls);
1375 while Present (Decl) loop
1376 if Comes_From_Source (Decl) then
1377 Insert_Before (Decl, Prag);
1385 -- The pragma is placed after the instance "header"
1387 if not Inserted then
1388 Append_To (Decls, Prag);
1391 -- Otherwise this is not a generic instance
1394 Prepend_To (Decls, Prag);
1397 -- When the aspect is associated with a protected unit declaration,
1398 -- insert the generated pragma at the top of the visible declarations
1399 -- the emulate the behavior of a source pragma.
1401 -- protected [type] Prot with Aspect is
1403 -- protected [type] Prot is
1406 elsif Nkind (N) = N_Protected_Type_Declaration then
1407 Def := Protected_Definition (N);
1411 Make_Protected_Definition (Sloc (N),
1412 Visible_Declarations => New_List,
1413 End_Label => Empty);
1415 Set_Protected_Definition (N, Def);
1418 Decls := Visible_Declarations (Def);
1422 Set_Visible_Declarations (Def, Decls);
1425 Prepend_To (Decls, Prag);
1427 -- When the aspect is associated with a task unit declaration, insert
1428 -- insert the generated pragma at the top of the visible declarations
1429 -- the emulate the behavior of a source pragma.
1431 -- task [type] Prot with Aspect is
1433 -- task [type] Prot is
1436 elsif Nkind (N) = N_Task_Type_Declaration then
1437 Def := Task_Definition (N);
1441 Make_Task_Definition (Sloc (N),
1442 Visible_Declarations => New_List,
1443 End_Label => Empty);
1445 Set_Task_Definition (N, Def);
1448 Decls := Visible_Declarations (Def);
1452 Set_Visible_Declarations (Def, Decls);
1455 Prepend_To (Decls, Prag);
1457 -- When the context is a library unit, the pragma is added to the
1458 -- Pragmas_After list.
1460 elsif Nkind (Parent (N)) = N_Compilation_Unit then
1461 Aux := Aux_Decls_Node (Parent (N));
1463 if No (Pragmas_After (Aux)) then
1464 Set_Pragmas_After (Aux, New_List);
1467 Prepend (Prag, Pragmas_After (Aux));
1469 -- Default, the pragma is inserted after the context
1472 Insert_After (N, Prag);
1482 L : constant List_Id := Aspect_Specifications (N);
1484 Ins_Node : Node_Id := N;
1485 -- Insert pragmas/attribute definition clause after this node when no
1486 -- delayed analysis is required.
1488 -- Start of processing for Analyze_Aspect_Specifications
1491 -- The general processing involves building an attribute definition
1492 -- clause or a pragma node that corresponds to the aspect. Then in order
1493 -- to delay the evaluation of this aspect to the freeze point, we attach
1494 -- the corresponding pragma/attribute definition clause to the aspect
1495 -- specification node, which is then placed in the Rep Item chain. In
1496 -- this case we mark the entity by setting the flag Has_Delayed_Aspects
1497 -- and we evaluate the rep item at the freeze point. When the aspect
1498 -- doesn't have a corresponding pragma/attribute definition clause, then
1499 -- its analysis is simply delayed at the freeze point.
1501 -- Some special cases don't require delay analysis, thus the aspect is
1502 -- analyzed right now.
1504 -- Note that there is a special handling for Pre, Post, Test_Case,
1505 -- Contract_Cases aspects. In these cases, we do not have to worry
1506 -- about delay issues, since the pragmas themselves deal with delay
1507 -- of visibility for the expression analysis. Thus, we just insert
1508 -- the pragma after the node N.
1510 pragma Assert (Present (L));
1512 -- Loop through aspects
1514 Aspect := First (L);
1515 Aspect_Loop : while Present (Aspect) loop
1516 Analyze_One_Aspect : declare
1517 Expr : constant Node_Id := Expression (Aspect);
1518 Id : constant Node_Id := Identifier (Aspect);
1519 Loc : constant Source_Ptr := Sloc (Aspect);
1520 Nam : constant Name_Id := Chars (Id);
1521 A_Id : constant Aspect_Id := Get_Aspect_Id (Nam);
1524 Delay_Required : Boolean;
1525 -- Set False if delay is not required
1527 Eloc : Source_Ptr := No_Location;
1528 -- Source location of expression, modified when we split PPC's. It
1529 -- is set below when Expr is present.
1531 procedure Analyze_Aspect_Convention;
1532 -- Perform analysis of aspect Convention
1534 procedure Analyze_Aspect_Export_Import;
1535 -- Perform analysis of aspects Export or Import
1537 procedure Analyze_Aspect_External_Link_Name;
1538 -- Perform analysis of aspects External_Name or Link_Name
1540 procedure Analyze_Aspect_Implicit_Dereference;
1541 -- Perform analysis of the Implicit_Dereference aspects
1543 procedure Make_Aitem_Pragma
1544 (Pragma_Argument_Associations : List_Id;
1545 Pragma_Name : Name_Id);
1546 -- This is a wrapper for Make_Pragma used for converting aspects
1547 -- to pragmas. It takes care of Sloc (set from Loc) and building
1548 -- the pragma identifier from the given name. In addition the
1549 -- flags Class_Present and Split_PPC are set from the aspect
1550 -- node, as well as Is_Ignored. This routine also sets the
1551 -- From_Aspect_Specification in the resulting pragma node to
1552 -- True, and sets Corresponding_Aspect to point to the aspect.
1553 -- The resulting pragma is assigned to Aitem.
1555 -------------------------------
1556 -- Analyze_Aspect_Convention --
1557 -------------------------------
1559 procedure Analyze_Aspect_Convention is
1568 -- Obtain all interfacing aspects that apply to the related
1571 Get_Interfacing_Aspects
1572 (Iface_Asp => Aspect,
1573 Conv_Asp => Dummy_1,
1580 -- The related entity is subject to aspect Export or Import.
1581 -- Do not process Convention now because it must be analysed
1582 -- as part of Export or Import.
1584 if Present (Expo) or else Present (Imp) then
1587 -- Otherwise Convention appears by itself
1590 -- The aspect specifies a particular convention
1592 if Present (Expr) then
1593 Conv := New_Copy_Tree (Expr);
1595 -- Otherwise assume convention Ada
1598 Conv := Make_Identifier (Loc, Name_Ada);
1602 -- pragma Convention (<Conv>, <E>);
1605 (Pragma_Name => Name_Convention,
1606 Pragma_Argument_Associations => New_List (
1607 Make_Pragma_Argument_Association (Loc,
1608 Expression => Conv),
1609 Make_Pragma_Argument_Association (Loc,
1610 Expression => New_Occurrence_Of (E, Loc))));
1612 Decorate (Aspect, Aitem);
1613 Insert_Pragma (Aitem);
1615 end Analyze_Aspect_Convention;
1617 ----------------------------------
1618 -- Analyze_Aspect_Export_Import --
1619 ----------------------------------
1621 procedure Analyze_Aspect_Export_Import is
1629 -- Obtain all interfacing aspects that apply to the related
1632 Get_Interfacing_Aspects
1633 (Iface_Asp => Aspect,
1634 Conv_Asp => Dummy_1,
1641 -- The related entity cannot be subject to both aspects Export
1644 if Present (Expo) and then Present (Imp) then
1646 ("incompatible interfacing aspects given for &", E);
1647 Error_Msg_Sloc := Sloc (Expo);
1648 Error_Msg_N ("\aspect `Export` #", E);
1649 Error_Msg_Sloc := Sloc (Imp);
1650 Error_Msg_N ("\aspect `Import` #", E);
1653 -- A variable is most likely modified from the outside. Take
1654 -- Take the optimistic approach to avoid spurious errors.
1656 if Ekind (E) = E_Variable then
1657 Set_Never_Set_In_Source (E, False);
1660 -- Resolve the expression of an Import or Export here, and
1661 -- require it to be of type Boolean and static. This is not
1662 -- quite right, because in general this should be delayed,
1663 -- but that seems tricky for these, because normally Boolean
1664 -- aspects are replaced with pragmas at the freeze point in
1665 -- Make_Pragma_From_Boolean_Aspect.
1667 if not Present (Expr)
1668 or else Is_True (Static_Boolean (Expr))
1670 if A_Id = Aspect_Import then
1671 Set_Has_Completion (E);
1672 Set_Is_Imported (E);
1674 -- An imported object cannot be explicitly initialized
1676 if Nkind (N) = N_Object_Declaration
1677 and then Present (Expression (N))
1680 ("imported entities cannot be initialized "
1681 & "(RM B.1(24))", Expression (N));
1685 pragma Assert (A_Id = Aspect_Export);
1686 Set_Is_Exported (E);
1689 -- Create the proper form of pragma Export or Import taking
1690 -- into account Conversion, External_Name, and Link_Name.
1692 Aitem := Build_Export_Import_Pragma (Aspect, E);
1694 -- Otherwise the expression is either False or erroneous. There
1695 -- is no corresponding pragma.
1700 end Analyze_Aspect_Export_Import;
1702 ---------------------------------------
1703 -- Analyze_Aspect_External_Link_Name --
1704 ---------------------------------------
1706 procedure Analyze_Aspect_External_Link_Name is
1714 -- Obtain all interfacing aspects that apply to the related
1717 Get_Interfacing_Aspects
1718 (Iface_Asp => Aspect,
1719 Conv_Asp => Dummy_1,
1726 -- Ensure that aspect External_Name applies to aspect Export or
1729 if A_Id = Aspect_External_Name then
1730 if No (Expo) and then No (Imp) then
1732 ("aspect `External_Name` requires aspect `Import` or "
1733 & "`Export`", Aspect);
1736 -- Otherwise ensure that aspect Link_Name applies to aspect
1737 -- Export or Import.
1740 pragma Assert (A_Id = Aspect_Link_Name);
1741 if No (Expo) and then No (Imp) then
1743 ("aspect `Link_Name` requires aspect `Import` or "
1744 & "`Export`", Aspect);
1747 end Analyze_Aspect_External_Link_Name;
1749 -----------------------------------------
1750 -- Analyze_Aspect_Implicit_Dereference --
1751 -----------------------------------------
1753 procedure Analyze_Aspect_Implicit_Dereference is
1755 Parent_Disc : Entity_Id;
1758 if not Is_Type (E) or else not Has_Discriminants (E) then
1760 ("aspect must apply to a type with discriminants", Expr);
1762 elsif not Is_Entity_Name (Expr) then
1764 ("aspect must name a discriminant of current type", Expr);
1767 Disc := First_Discriminant (E);
1768 while Present (Disc) loop
1769 if Chars (Expr) = Chars (Disc)
1770 and then Ekind (Etype (Disc)) =
1771 E_Anonymous_Access_Type
1773 Set_Has_Implicit_Dereference (E);
1774 Set_Has_Implicit_Dereference (Disc);
1778 Next_Discriminant (Disc);
1781 -- Error if no proper access discriminant
1784 Error_Msg_NE ("not an access discriminant of&", Expr, E);
1789 -- For a type extension, check whether parent has a
1790 -- reference discriminant, to verify that use is proper.
1792 if Is_Derived_Type (E)
1793 and then Has_Discriminants (Etype (E))
1795 Parent_Disc := Get_Reference_Discriminant (Etype (E));
1797 if Present (Parent_Disc)
1798 and then Corresponding_Discriminant (Disc) /= Parent_Disc
1801 ("reference discriminant does not match discriminant "
1802 & "of parent type", Expr);
1805 end Analyze_Aspect_Implicit_Dereference;
1807 -----------------------
1808 -- Make_Aitem_Pragma --
1809 -----------------------
1811 procedure Make_Aitem_Pragma
1812 (Pragma_Argument_Associations : List_Id;
1813 Pragma_Name : Name_Id)
1815 Args : List_Id := Pragma_Argument_Associations;
1818 -- We should never get here if aspect was disabled
1820 pragma Assert (not Is_Disabled (Aspect));
1822 -- Certain aspects allow for an optional name or expression. Do
1823 -- not generate a pragma with empty argument association list.
1825 if No (Args) or else No (Expression (First (Args))) then
1833 Pragma_Argument_Associations => Args,
1834 Pragma_Identifier =>
1835 Make_Identifier (Sloc (Id), Pragma_Name),
1836 Class_Present => Class_Present (Aspect),
1837 Split_PPC => Split_PPC (Aspect));
1839 -- Set additional semantic fields
1841 if Is_Ignored (Aspect) then
1842 Set_Is_Ignored (Aitem);
1843 elsif Is_Checked (Aspect) then
1844 Set_Is_Checked (Aitem);
1847 Set_Corresponding_Aspect (Aitem, Aspect);
1848 Set_From_Aspect_Specification (Aitem);
1849 end Make_Aitem_Pragma;
1851 -- Start of processing for Analyze_One_Aspect
1854 -- Skip aspect if already analyzed, to avoid looping in some cases
1856 if Analyzed (Aspect) then
1860 -- Skip looking at aspect if it is totally disabled. Just mark it
1861 -- as such for later reference in the tree. This also sets the
1862 -- Is_Ignored and Is_Checked flags appropriately.
1864 Check_Applicable_Policy (Aspect);
1866 if Is_Disabled (Aspect) then
1870 -- Set the source location of expression, used in the case of
1871 -- a failed precondition/postcondition or invariant. Note that
1872 -- the source location of the expression is not usually the best
1873 -- choice here. For example, it gets located on the last AND
1874 -- keyword in a chain of boolean expressiond AND'ed together.
1875 -- It is best to put the message on the first character of the
1876 -- assertion, which is the effect of the First_Node call here.
1878 if Present (Expr) then
1879 Eloc := Sloc (First_Node (Expr));
1882 -- Check restriction No_Implementation_Aspect_Specifications
1884 if Implementation_Defined_Aspect (A_Id) then
1886 (No_Implementation_Aspect_Specifications, Aspect);
1889 -- Check restriction No_Specification_Of_Aspect
1891 Check_Restriction_No_Specification_Of_Aspect (Aspect);
1893 -- Mark aspect analyzed (actual analysis is delayed till later)
1895 Set_Analyzed (Aspect);
1896 Set_Entity (Aspect, E);
1897 Ent := New_Occurrence_Of (E, Sloc (Id));
1899 -- Check for duplicate aspect. Note that the Comes_From_Source
1900 -- test allows duplicate Pre/Post's that we generate internally
1901 -- to escape being flagged here.
1903 if No_Duplicates_Allowed (A_Id) then
1905 while Anod /= Aspect loop
1906 if Comes_From_Source (Aspect)
1907 and then Same_Aspect (A_Id, Get_Aspect_Id (Anod))
1909 Error_Msg_Name_1 := Nam;
1910 Error_Msg_Sloc := Sloc (Anod);
1912 -- Case of same aspect specified twice
1914 if Class_Present (Anod) = Class_Present (Aspect) then
1915 if not Class_Present (Anod) then
1917 ("aspect% for & previously given#",
1921 ("aspect `%''Class` for & previously given#",
1931 -- Check some general restrictions on language defined aspects
1933 if not Implementation_Defined_Aspect (A_Id) then
1934 Error_Msg_Name_1 := Nam;
1936 -- Not allowed for renaming declarations
1938 if Nkind (N) in N_Renaming_Declaration then
1940 ("aspect % not allowed for renaming declaration",
1944 -- Not allowed for formal type declarations
1946 if Nkind (N) = N_Formal_Type_Declaration then
1948 ("aspect % not allowed for formal type declaration",
1953 -- Copy expression for later processing by the procedures
1954 -- Check_Aspect_At_[Freeze_Point | End_Of_Declarations]
1956 Set_Entity (Id, New_Copy_Tree (Expr));
1958 -- Set Delay_Required as appropriate to aspect
1960 case Aspect_Delay (A_Id) is
1961 when Always_Delay =>
1962 Delay_Required := True;
1965 Delay_Required := False;
1969 -- If expression has the form of an integer literal, then
1970 -- do not delay, since we know the value cannot change.
1971 -- This optimization catches most rep clause cases.
1973 -- For Boolean aspects, don't delay if no expression
1975 if A_Id in Boolean_Aspects and then No (Expr) then
1976 Delay_Required := False;
1978 -- For non-Boolean aspects, don't delay if integer literal
1980 elsif A_Id not in Boolean_Aspects
1981 and then Present (Expr)
1982 and then Nkind (Expr) = N_Integer_Literal
1984 Delay_Required := False;
1986 -- All other cases are delayed
1989 Delay_Required := True;
1990 Set_Has_Delayed_Rep_Aspects (E);
1994 -- Processing based on specific aspect
1997 when Aspect_Unimplemented =>
1998 null; -- ??? temp for now
2000 -- No_Aspect should be impossible
2003 raise Program_Error;
2005 -- Case 1: Aspects corresponding to attribute definition
2008 when Aspect_Address |
2011 Aspect_Component_Size |
2012 Aspect_Constant_Indexing |
2013 Aspect_Default_Iterator |
2014 Aspect_Dispatching_Domain |
2015 Aspect_External_Tag |
2018 Aspect_Iterator_Element |
2019 Aspect_Machine_Radix |
2020 Aspect_Object_Size |
2023 Aspect_Scalar_Storage_Order |
2026 Aspect_Simple_Storage_Pool |
2027 Aspect_Storage_Pool |
2028 Aspect_Stream_Size |
2030 Aspect_Variable_Indexing |
2033 -- Indexing aspects apply only to tagged type
2035 if (A_Id = Aspect_Constant_Indexing
2037 A_Id = Aspect_Variable_Indexing)
2038 and then not (Is_Type (E)
2039 and then Is_Tagged_Type (E))
2042 ("indexing aspect can only apply to a tagged type",
2047 -- For the case of aspect Address, we don't consider that we
2048 -- know the entity is never set in the source, since it is
2049 -- is likely aliasing is occurring.
2051 -- Note: one might think that the analysis of the resulting
2052 -- attribute definition clause would take care of that, but
2053 -- that's not the case since it won't be from source.
2055 if A_Id = Aspect_Address then
2056 Set_Never_Set_In_Source (E, False);
2059 -- Correctness of the profile of a stream operation is
2060 -- verified at the freeze point, but we must detect the
2061 -- illegal specification of this aspect for a subtype now,
2062 -- to prevent malformed rep_item chains.
2064 if A_Id = Aspect_Input or else
2065 A_Id = Aspect_Output or else
2066 A_Id = Aspect_Read or else
2069 if not Is_First_Subtype (E) then
2071 ("local name must be a first subtype", Aspect);
2074 -- If stream aspect applies to the class-wide type,
2075 -- the generated attribute definition applies to the
2076 -- class-wide type as well.
2078 elsif Class_Present (Aspect) then
2080 Make_Attribute_Reference (Loc,
2082 Attribute_Name => Name_Class);
2086 -- Construct the attribute definition clause
2089 Make_Attribute_Definition_Clause (Loc,
2091 Chars => Chars (Id),
2092 Expression => Relocate_Node (Expr));
2094 -- If the address is specified, then we treat the entity as
2095 -- referenced, to avoid spurious warnings. This is analogous
2096 -- to what is done with an attribute definition clause, but
2097 -- here we don't want to generate a reference because this
2098 -- is the point of definition of the entity.
2100 if A_Id = Aspect_Address then
2104 -- Case 2: Aspects corresponding to pragmas
2106 -- Case 2a: Aspects corresponding to pragmas with two
2107 -- arguments, where the first argument is a local name
2108 -- referring to the entity, and the second argument is the
2109 -- aspect definition expression.
2111 -- Linker_Section/Suppress/Unsuppress
2113 when Aspect_Linker_Section |
2115 Aspect_Unsuppress =>
2118 (Pragma_Argument_Associations => New_List (
2119 Make_Pragma_Argument_Association (Loc,
2120 Expression => New_Occurrence_Of (E, Loc)),
2121 Make_Pragma_Argument_Association (Sloc (Expr),
2122 Expression => Relocate_Node (Expr))),
2123 Pragma_Name => Chars (Id));
2127 -- Corresponds to pragma Implemented, construct the pragma
2129 when Aspect_Synchronization =>
2131 (Pragma_Argument_Associations => New_List (
2132 Make_Pragma_Argument_Association (Loc,
2133 Expression => New_Occurrence_Of (E, Loc)),
2134 Make_Pragma_Argument_Association (Sloc (Expr),
2135 Expression => Relocate_Node (Expr))),
2136 Pragma_Name => Name_Implemented);
2140 when Aspect_Attach_Handler =>
2142 (Pragma_Argument_Associations => New_List (
2143 Make_Pragma_Argument_Association (Sloc (Ent),
2145 Make_Pragma_Argument_Association (Sloc (Expr),
2146 Expression => Relocate_Node (Expr))),
2147 Pragma_Name => Name_Attach_Handler);
2149 -- We need to insert this pragma into the tree to get proper
2150 -- processing and to look valid from a placement viewpoint.
2152 Insert_Pragma (Aitem);
2155 -- Dynamic_Predicate, Predicate, Static_Predicate
2157 when Aspect_Dynamic_Predicate |
2159 Aspect_Static_Predicate =>
2161 -- These aspects apply only to subtypes
2163 if not Is_Type (E) then
2165 ("predicate can only be specified for a subtype",
2169 elsif Is_Incomplete_Type (E) then
2171 ("predicate cannot apply to incomplete view", Aspect);
2175 -- Construct the pragma (always a pragma Predicate, with
2176 -- flags recording whether it is static/dynamic). We also
2177 -- set flags recording this in the type itself.
2180 (Pragma_Argument_Associations => New_List (
2181 Make_Pragma_Argument_Association (Sloc (Ent),
2183 Make_Pragma_Argument_Association (Sloc (Expr),
2184 Expression => Relocate_Node (Expr))),
2185 Pragma_Name => Name_Predicate);
2187 -- Mark type has predicates, and remember what kind of
2188 -- aspect lead to this predicate (we need this to access
2189 -- the right set of check policies later on).
2191 Set_Has_Predicates (E);
2193 if A_Id = Aspect_Dynamic_Predicate then
2194 Set_Has_Dynamic_Predicate_Aspect (E);
2195 elsif A_Id = Aspect_Static_Predicate then
2196 Set_Has_Static_Predicate_Aspect (E);
2199 -- If the type is private, indicate that its completion
2200 -- has a freeze node, because that is the one that will
2201 -- be visible at freeze time.
2203 if Is_Private_Type (E) and then Present (Full_View (E)) then
2204 Set_Has_Predicates (Full_View (E));
2206 if A_Id = Aspect_Dynamic_Predicate then
2207 Set_Has_Dynamic_Predicate_Aspect (Full_View (E));
2208 elsif A_Id = Aspect_Static_Predicate then
2209 Set_Has_Static_Predicate_Aspect (Full_View (E));
2212 Set_Has_Delayed_Aspects (Full_View (E));
2213 Ensure_Freeze_Node (Full_View (E));
2216 -- Predicate_Failure
2218 when Aspect_Predicate_Failure =>
2220 -- This aspect applies only to subtypes
2222 if not Is_Type (E) then
2224 ("predicate can only be specified for a subtype",
2228 elsif Is_Incomplete_Type (E) then
2230 ("predicate cannot apply to incomplete view", Aspect);
2234 -- Construct the pragma
2237 (Pragma_Argument_Associations => New_List (
2238 Make_Pragma_Argument_Association (Sloc (Ent),
2240 Make_Pragma_Argument_Association (Sloc (Expr),
2241 Expression => Relocate_Node (Expr))),
2242 Pragma_Name => Name_Predicate_Failure);
2244 Set_Has_Predicates (E);
2246 -- If the type is private, indicate that its completion
2247 -- has a freeze node, because that is the one that will
2248 -- be visible at freeze time.
2250 if Is_Private_Type (E) and then Present (Full_View (E)) then
2251 Set_Has_Predicates (Full_View (E));
2252 Set_Has_Delayed_Aspects (Full_View (E));
2253 Ensure_Freeze_Node (Full_View (E));
2256 -- Case 2b: Aspects corresponding to pragmas with two
2257 -- arguments, where the second argument is a local name
2258 -- referring to the entity, and the first argument is the
2259 -- aspect definition expression.
2263 when Aspect_Convention =>
2264 Analyze_Aspect_Convention;
2267 -- External_Name, Link_Name
2269 when Aspect_External_Name |
2271 Analyze_Aspect_External_Link_Name;
2274 -- CPU, Interrupt_Priority, Priority
2276 -- These three aspects can be specified for a subprogram spec
2277 -- or body, in which case we analyze the expression and export
2278 -- the value of the aspect.
2280 -- Previously, we generated an equivalent pragma for bodies
2281 -- (note that the specs cannot contain these pragmas). The
2282 -- pragma was inserted ahead of local declarations, rather than
2283 -- after the body. This leads to a certain duplication between
2284 -- the processing performed for the aspect and the pragma, but
2285 -- given the straightforward handling required it is simpler
2286 -- to duplicate than to translate the aspect in the spec into
2287 -- a pragma in the declarative part of the body.
2290 Aspect_Interrupt_Priority |
2293 if Nkind_In (N, N_Subprogram_Body,
2294 N_Subprogram_Declaration)
2296 -- Analyze the aspect expression
2298 Analyze_And_Resolve (Expr, Standard_Integer);
2300 -- Interrupt_Priority aspect not allowed for main
2301 -- subprograms. RM D.1 does not forbid this explicitly,
2302 -- but RM J.15.11(6/3) does not permit pragma
2303 -- Interrupt_Priority for subprograms.
2305 if A_Id = Aspect_Interrupt_Priority then
2307 ("Interrupt_Priority aspect cannot apply to "
2308 & "subprogram", Expr);
2310 -- The expression must be static
2312 elsif not Is_OK_Static_Expression (Expr) then
2313 Flag_Non_Static_Expr
2314 ("aspect requires static expression!", Expr);
2316 -- Check whether this is the main subprogram. Issue a
2317 -- warning only if it is obviously not a main program
2318 -- (when it has parameters or when the subprogram is
2319 -- within a package).
2321 elsif Present (Parameter_Specifications
2322 (Specification (N)))
2323 or else not Is_Compilation_Unit (Defining_Entity (N))
2325 -- See RM D.1(14/3) and D.16(12/3)
2328 ("aspect applied to subprogram other than the "
2329 & "main subprogram has no effect??", Expr);
2331 -- Otherwise check in range and export the value
2333 -- For the CPU aspect
2335 elsif A_Id = Aspect_CPU then
2336 if Is_In_Range (Expr, RTE (RE_CPU_Range)) then
2338 -- Value is correct so we export the value to make
2339 -- it available at execution time.
2342 (Main_Unit, UI_To_Int (Expr_Value (Expr)));
2346 ("main subprogram CPU is out of range", Expr);
2349 -- For the Priority aspect
2351 elsif A_Id = Aspect_Priority then
2352 if Is_In_Range (Expr, RTE (RE_Priority)) then
2354 -- Value is correct so we export the value to make
2355 -- it available at execution time.
2358 (Main_Unit, UI_To_Int (Expr_Value (Expr)));
2360 -- Ignore pragma if Relaxed_RM_Semantics to support
2361 -- other targets/non GNAT compilers.
2363 elsif not Relaxed_RM_Semantics then
2365 ("main subprogram priority is out of range",
2370 -- Load an arbitrary entity from System.Tasking.Stages
2371 -- or System.Tasking.Restricted.Stages (depending on
2372 -- the supported profile) to make sure that one of these
2373 -- packages is implicitly with'ed, since we need to have
2374 -- the tasking run time active for the pragma Priority to
2375 -- have any effect. Previously we with'ed the package
2376 -- System.Tasking, but this package does not trigger the
2377 -- required initialization of the run-time library.
2380 Discard : Entity_Id;
2382 if Restricted_Profile then
2383 Discard := RTE (RE_Activate_Restricted_Tasks);
2385 Discard := RTE (RE_Activate_Tasks);
2389 -- Handling for these Aspects in subprograms is complete
2393 -- For tasks pass the aspect as an attribute
2397 Make_Attribute_Definition_Clause (Loc,
2399 Chars => Chars (Id),
2400 Expression => Relocate_Node (Expr));
2405 when Aspect_Warnings =>
2407 (Pragma_Argument_Associations => New_List (
2408 Make_Pragma_Argument_Association (Sloc (Expr),
2409 Expression => Relocate_Node (Expr)),
2410 Make_Pragma_Argument_Association (Loc,
2411 Expression => New_Occurrence_Of (E, Loc))),
2412 Pragma_Name => Chars (Id));
2414 Decorate (Aspect, Aitem);
2415 Insert_Pragma (Aitem);
2418 -- Case 2c: Aspects corresponding to pragmas with three
2421 -- Invariant aspects have a first argument that references the
2422 -- entity, a second argument that is the expression and a third
2423 -- argument that is an appropriate message.
2425 -- Invariant, Type_Invariant
2427 when Aspect_Invariant |
2428 Aspect_Type_Invariant =>
2430 -- Analysis of the pragma will verify placement legality:
2431 -- an invariant must apply to a private type, or appear in
2432 -- the private part of a spec and apply to a completion.
2435 (Pragma_Argument_Associations => New_List (
2436 Make_Pragma_Argument_Association (Sloc (Ent),
2438 Make_Pragma_Argument_Association (Sloc (Expr),
2439 Expression => Relocate_Node (Expr))),
2440 Pragma_Name => Name_Invariant);
2442 -- Add message unless exception messages are suppressed
2444 if not Opt.Exception_Locations_Suppressed then
2445 Append_To (Pragma_Argument_Associations (Aitem),
2446 Make_Pragma_Argument_Association (Eloc,
2447 Chars => Name_Message,
2449 Make_String_Literal (Eloc,
2450 Strval => "failed invariant from "
2451 & Build_Location_String (Eloc))));
2454 -- For Invariant case, insert immediately after the entity
2455 -- declaration. We do not have to worry about delay issues
2456 -- since the pragma processing takes care of this.
2458 Delay_Required := False;
2460 -- Case 2d : Aspects that correspond to a pragma with one
2465 -- Aspect Abstract_State introduces implicit declarations for
2466 -- all state abstraction entities it defines. To emulate this
2467 -- behavior, insert the pragma at the beginning of the visible
2468 -- declarations of the related package so that it is analyzed
2471 when Aspect_Abstract_State => Abstract_State : declare
2472 Context : Node_Id := N;
2475 -- When aspect Abstract_State appears on a generic package,
2476 -- it is propageted to the package instance. The context in
2477 -- this case is the instance spec.
2479 if Nkind (Context) = N_Package_Instantiation then
2480 Context := Instance_Spec (Context);
2483 if Nkind_In (Context, N_Generic_Package_Declaration,
2484 N_Package_Declaration)
2487 (Pragma_Argument_Associations => New_List (
2488 Make_Pragma_Argument_Association (Loc,
2489 Expression => Relocate_Node (Expr))),
2490 Pragma_Name => Name_Abstract_State);
2492 Decorate (Aspect, Aitem);
2496 Is_Generic_Instance (Defining_Entity (Context)));
2500 ("aspect & must apply to a package declaration",
2507 -- Aspect Async_Readers is never delayed because it is
2508 -- equivalent to a source pragma which appears after the
2509 -- related object declaration.
2511 when Aspect_Async_Readers =>
2513 (Pragma_Argument_Associations => New_List (
2514 Make_Pragma_Argument_Association (Loc,
2515 Expression => Relocate_Node (Expr))),
2516 Pragma_Name => Name_Async_Readers);
2518 Decorate (Aspect, Aitem);
2519 Insert_Pragma (Aitem);
2522 -- Aspect Async_Writers is never delayed because it is
2523 -- equivalent to a source pragma which appears after the
2524 -- related object declaration.
2526 when Aspect_Async_Writers =>
2528 (Pragma_Argument_Associations => New_List (
2529 Make_Pragma_Argument_Association (Loc,
2530 Expression => Relocate_Node (Expr))),
2531 Pragma_Name => Name_Async_Writers);
2533 Decorate (Aspect, Aitem);
2534 Insert_Pragma (Aitem);
2537 -- Aspect Constant_After_Elaboration is never delayed because
2538 -- it is equivalent to a source pragma which appears after the
2539 -- related object declaration.
2541 when Aspect_Constant_After_Elaboration =>
2543 (Pragma_Argument_Associations => New_List (
2544 Make_Pragma_Argument_Association (Loc,
2545 Expression => Relocate_Node (Expr))),
2547 Name_Constant_After_Elaboration);
2549 Decorate (Aspect, Aitem);
2550 Insert_Pragma (Aitem);
2553 -- Aspect Default_Internal_Condition is never delayed because
2554 -- it is equivalent to a source pragma which appears after the
2555 -- related private type. To deal with forward references, the
2556 -- generated pragma is stored in the rep chain of the related
2557 -- private type as types do not carry contracts. The pragma is
2558 -- wrapped inside of a procedure at the freeze point of the
2559 -- private type's full view.
2561 when Aspect_Default_Initial_Condition =>
2563 (Pragma_Argument_Associations => New_List (
2564 Make_Pragma_Argument_Association (Loc,
2565 Expression => Relocate_Node (Expr))),
2567 Name_Default_Initial_Condition);
2569 Decorate (Aspect, Aitem);
2570 Insert_Pragma (Aitem);
2573 -- Default_Storage_Pool
2575 when Aspect_Default_Storage_Pool =>
2577 (Pragma_Argument_Associations => New_List (
2578 Make_Pragma_Argument_Association (Loc,
2579 Expression => Relocate_Node (Expr))),
2581 Name_Default_Storage_Pool);
2583 Decorate (Aspect, Aitem);
2584 Insert_Pragma (Aitem);
2589 -- Aspect Depends is never delayed because it is equivalent to
2590 -- a source pragma which appears after the related subprogram.
2591 -- To deal with forward references, the generated pragma is
2592 -- stored in the contract of the related subprogram and later
2593 -- analyzed at the end of the declarative region. See routine
2594 -- Analyze_Depends_In_Decl_Part for details.
2596 when Aspect_Depends =>
2598 (Pragma_Argument_Associations => New_List (
2599 Make_Pragma_Argument_Association (Loc,
2600 Expression => Relocate_Node (Expr))),
2601 Pragma_Name => Name_Depends);
2603 Decorate (Aspect, Aitem);
2604 Insert_Pragma (Aitem);
2607 -- Aspect Effecitve_Reads is never delayed because it is
2608 -- equivalent to a source pragma which appears after the
2609 -- related object declaration.
2611 when Aspect_Effective_Reads =>
2613 (Pragma_Argument_Associations => New_List (
2614 Make_Pragma_Argument_Association (Loc,
2615 Expression => Relocate_Node (Expr))),
2616 Pragma_Name => Name_Effective_Reads);
2618 Decorate (Aspect, Aitem);
2619 Insert_Pragma (Aitem);
2622 -- Aspect Effective_Writes is never delayed because it is
2623 -- equivalent to a source pragma which appears after the
2624 -- related object declaration.
2626 when Aspect_Effective_Writes =>
2628 (Pragma_Argument_Associations => New_List (
2629 Make_Pragma_Argument_Association (Loc,
2630 Expression => Relocate_Node (Expr))),
2631 Pragma_Name => Name_Effective_Writes);
2633 Decorate (Aspect, Aitem);
2634 Insert_Pragma (Aitem);
2637 -- Aspect Extensions_Visible is never delayed because it is
2638 -- equivalent to a source pragma which appears after the
2639 -- related subprogram.
2641 when Aspect_Extensions_Visible =>
2643 (Pragma_Argument_Associations => New_List (
2644 Make_Pragma_Argument_Association (Loc,
2645 Expression => Relocate_Node (Expr))),
2646 Pragma_Name => Name_Extensions_Visible);
2648 Decorate (Aspect, Aitem);
2649 Insert_Pragma (Aitem);
2652 -- Aspect Ghost is never delayed because it is equivalent to a
2653 -- source pragma which appears at the top of [generic] package
2654 -- declarations or after an object, a [generic] subprogram, or
2655 -- a type declaration.
2657 when Aspect_Ghost =>
2659 (Pragma_Argument_Associations => New_List (
2660 Make_Pragma_Argument_Association (Loc,
2661 Expression => Relocate_Node (Expr))),
2662 Pragma_Name => Name_Ghost);
2664 Decorate (Aspect, Aitem);
2665 Insert_Pragma (Aitem);
2670 -- Aspect Global is never delayed because it is equivalent to
2671 -- a source pragma which appears after the related subprogram.
2672 -- To deal with forward references, the generated pragma is
2673 -- stored in the contract of the related subprogram and later
2674 -- analyzed at the end of the declarative region. See routine
2675 -- Analyze_Global_In_Decl_Part for details.
2677 when Aspect_Global =>
2679 (Pragma_Argument_Associations => New_List (
2680 Make_Pragma_Argument_Association (Loc,
2681 Expression => Relocate_Node (Expr))),
2682 Pragma_Name => Name_Global);
2684 Decorate (Aspect, Aitem);
2685 Insert_Pragma (Aitem);
2688 -- Initial_Condition
2690 -- Aspect Initial_Condition is never delayed because it is
2691 -- equivalent to a source pragma which appears after the
2692 -- related package. To deal with forward references, the
2693 -- generated pragma is stored in the contract of the related
2694 -- package and later analyzed at the end of the declarative
2695 -- region. See routine Analyze_Initial_Condition_In_Decl_Part
2698 when Aspect_Initial_Condition => Initial_Condition : declare
2699 Context : Node_Id := N;
2702 -- When aspect Initial_Condition appears on a generic
2703 -- package, it is propageted to the package instance. The
2704 -- context in this case is the instance spec.
2706 if Nkind (Context) = N_Package_Instantiation then
2707 Context := Instance_Spec (Context);
2710 if Nkind_In (Context, N_Generic_Package_Declaration,
2711 N_Package_Declaration)
2714 (Pragma_Argument_Associations => New_List (
2715 Make_Pragma_Argument_Association (Loc,
2716 Expression => Relocate_Node (Expr))),
2718 Name_Initial_Condition);
2720 Decorate (Aspect, Aitem);
2724 Is_Generic_Instance (Defining_Entity (Context)));
2726 -- Otherwise the context is illegal
2730 ("aspect & must apply to a package declaration",
2735 end Initial_Condition;
2739 -- Aspect Initializes is never delayed because it is equivalent
2740 -- to a source pragma appearing after the related package. To
2741 -- deal with forward references, the generated pragma is stored
2742 -- in the contract of the related package and later analyzed at
2743 -- the end of the declarative region. For details, see routine
2744 -- Analyze_Initializes_In_Decl_Part.
2746 when Aspect_Initializes => Initializes : declare
2747 Context : Node_Id := N;
2750 -- When aspect Initializes appears on a generic package,
2751 -- it is propageted to the package instance. The context
2752 -- in this case is the instance spec.
2754 if Nkind (Context) = N_Package_Instantiation then
2755 Context := Instance_Spec (Context);
2758 if Nkind_In (Context, N_Generic_Package_Declaration,
2759 N_Package_Declaration)
2762 (Pragma_Argument_Associations => New_List (
2763 Make_Pragma_Argument_Association (Loc,
2764 Expression => Relocate_Node (Expr))),
2765 Pragma_Name => Name_Initializes);
2767 Decorate (Aspect, Aitem);
2771 Is_Generic_Instance (Defining_Entity (Context)));
2773 -- Otherwise the context is illegal
2777 ("aspect & must apply to a package declaration",
2786 when Aspect_Obsolescent => declare
2794 Make_Pragma_Argument_Association (Sloc (Expr),
2795 Expression => Relocate_Node (Expr)));
2799 (Pragma_Argument_Associations => Args,
2800 Pragma_Name => Chars (Id));
2805 when Aspect_Part_Of =>
2806 if Nkind_In (N, N_Object_Declaration,
2807 N_Package_Instantiation)
2808 or else Is_Single_Concurrent_Type_Declaration (N)
2811 (Pragma_Argument_Associations => New_List (
2812 Make_Pragma_Argument_Association (Loc,
2813 Expression => Relocate_Node (Expr))),
2814 Pragma_Name => Name_Part_Of);
2816 Decorate (Aspect, Aitem);
2817 Insert_Pragma (Aitem);
2821 ("aspect & must apply to package instantiation, "
2822 & "object, single protected type or single task type",
2830 when Aspect_SPARK_Mode =>
2832 (Pragma_Argument_Associations => New_List (
2833 Make_Pragma_Argument_Association (Loc,
2834 Expression => Relocate_Node (Expr))),
2835 Pragma_Name => Name_SPARK_Mode);
2837 Decorate (Aspect, Aitem);
2838 Insert_Pragma (Aitem);
2843 -- Aspect Refined_Depends is never delayed because it is
2844 -- equivalent to a source pragma which appears in the
2845 -- declarations of the related subprogram body. To deal with
2846 -- forward references, the generated pragma is stored in the
2847 -- contract of the related subprogram body and later analyzed
2848 -- at the end of the declarative region. For details, see
2849 -- routine Analyze_Refined_Depends_In_Decl_Part.
2851 when Aspect_Refined_Depends =>
2853 (Pragma_Argument_Associations => New_List (
2854 Make_Pragma_Argument_Association (Loc,
2855 Expression => Relocate_Node (Expr))),
2856 Pragma_Name => Name_Refined_Depends);
2858 Decorate (Aspect, Aitem);
2859 Insert_Pragma (Aitem);
2864 -- Aspect Refined_Global is never delayed because it is
2865 -- equivalent to a source pragma which appears in the
2866 -- declarations of the related subprogram body. To deal with
2867 -- forward references, the generated pragma is stored in the
2868 -- contract of the related subprogram body and later analyzed
2869 -- at the end of the declarative region. For details, see
2870 -- routine Analyze_Refined_Global_In_Decl_Part.
2872 when Aspect_Refined_Global =>
2874 (Pragma_Argument_Associations => New_List (
2875 Make_Pragma_Argument_Association (Loc,
2876 Expression => Relocate_Node (Expr))),
2877 Pragma_Name => Name_Refined_Global);
2879 Decorate (Aspect, Aitem);
2880 Insert_Pragma (Aitem);
2885 when Aspect_Refined_Post =>
2887 (Pragma_Argument_Associations => New_List (
2888 Make_Pragma_Argument_Association (Loc,
2889 Expression => Relocate_Node (Expr))),
2890 Pragma_Name => Name_Refined_Post);
2892 Decorate (Aspect, Aitem);
2893 Insert_Pragma (Aitem);
2898 when Aspect_Refined_State =>
2900 -- The corresponding pragma for Refined_State is inserted in
2901 -- the declarations of the related package body. This action
2902 -- synchronizes both the source and from-aspect versions of
2905 if Nkind (N) = N_Package_Body then
2907 (Pragma_Argument_Associations => New_List (
2908 Make_Pragma_Argument_Association (Loc,
2909 Expression => Relocate_Node (Expr))),
2910 Pragma_Name => Name_Refined_State);
2912 Decorate (Aspect, Aitem);
2913 Insert_Pragma (Aitem);
2915 -- Otherwise the context is illegal
2919 ("aspect & must apply to a package body", Aspect, Id);
2924 -- Relative_Deadline
2926 when Aspect_Relative_Deadline =>
2928 (Pragma_Argument_Associations => New_List (
2929 Make_Pragma_Argument_Association (Loc,
2930 Expression => Relocate_Node (Expr))),
2931 Pragma_Name => Name_Relative_Deadline);
2933 -- If the aspect applies to a task, the corresponding pragma
2934 -- must appear within its declarations, not after.
2936 if Nkind (N) = N_Task_Type_Declaration then
2942 if No (Task_Definition (N)) then
2943 Set_Task_Definition (N,
2944 Make_Task_Definition (Loc,
2945 Visible_Declarations => New_List,
2946 End_Label => Empty));
2949 Def := Task_Definition (N);
2950 V := Visible_Declarations (Def);
2951 if not Is_Empty_List (V) then
2952 Insert_Before (First (V), Aitem);
2955 Set_Visible_Declarations (Def, New_List (Aitem));
2962 -- Aspect Volatile_Function is never delayed because it is
2963 -- equivalent to a source pragma which appears after the
2964 -- related subprogram.
2966 when Aspect_Volatile_Function =>
2968 (Pragma_Argument_Associations => New_List (
2969 Make_Pragma_Argument_Association (Loc,
2970 Expression => Relocate_Node (Expr))),
2971 Pragma_Name => Name_Volatile_Function);
2973 Decorate (Aspect, Aitem);
2974 Insert_Pragma (Aitem);
2977 -- Case 2e: Annotate aspect
2979 when Aspect_Annotate =>
2986 -- The argument can be a single identifier
2988 if Nkind (Expr) = N_Identifier then
2990 -- One level of parens is allowed
2992 if Paren_Count (Expr) > 1 then
2993 Error_Msg_F ("extra parentheses ignored", Expr);
2996 Set_Paren_Count (Expr, 0);
2998 -- Add the single item to the list
3000 Args := New_List (Expr);
3002 -- Otherwise we must have an aggregate
3004 elsif Nkind (Expr) = N_Aggregate then
3006 -- Must be positional
3008 if Present (Component_Associations (Expr)) then
3010 ("purely positional aggregate required", Expr);
3014 -- Must not be parenthesized
3016 if Paren_Count (Expr) /= 0 then
3017 Error_Msg_F ("extra parentheses ignored", Expr);
3020 -- List of arguments is list of aggregate expressions
3022 Args := Expressions (Expr);
3024 -- Anything else is illegal
3027 Error_Msg_F ("wrong form for Annotate aspect", Expr);
3031 -- Prepare pragma arguments
3034 Arg := First (Args);
3035 while Present (Arg) loop
3037 Make_Pragma_Argument_Association (Sloc (Arg),
3038 Expression => Relocate_Node (Arg)));
3043 Make_Pragma_Argument_Association (Sloc (Ent),
3044 Chars => Name_Entity,
3045 Expression => Ent));
3048 (Pragma_Argument_Associations => Pargs,
3049 Pragma_Name => Name_Annotate);
3052 -- Case 3 : Aspects that don't correspond to pragma/attribute
3053 -- definition clause.
3055 -- Case 3a: The aspects listed below don't correspond to
3056 -- pragmas/attributes but do require delayed analysis.
3058 -- Default_Value can only apply to a scalar type
3060 when Aspect_Default_Value =>
3061 if not Is_Scalar_Type (E) then
3063 ("aspect Default_Value must apply to a scalar type", N);
3068 -- Default_Component_Value can only apply to an array type
3069 -- with scalar components.
3071 when Aspect_Default_Component_Value =>
3072 if not (Is_Array_Type (E)
3073 and then Is_Scalar_Type (Component_Type (E)))
3076 ("aspect Default_Component_Value can only apply to an "
3077 & "array of scalar components", N);
3082 -- Case 3b: The aspects listed below don't correspond to
3083 -- pragmas/attributes and don't need delayed analysis.
3085 -- Implicit_Dereference
3087 -- For Implicit_Dereference, External_Name and Link_Name, only
3088 -- the legality checks are done during the analysis, thus no
3089 -- delay is required.
3091 when Aspect_Implicit_Dereference =>
3092 Analyze_Aspect_Implicit_Dereference;
3097 when Aspect_Dimension =>
3098 Analyze_Aspect_Dimension (N, Id, Expr);
3103 when Aspect_Dimension_System =>
3104 Analyze_Aspect_Dimension_System (N, Id, Expr);
3107 -- Case 4: Aspects requiring special handling
3109 -- Pre/Post/Test_Case/Contract_Cases whose corresponding
3110 -- pragmas take care of the delay.
3114 -- Aspects Pre/Post generate Precondition/Postcondition pragmas
3115 -- with a first argument that is the expression, and a second
3116 -- argument that is an informative message if the test fails.
3117 -- This is inserted right after the declaration, to get the
3118 -- required pragma placement. The processing for the pragmas
3119 -- takes care of the required delay.
3121 when Pre_Post_Aspects => Pre_Post : declare
3125 if A_Id = Aspect_Pre or else A_Id = Aspect_Precondition then
3126 Pname := Name_Precondition;
3128 Pname := Name_Postcondition;
3131 -- Check that the class-wide predicate cannot be applied to
3132 -- an operation of a synchronized type that is not a tagged
3133 -- type. Other legality checks are performed when analyzing
3134 -- the contract of the operation.
3136 if Class_Present (Aspect)
3137 and then Is_Concurrent_Type (Current_Scope)
3138 and then not Is_Tagged_Type (Current_Scope)
3139 and then Ekind_In (E, E_Entry, E_Function, E_Procedure)
3141 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (Aspect);
3143 ("aspect % can only be specified for a primitive "
3144 & "operation of a tagged type", Aspect);
3149 -- If the expressions is of the form A and then B, then
3150 -- we generate separate Pre/Post aspects for the separate
3151 -- clauses. Since we allow multiple pragmas, there is no
3152 -- problem in allowing multiple Pre/Post aspects internally.
3153 -- These should be treated in reverse order (B first and
3154 -- A second) since they are later inserted just after N in
3155 -- the order they are treated. This way, the pragma for A
3156 -- ends up preceding the pragma for B, which may have an
3157 -- importance for the error raised (either constraint error
3158 -- or precondition error).
3160 -- We do not do this for Pre'Class, since we have to put
3161 -- these conditions together in a complex OR expression.
3163 -- We do not do this in ASIS mode, as ASIS relies on the
3164 -- original node representing the complete expression, when
3165 -- retrieving it through the source aspect table.
3168 and then (Pname = Name_Postcondition
3169 or else not Class_Present (Aspect))
3171 while Nkind (Expr) = N_And_Then loop
3172 Insert_After (Aspect,
3173 Make_Aspect_Specification (Sloc (Left_Opnd (Expr)),
3174 Identifier => Identifier (Aspect),
3175 Expression => Relocate_Node (Left_Opnd (Expr)),
3176 Class_Present => Class_Present (Aspect),
3177 Split_PPC => True));
3178 Rewrite (Expr, Relocate_Node (Right_Opnd (Expr)));
3179 Eloc := Sloc (Expr);
3183 -- Build the precondition/postcondition pragma
3185 -- Add note about why we do NOT need Copy_Tree here???
3188 (Pragma_Argument_Associations => New_List (
3189 Make_Pragma_Argument_Association (Eloc,
3190 Chars => Name_Check,
3191 Expression => Relocate_Node (Expr))),
3192 Pragma_Name => Pname);
3194 -- Add message unless exception messages are suppressed
3196 if not Opt.Exception_Locations_Suppressed then
3197 Append_To (Pragma_Argument_Associations (Aitem),
3198 Make_Pragma_Argument_Association (Eloc,
3199 Chars => Name_Message,
3201 Make_String_Literal (Eloc,
3203 & Get_Name_String (Pname)
3205 & Build_Location_String (Eloc))));
3208 Set_Is_Delayed_Aspect (Aspect);
3210 -- For Pre/Post cases, insert immediately after the entity
3211 -- declaration, since that is the required pragma placement.
3212 -- Note that for these aspects, we do not have to worry
3213 -- about delay issues, since the pragmas themselves deal
3214 -- with delay of visibility for the expression analysis.
3216 Insert_Pragma (Aitem);
3223 when Aspect_Test_Case => Test_Case : declare
3225 Comp_Expr : Node_Id;
3226 Comp_Assn : Node_Id;
3232 if Nkind (Parent (N)) = N_Compilation_Unit then
3233 Error_Msg_Name_1 := Nam;
3234 Error_Msg_N ("incorrect placement of aspect `%`", E);
3238 if Nkind (Expr) /= N_Aggregate then
3239 Error_Msg_Name_1 := Nam;
3241 ("wrong syntax for aspect `%` for &", Id, E);
3245 -- Make pragma expressions refer to the original aspect
3246 -- expressions through the Original_Node link. This is used
3247 -- in semantic analysis for ASIS mode, so that the original
3248 -- expression also gets analyzed.
3250 Comp_Expr := First (Expressions (Expr));
3251 while Present (Comp_Expr) loop
3252 New_Expr := Relocate_Node (Comp_Expr);
3254 Make_Pragma_Argument_Association (Sloc (Comp_Expr),
3255 Expression => New_Expr));
3259 Comp_Assn := First (Component_Associations (Expr));
3260 while Present (Comp_Assn) loop
3261 if List_Length (Choices (Comp_Assn)) /= 1
3263 Nkind (First (Choices (Comp_Assn))) /= N_Identifier
3265 Error_Msg_Name_1 := Nam;
3267 ("wrong syntax for aspect `%` for &", Id, E);
3272 Make_Pragma_Argument_Association (Sloc (Comp_Assn),
3273 Chars => Chars (First (Choices (Comp_Assn))),
3275 Relocate_Node (Expression (Comp_Assn))));
3279 -- Build the test-case pragma
3282 (Pragma_Argument_Associations => Args,
3283 Pragma_Name => Nam);
3288 when Aspect_Contract_Cases =>
3290 (Pragma_Argument_Associations => New_List (
3291 Make_Pragma_Argument_Association (Loc,
3292 Expression => Relocate_Node (Expr))),
3293 Pragma_Name => Nam);
3295 Decorate (Aspect, Aitem);
3296 Insert_Pragma (Aitem);
3299 -- Case 5: Special handling for aspects with an optional
3300 -- boolean argument.
3302 -- In the delayed case, the corresponding pragma cannot be
3303 -- generated yet because the evaluation of the boolean needs
3304 -- to be delayed till the freeze point.
3306 when Boolean_Aspects |
3307 Library_Unit_Aspects =>
3309 Set_Is_Boolean_Aspect (Aspect);
3311 -- Lock_Free aspect only apply to protected objects
3313 if A_Id = Aspect_Lock_Free then
3314 if Ekind (E) /= E_Protected_Type then
3315 Error_Msg_Name_1 := Nam;
3317 ("aspect % only applies to a protected object",
3321 -- Set the Uses_Lock_Free flag to True if there is no
3322 -- expression or if the expression is True. The
3323 -- evaluation of this aspect should be delayed to the
3324 -- freeze point (why???)
3327 or else Is_True (Static_Boolean (Expr))
3329 Set_Uses_Lock_Free (E);
3332 Record_Rep_Item (E, Aspect);
3337 elsif A_Id = Aspect_Export or else A_Id = Aspect_Import then
3338 Analyze_Aspect_Export_Import;
3340 -- Disable_Controlled
3342 elsif A_Id = Aspect_Disable_Controlled then
3343 if Ekind (E) /= E_Record_Type
3344 or else not Is_Controlled (E)
3347 ("aspect % requires controlled record type", Aspect);
3351 -- If we're in a generic template, we don't want to try
3352 -- to disable controlled types, because typical usage is
3353 -- "Disable_Controlled => not <some_check>'Enabled", and
3354 -- the value of Enabled is not known until we see a
3355 -- particular instance. In such a context, we just need
3356 -- to preanalyze the expression for legality.
3358 if Expander_Active then
3359 Analyze_And_Resolve (Expr, Standard_Boolean);
3361 if not Present (Expr)
3362 or else Is_True (Static_Boolean (Expr))
3364 Set_Disable_Controlled (E);
3367 elsif Serious_Errors_Detected = 0 then
3368 Preanalyze_And_Resolve (Expr, Standard_Boolean);
3374 -- Library unit aspects require special handling in the case
3375 -- of a package declaration, the pragma needs to be inserted
3376 -- in the list of declarations for the associated package.
3377 -- There is no issue of visibility delay for these aspects.
3379 if A_Id in Library_Unit_Aspects
3381 Nkind_In (N, N_Package_Declaration,
3382 N_Generic_Package_Declaration)
3383 and then Nkind (Parent (N)) /= N_Compilation_Unit
3385 -- Aspect is legal on a local instantiation of a library-
3386 -- level generic unit.
3388 and then not Is_Generic_Instance (Defining_Entity (N))
3391 ("incorrect context for library unit aspect&", Id);
3395 -- Cases where we do not delay, includes all cases where the
3396 -- expression is missing other than the above cases.
3398 if not Delay_Required or else No (Expr) then
3400 -- Exclude aspects Export and Import because their pragma
3401 -- syntax does not map directly to a Boolean aspect.
3403 if A_Id /= Aspect_Export
3404 and then A_Id /= Aspect_Import
3407 (Pragma_Argument_Associations => New_List (
3408 Make_Pragma_Argument_Association (Sloc (Ent),
3409 Expression => Ent)),
3410 Pragma_Name => Chars (Id));
3413 Delay_Required := False;
3415 -- In general cases, the corresponding pragma/attribute
3416 -- definition clause will be inserted later at the freezing
3417 -- point, and we do not need to build it now.
3425 -- This is special because for access types we need to generate
3426 -- an attribute definition clause. This also works for single
3427 -- task declarations, but it does not work for task type
3428 -- declarations, because we have the case where the expression
3429 -- references a discriminant of the task type. That can't use
3430 -- an attribute definition clause because we would not have
3431 -- visibility on the discriminant. For that case we must
3432 -- generate a pragma in the task definition.
3434 when Aspect_Storage_Size =>
3438 if Ekind (E) = E_Task_Type then
3440 Decl : constant Node_Id := Declaration_Node (E);
3443 pragma Assert (Nkind (Decl) = N_Task_Type_Declaration);
3445 -- If no task definition, create one
3447 if No (Task_Definition (Decl)) then
3448 Set_Task_Definition (Decl,
3449 Make_Task_Definition (Loc,
3450 Visible_Declarations => Empty_List,
3451 End_Label => Empty));
3454 -- Create a pragma and put it at the start of the task
3455 -- definition for the task type declaration.
3458 (Pragma_Argument_Associations => New_List (
3459 Make_Pragma_Argument_Association (Loc,
3460 Expression => Relocate_Node (Expr))),
3461 Pragma_Name => Name_Storage_Size);
3465 Visible_Declarations (Task_Definition (Decl)));
3469 -- All other cases, generate attribute definition
3473 Make_Attribute_Definition_Clause (Loc,
3475 Chars => Chars (Id),
3476 Expression => Relocate_Node (Expr));
3480 -- Attach the corresponding pragma/attribute definition clause to
3481 -- the aspect specification node.
3483 if Present (Aitem) then
3484 Set_From_Aspect_Specification (Aitem);
3487 -- In the context of a compilation unit, we directly put the
3488 -- pragma in the Pragmas_After list of the N_Compilation_Unit_Aux
3489 -- node (no delay is required here) except for aspects on a
3490 -- subprogram body (see below) and a generic package, for which we
3491 -- need to introduce the pragma before building the generic copy
3492 -- (see sem_ch12), and for package instantiations, where the
3493 -- library unit pragmas are better handled early.
3495 if Nkind (Parent (N)) = N_Compilation_Unit
3496 and then (Present (Aitem) or else Is_Boolean_Aspect (Aspect))
3499 Aux : constant Node_Id := Aux_Decls_Node (Parent (N));
3502 pragma Assert (Nkind (Aux) = N_Compilation_Unit_Aux);
3504 -- For a Boolean aspect, create the corresponding pragma if
3505 -- no expression or if the value is True.
3507 if Is_Boolean_Aspect (Aspect) and then No (Aitem) then
3508 if Is_True (Static_Boolean (Expr)) then
3510 (Pragma_Argument_Associations => New_List (
3511 Make_Pragma_Argument_Association (Sloc (Ent),
3512 Expression => Ent)),
3513 Pragma_Name => Chars (Id));
3515 Set_From_Aspect_Specification (Aitem, True);
3516 Set_Corresponding_Aspect (Aitem, Aspect);
3523 -- If the aspect is on a subprogram body (relevant aspect
3524 -- is Inline), add the pragma in front of the declarations.
3526 if Nkind (N) = N_Subprogram_Body then
3527 if No (Declarations (N)) then
3528 Set_Declarations (N, New_List);
3531 Prepend (Aitem, Declarations (N));
3533 elsif Nkind (N) = N_Generic_Package_Declaration then
3534 if No (Visible_Declarations (Specification (N))) then
3535 Set_Visible_Declarations (Specification (N), New_List);
3539 Visible_Declarations (Specification (N)));
3541 elsif Nkind (N) = N_Package_Instantiation then
3543 Spec : constant Node_Id :=
3544 Specification (Instance_Spec (N));
3546 if No (Visible_Declarations (Spec)) then
3547 Set_Visible_Declarations (Spec, New_List);
3550 Prepend (Aitem, Visible_Declarations (Spec));
3554 if No (Pragmas_After (Aux)) then
3555 Set_Pragmas_After (Aux, New_List);
3558 Append (Aitem, Pragmas_After (Aux));
3565 -- The evaluation of the aspect is delayed to the freezing point.
3566 -- The pragma or attribute clause if there is one is then attached
3567 -- to the aspect specification which is put in the rep item list.
3569 if Delay_Required then
3570 if Present (Aitem) then
3571 Set_Is_Delayed_Aspect (Aitem);
3572 Set_Aspect_Rep_Item (Aspect, Aitem);
3573 Set_Parent (Aitem, Aspect);
3576 Set_Is_Delayed_Aspect (Aspect);
3578 -- In the case of Default_Value, link the aspect to base type
3579 -- as well, even though it appears on a first subtype. This is
3580 -- mandated by the semantics of the aspect. Do not establish
3581 -- the link when processing the base type itself as this leads
3582 -- to a rep item circularity. Verify that we are dealing with
3583 -- a scalar type to prevent cascaded errors.
3585 if A_Id = Aspect_Default_Value
3586 and then Is_Scalar_Type (E)
3587 and then Base_Type (E) /= E
3589 Set_Has_Delayed_Aspects (Base_Type (E));
3590 Record_Rep_Item (Base_Type (E), Aspect);
3593 Set_Has_Delayed_Aspects (E);
3594 Record_Rep_Item (E, Aspect);
3596 -- When delay is not required and the context is a package or a
3597 -- subprogram body, insert the pragma in the body declarations.
3599 elsif Nkind_In (N, N_Package_Body, N_Subprogram_Body) then
3600 if No (Declarations (N)) then
3601 Set_Declarations (N, New_List);
3604 -- The pragma is added before source declarations
3606 Prepend_To (Declarations (N), Aitem);
3608 -- When delay is not required and the context is not a compilation
3609 -- unit, we simply insert the pragma/attribute definition clause
3612 elsif Present (Aitem) then
3613 Insert_After (Ins_Node, Aitem);
3616 end Analyze_One_Aspect;
3620 end loop Aspect_Loop;
3622 if Has_Delayed_Aspects (E) then
3623 Ensure_Freeze_Node (E);
3625 end Analyze_Aspect_Specifications;
3627 ---------------------------------------------------
3628 -- Analyze_Aspect_Specifications_On_Body_Or_Stub --
3629 ---------------------------------------------------
3631 procedure Analyze_Aspect_Specifications_On_Body_Or_Stub (N : Node_Id) is
3632 Body_Id : constant Entity_Id := Defining_Entity (N);
3634 procedure Diagnose_Misplaced_Aspects (Spec_Id : Entity_Id);
3635 -- Body [stub] N has aspects, but they are not properly placed. Emit an
3636 -- error message depending on the aspects involved. Spec_Id denotes the
3637 -- entity of the corresponding spec.
3639 --------------------------------
3640 -- Diagnose_Misplaced_Aspects --
3641 --------------------------------
3643 procedure Diagnose_Misplaced_Aspects (Spec_Id : Entity_Id) is
3644 procedure Misplaced_Aspect_Error
3647 -- Emit an error message concerning misplaced aspect Asp. Ref_Nam is
3648 -- the name of the refined version of the aspect.
3650 ----------------------------
3651 -- Misplaced_Aspect_Error --
3652 ----------------------------
3654 procedure Misplaced_Aspect_Error
3658 Asp_Nam : constant Name_Id := Chars (Identifier (Asp));
3659 Asp_Id : constant Aspect_Id := Get_Aspect_Id (Asp_Nam);
3662 -- The corresponding spec already contains the aspect in question
3663 -- and the one appearing on the body must be the refined form:
3665 -- procedure P with Global ...;
3666 -- procedure P with Global ... is ... end P;
3670 if Has_Aspect (Spec_Id, Asp_Id) then
3671 Error_Msg_Name_1 := Asp_Nam;
3673 -- Subunits cannot carry aspects that apply to a subprogram
3676 if Nkind (Parent (N)) = N_Subunit then
3677 Error_Msg_N ("aspect % cannot apply to a subunit", Asp);
3679 -- Otherwise suggest the refined form
3682 Error_Msg_Name_2 := Ref_Nam;
3683 Error_Msg_N ("aspect % should be %", Asp);
3686 -- Otherwise the aspect must appear on the spec, not on the body
3689 -- procedure P with Global ... is ... end P;
3693 ("aspect specification must appear on initial declaration",
3696 end Misplaced_Aspect_Error;
3703 -- Start of processing for Diagnose_Misplaced_Aspects
3706 -- Iterate over the aspect specifications and emit specific errors
3707 -- where applicable.
3709 Asp := First (Aspect_Specifications (N));
3710 while Present (Asp) loop
3711 Asp_Nam := Chars (Identifier (Asp));
3713 -- Do not emit errors on aspects that can appear on a subprogram
3714 -- body. This scenario occurs when the aspect specification list
3715 -- contains both misplaced and properly placed aspects.
3717 if Aspect_On_Body_Or_Stub_OK (Get_Aspect_Id (Asp_Nam)) then
3720 -- Special diagnostics for SPARK aspects
3722 elsif Asp_Nam = Name_Depends then
3723 Misplaced_Aspect_Error (Asp, Name_Refined_Depends);
3725 elsif Asp_Nam = Name_Global then
3726 Misplaced_Aspect_Error (Asp, Name_Refined_Global);
3728 elsif Asp_Nam = Name_Post then
3729 Misplaced_Aspect_Error (Asp, Name_Refined_Post);
3731 -- Otherwise a language-defined aspect is misplaced
3735 ("aspect specification must appear on initial declaration",
3741 end Diagnose_Misplaced_Aspects;
3745 Spec_Id : constant Entity_Id := Unique_Defining_Entity (N);
3747 -- Start of processing for Analyze_Aspects_On_Body_Or_Stub
3750 -- Language-defined aspects cannot be associated with a subprogram body
3751 -- [stub] if the subprogram has a spec. Certain implementation defined
3752 -- aspects are allowed to break this rule (for all applicable cases, see
3753 -- table Aspects.Aspect_On_Body_Or_Stub_OK).
3755 if Spec_Id /= Body_Id and then not Aspects_On_Body_Or_Stub_OK (N) then
3756 Diagnose_Misplaced_Aspects (Spec_Id);
3758 Analyze_Aspect_Specifications (N, Body_Id);
3760 end Analyze_Aspect_Specifications_On_Body_Or_Stub;
3762 -----------------------
3763 -- Analyze_At_Clause --
3764 -----------------------
3766 -- An at clause is replaced by the corresponding Address attribute
3767 -- definition clause that is the preferred approach in Ada 95.
3769 procedure Analyze_At_Clause (N : Node_Id) is
3770 CS : constant Boolean := Comes_From_Source (N);
3773 -- This is an obsolescent feature
3775 Check_Restriction (No_Obsolescent_Features, N);
3777 if Warn_On_Obsolescent_Feature then
3779 ("?j?at clause is an obsolescent feature (RM J.7(2))", N);
3781 ("\?j?use address attribute definition clause instead", N);
3784 -- Rewrite as address clause
3787 Make_Attribute_Definition_Clause (Sloc (N),
3788 Name => Identifier (N),
3789 Chars => Name_Address,
3790 Expression => Expression (N)));
3792 -- We preserve Comes_From_Source, since logically the clause still comes
3793 -- from the source program even though it is changed in form.
3795 Set_Comes_From_Source (N, CS);
3797 -- Analyze rewritten clause
3799 Analyze_Attribute_Definition_Clause (N);
3800 end Analyze_At_Clause;
3802 -----------------------------------------
3803 -- Analyze_Attribute_Definition_Clause --
3804 -----------------------------------------
3806 procedure Analyze_Attribute_Definition_Clause (N : Node_Id) is
3807 Loc : constant Source_Ptr := Sloc (N);
3808 Nam : constant Node_Id := Name (N);
3809 Attr : constant Name_Id := Chars (N);
3810 Expr : constant Node_Id := Expression (N);
3811 Id : constant Attribute_Id := Get_Attribute_Id (Attr);
3814 -- The entity of Nam after it is analyzed. In the case of an incomplete
3815 -- type, this is the underlying type.
3818 -- The underlying entity to which the attribute applies. Generally this
3819 -- is the Underlying_Type of Ent, except in the case where the clause
3820 -- applies to full view of incomplete type or private type in which case
3821 -- U_Ent is just a copy of Ent.
3823 FOnly : Boolean := False;
3824 -- Reset to True for subtype specific attribute (Alignment, Size)
3825 -- and for stream attributes, i.e. those cases where in the call to
3826 -- Rep_Item_Too_Late, FOnly is set True so that only the freezing rules
3827 -- are checked. Note that the case of stream attributes is not clear
3828 -- from the RM, but see AI95-00137. Also, the RM seems to disallow
3829 -- Storage_Size for derived task types, but that is also clearly
3832 procedure Analyze_Stream_TSS_Definition (TSS_Nam : TSS_Name_Type);
3833 -- Common processing for 'Read, 'Write, 'Input and 'Output attribute
3834 -- definition clauses.
3836 function Duplicate_Clause return Boolean;
3837 -- This routine checks if the aspect for U_Ent being given by attribute
3838 -- definition clause N is for an aspect that has already been specified,
3839 -- and if so gives an error message. If there is a duplicate, True is
3840 -- returned, otherwise if there is no error, False is returned.
3842 procedure Check_Indexing_Functions;
3843 -- Check that the function in Constant_Indexing or Variable_Indexing
3844 -- attribute has the proper type structure. If the name is overloaded,
3845 -- check that some interpretation is legal.
3847 procedure Check_Iterator_Functions;
3848 -- Check that there is a single function in Default_Iterator attribute
3849 -- has the proper type structure.
3851 function Check_Primitive_Function (Subp : Entity_Id) return Boolean;
3852 -- Common legality check for the previous two
3854 -----------------------------------
3855 -- Analyze_Stream_TSS_Definition --
3856 -----------------------------------
3858 procedure Analyze_Stream_TSS_Definition (TSS_Nam : TSS_Name_Type) is
3859 Subp : Entity_Id := Empty;
3864 Is_Read : constant Boolean := (TSS_Nam = TSS_Stream_Read);
3865 -- True for Read attribute, False for other attributes
3867 function Has_Good_Profile
3869 Report : Boolean := False) return Boolean;
3870 -- Return true if the entity is a subprogram with an appropriate
3871 -- profile for the attribute being defined. If result is False and
3872 -- Report is True, function emits appropriate error.
3874 ----------------------
3875 -- Has_Good_Profile --
3876 ----------------------
3878 function Has_Good_Profile
3880 Report : Boolean := False) return Boolean
3882 Expected_Ekind : constant array (Boolean) of Entity_Kind :=
3883 (False => E_Procedure, True => E_Function);
3884 Is_Function : constant Boolean := (TSS_Nam = TSS_Stream_Input);
3889 if Ekind (Subp) /= Expected_Ekind (Is_Function) then
3893 F := First_Formal (Subp);
3896 or else Ekind (Etype (F)) /= E_Anonymous_Access_Type
3897 or else Designated_Type (Etype (F)) /=
3898 Class_Wide_Type (RTE (RE_Root_Stream_Type))
3903 if not Is_Function then
3907 Expected_Mode : constant array (Boolean) of Entity_Kind :=
3908 (False => E_In_Parameter,
3909 True => E_Out_Parameter);
3911 if Parameter_Mode (F) /= Expected_Mode (Is_Read) then
3918 -- If the attribute specification comes from an aspect
3919 -- specification for a class-wide stream, the parameter must be
3920 -- a class-wide type of the entity to which the aspect applies.
3922 if From_Aspect_Specification (N)
3923 and then Class_Present (Parent (N))
3924 and then Is_Class_Wide_Type (Typ)
3930 Typ := Etype (Subp);
3933 -- Verify that the prefix of the attribute and the local name for
3934 -- the type of the formal match, or one is the class-wide of the
3935 -- other, in the case of a class-wide stream operation.
3937 if Base_Type (Typ) = Base_Type (Ent)
3938 or else (Is_Class_Wide_Type (Typ)
3939 and then Typ = Class_Wide_Type (Base_Type (Ent)))
3940 or else (Is_Class_Wide_Type (Ent)
3941 and then Ent = Class_Wide_Type (Base_Type (Typ)))
3948 if Present (Next_Formal (F)) then
3951 elsif not Is_Scalar_Type (Typ)
3952 and then not Is_First_Subtype (Typ)
3953 and then not Is_Class_Wide_Type (Typ)
3955 if Report and not Is_First_Subtype (Typ) then
3957 ("subtype of formal in stream operation must be a first "
3958 & "subtype", Parameter_Type (Parent (F)));
3966 end Has_Good_Profile;
3968 -- Start of processing for Analyze_Stream_TSS_Definition
3973 if not Is_Type (U_Ent) then
3974 Error_Msg_N ("local name must be a subtype", Nam);
3977 elsif not Is_First_Subtype (U_Ent) then
3978 Error_Msg_N ("local name must be a first subtype", Nam);
3982 Pnam := TSS (Base_Type (U_Ent), TSS_Nam);
3984 -- If Pnam is present, it can be either inherited from an ancestor
3985 -- type (in which case it is legal to redefine it for this type), or
3986 -- be a previous definition of the attribute for the same type (in
3987 -- which case it is illegal).
3989 -- In the first case, it will have been analyzed already, and we
3990 -- can check that its profile does not match the expected profile
3991 -- for a stream attribute of U_Ent. In the second case, either Pnam
3992 -- has been analyzed (and has the expected profile), or it has not
3993 -- been analyzed yet (case of a type that has not been frozen yet
3994 -- and for which the stream attribute has been set using Set_TSS).
3997 and then (No (First_Entity (Pnam)) or else Has_Good_Profile (Pnam))
3999 Error_Msg_Sloc := Sloc (Pnam);
4000 Error_Msg_Name_1 := Attr;
4001 Error_Msg_N ("% attribute already defined #", Nam);
4007 if Is_Entity_Name (Expr) then
4008 if not Is_Overloaded (Expr) then
4009 if Has_Good_Profile (Entity (Expr), Report => True) then
4010 Subp := Entity (Expr);
4014 Get_First_Interp (Expr, I, It);
4015 while Present (It.Nam) loop
4016 if Has_Good_Profile (It.Nam) then
4021 Get_Next_Interp (I, It);
4026 if Present (Subp) then
4027 if Is_Abstract_Subprogram (Subp) then
4028 Error_Msg_N ("stream subprogram must not be abstract", Expr);
4031 -- A stream subprogram for an interface type must be a null
4032 -- procedure (RM 13.13.2 (38/3)). Note that the class-wide type
4033 -- of an interface is not an interface type (3.9.4 (6.b/2)).
4035 elsif Is_Interface (U_Ent)
4036 and then not Is_Class_Wide_Type (U_Ent)
4037 and then not Inside_A_Generic
4039 (Ekind (Subp) = E_Function
4043 (Unit_Declaration_Node (Ultimate_Alias (Subp)))))
4046 ("stream subprogram for interface type must be null "
4047 & "procedure", Expr);
4050 Set_Entity (Expr, Subp);
4051 Set_Etype (Expr, Etype (Subp));
4053 New_Stream_Subprogram (N, U_Ent, Subp, TSS_Nam);
4056 Error_Msg_Name_1 := Attr;
4057 Error_Msg_N ("incorrect expression for% attribute", Expr);
4059 end Analyze_Stream_TSS_Definition;
4061 ------------------------------
4062 -- Check_Indexing_Functions --
4063 ------------------------------
4065 procedure Check_Indexing_Functions is
4066 Indexing_Found : Boolean := False;
4068 procedure Check_Inherited_Indexing;
4069 -- For a derived type, check that no indexing aspect is specified
4070 -- for the type if it is also inherited
4072 procedure Check_One_Function (Subp : Entity_Id);
4073 -- Check one possible interpretation. Sets Indexing_Found True if a
4074 -- legal indexing function is found.
4076 procedure Illegal_Indexing (Msg : String);
4077 -- Diagnose illegal indexing function if not overloaded. In the
4078 -- overloaded case indicate that no legal interpretation exists.
4080 ------------------------------
4081 -- Check_Inherited_Indexing --
4082 ------------------------------
4084 procedure Check_Inherited_Indexing is
4085 Inherited : Node_Id;
4088 if Attr = Name_Constant_Indexing then
4090 Find_Aspect (Etype (Ent), Aspect_Constant_Indexing);
4091 else pragma Assert (Attr = Name_Variable_Indexing);
4093 Find_Aspect (Etype (Ent), Aspect_Variable_Indexing);
4096 if Present (Inherited) then
4097 if Debug_Flag_Dot_XX then
4100 -- OK if current attribute_definition_clause is expansion of
4101 -- inherited aspect.
4103 elsif Aspect_Rep_Item (Inherited) = N then
4106 -- Indicate the operation that must be overridden, rather than
4107 -- redefining the indexing aspect.
4111 ("indexing function already inherited from parent type");
4113 ("!override & instead",
4114 N, Entity (Expression (Inherited)));
4117 end Check_Inherited_Indexing;
4119 ------------------------
4120 -- Check_One_Function --
4121 ------------------------
4123 procedure Check_One_Function (Subp : Entity_Id) is
4124 Default_Element : Node_Id;
4125 Ret_Type : constant Entity_Id := Etype (Subp);
4128 if not Is_Overloadable (Subp) then
4129 Illegal_Indexing ("illegal indexing function for type&");
4132 elsif Scope (Subp) /= Scope (Ent) then
4133 if Nkind (Expr) = N_Expanded_Name then
4135 -- Indexing function can't be declared elsewhere
4138 ("indexing function must be declared in scope of type&");
4143 elsif No (First_Formal (Subp)) then
4145 ("Indexing requires a function that applies to type&");
4148 elsif No (Next_Formal (First_Formal (Subp))) then
4150 ("indexing function must have at least two parameters");
4153 elsif Is_Derived_Type (Ent) then
4154 Check_Inherited_Indexing;
4157 if not Check_Primitive_Function (Subp) then
4159 ("Indexing aspect requires a function that applies to type&");
4163 -- If partial declaration exists, verify that it is not tagged.
4165 if Ekind (Current_Scope) = E_Package
4166 and then Has_Private_Declaration (Ent)
4167 and then From_Aspect_Specification (N)
4169 List_Containing (Parent (Ent)) =
4170 Private_Declarations
4171 (Specification (Unit_Declaration_Node (Current_Scope)))
4172 and then Nkind (N) = N_Attribute_Definition_Clause
4179 First (Visible_Declarations
4181 (Unit_Declaration_Node (Current_Scope))));
4183 while Present (Decl) loop
4184 if Nkind (Decl) = N_Private_Type_Declaration
4185 and then Ent = Full_View (Defining_Identifier (Decl))
4186 and then Tagged_Present (Decl)
4187 and then No (Aspect_Specifications (Decl))
4190 ("Indexing aspect cannot be specified on full view "
4191 & "if partial view is tagged");
4200 -- An indexing function must return either the default element of
4201 -- the container, or a reference type. For variable indexing it
4202 -- must be the latter.
4205 Find_Value_Of_Aspect
4206 (Etype (First_Formal (Subp)), Aspect_Iterator_Element);
4208 if Present (Default_Element) then
4209 Analyze (Default_Element);
4211 if Is_Entity_Name (Default_Element)
4212 and then not Covers (Entity (Default_Element), Ret_Type)
4216 ("wrong return type for indexing function");
4221 -- For variable_indexing the return type must be a reference type
4223 if Attr = Name_Variable_Indexing then
4224 if not Has_Implicit_Dereference (Ret_Type) then
4226 ("variable indexing must return a reference type");
4229 elsif Is_Access_Constant
4230 (Etype (First_Discriminant (Ret_Type)))
4233 ("variable indexing must return an access to variable");
4238 if Has_Implicit_Dereference (Ret_Type)
4240 Is_Access_Constant (Etype (First_Discriminant (Ret_Type)))
4243 ("constant indexing must return an access to constant");
4246 elsif Is_Access_Type (Etype (First_Formal (Subp)))
4247 and then not Is_Access_Constant (Etype (First_Formal (Subp)))
4250 ("constant indexing must apply to an access to constant");
4255 -- All checks succeeded.
4257 Indexing_Found := True;
4258 end Check_One_Function;
4260 -----------------------
4261 -- Illegal_Indexing --
4262 -----------------------
4264 procedure Illegal_Indexing (Msg : String) is
4266 Error_Msg_NE (Msg, N, Ent);
4267 end Illegal_Indexing;
4269 -- Start of processing for Check_Indexing_Functions
4273 Check_Inherited_Indexing;
4278 if not Is_Overloaded (Expr) then
4279 Check_One_Function (Entity (Expr));
4287 Indexing_Found := False;
4288 Get_First_Interp (Expr, I, It);
4289 while Present (It.Nam) loop
4291 -- Note that analysis will have added the interpretation
4292 -- that corresponds to the dereference. We only check the
4293 -- subprogram itself.
4295 if Is_Overloadable (It.Nam) then
4296 Check_One_Function (It.Nam);
4299 Get_Next_Interp (I, It);
4304 if not Indexing_Found and then not Error_Posted (N) then
4306 ("aspect Indexing requires a local function that "
4307 & "applies to type&", Expr, Ent);
4309 end Check_Indexing_Functions;
4311 ------------------------------
4312 -- Check_Iterator_Functions --
4313 ------------------------------
4315 procedure Check_Iterator_Functions is
4316 function Valid_Default_Iterator (Subp : Entity_Id) return Boolean;
4317 -- Check one possible interpretation for validity
4319 ----------------------------
4320 -- Valid_Default_Iterator --
4321 ----------------------------
4323 function Valid_Default_Iterator (Subp : Entity_Id) return Boolean is
4324 Root_T : constant Entity_Id := Root_Type (Etype (Etype (Subp)));
4328 if not Check_Primitive_Function (Subp) then
4331 -- The return type must be derived from a type in an instance
4332 -- of Iterator.Interfaces, and thus its root type must have a
4335 elsif Chars (Root_T) /= Name_Forward_Iterator
4336 and then Chars (Root_T) /= Name_Reversible_Iterator
4341 Formal := First_Formal (Subp);
4344 -- False if any subsequent formal has no default expression
4346 Formal := Next_Formal (Formal);
4347 while Present (Formal) loop
4348 if No (Expression (Parent (Formal))) then
4352 Next_Formal (Formal);
4355 -- True if all subsequent formals have default expressions
4358 end Valid_Default_Iterator;
4360 -- Start of processing for Check_Iterator_Functions
4365 if not Is_Entity_Name (Expr) then
4366 Error_Msg_N ("aspect Iterator must be a function name", Expr);
4369 if not Is_Overloaded (Expr) then
4370 if not Check_Primitive_Function (Entity (Expr)) then
4372 ("aspect Indexing requires a function that applies to type&",
4373 Entity (Expr), Ent);
4376 -- Flag the default_iterator as well as the denoted function.
4378 if not Valid_Default_Iterator (Entity (Expr)) then
4379 Error_Msg_N ("improper function for default iterator!", Expr);
4384 Default : Entity_Id := Empty;
4389 Get_First_Interp (Expr, I, It);
4390 while Present (It.Nam) loop
4391 if not Check_Primitive_Function (It.Nam)
4392 or else not Valid_Default_Iterator (It.Nam)
4396 elsif Present (Default) then
4398 -- An explicit one should override an implicit one
4400 if Comes_From_Source (Default) =
4401 Comes_From_Source (It.Nam)
4403 Error_Msg_N ("default iterator must be unique", Expr);
4404 Error_Msg_Sloc := Sloc (Default);
4405 Error_Msg_N ("\\possible interpretation#", Expr);
4406 Error_Msg_Sloc := Sloc (It.Nam);
4407 Error_Msg_N ("\\possible interpretation#", Expr);
4409 elsif Comes_From_Source (It.Nam) then
4416 Get_Next_Interp (I, It);
4419 if Present (Default) then
4420 Set_Entity (Expr, Default);
4421 Set_Is_Overloaded (Expr, False);
4424 ("no interpretation is a valid default iterator!", Expr);
4428 end Check_Iterator_Functions;
4430 -------------------------------
4431 -- Check_Primitive_Function --
4432 -------------------------------
4434 function Check_Primitive_Function (Subp : Entity_Id) return Boolean is
4438 if Ekind (Subp) /= E_Function then
4442 if No (First_Formal (Subp)) then
4445 Ctrl := Etype (First_Formal (Subp));
4448 -- To be a primitive operation subprogram has to be in same scope.
4450 if Scope (Ctrl) /= Scope (Subp) then
4454 -- Type of formal may be the class-wide type, an access to such,
4455 -- or an incomplete view.
4458 or else Ctrl = Class_Wide_Type (Ent)
4460 (Ekind (Ctrl) = E_Anonymous_Access_Type
4461 and then (Designated_Type (Ctrl) = Ent
4463 Designated_Type (Ctrl) = Class_Wide_Type (Ent)))
4465 (Ekind (Ctrl) = E_Incomplete_Type
4466 and then Full_View (Ctrl) = Ent)
4474 end Check_Primitive_Function;
4476 ----------------------
4477 -- Duplicate_Clause --
4478 ----------------------
4480 function Duplicate_Clause return Boolean is
4484 -- Nothing to do if this attribute definition clause comes from
4485 -- an aspect specification, since we could not be duplicating an
4486 -- explicit clause, and we dealt with the case of duplicated aspects
4487 -- in Analyze_Aspect_Specifications.
4489 if From_Aspect_Specification (N) then
4493 -- Otherwise current clause may duplicate previous clause, or a
4494 -- previously given pragma or aspect specification for the same
4497 A := Get_Rep_Item (U_Ent, Chars (N), Check_Parents => False);
4500 Error_Msg_Name_1 := Chars (N);
4501 Error_Msg_Sloc := Sloc (A);
4503 Error_Msg_NE ("aspect% for & previously given#", N, U_Ent);
4508 end Duplicate_Clause;
4510 -- Start of processing for Analyze_Attribute_Definition_Clause
4513 -- The following code is a defense against recursion. Not clear that
4514 -- this can happen legitimately, but perhaps some error situations can
4515 -- cause it, and we did see this recursion during testing.
4517 if Analyzed (N) then
4520 Set_Analyzed (N, True);
4523 Check_Restriction_No_Use_Of_Attribute (N);
4525 -- Ignore some selected attributes in CodePeer mode since they are not
4526 -- relevant in this context.
4528 if CodePeer_Mode then
4531 -- Ignore Component_Size in CodePeer mode, to avoid changing the
4532 -- internal representation of types by implicitly packing them.
4534 when Attribute_Component_Size =>
4535 Rewrite (N, Make_Null_Statement (Sloc (N)));
4543 -- Process Ignore_Rep_Clauses option
4545 if Ignore_Rep_Clauses then
4548 -- The following should be ignored. They do not affect legality
4549 -- and may be target dependent. The basic idea of -gnatI is to
4550 -- ignore any rep clauses that may be target dependent but do not
4551 -- affect legality (except possibly to be rejected because they
4552 -- are incompatible with the compilation target).
4554 when Attribute_Alignment |
4555 Attribute_Bit_Order |
4556 Attribute_Component_Size |
4557 Attribute_Machine_Radix |
4558 Attribute_Object_Size |
4561 Attribute_Stream_Size |
4562 Attribute_Value_Size =>
4563 Kill_Rep_Clause (N);
4566 -- The following should not be ignored, because in the first place
4567 -- they are reasonably portable, and should not cause problems
4568 -- in compiling code from another target, and also they do affect
4569 -- legality, e.g. failing to provide a stream attribute for a type
4570 -- may make a program illegal.
4572 when Attribute_External_Tag |
4576 Attribute_Simple_Storage_Pool |
4577 Attribute_Storage_Pool |
4578 Attribute_Storage_Size |
4582 -- We do not do anything here with address clauses, they will be
4583 -- removed by Freeze later on, but for now, it works better to
4584 -- keep then in the tree.
4586 when Attribute_Address =>
4589 -- Other cases are errors ("attribute& cannot be set with
4590 -- definition clause"), which will be caught below.
4598 Ent := Entity (Nam);
4600 if Rep_Item_Too_Early (Ent, N) then
4604 -- Rep clause applies to full view of incomplete type or private type if
4605 -- we have one (if not, this is a premature use of the type). However,
4606 -- certain semantic checks need to be done on the specified entity (i.e.
4607 -- the private view), so we save it in Ent.
4609 if Is_Private_Type (Ent)
4610 and then Is_Derived_Type (Ent)
4611 and then not Is_Tagged_Type (Ent)
4612 and then No (Full_View (Ent))
4614 -- If this is a private type whose completion is a derivation from
4615 -- another private type, there is no full view, and the attribute
4616 -- belongs to the type itself, not its underlying parent.
4620 elsif Ekind (Ent) = E_Incomplete_Type then
4622 -- The attribute applies to the full view, set the entity of the
4623 -- attribute definition accordingly.
4625 Ent := Underlying_Type (Ent);
4627 Set_Entity (Nam, Ent);
4630 U_Ent := Underlying_Type (Ent);
4633 -- Avoid cascaded error
4635 if Etype (Nam) = Any_Type then
4638 -- Must be declared in current scope or in case of an aspect
4639 -- specification, must be visible in current scope.
4641 elsif Scope (Ent) /= Current_Scope
4643 not (From_Aspect_Specification (N)
4644 and then Scope_Within_Or_Same (Current_Scope, Scope (Ent)))
4646 Error_Msg_N ("entity must be declared in this scope", Nam);
4649 -- Must not be a source renaming (we do have some cases where the
4650 -- expander generates a renaming, and those cases are OK, in such
4651 -- cases any attribute applies to the renamed object as well).
4653 elsif Is_Object (Ent)
4654 and then Present (Renamed_Object (Ent))
4656 -- Case of renamed object from source, this is an error
4658 if Comes_From_Source (Renamed_Object (Ent)) then
4659 Get_Name_String (Chars (N));
4660 Error_Msg_Strlen := Name_Len;
4661 Error_Msg_String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len);
4663 ("~ clause not allowed for a renaming declaration "
4664 & "(RM 13.1(6))", Nam);
4667 -- For the case of a compiler generated renaming, the attribute
4668 -- definition clause applies to the renamed object created by the
4669 -- expander. The easiest general way to handle this is to create a
4670 -- copy of the attribute definition clause for this object.
4672 elsif Is_Entity_Name (Renamed_Object (Ent)) then
4674 Make_Attribute_Definition_Clause (Loc,
4676 New_Occurrence_Of (Entity (Renamed_Object (Ent)), Loc),
4678 Expression => Duplicate_Subexpr (Expression (N))));
4680 -- If the renamed object is not an entity, it must be a dereference
4681 -- of an unconstrained function call, and we must introduce a new
4682 -- declaration to capture the expression. This is needed in the case
4683 -- of 'Alignment, where the original declaration must be rewritten.
4687 (Nkind (Renamed_Object (Ent)) = N_Explicit_Dereference);
4691 -- If no underlying entity, use entity itself, applies to some
4692 -- previously detected error cases ???
4694 elsif No (U_Ent) then
4697 -- Cannot specify for a subtype (exception Object/Value_Size)
4699 elsif Is_Type (U_Ent)
4700 and then not Is_First_Subtype (U_Ent)
4701 and then Id /= Attribute_Object_Size
4702 and then Id /= Attribute_Value_Size
4703 and then not From_At_Mod (N)
4705 Error_Msg_N ("cannot specify attribute for subtype", Nam);
4709 Set_Entity (N, U_Ent);
4711 -- Switch on particular attribute
4719 -- Address attribute definition clause
4721 when Attribute_Address => Address : begin
4723 -- A little error check, catch for X'Address use X'Address;
4725 if Nkind (Nam) = N_Identifier
4726 and then Nkind (Expr) = N_Attribute_Reference
4727 and then Attribute_Name (Expr) = Name_Address
4728 and then Nkind (Prefix (Expr)) = N_Identifier
4729 and then Chars (Nam) = Chars (Prefix (Expr))
4732 ("address for & is self-referencing", Prefix (Expr), Ent);
4736 -- Not that special case, carry on with analysis of expression
4738 Analyze_And_Resolve (Expr, RTE (RE_Address));
4740 -- Even when ignoring rep clauses we need to indicate that the
4741 -- entity has an address clause and thus it is legal to declare
4742 -- it imported. Freeze will get rid of the address clause later.
4744 if Ignore_Rep_Clauses then
4745 if Ekind_In (U_Ent, E_Variable, E_Constant) then
4746 Record_Rep_Item (U_Ent, N);
4752 if Duplicate_Clause then
4755 -- Case of address clause for subprogram
4757 elsif Is_Subprogram (U_Ent) then
4758 if Has_Homonym (U_Ent) then
4760 ("address clause cannot be given for overloaded "
4761 & "subprogram", Nam);
4765 -- For subprograms, all address clauses are permitted, and we
4766 -- mark the subprogram as having a deferred freeze so that Gigi
4767 -- will not elaborate it too soon.
4769 -- Above needs more comments, what is too soon about???
4771 Set_Has_Delayed_Freeze (U_Ent);
4773 -- Case of address clause for entry
4775 elsif Ekind (U_Ent) = E_Entry then
4776 if Nkind (Parent (N)) = N_Task_Body then
4778 ("entry address must be specified in task spec", Nam);
4782 -- For entries, we require a constant address
4784 Check_Constant_Address_Clause (Expr, U_Ent);
4786 -- Special checks for task types
4788 if Is_Task_Type (Scope (U_Ent))
4789 and then Comes_From_Source (Scope (U_Ent))
4792 ("??entry address declared for entry in task type", N);
4794 ("\??only one task can be declared of this type", N);
4797 -- Entry address clauses are obsolescent
4799 Check_Restriction (No_Obsolescent_Features, N);
4801 if Warn_On_Obsolescent_Feature then
4803 ("?j?attaching interrupt to task entry is an obsolescent "
4804 & "feature (RM J.7.1)", N);
4806 ("\?j?use interrupt procedure instead", N);
4809 -- Case of an address clause for a controlled object which we
4810 -- consider to be erroneous.
4812 elsif Is_Controlled (Etype (U_Ent))
4813 or else Has_Controlled_Component (Etype (U_Ent))
4816 ("??controlled object& must not be overlaid", Nam, U_Ent);
4818 ("\??Program_Error will be raised at run time", Nam);
4819 Insert_Action (Declaration_Node (U_Ent),
4820 Make_Raise_Program_Error (Loc,
4821 Reason => PE_Overlaid_Controlled_Object));
4824 -- Case of address clause for a (non-controlled) object
4826 elsif Ekind_In (U_Ent, E_Variable, E_Constant) then
4828 Expr : constant Node_Id := Expression (N);
4833 -- Exported variables cannot have an address clause, because
4834 -- this cancels the effect of the pragma Export.
4836 if Is_Exported (U_Ent) then
4838 ("cannot export object with address clause", Nam);
4842 Find_Overlaid_Entity (N, O_Ent, Off);
4844 if Present (O_Ent) then
4846 -- If the object overlays a constant object, mark it so
4848 if Is_Constant_Object (O_Ent) then
4849 Set_Overlays_Constant (U_Ent);
4853 -- If this is not an overlay, mark a variable as being
4854 -- volatile to prevent unwanted optimizations. It's a
4855 -- conservative interpretation of RM 13.3(19) for the
4856 -- cases where the compiler cannot detect potential
4857 -- aliasing issues easily and it also covers the case
4858 -- of an absolute address where the volatile aspect is
4859 -- kind of implicit.
4861 if Ekind (U_Ent) = E_Variable then
4862 Set_Treat_As_Volatile (U_Ent);
4866 -- Overlaying controlled objects is erroneous. Emit warning
4867 -- but continue analysis because program is itself legal,
4868 -- and back end must see address clause.
4871 and then (Has_Controlled_Component (Etype (O_Ent))
4872 or else Is_Controlled (Etype (O_Ent)))
4873 and then not Inside_A_Generic
4876 ("??cannot use overlays with controlled objects", Expr);
4878 ("\??Program_Error will be raised at run time", Expr);
4879 Insert_Action (Declaration_Node (U_Ent),
4880 Make_Raise_Program_Error (Loc,
4881 Reason => PE_Overlaid_Controlled_Object));
4883 -- Issue an unconditional warning for a constant overlaying
4884 -- a variable. For the reverse case, we will issue it only
4885 -- if the variable is modified.
4887 elsif Ekind (U_Ent) = E_Constant
4888 and then Present (O_Ent)
4889 and then not Overlays_Constant (U_Ent)
4890 and then Address_Clause_Overlay_Warnings
4892 Error_Msg_N ("??constant overlays a variable", Expr);
4894 -- Imported variables can have an address clause, but then
4895 -- the import is pretty meaningless except to suppress
4896 -- initializations, so we do not need such variables to
4897 -- be statically allocated (and in fact it causes trouble
4898 -- if the address clause is a local value).
4900 elsif Is_Imported (U_Ent) then
4901 Set_Is_Statically_Allocated (U_Ent, False);
4904 -- We mark a possible modification of a variable with an
4905 -- address clause, since it is likely aliasing is occurring.
4907 Note_Possible_Modification (Nam, Sure => False);
4909 -- Legality checks on the address clause for initialized
4910 -- objects is deferred until the freeze point, because
4911 -- a subsequent pragma might indicate that the object
4912 -- is imported and thus not initialized. Also, the address
4913 -- clause might involve entities that have yet to be
4916 Set_Has_Delayed_Freeze (U_Ent);
4918 -- If an initialization call has been generated for this
4919 -- object, it needs to be deferred to after the freeze node
4920 -- we have just now added, otherwise GIGI will see a
4921 -- reference to the variable (as actual to the IP call)
4922 -- before its definition.
4925 Init_Call : constant Node_Id :=
4926 Remove_Init_Call (U_Ent, N);
4929 if Present (Init_Call) then
4930 Append_Freeze_Action (U_Ent, Init_Call);
4932 -- Reset Initialization_Statements pointer so that
4933 -- if there is a pragma Import further down, it can
4934 -- clear any default initialization.
4936 Set_Initialization_Statements (U_Ent, Init_Call);
4940 -- Entity has delayed freeze, so we will generate an
4941 -- alignment check at the freeze point unless suppressed.
4943 if not Range_Checks_Suppressed (U_Ent)
4944 and then not Alignment_Checks_Suppressed (U_Ent)
4946 Set_Check_Address_Alignment (N);
4949 -- Kill the size check code, since we are not allocating
4950 -- the variable, it is somewhere else.
4952 Kill_Size_Check_Code (U_Ent);
4954 -- If the address clause is of the form:
4956 -- for Y'Address use X'Address
4960 -- Const : constant Address := X'Address;
4962 -- for Y'Address use Const;
4964 -- then we make an entry in the table for checking the size
4965 -- and alignment of the overlaying variable. We defer this
4966 -- check till after code generation to take full advantage
4967 -- of the annotation done by the back end.
4969 -- If the entity has a generic type, the check will be
4970 -- performed in the instance if the actual type justifies
4971 -- it, and we do not insert the clause in the table to
4972 -- prevent spurious warnings.
4974 -- Note: we used to test Comes_From_Source and only give
4975 -- this warning for source entities, but we have removed
4976 -- this test. It really seems bogus to generate overlays
4977 -- that would trigger this warning in generated code.
4978 -- Furthermore, by removing the test, we handle the
4979 -- aspect case properly.
4982 and then Is_Object (O_Ent)
4983 and then not Is_Generic_Type (Etype (U_Ent))
4984 and then Address_Clause_Overlay_Warnings
4986 Address_Clause_Checks.Append ((N, U_Ent, O_Ent, Off));
4990 -- Not a valid entity for an address clause
4993 Error_Msg_N ("address cannot be given for &", Nam);
5001 -- Alignment attribute definition clause
5003 when Attribute_Alignment => Alignment : declare
5004 Align : constant Uint := Get_Alignment_Value (Expr);
5005 Max_Align : constant Uint := UI_From_Int (Maximum_Alignment);
5010 if not Is_Type (U_Ent)
5011 and then Ekind (U_Ent) /= E_Variable
5012 and then Ekind (U_Ent) /= E_Constant
5014 Error_Msg_N ("alignment cannot be given for &", Nam);
5016 elsif Duplicate_Clause then
5019 elsif Align /= No_Uint then
5020 Set_Has_Alignment_Clause (U_Ent);
5022 -- Tagged type case, check for attempt to set alignment to a
5023 -- value greater than Max_Align, and reset if so. This error
5024 -- is suppressed in ASIS mode to allow for different ASIS
5025 -- back ends or ASIS-based tools to query the illegal clause.
5027 if Is_Tagged_Type (U_Ent)
5028 and then Align > Max_Align
5029 and then not ASIS_Mode
5032 ("alignment for & set to Maximum_Aligment??", Nam);
5033 Set_Alignment (U_Ent, Max_Align);
5038 Set_Alignment (U_Ent, Align);
5041 -- For an array type, U_Ent is the first subtype. In that case,
5042 -- also set the alignment of the anonymous base type so that
5043 -- other subtypes (such as the itypes for aggregates of the
5044 -- type) also receive the expected alignment.
5046 if Is_Array_Type (U_Ent) then
5047 Set_Alignment (Base_Type (U_Ent), Align);
5056 -- Bit_Order attribute definition clause
5058 when Attribute_Bit_Order => Bit_Order : declare
5060 if not Is_Record_Type (U_Ent) then
5062 ("Bit_Order can only be defined for record type", Nam);
5064 elsif Duplicate_Clause then
5068 Analyze_And_Resolve (Expr, RTE (RE_Bit_Order));
5070 if Etype (Expr) = Any_Type then
5073 elsif not Is_OK_Static_Expression (Expr) then
5074 Flag_Non_Static_Expr
5075 ("Bit_Order requires static expression!", Expr);
5078 if (Expr_Value (Expr) = 0) /= Bytes_Big_Endian then
5079 Set_Reverse_Bit_Order (Base_Type (U_Ent), True);
5085 --------------------
5086 -- Component_Size --
5087 --------------------
5089 -- Component_Size attribute definition clause
5091 when Attribute_Component_Size => Component_Size_Case : declare
5092 Csize : constant Uint := Static_Integer (Expr);
5096 New_Ctyp : Entity_Id;
5100 if not Is_Array_Type (U_Ent) then
5101 Error_Msg_N ("component size requires array type", Nam);
5105 Btype := Base_Type (U_Ent);
5106 Ctyp := Component_Type (Btype);
5108 if Duplicate_Clause then
5111 elsif Rep_Item_Too_Early (Btype, N) then
5114 elsif Csize /= No_Uint then
5115 Check_Size (Expr, Ctyp, Csize, Biased);
5117 -- For the biased case, build a declaration for a subtype that
5118 -- will be used to represent the biased subtype that reflects
5119 -- the biased representation of components. We need the subtype
5120 -- to get proper conversions on referencing elements of the
5125 Make_Defining_Identifier (Loc,
5127 New_External_Name (Chars (U_Ent), 'C', 0, 'T'));
5130 Make_Subtype_Declaration (Loc,
5131 Defining_Identifier => New_Ctyp,
5132 Subtype_Indication =>
5133 New_Occurrence_Of (Component_Type (Btype), Loc));
5135 Set_Parent (Decl, N);
5136 Analyze (Decl, Suppress => All_Checks);
5138 Set_Has_Delayed_Freeze (New_Ctyp, False);
5139 Set_Esize (New_Ctyp, Csize);
5140 Set_RM_Size (New_Ctyp, Csize);
5141 Init_Alignment (New_Ctyp);
5142 Set_Is_Itype (New_Ctyp, True);
5143 Set_Associated_Node_For_Itype (New_Ctyp, U_Ent);
5145 Set_Component_Type (Btype, New_Ctyp);
5146 Set_Biased (New_Ctyp, N, "component size clause");
5149 Set_Component_Size (Btype, Csize);
5151 -- Deal with warning on overridden size
5153 if Warn_On_Overridden_Size
5154 and then Has_Size_Clause (Ctyp)
5155 and then RM_Size (Ctyp) /= Csize
5158 ("component size overrides size clause for&?S?", N, Ctyp);
5161 Set_Has_Component_Size_Clause (Btype, True);
5162 Set_Has_Non_Standard_Rep (Btype, True);
5164 end Component_Size_Case;
5166 -----------------------
5167 -- Constant_Indexing --
5168 -----------------------
5170 when Attribute_Constant_Indexing =>
5171 Check_Indexing_Functions;
5177 when Attribute_CPU => CPU :
5179 -- CPU attribute definition clause not allowed except from aspect
5182 if From_Aspect_Specification (N) then
5183 if not Is_Task_Type (U_Ent) then
5184 Error_Msg_N ("CPU can only be defined for task", Nam);
5186 elsif Duplicate_Clause then
5190 -- The expression must be analyzed in the special manner
5191 -- described in "Handling of Default and Per-Object
5192 -- Expressions" in sem.ads.
5194 -- The visibility to the discriminants must be restored
5196 Push_Scope_And_Install_Discriminants (U_Ent);
5197 Preanalyze_Spec_Expression (Expr, RTE (RE_CPU_Range));
5198 Uninstall_Discriminants_And_Pop_Scope (U_Ent);
5200 if not Is_OK_Static_Expression (Expr) then
5201 Check_Restriction (Static_Priorities, Expr);
5207 ("attribute& cannot be set with definition clause", N);
5211 ----------------------
5212 -- Default_Iterator --
5213 ----------------------
5215 when Attribute_Default_Iterator => Default_Iterator : declare
5220 -- If target type is untagged, further checks are irrelevant
5222 if not Is_Tagged_Type (U_Ent) then
5224 ("aspect Default_Iterator applies to tagged type", Nam);
5228 Check_Iterator_Functions;
5232 if not Is_Entity_Name (Expr)
5233 or else Ekind (Entity (Expr)) /= E_Function
5235 Error_Msg_N ("aspect Iterator must be a function", Expr);
5238 Func := Entity (Expr);
5241 -- The type of the first parameter must be T, T'class, or a
5242 -- corresponding access type (5.5.1 (8/3). If function is
5243 -- parameterless label type accordingly.
5245 if No (First_Formal (Func)) then
5248 Typ := Etype (First_Formal (Func));
5252 or else Typ = Class_Wide_Type (U_Ent)
5253 or else (Is_Access_Type (Typ)
5254 and then Designated_Type (Typ) = U_Ent)
5255 or else (Is_Access_Type (Typ)
5256 and then Designated_Type (Typ) =
5257 Class_Wide_Type (U_Ent))
5263 ("Default Iterator must be a primitive of&", Func, U_Ent);
5265 end Default_Iterator;
5267 ------------------------
5268 -- Dispatching_Domain --
5269 ------------------------
5271 when Attribute_Dispatching_Domain => Dispatching_Domain :
5273 -- Dispatching_Domain attribute definition clause not allowed
5274 -- except from aspect specification.
5276 if From_Aspect_Specification (N) then
5277 if not Is_Task_Type (U_Ent) then
5279 ("Dispatching_Domain can only be defined for task", Nam);
5281 elsif Duplicate_Clause then
5285 -- The expression must be analyzed in the special manner
5286 -- described in "Handling of Default and Per-Object
5287 -- Expressions" in sem.ads.
5289 -- The visibility to the discriminants must be restored
5291 Push_Scope_And_Install_Discriminants (U_Ent);
5293 Preanalyze_Spec_Expression
5294 (Expr, RTE (RE_Dispatching_Domain));
5296 Uninstall_Discriminants_And_Pop_Scope (U_Ent);
5301 ("attribute& cannot be set with definition clause", N);
5303 end Dispatching_Domain;
5309 when Attribute_External_Tag => External_Tag :
5311 if not Is_Tagged_Type (U_Ent) then
5312 Error_Msg_N ("should be a tagged type", Nam);
5315 if Duplicate_Clause then
5319 Analyze_And_Resolve (Expr, Standard_String);
5321 if not Is_OK_Static_Expression (Expr) then
5322 Flag_Non_Static_Expr
5323 ("static string required for tag name!", Nam);
5326 if not Is_Library_Level_Entity (U_Ent) then
5328 ("??non-unique external tag supplied for &", N, U_Ent);
5330 ("\??same external tag applies to all subprogram calls",
5333 ("\??corresponding internal tag cannot be obtained", N);
5338 --------------------------
5339 -- Implicit_Dereference --
5340 --------------------------
5342 when Attribute_Implicit_Dereference =>
5344 -- Legality checks already performed at the point of the type
5345 -- declaration, aspect is not delayed.
5353 when Attribute_Input =>
5354 Analyze_Stream_TSS_Definition (TSS_Stream_Input);
5355 Set_Has_Specified_Stream_Input (Ent);
5357 ------------------------
5358 -- Interrupt_Priority --
5359 ------------------------
5361 when Attribute_Interrupt_Priority => Interrupt_Priority :
5363 -- Interrupt_Priority attribute definition clause not allowed
5364 -- except from aspect specification.
5366 if From_Aspect_Specification (N) then
5367 if not Is_Concurrent_Type (U_Ent) then
5369 ("Interrupt_Priority can only be defined for task and "
5370 & "protected object", Nam);
5372 elsif Duplicate_Clause then
5376 -- The expression must be analyzed in the special manner
5377 -- described in "Handling of Default and Per-Object
5378 -- Expressions" in sem.ads.
5380 -- The visibility to the discriminants must be restored
5382 Push_Scope_And_Install_Discriminants (U_Ent);
5384 Preanalyze_Spec_Expression
5385 (Expr, RTE (RE_Interrupt_Priority));
5387 Uninstall_Discriminants_And_Pop_Scope (U_Ent);
5389 -- Check the No_Task_At_Interrupt_Priority restriction
5391 if Is_Task_Type (U_Ent) then
5392 Check_Restriction (No_Task_At_Interrupt_Priority, N);
5398 ("attribute& cannot be set with definition clause", N);
5400 end Interrupt_Priority;
5406 when Attribute_Iterable =>
5409 if Nkind (Expr) /= N_Aggregate then
5410 Error_Msg_N ("aspect Iterable must be an aggregate", Expr);
5417 Assoc := First (Component_Associations (Expr));
5418 while Present (Assoc) loop
5419 if not Is_Entity_Name (Expression (Assoc)) then
5420 Error_Msg_N ("value must be a function", Assoc);
5427 ----------------------
5428 -- Iterator_Element --
5429 ----------------------
5431 when Attribute_Iterator_Element =>
5434 if not Is_Entity_Name (Expr)
5435 or else not Is_Type (Entity (Expr))
5437 Error_Msg_N ("aspect Iterator_Element must be a type", Expr);
5444 -- Machine radix attribute definition clause
5446 when Attribute_Machine_Radix => Machine_Radix : declare
5447 Radix : constant Uint := Static_Integer (Expr);
5450 if not Is_Decimal_Fixed_Point_Type (U_Ent) then
5451 Error_Msg_N ("decimal fixed-point type expected for &", Nam);
5453 elsif Duplicate_Clause then
5456 elsif Radix /= No_Uint then
5457 Set_Has_Machine_Radix_Clause (U_Ent);
5458 Set_Has_Non_Standard_Rep (Base_Type (U_Ent));
5463 elsif Radix = 10 then
5464 Set_Machine_Radix_10 (U_Ent);
5466 -- The following error is suppressed in ASIS mode to allow for
5467 -- different ASIS back ends or ASIS-based tools to query the
5470 elsif not ASIS_Mode then
5471 Error_Msg_N ("machine radix value must be 2 or 10", Expr);
5480 -- Object_Size attribute definition clause
5482 when Attribute_Object_Size => Object_Size : declare
5483 Size : constant Uint := Static_Integer (Expr);
5486 pragma Warnings (Off, Biased);
5489 if not Is_Type (U_Ent) then
5490 Error_Msg_N ("Object_Size cannot be given for &", Nam);
5492 elsif Duplicate_Clause then
5496 Check_Size (Expr, U_Ent, Size, Biased);
5498 -- The following errors are suppressed in ASIS mode to allow
5499 -- for different ASIS back ends or ASIS-based tools to query
5500 -- the illegal clause.
5505 elsif Is_Scalar_Type (U_Ent) then
5506 if Size /= 8 and then Size /= 16 and then Size /= 32
5507 and then UI_Mod (Size, 64) /= 0
5510 ("Object_Size must be 8, 16, 32, or multiple of 64",
5514 elsif Size mod 8 /= 0 then
5515 Error_Msg_N ("Object_Size must be a multiple of 8", Expr);
5518 Set_Esize (U_Ent, Size);
5519 Set_Has_Object_Size_Clause (U_Ent);
5520 Alignment_Check_For_Size_Change (U_Ent, Size);
5528 when Attribute_Output =>
5529 Analyze_Stream_TSS_Definition (TSS_Stream_Output);
5530 Set_Has_Specified_Stream_Output (Ent);
5536 when Attribute_Priority => Priority :
5538 -- Priority attribute definition clause not allowed except from
5539 -- aspect specification.
5541 if From_Aspect_Specification (N) then
5542 if not (Is_Concurrent_Type (U_Ent)
5543 or else Ekind (U_Ent) = E_Procedure)
5546 ("Priority can only be defined for task and protected "
5549 elsif Duplicate_Clause then
5553 -- The expression must be analyzed in the special manner
5554 -- described in "Handling of Default and Per-Object
5555 -- Expressions" in sem.ads.
5557 -- The visibility to the discriminants must be restored
5559 Push_Scope_And_Install_Discriminants (U_Ent);
5560 Preanalyze_Spec_Expression (Expr, Standard_Integer);
5561 Uninstall_Discriminants_And_Pop_Scope (U_Ent);
5563 if not Is_OK_Static_Expression (Expr) then
5564 Check_Restriction (Static_Priorities, Expr);
5570 ("attribute& cannot be set with definition clause", N);
5578 when Attribute_Read =>
5579 Analyze_Stream_TSS_Definition (TSS_Stream_Read);
5580 Set_Has_Specified_Stream_Read (Ent);
5582 --------------------------
5583 -- Scalar_Storage_Order --
5584 --------------------------
5586 -- Scalar_Storage_Order attribute definition clause
5588 when Attribute_Scalar_Storage_Order => Scalar_Storage_Order : declare
5590 if not (Is_Record_Type (U_Ent) or else Is_Array_Type (U_Ent)) then
5592 ("Scalar_Storage_Order can only be defined for record or "
5593 & "array type", Nam);
5595 elsif Duplicate_Clause then
5599 Analyze_And_Resolve (Expr, RTE (RE_Bit_Order));
5601 if Etype (Expr) = Any_Type then
5604 elsif not Is_OK_Static_Expression (Expr) then
5605 Flag_Non_Static_Expr
5606 ("Scalar_Storage_Order requires static expression!", Expr);
5608 elsif (Expr_Value (Expr) = 0) /= Bytes_Big_Endian then
5610 -- Here for the case of a non-default (i.e. non-confirming)
5611 -- Scalar_Storage_Order attribute definition.
5613 if Support_Nondefault_SSO_On_Target then
5614 Set_Reverse_Storage_Order (Base_Type (U_Ent), True);
5617 ("non-default Scalar_Storage_Order not supported on "
5622 -- Clear SSO default indications since explicit setting of the
5623 -- order overrides the defaults.
5625 Set_SSO_Set_Low_By_Default (Base_Type (U_Ent), False);
5626 Set_SSO_Set_High_By_Default (Base_Type (U_Ent), False);
5628 end Scalar_Storage_Order;
5634 -- Size attribute definition clause
5636 when Attribute_Size => Size : declare
5637 Size : constant Uint := Static_Integer (Expr);
5644 if Duplicate_Clause then
5647 elsif not Is_Type (U_Ent)
5648 and then Ekind (U_Ent) /= E_Variable
5649 and then Ekind (U_Ent) /= E_Constant
5651 Error_Msg_N ("size cannot be given for &", Nam);
5653 elsif Is_Array_Type (U_Ent)
5654 and then not Is_Constrained (U_Ent)
5657 ("size cannot be given for unconstrained array", Nam);
5659 elsif Size /= No_Uint then
5660 if Is_Type (U_Ent) then
5663 Etyp := Etype (U_Ent);
5666 -- Check size, note that Gigi is in charge of checking that the
5667 -- size of an array or record type is OK. Also we do not check
5668 -- the size in the ordinary fixed-point case, since it is too
5669 -- early to do so (there may be subsequent small clause that
5670 -- affects the size). We can check the size if a small clause
5671 -- has already been given.
5673 if not Is_Ordinary_Fixed_Point_Type (U_Ent)
5674 or else Has_Small_Clause (U_Ent)
5676 Check_Size (Expr, Etyp, Size, Biased);
5677 Set_Biased (U_Ent, N, "size clause", Biased);
5680 -- For types set RM_Size and Esize if possible
5682 if Is_Type (U_Ent) then
5683 Set_RM_Size (U_Ent, Size);
5685 -- For elementary types, increase Object_Size to power of 2,
5686 -- but not less than a storage unit in any case (normally
5687 -- this means it will be byte addressable).
5689 -- For all other types, nothing else to do, we leave Esize
5690 -- (object size) unset, the back end will set it from the
5691 -- size and alignment in an appropriate manner.
5693 -- In both cases, we check whether the alignment must be
5694 -- reset in the wake of the size change.
5696 if Is_Elementary_Type (U_Ent) then
5697 if Size <= System_Storage_Unit then
5698 Init_Esize (U_Ent, System_Storage_Unit);
5699 elsif Size <= 16 then
5700 Init_Esize (U_Ent, 16);
5701 elsif Size <= 32 then
5702 Init_Esize (U_Ent, 32);
5704 Set_Esize (U_Ent, (Size + 63) / 64 * 64);
5707 Alignment_Check_For_Size_Change (U_Ent, Esize (U_Ent));
5709 Alignment_Check_For_Size_Change (U_Ent, Size);
5712 -- For objects, set Esize only
5715 -- The following error is suppressed in ASIS mode to allow
5716 -- for different ASIS back ends or ASIS-based tools to query
5717 -- the illegal clause.
5719 if Is_Elementary_Type (Etyp)
5720 and then Size /= System_Storage_Unit
5721 and then Size /= System_Storage_Unit * 2
5722 and then Size /= System_Storage_Unit * 4
5723 and then Size /= System_Storage_Unit * 8
5724 and then not ASIS_Mode
5726 Error_Msg_Uint_1 := UI_From_Int (System_Storage_Unit);
5727 Error_Msg_Uint_2 := Error_Msg_Uint_1 * 8;
5729 ("size for primitive object must be a power of 2 in "
5730 & "the range ^-^", N);
5733 Set_Esize (U_Ent, Size);
5736 Set_Has_Size_Clause (U_Ent);
5744 -- Small attribute definition clause
5746 when Attribute_Small => Small : declare
5747 Implicit_Base : constant Entity_Id := Base_Type (U_Ent);
5751 Analyze_And_Resolve (Expr, Any_Real);
5753 if Etype (Expr) = Any_Type then
5756 elsif not Is_OK_Static_Expression (Expr) then
5757 Flag_Non_Static_Expr
5758 ("small requires static expression!", Expr);
5762 Small := Expr_Value_R (Expr);
5764 if Small <= Ureal_0 then
5765 Error_Msg_N ("small value must be greater than zero", Expr);
5771 if not Is_Ordinary_Fixed_Point_Type (U_Ent) then
5773 ("small requires an ordinary fixed point type", Nam);
5775 elsif Has_Small_Clause (U_Ent) then
5776 Error_Msg_N ("small already given for &", Nam);
5778 elsif Small > Delta_Value (U_Ent) then
5780 ("small value must not be greater than delta value", Nam);
5783 Set_Small_Value (U_Ent, Small);
5784 Set_Small_Value (Implicit_Base, Small);
5785 Set_Has_Small_Clause (U_Ent);
5786 Set_Has_Small_Clause (Implicit_Base);
5787 Set_Has_Non_Standard_Rep (Implicit_Base);
5795 -- Storage_Pool attribute definition clause
5797 when Attribute_Storage_Pool | Attribute_Simple_Storage_Pool => declare
5802 if Ekind (U_Ent) = E_Access_Subprogram_Type then
5804 ("storage pool cannot be given for access-to-subprogram type",
5809 Ekind_In (U_Ent, E_Access_Type, E_General_Access_Type)
5812 ("storage pool can only be given for access types", Nam);
5815 elsif Is_Derived_Type (U_Ent) then
5817 ("storage pool cannot be given for a derived access type",
5820 elsif Duplicate_Clause then
5823 elsif Present (Associated_Storage_Pool (U_Ent)) then
5824 Error_Msg_N ("storage pool already given for &", Nam);
5828 -- Check for Storage_Size previously given
5831 SS : constant Node_Id :=
5832 Get_Attribute_Definition_Clause
5833 (U_Ent, Attribute_Storage_Size);
5835 if Present (SS) then
5836 Check_Pool_Size_Clash (U_Ent, N, SS);
5840 -- Storage_Pool case
5842 if Id = Attribute_Storage_Pool then
5844 (Expr, Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
5846 -- In the Simple_Storage_Pool case, we allow a variable of any
5847 -- simple storage pool type, so we Resolve without imposing an
5851 Analyze_And_Resolve (Expr);
5853 if not Present (Get_Rep_Pragma
5854 (Etype (Expr), Name_Simple_Storage_Pool_Type))
5857 ("expression must be of a simple storage pool type", Expr);
5861 if not Denotes_Variable (Expr) then
5862 Error_Msg_N ("storage pool must be a variable", Expr);
5866 if Nkind (Expr) = N_Type_Conversion then
5867 T := Etype (Expression (Expr));
5872 -- The Stack_Bounded_Pool is used internally for implementing
5873 -- access types with a Storage_Size. Since it only work properly
5874 -- when used on one specific type, we need to check that it is not
5875 -- hijacked improperly:
5877 -- type T is access Integer;
5878 -- for T'Storage_Size use n;
5879 -- type Q is access Float;
5880 -- for Q'Storage_Size use T'Storage_Size; -- incorrect
5882 if RTE_Available (RE_Stack_Bounded_Pool)
5883 and then Base_Type (T) = RTE (RE_Stack_Bounded_Pool)
5885 Error_Msg_N ("non-shareable internal Pool", Expr);
5889 -- If the argument is a name that is not an entity name, then
5890 -- we construct a renaming operation to define an entity of
5891 -- type storage pool.
5893 if not Is_Entity_Name (Expr)
5894 and then Is_Object_Reference (Expr)
5896 Pool := Make_Temporary (Loc, 'P', Expr);
5899 Rnode : constant Node_Id :=
5900 Make_Object_Renaming_Declaration (Loc,
5901 Defining_Identifier => Pool,
5903 New_Occurrence_Of (Etype (Expr), Loc),
5907 -- If the attribute definition clause comes from an aspect
5908 -- clause, then insert the renaming before the associated
5909 -- entity's declaration, since the attribute clause has
5910 -- not yet been appended to the declaration list.
5912 if From_Aspect_Specification (N) then
5913 Insert_Before (Parent (Entity (N)), Rnode);
5915 Insert_Before (N, Rnode);
5919 Set_Associated_Storage_Pool (U_Ent, Pool);
5922 elsif Is_Entity_Name (Expr) then
5923 Pool := Entity (Expr);
5925 -- If pool is a renamed object, get original one. This can
5926 -- happen with an explicit renaming, and within instances.
5928 while Present (Renamed_Object (Pool))
5929 and then Is_Entity_Name (Renamed_Object (Pool))
5931 Pool := Entity (Renamed_Object (Pool));
5934 if Present (Renamed_Object (Pool))
5935 and then Nkind (Renamed_Object (Pool)) = N_Type_Conversion
5936 and then Is_Entity_Name (Expression (Renamed_Object (Pool)))
5938 Pool := Entity (Expression (Renamed_Object (Pool)));
5941 Set_Associated_Storage_Pool (U_Ent, Pool);
5943 elsif Nkind (Expr) = N_Type_Conversion
5944 and then Is_Entity_Name (Expression (Expr))
5945 and then Nkind (Original_Node (Expr)) = N_Attribute_Reference
5947 Pool := Entity (Expression (Expr));
5948 Set_Associated_Storage_Pool (U_Ent, Pool);
5951 Error_Msg_N ("incorrect reference to a Storage Pool", Expr);
5960 -- Storage_Size attribute definition clause
5962 when Attribute_Storage_Size => Storage_Size : declare
5963 Btype : constant Entity_Id := Base_Type (U_Ent);
5966 if Is_Task_Type (U_Ent) then
5968 -- Check obsolescent (but never obsolescent if from aspect)
5970 if not From_Aspect_Specification (N) then
5971 Check_Restriction (No_Obsolescent_Features, N);
5973 if Warn_On_Obsolescent_Feature then
5975 ("?j?storage size clause for task is an obsolescent "
5976 & "feature (RM J.9)", N);
5977 Error_Msg_N ("\?j?use Storage_Size pragma instead", N);
5984 if not Is_Access_Type (U_Ent)
5985 and then Ekind (U_Ent) /= E_Task_Type
5987 Error_Msg_N ("storage size cannot be given for &", Nam);
5989 elsif Is_Access_Type (U_Ent) and Is_Derived_Type (U_Ent) then
5991 ("storage size cannot be given for a derived access type",
5994 elsif Duplicate_Clause then
5998 Analyze_And_Resolve (Expr, Any_Integer);
6000 if Is_Access_Type (U_Ent) then
6002 -- Check for Storage_Pool previously given
6005 SP : constant Node_Id :=
6006 Get_Attribute_Definition_Clause
6007 (U_Ent, Attribute_Storage_Pool);
6010 if Present (SP) then
6011 Check_Pool_Size_Clash (U_Ent, SP, N);
6015 -- Special case of for x'Storage_Size use 0
6017 if Is_OK_Static_Expression (Expr)
6018 and then Expr_Value (Expr) = 0
6020 Set_No_Pool_Assigned (Btype);
6024 Set_Has_Storage_Size_Clause (Btype);
6032 when Attribute_Stream_Size => Stream_Size : declare
6033 Size : constant Uint := Static_Integer (Expr);
6036 if Ada_Version <= Ada_95 then
6037 Check_Restriction (No_Implementation_Attributes, N);
6040 if Duplicate_Clause then
6043 elsif Is_Elementary_Type (U_Ent) then
6045 -- The following errors are suppressed in ASIS mode to allow
6046 -- for different ASIS back ends or ASIS-based tools to query
6047 -- the illegal clause.
6052 elsif Size /= System_Storage_Unit
6053 and then Size /= System_Storage_Unit * 2
6054 and then Size /= System_Storage_Unit * 4
6055 and then Size /= System_Storage_Unit * 8
6057 Error_Msg_Uint_1 := UI_From_Int (System_Storage_Unit);
6059 ("stream size for elementary type must be a power of 2 "
6060 & "and at least ^", N);
6062 elsif RM_Size (U_Ent) > Size then
6063 Error_Msg_Uint_1 := RM_Size (U_Ent);
6065 ("stream size for elementary type must be a power of 2 "
6066 & "and at least ^", N);
6069 Set_Has_Stream_Size_Clause (U_Ent);
6072 Error_Msg_N ("Stream_Size cannot be given for &", Nam);
6080 -- Value_Size attribute definition clause
6082 when Attribute_Value_Size => Value_Size : declare
6083 Size : constant Uint := Static_Integer (Expr);
6087 if not Is_Type (U_Ent) then
6088 Error_Msg_N ("Value_Size cannot be given for &", Nam);
6090 elsif Duplicate_Clause then
6093 elsif Is_Array_Type (U_Ent)
6094 and then not Is_Constrained (U_Ent)
6097 ("Value_Size cannot be given for unconstrained array", Nam);
6100 if Is_Elementary_Type (U_Ent) then
6101 Check_Size (Expr, U_Ent, Size, Biased);
6102 Set_Biased (U_Ent, N, "value size clause", Biased);
6105 Set_RM_Size (U_Ent, Size);
6109 -----------------------
6110 -- Variable_Indexing --
6111 -----------------------
6113 when Attribute_Variable_Indexing =>
6114 Check_Indexing_Functions;
6120 when Attribute_Write =>
6121 Analyze_Stream_TSS_Definition (TSS_Stream_Write);
6122 Set_Has_Specified_Stream_Write (Ent);
6124 -- All other attributes cannot be set
6128 ("attribute& cannot be set with definition clause", N);
6131 -- The test for the type being frozen must be performed after any
6132 -- expression the clause has been analyzed since the expression itself
6133 -- might cause freezing that makes the clause illegal.
6135 if Rep_Item_Too_Late (U_Ent, N, FOnly) then
6138 end Analyze_Attribute_Definition_Clause;
6140 ----------------------------
6141 -- Analyze_Code_Statement --
6142 ----------------------------
6144 procedure Analyze_Code_Statement (N : Node_Id) is
6145 HSS : constant Node_Id := Parent (N);
6146 SBody : constant Node_Id := Parent (HSS);
6147 Subp : constant Entity_Id := Current_Scope;
6154 -- Accept foreign code statements for CodePeer. The analysis is skipped
6155 -- to avoid rejecting unrecognized constructs.
6157 if CodePeer_Mode then
6162 -- Analyze and check we get right type, note that this implements the
6163 -- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that is
6164 -- the only way that Asm_Insn could possibly be visible.
6166 Analyze_And_Resolve (Expression (N));
6168 if Etype (Expression (N)) = Any_Type then
6170 elsif Etype (Expression (N)) /= RTE (RE_Asm_Insn) then
6171 Error_Msg_N ("incorrect type for code statement", N);
6175 Check_Code_Statement (N);
6177 -- Make sure we appear in the handled statement sequence of a subprogram
6180 if Nkind (HSS) /= N_Handled_Sequence_Of_Statements
6181 or else Nkind (SBody) /= N_Subprogram_Body
6184 ("code statement can only appear in body of subprogram", N);
6188 -- Do remaining checks (RM 13.8(3)) if not already done
6190 if not Is_Machine_Code_Subprogram (Subp) then
6191 Set_Is_Machine_Code_Subprogram (Subp);
6193 -- No exception handlers allowed
6195 if Present (Exception_Handlers (HSS)) then
6197 ("exception handlers not permitted in machine code subprogram",
6198 First (Exception_Handlers (HSS)));
6201 -- No declarations other than use clauses and pragmas (we allow
6202 -- certain internally generated declarations as well).
6204 Decl := First (Declarations (SBody));
6205 while Present (Decl) loop
6206 DeclO := Original_Node (Decl);
6207 if Comes_From_Source (DeclO)
6208 and not Nkind_In (DeclO, N_Pragma,
6209 N_Use_Package_Clause,
6211 N_Implicit_Label_Declaration)
6214 ("this declaration not allowed in machine code subprogram",
6221 -- No statements other than code statements, pragmas, and labels.
6222 -- Again we allow certain internally generated statements.
6224 -- In Ada 2012, qualified expressions are names, and the code
6225 -- statement is initially parsed as a procedure call.
6227 Stmt := First (Statements (HSS));
6228 while Present (Stmt) loop
6229 StmtO := Original_Node (Stmt);
6231 -- A procedure call transformed into a code statement is OK
6233 if Ada_Version >= Ada_2012
6234 and then Nkind (StmtO) = N_Procedure_Call_Statement
6235 and then Nkind (Name (StmtO)) = N_Qualified_Expression
6239 elsif Comes_From_Source (StmtO)
6240 and then not Nkind_In (StmtO, N_Pragma,
6245 ("this statement is not allowed in machine code subprogram",
6252 end Analyze_Code_Statement;
6254 -----------------------------------------------
6255 -- Analyze_Enumeration_Representation_Clause --
6256 -----------------------------------------------
6258 procedure Analyze_Enumeration_Representation_Clause (N : Node_Id) is
6259 Ident : constant Node_Id := Identifier (N);
6260 Aggr : constant Node_Id := Array_Aggregate (N);
6261 Enumtype : Entity_Id;
6268 Err : Boolean := False;
6269 -- Set True to avoid cascade errors and crashes on incorrect source code
6271 Lo : constant Uint := Expr_Value (Type_Low_Bound (Universal_Integer));
6272 Hi : constant Uint := Expr_Value (Type_High_Bound (Universal_Integer));
6273 -- Allowed range of universal integer (= allowed range of enum lit vals)
6277 -- Minimum and maximum values of entries
6280 -- Pointer to node for literal providing max value
6283 if Ignore_Rep_Clauses then
6284 Kill_Rep_Clause (N);
6288 -- Ignore enumeration rep clauses by default in CodePeer mode,
6289 -- unless -gnatd.I is specified, as a work around for potential false
6290 -- positive messages.
6292 if CodePeer_Mode and not Debug_Flag_Dot_II then
6296 -- First some basic error checks
6299 Enumtype := Entity (Ident);
6301 if Enumtype = Any_Type
6302 or else Rep_Item_Too_Early (Enumtype, N)
6306 Enumtype := Underlying_Type (Enumtype);
6309 if not Is_Enumeration_Type (Enumtype) then
6311 ("enumeration type required, found}",
6312 Ident, First_Subtype (Enumtype));
6316 -- Ignore rep clause on generic actual type. This will already have
6317 -- been flagged on the template as an error, and this is the safest
6318 -- way to ensure we don't get a junk cascaded message in the instance.
6320 if Is_Generic_Actual_Type (Enumtype) then
6323 -- Type must be in current scope
6325 elsif Scope (Enumtype) /= Current_Scope then
6326 Error_Msg_N ("type must be declared in this scope", Ident);
6329 -- Type must be a first subtype
6331 elsif not Is_First_Subtype (Enumtype) then
6332 Error_Msg_N ("cannot give enumeration rep clause for subtype", N);
6335 -- Ignore duplicate rep clause
6337 elsif Has_Enumeration_Rep_Clause (Enumtype) then
6338 Error_Msg_N ("duplicate enumeration rep clause ignored", N);
6341 -- Don't allow rep clause for standard [wide_[wide_]]character
6343 elsif Is_Standard_Character_Type (Enumtype) then
6344 Error_Msg_N ("enumeration rep clause not allowed for this type", N);
6347 -- Check that the expression is a proper aggregate (no parentheses)
6349 elsif Paren_Count (Aggr) /= 0 then
6351 ("extra parentheses surrounding aggregate not allowed",
6355 -- All tests passed, so set rep clause in place
6358 Set_Has_Enumeration_Rep_Clause (Enumtype);
6359 Set_Has_Enumeration_Rep_Clause (Base_Type (Enumtype));
6362 -- Now we process the aggregate. Note that we don't use the normal
6363 -- aggregate code for this purpose, because we don't want any of the
6364 -- normal expansion activities, and a number of special semantic
6365 -- rules apply (including the component type being any integer type)
6367 Elit := First_Literal (Enumtype);
6369 -- First the positional entries if any
6371 if Present (Expressions (Aggr)) then
6372 Expr := First (Expressions (Aggr));
6373 while Present (Expr) loop
6375 Error_Msg_N ("too many entries in aggregate", Expr);
6379 Val := Static_Integer (Expr);
6381 -- Err signals that we found some incorrect entries processing
6382 -- the list. The final checks for completeness and ordering are
6383 -- skipped in this case.
6385 if Val = No_Uint then
6388 elsif Val < Lo or else Hi < Val then
6389 Error_Msg_N ("value outside permitted range", Expr);
6393 Set_Enumeration_Rep (Elit, Val);
6394 Set_Enumeration_Rep_Expr (Elit, Expr);
6400 -- Now process the named entries if present
6402 if Present (Component_Associations (Aggr)) then
6403 Assoc := First (Component_Associations (Aggr));
6404 while Present (Assoc) loop
6405 Choice := First (Choices (Assoc));
6407 if Present (Next (Choice)) then
6409 ("multiple choice not allowed here", Next (Choice));
6413 if Nkind (Choice) = N_Others_Choice then
6414 Error_Msg_N ("others choice not allowed here", Choice);
6417 elsif Nkind (Choice) = N_Range then
6419 -- ??? should allow zero/one element range here
6421 Error_Msg_N ("range not allowed here", Choice);
6425 Analyze_And_Resolve (Choice, Enumtype);
6427 if Error_Posted (Choice) then
6432 if Is_Entity_Name (Choice)
6433 and then Is_Type (Entity (Choice))
6435 Error_Msg_N ("subtype name not allowed here", Choice);
6438 -- ??? should allow static subtype with zero/one entry
6440 elsif Etype (Choice) = Base_Type (Enumtype) then
6441 if not Is_OK_Static_Expression (Choice) then
6442 Flag_Non_Static_Expr
6443 ("non-static expression used for choice!", Choice);
6447 Elit := Expr_Value_E (Choice);
6449 if Present (Enumeration_Rep_Expr (Elit)) then
6451 Sloc (Enumeration_Rep_Expr (Elit));
6453 ("representation for& previously given#",
6458 Set_Enumeration_Rep_Expr (Elit, Expression (Assoc));
6460 Expr := Expression (Assoc);
6461 Val := Static_Integer (Expr);
6463 if Val = No_Uint then
6466 elsif Val < Lo or else Hi < Val then
6467 Error_Msg_N ("value outside permitted range", Expr);
6471 Set_Enumeration_Rep (Elit, Val);
6481 -- Aggregate is fully processed. Now we check that a full set of
6482 -- representations was given, and that they are in range and in order.
6483 -- These checks are only done if no other errors occurred.
6489 Elit := First_Literal (Enumtype);
6490 while Present (Elit) loop
6491 if No (Enumeration_Rep_Expr (Elit)) then
6492 Error_Msg_NE ("missing representation for&!", N, Elit);
6495 Val := Enumeration_Rep (Elit);
6497 if Min = No_Uint then
6501 if Val /= No_Uint then
6502 if Max /= No_Uint and then Val <= Max then
6504 ("enumeration value for& not ordered!",
6505 Enumeration_Rep_Expr (Elit), Elit);
6508 Max_Node := Enumeration_Rep_Expr (Elit);
6512 -- If there is at least one literal whose representation is not
6513 -- equal to the Pos value, then note that this enumeration type
6514 -- has a non-standard representation.
6516 if Val /= Enumeration_Pos (Elit) then
6517 Set_Has_Non_Standard_Rep (Base_Type (Enumtype));
6524 -- Now set proper size information
6527 Minsize : Uint := UI_From_Int (Minimum_Size (Enumtype));
6530 if Has_Size_Clause (Enumtype) then
6532 -- All OK, if size is OK now
6534 if RM_Size (Enumtype) >= Minsize then
6538 -- Try if we can get by with biasing
6541 UI_From_Int (Minimum_Size (Enumtype, Biased => True));
6543 -- Error message if even biasing does not work
6545 if RM_Size (Enumtype) < Minsize then
6546 Error_Msg_Uint_1 := RM_Size (Enumtype);
6547 Error_Msg_Uint_2 := Max;
6549 ("previously given size (^) is too small "
6550 & "for this value (^)", Max_Node);
6552 -- If biasing worked, indicate that we now have biased rep
6556 (Enumtype, Size_Clause (Enumtype), "size clause");
6561 Set_RM_Size (Enumtype, Minsize);
6562 Set_Enum_Esize (Enumtype);
6565 Set_RM_Size (Base_Type (Enumtype), RM_Size (Enumtype));
6566 Set_Esize (Base_Type (Enumtype), Esize (Enumtype));
6567 Set_Alignment (Base_Type (Enumtype), Alignment (Enumtype));
6571 -- We repeat the too late test in case it froze itself
6573 if Rep_Item_Too_Late (Enumtype, N) then
6576 end Analyze_Enumeration_Representation_Clause;
6578 ----------------------------
6579 -- Analyze_Free_Statement --
6580 ----------------------------
6582 procedure Analyze_Free_Statement (N : Node_Id) is
6584 Analyze (Expression (N));
6585 end Analyze_Free_Statement;
6587 ---------------------------
6588 -- Analyze_Freeze_Entity --
6589 ---------------------------
6591 procedure Analyze_Freeze_Entity (N : Node_Id) is
6593 Freeze_Entity_Checks (N);
6594 end Analyze_Freeze_Entity;
6596 -----------------------------------
6597 -- Analyze_Freeze_Generic_Entity --
6598 -----------------------------------
6600 procedure Analyze_Freeze_Generic_Entity (N : Node_Id) is
6602 Freeze_Entity_Checks (N);
6603 end Analyze_Freeze_Generic_Entity;
6605 ------------------------------------------
6606 -- Analyze_Record_Representation_Clause --
6607 ------------------------------------------
6609 -- Note: we check as much as we can here, but we can't do any checks
6610 -- based on the position values (e.g. overlap checks) until freeze time
6611 -- because especially in Ada 2005 (machine scalar mode), the processing
6612 -- for non-standard bit order can substantially change the positions.
6613 -- See procedure Check_Record_Representation_Clause (called from Freeze)
6614 -- for the remainder of this processing.
6616 procedure Analyze_Record_Representation_Clause (N : Node_Id) is
6617 Ident : constant Node_Id := Identifier (N);
6622 Hbit : Uint := Uint_0;
6626 Rectype : Entity_Id;
6629 function Is_Inherited (Comp : Entity_Id) return Boolean;
6630 -- True if Comp is an inherited component in a record extension
6636 function Is_Inherited (Comp : Entity_Id) return Boolean is
6637 Comp_Base : Entity_Id;
6640 if Ekind (Rectype) = E_Record_Subtype then
6641 Comp_Base := Original_Record_Component (Comp);
6646 return Comp_Base /= Original_Record_Component (Comp_Base);
6651 Is_Record_Extension : Boolean;
6652 -- True if Rectype is a record extension
6654 CR_Pragma : Node_Id := Empty;
6655 -- Points to N_Pragma node if Complete_Representation pragma present
6657 -- Start of processing for Analyze_Record_Representation_Clause
6660 if Ignore_Rep_Clauses then
6661 Kill_Rep_Clause (N);
6666 Rectype := Entity (Ident);
6668 if Rectype = Any_Type or else Rep_Item_Too_Early (Rectype, N) then
6671 Rectype := Underlying_Type (Rectype);
6674 -- First some basic error checks
6676 if not Is_Record_Type (Rectype) then
6678 ("record type required, found}", Ident, First_Subtype (Rectype));
6681 elsif Scope (Rectype) /= Current_Scope then
6682 Error_Msg_N ("type must be declared in this scope", N);
6685 elsif not Is_First_Subtype (Rectype) then
6686 Error_Msg_N ("cannot give record rep clause for subtype", N);
6689 elsif Has_Record_Rep_Clause (Rectype) then
6690 Error_Msg_N ("duplicate record rep clause ignored", N);
6693 elsif Rep_Item_Too_Late (Rectype, N) then
6697 -- We know we have a first subtype, now possibly go to the anonymous
6698 -- base type to determine whether Rectype is a record extension.
6700 Recdef := Type_Definition (Declaration_Node (Base_Type (Rectype)));
6701 Is_Record_Extension :=
6702 Nkind (Recdef) = N_Derived_Type_Definition
6703 and then Present (Record_Extension_Part (Recdef));
6705 if Present (Mod_Clause (N)) then
6707 Loc : constant Source_Ptr := Sloc (N);
6708 M : constant Node_Id := Mod_Clause (N);
6709 P : constant List_Id := Pragmas_Before (M);
6713 pragma Warnings (Off, Mod_Val);
6716 Check_Restriction (No_Obsolescent_Features, Mod_Clause (N));
6718 if Warn_On_Obsolescent_Feature then
6720 ("?j?mod clause is an obsolescent feature (RM J.8)", N);
6722 ("\?j?use alignment attribute definition clause instead", N);
6729 -- In ASIS_Mode mode, expansion is disabled, but we must convert
6730 -- the Mod clause into an alignment clause anyway, so that the
6731 -- back end can compute and back-annotate properly the size and
6732 -- alignment of types that may include this record.
6734 -- This seems dubious, this destroys the source tree in a manner
6735 -- not detectable by ASIS ???
6737 if Operating_Mode = Check_Semantics and then ASIS_Mode then
6739 Make_Attribute_Definition_Clause (Loc,
6740 Name => New_Occurrence_Of (Base_Type (Rectype), Loc),
6741 Chars => Name_Alignment,
6742 Expression => Relocate_Node (Expression (M)));
6744 Set_From_At_Mod (AtM_Nod);
6745 Insert_After (N, AtM_Nod);
6746 Mod_Val := Get_Alignment_Value (Expression (AtM_Nod));
6747 Set_Mod_Clause (N, Empty);
6750 -- Get the alignment value to perform error checking
6752 Mod_Val := Get_Alignment_Value (Expression (M));
6757 -- For untagged types, clear any existing component clauses for the
6758 -- type. If the type is derived, this is what allows us to override
6759 -- a rep clause for the parent. For type extensions, the representation
6760 -- of the inherited components is inherited, so we want to keep previous
6761 -- component clauses for completeness.
6763 if not Is_Tagged_Type (Rectype) then
6764 Comp := First_Component_Or_Discriminant (Rectype);
6765 while Present (Comp) loop
6766 Set_Component_Clause (Comp, Empty);
6767 Next_Component_Or_Discriminant (Comp);
6771 -- All done if no component clauses
6773 CC := First (Component_Clauses (N));
6779 -- A representation like this applies to the base type
6781 Set_Has_Record_Rep_Clause (Base_Type (Rectype));
6782 Set_Has_Non_Standard_Rep (Base_Type (Rectype));
6783 Set_Has_Specified_Layout (Base_Type (Rectype));
6785 -- Process the component clauses
6787 while Present (CC) loop
6791 if Nkind (CC) = N_Pragma then
6794 -- The only pragma of interest is Complete_Representation
6796 if Pragma_Name (CC) = Name_Complete_Representation then
6800 -- Processing for real component clause
6803 Posit := Static_Integer (Position (CC));
6804 Fbit := Static_Integer (First_Bit (CC));
6805 Lbit := Static_Integer (Last_Bit (CC));
6808 and then Fbit /= No_Uint
6809 and then Lbit /= No_Uint
6812 Error_Msg_N ("position cannot be negative", Position (CC));
6815 Error_Msg_N ("first bit cannot be negative", First_Bit (CC));
6817 -- The Last_Bit specified in a component clause must not be
6818 -- less than the First_Bit minus one (RM-13.5.1(10)).
6820 elsif Lbit < Fbit - 1 then
6822 ("last bit cannot be less than first bit minus one",
6825 -- Values look OK, so find the corresponding record component
6826 -- Even though the syntax allows an attribute reference for
6827 -- implementation-defined components, GNAT does not allow the
6828 -- tag to get an explicit position.
6830 elsif Nkind (Component_Name (CC)) = N_Attribute_Reference then
6831 if Attribute_Name (Component_Name (CC)) = Name_Tag then
6832 Error_Msg_N ("position of tag cannot be specified", CC);
6834 Error_Msg_N ("illegal component name", CC);
6838 Comp := First_Entity (Rectype);
6839 while Present (Comp) loop
6840 exit when Chars (Comp) = Chars (Component_Name (CC));
6846 -- Maybe component of base type that is absent from
6847 -- statically constrained first subtype.
6849 Comp := First_Entity (Base_Type (Rectype));
6850 while Present (Comp) loop
6851 exit when Chars (Comp) = Chars (Component_Name (CC));
6858 ("component clause is for non-existent field", CC);
6860 -- Ada 2012 (AI05-0026): Any name that denotes a
6861 -- discriminant of an object of an unchecked union type
6862 -- shall not occur within a record_representation_clause.
6864 -- The general restriction of using record rep clauses on
6865 -- Unchecked_Union types has now been lifted. Since it is
6866 -- possible to introduce a record rep clause which mentions
6867 -- the discriminant of an Unchecked_Union in non-Ada 2012
6868 -- code, this check is applied to all versions of the
6871 elsif Ekind (Comp) = E_Discriminant
6872 and then Is_Unchecked_Union (Rectype)
6875 ("cannot reference discriminant of unchecked union",
6876 Component_Name (CC));
6878 elsif Is_Record_Extension and then Is_Inherited (Comp) then
6880 ("component clause not allowed for inherited "
6881 & "component&", CC, Comp);
6883 elsif Present (Component_Clause (Comp)) then
6885 -- Diagnose duplicate rep clause, or check consistency
6886 -- if this is an inherited component. In a double fault,
6887 -- there may be a duplicate inconsistent clause for an
6888 -- inherited component.
6890 if Scope (Original_Record_Component (Comp)) = Rectype
6891 or else Parent (Component_Clause (Comp)) = N
6893 Error_Msg_Sloc := Sloc (Component_Clause (Comp));
6894 Error_Msg_N ("component clause previously given#", CC);
6898 Rep1 : constant Node_Id := Component_Clause (Comp);
6900 if Intval (Position (Rep1)) /=
6901 Intval (Position (CC))
6902 or else Intval (First_Bit (Rep1)) /=
6903 Intval (First_Bit (CC))
6904 or else Intval (Last_Bit (Rep1)) /=
6905 Intval (Last_Bit (CC))
6908 ("component clause inconsistent with "
6909 & "representation of ancestor", CC);
6911 elsif Warn_On_Redundant_Constructs then
6913 ("?r?redundant confirming component clause "
6914 & "for component!", CC);
6919 -- Normal case where this is the first component clause we
6920 -- have seen for this entity, so set it up properly.
6923 -- Make reference for field in record rep clause and set
6924 -- appropriate entity field in the field identifier.
6927 (Comp, Component_Name (CC), Set_Ref => False);
6928 Set_Entity (Component_Name (CC), Comp);
6930 -- Update Fbit and Lbit to the actual bit number
6932 Fbit := Fbit + UI_From_Int (SSU) * Posit;
6933 Lbit := Lbit + UI_From_Int (SSU) * Posit;
6935 if Has_Size_Clause (Rectype)
6936 and then RM_Size (Rectype) <= Lbit
6939 ("bit number out of range of specified size",
6942 Set_Component_Clause (Comp, CC);
6943 Set_Component_Bit_Offset (Comp, Fbit);
6944 Set_Esize (Comp, 1 + (Lbit - Fbit));
6945 Set_Normalized_First_Bit (Comp, Fbit mod SSU);
6946 Set_Normalized_Position (Comp, Fbit / SSU);
6948 if Warn_On_Overridden_Size
6949 and then Has_Size_Clause (Etype (Comp))
6950 and then RM_Size (Etype (Comp)) /= Esize (Comp)
6953 ("?S?component size overrides size clause for&",
6954 Component_Name (CC), Etype (Comp));
6957 -- This information is also set in the corresponding
6958 -- component of the base type, found by accessing the
6959 -- Original_Record_Component link if it is present.
6961 Ocomp := Original_Record_Component (Comp);
6968 (Component_Name (CC),
6974 (Comp, First_Node (CC), "component clause", Biased);
6976 if Present (Ocomp) then
6977 Set_Component_Clause (Ocomp, CC);
6978 Set_Component_Bit_Offset (Ocomp, Fbit);
6979 Set_Normalized_First_Bit (Ocomp, Fbit mod SSU);
6980 Set_Normalized_Position (Ocomp, Fbit / SSU);
6981 Set_Esize (Ocomp, 1 + (Lbit - Fbit));
6983 Set_Normalized_Position_Max
6984 (Ocomp, Normalized_Position (Ocomp));
6986 -- Note: we don't use Set_Biased here, because we
6987 -- already gave a warning above if needed, and we
6988 -- would get a duplicate for the same name here.
6990 Set_Has_Biased_Representation
6991 (Ocomp, Has_Biased_Representation (Comp));
6994 if Esize (Comp) < 0 then
6995 Error_Msg_N ("component size is negative", CC);
7006 -- Check missing components if Complete_Representation pragma appeared
7008 if Present (CR_Pragma) then
7009 Comp := First_Component_Or_Discriminant (Rectype);
7010 while Present (Comp) loop
7011 if No (Component_Clause (Comp)) then
7013 ("missing component clause for &", CR_Pragma, Comp);
7016 Next_Component_Or_Discriminant (Comp);
7019 -- Give missing components warning if required
7021 elsif Warn_On_Unrepped_Components then
7023 Num_Repped_Components : Nat := 0;
7024 Num_Unrepped_Components : Nat := 0;
7027 -- First count number of repped and unrepped components
7029 Comp := First_Component_Or_Discriminant (Rectype);
7030 while Present (Comp) loop
7031 if Present (Component_Clause (Comp)) then
7032 Num_Repped_Components := Num_Repped_Components + 1;
7034 Num_Unrepped_Components := Num_Unrepped_Components + 1;
7037 Next_Component_Or_Discriminant (Comp);
7040 -- We are only interested in the case where there is at least one
7041 -- unrepped component, and at least half the components have rep
7042 -- clauses. We figure that if less than half have them, then the
7043 -- partial rep clause is really intentional. If the component
7044 -- type has no underlying type set at this point (as for a generic
7045 -- formal type), we don't know enough to give a warning on the
7048 if Num_Unrepped_Components > 0
7049 and then Num_Unrepped_Components < Num_Repped_Components
7051 Comp := First_Component_Or_Discriminant (Rectype);
7052 while Present (Comp) loop
7053 if No (Component_Clause (Comp))
7054 and then Comes_From_Source (Comp)
7055 and then Present (Underlying_Type (Etype (Comp)))
7056 and then (Is_Scalar_Type (Underlying_Type (Etype (Comp)))
7057 or else Size_Known_At_Compile_Time
7058 (Underlying_Type (Etype (Comp))))
7059 and then not Has_Warnings_Off (Rectype)
7061 -- Ignore discriminant in unchecked union, since it is
7062 -- not there, and cannot have a component clause.
7064 and then (not Is_Unchecked_Union (Rectype)
7065 or else Ekind (Comp) /= E_Discriminant)
7067 Error_Msg_Sloc := Sloc (Comp);
7069 ("?C?no component clause given for & declared #",
7073 Next_Component_Or_Discriminant (Comp);
7078 end Analyze_Record_Representation_Clause;
7080 -------------------------------------
7081 -- Build_Discrete_Static_Predicate --
7082 -------------------------------------
7084 procedure Build_Discrete_Static_Predicate
7089 Loc : constant Source_Ptr := Sloc (Expr);
7091 Non_Static : exception;
7092 -- Raised if something non-static is found
7094 Btyp : constant Entity_Id := Base_Type (Typ);
7096 BLo : constant Uint := Expr_Value (Type_Low_Bound (Btyp));
7097 BHi : constant Uint := Expr_Value (Type_High_Bound (Btyp));
7098 -- Low bound and high bound value of base type of Typ
7102 -- Bounds for constructing the static predicate. We use the bound of the
7103 -- subtype if it is static, otherwise the corresponding base type bound.
7104 -- Note: a non-static subtype can have a static predicate.
7109 -- One entry in a Rlist value, a single REnt (range entry) value denotes
7110 -- one range from Lo to Hi. To represent a single value range Lo = Hi =
7113 type RList is array (Nat range <>) of REnt;
7114 -- A list of ranges. The ranges are sorted in increasing order, and are
7115 -- disjoint (there is a gap of at least one value between each range in
7116 -- the table). A value is in the set of ranges in Rlist if it lies
7117 -- within one of these ranges.
7119 False_Range : constant RList :=
7120 RList'(1 .. 0 => REnt'(No_Uint, No_Uint));
7121 -- An empty set of ranges represents a range list that can never be
7122 -- satisfied, since there are no ranges in which the value could lie,
7123 -- so it does not lie in any of them. False_Range is a canonical value
7124 -- for this empty set, but general processing should test for an Rlist
7125 -- with length zero (see Is_False predicate), since other null ranges
7126 -- may appear which must be treated as False.
7128 True_Range : constant RList := RList'(1 => REnt'(BLo, BHi));
7129 -- Range representing True, value must be in the base range
7131 function "and" (Left : RList; Right : RList) return RList;
7132 -- And's together two range lists, returning a range list. This is a set
7133 -- intersection operation.
7135 function "or" (Left : RList; Right : RList) return RList;
7136 -- Or's together two range lists, returning a range list. This is a set
7139 function "not" (Right : RList) return RList;
7140 -- Returns complement of a given range list, i.e. a range list
7141 -- representing all the values in TLo .. THi that are not in the input
7144 function Build_Val (V : Uint) return Node_Id;
7145 -- Return an analyzed N_Identifier node referencing this value, suitable
7146 -- for use as an entry in the Static_Discrte_Predicate list. This node
7147 -- is typed with the base type.
7149 function Build_Range (Lo : Uint; Hi : Uint) return Node_Id;
7150 -- Return an analyzed N_Range node referencing this range, suitable for
7151 -- use as an entry in the Static_Discrete_Predicate list. This node is
7152 -- typed with the base type.
7154 function Get_RList (Exp : Node_Id) return RList;
7155 -- This is a recursive routine that converts the given expression into a
7156 -- list of ranges, suitable for use in building the static predicate.
7158 function Is_False (R : RList) return Boolean;
7159 pragma Inline (Is_False);
7160 -- Returns True if the given range list is empty, and thus represents a
7161 -- False list of ranges that can never be satisfied.
7163 function Is_True (R : RList) return Boolean;
7164 -- Returns True if R trivially represents the True predicate by having a
7165 -- single range from BLo to BHi.
7167 function Is_Type_Ref (N : Node_Id) return Boolean;
7168 pragma Inline (Is_Type_Ref);
7169 -- Returns if True if N is a reference to the type for the predicate in
7170 -- the expression (i.e. if it is an identifier whose Chars field matches
7171 -- the Nam given in the call). N must not be parenthesized, if the type
7172 -- name appears in parens, this routine will return False.
7174 function Lo_Val (N : Node_Id) return Uint;
7175 -- Given an entry from a Static_Discrete_Predicate list that is either
7176 -- a static expression or static range, gets either the expression value
7177 -- or the low bound of the range.
7179 function Hi_Val (N : Node_Id) return Uint;
7180 -- Given an entry from a Static_Discrete_Predicate list that is either
7181 -- a static expression or static range, gets either the expression value
7182 -- or the high bound of the range.
7184 function Membership_Entry (N : Node_Id) return RList;
7185 -- Given a single membership entry (range, value, or subtype), returns
7186 -- the corresponding range list. Raises Static_Error if not static.
7188 function Membership_Entries (N : Node_Id) return RList;
7189 -- Given an element on an alternatives list of a membership operation,
7190 -- returns the range list corresponding to this entry and all following
7191 -- entries (i.e. returns the "or" of this list of values).
7193 function Stat_Pred (Typ : Entity_Id) return RList;
7194 -- Given a type, if it has a static predicate, then return the predicate
7195 -- as a range list, otherwise raise Non_Static.
7201 function "and" (Left : RList; Right : RList) return RList is
7203 -- First range of result
7205 SLeft : Nat := Left'First;
7206 -- Start of rest of left entries
7208 SRight : Nat := Right'First;
7209 -- Start of rest of right entries
7212 -- If either range is True, return the other
7214 if Is_True (Left) then
7216 elsif Is_True (Right) then
7220 -- If either range is False, return False
7222 if Is_False (Left) or else Is_False (Right) then
7226 -- Loop to remove entries at start that are disjoint, and thus just
7227 -- get discarded from the result entirely.
7230 -- If no operands left in either operand, result is false
7232 if SLeft > Left'Last or else SRight > Right'Last then
7235 -- Discard first left operand entry if disjoint with right
7237 elsif Left (SLeft).Hi < Right (SRight).Lo then
7240 -- Discard first right operand entry if disjoint with left
7242 elsif Right (SRight).Hi < Left (SLeft).Lo then
7243 SRight := SRight + 1;
7245 -- Otherwise we have an overlapping entry
7252 -- Now we have two non-null operands, and first entries overlap. The
7253 -- first entry in the result will be the overlapping part of these
7256 FEnt := REnt'(Lo => UI_Max (Left (SLeft).Lo, Right (SRight).Lo),
7257 Hi => UI_Min (Left (SLeft).Hi, Right (SRight).Hi));
7259 -- Now we can remove the entry that ended at a lower value, since its
7260 -- contribution is entirely contained in Fent.
7262 if Left (SLeft).Hi <= Right (SRight).Hi then
7265 SRight := SRight + 1;
7268 -- Compute result by concatenating this first entry with the "and" of
7269 -- the remaining parts of the left and right operands. Note that if
7270 -- either of these is empty, "and" will yield empty, so that we will
7271 -- end up with just Fent, which is what we want in that case.
7274 FEnt & (Left (SLeft .. Left'Last) and Right (SRight .. Right'Last));
7281 function "not" (Right : RList) return RList is
7283 -- Return True if False range
7285 if Is_False (Right) then
7289 -- Return False if True range
7291 if Is_True (Right) then
7295 -- Here if not trivial case
7298 Result : RList (1 .. Right'Length + 1);
7299 -- May need one more entry for gap at beginning and end
7302 -- Number of entries stored in Result
7307 if Right (Right'First).Lo > TLo then
7309 Result (Count) := REnt'(TLo, Right (Right'First).Lo - 1);
7312 -- Gaps between ranges
7314 for J in Right'First .. Right'Last - 1 loop
7316 Result (Count) := REnt'(Right (J).Hi + 1, Right (J + 1).Lo - 1);
7321 if Right (Right'Last).Hi < THi then
7323 Result (Count) := REnt'(Right (Right'Last).Hi + 1, THi);
7326 return Result (1 .. Count);
7334 function "or" (Left : RList; Right : RList) return RList is
7336 -- First range of result
7338 SLeft : Nat := Left'First;
7339 -- Start of rest of left entries
7341 SRight : Nat := Right'First;
7342 -- Start of rest of right entries
7345 -- If either range is True, return True
7347 if Is_True (Left) or else Is_True (Right) then
7351 -- If either range is False (empty), return the other
7353 if Is_False (Left) then
7355 elsif Is_False (Right) then
7359 -- Initialize result first entry from left or right operand depending
7360 -- on which starts with the lower range.
7362 if Left (SLeft).Lo < Right (SRight).Lo then
7363 FEnt := Left (SLeft);
7366 FEnt := Right (SRight);
7367 SRight := SRight + 1;
7370 -- This loop eats ranges from left and right operands that are
7371 -- contiguous with the first range we are gathering.
7374 -- Eat first entry in left operand if contiguous or overlapped by
7375 -- gathered first operand of result.
7377 if SLeft <= Left'Last
7378 and then Left (SLeft).Lo <= FEnt.Hi + 1
7380 FEnt.Hi := UI_Max (FEnt.Hi, Left (SLeft).Hi);
7383 -- Eat first entry in right operand if contiguous or overlapped by
7384 -- gathered right operand of result.
7386 elsif SRight <= Right'Last
7387 and then Right (SRight).Lo <= FEnt.Hi + 1
7389 FEnt.Hi := UI_Max (FEnt.Hi, Right (SRight).Hi);
7390 SRight := SRight + 1;
7392 -- All done if no more entries to eat
7399 -- Obtain result as the first entry we just computed, concatenated
7400 -- to the "or" of the remaining results (if one operand is empty,
7401 -- this will just concatenate with the other
7404 FEnt & (Left (SLeft .. Left'Last) or Right (SRight .. Right'Last));
7411 function Build_Range (Lo : Uint; Hi : Uint) return Node_Id is
7416 Low_Bound => Build_Val (Lo),
7417 High_Bound => Build_Val (Hi));
7418 Set_Etype (Result, Btyp);
7419 Set_Analyzed (Result);
7427 function Build_Val (V : Uint) return Node_Id is
7431 if Is_Enumeration_Type (Typ) then
7432 Result := Get_Enum_Lit_From_Pos (Typ, V, Loc);
7434 Result := Make_Integer_Literal (Loc, V);
7437 Set_Etype (Result, Btyp);
7438 Set_Is_Static_Expression (Result);
7439 Set_Analyzed (Result);
7447 function Get_RList (Exp : Node_Id) return RList is
7452 -- Static expression can only be true or false
7454 if Is_OK_Static_Expression (Exp) then
7455 if Expr_Value (Exp) = 0 then
7462 -- Otherwise test node type
7470 when N_Op_And | N_And_Then =>
7471 return Get_RList (Left_Opnd (Exp))
7473 Get_RList (Right_Opnd (Exp));
7477 when N_Op_Or | N_Or_Else =>
7478 return Get_RList (Left_Opnd (Exp))
7480 Get_RList (Right_Opnd (Exp));
7485 return not Get_RList (Right_Opnd (Exp));
7487 -- Comparisons of type with static value
7489 when N_Op_Compare =>
7491 -- Type is left operand
7493 if Is_Type_Ref (Left_Opnd (Exp))
7494 and then Is_OK_Static_Expression (Right_Opnd (Exp))
7496 Val := Expr_Value (Right_Opnd (Exp));
7498 -- Typ is right operand
7500 elsif Is_Type_Ref (Right_Opnd (Exp))
7501 and then Is_OK_Static_Expression (Left_Opnd (Exp))
7503 Val := Expr_Value (Left_Opnd (Exp));
7505 -- Invert sense of comparison
7508 when N_Op_Gt => Op := N_Op_Lt;
7509 when N_Op_Lt => Op := N_Op_Gt;
7510 when N_Op_Ge => Op := N_Op_Le;
7511 when N_Op_Le => Op := N_Op_Ge;
7512 when others => null;
7515 -- Other cases are non-static
7521 -- Construct range according to comparison operation
7525 return RList'(1 => REnt'(Val, Val));
7528 return RList'(1 => REnt'(Val, BHi));
7531 return RList'(1 => REnt'(Val + 1, BHi));
7534 return RList'(1 => REnt'(BLo, Val));
7537 return RList'(1 => REnt'(BLo, Val - 1));
7540 return RList'(REnt'(BLo, Val - 1), REnt'(Val + 1, BHi));
7543 raise Program_Error;
7549 if not Is_Type_Ref (Left_Opnd (Exp)) then
7553 if Present (Right_Opnd (Exp)) then
7554 return Membership_Entry (Right_Opnd (Exp));
7556 return Membership_Entries (First (Alternatives (Exp)));
7559 -- Negative membership (NOT IN)
7562 if not Is_Type_Ref (Left_Opnd (Exp)) then
7566 if Present (Right_Opnd (Exp)) then
7567 return not Membership_Entry (Right_Opnd (Exp));
7569 return not Membership_Entries (First (Alternatives (Exp)));
7572 -- Function call, may be call to static predicate
7574 when N_Function_Call =>
7575 if Is_Entity_Name (Name (Exp)) then
7577 Ent : constant Entity_Id := Entity (Name (Exp));
7579 if Is_Predicate_Function (Ent)
7581 Is_Predicate_Function_M (Ent)
7583 return Stat_Pred (Etype (First_Formal (Ent)));
7588 -- Other function call cases are non-static
7592 -- Qualified expression, dig out the expression
7594 when N_Qualified_Expression =>
7595 return Get_RList (Expression (Exp));
7597 when N_Case_Expression =>
7604 if not Is_Entity_Name (Expression (Expr))
7605 or else Etype (Expression (Expr)) /= Typ
7608 ("expression must denaote subtype", Expression (Expr));
7612 -- Collect discrete choices in all True alternatives
7614 Choices := New_List;
7615 Alt := First (Alternatives (Exp));
7616 while Present (Alt) loop
7617 Dep := Expression (Alt);
7619 if not Is_OK_Static_Expression (Dep) then
7622 elsif Is_True (Expr_Value (Dep)) then
7623 Append_List_To (Choices,
7624 New_Copy_List (Discrete_Choices (Alt)));
7630 return Membership_Entries (First (Choices));
7633 -- Expression with actions: if no actions, dig out expression
7635 when N_Expression_With_Actions =>
7636 if Is_Empty_List (Actions (Exp)) then
7637 return Get_RList (Expression (Exp));
7645 return (Get_RList (Left_Opnd (Exp))
7646 and not Get_RList (Right_Opnd (Exp)))
7647 or (Get_RList (Right_Opnd (Exp))
7648 and not Get_RList (Left_Opnd (Exp)));
7650 -- Any other node type is non-static
7661 function Hi_Val (N : Node_Id) return Uint is
7663 if Is_OK_Static_Expression (N) then
7664 return Expr_Value (N);
7666 pragma Assert (Nkind (N) = N_Range);
7667 return Expr_Value (High_Bound (N));
7675 function Is_False (R : RList) return Boolean is
7677 return R'Length = 0;
7684 function Is_True (R : RList) return Boolean is
7687 and then R (R'First).Lo = BLo
7688 and then R (R'First).Hi = BHi;
7695 function Is_Type_Ref (N : Node_Id) return Boolean is
7697 return Nkind (N) = N_Identifier
7698 and then Chars (N) = Nam
7699 and then Paren_Count (N) = 0;
7706 function Lo_Val (N : Node_Id) return Uint is
7708 if Is_OK_Static_Expression (N) then
7709 return Expr_Value (N);
7711 pragma Assert (Nkind (N) = N_Range);
7712 return Expr_Value (Low_Bound (N));
7716 ------------------------
7717 -- Membership_Entries --
7718 ------------------------
7720 function Membership_Entries (N : Node_Id) return RList is
7722 if No (Next (N)) then
7723 return Membership_Entry (N);
7725 return Membership_Entry (N) or Membership_Entries (Next (N));
7727 end Membership_Entries;
7729 ----------------------
7730 -- Membership_Entry --
7731 ----------------------
7733 function Membership_Entry (N : Node_Id) return RList is
7741 if Nkind (N) = N_Range then
7742 if not Is_OK_Static_Expression (Low_Bound (N))
7744 not Is_OK_Static_Expression (High_Bound (N))
7748 SLo := Expr_Value (Low_Bound (N));
7749 SHi := Expr_Value (High_Bound (N));
7750 return RList'(1 => REnt'(SLo, SHi));
7753 -- Static expression case
7755 elsif Is_OK_Static_Expression (N) then
7756 Val := Expr_Value (N);
7757 return RList'(1 => REnt'(Val, Val));
7759 -- Identifier (other than static expression) case
7761 else pragma Assert (Nkind (N) = N_Identifier);
7765 if Is_Type (Entity (N)) then
7767 -- If type has predicates, process them
7769 if Has_Predicates (Entity (N)) then
7770 return Stat_Pred (Entity (N));
7772 -- For static subtype without predicates, get range
7774 elsif Is_OK_Static_Subtype (Entity (N)) then
7775 SLo := Expr_Value (Type_Low_Bound (Entity (N)));
7776 SHi := Expr_Value (Type_High_Bound (Entity (N)));
7777 return RList'(1 => REnt'(SLo, SHi));
7779 -- Any other type makes us non-static
7785 -- Any other kind of identifier in predicate (e.g. a non-static
7786 -- expression value) means this is not a static predicate.
7792 end Membership_Entry;
7798 function Stat_Pred (Typ : Entity_Id) return RList is
7800 -- Not static if type does not have static predicates
7802 if not Has_Static_Predicate (Typ) then
7806 -- Otherwise we convert the predicate list to a range list
7809 Spred : constant List_Id := Static_Discrete_Predicate (Typ);
7810 Result : RList (1 .. List_Length (Spred));
7814 P := First (Static_Discrete_Predicate (Typ));
7815 for J in Result'Range loop
7816 Result (J) := REnt'(Lo_Val (P), Hi_Val (P));
7824 -- Start of processing for Build_Discrete_Static_Predicate
7827 -- Establish bounds for the predicate
7829 if Compile_Time_Known_Value (Type_Low_Bound (Typ)) then
7830 TLo := Expr_Value (Type_Low_Bound (Typ));
7835 if Compile_Time_Known_Value (Type_High_Bound (Typ)) then
7836 THi := Expr_Value (Type_High_Bound (Typ));
7841 -- Analyze the expression to see if it is a static predicate
7844 Ranges : constant RList := Get_RList (Expr);
7845 -- Range list from expression if it is static
7850 -- Convert range list into a form for the static predicate. In the
7851 -- Ranges array, we just have raw ranges, these must be converted
7852 -- to properly typed and analyzed static expressions or range nodes.
7854 -- Note: here we limit ranges to the ranges of the subtype, so that
7855 -- a predicate is always false for values outside the subtype. That
7856 -- seems fine, such values are invalid anyway, and considering them
7857 -- to fail the predicate seems allowed and friendly, and furthermore
7858 -- simplifies processing for case statements and loops.
7862 for J in Ranges'Range loop
7864 Lo : Uint := Ranges (J).Lo;
7865 Hi : Uint := Ranges (J).Hi;
7868 -- Ignore completely out of range entry
7870 if Hi < TLo or else Lo > THi then
7873 -- Otherwise process entry
7876 -- Adjust out of range value to subtype range
7886 -- Convert range into required form
7888 Append_To (Plist, Build_Range (Lo, Hi));
7893 -- Processing was successful and all entries were static, so now we
7894 -- can store the result as the predicate list.
7896 Set_Static_Discrete_Predicate (Typ, Plist);
7898 -- The processing for static predicates put the expression into
7899 -- canonical form as a series of ranges. It also eliminated
7900 -- duplicates and collapsed and combined ranges. We might as well
7901 -- replace the alternatives list of the right operand of the
7902 -- membership test with the static predicate list, which will
7903 -- usually be more efficient.
7906 New_Alts : constant List_Id := New_List;
7911 Old_Node := First (Plist);
7912 while Present (Old_Node) loop
7913 New_Node := New_Copy (Old_Node);
7915 if Nkind (New_Node) = N_Range then
7916 Set_Low_Bound (New_Node, New_Copy (Low_Bound (Old_Node)));
7917 Set_High_Bound (New_Node, New_Copy (High_Bound (Old_Node)));
7920 Append_To (New_Alts, New_Node);
7924 -- If empty list, replace by False
7926 if Is_Empty_List (New_Alts) then
7927 Rewrite (Expr, New_Occurrence_Of (Standard_False, Loc));
7929 -- Else replace by set membership test
7934 Left_Opnd => Make_Identifier (Loc, Nam),
7935 Right_Opnd => Empty,
7936 Alternatives => New_Alts));
7938 -- Resolve new expression in function context
7940 Install_Formals (Predicate_Function (Typ));
7941 Push_Scope (Predicate_Function (Typ));
7942 Analyze_And_Resolve (Expr, Standard_Boolean);
7948 -- If non-static, return doing nothing
7953 end Build_Discrete_Static_Predicate;
7955 --------------------------------
7956 -- Build_Export_Import_Pragma --
7957 --------------------------------
7959 function Build_Export_Import_Pragma
7961 Id : Entity_Id) return Node_Id
7963 Asp_Id : constant Aspect_Id := Get_Aspect_Id (Asp);
7964 Expr : constant Node_Id := Expression (Asp);
7965 Loc : constant Source_Ptr := Sloc (Asp);
7976 Create_Pragma : Boolean := False;
7977 -- This flag is set when the aspect form is such that it warrants the
7978 -- creation of a corresponding pragma.
7981 if Present (Expr) then
7982 if Error_Posted (Expr) then
7985 elsif Is_True (Expr_Value (Expr)) then
7986 Create_Pragma := True;
7989 -- Otherwise the aspect defaults to True
7992 Create_Pragma := True;
7995 -- Nothing to do when the expression is False or is erroneous
7997 if not Create_Pragma then
8001 -- Obtain all interfacing aspects that apply to the related entity
8003 Get_Interfacing_Aspects
8007 Expo_Asp => Dummy_1,
8013 -- Handle the convention argument
8015 if Present (Conv) then
8016 Conv_Arg := New_Copy_Tree (Expression (Conv));
8018 -- Assume convention "Ada' when aspect Convention is missing
8021 Conv_Arg := Make_Identifier (Loc, Name_Ada);
8025 Make_Pragma_Argument_Association (Loc,
8026 Chars => Name_Convention,
8027 Expression => Conv_Arg));
8029 -- Handle the entity argument
8032 Make_Pragma_Argument_Association (Loc,
8033 Chars => Name_Entity,
8034 Expression => New_Occurrence_Of (Id, Loc)));
8036 -- Handle the External_Name argument
8038 if Present (EN) then
8040 Make_Pragma_Argument_Association (Loc,
8041 Chars => Name_External_Name,
8042 Expression => New_Copy_Tree (Expression (EN))));
8045 -- Handle the Link_Name argument
8047 if Present (LN) then
8049 Make_Pragma_Argument_Association (Loc,
8050 Chars => Name_Link_Name,
8051 Expression => New_Copy_Tree (Expression (LN))));
8055 -- pragma Export/Import
8056 -- (Convention => <Conv>/Ada,
8058 -- [External_Name => <EN>,]
8059 -- [Link_Name => <LN>]);
8063 Pragma_Identifier =>
8064 Make_Identifier (Loc, Chars (Identifier (Asp))),
8065 Pragma_Argument_Associations => Args);
8067 -- Decorate the relevant aspect and the pragma
8069 Set_Aspect_Rep_Item (Asp, Prag);
8071 Set_Corresponding_Aspect (Prag, Asp);
8072 Set_From_Aspect_Specification (Prag);
8073 Set_Parent (Prag, Asp);
8075 if Asp_Id = Aspect_Import and then Is_Subprogram (Id) then
8076 Set_Import_Pragma (Id, Prag);
8080 end Build_Export_Import_Pragma;
8082 -------------------------------
8083 -- Build_Predicate_Functions --
8084 -------------------------------
8086 -- The procedures that are constructed here have the form:
8088 -- function typPredicate (Ixxx : typ) return Boolean is
8091 -- typ1Predicate (typ1 (Ixxx))
8092 -- and then typ2Predicate (typ2 (Ixxx))
8094 -- exp1 and then exp2 and then ...
8095 -- end typPredicate;
8097 -- Here exp1, and exp2 are expressions from Predicate pragmas. Note that
8098 -- this is the point at which these expressions get analyzed, providing the
8099 -- required delay, and typ1, typ2, are entities from which predicates are
8100 -- inherited. Note that we do NOT generate Check pragmas, that's because we
8101 -- use this function even if checks are off, e.g. for membership tests.
8103 -- Note that the inherited predicates are evaluated first, as required by
8106 -- Note that Sem_Eval.Real_Or_String_Static_Predicate_Matches depends on
8107 -- the form of this return expression.
8109 -- If the expression has at least one Raise_Expression, then we also build
8110 -- the typPredicateM version of the function, in which any occurrence of a
8111 -- Raise_Expression is converted to "return False".
8113 procedure Build_Predicate_Functions (Typ : Entity_Id; N : Node_Id) is
8114 Loc : constant Source_Ptr := Sloc (Typ);
8117 -- This is the expression for the result of the function. It is
8118 -- is build by connecting the component predicates with AND THEN.
8121 -- This is the corresponding return expression for the Predicate_M
8122 -- function. It differs in that raise expressions are marked for
8123 -- special expansion (see Process_REs).
8125 Object_Name : Name_Id;
8126 -- Name for argument of Predicate procedure. Note that we use the same
8127 -- name for both predicate functions. That way the reference within the
8128 -- predicate expression is the same in both functions.
8130 Object_Entity : Entity_Id;
8131 -- Entity for argument of Predicate procedure
8133 Object_Entity_M : Entity_Id;
8134 -- Entity for argument of separate Predicate procedure when exceptions
8135 -- are present in expression.
8138 -- The function declaration
8143 Raise_Expression_Present : Boolean := False;
8144 -- Set True if Expr has at least one Raise_Expression
8146 procedure Add_Condition (Cond : Node_Id);
8147 -- Append Cond to Expr using "and then" (or just copy Cond to Expr if
8150 procedure Add_Predicates;
8151 -- Appends expressions for any Predicate pragmas in the rep item chain
8152 -- Typ to Expr. Note that we look only at items for this exact entity.
8153 -- Inheritance of predicates for the parent type is done by calling the
8154 -- Predicate_Function of the parent type, using Add_Call above.
8156 procedure Add_Call (T : Entity_Id);
8157 -- Includes a call to the predicate function for type T in Expr if T
8158 -- has predicates and Predicate_Function (T) is non-empty.
8160 function Process_RE (N : Node_Id) return Traverse_Result;
8161 -- Used in Process REs, tests if node N is a raise expression, and if
8162 -- so, marks it to be converted to return False.
8164 procedure Process_REs is new Traverse_Proc (Process_RE);
8165 -- Marks any raise expressions in Expr_M to return False
8167 function Test_RE (N : Node_Id) return Traverse_Result;
8168 -- Used in Test_REs, tests one node for being a raise expression, and if
8169 -- so sets Raise_Expression_Present True.
8171 procedure Test_REs is new Traverse_Proc (Test_RE);
8172 -- Tests to see if Expr contains any raise expressions
8178 procedure Add_Call (T : Entity_Id) is
8182 if Present (T) and then Present (Predicate_Function (T)) then
8183 Set_Has_Predicates (Typ);
8185 -- Build the call to the predicate function of T
8189 (T, Convert_To (T, Make_Identifier (Loc, Object_Name)));
8191 -- "and"-in the call to evolving expression
8193 Add_Condition (Exp);
8195 -- Output info message on inheritance if required. Note we do not
8196 -- give this information for generic actual types, since it is
8197 -- unwelcome noise in that case in instantiations. We also
8198 -- generally suppress the message in instantiations, and also
8199 -- if it involves internal names.
8201 if Opt.List_Inherited_Aspects
8202 and then not Is_Generic_Actual_Type (Typ)
8203 and then Instantiation_Depth (Sloc (Typ)) = 0
8204 and then not Is_Internal_Name (Chars (T))
8205 and then not Is_Internal_Name (Chars (Typ))
8207 Error_Msg_Sloc := Sloc (Predicate_Function (T));
8208 Error_Msg_Node_2 := T;
8209 Error_Msg_N ("info: & inherits predicate from & #?L?", Typ);
8218 procedure Add_Condition (Cond : Node_Id) is
8220 -- This is the first predicate expression
8225 -- Otherwise concatenate to the existing predicate expressions by
8226 -- using "and then".
8231 Left_Opnd => Relocate_Node (Expr),
8232 Right_Opnd => Cond);
8236 --------------------
8237 -- Add_Predicates --
8238 --------------------
8240 procedure Add_Predicates is
8241 procedure Add_Predicate (Prag : Node_Id);
8242 -- Concatenate the expression of predicate pragma Prag to Expr by
8243 -- using a short circuit "and then" operator.
8249 procedure Add_Predicate (Prag : Node_Id) is
8250 procedure Replace_Type_Reference (N : Node_Id);
8251 -- Replace a single occurrence N of the subtype name with a
8252 -- reference to the formal of the predicate function. N can be an
8253 -- identifier referencing the subtype, or a selected component,
8254 -- representing an appropriately qualified occurrence of the
8257 procedure Replace_Type_References is
8258 new Replace_Type_References_Generic (Replace_Type_Reference);
8259 -- Traverse an expression changing every occurrence of an
8260 -- identifier whose name matches the name of the subtype with a
8261 -- reference to the formal parameter of the predicate function.
8263 ----------------------------
8264 -- Replace_Type_Reference --
8265 ----------------------------
8267 procedure Replace_Type_Reference (N : Node_Id) is
8269 Rewrite (N, Make_Identifier (Sloc (N), Object_Name));
8270 -- Use the Sloc of the usage name, not the defining name
8273 Set_Entity (N, Object_Entity);
8275 -- We want to treat the node as if it comes from source, so
8276 -- that ASIS will not ignore it.
8278 Set_Comes_From_Source (N, True);
8279 end Replace_Type_Reference;
8283 Asp : constant Node_Id := Corresponding_Aspect (Prag);
8287 -- Start of processing for Add_Predicate
8290 -- Extract the arguments of the pragma. The expression itself
8291 -- is copied for use in the predicate function, to preserve the
8292 -- original version for ASIS use.
8294 Arg1 := First (Pragma_Argument_Associations (Prag));
8295 Arg2 := Next (Arg1);
8297 Arg1 := Get_Pragma_Arg (Arg1);
8298 Arg2 := New_Copy_Tree (Get_Pragma_Arg (Arg2));
8300 -- When the predicate pragma applies to the current type or its
8301 -- full view, replace all occurrences of the subtype name with
8302 -- references to the formal parameter of the predicate function.
8304 if Entity (Arg1) = Typ
8305 or else Full_View (Entity (Arg1)) = Typ
8307 Replace_Type_References (Arg2, Typ);
8309 -- If the predicate pragma comes from an aspect, replace the
8310 -- saved expression because we need the subtype references
8311 -- replaced for the calls to Preanalyze_Spec_Expression in
8312 -- Check_Aspect_At_xxx routines.
8314 if Present (Asp) then
8315 Set_Entity (Identifier (Asp), New_Copy_Tree (Arg2));
8318 -- "and"-in the Arg2 condition to evolving expression
8320 Add_Condition (Relocate_Node (Arg2));
8328 -- Start of processing for Add_Predicates
8331 Ritem := First_Rep_Item (Typ);
8332 while Present (Ritem) loop
8333 if Nkind (Ritem) = N_Pragma
8334 and then Pragma_Name (Ritem) = Name_Predicate
8336 Add_Predicate (Ritem);
8338 -- If the type is declared in an inner package it may be frozen
8339 -- outside of the package, and the generated pragma has not been
8340 -- analyzed yet, so capture the expression for the predicate
8341 -- function at this point.
8343 elsif Nkind (Ritem) = N_Aspect_Specification
8344 and then Present (Aspect_Rep_Item (Ritem))
8345 and then Scope (Typ) /= Current_Scope
8348 Prag : constant Node_Id := Aspect_Rep_Item (Ritem);
8351 if Nkind (Prag) = N_Pragma
8352 and then Pragma_Name (Prag) = Name_Predicate
8354 Add_Predicate (Prag);
8359 Next_Rep_Item (Ritem);
8367 function Process_RE (N : Node_Id) return Traverse_Result is
8369 if Nkind (N) = N_Raise_Expression then
8370 Set_Convert_To_Return_False (N);
8381 function Test_RE (N : Node_Id) return Traverse_Result is
8383 if Nkind (N) = N_Raise_Expression then
8384 Raise_Expression_Present := True;
8393 Save_Ghost_Mode : constant Ghost_Mode_Type := Ghost_Mode;
8395 -- Start of processing for Build_Predicate_Functions
8398 -- Return if already built or if type does not have predicates
8400 SId := Predicate_Function (Typ);
8401 if not Has_Predicates (Typ)
8402 or else (Present (SId) and then Has_Completion (SId))
8407 -- The related type may be subject to pragma Ghost. Set the mode now to
8408 -- ensure that the predicate functions are properly marked as Ghost.
8410 Set_Ghost_Mode_From_Entity (Typ);
8412 -- Prepare to construct predicate expression
8416 if Present (SId) then
8417 FDecl := Unit_Declaration_Node (SId);
8420 FDecl := Build_Predicate_Function_Declaration (Typ);
8421 SId := Defining_Entity (FDecl);
8424 -- Recover name of formal parameter of function that replaces references
8425 -- to the type in predicate expressions.
8429 (First (Parameter_Specifications (Specification (FDecl))));
8431 Object_Name := Chars (Object_Entity);
8432 Object_Entity_M := Make_Defining_Identifier (Loc, Chars => Object_Name);
8434 -- Add predicates for ancestor if present. These must come before the
8435 -- ones for the current type, as required by AI12-0071-1.
8438 Atyp : constant Entity_Id := Nearest_Ancestor (Typ);
8440 if Present (Atyp) then
8445 -- Add Predicates for the current type
8449 -- Case where predicates are present
8451 if Present (Expr) then
8453 -- Test for raise expression present
8457 -- If raise expression is present, capture a copy of Expr for use
8458 -- in building the predicateM function version later on. For this
8459 -- copy we replace references to Object_Entity by Object_Entity_M.
8461 if Raise_Expression_Present then
8463 Map : constant Elist_Id := New_Elmt_List;
8464 New_V : Entity_Id := Empty;
8466 -- The unanalyzed expression will be copied and appear in
8467 -- both functions. Normally expressions do not declare new
8468 -- entities, but quantified expressions do, so we need to
8469 -- create new entities for their bound variables, to prevent
8470 -- multiple definitions in gigi.
8472 function Reset_Loop_Variable (N : Node_Id)
8473 return Traverse_Result;
8475 procedure Collect_Loop_Variables is
8476 new Traverse_Proc (Reset_Loop_Variable);
8478 ------------------------
8479 -- Reset_Loop_Variable --
8480 ------------------------
8482 function Reset_Loop_Variable (N : Node_Id)
8483 return Traverse_Result
8486 if Nkind (N) = N_Iterator_Specification then
8487 New_V := Make_Defining_Identifier
8488 (Sloc (N), Chars (Defining_Identifier (N)));
8490 Set_Defining_Identifier (N, New_V);
8494 end Reset_Loop_Variable;
8497 Append_Elmt (Object_Entity, Map);
8498 Append_Elmt (Object_Entity_M, Map);
8499 Expr_M := New_Copy_Tree (Expr, Map => Map);
8500 Collect_Loop_Variables (Expr_M);
8504 -- Build the main predicate function
8507 SIdB : constant Entity_Id :=
8508 Make_Defining_Identifier (Loc,
8509 Chars => New_External_Name (Chars (Typ), "Predicate"));
8510 -- The entity for the function body
8517 -- The predicate function is shared between views of a type
8519 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
8520 Set_Predicate_Function (Full_View (Typ), SId);
8523 -- Mark the predicate function explicitly as Ghost because it does
8524 -- not come from source.
8526 if Ghost_Mode > None then
8527 Set_Is_Ghost_Entity (SId);
8530 -- Build function body
8533 Make_Function_Specification (Loc,
8534 Defining_Unit_Name => SIdB,
8535 Parameter_Specifications => New_List (
8536 Make_Parameter_Specification (Loc,
8537 Defining_Identifier =>
8538 Make_Defining_Identifier (Loc, Object_Name),
8540 New_Occurrence_Of (Typ, Loc))),
8541 Result_Definition =>
8542 New_Occurrence_Of (Standard_Boolean, Loc));
8545 Make_Subprogram_Body (Loc,
8546 Specification => Spec,
8547 Declarations => Empty_List,
8548 Handled_Statement_Sequence =>
8549 Make_Handled_Sequence_Of_Statements (Loc,
8550 Statements => New_List (
8551 Make_Simple_Return_Statement (Loc,
8552 Expression => Expr))));
8554 -- If declaration has not been analyzed yet, Insert declaration
8555 -- before freeze node.
8556 -- Insert body after freeze node.
8558 if not Analyzed (FDecl) then
8559 Insert_Before_And_Analyze (N, FDecl);
8562 Insert_After_And_Analyze (N, FBody);
8564 -- Static predicate functions are always side-effect free, and
8565 -- in most cases dynamic predicate functions are as well. Mark
8566 -- them as such whenever possible, so redundant predicate checks
8567 -- can be optimized. If there is a variable reference within the
8568 -- expression, the function is not pure.
8570 if Expander_Active then
8572 Side_Effect_Free (Expr, Variable_Ref => True));
8573 Set_Is_Inlined (SId);
8577 -- Test for raise expressions present and if so build M version
8579 if Raise_Expression_Present then
8581 SId : constant Entity_Id :=
8582 Make_Defining_Identifier (Loc,
8583 Chars => New_External_Name (Chars (Typ), "PredicateM"));
8584 -- The entity for the function spec
8586 SIdB : constant Entity_Id :=
8587 Make_Defining_Identifier (Loc,
8588 Chars => New_External_Name (Chars (Typ), "PredicateM"));
8589 -- The entity for the function body
8597 -- Mark any raise expressions for special expansion
8599 Process_REs (Expr_M);
8601 -- Build function declaration
8603 Set_Ekind (SId, E_Function);
8604 Set_Is_Predicate_Function_M (SId);
8605 Set_Predicate_Function_M (Typ, SId);
8607 -- The predicate function is shared between views of a type
8609 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
8610 Set_Predicate_Function_M (Full_View (Typ), SId);
8613 -- Mark the predicate function explicitly as Ghost because it
8614 -- does not come from source.
8616 if Ghost_Mode > None then
8617 Set_Is_Ghost_Entity (SId);
8621 Make_Function_Specification (Loc,
8622 Defining_Unit_Name => SId,
8623 Parameter_Specifications => New_List (
8624 Make_Parameter_Specification (Loc,
8625 Defining_Identifier => Object_Entity_M,
8626 Parameter_Type => New_Occurrence_Of (Typ, Loc))),
8627 Result_Definition =>
8628 New_Occurrence_Of (Standard_Boolean, Loc));
8631 Make_Subprogram_Declaration (Loc,
8632 Specification => Spec);
8634 -- Build function body
8637 Make_Function_Specification (Loc,
8638 Defining_Unit_Name => SIdB,
8639 Parameter_Specifications => New_List (
8640 Make_Parameter_Specification (Loc,
8641 Defining_Identifier =>
8642 Make_Defining_Identifier (Loc, Object_Name),
8644 New_Occurrence_Of (Typ, Loc))),
8645 Result_Definition =>
8646 New_Occurrence_Of (Standard_Boolean, Loc));
8648 -- Build the body, we declare the boolean expression before
8649 -- doing the return, because we are not really confident of
8650 -- what happens if a return appears within a return.
8653 Make_Defining_Identifier (Loc,
8654 Chars => New_Internal_Name ('B'));
8657 Make_Subprogram_Body (Loc,
8658 Specification => Spec,
8660 Declarations => New_List (
8661 Make_Object_Declaration (Loc,
8662 Defining_Identifier => BTemp,
8663 Constant_Present => True,
8664 Object_Definition =>
8665 New_Occurrence_Of (Standard_Boolean, Loc),
8666 Expression => Expr_M)),
8668 Handled_Statement_Sequence =>
8669 Make_Handled_Sequence_Of_Statements (Loc,
8670 Statements => New_List (
8671 Make_Simple_Return_Statement (Loc,
8672 Expression => New_Occurrence_Of (BTemp, Loc)))));
8674 -- Insert declaration before freeze node and body after
8676 Insert_Before_And_Analyze (N, FDecl);
8677 Insert_After_And_Analyze (N, FBody);
8681 -- See if we have a static predicate. Note that the answer may be
8682 -- yes even if we have an explicit Dynamic_Predicate present.
8689 if not Is_Scalar_Type (Typ) and then not Is_String_Type (Typ) then
8692 PS := Is_Predicate_Static (Expr, Object_Name);
8695 -- Case where we have a predicate-static aspect
8699 -- We don't set Has_Static_Predicate_Aspect, since we can have
8700 -- any of the three cases (Predicate, Dynamic_Predicate, or
8701 -- Static_Predicate) generating a predicate with an expression
8702 -- that is predicate-static. We just indicate that we have a
8703 -- predicate that can be treated as static.
8705 Set_Has_Static_Predicate (Typ);
8707 -- For discrete subtype, build the static predicate list
8709 if Is_Discrete_Type (Typ) then
8710 Build_Discrete_Static_Predicate (Typ, Expr, Object_Name);
8712 -- If we don't get a static predicate list, it means that we
8713 -- have a case where this is not possible, most typically in
8714 -- the case where we inherit a dynamic predicate. We do not
8715 -- consider this an error, we just leave the predicate as
8716 -- dynamic. But if we do succeed in building the list, then
8717 -- we mark the predicate as static.
8719 if No (Static_Discrete_Predicate (Typ)) then
8720 Set_Has_Static_Predicate (Typ, False);
8723 -- For real or string subtype, save predicate expression
8725 elsif Is_Real_Type (Typ) or else Is_String_Type (Typ) then
8726 Set_Static_Real_Or_String_Predicate (Typ, Expr);
8729 -- Case of dynamic predicate (expression is not predicate-static)
8732 -- Again, we don't set Has_Dynamic_Predicate_Aspect, since that
8733 -- is only set if we have an explicit Dynamic_Predicate aspect
8734 -- given. Here we may simply have a Predicate aspect where the
8735 -- expression happens not to be predicate-static.
8737 -- Emit an error when the predicate is categorized as static
8738 -- but its expression is not predicate-static.
8740 -- First a little fiddling to get a nice location for the
8741 -- message. If the expression is of the form (A and then B),
8742 -- where A is an inherited predicate, then use the right
8743 -- operand for the Sloc. This avoids getting confused by a call
8744 -- to an inherited predicate with a less convenient source
8748 while Nkind (EN) = N_And_Then
8749 and then Nkind (Left_Opnd (EN)) = N_Function_Call
8750 and then Is_Predicate_Function
8751 (Entity (Name (Left_Opnd (EN))))
8753 EN := Right_Opnd (EN);
8756 -- Now post appropriate message
8758 if Has_Static_Predicate_Aspect (Typ) then
8759 if Is_Scalar_Type (Typ) or else Is_String_Type (Typ) then
8761 ("expression is not predicate-static (RM 3.2.4(16-22))",
8765 ("static predicate requires scalar or string type", EN);
8772 Ghost_Mode := Save_Ghost_Mode;
8773 end Build_Predicate_Functions;
8775 ------------------------------------------
8776 -- Build_Predicate_Function_Declaration --
8777 ------------------------------------------
8779 function Build_Predicate_Function_Declaration
8780 (Typ : Entity_Id) return Node_Id
8782 Loc : constant Source_Ptr := Sloc (Typ);
8784 Object_Entity : constant Entity_Id :=
8785 Make_Defining_Identifier (Loc,
8786 Chars => New_Internal_Name ('I'));
8788 -- The formal parameter of the function
8790 SId : constant Entity_Id :=
8791 Make_Defining_Identifier (Loc,
8792 Chars => New_External_Name (Chars (Typ), "Predicate"));
8794 -- The entity for the function spec
8801 Make_Function_Specification (Loc,
8802 Defining_Unit_Name => SId,
8803 Parameter_Specifications => New_List (
8804 Make_Parameter_Specification (Loc,
8805 Defining_Identifier => Object_Entity,
8806 Parameter_Type => New_Occurrence_Of (Typ, Loc))),
8807 Result_Definition =>
8808 New_Occurrence_Of (Standard_Boolean, Loc));
8810 FDecl := Make_Subprogram_Declaration (Loc, Specification => Spec);
8812 Set_Ekind (SId, E_Function);
8813 Set_Etype (SId, Standard_Boolean);
8814 Set_Is_Internal (SId);
8815 Set_Is_Predicate_Function (SId);
8816 Set_Predicate_Function (Typ, SId);
8818 Insert_After (Parent (Typ), FDecl);
8823 end Build_Predicate_Function_Declaration;
8825 -----------------------------------------
8826 -- Check_Aspect_At_End_Of_Declarations --
8827 -----------------------------------------
8829 procedure Check_Aspect_At_End_Of_Declarations (ASN : Node_Id) is
8830 Ent : constant Entity_Id := Entity (ASN);
8831 Ident : constant Node_Id := Identifier (ASN);
8832 A_Id : constant Aspect_Id := Get_Aspect_Id (Chars (Ident));
8834 End_Decl_Expr : constant Node_Id := Entity (Ident);
8835 -- Expression to be analyzed at end of declarations
8837 Freeze_Expr : constant Node_Id := Expression (ASN);
8838 -- Expression from call to Check_Aspect_At_Freeze_Point
8840 T : constant Entity_Id := Etype (Freeze_Expr);
8841 -- Type required for preanalyze call
8844 -- Set False if error
8846 -- On entry to this procedure, Entity (Ident) contains a copy of the
8847 -- original expression from the aspect, saved for this purpose, and
8848 -- but Expression (Ident) is a preanalyzed copy of the expression,
8849 -- preanalyzed just after the freeze point.
8851 procedure Check_Overloaded_Name;
8852 -- For aspects whose expression is simply a name, this routine checks if
8853 -- the name is overloaded or not. If so, it verifies there is an
8854 -- interpretation that matches the entity obtained at the freeze point,
8855 -- otherwise the compiler complains.
8857 ---------------------------
8858 -- Check_Overloaded_Name --
8859 ---------------------------
8861 procedure Check_Overloaded_Name is
8863 if not Is_Overloaded (End_Decl_Expr) then
8864 Err := not Is_Entity_Name (End_Decl_Expr)
8865 or else Entity (End_Decl_Expr) /= Entity (Freeze_Expr);
8871 Index : Interp_Index;
8875 Get_First_Interp (End_Decl_Expr, Index, It);
8876 while Present (It.Typ) loop
8877 if It.Nam = Entity (Freeze_Expr) then
8882 Get_Next_Interp (Index, It);
8886 end Check_Overloaded_Name;
8888 -- Start of processing for Check_Aspect_At_End_Of_Declarations
8891 -- In an instance we do not perform the consistency check between freeze
8892 -- point and end of declarations, because it was done already in the
8893 -- analysis of the generic. Furthermore, the delayed analysis of an
8894 -- aspect of the instance may produce spurious errors when the generic
8895 -- is a child unit that references entities in the parent (which might
8896 -- not be in scope at the freeze point of the instance).
8901 -- Case of aspects Dimension, Dimension_System and Synchronization
8903 elsif A_Id = Aspect_Synchronization then
8906 -- Case of stream attributes, just have to compare entities. However,
8907 -- the expression is just a name (possibly overloaded), and there may
8908 -- be stream operations declared for unrelated types, so we just need
8909 -- to verify that one of these interpretations is the one available at
8910 -- at the freeze point.
8912 elsif A_Id = Aspect_Input or else
8913 A_Id = Aspect_Output or else
8914 A_Id = Aspect_Read or else
8917 Analyze (End_Decl_Expr);
8918 Check_Overloaded_Name;
8920 elsif A_Id = Aspect_Variable_Indexing or else
8921 A_Id = Aspect_Constant_Indexing or else
8922 A_Id = Aspect_Default_Iterator or else
8923 A_Id = Aspect_Iterator_Element
8925 -- Make type unfrozen before analysis, to prevent spurious errors
8926 -- about late attributes.
8928 Set_Is_Frozen (Ent, False);
8929 Analyze (End_Decl_Expr);
8930 Set_Is_Frozen (Ent, True);
8932 -- If the end of declarations comes before any other freeze
8933 -- point, the Freeze_Expr is not analyzed: no check needed.
8935 if Analyzed (Freeze_Expr) and then not In_Instance then
8936 Check_Overloaded_Name;
8944 -- Indicate that the expression comes from an aspect specification,
8945 -- which is used in subsequent analysis even if expansion is off.
8947 Set_Parent (End_Decl_Expr, ASN);
8949 -- In a generic context the aspect expressions have not been
8950 -- preanalyzed, so do it now. There are no conformance checks
8951 -- to perform in this case.
8954 Check_Aspect_At_Freeze_Point (ASN);
8957 -- The default values attributes may be defined in the private part,
8958 -- and the analysis of the expression may take place when only the
8959 -- partial view is visible. The expression must be scalar, so use
8960 -- the full view to resolve.
8962 elsif (A_Id = Aspect_Default_Value
8964 A_Id = Aspect_Default_Component_Value)
8965 and then Is_Private_Type (T)
8967 Preanalyze_Spec_Expression (End_Decl_Expr, Full_View (T));
8970 Preanalyze_Spec_Expression (End_Decl_Expr, T);
8973 Err := not Fully_Conformant_Expressions (End_Decl_Expr, Freeze_Expr);
8976 -- Output error message if error. Force error on aspect specification
8977 -- even if there is an error on the expression itself.
8981 ("!visibility of aspect for& changes after freeze point",
8984 ("info: & is frozen here, aspects evaluated at this point??",
8985 Freeze_Node (Ent), Ent);
8987 end Check_Aspect_At_End_Of_Declarations;
8989 ----------------------------------
8990 -- Check_Aspect_At_Freeze_Point --
8991 ----------------------------------
8993 procedure Check_Aspect_At_Freeze_Point (ASN : Node_Id) is
8994 Ident : constant Node_Id := Identifier (ASN);
8995 -- Identifier (use Entity field to save expression)
8997 A_Id : constant Aspect_Id := Get_Aspect_Id (Chars (Ident));
8999 T : Entity_Id := Empty;
9000 -- Type required for preanalyze call
9003 -- On entry to this procedure, Entity (Ident) contains a copy of the
9004 -- original expression from the aspect, saved for this purpose.
9006 -- On exit from this procedure Entity (Ident) is unchanged, still
9007 -- containing that copy, but Expression (Ident) is a preanalyzed copy
9008 -- of the expression, preanalyzed just after the freeze point.
9010 -- Make a copy of the expression to be preanalyzed
9012 Set_Expression (ASN, New_Copy_Tree (Entity (Ident)));
9014 -- Find type for preanalyze call
9018 -- No_Aspect should be impossible
9021 raise Program_Error;
9023 -- Aspects taking an optional boolean argument
9025 when Boolean_Aspects |
9026 Library_Unit_Aspects =>
9028 T := Standard_Boolean;
9030 -- Aspects corresponding to attribute definition clauses
9032 when Aspect_Address =>
9033 T := RTE (RE_Address);
9035 when Aspect_Attach_Handler =>
9036 T := RTE (RE_Interrupt_ID);
9038 when Aspect_Bit_Order | Aspect_Scalar_Storage_Order =>
9039 T := RTE (RE_Bit_Order);
9041 when Aspect_Convention =>
9045 T := RTE (RE_CPU_Range);
9047 -- Default_Component_Value is resolved with the component type
9049 when Aspect_Default_Component_Value =>
9050 T := Component_Type (Entity (ASN));
9052 when Aspect_Default_Storage_Pool =>
9053 T := Class_Wide_Type (RTE (RE_Root_Storage_Pool));
9055 -- Default_Value is resolved with the type entity in question
9057 when Aspect_Default_Value =>
9060 when Aspect_Dispatching_Domain =>
9061 T := RTE (RE_Dispatching_Domain);
9063 when Aspect_External_Tag =>
9064 T := Standard_String;
9066 when Aspect_External_Name =>
9067 T := Standard_String;
9069 when Aspect_Link_Name =>
9070 T := Standard_String;
9072 when Aspect_Priority | Aspect_Interrupt_Priority =>
9073 T := Standard_Integer;
9075 when Aspect_Relative_Deadline =>
9076 T := RTE (RE_Time_Span);
9078 when Aspect_Small =>
9079 T := Universal_Real;
9081 -- For a simple storage pool, we have to retrieve the type of the
9082 -- pool object associated with the aspect's corresponding attribute
9083 -- definition clause.
9085 when Aspect_Simple_Storage_Pool =>
9086 T := Etype (Expression (Aspect_Rep_Item (ASN)));
9088 when Aspect_Storage_Pool =>
9089 T := Class_Wide_Type (RTE (RE_Root_Storage_Pool));
9091 when Aspect_Alignment |
9092 Aspect_Component_Size |
9093 Aspect_Machine_Radix |
9094 Aspect_Object_Size |
9096 Aspect_Storage_Size |
9097 Aspect_Stream_Size |
9098 Aspect_Value_Size =>
9101 when Aspect_Linker_Section =>
9102 T := Standard_String;
9104 when Aspect_Synchronization =>
9107 -- Special case, the expression of these aspects is just an entity
9108 -- that does not need any resolution, so just analyze.
9117 Analyze (Expression (ASN));
9120 -- Same for Iterator aspects, where the expression is a function
9121 -- name. Legality rules are checked separately.
9123 when Aspect_Constant_Indexing |
9124 Aspect_Default_Iterator |
9125 Aspect_Iterator_Element |
9126 Aspect_Variable_Indexing =>
9127 Analyze (Expression (ASN));
9130 -- Ditto for Iterable, legality checks in Validate_Iterable_Aspect.
9132 when Aspect_Iterable =>
9136 Cursor : constant Entity_Id := Get_Cursor_Type (ASN, T);
9141 if Cursor = Any_Type then
9145 Assoc := First (Component_Associations (Expression (ASN)));
9146 while Present (Assoc) loop
9147 Expr := Expression (Assoc);
9150 if not Error_Posted (Expr) then
9151 Resolve_Iterable_Operation
9152 (Expr, Cursor, T, Chars (First (Choices (Assoc))));
9161 -- Invariant/Predicate take boolean expressions
9163 when Aspect_Dynamic_Predicate |
9166 Aspect_Static_Predicate |
9167 Aspect_Type_Invariant =>
9168 T := Standard_Boolean;
9170 when Aspect_Predicate_Failure =>
9171 T := Standard_String;
9173 -- Here is the list of aspects that don't require delay analysis
9175 when Aspect_Abstract_State |
9177 Aspect_Async_Readers |
9178 Aspect_Async_Writers |
9179 Aspect_Constant_After_Elaboration |
9180 Aspect_Contract_Cases |
9181 Aspect_Default_Initial_Condition |
9184 Aspect_Dimension_System |
9185 Aspect_Effective_Reads |
9186 Aspect_Effective_Writes |
9187 Aspect_Extensions_Visible |
9190 Aspect_Implicit_Dereference |
9191 Aspect_Initial_Condition |
9192 Aspect_Initializes |
9193 Aspect_Obsolescent |
9196 Aspect_Postcondition |
9198 Aspect_Precondition |
9199 Aspect_Refined_Depends |
9200 Aspect_Refined_Global |
9201 Aspect_Refined_Post |
9202 Aspect_Refined_State |
9205 Aspect_Unimplemented |
9206 Aspect_Volatile_Function =>
9207 raise Program_Error;
9211 -- Do the preanalyze call
9213 Preanalyze_Spec_Expression (Expression (ASN), T);
9214 end Check_Aspect_At_Freeze_Point;
9216 -----------------------------------
9217 -- Check_Constant_Address_Clause --
9218 -----------------------------------
9220 procedure Check_Constant_Address_Clause
9224 procedure Check_At_Constant_Address (Nod : Node_Id);
9225 -- Checks that the given node N represents a name whose 'Address is
9226 -- constant (in the same sense as OK_Constant_Address_Clause, i.e. the
9227 -- address value is the same at the point of declaration of U_Ent and at
9228 -- the time of elaboration of the address clause.
9230 procedure Check_Expr_Constants (Nod : Node_Id);
9231 -- Checks that Nod meets the requirements for a constant address clause
9232 -- in the sense of the enclosing procedure.
9234 procedure Check_List_Constants (Lst : List_Id);
9235 -- Check that all elements of list Lst meet the requirements for a
9236 -- constant address clause in the sense of the enclosing procedure.
9238 -------------------------------
9239 -- Check_At_Constant_Address --
9240 -------------------------------
9242 procedure Check_At_Constant_Address (Nod : Node_Id) is
9244 if Is_Entity_Name (Nod) then
9245 if Present (Address_Clause (Entity ((Nod)))) then
9247 ("invalid address clause for initialized object &!",
9250 ("address for& cannot" &
9251 " depend on another address clause! (RM 13.1(22))!",
9254 elsif In_Same_Source_Unit (Entity (Nod), U_Ent)
9255 and then Sloc (U_Ent) < Sloc (Entity (Nod))
9258 ("invalid address clause for initialized object &!",
9260 Error_Msg_Node_2 := U_Ent;
9262 ("\& must be defined before & (RM 13.1(22))!",
9266 elsif Nkind (Nod) = N_Selected_Component then
9268 T : constant Entity_Id := Etype (Prefix (Nod));
9271 if (Is_Record_Type (T)
9272 and then Has_Discriminants (T))
9275 and then Is_Record_Type (Designated_Type (T))
9276 and then Has_Discriminants (Designated_Type (T)))
9279 ("invalid address clause for initialized object &!",
9282 ("\address cannot depend on component" &
9283 " of discriminated record (RM 13.1(22))!",
9286 Check_At_Constant_Address (Prefix (Nod));
9290 elsif Nkind (Nod) = N_Indexed_Component then
9291 Check_At_Constant_Address (Prefix (Nod));
9292 Check_List_Constants (Expressions (Nod));
9295 Check_Expr_Constants (Nod);
9297 end Check_At_Constant_Address;
9299 --------------------------
9300 -- Check_Expr_Constants --
9301 --------------------------
9303 procedure Check_Expr_Constants (Nod : Node_Id) is
9304 Loc_U_Ent : constant Source_Ptr := Sloc (U_Ent);
9305 Ent : Entity_Id := Empty;
9308 if Nkind (Nod) in N_Has_Etype
9309 and then Etype (Nod) = Any_Type
9315 when N_Empty | N_Error =>
9318 when N_Identifier | N_Expanded_Name =>
9319 Ent := Entity (Nod);
9321 -- We need to look at the original node if it is different
9322 -- from the node, since we may have rewritten things and
9323 -- substituted an identifier representing the rewrite.
9325 if Original_Node (Nod) /= Nod then
9326 Check_Expr_Constants (Original_Node (Nod));
9328 -- If the node is an object declaration without initial
9329 -- value, some code has been expanded, and the expression
9330 -- is not constant, even if the constituents might be
9331 -- acceptable, as in A'Address + offset.
9333 if Ekind (Ent) = E_Variable
9335 Nkind (Declaration_Node (Ent)) = N_Object_Declaration
9337 No (Expression (Declaration_Node (Ent)))
9340 ("invalid address clause for initialized object &!",
9343 -- If entity is constant, it may be the result of expanding
9344 -- a check. We must verify that its declaration appears
9345 -- before the object in question, else we also reject the
9348 elsif Ekind (Ent) = E_Constant
9349 and then In_Same_Source_Unit (Ent, U_Ent)
9350 and then Sloc (Ent) > Loc_U_Ent
9353 ("invalid address clause for initialized object &!",
9360 -- Otherwise look at the identifier and see if it is OK
9362 if Ekind_In (Ent, E_Named_Integer, E_Named_Real)
9363 or else Is_Type (Ent)
9367 elsif Ekind_In (Ent, E_Constant, E_In_Parameter) then
9369 -- This is the case where we must have Ent defined before
9370 -- U_Ent. Clearly if they are in different units this
9371 -- requirement is met since the unit containing Ent is
9372 -- already processed.
9374 if not In_Same_Source_Unit (Ent, U_Ent) then
9377 -- Otherwise location of Ent must be before the location
9378 -- of U_Ent, that's what prior defined means.
9380 elsif Sloc (Ent) < Loc_U_Ent then
9385 ("invalid address clause for initialized object &!",
9387 Error_Msg_Node_2 := U_Ent;
9389 ("\& must be defined before & (RM 13.1(22))!",
9393 elsif Nkind (Original_Node (Nod)) = N_Function_Call then
9394 Check_Expr_Constants (Original_Node (Nod));
9398 ("invalid address clause for initialized object &!",
9401 if Comes_From_Source (Ent) then
9403 ("\reference to variable& not allowed"
9404 & " (RM 13.1(22))!", Nod, Ent);
9407 ("non-static expression not allowed"
9408 & " (RM 13.1(22))!", Nod);
9412 when N_Integer_Literal =>
9414 -- If this is a rewritten unchecked conversion, in a system
9415 -- where Address is an integer type, always use the base type
9416 -- for a literal value. This is user-friendly and prevents
9417 -- order-of-elaboration issues with instances of unchecked
9420 if Nkind (Original_Node (Nod)) = N_Function_Call then
9421 Set_Etype (Nod, Base_Type (Etype (Nod)));
9424 when N_Real_Literal |
9426 N_Character_Literal =>
9430 Check_Expr_Constants (Low_Bound (Nod));
9431 Check_Expr_Constants (High_Bound (Nod));
9433 when N_Explicit_Dereference =>
9434 Check_Expr_Constants (Prefix (Nod));
9436 when N_Indexed_Component =>
9437 Check_Expr_Constants (Prefix (Nod));
9438 Check_List_Constants (Expressions (Nod));
9441 Check_Expr_Constants (Prefix (Nod));
9442 Check_Expr_Constants (Discrete_Range (Nod));
9444 when N_Selected_Component =>
9445 Check_Expr_Constants (Prefix (Nod));
9447 when N_Attribute_Reference =>
9448 if Nam_In (Attribute_Name (Nod), Name_Address,
9450 Name_Unchecked_Access,
9451 Name_Unrestricted_Access)
9453 Check_At_Constant_Address (Prefix (Nod));
9456 Check_Expr_Constants (Prefix (Nod));
9457 Check_List_Constants (Expressions (Nod));
9461 Check_List_Constants (Component_Associations (Nod));
9462 Check_List_Constants (Expressions (Nod));
9464 when N_Component_Association =>
9465 Check_Expr_Constants (Expression (Nod));
9467 when N_Extension_Aggregate =>
9468 Check_Expr_Constants (Ancestor_Part (Nod));
9469 Check_List_Constants (Component_Associations (Nod));
9470 Check_List_Constants (Expressions (Nod));
9475 when N_Binary_Op | N_Short_Circuit | N_Membership_Test =>
9476 Check_Expr_Constants (Left_Opnd (Nod));
9477 Check_Expr_Constants (Right_Opnd (Nod));
9480 Check_Expr_Constants (Right_Opnd (Nod));
9482 when N_Type_Conversion |
9483 N_Qualified_Expression |
9485 N_Unchecked_Type_Conversion =>
9486 Check_Expr_Constants (Expression (Nod));
9488 when N_Function_Call =>
9489 if not Is_Pure (Entity (Name (Nod))) then
9491 ("invalid address clause for initialized object &!",
9495 ("\function & is not pure (RM 13.1(22))!",
9496 Nod, Entity (Name (Nod)));
9499 Check_List_Constants (Parameter_Associations (Nod));
9502 when N_Parameter_Association =>
9503 Check_Expr_Constants (Explicit_Actual_Parameter (Nod));
9507 ("invalid address clause for initialized object &!",
9510 ("\must be constant defined before& (RM 13.1(22))!",
9513 end Check_Expr_Constants;
9515 --------------------------
9516 -- Check_List_Constants --
9517 --------------------------
9519 procedure Check_List_Constants (Lst : List_Id) is
9523 if Present (Lst) then
9524 Nod1 := First (Lst);
9525 while Present (Nod1) loop
9526 Check_Expr_Constants (Nod1);
9530 end Check_List_Constants;
9532 -- Start of processing for Check_Constant_Address_Clause
9535 -- If rep_clauses are to be ignored, no need for legality checks. In
9536 -- particular, no need to pester user about rep clauses that violate the
9537 -- rule on constant addresses, given that these clauses will be removed
9538 -- by Freeze before they reach the back end. Similarly in CodePeer mode,
9539 -- we want to relax these checks.
9541 if not Ignore_Rep_Clauses and not CodePeer_Mode then
9542 Check_Expr_Constants (Expr);
9544 end Check_Constant_Address_Clause;
9546 ---------------------------
9547 -- Check_Pool_Size_Clash --
9548 ---------------------------
9550 procedure Check_Pool_Size_Clash (Ent : Entity_Id; SP, SS : Node_Id) is
9554 -- We need to find out which one came first. Note that in the case of
9555 -- aspects mixed with pragmas there are cases where the processing order
9556 -- is reversed, which is why we do the check here.
9558 if Sloc (SP) < Sloc (SS) then
9559 Error_Msg_Sloc := Sloc (SP);
9561 Error_Msg_NE ("Storage_Pool previously given for&#", Post, Ent);
9564 Error_Msg_Sloc := Sloc (SS);
9566 Error_Msg_NE ("Storage_Size previously given for&#", Post, Ent);
9570 ("\cannot have Storage_Size and Storage_Pool (RM 13.11(3))", Post);
9571 end Check_Pool_Size_Clash;
9573 ----------------------------------------
9574 -- Check_Record_Representation_Clause --
9575 ----------------------------------------
9577 procedure Check_Record_Representation_Clause (N : Node_Id) is
9578 Loc : constant Source_Ptr := Sloc (N);
9579 Ident : constant Node_Id := Identifier (N);
9580 Rectype : Entity_Id;
9585 Hbit : Uint := Uint_0;
9589 Max_Bit_So_Far : Uint;
9590 -- Records the maximum bit position so far. If all field positions
9591 -- are monotonically increasing, then we can skip the circuit for
9592 -- checking for overlap, since no overlap is possible.
9594 Tagged_Parent : Entity_Id := Empty;
9595 -- This is set in the case of a derived tagged type for which we have
9596 -- Is_Fully_Repped_Tagged_Type True (indicating that all components are
9597 -- positioned by record representation clauses). In this case we must
9598 -- check for overlap between components of this tagged type, and the
9599 -- components of its parent. Tagged_Parent will point to this parent
9600 -- type. For all other cases Tagged_Parent is left set to Empty.
9602 Parent_Last_Bit : Uint;
9603 -- Relevant only if Tagged_Parent is set, Parent_Last_Bit indicates the
9604 -- last bit position for any field in the parent type. We only need to
9605 -- check overlap for fields starting below this point.
9607 Overlap_Check_Required : Boolean;
9608 -- Used to keep track of whether or not an overlap check is required
9610 Overlap_Detected : Boolean := False;
9611 -- Set True if an overlap is detected
9613 Ccount : Natural := 0;
9614 -- Number of component clauses in record rep clause
9616 procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id);
9617 -- Given two entities for record components or discriminants, checks
9618 -- if they have overlapping component clauses and issues errors if so.
9620 procedure Find_Component;
9621 -- Finds component entity corresponding to current component clause (in
9622 -- CC), and sets Comp to the entity, and Fbit/Lbit to the zero origin
9623 -- start/stop bits for the field. If there is no matching component or
9624 -- if the matching component does not have a component clause, then
9625 -- that's an error and Comp is set to Empty, but no error message is
9626 -- issued, since the message was already given. Comp is also set to
9627 -- Empty if the current "component clause" is in fact a pragma.
9629 -----------------------------
9630 -- Check_Component_Overlap --
9631 -----------------------------
9633 procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id) is
9634 CC1 : constant Node_Id := Component_Clause (C1_Ent);
9635 CC2 : constant Node_Id := Component_Clause (C2_Ent);
9638 if Present (CC1) and then Present (CC2) then
9640 -- Exclude odd case where we have two tag components in the same
9641 -- record, both at location zero. This seems a bit strange, but
9642 -- it seems to happen in some circumstances, perhaps on an error.
9644 if Nam_In (Chars (C1_Ent), Name_uTag, Name_uTag) then
9648 -- Here we check if the two fields overlap
9651 S1 : constant Uint := Component_Bit_Offset (C1_Ent);
9652 S2 : constant Uint := Component_Bit_Offset (C2_Ent);
9653 E1 : constant Uint := S1 + Esize (C1_Ent);
9654 E2 : constant Uint := S2 + Esize (C2_Ent);
9657 if E2 <= S1 or else E1 <= S2 then
9660 Error_Msg_Node_2 := Component_Name (CC2);
9661 Error_Msg_Sloc := Sloc (Error_Msg_Node_2);
9662 Error_Msg_Node_1 := Component_Name (CC1);
9664 ("component& overlaps & #", Component_Name (CC1));
9665 Overlap_Detected := True;
9669 end Check_Component_Overlap;
9671 --------------------
9672 -- Find_Component --
9673 --------------------
9675 procedure Find_Component is
9677 procedure Search_Component (R : Entity_Id);
9678 -- Search components of R for a match. If found, Comp is set
9680 ----------------------
9681 -- Search_Component --
9682 ----------------------
9684 procedure Search_Component (R : Entity_Id) is
9686 Comp := First_Component_Or_Discriminant (R);
9687 while Present (Comp) loop
9689 -- Ignore error of attribute name for component name (we
9690 -- already gave an error message for this, so no need to
9693 if Nkind (Component_Name (CC)) = N_Attribute_Reference then
9696 exit when Chars (Comp) = Chars (Component_Name (CC));
9699 Next_Component_Or_Discriminant (Comp);
9701 end Search_Component;
9703 -- Start of processing for Find_Component
9706 -- Return with Comp set to Empty if we have a pragma
9708 if Nkind (CC) = N_Pragma then
9713 -- Search current record for matching component
9715 Search_Component (Rectype);
9717 -- If not found, maybe component of base type discriminant that is
9718 -- absent from statically constrained first subtype.
9721 Search_Component (Base_Type (Rectype));
9724 -- If no component, or the component does not reference the component
9725 -- clause in question, then there was some previous error for which
9726 -- we already gave a message, so just return with Comp Empty.
9728 if No (Comp) or else Component_Clause (Comp) /= CC then
9729 Check_Error_Detected;
9732 -- Normal case where we have a component clause
9735 Fbit := Component_Bit_Offset (Comp);
9736 Lbit := Fbit + Esize (Comp) - 1;
9740 -- Start of processing for Check_Record_Representation_Clause
9744 Rectype := Entity (Ident);
9746 if Rectype = Any_Type then
9749 Rectype := Underlying_Type (Rectype);
9752 -- See if we have a fully repped derived tagged type
9755 PS : constant Entity_Id := Parent_Subtype (Rectype);
9758 if Present (PS) and then Is_Fully_Repped_Tagged_Type (PS) then
9759 Tagged_Parent := PS;
9761 -- Find maximum bit of any component of the parent type
9763 Parent_Last_Bit := UI_From_Int (System_Address_Size - 1);
9764 Pcomp := First_Entity (Tagged_Parent);
9765 while Present (Pcomp) loop
9766 if Ekind_In (Pcomp, E_Discriminant, E_Component) then
9767 if Component_Bit_Offset (Pcomp) /= No_Uint
9768 and then Known_Static_Esize (Pcomp)
9773 Component_Bit_Offset (Pcomp) + Esize (Pcomp) - 1);
9777 -- Skip anonymous types generated for constrained array
9778 -- or record components.
9783 Next_Entity (Pcomp);
9788 -- All done if no component clauses
9790 CC := First (Component_Clauses (N));
9796 -- If a tag is present, then create a component clause that places it
9797 -- at the start of the record (otherwise gigi may place it after other
9798 -- fields that have rep clauses).
9800 Fent := First_Entity (Rectype);
9802 if Nkind (Fent) = N_Defining_Identifier
9803 and then Chars (Fent) = Name_uTag
9805 Set_Component_Bit_Offset (Fent, Uint_0);
9806 Set_Normalized_Position (Fent, Uint_0);
9807 Set_Normalized_First_Bit (Fent, Uint_0);
9808 Set_Normalized_Position_Max (Fent, Uint_0);
9809 Init_Esize (Fent, System_Address_Size);
9811 Set_Component_Clause (Fent,
9812 Make_Component_Clause (Loc,
9813 Component_Name => Make_Identifier (Loc, Name_uTag),
9815 Position => Make_Integer_Literal (Loc, Uint_0),
9816 First_Bit => Make_Integer_Literal (Loc, Uint_0),
9818 Make_Integer_Literal (Loc,
9819 UI_From_Int (System_Address_Size))));
9821 Ccount := Ccount + 1;
9824 Max_Bit_So_Far := Uint_Minus_1;
9825 Overlap_Check_Required := False;
9827 -- Process the component clauses
9829 while Present (CC) loop
9832 if Present (Comp) then
9833 Ccount := Ccount + 1;
9835 -- We need a full overlap check if record positions non-monotonic
9837 if Fbit <= Max_Bit_So_Far then
9838 Overlap_Check_Required := True;
9841 Max_Bit_So_Far := Lbit;
9843 -- Check bit position out of range of specified size
9845 if Has_Size_Clause (Rectype)
9846 and then RM_Size (Rectype) <= Lbit
9849 ("bit number out of range of specified size",
9852 -- Check for overlap with tag component
9855 if Is_Tagged_Type (Rectype)
9856 and then Fbit < System_Address_Size
9859 ("component overlaps tag field of&",
9860 Component_Name (CC), Rectype);
9861 Overlap_Detected := True;
9869 -- Check parent overlap if component might overlap parent field
9871 if Present (Tagged_Parent) and then Fbit <= Parent_Last_Bit then
9872 Pcomp := First_Component_Or_Discriminant (Tagged_Parent);
9873 while Present (Pcomp) loop
9874 if not Is_Tag (Pcomp)
9875 and then Chars (Pcomp) /= Name_uParent
9877 Check_Component_Overlap (Comp, Pcomp);
9880 Next_Component_Or_Discriminant (Pcomp);
9888 -- Now that we have processed all the component clauses, check for
9889 -- overlap. We have to leave this till last, since the components can
9890 -- appear in any arbitrary order in the representation clause.
9892 -- We do not need this check if all specified ranges were monotonic,
9893 -- as recorded by Overlap_Check_Required being False at this stage.
9895 -- This first section checks if there are any overlapping entries at
9896 -- all. It does this by sorting all entries and then seeing if there are
9897 -- any overlaps. If there are none, then that is decisive, but if there
9898 -- are overlaps, they may still be OK (they may result from fields in
9899 -- different variants).
9901 if Overlap_Check_Required then
9902 Overlap_Check1 : declare
9904 OC_Fbit : array (0 .. Ccount) of Uint;
9905 -- First-bit values for component clauses, the value is the offset
9906 -- of the first bit of the field from start of record. The zero
9907 -- entry is for use in sorting.
9909 OC_Lbit : array (0 .. Ccount) of Uint;
9910 -- Last-bit values for component clauses, the value is the offset
9911 -- of the last bit of the field from start of record. The zero
9912 -- entry is for use in sorting.
9914 OC_Count : Natural := 0;
9915 -- Count of entries in OC_Fbit and OC_Lbit
9917 function OC_Lt (Op1, Op2 : Natural) return Boolean;
9918 -- Compare routine for Sort
9920 procedure OC_Move (From : Natural; To : Natural);
9921 -- Move routine for Sort
9923 package Sorting is new GNAT.Heap_Sort_G (OC_Move, OC_Lt);
9929 function OC_Lt (Op1, Op2 : Natural) return Boolean is
9931 return OC_Fbit (Op1) < OC_Fbit (Op2);
9938 procedure OC_Move (From : Natural; To : Natural) is
9940 OC_Fbit (To) := OC_Fbit (From);
9941 OC_Lbit (To) := OC_Lbit (From);
9944 -- Start of processing for Overlap_Check
9947 CC := First (Component_Clauses (N));
9948 while Present (CC) loop
9950 -- Exclude component clause already marked in error
9952 if not Error_Posted (CC) then
9955 if Present (Comp) then
9956 OC_Count := OC_Count + 1;
9957 OC_Fbit (OC_Count) := Fbit;
9958 OC_Lbit (OC_Count) := Lbit;
9965 Sorting.Sort (OC_Count);
9967 Overlap_Check_Required := False;
9968 for J in 1 .. OC_Count - 1 loop
9969 if OC_Lbit (J) >= OC_Fbit (J + 1) then
9970 Overlap_Check_Required := True;
9977 -- If Overlap_Check_Required is still True, then we have to do the full
9978 -- scale overlap check, since we have at least two fields that do
9979 -- overlap, and we need to know if that is OK since they are in
9980 -- different variant, or whether we have a definite problem.
9982 if Overlap_Check_Required then
9983 Overlap_Check2 : declare
9984 C1_Ent, C2_Ent : Entity_Id;
9985 -- Entities of components being checked for overlap
9988 -- Component_List node whose Component_Items are being checked
9991 -- Component declaration for component being checked
9994 C1_Ent := First_Entity (Base_Type (Rectype));
9996 -- Loop through all components in record. For each component check
9997 -- for overlap with any of the preceding elements on the component
9998 -- list containing the component and also, if the component is in
9999 -- a variant, check against components outside the case structure.
10000 -- This latter test is repeated recursively up the variant tree.
10002 Main_Component_Loop : while Present (C1_Ent) loop
10003 if not Ekind_In (C1_Ent, E_Component, E_Discriminant) then
10004 goto Continue_Main_Component_Loop;
10007 -- Skip overlap check if entity has no declaration node. This
10008 -- happens with discriminants in constrained derived types.
10009 -- Possibly we are missing some checks as a result, but that
10010 -- does not seem terribly serious.
10012 if No (Declaration_Node (C1_Ent)) then
10013 goto Continue_Main_Component_Loop;
10016 Clist := Parent (List_Containing (Declaration_Node (C1_Ent)));
10018 -- Loop through component lists that need checking. Check the
10019 -- current component list and all lists in variants above us.
10021 Component_List_Loop : loop
10023 -- If derived type definition, go to full declaration
10024 -- If at outer level, check discriminants if there are any.
10026 if Nkind (Clist) = N_Derived_Type_Definition then
10027 Clist := Parent (Clist);
10030 -- Outer level of record definition, check discriminants
10032 if Nkind_In (Clist, N_Full_Type_Declaration,
10033 N_Private_Type_Declaration)
10035 if Has_Discriminants (Defining_Identifier (Clist)) then
10037 First_Discriminant (Defining_Identifier (Clist));
10038 while Present (C2_Ent) loop
10039 exit when C1_Ent = C2_Ent;
10040 Check_Component_Overlap (C1_Ent, C2_Ent);
10041 Next_Discriminant (C2_Ent);
10045 -- Record extension case
10047 elsif Nkind (Clist) = N_Derived_Type_Definition then
10050 -- Otherwise check one component list
10053 Citem := First (Component_Items (Clist));
10054 while Present (Citem) loop
10055 if Nkind (Citem) = N_Component_Declaration then
10056 C2_Ent := Defining_Identifier (Citem);
10057 exit when C1_Ent = C2_Ent;
10058 Check_Component_Overlap (C1_Ent, C2_Ent);
10065 -- Check for variants above us (the parent of the Clist can
10066 -- be a variant, in which case its parent is a variant part,
10067 -- and the parent of the variant part is a component list
10068 -- whose components must all be checked against the current
10069 -- component for overlap).
10071 if Nkind (Parent (Clist)) = N_Variant then
10072 Clist := Parent (Parent (Parent (Clist)));
10074 -- Check for possible discriminant part in record, this
10075 -- is treated essentially as another level in the
10076 -- recursion. For this case the parent of the component
10077 -- list is the record definition, and its parent is the
10078 -- full type declaration containing the discriminant
10081 elsif Nkind (Parent (Clist)) = N_Record_Definition then
10082 Clist := Parent (Parent ((Clist)));
10084 -- If neither of these two cases, we are at the top of
10088 exit Component_List_Loop;
10090 end loop Component_List_Loop;
10092 <<Continue_Main_Component_Loop>>
10093 Next_Entity (C1_Ent);
10095 end loop Main_Component_Loop;
10096 end Overlap_Check2;
10099 -- The following circuit deals with warning on record holes (gaps). We
10100 -- skip this check if overlap was detected, since it makes sense for the
10101 -- programmer to fix this illegality before worrying about warnings.
10103 if not Overlap_Detected and Warn_On_Record_Holes then
10104 Record_Hole_Check : declare
10105 Decl : constant Node_Id := Declaration_Node (Base_Type (Rectype));
10106 -- Full declaration of record type
10108 procedure Check_Component_List
10112 -- Check component list CL for holes. The starting bit should be
10113 -- Sbit. which is zero for the main record component list and set
10114 -- appropriately for recursive calls for variants. DS is set to
10115 -- a list of discriminant specifications to be included in the
10116 -- consideration of components. It is No_List if none to consider.
10118 --------------------------
10119 -- Check_Component_List --
10120 --------------------------
10122 procedure Check_Component_List
10130 Compl := Integer (List_Length (Component_Items (CL)));
10132 if DS /= No_List then
10133 Compl := Compl + Integer (List_Length (DS));
10137 Comps : array (Natural range 0 .. Compl) of Entity_Id;
10138 -- Gather components (zero entry is for sort routine)
10140 Ncomps : Natural := 0;
10141 -- Number of entries stored in Comps (starting at Comps (1))
10144 -- One component item or discriminant specification
10147 -- Starting bit for next component
10150 -- Component entity
10155 function Lt (Op1, Op2 : Natural) return Boolean;
10156 -- Compare routine for Sort
10158 procedure Move (From : Natural; To : Natural);
10159 -- Move routine for Sort
10161 package Sorting is new GNAT.Heap_Sort_G (Move, Lt);
10167 function Lt (Op1, Op2 : Natural) return Boolean is
10169 return Component_Bit_Offset (Comps (Op1))
10171 Component_Bit_Offset (Comps (Op2));
10178 procedure Move (From : Natural; To : Natural) is
10180 Comps (To) := Comps (From);
10184 -- Gather discriminants into Comp
10186 if DS /= No_List then
10187 Citem := First (DS);
10188 while Present (Citem) loop
10189 if Nkind (Citem) = N_Discriminant_Specification then
10191 Ent : constant Entity_Id :=
10192 Defining_Identifier (Citem);
10194 if Ekind (Ent) = E_Discriminant then
10195 Ncomps := Ncomps + 1;
10196 Comps (Ncomps) := Ent;
10205 -- Gather component entities into Comp
10207 Citem := First (Component_Items (CL));
10208 while Present (Citem) loop
10209 if Nkind (Citem) = N_Component_Declaration then
10210 Ncomps := Ncomps + 1;
10211 Comps (Ncomps) := Defining_Identifier (Citem);
10217 -- Now sort the component entities based on the first bit.
10218 -- Note we already know there are no overlapping components.
10220 Sorting.Sort (Ncomps);
10222 -- Loop through entries checking for holes
10225 for J in 1 .. Ncomps loop
10227 Error_Msg_Uint_1 := Component_Bit_Offset (CEnt) - Nbit;
10229 if Error_Msg_Uint_1 > 0 then
10231 ("?H?^-bit gap before component&",
10232 Component_Name (Component_Clause (CEnt)), CEnt);
10235 Nbit := Component_Bit_Offset (CEnt) + Esize (CEnt);
10238 -- Process variant parts recursively if present
10240 if Present (Variant_Part (CL)) then
10241 Variant := First (Variants (Variant_Part (CL)));
10242 while Present (Variant) loop
10243 Check_Component_List
10244 (Component_List (Variant), Nbit, No_List);
10249 end Check_Component_List;
10251 -- Start of processing for Record_Hole_Check
10258 if Is_Tagged_Type (Rectype) then
10259 Sbit := UI_From_Int (System_Address_Size);
10264 if Nkind (Decl) = N_Full_Type_Declaration
10265 and then Nkind (Type_Definition (Decl)) = N_Record_Definition
10267 Check_Component_List
10268 (Component_List (Type_Definition (Decl)),
10270 Discriminant_Specifications (Decl));
10273 end Record_Hole_Check;
10276 -- For records that have component clauses for all components, and whose
10277 -- size is less than or equal to 32, we need to know the size in the
10278 -- front end to activate possible packed array processing where the
10279 -- component type is a record.
10281 -- At this stage Hbit + 1 represents the first unused bit from all the
10282 -- component clauses processed, so if the component clauses are
10283 -- complete, then this is the length of the record.
10285 -- For records longer than System.Storage_Unit, and for those where not
10286 -- all components have component clauses, the back end determines the
10287 -- length (it may for example be appropriate to round up the size
10288 -- to some convenient boundary, based on alignment considerations, etc).
10290 if Unknown_RM_Size (Rectype) and then Hbit + 1 <= 32 then
10292 -- Nothing to do if at least one component has no component clause
10294 Comp := First_Component_Or_Discriminant (Rectype);
10295 while Present (Comp) loop
10296 exit when No (Component_Clause (Comp));
10297 Next_Component_Or_Discriminant (Comp);
10300 -- If we fall out of loop, all components have component clauses
10301 -- and so we can set the size to the maximum value.
10304 Set_RM_Size (Rectype, Hbit + 1);
10307 end Check_Record_Representation_Clause;
10313 procedure Check_Size
10317 Biased : out Boolean)
10319 procedure Size_Too_Small_Error (Min_Siz : Uint);
10320 -- Emit an error concerning illegal size Siz. Min_Siz denotes the
10323 --------------------------
10324 -- Size_Too_Small_Error --
10325 --------------------------
10327 procedure Size_Too_Small_Error (Min_Siz : Uint) is
10329 -- This error is suppressed in ASIS mode to allow for different ASIS
10330 -- back ends or ASIS-based tools to query the illegal clause.
10332 if not ASIS_Mode then
10333 Error_Msg_Uint_1 := Min_Siz;
10334 Error_Msg_NE ("size for& too small, minimum allowed is ^", N, T);
10336 end Size_Too_Small_Error;
10340 UT : constant Entity_Id := Underlying_Type (T);
10343 -- Start of processing for Check_Size
10348 -- Reject patently improper size values
10350 if Is_Elementary_Type (T)
10351 and then Siz > UI_From_Int (Int'Last)
10353 Error_Msg_N ("Size value too large for elementary type", N);
10355 if Nkind (Original_Node (N)) = N_Op_Expon then
10357 ("\maybe '* was meant, rather than '*'*", Original_Node (N));
10361 -- Dismiss generic types
10363 if Is_Generic_Type (T)
10365 Is_Generic_Type (UT)
10367 Is_Generic_Type (Root_Type (UT))
10371 -- Guard against previous errors
10373 elsif No (UT) or else UT = Any_Type then
10374 Check_Error_Detected;
10377 -- Check case of bit packed array
10379 elsif Is_Array_Type (UT)
10380 and then Known_Static_Component_Size (UT)
10381 and then Is_Bit_Packed_Array (UT)
10389 Asiz := Component_Size (UT);
10390 Indx := First_Index (UT);
10392 Ityp := Etype (Indx);
10394 -- If non-static bound, then we are not in the business of
10395 -- trying to check the length, and indeed an error will be
10396 -- issued elsewhere, since sizes of non-static array types
10397 -- cannot be set implicitly or explicitly.
10399 if not Is_OK_Static_Subtype (Ityp) then
10403 -- Otherwise accumulate next dimension
10405 Asiz := Asiz * (Expr_Value (Type_High_Bound (Ityp)) -
10406 Expr_Value (Type_Low_Bound (Ityp)) +
10410 exit when No (Indx);
10413 if Asiz <= Siz then
10417 Size_Too_Small_Error (Asiz);
10418 Set_Esize (T, Asiz);
10419 Set_RM_Size (T, Asiz);
10423 -- All other composite types are ignored
10425 elsif Is_Composite_Type (UT) then
10428 -- For fixed-point types, don't check minimum if type is not frozen,
10429 -- since we don't know all the characteristics of the type that can
10430 -- affect the size (e.g. a specified small) till freeze time.
10432 elsif Is_Fixed_Point_Type (UT) and then not Is_Frozen (UT) then
10435 -- Cases for which a minimum check is required
10438 -- Ignore if specified size is correct for the type
10440 if Known_Esize (UT) and then Siz = Esize (UT) then
10444 -- Otherwise get minimum size
10446 M := UI_From_Int (Minimum_Size (UT));
10450 -- Size is less than minimum size, but one possibility remains
10451 -- that we can manage with the new size if we bias the type.
10453 M := UI_From_Int (Minimum_Size (UT, Biased => True));
10456 Size_Too_Small_Error (M);
10458 Set_RM_Size (T, M);
10466 --------------------------
10467 -- Freeze_Entity_Checks --
10468 --------------------------
10470 procedure Freeze_Entity_Checks (N : Node_Id) is
10471 procedure Hide_Non_Overridden_Subprograms (Typ : Entity_Id);
10472 -- Inspect the primitive operations of type Typ and hide all pairs of
10473 -- implicitly declared non-overridden non-fully conformant homographs
10474 -- (Ada RM 8.3 12.3/2).
10476 -------------------------------------
10477 -- Hide_Non_Overridden_Subprograms --
10478 -------------------------------------
10480 procedure Hide_Non_Overridden_Subprograms (Typ : Entity_Id) is
10481 procedure Hide_Matching_Homographs
10482 (Subp_Id : Entity_Id;
10483 Start_Elmt : Elmt_Id);
10484 -- Inspect a list of primitive operations starting with Start_Elmt
10485 -- and find matching implicitly declared non-overridden non-fully
10486 -- conformant homographs of Subp_Id. If found, all matches along
10487 -- with Subp_Id are hidden from all visibility.
10489 function Is_Non_Overridden_Or_Null_Procedure
10490 (Subp_Id : Entity_Id) return Boolean;
10491 -- Determine whether subprogram Subp_Id is implicitly declared non-
10492 -- overridden subprogram or an implicitly declared null procedure.
10494 ------------------------------
10495 -- Hide_Matching_Homographs --
10496 ------------------------------
10498 procedure Hide_Matching_Homographs
10499 (Subp_Id : Entity_Id;
10500 Start_Elmt : Elmt_Id)
10503 Prim_Elmt : Elmt_Id;
10506 Prim_Elmt := Start_Elmt;
10507 while Present (Prim_Elmt) loop
10508 Prim := Node (Prim_Elmt);
10510 -- The current primitive is implicitly declared non-overridden
10511 -- non-fully conformant homograph of Subp_Id. Both subprograms
10512 -- must be hidden from visibility.
10514 if Chars (Prim) = Chars (Subp_Id)
10515 and then Is_Non_Overridden_Or_Null_Procedure (Prim)
10516 and then not Fully_Conformant (Prim, Subp_Id)
10518 Set_Is_Hidden_Non_Overridden_Subpgm (Prim);
10519 Set_Is_Immediately_Visible (Prim, False);
10520 Set_Is_Potentially_Use_Visible (Prim, False);
10522 Set_Is_Hidden_Non_Overridden_Subpgm (Subp_Id);
10523 Set_Is_Immediately_Visible (Subp_Id, False);
10524 Set_Is_Potentially_Use_Visible (Subp_Id, False);
10527 Next_Elmt (Prim_Elmt);
10529 end Hide_Matching_Homographs;
10531 -----------------------------------------
10532 -- Is_Non_Overridden_Or_Null_Procedure --
10533 -----------------------------------------
10535 function Is_Non_Overridden_Or_Null_Procedure
10536 (Subp_Id : Entity_Id) return Boolean
10538 Alias_Id : Entity_Id;
10541 -- The subprogram is inherited (implicitly declared), it does not
10542 -- override and does not cover a primitive of an interface.
10544 if Ekind_In (Subp_Id, E_Function, E_Procedure)
10545 and then Present (Alias (Subp_Id))
10546 and then No (Interface_Alias (Subp_Id))
10547 and then No (Overridden_Operation (Subp_Id))
10549 Alias_Id := Alias (Subp_Id);
10551 if Requires_Overriding (Alias_Id) then
10554 elsif Nkind (Parent (Alias_Id)) = N_Procedure_Specification
10555 and then Null_Present (Parent (Alias_Id))
10562 end Is_Non_Overridden_Or_Null_Procedure;
10566 Prim_Ops : constant Elist_Id := Direct_Primitive_Operations (Typ);
10568 Prim_Elmt : Elmt_Id;
10570 -- Start of processing for Hide_Non_Overridden_Subprograms
10573 -- Inspect the list of primitives looking for non-overridden
10576 if Present (Prim_Ops) then
10577 Prim_Elmt := First_Elmt (Prim_Ops);
10578 while Present (Prim_Elmt) loop
10579 Prim := Node (Prim_Elmt);
10580 Next_Elmt (Prim_Elmt);
10582 if Is_Non_Overridden_Or_Null_Procedure (Prim) then
10583 Hide_Matching_Homographs
10585 Start_Elmt => Prim_Elmt);
10589 end Hide_Non_Overridden_Subprograms;
10593 E : constant Entity_Id := Entity (N);
10595 Non_Generic_Case : constant Boolean := Nkind (N) = N_Freeze_Entity;
10596 -- True in non-generic case. Some of the processing here is skipped
10597 -- for the generic case since it is not needed. Basically in the
10598 -- generic case, we only need to do stuff that might generate error
10599 -- messages or warnings.
10601 -- Start of processing for Freeze_Entity_Checks
10604 -- Remember that we are processing a freezing entity. Required to
10605 -- ensure correct decoration of internal entities associated with
10606 -- interfaces (see New_Overloaded_Entity).
10608 Inside_Freezing_Actions := Inside_Freezing_Actions + 1;
10610 -- For tagged types covering interfaces add internal entities that link
10611 -- the primitives of the interfaces with the primitives that cover them.
10612 -- Note: These entities were originally generated only when generating
10613 -- code because their main purpose was to provide support to initialize
10614 -- the secondary dispatch tables. They are now generated also when
10615 -- compiling with no code generation to provide ASIS the relationship
10616 -- between interface primitives and tagged type primitives. They are
10617 -- also used to locate primitives covering interfaces when processing
10618 -- generics (see Derive_Subprograms).
10620 -- This is not needed in the generic case
10622 if Ada_Version >= Ada_2005
10623 and then Non_Generic_Case
10624 and then Ekind (E) = E_Record_Type
10625 and then Is_Tagged_Type (E)
10626 and then not Is_Interface (E)
10627 and then Has_Interfaces (E)
10629 -- This would be a good common place to call the routine that checks
10630 -- overriding of interface primitives (and thus factorize calls to
10631 -- Check_Abstract_Overriding located at different contexts in the
10632 -- compiler). However, this is not possible because it causes
10633 -- spurious errors in case of late overriding.
10635 Add_Internal_Interface_Entities (E);
10638 -- After all forms of overriding have been resolved, a tagged type may
10639 -- be left with a set of implicitly declared and possibly erroneous
10640 -- abstract subprograms, null procedures and subprograms that require
10641 -- overriding. If this set contains fully conformant homographs, then
10642 -- one is chosen arbitrarily (already done during resolution), otherwise
10643 -- all remaining non-fully conformant homographs are hidden from
10644 -- visibility (Ada RM 8.3 12.3/2).
10646 if Is_Tagged_Type (E) then
10647 Hide_Non_Overridden_Subprograms (E);
10652 if Ekind (E) = E_Record_Type
10653 and then Is_CPP_Class (E)
10654 and then Is_Tagged_Type (E)
10655 and then Tagged_Type_Expansion
10657 if CPP_Num_Prims (E) = 0 then
10659 -- If the CPP type has user defined components then it must import
10660 -- primitives from C++. This is required because if the C++ class
10661 -- has no primitives then the C++ compiler does not added the _tag
10662 -- component to the type.
10664 if First_Entity (E) /= Last_Entity (E) then
10666 ("'C'P'P type must import at least one primitive from C++??",
10671 -- Check that all its primitives are abstract or imported from C++.
10672 -- Check also availability of the C++ constructor.
10675 Has_Constructors : constant Boolean := Has_CPP_Constructors (E);
10677 Error_Reported : Boolean := False;
10681 Elmt := First_Elmt (Primitive_Operations (E));
10682 while Present (Elmt) loop
10683 Prim := Node (Elmt);
10685 if Comes_From_Source (Prim) then
10686 if Is_Abstract_Subprogram (Prim) then
10689 elsif not Is_Imported (Prim)
10690 or else Convention (Prim) /= Convention_CPP
10693 ("primitives of 'C'P'P types must be imported from C++ "
10694 & "or abstract??", Prim);
10696 elsif not Has_Constructors
10697 and then not Error_Reported
10699 Error_Msg_Name_1 := Chars (E);
10701 ("??'C'P'P constructor required for type %", Prim);
10702 Error_Reported := True;
10711 -- Check Ada derivation of CPP type
10713 if Expander_Active -- why? losing errors in -gnatc mode???
10714 and then Present (Etype (E)) -- defend against errors
10715 and then Tagged_Type_Expansion
10716 and then Ekind (E) = E_Record_Type
10717 and then Etype (E) /= E
10718 and then Is_CPP_Class (Etype (E))
10719 and then CPP_Num_Prims (Etype (E)) > 0
10720 and then not Is_CPP_Class (E)
10721 and then not Has_CPP_Constructors (Etype (E))
10723 -- If the parent has C++ primitives but it has no constructor then
10724 -- check that all the primitives are overridden in this derivation;
10725 -- otherwise the constructor of the parent is needed to build the
10733 Elmt := First_Elmt (Primitive_Operations (E));
10734 while Present (Elmt) loop
10735 Prim := Node (Elmt);
10737 if not Is_Abstract_Subprogram (Prim)
10738 and then No (Interface_Alias (Prim))
10739 and then Find_Dispatching_Type (Ultimate_Alias (Prim)) /= E
10741 Error_Msg_Name_1 := Chars (Etype (E));
10743 ("'C'P'P constructor required for parent type %", E);
10752 Inside_Freezing_Actions := Inside_Freezing_Actions - 1;
10754 -- If we have a type with predicates, build predicate function. This is
10755 -- not needed in the generic case, nor within TSS subprograms and other
10756 -- predefined primitives.
10759 and then Non_Generic_Case
10760 and then not Within_Internal_Subprogram
10761 and then Has_Predicates (E)
10763 Build_Predicate_Functions (E, N);
10766 -- If type has delayed aspects, this is where we do the preanalysis at
10767 -- the freeze point, as part of the consistent visibility check. Note
10768 -- that this must be done after calling Build_Predicate_Functions or
10769 -- Build_Invariant_Procedure since these subprograms fix occurrences of
10770 -- the subtype name in the saved expression so that they will not cause
10771 -- trouble in the preanalysis.
10773 -- This is also not needed in the generic case
10775 if Non_Generic_Case
10776 and then Has_Delayed_Aspects (E)
10777 and then Scope (E) = Current_Scope
10779 -- Retrieve the visibility to the discriminants in order to properly
10780 -- analyze the aspects.
10782 Push_Scope_And_Install_Discriminants (E);
10788 -- Look for aspect specification entries for this entity
10790 Ritem := First_Rep_Item (E);
10791 while Present (Ritem) loop
10792 if Nkind (Ritem) = N_Aspect_Specification
10793 and then Entity (Ritem) = E
10794 and then Is_Delayed_Aspect (Ritem)
10796 Check_Aspect_At_Freeze_Point (Ritem);
10799 Next_Rep_Item (Ritem);
10803 Uninstall_Discriminants_And_Pop_Scope (E);
10806 -- For a record type, deal with variant parts. This has to be delayed
10807 -- to this point, because of the issue of statically predicated
10808 -- subtypes, which we have to ensure are frozen before checking
10809 -- choices, since we need to have the static choice list set.
10811 if Is_Record_Type (E) then
10812 Check_Variant_Part : declare
10813 D : constant Node_Id := Declaration_Node (E);
10818 Others_Present : Boolean;
10819 pragma Warnings (Off, Others_Present);
10820 -- Indicates others present, not used in this case
10822 procedure Non_Static_Choice_Error (Choice : Node_Id);
10823 -- Error routine invoked by the generic instantiation below when
10824 -- the variant part has a non static choice.
10826 procedure Process_Declarations (Variant : Node_Id);
10827 -- Processes declarations associated with a variant. We analyzed
10828 -- the declarations earlier (in Sem_Ch3.Analyze_Variant_Part),
10829 -- but we still need the recursive call to Check_Choices for any
10830 -- nested variant to get its choices properly processed. This is
10831 -- also where we expand out the choices if expansion is active.
10833 package Variant_Choices_Processing is new
10834 Generic_Check_Choices
10835 (Process_Empty_Choice => No_OP,
10836 Process_Non_Static_Choice => Non_Static_Choice_Error,
10837 Process_Associated_Node => Process_Declarations);
10838 use Variant_Choices_Processing;
10840 -----------------------------
10841 -- Non_Static_Choice_Error --
10842 -----------------------------
10844 procedure Non_Static_Choice_Error (Choice : Node_Id) is
10846 Flag_Non_Static_Expr
10847 ("choice given in variant part is not static!", Choice);
10848 end Non_Static_Choice_Error;
10850 --------------------------
10851 -- Process_Declarations --
10852 --------------------------
10854 procedure Process_Declarations (Variant : Node_Id) is
10855 CL : constant Node_Id := Component_List (Variant);
10859 -- Check for static predicate present in this variant
10861 if Has_SP_Choice (Variant) then
10863 -- Here we expand. You might expect to find this call in
10864 -- Expand_N_Variant_Part, but that is called when we first
10865 -- see the variant part, and we cannot do this expansion
10866 -- earlier than the freeze point, since for statically
10867 -- predicated subtypes, the predicate is not known till
10868 -- the freeze point.
10870 -- Furthermore, we do this expansion even if the expander
10871 -- is not active, because other semantic processing, e.g.
10872 -- for aggregates, requires the expanded list of choices.
10874 -- If the expander is not active, then we can't just clobber
10875 -- the list since it would invalidate the ASIS -gnatct tree.
10876 -- So we have to rewrite the variant part with a Rewrite
10877 -- call that replaces it with a copy and clobber the copy.
10879 if not Expander_Active then
10881 NewV : constant Node_Id := New_Copy (Variant);
10883 Set_Discrete_Choices
10884 (NewV, New_Copy_List (Discrete_Choices (Variant)));
10885 Rewrite (Variant, NewV);
10889 Expand_Static_Predicates_In_Choices (Variant);
10892 -- We don't need to worry about the declarations in the variant
10893 -- (since they were analyzed by Analyze_Choices when we first
10894 -- encountered the variant), but we do need to take care of
10895 -- expansion of any nested variants.
10897 if not Null_Present (CL) then
10898 VP := Variant_Part (CL);
10900 if Present (VP) then
10902 (VP, Variants (VP), Etype (Name (VP)), Others_Present);
10905 end Process_Declarations;
10907 -- Start of processing for Check_Variant_Part
10910 -- Find component list
10914 if Nkind (D) = N_Full_Type_Declaration then
10915 T := Type_Definition (D);
10917 if Nkind (T) = N_Record_Definition then
10918 C := Component_List (T);
10920 elsif Nkind (T) = N_Derived_Type_Definition
10921 and then Present (Record_Extension_Part (T))
10923 C := Component_List (Record_Extension_Part (T));
10927 -- Case of variant part present
10929 if Present (C) and then Present (Variant_Part (C)) then
10930 VP := Variant_Part (C);
10935 (VP, Variants (VP), Etype (Name (VP)), Others_Present);
10937 -- If the last variant does not contain the Others choice,
10938 -- replace it with an N_Others_Choice node since Gigi always
10939 -- wants an Others. Note that we do not bother to call Analyze
10940 -- on the modified variant part, since its only effect would be
10941 -- to compute the Others_Discrete_Choices node laboriously, and
10942 -- of course we already know the list of choices corresponding
10943 -- to the others choice (it's the list we're replacing).
10945 -- We only want to do this if the expander is active, since
10946 -- we do not want to clobber the ASIS tree.
10948 if Expander_Active then
10950 Last_Var : constant Node_Id :=
10951 Last_Non_Pragma (Variants (VP));
10953 Others_Node : Node_Id;
10956 if Nkind (First (Discrete_Choices (Last_Var))) /=
10959 Others_Node := Make_Others_Choice (Sloc (Last_Var));
10960 Set_Others_Discrete_Choices
10961 (Others_Node, Discrete_Choices (Last_Var));
10962 Set_Discrete_Choices
10963 (Last_Var, New_List (Others_Node));
10968 end Check_Variant_Part;
10970 end Freeze_Entity_Checks;
10972 -------------------------
10973 -- Get_Alignment_Value --
10974 -------------------------
10976 function Get_Alignment_Value (Expr : Node_Id) return Uint is
10977 Align : constant Uint := Static_Integer (Expr);
10980 if Align = No_Uint then
10983 elsif Align <= 0 then
10985 -- This error is suppressed in ASIS mode to allow for different ASIS
10986 -- back ends or ASIS-based tools to query the illegal clause.
10988 if not ASIS_Mode then
10989 Error_Msg_N ("alignment value must be positive", Expr);
10995 for J in Int range 0 .. 64 loop
10997 M : constant Uint := Uint_2 ** J;
11000 exit when M = Align;
11004 -- This error is suppressed in ASIS mode to allow for
11005 -- different ASIS back ends or ASIS-based tools to query the
11008 if not ASIS_Mode then
11009 Error_Msg_N ("alignment value must be power of 2", Expr);
11019 end Get_Alignment_Value;
11021 -----------------------------
11022 -- Get_Interfacing_Aspects --
11023 -----------------------------
11025 procedure Get_Interfacing_Aspects
11026 (Iface_Asp : Node_Id;
11027 Conv_Asp : out Node_Id;
11028 EN_Asp : out Node_Id;
11029 Expo_Asp : out Node_Id;
11030 Imp_Asp : out Node_Id;
11031 LN_Asp : out Node_Id;
11032 Do_Checks : Boolean := False)
11034 procedure Save_Or_Duplication_Error
11036 To : in out Node_Id);
11037 -- Save the value of aspect Asp in node To. If To already has a value,
11038 -- then this is considered a duplicate use of aspect. Emit an error if
11039 -- flag Do_Checks is set.
11041 -------------------------------
11042 -- Save_Or_Duplication_Error --
11043 -------------------------------
11045 procedure Save_Or_Duplication_Error
11047 To : in out Node_Id)
11050 -- Detect an extra aspect and issue an error
11052 if Present (To) then
11054 Error_Msg_Name_1 := Chars (Identifier (Asp));
11055 Error_Msg_Sloc := Sloc (To);
11056 Error_Msg_N ("aspect % previously given #", Asp);
11059 -- Otherwise capture the aspect
11064 end Save_Or_Duplication_Error;
11069 Asp_Id : Aspect_Id;
11071 -- The following variables capture each individual aspect
11073 Conv : Node_Id := Empty;
11074 EN : Node_Id := Empty;
11075 Expo : Node_Id := Empty;
11076 Imp : Node_Id := Empty;
11077 LN : Node_Id := Empty;
11079 -- Start of processing for Get_Interfacing_Aspects
11082 -- The input interfacing aspect should reside in an aspect specification
11085 pragma Assert (Is_List_Member (Iface_Asp));
11087 -- Examine the aspect specifications of the related entity. Find and
11088 -- capture all interfacing aspects. Detect duplicates and emit errors
11091 Asp := First (List_Containing (Iface_Asp));
11092 while Present (Asp) loop
11093 Asp_Id := Get_Aspect_Id (Asp);
11095 if Asp_Id = Aspect_Convention then
11096 Save_Or_Duplication_Error (Asp, Conv);
11098 elsif Asp_Id = Aspect_External_Name then
11099 Save_Or_Duplication_Error (Asp, EN);
11101 elsif Asp_Id = Aspect_Export then
11102 Save_Or_Duplication_Error (Asp, Expo);
11104 elsif Asp_Id = Aspect_Import then
11105 Save_Or_Duplication_Error (Asp, Imp);
11107 elsif Asp_Id = Aspect_Link_Name then
11108 Save_Or_Duplication_Error (Asp, LN);
11119 end Get_Interfacing_Aspects;
11121 -------------------------------------
11122 -- Inherit_Aspects_At_Freeze_Point --
11123 -------------------------------------
11125 procedure Inherit_Aspects_At_Freeze_Point (Typ : Entity_Id) is
11126 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11127 (Rep_Item : Node_Id) return Boolean;
11128 -- This routine checks if Rep_Item is either a pragma or an aspect
11129 -- specification node whose correponding pragma (if any) is present in
11130 -- the Rep Item chain of the entity it has been specified to.
11132 --------------------------------------------------
11133 -- Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item --
11134 --------------------------------------------------
11136 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11137 (Rep_Item : Node_Id) return Boolean
11141 Nkind (Rep_Item) = N_Pragma
11142 or else Present_In_Rep_Item
11143 (Entity (Rep_Item), Aspect_Rep_Item (Rep_Item));
11144 end Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item;
11146 -- Start of processing for Inherit_Aspects_At_Freeze_Point
11149 -- A representation item is either subtype-specific (Size and Alignment
11150 -- clauses) or type-related (all others). Subtype-specific aspects may
11151 -- differ for different subtypes of the same type (RM 13.1.8).
11153 -- A derived type inherits each type-related representation aspect of
11154 -- its parent type that was directly specified before the declaration of
11155 -- the derived type (RM 13.1.15).
11157 -- A derived subtype inherits each subtype-specific representation
11158 -- aspect of its parent subtype that was directly specified before the
11159 -- declaration of the derived type (RM 13.1.15).
11161 -- The general processing involves inheriting a representation aspect
11162 -- from a parent type whenever the first rep item (aspect specification,
11163 -- attribute definition clause, pragma) corresponding to the given
11164 -- representation aspect in the rep item chain of Typ, if any, isn't
11165 -- directly specified to Typ but to one of its parents.
11167 -- ??? Note that, for now, just a limited number of representation
11168 -- aspects have been inherited here so far. Many of them are
11169 -- still inherited in Sem_Ch3. This will be fixed soon. Here is
11170 -- a non- exhaustive list of aspects that likely also need to
11171 -- be moved to this routine: Alignment, Component_Alignment,
11172 -- Component_Size, Machine_Radix, Object_Size, Pack, Predicates,
11173 -- Preelaborable_Initialization, RM_Size and Small.
11175 -- In addition, Convention must be propagated from base type to subtype,
11176 -- because the subtype may have been declared on an incomplete view.
11178 if Nkind (Parent (Typ)) = N_Private_Extension_Declaration then
11184 if not Has_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005, False)
11185 and then Has_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005)
11186 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11187 (Get_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005))
11189 Set_Is_Ada_2005_Only (Typ);
11194 if not Has_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012, False)
11195 and then Has_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012)
11196 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11197 (Get_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012))
11199 Set_Is_Ada_2012_Only (Typ);
11204 if not Has_Rep_Item (Typ, Name_Atomic, Name_Shared, False)
11205 and then Has_Rep_Pragma (Typ, Name_Atomic, Name_Shared)
11206 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11207 (Get_Rep_Item (Typ, Name_Atomic, Name_Shared))
11209 Set_Is_Atomic (Typ);
11210 Set_Is_Volatile (Typ);
11211 Set_Treat_As_Volatile (Typ);
11216 if Is_Record_Type (Typ)
11217 and then Typ /= Base_Type (Typ) and then Is_Frozen (Base_Type (Typ))
11219 Set_Convention (Typ, Convention (Base_Type (Typ)));
11222 -- Default_Component_Value
11224 -- Verify that there is no rep_item declared for the type, and there
11225 -- is one coming from an ancestor.
11227 if Is_Array_Type (Typ)
11228 and then Is_Base_Type (Typ)
11229 and then not Has_Rep_Item (Typ, Name_Default_Component_Value, False)
11230 and then Has_Rep_Item (Typ, Name_Default_Component_Value)
11232 Set_Default_Aspect_Component_Value (Typ,
11233 Default_Aspect_Component_Value
11234 (Entity (Get_Rep_Item (Typ, Name_Default_Component_Value))));
11239 if Is_Scalar_Type (Typ)
11240 and then Is_Base_Type (Typ)
11241 and then not Has_Rep_Item (Typ, Name_Default_Value, False)
11242 and then Has_Rep_Item (Typ, Name_Default_Value)
11244 Set_Has_Default_Aspect (Typ);
11245 Set_Default_Aspect_Value (Typ,
11246 Default_Aspect_Value
11247 (Entity (Get_Rep_Item (Typ, Name_Default_Value))));
11252 if not Has_Rep_Item (Typ, Name_Discard_Names, False)
11253 and then Has_Rep_Item (Typ, Name_Discard_Names)
11254 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11255 (Get_Rep_Item (Typ, Name_Discard_Names))
11257 Set_Discard_Names (Typ);
11262 if not Has_Rep_Item (Typ, Name_Volatile, False)
11263 and then Has_Rep_Item (Typ, Name_Volatile)
11264 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11265 (Get_Rep_Item (Typ, Name_Volatile))
11267 Set_Is_Volatile (Typ);
11268 Set_Treat_As_Volatile (Typ);
11271 -- Volatile_Full_Access
11273 if not Has_Rep_Item (Typ, Name_Volatile_Full_Access, False)
11274 and then Has_Rep_Pragma (Typ, Name_Volatile_Full_Access)
11275 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11276 (Get_Rep_Item (Typ, Name_Volatile_Full_Access))
11278 Set_Is_Volatile_Full_Access (Typ);
11279 Set_Is_Volatile (Typ);
11280 Set_Treat_As_Volatile (Typ);
11283 -- Inheritance for derived types only
11285 if Is_Derived_Type (Typ) then
11287 Bas_Typ : constant Entity_Id := Base_Type (Typ);
11288 Imp_Bas_Typ : constant Entity_Id := Implementation_Base_Type (Typ);
11291 -- Atomic_Components
11293 if not Has_Rep_Item (Typ, Name_Atomic_Components, False)
11294 and then Has_Rep_Item (Typ, Name_Atomic_Components)
11295 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11296 (Get_Rep_Item (Typ, Name_Atomic_Components))
11298 Set_Has_Atomic_Components (Imp_Bas_Typ);
11301 -- Volatile_Components
11303 if not Has_Rep_Item (Typ, Name_Volatile_Components, False)
11304 and then Has_Rep_Item (Typ, Name_Volatile_Components)
11305 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11306 (Get_Rep_Item (Typ, Name_Volatile_Components))
11308 Set_Has_Volatile_Components (Imp_Bas_Typ);
11311 -- Finalize_Storage_Only
11313 if not Has_Rep_Pragma (Typ, Name_Finalize_Storage_Only, False)
11314 and then Has_Rep_Pragma (Typ, Name_Finalize_Storage_Only)
11316 Set_Finalize_Storage_Only (Bas_Typ);
11319 -- Universal_Aliasing
11321 if not Has_Rep_Item (Typ, Name_Universal_Aliasing, False)
11322 and then Has_Rep_Item (Typ, Name_Universal_Aliasing)
11323 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11324 (Get_Rep_Item (Typ, Name_Universal_Aliasing))
11326 Set_Universal_Aliasing (Imp_Bas_Typ);
11331 if Is_Record_Type (Typ) then
11332 if not Has_Rep_Item (Typ, Name_Bit_Order, False)
11333 and then Has_Rep_Item (Typ, Name_Bit_Order)
11335 Set_Reverse_Bit_Order (Bas_Typ,
11336 Reverse_Bit_Order (Entity (Name
11337 (Get_Rep_Item (Typ, Name_Bit_Order)))));
11341 -- Scalar_Storage_Order
11343 -- Note: the aspect is specified on a first subtype, but recorded
11344 -- in a flag of the base type!
11346 if (Is_Record_Type (Typ) or else Is_Array_Type (Typ))
11347 and then Typ = Bas_Typ
11349 -- For a type extension, always inherit from parent; otherwise
11350 -- inherit if no default applies. Note: we do not check for
11351 -- an explicit rep item on the parent type when inheriting,
11352 -- because the parent SSO may itself have been set by default.
11354 if not Has_Rep_Item (First_Subtype (Typ),
11355 Name_Scalar_Storage_Order, False)
11356 and then (Is_Tagged_Type (Bas_Typ)
11357 or else not (SSO_Set_Low_By_Default (Bas_Typ)
11359 SSO_Set_High_By_Default (Bas_Typ)))
11361 Set_Reverse_Storage_Order (Bas_Typ,
11362 Reverse_Storage_Order
11363 (Implementation_Base_Type (Etype (Bas_Typ))));
11365 -- Clear default SSO indications, since the inherited aspect
11366 -- which was set explicitly overrides the default.
11368 Set_SSO_Set_Low_By_Default (Bas_Typ, False);
11369 Set_SSO_Set_High_By_Default (Bas_Typ, False);
11374 end Inherit_Aspects_At_Freeze_Point;
11380 procedure Initialize is
11382 Address_Clause_Checks.Init;
11383 Unchecked_Conversions.Init;
11385 if AAMP_On_Target then
11386 Independence_Checks.Init;
11390 ---------------------------
11391 -- Install_Discriminants --
11392 ---------------------------
11394 procedure Install_Discriminants (E : Entity_Id) is
11398 Disc := First_Discriminant (E);
11399 while Present (Disc) loop
11400 Prev := Current_Entity (Disc);
11401 Set_Current_Entity (Disc);
11402 Set_Is_Immediately_Visible (Disc);
11403 Set_Homonym (Disc, Prev);
11404 Next_Discriminant (Disc);
11406 end Install_Discriminants;
11408 -------------------------
11409 -- Is_Operational_Item --
11410 -------------------------
11412 function Is_Operational_Item (N : Node_Id) return Boolean is
11414 if Nkind (N) /= N_Attribute_Definition_Clause then
11419 Id : constant Attribute_Id := Get_Attribute_Id (Chars (N));
11422 -- List of operational items is given in AARM 13.1(8.mm/1).
11423 -- It is clearly incomplete, as it does not include iterator
11424 -- aspects, among others.
11426 return Id = Attribute_Constant_Indexing
11427 or else Id = Attribute_Default_Iterator
11428 or else Id = Attribute_Implicit_Dereference
11429 or else Id = Attribute_Input
11430 or else Id = Attribute_Iterator_Element
11431 or else Id = Attribute_Iterable
11432 or else Id = Attribute_Output
11433 or else Id = Attribute_Read
11434 or else Id = Attribute_Variable_Indexing
11435 or else Id = Attribute_Write
11436 or else Id = Attribute_External_Tag;
11439 end Is_Operational_Item;
11441 -------------------------
11442 -- Is_Predicate_Static --
11443 -------------------------
11445 -- Note: the basic legality of the expression has already been checked, so
11446 -- we don't need to worry about cases or ranges on strings for example.
11448 function Is_Predicate_Static
11450 Nam : Name_Id) return Boolean
11452 function All_Static_Case_Alternatives (L : List_Id) return Boolean;
11453 -- Given a list of case expression alternatives, returns True if all
11454 -- the alternatives are static (have all static choices, and a static
11457 function All_Static_Choices (L : List_Id) return Boolean;
11458 -- Returns true if all elements of the list are OK static choices
11459 -- as defined below for Is_Static_Choice. Used for case expression
11460 -- alternatives and for the right operand of a membership test. An
11461 -- others_choice is static if the corresponding expression is static.
11462 -- The staticness of the bounds is checked separately.
11464 function Is_Static_Choice (N : Node_Id) return Boolean;
11465 -- Returns True if N represents a static choice (static subtype, or
11466 -- static subtype indication, or static expression, or static range).
11468 -- Note that this is a bit more inclusive than we actually need
11469 -- (in particular membership tests do not allow the use of subtype
11470 -- indications). But that doesn't matter, we have already checked
11471 -- that the construct is legal to get this far.
11473 function Is_Type_Ref (N : Node_Id) return Boolean;
11474 pragma Inline (Is_Type_Ref);
11475 -- Returns True if N is a reference to the type for the predicate in the
11476 -- expression (i.e. if it is an identifier whose Chars field matches the
11477 -- Nam given in the call). N must not be parenthesized, if the type name
11478 -- appears in parens, this routine will return False.
11480 ----------------------------------
11481 -- All_Static_Case_Alternatives --
11482 ----------------------------------
11484 function All_Static_Case_Alternatives (L : List_Id) return Boolean is
11489 while Present (N) loop
11490 if not (All_Static_Choices (Discrete_Choices (N))
11491 and then Is_OK_Static_Expression (Expression (N)))
11500 end All_Static_Case_Alternatives;
11502 ------------------------
11503 -- All_Static_Choices --
11504 ------------------------
11506 function All_Static_Choices (L : List_Id) return Boolean is
11511 while Present (N) loop
11512 if not Is_Static_Choice (N) then
11520 end All_Static_Choices;
11522 ----------------------
11523 -- Is_Static_Choice --
11524 ----------------------
11526 function Is_Static_Choice (N : Node_Id) return Boolean is
11528 return Nkind (N) = N_Others_Choice
11529 or else Is_OK_Static_Expression (N)
11530 or else (Is_Entity_Name (N) and then Is_Type (Entity (N))
11531 and then Is_OK_Static_Subtype (Entity (N)))
11532 or else (Nkind (N) = N_Subtype_Indication
11533 and then Is_OK_Static_Subtype (Entity (N)))
11534 or else (Nkind (N) = N_Range and then Is_OK_Static_Range (N));
11535 end Is_Static_Choice;
11541 function Is_Type_Ref (N : Node_Id) return Boolean is
11543 return Nkind (N) = N_Identifier
11544 and then Chars (N) = Nam
11545 and then Paren_Count (N) = 0;
11548 -- Start of processing for Is_Predicate_Static
11551 -- Predicate_Static means one of the following holds. Numbers are the
11552 -- corresponding paragraph numbers in (RM 3.2.4(16-22)).
11554 -- 16: A static expression
11556 if Is_OK_Static_Expression (Expr) then
11559 -- 17: A membership test whose simple_expression is the current
11560 -- instance, and whose membership_choice_list meets the requirements
11561 -- for a static membership test.
11563 elsif Nkind (Expr) in N_Membership_Test
11564 and then ((Present (Right_Opnd (Expr))
11565 and then Is_Static_Choice (Right_Opnd (Expr)))
11567 (Present (Alternatives (Expr))
11568 and then All_Static_Choices (Alternatives (Expr))))
11572 -- 18. A case_expression whose selecting_expression is the current
11573 -- instance, and whose dependent expressions are static expressions.
11575 elsif Nkind (Expr) = N_Case_Expression
11576 and then Is_Type_Ref (Expression (Expr))
11577 and then All_Static_Case_Alternatives (Alternatives (Expr))
11581 -- 19. A call to a predefined equality or ordering operator, where one
11582 -- operand is the current instance, and the other is a static
11585 -- Note: the RM is clearly wrong here in not excluding string types.
11586 -- Without this exclusion, we would allow expressions like X > "ABC"
11587 -- to be considered as predicate-static, which is clearly not intended,
11588 -- since the idea is for predicate-static to be a subset of normal
11589 -- static expressions (and "DEF" > "ABC" is not a static expression).
11591 -- However, we do allow internally generated (not from source) equality
11592 -- and inequality operations to be valid on strings (this helps deal
11593 -- with cases where we transform A in "ABC" to A = "ABC).
11595 elsif Nkind (Expr) in N_Op_Compare
11596 and then ((not Is_String_Type (Etype (Left_Opnd (Expr))))
11597 or else (Nkind_In (Expr, N_Op_Eq, N_Op_Ne)
11598 and then not Comes_From_Source (Expr)))
11599 and then ((Is_Type_Ref (Left_Opnd (Expr))
11600 and then Is_OK_Static_Expression (Right_Opnd (Expr)))
11602 (Is_Type_Ref (Right_Opnd (Expr))
11603 and then Is_OK_Static_Expression (Left_Opnd (Expr))))
11607 -- 20. A call to a predefined boolean logical operator, where each
11608 -- operand is predicate-static.
11610 elsif (Nkind_In (Expr, N_Op_And, N_Op_Or, N_Op_Xor)
11611 and then Is_Predicate_Static (Left_Opnd (Expr), Nam)
11612 and then Is_Predicate_Static (Right_Opnd (Expr), Nam))
11614 (Nkind (Expr) = N_Op_Not
11615 and then Is_Predicate_Static (Right_Opnd (Expr), Nam))
11619 -- 21. A short-circuit control form where both operands are
11620 -- predicate-static.
11622 elsif Nkind (Expr) in N_Short_Circuit
11623 and then Is_Predicate_Static (Left_Opnd (Expr), Nam)
11624 and then Is_Predicate_Static (Right_Opnd (Expr), Nam)
11628 -- 22. A parenthesized predicate-static expression. This does not
11629 -- require any special test, since we just ignore paren levels in
11630 -- all the cases above.
11632 -- One more test that is an implementation artifact caused by the fact
11633 -- that we are analyzing not the original expression, but the generated
11634 -- expression in the body of the predicate function. This can include
11635 -- references to inherited predicates, so that the expression we are
11636 -- processing looks like:
11638 -- xxPredicate (typ (Inns)) and then expression
11640 -- Where the call is to a Predicate function for an inherited predicate.
11641 -- We simply ignore such a call, which could be to either a dynamic or
11642 -- a static predicate. Note that if the parent predicate is dynamic then
11643 -- eventually this type will be marked as dynamic, but you are allowed
11644 -- to specify a static predicate for a subtype which is inheriting a
11645 -- dynamic predicate, so the static predicate validation here ignores
11646 -- the inherited predicate even if it is dynamic.
11648 elsif Nkind (Expr) = N_Function_Call
11649 and then Is_Predicate_Function (Entity (Name (Expr)))
11653 -- That's an exhaustive list of tests, all other cases are not
11654 -- predicate-static, so we return False.
11659 end Is_Predicate_Static;
11661 ---------------------
11662 -- Kill_Rep_Clause --
11663 ---------------------
11665 procedure Kill_Rep_Clause (N : Node_Id) is
11667 pragma Assert (Ignore_Rep_Clauses);
11669 -- Note: we use Replace rather than Rewrite, because we don't want
11670 -- ASIS to be able to use Original_Node to dig out the (undecorated)
11671 -- rep clause that is being replaced.
11673 Replace (N, Make_Null_Statement (Sloc (N)));
11675 -- The null statement must be marked as not coming from source. This is
11676 -- so that ASIS ignores it, and also the back end does not expect bogus
11677 -- "from source" null statements in weird places (e.g. in declarative
11678 -- regions where such null statements are not allowed).
11680 Set_Comes_From_Source (N, False);
11681 end Kill_Rep_Clause;
11687 function Minimum_Size
11689 Biased : Boolean := False) return Nat
11691 Lo : Uint := No_Uint;
11692 Hi : Uint := No_Uint;
11693 LoR : Ureal := No_Ureal;
11694 HiR : Ureal := No_Ureal;
11695 LoSet : Boolean := False;
11696 HiSet : Boolean := False;
11699 Ancest : Entity_Id;
11700 R_Typ : constant Entity_Id := Root_Type (T);
11703 -- If bad type, return 0
11705 if T = Any_Type then
11708 -- For generic types, just return zero. There cannot be any legitimate
11709 -- need to know such a size, but this routine may be called with a
11710 -- generic type as part of normal processing.
11712 elsif Is_Generic_Type (R_Typ) or else R_Typ = Any_Type then
11715 -- Access types (cannot have size smaller than System.Address)
11717 elsif Is_Access_Type (T) then
11718 return System_Address_Size;
11720 -- Floating-point types
11722 elsif Is_Floating_Point_Type (T) then
11723 return UI_To_Int (Esize (R_Typ));
11727 elsif Is_Discrete_Type (T) then
11729 -- The following loop is looking for the nearest compile time known
11730 -- bounds following the ancestor subtype chain. The idea is to find
11731 -- the most restrictive known bounds information.
11735 if Ancest = Any_Type or else Etype (Ancest) = Any_Type then
11740 if Compile_Time_Known_Value (Type_Low_Bound (Ancest)) then
11741 Lo := Expr_Rep_Value (Type_Low_Bound (Ancest));
11748 if Compile_Time_Known_Value (Type_High_Bound (Ancest)) then
11749 Hi := Expr_Rep_Value (Type_High_Bound (Ancest));
11755 Ancest := Ancestor_Subtype (Ancest);
11757 if No (Ancest) then
11758 Ancest := Base_Type (T);
11760 if Is_Generic_Type (Ancest) then
11766 -- Fixed-point types. We can't simply use Expr_Value to get the
11767 -- Corresponding_Integer_Value values of the bounds, since these do not
11768 -- get set till the type is frozen, and this routine can be called
11769 -- before the type is frozen. Similarly the test for bounds being static
11770 -- needs to include the case where we have unanalyzed real literals for
11771 -- the same reason.
11773 elsif Is_Fixed_Point_Type (T) then
11775 -- The following loop is looking for the nearest compile time known
11776 -- bounds following the ancestor subtype chain. The idea is to find
11777 -- the most restrictive known bounds information.
11781 if Ancest = Any_Type or else Etype (Ancest) = Any_Type then
11785 -- Note: In the following two tests for LoSet and HiSet, it may
11786 -- seem redundant to test for N_Real_Literal here since normally
11787 -- one would assume that the test for the value being known at
11788 -- compile time includes this case. However, there is a glitch.
11789 -- If the real literal comes from folding a non-static expression,
11790 -- then we don't consider any non- static expression to be known
11791 -- at compile time if we are in configurable run time mode (needed
11792 -- in some cases to give a clearer definition of what is and what
11793 -- is not accepted). So the test is indeed needed. Without it, we
11794 -- would set neither Lo_Set nor Hi_Set and get an infinite loop.
11797 if Nkind (Type_Low_Bound (Ancest)) = N_Real_Literal
11798 or else Compile_Time_Known_Value (Type_Low_Bound (Ancest))
11800 LoR := Expr_Value_R (Type_Low_Bound (Ancest));
11807 if Nkind (Type_High_Bound (Ancest)) = N_Real_Literal
11808 or else Compile_Time_Known_Value (Type_High_Bound (Ancest))
11810 HiR := Expr_Value_R (Type_High_Bound (Ancest));
11816 Ancest := Ancestor_Subtype (Ancest);
11818 if No (Ancest) then
11819 Ancest := Base_Type (T);
11821 if Is_Generic_Type (Ancest) then
11827 Lo := UR_To_Uint (LoR / Small_Value (T));
11828 Hi := UR_To_Uint (HiR / Small_Value (T));
11830 -- No other types allowed
11833 raise Program_Error;
11836 -- Fall through with Hi and Lo set. Deal with biased case
11839 and then not Is_Fixed_Point_Type (T)
11840 and then not (Is_Enumeration_Type (T)
11841 and then Has_Non_Standard_Rep (T)))
11842 or else Has_Biased_Representation (T)
11848 -- Null range case, size is always zero. We only do this in the discrete
11849 -- type case, since that's the odd case that came up. Probably we should
11850 -- also do this in the fixed-point case, but doing so causes peculiar
11851 -- gigi failures, and it is not worth worrying about this incredibly
11852 -- marginal case (explicit null-range fixed-point type declarations)???
11854 if Lo > Hi and then Is_Discrete_Type (T) then
11857 -- Signed case. Note that we consider types like range 1 .. -1 to be
11858 -- signed for the purpose of computing the size, since the bounds have
11859 -- to be accommodated in the base type.
11861 elsif Lo < 0 or else Hi < 0 then
11865 -- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1))
11866 -- Note that we accommodate the case where the bounds cross. This
11867 -- can happen either because of the way the bounds are declared
11868 -- or because of the algorithm in Freeze_Fixed_Point_Type.
11882 -- If both bounds are positive, make sure that both are represen-
11883 -- table in the case where the bounds are crossed. This can happen
11884 -- either because of the way the bounds are declared, or because of
11885 -- the algorithm in Freeze_Fixed_Point_Type.
11891 -- S = size, (can accommodate 0 .. (2**size - 1))
11894 while Hi >= Uint_2 ** S loop
11902 ---------------------------
11903 -- New_Stream_Subprogram --
11904 ---------------------------
11906 procedure New_Stream_Subprogram
11910 Nam : TSS_Name_Type)
11912 Loc : constant Source_Ptr := Sloc (N);
11913 Sname : constant Name_Id := Make_TSS_Name (Base_Type (Ent), Nam);
11914 Subp_Id : Entity_Id;
11915 Subp_Decl : Node_Id;
11919 Defer_Declaration : constant Boolean :=
11920 Is_Tagged_Type (Ent) or else Is_Private_Type (Ent);
11921 -- For a tagged type, there is a declaration for each stream attribute
11922 -- at the freeze point, and we must generate only a completion of this
11923 -- declaration. We do the same for private types, because the full view
11924 -- might be tagged. Otherwise we generate a declaration at the point of
11925 -- the attribute definition clause.
11927 function Build_Spec return Node_Id;
11928 -- Used for declaration and renaming declaration, so that this is
11929 -- treated as a renaming_as_body.
11935 function Build_Spec return Node_Id is
11936 Out_P : constant Boolean := (Nam = TSS_Stream_Read);
11939 T_Ref : constant Node_Id := New_Occurrence_Of (Etyp, Loc);
11942 Subp_Id := Make_Defining_Identifier (Loc, Sname);
11944 -- S : access Root_Stream_Type'Class
11946 Formals := New_List (
11947 Make_Parameter_Specification (Loc,
11948 Defining_Identifier =>
11949 Make_Defining_Identifier (Loc, Name_S),
11951 Make_Access_Definition (Loc,
11953 New_Occurrence_Of (
11954 Designated_Type (Etype (F)), Loc))));
11956 if Nam = TSS_Stream_Input then
11958 Make_Function_Specification (Loc,
11959 Defining_Unit_Name => Subp_Id,
11960 Parameter_Specifications => Formals,
11961 Result_Definition => T_Ref);
11965 Append_To (Formals,
11966 Make_Parameter_Specification (Loc,
11967 Defining_Identifier => Make_Defining_Identifier (Loc, Name_V),
11968 Out_Present => Out_P,
11969 Parameter_Type => T_Ref));
11972 Make_Procedure_Specification (Loc,
11973 Defining_Unit_Name => Subp_Id,
11974 Parameter_Specifications => Formals);
11980 -- Start of processing for New_Stream_Subprogram
11983 F := First_Formal (Subp);
11985 if Ekind (Subp) = E_Procedure then
11986 Etyp := Etype (Next_Formal (F));
11988 Etyp := Etype (Subp);
11991 -- Prepare subprogram declaration and insert it as an action on the
11992 -- clause node. The visibility for this entity is used to test for
11993 -- visibility of the attribute definition clause (in the sense of
11994 -- 8.3(23) as amended by AI-195).
11996 if not Defer_Declaration then
11998 Make_Subprogram_Declaration (Loc,
11999 Specification => Build_Spec);
12001 -- For a tagged type, there is always a visible declaration for each
12002 -- stream TSS (it is a predefined primitive operation), and the
12003 -- completion of this declaration occurs at the freeze point, which is
12004 -- not always visible at places where the attribute definition clause is
12005 -- visible. So, we create a dummy entity here for the purpose of
12006 -- tracking the visibility of the attribute definition clause itself.
12010 Make_Defining_Identifier (Loc, New_External_Name (Sname, 'V'));
12012 Make_Object_Declaration (Loc,
12013 Defining_Identifier => Subp_Id,
12014 Object_Definition => New_Occurrence_Of (Standard_Boolean, Loc));
12017 Insert_Action (N, Subp_Decl);
12018 Set_Entity (N, Subp_Id);
12021 Make_Subprogram_Renaming_Declaration (Loc,
12022 Specification => Build_Spec,
12023 Name => New_Occurrence_Of (Subp, Loc));
12025 if Defer_Declaration then
12026 Set_TSS (Base_Type (Ent), Subp_Id);
12028 Insert_Action (N, Subp_Decl);
12029 Copy_TSS (Subp_Id, Base_Type (Ent));
12031 end New_Stream_Subprogram;
12033 ------------------------------------------
12034 -- Push_Scope_And_Install_Discriminants --
12035 ------------------------------------------
12037 procedure Push_Scope_And_Install_Discriminants (E : Entity_Id) is
12039 if Has_Discriminants (E) then
12042 -- Make the discriminants visible for type declarations and protected
12043 -- type declarations, not for subtype declarations (RM 13.1.1 (12/3))
12045 if Nkind (Parent (E)) /= N_Subtype_Declaration then
12046 Install_Discriminants (E);
12049 end Push_Scope_And_Install_Discriminants;
12051 ------------------------
12052 -- Rep_Item_Too_Early --
12053 ------------------------
12055 function Rep_Item_Too_Early (T : Entity_Id; N : Node_Id) return Boolean is
12057 -- Cannot apply non-operational rep items to generic types
12059 if Is_Operational_Item (N) then
12063 and then Is_Generic_Type (Root_Type (T))
12064 and then (Nkind (N) /= N_Pragma
12065 or else Get_Pragma_Id (N) /= Pragma_Convention)
12067 Error_Msg_N ("representation item not allowed for generic type", N);
12071 -- Otherwise check for incomplete type
12073 if Is_Incomplete_Or_Private_Type (T)
12074 and then No (Underlying_Type (T))
12076 (Nkind (N) /= N_Pragma
12077 or else Get_Pragma_Id (N) /= Pragma_Import)
12080 ("representation item must be after full type declaration", N);
12083 -- If the type has incomplete components, a representation clause is
12084 -- illegal but stream attributes and Convention pragmas are correct.
12086 elsif Has_Private_Component (T) then
12087 if Nkind (N) = N_Pragma then
12092 ("representation item must appear after type is fully defined",
12099 end Rep_Item_Too_Early;
12101 -----------------------
12102 -- Rep_Item_Too_Late --
12103 -----------------------
12105 function Rep_Item_Too_Late
12108 FOnly : Boolean := False) return Boolean
12111 Parent_Type : Entity_Id;
12113 procedure No_Type_Rep_Item;
12114 -- Output message indicating that no type-related aspects can be
12115 -- specified due to some property of the parent type.
12117 procedure Too_Late;
12118 -- Output message for an aspect being specified too late
12120 -- Note that neither of the above errors is considered a serious one,
12121 -- since the effect is simply that we ignore the representation clause
12123 -- Is this really true? In any case if we make this change we must
12124 -- document the requirement in the spec of Rep_Item_Too_Late that
12125 -- if True is returned, then the rep item must be completely ignored???
12127 ----------------------
12128 -- No_Type_Rep_Item --
12129 ----------------------
12131 procedure No_Type_Rep_Item is
12133 Error_Msg_N ("|type-related representation item not permitted!", N);
12134 end No_Type_Rep_Item;
12140 procedure Too_Late is
12142 -- Other compilers seem more relaxed about rep items appearing too
12143 -- late. Since analysis tools typically don't care about rep items
12144 -- anyway, no reason to be too strict about this.
12146 if not Relaxed_RM_Semantics then
12147 Error_Msg_N ("|representation item appears too late!", N);
12151 -- Start of processing for Rep_Item_Too_Late
12154 -- First make sure entity is not frozen (RM 13.1(9))
12158 -- Exclude imported types, which may be frozen if they appear in a
12159 -- representation clause for a local type.
12161 and then not From_Limited_With (T)
12163 -- Exclude generated entities (not coming from source). The common
12164 -- case is when we generate a renaming which prematurely freezes the
12165 -- renamed internal entity, but we still want to be able to set copies
12166 -- of attribute values such as Size/Alignment.
12168 and then Comes_From_Source (T)
12170 -- A self-referential aspect is illegal if it forces freezing the
12171 -- entity before the corresponding pragma has been analyzed.
12173 if Nkind_In (N, N_Attribute_Definition_Clause, N_Pragma)
12174 and then From_Aspect_Specification (N)
12177 ("aspect specification causes premature freezing of&", T, N);
12178 Set_Has_Delayed_Freeze (T, False);
12183 S := First_Subtype (T);
12185 if Present (Freeze_Node (S)) then
12186 if not Relaxed_RM_Semantics then
12188 ("??no more representation items for }", Freeze_Node (S), S);
12194 -- Check for case of untagged derived type whose parent either has
12195 -- primitive operations, or is a by reference type (RM 13.1(10)). In
12196 -- this case we do not output a Too_Late message, since there is no
12197 -- earlier point where the rep item could be placed to make it legal.
12201 and then Is_Derived_Type (T)
12202 and then not Is_Tagged_Type (T)
12204 Parent_Type := Etype (Base_Type (T));
12206 if Has_Primitive_Operations (Parent_Type) then
12209 if not Relaxed_RM_Semantics then
12211 ("\parent type & has primitive operations!", N, Parent_Type);
12216 elsif Is_By_Reference_Type (Parent_Type) then
12219 if not Relaxed_RM_Semantics then
12221 ("\parent type & is a by reference type!", N, Parent_Type);
12228 -- No error, but one more warning to consider. The RM (surprisingly)
12229 -- allows this pattern:
12232 -- primitive operations for S
12233 -- type R is new S;
12234 -- rep clause for S
12236 -- Meaning that calls on the primitive operations of S for values of
12237 -- type R may require possibly expensive implicit conversion operations.
12238 -- This is not an error, but is worth a warning.
12240 if not Relaxed_RM_Semantics and then Is_Type (T) then
12242 DTL : constant Entity_Id := Derived_Type_Link (Base_Type (T));
12246 and then Has_Primitive_Operations (Base_Type (T))
12248 -- For now, do not generate this warning for the case of aspect
12249 -- specification using Ada 2012 syntax, since we get wrong
12250 -- messages we do not understand. The whole business of derived
12251 -- types and rep items seems a bit confused when aspects are
12252 -- used, since the aspects are not evaluated till freeze time.
12254 and then not From_Aspect_Specification (N)
12256 Error_Msg_Sloc := Sloc (DTL);
12258 ("representation item for& appears after derived type "
12259 & "declaration#??", N);
12261 ("\may result in implicit conversions for primitive "
12262 & "operations of&??", N, T);
12264 ("\to change representations when called with arguments "
12265 & "of type&??", N, DTL);
12270 -- No error, link item into head of chain of rep items for the entity,
12271 -- but avoid chaining if we have an overloadable entity, and the pragma
12272 -- is one that can apply to multiple overloaded entities.
12274 if Is_Overloadable (T) and then Nkind (N) = N_Pragma then
12276 Pname : constant Name_Id := Pragma_Name (N);
12278 if Nam_In (Pname, Name_Convention, Name_Import, Name_Export,
12279 Name_External, Name_Interface)
12286 Record_Rep_Item (T, N);
12288 end Rep_Item_Too_Late;
12290 -------------------------------------
12291 -- Replace_Type_References_Generic --
12292 -------------------------------------
12294 procedure Replace_Type_References_Generic (N : Node_Id; T : Entity_Id) is
12295 TName : constant Name_Id := Chars (T);
12297 function Replace_Type_Ref (N : Node_Id) return Traverse_Result;
12298 -- Processes a single node in the traversal procedure below, checking
12299 -- if node N should be replaced, and if so, doing the replacement.
12301 ----------------------
12302 -- Replace_Type_Ref --
12303 ----------------------
12305 function Replace_Type_Ref (N : Node_Id) return Traverse_Result is
12310 -- Case of identifier
12312 if Nkind (N) = N_Identifier then
12314 -- If not the type name, check whether it is a reference to some
12315 -- other type, which must be frozen before the predicate function
12316 -- is analyzed, i.e. before the freeze node of the type to which
12317 -- the predicate applies.
12319 if Chars (N) /= TName then
12320 if Present (Current_Entity (N))
12321 and then Is_Type (Current_Entity (N))
12323 Freeze_Before (Freeze_Node (T), Current_Entity (N));
12328 -- Otherwise do the replacement and we are done with this node
12331 Replace_Type_Reference (N);
12335 -- Case of selected component (which is what a qualification looks
12336 -- like in the unanalyzed tree, which is what we have.
12338 elsif Nkind (N) = N_Selected_Component then
12340 -- If selector name is not our type, keeping going (we might still
12341 -- have an occurrence of the type in the prefix).
12343 if Nkind (Selector_Name (N)) /= N_Identifier
12344 or else Chars (Selector_Name (N)) /= TName
12348 -- Selector name is our type, check qualification
12351 -- Loop through scopes and prefixes, doing comparison
12353 S := Current_Scope;
12356 -- Continue if no more scopes or scope with no name
12358 if No (S) or else Nkind (S) not in N_Has_Chars then
12362 -- Do replace if prefix is an identifier matching the scope
12363 -- that we are currently looking at.
12365 if Nkind (P) = N_Identifier
12366 and then Chars (P) = Chars (S)
12368 Replace_Type_Reference (N);
12372 -- Go check scope above us if prefix is itself of the form
12373 -- of a selected component, whose selector matches the scope
12374 -- we are currently looking at.
12376 if Nkind (P) = N_Selected_Component
12377 and then Nkind (Selector_Name (P)) = N_Identifier
12378 and then Chars (Selector_Name (P)) = Chars (S)
12383 -- For anything else, we don't have a match, so keep on
12384 -- going, there are still some weird cases where we may
12385 -- still have a replacement within the prefix.
12393 -- Continue for any other node kind
12398 end Replace_Type_Ref;
12400 procedure Replace_Type_Refs is new Traverse_Proc (Replace_Type_Ref);
12403 Replace_Type_Refs (N);
12404 end Replace_Type_References_Generic;
12406 --------------------------------
12407 -- Resolve_Aspect_Expressions --
12408 --------------------------------
12410 procedure Resolve_Aspect_Expressions (E : Entity_Id) is
12415 function Resolve_Name (N : Node_Id) return Traverse_Result;
12416 -- Verify that all identifiers in the expression, with the exception
12417 -- of references to the current entity, denote visible entities. This
12418 -- is done only to detect visibility errors, as the expression will be
12419 -- properly analyzed/expanded during analysis of the predicate function
12420 -- body. We omit quantified expressions from this test, given that they
12421 -- introduce a local identifier that would require proper expansion to
12422 -- handle properly.
12428 function Resolve_Name (N : Node_Id) return Traverse_Result is
12430 if Nkind (N) = N_Selected_Component then
12431 if Nkind (Prefix (N)) = N_Identifier
12432 and then Chars (Prefix (N)) /= Chars (E)
12434 Find_Selected_Component (N);
12439 elsif Nkind (N) = N_Identifier and then Chars (N) /= Chars (E) then
12440 Find_Direct_Name (N);
12441 Set_Entity (N, Empty);
12443 elsif Nkind (N) = N_Quantified_Expression then
12450 procedure Resolve_Aspect_Expression is new Traverse_Proc (Resolve_Name);
12452 -- Start of processing for Resolve_Aspect_Expressions
12455 ASN := First_Rep_Item (E);
12456 while Present (ASN) loop
12457 if Nkind (ASN) = N_Aspect_Specification and then Entity (ASN) = E then
12458 A_Id := Get_Aspect_Id (ASN);
12459 Expr := Expression (ASN);
12463 -- For now we only deal with aspects that do not generate
12464 -- subprograms, or that may mention current instances of
12465 -- types. These will require special handling (???TBD).
12467 when Aspect_Predicate |
12468 Aspect_Predicate_Failure |
12469 Aspect_Invariant =>
12472 when Aspect_Dynamic_Predicate |
12473 Aspect_Static_Predicate =>
12475 -- Build predicate function specification and preanalyze
12476 -- expression after type replacement.
12478 if No (Predicate_Function (E)) then
12480 FDecl : constant Node_Id :=
12481 Build_Predicate_Function_Declaration (E);
12482 pragma Unreferenced (FDecl);
12484 Resolve_Aspect_Expression (Expr);
12488 when Pre_Post_Aspects =>
12491 when Aspect_Iterable =>
12492 if Nkind (Expr) = N_Aggregate then
12497 Assoc := First (Component_Associations (Expr));
12498 while Present (Assoc) loop
12499 Find_Direct_Name (Expression (Assoc));
12506 if Present (Expr) then
12507 case Aspect_Argument (A_Id) is
12508 when Expression | Optional_Expression =>
12509 Analyze_And_Resolve (Expression (ASN));
12511 when Name | Optional_Name =>
12512 if Nkind (Expr) = N_Identifier then
12513 Find_Direct_Name (Expr);
12515 elsif Nkind (Expr) = N_Selected_Component then
12516 Find_Selected_Component (Expr);
12526 ASN := Next_Rep_Item (ASN);
12528 end Resolve_Aspect_Expressions;
12530 -------------------------
12531 -- Same_Representation --
12532 -------------------------
12534 function Same_Representation (Typ1, Typ2 : Entity_Id) return Boolean is
12535 T1 : constant Entity_Id := Underlying_Type (Typ1);
12536 T2 : constant Entity_Id := Underlying_Type (Typ2);
12539 -- A quick check, if base types are the same, then we definitely have
12540 -- the same representation, because the subtype specific representation
12541 -- attributes (Size and Alignment) do not affect representation from
12542 -- the point of view of this test.
12544 if Base_Type (T1) = Base_Type (T2) then
12547 elsif Is_Private_Type (Base_Type (T2))
12548 and then Base_Type (T1) = Full_View (Base_Type (T2))
12553 -- Tagged types never have differing representations
12555 if Is_Tagged_Type (T1) then
12559 -- Representations are definitely different if conventions differ
12561 if Convention (T1) /= Convention (T2) then
12565 -- Representations are different if component alignments or scalar
12566 -- storage orders differ.
12568 if (Is_Record_Type (T1) or else Is_Array_Type (T1))
12570 (Is_Record_Type (T2) or else Is_Array_Type (T2))
12572 (Component_Alignment (T1) /= Component_Alignment (T2)
12573 or else Reverse_Storage_Order (T1) /= Reverse_Storage_Order (T2))
12578 -- For arrays, the only real issue is component size. If we know the
12579 -- component size for both arrays, and it is the same, then that's
12580 -- good enough to know we don't have a change of representation.
12582 if Is_Array_Type (T1) then
12583 if Known_Component_Size (T1)
12584 and then Known_Component_Size (T2)
12585 and then Component_Size (T1) = Component_Size (T2)
12591 -- Types definitely have same representation if neither has non-standard
12592 -- representation since default representations are always consistent.
12593 -- If only one has non-standard representation, and the other does not,
12594 -- then we consider that they do not have the same representation. They
12595 -- might, but there is no way of telling early enough.
12597 if Has_Non_Standard_Rep (T1) then
12598 if not Has_Non_Standard_Rep (T2) then
12602 return not Has_Non_Standard_Rep (T2);
12605 -- Here the two types both have non-standard representation, and we need
12606 -- to determine if they have the same non-standard representation.
12608 -- For arrays, we simply need to test if the component sizes are the
12609 -- same. Pragma Pack is reflected in modified component sizes, so this
12610 -- check also deals with pragma Pack.
12612 if Is_Array_Type (T1) then
12613 return Component_Size (T1) = Component_Size (T2);
12615 -- Tagged types always have the same representation, because it is not
12616 -- possible to specify different representations for common fields.
12618 elsif Is_Tagged_Type (T1) then
12621 -- Case of record types
12623 elsif Is_Record_Type (T1) then
12625 -- Packed status must conform
12627 if Is_Packed (T1) /= Is_Packed (T2) then
12630 -- Otherwise we must check components. Typ2 maybe a constrained
12631 -- subtype with fewer components, so we compare the components
12632 -- of the base types.
12635 Record_Case : declare
12636 CD1, CD2 : Entity_Id;
12638 function Same_Rep return Boolean;
12639 -- CD1 and CD2 are either components or discriminants. This
12640 -- function tests whether they have the same representation.
12646 function Same_Rep return Boolean is
12648 if No (Component_Clause (CD1)) then
12649 return No (Component_Clause (CD2));
12651 -- Note: at this point, component clauses have been
12652 -- normalized to the default bit order, so that the
12653 -- comparison of Component_Bit_Offsets is meaningful.
12656 Present (Component_Clause (CD2))
12658 Component_Bit_Offset (CD1) = Component_Bit_Offset (CD2)
12660 Esize (CD1) = Esize (CD2);
12664 -- Start of processing for Record_Case
12667 if Has_Discriminants (T1) then
12669 -- The number of discriminants may be different if the
12670 -- derived type has fewer (constrained by values). The
12671 -- invisible discriminants retain the representation of
12672 -- the original, so the discrepancy does not per se
12673 -- indicate a different representation.
12675 CD1 := First_Discriminant (T1);
12676 CD2 := First_Discriminant (T2);
12677 while Present (CD1) and then Present (CD2) loop
12678 if not Same_Rep then
12681 Next_Discriminant (CD1);
12682 Next_Discriminant (CD2);
12687 CD1 := First_Component (Underlying_Type (Base_Type (T1)));
12688 CD2 := First_Component (Underlying_Type (Base_Type (T2)));
12689 while Present (CD1) loop
12690 if not Same_Rep then
12693 Next_Component (CD1);
12694 Next_Component (CD2);
12702 -- For enumeration types, we must check each literal to see if the
12703 -- representation is the same. Note that we do not permit enumeration
12704 -- representation clauses for Character and Wide_Character, so these
12705 -- cases were already dealt with.
12707 elsif Is_Enumeration_Type (T1) then
12708 Enumeration_Case : declare
12709 L1, L2 : Entity_Id;
12712 L1 := First_Literal (T1);
12713 L2 := First_Literal (T2);
12714 while Present (L1) loop
12715 if Enumeration_Rep (L1) /= Enumeration_Rep (L2) then
12724 end Enumeration_Case;
12726 -- Any other types have the same representation for these purposes
12731 end Same_Representation;
12733 --------------------------------
12734 -- Resolve_Iterable_Operation --
12735 --------------------------------
12737 procedure Resolve_Iterable_Operation
12739 Cursor : Entity_Id;
12748 if not Is_Overloaded (N) then
12749 if not Is_Entity_Name (N)
12750 or else Ekind (Entity (N)) /= E_Function
12751 or else Scope (Entity (N)) /= Scope (Typ)
12752 or else No (First_Formal (Entity (N)))
12753 or else Etype (First_Formal (Entity (N))) /= Typ
12755 Error_Msg_N ("iterable primitive must be local function name "
12756 & "whose first formal is an iterable type", N);
12761 F1 := First_Formal (Ent);
12762 if Nam = Name_First then
12764 -- First (Container) => Cursor
12766 if Etype (Ent) /= Cursor then
12767 Error_Msg_N ("primitive for First must yield a curosr", N);
12770 elsif Nam = Name_Next then
12772 -- Next (Container, Cursor) => Cursor
12774 F2 := Next_Formal (F1);
12776 if Etype (F2) /= Cursor
12777 or else Etype (Ent) /= Cursor
12778 or else Present (Next_Formal (F2))
12780 Error_Msg_N ("no match for Next iterable primitive", N);
12783 elsif Nam = Name_Has_Element then
12785 -- Has_Element (Container, Cursor) => Boolean
12787 F2 := Next_Formal (F1);
12788 if Etype (F2) /= Cursor
12789 or else Etype (Ent) /= Standard_Boolean
12790 or else Present (Next_Formal (F2))
12792 Error_Msg_N ("no match for Has_Element iterable primitive", N);
12795 elsif Nam = Name_Element then
12796 F2 := Next_Formal (F1);
12799 or else Etype (F2) /= Cursor
12800 or else Present (Next_Formal (F2))
12802 Error_Msg_N ("no match for Element iterable primitive", N);
12807 raise Program_Error;
12811 -- Overloaded case: find subprogram with proper signature.
12812 -- Caller will report error if no match is found.
12819 Get_First_Interp (N, I, It);
12820 while Present (It.Typ) loop
12821 if Ekind (It.Nam) = E_Function
12822 and then Scope (It.Nam) = Scope (Typ)
12823 and then Etype (First_Formal (It.Nam)) = Typ
12825 F1 := First_Formal (It.Nam);
12827 if Nam = Name_First then
12828 if Etype (It.Nam) = Cursor
12829 and then No (Next_Formal (F1))
12831 Set_Entity (N, It.Nam);
12835 elsif Nam = Name_Next then
12836 F2 := Next_Formal (F1);
12839 and then No (Next_Formal (F2))
12840 and then Etype (F2) = Cursor
12841 and then Etype (It.Nam) = Cursor
12843 Set_Entity (N, It.Nam);
12847 elsif Nam = Name_Has_Element then
12848 F2 := Next_Formal (F1);
12851 and then No (Next_Formal (F2))
12852 and then Etype (F2) = Cursor
12853 and then Etype (It.Nam) = Standard_Boolean
12855 Set_Entity (N, It.Nam);
12856 F2 := Next_Formal (F1);
12860 elsif Nam = Name_Element then
12861 F2 := Next_Formal (F1);
12864 and then No (Next_Formal (F2))
12865 and then Etype (F2) = Cursor
12867 Set_Entity (N, It.Nam);
12873 Get_Next_Interp (I, It);
12877 end Resolve_Iterable_Operation;
12883 procedure Set_Biased
12887 Biased : Boolean := True)
12891 Set_Has_Biased_Representation (E);
12893 if Warn_On_Biased_Representation then
12895 ("?B?" & Msg & " forces biased representation for&", N, E);
12900 --------------------
12901 -- Set_Enum_Esize --
12902 --------------------
12904 procedure Set_Enum_Esize (T : Entity_Id) is
12910 Init_Alignment (T);
12912 -- Find the minimum standard size (8,16,32,64) that fits
12914 Lo := Enumeration_Rep (Entity (Type_Low_Bound (T)));
12915 Hi := Enumeration_Rep (Entity (Type_High_Bound (T)));
12918 if Lo >= -Uint_2**07 and then Hi < Uint_2**07 then
12919 Sz := Standard_Character_Size; -- May be > 8 on some targets
12921 elsif Lo >= -Uint_2**15 and then Hi < Uint_2**15 then
12924 elsif Lo >= -Uint_2**31 and then Hi < Uint_2**31 then
12927 else pragma Assert (Lo >= -Uint_2**63 and then Hi < Uint_2**63);
12932 if Hi < Uint_2**08 then
12933 Sz := Standard_Character_Size; -- May be > 8 on some targets
12935 elsif Hi < Uint_2**16 then
12938 elsif Hi < Uint_2**32 then
12941 else pragma Assert (Hi < Uint_2**63);
12946 -- That minimum is the proper size unless we have a foreign convention
12947 -- and the size required is 32 or less, in which case we bump the size
12948 -- up to 32. This is required for C and C++ and seems reasonable for
12949 -- all other foreign conventions.
12951 if Has_Foreign_Convention (T)
12952 and then Esize (T) < Standard_Integer_Size
12954 -- Don't do this if Short_Enums on target
12956 and then not Target_Short_Enums
12958 Init_Esize (T, Standard_Integer_Size);
12960 Init_Esize (T, Sz);
12962 end Set_Enum_Esize;
12964 -----------------------------
12965 -- Uninstall_Discriminants --
12966 -----------------------------
12968 procedure Uninstall_Discriminants (E : Entity_Id) is
12974 -- Discriminants have been made visible for type declarations and
12975 -- protected type declarations, not for subtype declarations.
12977 if Nkind (Parent (E)) /= N_Subtype_Declaration then
12978 Disc := First_Discriminant (E);
12979 while Present (Disc) loop
12980 if Disc /= Current_Entity (Disc) then
12981 Prev := Current_Entity (Disc);
12982 while Present (Prev)
12983 and then Present (Homonym (Prev))
12984 and then Homonym (Prev) /= Disc
12986 Prev := Homonym (Prev);
12992 Set_Is_Immediately_Visible (Disc, False);
12994 Outer := Homonym (Disc);
12995 while Present (Outer) and then Scope (Outer) = E loop
12996 Outer := Homonym (Outer);
12999 -- Reset homonym link of other entities, but do not modify link
13000 -- between entities in current scope, so that the back end can
13001 -- have a proper count of local overloadings.
13004 Set_Name_Entity_Id (Chars (Disc), Outer);
13006 elsif Scope (Prev) /= Scope (Disc) then
13007 Set_Homonym (Prev, Outer);
13010 Next_Discriminant (Disc);
13013 end Uninstall_Discriminants;
13015 -------------------------------------------
13016 -- Uninstall_Discriminants_And_Pop_Scope --
13017 -------------------------------------------
13019 procedure Uninstall_Discriminants_And_Pop_Scope (E : Entity_Id) is
13021 if Has_Discriminants (E) then
13022 Uninstall_Discriminants (E);
13025 end Uninstall_Discriminants_And_Pop_Scope;
13027 ------------------------------
13028 -- Validate_Address_Clauses --
13029 ------------------------------
13031 procedure Validate_Address_Clauses is
13032 function Offset_Value (Expr : Node_Id) return Uint;
13033 -- Given an Address attribute reference, return the value in bits of its
13034 -- offset from the first bit of the underlying entity, or 0 if it is not
13035 -- known at compile time.
13041 function Offset_Value (Expr : Node_Id) return Uint is
13042 N : Node_Id := Prefix (Expr);
13044 Val : Uint := Uint_0;
13047 -- Climb the prefix chain and compute the cumulative offset
13050 if Is_Entity_Name (N) then
13053 elsif Nkind (N) = N_Selected_Component then
13054 Off := Component_Bit_Offset (Entity (Selector_Name (N)));
13055 if Off /= No_Uint and then Off >= Uint_0 then
13062 elsif Nkind (N) = N_Indexed_Component then
13063 Off := Indexed_Component_Bit_Offset (N);
13064 if Off /= No_Uint then
13077 -- Start of processing for Validate_Address_Clauses
13080 for J in Address_Clause_Checks.First .. Address_Clause_Checks.Last loop
13082 ACCR : Address_Clause_Check_Record
13083 renames Address_Clause_Checks.Table (J);
13087 X_Alignment : Uint;
13088 Y_Alignment : Uint;
13096 -- Skip processing of this entry if warning already posted
13098 if not Address_Warning_Posted (ACCR.N) then
13099 Expr := Original_Node (Expression (ACCR.N));
13103 X_Alignment := Alignment (ACCR.X);
13104 Y_Alignment := Alignment (ACCR.Y);
13106 -- Similarly obtain sizes and offset
13108 X_Size := Esize (ACCR.X);
13109 Y_Size := Esize (ACCR.Y);
13112 and then Nkind (Expr) = N_Attribute_Reference
13113 and then Attribute_Name (Expr) = Name_Address
13115 X_Offs := Offset_Value (Expr);
13120 -- Check for large object overlaying smaller one
13123 and then X_Size > Uint_0
13124 and then X_Offs + X_Size > Y_Size
13126 Error_Msg_NE ("??& overlays smaller object", ACCR.N, ACCR.X);
13128 ("\??program execution may be erroneous", ACCR.N);
13130 Error_Msg_Uint_1 := X_Size;
13131 Error_Msg_NE ("\??size of & is ^", ACCR.N, ACCR.X);
13133 Error_Msg_Uint_1 := Y_Size;
13134 Error_Msg_NE ("\??size of & is ^", ACCR.N, ACCR.Y);
13136 if Y_Size >= X_Size then
13137 Error_Msg_Uint_1 := X_Offs;
13138 Error_Msg_NE ("\??but offset of & is ^", ACCR.N, ACCR.X);
13141 -- Check for inadequate alignment, both of the base object
13142 -- and of the offset, if any. We only do this check if the
13143 -- run-time Alignment_Check is active. No point in warning
13144 -- if this check has been suppressed (or is suppressed by
13145 -- default in the non-strict alignment machine case).
13147 -- Note: we do not check the alignment if we gave a size
13148 -- warning, since it would likely be redundant.
13150 elsif not Alignment_Checks_Suppressed (ACCR.Y)
13151 and then Y_Alignment /= Uint_0
13153 (Y_Alignment < X_Alignment
13156 and then Nkind (Expr) = N_Attribute_Reference
13157 and then Attribute_Name (Expr) = Name_Address
13158 and then Has_Compatible_Alignment
13159 (ACCR.X, Prefix (Expr), True) /=
13163 ("??specified address for& may be inconsistent with "
13164 & "alignment", ACCR.N, ACCR.X);
13166 ("\??program execution may be erroneous (RM 13.3(27))",
13169 Error_Msg_Uint_1 := X_Alignment;
13170 Error_Msg_NE ("\??alignment of & is ^", ACCR.N, ACCR.X);
13172 Error_Msg_Uint_1 := Y_Alignment;
13173 Error_Msg_NE ("\??alignment of & is ^", ACCR.N, ACCR.Y);
13175 if Y_Alignment >= X_Alignment then
13177 ("\??but offset is not multiple of alignment", ACCR.N);
13183 end Validate_Address_Clauses;
13185 ---------------------------
13186 -- Validate_Independence --
13187 ---------------------------
13189 procedure Validate_Independence is
13190 SU : constant Uint := UI_From_Int (System_Storage_Unit);
13198 procedure Check_Array_Type (Atyp : Entity_Id);
13199 -- Checks if the array type Atyp has independent components, and
13200 -- if not, outputs an appropriate set of error messages.
13202 procedure No_Independence;
13203 -- Output message that independence cannot be guaranteed
13205 function OK_Component (C : Entity_Id) return Boolean;
13206 -- Checks one component to see if it is independently accessible, and
13207 -- if so yields True, otherwise yields False if independent access
13208 -- cannot be guaranteed. This is a conservative routine, it only
13209 -- returns True if it knows for sure, it returns False if it knows
13210 -- there is a problem, or it cannot be sure there is no problem.
13212 procedure Reason_Bad_Component (C : Entity_Id);
13213 -- Outputs continuation message if a reason can be determined for
13214 -- the component C being bad.
13216 ----------------------
13217 -- Check_Array_Type --
13218 ----------------------
13220 procedure Check_Array_Type (Atyp : Entity_Id) is
13221 Ctyp : constant Entity_Id := Component_Type (Atyp);
13224 -- OK if no alignment clause, no pack, and no component size
13226 if not Has_Component_Size_Clause (Atyp)
13227 and then not Has_Alignment_Clause (Atyp)
13228 and then not Is_Packed (Atyp)
13233 -- Case of component size is greater than or equal to 64 and the
13234 -- alignment of the array is at least as large as the alignment
13235 -- of the component. We are definitely OK in this situation.
13237 if Known_Component_Size (Atyp)
13238 and then Component_Size (Atyp) >= 64
13239 and then Known_Alignment (Atyp)
13240 and then Known_Alignment (Ctyp)
13241 and then Alignment (Atyp) >= Alignment (Ctyp)
13246 -- Check actual component size
13248 if not Known_Component_Size (Atyp)
13249 or else not (Addressable (Component_Size (Atyp))
13250 and then Component_Size (Atyp) < 64)
13251 or else Component_Size (Atyp) mod Esize (Ctyp) /= 0
13255 -- Bad component size, check reason
13257 if Has_Component_Size_Clause (Atyp) then
13258 P := Get_Attribute_Definition_Clause
13259 (Atyp, Attribute_Component_Size);
13261 if Present (P) then
13262 Error_Msg_Sloc := Sloc (P);
13263 Error_Msg_N ("\because of Component_Size clause#", N);
13268 if Is_Packed (Atyp) then
13269 P := Get_Rep_Pragma (Atyp, Name_Pack);
13271 if Present (P) then
13272 Error_Msg_Sloc := Sloc (P);
13273 Error_Msg_N ("\because of pragma Pack#", N);
13278 -- No reason found, just return
13283 -- Array type is OK independence-wise
13286 end Check_Array_Type;
13288 ---------------------
13289 -- No_Independence --
13290 ---------------------
13292 procedure No_Independence is
13294 if Pragma_Name (N) = Name_Independent then
13295 Error_Msg_NE ("independence cannot be guaranteed for&", N, E);
13298 ("independent components cannot be guaranteed for&", N, E);
13300 end No_Independence;
13306 function OK_Component (C : Entity_Id) return Boolean is
13307 Rec : constant Entity_Id := Scope (C);
13308 Ctyp : constant Entity_Id := Etype (C);
13311 -- OK if no component clause, no Pack, and no alignment clause
13313 if No (Component_Clause (C))
13314 and then not Is_Packed (Rec)
13315 and then not Has_Alignment_Clause (Rec)
13320 -- Here we look at the actual component layout. A component is
13321 -- addressable if its size is a multiple of the Esize of the
13322 -- component type, and its starting position in the record has
13323 -- appropriate alignment, and the record itself has appropriate
13324 -- alignment to guarantee the component alignment.
13326 -- Make sure sizes are static, always assume the worst for any
13327 -- cases where we cannot check static values.
13329 if not (Known_Static_Esize (C)
13331 Known_Static_Esize (Ctyp))
13336 -- Size of component must be addressable or greater than 64 bits
13337 -- and a multiple of bytes.
13339 if not Addressable (Esize (C)) and then Esize (C) < Uint_64 then
13343 -- Check size is proper multiple
13345 if Esize (C) mod Esize (Ctyp) /= 0 then
13349 -- Check alignment of component is OK
13351 if not Known_Component_Bit_Offset (C)
13352 or else Component_Bit_Offset (C) < Uint_0
13353 or else Component_Bit_Offset (C) mod Esize (Ctyp) /= 0
13358 -- Check alignment of record type is OK
13360 if not Known_Alignment (Rec)
13361 or else (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0
13366 -- All tests passed, component is addressable
13371 --------------------------
13372 -- Reason_Bad_Component --
13373 --------------------------
13375 procedure Reason_Bad_Component (C : Entity_Id) is
13376 Rec : constant Entity_Id := Scope (C);
13377 Ctyp : constant Entity_Id := Etype (C);
13380 -- If component clause present assume that's the problem
13382 if Present (Component_Clause (C)) then
13383 Error_Msg_Sloc := Sloc (Component_Clause (C));
13384 Error_Msg_N ("\because of Component_Clause#", N);
13388 -- If pragma Pack clause present, assume that's the problem
13390 if Is_Packed (Rec) then
13391 P := Get_Rep_Pragma (Rec, Name_Pack);
13393 if Present (P) then
13394 Error_Msg_Sloc := Sloc (P);
13395 Error_Msg_N ("\because of pragma Pack#", N);
13400 -- See if record has bad alignment clause
13402 if Has_Alignment_Clause (Rec)
13403 and then Known_Alignment (Rec)
13404 and then (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0
13406 P := Get_Attribute_Definition_Clause (Rec, Attribute_Alignment);
13408 if Present (P) then
13409 Error_Msg_Sloc := Sloc (P);
13410 Error_Msg_N ("\because of Alignment clause#", N);
13414 -- Couldn't find a reason, so return without a message
13417 end Reason_Bad_Component;
13419 -- Start of processing for Validate_Independence
13422 for J in Independence_Checks.First .. Independence_Checks.Last loop
13423 N := Independence_Checks.Table (J).N;
13424 E := Independence_Checks.Table (J).E;
13425 IC := Pragma_Name (N) = Name_Independent_Components;
13427 -- Deal with component case
13429 if Ekind (E) = E_Discriminant or else Ekind (E) = E_Component then
13430 if not OK_Component (E) then
13432 Reason_Bad_Component (E);
13437 -- Deal with record with Independent_Components
13439 if IC and then Is_Record_Type (E) then
13440 Comp := First_Component_Or_Discriminant (E);
13441 while Present (Comp) loop
13442 if not OK_Component (Comp) then
13444 Reason_Bad_Component (Comp);
13448 Next_Component_Or_Discriminant (Comp);
13452 -- Deal with address clause case
13454 if Is_Object (E) then
13455 Addr := Address_Clause (E);
13457 if Present (Addr) then
13459 Error_Msg_Sloc := Sloc (Addr);
13460 Error_Msg_N ("\because of Address clause#", N);
13465 -- Deal with independent components for array type
13467 if IC and then Is_Array_Type (E) then
13468 Check_Array_Type (E);
13471 -- Deal with independent components for array object
13473 if IC and then Is_Object (E) and then Is_Array_Type (Etype (E)) then
13474 Check_Array_Type (Etype (E));
13479 end Validate_Independence;
13481 ------------------------------
13482 -- Validate_Iterable_Aspect --
13483 ------------------------------
13485 procedure Validate_Iterable_Aspect (Typ : Entity_Id; ASN : Node_Id) is
13490 Cursor : constant Entity_Id := Get_Cursor_Type (ASN, Typ);
13492 First_Id : Entity_Id;
13493 Next_Id : Entity_Id;
13494 Has_Element_Id : Entity_Id;
13495 Element_Id : Entity_Id;
13498 -- If previous error aspect is unusable
13500 if Cursor = Any_Type then
13506 Has_Element_Id := Empty;
13507 Element_Id := Empty;
13509 -- Each expression must resolve to a function with the proper signature
13511 Assoc := First (Component_Associations (Expression (ASN)));
13512 while Present (Assoc) loop
13513 Expr := Expression (Assoc);
13516 Prim := First (Choices (Assoc));
13518 if Nkind (Prim) /= N_Identifier or else Present (Next (Prim)) then
13519 Error_Msg_N ("illegal name in association", Prim);
13521 elsif Chars (Prim) = Name_First then
13522 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_First);
13523 First_Id := Entity (Expr);
13525 elsif Chars (Prim) = Name_Next then
13526 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Next);
13527 Next_Id := Entity (Expr);
13529 elsif Chars (Prim) = Name_Has_Element then
13530 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Has_Element);
13531 Has_Element_Id := Entity (Expr);
13533 elsif Chars (Prim) = Name_Element then
13534 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Element);
13535 Element_Id := Entity (Expr);
13538 Error_Msg_N ("invalid name for iterable function", Prim);
13544 if No (First_Id) then
13545 Error_Msg_N ("match for First primitive not found", ASN);
13547 elsif No (Next_Id) then
13548 Error_Msg_N ("match for Next primitive not found", ASN);
13550 elsif No (Has_Element_Id) then
13551 Error_Msg_N ("match for Has_Element primitive not found", ASN);
13553 elsif No (Element_Id) then
13556 end Validate_Iterable_Aspect;
13558 -----------------------------------
13559 -- Validate_Unchecked_Conversion --
13560 -----------------------------------
13562 procedure Validate_Unchecked_Conversion
13564 Act_Unit : Entity_Id)
13566 Source : Entity_Id;
13567 Target : Entity_Id;
13571 -- Obtain source and target types. Note that we call Ancestor_Subtype
13572 -- here because the processing for generic instantiation always makes
13573 -- subtypes, and we want the original frozen actual types.
13575 -- If we are dealing with private types, then do the check on their
13576 -- fully declared counterparts if the full declarations have been
13577 -- encountered (they don't have to be visible, but they must exist).
13579 Source := Ancestor_Subtype (Etype (First_Formal (Act_Unit)));
13581 if Is_Private_Type (Source)
13582 and then Present (Underlying_Type (Source))
13584 Source := Underlying_Type (Source);
13587 Target := Ancestor_Subtype (Etype (Act_Unit));
13589 -- If either type is generic, the instantiation happens within a generic
13590 -- unit, and there is nothing to check. The proper check will happen
13591 -- when the enclosing generic is instantiated.
13593 if Is_Generic_Type (Source) or else Is_Generic_Type (Target) then
13597 if Is_Private_Type (Target)
13598 and then Present (Underlying_Type (Target))
13600 Target := Underlying_Type (Target);
13603 -- Source may be unconstrained array, but not target, except in relaxed
13606 if Is_Array_Type (Target)
13607 and then not Is_Constrained (Target)
13608 and then not Relaxed_RM_Semantics
13611 ("unchecked conversion to unconstrained array not allowed", N);
13615 -- Warn if conversion between two different convention pointers
13617 if Is_Access_Type (Target)
13618 and then Is_Access_Type (Source)
13619 and then Convention (Target) /= Convention (Source)
13620 and then Warn_On_Unchecked_Conversion
13622 -- Give warnings for subprogram pointers only on most targets
13624 if Is_Access_Subprogram_Type (Target)
13625 or else Is_Access_Subprogram_Type (Source)
13628 ("?z?conversion between pointers with different conventions!",
13633 -- Warn if one of the operands is Ada.Calendar.Time. Do not emit a
13634 -- warning when compiling GNAT-related sources.
13636 if Warn_On_Unchecked_Conversion
13637 and then not In_Predefined_Unit (N)
13638 and then RTU_Loaded (Ada_Calendar)
13639 and then (Chars (Source) = Name_Time
13641 Chars (Target) = Name_Time)
13643 -- If Ada.Calendar is loaded and the name of one of the operands is
13644 -- Time, there is a good chance that this is Ada.Calendar.Time.
13647 Calendar_Time : constant Entity_Id := Full_View (RTE (RO_CA_Time));
13649 pragma Assert (Present (Calendar_Time));
13651 if Source = Calendar_Time or else Target = Calendar_Time then
13653 ("?z?representation of 'Time values may change between "
13654 & "'G'N'A'T versions", N);
13659 -- Make entry in unchecked conversion table for later processing by
13660 -- Validate_Unchecked_Conversions, which will check sizes and alignments
13661 -- (using values set by the back end where possible). This is only done
13662 -- if the appropriate warning is active.
13664 if Warn_On_Unchecked_Conversion then
13665 Unchecked_Conversions.Append
13666 (New_Val => UC_Entry'(Eloc => Sloc (N),
13669 Act_Unit => Act_Unit));
13671 -- If both sizes are known statically now, then back-end annotation
13672 -- is not required to do a proper check but if either size is not
13673 -- known statically, then we need the annotation.
13675 if Known_Static_RM_Size (Source)
13677 Known_Static_RM_Size (Target)
13681 Back_Annotate_Rep_Info := True;
13685 -- If unchecked conversion to access type, and access type is declared
13686 -- in the same unit as the unchecked conversion, then set the flag
13687 -- No_Strict_Aliasing (no strict aliasing is implicit here)
13689 if Is_Access_Type (Target) and then
13690 In_Same_Source_Unit (Target, N)
13692 Set_No_Strict_Aliasing (Implementation_Base_Type (Target));
13695 -- Generate N_Validate_Unchecked_Conversion node for back end in case
13696 -- the back end needs to perform special validation checks.
13698 -- Shouldn't this be in Exp_Ch13, since the check only gets done if we
13699 -- have full expansion and the back end is called ???
13702 Make_Validate_Unchecked_Conversion (Sloc (N));
13703 Set_Source_Type (Vnode, Source);
13704 Set_Target_Type (Vnode, Target);
13706 -- If the unchecked conversion node is in a list, just insert before it.
13707 -- If not we have some strange case, not worth bothering about.
13709 if Is_List_Member (N) then
13710 Insert_After (N, Vnode);
13712 end Validate_Unchecked_Conversion;
13714 ------------------------------------
13715 -- Validate_Unchecked_Conversions --
13716 ------------------------------------
13718 procedure Validate_Unchecked_Conversions is
13720 for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop
13722 T : UC_Entry renames Unchecked_Conversions.Table (N);
13724 Act_Unit : constant Entity_Id := T.Act_Unit;
13725 Eloc : constant Source_Ptr := T.Eloc;
13726 Source : constant Entity_Id := T.Source;
13727 Target : constant Entity_Id := T.Target;
13733 -- Skip if function marked as warnings off
13735 if Warnings_Off (Act_Unit) then
13739 -- This validation check, which warns if we have unequal sizes for
13740 -- unchecked conversion, and thus potentially implementation
13741 -- dependent semantics, is one of the few occasions on which we
13742 -- use the official RM size instead of Esize. See description in
13743 -- Einfo "Handling of Type'Size Values" for details.
13745 if Serious_Errors_Detected = 0
13746 and then Known_Static_RM_Size (Source)
13747 and then Known_Static_RM_Size (Target)
13749 -- Don't do the check if warnings off for either type, note the
13750 -- deliberate use of OR here instead of OR ELSE to get the flag
13751 -- Warnings_Off_Used set for both types if appropriate.
13753 and then not (Has_Warnings_Off (Source)
13755 Has_Warnings_Off (Target))
13757 Source_Siz := RM_Size (Source);
13758 Target_Siz := RM_Size (Target);
13760 if Source_Siz /= Target_Siz then
13762 ("?z?types for unchecked conversion have different sizes!",
13765 if All_Errors_Mode then
13766 Error_Msg_Name_1 := Chars (Source);
13767 Error_Msg_Uint_1 := Source_Siz;
13768 Error_Msg_Name_2 := Chars (Target);
13769 Error_Msg_Uint_2 := Target_Siz;
13770 Error_Msg ("\size of % is ^, size of % is ^?z?", Eloc);
13772 Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz);
13774 if Is_Discrete_Type (Source)
13776 Is_Discrete_Type (Target)
13778 if Source_Siz > Target_Siz then
13780 ("\?z?^ high order bits of source will "
13781 & "be ignored!", Eloc);
13783 elsif Is_Unsigned_Type (Source) then
13785 ("\?z?source will be extended with ^ high order "
13786 & "zero bits!", Eloc);
13790 ("\?z?source will be extended with ^ high order "
13791 & "sign bits!", Eloc);
13794 elsif Source_Siz < Target_Siz then
13795 if Is_Discrete_Type (Target) then
13796 if Bytes_Big_Endian then
13798 ("\?z?target value will include ^ undefined "
13799 & "low order bits!", Eloc);
13802 ("\?z?target value will include ^ undefined "
13803 & "high order bits!", Eloc);
13808 ("\?z?^ trailing bits of target value will be "
13809 & "undefined!", Eloc);
13812 else pragma Assert (Source_Siz > Target_Siz);
13813 if Is_Discrete_Type (Source) then
13814 if Bytes_Big_Endian then
13816 ("\?z?^ low order bits of source will be "
13817 & "ignored!", Eloc);
13820 ("\?z?^ high order bits of source will be "
13821 & "ignored!", Eloc);
13826 ("\?z?^ trailing bits of source will be "
13827 & "ignored!", Eloc);
13834 -- If both types are access types, we need to check the alignment.
13835 -- If the alignment of both is specified, we can do it here.
13837 if Serious_Errors_Detected = 0
13838 and then Is_Access_Type (Source)
13839 and then Is_Access_Type (Target)
13840 and then Target_Strict_Alignment
13841 and then Present (Designated_Type (Source))
13842 and then Present (Designated_Type (Target))
13845 D_Source : constant Entity_Id := Designated_Type (Source);
13846 D_Target : constant Entity_Id := Designated_Type (Target);
13849 if Known_Alignment (D_Source)
13851 Known_Alignment (D_Target)
13854 Source_Align : constant Uint := Alignment (D_Source);
13855 Target_Align : constant Uint := Alignment (D_Target);
13858 if Source_Align < Target_Align
13859 and then not Is_Tagged_Type (D_Source)
13861 -- Suppress warning if warnings suppressed on either
13862 -- type or either designated type. Note the use of
13863 -- OR here instead of OR ELSE. That is intentional,
13864 -- we would like to set flag Warnings_Off_Used in
13865 -- all types for which warnings are suppressed.
13867 and then not (Has_Warnings_Off (D_Source)
13869 Has_Warnings_Off (D_Target)
13871 Has_Warnings_Off (Source)
13873 Has_Warnings_Off (Target))
13875 Error_Msg_Uint_1 := Target_Align;
13876 Error_Msg_Uint_2 := Source_Align;
13877 Error_Msg_Node_1 := D_Target;
13878 Error_Msg_Node_2 := D_Source;
13880 ("?z?alignment of & (^) is stricter than "
13881 & "alignment of & (^)!", Eloc);
13883 ("\?z?resulting access value may have invalid "
13884 & "alignment!", Eloc);
13895 end Validate_Unchecked_Conversions;