1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2019, 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 Par_SCO; use Par_SCO;
45 with Restrict; use Restrict;
46 with Rident; use Rident;
47 with Rtsfind; use Rtsfind;
49 with Sem_Aux; use Sem_Aux;
50 with Sem_Case; use Sem_Case;
51 with Sem_Ch3; use Sem_Ch3;
52 with Sem_Ch6; use Sem_Ch6;
53 with Sem_Ch7; use Sem_Ch7;
54 with Sem_Ch8; use Sem_Ch8;
55 with Sem_Dim; use Sem_Dim;
56 with Sem_Disp; use Sem_Disp;
57 with Sem_Eval; use Sem_Eval;
58 with Sem_Prag; use Sem_Prag;
59 with Sem_Res; use Sem_Res;
60 with Sem_Type; use Sem_Type;
61 with Sem_Util; use Sem_Util;
62 with Sem_Warn; use Sem_Warn;
63 with Sinfo; use Sinfo;
64 with Sinput; use Sinput;
65 with Snames; use Snames;
66 with Stand; use Stand;
67 with Targparm; use Targparm;
68 with Ttypes; use Ttypes;
69 with Tbuild; use Tbuild;
70 with Urealp; use Urealp;
71 with Warnsw; use Warnsw;
73 with GNAT.Heap_Sort_G;
75 package body Sem_Ch13 is
77 SSU : constant Pos := System_Storage_Unit;
78 -- Convenient short hand for commonly used constant
80 -----------------------
81 -- Local Subprograms --
82 -----------------------
84 procedure Adjust_Record_For_Reverse_Bit_Order_Ada_95 (R : Entity_Id);
85 -- Helper routine providing the original (pre-AI95-0133) behavior for
86 -- Adjust_Record_For_Reverse_Bit_Order.
88 procedure Alignment_Check_For_Size_Change (Typ : Entity_Id; Size : Uint);
89 -- This routine is called after setting one of the sizes of type entity
90 -- Typ to Size. The purpose is to deal with the situation of a derived
91 -- type whose inherited alignment is no longer appropriate for the new
92 -- size value. In this case, we reset the Alignment to unknown.
94 procedure Build_Discrete_Static_Predicate
98 -- Given a predicated type Typ, where Typ is a discrete static subtype,
99 -- whose predicate expression is Expr, tests if Expr is a static predicate,
100 -- and if so, builds the predicate range list. Nam is the name of the one
101 -- argument to the predicate function. Occurrences of the type name in the
102 -- predicate expression have been replaced by identifier references to this
103 -- name, which is unique, so any identifier with Chars matching Nam must be
104 -- a reference to the type. If the predicate is non-static, this procedure
105 -- returns doing nothing. If the predicate is static, then the predicate
106 -- list is stored in Static_Discrete_Predicate (Typ), and the Expr is
107 -- rewritten as a canonicalized membership operation.
109 function Build_Export_Import_Pragma
111 Id : Entity_Id) return Node_Id;
112 -- Create the corresponding pragma for aspect Export or Import denoted by
113 -- Asp. Id is the related entity subject to the aspect. Return Empty when
114 -- the expression of aspect Asp evaluates to False or is erroneous.
116 function Build_Predicate_Function_Declaration
117 (Typ : Entity_Id) return Node_Id;
118 -- Build the declaration for a predicate function. The declaration is built
119 -- at the end of the declarative part containing the type definition, which
120 -- may be before the freeze point of the type. The predicate expression is
121 -- preanalyzed at this point, to catch visibility errors.
123 procedure Build_Predicate_Functions (Typ : Entity_Id; N : Node_Id);
124 -- If Typ has predicates (indicated by Has_Predicates being set for Typ),
125 -- then either there are pragma Predicate entries on the rep chain for the
126 -- type (note that Predicate aspects are converted to pragma Predicate), or
127 -- there are inherited aspects from a parent type, or ancestor subtypes.
128 -- This procedure builds body for the Predicate function that tests these
129 -- predicates. N is the freeze node for the type. The spec of the function
130 -- is inserted before the freeze node, and the body of the function is
131 -- inserted after the freeze node. If the predicate expression has a least
132 -- one Raise_Expression, then this procedure also builds the M version of
133 -- the predicate function for use in membership tests.
135 procedure Check_Pool_Size_Clash (Ent : Entity_Id; SP, SS : Node_Id);
136 -- Called if both Storage_Pool and Storage_Size attribute definition
137 -- clauses (SP and SS) are present for entity Ent. Issue error message.
139 procedure Freeze_Entity_Checks (N : Node_Id);
140 -- Called from Analyze_Freeze_Entity and Analyze_Generic_Freeze Entity
141 -- to generate appropriate semantic checks that are delayed until this
142 -- point (they had to be delayed this long for cases of delayed aspects,
143 -- e.g. analysis of statically predicated subtypes in choices, for which
144 -- we have to be sure the subtypes in question are frozen before checking).
146 function Get_Alignment_Value (Expr : Node_Id) return Uint;
147 -- Given the expression for an alignment value, returns the corresponding
148 -- Uint value. If the value is inappropriate, then error messages are
149 -- posted as required, and a value of No_Uint is returned.
151 function Is_Operational_Item (N : Node_Id) return Boolean;
152 -- A specification for a stream attribute is allowed before the full type
153 -- is declared, as explained in AI-00137 and the corrigendum. Attributes
154 -- that do not specify a representation characteristic are operational
157 function Is_Type_Related_Rep_Item (N : Node_Id) return Boolean;
158 -- Returns True for a representation clause/pragma that specifies a
159 -- type-related representation (as opposed to operational) aspect.
161 function Is_Predicate_Static
163 Nam : Name_Id) return Boolean;
164 -- Given predicate expression Expr, tests if Expr is predicate-static in
165 -- the sense of the rules in (RM 3.2.4 (15-24)). Occurrences of the type
166 -- name in the predicate expression have been replaced by references to
167 -- an identifier whose Chars field is Nam. This name is unique, so any
168 -- identifier with Chars matching Nam must be a reference to the type.
169 -- Returns True if the expression is predicate-static and False otherwise,
170 -- but is not in the business of setting flags or issuing error messages.
172 -- Only scalar types can have static predicates, so False is always
173 -- returned for non-scalar types.
175 -- Note: the RM seems to suggest that string types can also have static
176 -- predicates. But that really makes lttle sense as very few useful
177 -- predicates can be constructed for strings. Remember that:
181 -- is not a static expression. So even though the clearly faulty RM wording
182 -- allows the following:
184 -- subtype S is String with Static_Predicate => S < "DEF"
186 -- We can't allow this, otherwise we have predicate-static applying to a
187 -- larger class than static expressions, which was never intended.
189 procedure New_Stream_Subprogram
193 Nam : TSS_Name_Type);
194 -- Create a subprogram renaming of a given stream attribute to the
195 -- designated subprogram and then in the tagged case, provide this as a
196 -- primitive operation, or in the untagged case make an appropriate TSS
197 -- entry. This is more properly an expansion activity than just semantics,
198 -- but the presence of user-defined stream functions for limited types
199 -- is a legality check, which is why this takes place here rather than in
200 -- exp_ch13, where it was previously. Nam indicates the name of the TSS
201 -- function to be generated.
203 -- To avoid elaboration anomalies with freeze nodes, for untagged types
204 -- we generate both a subprogram declaration and a subprogram renaming
205 -- declaration, so that the attribute specification is handled as a
206 -- renaming_as_body. For tagged types, the specification is one of the
209 procedure Register_Address_Clause_Check
215 -- Register a check for the address clause N. The rest of the parameters
216 -- are in keeping with the components of Address_Clause_Check_Record below.
218 procedure Resolve_Iterable_Operation
223 -- If the name of a primitive operation for an Iterable aspect is
224 -- overloaded, resolve according to required signature.
230 Biased : Boolean := True);
231 -- If Biased is True, sets Has_Biased_Representation flag for E, and
232 -- outputs a warning message at node N if Warn_On_Biased_Representation is
233 -- is True. This warning inserts the string Msg to describe the construct
236 -----------------------------------------------------------
237 -- Visibility of Discriminants in Aspect Specifications --
238 -----------------------------------------------------------
240 -- The discriminants of a type are visible when analyzing the aspect
241 -- specifications of a type declaration or protected type declaration,
242 -- but not when analyzing those of a subtype declaration. The following
243 -- routines enforce this distinction.
245 procedure Push_Type (E : Entity_Id);
246 -- Push scope E and make visible the discriminants of type entity E if E
247 -- has discriminants and is not a subtype.
249 procedure Pop_Type (E : Entity_Id);
250 -- Remove visibility to the discriminants of type entity E and pop the
251 -- scope stack if E has discriminants and is not a subtype.
253 ----------------------------------------------
254 -- Table for Validate_Unchecked_Conversions --
255 ----------------------------------------------
257 -- The following table collects unchecked conversions for validation.
258 -- Entries are made by Validate_Unchecked_Conversion and then the call
259 -- to Validate_Unchecked_Conversions does the actual error checking and
260 -- posting of warnings. The reason for this delayed processing is to take
261 -- advantage of back-annotations of size and alignment values performed by
264 -- Note: the reason we store a Source_Ptr value instead of a Node_Id is
265 -- that by the time Validate_Unchecked_Conversions is called, Sprint will
266 -- already have modified all Sloc values if the -gnatD option is set.
268 type UC_Entry is record
269 Eloc : Source_Ptr; -- node used for posting warnings
270 Source : Entity_Id; -- source type for unchecked conversion
271 Target : Entity_Id; -- target type for unchecked conversion
272 Act_Unit : Entity_Id; -- actual function instantiated
275 package Unchecked_Conversions is new Table.Table (
276 Table_Component_Type => UC_Entry,
277 Table_Index_Type => Int,
278 Table_Low_Bound => 1,
280 Table_Increment => 200,
281 Table_Name => "Unchecked_Conversions");
283 ----------------------------------------
284 -- Table for Validate_Address_Clauses --
285 ----------------------------------------
287 -- If an address clause has the form
289 -- for X'Address use Expr
291 -- where Expr has a value known at compile time or is of the form Y'Address
292 -- or recursively is a reference to a constant initialized with either of
293 -- these forms, and the value of Expr is not a multiple of X's alignment,
294 -- or if Y has a smaller alignment than X, then that merits a warning about
295 -- possible bad alignment. The following table collects address clauses of
296 -- this kind. We put these in a table so that they can be checked after the
297 -- back end has completed annotation of the alignments of objects, since we
298 -- can catch more cases that way.
300 type Address_Clause_Check_Record is record
302 -- The address clause
305 -- The entity of the object subject to the address clause
308 -- The value of the address in the first case
311 -- The entity of the object being overlaid in the second case
314 -- Whether the address is offset within Y in the second case
316 Alignment_Checks_Suppressed : Boolean;
317 -- Whether alignment checks are suppressed by an active scope suppress
318 -- setting. We need to save the value in order to be able to reuse it
319 -- after the back end has been run.
322 package Address_Clause_Checks is new Table.Table (
323 Table_Component_Type => Address_Clause_Check_Record,
324 Table_Index_Type => Int,
325 Table_Low_Bound => 1,
327 Table_Increment => 200,
328 Table_Name => "Address_Clause_Checks");
330 function Alignment_Checks_Suppressed
331 (ACCR : Address_Clause_Check_Record) return Boolean;
332 -- Return whether the alignment check generated for the address clause
335 ---------------------------------
336 -- Alignment_Checks_Suppressed --
337 ---------------------------------
339 function Alignment_Checks_Suppressed
340 (ACCR : Address_Clause_Check_Record) return Boolean
343 if Checks_May_Be_Suppressed (ACCR.X) then
344 return Is_Check_Suppressed (ACCR.X, Alignment_Check);
346 return ACCR.Alignment_Checks_Suppressed;
348 end Alignment_Checks_Suppressed;
350 -----------------------------------------
351 -- Adjust_Record_For_Reverse_Bit_Order --
352 -----------------------------------------
354 procedure Adjust_Record_For_Reverse_Bit_Order (R : Entity_Id) is
355 Max_Machine_Scalar_Size : constant Uint :=
357 (Standard_Long_Long_Integer_Size);
358 -- We use this as the maximum machine scalar size
360 SSU : constant Uint := UI_From_Int (System_Storage_Unit);
367 -- The processing done here used to depend on the Ada version, but the
368 -- behavior has been changed by AI95-0133. However this AI is a Binding
369 -- Interpretation, so we now implement it even in Ada 95 mode. But the
370 -- original behavior from unamended Ada 95 is available for the sake of
371 -- compatibility under the debugging switch -gnatd.p in Ada 95 mode.
373 if Ada_Version < Ada_2005 and then Debug_Flag_Dot_P then
374 Adjust_Record_For_Reverse_Bit_Order_Ada_95 (R);
378 -- For Ada 2005, we do machine scalar processing, as fully described In
379 -- AI-133. This involves gathering all components which start at the
380 -- same byte offset and processing them together. Same approach is still
381 -- valid in later versions including Ada 2012.
383 -- Note that component clauses found on record types may be inherited,
384 -- in which case the layout of the component with such a clause still
385 -- has to be done at this point. Therefore, the processing done here
386 -- must exclusively rely on the Component_Clause of the component.
388 -- This first loop through components does two things. First it deals
389 -- with the case of components with component clauses whose length is
390 -- greater than the maximum machine scalar size (either accepting them
391 -- or rejecting as needed). Second, it counts the number of components
392 -- with component clauses whose length does not exceed this maximum for
396 Comp := First_Component_Or_Discriminant (R);
397 while Present (Comp) loop
398 CC := Component_Clause (Comp);
402 Fbit : constant Uint := Static_Integer (First_Bit (CC));
403 Lbit : constant Uint := Static_Integer (Last_Bit (CC));
406 -- Case of component with last bit >= max machine scalar
408 if Lbit >= Max_Machine_Scalar_Size then
410 -- This is allowed only if first bit is zero, and last bit
411 -- + 1 is a multiple of storage unit size.
413 if Fbit = 0 and then (Lbit + 1) mod SSU = 0 then
415 -- This is the case to give a warning if enabled
417 if Warn_On_Reverse_Bit_Order then
419 ("info: multi-byte field specified with "
420 & "non-standard Bit_Order?V?", CC);
422 if Bytes_Big_Endian then
424 ("\bytes are not reversed "
425 & "(component is big-endian)?V?", CC);
428 ("\bytes are not reversed "
429 & "(component is little-endian)?V?", CC);
433 -- Give error message for RM 13.5.1(10) violation
437 ("machine scalar rules not followed for&",
438 First_Bit (CC), Comp);
440 Error_Msg_Uint_1 := Lbit + 1;
441 Error_Msg_Uint_2 := Max_Machine_Scalar_Size;
443 ("\last bit + 1 (^) exceeds maximum machine scalar "
444 & "size (^)", First_Bit (CC));
446 if (Lbit + 1) mod SSU /= 0 then
447 Error_Msg_Uint_1 := SSU;
449 ("\and is not a multiple of Storage_Unit (^) "
450 & "(RM 13.5.1(10))", First_Bit (CC));
453 Error_Msg_Uint_1 := Fbit;
455 ("\and first bit (^) is non-zero "
456 & "(RM 13.4.1(10))", First_Bit (CC));
460 -- OK case of machine scalar related component clause. For now,
464 Num_CC := Num_CC + 1;
469 Next_Component_Or_Discriminant (Comp);
472 -- We need to sort the component clauses on the basis of the Position
473 -- values in the clause, so we can group clauses with the same Position
474 -- together to determine the relevant machine scalar size.
477 Comps : array (0 .. Num_CC) of Entity_Id;
478 -- Array to collect component and discriminant entities. The data
479 -- starts at index 1, the 0'th entry is for the sort routine.
481 function CP_Lt (Op1, Op2 : Natural) return Boolean;
482 -- Compare routine for Sort
484 procedure CP_Move (From : Natural; To : Natural);
485 -- Move routine for Sort
487 package Sorting is new GNAT.Heap_Sort_G (CP_Move, CP_Lt);
490 -- Maximum last bit value of any component in this set
493 -- Corresponding machine scalar size
497 -- Start and stop positions in the component list of the set of
498 -- components with the same starting position (that constitute
499 -- components in a single machine scalar).
505 function CP_Lt (Op1, Op2 : Natural) return Boolean is
508 Position (Component_Clause (Comps (Op1))) <
509 Position (Component_Clause (Comps (Op2)));
516 procedure CP_Move (From : Natural; To : Natural) is
518 Comps (To) := Comps (From);
521 -- Start of processing for Sort_CC
524 -- Collect the machine scalar relevant component clauses
527 Comp := First_Component_Or_Discriminant (R);
528 while Present (Comp) loop
530 CC : constant Node_Id := Component_Clause (Comp);
533 -- Collect only component clauses whose last bit is less than
534 -- machine scalar size. Any component clause whose last bit
535 -- exceeds this value does not take part in machine scalar
536 -- layout considerations. The test for Error_Posted makes sure
537 -- we exclude component clauses for which we already posted an
541 and then not Error_Posted (Last_Bit (CC))
542 and then Static_Integer (Last_Bit (CC)) <
543 Max_Machine_Scalar_Size
545 Num_CC := Num_CC + 1;
546 Comps (Num_CC) := Comp;
550 Next_Component_Or_Discriminant (Comp);
553 -- Sort by ascending position number
555 Sorting.Sort (Num_CC);
557 -- We now have all the components whose size does not exceed the max
558 -- machine scalar value, sorted by starting position. In this loop we
559 -- gather groups of clauses starting at the same position, to process
560 -- them in accordance with AI-133.
563 while Stop < Num_CC loop
568 (Last_Bit (Component_Clause (Comps (Start))));
569 while Stop < Num_CC loop
571 (Position (Component_Clause (Comps (Stop + 1)))) =
573 (Position (Component_Clause (Comps (Stop))))
581 (Component_Clause (Comps (Stop)))));
587 -- Now we have a group of component clauses from Start to Stop
588 -- whose positions are identical, and MaxL is the maximum last
589 -- bit value of any of these components.
591 -- We need to determine the corresponding machine scalar size.
592 -- This loop assumes that machine scalar sizes are even, and that
593 -- each possible machine scalar has twice as many bits as the next
596 MSS := Max_Machine_Scalar_Size;
598 and then (MSS / 2) >= SSU
599 and then (MSS / 2) > MaxL
604 -- Here is where we fix up the Component_Bit_Offset value to
605 -- account for the reverse bit order. Some examples of what needs
606 -- to be done for the case of a machine scalar size of 8 are:
608 -- First_Bit .. Last_Bit Component_Bit_Offset
620 -- The rule is that the first bit is obtained by subtracting the
621 -- old ending bit from machine scalar size - 1.
623 for C in Start .. Stop loop
625 Comp : constant Entity_Id := Comps (C);
626 CC : constant Node_Id := Component_Clause (Comp);
628 FB : constant Uint := Static_Integer (First_Bit (CC));
629 LB : constant Uint := Static_Integer (Last_Bit (CC));
630 NFB : constant Uint := MSS - 1 - LB;
631 NLB : constant Uint := NFB + LB - FB;
632 Pos : constant Uint := Static_Integer (Position (CC));
635 -- Do not warn for the artificial clause built for the tag
636 -- in Check_Record_Representation_Clause if it is inherited.
638 if Warn_On_Reverse_Bit_Order
639 and then Chars (Comp) /= Name_uTag
641 Error_Msg_Uint_1 := MSS;
643 ("info: reverse bit order in machine scalar of "
644 & "length^?V?", First_Bit (CC));
645 Error_Msg_Uint_1 := NFB;
646 Error_Msg_Uint_2 := NLB;
648 if Bytes_Big_Endian then
650 ("\big-endian range for component & is ^ .. ^?V?",
651 First_Bit (CC), Comp);
654 ("\little-endian range for component & is ^ .. ^?V?",
655 First_Bit (CC), Comp);
659 Set_Component_Bit_Offset (Comp, Pos * SSU + NFB);
660 Set_Esize (Comp, 1 + (NLB - NFB));
661 Set_Normalized_First_Bit (Comp, NFB mod SSU);
662 Set_Normalized_Position (Comp, Pos + NFB / SSU);
667 end Adjust_Record_For_Reverse_Bit_Order;
669 ------------------------------------------------
670 -- Adjust_Record_For_Reverse_Bit_Order_Ada_95 --
671 ------------------------------------------------
673 procedure Adjust_Record_For_Reverse_Bit_Order_Ada_95 (R : Entity_Id) is
678 -- For Ada 95, we just renumber bits within a storage unit. We do the
679 -- same for Ada 83 mode, since we recognize the Bit_Order attribute in
680 -- Ada 83, and are free to add this extension.
682 Comp := First_Component_Or_Discriminant (R);
683 while Present (Comp) loop
684 CC := Component_Clause (Comp);
686 -- If component clause is present, then deal with the non-default
687 -- bit order case for Ada 95 mode.
689 -- We only do this processing for the base type, and in fact that
690 -- is important, since otherwise if there are record subtypes, we
691 -- could reverse the bits once for each subtype, which is wrong.
693 if Present (CC) and then Ekind (R) = E_Record_Type then
695 CFB : constant Uint := Component_Bit_Offset (Comp);
696 CSZ : constant Uint := Esize (Comp);
697 CLC : constant Node_Id := Component_Clause (Comp);
698 Pos : constant Node_Id := Position (CLC);
699 FB : constant Node_Id := First_Bit (CLC);
701 Storage_Unit_Offset : constant Uint :=
702 CFB / System_Storage_Unit;
704 Start_Bit : constant Uint :=
705 CFB mod System_Storage_Unit;
708 -- Cases where field goes over storage unit boundary
710 if Start_Bit + CSZ > System_Storage_Unit then
712 -- Allow multi-byte field but generate warning
714 if Start_Bit mod System_Storage_Unit = 0
715 and then CSZ mod System_Storage_Unit = 0
718 ("info: multi-byte field specified with non-standard "
719 & "Bit_Order?V?", CLC);
721 if Bytes_Big_Endian then
723 ("\bytes are not reversed "
724 & "(component is big-endian)?V?", CLC);
727 ("\bytes are not reversed "
728 & "(component is little-endian)?V?", CLC);
731 -- Do not allow non-contiguous field
735 ("attempt to specify non-contiguous field not "
738 ("\caused by non-standard Bit_Order specified in "
739 & "legacy Ada 95 mode", CLC);
742 -- Case where field fits in one storage unit
745 -- Give warning if suspicious component clause
747 if Intval (FB) >= System_Storage_Unit
748 and then Warn_On_Reverse_Bit_Order
751 ("info: Bit_Order clause does not affect byte "
752 & "ordering?V?", Pos);
754 Intval (Pos) + Intval (FB) /
757 ("info: position normalized to ^ before bit order "
758 & "interpreted?V?", Pos);
761 -- Here is where we fix up the Component_Bit_Offset value
762 -- to account for the reverse bit order. Some examples of
763 -- what needs to be done are:
765 -- First_Bit .. Last_Bit Component_Bit_Offset
777 -- The rule is that the first bit is obtained by subtracting
778 -- the old ending bit from storage_unit - 1.
780 Set_Component_Bit_Offset (Comp,
781 (Storage_Unit_Offset * System_Storage_Unit) +
782 (System_Storage_Unit - 1) -
783 (Start_Bit + CSZ - 1));
785 Set_Normalized_Position (Comp,
786 Component_Bit_Offset (Comp) / System_Storage_Unit);
788 Set_Normalized_First_Bit (Comp,
789 Component_Bit_Offset (Comp) mod System_Storage_Unit);
794 Next_Component_Or_Discriminant (Comp);
796 end Adjust_Record_For_Reverse_Bit_Order_Ada_95;
798 -------------------------------------
799 -- Alignment_Check_For_Size_Change --
800 -------------------------------------
802 procedure Alignment_Check_For_Size_Change (Typ : Entity_Id; Size : Uint) is
804 -- If the alignment is known, and not set by a rep clause, and is
805 -- inconsistent with the size being set, then reset it to unknown,
806 -- we assume in this case that the size overrides the inherited
807 -- alignment, and that the alignment must be recomputed.
809 if Known_Alignment (Typ)
810 and then not Has_Alignment_Clause (Typ)
811 and then Size mod (Alignment (Typ) * SSU) /= 0
813 Init_Alignment (Typ);
815 end Alignment_Check_For_Size_Change;
817 -------------------------------------
818 -- Analyze_Aspects_At_Freeze_Point --
819 -------------------------------------
821 procedure Analyze_Aspects_At_Freeze_Point (E : Entity_Id) is
822 procedure Analyze_Aspect_Default_Value (ASN : Node_Id);
823 -- This routine analyzes an Aspect_Default_[Component_]Value denoted by
824 -- the aspect specification node ASN.
826 procedure Inherit_Delayed_Rep_Aspects (ASN : Node_Id);
827 -- As discussed in the spec of Aspects (see Aspect_Delay declaration),
828 -- a derived type can inherit aspects from its parent which have been
829 -- specified at the time of the derivation using an aspect, as in:
831 -- type A is range 1 .. 10
832 -- with Size => Not_Defined_Yet;
836 -- Not_Defined_Yet : constant := 64;
838 -- In this example, the Size of A is considered to be specified prior
839 -- to the derivation, and thus inherited, even though the value is not
840 -- known at the time of derivation. To deal with this, we use two entity
841 -- flags. The flag Has_Derived_Rep_Aspects is set in the parent type (A
842 -- here), and then the flag May_Inherit_Delayed_Rep_Aspects is set in
843 -- the derived type (B here). If this flag is set when the derived type
844 -- is frozen, then this procedure is called to ensure proper inheritance
845 -- of all delayed aspects from the parent type. The derived type is E,
846 -- the argument to Analyze_Aspects_At_Freeze_Point. ASN is the first
847 -- aspect specification node in the Rep_Item chain for the parent type.
849 procedure Make_Pragma_From_Boolean_Aspect (ASN : Node_Id);
850 -- Given an aspect specification node ASN whose expression is an
851 -- optional Boolean, this routines creates the corresponding pragma
852 -- at the freezing point.
854 ----------------------------------
855 -- Analyze_Aspect_Default_Value --
856 ----------------------------------
858 procedure Analyze_Aspect_Default_Value (ASN : Node_Id) is
859 A_Id : constant Aspect_Id := Get_Aspect_Id (ASN);
860 Ent : constant Entity_Id := Entity (ASN);
861 Expr : constant Node_Id := Expression (ASN);
862 Id : constant Node_Id := Identifier (ASN);
865 Error_Msg_Name_1 := Chars (Id);
867 if not Is_Type (Ent) then
868 Error_Msg_N ("aspect% can only apply to a type", Id);
871 elsif not Is_First_Subtype (Ent) then
872 Error_Msg_N ("aspect% cannot apply to subtype", Id);
875 elsif A_Id = Aspect_Default_Value
876 and then not Is_Scalar_Type (Ent)
878 Error_Msg_N ("aspect% can only be applied to scalar type", Id);
881 elsif A_Id = Aspect_Default_Component_Value then
882 if not Is_Array_Type (Ent) then
883 Error_Msg_N ("aspect% can only be applied to array type", Id);
886 elsif not Is_Scalar_Type (Component_Type (Ent)) then
887 Error_Msg_N ("aspect% requires scalar components", Id);
892 Set_Has_Default_Aspect (Base_Type (Ent));
894 if Is_Scalar_Type (Ent) then
895 Set_Default_Aspect_Value (Base_Type (Ent), Expr);
897 Set_Default_Aspect_Component_Value (Base_Type (Ent), Expr);
899 end Analyze_Aspect_Default_Value;
901 ---------------------------------
902 -- Inherit_Delayed_Rep_Aspects --
903 ---------------------------------
905 procedure Inherit_Delayed_Rep_Aspects (ASN : Node_Id) is
906 A_Id : constant Aspect_Id := Get_Aspect_Id (ASN);
907 P : constant Entity_Id := Entity (ASN);
908 -- Entithy for parent type
911 -- Item from Rep_Item chain
916 -- Loop through delayed aspects for the parent type
919 while Present (N) loop
920 if Nkind (N) = N_Aspect_Specification then
921 exit when Entity (N) /= P;
923 if Is_Delayed_Aspect (N) then
924 A := Get_Aspect_Id (Chars (Identifier (N)));
926 -- Process delayed rep aspect. For Boolean attributes it is
927 -- not possible to cancel an attribute once set (the attempt
928 -- to use an aspect with xxx => False is an error) for a
929 -- derived type. So for those cases, we do not have to check
930 -- if a clause has been given for the derived type, since it
931 -- is harmless to set it again if it is already set.
937 when Aspect_Alignment =>
938 if not Has_Alignment_Clause (E) then
939 Set_Alignment (E, Alignment (P));
944 when Aspect_Atomic =>
945 if Is_Atomic (P) then
951 when Aspect_Atomic_Components =>
952 if Has_Atomic_Components (P) then
953 Set_Has_Atomic_Components (Base_Type (E));
958 when Aspect_Bit_Order =>
959 if Is_Record_Type (E)
960 and then No (Get_Attribute_Definition_Clause
961 (E, Attribute_Bit_Order))
962 and then Reverse_Bit_Order (P)
964 Set_Reverse_Bit_Order (Base_Type (E));
969 when Aspect_Component_Size =>
971 and then not Has_Component_Size_Clause (E)
974 (Base_Type (E), Component_Size (P));
979 when Aspect_Machine_Radix =>
980 if Is_Decimal_Fixed_Point_Type (E)
981 and then not Has_Machine_Radix_Clause (E)
983 Set_Machine_Radix_10 (E, Machine_Radix_10 (P));
986 -- Object_Size (also Size which also sets Object_Size)
988 when Aspect_Object_Size
991 if not Has_Size_Clause (E)
993 No (Get_Attribute_Definition_Clause
994 (E, Attribute_Object_Size))
996 Set_Esize (E, Esize (P));
1002 if not Is_Packed (E) then
1003 Set_Is_Packed (Base_Type (E));
1005 if Is_Bit_Packed_Array (P) then
1006 Set_Is_Bit_Packed_Array (Base_Type (E));
1007 Set_Packed_Array_Impl_Type
1008 (E, Packed_Array_Impl_Type (P));
1012 -- Scalar_Storage_Order
1014 when Aspect_Scalar_Storage_Order =>
1015 if (Is_Record_Type (E) or else Is_Array_Type (E))
1016 and then No (Get_Attribute_Definition_Clause
1017 (E, Attribute_Scalar_Storage_Order))
1018 and then Reverse_Storage_Order (P)
1020 Set_Reverse_Storage_Order (Base_Type (E));
1022 -- Clear default SSO indications, since the aspect
1023 -- overrides the default.
1025 Set_SSO_Set_Low_By_Default (Base_Type (E), False);
1026 Set_SSO_Set_High_By_Default (Base_Type (E), False);
1031 when Aspect_Small =>
1032 if Is_Fixed_Point_Type (E)
1033 and then not Has_Small_Clause (E)
1035 Set_Small_Value (E, Small_Value (P));
1040 when Aspect_Storage_Size =>
1041 if (Is_Access_Type (E) or else Is_Task_Type (E))
1042 and then not Has_Storage_Size_Clause (E)
1044 Set_Storage_Size_Variable
1045 (Base_Type (E), Storage_Size_Variable (P));
1050 when Aspect_Value_Size =>
1052 -- Value_Size is never inherited, it is either set by
1053 -- default, or it is explicitly set for the derived
1054 -- type. So nothing to do here.
1060 when Aspect_Volatile =>
1061 if Is_Volatile (P) then
1062 Set_Is_Volatile (E);
1065 -- Volatile_Full_Access
1067 when Aspect_Volatile_Full_Access =>
1068 if Is_Volatile_Full_Access (P) then
1069 Set_Is_Volatile_Full_Access (E);
1072 -- Volatile_Components
1074 when Aspect_Volatile_Components =>
1075 if Has_Volatile_Components (P) then
1076 Set_Has_Volatile_Components (Base_Type (E));
1079 -- That should be all the Rep Aspects
1082 pragma Assert (Aspect_Delay (A_Id) /= Rep_Aspect);
1088 N := Next_Rep_Item (N);
1090 end Inherit_Delayed_Rep_Aspects;
1092 -------------------------------------
1093 -- Make_Pragma_From_Boolean_Aspect --
1094 -------------------------------------
1096 procedure Make_Pragma_From_Boolean_Aspect (ASN : Node_Id) is
1097 Ident : constant Node_Id := Identifier (ASN);
1098 A_Name : constant Name_Id := Chars (Ident);
1099 A_Id : constant Aspect_Id := Get_Aspect_Id (A_Name);
1100 Ent : constant Entity_Id := Entity (ASN);
1101 Expr : constant Node_Id := Expression (ASN);
1102 Loc : constant Source_Ptr := Sloc (ASN);
1104 procedure Check_False_Aspect_For_Derived_Type;
1105 -- This procedure checks for the case of a false aspect for a derived
1106 -- type, which improperly tries to cancel an aspect inherited from
1109 -----------------------------------------
1110 -- Check_False_Aspect_For_Derived_Type --
1111 -----------------------------------------
1113 procedure Check_False_Aspect_For_Derived_Type is
1117 -- We are only checking derived types
1119 if not Is_Derived_Type (E) then
1123 Par := Nearest_Ancestor (E);
1129 if not Is_Atomic (Par) then
1133 when Aspect_Atomic_Components =>
1134 if not Has_Atomic_Components (Par) then
1138 when Aspect_Discard_Names =>
1139 if not Discard_Names (Par) then
1144 if not Is_Packed (Par) then
1148 when Aspect_Unchecked_Union =>
1149 if not Is_Unchecked_Union (Par) then
1153 when Aspect_Volatile =>
1154 if not Is_Volatile (Par) then
1158 when Aspect_Volatile_Components =>
1159 if not Has_Volatile_Components (Par) then
1163 when Aspect_Volatile_Full_Access =>
1164 if not Is_Volatile_Full_Access (Par) then
1172 -- Fall through means we are canceling an inherited aspect
1174 Error_Msg_Name_1 := A_Name;
1176 ("derived type& inherits aspect%, cannot cancel", Expr, E);
1177 end Check_False_Aspect_For_Derived_Type;
1183 -- Start of processing for Make_Pragma_From_Boolean_Aspect
1186 -- Note that we know Expr is present, because for a missing Expr
1187 -- argument, we knew it was True and did not need to delay the
1188 -- evaluation to the freeze point.
1190 if Is_False (Static_Boolean (Expr)) then
1191 Check_False_Aspect_For_Derived_Type;
1196 Pragma_Identifier =>
1197 Make_Identifier (Sloc (Ident), Chars (Ident)),
1198 Pragma_Argument_Associations => New_List (
1199 Make_Pragma_Argument_Association (Sloc (Ident),
1200 Expression => New_Occurrence_Of (Ent, Sloc (Ident)))));
1202 Set_From_Aspect_Specification (Prag, True);
1203 Set_Corresponding_Aspect (Prag, ASN);
1204 Set_Aspect_Rep_Item (ASN, Prag);
1205 Set_Is_Delayed_Aspect (Prag);
1206 Set_Parent (Prag, ASN);
1208 end Make_Pragma_From_Boolean_Aspect;
1216 -- Start of processing for Analyze_Aspects_At_Freeze_Point
1219 -- Must be visible in current scope, but if this is a type from a nested
1220 -- package it may be frozen from an object declaration in the enclosing
1221 -- scope, so install the package declarations to complete the analysis
1222 -- of the aspects, if any. If the package itself is frozen the type will
1223 -- have been frozen as well.
1225 if not Scope_Within_Or_Same (Current_Scope, Scope (E)) then
1226 if Is_Type (E) and then From_Nested_Package (E) then
1228 Pack : constant Entity_Id := Scope (E);
1232 Install_Visible_Declarations (Pack);
1233 Install_Private_Declarations (Pack);
1234 Analyze_Aspects_At_Freeze_Point (E);
1236 if Is_Private_Type (E)
1237 and then Present (Full_View (E))
1239 Analyze_Aspects_At_Freeze_Point (Full_View (E));
1242 End_Package_Scope (Pack);
1246 -- Aspects from other entities in different contexts are analyzed
1254 -- Look for aspect specification entries for this entity
1256 ASN := First_Rep_Item (E);
1257 while Present (ASN) loop
1258 if Nkind (ASN) = N_Aspect_Specification then
1259 exit when Entity (ASN) /= E;
1261 if Is_Delayed_Aspect (ASN) then
1262 A_Id := Get_Aspect_Id (ASN);
1266 -- For aspects whose expression is an optional Boolean, make
1267 -- the corresponding pragma at the freeze point.
1269 when Boolean_Aspects
1270 | Library_Unit_Aspects
1272 -- Aspects Export and Import require special handling.
1273 -- Both are by definition Boolean and may benefit from
1274 -- forward references, however their expressions are
1275 -- treated as static. In addition, the syntax of their
1276 -- corresponding pragmas requires extra "pieces" which
1277 -- may also contain forward references. To account for
1278 -- all of this, the corresponding pragma is created by
1279 -- Analyze_Aspect_Export_Import, but is not analyzed as
1280 -- the complete analysis must happen now.
1282 if A_Id = Aspect_Export or else A_Id = Aspect_Import then
1285 -- Otherwise create a corresponding pragma
1288 Make_Pragma_From_Boolean_Aspect (ASN);
1291 -- Special handling for aspects that don't correspond to
1292 -- pragmas/attributes.
1294 when Aspect_Default_Value
1295 | Aspect_Default_Component_Value
1297 -- Do not inherit aspect for anonymous base type of a
1298 -- scalar or array type, because they apply to the first
1299 -- subtype of the type, and will be processed when that
1300 -- first subtype is frozen.
1302 if Is_Derived_Type (E)
1303 and then not Comes_From_Source (E)
1304 and then E /= First_Subtype (E)
1308 Analyze_Aspect_Default_Value (ASN);
1311 -- Ditto for iterator aspects, because the corresponding
1312 -- attributes may not have been analyzed yet.
1314 when Aspect_Constant_Indexing
1315 | Aspect_Default_Iterator
1316 | Aspect_Iterator_Element
1317 | Aspect_Variable_Indexing
1319 Analyze (Expression (ASN));
1321 if Etype (Expression (ASN)) = Any_Type then
1323 ("\aspect must be fully defined before & is frozen",
1327 when Aspect_Iterable =>
1328 Validate_Iterable_Aspect (E, ASN);
1334 Ritem := Aspect_Rep_Item (ASN);
1336 if Present (Ritem) then
1342 Next_Rep_Item (ASN);
1345 -- This is where we inherit delayed rep aspects from our parent. Note
1346 -- that if we fell out of the above loop with ASN non-empty, it means
1347 -- we hit an aspect for an entity other than E, and it must be the
1348 -- type from which we were derived.
1350 if May_Inherit_Delayed_Rep_Aspects (E) then
1351 Inherit_Delayed_Rep_Aspects (ASN);
1355 and then E /= Base_Type (E)
1356 and then Is_First_Subtype (E)
1358 Inherit_Rep_Item_Chain (Base_Type (E), E);
1360 end Analyze_Aspects_At_Freeze_Point;
1362 -----------------------------------
1363 -- Analyze_Aspect_Specifications --
1364 -----------------------------------
1366 procedure Analyze_Aspect_Specifications (N : Node_Id; E : Entity_Id) is
1367 pragma Assert (Present (E));
1369 procedure Decorate (Asp : Node_Id; Prag : Node_Id);
1370 -- Establish linkages between an aspect and its corresponding pragma
1372 procedure Insert_Pragma
1374 Is_Instance : Boolean := False);
1375 -- Subsidiary to the analysis of aspects
1382 -- Initial_Condition
1391 -- Insert pragma Prag such that it mimics the placement of a source
1392 -- pragma of the same kind. Flag Is_Generic should be set when the
1393 -- context denotes a generic instance.
1399 procedure Decorate (Asp : Node_Id; Prag : Node_Id) is
1401 Set_Aspect_Rep_Item (Asp, Prag);
1402 Set_Corresponding_Aspect (Prag, Asp);
1403 Set_From_Aspect_Specification (Prag);
1404 Set_Parent (Prag, Asp);
1411 procedure Insert_Pragma
1413 Is_Instance : Boolean := False)
1419 Inserted : Boolean := False;
1422 -- When the aspect appears on an entry, package, protected unit,
1423 -- subprogram, or task unit body, insert the generated pragma at the
1424 -- top of the body declarations to emulate the behavior of a source
1427 -- package body Pack with Aspect is
1429 -- package body Pack is
1432 if Nkind_In (N, N_Entry_Body,
1438 Decls := Declarations (N);
1442 Set_Declarations (N, Decls);
1445 Prepend_To (Decls, Prag);
1447 -- When the aspect is associated with a [generic] package declaration
1448 -- insert the generated pragma at the top of the visible declarations
1449 -- to emulate the behavior of a source pragma.
1451 -- package Pack with Aspect is
1456 elsif Nkind_In (N, N_Generic_Package_Declaration,
1457 N_Package_Declaration)
1459 Decls := Visible_Declarations (Specification (N));
1463 Set_Visible_Declarations (Specification (N), Decls);
1466 -- The visible declarations of a generic instance have the
1467 -- following structure:
1469 -- <renamings of generic formals>
1470 -- <renamings of internally-generated spec and body>
1471 -- <first source declaration>
1473 -- Insert the pragma before the first source declaration by
1474 -- skipping the instance "header" to ensure proper visibility of
1478 Decl := First (Decls);
1479 while Present (Decl) loop
1480 if Comes_From_Source (Decl) then
1481 Insert_Before (Decl, Prag);
1489 -- The pragma is placed after the instance "header"
1491 if not Inserted then
1492 Append_To (Decls, Prag);
1495 -- Otherwise this is not a generic instance
1498 Prepend_To (Decls, Prag);
1501 -- When the aspect is associated with a protected unit declaration,
1502 -- insert the generated pragma at the top of the visible declarations
1503 -- the emulate the behavior of a source pragma.
1505 -- protected [type] Prot with Aspect is
1507 -- protected [type] Prot is
1510 elsif Nkind (N) = N_Protected_Type_Declaration then
1511 Def := Protected_Definition (N);
1515 Make_Protected_Definition (Sloc (N),
1516 Visible_Declarations => New_List,
1517 End_Label => Empty);
1519 Set_Protected_Definition (N, Def);
1522 Decls := Visible_Declarations (Def);
1526 Set_Visible_Declarations (Def, Decls);
1529 Prepend_To (Decls, Prag);
1531 -- When the aspect is associated with a task unit declaration, insert
1532 -- insert the generated pragma at the top of the visible declarations
1533 -- the emulate the behavior of a source pragma.
1535 -- task [type] Prot with Aspect is
1537 -- task [type] Prot is
1540 elsif Nkind (N) = N_Task_Type_Declaration then
1541 Def := Task_Definition (N);
1545 Make_Task_Definition (Sloc (N),
1546 Visible_Declarations => New_List,
1547 End_Label => Empty);
1549 Set_Task_Definition (N, Def);
1552 Decls := Visible_Declarations (Def);
1556 Set_Visible_Declarations (Def, Decls);
1559 Prepend_To (Decls, Prag);
1561 -- When the context is a library unit, the pragma is added to the
1562 -- Pragmas_After list.
1564 elsif Nkind (Parent (N)) = N_Compilation_Unit then
1565 Aux := Aux_Decls_Node (Parent (N));
1567 if No (Pragmas_After (Aux)) then
1568 Set_Pragmas_After (Aux, New_List);
1571 Prepend (Prag, Pragmas_After (Aux));
1573 -- Default, the pragma is inserted after the context
1576 Insert_After (N, Prag);
1586 L : constant List_Id := Aspect_Specifications (N);
1587 pragma Assert (Present (L));
1589 Ins_Node : Node_Id := N;
1590 -- Insert pragmas/attribute definition clause after this node when no
1591 -- delayed analysis is required.
1593 -- Start of processing for Analyze_Aspect_Specifications
1596 -- The general processing involves building an attribute definition
1597 -- clause or a pragma node that corresponds to the aspect. Then in order
1598 -- to delay the evaluation of this aspect to the freeze point, we attach
1599 -- the corresponding pragma/attribute definition clause to the aspect
1600 -- specification node, which is then placed in the Rep Item chain. In
1601 -- this case we mark the entity by setting the flag Has_Delayed_Aspects
1602 -- and we evaluate the rep item at the freeze point. When the aspect
1603 -- doesn't have a corresponding pragma/attribute definition clause, then
1604 -- its analysis is simply delayed at the freeze point.
1606 -- Some special cases don't require delay analysis, thus the aspect is
1607 -- analyzed right now.
1609 -- Note that there is a special handling for Pre, Post, Test_Case,
1610 -- Contract_Cases aspects. In these cases, we do not have to worry
1611 -- about delay issues, since the pragmas themselves deal with delay
1612 -- of visibility for the expression analysis. Thus, we just insert
1613 -- the pragma after the node N.
1615 -- Loop through aspects
1617 Aspect := First (L);
1618 Aspect_Loop : while Present (Aspect) loop
1619 Analyze_One_Aspect : declare
1620 Expr : constant Node_Id := Expression (Aspect);
1621 Id : constant Node_Id := Identifier (Aspect);
1622 Loc : constant Source_Ptr := Sloc (Aspect);
1623 Nam : constant Name_Id := Chars (Id);
1624 A_Id : constant Aspect_Id := Get_Aspect_Id (Nam);
1627 Delay_Required : Boolean;
1628 -- Set False if delay is not required
1630 Eloc : Source_Ptr := No_Location;
1631 -- Source location of expression, modified when we split PPC's. It
1632 -- is set below when Expr is present.
1634 procedure Analyze_Aspect_Convention;
1635 -- Perform analysis of aspect Convention
1637 procedure Analyze_Aspect_Disable_Controlled;
1638 -- Perform analysis of aspect Disable_Controlled
1640 procedure Analyze_Aspect_Export_Import;
1641 -- Perform analysis of aspects Export or Import
1643 procedure Analyze_Aspect_External_Link_Name;
1644 -- Perform analysis of aspects External_Name or Link_Name
1646 procedure Analyze_Aspect_Implicit_Dereference;
1647 -- Perform analysis of the Implicit_Dereference aspects
1649 procedure Make_Aitem_Pragma
1650 (Pragma_Argument_Associations : List_Id;
1651 Pragma_Name : Name_Id);
1652 -- This is a wrapper for Make_Pragma used for converting aspects
1653 -- to pragmas. It takes care of Sloc (set from Loc) and building
1654 -- the pragma identifier from the given name. In addition the
1655 -- flags Class_Present and Split_PPC are set from the aspect
1656 -- node, as well as Is_Ignored. This routine also sets the
1657 -- From_Aspect_Specification in the resulting pragma node to
1658 -- True, and sets Corresponding_Aspect to point to the aspect.
1659 -- The resulting pragma is assigned to Aitem.
1661 -------------------------------
1662 -- Analyze_Aspect_Convention --
1663 -------------------------------
1665 procedure Analyze_Aspect_Convention is
1674 -- Obtain all interfacing aspects that apply to the related
1677 Get_Interfacing_Aspects
1678 (Iface_Asp => Aspect,
1679 Conv_Asp => Dummy_1,
1686 -- The related entity is subject to aspect Export or Import.
1687 -- Do not process Convention now because it must be analysed
1688 -- as part of Export or Import.
1690 if Present (Expo) or else Present (Imp) then
1693 -- Otherwise Convention appears by itself
1696 -- The aspect specifies a particular convention
1698 if Present (Expr) then
1699 Conv := New_Copy_Tree (Expr);
1701 -- Otherwise assume convention Ada
1704 Conv := Make_Identifier (Loc, Name_Ada);
1708 -- pragma Convention (<Conv>, <E>);
1711 (Pragma_Name => Name_Convention,
1712 Pragma_Argument_Associations => New_List (
1713 Make_Pragma_Argument_Association (Loc,
1714 Expression => Conv),
1715 Make_Pragma_Argument_Association (Loc,
1716 Expression => New_Occurrence_Of (E, Loc))));
1718 Decorate (Aspect, Aitem);
1719 Insert_Pragma (Aitem);
1721 end Analyze_Aspect_Convention;
1723 ---------------------------------------
1724 -- Analyze_Aspect_Disable_Controlled --
1725 ---------------------------------------
1727 procedure Analyze_Aspect_Disable_Controlled is
1729 -- The aspect applies only to controlled records
1731 if not (Ekind (E) = E_Record_Type
1732 and then Is_Controlled_Active (E))
1735 ("aspect % requires controlled record type", Aspect);
1739 -- Preanalyze the expression (if any) when the aspect resides
1740 -- in a generic unit.
1742 if Inside_A_Generic then
1743 if Present (Expr) then
1744 Preanalyze_And_Resolve (Expr, Any_Boolean);
1747 -- Otherwise the aspect resides in a nongeneric context
1750 -- A controlled record type loses its controlled semantics
1751 -- when the expression statically evaluates to True.
1753 if Present (Expr) then
1754 Analyze_And_Resolve (Expr, Any_Boolean);
1756 if Is_OK_Static_Expression (Expr) then
1757 if Is_True (Static_Boolean (Expr)) then
1758 Set_Disable_Controlled (E);
1761 -- Otherwise the expression is not static
1765 ("expression of aspect % must be static", Aspect);
1768 -- Otherwise the aspect appears without an expression and
1769 -- defaults to True.
1772 Set_Disable_Controlled (E);
1775 end Analyze_Aspect_Disable_Controlled;
1777 ----------------------------------
1778 -- Analyze_Aspect_Export_Import --
1779 ----------------------------------
1781 procedure Analyze_Aspect_Export_Import is
1789 -- Obtain all interfacing aspects that apply to the related
1792 Get_Interfacing_Aspects
1793 (Iface_Asp => Aspect,
1794 Conv_Asp => Dummy_1,
1801 -- The related entity cannot be subject to both aspects Export
1804 if Present (Expo) and then Present (Imp) then
1806 ("incompatible interfacing aspects given for &", E);
1807 Error_Msg_Sloc := Sloc (Expo);
1808 Error_Msg_N ("\aspect `Export` #", E);
1809 Error_Msg_Sloc := Sloc (Imp);
1810 Error_Msg_N ("\aspect `Import` #", E);
1813 -- A variable is most likely modified from the outside. Take
1814 -- the optimistic approach to avoid spurious errors.
1816 if Ekind (E) = E_Variable then
1817 Set_Never_Set_In_Source (E, False);
1820 -- Resolve the expression of an Import or Export here, and
1821 -- require it to be of type Boolean and static. This is not
1822 -- quite right, because in general this should be delayed,
1823 -- but that seems tricky for these, because normally Boolean
1824 -- aspects are replaced with pragmas at the freeze point in
1825 -- Make_Pragma_From_Boolean_Aspect.
1827 if not Present (Expr)
1828 or else Is_True (Static_Boolean (Expr))
1830 if A_Id = Aspect_Import then
1831 Set_Has_Completion (E);
1832 Set_Is_Imported (E);
1834 -- An imported object cannot be explicitly initialized
1836 if Nkind (N) = N_Object_Declaration
1837 and then Present (Expression (N))
1840 ("imported entities cannot be initialized "
1841 & "(RM B.1(24))", Expression (N));
1845 pragma Assert (A_Id = Aspect_Export);
1846 Set_Is_Exported (E);
1849 -- Create the proper form of pragma Export or Import taking
1850 -- into account Conversion, External_Name, and Link_Name.
1852 Aitem := Build_Export_Import_Pragma (Aspect, E);
1854 -- Otherwise the expression is either False or erroneous. There
1855 -- is no corresponding pragma.
1860 end Analyze_Aspect_Export_Import;
1862 ---------------------------------------
1863 -- Analyze_Aspect_External_Link_Name --
1864 ---------------------------------------
1866 procedure Analyze_Aspect_External_Link_Name is
1874 -- Obtain all interfacing aspects that apply to the related
1877 Get_Interfacing_Aspects
1878 (Iface_Asp => Aspect,
1879 Conv_Asp => Dummy_1,
1886 -- Ensure that aspect External_Name applies to aspect Export or
1889 if A_Id = Aspect_External_Name then
1890 if No (Expo) and then No (Imp) then
1892 ("aspect `External_Name` requires aspect `Import` or "
1893 & "`Export`", Aspect);
1896 -- Otherwise ensure that aspect Link_Name applies to aspect
1897 -- Export or Import.
1900 pragma Assert (A_Id = Aspect_Link_Name);
1901 if No (Expo) and then No (Imp) then
1903 ("aspect `Link_Name` requires aspect `Import` or "
1904 & "`Export`", Aspect);
1907 end Analyze_Aspect_External_Link_Name;
1909 -----------------------------------------
1910 -- Analyze_Aspect_Implicit_Dereference --
1911 -----------------------------------------
1913 procedure Analyze_Aspect_Implicit_Dereference is
1915 if not Is_Type (E) or else not Has_Discriminants (E) then
1917 ("aspect must apply to a type with discriminants", Expr);
1919 elsif not Is_Entity_Name (Expr) then
1921 ("aspect must name a discriminant of current type", Expr);
1924 -- Discriminant type be an anonymous access type or an
1925 -- anonymous access to subprogram.
1927 -- Missing synchronized types???
1930 Disc : Entity_Id := First_Discriminant (E);
1932 while Present (Disc) loop
1933 if Chars (Expr) = Chars (Disc)
1936 E_Anonymous_Access_Subprogram_Type,
1937 E_Anonymous_Access_Type)
1939 Set_Has_Implicit_Dereference (E);
1940 Set_Has_Implicit_Dereference (Disc);
1944 Next_Discriminant (Disc);
1947 -- Error if no proper access discriminant
1949 if Present (Disc) then
1950 -- For a type extension, check whether parent has
1951 -- a reference discriminant, to verify that use is
1954 if Is_Derived_Type (E)
1955 and then Has_Discriminants (Etype (E))
1958 Parent_Disc : constant Entity_Id :=
1959 Get_Reference_Discriminant (Etype (E));
1961 if Present (Parent_Disc)
1962 and then Corresponding_Discriminant (Disc) /=
1966 ("reference discriminant does not match "
1967 & "discriminant of parent type", Expr);
1974 ("not an access discriminant of&", Expr, E);
1979 end Analyze_Aspect_Implicit_Dereference;
1981 -----------------------
1982 -- Make_Aitem_Pragma --
1983 -----------------------
1985 procedure Make_Aitem_Pragma
1986 (Pragma_Argument_Associations : List_Id;
1987 Pragma_Name : Name_Id)
1989 Args : List_Id := Pragma_Argument_Associations;
1992 -- We should never get here if aspect was disabled
1994 pragma Assert (not Is_Disabled (Aspect));
1996 -- Certain aspects allow for an optional name or expression. Do
1997 -- not generate a pragma with empty argument association list.
1999 if No (Args) or else No (Expression (First (Args))) then
2007 Pragma_Argument_Associations => Args,
2008 Pragma_Identifier =>
2009 Make_Identifier (Sloc (Id), Pragma_Name),
2010 Class_Present => Class_Present (Aspect),
2011 Split_PPC => Split_PPC (Aspect));
2013 -- Set additional semantic fields
2015 if Is_Ignored (Aspect) then
2016 Set_Is_Ignored (Aitem);
2017 elsif Is_Checked (Aspect) then
2018 Set_Is_Checked (Aitem);
2021 Set_Corresponding_Aspect (Aitem, Aspect);
2022 Set_From_Aspect_Specification (Aitem);
2023 end Make_Aitem_Pragma;
2025 -- Start of processing for Analyze_One_Aspect
2028 -- Skip aspect if already analyzed, to avoid looping in some cases
2030 if Analyzed (Aspect) then
2034 -- Skip looking at aspect if it is totally disabled. Just mark it
2035 -- as such for later reference in the tree. This also sets the
2036 -- Is_Ignored and Is_Checked flags appropriately.
2038 Check_Applicable_Policy (Aspect);
2040 if Is_Disabled (Aspect) then
2044 -- Set the source location of expression, used in the case of
2045 -- a failed precondition/postcondition or invariant. Note that
2046 -- the source location of the expression is not usually the best
2047 -- choice here. For example, it gets located on the last AND
2048 -- keyword in a chain of boolean expressiond AND'ed together.
2049 -- It is best to put the message on the first character of the
2050 -- assertion, which is the effect of the First_Node call here.
2052 if Present (Expr) then
2053 Eloc := Sloc (First_Node (Expr));
2056 -- Check restriction No_Implementation_Aspect_Specifications
2058 if Implementation_Defined_Aspect (A_Id) then
2060 (No_Implementation_Aspect_Specifications, Aspect);
2063 -- Check restriction No_Specification_Of_Aspect
2065 Check_Restriction_No_Specification_Of_Aspect (Aspect);
2067 -- Mark aspect analyzed (actual analysis is delayed till later)
2069 Set_Analyzed (Aspect);
2070 Set_Entity (Aspect, E);
2072 -- Build the reference to E that will be used in the built pragmas
2074 Ent := New_Occurrence_Of (E, Sloc (Id));
2076 if A_Id = Aspect_Attach_Handler
2077 or else A_Id = Aspect_Interrupt_Handler
2080 -- Treat the specification as a reference to the protected
2081 -- operation, which might otherwise appear unreferenced and
2082 -- generate spurious warnings.
2084 Generate_Reference (E, Id);
2087 -- Check for duplicate aspect. Note that the Comes_From_Source
2088 -- test allows duplicate Pre/Post's that we generate internally
2089 -- to escape being flagged here.
2091 if No_Duplicates_Allowed (A_Id) then
2093 while Anod /= Aspect loop
2094 if Comes_From_Source (Aspect)
2095 and then Same_Aspect (A_Id, Get_Aspect_Id (Anod))
2097 Error_Msg_Name_1 := Nam;
2098 Error_Msg_Sloc := Sloc (Anod);
2100 -- Case of same aspect specified twice
2102 if Class_Present (Anod) = Class_Present (Aspect) then
2103 if not Class_Present (Anod) then
2105 ("aspect% for & previously given#",
2109 ("aspect `%''Class` for & previously given#",
2119 -- Check some general restrictions on language defined aspects
2121 if not Implementation_Defined_Aspect (A_Id) then
2122 Error_Msg_Name_1 := Nam;
2124 -- Not allowed for renaming declarations. Examine the original
2125 -- node because a subprogram renaming may have been rewritten
2128 if Nkind (Original_Node (N)) in N_Renaming_Declaration then
2130 ("aspect % not allowed for renaming declaration",
2134 -- Not allowed for formal type declarations in previous
2135 -- versions of the language. Allowed for them only for
2136 -- shared variable control aspects.
2138 if Nkind (N) = N_Formal_Type_Declaration then
2139 if Ada_Version < Ada_2020 then
2141 ("aspect % not allowed for formal type declaration",
2144 elsif A_Id /= Aspect_Atomic
2145 and then A_Id /= Aspect_Volatile
2146 and then A_Id /= Aspect_Independent
2147 and then A_Id /= Aspect_Atomic_Components
2148 and then A_Id /= Aspect_Independent_Components
2149 and then A_Id /= Aspect_Volatile_Components
2152 ("aspect % not allowed for formal type declaration",
2158 -- Copy expression for later processing by the procedures
2159 -- Check_Aspect_At_[Freeze_Point | End_Of_Declarations]
2161 Set_Entity (Id, New_Copy_Tree (Expr));
2163 -- Set Delay_Required as appropriate to aspect
2165 case Aspect_Delay (A_Id) is
2166 when Always_Delay =>
2167 Delay_Required := True;
2170 Delay_Required := False;
2174 -- If expression has the form of an integer literal, then
2175 -- do not delay, since we know the value cannot change.
2176 -- This optimization catches most rep clause cases.
2178 -- For Boolean aspects, don't delay if no expression
2180 if A_Id in Boolean_Aspects and then No (Expr) then
2181 Delay_Required := False;
2183 -- For non-Boolean aspects, don't delay if integer literal,
2184 -- unless the aspect is Alignment, which affects the
2185 -- freezing of an initialized object.
2187 elsif A_Id not in Boolean_Aspects
2188 and then A_Id /= Aspect_Alignment
2189 and then Present (Expr)
2190 and then Nkind (Expr) = N_Integer_Literal
2192 Delay_Required := False;
2194 -- All other cases are delayed
2197 Delay_Required := True;
2198 Set_Has_Delayed_Rep_Aspects (E);
2202 -- Processing based on specific aspect
2205 when Aspect_Unimplemented =>
2206 null; -- ??? temp for now
2208 -- No_Aspect should be impossible
2211 raise Program_Error;
2213 -- Case 1: Aspects corresponding to attribute definition
2219 | Aspect_Component_Size
2220 | Aspect_Constant_Indexing
2221 | Aspect_Default_Iterator
2222 | Aspect_Dispatching_Domain
2223 | Aspect_External_Tag
2226 | Aspect_Iterator_Element
2227 | Aspect_Machine_Radix
2228 | Aspect_Object_Size
2231 | Aspect_Scalar_Storage_Order
2232 | Aspect_Simple_Storage_Pool
2235 | Aspect_Storage_Pool
2236 | Aspect_Stream_Size
2238 | Aspect_Variable_Indexing
2241 -- Indexing aspects apply only to tagged type
2243 if (A_Id = Aspect_Constant_Indexing
2245 A_Id = Aspect_Variable_Indexing)
2246 and then not (Is_Type (E)
2247 and then Is_Tagged_Type (E))
2250 ("indexing aspect can only apply to a tagged type",
2255 -- For the case of aspect Address, we don't consider that we
2256 -- know the entity is never set in the source, since it is
2257 -- is likely aliasing is occurring.
2259 -- Note: one might think that the analysis of the resulting
2260 -- attribute definition clause would take care of that, but
2261 -- that's not the case since it won't be from source.
2263 if A_Id = Aspect_Address then
2264 Set_Never_Set_In_Source (E, False);
2267 -- Correctness of the profile of a stream operation is
2268 -- verified at the freeze point, but we must detect the
2269 -- illegal specification of this aspect for a subtype now,
2270 -- to prevent malformed rep_item chains.
2272 if A_Id = Aspect_Input or else
2273 A_Id = Aspect_Output or else
2274 A_Id = Aspect_Read or else
2277 if not Is_First_Subtype (E) then
2279 ("local name must be a first subtype", Aspect);
2282 -- If stream aspect applies to the class-wide type,
2283 -- the generated attribute definition applies to the
2284 -- class-wide type as well.
2286 elsif Class_Present (Aspect) then
2288 Make_Attribute_Reference (Loc,
2290 Attribute_Name => Name_Class);
2294 -- Construct the attribute_definition_clause. The expression
2295 -- in the aspect specification is simply shared with the
2296 -- constructed attribute, because it will be fully analyzed
2297 -- when the attribute is processed. However, in ASIS mode
2298 -- the aspect expression itself is preanalyzed and resolved
2299 -- to catch visibility errors that are otherwise caught
2300 -- later, and we create a separate copy of the expression
2301 -- to prevent analysis of a malformed tree (e.g. a function
2302 -- call with parameter associations).
2306 Make_Attribute_Definition_Clause (Loc,
2308 Chars => Chars (Id),
2309 Expression => New_Copy_Tree (Expr));
2312 Make_Attribute_Definition_Clause (Loc,
2314 Chars => Chars (Id),
2315 Expression => Relocate_Node (Expr));
2318 -- If the address is specified, then we treat the entity as
2319 -- referenced, to avoid spurious warnings. This is analogous
2320 -- to what is done with an attribute definition clause, but
2321 -- here we don't want to generate a reference because this
2322 -- is the point of definition of the entity.
2324 if A_Id = Aspect_Address then
2328 -- Case 2: Aspects corresponding to pragmas
2330 -- Case 2a: Aspects corresponding to pragmas with two
2331 -- arguments, where the first argument is a local name
2332 -- referring to the entity, and the second argument is the
2333 -- aspect definition expression.
2335 -- Linker_Section/Suppress/Unsuppress
2337 when Aspect_Linker_Section
2342 (Pragma_Argument_Associations => New_List (
2343 Make_Pragma_Argument_Association (Loc,
2344 Expression => New_Occurrence_Of (E, Loc)),
2345 Make_Pragma_Argument_Association (Sloc (Expr),
2346 Expression => Relocate_Node (Expr))),
2347 Pragma_Name => Chars (Id));
2349 -- Linker_Section does not need delaying, as its argument
2350 -- must be a static string. Furthermore, if applied to
2351 -- an object with an explicit initialization, the object
2352 -- must be frozen in order to elaborate the initialization
2353 -- code. (This is already done for types with implicit
2354 -- initialization, such as protected types.)
2356 if A_Id = Aspect_Linker_Section
2357 and then Nkind (N) = N_Object_Declaration
2358 and then Has_Init_Expression (N)
2360 Delay_Required := False;
2365 -- Corresponds to pragma Implemented, construct the pragma
2367 when Aspect_Synchronization =>
2369 (Pragma_Argument_Associations => New_List (
2370 Make_Pragma_Argument_Association (Loc,
2371 Expression => New_Occurrence_Of (E, Loc)),
2372 Make_Pragma_Argument_Association (Sloc (Expr),
2373 Expression => Relocate_Node (Expr))),
2374 Pragma_Name => Name_Implemented);
2378 when Aspect_Attach_Handler =>
2380 (Pragma_Argument_Associations => New_List (
2381 Make_Pragma_Argument_Association (Sloc (Ent),
2383 Make_Pragma_Argument_Association (Sloc (Expr),
2384 Expression => Relocate_Node (Expr))),
2385 Pragma_Name => Name_Attach_Handler);
2387 -- We need to insert this pragma into the tree to get proper
2388 -- processing and to look valid from a placement viewpoint.
2390 Insert_Pragma (Aitem);
2393 -- Dynamic_Predicate, Predicate, Static_Predicate
2395 when Aspect_Dynamic_Predicate
2397 | Aspect_Static_Predicate
2399 -- These aspects apply only to subtypes
2401 if not Is_Type (E) then
2403 ("predicate can only be specified for a subtype",
2407 elsif Is_Incomplete_Type (E) then
2409 ("predicate cannot apply to incomplete view", Aspect);
2411 elsif Is_Generic_Type (E) then
2413 ("predicate cannot apply to formal type", Aspect);
2417 -- Construct the pragma (always a pragma Predicate, with
2418 -- flags recording whether it is static/dynamic). We also
2419 -- set flags recording this in the type itself.
2422 (Pragma_Argument_Associations => New_List (
2423 Make_Pragma_Argument_Association (Sloc (Ent),
2425 Make_Pragma_Argument_Association (Sloc (Expr),
2426 Expression => Relocate_Node (Expr))),
2427 Pragma_Name => Name_Predicate);
2429 -- Mark type has predicates, and remember what kind of
2430 -- aspect lead to this predicate (we need this to access
2431 -- the right set of check policies later on).
2433 Set_Has_Predicates (E);
2435 if A_Id = Aspect_Dynamic_Predicate then
2436 Set_Has_Dynamic_Predicate_Aspect (E);
2438 -- If the entity has a dynamic predicate, any inherited
2439 -- static predicate becomes dynamic as well, and the
2440 -- predicate function includes the conjunction of both.
2442 Set_Has_Static_Predicate_Aspect (E, False);
2444 elsif A_Id = Aspect_Static_Predicate then
2445 Set_Has_Static_Predicate_Aspect (E);
2448 -- If the type is private, indicate that its completion
2449 -- has a freeze node, because that is the one that will
2450 -- be visible at freeze time.
2452 if Is_Private_Type (E) and then Present (Full_View (E)) then
2453 Set_Has_Predicates (Full_View (E));
2455 if A_Id = Aspect_Dynamic_Predicate then
2456 Set_Has_Dynamic_Predicate_Aspect (Full_View (E));
2457 elsif A_Id = Aspect_Static_Predicate then
2458 Set_Has_Static_Predicate_Aspect (Full_View (E));
2461 Set_Has_Delayed_Aspects (Full_View (E));
2462 Ensure_Freeze_Node (Full_View (E));
2465 -- Predicate_Failure
2467 when Aspect_Predicate_Failure =>
2469 -- This aspect applies only to subtypes
2471 if not Is_Type (E) then
2473 ("predicate can only be specified for a subtype",
2477 elsif Is_Incomplete_Type (E) then
2479 ("predicate cannot apply to incomplete view", Aspect);
2483 -- Construct the pragma
2486 (Pragma_Argument_Associations => New_List (
2487 Make_Pragma_Argument_Association (Sloc (Ent),
2489 Make_Pragma_Argument_Association (Sloc (Expr),
2490 Expression => Relocate_Node (Expr))),
2491 Pragma_Name => Name_Predicate_Failure);
2493 Set_Has_Predicates (E);
2495 -- If the type is private, indicate that its completion
2496 -- has a freeze node, because that is the one that will
2497 -- be visible at freeze time.
2499 if Is_Private_Type (E) and then Present (Full_View (E)) then
2500 Set_Has_Predicates (Full_View (E));
2501 Set_Has_Delayed_Aspects (Full_View (E));
2502 Ensure_Freeze_Node (Full_View (E));
2505 -- Case 2b: Aspects corresponding to pragmas with two
2506 -- arguments, where the second argument is a local name
2507 -- referring to the entity, and the first argument is the
2508 -- aspect definition expression.
2512 when Aspect_Convention =>
2513 Analyze_Aspect_Convention;
2516 -- External_Name, Link_Name
2518 when Aspect_External_Name
2521 Analyze_Aspect_External_Link_Name;
2524 -- CPU, Interrupt_Priority, Priority
2526 -- These three aspects can be specified for a subprogram spec
2527 -- or body, in which case we analyze the expression and export
2528 -- the value of the aspect.
2530 -- Previously, we generated an equivalent pragma for bodies
2531 -- (note that the specs cannot contain these pragmas). The
2532 -- pragma was inserted ahead of local declarations, rather than
2533 -- after the body. This leads to a certain duplication between
2534 -- the processing performed for the aspect and the pragma, but
2535 -- given the straightforward handling required it is simpler
2536 -- to duplicate than to translate the aspect in the spec into
2537 -- a pragma in the declarative part of the body.
2540 | Aspect_Interrupt_Priority
2543 if Nkind_In (N, N_Subprogram_Body,
2544 N_Subprogram_Declaration)
2546 -- Analyze the aspect expression
2548 Analyze_And_Resolve (Expr, Standard_Integer);
2550 -- Interrupt_Priority aspect not allowed for main
2551 -- subprograms. RM D.1 does not forbid this explicitly,
2552 -- but RM J.15.11(6/3) does not permit pragma
2553 -- Interrupt_Priority for subprograms.
2555 if A_Id = Aspect_Interrupt_Priority then
2557 ("Interrupt_Priority aspect cannot apply to "
2558 & "subprogram", Expr);
2560 -- The expression must be static
2562 elsif not Is_OK_Static_Expression (Expr) then
2563 Flag_Non_Static_Expr
2564 ("aspect requires static expression!", Expr);
2566 -- Check whether this is the main subprogram. Issue a
2567 -- warning only if it is obviously not a main program
2568 -- (when it has parameters or when the subprogram is
2569 -- within a package).
2571 elsif Present (Parameter_Specifications
2572 (Specification (N)))
2573 or else not Is_Compilation_Unit (Defining_Entity (N))
2575 -- See RM D.1(14/3) and D.16(12/3)
2578 ("aspect applied to subprogram other than the "
2579 & "main subprogram has no effect??", Expr);
2581 -- Otherwise check in range and export the value
2583 -- For the CPU aspect
2585 elsif A_Id = Aspect_CPU then
2586 if Is_In_Range (Expr, RTE (RE_CPU_Range)) then
2588 -- Value is correct so we export the value to make
2589 -- it available at execution time.
2592 (Main_Unit, UI_To_Int (Expr_Value (Expr)));
2596 ("main subprogram CPU is out of range", Expr);
2599 -- For the Priority aspect
2601 elsif A_Id = Aspect_Priority then
2602 if Is_In_Range (Expr, RTE (RE_Priority)) then
2604 -- Value is correct so we export the value to make
2605 -- it available at execution time.
2608 (Main_Unit, UI_To_Int (Expr_Value (Expr)));
2610 -- Ignore pragma if Relaxed_RM_Semantics to support
2611 -- other targets/non GNAT compilers.
2613 elsif not Relaxed_RM_Semantics then
2615 ("main subprogram priority is out of range",
2620 -- Load an arbitrary entity from System.Tasking.Stages
2621 -- or System.Tasking.Restricted.Stages (depending on
2622 -- the supported profile) to make sure that one of these
2623 -- packages is implicitly with'ed, since we need to have
2624 -- the tasking run time active for the pragma Priority to
2625 -- have any effect. Previously we with'ed the package
2626 -- System.Tasking, but this package does not trigger the
2627 -- required initialization of the run-time library.
2630 Discard : Entity_Id;
2632 if Restricted_Profile then
2633 Discard := RTE (RE_Activate_Restricted_Tasks);
2635 Discard := RTE (RE_Activate_Tasks);
2639 -- Handling for these aspects in subprograms is complete
2643 -- For task and protected types pass the aspect as an
2648 Make_Attribute_Definition_Clause (Loc,
2650 Chars => Chars (Id),
2651 Expression => Relocate_Node (Expr));
2656 when Aspect_Warnings =>
2658 (Pragma_Argument_Associations => New_List (
2659 Make_Pragma_Argument_Association (Sloc (Expr),
2660 Expression => Relocate_Node (Expr)),
2661 Make_Pragma_Argument_Association (Loc,
2662 Expression => New_Occurrence_Of (E, Loc))),
2663 Pragma_Name => Chars (Id));
2665 Decorate (Aspect, Aitem);
2666 Insert_Pragma (Aitem);
2669 -- Case 2c: Aspects corresponding to pragmas with three
2672 -- Invariant aspects have a first argument that references the
2673 -- entity, a second argument that is the expression and a third
2674 -- argument that is an appropriate message.
2676 -- Invariant, Type_Invariant
2678 when Aspect_Invariant
2679 | Aspect_Type_Invariant
2681 -- Analysis of the pragma will verify placement legality:
2682 -- an invariant must apply to a private type, or appear in
2683 -- the private part of a spec and apply to a completion.
2686 (Pragma_Argument_Associations => New_List (
2687 Make_Pragma_Argument_Association (Sloc (Ent),
2689 Make_Pragma_Argument_Association (Sloc (Expr),
2690 Expression => Relocate_Node (Expr))),
2691 Pragma_Name => Name_Invariant);
2693 -- Add message unless exception messages are suppressed
2695 if not Opt.Exception_Locations_Suppressed then
2696 Append_To (Pragma_Argument_Associations (Aitem),
2697 Make_Pragma_Argument_Association (Eloc,
2698 Chars => Name_Message,
2700 Make_String_Literal (Eloc,
2701 Strval => "failed invariant from "
2702 & Build_Location_String (Eloc))));
2705 -- For Invariant case, insert immediately after the entity
2706 -- declaration. We do not have to worry about delay issues
2707 -- since the pragma processing takes care of this.
2709 Delay_Required := False;
2711 -- Case 2d : Aspects that correspond to a pragma with one
2716 -- Aspect Abstract_State introduces implicit declarations for
2717 -- all state abstraction entities it defines. To emulate this
2718 -- behavior, insert the pragma at the beginning of the visible
2719 -- declarations of the related package so that it is analyzed
2722 when Aspect_Abstract_State => Abstract_State : declare
2723 Context : Node_Id := N;
2726 -- When aspect Abstract_State appears on a generic package,
2727 -- it is propageted to the package instance. The context in
2728 -- this case is the instance spec.
2730 if Nkind (Context) = N_Package_Instantiation then
2731 Context := Instance_Spec (Context);
2734 if Nkind_In (Context, N_Generic_Package_Declaration,
2735 N_Package_Declaration)
2738 (Pragma_Argument_Associations => New_List (
2739 Make_Pragma_Argument_Association (Loc,
2740 Expression => Relocate_Node (Expr))),
2741 Pragma_Name => Name_Abstract_State);
2743 Decorate (Aspect, Aitem);
2747 Is_Generic_Instance (Defining_Entity (Context)));
2751 ("aspect & must apply to a package declaration",
2758 -- Aspect Async_Readers is never delayed because it is
2759 -- equivalent to a source pragma which appears after the
2760 -- related object declaration.
2762 when Aspect_Async_Readers =>
2764 (Pragma_Argument_Associations => New_List (
2765 Make_Pragma_Argument_Association (Loc,
2766 Expression => Relocate_Node (Expr))),
2767 Pragma_Name => Name_Async_Readers);
2769 Decorate (Aspect, Aitem);
2770 Insert_Pragma (Aitem);
2773 -- Aspect Async_Writers is never delayed because it is
2774 -- equivalent to a source pragma which appears after the
2775 -- related object declaration.
2777 when Aspect_Async_Writers =>
2779 (Pragma_Argument_Associations => New_List (
2780 Make_Pragma_Argument_Association (Loc,
2781 Expression => Relocate_Node (Expr))),
2782 Pragma_Name => Name_Async_Writers);
2784 Decorate (Aspect, Aitem);
2785 Insert_Pragma (Aitem);
2788 -- Aspect Constant_After_Elaboration is never delayed because
2789 -- it is equivalent to a source pragma which appears after the
2790 -- related object declaration.
2792 when Aspect_Constant_After_Elaboration =>
2794 (Pragma_Argument_Associations => New_List (
2795 Make_Pragma_Argument_Association (Loc,
2796 Expression => Relocate_Node (Expr))),
2798 Name_Constant_After_Elaboration);
2800 Decorate (Aspect, Aitem);
2801 Insert_Pragma (Aitem);
2804 -- Aspect Default_Internal_Condition is never delayed because
2805 -- it is equivalent to a source pragma which appears after the
2806 -- related private type. To deal with forward references, the
2807 -- generated pragma is stored in the rep chain of the related
2808 -- private type as types do not carry contracts. The pragma is
2809 -- wrapped inside of a procedure at the freeze point of the
2810 -- private type's full view.
2812 when Aspect_Default_Initial_Condition =>
2814 (Pragma_Argument_Associations => New_List (
2815 Make_Pragma_Argument_Association (Loc,
2816 Expression => Relocate_Node (Expr))),
2818 Name_Default_Initial_Condition);
2820 Decorate (Aspect, Aitem);
2821 Insert_Pragma (Aitem);
2824 -- Default_Storage_Pool
2826 when Aspect_Default_Storage_Pool =>
2828 (Pragma_Argument_Associations => New_List (
2829 Make_Pragma_Argument_Association (Loc,
2830 Expression => Relocate_Node (Expr))),
2832 Name_Default_Storage_Pool);
2834 Decorate (Aspect, Aitem);
2835 Insert_Pragma (Aitem);
2840 -- Aspect Depends is never delayed because it is equivalent to
2841 -- a source pragma which appears after the related subprogram.
2842 -- To deal with forward references, the generated pragma is
2843 -- stored in the contract of the related subprogram and later
2844 -- analyzed at the end of the declarative region. See routine
2845 -- Analyze_Depends_In_Decl_Part for details.
2847 when Aspect_Depends =>
2849 (Pragma_Argument_Associations => New_List (
2850 Make_Pragma_Argument_Association (Loc,
2851 Expression => Relocate_Node (Expr))),
2852 Pragma_Name => Name_Depends);
2854 Decorate (Aspect, Aitem);
2855 Insert_Pragma (Aitem);
2858 -- Aspect Effective_Reads is never delayed because it is
2859 -- equivalent to a source pragma which appears after the
2860 -- related object declaration.
2862 when Aspect_Effective_Reads =>
2864 (Pragma_Argument_Associations => New_List (
2865 Make_Pragma_Argument_Association (Loc,
2866 Expression => Relocate_Node (Expr))),
2867 Pragma_Name => Name_Effective_Reads);
2869 Decorate (Aspect, Aitem);
2870 Insert_Pragma (Aitem);
2873 -- Aspect Effective_Writes is never delayed because it is
2874 -- equivalent to a source pragma which appears after the
2875 -- related object declaration.
2877 when Aspect_Effective_Writes =>
2879 (Pragma_Argument_Associations => New_List (
2880 Make_Pragma_Argument_Association (Loc,
2881 Expression => Relocate_Node (Expr))),
2882 Pragma_Name => Name_Effective_Writes);
2884 Decorate (Aspect, Aitem);
2885 Insert_Pragma (Aitem);
2888 -- Aspect Extensions_Visible is never delayed because it is
2889 -- equivalent to a source pragma which appears after the
2890 -- related subprogram.
2892 when Aspect_Extensions_Visible =>
2894 (Pragma_Argument_Associations => New_List (
2895 Make_Pragma_Argument_Association (Loc,
2896 Expression => Relocate_Node (Expr))),
2897 Pragma_Name => Name_Extensions_Visible);
2899 Decorate (Aspect, Aitem);
2900 Insert_Pragma (Aitem);
2903 -- Aspect Ghost is never delayed because it is equivalent to a
2904 -- source pragma which appears at the top of [generic] package
2905 -- declarations or after an object, a [generic] subprogram, or
2906 -- a type declaration.
2908 when Aspect_Ghost =>
2910 (Pragma_Argument_Associations => New_List (
2911 Make_Pragma_Argument_Association (Loc,
2912 Expression => Relocate_Node (Expr))),
2913 Pragma_Name => Name_Ghost);
2915 Decorate (Aspect, Aitem);
2916 Insert_Pragma (Aitem);
2921 -- Aspect Global is never delayed because it is equivalent to
2922 -- a source pragma which appears after the related subprogram.
2923 -- To deal with forward references, the generated pragma is
2924 -- stored in the contract of the related subprogram and later
2925 -- analyzed at the end of the declarative region. See routine
2926 -- Analyze_Global_In_Decl_Part for details.
2928 when Aspect_Global =>
2930 (Pragma_Argument_Associations => New_List (
2931 Make_Pragma_Argument_Association (Loc,
2932 Expression => Relocate_Node (Expr))),
2933 Pragma_Name => Name_Global);
2935 Decorate (Aspect, Aitem);
2936 Insert_Pragma (Aitem);
2939 -- Initial_Condition
2941 -- Aspect Initial_Condition is never delayed because it is
2942 -- equivalent to a source pragma which appears after the
2943 -- related package. To deal with forward references, the
2944 -- generated pragma is stored in the contract of the related
2945 -- package and later analyzed at the end of the declarative
2946 -- region. See routine Analyze_Initial_Condition_In_Decl_Part
2949 when Aspect_Initial_Condition => Initial_Condition : declare
2950 Context : Node_Id := N;
2953 -- When aspect Initial_Condition appears on a generic
2954 -- package, it is propageted to the package instance. The
2955 -- context in this case is the instance spec.
2957 if Nkind (Context) = N_Package_Instantiation then
2958 Context := Instance_Spec (Context);
2961 if Nkind_In (Context, N_Generic_Package_Declaration,
2962 N_Package_Declaration)
2965 (Pragma_Argument_Associations => New_List (
2966 Make_Pragma_Argument_Association (Loc,
2967 Expression => Relocate_Node (Expr))),
2969 Name_Initial_Condition);
2971 Decorate (Aspect, Aitem);
2975 Is_Generic_Instance (Defining_Entity (Context)));
2977 -- Otherwise the context is illegal
2981 ("aspect & must apply to a package declaration",
2986 end Initial_Condition;
2990 -- Aspect Initializes is never delayed because it is equivalent
2991 -- to a source pragma appearing after the related package. To
2992 -- deal with forward references, the generated pragma is stored
2993 -- in the contract of the related package and later analyzed at
2994 -- the end of the declarative region. For details, see routine
2995 -- Analyze_Initializes_In_Decl_Part.
2997 when Aspect_Initializes => Initializes : declare
2998 Context : Node_Id := N;
3001 -- When aspect Initializes appears on a generic package,
3002 -- it is propageted to the package instance. The context
3003 -- in this case is the instance spec.
3005 if Nkind (Context) = N_Package_Instantiation then
3006 Context := Instance_Spec (Context);
3009 if Nkind_In (Context, N_Generic_Package_Declaration,
3010 N_Package_Declaration)
3013 (Pragma_Argument_Associations => New_List (
3014 Make_Pragma_Argument_Association (Loc,
3015 Expression => Relocate_Node (Expr))),
3016 Pragma_Name => Name_Initializes);
3018 Decorate (Aspect, Aitem);
3022 Is_Generic_Instance (Defining_Entity (Context)));
3024 -- Otherwise the context is illegal
3028 ("aspect & must apply to a package declaration",
3035 -- Max_Entry_Queue_Depth
3037 when Aspect_Max_Entry_Queue_Depth =>
3039 (Pragma_Argument_Associations => New_List (
3040 Make_Pragma_Argument_Association (Loc,
3041 Expression => Relocate_Node (Expr))),
3042 Pragma_Name => Name_Max_Entry_Queue_Depth);
3044 Decorate (Aspect, Aitem);
3045 Insert_Pragma (Aitem);
3048 -- Max_Entry_Queue_Length
3050 when Aspect_Max_Entry_Queue_Length =>
3052 (Pragma_Argument_Associations => New_List (
3053 Make_Pragma_Argument_Association (Loc,
3054 Expression => Relocate_Node (Expr))),
3055 Pragma_Name => Name_Max_Entry_Queue_Length);
3057 Decorate (Aspect, Aitem);
3058 Insert_Pragma (Aitem);
3063 when Aspect_Max_Queue_Length =>
3065 (Pragma_Argument_Associations => New_List (
3066 Make_Pragma_Argument_Association (Loc,
3067 Expression => Relocate_Node (Expr))),
3068 Pragma_Name => Name_Max_Queue_Length);
3070 Decorate (Aspect, Aitem);
3071 Insert_Pragma (Aitem);
3074 -- Aspect No_Caching is never delayed because it is equivalent
3075 -- to a source pragma which appears after the related object
3078 when Aspect_No_Caching =>
3080 (Pragma_Argument_Associations => New_List (
3081 Make_Pragma_Argument_Association (Loc,
3082 Expression => Relocate_Node (Expr))),
3083 Pragma_Name => Name_No_Caching);
3085 Decorate (Aspect, Aitem);
3086 Insert_Pragma (Aitem);
3091 when Aspect_Obsolescent => declare
3099 Make_Pragma_Argument_Association (Sloc (Expr),
3100 Expression => Relocate_Node (Expr)));
3104 (Pragma_Argument_Associations => Args,
3105 Pragma_Name => Chars (Id));
3110 when Aspect_Part_Of =>
3111 if Nkind_In (N, N_Object_Declaration,
3112 N_Package_Instantiation)
3113 or else Is_Single_Concurrent_Type_Declaration (N)
3116 (Pragma_Argument_Associations => New_List (
3117 Make_Pragma_Argument_Association (Loc,
3118 Expression => Relocate_Node (Expr))),
3119 Pragma_Name => Name_Part_Of);
3121 Decorate (Aspect, Aitem);
3122 Insert_Pragma (Aitem);
3126 ("aspect & must apply to package instantiation, "
3127 & "object, single protected type or single task type",
3135 when Aspect_SPARK_Mode =>
3137 (Pragma_Argument_Associations => New_List (
3138 Make_Pragma_Argument_Association (Loc,
3139 Expression => Relocate_Node (Expr))),
3140 Pragma_Name => Name_SPARK_Mode);
3142 Decorate (Aspect, Aitem);
3143 Insert_Pragma (Aitem);
3148 -- Aspect Refined_Depends is never delayed because it is
3149 -- equivalent to a source pragma which appears in the
3150 -- declarations of the related subprogram body. To deal with
3151 -- forward references, the generated pragma is stored in the
3152 -- contract of the related subprogram body and later analyzed
3153 -- at the end of the declarative region. For details, see
3154 -- routine Analyze_Refined_Depends_In_Decl_Part.
3156 when Aspect_Refined_Depends =>
3158 (Pragma_Argument_Associations => New_List (
3159 Make_Pragma_Argument_Association (Loc,
3160 Expression => Relocate_Node (Expr))),
3161 Pragma_Name => Name_Refined_Depends);
3163 Decorate (Aspect, Aitem);
3164 Insert_Pragma (Aitem);
3169 -- Aspect Refined_Global is never delayed because it is
3170 -- equivalent to a source pragma which appears in the
3171 -- declarations of the related subprogram body. To deal with
3172 -- forward references, the generated pragma is stored in the
3173 -- contract of the related subprogram body and later analyzed
3174 -- at the end of the declarative region. For details, see
3175 -- routine Analyze_Refined_Global_In_Decl_Part.
3177 when Aspect_Refined_Global =>
3179 (Pragma_Argument_Associations => New_List (
3180 Make_Pragma_Argument_Association (Loc,
3181 Expression => Relocate_Node (Expr))),
3182 Pragma_Name => Name_Refined_Global);
3184 Decorate (Aspect, Aitem);
3185 Insert_Pragma (Aitem);
3190 when Aspect_Refined_Post =>
3192 (Pragma_Argument_Associations => New_List (
3193 Make_Pragma_Argument_Association (Loc,
3194 Expression => Relocate_Node (Expr))),
3195 Pragma_Name => Name_Refined_Post);
3197 Decorate (Aspect, Aitem);
3198 Insert_Pragma (Aitem);
3203 when Aspect_Refined_State =>
3205 -- The corresponding pragma for Refined_State is inserted in
3206 -- the declarations of the related package body. This action
3207 -- synchronizes both the source and from-aspect versions of
3210 if Nkind (N) = N_Package_Body then
3212 (Pragma_Argument_Associations => New_List (
3213 Make_Pragma_Argument_Association (Loc,
3214 Expression => Relocate_Node (Expr))),
3215 Pragma_Name => Name_Refined_State);
3217 Decorate (Aspect, Aitem);
3218 Insert_Pragma (Aitem);
3220 -- Otherwise the context is illegal
3224 ("aspect & must apply to a package body", Aspect, Id);
3229 -- Relative_Deadline
3231 when Aspect_Relative_Deadline =>
3233 (Pragma_Argument_Associations => New_List (
3234 Make_Pragma_Argument_Association (Loc,
3235 Expression => Relocate_Node (Expr))),
3236 Pragma_Name => Name_Relative_Deadline);
3238 -- If the aspect applies to a task, the corresponding pragma
3239 -- must appear within its declarations, not after.
3241 if Nkind (N) = N_Task_Type_Declaration then
3247 if No (Task_Definition (N)) then
3248 Set_Task_Definition (N,
3249 Make_Task_Definition (Loc,
3250 Visible_Declarations => New_List,
3251 End_Label => Empty));
3254 Def := Task_Definition (N);
3255 V := Visible_Declarations (Def);
3256 if not Is_Empty_List (V) then
3257 Insert_Before (First (V), Aitem);
3260 Set_Visible_Declarations (Def, New_List (Aitem));
3267 -- Secondary_Stack_Size
3269 -- Aspect Secondary_Stack_Size needs to be converted into a
3270 -- pragma for two reasons: the attribute is not analyzed until
3271 -- after the expansion of the task type declaration and the
3272 -- attribute does not have visibility on the discriminant.
3274 when Aspect_Secondary_Stack_Size =>
3276 (Pragma_Argument_Associations => New_List (
3277 Make_Pragma_Argument_Association (Loc,
3278 Expression => Relocate_Node (Expr))),
3280 Name_Secondary_Stack_Size);
3282 Decorate (Aspect, Aitem);
3283 Insert_Pragma (Aitem);
3286 -- Volatile_Function
3288 -- Aspect Volatile_Function is never delayed because it is
3289 -- equivalent to a source pragma which appears after the
3290 -- related subprogram.
3292 when Aspect_Volatile_Function =>
3294 (Pragma_Argument_Associations => New_List (
3295 Make_Pragma_Argument_Association (Loc,
3296 Expression => Relocate_Node (Expr))),
3297 Pragma_Name => Name_Volatile_Function);
3299 Decorate (Aspect, Aitem);
3300 Insert_Pragma (Aitem);
3303 -- Case 2e: Annotate aspect
3305 when Aspect_Annotate =>
3312 -- The argument can be a single identifier
3314 if Nkind (Expr) = N_Identifier then
3316 -- One level of parens is allowed
3318 if Paren_Count (Expr) > 1 then
3319 Error_Msg_F ("extra parentheses ignored", Expr);
3322 Set_Paren_Count (Expr, 0);
3324 -- Add the single item to the list
3326 Args := New_List (Expr);
3328 -- Otherwise we must have an aggregate
3330 elsif Nkind (Expr) = N_Aggregate then
3332 -- Must be positional
3334 if Present (Component_Associations (Expr)) then
3336 ("purely positional aggregate required", Expr);
3340 -- Must not be parenthesized
3342 if Paren_Count (Expr) /= 0 then
3343 Error_Msg_F ("extra parentheses ignored", Expr);
3346 -- List of arguments is list of aggregate expressions
3348 Args := Expressions (Expr);
3350 -- Anything else is illegal
3353 Error_Msg_F ("wrong form for Annotate aspect", Expr);
3357 -- Prepare pragma arguments
3360 Arg := First (Args);
3361 while Present (Arg) loop
3363 Make_Pragma_Argument_Association (Sloc (Arg),
3364 Expression => Relocate_Node (Arg)));
3369 Make_Pragma_Argument_Association (Sloc (Ent),
3370 Chars => Name_Entity,
3371 Expression => Ent));
3374 (Pragma_Argument_Associations => Pargs,
3375 Pragma_Name => Name_Annotate);
3378 -- Case 3 : Aspects that don't correspond to pragma/attribute
3379 -- definition clause.
3381 -- Case 3a: The aspects listed below don't correspond to
3382 -- pragmas/attributes but do require delayed analysis.
3384 -- Default_Value can only apply to a scalar type
3386 when Aspect_Default_Value =>
3387 if not Is_Scalar_Type (E) then
3389 ("aspect Default_Value must apply to a scalar type", N);
3394 -- Default_Component_Value can only apply to an array type
3395 -- with scalar components.
3397 when Aspect_Default_Component_Value =>
3398 if not (Is_Array_Type (E)
3399 and then Is_Scalar_Type (Component_Type (E)))
3402 ("aspect Default_Component_Value can only apply to an "
3403 & "array of scalar components", N);
3408 -- Case 3b: The aspects listed below don't correspond to
3409 -- pragmas/attributes and don't need delayed analysis.
3411 -- Implicit_Dereference
3413 -- For Implicit_Dereference, External_Name and Link_Name, only
3414 -- the legality checks are done during the analysis, thus no
3415 -- delay is required.
3417 when Aspect_Implicit_Dereference =>
3418 Analyze_Aspect_Implicit_Dereference;
3423 when Aspect_Dimension =>
3424 Analyze_Aspect_Dimension (N, Id, Expr);
3429 when Aspect_Dimension_System =>
3430 Analyze_Aspect_Dimension_System (N, Id, Expr);
3433 -- Case 4: Aspects requiring special handling
3435 -- Pre/Post/Test_Case/Contract_Cases whose corresponding
3436 -- pragmas take care of the delay.
3440 -- Aspects Pre/Post generate Precondition/Postcondition pragmas
3441 -- with a first argument that is the expression, and a second
3442 -- argument that is an informative message if the test fails.
3443 -- This is inserted right after the declaration, to get the
3444 -- required pragma placement. The processing for the pragmas
3445 -- takes care of the required delay.
3447 when Pre_Post_Aspects => Pre_Post : declare
3451 if A_Id = Aspect_Pre or else A_Id = Aspect_Precondition then
3452 Pname := Name_Precondition;
3454 Pname := Name_Postcondition;
3457 -- Check that the class-wide predicate cannot be applied to
3458 -- an operation of a synchronized type. AI12-0182 forbids
3459 -- these altogether, while earlier language semantics made
3460 -- them legal on tagged synchronized types.
3462 -- Other legality checks are performed when analyzing the
3463 -- contract of the operation.
3465 if Class_Present (Aspect)
3466 and then Is_Concurrent_Type (Current_Scope)
3467 and then Ekind_In (E, E_Entry, E_Function, E_Procedure)
3469 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (Aspect);
3471 ("aspect % can only be specified for a primitive "
3472 & "operation of a tagged type", Aspect);
3477 -- If the expressions is of the form A and then B, then
3478 -- we generate separate Pre/Post aspects for the separate
3479 -- clauses. Since we allow multiple pragmas, there is no
3480 -- problem in allowing multiple Pre/Post aspects internally.
3481 -- These should be treated in reverse order (B first and
3482 -- A second) since they are later inserted just after N in
3483 -- the order they are treated. This way, the pragma for A
3484 -- ends up preceding the pragma for B, which may have an
3485 -- importance for the error raised (either constraint error
3486 -- or precondition error).
3488 -- We do not do this for Pre'Class, since we have to put
3489 -- these conditions together in a complex OR expression.
3491 -- We do not do this in ASIS mode, as ASIS relies on the
3492 -- original node representing the complete expression, when
3493 -- retrieving it through the source aspect table. Also, we
3494 -- don't do this in GNATprove mode, because it brings no
3495 -- benefit for proof and causes annoynace for flow analysis,
3496 -- which prefers to be as close to the original source code
3497 -- as possible. Also we don't do this when analyzing generic
3498 -- units since it causes spurious visibility errors in the
3499 -- preanalysis of instantiations.
3501 if not (ASIS_Mode or GNATprove_Mode)
3502 and then (Pname = Name_Postcondition
3503 or else not Class_Present (Aspect))
3504 and then not Inside_A_Generic
3506 while Nkind (Expr) = N_And_Then loop
3507 Insert_After (Aspect,
3508 Make_Aspect_Specification (Sloc (Left_Opnd (Expr)),
3509 Identifier => Identifier (Aspect),
3510 Expression => Relocate_Node (Left_Opnd (Expr)),
3511 Class_Present => Class_Present (Aspect),
3512 Split_PPC => True));
3513 Rewrite (Expr, Relocate_Node (Right_Opnd (Expr)));
3514 Eloc := Sloc (Expr);
3518 -- Build the precondition/postcondition pragma
3520 -- We use Relocate_Node here rather than New_Copy_Tree
3521 -- because subsequent visibility analysis of the aspect
3522 -- depends on this sharing. This should be cleaned up???
3524 -- If the context is generic or involves ASIS, we want
3525 -- to preserve the original tree, and simply share it
3526 -- between aspect and generated attribute. This parallels
3527 -- what is done in sem_prag.adb (see Get_Argument).
3533 if ASIS_Mode or else Inside_A_Generic then
3536 New_Expr := Relocate_Node (Expr);
3540 (Pragma_Argument_Associations => New_List (
3541 Make_Pragma_Argument_Association (Eloc,
3542 Chars => Name_Check,
3543 Expression => New_Expr)),
3544 Pragma_Name => Pname);
3547 -- Add message unless exception messages are suppressed
3549 if not Opt.Exception_Locations_Suppressed then
3550 Append_To (Pragma_Argument_Associations (Aitem),
3551 Make_Pragma_Argument_Association (Eloc,
3552 Chars => Name_Message,
3554 Make_String_Literal (Eloc,
3556 & Get_Name_String (Pname)
3558 & Build_Location_String (Eloc))));
3561 Set_Is_Delayed_Aspect (Aspect);
3563 -- For Pre/Post cases, insert immediately after the entity
3564 -- declaration, since that is the required pragma placement.
3565 -- Note that for these aspects, we do not have to worry
3566 -- about delay issues, since the pragmas themselves deal
3567 -- with delay of visibility for the expression analysis.
3569 Insert_Pragma (Aitem);
3576 when Aspect_Test_Case => Test_Case : declare
3578 Comp_Expr : Node_Id;
3579 Comp_Assn : Node_Id;
3585 if Nkind (Parent (N)) = N_Compilation_Unit then
3586 Error_Msg_Name_1 := Nam;
3587 Error_Msg_N ("incorrect placement of aspect `%`", E);
3591 if Nkind (Expr) /= N_Aggregate then
3592 Error_Msg_Name_1 := Nam;
3594 ("wrong syntax for aspect `%` for &", Id, E);
3598 -- Make pragma expressions refer to the original aspect
3599 -- expressions through the Original_Node link. This is used
3600 -- in semantic analysis for ASIS mode, so that the original
3601 -- expression also gets analyzed.
3603 Comp_Expr := First (Expressions (Expr));
3604 while Present (Comp_Expr) loop
3605 New_Expr := Relocate_Node (Comp_Expr);
3607 Make_Pragma_Argument_Association (Sloc (Comp_Expr),
3608 Expression => New_Expr));
3612 Comp_Assn := First (Component_Associations (Expr));
3613 while Present (Comp_Assn) loop
3614 if List_Length (Choices (Comp_Assn)) /= 1
3616 Nkind (First (Choices (Comp_Assn))) /= N_Identifier
3618 Error_Msg_Name_1 := Nam;
3620 ("wrong syntax for aspect `%` for &", Id, E);
3625 Make_Pragma_Argument_Association (Sloc (Comp_Assn),
3626 Chars => Chars (First (Choices (Comp_Assn))),
3628 Relocate_Node (Expression (Comp_Assn))));
3632 -- Build the test-case pragma
3635 (Pragma_Argument_Associations => Args,
3636 Pragma_Name => Nam);
3641 when Aspect_Contract_Cases =>
3643 (Pragma_Argument_Associations => New_List (
3644 Make_Pragma_Argument_Association (Loc,
3645 Expression => Relocate_Node (Expr))),
3646 Pragma_Name => Nam);
3648 Decorate (Aspect, Aitem);
3649 Insert_Pragma (Aitem);
3652 -- Case 5: Special handling for aspects with an optional
3653 -- boolean argument.
3655 -- In the delayed case, the corresponding pragma cannot be
3656 -- generated yet because the evaluation of the boolean needs
3657 -- to be delayed till the freeze point.
3659 when Boolean_Aspects
3660 | Library_Unit_Aspects
3662 Set_Is_Boolean_Aspect (Aspect);
3664 -- Lock_Free aspect only apply to protected objects
3666 if A_Id = Aspect_Lock_Free then
3667 if Ekind (E) /= E_Protected_Type then
3668 Error_Msg_Name_1 := Nam;
3670 ("aspect % only applies to a protected object",
3674 -- Set the Uses_Lock_Free flag to True if there is no
3675 -- expression or if the expression is True. The
3676 -- evaluation of this aspect should be delayed to the
3677 -- freeze point (why???)
3680 or else Is_True (Static_Boolean (Expr))
3682 Set_Uses_Lock_Free (E);
3685 Record_Rep_Item (E, Aspect);
3690 elsif A_Id = Aspect_Export or else A_Id = Aspect_Import then
3691 Analyze_Aspect_Export_Import;
3693 -- Disable_Controlled
3695 elsif A_Id = Aspect_Disable_Controlled then
3696 Analyze_Aspect_Disable_Controlled;
3700 -- Library unit aspects require special handling in the case
3701 -- of a package declaration, the pragma needs to be inserted
3702 -- in the list of declarations for the associated package.
3703 -- There is no issue of visibility delay for these aspects.
3705 if A_Id in Library_Unit_Aspects
3707 Nkind_In (N, N_Package_Declaration,
3708 N_Generic_Package_Declaration)
3709 and then Nkind (Parent (N)) /= N_Compilation_Unit
3711 -- Aspect is legal on a local instantiation of a library-
3712 -- level generic unit.
3714 and then not Is_Generic_Instance (Defining_Entity (N))
3717 ("incorrect context for library unit aspect&", Id);
3721 -- Cases where we do not delay, includes all cases where the
3722 -- expression is missing other than the above cases.
3724 if not Delay_Required or else No (Expr) then
3726 -- Exclude aspects Export and Import because their pragma
3727 -- syntax does not map directly to a Boolean aspect.
3729 if A_Id /= Aspect_Export
3730 and then A_Id /= Aspect_Import
3733 (Pragma_Argument_Associations => New_List (
3734 Make_Pragma_Argument_Association (Sloc (Ent),
3735 Expression => Ent)),
3736 Pragma_Name => Chars (Id));
3739 Delay_Required := False;
3741 -- In general cases, the corresponding pragma/attribute
3742 -- definition clause will be inserted later at the freezing
3743 -- point, and we do not need to build it now.
3751 -- This is special because for access types we need to generate
3752 -- an attribute definition clause. This also works for single
3753 -- task declarations, but it does not work for task type
3754 -- declarations, because we have the case where the expression
3755 -- references a discriminant of the task type. That can't use
3756 -- an attribute definition clause because we would not have
3757 -- visibility on the discriminant. For that case we must
3758 -- generate a pragma in the task definition.
3760 when Aspect_Storage_Size =>
3764 if Ekind (E) = E_Task_Type then
3766 Decl : constant Node_Id := Declaration_Node (E);
3769 pragma Assert (Nkind (Decl) = N_Task_Type_Declaration);
3771 -- If no task definition, create one
3773 if No (Task_Definition (Decl)) then
3774 Set_Task_Definition (Decl,
3775 Make_Task_Definition (Loc,
3776 Visible_Declarations => Empty_List,
3777 End_Label => Empty));
3780 -- Create a pragma and put it at the start of the task
3781 -- definition for the task type declaration.
3784 (Pragma_Argument_Associations => New_List (
3785 Make_Pragma_Argument_Association (Loc,
3786 Expression => Relocate_Node (Expr))),
3787 Pragma_Name => Name_Storage_Size);
3791 Visible_Declarations (Task_Definition (Decl)));
3795 -- All other cases, generate attribute definition
3799 Make_Attribute_Definition_Clause (Loc,
3801 Chars => Chars (Id),
3802 Expression => Relocate_Node (Expr));
3806 -- Attach the corresponding pragma/attribute definition clause to
3807 -- the aspect specification node.
3809 if Present (Aitem) then
3810 Set_From_Aspect_Specification (Aitem);
3813 -- For an aspect that applies to a type, indicate whether it
3814 -- appears on a partial view of the type.
3817 and then Is_Private_Type (E)
3819 Set_Aspect_On_Partial_View (Aspect);
3822 -- In the context of a compilation unit, we directly put the
3823 -- pragma in the Pragmas_After list of the N_Compilation_Unit_Aux
3824 -- node (no delay is required here) except for aspects on a
3825 -- subprogram body (see below) and a generic package, for which we
3826 -- need to introduce the pragma before building the generic copy
3827 -- (see sem_ch12), and for package instantiations, where the
3828 -- library unit pragmas are better handled early.
3830 if Nkind (Parent (N)) = N_Compilation_Unit
3831 and then (Present (Aitem) or else Is_Boolean_Aspect (Aspect))
3834 Aux : constant Node_Id := Aux_Decls_Node (Parent (N));
3837 pragma Assert (Nkind (Aux) = N_Compilation_Unit_Aux);
3839 -- For a Boolean aspect, create the corresponding pragma if
3840 -- no expression or if the value is True.
3842 if Is_Boolean_Aspect (Aspect) and then No (Aitem) then
3843 if Is_True (Static_Boolean (Expr)) then
3845 (Pragma_Argument_Associations => New_List (
3846 Make_Pragma_Argument_Association (Sloc (Ent),
3847 Expression => Ent)),
3848 Pragma_Name => Chars (Id));
3850 Set_From_Aspect_Specification (Aitem, True);
3851 Set_Corresponding_Aspect (Aitem, Aspect);
3858 -- If the aspect is on a subprogram body (relevant aspect
3859 -- is Inline), add the pragma in front of the declarations.
3861 if Nkind (N) = N_Subprogram_Body then
3862 if No (Declarations (N)) then
3863 Set_Declarations (N, New_List);
3866 Prepend (Aitem, Declarations (N));
3868 elsif Nkind (N) = N_Generic_Package_Declaration then
3869 if No (Visible_Declarations (Specification (N))) then
3870 Set_Visible_Declarations (Specification (N), New_List);
3874 Visible_Declarations (Specification (N)));
3876 elsif Nkind (N) = N_Package_Instantiation then
3878 Spec : constant Node_Id :=
3879 Specification (Instance_Spec (N));
3881 if No (Visible_Declarations (Spec)) then
3882 Set_Visible_Declarations (Spec, New_List);
3885 Prepend (Aitem, Visible_Declarations (Spec));
3889 if No (Pragmas_After (Aux)) then
3890 Set_Pragmas_After (Aux, New_List);
3893 Append (Aitem, Pragmas_After (Aux));
3900 -- The evaluation of the aspect is delayed to the freezing point.
3901 -- The pragma or attribute clause if there is one is then attached
3902 -- to the aspect specification which is put in the rep item list.
3904 if Delay_Required then
3905 if Present (Aitem) then
3906 Set_Is_Delayed_Aspect (Aitem);
3907 Set_Aspect_Rep_Item (Aspect, Aitem);
3908 Set_Parent (Aitem, Aspect);
3911 Set_Is_Delayed_Aspect (Aspect);
3913 -- In the case of Default_Value, link the aspect to base type
3914 -- as well, even though it appears on a first subtype. This is
3915 -- mandated by the semantics of the aspect. Do not establish
3916 -- the link when processing the base type itself as this leads
3917 -- to a rep item circularity. Verify that we are dealing with
3918 -- a scalar type to prevent cascaded errors.
3920 if A_Id = Aspect_Default_Value
3921 and then Is_Scalar_Type (E)
3922 and then Base_Type (E) /= E
3924 Set_Has_Delayed_Aspects (Base_Type (E));
3925 Record_Rep_Item (Base_Type (E), Aspect);
3928 Set_Has_Delayed_Aspects (E);
3929 Record_Rep_Item (E, Aspect);
3931 -- When delay is not required and the context is a package or a
3932 -- subprogram body, insert the pragma in the body declarations.
3934 elsif Nkind_In (N, N_Package_Body, N_Subprogram_Body) then
3935 if No (Declarations (N)) then
3936 Set_Declarations (N, New_List);
3939 -- The pragma is added before source declarations
3941 Prepend_To (Declarations (N), Aitem);
3943 -- When delay is not required and the context is not a compilation
3944 -- unit, we simply insert the pragma/attribute definition clause
3947 elsif Present (Aitem) then
3948 Insert_After (Ins_Node, Aitem);
3951 end Analyze_One_Aspect;
3955 end loop Aspect_Loop;
3957 if Has_Delayed_Aspects (E) then
3958 Ensure_Freeze_Node (E);
3960 end Analyze_Aspect_Specifications;
3962 ------------------------------------------------
3963 -- Analyze_Aspects_On_Subprogram_Body_Or_Stub --
3964 ------------------------------------------------
3966 procedure Analyze_Aspects_On_Subprogram_Body_Or_Stub (N : Node_Id) is
3967 Body_Id : constant Entity_Id := Defining_Entity (N);
3969 procedure Diagnose_Misplaced_Aspects (Spec_Id : Entity_Id);
3970 -- Body [stub] N has aspects, but they are not properly placed. Emit an
3971 -- error message depending on the aspects involved. Spec_Id denotes the
3972 -- entity of the corresponding spec.
3974 --------------------------------
3975 -- Diagnose_Misplaced_Aspects --
3976 --------------------------------
3978 procedure Diagnose_Misplaced_Aspects (Spec_Id : Entity_Id) is
3979 procedure Misplaced_Aspect_Error
3982 -- Emit an error message concerning misplaced aspect Asp. Ref_Nam is
3983 -- the name of the refined version of the aspect.
3985 ----------------------------
3986 -- Misplaced_Aspect_Error --
3987 ----------------------------
3989 procedure Misplaced_Aspect_Error
3993 Asp_Nam : constant Name_Id := Chars (Identifier (Asp));
3994 Asp_Id : constant Aspect_Id := Get_Aspect_Id (Asp_Nam);
3997 -- The corresponding spec already contains the aspect in question
3998 -- and the one appearing on the body must be the refined form:
4000 -- procedure P with Global ...;
4001 -- procedure P with Global ... is ... end P;
4005 if Has_Aspect (Spec_Id, Asp_Id) then
4006 Error_Msg_Name_1 := Asp_Nam;
4008 -- Subunits cannot carry aspects that apply to a subprogram
4011 if Nkind (Parent (N)) = N_Subunit then
4012 Error_Msg_N ("aspect % cannot apply to a subunit", Asp);
4014 -- Otherwise suggest the refined form
4017 Error_Msg_Name_2 := Ref_Nam;
4018 Error_Msg_N ("aspect % should be %", Asp);
4021 -- Otherwise the aspect must appear on the spec, not on the body
4024 -- procedure P with Global ... is ... end P;
4028 ("aspect specification must appear on initial declaration",
4031 end Misplaced_Aspect_Error;
4038 -- Start of processing for Diagnose_Misplaced_Aspects
4041 -- Iterate over the aspect specifications and emit specific errors
4042 -- where applicable.
4044 Asp := First (Aspect_Specifications (N));
4045 while Present (Asp) loop
4046 Asp_Nam := Chars (Identifier (Asp));
4048 -- Do not emit errors on aspects that can appear on a subprogram
4049 -- body. This scenario occurs when the aspect specification list
4050 -- contains both misplaced and properly placed aspects.
4052 if Aspect_On_Body_Or_Stub_OK (Get_Aspect_Id (Asp_Nam)) then
4055 -- Special diagnostics for SPARK aspects
4057 elsif Asp_Nam = Name_Depends then
4058 Misplaced_Aspect_Error (Asp, Name_Refined_Depends);
4060 elsif Asp_Nam = Name_Global then
4061 Misplaced_Aspect_Error (Asp, Name_Refined_Global);
4063 elsif Asp_Nam = Name_Post then
4064 Misplaced_Aspect_Error (Asp, Name_Refined_Post);
4066 -- Otherwise a language-defined aspect is misplaced
4070 ("aspect specification must appear on initial declaration",
4076 end Diagnose_Misplaced_Aspects;
4080 Spec_Id : constant Entity_Id := Unique_Defining_Entity (N);
4082 -- Start of processing for Analyze_Aspects_On_Subprogram_Body_Or_Stub
4085 -- Language-defined aspects cannot be associated with a subprogram body
4086 -- [stub] if the subprogram has a spec. Certain implementation defined
4087 -- aspects are allowed to break this rule (for all applicable cases, see
4088 -- table Aspects.Aspect_On_Body_Or_Stub_OK).
4090 if Spec_Id /= Body_Id and then not Aspects_On_Body_Or_Stub_OK (N) then
4091 Diagnose_Misplaced_Aspects (Spec_Id);
4093 Analyze_Aspect_Specifications (N, Body_Id);
4095 end Analyze_Aspects_On_Subprogram_Body_Or_Stub;
4097 -----------------------
4098 -- Analyze_At_Clause --
4099 -----------------------
4101 -- An at clause is replaced by the corresponding Address attribute
4102 -- definition clause that is the preferred approach in Ada 95.
4104 procedure Analyze_At_Clause (N : Node_Id) is
4105 CS : constant Boolean := Comes_From_Source (N);
4108 -- This is an obsolescent feature
4110 Check_Restriction (No_Obsolescent_Features, N);
4112 if Warn_On_Obsolescent_Feature then
4114 ("?j?at clause is an obsolescent feature (RM J.7(2))", N);
4116 ("\?j?use address attribute definition clause instead", N);
4119 -- Rewrite as address clause
4122 Make_Attribute_Definition_Clause (Sloc (N),
4123 Name => Identifier (N),
4124 Chars => Name_Address,
4125 Expression => Expression (N)));
4127 -- We preserve Comes_From_Source, since logically the clause still comes
4128 -- from the source program even though it is changed in form.
4130 Set_Comes_From_Source (N, CS);
4132 -- Analyze rewritten clause
4134 Analyze_Attribute_Definition_Clause (N);
4135 end Analyze_At_Clause;
4137 -----------------------------------------
4138 -- Analyze_Attribute_Definition_Clause --
4139 -----------------------------------------
4141 procedure Analyze_Attribute_Definition_Clause (N : Node_Id) is
4142 Loc : constant Source_Ptr := Sloc (N);
4143 Nam : constant Node_Id := Name (N);
4144 Attr : constant Name_Id := Chars (N);
4145 Expr : constant Node_Id := Expression (N);
4146 Id : constant Attribute_Id := Get_Attribute_Id (Attr);
4149 -- The entity of Nam after it is analyzed. In the case of an incomplete
4150 -- type, this is the underlying type.
4153 -- The underlying entity to which the attribute applies. Generally this
4154 -- is the Underlying_Type of Ent, except in the case where the clause
4155 -- applies to the full view of an incomplete or private type, in which
4156 -- case U_Ent is just a copy of Ent.
4158 FOnly : Boolean := False;
4159 -- Reset to True for subtype specific attribute (Alignment, Size)
4160 -- and for stream attributes, i.e. those cases where in the call to
4161 -- Rep_Item_Too_Late, FOnly is set True so that only the freezing rules
4162 -- are checked. Note that the case of stream attributes is not clear
4163 -- from the RM, but see AI95-00137. Also, the RM seems to disallow
4164 -- Storage_Size for derived task types, but that is also clearly
4167 procedure Analyze_Stream_TSS_Definition (TSS_Nam : TSS_Name_Type);
4168 -- Common processing for 'Read, 'Write, 'Input and 'Output attribute
4169 -- definition clauses.
4171 function Duplicate_Clause return Boolean;
4172 -- This routine checks if the aspect for U_Ent being given by attribute
4173 -- definition clause N is for an aspect that has already been specified,
4174 -- and if so gives an error message. If there is a duplicate, True is
4175 -- returned, otherwise if there is no error, False is returned.
4177 procedure Check_Indexing_Functions;
4178 -- Check that the function in Constant_Indexing or Variable_Indexing
4179 -- attribute has the proper type structure. If the name is overloaded,
4180 -- check that some interpretation is legal.
4182 procedure Check_Iterator_Functions;
4183 -- Check that there is a single function in Default_Iterator attribute
4184 -- that has the proper type structure.
4186 function Check_Primitive_Function (Subp : Entity_Id) return Boolean;
4187 -- Common legality check for the previous two
4189 -----------------------------------
4190 -- Analyze_Stream_TSS_Definition --
4191 -----------------------------------
4193 procedure Analyze_Stream_TSS_Definition (TSS_Nam : TSS_Name_Type) is
4194 Subp : Entity_Id := Empty;
4199 Is_Read : constant Boolean := (TSS_Nam = TSS_Stream_Read);
4200 -- True for Read attribute, False for other attributes
4202 function Has_Good_Profile
4204 Report : Boolean := False) return Boolean;
4205 -- Return true if the entity is a subprogram with an appropriate
4206 -- profile for the attribute being defined. If result is False and
4207 -- Report is True, function emits appropriate error.
4209 ----------------------
4210 -- Has_Good_Profile --
4211 ----------------------
4213 function Has_Good_Profile
4215 Report : Boolean := False) return Boolean
4217 Expected_Ekind : constant array (Boolean) of Entity_Kind :=
4218 (False => E_Procedure, True => E_Function);
4219 Is_Function : constant Boolean := (TSS_Nam = TSS_Stream_Input);
4224 if Ekind (Subp) /= Expected_Ekind (Is_Function) then
4228 F := First_Formal (Subp);
4231 or else Ekind (Etype (F)) /= E_Anonymous_Access_Type
4232 or else Designated_Type (Etype (F)) /=
4233 Class_Wide_Type (RTE (RE_Root_Stream_Type))
4238 if not Is_Function then
4242 Expected_Mode : constant array (Boolean) of Entity_Kind :=
4243 (False => E_In_Parameter,
4244 True => E_Out_Parameter);
4246 if Parameter_Mode (F) /= Expected_Mode (Is_Read) then
4253 -- If the attribute specification comes from an aspect
4254 -- specification for a class-wide stream, the parameter must be
4255 -- a class-wide type of the entity to which the aspect applies.
4257 if From_Aspect_Specification (N)
4258 and then Class_Present (Parent (N))
4259 and then Is_Class_Wide_Type (Typ)
4265 Typ := Etype (Subp);
4268 -- Verify that the prefix of the attribute and the local name for
4269 -- the type of the formal match, or one is the class-wide of the
4270 -- other, in the case of a class-wide stream operation.
4272 if Base_Type (Typ) = Base_Type (Ent)
4273 or else (Is_Class_Wide_Type (Typ)
4274 and then Typ = Class_Wide_Type (Base_Type (Ent)))
4275 or else (Is_Class_Wide_Type (Ent)
4276 and then Ent = Class_Wide_Type (Base_Type (Typ)))
4283 if Present (Next_Formal (F)) then
4286 elsif not Is_Scalar_Type (Typ)
4287 and then not Is_First_Subtype (Typ)
4288 and then not Is_Class_Wide_Type (Typ)
4290 if Report and not Is_First_Subtype (Typ) then
4292 ("subtype of formal in stream operation must be a first "
4293 & "subtype", Parameter_Type (Parent (F)));
4301 end Has_Good_Profile;
4303 -- Start of processing for Analyze_Stream_TSS_Definition
4308 if not Is_Type (U_Ent) then
4309 Error_Msg_N ("local name must be a subtype", Nam);
4312 elsif not Is_First_Subtype (U_Ent) then
4313 Error_Msg_N ("local name must be a first subtype", Nam);
4317 Pnam := TSS (Base_Type (U_Ent), TSS_Nam);
4319 -- If Pnam is present, it can be either inherited from an ancestor
4320 -- type (in which case it is legal to redefine it for this type), or
4321 -- be a previous definition of the attribute for the same type (in
4322 -- which case it is illegal).
4324 -- In the first case, it will have been analyzed already, and we
4325 -- can check that its profile does not match the expected profile
4326 -- for a stream attribute of U_Ent. In the second case, either Pnam
4327 -- has been analyzed (and has the expected profile), or it has not
4328 -- been analyzed yet (case of a type that has not been frozen yet
4329 -- and for which the stream attribute has been set using Set_TSS).
4332 and then (No (First_Entity (Pnam)) or else Has_Good_Profile (Pnam))
4334 Error_Msg_Sloc := Sloc (Pnam);
4335 Error_Msg_Name_1 := Attr;
4336 Error_Msg_N ("% attribute already defined #", Nam);
4342 if Is_Entity_Name (Expr) then
4343 if not Is_Overloaded (Expr) then
4344 if Has_Good_Profile (Entity (Expr), Report => True) then
4345 Subp := Entity (Expr);
4349 Get_First_Interp (Expr, I, It);
4350 while Present (It.Nam) loop
4351 if Has_Good_Profile (It.Nam) then
4356 Get_Next_Interp (I, It);
4361 if Present (Subp) then
4362 if Is_Abstract_Subprogram (Subp) then
4363 Error_Msg_N ("stream subprogram must not be abstract", Expr);
4366 -- A stream subprogram for an interface type must be a null
4367 -- procedure (RM 13.13.2 (38/3)). Note that the class-wide type
4368 -- of an interface is not an interface type (3.9.4 (6.b/2)).
4370 elsif Is_Interface (U_Ent)
4371 and then not Is_Class_Wide_Type (U_Ent)
4372 and then not Inside_A_Generic
4374 (Ekind (Subp) = E_Function
4378 (Unit_Declaration_Node (Ultimate_Alias (Subp)))))
4381 ("stream subprogram for interface type must be null "
4382 & "procedure", Expr);
4385 Set_Entity (Expr, Subp);
4386 Set_Etype (Expr, Etype (Subp));
4388 New_Stream_Subprogram (N, U_Ent, Subp, TSS_Nam);
4391 Error_Msg_Name_1 := Attr;
4392 Error_Msg_N ("incorrect expression for% attribute", Expr);
4394 end Analyze_Stream_TSS_Definition;
4396 ------------------------------
4397 -- Check_Indexing_Functions --
4398 ------------------------------
4400 procedure Check_Indexing_Functions is
4401 Indexing_Found : Boolean := False;
4403 procedure Check_Inherited_Indexing;
4404 -- For a derived type, check that no indexing aspect is specified
4405 -- for the type if it is also inherited
4407 procedure Check_One_Function (Subp : Entity_Id);
4408 -- Check one possible interpretation. Sets Indexing_Found True if a
4409 -- legal indexing function is found.
4411 procedure Illegal_Indexing (Msg : String);
4412 -- Diagnose illegal indexing function if not overloaded. In the
4413 -- overloaded case indicate that no legal interpretation exists.
4415 ------------------------------
4416 -- Check_Inherited_Indexing --
4417 ------------------------------
4419 procedure Check_Inherited_Indexing is
4420 Inherited : Node_Id;
4423 if Attr = Name_Constant_Indexing then
4425 Find_Aspect (Etype (Ent), Aspect_Constant_Indexing);
4426 else pragma Assert (Attr = Name_Variable_Indexing);
4428 Find_Aspect (Etype (Ent), Aspect_Variable_Indexing);
4431 if Present (Inherited) then
4432 if Debug_Flag_Dot_XX then
4435 -- OK if current attribute_definition_clause is expansion of
4436 -- inherited aspect.
4438 elsif Aspect_Rep_Item (Inherited) = N then
4441 -- Indicate the operation that must be overridden, rather than
4442 -- redefining the indexing aspect.
4446 ("indexing function already inherited from parent type");
4448 ("!override & instead",
4449 N, Entity (Expression (Inherited)));
4452 end Check_Inherited_Indexing;
4454 ------------------------
4455 -- Check_One_Function --
4456 ------------------------
4458 procedure Check_One_Function (Subp : Entity_Id) is
4459 Default_Element : Node_Id;
4460 Ret_Type : constant Entity_Id := Etype (Subp);
4463 if not Is_Overloadable (Subp) then
4464 Illegal_Indexing ("illegal indexing function for type&");
4467 elsif Scope (Subp) /= Scope (Ent) then
4468 if Nkind (Expr) = N_Expanded_Name then
4470 -- Indexing function can't be declared elsewhere
4473 ("indexing function must be declared in scope of type&");
4478 elsif No (First_Formal (Subp)) then
4480 ("Indexing requires a function that applies to type&");
4483 elsif No (Next_Formal (First_Formal (Subp))) then
4485 ("indexing function must have at least two parameters");
4488 elsif Is_Derived_Type (Ent) then
4489 Check_Inherited_Indexing;
4492 if not Check_Primitive_Function (Subp) then
4494 ("Indexing aspect requires a function that applies to type&");
4498 -- If partial declaration exists, verify that it is not tagged.
4500 if Ekind (Current_Scope) = E_Package
4501 and then Has_Private_Declaration (Ent)
4502 and then From_Aspect_Specification (N)
4504 List_Containing (Parent (Ent)) =
4505 Private_Declarations
4506 (Specification (Unit_Declaration_Node (Current_Scope)))
4507 and then Nkind (N) = N_Attribute_Definition_Clause
4514 First (Visible_Declarations
4516 (Unit_Declaration_Node (Current_Scope))));
4518 while Present (Decl) loop
4519 if Nkind (Decl) = N_Private_Type_Declaration
4520 and then Ent = Full_View (Defining_Identifier (Decl))
4521 and then Tagged_Present (Decl)
4522 and then No (Aspect_Specifications (Decl))
4525 ("Indexing aspect cannot be specified on full view "
4526 & "if partial view is tagged");
4535 -- An indexing function must return either the default element of
4536 -- the container, or a reference type. For variable indexing it
4537 -- must be the latter.
4540 Find_Value_Of_Aspect
4541 (Etype (First_Formal (Subp)), Aspect_Iterator_Element);
4543 if Present (Default_Element) then
4544 Analyze (Default_Element);
4547 -- For variable_indexing the return type must be a reference type
4549 if Attr = Name_Variable_Indexing then
4550 if not Has_Implicit_Dereference (Ret_Type) then
4552 ("variable indexing must return a reference type");
4555 elsif Is_Access_Constant
4556 (Etype (First_Discriminant (Ret_Type)))
4559 ("variable indexing must return an access to variable");
4564 if Has_Implicit_Dereference (Ret_Type)
4566 Is_Access_Constant (Etype (First_Discriminant (Ret_Type)))
4569 ("constant indexing must return an access to constant");
4572 elsif Is_Access_Type (Etype (First_Formal (Subp)))
4573 and then not Is_Access_Constant (Etype (First_Formal (Subp)))
4576 ("constant indexing must apply to an access to constant");
4581 -- All checks succeeded.
4583 Indexing_Found := True;
4584 end Check_One_Function;
4586 -----------------------
4587 -- Illegal_Indexing --
4588 -----------------------
4590 procedure Illegal_Indexing (Msg : String) is
4592 Error_Msg_NE (Msg, N, Ent);
4593 end Illegal_Indexing;
4595 -- Start of processing for Check_Indexing_Functions
4599 Check_Inherited_Indexing;
4604 if not Is_Overloaded (Expr) then
4605 Check_One_Function (Entity (Expr));
4613 Indexing_Found := False;
4614 Get_First_Interp (Expr, I, It);
4615 while Present (It.Nam) loop
4617 -- Note that analysis will have added the interpretation
4618 -- that corresponds to the dereference. We only check the
4619 -- subprogram itself. Ignore homonyms that may come from
4620 -- derived types in the context.
4622 if Is_Overloadable (It.Nam)
4623 and then Comes_From_Source (It.Nam)
4625 Check_One_Function (It.Nam);
4628 Get_Next_Interp (I, It);
4633 if not Indexing_Found and then not Error_Posted (N) then
4635 ("aspect Indexing requires a local function that applies to "
4636 & "type&", Expr, Ent);
4638 end Check_Indexing_Functions;
4640 ------------------------------
4641 -- Check_Iterator_Functions --
4642 ------------------------------
4644 procedure Check_Iterator_Functions is
4645 function Valid_Default_Iterator (Subp : Entity_Id) return Boolean;
4646 -- Check one possible interpretation for validity
4648 ----------------------------
4649 -- Valid_Default_Iterator --
4650 ----------------------------
4652 function Valid_Default_Iterator (Subp : Entity_Id) return Boolean is
4653 Root_T : constant Entity_Id := Root_Type (Etype (Etype (Subp)));
4657 if not Check_Primitive_Function (Subp) then
4660 -- The return type must be derived from a type in an instance
4661 -- of Iterator.Interfaces, and thus its root type must have a
4664 elsif Chars (Root_T) /= Name_Forward_Iterator
4665 and then Chars (Root_T) /= Name_Reversible_Iterator
4670 Formal := First_Formal (Subp);
4673 -- False if any subsequent formal has no default expression
4675 Formal := Next_Formal (Formal);
4676 while Present (Formal) loop
4677 if No (Expression (Parent (Formal))) then
4681 Next_Formal (Formal);
4684 -- True if all subsequent formals have default expressions
4687 end Valid_Default_Iterator;
4689 -- Start of processing for Check_Iterator_Functions
4694 if not Is_Entity_Name (Expr) then
4695 Error_Msg_N ("aspect Iterator must be a function name", Expr);
4698 if not Is_Overloaded (Expr) then
4699 if Entity (Expr) /= Any_Id
4700 and then not Check_Primitive_Function (Entity (Expr))
4703 ("aspect Indexing requires a function that applies to type&",
4704 Entity (Expr), Ent);
4707 -- Flag the default_iterator as well as the denoted function.
4709 if not Valid_Default_Iterator (Entity (Expr)) then
4710 Error_Msg_N ("improper function for default iterator!", Expr);
4715 Default : Entity_Id := Empty;
4720 Get_First_Interp (Expr, I, It);
4721 while Present (It.Nam) loop
4722 if not Check_Primitive_Function (It.Nam)
4723 or else not Valid_Default_Iterator (It.Nam)
4727 elsif Present (Default) then
4729 -- An explicit one should override an implicit one
4731 if Comes_From_Source (Default) =
4732 Comes_From_Source (It.Nam)
4734 Error_Msg_N ("default iterator must be unique", Expr);
4735 Error_Msg_Sloc := Sloc (Default);
4736 Error_Msg_N ("\\possible interpretation#", Expr);
4737 Error_Msg_Sloc := Sloc (It.Nam);
4738 Error_Msg_N ("\\possible interpretation#", Expr);
4740 elsif Comes_From_Source (It.Nam) then
4747 Get_Next_Interp (I, It);
4750 if Present (Default) then
4751 Set_Entity (Expr, Default);
4752 Set_Is_Overloaded (Expr, False);
4755 ("no interpretation is a valid default iterator!", Expr);
4759 end Check_Iterator_Functions;
4761 -------------------------------
4762 -- Check_Primitive_Function --
4763 -------------------------------
4765 function Check_Primitive_Function (Subp : Entity_Id) return Boolean is
4769 if Ekind (Subp) /= E_Function then
4773 if No (First_Formal (Subp)) then
4776 Ctrl := Etype (First_Formal (Subp));
4779 -- To be a primitive operation subprogram has to be in same scope.
4781 if Scope (Ctrl) /= Scope (Subp) then
4785 -- Type of formal may be the class-wide type, an access to such,
4786 -- or an incomplete view.
4789 or else Ctrl = Class_Wide_Type (Ent)
4791 (Ekind (Ctrl) = E_Anonymous_Access_Type
4792 and then (Designated_Type (Ctrl) = Ent
4794 Designated_Type (Ctrl) = Class_Wide_Type (Ent)))
4796 (Ekind (Ctrl) = E_Incomplete_Type
4797 and then Full_View (Ctrl) = Ent)
4805 end Check_Primitive_Function;
4807 ----------------------
4808 -- Duplicate_Clause --
4809 ----------------------
4811 function Duplicate_Clause return Boolean is
4815 -- Nothing to do if this attribute definition clause comes from
4816 -- an aspect specification, since we could not be duplicating an
4817 -- explicit clause, and we dealt with the case of duplicated aspects
4818 -- in Analyze_Aspect_Specifications.
4820 if From_Aspect_Specification (N) then
4824 -- Otherwise current clause may duplicate previous clause, or a
4825 -- previously given pragma or aspect specification for the same
4828 A := Get_Rep_Item (U_Ent, Chars (N), Check_Parents => False);
4831 Error_Msg_Name_1 := Chars (N);
4832 Error_Msg_Sloc := Sloc (A);
4834 Error_Msg_NE ("aspect% for & previously given#", N, U_Ent);
4839 end Duplicate_Clause;
4841 -- Start of processing for Analyze_Attribute_Definition_Clause
4844 -- The following code is a defense against recursion. Not clear that
4845 -- this can happen legitimately, but perhaps some error situations can
4846 -- cause it, and we did see this recursion during testing.
4848 if Analyzed (N) then
4851 Set_Analyzed (N, True);
4854 Check_Restriction_No_Use_Of_Attribute (N);
4856 -- Ignore some selected attributes in CodePeer mode since they are not
4857 -- relevant in this context.
4859 if CodePeer_Mode then
4862 -- Ignore Component_Size in CodePeer mode, to avoid changing the
4863 -- internal representation of types by implicitly packing them.
4865 when Attribute_Component_Size =>
4866 Rewrite (N, Make_Null_Statement (Sloc (N)));
4874 -- Process Ignore_Rep_Clauses option
4876 if Ignore_Rep_Clauses then
4879 -- The following should be ignored. They do not affect legality
4880 -- and may be target dependent. The basic idea of -gnatI is to
4881 -- ignore any rep clauses that may be target dependent but do not
4882 -- affect legality (except possibly to be rejected because they
4883 -- are incompatible with the compilation target).
4885 when Attribute_Alignment
4886 | Attribute_Bit_Order
4887 | Attribute_Component_Size
4888 | Attribute_Default_Scalar_Storage_Order
4889 | Attribute_Machine_Radix
4890 | Attribute_Object_Size
4891 | Attribute_Scalar_Storage_Order
4894 | Attribute_Stream_Size
4895 | Attribute_Value_Size
4897 Kill_Rep_Clause (N);
4900 -- The following should not be ignored, because in the first place
4901 -- they are reasonably portable, and should not cause problems
4902 -- in compiling code from another target, and also they do affect
4903 -- legality, e.g. failing to provide a stream attribute for a type
4904 -- may make a program illegal.
4906 when Attribute_External_Tag
4910 | Attribute_Simple_Storage_Pool
4911 | Attribute_Storage_Pool
4912 | Attribute_Storage_Size
4917 -- We do not do anything here with address clauses, they will be
4918 -- removed by Freeze later on, but for now, it works better to
4919 -- keep them in the tree.
4921 when Attribute_Address =>
4924 -- Other cases are errors ("attribute& cannot be set with
4925 -- definition clause"), which will be caught below.
4933 Ent := Entity (Nam);
4935 if Rep_Item_Too_Early (Ent, N) then
4939 -- Rep clause applies to full view of incomplete type or private type if
4940 -- we have one (if not, this is a premature use of the type). However,
4941 -- certain semantic checks need to be done on the specified entity (i.e.
4942 -- the private view), so we save it in Ent.
4944 if Is_Private_Type (Ent)
4945 and then Is_Derived_Type (Ent)
4946 and then not Is_Tagged_Type (Ent)
4947 and then No (Full_View (Ent))
4949 -- If this is a private type whose completion is a derivation from
4950 -- another private type, there is no full view, and the attribute
4951 -- belongs to the type itself, not its underlying parent.
4955 elsif Ekind (Ent) = E_Incomplete_Type then
4957 -- The attribute applies to the full view, set the entity of the
4958 -- attribute definition accordingly.
4960 Ent := Underlying_Type (Ent);
4962 Set_Entity (Nam, Ent);
4965 U_Ent := Underlying_Type (Ent);
4968 -- Avoid cascaded error
4970 if Etype (Nam) = Any_Type then
4973 -- Must be declared in current scope or in case of an aspect
4974 -- specification, must be visible in current scope.
4976 elsif Scope (Ent) /= Current_Scope
4978 not (From_Aspect_Specification (N)
4979 and then Scope_Within_Or_Same (Current_Scope, Scope (Ent)))
4981 Error_Msg_N ("entity must be declared in this scope", Nam);
4984 -- Must not be a source renaming (we do have some cases where the
4985 -- expander generates a renaming, and those cases are OK, in such
4986 -- cases any attribute applies to the renamed object as well).
4988 elsif Is_Object (Ent)
4989 and then Present (Renamed_Object (Ent))
4991 -- In the case of a renamed object from source, this is an error
4992 -- unless the object is an aggregate and the renaming is created
4993 -- for an object declaration.
4995 if Comes_From_Source (Renamed_Object (Ent))
4996 and then Nkind (Renamed_Object (Ent)) /= N_Aggregate
4998 Get_Name_String (Chars (N));
4999 Error_Msg_Strlen := Name_Len;
5000 Error_Msg_String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len);
5002 ("~ clause not allowed for a renaming declaration "
5003 & "(RM 13.1(6))", Nam);
5006 -- For the case of a compiler generated renaming, the attribute
5007 -- definition clause applies to the renamed object created by the
5008 -- expander. The easiest general way to handle this is to create a
5009 -- copy of the attribute definition clause for this object.
5011 elsif Is_Entity_Name (Renamed_Object (Ent)) then
5013 Make_Attribute_Definition_Clause (Loc,
5015 New_Occurrence_Of (Entity (Renamed_Object (Ent)), Loc),
5017 Expression => Duplicate_Subexpr (Expression (N))));
5019 -- If the renamed object is not an entity, it must be a dereference
5020 -- of an unconstrained function call, and we must introduce a new
5021 -- declaration to capture the expression. This is needed in the case
5022 -- of 'Alignment, where the original declaration must be rewritten.
5026 (Nkind (Renamed_Object (Ent)) = N_Explicit_Dereference);
5030 -- If no underlying entity, use entity itself, applies to some
5031 -- previously detected error cases ???
5033 elsif No (U_Ent) then
5036 -- Cannot specify for a subtype (exception Object/Value_Size)
5038 elsif Is_Type (U_Ent)
5039 and then not Is_First_Subtype (U_Ent)
5040 and then Id /= Attribute_Object_Size
5041 and then Id /= Attribute_Value_Size
5042 and then not From_At_Mod (N)
5044 Error_Msg_N ("cannot specify attribute for subtype", Nam);
5048 Set_Entity (N, U_Ent);
5050 -- Switch on particular attribute
5058 -- Address attribute definition clause
5060 when Attribute_Address => Address : begin
5062 -- A little error check, catch for X'Address use X'Address;
5064 if Nkind (Nam) = N_Identifier
5065 and then Nkind (Expr) = N_Attribute_Reference
5066 and then Attribute_Name (Expr) = Name_Address
5067 and then Nkind (Prefix (Expr)) = N_Identifier
5068 and then Chars (Nam) = Chars (Prefix (Expr))
5071 ("address for & is self-referencing", Prefix (Expr), Ent);
5075 -- Not that special case, carry on with analysis of expression
5077 Analyze_And_Resolve (Expr, RTE (RE_Address));
5079 -- Even when ignoring rep clauses we need to indicate that the
5080 -- entity has an address clause and thus it is legal to declare
5081 -- it imported. Freeze will get rid of the address clause later.
5082 -- Also call Set_Address_Taken to indicate that an address clause
5083 -- was present, even if we are about to remove it.
5085 if Ignore_Rep_Clauses then
5086 Set_Address_Taken (U_Ent);
5088 if Ekind_In (U_Ent, E_Variable, E_Constant) then
5089 Record_Rep_Item (U_Ent, N);
5095 if Duplicate_Clause then
5098 -- Case of address clause for subprogram
5100 elsif Is_Subprogram (U_Ent) then
5101 if Has_Homonym (U_Ent) then
5103 ("address clause cannot be given for overloaded "
5104 & "subprogram", Nam);
5108 -- For subprograms, all address clauses are permitted, and we
5109 -- mark the subprogram as having a deferred freeze so that Gigi
5110 -- will not elaborate it too soon.
5112 -- Above needs more comments, what is too soon about???
5114 Set_Has_Delayed_Freeze (U_Ent);
5116 -- Case of address clause for entry
5118 elsif Ekind (U_Ent) = E_Entry then
5119 if Nkind (Parent (N)) = N_Task_Body then
5121 ("entry address must be specified in task spec", Nam);
5125 -- For entries, we require a constant address
5127 Check_Constant_Address_Clause (Expr, U_Ent);
5129 -- Special checks for task types
5131 if Is_Task_Type (Scope (U_Ent))
5132 and then Comes_From_Source (Scope (U_Ent))
5135 ("??entry address declared for entry in task type", N);
5137 ("\??only one task can be declared of this type", N);
5140 -- Entry address clauses are obsolescent
5142 Check_Restriction (No_Obsolescent_Features, N);
5144 if Warn_On_Obsolescent_Feature then
5146 ("?j?attaching interrupt to task entry is an obsolescent "
5147 & "feature (RM J.7.1)", N);
5149 ("\?j?use interrupt procedure instead", N);
5152 -- Case of an address clause for a class-wide object, which is
5153 -- considered erroneous.
5155 elsif Is_Class_Wide_Type (Etype (U_Ent)) then
5157 ("??class-wide object & must not be overlaid", Nam, U_Ent);
5159 ("\??Program_Error will be raised at run time", Nam);
5160 Insert_Action (Declaration_Node (U_Ent),
5161 Make_Raise_Program_Error (Loc,
5162 Reason => PE_Overlaid_Controlled_Object));
5165 -- Case of address clause for an object
5167 elsif Ekind_In (U_Ent, E_Constant, E_Variable) then
5169 Expr : constant Node_Id := Expression (N);
5174 -- Exported variables cannot have an address clause, because
5175 -- this cancels the effect of the pragma Export.
5177 if Is_Exported (U_Ent) then
5179 ("cannot export object with address clause", Nam);
5183 Find_Overlaid_Entity (N, O_Ent, Off);
5185 if Present (O_Ent) then
5187 -- If the object overlays a constant object, mark it so
5189 if Is_Constant_Object (O_Ent) then
5190 Set_Overlays_Constant (U_Ent);
5193 -- If the address clause is of the form:
5195 -- for X'Address use Y'Address;
5199 -- C : constant Address := Y'Address;
5201 -- for X'Address use C;
5203 -- then we make an entry in the table to check the size
5204 -- and alignment of the overlaying variable. But we defer
5205 -- this check till after code generation to take full
5206 -- advantage of the annotation done by the back end.
5208 -- If the entity has a generic type, the check will be
5209 -- performed in the instance if the actual type justifies
5210 -- it, and we do not insert the clause in the table to
5211 -- prevent spurious warnings.
5213 -- Note: we used to test Comes_From_Source and only give
5214 -- this warning for source entities, but we have removed
5215 -- this test. It really seems bogus to generate overlays
5216 -- that would trigger this warning in generated code.
5217 -- Furthermore, by removing the test, we handle the
5218 -- aspect case properly.
5220 if Is_Object (O_Ent)
5221 and then not Is_Generic_Formal (O_Ent)
5222 and then not Is_Generic_Type (Etype (U_Ent))
5223 and then Address_Clause_Overlay_Warnings
5225 Register_Address_Clause_Check
5226 (N, U_Ent, No_Uint, O_Ent, Off);
5229 -- If the overlay changes the storage order, mark the
5230 -- entity as being volatile to block any optimization
5231 -- for it since the construct is not really supported
5234 if (Is_Record_Type (Etype (U_Ent))
5235 or else Is_Array_Type (Etype (U_Ent)))
5236 and then (Is_Record_Type (Etype (O_Ent))
5237 or else Is_Array_Type (Etype (O_Ent)))
5238 and then Reverse_Storage_Order (Etype (U_Ent)) /=
5239 Reverse_Storage_Order (Etype (O_Ent))
5241 Set_Treat_As_Volatile (U_Ent);
5245 -- If this is not an overlay, mark a variable as being
5246 -- volatile to prevent unwanted optimizations. It's a
5247 -- conservative interpretation of RM 13.3(19) for the
5248 -- cases where the compiler cannot detect potential
5249 -- aliasing issues easily and it also covers the case
5250 -- of an absolute address where the volatile aspect is
5251 -- kind of implicit.
5253 if Ekind (U_Ent) = E_Variable then
5254 Set_Treat_As_Volatile (U_Ent);
5257 -- Make an entry in the table for an absolute address as
5258 -- above to check that the value is compatible with the
5259 -- alignment of the object.
5262 Addr : constant Node_Id := Address_Value (Expr);
5264 if Compile_Time_Known_Value (Addr)
5265 and then Address_Clause_Overlay_Warnings
5267 Register_Address_Clause_Check
5268 (N, U_Ent, Expr_Value (Addr), Empty, False);
5273 -- Issue an unconditional warning for a constant overlaying
5274 -- a variable. For the reverse case, we will issue it only
5275 -- if the variable is modified.
5277 if Ekind (U_Ent) = E_Constant
5278 and then Present (O_Ent)
5279 and then not Overlays_Constant (U_Ent)
5280 and then Address_Clause_Overlay_Warnings
5282 Error_Msg_N ("??constant overlays a variable", Expr);
5284 -- Imported variables can have an address clause, but then
5285 -- the import is pretty meaningless except to suppress
5286 -- initializations, so we do not need such variables to
5287 -- be statically allocated (and in fact it causes trouble
5288 -- if the address clause is a local value).
5290 elsif Is_Imported (U_Ent) then
5291 Set_Is_Statically_Allocated (U_Ent, False);
5294 -- We mark a possible modification of a variable with an
5295 -- address clause, since it is likely aliasing is occurring.
5297 Note_Possible_Modification (Nam, Sure => False);
5299 -- Legality checks on the address clause for initialized
5300 -- objects is deferred until the freeze point, because
5301 -- a subsequent pragma might indicate that the object
5302 -- is imported and thus not initialized. Also, the address
5303 -- clause might involve entities that have yet to be
5306 Set_Has_Delayed_Freeze (U_Ent);
5308 -- If an initialization call has been generated for this
5309 -- object, it needs to be deferred to after the freeze node
5310 -- we have just now added, otherwise GIGI will see a
5311 -- reference to the variable (as actual to the IP call)
5312 -- before its definition.
5315 Init_Call : constant Node_Id :=
5316 Remove_Init_Call (U_Ent, N);
5319 if Present (Init_Call) then
5320 Append_Freeze_Action (U_Ent, Init_Call);
5322 -- Reset Initialization_Statements pointer so that
5323 -- if there is a pragma Import further down, it can
5324 -- clear any default initialization.
5326 Set_Initialization_Statements (U_Ent, Init_Call);
5330 -- Entity has delayed freeze, so we will generate an
5331 -- alignment check at the freeze point unless suppressed.
5333 if not Range_Checks_Suppressed (U_Ent)
5334 and then not Alignment_Checks_Suppressed (U_Ent)
5336 Set_Check_Address_Alignment (N);
5339 -- Kill the size check code, since we are not allocating
5340 -- the variable, it is somewhere else.
5342 Kill_Size_Check_Code (U_Ent);
5345 -- Not a valid entity for an address clause
5348 Error_Msg_N ("address cannot be given for &", Nam);
5356 -- Alignment attribute definition clause
5358 when Attribute_Alignment => Alignment : declare
5359 Align : constant Uint := Get_Alignment_Value (Expr);
5360 Max_Align : constant Uint := UI_From_Int (Maximum_Alignment);
5365 if not Is_Type (U_Ent)
5366 and then Ekind (U_Ent) /= E_Variable
5367 and then Ekind (U_Ent) /= E_Constant
5369 Error_Msg_N ("alignment cannot be given for &", Nam);
5371 elsif Duplicate_Clause then
5374 elsif Align /= No_Uint then
5375 Set_Has_Alignment_Clause (U_Ent);
5377 -- Tagged type case, check for attempt to set alignment to a
5378 -- value greater than Max_Align, and reset if so. This error
5379 -- is suppressed in ASIS mode to allow for different ASIS
5380 -- back ends or ASIS-based tools to query the illegal clause.
5382 if Is_Tagged_Type (U_Ent)
5383 and then Align > Max_Align
5384 and then not ASIS_Mode
5387 ("alignment for & set to Maximum_Aligment??", Nam);
5388 Set_Alignment (U_Ent, Max_Align);
5393 Set_Alignment (U_Ent, Align);
5396 -- For an array type, U_Ent is the first subtype. In that case,
5397 -- also set the alignment of the anonymous base type so that
5398 -- other subtypes (such as the itypes for aggregates of the
5399 -- type) also receive the expected alignment.
5401 if Is_Array_Type (U_Ent) then
5402 Set_Alignment (Base_Type (U_Ent), Align);
5411 -- Bit_Order attribute definition clause
5413 when Attribute_Bit_Order =>
5414 if not Is_Record_Type (U_Ent) then
5416 ("Bit_Order can only be defined for record type", Nam);
5418 elsif Is_Tagged_Type (U_Ent) and then Is_Derived_Type (U_Ent) then
5420 ("Bit_Order cannot be defined for record extensions", Nam);
5422 elsif Duplicate_Clause then
5426 Analyze_And_Resolve (Expr, RTE (RE_Bit_Order));
5428 if Etype (Expr) = Any_Type then
5431 elsif not Is_OK_Static_Expression (Expr) then
5432 Flag_Non_Static_Expr
5433 ("Bit_Order requires static expression!", Expr);
5435 elsif (Expr_Value (Expr) = 0) /= Bytes_Big_Endian then
5436 Set_Reverse_Bit_Order (Base_Type (U_Ent), True);
5440 --------------------
5441 -- Component_Size --
5442 --------------------
5444 -- Component_Size attribute definition clause
5446 when Attribute_Component_Size => Component_Size_Case : declare
5447 Csize : constant Uint := Static_Integer (Expr);
5451 New_Ctyp : Entity_Id;
5455 if not Is_Array_Type (U_Ent) then
5456 Error_Msg_N ("component size requires array type", Nam);
5460 Btype := Base_Type (U_Ent);
5461 Ctyp := Component_Type (Btype);
5463 if Duplicate_Clause then
5466 elsif Rep_Item_Too_Early (Btype, N) then
5469 elsif Csize /= No_Uint then
5470 Check_Size (Expr, Ctyp, Csize, Biased);
5472 -- For the biased case, build a declaration for a subtype that
5473 -- will be used to represent the biased subtype that reflects
5474 -- the biased representation of components. We need the subtype
5475 -- to get proper conversions on referencing elements of the
5480 Make_Defining_Identifier (Loc,
5482 New_External_Name (Chars (U_Ent), 'C', 0, 'T'));
5485 Make_Subtype_Declaration (Loc,
5486 Defining_Identifier => New_Ctyp,
5487 Subtype_Indication =>
5488 New_Occurrence_Of (Component_Type (Btype), Loc));
5490 Set_Parent (Decl, N);
5491 Analyze (Decl, Suppress => All_Checks);
5493 Set_Has_Delayed_Freeze (New_Ctyp, False);
5494 Init_Esize (New_Ctyp);
5495 Set_RM_Size (New_Ctyp, Csize);
5496 Init_Alignment (New_Ctyp);
5497 Set_Is_Itype (New_Ctyp, True);
5498 Set_Associated_Node_For_Itype (New_Ctyp, U_Ent);
5500 Set_Component_Type (Btype, New_Ctyp);
5501 Set_Biased (New_Ctyp, N, "component size clause");
5504 Set_Component_Size (Btype, Csize);
5506 -- Deal with warning on overridden size
5508 if Warn_On_Overridden_Size
5509 and then Has_Size_Clause (Ctyp)
5510 and then RM_Size (Ctyp) /= Csize
5513 ("component size overrides size clause for&?S?", N, Ctyp);
5516 Set_Has_Component_Size_Clause (Btype, True);
5517 Set_Has_Non_Standard_Rep (Btype, True);
5519 end Component_Size_Case;
5521 -----------------------
5522 -- Constant_Indexing --
5523 -----------------------
5525 when Attribute_Constant_Indexing =>
5526 Check_Indexing_Functions;
5532 when Attribute_CPU =>
5534 -- CPU attribute definition clause not allowed except from aspect
5537 if From_Aspect_Specification (N) then
5538 if not Is_Task_Type (U_Ent) then
5539 Error_Msg_N ("CPU can only be defined for task", Nam);
5541 elsif Duplicate_Clause then
5545 -- The expression must be analyzed in the special manner
5546 -- described in "Handling of Default and Per-Object
5547 -- Expressions" in sem.ads.
5549 -- The visibility to the components must be established
5550 -- and restored before and after analysis.
5553 Preanalyze_Spec_Expression (Expr, RTE (RE_CPU_Range));
5556 if not Is_OK_Static_Expression (Expr) then
5557 Check_Restriction (Static_Priorities, Expr);
5563 ("attribute& cannot be set with definition clause", N);
5566 ----------------------
5567 -- Default_Iterator --
5568 ----------------------
5570 when Attribute_Default_Iterator => Default_Iterator : declare
5575 -- If target type is untagged, further checks are irrelevant
5577 if not Is_Tagged_Type (U_Ent) then
5579 ("aspect Default_Iterator applies to tagged type", Nam);
5583 Check_Iterator_Functions;
5587 if not Is_Entity_Name (Expr)
5588 or else Ekind (Entity (Expr)) /= E_Function
5590 Error_Msg_N ("aspect Iterator must be a function", Expr);
5593 Func := Entity (Expr);
5596 -- The type of the first parameter must be T, T'class, or a
5597 -- corresponding access type (5.5.1 (8/3). If function is
5598 -- parameterless label type accordingly.
5600 if No (First_Formal (Func)) then
5603 Typ := Etype (First_Formal (Func));
5607 or else Typ = Class_Wide_Type (U_Ent)
5608 or else (Is_Access_Type (Typ)
5609 and then Designated_Type (Typ) = U_Ent)
5610 or else (Is_Access_Type (Typ)
5611 and then Designated_Type (Typ) =
5612 Class_Wide_Type (U_Ent))
5618 ("Default Iterator must be a primitive of&", Func, U_Ent);
5620 end Default_Iterator;
5622 ------------------------
5623 -- Dispatching_Domain --
5624 ------------------------
5626 when Attribute_Dispatching_Domain =>
5628 -- Dispatching_Domain attribute definition clause not allowed
5629 -- except from aspect specification.
5631 if From_Aspect_Specification (N) then
5632 if not Is_Task_Type (U_Ent) then
5634 ("Dispatching_Domain can only be defined for task", Nam);
5636 elsif Duplicate_Clause then
5640 -- The expression must be analyzed in the special manner
5641 -- described in "Handling of Default and Per-Object
5642 -- Expressions" in sem.ads.
5644 -- The visibility to the components must be restored
5648 Preanalyze_Spec_Expression
5649 (Expr, RTE (RE_Dispatching_Domain));
5656 ("attribute& cannot be set with definition clause", N);
5663 when Attribute_External_Tag =>
5664 if not Is_Tagged_Type (U_Ent) then
5665 Error_Msg_N ("should be a tagged type", Nam);
5668 if Duplicate_Clause then
5672 Analyze_And_Resolve (Expr, Standard_String);
5674 if not Is_OK_Static_Expression (Expr) then
5675 Flag_Non_Static_Expr
5676 ("static string required for tag name!", Nam);
5679 if not Is_Library_Level_Entity (U_Ent) then
5681 ("??non-unique external tag supplied for &", N, U_Ent);
5683 ("\??same external tag applies to all subprogram calls",
5686 ("\??corresponding internal tag cannot be obtained", N);
5690 --------------------------
5691 -- Implicit_Dereference --
5692 --------------------------
5694 when Attribute_Implicit_Dereference =>
5696 -- Legality checks already performed at the point of the type
5697 -- declaration, aspect is not delayed.
5705 when Attribute_Input =>
5706 Analyze_Stream_TSS_Definition (TSS_Stream_Input);
5707 Set_Has_Specified_Stream_Input (Ent);
5709 ------------------------
5710 -- Interrupt_Priority --
5711 ------------------------
5713 when Attribute_Interrupt_Priority =>
5715 -- Interrupt_Priority attribute definition clause not allowed
5716 -- except from aspect specification.
5718 if From_Aspect_Specification (N) then
5719 if not Is_Concurrent_Type (U_Ent) then
5721 ("Interrupt_Priority can only be defined for task and "
5722 & "protected object", Nam);
5724 elsif Duplicate_Clause then
5728 -- The expression must be analyzed in the special manner
5729 -- described in "Handling of Default and Per-Object
5730 -- Expressions" in sem.ads.
5732 -- The visibility to the components must be restored
5736 Preanalyze_Spec_Expression
5737 (Expr, RTE (RE_Interrupt_Priority));
5741 -- Check the No_Task_At_Interrupt_Priority restriction
5743 if Is_Task_Type (U_Ent) then
5744 Check_Restriction (No_Task_At_Interrupt_Priority, N);
5750 ("attribute& cannot be set with definition clause", N);
5757 when Attribute_Iterable =>
5760 if Nkind (Expr) /= N_Aggregate then
5761 Error_Msg_N ("aspect Iterable must be an aggregate", Expr);
5768 Assoc := First (Component_Associations (Expr));
5769 while Present (Assoc) loop
5770 Analyze (Expression (Assoc));
5772 if not Is_Entity_Name (Expression (Assoc)) then
5773 Error_Msg_N ("value must be a function", Assoc);
5780 ----------------------
5781 -- Iterator_Element --
5782 ----------------------
5784 when Attribute_Iterator_Element =>
5787 if not Is_Entity_Name (Expr)
5788 or else not Is_Type (Entity (Expr))
5790 Error_Msg_N ("aspect Iterator_Element must be a type", Expr);
5797 -- Machine radix attribute definition clause
5799 when Attribute_Machine_Radix => Machine_Radix : declare
5800 Radix : constant Uint := Static_Integer (Expr);
5803 if not Is_Decimal_Fixed_Point_Type (U_Ent) then
5804 Error_Msg_N ("decimal fixed-point type expected for &", Nam);
5806 elsif Duplicate_Clause then
5809 elsif Radix /= No_Uint then
5810 Set_Has_Machine_Radix_Clause (U_Ent);
5811 Set_Has_Non_Standard_Rep (Base_Type (U_Ent));
5816 elsif Radix = 10 then
5817 Set_Machine_Radix_10 (U_Ent);
5819 -- The following error is suppressed in ASIS mode to allow for
5820 -- different ASIS back ends or ASIS-based tools to query the
5823 elsif not ASIS_Mode then
5824 Error_Msg_N ("machine radix value must be 2 or 10", Expr);
5833 -- Object_Size attribute definition clause
5835 when Attribute_Object_Size => Object_Size : declare
5836 Size : constant Uint := Static_Integer (Expr);
5839 pragma Warnings (Off, Biased);
5842 if not Is_Type (U_Ent) then
5843 Error_Msg_N ("Object_Size cannot be given for &", Nam);
5845 elsif Duplicate_Clause then
5849 Check_Size (Expr, U_Ent, Size, Biased);
5851 -- The following errors are suppressed in ASIS mode to allow
5852 -- for different ASIS back ends or ASIS-based tools to query
5853 -- the illegal clause.
5858 elsif Size <= 0 then
5859 Error_Msg_N ("Object_Size must be positive", Expr);
5861 elsif Is_Scalar_Type (U_Ent) then
5862 if Size /= 8 and then Size /= 16 and then Size /= 32
5863 and then UI_Mod (Size, 64) /= 0
5866 ("Object_Size must be 8, 16, 32, or multiple of 64",
5870 elsif Size mod 8 /= 0 then
5871 Error_Msg_N ("Object_Size must be a multiple of 8", Expr);
5874 Set_Esize (U_Ent, Size);
5875 Set_Has_Object_Size_Clause (U_Ent);
5876 Alignment_Check_For_Size_Change (U_Ent, Size);
5884 when Attribute_Output =>
5885 Analyze_Stream_TSS_Definition (TSS_Stream_Output);
5886 Set_Has_Specified_Stream_Output (Ent);
5892 when Attribute_Priority =>
5894 -- Priority attribute definition clause not allowed except from
5895 -- aspect specification.
5897 if From_Aspect_Specification (N) then
5898 if not (Is_Concurrent_Type (U_Ent)
5899 or else Ekind (U_Ent) = E_Procedure)
5902 ("Priority can only be defined for task and protected "
5905 elsif Duplicate_Clause then
5909 -- The expression must be analyzed in the special manner
5910 -- described in "Handling of Default and Per-Object
5911 -- Expressions" in sem.ads.
5913 -- The visibility to the components must be restored
5916 Preanalyze_Spec_Expression (Expr, Standard_Integer);
5919 if not Is_OK_Static_Expression (Expr) then
5920 Check_Restriction (Static_Priorities, Expr);
5926 ("attribute& cannot be set with definition clause", N);
5933 when Attribute_Read =>
5934 Analyze_Stream_TSS_Definition (TSS_Stream_Read);
5935 Set_Has_Specified_Stream_Read (Ent);
5937 --------------------------
5938 -- Scalar_Storage_Order --
5939 --------------------------
5941 -- Scalar_Storage_Order attribute definition clause
5943 when Attribute_Scalar_Storage_Order =>
5944 if not (Is_Record_Type (U_Ent) or else Is_Array_Type (U_Ent)) then
5946 ("Scalar_Storage_Order can only be defined for record or "
5947 & "array type", Nam);
5949 elsif Duplicate_Clause then
5953 Analyze_And_Resolve (Expr, RTE (RE_Bit_Order));
5955 if Etype (Expr) = Any_Type then
5958 elsif not Is_OK_Static_Expression (Expr) then
5959 Flag_Non_Static_Expr
5960 ("Scalar_Storage_Order requires static expression!", Expr);
5962 elsif (Expr_Value (Expr) = 0) /= Bytes_Big_Endian then
5964 -- Here for the case of a non-default (i.e. non-confirming)
5965 -- Scalar_Storage_Order attribute definition.
5967 if Support_Nondefault_SSO_On_Target then
5968 Set_Reverse_Storage_Order (Base_Type (U_Ent), True);
5971 ("non-default Scalar_Storage_Order not supported on "
5976 -- Clear SSO default indications since explicit setting of the
5977 -- order overrides the defaults.
5979 Set_SSO_Set_Low_By_Default (Base_Type (U_Ent), False);
5980 Set_SSO_Set_High_By_Default (Base_Type (U_Ent), False);
5987 -- Size attribute definition clause
5989 when Attribute_Size => Size : declare
5990 Size : constant Uint := Static_Integer (Expr);
5997 if Duplicate_Clause then
6000 elsif not Is_Type (U_Ent)
6001 and then Ekind (U_Ent) /= E_Variable
6002 and then Ekind (U_Ent) /= E_Constant
6004 Error_Msg_N ("size cannot be given for &", Nam);
6006 elsif Is_Array_Type (U_Ent)
6007 and then not Is_Constrained (U_Ent)
6010 ("size cannot be given for unconstrained array", Nam);
6012 elsif Size /= No_Uint then
6013 if Is_Type (U_Ent) then
6016 Etyp := Etype (U_Ent);
6019 -- Check size, note that Gigi is in charge of checking that the
6020 -- size of an array or record type is OK. Also we do not check
6021 -- the size in the ordinary fixed-point case, since it is too
6022 -- early to do so (there may be subsequent small clause that
6023 -- affects the size). We can check the size if a small clause
6024 -- has already been given.
6026 if not Is_Ordinary_Fixed_Point_Type (U_Ent)
6027 or else Has_Small_Clause (U_Ent)
6029 Check_Size (Expr, Etyp, Size, Biased);
6030 Set_Biased (U_Ent, N, "size clause", Biased);
6033 -- For types set RM_Size and Esize if possible
6035 if Is_Type (U_Ent) then
6036 Set_RM_Size (U_Ent, Size);
6038 -- For elementary types, increase Object_Size to power of 2,
6039 -- but not less than a storage unit in any case (normally
6040 -- this means it will be byte addressable).
6042 -- For all other types, nothing else to do, we leave Esize
6043 -- (object size) unset, the back end will set it from the
6044 -- size and alignment in an appropriate manner.
6046 -- In both cases, we check whether the alignment must be
6047 -- reset in the wake of the size change.
6049 if Is_Elementary_Type (U_Ent) then
6050 if Size <= System_Storage_Unit then
6051 Init_Esize (U_Ent, System_Storage_Unit);
6052 elsif Size <= 16 then
6053 Init_Esize (U_Ent, 16);
6054 elsif Size <= 32 then
6055 Init_Esize (U_Ent, 32);
6057 Set_Esize (U_Ent, (Size + 63) / 64 * 64);
6060 Alignment_Check_For_Size_Change (U_Ent, Esize (U_Ent));
6062 Alignment_Check_For_Size_Change (U_Ent, Size);
6065 -- For objects, set Esize only
6068 -- The following error is suppressed in ASIS mode to allow
6069 -- for different ASIS back ends or ASIS-based tools to query
6070 -- the illegal clause.
6072 if Is_Elementary_Type (Etyp)
6073 and then Size /= System_Storage_Unit
6074 and then Size /= System_Storage_Unit * 2
6075 and then Size /= System_Storage_Unit * 4
6076 and then Size /= System_Storage_Unit * 8
6077 and then not ASIS_Mode
6079 Error_Msg_Uint_1 := UI_From_Int (System_Storage_Unit);
6080 Error_Msg_Uint_2 := Error_Msg_Uint_1 * 8;
6082 ("size for primitive object must be a power of 2 in "
6083 & "the range ^-^", N);
6086 Set_Esize (U_Ent, Size);
6089 Set_Has_Size_Clause (U_Ent);
6097 -- Small attribute definition clause
6099 when Attribute_Small => Small : declare
6100 Implicit_Base : constant Entity_Id := Base_Type (U_Ent);
6104 Analyze_And_Resolve (Expr, Any_Real);
6106 if Etype (Expr) = Any_Type then
6109 elsif not Is_OK_Static_Expression (Expr) then
6110 Flag_Non_Static_Expr
6111 ("small requires static expression!", Expr);
6115 Small := Expr_Value_R (Expr);
6117 if Small <= Ureal_0 then
6118 Error_Msg_N ("small value must be greater than zero", Expr);
6124 if not Is_Ordinary_Fixed_Point_Type (U_Ent) then
6126 ("small requires an ordinary fixed point type", Nam);
6128 elsif Has_Small_Clause (U_Ent) then
6129 Error_Msg_N ("small already given for &", Nam);
6131 elsif Small > Delta_Value (U_Ent) then
6133 ("small value must not be greater than delta value", Nam);
6136 Set_Small_Value (U_Ent, Small);
6137 Set_Small_Value (Implicit_Base, Small);
6138 Set_Has_Small_Clause (U_Ent);
6139 Set_Has_Small_Clause (Implicit_Base);
6140 Set_Has_Non_Standard_Rep (Implicit_Base);
6148 -- Storage_Pool attribute definition clause
6150 when Attribute_Simple_Storage_Pool
6151 | Attribute_Storage_Pool
6153 Storage_Pool : declare
6158 if Ekind (U_Ent) = E_Access_Subprogram_Type then
6160 ("storage pool cannot be given for access-to-subprogram type",
6164 elsif not Ekind_In (U_Ent, E_Access_Type, E_General_Access_Type)
6167 ("storage pool can only be given for access types", Nam);
6170 elsif Is_Derived_Type (U_Ent) then
6172 ("storage pool cannot be given for a derived access type",
6175 elsif Duplicate_Clause then
6178 elsif Present (Associated_Storage_Pool (U_Ent)) then
6179 Error_Msg_N ("storage pool already given for &", Nam);
6183 -- Check for Storage_Size previously given
6186 SS : constant Node_Id :=
6187 Get_Attribute_Definition_Clause
6188 (U_Ent, Attribute_Storage_Size);
6190 if Present (SS) then
6191 Check_Pool_Size_Clash (U_Ent, N, SS);
6195 -- Storage_Pool case
6197 if Id = Attribute_Storage_Pool then
6199 (Expr, Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
6201 -- In the Simple_Storage_Pool case, we allow a variable of any
6202 -- simple storage pool type, so we Resolve without imposing an
6206 Analyze_And_Resolve (Expr);
6208 if not Present (Get_Rep_Pragma
6209 (Etype (Expr), Name_Simple_Storage_Pool_Type))
6212 ("expression must be of a simple storage pool type", Expr);
6216 if not Denotes_Variable (Expr) then
6217 Error_Msg_N ("storage pool must be a variable", Expr);
6221 if Nkind (Expr) = N_Type_Conversion then
6222 T := Etype (Expression (Expr));
6227 -- The Stack_Bounded_Pool is used internally for implementing
6228 -- access types with a Storage_Size. Since it only work properly
6229 -- when used on one specific type, we need to check that it is not
6230 -- hijacked improperly:
6232 -- type T is access Integer;
6233 -- for T'Storage_Size use n;
6234 -- type Q is access Float;
6235 -- for Q'Storage_Size use T'Storage_Size; -- incorrect
6237 if RTE_Available (RE_Stack_Bounded_Pool)
6238 and then Base_Type (T) = RTE (RE_Stack_Bounded_Pool)
6240 Error_Msg_N ("non-shareable internal Pool", Expr);
6244 -- If the argument is a name that is not an entity name, then
6245 -- we construct a renaming operation to define an entity of
6246 -- type storage pool.
6248 if not Is_Entity_Name (Expr)
6249 and then Is_Object_Reference (Expr)
6251 Pool := Make_Temporary (Loc, 'P', Expr);
6254 Rnode : constant Node_Id :=
6255 Make_Object_Renaming_Declaration (Loc,
6256 Defining_Identifier => Pool,
6258 New_Occurrence_Of (Etype (Expr), Loc),
6262 -- If the attribute definition clause comes from an aspect
6263 -- clause, then insert the renaming before the associated
6264 -- entity's declaration, since the attribute clause has
6265 -- not yet been appended to the declaration list.
6267 if From_Aspect_Specification (N) then
6268 Insert_Before (Parent (Entity (N)), Rnode);
6270 Insert_Before (N, Rnode);
6274 Set_Associated_Storage_Pool (U_Ent, Pool);
6277 elsif Is_Entity_Name (Expr) then
6278 Pool := Entity (Expr);
6280 -- If pool is a renamed object, get original one. This can
6281 -- happen with an explicit renaming, and within instances.
6283 while Present (Renamed_Object (Pool))
6284 and then Is_Entity_Name (Renamed_Object (Pool))
6286 Pool := Entity (Renamed_Object (Pool));
6289 if Present (Renamed_Object (Pool))
6290 and then Nkind (Renamed_Object (Pool)) = N_Type_Conversion
6291 and then Is_Entity_Name (Expression (Renamed_Object (Pool)))
6293 Pool := Entity (Expression (Renamed_Object (Pool)));
6296 Set_Associated_Storage_Pool (U_Ent, Pool);
6298 elsif Nkind (Expr) = N_Type_Conversion
6299 and then Is_Entity_Name (Expression (Expr))
6300 and then Nkind (Original_Node (Expr)) = N_Attribute_Reference
6302 Pool := Entity (Expression (Expr));
6303 Set_Associated_Storage_Pool (U_Ent, Pool);
6306 Error_Msg_N ("incorrect reference to a Storage Pool", Expr);
6315 -- Storage_Size attribute definition clause
6317 when Attribute_Storage_Size => Storage_Size : declare
6318 Btype : constant Entity_Id := Base_Type (U_Ent);
6321 if Is_Task_Type (U_Ent) then
6323 -- Check obsolescent (but never obsolescent if from aspect)
6325 if not From_Aspect_Specification (N) then
6326 Check_Restriction (No_Obsolescent_Features, N);
6328 if Warn_On_Obsolescent_Feature then
6330 ("?j?storage size clause for task is an obsolescent "
6331 & "feature (RM J.9)", N);
6332 Error_Msg_N ("\?j?use Storage_Size pragma instead", N);
6339 if not Is_Access_Type (U_Ent)
6340 and then Ekind (U_Ent) /= E_Task_Type
6342 Error_Msg_N ("storage size cannot be given for &", Nam);
6344 elsif Is_Access_Type (U_Ent) and Is_Derived_Type (U_Ent) then
6346 ("storage size cannot be given for a derived access type",
6349 elsif Duplicate_Clause then
6353 Analyze_And_Resolve (Expr, Any_Integer);
6355 if Is_Access_Type (U_Ent) then
6357 -- Check for Storage_Pool previously given
6360 SP : constant Node_Id :=
6361 Get_Attribute_Definition_Clause
6362 (U_Ent, Attribute_Storage_Pool);
6365 if Present (SP) then
6366 Check_Pool_Size_Clash (U_Ent, SP, N);
6370 -- Special case of for x'Storage_Size use 0
6372 if Is_OK_Static_Expression (Expr)
6373 and then Expr_Value (Expr) = 0
6375 Set_No_Pool_Assigned (Btype);
6379 Set_Has_Storage_Size_Clause (Btype);
6387 when Attribute_Stream_Size => Stream_Size : declare
6388 Size : constant Uint := Static_Integer (Expr);
6391 if Ada_Version <= Ada_95 then
6392 Check_Restriction (No_Implementation_Attributes, N);
6395 if Duplicate_Clause then
6398 elsif Is_Elementary_Type (U_Ent) then
6400 -- The following errors are suppressed in ASIS mode to allow
6401 -- for different ASIS back ends or ASIS-based tools to query
6402 -- the illegal clause.
6407 elsif Size /= System_Storage_Unit
6408 and then Size /= System_Storage_Unit * 2
6409 and then Size /= System_Storage_Unit * 4
6410 and then Size /= System_Storage_Unit * 8
6412 Error_Msg_Uint_1 := UI_From_Int (System_Storage_Unit);
6414 ("stream size for elementary type must be a power of 2 "
6415 & "and at least ^", N);
6417 elsif RM_Size (U_Ent) > Size then
6418 Error_Msg_Uint_1 := RM_Size (U_Ent);
6420 ("stream size for elementary type must be a power of 2 "
6421 & "and at least ^", N);
6424 Set_Has_Stream_Size_Clause (U_Ent);
6427 Error_Msg_N ("Stream_Size cannot be given for &", Nam);
6435 -- Value_Size attribute definition clause
6437 when Attribute_Value_Size => Value_Size : declare
6438 Size : constant Uint := Static_Integer (Expr);
6442 if not Is_Type (U_Ent) then
6443 Error_Msg_N ("Value_Size cannot be given for &", Nam);
6445 elsif Duplicate_Clause then
6448 elsif Is_Array_Type (U_Ent)
6449 and then not Is_Constrained (U_Ent)
6452 ("Value_Size cannot be given for unconstrained array", Nam);
6455 if Is_Elementary_Type (U_Ent) then
6456 Check_Size (Expr, U_Ent, Size, Biased);
6457 Set_Biased (U_Ent, N, "value size clause", Biased);
6460 Set_RM_Size (U_Ent, Size);
6464 -----------------------
6465 -- Variable_Indexing --
6466 -----------------------
6468 when Attribute_Variable_Indexing =>
6469 Check_Indexing_Functions;
6475 when Attribute_Write =>
6476 Analyze_Stream_TSS_Definition (TSS_Stream_Write);
6477 Set_Has_Specified_Stream_Write (Ent);
6479 -- All other attributes cannot be set
6483 ("attribute& cannot be set with definition clause", N);
6486 -- The test for the type being frozen must be performed after any
6487 -- expression the clause has been analyzed since the expression itself
6488 -- might cause freezing that makes the clause illegal.
6490 if Rep_Item_Too_Late (U_Ent, N, FOnly) then
6493 end Analyze_Attribute_Definition_Clause;
6495 ----------------------------
6496 -- Analyze_Code_Statement --
6497 ----------------------------
6499 procedure Analyze_Code_Statement (N : Node_Id) is
6500 HSS : constant Node_Id := Parent (N);
6501 SBody : constant Node_Id := Parent (HSS);
6502 Subp : constant Entity_Id := Current_Scope;
6509 -- Accept foreign code statements for CodePeer. The analysis is skipped
6510 -- to avoid rejecting unrecognized constructs.
6512 if CodePeer_Mode then
6517 -- Analyze and check we get right type, note that this implements the
6518 -- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that is
6519 -- the only way that Asm_Insn could possibly be visible.
6521 Analyze_And_Resolve (Expression (N));
6523 if Etype (Expression (N)) = Any_Type then
6525 elsif Etype (Expression (N)) /= RTE (RE_Asm_Insn) then
6526 Error_Msg_N ("incorrect type for code statement", N);
6530 Check_Code_Statement (N);
6532 -- Make sure we appear in the handled statement sequence of a subprogram
6535 if Nkind (HSS) /= N_Handled_Sequence_Of_Statements
6536 or else Nkind (SBody) /= N_Subprogram_Body
6539 ("code statement can only appear in body of subprogram", N);
6543 -- Do remaining checks (RM 13.8(3)) if not already done
6545 if not Is_Machine_Code_Subprogram (Subp) then
6546 Set_Is_Machine_Code_Subprogram (Subp);
6548 -- No exception handlers allowed
6550 if Present (Exception_Handlers (HSS)) then
6552 ("exception handlers not permitted in machine code subprogram",
6553 First (Exception_Handlers (HSS)));
6556 -- No declarations other than use clauses and pragmas (we allow
6557 -- certain internally generated declarations as well).
6559 Decl := First (Declarations (SBody));
6560 while Present (Decl) loop
6561 DeclO := Original_Node (Decl);
6562 if Comes_From_Source (DeclO)
6563 and not Nkind_In (DeclO, N_Pragma,
6564 N_Use_Package_Clause,
6566 N_Implicit_Label_Declaration)
6569 ("this declaration not allowed in machine code subprogram",
6576 -- No statements other than code statements, pragmas, and labels.
6577 -- Again we allow certain internally generated statements.
6579 -- In Ada 2012, qualified expressions are names, and the code
6580 -- statement is initially parsed as a procedure call.
6582 Stmt := First (Statements (HSS));
6583 while Present (Stmt) loop
6584 StmtO := Original_Node (Stmt);
6586 -- A procedure call transformed into a code statement is OK
6588 if Ada_Version >= Ada_2012
6589 and then Nkind (StmtO) = N_Procedure_Call_Statement
6590 and then Nkind (Name (StmtO)) = N_Qualified_Expression
6594 elsif Comes_From_Source (StmtO)
6595 and then not Nkind_In (StmtO, N_Pragma,
6600 ("this statement is not allowed in machine code subprogram",
6607 end Analyze_Code_Statement;
6609 -----------------------------------------------
6610 -- Analyze_Enumeration_Representation_Clause --
6611 -----------------------------------------------
6613 procedure Analyze_Enumeration_Representation_Clause (N : Node_Id) is
6614 Ident : constant Node_Id := Identifier (N);
6615 Aggr : constant Node_Id := Array_Aggregate (N);
6616 Enumtype : Entity_Id;
6623 Err : Boolean := False;
6624 -- Set True to avoid cascade errors and crashes on incorrect source code
6626 Lo : constant Uint := Expr_Value (Type_Low_Bound (Universal_Integer));
6627 Hi : constant Uint := Expr_Value (Type_High_Bound (Universal_Integer));
6628 -- Allowed range of universal integer (= allowed range of enum lit vals)
6632 -- Minimum and maximum values of entries
6634 Max_Node : Node_Id := Empty; -- init to avoid warning
6635 -- Pointer to node for literal providing max value
6638 if Ignore_Rep_Clauses then
6639 Kill_Rep_Clause (N);
6643 -- Ignore enumeration rep clauses by default in CodePeer mode,
6644 -- unless -gnatd.I is specified, as a work around for potential false
6645 -- positive messages.
6647 if CodePeer_Mode and not Debug_Flag_Dot_II then
6651 -- First some basic error checks
6654 Enumtype := Entity (Ident);
6656 if Enumtype = Any_Type
6657 or else Rep_Item_Too_Early (Enumtype, N)
6661 Enumtype := Underlying_Type (Enumtype);
6664 if not Is_Enumeration_Type (Enumtype) then
6666 ("enumeration type required, found}",
6667 Ident, First_Subtype (Enumtype));
6671 -- Ignore rep clause on generic actual type. This will already have
6672 -- been flagged on the template as an error, and this is the safest
6673 -- way to ensure we don't get a junk cascaded message in the instance.
6675 if Is_Generic_Actual_Type (Enumtype) then
6678 -- Type must be in current scope
6680 elsif Scope (Enumtype) /= Current_Scope then
6681 Error_Msg_N ("type must be declared in this scope", Ident);
6684 -- Type must be a first subtype
6686 elsif not Is_First_Subtype (Enumtype) then
6687 Error_Msg_N ("cannot give enumeration rep clause for subtype", N);
6690 -- Ignore duplicate rep clause
6692 elsif Has_Enumeration_Rep_Clause (Enumtype) then
6693 Error_Msg_N ("duplicate enumeration rep clause ignored", N);
6696 -- Don't allow rep clause for standard [wide_[wide_]]character
6698 elsif Is_Standard_Character_Type (Enumtype) then
6699 Error_Msg_N ("enumeration rep clause not allowed for this type", N);
6702 -- Check that the expression is a proper aggregate (no parentheses)
6704 elsif Paren_Count (Aggr) /= 0 then
6706 ("extra parentheses surrounding aggregate not allowed",
6710 -- All tests passed, so set rep clause in place
6713 Set_Has_Enumeration_Rep_Clause (Enumtype);
6714 Set_Has_Enumeration_Rep_Clause (Base_Type (Enumtype));
6717 -- Now we process the aggregate. Note that we don't use the normal
6718 -- aggregate code for this purpose, because we don't want any of the
6719 -- normal expansion activities, and a number of special semantic
6720 -- rules apply (including the component type being any integer type)
6722 Elit := First_Literal (Enumtype);
6724 -- First the positional entries if any
6726 if Present (Expressions (Aggr)) then
6727 Expr := First (Expressions (Aggr));
6728 while Present (Expr) loop
6730 Error_Msg_N ("too many entries in aggregate", Expr);
6734 Val := Static_Integer (Expr);
6736 -- Err signals that we found some incorrect entries processing
6737 -- the list. The final checks for completeness and ordering are
6738 -- skipped in this case.
6740 if Val = No_Uint then
6743 elsif Val < Lo or else Hi < Val then
6744 Error_Msg_N ("value outside permitted range", Expr);
6748 Set_Enumeration_Rep (Elit, Val);
6749 Set_Enumeration_Rep_Expr (Elit, Expr);
6755 -- Now process the named entries if present
6757 if Present (Component_Associations (Aggr)) then
6758 Assoc := First (Component_Associations (Aggr));
6759 while Present (Assoc) loop
6760 Choice := First (Choices (Assoc));
6762 if Present (Next (Choice)) then
6764 ("multiple choice not allowed here", Next (Choice));
6768 if Nkind (Choice) = N_Others_Choice then
6769 Error_Msg_N ("others choice not allowed here", Choice);
6772 elsif Nkind (Choice) = N_Range then
6774 -- ??? should allow zero/one element range here
6776 Error_Msg_N ("range not allowed here", Choice);
6780 Analyze_And_Resolve (Choice, Enumtype);
6782 if Error_Posted (Choice) then
6787 if Is_Entity_Name (Choice)
6788 and then Is_Type (Entity (Choice))
6790 Error_Msg_N ("subtype name not allowed here", Choice);
6793 -- ??? should allow static subtype with zero/one entry
6795 elsif Etype (Choice) = Base_Type (Enumtype) then
6796 if not Is_OK_Static_Expression (Choice) then
6797 Flag_Non_Static_Expr
6798 ("non-static expression used for choice!", Choice);
6802 Elit := Expr_Value_E (Choice);
6804 if Present (Enumeration_Rep_Expr (Elit)) then
6806 Sloc (Enumeration_Rep_Expr (Elit));
6808 ("representation for& previously given#",
6813 Set_Enumeration_Rep_Expr (Elit, Expression (Assoc));
6815 Expr := Expression (Assoc);
6816 Val := Static_Integer (Expr);
6818 if Val = No_Uint then
6821 elsif Val < Lo or else Hi < Val then
6822 Error_Msg_N ("value outside permitted range", Expr);
6826 Set_Enumeration_Rep (Elit, Val);
6836 -- Aggregate is fully processed. Now we check that a full set of
6837 -- representations was given, and that they are in range and in order.
6838 -- These checks are only done if no other errors occurred.
6844 Elit := First_Literal (Enumtype);
6845 while Present (Elit) loop
6846 if No (Enumeration_Rep_Expr (Elit)) then
6847 Error_Msg_NE ("missing representation for&!", N, Elit);
6850 Val := Enumeration_Rep (Elit);
6852 if Min = No_Uint then
6856 if Val /= No_Uint then
6857 if Max /= No_Uint and then Val <= Max then
6859 ("enumeration value for& not ordered!",
6860 Enumeration_Rep_Expr (Elit), Elit);
6863 Max_Node := Enumeration_Rep_Expr (Elit);
6867 -- If there is at least one literal whose representation is not
6868 -- equal to the Pos value, then note that this enumeration type
6869 -- has a non-standard representation.
6871 if Val /= Enumeration_Pos (Elit) then
6872 Set_Has_Non_Standard_Rep (Base_Type (Enumtype));
6879 -- Now set proper size information
6882 Minsize : Uint := UI_From_Int (Minimum_Size (Enumtype));
6885 if Has_Size_Clause (Enumtype) then
6887 -- All OK, if size is OK now
6889 if RM_Size (Enumtype) >= Minsize then
6893 -- Try if we can get by with biasing
6896 UI_From_Int (Minimum_Size (Enumtype, Biased => True));
6898 -- Error message if even biasing does not work
6900 if RM_Size (Enumtype) < Minsize then
6901 Error_Msg_Uint_1 := RM_Size (Enumtype);
6902 Error_Msg_Uint_2 := Max;
6904 ("previously given size (^) is too small "
6905 & "for this value (^)", Max_Node);
6907 -- If biasing worked, indicate that we now have biased rep
6911 (Enumtype, Size_Clause (Enumtype), "size clause");
6916 Set_RM_Size (Enumtype, Minsize);
6917 Set_Enum_Esize (Enumtype);
6920 Set_RM_Size (Base_Type (Enumtype), RM_Size (Enumtype));
6921 Set_Esize (Base_Type (Enumtype), Esize (Enumtype));
6922 Set_Alignment (Base_Type (Enumtype), Alignment (Enumtype));
6926 -- We repeat the too late test in case it froze itself
6928 if Rep_Item_Too_Late (Enumtype, N) then
6931 end Analyze_Enumeration_Representation_Clause;
6933 ----------------------------
6934 -- Analyze_Free_Statement --
6935 ----------------------------
6937 procedure Analyze_Free_Statement (N : Node_Id) is
6939 Analyze (Expression (N));
6940 end Analyze_Free_Statement;
6942 ---------------------------
6943 -- Analyze_Freeze_Entity --
6944 ---------------------------
6946 procedure Analyze_Freeze_Entity (N : Node_Id) is
6948 Freeze_Entity_Checks (N);
6949 end Analyze_Freeze_Entity;
6951 -----------------------------------
6952 -- Analyze_Freeze_Generic_Entity --
6953 -----------------------------------
6955 procedure Analyze_Freeze_Generic_Entity (N : Node_Id) is
6956 E : constant Entity_Id := Entity (N);
6959 if not Is_Frozen (E) and then Has_Delayed_Aspects (E) then
6960 Analyze_Aspects_At_Freeze_Point (E);
6963 Freeze_Entity_Checks (N);
6964 end Analyze_Freeze_Generic_Entity;
6966 ------------------------------------------
6967 -- Analyze_Record_Representation_Clause --
6968 ------------------------------------------
6970 -- Note: we check as much as we can here, but we can't do any checks
6971 -- based on the position values (e.g. overlap checks) until freeze time
6972 -- because especially in Ada 2005 (machine scalar mode), the processing
6973 -- for non-standard bit order can substantially change the positions.
6974 -- See procedure Check_Record_Representation_Clause (called from Freeze)
6975 -- for the remainder of this processing.
6977 procedure Analyze_Record_Representation_Clause (N : Node_Id) is
6978 Ident : constant Node_Id := Identifier (N);
6986 Rectype : Entity_Id;
6989 function Is_Inherited (Comp : Entity_Id) return Boolean;
6990 -- True if Comp is an inherited component in a record extension
6996 function Is_Inherited (Comp : Entity_Id) return Boolean is
6997 Comp_Base : Entity_Id;
7000 if Ekind (Rectype) = E_Record_Subtype then
7001 Comp_Base := Original_Record_Component (Comp);
7006 return Comp_Base /= Original_Record_Component (Comp_Base);
7011 Is_Record_Extension : Boolean;
7012 -- True if Rectype is a record extension
7014 CR_Pragma : Node_Id := Empty;
7015 -- Points to N_Pragma node if Complete_Representation pragma present
7017 -- Start of processing for Analyze_Record_Representation_Clause
7020 if Ignore_Rep_Clauses then
7021 Kill_Rep_Clause (N);
7026 Rectype := Entity (Ident);
7028 if Rectype = Any_Type or else Rep_Item_Too_Early (Rectype, N) then
7031 Rectype := Underlying_Type (Rectype);
7034 -- First some basic error checks
7036 if not Is_Record_Type (Rectype) then
7038 ("record type required, found}", Ident, First_Subtype (Rectype));
7041 elsif Scope (Rectype) /= Current_Scope then
7042 Error_Msg_N ("type must be declared in this scope", N);
7045 elsif not Is_First_Subtype (Rectype) then
7046 Error_Msg_N ("cannot give record rep clause for subtype", N);
7049 elsif Has_Record_Rep_Clause (Rectype) then
7050 Error_Msg_N ("duplicate record rep clause ignored", N);
7053 elsif Rep_Item_Too_Late (Rectype, N) then
7057 -- We know we have a first subtype, now possibly go to the anonymous
7058 -- base type to determine whether Rectype is a record extension.
7060 Recdef := Type_Definition (Declaration_Node (Base_Type (Rectype)));
7061 Is_Record_Extension :=
7062 Nkind (Recdef) = N_Derived_Type_Definition
7063 and then Present (Record_Extension_Part (Recdef));
7065 if Present (Mod_Clause (N)) then
7067 Loc : constant Source_Ptr := Sloc (N);
7068 M : constant Node_Id := Mod_Clause (N);
7069 P : constant List_Id := Pragmas_Before (M);
7073 pragma Warnings (Off, Mod_Val);
7076 Check_Restriction (No_Obsolescent_Features, Mod_Clause (N));
7078 if Warn_On_Obsolescent_Feature then
7080 ("?j?mod clause is an obsolescent feature (RM J.8)", N);
7082 ("\?j?use alignment attribute definition clause instead", N);
7089 -- In ASIS_Mode mode, expansion is disabled, but we must convert
7090 -- the Mod clause into an alignment clause anyway, so that the
7091 -- back end can compute and back-annotate properly the size and
7092 -- alignment of types that may include this record.
7094 -- This seems dubious, this destroys the source tree in a manner
7095 -- not detectable by ASIS ???
7097 if Operating_Mode = Check_Semantics and then ASIS_Mode then
7099 Make_Attribute_Definition_Clause (Loc,
7100 Name => New_Occurrence_Of (Base_Type (Rectype), Loc),
7101 Chars => Name_Alignment,
7102 Expression => Relocate_Node (Expression (M)));
7104 Set_From_At_Mod (AtM_Nod);
7105 Insert_After (N, AtM_Nod);
7106 Mod_Val := Get_Alignment_Value (Expression (AtM_Nod));
7107 Set_Mod_Clause (N, Empty);
7110 -- Get the alignment value to perform error checking
7112 Mod_Val := Get_Alignment_Value (Expression (M));
7117 -- For untagged types, clear any existing component clauses for the
7118 -- type. If the type is derived, this is what allows us to override
7119 -- a rep clause for the parent. For type extensions, the representation
7120 -- of the inherited components is inherited, so we want to keep previous
7121 -- component clauses for completeness.
7123 if not Is_Tagged_Type (Rectype) then
7124 Comp := First_Component_Or_Discriminant (Rectype);
7125 while Present (Comp) loop
7126 Set_Component_Clause (Comp, Empty);
7127 Next_Component_Or_Discriminant (Comp);
7131 -- All done if no component clauses
7133 CC := First (Component_Clauses (N));
7139 -- A representation like this applies to the base type
7141 Set_Has_Record_Rep_Clause (Base_Type (Rectype));
7142 Set_Has_Non_Standard_Rep (Base_Type (Rectype));
7143 Set_Has_Specified_Layout (Base_Type (Rectype));
7145 -- Process the component clauses
7147 while Present (CC) loop
7151 if Nkind (CC) = N_Pragma then
7154 -- The only pragma of interest is Complete_Representation
7156 if Pragma_Name (CC) = Name_Complete_Representation then
7160 -- Processing for real component clause
7163 Posit := Static_Integer (Position (CC));
7164 Fbit := Static_Integer (First_Bit (CC));
7165 Lbit := Static_Integer (Last_Bit (CC));
7168 and then Fbit /= No_Uint
7169 and then Lbit /= No_Uint
7172 Error_Msg_N ("position cannot be negative", Position (CC));
7175 Error_Msg_N ("first bit cannot be negative", First_Bit (CC));
7177 -- The Last_Bit specified in a component clause must not be
7178 -- less than the First_Bit minus one (RM-13.5.1(10)).
7180 elsif Lbit < Fbit - 1 then
7182 ("last bit cannot be less than first bit minus one",
7185 -- Values look OK, so find the corresponding record component
7186 -- Even though the syntax allows an attribute reference for
7187 -- implementation-defined components, GNAT does not allow the
7188 -- tag to get an explicit position.
7190 elsif Nkind (Component_Name (CC)) = N_Attribute_Reference then
7191 if Attribute_Name (Component_Name (CC)) = Name_Tag then
7192 Error_Msg_N ("position of tag cannot be specified", CC);
7194 Error_Msg_N ("illegal component name", CC);
7198 Comp := First_Entity (Rectype);
7199 while Present (Comp) loop
7200 exit when Chars (Comp) = Chars (Component_Name (CC));
7206 -- Maybe component of base type that is absent from
7207 -- statically constrained first subtype.
7209 Comp := First_Entity (Base_Type (Rectype));
7210 while Present (Comp) loop
7211 exit when Chars (Comp) = Chars (Component_Name (CC));
7218 ("component clause is for non-existent field", CC);
7220 -- Ada 2012 (AI05-0026): Any name that denotes a
7221 -- discriminant of an object of an unchecked union type
7222 -- shall not occur within a record_representation_clause.
7224 -- The general restriction of using record rep clauses on
7225 -- Unchecked_Union types has now been lifted. Since it is
7226 -- possible to introduce a record rep clause which mentions
7227 -- the discriminant of an Unchecked_Union in non-Ada 2012
7228 -- code, this check is applied to all versions of the
7231 elsif Ekind (Comp) = E_Discriminant
7232 and then Is_Unchecked_Union (Rectype)
7235 ("cannot reference discriminant of unchecked union",
7236 Component_Name (CC));
7238 elsif Is_Record_Extension and then Is_Inherited (Comp) then
7240 ("component clause not allowed for inherited "
7241 & "component&", CC, Comp);
7243 elsif Present (Component_Clause (Comp)) then
7245 -- Diagnose duplicate rep clause, or check consistency
7246 -- if this is an inherited component. In a double fault,
7247 -- there may be a duplicate inconsistent clause for an
7248 -- inherited component.
7250 if Scope (Original_Record_Component (Comp)) = Rectype
7251 or else Parent (Component_Clause (Comp)) = N
7253 Error_Msg_Sloc := Sloc (Component_Clause (Comp));
7254 Error_Msg_N ("component clause previously given#", CC);
7258 Rep1 : constant Node_Id := Component_Clause (Comp);
7260 if Intval (Position (Rep1)) /=
7261 Intval (Position (CC))
7262 or else Intval (First_Bit (Rep1)) /=
7263 Intval (First_Bit (CC))
7264 or else Intval (Last_Bit (Rep1)) /=
7265 Intval (Last_Bit (CC))
7268 ("component clause inconsistent with "
7269 & "representation of ancestor", CC);
7271 elsif Warn_On_Redundant_Constructs then
7273 ("?r?redundant confirming component clause "
7274 & "for component!", CC);
7279 -- Normal case where this is the first component clause we
7280 -- have seen for this entity, so set it up properly.
7283 -- Make reference for field in record rep clause and set
7284 -- appropriate entity field in the field identifier.
7287 (Comp, Component_Name (CC), Set_Ref => False);
7288 Set_Entity (Component_Name (CC), Comp);
7290 -- Update Fbit and Lbit to the actual bit number
7292 Fbit := Fbit + UI_From_Int (SSU) * Posit;
7293 Lbit := Lbit + UI_From_Int (SSU) * Posit;
7295 if Has_Size_Clause (Rectype)
7296 and then RM_Size (Rectype) <= Lbit
7299 ("bit number out of range of specified size",
7302 Set_Component_Clause (Comp, CC);
7303 Set_Component_Bit_Offset (Comp, Fbit);
7304 Set_Esize (Comp, 1 + (Lbit - Fbit));
7305 Set_Normalized_First_Bit (Comp, Fbit mod SSU);
7306 Set_Normalized_Position (Comp, Fbit / SSU);
7308 Set_Normalized_Position_Max
7309 (Comp, Normalized_Position (Comp));
7311 if Warn_On_Overridden_Size
7312 and then Has_Size_Clause (Etype (Comp))
7313 and then RM_Size (Etype (Comp)) /= Esize (Comp)
7316 ("?S?component size overrides size clause for&",
7317 Component_Name (CC), Etype (Comp));
7321 (Component_Name (CC),
7327 (Comp, First_Node (CC), "component clause", Biased);
7329 -- This information is also set in the corresponding
7330 -- component of the base type, found by accessing the
7331 -- Original_Record_Component link if it is present.
7333 Ocomp := Original_Record_Component (Comp);
7335 if Present (Ocomp) and then Ocomp /= Comp then
7336 Set_Component_Clause (Ocomp, CC);
7337 Set_Component_Bit_Offset (Ocomp, Fbit);
7338 Set_Esize (Ocomp, 1 + (Lbit - Fbit));
7339 Set_Normalized_First_Bit (Ocomp, Fbit mod SSU);
7340 Set_Normalized_Position (Ocomp, Fbit / SSU);
7342 Set_Normalized_Position_Max
7343 (Ocomp, Normalized_Position (Ocomp));
7345 -- Note: we don't use Set_Biased here, because we
7346 -- already gave a warning above if needed, and we
7347 -- would get a duplicate for the same name here.
7349 Set_Has_Biased_Representation
7350 (Ocomp, Has_Biased_Representation (Comp));
7353 if Esize (Comp) < 0 then
7354 Error_Msg_N ("component size is negative", CC);
7365 -- Check missing components if Complete_Representation pragma appeared
7367 if Present (CR_Pragma) then
7368 Comp := First_Component_Or_Discriminant (Rectype);
7369 while Present (Comp) loop
7370 if No (Component_Clause (Comp)) then
7372 ("missing component clause for &", CR_Pragma, Comp);
7375 Next_Component_Or_Discriminant (Comp);
7378 -- Give missing components warning if required
7380 elsif Warn_On_Unrepped_Components then
7382 Num_Repped_Components : Nat := 0;
7383 Num_Unrepped_Components : Nat := 0;
7386 -- First count number of repped and unrepped components
7388 Comp := First_Component_Or_Discriminant (Rectype);
7389 while Present (Comp) loop
7390 if Present (Component_Clause (Comp)) then
7391 Num_Repped_Components := Num_Repped_Components + 1;
7393 Num_Unrepped_Components := Num_Unrepped_Components + 1;
7396 Next_Component_Or_Discriminant (Comp);
7399 -- We are only interested in the case where there is at least one
7400 -- unrepped component, and at least half the components have rep
7401 -- clauses. We figure that if less than half have them, then the
7402 -- partial rep clause is really intentional. If the component
7403 -- type has no underlying type set at this point (as for a generic
7404 -- formal type), we don't know enough to give a warning on the
7407 if Num_Unrepped_Components > 0
7408 and then Num_Unrepped_Components < Num_Repped_Components
7410 Comp := First_Component_Or_Discriminant (Rectype);
7411 while Present (Comp) loop
7412 if No (Component_Clause (Comp))
7413 and then Comes_From_Source (Comp)
7414 and then Present (Underlying_Type (Etype (Comp)))
7415 and then (Is_Scalar_Type (Underlying_Type (Etype (Comp)))
7416 or else Size_Known_At_Compile_Time
7417 (Underlying_Type (Etype (Comp))))
7418 and then not Has_Warnings_Off (Rectype)
7420 -- Ignore discriminant in unchecked union, since it is
7421 -- not there, and cannot have a component clause.
7423 and then (not Is_Unchecked_Union (Rectype)
7424 or else Ekind (Comp) /= E_Discriminant)
7426 Error_Msg_Sloc := Sloc (Comp);
7428 ("?C?no component clause given for & declared #",
7432 Next_Component_Or_Discriminant (Comp);
7437 end Analyze_Record_Representation_Clause;
7439 -------------------------------------
7440 -- Build_Discrete_Static_Predicate --
7441 -------------------------------------
7443 procedure Build_Discrete_Static_Predicate
7448 Loc : constant Source_Ptr := Sloc (Expr);
7450 Non_Static : exception;
7451 -- Raised if something non-static is found
7453 Btyp : constant Entity_Id := Base_Type (Typ);
7455 BLo : constant Uint := Expr_Value (Type_Low_Bound (Btyp));
7456 BHi : constant Uint := Expr_Value (Type_High_Bound (Btyp));
7457 -- Low bound and high bound value of base type of Typ
7461 -- Bounds for constructing the static predicate. We use the bound of the
7462 -- subtype if it is static, otherwise the corresponding base type bound.
7463 -- Note: a non-static subtype can have a static predicate.
7468 -- One entry in a Rlist value, a single REnt (range entry) value denotes
7469 -- one range from Lo to Hi. To represent a single value range Lo = Hi =
7472 type RList is array (Nat range <>) of REnt;
7473 -- A list of ranges. The ranges are sorted in increasing order, and are
7474 -- disjoint (there is a gap of at least one value between each range in
7475 -- the table). A value is in the set of ranges in Rlist if it lies
7476 -- within one of these ranges.
7478 False_Range : constant RList :=
7479 RList'(1 .. 0 => REnt'(No_Uint, No_Uint));
7480 -- An empty set of ranges represents a range list that can never be
7481 -- satisfied, since there are no ranges in which the value could lie,
7482 -- so it does not lie in any of them. False_Range is a canonical value
7483 -- for this empty set, but general processing should test for an Rlist
7484 -- with length zero (see Is_False predicate), since other null ranges
7485 -- may appear which must be treated as False.
7487 True_Range : constant RList := RList'(1 => REnt'(BLo, BHi));
7488 -- Range representing True, value must be in the base range
7490 function "and" (Left : RList; Right : RList) return RList;
7491 -- And's together two range lists, returning a range list. This is a set
7492 -- intersection operation.
7494 function "or" (Left : RList; Right : RList) return RList;
7495 -- Or's together two range lists, returning a range list. This is a set
7498 function "not" (Right : RList) return RList;
7499 -- Returns complement of a given range list, i.e. a range list
7500 -- representing all the values in TLo .. THi that are not in the input
7503 function Build_Val (V : Uint) return Node_Id;
7504 -- Return an analyzed N_Identifier node referencing this value, suitable
7505 -- for use as an entry in the Static_Discrte_Predicate list. This node
7506 -- is typed with the base type.
7508 function Build_Range (Lo : Uint; Hi : Uint) return Node_Id;
7509 -- Return an analyzed N_Range node referencing this range, suitable for
7510 -- use as an entry in the Static_Discrete_Predicate list. This node is
7511 -- typed with the base type.
7513 function Get_RList (Exp : Node_Id) return RList;
7514 -- This is a recursive routine that converts the given expression into a
7515 -- list of ranges, suitable for use in building the static predicate.
7517 function Is_False (R : RList) return Boolean;
7518 pragma Inline (Is_False);
7519 -- Returns True if the given range list is empty, and thus represents a
7520 -- False list of ranges that can never be satisfied.
7522 function Is_True (R : RList) return Boolean;
7523 -- Returns True if R trivially represents the True predicate by having a
7524 -- single range from BLo to BHi.
7526 function Is_Type_Ref (N : Node_Id) return Boolean;
7527 pragma Inline (Is_Type_Ref);
7528 -- Returns if True if N is a reference to the type for the predicate in
7529 -- the expression (i.e. if it is an identifier whose Chars field matches
7530 -- the Nam given in the call). N must not be parenthesized, if the type
7531 -- name appears in parens, this routine will return False.
7533 function Lo_Val (N : Node_Id) return Uint;
7534 -- Given an entry from a Static_Discrete_Predicate list that is either
7535 -- a static expression or static range, gets either the expression value
7536 -- or the low bound of the range.
7538 function Hi_Val (N : Node_Id) return Uint;
7539 -- Given an entry from a Static_Discrete_Predicate list that is either
7540 -- a static expression or static range, gets either the expression value
7541 -- or the high bound of the range.
7543 function Membership_Entry (N : Node_Id) return RList;
7544 -- Given a single membership entry (range, value, or subtype), returns
7545 -- the corresponding range list. Raises Static_Error if not static.
7547 function Membership_Entries (N : Node_Id) return RList;
7548 -- Given an element on an alternatives list of a membership operation,
7549 -- returns the range list corresponding to this entry and all following
7550 -- entries (i.e. returns the "or" of this list of values).
7552 function Stat_Pred (Typ : Entity_Id) return RList;
7553 -- Given a type, if it has a static predicate, then return the predicate
7554 -- as a range list, otherwise raise Non_Static.
7560 function "and" (Left : RList; Right : RList) return RList is
7562 -- First range of result
7564 SLeft : Nat := Left'First;
7565 -- Start of rest of left entries
7567 SRight : Nat := Right'First;
7568 -- Start of rest of right entries
7571 -- If either range is True, return the other
7573 if Is_True (Left) then
7575 elsif Is_True (Right) then
7579 -- If either range is False, return False
7581 if Is_False (Left) or else Is_False (Right) then
7585 -- Loop to remove entries at start that are disjoint, and thus just
7586 -- get discarded from the result entirely.
7589 -- If no operands left in either operand, result is false
7591 if SLeft > Left'Last or else SRight > Right'Last then
7594 -- Discard first left operand entry if disjoint with right
7596 elsif Left (SLeft).Hi < Right (SRight).Lo then
7599 -- Discard first right operand entry if disjoint with left
7601 elsif Right (SRight).Hi < Left (SLeft).Lo then
7602 SRight := SRight + 1;
7604 -- Otherwise we have an overlapping entry
7611 -- Now we have two non-null operands, and first entries overlap. The
7612 -- first entry in the result will be the overlapping part of these
7615 FEnt := REnt'(Lo => UI_Max (Left (SLeft).Lo, Right (SRight).Lo),
7616 Hi => UI_Min (Left (SLeft).Hi, Right (SRight).Hi));
7618 -- Now we can remove the entry that ended at a lower value, since its
7619 -- contribution is entirely contained in Fent.
7621 if Left (SLeft).Hi <= Right (SRight).Hi then
7624 SRight := SRight + 1;
7627 -- Compute result by concatenating this first entry with the "and" of
7628 -- the remaining parts of the left and right operands. Note that if
7629 -- either of these is empty, "and" will yield empty, so that we will
7630 -- end up with just Fent, which is what we want in that case.
7633 FEnt & (Left (SLeft .. Left'Last) and Right (SRight .. Right'Last));
7640 function "not" (Right : RList) return RList is
7642 -- Return True if False range
7644 if Is_False (Right) then
7648 -- Return False if True range
7650 if Is_True (Right) then
7654 -- Here if not trivial case
7657 Result : RList (1 .. Right'Length + 1);
7658 -- May need one more entry for gap at beginning and end
7661 -- Number of entries stored in Result
7666 if Right (Right'First).Lo > TLo then
7668 Result (Count) := REnt'(TLo, Right (Right'First).Lo - 1);
7671 -- Gaps between ranges
7673 for J in Right'First .. Right'Last - 1 loop
7675 Result (Count) := REnt'(Right (J).Hi + 1, Right (J + 1).Lo - 1);
7680 if Right (Right'Last).Hi < THi then
7682 Result (Count) := REnt'(Right (Right'Last).Hi + 1, THi);
7685 return Result (1 .. Count);
7693 function "or" (Left : RList; Right : RList) return RList is
7695 -- First range of result
7697 SLeft : Nat := Left'First;
7698 -- Start of rest of left entries
7700 SRight : Nat := Right'First;
7701 -- Start of rest of right entries
7704 -- If either range is True, return True
7706 if Is_True (Left) or else Is_True (Right) then
7710 -- If either range is False (empty), return the other
7712 if Is_False (Left) then
7714 elsif Is_False (Right) then
7718 -- Initialize result first entry from left or right operand depending
7719 -- on which starts with the lower range.
7721 if Left (SLeft).Lo < Right (SRight).Lo then
7722 FEnt := Left (SLeft);
7725 FEnt := Right (SRight);
7726 SRight := SRight + 1;
7729 -- This loop eats ranges from left and right operands that are
7730 -- contiguous with the first range we are gathering.
7733 -- Eat first entry in left operand if contiguous or overlapped by
7734 -- gathered first operand of result.
7736 if SLeft <= Left'Last
7737 and then Left (SLeft).Lo <= FEnt.Hi + 1
7739 FEnt.Hi := UI_Max (FEnt.Hi, Left (SLeft).Hi);
7742 -- Eat first entry in right operand if contiguous or overlapped by
7743 -- gathered right operand of result.
7745 elsif SRight <= Right'Last
7746 and then Right (SRight).Lo <= FEnt.Hi + 1
7748 FEnt.Hi := UI_Max (FEnt.Hi, Right (SRight).Hi);
7749 SRight := SRight + 1;
7751 -- All done if no more entries to eat
7758 -- Obtain result as the first entry we just computed, concatenated
7759 -- to the "or" of the remaining results (if one operand is empty,
7760 -- this will just concatenate with the other
7763 FEnt & (Left (SLeft .. Left'Last) or Right (SRight .. Right'Last));
7770 function Build_Range (Lo : Uint; Hi : Uint) return Node_Id is
7775 Low_Bound => Build_Val (Lo),
7776 High_Bound => Build_Val (Hi));
7777 Set_Etype (Result, Btyp);
7778 Set_Analyzed (Result);
7786 function Build_Val (V : Uint) return Node_Id is
7790 if Is_Enumeration_Type (Typ) then
7791 Result := Get_Enum_Lit_From_Pos (Typ, V, Loc);
7793 Result := Make_Integer_Literal (Loc, V);
7796 Set_Etype (Result, Btyp);
7797 Set_Is_Static_Expression (Result);
7798 Set_Analyzed (Result);
7806 function Get_RList (Exp : Node_Id) return RList is
7811 -- Static expression can only be true or false
7813 if Is_OK_Static_Expression (Exp) then
7814 if Expr_Value (Exp) = 0 then
7821 -- Otherwise test node type
7832 return Get_RList (Left_Opnd (Exp))
7834 Get_RList (Right_Opnd (Exp));
7841 return Get_RList (Left_Opnd (Exp))
7843 Get_RList (Right_Opnd (Exp));
7848 return not Get_RList (Right_Opnd (Exp));
7850 -- Comparisons of type with static value
7852 when N_Op_Compare =>
7854 -- Type is left operand
7856 if Is_Type_Ref (Left_Opnd (Exp))
7857 and then Is_OK_Static_Expression (Right_Opnd (Exp))
7859 Val := Expr_Value (Right_Opnd (Exp));
7861 -- Typ is right operand
7863 elsif Is_Type_Ref (Right_Opnd (Exp))
7864 and then Is_OK_Static_Expression (Left_Opnd (Exp))
7866 Val := Expr_Value (Left_Opnd (Exp));
7868 -- Invert sense of comparison
7871 when N_Op_Gt => Op := N_Op_Lt;
7872 when N_Op_Lt => Op := N_Op_Gt;
7873 when N_Op_Ge => Op := N_Op_Le;
7874 when N_Op_Le => Op := N_Op_Ge;
7875 when others => null;
7878 -- Other cases are non-static
7884 -- Construct range according to comparison operation
7888 return RList'(1 => REnt'(Val, Val));
7891 return RList'(1 => REnt'(Val, BHi));
7894 return RList'(1 => REnt'(Val + 1, BHi));
7897 return RList'(1 => REnt'(BLo, Val));
7900 return RList'(1 => REnt'(BLo, Val - 1));
7903 return RList'(REnt'(BLo, Val - 1), REnt'(Val + 1, BHi));
7906 raise Program_Error;
7912 if not Is_Type_Ref (Left_Opnd (Exp)) then
7916 if Present (Right_Opnd (Exp)) then
7917 return Membership_Entry (Right_Opnd (Exp));
7919 return Membership_Entries (First (Alternatives (Exp)));
7922 -- Negative membership (NOT IN)
7925 if not Is_Type_Ref (Left_Opnd (Exp)) then
7929 if Present (Right_Opnd (Exp)) then
7930 return not Membership_Entry (Right_Opnd (Exp));
7932 return not Membership_Entries (First (Alternatives (Exp)));
7935 -- Function call, may be call to static predicate
7937 when N_Function_Call =>
7938 if Is_Entity_Name (Name (Exp)) then
7940 Ent : constant Entity_Id := Entity (Name (Exp));
7942 if Is_Predicate_Function (Ent)
7944 Is_Predicate_Function_M (Ent)
7946 return Stat_Pred (Etype (First_Formal (Ent)));
7951 -- Other function call cases are non-static
7955 -- Qualified expression, dig out the expression
7957 when N_Qualified_Expression =>
7958 return Get_RList (Expression (Exp));
7960 when N_Case_Expression =>
7967 if not Is_Entity_Name (Expression (Expr))
7968 or else Etype (Expression (Expr)) /= Typ
7971 ("expression must denaote subtype", Expression (Expr));
7975 -- Collect discrete choices in all True alternatives
7977 Choices := New_List;
7978 Alt := First (Alternatives (Exp));
7979 while Present (Alt) loop
7980 Dep := Expression (Alt);
7982 if not Is_OK_Static_Expression (Dep) then
7985 elsif Is_True (Expr_Value (Dep)) then
7986 Append_List_To (Choices,
7987 New_Copy_List (Discrete_Choices (Alt)));
7993 return Membership_Entries (First (Choices));
7996 -- Expression with actions: if no actions, dig out expression
7998 when N_Expression_With_Actions =>
7999 if Is_Empty_List (Actions (Exp)) then
8000 return Get_RList (Expression (Exp));
8008 return (Get_RList (Left_Opnd (Exp))
8009 and not Get_RList (Right_Opnd (Exp)))
8010 or (Get_RList (Right_Opnd (Exp))
8011 and not Get_RList (Left_Opnd (Exp)));
8013 -- Any other node type is non-static
8024 function Hi_Val (N : Node_Id) return Uint is
8026 if Is_OK_Static_Expression (N) then
8027 return Expr_Value (N);
8029 pragma Assert (Nkind (N) = N_Range);
8030 return Expr_Value (High_Bound (N));
8038 function Is_False (R : RList) return Boolean is
8040 return R'Length = 0;
8047 function Is_True (R : RList) return Boolean is
8050 and then R (R'First).Lo = BLo
8051 and then R (R'First).Hi = BHi;
8058 function Is_Type_Ref (N : Node_Id) return Boolean is
8060 return Nkind (N) = N_Identifier
8061 and then Chars (N) = Nam
8062 and then Paren_Count (N) = 0;
8069 function Lo_Val (N : Node_Id) return Uint is
8071 if Is_OK_Static_Expression (N) then
8072 return Expr_Value (N);
8074 pragma Assert (Nkind (N) = N_Range);
8075 return Expr_Value (Low_Bound (N));
8079 ------------------------
8080 -- Membership_Entries --
8081 ------------------------
8083 function Membership_Entries (N : Node_Id) return RList is
8085 if No (Next (N)) then
8086 return Membership_Entry (N);
8088 return Membership_Entry (N) or Membership_Entries (Next (N));
8090 end Membership_Entries;
8092 ----------------------
8093 -- Membership_Entry --
8094 ----------------------
8096 function Membership_Entry (N : Node_Id) return RList is
8104 if Nkind (N) = N_Range then
8105 if not Is_OK_Static_Expression (Low_Bound (N))
8107 not Is_OK_Static_Expression (High_Bound (N))
8111 SLo := Expr_Value (Low_Bound (N));
8112 SHi := Expr_Value (High_Bound (N));
8113 return RList'(1 => REnt'(SLo, SHi));
8116 -- Static expression case
8118 elsif Is_OK_Static_Expression (N) then
8119 Val := Expr_Value (N);
8120 return RList'(1 => REnt'(Val, Val));
8122 -- Identifier (other than static expression) case
8124 else pragma Assert (Nkind (N) = N_Identifier);
8128 if Is_Type (Entity (N)) then
8130 -- If type has predicates, process them
8132 if Has_Predicates (Entity (N)) then
8133 return Stat_Pred (Entity (N));
8135 -- For static subtype without predicates, get range
8137 elsif Is_OK_Static_Subtype (Entity (N)) then
8138 SLo := Expr_Value (Type_Low_Bound (Entity (N)));
8139 SHi := Expr_Value (Type_High_Bound (Entity (N)));
8140 return RList'(1 => REnt'(SLo, SHi));
8142 -- Any other type makes us non-static
8148 -- Any other kind of identifier in predicate (e.g. a non-static
8149 -- expression value) means this is not a static predicate.
8155 end Membership_Entry;
8161 function Stat_Pred (Typ : Entity_Id) return RList is
8163 -- Not static if type does not have static predicates
8165 if not Has_Static_Predicate (Typ) then
8169 -- Otherwise we convert the predicate list to a range list
8172 Spred : constant List_Id := Static_Discrete_Predicate (Typ);
8173 Result : RList (1 .. List_Length (Spred));
8177 P := First (Static_Discrete_Predicate (Typ));
8178 for J in Result'Range loop
8179 Result (J) := REnt'(Lo_Val (P), Hi_Val (P));
8187 -- Start of processing for Build_Discrete_Static_Predicate
8190 -- Establish bounds for the predicate
8192 if Compile_Time_Known_Value (Type_Low_Bound (Typ)) then
8193 TLo := Expr_Value (Type_Low_Bound (Typ));
8198 if Compile_Time_Known_Value (Type_High_Bound (Typ)) then
8199 THi := Expr_Value (Type_High_Bound (Typ));
8204 -- Analyze the expression to see if it is a static predicate
8207 Ranges : constant RList := Get_RList (Expr);
8208 -- Range list from expression if it is static
8213 -- Convert range list into a form for the static predicate. In the
8214 -- Ranges array, we just have raw ranges, these must be converted
8215 -- to properly typed and analyzed static expressions or range nodes.
8217 -- Note: here we limit ranges to the ranges of the subtype, so that
8218 -- a predicate is always false for values outside the subtype. That
8219 -- seems fine, such values are invalid anyway, and considering them
8220 -- to fail the predicate seems allowed and friendly, and furthermore
8221 -- simplifies processing for case statements and loops.
8225 for J in Ranges'Range loop
8227 Lo : Uint := Ranges (J).Lo;
8228 Hi : Uint := Ranges (J).Hi;
8231 -- Ignore completely out of range entry
8233 if Hi < TLo or else Lo > THi then
8236 -- Otherwise process entry
8239 -- Adjust out of range value to subtype range
8249 -- Convert range into required form
8251 Append_To (Plist, Build_Range (Lo, Hi));
8256 -- Processing was successful and all entries were static, so now we
8257 -- can store the result as the predicate list.
8259 Set_Static_Discrete_Predicate (Typ, Plist);
8261 -- Within a generic the predicate functions themselves need not
8264 if Inside_A_Generic then
8268 -- The processing for static predicates put the expression into
8269 -- canonical form as a series of ranges. It also eliminated
8270 -- duplicates and collapsed and combined ranges. We might as well
8271 -- replace the alternatives list of the right operand of the
8272 -- membership test with the static predicate list, which will
8273 -- usually be more efficient.
8276 New_Alts : constant List_Id := New_List;
8281 Old_Node := First (Plist);
8282 while Present (Old_Node) loop
8283 New_Node := New_Copy (Old_Node);
8285 if Nkind (New_Node) = N_Range then
8286 Set_Low_Bound (New_Node, New_Copy (Low_Bound (Old_Node)));
8287 Set_High_Bound (New_Node, New_Copy (High_Bound (Old_Node)));
8290 Append_To (New_Alts, New_Node);
8294 -- If empty list, replace by False
8296 if Is_Empty_List (New_Alts) then
8297 Rewrite (Expr, New_Occurrence_Of (Standard_False, Loc));
8299 -- Else replace by set membership test
8304 Left_Opnd => Make_Identifier (Loc, Nam),
8305 Right_Opnd => Empty,
8306 Alternatives => New_Alts));
8308 -- Resolve new expression in function context
8310 Install_Formals (Predicate_Function (Typ));
8311 Push_Scope (Predicate_Function (Typ));
8312 Analyze_And_Resolve (Expr, Standard_Boolean);
8318 -- If non-static, return doing nothing
8323 end Build_Discrete_Static_Predicate;
8325 --------------------------------
8326 -- Build_Export_Import_Pragma --
8327 --------------------------------
8329 function Build_Export_Import_Pragma
8331 Id : Entity_Id) return Node_Id
8333 Asp_Id : constant Aspect_Id := Get_Aspect_Id (Asp);
8334 Expr : constant Node_Id := Expression (Asp);
8335 Loc : constant Source_Ptr := Sloc (Asp);
8346 Create_Pragma : Boolean := False;
8347 -- This flag is set when the aspect form is such that it warrants the
8348 -- creation of a corresponding pragma.
8351 if Present (Expr) then
8352 if Error_Posted (Expr) then
8355 elsif Is_True (Expr_Value (Expr)) then
8356 Create_Pragma := True;
8359 -- Otherwise the aspect defaults to True
8362 Create_Pragma := True;
8365 -- Nothing to do when the expression is False or is erroneous
8367 if not Create_Pragma then
8371 -- Obtain all interfacing aspects that apply to the related entity
8373 Get_Interfacing_Aspects
8377 Expo_Asp => Dummy_1,
8383 -- Handle the convention argument
8385 if Present (Conv) then
8386 Conv_Arg := New_Copy_Tree (Expression (Conv));
8388 -- Assume convention "Ada' when aspect Convention is missing
8391 Conv_Arg := Make_Identifier (Loc, Name_Ada);
8395 Make_Pragma_Argument_Association (Loc,
8396 Chars => Name_Convention,
8397 Expression => Conv_Arg));
8399 -- Handle the entity argument
8402 Make_Pragma_Argument_Association (Loc,
8403 Chars => Name_Entity,
8404 Expression => New_Occurrence_Of (Id, Loc)));
8406 -- Handle the External_Name argument
8408 if Present (EN) then
8410 Make_Pragma_Argument_Association (Loc,
8411 Chars => Name_External_Name,
8412 Expression => New_Copy_Tree (Expression (EN))));
8415 -- Handle the Link_Name argument
8417 if Present (LN) then
8419 Make_Pragma_Argument_Association (Loc,
8420 Chars => Name_Link_Name,
8421 Expression => New_Copy_Tree (Expression (LN))));
8425 -- pragma Export/Import
8426 -- (Convention => <Conv>/Ada,
8428 -- [External_Name => <EN>,]
8429 -- [Link_Name => <LN>]);
8433 Pragma_Identifier =>
8434 Make_Identifier (Loc, Chars (Identifier (Asp))),
8435 Pragma_Argument_Associations => Args);
8437 -- Decorate the relevant aspect and the pragma
8439 Set_Aspect_Rep_Item (Asp, Prag);
8441 Set_Corresponding_Aspect (Prag, Asp);
8442 Set_From_Aspect_Specification (Prag);
8443 Set_Parent (Prag, Asp);
8445 if Asp_Id = Aspect_Import and then Is_Subprogram (Id) then
8446 Set_Import_Pragma (Id, Prag);
8450 end Build_Export_Import_Pragma;
8452 -------------------------------
8453 -- Build_Predicate_Functions --
8454 -------------------------------
8456 -- The functions that are constructed here have the form:
8458 -- function typPredicate (Ixxx : typ) return Boolean is
8461 -- typ1Predicate (typ1 (Ixxx))
8462 -- and then typ2Predicate (typ2 (Ixxx))
8464 -- and then exp1 and then exp2 and then ...;
8465 -- end typPredicate;
8467 -- Here exp1, and exp2 are expressions from Predicate pragmas. Note that
8468 -- this is the point at which these expressions get analyzed, providing the
8469 -- required delay, and typ1, typ2, are entities from which predicates are
8470 -- inherited. Note that we do NOT generate Check pragmas, that's because we
8471 -- use this function even if checks are off, e.g. for membership tests.
8473 -- Note that the inherited predicates are evaluated first, as required by
8476 -- Note that Sem_Eval.Real_Or_String_Static_Predicate_Matches depends on
8477 -- the form of this return expression.
8479 -- If the expression has at least one Raise_Expression, then we also build
8480 -- the typPredicateM version of the function, in which any occurrence of a
8481 -- Raise_Expression is converted to "return False".
8483 -- WARNING: This routine manages Ghost regions. Return statements must be
8484 -- replaced by gotos which jump to the end of the routine and restore the
8487 procedure Build_Predicate_Functions (Typ : Entity_Id; N : Node_Id) is
8488 Loc : constant Source_Ptr := Sloc (Typ);
8491 -- This is the expression for the result of the function. It is
8492 -- is build by connecting the component predicates with AND THEN.
8494 Expr_M : Node_Id := Empty; -- init to avoid warning
8495 -- This is the corresponding return expression for the Predicate_M
8496 -- function. It differs in that raise expressions are marked for
8497 -- special expansion (see Process_REs).
8499 Object_Name : Name_Id;
8500 -- Name for argument of Predicate procedure. Note that we use the same
8501 -- name for both predicate functions. That way the reference within the
8502 -- predicate expression is the same in both functions.
8504 Object_Entity : Entity_Id;
8505 -- Entity for argument of Predicate procedure
8507 Object_Entity_M : Entity_Id;
8508 -- Entity for argument of separate Predicate procedure when exceptions
8509 -- are present in expression.
8512 -- The function declaration
8517 Raise_Expression_Present : Boolean := False;
8518 -- Set True if Expr has at least one Raise_Expression
8520 procedure Add_Condition (Cond : Node_Id);
8521 -- Append Cond to Expr using "and then" (or just copy Cond to Expr if
8524 procedure Add_Predicates;
8525 -- Appends expressions for any Predicate pragmas in the rep item chain
8526 -- Typ to Expr. Note that we look only at items for this exact entity.
8527 -- Inheritance of predicates for the parent type is done by calling the
8528 -- Predicate_Function of the parent type, using Add_Call above.
8530 procedure Add_Call (T : Entity_Id);
8531 -- Includes a call to the predicate function for type T in Expr if T
8532 -- has predicates and Predicate_Function (T) is non-empty.
8534 function Process_RE (N : Node_Id) return Traverse_Result;
8535 -- Used in Process REs, tests if node N is a raise expression, and if
8536 -- so, marks it to be converted to return False.
8538 procedure Process_REs is new Traverse_Proc (Process_RE);
8539 -- Marks any raise expressions in Expr_M to return False
8541 function Test_RE (N : Node_Id) return Traverse_Result;
8542 -- Used in Test_REs, tests one node for being a raise expression, and if
8543 -- so sets Raise_Expression_Present True.
8545 procedure Test_REs is new Traverse_Proc (Test_RE);
8546 -- Tests to see if Expr contains any raise expressions
8552 procedure Add_Call (T : Entity_Id) is
8556 if Present (T) and then Present (Predicate_Function (T)) then
8557 Set_Has_Predicates (Typ);
8559 -- Build the call to the predicate function of T. The type may be
8560 -- derived, so use an unchecked conversion for the actual.
8566 Unchecked_Convert_To (T,
8567 Make_Identifier (Loc, Object_Name)));
8569 -- "and"-in the call to evolving expression
8571 Add_Condition (Exp);
8573 -- Output info message on inheritance if required. Note we do not
8574 -- give this information for generic actual types, since it is
8575 -- unwelcome noise in that case in instantiations. We also
8576 -- generally suppress the message in instantiations, and also
8577 -- if it involves internal names.
8579 if Opt.List_Inherited_Aspects
8580 and then not Is_Generic_Actual_Type (Typ)
8581 and then Instantiation_Depth (Sloc (Typ)) = 0
8582 and then not Is_Internal_Name (Chars (T))
8583 and then not Is_Internal_Name (Chars (Typ))
8585 Error_Msg_Sloc := Sloc (Predicate_Function (T));
8586 Error_Msg_Node_2 := T;
8587 Error_Msg_N ("info: & inherits predicate from & #?L?", Typ);
8596 procedure Add_Condition (Cond : Node_Id) is
8598 -- This is the first predicate expression
8603 -- Otherwise concatenate to the existing predicate expressions by
8604 -- using "and then".
8609 Left_Opnd => Relocate_Node (Expr),
8610 Right_Opnd => Cond);
8614 --------------------
8615 -- Add_Predicates --
8616 --------------------
8618 procedure Add_Predicates is
8619 procedure Add_Predicate (Prag : Node_Id);
8620 -- Concatenate the expression of predicate pragma Prag to Expr by
8621 -- using a short circuit "and then" operator.
8627 procedure Add_Predicate (Prag : Node_Id) is
8628 procedure Replace_Type_Reference (N : Node_Id);
8629 -- Replace a single occurrence N of the subtype name with a
8630 -- reference to the formal of the predicate function. N can be an
8631 -- identifier referencing the subtype, or a selected component,
8632 -- representing an appropriately qualified occurrence of the
8635 procedure Replace_Type_References is
8636 new Replace_Type_References_Generic (Replace_Type_Reference);
8637 -- Traverse an expression changing every occurrence of an
8638 -- identifier whose name matches the name of the subtype with a
8639 -- reference to the formal parameter of the predicate function.
8641 ----------------------------
8642 -- Replace_Type_Reference --
8643 ----------------------------
8645 procedure Replace_Type_Reference (N : Node_Id) is
8647 Rewrite (N, Make_Identifier (Sloc (N), Object_Name));
8648 -- Use the Sloc of the usage name, not the defining name
8651 Set_Entity (N, Object_Entity);
8653 -- We want to treat the node as if it comes from source, so
8654 -- that ASIS will not ignore it.
8656 Set_Comes_From_Source (N, True);
8657 end Replace_Type_Reference;
8661 Asp : constant Node_Id := Corresponding_Aspect (Prag);
8665 -- Start of processing for Add_Predicate
8668 -- Mark corresponding SCO as enabled
8670 Set_SCO_Pragma_Enabled (Sloc (Prag));
8672 -- Extract the arguments of the pragma. The expression itself
8673 -- is copied for use in the predicate function, to preserve the
8674 -- original version for ASIS use.
8676 Arg1 := First (Pragma_Argument_Associations (Prag));
8677 Arg2 := Next (Arg1);
8679 Arg1 := Get_Pragma_Arg (Arg1);
8680 Arg2 := New_Copy_Tree (Get_Pragma_Arg (Arg2));
8682 -- When the predicate pragma applies to the current type or its
8683 -- full view, replace all occurrences of the subtype name with
8684 -- references to the formal parameter of the predicate function.
8686 if Entity (Arg1) = Typ
8687 or else Full_View (Entity (Arg1)) = Typ
8689 Replace_Type_References (Arg2, Typ);
8691 -- If the predicate pragma comes from an aspect, replace the
8692 -- saved expression because we need the subtype references
8693 -- replaced for the calls to Preanalyze_Spec_Expression in
8694 -- Check_Aspect_At_xxx routines.
8696 if Present (Asp) then
8697 Set_Entity (Identifier (Asp), New_Copy_Tree (Arg2));
8700 -- "and"-in the Arg2 condition to evolving expression
8702 Add_Condition (Relocate_Node (Arg2));
8710 -- Start of processing for Add_Predicates
8713 Ritem := First_Rep_Item (Typ);
8715 -- If the type is private, check whether full view has inherited
8718 if Is_Private_Type (Typ) and then No (Ritem) then
8719 Ritem := First_Rep_Item (Full_View (Typ));
8722 while Present (Ritem) loop
8723 if Nkind (Ritem) = N_Pragma
8724 and then Pragma_Name (Ritem) = Name_Predicate
8726 Add_Predicate (Ritem);
8728 -- If the type is declared in an inner package it may be frozen
8729 -- outside of the package, and the generated pragma has not been
8730 -- analyzed yet, so capture the expression for the predicate
8731 -- function at this point.
8733 elsif Nkind (Ritem) = N_Aspect_Specification
8734 and then Present (Aspect_Rep_Item (Ritem))
8735 and then Scope (Typ) /= Current_Scope
8738 Prag : constant Node_Id := Aspect_Rep_Item (Ritem);
8741 if Nkind (Prag) = N_Pragma
8742 and then Pragma_Name (Prag) = Name_Predicate
8744 Add_Predicate (Prag);
8749 Next_Rep_Item (Ritem);
8757 function Process_RE (N : Node_Id) return Traverse_Result is
8759 if Nkind (N) = N_Raise_Expression then
8760 Set_Convert_To_Return_False (N);
8771 function Test_RE (N : Node_Id) return Traverse_Result is
8773 if Nkind (N) = N_Raise_Expression then
8774 Raise_Expression_Present := True;
8783 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
8784 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
8785 -- Save the Ghost-related attributes to restore on exit
8787 -- Start of processing for Build_Predicate_Functions
8790 -- Return if already built or if type does not have predicates
8792 SId := Predicate_Function (Typ);
8793 if not Has_Predicates (Typ)
8794 or else (Present (SId) and then Has_Completion (SId))
8798 -- Do not generate predicate bodies within a generic unit. The
8799 -- expressions have been analyzed already, and the bodies play
8800 -- no role if not within an executable unit. However, if a statc
8801 -- predicate is present it must be processed for legality checks
8802 -- such as case coverage in an expression.
8804 elsif Inside_A_Generic
8805 and then not Has_Static_Predicate_Aspect (Typ)
8810 -- The related type may be subject to pragma Ghost. Set the mode now to
8811 -- ensure that the predicate functions are properly marked as Ghost.
8813 Set_Ghost_Mode (Typ);
8815 -- Prepare to construct predicate expression
8819 if Present (SId) then
8820 FDecl := Unit_Declaration_Node (SId);
8823 FDecl := Build_Predicate_Function_Declaration (Typ);
8824 SId := Defining_Entity (FDecl);
8827 -- Recover name of formal parameter of function that replaces references
8828 -- to the type in predicate expressions.
8832 (First (Parameter_Specifications (Specification (FDecl))));
8834 Object_Name := Chars (Object_Entity);
8835 Object_Entity_M := Make_Defining_Identifier (Loc, Chars => Object_Name);
8837 -- Add predicates for ancestor if present. These must come before the
8838 -- ones for the current type, as required by AI12-0071-1.
8843 Atyp := Nearest_Ancestor (Typ);
8845 -- The type may be private but the full view may inherit predicates
8847 if No (Atyp) and then Is_Private_Type (Typ) then
8848 Atyp := Nearest_Ancestor (Full_View (Typ));
8851 if Present (Atyp) then
8856 -- Add Predicates for the current type
8860 -- Case where predicates are present
8862 if Present (Expr) then
8864 -- Test for raise expression present
8868 -- If raise expression is present, capture a copy of Expr for use
8869 -- in building the predicateM function version later on. For this
8870 -- copy we replace references to Object_Entity by Object_Entity_M.
8872 if Raise_Expression_Present then
8874 function Reset_Loop_Variable
8875 (N : Node_Id) return Traverse_Result;
8877 procedure Reset_Loop_Variables is
8878 new Traverse_Proc (Reset_Loop_Variable);
8880 ------------------------
8881 -- Reset_Loop_Variable --
8882 ------------------------
8884 function Reset_Loop_Variable
8885 (N : Node_Id) return Traverse_Result
8888 if Nkind (N) = N_Iterator_Specification then
8889 Set_Defining_Identifier (N,
8890 Make_Defining_Identifier
8891 (Sloc (N), Chars (Defining_Identifier (N))));
8895 end Reset_Loop_Variable;
8899 Map : constant Elist_Id := New_Elmt_List;
8902 Append_Elmt (Object_Entity, Map);
8903 Append_Elmt (Object_Entity_M, Map);
8904 Expr_M := New_Copy_Tree (Expr, Map => Map);
8906 -- The unanalyzed expression will be copied and appear in
8907 -- both functions. Normally expressions do not declare new
8908 -- entities, but quantified expressions do, so we need to
8909 -- create new entities for their bound variables, to prevent
8910 -- multiple definitions in gigi.
8912 Reset_Loop_Variables (Expr_M);
8916 -- Build the main predicate function
8919 SIdB : constant Entity_Id :=
8920 Make_Defining_Identifier (Loc,
8921 Chars => New_External_Name (Chars (Typ), "Predicate"));
8922 -- The entity for the function body
8928 Set_Ekind (SIdB, E_Function);
8929 Set_Is_Predicate_Function (SIdB);
8931 -- The predicate function is shared between views of a type
8933 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
8934 Set_Predicate_Function (Full_View (Typ), SId);
8937 -- Build function body
8940 Make_Function_Specification (Loc,
8941 Defining_Unit_Name => SIdB,
8942 Parameter_Specifications => New_List (
8943 Make_Parameter_Specification (Loc,
8944 Defining_Identifier =>
8945 Make_Defining_Identifier (Loc, Object_Name),
8947 New_Occurrence_Of (Typ, Loc))),
8948 Result_Definition =>
8949 New_Occurrence_Of (Standard_Boolean, Loc));
8952 Make_Subprogram_Body (Loc,
8953 Specification => Spec,
8954 Declarations => Empty_List,
8955 Handled_Statement_Sequence =>
8956 Make_Handled_Sequence_Of_Statements (Loc,
8957 Statements => New_List (
8958 Make_Simple_Return_Statement (Loc,
8959 Expression => Expr))));
8961 -- The declaration has been analyzed when created, and placed
8962 -- after type declaration. Insert body itself after freeze node,
8963 -- unless subprogram declaration is already there, in which case
8964 -- body better be placed afterwards.
8966 if FDecl = Next (N) then
8967 Insert_After_And_Analyze (FDecl, FBody);
8969 Insert_After_And_Analyze (N, FBody);
8972 -- The defining identifier of a quantified expression carries the
8973 -- scope in which the type appears, but when unnesting we need
8974 -- to indicate that its proper scope is the constructed predicate
8975 -- function. The quantified expressions have been converted into
8976 -- loops during analysis and expansion.
8979 function Reset_Quantified_Variable_Scope
8980 (N : Node_Id) return Traverse_Result;
8982 procedure Reset_Quantified_Variables_Scope is
8983 new Traverse_Proc (Reset_Quantified_Variable_Scope);
8985 -------------------------------------
8986 -- Reset_Quantified_Variable_Scope --
8987 -------------------------------------
8989 function Reset_Quantified_Variable_Scope
8990 (N : Node_Id) return Traverse_Result
8993 if Nkind_In (N, N_Iterator_Specification,
8994 N_Loop_Parameter_Specification)
8996 Set_Scope (Defining_Identifier (N),
8997 Predicate_Function (Typ));
9001 end Reset_Quantified_Variable_Scope;
9004 if Unnest_Subprogram_Mode then
9005 Reset_Quantified_Variables_Scope (Expr);
9009 -- within a generic unit, prevent a double analysis of the body
9010 -- which will not be marked analyzed yet. This will happen when
9011 -- the freeze node is created during the preanalysis of an
9012 -- expression function.
9014 if Inside_A_Generic then
9015 Set_Analyzed (FBody);
9018 -- Static predicate functions are always side-effect free, and
9019 -- in most cases dynamic predicate functions are as well. Mark
9020 -- them as such whenever possible, so redundant predicate checks
9021 -- can be optimized. If there is a variable reference within the
9022 -- expression, the function is not pure.
9024 if Expander_Active then
9026 Side_Effect_Free (Expr, Variable_Ref => True));
9027 Set_Is_Inlined (SId);
9031 -- Test for raise expressions present and if so build M version
9033 if Raise_Expression_Present then
9035 SId : constant Entity_Id :=
9036 Make_Defining_Identifier (Loc,
9037 Chars => New_External_Name (Chars (Typ), "PredicateM"));
9038 -- The entity for the function spec
9040 SIdB : constant Entity_Id :=
9041 Make_Defining_Identifier (Loc,
9042 Chars => New_External_Name (Chars (Typ), "PredicateM"));
9043 -- The entity for the function body
9051 -- Mark any raise expressions for special expansion
9053 Process_REs (Expr_M);
9055 -- Build function declaration
9057 Set_Ekind (SId, E_Function);
9058 Set_Is_Predicate_Function_M (SId);
9059 Set_Predicate_Function_M (Typ, SId);
9061 -- The predicate function is shared between views of a type
9063 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
9064 Set_Predicate_Function_M (Full_View (Typ), SId);
9068 Make_Function_Specification (Loc,
9069 Defining_Unit_Name => SId,
9070 Parameter_Specifications => New_List (
9071 Make_Parameter_Specification (Loc,
9072 Defining_Identifier => Object_Entity_M,
9073 Parameter_Type => New_Occurrence_Of (Typ, Loc))),
9074 Result_Definition =>
9075 New_Occurrence_Of (Standard_Boolean, Loc));
9078 Make_Subprogram_Declaration (Loc,
9079 Specification => Spec);
9081 -- Build function body
9084 Make_Function_Specification (Loc,
9085 Defining_Unit_Name => SIdB,
9086 Parameter_Specifications => New_List (
9087 Make_Parameter_Specification (Loc,
9088 Defining_Identifier =>
9089 Make_Defining_Identifier (Loc, Object_Name),
9091 New_Occurrence_Of (Typ, Loc))),
9092 Result_Definition =>
9093 New_Occurrence_Of (Standard_Boolean, Loc));
9095 -- Build the body, we declare the boolean expression before
9096 -- doing the return, because we are not really confident of
9097 -- what happens if a return appears within a return.
9100 Make_Defining_Identifier (Loc,
9101 Chars => New_Internal_Name ('B'));
9104 Make_Subprogram_Body (Loc,
9105 Specification => Spec,
9107 Declarations => New_List (
9108 Make_Object_Declaration (Loc,
9109 Defining_Identifier => BTemp,
9110 Constant_Present => True,
9111 Object_Definition =>
9112 New_Occurrence_Of (Standard_Boolean, Loc),
9113 Expression => Expr_M)),
9115 Handled_Statement_Sequence =>
9116 Make_Handled_Sequence_Of_Statements (Loc,
9117 Statements => New_List (
9118 Make_Simple_Return_Statement (Loc,
9119 Expression => New_Occurrence_Of (BTemp, Loc)))));
9121 -- Insert declaration before freeze node and body after
9123 Insert_Before_And_Analyze (N, FDecl);
9124 Insert_After_And_Analyze (N, FBody);
9126 -- Should quantified expressions be handled here as well ???
9130 -- See if we have a static predicate. Note that the answer may be
9131 -- yes even if we have an explicit Dynamic_Predicate present.
9138 if not Is_Scalar_Type (Typ) and then not Is_String_Type (Typ) then
9141 PS := Is_Predicate_Static (Expr, Object_Name);
9144 -- Case where we have a predicate-static aspect
9148 -- We don't set Has_Static_Predicate_Aspect, since we can have
9149 -- any of the three cases (Predicate, Dynamic_Predicate, or
9150 -- Static_Predicate) generating a predicate with an expression
9151 -- that is predicate-static. We just indicate that we have a
9152 -- predicate that can be treated as static.
9154 Set_Has_Static_Predicate (Typ);
9156 -- For discrete subtype, build the static predicate list
9158 if Is_Discrete_Type (Typ) then
9159 Build_Discrete_Static_Predicate (Typ, Expr, Object_Name);
9161 -- If we don't get a static predicate list, it means that we
9162 -- have a case where this is not possible, most typically in
9163 -- the case where we inherit a dynamic predicate. We do not
9164 -- consider this an error, we just leave the predicate as
9165 -- dynamic. But if we do succeed in building the list, then
9166 -- we mark the predicate as static.
9168 if No (Static_Discrete_Predicate (Typ)) then
9169 Set_Has_Static_Predicate (Typ, False);
9172 -- For real or string subtype, save predicate expression
9174 elsif Is_Real_Type (Typ) or else Is_String_Type (Typ) then
9175 Set_Static_Real_Or_String_Predicate (Typ, Expr);
9178 -- Case of dynamic predicate (expression is not predicate-static)
9181 -- Again, we don't set Has_Dynamic_Predicate_Aspect, since that
9182 -- is only set if we have an explicit Dynamic_Predicate aspect
9183 -- given. Here we may simply have a Predicate aspect where the
9184 -- expression happens not to be predicate-static.
9186 -- Emit an error when the predicate is categorized as static
9187 -- but its expression is not predicate-static.
9189 -- First a little fiddling to get a nice location for the
9190 -- message. If the expression is of the form (A and then B),
9191 -- where A is an inherited predicate, then use the right
9192 -- operand for the Sloc. This avoids getting confused by a call
9193 -- to an inherited predicate with a less convenient source
9197 while Nkind (EN) = N_And_Then
9198 and then Nkind (Left_Opnd (EN)) = N_Function_Call
9199 and then Is_Predicate_Function
9200 (Entity (Name (Left_Opnd (EN))))
9202 EN := Right_Opnd (EN);
9205 -- Now post appropriate message
9207 if Has_Static_Predicate_Aspect (Typ) then
9208 if Is_Scalar_Type (Typ) or else Is_String_Type (Typ) then
9210 ("expression is not predicate-static (RM 3.2.4(16-22))",
9214 ("static predicate requires scalar or string type", EN);
9221 Restore_Ghost_Region (Saved_GM, Saved_IGR);
9222 end Build_Predicate_Functions;
9224 ------------------------------------------
9225 -- Build_Predicate_Function_Declaration --
9226 ------------------------------------------
9228 -- WARNING: This routine manages Ghost regions. Return statements must be
9229 -- replaced by gotos which jump to the end of the routine and restore the
9232 function Build_Predicate_Function_Declaration
9233 (Typ : Entity_Id) return Node_Id
9235 Loc : constant Source_Ptr := Sloc (Typ);
9237 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
9238 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
9239 -- Save the Ghost-related attributes to restore on exit
9241 Func_Decl : Node_Id;
9242 Func_Id : Entity_Id;
9246 -- The related type may be subject to pragma Ghost. Set the mode now to
9247 -- ensure that the predicate functions are properly marked as Ghost.
9249 Set_Ghost_Mode (Typ);
9252 Make_Defining_Identifier (Loc,
9253 Chars => New_External_Name (Chars (Typ), "Predicate"));
9255 -- The predicate function requires debug info when the predicates are
9256 -- subject to Source Coverage Obligations.
9258 if Opt.Generate_SCO then
9259 Set_Debug_Info_Needed (Func_Id);
9263 Make_Function_Specification (Loc,
9264 Defining_Unit_Name => Func_Id,
9265 Parameter_Specifications => New_List (
9266 Make_Parameter_Specification (Loc,
9267 Defining_Identifier => Make_Temporary (Loc, 'I'),
9268 Parameter_Type => New_Occurrence_Of (Typ, Loc))),
9269 Result_Definition =>
9270 New_Occurrence_Of (Standard_Boolean, Loc));
9272 Func_Decl := Make_Subprogram_Declaration (Loc, Specification => Spec);
9274 Set_Ekind (Func_Id, E_Function);
9275 Set_Etype (Func_Id, Standard_Boolean);
9276 Set_Is_Internal (Func_Id);
9277 Set_Is_Predicate_Function (Func_Id);
9278 Set_Predicate_Function (Typ, Func_Id);
9280 Insert_After (Parent (Typ), Func_Decl);
9281 Analyze (Func_Decl);
9283 Restore_Ghost_Region (Saved_GM, Saved_IGR);
9286 end Build_Predicate_Function_Declaration;
9288 -----------------------------------------
9289 -- Check_Aspect_At_End_Of_Declarations --
9290 -----------------------------------------
9292 procedure Check_Aspect_At_End_Of_Declarations (ASN : Node_Id) is
9293 Ent : constant Entity_Id := Entity (ASN);
9294 Ident : constant Node_Id := Identifier (ASN);
9295 A_Id : constant Aspect_Id := Get_Aspect_Id (Chars (Ident));
9297 End_Decl_Expr : constant Node_Id := Entity (Ident);
9298 -- Expression to be analyzed at end of declarations
9300 Freeze_Expr : constant Node_Id := Expression (ASN);
9301 -- Expression from call to Check_Aspect_At_Freeze_Point.
9303 T : constant Entity_Id := Etype (Original_Node (Freeze_Expr));
9304 -- Type required for preanalyze call. We use the original expression to
9305 -- get the proper type, to prevent cascaded errors when the expression
9306 -- is constant-folded.
9309 -- Set False if error
9311 -- On entry to this procedure, Entity (Ident) contains a copy of the
9312 -- original expression from the aspect, saved for this purpose, and
9313 -- but Expression (Ident) is a preanalyzed copy of the expression,
9314 -- preanalyzed just after the freeze point.
9316 procedure Check_Overloaded_Name;
9317 -- For aspects whose expression is simply a name, this routine checks if
9318 -- the name is overloaded or not. If so, it verifies there is an
9319 -- interpretation that matches the entity obtained at the freeze point,
9320 -- otherwise the compiler complains.
9322 ---------------------------
9323 -- Check_Overloaded_Name --
9324 ---------------------------
9326 procedure Check_Overloaded_Name is
9328 if not Is_Overloaded (End_Decl_Expr) then
9329 Err := not Is_Entity_Name (End_Decl_Expr)
9330 or else Entity (End_Decl_Expr) /= Entity (Freeze_Expr);
9336 Index : Interp_Index;
9340 Get_First_Interp (End_Decl_Expr, Index, It);
9341 while Present (It.Typ) loop
9342 if It.Nam = Entity (Freeze_Expr) then
9347 Get_Next_Interp (Index, It);
9351 end Check_Overloaded_Name;
9353 -- Start of processing for Check_Aspect_At_End_Of_Declarations
9356 -- In an instance we do not perform the consistency check between freeze
9357 -- point and end of declarations, because it was done already in the
9358 -- analysis of the generic. Furthermore, the delayed analysis of an
9359 -- aspect of the instance may produce spurious errors when the generic
9360 -- is a child unit that references entities in the parent (which might
9361 -- not be in scope at the freeze point of the instance).
9366 -- The enclosing scope may have been rewritten during expansion (.e.g. a
9367 -- task body is rewritten as a procedure) after this conformance check
9368 -- has been performed, so do not perform it again (it may not easily be
9369 -- done if full visibility of local entities is not available).
9371 elsif not Comes_From_Source (Current_Scope) then
9374 -- Case of aspects Dimension, Dimension_System and Synchronization
9376 elsif A_Id = Aspect_Synchronization then
9379 -- Case of stream attributes, just have to compare entities. However,
9380 -- the expression is just a name (possibly overloaded), and there may
9381 -- be stream operations declared for unrelated types, so we just need
9382 -- to verify that one of these interpretations is the one available at
9383 -- at the freeze point.
9385 elsif A_Id = Aspect_Input or else
9386 A_Id = Aspect_Output or else
9387 A_Id = Aspect_Read or else
9390 Analyze (End_Decl_Expr);
9391 Check_Overloaded_Name;
9393 elsif A_Id = Aspect_Variable_Indexing or else
9394 A_Id = Aspect_Constant_Indexing or else
9395 A_Id = Aspect_Default_Iterator or else
9396 A_Id = Aspect_Iterator_Element
9398 -- Make type unfrozen before analysis, to prevent spurious errors
9399 -- about late attributes.
9401 Set_Is_Frozen (Ent, False);
9402 Analyze (End_Decl_Expr);
9403 Set_Is_Frozen (Ent, True);
9405 -- If the end of declarations comes before any other freeze point,
9406 -- the Freeze_Expr is not analyzed: no check needed.
9408 if Analyzed (Freeze_Expr) and then not In_Instance then
9409 Check_Overloaded_Name;
9417 -- In a generic context freeze nodes are not always generated, so
9418 -- analyze the expression now. If the aspect is for a type, we must
9419 -- also make its potential components accessible.
9421 if not Analyzed (Freeze_Expr) and then Inside_A_Generic then
9422 if A_Id = Aspect_Dynamic_Predicate
9423 or else A_Id = Aspect_Predicate
9426 Preanalyze_Spec_Expression (Freeze_Expr, Standard_Boolean);
9429 elsif A_Id = Aspect_Priority then
9431 Preanalyze_Spec_Expression (Freeze_Expr, Any_Integer);
9435 Preanalyze (Freeze_Expr);
9439 -- Indicate that the expression comes from an aspect specification,
9440 -- which is used in subsequent analysis even if expansion is off.
9442 Set_Parent (End_Decl_Expr, ASN);
9444 -- In a generic context the original aspect expressions have not
9445 -- been preanalyzed, so do it now. There are no conformance checks
9446 -- to perform in this case. As before, we have to make components
9447 -- visible for aspects that may reference them.
9450 if A_Id = Aspect_Dynamic_Predicate
9451 or else A_Id = Aspect_Predicate
9452 or else A_Id = Aspect_Priority
9455 Check_Aspect_At_Freeze_Point (ASN);
9459 Check_Aspect_At_Freeze_Point (ASN);
9463 -- The default values attributes may be defined in the private part,
9464 -- and the analysis of the expression may take place when only the
9465 -- partial view is visible. The expression must be scalar, so use
9466 -- the full view to resolve.
9468 elsif (A_Id = Aspect_Default_Value
9470 A_Id = Aspect_Default_Component_Value)
9471 and then Is_Private_Type (T)
9473 Preanalyze_Spec_Expression (End_Decl_Expr, Full_View (T));
9475 -- The following aspect expressions may contain references to
9476 -- components and discriminants of the type.
9478 elsif A_Id = Aspect_Dynamic_Predicate
9479 or else A_Id = Aspect_Predicate
9480 or else A_Id = Aspect_Priority
9481 or else A_Id = Aspect_CPU
9484 Preanalyze_Spec_Expression (End_Decl_Expr, T);
9488 Preanalyze_Spec_Expression (End_Decl_Expr, T);
9492 not Fully_Conformant_Expressions
9493 (End_Decl_Expr, Freeze_Expr, Report => True);
9496 -- Output error message if error. Force error on aspect specification
9497 -- even if there is an error on the expression itself.
9501 ("!visibility of aspect for& changes after freeze point",
9504 ("info: & is frozen here, (RM 13.1.1 (13/3))??",
9505 Freeze_Node (Ent), Ent);
9507 end Check_Aspect_At_End_Of_Declarations;
9509 ----------------------------------
9510 -- Check_Aspect_At_Freeze_Point --
9511 ----------------------------------
9513 procedure Check_Aspect_At_Freeze_Point (ASN : Node_Id) is
9514 Ident : constant Node_Id := Identifier (ASN);
9515 -- Identifier (use Entity field to save expression)
9517 A_Id : constant Aspect_Id := Get_Aspect_Id (Chars (Ident));
9519 T : Entity_Id := Empty;
9520 -- Type required for preanalyze call
9523 -- On entry to this procedure, Entity (Ident) contains a copy of the
9524 -- original expression from the aspect, saved for this purpose.
9526 -- On exit from this procedure Entity (Ident) is unchanged, still
9527 -- containing that copy, but Expression (Ident) is a preanalyzed copy
9528 -- of the expression, preanalyzed just after the freeze point.
9530 -- Make a copy of the expression to be preanalyzed
9532 Set_Expression (ASN, New_Copy_Tree (Entity (Ident)));
9534 -- Find type for preanalyze call
9538 -- No_Aspect should be impossible
9541 raise Program_Error;
9543 -- Aspects taking an optional boolean argument
9545 when Boolean_Aspects
9546 | Library_Unit_Aspects
9548 T := Standard_Boolean;
9550 -- Aspects corresponding to attribute definition clauses
9552 when Aspect_Address =>
9553 T := RTE (RE_Address);
9555 when Aspect_Attach_Handler =>
9556 T := RTE (RE_Interrupt_ID);
9558 when Aspect_Bit_Order
9559 | Aspect_Scalar_Storage_Order
9561 T := RTE (RE_Bit_Order);
9563 when Aspect_Convention =>
9567 T := RTE (RE_CPU_Range);
9569 -- Default_Component_Value is resolved with the component type
9571 when Aspect_Default_Component_Value =>
9572 T := Component_Type (Entity (ASN));
9574 when Aspect_Default_Storage_Pool =>
9575 T := Class_Wide_Type (RTE (RE_Root_Storage_Pool));
9577 -- Default_Value is resolved with the type entity in question
9579 when Aspect_Default_Value =>
9582 when Aspect_Dispatching_Domain =>
9583 T := RTE (RE_Dispatching_Domain);
9585 when Aspect_External_Tag =>
9586 T := Standard_String;
9588 when Aspect_External_Name =>
9589 T := Standard_String;
9591 when Aspect_Link_Name =>
9592 T := Standard_String;
9594 when Aspect_Interrupt_Priority
9597 T := Standard_Integer;
9599 when Aspect_Relative_Deadline =>
9600 T := RTE (RE_Time_Span);
9602 when Aspect_Secondary_Stack_Size =>
9603 T := Standard_Integer;
9605 when Aspect_Small =>
9607 -- Note that the expression can be of any real type (not just a
9608 -- real universal literal) as long as it is a static constant.
9612 -- For a simple storage pool, we have to retrieve the type of the
9613 -- pool object associated with the aspect's corresponding attribute
9614 -- definition clause.
9616 when Aspect_Simple_Storage_Pool =>
9617 T := Etype (Expression (Aspect_Rep_Item (ASN)));
9619 when Aspect_Storage_Pool =>
9620 T := Class_Wide_Type (RTE (RE_Root_Storage_Pool));
9622 when Aspect_Alignment
9623 | Aspect_Component_Size
9624 | Aspect_Machine_Radix
9625 | Aspect_Object_Size
9627 | Aspect_Storage_Size
9628 | Aspect_Stream_Size
9633 when Aspect_Linker_Section =>
9634 T := Standard_String;
9636 when Aspect_Synchronization =>
9639 -- Special case, the expression of these aspects is just an entity
9640 -- that does not need any resolution, so just analyze.
9650 Analyze (Expression (ASN));
9653 -- Same for Iterator aspects, where the expression is a function
9654 -- name. Legality rules are checked separately.
9656 when Aspect_Constant_Indexing
9657 | Aspect_Default_Iterator
9658 | Aspect_Iterator_Element
9659 | Aspect_Variable_Indexing
9661 Analyze (Expression (ASN));
9664 -- Ditto for Iterable, legality checks in Validate_Iterable_Aspect.
9666 when Aspect_Iterable =>
9670 Cursor : constant Entity_Id := Get_Cursor_Type (ASN, T);
9675 if Cursor = Any_Type then
9679 Assoc := First (Component_Associations (Expression (ASN)));
9680 while Present (Assoc) loop
9681 Expr := Expression (Assoc);
9684 if not Error_Posted (Expr) then
9685 Resolve_Iterable_Operation
9686 (Expr, Cursor, T, Chars (First (Choices (Assoc))));
9695 -- Invariant/Predicate take boolean expressions
9697 when Aspect_Dynamic_Predicate
9700 | Aspect_Static_Predicate
9701 | Aspect_Type_Invariant
9703 T := Standard_Boolean;
9705 when Aspect_Predicate_Failure =>
9706 T := Standard_String;
9708 -- Here is the list of aspects that don't require delay analysis
9710 when Aspect_Abstract_State
9712 | Aspect_Async_Readers
9713 | Aspect_Async_Writers
9714 | Aspect_Constant_After_Elaboration
9715 | Aspect_Contract_Cases
9716 | Aspect_Default_Initial_Condition
9719 | Aspect_Dimension_System
9720 | Aspect_Effective_Reads
9721 | Aspect_Effective_Writes
9722 | Aspect_Extensions_Visible
9725 | Aspect_Implicit_Dereference
9726 | Aspect_Initial_Condition
9727 | Aspect_Initializes
9728 | Aspect_Max_Entry_Queue_Depth
9729 | Aspect_Max_Entry_Queue_Length
9730 | Aspect_Max_Queue_Length
9732 | Aspect_Obsolescent
9735 | Aspect_Postcondition
9737 | Aspect_Precondition
9738 | Aspect_Refined_Depends
9739 | Aspect_Refined_Global
9740 | Aspect_Refined_Post
9741 | Aspect_Refined_State
9744 | Aspect_Unimplemented
9745 | Aspect_Volatile_Function
9747 raise Program_Error;
9751 -- Do the preanalyze call
9753 Preanalyze_Spec_Expression (Expression (ASN), T);
9754 end Check_Aspect_At_Freeze_Point;
9756 -----------------------------------
9757 -- Check_Constant_Address_Clause --
9758 -----------------------------------
9760 procedure Check_Constant_Address_Clause
9764 procedure Check_At_Constant_Address (Nod : Node_Id);
9765 -- Checks that the given node N represents a name whose 'Address is
9766 -- constant (in the same sense as OK_Constant_Address_Clause, i.e. the
9767 -- address value is the same at the point of declaration of U_Ent and at
9768 -- the time of elaboration of the address clause.
9770 procedure Check_Expr_Constants (Nod : Node_Id);
9771 -- Checks that Nod meets the requirements for a constant address clause
9772 -- in the sense of the enclosing procedure.
9774 procedure Check_List_Constants (Lst : List_Id);
9775 -- Check that all elements of list Lst meet the requirements for a
9776 -- constant address clause in the sense of the enclosing procedure.
9778 -------------------------------
9779 -- Check_At_Constant_Address --
9780 -------------------------------
9782 procedure Check_At_Constant_Address (Nod : Node_Id) is
9784 if Is_Entity_Name (Nod) then
9785 if Present (Address_Clause (Entity ((Nod)))) then
9787 ("invalid address clause for initialized object &!",
9790 ("address for& cannot depend on another address clause! "
9791 & "(RM 13.1(22))!", Nod, U_Ent);
9793 elsif In_Same_Source_Unit (Entity (Nod), U_Ent)
9794 and then Sloc (U_Ent) < Sloc (Entity (Nod))
9797 ("invalid address clause for initialized object &!",
9799 Error_Msg_Node_2 := U_Ent;
9801 ("\& must be defined before & (RM 13.1(22))!",
9805 elsif Nkind (Nod) = N_Selected_Component then
9807 T : constant Entity_Id := Etype (Prefix (Nod));
9810 if (Is_Record_Type (T)
9811 and then Has_Discriminants (T))
9814 and then Is_Record_Type (Designated_Type (T))
9815 and then Has_Discriminants (Designated_Type (T)))
9818 ("invalid address clause for initialized object &!",
9821 ("\address cannot depend on component of discriminated "
9822 & "record (RM 13.1(22))!", Nod);
9824 Check_At_Constant_Address (Prefix (Nod));
9828 elsif Nkind (Nod) = N_Indexed_Component then
9829 Check_At_Constant_Address (Prefix (Nod));
9830 Check_List_Constants (Expressions (Nod));
9833 Check_Expr_Constants (Nod);
9835 end Check_At_Constant_Address;
9837 --------------------------
9838 -- Check_Expr_Constants --
9839 --------------------------
9841 procedure Check_Expr_Constants (Nod : Node_Id) is
9842 Loc_U_Ent : constant Source_Ptr := Sloc (U_Ent);
9843 Ent : Entity_Id := Empty;
9846 if Nkind (Nod) in N_Has_Etype
9847 and then Etype (Nod) = Any_Type
9858 when N_Expanded_Name
9861 Ent := Entity (Nod);
9863 -- We need to look at the original node if it is different
9864 -- from the node, since we may have rewritten things and
9865 -- substituted an identifier representing the rewrite.
9867 if Is_Rewrite_Substitution (Nod) then
9868 Check_Expr_Constants (Original_Node (Nod));
9870 -- If the node is an object declaration without initial
9871 -- value, some code has been expanded, and the expression
9872 -- is not constant, even if the constituents might be
9873 -- acceptable, as in A'Address + offset.
9875 if Ekind (Ent) = E_Variable
9877 Nkind (Declaration_Node (Ent)) = N_Object_Declaration
9879 No (Expression (Declaration_Node (Ent)))
9882 ("invalid address clause for initialized object &!",
9885 -- If entity is constant, it may be the result of expanding
9886 -- a check. We must verify that its declaration appears
9887 -- before the object in question, else we also reject the
9890 elsif Ekind (Ent) = E_Constant
9891 and then In_Same_Source_Unit (Ent, U_Ent)
9892 and then Sloc (Ent) > Loc_U_Ent
9895 ("invalid address clause for initialized object &!",
9902 -- Otherwise look at the identifier and see if it is OK
9904 if Ekind_In (Ent, E_Named_Integer, E_Named_Real)
9905 or else Is_Type (Ent)
9909 elsif Ekind_In (Ent, E_Constant, E_In_Parameter) then
9911 -- This is the case where we must have Ent defined before
9912 -- U_Ent. Clearly if they are in different units this
9913 -- requirement is met since the unit containing Ent is
9914 -- already processed.
9916 if not In_Same_Source_Unit (Ent, U_Ent) then
9919 -- Otherwise location of Ent must be before the location
9920 -- of U_Ent, that's what prior defined means.
9922 elsif Sloc (Ent) < Loc_U_Ent then
9927 ("invalid address clause for initialized object &!",
9929 Error_Msg_Node_2 := U_Ent;
9931 ("\& must be defined before & (RM 13.1(22))!",
9935 elsif Nkind (Original_Node (Nod)) = N_Function_Call then
9936 Check_Expr_Constants (Original_Node (Nod));
9940 ("invalid address clause for initialized object &!",
9943 if Comes_From_Source (Ent) then
9945 ("\reference to variable& not allowed"
9946 & " (RM 13.1(22))!", Nod, Ent);
9949 ("non-static expression not allowed"
9950 & " (RM 13.1(22))!", Nod);
9954 when N_Integer_Literal =>
9956 -- If this is a rewritten unchecked conversion, in a system
9957 -- where Address is an integer type, always use the base type
9958 -- for a literal value. This is user-friendly and prevents
9959 -- order-of-elaboration issues with instances of unchecked
9962 if Nkind (Original_Node (Nod)) = N_Function_Call then
9963 Set_Etype (Nod, Base_Type (Etype (Nod)));
9966 when N_Character_Literal
9973 Check_Expr_Constants (Low_Bound (Nod));
9974 Check_Expr_Constants (High_Bound (Nod));
9976 when N_Explicit_Dereference =>
9977 Check_Expr_Constants (Prefix (Nod));
9979 when N_Indexed_Component =>
9980 Check_Expr_Constants (Prefix (Nod));
9981 Check_List_Constants (Expressions (Nod));
9984 Check_Expr_Constants (Prefix (Nod));
9985 Check_Expr_Constants (Discrete_Range (Nod));
9987 when N_Selected_Component =>
9988 Check_Expr_Constants (Prefix (Nod));
9990 when N_Attribute_Reference =>
9991 if Nam_In (Attribute_Name (Nod), Name_Address,
9993 Name_Unchecked_Access,
9994 Name_Unrestricted_Access)
9996 Check_At_Constant_Address (Prefix (Nod));
9998 -- Normally, System'To_Address will have been transformed into
9999 -- an Unchecked_Conversion, but in -gnatc mode, it will not,
10000 -- and we don't want to give an error, because the whole point
10001 -- of 'To_Address is that it is static.
10003 elsif Attribute_Name (Nod) = Name_To_Address then
10004 pragma Assert (Operating_Mode = Check_Semantics);
10008 Check_Expr_Constants (Prefix (Nod));
10009 Check_List_Constants (Expressions (Nod));
10012 when N_Aggregate =>
10013 Check_List_Constants (Component_Associations (Nod));
10014 Check_List_Constants (Expressions (Nod));
10016 when N_Component_Association =>
10017 Check_Expr_Constants (Expression (Nod));
10019 when N_Extension_Aggregate =>
10020 Check_Expr_Constants (Ancestor_Part (Nod));
10021 Check_List_Constants (Component_Associations (Nod));
10022 Check_List_Constants (Expressions (Nod));
10028 | N_Membership_Test
10031 Check_Expr_Constants (Left_Opnd (Nod));
10032 Check_Expr_Constants (Right_Opnd (Nod));
10035 Check_Expr_Constants (Right_Opnd (Nod));
10038 | N_Qualified_Expression
10039 | N_Type_Conversion
10040 | N_Unchecked_Type_Conversion
10042 Check_Expr_Constants (Expression (Nod));
10044 when N_Function_Call =>
10045 if not Is_Pure (Entity (Name (Nod))) then
10047 ("invalid address clause for initialized object &!",
10051 ("\function & is not pure (RM 13.1(22))!",
10052 Nod, Entity (Name (Nod)));
10055 Check_List_Constants (Parameter_Associations (Nod));
10058 when N_Parameter_Association =>
10059 Check_Expr_Constants (Explicit_Actual_Parameter (Nod));
10063 ("invalid address clause for initialized object &!",
10066 ("\must be constant defined before& (RM 13.1(22))!",
10069 end Check_Expr_Constants;
10071 --------------------------
10072 -- Check_List_Constants --
10073 --------------------------
10075 procedure Check_List_Constants (Lst : List_Id) is
10079 if Present (Lst) then
10080 Nod1 := First (Lst);
10081 while Present (Nod1) loop
10082 Check_Expr_Constants (Nod1);
10086 end Check_List_Constants;
10088 -- Start of processing for Check_Constant_Address_Clause
10091 -- If rep_clauses are to be ignored, no need for legality checks. In
10092 -- particular, no need to pester user about rep clauses that violate the
10093 -- rule on constant addresses, given that these clauses will be removed
10094 -- by Freeze before they reach the back end. Similarly in CodePeer mode,
10095 -- we want to relax these checks.
10097 if not Ignore_Rep_Clauses and not CodePeer_Mode then
10098 Check_Expr_Constants (Expr);
10100 end Check_Constant_Address_Clause;
10102 ---------------------------
10103 -- Check_Pool_Size_Clash --
10104 ---------------------------
10106 procedure Check_Pool_Size_Clash (Ent : Entity_Id; SP, SS : Node_Id) is
10110 -- We need to find out which one came first. Note that in the case of
10111 -- aspects mixed with pragmas there are cases where the processing order
10112 -- is reversed, which is why we do the check here.
10114 if Sloc (SP) < Sloc (SS) then
10115 Error_Msg_Sloc := Sloc (SP);
10117 Error_Msg_NE ("Storage_Pool previously given for&#", Post, Ent);
10120 Error_Msg_Sloc := Sloc (SS);
10122 Error_Msg_NE ("Storage_Size previously given for&#", Post, Ent);
10126 ("\cannot have Storage_Size and Storage_Pool (RM 13.11(3))", Post);
10127 end Check_Pool_Size_Clash;
10129 ----------------------------------------
10130 -- Check_Record_Representation_Clause --
10131 ----------------------------------------
10133 procedure Check_Record_Representation_Clause (N : Node_Id) is
10134 Loc : constant Source_Ptr := Sloc (N);
10135 Ident : constant Node_Id := Identifier (N);
10136 Rectype : Entity_Id;
10141 Hbit : Uint := Uint_0;
10145 Max_Bit_So_Far : Uint;
10146 -- Records the maximum bit position so far. If all field positions
10147 -- are monotonically increasing, then we can skip the circuit for
10148 -- checking for overlap, since no overlap is possible.
10150 Tagged_Parent : Entity_Id := Empty;
10151 -- This is set in the case of an extension for which we have either a
10152 -- size clause or Is_Fully_Repped_Tagged_Type True (indicating that all
10153 -- components are positioned by record representation clauses) on the
10154 -- parent type. In this case we check for overlap between components of
10155 -- this tagged type and the parent component. Tagged_Parent will point
10156 -- to this parent type. For all other cases, Tagged_Parent is Empty.
10158 Parent_Last_Bit : Uint := No_Uint; -- init to avoid warning
10159 -- Relevant only if Tagged_Parent is set, Parent_Last_Bit indicates the
10160 -- last bit position for any field in the parent type. We only need to
10161 -- check overlap for fields starting below this point.
10163 Overlap_Check_Required : Boolean;
10164 -- Used to keep track of whether or not an overlap check is required
10166 Overlap_Detected : Boolean := False;
10167 -- Set True if an overlap is detected
10169 Ccount : Natural := 0;
10170 -- Number of component clauses in record rep clause
10172 procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id);
10173 -- Given two entities for record components or discriminants, checks
10174 -- if they have overlapping component clauses and issues errors if so.
10176 procedure Find_Component;
10177 -- Finds component entity corresponding to current component clause (in
10178 -- CC), and sets Comp to the entity, and Fbit/Lbit to the zero origin
10179 -- start/stop bits for the field. If there is no matching component or
10180 -- if the matching component does not have a component clause, then
10181 -- that's an error and Comp is set to Empty, but no error message is
10182 -- issued, since the message was already given. Comp is also set to
10183 -- Empty if the current "component clause" is in fact a pragma.
10185 procedure Record_Hole_Check
10186 (Rectype : Entity_Id; After_Last : out Uint; Warn : Boolean);
10187 -- Checks for gaps in the given Rectype. Compute After_Last, the bit
10188 -- number after the last component. Warn is True on the initial call,
10189 -- and warnings are given for gaps. For a type extension, this is called
10190 -- recursively to compute After_Last for the parent type; in this case
10191 -- Warn is False and the warnings are suppressed.
10193 procedure Component_Order_Check (Rectype : Entity_Id);
10194 -- Check that the order of component clauses agrees with the order of
10195 -- component declarations, and that the component clauses are given in
10196 -- increasing order of bit offset.
10198 -----------------------------
10199 -- Check_Component_Overlap --
10200 -----------------------------
10202 procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id) is
10203 CC1 : constant Node_Id := Component_Clause (C1_Ent);
10204 CC2 : constant Node_Id := Component_Clause (C2_Ent);
10207 if Present (CC1) and then Present (CC2) then
10209 -- Exclude odd case where we have two tag components in the same
10210 -- record, both at location zero. This seems a bit strange, but
10211 -- it seems to happen in some circumstances, perhaps on an error.
10213 if Nam_In (Chars (C1_Ent), Name_uTag, Name_uTag) then
10217 -- Here we check if the two fields overlap
10220 S1 : constant Uint := Component_Bit_Offset (C1_Ent);
10221 S2 : constant Uint := Component_Bit_Offset (C2_Ent);
10222 E1 : constant Uint := S1 + Esize (C1_Ent);
10223 E2 : constant Uint := S2 + Esize (C2_Ent);
10226 if E2 <= S1 or else E1 <= S2 then
10229 Error_Msg_Node_2 := Component_Name (CC2);
10230 Error_Msg_Sloc := Sloc (Error_Msg_Node_2);
10231 Error_Msg_Node_1 := Component_Name (CC1);
10233 ("component& overlaps & #", Component_Name (CC1));
10234 Overlap_Detected := True;
10238 end Check_Component_Overlap;
10240 ---------------------------
10241 -- Component_Order_Check --
10242 ---------------------------
10244 procedure Component_Order_Check (Rectype : Entity_Id) is
10245 Comp : Entity_Id := First_Component (Rectype);
10246 Clause : Node_Id := First (Component_Clauses (N));
10247 Prev_Bit_Offset : Uint := Uint_0;
10248 OOO : constant String :=
10249 "?component clause out of order with respect to declaration";
10252 -- Step Comp through components and Clause through component clauses,
10253 -- skipping pragmas. We ignore discriminants and variant parts,
10254 -- because we get most of the benefit from the plain vanilla
10255 -- component cases, without the extra complexity. If we find a Comp
10256 -- and Clause that don't match, give a warning on both and quit. If
10257 -- we find two subsequent clauses out of order by bit layout, give
10258 -- warning and quit. On each iteration, Prev_Bit_Offset is the one
10259 -- from the previous iteration (or 0 to start).
10261 while Present (Comp) and then Present (Clause) loop
10262 if Nkind (Clause) = N_Component_Clause
10263 and then Ekind (Entity (Component_Name (Clause))) = E_Component
10265 if Entity (Component_Name (Clause)) /= Comp then
10266 Error_Msg_N (OOO, Comp);
10267 Error_Msg_N (OOO, Clause);
10271 if not Reverse_Bit_Order (Rectype)
10272 and then not Reverse_Storage_Order (Rectype)
10273 and then Component_Bit_Offset (Comp) < Prev_Bit_Offset
10275 Error_Msg_N ("?memory layout out of order", Clause);
10279 Prev_Bit_Offset := Component_Bit_Offset (Comp);
10280 Comp := Next_Component (Comp);
10285 end Component_Order_Check;
10287 --------------------
10288 -- Find_Component --
10289 --------------------
10291 procedure Find_Component is
10293 procedure Search_Component (R : Entity_Id);
10294 -- Search components of R for a match. If found, Comp is set
10296 ----------------------
10297 -- Search_Component --
10298 ----------------------
10300 procedure Search_Component (R : Entity_Id) is
10302 Comp := First_Component_Or_Discriminant (R);
10303 while Present (Comp) loop
10305 -- Ignore error of attribute name for component name (we
10306 -- already gave an error message for this, so no need to
10309 if Nkind (Component_Name (CC)) = N_Attribute_Reference then
10312 exit when Chars (Comp) = Chars (Component_Name (CC));
10315 Next_Component_Or_Discriminant (Comp);
10317 end Search_Component;
10319 -- Start of processing for Find_Component
10322 -- Return with Comp set to Empty if we have a pragma
10324 if Nkind (CC) = N_Pragma then
10329 -- Search current record for matching component
10331 Search_Component (Rectype);
10333 -- If not found, maybe component of base type discriminant that is
10334 -- absent from statically constrained first subtype.
10337 Search_Component (Base_Type (Rectype));
10340 -- If no component, or the component does not reference the component
10341 -- clause in question, then there was some previous error for which
10342 -- we already gave a message, so just return with Comp Empty.
10344 if No (Comp) or else Component_Clause (Comp) /= CC then
10345 Check_Error_Detected;
10348 -- Normal case where we have a component clause
10351 Fbit := Component_Bit_Offset (Comp);
10352 Lbit := Fbit + Esize (Comp) - 1;
10354 end Find_Component;
10356 -----------------------
10357 -- Record_Hole_Check --
10358 -----------------------
10360 procedure Record_Hole_Check
10361 (Rectype : Entity_Id; After_Last : out Uint; Warn : Boolean)
10363 Decl : constant Node_Id := Declaration_Node (Base_Type (Rectype));
10364 -- Full declaration of record type
10366 procedure Check_Component_List
10371 -- Check component list CL for holes. DS is a list of discriminant
10372 -- specifications to be included in the consideration of components.
10373 -- Sbit is the starting bit, which is zero if there are no preceding
10374 -- components (before a variant part, or a parent type, or a tag
10375 -- field). If there are preceding components, Sbit is the bit just
10376 -- after the last such component. Abit is set to the bit just after
10377 -- the last component of DS and CL.
10379 --------------------------
10380 -- Check_Component_List --
10381 --------------------------
10383 procedure Check_Component_List
10392 Compl := Integer (List_Length (Component_Items (CL)));
10394 if DS /= No_List then
10395 Compl := Compl + Integer (List_Length (DS));
10399 Comps : array (Natural range 0 .. Compl) of Entity_Id;
10400 -- Gather components (zero entry is for sort routine)
10402 Ncomps : Natural := 0;
10403 -- Number of entries stored in Comps (starting at Comps (1))
10406 -- One component item or discriminant specification
10409 -- Starting bit for next component
10412 -- Component entity
10417 function Lt (Op1, Op2 : Natural) return Boolean;
10418 -- Compare routine for Sort
10420 procedure Move (From : Natural; To : Natural);
10421 -- Move routine for Sort
10423 package Sorting is new GNAT.Heap_Sort_G (Move, Lt);
10429 function Lt (Op1, Op2 : Natural) return Boolean is
10431 return Component_Bit_Offset (Comps (Op1))
10432 < Component_Bit_Offset (Comps (Op2));
10439 procedure Move (From : Natural; To : Natural) is
10441 Comps (To) := Comps (From);
10445 -- Gather discriminants into Comp
10447 if DS /= No_List then
10448 Citem := First (DS);
10449 while Present (Citem) loop
10450 if Nkind (Citem) = N_Discriminant_Specification then
10452 Ent : constant Entity_Id :=
10453 Defining_Identifier (Citem);
10455 if Ekind (Ent) = E_Discriminant then
10456 Ncomps := Ncomps + 1;
10457 Comps (Ncomps) := Ent;
10466 -- Gather component entities into Comp
10468 Citem := First (Component_Items (CL));
10469 while Present (Citem) loop
10470 if Nkind (Citem) = N_Component_Declaration then
10471 Ncomps := Ncomps + 1;
10472 Comps (Ncomps) := Defining_Identifier (Citem);
10478 -- Now sort the component entities based on the first bit.
10479 -- Note we already know there are no overlapping components.
10481 Sorting.Sort (Ncomps);
10483 -- Loop through entries checking for holes
10486 for J in 1 .. Ncomps loop
10490 CBO : constant Uint := Component_Bit_Offset (CEnt);
10493 -- Skip components with unknown offsets
10495 if CBO /= No_Uint and then CBO >= 0 then
10496 Error_Msg_Uint_1 := CBO - Nbit;
10498 if Warn and then Error_Msg_Uint_1 > 0 then
10500 ("?H?^-bit gap before component&",
10501 Component_Name (Component_Clause (CEnt)),
10505 Nbit := CBO + Esize (CEnt);
10510 -- Set Abit to just after the last nonvariant component
10514 -- Process variant parts recursively if present. Set Abit to
10515 -- the maximum for all variant parts.
10517 if Present (Variant_Part (CL)) then
10519 Var_Start : constant Uint := Nbit;
10521 Variant := First (Variants (Variant_Part (CL)));
10522 while Present (Variant) loop
10523 Check_Component_List
10524 (No_List, Component_List (Variant), Var_Start, Nbit);
10526 if Nbit > Abit then
10533 end Check_Component_List;
10536 -- Starting bit for call to Check_Component_List. Zero for an
10537 -- untagged type. The size of the Tag for a nonderived tagged
10538 -- type. Parent size for a type extension.
10540 Record_Definition : Node_Id;
10541 -- Record_Definition containing Component_List to pass to
10542 -- Check_Component_List.
10544 -- Start of processing for Record_Hole_Check
10547 if Is_Tagged_Type (Rectype) then
10548 Sbit := UI_From_Int (System_Address_Size);
10553 After_Last := Uint_0;
10555 if Nkind (Decl) = N_Full_Type_Declaration then
10556 Record_Definition := Type_Definition (Decl);
10558 -- If we have a record extension, set Sbit to point after the last
10559 -- component of the parent type, by calling Record_Hole_Check
10562 if Nkind (Record_Definition) = N_Derived_Type_Definition then
10563 Record_Definition := Record_Extension_Part (Record_Definition);
10564 Record_Hole_Check (Underlying_Type (Parent_Subtype (Rectype)),
10565 After_Last => Sbit, Warn => False);
10568 if Nkind (Record_Definition) = N_Record_Definition then
10569 Check_Component_List
10570 (Discriminant_Specifications (Decl),
10571 Component_List (Record_Definition),
10575 end Record_Hole_Check;
10577 -- Start of processing for Check_Record_Representation_Clause
10581 Rectype := Entity (Ident);
10583 if Rectype = Any_Type then
10587 Rectype := Underlying_Type (Rectype);
10589 -- See if we have a fully repped derived tagged type
10592 PS : constant Entity_Id := Parent_Subtype (Rectype);
10595 if Present (PS) and then Known_Static_RM_Size (PS) then
10596 Tagged_Parent := PS;
10597 Parent_Last_Bit := RM_Size (PS) - 1;
10599 elsif Present (PS) and then Is_Fully_Repped_Tagged_Type (PS) then
10600 Tagged_Parent := PS;
10602 -- Find maximum bit of any component of the parent type
10604 Parent_Last_Bit := UI_From_Int (System_Address_Size - 1);
10605 Pcomp := First_Entity (Tagged_Parent);
10606 while Present (Pcomp) loop
10607 if Ekind_In (Pcomp, E_Discriminant, E_Component) then
10608 if Component_Bit_Offset (Pcomp) /= No_Uint
10609 and then Known_Static_Esize (Pcomp)
10614 Component_Bit_Offset (Pcomp) + Esize (Pcomp) - 1);
10618 -- Skip anonymous types generated for constrained array
10619 -- or record components.
10624 Next_Entity (Pcomp);
10629 -- All done if no component clauses
10631 CC := First (Component_Clauses (N));
10637 -- If a tag is present, then create a component clause that places it
10638 -- at the start of the record (otherwise gigi may place it after other
10639 -- fields that have rep clauses).
10641 Fent := First_Entity (Rectype);
10643 if Nkind (Fent) = N_Defining_Identifier
10644 and then Chars (Fent) = Name_uTag
10646 Set_Component_Bit_Offset (Fent, Uint_0);
10647 Set_Normalized_Position (Fent, Uint_0);
10648 Set_Normalized_First_Bit (Fent, Uint_0);
10649 Set_Normalized_Position_Max (Fent, Uint_0);
10650 Init_Esize (Fent, System_Address_Size);
10652 Set_Component_Clause (Fent,
10653 Make_Component_Clause (Loc,
10654 Component_Name => Make_Identifier (Loc, Name_uTag),
10656 Position => Make_Integer_Literal (Loc, Uint_0),
10657 First_Bit => Make_Integer_Literal (Loc, Uint_0),
10659 Make_Integer_Literal (Loc,
10660 UI_From_Int (System_Address_Size - 1))));
10662 Ccount := Ccount + 1;
10665 Max_Bit_So_Far := Uint_Minus_1;
10666 Overlap_Check_Required := False;
10668 -- Process the component clauses
10670 while Present (CC) loop
10673 if Present (Comp) then
10674 Ccount := Ccount + 1;
10676 -- We need a full overlap check if record positions non-monotonic
10678 if Fbit <= Max_Bit_So_Far then
10679 Overlap_Check_Required := True;
10682 Max_Bit_So_Far := Lbit;
10684 -- Check bit position out of range of specified size
10686 if Has_Size_Clause (Rectype)
10687 and then RM_Size (Rectype) <= Lbit
10690 ("bit number out of range of specified size",
10693 -- Check for overlap with tag or parent component
10696 if Is_Tagged_Type (Rectype)
10697 and then Fbit < System_Address_Size
10700 ("component overlaps tag field of&",
10701 Component_Name (CC), Rectype);
10702 Overlap_Detected := True;
10704 elsif Present (Tagged_Parent)
10705 and then Fbit <= Parent_Last_Bit
10708 ("component overlaps parent field of&",
10709 Component_Name (CC), Rectype);
10710 Overlap_Detected := True;
10713 if Hbit < Lbit then
10722 -- Now that we have processed all the component clauses, check for
10723 -- overlap. We have to leave this till last, since the components can
10724 -- appear in any arbitrary order in the representation clause.
10726 -- We do not need this check if all specified ranges were monotonic,
10727 -- as recorded by Overlap_Check_Required being False at this stage.
10729 -- This first section checks if there are any overlapping entries at
10730 -- all. It does this by sorting all entries and then seeing if there are
10731 -- any overlaps. If there are none, then that is decisive, but if there
10732 -- are overlaps, they may still be OK (they may result from fields in
10733 -- different variants).
10735 if Overlap_Check_Required then
10736 Overlap_Check1 : declare
10738 OC_Fbit : array (0 .. Ccount) of Uint;
10739 -- First-bit values for component clauses, the value is the offset
10740 -- of the first bit of the field from start of record. The zero
10741 -- entry is for use in sorting.
10743 OC_Lbit : array (0 .. Ccount) of Uint;
10744 -- Last-bit values for component clauses, the value is the offset
10745 -- of the last bit of the field from start of record. The zero
10746 -- entry is for use in sorting.
10748 OC_Count : Natural := 0;
10749 -- Count of entries in OC_Fbit and OC_Lbit
10751 function OC_Lt (Op1, Op2 : Natural) return Boolean;
10752 -- Compare routine for Sort
10754 procedure OC_Move (From : Natural; To : Natural);
10755 -- Move routine for Sort
10757 package Sorting is new GNAT.Heap_Sort_G (OC_Move, OC_Lt);
10763 function OC_Lt (Op1, Op2 : Natural) return Boolean is
10765 return OC_Fbit (Op1) < OC_Fbit (Op2);
10772 procedure OC_Move (From : Natural; To : Natural) is
10774 OC_Fbit (To) := OC_Fbit (From);
10775 OC_Lbit (To) := OC_Lbit (From);
10778 -- Start of processing for Overlap_Check
10781 CC := First (Component_Clauses (N));
10782 while Present (CC) loop
10784 -- Exclude component clause already marked in error
10786 if not Error_Posted (CC) then
10789 if Present (Comp) then
10790 OC_Count := OC_Count + 1;
10791 OC_Fbit (OC_Count) := Fbit;
10792 OC_Lbit (OC_Count) := Lbit;
10799 Sorting.Sort (OC_Count);
10801 Overlap_Check_Required := False;
10802 for J in 1 .. OC_Count - 1 loop
10803 if OC_Lbit (J) >= OC_Fbit (J + 1) then
10804 Overlap_Check_Required := True;
10808 end Overlap_Check1;
10811 -- If Overlap_Check_Required is still True, then we have to do the full
10812 -- scale overlap check, since we have at least two fields that do
10813 -- overlap, and we need to know if that is OK since they are in
10814 -- different variant, or whether we have a definite problem.
10816 if Overlap_Check_Required then
10817 Overlap_Check2 : declare
10818 C1_Ent, C2_Ent : Entity_Id;
10819 -- Entities of components being checked for overlap
10822 -- Component_List node whose Component_Items are being checked
10825 -- Component declaration for component being checked
10828 C1_Ent := First_Entity (Base_Type (Rectype));
10830 -- Loop through all components in record. For each component check
10831 -- for overlap with any of the preceding elements on the component
10832 -- list containing the component and also, if the component is in
10833 -- a variant, check against components outside the case structure.
10834 -- This latter test is repeated recursively up the variant tree.
10836 Main_Component_Loop : while Present (C1_Ent) loop
10837 if not Ekind_In (C1_Ent, E_Component, E_Discriminant) then
10838 goto Continue_Main_Component_Loop;
10841 -- Skip overlap check if entity has no declaration node. This
10842 -- happens with discriminants in constrained derived types.
10843 -- Possibly we are missing some checks as a result, but that
10844 -- does not seem terribly serious.
10846 if No (Declaration_Node (C1_Ent)) then
10847 goto Continue_Main_Component_Loop;
10850 Clist := Parent (List_Containing (Declaration_Node (C1_Ent)));
10852 -- Loop through component lists that need checking. Check the
10853 -- current component list and all lists in variants above us.
10855 Component_List_Loop : loop
10857 -- If derived type definition, go to full declaration
10858 -- If at outer level, check discriminants if there are any.
10860 if Nkind (Clist) = N_Derived_Type_Definition then
10861 Clist := Parent (Clist);
10864 -- Outer level of record definition, check discriminants
10866 if Nkind_In (Clist, N_Full_Type_Declaration,
10867 N_Private_Type_Declaration)
10869 if Has_Discriminants (Defining_Identifier (Clist)) then
10871 First_Discriminant (Defining_Identifier (Clist));
10872 while Present (C2_Ent) loop
10873 exit when C1_Ent = C2_Ent;
10874 Check_Component_Overlap (C1_Ent, C2_Ent);
10875 Next_Discriminant (C2_Ent);
10879 -- Record extension case
10881 elsif Nkind (Clist) = N_Derived_Type_Definition then
10884 -- Otherwise check one component list
10887 Citem := First (Component_Items (Clist));
10888 while Present (Citem) loop
10889 if Nkind (Citem) = N_Component_Declaration then
10890 C2_Ent := Defining_Identifier (Citem);
10891 exit when C1_Ent = C2_Ent;
10892 Check_Component_Overlap (C1_Ent, C2_Ent);
10899 -- Check for variants above us (the parent of the Clist can
10900 -- be a variant, in which case its parent is a variant part,
10901 -- and the parent of the variant part is a component list
10902 -- whose components must all be checked against the current
10903 -- component for overlap).
10905 if Nkind (Parent (Clist)) = N_Variant then
10906 Clist := Parent (Parent (Parent (Clist)));
10908 -- Check for possible discriminant part in record, this
10909 -- is treated essentially as another level in the
10910 -- recursion. For this case the parent of the component
10911 -- list is the record definition, and its parent is the
10912 -- full type declaration containing the discriminant
10915 elsif Nkind (Parent (Clist)) = N_Record_Definition then
10916 Clist := Parent (Parent ((Clist)));
10918 -- If neither of these two cases, we are at the top of
10922 exit Component_List_Loop;
10924 end loop Component_List_Loop;
10926 <<Continue_Main_Component_Loop>>
10927 Next_Entity (C1_Ent);
10929 end loop Main_Component_Loop;
10930 end Overlap_Check2;
10933 -- Skip the following warnings if overlap was detected; programmer
10934 -- should fix the errors first.
10936 if not Overlap_Detected then
10937 -- Check for record holes (gaps)
10939 if Warn_On_Record_Holes then
10943 Record_Hole_Check (Rectype, After_Last => Ignore, Warn => True);
10947 -- Check for out-of-order component clauses
10949 if Warn_On_Component_Order then
10950 Component_Order_Check (Rectype);
10954 -- For records that have component clauses for all components, and whose
10955 -- size is less than or equal to 32, and which can be fully packed, we
10956 -- need to know the size in the front end to activate possible packed
10957 -- array processing where the component type is a record.
10959 -- At this stage Hbit + 1 represents the first unused bit from all the
10960 -- component clauses processed, so if the component clauses are
10961 -- complete, then this is the length of the record.
10963 -- For records longer than System.Storage_Unit, and for those where not
10964 -- all components have component clauses, the back end determines the
10965 -- length (it may for example be appropriate to round up the size
10966 -- to some convenient boundary, based on alignment considerations, etc).
10968 if Unknown_RM_Size (Rectype)
10969 and then Hbit + 1 <= 32
10970 and then not Strict_Alignment (Rectype)
10973 -- Nothing to do if at least one component has no component clause
10975 Comp := First_Component_Or_Discriminant (Rectype);
10976 while Present (Comp) loop
10977 exit when No (Component_Clause (Comp));
10978 Next_Component_Or_Discriminant (Comp);
10981 -- If we fall out of loop, all components have component clauses
10982 -- and so we can set the size to the maximum value.
10985 Set_RM_Size (Rectype, Hbit + 1);
10988 end Check_Record_Representation_Clause;
10994 procedure Check_Size
10998 Biased : out Boolean)
11000 procedure Size_Too_Small_Error (Min_Siz : Uint);
11001 -- Emit an error concerning illegal size Siz. Min_Siz denotes the
11004 --------------------------
11005 -- Size_Too_Small_Error --
11006 --------------------------
11008 procedure Size_Too_Small_Error (Min_Siz : Uint) is
11010 -- This error is suppressed in ASIS mode to allow for different ASIS
11011 -- back ends or ASIS-based tools to query the illegal clause.
11013 if not ASIS_Mode then
11014 Error_Msg_Uint_1 := Min_Siz;
11015 Error_Msg_NE (Size_Too_Small_Message, N, T);
11017 end Size_Too_Small_Error;
11021 UT : constant Entity_Id := Underlying_Type (T);
11024 -- Start of processing for Check_Size
11029 -- Reject patently improper size values
11031 if Is_Elementary_Type (T)
11032 and then Siz > UI_From_Int (Int'Last)
11034 Error_Msg_N ("Size value too large for elementary type", N);
11036 if Nkind (Original_Node (N)) = N_Op_Expon then
11038 ("\maybe '* was meant, rather than '*'*", Original_Node (N));
11042 -- Dismiss generic types
11044 if Is_Generic_Type (T)
11046 Is_Generic_Type (UT)
11048 Is_Generic_Type (Root_Type (UT))
11052 -- Guard against previous errors
11054 elsif No (UT) or else UT = Any_Type then
11055 Check_Error_Detected;
11058 -- Check case of bit packed array
11060 elsif Is_Array_Type (UT)
11061 and then Known_Static_Component_Size (UT)
11062 and then Is_Bit_Packed_Array (UT)
11070 Asiz := Component_Size (UT);
11071 Indx := First_Index (UT);
11073 Ityp := Etype (Indx);
11075 -- If non-static bound, then we are not in the business of
11076 -- trying to check the length, and indeed an error will be
11077 -- issued elsewhere, since sizes of non-static array types
11078 -- cannot be set implicitly or explicitly.
11080 if not Is_OK_Static_Subtype (Ityp) then
11084 -- Otherwise accumulate next dimension
11086 Asiz := Asiz * (Expr_Value (Type_High_Bound (Ityp)) -
11087 Expr_Value (Type_Low_Bound (Ityp)) +
11091 exit when No (Indx);
11094 if Asiz <= Siz then
11098 Size_Too_Small_Error (Asiz);
11099 Set_Esize (T, Asiz);
11100 Set_RM_Size (T, Asiz);
11104 -- All other composite types are ignored
11106 elsif Is_Composite_Type (UT) then
11109 -- For fixed-point types, don't check minimum if type is not frozen,
11110 -- since we don't know all the characteristics of the type that can
11111 -- affect the size (e.g. a specified small) till freeze time.
11113 elsif Is_Fixed_Point_Type (UT) and then not Is_Frozen (UT) then
11116 -- Cases for which a minimum check is required
11119 -- Ignore if specified size is correct for the type
11121 if Known_Esize (UT) and then Siz = Esize (UT) then
11125 -- Otherwise get minimum size
11127 M := UI_From_Int (Minimum_Size (UT));
11131 -- Size is less than minimum size, but one possibility remains
11132 -- that we can manage with the new size if we bias the type.
11134 M := UI_From_Int (Minimum_Size (UT, Biased => True));
11137 Size_Too_Small_Error (M);
11139 Set_RM_Size (T, M);
11147 --------------------------
11148 -- Freeze_Entity_Checks --
11149 --------------------------
11151 procedure Freeze_Entity_Checks (N : Node_Id) is
11152 procedure Hide_Non_Overridden_Subprograms (Typ : Entity_Id);
11153 -- Inspect the primitive operations of type Typ and hide all pairs of
11154 -- implicitly declared non-overridden non-fully conformant homographs
11155 -- (Ada RM 8.3 12.3/2).
11157 -------------------------------------
11158 -- Hide_Non_Overridden_Subprograms --
11159 -------------------------------------
11161 procedure Hide_Non_Overridden_Subprograms (Typ : Entity_Id) is
11162 procedure Hide_Matching_Homographs
11163 (Subp_Id : Entity_Id;
11164 Start_Elmt : Elmt_Id);
11165 -- Inspect a list of primitive operations starting with Start_Elmt
11166 -- and find matching implicitly declared non-overridden non-fully
11167 -- conformant homographs of Subp_Id. If found, all matches along
11168 -- with Subp_Id are hidden from all visibility.
11170 function Is_Non_Overridden_Or_Null_Procedure
11171 (Subp_Id : Entity_Id) return Boolean;
11172 -- Determine whether subprogram Subp_Id is implicitly declared non-
11173 -- overridden subprogram or an implicitly declared null procedure.
11175 ------------------------------
11176 -- Hide_Matching_Homographs --
11177 ------------------------------
11179 procedure Hide_Matching_Homographs
11180 (Subp_Id : Entity_Id;
11181 Start_Elmt : Elmt_Id)
11184 Prim_Elmt : Elmt_Id;
11187 Prim_Elmt := Start_Elmt;
11188 while Present (Prim_Elmt) loop
11189 Prim := Node (Prim_Elmt);
11191 -- The current primitive is implicitly declared non-overridden
11192 -- non-fully conformant homograph of Subp_Id. Both subprograms
11193 -- must be hidden from visibility.
11195 if Chars (Prim) = Chars (Subp_Id)
11196 and then Is_Non_Overridden_Or_Null_Procedure (Prim)
11197 and then not Fully_Conformant (Prim, Subp_Id)
11199 Set_Is_Hidden_Non_Overridden_Subpgm (Prim);
11200 Set_Is_Immediately_Visible (Prim, False);
11201 Set_Is_Potentially_Use_Visible (Prim, False);
11203 Set_Is_Hidden_Non_Overridden_Subpgm (Subp_Id);
11204 Set_Is_Immediately_Visible (Subp_Id, False);
11205 Set_Is_Potentially_Use_Visible (Subp_Id, False);
11208 Next_Elmt (Prim_Elmt);
11210 end Hide_Matching_Homographs;
11212 -----------------------------------------
11213 -- Is_Non_Overridden_Or_Null_Procedure --
11214 -----------------------------------------
11216 function Is_Non_Overridden_Or_Null_Procedure
11217 (Subp_Id : Entity_Id) return Boolean
11219 Alias_Id : Entity_Id;
11222 -- The subprogram is inherited (implicitly declared), it does not
11223 -- override and does not cover a primitive of an interface.
11225 if Ekind_In (Subp_Id, E_Function, E_Procedure)
11226 and then Present (Alias (Subp_Id))
11227 and then No (Interface_Alias (Subp_Id))
11228 and then No (Overridden_Operation (Subp_Id))
11230 Alias_Id := Alias (Subp_Id);
11232 if Requires_Overriding (Alias_Id) then
11235 elsif Nkind (Parent (Alias_Id)) = N_Procedure_Specification
11236 and then Null_Present (Parent (Alias_Id))
11243 end Is_Non_Overridden_Or_Null_Procedure;
11247 Prim_Ops : constant Elist_Id := Direct_Primitive_Operations (Typ);
11249 Prim_Elmt : Elmt_Id;
11251 -- Start of processing for Hide_Non_Overridden_Subprograms
11254 -- Inspect the list of primitives looking for non-overridden
11257 if Present (Prim_Ops) then
11258 Prim_Elmt := First_Elmt (Prim_Ops);
11259 while Present (Prim_Elmt) loop
11260 Prim := Node (Prim_Elmt);
11261 Next_Elmt (Prim_Elmt);
11263 if Is_Non_Overridden_Or_Null_Procedure (Prim) then
11264 Hide_Matching_Homographs
11266 Start_Elmt => Prim_Elmt);
11270 end Hide_Non_Overridden_Subprograms;
11274 E : constant Entity_Id := Entity (N);
11276 Nongeneric_Case : constant Boolean := Nkind (N) = N_Freeze_Entity;
11277 -- True in nongeneric case. Some of the processing here is skipped
11278 -- for the generic case since it is not needed. Basically in the
11279 -- generic case, we only need to do stuff that might generate error
11280 -- messages or warnings.
11282 -- Start of processing for Freeze_Entity_Checks
11285 -- Remember that we are processing a freezing entity. Required to
11286 -- ensure correct decoration of internal entities associated with
11287 -- interfaces (see New_Overloaded_Entity).
11289 Inside_Freezing_Actions := Inside_Freezing_Actions + 1;
11291 -- For tagged types covering interfaces add internal entities that link
11292 -- the primitives of the interfaces with the primitives that cover them.
11293 -- Note: These entities were originally generated only when generating
11294 -- code because their main purpose was to provide support to initialize
11295 -- the secondary dispatch tables. They are now generated also when
11296 -- compiling with no code generation to provide ASIS the relationship
11297 -- between interface primitives and tagged type primitives. They are
11298 -- also used to locate primitives covering interfaces when processing
11299 -- generics (see Derive_Subprograms).
11301 -- This is not needed in the generic case
11303 if Ada_Version >= Ada_2005
11304 and then Nongeneric_Case
11305 and then Ekind (E) = E_Record_Type
11306 and then Is_Tagged_Type (E)
11307 and then not Is_Interface (E)
11308 and then Has_Interfaces (E)
11310 -- This would be a good common place to call the routine that checks
11311 -- overriding of interface primitives (and thus factorize calls to
11312 -- Check_Abstract_Overriding located at different contexts in the
11313 -- compiler). However, this is not possible because it causes
11314 -- spurious errors in case of late overriding.
11316 Add_Internal_Interface_Entities (E);
11319 -- After all forms of overriding have been resolved, a tagged type may
11320 -- be left with a set of implicitly declared and possibly erroneous
11321 -- abstract subprograms, null procedures and subprograms that require
11322 -- overriding. If this set contains fully conformant homographs, then
11323 -- one is chosen arbitrarily (already done during resolution), otherwise
11324 -- all remaining non-fully conformant homographs are hidden from
11325 -- visibility (Ada RM 8.3 12.3/2).
11327 if Is_Tagged_Type (E) then
11328 Hide_Non_Overridden_Subprograms (E);
11333 if Ekind (E) = E_Record_Type
11334 and then Is_CPP_Class (E)
11335 and then Is_Tagged_Type (E)
11336 and then Tagged_Type_Expansion
11338 if CPP_Num_Prims (E) = 0 then
11340 -- If the CPP type has user defined components then it must import
11341 -- primitives from C++. This is required because if the C++ class
11342 -- has no primitives then the C++ compiler does not added the _tag
11343 -- component to the type.
11345 if First_Entity (E) /= Last_Entity (E) then
11347 ("'C'P'P type must import at least one primitive from C++??",
11352 -- Check that all its primitives are abstract or imported from C++.
11353 -- Check also availability of the C++ constructor.
11356 Has_Constructors : constant Boolean := Has_CPP_Constructors (E);
11358 Error_Reported : Boolean := False;
11362 Elmt := First_Elmt (Primitive_Operations (E));
11363 while Present (Elmt) loop
11364 Prim := Node (Elmt);
11366 if Comes_From_Source (Prim) then
11367 if Is_Abstract_Subprogram (Prim) then
11370 elsif not Is_Imported (Prim)
11371 or else Convention (Prim) /= Convention_CPP
11374 ("primitives of 'C'P'P types must be imported from C++ "
11375 & "or abstract??", Prim);
11377 elsif not Has_Constructors
11378 and then not Error_Reported
11380 Error_Msg_Name_1 := Chars (E);
11382 ("??'C'P'P constructor required for type %", Prim);
11383 Error_Reported := True;
11392 -- Check Ada derivation of CPP type
11394 if Expander_Active -- why? losing errors in -gnatc mode???
11395 and then Present (Etype (E)) -- defend against errors
11396 and then Tagged_Type_Expansion
11397 and then Ekind (E) = E_Record_Type
11398 and then Etype (E) /= E
11399 and then Is_CPP_Class (Etype (E))
11400 and then CPP_Num_Prims (Etype (E)) > 0
11401 and then not Is_CPP_Class (E)
11402 and then not Has_CPP_Constructors (Etype (E))
11404 -- If the parent has C++ primitives but it has no constructor then
11405 -- check that all the primitives are overridden in this derivation;
11406 -- otherwise the constructor of the parent is needed to build the
11414 Elmt := First_Elmt (Primitive_Operations (E));
11415 while Present (Elmt) loop
11416 Prim := Node (Elmt);
11418 if not Is_Abstract_Subprogram (Prim)
11419 and then No (Interface_Alias (Prim))
11420 and then Find_Dispatching_Type (Ultimate_Alias (Prim)) /= E
11422 Error_Msg_Name_1 := Chars (Etype (E));
11424 ("'C'P'P constructor required for parent type %", E);
11433 Inside_Freezing_Actions := Inside_Freezing_Actions - 1;
11435 -- If we have a type with predicates, build predicate function. This is
11436 -- not needed in the generic case, nor within TSS subprograms and other
11437 -- predefined primitives. For a derived type, ensure that the parent
11438 -- type is already frozen so that its predicate function has been
11439 -- constructed already. This is necessary if the parent is declared
11440 -- in a nested package and its own freeze point has not been reached.
11443 and then Nongeneric_Case
11444 and then not Within_Internal_Subprogram
11445 and then Has_Predicates (E)
11448 Atyp : constant Entity_Id := Nearest_Ancestor (E);
11451 and then Has_Predicates (Atyp)
11452 and then not Is_Frozen (Atyp)
11454 Freeze_Before (N, Atyp);
11458 Build_Predicate_Functions (E, N);
11461 -- If type has delayed aspects, this is where we do the preanalysis at
11462 -- the freeze point, as part of the consistent visibility check. Note
11463 -- that this must be done after calling Build_Predicate_Functions or
11464 -- Build_Invariant_Procedure since these subprograms fix occurrences of
11465 -- the subtype name in the saved expression so that they will not cause
11466 -- trouble in the preanalysis.
11468 -- This is also not needed in the generic case
11471 and then Has_Delayed_Aspects (E)
11472 and then Scope (E) = Current_Scope
11479 -- Look for aspect specification entries for this entity
11481 Ritem := First_Rep_Item (E);
11482 while Present (Ritem) loop
11483 if Nkind (Ritem) = N_Aspect_Specification
11484 and then Entity (Ritem) = E
11485 and then Is_Delayed_Aspect (Ritem)
11487 A_Id := Get_Aspect_Id (Ritem);
11489 if A_Id = Aspect_Dynamic_Predicate
11490 or else A_Id = Aspect_Predicate
11491 or else A_Id = Aspect_Priority
11492 or else A_Id = Aspect_CPU
11494 -- Retrieve the visibility to components and discriminants
11495 -- in order to properly analyze the aspects.
11498 Check_Aspect_At_Freeze_Point (Ritem);
11502 Check_Aspect_At_Freeze_Point (Ritem);
11506 Next_Rep_Item (Ritem);
11512 -- For a record type, deal with variant parts. This has to be delayed to
11513 -- this point, because of the issue of statically predicated subtypes,
11514 -- which we have to ensure are frozen before checking choices, since we
11515 -- need to have the static choice list set.
11517 if Is_Record_Type (E) then
11518 Check_Variant_Part : declare
11519 D : constant Node_Id := Declaration_Node (E);
11524 Others_Present : Boolean;
11525 pragma Warnings (Off, Others_Present);
11526 -- Indicates others present, not used in this case
11528 procedure Non_Static_Choice_Error (Choice : Node_Id);
11529 -- Error routine invoked by the generic instantiation below when
11530 -- the variant part has a non static choice.
11532 procedure Process_Declarations (Variant : Node_Id);
11533 -- Processes declarations associated with a variant. We analyzed
11534 -- the declarations earlier (in Sem_Ch3.Analyze_Variant_Part),
11535 -- but we still need the recursive call to Check_Choices for any
11536 -- nested variant to get its choices properly processed. This is
11537 -- also where we expand out the choices if expansion is active.
11539 package Variant_Choices_Processing is new
11540 Generic_Check_Choices
11541 (Process_Empty_Choice => No_OP,
11542 Process_Non_Static_Choice => Non_Static_Choice_Error,
11543 Process_Associated_Node => Process_Declarations);
11544 use Variant_Choices_Processing;
11546 -----------------------------
11547 -- Non_Static_Choice_Error --
11548 -----------------------------
11550 procedure Non_Static_Choice_Error (Choice : Node_Id) is
11552 Flag_Non_Static_Expr
11553 ("choice given in variant part is not static!", Choice);
11554 end Non_Static_Choice_Error;
11556 --------------------------
11557 -- Process_Declarations --
11558 --------------------------
11560 procedure Process_Declarations (Variant : Node_Id) is
11561 CL : constant Node_Id := Component_List (Variant);
11565 -- Check for static predicate present in this variant
11567 if Has_SP_Choice (Variant) then
11569 -- Here we expand. You might expect to find this call in
11570 -- Expand_N_Variant_Part, but that is called when we first
11571 -- see the variant part, and we cannot do this expansion
11572 -- earlier than the freeze point, since for statically
11573 -- predicated subtypes, the predicate is not known till
11574 -- the freeze point.
11576 -- Furthermore, we do this expansion even if the expander
11577 -- is not active, because other semantic processing, e.g.
11578 -- for aggregates, requires the expanded list of choices.
11580 -- If the expander is not active, then we can't just clobber
11581 -- the list since it would invalidate the ASIS -gnatct tree.
11582 -- So we have to rewrite the variant part with a Rewrite
11583 -- call that replaces it with a copy and clobber the copy.
11585 if not Expander_Active then
11587 NewV : constant Node_Id := New_Copy (Variant);
11589 Set_Discrete_Choices
11590 (NewV, New_Copy_List (Discrete_Choices (Variant)));
11591 Rewrite (Variant, NewV);
11595 Expand_Static_Predicates_In_Choices (Variant);
11598 -- We don't need to worry about the declarations in the variant
11599 -- (since they were analyzed by Analyze_Choices when we first
11600 -- encountered the variant), but we do need to take care of
11601 -- expansion of any nested variants.
11603 if not Null_Present (CL) then
11604 VP := Variant_Part (CL);
11606 if Present (VP) then
11608 (VP, Variants (VP), Etype (Name (VP)), Others_Present);
11611 end Process_Declarations;
11613 -- Start of processing for Check_Variant_Part
11616 -- Find component list
11620 if Nkind (D) = N_Full_Type_Declaration then
11621 T := Type_Definition (D);
11623 if Nkind (T) = N_Record_Definition then
11624 C := Component_List (T);
11626 elsif Nkind (T) = N_Derived_Type_Definition
11627 and then Present (Record_Extension_Part (T))
11629 C := Component_List (Record_Extension_Part (T));
11633 -- Case of variant part present
11635 if Present (C) and then Present (Variant_Part (C)) then
11636 VP := Variant_Part (C);
11641 (VP, Variants (VP), Etype (Name (VP)), Others_Present);
11643 -- If the last variant does not contain the Others choice,
11644 -- replace it with an N_Others_Choice node since Gigi always
11645 -- wants an Others. Note that we do not bother to call Analyze
11646 -- on the modified variant part, since its only effect would be
11647 -- to compute the Others_Discrete_Choices node laboriously, and
11648 -- of course we already know the list of choices corresponding
11649 -- to the others choice (it's the list we're replacing).
11651 -- We only want to do this if the expander is active, since
11652 -- we do not want to clobber the ASIS tree.
11654 if Expander_Active then
11656 Last_Var : constant Node_Id :=
11657 Last_Non_Pragma (Variants (VP));
11659 Others_Node : Node_Id;
11662 if Nkind (First (Discrete_Choices (Last_Var))) /=
11665 Others_Node := Make_Others_Choice (Sloc (Last_Var));
11666 Set_Others_Discrete_Choices
11667 (Others_Node, Discrete_Choices (Last_Var));
11668 Set_Discrete_Choices
11669 (Last_Var, New_List (Others_Node));
11674 end Check_Variant_Part;
11676 end Freeze_Entity_Checks;
11678 -------------------------
11679 -- Get_Alignment_Value --
11680 -------------------------
11682 function Get_Alignment_Value (Expr : Node_Id) return Uint is
11683 Align : constant Uint := Static_Integer (Expr);
11686 if Align = No_Uint then
11689 elsif Align < 0 then
11691 -- This error is suppressed in ASIS mode to allow for different ASIS
11692 -- back ends or ASIS-based tools to query the illegal clause.
11694 if not ASIS_Mode then
11695 Error_Msg_N ("alignment value must be positive", Expr);
11700 -- If Alignment is specified to be 0, we treat it the same as 1
11702 elsif Align = 0 then
11706 for J in Int range 0 .. 64 loop
11708 M : constant Uint := Uint_2 ** J;
11711 exit when M = Align;
11715 -- This error is suppressed in ASIS mode to allow for
11716 -- different ASIS back ends or ASIS-based tools to query the
11719 if not ASIS_Mode then
11720 Error_Msg_N ("alignment value must be power of 2", Expr);
11730 end Get_Alignment_Value;
11732 -------------------------------------
11733 -- Inherit_Aspects_At_Freeze_Point --
11734 -------------------------------------
11736 procedure Inherit_Aspects_At_Freeze_Point (Typ : Entity_Id) is
11737 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11738 (Rep_Item : Node_Id) return Boolean;
11739 -- This routine checks if Rep_Item is either a pragma or an aspect
11740 -- specification node whose correponding pragma (if any) is present in
11741 -- the Rep Item chain of the entity it has been specified to.
11743 function Rep_Item_Entity (Rep_Item : Node_Id) return Entity_Id;
11744 -- Return the entity for which Rep_Item is specified
11746 --------------------------------------------------
11747 -- Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item --
11748 --------------------------------------------------
11750 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11751 (Rep_Item : Node_Id) return Boolean
11755 Nkind (Rep_Item) = N_Pragma
11756 or else Present_In_Rep_Item
11757 (Entity (Rep_Item), Aspect_Rep_Item (Rep_Item));
11758 end Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item;
11760 ---------------------
11761 -- Rep_Item_Entity --
11762 ---------------------
11764 function Rep_Item_Entity (Rep_Item : Node_Id) return Entity_Id is
11766 if Nkind (Rep_Item) = N_Aspect_Specification then
11767 return Entity (Rep_Item);
11770 pragma Assert (Nkind_In (Rep_Item,
11771 N_Attribute_Definition_Clause,
11773 return Entity (Name (Rep_Item));
11775 end Rep_Item_Entity;
11777 -- Start of processing for Inherit_Aspects_At_Freeze_Point
11780 -- A representation item is either subtype-specific (Size and Alignment
11781 -- clauses) or type-related (all others). Subtype-specific aspects may
11782 -- differ for different subtypes of the same type (RM 13.1.8).
11784 -- A derived type inherits each type-related representation aspect of
11785 -- its parent type that was directly specified before the declaration of
11786 -- the derived type (RM 13.1.15).
11788 -- A derived subtype inherits each subtype-specific representation
11789 -- aspect of its parent subtype that was directly specified before the
11790 -- declaration of the derived type (RM 13.1.15).
11792 -- The general processing involves inheriting a representation aspect
11793 -- from a parent type whenever the first rep item (aspect specification,
11794 -- attribute definition clause, pragma) corresponding to the given
11795 -- representation aspect in the rep item chain of Typ, if any, isn't
11796 -- directly specified to Typ but to one of its parents.
11798 -- ??? Note that, for now, just a limited number of representation
11799 -- aspects have been inherited here so far. Many of them are
11800 -- still inherited in Sem_Ch3. This will be fixed soon. Here is
11801 -- a non- exhaustive list of aspects that likely also need to
11802 -- be moved to this routine: Alignment, Component_Alignment,
11803 -- Component_Size, Machine_Radix, Object_Size, Pack, Predicates,
11804 -- Preelaborable_Initialization, RM_Size and Small.
11806 -- In addition, Convention must be propagated from base type to subtype,
11807 -- because the subtype may have been declared on an incomplete view.
11809 if Nkind (Parent (Typ)) = N_Private_Extension_Declaration then
11815 if not Has_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005, False)
11816 and then Has_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005)
11817 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11818 (Get_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005))
11820 Set_Is_Ada_2005_Only (Typ);
11825 if not Has_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012, False)
11826 and then Has_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012)
11827 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11828 (Get_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012))
11830 Set_Is_Ada_2012_Only (Typ);
11835 if not Has_Rep_Item (Typ, Name_Atomic, Name_Shared, False)
11836 and then Has_Rep_Pragma (Typ, Name_Atomic, Name_Shared)
11837 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11838 (Get_Rep_Item (Typ, Name_Atomic, Name_Shared))
11840 Set_Is_Atomic (Typ);
11841 Set_Is_Volatile (Typ);
11842 Set_Treat_As_Volatile (Typ);
11847 if Is_Record_Type (Typ)
11848 and then Typ /= Base_Type (Typ) and then Is_Frozen (Base_Type (Typ))
11850 Set_Convention (Typ, Convention (Base_Type (Typ)));
11853 -- Default_Component_Value
11855 -- Verify that there is no rep_item declared for the type, and there
11856 -- is one coming from an ancestor.
11858 if Is_Array_Type (Typ)
11859 and then Is_Base_Type (Typ)
11860 and then not Has_Rep_Item (Typ, Name_Default_Component_Value, False)
11861 and then Has_Rep_Item (Typ, Name_Default_Component_Value)
11863 Set_Default_Aspect_Component_Value (Typ,
11864 Default_Aspect_Component_Value
11865 (Entity (Get_Rep_Item (Typ, Name_Default_Component_Value))));
11870 if Is_Scalar_Type (Typ)
11871 and then Is_Base_Type (Typ)
11872 and then not Has_Rep_Item (Typ, Name_Default_Value, False)
11873 and then Has_Rep_Item (Typ, Name_Default_Value)
11875 Set_Has_Default_Aspect (Typ);
11876 Set_Default_Aspect_Value (Typ,
11877 Default_Aspect_Value
11878 (Entity (Get_Rep_Item (Typ, Name_Default_Value))));
11883 if not Has_Rep_Item (Typ, Name_Discard_Names, False)
11884 and then Has_Rep_Item (Typ, Name_Discard_Names)
11885 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11886 (Get_Rep_Item (Typ, Name_Discard_Names))
11888 Set_Discard_Names (Typ);
11893 if not Has_Rep_Item (Typ, Name_Volatile, False)
11894 and then Has_Rep_Item (Typ, Name_Volatile)
11895 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11896 (Get_Rep_Item (Typ, Name_Volatile))
11898 Set_Is_Volatile (Typ);
11899 Set_Treat_As_Volatile (Typ);
11902 -- Volatile_Full_Access
11904 if not Has_Rep_Item (Typ, Name_Volatile_Full_Access, False)
11905 and then Has_Rep_Pragma (Typ, Name_Volatile_Full_Access)
11906 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11907 (Get_Rep_Item (Typ, Name_Volatile_Full_Access))
11909 Set_Is_Volatile_Full_Access (Typ);
11910 Set_Is_Volatile (Typ);
11911 Set_Treat_As_Volatile (Typ);
11914 -- Inheritance for derived types only
11916 if Is_Derived_Type (Typ) then
11918 Bas_Typ : constant Entity_Id := Base_Type (Typ);
11919 Imp_Bas_Typ : constant Entity_Id := Implementation_Base_Type (Typ);
11922 -- Atomic_Components
11924 if not Has_Rep_Item (Typ, Name_Atomic_Components, False)
11925 and then Has_Rep_Item (Typ, Name_Atomic_Components)
11926 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11927 (Get_Rep_Item (Typ, Name_Atomic_Components))
11929 Set_Has_Atomic_Components (Imp_Bas_Typ);
11932 -- Volatile_Components
11934 if not Has_Rep_Item (Typ, Name_Volatile_Components, False)
11935 and then Has_Rep_Item (Typ, Name_Volatile_Components)
11936 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11937 (Get_Rep_Item (Typ, Name_Volatile_Components))
11939 Set_Has_Volatile_Components (Imp_Bas_Typ);
11942 -- Finalize_Storage_Only
11944 if not Has_Rep_Pragma (Typ, Name_Finalize_Storage_Only, False)
11945 and then Has_Rep_Pragma (Typ, Name_Finalize_Storage_Only)
11947 Set_Finalize_Storage_Only (Bas_Typ);
11950 -- Universal_Aliasing
11952 if not Has_Rep_Item (Typ, Name_Universal_Aliasing, False)
11953 and then Has_Rep_Item (Typ, Name_Universal_Aliasing)
11954 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11955 (Get_Rep_Item (Typ, Name_Universal_Aliasing))
11957 Set_Universal_Aliasing (Imp_Bas_Typ);
11962 if Is_Record_Type (Typ) then
11963 if not Has_Rep_Item (Typ, Name_Bit_Order, False)
11964 and then Has_Rep_Item (Typ, Name_Bit_Order)
11966 Set_Reverse_Bit_Order (Bas_Typ,
11967 Reverse_Bit_Order (Rep_Item_Entity
11968 (Get_Rep_Item (Typ, Name_Bit_Order))));
11972 -- Scalar_Storage_Order
11974 -- Note: the aspect is specified on a first subtype, but recorded
11975 -- in a flag of the base type!
11977 if (Is_Record_Type (Typ) or else Is_Array_Type (Typ))
11978 and then Typ = Bas_Typ
11980 -- For a type extension, always inherit from parent; otherwise
11981 -- inherit if no default applies. Note: we do not check for
11982 -- an explicit rep item on the parent type when inheriting,
11983 -- because the parent SSO may itself have been set by default.
11985 if not Has_Rep_Item (First_Subtype (Typ),
11986 Name_Scalar_Storage_Order, False)
11987 and then (Is_Tagged_Type (Bas_Typ)
11988 or else not (SSO_Set_Low_By_Default (Bas_Typ)
11990 SSO_Set_High_By_Default (Bas_Typ)))
11992 Set_Reverse_Storage_Order (Bas_Typ,
11993 Reverse_Storage_Order
11994 (Implementation_Base_Type (Etype (Bas_Typ))));
11996 -- Clear default SSO indications, since the inherited aspect
11997 -- which was set explicitly overrides the default.
11999 Set_SSO_Set_Low_By_Default (Bas_Typ, False);
12000 Set_SSO_Set_High_By_Default (Bas_Typ, False);
12005 end Inherit_Aspects_At_Freeze_Point;
12011 procedure Initialize is
12013 Address_Clause_Checks.Init;
12014 Unchecked_Conversions.Init;
12016 -- ??? Might be needed in the future for some non GCC back-ends
12017 -- if AAMP_On_Target then
12018 -- Independence_Checks.Init;
12022 ---------------------------
12023 -- Install_Discriminants --
12024 ---------------------------
12026 procedure Install_Discriminants (E : Entity_Id) is
12030 Disc := First_Discriminant (E);
12031 while Present (Disc) loop
12032 Prev := Current_Entity (Disc);
12033 Set_Current_Entity (Disc);
12034 Set_Is_Immediately_Visible (Disc);
12035 Set_Homonym (Disc, Prev);
12036 Next_Discriminant (Disc);
12038 end Install_Discriminants;
12040 -------------------------
12041 -- Is_Operational_Item --
12042 -------------------------
12044 function Is_Operational_Item (N : Node_Id) return Boolean is
12046 if Nkind (N) /= N_Attribute_Definition_Clause then
12051 Id : constant Attribute_Id := Get_Attribute_Id (Chars (N));
12054 -- List of operational items is given in AARM 13.1(8.mm/1).
12055 -- It is clearly incomplete, as it does not include iterator
12056 -- aspects, among others.
12058 return Id = Attribute_Constant_Indexing
12059 or else Id = Attribute_Default_Iterator
12060 or else Id = Attribute_Implicit_Dereference
12061 or else Id = Attribute_Input
12062 or else Id = Attribute_Iterator_Element
12063 or else Id = Attribute_Iterable
12064 or else Id = Attribute_Output
12065 or else Id = Attribute_Read
12066 or else Id = Attribute_Variable_Indexing
12067 or else Id = Attribute_Write
12068 or else Id = Attribute_External_Tag;
12071 end Is_Operational_Item;
12073 -------------------------
12074 -- Is_Predicate_Static --
12075 -------------------------
12077 -- Note: the basic legality of the expression has already been checked, so
12078 -- we don't need to worry about cases or ranges on strings for example.
12080 function Is_Predicate_Static
12082 Nam : Name_Id) return Boolean
12084 function All_Static_Case_Alternatives (L : List_Id) return Boolean;
12085 -- Given a list of case expression alternatives, returns True if all
12086 -- the alternatives are static (have all static choices, and a static
12089 function All_Static_Choices (L : List_Id) return Boolean;
12090 -- Returns true if all elements of the list are OK static choices
12091 -- as defined below for Is_Static_Choice. Used for case expression
12092 -- alternatives and for the right operand of a membership test. An
12093 -- others_choice is static if the corresponding expression is static.
12094 -- The staticness of the bounds is checked separately.
12096 function Is_Static_Choice (N : Node_Id) return Boolean;
12097 -- Returns True if N represents a static choice (static subtype, or
12098 -- static subtype indication, or static expression, or static range).
12100 -- Note that this is a bit more inclusive than we actually need
12101 -- (in particular membership tests do not allow the use of subtype
12102 -- indications). But that doesn't matter, we have already checked
12103 -- that the construct is legal to get this far.
12105 function Is_Type_Ref (N : Node_Id) return Boolean;
12106 pragma Inline (Is_Type_Ref);
12107 -- Returns True if N is a reference to the type for the predicate in the
12108 -- expression (i.e. if it is an identifier whose Chars field matches the
12109 -- Nam given in the call). N must not be parenthesized, if the type name
12110 -- appears in parens, this routine will return False.
12112 -- The routine also returns True for function calls generated during the
12113 -- expansion of comparison operators on strings, which are intended to
12114 -- be legal in static predicates, and are converted into calls to array
12115 -- comparison routines in the body of the corresponding predicate
12118 ----------------------------------
12119 -- All_Static_Case_Alternatives --
12120 ----------------------------------
12122 function All_Static_Case_Alternatives (L : List_Id) return Boolean is
12127 while Present (N) loop
12128 if not (All_Static_Choices (Discrete_Choices (N))
12129 and then Is_OK_Static_Expression (Expression (N)))
12138 end All_Static_Case_Alternatives;
12140 ------------------------
12141 -- All_Static_Choices --
12142 ------------------------
12144 function All_Static_Choices (L : List_Id) return Boolean is
12149 while Present (N) loop
12150 if not Is_Static_Choice (N) then
12158 end All_Static_Choices;
12160 ----------------------
12161 -- Is_Static_Choice --
12162 ----------------------
12164 function Is_Static_Choice (N : Node_Id) return Boolean is
12166 return Nkind (N) = N_Others_Choice
12167 or else Is_OK_Static_Expression (N)
12168 or else (Is_Entity_Name (N) and then Is_Type (Entity (N))
12169 and then Is_OK_Static_Subtype (Entity (N)))
12170 or else (Nkind (N) = N_Subtype_Indication
12171 and then Is_OK_Static_Subtype (Entity (N)))
12172 or else (Nkind (N) = N_Range and then Is_OK_Static_Range (N));
12173 end Is_Static_Choice;
12179 function Is_Type_Ref (N : Node_Id) return Boolean is
12181 return (Nkind (N) = N_Identifier
12182 and then Chars (N) = Nam
12183 and then Paren_Count (N) = 0)
12184 or else Nkind (N) = N_Function_Call;
12187 -- Start of processing for Is_Predicate_Static
12190 -- Predicate_Static means one of the following holds. Numbers are the
12191 -- corresponding paragraph numbers in (RM 3.2.4(16-22)).
12193 -- 16: A static expression
12195 if Is_OK_Static_Expression (Expr) then
12198 -- 17: A membership test whose simple_expression is the current
12199 -- instance, and whose membership_choice_list meets the requirements
12200 -- for a static membership test.
12202 elsif Nkind (Expr) in N_Membership_Test
12203 and then ((Present (Right_Opnd (Expr))
12204 and then Is_Static_Choice (Right_Opnd (Expr)))
12206 (Present (Alternatives (Expr))
12207 and then All_Static_Choices (Alternatives (Expr))))
12211 -- 18. A case_expression whose selecting_expression is the current
12212 -- instance, and whose dependent expressions are static expressions.
12214 elsif Nkind (Expr) = N_Case_Expression
12215 and then Is_Type_Ref (Expression (Expr))
12216 and then All_Static_Case_Alternatives (Alternatives (Expr))
12220 -- 19. A call to a predefined equality or ordering operator, where one
12221 -- operand is the current instance, and the other is a static
12224 -- Note: the RM is clearly wrong here in not excluding string types.
12225 -- Without this exclusion, we would allow expressions like X > "ABC"
12226 -- to be considered as predicate-static, which is clearly not intended,
12227 -- since the idea is for predicate-static to be a subset of normal
12228 -- static expressions (and "DEF" > "ABC" is not a static expression).
12230 -- However, we do allow internally generated (not from source) equality
12231 -- and inequality operations to be valid on strings (this helps deal
12232 -- with cases where we transform A in "ABC" to A = "ABC).
12234 -- In fact, it appears that the intent of the ARG is to extend static
12235 -- predicates to strings, and that the extension should probably apply
12236 -- to static expressions themselves. The code below accepts comparison
12237 -- operators that apply to static strings.
12239 elsif Nkind (Expr) in N_Op_Compare
12240 and then ((Is_Type_Ref (Left_Opnd (Expr))
12241 and then Is_OK_Static_Expression (Right_Opnd (Expr)))
12243 (Is_Type_Ref (Right_Opnd (Expr))
12244 and then Is_OK_Static_Expression (Left_Opnd (Expr))))
12248 -- 20. A call to a predefined boolean logical operator, where each
12249 -- operand is predicate-static.
12251 elsif (Nkind_In (Expr, N_Op_And, N_Op_Or, N_Op_Xor)
12252 and then Is_Predicate_Static (Left_Opnd (Expr), Nam)
12253 and then Is_Predicate_Static (Right_Opnd (Expr), Nam))
12255 (Nkind (Expr) = N_Op_Not
12256 and then Is_Predicate_Static (Right_Opnd (Expr), Nam))
12260 -- 21. A short-circuit control form where both operands are
12261 -- predicate-static.
12263 elsif Nkind (Expr) in N_Short_Circuit
12264 and then Is_Predicate_Static (Left_Opnd (Expr), Nam)
12265 and then Is_Predicate_Static (Right_Opnd (Expr), Nam)
12269 -- 22. A parenthesized predicate-static expression. This does not
12270 -- require any special test, since we just ignore paren levels in
12271 -- all the cases above.
12273 -- One more test that is an implementation artifact caused by the fact
12274 -- that we are analyzing not the original expression, but the generated
12275 -- expression in the body of the predicate function. This can include
12276 -- references to inherited predicates, so that the expression we are
12277 -- processing looks like:
12279 -- xxPredicate (typ (Inns)) and then expression
12281 -- Where the call is to a Predicate function for an inherited predicate.
12282 -- We simply ignore such a call, which could be to either a dynamic or
12283 -- a static predicate. Note that if the parent predicate is dynamic then
12284 -- eventually this type will be marked as dynamic, but you are allowed
12285 -- to specify a static predicate for a subtype which is inheriting a
12286 -- dynamic predicate, so the static predicate validation here ignores
12287 -- the inherited predicate even if it is dynamic.
12288 -- In all cases, a static predicate can only apply to a scalar type.
12290 elsif Nkind (Expr) = N_Function_Call
12291 and then Is_Predicate_Function (Entity (Name (Expr)))
12292 and then Is_Scalar_Type (Etype (First_Entity (Entity (Name (Expr)))))
12296 elsif Is_Entity_Name (Expr)
12297 and then Entity (Expr) = Standard_True
12299 Error_Msg_N ("predicate is redundant (always True)?", Expr);
12302 -- That's an exhaustive list of tests, all other cases are not
12303 -- predicate-static, so we return False.
12308 end Is_Predicate_Static;
12310 ------------------------------
12311 -- Is_Type_Related_Rep_Item --
12312 ------------------------------
12314 function Is_Type_Related_Rep_Item (N : Node_Id) return Boolean is
12317 when N_Attribute_Definition_Clause =>
12319 Id : constant Attribute_Id := Get_Attribute_Id (Chars (N));
12320 -- See AARM 13.1(8.f-8.x) list items that end in "clause"
12321 -- ???: include any GNAT-defined attributes here?
12323 return Id = Attribute_Component_Size
12324 or else Id = Attribute_Bit_Order
12325 or else Id = Attribute_Storage_Pool
12326 or else Id = Attribute_Stream_Size
12327 or else Id = Attribute_Machine_Radix;
12331 case Get_Pragma_Id (N) is
12332 -- See AARM 13.1(8.f-8.x) list items that start with "pragma"
12333 -- ???: include any GNAT-defined pragmas here?
12337 | Pragma_Convention
12339 | Pragma_Independent
12341 | Pragma_Atomic_Components
12342 | Pragma_Independent_Components
12343 | Pragma_Volatile_Components
12344 | Pragma_Discard_Names
12351 when N_Enumeration_Representation_Clause
12352 | N_Record_Representation_Clause
12361 end Is_Type_Related_Rep_Item;
12363 ---------------------
12364 -- Kill_Rep_Clause --
12365 ---------------------
12367 procedure Kill_Rep_Clause (N : Node_Id) is
12369 pragma Assert (Ignore_Rep_Clauses);
12371 -- Note: we use Replace rather than Rewrite, because we don't want
12372 -- ASIS to be able to use Original_Node to dig out the (undecorated)
12373 -- rep clause that is being replaced.
12375 Replace (N, Make_Null_Statement (Sloc (N)));
12377 -- The null statement must be marked as not coming from source. This is
12378 -- so that ASIS ignores it, and also the back end does not expect bogus
12379 -- "from source" null statements in weird places (e.g. in declarative
12380 -- regions where such null statements are not allowed).
12382 Set_Comes_From_Source (N, False);
12383 end Kill_Rep_Clause;
12389 function Minimum_Size
12391 Biased : Boolean := False) return Nat
12393 Lo : Uint := No_Uint;
12394 Hi : Uint := No_Uint;
12395 LoR : Ureal := No_Ureal;
12396 HiR : Ureal := No_Ureal;
12397 LoSet : Boolean := False;
12398 HiSet : Boolean := False;
12401 Ancest : Entity_Id;
12402 R_Typ : constant Entity_Id := Root_Type (T);
12405 -- If bad type, return 0
12407 if T = Any_Type then
12410 -- For generic types, just return zero. There cannot be any legitimate
12411 -- need to know such a size, but this routine may be called with a
12412 -- generic type as part of normal processing.
12414 elsif Is_Generic_Type (R_Typ) or else R_Typ = Any_Type then
12417 -- Access types (cannot have size smaller than System.Address)
12419 elsif Is_Access_Type (T) then
12420 return System_Address_Size;
12422 -- Floating-point types
12424 elsif Is_Floating_Point_Type (T) then
12425 return UI_To_Int (Esize (R_Typ));
12429 elsif Is_Discrete_Type (T) then
12431 -- The following loop is looking for the nearest compile time known
12432 -- bounds following the ancestor subtype chain. The idea is to find
12433 -- the most restrictive known bounds information.
12437 if Ancest = Any_Type or else Etype (Ancest) = Any_Type then
12442 if Compile_Time_Known_Value (Type_Low_Bound (Ancest)) then
12443 Lo := Expr_Rep_Value (Type_Low_Bound (Ancest));
12450 if Compile_Time_Known_Value (Type_High_Bound (Ancest)) then
12451 Hi := Expr_Rep_Value (Type_High_Bound (Ancest));
12457 Ancest := Ancestor_Subtype (Ancest);
12459 if No (Ancest) then
12460 Ancest := Base_Type (T);
12462 if Is_Generic_Type (Ancest) then
12468 -- Fixed-point types. We can't simply use Expr_Value to get the
12469 -- Corresponding_Integer_Value values of the bounds, since these do not
12470 -- get set till the type is frozen, and this routine can be called
12471 -- before the type is frozen. Similarly the test for bounds being static
12472 -- needs to include the case where we have unanalyzed real literals for
12473 -- the same reason.
12475 elsif Is_Fixed_Point_Type (T) then
12477 -- The following loop is looking for the nearest compile time known
12478 -- bounds following the ancestor subtype chain. The idea is to find
12479 -- the most restrictive known bounds information.
12483 if Ancest = Any_Type or else Etype (Ancest) = Any_Type then
12487 -- Note: In the following two tests for LoSet and HiSet, it may
12488 -- seem redundant to test for N_Real_Literal here since normally
12489 -- one would assume that the test for the value being known at
12490 -- compile time includes this case. However, there is a glitch.
12491 -- If the real literal comes from folding a non-static expression,
12492 -- then we don't consider any non- static expression to be known
12493 -- at compile time if we are in configurable run time mode (needed
12494 -- in some cases to give a clearer definition of what is and what
12495 -- is not accepted). So the test is indeed needed. Without it, we
12496 -- would set neither Lo_Set nor Hi_Set and get an infinite loop.
12499 if Nkind (Type_Low_Bound (Ancest)) = N_Real_Literal
12500 or else Compile_Time_Known_Value (Type_Low_Bound (Ancest))
12502 LoR := Expr_Value_R (Type_Low_Bound (Ancest));
12509 if Nkind (Type_High_Bound (Ancest)) = N_Real_Literal
12510 or else Compile_Time_Known_Value (Type_High_Bound (Ancest))
12512 HiR := Expr_Value_R (Type_High_Bound (Ancest));
12518 Ancest := Ancestor_Subtype (Ancest);
12520 if No (Ancest) then
12521 Ancest := Base_Type (T);
12523 if Is_Generic_Type (Ancest) then
12529 Lo := UR_To_Uint (LoR / Small_Value (T));
12530 Hi := UR_To_Uint (HiR / Small_Value (T));
12532 -- No other types allowed
12535 raise Program_Error;
12538 -- Fall through with Hi and Lo set. Deal with biased case
12541 and then not Is_Fixed_Point_Type (T)
12542 and then not (Is_Enumeration_Type (T)
12543 and then Has_Non_Standard_Rep (T)))
12544 or else Has_Biased_Representation (T)
12550 -- Null range case, size is always zero. We only do this in the discrete
12551 -- type case, since that's the odd case that came up. Probably we should
12552 -- also do this in the fixed-point case, but doing so causes peculiar
12553 -- gigi failures, and it is not worth worrying about this incredibly
12554 -- marginal case (explicit null-range fixed-point type declarations)???
12556 if Lo > Hi and then Is_Discrete_Type (T) then
12559 -- Signed case. Note that we consider types like range 1 .. -1 to be
12560 -- signed for the purpose of computing the size, since the bounds have
12561 -- to be accommodated in the base type.
12563 elsif Lo < 0 or else Hi < 0 then
12567 -- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1))
12568 -- Note that we accommodate the case where the bounds cross. This
12569 -- can happen either because of the way the bounds are declared
12570 -- or because of the algorithm in Freeze_Fixed_Point_Type.
12584 -- If both bounds are positive, make sure that both are represen-
12585 -- table in the case where the bounds are crossed. This can happen
12586 -- either because of the way the bounds are declared, or because of
12587 -- the algorithm in Freeze_Fixed_Point_Type.
12593 -- S = size, (can accommodate 0 .. (2**size - 1))
12596 while Hi >= Uint_2 ** S loop
12604 ---------------------------
12605 -- New_Stream_Subprogram --
12606 ---------------------------
12608 procedure New_Stream_Subprogram
12612 Nam : TSS_Name_Type)
12614 Loc : constant Source_Ptr := Sloc (N);
12615 Sname : constant Name_Id := Make_TSS_Name (Base_Type (Ent), Nam);
12616 Subp_Id : Entity_Id;
12617 Subp_Decl : Node_Id;
12621 Defer_Declaration : constant Boolean :=
12622 Is_Tagged_Type (Ent) or else Is_Private_Type (Ent);
12623 -- For a tagged type, there is a declaration for each stream attribute
12624 -- at the freeze point, and we must generate only a completion of this
12625 -- declaration. We do the same for private types, because the full view
12626 -- might be tagged. Otherwise we generate a declaration at the point of
12627 -- the attribute definition clause. If the attribute definition comes
12628 -- from an aspect specification the declaration is part of the freeze
12629 -- actions of the type.
12631 function Build_Spec return Node_Id;
12632 -- Used for declaration and renaming declaration, so that this is
12633 -- treated as a renaming_as_body.
12639 function Build_Spec return Node_Id is
12640 Out_P : constant Boolean := (Nam = TSS_Stream_Read);
12643 T_Ref : constant Node_Id := New_Occurrence_Of (Etyp, Loc);
12646 Subp_Id := Make_Defining_Identifier (Loc, Sname);
12648 -- S : access Root_Stream_Type'Class
12650 Formals := New_List (
12651 Make_Parameter_Specification (Loc,
12652 Defining_Identifier =>
12653 Make_Defining_Identifier (Loc, Name_S),
12655 Make_Access_Definition (Loc,
12657 New_Occurrence_Of (
12658 Designated_Type (Etype (F)), Loc))));
12660 if Nam = TSS_Stream_Input then
12662 Make_Function_Specification (Loc,
12663 Defining_Unit_Name => Subp_Id,
12664 Parameter_Specifications => Formals,
12665 Result_Definition => T_Ref);
12669 Append_To (Formals,
12670 Make_Parameter_Specification (Loc,
12671 Defining_Identifier => Make_Defining_Identifier (Loc, Name_V),
12672 Out_Present => Out_P,
12673 Parameter_Type => T_Ref));
12676 Make_Procedure_Specification (Loc,
12677 Defining_Unit_Name => Subp_Id,
12678 Parameter_Specifications => Formals);
12684 -- Start of processing for New_Stream_Subprogram
12687 F := First_Formal (Subp);
12689 if Ekind (Subp) = E_Procedure then
12690 Etyp := Etype (Next_Formal (F));
12692 Etyp := Etype (Subp);
12695 -- Prepare subprogram declaration and insert it as an action on the
12696 -- clause node. The visibility for this entity is used to test for
12697 -- visibility of the attribute definition clause (in the sense of
12698 -- 8.3(23) as amended by AI-195).
12700 if not Defer_Declaration then
12702 Make_Subprogram_Declaration (Loc,
12703 Specification => Build_Spec);
12705 -- For a tagged type, there is always a visible declaration for each
12706 -- stream TSS (it is a predefined primitive operation), and the
12707 -- completion of this declaration occurs at the freeze point, which is
12708 -- not always visible at places where the attribute definition clause is
12709 -- visible. So, we create a dummy entity here for the purpose of
12710 -- tracking the visibility of the attribute definition clause itself.
12714 Make_Defining_Identifier (Loc, New_External_Name (Sname, 'V'));
12716 Make_Object_Declaration (Loc,
12717 Defining_Identifier => Subp_Id,
12718 Object_Definition => New_Occurrence_Of (Standard_Boolean, Loc));
12721 if not Defer_Declaration
12722 and then From_Aspect_Specification (N)
12723 and then Has_Delayed_Freeze (Ent)
12725 Append_Freeze_Action (Ent, Subp_Decl);
12728 Insert_Action (N, Subp_Decl);
12729 Set_Entity (N, Subp_Id);
12733 Make_Subprogram_Renaming_Declaration (Loc,
12734 Specification => Build_Spec,
12735 Name => New_Occurrence_Of (Subp, Loc));
12737 if Defer_Declaration then
12738 Set_TSS (Base_Type (Ent), Subp_Id);
12741 if From_Aspect_Specification (N) then
12742 Append_Freeze_Action (Ent, Subp_Decl);
12744 Insert_Action (N, Subp_Decl);
12747 Copy_TSS (Subp_Id, Base_Type (Ent));
12749 end New_Stream_Subprogram;
12755 procedure Pop_Type (E : Entity_Id) is
12757 if Ekind (E) = E_Record_Type and then E = Current_Scope then
12761 and then Has_Discriminants (E)
12762 and then Nkind (Parent (E)) /= N_Subtype_Declaration
12764 Uninstall_Discriminants (E);
12773 procedure Push_Type (E : Entity_Id) is
12777 if Ekind (E) = E_Record_Type then
12780 Comp := First_Component (E);
12781 while Present (Comp) loop
12782 Install_Entity (Comp);
12783 Next_Component (Comp);
12786 if Has_Discriminants (E) then
12787 Install_Discriminants (E);
12791 and then Has_Discriminants (E)
12792 and then Nkind (Parent (E)) /= N_Subtype_Declaration
12795 Install_Discriminants (E);
12799 -----------------------------------
12800 -- Register_Address_Clause_Check --
12801 -----------------------------------
12803 procedure Register_Address_Clause_Check
12810 ACS : constant Boolean := Scope_Suppress.Suppress (Alignment_Check);
12812 Address_Clause_Checks.Append ((N, X, A, Y, Off, ACS));
12813 end Register_Address_Clause_Check;
12815 ------------------------
12816 -- Rep_Item_Too_Early --
12817 ------------------------
12819 function Rep_Item_Too_Early (T : Entity_Id; N : Node_Id) return Boolean is
12820 function Has_Generic_Parent (E : Entity_Id) return Boolean;
12821 -- Return True if any ancestor is a generic type
12823 ------------------------
12824 -- Has_Generic_Parent --
12825 ------------------------
12827 function Has_Generic_Parent (E : Entity_Id) return Boolean is
12828 Ancestor_Type : Entity_Id := Etype (E);
12831 while Present (Ancestor_Type)
12832 and then not Is_Generic_Type (Ancestor_Type)
12833 and then Etype (Ancestor_Type) /= Ancestor_Type
12835 Ancestor_Type := Etype (Ancestor_Type);
12839 Present (Ancestor_Type) and then Is_Generic_Type (Ancestor_Type);
12840 end Has_Generic_Parent;
12842 -- Start of processing for Rep_Item_Too_Early
12845 -- Cannot apply non-operational rep items to generic types
12847 if Is_Operational_Item (N) then
12851 and then Has_Generic_Parent (T)
12852 and then (Nkind (N) /= N_Pragma
12853 or else Get_Pragma_Id (N) /= Pragma_Convention)
12855 if Ada_Version < Ada_2020 then
12857 ("representation item not allowed for generic type", N);
12864 -- Otherwise check for incomplete type
12866 if Is_Incomplete_Or_Private_Type (T)
12867 and then No (Underlying_Type (T))
12869 (Nkind (N) /= N_Pragma
12870 or else Get_Pragma_Id (N) /= Pragma_Import)
12873 ("representation item must be after full type declaration", N);
12876 -- If the type has incomplete components, a representation clause is
12877 -- illegal but stream attributes and Convention pragmas are correct.
12879 elsif Has_Private_Component (T) then
12880 if Nkind (N) = N_Pragma then
12885 ("representation item must appear after type is fully defined",
12892 end Rep_Item_Too_Early;
12894 -----------------------
12895 -- Rep_Item_Too_Late --
12896 -----------------------
12898 function Rep_Item_Too_Late
12901 FOnly : Boolean := False) return Boolean
12903 function Is_Derived_Type_With_Constraint return Boolean;
12904 -- Check whether T is a derived type with an explicit constraint, in
12905 -- which case the constraint has frozen the type and the item is too
12906 -- late. This compensates for the fact that for derived scalar types
12907 -- we freeze the base type unconditionally on account of a long-standing
12910 procedure No_Type_Rep_Item;
12911 -- Output message indicating that no type-related aspects can be
12912 -- specified due to some property of the parent type.
12914 procedure Too_Late;
12915 -- Output message for an aspect being specified too late
12917 -- Note that neither of the above errors is considered a serious one,
12918 -- since the effect is simply that we ignore the representation clause
12920 -- Is this really true? In any case if we make this change we must
12921 -- document the requirement in the spec of Rep_Item_Too_Late that
12922 -- if True is returned, then the rep item must be completely ignored???
12924 --------------------------------------
12925 -- Is_Derived_Type_With_Constraint --
12926 --------------------------------------
12928 function Is_Derived_Type_With_Constraint return Boolean is
12929 Decl : constant Node_Id := Declaration_Node (T);
12932 return Is_Derived_Type (T)
12933 and then Is_Frozen (Base_Type (T))
12934 and then Is_Enumeration_Type (T)
12936 and then Nkind (N) = N_Enumeration_Representation_Clause
12937 and then Nkind (Decl) = N_Subtype_Declaration
12938 and then not Is_Entity_Name (Subtype_Indication (Decl));
12939 end Is_Derived_Type_With_Constraint;
12941 ----------------------
12942 -- No_Type_Rep_Item --
12943 ----------------------
12945 procedure No_Type_Rep_Item is
12947 Error_Msg_N ("|type-related representation item not permitted!", N);
12948 end No_Type_Rep_Item;
12954 procedure Too_Late is
12956 -- Other compilers seem more relaxed about rep items appearing too
12957 -- late. Since analysis tools typically don't care about rep items
12958 -- anyway, no reason to be too strict about this.
12960 if not Relaxed_RM_Semantics then
12961 Error_Msg_N ("|representation item appears too late!", N);
12967 Parent_Type : Entity_Id;
12970 -- Start of processing for Rep_Item_Too_Late
12973 -- First make sure entity is not frozen (RM 13.1(9))
12976 or else (Is_Type (T)
12977 and then Is_Derived_Type_With_Constraint))
12979 -- Exclude imported types, which may be frozen if they appear in a
12980 -- representation clause for a local type.
12982 and then not From_Limited_With (T)
12984 -- Exclude generated entities (not coming from source). The common
12985 -- case is when we generate a renaming which prematurely freezes the
12986 -- renamed internal entity, but we still want to be able to set copies
12987 -- of attribute values such as Size/Alignment.
12989 and then Comes_From_Source (T)
12991 -- A self-referential aspect is illegal if it forces freezing the
12992 -- entity before the corresponding pragma has been analyzed.
12994 if Nkind_In (N, N_Attribute_Definition_Clause, N_Pragma)
12995 and then From_Aspect_Specification (N)
12998 ("aspect specification causes premature freezing of&", N, T);
12999 Set_Has_Delayed_Freeze (T, False);
13004 S := First_Subtype (T);
13006 if Present (Freeze_Node (S)) then
13007 if not Relaxed_RM_Semantics then
13009 ("??no more representation items for }", Freeze_Node (S), S);
13015 -- Check for case of untagged derived type whose parent either has
13016 -- primitive operations, or is a by reference type (RM 13.1(10)). In
13017 -- this case we do not output a Too_Late message, since there is no
13018 -- earlier point where the rep item could be placed to make it legal.
13022 and then Is_Derived_Type (T)
13023 and then not Is_Tagged_Type (T)
13025 Parent_Type := Etype (Base_Type (T));
13027 if Has_Primitive_Operations (Parent_Type) then
13030 if not Relaxed_RM_Semantics then
13032 ("\parent type & has primitive operations!", N, Parent_Type);
13037 elsif Is_By_Reference_Type (Parent_Type) then
13040 if not Relaxed_RM_Semantics then
13042 ("\parent type & is a by reference type!", N, Parent_Type);
13049 -- No error, but one more warning to consider. The RM (surprisingly)
13050 -- allows this pattern in some cases:
13053 -- primitive operations for S
13054 -- type R is new S;
13055 -- rep clause for S
13057 -- Meaning that calls on the primitive operations of S for values of
13058 -- type R may require possibly expensive implicit conversion operations.
13059 -- So even when this is not an error, it is still worth a warning.
13061 if not Relaxed_RM_Semantics and then Is_Type (T) then
13063 DTL : constant Entity_Id := Derived_Type_Link (Base_Type (T));
13068 -- For now, do not generate this warning for the case of
13069 -- aspect specification using Ada 2012 syntax, since we get
13070 -- wrong messages we do not understand. The whole business
13071 -- of derived types and rep items seems a bit confused when
13072 -- aspects are used, since the aspects are not evaluated
13073 -- till freeze time. However, AI12-0109 confirms (in an AARM
13074 -- ramification) that inheritance in this case is required
13077 and then not From_Aspect_Specification (N)
13079 if Is_By_Reference_Type (T)
13080 and then not Is_Tagged_Type (T)
13081 and then Is_Type_Related_Rep_Item (N)
13082 and then (Ada_Version >= Ada_2012
13083 or else Has_Primitive_Operations (Base_Type (T)))
13085 -- Treat as hard error (AI12-0109, binding interpretation).
13086 -- Implementing a change of representation is not really
13087 -- an option in the case of a by-reference type, so we
13088 -- take this path for all Ada dialects if primitive
13089 -- operations are present.
13090 Error_Msg_Sloc := Sloc (DTL);
13092 ("representation item for& appears after derived type "
13093 & "declaration#", N);
13095 elsif Has_Primitive_Operations (Base_Type (T)) then
13096 Error_Msg_Sloc := Sloc (DTL);
13099 ("representation item for& appears after derived type "
13100 & "declaration#??", N);
13102 ("\may result in implicit conversions for primitive "
13103 & "operations of&??", N, T);
13105 ("\to change representations when called with arguments "
13106 & "of type&??", N, DTL);
13112 -- No error, link item into head of chain of rep items for the entity,
13113 -- but avoid chaining if we have an overloadable entity, and the pragma
13114 -- is one that can apply to multiple overloaded entities.
13116 if Is_Overloadable (T) and then Nkind (N) = N_Pragma then
13118 Pname : constant Name_Id := Pragma_Name (N);
13120 if Nam_In (Pname, Name_Convention, Name_Import, Name_Export,
13121 Name_External, Name_Interface)
13128 Record_Rep_Item (T, N);
13130 end Rep_Item_Too_Late;
13132 -------------------------------------
13133 -- Replace_Type_References_Generic --
13134 -------------------------------------
13136 procedure Replace_Type_References_Generic (N : Node_Id; T : Entity_Id) is
13137 TName : constant Name_Id := Chars (T);
13139 function Replace_Type_Ref (N : Node_Id) return Traverse_Result;
13140 -- Processes a single node in the traversal procedure below, checking
13141 -- if node N should be replaced, and if so, doing the replacement.
13143 function Visible_Component (Comp : Name_Id) return Entity_Id;
13144 -- Given an identifier in the expression, check whether there is a
13145 -- discriminant or component of the type that is directy visible, and
13146 -- rewrite it as the corresponding selected component of the formal of
13147 -- the subprogram. The entity is located by a sequential search, which
13148 -- seems acceptable given the typical size of component lists and check
13149 -- expressions. Possible optimization ???
13151 ----------------------
13152 -- Replace_Type_Ref --
13153 ----------------------
13155 function Replace_Type_Ref (N : Node_Id) return Traverse_Result is
13156 Loc : constant Source_Ptr := Sloc (N);
13158 procedure Add_Prefix (Ref : Node_Id; Comp : Entity_Id);
13159 -- Add the proper prefix to a reference to a component of the type
13160 -- when it is not already a selected component.
13166 procedure Add_Prefix (Ref : Node_Id; Comp : Entity_Id) is
13169 Make_Selected_Component (Loc,
13170 Prefix => New_Occurrence_Of (T, Loc),
13171 Selector_Name => New_Occurrence_Of (Comp, Loc)));
13172 Replace_Type_Reference (Prefix (Ref));
13181 -- Start of processing for Replace_Type_Ref
13184 if Nkind (N) = N_Identifier then
13186 -- If not the type name, check whether it is a reference to some
13187 -- other type, which must be frozen before the predicate function
13188 -- is analyzed, i.e. before the freeze node of the type to which
13189 -- the predicate applies.
13191 if Chars (N) /= TName then
13192 if Present (Current_Entity (N))
13193 and then Is_Type (Current_Entity (N))
13195 Freeze_Before (Freeze_Node (T), Current_Entity (N));
13198 -- The components of the type are directly visible and can
13199 -- be referenced without a prefix.
13201 if Nkind (Parent (N)) = N_Selected_Component then
13204 -- In expression C (I), C may be a directly visible function
13205 -- or a visible component that has an array type. Disambiguate
13206 -- by examining the component type.
13208 elsif Nkind (Parent (N)) = N_Indexed_Component
13209 and then N = Prefix (Parent (N))
13211 Comp := Visible_Component (Chars (N));
13213 if Present (Comp) and then Is_Array_Type (Etype (Comp)) then
13214 Add_Prefix (N, Comp);
13218 Comp := Visible_Component (Chars (N));
13220 if Present (Comp) then
13221 Add_Prefix (N, Comp);
13227 -- Otherwise do the replacement if this is not a qualified
13228 -- reference to a homograph of the type itself. Note that the
13229 -- current instance could not appear in such a context, e.g.
13230 -- the prefix of a type conversion.
13233 if Nkind (Parent (N)) /= N_Selected_Component
13234 or else N /= Selector_Name (Parent (N))
13236 Replace_Type_Reference (N);
13242 -- Case of selected component, which may be a subcomponent of the
13243 -- current instance, or an expanded name which is still unanalyzed.
13245 elsif Nkind (N) = N_Selected_Component then
13247 -- If selector name is not our type, keep going (we might still
13248 -- have an occurrence of the type in the prefix). If it is a
13249 -- subcomponent of the current entity, add prefix.
13251 if Nkind (Selector_Name (N)) /= N_Identifier
13252 or else Chars (Selector_Name (N)) /= TName
13254 if Nkind (Prefix (N)) = N_Identifier then
13255 Comp := Visible_Component (Chars (Prefix (N)));
13257 if Present (Comp) then
13258 Add_Prefix (Prefix (N), Comp);
13264 -- Selector name is our type, check qualification
13267 -- Loop through scopes and prefixes, doing comparison
13269 Scop := Current_Scope;
13270 Pref := Prefix (N);
13272 -- Continue if no more scopes or scope with no name
13274 if No (Scop) or else Nkind (Scop) not in N_Has_Chars then
13278 -- Do replace if prefix is an identifier matching the scope
13279 -- that we are currently looking at.
13281 if Nkind (Pref) = N_Identifier
13282 and then Chars (Pref) = Chars (Scop)
13284 Replace_Type_Reference (N);
13288 -- Go check scope above us if prefix is itself of the form
13289 -- of a selected component, whose selector matches the scope
13290 -- we are currently looking at.
13292 if Nkind (Pref) = N_Selected_Component
13293 and then Nkind (Selector_Name (Pref)) = N_Identifier
13294 and then Chars (Selector_Name (Pref)) = Chars (Scop)
13296 Scop := Scope (Scop);
13297 Pref := Prefix (Pref);
13299 -- For anything else, we don't have a match, so keep on
13300 -- going, there are still some weird cases where we may
13301 -- still have a replacement within the prefix.
13309 -- Continue for any other node kind
13314 end Replace_Type_Ref;
13316 procedure Replace_Type_Refs is new Traverse_Proc (Replace_Type_Ref);
13318 -----------------------
13319 -- Visible_Component --
13320 -----------------------
13322 function Visible_Component (Comp : Name_Id) return Entity_Id is
13326 -- Types with nameable components are records and discriminated
13329 if Ekind (T) = E_Record_Type
13330 or else (Is_Private_Type (T) and then Has_Discriminants (T))
13332 E := First_Entity (T);
13333 while Present (E) loop
13334 if Comes_From_Source (E) and then Chars (E) = Comp then
13342 -- Nothing by that name, or the type has no components
13345 end Visible_Component;
13347 -- Start of processing for Replace_Type_References_Generic
13350 Replace_Type_Refs (N);
13351 end Replace_Type_References_Generic;
13353 --------------------------------
13354 -- Resolve_Aspect_Expressions --
13355 --------------------------------
13357 procedure Resolve_Aspect_Expressions (E : Entity_Id) is
13358 function Resolve_Name (N : Node_Id) return Traverse_Result;
13359 -- Verify that all identifiers in the expression, with the exception
13360 -- of references to the current entity, denote visible entities. This
13361 -- is done only to detect visibility errors, as the expression will be
13362 -- properly analyzed/expanded during analysis of the predicate function
13363 -- body. We omit quantified expressions from this test, given that they
13364 -- introduce a local identifier that would require proper expansion to
13365 -- handle properly.
13367 -- In ASIS_Mode we preserve the entity in the source because there is
13368 -- no subsequent expansion to decorate the tree.
13374 function Resolve_Name (N : Node_Id) return Traverse_Result is
13375 Dummy : Traverse_Result;
13378 if Nkind (N) = N_Selected_Component then
13379 if Nkind (Prefix (N)) = N_Identifier
13380 and then Chars (Prefix (N)) /= Chars (E)
13382 Find_Selected_Component (N);
13387 -- Resolve identifiers that are not selectors in parameter
13388 -- associations (these are never resolved by visibility).
13390 elsif Nkind (N) = N_Identifier
13391 and then Chars (N) /= Chars (E)
13392 and then (Nkind (Parent (N)) /= N_Parameter_Association
13393 or else N /= Selector_Name (Parent (N)))
13395 Find_Direct_Name (N);
13397 -- In ASIS mode we must analyze overloaded identifiers to ensure
13398 -- their correct decoration because expansion is disabled (and
13399 -- the expansion of freeze nodes takes care of resolving aspect
13403 if Is_Overloaded (N) then
13404 Analyze (Parent (N));
13407 Set_Entity (N, Empty);
13410 -- The name is component association needs no resolution.
13412 elsif Nkind (N) = N_Component_Association then
13413 Dummy := Resolve_Name (Expression (N));
13416 elsif Nkind (N) = N_Quantified_Expression then
13423 procedure Resolve_Aspect_Expression is new Traverse_Proc (Resolve_Name);
13427 ASN : Node_Id := First_Rep_Item (E);
13429 -- Start of processing for Resolve_Aspect_Expressions
13436 while Present (ASN) loop
13437 if Nkind (ASN) = N_Aspect_Specification and then Entity (ASN) = E then
13439 A_Id : constant Aspect_Id := Get_Aspect_Id (ASN);
13440 Expr : constant Node_Id := Expression (ASN);
13445 -- For now we only deal with aspects that do not generate
13446 -- subprograms, or that may mention current instances of
13447 -- types. These will require special handling (???TBD).
13449 when Aspect_Invariant
13451 | Aspect_Predicate_Failure
13455 when Aspect_Dynamic_Predicate
13456 | Aspect_Static_Predicate
13458 -- Build predicate function specification and preanalyze
13459 -- expression after type replacement. The function
13460 -- declaration must be analyzed in the scope of the type,
13461 -- but the expression can reference components and
13462 -- discriminants of the type.
13464 if No (Predicate_Function (E)) then
13466 FDecl : constant Node_Id :=
13467 Build_Predicate_Function_Declaration (E);
13468 pragma Unreferenced (FDecl);
13472 Resolve_Aspect_Expression (Expr);
13477 when Pre_Post_Aspects =>
13480 when Aspect_Iterable =>
13481 if Nkind (Expr) = N_Aggregate then
13486 Assoc := First (Component_Associations (Expr));
13487 while Present (Assoc) loop
13488 Find_Direct_Name (Expression (Assoc));
13494 -- The expression for Default_Value is a static expression
13495 -- of the type, but this expression does not freeze the
13496 -- type, so it can still appear in a representation clause
13497 -- before the actual freeze point.
13499 when Aspect_Default_Value =>
13500 Set_Must_Not_Freeze (Expr);
13501 Preanalyze_Spec_Expression (Expr, E);
13503 when Aspect_Priority =>
13505 Preanalyze_Spec_Expression (Expr, Any_Integer);
13508 -- Ditto for Storage_Size. Any other aspects that carry
13509 -- expressions that should not freeze ??? This is only
13510 -- relevant to the misuse of deferred constants.
13512 when Aspect_Storage_Size =>
13513 Set_Must_Not_Freeze (Expr);
13514 Preanalyze_Spec_Expression (Expr, Any_Integer);
13517 if Present (Expr) then
13518 case Aspect_Argument (A_Id) is
13520 | Optional_Expression
13522 Analyze_And_Resolve (Expr);
13527 if Nkind (Expr) = N_Identifier then
13528 Find_Direct_Name (Expr);
13530 elsif Nkind (Expr) = N_Selected_Component then
13531 Find_Selected_Component (Expr);
13539 ASN := Next_Rep_Item (ASN);
13541 end Resolve_Aspect_Expressions;
13543 -------------------------
13544 -- Same_Representation --
13545 -------------------------
13547 function Same_Representation (Typ1, Typ2 : Entity_Id) return Boolean is
13548 T1 : constant Entity_Id := Underlying_Type (Typ1);
13549 T2 : constant Entity_Id := Underlying_Type (Typ2);
13552 -- A quick check, if base types are the same, then we definitely have
13553 -- the same representation, because the subtype specific representation
13554 -- attributes (Size and Alignment) do not affect representation from
13555 -- the point of view of this test.
13557 if Base_Type (T1) = Base_Type (T2) then
13560 elsif Is_Private_Type (Base_Type (T2))
13561 and then Base_Type (T1) = Full_View (Base_Type (T2))
13565 -- If T2 is a generic actual it is declared as a subtype, so
13566 -- check against its base type.
13568 elsif Is_Generic_Actual_Type (T1)
13569 and then Same_Representation (Base_Type (T1), T2)
13574 -- Tagged types always have the same representation, because it is not
13575 -- possible to specify different representations for common fields.
13577 if Is_Tagged_Type (T1) then
13581 -- Representations are definitely different if conventions differ
13583 if Convention (T1) /= Convention (T2) then
13587 -- Representations are different if component alignments or scalar
13588 -- storage orders differ.
13590 if (Is_Record_Type (T1) or else Is_Array_Type (T1))
13592 (Is_Record_Type (T2) or else Is_Array_Type (T2))
13594 (Component_Alignment (T1) /= Component_Alignment (T2)
13595 or else Reverse_Storage_Order (T1) /= Reverse_Storage_Order (T2))
13600 -- For arrays, the only real issue is component size. If we know the
13601 -- component size for both arrays, and it is the same, then that's
13602 -- good enough to know we don't have a change of representation.
13604 if Is_Array_Type (T1) then
13605 if Known_Component_Size (T1)
13606 and then Known_Component_Size (T2)
13607 and then Component_Size (T1) = Component_Size (T2)
13613 -- For records, representations are different if reorderings differ
13615 if Is_Record_Type (T1)
13616 and then Is_Record_Type (T2)
13617 and then No_Reordering (T1) /= No_Reordering (T2)
13622 -- Types definitely have same representation if neither has non-standard
13623 -- representation since default representations are always consistent.
13624 -- If only one has non-standard representation, and the other does not,
13625 -- then we consider that they do not have the same representation. They
13626 -- might, but there is no way of telling early enough.
13628 if Has_Non_Standard_Rep (T1) then
13629 if not Has_Non_Standard_Rep (T2) then
13633 return not Has_Non_Standard_Rep (T2);
13636 -- Here the two types both have non-standard representation, and we need
13637 -- to determine if they have the same non-standard representation.
13639 -- For arrays, we simply need to test if the component sizes are the
13640 -- same. Pragma Pack is reflected in modified component sizes, so this
13641 -- check also deals with pragma Pack.
13643 if Is_Array_Type (T1) then
13644 return Component_Size (T1) = Component_Size (T2);
13646 -- Case of record types
13648 elsif Is_Record_Type (T1) then
13650 -- Packed status must conform
13652 if Is_Packed (T1) /= Is_Packed (T2) then
13655 -- Otherwise we must check components. Typ2 maybe a constrained
13656 -- subtype with fewer components, so we compare the components
13657 -- of the base types.
13660 Record_Case : declare
13661 CD1, CD2 : Entity_Id;
13663 function Same_Rep return Boolean;
13664 -- CD1 and CD2 are either components or discriminants. This
13665 -- function tests whether they have the same representation.
13671 function Same_Rep return Boolean is
13673 if No (Component_Clause (CD1)) then
13674 return No (Component_Clause (CD2));
13676 -- Note: at this point, component clauses have been
13677 -- normalized to the default bit order, so that the
13678 -- comparison of Component_Bit_Offsets is meaningful.
13681 Present (Component_Clause (CD2))
13683 Component_Bit_Offset (CD1) = Component_Bit_Offset (CD2)
13685 Esize (CD1) = Esize (CD2);
13689 -- Start of processing for Record_Case
13692 if Has_Discriminants (T1) then
13694 -- The number of discriminants may be different if the
13695 -- derived type has fewer (constrained by values). The
13696 -- invisible discriminants retain the representation of
13697 -- the original, so the discrepancy does not per se
13698 -- indicate a different representation.
13700 CD1 := First_Discriminant (T1);
13701 CD2 := First_Discriminant (T2);
13702 while Present (CD1) and then Present (CD2) loop
13703 if not Same_Rep then
13706 Next_Discriminant (CD1);
13707 Next_Discriminant (CD2);
13712 CD1 := First_Component (Underlying_Type (Base_Type (T1)));
13713 CD2 := First_Component (Underlying_Type (Base_Type (T2)));
13714 while Present (CD1) loop
13715 if not Same_Rep then
13718 Next_Component (CD1);
13719 Next_Component (CD2);
13727 -- For enumeration types, we must check each literal to see if the
13728 -- representation is the same. Note that we do not permit enumeration
13729 -- representation clauses for Character and Wide_Character, so these
13730 -- cases were already dealt with.
13732 elsif Is_Enumeration_Type (T1) then
13733 Enumeration_Case : declare
13734 L1, L2 : Entity_Id;
13737 L1 := First_Literal (T1);
13738 L2 := First_Literal (T2);
13739 while Present (L1) loop
13740 if Enumeration_Rep (L1) /= Enumeration_Rep (L2) then
13749 end Enumeration_Case;
13751 -- Any other types have the same representation for these purposes
13756 end Same_Representation;
13758 --------------------------------
13759 -- Resolve_Iterable_Operation --
13760 --------------------------------
13762 procedure Resolve_Iterable_Operation
13764 Cursor : Entity_Id;
13773 if not Is_Overloaded (N) then
13774 if not Is_Entity_Name (N)
13775 or else Ekind (Entity (N)) /= E_Function
13776 or else Scope (Entity (N)) /= Scope (Typ)
13777 or else No (First_Formal (Entity (N)))
13778 or else Etype (First_Formal (Entity (N))) /= Typ
13781 ("iterable primitive must be local function name whose first "
13782 & "formal is an iterable type", N);
13787 F1 := First_Formal (Ent);
13789 if Nam = Name_First or else Nam = Name_Last then
13791 -- First or Last (Container) => Cursor
13793 if Etype (Ent) /= Cursor then
13794 Error_Msg_N ("primitive for First must yield a curosr", N);
13797 elsif Nam = Name_Next then
13799 -- Next (Container, Cursor) => Cursor
13801 F2 := Next_Formal (F1);
13803 if Etype (F2) /= Cursor
13804 or else Etype (Ent) /= Cursor
13805 or else Present (Next_Formal (F2))
13807 Error_Msg_N ("no match for Next iterable primitive", N);
13810 elsif Nam = Name_Previous then
13812 -- Previous (Container, Cursor) => Cursor
13814 F2 := Next_Formal (F1);
13816 if Etype (F2) /= Cursor
13817 or else Etype (Ent) /= Cursor
13818 or else Present (Next_Formal (F2))
13820 Error_Msg_N ("no match for Previous iterable primitive", N);
13823 elsif Nam = Name_Has_Element then
13825 -- Has_Element (Container, Cursor) => Boolean
13827 F2 := Next_Formal (F1);
13829 if Etype (F2) /= Cursor
13830 or else Etype (Ent) /= Standard_Boolean
13831 or else Present (Next_Formal (F2))
13833 Error_Msg_N ("no match for Has_Element iterable primitive", N);
13836 elsif Nam = Name_Element then
13837 F2 := Next_Formal (F1);
13840 or else Etype (F2) /= Cursor
13841 or else Present (Next_Formal (F2))
13843 Error_Msg_N ("no match for Element iterable primitive", N);
13847 raise Program_Error;
13851 -- Overloaded case: find subprogram with proper signature. Caller
13852 -- will report error if no match is found.
13859 Get_First_Interp (N, I, It);
13860 while Present (It.Typ) loop
13861 if Ekind (It.Nam) = E_Function
13862 and then Scope (It.Nam) = Scope (Typ)
13863 and then Etype (First_Formal (It.Nam)) = Typ
13865 F1 := First_Formal (It.Nam);
13867 if Nam = Name_First then
13868 if Etype (It.Nam) = Cursor
13869 and then No (Next_Formal (F1))
13871 Set_Entity (N, It.Nam);
13875 elsif Nam = Name_Next then
13876 F2 := Next_Formal (F1);
13879 and then No (Next_Formal (F2))
13880 and then Etype (F2) = Cursor
13881 and then Etype (It.Nam) = Cursor
13883 Set_Entity (N, It.Nam);
13887 elsif Nam = Name_Has_Element then
13888 F2 := Next_Formal (F1);
13891 and then No (Next_Formal (F2))
13892 and then Etype (F2) = Cursor
13893 and then Etype (It.Nam) = Standard_Boolean
13895 Set_Entity (N, It.Nam);
13896 F2 := Next_Formal (F1);
13900 elsif Nam = Name_Element then
13901 F2 := Next_Formal (F1);
13904 and then No (Next_Formal (F2))
13905 and then Etype (F2) = Cursor
13907 Set_Entity (N, It.Nam);
13913 Get_Next_Interp (I, It);
13917 end Resolve_Iterable_Operation;
13923 procedure Set_Biased
13927 Biased : Boolean := True)
13931 Set_Has_Biased_Representation (E);
13933 if Warn_On_Biased_Representation then
13935 ("?B?" & Msg & " forces biased representation for&", N, E);
13940 --------------------
13941 -- Set_Enum_Esize --
13942 --------------------
13944 procedure Set_Enum_Esize (T : Entity_Id) is
13950 Init_Alignment (T);
13952 -- Find the minimum standard size (8,16,32,64) that fits
13954 Lo := Enumeration_Rep (Entity (Type_Low_Bound (T)));
13955 Hi := Enumeration_Rep (Entity (Type_High_Bound (T)));
13958 if Lo >= -Uint_2**07 and then Hi < Uint_2**07 then
13959 Sz := Standard_Character_Size; -- May be > 8 on some targets
13961 elsif Lo >= -Uint_2**15 and then Hi < Uint_2**15 then
13964 elsif Lo >= -Uint_2**31 and then Hi < Uint_2**31 then
13967 else pragma Assert (Lo >= -Uint_2**63 and then Hi < Uint_2**63);
13972 if Hi < Uint_2**08 then
13973 Sz := Standard_Character_Size; -- May be > 8 on some targets
13975 elsif Hi < Uint_2**16 then
13978 elsif Hi < Uint_2**32 then
13981 else pragma Assert (Hi < Uint_2**63);
13986 -- That minimum is the proper size unless we have a foreign convention
13987 -- and the size required is 32 or less, in which case we bump the size
13988 -- up to 32. This is required for C and C++ and seems reasonable for
13989 -- all other foreign conventions.
13991 if Has_Foreign_Convention (T)
13992 and then Esize (T) < Standard_Integer_Size
13994 -- Don't do this if Short_Enums on target
13996 and then not Target_Short_Enums
13998 Init_Esize (T, Standard_Integer_Size);
14000 Init_Esize (T, Sz);
14002 end Set_Enum_Esize;
14004 -----------------------------
14005 -- Uninstall_Discriminants --
14006 -----------------------------
14008 procedure Uninstall_Discriminants (E : Entity_Id) is
14014 -- Discriminants have been made visible for type declarations and
14015 -- protected type declarations, not for subtype declarations.
14017 if Nkind (Parent (E)) /= N_Subtype_Declaration then
14018 Disc := First_Discriminant (E);
14019 while Present (Disc) loop
14020 if Disc /= Current_Entity (Disc) then
14021 Prev := Current_Entity (Disc);
14022 while Present (Prev)
14023 and then Present (Homonym (Prev))
14024 and then Homonym (Prev) /= Disc
14026 Prev := Homonym (Prev);
14032 Set_Is_Immediately_Visible (Disc, False);
14034 Outer := Homonym (Disc);
14035 while Present (Outer) and then Scope (Outer) = E loop
14036 Outer := Homonym (Outer);
14039 -- Reset homonym link of other entities, but do not modify link
14040 -- between entities in current scope, so that the back end can
14041 -- have a proper count of local overloadings.
14044 Set_Name_Entity_Id (Chars (Disc), Outer);
14046 elsif Scope (Prev) /= Scope (Disc) then
14047 Set_Homonym (Prev, Outer);
14050 Next_Discriminant (Disc);
14053 end Uninstall_Discriminants;
14055 ------------------------------
14056 -- Validate_Address_Clauses --
14057 ------------------------------
14059 procedure Validate_Address_Clauses is
14060 function Offset_Value (Expr : Node_Id) return Uint;
14061 -- Given an Address attribute reference, return the value in bits of its
14062 -- offset from the first bit of the underlying entity, or 0 if it is not
14063 -- known at compile time.
14069 function Offset_Value (Expr : Node_Id) return Uint is
14070 N : Node_Id := Prefix (Expr);
14072 Val : Uint := Uint_0;
14075 -- Climb the prefix chain and compute the cumulative offset
14078 if Is_Entity_Name (N) then
14081 elsif Nkind (N) = N_Selected_Component then
14082 Off := Component_Bit_Offset (Entity (Selector_Name (N)));
14083 if Off /= No_Uint and then Off >= Uint_0 then
14090 elsif Nkind (N) = N_Indexed_Component then
14091 Off := Indexed_Component_Bit_Offset (N);
14092 if Off /= No_Uint then
14105 -- Start of processing for Validate_Address_Clauses
14108 for J in Address_Clause_Checks.First .. Address_Clause_Checks.Last loop
14110 ACCR : Address_Clause_Check_Record
14111 renames Address_Clause_Checks.Table (J);
14115 X_Alignment : Uint;
14116 Y_Alignment : Uint := Uint_0;
14119 Y_Size : Uint := Uint_0;
14124 -- Skip processing of this entry if warning already posted
14126 if not Address_Warning_Posted (ACCR.N) then
14127 Expr := Original_Node (Expression (ACCR.N));
14129 -- Get alignments, sizes and offset, if any
14131 X_Alignment := Alignment (ACCR.X);
14132 X_Size := Esize (ACCR.X);
14134 if Present (ACCR.Y) then
14135 Y_Alignment := Alignment (ACCR.Y);
14136 Y_Size := Esize (ACCR.Y);
14140 and then Nkind (Expr) = N_Attribute_Reference
14141 and then Attribute_Name (Expr) = Name_Address
14143 X_Offs := Offset_Value (Expr);
14148 -- Check for known value not multiple of alignment
14150 if No (ACCR.Y) then
14151 if not Alignment_Checks_Suppressed (ACCR)
14152 and then X_Alignment /= 0
14153 and then ACCR.A mod X_Alignment /= 0
14156 ("??specified address for& is inconsistent with "
14157 & "alignment", ACCR.N, ACCR.X);
14159 ("\??program execution may be erroneous (RM 13.3(27))",
14162 Error_Msg_Uint_1 := X_Alignment;
14163 Error_Msg_NE ("\??alignment of & is ^", ACCR.N, ACCR.X);
14166 -- Check for large object overlaying smaller one
14168 elsif Y_Size > Uint_0
14169 and then X_Size > Uint_0
14170 and then X_Offs + X_Size > Y_Size
14172 Error_Msg_NE ("??& overlays smaller object", ACCR.N, ACCR.X);
14174 ("\??program execution may be erroneous", ACCR.N);
14176 Error_Msg_Uint_1 := X_Size;
14177 Error_Msg_NE ("\??size of & is ^", ACCR.N, ACCR.X);
14179 Error_Msg_Uint_1 := Y_Size;
14180 Error_Msg_NE ("\??size of & is ^", ACCR.N, ACCR.Y);
14182 if Y_Size >= X_Size then
14183 Error_Msg_Uint_1 := X_Offs;
14184 Error_Msg_NE ("\??but offset of & is ^", ACCR.N, ACCR.X);
14187 -- Check for inadequate alignment, both of the base object
14188 -- and of the offset, if any. We only do this check if the
14189 -- run-time Alignment_Check is active. No point in warning
14190 -- if this check has been suppressed (or is suppressed by
14191 -- default in the non-strict alignment machine case).
14193 -- Note: we do not check the alignment if we gave a size
14194 -- warning, since it would likely be redundant.
14196 elsif not Alignment_Checks_Suppressed (ACCR)
14197 and then Y_Alignment /= Uint_0
14199 (Y_Alignment < X_Alignment
14202 and then Nkind (Expr) = N_Attribute_Reference
14203 and then Attribute_Name (Expr) = Name_Address
14204 and then Has_Compatible_Alignment
14205 (ACCR.X, Prefix (Expr), True) /=
14209 ("??specified address for& may be inconsistent with "
14210 & "alignment", ACCR.N, ACCR.X);
14212 ("\??program execution may be erroneous (RM 13.3(27))",
14215 Error_Msg_Uint_1 := X_Alignment;
14216 Error_Msg_NE ("\??alignment of & is ^", ACCR.N, ACCR.X);
14218 Error_Msg_Uint_1 := Y_Alignment;
14219 Error_Msg_NE ("\??alignment of & is ^", ACCR.N, ACCR.Y);
14221 if Y_Alignment >= X_Alignment then
14223 ("\??but offset is not multiple of alignment", ACCR.N);
14229 end Validate_Address_Clauses;
14231 ---------------------------
14232 -- Validate_Independence --
14233 ---------------------------
14235 procedure Validate_Independence is
14236 SU : constant Uint := UI_From_Int (System_Storage_Unit);
14244 procedure Check_Array_Type (Atyp : Entity_Id);
14245 -- Checks if the array type Atyp has independent components, and
14246 -- if not, outputs an appropriate set of error messages.
14248 procedure No_Independence;
14249 -- Output message that independence cannot be guaranteed
14251 function OK_Component (C : Entity_Id) return Boolean;
14252 -- Checks one component to see if it is independently accessible, and
14253 -- if so yields True, otherwise yields False if independent access
14254 -- cannot be guaranteed. This is a conservative routine, it only
14255 -- returns True if it knows for sure, it returns False if it knows
14256 -- there is a problem, or it cannot be sure there is no problem.
14258 procedure Reason_Bad_Component (C : Entity_Id);
14259 -- Outputs continuation message if a reason can be determined for
14260 -- the component C being bad.
14262 ----------------------
14263 -- Check_Array_Type --
14264 ----------------------
14266 procedure Check_Array_Type (Atyp : Entity_Id) is
14267 Ctyp : constant Entity_Id := Component_Type (Atyp);
14270 -- OK if no alignment clause, no pack, and no component size
14272 if not Has_Component_Size_Clause (Atyp)
14273 and then not Has_Alignment_Clause (Atyp)
14274 and then not Is_Packed (Atyp)
14279 -- Case of component size is greater than or equal to 64 and the
14280 -- alignment of the array is at least as large as the alignment
14281 -- of the component. We are definitely OK in this situation.
14283 if Known_Component_Size (Atyp)
14284 and then Component_Size (Atyp) >= 64
14285 and then Known_Alignment (Atyp)
14286 and then Known_Alignment (Ctyp)
14287 and then Alignment (Atyp) >= Alignment (Ctyp)
14292 -- Check actual component size
14294 if not Known_Component_Size (Atyp)
14295 or else not (Addressable (Component_Size (Atyp))
14296 and then Component_Size (Atyp) < 64)
14297 or else Component_Size (Atyp) mod Esize (Ctyp) /= 0
14301 -- Bad component size, check reason
14303 if Has_Component_Size_Clause (Atyp) then
14304 P := Get_Attribute_Definition_Clause
14305 (Atyp, Attribute_Component_Size);
14307 if Present (P) then
14308 Error_Msg_Sloc := Sloc (P);
14309 Error_Msg_N ("\because of Component_Size clause#", N);
14314 if Is_Packed (Atyp) then
14315 P := Get_Rep_Pragma (Atyp, Name_Pack);
14317 if Present (P) then
14318 Error_Msg_Sloc := Sloc (P);
14319 Error_Msg_N ("\because of pragma Pack#", N);
14324 -- No reason found, just return
14329 -- Array type is OK independence-wise
14332 end Check_Array_Type;
14334 ---------------------
14335 -- No_Independence --
14336 ---------------------
14338 procedure No_Independence is
14340 if Pragma_Name (N) = Name_Independent then
14341 Error_Msg_NE ("independence cannot be guaranteed for&", N, E);
14344 ("independent components cannot be guaranteed for&", N, E);
14346 end No_Independence;
14352 function OK_Component (C : Entity_Id) return Boolean is
14353 Rec : constant Entity_Id := Scope (C);
14354 Ctyp : constant Entity_Id := Etype (C);
14357 -- OK if no component clause, no Pack, and no alignment clause
14359 if No (Component_Clause (C))
14360 and then not Is_Packed (Rec)
14361 and then not Has_Alignment_Clause (Rec)
14366 -- Here we look at the actual component layout. A component is
14367 -- addressable if its size is a multiple of the Esize of the
14368 -- component type, and its starting position in the record has
14369 -- appropriate alignment, and the record itself has appropriate
14370 -- alignment to guarantee the component alignment.
14372 -- Make sure sizes are static, always assume the worst for any
14373 -- cases where we cannot check static values.
14375 if not (Known_Static_Esize (C)
14377 Known_Static_Esize (Ctyp))
14382 -- Size of component must be addressable or greater than 64 bits
14383 -- and a multiple of bytes.
14385 if not Addressable (Esize (C)) and then Esize (C) < Uint_64 then
14389 -- Check size is proper multiple
14391 if Esize (C) mod Esize (Ctyp) /= 0 then
14395 -- Check alignment of component is OK
14397 if not Known_Component_Bit_Offset (C)
14398 or else Component_Bit_Offset (C) < Uint_0
14399 or else Component_Bit_Offset (C) mod Esize (Ctyp) /= 0
14404 -- Check alignment of record type is OK
14406 if not Known_Alignment (Rec)
14407 or else (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0
14412 -- All tests passed, component is addressable
14417 --------------------------
14418 -- Reason_Bad_Component --
14419 --------------------------
14421 procedure Reason_Bad_Component (C : Entity_Id) is
14422 Rec : constant Entity_Id := Scope (C);
14423 Ctyp : constant Entity_Id := Etype (C);
14426 -- If component clause present assume that's the problem
14428 if Present (Component_Clause (C)) then
14429 Error_Msg_Sloc := Sloc (Component_Clause (C));
14430 Error_Msg_N ("\because of Component_Clause#", N);
14434 -- If pragma Pack clause present, assume that's the problem
14436 if Is_Packed (Rec) then
14437 P := Get_Rep_Pragma (Rec, Name_Pack);
14439 if Present (P) then
14440 Error_Msg_Sloc := Sloc (P);
14441 Error_Msg_N ("\because of pragma Pack#", N);
14446 -- See if record has bad alignment clause
14448 if Has_Alignment_Clause (Rec)
14449 and then Known_Alignment (Rec)
14450 and then (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0
14452 P := Get_Attribute_Definition_Clause (Rec, Attribute_Alignment);
14454 if Present (P) then
14455 Error_Msg_Sloc := Sloc (P);
14456 Error_Msg_N ("\because of Alignment clause#", N);
14460 -- Couldn't find a reason, so return without a message
14463 end Reason_Bad_Component;
14465 -- Start of processing for Validate_Independence
14468 for J in Independence_Checks.First .. Independence_Checks.Last loop
14469 N := Independence_Checks.Table (J).N;
14470 E := Independence_Checks.Table (J).E;
14471 IC := Pragma_Name (N) = Name_Independent_Components;
14473 -- Deal with component case
14475 if Ekind (E) = E_Discriminant or else Ekind (E) = E_Component then
14476 if not OK_Component (E) then
14478 Reason_Bad_Component (E);
14483 -- Deal with record with Independent_Components
14485 if IC and then Is_Record_Type (E) then
14486 Comp := First_Component_Or_Discriminant (E);
14487 while Present (Comp) loop
14488 if not OK_Component (Comp) then
14490 Reason_Bad_Component (Comp);
14494 Next_Component_Or_Discriminant (Comp);
14498 -- Deal with address clause case
14500 if Is_Object (E) then
14501 Addr := Address_Clause (E);
14503 if Present (Addr) then
14505 Error_Msg_Sloc := Sloc (Addr);
14506 Error_Msg_N ("\because of Address clause#", N);
14511 -- Deal with independent components for array type
14513 if IC and then Is_Array_Type (E) then
14514 Check_Array_Type (E);
14517 -- Deal with independent components for array object
14519 if IC and then Is_Object (E) and then Is_Array_Type (Etype (E)) then
14520 Check_Array_Type (Etype (E));
14525 end Validate_Independence;
14527 ------------------------------
14528 -- Validate_Iterable_Aspect --
14529 ------------------------------
14531 procedure Validate_Iterable_Aspect (Typ : Entity_Id; ASN : Node_Id) is
14536 Cursor : constant Entity_Id := Get_Cursor_Type (ASN, Typ);
14538 First_Id : Entity_Id;
14539 Last_Id : Entity_Id;
14540 Next_Id : Entity_Id;
14541 Has_Element_Id : Entity_Id;
14542 Element_Id : Entity_Id;
14545 -- If previous error aspect is unusable
14547 if Cursor = Any_Type then
14554 Has_Element_Id := Empty;
14555 Element_Id := Empty;
14557 -- Each expression must resolve to a function with the proper signature
14559 Assoc := First (Component_Associations (Expression (ASN)));
14560 while Present (Assoc) loop
14561 Expr := Expression (Assoc);
14564 Prim := First (Choices (Assoc));
14566 if Nkind (Prim) /= N_Identifier or else Present (Next (Prim)) then
14567 Error_Msg_N ("illegal name in association", Prim);
14569 elsif Chars (Prim) = Name_First then
14570 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_First);
14571 First_Id := Entity (Expr);
14573 elsif Chars (Prim) = Name_Last then
14574 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Last);
14575 Last_Id := Entity (Expr);
14577 elsif Chars (Prim) = Name_Previous then
14578 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Previous);
14579 Last_Id := Entity (Expr);
14581 elsif Chars (Prim) = Name_Next then
14582 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Next);
14583 Next_Id := Entity (Expr);
14585 elsif Chars (Prim) = Name_Has_Element then
14586 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Has_Element);
14587 Has_Element_Id := Entity (Expr);
14589 elsif Chars (Prim) = Name_Element then
14590 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Element);
14591 Element_Id := Entity (Expr);
14594 Error_Msg_N ("invalid name for iterable function", Prim);
14600 if No (First_Id) then
14601 Error_Msg_N ("match for First primitive not found", ASN);
14603 elsif No (Next_Id) then
14604 Error_Msg_N ("match for Next primitive not found", ASN);
14606 elsif No (Has_Element_Id) then
14607 Error_Msg_N ("match for Has_Element primitive not found", ASN);
14609 elsif No (Element_Id) or else No (Last_Id) then
14612 end Validate_Iterable_Aspect;
14614 -----------------------------------
14615 -- Validate_Unchecked_Conversion --
14616 -----------------------------------
14618 procedure Validate_Unchecked_Conversion
14620 Act_Unit : Entity_Id)
14622 Source : Entity_Id;
14623 Target : Entity_Id;
14627 -- Obtain source and target types. Note that we call Ancestor_Subtype
14628 -- here because the processing for generic instantiation always makes
14629 -- subtypes, and we want the original frozen actual types.
14631 -- If we are dealing with private types, then do the check on their
14632 -- fully declared counterparts if the full declarations have been
14633 -- encountered (they don't have to be visible, but they must exist).
14635 Source := Ancestor_Subtype (Etype (First_Formal (Act_Unit)));
14637 if Is_Private_Type (Source)
14638 and then Present (Underlying_Type (Source))
14640 Source := Underlying_Type (Source);
14643 Target := Ancestor_Subtype (Etype (Act_Unit));
14645 -- If either type is generic, the instantiation happens within a generic
14646 -- unit, and there is nothing to check. The proper check will happen
14647 -- when the enclosing generic is instantiated.
14649 if Is_Generic_Type (Source) or else Is_Generic_Type (Target) then
14653 if Is_Private_Type (Target)
14654 and then Present (Underlying_Type (Target))
14656 Target := Underlying_Type (Target);
14659 -- Source may be unconstrained array, but not target, except in relaxed
14662 if Is_Array_Type (Target)
14663 and then not Is_Constrained (Target)
14664 and then not Relaxed_RM_Semantics
14667 ("unchecked conversion to unconstrained array not allowed", N);
14671 -- Warn if conversion between two different convention pointers
14673 if Is_Access_Type (Target)
14674 and then Is_Access_Type (Source)
14675 and then Convention (Target) /= Convention (Source)
14676 and then Warn_On_Unchecked_Conversion
14678 -- Give warnings for subprogram pointers only on most targets
14680 if Is_Access_Subprogram_Type (Target)
14681 or else Is_Access_Subprogram_Type (Source)
14684 ("?z?conversion between pointers with different conventions!",
14689 -- Warn if one of the operands is Ada.Calendar.Time. Do not emit a
14690 -- warning when compiling GNAT-related sources.
14692 if Warn_On_Unchecked_Conversion
14693 and then not In_Predefined_Unit (N)
14694 and then RTU_Loaded (Ada_Calendar)
14695 and then (Chars (Source) = Name_Time
14697 Chars (Target) = Name_Time)
14699 -- If Ada.Calendar is loaded and the name of one of the operands is
14700 -- Time, there is a good chance that this is Ada.Calendar.Time.
14703 Calendar_Time : constant Entity_Id := Full_View (RTE (RO_CA_Time));
14705 pragma Assert (Present (Calendar_Time));
14707 if Source = Calendar_Time or else Target = Calendar_Time then
14709 ("?z?representation of 'Time values may change between "
14710 & "'G'N'A'T versions", N);
14715 -- Make entry in unchecked conversion table for later processing by
14716 -- Validate_Unchecked_Conversions, which will check sizes and alignments
14717 -- (using values set by the back end where possible). This is only done
14718 -- if the appropriate warning is active.
14720 if Warn_On_Unchecked_Conversion then
14721 Unchecked_Conversions.Append
14722 (New_Val => UC_Entry'(Eloc => Sloc (N),
14725 Act_Unit => Act_Unit));
14727 -- If both sizes are known statically now, then back-end annotation
14728 -- is not required to do a proper check but if either size is not
14729 -- known statically, then we need the annotation.
14731 if Known_Static_RM_Size (Source)
14733 Known_Static_RM_Size (Target)
14737 Back_Annotate_Rep_Info := True;
14741 -- If unchecked conversion to access type, and access type is declared
14742 -- in the same unit as the unchecked conversion, then set the flag
14743 -- No_Strict_Aliasing (no strict aliasing is implicit here)
14745 if Is_Access_Type (Target) and then
14746 In_Same_Source_Unit (Target, N)
14748 Set_No_Strict_Aliasing (Implementation_Base_Type (Target));
14751 -- Generate N_Validate_Unchecked_Conversion node for back end in case
14752 -- the back end needs to perform special validation checks.
14754 -- Shouldn't this be in Exp_Ch13, since the check only gets done if we
14755 -- have full expansion and the back end is called ???
14758 Make_Validate_Unchecked_Conversion (Sloc (N));
14759 Set_Source_Type (Vnode, Source);
14760 Set_Target_Type (Vnode, Target);
14762 -- If the unchecked conversion node is in a list, just insert before it.
14763 -- If not we have some strange case, not worth bothering about.
14765 if Is_List_Member (N) then
14766 Insert_After (N, Vnode);
14768 end Validate_Unchecked_Conversion;
14770 ------------------------------------
14771 -- Validate_Unchecked_Conversions --
14772 ------------------------------------
14774 procedure Validate_Unchecked_Conversions is
14775 function Is_Null_Array (T : Entity_Id) return Boolean;
14776 -- We want to warn in the case of converting to a wrong-sized array of
14777 -- bytes, including the zero-size case. This returns True in that case,
14778 -- which is necessary because a size of 0 is used to indicate both an
14779 -- unknown size and a size of 0. It's OK for this to return True in
14780 -- other zero-size cases, but we don't go out of our way; for example,
14781 -- we don't bother with multidimensional arrays.
14783 function Is_Null_Array (T : Entity_Id) return Boolean is
14785 if Is_Array_Type (T) and then Is_Constrained (T) then
14787 Index : constant Node_Id := First_Index (T);
14788 R : Node_Id; -- N_Range
14790 case Nkind (Index) is
14793 when N_Subtype_Indication =>
14794 R := Range_Expression (Constraint (Index));
14795 when N_Identifier | N_Expanded_Name =>
14796 R := Scalar_Range (Entity (Index));
14798 raise Program_Error;
14801 return Is_Null_Range (Low_Bound (R), High_Bound (R));
14809 for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop
14811 T : UC_Entry renames Unchecked_Conversions.Table (N);
14813 Act_Unit : constant Entity_Id := T.Act_Unit;
14814 Eloc : constant Source_Ptr := T.Eloc;
14815 Source : constant Entity_Id := T.Source;
14816 Target : constant Entity_Id := T.Target;
14822 -- Skip if function marked as warnings off
14824 if Warnings_Off (Act_Unit) or else Serious_Errors_Detected > 0 then
14828 -- Don't do the check if warnings off for either type, note the
14829 -- deliberate use of OR here instead of OR ELSE to get the flag
14830 -- Warnings_Off_Used set for both types if appropriate.
14832 if Has_Warnings_Off (Source) or Has_Warnings_Off (Target) then
14836 if (Known_Static_RM_Size (Source)
14837 and then Known_Static_RM_Size (Target))
14838 or else Is_Null_Array (Target)
14840 -- This validation check, which warns if we have unequal sizes
14841 -- for unchecked conversion, and thus implementation dependent
14842 -- semantics, is one of the few occasions on which we use the
14843 -- official RM size instead of Esize. See description in Einfo
14844 -- "Handling of Type'Size Values" for details.
14846 Source_Siz := RM_Size (Source);
14847 Target_Siz := RM_Size (Target);
14849 if Source_Siz /= Target_Siz then
14851 ("?z?types for unchecked conversion have different sizes!",
14854 if All_Errors_Mode then
14855 Error_Msg_Name_1 := Chars (Source);
14856 Error_Msg_Uint_1 := Source_Siz;
14857 Error_Msg_Name_2 := Chars (Target);
14858 Error_Msg_Uint_2 := Target_Siz;
14859 Error_Msg ("\size of % is ^, size of % is ^?z?", Eloc);
14861 Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz);
14863 if Is_Discrete_Type (Source)
14865 Is_Discrete_Type (Target)
14867 if Source_Siz > Target_Siz then
14869 ("\?z?^ high order bits of source will "
14870 & "be ignored!", Eloc);
14872 elsif Is_Unsigned_Type (Source) then
14874 ("\?z?source will be extended with ^ high order "
14875 & "zero bits!", Eloc);
14879 ("\?z?source will be extended with ^ high order "
14880 & "sign bits!", Eloc);
14883 elsif Source_Siz < Target_Siz then
14884 if Is_Discrete_Type (Target) then
14885 if Bytes_Big_Endian then
14887 ("\?z?target value will include ^ undefined "
14888 & "low order bits!", Eloc, Act_Unit);
14891 ("\?z?target value will include ^ undefined "
14892 & "high order bits!", Eloc, Act_Unit);
14897 ("\?z?^ trailing bits of target value will be "
14898 & "undefined!", Eloc, Act_Unit);
14901 else pragma Assert (Source_Siz > Target_Siz);
14902 if Is_Discrete_Type (Source) then
14903 if Bytes_Big_Endian then
14905 ("\?z?^ low order bits of source will be "
14906 & "ignored!", Eloc, Act_Unit);
14909 ("\?z?^ high order bits of source will be "
14910 & "ignored!", Eloc, Act_Unit);
14915 ("\?z?^ trailing bits of source will be "
14916 & "ignored!", Eloc, Act_Unit);
14923 -- If both types are access types, we need to check the alignment.
14924 -- If the alignment of both is specified, we can do it here.
14926 if Serious_Errors_Detected = 0
14927 and then Is_Access_Type (Source)
14928 and then Is_Access_Type (Target)
14929 and then Target_Strict_Alignment
14930 and then Present (Designated_Type (Source))
14931 and then Present (Designated_Type (Target))
14934 D_Source : constant Entity_Id := Designated_Type (Source);
14935 D_Target : constant Entity_Id := Designated_Type (Target);
14938 if Known_Alignment (D_Source)
14940 Known_Alignment (D_Target)
14943 Source_Align : constant Uint := Alignment (D_Source);
14944 Target_Align : constant Uint := Alignment (D_Target);
14947 if Source_Align < Target_Align
14948 and then not Is_Tagged_Type (D_Source)
14950 -- Suppress warning if warnings suppressed on either
14951 -- type or either designated type. Note the use of
14952 -- OR here instead of OR ELSE. That is intentional,
14953 -- we would like to set flag Warnings_Off_Used in
14954 -- all types for which warnings are suppressed.
14956 and then not (Has_Warnings_Off (D_Source)
14958 Has_Warnings_Off (D_Target)
14960 Has_Warnings_Off (Source)
14962 Has_Warnings_Off (Target))
14964 Error_Msg_Uint_1 := Target_Align;
14965 Error_Msg_Uint_2 := Source_Align;
14966 Error_Msg_Node_1 := D_Target;
14967 Error_Msg_Node_2 := D_Source;
14969 ("?z?alignment of & (^) is stricter than "
14970 & "alignment of & (^)!", Eloc, Act_Unit);
14972 ("\?z?resulting access value may have invalid "
14973 & "alignment!", Eloc, Act_Unit);
14984 end Validate_Unchecked_Conversions;