1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2020, 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_Cat; use Sem_Cat;
52 with Sem_Ch3; use Sem_Ch3;
53 with Sem_Ch6; use Sem_Ch6;
54 with Sem_Ch7; use Sem_Ch7;
55 with Sem_Ch8; use Sem_Ch8;
56 with Sem_Dim; use Sem_Dim;
57 with Sem_Disp; use Sem_Disp;
58 with Sem_Eval; use Sem_Eval;
59 with Sem_Prag; use Sem_Prag;
60 with Sem_Res; use Sem_Res;
61 with Sem_Type; use Sem_Type;
62 with Sem_Util; use Sem_Util;
63 with Sem_Warn; use Sem_Warn;
64 with Sinfo; use Sinfo;
65 with Sinput; use Sinput;
66 with Snames; use Snames;
67 with Stand; use Stand;
68 with Targparm; use Targparm;
69 with Ttypes; use Ttypes;
70 with Tbuild; use Tbuild;
71 with Urealp; use Urealp;
72 with Warnsw; use Warnsw;
74 with GNAT.Heap_Sort_G;
76 package body Sem_Ch13 is
78 SSU : constant Pos := System_Storage_Unit;
79 -- Convenient short hand for commonly used constant
81 -----------------------
82 -- Local Subprograms --
83 -----------------------
85 procedure Adjust_Record_For_Reverse_Bit_Order_Ada_95 (R : Entity_Id);
86 -- Helper routine providing the original (pre-AI95-0133) behavior for
87 -- Adjust_Record_For_Reverse_Bit_Order.
89 procedure Alignment_Check_For_Size_Change (Typ : Entity_Id; Size : Uint);
90 -- This routine is called after setting one of the sizes of type entity
91 -- Typ to Size. The purpose is to deal with the situation of a derived
92 -- type whose inherited alignment is no longer appropriate for the new
93 -- size value. In this case, we reset the Alignment to unknown.
95 function All_Static_Choices (L : List_Id) return Boolean;
96 -- Returns true if all elements of the list are OK static choices
97 -- as defined below for Is_Static_Choice. Used for case expression
98 -- alternatives and for the right operand of a membership test. An
99 -- others_choice is static if the corresponding expression is static.
100 -- The staticness of the bounds is checked separately.
102 procedure Build_Discrete_Static_Predicate
106 -- Given a predicated type Typ, where Typ is a discrete static subtype,
107 -- whose predicate expression is Expr, tests if Expr is a static predicate,
108 -- and if so, builds the predicate range list. Nam is the name of the one
109 -- argument to the predicate function. Occurrences of the type name in the
110 -- predicate expression have been replaced by identifier references to this
111 -- name, which is unique, so any identifier with Chars matching Nam must be
112 -- a reference to the type. If the predicate is non-static, this procedure
113 -- returns doing nothing. If the predicate is static, then the predicate
114 -- list is stored in Static_Discrete_Predicate (Typ), and the Expr is
115 -- rewritten as a canonicalized membership operation.
117 function Build_Export_Import_Pragma
119 Id : Entity_Id) return Node_Id;
120 -- Create the corresponding pragma for aspect Export or Import denoted by
121 -- Asp. Id is the related entity subject to the aspect. Return Empty when
122 -- the expression of aspect Asp evaluates to False or is erroneous.
124 function Build_Predicate_Function_Declaration
125 (Typ : Entity_Id) return Node_Id;
126 -- Build the declaration for a predicate function. The declaration is built
127 -- at the end of the declarative part containing the type definition, which
128 -- may be before the freeze point of the type. The predicate expression is
129 -- preanalyzed at this point, to catch visibility errors.
131 procedure Build_Predicate_Functions (Typ : Entity_Id; N : Node_Id);
132 -- If Typ has predicates (indicated by Has_Predicates being set for Typ),
133 -- then either there are pragma Predicate entries on the rep chain for the
134 -- type (note that Predicate aspects are converted to pragma Predicate), or
135 -- there are inherited aspects from a parent type, or ancestor subtypes.
136 -- This procedure builds body for the Predicate function that tests these
137 -- predicates. N is the freeze node for the type. The spec of the function
138 -- is inserted before the freeze node, and the body of the function is
139 -- inserted after the freeze node. If the predicate expression has a least
140 -- one Raise_Expression, then this procedure also builds the M version of
141 -- the predicate function for use in membership tests.
143 procedure Check_Pool_Size_Clash (Ent : Entity_Id; SP, SS : Node_Id);
144 -- Called if both Storage_Pool and Storage_Size attribute definition
145 -- clauses (SP and SS) are present for entity Ent. Issue error message.
147 procedure Freeze_Entity_Checks (N : Node_Id);
148 -- Called from Analyze_Freeze_Entity and Analyze_Generic_Freeze Entity
149 -- to generate appropriate semantic checks that are delayed until this
150 -- point (they had to be delayed this long for cases of delayed aspects,
151 -- e.g. analysis of statically predicated subtypes in choices, for which
152 -- we have to be sure the subtypes in question are frozen before checking).
154 function Get_Alignment_Value (Expr : Node_Id) return Uint;
155 -- Given the expression for an alignment value, returns the corresponding
156 -- Uint value. If the value is inappropriate, then error messages are
157 -- posted as required, and a value of No_Uint is returned.
159 function Is_Operational_Item (N : Node_Id) return Boolean;
160 -- A specification for a stream attribute is allowed before the full type
161 -- is declared, as explained in AI-00137 and the corrigendum. Attributes
162 -- that do not specify a representation characteristic are operational
165 function Is_Static_Choice (N : Node_Id) return Boolean;
166 -- Returns True if N represents a static choice (static subtype, or
167 -- static subtype indication, or static expression, or static range).
169 -- Note that this is a bit more inclusive than we actually need
170 -- (in particular membership tests do not allow the use of subtype
171 -- indications). But that doesn't matter, we have already checked
172 -- that the construct is legal to get this far.
174 function Is_Type_Related_Rep_Item (N : Node_Id) return Boolean;
175 -- Returns True for a representation clause/pragma that specifies a
176 -- type-related representation (as opposed to operational) aspect.
178 function Is_Predicate_Static
180 Nam : Name_Id) return Boolean;
181 -- Given predicate expression Expr, tests if Expr is predicate-static in
182 -- the sense of the rules in (RM 3.2.4 (15-24)). Occurrences of the type
183 -- name in the predicate expression have been replaced by references to
184 -- an identifier whose Chars field is Nam. This name is unique, so any
185 -- identifier with Chars matching Nam must be a reference to the type.
186 -- Returns True if the expression is predicate-static and False otherwise,
187 -- but is not in the business of setting flags or issuing error messages.
189 -- Only scalar types can have static predicates, so False is always
190 -- returned for non-scalar types.
192 -- Note: the RM seems to suggest that string types can also have static
193 -- predicates. But that really makes lttle sense as very few useful
194 -- predicates can be constructed for strings. Remember that:
198 -- is not a static expression. So even though the clearly faulty RM wording
199 -- allows the following:
201 -- subtype S is String with Static_Predicate => S < "DEF"
203 -- We can't allow this, otherwise we have predicate-static applying to a
204 -- larger class than static expressions, which was never intended.
206 procedure New_Put_Image_Subprogram
210 -- Similar to New_Stream_Subprogram, but for the Put_Image attribute
212 procedure New_Stream_Subprogram
216 Nam : TSS_Name_Type);
217 -- Create a subprogram renaming of a given stream attribute to the
218 -- designated subprogram and then in the tagged case, provide this as a
219 -- primitive operation, or in the untagged case make an appropriate TSS
220 -- entry. This is more properly an expansion activity than just semantics,
221 -- but the presence of user-defined stream functions for limited types
222 -- is a legality check, which is why this takes place here rather than in
223 -- exp_ch13, where it was previously. Nam indicates the name of the TSS
224 -- function to be generated.
226 -- To avoid elaboration anomalies with freeze nodes, for untagged types
227 -- we generate both a subprogram declaration and a subprogram renaming
228 -- declaration, so that the attribute specification is handled as a
229 -- renaming_as_body. For tagged types, the specification is one of the
232 procedure No_Type_Rep_Item (N : Node_Id);
233 -- Output message indicating that no type-related aspects can be
234 -- specified due to some property of the parent type.
236 procedure Register_Address_Clause_Check
242 -- Register a check for the address clause N. The rest of the parameters
243 -- are in keeping with the components of Address_Clause_Check_Record below.
245 procedure Validate_Aspect_Aggregate (N : Node_Id);
246 -- Check legality of operations given in the Ada 202x Aggregate aspect for
249 procedure Resolve_Aspect_Aggregate
252 -- Resolve each one of the operations specified in the specification of
255 procedure Resolve_Iterable_Operation
260 -- If the name of a primitive operation for an Iterable aspect is
261 -- overloaded, resolve according to required signature.
267 Biased : Boolean := True);
268 -- If Biased is True, sets Has_Biased_Representation flag for E, and
269 -- outputs a warning message at node N if Warn_On_Biased_Representation is
270 -- is True. This warning inserts the string Msg to describe the construct
273 -----------------------------------------------------------
274 -- Visibility of Discriminants in Aspect Specifications --
275 -----------------------------------------------------------
277 -- The discriminants of a type are visible when analyzing the aspect
278 -- specifications of a type declaration or protected type declaration,
279 -- but not when analyzing those of a subtype declaration. The following
280 -- routines enforce this distinction.
282 procedure Push_Type (E : Entity_Id);
283 -- Push scope E and make visible the discriminants of type entity E if E
284 -- has discriminants and is not a subtype.
286 procedure Pop_Type (E : Entity_Id);
287 -- Remove visibility to the discriminants of type entity E and pop the
288 -- scope stack if E has discriminants and is not a subtype.
290 ----------------------------------------------
291 -- Table for Validate_Unchecked_Conversions --
292 ----------------------------------------------
294 -- The following table collects unchecked conversions for validation.
295 -- Entries are made by Validate_Unchecked_Conversion and then the call
296 -- to Validate_Unchecked_Conversions does the actual error checking and
297 -- posting of warnings. The reason for this delayed processing is to take
298 -- advantage of back-annotations of size and alignment values performed by
301 -- Note: the reason we store a Source_Ptr value instead of a Node_Id is
302 -- that by the time Validate_Unchecked_Conversions is called, Sprint will
303 -- already have modified all Sloc values if the -gnatD option is set.
305 type UC_Entry is record
306 Eloc : Source_Ptr; -- node used for posting warnings
307 Source : Entity_Id; -- source type for unchecked conversion
308 Target : Entity_Id; -- target type for unchecked conversion
309 Act_Unit : Entity_Id; -- actual function instantiated
312 package Unchecked_Conversions is new Table.Table (
313 Table_Component_Type => UC_Entry,
314 Table_Index_Type => Int,
315 Table_Low_Bound => 1,
317 Table_Increment => 200,
318 Table_Name => "Unchecked_Conversions");
320 ----------------------------------------
321 -- Table for Validate_Address_Clauses --
322 ----------------------------------------
324 -- If an address clause has the form
326 -- for X'Address use Expr
328 -- where Expr has a value known at compile time or is of the form Y'Address
329 -- or recursively is a reference to a constant initialized with either of
330 -- these forms, and the value of Expr is not a multiple of X's alignment,
331 -- or if Y has a smaller alignment than X, then that merits a warning about
332 -- possible bad alignment. The following table collects address clauses of
333 -- this kind. We put these in a table so that they can be checked after the
334 -- back end has completed annotation of the alignments of objects, since we
335 -- can catch more cases that way.
337 type Address_Clause_Check_Record is record
339 -- The address clause
342 -- The entity of the object subject to the address clause
345 -- The value of the address in the first case
348 -- The entity of the object being overlaid in the second case
351 -- Whether the address is offset within Y in the second case
353 Alignment_Checks_Suppressed : Boolean;
354 -- Whether alignment checks are suppressed by an active scope suppress
355 -- setting. We need to save the value in order to be able to reuse it
356 -- after the back end has been run.
359 package Address_Clause_Checks is new Table.Table (
360 Table_Component_Type => Address_Clause_Check_Record,
361 Table_Index_Type => Int,
362 Table_Low_Bound => 1,
364 Table_Increment => 200,
365 Table_Name => "Address_Clause_Checks");
367 function Alignment_Checks_Suppressed
368 (ACCR : Address_Clause_Check_Record) return Boolean;
369 -- Return whether the alignment check generated for the address clause
372 ---------------------------------
373 -- Alignment_Checks_Suppressed --
374 ---------------------------------
376 function Alignment_Checks_Suppressed
377 (ACCR : Address_Clause_Check_Record) return Boolean
380 if Checks_May_Be_Suppressed (ACCR.X) then
381 return Is_Check_Suppressed (ACCR.X, Alignment_Check);
383 return ACCR.Alignment_Checks_Suppressed;
385 end Alignment_Checks_Suppressed;
387 -----------------------------------------
388 -- Adjust_Record_For_Reverse_Bit_Order --
389 -----------------------------------------
391 procedure Adjust_Record_For_Reverse_Bit_Order (R : Entity_Id) is
392 Max_Machine_Scalar_Size : constant Uint :=
393 UI_From_Int (System_Max_Integer_Size);
394 -- We use this as the maximum machine scalar size
396 SSU : constant Uint := UI_From_Int (System_Storage_Unit);
403 -- The processing done here used to depend on the Ada version, but the
404 -- behavior has been changed by AI95-0133. However this AI is a Binding
405 -- Interpretation, so we now implement it even in Ada 95 mode. But the
406 -- original behavior from unamended Ada 95 is available for the sake of
407 -- compatibility under the debugging switch -gnatd.p in Ada 95 mode.
409 if Ada_Version < Ada_2005 and then Debug_Flag_Dot_P then
410 Adjust_Record_For_Reverse_Bit_Order_Ada_95 (R);
414 -- For Ada 2005, we do machine scalar processing, as fully described In
415 -- AI-133. This involves gathering all components which start at the
416 -- same byte offset and processing them together. Same approach is still
417 -- valid in later versions including Ada 2012.
419 -- Note that component clauses found on record types may be inherited,
420 -- in which case the layout of the component with such a clause still
421 -- has to be done at this point. Therefore, the processing done here
422 -- must exclusively rely on the Component_Clause of the component.
424 -- This first loop through components does two things. First it deals
425 -- with the case of components with component clauses whose length is
426 -- greater than the maximum machine scalar size (either accepting them
427 -- or rejecting as needed). Second, it counts the number of components
428 -- with component clauses whose length does not exceed this maximum for
432 Comp := First_Component_Or_Discriminant (R);
433 while Present (Comp) loop
434 CC := Component_Clause (Comp);
438 Fbit : constant Uint := Static_Integer (First_Bit (CC));
439 Lbit : constant Uint := Static_Integer (Last_Bit (CC));
442 -- Case of component with last bit >= max machine scalar
444 if Lbit >= Max_Machine_Scalar_Size then
446 -- This is allowed only if first bit is zero, and last bit
447 -- + 1 is a multiple of storage unit size.
449 if Fbit = 0 and then (Lbit + 1) mod SSU = 0 then
451 -- This is the case to give a warning if enabled
453 if Warn_On_Reverse_Bit_Order then
455 ("info: multi-byte field specified with "
456 & "non-standard Bit_Order?V?", CC);
458 if Bytes_Big_Endian then
460 ("\bytes are not reversed "
461 & "(component is big-endian)?V?", CC);
464 ("\bytes are not reversed "
465 & "(component is little-endian)?V?", CC);
469 -- Give error message for RM 13.5.1(10) violation
473 ("machine scalar rules not followed for&",
474 First_Bit (CC), Comp);
476 Error_Msg_Uint_1 := Lbit + 1;
477 Error_Msg_Uint_2 := Max_Machine_Scalar_Size;
479 ("\last bit + 1 (^) exceeds maximum machine scalar "
480 & "size (^)", First_Bit (CC));
482 if (Lbit + 1) mod SSU /= 0 then
483 Error_Msg_Uint_1 := SSU;
485 ("\and is not a multiple of Storage_Unit (^) "
486 & "(RM 13.5.1(10))", First_Bit (CC));
489 Error_Msg_Uint_1 := Fbit;
491 ("\and first bit (^) is non-zero "
492 & "(RM 13.4.1(10))", First_Bit (CC));
496 -- OK case of machine scalar related component clause. For now,
500 Num_CC := Num_CC + 1;
505 Next_Component_Or_Discriminant (Comp);
508 -- We need to sort the component clauses on the basis of the Position
509 -- values in the clause, so we can group clauses with the same Position
510 -- together to determine the relevant machine scalar size.
513 Comps : array (0 .. Num_CC) of Entity_Id;
514 -- Array to collect component and discriminant entities. The data
515 -- starts at index 1, the 0'th entry is for the sort routine.
517 function CP_Lt (Op1, Op2 : Natural) return Boolean;
518 -- Compare routine for Sort
520 procedure CP_Move (From : Natural; To : Natural);
521 -- Move routine for Sort
523 package Sorting is new GNAT.Heap_Sort_G (CP_Move, CP_Lt);
526 -- Maximum last bit value of any component in this set
529 -- Corresponding machine scalar size
533 -- Start and stop positions in the component list of the set of
534 -- components with the same starting position (that constitute
535 -- components in a single machine scalar).
541 function CP_Lt (Op1, Op2 : Natural) return Boolean is
544 Position (Component_Clause (Comps (Op1))) <
545 Position (Component_Clause (Comps (Op2)));
552 procedure CP_Move (From : Natural; To : Natural) is
554 Comps (To) := Comps (From);
557 -- Start of processing for Sort_CC
560 -- Collect the machine scalar relevant component clauses
563 Comp := First_Component_Or_Discriminant (R);
564 while Present (Comp) loop
566 CC : constant Node_Id := Component_Clause (Comp);
569 -- Collect only component clauses whose last bit is less than
570 -- machine scalar size. Any component clause whose last bit
571 -- exceeds this value does not take part in machine scalar
572 -- layout considerations. The test for Error_Posted makes sure
573 -- we exclude component clauses for which we already posted an
577 and then not Error_Posted (Last_Bit (CC))
578 and then Static_Integer (Last_Bit (CC)) <
579 Max_Machine_Scalar_Size
581 Num_CC := Num_CC + 1;
582 Comps (Num_CC) := Comp;
586 Next_Component_Or_Discriminant (Comp);
589 -- Sort by ascending position number
591 Sorting.Sort (Num_CC);
593 -- We now have all the components whose size does not exceed the max
594 -- machine scalar value, sorted by starting position. In this loop we
595 -- gather groups of clauses starting at the same position, to process
596 -- them in accordance with AI-133.
599 while Stop < Num_CC loop
604 (Last_Bit (Component_Clause (Comps (Start))));
605 while Stop < Num_CC loop
607 (Position (Component_Clause (Comps (Stop + 1)))) =
609 (Position (Component_Clause (Comps (Stop))))
617 (Component_Clause (Comps (Stop)))));
623 -- Now we have a group of component clauses from Start to Stop
624 -- whose positions are identical, and MaxL is the maximum last
625 -- bit value of any of these components.
627 -- We need to determine the corresponding machine scalar size.
628 -- This loop assumes that machine scalar sizes are even, and that
629 -- each possible machine scalar has twice as many bits as the next
632 MSS := Max_Machine_Scalar_Size;
634 and then (MSS / 2) >= SSU
635 and then (MSS / 2) > MaxL
640 -- Here is where we fix up the Component_Bit_Offset value to
641 -- account for the reverse bit order. Some examples of what needs
642 -- to be done for the case of a machine scalar size of 8 are:
644 -- First_Bit .. Last_Bit Component_Bit_Offset
656 -- The rule is that the first bit is obtained by subtracting the
657 -- old ending bit from machine scalar size - 1.
659 for C in Start .. Stop loop
661 Comp : constant Entity_Id := Comps (C);
662 CC : constant Node_Id := Component_Clause (Comp);
664 FB : constant Uint := Static_Integer (First_Bit (CC));
665 LB : constant Uint := Static_Integer (Last_Bit (CC));
666 NFB : constant Uint := MSS - 1 - LB;
667 NLB : constant Uint := NFB + LB - FB;
668 Pos : constant Uint := Static_Integer (Position (CC));
671 -- Do not warn for the artificial clause built for the tag
672 -- in Check_Record_Representation_Clause if it is inherited.
674 if Warn_On_Reverse_Bit_Order
675 and then Chars (Comp) /= Name_uTag
677 Error_Msg_Uint_1 := MSS;
679 ("info: reverse bit order in machine scalar of "
680 & "length^?V?", First_Bit (CC));
681 Error_Msg_Uint_1 := NFB;
682 Error_Msg_Uint_2 := NLB;
684 if Bytes_Big_Endian then
686 ("\big-endian range for component & is ^ .. ^?V?",
687 First_Bit (CC), Comp);
690 ("\little-endian range for component & is ^ .. ^?V?",
691 First_Bit (CC), Comp);
695 Set_Component_Bit_Offset (Comp, Pos * SSU + NFB);
696 Set_Esize (Comp, 1 + (NLB - NFB));
697 Set_Normalized_First_Bit (Comp, NFB mod SSU);
698 Set_Normalized_Position (Comp, Pos + NFB / SSU);
703 end Adjust_Record_For_Reverse_Bit_Order;
705 ------------------------------------------------
706 -- Adjust_Record_For_Reverse_Bit_Order_Ada_95 --
707 ------------------------------------------------
709 procedure Adjust_Record_For_Reverse_Bit_Order_Ada_95 (R : Entity_Id) is
714 -- For Ada 95, we just renumber bits within a storage unit. We do the
715 -- same for Ada 83 mode, since we recognize the Bit_Order attribute in
716 -- Ada 83, and are free to add this extension.
718 Comp := First_Component_Or_Discriminant (R);
719 while Present (Comp) loop
720 CC := Component_Clause (Comp);
722 -- If component clause is present, then deal with the non-default
723 -- bit order case for Ada 95 mode.
725 -- We only do this processing for the base type, and in fact that
726 -- is important, since otherwise if there are record subtypes, we
727 -- could reverse the bits once for each subtype, which is wrong.
729 if Present (CC) and then Ekind (R) = E_Record_Type then
731 CFB : constant Uint := Component_Bit_Offset (Comp);
732 CSZ : constant Uint := Esize (Comp);
733 CLC : constant Node_Id := Component_Clause (Comp);
734 Pos : constant Node_Id := Position (CLC);
735 FB : constant Node_Id := First_Bit (CLC);
737 Storage_Unit_Offset : constant Uint :=
738 CFB / System_Storage_Unit;
740 Start_Bit : constant Uint :=
741 CFB mod System_Storage_Unit;
744 -- Cases where field goes over storage unit boundary
746 if Start_Bit + CSZ > System_Storage_Unit then
748 -- Allow multi-byte field but generate warning
750 if Start_Bit mod System_Storage_Unit = 0
751 and then CSZ mod System_Storage_Unit = 0
754 ("info: multi-byte field specified with non-standard "
755 & "Bit_Order?V?", CLC);
757 if Bytes_Big_Endian then
759 ("\bytes are not reversed "
760 & "(component is big-endian)?V?", CLC);
763 ("\bytes are not reversed "
764 & "(component is little-endian)?V?", CLC);
767 -- Do not allow non-contiguous field
771 ("attempt to specify non-contiguous field not "
774 ("\caused by non-standard Bit_Order specified in "
775 & "legacy Ada 95 mode", CLC);
778 -- Case where field fits in one storage unit
781 -- Give warning if suspicious component clause
783 if Intval (FB) >= System_Storage_Unit
784 and then Warn_On_Reverse_Bit_Order
787 ("info: Bit_Order clause does not affect byte "
788 & "ordering?V?", Pos);
790 Intval (Pos) + Intval (FB) /
793 ("info: position normalized to ^ before bit order "
794 & "interpreted?V?", Pos);
797 -- Here is where we fix up the Component_Bit_Offset value
798 -- to account for the reverse bit order. Some examples of
799 -- what needs to be done are:
801 -- First_Bit .. Last_Bit Component_Bit_Offset
813 -- The rule is that the first bit is obtained by subtracting
814 -- the old ending bit from storage_unit - 1.
816 Set_Component_Bit_Offset (Comp,
817 (Storage_Unit_Offset * System_Storage_Unit) +
818 (System_Storage_Unit - 1) -
819 (Start_Bit + CSZ - 1));
821 Set_Normalized_Position (Comp,
822 Component_Bit_Offset (Comp) / System_Storage_Unit);
824 Set_Normalized_First_Bit (Comp,
825 Component_Bit_Offset (Comp) mod System_Storage_Unit);
830 Next_Component_Or_Discriminant (Comp);
832 end Adjust_Record_For_Reverse_Bit_Order_Ada_95;
834 -------------------------------------
835 -- Alignment_Check_For_Size_Change --
836 -------------------------------------
838 procedure Alignment_Check_For_Size_Change (Typ : Entity_Id; Size : Uint) is
840 -- If the alignment is known, and not set by a rep clause, and is
841 -- inconsistent with the size being set, then reset it to unknown,
842 -- we assume in this case that the size overrides the inherited
843 -- alignment, and that the alignment must be recomputed.
845 if Known_Alignment (Typ)
846 and then not Has_Alignment_Clause (Typ)
847 and then Size mod (Alignment (Typ) * SSU) /= 0
849 Init_Alignment (Typ);
851 end Alignment_Check_For_Size_Change;
853 -----------------------------------
854 -- All_Membership_Choices_Static --
855 -----------------------------------
857 function All_Membership_Choices_Static (Expr : Node_Id) return Boolean is
858 pragma Assert (Nkind (Expr) in N_Membership_Test);
861 (Present (Right_Opnd (Expr))
863 Present (Alternatives (Expr)));
865 if Present (Right_Opnd (Expr)) then
866 return Is_Static_Choice (Right_Opnd (Expr));
868 return All_Static_Choices (Alternatives (Expr));
870 end All_Membership_Choices_Static;
872 ------------------------
873 -- All_Static_Choices --
874 ------------------------
876 function All_Static_Choices (L : List_Id) return Boolean is
881 while Present (N) loop
882 if not Is_Static_Choice (N) then
890 end All_Static_Choices;
892 -------------------------------------
893 -- Analyze_Aspects_At_Freeze_Point --
894 -------------------------------------
896 procedure Analyze_Aspects_At_Freeze_Point (E : Entity_Id) is
897 procedure Analyze_Aspect_Default_Value (ASN : Node_Id);
898 -- This routine analyzes an Aspect_Default_[Component_]Value denoted by
899 -- the aspect specification node ASN.
901 procedure Check_Aspect_Too_Late (N : Node_Id);
902 -- This procedure is similar to Rep_Item_Too_Late for representation
903 -- aspects that apply to type and that do not have a corresponding
905 -- Used to check in particular that the expression associated with
906 -- aspect node N for the given type (entity) of the aspect does not
907 -- appear too late according to the rules in RM 13.1(9) and 13.1(10).
909 procedure Inherit_Delayed_Rep_Aspects (ASN : Node_Id);
910 -- As discussed in the spec of Aspects (see Aspect_Delay declaration),
911 -- a derived type can inherit aspects from its parent which have been
912 -- specified at the time of the derivation using an aspect, as in:
914 -- type A is range 1 .. 10
915 -- with Size => Not_Defined_Yet;
919 -- Not_Defined_Yet : constant := 64;
921 -- In this example, the Size of A is considered to be specified prior
922 -- to the derivation, and thus inherited, even though the value is not
923 -- known at the time of derivation. To deal with this, we use two entity
924 -- flags. The flag Has_Derived_Rep_Aspects is set in the parent type (A
925 -- here), and then the flag May_Inherit_Delayed_Rep_Aspects is set in
926 -- the derived type (B here). If this flag is set when the derived type
927 -- is frozen, then this procedure is called to ensure proper inheritance
928 -- of all delayed aspects from the parent type. The derived type is E,
929 -- the argument to Analyze_Aspects_At_Freeze_Point. ASN is the first
930 -- aspect specification node in the Rep_Item chain for the parent type.
932 procedure Make_Pragma_From_Boolean_Aspect (ASN : Node_Id);
933 -- Given an aspect specification node ASN whose expression is an
934 -- optional Boolean, this routines creates the corresponding pragma
935 -- at the freezing point.
937 ----------------------------------
938 -- Analyze_Aspect_Default_Value --
939 ----------------------------------
941 procedure Analyze_Aspect_Default_Value (ASN : Node_Id) is
942 Ent : constant Entity_Id := Entity (ASN);
943 Expr : constant Node_Id := Expression (ASN);
946 Set_Has_Default_Aspect (Base_Type (Ent));
948 if Is_Scalar_Type (Ent) then
949 Set_Default_Aspect_Value (Base_Type (Ent), Expr);
951 Set_Default_Aspect_Component_Value (Base_Type (Ent), Expr);
954 Check_Aspect_Too_Late (ASN);
955 end Analyze_Aspect_Default_Value;
957 ---------------------------
958 -- Check_Aspect_Too_Late --
959 ---------------------------
961 procedure Check_Aspect_Too_Late (N : Node_Id) is
962 Typ : constant Entity_Id := Entity (N);
963 Expr : constant Node_Id := Expression (N);
965 function Find_Type_Reference
966 (Typ : Entity_Id; Expr : Node_Id) return Boolean;
967 -- Return True if a reference to type Typ is found in the expression
970 -------------------------
971 -- Find_Type_Reference --
972 -------------------------
974 function Find_Type_Reference
975 (Typ : Entity_Id; Expr : Node_Id) return Boolean
977 function Find_Type (N : Node_Id) return Traverse_Result;
978 -- Set Found to True if N refers to Typ
984 function Find_Type (N : Node_Id) return Traverse_Result is
987 or else (Nkind (N) in N_Identifier | N_Expanded_Name
988 and then Present (Entity (N))
989 and then Entity (N) = Typ)
997 function Search_Type_Reference is new Traverse_Func (Find_Type);
1000 return Search_Type_Reference (Expr) = Abandon;
1001 end Find_Type_Reference;
1003 Parent_Type : Entity_Id;
1006 -- Ensure Expr is analyzed so that e.g. all types are properly
1007 -- resolved for Find_Type_Reference.
1011 -- A self-referential aspect is illegal if it forces freezing the
1012 -- entity before the corresponding aspect has been analyzed.
1014 if Find_Type_Reference (Typ, Expr) then
1016 ("aspect specification causes premature freezing of&", N, Typ);
1019 -- For representation aspects, check for case of untagged derived
1020 -- type whose parent either has primitive operations (pre Ada 202x),
1021 -- or is a by-reference type (RM 13.1(10)).
1022 -- Strictly speaking the check also applies to Ada 2012 but it is
1023 -- really too constraining for existing code already, so relax it.
1024 -- ??? Confirming aspects should be allowed here.
1026 if Is_Representation_Aspect (Get_Aspect_Id (N))
1027 and then Is_Derived_Type (Typ)
1028 and then not Is_Tagged_Type (Typ)
1030 Parent_Type := Etype (Base_Type (Typ));
1032 if Ada_Version <= Ada_2012
1033 and then Has_Primitive_Operations (Parent_Type)
1036 ("|representation aspect not permitted before Ada 202x: " &
1037 "use -gnat2020!", N);
1039 ("\parent type & has primitive operations!", N, Parent_Type);
1041 elsif Is_By_Reference_Type (Parent_Type) then
1042 No_Type_Rep_Item (N);
1044 ("\parent type & is a by-reference type!", N, Parent_Type);
1047 end Check_Aspect_Too_Late;
1049 ---------------------------------
1050 -- Inherit_Delayed_Rep_Aspects --
1051 ---------------------------------
1053 procedure Inherit_Delayed_Rep_Aspects (ASN : Node_Id) is
1054 A_Id : constant Aspect_Id := Get_Aspect_Id (ASN);
1055 P : constant Entity_Id := Entity (ASN);
1056 -- Entity for parent type
1059 -- Item from Rep_Item chain
1064 -- Loop through delayed aspects for the parent type
1067 while Present (N) loop
1068 if Nkind (N) = N_Aspect_Specification then
1069 exit when Entity (N) /= P;
1071 if Is_Delayed_Aspect (N) then
1072 A := Get_Aspect_Id (Chars (Identifier (N)));
1074 -- Process delayed rep aspect. For Boolean attributes it is
1075 -- not possible to cancel an attribute once set (the attempt
1076 -- to use an aspect with xxx => False is an error) for a
1077 -- derived type. So for those cases, we do not have to check
1078 -- if a clause has been given for the derived type, since it
1079 -- is harmless to set it again if it is already set.
1085 when Aspect_Alignment =>
1086 if not Has_Alignment_Clause (E) then
1087 Set_Alignment (E, Alignment (P));
1092 when Aspect_Atomic =>
1093 if Is_Atomic (P) then
1097 -- Atomic_Components
1099 when Aspect_Atomic_Components =>
1100 if Has_Atomic_Components (P) then
1101 Set_Has_Atomic_Components (Base_Type (E));
1106 when Aspect_Bit_Order =>
1107 if Is_Record_Type (E)
1108 and then No (Get_Attribute_Definition_Clause
1109 (E, Attribute_Bit_Order))
1110 and then Reverse_Bit_Order (P)
1112 Set_Reverse_Bit_Order (Base_Type (E));
1117 when Aspect_Component_Size =>
1118 if Is_Array_Type (E)
1119 and then not Has_Component_Size_Clause (E)
1122 (Base_Type (E), Component_Size (P));
1127 when Aspect_Machine_Radix =>
1128 if Is_Decimal_Fixed_Point_Type (E)
1129 and then not Has_Machine_Radix_Clause (E)
1131 Set_Machine_Radix_10 (E, Machine_Radix_10 (P));
1134 -- Object_Size (also Size which also sets Object_Size)
1136 when Aspect_Object_Size
1139 if not Has_Size_Clause (E)
1141 No (Get_Attribute_Definition_Clause
1142 (E, Attribute_Object_Size))
1144 Set_Esize (E, Esize (P));
1150 if not Is_Packed (E) then
1151 Set_Is_Packed (Base_Type (E));
1153 if Is_Bit_Packed_Array (P) then
1154 Set_Is_Bit_Packed_Array (Base_Type (E));
1155 Set_Packed_Array_Impl_Type
1156 (E, Packed_Array_Impl_Type (P));
1160 -- Scalar_Storage_Order
1162 when Aspect_Scalar_Storage_Order =>
1163 if (Is_Record_Type (E) or else Is_Array_Type (E))
1164 and then No (Get_Attribute_Definition_Clause
1165 (E, Attribute_Scalar_Storage_Order))
1166 and then Reverse_Storage_Order (P)
1168 Set_Reverse_Storage_Order (Base_Type (E));
1170 -- Clear default SSO indications, since the aspect
1171 -- overrides the default.
1173 Set_SSO_Set_Low_By_Default (Base_Type (E), False);
1174 Set_SSO_Set_High_By_Default (Base_Type (E), False);
1179 when Aspect_Small =>
1180 if Is_Fixed_Point_Type (E)
1181 and then not Has_Small_Clause (E)
1183 Set_Small_Value (E, Small_Value (P));
1188 when Aspect_Storage_Size =>
1189 if (Is_Access_Type (E) or else Is_Task_Type (E))
1190 and then not Has_Storage_Size_Clause (E)
1192 Set_Storage_Size_Variable
1193 (Base_Type (E), Storage_Size_Variable (P));
1198 when Aspect_Value_Size =>
1200 -- Value_Size is never inherited, it is either set by
1201 -- default, or it is explicitly set for the derived
1202 -- type. So nothing to do here.
1208 when Aspect_Volatile =>
1209 if Is_Volatile (P) then
1210 Set_Is_Volatile (E);
1213 -- Volatile_Full_Access (also Full_Access_Only)
1215 when Aspect_Volatile_Full_Access
1216 | Aspect_Full_Access_Only
1218 if Is_Volatile_Full_Access (P) then
1219 Set_Is_Volatile_Full_Access (E);
1222 -- Volatile_Components
1224 when Aspect_Volatile_Components =>
1225 if Has_Volatile_Components (P) then
1226 Set_Has_Volatile_Components (Base_Type (E));
1229 -- That should be all the Rep Aspects
1232 pragma Assert (Aspect_Delay (A_Id) /= Rep_Aspect);
1240 end Inherit_Delayed_Rep_Aspects;
1242 -------------------------------------
1243 -- Make_Pragma_From_Boolean_Aspect --
1244 -------------------------------------
1246 procedure Make_Pragma_From_Boolean_Aspect (ASN : Node_Id) is
1247 Ident : constant Node_Id := Identifier (ASN);
1248 A_Name : constant Name_Id := Chars (Ident);
1249 A_Id : constant Aspect_Id := Get_Aspect_Id (A_Name);
1250 Ent : constant Entity_Id := Entity (ASN);
1251 Expr : constant Node_Id := Expression (ASN);
1252 Loc : constant Source_Ptr := Sloc (ASN);
1254 procedure Check_False_Aspect_For_Derived_Type;
1255 -- This procedure checks for the case of a false aspect for a derived
1256 -- type, which improperly tries to cancel an aspect inherited from
1259 -----------------------------------------
1260 -- Check_False_Aspect_For_Derived_Type --
1261 -----------------------------------------
1263 procedure Check_False_Aspect_For_Derived_Type is
1267 -- We are only checking derived types
1269 if not Is_Derived_Type (E) then
1273 Par := Nearest_Ancestor (E);
1279 if not Is_Atomic (Par) then
1283 when Aspect_Atomic_Components =>
1284 if not Has_Atomic_Components (Par) then
1288 when Aspect_Discard_Names =>
1289 if not Discard_Names (Par) then
1294 if not Is_Packed (Par) then
1298 when Aspect_Unchecked_Union =>
1299 if not Is_Unchecked_Union (Par) then
1303 when Aspect_Volatile =>
1304 if not Is_Volatile (Par) then
1308 when Aspect_Volatile_Components =>
1309 if not Has_Volatile_Components (Par) then
1313 when Aspect_Volatile_Full_Access
1314 | Aspect_Full_Access_Only
1316 if not Is_Volatile_Full_Access (Par) then
1324 -- Fall through means we are canceling an inherited aspect
1326 Error_Msg_Name_1 := A_Name;
1328 ("derived type& inherits aspect%, cannot cancel", Expr, E);
1329 end Check_False_Aspect_For_Derived_Type;
1336 -- Start of processing for Make_Pragma_From_Boolean_Aspect
1339 if Present (Expr) and then Is_False (Static_Boolean (Expr)) then
1340 Check_False_Aspect_For_Derived_Type;
1343 -- There is no Full_Access_Only pragma so use VFA instead
1345 if A_Name = Name_Full_Access_Only then
1346 P_Name := Name_Volatile_Full_Access;
1353 Pragma_Identifier =>
1354 Make_Identifier (Sloc (Ident), P_Name),
1355 Pragma_Argument_Associations => New_List (
1356 Make_Pragma_Argument_Association (Sloc (Ident),
1357 Expression => New_Occurrence_Of (Ent, Sloc (Ident)))));
1359 Set_From_Aspect_Specification (Prag, True);
1360 Set_Corresponding_Aspect (Prag, ASN);
1361 Set_Aspect_Rep_Item (ASN, Prag);
1362 Set_Is_Delayed_Aspect (Prag);
1363 Set_Parent (Prag, ASN);
1365 end Make_Pragma_From_Boolean_Aspect;
1373 -- Start of processing for Analyze_Aspects_At_Freeze_Point
1376 -- Must be visible in current scope, but if this is a type from a nested
1377 -- package it may be frozen from an object declaration in the enclosing
1378 -- scope, so install the package declarations to complete the analysis
1379 -- of the aspects, if any. If the package itself is frozen the type will
1380 -- have been frozen as well.
1382 if not Scope_Within_Or_Same (Current_Scope, Scope (E)) then
1383 if Is_Type (E) and then From_Nested_Package (E) then
1385 Pack : constant Entity_Id := Scope (E);
1389 Install_Visible_Declarations (Pack);
1390 Install_Private_Declarations (Pack);
1391 Analyze_Aspects_At_Freeze_Point (E);
1393 if Is_Private_Type (E)
1394 and then Present (Full_View (E))
1396 Analyze_Aspects_At_Freeze_Point (Full_View (E));
1399 End_Package_Scope (Pack);
1403 -- Aspects from other entities in different contexts are analyzed
1411 -- Look for aspect specification entries for this entity
1413 ASN := First_Rep_Item (E);
1414 while Present (ASN) loop
1415 if Nkind (ASN) = N_Aspect_Specification then
1416 exit when Entity (ASN) /= E;
1418 if Is_Delayed_Aspect (ASN) then
1419 A_Id := Get_Aspect_Id (ASN);
1423 -- For aspects whose expression is an optional Boolean, make
1424 -- the corresponding pragma at the freeze point.
1426 when Boolean_Aspects
1427 | Library_Unit_Aspects
1429 -- Aspects Export and Import require special handling.
1430 -- Both are by definition Boolean and may benefit from
1431 -- forward references, however their expressions are
1432 -- treated as static. In addition, the syntax of their
1433 -- corresponding pragmas requires extra "pieces" which
1434 -- may also contain forward references. To account for
1435 -- all of this, the corresponding pragma is created by
1436 -- Analyze_Aspect_Export_Import, but is not analyzed as
1437 -- the complete analysis must happen now.
1439 -- Aspect Full_Access_Only must be analyzed last so that
1440 -- aspects Volatile and Atomic, if any, are analyzed.
1442 if A_Id /= Aspect_Export
1443 and then A_Id /= Aspect_Import
1444 and then A_Id /= Aspect_Full_Access_Only
1446 Make_Pragma_From_Boolean_Aspect (ASN);
1449 -- Special handling for aspects that don't correspond to
1450 -- pragmas/attributes.
1452 when Aspect_Default_Value
1453 | Aspect_Default_Component_Value
1455 -- Do not inherit aspect for anonymous base type of a
1456 -- scalar or array type, because they apply to the first
1457 -- subtype of the type, and will be processed when that
1458 -- first subtype is frozen.
1460 if Is_Derived_Type (E)
1461 and then not Comes_From_Source (E)
1462 and then E /= First_Subtype (E)
1466 Analyze_Aspect_Default_Value (ASN);
1469 -- Ditto for iterator aspects, because the corresponding
1470 -- attributes may not have been analyzed yet.
1472 when Aspect_Constant_Indexing
1473 | Aspect_Default_Iterator
1474 | Aspect_Iterator_Element
1475 | Aspect_Variable_Indexing
1477 Analyze (Expression (ASN));
1479 if Etype (Expression (ASN)) = Any_Type then
1481 ("\aspect must be fully defined before & is frozen",
1485 when Aspect_Integer_Literal
1486 | Aspect_Real_Literal
1487 | Aspect_String_Literal
1489 Validate_Literal_Aspect (E, ASN);
1491 when Aspect_Iterable =>
1492 Validate_Iterable_Aspect (E, ASN);
1494 when Aspect_Aggregate =>
1501 Ritem := Aspect_Rep_Item (ASN);
1503 if Present (Ritem) then
1509 Next_Rep_Item (ASN);
1512 -- Make a second pass for a Full_Access_Only entry
1514 ASN := First_Rep_Item (E);
1515 while Present (ASN) loop
1516 if Nkind (ASN) = N_Aspect_Specification then
1517 exit when Entity (ASN) /= E;
1519 if Get_Aspect_Id (ASN) = Aspect_Full_Access_Only then
1520 Make_Pragma_From_Boolean_Aspect (ASN);
1521 Ritem := Aspect_Rep_Item (ASN);
1522 if Present (Ritem) then
1528 Next_Rep_Item (ASN);
1531 -- This is where we inherit delayed rep aspects from our parent. Note
1532 -- that if we fell out of the above loop with ASN non-empty, it means
1533 -- we hit an aspect for an entity other than E, and it must be the
1534 -- type from which we were derived.
1536 if May_Inherit_Delayed_Rep_Aspects (E) then
1537 Inherit_Delayed_Rep_Aspects (ASN);
1541 and then E /= Base_Type (E)
1542 and then Is_First_Subtype (E)
1544 Inherit_Rep_Item_Chain (Base_Type (E), E);
1546 end Analyze_Aspects_At_Freeze_Point;
1548 -----------------------------------
1549 -- Analyze_Aspect_Specifications --
1550 -----------------------------------
1552 procedure Analyze_Aspect_Specifications (N : Node_Id; E : Entity_Id) is
1553 pragma Assert (Present (E));
1555 procedure Decorate (Asp : Node_Id; Prag : Node_Id);
1556 -- Establish linkages between an aspect and its corresponding pragma
1558 procedure Insert_Pragma
1560 Is_Instance : Boolean := False);
1561 -- Subsidiary to the analysis of aspects
1568 -- Initial_Condition
1576 -- Subprogram_Variant
1578 -- Insert pragma Prag such that it mimics the placement of a source
1579 -- pragma of the same kind. Flag Is_Generic should be set when the
1580 -- context denotes a generic instance.
1586 procedure Decorate (Asp : Node_Id; Prag : Node_Id) is
1588 Set_Aspect_Rep_Item (Asp, Prag);
1589 Set_Corresponding_Aspect (Prag, Asp);
1590 Set_From_Aspect_Specification (Prag);
1591 Set_Parent (Prag, Asp);
1598 procedure Insert_Pragma
1600 Is_Instance : Boolean := False)
1606 Inserted : Boolean := False;
1609 -- When the aspect appears on an entry, package, protected unit,
1610 -- subprogram, or task unit body, insert the generated pragma at the
1611 -- top of the body declarations to emulate the behavior of a source
1614 -- package body Pack with Aspect is
1616 -- package body Pack is
1619 if Nkind (N) in N_Entry_Body
1625 Decls := Declarations (N);
1629 Set_Declarations (N, Decls);
1632 Prepend_To (Decls, Prag);
1634 -- When the aspect is associated with a [generic] package declaration
1635 -- insert the generated pragma at the top of the visible declarations
1636 -- to emulate the behavior of a source pragma.
1638 -- package Pack with Aspect is
1643 elsif Nkind (N) in N_Generic_Package_Declaration
1644 | N_Package_Declaration
1646 Decls := Visible_Declarations (Specification (N));
1650 Set_Visible_Declarations (Specification (N), Decls);
1653 -- The visible declarations of a generic instance have the
1654 -- following structure:
1656 -- <renamings of generic formals>
1657 -- <renamings of internally-generated spec and body>
1658 -- <first source declaration>
1660 -- Insert the pragma before the first source declaration by
1661 -- skipping the instance "header" to ensure proper visibility of
1665 Decl := First (Decls);
1666 while Present (Decl) loop
1667 if Comes_From_Source (Decl) then
1668 Insert_Before (Decl, Prag);
1676 -- The pragma is placed after the instance "header"
1678 if not Inserted then
1679 Append_To (Decls, Prag);
1682 -- Otherwise this is not a generic instance
1685 Prepend_To (Decls, Prag);
1688 -- When the aspect is associated with a protected unit declaration,
1689 -- insert the generated pragma at the top of the visible declarations
1690 -- the emulate the behavior of a source pragma.
1692 -- protected [type] Prot with Aspect is
1694 -- protected [type] Prot is
1697 elsif Nkind (N) = N_Protected_Type_Declaration then
1698 Def := Protected_Definition (N);
1702 Make_Protected_Definition (Sloc (N),
1703 Visible_Declarations => New_List,
1704 End_Label => Empty);
1706 Set_Protected_Definition (N, Def);
1709 Decls := Visible_Declarations (Def);
1713 Set_Visible_Declarations (Def, Decls);
1716 Prepend_To (Decls, Prag);
1718 -- When the aspect is associated with a task unit declaration, insert
1719 -- insert the generated pragma at the top of the visible declarations
1720 -- the emulate the behavior of a source pragma.
1722 -- task [type] Prot with Aspect is
1724 -- task [type] Prot is
1727 elsif Nkind (N) = N_Task_Type_Declaration then
1728 Def := Task_Definition (N);
1732 Make_Task_Definition (Sloc (N),
1733 Visible_Declarations => New_List,
1734 End_Label => Empty);
1736 Set_Task_Definition (N, Def);
1739 Decls := Visible_Declarations (Def);
1743 Set_Visible_Declarations (Def, Decls);
1746 Prepend_To (Decls, Prag);
1748 -- When the context is a library unit, the pragma is added to the
1749 -- Pragmas_After list.
1751 elsif Nkind (Parent (N)) = N_Compilation_Unit then
1752 Aux := Aux_Decls_Node (Parent (N));
1754 if No (Pragmas_After (Aux)) then
1755 Set_Pragmas_After (Aux, New_List);
1758 Prepend (Prag, Pragmas_After (Aux));
1760 -- Default, the pragma is inserted after the context
1763 Insert_After (N, Prag);
1770 Aitem : Node_Id := Empty;
1773 L : constant List_Id := Aspect_Specifications (N);
1774 pragma Assert (Present (L));
1776 Ins_Node : Node_Id := N;
1777 -- Insert pragmas/attribute definition clause after this node when no
1778 -- delayed analysis is required.
1780 -- Start of processing for Analyze_Aspect_Specifications
1783 -- The general processing involves building an attribute definition
1784 -- clause or a pragma node that corresponds to the aspect. Then in order
1785 -- to delay the evaluation of this aspect to the freeze point, we attach
1786 -- the corresponding pragma/attribute definition clause to the aspect
1787 -- specification node, which is then placed in the Rep Item chain. In
1788 -- this case we mark the entity by setting the flag Has_Delayed_Aspects
1789 -- and we evaluate the rep item at the freeze point. When the aspect
1790 -- doesn't have a corresponding pragma/attribute definition clause, then
1791 -- its analysis is simply delayed at the freeze point.
1793 -- Some special cases don't require delay analysis, thus the aspect is
1794 -- analyzed right now.
1796 -- Note that there is a special handling for Pre, Post, Test_Case,
1797 -- Contract_Cases and Subprogram_Variant aspects. In these cases, we do
1798 -- not have to worry about delay issues, since the pragmas themselves
1799 -- deal with delay of visibility for the expression analysis. Thus, we
1800 -- just insert the pragma after the node N.
1802 -- Loop through aspects
1804 Aspect := First (L);
1805 Aspect_Loop : while Present (Aspect) loop
1806 Analyze_One_Aspect : declare
1807 Expr : constant Node_Id := Expression (Aspect);
1808 Id : constant Node_Id := Identifier (Aspect);
1809 Loc : constant Source_Ptr := Sloc (Aspect);
1810 Nam : constant Name_Id := Chars (Id);
1811 A_Id : constant Aspect_Id := Get_Aspect_Id (Nam);
1814 Delay_Required : Boolean;
1815 -- Set False if delay is not required
1817 Eloc : Source_Ptr := No_Location;
1818 -- Source location of expression, modified when we split PPC's. It
1819 -- is set below when Expr is present.
1821 procedure Analyze_Aspect_Convention;
1822 -- Perform analysis of aspect Convention
1824 procedure Analyze_Aspect_Disable_Controlled;
1825 -- Perform analysis of aspect Disable_Controlled
1827 procedure Analyze_Aspect_Export_Import;
1828 -- Perform analysis of aspects Export or Import
1830 procedure Analyze_Aspect_External_Link_Name;
1831 -- Perform analysis of aspects External_Name or Link_Name
1833 procedure Analyze_Aspect_Implicit_Dereference;
1834 -- Perform analysis of the Implicit_Dereference aspects
1836 procedure Analyze_Aspect_Relaxed_Initialization;
1837 -- Perform analysis of aspect Relaxed_Initialization
1839 procedure Analyze_Aspect_Yield;
1840 -- Perform analysis of aspect Yield
1842 procedure Analyze_Aspect_Static;
1843 -- Ada 202x (AI12-0075): Perform analysis of aspect Static
1845 function Make_Aitem_Pragma
1846 (Pragma_Argument_Associations : List_Id;
1847 Pragma_Name : Name_Id) return Node_Id;
1848 -- This is a wrapper for Make_Pragma used for converting aspects
1849 -- to pragmas. It takes care of Sloc (set from Loc) and building
1850 -- the pragma identifier from the given name. In addition the
1851 -- flags Class_Present and Split_PPC are set from the aspect
1852 -- node, as well as Is_Ignored. This routine also sets the
1853 -- From_Aspect_Specification in the resulting pragma node to
1854 -- True, and sets Corresponding_Aspect to point to the aspect.
1855 -- The resulting pragma is assigned to Aitem.
1857 -------------------------------
1858 -- Analyze_Aspect_Convention --
1859 -------------------------------
1861 procedure Analyze_Aspect_Convention is
1870 -- Obtain all interfacing aspects that apply to the related
1873 Get_Interfacing_Aspects
1874 (Iface_Asp => Aspect,
1875 Conv_Asp => Dummy_1,
1882 -- The related entity is subject to aspect Export or Import.
1883 -- Do not process Convention now because it must be analysed
1884 -- as part of Export or Import.
1886 if Present (Expo) or else Present (Imp) then
1889 -- Otherwise Convention appears by itself
1892 -- The aspect specifies a particular convention
1894 if Present (Expr) then
1895 Conv := New_Copy_Tree (Expr);
1897 -- Otherwise assume convention Ada
1900 Conv := Make_Identifier (Loc, Name_Ada);
1904 -- pragma Convention (<Conv>, <E>);
1906 Aitem := Make_Aitem_Pragma
1907 (Pragma_Name => Name_Convention,
1908 Pragma_Argument_Associations => New_List (
1909 Make_Pragma_Argument_Association (Loc,
1910 Expression => Conv),
1911 Make_Pragma_Argument_Association (Loc,
1912 Expression => New_Occurrence_Of (E, Loc))));
1914 Decorate (Aspect, Aitem);
1915 Insert_Pragma (Aitem);
1917 end Analyze_Aspect_Convention;
1919 ---------------------------------------
1920 -- Analyze_Aspect_Disable_Controlled --
1921 ---------------------------------------
1923 procedure Analyze_Aspect_Disable_Controlled is
1925 -- The aspect applies only to controlled records
1927 if not (Ekind (E) = E_Record_Type
1928 and then Is_Controlled_Active (E))
1931 ("aspect % requires controlled record type", Aspect);
1935 -- Preanalyze the expression (if any) when the aspect resides
1936 -- in a generic unit.
1938 if Inside_A_Generic then
1939 if Present (Expr) then
1940 Preanalyze_And_Resolve (Expr, Any_Boolean);
1943 -- Otherwise the aspect resides in a nongeneric context
1946 -- A controlled record type loses its controlled semantics
1947 -- when the expression statically evaluates to True.
1949 if Present (Expr) then
1950 Analyze_And_Resolve (Expr, Any_Boolean);
1952 if Is_OK_Static_Expression (Expr) then
1953 if Is_True (Static_Boolean (Expr)) then
1954 Set_Disable_Controlled (E);
1957 -- Otherwise the expression is not static
1961 ("expression of aspect % must be static", Aspect);
1964 -- Otherwise the aspect appears without an expression and
1965 -- defaults to True.
1968 Set_Disable_Controlled (E);
1971 end Analyze_Aspect_Disable_Controlled;
1973 ----------------------------------
1974 -- Analyze_Aspect_Export_Import --
1975 ----------------------------------
1977 procedure Analyze_Aspect_Export_Import is
1985 -- Obtain all interfacing aspects that apply to the related
1988 Get_Interfacing_Aspects
1989 (Iface_Asp => Aspect,
1990 Conv_Asp => Dummy_1,
1997 -- The related entity cannot be subject to both aspects Export
2000 if Present (Expo) and then Present (Imp) then
2002 ("incompatible interfacing aspects given for &", E);
2003 Error_Msg_Sloc := Sloc (Expo);
2004 Error_Msg_N ("\aspect `Export` #", E);
2005 Error_Msg_Sloc := Sloc (Imp);
2006 Error_Msg_N ("\aspect `Import` #", E);
2009 -- A variable is most likely modified from the outside. Take
2010 -- the optimistic approach to avoid spurious errors.
2012 if Ekind (E) = E_Variable then
2013 Set_Never_Set_In_Source (E, False);
2016 -- Resolve the expression of an Import or Export here, and
2017 -- require it to be of type Boolean and static. This is not
2018 -- quite right, because in general this should be delayed,
2019 -- but that seems tricky for these, because normally Boolean
2020 -- aspects are replaced with pragmas at the freeze point in
2021 -- Make_Pragma_From_Boolean_Aspect.
2023 if not Present (Expr)
2024 or else Is_True (Static_Boolean (Expr))
2026 if A_Id = Aspect_Import then
2027 Set_Has_Completion (E);
2028 Set_Is_Imported (E);
2030 -- An imported object cannot be explicitly initialized
2032 if Nkind (N) = N_Object_Declaration
2033 and then Present (Expression (N))
2036 ("imported entities cannot be initialized "
2037 & "(RM B.1(24))", Expression (N));
2041 pragma Assert (A_Id = Aspect_Export);
2042 Set_Is_Exported (E);
2045 -- Create the proper form of pragma Export or Import taking
2046 -- into account Conversion, External_Name, and Link_Name.
2048 Aitem := Build_Export_Import_Pragma (Aspect, E);
2050 -- Otherwise the expression is either False or erroneous. There
2051 -- is no corresponding pragma.
2056 end Analyze_Aspect_Export_Import;
2058 ---------------------------------------
2059 -- Analyze_Aspect_External_Link_Name --
2060 ---------------------------------------
2062 procedure Analyze_Aspect_External_Link_Name is
2070 -- Obtain all interfacing aspects that apply to the related
2073 Get_Interfacing_Aspects
2074 (Iface_Asp => Aspect,
2075 Conv_Asp => Dummy_1,
2082 -- Ensure that aspect External_Name applies to aspect Export or
2085 if A_Id = Aspect_External_Name then
2086 if No (Expo) and then No (Imp) then
2088 ("aspect `External_Name` requires aspect `Import` or "
2089 & "`Export`", Aspect);
2092 -- Otherwise ensure that aspect Link_Name applies to aspect
2093 -- Export or Import.
2096 pragma Assert (A_Id = Aspect_Link_Name);
2097 if No (Expo) and then No (Imp) then
2099 ("aspect `Link_Name` requires aspect `Import` or "
2100 & "`Export`", Aspect);
2103 end Analyze_Aspect_External_Link_Name;
2105 -----------------------------------------
2106 -- Analyze_Aspect_Implicit_Dereference --
2107 -----------------------------------------
2109 procedure Analyze_Aspect_Implicit_Dereference is
2111 if not Is_Type (E) or else not Has_Discriminants (E) then
2113 ("aspect must apply to a type with discriminants", Expr);
2115 elsif not Is_Entity_Name (Expr) then
2117 ("aspect must name a discriminant of current type", Expr);
2120 -- Discriminant type be an anonymous access type or an
2121 -- anonymous access to subprogram.
2123 -- Missing synchronized types???
2126 Disc : Entity_Id := First_Discriminant (E);
2128 while Present (Disc) loop
2129 if Chars (Expr) = Chars (Disc)
2130 and then Ekind (Etype (Disc)) in
2131 E_Anonymous_Access_Subprogram_Type |
2132 E_Anonymous_Access_Type
2134 Set_Has_Implicit_Dereference (E);
2135 Set_Has_Implicit_Dereference (Disc);
2139 Next_Discriminant (Disc);
2142 -- Error if no proper access discriminant
2144 if Present (Disc) then
2145 -- For a type extension, check whether parent has
2146 -- a reference discriminant, to verify that use is
2149 if Is_Derived_Type (E)
2150 and then Has_Discriminants (Etype (E))
2153 Parent_Disc : constant Entity_Id :=
2154 Get_Reference_Discriminant (Etype (E));
2156 if Present (Parent_Disc)
2157 and then Corresponding_Discriminant (Disc) /=
2161 ("reference discriminant does not match "
2162 & "discriminant of parent type", Expr);
2169 ("not an access discriminant of&", Expr, E);
2174 end Analyze_Aspect_Implicit_Dereference;
2176 -------------------------------------------
2177 -- Analyze_Aspect_Relaxed_Initialization --
2178 -------------------------------------------
2180 procedure Analyze_Aspect_Relaxed_Initialization is
2181 procedure Analyze_Relaxed_Parameter
2182 (Subp_Id : Entity_Id;
2184 Seen : in out Elist_Id);
2185 -- Analyze parameter that appears in the expression of the
2186 -- aspect Relaxed_Initialization.
2188 -------------------------------
2189 -- Analyze_Relaxed_Parameter --
2190 -------------------------------
2192 procedure Analyze_Relaxed_Parameter
2193 (Subp_Id : Entity_Id;
2195 Seen : in out Elist_Id)
2198 -- Set name of the aspect for error messages
2199 Error_Msg_Name_1 := Nam;
2201 -- The relaxed parameter is a formal parameter
2203 if Nkind (Param) in N_Identifier | N_Expanded_Name then
2207 Item : constant Entity_Id := Entity (Param);
2209 -- It must be a formal of the analyzed subprogram
2211 if Scope (Item) = Subp_Id then
2213 pragma Assert (Is_Formal (Item));
2215 -- It must not have scalar or access type
2217 if Is_Elementary_Type (Etype (Item)) then
2218 Error_Msg_N ("illegal aspect % item", Param);
2220 ("\item must not have elementary type", Param);
2223 -- Detect duplicated items
2225 if Contains (Seen, Item) then
2226 Error_Msg_N ("duplicate aspect % item", Param);
2228 Append_New_Elmt (Item, Seen);
2231 Error_Msg_N ("illegal aspect % item", Param);
2235 -- The relaxed parameter is the function's Result attribute
2237 elsif Is_Attribute_Result (Param) then
2241 Pref : constant Node_Id := Prefix (Param);
2245 Nkind (Pref) in N_Identifier | N_Expanded_Name
2247 Entity (Pref) = Subp_Id
2249 -- Function result must not have scalar or access
2252 if Is_Elementary_Type (Etype (Pref)) then
2253 Error_Msg_N ("illegal aspect % item", Param);
2255 ("\function result must not have elementary"
2259 -- Detect duplicated items
2261 if Contains (Seen, Subp_Id) then
2262 Error_Msg_N ("duplicate aspect % item", Param);
2264 Append_New_Elmt (Entity (Pref), Seen);
2268 Error_Msg_N ("illegal aspect % item", Param);
2272 Error_Msg_N ("illegal aspect % item", Param);
2274 end Analyze_Relaxed_Parameter;
2278 Seen : Elist_Id := No_Elist;
2279 -- Items that appear in the relaxed initialization aspect
2280 -- expression of a subprogram; for detecting duplicates.
2282 Restore_Scope : Boolean;
2283 -- Will be set to True if we need to restore the scope table
2284 -- after analyzing the aspect expression.
2286 Prev_Id : Entity_Id;
2288 -- Start of processing for Analyze_Aspect_Relaxed_Initialization
2291 -- Set name of the aspect for error messages
2292 Error_Msg_Name_1 := Nam;
2294 -- Annotation of a type; no aspect expression is allowed.
2295 -- For a private type, the aspect must be attached to the
2298 -- ??? Once the exact rule for this aspect is ready, we will
2299 -- likely reject concurrent types, etc., so let's keep the code
2300 -- for types and variable separate.
2302 if Is_First_Subtype (E) then
2303 Prev_Id := Incomplete_Or_Partial_View (E);
2304 if Present (Prev_Id) then
2306 -- Aspect may appear on the full view of an incomplete
2307 -- type because the incomplete declaration cannot have
2310 if Ekind (Prev_Id) = E_Incomplete_Type then
2313 Error_Msg_N ("aspect % must apply to partial view", N);
2316 elsif Present (Expr) then
2317 Error_Msg_N ("illegal aspect % expression", Expr);
2320 -- Annotation of a variable; no aspect expression is allowed
2322 elsif Ekind (E) = E_Variable then
2323 if Present (Expr) then
2324 Error_Msg_N ("illegal aspect % expression", Expr);
2327 -- Annotation of a constant; no aspect expression is allowed.
2328 -- For a deferred constant, the aspect must be attached to the
2331 elsif Ekind (E) = E_Constant then
2332 if Present (Incomplete_Or_Partial_View (E)) then
2334 ("aspect % must apply to deferred constant", N);
2336 elsif Present (Expr) then
2337 Error_Msg_N ("illegal aspect % expression", Expr);
2340 -- Annotation of a subprogram; aspect expression is required
2342 elsif Is_Subprogram_Or_Entry (E)
2343 or else Is_Generic_Subprogram (E)
2345 if Present (Expr) then
2347 -- If we analyze subprogram body that acts as its own
2348 -- spec, then the subprogram itself and its formals are
2349 -- already installed; otherwise, we need to install them,
2350 -- as they must be visible when analyzing the aspect
2353 if In_Open_Scopes (E) then
2354 Restore_Scope := False;
2356 Restore_Scope := True;
2359 -- Only formals of the subprogram itself can appear
2360 -- in Relaxed_Initialization aspect expression, not
2361 -- formals of the enclosing generic unit. (This is
2362 -- different than in Precondition or Depends aspects,
2363 -- where both kinds of formals are allowed.)
2365 Install_Formals (E);
2368 -- Aspect expression is either an aggregate with list of
2369 -- parameters (and possibly the Result attribute for a
2372 if Nkind (Expr) = N_Aggregate then
2374 -- Component associations in the aggregate must be a
2375 -- parameter name followed by a static boolean
2378 if Present (Component_Associations (Expr)) then
2381 First (Component_Associations (Expr));
2383 while Present (Assoc) loop
2384 if List_Length (Choices (Assoc)) = 1 then
2385 Analyze_Relaxed_Parameter
2386 (E, First (Choices (Assoc)), Seen);
2388 if Inside_A_Generic then
2389 Preanalyze_And_Resolve
2390 (Expression (Assoc), Any_Boolean);
2393 (Expression (Assoc), Any_Boolean);
2396 if not Is_OK_Static_Expression
2397 (Expression (Assoc))
2399 Error_Msg_Name_1 := Nam;
2401 ("expression of aspect %" &
2402 "must be static", Aspect);
2406 Error_Msg_Name_1 := Nam;
2408 ("illegal aspect % expression", Expr);
2415 -- Expressions of the aggregate are parameter names
2417 if Present (Expressions (Expr)) then
2419 Param : Node_Id := First (Expressions (Expr));
2422 while Present (Param) loop
2423 Analyze_Relaxed_Parameter (E, Param, Seen);
2429 -- Mark the aggregate expression itself as analyzed;
2430 -- its subexpressions were marked when they themselves
2433 Set_Analyzed (Expr);
2435 -- Otherwise, it is a single name of a subprogram
2436 -- parameter (or possibly the Result attribute for
2440 Analyze_Relaxed_Parameter (E, Expr, Seen);
2443 if Restore_Scope then
2447 Error_Msg_N ("missing expression for aspect %", N);
2451 Error_Msg_N ("inappropriate entity for aspect %", E);
2453 end Analyze_Aspect_Relaxed_Initialization;
2455 ---------------------------
2456 -- Analyze_Aspect_Static --
2457 ---------------------------
2459 procedure Analyze_Aspect_Static is
2460 function Has_Convention_Intrinsic (L : List_Id) return Boolean;
2461 -- Return True if L contains a pragma argument association
2462 -- node representing a convention Intrinsic.
2464 ------------------------------
2465 -- Has_Convention_Intrinsic --
2466 ------------------------------
2468 function Has_Convention_Intrinsic
2469 (L : List_Id) return Boolean
2471 Arg : Node_Id := First (L);
2473 while Present (Arg) loop
2474 if Nkind (Arg) = N_Pragma_Argument_Association
2475 and then Chars (Arg) = Name_Convention
2476 and then Chars (Expression (Arg)) = Name_Intrinsic
2485 end Has_Convention_Intrinsic;
2487 Is_Imported_Intrinsic : Boolean;
2490 if Ada_Version < Ada_2020 then
2492 ("aspect % is an Ada 202x feature", Aspect);
2493 Error_Msg_N ("\compile with -gnat2020", Aspect);
2498 Is_Imported_Intrinsic := Is_Imported (E)
2500 Has_Convention_Intrinsic
2501 (Pragma_Argument_Associations (Import_Pragma (E)));
2503 -- The aspect applies only to expression functions that
2504 -- statisfy the requirements for a static expression function
2505 -- (such as having an expression that is predicate-static) as
2506 -- well as Intrinsic imported functions as a -gnatX extension.
2508 if not Is_Expression_Function (E)
2510 not (Extensions_Allowed and then Is_Imported_Intrinsic)
2512 if Extensions_Allowed then
2514 ("aspect % requires intrinsic or expression function",
2517 elsif Is_Imported_Intrinsic then
2519 ("aspect % on intrinsic function is an extension: " &
2525 ("aspect % requires expression function", Aspect);
2530 -- Ada 202x (AI12-0075): Check that the function satisfies
2531 -- several requirements of static functions as specified in
2532 -- RM 6.8(5.1-5.8). Note that some of the requirements given
2533 -- there are checked elsewhere.
2536 -- The expression of the expression function must be a
2537 -- potentially static expression (RM 202x 6.8(3.2-3.4)).
2538 -- That's checked in Sem_Ch6.Analyze_Expression_Function.
2540 -- The function must not contain any calls to itself, which
2541 -- is checked in Sem_Res.Resolve_Call.
2543 -- Each formal must be of mode in and have a static subtype
2546 Formal : Entity_Id := First_Formal (E);
2548 while Present (Formal) loop
2549 if Ekind (Formal) /= E_In_Parameter then
2551 ("aspect % requires formals of mode IN",
2557 if not Is_Static_Subtype (Etype (Formal)) then
2559 ("aspect % requires formals with static subtypes",
2565 Next_Formal (Formal);
2569 -- The function's result subtype must be a static subtype
2571 if not Is_Static_Subtype (Etype (E)) then
2573 ("aspect % requires function with result of "
2574 & "a static subtype",
2580 -- Check that the function does not have any applicable
2581 -- precondition or postcondition expression.
2583 for Asp in Pre_Post_Aspects loop
2584 if Has_Aspect (E, Asp) then
2586 ("this aspect not allowed for static expression "
2587 & "functions", Find_Aspect (E, Asp));
2593 -- ??? TBD: Must check that "for result type R, if the
2594 -- function is a boundary entity for type R (see 7.3.2),
2595 -- no type invariant applies to type R; if R has a
2596 -- component type C, a similar rule applies to C."
2599 -- Preanalyze the expression (if any) when the aspect resides
2600 -- in a generic unit. (Is this generic-related code necessary
2601 -- for this aspect? It's modeled on what's done for aspect
2602 -- Disable_Controlled. ???)
2604 if Inside_A_Generic then
2605 if Present (Expr) then
2606 Preanalyze_And_Resolve (Expr, Any_Boolean);
2609 -- Otherwise the aspect resides in a nongeneric context
2612 -- When the expression statically evaluates to True, the
2613 -- expression function is treated as a static function.
2614 -- Otherwise the aspect appears without an expression and
2615 -- defaults to True.
2617 if Present (Expr) then
2618 Analyze_And_Resolve (Expr, Any_Boolean);
2620 -- Error if the boolean expression is not static
2622 if not Is_OK_Static_Expression (Expr) then
2624 ("expression of aspect % must be static", Aspect);
2628 end Analyze_Aspect_Static;
2630 --------------------------
2631 -- Analyze_Aspect_Yield --
2632 --------------------------
2634 procedure Analyze_Aspect_Yield is
2635 Expr_Value : Boolean := False;
2638 -- Check valid declarations for 'Yield
2640 if Nkind (N) in N_Abstract_Subprogram_Declaration
2641 | N_Entry_Declaration
2642 | N_Generic_Subprogram_Declaration
2643 | N_Subprogram_Declaration
2644 | N_Formal_Subprogram_Declaration
2645 and then not Within_Protected_Type (E)
2649 elsif Within_Protected_Type (E) then
2651 ("aspect% not applicable to protected operations", Id);
2656 ("aspect% only applicable to subprogram and entry "
2657 & "declarations", Id);
2661 -- Evaluate its static expression (if available); otherwise it
2662 -- defaults to True.
2667 -- Otherwise it must have a static boolean expression
2670 if Inside_A_Generic then
2671 Preanalyze_And_Resolve (Expr, Any_Boolean);
2673 Analyze_And_Resolve (Expr, Any_Boolean);
2676 if Is_OK_Static_Expression (Expr) then
2677 if Is_True (Static_Boolean (Expr)) then
2682 ("expression of aspect % must be static", Aspect);
2687 Set_Has_Yield_Aspect (E);
2690 -- If the Yield aspect is specified for a dispatching
2691 -- subprogram that inherits the aspect, the specified
2692 -- value shall be confirming.
2695 and then Is_Dispatching_Operation (E)
2696 and then Present (Overridden_Operation (E))
2697 and then Has_Yield_Aspect (Overridden_Operation (E))
2698 /= Is_True (Static_Boolean (Expr))
2700 Error_Msg_N ("specification of inherited aspect% can only " &
2701 "confirm parent value", Id);
2703 end Analyze_Aspect_Yield;
2705 -----------------------
2706 -- Make_Aitem_Pragma --
2707 -----------------------
2709 function Make_Aitem_Pragma
2710 (Pragma_Argument_Associations : List_Id;
2711 Pragma_Name : Name_Id) return Node_Id
2713 Args : List_Id := Pragma_Argument_Associations;
2717 -- We should never get here if aspect was disabled
2719 pragma Assert (not Is_Disabled (Aspect));
2721 -- Certain aspects allow for an optional name or expression. Do
2722 -- not generate a pragma with empty argument association list.
2724 if No (Args) or else No (Expression (First (Args))) then
2732 Pragma_Argument_Associations => Args,
2733 Pragma_Identifier =>
2734 Make_Identifier (Sloc (Id), Pragma_Name),
2735 Class_Present => Class_Present (Aspect),
2736 Split_PPC => Split_PPC (Aspect));
2738 -- Set additional semantic fields
2740 if Is_Ignored (Aspect) then
2741 Set_Is_Ignored (Aitem);
2742 elsif Is_Checked (Aspect) then
2743 Set_Is_Checked (Aitem);
2746 Set_Corresponding_Aspect (Aitem, Aspect);
2747 Set_From_Aspect_Specification (Aitem);
2750 end Make_Aitem_Pragma;
2752 -- Start of processing for Analyze_One_Aspect
2755 -- Skip aspect if already analyzed, to avoid looping in some cases
2757 if Analyzed (Aspect) then
2761 -- Skip looking at aspect if it is totally disabled. Just mark it
2762 -- as such for later reference in the tree. This also sets the
2763 -- Is_Ignored and Is_Checked flags appropriately.
2765 Check_Applicable_Policy (Aspect);
2767 if Is_Disabled (Aspect) then
2771 -- Set the source location of expression, used in the case of
2772 -- a failed precondition/postcondition or invariant. Note that
2773 -- the source location of the expression is not usually the best
2774 -- choice here. For example, it gets located on the last AND
2775 -- keyword in a chain of boolean expressiond AND'ed together.
2776 -- It is best to put the message on the first character of the
2777 -- assertion, which is the effect of the First_Node call here.
2779 if Present (Expr) then
2780 Eloc := Sloc (First_Node (Expr));
2783 -- Check restriction No_Implementation_Aspect_Specifications
2785 if Implementation_Defined_Aspect (A_Id) then
2787 (No_Implementation_Aspect_Specifications, Aspect);
2790 -- Check restriction No_Specification_Of_Aspect
2792 Check_Restriction_No_Specification_Of_Aspect (Aspect);
2794 -- Mark aspect analyzed (actual analysis is delayed till later)
2796 Set_Analyzed (Aspect);
2797 Set_Entity (Aspect, E);
2799 -- Build the reference to E that will be used in the built pragmas
2801 Ent := New_Occurrence_Of (E, Sloc (Id));
2803 if A_Id = Aspect_Attach_Handler
2804 or else A_Id = Aspect_Interrupt_Handler
2807 -- Treat the specification as a reference to the protected
2808 -- operation, which might otherwise appear unreferenced and
2809 -- generate spurious warnings.
2811 Generate_Reference (E, Id);
2814 -- Check for duplicate aspect. Note that the Comes_From_Source
2815 -- test allows duplicate Pre/Post's that we generate internally
2816 -- to escape being flagged here.
2818 if No_Duplicates_Allowed (A_Id) then
2820 while Anod /= Aspect loop
2821 if Comes_From_Source (Aspect)
2822 and then Same_Aspect (A_Id, Get_Aspect_Id (Anod))
2824 Error_Msg_Name_1 := Nam;
2825 Error_Msg_Sloc := Sloc (Anod);
2827 -- Case of same aspect specified twice
2829 if Class_Present (Anod) = Class_Present (Aspect) then
2830 if not Class_Present (Anod) then
2832 ("aspect% for & previously given#",
2836 ("aspect `%''Class` for & previously given#",
2846 -- Check some general restrictions on language defined aspects
2848 if not Implementation_Defined_Aspect (A_Id)
2849 or else A_Id = Aspect_Async_Readers
2850 or else A_Id = Aspect_Async_Writers
2851 or else A_Id = Aspect_Effective_Reads
2852 or else A_Id = Aspect_Effective_Reads
2854 Error_Msg_Name_1 := Nam;
2856 -- Not allowed for renaming declarations. Examine the original
2857 -- node because a subprogram renaming may have been rewritten
2860 if Nkind (Original_Node (N)) in N_Renaming_Declaration then
2862 ("aspect % not allowed for renaming declaration",
2866 -- Not allowed for formal type declarations in previous
2867 -- versions of the language. Allowed for them only for
2868 -- shared variable control aspects.
2870 if Nkind (N) = N_Formal_Type_Declaration then
2871 if Ada_Version < Ada_2020 then
2873 ("aspect % not allowed for formal type declaration",
2876 elsif A_Id /= Aspect_Atomic
2877 and then A_Id /= Aspect_Volatile
2878 and then A_Id /= Aspect_Independent
2879 and then A_Id /= Aspect_Atomic_Components
2880 and then A_Id /= Aspect_Independent_Components
2881 and then A_Id /= Aspect_Volatile_Components
2882 and then A_Id /= Aspect_Async_Readers
2883 and then A_Id /= Aspect_Async_Writers
2884 and then A_Id /= Aspect_Effective_Reads
2885 and then A_Id /= Aspect_Effective_Reads
2888 ("aspect % not allowed for formal type declaration",
2894 -- Copy expression for later processing by the procedures
2895 -- Check_Aspect_At_[Freeze_Point | End_Of_Declarations]
2897 Set_Entity (Id, New_Copy_Tree (Expr));
2899 -- Set Delay_Required as appropriate to aspect
2901 case Aspect_Delay (A_Id) is
2902 when Always_Delay =>
2903 -- For Boolean aspects, do not delay if no expression
2905 if A_Id in Boolean_Aspects | Library_Unit_Aspects then
2906 Delay_Required := Present (Expr);
2908 Delay_Required := True;
2912 Delay_Required := False;
2916 -- For Boolean aspects, do not delay if no expression except
2917 -- for Full_Access_Only because we need to process it after
2918 -- Volatile and Atomic, which can be independently delayed.
2920 if A_Id in Boolean_Aspects
2921 and then A_Id /= Aspect_Full_Access_Only
2924 Delay_Required := False;
2926 -- For non-Boolean aspects, if the expression has the form
2927 -- of an integer literal, then do not delay, since we know
2928 -- the value cannot change. This optimization catches most
2929 -- rep clause cases.
2931 elsif A_Id not in Boolean_Aspects
2932 and then Present (Expr)
2933 and then Nkind (Expr) = N_Integer_Literal
2935 Delay_Required := False;
2937 -- For Alignment and various Size aspects, do not delay for
2938 -- an attribute reference whose prefix is Standard, for
2939 -- example Standard'Maximum_Alignment or Standard'Word_Size.
2941 elsif (A_Id = Aspect_Alignment
2942 or else A_Id = Aspect_Component_Size
2943 or else A_Id = Aspect_Object_Size
2944 or else A_Id = Aspect_Size
2945 or else A_Id = Aspect_Value_Size)
2946 and then Present (Expr)
2947 and then Nkind (Expr) = N_Attribute_Reference
2948 and then Nkind (Prefix (Expr)) = N_Identifier
2949 and then Chars (Prefix (Expr)) = Name_Standard
2951 Delay_Required := False;
2953 -- All other cases are delayed
2956 Delay_Required := True;
2957 Set_Has_Delayed_Rep_Aspects (E);
2961 -- Check 13.1(9.2/5): A representation aspect of a subtype or type
2962 -- shall not be specified (whether by a representation item or an
2963 -- aspect_specification) before the type is completely defined
2966 if Is_Representation_Aspect (A_Id)
2967 and then Rep_Item_Too_Early (E, N)
2972 -- Processing based on specific aspect
2975 when Aspect_Unimplemented =>
2976 null; -- ??? temp for now
2978 -- No_Aspect should be impossible
2981 raise Program_Error;
2983 -- Case 1: Aspects corresponding to attribute definition
2989 | Aspect_Component_Size
2990 | Aspect_Constant_Indexing
2991 | Aspect_Default_Iterator
2992 | Aspect_Dispatching_Domain
2993 | Aspect_External_Tag
2996 | Aspect_Iterator_Element
2997 | Aspect_Machine_Radix
2998 | Aspect_Object_Size
3002 | Aspect_Scalar_Storage_Order
3003 | Aspect_Simple_Storage_Pool
3006 | Aspect_Storage_Pool
3007 | Aspect_Stream_Size
3009 | Aspect_Variable_Indexing
3012 -- Indexing aspects apply only to tagged type
3014 if (A_Id = Aspect_Constant_Indexing
3016 A_Id = Aspect_Variable_Indexing)
3017 and then not (Is_Type (E)
3018 and then Is_Tagged_Type (E))
3021 ("indexing aspect can only apply to a tagged type",
3026 -- For the case of aspect Address, we don't consider that we
3027 -- know the entity is never set in the source, since it is
3028 -- is likely aliasing is occurring.
3030 -- Note: one might think that the analysis of the resulting
3031 -- attribute definition clause would take care of that, but
3032 -- that's not the case since it won't be from source.
3034 if A_Id = Aspect_Address then
3035 Set_Never_Set_In_Source (E, False);
3038 -- Correctness of the profile of a stream operation is
3039 -- verified at the freeze point, but we must detect the
3040 -- illegal specification of this aspect for a subtype now,
3041 -- to prevent malformed rep_item chains.
3043 if A_Id = Aspect_Input or else
3044 A_Id = Aspect_Output or else
3045 A_Id = Aspect_Read or else
3048 if not Is_First_Subtype (E) then
3050 ("local name must be a first subtype", Aspect);
3053 -- If stream aspect applies to the class-wide type,
3054 -- the generated attribute definition applies to the
3055 -- class-wide type as well.
3057 elsif Class_Present (Aspect) then
3059 Make_Attribute_Reference (Loc,
3061 Attribute_Name => Name_Class);
3065 -- Construct the attribute_definition_clause. The expression
3066 -- in the aspect specification is simply shared with the
3067 -- constructed attribute, because it will be fully analyzed
3068 -- when the attribute is processed.
3071 Make_Attribute_Definition_Clause (Loc,
3073 Chars => Chars (Id),
3074 Expression => Relocate_Node (Expr));
3076 -- If the address is specified, then we treat the entity as
3077 -- referenced, to avoid spurious warnings. This is analogous
3078 -- to what is done with an attribute definition clause, but
3079 -- here we don't want to generate a reference because this
3080 -- is the point of definition of the entity.
3082 if A_Id = Aspect_Address then
3086 -- Case 2: Aspects corresponding to pragmas
3088 -- Case 2a: Aspects corresponding to pragmas with two
3089 -- arguments, where the first argument is a local name
3090 -- referring to the entity, and the second argument is the
3091 -- aspect definition expression.
3095 when Aspect_Linker_Section =>
3096 Aitem := Make_Aitem_Pragma
3097 (Pragma_Argument_Associations => New_List (
3098 Make_Pragma_Argument_Association (Loc,
3099 Expression => New_Occurrence_Of (E, Loc)),
3100 Make_Pragma_Argument_Association (Sloc (Expr),
3101 Expression => Relocate_Node (Expr))),
3102 Pragma_Name => Chars (Id));
3104 -- Linker_Section does not need delaying, as its argument
3105 -- must be a static string. Furthermore, if applied to
3106 -- an object with an explicit initialization, the object
3107 -- must be frozen in order to elaborate the initialization
3108 -- code. (This is already done for types with implicit
3109 -- initialization, such as protected types.)
3111 if Nkind (N) = N_Object_Declaration
3112 and then Has_Init_Expression (N)
3114 Delay_Required := False;
3119 -- Corresponds to pragma Implemented, construct the pragma
3121 when Aspect_Synchronization =>
3122 Aitem := Make_Aitem_Pragma
3123 (Pragma_Argument_Associations => New_List (
3124 Make_Pragma_Argument_Association (Loc,
3125 Expression => New_Occurrence_Of (E, Loc)),
3126 Make_Pragma_Argument_Association (Sloc (Expr),
3127 Expression => Relocate_Node (Expr))),
3128 Pragma_Name => Name_Implemented);
3132 when Aspect_Attach_Handler =>
3133 Aitem := Make_Aitem_Pragma
3134 (Pragma_Argument_Associations => New_List (
3135 Make_Pragma_Argument_Association (Sloc (Ent),
3137 Make_Pragma_Argument_Association (Sloc (Expr),
3138 Expression => Relocate_Node (Expr))),
3139 Pragma_Name => Name_Attach_Handler);
3141 -- We need to insert this pragma into the tree to get proper
3142 -- processing and to look valid from a placement viewpoint.
3144 Insert_Pragma (Aitem);
3147 -- Dynamic_Predicate, Predicate, Static_Predicate
3149 when Aspect_Dynamic_Predicate
3151 | Aspect_Static_Predicate
3153 -- These aspects apply only to subtypes
3155 if not Is_Type (E) then
3157 ("predicate can only be specified for a subtype",
3161 elsif Is_Incomplete_Type (E) then
3163 ("predicate cannot apply to incomplete view", Aspect);
3165 elsif Is_Generic_Type (E) then
3167 ("predicate cannot apply to formal type", Aspect);
3171 -- Construct the pragma (always a pragma Predicate, with
3172 -- flags recording whether it is static/dynamic). We also
3173 -- set flags recording this in the type itself.
3175 Aitem := Make_Aitem_Pragma
3176 (Pragma_Argument_Associations => New_List (
3177 Make_Pragma_Argument_Association (Sloc (Ent),
3179 Make_Pragma_Argument_Association (Sloc (Expr),
3180 Expression => Relocate_Node (Expr))),
3181 Pragma_Name => Name_Predicate);
3183 -- Mark type has predicates, and remember what kind of
3184 -- aspect lead to this predicate (we need this to access
3185 -- the right set of check policies later on).
3187 Set_Has_Predicates (E);
3189 if A_Id = Aspect_Dynamic_Predicate then
3190 Set_Has_Dynamic_Predicate_Aspect (E);
3192 -- If the entity has a dynamic predicate, any inherited
3193 -- static predicate becomes dynamic as well, and the
3194 -- predicate function includes the conjunction of both.
3196 Set_Has_Static_Predicate_Aspect (E, False);
3198 elsif A_Id = Aspect_Static_Predicate then
3199 Set_Has_Static_Predicate_Aspect (E);
3202 -- If the type is private, indicate that its completion
3203 -- has a freeze node, because that is the one that will
3204 -- be visible at freeze time.
3206 if Is_Private_Type (E) and then Present (Full_View (E)) then
3207 Set_Has_Predicates (Full_View (E));
3209 if A_Id = Aspect_Dynamic_Predicate then
3210 Set_Has_Dynamic_Predicate_Aspect (Full_View (E));
3211 elsif A_Id = Aspect_Static_Predicate then
3212 Set_Has_Static_Predicate_Aspect (Full_View (E));
3215 Set_Has_Delayed_Aspects (Full_View (E));
3216 Ensure_Freeze_Node (Full_View (E));
3218 -- If there is an Underlying_Full_View, also create a
3219 -- freeze node for that one.
3221 if Is_Private_Type (Full_View (E)) then
3223 U_Full : constant Entity_Id :=
3224 Underlying_Full_View (Full_View (E));
3226 if Present (U_Full) then
3227 Set_Has_Delayed_Aspects (U_Full);
3228 Ensure_Freeze_Node (U_Full);
3234 -- Predicate_Failure
3236 when Aspect_Predicate_Failure =>
3238 -- This aspect applies only to subtypes
3240 if not Is_Type (E) then
3242 ("predicate can only be specified for a subtype",
3246 elsif Is_Incomplete_Type (E) then
3248 ("predicate cannot apply to incomplete view", Aspect);
3251 elsif not Has_Predicates (E) then
3253 ("Predicate_Failure requires previous predicate" &
3254 " specification", Aspect);
3258 -- Construct the pragma
3260 Aitem := Make_Aitem_Pragma
3261 (Pragma_Argument_Associations => New_List (
3262 Make_Pragma_Argument_Association (Sloc (Ent),
3264 Make_Pragma_Argument_Association (Sloc (Expr),
3265 Expression => Relocate_Node (Expr))),
3266 Pragma_Name => Name_Predicate_Failure);
3268 -- Case 2b: Aspects corresponding to pragmas with two
3269 -- arguments, where the second argument is a local name
3270 -- referring to the entity, and the first argument is the
3271 -- aspect definition expression.
3275 when Aspect_Convention =>
3276 Analyze_Aspect_Convention;
3279 -- External_Name, Link_Name
3281 when Aspect_External_Name
3284 Analyze_Aspect_External_Link_Name;
3287 -- CPU, Interrupt_Priority, Priority
3289 -- These three aspects can be specified for a subprogram spec
3290 -- or body, in which case we analyze the expression and export
3291 -- the value of the aspect.
3293 -- Previously, we generated an equivalent pragma for bodies
3294 -- (note that the specs cannot contain these pragmas). The
3295 -- pragma was inserted ahead of local declarations, rather than
3296 -- after the body. This leads to a certain duplication between
3297 -- the processing performed for the aspect and the pragma, but
3298 -- given the straightforward handling required it is simpler
3299 -- to duplicate than to translate the aspect in the spec into
3300 -- a pragma in the declarative part of the body.
3303 | Aspect_Interrupt_Priority
3306 if Nkind (N) in N_Subprogram_Body | N_Subprogram_Declaration
3308 -- Analyze the aspect expression
3310 Analyze_And_Resolve (Expr, Standard_Integer);
3312 -- Interrupt_Priority aspect not allowed for main
3313 -- subprograms. RM D.1 does not forbid this explicitly,
3314 -- but RM J.15.11(6/3) does not permit pragma
3315 -- Interrupt_Priority for subprograms.
3317 if A_Id = Aspect_Interrupt_Priority then
3319 ("Interrupt_Priority aspect cannot apply to "
3320 & "subprogram", Expr);
3322 -- The expression must be static
3324 elsif not Is_OK_Static_Expression (Expr) then
3325 Flag_Non_Static_Expr
3326 ("aspect requires static expression!", Expr);
3328 -- Check whether this is the main subprogram. Issue a
3329 -- warning only if it is obviously not a main program
3330 -- (when it has parameters or when the subprogram is
3331 -- within a package).
3333 elsif Present (Parameter_Specifications
3334 (Specification (N)))
3335 or else not Is_Compilation_Unit (Defining_Entity (N))
3337 -- See RM D.1(14/3) and D.16(12/3)
3340 ("aspect applied to subprogram other than the "
3341 & "main subprogram has no effect??", Expr);
3343 -- Otherwise check in range and export the value
3345 -- For the CPU aspect
3347 elsif A_Id = Aspect_CPU then
3348 if Is_In_Range (Expr, RTE (RE_CPU_Range)) then
3350 -- Value is correct so we export the value to make
3351 -- it available at execution time.
3354 (Main_Unit, UI_To_Int (Expr_Value (Expr)));
3358 ("main subprogram CPU is out of range", Expr);
3361 -- For the Priority aspect
3363 elsif A_Id = Aspect_Priority then
3364 if Is_In_Range (Expr, RTE (RE_Priority)) then
3366 -- Value is correct so we export the value to make
3367 -- it available at execution time.
3370 (Main_Unit, UI_To_Int (Expr_Value (Expr)));
3372 -- Ignore pragma if Relaxed_RM_Semantics to support
3373 -- other targets/non GNAT compilers.
3375 elsif not Relaxed_RM_Semantics then
3377 ("main subprogram priority is out of range",
3382 -- Load an arbitrary entity from System.Tasking.Stages
3383 -- or System.Tasking.Restricted.Stages (depending on
3384 -- the supported profile) to make sure that one of these
3385 -- packages is implicitly with'ed, since we need to have
3386 -- the tasking run time active for the pragma Priority to
3387 -- have any effect. Previously we with'ed the package
3388 -- System.Tasking, but this package does not trigger the
3389 -- required initialization of the run-time library.
3392 Discard : Entity_Id;
3394 if Restricted_Profile then
3395 Discard := RTE (RE_Activate_Restricted_Tasks);
3397 Discard := RTE (RE_Activate_Tasks);
3401 -- Handling for these aspects in subprograms is complete
3405 -- For task and protected types pass the aspect as an
3410 Make_Attribute_Definition_Clause (Loc,
3412 Chars => Chars (Id),
3413 Expression => Relocate_Node (Expr));
3416 -- Suppress/Unsuppress
3418 when Aspect_Suppress
3421 Aitem := Make_Aitem_Pragma
3422 (Pragma_Argument_Associations => New_List (
3423 Make_Pragma_Argument_Association (Loc,
3424 Expression => Relocate_Node (Expr)),
3425 Make_Pragma_Argument_Association (Sloc (Expr),
3426 Expression => New_Occurrence_Of (E, Loc))),
3427 Pragma_Name => Chars (Id));
3429 Delay_Required := False;
3433 when Aspect_Warnings =>
3434 Aitem := Make_Aitem_Pragma
3435 (Pragma_Argument_Associations => New_List (
3436 Make_Pragma_Argument_Association (Sloc (Expr),
3437 Expression => Relocate_Node (Expr)),
3438 Make_Pragma_Argument_Association (Loc,
3439 Expression => New_Occurrence_Of (E, Loc))),
3440 Pragma_Name => Chars (Id));
3442 Decorate (Aspect, Aitem);
3443 Insert_Pragma (Aitem);
3446 -- Case 2c: Aspects corresponding to pragmas with three
3449 -- Invariant aspects have a first argument that references the
3450 -- entity, a second argument that is the expression and a third
3451 -- argument that is an appropriate message.
3453 -- Invariant, Type_Invariant
3455 when Aspect_Invariant
3456 | Aspect_Type_Invariant
3458 -- Analysis of the pragma will verify placement legality:
3459 -- an invariant must apply to a private type, or appear in
3460 -- the private part of a spec and apply to a completion.
3462 Aitem := Make_Aitem_Pragma
3463 (Pragma_Argument_Associations => New_List (
3464 Make_Pragma_Argument_Association (Sloc (Ent),
3466 Make_Pragma_Argument_Association (Sloc (Expr),
3467 Expression => Relocate_Node (Expr))),
3468 Pragma_Name => Name_Invariant);
3470 -- Add message unless exception messages are suppressed
3472 if not Opt.Exception_Locations_Suppressed then
3473 Append_To (Pragma_Argument_Associations (Aitem),
3474 Make_Pragma_Argument_Association (Eloc,
3475 Chars => Name_Message,
3477 Make_String_Literal (Eloc,
3478 Strval => "failed invariant from "
3479 & Build_Location_String (Eloc))));
3482 -- For Invariant case, insert immediately after the entity
3483 -- declaration. We do not have to worry about delay issues
3484 -- since the pragma processing takes care of this.
3486 Delay_Required := False;
3488 -- Case 2d : Aspects that correspond to a pragma with one
3493 -- Aspect Abstract_State introduces implicit declarations for
3494 -- all state abstraction entities it defines. To emulate this
3495 -- behavior, insert the pragma at the beginning of the visible
3496 -- declarations of the related package so that it is analyzed
3499 when Aspect_Abstract_State => Abstract_State : declare
3500 Context : Node_Id := N;
3503 -- When aspect Abstract_State appears on a generic package,
3504 -- it is propageted to the package instance. The context in
3505 -- this case is the instance spec.
3507 if Nkind (Context) = N_Package_Instantiation then
3508 Context := Instance_Spec (Context);
3511 if Nkind (Context) in N_Generic_Package_Declaration
3512 | N_Package_Declaration
3514 Aitem := Make_Aitem_Pragma
3515 (Pragma_Argument_Associations => New_List (
3516 Make_Pragma_Argument_Association (Loc,
3517 Expression => Relocate_Node (Expr))),
3518 Pragma_Name => Name_Abstract_State);
3520 Decorate (Aspect, Aitem);
3524 Is_Generic_Instance (Defining_Entity (Context)));
3528 ("aspect & must apply to a package declaration",
3535 -- Aspect Async_Readers is never delayed because it is
3536 -- equivalent to a source pragma which appears after the
3537 -- related object declaration.
3539 when Aspect_Async_Readers =>
3540 Aitem := Make_Aitem_Pragma
3541 (Pragma_Argument_Associations => New_List (
3542 Make_Pragma_Argument_Association (Loc,
3543 Expression => Relocate_Node (Expr))),
3544 Pragma_Name => Name_Async_Readers);
3546 Decorate (Aspect, Aitem);
3547 Insert_Pragma (Aitem);
3550 -- Aspect Async_Writers is never delayed because it is
3551 -- equivalent to a source pragma which appears after the
3552 -- related object declaration.
3554 when Aspect_Async_Writers =>
3555 Aitem := Make_Aitem_Pragma
3556 (Pragma_Argument_Associations => New_List (
3557 Make_Pragma_Argument_Association (Loc,
3558 Expression => Relocate_Node (Expr))),
3559 Pragma_Name => Name_Async_Writers);
3561 Decorate (Aspect, Aitem);
3562 Insert_Pragma (Aitem);
3565 -- Aspect Constant_After_Elaboration is never delayed because
3566 -- it is equivalent to a source pragma which appears after the
3567 -- related object declaration.
3569 when Aspect_Constant_After_Elaboration =>
3570 Aitem := Make_Aitem_Pragma
3571 (Pragma_Argument_Associations => New_List (
3572 Make_Pragma_Argument_Association (Loc,
3573 Expression => Relocate_Node (Expr))),
3575 Name_Constant_After_Elaboration);
3577 Decorate (Aspect, Aitem);
3578 Insert_Pragma (Aitem);
3581 -- Aspect Default_Internal_Condition is never delayed because
3582 -- it is equivalent to a source pragma which appears after the
3583 -- related private type. To deal with forward references, the
3584 -- generated pragma is stored in the rep chain of the related
3585 -- private type as types do not carry contracts. The pragma is
3586 -- wrapped inside of a procedure at the freeze point of the
3587 -- private type's full view.
3589 when Aspect_Default_Initial_Condition =>
3590 Aitem := Make_Aitem_Pragma
3591 (Pragma_Argument_Associations => New_List (
3592 Make_Pragma_Argument_Association (Loc,
3593 Expression => Relocate_Node (Expr))),
3595 Name_Default_Initial_Condition);
3597 Decorate (Aspect, Aitem);
3598 Insert_Pragma (Aitem);
3601 -- Default_Storage_Pool
3603 when Aspect_Default_Storage_Pool =>
3604 Aitem := Make_Aitem_Pragma
3605 (Pragma_Argument_Associations => New_List (
3606 Make_Pragma_Argument_Association (Loc,
3607 Expression => Relocate_Node (Expr))),
3609 Name_Default_Storage_Pool);
3611 Decorate (Aspect, Aitem);
3612 Insert_Pragma (Aitem);
3617 -- Aspect Depends is never delayed because it is equivalent to
3618 -- a source pragma which appears after the related subprogram.
3619 -- To deal with forward references, the generated pragma is
3620 -- stored in the contract of the related subprogram and later
3621 -- analyzed at the end of the declarative region. See routine
3622 -- Analyze_Depends_In_Decl_Part for details.
3624 when Aspect_Depends =>
3625 Aitem := Make_Aitem_Pragma
3626 (Pragma_Argument_Associations => New_List (
3627 Make_Pragma_Argument_Association (Loc,
3628 Expression => Relocate_Node (Expr))),
3629 Pragma_Name => Name_Depends);
3631 Decorate (Aspect, Aitem);
3632 Insert_Pragma (Aitem);
3635 -- Aspect Effective_Reads is never delayed because it is
3636 -- equivalent to a source pragma which appears after the
3637 -- related object declaration.
3639 when Aspect_Effective_Reads =>
3640 Aitem := Make_Aitem_Pragma
3641 (Pragma_Argument_Associations => New_List (
3642 Make_Pragma_Argument_Association (Loc,
3643 Expression => Relocate_Node (Expr))),
3644 Pragma_Name => Name_Effective_Reads);
3646 Decorate (Aspect, Aitem);
3647 Insert_Pragma (Aitem);
3650 -- Aspect Effective_Writes is never delayed because it is
3651 -- equivalent to a source pragma which appears after the
3652 -- related object declaration.
3654 when Aspect_Effective_Writes =>
3655 Aitem := Make_Aitem_Pragma
3656 (Pragma_Argument_Associations => New_List (
3657 Make_Pragma_Argument_Association (Loc,
3658 Expression => Relocate_Node (Expr))),
3659 Pragma_Name => Name_Effective_Writes);
3661 Decorate (Aspect, Aitem);
3662 Insert_Pragma (Aitem);
3665 -- Aspect Extensions_Visible is never delayed because it is
3666 -- equivalent to a source pragma which appears after the
3667 -- related subprogram.
3669 when Aspect_Extensions_Visible =>
3670 Aitem := Make_Aitem_Pragma
3671 (Pragma_Argument_Associations => New_List (
3672 Make_Pragma_Argument_Association (Loc,
3673 Expression => Relocate_Node (Expr))),
3674 Pragma_Name => Name_Extensions_Visible);
3676 Decorate (Aspect, Aitem);
3677 Insert_Pragma (Aitem);
3680 -- Aspect Ghost is never delayed because it is equivalent to a
3681 -- source pragma which appears at the top of [generic] package
3682 -- declarations or after an object, a [generic] subprogram, or
3683 -- a type declaration.
3685 when Aspect_Ghost =>
3686 Aitem := Make_Aitem_Pragma
3687 (Pragma_Argument_Associations => New_List (
3688 Make_Pragma_Argument_Association (Loc,
3689 Expression => Relocate_Node (Expr))),
3690 Pragma_Name => Name_Ghost);
3692 Decorate (Aspect, Aitem);
3693 Insert_Pragma (Aitem);
3698 -- Aspect Global is never delayed because it is equivalent to
3699 -- a source pragma which appears after the related subprogram.
3700 -- To deal with forward references, the generated pragma is
3701 -- stored in the contract of the related subprogram and later
3702 -- analyzed at the end of the declarative region. See routine
3703 -- Analyze_Global_In_Decl_Part for details.
3705 when Aspect_Global =>
3706 Aitem := Make_Aitem_Pragma
3707 (Pragma_Argument_Associations => New_List (
3708 Make_Pragma_Argument_Association (Loc,
3709 Expression => Relocate_Node (Expr))),
3710 Pragma_Name => Name_Global);
3712 Decorate (Aspect, Aitem);
3713 Insert_Pragma (Aitem);
3716 -- Initial_Condition
3718 -- Aspect Initial_Condition is never delayed because it is
3719 -- equivalent to a source pragma which appears after the
3720 -- related package. To deal with forward references, the
3721 -- generated pragma is stored in the contract of the related
3722 -- package and later analyzed at the end of the declarative
3723 -- region. See routine Analyze_Initial_Condition_In_Decl_Part
3726 when Aspect_Initial_Condition => Initial_Condition : declare
3727 Context : Node_Id := N;
3730 -- When aspect Initial_Condition appears on a generic
3731 -- package, it is propageted to the package instance. The
3732 -- context in this case is the instance spec.
3734 if Nkind (Context) = N_Package_Instantiation then
3735 Context := Instance_Spec (Context);
3738 if Nkind (Context) in N_Generic_Package_Declaration
3739 | N_Package_Declaration
3741 Aitem := Make_Aitem_Pragma
3742 (Pragma_Argument_Associations => New_List (
3743 Make_Pragma_Argument_Association (Loc,
3744 Expression => Relocate_Node (Expr))),
3746 Name_Initial_Condition);
3748 Decorate (Aspect, Aitem);
3752 Is_Generic_Instance (Defining_Entity (Context)));
3754 -- Otherwise the context is illegal
3758 ("aspect & must apply to a package declaration",
3763 end Initial_Condition;
3767 -- Aspect Initializes is never delayed because it is equivalent
3768 -- to a source pragma appearing after the related package. To
3769 -- deal with forward references, the generated pragma is stored
3770 -- in the contract of the related package and later analyzed at
3771 -- the end of the declarative region. For details, see routine
3772 -- Analyze_Initializes_In_Decl_Part.
3774 when Aspect_Initializes => Initializes : declare
3775 Context : Node_Id := N;
3778 -- When aspect Initializes appears on a generic package,
3779 -- it is propageted to the package instance. The context
3780 -- in this case is the instance spec.
3782 if Nkind (Context) = N_Package_Instantiation then
3783 Context := Instance_Spec (Context);
3786 if Nkind (Context) in N_Generic_Package_Declaration
3787 | N_Package_Declaration
3789 Aitem := Make_Aitem_Pragma
3790 (Pragma_Argument_Associations => New_List (
3791 Make_Pragma_Argument_Association (Loc,
3792 Expression => Relocate_Node (Expr))),
3793 Pragma_Name => Name_Initializes);
3795 Decorate (Aspect, Aitem);
3799 Is_Generic_Instance (Defining_Entity (Context)));
3801 -- Otherwise the context is illegal
3805 ("aspect & must apply to a package declaration",
3812 -- Max_Entry_Queue_Depth
3814 when Aspect_Max_Entry_Queue_Depth =>
3815 Aitem := Make_Aitem_Pragma
3816 (Pragma_Argument_Associations => New_List (
3817 Make_Pragma_Argument_Association (Loc,
3818 Expression => Relocate_Node (Expr))),
3819 Pragma_Name => Name_Max_Entry_Queue_Depth);
3821 Decorate (Aspect, Aitem);
3822 Insert_Pragma (Aitem);
3825 -- Max_Entry_Queue_Length
3827 when Aspect_Max_Entry_Queue_Length =>
3828 Aitem := Make_Aitem_Pragma
3829 (Pragma_Argument_Associations => New_List (
3830 Make_Pragma_Argument_Association (Loc,
3831 Expression => Relocate_Node (Expr))),
3832 Pragma_Name => Name_Max_Entry_Queue_Length);
3834 Decorate (Aspect, Aitem);
3835 Insert_Pragma (Aitem);
3840 when Aspect_Max_Queue_Length =>
3841 Aitem := Make_Aitem_Pragma
3842 (Pragma_Argument_Associations => New_List (
3843 Make_Pragma_Argument_Association (Loc,
3844 Expression => Relocate_Node (Expr))),
3845 Pragma_Name => Name_Max_Queue_Length);
3847 Decorate (Aspect, Aitem);
3848 Insert_Pragma (Aitem);
3851 -- Aspect No_Caching is never delayed because it is equivalent
3852 -- to a source pragma which appears after the related object
3855 when Aspect_No_Caching =>
3856 Aitem := Make_Aitem_Pragma
3857 (Pragma_Argument_Associations => New_List (
3858 Make_Pragma_Argument_Association (Loc,
3859 Expression => Relocate_Node (Expr))),
3860 Pragma_Name => Name_No_Caching);
3862 Decorate (Aspect, Aitem);
3863 Insert_Pragma (Aitem);
3868 when Aspect_Obsolescent => declare
3876 Make_Pragma_Argument_Association (Sloc (Expr),
3877 Expression => Relocate_Node (Expr)));
3880 Aitem := Make_Aitem_Pragma
3881 (Pragma_Argument_Associations => Args,
3882 Pragma_Name => Chars (Id));
3887 when Aspect_Part_Of =>
3888 if Nkind (N) in N_Object_Declaration
3889 | N_Package_Instantiation
3890 or else Is_Single_Concurrent_Type_Declaration (N)
3892 Aitem := Make_Aitem_Pragma
3893 (Pragma_Argument_Associations => New_List (
3894 Make_Pragma_Argument_Association (Loc,
3895 Expression => Relocate_Node (Expr))),
3896 Pragma_Name => Name_Part_Of);
3898 Decorate (Aspect, Aitem);
3899 Insert_Pragma (Aitem);
3903 ("aspect & must apply to package instantiation, "
3904 & "object, single protected type or single task type",
3912 when Aspect_SPARK_Mode =>
3913 Aitem := Make_Aitem_Pragma
3914 (Pragma_Argument_Associations => New_List (
3915 Make_Pragma_Argument_Association (Loc,
3916 Expression => Relocate_Node (Expr))),
3917 Pragma_Name => Name_SPARK_Mode);
3919 Decorate (Aspect, Aitem);
3920 Insert_Pragma (Aitem);
3925 -- Aspect Refined_Depends is never delayed because it is
3926 -- equivalent to a source pragma which appears in the
3927 -- declarations of the related subprogram body. To deal with
3928 -- forward references, the generated pragma is stored in the
3929 -- contract of the related subprogram body and later analyzed
3930 -- at the end of the declarative region. For details, see
3931 -- routine Analyze_Refined_Depends_In_Decl_Part.
3933 when Aspect_Refined_Depends =>
3934 Aitem := Make_Aitem_Pragma
3935 (Pragma_Argument_Associations => New_List (
3936 Make_Pragma_Argument_Association (Loc,
3937 Expression => Relocate_Node (Expr))),
3938 Pragma_Name => Name_Refined_Depends);
3940 Decorate (Aspect, Aitem);
3941 Insert_Pragma (Aitem);
3946 -- Aspect Refined_Global is never delayed because it is
3947 -- equivalent to a source pragma which appears in the
3948 -- declarations of the related subprogram body. To deal with
3949 -- forward references, the generated pragma is stored in the
3950 -- contract of the related subprogram body and later analyzed
3951 -- at the end of the declarative region. For details, see
3952 -- routine Analyze_Refined_Global_In_Decl_Part.
3954 when Aspect_Refined_Global =>
3955 Aitem := Make_Aitem_Pragma
3956 (Pragma_Argument_Associations => New_List (
3957 Make_Pragma_Argument_Association (Loc,
3958 Expression => Relocate_Node (Expr))),
3959 Pragma_Name => Name_Refined_Global);
3961 Decorate (Aspect, Aitem);
3962 Insert_Pragma (Aitem);
3967 when Aspect_Refined_Post =>
3968 Aitem := Make_Aitem_Pragma
3969 (Pragma_Argument_Associations => New_List (
3970 Make_Pragma_Argument_Association (Loc,
3971 Expression => Relocate_Node (Expr))),
3972 Pragma_Name => Name_Refined_Post);
3974 Decorate (Aspect, Aitem);
3975 Insert_Pragma (Aitem);
3980 when Aspect_Refined_State =>
3982 -- The corresponding pragma for Refined_State is inserted in
3983 -- the declarations of the related package body. This action
3984 -- synchronizes both the source and from-aspect versions of
3987 if Nkind (N) = N_Package_Body then
3988 Aitem := Make_Aitem_Pragma
3989 (Pragma_Argument_Associations => New_List (
3990 Make_Pragma_Argument_Association (Loc,
3991 Expression => Relocate_Node (Expr))),
3992 Pragma_Name => Name_Refined_State);
3994 Decorate (Aspect, Aitem);
3995 Insert_Pragma (Aitem);
3997 -- Otherwise the context is illegal
4001 ("aspect & must apply to a package body", Aspect, Id);
4006 -- Relative_Deadline
4008 when Aspect_Relative_Deadline =>
4009 Aitem := Make_Aitem_Pragma
4010 (Pragma_Argument_Associations => New_List (
4011 Make_Pragma_Argument_Association (Loc,
4012 Expression => Relocate_Node (Expr))),
4013 Pragma_Name => Name_Relative_Deadline);
4015 -- If the aspect applies to a task, the corresponding pragma
4016 -- must appear within its declarations, not after.
4018 if Nkind (N) = N_Task_Type_Declaration then
4024 if No (Task_Definition (N)) then
4025 Set_Task_Definition (N,
4026 Make_Task_Definition (Loc,
4027 Visible_Declarations => New_List,
4028 End_Label => Empty));
4031 Def := Task_Definition (N);
4032 V := Visible_Declarations (Def);
4033 if not Is_Empty_List (V) then
4034 Insert_Before (First (V), Aitem);
4037 Set_Visible_Declarations (Def, New_List (Aitem));
4044 -- Relaxed_Initialization
4046 when Aspect_Relaxed_Initialization =>
4047 Analyze_Aspect_Relaxed_Initialization;
4050 -- Secondary_Stack_Size
4052 -- Aspect Secondary_Stack_Size needs to be converted into a
4053 -- pragma for two reasons: the attribute is not analyzed until
4054 -- after the expansion of the task type declaration and the
4055 -- attribute does not have visibility on the discriminant.
4057 when Aspect_Secondary_Stack_Size =>
4058 Aitem := Make_Aitem_Pragma
4059 (Pragma_Argument_Associations => New_List (
4060 Make_Pragma_Argument_Association (Loc,
4061 Expression => Relocate_Node (Expr))),
4063 Name_Secondary_Stack_Size);
4065 Decorate (Aspect, Aitem);
4066 Insert_Pragma (Aitem);
4069 -- Volatile_Function
4071 -- Aspect Volatile_Function is never delayed because it is
4072 -- equivalent to a source pragma which appears after the
4073 -- related subprogram.
4075 when Aspect_Volatile_Function =>
4076 Aitem := Make_Aitem_Pragma
4077 (Pragma_Argument_Associations => New_List (
4078 Make_Pragma_Argument_Association (Loc,
4079 Expression => Relocate_Node (Expr))),
4080 Pragma_Name => Name_Volatile_Function);
4082 Decorate (Aspect, Aitem);
4083 Insert_Pragma (Aitem);
4086 -- Case 2e: Annotate aspect
4088 when Aspect_Annotate =>
4095 -- The argument can be a single identifier
4097 if Nkind (Expr) = N_Identifier then
4099 -- One level of parens is allowed
4101 if Paren_Count (Expr) > 1 then
4102 Error_Msg_F ("extra parentheses ignored", Expr);
4105 Set_Paren_Count (Expr, 0);
4107 -- Add the single item to the list
4109 Args := New_List (Expr);
4111 -- Otherwise we must have an aggregate
4113 elsif Nkind (Expr) = N_Aggregate then
4115 -- Must be positional
4117 if Present (Component_Associations (Expr)) then
4119 ("purely positional aggregate required", Expr);
4123 -- Must not be parenthesized
4125 if Paren_Count (Expr) /= 0 then
4126 Error_Msg_F ("extra parentheses ignored", Expr);
4129 -- List of arguments is list of aggregate expressions
4131 Args := Expressions (Expr);
4133 -- Anything else is illegal
4136 Error_Msg_F ("wrong form for Annotate aspect", Expr);
4140 -- Prepare pragma arguments
4143 Arg := First (Args);
4144 while Present (Arg) loop
4146 Make_Pragma_Argument_Association (Sloc (Arg),
4147 Expression => Relocate_Node (Arg)));
4152 Make_Pragma_Argument_Association (Sloc (Ent),
4153 Chars => Name_Entity,
4154 Expression => Ent));
4156 Aitem := Make_Aitem_Pragma
4157 (Pragma_Argument_Associations => Pargs,
4158 Pragma_Name => Name_Annotate);
4161 -- Case 3 : Aspects that don't correspond to pragma/attribute
4162 -- definition clause.
4164 -- Case 3a: The aspects listed below don't correspond to
4165 -- pragmas/attributes but do require delayed analysis.
4167 when Aspect_Default_Value | Aspect_Default_Component_Value =>
4168 Error_Msg_Name_1 := Chars (Id);
4170 if not Is_Type (E) then
4171 Error_Msg_N ("aspect% can only apply to a type", Id);
4174 elsif not Is_First_Subtype (E) then
4175 Error_Msg_N ("aspect% cannot apply to subtype", Id);
4178 elsif A_Id = Aspect_Default_Value
4179 and then not Is_Scalar_Type (E)
4181 Error_Msg_N ("aspect% can only be applied to scalar type",
4185 elsif A_Id = Aspect_Default_Component_Value then
4186 if not Is_Array_Type (E) then
4187 Error_Msg_N ("aspect% can only be applied to array " &
4191 elsif not Is_Scalar_Type (Component_Type (E)) then
4192 Error_Msg_N ("aspect% requires scalar components", Id);
4199 when Aspect_Aggregate =>
4200 Validate_Aspect_Aggregate (Expr);
4201 Record_Rep_Item (E, Aspect);
4204 when Aspect_Integer_Literal
4205 | Aspect_Real_Literal
4206 | Aspect_String_Literal
4209 if not Is_First_Subtype (E) then
4211 ("may only be specified for a first subtype", Aspect);
4215 if Ada_Version < Ada_2020 then
4217 (No_Implementation_Aspect_Specifications, N);
4222 -- Case 3b: The aspects listed below don't correspond to
4223 -- pragmas/attributes and don't need delayed analysis.
4225 -- Implicit_Dereference
4227 -- For Implicit_Dereference, External_Name and Link_Name, only
4228 -- the legality checks are done during the analysis, thus no
4229 -- delay is required.
4231 when Aspect_Implicit_Dereference =>
4232 Analyze_Aspect_Implicit_Dereference;
4237 when Aspect_Dimension =>
4238 Analyze_Aspect_Dimension (N, Id, Expr);
4243 when Aspect_Dimension_System =>
4244 Analyze_Aspect_Dimension_System (N, Id, Expr);
4247 -- Case 4: Aspects requiring special handling
4249 -- Pre/Post/Test_Case/Contract_Cases/Subprogram_Variant whose
4250 -- corresponding pragmas take care of the delay.
4254 -- Aspects Pre/Post generate Precondition/Postcondition pragmas
4255 -- with a first argument that is the expression, and a second
4256 -- argument that is an informative message if the test fails.
4257 -- This is inserted right after the declaration, to get the
4258 -- required pragma placement. The processing for the pragmas
4259 -- takes care of the required delay.
4261 when Pre_Post_Aspects => Pre_Post : declare
4265 if A_Id = Aspect_Pre or else A_Id = Aspect_Precondition then
4266 Pname := Name_Precondition;
4268 Pname := Name_Postcondition;
4271 -- Check that the class-wide predicate cannot be applied to
4272 -- an operation of a synchronized type. AI12-0182 forbids
4273 -- these altogether, while earlier language semantics made
4274 -- them legal on tagged synchronized types.
4276 -- Other legality checks are performed when analyzing the
4277 -- contract of the operation.
4279 if Class_Present (Aspect)
4280 and then Is_Concurrent_Type (Current_Scope)
4281 and then Ekind (E) in E_Entry | E_Function | E_Procedure
4283 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (Aspect);
4285 ("aspect % can only be specified for a primitive "
4286 & "operation of a tagged type", Aspect);
4291 -- If the expressions is of the form A and then B, then
4292 -- we generate separate Pre/Post aspects for the separate
4293 -- clauses. Since we allow multiple pragmas, there is no
4294 -- problem in allowing multiple Pre/Post aspects internally.
4295 -- These should be treated in reverse order (B first and
4296 -- A second) since they are later inserted just after N in
4297 -- the order they are treated. This way, the pragma for A
4298 -- ends up preceding the pragma for B, which may have an
4299 -- importance for the error raised (either constraint error
4300 -- or precondition error).
4302 -- We do not do this for Pre'Class, since we have to put
4303 -- these conditions together in a complex OR expression.
4305 -- We don't do this in GNATprove mode, because it brings no
4306 -- benefit for proof and causes annoyance for flow analysis,
4307 -- which prefers to be as close to the original source code
4308 -- as possible. Also we don't do this when analyzing generic
4309 -- units since it causes spurious visibility errors in the
4310 -- preanalysis of instantiations.
4312 if not GNATprove_Mode
4313 and then (Pname = Name_Postcondition
4314 or else not Class_Present (Aspect))
4315 and then not Inside_A_Generic
4317 while Nkind (Expr) = N_And_Then loop
4318 Insert_After (Aspect,
4319 Make_Aspect_Specification (Sloc (Left_Opnd (Expr)),
4320 Identifier => Identifier (Aspect),
4321 Expression => Relocate_Node (Left_Opnd (Expr)),
4322 Class_Present => Class_Present (Aspect),
4323 Split_PPC => True));
4324 Rewrite (Expr, Relocate_Node (Right_Opnd (Expr)));
4325 Eloc := Sloc (Expr);
4329 -- Build the precondition/postcondition pragma
4331 -- We use Relocate_Node here rather than New_Copy_Tree
4332 -- because subsequent visibility analysis of the aspect
4333 -- depends on this sharing. This should be cleaned up???
4335 -- If the context is generic, we want to preserve the
4336 -- original tree, and simply share it between aspect and
4337 -- generated attribute. This parallels what is done in
4338 -- sem_prag.adb (see Get_Argument).
4344 if Inside_A_Generic then
4347 New_Expr := Relocate_Node (Expr);
4350 Aitem := Make_Aitem_Pragma
4351 (Pragma_Argument_Associations => New_List (
4352 Make_Pragma_Argument_Association (Eloc,
4353 Chars => Name_Check,
4354 Expression => New_Expr)),
4355 Pragma_Name => Pname);
4358 -- Add message unless exception messages are suppressed
4360 if not Opt.Exception_Locations_Suppressed then
4361 Append_To (Pragma_Argument_Associations (Aitem),
4362 Make_Pragma_Argument_Association (Eloc,
4363 Chars => Name_Message,
4365 Make_String_Literal (Eloc,
4367 & Get_Name_String (Pname)
4369 & Build_Location_String (Eloc))));
4372 Set_Is_Delayed_Aspect (Aspect);
4374 -- For Pre/Post cases, insert immediately after the entity
4375 -- declaration, since that is the required pragma placement.
4376 -- Note that for these aspects, we do not have to worry
4377 -- about delay issues, since the pragmas themselves deal
4378 -- with delay of visibility for the expression analysis.
4380 Insert_Pragma (Aitem);
4387 when Aspect_Test_Case => Test_Case : declare
4389 Comp_Expr : Node_Id;
4390 Comp_Assn : Node_Id;
4395 if Nkind (Parent (N)) = N_Compilation_Unit then
4396 Error_Msg_Name_1 := Nam;
4397 Error_Msg_N ("incorrect placement of aspect `%`", E);
4401 if Nkind (Expr) /= N_Aggregate then
4402 Error_Msg_Name_1 := Nam;
4404 ("wrong syntax for aspect `%` for &", Id, E);
4408 -- Create the list of arguments for building the Test_Case
4411 Comp_Expr := First (Expressions (Expr));
4412 while Present (Comp_Expr) loop
4414 Make_Pragma_Argument_Association (Sloc (Comp_Expr),
4415 Expression => Relocate_Node (Comp_Expr)));
4419 Comp_Assn := First (Component_Associations (Expr));
4420 while Present (Comp_Assn) loop
4421 if List_Length (Choices (Comp_Assn)) /= 1
4423 Nkind (First (Choices (Comp_Assn))) /= N_Identifier
4425 Error_Msg_Name_1 := Nam;
4427 ("wrong syntax for aspect `%` for &", Id, E);
4432 Make_Pragma_Argument_Association (Sloc (Comp_Assn),
4433 Chars => Chars (First (Choices (Comp_Assn))),
4435 Relocate_Node (Expression (Comp_Assn))));
4439 -- Build the test-case pragma
4441 Aitem := Make_Aitem_Pragma
4442 (Pragma_Argument_Associations => Args,
4443 Pragma_Name => Nam);
4448 when Aspect_Contract_Cases =>
4449 Aitem := Make_Aitem_Pragma
4450 (Pragma_Argument_Associations => New_List (
4451 Make_Pragma_Argument_Association (Loc,
4452 Expression => Relocate_Node (Expr))),
4453 Pragma_Name => Nam);
4455 Decorate (Aspect, Aitem);
4456 Insert_Pragma (Aitem);
4459 -- Subprogram_Variant
4461 when Aspect_Subprogram_Variant =>
4462 Aitem := Make_Aitem_Pragma
4463 (Pragma_Argument_Associations => New_List (
4464 Make_Pragma_Argument_Association (Loc,
4465 Expression => Relocate_Node (Expr))),
4466 Pragma_Name => Nam);
4468 Decorate (Aspect, Aitem);
4469 Insert_Pragma (Aitem);
4472 -- Case 5: Special handling for aspects with an optional
4473 -- boolean argument.
4475 -- In the delayed case, the corresponding pragma cannot be
4476 -- generated yet because the evaluation of the boolean needs
4477 -- to be delayed till the freeze point.
4479 when Boolean_Aspects
4480 | Library_Unit_Aspects
4482 Set_Is_Boolean_Aspect (Aspect);
4484 -- Lock_Free aspect only apply to protected objects
4486 if A_Id = Aspect_Lock_Free then
4487 if Ekind (E) /= E_Protected_Type then
4488 Error_Msg_Name_1 := Nam;
4490 ("aspect % only applies to a protected type " &
4495 -- Set the Uses_Lock_Free flag to True if there is no
4496 -- expression or if the expression is True. The
4497 -- evaluation of this aspect should be delayed to the
4498 -- freeze point if we wanted to handle the corner case
4499 -- of "true" or "false" being redefined.
4502 or else Is_True (Static_Boolean (Expr))
4504 Set_Uses_Lock_Free (E);
4507 Record_Rep_Item (E, Aspect);
4512 elsif A_Id = Aspect_Export or else A_Id = Aspect_Import then
4513 Analyze_Aspect_Export_Import;
4515 -- Disable_Controlled
4517 elsif A_Id = Aspect_Disable_Controlled then
4518 Analyze_Aspect_Disable_Controlled;
4521 -- Ada 202x (AI12-0129): Exclusive_Functions
4523 elsif A_Id = Aspect_Exclusive_Functions then
4524 if Ekind (E) /= E_Protected_Type then
4525 Error_Msg_Name_1 := Nam;
4527 ("aspect % only applies to a protected type " &
4534 -- Ada 202x (AI12-0363): Full_Access_Only
4536 elsif A_Id = Aspect_Full_Access_Only then
4537 if Ada_Version < Ada_2020 then
4539 ("aspect % is an Ada 202x feature", Aspect);
4540 Error_Msg_N ("\compile with -gnat2020", Aspect);
4543 -- Ada 202x (AI12-0075): static expression functions
4545 elsif A_Id = Aspect_Static then
4546 Analyze_Aspect_Static;
4549 -- Ada 2020 (AI12-0279)
4551 elsif A_Id = Aspect_Yield then
4552 Analyze_Aspect_Yield;
4556 -- Library unit aspects require special handling in the case
4557 -- of a package declaration, the pragma needs to be inserted
4558 -- in the list of declarations for the associated package.
4559 -- There is no issue of visibility delay for these aspects.
4561 if A_Id in Library_Unit_Aspects
4563 Nkind (N) in N_Package_Declaration
4564 | N_Generic_Package_Declaration
4565 and then Nkind (Parent (N)) /= N_Compilation_Unit
4567 -- Aspect is legal on a local instantiation of a library-
4568 -- level generic unit.
4570 and then not Is_Generic_Instance (Defining_Entity (N))
4573 ("incorrect context for library unit aspect&", Id);
4577 -- Cases where we do not delay
4579 if not Delay_Required then
4581 -- Exclude aspects Export and Import because their pragma
4582 -- syntax does not map directly to a Boolean aspect.
4584 if A_Id /= Aspect_Export
4585 and then A_Id /= Aspect_Import
4587 Aitem := Make_Aitem_Pragma
4588 (Pragma_Argument_Associations => New_List (
4589 Make_Pragma_Argument_Association (Sloc (Ent),
4590 Expression => Ent)),
4591 Pragma_Name => Chars (Id));
4594 -- In general cases, the corresponding pragma/attribute
4595 -- definition clause will be inserted later at the freezing
4596 -- point, and we do not need to build it now.
4604 -- This is special because for access types we need to generate
4605 -- an attribute definition clause. This also works for single
4606 -- task declarations, but it does not work for task type
4607 -- declarations, because we have the case where the expression
4608 -- references a discriminant of the task type. That can't use
4609 -- an attribute definition clause because we would not have
4610 -- visibility on the discriminant. For that case we must
4611 -- generate a pragma in the task definition.
4613 when Aspect_Storage_Size =>
4617 if Ekind (E) = E_Task_Type then
4619 Decl : constant Node_Id := Declaration_Node (E);
4622 pragma Assert (Nkind (Decl) = N_Task_Type_Declaration);
4624 -- If no task definition, create one
4626 if No (Task_Definition (Decl)) then
4627 Set_Task_Definition (Decl,
4628 Make_Task_Definition (Loc,
4629 Visible_Declarations => Empty_List,
4630 End_Label => Empty));
4633 -- Create a pragma and put it at the start of the task
4634 -- definition for the task type declaration.
4636 Aitem := Make_Aitem_Pragma
4637 (Pragma_Argument_Associations => New_List (
4638 Make_Pragma_Argument_Association (Loc,
4639 Expression => Relocate_Node (Expr))),
4640 Pragma_Name => Name_Storage_Size);
4644 Visible_Declarations (Task_Definition (Decl)));
4648 -- All other cases, generate attribute definition
4652 Make_Attribute_Definition_Clause (Loc,
4654 Chars => Chars (Id),
4655 Expression => Relocate_Node (Expr));
4659 -- Attach the corresponding pragma/attribute definition clause to
4660 -- the aspect specification node.
4662 if Present (Aitem) then
4663 Set_From_Aspect_Specification (Aitem);
4666 -- For an aspect that applies to a type, indicate whether it
4667 -- appears on a partial view of the type.
4670 and then Is_Private_Type (E)
4672 Set_Aspect_On_Partial_View (Aspect);
4675 -- In the context of a compilation unit, we directly put the
4676 -- pragma in the Pragmas_After list of the N_Compilation_Unit_Aux
4677 -- node (no delay is required here) except for aspects on a
4678 -- subprogram body (see below) and a generic package, for which we
4679 -- need to introduce the pragma before building the generic copy
4680 -- (see sem_ch12), and for package instantiations, where the
4681 -- library unit pragmas are better handled early.
4683 if Nkind (Parent (N)) = N_Compilation_Unit
4684 and then (Present (Aitem) or else Is_Boolean_Aspect (Aspect))
4687 Aux : constant Node_Id := Aux_Decls_Node (Parent (N));
4690 pragma Assert (Nkind (Aux) = N_Compilation_Unit_Aux);
4692 -- For a Boolean aspect, create the corresponding pragma if
4693 -- no expression or if the value is True.
4695 if Is_Boolean_Aspect (Aspect) and then No (Aitem) then
4696 if Is_True (Static_Boolean (Expr)) then
4697 Aitem := Make_Aitem_Pragma
4698 (Pragma_Argument_Associations => New_List (
4699 Make_Pragma_Argument_Association (Sloc (Ent),
4700 Expression => Ent)),
4701 Pragma_Name => Chars (Id));
4703 Set_From_Aspect_Specification (Aitem, True);
4704 Set_Corresponding_Aspect (Aitem, Aspect);
4711 -- If the aspect is on a subprogram body (relevant aspect
4712 -- is Inline), add the pragma in front of the declarations.
4714 if Nkind (N) = N_Subprogram_Body then
4715 if No (Declarations (N)) then
4716 Set_Declarations (N, New_List);
4719 Prepend (Aitem, Declarations (N));
4721 elsif Nkind (N) = N_Generic_Package_Declaration then
4722 if No (Visible_Declarations (Specification (N))) then
4723 Set_Visible_Declarations (Specification (N), New_List);
4727 Visible_Declarations (Specification (N)));
4729 elsif Nkind (N) = N_Package_Instantiation then
4731 Spec : constant Node_Id :=
4732 Specification (Instance_Spec (N));
4734 if No (Visible_Declarations (Spec)) then
4735 Set_Visible_Declarations (Spec, New_List);
4738 Prepend (Aitem, Visible_Declarations (Spec));
4742 if No (Pragmas_After (Aux)) then
4743 Set_Pragmas_After (Aux, New_List);
4746 Append (Aitem, Pragmas_After (Aux));
4753 -- The evaluation of the aspect is delayed to the freezing point.
4754 -- The pragma or attribute clause if there is one is then attached
4755 -- to the aspect specification which is put in the rep item list.
4757 if Delay_Required then
4758 if Present (Aitem) then
4759 Set_Is_Delayed_Aspect (Aitem);
4760 Set_Aspect_Rep_Item (Aspect, Aitem);
4761 Set_Parent (Aitem, Aspect);
4764 Set_Is_Delayed_Aspect (Aspect);
4766 -- In the case of Default_Value, link the aspect to base type
4767 -- as well, even though it appears on a first subtype. This is
4768 -- mandated by the semantics of the aspect. Do not establish
4769 -- the link when processing the base type itself as this leads
4770 -- to a rep item circularity.
4772 if A_Id = Aspect_Default_Value and then Base_Type (E) /= E then
4773 Set_Has_Delayed_Aspects (Base_Type (E));
4774 Record_Rep_Item (Base_Type (E), Aspect);
4777 Set_Has_Delayed_Aspects (E);
4778 Record_Rep_Item (E, Aspect);
4780 -- When delay is not required and the context is a package or a
4781 -- subprogram body, insert the pragma in the body declarations.
4783 elsif Nkind (N) in N_Package_Body | N_Subprogram_Body then
4784 if No (Declarations (N)) then
4785 Set_Declarations (N, New_List);
4788 -- The pragma is added before source declarations
4790 Prepend_To (Declarations (N), Aitem);
4792 -- When delay is not required and the context is not a compilation
4793 -- unit, we simply insert the pragma/attribute definition clause
4796 elsif Present (Aitem) then
4797 Insert_After (Ins_Node, Aitem);
4803 -- If a nonoverridable aspect is explicitly specified for a
4804 -- derived type, then check consistency with the parent type.
4806 if A_Id in Nonoverridable_Aspect_Id
4807 and then Nkind (N) = N_Full_Type_Declaration
4808 and then Nkind (Type_Definition (N)) = N_Derived_Type_Definition
4809 and then not In_Instance_Body
4812 Parent_Type : constant Entity_Id := Etype (E);
4813 Inherited_Aspect : constant Node_Id :=
4814 Find_Aspect (Parent_Type, A_Id);
4816 if Present (Inherited_Aspect)
4817 and then not Is_Confirming
4818 (A_Id, Inherited_Aspect, Aspect)
4820 Error_Msg_Name_1 := Aspect_Names (A_Id);
4821 Error_Msg_Sloc := Sloc (Inherited_Aspect);
4824 ("overriding aspect specification for "
4825 & "nonoverridable aspect % does not confirm "
4826 & "aspect specification inherited from #",
4831 end Analyze_One_Aspect;
4834 end loop Aspect_Loop;
4836 if Has_Delayed_Aspects (E) then
4837 Ensure_Freeze_Node (E);
4839 end Analyze_Aspect_Specifications;
4841 ------------------------------------------------
4842 -- Analyze_Aspects_On_Subprogram_Body_Or_Stub --
4843 ------------------------------------------------
4845 procedure Analyze_Aspects_On_Subprogram_Body_Or_Stub (N : Node_Id) is
4846 Body_Id : constant Entity_Id := Defining_Entity (N);
4848 procedure Diagnose_Misplaced_Aspects (Spec_Id : Entity_Id);
4849 -- Body [stub] N has aspects, but they are not properly placed. Emit an
4850 -- error message depending on the aspects involved. Spec_Id denotes the
4851 -- entity of the corresponding spec.
4853 --------------------------------
4854 -- Diagnose_Misplaced_Aspects --
4855 --------------------------------
4857 procedure Diagnose_Misplaced_Aspects (Spec_Id : Entity_Id) is
4858 procedure Misplaced_Aspect_Error
4861 -- Emit an error message concerning misplaced aspect Asp. Ref_Nam is
4862 -- the name of the refined version of the aspect.
4864 ----------------------------
4865 -- Misplaced_Aspect_Error --
4866 ----------------------------
4868 procedure Misplaced_Aspect_Error
4872 Asp_Nam : constant Name_Id := Chars (Identifier (Asp));
4873 Asp_Id : constant Aspect_Id := Get_Aspect_Id (Asp_Nam);
4876 -- The corresponding spec already contains the aspect in question
4877 -- and the one appearing on the body must be the refined form:
4879 -- procedure P with Global ...;
4880 -- procedure P with Global ... is ... end P;
4884 if Has_Aspect (Spec_Id, Asp_Id) then
4885 Error_Msg_Name_1 := Asp_Nam;
4887 -- Subunits cannot carry aspects that apply to a subprogram
4890 if Nkind (Parent (N)) = N_Subunit then
4891 Error_Msg_N ("aspect % cannot apply to a subunit", Asp);
4893 -- Otherwise suggest the refined form
4896 Error_Msg_Name_2 := Ref_Nam;
4897 Error_Msg_N ("aspect % should be %", Asp);
4900 -- Otherwise the aspect must appear on the spec, not on the body
4903 -- procedure P with Global ... is ... end P;
4907 ("aspect specification must appear on initial declaration",
4910 end Misplaced_Aspect_Error;
4917 -- Start of processing for Diagnose_Misplaced_Aspects
4920 -- Iterate over the aspect specifications and emit specific errors
4921 -- where applicable.
4923 Asp := First (Aspect_Specifications (N));
4924 while Present (Asp) loop
4925 Asp_Nam := Chars (Identifier (Asp));
4927 -- Do not emit errors on aspects that can appear on a subprogram
4928 -- body. This scenario occurs when the aspect specification list
4929 -- contains both misplaced and properly placed aspects.
4931 if Aspect_On_Body_Or_Stub_OK (Get_Aspect_Id (Asp_Nam)) then
4934 -- Special diagnostics for SPARK aspects
4936 elsif Asp_Nam = Name_Depends then
4937 Misplaced_Aspect_Error (Asp, Name_Refined_Depends);
4939 elsif Asp_Nam = Name_Global then
4940 Misplaced_Aspect_Error (Asp, Name_Refined_Global);
4942 elsif Asp_Nam = Name_Post then
4943 Misplaced_Aspect_Error (Asp, Name_Refined_Post);
4945 -- Otherwise a language-defined aspect is misplaced
4949 ("aspect specification must appear on initial declaration",
4955 end Diagnose_Misplaced_Aspects;
4959 Spec_Id : constant Entity_Id := Unique_Defining_Entity (N);
4961 -- Start of processing for Analyze_Aspects_On_Subprogram_Body_Or_Stub
4964 -- Language-defined aspects cannot be associated with a subprogram body
4965 -- [stub] if the subprogram has a spec. Certain implementation defined
4966 -- aspects are allowed to break this rule (for all applicable cases, see
4967 -- table Aspects.Aspect_On_Body_Or_Stub_OK).
4969 if Spec_Id /= Body_Id and then not Aspects_On_Body_Or_Stub_OK (N) then
4970 Diagnose_Misplaced_Aspects (Spec_Id);
4972 Analyze_Aspect_Specifications (N, Body_Id);
4974 end Analyze_Aspects_On_Subprogram_Body_Or_Stub;
4976 -----------------------
4977 -- Analyze_At_Clause --
4978 -----------------------
4980 -- An at clause is replaced by the corresponding Address attribute
4981 -- definition clause that is the preferred approach in Ada 95.
4983 procedure Analyze_At_Clause (N : Node_Id) is
4984 CS : constant Boolean := Comes_From_Source (N);
4987 -- This is an obsolescent feature
4989 Check_Restriction (No_Obsolescent_Features, N);
4991 if Warn_On_Obsolescent_Feature then
4993 ("?j?at clause is an obsolescent feature (RM J.7(2))", N);
4995 ("\?j?use address attribute definition clause instead", N);
4998 -- Rewrite as address clause
5001 Make_Attribute_Definition_Clause (Sloc (N),
5002 Name => Identifier (N),
5003 Chars => Name_Address,
5004 Expression => Expression (N)));
5006 -- We preserve Comes_From_Source, since logically the clause still comes
5007 -- from the source program even though it is changed in form.
5009 Set_Comes_From_Source (N, CS);
5011 -- Analyze rewritten clause
5013 Analyze_Attribute_Definition_Clause (N);
5014 end Analyze_At_Clause;
5016 -----------------------------------------
5017 -- Analyze_Attribute_Definition_Clause --
5018 -----------------------------------------
5020 procedure Analyze_Attribute_Definition_Clause (N : Node_Id) is
5021 Loc : constant Source_Ptr := Sloc (N);
5022 Nam : constant Node_Id := Name (N);
5023 Attr : constant Name_Id := Chars (N);
5024 Expr : constant Node_Id := Expression (N);
5025 Id : constant Attribute_Id := Get_Attribute_Id (Attr);
5028 -- The entity of Nam after it is analyzed. In the case of an incomplete
5029 -- type, this is the underlying type.
5032 -- The underlying entity to which the attribute applies. Generally this
5033 -- is the Underlying_Type of Ent, except in the case where the clause
5034 -- applies to the full view of an incomplete or private type, in which
5035 -- case U_Ent is just a copy of Ent.
5037 FOnly : Boolean := False;
5038 -- Reset to True for subtype specific attribute (Alignment, Size)
5039 -- and for stream attributes, i.e. those cases where in the call to
5040 -- Rep_Item_Too_Late, FOnly is set True so that only the freezing rules
5041 -- are checked. Note that the case of stream attributes is not clear
5042 -- from the RM, but see AI95-00137. Also, the RM seems to disallow
5043 -- Storage_Size for derived task types, but that is also clearly
5046 procedure Analyze_Put_Image_TSS_Definition;
5048 procedure Analyze_Stream_TSS_Definition (TSS_Nam : TSS_Name_Type);
5049 -- Common processing for 'Read, 'Write, 'Input and 'Output attribute
5050 -- definition clauses.
5052 function Duplicate_Clause return Boolean;
5053 -- This routine checks if the aspect for U_Ent being given by attribute
5054 -- definition clause N is for an aspect that has already been specified,
5055 -- and if so gives an error message. If there is a duplicate, True is
5056 -- returned, otherwise if there is no error, False is returned.
5058 procedure Check_Indexing_Functions;
5059 -- Check that the function in Constant_Indexing or Variable_Indexing
5060 -- attribute has the proper type structure. If the name is overloaded,
5061 -- check that some interpretation is legal.
5063 procedure Check_Iterator_Functions;
5064 -- Check that there is a single function in Default_Iterator attribute
5065 -- that has the proper type structure.
5067 function Check_Primitive_Function (Subp : Entity_Id) return Boolean;
5068 -- Common legality check for the previous two
5070 -----------------------------------
5071 -- Analyze_Put_Image_TSS_Definition --
5072 -----------------------------------
5074 procedure Analyze_Put_Image_TSS_Definition is
5075 Subp : Entity_Id := Empty;
5080 function Has_Good_Profile
5082 Report : Boolean := False) return Boolean;
5083 -- Return true if the entity is a subprogram with an appropriate
5084 -- profile for the attribute being defined. If result is False and
5085 -- Report is True, function emits appropriate error.
5087 ----------------------
5088 -- Has_Good_Profile --
5089 ----------------------
5091 function Has_Good_Profile
5093 Report : Boolean := False) return Boolean
5099 if Ekind (Subp) /= E_Procedure then
5103 F := First_Formal (Subp);
5105 if No (F) or else Etype (F) /= Class_Wide_Type (RTE (RE_Sink)) then
5111 if Parameter_Mode (F) /= E_In_Parameter then
5117 -- Verify that the prefix of the attribute and the local name for
5118 -- the type of the formal match.
5124 if Present (Next_Formal (F)) then
5127 elsif not Is_Scalar_Type (Typ)
5128 and then not Is_First_Subtype (Typ)
5130 if Report and not Is_First_Subtype (Typ) then
5132 ("subtype of formal in Put_Image operation must be a "
5133 & "first subtype", Parameter_Type (Parent (F)));
5141 end Has_Good_Profile;
5143 -- Start of processing for Analyze_Put_Image_TSS_Definition
5146 if not Is_Type (U_Ent) then
5147 Error_Msg_N ("local name must be a subtype", Nam);
5150 elsif not Is_First_Subtype (U_Ent) then
5151 Error_Msg_N ("local name must be a first subtype", Nam);
5155 Pnam := TSS (Base_Type (U_Ent), TSS_Put_Image);
5157 -- If Pnam is present, it can be either inherited from an ancestor
5158 -- type (in which case it is legal to redefine it for this type), or
5159 -- be a previous definition of the attribute for the same type (in
5160 -- which case it is illegal).
5162 -- In the first case, it will have been analyzed already, and we can
5163 -- check that its profile does not match the expected profile for the
5164 -- Put_Image attribute of U_Ent. In the second case, either Pnam has
5165 -- been analyzed (and has the expected profile), or it has not been
5166 -- analyzed yet (case of a type that has not been frozen yet and for
5167 -- which Put_Image has been set using Set_TSS).
5170 and then (No (First_Entity (Pnam)) or else Has_Good_Profile (Pnam))
5172 Error_Msg_Sloc := Sloc (Pnam);
5173 Error_Msg_Name_1 := Attr;
5174 Error_Msg_N ("% attribute already defined #", Nam);
5180 if Is_Entity_Name (Expr) then
5181 if not Is_Overloaded (Expr) then
5182 if Has_Good_Profile (Entity (Expr), Report => True) then
5183 Subp := Entity (Expr);
5187 Get_First_Interp (Expr, I, It);
5188 while Present (It.Nam) loop
5189 if Has_Good_Profile (It.Nam) then
5194 Get_Next_Interp (I, It);
5199 if Present (Subp) then
5200 if Is_Abstract_Subprogram (Subp) then
5201 Error_Msg_N ("Put_Image subprogram must not be abstract", Expr);
5205 Set_Entity (Expr, Subp);
5206 Set_Etype (Expr, Etype (Subp));
5208 New_Put_Image_Subprogram (N, U_Ent, Subp);
5211 Error_Msg_Name_1 := Attr;
5212 Error_Msg_N ("incorrect expression for% attribute", Expr);
5214 end Analyze_Put_Image_TSS_Definition;
5216 -----------------------------------
5217 -- Analyze_Stream_TSS_Definition --
5218 -----------------------------------
5220 procedure Analyze_Stream_TSS_Definition (TSS_Nam : TSS_Name_Type) is
5221 Subp : Entity_Id := Empty;
5226 Is_Read : constant Boolean := (TSS_Nam = TSS_Stream_Read);
5227 -- True for Read attribute, False for other attributes
5229 function Has_Good_Profile
5231 Report : Boolean := False) return Boolean;
5232 -- Return true if the entity is a subprogram with an appropriate
5233 -- profile for the attribute being defined. If result is False and
5234 -- Report is True, function emits appropriate error.
5236 ----------------------
5237 -- Has_Good_Profile --
5238 ----------------------
5240 function Has_Good_Profile
5242 Report : Boolean := False) return Boolean
5244 Expected_Ekind : constant array (Boolean) of Entity_Kind :=
5245 (False => E_Procedure, True => E_Function);
5246 Is_Function : constant Boolean := (TSS_Nam = TSS_Stream_Input);
5251 if Ekind (Subp) /= Expected_Ekind (Is_Function) then
5255 F := First_Formal (Subp);
5258 or else Ekind (Etype (F)) /= E_Anonymous_Access_Type
5259 or else Designated_Type (Etype (F)) /=
5260 Class_Wide_Type (RTE (RE_Root_Stream_Type))
5265 if not Is_Function then
5269 Expected_Mode : constant array (Boolean) of Entity_Kind :=
5270 (False => E_In_Parameter,
5271 True => E_Out_Parameter);
5273 if Parameter_Mode (F) /= Expected_Mode (Is_Read) then
5281 Typ := Etype (Subp);
5284 -- Verify that the prefix of the attribute and the local name for
5285 -- the type of the formal match.
5287 if Base_Type (Typ) /= Base_Type (Ent) then
5291 if Present (Next_Formal (F)) then
5294 elsif not Is_Scalar_Type (Typ)
5295 and then not Is_First_Subtype (Typ)
5296 and then not Is_Class_Wide_Type (Typ)
5298 if Report and not Is_First_Subtype (Typ) then
5300 ("subtype of formal in stream operation must be a first "
5301 & "subtype", Parameter_Type (Parent (F)));
5309 end Has_Good_Profile;
5311 -- Start of processing for Analyze_Stream_TSS_Definition
5316 if not Is_Type (U_Ent) then
5317 Error_Msg_N ("local name must be a subtype", Nam);
5320 elsif not Is_First_Subtype (U_Ent) then
5321 Error_Msg_N ("local name must be a first subtype", Nam);
5325 Pnam := TSS (Base_Type (U_Ent), TSS_Nam);
5327 -- If Pnam is present, it can be either inherited from an ancestor
5328 -- type (in which case it is legal to redefine it for this type), or
5329 -- be a previous definition of the attribute for the same type (in
5330 -- which case it is illegal).
5332 -- In the first case, it will have been analyzed already, and we
5333 -- can check that its profile does not match the expected profile
5334 -- for a stream attribute of U_Ent. In the second case, either Pnam
5335 -- has been analyzed (and has the expected profile), or it has not
5336 -- been analyzed yet (case of a type that has not been frozen yet
5337 -- and for which the stream attribute has been set using Set_TSS).
5340 and then (No (First_Entity (Pnam)) or else Has_Good_Profile (Pnam))
5342 Error_Msg_Sloc := Sloc (Pnam);
5343 Error_Msg_Name_1 := Attr;
5344 Error_Msg_N ("% attribute already defined #", Nam);
5350 if Is_Entity_Name (Expr) then
5351 if not Is_Overloaded (Expr) then
5352 if Has_Good_Profile (Entity (Expr), Report => True) then
5353 Subp := Entity (Expr);
5357 Get_First_Interp (Expr, I, It);
5358 while Present (It.Nam) loop
5359 if Has_Good_Profile (It.Nam) then
5364 Get_Next_Interp (I, It);
5369 if Present (Subp) then
5370 if Is_Abstract_Subprogram (Subp) then
5371 Error_Msg_N ("stream subprogram must not be abstract", Expr);
5374 -- A stream subprogram for an interface type must be a null
5375 -- procedure (RM 13.13.2 (38/3)). Note that the class-wide type
5376 -- of an interface is not an interface type (3.9.4 (6.b/2)).
5378 elsif Is_Interface (U_Ent)
5379 and then not Is_Class_Wide_Type (U_Ent)
5380 and then not Inside_A_Generic
5382 (Ekind (Subp) = E_Function
5386 (Unit_Declaration_Node (Ultimate_Alias (Subp)))))
5389 ("stream subprogram for interface type must be null "
5390 & "procedure", Expr);
5393 Set_Entity (Expr, Subp);
5394 Set_Etype (Expr, Etype (Subp));
5396 New_Stream_Subprogram (N, U_Ent, Subp, TSS_Nam);
5399 Error_Msg_Name_1 := Attr;
5401 if Is_Class_Wide_Type (Base_Type (Ent)) then
5403 ("incorrect expression for class-wide% attribute", Expr);
5405 Error_Msg_N ("incorrect expression for% attribute", Expr);
5408 end Analyze_Stream_TSS_Definition;
5410 ------------------------------
5411 -- Check_Indexing_Functions --
5412 ------------------------------
5414 procedure Check_Indexing_Functions is
5415 Indexing_Found : Boolean := False;
5417 procedure Check_Inherited_Indexing;
5418 -- For a derived type, check that for a derived type, a specification
5419 -- of an indexing aspect can only be confirming, i.e. uses the same
5420 -- name as in the parent type.
5421 -- AI12-0160: Verify that an indexing cannot be specified for
5422 -- a derived type unless it is specified for the parent.
5424 procedure Check_One_Function (Subp : Entity_Id);
5425 -- Check one possible interpretation. Sets Indexing_Found True if a
5426 -- legal indexing function is found.
5428 procedure Illegal_Indexing (Msg : String);
5429 -- Diagnose illegal indexing function if not overloaded. In the
5430 -- overloaded case indicate that no legal interpretation exists.
5432 ------------------------------
5433 -- Check_Inherited_Indexing --
5434 ------------------------------
5436 procedure Check_Inherited_Indexing is
5437 Inherited : Node_Id;
5438 Other_Indexing : Node_Id;
5441 if Attr = Name_Constant_Indexing then
5443 Find_Aspect (Etype (Ent), Aspect_Constant_Indexing);
5445 Find_Aspect (Etype (Ent), Aspect_Variable_Indexing);
5447 else pragma Assert (Attr = Name_Variable_Indexing);
5449 Find_Aspect (Etype (Ent), Aspect_Variable_Indexing);
5451 Find_Aspect (Etype (Ent), Aspect_Constant_Indexing);
5454 if Present (Inherited) then
5455 if Debug_Flag_Dot_XX then
5458 -- OK if current attribute_definition_clause is expansion of
5459 -- inherited aspect.
5461 elsif Aspect_Rep_Item (Inherited) = N then
5464 -- Check if this is a confirming specification. The name
5465 -- may be overloaded between the parent operation and the
5466 -- inherited one, so we check that the Chars fields match.
5468 elsif Is_Entity_Name (Expression (Inherited))
5469 and then Chars (Entity (Expression (Inherited))) =
5470 Chars (Entity (Expression (N)))
5472 Indexing_Found := True;
5474 -- Indicate the operation that must be overridden, rather than
5475 -- redefining the indexing aspect.
5479 ("indexing function already inherited from parent type");
5481 ("!override & instead",
5482 N, Entity (Expression (Inherited)));
5485 -- If not inherited and the parent has another indexing function
5486 -- this is illegal, because it leads to inconsistent results in
5487 -- class-wide calls.
5489 elsif Present (Other_Indexing) then
5491 ("cannot specify indexing operation on derived type"
5492 & " if not specified for parent", N);
5494 end Check_Inherited_Indexing;
5496 ------------------------
5497 -- Check_One_Function --
5498 ------------------------
5500 procedure Check_One_Function (Subp : Entity_Id) is
5501 Default_Element : Node_Id;
5502 Ret_Type : constant Entity_Id := Etype (Subp);
5505 if not Is_Overloadable (Subp) then
5506 Illegal_Indexing ("illegal indexing function for type&");
5509 elsif Scope (Subp) /= Scope (Ent) then
5510 if Nkind (Expr) = N_Expanded_Name then
5512 -- Indexing function can't be declared elsewhere
5515 ("indexing function must be declared"
5516 & " in scope of type&");
5519 if Is_Derived_Type (Ent) then
5520 Check_Inherited_Indexing;
5525 elsif No (First_Formal (Subp)) then
5527 ("Indexing requires a function that applies to type&");
5530 elsif No (Next_Formal (First_Formal (Subp))) then
5532 ("indexing function must have at least two parameters");
5535 elsif Is_Derived_Type (Ent) then
5536 Check_Inherited_Indexing;
5539 if not Check_Primitive_Function (Subp) then
5541 ("Indexing aspect requires a function that applies to type&");
5545 -- If partial declaration exists, verify that it is not tagged.
5547 if Ekind (Current_Scope) = E_Package
5548 and then Has_Private_Declaration (Ent)
5549 and then From_Aspect_Specification (N)
5551 List_Containing (Parent (Ent)) =
5552 Private_Declarations
5553 (Specification (Unit_Declaration_Node (Current_Scope)))
5554 and then Nkind (N) = N_Attribute_Definition_Clause
5561 First (Visible_Declarations
5563 (Unit_Declaration_Node (Current_Scope))));
5565 while Present (Decl) loop
5566 if Nkind (Decl) = N_Private_Type_Declaration
5567 and then Ent = Full_View (Defining_Identifier (Decl))
5568 and then Tagged_Present (Decl)
5569 and then No (Aspect_Specifications (Decl))
5572 ("Indexing aspect cannot be specified on full view "
5573 & "if partial view is tagged");
5582 -- An indexing function must return either the default element of
5583 -- the container, or a reference type. For variable indexing it
5584 -- must be the latter.
5587 Find_Value_Of_Aspect
5588 (Etype (First_Formal (Subp)), Aspect_Iterator_Element);
5590 if Present (Default_Element) then
5591 Analyze (Default_Element);
5594 -- For variable_indexing the return type must be a reference type
5596 if Attr = Name_Variable_Indexing then
5597 if not Has_Implicit_Dereference (Ret_Type) then
5599 ("variable indexing must return a reference type");
5602 elsif Is_Access_Constant
5603 (Etype (First_Discriminant (Ret_Type)))
5606 ("variable indexing must return an access to variable");
5611 if Has_Implicit_Dereference (Ret_Type)
5614 (Etype (Get_Reference_Discriminant (Ret_Type)))
5617 ("constant indexing must return an access to constant");
5620 elsif Is_Access_Type (Etype (First_Formal (Subp)))
5621 and then not Is_Access_Constant (Etype (First_Formal (Subp)))
5624 ("constant indexing must apply to an access to constant");
5629 -- All checks succeeded
5631 Indexing_Found := True;
5632 end Check_One_Function;
5634 -----------------------
5635 -- Illegal_Indexing --
5636 -----------------------
5638 procedure Illegal_Indexing (Msg : String) is
5640 Error_Msg_NE (Msg, N, Ent);
5641 end Illegal_Indexing;
5643 -- Start of processing for Check_Indexing_Functions
5647 Check_Inherited_Indexing;
5652 if not Is_Overloaded (Expr) then
5653 Check_One_Function (Entity (Expr));
5661 Indexing_Found := False;
5662 Get_First_Interp (Expr, I, It);
5663 while Present (It.Nam) loop
5665 -- Note that analysis will have added the interpretation
5666 -- that corresponds to the dereference. We only check the
5667 -- subprogram itself. Ignore homonyms that may come from
5668 -- derived types in the context.
5670 if Is_Overloadable (It.Nam)
5671 and then Comes_From_Source (It.Nam)
5673 Check_One_Function (It.Nam);
5676 Get_Next_Interp (I, It);
5681 if not Indexing_Found and then not Error_Posted (N) then
5683 ("aspect Indexing requires a local function that applies to "
5684 & "type&", Expr, Ent);
5686 end Check_Indexing_Functions;
5688 ------------------------------
5689 -- Check_Iterator_Functions --
5690 ------------------------------
5692 procedure Check_Iterator_Functions is
5693 function Valid_Default_Iterator (Subp : Entity_Id) return Boolean;
5694 -- Check one possible interpretation for validity
5696 ----------------------------
5697 -- Valid_Default_Iterator --
5698 ----------------------------
5700 function Valid_Default_Iterator (Subp : Entity_Id) return Boolean is
5701 Root_T : constant Entity_Id := Root_Type (Etype (Etype (Subp)));
5705 if not Check_Primitive_Function (Subp) then
5708 -- The return type must be derived from a type in an instance
5709 -- of Iterator.Interfaces, and thus its root type must have a
5712 elsif Chars (Root_T) /= Name_Forward_Iterator
5713 and then Chars (Root_T) /= Name_Reversible_Iterator
5718 Formal := First_Formal (Subp);
5721 -- False if any subsequent formal has no default expression
5723 Next_Formal (Formal);
5724 while Present (Formal) loop
5725 if No (Expression (Parent (Formal))) then
5729 Next_Formal (Formal);
5732 -- True if all subsequent formals have default expressions
5735 end Valid_Default_Iterator;
5737 -- Start of processing for Check_Iterator_Functions
5742 if not Is_Entity_Name (Expr) then
5743 Error_Msg_N ("aspect Iterator must be a function name", Expr);
5746 if not Is_Overloaded (Expr) then
5747 if Entity (Expr) /= Any_Id
5748 and then not Check_Primitive_Function (Entity (Expr))
5751 ("aspect Indexing requires a function that applies to type&",
5752 Entity (Expr), Ent);
5755 -- Flag the default_iterator as well as the denoted function.
5757 if not Valid_Default_Iterator (Entity (Expr)) then
5758 Error_Msg_N ("improper function for default iterator!", Expr);
5763 Default : Entity_Id := Empty;
5768 Get_First_Interp (Expr, I, It);
5769 while Present (It.Nam) loop
5770 if not Check_Primitive_Function (It.Nam)
5771 or else not Valid_Default_Iterator (It.Nam)
5775 elsif Present (Default) then
5777 -- An explicit one should override an implicit one
5779 if Comes_From_Source (Default) =
5780 Comes_From_Source (It.Nam)
5782 Error_Msg_N ("default iterator must be unique", Expr);
5783 Error_Msg_Sloc := Sloc (Default);
5784 Error_Msg_N ("\\possible interpretation#", Expr);
5785 Error_Msg_Sloc := Sloc (It.Nam);
5786 Error_Msg_N ("\\possible interpretation#", Expr);
5788 elsif Comes_From_Source (It.Nam) then
5795 Get_Next_Interp (I, It);
5798 if Present (Default) then
5799 Set_Entity (Expr, Default);
5800 Set_Is_Overloaded (Expr, False);
5803 ("no interpretation is a valid default iterator!", Expr);
5807 end Check_Iterator_Functions;
5809 -------------------------------
5810 -- Check_Primitive_Function --
5811 -------------------------------
5813 function Check_Primitive_Function (Subp : Entity_Id) return Boolean is
5817 if Ekind (Subp) /= E_Function then
5821 if No (First_Formal (Subp)) then
5824 Ctrl := Etype (First_Formal (Subp));
5827 -- To be a primitive operation subprogram has to be in same scope.
5829 if Scope (Ctrl) /= Scope (Subp) then
5833 -- Type of formal may be the class-wide type, an access to such,
5834 -- or an incomplete view.
5837 or else Ctrl = Class_Wide_Type (Ent)
5839 (Ekind (Ctrl) = E_Anonymous_Access_Type
5840 and then (Designated_Type (Ctrl) = Ent
5842 Designated_Type (Ctrl) = Class_Wide_Type (Ent)))
5844 (Ekind (Ctrl) = E_Incomplete_Type
5845 and then Full_View (Ctrl) = Ent)
5853 end Check_Primitive_Function;
5855 ----------------------
5856 -- Duplicate_Clause --
5857 ----------------------
5859 function Duplicate_Clause return Boolean is
5863 -- Nothing to do if this attribute definition clause comes from
5864 -- an aspect specification, since we could not be duplicating an
5865 -- explicit clause, and we dealt with the case of duplicated aspects
5866 -- in Analyze_Aspect_Specifications.
5868 if From_Aspect_Specification (N) then
5872 -- Otherwise current clause may duplicate previous clause, or a
5873 -- previously given pragma or aspect specification for the same
5876 A := Get_Rep_Item (U_Ent, Chars (N), Check_Parents => False);
5879 Error_Msg_Name_1 := Chars (N);
5880 Error_Msg_Sloc := Sloc (A);
5882 Error_Msg_NE ("aspect% for & previously given#", N, U_Ent);
5887 end Duplicate_Clause;
5889 -- Start of processing for Analyze_Attribute_Definition_Clause
5892 -- The following code is a defense against recursion. Not clear that
5893 -- this can happen legitimately, but perhaps some error situations can
5894 -- cause it, and we did see this recursion during testing.
5896 if Analyzed (N) then
5899 Set_Analyzed (N, True);
5902 Check_Restriction_No_Use_Of_Attribute (N);
5904 if Get_Aspect_Id (Chars (N)) /= No_Aspect then
5905 -- 6.1/3 No_Specification_of_Aspect: Identifies an aspect for which
5906 -- no aspect_specification, attribute_definition_clause, or pragma
5908 Check_Restriction_No_Specification_Of_Aspect (N);
5911 -- Ignore some selected attributes in CodePeer mode since they are not
5912 -- relevant in this context.
5914 if CodePeer_Mode then
5917 -- Ignore Component_Size in CodePeer mode, to avoid changing the
5918 -- internal representation of types by implicitly packing them.
5920 when Attribute_Component_Size =>
5921 Rewrite (N, Make_Null_Statement (Sloc (N)));
5929 -- Process Ignore_Rep_Clauses option
5931 if Ignore_Rep_Clauses then
5934 -- The following should be ignored. They do not affect legality
5935 -- and may be target dependent. The basic idea of -gnatI is to
5936 -- ignore any rep clauses that may be target dependent but do not
5937 -- affect legality (except possibly to be rejected because they
5938 -- are incompatible with the compilation target).
5940 when Attribute_Alignment
5941 | Attribute_Bit_Order
5942 | Attribute_Component_Size
5943 | Attribute_Default_Scalar_Storage_Order
5944 | Attribute_Machine_Radix
5945 | Attribute_Object_Size
5946 | Attribute_Scalar_Storage_Order
5949 | Attribute_Stream_Size
5950 | Attribute_Value_Size
5952 Kill_Rep_Clause (N);
5955 -- The following should not be ignored, because in the first place
5956 -- they are reasonably portable, and should not cause problems
5957 -- in compiling code from another target, and also they do affect
5958 -- legality, e.g. failing to provide a stream attribute for a type
5959 -- may make a program illegal.
5961 when Attribute_External_Tag
5964 | Attribute_Put_Image
5966 | Attribute_Simple_Storage_Pool
5967 | Attribute_Storage_Pool
5968 | Attribute_Storage_Size
5973 -- We do not do anything here with address clauses, they will be
5974 -- removed by Freeze later on, but for now, it works better to
5975 -- keep them in the tree.
5977 when Attribute_Address =>
5980 -- Other cases are errors ("attribute& cannot be set with
5981 -- definition clause"), which will be caught below.
5989 Ent := Entity (Nam);
5991 if Rep_Item_Too_Early (Ent, N) then
5995 -- Rep clause applies to (underlying) full view of private or incomplete
5996 -- type if we have one (if not, this is a premature use of the type).
5997 -- However, some semantic checks need to be done on the specified entity
5998 -- i.e. the private view, so we save it in Ent.
6000 if Is_Private_Type (Ent)
6001 and then Is_Derived_Type (Ent)
6002 and then not Is_Tagged_Type (Ent)
6003 and then No (Full_View (Ent))
6004 and then No (Underlying_Full_View (Ent))
6008 elsif Ekind (Ent) = E_Incomplete_Type then
6010 -- The attribute applies to the full view, set the entity of the
6011 -- attribute definition accordingly.
6013 Ent := Underlying_Type (Ent);
6015 Set_Entity (Nam, Ent);
6018 U_Ent := Underlying_Type (Ent);
6021 -- Avoid cascaded error
6023 if Etype (Nam) = Any_Type then
6026 -- Must be declared in current scope or in case of an aspect
6027 -- specification, must be visible in current scope.
6029 elsif Scope (Ent) /= Current_Scope
6031 not (From_Aspect_Specification (N)
6032 and then Scope_Within_Or_Same (Current_Scope, Scope (Ent)))
6034 Error_Msg_N ("entity must be declared in this scope", Nam);
6037 -- Must not be a source renaming (we do have some cases where the
6038 -- expander generates a renaming, and those cases are OK, in such
6039 -- cases any attribute applies to the renamed object as well).
6041 elsif Is_Object (Ent)
6042 and then Present (Renamed_Object (Ent))
6044 -- In the case of a renamed object from source, this is an error
6045 -- unless the object is an aggregate and the renaming is created
6046 -- for an object declaration.
6048 if Comes_From_Source (Renamed_Object (Ent))
6049 and then Nkind (Renamed_Object (Ent)) /= N_Aggregate
6051 Get_Name_String (Chars (N));
6052 Error_Msg_Strlen := Name_Len;
6053 Error_Msg_String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len);
6055 ("~ clause not allowed for a renaming declaration "
6056 & "(RM 13.1(6))", Nam);
6059 -- For the case of a compiler generated renaming, the attribute
6060 -- definition clause applies to the renamed object created by the
6061 -- expander. The easiest general way to handle this is to create a
6062 -- copy of the attribute definition clause for this object.
6064 elsif Is_Entity_Name (Renamed_Object (Ent)) then
6066 Make_Attribute_Definition_Clause (Loc,
6068 New_Occurrence_Of (Entity (Renamed_Object (Ent)), Loc),
6070 Expression => Duplicate_Subexpr (Expression (N))));
6072 -- If the renamed object is not an entity, it must be a dereference
6073 -- of an unconstrained function call, and we must introduce a new
6074 -- declaration to capture the expression. This is needed in the case
6075 -- of 'Alignment, where the original declaration must be rewritten.
6079 (Nkind (Renamed_Object (Ent)) = N_Explicit_Dereference);
6083 -- If no underlying entity, use entity itself, applies to some
6084 -- previously detected error cases ???
6086 elsif No (U_Ent) then
6089 -- Cannot specify for a subtype (exception Object/Value_Size)
6091 elsif Is_Type (U_Ent)
6092 and then not Is_First_Subtype (U_Ent)
6093 and then Id /= Attribute_Object_Size
6094 and then Id /= Attribute_Value_Size
6095 and then not From_At_Mod (N)
6097 Error_Msg_N ("cannot specify attribute for subtype", Nam);
6101 Set_Entity (N, U_Ent);
6103 -- Switch on particular attribute
6111 -- Address attribute definition clause
6113 when Attribute_Address => Address : begin
6115 -- A little error check, catch for X'Address use X'Address;
6117 if Nkind (Nam) = N_Identifier
6118 and then Nkind (Expr) = N_Attribute_Reference
6119 and then Attribute_Name (Expr) = Name_Address
6120 and then Nkind (Prefix (Expr)) = N_Identifier
6121 and then Chars (Nam) = Chars (Prefix (Expr))
6124 ("address for & is self-referencing", Prefix (Expr), Ent);
6128 -- Not that special case, carry on with analysis of expression
6130 Analyze_And_Resolve (Expr, RTE (RE_Address));
6132 -- Even when ignoring rep clauses we need to indicate that the
6133 -- entity has an address clause and thus it is legal to declare
6134 -- it imported. Freeze will get rid of the address clause later.
6135 -- Also call Set_Address_Taken to indicate that an address clause
6136 -- was present, even if we are about to remove it.
6138 if Ignore_Rep_Clauses then
6139 Set_Address_Taken (U_Ent);
6141 if Ekind (U_Ent) in E_Variable | E_Constant then
6142 Record_Rep_Item (U_Ent, N);
6148 if Duplicate_Clause then
6151 -- Case of address clause for subprogram
6153 elsif Is_Subprogram (U_Ent) then
6154 if Has_Homonym (U_Ent) then
6156 ("address clause cannot be given for overloaded "
6157 & "subprogram", Nam);
6161 -- For subprograms, all address clauses are permitted, and we
6162 -- mark the subprogram as having a deferred freeze so that Gigi
6163 -- will not elaborate it too soon.
6165 -- Above needs more comments, what is too soon about???
6167 Set_Has_Delayed_Freeze (U_Ent);
6169 -- Case of address clause for entry
6171 elsif Ekind (U_Ent) = E_Entry then
6172 if Nkind (Parent (N)) = N_Task_Body then
6174 ("entry address must be specified in task spec", Nam);
6178 -- For entries, we require a constant address
6180 Check_Constant_Address_Clause (Expr, U_Ent);
6182 -- Special checks for task types
6184 if Is_Task_Type (Scope (U_Ent))
6185 and then Comes_From_Source (Scope (U_Ent))
6188 ("??entry address declared for entry in task type", N);
6190 ("\??only one task can be declared of this type", N);
6193 -- Entry address clauses are obsolescent
6195 Check_Restriction (No_Obsolescent_Features, N);
6197 if Warn_On_Obsolescent_Feature then
6199 ("?j?attaching interrupt to task entry is an obsolescent "
6200 & "feature (RM J.7.1)", N);
6202 ("\?j?use interrupt procedure instead", N);
6205 -- Case of an address clause for a class-wide object, which is
6206 -- considered erroneous.
6208 elsif Is_Class_Wide_Type (Etype (U_Ent)) then
6210 ("??class-wide object & must not be overlaid", Nam, U_Ent);
6212 ("\??Program_Error will be raised at run time", Nam);
6213 Insert_Action (Declaration_Node (U_Ent),
6214 Make_Raise_Program_Error (Loc,
6215 Reason => PE_Overlaid_Controlled_Object));
6218 -- Case of address clause for an object
6220 elsif Ekind (U_Ent) in E_Constant | E_Variable then
6222 Expr : constant Node_Id := Expression (N);
6227 -- Exported variables cannot have an address clause, because
6228 -- this cancels the effect of the pragma Export.
6230 if Is_Exported (U_Ent) then
6232 ("cannot export object with address clause", Nam);
6236 Find_Overlaid_Entity (N, O_Ent, Off);
6238 if Present (O_Ent) then
6240 -- If the object overlays a constant object, mark it so
6242 if Is_Constant_Object (O_Ent) then
6243 Set_Overlays_Constant (U_Ent);
6246 -- If the address clause is of the form:
6248 -- for X'Address use Y'Address;
6252 -- C : constant Address := Y'Address;
6254 -- for X'Address use C;
6256 -- then we make an entry in the table to check the size
6257 -- and alignment of the overlaying variable. But we defer
6258 -- this check till after code generation to take full
6259 -- advantage of the annotation done by the back end.
6261 -- If the entity has a generic type, the check will be
6262 -- performed in the instance if the actual type justifies
6263 -- it, and we do not insert the clause in the table to
6264 -- prevent spurious warnings.
6266 -- Note: we used to test Comes_From_Source and only give
6267 -- this warning for source entities, but we have removed
6268 -- this test. It really seems bogus to generate overlays
6269 -- that would trigger this warning in generated code.
6270 -- Furthermore, by removing the test, we handle the
6271 -- aspect case properly.
6273 if Is_Object (O_Ent)
6274 and then not Is_Generic_Formal (O_Ent)
6275 and then not Is_Generic_Type (Etype (U_Ent))
6276 and then Address_Clause_Overlay_Warnings
6278 Register_Address_Clause_Check
6279 (N, U_Ent, No_Uint, O_Ent, Off);
6282 -- If the overlay changes the storage order, warn since
6283 -- the construct is not really supported by the back end.
6284 -- Also mark the entity as being volatile to block the
6285 -- optimizer, even if there is no warranty on the result.
6287 if (Is_Record_Type (Etype (U_Ent))
6288 or else Is_Array_Type (Etype (U_Ent)))
6289 and then (Is_Record_Type (Etype (O_Ent))
6290 or else Is_Array_Type (Etype (O_Ent)))
6291 and then Reverse_Storage_Order (Etype (U_Ent)) /=
6292 Reverse_Storage_Order (Etype (O_Ent))
6295 ("??overlay changes scalar storage order", Expr);
6296 Set_Treat_As_Volatile (U_Ent);
6300 -- If this is not an overlay, mark a variable as being
6301 -- volatile to prevent unwanted optimizations. It's a
6302 -- conservative interpretation of RM 13.3(19) for the
6303 -- cases where the compiler cannot detect potential
6304 -- aliasing issues easily and it also covers the case
6305 -- of an absolute address where the volatile aspect is
6306 -- kind of implicit.
6308 if Ekind (U_Ent) = E_Variable then
6309 Set_Treat_As_Volatile (U_Ent);
6312 -- Make an entry in the table for an absolute address as
6313 -- above to check that the value is compatible with the
6314 -- alignment of the object.
6317 Addr : constant Node_Id := Address_Value (Expr);
6319 if Compile_Time_Known_Value (Addr)
6320 and then Address_Clause_Overlay_Warnings
6322 Register_Address_Clause_Check
6323 (N, U_Ent, Expr_Value (Addr), Empty, False);
6328 -- Issue an unconditional warning for a constant overlaying
6329 -- a variable. For the reverse case, we will issue it only
6330 -- if the variable is modified.
6331 -- Within a generic unit an In_Parameter is a constant.
6332 -- It can be instantiated with a variable, in which case
6333 -- there will be a warning on the instance.
6335 if Ekind (U_Ent) = E_Constant
6336 and then Present (O_Ent)
6337 and then Ekind (O_Ent) /= E_Generic_In_Parameter
6338 and then not Overlays_Constant (U_Ent)
6339 and then Address_Clause_Overlay_Warnings
6341 Error_Msg_N ("??constant overlays a variable", Expr);
6343 -- Imported variables can have an address clause, but then
6344 -- the import is pretty meaningless except to suppress
6345 -- initializations, so we do not need such variables to
6346 -- be statically allocated (and in fact it causes trouble
6347 -- if the address clause is a local value).
6349 elsif Is_Imported (U_Ent) then
6350 Set_Is_Statically_Allocated (U_Ent, False);
6353 -- We mark a possible modification of a variable with an
6354 -- address clause, since it is likely aliasing is occurring.
6356 Note_Possible_Modification (Nam, Sure => False);
6358 -- Legality checks on the address clause for initialized
6359 -- objects is deferred until the freeze point, because
6360 -- a subsequent pragma might indicate that the object
6361 -- is imported and thus not initialized. Also, the address
6362 -- clause might involve entities that have yet to be
6365 Set_Has_Delayed_Freeze (U_Ent);
6367 -- If an initialization call has been generated for this
6368 -- object, it needs to be deferred to after the freeze node
6369 -- we have just now added, otherwise GIGI will see a
6370 -- reference to the variable (as actual to the IP call)
6371 -- before its definition.
6374 Init_Call : constant Node_Id :=
6375 Remove_Init_Call (U_Ent, N);
6378 if Present (Init_Call) then
6379 Append_Freeze_Action (U_Ent, Init_Call);
6381 -- Reset Initialization_Statements pointer so that
6382 -- if there is a pragma Import further down, it can
6383 -- clear any default initialization.
6385 Set_Initialization_Statements (U_Ent, Init_Call);
6389 -- Entity has delayed freeze, so we will generate an
6390 -- alignment check at the freeze point unless suppressed.
6392 if not Range_Checks_Suppressed (U_Ent)
6393 and then not Alignment_Checks_Suppressed (U_Ent)
6395 Set_Check_Address_Alignment (N);
6398 -- Kill the size check code, since we are not allocating
6399 -- the variable, it is somewhere else.
6401 Kill_Size_Check_Code (U_Ent);
6404 -- Not a valid entity for an address clause
6407 Error_Msg_N ("address cannot be given for &", Nam);
6415 -- Alignment attribute definition clause
6417 when Attribute_Alignment => Alignment : declare
6418 Align : constant Uint := Get_Alignment_Value (Expr);
6419 Max_Align : constant Uint := UI_From_Int (Maximum_Alignment);
6424 if not Is_Type (U_Ent)
6425 and then Ekind (U_Ent) /= E_Variable
6426 and then Ekind (U_Ent) /= E_Constant
6428 Error_Msg_N ("alignment cannot be given for &", Nam);
6430 elsif Duplicate_Clause then
6433 elsif Align /= No_Uint then
6434 Set_Has_Alignment_Clause (U_Ent);
6436 -- Tagged type case, check for attempt to set alignment to a
6437 -- value greater than Max_Align, and reset if so.
6439 if Is_Tagged_Type (U_Ent) and then Align > Max_Align then
6441 ("alignment for & set to Maximum_Aligment??", Nam);
6442 Set_Alignment (U_Ent, Max_Align);
6447 Set_Alignment (U_Ent, Align);
6450 -- For an array type, U_Ent is the first subtype. In that case,
6451 -- also set the alignment of the anonymous base type so that
6452 -- other subtypes (such as the itypes for aggregates of the
6453 -- type) also receive the expected alignment.
6455 if Is_Array_Type (U_Ent) then
6456 Set_Alignment (Base_Type (U_Ent), Align);
6465 -- Bit_Order attribute definition clause
6467 when Attribute_Bit_Order =>
6468 if not Is_Record_Type (U_Ent) then
6470 ("Bit_Order can only be defined for record type", Nam);
6472 elsif Is_Tagged_Type (U_Ent) and then Is_Derived_Type (U_Ent) then
6474 ("Bit_Order cannot be defined for record extensions", Nam);
6476 elsif Duplicate_Clause then
6480 Analyze_And_Resolve (Expr, RTE (RE_Bit_Order));
6482 if Etype (Expr) = Any_Type then
6485 elsif not Is_OK_Static_Expression (Expr) then
6486 Flag_Non_Static_Expr
6487 ("Bit_Order requires static expression!", Expr);
6489 elsif (Expr_Value (Expr) = 0) /= Bytes_Big_Endian then
6490 Set_Reverse_Bit_Order (Base_Type (U_Ent), True);
6494 --------------------
6495 -- Component_Size --
6496 --------------------
6498 -- Component_Size attribute definition clause
6500 when Attribute_Component_Size => Component_Size_Case : declare
6501 Csize : constant Uint := Static_Integer (Expr);
6505 New_Ctyp : Entity_Id;
6509 if not Is_Array_Type (U_Ent) then
6510 Error_Msg_N ("component size requires array type", Nam);
6514 Btype := Base_Type (U_Ent);
6515 Ctyp := Component_Type (Btype);
6517 if Duplicate_Clause then
6520 elsif Rep_Item_Too_Early (Btype, N) then
6523 elsif Csize /= No_Uint then
6524 Check_Size (Expr, Ctyp, Csize, Biased);
6526 -- For the biased case, build a declaration for a subtype that
6527 -- will be used to represent the biased subtype that reflects
6528 -- the biased representation of components. We need the subtype
6529 -- to get proper conversions on referencing elements of the
6534 Make_Defining_Identifier (Loc,
6536 New_External_Name (Chars (U_Ent), 'C', 0, 'T'));
6539 Make_Subtype_Declaration (Loc,
6540 Defining_Identifier => New_Ctyp,
6541 Subtype_Indication =>
6542 New_Occurrence_Of (Component_Type (Btype), Loc));
6544 Set_Parent (Decl, N);
6545 Analyze (Decl, Suppress => All_Checks);
6547 Set_Has_Delayed_Freeze (New_Ctyp, False);
6548 Init_Esize (New_Ctyp);
6549 Set_RM_Size (New_Ctyp, Csize);
6550 Init_Alignment (New_Ctyp);
6551 Set_Is_Itype (New_Ctyp, True);
6552 Set_Associated_Node_For_Itype (New_Ctyp, U_Ent);
6554 Set_Component_Type (Btype, New_Ctyp);
6555 Set_Biased (New_Ctyp, N, "component size clause");
6558 Set_Component_Size (Btype, Csize);
6560 -- Deal with warning on overridden size
6562 if Warn_On_Overridden_Size
6563 and then Has_Size_Clause (Ctyp)
6564 and then RM_Size (Ctyp) /= Csize
6567 ("component size overrides size clause for&?S?", N, Ctyp);
6570 Set_Has_Component_Size_Clause (Btype, True);
6571 Set_Has_Non_Standard_Rep (Btype, True);
6573 end Component_Size_Case;
6575 -----------------------
6576 -- Constant_Indexing --
6577 -----------------------
6579 when Attribute_Constant_Indexing =>
6580 Check_Indexing_Functions;
6586 when Attribute_CPU =>
6587 pragma Assert (From_Aspect_Specification (N));
6588 -- The parser forbids this clause in source code, so it must have
6589 -- come from an aspect specification.
6591 if not Is_Task_Type (U_Ent) then
6592 Error_Msg_N ("CPU can only be defined for task", Nam);
6594 elsif Duplicate_Clause then
6598 -- The expression must be analyzed in the special manner
6599 -- described in "Handling of Default and Per-Object
6600 -- Expressions" in sem.ads.
6602 -- The visibility to the components must be established
6603 -- and restored before and after analysis.
6606 Preanalyze_Spec_Expression (Expr, RTE (RE_CPU_Range));
6609 -- AI12-0117-1, "Restriction No_Tasks_Unassigned_To_CPU":
6610 -- If the expression is static, and its value is
6611 -- System.Multiprocessors.Not_A_Specific_CPU (i.e. zero) then
6612 -- that's a violation of No_Tasks_Unassigned_To_CPU. It might
6613 -- seem better to refer to Not_A_Specific_CPU here, but that
6614 -- involves a lot of horsing around with Rtsfind, and this
6615 -- value is not going to change, so it's better to hardwire
6618 -- AI12-0055-1, "All properties of a usage profile are defined
6619 -- by pragmas": If the expression is nonstatic, that's a
6620 -- violation of No_Dynamic_CPU_Assignment.
6622 if Is_OK_Static_Expression (Expr) then
6623 if Expr_Value (Expr) = Uint_0 then
6624 Check_Restriction (No_Tasks_Unassigned_To_CPU, Expr);
6627 Check_Restriction (No_Dynamic_CPU_Assignment, Expr);
6631 ----------------------
6632 -- Default_Iterator --
6633 ----------------------
6635 when Attribute_Default_Iterator => Default_Iterator : declare
6640 -- If target type is untagged, further checks are irrelevant
6642 if not Is_Tagged_Type (U_Ent) then
6644 ("aspect Default_Iterator applies to tagged type", Nam);
6648 Check_Iterator_Functions;
6652 if not Is_Entity_Name (Expr)
6653 or else Ekind (Entity (Expr)) /= E_Function
6655 Error_Msg_N ("aspect Iterator must be a function", Expr);
6658 Func := Entity (Expr);
6661 -- The type of the first parameter must be T, T'class, or a
6662 -- corresponding access type (5.5.1 (8/3). If function is
6663 -- parameterless label type accordingly.
6665 if No (First_Formal (Func)) then
6668 Typ := Etype (First_Formal (Func));
6672 or else Typ = Class_Wide_Type (U_Ent)
6673 or else (Is_Access_Type (Typ)
6674 and then Designated_Type (Typ) = U_Ent)
6675 or else (Is_Access_Type (Typ)
6676 and then Designated_Type (Typ) =
6677 Class_Wide_Type (U_Ent))
6683 ("Default Iterator must be a primitive of&", Func, U_Ent);
6685 end Default_Iterator;
6687 ------------------------
6688 -- Dispatching_Domain --
6689 ------------------------
6691 when Attribute_Dispatching_Domain =>
6692 pragma Assert (From_Aspect_Specification (N));
6693 -- The parser forbids this clause in source code, so it must have
6694 -- come from an aspect specification.
6696 if not Is_Task_Type (U_Ent) then
6698 ("Dispatching_Domain can only be defined for task", Nam);
6700 elsif Duplicate_Clause then
6704 -- The expression must be analyzed in the special manner
6705 -- described in "Handling of Default and Per-Object
6706 -- Expressions" in sem.ads.
6708 -- The visibility to the components must be restored
6712 Preanalyze_Spec_Expression
6713 (Expr, RTE (RE_Dispatching_Domain));
6722 when Attribute_External_Tag =>
6723 if not Is_Tagged_Type (U_Ent) then
6724 Error_Msg_N ("should be a tagged type", Nam);
6727 if Duplicate_Clause then
6731 Analyze_And_Resolve (Expr, Standard_String);
6733 if not Is_OK_Static_Expression (Expr) then
6734 Flag_Non_Static_Expr
6735 ("static string required for tag name!", Nam);
6738 if not Is_Library_Level_Entity (U_Ent) then
6740 ("??non-unique external tag supplied for &", N, U_Ent);
6742 ("\??same external tag applies to all subprogram calls",
6745 ("\??corresponding internal tag cannot be obtained", N);
6749 --------------------------
6750 -- Implicit_Dereference --
6751 --------------------------
6753 when Attribute_Implicit_Dereference =>
6755 -- Legality checks already performed at the point of the type
6756 -- declaration, aspect is not delayed.
6764 when Attribute_Input =>
6765 Analyze_Stream_TSS_Definition (TSS_Stream_Input);
6766 Set_Has_Specified_Stream_Input (Ent);
6768 ------------------------
6769 -- Interrupt_Priority --
6770 ------------------------
6772 when Attribute_Interrupt_Priority =>
6773 pragma Assert (From_Aspect_Specification (N));
6774 -- The parser forbids this clause in source code, so it must have
6775 -- come from an aspect specification.
6777 if not Is_Concurrent_Type (U_Ent) then
6779 ("Interrupt_Priority can only be defined for task and "
6780 & "protected object", Nam);
6782 elsif Duplicate_Clause then
6786 -- The expression must be analyzed in the special manner
6787 -- described in "Handling of Default and Per-Object
6788 -- Expressions" in sem.ads.
6790 -- The visibility to the components must be restored
6794 Preanalyze_Spec_Expression
6795 (Expr, RTE (RE_Interrupt_Priority));
6799 -- Check the No_Task_At_Interrupt_Priority restriction
6801 if Is_Task_Type (U_Ent) then
6802 Check_Restriction (No_Task_At_Interrupt_Priority, N);
6810 when Attribute_Iterable =>
6813 if Nkind (Expr) /= N_Aggregate then
6814 Error_Msg_N ("aspect Iterable must be an aggregate", Expr);
6821 Assoc := First (Component_Associations (Expr));
6822 while Present (Assoc) loop
6823 Analyze (Expression (Assoc));
6825 if not Is_Entity_Name (Expression (Assoc)) then
6826 Error_Msg_N ("value must be a function", Assoc);
6833 ----------------------
6834 -- Iterator_Element --
6835 ----------------------
6837 when Attribute_Iterator_Element =>
6840 if not Is_Entity_Name (Expr)
6841 or else not Is_Type (Entity (Expr))
6843 Error_Msg_N ("aspect Iterator_Element must be a type", Expr);
6851 -- Machine radix attribute definition clause
6853 when Attribute_Machine_Radix => Machine_Radix : declare
6854 Radix : constant Uint := Static_Integer (Expr);
6857 if not Is_Decimal_Fixed_Point_Type (U_Ent) then
6858 Error_Msg_N ("decimal fixed-point type expected for &", Nam);
6860 elsif Duplicate_Clause then
6863 elsif Radix /= No_Uint then
6864 Set_Has_Machine_Radix_Clause (U_Ent);
6865 Set_Has_Non_Standard_Rep (Base_Type (U_Ent));
6870 elsif Radix = 10 then
6871 Set_Machine_Radix_10 (U_Ent);
6874 Error_Msg_N ("machine radix value must be 2 or 10", Expr);
6883 -- Object_Size attribute definition clause
6885 when Attribute_Object_Size => Object_Size : declare
6886 Size : constant Uint := Static_Integer (Expr);
6889 pragma Warnings (Off, Biased);
6892 if not Is_Type (U_Ent) then
6893 Error_Msg_N ("Object_Size cannot be given for &", Nam);
6895 elsif Duplicate_Clause then
6899 Check_Size (Expr, U_Ent, Size, Biased);
6902 Error_Msg_N ("Object_Size must be positive", Expr);
6904 elsif Is_Scalar_Type (U_Ent) then
6905 if Size /= 8 and then Size /= 16 and then Size /= 32
6906 and then UI_Mod (Size, 64) /= 0
6909 ("Object_Size must be 8, 16, 32, or multiple of 64",
6913 elsif Size mod 8 /= 0 then
6914 Error_Msg_N ("Object_Size must be a multiple of 8", Expr);
6917 Set_Esize (U_Ent, Size);
6918 Set_Has_Object_Size_Clause (U_Ent);
6919 Alignment_Check_For_Size_Change (U_Ent, Size);
6927 when Attribute_Output =>
6928 Analyze_Stream_TSS_Definition (TSS_Stream_Output);
6929 Set_Has_Specified_Stream_Output (Ent);
6935 when Attribute_Priority =>
6937 -- Priority attribute definition clause not allowed except from
6938 -- aspect specification.
6940 if From_Aspect_Specification (N) then
6941 if not (Is_Concurrent_Type (U_Ent)
6942 or else Ekind (U_Ent) = E_Procedure)
6945 ("Priority can only be defined for task and protected "
6948 elsif Duplicate_Clause then
6952 -- The expression must be analyzed in the special manner
6953 -- described in "Handling of Default and Per-Object
6954 -- Expressions" in sem.ads.
6956 -- The visibility to the components must be restored
6959 Preanalyze_Spec_Expression (Expr, Standard_Integer);
6962 if not Is_OK_Static_Expression (Expr) then
6963 Check_Restriction (Static_Priorities, Expr);
6969 ("attribute& cannot be set with definition clause", N);
6976 when Attribute_Put_Image =>
6977 Analyze_Put_Image_TSS_Definition;
6983 when Attribute_Read =>
6984 Analyze_Stream_TSS_Definition (TSS_Stream_Read);
6985 Set_Has_Specified_Stream_Read (Ent);
6987 --------------------------
6988 -- Scalar_Storage_Order --
6989 --------------------------
6991 -- Scalar_Storage_Order attribute definition clause
6993 when Attribute_Scalar_Storage_Order =>
6994 if not (Is_Record_Type (U_Ent) or else Is_Array_Type (U_Ent)) then
6996 ("Scalar_Storage_Order can only be defined for record or "
6997 & "array type", Nam);
6999 elsif Duplicate_Clause then
7003 Analyze_And_Resolve (Expr, RTE (RE_Bit_Order));
7005 if Etype (Expr) = Any_Type then
7008 elsif not Is_OK_Static_Expression (Expr) then
7009 Flag_Non_Static_Expr
7010 ("Scalar_Storage_Order requires static expression!", Expr);
7012 elsif (Expr_Value (Expr) = 0) /= Bytes_Big_Endian then
7014 -- Here for the case of a non-default (i.e. non-confirming)
7015 -- Scalar_Storage_Order attribute definition.
7017 if Support_Nondefault_SSO_On_Target then
7018 Set_Reverse_Storage_Order (Base_Type (U_Ent), True);
7021 ("non-default Scalar_Storage_Order not supported on "
7026 -- Clear SSO default indications since explicit setting of the
7027 -- order overrides the defaults.
7029 Set_SSO_Set_Low_By_Default (Base_Type (U_Ent), False);
7030 Set_SSO_Set_High_By_Default (Base_Type (U_Ent), False);
7037 -- Size attribute definition clause
7039 when Attribute_Size => Size : declare
7040 Size : constant Uint := Static_Integer (Expr);
7047 if Duplicate_Clause then
7050 elsif not Is_Type (U_Ent)
7051 and then Ekind (U_Ent) /= E_Variable
7052 and then Ekind (U_Ent) /= E_Constant
7054 Error_Msg_N ("size cannot be given for &", Nam);
7056 elsif Is_Array_Type (U_Ent)
7057 and then not Is_Constrained (U_Ent)
7060 ("size cannot be given for unconstrained array", Nam);
7062 elsif Size /= No_Uint then
7063 if Is_Type (U_Ent) then
7066 Etyp := Etype (U_Ent);
7069 -- Check size, note that Gigi is in charge of checking that the
7070 -- size of an array or record type is OK. Also we do not check
7071 -- the size in the ordinary fixed-point case, since it is too
7072 -- early to do so (there may be subsequent small clause that
7073 -- affects the size). We can check the size if a small clause
7074 -- has already been given.
7076 if not Is_Ordinary_Fixed_Point_Type (U_Ent)
7077 or else Has_Small_Clause (U_Ent)
7079 Check_Size (Expr, Etyp, Size, Biased);
7080 Set_Biased (U_Ent, N, "size clause", Biased);
7083 -- For types set RM_Size and Esize if possible
7085 if Is_Type (U_Ent) then
7086 Set_RM_Size (U_Ent, Size);
7088 -- For elementary types, increase Object_Size to power of 2,
7089 -- but not less than a storage unit in any case (normally
7090 -- this means it will be byte addressable).
7092 -- For all other types, nothing else to do, we leave Esize
7093 -- (object size) unset, the back end will set it from the
7094 -- size and alignment in an appropriate manner.
7096 -- In both cases, we check whether the alignment must be
7097 -- reset in the wake of the size change.
7099 if Is_Elementary_Type (U_Ent) then
7100 if Size <= System_Storage_Unit then
7101 Init_Esize (U_Ent, System_Storage_Unit);
7102 elsif Size <= 16 then
7103 Init_Esize (U_Ent, 16);
7104 elsif Size <= 32 then
7105 Init_Esize (U_Ent, 32);
7107 Set_Esize (U_Ent, (Size + 63) / 64 * 64);
7110 Alignment_Check_For_Size_Change (U_Ent, Esize (U_Ent));
7112 Alignment_Check_For_Size_Change (U_Ent, Size);
7115 -- For objects, set Esize only
7118 if Is_Elementary_Type (Etyp)
7119 and then Size /= System_Storage_Unit
7123 and then Size /= System_Max_Integer_Size
7125 Error_Msg_Uint_1 := UI_From_Int (System_Storage_Unit);
7126 Error_Msg_Uint_2 := UI_From_Int (System_Max_Integer_Size);
7128 ("size for primitive object must be a power of 2 in "
7129 & "the range ^-^", N);
7132 Set_Esize (U_Ent, Size);
7135 Set_Has_Size_Clause (U_Ent);
7143 -- Small attribute definition clause
7145 when Attribute_Small => Small : declare
7146 Implicit_Base : constant Entity_Id := Base_Type (U_Ent);
7150 Analyze_And_Resolve (Expr, Any_Real);
7152 if Etype (Expr) = Any_Type then
7155 elsif not Is_OK_Static_Expression (Expr) then
7156 Flag_Non_Static_Expr
7157 ("small requires static expression!", Expr);
7161 Small := Expr_Value_R (Expr);
7163 if Small <= Ureal_0 then
7164 Error_Msg_N ("small value must be greater than zero", Expr);
7170 if not Is_Ordinary_Fixed_Point_Type (U_Ent) then
7172 ("small requires an ordinary fixed point type", Nam);
7174 elsif Has_Small_Clause (U_Ent) then
7175 Error_Msg_N ("small already given for &", Nam);
7177 elsif Small > Delta_Value (U_Ent) then
7179 ("small value must not be greater than delta value", Nam);
7182 Set_Small_Value (U_Ent, Small);
7183 Set_Small_Value (Implicit_Base, Small);
7184 Set_Has_Small_Clause (U_Ent);
7185 Set_Has_Small_Clause (Implicit_Base);
7186 Set_Has_Non_Standard_Rep (Implicit_Base);
7194 -- Storage_Pool attribute definition clause
7196 when Attribute_Simple_Storage_Pool
7197 | Attribute_Storage_Pool
7199 Storage_Pool : declare
7203 procedure Associate_Storage_Pool
7204 (Ent : Entity_Id; Pool : Entity_Id);
7205 -- Associate Pool to Ent and perform legality checks on subpools
7207 ----------------------------
7208 -- Associate_Storage_Pool --
7209 ----------------------------
7211 procedure Associate_Storage_Pool
7212 (Ent : Entity_Id; Pool : Entity_Id)
7214 function Object_From (Pool : Entity_Id) return Entity_Id;
7215 -- Return the entity of which Pool is a part of
7221 function Object_From
7222 (Pool : Entity_Id) return Entity_Id
7224 N : Node_Id := Pool;
7226 if Present (Renamed_Object (Pool)) then
7227 N := Renamed_Object (Pool);
7230 while Present (N) loop
7232 when N_Defining_Identifier =>
7235 when N_Identifier | N_Expanded_Name =>
7238 when N_Indexed_Component | N_Selected_Component |
7239 N_Explicit_Dereference
7243 when N_Type_Conversion =>
7244 N := Expression (N);
7247 -- ??? we probably should handle more cases but
7248 -- this is good enough in practice for this check
7249 -- on a corner case.
7261 Set_Associated_Storage_Pool (Ent, Pool);
7263 -- Check RM 13.11.4(22-23/3): a specification of a storage pool
7264 -- is illegal if the storage pool supports subpools and:
7265 -- (A) The access type is a general access type.
7266 -- (B) The access type is statically deeper than the storage
7268 -- (C) The storage pool object is a part of a formal parameter;
7269 -- (D) The storage pool object is a part of the dereference of
7270 -- a non-library level general access type;
7272 if Ada_Version >= Ada_2012
7273 and then RTU_Loaded (System_Storage_Pools_Subpools)
7275 Is_Ancestor (RTE (RE_Root_Storage_Pool_With_Subpools),
7280 if Ekind (Etype (Ent)) = E_General_Access_Type then
7282 ("subpool cannot be used on general access type", Ent);
7287 if Type_Access_Level (Ent)
7288 > Static_Accessibility_Level
7289 (Pool, Object_Decl_Level)
7292 ("subpool access type has deeper accessibility "
7293 & "level than pool", Ent);
7297 Obj := Object_From (Pool);
7301 if Present (Obj) and then Is_Formal (Obj) then
7303 ("subpool cannot be part of a parameter", Ent);
7310 and then Ekind (Etype (Obj)) = E_General_Access_Type
7311 and then not Is_Library_Level_Entity (Etype (Obj))
7314 ("subpool cannot be part of the dereference of a " &
7315 "nested general access type", Ent);
7319 end Associate_Storage_Pool;
7322 if Ekind (U_Ent) = E_Access_Subprogram_Type then
7324 ("storage pool cannot be given for access-to-subprogram type",
7328 elsif Ekind (U_Ent) not in E_Access_Type | E_General_Access_Type
7331 ("storage pool can only be given for access types", Nam);
7334 elsif Is_Derived_Type (U_Ent) then
7336 ("storage pool cannot be given for a derived access type",
7339 elsif Duplicate_Clause then
7342 elsif Present (Associated_Storage_Pool (U_Ent)) then
7343 Error_Msg_N ("storage pool already given for &", Nam);
7347 -- Check for Storage_Size previously given
7350 SS : constant Node_Id :=
7351 Get_Attribute_Definition_Clause
7352 (U_Ent, Attribute_Storage_Size);
7354 if Present (SS) then
7355 Check_Pool_Size_Clash (U_Ent, N, SS);
7359 -- Storage_Pool case
7361 if Id = Attribute_Storage_Pool then
7363 (Expr, Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
7365 -- In the Simple_Storage_Pool case, we allow a variable of any
7366 -- simple storage pool type, so we Resolve without imposing an
7370 Analyze_And_Resolve (Expr);
7372 if not Present (Get_Rep_Pragma
7373 (Etype (Expr), Name_Simple_Storage_Pool_Type))
7376 ("expression must be of a simple storage pool type", Expr);
7380 if not Denotes_Variable (Expr) then
7381 Error_Msg_N ("storage pool must be a variable", Expr);
7385 if Nkind (Expr) = N_Type_Conversion then
7386 T := Etype (Expression (Expr));
7391 -- The Stack_Bounded_Pool is used internally for implementing
7392 -- access types with a Storage_Size. Since it only work properly
7393 -- when used on one specific type, we need to check that it is not
7394 -- hijacked improperly:
7396 -- type T is access Integer;
7397 -- for T'Storage_Size use n;
7398 -- type Q is access Float;
7399 -- for Q'Storage_Size use T'Storage_Size; -- incorrect
7401 if RTE_Available (RE_Stack_Bounded_Pool)
7402 and then Base_Type (T) = RTE (RE_Stack_Bounded_Pool)
7404 Error_Msg_N ("non-shareable internal Pool", Expr);
7408 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
7409 -- Storage_Pool since this attribute cannot be defined for such
7410 -- types (RM E.2.2(17)).
7412 Validate_Remote_Access_To_Class_Wide_Type (N);
7414 -- If the argument is a name that is not an entity name, then
7415 -- we construct a renaming operation to define an entity of
7416 -- type storage pool.
7418 if not Is_Entity_Name (Expr)
7419 and then Is_Object_Reference (Expr)
7421 Pool := Make_Temporary (Loc, 'P', Expr);
7424 Rnode : constant Node_Id :=
7425 Make_Object_Renaming_Declaration (Loc,
7426 Defining_Identifier => Pool,
7428 New_Occurrence_Of (Etype (Expr), Loc),
7432 -- If the attribute definition clause comes from an aspect
7433 -- clause, then insert the renaming before the associated
7434 -- entity's declaration, since the attribute clause has
7435 -- not yet been appended to the declaration list.
7437 if From_Aspect_Specification (N) then
7438 Insert_Before (Parent (Entity (N)), Rnode);
7440 Insert_Before (N, Rnode);
7444 Associate_Storage_Pool (U_Ent, Pool);
7447 elsif Is_Entity_Name (Expr) then
7448 Pool := Entity (Expr);
7450 -- If pool is a renamed object, get original one. This can
7451 -- happen with an explicit renaming, and within instances.
7453 while Present (Renamed_Object (Pool))
7454 and then Is_Entity_Name (Renamed_Object (Pool))
7456 Pool := Entity (Renamed_Object (Pool));
7459 if Present (Renamed_Object (Pool))
7460 and then Nkind (Renamed_Object (Pool)) = N_Type_Conversion
7461 and then Is_Entity_Name (Expression (Renamed_Object (Pool)))
7463 Pool := Entity (Expression (Renamed_Object (Pool)));
7466 Associate_Storage_Pool (U_Ent, Pool);
7468 elsif Nkind (Expr) = N_Type_Conversion
7469 and then Is_Entity_Name (Expression (Expr))
7470 and then Nkind (Original_Node (Expr)) = N_Attribute_Reference
7472 Pool := Entity (Expression (Expr));
7473 Associate_Storage_Pool (U_Ent, Pool);
7476 Error_Msg_N ("incorrect reference to a Storage Pool", Expr);
7485 -- Storage_Size attribute definition clause
7487 when Attribute_Storage_Size => Storage_Size : declare
7488 Btype : constant Entity_Id := Base_Type (U_Ent);
7491 if Is_Task_Type (U_Ent) then
7493 -- Check obsolescent (but never obsolescent if from aspect)
7495 if not From_Aspect_Specification (N) then
7496 Check_Restriction (No_Obsolescent_Features, N);
7498 if Warn_On_Obsolescent_Feature then
7500 ("?j?storage size clause for task is an obsolescent "
7501 & "feature (RM J.9)", N);
7502 Error_Msg_N ("\?j?use Storage_Size pragma instead", N);
7509 if not Is_Access_Type (U_Ent)
7510 and then Ekind (U_Ent) /= E_Task_Type
7512 Error_Msg_N ("storage size cannot be given for &", Nam);
7514 elsif Is_Access_Type (U_Ent) and Is_Derived_Type (U_Ent) then
7516 ("storage size cannot be given for a derived access type",
7519 elsif Duplicate_Clause then
7523 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
7524 -- Storage_Size since this attribute cannot be defined for such
7525 -- types (RM E.2.2(17)).
7527 Validate_Remote_Access_To_Class_Wide_Type (N);
7529 Analyze_And_Resolve (Expr, Any_Integer);
7531 if Is_Access_Type (U_Ent) then
7533 -- Check for Storage_Pool previously given
7536 SP : constant Node_Id :=
7537 Get_Attribute_Definition_Clause
7538 (U_Ent, Attribute_Storage_Pool);
7541 if Present (SP) then
7542 Check_Pool_Size_Clash (U_Ent, SP, N);
7546 -- Special case of for x'Storage_Size use 0
7548 if Is_OK_Static_Expression (Expr)
7549 and then Expr_Value (Expr) = 0
7551 Set_No_Pool_Assigned (Btype);
7555 Set_Has_Storage_Size_Clause (Btype);
7563 when Attribute_Stream_Size => Stream_Size : declare
7564 Size : constant Uint := Static_Integer (Expr);
7567 if Ada_Version <= Ada_95 then
7568 Check_Restriction (No_Implementation_Attributes, N);
7571 if Duplicate_Clause then
7574 elsif Is_Elementary_Type (U_Ent) then
7575 if Size /= System_Storage_Unit
7576 and then Size /= System_Storage_Unit * 2
7577 and then Size /= System_Storage_Unit * 3
7578 and then Size /= System_Storage_Unit * 4
7579 and then Size /= System_Storage_Unit * 8
7582 ("stream size for elementary type must be 8, 16, 24, " &
7585 elsif RM_Size (U_Ent) > Size then
7586 Error_Msg_Uint_1 := RM_Size (U_Ent);
7588 ("stream size for elementary type must be 8, 16, 24, " &
7589 "32 or 64 and at least ^", N);
7592 Set_Has_Stream_Size_Clause (U_Ent);
7595 Error_Msg_N ("Stream_Size cannot be given for &", Nam);
7603 -- Value_Size attribute definition clause
7605 when Attribute_Value_Size => Value_Size : declare
7606 Size : constant Uint := Static_Integer (Expr);
7610 if not Is_Type (U_Ent) then
7611 Error_Msg_N ("Value_Size cannot be given for &", Nam);
7613 elsif Duplicate_Clause then
7616 elsif Is_Array_Type (U_Ent)
7617 and then not Is_Constrained (U_Ent)
7620 ("Value_Size cannot be given for unconstrained array", Nam);
7623 if Is_Elementary_Type (U_Ent) then
7624 Check_Size (Expr, U_Ent, Size, Biased);
7625 Set_Biased (U_Ent, N, "value size clause", Biased);
7628 Set_RM_Size (U_Ent, Size);
7632 -----------------------
7633 -- Variable_Indexing --
7634 -----------------------
7636 when Attribute_Variable_Indexing =>
7637 Check_Indexing_Functions;
7643 when Attribute_Write =>
7644 Analyze_Stream_TSS_Definition (TSS_Stream_Write);
7645 Set_Has_Specified_Stream_Write (Ent);
7647 -- All other attributes cannot be set
7651 ("attribute& cannot be set with definition clause", N);
7654 -- The test for the type being frozen must be performed after any
7655 -- expression the clause has been analyzed since the expression itself
7656 -- might cause freezing that makes the clause illegal.
7658 if Rep_Item_Too_Late (U_Ent, N, FOnly) then
7661 end Analyze_Attribute_Definition_Clause;
7663 ----------------------------
7664 -- Analyze_Code_Statement --
7665 ----------------------------
7667 procedure Analyze_Code_Statement (N : Node_Id) is
7668 HSS : constant Node_Id := Parent (N);
7669 SBody : constant Node_Id := Parent (HSS);
7670 Subp : constant Entity_Id := Current_Scope;
7677 -- Accept foreign code statements for CodePeer. The analysis is skipped
7678 -- to avoid rejecting unrecognized constructs.
7680 if CodePeer_Mode then
7685 -- Analyze and check we get right type, note that this implements the
7686 -- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that is
7687 -- the only way that Asm_Insn could possibly be visible.
7689 Analyze_And_Resolve (Expression (N));
7691 if Etype (Expression (N)) = Any_Type then
7693 elsif Etype (Expression (N)) /= RTE (RE_Asm_Insn) then
7694 Error_Msg_N ("incorrect type for code statement", N);
7698 Check_Code_Statement (N);
7700 -- Make sure we appear in the handled statement sequence of a subprogram
7703 if Nkind (HSS) /= N_Handled_Sequence_Of_Statements
7704 or else Nkind (SBody) /= N_Subprogram_Body
7707 ("code statement can only appear in body of subprogram", N);
7711 -- Do remaining checks (RM 13.8(3)) if not already done
7713 if not Is_Machine_Code_Subprogram (Subp) then
7714 Set_Is_Machine_Code_Subprogram (Subp);
7716 -- No exception handlers allowed
7718 if Present (Exception_Handlers (HSS)) then
7720 ("exception handlers not permitted in machine code subprogram",
7721 First (Exception_Handlers (HSS)));
7724 -- No declarations other than use clauses and pragmas (we allow
7725 -- certain internally generated declarations as well).
7727 Decl := First (Declarations (SBody));
7728 while Present (Decl) loop
7729 DeclO := Original_Node (Decl);
7730 if Comes_From_Source (DeclO)
7731 and Nkind (DeclO) not in N_Pragma
7732 | N_Use_Package_Clause
7734 | N_Implicit_Label_Declaration
7737 ("this declaration not allowed in machine code subprogram",
7744 -- No statements other than code statements, pragmas, and labels.
7745 -- Again we allow certain internally generated statements.
7747 -- In Ada 2012, qualified expressions are names, and the code
7748 -- statement is initially parsed as a procedure call.
7750 Stmt := First (Statements (HSS));
7751 while Present (Stmt) loop
7752 StmtO := Original_Node (Stmt);
7754 -- A procedure call transformed into a code statement is OK
7756 if Ada_Version >= Ada_2012
7757 and then Nkind (StmtO) = N_Procedure_Call_Statement
7758 and then Nkind (Name (StmtO)) = N_Qualified_Expression
7762 elsif Comes_From_Source (StmtO)
7763 and then Nkind (StmtO) not in
7764 N_Pragma | N_Label | N_Code_Statement
7767 ("this statement is not allowed in machine code subprogram",
7774 end Analyze_Code_Statement;
7776 -----------------------------------------------
7777 -- Analyze_Enumeration_Representation_Clause --
7778 -----------------------------------------------
7780 procedure Analyze_Enumeration_Representation_Clause (N : Node_Id) is
7781 Ident : constant Node_Id := Identifier (N);
7782 Aggr : constant Node_Id := Array_Aggregate (N);
7783 Enumtype : Entity_Id;
7790 Err : Boolean := False;
7791 -- Set True to avoid cascade errors and crashes on incorrect source code
7793 Lo : constant Uint := Expr_Value (Type_Low_Bound (Universal_Integer));
7794 Hi : constant Uint := Expr_Value (Type_High_Bound (Universal_Integer));
7795 -- Allowed range of universal integer (= allowed range of enum lit vals)
7799 -- Minimum and maximum values of entries
7801 Max_Node : Node_Id := Empty; -- init to avoid warning
7802 -- Pointer to node for literal providing max value
7805 if Ignore_Rep_Clauses then
7806 Kill_Rep_Clause (N);
7810 -- Ignore enumeration rep clauses by default in CodePeer mode,
7811 -- unless -gnatd.I is specified, as a work around for potential false
7812 -- positive messages.
7814 if CodePeer_Mode and not Debug_Flag_Dot_II then
7818 -- First some basic error checks
7821 Enumtype := Entity (Ident);
7823 if Enumtype = Any_Type
7824 or else Rep_Item_Too_Early (Enumtype, N)
7828 Enumtype := Underlying_Type (Enumtype);
7831 if not Is_Enumeration_Type (Enumtype) then
7833 ("enumeration type required, found}",
7834 Ident, First_Subtype (Enumtype));
7838 -- Ignore rep clause on generic actual type. This will already have
7839 -- been flagged on the template as an error, and this is the safest
7840 -- way to ensure we don't get a junk cascaded message in the instance.
7842 if Is_Generic_Actual_Type (Enumtype) then
7845 -- Type must be in current scope
7847 elsif Scope (Enumtype) /= Current_Scope then
7848 Error_Msg_N ("type must be declared in this scope", Ident);
7851 -- Type must be a first subtype
7853 elsif not Is_First_Subtype (Enumtype) then
7854 Error_Msg_N ("cannot give enumeration rep clause for subtype", N);
7857 -- Ignore duplicate rep clause
7859 elsif Has_Enumeration_Rep_Clause (Enumtype) then
7860 Error_Msg_N ("duplicate enumeration rep clause ignored", N);
7863 -- Don't allow rep clause for standard [wide_[wide_]]character
7865 elsif Is_Standard_Character_Type (Enumtype) then
7866 Error_Msg_N ("enumeration rep clause not allowed for this type", N);
7869 -- Check that the expression is a proper aggregate (no parentheses)
7871 elsif Paren_Count (Aggr) /= 0 then
7873 ("extra parentheses surrounding aggregate not allowed",
7877 -- All tests passed, so set rep clause in place
7880 Set_Has_Enumeration_Rep_Clause (Enumtype);
7881 Set_Has_Enumeration_Rep_Clause (Base_Type (Enumtype));
7884 -- Now we process the aggregate. Note that we don't use the normal
7885 -- aggregate code for this purpose, because we don't want any of the
7886 -- normal expansion activities, and a number of special semantic
7887 -- rules apply (including the component type being any integer type)
7889 Elit := First_Literal (Enumtype);
7891 -- First the positional entries if any
7893 if Present (Expressions (Aggr)) then
7894 Expr := First (Expressions (Aggr));
7895 while Present (Expr) loop
7897 Error_Msg_N ("too many entries in aggregate", Expr);
7901 Val := Static_Integer (Expr);
7903 -- Err signals that we found some incorrect entries processing
7904 -- the list. The final checks for completeness and ordering are
7905 -- skipped in this case.
7907 if Val = No_Uint then
7910 elsif Val < Lo or else Hi < Val then
7911 Error_Msg_N ("value outside permitted range", Expr);
7915 Set_Enumeration_Rep (Elit, Val);
7916 Set_Enumeration_Rep_Expr (Elit, Expr);
7922 -- Now process the named entries if present
7924 if Present (Component_Associations (Aggr)) then
7925 Assoc := First (Component_Associations (Aggr));
7926 while Present (Assoc) loop
7927 Choice := First (Choices (Assoc));
7929 if Present (Next (Choice)) then
7931 ("multiple choice not allowed here", Next (Choice));
7935 if Nkind (Choice) = N_Others_Choice then
7936 Error_Msg_N ("others choice not allowed here", Choice);
7939 elsif Nkind (Choice) = N_Range then
7941 -- ??? should allow zero/one element range here
7943 Error_Msg_N ("range not allowed here", Choice);
7947 Analyze_And_Resolve (Choice, Enumtype);
7949 if Error_Posted (Choice) then
7954 if Is_Entity_Name (Choice)
7955 and then Is_Type (Entity (Choice))
7957 Error_Msg_N ("subtype name not allowed here", Choice);
7960 -- ??? should allow static subtype with zero/one entry
7962 elsif Etype (Choice) = Base_Type (Enumtype) then
7963 if not Is_OK_Static_Expression (Choice) then
7964 Flag_Non_Static_Expr
7965 ("non-static expression used for choice!", Choice);
7969 Elit := Expr_Value_E (Choice);
7971 if Present (Enumeration_Rep_Expr (Elit)) then
7973 Sloc (Enumeration_Rep_Expr (Elit));
7975 ("representation for& previously given#",
7980 Set_Enumeration_Rep_Expr (Elit, Expression (Assoc));
7982 Expr := Expression (Assoc);
7983 Val := Static_Integer (Expr);
7985 if Val = No_Uint then
7988 elsif Val < Lo or else Hi < Val then
7989 Error_Msg_N ("value outside permitted range", Expr);
7993 Set_Enumeration_Rep (Elit, Val);
8003 -- Aggregate is fully processed. Now we check that a full set of
8004 -- representations was given, and that they are in range and in order.
8005 -- These checks are only done if no other errors occurred.
8011 Elit := First_Literal (Enumtype);
8012 while Present (Elit) loop
8013 if No (Enumeration_Rep_Expr (Elit)) then
8014 Error_Msg_NE ("missing representation for&!", N, Elit);
8017 Val := Enumeration_Rep (Elit);
8019 if Min = No_Uint then
8023 if Val /= No_Uint then
8024 if Max /= No_Uint and then Val <= Max then
8026 ("enumeration value for& not ordered!",
8027 Enumeration_Rep_Expr (Elit), Elit);
8030 Max_Node := Enumeration_Rep_Expr (Elit);
8034 -- If there is at least one literal whose representation is not
8035 -- equal to the Pos value, then note that this enumeration type
8036 -- has a non-standard representation.
8038 if Val /= Enumeration_Pos (Elit) then
8039 Set_Has_Non_Standard_Rep (Base_Type (Enumtype));
8046 -- Now set proper size information
8049 Minsize : Uint := UI_From_Int (Minimum_Size (Enumtype));
8052 if Has_Size_Clause (Enumtype) then
8054 -- All OK, if size is OK now
8056 if RM_Size (Enumtype) >= Minsize then
8060 -- Try if we can get by with biasing
8063 UI_From_Int (Minimum_Size (Enumtype, Biased => True));
8065 -- Error message if even biasing does not work
8067 if RM_Size (Enumtype) < Minsize then
8068 Error_Msg_Uint_1 := RM_Size (Enumtype);
8069 Error_Msg_Uint_2 := Max;
8071 ("previously given size (^) is too small "
8072 & "for this value (^)", Max_Node);
8074 -- If biasing worked, indicate that we now have biased rep
8078 (Enumtype, Size_Clause (Enumtype), "size clause");
8083 Set_RM_Size (Enumtype, Minsize);
8084 Set_Enum_Esize (Enumtype);
8087 Set_RM_Size (Base_Type (Enumtype), RM_Size (Enumtype));
8088 Set_Esize (Base_Type (Enumtype), Esize (Enumtype));
8089 Set_Alignment (Base_Type (Enumtype), Alignment (Enumtype));
8093 -- We repeat the too late test in case it froze itself
8095 if Rep_Item_Too_Late (Enumtype, N) then
8098 end Analyze_Enumeration_Representation_Clause;
8100 ----------------------------
8101 -- Analyze_Free_Statement --
8102 ----------------------------
8104 procedure Analyze_Free_Statement (N : Node_Id) is
8106 Analyze (Expression (N));
8107 end Analyze_Free_Statement;
8109 ---------------------------
8110 -- Analyze_Freeze_Entity --
8111 ---------------------------
8113 procedure Analyze_Freeze_Entity (N : Node_Id) is
8115 Freeze_Entity_Checks (N);
8116 end Analyze_Freeze_Entity;
8118 -----------------------------------
8119 -- Analyze_Freeze_Generic_Entity --
8120 -----------------------------------
8122 procedure Analyze_Freeze_Generic_Entity (N : Node_Id) is
8123 E : constant Entity_Id := Entity (N);
8126 if not Is_Frozen (E) and then Has_Delayed_Aspects (E) then
8127 Analyze_Aspects_At_Freeze_Point (E);
8130 Freeze_Entity_Checks (N);
8131 end Analyze_Freeze_Generic_Entity;
8133 ------------------------------------------
8134 -- Analyze_Record_Representation_Clause --
8135 ------------------------------------------
8137 -- Note: we check as much as we can here, but we can't do any checks
8138 -- based on the position values (e.g. overlap checks) until freeze time
8139 -- because especially in Ada 2005 (machine scalar mode), the processing
8140 -- for non-standard bit order can substantially change the positions.
8141 -- See procedure Check_Record_Representation_Clause (called from Freeze)
8142 -- for the remainder of this processing.
8144 procedure Analyze_Record_Representation_Clause (N : Node_Id) is
8145 Ident : constant Node_Id := Identifier (N);
8153 Rectype : Entity_Id;
8156 function Is_Inherited (Comp : Entity_Id) return Boolean;
8157 -- True if Comp is an inherited component in a record extension
8163 function Is_Inherited (Comp : Entity_Id) return Boolean is
8164 Comp_Base : Entity_Id;
8167 if Ekind (Rectype) = E_Record_Subtype then
8168 Comp_Base := Original_Record_Component (Comp);
8173 return Comp_Base /= Original_Record_Component (Comp_Base);
8178 Is_Record_Extension : Boolean;
8179 -- True if Rectype is a record extension
8181 CR_Pragma : Node_Id := Empty;
8182 -- Points to N_Pragma node if Complete_Representation pragma present
8184 -- Start of processing for Analyze_Record_Representation_Clause
8187 if Ignore_Rep_Clauses then
8188 Kill_Rep_Clause (N);
8193 Rectype := Entity (Ident);
8195 if Rectype = Any_Type or else Rep_Item_Too_Early (Rectype, N) then
8198 Rectype := Underlying_Type (Rectype);
8201 -- First some basic error checks
8203 if not Is_Record_Type (Rectype) then
8205 ("record type required, found}", Ident, First_Subtype (Rectype));
8208 elsif Scope (Rectype) /= Current_Scope then
8209 Error_Msg_N ("type must be declared in this scope", N);
8212 elsif not Is_First_Subtype (Rectype) then
8213 Error_Msg_N ("cannot give record rep clause for subtype", N);
8216 elsif Has_Record_Rep_Clause (Rectype) then
8217 Error_Msg_N ("duplicate record rep clause ignored", N);
8220 elsif Rep_Item_Too_Late (Rectype, N) then
8224 -- We know we have a first subtype, now possibly go to the anonymous
8225 -- base type to determine whether Rectype is a record extension.
8227 Recdef := Type_Definition (Declaration_Node (Base_Type (Rectype)));
8228 Is_Record_Extension :=
8229 Nkind (Recdef) = N_Derived_Type_Definition
8230 and then Present (Record_Extension_Part (Recdef));
8232 if Present (Mod_Clause (N)) then
8234 M : constant Node_Id := Mod_Clause (N);
8235 P : constant List_Id := Pragmas_Before (M);
8239 Check_Restriction (No_Obsolescent_Features, Mod_Clause (N));
8241 if Warn_On_Obsolescent_Feature then
8243 ("?j?mod clause is an obsolescent feature (RM J.8)", N);
8245 ("\?j?use alignment attribute definition clause instead", N);
8252 -- Get the alignment value to perform error checking
8254 Ignore := Get_Alignment_Value (Expression (M));
8258 -- For untagged types, clear any existing component clauses for the
8259 -- type. If the type is derived, this is what allows us to override
8260 -- a rep clause for the parent. For type extensions, the representation
8261 -- of the inherited components is inherited, so we want to keep previous
8262 -- component clauses for completeness.
8264 if not Is_Tagged_Type (Rectype) then
8265 Comp := First_Component_Or_Discriminant (Rectype);
8266 while Present (Comp) loop
8267 Set_Component_Clause (Comp, Empty);
8268 Next_Component_Or_Discriminant (Comp);
8272 -- All done if no component clauses
8274 CC := First (Component_Clauses (N));
8280 -- A representation like this applies to the base type
8282 Set_Has_Record_Rep_Clause (Base_Type (Rectype));
8283 Set_Has_Non_Standard_Rep (Base_Type (Rectype));
8284 Set_Has_Specified_Layout (Base_Type (Rectype));
8286 -- Process the component clauses
8288 while Present (CC) loop
8292 if Nkind (CC) = N_Pragma then
8295 -- The only pragma of interest is Complete_Representation
8297 if Pragma_Name (CC) = Name_Complete_Representation then
8301 -- Processing for real component clause
8304 Posit := Static_Integer (Position (CC));
8305 Fbit := Static_Integer (First_Bit (CC));
8306 Lbit := Static_Integer (Last_Bit (CC));
8309 and then Fbit /= No_Uint
8310 and then Lbit /= No_Uint
8313 Error_Msg_N ("position cannot be negative", Position (CC));
8316 Error_Msg_N ("first bit cannot be negative", First_Bit (CC));
8318 -- The Last_Bit specified in a component clause must not be
8319 -- less than the First_Bit minus one (RM-13.5.1(10)).
8321 elsif Lbit < Fbit - 1 then
8323 ("last bit cannot be less than first bit minus one",
8326 -- Values look OK, so find the corresponding record component
8327 -- Even though the syntax allows an attribute reference for
8328 -- implementation-defined components, GNAT does not allow the
8329 -- tag to get an explicit position.
8331 elsif Nkind (Component_Name (CC)) = N_Attribute_Reference then
8332 if Attribute_Name (Component_Name (CC)) = Name_Tag then
8333 Error_Msg_N ("position of tag cannot be specified", CC);
8335 Error_Msg_N ("illegal component name", CC);
8339 Comp := First_Entity (Rectype);
8340 while Present (Comp) loop
8341 exit when Chars (Comp) = Chars (Component_Name (CC));
8347 -- Maybe component of base type that is absent from
8348 -- statically constrained first subtype.
8350 Comp := First_Entity (Base_Type (Rectype));
8351 while Present (Comp) loop
8352 exit when Chars (Comp) = Chars (Component_Name (CC));
8359 ("component clause is for non-existent field", CC);
8361 -- Ada 2012 (AI05-0026): Any name that denotes a
8362 -- discriminant of an object of an unchecked union type
8363 -- shall not occur within a record_representation_clause.
8365 -- The general restriction of using record rep clauses on
8366 -- Unchecked_Union types has now been lifted. Since it is
8367 -- possible to introduce a record rep clause which mentions
8368 -- the discriminant of an Unchecked_Union in non-Ada 2012
8369 -- code, this check is applied to all versions of the
8372 elsif Ekind (Comp) = E_Discriminant
8373 and then Is_Unchecked_Union (Rectype)
8376 ("cannot reference discriminant of unchecked union",
8377 Component_Name (CC));
8379 elsif Is_Record_Extension and then Is_Inherited (Comp) then
8381 ("component clause not allowed for inherited "
8382 & "component&", CC, Comp);
8384 elsif Present (Component_Clause (Comp)) then
8386 -- Diagnose duplicate rep clause, or check consistency
8387 -- if this is an inherited component. In a double fault,
8388 -- there may be a duplicate inconsistent clause for an
8389 -- inherited component.
8391 if Scope (Original_Record_Component (Comp)) = Rectype
8392 or else Parent (Component_Clause (Comp)) = N
8394 Error_Msg_Sloc := Sloc (Component_Clause (Comp));
8395 Error_Msg_N ("component clause previously given#", CC);
8399 Rep1 : constant Node_Id := Component_Clause (Comp);
8401 if Intval (Position (Rep1)) /=
8402 Intval (Position (CC))
8403 or else Intval (First_Bit (Rep1)) /=
8404 Intval (First_Bit (CC))
8405 or else Intval (Last_Bit (Rep1)) /=
8406 Intval (Last_Bit (CC))
8409 ("component clause inconsistent with "
8410 & "representation of ancestor", CC);
8412 elsif Warn_On_Redundant_Constructs then
8414 ("?r?redundant confirming component clause "
8415 & "for component!", CC);
8420 -- Normal case where this is the first component clause we
8421 -- have seen for this entity, so set it up properly.
8424 -- Make reference for field in record rep clause and set
8425 -- appropriate entity field in the field identifier.
8428 (Comp, Component_Name (CC), Set_Ref => False);
8429 Set_Entity (Component_Name (CC), Comp);
8431 -- Update Fbit and Lbit to the actual bit number
8433 Fbit := Fbit + UI_From_Int (SSU) * Posit;
8434 Lbit := Lbit + UI_From_Int (SSU) * Posit;
8436 if Has_Size_Clause (Rectype)
8437 and then RM_Size (Rectype) <= Lbit
8439 Error_Msg_Uint_1 := RM_Size (Rectype);
8440 Error_Msg_Uint_2 := Lbit + 1;
8441 Error_Msg_N ("bit number out of range of specified "
8442 & "size (expected ^, got ^)",
8445 Set_Component_Clause (Comp, CC);
8446 Set_Component_Bit_Offset (Comp, Fbit);
8447 Set_Esize (Comp, 1 + (Lbit - Fbit));
8448 Set_Normalized_First_Bit (Comp, Fbit mod SSU);
8449 Set_Normalized_Position (Comp, Fbit / SSU);
8451 Set_Normalized_Position_Max
8452 (Comp, Normalized_Position (Comp));
8454 if Warn_On_Overridden_Size
8455 and then Has_Size_Clause (Etype (Comp))
8456 and then RM_Size (Etype (Comp)) /= Esize (Comp)
8459 ("?S?component size overrides size clause for&",
8460 Component_Name (CC), Etype (Comp));
8464 (Component_Name (CC),
8470 (Comp, First_Node (CC), "component clause", Biased);
8472 -- This information is also set in the corresponding
8473 -- component of the base type, found by accessing the
8474 -- Original_Record_Component link if it is present.
8476 Ocomp := Original_Record_Component (Comp);
8478 if Present (Ocomp) and then Ocomp /= Comp then
8479 Set_Component_Clause (Ocomp, CC);
8480 Set_Component_Bit_Offset (Ocomp, Fbit);
8481 Set_Esize (Ocomp, 1 + (Lbit - Fbit));
8482 Set_Normalized_First_Bit (Ocomp, Fbit mod SSU);
8483 Set_Normalized_Position (Ocomp, Fbit / SSU);
8485 Set_Normalized_Position_Max
8486 (Ocomp, Normalized_Position (Ocomp));
8488 -- Note: we don't use Set_Biased here, because we
8489 -- already gave a warning above if needed, and we
8490 -- would get a duplicate for the same name here.
8492 Set_Has_Biased_Representation
8493 (Ocomp, Has_Biased_Representation (Comp));
8496 if Esize (Comp) < 0 then
8497 Error_Msg_N ("component size is negative", CC);
8508 -- Check missing components if Complete_Representation pragma appeared
8510 if Present (CR_Pragma) then
8511 Comp := First_Component_Or_Discriminant (Rectype);
8512 while Present (Comp) loop
8513 if No (Component_Clause (Comp)) then
8515 ("missing component clause for &", CR_Pragma, Comp);
8518 Next_Component_Or_Discriminant (Comp);
8521 -- Give missing components warning if required
8523 elsif Warn_On_Unrepped_Components then
8525 Num_Repped_Components : Nat := 0;
8526 Num_Unrepped_Components : Nat := 0;
8529 -- First count number of repped and unrepped components
8531 Comp := First_Component_Or_Discriminant (Rectype);
8532 while Present (Comp) loop
8533 if Present (Component_Clause (Comp)) then
8534 Num_Repped_Components := Num_Repped_Components + 1;
8536 Num_Unrepped_Components := Num_Unrepped_Components + 1;
8539 Next_Component_Or_Discriminant (Comp);
8542 -- We are only interested in the case where there is at least one
8543 -- unrepped component, and at least half the components have rep
8544 -- clauses. We figure that if less than half have them, then the
8545 -- partial rep clause is really intentional. If the component
8546 -- type has no underlying type set at this point (as for a generic
8547 -- formal type), we don't know enough to give a warning on the
8550 if Num_Unrepped_Components > 0
8551 and then Num_Unrepped_Components < Num_Repped_Components
8553 Comp := First_Component_Or_Discriminant (Rectype);
8554 while Present (Comp) loop
8555 if No (Component_Clause (Comp))
8556 and then Comes_From_Source (Comp)
8557 and then Present (Underlying_Type (Etype (Comp)))
8558 and then (Is_Scalar_Type (Underlying_Type (Etype (Comp)))
8559 or else Size_Known_At_Compile_Time
8560 (Underlying_Type (Etype (Comp))))
8561 and then not Has_Warnings_Off (Rectype)
8563 -- Ignore discriminant in unchecked union, since it is
8564 -- not there, and cannot have a component clause.
8566 and then (not Is_Unchecked_Union (Rectype)
8567 or else Ekind (Comp) /= E_Discriminant)
8569 Error_Msg_Sloc := Sloc (Comp);
8571 ("?C?no component clause given for & declared #",
8575 Next_Component_Or_Discriminant (Comp);
8580 end Analyze_Record_Representation_Clause;
8582 -------------------------------------
8583 -- Build_Discrete_Static_Predicate --
8584 -------------------------------------
8586 procedure Build_Discrete_Static_Predicate
8591 Loc : constant Source_Ptr := Sloc (Expr);
8593 Non_Static : exception;
8594 -- Raised if something non-static is found
8596 Btyp : constant Entity_Id := Base_Type (Typ);
8598 BLo : constant Uint := Expr_Value (Type_Low_Bound (Btyp));
8599 BHi : constant Uint := Expr_Value (Type_High_Bound (Btyp));
8600 -- Low bound and high bound value of base type of Typ
8604 -- Bounds for constructing the static predicate. We use the bound of the
8605 -- subtype if it is static, otherwise the corresponding base type bound.
8606 -- Note: a non-static subtype can have a static predicate.
8611 -- One entry in a Rlist value, a single REnt (range entry) value denotes
8612 -- one range from Lo to Hi. To represent a single value range Lo = Hi =
8615 type RList is array (Nat range <>) of REnt;
8616 -- A list of ranges. The ranges are sorted in increasing order, and are
8617 -- disjoint (there is a gap of at least one value between each range in
8618 -- the table). A value is in the set of ranges in Rlist if it lies
8619 -- within one of these ranges.
8621 False_Range : constant RList :=
8622 RList'(1 .. 0 => REnt'(No_Uint, No_Uint));
8623 -- An empty set of ranges represents a range list that can never be
8624 -- satisfied, since there are no ranges in which the value could lie,
8625 -- so it does not lie in any of them. False_Range is a canonical value
8626 -- for this empty set, but general processing should test for an Rlist
8627 -- with length zero (see Is_False predicate), since other null ranges
8628 -- may appear which must be treated as False.
8630 True_Range : constant RList := RList'(1 => REnt'(BLo, BHi));
8631 -- Range representing True, value must be in the base range
8633 function "and" (Left : RList; Right : RList) return RList;
8634 -- And's together two range lists, returning a range list. This is a set
8635 -- intersection operation.
8637 function "or" (Left : RList; Right : RList) return RList;
8638 -- Or's together two range lists, returning a range list. This is a set
8641 function "not" (Right : RList) return RList;
8642 -- Returns complement of a given range list, i.e. a range list
8643 -- representing all the values in TLo .. THi that are not in the input
8646 function Build_Val (V : Uint) return Node_Id;
8647 -- Return an analyzed N_Identifier node referencing this value, suitable
8648 -- for use as an entry in the Static_Discrte_Predicate list. This node
8649 -- is typed with the base type.
8651 function Build_Range (Lo : Uint; Hi : Uint) return Node_Id;
8652 -- Return an analyzed N_Range node referencing this range, suitable for
8653 -- use as an entry in the Static_Discrete_Predicate list. This node is
8654 -- typed with the base type.
8656 function Get_RList (Exp : Node_Id) return RList;
8657 -- This is a recursive routine that converts the given expression into a
8658 -- list of ranges, suitable for use in building the static predicate.
8660 function Is_False (R : RList) return Boolean;
8661 pragma Inline (Is_False);
8662 -- Returns True if the given range list is empty, and thus represents a
8663 -- False list of ranges that can never be satisfied.
8665 function Is_True (R : RList) return Boolean;
8666 -- Returns True if R trivially represents the True predicate by having a
8667 -- single range from BLo to BHi.
8669 function Is_Type_Ref (N : Node_Id) return Boolean;
8670 pragma Inline (Is_Type_Ref);
8671 -- Returns if True if N is a reference to the type for the predicate in
8672 -- the expression (i.e. if it is an identifier whose Chars field matches
8673 -- the Nam given in the call). N must not be parenthesized, if the type
8674 -- name appears in parens, this routine will return False.
8676 function Lo_Val (N : Node_Id) return Uint;
8677 -- Given an entry from a Static_Discrete_Predicate list that is either
8678 -- a static expression or static range, gets either the expression value
8679 -- or the low bound of the range.
8681 function Hi_Val (N : Node_Id) return Uint;
8682 -- Given an entry from a Static_Discrete_Predicate list that is either
8683 -- a static expression or static range, gets either the expression value
8684 -- or the high bound of the range.
8686 function Membership_Entry (N : Node_Id) return RList;
8687 -- Given a single membership entry (range, value, or subtype), returns
8688 -- the corresponding range list. Raises Static_Error if not static.
8690 function Membership_Entries (N : Node_Id) return RList;
8691 -- Given an element on an alternatives list of a membership operation,
8692 -- returns the range list corresponding to this entry and all following
8693 -- entries (i.e. returns the "or" of this list of values).
8695 function Stat_Pred (Typ : Entity_Id) return RList;
8696 -- Given a type, if it has a static predicate, then return the predicate
8697 -- as a range list, otherwise raise Non_Static.
8703 function "and" (Left : RList; Right : RList) return RList is
8705 -- First range of result
8707 SLeft : Nat := Left'First;
8708 -- Start of rest of left entries
8710 SRight : Nat := Right'First;
8711 -- Start of rest of right entries
8714 -- If either range is True, return the other
8716 if Is_True (Left) then
8718 elsif Is_True (Right) then
8722 -- If either range is False, return False
8724 if Is_False (Left) or else Is_False (Right) then
8728 -- Loop to remove entries at start that are disjoint, and thus just
8729 -- get discarded from the result entirely.
8732 -- If no operands left in either operand, result is false
8734 if SLeft > Left'Last or else SRight > Right'Last then
8737 -- Discard first left operand entry if disjoint with right
8739 elsif Left (SLeft).Hi < Right (SRight).Lo then
8742 -- Discard first right operand entry if disjoint with left
8744 elsif Right (SRight).Hi < Left (SLeft).Lo then
8745 SRight := SRight + 1;
8747 -- Otherwise we have an overlapping entry
8754 -- Now we have two non-null operands, and first entries overlap. The
8755 -- first entry in the result will be the overlapping part of these
8758 FEnt := REnt'(Lo => UI_Max (Left (SLeft).Lo, Right (SRight).Lo),
8759 Hi => UI_Min (Left (SLeft).Hi, Right (SRight).Hi));
8761 -- Now we can remove the entry that ended at a lower value, since its
8762 -- contribution is entirely contained in Fent.
8764 if Left (SLeft).Hi <= Right (SRight).Hi then
8767 SRight := SRight + 1;
8770 -- Compute result by concatenating this first entry with the "and" of
8771 -- the remaining parts of the left and right operands. Note that if
8772 -- either of these is empty, "and" will yield empty, so that we will
8773 -- end up with just Fent, which is what we want in that case.
8776 FEnt & (Left (SLeft .. Left'Last) and Right (SRight .. Right'Last));
8783 function "not" (Right : RList) return RList is
8785 -- Return True if False range
8787 if Is_False (Right) then
8791 -- Return False if True range
8793 if Is_True (Right) then
8797 -- Here if not trivial case
8800 Result : RList (1 .. Right'Length + 1);
8801 -- May need one more entry for gap at beginning and end
8804 -- Number of entries stored in Result
8809 if Right (Right'First).Lo > TLo then
8811 Result (Count) := REnt'(TLo, Right (Right'First).Lo - 1);
8814 -- Gaps between ranges
8816 for J in Right'First .. Right'Last - 1 loop
8818 Result (Count) := REnt'(Right (J).Hi + 1, Right (J + 1).Lo - 1);
8823 if Right (Right'Last).Hi < THi then
8825 Result (Count) := REnt'(Right (Right'Last).Hi + 1, THi);
8828 return Result (1 .. Count);
8836 function "or" (Left : RList; Right : RList) return RList is
8838 -- First range of result
8840 SLeft : Nat := Left'First;
8841 -- Start of rest of left entries
8843 SRight : Nat := Right'First;
8844 -- Start of rest of right entries
8847 -- If either range is True, return True
8849 if Is_True (Left) or else Is_True (Right) then
8853 -- If either range is False (empty), return the other
8855 if Is_False (Left) then
8857 elsif Is_False (Right) then
8861 -- Initialize result first entry from left or right operand depending
8862 -- on which starts with the lower range.
8864 if Left (SLeft).Lo < Right (SRight).Lo then
8865 FEnt := Left (SLeft);
8868 FEnt := Right (SRight);
8869 SRight := SRight + 1;
8872 -- This loop eats ranges from left and right operands that are
8873 -- contiguous with the first range we are gathering.
8876 -- Eat first entry in left operand if contiguous or overlapped by
8877 -- gathered first operand of result.
8879 if SLeft <= Left'Last
8880 and then Left (SLeft).Lo <= FEnt.Hi + 1
8882 FEnt.Hi := UI_Max (FEnt.Hi, Left (SLeft).Hi);
8885 -- Eat first entry in right operand if contiguous or overlapped by
8886 -- gathered right operand of result.
8888 elsif SRight <= Right'Last
8889 and then Right (SRight).Lo <= FEnt.Hi + 1
8891 FEnt.Hi := UI_Max (FEnt.Hi, Right (SRight).Hi);
8892 SRight := SRight + 1;
8894 -- All done if no more entries to eat
8901 -- Obtain result as the first entry we just computed, concatenated
8902 -- to the "or" of the remaining results (if one operand is empty,
8903 -- this will just concatenate with the other
8906 FEnt & (Left (SLeft .. Left'Last) or Right (SRight .. Right'Last));
8913 function Build_Range (Lo : Uint; Hi : Uint) return Node_Id is
8918 Low_Bound => Build_Val (Lo),
8919 High_Bound => Build_Val (Hi));
8920 Set_Etype (Result, Btyp);
8921 Set_Analyzed (Result);
8929 function Build_Val (V : Uint) return Node_Id is
8933 if Is_Enumeration_Type (Typ) then
8934 Result := Get_Enum_Lit_From_Pos (Typ, V, Loc);
8936 Result := Make_Integer_Literal (Loc, V);
8939 Set_Etype (Result, Btyp);
8940 Set_Is_Static_Expression (Result);
8941 Set_Analyzed (Result);
8949 function Get_RList (Exp : Node_Id) return RList is
8954 -- Static expression can only be true or false
8956 if Is_OK_Static_Expression (Exp) then
8957 if Expr_Value (Exp) = 0 then
8964 -- Otherwise test node type
8975 return Get_RList (Left_Opnd (Exp))
8977 Get_RList (Right_Opnd (Exp));
8984 return Get_RList (Left_Opnd (Exp))
8986 Get_RList (Right_Opnd (Exp));
8991 return not Get_RList (Right_Opnd (Exp));
8993 -- Comparisons of type with static value
8995 when N_Op_Compare =>
8997 -- Type is left operand
8999 if Is_Type_Ref (Left_Opnd (Exp))
9000 and then Is_OK_Static_Expression (Right_Opnd (Exp))
9002 Val := Expr_Value (Right_Opnd (Exp));
9004 -- Typ is right operand
9006 elsif Is_Type_Ref (Right_Opnd (Exp))
9007 and then Is_OK_Static_Expression (Left_Opnd (Exp))
9009 Val := Expr_Value (Left_Opnd (Exp));
9011 -- Invert sense of comparison
9014 when N_Op_Gt => Op := N_Op_Lt;
9015 when N_Op_Lt => Op := N_Op_Gt;
9016 when N_Op_Ge => Op := N_Op_Le;
9017 when N_Op_Le => Op := N_Op_Ge;
9018 when others => null;
9021 -- Other cases are non-static
9027 -- Construct range according to comparison operation
9031 return RList'(1 => REnt'(Val, Val));
9034 return RList'(1 => REnt'(Val, BHi));
9037 return RList'(1 => REnt'(Val + 1, BHi));
9040 return RList'(1 => REnt'(BLo, Val));
9043 return RList'(1 => REnt'(BLo, Val - 1));
9046 return RList'(REnt'(BLo, Val - 1), REnt'(Val + 1, BHi));
9049 raise Program_Error;
9055 if not Is_Type_Ref (Left_Opnd (Exp)) then
9059 if Present (Right_Opnd (Exp)) then
9060 return Membership_Entry (Right_Opnd (Exp));
9062 return Membership_Entries (First (Alternatives (Exp)));
9065 -- Negative membership (NOT IN)
9068 if not Is_Type_Ref (Left_Opnd (Exp)) then
9072 if Present (Right_Opnd (Exp)) then
9073 return not Membership_Entry (Right_Opnd (Exp));
9075 return not Membership_Entries (First (Alternatives (Exp)));
9078 -- Function call, may be call to static predicate
9080 when N_Function_Call =>
9081 if Is_Entity_Name (Name (Exp)) then
9083 Ent : constant Entity_Id := Entity (Name (Exp));
9085 if Is_Predicate_Function (Ent)
9087 Is_Predicate_Function_M (Ent)
9089 return Stat_Pred (Etype (First_Formal (Ent)));
9094 -- Other function call cases are non-static
9098 -- Qualified expression, dig out the expression
9100 when N_Qualified_Expression =>
9101 return Get_RList (Expression (Exp));
9103 when N_Case_Expression =>
9110 if not Is_Entity_Name (Expression (Expr))
9111 or else Etype (Expression (Expr)) /= Typ
9114 ("expression must denaote subtype", Expression (Expr));
9118 -- Collect discrete choices in all True alternatives
9120 Choices := New_List;
9121 Alt := First (Alternatives (Exp));
9122 while Present (Alt) loop
9123 Dep := Expression (Alt);
9125 if not Is_OK_Static_Expression (Dep) then
9128 elsif Is_True (Expr_Value (Dep)) then
9129 Append_List_To (Choices,
9130 New_Copy_List (Discrete_Choices (Alt)));
9136 return Membership_Entries (First (Choices));
9139 -- Expression with actions: if no actions, dig out expression
9141 when N_Expression_With_Actions =>
9142 if Is_Empty_List (Actions (Exp)) then
9143 return Get_RList (Expression (Exp));
9151 return (Get_RList (Left_Opnd (Exp))
9152 and not Get_RList (Right_Opnd (Exp)))
9153 or (Get_RList (Right_Opnd (Exp))
9154 and not Get_RList (Left_Opnd (Exp)));
9156 -- Any other node type is non-static
9167 function Hi_Val (N : Node_Id) return Uint is
9169 if Is_OK_Static_Expression (N) then
9170 return Expr_Value (N);
9172 pragma Assert (Nkind (N) = N_Range);
9173 return Expr_Value (High_Bound (N));
9181 function Is_False (R : RList) return Boolean is
9183 return R'Length = 0;
9190 function Is_True (R : RList) return Boolean is
9193 and then R (R'First).Lo = BLo
9194 and then R (R'First).Hi = BHi;
9201 function Is_Type_Ref (N : Node_Id) return Boolean is
9203 return Nkind (N) = N_Identifier
9204 and then Chars (N) = Nam
9205 and then Paren_Count (N) = 0;
9212 function Lo_Val (N : Node_Id) return Uint is
9214 if Is_OK_Static_Expression (N) then
9215 return Expr_Value (N);
9217 pragma Assert (Nkind (N) = N_Range);
9218 return Expr_Value (Low_Bound (N));
9222 ------------------------
9223 -- Membership_Entries --
9224 ------------------------
9226 function Membership_Entries (N : Node_Id) return RList is
9228 if No (Next (N)) then
9229 return Membership_Entry (N);
9231 return Membership_Entry (N) or Membership_Entries (Next (N));
9233 end Membership_Entries;
9235 ----------------------
9236 -- Membership_Entry --
9237 ----------------------
9239 function Membership_Entry (N : Node_Id) return RList is
9247 if Nkind (N) = N_Range then
9248 if not Is_OK_Static_Expression (Low_Bound (N))
9250 not Is_OK_Static_Expression (High_Bound (N))
9254 SLo := Expr_Value (Low_Bound (N));
9255 SHi := Expr_Value (High_Bound (N));
9256 return RList'(1 => REnt'(SLo, SHi));
9261 elsif Nkind (N) = N_Others_Choice then
9263 Choices : constant List_Id := Others_Discrete_Choices (N);
9265 Range_List : RList (1 .. List_Length (Choices));
9268 Choice := First (Choices);
9270 for J in Range_List'Range loop
9271 Range_List (J) := REnt'(Lo_Val (Choice), Hi_Val (Choice));
9278 -- Static expression case
9280 elsif Is_OK_Static_Expression (N) then
9281 Val := Expr_Value (N);
9282 return RList'(1 => REnt'(Val, Val));
9284 -- Identifier (other than static expression) case
9286 else pragma Assert (Nkind (N) in N_Expanded_Name | N_Identifier);
9290 if Is_Type (Entity (N)) then
9292 -- If type has predicates, process them
9294 if Has_Predicates (Entity (N)) then
9295 return Stat_Pred (Entity (N));
9297 -- For static subtype without predicates, get range
9299 elsif Is_OK_Static_Subtype (Entity (N)) then
9300 SLo := Expr_Value (Type_Low_Bound (Entity (N)));
9301 SHi := Expr_Value (Type_High_Bound (Entity (N)));
9302 return RList'(1 => REnt'(SLo, SHi));
9304 -- Any other type makes us non-static
9310 -- Any other kind of identifier in predicate (e.g. a non-static
9311 -- expression value) means this is not a static predicate.
9317 end Membership_Entry;
9323 function Stat_Pred (Typ : Entity_Id) return RList is
9325 -- Not static if type does not have static predicates
9327 if not Has_Static_Predicate (Typ) then
9331 -- Otherwise we convert the predicate list to a range list
9334 Spred : constant List_Id := Static_Discrete_Predicate (Typ);
9335 Result : RList (1 .. List_Length (Spred));
9339 P := First (Static_Discrete_Predicate (Typ));
9340 for J in Result'Range loop
9341 Result (J) := REnt'(Lo_Val (P), Hi_Val (P));
9349 -- Start of processing for Build_Discrete_Static_Predicate
9352 -- Establish bounds for the predicate
9354 if Compile_Time_Known_Value (Type_Low_Bound (Typ)) then
9355 TLo := Expr_Value (Type_Low_Bound (Typ));
9360 if Compile_Time_Known_Value (Type_High_Bound (Typ)) then
9361 THi := Expr_Value (Type_High_Bound (Typ));
9366 -- Analyze the expression to see if it is a static predicate
9369 Ranges : constant RList := Get_RList (Expr);
9370 -- Range list from expression if it is static
9375 -- Convert range list into a form for the static predicate. In the
9376 -- Ranges array, we just have raw ranges, these must be converted
9377 -- to properly typed and analyzed static expressions or range nodes.
9379 -- Note: here we limit ranges to the ranges of the subtype, so that
9380 -- a predicate is always false for values outside the subtype. That
9381 -- seems fine, such values are invalid anyway, and considering them
9382 -- to fail the predicate seems allowed and friendly, and furthermore
9383 -- simplifies processing for case statements and loops.
9387 for J in Ranges'Range loop
9389 Lo : Uint := Ranges (J).Lo;
9390 Hi : Uint := Ranges (J).Hi;
9393 -- Ignore completely out of range entry
9395 if Hi < TLo or else Lo > THi then
9398 -- Otherwise process entry
9401 -- Adjust out of range value to subtype range
9411 -- Convert range into required form
9413 Append_To (Plist, Build_Range (Lo, Hi));
9418 -- Processing was successful and all entries were static, so now we
9419 -- can store the result as the predicate list.
9421 Set_Static_Discrete_Predicate (Typ, Plist);
9423 -- Within a generic the predicate functions themselves need not
9426 if Inside_A_Generic then
9430 -- The processing for static predicates put the expression into
9431 -- canonical form as a series of ranges. It also eliminated
9432 -- duplicates and collapsed and combined ranges. We might as well
9433 -- replace the alternatives list of the right operand of the
9434 -- membership test with the static predicate list, which will
9435 -- usually be more efficient.
9438 New_Alts : constant List_Id := New_List;
9443 Old_Node := First (Plist);
9444 while Present (Old_Node) loop
9445 New_Node := New_Copy (Old_Node);
9447 if Nkind (New_Node) = N_Range then
9448 Set_Low_Bound (New_Node, New_Copy (Low_Bound (Old_Node)));
9449 Set_High_Bound (New_Node, New_Copy (High_Bound (Old_Node)));
9452 Append_To (New_Alts, New_Node);
9456 -- If empty list, replace by False
9458 if Is_Empty_List (New_Alts) then
9459 Rewrite (Expr, New_Occurrence_Of (Standard_False, Loc));
9461 -- Else replace by set membership test
9466 Left_Opnd => Make_Identifier (Loc, Nam),
9467 Right_Opnd => Empty,
9468 Alternatives => New_Alts));
9470 -- Resolve new expression in function context
9472 Install_Formals (Predicate_Function (Typ));
9473 Push_Scope (Predicate_Function (Typ));
9474 Analyze_And_Resolve (Expr, Standard_Boolean);
9480 -- If non-static, return doing nothing
9485 end Build_Discrete_Static_Predicate;
9487 --------------------------------
9488 -- Build_Export_Import_Pragma --
9489 --------------------------------
9491 function Build_Export_Import_Pragma
9493 Id : Entity_Id) return Node_Id
9495 Asp_Id : constant Aspect_Id := Get_Aspect_Id (Asp);
9496 Expr : constant Node_Id := Expression (Asp);
9497 Loc : constant Source_Ptr := Sloc (Asp);
9508 Create_Pragma : Boolean := False;
9509 -- This flag is set when the aspect form is such that it warrants the
9510 -- creation of a corresponding pragma.
9513 if Present (Expr) then
9514 if Error_Posted (Expr) then
9517 elsif Is_True (Expr_Value (Expr)) then
9518 Create_Pragma := True;
9521 -- Otherwise the aspect defaults to True
9524 Create_Pragma := True;
9527 -- Nothing to do when the expression is False or is erroneous
9529 if not Create_Pragma then
9533 -- Obtain all interfacing aspects that apply to the related entity
9535 Get_Interfacing_Aspects
9539 Expo_Asp => Dummy_1,
9545 -- Handle the convention argument
9547 if Present (Conv) then
9548 Conv_Arg := New_Copy_Tree (Expression (Conv));
9550 -- Assume convention "Ada' when aspect Convention is missing
9553 Conv_Arg := Make_Identifier (Loc, Name_Ada);
9557 Make_Pragma_Argument_Association (Loc,
9558 Chars => Name_Convention,
9559 Expression => Conv_Arg));
9561 -- Handle the entity argument
9564 Make_Pragma_Argument_Association (Loc,
9565 Chars => Name_Entity,
9566 Expression => New_Occurrence_Of (Id, Loc)));
9568 -- Handle the External_Name argument
9570 if Present (EN) then
9572 Make_Pragma_Argument_Association (Loc,
9573 Chars => Name_External_Name,
9574 Expression => New_Copy_Tree (Expression (EN))));
9577 -- Handle the Link_Name argument
9579 if Present (LN) then
9581 Make_Pragma_Argument_Association (Loc,
9582 Chars => Name_Link_Name,
9583 Expression => New_Copy_Tree (Expression (LN))));
9587 -- pragma Export/Import
9588 -- (Convention => <Conv>/Ada,
9590 -- [External_Name => <EN>,]
9591 -- [Link_Name => <LN>]);
9595 Pragma_Identifier =>
9596 Make_Identifier (Loc, Chars (Identifier (Asp))),
9597 Pragma_Argument_Associations => Args);
9599 -- Decorate the relevant aspect and the pragma
9601 Set_Aspect_Rep_Item (Asp, Prag);
9603 Set_Corresponding_Aspect (Prag, Asp);
9604 Set_From_Aspect_Specification (Prag);
9605 Set_Parent (Prag, Asp);
9607 if Asp_Id = Aspect_Import and then Is_Subprogram (Id) then
9608 Set_Import_Pragma (Id, Prag);
9612 end Build_Export_Import_Pragma;
9614 -------------------------------
9615 -- Build_Predicate_Functions --
9616 -------------------------------
9618 -- The functions that are constructed here have the form:
9620 -- function typPredicate (Ixxx : typ) return Boolean is
9623 -- typ1Predicate (typ1 (Ixxx))
9624 -- and then typ2Predicate (typ2 (Ixxx))
9626 -- and then exp1 and then exp2 and then ...;
9627 -- end typPredicate;
9629 -- Here exp1, and exp2 are expressions from Predicate pragmas. Note that
9630 -- this is the point at which these expressions get analyzed, providing the
9631 -- required delay, and typ1, typ2, are entities from which predicates are
9632 -- inherited. Note that we do NOT generate Check pragmas, that's because we
9633 -- use this function even if checks are off, e.g. for membership tests.
9635 -- Note that the inherited predicates are evaluated first, as required by
9638 -- Note that Sem_Eval.Real_Or_String_Static_Predicate_Matches depends on
9639 -- the form of this return expression.
9641 -- If the expression has at least one Raise_Expression, then we also build
9642 -- the typPredicateM version of the function, in which any occurrence of a
9643 -- Raise_Expression is converted to "return False".
9645 -- WARNING: This routine manages Ghost regions. Return statements must be
9646 -- replaced by gotos which jump to the end of the routine and restore the
9649 procedure Build_Predicate_Functions (Typ : Entity_Id; N : Node_Id) is
9650 Loc : constant Source_Ptr := Sloc (Typ);
9653 -- This is the expression for the result of the function. It is
9654 -- is build by connecting the component predicates with AND THEN.
9656 Expr_M : Node_Id := Empty; -- init to avoid warning
9657 -- This is the corresponding return expression for the Predicate_M
9658 -- function. It differs in that raise expressions are marked for
9659 -- special expansion (see Process_REs).
9661 Object_Name : Name_Id;
9662 -- Name for argument of Predicate procedure. Note that we use the same
9663 -- name for both predicate functions. That way the reference within the
9664 -- predicate expression is the same in both functions.
9666 Object_Entity : Entity_Id;
9667 -- Entity for argument of Predicate procedure
9669 Object_Entity_M : Entity_Id;
9670 -- Entity for argument of separate Predicate procedure when exceptions
9671 -- are present in expression.
9674 -- The function declaration
9679 Raise_Expression_Present : Boolean := False;
9680 -- Set True if Expr has at least one Raise_Expression
9682 procedure Add_Condition (Cond : Node_Id);
9683 -- Append Cond to Expr using "and then" (or just copy Cond to Expr if
9686 procedure Add_Predicates;
9687 -- Appends expressions for any Predicate pragmas in the rep item chain
9688 -- Typ to Expr. Note that we look only at items for this exact entity.
9689 -- Inheritance of predicates for the parent type is done by calling the
9690 -- Predicate_Function of the parent type, using Add_Call above.
9692 procedure Add_Call (T : Entity_Id);
9693 -- Includes a call to the predicate function for type T in Expr if
9694 -- Predicate_Function (T) is non-empty.
9696 function Process_RE (N : Node_Id) return Traverse_Result;
9697 -- Used in Process REs, tests if node N is a raise expression, and if
9698 -- so, marks it to be converted to return False.
9700 procedure Process_REs is new Traverse_Proc (Process_RE);
9701 -- Marks any raise expressions in Expr_M to return False
9703 function Test_RE (N : Node_Id) return Traverse_Result;
9704 -- Used in Test_REs, tests one node for being a raise expression, and if
9705 -- so sets Raise_Expression_Present True.
9707 procedure Test_REs is new Traverse_Proc (Test_RE);
9708 -- Tests to see if Expr contains any raise expressions
9714 procedure Add_Call (T : Entity_Id) is
9718 if Present (Predicate_Function (T)) then
9719 pragma Assert (Has_Predicates (Typ));
9721 -- Build the call to the predicate function of T. The type may be
9722 -- derived, so use an unchecked conversion for the actual.
9728 Unchecked_Convert_To (T,
9729 Make_Identifier (Loc, Object_Name)));
9731 -- "and"-in the call to evolving expression
9733 Add_Condition (Exp);
9735 -- Output info message on inheritance if required. Note we do not
9736 -- give this information for generic actual types, since it is
9737 -- unwelcome noise in that case in instantiations. We also
9738 -- generally suppress the message in instantiations, and also
9739 -- if it involves internal names.
9741 if Opt.List_Inherited_Aspects
9742 and then not Is_Generic_Actual_Type (Typ)
9743 and then Instantiation_Depth (Sloc (Typ)) = 0
9744 and then not Is_Internal_Name (Chars (T))
9745 and then not Is_Internal_Name (Chars (Typ))
9747 Error_Msg_Sloc := Sloc (Predicate_Function (T));
9748 Error_Msg_Node_2 := T;
9749 Error_Msg_N ("info: & inherits predicate from & #?L?", Typ);
9758 procedure Add_Condition (Cond : Node_Id) is
9760 -- This is the first predicate expression
9765 -- Otherwise concatenate to the existing predicate expressions by
9766 -- using "and then".
9771 Left_Opnd => Relocate_Node (Expr),
9772 Right_Opnd => Cond);
9776 --------------------
9777 -- Add_Predicates --
9778 --------------------
9780 procedure Add_Predicates is
9781 procedure Add_Predicate (Prag : Node_Id);
9782 -- Concatenate the expression of predicate pragma Prag to Expr by
9783 -- using a short circuit "and then" operator.
9789 procedure Add_Predicate (Prag : Node_Id) is
9790 procedure Replace_Type_Reference (N : Node_Id);
9791 -- Replace a single occurrence N of the subtype name with a
9792 -- reference to the formal of the predicate function. N can be an
9793 -- identifier referencing the subtype, or a selected component,
9794 -- representing an appropriately qualified occurrence of the
9797 procedure Replace_Type_References is
9798 new Replace_Type_References_Generic (Replace_Type_Reference);
9799 -- Traverse an expression changing every occurrence of an
9800 -- identifier whose name matches the name of the subtype with a
9801 -- reference to the formal parameter of the predicate function.
9803 ----------------------------
9804 -- Replace_Type_Reference --
9805 ----------------------------
9807 procedure Replace_Type_Reference (N : Node_Id) is
9809 Rewrite (N, Make_Identifier (Sloc (N), Object_Name));
9810 -- Use the Sloc of the usage name, not the defining name
9813 Set_Entity (N, Object_Entity);
9814 end Replace_Type_Reference;
9818 Asp : constant Node_Id := Corresponding_Aspect (Prag);
9822 -- Start of processing for Add_Predicate
9825 -- Mark corresponding SCO as enabled
9827 Set_SCO_Pragma_Enabled (Sloc (Prag));
9829 -- Extract the arguments of the pragma. The expression itself
9830 -- is copied for use in the predicate function, to preserve the
9831 -- original version for ASIS use.
9832 -- Is this still needed???
9834 Arg1 := First (Pragma_Argument_Associations (Prag));
9835 Arg2 := Next (Arg1);
9837 Arg1 := Get_Pragma_Arg (Arg1);
9838 Arg2 := New_Copy_Tree (Get_Pragma_Arg (Arg2));
9840 -- When the predicate pragma applies to the current type or its
9841 -- full view, replace all occurrences of the subtype name with
9842 -- references to the formal parameter of the predicate function.
9844 if Entity (Arg1) = Typ
9845 or else Full_View (Entity (Arg1)) = Typ
9847 Replace_Type_References (Arg2, Typ);
9849 -- If the predicate pragma comes from an aspect, replace the
9850 -- saved expression because we need the subtype references
9851 -- replaced for the calls to Preanalyze_Spec_Expression in
9852 -- Check_Aspect_At_xxx routines.
9854 if Present (Asp) then
9855 Set_Entity (Identifier (Asp), New_Copy_Tree (Arg2));
9858 -- "and"-in the Arg2 condition to evolving expression
9860 Add_Condition (Relocate_Node (Arg2));
9868 -- Start of processing for Add_Predicates
9871 Ritem := First_Rep_Item (Typ);
9873 -- If the type is private, check whether full view has inherited
9876 if Is_Private_Type (Typ) and then No (Ritem) then
9877 Ritem := First_Rep_Item (Full_View (Typ));
9880 while Present (Ritem) loop
9881 if Nkind (Ritem) = N_Pragma
9882 and then Pragma_Name (Ritem) = Name_Predicate
9884 Add_Predicate (Ritem);
9886 -- If the type is declared in an inner package it may be frozen
9887 -- outside of the package, and the generated pragma has not been
9888 -- analyzed yet, so capture the expression for the predicate
9889 -- function at this point.
9891 elsif Nkind (Ritem) = N_Aspect_Specification
9892 and then Present (Aspect_Rep_Item (Ritem))
9893 and then Scope_Depth (Scope (Typ)) > Scope_Depth (Current_Scope)
9896 Prag : constant Node_Id := Aspect_Rep_Item (Ritem);
9899 if Nkind (Prag) = N_Pragma
9900 and then Pragma_Name (Prag) = Name_Predicate
9902 Add_Predicate (Prag);
9907 Next_Rep_Item (Ritem);
9915 function Process_RE (N : Node_Id) return Traverse_Result is
9917 if Nkind (N) = N_Raise_Expression then
9918 Set_Convert_To_Return_False (N);
9929 function Test_RE (N : Node_Id) return Traverse_Result is
9931 if Nkind (N) = N_Raise_Expression then
9932 Raise_Expression_Present := True;
9941 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
9942 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
9943 -- Save the Ghost-related attributes to restore on exit
9945 -- Start of processing for Build_Predicate_Functions
9948 -- Return if already built or if type does not have predicates
9950 SId := Predicate_Function (Typ);
9951 if not Has_Predicates (Typ)
9952 or else (Present (SId) and then Has_Completion (SId))
9956 -- Do not generate predicate bodies within a generic unit. The
9957 -- expressions have been analyzed already, and the bodies play
9958 -- no role if not within an executable unit. However, if a statc
9959 -- predicate is present it must be processed for legality checks
9960 -- such as case coverage in an expression.
9962 elsif Inside_A_Generic
9963 and then not Has_Static_Predicate_Aspect (Typ)
9968 -- The related type may be subject to pragma Ghost. Set the mode now to
9969 -- ensure that the predicate functions are properly marked as Ghost.
9971 Set_Ghost_Mode (Typ);
9973 -- Prepare to construct predicate expression
9977 if Present (SId) then
9978 FDecl := Unit_Declaration_Node (SId);
9981 FDecl := Build_Predicate_Function_Declaration (Typ);
9982 SId := Defining_Entity (FDecl);
9985 -- Recover name of formal parameter of function that replaces references
9986 -- to the type in predicate expressions.
9990 (First (Parameter_Specifications (Specification (FDecl))));
9992 Object_Name := Chars (Object_Entity);
9993 Object_Entity_M := Make_Defining_Identifier (Loc, Chars => Object_Name);
9995 -- Add predicates for ancestor if present. These must come before the
9996 -- ones for the current type, as required by AI12-0071-1.
9998 -- Looks like predicates aren't added for case of inheriting from
9999 -- multiple progenitors???
10004 Atyp := Nearest_Ancestor (Typ);
10006 -- The type may be private but the full view may inherit predicates
10008 if No (Atyp) and then Is_Private_Type (Typ) then
10009 Atyp := Nearest_Ancestor (Full_View (Typ));
10012 if Present (Atyp) then
10017 -- Add Predicates for the current type
10021 -- Case where predicates are present
10023 if Present (Expr) then
10025 -- Test for raise expression present
10029 -- If raise expression is present, capture a copy of Expr for use
10030 -- in building the predicateM function version later on. For this
10031 -- copy we replace references to Object_Entity by Object_Entity_M.
10033 if Raise_Expression_Present then
10035 function Reset_Loop_Variable
10036 (N : Node_Id) return Traverse_Result;
10038 procedure Reset_Loop_Variables is
10039 new Traverse_Proc (Reset_Loop_Variable);
10041 ------------------------
10042 -- Reset_Loop_Variable --
10043 ------------------------
10045 function Reset_Loop_Variable
10046 (N : Node_Id) return Traverse_Result
10049 if Nkind (N) = N_Iterator_Specification then
10050 Set_Defining_Identifier (N,
10051 Make_Defining_Identifier
10052 (Sloc (N), Chars (Defining_Identifier (N))));
10056 end Reset_Loop_Variable;
10060 Map : constant Elist_Id := New_Elmt_List;
10063 Append_Elmt (Object_Entity, Map);
10064 Append_Elmt (Object_Entity_M, Map);
10065 Expr_M := New_Copy_Tree (Expr, Map => Map);
10067 -- The unanalyzed expression will be copied and appear in
10068 -- both functions. Normally expressions do not declare new
10069 -- entities, but quantified expressions do, so we need to
10070 -- create new entities for their bound variables, to prevent
10071 -- multiple definitions in gigi.
10073 Reset_Loop_Variables (Expr_M);
10077 -- Build the main predicate function
10080 SIdB : constant Entity_Id :=
10081 Make_Defining_Identifier (Loc,
10082 Chars => New_External_Name (Chars (Typ), "Predicate"));
10083 -- The entity for the function body
10089 Set_Ekind (SIdB, E_Function);
10090 Set_Is_Predicate_Function (SIdB);
10092 -- Build function body
10095 Make_Function_Specification (Loc,
10096 Defining_Unit_Name => SIdB,
10097 Parameter_Specifications => New_List (
10098 Make_Parameter_Specification (Loc,
10099 Defining_Identifier =>
10100 Make_Defining_Identifier (Loc, Object_Name),
10102 New_Occurrence_Of (Typ, Loc))),
10103 Result_Definition =>
10104 New_Occurrence_Of (Standard_Boolean, Loc));
10107 Make_Subprogram_Body (Loc,
10108 Specification => Spec,
10109 Declarations => Empty_List,
10110 Handled_Statement_Sequence =>
10111 Make_Handled_Sequence_Of_Statements (Loc,
10112 Statements => New_List (
10113 Make_Simple_Return_Statement (Loc,
10114 Expression => Expr))));
10116 -- The declaration has been analyzed when created, and placed
10117 -- after type declaration. Insert body itself after freeze node,
10118 -- unless subprogram declaration is already there, in which case
10119 -- body better be placed afterwards.
10121 if FDecl = Next (N) then
10122 Insert_After_And_Analyze (FDecl, FBody);
10124 Insert_After_And_Analyze (N, FBody);
10127 -- The defining identifier of a quantified expression carries the
10128 -- scope in which the type appears, but when unnesting we need
10129 -- to indicate that its proper scope is the constructed predicate
10130 -- function. The quantified expressions have been converted into
10131 -- loops during analysis and expansion.
10134 function Reset_Quantified_Variable_Scope
10135 (N : Node_Id) return Traverse_Result;
10137 procedure Reset_Quantified_Variables_Scope is
10138 new Traverse_Proc (Reset_Quantified_Variable_Scope);
10140 -------------------------------------
10141 -- Reset_Quantified_Variable_Scope --
10142 -------------------------------------
10144 function Reset_Quantified_Variable_Scope
10145 (N : Node_Id) return Traverse_Result is
10147 if Nkind (N) in N_Iterator_Specification
10148 | N_Loop_Parameter_Specification
10150 Set_Scope (Defining_Identifier (N),
10151 Predicate_Function (Typ));
10155 end Reset_Quantified_Variable_Scope;
10158 if Unnest_Subprogram_Mode then
10159 Reset_Quantified_Variables_Scope (Expr);
10163 -- Within a generic unit, prevent a double analysis of the body
10164 -- which will not be marked analyzed yet. This will happen when
10165 -- the freeze node is created during the preanalysis of an
10166 -- expression function.
10168 if Inside_A_Generic then
10169 Set_Analyzed (FBody);
10172 -- Static predicate functions are always side-effect free, and
10173 -- in most cases dynamic predicate functions are as well. Mark
10174 -- them as such whenever possible, so redundant predicate checks
10175 -- can be optimized. If there is a variable reference within the
10176 -- expression, the function is not pure.
10178 if Expander_Active then
10180 Side_Effect_Free (Expr, Variable_Ref => True));
10181 Set_Is_Inlined (SId);
10185 -- Test for raise expressions present and if so build M version
10187 if Raise_Expression_Present then
10189 SId : constant Entity_Id :=
10190 Make_Defining_Identifier (Loc,
10191 Chars => New_External_Name (Chars (Typ), "PredicateM"));
10192 -- The entity for the function spec
10194 SIdB : constant Entity_Id :=
10195 Make_Defining_Identifier (Loc,
10196 Chars => New_External_Name (Chars (Typ), "PredicateM"));
10197 -- The entity for the function body
10204 CRec_Typ : Entity_Id;
10205 -- The corresponding record type of Full_Typ
10207 Full_Typ : Entity_Id;
10208 -- The full view of Typ
10210 Priv_Typ : Entity_Id;
10211 -- The partial view of Typ
10213 UFull_Typ : Entity_Id;
10214 -- The underlying full view of Full_Typ
10217 -- Mark any raise expressions for special expansion
10219 Process_REs (Expr_M);
10221 -- Build function declaration
10223 Set_Ekind (SId, E_Function);
10224 Set_Is_Predicate_Function_M (SId);
10225 Set_Predicate_Function_M (Typ, SId);
10227 -- Obtain all views of the input type
10229 Get_Views (Typ, Priv_Typ, Full_Typ, UFull_Typ, CRec_Typ);
10231 -- Associate the predicate function with all views
10233 Propagate_Predicate_Attributes (Priv_Typ, From_Typ => Typ);
10234 Propagate_Predicate_Attributes (Full_Typ, From_Typ => Typ);
10235 Propagate_Predicate_Attributes (UFull_Typ, From_Typ => Typ);
10236 Propagate_Predicate_Attributes (CRec_Typ, From_Typ => Typ);
10239 Make_Function_Specification (Loc,
10240 Defining_Unit_Name => SId,
10241 Parameter_Specifications => New_List (
10242 Make_Parameter_Specification (Loc,
10243 Defining_Identifier => Object_Entity_M,
10244 Parameter_Type => New_Occurrence_Of (Typ, Loc))),
10245 Result_Definition =>
10246 New_Occurrence_Of (Standard_Boolean, Loc));
10249 Make_Subprogram_Declaration (Loc,
10250 Specification => Spec);
10252 -- Build function body
10255 Make_Function_Specification (Loc,
10256 Defining_Unit_Name => SIdB,
10257 Parameter_Specifications => New_List (
10258 Make_Parameter_Specification (Loc,
10259 Defining_Identifier =>
10260 Make_Defining_Identifier (Loc, Object_Name),
10262 New_Occurrence_Of (Typ, Loc))),
10263 Result_Definition =>
10264 New_Occurrence_Of (Standard_Boolean, Loc));
10266 -- Build the body, we declare the boolean expression before
10267 -- doing the return, because we are not really confident of
10268 -- what happens if a return appears within a return.
10271 Make_Defining_Identifier (Loc,
10272 Chars => New_Internal_Name ('B'));
10275 Make_Subprogram_Body (Loc,
10276 Specification => Spec,
10278 Declarations => New_List (
10279 Make_Object_Declaration (Loc,
10280 Defining_Identifier => BTemp,
10281 Constant_Present => True,
10282 Object_Definition =>
10283 New_Occurrence_Of (Standard_Boolean, Loc),
10284 Expression => Expr_M)),
10286 Handled_Statement_Sequence =>
10287 Make_Handled_Sequence_Of_Statements (Loc,
10288 Statements => New_List (
10289 Make_Simple_Return_Statement (Loc,
10290 Expression => New_Occurrence_Of (BTemp, Loc)))));
10292 -- Insert declaration before freeze node and body after
10294 Insert_Before_And_Analyze (N, FDecl);
10295 Insert_After_And_Analyze (N, FBody);
10297 -- Should quantified expressions be handled here as well ???
10301 -- See if we have a static predicate. Note that the answer may be
10302 -- yes even if we have an explicit Dynamic_Predicate present.
10309 if not Is_Scalar_Type (Typ) and then not Is_String_Type (Typ) then
10312 PS := Is_Predicate_Static (Expr, Object_Name);
10315 -- Case where we have a predicate-static aspect
10319 -- We don't set Has_Static_Predicate_Aspect, since we can have
10320 -- any of the three cases (Predicate, Dynamic_Predicate, or
10321 -- Static_Predicate) generating a predicate with an expression
10322 -- that is predicate-static. We just indicate that we have a
10323 -- predicate that can be treated as static.
10325 Set_Has_Static_Predicate (Typ);
10327 -- For discrete subtype, build the static predicate list
10329 if Is_Discrete_Type (Typ) then
10330 Build_Discrete_Static_Predicate (Typ, Expr, Object_Name);
10332 -- If we don't get a static predicate list, it means that we
10333 -- have a case where this is not possible, most typically in
10334 -- the case where we inherit a dynamic predicate. We do not
10335 -- consider this an error, we just leave the predicate as
10336 -- dynamic. But if we do succeed in building the list, then
10337 -- we mark the predicate as static.
10339 if No (Static_Discrete_Predicate (Typ)) then
10340 Set_Has_Static_Predicate (Typ, False);
10343 -- For real or string subtype, save predicate expression
10345 elsif Is_Real_Type (Typ) or else Is_String_Type (Typ) then
10346 Set_Static_Real_Or_String_Predicate (Typ, Expr);
10349 -- Case of dynamic predicate (expression is not predicate-static)
10352 -- Again, we don't set Has_Dynamic_Predicate_Aspect, since that
10353 -- is only set if we have an explicit Dynamic_Predicate aspect
10354 -- given. Here we may simply have a Predicate aspect where the
10355 -- expression happens not to be predicate-static.
10357 -- Emit an error when the predicate is categorized as static
10358 -- but its expression is not predicate-static.
10360 -- First a little fiddling to get a nice location for the
10361 -- message. If the expression is of the form (A and then B),
10362 -- where A is an inherited predicate, then use the right
10363 -- operand for the Sloc. This avoids getting confused by a call
10364 -- to an inherited predicate with a less convenient source
10368 while Nkind (EN) = N_And_Then
10369 and then Nkind (Left_Opnd (EN)) = N_Function_Call
10370 and then Is_Predicate_Function
10371 (Entity (Name (Left_Opnd (EN))))
10373 EN := Right_Opnd (EN);
10376 -- Now post appropriate message
10378 if Has_Static_Predicate_Aspect (Typ) then
10379 if Is_Scalar_Type (Typ) or else Is_String_Type (Typ) then
10381 ("expression is not predicate-static (RM 3.2.4(16-22))",
10385 ("static predicate requires scalar or string type", EN);
10392 Restore_Ghost_Region (Saved_GM, Saved_IGR);
10393 end Build_Predicate_Functions;
10395 ------------------------------------------
10396 -- Build_Predicate_Function_Declaration --
10397 ------------------------------------------
10399 -- WARNING: This routine manages Ghost regions. Return statements must be
10400 -- replaced by gotos which jump to the end of the routine and restore the
10403 function Build_Predicate_Function_Declaration
10404 (Typ : Entity_Id) return Node_Id
10406 Loc : constant Source_Ptr := Sloc (Typ);
10408 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
10409 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
10410 -- Save the Ghost-related attributes to restore on exit
10412 Func_Decl : Node_Id;
10413 Func_Id : Entity_Id;
10416 CRec_Typ : Entity_Id;
10417 -- The corresponding record type of Full_Typ
10419 Full_Typ : Entity_Id;
10420 -- The full view of Typ
10422 Priv_Typ : Entity_Id;
10423 -- The partial view of Typ
10425 UFull_Typ : Entity_Id;
10426 -- The underlying full view of Full_Typ
10429 -- The related type may be subject to pragma Ghost. Set the mode now to
10430 -- ensure that the predicate functions are properly marked as Ghost.
10432 Set_Ghost_Mode (Typ);
10435 Make_Defining_Identifier (Loc,
10436 Chars => New_External_Name (Chars (Typ), "Predicate"));
10438 Set_Ekind (Func_Id, E_Function);
10439 Set_Etype (Func_Id, Standard_Boolean);
10440 Set_Is_Internal (Func_Id);
10441 Set_Is_Predicate_Function (Func_Id);
10442 Set_Predicate_Function (Typ, Func_Id);
10444 -- The predicate function requires debug info when the predicates are
10445 -- subject to Source Coverage Obligations.
10447 if Opt.Generate_SCO then
10448 Set_Debug_Info_Needed (Func_Id);
10451 -- Obtain all views of the input type
10453 Get_Views (Typ, Priv_Typ, Full_Typ, UFull_Typ, CRec_Typ);
10455 -- Associate the predicate function and various flags with all views
10457 Propagate_Predicate_Attributes (Priv_Typ, From_Typ => Typ);
10458 Propagate_Predicate_Attributes (Full_Typ, From_Typ => Typ);
10459 Propagate_Predicate_Attributes (UFull_Typ, From_Typ => Typ);
10460 Propagate_Predicate_Attributes (CRec_Typ, From_Typ => Typ);
10463 Make_Function_Specification (Loc,
10464 Defining_Unit_Name => Func_Id,
10465 Parameter_Specifications => New_List (
10466 Make_Parameter_Specification (Loc,
10467 Defining_Identifier => Make_Temporary (Loc, 'I'),
10468 Parameter_Type => New_Occurrence_Of (Typ, Loc))),
10469 Result_Definition =>
10470 New_Occurrence_Of (Standard_Boolean, Loc));
10472 Func_Decl := Make_Subprogram_Declaration (Loc, Specification => Spec);
10474 Insert_After (Parent (Typ), Func_Decl);
10475 Analyze (Func_Decl);
10477 Restore_Ghost_Region (Saved_GM, Saved_IGR);
10480 end Build_Predicate_Function_Declaration;
10482 -----------------------------------------
10483 -- Check_Aspect_At_End_Of_Declarations --
10484 -----------------------------------------
10486 procedure Check_Aspect_At_End_Of_Declarations (ASN : Node_Id) is
10487 Ent : constant Entity_Id := Entity (ASN);
10488 Ident : constant Node_Id := Identifier (ASN);
10489 A_Id : constant Aspect_Id := Get_Aspect_Id (Chars (Ident));
10491 End_Decl_Expr : constant Node_Id := Entity (Ident);
10492 -- Expression to be analyzed at end of declarations
10494 Freeze_Expr : constant Node_Id := Expression (ASN);
10495 -- Expression from call to Check_Aspect_At_Freeze_Point.
10497 T : constant Entity_Id :=
10498 (if Present (Freeze_Expr)
10499 then Etype (Original_Node (Freeze_Expr))
10501 -- Type required for preanalyze call. We use the original expression to
10502 -- get the proper type, to prevent cascaded errors when the expression
10503 -- is constant-folded.
10506 -- Set False if error
10508 -- On entry to this procedure, Entity (Ident) contains a copy of the
10509 -- original expression from the aspect, saved for this purpose, and
10510 -- but Expression (Ident) is a preanalyzed copy of the expression,
10511 -- preanalyzed just after the freeze point.
10513 procedure Check_Overloaded_Name;
10514 -- For aspects whose expression is simply a name, this routine checks if
10515 -- the name is overloaded or not. If so, it verifies there is an
10516 -- interpretation that matches the entity obtained at the freeze point,
10517 -- otherwise the compiler complains.
10519 ---------------------------
10520 -- Check_Overloaded_Name --
10521 ---------------------------
10523 procedure Check_Overloaded_Name is
10525 if not Is_Overloaded (End_Decl_Expr) then
10526 Err := not Is_Entity_Name (End_Decl_Expr)
10527 or else Entity (End_Decl_Expr) /= Entity (Freeze_Expr);
10533 Index : Interp_Index;
10537 Get_First_Interp (End_Decl_Expr, Index, It);
10538 while Present (It.Typ) loop
10539 if It.Nam = Entity (Freeze_Expr) then
10544 Get_Next_Interp (Index, It);
10548 end Check_Overloaded_Name;
10550 -- Start of processing for Check_Aspect_At_End_Of_Declarations
10553 -- In an instance we do not perform the consistency check between freeze
10554 -- point and end of declarations, because it was done already in the
10555 -- analysis of the generic. Furthermore, the delayed analysis of an
10556 -- aspect of the instance may produce spurious errors when the generic
10557 -- is a child unit that references entities in the parent (which might
10558 -- not be in scope at the freeze point of the instance).
10560 if In_Instance then
10563 -- The enclosing scope may have been rewritten during expansion (.e.g. a
10564 -- task body is rewritten as a procedure) after this conformance check
10565 -- has been performed, so do not perform it again (it may not easily be
10566 -- done if full visibility of local entities is not available).
10568 elsif not Comes_From_Source (Current_Scope) then
10571 -- Case of aspects Dimension, Dimension_System and Synchronization
10573 elsif A_Id = Aspect_Synchronization then
10576 -- Case of stream attributes and Put_Image, just have to compare
10577 -- entities. However, the expression is just a possibly-overloaded
10578 -- name, so we need to verify that one of these interpretations is
10579 -- the one available at at the freeze point.
10581 elsif A_Id = Aspect_Input or else
10582 A_Id = Aspect_Output or else
10583 A_Id = Aspect_Read or else
10584 A_Id = Aspect_Write or else
10585 A_Id = Aspect_Put_Image
10587 Analyze (End_Decl_Expr);
10588 Check_Overloaded_Name;
10590 elsif A_Id = Aspect_Variable_Indexing or else
10591 A_Id = Aspect_Constant_Indexing or else
10592 A_Id = Aspect_Default_Iterator or else
10593 A_Id = Aspect_Iterator_Element or else
10594 A_Id = Aspect_Integer_Literal or else
10595 A_Id = Aspect_Real_Literal or else
10596 A_Id = Aspect_String_Literal
10598 -- Make type unfrozen before analysis, to prevent spurious errors
10599 -- about late attributes.
10601 Set_Is_Frozen (Ent, False);
10602 Analyze (End_Decl_Expr);
10603 Set_Is_Frozen (Ent, True);
10605 -- If the end of declarations comes before any other freeze point,
10606 -- the Freeze_Expr is not analyzed: no check needed.
10608 if Analyzed (Freeze_Expr) and then not In_Instance then
10609 Check_Overloaded_Name;
10617 -- In a generic context freeze nodes are not always generated, so
10618 -- analyze the expression now. If the aspect is for a type, we must
10619 -- also make its potential components accessible.
10621 if not Analyzed (Freeze_Expr) and then Inside_A_Generic then
10622 if A_Id = Aspect_Dynamic_Predicate
10623 or else A_Id = Aspect_Predicate
10626 Preanalyze_Spec_Expression (Freeze_Expr, Standard_Boolean);
10629 elsif A_Id = Aspect_Priority then
10631 Preanalyze_Spec_Expression (Freeze_Expr, Any_Integer);
10635 Preanalyze (Freeze_Expr);
10639 -- Indicate that the expression comes from an aspect specification,
10640 -- which is used in subsequent analysis even if expansion is off.
10642 Set_Parent (End_Decl_Expr, ASN);
10644 -- In a generic context the original aspect expressions have not
10645 -- been preanalyzed, so do it now. There are no conformance checks
10646 -- to perform in this case. As before, we have to make components
10647 -- visible for aspects that may reference them.
10649 if Present (Freeze_Expr) and then No (T) then
10650 if A_Id = Aspect_Dynamic_Predicate
10651 or else A_Id = Aspect_Predicate
10652 or else A_Id = Aspect_Priority
10655 Check_Aspect_At_Freeze_Point (ASN);
10659 Check_Aspect_At_Freeze_Point (ASN);
10663 -- The default values attributes may be defined in the private part,
10664 -- and the analysis of the expression may take place when only the
10665 -- partial view is visible. The expression must be scalar, so use
10666 -- the full view to resolve.
10668 elsif (A_Id = Aspect_Default_Value
10670 A_Id = Aspect_Default_Component_Value)
10671 and then Is_Private_Type (T)
10673 Preanalyze_Spec_Expression (End_Decl_Expr, Full_View (T));
10675 -- The following aspect expressions may contain references to
10676 -- components and discriminants of the type.
10678 elsif A_Id = Aspect_Dynamic_Predicate
10679 or else A_Id = Aspect_Predicate
10680 or else A_Id = Aspect_Priority
10681 or else A_Id = Aspect_CPU
10684 Preanalyze_Spec_Expression (End_Decl_Expr, T);
10687 elsif A_Id = Aspect_Predicate_Failure then
10688 Preanalyze_Spec_Expression (End_Decl_Expr, Standard_String);
10689 elsif Present (End_Decl_Expr) then
10690 Preanalyze_Spec_Expression (End_Decl_Expr, T);
10694 not Fully_Conformant_Expressions
10695 (End_Decl_Expr, Freeze_Expr, Report => True);
10698 -- Output error message if error. Force error on aspect specification
10699 -- even if there is an error on the expression itself.
10703 ("!visibility of aspect for& changes after freeze point",
10706 ("info: & is frozen here, (RM 13.1.1 (13/3))??",
10707 Freeze_Node (Ent), Ent);
10709 end Check_Aspect_At_End_Of_Declarations;
10711 ----------------------------------
10712 -- Check_Aspect_At_Freeze_Point --
10713 ----------------------------------
10715 procedure Check_Aspect_At_Freeze_Point (ASN : Node_Id) is
10716 Ident : constant Node_Id := Identifier (ASN);
10717 -- Identifier (use Entity field to save expression)
10719 Expr : constant Node_Id := Expression (ASN);
10720 -- For cases where using Entity (Identifier) doesn't work
10722 A_Id : constant Aspect_Id := Get_Aspect_Id (Chars (Ident));
10724 T : Entity_Id := Empty;
10725 -- Type required for preanalyze call
10728 -- On entry to this procedure, Entity (Ident) contains a copy of the
10729 -- original expression from the aspect, saved for this purpose.
10731 -- On exit from this procedure Entity (Ident) is unchanged, still
10732 -- containing that copy, but Expression (Ident) is a preanalyzed copy
10733 -- of the expression, preanalyzed just after the freeze point.
10735 -- Make a copy of the expression to be preanalyzed
10737 Set_Expression (ASN, New_Copy_Tree (Entity (Ident)));
10739 -- Find type for preanalyze call
10743 -- No_Aspect should be impossible
10746 raise Program_Error;
10748 -- Aspects taking an optional boolean argument
10750 when Boolean_Aspects
10751 | Library_Unit_Aspects
10753 T := Standard_Boolean;
10755 -- Aspects corresponding to attribute definition clauses
10757 when Aspect_Address =>
10758 T := RTE (RE_Address);
10760 when Aspect_Attach_Handler =>
10761 T := RTE (RE_Interrupt_ID);
10763 when Aspect_Bit_Order
10764 | Aspect_Scalar_Storage_Order
10766 T := RTE (RE_Bit_Order);
10768 when Aspect_Convention =>
10772 T := RTE (RE_CPU_Range);
10774 -- Default_Component_Value is resolved with the component type
10776 when Aspect_Default_Component_Value =>
10777 T := Component_Type (Entity (ASN));
10779 when Aspect_Default_Storage_Pool =>
10780 T := Class_Wide_Type (RTE (RE_Root_Storage_Pool));
10782 -- Default_Value is resolved with the type entity in question
10784 when Aspect_Default_Value =>
10787 when Aspect_Dispatching_Domain =>
10788 T := RTE (RE_Dispatching_Domain);
10790 when Aspect_External_Tag =>
10791 T := Standard_String;
10793 when Aspect_External_Name =>
10794 T := Standard_String;
10796 when Aspect_Link_Name =>
10797 T := Standard_String;
10799 when Aspect_Interrupt_Priority
10802 T := Standard_Integer;
10804 when Aspect_Relative_Deadline =>
10805 T := RTE (RE_Time_Span);
10807 when Aspect_Secondary_Stack_Size =>
10808 T := Standard_Integer;
10810 when Aspect_Small =>
10812 -- Note that the expression can be of any real type (not just a
10813 -- real universal literal) as long as it is a static constant.
10817 -- For a simple storage pool, we have to retrieve the type of the
10818 -- pool object associated with the aspect's corresponding attribute
10819 -- definition clause.
10821 when Aspect_Simple_Storage_Pool =>
10822 T := Etype (Expression (Aspect_Rep_Item (ASN)));
10824 when Aspect_Storage_Pool =>
10825 T := Class_Wide_Type (RTE (RE_Root_Storage_Pool));
10827 when Aspect_Alignment
10828 | Aspect_Component_Size
10829 | Aspect_Machine_Radix
10830 | Aspect_Object_Size
10832 | Aspect_Storage_Size
10833 | Aspect_Stream_Size
10834 | Aspect_Value_Size
10838 when Aspect_Linker_Section =>
10839 T := Standard_String;
10841 when Aspect_Synchronization =>
10844 -- Special case, the expression of these aspects is just an entity
10845 -- that does not need any resolution, so just analyze.
10854 Analyze (Expression (ASN));
10857 -- Same for Iterator aspects, where the expression is a function
10858 -- name. Legality rules are checked separately.
10860 when Aspect_Constant_Indexing
10861 | Aspect_Default_Iterator
10862 | Aspect_Iterator_Element
10863 | Aspect_Variable_Indexing
10865 Analyze (Expression (ASN));
10868 -- Same for Literal aspects, where the expression is a function
10869 -- name. Legality rules are checked separately. Use Expr to avoid
10870 -- losing track of the previous resolution of Expression.
10872 when Aspect_Integer_Literal
10873 | Aspect_Real_Literal
10874 | Aspect_String_Literal
10876 Set_Entity (Expression (ASN), Entity (Expr));
10877 Set_Etype (Expression (ASN), Etype (Expr));
10878 Set_Is_Overloaded (Expression (ASN), False);
10879 Analyze (Expression (ASN));
10882 -- Ditto for Iterable, legality checks in Validate_Iterable_Aspect.
10884 when Aspect_Iterable =>
10888 Cursor : constant Entity_Id := Get_Cursor_Type (ASN, T);
10893 if Cursor = Any_Type then
10897 Assoc := First (Component_Associations (Expression (ASN)));
10898 while Present (Assoc) loop
10899 Expr := Expression (Assoc);
10902 if not Error_Posted (Expr) then
10903 Resolve_Iterable_Operation
10904 (Expr, Cursor, T, Chars (First (Choices (Assoc))));
10913 when Aspect_Aggregate =>
10914 Resolve_Aspect_Aggregate (Entity (ASN), Expr);
10917 -- Invariant/Predicate take boolean expressions
10919 when Aspect_Dynamic_Predicate
10922 | Aspect_Static_Predicate
10923 | Aspect_Type_Invariant
10925 T := Standard_Boolean;
10927 when Aspect_Predicate_Failure =>
10928 T := Standard_String;
10930 -- Here is the list of aspects that don't require delay analysis
10932 when Aspect_Abstract_State
10934 | Aspect_Async_Readers
10935 | Aspect_Async_Writers
10936 | Aspect_Constant_After_Elaboration
10937 | Aspect_Contract_Cases
10938 | Aspect_Default_Initial_Condition
10941 | Aspect_Dimension_System
10942 | Aspect_Effective_Reads
10943 | Aspect_Effective_Writes
10944 | Aspect_Extensions_Visible
10947 | Aspect_Implicit_Dereference
10948 | Aspect_Initial_Condition
10949 | Aspect_Initializes
10950 | Aspect_Max_Entry_Queue_Depth
10951 | Aspect_Max_Entry_Queue_Length
10952 | Aspect_Max_Queue_Length
10953 | Aspect_No_Caching
10954 | Aspect_Obsolescent
10957 | Aspect_Postcondition
10959 | Aspect_Precondition
10960 | Aspect_Refined_Depends
10961 | Aspect_Refined_Global
10962 | Aspect_Refined_Post
10963 | Aspect_Refined_State
10964 | Aspect_Relaxed_Initialization
10965 | Aspect_SPARK_Mode
10966 | Aspect_Subprogram_Variant
10969 | Aspect_Unimplemented
10970 | Aspect_Unsuppress
10971 | Aspect_Volatile_Function
10973 raise Program_Error;
10977 -- Do the preanalyze call
10979 if Present (Expression (ASN)) then
10980 Preanalyze_Spec_Expression (Expression (ASN), T);
10982 end Check_Aspect_At_Freeze_Point;
10984 -----------------------------------
10985 -- Check_Constant_Address_Clause --
10986 -----------------------------------
10988 procedure Check_Constant_Address_Clause
10992 procedure Check_At_Constant_Address (Nod : Node_Id);
10993 -- Checks that the given node N represents a name whose 'Address is
10994 -- constant (in the same sense as OK_Constant_Address_Clause, i.e. the
10995 -- address value is the same at the point of declaration of U_Ent and at
10996 -- the time of elaboration of the address clause.
10998 procedure Check_Expr_Constants (Nod : Node_Id);
10999 -- Checks that Nod meets the requirements for a constant address clause
11000 -- in the sense of the enclosing procedure.
11002 procedure Check_List_Constants (Lst : List_Id);
11003 -- Check that all elements of list Lst meet the requirements for a
11004 -- constant address clause in the sense of the enclosing procedure.
11006 -------------------------------
11007 -- Check_At_Constant_Address --
11008 -------------------------------
11010 procedure Check_At_Constant_Address (Nod : Node_Id) is
11012 if Is_Entity_Name (Nod) then
11013 if Present (Address_Clause (Entity ((Nod)))) then
11015 ("invalid address clause for initialized object &!",
11018 ("address for& cannot depend on another address clause! "
11019 & "(RM 13.1(22))!", Nod, U_Ent);
11021 elsif In_Same_Source_Unit (Entity (Nod), U_Ent)
11022 and then Sloc (U_Ent) < Sloc (Entity (Nod))
11025 ("invalid address clause for initialized object &!",
11027 Error_Msg_Node_2 := U_Ent;
11029 ("\& must be defined before & (RM 13.1(22))!",
11030 Nod, Entity (Nod));
11033 elsif Nkind (Nod) = N_Selected_Component then
11035 T : constant Entity_Id := Etype (Prefix (Nod));
11038 if (Is_Record_Type (T)
11039 and then Has_Discriminants (T))
11041 (Is_Access_Type (T)
11042 and then Is_Record_Type (Designated_Type (T))
11043 and then Has_Discriminants (Designated_Type (T)))
11046 ("invalid address clause for initialized object &!",
11049 ("\address cannot depend on component of discriminated "
11050 & "record (RM 13.1(22))!", Nod);
11052 Check_At_Constant_Address (Prefix (Nod));
11056 elsif Nkind (Nod) = N_Indexed_Component then
11057 Check_At_Constant_Address (Prefix (Nod));
11058 Check_List_Constants (Expressions (Nod));
11061 Check_Expr_Constants (Nod);
11063 end Check_At_Constant_Address;
11065 --------------------------
11066 -- Check_Expr_Constants --
11067 --------------------------
11069 procedure Check_Expr_Constants (Nod : Node_Id) is
11070 Loc_U_Ent : constant Source_Ptr := Sloc (U_Ent);
11071 Ent : Entity_Id := Empty;
11074 if Nkind (Nod) in N_Has_Etype
11075 and then Etype (Nod) = Any_Type
11080 case Nkind (Nod) is
11086 when N_Expanded_Name
11089 Ent := Entity (Nod);
11091 -- We need to look at the original node if it is different
11092 -- from the node, since we may have rewritten things and
11093 -- substituted an identifier representing the rewrite.
11095 if Is_Rewrite_Substitution (Nod) then
11096 Check_Expr_Constants (Original_Node (Nod));
11098 -- If the node is an object declaration without initial
11099 -- value, some code has been expanded, and the expression
11100 -- is not constant, even if the constituents might be
11101 -- acceptable, as in A'Address + offset.
11103 if Ekind (Ent) = E_Variable
11105 Nkind (Declaration_Node (Ent)) = N_Object_Declaration
11107 No (Expression (Declaration_Node (Ent)))
11110 ("invalid address clause for initialized object &!",
11113 -- If entity is constant, it may be the result of expanding
11114 -- a check. We must verify that its declaration appears
11115 -- before the object in question, else we also reject the
11118 elsif Ekind (Ent) = E_Constant
11119 and then In_Same_Source_Unit (Ent, U_Ent)
11120 and then Sloc (Ent) > Loc_U_Ent
11123 ("invalid address clause for initialized object &!",
11130 -- Otherwise look at the identifier and see if it is OK
11132 if Ekind (Ent) in E_Named_Integer | E_Named_Real
11133 or else Is_Type (Ent)
11137 elsif Ekind (Ent) in E_Constant | E_In_Parameter then
11139 -- This is the case where we must have Ent defined before
11140 -- U_Ent. Clearly if they are in different units this
11141 -- requirement is met since the unit containing Ent is
11142 -- already processed.
11144 if not In_Same_Source_Unit (Ent, U_Ent) then
11147 -- Otherwise location of Ent must be before the location
11148 -- of U_Ent, that's what prior defined means.
11150 elsif Sloc (Ent) < Loc_U_Ent then
11155 ("invalid address clause for initialized object &!",
11157 Error_Msg_Node_2 := U_Ent;
11159 ("\& must be defined before & (RM 13.1(22))!",
11163 elsif Nkind (Original_Node (Nod)) = N_Function_Call then
11164 Check_Expr_Constants (Original_Node (Nod));
11168 ("invalid address clause for initialized object &!",
11171 if Comes_From_Source (Ent) then
11173 ("\reference to variable& not allowed"
11174 & " (RM 13.1(22))!", Nod, Ent);
11177 ("non-static expression not allowed"
11178 & " (RM 13.1(22))!", Nod);
11182 when N_Integer_Literal =>
11184 -- If this is a rewritten unchecked conversion, in a system
11185 -- where Address is an integer type, always use the base type
11186 -- for a literal value. This is user-friendly and prevents
11187 -- order-of-elaboration issues with instances of unchecked
11190 if Nkind (Original_Node (Nod)) = N_Function_Call then
11191 Set_Etype (Nod, Base_Type (Etype (Nod)));
11194 when N_Character_Literal
11201 Check_Expr_Constants (Low_Bound (Nod));
11202 Check_Expr_Constants (High_Bound (Nod));
11204 when N_Explicit_Dereference =>
11205 Check_Expr_Constants (Prefix (Nod));
11207 when N_Indexed_Component =>
11208 Check_Expr_Constants (Prefix (Nod));
11209 Check_List_Constants (Expressions (Nod));
11212 Check_Expr_Constants (Prefix (Nod));
11213 Check_Expr_Constants (Discrete_Range (Nod));
11215 when N_Selected_Component =>
11216 Check_Expr_Constants (Prefix (Nod));
11218 when N_Attribute_Reference =>
11219 if Attribute_Name (Nod) in Name_Address
11221 | Name_Unchecked_Access
11222 | Name_Unrestricted_Access
11224 Check_At_Constant_Address (Prefix (Nod));
11226 -- Normally, System'To_Address will have been transformed into
11227 -- an Unchecked_Conversion, but in -gnatc mode, it will not,
11228 -- and we don't want to give an error, because the whole point
11229 -- of 'To_Address is that it is static.
11231 elsif Attribute_Name (Nod) = Name_To_Address then
11232 pragma Assert (Operating_Mode = Check_Semantics);
11236 Check_Expr_Constants (Prefix (Nod));
11237 Check_List_Constants (Expressions (Nod));
11240 when N_Aggregate =>
11241 Check_List_Constants (Component_Associations (Nod));
11242 Check_List_Constants (Expressions (Nod));
11244 when N_Component_Association =>
11245 Check_Expr_Constants (Expression (Nod));
11247 when N_Extension_Aggregate =>
11248 Check_Expr_Constants (Ancestor_Part (Nod));
11249 Check_List_Constants (Component_Associations (Nod));
11250 Check_List_Constants (Expressions (Nod));
11256 | N_Membership_Test
11259 Check_Expr_Constants (Left_Opnd (Nod));
11260 Check_Expr_Constants (Right_Opnd (Nod));
11263 Check_Expr_Constants (Right_Opnd (Nod));
11266 | N_Qualified_Expression
11267 | N_Type_Conversion
11268 | N_Unchecked_Type_Conversion
11270 Check_Expr_Constants (Expression (Nod));
11272 when N_Function_Call =>
11273 if not Is_Pure (Entity (Name (Nod))) then
11275 ("invalid address clause for initialized object &!",
11279 ("\function & is not pure (RM 13.1(22))!",
11280 Nod, Entity (Name (Nod)));
11283 Check_List_Constants (Parameter_Associations (Nod));
11286 when N_Parameter_Association =>
11287 Check_Expr_Constants (Explicit_Actual_Parameter (Nod));
11291 ("invalid address clause for initialized object &!",
11294 ("\must be constant defined before& (RM 13.1(22))!",
11297 end Check_Expr_Constants;
11299 --------------------------
11300 -- Check_List_Constants --
11301 --------------------------
11303 procedure Check_List_Constants (Lst : List_Id) is
11307 if Present (Lst) then
11308 Nod1 := First (Lst);
11309 while Present (Nod1) loop
11310 Check_Expr_Constants (Nod1);
11314 end Check_List_Constants;
11316 -- Start of processing for Check_Constant_Address_Clause
11319 -- If rep_clauses are to be ignored, no need for legality checks. In
11320 -- particular, no need to pester user about rep clauses that violate the
11321 -- rule on constant addresses, given that these clauses will be removed
11322 -- by Freeze before they reach the back end. Similarly in CodePeer mode,
11323 -- we want to relax these checks.
11325 if not Ignore_Rep_Clauses and not CodePeer_Mode then
11326 Check_Expr_Constants (Expr);
11328 end Check_Constant_Address_Clause;
11330 ---------------------------
11331 -- Check_Pool_Size_Clash --
11332 ---------------------------
11334 procedure Check_Pool_Size_Clash (Ent : Entity_Id; SP, SS : Node_Id) is
11338 -- We need to find out which one came first. Note that in the case of
11339 -- aspects mixed with pragmas there are cases where the processing order
11340 -- is reversed, which is why we do the check here.
11342 if Sloc (SP) < Sloc (SS) then
11343 Error_Msg_Sloc := Sloc (SP);
11345 Error_Msg_NE ("Storage_Pool previously given for&#", Post, Ent);
11348 Error_Msg_Sloc := Sloc (SS);
11350 Error_Msg_NE ("Storage_Size previously given for&#", Post, Ent);
11354 ("\cannot have Storage_Size and Storage_Pool (RM 13.11(3))", Post);
11355 end Check_Pool_Size_Clash;
11357 ----------------------------------------
11358 -- Check_Record_Representation_Clause --
11359 ----------------------------------------
11361 procedure Check_Record_Representation_Clause (N : Node_Id) is
11362 Loc : constant Source_Ptr := Sloc (N);
11363 Ident : constant Node_Id := Identifier (N);
11364 Rectype : Entity_Id;
11367 Fbit : Uint := No_Uint;
11368 Lbit : Uint := No_Uint;
11369 Hbit : Uint := Uint_0;
11373 Max_Bit_So_Far : Uint;
11374 -- Records the maximum bit position so far. If all field positions
11375 -- are monotonically increasing, then we can skip the circuit for
11376 -- checking for overlap, since no overlap is possible.
11378 Tagged_Parent : Entity_Id := Empty;
11379 -- This is set in the case of an extension for which we have either a
11380 -- size clause or Is_Fully_Repped_Tagged_Type True (indicating that all
11381 -- components are positioned by record representation clauses) on the
11382 -- parent type. In this case we check for overlap between components of
11383 -- this tagged type and the parent component. Tagged_Parent will point
11384 -- to this parent type. For all other cases, Tagged_Parent is Empty.
11386 Parent_Last_Bit : Uint := No_Uint; -- init to avoid warning
11387 -- Relevant only if Tagged_Parent is set, Parent_Last_Bit indicates the
11388 -- last bit position for any field in the parent type. We only need to
11389 -- check overlap for fields starting below this point.
11391 Overlap_Check_Required : Boolean;
11392 -- Used to keep track of whether or not an overlap check is required
11394 Overlap_Detected : Boolean := False;
11395 -- Set True if an overlap is detected
11397 Ccount : Natural := 0;
11398 -- Number of component clauses in record rep clause
11400 procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id);
11401 -- Given two entities for record components or discriminants, checks
11402 -- if they have overlapping component clauses and issues errors if so.
11404 procedure Find_Component;
11405 -- Finds component entity corresponding to current component clause (in
11406 -- CC), and sets Comp to the entity, and Fbit/Lbit to the zero origin
11407 -- start/stop bits for the field. If there is no matching component or
11408 -- if the matching component does not have a component clause, then
11409 -- that's an error and Comp is set to Empty, but no error message is
11410 -- issued, since the message was already given. Comp is also set to
11411 -- Empty if the current "component clause" is in fact a pragma.
11413 procedure Record_Hole_Check
11414 (Rectype : Entity_Id; After_Last : out Uint; Warn : Boolean);
11415 -- Checks for gaps in the given Rectype. Compute After_Last, the bit
11416 -- number after the last component. Warn is True on the initial call,
11417 -- and warnings are given for gaps. For a type extension, this is called
11418 -- recursively to compute After_Last for the parent type; in this case
11419 -- Warn is False and the warnings are suppressed.
11421 procedure Component_Order_Check (Rectype : Entity_Id);
11422 -- Check that the order of component clauses agrees with the order of
11423 -- component declarations, and that the component clauses are given in
11424 -- increasing order of bit offset.
11426 -----------------------------
11427 -- Check_Component_Overlap --
11428 -----------------------------
11430 procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id) is
11431 CC1 : constant Node_Id := Component_Clause (C1_Ent);
11432 CC2 : constant Node_Id := Component_Clause (C2_Ent);
11435 if Present (CC1) and then Present (CC2) then
11437 -- Exclude odd case where we have two tag components in the same
11438 -- record, both at location zero. This seems a bit strange, but
11439 -- it seems to happen in some circumstances, perhaps on an error.
11441 if Chars (C1_Ent) = Name_uTag then
11445 -- Here we check if the two fields overlap
11448 S1 : constant Uint := Component_Bit_Offset (C1_Ent);
11449 S2 : constant Uint := Component_Bit_Offset (C2_Ent);
11450 E1 : constant Uint := S1 + Esize (C1_Ent);
11451 E2 : constant Uint := S2 + Esize (C2_Ent);
11454 if E2 <= S1 or else E1 <= S2 then
11457 Error_Msg_Node_2 := Component_Name (CC2);
11458 Error_Msg_Sloc := Sloc (Error_Msg_Node_2);
11459 Error_Msg_Node_1 := Component_Name (CC1);
11461 ("component& overlaps & #", Component_Name (CC1));
11462 Overlap_Detected := True;
11466 end Check_Component_Overlap;
11468 ---------------------------
11469 -- Component_Order_Check --
11470 ---------------------------
11472 procedure Component_Order_Check (Rectype : Entity_Id) is
11473 Comp : Entity_Id := First_Component (Rectype);
11474 Clause : Node_Id := First (Component_Clauses (N));
11475 Prev_Bit_Offset : Uint := Uint_0;
11476 OOO : constant String :=
11477 "?component clause out of order with respect to declaration";
11480 -- Step Comp through components and Clause through component clauses,
11481 -- skipping pragmas. We ignore discriminants and variant parts,
11482 -- because we get most of the benefit from the plain vanilla
11483 -- component cases, without the extra complexity. If we find a Comp
11484 -- and Clause that don't match, give a warning on both and quit. If
11485 -- we find two subsequent clauses out of order by bit layout, give
11486 -- warning and quit. On each iteration, Prev_Bit_Offset is the one
11487 -- from the previous iteration (or 0 to start).
11489 while Present (Comp) and then Present (Clause) loop
11490 if Nkind (Clause) = N_Component_Clause
11491 and then Ekind (Entity (Component_Name (Clause))) = E_Component
11493 if Entity (Component_Name (Clause)) /= Comp then
11494 Error_Msg_N (OOO, Comp);
11495 Error_Msg_N (OOO, Clause);
11499 if not Reverse_Bit_Order (Rectype)
11500 and then not Reverse_Storage_Order (Rectype)
11501 and then Component_Bit_Offset (Comp) < Prev_Bit_Offset
11503 Error_Msg_N ("?memory layout out of order", Clause);
11507 Prev_Bit_Offset := Component_Bit_Offset (Comp);
11508 Next_Component (Comp);
11513 end Component_Order_Check;
11515 --------------------
11516 -- Find_Component --
11517 --------------------
11519 procedure Find_Component is
11521 procedure Search_Component (R : Entity_Id);
11522 -- Search components of R for a match. If found, Comp is set
11524 ----------------------
11525 -- Search_Component --
11526 ----------------------
11528 procedure Search_Component (R : Entity_Id) is
11530 Comp := First_Component_Or_Discriminant (R);
11531 while Present (Comp) loop
11533 -- Ignore error of attribute name for component name (we
11534 -- already gave an error message for this, so no need to
11537 if Nkind (Component_Name (CC)) = N_Attribute_Reference then
11540 exit when Chars (Comp) = Chars (Component_Name (CC));
11543 Next_Component_Or_Discriminant (Comp);
11545 end Search_Component;
11547 -- Start of processing for Find_Component
11550 -- Return with Comp set to Empty if we have a pragma
11552 if Nkind (CC) = N_Pragma then
11557 -- Search current record for matching component
11559 Search_Component (Rectype);
11561 -- If not found, maybe component of base type discriminant that is
11562 -- absent from statically constrained first subtype.
11565 Search_Component (Base_Type (Rectype));
11568 -- If no component, or the component does not reference the component
11569 -- clause in question, then there was some previous error for which
11570 -- we already gave a message, so just return with Comp Empty.
11572 if No (Comp) or else Component_Clause (Comp) /= CC then
11573 Check_Error_Detected;
11576 -- Normal case where we have a component clause
11579 Fbit := Component_Bit_Offset (Comp);
11580 Lbit := Fbit + Esize (Comp) - 1;
11582 end Find_Component;
11584 -----------------------
11585 -- Record_Hole_Check --
11586 -----------------------
11588 procedure Record_Hole_Check
11589 (Rectype : Entity_Id; After_Last : out Uint; Warn : Boolean)
11591 Decl : constant Node_Id := Declaration_Node (Base_Type (Rectype));
11592 -- Full declaration of record type
11594 procedure Check_Component_List
11599 -- Check component list CL for holes. DS is a list of discriminant
11600 -- specifications to be included in the consideration of components.
11601 -- Sbit is the starting bit, which is zero if there are no preceding
11602 -- components (before a variant part, or a parent type, or a tag
11603 -- field). If there are preceding components, Sbit is the bit just
11604 -- after the last such component. Abit is set to the bit just after
11605 -- the last component of DS and CL.
11607 --------------------------
11608 -- Check_Component_List --
11609 --------------------------
11611 procedure Check_Component_List
11620 Compl := Integer (List_Length (Component_Items (CL)));
11622 if DS /= No_List then
11623 Compl := Compl + Integer (List_Length (DS));
11627 Comps : array (Natural range 0 .. Compl) of Entity_Id;
11628 -- Gather components (zero entry is for sort routine)
11630 Ncomps : Natural := 0;
11631 -- Number of entries stored in Comps (starting at Comps (1))
11634 -- One component item or discriminant specification
11637 -- Starting bit for next component
11640 -- Component entity
11645 function Lt (Op1, Op2 : Natural) return Boolean;
11646 -- Compare routine for Sort
11648 procedure Move (From : Natural; To : Natural);
11649 -- Move routine for Sort
11651 package Sorting is new GNAT.Heap_Sort_G (Move, Lt);
11657 function Lt (Op1, Op2 : Natural) return Boolean is
11659 return Component_Bit_Offset (Comps (Op1))
11660 < Component_Bit_Offset (Comps (Op2));
11667 procedure Move (From : Natural; To : Natural) is
11669 Comps (To) := Comps (From);
11673 -- Gather discriminants into Comp
11675 if DS /= No_List then
11676 Citem := First (DS);
11677 while Present (Citem) loop
11678 if Nkind (Citem) = N_Discriminant_Specification then
11680 Ent : constant Entity_Id :=
11681 Defining_Identifier (Citem);
11683 if Ekind (Ent) = E_Discriminant then
11684 Ncomps := Ncomps + 1;
11685 Comps (Ncomps) := Ent;
11694 -- Gather component entities into Comp
11696 Citem := First (Component_Items (CL));
11697 while Present (Citem) loop
11698 if Nkind (Citem) = N_Component_Declaration then
11699 Ncomps := Ncomps + 1;
11700 Comps (Ncomps) := Defining_Identifier (Citem);
11706 -- Now sort the component entities based on the first bit.
11707 -- Note we already know there are no overlapping components.
11709 Sorting.Sort (Ncomps);
11711 -- Loop through entries checking for holes
11714 for J in 1 .. Ncomps loop
11716 pragma Annotate (CodePeer, Modified, CEnt);
11719 CBO : constant Uint := Component_Bit_Offset (CEnt);
11722 -- Skip components with unknown offsets
11724 if CBO /= No_Uint and then CBO >= 0 then
11725 Error_Msg_Uint_1 := CBO - Nbit;
11727 if Warn and then Error_Msg_Uint_1 > 0 then
11729 ("?H?^-bit gap before component&",
11730 Component_Name (Component_Clause (CEnt)),
11734 Nbit := CBO + Esize (CEnt);
11739 -- Set Abit to just after the last nonvariant component
11743 -- Process variant parts recursively if present. Set Abit to
11744 -- the maximum for all variant parts.
11746 if Present (Variant_Part (CL)) then
11748 Var_Start : constant Uint := Nbit;
11750 Variant := First (Variants (Variant_Part (CL)));
11751 while Present (Variant) loop
11752 Check_Component_List
11753 (No_List, Component_List (Variant), Var_Start, Nbit);
11755 if Nbit > Abit then
11762 end Check_Component_List;
11765 -- Starting bit for call to Check_Component_List. Zero for an
11766 -- untagged type. The size of the Tag for a nonderived tagged
11767 -- type. Parent size for a type extension.
11769 Record_Definition : Node_Id;
11770 -- Record_Definition containing Component_List to pass to
11771 -- Check_Component_List.
11773 -- Start of processing for Record_Hole_Check
11776 if Is_Tagged_Type (Rectype) then
11777 Sbit := UI_From_Int (System_Address_Size);
11782 After_Last := Uint_0;
11784 if Nkind (Decl) = N_Full_Type_Declaration then
11785 Record_Definition := Type_Definition (Decl);
11787 -- If we have a record extension, set Sbit to point after the last
11788 -- component of the parent type, by calling Record_Hole_Check
11791 if Nkind (Record_Definition) = N_Derived_Type_Definition then
11792 Record_Definition := Record_Extension_Part (Record_Definition);
11793 Record_Hole_Check (Underlying_Type (Parent_Subtype (Rectype)),
11794 After_Last => Sbit, Warn => False);
11797 if Nkind (Record_Definition) = N_Record_Definition then
11798 Check_Component_List
11799 (Discriminant_Specifications (Decl),
11800 Component_List (Record_Definition),
11804 end Record_Hole_Check;
11806 -- Start of processing for Check_Record_Representation_Clause
11810 Rectype := Entity (Ident);
11812 if Rectype = Any_Type then
11816 Rectype := Underlying_Type (Rectype);
11818 -- See if we have a fully repped derived tagged type
11821 PS : constant Entity_Id := Parent_Subtype (Rectype);
11824 if Present (PS) and then Known_Static_RM_Size (PS) then
11825 Tagged_Parent := PS;
11826 Parent_Last_Bit := RM_Size (PS) - 1;
11828 elsif Present (PS) and then Is_Fully_Repped_Tagged_Type (PS) then
11829 Tagged_Parent := PS;
11831 -- Find maximum bit of any component of the parent type
11833 Parent_Last_Bit := UI_From_Int (System_Address_Size - 1);
11834 Pcomp := First_Entity (Tagged_Parent);
11835 while Present (Pcomp) loop
11836 if Ekind (Pcomp) in E_Discriminant | E_Component then
11837 if Component_Bit_Offset (Pcomp) /= No_Uint
11838 and then Known_Static_Esize (Pcomp)
11843 Component_Bit_Offset (Pcomp) + Esize (Pcomp) - 1);
11847 -- Skip anonymous types generated for constrained array
11848 -- or record components.
11853 Next_Entity (Pcomp);
11858 -- All done if no component clauses
11860 CC := First (Component_Clauses (N));
11866 -- If a tag is present, then create a component clause that places it
11867 -- at the start of the record (otherwise gigi may place it after other
11868 -- fields that have rep clauses).
11870 Fent := First_Entity (Rectype);
11872 if Nkind (Fent) = N_Defining_Identifier
11873 and then Chars (Fent) = Name_uTag
11875 Set_Component_Bit_Offset (Fent, Uint_0);
11876 Set_Normalized_Position (Fent, Uint_0);
11877 Set_Normalized_First_Bit (Fent, Uint_0);
11878 Set_Normalized_Position_Max (Fent, Uint_0);
11879 Init_Esize (Fent, System_Address_Size);
11881 Set_Component_Clause (Fent,
11882 Make_Component_Clause (Loc,
11883 Component_Name => Make_Identifier (Loc, Name_uTag),
11885 Position => Make_Integer_Literal (Loc, Uint_0),
11886 First_Bit => Make_Integer_Literal (Loc, Uint_0),
11888 Make_Integer_Literal (Loc,
11889 UI_From_Int (System_Address_Size - 1))));
11891 Ccount := Ccount + 1;
11894 Max_Bit_So_Far := Uint_Minus_1;
11895 Overlap_Check_Required := False;
11897 -- Process the component clauses
11899 while Present (CC) loop
11902 if Present (Comp) then
11903 Ccount := Ccount + 1;
11905 -- We need a full overlap check if record positions non-monotonic
11907 if Fbit <= Max_Bit_So_Far then
11908 Overlap_Check_Required := True;
11911 Max_Bit_So_Far := Lbit;
11913 -- Check bit position out of range of specified size
11915 if Has_Size_Clause (Rectype)
11916 and then RM_Size (Rectype) <= Lbit
11918 Error_Msg_Uint_1 := RM_Size (Rectype);
11919 Error_Msg_Uint_2 := Lbit + 1;
11920 Error_Msg_N ("bit number out of range of specified "
11921 & "size (expected ^, got ^)",
11924 -- Check for overlap with tag or parent component
11927 if Is_Tagged_Type (Rectype)
11928 and then Fbit < System_Address_Size
11931 ("component overlaps tag field of&",
11932 Component_Name (CC), Rectype);
11933 Overlap_Detected := True;
11935 elsif Present (Tagged_Parent)
11936 and then Fbit <= Parent_Last_Bit
11939 ("component overlaps parent field of&",
11940 Component_Name (CC), Rectype);
11941 Overlap_Detected := True;
11944 if Hbit < Lbit then
11953 -- Now that we have processed all the component clauses, check for
11954 -- overlap. We have to leave this till last, since the components can
11955 -- appear in any arbitrary order in the representation clause.
11957 -- We do not need this check if all specified ranges were monotonic,
11958 -- as recorded by Overlap_Check_Required being False at this stage.
11960 -- This first section checks if there are any overlapping entries at
11961 -- all. It does this by sorting all entries and then seeing if there are
11962 -- any overlaps. If there are none, then that is decisive, but if there
11963 -- are overlaps, they may still be OK (they may result from fields in
11964 -- different variants).
11966 if Overlap_Check_Required then
11967 Overlap_Check1 : declare
11969 OC_Fbit : array (0 .. Ccount) of Uint;
11970 -- First-bit values for component clauses, the value is the offset
11971 -- of the first bit of the field from start of record. The zero
11972 -- entry is for use in sorting.
11974 OC_Lbit : array (0 .. Ccount) of Uint;
11975 -- Last-bit values for component clauses, the value is the offset
11976 -- of the last bit of the field from start of record. The zero
11977 -- entry is for use in sorting.
11979 OC_Count : Natural := 0;
11980 -- Count of entries in OC_Fbit and OC_Lbit
11982 function OC_Lt (Op1, Op2 : Natural) return Boolean;
11983 -- Compare routine for Sort
11985 procedure OC_Move (From : Natural; To : Natural);
11986 -- Move routine for Sort
11988 package Sorting is new GNAT.Heap_Sort_G (OC_Move, OC_Lt);
11994 function OC_Lt (Op1, Op2 : Natural) return Boolean is
11996 return OC_Fbit (Op1) < OC_Fbit (Op2);
12003 procedure OC_Move (From : Natural; To : Natural) is
12005 OC_Fbit (To) := OC_Fbit (From);
12006 OC_Lbit (To) := OC_Lbit (From);
12009 -- Start of processing for Overlap_Check
12012 CC := First (Component_Clauses (N));
12013 while Present (CC) loop
12015 -- Exclude component clause already marked in error
12017 if not Error_Posted (CC) then
12020 if Present (Comp) then
12021 OC_Count := OC_Count + 1;
12022 OC_Fbit (OC_Count) := Fbit;
12023 OC_Lbit (OC_Count) := Lbit;
12030 Sorting.Sort (OC_Count);
12032 Overlap_Check_Required := False;
12033 for J in 1 .. OC_Count - 1 loop
12034 if OC_Lbit (J) >= OC_Fbit (J + 1) then
12035 Overlap_Check_Required := True;
12039 end Overlap_Check1;
12042 -- If Overlap_Check_Required is still True, then we have to do the full
12043 -- scale overlap check, since we have at least two fields that do
12044 -- overlap, and we need to know if that is OK since they are in
12045 -- different variant, or whether we have a definite problem.
12047 if Overlap_Check_Required then
12048 Overlap_Check2 : declare
12049 C1_Ent, C2_Ent : Entity_Id;
12050 -- Entities of components being checked for overlap
12053 -- Component_List node whose Component_Items are being checked
12056 -- Component declaration for component being checked
12059 C1_Ent := First_Entity (Base_Type (Rectype));
12061 -- Loop through all components in record. For each component check
12062 -- for overlap with any of the preceding elements on the component
12063 -- list containing the component and also, if the component is in
12064 -- a variant, check against components outside the case structure.
12065 -- This latter test is repeated recursively up the variant tree.
12067 Main_Component_Loop : while Present (C1_Ent) loop
12068 if Ekind (C1_Ent) not in E_Component | E_Discriminant then
12069 goto Continue_Main_Component_Loop;
12072 -- Skip overlap check if entity has no declaration node. This
12073 -- happens with discriminants in constrained derived types.
12074 -- Possibly we are missing some checks as a result, but that
12075 -- does not seem terribly serious.
12077 if No (Declaration_Node (C1_Ent)) then
12078 goto Continue_Main_Component_Loop;
12081 Clist := Parent (List_Containing (Declaration_Node (C1_Ent)));
12083 -- Loop through component lists that need checking. Check the
12084 -- current component list and all lists in variants above us.
12086 Component_List_Loop : loop
12088 -- If derived type definition, go to full declaration
12089 -- If at outer level, check discriminants if there are any.
12091 if Nkind (Clist) = N_Derived_Type_Definition then
12092 Clist := Parent (Clist);
12095 -- Outer level of record definition, check discriminants
12096 -- but be careful not to flag a non-girder discriminant
12097 -- and the girder discriminant it renames as overlapping.
12099 if Nkind (Clist) in N_Full_Type_Declaration
12100 | N_Private_Type_Declaration
12102 if Has_Discriminants (Defining_Identifier (Clist)) then
12104 First_Discriminant (Defining_Identifier (Clist));
12105 while Present (C2_Ent) loop
12107 Original_Record_Component (C1_Ent) =
12108 Original_Record_Component (C2_Ent);
12109 Check_Component_Overlap (C1_Ent, C2_Ent);
12110 Next_Discriminant (C2_Ent);
12114 -- Record extension case
12116 elsif Nkind (Clist) = N_Derived_Type_Definition then
12119 -- Otherwise check one component list
12122 Citem := First (Component_Items (Clist));
12123 while Present (Citem) loop
12124 if Nkind (Citem) = N_Component_Declaration then
12125 C2_Ent := Defining_Identifier (Citem);
12126 exit when C1_Ent = C2_Ent;
12127 Check_Component_Overlap (C1_Ent, C2_Ent);
12134 -- Check for variants above us (the parent of the Clist can
12135 -- be a variant, in which case its parent is a variant part,
12136 -- and the parent of the variant part is a component list
12137 -- whose components must all be checked against the current
12138 -- component for overlap).
12140 if Nkind (Parent (Clist)) = N_Variant then
12141 Clist := Parent (Parent (Parent (Clist)));
12143 -- Check for possible discriminant part in record, this
12144 -- is treated essentially as another level in the
12145 -- recursion. For this case the parent of the component
12146 -- list is the record definition, and its parent is the
12147 -- full type declaration containing the discriminant
12150 elsif Nkind (Parent (Clist)) = N_Record_Definition then
12151 Clist := Parent (Parent ((Clist)));
12153 -- If neither of these two cases, we are at the top of
12157 exit Component_List_Loop;
12159 end loop Component_List_Loop;
12161 <<Continue_Main_Component_Loop>>
12162 Next_Entity (C1_Ent);
12164 end loop Main_Component_Loop;
12165 end Overlap_Check2;
12168 -- Skip the following warnings if overlap was detected; programmer
12169 -- should fix the errors first.
12171 if not Overlap_Detected then
12172 -- Check for record holes (gaps)
12174 if Warn_On_Record_Holes then
12178 Record_Hole_Check (Rectype, After_Last => Ignore, Warn => True);
12182 -- Check for out-of-order component clauses
12184 if Warn_On_Component_Order then
12185 Component_Order_Check (Rectype);
12189 -- For records that have component clauses for all components, and whose
12190 -- size is less than or equal to 32, and which can be fully packed, we
12191 -- need to know the size in the front end to activate possible packed
12192 -- array processing where the component type is a record.
12194 -- At this stage Hbit + 1 represents the first unused bit from all the
12195 -- component clauses processed, so if the component clauses are
12196 -- complete, then this is the length of the record.
12198 -- For records longer than System.Storage_Unit, and for those where not
12199 -- all components have component clauses, the back end determines the
12200 -- length (it may for example be appropriate to round up the size
12201 -- to some convenient boundary, based on alignment considerations, etc).
12203 if Unknown_RM_Size (Rectype)
12204 and then Hbit + 1 <= 32
12205 and then not Strict_Alignment (Rectype)
12208 -- Nothing to do if at least one component has no component clause
12210 Comp := First_Component_Or_Discriminant (Rectype);
12211 while Present (Comp) loop
12212 exit when No (Component_Clause (Comp));
12213 Next_Component_Or_Discriminant (Comp);
12216 -- If we fall out of loop, all components have component clauses
12217 -- and so we can set the size to the maximum value.
12220 Set_RM_Size (Rectype, Hbit + 1);
12223 end Check_Record_Representation_Clause;
12229 procedure Check_Size
12233 Biased : out Boolean)
12235 procedure Size_Too_Small_Error (Min_Siz : Uint);
12236 -- Emit an error concerning illegal size Siz. Min_Siz denotes the
12239 --------------------------
12240 -- Size_Too_Small_Error --
12241 --------------------------
12243 procedure Size_Too_Small_Error (Min_Siz : Uint) is
12245 Error_Msg_Uint_1 := Min_Siz;
12246 Error_Msg_NE (Size_Too_Small_Message, N, T);
12247 end Size_Too_Small_Error;
12251 UT : constant Entity_Id := Underlying_Type (T);
12254 -- Start of processing for Check_Size
12259 -- Reject patently improper size values
12261 if Is_Elementary_Type (T)
12262 and then Siz > UI_From_Int (Int'Last)
12264 Error_Msg_N ("Size value too large for elementary type", N);
12266 if Nkind (Original_Node (N)) = N_Op_Expon then
12268 ("\maybe '* was meant, rather than '*'*", Original_Node (N));
12272 -- Dismiss generic types
12274 if Is_Generic_Type (T)
12276 Is_Generic_Type (UT)
12278 Is_Generic_Type (Root_Type (UT))
12282 -- Guard against previous errors
12284 elsif No (UT) or else UT = Any_Type then
12285 Check_Error_Detected;
12288 -- Check case of bit packed array
12290 elsif Is_Array_Type (UT)
12291 and then Known_Static_Component_Size (UT)
12292 and then Is_Bit_Packed_Array (UT)
12300 Asiz := Component_Size (UT);
12301 Indx := First_Index (UT);
12303 Ityp := Etype (Indx);
12305 -- If non-static bound, then we are not in the business of
12306 -- trying to check the length, and indeed an error will be
12307 -- issued elsewhere, since sizes of non-static array types
12308 -- cannot be set implicitly or explicitly.
12310 if not Is_OK_Static_Subtype (Ityp) then
12314 -- Otherwise accumulate next dimension
12316 Asiz := Asiz * (Expr_Value (Type_High_Bound (Ityp)) -
12317 Expr_Value (Type_Low_Bound (Ityp)) +
12321 exit when No (Indx);
12324 if Asiz <= Siz then
12328 Size_Too_Small_Error (Asiz);
12329 Set_Esize (T, Asiz);
12330 Set_RM_Size (T, Asiz);
12334 -- All other composite types are ignored
12336 elsif Is_Composite_Type (UT) then
12339 -- For fixed-point types, don't check minimum if type is not frozen,
12340 -- since we don't know all the characteristics of the type that can
12341 -- affect the size (e.g. a specified small) till freeze time.
12343 elsif Is_Fixed_Point_Type (UT) and then not Is_Frozen (UT) then
12346 -- Cases for which a minimum check is required
12349 -- Ignore if specified size is correct for the type
12351 if Known_Esize (UT) and then Siz = Esize (UT) then
12355 -- Otherwise get minimum size
12357 M := UI_From_Int (Minimum_Size (UT));
12361 -- Size is less than minimum size, but one possibility remains
12362 -- that we can manage with the new size if we bias the type.
12364 M := UI_From_Int (Minimum_Size (UT, Biased => True));
12367 Size_Too_Small_Error (M);
12369 Set_RM_Size (T, M);
12377 --------------------------
12378 -- Freeze_Entity_Checks --
12379 --------------------------
12381 procedure Freeze_Entity_Checks (N : Node_Id) is
12382 procedure Hide_Non_Overridden_Subprograms (Typ : Entity_Id);
12383 -- Inspect the primitive operations of type Typ and hide all pairs of
12384 -- implicitly declared non-overridden non-fully conformant homographs
12385 -- (Ada RM 8.3 12.3/2).
12387 -------------------------------------
12388 -- Hide_Non_Overridden_Subprograms --
12389 -------------------------------------
12391 procedure Hide_Non_Overridden_Subprograms (Typ : Entity_Id) is
12392 procedure Hide_Matching_Homographs
12393 (Subp_Id : Entity_Id;
12394 Start_Elmt : Elmt_Id);
12395 -- Inspect a list of primitive operations starting with Start_Elmt
12396 -- and find matching implicitly declared non-overridden non-fully
12397 -- conformant homographs of Subp_Id. If found, all matches along
12398 -- with Subp_Id are hidden from all visibility.
12400 function Is_Non_Overridden_Or_Null_Procedure
12401 (Subp_Id : Entity_Id) return Boolean;
12402 -- Determine whether subprogram Subp_Id is implicitly declared non-
12403 -- overridden subprogram or an implicitly declared null procedure.
12405 ------------------------------
12406 -- Hide_Matching_Homographs --
12407 ------------------------------
12409 procedure Hide_Matching_Homographs
12410 (Subp_Id : Entity_Id;
12411 Start_Elmt : Elmt_Id)
12414 Prim_Elmt : Elmt_Id;
12417 Prim_Elmt := Start_Elmt;
12418 while Present (Prim_Elmt) loop
12419 Prim := Node (Prim_Elmt);
12421 -- The current primitive is implicitly declared non-overridden
12422 -- non-fully conformant homograph of Subp_Id. Both subprograms
12423 -- must be hidden from visibility.
12425 if Chars (Prim) = Chars (Subp_Id)
12426 and then Is_Non_Overridden_Or_Null_Procedure (Prim)
12427 and then not Fully_Conformant (Prim, Subp_Id)
12429 Set_Is_Hidden_Non_Overridden_Subpgm (Prim);
12430 Set_Is_Immediately_Visible (Prim, False);
12431 Set_Is_Potentially_Use_Visible (Prim, False);
12433 Set_Is_Hidden_Non_Overridden_Subpgm (Subp_Id);
12434 Set_Is_Immediately_Visible (Subp_Id, False);
12435 Set_Is_Potentially_Use_Visible (Subp_Id, False);
12438 Next_Elmt (Prim_Elmt);
12440 end Hide_Matching_Homographs;
12442 -----------------------------------------
12443 -- Is_Non_Overridden_Or_Null_Procedure --
12444 -----------------------------------------
12446 function Is_Non_Overridden_Or_Null_Procedure
12447 (Subp_Id : Entity_Id) return Boolean
12449 Alias_Id : Entity_Id;
12452 -- The subprogram is inherited (implicitly declared), it does not
12453 -- override and does not cover a primitive of an interface.
12455 if Ekind (Subp_Id) in E_Function | E_Procedure
12456 and then Present (Alias (Subp_Id))
12457 and then No (Interface_Alias (Subp_Id))
12458 and then No (Overridden_Operation (Subp_Id))
12460 Alias_Id := Alias (Subp_Id);
12462 if Requires_Overriding (Alias_Id) then
12465 elsif Nkind (Parent (Alias_Id)) = N_Procedure_Specification
12466 and then Null_Present (Parent (Alias_Id))
12473 end Is_Non_Overridden_Or_Null_Procedure;
12477 Prim_Ops : constant Elist_Id := Direct_Primitive_Operations (Typ);
12479 Prim_Elmt : Elmt_Id;
12481 -- Start of processing for Hide_Non_Overridden_Subprograms
12484 -- Inspect the list of primitives looking for non-overridden
12487 if Present (Prim_Ops) then
12488 Prim_Elmt := First_Elmt (Prim_Ops);
12489 while Present (Prim_Elmt) loop
12490 Prim := Node (Prim_Elmt);
12491 Next_Elmt (Prim_Elmt);
12493 if Is_Non_Overridden_Or_Null_Procedure (Prim) then
12494 Hide_Matching_Homographs
12496 Start_Elmt => Prim_Elmt);
12500 end Hide_Non_Overridden_Subprograms;
12504 E : constant Entity_Id := Entity (N);
12506 Nongeneric_Case : constant Boolean := Nkind (N) = N_Freeze_Entity;
12507 -- True in nongeneric case. Some of the processing here is skipped
12508 -- for the generic case since it is not needed. Basically in the
12509 -- generic case, we only need to do stuff that might generate error
12510 -- messages or warnings.
12512 -- Start of processing for Freeze_Entity_Checks
12515 -- Remember that we are processing a freezing entity. Required to
12516 -- ensure correct decoration of internal entities associated with
12517 -- interfaces (see New_Overloaded_Entity).
12519 Inside_Freezing_Actions := Inside_Freezing_Actions + 1;
12521 -- For tagged types covering interfaces add internal entities that link
12522 -- the primitives of the interfaces with the primitives that cover them.
12523 -- Note: These entities were originally generated only when generating
12524 -- code because their main purpose was to provide support to initialize
12525 -- the secondary dispatch tables. They are also used to locate
12526 -- primitives covering interfaces when processing generics (see
12527 -- Derive_Subprograms).
12529 -- This is not needed in the generic case
12531 if Ada_Version >= Ada_2005
12532 and then Nongeneric_Case
12533 and then Ekind (E) = E_Record_Type
12534 and then Is_Tagged_Type (E)
12535 and then not Is_Interface (E)
12536 and then Has_Interfaces (E)
12538 -- This would be a good common place to call the routine that checks
12539 -- overriding of interface primitives (and thus factorize calls to
12540 -- Check_Abstract_Overriding located at different contexts in the
12541 -- compiler). However, this is not possible because it causes
12542 -- spurious errors in case of late overriding.
12544 Add_Internal_Interface_Entities (E);
12547 -- After all forms of overriding have been resolved, a tagged type may
12548 -- be left with a set of implicitly declared and possibly erroneous
12549 -- abstract subprograms, null procedures and subprograms that require
12550 -- overriding. If this set contains fully conformant homographs, then
12551 -- one is chosen arbitrarily (already done during resolution), otherwise
12552 -- all remaining non-fully conformant homographs are hidden from
12553 -- visibility (Ada RM 8.3 12.3/2).
12555 if Is_Tagged_Type (E) then
12556 Hide_Non_Overridden_Subprograms (E);
12561 if Ekind (E) = E_Record_Type
12562 and then Is_CPP_Class (E)
12563 and then Is_Tagged_Type (E)
12564 and then Tagged_Type_Expansion
12566 if CPP_Num_Prims (E) = 0 then
12568 -- If the CPP type has user defined components then it must import
12569 -- primitives from C++. This is required because if the C++ class
12570 -- has no primitives then the C++ compiler does not added the _tag
12571 -- component to the type.
12573 if First_Entity (E) /= Last_Entity (E) then
12575 ("'C'P'P type must import at least one primitive from C++??",
12580 -- Check that all its primitives are abstract or imported from C++.
12581 -- Check also availability of the C++ constructor.
12584 Has_Constructors : constant Boolean := Has_CPP_Constructors (E);
12586 Error_Reported : Boolean := False;
12590 Elmt := First_Elmt (Primitive_Operations (E));
12591 while Present (Elmt) loop
12592 Prim := Node (Elmt);
12594 if Comes_From_Source (Prim) then
12595 if Is_Abstract_Subprogram (Prim) then
12598 elsif not Is_Imported (Prim)
12599 or else Convention (Prim) /= Convention_CPP
12602 ("primitives of 'C'P'P types must be imported from C++ "
12603 & "or abstract??", Prim);
12605 elsif not Has_Constructors
12606 and then not Error_Reported
12608 Error_Msg_Name_1 := Chars (E);
12610 ("??'C'P'P constructor required for type %", Prim);
12611 Error_Reported := True;
12620 -- Check Ada derivation of CPP type
12622 if Expander_Active -- why? losing errors in -gnatc mode???
12623 and then Present (Etype (E)) -- defend against errors
12624 and then Tagged_Type_Expansion
12625 and then Ekind (E) = E_Record_Type
12626 and then Etype (E) /= E
12627 and then Is_CPP_Class (Etype (E))
12628 and then CPP_Num_Prims (Etype (E)) > 0
12629 and then not Is_CPP_Class (E)
12630 and then not Has_CPP_Constructors (Etype (E))
12632 -- If the parent has C++ primitives but it has no constructor then
12633 -- check that all the primitives are overridden in this derivation;
12634 -- otherwise the constructor of the parent is needed to build the
12642 Elmt := First_Elmt (Primitive_Operations (E));
12643 while Present (Elmt) loop
12644 Prim := Node (Elmt);
12646 if not Is_Abstract_Subprogram (Prim)
12647 and then No (Interface_Alias (Prim))
12648 and then Find_Dispatching_Type (Ultimate_Alias (Prim)) /= E
12650 Error_Msg_Name_1 := Chars (Etype (E));
12652 ("'C'P'P constructor required for parent type %", E);
12661 Inside_Freezing_Actions := Inside_Freezing_Actions - 1;
12663 -- If we have a type with predicates, build predicate function. This is
12664 -- not needed in the generic case, nor within e.g. TSS subprograms and
12665 -- other predefined primitives. For a derived type, ensure that the
12666 -- parent type is already frozen so that its predicate function has been
12667 -- constructed already. This is necessary if the parent is declared
12668 -- in a nested package and its own freeze point has not been reached.
12671 and then Nongeneric_Case
12672 and then Has_Predicates (E)
12673 and then Predicate_Check_In_Scope (N)
12676 Atyp : constant Entity_Id := Nearest_Ancestor (E);
12679 and then Has_Predicates (Atyp)
12680 and then not Is_Frozen (Atyp)
12682 Freeze_Before (N, Atyp);
12686 Build_Predicate_Functions (E, N);
12689 -- If type has delayed aspects, this is where we do the preanalysis at
12690 -- the freeze point, as part of the consistent visibility check. Note
12691 -- that this must be done after calling Build_Predicate_Functions or
12692 -- Build_Invariant_Procedure since these subprograms fix occurrences of
12693 -- the subtype name in the saved expression so that they will not cause
12694 -- trouble in the preanalysis.
12696 -- This is also not needed in the generic case
12699 and then Has_Delayed_Aspects (E)
12700 and then Scope (E) = Current_Scope
12707 -- Look for aspect specification entries for this entity
12709 Ritem := First_Rep_Item (E);
12710 while Present (Ritem) loop
12711 if Nkind (Ritem) = N_Aspect_Specification
12712 and then Entity (Ritem) = E
12713 and then Is_Delayed_Aspect (Ritem)
12715 A_Id := Get_Aspect_Id (Ritem);
12717 if A_Id = Aspect_Dynamic_Predicate
12718 or else A_Id = Aspect_Predicate
12719 or else A_Id = Aspect_Priority
12720 or else A_Id = Aspect_CPU
12722 -- Retrieve the visibility to components and discriminants
12723 -- in order to properly analyze the aspects.
12726 Check_Aspect_At_Freeze_Point (Ritem);
12730 Check_Aspect_At_Freeze_Point (Ritem);
12734 Next_Rep_Item (Ritem);
12740 -- For a record type, deal with variant parts. This has to be delayed to
12741 -- this point, because of the issue of statically predicated subtypes,
12742 -- which we have to ensure are frozen before checking choices, since we
12743 -- need to have the static choice list set.
12745 if Is_Record_Type (E) then
12746 Check_Variant_Part : declare
12747 D : constant Node_Id := Declaration_Node (E);
12752 Others_Present : Boolean;
12753 pragma Warnings (Off, Others_Present);
12754 -- Indicates others present, not used in this case
12756 procedure Non_Static_Choice_Error (Choice : Node_Id);
12757 -- Error routine invoked by the generic instantiation below when
12758 -- the variant part has a non static choice.
12760 procedure Process_Declarations (Variant : Node_Id);
12761 -- Processes declarations associated with a variant. We analyzed
12762 -- the declarations earlier (in Sem_Ch3.Analyze_Variant_Part),
12763 -- but we still need the recursive call to Check_Choices for any
12764 -- nested variant to get its choices properly processed. This is
12765 -- also where we expand out the choices if expansion is active.
12767 package Variant_Choices_Processing is new
12768 Generic_Check_Choices
12769 (Process_Empty_Choice => No_OP,
12770 Process_Non_Static_Choice => Non_Static_Choice_Error,
12771 Process_Associated_Node => Process_Declarations);
12772 use Variant_Choices_Processing;
12774 -----------------------------
12775 -- Non_Static_Choice_Error --
12776 -----------------------------
12778 procedure Non_Static_Choice_Error (Choice : Node_Id) is
12780 Flag_Non_Static_Expr
12781 ("choice given in variant part is not static!", Choice);
12782 end Non_Static_Choice_Error;
12784 --------------------------
12785 -- Process_Declarations --
12786 --------------------------
12788 procedure Process_Declarations (Variant : Node_Id) is
12789 CL : constant Node_Id := Component_List (Variant);
12793 -- Check for static predicate present in this variant
12795 if Has_SP_Choice (Variant) then
12797 -- Here we expand. You might expect to find this call in
12798 -- Expand_N_Variant_Part, but that is called when we first
12799 -- see the variant part, and we cannot do this expansion
12800 -- earlier than the freeze point, since for statically
12801 -- predicated subtypes, the predicate is not known till
12802 -- the freeze point.
12804 -- Furthermore, we do this expansion even if the expander
12805 -- is not active, because other semantic processing, e.g.
12806 -- for aggregates, requires the expanded list of choices.
12808 -- If the expander is not active, then we can't just clobber
12809 -- the list since it would invalidate the tree.
12810 -- So we have to rewrite the variant part with a Rewrite
12811 -- call that replaces it with a copy and clobber the copy.
12813 if not Expander_Active then
12815 NewV : constant Node_Id := New_Copy (Variant);
12817 Set_Discrete_Choices
12818 (NewV, New_Copy_List (Discrete_Choices (Variant)));
12819 Rewrite (Variant, NewV);
12823 Expand_Static_Predicates_In_Choices (Variant);
12826 -- We don't need to worry about the declarations in the variant
12827 -- (since they were analyzed by Analyze_Choices when we first
12828 -- encountered the variant), but we do need to take care of
12829 -- expansion of any nested variants.
12831 if not Null_Present (CL) then
12832 VP := Variant_Part (CL);
12834 if Present (VP) then
12836 (VP, Variants (VP), Etype (Name (VP)), Others_Present);
12839 end Process_Declarations;
12841 -- Start of processing for Check_Variant_Part
12844 -- Find component list
12848 if Nkind (D) = N_Full_Type_Declaration then
12849 T := Type_Definition (D);
12851 if Nkind (T) = N_Record_Definition then
12852 C := Component_List (T);
12854 elsif Nkind (T) = N_Derived_Type_Definition
12855 and then Present (Record_Extension_Part (T))
12857 C := Component_List (Record_Extension_Part (T));
12861 -- Case of variant part present
12863 if Present (C) and then Present (Variant_Part (C)) then
12864 VP := Variant_Part (C);
12869 (VP, Variants (VP), Etype (Name (VP)), Others_Present);
12871 -- If the last variant does not contain the Others choice,
12872 -- replace it with an N_Others_Choice node since Gigi always
12873 -- wants an Others. Note that we do not bother to call Analyze
12874 -- on the modified variant part, since its only effect would be
12875 -- to compute the Others_Discrete_Choices node laboriously, and
12876 -- of course we already know the list of choices corresponding
12877 -- to the others choice (it's the list we're replacing).
12879 -- We only want to do this if the expander is active, since
12880 -- we do not want to clobber the tree.
12882 if Expander_Active then
12884 Last_Var : constant Node_Id :=
12885 Last_Non_Pragma (Variants (VP));
12887 Others_Node : Node_Id;
12890 if Nkind (First (Discrete_Choices (Last_Var))) /=
12893 Others_Node := Make_Others_Choice (Sloc (Last_Var));
12894 Set_Others_Discrete_Choices
12895 (Others_Node, Discrete_Choices (Last_Var));
12896 Set_Discrete_Choices
12897 (Last_Var, New_List (Others_Node));
12902 end Check_Variant_Part;
12904 end Freeze_Entity_Checks;
12906 -------------------------
12907 -- Get_Alignment_Value --
12908 -------------------------
12910 function Get_Alignment_Value (Expr : Node_Id) return Uint is
12911 Align : constant Uint := Static_Integer (Expr);
12914 if Align = No_Uint then
12917 elsif Align < 0 then
12918 Error_Msg_N ("alignment value must be positive", Expr);
12921 -- If Alignment is specified to be 0, we treat it the same as 1
12923 elsif Align = 0 then
12927 for J in Int range 0 .. 64 loop
12929 M : constant Uint := Uint_2 ** J;
12932 exit when M = Align;
12935 Error_Msg_N ("alignment value must be power of 2", Expr);
12943 end Get_Alignment_Value;
12945 -----------------------------------
12946 -- Has_Compatible_Representation --
12947 -----------------------------------
12949 function Has_Compatible_Representation
12950 (Target_Type, Operand_Type : Entity_Id) return Boolean
12952 T1 : constant Entity_Id := Underlying_Type (Target_Type);
12953 T2 : constant Entity_Id := Underlying_Type (Operand_Type);
12956 -- A quick check, if base types are the same, then we definitely have
12957 -- the same representation, because the subtype specific representation
12958 -- attributes (Size and Alignment) do not affect representation from
12959 -- the point of view of this test.
12961 if Base_Type (T1) = Base_Type (T2) then
12964 elsif Is_Private_Type (Base_Type (T2))
12965 and then Base_Type (T1) = Full_View (Base_Type (T2))
12969 -- If T2 is a generic actual it is declared as a subtype, so
12970 -- check against its base type.
12972 elsif Is_Generic_Actual_Type (T1)
12973 and then Has_Compatible_Representation (Base_Type (T1), T2)
12978 -- Tagged types always have the same representation, because it is not
12979 -- possible to specify different representations for common fields.
12981 if Is_Tagged_Type (T1) then
12985 -- Representations are definitely different if conventions differ
12987 if Convention (T1) /= Convention (T2) then
12991 -- Representations are different if component alignments or scalar
12992 -- storage orders differ.
12994 if (Is_Record_Type (T1) or else Is_Array_Type (T1))
12996 (Is_Record_Type (T2) or else Is_Array_Type (T2))
12998 (Component_Alignment (T1) /= Component_Alignment (T2)
12999 or else Reverse_Storage_Order (T1) /= Reverse_Storage_Order (T2))
13004 -- For arrays, the only real issue is component size. If we know the
13005 -- component size for both arrays, and it is the same, then that's
13006 -- good enough to know we don't have a change of representation.
13008 if Is_Array_Type (T1) then
13010 -- In a view conversion, if the target type is an array type having
13011 -- aliased components and the operand type is an array type having
13012 -- unaliased components, then a new object is created (4.6(58.3/4)).
13014 if Has_Aliased_Components (T1)
13015 and then not Has_Aliased_Components (T2)
13020 if Known_Component_Size (T1)
13021 and then Known_Component_Size (T2)
13022 and then Component_Size (T1) = Component_Size (T2)
13028 -- For records, representations are different if reorderings differ
13030 if Is_Record_Type (T1)
13031 and then Is_Record_Type (T2)
13032 and then No_Reordering (T1) /= No_Reordering (T2)
13037 -- Types definitely have same representation if neither has non-standard
13038 -- representation since default representations are always consistent.
13039 -- If only one has non-standard representation, and the other does not,
13040 -- then we consider that they do not have the same representation. They
13041 -- might, but there is no way of telling early enough.
13043 if Has_Non_Standard_Rep (T1) then
13044 if not Has_Non_Standard_Rep (T2) then
13048 return not Has_Non_Standard_Rep (T2);
13051 -- Here the two types both have non-standard representation, and we need
13052 -- to determine if they have the same non-standard representation.
13054 -- For arrays, we simply need to test if the component sizes are the
13055 -- same. Pragma Pack is reflected in modified component sizes, so this
13056 -- check also deals with pragma Pack.
13058 if Is_Array_Type (T1) then
13059 return Component_Size (T1) = Component_Size (T2);
13061 -- Case of record types
13063 elsif Is_Record_Type (T1) then
13065 -- Packed status must conform
13067 if Is_Packed (T1) /= Is_Packed (T2) then
13070 -- Otherwise we must check components. Typ2 maybe a constrained
13071 -- subtype with fewer components, so we compare the components
13072 -- of the base types.
13075 Record_Case : declare
13076 CD1, CD2 : Entity_Id;
13078 function Same_Rep return Boolean;
13079 -- CD1 and CD2 are either components or discriminants. This
13080 -- function tests whether they have the same representation.
13086 function Same_Rep return Boolean is
13088 if No (Component_Clause (CD1)) then
13089 return No (Component_Clause (CD2));
13091 -- Note: at this point, component clauses have been
13092 -- normalized to the default bit order, so that the
13093 -- comparison of Component_Bit_Offsets is meaningful.
13096 Present (Component_Clause (CD2))
13098 Component_Bit_Offset (CD1) = Component_Bit_Offset (CD2)
13100 Esize (CD1) = Esize (CD2);
13104 -- Start of processing for Record_Case
13107 if Has_Discriminants (T1) then
13109 -- The number of discriminants may be different if the
13110 -- derived type has fewer (constrained by values). The
13111 -- invisible discriminants retain the representation of
13112 -- the original, so the discrepancy does not per se
13113 -- indicate a different representation.
13115 CD1 := First_Discriminant (T1);
13116 CD2 := First_Discriminant (T2);
13117 while Present (CD1) and then Present (CD2) loop
13118 if not Same_Rep then
13121 Next_Discriminant (CD1);
13122 Next_Discriminant (CD2);
13127 CD1 := First_Component (Underlying_Type (Base_Type (T1)));
13128 CD2 := First_Component (Underlying_Type (Base_Type (T2)));
13129 while Present (CD1) loop
13130 if not Same_Rep then
13133 Next_Component (CD1);
13134 Next_Component (CD2);
13142 -- For enumeration types, we must check each literal to see if the
13143 -- representation is the same. Note that we do not permit enumeration
13144 -- representation clauses for Character and Wide_Character, so these
13145 -- cases were already dealt with.
13147 elsif Is_Enumeration_Type (T1) then
13148 Enumeration_Case : declare
13149 L1, L2 : Entity_Id;
13152 L1 := First_Literal (T1);
13153 L2 := First_Literal (T2);
13154 while Present (L1) loop
13155 if Enumeration_Rep (L1) /= Enumeration_Rep (L2) then
13164 end Enumeration_Case;
13166 -- Any other types have the same representation for these purposes
13171 end Has_Compatible_Representation;
13173 -------------------------------------
13174 -- Inherit_Aspects_At_Freeze_Point --
13175 -------------------------------------
13177 procedure Inherit_Aspects_At_Freeze_Point (Typ : Entity_Id) is
13178 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
13179 (Rep_Item : Node_Id) return Boolean;
13180 -- This routine checks if Rep_Item is either a pragma or an aspect
13181 -- specification node whose correponding pragma (if any) is present in
13182 -- the Rep Item chain of the entity it has been specified to.
13184 --------------------------------------------------
13185 -- Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item --
13186 --------------------------------------------------
13188 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
13189 (Rep_Item : Node_Id) return Boolean
13193 Nkind (Rep_Item) = N_Pragma
13195 Present_In_Rep_Item (Entity (Rep_Item), Aspect_Rep_Item (Rep_Item));
13196 end Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item;
13198 -- Start of processing for Inherit_Aspects_At_Freeze_Point
13201 -- A representation item is either subtype-specific (Size and Alignment
13202 -- clauses) or type-related (all others). Subtype-specific aspects may
13203 -- differ for different subtypes of the same type (RM 13.1.8).
13205 -- A derived type inherits each type-related representation aspect of
13206 -- its parent type that was directly specified before the declaration of
13207 -- the derived type (RM 13.1.15).
13209 -- A derived subtype inherits each subtype-specific representation
13210 -- aspect of its parent subtype that was directly specified before the
13211 -- declaration of the derived type (RM 13.1.15).
13213 -- The general processing involves inheriting a representation aspect
13214 -- from a parent type whenever the first rep item (aspect specification,
13215 -- attribute definition clause, pragma) corresponding to the given
13216 -- representation aspect in the rep item chain of Typ, if any, isn't
13217 -- directly specified to Typ but to one of its parents.
13219 -- ??? Note that, for now, just a limited number of representation
13220 -- aspects have been inherited here so far. Many of them are
13221 -- still inherited in Sem_Ch3. This will be fixed soon. Here is
13222 -- a non- exhaustive list of aspects that likely also need to
13223 -- be moved to this routine: Alignment, Component_Alignment,
13224 -- Component_Size, Machine_Radix, Object_Size, Pack, Predicates,
13225 -- Preelaborable_Initialization, RM_Size and Small.
13227 -- In addition, Convention must be propagated from base type to subtype,
13228 -- because the subtype may have been declared on an incomplete view.
13230 if Nkind (Parent (Typ)) = N_Private_Extension_Declaration then
13236 if not Has_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005, False)
13237 and then Has_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005)
13238 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
13239 (Get_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005))
13241 Set_Is_Ada_2005_Only (Typ);
13246 if not Has_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012, False)
13247 and then Has_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012)
13248 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
13249 (Get_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012))
13251 Set_Is_Ada_2012_Only (Typ);
13256 if not Has_Rep_Item (Typ, Name_Atomic, Name_Shared, False)
13257 and then Has_Rep_Pragma (Typ, Name_Atomic, Name_Shared)
13258 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
13259 (Get_Rep_Item (Typ, Name_Atomic, Name_Shared))
13261 Set_Is_Atomic (Typ);
13262 Set_Is_Volatile (Typ);
13263 Set_Treat_As_Volatile (Typ);
13268 if Is_Record_Type (Typ)
13269 and then Typ /= Base_Type (Typ) and then Is_Frozen (Base_Type (Typ))
13271 Set_Convention (Typ, Convention (Base_Type (Typ)));
13274 -- Default_Component_Value
13276 -- Verify that there is no rep_item declared for the type, and there
13277 -- is one coming from an ancestor.
13279 if Is_Array_Type (Typ)
13280 and then Is_Base_Type (Typ)
13281 and then not Has_Rep_Item (Typ, Name_Default_Component_Value, False)
13282 and then Has_Rep_Item (Typ, Name_Default_Component_Value)
13284 Set_Default_Aspect_Component_Value (Typ,
13285 Default_Aspect_Component_Value
13286 (Entity (Get_Rep_Item (Typ, Name_Default_Component_Value))));
13291 if Is_Scalar_Type (Typ)
13292 and then Is_Base_Type (Typ)
13293 and then not Has_Rep_Item (Typ, Name_Default_Value, False)
13294 and then Has_Rep_Item (Typ, Name_Default_Value)
13296 Set_Has_Default_Aspect (Typ);
13297 Set_Default_Aspect_Value (Typ,
13298 Default_Aspect_Value
13299 (Entity (Get_Rep_Item (Typ, Name_Default_Value))));
13304 if not Has_Rep_Item (Typ, Name_Discard_Names, False)
13305 and then Has_Rep_Item (Typ, Name_Discard_Names)
13306 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
13307 (Get_Rep_Item (Typ, Name_Discard_Names))
13309 Set_Discard_Names (Typ);
13314 if not Has_Rep_Item (Typ, Name_Volatile, False)
13315 and then Has_Rep_Item (Typ, Name_Volatile)
13316 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
13317 (Get_Rep_Item (Typ, Name_Volatile))
13319 Set_Is_Volatile (Typ);
13320 Set_Treat_As_Volatile (Typ);
13323 -- Volatile_Full_Access and Full_Access_Only
13325 if not Has_Rep_Item (Typ, Name_Volatile_Full_Access, False)
13326 and then not Has_Rep_Item (Typ, Name_Full_Access_Only, False)
13327 and then (Has_Rep_Item (Typ, Name_Volatile_Full_Access)
13328 or else Has_Rep_Item (Typ, Name_Full_Access_Only))
13329 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
13330 (Get_Rep_Item (Typ, Name_Volatile_Full_Access))
13332 Set_Is_Volatile_Full_Access (Typ);
13333 Set_Is_Volatile (Typ);
13334 Set_Treat_As_Volatile (Typ);
13337 -- Inheritance for derived types only
13339 if Is_Derived_Type (Typ) then
13341 Bas_Typ : constant Entity_Id := Base_Type (Typ);
13342 Imp_Bas_Typ : constant Entity_Id := Implementation_Base_Type (Typ);
13345 -- Atomic_Components
13347 if not Has_Rep_Item (Typ, Name_Atomic_Components, False)
13348 and then Has_Rep_Item (Typ, Name_Atomic_Components)
13349 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
13350 (Get_Rep_Item (Typ, Name_Atomic_Components))
13352 Set_Has_Atomic_Components (Imp_Bas_Typ);
13355 -- Volatile_Components
13357 if not Has_Rep_Item (Typ, Name_Volatile_Components, False)
13358 and then Has_Rep_Item (Typ, Name_Volatile_Components)
13359 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
13360 (Get_Rep_Item (Typ, Name_Volatile_Components))
13362 Set_Has_Volatile_Components (Imp_Bas_Typ);
13365 -- Finalize_Storage_Only
13367 if not Has_Rep_Pragma (Typ, Name_Finalize_Storage_Only, False)
13368 and then Has_Rep_Pragma (Typ, Name_Finalize_Storage_Only)
13370 Set_Finalize_Storage_Only (Bas_Typ);
13373 -- Universal_Aliasing
13375 if not Has_Rep_Item (Typ, Name_Universal_Aliasing, False)
13376 and then Has_Rep_Item (Typ, Name_Universal_Aliasing)
13377 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
13378 (Get_Rep_Item (Typ, Name_Universal_Aliasing))
13380 Set_Universal_Aliasing (Imp_Bas_Typ);
13385 if Is_Record_Type (Typ) and then Typ = Bas_Typ then
13386 if not Has_Rep_Item (Typ, Name_Bit_Order, False)
13387 and then Has_Rep_Item (Typ, Name_Bit_Order)
13389 Set_Reverse_Bit_Order (Bas_Typ,
13391 (Implementation_Base_Type (Etype (Bas_Typ))));
13395 -- Scalar_Storage_Order
13397 if (Is_Record_Type (Typ) or else Is_Array_Type (Typ))
13398 and then Typ = Bas_Typ
13400 -- For a type extension, always inherit from parent; otherwise
13401 -- inherit if no default applies. Note: we do not check for
13402 -- an explicit rep item on the parent type when inheriting,
13403 -- because the parent SSO may itself have been set by default.
13405 if not Has_Rep_Item (First_Subtype (Typ),
13406 Name_Scalar_Storage_Order, False)
13407 and then (Is_Tagged_Type (Bas_Typ)
13408 or else not (SSO_Set_Low_By_Default (Bas_Typ)
13410 SSO_Set_High_By_Default (Bas_Typ)))
13412 Set_Reverse_Storage_Order (Bas_Typ,
13413 Reverse_Storage_Order
13414 (Implementation_Base_Type (Etype (Bas_Typ))));
13416 -- Clear default SSO indications, since the inherited aspect
13417 -- which was set explicitly overrides the default.
13419 Set_SSO_Set_Low_By_Default (Bas_Typ, False);
13420 Set_SSO_Set_High_By_Default (Bas_Typ, False);
13425 end Inherit_Aspects_At_Freeze_Point;
13431 procedure Initialize is
13433 Address_Clause_Checks.Init;
13434 Unchecked_Conversions.Init;
13436 -- ??? Might be needed in the future for some non GCC back-ends
13437 -- if AAMP_On_Target then
13438 -- Independence_Checks.Init;
13442 ---------------------------
13443 -- Install_Discriminants --
13444 ---------------------------
13446 procedure Install_Discriminants (E : Entity_Id) is
13450 Disc := First_Discriminant (E);
13451 while Present (Disc) loop
13452 Prev := Current_Entity (Disc);
13453 Set_Current_Entity (Disc);
13454 Set_Is_Immediately_Visible (Disc);
13455 Set_Homonym (Disc, Prev);
13456 Next_Discriminant (Disc);
13458 end Install_Discriminants;
13460 -------------------------
13461 -- Is_Operational_Item --
13462 -------------------------
13464 function Is_Operational_Item (N : Node_Id) return Boolean is
13466 if Nkind (N) /= N_Attribute_Definition_Clause then
13471 Id : constant Attribute_Id := Get_Attribute_Id (Chars (N));
13474 -- List of operational items is given in AARM 13.1(8.mm/1).
13475 -- It is clearly incomplete, as it does not include iterator
13476 -- aspects, among others.
13478 return Id = Attribute_Constant_Indexing
13479 or else Id = Attribute_Default_Iterator
13480 or else Id = Attribute_Implicit_Dereference
13481 or else Id = Attribute_Input
13482 or else Id = Attribute_Iterator_Element
13483 or else Id = Attribute_Iterable
13484 or else Id = Attribute_Output
13485 or else Id = Attribute_Read
13486 or else Id = Attribute_Variable_Indexing
13487 or else Id = Attribute_Write
13488 or else Id = Attribute_External_Tag;
13491 end Is_Operational_Item;
13493 -------------------------
13494 -- Is_Predicate_Static --
13495 -------------------------
13497 -- Note: the basic legality of the expression has already been checked, so
13498 -- we don't need to worry about cases or ranges on strings for example.
13500 function Is_Predicate_Static
13502 Nam : Name_Id) return Boolean
13504 function All_Static_Case_Alternatives (L : List_Id) return Boolean;
13505 -- Given a list of case expression alternatives, returns True if all
13506 -- the alternatives are static (have all static choices, and a static
13509 function Is_Type_Ref (N : Node_Id) return Boolean;
13510 pragma Inline (Is_Type_Ref);
13511 -- Returns True if N is a reference to the type for the predicate in the
13512 -- expression (i.e. if it is an identifier whose Chars field matches the
13513 -- Nam given in the call). N must not be parenthesized, if the type name
13514 -- appears in parens, this routine will return False.
13516 -- The routine also returns True for function calls generated during the
13517 -- expansion of comparison operators on strings, which are intended to
13518 -- be legal in static predicates, and are converted into calls to array
13519 -- comparison routines in the body of the corresponding predicate
13522 ----------------------------------
13523 -- All_Static_Case_Alternatives --
13524 ----------------------------------
13526 function All_Static_Case_Alternatives (L : List_Id) return Boolean is
13531 while Present (N) loop
13532 if not (All_Static_Choices (Discrete_Choices (N))
13533 and then Is_OK_Static_Expression (Expression (N)))
13542 end All_Static_Case_Alternatives;
13548 function Is_Type_Ref (N : Node_Id) return Boolean is
13550 return (Nkind (N) = N_Identifier
13551 and then Chars (N) = Nam
13552 and then Paren_Count (N) = 0)
13553 or else Nkind (N) = N_Function_Call;
13556 -- Start of processing for Is_Predicate_Static
13559 -- Predicate_Static means one of the following holds. Numbers are the
13560 -- corresponding paragraph numbers in (RM 3.2.4(16-22)).
13562 -- 16: A static expression
13564 if Is_OK_Static_Expression (Expr) then
13567 -- 17: A membership test whose simple_expression is the current
13568 -- instance, and whose membership_choice_list meets the requirements
13569 -- for a static membership test.
13571 elsif Nkind (Expr) in N_Membership_Test
13572 and then All_Membership_Choices_Static (Expr)
13576 -- 18. A case_expression whose selecting_expression is the current
13577 -- instance, and whose dependent expressions are static expressions.
13579 elsif Nkind (Expr) = N_Case_Expression
13580 and then Is_Type_Ref (Expression (Expr))
13581 and then All_Static_Case_Alternatives (Alternatives (Expr))
13585 -- 19. A call to a predefined equality or ordering operator, where one
13586 -- operand is the current instance, and the other is a static
13589 -- Note: the RM is clearly wrong here in not excluding string types.
13590 -- Without this exclusion, we would allow expressions like X > "ABC"
13591 -- to be considered as predicate-static, which is clearly not intended,
13592 -- since the idea is for predicate-static to be a subset of normal
13593 -- static expressions (and "DEF" > "ABC" is not a static expression).
13595 -- However, we do allow internally generated (not from source) equality
13596 -- and inequality operations to be valid on strings (this helps deal
13597 -- with cases where we transform A in "ABC" to A = "ABC).
13599 -- In fact, it appears that the intent of the ARG is to extend static
13600 -- predicates to strings, and that the extension should probably apply
13601 -- to static expressions themselves. The code below accepts comparison
13602 -- operators that apply to static strings.
13604 elsif Nkind (Expr) in N_Op_Compare
13605 and then ((Is_Type_Ref (Left_Opnd (Expr))
13606 and then Is_OK_Static_Expression (Right_Opnd (Expr)))
13608 (Is_Type_Ref (Right_Opnd (Expr))
13609 and then Is_OK_Static_Expression (Left_Opnd (Expr))))
13613 -- 20. A call to a predefined boolean logical operator, where each
13614 -- operand is predicate-static.
13616 elsif (Nkind (Expr) in N_Op_And | N_Op_Or | N_Op_Xor
13617 and then Is_Predicate_Static (Left_Opnd (Expr), Nam)
13618 and then Is_Predicate_Static (Right_Opnd (Expr), Nam))
13620 (Nkind (Expr) = N_Op_Not
13621 and then Is_Predicate_Static (Right_Opnd (Expr), Nam))
13625 -- 21. A short-circuit control form where both operands are
13626 -- predicate-static.
13628 elsif Nkind (Expr) in N_Short_Circuit
13629 and then Is_Predicate_Static (Left_Opnd (Expr), Nam)
13630 and then Is_Predicate_Static (Right_Opnd (Expr), Nam)
13634 -- 22. A parenthesized predicate-static expression. This does not
13635 -- require any special test, since we just ignore paren levels in
13636 -- all the cases above.
13638 -- One more test that is an implementation artifact caused by the fact
13639 -- that we are analyzing not the original expression, but the generated
13640 -- expression in the body of the predicate function. This can include
13641 -- references to inherited predicates, so that the expression we are
13642 -- processing looks like:
13644 -- xxPredicate (typ (Inns)) and then expression
13646 -- Where the call is to a Predicate function for an inherited predicate.
13647 -- We simply ignore such a call, which could be to either a dynamic or
13648 -- a static predicate. Note that if the parent predicate is dynamic then
13649 -- eventually this type will be marked as dynamic, but you are allowed
13650 -- to specify a static predicate for a subtype which is inheriting a
13651 -- dynamic predicate, so the static predicate validation here ignores
13652 -- the inherited predicate even if it is dynamic.
13653 -- In all cases, a static predicate can only apply to a scalar type.
13655 elsif Nkind (Expr) = N_Function_Call
13656 and then Is_Predicate_Function (Entity (Name (Expr)))
13657 and then Is_Scalar_Type (Etype (First_Entity (Entity (Name (Expr)))))
13661 elsif Is_Entity_Name (Expr)
13662 and then Entity (Expr) = Standard_True
13664 Error_Msg_N ("predicate is redundant (always True)?", Expr);
13667 -- That's an exhaustive list of tests, all other cases are not
13668 -- predicate-static, so we return False.
13673 end Is_Predicate_Static;
13675 ----------------------
13676 -- Is_Static_Choice --
13677 ----------------------
13679 function Is_Static_Choice (N : Node_Id) return Boolean is
13681 return Nkind (N) = N_Others_Choice
13682 or else Is_OK_Static_Expression (N)
13683 or else (Is_Entity_Name (N) and then Is_Type (Entity (N))
13684 and then Is_OK_Static_Subtype (Entity (N)))
13685 or else (Nkind (N) = N_Subtype_Indication
13686 and then Is_OK_Static_Subtype (Entity (N)))
13687 or else (Nkind (N) = N_Range and then Is_OK_Static_Range (N));
13688 end Is_Static_Choice;
13690 ------------------------------
13691 -- Is_Type_Related_Rep_Item --
13692 ------------------------------
13694 function Is_Type_Related_Rep_Item (N : Node_Id) return Boolean is
13697 when N_Attribute_Definition_Clause =>
13699 Id : constant Attribute_Id := Get_Attribute_Id (Chars (N));
13700 -- See AARM 13.1(8.f-8.x) list items that end in "clause"
13701 -- ???: include any GNAT-defined attributes here?
13703 return Id = Attribute_Component_Size
13704 or else Id = Attribute_Bit_Order
13705 or else Id = Attribute_Storage_Pool
13706 or else Id = Attribute_Stream_Size
13707 or else Id = Attribute_Machine_Radix;
13711 case Get_Pragma_Id (N) is
13712 -- See AARM 13.1(8.f-8.x) list items that start with "pragma"
13713 -- ???: include any GNAT-defined pragmas here?
13717 | Pragma_Convention
13719 | Pragma_Independent
13721 | Pragma_Atomic_Components
13722 | Pragma_Independent_Components
13723 | Pragma_Volatile_Components
13724 | Pragma_Discard_Names
13731 when N_Enumeration_Representation_Clause
13732 | N_Record_Representation_Clause
13741 end Is_Type_Related_Rep_Item;
13743 ---------------------
13744 -- Kill_Rep_Clause --
13745 ---------------------
13747 procedure Kill_Rep_Clause (N : Node_Id) is
13749 pragma Assert (Ignore_Rep_Clauses);
13751 -- Note: we use Replace rather than Rewrite, because we don't want
13752 -- tools to be able to use Original_Node to dig out the (undecorated)
13753 -- rep clause that is being replaced.
13755 Replace (N, Make_Null_Statement (Sloc (N)));
13757 -- The null statement must be marked as not coming from source. This is
13758 -- so that tools ignore it, and also the back end does not expect bogus
13759 -- "from source" null statements in weird places (e.g. in declarative
13760 -- regions where such null statements are not allowed).
13762 Set_Comes_From_Source (N, False);
13763 end Kill_Rep_Clause;
13769 function Minimum_Size
13771 Biased : Boolean := False) return Nat
13773 Lo : Uint := No_Uint;
13774 Hi : Uint := No_Uint;
13775 LoR : Ureal := No_Ureal;
13776 HiR : Ureal := No_Ureal;
13777 LoSet : Boolean := False;
13778 HiSet : Boolean := False;
13781 Ancest : Entity_Id;
13782 R_Typ : constant Entity_Id := Root_Type (T);
13785 -- If bad type, return 0
13787 if T = Any_Type then
13790 -- For generic types, just return zero. There cannot be any legitimate
13791 -- need to know such a size, but this routine may be called with a
13792 -- generic type as part of normal processing.
13794 elsif Is_Generic_Type (R_Typ) or else R_Typ = Any_Type then
13797 -- Access types (cannot have size smaller than System.Address)
13799 elsif Is_Access_Type (T) then
13800 return System_Address_Size;
13802 -- Floating-point types
13804 elsif Is_Floating_Point_Type (T) then
13805 return UI_To_Int (Esize (R_Typ));
13809 elsif Is_Discrete_Type (T) then
13811 -- The following loop is looking for the nearest compile time known
13812 -- bounds following the ancestor subtype chain. The idea is to find
13813 -- the most restrictive known bounds information.
13817 if Ancest = Any_Type or else Etype (Ancest) = Any_Type then
13822 if Compile_Time_Known_Value (Type_Low_Bound (Ancest)) then
13823 Lo := Expr_Rep_Value (Type_Low_Bound (Ancest));
13830 if Compile_Time_Known_Value (Type_High_Bound (Ancest)) then
13831 Hi := Expr_Rep_Value (Type_High_Bound (Ancest));
13837 Ancest := Ancestor_Subtype (Ancest);
13839 if No (Ancest) then
13840 Ancest := Base_Type (T);
13842 if Is_Generic_Type (Ancest) then
13848 -- Fixed-point types. We can't simply use Expr_Value to get the
13849 -- Corresponding_Integer_Value values of the bounds, since these do not
13850 -- get set till the type is frozen, and this routine can be called
13851 -- before the type is frozen. Similarly the test for bounds being static
13852 -- needs to include the case where we have unanalyzed real literals for
13853 -- the same reason.
13855 elsif Is_Fixed_Point_Type (T) then
13857 -- The following loop is looking for the nearest compile time known
13858 -- bounds following the ancestor subtype chain. The idea is to find
13859 -- the most restrictive known bounds information.
13863 if Ancest = Any_Type or else Etype (Ancest) = Any_Type then
13867 -- Note: In the following two tests for LoSet and HiSet, it may
13868 -- seem redundant to test for N_Real_Literal here since normally
13869 -- one would assume that the test for the value being known at
13870 -- compile time includes this case. However, there is a glitch.
13871 -- If the real literal comes from folding a non-static expression,
13872 -- then we don't consider any non- static expression to be known
13873 -- at compile time if we are in configurable run time mode (needed
13874 -- in some cases to give a clearer definition of what is and what
13875 -- is not accepted). So the test is indeed needed. Without it, we
13876 -- would set neither Lo_Set nor Hi_Set and get an infinite loop.
13879 if Nkind (Type_Low_Bound (Ancest)) = N_Real_Literal
13880 or else Compile_Time_Known_Value (Type_Low_Bound (Ancest))
13882 LoR := Expr_Value_R (Type_Low_Bound (Ancest));
13889 if Nkind (Type_High_Bound (Ancest)) = N_Real_Literal
13890 or else Compile_Time_Known_Value (Type_High_Bound (Ancest))
13892 HiR := Expr_Value_R (Type_High_Bound (Ancest));
13898 Ancest := Ancestor_Subtype (Ancest);
13900 if No (Ancest) then
13901 Ancest := Base_Type (T);
13903 if Is_Generic_Type (Ancest) then
13909 Lo := UR_To_Uint (LoR / Small_Value (T));
13910 Hi := UR_To_Uint (HiR / Small_Value (T));
13912 -- No other types allowed
13915 raise Program_Error;
13918 -- Fall through with Hi and Lo set. Deal with biased case
13921 and then not Is_Fixed_Point_Type (T)
13922 and then not (Is_Enumeration_Type (T)
13923 and then Has_Non_Standard_Rep (T)))
13924 or else Has_Biased_Representation (T)
13930 -- Null range case, size is always zero. We only do this in the discrete
13931 -- type case, since that's the odd case that came up. Probably we should
13932 -- also do this in the fixed-point case, but doing so causes peculiar
13933 -- gigi failures, and it is not worth worrying about this incredibly
13934 -- marginal case (explicit null-range fixed-point type declarations)???
13936 if Lo > Hi and then Is_Discrete_Type (T) then
13939 -- Signed case. Note that we consider types like range 1 .. -1 to be
13940 -- signed for the purpose of computing the size, since the bounds have
13941 -- to be accommodated in the base type.
13943 elsif Lo < 0 or else Hi < 0 then
13947 -- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1))
13948 -- Note that we accommodate the case where the bounds cross. This
13949 -- can happen either because of the way the bounds are declared
13950 -- or because of the algorithm in Freeze_Fixed_Point_Type.
13964 -- If both bounds are positive, make sure that both are represen-
13965 -- table in the case where the bounds are crossed. This can happen
13966 -- either because of the way the bounds are declared, or because of
13967 -- the algorithm in Freeze_Fixed_Point_Type.
13973 -- S = size, (can accommodate 0 .. (2**size - 1))
13976 while Hi >= Uint_2 ** S loop
13984 ------------------------------
13985 -- New_Put_Image_Subprogram --
13986 ------------------------------
13988 procedure New_Put_Image_Subprogram
13993 Loc : constant Source_Ptr := Sloc (N);
13994 Sname : constant Name_Id :=
13995 Make_TSS_Name (Base_Type (Ent), TSS_Put_Image);
13996 Subp_Id : Entity_Id;
13997 Subp_Decl : Node_Id;
14001 Defer_Declaration : constant Boolean :=
14002 Is_Tagged_Type (Ent) or else Is_Private_Type (Ent);
14003 -- For a tagged type, there is a declaration at the freeze point, and
14004 -- we must generate only a completion of this declaration. We do the
14005 -- same for private types, because the full view might be tagged.
14006 -- Otherwise we generate a declaration at the point of the attribute
14007 -- definition clause. If the attribute definition comes from an aspect
14008 -- specification the declaration is part of the freeze actions of the
14011 function Build_Spec return Node_Id;
14012 -- Used for declaration and renaming declaration, so that this is
14013 -- treated as a renaming_as_body.
14019 function Build_Spec return Node_Id is
14022 T_Ref : constant Node_Id := New_Occurrence_Of (Etyp, Loc);
14025 Subp_Id := Make_Defining_Identifier (Loc, Sname);
14029 Formals := New_List (
14030 Make_Parameter_Specification (Loc,
14031 Defining_Identifier =>
14032 Make_Defining_Identifier (Loc, Name_S),
14033 In_Present => True,
14034 Out_Present => True,
14036 New_Occurrence_Of (Etype (F), Loc)));
14040 Append_To (Formals,
14041 Make_Parameter_Specification (Loc,
14042 Defining_Identifier => Make_Defining_Identifier (Loc, Name_V),
14043 Parameter_Type => T_Ref));
14046 Make_Procedure_Specification (Loc,
14047 Defining_Unit_Name => Subp_Id,
14048 Parameter_Specifications => Formals);
14053 -- Start of processing for New_Put_Image_Subprogram
14056 F := First_Formal (Subp);
14058 Etyp := Etype (Next_Formal (F));
14060 -- Prepare subprogram declaration and insert it as an action on the
14061 -- clause node. The visibility for this entity is used to test for
14062 -- visibility of the attribute definition clause (in the sense of
14063 -- 8.3(23) as amended by AI-195).
14065 if not Defer_Declaration then
14067 Make_Subprogram_Declaration (Loc,
14068 Specification => Build_Spec);
14070 -- For a tagged type, there is always a visible declaration for the
14071 -- Put_Image TSS (it is a predefined primitive operation), and the
14072 -- completion of this declaration occurs at the freeze point, which is
14073 -- not always visible at places where the attribute definition clause is
14074 -- visible. So, we create a dummy entity here for the purpose of
14075 -- tracking the visibility of the attribute definition clause itself.
14079 Make_Defining_Identifier (Loc, New_External_Name (Sname, 'V'));
14081 Make_Object_Declaration (Loc,
14082 Defining_Identifier => Subp_Id,
14083 Object_Definition => New_Occurrence_Of (Standard_Boolean, Loc));
14086 if not Defer_Declaration
14087 and then From_Aspect_Specification (N)
14088 and then Has_Delayed_Freeze (Ent)
14090 Append_Freeze_Action (Ent, Subp_Decl);
14093 Insert_Action (N, Subp_Decl);
14094 Set_Entity (N, Subp_Id);
14098 Make_Subprogram_Renaming_Declaration (Loc,
14099 Specification => Build_Spec,
14100 Name => New_Occurrence_Of (Subp, Loc));
14102 if Defer_Declaration then
14103 Set_TSS (Base_Type (Ent), Subp_Id);
14106 if From_Aspect_Specification (N) then
14107 Append_Freeze_Action (Ent, Subp_Decl);
14109 Insert_Action (N, Subp_Decl);
14112 Copy_TSS (Subp_Id, Base_Type (Ent));
14114 end New_Put_Image_Subprogram;
14116 ---------------------------
14117 -- New_Stream_Subprogram --
14118 ---------------------------
14120 procedure New_Stream_Subprogram
14124 Nam : TSS_Name_Type)
14126 Loc : constant Source_Ptr := Sloc (N);
14127 Sname : constant Name_Id := Make_TSS_Name (Base_Type (Ent), Nam);
14128 Subp_Id : Entity_Id;
14129 Subp_Decl : Node_Id;
14133 Defer_Declaration : constant Boolean :=
14134 Is_Tagged_Type (Ent) or else Is_Private_Type (Ent);
14135 -- For a tagged type, there is a declaration for each stream attribute
14136 -- at the freeze point, and we must generate only a completion of this
14137 -- declaration. We do the same for private types, because the full view
14138 -- might be tagged. Otherwise we generate a declaration at the point of
14139 -- the attribute definition clause. If the attribute definition comes
14140 -- from an aspect specification the declaration is part of the freeze
14141 -- actions of the type.
14143 function Build_Spec return Node_Id;
14144 -- Used for declaration and renaming declaration, so that this is
14145 -- treated as a renaming_as_body.
14151 function Build_Spec return Node_Id is
14152 Out_P : constant Boolean := (Nam = TSS_Stream_Read);
14155 T_Ref : constant Node_Id := New_Occurrence_Of (Etyp, Loc);
14158 Subp_Id := Make_Defining_Identifier (Loc, Sname);
14160 -- S : access Root_Stream_Type'Class
14162 Formals := New_List (
14163 Make_Parameter_Specification (Loc,
14164 Defining_Identifier =>
14165 Make_Defining_Identifier (Loc, Name_S),
14167 Make_Access_Definition (Loc,
14169 New_Occurrence_Of (
14170 Designated_Type (Etype (F)), Loc))));
14172 if Nam = TSS_Stream_Input then
14174 Make_Function_Specification (Loc,
14175 Defining_Unit_Name => Subp_Id,
14176 Parameter_Specifications => Formals,
14177 Result_Definition => T_Ref);
14181 Append_To (Formals,
14182 Make_Parameter_Specification (Loc,
14183 Defining_Identifier => Make_Defining_Identifier (Loc, Name_V),
14184 Out_Present => Out_P,
14185 Parameter_Type => T_Ref));
14188 Make_Procedure_Specification (Loc,
14189 Defining_Unit_Name => Subp_Id,
14190 Parameter_Specifications => Formals);
14196 -- Start of processing for New_Stream_Subprogram
14199 F := First_Formal (Subp);
14201 if Ekind (Subp) = E_Procedure then
14202 Etyp := Etype (Next_Formal (F));
14204 Etyp := Etype (Subp);
14207 -- Prepare subprogram declaration and insert it as an action on the
14208 -- clause node. The visibility for this entity is used to test for
14209 -- visibility of the attribute definition clause (in the sense of
14210 -- 8.3(23) as amended by AI-195).
14212 if not Defer_Declaration then
14214 Make_Subprogram_Declaration (Loc,
14215 Specification => Build_Spec);
14217 -- For a tagged type, there is always a visible declaration for each
14218 -- stream TSS (it is a predefined primitive operation), and the
14219 -- completion of this declaration occurs at the freeze point, which is
14220 -- not always visible at places where the attribute definition clause is
14221 -- visible. So, we create a dummy entity here for the purpose of
14222 -- tracking the visibility of the attribute definition clause itself.
14226 Make_Defining_Identifier (Loc, New_External_Name (Sname, 'V'));
14228 Make_Object_Declaration (Loc,
14229 Defining_Identifier => Subp_Id,
14230 Object_Definition => New_Occurrence_Of (Standard_Boolean, Loc));
14233 if not Defer_Declaration
14234 and then From_Aspect_Specification (N)
14235 and then Has_Delayed_Freeze (Ent)
14237 Append_Freeze_Action (Ent, Subp_Decl);
14240 Insert_Action (N, Subp_Decl);
14241 Set_Entity (N, Subp_Id);
14245 Make_Subprogram_Renaming_Declaration (Loc,
14246 Specification => Build_Spec,
14247 Name => New_Occurrence_Of (Subp, Loc));
14249 if Defer_Declaration then
14250 Set_TSS (Base_Type (Ent), Subp_Id);
14253 if From_Aspect_Specification (N) then
14254 Append_Freeze_Action (Ent, Subp_Decl);
14256 Insert_Action (N, Subp_Decl);
14259 Copy_TSS (Subp_Id, Base_Type (Ent));
14261 end New_Stream_Subprogram;
14263 ----------------------
14264 -- No_Type_Rep_Item --
14265 ----------------------
14267 procedure No_Type_Rep_Item (N : Node_Id) is
14269 Error_Msg_N ("|type-related representation item not permitted!", N);
14270 end No_Type_Rep_Item;
14276 procedure Pop_Type (E : Entity_Id) is
14278 if Ekind (E) = E_Record_Type and then E = Current_Scope then
14282 and then Has_Discriminants (E)
14283 and then Nkind (Parent (E)) /= N_Subtype_Declaration
14285 Uninstall_Discriminants (E);
14294 procedure Push_Type (E : Entity_Id) is
14298 if Ekind (E) = E_Record_Type then
14301 Comp := First_Component (E);
14302 while Present (Comp) loop
14303 Install_Entity (Comp);
14304 Next_Component (Comp);
14307 if Has_Discriminants (E) then
14308 Install_Discriminants (E);
14312 and then Has_Discriminants (E)
14313 and then Nkind (Parent (E)) /= N_Subtype_Declaration
14316 Install_Discriminants (E);
14320 -----------------------------------
14321 -- Register_Address_Clause_Check --
14322 -----------------------------------
14324 procedure Register_Address_Clause_Check
14331 ACS : constant Boolean := Scope_Suppress.Suppress (Alignment_Check);
14333 Address_Clause_Checks.Append ((N, X, A, Y, Off, ACS));
14334 end Register_Address_Clause_Check;
14336 ------------------------
14337 -- Rep_Item_Too_Early --
14338 ------------------------
14340 function Rep_Item_Too_Early (T : Entity_Id; N : Node_Id) return Boolean is
14341 function Has_Generic_Parent (E : Entity_Id) return Boolean;
14342 -- Return True if R or any ancestor is a generic type
14344 ------------------------
14345 -- Has_Generic_Parent --
14346 ------------------------
14348 function Has_Generic_Parent (E : Entity_Id) return Boolean is
14349 Ancestor_Type : Entity_Id := Etype (E);
14352 if Is_Generic_Type (E) then
14356 while Present (Ancestor_Type)
14357 and then not Is_Generic_Type (Ancestor_Type)
14358 and then Etype (Ancestor_Type) /= Ancestor_Type
14360 Ancestor_Type := Etype (Ancestor_Type);
14364 Present (Ancestor_Type) and then Is_Generic_Type (Ancestor_Type);
14365 end Has_Generic_Parent;
14367 -- Start of processing for Rep_Item_Too_Early
14370 -- Cannot apply non-operational rep items to generic types
14372 if Is_Operational_Item (N) then
14376 and then Has_Generic_Parent (T)
14377 and then (Nkind (N) /= N_Pragma
14378 or else Get_Pragma_Id (N) /= Pragma_Convention)
14380 if Ada_Version < Ada_2020 then
14382 ("representation item not allowed for generic type", N);
14389 -- Otherwise check for incomplete type
14391 if Is_Incomplete_Or_Private_Type (T)
14392 and then No (Underlying_Type (T))
14394 (Nkind (N) /= N_Pragma
14395 or else Get_Pragma_Id (N) /= Pragma_Import)
14398 ("representation item must be after full type declaration", N);
14401 -- If the type has incomplete components, a representation clause is
14402 -- illegal but stream attributes and Convention pragmas are correct.
14404 elsif Has_Private_Component (T) then
14405 if Nkind (N) = N_Pragma then
14410 ("representation item must appear after type is fully defined",
14417 end Rep_Item_Too_Early;
14419 -----------------------
14420 -- Rep_Item_Too_Late --
14421 -----------------------
14423 function Rep_Item_Too_Late
14426 FOnly : Boolean := False) return Boolean
14428 procedure Too_Late;
14429 -- Output message for an aspect being specified too late
14431 -- Note that neither of the above errors is considered a serious one,
14432 -- since the effect is simply that we ignore the representation clause
14434 -- Is this really true? In any case if we make this change we must
14435 -- document the requirement in the spec of Rep_Item_Too_Late that
14436 -- if True is returned, then the rep item must be completely ignored???
14442 procedure Too_Late is
14444 -- Other compilers seem more relaxed about rep items appearing too
14445 -- late. Since analysis tools typically don't care about rep items
14446 -- anyway, no reason to be too strict about this.
14448 if not Relaxed_RM_Semantics then
14449 Error_Msg_N ("|representation item appears too late!", N);
14455 Parent_Type : Entity_Id;
14458 -- Start of processing for Rep_Item_Too_Late
14461 -- First make sure entity is not frozen (RM 13.1(9))
14465 -- Exclude imported types, which may be frozen if they appear in a
14466 -- representation clause for a local type.
14468 and then not From_Limited_With (T)
14470 -- Exclude generated entities (not coming from source). The common
14471 -- case is when we generate a renaming which prematurely freezes the
14472 -- renamed internal entity, but we still want to be able to set copies
14473 -- of attribute values such as Size/Alignment.
14475 and then Comes_From_Source (T)
14477 -- A self-referential aspect is illegal if it forces freezing the
14478 -- entity before the corresponding pragma has been analyzed.
14480 if Nkind (N) in N_Attribute_Definition_Clause | N_Pragma
14481 and then From_Aspect_Specification (N)
14484 ("aspect specification causes premature freezing of&", N, T);
14485 Set_Has_Delayed_Freeze (T, False);
14490 S := First_Subtype (T);
14492 if Present (Freeze_Node (S)) then
14493 if not Relaxed_RM_Semantics then
14495 ("??no more representation items for }", Freeze_Node (S), S);
14501 -- Check for case of untagged derived type whose parent either has
14502 -- primitive operations (pre Ada 202x), or is a by-reference type (RM
14503 -- 13.1(10)). In this case we do not output a Too_Late message, since
14504 -- there is no earlier point where the rep item could be placed to make
14506 -- ??? Confirming representation clauses should be allowed here.
14510 and then Is_Derived_Type (T)
14511 and then not Is_Tagged_Type (T)
14513 Parent_Type := Etype (Base_Type (T));
14515 if Relaxed_RM_Semantics then
14518 elsif Ada_Version <= Ada_2012
14519 and then Has_Primitive_Operations (Parent_Type)
14522 ("|representation item not permitted before Ada 202x!", N);
14524 ("\parent type & has primitive operations!", N, Parent_Type);
14527 elsif Is_By_Reference_Type (Parent_Type) then
14528 No_Type_Rep_Item (N);
14530 ("\parent type & is a by-reference type!", N, Parent_Type);
14535 -- No error, but one more warning to consider. The RM (surprisingly)
14536 -- allows this pattern in some cases:
14539 -- primitive operations for S
14540 -- type R is new S;
14541 -- rep clause for S
14543 -- Meaning that calls on the primitive operations of S for values of
14544 -- type R may require possibly expensive implicit conversion operations.
14545 -- So even when this is not an error, it is still worth a warning.
14547 if not Relaxed_RM_Semantics and then Is_Type (T) then
14549 DTL : constant Entity_Id := Derived_Type_Link (Base_Type (T));
14554 -- For now, do not generate this warning for the case of
14555 -- aspect specification using Ada 2012 syntax, since we get
14556 -- wrong messages we do not understand. The whole business
14557 -- of derived types and rep items seems a bit confused when
14558 -- aspects are used, since the aspects are not evaluated
14559 -- till freeze time. However, AI12-0109 confirms (in an AARM
14560 -- ramification) that inheritance in this case is required
14563 and then not From_Aspect_Specification (N)
14565 if Is_By_Reference_Type (T)
14566 and then not Is_Tagged_Type (T)
14567 and then Is_Type_Related_Rep_Item (N)
14568 and then (Ada_Version >= Ada_2012
14569 or else Has_Primitive_Operations (Base_Type (T)))
14571 -- Treat as hard error (AI12-0109, binding interpretation).
14572 -- Implementing a change of representation is not really
14573 -- an option in the case of a by-reference type, so we
14574 -- take this path for all Ada dialects if primitive
14575 -- operations are present.
14576 Error_Msg_Sloc := Sloc (DTL);
14578 ("representation item for& appears after derived type "
14579 & "declaration#", N);
14581 elsif Has_Primitive_Operations (Base_Type (T)) then
14582 Error_Msg_Sloc := Sloc (DTL);
14585 ("representation item for& appears after derived type "
14586 & "declaration#??", N);
14588 ("\may result in implicit conversions for primitive "
14589 & "operations of&??", N, T);
14591 ("\to change representations when called with arguments "
14592 & "of type&??", N, DTL);
14598 -- No error, link item into head of chain of rep items for the entity,
14599 -- but avoid chaining if we have an overloadable entity, and the pragma
14600 -- is one that can apply to multiple overloaded entities.
14602 if Is_Overloadable (T) and then Nkind (N) = N_Pragma then
14604 Pname : constant Name_Id := Pragma_Name (N);
14606 if Pname in Name_Convention | Name_Import | Name_Export
14607 | Name_External | Name_Interface
14614 Record_Rep_Item (T, N);
14616 end Rep_Item_Too_Late;
14618 -------------------------------------
14619 -- Replace_Type_References_Generic --
14620 -------------------------------------
14622 procedure Replace_Type_References_Generic (N : Node_Id; T : Entity_Id) is
14623 TName : constant Name_Id := Chars (T);
14625 function Replace_Type_Ref (N : Node_Id) return Traverse_Result;
14626 -- Processes a single node in the traversal procedure below, checking
14627 -- if node N should be replaced, and if so, doing the replacement.
14629 function Visible_Component (Comp : Name_Id) return Entity_Id;
14630 -- Given an identifier in the expression, check whether there is a
14631 -- discriminant, component, protected procedure, or entry of the type
14632 -- that is directy visible, and rewrite it as the corresponding selected
14633 -- component of the formal of the subprogram.
14635 ----------------------
14636 -- Replace_Type_Ref --
14637 ----------------------
14639 function Replace_Type_Ref (N : Node_Id) return Traverse_Result is
14640 Loc : constant Source_Ptr := Sloc (N);
14642 procedure Add_Prefix (Ref : Node_Id; Comp : Entity_Id);
14643 -- Add the proper prefix to a reference to a component of the type
14644 -- when it is not already a selected component.
14650 procedure Add_Prefix (Ref : Node_Id; Comp : Entity_Id) is
14653 Make_Selected_Component (Loc,
14654 Prefix => New_Occurrence_Of (T, Loc),
14655 Selector_Name => New_Occurrence_Of (Comp, Loc)));
14656 Replace_Type_Reference (Prefix (Ref));
14665 -- Start of processing for Replace_Type_Ref
14668 if Nkind (N) = N_Identifier then
14670 -- If not the type name, check whether it is a reference to some
14671 -- other type, which must be frozen before the predicate function
14672 -- is analyzed, i.e. before the freeze node of the type to which
14673 -- the predicate applies.
14675 if Chars (N) /= TName then
14676 if Present (Current_Entity (N))
14677 and then Is_Type (Current_Entity (N))
14679 Freeze_Before (Freeze_Node (T), Current_Entity (N));
14682 -- The components of the type are directly visible and can
14683 -- be referenced without a prefix.
14685 if Nkind (Parent (N)) = N_Selected_Component then
14688 -- In expression C (I), C may be a directly visible function
14689 -- or a visible component that has an array type. Disambiguate
14690 -- by examining the component type.
14692 elsif Nkind (Parent (N)) = N_Indexed_Component
14693 and then N = Prefix (Parent (N))
14695 Comp := Visible_Component (Chars (N));
14697 if Present (Comp) and then Is_Array_Type (Etype (Comp)) then
14698 Add_Prefix (N, Comp);
14702 Comp := Visible_Component (Chars (N));
14704 if Present (Comp) then
14705 Add_Prefix (N, Comp);
14711 -- Otherwise do the replacement if this is not a qualified
14712 -- reference to a homograph of the type itself. Note that the
14713 -- current instance could not appear in such a context, e.g.
14714 -- the prefix of a type conversion.
14717 if Nkind (Parent (N)) /= N_Selected_Component
14718 or else N /= Selector_Name (Parent (N))
14720 Replace_Type_Reference (N);
14726 -- Case of selected component, which may be a subcomponent of the
14727 -- current instance, or an expanded name which is still unanalyzed.
14729 elsif Nkind (N) = N_Selected_Component then
14731 -- If selector name is not our type, keep going (we might still
14732 -- have an occurrence of the type in the prefix). If it is a
14733 -- subcomponent of the current entity, add prefix.
14735 if Nkind (Selector_Name (N)) /= N_Identifier
14736 or else Chars (Selector_Name (N)) /= TName
14738 if Nkind (Prefix (N)) = N_Identifier then
14739 Comp := Visible_Component (Chars (Prefix (N)));
14741 if Present (Comp) then
14742 Add_Prefix (Prefix (N), Comp);
14748 -- Selector name is our type, check qualification
14751 -- Loop through scopes and prefixes, doing comparison
14753 Scop := Current_Scope;
14754 Pref := Prefix (N);
14756 -- Continue if no more scopes or scope with no name
14758 if No (Scop) or else Nkind (Scop) not in N_Has_Chars then
14762 -- Do replace if prefix is an identifier matching the scope
14763 -- that we are currently looking at.
14765 if Nkind (Pref) = N_Identifier
14766 and then Chars (Pref) = Chars (Scop)
14768 Replace_Type_Reference (N);
14772 -- Go check scope above us if prefix is itself of the form
14773 -- of a selected component, whose selector matches the scope
14774 -- we are currently looking at.
14776 if Nkind (Pref) = N_Selected_Component
14777 and then Nkind (Selector_Name (Pref)) = N_Identifier
14778 and then Chars (Selector_Name (Pref)) = Chars (Scop)
14780 Scop := Scope (Scop);
14781 Pref := Prefix (Pref);
14783 -- For anything else, we don't have a match, so keep on
14784 -- going, there are still some weird cases where we may
14785 -- still have a replacement within the prefix.
14793 -- Continue for any other node kind
14798 end Replace_Type_Ref;
14800 procedure Replace_Type_Refs is new Traverse_Proc (Replace_Type_Ref);
14802 -----------------------
14803 -- Visible_Component --
14804 -----------------------
14806 function Visible_Component (Comp : Name_Id) return Entity_Id is
14809 -- Types with nameable components are record, task, and protected
14810 -- types, and discriminated private types.
14812 if Ekind (T) in E_Record_Type
14815 or else (Is_Private_Type (T) and then Has_Discriminants (T))
14817 -- This is a sequential search, which seems acceptable
14818 -- efficiency-wise, given the typical size of component
14819 -- lists, protected operation lists, task item lists, and
14820 -- check expressions.
14822 E := First_Entity (T);
14823 while Present (E) loop
14824 if Comes_From_Source (E) and then Chars (E) = Comp then
14832 -- Nothing by that name
14835 end Visible_Component;
14837 -- Start of processing for Replace_Type_References_Generic
14840 Replace_Type_Refs (N);
14841 end Replace_Type_References_Generic;
14843 --------------------------------
14844 -- Resolve_Aspect_Expressions --
14845 --------------------------------
14847 procedure Resolve_Aspect_Expressions (E : Entity_Id) is
14848 function Resolve_Name (N : Node_Id) return Traverse_Result;
14849 -- Verify that all identifiers in the expression, with the exception
14850 -- of references to the current entity, denote visible entities. This
14851 -- is done only to detect visibility errors, as the expression will be
14852 -- properly analyzed/expanded during analysis of the predicate function
14853 -- body. We omit quantified expressions from this test, given that they
14854 -- introduce a local identifier that would require proper expansion to
14855 -- handle properly.
14861 function Resolve_Name (N : Node_Id) return Traverse_Result is
14862 Dummy : Traverse_Result;
14865 if Nkind (N) = N_Selected_Component then
14866 if Nkind (Prefix (N)) = N_Identifier
14867 and then Chars (Prefix (N)) /= Chars (E)
14869 Find_Selected_Component (N);
14874 -- Resolve identifiers that are not selectors in parameter
14875 -- associations (these are never resolved by visibility).
14877 elsif Nkind (N) = N_Identifier
14878 and then Chars (N) /= Chars (E)
14879 and then (Nkind (Parent (N)) /= N_Parameter_Association
14880 or else N /= Selector_Name (Parent (N)))
14882 Find_Direct_Name (N);
14883 Set_Entity (N, Empty);
14885 -- The name is component association needs no resolution.
14887 elsif Nkind (N) = N_Component_Association then
14888 Dummy := Resolve_Name (Expression (N));
14891 elsif Nkind (N) = N_Quantified_Expression then
14898 procedure Resolve_Aspect_Expression is new Traverse_Proc (Resolve_Name);
14902 ASN : Node_Id := First_Rep_Item (E);
14904 -- Start of processing for Resolve_Aspect_Expressions
14911 while Present (ASN) loop
14912 if Nkind (ASN) = N_Aspect_Specification and then Entity (ASN) = E then
14914 A_Id : constant Aspect_Id := Get_Aspect_Id (ASN);
14915 Expr : constant Node_Id := Expression (ASN);
14920 when Aspect_Aggregate =>
14921 Resolve_Aspect_Aggregate (Entity (ASN), Expr);
14923 -- For now we only deal with aspects that do not generate
14924 -- subprograms, or that may mention current instances of
14925 -- types. These will require special handling (???TBD).
14927 when Aspect_Invariant
14929 | Aspect_Predicate_Failure
14933 when Aspect_Dynamic_Predicate
14934 | Aspect_Static_Predicate
14936 -- Build predicate function specification and preanalyze
14937 -- expression after type replacement. The function
14938 -- declaration must be analyzed in the scope of the type,
14939 -- but the expression can reference components and
14940 -- discriminants of the type.
14942 if No (Predicate_Function (E)) then
14944 FDecl : constant Node_Id :=
14945 Build_Predicate_Function_Declaration (E);
14946 pragma Unreferenced (FDecl);
14950 Resolve_Aspect_Expression (Expr);
14955 when Pre_Post_Aspects =>
14958 when Aspect_Iterable =>
14959 if Nkind (Expr) = N_Aggregate then
14964 Assoc := First (Component_Associations (Expr));
14965 while Present (Assoc) loop
14966 Find_Direct_Name (Expression (Assoc));
14972 -- The expression for Default_Value is a static expression
14973 -- of the type, but this expression does not freeze the
14974 -- type, so it can still appear in a representation clause
14975 -- before the actual freeze point.
14977 when Aspect_Default_Value =>
14978 Set_Must_Not_Freeze (Expr);
14979 Preanalyze_Spec_Expression (Expr, E);
14981 when Aspect_Priority =>
14983 Preanalyze_Spec_Expression (Expr, Any_Integer);
14986 -- Ditto for Storage_Size. Any other aspects that carry
14987 -- expressions that should not freeze ??? This is only
14988 -- relevant to the misuse of deferred constants.
14990 when Aspect_Storage_Size =>
14991 Set_Must_Not_Freeze (Expr);
14992 Preanalyze_Spec_Expression (Expr, Any_Integer);
14995 if Present (Expr) then
14996 case Aspect_Argument (A_Id) is
14998 | Optional_Expression
15000 Analyze_And_Resolve (Expr);
15005 if Nkind (Expr) = N_Identifier then
15006 Find_Direct_Name (Expr);
15008 elsif Nkind (Expr) = N_Selected_Component then
15009 Find_Selected_Component (Expr);
15017 Next_Rep_Item (ASN);
15019 end Resolve_Aspect_Expressions;
15021 ----------------------------
15022 -- Parse_Aspect_Aggregate --
15023 ----------------------------
15025 procedure Parse_Aspect_Aggregate
15027 Empty_Subp : in out Node_Id;
15028 Add_Named_Subp : in out Node_Id;
15029 Add_Unnamed_Subp : in out Node_Id;
15030 New_Indexed_Subp : in out Node_Id;
15031 Assign_Indexed_Subp : in out Node_Id)
15033 Assoc : Node_Id := First (Component_Associations (N));
15038 while Present (Assoc) loop
15039 Subp := Expression (Assoc);
15040 Op_Name := Chars (First (Choices (Assoc)));
15041 if Op_Name = Name_Empty then
15042 Empty_Subp := Subp;
15044 elsif Op_Name = Name_Add_Named then
15045 Add_Named_Subp := Subp;
15047 elsif Op_Name = Name_Add_Unnamed then
15048 Add_Unnamed_Subp := Subp;
15050 elsif Op_Name = Name_New_Indexed then
15051 New_Indexed_Subp := Subp;
15053 elsif Op_Name = Name_Assign_Indexed then
15054 Assign_Indexed_Subp := Subp;
15059 end Parse_Aspect_Aggregate;
15061 -------------------------------
15062 -- Validate_Aspect_Aggregate --
15063 -------------------------------
15065 procedure Validate_Aspect_Aggregate (N : Node_Id) is
15066 Empty_Subp : Node_Id := Empty;
15067 Add_Named_Subp : Node_Id := Empty;
15068 Add_Unnamed_Subp : Node_Id := Empty;
15069 New_Indexed_Subp : Node_Id := Empty;
15070 Assign_Indexed_Subp : Node_Id := Empty;
15073 if Ada_Version < Ada_2020 then
15074 Error_Msg_N ("Aspect Aggregate is an Ada_2020 feature", N);
15076 elsif Nkind (N) /= N_Aggregate
15077 or else Present (Expressions (N))
15078 or else No (Component_Associations (N))
15080 Error_Msg_N ("Aspect Aggregate requires an aggregate "
15081 & "with component associations", N);
15085 Parse_Aspect_Aggregate (N,
15086 Empty_Subp, Add_Named_Subp, Add_Unnamed_Subp,
15087 New_Indexed_Subp, Assign_Indexed_Subp);
15089 if No (Empty_Subp) then
15090 Error_Msg_N ("missing specification for Empty in aggregate", N);
15093 if Present (Add_Named_Subp) then
15094 if Present (Add_Unnamed_Subp)
15095 or else Present (Assign_Indexed_Subp)
15098 ("conflicting operations for aggregate (RM 4.3.5)", N);
15102 elsif Present (New_Indexed_Subp) /= Present (Assign_Indexed_Subp) then
15103 Error_Msg_N ("incomplete specification for indexed aggregate", N);
15105 end Validate_Aspect_Aggregate;
15107 --------------------------------
15108 -- Resolve_Iterable_Operation --
15109 --------------------------------
15111 procedure Resolve_Iterable_Operation
15113 Cursor : Entity_Id;
15122 if not Is_Overloaded (N) then
15123 if not Is_Entity_Name (N)
15124 or else Ekind (Entity (N)) /= E_Function
15125 or else Scope (Entity (N)) /= Scope (Typ)
15126 or else No (First_Formal (Entity (N)))
15127 or else Etype (First_Formal (Entity (N))) /= Typ
15130 ("iterable primitive must be local function name whose first "
15131 & "formal is an iterable type", N);
15136 F1 := First_Formal (Ent);
15138 if Nam = Name_First or else Nam = Name_Last then
15140 -- First or Last (Container) => Cursor
15142 if Etype (Ent) /= Cursor then
15143 Error_Msg_N ("primitive for First must yield a curosr", N);
15146 elsif Nam = Name_Next then
15148 -- Next (Container, Cursor) => Cursor
15150 F2 := Next_Formal (F1);
15152 if Etype (F2) /= Cursor
15153 or else Etype (Ent) /= Cursor
15154 or else Present (Next_Formal (F2))
15156 Error_Msg_N ("no match for Next iterable primitive", N);
15159 elsif Nam = Name_Previous then
15161 -- Previous (Container, Cursor) => Cursor
15163 F2 := Next_Formal (F1);
15165 if Etype (F2) /= Cursor
15166 or else Etype (Ent) /= Cursor
15167 or else Present (Next_Formal (F2))
15169 Error_Msg_N ("no match for Previous iterable primitive", N);
15172 elsif Nam = Name_Has_Element then
15174 -- Has_Element (Container, Cursor) => Boolean
15176 F2 := Next_Formal (F1);
15178 if Etype (F2) /= Cursor
15179 or else Etype (Ent) /= Standard_Boolean
15180 or else Present (Next_Formal (F2))
15182 Error_Msg_N ("no match for Has_Element iterable primitive", N);
15185 elsif Nam = Name_Element then
15186 F2 := Next_Formal (F1);
15189 or else Etype (F2) /= Cursor
15190 or else Present (Next_Formal (F2))
15192 Error_Msg_N ("no match for Element iterable primitive", N);
15196 raise Program_Error;
15200 -- Overloaded case: find subprogram with proper signature. Caller
15201 -- will report error if no match is found.
15208 Get_First_Interp (N, I, It);
15209 while Present (It.Typ) loop
15210 if Ekind (It.Nam) = E_Function
15211 and then Scope (It.Nam) = Scope (Typ)
15212 and then Etype (First_Formal (It.Nam)) = Typ
15214 F1 := First_Formal (It.Nam);
15216 if Nam = Name_First then
15217 if Etype (It.Nam) = Cursor
15218 and then No (Next_Formal (F1))
15220 Set_Entity (N, It.Nam);
15224 elsif Nam = Name_Next then
15225 F2 := Next_Formal (F1);
15228 and then No (Next_Formal (F2))
15229 and then Etype (F2) = Cursor
15230 and then Etype (It.Nam) = Cursor
15232 Set_Entity (N, It.Nam);
15236 elsif Nam = Name_Has_Element then
15237 F2 := Next_Formal (F1);
15240 and then No (Next_Formal (F2))
15241 and then Etype (F2) = Cursor
15242 and then Etype (It.Nam) = Standard_Boolean
15244 Set_Entity (N, It.Nam);
15245 F2 := Next_Formal (F1);
15249 elsif Nam = Name_Element then
15250 F2 := Next_Formal (F1);
15253 and then No (Next_Formal (F2))
15254 and then Etype (F2) = Cursor
15256 Set_Entity (N, It.Nam);
15262 Get_Next_Interp (I, It);
15266 end Resolve_Iterable_Operation;
15268 ------------------------------
15269 -- Resolve_Aspect_Aggregate --
15270 ------------------------------
15272 procedure Resolve_Aspect_Aggregate
15276 -- Predicates that establish the legality of each possible operation in
15277 -- an Aggregate aspect.
15279 function Valid_Empty (E : Entity_Id) return Boolean;
15280 function Valid_Add_Named (E : Entity_Id) return Boolean;
15281 function Valid_Add_Unnamed (E : Entity_Id) return Boolean;
15282 function Valid_New_Indexed (E : Entity_Id) return Boolean;
15283 function Valid_Assign_Indexed (E : Entity_Id) return Boolean;
15286 with function Pred (Id : Node_Id) return Boolean;
15287 procedure Resolve_Operation (Subp_Id : Node_Id);
15288 -- Common processing to resolve each aggregate operation.
15290 ------------------------
15291 -- Valid_Assign_Index --
15292 ------------------------
15294 function Valid_Assign_Indexed (E : Entity_Id) return Boolean is
15296 -- The profile must be the same as for Add_Named, with the added
15297 -- requirement that the key_type be a discrete type.
15299 if Valid_Add_Named (E) then
15300 return Is_Discrete_Type (Etype (Next_Formal (First_Formal (E))));
15304 end Valid_Assign_Indexed;
15310 function Valid_Empty (E : Entity_Id) return Boolean is
15312 if Etype (E) /= Typ or else Scope (E) /= Scope (Typ) then
15315 elsif Ekind (E) = E_Constant then
15318 elsif Ekind (E) = E_Function then
15319 return No (First_Formal (E))
15321 (Is_Integer_Type (Etype (First_Formal (E)))
15322 and then No (Next_Formal (First_Formal (E))));
15328 ---------------------
15329 -- Valid_Add_Named --
15330 ---------------------
15332 function Valid_Add_Named (E : Entity_Id) return Boolean is
15333 F2, F3 : Entity_Id;
15335 if Ekind (E) = E_Procedure
15336 and then Scope (E) = Scope (Typ)
15337 and then Number_Formals (E) = 3
15338 and then Etype (First_Formal (E)) = Typ
15339 and then Ekind (First_Formal (E)) = E_In_Out_Parameter
15341 F2 := Next_Formal (First_Formal (E));
15342 F3 := Next_Formal (F2);
15343 return Ekind (F2) = E_In_Parameter
15344 and then Ekind (F3) = E_In_Parameter
15345 and then not Is_Limited_Type (Etype (F2))
15346 and then not Is_Limited_Type (Etype (F3));
15350 end Valid_Add_Named;
15352 -----------------------
15353 -- Valid_Add_Unnamed --
15354 -----------------------
15356 function Valid_Add_Unnamed (E : Entity_Id) return Boolean is
15358 return Ekind (E) = E_Procedure
15359 and then Scope (E) = Scope (Typ)
15360 and then Number_Formals (E) = 2
15361 and then Etype (First_Formal (E)) = Typ
15362 and then Ekind (First_Formal (E)) = E_In_Out_Parameter
15364 not Is_Limited_Type (Etype (Next_Formal (First_Formal (E))));
15365 end Valid_Add_Unnamed;
15367 -----------------------
15368 -- Valid_Nmw_Indexed --
15369 -----------------------
15371 function Valid_New_Indexed (E : Entity_Id) return Boolean is
15373 return Ekind (E) = E_Function
15374 and then Scope (E) = Scope (Typ)
15375 and then Etype (E) = Typ
15376 and then Number_Formals (E) = 2
15377 and then Is_Discrete_Type (Etype (First_Formal (E)))
15378 and then Etype (First_Formal (E)) =
15379 Etype (Next_Formal (First_Formal (E)));
15380 end Valid_New_Indexed;
15382 -----------------------
15383 -- Resolve_Operation --
15384 -----------------------
15386 procedure Resolve_Operation (Subp_Id : Node_Id) is
15393 if not Is_Overloaded (Subp_Id) then
15394 Subp := Entity (Subp_Id);
15395 if not Pred (Subp) then
15397 ("improper aggregate operation for&", Subp_Id, Typ);
15401 Set_Entity (Subp_Id, Empty);
15402 Get_First_Interp (Subp_Id, I, It);
15403 while Present (It.Nam) loop
15404 if Pred (It.Nam) then
15405 Set_Is_Overloaded (Subp_Id, False);
15406 Set_Entity (Subp_Id, It.Nam);
15410 Get_Next_Interp (I, It);
15413 if No (Entity (Subp_Id)) then
15415 ("improper aggregate operation for&", Subp_Id, Typ);
15418 end Resolve_Operation;
15424 procedure Resolve_Empty is new Resolve_Operation (Valid_Empty);
15425 procedure Resolve_Unnamed is new Resolve_Operation (Valid_Add_Unnamed);
15426 procedure Resolve_Named is new Resolve_Operation (Valid_Add_Named);
15427 procedure Resolve_Indexed is new Resolve_Operation (Valid_New_Indexed);
15428 procedure Resolve_Assign_Indexed
15429 is new Resolve_Operation
15430 (Valid_Assign_Indexed);
15432 Assoc := First (Component_Associations (Expr));
15434 while Present (Assoc) loop
15435 Op_Name := Chars (First (Choices (Assoc)));
15437 -- When verifying the consistency of aspects between the freeze point
15438 -- and the end of declarqtions, we use a copy which is not analyzed
15439 -- yet, so do it now.
15441 Subp_Id := Expression (Assoc);
15442 if No (Etype (Subp_Id)) then
15446 if Op_Name = Name_Empty then
15447 Resolve_Empty (Subp_Id);
15449 elsif Op_Name = Name_Add_Named then
15450 Resolve_Named (Subp_Id);
15452 elsif Op_Name = Name_Add_Unnamed then
15453 Resolve_Unnamed (Subp_Id);
15455 elsif Op_Name = Name_New_Indexed then
15456 Resolve_Indexed (Subp_Id);
15458 elsif Op_Name = Name_Assign_Indexed then
15459 Resolve_Assign_Indexed (Subp_Id);
15464 end Resolve_Aspect_Aggregate;
15470 procedure Set_Biased
15474 Biased : Boolean := True)
15478 Set_Has_Biased_Representation (E);
15480 if Warn_On_Biased_Representation then
15482 ("?B?" & Msg & " forces biased representation for&", N, E);
15487 --------------------
15488 -- Set_Enum_Esize --
15489 --------------------
15491 procedure Set_Enum_Esize (T : Entity_Id) is
15497 Init_Alignment (T);
15499 -- Find the minimum standard size (8,16,32,64,128) that fits
15501 Lo := Enumeration_Rep (Entity (Type_Low_Bound (T)));
15502 Hi := Enumeration_Rep (Entity (Type_High_Bound (T)));
15505 if Lo >= -Uint_2**07 and then Hi < Uint_2**07 then
15506 Sz := Standard_Character_Size; -- May be > 8 on some targets
15508 elsif Lo >= -Uint_2**15 and then Hi < Uint_2**15 then
15511 elsif Lo >= -Uint_2**31 and then Hi < Uint_2**31 then
15514 elsif Lo >= -Uint_2**63 and then Hi < Uint_2**63 then
15517 else pragma Assert (Lo >= -Uint_2**127 and then Hi < Uint_2**127);
15522 if Hi < Uint_2**08 then
15523 Sz := Standard_Character_Size; -- May be > 8 on some targets
15525 elsif Hi < Uint_2**16 then
15528 elsif Hi < Uint_2**32 then
15531 elsif Hi < Uint_2**64 then
15534 else pragma Assert (Hi < Uint_2**128);
15539 -- That minimum is the proper size unless we have a foreign convention
15540 -- and the size required is 32 or less, in which case we bump the size
15541 -- up to 32. This is required for C and C++ and seems reasonable for
15542 -- all other foreign conventions.
15544 if Has_Foreign_Convention (T)
15545 and then Esize (T) < Standard_Integer_Size
15547 -- Don't do this if Short_Enums on target
15549 and then not Target_Short_Enums
15551 Init_Esize (T, Standard_Integer_Size);
15553 Init_Esize (T, Sz);
15555 end Set_Enum_Esize;
15557 -----------------------------
15558 -- Uninstall_Discriminants --
15559 -----------------------------
15561 procedure Uninstall_Discriminants (E : Entity_Id) is
15567 -- Discriminants have been made visible for type declarations and
15568 -- protected type declarations, not for subtype declarations.
15570 if Nkind (Parent (E)) /= N_Subtype_Declaration then
15571 Disc := First_Discriminant (E);
15572 while Present (Disc) loop
15573 if Disc /= Current_Entity (Disc) then
15574 Prev := Current_Entity (Disc);
15575 while Present (Prev)
15576 and then Present (Homonym (Prev))
15577 and then Homonym (Prev) /= Disc
15579 Prev := Homonym (Prev);
15585 Set_Is_Immediately_Visible (Disc, False);
15587 Outer := Homonym (Disc);
15588 while Present (Outer) and then Scope (Outer) = E loop
15589 Outer := Homonym (Outer);
15592 -- Reset homonym link of other entities, but do not modify link
15593 -- between entities in current scope, so that the back end can
15594 -- have a proper count of local overloadings.
15597 Set_Name_Entity_Id (Chars (Disc), Outer);
15599 elsif Scope (Prev) /= Scope (Disc) then
15600 Set_Homonym (Prev, Outer);
15603 Next_Discriminant (Disc);
15606 end Uninstall_Discriminants;
15608 ------------------------------
15609 -- Validate_Address_Clauses --
15610 ------------------------------
15612 procedure Validate_Address_Clauses is
15613 function Offset_Value (Expr : Node_Id) return Uint;
15614 -- Given an Address attribute reference, return the value in bits of its
15615 -- offset from the first bit of the underlying entity, or 0 if it is not
15616 -- known at compile time.
15622 function Offset_Value (Expr : Node_Id) return Uint is
15623 N : Node_Id := Prefix (Expr);
15625 Val : Uint := Uint_0;
15628 -- Climb the prefix chain and compute the cumulative offset
15631 if Is_Entity_Name (N) then
15634 elsif Nkind (N) = N_Selected_Component then
15635 Off := Component_Bit_Offset (Entity (Selector_Name (N)));
15636 if Off /= No_Uint and then Off >= Uint_0 then
15643 elsif Nkind (N) = N_Indexed_Component then
15644 Off := Indexed_Component_Bit_Offset (N);
15645 if Off /= No_Uint then
15658 -- Start of processing for Validate_Address_Clauses
15661 for J in Address_Clause_Checks.First .. Address_Clause_Checks.Last loop
15663 ACCR : Address_Clause_Check_Record
15664 renames Address_Clause_Checks.Table (J);
15668 X_Alignment : Uint;
15669 Y_Alignment : Uint := Uint_0;
15672 Y_Size : Uint := Uint_0;
15677 -- Skip processing of this entry if warning already posted
15679 if not Address_Warning_Posted (ACCR.N) then
15680 Expr := Original_Node (Expression (ACCR.N));
15682 -- Get alignments, sizes and offset, if any
15684 X_Alignment := Alignment (ACCR.X);
15685 X_Size := Esize (ACCR.X);
15687 if Present (ACCR.Y) then
15688 Y_Alignment := Alignment (ACCR.Y);
15689 Y_Size := Esize (ACCR.Y);
15693 and then Nkind (Expr) = N_Attribute_Reference
15694 and then Attribute_Name (Expr) = Name_Address
15696 X_Offs := Offset_Value (Expr);
15701 -- Check for known value not multiple of alignment
15703 if No (ACCR.Y) then
15704 if not Alignment_Checks_Suppressed (ACCR)
15705 and then X_Alignment /= 0
15706 and then ACCR.A mod X_Alignment /= 0
15709 ("??specified address for& is inconsistent with "
15710 & "alignment", ACCR.N, ACCR.X);
15712 ("\??program execution may be erroneous (RM 13.3(27))",
15715 Error_Msg_Uint_1 := X_Alignment;
15716 Error_Msg_NE ("\??alignment of & is ^", ACCR.N, ACCR.X);
15719 -- Check for large object overlaying smaller one
15721 elsif Y_Size > Uint_0
15722 and then X_Size > Uint_0
15723 and then X_Offs + X_Size > Y_Size
15725 Error_Msg_NE ("??& overlays smaller object", ACCR.N, ACCR.X);
15727 ("\??program execution may be erroneous", ACCR.N);
15729 Error_Msg_Uint_1 := X_Size;
15730 Error_Msg_NE ("\??size of & is ^", ACCR.N, ACCR.X);
15732 Error_Msg_Uint_1 := Y_Size;
15733 Error_Msg_NE ("\??size of & is ^", ACCR.N, ACCR.Y);
15735 if Y_Size >= X_Size then
15736 Error_Msg_Uint_1 := X_Offs;
15737 Error_Msg_NE ("\??but offset of & is ^", ACCR.N, ACCR.X);
15740 -- Check for inadequate alignment, both of the base object
15741 -- and of the offset, if any. We only do this check if the
15742 -- run-time Alignment_Check is active. No point in warning
15743 -- if this check has been suppressed (or is suppressed by
15744 -- default in the non-strict alignment machine case).
15746 -- Note: we do not check the alignment if we gave a size
15747 -- warning, since it would likely be redundant.
15749 elsif not Alignment_Checks_Suppressed (ACCR)
15750 and then Y_Alignment /= Uint_0
15752 (Y_Alignment < X_Alignment
15755 and then Nkind (Expr) = N_Attribute_Reference
15756 and then Attribute_Name (Expr) = Name_Address
15757 and then Has_Compatible_Alignment
15758 (ACCR.X, Prefix (Expr), True) /=
15762 ("??specified address for& may be inconsistent with "
15763 & "alignment", ACCR.N, ACCR.X);
15765 ("\??program execution may be erroneous (RM 13.3(27))",
15768 Error_Msg_Uint_1 := X_Alignment;
15769 Error_Msg_NE ("\??alignment of & is ^", ACCR.N, ACCR.X);
15771 Error_Msg_Uint_1 := Y_Alignment;
15772 Error_Msg_NE ("\??alignment of & is ^", ACCR.N, ACCR.Y);
15774 if Y_Alignment >= X_Alignment then
15776 ("\??but offset is not multiple of alignment", ACCR.N);
15782 end Validate_Address_Clauses;
15784 ---------------------------
15785 -- Validate_Independence --
15786 ---------------------------
15788 procedure Validate_Independence is
15789 SU : constant Uint := UI_From_Int (System_Storage_Unit);
15797 procedure Check_Array_Type (Atyp : Entity_Id);
15798 -- Checks if the array type Atyp has independent components, and
15799 -- if not, outputs an appropriate set of error messages.
15801 procedure No_Independence;
15802 -- Output message that independence cannot be guaranteed
15804 function OK_Component (C : Entity_Id) return Boolean;
15805 -- Checks one component to see if it is independently accessible, and
15806 -- if so yields True, otherwise yields False if independent access
15807 -- cannot be guaranteed. This is a conservative routine, it only
15808 -- returns True if it knows for sure, it returns False if it knows
15809 -- there is a problem, or it cannot be sure there is no problem.
15811 procedure Reason_Bad_Component (C : Entity_Id);
15812 -- Outputs continuation message if a reason can be determined for
15813 -- the component C being bad.
15815 ----------------------
15816 -- Check_Array_Type --
15817 ----------------------
15819 procedure Check_Array_Type (Atyp : Entity_Id) is
15820 Ctyp : constant Entity_Id := Component_Type (Atyp);
15823 -- OK if no alignment clause, no pack, and no component size
15825 if not Has_Component_Size_Clause (Atyp)
15826 and then not Has_Alignment_Clause (Atyp)
15827 and then not Is_Packed (Atyp)
15832 -- Case where component size is greater than or equal to the maximum
15833 -- integer size and the alignment of the array is at least as large
15834 -- as the alignment of the component. We are OK in this situation.
15836 if Known_Component_Size (Atyp)
15837 and then Component_Size (Atyp) >= System_Max_Integer_Size
15838 and then Known_Alignment (Atyp)
15839 and then Known_Alignment (Ctyp)
15840 and then Alignment (Atyp) >= Alignment (Ctyp)
15845 -- Check actual component size
15847 if not Known_Component_Size (Atyp)
15848 or else not Addressable (Component_Size (Atyp))
15849 or else Component_Size (Atyp) mod Esize (Ctyp) /= 0
15853 -- Bad component size, check reason
15855 if Has_Component_Size_Clause (Atyp) then
15856 P := Get_Attribute_Definition_Clause
15857 (Atyp, Attribute_Component_Size);
15859 if Present (P) then
15860 Error_Msg_Sloc := Sloc (P);
15861 Error_Msg_N ("\because of Component_Size clause#", N);
15866 if Is_Packed (Atyp) then
15867 P := Get_Rep_Pragma (Atyp, Name_Pack);
15869 if Present (P) then
15870 Error_Msg_Sloc := Sloc (P);
15871 Error_Msg_N ("\because of pragma Pack#", N);
15876 -- No reason found, just return
15881 -- Array type is OK independence-wise
15884 end Check_Array_Type;
15886 ---------------------
15887 -- No_Independence --
15888 ---------------------
15890 procedure No_Independence is
15892 if Pragma_Name (N) = Name_Independent then
15893 Error_Msg_NE ("independence cannot be guaranteed for&", N, E);
15896 ("independent components cannot be guaranteed for&", N, E);
15898 end No_Independence;
15904 function OK_Component (C : Entity_Id) return Boolean is
15905 Rec : constant Entity_Id := Scope (C);
15906 Ctyp : constant Entity_Id := Etype (C);
15909 -- OK if no component clause, no Pack, and no alignment clause
15911 if No (Component_Clause (C))
15912 and then not Is_Packed (Rec)
15913 and then not Has_Alignment_Clause (Rec)
15918 -- Here we look at the actual component layout. A component is
15919 -- addressable if its size is a multiple of the Esize of the
15920 -- component type, and its starting position in the record has
15921 -- appropriate alignment, and the record itself has appropriate
15922 -- alignment to guarantee the component alignment.
15924 -- Make sure sizes are static, always assume the worst for any
15925 -- cases where we cannot check static values.
15927 if not (Known_Static_Esize (C)
15929 Known_Static_Esize (Ctyp))
15934 -- Size of component must be addressable or greater than the maximum
15935 -- integer size and a multiple of bytes.
15937 if not Addressable (Esize (C))
15938 and then Esize (C) < System_Max_Integer_Size
15943 -- Check size is proper multiple
15945 if Esize (C) mod Esize (Ctyp) /= 0 then
15949 -- Check alignment of component is OK
15951 if not Known_Component_Bit_Offset (C)
15952 or else Component_Bit_Offset (C) < Uint_0
15953 or else Component_Bit_Offset (C) mod Esize (Ctyp) /= 0
15958 -- Check alignment of record type is OK
15960 if not Known_Alignment (Rec)
15961 or else (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0
15966 -- All tests passed, component is addressable
15971 --------------------------
15972 -- Reason_Bad_Component --
15973 --------------------------
15975 procedure Reason_Bad_Component (C : Entity_Id) is
15976 Rec : constant Entity_Id := Scope (C);
15977 Ctyp : constant Entity_Id := Etype (C);
15980 -- If component clause present assume that's the problem
15982 if Present (Component_Clause (C)) then
15983 Error_Msg_Sloc := Sloc (Component_Clause (C));
15984 Error_Msg_N ("\because of Component_Clause#", N);
15988 -- If pragma Pack clause present, assume that's the problem
15990 if Is_Packed (Rec) then
15991 P := Get_Rep_Pragma (Rec, Name_Pack);
15993 if Present (P) then
15994 Error_Msg_Sloc := Sloc (P);
15995 Error_Msg_N ("\because of pragma Pack#", N);
16000 -- See if record has bad alignment clause
16002 if Has_Alignment_Clause (Rec)
16003 and then Known_Alignment (Rec)
16004 and then (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0
16006 P := Get_Attribute_Definition_Clause (Rec, Attribute_Alignment);
16008 if Present (P) then
16009 Error_Msg_Sloc := Sloc (P);
16010 Error_Msg_N ("\because of Alignment clause#", N);
16014 -- Couldn't find a reason, so return without a message
16017 end Reason_Bad_Component;
16019 -- Start of processing for Validate_Independence
16022 for J in Independence_Checks.First .. Independence_Checks.Last loop
16023 N := Independence_Checks.Table (J).N;
16024 E := Independence_Checks.Table (J).E;
16025 IC := Pragma_Name (N) = Name_Independent_Components;
16027 -- Deal with component case
16029 if Ekind (E) = E_Discriminant or else Ekind (E) = E_Component then
16030 if not OK_Component (E) then
16032 Reason_Bad_Component (E);
16037 -- Deal with record with Independent_Components
16039 if IC and then Is_Record_Type (E) then
16040 Comp := First_Component_Or_Discriminant (E);
16041 while Present (Comp) loop
16042 if not OK_Component (Comp) then
16044 Reason_Bad_Component (Comp);
16048 Next_Component_Or_Discriminant (Comp);
16052 -- Deal with address clause case
16054 if Is_Object (E) then
16055 Addr := Address_Clause (E);
16057 if Present (Addr) then
16059 Error_Msg_Sloc := Sloc (Addr);
16060 Error_Msg_N ("\because of Address clause#", N);
16065 -- Deal with independent components for array type
16067 if IC and then Is_Array_Type (E) then
16068 Check_Array_Type (E);
16071 -- Deal with independent components for array object
16073 if IC and then Is_Object (E) and then Is_Array_Type (Etype (E)) then
16074 Check_Array_Type (Etype (E));
16079 end Validate_Independence;
16081 ------------------------------
16082 -- Validate_Iterable_Aspect --
16083 ------------------------------
16085 procedure Validate_Iterable_Aspect (Typ : Entity_Id; ASN : Node_Id) is
16090 Cursor : constant Entity_Id := Get_Cursor_Type (ASN, Typ);
16092 First_Id : Entity_Id;
16093 Last_Id : Entity_Id;
16094 Next_Id : Entity_Id;
16095 Has_Element_Id : Entity_Id;
16096 Element_Id : Entity_Id;
16099 -- If previous error aspect is unusable
16101 if Cursor = Any_Type then
16108 Has_Element_Id := Empty;
16109 Element_Id := Empty;
16111 -- Each expression must resolve to a function with the proper signature
16113 Assoc := First (Component_Associations (Expression (ASN)));
16114 while Present (Assoc) loop
16115 Expr := Expression (Assoc);
16118 Prim := First (Choices (Assoc));
16120 if Nkind (Prim) /= N_Identifier or else Present (Next (Prim)) then
16121 Error_Msg_N ("illegal name in association", Prim);
16123 elsif Chars (Prim) = Name_First then
16124 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_First);
16125 First_Id := Entity (Expr);
16127 elsif Chars (Prim) = Name_Last then
16128 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Last);
16129 Last_Id := Entity (Expr);
16131 elsif Chars (Prim) = Name_Previous then
16132 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Previous);
16133 Last_Id := Entity (Expr);
16135 elsif Chars (Prim) = Name_Next then
16136 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Next);
16137 Next_Id := Entity (Expr);
16139 elsif Chars (Prim) = Name_Has_Element then
16140 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Has_Element);
16141 Has_Element_Id := Entity (Expr);
16143 elsif Chars (Prim) = Name_Element then
16144 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Element);
16145 Element_Id := Entity (Expr);
16148 Error_Msg_N ("invalid name for iterable function", Prim);
16154 if No (First_Id) then
16155 Error_Msg_N ("match for First primitive not found", ASN);
16157 elsif No (Next_Id) then
16158 Error_Msg_N ("match for Next primitive not found", ASN);
16160 elsif No (Has_Element_Id) then
16161 Error_Msg_N ("match for Has_Element primitive not found", ASN);
16163 elsif No (Element_Id) or else No (Last_Id) then
16166 end Validate_Iterable_Aspect;
16168 ------------------------------
16169 -- Validate_Literal_Aspect --
16170 ------------------------------
16172 procedure Validate_Literal_Aspect (Typ : Entity_Id; ASN : Node_Id) is
16173 A_Id : constant Aspect_Id := Get_Aspect_Id (ASN);
16174 pragma Assert ((A_Id = Aspect_Integer_Literal) or
16175 (A_Id = Aspect_Real_Literal) or
16176 (A_Id = Aspect_String_Literal));
16177 Func_Name : constant Node_Id := Expression (ASN);
16178 Overloaded : Boolean := Is_Overloaded (Func_Name);
16182 Param_Type : Entity_Id;
16183 Match_Found : Boolean := False;
16184 Match2_Found : Boolean := False;
16185 Is_Match : Boolean;
16187 Match2 : Entity_Id := Empty;
16190 (Param_Id : Entity_Id; Param_Type : Entity_Id) return Boolean;
16191 -- Return True if Param_Id is a non aliased in parameter whose base type
16199 (Param_Id : Entity_Id; Param_Type : Entity_Id) return Boolean is
16201 return Base_Type (Etype (Param_Id)) = Param_Type
16202 and then Ekind (Param_Id) = E_In_Parameter
16203 and then not Is_Aliased (Param_Id);
16207 if not Is_Type (Typ) then
16208 Error_Msg_N ("aspect can only be specified for a type", ASN);
16211 elsif not Is_First_Subtype (Typ) then
16212 Error_Msg_N ("aspect cannot be specified for a subtype", ASN);
16216 if A_Id = Aspect_String_Literal then
16217 if Is_String_Type (Typ) then
16218 Error_Msg_N ("aspect cannot be specified for a string type", ASN);
16222 Param_Type := Standard_Wide_Wide_String;
16225 if Is_Numeric_Type (Typ) then
16226 Error_Msg_N ("aspect cannot be specified for a numeric type", ASN);
16230 Param_Type := Standard_String;
16233 if not Overloaded and then not Present (Entity (Func_Name)) then
16234 Analyze (Func_Name);
16235 Overloaded := Is_Overloaded (Func_Name);
16239 Get_First_Interp (Func_Name, I => I, It => It);
16241 -- only one possible interpretation
16242 It.Nam := Entity (Func_Name);
16243 pragma Assert (Present (It.Nam));
16246 while It.Nam /= Empty loop
16249 if Ekind (It.Nam) = E_Function
16250 and then Base_Type (Etype (It.Nam)) = Base_Type (Typ)
16253 Params : constant List_Id :=
16254 Parameter_Specifications (Parent (It.Nam));
16255 Param_Spec : Node_Id;
16258 if List_Length (Params) = 1 then
16259 Param_Spec := First (Params);
16261 Matching (Defining_Identifier (Param_Spec), Param_Type);
16263 -- Look for the optional overloaded 2-param Real_Literal
16265 elsif List_Length (Params) = 2
16266 and then A_Id = Aspect_Real_Literal
16268 Param_Spec := First (Params);
16270 if Matching (Defining_Identifier (Param_Spec), Param_Type)
16272 Param_Spec := Next (Param_Spec);
16274 if Matching (Defining_Identifier (Param_Spec), Param_Type)
16276 if No (Match2) then
16278 Match2_Found := True;
16280 -- If we find more than one possible match then
16281 -- do not take any into account here: since the
16282 -- 2-parameter version of Real_Literal is optional
16283 -- we cannot generate an error here, so let
16284 -- standard resolution fail later if we do need to
16285 -- call this variant.
16287 Match2_Found := False;
16296 if Match_Found then
16297 Error_Msg_N ("aspect specification is ambiguous", ASN);
16301 Match_Found := True;
16305 exit when not Overloaded;
16307 if not Is_Match then
16308 Remove_Interp (I => I);
16311 Get_Next_Interp (I => I, It => It);
16314 if not Match_Found then
16316 ("function name in aspect specification cannot be resolved", ASN);
16320 Set_Entity (Func_Name, Match.Nam);
16321 Set_Etype (Func_Name, Etype (Match.Nam));
16322 Set_Is_Overloaded (Func_Name, False);
16324 -- Record the match for 2-parameter function if found
16326 if Match2_Found then
16327 Set_Related_Expression (Match.Nam, Match2);
16329 end Validate_Literal_Aspect;
16331 -----------------------------------
16332 -- Validate_Unchecked_Conversion --
16333 -----------------------------------
16335 procedure Validate_Unchecked_Conversion
16337 Act_Unit : Entity_Id)
16339 Source : Entity_Id;
16340 Target : Entity_Id;
16344 -- Obtain source and target types. Note that we call Ancestor_Subtype
16345 -- here because the processing for generic instantiation always makes
16346 -- subtypes, and we want the original frozen actual types.
16348 -- If we are dealing with private types, then do the check on their
16349 -- fully declared counterparts if the full declarations have been
16350 -- encountered (they don't have to be visible, but they must exist).
16352 Source := Ancestor_Subtype (Etype (First_Formal (Act_Unit)));
16354 if Is_Private_Type (Source)
16355 and then Present (Underlying_Type (Source))
16357 Source := Underlying_Type (Source);
16360 Target := Ancestor_Subtype (Etype (Act_Unit));
16362 -- If either type is generic, the instantiation happens within a generic
16363 -- unit, and there is nothing to check. The proper check will happen
16364 -- when the enclosing generic is instantiated.
16366 if Is_Generic_Type (Source) or else Is_Generic_Type (Target) then
16370 if Is_Private_Type (Target)
16371 and then Present (Underlying_Type (Target))
16373 Target := Underlying_Type (Target);
16376 -- Source may be unconstrained array, but not target, except in relaxed
16379 if Is_Array_Type (Target)
16380 and then not Is_Constrained (Target)
16381 and then not Relaxed_RM_Semantics
16384 ("unchecked conversion to unconstrained array not allowed", N);
16388 -- Warn if conversion between two different convention pointers
16390 if Is_Access_Type (Target)
16391 and then Is_Access_Type (Source)
16392 and then Convention (Target) /= Convention (Source)
16393 and then Warn_On_Unchecked_Conversion
16395 -- Give warnings for subprogram pointers only on most targets
16397 if Is_Access_Subprogram_Type (Target)
16398 or else Is_Access_Subprogram_Type (Source)
16401 ("?z?conversion between pointers with different conventions!",
16406 -- Warn if one of the operands is Ada.Calendar.Time. Do not emit a
16407 -- warning when compiling GNAT-related sources.
16409 if Warn_On_Unchecked_Conversion
16410 and then not In_Predefined_Unit (N)
16411 and then RTU_Loaded (Ada_Calendar)
16412 and then (Chars (Source) = Name_Time
16414 Chars (Target) = Name_Time)
16416 -- If Ada.Calendar is loaded and the name of one of the operands is
16417 -- Time, there is a good chance that this is Ada.Calendar.Time.
16420 Calendar_Time : constant Entity_Id := Full_View (RTE (RO_CA_Time));
16422 pragma Assert (Present (Calendar_Time));
16424 if Source = Calendar_Time or else Target = Calendar_Time then
16426 ("?z?representation of 'Time values may change between "
16427 & "'G'N'A'T versions", N);
16432 -- Make entry in unchecked conversion table for later processing by
16433 -- Validate_Unchecked_Conversions, which will check sizes and alignments
16434 -- (using values set by the back end where possible). This is only done
16435 -- if the appropriate warning is active.
16437 if Warn_On_Unchecked_Conversion then
16438 Unchecked_Conversions.Append
16439 (New_Val => UC_Entry'(Eloc => Sloc (N),
16442 Act_Unit => Act_Unit));
16444 -- If both sizes are known statically now, then back-end annotation
16445 -- is not required to do a proper check but if either size is not
16446 -- known statically, then we need the annotation.
16448 if Known_Static_RM_Size (Source)
16450 Known_Static_RM_Size (Target)
16454 Back_Annotate_Rep_Info := True;
16458 -- If unchecked conversion to access type, and access type is declared
16459 -- in the same unit as the unchecked conversion, then set the flag
16460 -- No_Strict_Aliasing (no strict aliasing is implicit here)
16462 if Is_Access_Type (Target) and then
16463 In_Same_Source_Unit (Target, N)
16465 Set_No_Strict_Aliasing (Implementation_Base_Type (Target));
16468 -- Generate N_Validate_Unchecked_Conversion node for back end in case
16469 -- the back end needs to perform special validation checks.
16471 -- Shouldn't this be in Exp_Ch13, since the check only gets done if we
16472 -- have full expansion and the back end is called ???
16475 Make_Validate_Unchecked_Conversion (Sloc (N));
16476 Set_Source_Type (Vnode, Source);
16477 Set_Target_Type (Vnode, Target);
16479 -- If the unchecked conversion node is in a list, just insert before it.
16480 -- If not we have some strange case, not worth bothering about.
16482 if Is_List_Member (N) then
16483 Insert_After (N, Vnode);
16485 end Validate_Unchecked_Conversion;
16487 ------------------------------------
16488 -- Validate_Unchecked_Conversions --
16489 ------------------------------------
16491 procedure Validate_Unchecked_Conversions is
16492 function Is_Null_Array (T : Entity_Id) return Boolean;
16493 -- We want to warn in the case of converting to a wrong-sized array of
16494 -- bytes, including the zero-size case. This returns True in that case,
16495 -- which is necessary because a size of 0 is used to indicate both an
16496 -- unknown size and a size of 0. It's OK for this to return True in
16497 -- other zero-size cases, but we don't go out of our way; for example,
16498 -- we don't bother with multidimensional arrays.
16500 function Is_Null_Array (T : Entity_Id) return Boolean is
16502 if Is_Array_Type (T) and then Is_Constrained (T) then
16504 Index : constant Node_Id := First_Index (T);
16505 R : Node_Id; -- N_Range
16507 case Nkind (Index) is
16510 when N_Subtype_Indication =>
16511 R := Range_Expression (Constraint (Index));
16512 when N_Identifier | N_Expanded_Name =>
16513 R := Scalar_Range (Entity (Index));
16515 raise Program_Error;
16518 return Is_Null_Range (Low_Bound (R), High_Bound (R));
16526 for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop
16528 T : UC_Entry renames Unchecked_Conversions.Table (N);
16530 Act_Unit : constant Entity_Id := T.Act_Unit;
16531 Eloc : constant Source_Ptr := T.Eloc;
16532 Source : constant Entity_Id := T.Source;
16533 Target : constant Entity_Id := T.Target;
16539 -- Skip if function marked as warnings off
16541 if Warnings_Off (Act_Unit) or else Serious_Errors_Detected > 0 then
16545 -- Don't do the check if warnings off for either type, note the
16546 -- deliberate use of OR here instead of OR ELSE to get the flag
16547 -- Warnings_Off_Used set for both types if appropriate.
16549 if Has_Warnings_Off (Source) or Has_Warnings_Off (Target) then
16553 if (Known_Static_RM_Size (Source)
16554 and then Known_Static_RM_Size (Target))
16555 or else Is_Null_Array (Target)
16557 -- This validation check, which warns if we have unequal sizes
16558 -- for unchecked conversion, and thus implementation dependent
16559 -- semantics, is one of the few occasions on which we use the
16560 -- official RM size instead of Esize. See description in Einfo
16561 -- "Handling of Type'Size Values" for details.
16563 Source_Siz := RM_Size (Source);
16564 Target_Siz := RM_Size (Target);
16566 if Source_Siz /= Target_Siz then
16568 ("?z?types for unchecked conversion have different sizes!",
16571 if All_Errors_Mode then
16572 Error_Msg_Name_1 := Chars (Source);
16573 Error_Msg_Uint_1 := Source_Siz;
16574 Error_Msg_Name_2 := Chars (Target);
16575 Error_Msg_Uint_2 := Target_Siz;
16576 Error_Msg ("\size of % is ^, size of % is ^?z?", Eloc);
16578 Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz);
16580 if Is_Discrete_Type (Source)
16582 Is_Discrete_Type (Target)
16584 if Source_Siz > Target_Siz then
16586 ("\?z?^ high order bits of source will "
16587 & "be ignored!", Eloc);
16589 elsif Is_Unsigned_Type (Source) then
16591 ("\?z?source will be extended with ^ high order "
16592 & "zero bits!", Eloc);
16596 ("\?z?source will be extended with ^ high order "
16597 & "sign bits!", Eloc);
16600 elsif Source_Siz < Target_Siz then
16601 if Is_Discrete_Type (Target) then
16602 if Bytes_Big_Endian then
16604 ("\?z?target value will include ^ undefined "
16605 & "low order bits!", Eloc, Act_Unit);
16608 ("\?z?target value will include ^ undefined "
16609 & "high order bits!", Eloc, Act_Unit);
16614 ("\?z?^ trailing bits of target value will be "
16615 & "undefined!", Eloc, Act_Unit);
16618 else pragma Assert (Source_Siz > Target_Siz);
16619 if Is_Discrete_Type (Source) then
16620 if Bytes_Big_Endian then
16622 ("\?z?^ low order bits of source will be "
16623 & "ignored!", Eloc, Act_Unit);
16626 ("\?z?^ high order bits of source will be "
16627 & "ignored!", Eloc, Act_Unit);
16632 ("\?z?^ trailing bits of source will be "
16633 & "ignored!", Eloc, Act_Unit);
16640 -- If both types are access types, we need to check the alignment.
16641 -- If the alignment of both is specified, we can do it here.
16643 if Serious_Errors_Detected = 0
16644 and then Is_Access_Type (Source)
16645 and then Is_Access_Type (Target)
16646 and then Target_Strict_Alignment
16647 and then Present (Designated_Type (Source))
16648 and then Present (Designated_Type (Target))
16651 D_Source : constant Entity_Id := Designated_Type (Source);
16652 D_Target : constant Entity_Id := Designated_Type (Target);
16655 if Known_Alignment (D_Source)
16657 Known_Alignment (D_Target)
16660 Source_Align : constant Uint := Alignment (D_Source);
16661 Target_Align : constant Uint := Alignment (D_Target);
16664 if Source_Align < Target_Align
16665 and then not Is_Tagged_Type (D_Source)
16667 -- Suppress warning if warnings suppressed on either
16668 -- type or either designated type. Note the use of
16669 -- OR here instead of OR ELSE. That is intentional,
16670 -- we would like to set flag Warnings_Off_Used in
16671 -- all types for which warnings are suppressed.
16673 and then not (Has_Warnings_Off (D_Source)
16675 Has_Warnings_Off (D_Target)
16677 Has_Warnings_Off (Source)
16679 Has_Warnings_Off (Target))
16681 Error_Msg_Uint_1 := Target_Align;
16682 Error_Msg_Uint_2 := Source_Align;
16683 Error_Msg_Node_1 := D_Target;
16684 Error_Msg_Node_2 := D_Source;
16686 ("?z?alignment of & (^) is stricter than "
16687 & "alignment of & (^)!", Eloc, Act_Unit);
16689 ("\?z?resulting access value may have invalid "
16690 & "alignment!", Eloc, Act_Unit);
16701 end Validate_Unchecked_Conversions;