1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2017, 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 Expander; use Expander;
34 with Exp_Disp; use Exp_Disp;
35 with Exp_Tss; use Exp_Tss;
36 with Exp_Util; use Exp_Util;
37 with Freeze; use Freeze;
38 with Ghost; use Ghost;
40 with Lib.Xref; use Lib.Xref;
41 with Namet; use Namet;
42 with Nlists; use Nlists;
43 with Nmake; use Nmake;
45 with Par_SCO; use Par_SCO;
46 with Restrict; use Restrict;
47 with Rident; use Rident;
48 with Rtsfind; use Rtsfind;
50 with Sem_Aux; use Sem_Aux;
51 with Sem_Case; use Sem_Case;
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 procedure Build_Discrete_Static_Predicate
99 -- Given a predicated type Typ, where Typ is a discrete static subtype,
100 -- whose predicate expression is Expr, tests if Expr is a static predicate,
101 -- and if so, builds the predicate range list. Nam is the name of the one
102 -- argument to the predicate function. Occurrences of the type name in the
103 -- predicate expression have been replaced by identifier references to this
104 -- name, which is unique, so any identifier with Chars matching Nam must be
105 -- a reference to the type. If the predicate is non-static, this procedure
106 -- returns doing nothing. If the predicate is static, then the predicate
107 -- list is stored in Static_Discrete_Predicate (Typ), and the Expr is
108 -- rewritten as a canonicalized membership operation.
110 function Build_Export_Import_Pragma
112 Id : Entity_Id) return Node_Id;
113 -- Create the corresponding pragma for aspect Export or Import denoted by
114 -- Asp. Id is the related entity subject to the aspect. Return Empty when
115 -- the expression of aspect Asp evaluates to False or is erroneous.
117 function Build_Predicate_Function_Declaration
118 (Typ : Entity_Id) return Node_Id;
119 -- Build the declaration for a predicate function. The declaration is built
120 -- at the end of the declarative part containing the type definition, which
121 -- may be before the freeze point of the type. The predicate expression is
122 -- pre-analyzed at this point, to catch visibility errors.
124 procedure Build_Predicate_Functions (Typ : Entity_Id; N : Node_Id);
125 -- If Typ has predicates (indicated by Has_Predicates being set for Typ),
126 -- then either there are pragma Predicate entries on the rep chain for the
127 -- type (note that Predicate aspects are converted to pragma Predicate), or
128 -- there are inherited aspects from a parent type, or ancestor subtypes.
129 -- This procedure builds body for the Predicate function that tests these
130 -- predicates. N is the freeze node for the type. The spec of the function
131 -- is inserted before the freeze node, and the body of the function is
132 -- inserted after the freeze node. If the predicate expression has a least
133 -- one Raise_Expression, then this procedure also builds the M version of
134 -- the predicate function for use in membership tests.
136 procedure Check_Pool_Size_Clash (Ent : Entity_Id; SP, SS : Node_Id);
137 -- Called if both Storage_Pool and Storage_Size attribute definition
138 -- clauses (SP and SS) are present for entity Ent. Issue error message.
140 procedure Freeze_Entity_Checks (N : Node_Id);
141 -- Called from Analyze_Freeze_Entity and Analyze_Generic_Freeze Entity
142 -- to generate appropriate semantic checks that are delayed until this
143 -- point (they had to be delayed this long for cases of delayed aspects,
144 -- e.g. analysis of statically predicated subtypes in choices, for which
145 -- we have to be sure the subtypes in question are frozen before checking).
147 function Get_Alignment_Value (Expr : Node_Id) return Uint;
148 -- Given the expression for an alignment value, returns the corresponding
149 -- Uint value. If the value is inappropriate, then error messages are
150 -- posted as required, and a value of No_Uint is returned.
152 function Is_Operational_Item (N : Node_Id) return Boolean;
153 -- A specification for a stream attribute is allowed before the full type
154 -- is declared, as explained in AI-00137 and the corrigendum. Attributes
155 -- that do not specify a representation characteristic are operational
158 function Is_Predicate_Static
160 Nam : Name_Id) return Boolean;
161 -- Given predicate expression Expr, tests if Expr is predicate-static in
162 -- the sense of the rules in (RM 3.2.4 (15-24)). Occurrences of the type
163 -- name in the predicate expression have been replaced by references to
164 -- an identifier whose Chars field is Nam. This name is unique, so any
165 -- identifier with Chars matching Nam must be a reference to the type.
166 -- Returns True if the expression is predicate-static and False otherwise,
167 -- but is not in the business of setting flags or issuing error messages.
169 -- Only scalar types can have static predicates, so False is always
170 -- returned for non-scalar types.
172 -- Note: the RM seems to suggest that string types can also have static
173 -- predicates. But that really makes lttle sense as very few useful
174 -- predicates can be constructed for strings. Remember that:
178 -- is not a static expression. So even though the clearly faulty RM wording
179 -- allows the following:
181 -- subtype S is String with Static_Predicate => S < "DEF"
183 -- We can't allow this, otherwise we have predicate-static applying to a
184 -- larger class than static expressions, which was never intended.
186 procedure New_Stream_Subprogram
190 Nam : TSS_Name_Type);
191 -- Create a subprogram renaming of a given stream attribute to the
192 -- designated subprogram and then in the tagged case, provide this as a
193 -- primitive operation, or in the untagged case make an appropriate TSS
194 -- entry. This is more properly an expansion activity than just semantics,
195 -- but the presence of user-defined stream functions for limited types
196 -- is a legality check, which is why this takes place here rather than in
197 -- exp_ch13, where it was previously. Nam indicates the name of the TSS
198 -- function to be generated.
200 -- To avoid elaboration anomalies with freeze nodes, for untagged types
201 -- we generate both a subprogram declaration and a subprogram renaming
202 -- declaration, so that the attribute specification is handled as a
203 -- renaming_as_body. For tagged types, the specification is one of the
206 procedure Resolve_Iterable_Operation
211 -- If the name of a primitive operation for an Iterable aspect is
212 -- overloaded, resolve according to required signature.
218 Biased : Boolean := True);
219 -- If Biased is True, sets Has_Biased_Representation flag for E, and
220 -- outputs a warning message at node N if Warn_On_Biased_Representation is
221 -- is True. This warning inserts the string Msg to describe the construct
224 ---------------------------------------------------
225 -- Table for Validate_Compile_Time_Warning_Error --
226 ---------------------------------------------------
228 -- The following table collects pragmas Compile_Time_Error and Compile_
229 -- Time_Warning for validation. Entries are made by calls to subprogram
230 -- Validate_Compile_Time_Warning_Error, and the call to the procedure
231 -- Validate_Compile_Time_Warning_Errors does the actual error checking
232 -- and posting of warning and error messages. The reason for this delayed
233 -- processing is to take advantage of back-annotations of attributes size
234 -- and alignment values performed by the back end.
236 -- Note: the reason we store a Source_Ptr value instead of a Node_Id is
237 -- that by the time Validate_Unchecked_Conversions is called, Sprint will
238 -- already have modified all Sloc values if the -gnatD option is set.
240 type CTWE_Entry is record
242 -- Source location used in warnings and error messages
245 -- Pragma Compile_Time_Error or Compile_Time_Warning
248 -- The scope which encloses the pragma
251 package Compile_Time_Warnings_Errors is new Table.Table (
252 Table_Component_Type => CTWE_Entry,
253 Table_Index_Type => Int,
254 Table_Low_Bound => 1,
256 Table_Increment => 200,
257 Table_Name => "Compile_Time_Warnings_Errors");
259 ----------------------------------------------
260 -- Table for Validate_Unchecked_Conversions --
261 ----------------------------------------------
263 -- The following table collects unchecked conversions for validation.
264 -- Entries are made by Validate_Unchecked_Conversion and then the call
265 -- to Validate_Unchecked_Conversions does the actual error checking and
266 -- posting of warnings. The reason for this delayed processing is to take
267 -- advantage of back-annotations of size and alignment values performed by
270 -- Note: the reason we store a Source_Ptr value instead of a Node_Id is
271 -- that by the time Validate_Unchecked_Conversions is called, Sprint will
272 -- already have modified all Sloc values if the -gnatD option is set.
274 type UC_Entry is record
275 Eloc : Source_Ptr; -- node used for posting warnings
276 Source : Entity_Id; -- source type for unchecked conversion
277 Target : Entity_Id; -- target type for unchecked conversion
278 Act_Unit : Entity_Id; -- actual function instantiated
281 package Unchecked_Conversions is new Table.Table (
282 Table_Component_Type => UC_Entry,
283 Table_Index_Type => Int,
284 Table_Low_Bound => 1,
286 Table_Increment => 200,
287 Table_Name => "Unchecked_Conversions");
289 ----------------------------------------
290 -- Table for Validate_Address_Clauses --
291 ----------------------------------------
293 -- If an address clause has the form
295 -- for X'Address use Expr
297 -- where Expr has a value known at compile time or is of the form Y'Address
298 -- or recursively is a reference to a constant initialized with either of
299 -- these forms, and the value of Expr is not a multiple of X's alignment,
300 -- or if Y has a smaller alignment than X, then that merits a warning about
301 -- possible bad alignment. The following table collects address clauses of
302 -- this kind. We put these in a table so that they can be checked after the
303 -- back end has completed annotation of the alignments of objects, since we
304 -- can catch more cases that way.
306 type Address_Clause_Check_Record is record
308 -- The address clause
311 -- The entity of the object subject to the address clause
314 -- The value of the address in the first case
317 -- The entity of the object being overlaid in the second case
320 -- Whether the address is offset within Y in the second case
323 package Address_Clause_Checks is new Table.Table (
324 Table_Component_Type => Address_Clause_Check_Record,
325 Table_Index_Type => Int,
326 Table_Low_Bound => 1,
328 Table_Increment => 200,
329 Table_Name => "Address_Clause_Checks");
331 -----------------------------------------
332 -- Adjust_Record_For_Reverse_Bit_Order --
333 -----------------------------------------
335 procedure Adjust_Record_For_Reverse_Bit_Order (R : Entity_Id) is
336 Max_Machine_Scalar_Size : constant Uint :=
338 (Standard_Long_Long_Integer_Size);
339 -- We use this as the maximum machine scalar size
341 SSU : constant Uint := UI_From_Int (System_Storage_Unit);
348 -- Processing here used to depend on Ada version: the behavior was
349 -- changed by AI95-0133. However this AI is a Binding interpretation,
350 -- so we now implement it even in Ada 95 mode. The original behavior
351 -- from unamended Ada 95 is still available for compatibility under
352 -- debugging switch -gnatd.
354 if Ada_Version < Ada_2005 and then Debug_Flag_Dot_P then
355 Adjust_Record_For_Reverse_Bit_Order_Ada_95 (R);
359 -- For Ada 2005, we do machine scalar processing, as fully described In
360 -- AI-133. This involves gathering all components which start at the
361 -- same byte offset and processing them together. Same approach is still
362 -- valid in later versions including Ada 2012.
364 -- This first loop through components does two things. First it deals
365 -- with the case of components with component clauses whose length is
366 -- greater than the maximum machine scalar size (either accepting them
367 -- or rejecting as needed). Second, it counts the number of components
368 -- with component clauses whose length does not exceed this maximum for
372 Comp := First_Component_Or_Discriminant (R);
373 while Present (Comp) loop
374 CC := Component_Clause (Comp);
378 Fbit : constant Uint := Static_Integer (First_Bit (CC));
379 Lbit : constant Uint := Static_Integer (Last_Bit (CC));
382 -- Case of component with last bit >= max machine scalar
384 if Lbit >= Max_Machine_Scalar_Size then
386 -- This is allowed only if first bit is zero, and last bit
387 -- + 1 is a multiple of storage unit size.
389 if Fbit = 0 and then (Lbit + 1) mod SSU = 0 then
391 -- This is the case to give a warning if enabled
393 if Warn_On_Reverse_Bit_Order then
395 ("info: multi-byte field specified with "
396 & "non-standard Bit_Order?V?", CC);
398 if Bytes_Big_Endian then
400 ("\bytes are not reversed "
401 & "(component is big-endian)?V?", CC);
404 ("\bytes are not reversed "
405 & "(component is little-endian)?V?", CC);
409 -- Give error message for RM 13.5.1(10) violation
413 ("machine scalar rules not followed for&",
414 First_Bit (CC), Comp);
416 Error_Msg_Uint_1 := Lbit + 1;
417 Error_Msg_Uint_2 := Max_Machine_Scalar_Size;
419 ("\last bit + 1 (^) exceeds maximum machine scalar "
420 & "size (^)", First_Bit (CC));
422 if (Lbit + 1) mod SSU /= 0 then
423 Error_Msg_Uint_1 := SSU;
425 ("\and is not a multiple of Storage_Unit (^) "
426 & "(RM 13.5.1(10))", First_Bit (CC));
429 Error_Msg_Uint_1 := Fbit;
431 ("\and first bit (^) is non-zero "
432 & "(RM 13.4.1(10))", First_Bit (CC));
436 -- OK case of machine scalar related component clause. For now,
440 Num_CC := Num_CC + 1;
445 Next_Component_Or_Discriminant (Comp);
448 -- We need to sort the component clauses on the basis of the Position
449 -- values in the clause, so we can group clauses with the same Position
450 -- together to determine the relevant machine scalar size.
453 Comps : array (0 .. Num_CC) of Entity_Id;
454 -- Array to collect component and discriminant entities. The data
455 -- starts at index 1, the 0'th entry is for the sort routine.
457 function CP_Lt (Op1, Op2 : Natural) return Boolean;
458 -- Compare routine for Sort
460 procedure CP_Move (From : Natural; To : Natural);
461 -- Move routine for Sort
463 package Sorting is new GNAT.Heap_Sort_G (CP_Move, CP_Lt);
466 -- Maximum last bit value of any component in this set
469 -- Corresponding machine scalar size
473 -- Start and stop positions in the component list of the set of
474 -- components with the same starting position (that constitute
475 -- components in a single machine scalar).
481 function CP_Lt (Op1, Op2 : Natural) return Boolean is
484 Position (Component_Clause (Comps (Op1))) <
485 Position (Component_Clause (Comps (Op2)));
492 procedure CP_Move (From : Natural; To : Natural) is
494 Comps (To) := Comps (From);
497 -- Start of processing for Sort_CC
500 -- Collect the machine scalar relevant component clauses
503 Comp := First_Component_Or_Discriminant (R);
504 while Present (Comp) loop
506 CC : constant Node_Id := Component_Clause (Comp);
509 -- Collect only component clauses whose last bit is less than
510 -- machine scalar size. Any component clause whose last bit
511 -- exceeds this value does not take part in machine scalar
512 -- layout considerations. The test for Error_Posted makes sure
513 -- we exclude component clauses for which we already posted an
517 and then not Error_Posted (Last_Bit (CC))
518 and then Static_Integer (Last_Bit (CC)) <
519 Max_Machine_Scalar_Size
521 Num_CC := Num_CC + 1;
522 Comps (Num_CC) := Comp;
526 Next_Component_Or_Discriminant (Comp);
529 -- Sort by ascending position number
531 Sorting.Sort (Num_CC);
533 -- We now have all the components whose size does not exceed the max
534 -- machine scalar value, sorted by starting position. In this loop we
535 -- gather groups of clauses starting at the same position, to process
536 -- them in accordance with AI-133.
539 while Stop < Num_CC loop
544 (Last_Bit (Component_Clause (Comps (Start))));
545 while Stop < Num_CC loop
547 (Position (Component_Clause (Comps (Stop + 1)))) =
549 (Position (Component_Clause (Comps (Stop))))
557 (Component_Clause (Comps (Stop)))));
563 -- Now we have a group of component clauses from Start to Stop
564 -- whose positions are identical, and MaxL is the maximum last
565 -- bit value of any of these components.
567 -- We need to determine the corresponding machine scalar size.
568 -- This loop assumes that machine scalar sizes are even, and that
569 -- each possible machine scalar has twice as many bits as the next
572 MSS := Max_Machine_Scalar_Size;
574 and then (MSS / 2) >= SSU
575 and then (MSS / 2) > MaxL
580 -- Here is where we fix up the Component_Bit_Offset value to
581 -- account for the reverse bit order. Some examples of what needs
582 -- to be done for the case of a machine scalar size of 8 are:
584 -- First_Bit .. Last_Bit Component_Bit_Offset
596 -- The rule is that the first bit is obtained by subtracting the
597 -- old ending bit from machine scalar size - 1.
599 for C in Start .. Stop loop
601 Comp : constant Entity_Id := Comps (C);
602 CC : constant Node_Id := Component_Clause (Comp);
604 LB : constant Uint := Static_Integer (Last_Bit (CC));
605 NFB : constant Uint := MSS - Uint_1 - LB;
606 NLB : constant Uint := NFB + Esize (Comp) - 1;
607 Pos : constant Uint := Static_Integer (Position (CC));
610 if Warn_On_Reverse_Bit_Order then
611 Error_Msg_Uint_1 := MSS;
613 ("info: reverse bit order in machine scalar of "
614 & "length^?V?", First_Bit (CC));
615 Error_Msg_Uint_1 := NFB;
616 Error_Msg_Uint_2 := NLB;
618 if Bytes_Big_Endian then
620 ("\big-endian range for component & is ^ .. ^?V?",
621 First_Bit (CC), Comp);
624 ("\little-endian range for component & is ^ .. ^?V?",
625 First_Bit (CC), Comp);
629 Set_Component_Bit_Offset (Comp, Pos * SSU + NFB);
630 Set_Normalized_First_Bit (Comp, NFB mod SSU);
635 end Adjust_Record_For_Reverse_Bit_Order;
637 ------------------------------------------------
638 -- Adjust_Record_For_Reverse_Bit_Order_Ada_95 --
639 ------------------------------------------------
641 procedure Adjust_Record_For_Reverse_Bit_Order_Ada_95 (R : Entity_Id) is
646 -- For Ada 95, we just renumber bits within a storage unit. We do the
647 -- same for Ada 83 mode, since we recognize the Bit_Order attribute in
648 -- Ada 83, and are free to add this extension.
650 Comp := First_Component_Or_Discriminant (R);
651 while Present (Comp) loop
652 CC := Component_Clause (Comp);
654 -- If component clause is present, then deal with the non-default
655 -- bit order case for Ada 95 mode.
657 -- We only do this processing for the base type, and in fact that
658 -- is important, since otherwise if there are record subtypes, we
659 -- could reverse the bits once for each subtype, which is wrong.
661 if Present (CC) and then Ekind (R) = E_Record_Type then
663 CFB : constant Uint := Component_Bit_Offset (Comp);
664 CSZ : constant Uint := Esize (Comp);
665 CLC : constant Node_Id := Component_Clause (Comp);
666 Pos : constant Node_Id := Position (CLC);
667 FB : constant Node_Id := First_Bit (CLC);
669 Storage_Unit_Offset : constant Uint :=
670 CFB / System_Storage_Unit;
672 Start_Bit : constant Uint :=
673 CFB mod System_Storage_Unit;
676 -- Cases where field goes over storage unit boundary
678 if Start_Bit + CSZ > System_Storage_Unit then
680 -- Allow multi-byte field but generate warning
682 if Start_Bit mod System_Storage_Unit = 0
683 and then CSZ mod System_Storage_Unit = 0
686 ("info: multi-byte field specified with non-standard "
687 & "Bit_Order?V?", CLC);
689 if Bytes_Big_Endian then
691 ("\bytes are not reversed "
692 & "(component is big-endian)?V?", CLC);
695 ("\bytes are not reversed "
696 & "(component is little-endian)?V?", CLC);
699 -- Do not allow non-contiguous field
703 ("attempt to specify non-contiguous field not "
706 ("\caused by non-standard Bit_Order specified in "
707 & "legacy Ada 95 mode", CLC);
710 -- Case where field fits in one storage unit
713 -- Give warning if suspicious component clause
715 if Intval (FB) >= System_Storage_Unit
716 and then Warn_On_Reverse_Bit_Order
719 ("info: Bit_Order clause does not affect byte "
720 & "ordering?V?", Pos);
722 Intval (Pos) + Intval (FB) /
725 ("info: position normalized to ^ before bit order "
726 & "interpreted?V?", Pos);
729 -- Here is where we fix up the Component_Bit_Offset value
730 -- to account for the reverse bit order. Some examples of
731 -- what needs to be done are:
733 -- First_Bit .. Last_Bit Component_Bit_Offset
745 -- The rule is that the first bit is is obtained by
746 -- subtracting the old ending bit from storage_unit - 1.
748 Set_Component_Bit_Offset (Comp,
749 (Storage_Unit_Offset * System_Storage_Unit) +
750 (System_Storage_Unit - 1) -
751 (Start_Bit + CSZ - 1));
753 Set_Normalized_First_Bit (Comp,
754 Component_Bit_Offset (Comp) mod System_Storage_Unit);
759 Next_Component_Or_Discriminant (Comp);
761 end Adjust_Record_For_Reverse_Bit_Order_Ada_95;
763 -------------------------------------
764 -- Alignment_Check_For_Size_Change --
765 -------------------------------------
767 procedure Alignment_Check_For_Size_Change (Typ : Entity_Id; Size : Uint) is
769 -- If the alignment is known, and not set by a rep clause, and is
770 -- inconsistent with the size being set, then reset it to unknown,
771 -- we assume in this case that the size overrides the inherited
772 -- alignment, and that the alignment must be recomputed.
774 if Known_Alignment (Typ)
775 and then not Has_Alignment_Clause (Typ)
776 and then Size mod (Alignment (Typ) * SSU) /= 0
778 Init_Alignment (Typ);
780 end Alignment_Check_For_Size_Change;
782 -------------------------------------
783 -- Analyze_Aspects_At_Freeze_Point --
784 -------------------------------------
786 procedure Analyze_Aspects_At_Freeze_Point (E : Entity_Id) is
787 procedure Analyze_Aspect_Default_Value (ASN : Node_Id);
788 -- This routine analyzes an Aspect_Default_[Component_]Value denoted by
789 -- the aspect specification node ASN.
791 procedure Inherit_Delayed_Rep_Aspects (ASN : Node_Id);
792 -- As discussed in the spec of Aspects (see Aspect_Delay declaration),
793 -- a derived type can inherit aspects from its parent which have been
794 -- specified at the time of the derivation using an aspect, as in:
796 -- type A is range 1 .. 10
797 -- with Size => Not_Defined_Yet;
801 -- Not_Defined_Yet : constant := 64;
803 -- In this example, the Size of A is considered to be specified prior
804 -- to the derivation, and thus inherited, even though the value is not
805 -- known at the time of derivation. To deal with this, we use two entity
806 -- flags. The flag Has_Derived_Rep_Aspects is set in the parent type (A
807 -- here), and then the flag May_Inherit_Delayed_Rep_Aspects is set in
808 -- the derived type (B here). If this flag is set when the derived type
809 -- is frozen, then this procedure is called to ensure proper inheritance
810 -- of all delayed aspects from the parent type. The derived type is E,
811 -- the argument to Analyze_Aspects_At_Freeze_Point. ASN is the first
812 -- aspect specification node in the Rep_Item chain for the parent type.
814 procedure Make_Pragma_From_Boolean_Aspect (ASN : Node_Id);
815 -- Given an aspect specification node ASN whose expression is an
816 -- optional Boolean, this routines creates the corresponding pragma
817 -- at the freezing point.
819 ----------------------------------
820 -- Analyze_Aspect_Default_Value --
821 ----------------------------------
823 procedure Analyze_Aspect_Default_Value (ASN : Node_Id) is
824 A_Id : constant Aspect_Id := Get_Aspect_Id (ASN);
825 Ent : constant Entity_Id := Entity (ASN);
826 Expr : constant Node_Id := Expression (ASN);
827 Id : constant Node_Id := Identifier (ASN);
830 Error_Msg_Name_1 := Chars (Id);
832 if not Is_Type (Ent) then
833 Error_Msg_N ("aspect% can only apply to a type", Id);
836 elsif not Is_First_Subtype (Ent) then
837 Error_Msg_N ("aspect% cannot apply to subtype", Id);
840 elsif A_Id = Aspect_Default_Value
841 and then not Is_Scalar_Type (Ent)
843 Error_Msg_N ("aspect% can only be applied to scalar type", Id);
846 elsif A_Id = Aspect_Default_Component_Value then
847 if not Is_Array_Type (Ent) then
848 Error_Msg_N ("aspect% can only be applied to array type", Id);
851 elsif not Is_Scalar_Type (Component_Type (Ent)) then
852 Error_Msg_N ("aspect% requires scalar components", Id);
857 Set_Has_Default_Aspect (Base_Type (Ent));
859 if Is_Scalar_Type (Ent) then
860 Set_Default_Aspect_Value (Base_Type (Ent), Expr);
862 Set_Default_Aspect_Component_Value (Base_Type (Ent), Expr);
864 end Analyze_Aspect_Default_Value;
866 ---------------------------------
867 -- Inherit_Delayed_Rep_Aspects --
868 ---------------------------------
870 procedure Inherit_Delayed_Rep_Aspects (ASN : Node_Id) is
871 A_Id : constant Aspect_Id := Get_Aspect_Id (ASN);
872 P : constant Entity_Id := Entity (ASN);
873 -- Entithy for parent type
876 -- Item from Rep_Item chain
881 -- Loop through delayed aspects for the parent type
884 while Present (N) loop
885 if Nkind (N) = N_Aspect_Specification then
886 exit when Entity (N) /= P;
888 if Is_Delayed_Aspect (N) then
889 A := Get_Aspect_Id (Chars (Identifier (N)));
891 -- Process delayed rep aspect. For Boolean attributes it is
892 -- not possible to cancel an attribute once set (the attempt
893 -- to use an aspect with xxx => False is an error) for a
894 -- derived type. So for those cases, we do not have to check
895 -- if a clause has been given for the derived type, since it
896 -- is harmless to set it again if it is already set.
902 when Aspect_Alignment =>
903 if not Has_Alignment_Clause (E) then
904 Set_Alignment (E, Alignment (P));
909 when Aspect_Atomic =>
910 if Is_Atomic (P) then
916 when Aspect_Atomic_Components =>
917 if Has_Atomic_Components (P) then
918 Set_Has_Atomic_Components (Base_Type (E));
923 when Aspect_Bit_Order =>
924 if Is_Record_Type (E)
925 and then No (Get_Attribute_Definition_Clause
926 (E, Attribute_Bit_Order))
927 and then Reverse_Bit_Order (P)
929 Set_Reverse_Bit_Order (Base_Type (E));
934 when Aspect_Component_Size =>
936 and then not Has_Component_Size_Clause (E)
939 (Base_Type (E), Component_Size (P));
944 when Aspect_Machine_Radix =>
945 if Is_Decimal_Fixed_Point_Type (E)
946 and then not Has_Machine_Radix_Clause (E)
948 Set_Machine_Radix_10 (E, Machine_Radix_10 (P));
951 -- Object_Size (also Size which also sets Object_Size)
953 when Aspect_Object_Size
956 if not Has_Size_Clause (E)
958 No (Get_Attribute_Definition_Clause
959 (E, Attribute_Object_Size))
961 Set_Esize (E, Esize (P));
967 if not Is_Packed (E) then
968 Set_Is_Packed (Base_Type (E));
970 if Is_Bit_Packed_Array (P) then
971 Set_Is_Bit_Packed_Array (Base_Type (E));
972 Set_Packed_Array_Impl_Type
973 (E, Packed_Array_Impl_Type (P));
977 -- Scalar_Storage_Order
979 when Aspect_Scalar_Storage_Order =>
980 if (Is_Record_Type (E) or else Is_Array_Type (E))
981 and then No (Get_Attribute_Definition_Clause
982 (E, Attribute_Scalar_Storage_Order))
983 and then Reverse_Storage_Order (P)
985 Set_Reverse_Storage_Order (Base_Type (E));
987 -- Clear default SSO indications, since the aspect
988 -- overrides the default.
990 Set_SSO_Set_Low_By_Default (Base_Type (E), False);
991 Set_SSO_Set_High_By_Default (Base_Type (E), False);
997 if Is_Fixed_Point_Type (E)
998 and then not Has_Small_Clause (E)
1000 Set_Small_Value (E, Small_Value (P));
1005 when Aspect_Storage_Size =>
1006 if (Is_Access_Type (E) or else Is_Task_Type (E))
1007 and then not Has_Storage_Size_Clause (E)
1009 Set_Storage_Size_Variable
1010 (Base_Type (E), Storage_Size_Variable (P));
1015 when Aspect_Value_Size =>
1017 -- Value_Size is never inherited, it is either set by
1018 -- default, or it is explicitly set for the derived
1019 -- type. So nothing to do here.
1025 when Aspect_Volatile =>
1026 if Is_Volatile (P) then
1027 Set_Is_Volatile (E);
1030 -- Volatile_Full_Access
1032 when Aspect_Volatile_Full_Access =>
1033 if Is_Volatile_Full_Access (P) then
1034 Set_Is_Volatile_Full_Access (E);
1037 -- Volatile_Components
1039 when Aspect_Volatile_Components =>
1040 if Has_Volatile_Components (P) then
1041 Set_Has_Volatile_Components (Base_Type (E));
1044 -- That should be all the Rep Aspects
1047 pragma Assert (Aspect_Delay (A_Id) /= Rep_Aspect);
1053 N := Next_Rep_Item (N);
1055 end Inherit_Delayed_Rep_Aspects;
1057 -------------------------------------
1058 -- Make_Pragma_From_Boolean_Aspect --
1059 -------------------------------------
1061 procedure Make_Pragma_From_Boolean_Aspect (ASN : Node_Id) is
1062 Ident : constant Node_Id := Identifier (ASN);
1063 A_Name : constant Name_Id := Chars (Ident);
1064 A_Id : constant Aspect_Id := Get_Aspect_Id (A_Name);
1065 Ent : constant Entity_Id := Entity (ASN);
1066 Expr : constant Node_Id := Expression (ASN);
1067 Loc : constant Source_Ptr := Sloc (ASN);
1069 procedure Check_False_Aspect_For_Derived_Type;
1070 -- This procedure checks for the case of a false aspect for a derived
1071 -- type, which improperly tries to cancel an aspect inherited from
1074 -----------------------------------------
1075 -- Check_False_Aspect_For_Derived_Type --
1076 -----------------------------------------
1078 procedure Check_False_Aspect_For_Derived_Type is
1082 -- We are only checking derived types
1084 if not Is_Derived_Type (E) then
1088 Par := Nearest_Ancestor (E);
1094 if not Is_Atomic (Par) then
1098 when Aspect_Atomic_Components =>
1099 if not Has_Atomic_Components (Par) then
1103 when Aspect_Discard_Names =>
1104 if not Discard_Names (Par) then
1109 if not Is_Packed (Par) then
1113 when Aspect_Unchecked_Union =>
1114 if not Is_Unchecked_Union (Par) then
1118 when Aspect_Volatile =>
1119 if not Is_Volatile (Par) then
1123 when Aspect_Volatile_Components =>
1124 if not Has_Volatile_Components (Par) then
1128 when Aspect_Volatile_Full_Access =>
1129 if not Is_Volatile_Full_Access (Par) then
1137 -- Fall through means we are canceling an inherited aspect
1139 Error_Msg_Name_1 := A_Name;
1141 ("derived type& inherits aspect%, cannot cancel", Expr, E);
1142 end Check_False_Aspect_For_Derived_Type;
1148 -- Start of processing for Make_Pragma_From_Boolean_Aspect
1151 -- Note that we know Expr is present, because for a missing Expr
1152 -- argument, we knew it was True and did not need to delay the
1153 -- evaluation to the freeze point.
1155 if Is_False (Static_Boolean (Expr)) then
1156 Check_False_Aspect_For_Derived_Type;
1161 Pragma_Identifier =>
1162 Make_Identifier (Sloc (Ident), Chars (Ident)),
1163 Pragma_Argument_Associations => New_List (
1164 Make_Pragma_Argument_Association (Sloc (Ident),
1165 Expression => New_Occurrence_Of (Ent, Sloc (Ident)))));
1167 Set_From_Aspect_Specification (Prag, True);
1168 Set_Corresponding_Aspect (Prag, ASN);
1169 Set_Aspect_Rep_Item (ASN, Prag);
1170 Set_Is_Delayed_Aspect (Prag);
1171 Set_Parent (Prag, ASN);
1173 end Make_Pragma_From_Boolean_Aspect;
1181 -- Start of processing for Analyze_Aspects_At_Freeze_Point
1184 -- Must be visible in current scope, but if this is a type from a nested
1185 -- package it may be frozen from an object declaration in the enclosing
1186 -- scope, so install the package declarations to complete the analysis
1187 -- of the aspects, if any. If the package itself is frozen the type will
1188 -- have been frozen as well.
1190 if not Scope_Within_Or_Same (Current_Scope, Scope (E)) then
1191 if Is_Type (E) and then From_Nested_Package (E) then
1193 Pack : constant Entity_Id := Scope (E);
1197 Install_Visible_Declarations (Pack);
1198 Install_Private_Declarations (Pack);
1199 Analyze_Aspects_At_Freeze_Point (E);
1201 if Is_Private_Type (E)
1202 and then Present (Full_View (E))
1204 Analyze_Aspects_At_Freeze_Point (Full_View (E));
1207 End_Package_Scope (Pack);
1211 -- Aspects from other entities in different contexts are analyzed
1219 -- Look for aspect specification entries for this entity
1221 ASN := First_Rep_Item (E);
1222 while Present (ASN) loop
1223 if Nkind (ASN) = N_Aspect_Specification then
1224 exit when Entity (ASN) /= E;
1226 if Is_Delayed_Aspect (ASN) then
1227 A_Id := Get_Aspect_Id (ASN);
1231 -- For aspects whose expression is an optional Boolean, make
1232 -- the corresponding pragma at the freeze point.
1234 when Boolean_Aspects
1235 | Library_Unit_Aspects
1237 -- Aspects Export and Import require special handling.
1238 -- Both are by definition Boolean and may benefit from
1239 -- forward references, however their expressions are
1240 -- treated as static. In addition, the syntax of their
1241 -- corresponding pragmas requires extra "pieces" which
1242 -- may also contain forward references. To account for
1243 -- all of this, the corresponding pragma is created by
1244 -- Analyze_Aspect_Export_Import, but is not analyzed as
1245 -- the complete analysis must happen now.
1247 if A_Id = Aspect_Export or else A_Id = Aspect_Import then
1250 -- Otherwise create a corresponding pragma
1253 Make_Pragma_From_Boolean_Aspect (ASN);
1256 -- Special handling for aspects that don't correspond to
1257 -- pragmas/attributes.
1259 when Aspect_Default_Value
1260 | Aspect_Default_Component_Value
1262 -- Do not inherit aspect for anonymous base type of a
1263 -- scalar or array type, because they apply to the first
1264 -- subtype of the type, and will be processed when that
1265 -- first subtype is frozen.
1267 if Is_Derived_Type (E)
1268 and then not Comes_From_Source (E)
1269 and then E /= First_Subtype (E)
1273 Analyze_Aspect_Default_Value (ASN);
1276 -- Ditto for iterator aspects, because the corresponding
1277 -- attributes may not have been analyzed yet.
1279 when Aspect_Constant_Indexing
1280 | Aspect_Default_Iterator
1281 | Aspect_Iterator_Element
1282 | Aspect_Variable_Indexing
1284 Analyze (Expression (ASN));
1286 if Etype (Expression (ASN)) = Any_Type then
1288 ("\aspect must be fully defined before & is frozen",
1292 when Aspect_Iterable =>
1293 Validate_Iterable_Aspect (E, ASN);
1299 Ritem := Aspect_Rep_Item (ASN);
1301 if Present (Ritem) then
1307 Next_Rep_Item (ASN);
1310 -- This is where we inherit delayed rep aspects from our parent. Note
1311 -- that if we fell out of the above loop with ASN non-empty, it means
1312 -- we hit an aspect for an entity other than E, and it must be the
1313 -- type from which we were derived.
1315 if May_Inherit_Delayed_Rep_Aspects (E) then
1316 Inherit_Delayed_Rep_Aspects (ASN);
1318 end Analyze_Aspects_At_Freeze_Point;
1320 -----------------------------------
1321 -- Analyze_Aspect_Specifications --
1322 -----------------------------------
1324 procedure Analyze_Aspect_Specifications (N : Node_Id; E : Entity_Id) is
1325 procedure Decorate (Asp : Node_Id; Prag : Node_Id);
1326 -- Establish linkages between an aspect and its corresponding pragma
1328 procedure Insert_Pragma
1330 Is_Instance : Boolean := False);
1331 -- Subsidiary to the analysis of aspects
1338 -- Initial_Condition
1347 -- Insert pragma Prag such that it mimics the placement of a source
1348 -- pragma of the same kind. Flag Is_Generic should be set when the
1349 -- context denotes a generic instance.
1355 procedure Decorate (Asp : Node_Id; Prag : Node_Id) is
1357 Set_Aspect_Rep_Item (Asp, Prag);
1358 Set_Corresponding_Aspect (Prag, Asp);
1359 Set_From_Aspect_Specification (Prag);
1360 Set_Parent (Prag, Asp);
1367 procedure Insert_Pragma
1369 Is_Instance : Boolean := False)
1375 Inserted : Boolean := False;
1378 -- When the aspect appears on an entry, package, protected unit,
1379 -- subprogram, or task unit body, insert the generated pragma at the
1380 -- top of the body declarations to emulate the behavior of a source
1383 -- package body Pack with Aspect is
1385 -- package body Pack is
1388 if Nkind_In (N, N_Entry_Body,
1394 Decls := Declarations (N);
1398 Set_Declarations (N, Decls);
1401 Prepend_To (Decls, Prag);
1403 -- When the aspect is associated with a [generic] package declaration
1404 -- insert the generated pragma at the top of the visible declarations
1405 -- to emulate the behavior of a source pragma.
1407 -- package Pack with Aspect is
1412 elsif Nkind_In (N, N_Generic_Package_Declaration,
1413 N_Package_Declaration)
1415 Decls := Visible_Declarations (Specification (N));
1419 Set_Visible_Declarations (Specification (N), Decls);
1422 -- The visible declarations of a generic instance have the
1423 -- following structure:
1425 -- <renamings of generic formals>
1426 -- <renamings of internally-generated spec and body>
1427 -- <first source declaration>
1429 -- Insert the pragma before the first source declaration by
1430 -- skipping the instance "header" to ensure proper visibility of
1434 Decl := First (Decls);
1435 while Present (Decl) loop
1436 if Comes_From_Source (Decl) then
1437 Insert_Before (Decl, Prag);
1445 -- The pragma is placed after the instance "header"
1447 if not Inserted then
1448 Append_To (Decls, Prag);
1451 -- Otherwise this is not a generic instance
1454 Prepend_To (Decls, Prag);
1457 -- When the aspect is associated with a protected unit declaration,
1458 -- insert the generated pragma at the top of the visible declarations
1459 -- the emulate the behavior of a source pragma.
1461 -- protected [type] Prot with Aspect is
1463 -- protected [type] Prot is
1466 elsif Nkind (N) = N_Protected_Type_Declaration then
1467 Def := Protected_Definition (N);
1471 Make_Protected_Definition (Sloc (N),
1472 Visible_Declarations => New_List,
1473 End_Label => Empty);
1475 Set_Protected_Definition (N, Def);
1478 Decls := Visible_Declarations (Def);
1482 Set_Visible_Declarations (Def, Decls);
1485 Prepend_To (Decls, Prag);
1487 -- When the aspect is associated with a task unit declaration, insert
1488 -- insert the generated pragma at the top of the visible declarations
1489 -- the emulate the behavior of a source pragma.
1491 -- task [type] Prot with Aspect is
1493 -- task [type] Prot is
1496 elsif Nkind (N) = N_Task_Type_Declaration then
1497 Def := Task_Definition (N);
1501 Make_Task_Definition (Sloc (N),
1502 Visible_Declarations => New_List,
1503 End_Label => Empty);
1505 Set_Task_Definition (N, Def);
1508 Decls := Visible_Declarations (Def);
1512 Set_Visible_Declarations (Def, Decls);
1515 Prepend_To (Decls, Prag);
1517 -- When the context is a library unit, the pragma is added to the
1518 -- Pragmas_After list.
1520 elsif Nkind (Parent (N)) = N_Compilation_Unit then
1521 Aux := Aux_Decls_Node (Parent (N));
1523 if No (Pragmas_After (Aux)) then
1524 Set_Pragmas_After (Aux, New_List);
1527 Prepend (Prag, Pragmas_After (Aux));
1529 -- Default, the pragma is inserted after the context
1532 Insert_After (N, Prag);
1542 L : constant List_Id := Aspect_Specifications (N);
1544 Ins_Node : Node_Id := N;
1545 -- Insert pragmas/attribute definition clause after this node when no
1546 -- delayed analysis is required.
1548 -- Start of processing for Analyze_Aspect_Specifications
1551 -- The general processing involves building an attribute definition
1552 -- clause or a pragma node that corresponds to the aspect. Then in order
1553 -- to delay the evaluation of this aspect to the freeze point, we attach
1554 -- the corresponding pragma/attribute definition clause to the aspect
1555 -- specification node, which is then placed in the Rep Item chain. In
1556 -- this case we mark the entity by setting the flag Has_Delayed_Aspects
1557 -- and we evaluate the rep item at the freeze point. When the aspect
1558 -- doesn't have a corresponding pragma/attribute definition clause, then
1559 -- its analysis is simply delayed at the freeze point.
1561 -- Some special cases don't require delay analysis, thus the aspect is
1562 -- analyzed right now.
1564 -- Note that there is a special handling for Pre, Post, Test_Case,
1565 -- Contract_Cases aspects. In these cases, we do not have to worry
1566 -- about delay issues, since the pragmas themselves deal with delay
1567 -- of visibility for the expression analysis. Thus, we just insert
1568 -- the pragma after the node N.
1570 pragma Assert (Present (L));
1572 -- Loop through aspects
1574 Aspect := First (L);
1575 Aspect_Loop : while Present (Aspect) loop
1576 Analyze_One_Aspect : declare
1577 Expr : constant Node_Id := Expression (Aspect);
1578 Id : constant Node_Id := Identifier (Aspect);
1579 Loc : constant Source_Ptr := Sloc (Aspect);
1580 Nam : constant Name_Id := Chars (Id);
1581 A_Id : constant Aspect_Id := Get_Aspect_Id (Nam);
1584 Delay_Required : Boolean;
1585 -- Set False if delay is not required
1587 Eloc : Source_Ptr := No_Location;
1588 -- Source location of expression, modified when we split PPC's. It
1589 -- is set below when Expr is present.
1591 procedure Analyze_Aspect_Convention;
1592 -- Perform analysis of aspect Convention
1594 procedure Analyze_Aspect_Export_Import;
1595 -- Perform analysis of aspects Export or Import
1597 procedure Analyze_Aspect_External_Link_Name;
1598 -- Perform analysis of aspects External_Name or Link_Name
1600 procedure Analyze_Aspect_Implicit_Dereference;
1601 -- Perform analysis of the Implicit_Dereference aspects
1603 procedure Make_Aitem_Pragma
1604 (Pragma_Argument_Associations : List_Id;
1605 Pragma_Name : Name_Id);
1606 -- This is a wrapper for Make_Pragma used for converting aspects
1607 -- to pragmas. It takes care of Sloc (set from Loc) and building
1608 -- the pragma identifier from the given name. In addition the
1609 -- flags Class_Present and Split_PPC are set from the aspect
1610 -- node, as well as Is_Ignored. This routine also sets the
1611 -- From_Aspect_Specification in the resulting pragma node to
1612 -- True, and sets Corresponding_Aspect to point to the aspect.
1613 -- The resulting pragma is assigned to Aitem.
1615 -------------------------------
1616 -- Analyze_Aspect_Convention --
1617 -------------------------------
1619 procedure Analyze_Aspect_Convention is
1628 -- Obtain all interfacing aspects that apply to the related
1631 Get_Interfacing_Aspects
1632 (Iface_Asp => Aspect,
1633 Conv_Asp => Dummy_1,
1640 -- The related entity is subject to aspect Export or Import.
1641 -- Do not process Convention now because it must be analysed
1642 -- as part of Export or Import.
1644 if Present (Expo) or else Present (Imp) then
1647 -- Otherwise Convention appears by itself
1650 -- The aspect specifies a particular convention
1652 if Present (Expr) then
1653 Conv := New_Copy_Tree (Expr);
1655 -- Otherwise assume convention Ada
1658 Conv := Make_Identifier (Loc, Name_Ada);
1662 -- pragma Convention (<Conv>, <E>);
1665 (Pragma_Name => Name_Convention,
1666 Pragma_Argument_Associations => New_List (
1667 Make_Pragma_Argument_Association (Loc,
1668 Expression => Conv),
1669 Make_Pragma_Argument_Association (Loc,
1670 Expression => New_Occurrence_Of (E, Loc))));
1672 Decorate (Aspect, Aitem);
1673 Insert_Pragma (Aitem);
1675 end Analyze_Aspect_Convention;
1677 ----------------------------------
1678 -- Analyze_Aspect_Export_Import --
1679 ----------------------------------
1681 procedure Analyze_Aspect_Export_Import is
1689 -- Obtain all interfacing aspects that apply to the related
1692 Get_Interfacing_Aspects
1693 (Iface_Asp => Aspect,
1694 Conv_Asp => Dummy_1,
1701 -- The related entity cannot be subject to both aspects Export
1704 if Present (Expo) and then Present (Imp) then
1706 ("incompatible interfacing aspects given for &", E);
1707 Error_Msg_Sloc := Sloc (Expo);
1708 Error_Msg_N ("\aspect `Export` #", E);
1709 Error_Msg_Sloc := Sloc (Imp);
1710 Error_Msg_N ("\aspect `Import` #", E);
1713 -- A variable is most likely modified from the outside. Take
1714 -- the optimistic approach to avoid spurious errors.
1716 if Ekind (E) = E_Variable then
1717 Set_Never_Set_In_Source (E, False);
1720 -- Resolve the expression of an Import or Export here, and
1721 -- require it to be of type Boolean and static. This is not
1722 -- quite right, because in general this should be delayed,
1723 -- but that seems tricky for these, because normally Boolean
1724 -- aspects are replaced with pragmas at the freeze point in
1725 -- Make_Pragma_From_Boolean_Aspect.
1727 if not Present (Expr)
1728 or else Is_True (Static_Boolean (Expr))
1730 if A_Id = Aspect_Import then
1731 Set_Has_Completion (E);
1732 Set_Is_Imported (E);
1734 -- An imported object cannot be explicitly initialized
1736 if Nkind (N) = N_Object_Declaration
1737 and then Present (Expression (N))
1740 ("imported entities cannot be initialized "
1741 & "(RM B.1(24))", Expression (N));
1745 pragma Assert (A_Id = Aspect_Export);
1746 Set_Is_Exported (E);
1749 -- Create the proper form of pragma Export or Import taking
1750 -- into account Conversion, External_Name, and Link_Name.
1752 Aitem := Build_Export_Import_Pragma (Aspect, E);
1754 -- Otherwise the expression is either False or erroneous. There
1755 -- is no corresponding pragma.
1760 end Analyze_Aspect_Export_Import;
1762 ---------------------------------------
1763 -- Analyze_Aspect_External_Link_Name --
1764 ---------------------------------------
1766 procedure Analyze_Aspect_External_Link_Name is
1774 -- Obtain all interfacing aspects that apply to the related
1777 Get_Interfacing_Aspects
1778 (Iface_Asp => Aspect,
1779 Conv_Asp => Dummy_1,
1786 -- Ensure that aspect External_Name applies to aspect Export or
1789 if A_Id = Aspect_External_Name then
1790 if No (Expo) and then No (Imp) then
1792 ("aspect `External_Name` requires aspect `Import` or "
1793 & "`Export`", Aspect);
1796 -- Otherwise ensure that aspect Link_Name applies to aspect
1797 -- Export or Import.
1800 pragma Assert (A_Id = Aspect_Link_Name);
1801 if No (Expo) and then No (Imp) then
1803 ("aspect `Link_Name` requires aspect `Import` or "
1804 & "`Export`", Aspect);
1807 end Analyze_Aspect_External_Link_Name;
1809 -----------------------------------------
1810 -- Analyze_Aspect_Implicit_Dereference --
1811 -----------------------------------------
1813 procedure Analyze_Aspect_Implicit_Dereference is
1815 Parent_Disc : Entity_Id;
1818 if not Is_Type (E) or else not Has_Discriminants (E) then
1820 ("aspect must apply to a type with discriminants", Expr);
1822 elsif not Is_Entity_Name (Expr) then
1824 ("aspect must name a discriminant of current type", Expr);
1827 -- Discriminant type be an anonymous access type or an
1828 -- anonymous access to subprogram.
1830 -- Missing synchronized types???
1832 Disc := First_Discriminant (E);
1833 while Present (Disc) loop
1834 if Chars (Expr) = Chars (Disc)
1835 and then Ekind_In (Etype (Disc),
1836 E_Anonymous_Access_Subprogram_Type,
1837 E_Anonymous_Access_Type)
1839 Set_Has_Implicit_Dereference (E);
1840 Set_Has_Implicit_Dereference (Disc);
1844 Next_Discriminant (Disc);
1847 -- Error if no proper access discriminant
1850 Error_Msg_NE ("not an access discriminant of&", Expr, E);
1855 -- For a type extension, check whether parent has a
1856 -- reference discriminant, to verify that use is proper.
1858 if Is_Derived_Type (E)
1859 and then Has_Discriminants (Etype (E))
1861 Parent_Disc := Get_Reference_Discriminant (Etype (E));
1863 if Present (Parent_Disc)
1864 and then Corresponding_Discriminant (Disc) /= Parent_Disc
1867 ("reference discriminant does not match discriminant "
1868 & "of parent type", Expr);
1871 end Analyze_Aspect_Implicit_Dereference;
1873 -----------------------
1874 -- Make_Aitem_Pragma --
1875 -----------------------
1877 procedure Make_Aitem_Pragma
1878 (Pragma_Argument_Associations : List_Id;
1879 Pragma_Name : Name_Id)
1881 Args : List_Id := Pragma_Argument_Associations;
1884 -- We should never get here if aspect was disabled
1886 pragma Assert (not Is_Disabled (Aspect));
1888 -- Certain aspects allow for an optional name or expression. Do
1889 -- not generate a pragma with empty argument association list.
1891 if No (Args) or else No (Expression (First (Args))) then
1899 Pragma_Argument_Associations => Args,
1900 Pragma_Identifier =>
1901 Make_Identifier (Sloc (Id), Pragma_Name),
1902 Class_Present => Class_Present (Aspect),
1903 Split_PPC => Split_PPC (Aspect));
1905 -- Set additional semantic fields
1907 if Is_Ignored (Aspect) then
1908 Set_Is_Ignored (Aitem);
1909 elsif Is_Checked (Aspect) then
1910 Set_Is_Checked (Aitem);
1913 Set_Corresponding_Aspect (Aitem, Aspect);
1914 Set_From_Aspect_Specification (Aitem);
1915 end Make_Aitem_Pragma;
1917 -- Start of processing for Analyze_One_Aspect
1920 -- Skip aspect if already analyzed, to avoid looping in some cases
1922 if Analyzed (Aspect) then
1926 -- Skip looking at aspect if it is totally disabled. Just mark it
1927 -- as such for later reference in the tree. This also sets the
1928 -- Is_Ignored and Is_Checked flags appropriately.
1930 Check_Applicable_Policy (Aspect);
1932 if Is_Disabled (Aspect) then
1936 -- Set the source location of expression, used in the case of
1937 -- a failed precondition/postcondition or invariant. Note that
1938 -- the source location of the expression is not usually the best
1939 -- choice here. For example, it gets located on the last AND
1940 -- keyword in a chain of boolean expressiond AND'ed together.
1941 -- It is best to put the message on the first character of the
1942 -- assertion, which is the effect of the First_Node call here.
1944 if Present (Expr) then
1945 Eloc := Sloc (First_Node (Expr));
1948 -- Check restriction No_Implementation_Aspect_Specifications
1950 if Implementation_Defined_Aspect (A_Id) then
1952 (No_Implementation_Aspect_Specifications, Aspect);
1955 -- Check restriction No_Specification_Of_Aspect
1957 Check_Restriction_No_Specification_Of_Aspect (Aspect);
1959 -- Mark aspect analyzed (actual analysis is delayed till later)
1961 Set_Analyzed (Aspect);
1962 Set_Entity (Aspect, E);
1964 -- Build the reference to E that will be used in the built pragmas
1966 Ent := New_Occurrence_Of (E, Sloc (Id));
1968 if A_Id = Aspect_Attach_Handler
1969 or else A_Id = Aspect_Interrupt_Handler
1971 -- Decorate the reference as comming from the sources and force
1972 -- its reanalysis to generate the reference to E; required to
1973 -- avoid reporting spurious warning on E as unreferenced entity
1974 -- (because aspects are not fully analyzed).
1976 Set_Comes_From_Source (Ent, Comes_From_Source (Id));
1977 Set_Entity (Ent, Empty);
1982 -- Check for duplicate aspect. Note that the Comes_From_Source
1983 -- test allows duplicate Pre/Post's that we generate internally
1984 -- to escape being flagged here.
1986 if No_Duplicates_Allowed (A_Id) then
1988 while Anod /= Aspect loop
1989 if Comes_From_Source (Aspect)
1990 and then Same_Aspect (A_Id, Get_Aspect_Id (Anod))
1992 Error_Msg_Name_1 := Nam;
1993 Error_Msg_Sloc := Sloc (Anod);
1995 -- Case of same aspect specified twice
1997 if Class_Present (Anod) = Class_Present (Aspect) then
1998 if not Class_Present (Anod) then
2000 ("aspect% for & previously given#",
2004 ("aspect `%''Class` for & previously given#",
2014 -- Check some general restrictions on language defined aspects
2016 if not Implementation_Defined_Aspect (A_Id) then
2017 Error_Msg_Name_1 := Nam;
2019 -- Not allowed for renaming declarations. Examine the original
2020 -- node because a subprogram renaming may have been rewritten
2023 if Nkind (Original_Node (N)) in N_Renaming_Declaration then
2025 ("aspect % not allowed for renaming declaration",
2029 -- Not allowed for formal type declarations
2031 if Nkind (N) = N_Formal_Type_Declaration then
2033 ("aspect % not allowed for formal type declaration",
2038 -- Copy expression for later processing by the procedures
2039 -- Check_Aspect_At_[Freeze_Point | End_Of_Declarations]
2041 Set_Entity (Id, New_Copy_Tree (Expr));
2043 -- Set Delay_Required as appropriate to aspect
2045 case Aspect_Delay (A_Id) is
2046 when Always_Delay =>
2047 Delay_Required := True;
2050 Delay_Required := False;
2054 -- If expression has the form of an integer literal, then
2055 -- do not delay, since we know the value cannot change.
2056 -- This optimization catches most rep clause cases.
2058 -- For Boolean aspects, don't delay if no expression
2060 if A_Id in Boolean_Aspects and then No (Expr) then
2061 Delay_Required := False;
2063 -- For non-Boolean aspects, don't delay if integer literal,
2064 -- unless the aspect is Alignment, which affects the
2065 -- freezing of an initialized object.
2067 elsif A_Id not in Boolean_Aspects
2068 and then A_Id /= Aspect_Alignment
2069 and then Present (Expr)
2070 and then Nkind (Expr) = N_Integer_Literal
2072 Delay_Required := False;
2074 -- All other cases are delayed
2077 Delay_Required := True;
2078 Set_Has_Delayed_Rep_Aspects (E);
2082 -- Processing based on specific aspect
2085 when Aspect_Unimplemented =>
2086 null; -- ??? temp for now
2088 -- No_Aspect should be impossible
2091 raise Program_Error;
2093 -- Case 1: Aspects corresponding to attribute definition
2099 | Aspect_Component_Size
2100 | Aspect_Constant_Indexing
2101 | Aspect_Default_Iterator
2102 | Aspect_Dispatching_Domain
2103 | Aspect_External_Tag
2106 | Aspect_Iterator_Element
2107 | Aspect_Machine_Radix
2108 | Aspect_Object_Size
2111 | Aspect_Scalar_Storage_Order
2112 | Aspect_Secondary_Stack_Size
2113 | Aspect_Simple_Storage_Pool
2116 | Aspect_Storage_Pool
2117 | Aspect_Stream_Size
2119 | Aspect_Variable_Indexing
2122 -- Indexing aspects apply only to tagged type
2124 if (A_Id = Aspect_Constant_Indexing
2126 A_Id = Aspect_Variable_Indexing)
2127 and then not (Is_Type (E)
2128 and then Is_Tagged_Type (E))
2131 ("indexing aspect can only apply to a tagged type",
2136 -- For the case of aspect Address, we don't consider that we
2137 -- know the entity is never set in the source, since it is
2138 -- is likely aliasing is occurring.
2140 -- Note: one might think that the analysis of the resulting
2141 -- attribute definition clause would take care of that, but
2142 -- that's not the case since it won't be from source.
2144 if A_Id = Aspect_Address then
2145 Set_Never_Set_In_Source (E, False);
2148 -- Correctness of the profile of a stream operation is
2149 -- verified at the freeze point, but we must detect the
2150 -- illegal specification of this aspect for a subtype now,
2151 -- to prevent malformed rep_item chains.
2153 if A_Id = Aspect_Input or else
2154 A_Id = Aspect_Output or else
2155 A_Id = Aspect_Read or else
2158 if not Is_First_Subtype (E) then
2160 ("local name must be a first subtype", Aspect);
2163 -- If stream aspect applies to the class-wide type,
2164 -- the generated attribute definition applies to the
2165 -- class-wide type as well.
2167 elsif Class_Present (Aspect) then
2169 Make_Attribute_Reference (Loc,
2171 Attribute_Name => Name_Class);
2175 -- Construct the attribute definition clause
2178 Make_Attribute_Definition_Clause (Loc,
2180 Chars => Chars (Id),
2181 Expression => Relocate_Node (Expr));
2183 -- If the address is specified, then we treat the entity as
2184 -- referenced, to avoid spurious warnings. This is analogous
2185 -- to what is done with an attribute definition clause, but
2186 -- here we don't want to generate a reference because this
2187 -- is the point of definition of the entity.
2189 if A_Id = Aspect_Address then
2193 -- Case 2: Aspects corresponding to pragmas
2195 -- Case 2a: Aspects corresponding to pragmas with two
2196 -- arguments, where the first argument is a local name
2197 -- referring to the entity, and the second argument is the
2198 -- aspect definition expression.
2200 -- Linker_Section/Suppress/Unsuppress
2202 when Aspect_Linker_Section
2207 (Pragma_Argument_Associations => New_List (
2208 Make_Pragma_Argument_Association (Loc,
2209 Expression => New_Occurrence_Of (E, Loc)),
2210 Make_Pragma_Argument_Association (Sloc (Expr),
2211 Expression => Relocate_Node (Expr))),
2212 Pragma_Name => Chars (Id));
2216 -- Corresponds to pragma Implemented, construct the pragma
2218 when Aspect_Synchronization =>
2220 (Pragma_Argument_Associations => New_List (
2221 Make_Pragma_Argument_Association (Loc,
2222 Expression => New_Occurrence_Of (E, Loc)),
2223 Make_Pragma_Argument_Association (Sloc (Expr),
2224 Expression => Relocate_Node (Expr))),
2225 Pragma_Name => Name_Implemented);
2229 when Aspect_Attach_Handler =>
2231 (Pragma_Argument_Associations => New_List (
2232 Make_Pragma_Argument_Association (Sloc (Ent),
2234 Make_Pragma_Argument_Association (Sloc (Expr),
2235 Expression => Relocate_Node (Expr))),
2236 Pragma_Name => Name_Attach_Handler);
2238 -- We need to insert this pragma into the tree to get proper
2239 -- processing and to look valid from a placement viewpoint.
2241 Insert_Pragma (Aitem);
2244 -- Dynamic_Predicate, Predicate, Static_Predicate
2246 when Aspect_Dynamic_Predicate
2248 | Aspect_Static_Predicate
2250 -- These aspects apply only to subtypes
2252 if not Is_Type (E) then
2254 ("predicate can only be specified for a subtype",
2258 elsif Is_Incomplete_Type (E) then
2260 ("predicate cannot apply to incomplete view", Aspect);
2264 -- Construct the pragma (always a pragma Predicate, with
2265 -- flags recording whether it is static/dynamic). We also
2266 -- set flags recording this in the type itself.
2269 (Pragma_Argument_Associations => New_List (
2270 Make_Pragma_Argument_Association (Sloc (Ent),
2272 Make_Pragma_Argument_Association (Sloc (Expr),
2273 Expression => Relocate_Node (Expr))),
2274 Pragma_Name => Name_Predicate);
2276 -- Mark type has predicates, and remember what kind of
2277 -- aspect lead to this predicate (we need this to access
2278 -- the right set of check policies later on).
2280 Set_Has_Predicates (E);
2282 if A_Id = Aspect_Dynamic_Predicate then
2283 Set_Has_Dynamic_Predicate_Aspect (E);
2285 -- If the entity has a dynamic predicate, any inherited
2286 -- static predicate becomes dynamic as well, and the
2287 -- predicate function includes the conjunction of both.
2289 Set_Has_Static_Predicate_Aspect (E, False);
2291 elsif A_Id = Aspect_Static_Predicate then
2292 Set_Has_Static_Predicate_Aspect (E);
2295 -- If the type is private, indicate that its completion
2296 -- has a freeze node, because that is the one that will
2297 -- be visible at freeze time.
2299 if Is_Private_Type (E) and then Present (Full_View (E)) then
2300 Set_Has_Predicates (Full_View (E));
2302 if A_Id = Aspect_Dynamic_Predicate then
2303 Set_Has_Dynamic_Predicate_Aspect (Full_View (E));
2304 elsif A_Id = Aspect_Static_Predicate then
2305 Set_Has_Static_Predicate_Aspect (Full_View (E));
2308 Set_Has_Delayed_Aspects (Full_View (E));
2309 Ensure_Freeze_Node (Full_View (E));
2312 -- Predicate_Failure
2314 when Aspect_Predicate_Failure =>
2316 -- This aspect applies only to subtypes
2318 if not Is_Type (E) then
2320 ("predicate can only be specified for a subtype",
2324 elsif Is_Incomplete_Type (E) then
2326 ("predicate cannot apply to incomplete view", Aspect);
2330 -- Construct the pragma
2333 (Pragma_Argument_Associations => New_List (
2334 Make_Pragma_Argument_Association (Sloc (Ent),
2336 Make_Pragma_Argument_Association (Sloc (Expr),
2337 Expression => Relocate_Node (Expr))),
2338 Pragma_Name => Name_Predicate_Failure);
2340 Set_Has_Predicates (E);
2342 -- If the type is private, indicate that its completion
2343 -- has a freeze node, because that is the one that will
2344 -- be visible at freeze time.
2346 if Is_Private_Type (E) and then Present (Full_View (E)) then
2347 Set_Has_Predicates (Full_View (E));
2348 Set_Has_Delayed_Aspects (Full_View (E));
2349 Ensure_Freeze_Node (Full_View (E));
2352 -- Case 2b: Aspects corresponding to pragmas with two
2353 -- arguments, where the second argument is a local name
2354 -- referring to the entity, and the first argument is the
2355 -- aspect definition expression.
2359 when Aspect_Convention =>
2360 Analyze_Aspect_Convention;
2363 -- External_Name, Link_Name
2365 when Aspect_External_Name
2368 Analyze_Aspect_External_Link_Name;
2371 -- CPU, Interrupt_Priority, Priority
2373 -- These three aspects can be specified for a subprogram spec
2374 -- or body, in which case we analyze the expression and export
2375 -- the value of the aspect.
2377 -- Previously, we generated an equivalent pragma for bodies
2378 -- (note that the specs cannot contain these pragmas). The
2379 -- pragma was inserted ahead of local declarations, rather than
2380 -- after the body. This leads to a certain duplication between
2381 -- the processing performed for the aspect and the pragma, but
2382 -- given the straightforward handling required it is simpler
2383 -- to duplicate than to translate the aspect in the spec into
2384 -- a pragma in the declarative part of the body.
2387 | Aspect_Interrupt_Priority
2390 if Nkind_In (N, N_Subprogram_Body,
2391 N_Subprogram_Declaration)
2393 -- Analyze the aspect expression
2395 Analyze_And_Resolve (Expr, Standard_Integer);
2397 -- Interrupt_Priority aspect not allowed for main
2398 -- subprograms. RM D.1 does not forbid this explicitly,
2399 -- but RM J.15.11(6/3) does not permit pragma
2400 -- Interrupt_Priority for subprograms.
2402 if A_Id = Aspect_Interrupt_Priority then
2404 ("Interrupt_Priority aspect cannot apply to "
2405 & "subprogram", Expr);
2407 -- The expression must be static
2409 elsif not Is_OK_Static_Expression (Expr) then
2410 Flag_Non_Static_Expr
2411 ("aspect requires static expression!", Expr);
2413 -- Check whether this is the main subprogram. Issue a
2414 -- warning only if it is obviously not a main program
2415 -- (when it has parameters or when the subprogram is
2416 -- within a package).
2418 elsif Present (Parameter_Specifications
2419 (Specification (N)))
2420 or else not Is_Compilation_Unit (Defining_Entity (N))
2422 -- See RM D.1(14/3) and D.16(12/3)
2425 ("aspect applied to subprogram other than the "
2426 & "main subprogram has no effect??", Expr);
2428 -- Otherwise check in range and export the value
2430 -- For the CPU aspect
2432 elsif A_Id = Aspect_CPU then
2433 if Is_In_Range (Expr, RTE (RE_CPU_Range)) then
2435 -- Value is correct so we export the value to make
2436 -- it available at execution time.
2439 (Main_Unit, UI_To_Int (Expr_Value (Expr)));
2443 ("main subprogram CPU is out of range", Expr);
2446 -- For the Priority aspect
2448 elsif A_Id = Aspect_Priority then
2449 if Is_In_Range (Expr, RTE (RE_Priority)) then
2451 -- Value is correct so we export the value to make
2452 -- it available at execution time.
2455 (Main_Unit, UI_To_Int (Expr_Value (Expr)));
2457 -- Ignore pragma if Relaxed_RM_Semantics to support
2458 -- other targets/non GNAT compilers.
2460 elsif not Relaxed_RM_Semantics then
2462 ("main subprogram priority is out of range",
2467 -- Load an arbitrary entity from System.Tasking.Stages
2468 -- or System.Tasking.Restricted.Stages (depending on
2469 -- the supported profile) to make sure that one of these
2470 -- packages is implicitly with'ed, since we need to have
2471 -- the tasking run time active for the pragma Priority to
2472 -- have any effect. Previously we with'ed the package
2473 -- System.Tasking, but this package does not trigger the
2474 -- required initialization of the run-time library.
2477 Discard : Entity_Id;
2479 if Restricted_Profile then
2480 Discard := RTE (RE_Activate_Restricted_Tasks);
2482 Discard := RTE (RE_Activate_Tasks);
2486 -- Handling for these aspects in subprograms is complete
2490 -- For task and protected types pass the aspect as an
2495 Make_Attribute_Definition_Clause (Loc,
2497 Chars => Chars (Id),
2498 Expression => Relocate_Node (Expr));
2503 when Aspect_Warnings =>
2505 (Pragma_Argument_Associations => New_List (
2506 Make_Pragma_Argument_Association (Sloc (Expr),
2507 Expression => Relocate_Node (Expr)),
2508 Make_Pragma_Argument_Association (Loc,
2509 Expression => New_Occurrence_Of (E, Loc))),
2510 Pragma_Name => Chars (Id));
2512 Decorate (Aspect, Aitem);
2513 Insert_Pragma (Aitem);
2516 -- Case 2c: Aspects corresponding to pragmas with three
2519 -- Invariant aspects have a first argument that references the
2520 -- entity, a second argument that is the expression and a third
2521 -- argument that is an appropriate message.
2523 -- Invariant, Type_Invariant
2525 when Aspect_Invariant
2526 | Aspect_Type_Invariant
2528 -- Analysis of the pragma will verify placement legality:
2529 -- an invariant must apply to a private type, or appear in
2530 -- the private part of a spec and apply to a completion.
2533 (Pragma_Argument_Associations => New_List (
2534 Make_Pragma_Argument_Association (Sloc (Ent),
2536 Make_Pragma_Argument_Association (Sloc (Expr),
2537 Expression => Relocate_Node (Expr))),
2538 Pragma_Name => Name_Invariant);
2540 -- Add message unless exception messages are suppressed
2542 if not Opt.Exception_Locations_Suppressed then
2543 Append_To (Pragma_Argument_Associations (Aitem),
2544 Make_Pragma_Argument_Association (Eloc,
2545 Chars => Name_Message,
2547 Make_String_Literal (Eloc,
2548 Strval => "failed invariant from "
2549 & Build_Location_String (Eloc))));
2552 -- For Invariant case, insert immediately after the entity
2553 -- declaration. We do not have to worry about delay issues
2554 -- since the pragma processing takes care of this.
2556 Delay_Required := False;
2558 -- Case 2d : Aspects that correspond to a pragma with one
2563 -- Aspect Abstract_State introduces implicit declarations for
2564 -- all state abstraction entities it defines. To emulate this
2565 -- behavior, insert the pragma at the beginning of the visible
2566 -- declarations of the related package so that it is analyzed
2569 when Aspect_Abstract_State => Abstract_State : declare
2570 Context : Node_Id := N;
2573 -- When aspect Abstract_State appears on a generic package,
2574 -- it is propageted to the package instance. The context in
2575 -- this case is the instance spec.
2577 if Nkind (Context) = N_Package_Instantiation then
2578 Context := Instance_Spec (Context);
2581 if Nkind_In (Context, N_Generic_Package_Declaration,
2582 N_Package_Declaration)
2585 (Pragma_Argument_Associations => New_List (
2586 Make_Pragma_Argument_Association (Loc,
2587 Expression => Relocate_Node (Expr))),
2588 Pragma_Name => Name_Abstract_State);
2590 Decorate (Aspect, Aitem);
2594 Is_Generic_Instance (Defining_Entity (Context)));
2598 ("aspect & must apply to a package declaration",
2605 -- Aspect Async_Readers is never delayed because it is
2606 -- equivalent to a source pragma which appears after the
2607 -- related object declaration.
2609 when Aspect_Async_Readers =>
2611 (Pragma_Argument_Associations => New_List (
2612 Make_Pragma_Argument_Association (Loc,
2613 Expression => Relocate_Node (Expr))),
2614 Pragma_Name => Name_Async_Readers);
2616 Decorate (Aspect, Aitem);
2617 Insert_Pragma (Aitem);
2620 -- Aspect Async_Writers is never delayed because it is
2621 -- equivalent to a source pragma which appears after the
2622 -- related object declaration.
2624 when Aspect_Async_Writers =>
2626 (Pragma_Argument_Associations => New_List (
2627 Make_Pragma_Argument_Association (Loc,
2628 Expression => Relocate_Node (Expr))),
2629 Pragma_Name => Name_Async_Writers);
2631 Decorate (Aspect, Aitem);
2632 Insert_Pragma (Aitem);
2635 -- Aspect Constant_After_Elaboration is never delayed because
2636 -- it is equivalent to a source pragma which appears after the
2637 -- related object declaration.
2639 when Aspect_Constant_After_Elaboration =>
2641 (Pragma_Argument_Associations => New_List (
2642 Make_Pragma_Argument_Association (Loc,
2643 Expression => Relocate_Node (Expr))),
2645 Name_Constant_After_Elaboration);
2647 Decorate (Aspect, Aitem);
2648 Insert_Pragma (Aitem);
2651 -- Aspect Default_Internal_Condition is never delayed because
2652 -- it is equivalent to a source pragma which appears after the
2653 -- related private type. To deal with forward references, the
2654 -- generated pragma is stored in the rep chain of the related
2655 -- private type as types do not carry contracts. The pragma is
2656 -- wrapped inside of a procedure at the freeze point of the
2657 -- private type's full view.
2659 when Aspect_Default_Initial_Condition =>
2661 (Pragma_Argument_Associations => New_List (
2662 Make_Pragma_Argument_Association (Loc,
2663 Expression => Relocate_Node (Expr))),
2665 Name_Default_Initial_Condition);
2667 Decorate (Aspect, Aitem);
2668 Insert_Pragma (Aitem);
2671 -- Default_Storage_Pool
2673 when Aspect_Default_Storage_Pool =>
2675 (Pragma_Argument_Associations => New_List (
2676 Make_Pragma_Argument_Association (Loc,
2677 Expression => Relocate_Node (Expr))),
2679 Name_Default_Storage_Pool);
2681 Decorate (Aspect, Aitem);
2682 Insert_Pragma (Aitem);
2687 -- Aspect Depends is never delayed because it is equivalent to
2688 -- a source pragma which appears after the related subprogram.
2689 -- To deal with forward references, the generated pragma is
2690 -- stored in the contract of the related subprogram and later
2691 -- analyzed at the end of the declarative region. See routine
2692 -- Analyze_Depends_In_Decl_Part for details.
2694 when Aspect_Depends =>
2696 (Pragma_Argument_Associations => New_List (
2697 Make_Pragma_Argument_Association (Loc,
2698 Expression => Relocate_Node (Expr))),
2699 Pragma_Name => Name_Depends);
2701 Decorate (Aspect, Aitem);
2702 Insert_Pragma (Aitem);
2705 -- Aspect Effecitve_Reads is never delayed because it is
2706 -- equivalent to a source pragma which appears after the
2707 -- related object declaration.
2709 when Aspect_Effective_Reads =>
2711 (Pragma_Argument_Associations => New_List (
2712 Make_Pragma_Argument_Association (Loc,
2713 Expression => Relocate_Node (Expr))),
2714 Pragma_Name => Name_Effective_Reads);
2716 Decorate (Aspect, Aitem);
2717 Insert_Pragma (Aitem);
2720 -- Aspect Effective_Writes is never delayed because it is
2721 -- equivalent to a source pragma which appears after the
2722 -- related object declaration.
2724 when Aspect_Effective_Writes =>
2726 (Pragma_Argument_Associations => New_List (
2727 Make_Pragma_Argument_Association (Loc,
2728 Expression => Relocate_Node (Expr))),
2729 Pragma_Name => Name_Effective_Writes);
2731 Decorate (Aspect, Aitem);
2732 Insert_Pragma (Aitem);
2735 -- Aspect Extensions_Visible is never delayed because it is
2736 -- equivalent to a source pragma which appears after the
2737 -- related subprogram.
2739 when Aspect_Extensions_Visible =>
2741 (Pragma_Argument_Associations => New_List (
2742 Make_Pragma_Argument_Association (Loc,
2743 Expression => Relocate_Node (Expr))),
2744 Pragma_Name => Name_Extensions_Visible);
2746 Decorate (Aspect, Aitem);
2747 Insert_Pragma (Aitem);
2750 -- Aspect Ghost is never delayed because it is equivalent to a
2751 -- source pragma which appears at the top of [generic] package
2752 -- declarations or after an object, a [generic] subprogram, or
2753 -- a type declaration.
2755 when Aspect_Ghost =>
2757 (Pragma_Argument_Associations => New_List (
2758 Make_Pragma_Argument_Association (Loc,
2759 Expression => Relocate_Node (Expr))),
2760 Pragma_Name => Name_Ghost);
2762 Decorate (Aspect, Aitem);
2763 Insert_Pragma (Aitem);
2768 -- Aspect Global is never delayed because it is equivalent to
2769 -- a source pragma which appears after the related subprogram.
2770 -- To deal with forward references, the generated pragma is
2771 -- stored in the contract of the related subprogram and later
2772 -- analyzed at the end of the declarative region. See routine
2773 -- Analyze_Global_In_Decl_Part for details.
2775 when Aspect_Global =>
2777 (Pragma_Argument_Associations => New_List (
2778 Make_Pragma_Argument_Association (Loc,
2779 Expression => Relocate_Node (Expr))),
2780 Pragma_Name => Name_Global);
2782 Decorate (Aspect, Aitem);
2783 Insert_Pragma (Aitem);
2786 -- Initial_Condition
2788 -- Aspect Initial_Condition is never delayed because it is
2789 -- equivalent to a source pragma which appears after the
2790 -- related package. To deal with forward references, the
2791 -- generated pragma is stored in the contract of the related
2792 -- package and later analyzed at the end of the declarative
2793 -- region. See routine Analyze_Initial_Condition_In_Decl_Part
2796 when Aspect_Initial_Condition => Initial_Condition : declare
2797 Context : Node_Id := N;
2800 -- When aspect Initial_Condition appears on a generic
2801 -- package, it is propageted to the package instance. The
2802 -- context in this case is the instance spec.
2804 if Nkind (Context) = N_Package_Instantiation then
2805 Context := Instance_Spec (Context);
2808 if Nkind_In (Context, N_Generic_Package_Declaration,
2809 N_Package_Declaration)
2812 (Pragma_Argument_Associations => New_List (
2813 Make_Pragma_Argument_Association (Loc,
2814 Expression => Relocate_Node (Expr))),
2816 Name_Initial_Condition);
2818 Decorate (Aspect, Aitem);
2822 Is_Generic_Instance (Defining_Entity (Context)));
2824 -- Otherwise the context is illegal
2828 ("aspect & must apply to a package declaration",
2833 end Initial_Condition;
2837 -- Aspect Initializes is never delayed because it is equivalent
2838 -- to a source pragma appearing after the related package. To
2839 -- deal with forward references, the generated pragma is stored
2840 -- in the contract of the related package and later analyzed at
2841 -- the end of the declarative region. For details, see routine
2842 -- Analyze_Initializes_In_Decl_Part.
2844 when Aspect_Initializes => Initializes : declare
2845 Context : Node_Id := N;
2848 -- When aspect Initializes appears on a generic package,
2849 -- it is propageted to the package instance. The context
2850 -- in this case is the instance spec.
2852 if Nkind (Context) = N_Package_Instantiation then
2853 Context := Instance_Spec (Context);
2856 if Nkind_In (Context, N_Generic_Package_Declaration,
2857 N_Package_Declaration)
2860 (Pragma_Argument_Associations => New_List (
2861 Make_Pragma_Argument_Association (Loc,
2862 Expression => Relocate_Node (Expr))),
2863 Pragma_Name => Name_Initializes);
2865 Decorate (Aspect, Aitem);
2869 Is_Generic_Instance (Defining_Entity (Context)));
2871 -- Otherwise the context is illegal
2875 ("aspect & must apply to a package declaration",
2884 when Aspect_Max_Queue_Length =>
2886 (Pragma_Argument_Associations => New_List (
2887 Make_Pragma_Argument_Association (Loc,
2888 Expression => Relocate_Node (Expr))),
2889 Pragma_Name => Name_Max_Queue_Length);
2891 Decorate (Aspect, Aitem);
2892 Insert_Pragma (Aitem);
2897 when Aspect_Obsolescent => declare
2905 Make_Pragma_Argument_Association (Sloc (Expr),
2906 Expression => Relocate_Node (Expr)));
2910 (Pragma_Argument_Associations => Args,
2911 Pragma_Name => Chars (Id));
2916 when Aspect_Part_Of =>
2917 if Nkind_In (N, N_Object_Declaration,
2918 N_Package_Instantiation)
2919 or else Is_Single_Concurrent_Type_Declaration (N)
2922 (Pragma_Argument_Associations => New_List (
2923 Make_Pragma_Argument_Association (Loc,
2924 Expression => Relocate_Node (Expr))),
2925 Pragma_Name => Name_Part_Of);
2927 Decorate (Aspect, Aitem);
2928 Insert_Pragma (Aitem);
2932 ("aspect & must apply to package instantiation, "
2933 & "object, single protected type or single task type",
2941 when Aspect_SPARK_Mode =>
2943 (Pragma_Argument_Associations => New_List (
2944 Make_Pragma_Argument_Association (Loc,
2945 Expression => Relocate_Node (Expr))),
2946 Pragma_Name => Name_SPARK_Mode);
2948 Decorate (Aspect, Aitem);
2949 Insert_Pragma (Aitem);
2954 -- Aspect Refined_Depends is never delayed because it is
2955 -- equivalent to a source pragma which appears in the
2956 -- declarations of the related subprogram body. To deal with
2957 -- forward references, the generated pragma is stored in the
2958 -- contract of the related subprogram body and later analyzed
2959 -- at the end of the declarative region. For details, see
2960 -- routine Analyze_Refined_Depends_In_Decl_Part.
2962 when Aspect_Refined_Depends =>
2964 (Pragma_Argument_Associations => New_List (
2965 Make_Pragma_Argument_Association (Loc,
2966 Expression => Relocate_Node (Expr))),
2967 Pragma_Name => Name_Refined_Depends);
2969 Decorate (Aspect, Aitem);
2970 Insert_Pragma (Aitem);
2975 -- Aspect Refined_Global is never delayed because it is
2976 -- equivalent to a source pragma which appears in the
2977 -- declarations of the related subprogram body. To deal with
2978 -- forward references, the generated pragma is stored in the
2979 -- contract of the related subprogram body and later analyzed
2980 -- at the end of the declarative region. For details, see
2981 -- routine Analyze_Refined_Global_In_Decl_Part.
2983 when Aspect_Refined_Global =>
2985 (Pragma_Argument_Associations => New_List (
2986 Make_Pragma_Argument_Association (Loc,
2987 Expression => Relocate_Node (Expr))),
2988 Pragma_Name => Name_Refined_Global);
2990 Decorate (Aspect, Aitem);
2991 Insert_Pragma (Aitem);
2996 when Aspect_Refined_Post =>
2998 (Pragma_Argument_Associations => New_List (
2999 Make_Pragma_Argument_Association (Loc,
3000 Expression => Relocate_Node (Expr))),
3001 Pragma_Name => Name_Refined_Post);
3003 Decorate (Aspect, Aitem);
3004 Insert_Pragma (Aitem);
3009 when Aspect_Refined_State =>
3011 -- The corresponding pragma for Refined_State is inserted in
3012 -- the declarations of the related package body. This action
3013 -- synchronizes both the source and from-aspect versions of
3016 if Nkind (N) = N_Package_Body then
3018 (Pragma_Argument_Associations => New_List (
3019 Make_Pragma_Argument_Association (Loc,
3020 Expression => Relocate_Node (Expr))),
3021 Pragma_Name => Name_Refined_State);
3023 Decorate (Aspect, Aitem);
3024 Insert_Pragma (Aitem);
3026 -- Otherwise the context is illegal
3030 ("aspect & must apply to a package body", Aspect, Id);
3035 -- Relative_Deadline
3037 when Aspect_Relative_Deadline =>
3039 (Pragma_Argument_Associations => New_List (
3040 Make_Pragma_Argument_Association (Loc,
3041 Expression => Relocate_Node (Expr))),
3042 Pragma_Name => Name_Relative_Deadline);
3044 -- If the aspect applies to a task, the corresponding pragma
3045 -- must appear within its declarations, not after.
3047 if Nkind (N) = N_Task_Type_Declaration then
3053 if No (Task_Definition (N)) then
3054 Set_Task_Definition (N,
3055 Make_Task_Definition (Loc,
3056 Visible_Declarations => New_List,
3057 End_Label => Empty));
3060 Def := Task_Definition (N);
3061 V := Visible_Declarations (Def);
3062 if not Is_Empty_List (V) then
3063 Insert_Before (First (V), Aitem);
3066 Set_Visible_Declarations (Def, New_List (Aitem));
3073 -- Aspect Volatile_Function is never delayed because it is
3074 -- equivalent to a source pragma which appears after the
3075 -- related subprogram.
3077 when Aspect_Volatile_Function =>
3079 (Pragma_Argument_Associations => New_List (
3080 Make_Pragma_Argument_Association (Loc,
3081 Expression => Relocate_Node (Expr))),
3082 Pragma_Name => Name_Volatile_Function);
3084 Decorate (Aspect, Aitem);
3085 Insert_Pragma (Aitem);
3088 -- Case 2e: Annotate aspect
3090 when Aspect_Annotate =>
3097 -- The argument can be a single identifier
3099 if Nkind (Expr) = N_Identifier then
3101 -- One level of parens is allowed
3103 if Paren_Count (Expr) > 1 then
3104 Error_Msg_F ("extra parentheses ignored", Expr);
3107 Set_Paren_Count (Expr, 0);
3109 -- Add the single item to the list
3111 Args := New_List (Expr);
3113 -- Otherwise we must have an aggregate
3115 elsif Nkind (Expr) = N_Aggregate then
3117 -- Must be positional
3119 if Present (Component_Associations (Expr)) then
3121 ("purely positional aggregate required", Expr);
3125 -- Must not be parenthesized
3127 if Paren_Count (Expr) /= 0 then
3128 Error_Msg_F ("extra parentheses ignored", Expr);
3131 -- List of arguments is list of aggregate expressions
3133 Args := Expressions (Expr);
3135 -- Anything else is illegal
3138 Error_Msg_F ("wrong form for Annotate aspect", Expr);
3142 -- Prepare pragma arguments
3145 Arg := First (Args);
3146 while Present (Arg) loop
3148 Make_Pragma_Argument_Association (Sloc (Arg),
3149 Expression => Relocate_Node (Arg)));
3154 Make_Pragma_Argument_Association (Sloc (Ent),
3155 Chars => Name_Entity,
3156 Expression => Ent));
3159 (Pragma_Argument_Associations => Pargs,
3160 Pragma_Name => Name_Annotate);
3163 -- Case 3 : Aspects that don't correspond to pragma/attribute
3164 -- definition clause.
3166 -- Case 3a: The aspects listed below don't correspond to
3167 -- pragmas/attributes but do require delayed analysis.
3169 -- Default_Value can only apply to a scalar type
3171 when Aspect_Default_Value =>
3172 if not Is_Scalar_Type (E) then
3174 ("aspect Default_Value must apply to a scalar type", N);
3179 -- Default_Component_Value can only apply to an array type
3180 -- with scalar components.
3182 when Aspect_Default_Component_Value =>
3183 if not (Is_Array_Type (E)
3184 and then Is_Scalar_Type (Component_Type (E)))
3187 ("aspect Default_Component_Value can only apply to an "
3188 & "array of scalar components", N);
3193 -- Case 3b: The aspects listed below don't correspond to
3194 -- pragmas/attributes and don't need delayed analysis.
3196 -- Implicit_Dereference
3198 -- For Implicit_Dereference, External_Name and Link_Name, only
3199 -- the legality checks are done during the analysis, thus no
3200 -- delay is required.
3202 when Aspect_Implicit_Dereference =>
3203 Analyze_Aspect_Implicit_Dereference;
3208 when Aspect_Dimension =>
3209 Analyze_Aspect_Dimension (N, Id, Expr);
3214 when Aspect_Dimension_System =>
3215 Analyze_Aspect_Dimension_System (N, Id, Expr);
3218 -- Case 4: Aspects requiring special handling
3220 -- Pre/Post/Test_Case/Contract_Cases whose corresponding
3221 -- pragmas take care of the delay.
3225 -- Aspects Pre/Post generate Precondition/Postcondition pragmas
3226 -- with a first argument that is the expression, and a second
3227 -- argument that is an informative message if the test fails.
3228 -- This is inserted right after the declaration, to get the
3229 -- required pragma placement. The processing for the pragmas
3230 -- takes care of the required delay.
3232 when Pre_Post_Aspects => Pre_Post : declare
3236 if A_Id = Aspect_Pre or else A_Id = Aspect_Precondition then
3237 Pname := Name_Precondition;
3239 Pname := Name_Postcondition;
3242 -- Check that the class-wide predicate cannot be applied to
3243 -- an operation of a synchronized type. AI12-0182 forbids
3244 -- these altogether, while earlier language semantics made
3245 -- them legal on tagged synchronized types.
3247 -- Other legality checks are performed when analyzing the
3248 -- contract of the operation.
3250 if Class_Present (Aspect)
3251 and then Is_Concurrent_Type (Current_Scope)
3252 and then Ekind_In (E, E_Entry, E_Function, E_Procedure)
3254 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (Aspect);
3256 ("aspect % can only be specified for a primitive "
3257 & "operation of a tagged type", Aspect);
3262 -- If the expressions is of the form A and then B, then
3263 -- we generate separate Pre/Post aspects for the separate
3264 -- clauses. Since we allow multiple pragmas, there is no
3265 -- problem in allowing multiple Pre/Post aspects internally.
3266 -- These should be treated in reverse order (B first and
3267 -- A second) since they are later inserted just after N in
3268 -- the order they are treated. This way, the pragma for A
3269 -- ends up preceding the pragma for B, which may have an
3270 -- importance for the error raised (either constraint error
3271 -- or precondition error).
3273 -- We do not do this for Pre'Class, since we have to put
3274 -- these conditions together in a complex OR expression.
3276 -- We do not do this in ASIS mode, as ASIS relies on the
3277 -- original node representing the complete expression, when
3278 -- retrieving it through the source aspect table.
3281 and then (Pname = Name_Postcondition
3282 or else not Class_Present (Aspect))
3284 while Nkind (Expr) = N_And_Then loop
3285 Insert_After (Aspect,
3286 Make_Aspect_Specification (Sloc (Left_Opnd (Expr)),
3287 Identifier => Identifier (Aspect),
3288 Expression => Relocate_Node (Left_Opnd (Expr)),
3289 Class_Present => Class_Present (Aspect),
3290 Split_PPC => True));
3291 Rewrite (Expr, Relocate_Node (Right_Opnd (Expr)));
3292 Eloc := Sloc (Expr);
3296 -- Build the precondition/postcondition pragma
3298 -- Add note about why we do NOT need Copy_Tree here???
3301 (Pragma_Argument_Associations => New_List (
3302 Make_Pragma_Argument_Association (Eloc,
3303 Chars => Name_Check,
3304 Expression => Relocate_Node (Expr))),
3305 Pragma_Name => Pname);
3307 -- Add message unless exception messages are suppressed
3309 if not Opt.Exception_Locations_Suppressed then
3310 Append_To (Pragma_Argument_Associations (Aitem),
3311 Make_Pragma_Argument_Association (Eloc,
3312 Chars => Name_Message,
3314 Make_String_Literal (Eloc,
3316 & Get_Name_String (Pname)
3318 & Build_Location_String (Eloc))));
3321 Set_Is_Delayed_Aspect (Aspect);
3323 -- For Pre/Post cases, insert immediately after the entity
3324 -- declaration, since that is the required pragma placement.
3325 -- Note that for these aspects, we do not have to worry
3326 -- about delay issues, since the pragmas themselves deal
3327 -- with delay of visibility for the expression analysis.
3329 Insert_Pragma (Aitem);
3336 when Aspect_Test_Case => Test_Case : declare
3338 Comp_Expr : Node_Id;
3339 Comp_Assn : Node_Id;
3345 if Nkind (Parent (N)) = N_Compilation_Unit then
3346 Error_Msg_Name_1 := Nam;
3347 Error_Msg_N ("incorrect placement of aspect `%`", E);
3351 if Nkind (Expr) /= N_Aggregate then
3352 Error_Msg_Name_1 := Nam;
3354 ("wrong syntax for aspect `%` for &", Id, E);
3358 -- Make pragma expressions refer to the original aspect
3359 -- expressions through the Original_Node link. This is used
3360 -- in semantic analysis for ASIS mode, so that the original
3361 -- expression also gets analyzed.
3363 Comp_Expr := First (Expressions (Expr));
3364 while Present (Comp_Expr) loop
3365 New_Expr := Relocate_Node (Comp_Expr);
3367 Make_Pragma_Argument_Association (Sloc (Comp_Expr),
3368 Expression => New_Expr));
3372 Comp_Assn := First (Component_Associations (Expr));
3373 while Present (Comp_Assn) loop
3374 if List_Length (Choices (Comp_Assn)) /= 1
3376 Nkind (First (Choices (Comp_Assn))) /= N_Identifier
3378 Error_Msg_Name_1 := Nam;
3380 ("wrong syntax for aspect `%` for &", Id, E);
3385 Make_Pragma_Argument_Association (Sloc (Comp_Assn),
3386 Chars => Chars (First (Choices (Comp_Assn))),
3388 Relocate_Node (Expression (Comp_Assn))));
3392 -- Build the test-case pragma
3395 (Pragma_Argument_Associations => Args,
3396 Pragma_Name => Nam);
3401 when Aspect_Contract_Cases =>
3403 (Pragma_Argument_Associations => New_List (
3404 Make_Pragma_Argument_Association (Loc,
3405 Expression => Relocate_Node (Expr))),
3406 Pragma_Name => Nam);
3408 Decorate (Aspect, Aitem);
3409 Insert_Pragma (Aitem);
3412 -- Case 5: Special handling for aspects with an optional
3413 -- boolean argument.
3415 -- In the delayed case, the corresponding pragma cannot be
3416 -- generated yet because the evaluation of the boolean needs
3417 -- to be delayed till the freeze point.
3419 when Boolean_Aspects
3420 | Library_Unit_Aspects
3422 Set_Is_Boolean_Aspect (Aspect);
3424 -- Lock_Free aspect only apply to protected objects
3426 if A_Id = Aspect_Lock_Free then
3427 if Ekind (E) /= E_Protected_Type then
3428 Error_Msg_Name_1 := Nam;
3430 ("aspect % only applies to a protected object",
3434 -- Set the Uses_Lock_Free flag to True if there is no
3435 -- expression or if the expression is True. The
3436 -- evaluation of this aspect should be delayed to the
3437 -- freeze point (why???)
3440 or else Is_True (Static_Boolean (Expr))
3442 Set_Uses_Lock_Free (E);
3445 Record_Rep_Item (E, Aspect);
3450 elsif A_Id = Aspect_Export or else A_Id = Aspect_Import then
3451 Analyze_Aspect_Export_Import;
3453 -- Disable_Controlled
3455 elsif A_Id = Aspect_Disable_Controlled then
3456 if Ekind (E) /= E_Record_Type
3457 or else not Is_Controlled (E)
3460 ("aspect % requires controlled record type", Aspect);
3464 -- If we're in a generic template, we don't want to try
3465 -- to disable controlled types, because typical usage is
3466 -- "Disable_Controlled => not <some_check>'Enabled", and
3467 -- the value of Enabled is not known until we see a
3468 -- particular instance. In such a context, we just need
3469 -- to preanalyze the expression for legality.
3471 if Expander_Active then
3472 Analyze_And_Resolve (Expr, Standard_Boolean);
3474 if not Present (Expr)
3475 or else Is_True (Static_Boolean (Expr))
3477 Set_Disable_Controlled (E);
3480 elsif Serious_Errors_Detected = 0 then
3481 Preanalyze_And_Resolve (Expr, Standard_Boolean);
3487 -- Library unit aspects require special handling in the case
3488 -- of a package declaration, the pragma needs to be inserted
3489 -- in the list of declarations for the associated package.
3490 -- There is no issue of visibility delay for these aspects.
3492 if A_Id in Library_Unit_Aspects
3494 Nkind_In (N, N_Package_Declaration,
3495 N_Generic_Package_Declaration)
3496 and then Nkind (Parent (N)) /= N_Compilation_Unit
3498 -- Aspect is legal on a local instantiation of a library-
3499 -- level generic unit.
3501 and then not Is_Generic_Instance (Defining_Entity (N))
3504 ("incorrect context for library unit aspect&", Id);
3508 -- Cases where we do not delay, includes all cases where the
3509 -- expression is missing other than the above cases.
3511 if not Delay_Required or else No (Expr) then
3513 -- Exclude aspects Export and Import because their pragma
3514 -- syntax does not map directly to a Boolean aspect.
3516 if A_Id /= Aspect_Export
3517 and then A_Id /= Aspect_Import
3520 (Pragma_Argument_Associations => New_List (
3521 Make_Pragma_Argument_Association (Sloc (Ent),
3522 Expression => Ent)),
3523 Pragma_Name => Chars (Id));
3526 Delay_Required := False;
3528 -- In general cases, the corresponding pragma/attribute
3529 -- definition clause will be inserted later at the freezing
3530 -- point, and we do not need to build it now.
3538 -- This is special because for access types we need to generate
3539 -- an attribute definition clause. This also works for single
3540 -- task declarations, but it does not work for task type
3541 -- declarations, because we have the case where the expression
3542 -- references a discriminant of the task type. That can't use
3543 -- an attribute definition clause because we would not have
3544 -- visibility on the discriminant. For that case we must
3545 -- generate a pragma in the task definition.
3547 when Aspect_Storage_Size =>
3551 if Ekind (E) = E_Task_Type then
3553 Decl : constant Node_Id := Declaration_Node (E);
3556 pragma Assert (Nkind (Decl) = N_Task_Type_Declaration);
3558 -- If no task definition, create one
3560 if No (Task_Definition (Decl)) then
3561 Set_Task_Definition (Decl,
3562 Make_Task_Definition (Loc,
3563 Visible_Declarations => Empty_List,
3564 End_Label => Empty));
3567 -- Create a pragma and put it at the start of the task
3568 -- definition for the task type declaration.
3571 (Pragma_Argument_Associations => New_List (
3572 Make_Pragma_Argument_Association (Loc,
3573 Expression => Relocate_Node (Expr))),
3574 Pragma_Name => Name_Storage_Size);
3578 Visible_Declarations (Task_Definition (Decl)));
3582 -- All other cases, generate attribute definition
3586 Make_Attribute_Definition_Clause (Loc,
3588 Chars => Chars (Id),
3589 Expression => Relocate_Node (Expr));
3593 -- Attach the corresponding pragma/attribute definition clause to
3594 -- the aspect specification node.
3596 if Present (Aitem) then
3597 Set_From_Aspect_Specification (Aitem);
3600 -- In the context of a compilation unit, we directly put the
3601 -- pragma in the Pragmas_After list of the N_Compilation_Unit_Aux
3602 -- node (no delay is required here) except for aspects on a
3603 -- subprogram body (see below) and a generic package, for which we
3604 -- need to introduce the pragma before building the generic copy
3605 -- (see sem_ch12), and for package instantiations, where the
3606 -- library unit pragmas are better handled early.
3608 if Nkind (Parent (N)) = N_Compilation_Unit
3609 and then (Present (Aitem) or else Is_Boolean_Aspect (Aspect))
3612 Aux : constant Node_Id := Aux_Decls_Node (Parent (N));
3615 pragma Assert (Nkind (Aux) = N_Compilation_Unit_Aux);
3617 -- For a Boolean aspect, create the corresponding pragma if
3618 -- no expression or if the value is True.
3620 if Is_Boolean_Aspect (Aspect) and then No (Aitem) then
3621 if Is_True (Static_Boolean (Expr)) then
3623 (Pragma_Argument_Associations => New_List (
3624 Make_Pragma_Argument_Association (Sloc (Ent),
3625 Expression => Ent)),
3626 Pragma_Name => Chars (Id));
3628 Set_From_Aspect_Specification (Aitem, True);
3629 Set_Corresponding_Aspect (Aitem, Aspect);
3636 -- If the aspect is on a subprogram body (relevant aspect
3637 -- is Inline), add the pragma in front of the declarations.
3639 if Nkind (N) = N_Subprogram_Body then
3640 if No (Declarations (N)) then
3641 Set_Declarations (N, New_List);
3644 Prepend (Aitem, Declarations (N));
3646 elsif Nkind (N) = N_Generic_Package_Declaration then
3647 if No (Visible_Declarations (Specification (N))) then
3648 Set_Visible_Declarations (Specification (N), New_List);
3652 Visible_Declarations (Specification (N)));
3654 elsif Nkind (N) = N_Package_Instantiation then
3656 Spec : constant Node_Id :=
3657 Specification (Instance_Spec (N));
3659 if No (Visible_Declarations (Spec)) then
3660 Set_Visible_Declarations (Spec, New_List);
3663 Prepend (Aitem, Visible_Declarations (Spec));
3667 if No (Pragmas_After (Aux)) then
3668 Set_Pragmas_After (Aux, New_List);
3671 Append (Aitem, Pragmas_After (Aux));
3678 -- The evaluation of the aspect is delayed to the freezing point.
3679 -- The pragma or attribute clause if there is one is then attached
3680 -- to the aspect specification which is put in the rep item list.
3682 if Delay_Required then
3683 if Present (Aitem) then
3684 Set_Is_Delayed_Aspect (Aitem);
3685 Set_Aspect_Rep_Item (Aspect, Aitem);
3686 Set_Parent (Aitem, Aspect);
3689 Set_Is_Delayed_Aspect (Aspect);
3691 -- In the case of Default_Value, link the aspect to base type
3692 -- as well, even though it appears on a first subtype. This is
3693 -- mandated by the semantics of the aspect. Do not establish
3694 -- the link when processing the base type itself as this leads
3695 -- to a rep item circularity. Verify that we are dealing with
3696 -- a scalar type to prevent cascaded errors.
3698 if A_Id = Aspect_Default_Value
3699 and then Is_Scalar_Type (E)
3700 and then Base_Type (E) /= E
3702 Set_Has_Delayed_Aspects (Base_Type (E));
3703 Record_Rep_Item (Base_Type (E), Aspect);
3706 Set_Has_Delayed_Aspects (E);
3707 Record_Rep_Item (E, Aspect);
3709 -- When delay is not required and the context is a package or a
3710 -- subprogram body, insert the pragma in the body declarations.
3712 elsif Nkind_In (N, N_Package_Body, N_Subprogram_Body) then
3713 if No (Declarations (N)) then
3714 Set_Declarations (N, New_List);
3717 -- The pragma is added before source declarations
3719 Prepend_To (Declarations (N), Aitem);
3721 -- When delay is not required and the context is not a compilation
3722 -- unit, we simply insert the pragma/attribute definition clause
3725 elsif Present (Aitem) then
3726 Insert_After (Ins_Node, Aitem);
3729 end Analyze_One_Aspect;
3733 end loop Aspect_Loop;
3735 if Has_Delayed_Aspects (E) then
3736 Ensure_Freeze_Node (E);
3738 end Analyze_Aspect_Specifications;
3740 ---------------------------------------------------
3741 -- Analyze_Aspect_Specifications_On_Body_Or_Stub --
3742 ---------------------------------------------------
3744 procedure Analyze_Aspect_Specifications_On_Body_Or_Stub (N : Node_Id) is
3745 Body_Id : constant Entity_Id := Defining_Entity (N);
3747 procedure Diagnose_Misplaced_Aspects (Spec_Id : Entity_Id);
3748 -- Body [stub] N has aspects, but they are not properly placed. Emit an
3749 -- error message depending on the aspects involved. Spec_Id denotes the
3750 -- entity of the corresponding spec.
3752 --------------------------------
3753 -- Diagnose_Misplaced_Aspects --
3754 --------------------------------
3756 procedure Diagnose_Misplaced_Aspects (Spec_Id : Entity_Id) is
3757 procedure Misplaced_Aspect_Error
3760 -- Emit an error message concerning misplaced aspect Asp. Ref_Nam is
3761 -- the name of the refined version of the aspect.
3763 ----------------------------
3764 -- Misplaced_Aspect_Error --
3765 ----------------------------
3767 procedure Misplaced_Aspect_Error
3771 Asp_Nam : constant Name_Id := Chars (Identifier (Asp));
3772 Asp_Id : constant Aspect_Id := Get_Aspect_Id (Asp_Nam);
3775 -- The corresponding spec already contains the aspect in question
3776 -- and the one appearing on the body must be the refined form:
3778 -- procedure P with Global ...;
3779 -- procedure P with Global ... is ... end P;
3783 if Has_Aspect (Spec_Id, Asp_Id) then
3784 Error_Msg_Name_1 := Asp_Nam;
3786 -- Subunits cannot carry aspects that apply to a subprogram
3789 if Nkind (Parent (N)) = N_Subunit then
3790 Error_Msg_N ("aspect % cannot apply to a subunit", Asp);
3792 -- Otherwise suggest the refined form
3795 Error_Msg_Name_2 := Ref_Nam;
3796 Error_Msg_N ("aspect % should be %", Asp);
3799 -- Otherwise the aspect must appear on the spec, not on the body
3802 -- procedure P with Global ... is ... end P;
3806 ("aspect specification must appear on initial declaration",
3809 end Misplaced_Aspect_Error;
3816 -- Start of processing for Diagnose_Misplaced_Aspects
3819 -- Iterate over the aspect specifications and emit specific errors
3820 -- where applicable.
3822 Asp := First (Aspect_Specifications (N));
3823 while Present (Asp) loop
3824 Asp_Nam := Chars (Identifier (Asp));
3826 -- Do not emit errors on aspects that can appear on a subprogram
3827 -- body. This scenario occurs when the aspect specification list
3828 -- contains both misplaced and properly placed aspects.
3830 if Aspect_On_Body_Or_Stub_OK (Get_Aspect_Id (Asp_Nam)) then
3833 -- Special diagnostics for SPARK aspects
3835 elsif Asp_Nam = Name_Depends then
3836 Misplaced_Aspect_Error (Asp, Name_Refined_Depends);
3838 elsif Asp_Nam = Name_Global then
3839 Misplaced_Aspect_Error (Asp, Name_Refined_Global);
3841 elsif Asp_Nam = Name_Post then
3842 Misplaced_Aspect_Error (Asp, Name_Refined_Post);
3844 -- Otherwise a language-defined aspect is misplaced
3848 ("aspect specification must appear on initial declaration",
3854 end Diagnose_Misplaced_Aspects;
3858 Spec_Id : constant Entity_Id := Unique_Defining_Entity (N);
3860 -- Start of processing for Analyze_Aspects_On_Body_Or_Stub
3863 -- Language-defined aspects cannot be associated with a subprogram body
3864 -- [stub] if the subprogram has a spec. Certain implementation defined
3865 -- aspects are allowed to break this rule (for all applicable cases, see
3866 -- table Aspects.Aspect_On_Body_Or_Stub_OK).
3868 if Spec_Id /= Body_Id and then not Aspects_On_Body_Or_Stub_OK (N) then
3869 Diagnose_Misplaced_Aspects (Spec_Id);
3871 Analyze_Aspect_Specifications (N, Body_Id);
3873 end Analyze_Aspect_Specifications_On_Body_Or_Stub;
3875 -----------------------
3876 -- Analyze_At_Clause --
3877 -----------------------
3879 -- An at clause is replaced by the corresponding Address attribute
3880 -- definition clause that is the preferred approach in Ada 95.
3882 procedure Analyze_At_Clause (N : Node_Id) is
3883 CS : constant Boolean := Comes_From_Source (N);
3886 -- This is an obsolescent feature
3888 Check_Restriction (No_Obsolescent_Features, N);
3890 if Warn_On_Obsolescent_Feature then
3892 ("?j?at clause is an obsolescent feature (RM J.7(2))", N);
3894 ("\?j?use address attribute definition clause instead", N);
3897 -- Rewrite as address clause
3900 Make_Attribute_Definition_Clause (Sloc (N),
3901 Name => Identifier (N),
3902 Chars => Name_Address,
3903 Expression => Expression (N)));
3905 -- We preserve Comes_From_Source, since logically the clause still comes
3906 -- from the source program even though it is changed in form.
3908 Set_Comes_From_Source (N, CS);
3910 -- Analyze rewritten clause
3912 Analyze_Attribute_Definition_Clause (N);
3913 end Analyze_At_Clause;
3915 -----------------------------------------
3916 -- Analyze_Attribute_Definition_Clause --
3917 -----------------------------------------
3919 procedure Analyze_Attribute_Definition_Clause (N : Node_Id) is
3920 Loc : constant Source_Ptr := Sloc (N);
3921 Nam : constant Node_Id := Name (N);
3922 Attr : constant Name_Id := Chars (N);
3923 Expr : constant Node_Id := Expression (N);
3924 Id : constant Attribute_Id := Get_Attribute_Id (Attr);
3927 -- The entity of Nam after it is analyzed. In the case of an incomplete
3928 -- type, this is the underlying type.
3931 -- The underlying entity to which the attribute applies. Generally this
3932 -- is the Underlying_Type of Ent, except in the case where the clause
3933 -- applies to the full view of an incomplete or private type, in which
3934 -- case U_Ent is just a copy of Ent.
3936 FOnly : Boolean := False;
3937 -- Reset to True for subtype specific attribute (Alignment, Size)
3938 -- and for stream attributes, i.e. those cases where in the call to
3939 -- Rep_Item_Too_Late, FOnly is set True so that only the freezing rules
3940 -- are checked. Note that the case of stream attributes is not clear
3941 -- from the RM, but see AI95-00137. Also, the RM seems to disallow
3942 -- Storage_Size for derived task types, but that is also clearly
3945 procedure Analyze_Stream_TSS_Definition (TSS_Nam : TSS_Name_Type);
3946 -- Common processing for 'Read, 'Write, 'Input and 'Output attribute
3947 -- definition clauses.
3949 function Duplicate_Clause return Boolean;
3950 -- This routine checks if the aspect for U_Ent being given by attribute
3951 -- definition clause N is for an aspect that has already been specified,
3952 -- and if so gives an error message. If there is a duplicate, True is
3953 -- returned, otherwise if there is no error, False is returned.
3955 procedure Check_Indexing_Functions;
3956 -- Check that the function in Constant_Indexing or Variable_Indexing
3957 -- attribute has the proper type structure. If the name is overloaded,
3958 -- check that some interpretation is legal.
3960 procedure Check_Iterator_Functions;
3961 -- Check that there is a single function in Default_Iterator attribute
3962 -- has the proper type structure.
3964 function Check_Primitive_Function (Subp : Entity_Id) return Boolean;
3965 -- Common legality check for the previous two
3967 -----------------------------------
3968 -- Analyze_Stream_TSS_Definition --
3969 -----------------------------------
3971 procedure Analyze_Stream_TSS_Definition (TSS_Nam : TSS_Name_Type) is
3972 Subp : Entity_Id := Empty;
3977 Is_Read : constant Boolean := (TSS_Nam = TSS_Stream_Read);
3978 -- True for Read attribute, False for other attributes
3980 function Has_Good_Profile
3982 Report : Boolean := False) return Boolean;
3983 -- Return true if the entity is a subprogram with an appropriate
3984 -- profile for the attribute being defined. If result is False and
3985 -- Report is True, function emits appropriate error.
3987 ----------------------
3988 -- Has_Good_Profile --
3989 ----------------------
3991 function Has_Good_Profile
3993 Report : Boolean := False) return Boolean
3995 Expected_Ekind : constant array (Boolean) of Entity_Kind :=
3996 (False => E_Procedure, True => E_Function);
3997 Is_Function : constant Boolean := (TSS_Nam = TSS_Stream_Input);
4002 if Ekind (Subp) /= Expected_Ekind (Is_Function) then
4006 F := First_Formal (Subp);
4009 or else Ekind (Etype (F)) /= E_Anonymous_Access_Type
4010 or else Designated_Type (Etype (F)) /=
4011 Class_Wide_Type (RTE (RE_Root_Stream_Type))
4016 if not Is_Function then
4020 Expected_Mode : constant array (Boolean) of Entity_Kind :=
4021 (False => E_In_Parameter,
4022 True => E_Out_Parameter);
4024 if Parameter_Mode (F) /= Expected_Mode (Is_Read) then
4031 -- If the attribute specification comes from an aspect
4032 -- specification for a class-wide stream, the parameter must be
4033 -- a class-wide type of the entity to which the aspect applies.
4035 if From_Aspect_Specification (N)
4036 and then Class_Present (Parent (N))
4037 and then Is_Class_Wide_Type (Typ)
4043 Typ := Etype (Subp);
4046 -- Verify that the prefix of the attribute and the local name for
4047 -- the type of the formal match, or one is the class-wide of the
4048 -- other, in the case of a class-wide stream operation.
4050 if Base_Type (Typ) = Base_Type (Ent)
4051 or else (Is_Class_Wide_Type (Typ)
4052 and then Typ = Class_Wide_Type (Base_Type (Ent)))
4053 or else (Is_Class_Wide_Type (Ent)
4054 and then Ent = Class_Wide_Type (Base_Type (Typ)))
4061 if Present (Next_Formal (F)) then
4064 elsif not Is_Scalar_Type (Typ)
4065 and then not Is_First_Subtype (Typ)
4066 and then not Is_Class_Wide_Type (Typ)
4068 if Report and not Is_First_Subtype (Typ) then
4070 ("subtype of formal in stream operation must be a first "
4071 & "subtype", Parameter_Type (Parent (F)));
4079 end Has_Good_Profile;
4081 -- Start of processing for Analyze_Stream_TSS_Definition
4086 if not Is_Type (U_Ent) then
4087 Error_Msg_N ("local name must be a subtype", Nam);
4090 elsif not Is_First_Subtype (U_Ent) then
4091 Error_Msg_N ("local name must be a first subtype", Nam);
4095 Pnam := TSS (Base_Type (U_Ent), TSS_Nam);
4097 -- If Pnam is present, it can be either inherited from an ancestor
4098 -- type (in which case it is legal to redefine it for this type), or
4099 -- be a previous definition of the attribute for the same type (in
4100 -- which case it is illegal).
4102 -- In the first case, it will have been analyzed already, and we
4103 -- can check that its profile does not match the expected profile
4104 -- for a stream attribute of U_Ent. In the second case, either Pnam
4105 -- has been analyzed (and has the expected profile), or it has not
4106 -- been analyzed yet (case of a type that has not been frozen yet
4107 -- and for which the stream attribute has been set using Set_TSS).
4110 and then (No (First_Entity (Pnam)) or else Has_Good_Profile (Pnam))
4112 Error_Msg_Sloc := Sloc (Pnam);
4113 Error_Msg_Name_1 := Attr;
4114 Error_Msg_N ("% attribute already defined #", Nam);
4120 if Is_Entity_Name (Expr) then
4121 if not Is_Overloaded (Expr) then
4122 if Has_Good_Profile (Entity (Expr), Report => True) then
4123 Subp := Entity (Expr);
4127 Get_First_Interp (Expr, I, It);
4128 while Present (It.Nam) loop
4129 if Has_Good_Profile (It.Nam) then
4134 Get_Next_Interp (I, It);
4139 if Present (Subp) then
4140 if Is_Abstract_Subprogram (Subp) then
4141 Error_Msg_N ("stream subprogram must not be abstract", Expr);
4144 -- A stream subprogram for an interface type must be a null
4145 -- procedure (RM 13.13.2 (38/3)). Note that the class-wide type
4146 -- of an interface is not an interface type (3.9.4 (6.b/2)).
4148 elsif Is_Interface (U_Ent)
4149 and then not Is_Class_Wide_Type (U_Ent)
4150 and then not Inside_A_Generic
4152 (Ekind (Subp) = E_Function
4156 (Unit_Declaration_Node (Ultimate_Alias (Subp)))))
4159 ("stream subprogram for interface type must be null "
4160 & "procedure", Expr);
4163 Set_Entity (Expr, Subp);
4164 Set_Etype (Expr, Etype (Subp));
4166 New_Stream_Subprogram (N, U_Ent, Subp, TSS_Nam);
4169 Error_Msg_Name_1 := Attr;
4170 Error_Msg_N ("incorrect expression for% attribute", Expr);
4172 end Analyze_Stream_TSS_Definition;
4174 ------------------------------
4175 -- Check_Indexing_Functions --
4176 ------------------------------
4178 procedure Check_Indexing_Functions is
4179 Indexing_Found : Boolean := False;
4181 procedure Check_Inherited_Indexing;
4182 -- For a derived type, check that no indexing aspect is specified
4183 -- for the type if it is also inherited
4185 procedure Check_One_Function (Subp : Entity_Id);
4186 -- Check one possible interpretation. Sets Indexing_Found True if a
4187 -- legal indexing function is found.
4189 procedure Illegal_Indexing (Msg : String);
4190 -- Diagnose illegal indexing function if not overloaded. In the
4191 -- overloaded case indicate that no legal interpretation exists.
4193 ------------------------------
4194 -- Check_Inherited_Indexing --
4195 ------------------------------
4197 procedure Check_Inherited_Indexing is
4198 Inherited : Node_Id;
4201 if Attr = Name_Constant_Indexing then
4203 Find_Aspect (Etype (Ent), Aspect_Constant_Indexing);
4204 else pragma Assert (Attr = Name_Variable_Indexing);
4206 Find_Aspect (Etype (Ent), Aspect_Variable_Indexing);
4209 if Present (Inherited) then
4210 if Debug_Flag_Dot_XX then
4213 -- OK if current attribute_definition_clause is expansion of
4214 -- inherited aspect.
4216 elsif Aspect_Rep_Item (Inherited) = N then
4219 -- Indicate the operation that must be overridden, rather than
4220 -- redefining the indexing aspect.
4224 ("indexing function already inherited from parent type");
4226 ("!override & instead",
4227 N, Entity (Expression (Inherited)));
4230 end Check_Inherited_Indexing;
4232 ------------------------
4233 -- Check_One_Function --
4234 ------------------------
4236 procedure Check_One_Function (Subp : Entity_Id) is
4237 Default_Element : Node_Id;
4238 Ret_Type : constant Entity_Id := Etype (Subp);
4241 if not Is_Overloadable (Subp) then
4242 Illegal_Indexing ("illegal indexing function for type&");
4245 elsif Scope (Subp) /= Scope (Ent) then
4246 if Nkind (Expr) = N_Expanded_Name then
4248 -- Indexing function can't be declared elsewhere
4251 ("indexing function must be declared in scope of type&");
4256 elsif No (First_Formal (Subp)) then
4258 ("Indexing requires a function that applies to type&");
4261 elsif No (Next_Formal (First_Formal (Subp))) then
4263 ("indexing function must have at least two parameters");
4266 elsif Is_Derived_Type (Ent) then
4267 Check_Inherited_Indexing;
4270 if not Check_Primitive_Function (Subp) then
4272 ("Indexing aspect requires a function that applies to type&");
4276 -- If partial declaration exists, verify that it is not tagged.
4278 if Ekind (Current_Scope) = E_Package
4279 and then Has_Private_Declaration (Ent)
4280 and then From_Aspect_Specification (N)
4282 List_Containing (Parent (Ent)) =
4283 Private_Declarations
4284 (Specification (Unit_Declaration_Node (Current_Scope)))
4285 and then Nkind (N) = N_Attribute_Definition_Clause
4292 First (Visible_Declarations
4294 (Unit_Declaration_Node (Current_Scope))));
4296 while Present (Decl) loop
4297 if Nkind (Decl) = N_Private_Type_Declaration
4298 and then Ent = Full_View (Defining_Identifier (Decl))
4299 and then Tagged_Present (Decl)
4300 and then No (Aspect_Specifications (Decl))
4303 ("Indexing aspect cannot be specified on full view "
4304 & "if partial view is tagged");
4313 -- An indexing function must return either the default element of
4314 -- the container, or a reference type. For variable indexing it
4315 -- must be the latter.
4318 Find_Value_Of_Aspect
4319 (Etype (First_Formal (Subp)), Aspect_Iterator_Element);
4321 if Present (Default_Element) then
4322 Analyze (Default_Element);
4324 if Is_Entity_Name (Default_Element)
4325 and then not Covers (Entity (Default_Element), Ret_Type)
4329 ("wrong return type for indexing function");
4334 -- For variable_indexing the return type must be a reference type
4336 if Attr = Name_Variable_Indexing then
4337 if not Has_Implicit_Dereference (Ret_Type) then
4339 ("variable indexing must return a reference type");
4342 elsif Is_Access_Constant
4343 (Etype (First_Discriminant (Ret_Type)))
4346 ("variable indexing must return an access to variable");
4351 if Has_Implicit_Dereference (Ret_Type)
4353 Is_Access_Constant (Etype (First_Discriminant (Ret_Type)))
4356 ("constant indexing must return an access to constant");
4359 elsif Is_Access_Type (Etype (First_Formal (Subp)))
4360 and then not Is_Access_Constant (Etype (First_Formal (Subp)))
4363 ("constant indexing must apply to an access to constant");
4368 -- All checks succeeded.
4370 Indexing_Found := True;
4371 end Check_One_Function;
4373 -----------------------
4374 -- Illegal_Indexing --
4375 -----------------------
4377 procedure Illegal_Indexing (Msg : String) is
4379 Error_Msg_NE (Msg, N, Ent);
4380 end Illegal_Indexing;
4382 -- Start of processing for Check_Indexing_Functions
4386 Check_Inherited_Indexing;
4391 if not Is_Overloaded (Expr) then
4392 Check_One_Function (Entity (Expr));
4400 Indexing_Found := False;
4401 Get_First_Interp (Expr, I, It);
4402 while Present (It.Nam) loop
4404 -- Note that analysis will have added the interpretation
4405 -- that corresponds to the dereference. We only check the
4406 -- subprogram itself. Ignore homonyms that may come from
4407 -- derived types in the context.
4409 if Is_Overloadable (It.Nam)
4410 and then Comes_From_Source (It.Nam)
4412 Check_One_Function (It.Nam);
4415 Get_Next_Interp (I, It);
4420 if not Indexing_Found and then not Error_Posted (N) then
4422 ("aspect Indexing requires a local function that applies to "
4423 & "type&", Expr, Ent);
4425 end Check_Indexing_Functions;
4427 ------------------------------
4428 -- Check_Iterator_Functions --
4429 ------------------------------
4431 procedure Check_Iterator_Functions is
4432 function Valid_Default_Iterator (Subp : Entity_Id) return Boolean;
4433 -- Check one possible interpretation for validity
4435 ----------------------------
4436 -- Valid_Default_Iterator --
4437 ----------------------------
4439 function Valid_Default_Iterator (Subp : Entity_Id) return Boolean is
4440 Root_T : constant Entity_Id := Root_Type (Etype (Etype (Subp)));
4444 if not Check_Primitive_Function (Subp) then
4447 -- The return type must be derived from a type in an instance
4448 -- of Iterator.Interfaces, and thus its root type must have a
4451 elsif Chars (Root_T) /= Name_Forward_Iterator
4452 and then Chars (Root_T) /= Name_Reversible_Iterator
4457 Formal := First_Formal (Subp);
4460 -- False if any subsequent formal has no default expression
4462 Formal := Next_Formal (Formal);
4463 while Present (Formal) loop
4464 if No (Expression (Parent (Formal))) then
4468 Next_Formal (Formal);
4471 -- True if all subsequent formals have default expressions
4474 end Valid_Default_Iterator;
4476 -- Start of processing for Check_Iterator_Functions
4481 if not Is_Entity_Name (Expr) then
4482 Error_Msg_N ("aspect Iterator must be a function name", Expr);
4485 if not Is_Overloaded (Expr) then
4486 if not Check_Primitive_Function (Entity (Expr)) then
4488 ("aspect Indexing requires a function that applies to type&",
4489 Entity (Expr), Ent);
4492 -- Flag the default_iterator as well as the denoted function.
4494 if not Valid_Default_Iterator (Entity (Expr)) then
4495 Error_Msg_N ("improper function for default iterator!", Expr);
4500 Default : Entity_Id := Empty;
4505 Get_First_Interp (Expr, I, It);
4506 while Present (It.Nam) loop
4507 if not Check_Primitive_Function (It.Nam)
4508 or else not Valid_Default_Iterator (It.Nam)
4512 elsif Present (Default) then
4514 -- An explicit one should override an implicit one
4516 if Comes_From_Source (Default) =
4517 Comes_From_Source (It.Nam)
4519 Error_Msg_N ("default iterator must be unique", Expr);
4520 Error_Msg_Sloc := Sloc (Default);
4521 Error_Msg_N ("\\possible interpretation#", Expr);
4522 Error_Msg_Sloc := Sloc (It.Nam);
4523 Error_Msg_N ("\\possible interpretation#", Expr);
4525 elsif Comes_From_Source (It.Nam) then
4532 Get_Next_Interp (I, It);
4535 if Present (Default) then
4536 Set_Entity (Expr, Default);
4537 Set_Is_Overloaded (Expr, False);
4540 ("no interpretation is a valid default iterator!", Expr);
4544 end Check_Iterator_Functions;
4546 -------------------------------
4547 -- Check_Primitive_Function --
4548 -------------------------------
4550 function Check_Primitive_Function (Subp : Entity_Id) return Boolean is
4554 if Ekind (Subp) /= E_Function then
4558 if No (First_Formal (Subp)) then
4561 Ctrl := Etype (First_Formal (Subp));
4564 -- To be a primitive operation subprogram has to be in same scope.
4566 if Scope (Ctrl) /= Scope (Subp) then
4570 -- Type of formal may be the class-wide type, an access to such,
4571 -- or an incomplete view.
4574 or else Ctrl = Class_Wide_Type (Ent)
4576 (Ekind (Ctrl) = E_Anonymous_Access_Type
4577 and then (Designated_Type (Ctrl) = Ent
4579 Designated_Type (Ctrl) = Class_Wide_Type (Ent)))
4581 (Ekind (Ctrl) = E_Incomplete_Type
4582 and then Full_View (Ctrl) = Ent)
4590 end Check_Primitive_Function;
4592 ----------------------
4593 -- Duplicate_Clause --
4594 ----------------------
4596 function Duplicate_Clause return Boolean is
4600 -- Nothing to do if this attribute definition clause comes from
4601 -- an aspect specification, since we could not be duplicating an
4602 -- explicit clause, and we dealt with the case of duplicated aspects
4603 -- in Analyze_Aspect_Specifications.
4605 if From_Aspect_Specification (N) then
4609 -- Otherwise current clause may duplicate previous clause, or a
4610 -- previously given pragma or aspect specification for the same
4613 A := Get_Rep_Item (U_Ent, Chars (N), Check_Parents => False);
4616 Error_Msg_Name_1 := Chars (N);
4617 Error_Msg_Sloc := Sloc (A);
4619 Error_Msg_NE ("aspect% for & previously given#", N, U_Ent);
4624 end Duplicate_Clause;
4626 -- Start of processing for Analyze_Attribute_Definition_Clause
4629 -- The following code is a defense against recursion. Not clear that
4630 -- this can happen legitimately, but perhaps some error situations can
4631 -- cause it, and we did see this recursion during testing.
4633 if Analyzed (N) then
4636 Set_Analyzed (N, True);
4639 Check_Restriction_No_Use_Of_Attribute (N);
4641 -- Ignore some selected attributes in CodePeer mode since they are not
4642 -- relevant in this context.
4644 if CodePeer_Mode then
4647 -- Ignore Component_Size in CodePeer mode, to avoid changing the
4648 -- internal representation of types by implicitly packing them.
4650 when Attribute_Component_Size =>
4651 Rewrite (N, Make_Null_Statement (Sloc (N)));
4659 -- Process Ignore_Rep_Clauses option
4661 if Ignore_Rep_Clauses then
4664 -- The following should be ignored. They do not affect legality
4665 -- and may be target dependent. The basic idea of -gnatI is to
4666 -- ignore any rep clauses that may be target dependent but do not
4667 -- affect legality (except possibly to be rejected because they
4668 -- are incompatible with the compilation target).
4670 when Attribute_Alignment
4671 | Attribute_Bit_Order
4672 | Attribute_Component_Size
4673 | Attribute_Default_Scalar_Storage_Order
4674 | Attribute_Machine_Radix
4675 | Attribute_Object_Size
4676 | Attribute_Scalar_Storage_Order
4679 | Attribute_Stream_Size
4680 | Attribute_Value_Size
4682 Kill_Rep_Clause (N);
4685 -- The following should not be ignored, because in the first place
4686 -- they are reasonably portable, and should not cause problems
4687 -- in compiling code from another target, and also they do affect
4688 -- legality, e.g. failing to provide a stream attribute for a type
4689 -- may make a program illegal.
4691 when Attribute_External_Tag
4695 | Attribute_Simple_Storage_Pool
4696 | Attribute_Storage_Pool
4697 | Attribute_Storage_Size
4702 -- We do not do anything here with address clauses, they will be
4703 -- removed by Freeze later on, but for now, it works better to
4704 -- keep then in the tree.
4706 when Attribute_Address =>
4709 -- Other cases are errors ("attribute& cannot be set with
4710 -- definition clause"), which will be caught below.
4718 Ent := Entity (Nam);
4720 if Rep_Item_Too_Early (Ent, N) then
4724 -- Rep clause applies to full view of incomplete type or private type if
4725 -- we have one (if not, this is a premature use of the type). However,
4726 -- certain semantic checks need to be done on the specified entity (i.e.
4727 -- the private view), so we save it in Ent.
4729 if Is_Private_Type (Ent)
4730 and then Is_Derived_Type (Ent)
4731 and then not Is_Tagged_Type (Ent)
4732 and then No (Full_View (Ent))
4734 -- If this is a private type whose completion is a derivation from
4735 -- another private type, there is no full view, and the attribute
4736 -- belongs to the type itself, not its underlying parent.
4740 elsif Ekind (Ent) = E_Incomplete_Type then
4742 -- The attribute applies to the full view, set the entity of the
4743 -- attribute definition accordingly.
4745 Ent := Underlying_Type (Ent);
4747 Set_Entity (Nam, Ent);
4750 U_Ent := Underlying_Type (Ent);
4753 -- Avoid cascaded error
4755 if Etype (Nam) = Any_Type then
4758 -- Must be declared in current scope or in case of an aspect
4759 -- specification, must be visible in current scope.
4761 elsif Scope (Ent) /= Current_Scope
4763 not (From_Aspect_Specification (N)
4764 and then Scope_Within_Or_Same (Current_Scope, Scope (Ent)))
4766 Error_Msg_N ("entity must be declared in this scope", Nam);
4769 -- Must not be a source renaming (we do have some cases where the
4770 -- expander generates a renaming, and those cases are OK, in such
4771 -- cases any attribute applies to the renamed object as well).
4773 elsif Is_Object (Ent)
4774 and then Present (Renamed_Object (Ent))
4776 -- Case of renamed object from source, this is an error
4778 if Comes_From_Source (Renamed_Object (Ent)) then
4779 Get_Name_String (Chars (N));
4780 Error_Msg_Strlen := Name_Len;
4781 Error_Msg_String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len);
4783 ("~ clause not allowed for a renaming declaration "
4784 & "(RM 13.1(6))", Nam);
4787 -- For the case of a compiler generated renaming, the attribute
4788 -- definition clause applies to the renamed object created by the
4789 -- expander. The easiest general way to handle this is to create a
4790 -- copy of the attribute definition clause for this object.
4792 elsif Is_Entity_Name (Renamed_Object (Ent)) then
4794 Make_Attribute_Definition_Clause (Loc,
4796 New_Occurrence_Of (Entity (Renamed_Object (Ent)), Loc),
4798 Expression => Duplicate_Subexpr (Expression (N))));
4800 -- If the renamed object is not an entity, it must be a dereference
4801 -- of an unconstrained function call, and we must introduce a new
4802 -- declaration to capture the expression. This is needed in the case
4803 -- of 'Alignment, where the original declaration must be rewritten.
4807 (Nkind (Renamed_Object (Ent)) = N_Explicit_Dereference);
4811 -- If no underlying entity, use entity itself, applies to some
4812 -- previously detected error cases ???
4814 elsif No (U_Ent) then
4817 -- Cannot specify for a subtype (exception Object/Value_Size)
4819 elsif Is_Type (U_Ent)
4820 and then not Is_First_Subtype (U_Ent)
4821 and then Id /= Attribute_Object_Size
4822 and then Id /= Attribute_Value_Size
4823 and then not From_At_Mod (N)
4825 Error_Msg_N ("cannot specify attribute for subtype", Nam);
4829 Set_Entity (N, U_Ent);
4831 -- Switch on particular attribute
4839 -- Address attribute definition clause
4841 when Attribute_Address => Address : begin
4843 -- A little error check, catch for X'Address use X'Address;
4845 if Nkind (Nam) = N_Identifier
4846 and then Nkind (Expr) = N_Attribute_Reference
4847 and then Attribute_Name (Expr) = Name_Address
4848 and then Nkind (Prefix (Expr)) = N_Identifier
4849 and then Chars (Nam) = Chars (Prefix (Expr))
4852 ("address for & is self-referencing", Prefix (Expr), Ent);
4856 -- Not that special case, carry on with analysis of expression
4858 Analyze_And_Resolve (Expr, RTE (RE_Address));
4860 -- Even when ignoring rep clauses we need to indicate that the
4861 -- entity has an address clause and thus it is legal to declare
4862 -- it imported. Freeze will get rid of the address clause later.
4864 if Ignore_Rep_Clauses then
4865 if Ekind_In (U_Ent, E_Variable, E_Constant) then
4866 Record_Rep_Item (U_Ent, N);
4872 if Duplicate_Clause then
4875 -- Case of address clause for subprogram
4877 elsif Is_Subprogram (U_Ent) then
4878 if Has_Homonym (U_Ent) then
4880 ("address clause cannot be given for overloaded "
4881 & "subprogram", Nam);
4885 -- For subprograms, all address clauses are permitted, and we
4886 -- mark the subprogram as having a deferred freeze so that Gigi
4887 -- will not elaborate it too soon.
4889 -- Above needs more comments, what is too soon about???
4891 Set_Has_Delayed_Freeze (U_Ent);
4893 -- Case of address clause for entry
4895 elsif Ekind (U_Ent) = E_Entry then
4896 if Nkind (Parent (N)) = N_Task_Body then
4898 ("entry address must be specified in task spec", Nam);
4902 -- For entries, we require a constant address
4904 Check_Constant_Address_Clause (Expr, U_Ent);
4906 -- Special checks for task types
4908 if Is_Task_Type (Scope (U_Ent))
4909 and then Comes_From_Source (Scope (U_Ent))
4912 ("??entry address declared for entry in task type", N);
4914 ("\??only one task can be declared of this type", N);
4917 -- Entry address clauses are obsolescent
4919 Check_Restriction (No_Obsolescent_Features, N);
4921 if Warn_On_Obsolescent_Feature then
4923 ("?j?attaching interrupt to task entry is an obsolescent "
4924 & "feature (RM J.7.1)", N);
4926 ("\?j?use interrupt procedure instead", N);
4929 -- Case of an address clause for a class-wide object, which is
4930 -- considered erroneous.
4932 elsif Is_Class_Wide_Type (Etype (U_Ent)) then
4934 ("??class-wide object & must not be overlaid", Nam, U_Ent);
4936 ("\??Program_Error will be raised at run time", Nam);
4937 Insert_Action (Declaration_Node (U_Ent),
4938 Make_Raise_Program_Error (Loc,
4939 Reason => PE_Overlaid_Controlled_Object));
4942 -- Case of address clause for an object
4944 elsif Ekind_In (U_Ent, E_Constant, E_Variable) then
4946 Expr : constant Node_Id := Expression (N);
4951 -- Exported variables cannot have an address clause, because
4952 -- this cancels the effect of the pragma Export.
4954 if Is_Exported (U_Ent) then
4956 ("cannot export object with address clause", Nam);
4960 Find_Overlaid_Entity (N, O_Ent, Off);
4962 if Present (O_Ent) then
4964 -- If the object overlays a constant object, mark it so
4966 if Is_Constant_Object (O_Ent) then
4967 Set_Overlays_Constant (U_Ent);
4970 -- If the address clause is of the form:
4972 -- for X'Address use Y'Address;
4976 -- C : constant Address := Y'Address;
4978 -- for X'Address use C;
4980 -- then we make an entry in the table to check the size
4981 -- and alignment of the overlaying variable. But we defer
4982 -- this check till after code generation to take full
4983 -- advantage of the annotation done by the back end.
4985 -- If the entity has a generic type, the check will be
4986 -- performed in the instance if the actual type justifies
4987 -- it, and we do not insert the clause in the table to
4988 -- prevent spurious warnings.
4990 -- Note: we used to test Comes_From_Source and only give
4991 -- this warning for source entities, but we have removed
4992 -- this test. It really seems bogus to generate overlays
4993 -- that would trigger this warning in generated code.
4994 -- Furthermore, by removing the test, we handle the
4995 -- aspect case properly.
4997 if Is_Object (O_Ent)
4998 and then not Is_Generic_Type (Etype (U_Ent))
4999 and then Address_Clause_Overlay_Warnings
5001 Address_Clause_Checks.Append
5002 ((N, U_Ent, No_Uint, O_Ent, Off));
5005 -- If this is not an overlay, mark a variable as being
5006 -- volatile to prevent unwanted optimizations. It's a
5007 -- conservative interpretation of RM 13.3(19) for the
5008 -- cases where the compiler cannot detect potential
5009 -- aliasing issues easily and it also covers the case
5010 -- of an absolute address where the volatile aspect is
5011 -- kind of implicit.
5013 if Ekind (U_Ent) = E_Variable then
5014 Set_Treat_As_Volatile (U_Ent);
5017 -- Make an entry in the table for an absolute address as
5018 -- above to check that the value is compatible with the
5019 -- alignment of the object.
5022 Addr : constant Node_Id := Address_Value (Expr);
5024 if Compile_Time_Known_Value (Addr)
5025 and then Address_Clause_Overlay_Warnings
5027 Address_Clause_Checks.Append
5028 ((N, U_Ent, Expr_Value (Addr), Empty, False));
5033 -- Issue an unconditional warning for a constant overlaying
5034 -- a variable. For the reverse case, we will issue it only
5035 -- if the variable is modified.
5037 if Ekind (U_Ent) = E_Constant
5038 and then Present (O_Ent)
5039 and then not Overlays_Constant (U_Ent)
5040 and then Address_Clause_Overlay_Warnings
5042 Error_Msg_N ("??constant overlays a variable", Expr);
5044 -- Imported variables can have an address clause, but then
5045 -- the import is pretty meaningless except to suppress
5046 -- initializations, so we do not need such variables to
5047 -- be statically allocated (and in fact it causes trouble
5048 -- if the address clause is a local value).
5050 elsif Is_Imported (U_Ent) then
5051 Set_Is_Statically_Allocated (U_Ent, False);
5054 -- We mark a possible modification of a variable with an
5055 -- address clause, since it is likely aliasing is occurring.
5057 Note_Possible_Modification (Nam, Sure => False);
5059 -- Legality checks on the address clause for initialized
5060 -- objects is deferred until the freeze point, because
5061 -- a subsequent pragma might indicate that the object
5062 -- is imported and thus not initialized. Also, the address
5063 -- clause might involve entities that have yet to be
5066 Set_Has_Delayed_Freeze (U_Ent);
5068 -- If an initialization call has been generated for this
5069 -- object, it needs to be deferred to after the freeze node
5070 -- we have just now added, otherwise GIGI will see a
5071 -- reference to the variable (as actual to the IP call)
5072 -- before its definition.
5075 Init_Call : constant Node_Id :=
5076 Remove_Init_Call (U_Ent, N);
5079 if Present (Init_Call) then
5080 Append_Freeze_Action (U_Ent, Init_Call);
5082 -- Reset Initialization_Statements pointer so that
5083 -- if there is a pragma Import further down, it can
5084 -- clear any default initialization.
5086 Set_Initialization_Statements (U_Ent, Init_Call);
5090 -- Entity has delayed freeze, so we will generate an
5091 -- alignment check at the freeze point unless suppressed.
5093 if not Range_Checks_Suppressed (U_Ent)
5094 and then not Alignment_Checks_Suppressed (U_Ent)
5096 Set_Check_Address_Alignment (N);
5099 -- Kill the size check code, since we are not allocating
5100 -- the variable, it is somewhere else.
5102 Kill_Size_Check_Code (U_Ent);
5105 -- Not a valid entity for an address clause
5108 Error_Msg_N ("address cannot be given for &", Nam);
5116 -- Alignment attribute definition clause
5118 when Attribute_Alignment => Alignment : declare
5119 Align : constant Uint := Get_Alignment_Value (Expr);
5120 Max_Align : constant Uint := UI_From_Int (Maximum_Alignment);
5125 if not Is_Type (U_Ent)
5126 and then Ekind (U_Ent) /= E_Variable
5127 and then Ekind (U_Ent) /= E_Constant
5129 Error_Msg_N ("alignment cannot be given for &", Nam);
5131 elsif Duplicate_Clause then
5134 elsif Align /= No_Uint then
5135 Set_Has_Alignment_Clause (U_Ent);
5137 -- Tagged type case, check for attempt to set alignment to a
5138 -- value greater than Max_Align, and reset if so. This error
5139 -- is suppressed in ASIS mode to allow for different ASIS
5140 -- back ends or ASIS-based tools to query the illegal clause.
5142 if Is_Tagged_Type (U_Ent)
5143 and then Align > Max_Align
5144 and then not ASIS_Mode
5147 ("alignment for & set to Maximum_Aligment??", Nam);
5148 Set_Alignment (U_Ent, Max_Align);
5153 Set_Alignment (U_Ent, Align);
5156 -- For an array type, U_Ent is the first subtype. In that case,
5157 -- also set the alignment of the anonymous base type so that
5158 -- other subtypes (such as the itypes for aggregates of the
5159 -- type) also receive the expected alignment.
5161 if Is_Array_Type (U_Ent) then
5162 Set_Alignment (Base_Type (U_Ent), Align);
5171 -- Bit_Order attribute definition clause
5173 when Attribute_Bit_Order =>
5174 if not Is_Record_Type (U_Ent) then
5176 ("Bit_Order can only be defined for record type", Nam);
5178 elsif Duplicate_Clause then
5182 Analyze_And_Resolve (Expr, RTE (RE_Bit_Order));
5184 if Etype (Expr) = Any_Type then
5187 elsif not Is_OK_Static_Expression (Expr) then
5188 Flag_Non_Static_Expr
5189 ("Bit_Order requires static expression!", Expr);
5192 if (Expr_Value (Expr) = 0) /= Bytes_Big_Endian then
5193 Set_Reverse_Bit_Order (Base_Type (U_Ent), True);
5198 --------------------
5199 -- Component_Size --
5200 --------------------
5202 -- Component_Size attribute definition clause
5204 when Attribute_Component_Size => Component_Size_Case : declare
5205 Csize : constant Uint := Static_Integer (Expr);
5209 New_Ctyp : Entity_Id;
5213 if not Is_Array_Type (U_Ent) then
5214 Error_Msg_N ("component size requires array type", Nam);
5218 Btype := Base_Type (U_Ent);
5219 Ctyp := Component_Type (Btype);
5221 if Duplicate_Clause then
5224 elsif Rep_Item_Too_Early (Btype, N) then
5227 elsif Csize /= No_Uint then
5228 Check_Size (Expr, Ctyp, Csize, Biased);
5230 -- For the biased case, build a declaration for a subtype that
5231 -- will be used to represent the biased subtype that reflects
5232 -- the biased representation of components. We need the subtype
5233 -- to get proper conversions on referencing elements of the
5238 Make_Defining_Identifier (Loc,
5240 New_External_Name (Chars (U_Ent), 'C', 0, 'T'));
5243 Make_Subtype_Declaration (Loc,
5244 Defining_Identifier => New_Ctyp,
5245 Subtype_Indication =>
5246 New_Occurrence_Of (Component_Type (Btype), Loc));
5248 Set_Parent (Decl, N);
5249 Analyze (Decl, Suppress => All_Checks);
5251 Set_Has_Delayed_Freeze (New_Ctyp, False);
5252 Set_Esize (New_Ctyp, Csize);
5253 Set_RM_Size (New_Ctyp, Csize);
5254 Init_Alignment (New_Ctyp);
5255 Set_Is_Itype (New_Ctyp, True);
5256 Set_Associated_Node_For_Itype (New_Ctyp, U_Ent);
5258 Set_Component_Type (Btype, New_Ctyp);
5259 Set_Biased (New_Ctyp, N, "component size clause");
5262 Set_Component_Size (Btype, Csize);
5264 -- Deal with warning on overridden size
5266 if Warn_On_Overridden_Size
5267 and then Has_Size_Clause (Ctyp)
5268 and then RM_Size (Ctyp) /= Csize
5271 ("component size overrides size clause for&?S?", N, Ctyp);
5274 Set_Has_Component_Size_Clause (Btype, True);
5275 Set_Has_Non_Standard_Rep (Btype, True);
5277 end Component_Size_Case;
5279 -----------------------
5280 -- Constant_Indexing --
5281 -----------------------
5283 when Attribute_Constant_Indexing =>
5284 Check_Indexing_Functions;
5290 when Attribute_CPU =>
5292 -- CPU attribute definition clause not allowed except from aspect
5295 if From_Aspect_Specification (N) then
5296 if not Is_Task_Type (U_Ent) then
5297 Error_Msg_N ("CPU can only be defined for task", Nam);
5299 elsif Duplicate_Clause then
5303 -- The expression must be analyzed in the special manner
5304 -- described in "Handling of Default and Per-Object
5305 -- Expressions" in sem.ads.
5307 -- The visibility to the discriminants must be restored
5309 Push_Scope_And_Install_Discriminants (U_Ent);
5310 Preanalyze_Spec_Expression (Expr, RTE (RE_CPU_Range));
5311 Uninstall_Discriminants_And_Pop_Scope (U_Ent);
5313 if not Is_OK_Static_Expression (Expr) then
5314 Check_Restriction (Static_Priorities, Expr);
5320 ("attribute& cannot be set with definition clause", N);
5323 ----------------------
5324 -- Default_Iterator --
5325 ----------------------
5327 when Attribute_Default_Iterator => Default_Iterator : declare
5332 -- If target type is untagged, further checks are irrelevant
5334 if not Is_Tagged_Type (U_Ent) then
5336 ("aspect Default_Iterator applies to tagged type", Nam);
5340 Check_Iterator_Functions;
5344 if not Is_Entity_Name (Expr)
5345 or else Ekind (Entity (Expr)) /= E_Function
5347 Error_Msg_N ("aspect Iterator must be a function", Expr);
5350 Func := Entity (Expr);
5353 -- The type of the first parameter must be T, T'class, or a
5354 -- corresponding access type (5.5.1 (8/3). If function is
5355 -- parameterless label type accordingly.
5357 if No (First_Formal (Func)) then
5360 Typ := Etype (First_Formal (Func));
5364 or else Typ = Class_Wide_Type (U_Ent)
5365 or else (Is_Access_Type (Typ)
5366 and then Designated_Type (Typ) = U_Ent)
5367 or else (Is_Access_Type (Typ)
5368 and then Designated_Type (Typ) =
5369 Class_Wide_Type (U_Ent))
5375 ("Default Iterator must be a primitive of&", Func, U_Ent);
5377 end Default_Iterator;
5379 ------------------------
5380 -- Dispatching_Domain --
5381 ------------------------
5383 when Attribute_Dispatching_Domain =>
5385 -- Dispatching_Domain attribute definition clause not allowed
5386 -- except from aspect specification.
5388 if From_Aspect_Specification (N) then
5389 if not Is_Task_Type (U_Ent) then
5391 ("Dispatching_Domain can only be defined for task", Nam);
5393 elsif Duplicate_Clause then
5397 -- The expression must be analyzed in the special manner
5398 -- described in "Handling of Default and Per-Object
5399 -- Expressions" in sem.ads.
5401 -- The visibility to the discriminants must be restored
5403 Push_Scope_And_Install_Discriminants (U_Ent);
5405 Preanalyze_Spec_Expression
5406 (Expr, RTE (RE_Dispatching_Domain));
5408 Uninstall_Discriminants_And_Pop_Scope (U_Ent);
5413 ("attribute& cannot be set with definition clause", N);
5420 when Attribute_External_Tag =>
5421 if not Is_Tagged_Type (U_Ent) then
5422 Error_Msg_N ("should be a tagged type", Nam);
5425 if Duplicate_Clause then
5429 Analyze_And_Resolve (Expr, Standard_String);
5431 if not Is_OK_Static_Expression (Expr) then
5432 Flag_Non_Static_Expr
5433 ("static string required for tag name!", Nam);
5436 if not Is_Library_Level_Entity (U_Ent) then
5438 ("??non-unique external tag supplied for &", N, U_Ent);
5440 ("\??same external tag applies to all subprogram calls",
5443 ("\??corresponding internal tag cannot be obtained", N);
5447 --------------------------
5448 -- Implicit_Dereference --
5449 --------------------------
5451 when Attribute_Implicit_Dereference =>
5453 -- Legality checks already performed at the point of the type
5454 -- declaration, aspect is not delayed.
5462 when Attribute_Input =>
5463 Analyze_Stream_TSS_Definition (TSS_Stream_Input);
5464 Set_Has_Specified_Stream_Input (Ent);
5466 ------------------------
5467 -- Interrupt_Priority --
5468 ------------------------
5470 when Attribute_Interrupt_Priority =>
5472 -- Interrupt_Priority attribute definition clause not allowed
5473 -- except from aspect specification.
5475 if From_Aspect_Specification (N) then
5476 if not Is_Concurrent_Type (U_Ent) then
5478 ("Interrupt_Priority can only be defined for task and "
5479 & "protected object", Nam);
5481 elsif Duplicate_Clause then
5485 -- The expression must be analyzed in the special manner
5486 -- described in "Handling of Default and Per-Object
5487 -- Expressions" in sem.ads.
5489 -- The visibility to the discriminants must be restored
5491 Push_Scope_And_Install_Discriminants (U_Ent);
5493 Preanalyze_Spec_Expression
5494 (Expr, RTE (RE_Interrupt_Priority));
5496 Uninstall_Discriminants_And_Pop_Scope (U_Ent);
5498 -- Check the No_Task_At_Interrupt_Priority restriction
5500 if Is_Task_Type (U_Ent) then
5501 Check_Restriction (No_Task_At_Interrupt_Priority, N);
5507 ("attribute& cannot be set with definition clause", N);
5514 when Attribute_Iterable =>
5517 if Nkind (Expr) /= N_Aggregate then
5518 Error_Msg_N ("aspect Iterable must be an aggregate", Expr);
5525 Assoc := First (Component_Associations (Expr));
5526 while Present (Assoc) loop
5527 if not Is_Entity_Name (Expression (Assoc)) then
5528 Error_Msg_N ("value must be a function", Assoc);
5535 ----------------------
5536 -- Iterator_Element --
5537 ----------------------
5539 when Attribute_Iterator_Element =>
5542 if not Is_Entity_Name (Expr)
5543 or else not Is_Type (Entity (Expr))
5545 Error_Msg_N ("aspect Iterator_Element must be a type", Expr);
5552 -- Machine radix attribute definition clause
5554 when Attribute_Machine_Radix => Machine_Radix : declare
5555 Radix : constant Uint := Static_Integer (Expr);
5558 if not Is_Decimal_Fixed_Point_Type (U_Ent) then
5559 Error_Msg_N ("decimal fixed-point type expected for &", Nam);
5561 elsif Duplicate_Clause then
5564 elsif Radix /= No_Uint then
5565 Set_Has_Machine_Radix_Clause (U_Ent);
5566 Set_Has_Non_Standard_Rep (Base_Type (U_Ent));
5571 elsif Radix = 10 then
5572 Set_Machine_Radix_10 (U_Ent);
5574 -- The following error is suppressed in ASIS mode to allow for
5575 -- different ASIS back ends or ASIS-based tools to query the
5578 elsif not ASIS_Mode then
5579 Error_Msg_N ("machine radix value must be 2 or 10", Expr);
5588 -- Object_Size attribute definition clause
5590 when Attribute_Object_Size => Object_Size : declare
5591 Size : constant Uint := Static_Integer (Expr);
5594 pragma Warnings (Off, Biased);
5597 if not Is_Type (U_Ent) then
5598 Error_Msg_N ("Object_Size cannot be given for &", Nam);
5600 elsif Duplicate_Clause then
5604 Check_Size (Expr, U_Ent, Size, Biased);
5606 -- The following errors are suppressed in ASIS mode to allow
5607 -- for different ASIS back ends or ASIS-based tools to query
5608 -- the illegal clause.
5613 elsif Is_Scalar_Type (U_Ent) then
5614 if Size /= 8 and then Size /= 16 and then Size /= 32
5615 and then UI_Mod (Size, 64) /= 0
5618 ("Object_Size must be 8, 16, 32, or multiple of 64",
5622 elsif Size mod 8 /= 0 then
5623 Error_Msg_N ("Object_Size must be a multiple of 8", Expr);
5626 Set_Esize (U_Ent, Size);
5627 Set_Has_Object_Size_Clause (U_Ent);
5628 Alignment_Check_For_Size_Change (U_Ent, Size);
5636 when Attribute_Output =>
5637 Analyze_Stream_TSS_Definition (TSS_Stream_Output);
5638 Set_Has_Specified_Stream_Output (Ent);
5644 when Attribute_Priority =>
5646 -- Priority attribute definition clause not allowed except from
5647 -- aspect specification.
5649 if From_Aspect_Specification (N) then
5650 if not (Is_Concurrent_Type (U_Ent)
5651 or else Ekind (U_Ent) = E_Procedure)
5654 ("Priority can only be defined for task and protected "
5657 elsif Duplicate_Clause then
5661 -- The expression must be analyzed in the special manner
5662 -- described in "Handling of Default and Per-Object
5663 -- Expressions" in sem.ads.
5665 -- The visibility to the discriminants must be restored
5667 Push_Scope_And_Install_Discriminants (U_Ent);
5668 Preanalyze_Spec_Expression (Expr, Standard_Integer);
5669 Uninstall_Discriminants_And_Pop_Scope (U_Ent);
5671 if not Is_OK_Static_Expression (Expr) then
5672 Check_Restriction (Static_Priorities, Expr);
5678 ("attribute& cannot be set with definition clause", N);
5685 when Attribute_Read =>
5686 Analyze_Stream_TSS_Definition (TSS_Stream_Read);
5687 Set_Has_Specified_Stream_Read (Ent);
5689 --------------------------
5690 -- Scalar_Storage_Order --
5691 --------------------------
5693 -- Scalar_Storage_Order attribute definition clause
5695 when Attribute_Scalar_Storage_Order =>
5696 if not (Is_Record_Type (U_Ent) or else Is_Array_Type (U_Ent)) then
5698 ("Scalar_Storage_Order can only be defined for record or "
5699 & "array type", Nam);
5701 elsif Duplicate_Clause then
5705 Analyze_And_Resolve (Expr, RTE (RE_Bit_Order));
5707 if Etype (Expr) = Any_Type then
5710 elsif not Is_OK_Static_Expression (Expr) then
5711 Flag_Non_Static_Expr
5712 ("Scalar_Storage_Order requires static expression!", Expr);
5714 elsif (Expr_Value (Expr) = 0) /= Bytes_Big_Endian then
5716 -- Here for the case of a non-default (i.e. non-confirming)
5717 -- Scalar_Storage_Order attribute definition.
5719 if Support_Nondefault_SSO_On_Target then
5720 Set_Reverse_Storage_Order (Base_Type (U_Ent), True);
5723 ("non-default Scalar_Storage_Order not supported on "
5728 -- Clear SSO default indications since explicit setting of the
5729 -- order overrides the defaults.
5731 Set_SSO_Set_Low_By_Default (Base_Type (U_Ent), False);
5732 Set_SSO_Set_High_By_Default (Base_Type (U_Ent), False);
5735 --------------------------
5736 -- Secondary_Stack_Size --
5737 --------------------------
5739 when Attribute_Secondary_Stack_Size =>
5741 -- Secondary_Stack_Size attribute definition clause not allowed
5742 -- except from aspect specification.
5744 if From_Aspect_Specification (N) then
5745 if not Is_Task_Type (U_Ent) then
5747 ("Secondary Stack Size can only be defined for task", Nam);
5749 elsif Duplicate_Clause then
5753 Check_Restriction (No_Secondary_Stack, Expr);
5755 -- The expression must be analyzed in the special manner
5756 -- described in "Handling of Default and Per-Object
5757 -- Expressions" in sem.ads.
5759 -- The visibility to the discriminants must be restored
5761 Push_Scope_And_Install_Discriminants (U_Ent);
5762 Preanalyze_Spec_Expression (Expr, Any_Integer);
5763 Uninstall_Discriminants_And_Pop_Scope (U_Ent);
5765 if not Is_OK_Static_Expression (Expr) then
5766 Check_Restriction (Static_Storage_Size, Expr);
5772 ("attribute& cannot be set with definition clause", N);
5779 -- Size attribute definition clause
5781 when Attribute_Size => Size : declare
5782 Size : constant Uint := Static_Integer (Expr);
5789 if Duplicate_Clause then
5792 elsif not Is_Type (U_Ent)
5793 and then Ekind (U_Ent) /= E_Variable
5794 and then Ekind (U_Ent) /= E_Constant
5796 Error_Msg_N ("size cannot be given for &", Nam);
5798 elsif Is_Array_Type (U_Ent)
5799 and then not Is_Constrained (U_Ent)
5802 ("size cannot be given for unconstrained array", Nam);
5804 elsif Size /= No_Uint then
5805 if Is_Type (U_Ent) then
5808 Etyp := Etype (U_Ent);
5811 -- Check size, note that Gigi is in charge of checking that the
5812 -- size of an array or record type is OK. Also we do not check
5813 -- the size in the ordinary fixed-point case, since it is too
5814 -- early to do so (there may be subsequent small clause that
5815 -- affects the size). We can check the size if a small clause
5816 -- has already been given.
5818 if not Is_Ordinary_Fixed_Point_Type (U_Ent)
5819 or else Has_Small_Clause (U_Ent)
5821 Check_Size (Expr, Etyp, Size, Biased);
5822 Set_Biased (U_Ent, N, "size clause", Biased);
5825 -- For types set RM_Size and Esize if possible
5827 if Is_Type (U_Ent) then
5828 Set_RM_Size (U_Ent, Size);
5830 -- For elementary types, increase Object_Size to power of 2,
5831 -- but not less than a storage unit in any case (normally
5832 -- this means it will be byte addressable).
5834 -- For all other types, nothing else to do, we leave Esize
5835 -- (object size) unset, the back end will set it from the
5836 -- size and alignment in an appropriate manner.
5838 -- In both cases, we check whether the alignment must be
5839 -- reset in the wake of the size change.
5841 if Is_Elementary_Type (U_Ent) then
5842 if Size <= System_Storage_Unit then
5843 Init_Esize (U_Ent, System_Storage_Unit);
5844 elsif Size <= 16 then
5845 Init_Esize (U_Ent, 16);
5846 elsif Size <= 32 then
5847 Init_Esize (U_Ent, 32);
5849 Set_Esize (U_Ent, (Size + 63) / 64 * 64);
5852 Alignment_Check_For_Size_Change (U_Ent, Esize (U_Ent));
5854 Alignment_Check_For_Size_Change (U_Ent, Size);
5857 -- For objects, set Esize only
5860 -- The following error is suppressed in ASIS mode to allow
5861 -- for different ASIS back ends or ASIS-based tools to query
5862 -- the illegal clause.
5864 if Is_Elementary_Type (Etyp)
5865 and then Size /= System_Storage_Unit
5866 and then Size /= System_Storage_Unit * 2
5867 and then Size /= System_Storage_Unit * 4
5868 and then Size /= System_Storage_Unit * 8
5869 and then not ASIS_Mode
5871 Error_Msg_Uint_1 := UI_From_Int (System_Storage_Unit);
5872 Error_Msg_Uint_2 := Error_Msg_Uint_1 * 8;
5874 ("size for primitive object must be a power of 2 in "
5875 & "the range ^-^", N);
5878 Set_Esize (U_Ent, Size);
5881 Set_Has_Size_Clause (U_Ent);
5889 -- Small attribute definition clause
5891 when Attribute_Small => Small : declare
5892 Implicit_Base : constant Entity_Id := Base_Type (U_Ent);
5896 Analyze_And_Resolve (Expr, Any_Real);
5898 if Etype (Expr) = Any_Type then
5901 elsif not Is_OK_Static_Expression (Expr) then
5902 Flag_Non_Static_Expr
5903 ("small requires static expression!", Expr);
5907 Small := Expr_Value_R (Expr);
5909 if Small <= Ureal_0 then
5910 Error_Msg_N ("small value must be greater than zero", Expr);
5916 if not Is_Ordinary_Fixed_Point_Type (U_Ent) then
5918 ("small requires an ordinary fixed point type", Nam);
5920 elsif Has_Small_Clause (U_Ent) then
5921 Error_Msg_N ("small already given for &", Nam);
5923 elsif Small > Delta_Value (U_Ent) then
5925 ("small value must not be greater than delta value", Nam);
5928 Set_Small_Value (U_Ent, Small);
5929 Set_Small_Value (Implicit_Base, Small);
5930 Set_Has_Small_Clause (U_Ent);
5931 Set_Has_Small_Clause (Implicit_Base);
5932 Set_Has_Non_Standard_Rep (Implicit_Base);
5940 -- Storage_Pool attribute definition clause
5942 when Attribute_Simple_Storage_Pool
5943 | Attribute_Storage_Pool
5945 Storage_Pool : declare
5950 if Ekind (U_Ent) = E_Access_Subprogram_Type then
5952 ("storage pool cannot be given for access-to-subprogram type",
5956 elsif not Ekind_In (U_Ent, E_Access_Type, E_General_Access_Type)
5959 ("storage pool can only be given for access types", Nam);
5962 elsif Is_Derived_Type (U_Ent) then
5964 ("storage pool cannot be given for a derived access type",
5967 elsif Duplicate_Clause then
5970 elsif Present (Associated_Storage_Pool (U_Ent)) then
5971 Error_Msg_N ("storage pool already given for &", Nam);
5975 -- Check for Storage_Size previously given
5978 SS : constant Node_Id :=
5979 Get_Attribute_Definition_Clause
5980 (U_Ent, Attribute_Storage_Size);
5982 if Present (SS) then
5983 Check_Pool_Size_Clash (U_Ent, N, SS);
5987 -- Storage_Pool case
5989 if Id = Attribute_Storage_Pool then
5991 (Expr, Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
5993 -- In the Simple_Storage_Pool case, we allow a variable of any
5994 -- simple storage pool type, so we Resolve without imposing an
5998 Analyze_And_Resolve (Expr);
6000 if not Present (Get_Rep_Pragma
6001 (Etype (Expr), Name_Simple_Storage_Pool_Type))
6004 ("expression must be of a simple storage pool type", Expr);
6008 if not Denotes_Variable (Expr) then
6009 Error_Msg_N ("storage pool must be a variable", Expr);
6013 if Nkind (Expr) = N_Type_Conversion then
6014 T := Etype (Expression (Expr));
6019 -- The Stack_Bounded_Pool is used internally for implementing
6020 -- access types with a Storage_Size. Since it only work properly
6021 -- when used on one specific type, we need to check that it is not
6022 -- hijacked improperly:
6024 -- type T is access Integer;
6025 -- for T'Storage_Size use n;
6026 -- type Q is access Float;
6027 -- for Q'Storage_Size use T'Storage_Size; -- incorrect
6029 if RTE_Available (RE_Stack_Bounded_Pool)
6030 and then Base_Type (T) = RTE (RE_Stack_Bounded_Pool)
6032 Error_Msg_N ("non-shareable internal Pool", Expr);
6036 -- If the argument is a name that is not an entity name, then
6037 -- we construct a renaming operation to define an entity of
6038 -- type storage pool.
6040 if not Is_Entity_Name (Expr)
6041 and then Is_Object_Reference (Expr)
6043 Pool := Make_Temporary (Loc, 'P', Expr);
6046 Rnode : constant Node_Id :=
6047 Make_Object_Renaming_Declaration (Loc,
6048 Defining_Identifier => Pool,
6050 New_Occurrence_Of (Etype (Expr), Loc),
6054 -- If the attribute definition clause comes from an aspect
6055 -- clause, then insert the renaming before the associated
6056 -- entity's declaration, since the attribute clause has
6057 -- not yet been appended to the declaration list.
6059 if From_Aspect_Specification (N) then
6060 Insert_Before (Parent (Entity (N)), Rnode);
6062 Insert_Before (N, Rnode);
6066 Set_Associated_Storage_Pool (U_Ent, Pool);
6069 elsif Is_Entity_Name (Expr) then
6070 Pool := Entity (Expr);
6072 -- If pool is a renamed object, get original one. This can
6073 -- happen with an explicit renaming, and within instances.
6075 while Present (Renamed_Object (Pool))
6076 and then Is_Entity_Name (Renamed_Object (Pool))
6078 Pool := Entity (Renamed_Object (Pool));
6081 if Present (Renamed_Object (Pool))
6082 and then Nkind (Renamed_Object (Pool)) = N_Type_Conversion
6083 and then Is_Entity_Name (Expression (Renamed_Object (Pool)))
6085 Pool := Entity (Expression (Renamed_Object (Pool)));
6088 Set_Associated_Storage_Pool (U_Ent, Pool);
6090 elsif Nkind (Expr) = N_Type_Conversion
6091 and then Is_Entity_Name (Expression (Expr))
6092 and then Nkind (Original_Node (Expr)) = N_Attribute_Reference
6094 Pool := Entity (Expression (Expr));
6095 Set_Associated_Storage_Pool (U_Ent, Pool);
6098 Error_Msg_N ("incorrect reference to a Storage Pool", Expr);
6107 -- Storage_Size attribute definition clause
6109 when Attribute_Storage_Size => Storage_Size : declare
6110 Btype : constant Entity_Id := Base_Type (U_Ent);
6113 if Is_Task_Type (U_Ent) then
6115 -- Check obsolescent (but never obsolescent if from aspect)
6117 if not From_Aspect_Specification (N) then
6118 Check_Restriction (No_Obsolescent_Features, N);
6120 if Warn_On_Obsolescent_Feature then
6122 ("?j?storage size clause for task is an obsolescent "
6123 & "feature (RM J.9)", N);
6124 Error_Msg_N ("\?j?use Storage_Size pragma instead", N);
6131 if not Is_Access_Type (U_Ent)
6132 and then Ekind (U_Ent) /= E_Task_Type
6134 Error_Msg_N ("storage size cannot be given for &", Nam);
6136 elsif Is_Access_Type (U_Ent) and Is_Derived_Type (U_Ent) then
6138 ("storage size cannot be given for a derived access type",
6141 elsif Duplicate_Clause then
6145 Analyze_And_Resolve (Expr, Any_Integer);
6147 if Is_Access_Type (U_Ent) then
6149 -- Check for Storage_Pool previously given
6152 SP : constant Node_Id :=
6153 Get_Attribute_Definition_Clause
6154 (U_Ent, Attribute_Storage_Pool);
6157 if Present (SP) then
6158 Check_Pool_Size_Clash (U_Ent, SP, N);
6162 -- Special case of for x'Storage_Size use 0
6164 if Is_OK_Static_Expression (Expr)
6165 and then Expr_Value (Expr) = 0
6167 Set_No_Pool_Assigned (Btype);
6171 Set_Has_Storage_Size_Clause (Btype);
6179 when Attribute_Stream_Size => Stream_Size : declare
6180 Size : constant Uint := Static_Integer (Expr);
6183 if Ada_Version <= Ada_95 then
6184 Check_Restriction (No_Implementation_Attributes, N);
6187 if Duplicate_Clause then
6190 elsif Is_Elementary_Type (U_Ent) then
6192 -- The following errors are suppressed in ASIS mode to allow
6193 -- for different ASIS back ends or ASIS-based tools to query
6194 -- the illegal clause.
6199 elsif Size /= System_Storage_Unit
6200 and then Size /= System_Storage_Unit * 2
6201 and then Size /= System_Storage_Unit * 4
6202 and then Size /= System_Storage_Unit * 8
6204 Error_Msg_Uint_1 := UI_From_Int (System_Storage_Unit);
6206 ("stream size for elementary type must be a power of 2 "
6207 & "and at least ^", N);
6209 elsif RM_Size (U_Ent) > Size then
6210 Error_Msg_Uint_1 := RM_Size (U_Ent);
6212 ("stream size for elementary type must be a power of 2 "
6213 & "and at least ^", N);
6216 Set_Has_Stream_Size_Clause (U_Ent);
6219 Error_Msg_N ("Stream_Size cannot be given for &", Nam);
6227 -- Value_Size attribute definition clause
6229 when Attribute_Value_Size => Value_Size : declare
6230 Size : constant Uint := Static_Integer (Expr);
6234 if not Is_Type (U_Ent) then
6235 Error_Msg_N ("Value_Size cannot be given for &", Nam);
6237 elsif Duplicate_Clause then
6240 elsif Is_Array_Type (U_Ent)
6241 and then not Is_Constrained (U_Ent)
6244 ("Value_Size cannot be given for unconstrained array", Nam);
6247 if Is_Elementary_Type (U_Ent) then
6248 Check_Size (Expr, U_Ent, Size, Biased);
6249 Set_Biased (U_Ent, N, "value size clause", Biased);
6252 Set_RM_Size (U_Ent, Size);
6256 -----------------------
6257 -- Variable_Indexing --
6258 -----------------------
6260 when Attribute_Variable_Indexing =>
6261 Check_Indexing_Functions;
6267 when Attribute_Write =>
6268 Analyze_Stream_TSS_Definition (TSS_Stream_Write);
6269 Set_Has_Specified_Stream_Write (Ent);
6271 -- All other attributes cannot be set
6275 ("attribute& cannot be set with definition clause", N);
6278 -- The test for the type being frozen must be performed after any
6279 -- expression the clause has been analyzed since the expression itself
6280 -- might cause freezing that makes the clause illegal.
6282 if Rep_Item_Too_Late (U_Ent, N, FOnly) then
6285 end Analyze_Attribute_Definition_Clause;
6287 ----------------------------
6288 -- Analyze_Code_Statement --
6289 ----------------------------
6291 procedure Analyze_Code_Statement (N : Node_Id) is
6292 HSS : constant Node_Id := Parent (N);
6293 SBody : constant Node_Id := Parent (HSS);
6294 Subp : constant Entity_Id := Current_Scope;
6301 -- Accept foreign code statements for CodePeer. The analysis is skipped
6302 -- to avoid rejecting unrecognized constructs.
6304 if CodePeer_Mode then
6309 -- Analyze and check we get right type, note that this implements the
6310 -- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that is
6311 -- the only way that Asm_Insn could possibly be visible.
6313 Analyze_And_Resolve (Expression (N));
6315 if Etype (Expression (N)) = Any_Type then
6317 elsif Etype (Expression (N)) /= RTE (RE_Asm_Insn) then
6318 Error_Msg_N ("incorrect type for code statement", N);
6322 Check_Code_Statement (N);
6324 -- Make sure we appear in the handled statement sequence of a subprogram
6327 if Nkind (HSS) /= N_Handled_Sequence_Of_Statements
6328 or else Nkind (SBody) /= N_Subprogram_Body
6331 ("code statement can only appear in body of subprogram", N);
6335 -- Do remaining checks (RM 13.8(3)) if not already done
6337 if not Is_Machine_Code_Subprogram (Subp) then
6338 Set_Is_Machine_Code_Subprogram (Subp);
6340 -- No exception handlers allowed
6342 if Present (Exception_Handlers (HSS)) then
6344 ("exception handlers not permitted in machine code subprogram",
6345 First (Exception_Handlers (HSS)));
6348 -- No declarations other than use clauses and pragmas (we allow
6349 -- certain internally generated declarations as well).
6351 Decl := First (Declarations (SBody));
6352 while Present (Decl) loop
6353 DeclO := Original_Node (Decl);
6354 if Comes_From_Source (DeclO)
6355 and not Nkind_In (DeclO, N_Pragma,
6356 N_Use_Package_Clause,
6358 N_Implicit_Label_Declaration)
6361 ("this declaration not allowed in machine code subprogram",
6368 -- No statements other than code statements, pragmas, and labels.
6369 -- Again we allow certain internally generated statements.
6371 -- In Ada 2012, qualified expressions are names, and the code
6372 -- statement is initially parsed as a procedure call.
6374 Stmt := First (Statements (HSS));
6375 while Present (Stmt) loop
6376 StmtO := Original_Node (Stmt);
6378 -- A procedure call transformed into a code statement is OK
6380 if Ada_Version >= Ada_2012
6381 and then Nkind (StmtO) = N_Procedure_Call_Statement
6382 and then Nkind (Name (StmtO)) = N_Qualified_Expression
6386 elsif Comes_From_Source (StmtO)
6387 and then not Nkind_In (StmtO, N_Pragma,
6392 ("this statement is not allowed in machine code subprogram",
6399 end Analyze_Code_Statement;
6401 -----------------------------------------------
6402 -- Analyze_Enumeration_Representation_Clause --
6403 -----------------------------------------------
6405 procedure Analyze_Enumeration_Representation_Clause (N : Node_Id) is
6406 Ident : constant Node_Id := Identifier (N);
6407 Aggr : constant Node_Id := Array_Aggregate (N);
6408 Enumtype : Entity_Id;
6415 Err : Boolean := False;
6416 -- Set True to avoid cascade errors and crashes on incorrect source code
6418 Lo : constant Uint := Expr_Value (Type_Low_Bound (Universal_Integer));
6419 Hi : constant Uint := Expr_Value (Type_High_Bound (Universal_Integer));
6420 -- Allowed range of universal integer (= allowed range of enum lit vals)
6424 -- Minimum and maximum values of entries
6427 -- Pointer to node for literal providing max value
6430 if Ignore_Rep_Clauses then
6431 Kill_Rep_Clause (N);
6435 -- Ignore enumeration rep clauses by default in CodePeer mode,
6436 -- unless -gnatd.I is specified, as a work around for potential false
6437 -- positive messages.
6439 if CodePeer_Mode and not Debug_Flag_Dot_II then
6443 -- First some basic error checks
6446 Enumtype := Entity (Ident);
6448 if Enumtype = Any_Type
6449 or else Rep_Item_Too_Early (Enumtype, N)
6453 Enumtype := Underlying_Type (Enumtype);
6456 if not Is_Enumeration_Type (Enumtype) then
6458 ("enumeration type required, found}",
6459 Ident, First_Subtype (Enumtype));
6463 -- Ignore rep clause on generic actual type. This will already have
6464 -- been flagged on the template as an error, and this is the safest
6465 -- way to ensure we don't get a junk cascaded message in the instance.
6467 if Is_Generic_Actual_Type (Enumtype) then
6470 -- Type must be in current scope
6472 elsif Scope (Enumtype) /= Current_Scope then
6473 Error_Msg_N ("type must be declared in this scope", Ident);
6476 -- Type must be a first subtype
6478 elsif not Is_First_Subtype (Enumtype) then
6479 Error_Msg_N ("cannot give enumeration rep clause for subtype", N);
6482 -- Ignore duplicate rep clause
6484 elsif Has_Enumeration_Rep_Clause (Enumtype) then
6485 Error_Msg_N ("duplicate enumeration rep clause ignored", N);
6488 -- Don't allow rep clause for standard [wide_[wide_]]character
6490 elsif Is_Standard_Character_Type (Enumtype) then
6491 Error_Msg_N ("enumeration rep clause not allowed for this type", N);
6494 -- Check that the expression is a proper aggregate (no parentheses)
6496 elsif Paren_Count (Aggr) /= 0 then
6498 ("extra parentheses surrounding aggregate not allowed",
6502 -- All tests passed, so set rep clause in place
6505 Set_Has_Enumeration_Rep_Clause (Enumtype);
6506 Set_Has_Enumeration_Rep_Clause (Base_Type (Enumtype));
6509 -- Now we process the aggregate. Note that we don't use the normal
6510 -- aggregate code for this purpose, because we don't want any of the
6511 -- normal expansion activities, and a number of special semantic
6512 -- rules apply (including the component type being any integer type)
6514 Elit := First_Literal (Enumtype);
6516 -- First the positional entries if any
6518 if Present (Expressions (Aggr)) then
6519 Expr := First (Expressions (Aggr));
6520 while Present (Expr) loop
6522 Error_Msg_N ("too many entries in aggregate", Expr);
6526 Val := Static_Integer (Expr);
6528 -- Err signals that we found some incorrect entries processing
6529 -- the list. The final checks for completeness and ordering are
6530 -- skipped in this case.
6532 if Val = No_Uint then
6535 elsif Val < Lo or else Hi < Val then
6536 Error_Msg_N ("value outside permitted range", Expr);
6540 Set_Enumeration_Rep (Elit, Val);
6541 Set_Enumeration_Rep_Expr (Elit, Expr);
6547 -- Now process the named entries if present
6549 if Present (Component_Associations (Aggr)) then
6550 Assoc := First (Component_Associations (Aggr));
6551 while Present (Assoc) loop
6552 Choice := First (Choices (Assoc));
6554 if Present (Next (Choice)) then
6556 ("multiple choice not allowed here", Next (Choice));
6560 if Nkind (Choice) = N_Others_Choice then
6561 Error_Msg_N ("others choice not allowed here", Choice);
6564 elsif Nkind (Choice) = N_Range then
6566 -- ??? should allow zero/one element range here
6568 Error_Msg_N ("range not allowed here", Choice);
6572 Analyze_And_Resolve (Choice, Enumtype);
6574 if Error_Posted (Choice) then
6579 if Is_Entity_Name (Choice)
6580 and then Is_Type (Entity (Choice))
6582 Error_Msg_N ("subtype name not allowed here", Choice);
6585 -- ??? should allow static subtype with zero/one entry
6587 elsif Etype (Choice) = Base_Type (Enumtype) then
6588 if not Is_OK_Static_Expression (Choice) then
6589 Flag_Non_Static_Expr
6590 ("non-static expression used for choice!", Choice);
6594 Elit := Expr_Value_E (Choice);
6596 if Present (Enumeration_Rep_Expr (Elit)) then
6598 Sloc (Enumeration_Rep_Expr (Elit));
6600 ("representation for& previously given#",
6605 Set_Enumeration_Rep_Expr (Elit, Expression (Assoc));
6607 Expr := Expression (Assoc);
6608 Val := Static_Integer (Expr);
6610 if Val = No_Uint then
6613 elsif Val < Lo or else Hi < Val then
6614 Error_Msg_N ("value outside permitted range", Expr);
6618 Set_Enumeration_Rep (Elit, Val);
6628 -- Aggregate is fully processed. Now we check that a full set of
6629 -- representations was given, and that they are in range and in order.
6630 -- These checks are only done if no other errors occurred.
6636 Elit := First_Literal (Enumtype);
6637 while Present (Elit) loop
6638 if No (Enumeration_Rep_Expr (Elit)) then
6639 Error_Msg_NE ("missing representation for&!", N, Elit);
6642 Val := Enumeration_Rep (Elit);
6644 if Min = No_Uint then
6648 if Val /= No_Uint then
6649 if Max /= No_Uint and then Val <= Max then
6651 ("enumeration value for& not ordered!",
6652 Enumeration_Rep_Expr (Elit), Elit);
6655 Max_Node := Enumeration_Rep_Expr (Elit);
6659 -- If there is at least one literal whose representation is not
6660 -- equal to the Pos value, then note that this enumeration type
6661 -- has a non-standard representation.
6663 if Val /= Enumeration_Pos (Elit) then
6664 Set_Has_Non_Standard_Rep (Base_Type (Enumtype));
6671 -- Now set proper size information
6674 Minsize : Uint := UI_From_Int (Minimum_Size (Enumtype));
6677 if Has_Size_Clause (Enumtype) then
6679 -- All OK, if size is OK now
6681 if RM_Size (Enumtype) >= Minsize then
6685 -- Try if we can get by with biasing
6688 UI_From_Int (Minimum_Size (Enumtype, Biased => True));
6690 -- Error message if even biasing does not work
6692 if RM_Size (Enumtype) < Minsize then
6693 Error_Msg_Uint_1 := RM_Size (Enumtype);
6694 Error_Msg_Uint_2 := Max;
6696 ("previously given size (^) is too small "
6697 & "for this value (^)", Max_Node);
6699 -- If biasing worked, indicate that we now have biased rep
6703 (Enumtype, Size_Clause (Enumtype), "size clause");
6708 Set_RM_Size (Enumtype, Minsize);
6709 Set_Enum_Esize (Enumtype);
6712 Set_RM_Size (Base_Type (Enumtype), RM_Size (Enumtype));
6713 Set_Esize (Base_Type (Enumtype), Esize (Enumtype));
6714 Set_Alignment (Base_Type (Enumtype), Alignment (Enumtype));
6718 -- We repeat the too late test in case it froze itself
6720 if Rep_Item_Too_Late (Enumtype, N) then
6723 end Analyze_Enumeration_Representation_Clause;
6725 ----------------------------
6726 -- Analyze_Free_Statement --
6727 ----------------------------
6729 procedure Analyze_Free_Statement (N : Node_Id) is
6731 Analyze (Expression (N));
6732 end Analyze_Free_Statement;
6734 ---------------------------
6735 -- Analyze_Freeze_Entity --
6736 ---------------------------
6738 procedure Analyze_Freeze_Entity (N : Node_Id) is
6740 Freeze_Entity_Checks (N);
6741 end Analyze_Freeze_Entity;
6743 -----------------------------------
6744 -- Analyze_Freeze_Generic_Entity --
6745 -----------------------------------
6747 procedure Analyze_Freeze_Generic_Entity (N : Node_Id) is
6748 E : constant Entity_Id := Entity (N);
6751 if not Is_Frozen (E) and then Has_Delayed_Aspects (E) then
6752 Analyze_Aspects_At_Freeze_Point (E);
6755 Freeze_Entity_Checks (N);
6756 end Analyze_Freeze_Generic_Entity;
6758 ------------------------------------------
6759 -- Analyze_Record_Representation_Clause --
6760 ------------------------------------------
6762 -- Note: we check as much as we can here, but we can't do any checks
6763 -- based on the position values (e.g. overlap checks) until freeze time
6764 -- because especially in Ada 2005 (machine scalar mode), the processing
6765 -- for non-standard bit order can substantially change the positions.
6766 -- See procedure Check_Record_Representation_Clause (called from Freeze)
6767 -- for the remainder of this processing.
6769 procedure Analyze_Record_Representation_Clause (N : Node_Id) is
6770 Ident : constant Node_Id := Identifier (N);
6775 Hbit : Uint := Uint_0;
6779 Rectype : Entity_Id;
6782 function Is_Inherited (Comp : Entity_Id) return Boolean;
6783 -- True if Comp is an inherited component in a record extension
6789 function Is_Inherited (Comp : Entity_Id) return Boolean is
6790 Comp_Base : Entity_Id;
6793 if Ekind (Rectype) = E_Record_Subtype then
6794 Comp_Base := Original_Record_Component (Comp);
6799 return Comp_Base /= Original_Record_Component (Comp_Base);
6804 Is_Record_Extension : Boolean;
6805 -- True if Rectype is a record extension
6807 CR_Pragma : Node_Id := Empty;
6808 -- Points to N_Pragma node if Complete_Representation pragma present
6810 -- Start of processing for Analyze_Record_Representation_Clause
6813 if Ignore_Rep_Clauses then
6814 Kill_Rep_Clause (N);
6819 Rectype := Entity (Ident);
6821 if Rectype = Any_Type or else Rep_Item_Too_Early (Rectype, N) then
6824 Rectype := Underlying_Type (Rectype);
6827 -- First some basic error checks
6829 if not Is_Record_Type (Rectype) then
6831 ("record type required, found}", Ident, First_Subtype (Rectype));
6834 elsif Scope (Rectype) /= Current_Scope then
6835 Error_Msg_N ("type must be declared in this scope", N);
6838 elsif not Is_First_Subtype (Rectype) then
6839 Error_Msg_N ("cannot give record rep clause for subtype", N);
6842 elsif Has_Record_Rep_Clause (Rectype) then
6843 Error_Msg_N ("duplicate record rep clause ignored", N);
6846 elsif Rep_Item_Too_Late (Rectype, N) then
6850 -- We know we have a first subtype, now possibly go to the anonymous
6851 -- base type to determine whether Rectype is a record extension.
6853 Recdef := Type_Definition (Declaration_Node (Base_Type (Rectype)));
6854 Is_Record_Extension :=
6855 Nkind (Recdef) = N_Derived_Type_Definition
6856 and then Present (Record_Extension_Part (Recdef));
6858 if Present (Mod_Clause (N)) then
6860 Loc : constant Source_Ptr := Sloc (N);
6861 M : constant Node_Id := Mod_Clause (N);
6862 P : constant List_Id := Pragmas_Before (M);
6866 pragma Warnings (Off, Mod_Val);
6869 Check_Restriction (No_Obsolescent_Features, Mod_Clause (N));
6871 if Warn_On_Obsolescent_Feature then
6873 ("?j?mod clause is an obsolescent feature (RM J.8)", N);
6875 ("\?j?use alignment attribute definition clause instead", N);
6882 -- In ASIS_Mode mode, expansion is disabled, but we must convert
6883 -- the Mod clause into an alignment clause anyway, so that the
6884 -- back end can compute and back-annotate properly the size and
6885 -- alignment of types that may include this record.
6887 -- This seems dubious, this destroys the source tree in a manner
6888 -- not detectable by ASIS ???
6890 if Operating_Mode = Check_Semantics and then ASIS_Mode then
6892 Make_Attribute_Definition_Clause (Loc,
6893 Name => New_Occurrence_Of (Base_Type (Rectype), Loc),
6894 Chars => Name_Alignment,
6895 Expression => Relocate_Node (Expression (M)));
6897 Set_From_At_Mod (AtM_Nod);
6898 Insert_After (N, AtM_Nod);
6899 Mod_Val := Get_Alignment_Value (Expression (AtM_Nod));
6900 Set_Mod_Clause (N, Empty);
6903 -- Get the alignment value to perform error checking
6905 Mod_Val := Get_Alignment_Value (Expression (M));
6910 -- For untagged types, clear any existing component clauses for the
6911 -- type. If the type is derived, this is what allows us to override
6912 -- a rep clause for the parent. For type extensions, the representation
6913 -- of the inherited components is inherited, so we want to keep previous
6914 -- component clauses for completeness.
6916 if not Is_Tagged_Type (Rectype) then
6917 Comp := First_Component_Or_Discriminant (Rectype);
6918 while Present (Comp) loop
6919 Set_Component_Clause (Comp, Empty);
6920 Next_Component_Or_Discriminant (Comp);
6924 -- All done if no component clauses
6926 CC := First (Component_Clauses (N));
6932 -- A representation like this applies to the base type
6934 Set_Has_Record_Rep_Clause (Base_Type (Rectype));
6935 Set_Has_Non_Standard_Rep (Base_Type (Rectype));
6936 Set_Has_Specified_Layout (Base_Type (Rectype));
6938 -- Process the component clauses
6940 while Present (CC) loop
6944 if Nkind (CC) = N_Pragma then
6947 -- The only pragma of interest is Complete_Representation
6949 if Pragma_Name (CC) = Name_Complete_Representation then
6953 -- Processing for real component clause
6956 Posit := Static_Integer (Position (CC));
6957 Fbit := Static_Integer (First_Bit (CC));
6958 Lbit := Static_Integer (Last_Bit (CC));
6961 and then Fbit /= No_Uint
6962 and then Lbit /= No_Uint
6965 Error_Msg_N ("position cannot be negative", Position (CC));
6968 Error_Msg_N ("first bit cannot be negative", First_Bit (CC));
6970 -- The Last_Bit specified in a component clause must not be
6971 -- less than the First_Bit minus one (RM-13.5.1(10)).
6973 elsif Lbit < Fbit - 1 then
6975 ("last bit cannot be less than first bit minus one",
6978 -- Values look OK, so find the corresponding record component
6979 -- Even though the syntax allows an attribute reference for
6980 -- implementation-defined components, GNAT does not allow the
6981 -- tag to get an explicit position.
6983 elsif Nkind (Component_Name (CC)) = N_Attribute_Reference then
6984 if Attribute_Name (Component_Name (CC)) = Name_Tag then
6985 Error_Msg_N ("position of tag cannot be specified", CC);
6987 Error_Msg_N ("illegal component name", CC);
6991 Comp := First_Entity (Rectype);
6992 while Present (Comp) loop
6993 exit when Chars (Comp) = Chars (Component_Name (CC));
6999 -- Maybe component of base type that is absent from
7000 -- statically constrained first subtype.
7002 Comp := First_Entity (Base_Type (Rectype));
7003 while Present (Comp) loop
7004 exit when Chars (Comp) = Chars (Component_Name (CC));
7011 ("component clause is for non-existent field", CC);
7013 -- Ada 2012 (AI05-0026): Any name that denotes a
7014 -- discriminant of an object of an unchecked union type
7015 -- shall not occur within a record_representation_clause.
7017 -- The general restriction of using record rep clauses on
7018 -- Unchecked_Union types has now been lifted. Since it is
7019 -- possible to introduce a record rep clause which mentions
7020 -- the discriminant of an Unchecked_Union in non-Ada 2012
7021 -- code, this check is applied to all versions of the
7024 elsif Ekind (Comp) = E_Discriminant
7025 and then Is_Unchecked_Union (Rectype)
7028 ("cannot reference discriminant of unchecked union",
7029 Component_Name (CC));
7031 elsif Is_Record_Extension and then Is_Inherited (Comp) then
7033 ("component clause not allowed for inherited "
7034 & "component&", CC, Comp);
7036 elsif Present (Component_Clause (Comp)) then
7038 -- Diagnose duplicate rep clause, or check consistency
7039 -- if this is an inherited component. In a double fault,
7040 -- there may be a duplicate inconsistent clause for an
7041 -- inherited component.
7043 if Scope (Original_Record_Component (Comp)) = Rectype
7044 or else Parent (Component_Clause (Comp)) = N
7046 Error_Msg_Sloc := Sloc (Component_Clause (Comp));
7047 Error_Msg_N ("component clause previously given#", CC);
7051 Rep1 : constant Node_Id := Component_Clause (Comp);
7053 if Intval (Position (Rep1)) /=
7054 Intval (Position (CC))
7055 or else Intval (First_Bit (Rep1)) /=
7056 Intval (First_Bit (CC))
7057 or else Intval (Last_Bit (Rep1)) /=
7058 Intval (Last_Bit (CC))
7061 ("component clause inconsistent with "
7062 & "representation of ancestor", CC);
7064 elsif Warn_On_Redundant_Constructs then
7066 ("?r?redundant confirming component clause "
7067 & "for component!", CC);
7072 -- Normal case where this is the first component clause we
7073 -- have seen for this entity, so set it up properly.
7076 -- Make reference for field in record rep clause and set
7077 -- appropriate entity field in the field identifier.
7080 (Comp, Component_Name (CC), Set_Ref => False);
7081 Set_Entity (Component_Name (CC), Comp);
7083 -- Update Fbit and Lbit to the actual bit number
7085 Fbit := Fbit + UI_From_Int (SSU) * Posit;
7086 Lbit := Lbit + UI_From_Int (SSU) * Posit;
7088 if Has_Size_Clause (Rectype)
7089 and then RM_Size (Rectype) <= Lbit
7092 ("bit number out of range of specified size",
7095 Set_Component_Clause (Comp, CC);
7096 Set_Component_Bit_Offset (Comp, Fbit);
7097 Set_Esize (Comp, 1 + (Lbit - Fbit));
7098 Set_Normalized_First_Bit (Comp, Fbit mod SSU);
7099 Set_Normalized_Position (Comp, Fbit / SSU);
7101 if Warn_On_Overridden_Size
7102 and then Has_Size_Clause (Etype (Comp))
7103 and then RM_Size (Etype (Comp)) /= Esize (Comp)
7106 ("?S?component size overrides size clause for&",
7107 Component_Name (CC), Etype (Comp));
7110 -- This information is also set in the corresponding
7111 -- component of the base type, found by accessing the
7112 -- Original_Record_Component link if it is present.
7114 Ocomp := Original_Record_Component (Comp);
7121 (Component_Name (CC),
7127 (Comp, First_Node (CC), "component clause", Biased);
7129 if Present (Ocomp) then
7130 Set_Component_Clause (Ocomp, CC);
7131 Set_Component_Bit_Offset (Ocomp, Fbit);
7132 Set_Normalized_First_Bit (Ocomp, Fbit mod SSU);
7133 Set_Normalized_Position (Ocomp, Fbit / SSU);
7134 Set_Esize (Ocomp, 1 + (Lbit - Fbit));
7136 Set_Normalized_Position_Max
7137 (Ocomp, Normalized_Position (Ocomp));
7139 -- Note: we don't use Set_Biased here, because we
7140 -- already gave a warning above if needed, and we
7141 -- would get a duplicate for the same name here.
7143 Set_Has_Biased_Representation
7144 (Ocomp, Has_Biased_Representation (Comp));
7147 if Esize (Comp) < 0 then
7148 Error_Msg_N ("component size is negative", CC);
7159 -- Check missing components if Complete_Representation pragma appeared
7161 if Present (CR_Pragma) then
7162 Comp := First_Component_Or_Discriminant (Rectype);
7163 while Present (Comp) loop
7164 if No (Component_Clause (Comp)) then
7166 ("missing component clause for &", CR_Pragma, Comp);
7169 Next_Component_Or_Discriminant (Comp);
7172 -- Give missing components warning if required
7174 elsif Warn_On_Unrepped_Components then
7176 Num_Repped_Components : Nat := 0;
7177 Num_Unrepped_Components : Nat := 0;
7180 -- First count number of repped and unrepped components
7182 Comp := First_Component_Or_Discriminant (Rectype);
7183 while Present (Comp) loop
7184 if Present (Component_Clause (Comp)) then
7185 Num_Repped_Components := Num_Repped_Components + 1;
7187 Num_Unrepped_Components := Num_Unrepped_Components + 1;
7190 Next_Component_Or_Discriminant (Comp);
7193 -- We are only interested in the case where there is at least one
7194 -- unrepped component, and at least half the components have rep
7195 -- clauses. We figure that if less than half have them, then the
7196 -- partial rep clause is really intentional. If the component
7197 -- type has no underlying type set at this point (as for a generic
7198 -- formal type), we don't know enough to give a warning on the
7201 if Num_Unrepped_Components > 0
7202 and then Num_Unrepped_Components < Num_Repped_Components
7204 Comp := First_Component_Or_Discriminant (Rectype);
7205 while Present (Comp) loop
7206 if No (Component_Clause (Comp))
7207 and then Comes_From_Source (Comp)
7208 and then Present (Underlying_Type (Etype (Comp)))
7209 and then (Is_Scalar_Type (Underlying_Type (Etype (Comp)))
7210 or else Size_Known_At_Compile_Time
7211 (Underlying_Type (Etype (Comp))))
7212 and then not Has_Warnings_Off (Rectype)
7214 -- Ignore discriminant in unchecked union, since it is
7215 -- not there, and cannot have a component clause.
7217 and then (not Is_Unchecked_Union (Rectype)
7218 or else Ekind (Comp) /= E_Discriminant)
7220 Error_Msg_Sloc := Sloc (Comp);
7222 ("?C?no component clause given for & declared #",
7226 Next_Component_Or_Discriminant (Comp);
7231 end Analyze_Record_Representation_Clause;
7233 -------------------------------------
7234 -- Build_Discrete_Static_Predicate --
7235 -------------------------------------
7237 procedure Build_Discrete_Static_Predicate
7242 Loc : constant Source_Ptr := Sloc (Expr);
7244 Non_Static : exception;
7245 -- Raised if something non-static is found
7247 Btyp : constant Entity_Id := Base_Type (Typ);
7249 BLo : constant Uint := Expr_Value (Type_Low_Bound (Btyp));
7250 BHi : constant Uint := Expr_Value (Type_High_Bound (Btyp));
7251 -- Low bound and high bound value of base type of Typ
7255 -- Bounds for constructing the static predicate. We use the bound of the
7256 -- subtype if it is static, otherwise the corresponding base type bound.
7257 -- Note: a non-static subtype can have a static predicate.
7262 -- One entry in a Rlist value, a single REnt (range entry) value denotes
7263 -- one range from Lo to Hi. To represent a single value range Lo = Hi =
7266 type RList is array (Nat range <>) of REnt;
7267 -- A list of ranges. The ranges are sorted in increasing order, and are
7268 -- disjoint (there is a gap of at least one value between each range in
7269 -- the table). A value is in the set of ranges in Rlist if it lies
7270 -- within one of these ranges.
7272 False_Range : constant RList :=
7273 RList'(1 .. 0 => REnt'(No_Uint, No_Uint));
7274 -- An empty set of ranges represents a range list that can never be
7275 -- satisfied, since there are no ranges in which the value could lie,
7276 -- so it does not lie in any of them. False_Range is a canonical value
7277 -- for this empty set, but general processing should test for an Rlist
7278 -- with length zero (see Is_False predicate), since other null ranges
7279 -- may appear which must be treated as False.
7281 True_Range : constant RList := RList'(1 => REnt'(BLo, BHi));
7282 -- Range representing True, value must be in the base range
7284 function "and" (Left : RList; Right : RList) return RList;
7285 -- And's together two range lists, returning a range list. This is a set
7286 -- intersection operation.
7288 function "or" (Left : RList; Right : RList) return RList;
7289 -- Or's together two range lists, returning a range list. This is a set
7292 function "not" (Right : RList) return RList;
7293 -- Returns complement of a given range list, i.e. a range list
7294 -- representing all the values in TLo .. THi that are not in the input
7297 function Build_Val (V : Uint) return Node_Id;
7298 -- Return an analyzed N_Identifier node referencing this value, suitable
7299 -- for use as an entry in the Static_Discrte_Predicate list. This node
7300 -- is typed with the base type.
7302 function Build_Range (Lo : Uint; Hi : Uint) return Node_Id;
7303 -- Return an analyzed N_Range node referencing this range, suitable for
7304 -- use as an entry in the Static_Discrete_Predicate list. This node is
7305 -- typed with the base type.
7307 function Get_RList (Exp : Node_Id) return RList;
7308 -- This is a recursive routine that converts the given expression into a
7309 -- list of ranges, suitable for use in building the static predicate.
7311 function Is_False (R : RList) return Boolean;
7312 pragma Inline (Is_False);
7313 -- Returns True if the given range list is empty, and thus represents a
7314 -- False list of ranges that can never be satisfied.
7316 function Is_True (R : RList) return Boolean;
7317 -- Returns True if R trivially represents the True predicate by having a
7318 -- single range from BLo to BHi.
7320 function Is_Type_Ref (N : Node_Id) return Boolean;
7321 pragma Inline (Is_Type_Ref);
7322 -- Returns if True if N is a reference to the type for the predicate in
7323 -- the expression (i.e. if it is an identifier whose Chars field matches
7324 -- the Nam given in the call). N must not be parenthesized, if the type
7325 -- name appears in parens, this routine will return False.
7327 function Lo_Val (N : Node_Id) return Uint;
7328 -- Given an entry from a Static_Discrete_Predicate list that is either
7329 -- a static expression or static range, gets either the expression value
7330 -- or the low bound of the range.
7332 function Hi_Val (N : Node_Id) return Uint;
7333 -- Given an entry from a Static_Discrete_Predicate list that is either
7334 -- a static expression or static range, gets either the expression value
7335 -- or the high bound of the range.
7337 function Membership_Entry (N : Node_Id) return RList;
7338 -- Given a single membership entry (range, value, or subtype), returns
7339 -- the corresponding range list. Raises Static_Error if not static.
7341 function Membership_Entries (N : Node_Id) return RList;
7342 -- Given an element on an alternatives list of a membership operation,
7343 -- returns the range list corresponding to this entry and all following
7344 -- entries (i.e. returns the "or" of this list of values).
7346 function Stat_Pred (Typ : Entity_Id) return RList;
7347 -- Given a type, if it has a static predicate, then return the predicate
7348 -- as a range list, otherwise raise Non_Static.
7354 function "and" (Left : RList; Right : RList) return RList is
7356 -- First range of result
7358 SLeft : Nat := Left'First;
7359 -- Start of rest of left entries
7361 SRight : Nat := Right'First;
7362 -- Start of rest of right entries
7365 -- If either range is True, return the other
7367 if Is_True (Left) then
7369 elsif Is_True (Right) then
7373 -- If either range is False, return False
7375 if Is_False (Left) or else Is_False (Right) then
7379 -- Loop to remove entries at start that are disjoint, and thus just
7380 -- get discarded from the result entirely.
7383 -- If no operands left in either operand, result is false
7385 if SLeft > Left'Last or else SRight > Right'Last then
7388 -- Discard first left operand entry if disjoint with right
7390 elsif Left (SLeft).Hi < Right (SRight).Lo then
7393 -- Discard first right operand entry if disjoint with left
7395 elsif Right (SRight).Hi < Left (SLeft).Lo then
7396 SRight := SRight + 1;
7398 -- Otherwise we have an overlapping entry
7405 -- Now we have two non-null operands, and first entries overlap. The
7406 -- first entry in the result will be the overlapping part of these
7409 FEnt := REnt'(Lo => UI_Max (Left (SLeft).Lo, Right (SRight).Lo),
7410 Hi => UI_Min (Left (SLeft).Hi, Right (SRight).Hi));
7412 -- Now we can remove the entry that ended at a lower value, since its
7413 -- contribution is entirely contained in Fent.
7415 if Left (SLeft).Hi <= Right (SRight).Hi then
7418 SRight := SRight + 1;
7421 -- Compute result by concatenating this first entry with the "and" of
7422 -- the remaining parts of the left and right operands. Note that if
7423 -- either of these is empty, "and" will yield empty, so that we will
7424 -- end up with just Fent, which is what we want in that case.
7427 FEnt & (Left (SLeft .. Left'Last) and Right (SRight .. Right'Last));
7434 function "not" (Right : RList) return RList is
7436 -- Return True if False range
7438 if Is_False (Right) then
7442 -- Return False if True range
7444 if Is_True (Right) then
7448 -- Here if not trivial case
7451 Result : RList (1 .. Right'Length + 1);
7452 -- May need one more entry for gap at beginning and end
7455 -- Number of entries stored in Result
7460 if Right (Right'First).Lo > TLo then
7462 Result (Count) := REnt'(TLo, Right (Right'First).Lo - 1);
7465 -- Gaps between ranges
7467 for J in Right'First .. Right'Last - 1 loop
7469 Result (Count) := REnt'(Right (J).Hi + 1, Right (J + 1).Lo - 1);
7474 if Right (Right'Last).Hi < THi then
7476 Result (Count) := REnt'(Right (Right'Last).Hi + 1, THi);
7479 return Result (1 .. Count);
7487 function "or" (Left : RList; Right : RList) return RList is
7489 -- First range of result
7491 SLeft : Nat := Left'First;
7492 -- Start of rest of left entries
7494 SRight : Nat := Right'First;
7495 -- Start of rest of right entries
7498 -- If either range is True, return True
7500 if Is_True (Left) or else Is_True (Right) then
7504 -- If either range is False (empty), return the other
7506 if Is_False (Left) then
7508 elsif Is_False (Right) then
7512 -- Initialize result first entry from left or right operand depending
7513 -- on which starts with the lower range.
7515 if Left (SLeft).Lo < Right (SRight).Lo then
7516 FEnt := Left (SLeft);
7519 FEnt := Right (SRight);
7520 SRight := SRight + 1;
7523 -- This loop eats ranges from left and right operands that are
7524 -- contiguous with the first range we are gathering.
7527 -- Eat first entry in left operand if contiguous or overlapped by
7528 -- gathered first operand of result.
7530 if SLeft <= Left'Last
7531 and then Left (SLeft).Lo <= FEnt.Hi + 1
7533 FEnt.Hi := UI_Max (FEnt.Hi, Left (SLeft).Hi);
7536 -- Eat first entry in right operand if contiguous or overlapped by
7537 -- gathered right operand of result.
7539 elsif SRight <= Right'Last
7540 and then Right (SRight).Lo <= FEnt.Hi + 1
7542 FEnt.Hi := UI_Max (FEnt.Hi, Right (SRight).Hi);
7543 SRight := SRight + 1;
7545 -- All done if no more entries to eat
7552 -- Obtain result as the first entry we just computed, concatenated
7553 -- to the "or" of the remaining results (if one operand is empty,
7554 -- this will just concatenate with the other
7557 FEnt & (Left (SLeft .. Left'Last) or Right (SRight .. Right'Last));
7564 function Build_Range (Lo : Uint; Hi : Uint) return Node_Id is
7569 Low_Bound => Build_Val (Lo),
7570 High_Bound => Build_Val (Hi));
7571 Set_Etype (Result, Btyp);
7572 Set_Analyzed (Result);
7580 function Build_Val (V : Uint) return Node_Id is
7584 if Is_Enumeration_Type (Typ) then
7585 Result := Get_Enum_Lit_From_Pos (Typ, V, Loc);
7587 Result := Make_Integer_Literal (Loc, V);
7590 Set_Etype (Result, Btyp);
7591 Set_Is_Static_Expression (Result);
7592 Set_Analyzed (Result);
7600 function Get_RList (Exp : Node_Id) return RList is
7605 -- Static expression can only be true or false
7607 if Is_OK_Static_Expression (Exp) then
7608 if Expr_Value (Exp) = 0 then
7615 -- Otherwise test node type
7626 return Get_RList (Left_Opnd (Exp))
7628 Get_RList (Right_Opnd (Exp));
7635 return Get_RList (Left_Opnd (Exp))
7637 Get_RList (Right_Opnd (Exp));
7642 return not Get_RList (Right_Opnd (Exp));
7644 -- Comparisons of type with static value
7646 when N_Op_Compare =>
7648 -- Type is left operand
7650 if Is_Type_Ref (Left_Opnd (Exp))
7651 and then Is_OK_Static_Expression (Right_Opnd (Exp))
7653 Val := Expr_Value (Right_Opnd (Exp));
7655 -- Typ is right operand
7657 elsif Is_Type_Ref (Right_Opnd (Exp))
7658 and then Is_OK_Static_Expression (Left_Opnd (Exp))
7660 Val := Expr_Value (Left_Opnd (Exp));
7662 -- Invert sense of comparison
7665 when N_Op_Gt => Op := N_Op_Lt;
7666 when N_Op_Lt => Op := N_Op_Gt;
7667 when N_Op_Ge => Op := N_Op_Le;
7668 when N_Op_Le => Op := N_Op_Ge;
7669 when others => null;
7672 -- Other cases are non-static
7678 -- Construct range according to comparison operation
7682 return RList'(1 => REnt'(Val, Val));
7685 return RList'(1 => REnt'(Val, BHi));
7688 return RList'(1 => REnt'(Val + 1, BHi));
7691 return RList'(1 => REnt'(BLo, Val));
7694 return RList'(1 => REnt'(BLo, Val - 1));
7697 return RList'(REnt'(BLo, Val - 1), REnt'(Val + 1, BHi));
7700 raise Program_Error;
7706 if not Is_Type_Ref (Left_Opnd (Exp)) then
7710 if Present (Right_Opnd (Exp)) then
7711 return Membership_Entry (Right_Opnd (Exp));
7713 return Membership_Entries (First (Alternatives (Exp)));
7716 -- Negative membership (NOT IN)
7719 if not Is_Type_Ref (Left_Opnd (Exp)) then
7723 if Present (Right_Opnd (Exp)) then
7724 return not Membership_Entry (Right_Opnd (Exp));
7726 return not Membership_Entries (First (Alternatives (Exp)));
7729 -- Function call, may be call to static predicate
7731 when N_Function_Call =>
7732 if Is_Entity_Name (Name (Exp)) then
7734 Ent : constant Entity_Id := Entity (Name (Exp));
7736 if Is_Predicate_Function (Ent)
7738 Is_Predicate_Function_M (Ent)
7740 return Stat_Pred (Etype (First_Formal (Ent)));
7745 -- Other function call cases are non-static
7749 -- Qualified expression, dig out the expression
7751 when N_Qualified_Expression =>
7752 return Get_RList (Expression (Exp));
7754 when N_Case_Expression =>
7761 if not Is_Entity_Name (Expression (Expr))
7762 or else Etype (Expression (Expr)) /= Typ
7765 ("expression must denaote subtype", Expression (Expr));
7769 -- Collect discrete choices in all True alternatives
7771 Choices := New_List;
7772 Alt := First (Alternatives (Exp));
7773 while Present (Alt) loop
7774 Dep := Expression (Alt);
7776 if not Is_OK_Static_Expression (Dep) then
7779 elsif Is_True (Expr_Value (Dep)) then
7780 Append_List_To (Choices,
7781 New_Copy_List (Discrete_Choices (Alt)));
7787 return Membership_Entries (First (Choices));
7790 -- Expression with actions: if no actions, dig out expression
7792 when N_Expression_With_Actions =>
7793 if Is_Empty_List (Actions (Exp)) then
7794 return Get_RList (Expression (Exp));
7802 return (Get_RList (Left_Opnd (Exp))
7803 and not Get_RList (Right_Opnd (Exp)))
7804 or (Get_RList (Right_Opnd (Exp))
7805 and not Get_RList (Left_Opnd (Exp)));
7807 -- Any other node type is non-static
7818 function Hi_Val (N : Node_Id) return Uint is
7820 if Is_OK_Static_Expression (N) then
7821 return Expr_Value (N);
7823 pragma Assert (Nkind (N) = N_Range);
7824 return Expr_Value (High_Bound (N));
7832 function Is_False (R : RList) return Boolean is
7834 return R'Length = 0;
7841 function Is_True (R : RList) return Boolean is
7844 and then R (R'First).Lo = BLo
7845 and then R (R'First).Hi = BHi;
7852 function Is_Type_Ref (N : Node_Id) return Boolean is
7854 return Nkind (N) = N_Identifier
7855 and then Chars (N) = Nam
7856 and then Paren_Count (N) = 0;
7863 function Lo_Val (N : Node_Id) return Uint is
7865 if Is_OK_Static_Expression (N) then
7866 return Expr_Value (N);
7868 pragma Assert (Nkind (N) = N_Range);
7869 return Expr_Value (Low_Bound (N));
7873 ------------------------
7874 -- Membership_Entries --
7875 ------------------------
7877 function Membership_Entries (N : Node_Id) return RList is
7879 if No (Next (N)) then
7880 return Membership_Entry (N);
7882 return Membership_Entry (N) or Membership_Entries (Next (N));
7884 end Membership_Entries;
7886 ----------------------
7887 -- Membership_Entry --
7888 ----------------------
7890 function Membership_Entry (N : Node_Id) return RList is
7898 if Nkind (N) = N_Range then
7899 if not Is_OK_Static_Expression (Low_Bound (N))
7901 not Is_OK_Static_Expression (High_Bound (N))
7905 SLo := Expr_Value (Low_Bound (N));
7906 SHi := Expr_Value (High_Bound (N));
7907 return RList'(1 => REnt'(SLo, SHi));
7910 -- Static expression case
7912 elsif Is_OK_Static_Expression (N) then
7913 Val := Expr_Value (N);
7914 return RList'(1 => REnt'(Val, Val));
7916 -- Identifier (other than static expression) case
7918 else pragma Assert (Nkind (N) = N_Identifier);
7922 if Is_Type (Entity (N)) then
7924 -- If type has predicates, process them
7926 if Has_Predicates (Entity (N)) then
7927 return Stat_Pred (Entity (N));
7929 -- For static subtype without predicates, get range
7931 elsif Is_OK_Static_Subtype (Entity (N)) then
7932 SLo := Expr_Value (Type_Low_Bound (Entity (N)));
7933 SHi := Expr_Value (Type_High_Bound (Entity (N)));
7934 return RList'(1 => REnt'(SLo, SHi));
7936 -- Any other type makes us non-static
7942 -- Any other kind of identifier in predicate (e.g. a non-static
7943 -- expression value) means this is not a static predicate.
7949 end Membership_Entry;
7955 function Stat_Pred (Typ : Entity_Id) return RList is
7957 -- Not static if type does not have static predicates
7959 if not Has_Static_Predicate (Typ) then
7963 -- Otherwise we convert the predicate list to a range list
7966 Spred : constant List_Id := Static_Discrete_Predicate (Typ);
7967 Result : RList (1 .. List_Length (Spred));
7971 P := First (Static_Discrete_Predicate (Typ));
7972 for J in Result'Range loop
7973 Result (J) := REnt'(Lo_Val (P), Hi_Val (P));
7981 -- Start of processing for Build_Discrete_Static_Predicate
7984 -- Establish bounds for the predicate
7986 if Compile_Time_Known_Value (Type_Low_Bound (Typ)) then
7987 TLo := Expr_Value (Type_Low_Bound (Typ));
7992 if Compile_Time_Known_Value (Type_High_Bound (Typ)) then
7993 THi := Expr_Value (Type_High_Bound (Typ));
7998 -- Analyze the expression to see if it is a static predicate
8001 Ranges : constant RList := Get_RList (Expr);
8002 -- Range list from expression if it is static
8007 -- Convert range list into a form for the static predicate. In the
8008 -- Ranges array, we just have raw ranges, these must be converted
8009 -- to properly typed and analyzed static expressions or range nodes.
8011 -- Note: here we limit ranges to the ranges of the subtype, so that
8012 -- a predicate is always false for values outside the subtype. That
8013 -- seems fine, such values are invalid anyway, and considering them
8014 -- to fail the predicate seems allowed and friendly, and furthermore
8015 -- simplifies processing for case statements and loops.
8019 for J in Ranges'Range loop
8021 Lo : Uint := Ranges (J).Lo;
8022 Hi : Uint := Ranges (J).Hi;
8025 -- Ignore completely out of range entry
8027 if Hi < TLo or else Lo > THi then
8030 -- Otherwise process entry
8033 -- Adjust out of range value to subtype range
8043 -- Convert range into required form
8045 Append_To (Plist, Build_Range (Lo, Hi));
8050 -- Processing was successful and all entries were static, so now we
8051 -- can store the result as the predicate list.
8053 Set_Static_Discrete_Predicate (Typ, Plist);
8055 -- The processing for static predicates put the expression into
8056 -- canonical form as a series of ranges. It also eliminated
8057 -- duplicates and collapsed and combined ranges. We might as well
8058 -- replace the alternatives list of the right operand of the
8059 -- membership test with the static predicate list, which will
8060 -- usually be more efficient.
8063 New_Alts : constant List_Id := New_List;
8068 Old_Node := First (Plist);
8069 while Present (Old_Node) loop
8070 New_Node := New_Copy (Old_Node);
8072 if Nkind (New_Node) = N_Range then
8073 Set_Low_Bound (New_Node, New_Copy (Low_Bound (Old_Node)));
8074 Set_High_Bound (New_Node, New_Copy (High_Bound (Old_Node)));
8077 Append_To (New_Alts, New_Node);
8081 -- If empty list, replace by False
8083 if Is_Empty_List (New_Alts) then
8084 Rewrite (Expr, New_Occurrence_Of (Standard_False, Loc));
8086 -- Else replace by set membership test
8091 Left_Opnd => Make_Identifier (Loc, Nam),
8092 Right_Opnd => Empty,
8093 Alternatives => New_Alts));
8095 -- Resolve new expression in function context
8097 Install_Formals (Predicate_Function (Typ));
8098 Push_Scope (Predicate_Function (Typ));
8099 Analyze_And_Resolve (Expr, Standard_Boolean);
8105 -- If non-static, return doing nothing
8110 end Build_Discrete_Static_Predicate;
8112 --------------------------------
8113 -- Build_Export_Import_Pragma --
8114 --------------------------------
8116 function Build_Export_Import_Pragma
8118 Id : Entity_Id) return Node_Id
8120 Asp_Id : constant Aspect_Id := Get_Aspect_Id (Asp);
8121 Expr : constant Node_Id := Expression (Asp);
8122 Loc : constant Source_Ptr := Sloc (Asp);
8133 Create_Pragma : Boolean := False;
8134 -- This flag is set when the aspect form is such that it warrants the
8135 -- creation of a corresponding pragma.
8138 if Present (Expr) then
8139 if Error_Posted (Expr) then
8142 elsif Is_True (Expr_Value (Expr)) then
8143 Create_Pragma := True;
8146 -- Otherwise the aspect defaults to True
8149 Create_Pragma := True;
8152 -- Nothing to do when the expression is False or is erroneous
8154 if not Create_Pragma then
8158 -- Obtain all interfacing aspects that apply to the related entity
8160 Get_Interfacing_Aspects
8164 Expo_Asp => Dummy_1,
8170 -- Handle the convention argument
8172 if Present (Conv) then
8173 Conv_Arg := New_Copy_Tree (Expression (Conv));
8175 -- Assume convention "Ada' when aspect Convention is missing
8178 Conv_Arg := Make_Identifier (Loc, Name_Ada);
8182 Make_Pragma_Argument_Association (Loc,
8183 Chars => Name_Convention,
8184 Expression => Conv_Arg));
8186 -- Handle the entity argument
8189 Make_Pragma_Argument_Association (Loc,
8190 Chars => Name_Entity,
8191 Expression => New_Occurrence_Of (Id, Loc)));
8193 -- Handle the External_Name argument
8195 if Present (EN) then
8197 Make_Pragma_Argument_Association (Loc,
8198 Chars => Name_External_Name,
8199 Expression => New_Copy_Tree (Expression (EN))));
8202 -- Handle the Link_Name argument
8204 if Present (LN) then
8206 Make_Pragma_Argument_Association (Loc,
8207 Chars => Name_Link_Name,
8208 Expression => New_Copy_Tree (Expression (LN))));
8212 -- pragma Export/Import
8213 -- (Convention => <Conv>/Ada,
8215 -- [External_Name => <EN>,]
8216 -- [Link_Name => <LN>]);
8220 Pragma_Identifier =>
8221 Make_Identifier (Loc, Chars (Identifier (Asp))),
8222 Pragma_Argument_Associations => Args);
8224 -- Decorate the relevant aspect and the pragma
8226 Set_Aspect_Rep_Item (Asp, Prag);
8228 Set_Corresponding_Aspect (Prag, Asp);
8229 Set_From_Aspect_Specification (Prag);
8230 Set_Parent (Prag, Asp);
8232 if Asp_Id = Aspect_Import and then Is_Subprogram (Id) then
8233 Set_Import_Pragma (Id, Prag);
8237 end Build_Export_Import_Pragma;
8239 -------------------------------
8240 -- Build_Predicate_Functions --
8241 -------------------------------
8243 -- The procedures that are constructed here have the form:
8245 -- function typPredicate (Ixxx : typ) return Boolean is
8248 -- typ1Predicate (typ1 (Ixxx))
8249 -- and then typ2Predicate (typ2 (Ixxx))
8251 -- exp1 and then exp2 and then ...
8252 -- end typPredicate;
8254 -- Here exp1, and exp2 are expressions from Predicate pragmas. Note that
8255 -- this is the point at which these expressions get analyzed, providing the
8256 -- required delay, and typ1, typ2, are entities from which predicates are
8257 -- inherited. Note that we do NOT generate Check pragmas, that's because we
8258 -- use this function even if checks are off, e.g. for membership tests.
8260 -- Note that the inherited predicates are evaluated first, as required by
8263 -- Note that Sem_Eval.Real_Or_String_Static_Predicate_Matches depends on
8264 -- the form of this return expression.
8266 -- If the expression has at least one Raise_Expression, then we also build
8267 -- the typPredicateM version of the function, in which any occurrence of a
8268 -- Raise_Expression is converted to "return False".
8270 -- WARNING: This routine manages Ghost regions. Return statements must be
8271 -- replaced by gotos which jump to the end of the routine and restore the
8274 procedure Build_Predicate_Functions (Typ : Entity_Id; N : Node_Id) is
8275 Loc : constant Source_Ptr := Sloc (Typ);
8278 -- This is the expression for the result of the function. It is
8279 -- is build by connecting the component predicates with AND THEN.
8282 -- This is the corresponding return expression for the Predicate_M
8283 -- function. It differs in that raise expressions are marked for
8284 -- special expansion (see Process_REs).
8286 Object_Name : Name_Id;
8287 -- Name for argument of Predicate procedure. Note that we use the same
8288 -- name for both predicate functions. That way the reference within the
8289 -- predicate expression is the same in both functions.
8291 Object_Entity : Entity_Id;
8292 -- Entity for argument of Predicate procedure
8294 Object_Entity_M : Entity_Id;
8295 -- Entity for argument of separate Predicate procedure when exceptions
8296 -- are present in expression.
8299 -- The function declaration
8304 Raise_Expression_Present : Boolean := False;
8305 -- Set True if Expr has at least one Raise_Expression
8307 procedure Add_Condition (Cond : Node_Id);
8308 -- Append Cond to Expr using "and then" (or just copy Cond to Expr if
8311 procedure Add_Predicates;
8312 -- Appends expressions for any Predicate pragmas in the rep item chain
8313 -- Typ to Expr. Note that we look only at items for this exact entity.
8314 -- Inheritance of predicates for the parent type is done by calling the
8315 -- Predicate_Function of the parent type, using Add_Call above.
8317 procedure Add_Call (T : Entity_Id);
8318 -- Includes a call to the predicate function for type T in Expr if T
8319 -- has predicates and Predicate_Function (T) is non-empty.
8321 function Process_RE (N : Node_Id) return Traverse_Result;
8322 -- Used in Process REs, tests if node N is a raise expression, and if
8323 -- so, marks it to be converted to return False.
8325 procedure Process_REs is new Traverse_Proc (Process_RE);
8326 -- Marks any raise expressions in Expr_M to return False
8328 function Test_RE (N : Node_Id) return Traverse_Result;
8329 -- Used in Test_REs, tests one node for being a raise expression, and if
8330 -- so sets Raise_Expression_Present True.
8332 procedure Test_REs is new Traverse_Proc (Test_RE);
8333 -- Tests to see if Expr contains any raise expressions
8339 procedure Add_Call (T : Entity_Id) is
8343 if Present (T) and then Present (Predicate_Function (T)) then
8344 Set_Has_Predicates (Typ);
8346 -- Build the call to the predicate function of T. The type may be
8347 -- derived, so use an unchecked conversion for the actual.
8353 Unchecked_Convert_To (T,
8354 Make_Identifier (Loc, Object_Name)));
8356 -- "and"-in the call to evolving expression
8358 Add_Condition (Exp);
8360 -- Output info message on inheritance if required. Note we do not
8361 -- give this information for generic actual types, since it is
8362 -- unwelcome noise in that case in instantiations. We also
8363 -- generally suppress the message in instantiations, and also
8364 -- if it involves internal names.
8366 if Opt.List_Inherited_Aspects
8367 and then not Is_Generic_Actual_Type (Typ)
8368 and then Instantiation_Depth (Sloc (Typ)) = 0
8369 and then not Is_Internal_Name (Chars (T))
8370 and then not Is_Internal_Name (Chars (Typ))
8372 Error_Msg_Sloc := Sloc (Predicate_Function (T));
8373 Error_Msg_Node_2 := T;
8374 Error_Msg_N ("info: & inherits predicate from & #?L?", Typ);
8383 procedure Add_Condition (Cond : Node_Id) is
8385 -- This is the first predicate expression
8390 -- Otherwise concatenate to the existing predicate expressions by
8391 -- using "and then".
8396 Left_Opnd => Relocate_Node (Expr),
8397 Right_Opnd => Cond);
8401 --------------------
8402 -- Add_Predicates --
8403 --------------------
8405 procedure Add_Predicates is
8406 procedure Add_Predicate (Prag : Node_Id);
8407 -- Concatenate the expression of predicate pragma Prag to Expr by
8408 -- using a short circuit "and then" operator.
8414 procedure Add_Predicate (Prag : Node_Id) is
8415 procedure Replace_Type_Reference (N : Node_Id);
8416 -- Replace a single occurrence N of the subtype name with a
8417 -- reference to the formal of the predicate function. N can be an
8418 -- identifier referencing the subtype, or a selected component,
8419 -- representing an appropriately qualified occurrence of the
8422 procedure Replace_Type_References is
8423 new Replace_Type_References_Generic (Replace_Type_Reference);
8424 -- Traverse an expression changing every occurrence of an
8425 -- identifier whose name matches the name of the subtype with a
8426 -- reference to the formal parameter of the predicate function.
8428 ----------------------------
8429 -- Replace_Type_Reference --
8430 ----------------------------
8432 procedure Replace_Type_Reference (N : Node_Id) is
8434 Rewrite (N, Make_Identifier (Sloc (N), Object_Name));
8435 -- Use the Sloc of the usage name, not the defining name
8438 Set_Entity (N, Object_Entity);
8440 -- We want to treat the node as if it comes from source, so
8441 -- that ASIS will not ignore it.
8443 Set_Comes_From_Source (N, True);
8444 end Replace_Type_Reference;
8448 Asp : constant Node_Id := Corresponding_Aspect (Prag);
8452 -- Start of processing for Add_Predicate
8455 -- Mark corresponding SCO as enabled
8457 Set_SCO_Pragma_Enabled (Sloc (Prag));
8459 -- Extract the arguments of the pragma. The expression itself
8460 -- is copied for use in the predicate function, to preserve the
8461 -- original version for ASIS use.
8463 Arg1 := First (Pragma_Argument_Associations (Prag));
8464 Arg2 := Next (Arg1);
8466 Arg1 := Get_Pragma_Arg (Arg1);
8467 Arg2 := New_Copy_Tree (Get_Pragma_Arg (Arg2));
8469 -- When the predicate pragma applies to the current type or its
8470 -- full view, replace all occurrences of the subtype name with
8471 -- references to the formal parameter of the predicate function.
8473 if Entity (Arg1) = Typ
8474 or else Full_View (Entity (Arg1)) = Typ
8476 Replace_Type_References (Arg2, Typ);
8478 -- If the predicate pragma comes from an aspect, replace the
8479 -- saved expression because we need the subtype references
8480 -- replaced for the calls to Preanalyze_Spec_Expression in
8481 -- Check_Aspect_At_xxx routines.
8483 if Present (Asp) then
8484 Set_Entity (Identifier (Asp), New_Copy_Tree (Arg2));
8487 -- "and"-in the Arg2 condition to evolving expression
8489 Add_Condition (Relocate_Node (Arg2));
8497 -- Start of processing for Add_Predicates
8500 Ritem := First_Rep_Item (Typ);
8502 -- If the type is private, check whether full view has inherited
8505 if Is_Private_Type (Typ) and then No (Ritem) then
8506 Ritem := First_Rep_Item (Full_View (Typ));
8509 while Present (Ritem) loop
8510 if Nkind (Ritem) = N_Pragma
8511 and then Pragma_Name (Ritem) = Name_Predicate
8513 Add_Predicate (Ritem);
8515 -- If the type is declared in an inner package it may be frozen
8516 -- outside of the package, and the generated pragma has not been
8517 -- analyzed yet, so capture the expression for the predicate
8518 -- function at this point.
8520 elsif Nkind (Ritem) = N_Aspect_Specification
8521 and then Present (Aspect_Rep_Item (Ritem))
8522 and then Scope (Typ) /= Current_Scope
8525 Prag : constant Node_Id := Aspect_Rep_Item (Ritem);
8528 if Nkind (Prag) = N_Pragma
8529 and then Pragma_Name (Prag) = Name_Predicate
8531 Add_Predicate (Prag);
8536 Next_Rep_Item (Ritem);
8544 function Process_RE (N : Node_Id) return Traverse_Result is
8546 if Nkind (N) = N_Raise_Expression then
8547 Set_Convert_To_Return_False (N);
8558 function Test_RE (N : Node_Id) return Traverse_Result is
8560 if Nkind (N) = N_Raise_Expression then
8561 Raise_Expression_Present := True;
8570 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
8571 -- Save the Ghost mode to restore on exit
8573 -- Start of processing for Build_Predicate_Functions
8576 -- Return if already built or if type does not have predicates
8578 SId := Predicate_Function (Typ);
8579 if not Has_Predicates (Typ)
8580 or else (Present (SId) and then Has_Completion (SId))
8585 -- The related type may be subject to pragma Ghost. Set the mode now to
8586 -- ensure that the predicate functions are properly marked as Ghost.
8588 Set_Ghost_Mode (Typ);
8590 -- Prepare to construct predicate expression
8594 if Present (SId) then
8595 FDecl := Unit_Declaration_Node (SId);
8598 FDecl := Build_Predicate_Function_Declaration (Typ);
8599 SId := Defining_Entity (FDecl);
8602 -- Recover name of formal parameter of function that replaces references
8603 -- to the type in predicate expressions.
8607 (First (Parameter_Specifications (Specification (FDecl))));
8609 Object_Name := Chars (Object_Entity);
8610 Object_Entity_M := Make_Defining_Identifier (Loc, Chars => Object_Name);
8612 -- Add predicates for ancestor if present. These must come before the
8613 -- ones for the current type, as required by AI12-0071-1.
8618 Atyp := Nearest_Ancestor (Typ);
8620 -- The type may be private but the full view may inherit predicates
8622 if No (Atyp) and then Is_Private_Type (Typ) then
8623 Atyp := Nearest_Ancestor (Full_View (Typ));
8626 if Present (Atyp) then
8631 -- Add Predicates for the current type
8635 -- Case where predicates are present
8637 if Present (Expr) then
8639 -- Test for raise expression present
8643 -- If raise expression is present, capture a copy of Expr for use
8644 -- in building the predicateM function version later on. For this
8645 -- copy we replace references to Object_Entity by Object_Entity_M.
8647 if Raise_Expression_Present then
8649 Map : constant Elist_Id := New_Elmt_List;
8650 New_V : Entity_Id := Empty;
8652 -- The unanalyzed expression will be copied and appear in
8653 -- both functions. Normally expressions do not declare new
8654 -- entities, but quantified expressions do, so we need to
8655 -- create new entities for their bound variables, to prevent
8656 -- multiple definitions in gigi.
8658 function Reset_Loop_Variable (N : Node_Id)
8659 return Traverse_Result;
8661 procedure Collect_Loop_Variables is
8662 new Traverse_Proc (Reset_Loop_Variable);
8664 ------------------------
8665 -- Reset_Loop_Variable --
8666 ------------------------
8668 function Reset_Loop_Variable (N : Node_Id)
8669 return Traverse_Result
8672 if Nkind (N) = N_Iterator_Specification then
8673 New_V := Make_Defining_Identifier
8674 (Sloc (N), Chars (Defining_Identifier (N)));
8676 Set_Defining_Identifier (N, New_V);
8680 end Reset_Loop_Variable;
8683 Append_Elmt (Object_Entity, Map);
8684 Append_Elmt (Object_Entity_M, Map);
8685 Expr_M := New_Copy_Tree (Expr, Map => Map);
8686 Collect_Loop_Variables (Expr_M);
8690 -- Build the main predicate function
8693 SIdB : constant Entity_Id :=
8694 Make_Defining_Identifier (Loc,
8695 Chars => New_External_Name (Chars (Typ), "Predicate"));
8696 -- The entity for the function body
8702 -- The predicate function is shared between views of a type
8704 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
8705 Set_Predicate_Function (Full_View (Typ), SId);
8708 -- Build function body
8711 Make_Function_Specification (Loc,
8712 Defining_Unit_Name => SIdB,
8713 Parameter_Specifications => New_List (
8714 Make_Parameter_Specification (Loc,
8715 Defining_Identifier =>
8716 Make_Defining_Identifier (Loc, Object_Name),
8718 New_Occurrence_Of (Typ, Loc))),
8719 Result_Definition =>
8720 New_Occurrence_Of (Standard_Boolean, Loc));
8723 Make_Subprogram_Body (Loc,
8724 Specification => Spec,
8725 Declarations => Empty_List,
8726 Handled_Statement_Sequence =>
8727 Make_Handled_Sequence_Of_Statements (Loc,
8728 Statements => New_List (
8729 Make_Simple_Return_Statement (Loc,
8730 Expression => Expr))));
8732 -- If declaration has not been analyzed yet, Insert declaration
8733 -- before freeze node. Insert body itself after freeze node.
8735 if not Analyzed (FDecl) then
8736 Insert_Before_And_Analyze (N, FDecl);
8739 Insert_After_And_Analyze (N, FBody);
8741 -- Static predicate functions are always side-effect free, and
8742 -- in most cases dynamic predicate functions are as well. Mark
8743 -- them as such whenever possible, so redundant predicate checks
8744 -- can be optimized. If there is a variable reference within the
8745 -- expression, the function is not pure.
8747 if Expander_Active then
8749 Side_Effect_Free (Expr, Variable_Ref => True));
8750 Set_Is_Inlined (SId);
8754 -- Test for raise expressions present and if so build M version
8756 if Raise_Expression_Present then
8758 SId : constant Entity_Id :=
8759 Make_Defining_Identifier (Loc,
8760 Chars => New_External_Name (Chars (Typ), "PredicateM"));
8761 -- The entity for the function spec
8763 SIdB : constant Entity_Id :=
8764 Make_Defining_Identifier (Loc,
8765 Chars => New_External_Name (Chars (Typ), "PredicateM"));
8766 -- The entity for the function body
8774 -- Mark any raise expressions for special expansion
8776 Process_REs (Expr_M);
8778 -- Build function declaration
8780 Set_Ekind (SId, E_Function);
8781 Set_Is_Predicate_Function_M (SId);
8782 Set_Predicate_Function_M (Typ, SId);
8784 -- The predicate function is shared between views of a type
8786 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
8787 Set_Predicate_Function_M (Full_View (Typ), SId);
8791 Make_Function_Specification (Loc,
8792 Defining_Unit_Name => SId,
8793 Parameter_Specifications => New_List (
8794 Make_Parameter_Specification (Loc,
8795 Defining_Identifier => Object_Entity_M,
8796 Parameter_Type => New_Occurrence_Of (Typ, Loc))),
8797 Result_Definition =>
8798 New_Occurrence_Of (Standard_Boolean, Loc));
8801 Make_Subprogram_Declaration (Loc,
8802 Specification => Spec);
8804 -- Build function body
8807 Make_Function_Specification (Loc,
8808 Defining_Unit_Name => SIdB,
8809 Parameter_Specifications => New_List (
8810 Make_Parameter_Specification (Loc,
8811 Defining_Identifier =>
8812 Make_Defining_Identifier (Loc, Object_Name),
8814 New_Occurrence_Of (Typ, Loc))),
8815 Result_Definition =>
8816 New_Occurrence_Of (Standard_Boolean, Loc));
8818 -- Build the body, we declare the boolean expression before
8819 -- doing the return, because we are not really confident of
8820 -- what happens if a return appears within a return.
8823 Make_Defining_Identifier (Loc,
8824 Chars => New_Internal_Name ('B'));
8827 Make_Subprogram_Body (Loc,
8828 Specification => Spec,
8830 Declarations => New_List (
8831 Make_Object_Declaration (Loc,
8832 Defining_Identifier => BTemp,
8833 Constant_Present => True,
8834 Object_Definition =>
8835 New_Occurrence_Of (Standard_Boolean, Loc),
8836 Expression => Expr_M)),
8838 Handled_Statement_Sequence =>
8839 Make_Handled_Sequence_Of_Statements (Loc,
8840 Statements => New_List (
8841 Make_Simple_Return_Statement (Loc,
8842 Expression => New_Occurrence_Of (BTemp, Loc)))));
8844 -- Insert declaration before freeze node and body after
8846 Insert_Before_And_Analyze (N, FDecl);
8847 Insert_After_And_Analyze (N, FBody);
8851 -- See if we have a static predicate. Note that the answer may be
8852 -- yes even if we have an explicit Dynamic_Predicate present.
8859 if not Is_Scalar_Type (Typ) and then not Is_String_Type (Typ) then
8862 PS := Is_Predicate_Static (Expr, Object_Name);
8865 -- Case where we have a predicate-static aspect
8869 -- We don't set Has_Static_Predicate_Aspect, since we can have
8870 -- any of the three cases (Predicate, Dynamic_Predicate, or
8871 -- Static_Predicate) generating a predicate with an expression
8872 -- that is predicate-static. We just indicate that we have a
8873 -- predicate that can be treated as static.
8875 Set_Has_Static_Predicate (Typ);
8877 -- For discrete subtype, build the static predicate list
8879 if Is_Discrete_Type (Typ) then
8880 Build_Discrete_Static_Predicate (Typ, Expr, Object_Name);
8882 -- If we don't get a static predicate list, it means that we
8883 -- have a case where this is not possible, most typically in
8884 -- the case where we inherit a dynamic predicate. We do not
8885 -- consider this an error, we just leave the predicate as
8886 -- dynamic. But if we do succeed in building the list, then
8887 -- we mark the predicate as static.
8889 if No (Static_Discrete_Predicate (Typ)) then
8890 Set_Has_Static_Predicate (Typ, False);
8893 -- For real or string subtype, save predicate expression
8895 elsif Is_Real_Type (Typ) or else Is_String_Type (Typ) then
8896 Set_Static_Real_Or_String_Predicate (Typ, Expr);
8899 -- Case of dynamic predicate (expression is not predicate-static)
8902 -- Again, we don't set Has_Dynamic_Predicate_Aspect, since that
8903 -- is only set if we have an explicit Dynamic_Predicate aspect
8904 -- given. Here we may simply have a Predicate aspect where the
8905 -- expression happens not to be predicate-static.
8907 -- Emit an error when the predicate is categorized as static
8908 -- but its expression is not predicate-static.
8910 -- First a little fiddling to get a nice location for the
8911 -- message. If the expression is of the form (A and then B),
8912 -- where A is an inherited predicate, then use the right
8913 -- operand for the Sloc. This avoids getting confused by a call
8914 -- to an inherited predicate with a less convenient source
8918 while Nkind (EN) = N_And_Then
8919 and then Nkind (Left_Opnd (EN)) = N_Function_Call
8920 and then Is_Predicate_Function
8921 (Entity (Name (Left_Opnd (EN))))
8923 EN := Right_Opnd (EN);
8926 -- Now post appropriate message
8928 if Has_Static_Predicate_Aspect (Typ) then
8929 if Is_Scalar_Type (Typ) or else Is_String_Type (Typ) then
8931 ("expression is not predicate-static (RM 3.2.4(16-22))",
8935 ("static predicate requires scalar or string type", EN);
8942 Restore_Ghost_Mode (Saved_GM);
8943 end Build_Predicate_Functions;
8945 ------------------------------------------
8946 -- Build_Predicate_Function_Declaration --
8947 ------------------------------------------
8949 -- WARNING: This routine manages Ghost regions. Return statements must be
8950 -- replaced by gotos which jump to the end of the routine and restore the
8953 function Build_Predicate_Function_Declaration
8954 (Typ : Entity_Id) return Node_Id
8956 Loc : constant Source_Ptr := Sloc (Typ);
8958 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
8959 -- Save the Ghost mode to restore on exit
8961 Func_Decl : Node_Id;
8962 Func_Id : Entity_Id;
8966 -- The related type may be subject to pragma Ghost. Set the mode now to
8967 -- ensure that the predicate functions are properly marked as Ghost.
8969 Set_Ghost_Mode (Typ);
8972 Make_Defining_Identifier (Loc,
8973 Chars => New_External_Name (Chars (Typ), "Predicate"));
8975 -- The predicate function requires debug info when the predicates are
8976 -- subject to Source Coverage Obligations.
8978 if Opt.Generate_SCO then
8979 Set_Debug_Info_Needed (Func_Id);
8983 Make_Function_Specification (Loc,
8984 Defining_Unit_Name => Func_Id,
8985 Parameter_Specifications => New_List (
8986 Make_Parameter_Specification (Loc,
8987 Defining_Identifier => Make_Temporary (Loc, 'I'),
8988 Parameter_Type => New_Occurrence_Of (Typ, Loc))),
8989 Result_Definition =>
8990 New_Occurrence_Of (Standard_Boolean, Loc));
8992 Func_Decl := Make_Subprogram_Declaration (Loc, Specification => Spec);
8994 Set_Ekind (Func_Id, E_Function);
8995 Set_Etype (Func_Id, Standard_Boolean);
8996 Set_Is_Internal (Func_Id);
8997 Set_Is_Predicate_Function (Func_Id);
8998 Set_Predicate_Function (Typ, Func_Id);
9000 Insert_After (Parent (Typ), Func_Decl);
9001 Analyze (Func_Decl);
9003 Restore_Ghost_Mode (Saved_GM);
9006 end Build_Predicate_Function_Declaration;
9008 -----------------------------------------
9009 -- Check_Aspect_At_End_Of_Declarations --
9010 -----------------------------------------
9012 procedure Check_Aspect_At_End_Of_Declarations (ASN : Node_Id) is
9013 Ent : constant Entity_Id := Entity (ASN);
9014 Ident : constant Node_Id := Identifier (ASN);
9015 A_Id : constant Aspect_Id := Get_Aspect_Id (Chars (Ident));
9017 End_Decl_Expr : constant Node_Id := Entity (Ident);
9018 -- Expression to be analyzed at end of declarations
9020 Freeze_Expr : constant Node_Id := Expression (ASN);
9021 -- Expression from call to Check_Aspect_At_Freeze_Point.
9023 T : constant Entity_Id := Etype (Original_Node (Freeze_Expr));
9024 -- Type required for preanalyze call. We use the original expression to
9025 -- get the proper type, to prevent cascaded errors when the expression
9026 -- is constant-folded.
9029 -- Set False if error
9031 -- On entry to this procedure, Entity (Ident) contains a copy of the
9032 -- original expression from the aspect, saved for this purpose, and
9033 -- but Expression (Ident) is a preanalyzed copy of the expression,
9034 -- preanalyzed just after the freeze point.
9036 procedure Check_Overloaded_Name;
9037 -- For aspects whose expression is simply a name, this routine checks if
9038 -- the name is overloaded or not. If so, it verifies there is an
9039 -- interpretation that matches the entity obtained at the freeze point,
9040 -- otherwise the compiler complains.
9042 ---------------------------
9043 -- Check_Overloaded_Name --
9044 ---------------------------
9046 procedure Check_Overloaded_Name is
9048 if not Is_Overloaded (End_Decl_Expr) then
9049 Err := not Is_Entity_Name (End_Decl_Expr)
9050 or else Entity (End_Decl_Expr) /= Entity (Freeze_Expr);
9056 Index : Interp_Index;
9060 Get_First_Interp (End_Decl_Expr, Index, It);
9061 while Present (It.Typ) loop
9062 if It.Nam = Entity (Freeze_Expr) then
9067 Get_Next_Interp (Index, It);
9071 end Check_Overloaded_Name;
9073 -- Start of processing for Check_Aspect_At_End_Of_Declarations
9076 -- In an instance we do not perform the consistency check between freeze
9077 -- point and end of declarations, because it was done already in the
9078 -- analysis of the generic. Furthermore, the delayed analysis of an
9079 -- aspect of the instance may produce spurious errors when the generic
9080 -- is a child unit that references entities in the parent (which might
9081 -- not be in scope at the freeze point of the instance).
9086 -- The enclosing scope may have been rewritten during expansion (.e.g.
9087 -- a task body is rewritten as a procedure) after this conformance check
9088 -- has been performed, so do not perform it again (it may not easily
9089 -- be done if full visibility of local entities is not available).
9091 elsif not Comes_From_Source (Current_Scope) then
9094 -- Case of aspects Dimension, Dimension_System and Synchronization
9096 elsif A_Id = Aspect_Synchronization then
9099 -- Case of stream attributes, just have to compare entities. However,
9100 -- the expression is just a name (possibly overloaded), and there may
9101 -- be stream operations declared for unrelated types, so we just need
9102 -- to verify that one of these interpretations is the one available at
9103 -- at the freeze point.
9105 elsif A_Id = Aspect_Input or else
9106 A_Id = Aspect_Output or else
9107 A_Id = Aspect_Read or else
9110 Analyze (End_Decl_Expr);
9111 Check_Overloaded_Name;
9113 elsif A_Id = Aspect_Variable_Indexing or else
9114 A_Id = Aspect_Constant_Indexing or else
9115 A_Id = Aspect_Default_Iterator or else
9116 A_Id = Aspect_Iterator_Element
9118 -- Make type unfrozen before analysis, to prevent spurious errors
9119 -- about late attributes.
9121 Set_Is_Frozen (Ent, False);
9122 Analyze (End_Decl_Expr);
9123 Set_Is_Frozen (Ent, True);
9125 -- If the end of declarations comes before any other freeze
9126 -- point, the Freeze_Expr is not analyzed: no check needed.
9128 if Analyzed (Freeze_Expr) and then not In_Instance then
9129 Check_Overloaded_Name;
9137 -- Indicate that the expression comes from an aspect specification,
9138 -- which is used in subsequent analysis even if expansion is off.
9140 Set_Parent (End_Decl_Expr, ASN);
9142 -- In a generic context the aspect expressions have not been
9143 -- preanalyzed, so do it now. There are no conformance checks
9144 -- to perform in this case.
9147 Check_Aspect_At_Freeze_Point (ASN);
9150 -- The default values attributes may be defined in the private part,
9151 -- and the analysis of the expression may take place when only the
9152 -- partial view is visible. The expression must be scalar, so use
9153 -- the full view to resolve.
9155 elsif (A_Id = Aspect_Default_Value
9157 A_Id = Aspect_Default_Component_Value)
9158 and then Is_Private_Type (T)
9160 Preanalyze_Spec_Expression (End_Decl_Expr, Full_View (T));
9163 Preanalyze_Spec_Expression (End_Decl_Expr, T);
9166 Err := not Fully_Conformant_Expressions (End_Decl_Expr, Freeze_Expr);
9169 -- Output error message if error. Force error on aspect specification
9170 -- even if there is an error on the expression itself.
9174 ("!visibility of aspect for& changes after freeze point",
9177 ("info: & is frozen here, aspects evaluated at this point??",
9178 Freeze_Node (Ent), Ent);
9180 end Check_Aspect_At_End_Of_Declarations;
9182 ----------------------------------
9183 -- Check_Aspect_At_Freeze_Point --
9184 ----------------------------------
9186 procedure Check_Aspect_At_Freeze_Point (ASN : Node_Id) is
9187 Ident : constant Node_Id := Identifier (ASN);
9188 -- Identifier (use Entity field to save expression)
9190 A_Id : constant Aspect_Id := Get_Aspect_Id (Chars (Ident));
9192 T : Entity_Id := Empty;
9193 -- Type required for preanalyze call
9196 -- On entry to this procedure, Entity (Ident) contains a copy of the
9197 -- original expression from the aspect, saved for this purpose.
9199 -- On exit from this procedure Entity (Ident) is unchanged, still
9200 -- containing that copy, but Expression (Ident) is a preanalyzed copy
9201 -- of the expression, preanalyzed just after the freeze point.
9203 -- Make a copy of the expression to be preanalyzed
9205 Set_Expression (ASN, New_Copy_Tree (Entity (Ident)));
9207 -- Find type for preanalyze call
9211 -- No_Aspect should be impossible
9214 raise Program_Error;
9216 -- Aspects taking an optional boolean argument
9218 when Boolean_Aspects
9219 | Library_Unit_Aspects
9221 T := Standard_Boolean;
9223 -- Aspects corresponding to attribute definition clauses
9225 when Aspect_Address =>
9226 T := RTE (RE_Address);
9228 when Aspect_Attach_Handler =>
9229 T := RTE (RE_Interrupt_ID);
9231 when Aspect_Bit_Order
9232 | Aspect_Scalar_Storage_Order
9234 T := RTE (RE_Bit_Order);
9236 when Aspect_Convention =>
9240 T := RTE (RE_CPU_Range);
9242 -- Default_Component_Value is resolved with the component type
9244 when Aspect_Default_Component_Value =>
9245 T := Component_Type (Entity (ASN));
9247 when Aspect_Default_Storage_Pool =>
9248 T := Class_Wide_Type (RTE (RE_Root_Storage_Pool));
9250 -- Default_Value is resolved with the type entity in question
9252 when Aspect_Default_Value =>
9255 when Aspect_Dispatching_Domain =>
9256 T := RTE (RE_Dispatching_Domain);
9258 when Aspect_External_Tag =>
9259 T := Standard_String;
9261 when Aspect_External_Name =>
9262 T := Standard_String;
9264 when Aspect_Link_Name =>
9265 T := Standard_String;
9267 when Aspect_Interrupt_Priority
9270 T := Standard_Integer;
9272 when Aspect_Relative_Deadline =>
9273 T := RTE (RE_Time_Span);
9275 when Aspect_Secondary_Stack_Size =>
9276 T := Standard_Integer;
9278 when Aspect_Small =>
9279 T := Universal_Real;
9281 -- For a simple storage pool, we have to retrieve the type of the
9282 -- pool object associated with the aspect's corresponding attribute
9283 -- definition clause.
9285 when Aspect_Simple_Storage_Pool =>
9286 T := Etype (Expression (Aspect_Rep_Item (ASN)));
9288 when Aspect_Storage_Pool =>
9289 T := Class_Wide_Type (RTE (RE_Root_Storage_Pool));
9291 when Aspect_Alignment
9292 | Aspect_Component_Size
9293 | Aspect_Machine_Radix
9294 | Aspect_Object_Size
9296 | Aspect_Storage_Size
9297 | Aspect_Stream_Size
9302 when Aspect_Linker_Section =>
9303 T := Standard_String;
9305 when Aspect_Synchronization =>
9308 -- Special case, the expression of these aspects is just an entity
9309 -- that does not need any resolution, so just analyze.
9319 Analyze (Expression (ASN));
9322 -- Same for Iterator aspects, where the expression is a function
9323 -- name. Legality rules are checked separately.
9325 when Aspect_Constant_Indexing
9326 | Aspect_Default_Iterator
9327 | Aspect_Iterator_Element
9328 | Aspect_Variable_Indexing
9330 Analyze (Expression (ASN));
9333 -- Ditto for Iterable, legality checks in Validate_Iterable_Aspect.
9335 when Aspect_Iterable =>
9339 Cursor : constant Entity_Id := Get_Cursor_Type (ASN, T);
9344 if Cursor = Any_Type then
9348 Assoc := First (Component_Associations (Expression (ASN)));
9349 while Present (Assoc) loop
9350 Expr := Expression (Assoc);
9353 if not Error_Posted (Expr) then
9354 Resolve_Iterable_Operation
9355 (Expr, Cursor, T, Chars (First (Choices (Assoc))));
9364 -- Invariant/Predicate take boolean expressions
9366 when Aspect_Dynamic_Predicate
9369 | Aspect_Static_Predicate
9370 | Aspect_Type_Invariant
9372 T := Standard_Boolean;
9374 when Aspect_Predicate_Failure =>
9375 T := Standard_String;
9377 -- Here is the list of aspects that don't require delay analysis
9379 when Aspect_Abstract_State
9381 | Aspect_Async_Readers
9382 | Aspect_Async_Writers
9383 | Aspect_Constant_After_Elaboration
9384 | Aspect_Contract_Cases
9385 | Aspect_Default_Initial_Condition
9388 | Aspect_Dimension_System
9389 | Aspect_Effective_Reads
9390 | Aspect_Effective_Writes
9391 | Aspect_Extensions_Visible
9394 | Aspect_Implicit_Dereference
9395 | Aspect_Initial_Condition
9396 | Aspect_Initializes
9397 | Aspect_Max_Queue_Length
9398 | Aspect_Obsolescent
9401 | Aspect_Postcondition
9403 | Aspect_Precondition
9404 | Aspect_Refined_Depends
9405 | Aspect_Refined_Global
9406 | Aspect_Refined_Post
9407 | Aspect_Refined_State
9410 | Aspect_Unimplemented
9411 | Aspect_Volatile_Function
9413 raise Program_Error;
9417 -- Do the preanalyze call
9419 Preanalyze_Spec_Expression (Expression (ASN), T);
9420 end Check_Aspect_At_Freeze_Point;
9422 -----------------------------------
9423 -- Check_Constant_Address_Clause --
9424 -----------------------------------
9426 procedure Check_Constant_Address_Clause
9430 procedure Check_At_Constant_Address (Nod : Node_Id);
9431 -- Checks that the given node N represents a name whose 'Address is
9432 -- constant (in the same sense as OK_Constant_Address_Clause, i.e. the
9433 -- address value is the same at the point of declaration of U_Ent and at
9434 -- the time of elaboration of the address clause.
9436 procedure Check_Expr_Constants (Nod : Node_Id);
9437 -- Checks that Nod meets the requirements for a constant address clause
9438 -- in the sense of the enclosing procedure.
9440 procedure Check_List_Constants (Lst : List_Id);
9441 -- Check that all elements of list Lst meet the requirements for a
9442 -- constant address clause in the sense of the enclosing procedure.
9444 -------------------------------
9445 -- Check_At_Constant_Address --
9446 -------------------------------
9448 procedure Check_At_Constant_Address (Nod : Node_Id) is
9450 if Is_Entity_Name (Nod) then
9451 if Present (Address_Clause (Entity ((Nod)))) then
9453 ("invalid address clause for initialized object &!",
9456 ("address for& cannot depend on another address clause! "
9457 & "(RM 13.1(22))!", Nod, U_Ent);
9459 elsif In_Same_Source_Unit (Entity (Nod), U_Ent)
9460 and then Sloc (U_Ent) < Sloc (Entity (Nod))
9463 ("invalid address clause for initialized object &!",
9465 Error_Msg_Node_2 := U_Ent;
9467 ("\& must be defined before & (RM 13.1(22))!",
9471 elsif Nkind (Nod) = N_Selected_Component then
9473 T : constant Entity_Id := Etype (Prefix (Nod));
9476 if (Is_Record_Type (T)
9477 and then Has_Discriminants (T))
9480 and then Is_Record_Type (Designated_Type (T))
9481 and then Has_Discriminants (Designated_Type (T)))
9484 ("invalid address clause for initialized object &!",
9487 ("\address cannot depend on component of discriminated "
9488 & "record (RM 13.1(22))!", Nod);
9490 Check_At_Constant_Address (Prefix (Nod));
9494 elsif Nkind (Nod) = N_Indexed_Component then
9495 Check_At_Constant_Address (Prefix (Nod));
9496 Check_List_Constants (Expressions (Nod));
9499 Check_Expr_Constants (Nod);
9501 end Check_At_Constant_Address;
9503 --------------------------
9504 -- Check_Expr_Constants --
9505 --------------------------
9507 procedure Check_Expr_Constants (Nod : Node_Id) is
9508 Loc_U_Ent : constant Source_Ptr := Sloc (U_Ent);
9509 Ent : Entity_Id := Empty;
9512 if Nkind (Nod) in N_Has_Etype
9513 and then Etype (Nod) = Any_Type
9524 when N_Expanded_Name
9527 Ent := Entity (Nod);
9529 -- We need to look at the original node if it is different
9530 -- from the node, since we may have rewritten things and
9531 -- substituted an identifier representing the rewrite.
9533 if Original_Node (Nod) /= Nod then
9534 Check_Expr_Constants (Original_Node (Nod));
9536 -- If the node is an object declaration without initial
9537 -- value, some code has been expanded, and the expression
9538 -- is not constant, even if the constituents might be
9539 -- acceptable, as in A'Address + offset.
9541 if Ekind (Ent) = E_Variable
9543 Nkind (Declaration_Node (Ent)) = N_Object_Declaration
9545 No (Expression (Declaration_Node (Ent)))
9548 ("invalid address clause for initialized object &!",
9551 -- If entity is constant, it may be the result of expanding
9552 -- a check. We must verify that its declaration appears
9553 -- before the object in question, else we also reject the
9556 elsif Ekind (Ent) = E_Constant
9557 and then In_Same_Source_Unit (Ent, U_Ent)
9558 and then Sloc (Ent) > Loc_U_Ent
9561 ("invalid address clause for initialized object &!",
9568 -- Otherwise look at the identifier and see if it is OK
9570 if Ekind_In (Ent, E_Named_Integer, E_Named_Real)
9571 or else Is_Type (Ent)
9575 elsif Ekind_In (Ent, E_Constant, E_In_Parameter) then
9577 -- This is the case where we must have Ent defined before
9578 -- U_Ent. Clearly if they are in different units this
9579 -- requirement is met since the unit containing Ent is
9580 -- already processed.
9582 if not In_Same_Source_Unit (Ent, U_Ent) then
9585 -- Otherwise location of Ent must be before the location
9586 -- of U_Ent, that's what prior defined means.
9588 elsif Sloc (Ent) < Loc_U_Ent then
9593 ("invalid address clause for initialized object &!",
9595 Error_Msg_Node_2 := U_Ent;
9597 ("\& must be defined before & (RM 13.1(22))!",
9601 elsif Nkind (Original_Node (Nod)) = N_Function_Call then
9602 Check_Expr_Constants (Original_Node (Nod));
9606 ("invalid address clause for initialized object &!",
9609 if Comes_From_Source (Ent) then
9611 ("\reference to variable& not allowed"
9612 & " (RM 13.1(22))!", Nod, Ent);
9615 ("non-static expression not allowed"
9616 & " (RM 13.1(22))!", Nod);
9620 when N_Integer_Literal =>
9622 -- If this is a rewritten unchecked conversion, in a system
9623 -- where Address is an integer type, always use the base type
9624 -- for a literal value. This is user-friendly and prevents
9625 -- order-of-elaboration issues with instances of unchecked
9628 if Nkind (Original_Node (Nod)) = N_Function_Call then
9629 Set_Etype (Nod, Base_Type (Etype (Nod)));
9632 when N_Character_Literal
9639 Check_Expr_Constants (Low_Bound (Nod));
9640 Check_Expr_Constants (High_Bound (Nod));
9642 when N_Explicit_Dereference =>
9643 Check_Expr_Constants (Prefix (Nod));
9645 when N_Indexed_Component =>
9646 Check_Expr_Constants (Prefix (Nod));
9647 Check_List_Constants (Expressions (Nod));
9650 Check_Expr_Constants (Prefix (Nod));
9651 Check_Expr_Constants (Discrete_Range (Nod));
9653 when N_Selected_Component =>
9654 Check_Expr_Constants (Prefix (Nod));
9656 when N_Attribute_Reference =>
9657 if Nam_In (Attribute_Name (Nod), Name_Address,
9659 Name_Unchecked_Access,
9660 Name_Unrestricted_Access)
9662 Check_At_Constant_Address (Prefix (Nod));
9665 Check_Expr_Constants (Prefix (Nod));
9666 Check_List_Constants (Expressions (Nod));
9670 Check_List_Constants (Component_Associations (Nod));
9671 Check_List_Constants (Expressions (Nod));
9673 when N_Component_Association =>
9674 Check_Expr_Constants (Expression (Nod));
9676 when N_Extension_Aggregate =>
9677 Check_Expr_Constants (Ancestor_Part (Nod));
9678 Check_List_Constants (Component_Associations (Nod));
9679 Check_List_Constants (Expressions (Nod));
9688 Check_Expr_Constants (Left_Opnd (Nod));
9689 Check_Expr_Constants (Right_Opnd (Nod));
9692 Check_Expr_Constants (Right_Opnd (Nod));
9695 | N_Qualified_Expression
9697 | N_Unchecked_Type_Conversion
9699 Check_Expr_Constants (Expression (Nod));
9701 when N_Function_Call =>
9702 if not Is_Pure (Entity (Name (Nod))) then
9704 ("invalid address clause for initialized object &!",
9708 ("\function & is not pure (RM 13.1(22))!",
9709 Nod, Entity (Name (Nod)));
9712 Check_List_Constants (Parameter_Associations (Nod));
9715 when N_Parameter_Association =>
9716 Check_Expr_Constants (Explicit_Actual_Parameter (Nod));
9720 ("invalid address clause for initialized object &!",
9723 ("\must be constant defined before& (RM 13.1(22))!",
9726 end Check_Expr_Constants;
9728 --------------------------
9729 -- Check_List_Constants --
9730 --------------------------
9732 procedure Check_List_Constants (Lst : List_Id) is
9736 if Present (Lst) then
9737 Nod1 := First (Lst);
9738 while Present (Nod1) loop
9739 Check_Expr_Constants (Nod1);
9743 end Check_List_Constants;
9745 -- Start of processing for Check_Constant_Address_Clause
9748 -- If rep_clauses are to be ignored, no need for legality checks. In
9749 -- particular, no need to pester user about rep clauses that violate the
9750 -- rule on constant addresses, given that these clauses will be removed
9751 -- by Freeze before they reach the back end. Similarly in CodePeer mode,
9752 -- we want to relax these checks.
9754 if not Ignore_Rep_Clauses and not CodePeer_Mode then
9755 Check_Expr_Constants (Expr);
9757 end Check_Constant_Address_Clause;
9759 ---------------------------
9760 -- Check_Pool_Size_Clash --
9761 ---------------------------
9763 procedure Check_Pool_Size_Clash (Ent : Entity_Id; SP, SS : Node_Id) is
9767 -- We need to find out which one came first. Note that in the case of
9768 -- aspects mixed with pragmas there are cases where the processing order
9769 -- is reversed, which is why we do the check here.
9771 if Sloc (SP) < Sloc (SS) then
9772 Error_Msg_Sloc := Sloc (SP);
9774 Error_Msg_NE ("Storage_Pool previously given for&#", Post, Ent);
9777 Error_Msg_Sloc := Sloc (SS);
9779 Error_Msg_NE ("Storage_Size previously given for&#", Post, Ent);
9783 ("\cannot have Storage_Size and Storage_Pool (RM 13.11(3))", Post);
9784 end Check_Pool_Size_Clash;
9786 ----------------------------------------
9787 -- Check_Record_Representation_Clause --
9788 ----------------------------------------
9790 procedure Check_Record_Representation_Clause (N : Node_Id) is
9791 Loc : constant Source_Ptr := Sloc (N);
9792 Ident : constant Node_Id := Identifier (N);
9793 Rectype : Entity_Id;
9798 Hbit : Uint := Uint_0;
9802 Max_Bit_So_Far : Uint;
9803 -- Records the maximum bit position so far. If all field positions
9804 -- are monotonically increasing, then we can skip the circuit for
9805 -- checking for overlap, since no overlap is possible.
9807 Tagged_Parent : Entity_Id := Empty;
9808 -- This is set in the case of a derived tagged type for which we have
9809 -- Is_Fully_Repped_Tagged_Type True (indicating that all components are
9810 -- positioned by record representation clauses). In this case we must
9811 -- check for overlap between components of this tagged type, and the
9812 -- components of its parent. Tagged_Parent will point to this parent
9813 -- type. For all other cases Tagged_Parent is left set to Empty.
9815 Parent_Last_Bit : Uint;
9816 -- Relevant only if Tagged_Parent is set, Parent_Last_Bit indicates the
9817 -- last bit position for any field in the parent type. We only need to
9818 -- check overlap for fields starting below this point.
9820 Overlap_Check_Required : Boolean;
9821 -- Used to keep track of whether or not an overlap check is required
9823 Overlap_Detected : Boolean := False;
9824 -- Set True if an overlap is detected
9826 Ccount : Natural := 0;
9827 -- Number of component clauses in record rep clause
9829 procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id);
9830 -- Given two entities for record components or discriminants, checks
9831 -- if they have overlapping component clauses and issues errors if so.
9833 procedure Find_Component;
9834 -- Finds component entity corresponding to current component clause (in
9835 -- CC), and sets Comp to the entity, and Fbit/Lbit to the zero origin
9836 -- start/stop bits for the field. If there is no matching component or
9837 -- if the matching component does not have a component clause, then
9838 -- that's an error and Comp is set to Empty, but no error message is
9839 -- issued, since the message was already given. Comp is also set to
9840 -- Empty if the current "component clause" is in fact a pragma.
9842 -----------------------------
9843 -- Check_Component_Overlap --
9844 -----------------------------
9846 procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id) is
9847 CC1 : constant Node_Id := Component_Clause (C1_Ent);
9848 CC2 : constant Node_Id := Component_Clause (C2_Ent);
9851 if Present (CC1) and then Present (CC2) then
9853 -- Exclude odd case where we have two tag components in the same
9854 -- record, both at location zero. This seems a bit strange, but
9855 -- it seems to happen in some circumstances, perhaps on an error.
9857 if Nam_In (Chars (C1_Ent), Name_uTag, Name_uTag) then
9861 -- Here we check if the two fields overlap
9864 S1 : constant Uint := Component_Bit_Offset (C1_Ent);
9865 S2 : constant Uint := Component_Bit_Offset (C2_Ent);
9866 E1 : constant Uint := S1 + Esize (C1_Ent);
9867 E2 : constant Uint := S2 + Esize (C2_Ent);
9870 if E2 <= S1 or else E1 <= S2 then
9873 Error_Msg_Node_2 := Component_Name (CC2);
9874 Error_Msg_Sloc := Sloc (Error_Msg_Node_2);
9875 Error_Msg_Node_1 := Component_Name (CC1);
9877 ("component& overlaps & #", Component_Name (CC1));
9878 Overlap_Detected := True;
9882 end Check_Component_Overlap;
9884 --------------------
9885 -- Find_Component --
9886 --------------------
9888 procedure Find_Component is
9890 procedure Search_Component (R : Entity_Id);
9891 -- Search components of R for a match. If found, Comp is set
9893 ----------------------
9894 -- Search_Component --
9895 ----------------------
9897 procedure Search_Component (R : Entity_Id) is
9899 Comp := First_Component_Or_Discriminant (R);
9900 while Present (Comp) loop
9902 -- Ignore error of attribute name for component name (we
9903 -- already gave an error message for this, so no need to
9906 if Nkind (Component_Name (CC)) = N_Attribute_Reference then
9909 exit when Chars (Comp) = Chars (Component_Name (CC));
9912 Next_Component_Or_Discriminant (Comp);
9914 end Search_Component;
9916 -- Start of processing for Find_Component
9919 -- Return with Comp set to Empty if we have a pragma
9921 if Nkind (CC) = N_Pragma then
9926 -- Search current record for matching component
9928 Search_Component (Rectype);
9930 -- If not found, maybe component of base type discriminant that is
9931 -- absent from statically constrained first subtype.
9934 Search_Component (Base_Type (Rectype));
9937 -- If no component, or the component does not reference the component
9938 -- clause in question, then there was some previous error for which
9939 -- we already gave a message, so just return with Comp Empty.
9941 if No (Comp) or else Component_Clause (Comp) /= CC then
9942 Check_Error_Detected;
9945 -- Normal case where we have a component clause
9948 Fbit := Component_Bit_Offset (Comp);
9949 Lbit := Fbit + Esize (Comp) - 1;
9953 -- Start of processing for Check_Record_Representation_Clause
9957 Rectype := Entity (Ident);
9959 if Rectype = Any_Type then
9962 Rectype := Underlying_Type (Rectype);
9965 -- See if we have a fully repped derived tagged type
9968 PS : constant Entity_Id := Parent_Subtype (Rectype);
9971 if Present (PS) and then Is_Fully_Repped_Tagged_Type (PS) then
9972 Tagged_Parent := PS;
9974 -- Find maximum bit of any component of the parent type
9976 Parent_Last_Bit := UI_From_Int (System_Address_Size - 1);
9977 Pcomp := First_Entity (Tagged_Parent);
9978 while Present (Pcomp) loop
9979 if Ekind_In (Pcomp, E_Discriminant, E_Component) then
9980 if Component_Bit_Offset (Pcomp) /= No_Uint
9981 and then Known_Static_Esize (Pcomp)
9986 Component_Bit_Offset (Pcomp) + Esize (Pcomp) - 1);
9990 -- Skip anonymous types generated for constrained array
9991 -- or record components.
9996 Next_Entity (Pcomp);
10001 -- All done if no component clauses
10003 CC := First (Component_Clauses (N));
10009 -- If a tag is present, then create a component clause that places it
10010 -- at the start of the record (otherwise gigi may place it after other
10011 -- fields that have rep clauses).
10013 Fent := First_Entity (Rectype);
10015 if Nkind (Fent) = N_Defining_Identifier
10016 and then Chars (Fent) = Name_uTag
10018 Set_Component_Bit_Offset (Fent, Uint_0);
10019 Set_Normalized_Position (Fent, Uint_0);
10020 Set_Normalized_First_Bit (Fent, Uint_0);
10021 Set_Normalized_Position_Max (Fent, Uint_0);
10022 Init_Esize (Fent, System_Address_Size);
10024 Set_Component_Clause (Fent,
10025 Make_Component_Clause (Loc,
10026 Component_Name => Make_Identifier (Loc, Name_uTag),
10028 Position => Make_Integer_Literal (Loc, Uint_0),
10029 First_Bit => Make_Integer_Literal (Loc, Uint_0),
10031 Make_Integer_Literal (Loc,
10032 UI_From_Int (System_Address_Size))));
10034 Ccount := Ccount + 1;
10037 Max_Bit_So_Far := Uint_Minus_1;
10038 Overlap_Check_Required := False;
10040 -- Process the component clauses
10042 while Present (CC) loop
10045 if Present (Comp) then
10046 Ccount := Ccount + 1;
10048 -- We need a full overlap check if record positions non-monotonic
10050 if Fbit <= Max_Bit_So_Far then
10051 Overlap_Check_Required := True;
10054 Max_Bit_So_Far := Lbit;
10056 -- Check bit position out of range of specified size
10058 if Has_Size_Clause (Rectype)
10059 and then RM_Size (Rectype) <= Lbit
10062 ("bit number out of range of specified size",
10065 -- Check for overlap with tag component
10068 if Is_Tagged_Type (Rectype)
10069 and then Fbit < System_Address_Size
10072 ("component overlaps tag field of&",
10073 Component_Name (CC), Rectype);
10074 Overlap_Detected := True;
10077 if Hbit < Lbit then
10082 -- Check parent overlap if component might overlap parent field
10084 if Present (Tagged_Parent) and then Fbit <= Parent_Last_Bit then
10085 Pcomp := First_Component_Or_Discriminant (Tagged_Parent);
10086 while Present (Pcomp) loop
10087 if not Is_Tag (Pcomp)
10088 and then Chars (Pcomp) /= Name_uParent
10090 Check_Component_Overlap (Comp, Pcomp);
10093 Next_Component_Or_Discriminant (Pcomp);
10101 -- Now that we have processed all the component clauses, check for
10102 -- overlap. We have to leave this till last, since the components can
10103 -- appear in any arbitrary order in the representation clause.
10105 -- We do not need this check if all specified ranges were monotonic,
10106 -- as recorded by Overlap_Check_Required being False at this stage.
10108 -- This first section checks if there are any overlapping entries at
10109 -- all. It does this by sorting all entries and then seeing if there are
10110 -- any overlaps. If there are none, then that is decisive, but if there
10111 -- are overlaps, they may still be OK (they may result from fields in
10112 -- different variants).
10114 if Overlap_Check_Required then
10115 Overlap_Check1 : declare
10117 OC_Fbit : array (0 .. Ccount) of Uint;
10118 -- First-bit values for component clauses, the value is the offset
10119 -- of the first bit of the field from start of record. The zero
10120 -- entry is for use in sorting.
10122 OC_Lbit : array (0 .. Ccount) of Uint;
10123 -- Last-bit values for component clauses, the value is the offset
10124 -- of the last bit of the field from start of record. The zero
10125 -- entry is for use in sorting.
10127 OC_Count : Natural := 0;
10128 -- Count of entries in OC_Fbit and OC_Lbit
10130 function OC_Lt (Op1, Op2 : Natural) return Boolean;
10131 -- Compare routine for Sort
10133 procedure OC_Move (From : Natural; To : Natural);
10134 -- Move routine for Sort
10136 package Sorting is new GNAT.Heap_Sort_G (OC_Move, OC_Lt);
10142 function OC_Lt (Op1, Op2 : Natural) return Boolean is
10144 return OC_Fbit (Op1) < OC_Fbit (Op2);
10151 procedure OC_Move (From : Natural; To : Natural) is
10153 OC_Fbit (To) := OC_Fbit (From);
10154 OC_Lbit (To) := OC_Lbit (From);
10157 -- Start of processing for Overlap_Check
10160 CC := First (Component_Clauses (N));
10161 while Present (CC) loop
10163 -- Exclude component clause already marked in error
10165 if not Error_Posted (CC) then
10168 if Present (Comp) then
10169 OC_Count := OC_Count + 1;
10170 OC_Fbit (OC_Count) := Fbit;
10171 OC_Lbit (OC_Count) := Lbit;
10178 Sorting.Sort (OC_Count);
10180 Overlap_Check_Required := False;
10181 for J in 1 .. OC_Count - 1 loop
10182 if OC_Lbit (J) >= OC_Fbit (J + 1) then
10183 Overlap_Check_Required := True;
10187 end Overlap_Check1;
10190 -- If Overlap_Check_Required is still True, then we have to do the full
10191 -- scale overlap check, since we have at least two fields that do
10192 -- overlap, and we need to know if that is OK since they are in
10193 -- different variant, or whether we have a definite problem.
10195 if Overlap_Check_Required then
10196 Overlap_Check2 : declare
10197 C1_Ent, C2_Ent : Entity_Id;
10198 -- Entities of components being checked for overlap
10201 -- Component_List node whose Component_Items are being checked
10204 -- Component declaration for component being checked
10207 C1_Ent := First_Entity (Base_Type (Rectype));
10209 -- Loop through all components in record. For each component check
10210 -- for overlap with any of the preceding elements on the component
10211 -- list containing the component and also, if the component is in
10212 -- a variant, check against components outside the case structure.
10213 -- This latter test is repeated recursively up the variant tree.
10215 Main_Component_Loop : while Present (C1_Ent) loop
10216 if not Ekind_In (C1_Ent, E_Component, E_Discriminant) then
10217 goto Continue_Main_Component_Loop;
10220 -- Skip overlap check if entity has no declaration node. This
10221 -- happens with discriminants in constrained derived types.
10222 -- Possibly we are missing some checks as a result, but that
10223 -- does not seem terribly serious.
10225 if No (Declaration_Node (C1_Ent)) then
10226 goto Continue_Main_Component_Loop;
10229 Clist := Parent (List_Containing (Declaration_Node (C1_Ent)));
10231 -- Loop through component lists that need checking. Check the
10232 -- current component list and all lists in variants above us.
10234 Component_List_Loop : loop
10236 -- If derived type definition, go to full declaration
10237 -- If at outer level, check discriminants if there are any.
10239 if Nkind (Clist) = N_Derived_Type_Definition then
10240 Clist := Parent (Clist);
10243 -- Outer level of record definition, check discriminants
10245 if Nkind_In (Clist, N_Full_Type_Declaration,
10246 N_Private_Type_Declaration)
10248 if Has_Discriminants (Defining_Identifier (Clist)) then
10250 First_Discriminant (Defining_Identifier (Clist));
10251 while Present (C2_Ent) loop
10252 exit when C1_Ent = C2_Ent;
10253 Check_Component_Overlap (C1_Ent, C2_Ent);
10254 Next_Discriminant (C2_Ent);
10258 -- Record extension case
10260 elsif Nkind (Clist) = N_Derived_Type_Definition then
10263 -- Otherwise check one component list
10266 Citem := First (Component_Items (Clist));
10267 while Present (Citem) loop
10268 if Nkind (Citem) = N_Component_Declaration then
10269 C2_Ent := Defining_Identifier (Citem);
10270 exit when C1_Ent = C2_Ent;
10271 Check_Component_Overlap (C1_Ent, C2_Ent);
10278 -- Check for variants above us (the parent of the Clist can
10279 -- be a variant, in which case its parent is a variant part,
10280 -- and the parent of the variant part is a component list
10281 -- whose components must all be checked against the current
10282 -- component for overlap).
10284 if Nkind (Parent (Clist)) = N_Variant then
10285 Clist := Parent (Parent (Parent (Clist)));
10287 -- Check for possible discriminant part in record, this
10288 -- is treated essentially as another level in the
10289 -- recursion. For this case the parent of the component
10290 -- list is the record definition, and its parent is the
10291 -- full type declaration containing the discriminant
10294 elsif Nkind (Parent (Clist)) = N_Record_Definition then
10295 Clist := Parent (Parent ((Clist)));
10297 -- If neither of these two cases, we are at the top of
10301 exit Component_List_Loop;
10303 end loop Component_List_Loop;
10305 <<Continue_Main_Component_Loop>>
10306 Next_Entity (C1_Ent);
10308 end loop Main_Component_Loop;
10309 end Overlap_Check2;
10312 -- The following circuit deals with warning on record holes (gaps). We
10313 -- skip this check if overlap was detected, since it makes sense for the
10314 -- programmer to fix this illegality before worrying about warnings.
10316 if not Overlap_Detected and Warn_On_Record_Holes then
10317 Record_Hole_Check : declare
10318 Decl : constant Node_Id := Declaration_Node (Base_Type (Rectype));
10319 -- Full declaration of record type
10321 procedure Check_Component_List
10325 -- Check component list CL for holes. The starting bit should be
10326 -- Sbit. which is zero for the main record component list and set
10327 -- appropriately for recursive calls for variants. DS is set to
10328 -- a list of discriminant specifications to be included in the
10329 -- consideration of components. It is No_List if none to consider.
10331 --------------------------
10332 -- Check_Component_List --
10333 --------------------------
10335 procedure Check_Component_List
10343 Compl := Integer (List_Length (Component_Items (CL)));
10345 if DS /= No_List then
10346 Compl := Compl + Integer (List_Length (DS));
10350 Comps : array (Natural range 0 .. Compl) of Entity_Id;
10351 -- Gather components (zero entry is for sort routine)
10353 Ncomps : Natural := 0;
10354 -- Number of entries stored in Comps (starting at Comps (1))
10357 -- One component item or discriminant specification
10360 -- Starting bit for next component
10363 -- Component entity
10368 function Lt (Op1, Op2 : Natural) return Boolean;
10369 -- Compare routine for Sort
10371 procedure Move (From : Natural; To : Natural);
10372 -- Move routine for Sort
10374 package Sorting is new GNAT.Heap_Sort_G (Move, Lt);
10380 function Lt (Op1, Op2 : Natural) return Boolean is
10382 return Component_Bit_Offset (Comps (Op1))
10384 Component_Bit_Offset (Comps (Op2));
10391 procedure Move (From : Natural; To : Natural) is
10393 Comps (To) := Comps (From);
10397 -- Gather discriminants into Comp
10399 if DS /= No_List then
10400 Citem := First (DS);
10401 while Present (Citem) loop
10402 if Nkind (Citem) = N_Discriminant_Specification then
10404 Ent : constant Entity_Id :=
10405 Defining_Identifier (Citem);
10407 if Ekind (Ent) = E_Discriminant then
10408 Ncomps := Ncomps + 1;
10409 Comps (Ncomps) := Ent;
10418 -- Gather component entities into Comp
10420 Citem := First (Component_Items (CL));
10421 while Present (Citem) loop
10422 if Nkind (Citem) = N_Component_Declaration then
10423 Ncomps := Ncomps + 1;
10424 Comps (Ncomps) := Defining_Identifier (Citem);
10430 -- Now sort the component entities based on the first bit.
10431 -- Note we already know there are no overlapping components.
10433 Sorting.Sort (Ncomps);
10435 -- Loop through entries checking for holes
10438 for J in 1 .. Ncomps loop
10442 CBO : constant Uint := Component_Bit_Offset (CEnt);
10445 -- Skip components with unknown offsets
10447 if CBO /= No_Uint and then CBO >= 0 then
10448 Error_Msg_Uint_1 := CBO - Nbit;
10450 if Error_Msg_Uint_1 > 0 then
10452 ("?H?^-bit gap before component&",
10453 Component_Name (Component_Clause (CEnt)),
10457 Nbit := CBO + Esize (CEnt);
10462 -- Process variant parts recursively if present
10464 if Present (Variant_Part (CL)) then
10465 Variant := First (Variants (Variant_Part (CL)));
10466 while Present (Variant) loop
10467 Check_Component_List
10468 (Component_List (Variant), Nbit, No_List);
10473 end Check_Component_List;
10475 -- Start of processing for Record_Hole_Check
10482 if Is_Tagged_Type (Rectype) then
10483 Sbit := UI_From_Int (System_Address_Size);
10488 if Nkind (Decl) = N_Full_Type_Declaration
10489 and then Nkind (Type_Definition (Decl)) = N_Record_Definition
10491 Check_Component_List
10492 (Component_List (Type_Definition (Decl)),
10494 Discriminant_Specifications (Decl));
10497 end Record_Hole_Check;
10500 -- For records that have component clauses for all components, and whose
10501 -- size is less than or equal to 32, we need to know the size in the
10502 -- front end to activate possible packed array processing where the
10503 -- component type is a record.
10505 -- At this stage Hbit + 1 represents the first unused bit from all the
10506 -- component clauses processed, so if the component clauses are
10507 -- complete, then this is the length of the record.
10509 -- For records longer than System.Storage_Unit, and for those where not
10510 -- all components have component clauses, the back end determines the
10511 -- length (it may for example be appropriate to round up the size
10512 -- to some convenient boundary, based on alignment considerations, etc).
10514 if Unknown_RM_Size (Rectype) and then Hbit + 1 <= 32 then
10516 -- Nothing to do if at least one component has no component clause
10518 Comp := First_Component_Or_Discriminant (Rectype);
10519 while Present (Comp) loop
10520 exit when No (Component_Clause (Comp));
10521 Next_Component_Or_Discriminant (Comp);
10524 -- If we fall out of loop, all components have component clauses
10525 -- and so we can set the size to the maximum value.
10528 Set_RM_Size (Rectype, Hbit + 1);
10531 end Check_Record_Representation_Clause;
10537 procedure Check_Size
10541 Biased : out Boolean)
10543 procedure Size_Too_Small_Error (Min_Siz : Uint);
10544 -- Emit an error concerning illegal size Siz. Min_Siz denotes the
10547 --------------------------
10548 -- Size_Too_Small_Error --
10549 --------------------------
10551 procedure Size_Too_Small_Error (Min_Siz : Uint) is
10553 -- This error is suppressed in ASIS mode to allow for different ASIS
10554 -- back ends or ASIS-based tools to query the illegal clause.
10556 if not ASIS_Mode then
10557 Error_Msg_Uint_1 := Min_Siz;
10558 Error_Msg_NE ("size for& too small, minimum allowed is ^", N, T);
10560 end Size_Too_Small_Error;
10564 UT : constant Entity_Id := Underlying_Type (T);
10567 -- Start of processing for Check_Size
10572 -- Reject patently improper size values
10574 if Is_Elementary_Type (T)
10575 and then Siz > UI_From_Int (Int'Last)
10577 Error_Msg_N ("Size value too large for elementary type", N);
10579 if Nkind (Original_Node (N)) = N_Op_Expon then
10581 ("\maybe '* was meant, rather than '*'*", Original_Node (N));
10585 -- Dismiss generic types
10587 if Is_Generic_Type (T)
10589 Is_Generic_Type (UT)
10591 Is_Generic_Type (Root_Type (UT))
10595 -- Guard against previous errors
10597 elsif No (UT) or else UT = Any_Type then
10598 Check_Error_Detected;
10601 -- Check case of bit packed array
10603 elsif Is_Array_Type (UT)
10604 and then Known_Static_Component_Size (UT)
10605 and then Is_Bit_Packed_Array (UT)
10613 Asiz := Component_Size (UT);
10614 Indx := First_Index (UT);
10616 Ityp := Etype (Indx);
10618 -- If non-static bound, then we are not in the business of
10619 -- trying to check the length, and indeed an error will be
10620 -- issued elsewhere, since sizes of non-static array types
10621 -- cannot be set implicitly or explicitly.
10623 if not Is_OK_Static_Subtype (Ityp) then
10627 -- Otherwise accumulate next dimension
10629 Asiz := Asiz * (Expr_Value (Type_High_Bound (Ityp)) -
10630 Expr_Value (Type_Low_Bound (Ityp)) +
10634 exit when No (Indx);
10637 if Asiz <= Siz then
10641 Size_Too_Small_Error (Asiz);
10642 Set_Esize (T, Asiz);
10643 Set_RM_Size (T, Asiz);
10647 -- All other composite types are ignored
10649 elsif Is_Composite_Type (UT) then
10652 -- For fixed-point types, don't check minimum if type is not frozen,
10653 -- since we don't know all the characteristics of the type that can
10654 -- affect the size (e.g. a specified small) till freeze time.
10656 elsif Is_Fixed_Point_Type (UT) and then not Is_Frozen (UT) then
10659 -- Cases for which a minimum check is required
10662 -- Ignore if specified size is correct for the type
10664 if Known_Esize (UT) and then Siz = Esize (UT) then
10668 -- Otherwise get minimum size
10670 M := UI_From_Int (Minimum_Size (UT));
10674 -- Size is less than minimum size, but one possibility remains
10675 -- that we can manage with the new size if we bias the type.
10677 M := UI_From_Int (Minimum_Size (UT, Biased => True));
10680 Size_Too_Small_Error (M);
10682 Set_RM_Size (T, M);
10690 --------------------------
10691 -- Freeze_Entity_Checks --
10692 --------------------------
10694 procedure Freeze_Entity_Checks (N : Node_Id) is
10695 procedure Hide_Non_Overridden_Subprograms (Typ : Entity_Id);
10696 -- Inspect the primitive operations of type Typ and hide all pairs of
10697 -- implicitly declared non-overridden non-fully conformant homographs
10698 -- (Ada RM 8.3 12.3/2).
10700 -------------------------------------
10701 -- Hide_Non_Overridden_Subprograms --
10702 -------------------------------------
10704 procedure Hide_Non_Overridden_Subprograms (Typ : Entity_Id) is
10705 procedure Hide_Matching_Homographs
10706 (Subp_Id : Entity_Id;
10707 Start_Elmt : Elmt_Id);
10708 -- Inspect a list of primitive operations starting with Start_Elmt
10709 -- and find matching implicitly declared non-overridden non-fully
10710 -- conformant homographs of Subp_Id. If found, all matches along
10711 -- with Subp_Id are hidden from all visibility.
10713 function Is_Non_Overridden_Or_Null_Procedure
10714 (Subp_Id : Entity_Id) return Boolean;
10715 -- Determine whether subprogram Subp_Id is implicitly declared non-
10716 -- overridden subprogram or an implicitly declared null procedure.
10718 ------------------------------
10719 -- Hide_Matching_Homographs --
10720 ------------------------------
10722 procedure Hide_Matching_Homographs
10723 (Subp_Id : Entity_Id;
10724 Start_Elmt : Elmt_Id)
10727 Prim_Elmt : Elmt_Id;
10730 Prim_Elmt := Start_Elmt;
10731 while Present (Prim_Elmt) loop
10732 Prim := Node (Prim_Elmt);
10734 -- The current primitive is implicitly declared non-overridden
10735 -- non-fully conformant homograph of Subp_Id. Both subprograms
10736 -- must be hidden from visibility.
10738 if Chars (Prim) = Chars (Subp_Id)
10739 and then Is_Non_Overridden_Or_Null_Procedure (Prim)
10740 and then not Fully_Conformant (Prim, Subp_Id)
10742 Set_Is_Hidden_Non_Overridden_Subpgm (Prim);
10743 Set_Is_Immediately_Visible (Prim, False);
10744 Set_Is_Potentially_Use_Visible (Prim, False);
10746 Set_Is_Hidden_Non_Overridden_Subpgm (Subp_Id);
10747 Set_Is_Immediately_Visible (Subp_Id, False);
10748 Set_Is_Potentially_Use_Visible (Subp_Id, False);
10751 Next_Elmt (Prim_Elmt);
10753 end Hide_Matching_Homographs;
10755 -----------------------------------------
10756 -- Is_Non_Overridden_Or_Null_Procedure --
10757 -----------------------------------------
10759 function Is_Non_Overridden_Or_Null_Procedure
10760 (Subp_Id : Entity_Id) return Boolean
10762 Alias_Id : Entity_Id;
10765 -- The subprogram is inherited (implicitly declared), it does not
10766 -- override and does not cover a primitive of an interface.
10768 if Ekind_In (Subp_Id, E_Function, E_Procedure)
10769 and then Present (Alias (Subp_Id))
10770 and then No (Interface_Alias (Subp_Id))
10771 and then No (Overridden_Operation (Subp_Id))
10773 Alias_Id := Alias (Subp_Id);
10775 if Requires_Overriding (Alias_Id) then
10778 elsif Nkind (Parent (Alias_Id)) = N_Procedure_Specification
10779 and then Null_Present (Parent (Alias_Id))
10786 end Is_Non_Overridden_Or_Null_Procedure;
10790 Prim_Ops : constant Elist_Id := Direct_Primitive_Operations (Typ);
10792 Prim_Elmt : Elmt_Id;
10794 -- Start of processing for Hide_Non_Overridden_Subprograms
10797 -- Inspect the list of primitives looking for non-overridden
10800 if Present (Prim_Ops) then
10801 Prim_Elmt := First_Elmt (Prim_Ops);
10802 while Present (Prim_Elmt) loop
10803 Prim := Node (Prim_Elmt);
10804 Next_Elmt (Prim_Elmt);
10806 if Is_Non_Overridden_Or_Null_Procedure (Prim) then
10807 Hide_Matching_Homographs
10809 Start_Elmt => Prim_Elmt);
10813 end Hide_Non_Overridden_Subprograms;
10817 E : constant Entity_Id := Entity (N);
10819 Non_Generic_Case : constant Boolean := Nkind (N) = N_Freeze_Entity;
10820 -- True in non-generic case. Some of the processing here is skipped
10821 -- for the generic case since it is not needed. Basically in the
10822 -- generic case, we only need to do stuff that might generate error
10823 -- messages or warnings.
10825 -- Start of processing for Freeze_Entity_Checks
10828 -- Remember that we are processing a freezing entity. Required to
10829 -- ensure correct decoration of internal entities associated with
10830 -- interfaces (see New_Overloaded_Entity).
10832 Inside_Freezing_Actions := Inside_Freezing_Actions + 1;
10834 -- For tagged types covering interfaces add internal entities that link
10835 -- the primitives of the interfaces with the primitives that cover them.
10836 -- Note: These entities were originally generated only when generating
10837 -- code because their main purpose was to provide support to initialize
10838 -- the secondary dispatch tables. They are now generated also when
10839 -- compiling with no code generation to provide ASIS the relationship
10840 -- between interface primitives and tagged type primitives. They are
10841 -- also used to locate primitives covering interfaces when processing
10842 -- generics (see Derive_Subprograms).
10844 -- This is not needed in the generic case
10846 if Ada_Version >= Ada_2005
10847 and then Non_Generic_Case
10848 and then Ekind (E) = E_Record_Type
10849 and then Is_Tagged_Type (E)
10850 and then not Is_Interface (E)
10851 and then Has_Interfaces (E)
10853 -- This would be a good common place to call the routine that checks
10854 -- overriding of interface primitives (and thus factorize calls to
10855 -- Check_Abstract_Overriding located at different contexts in the
10856 -- compiler). However, this is not possible because it causes
10857 -- spurious errors in case of late overriding.
10859 Add_Internal_Interface_Entities (E);
10862 -- After all forms of overriding have been resolved, a tagged type may
10863 -- be left with a set of implicitly declared and possibly erroneous
10864 -- abstract subprograms, null procedures and subprograms that require
10865 -- overriding. If this set contains fully conformant homographs, then
10866 -- one is chosen arbitrarily (already done during resolution), otherwise
10867 -- all remaining non-fully conformant homographs are hidden from
10868 -- visibility (Ada RM 8.3 12.3/2).
10870 if Is_Tagged_Type (E) then
10871 Hide_Non_Overridden_Subprograms (E);
10876 if Ekind (E) = E_Record_Type
10877 and then Is_CPP_Class (E)
10878 and then Is_Tagged_Type (E)
10879 and then Tagged_Type_Expansion
10881 if CPP_Num_Prims (E) = 0 then
10883 -- If the CPP type has user defined components then it must import
10884 -- primitives from C++. This is required because if the C++ class
10885 -- has no primitives then the C++ compiler does not added the _tag
10886 -- component to the type.
10888 if First_Entity (E) /= Last_Entity (E) then
10890 ("'C'P'P type must import at least one primitive from C++??",
10895 -- Check that all its primitives are abstract or imported from C++.
10896 -- Check also availability of the C++ constructor.
10899 Has_Constructors : constant Boolean := Has_CPP_Constructors (E);
10901 Error_Reported : Boolean := False;
10905 Elmt := First_Elmt (Primitive_Operations (E));
10906 while Present (Elmt) loop
10907 Prim := Node (Elmt);
10909 if Comes_From_Source (Prim) then
10910 if Is_Abstract_Subprogram (Prim) then
10913 elsif not Is_Imported (Prim)
10914 or else Convention (Prim) /= Convention_CPP
10917 ("primitives of 'C'P'P types must be imported from C++ "
10918 & "or abstract??", Prim);
10920 elsif not Has_Constructors
10921 and then not Error_Reported
10923 Error_Msg_Name_1 := Chars (E);
10925 ("??'C'P'P constructor required for type %", Prim);
10926 Error_Reported := True;
10935 -- Check Ada derivation of CPP type
10937 if Expander_Active -- why? losing errors in -gnatc mode???
10938 and then Present (Etype (E)) -- defend against errors
10939 and then Tagged_Type_Expansion
10940 and then Ekind (E) = E_Record_Type
10941 and then Etype (E) /= E
10942 and then Is_CPP_Class (Etype (E))
10943 and then CPP_Num_Prims (Etype (E)) > 0
10944 and then not Is_CPP_Class (E)
10945 and then not Has_CPP_Constructors (Etype (E))
10947 -- If the parent has C++ primitives but it has no constructor then
10948 -- check that all the primitives are overridden in this derivation;
10949 -- otherwise the constructor of the parent is needed to build the
10957 Elmt := First_Elmt (Primitive_Operations (E));
10958 while Present (Elmt) loop
10959 Prim := Node (Elmt);
10961 if not Is_Abstract_Subprogram (Prim)
10962 and then No (Interface_Alias (Prim))
10963 and then Find_Dispatching_Type (Ultimate_Alias (Prim)) /= E
10965 Error_Msg_Name_1 := Chars (Etype (E));
10967 ("'C'P'P constructor required for parent type %", E);
10976 Inside_Freezing_Actions := Inside_Freezing_Actions - 1;
10978 -- If we have a type with predicates, build predicate function. This is
10979 -- not needed in the generic case, nor within TSS subprograms and other
10980 -- predefined primitives.
10983 and then Non_Generic_Case
10984 and then not Within_Internal_Subprogram
10985 and then Has_Predicates (E)
10987 Build_Predicate_Functions (E, N);
10990 -- If type has delayed aspects, this is where we do the preanalysis at
10991 -- the freeze point, as part of the consistent visibility check. Note
10992 -- that this must be done after calling Build_Predicate_Functions or
10993 -- Build_Invariant_Procedure since these subprograms fix occurrences of
10994 -- the subtype name in the saved expression so that they will not cause
10995 -- trouble in the preanalysis.
10997 -- This is also not needed in the generic case
10999 if Non_Generic_Case
11000 and then Has_Delayed_Aspects (E)
11001 and then Scope (E) = Current_Scope
11003 -- Retrieve the visibility to the discriminants in order to properly
11004 -- analyze the aspects.
11006 Push_Scope_And_Install_Discriminants (E);
11012 -- Look for aspect specification entries for this entity
11014 Ritem := First_Rep_Item (E);
11015 while Present (Ritem) loop
11016 if Nkind (Ritem) = N_Aspect_Specification
11017 and then Entity (Ritem) = E
11018 and then Is_Delayed_Aspect (Ritem)
11020 Check_Aspect_At_Freeze_Point (Ritem);
11023 Next_Rep_Item (Ritem);
11027 Uninstall_Discriminants_And_Pop_Scope (E);
11030 -- For a record type, deal with variant parts. This has to be delayed
11031 -- to this point, because of the issue of statically predicated
11032 -- subtypes, which we have to ensure are frozen before checking
11033 -- choices, since we need to have the static choice list set.
11035 if Is_Record_Type (E) then
11036 Check_Variant_Part : declare
11037 D : constant Node_Id := Declaration_Node (E);
11042 Others_Present : Boolean;
11043 pragma Warnings (Off, Others_Present);
11044 -- Indicates others present, not used in this case
11046 procedure Non_Static_Choice_Error (Choice : Node_Id);
11047 -- Error routine invoked by the generic instantiation below when
11048 -- the variant part has a non static choice.
11050 procedure Process_Declarations (Variant : Node_Id);
11051 -- Processes declarations associated with a variant. We analyzed
11052 -- the declarations earlier (in Sem_Ch3.Analyze_Variant_Part),
11053 -- but we still need the recursive call to Check_Choices for any
11054 -- nested variant to get its choices properly processed. This is
11055 -- also where we expand out the choices if expansion is active.
11057 package Variant_Choices_Processing is new
11058 Generic_Check_Choices
11059 (Process_Empty_Choice => No_OP,
11060 Process_Non_Static_Choice => Non_Static_Choice_Error,
11061 Process_Associated_Node => Process_Declarations);
11062 use Variant_Choices_Processing;
11064 -----------------------------
11065 -- Non_Static_Choice_Error --
11066 -----------------------------
11068 procedure Non_Static_Choice_Error (Choice : Node_Id) is
11070 Flag_Non_Static_Expr
11071 ("choice given in variant part is not static!", Choice);
11072 end Non_Static_Choice_Error;
11074 --------------------------
11075 -- Process_Declarations --
11076 --------------------------
11078 procedure Process_Declarations (Variant : Node_Id) is
11079 CL : constant Node_Id := Component_List (Variant);
11083 -- Check for static predicate present in this variant
11085 if Has_SP_Choice (Variant) then
11087 -- Here we expand. You might expect to find this call in
11088 -- Expand_N_Variant_Part, but that is called when we first
11089 -- see the variant part, and we cannot do this expansion
11090 -- earlier than the freeze point, since for statically
11091 -- predicated subtypes, the predicate is not known till
11092 -- the freeze point.
11094 -- Furthermore, we do this expansion even if the expander
11095 -- is not active, because other semantic processing, e.g.
11096 -- for aggregates, requires the expanded list of choices.
11098 -- If the expander is not active, then we can't just clobber
11099 -- the list since it would invalidate the ASIS -gnatct tree.
11100 -- So we have to rewrite the variant part with a Rewrite
11101 -- call that replaces it with a copy and clobber the copy.
11103 if not Expander_Active then
11105 NewV : constant Node_Id := New_Copy (Variant);
11107 Set_Discrete_Choices
11108 (NewV, New_Copy_List (Discrete_Choices (Variant)));
11109 Rewrite (Variant, NewV);
11113 Expand_Static_Predicates_In_Choices (Variant);
11116 -- We don't need to worry about the declarations in the variant
11117 -- (since they were analyzed by Analyze_Choices when we first
11118 -- encountered the variant), but we do need to take care of
11119 -- expansion of any nested variants.
11121 if not Null_Present (CL) then
11122 VP := Variant_Part (CL);
11124 if Present (VP) then
11126 (VP, Variants (VP), Etype (Name (VP)), Others_Present);
11129 end Process_Declarations;
11131 -- Start of processing for Check_Variant_Part
11134 -- Find component list
11138 if Nkind (D) = N_Full_Type_Declaration then
11139 T := Type_Definition (D);
11141 if Nkind (T) = N_Record_Definition then
11142 C := Component_List (T);
11144 elsif Nkind (T) = N_Derived_Type_Definition
11145 and then Present (Record_Extension_Part (T))
11147 C := Component_List (Record_Extension_Part (T));
11151 -- Case of variant part present
11153 if Present (C) and then Present (Variant_Part (C)) then
11154 VP := Variant_Part (C);
11159 (VP, Variants (VP), Etype (Name (VP)), Others_Present);
11161 -- If the last variant does not contain the Others choice,
11162 -- replace it with an N_Others_Choice node since Gigi always
11163 -- wants an Others. Note that we do not bother to call Analyze
11164 -- on the modified variant part, since its only effect would be
11165 -- to compute the Others_Discrete_Choices node laboriously, and
11166 -- of course we already know the list of choices corresponding
11167 -- to the others choice (it's the list we're replacing).
11169 -- We only want to do this if the expander is active, since
11170 -- we do not want to clobber the ASIS tree.
11172 if Expander_Active then
11174 Last_Var : constant Node_Id :=
11175 Last_Non_Pragma (Variants (VP));
11177 Others_Node : Node_Id;
11180 if Nkind (First (Discrete_Choices (Last_Var))) /=
11183 Others_Node := Make_Others_Choice (Sloc (Last_Var));
11184 Set_Others_Discrete_Choices
11185 (Others_Node, Discrete_Choices (Last_Var));
11186 Set_Discrete_Choices
11187 (Last_Var, New_List (Others_Node));
11192 end Check_Variant_Part;
11194 end Freeze_Entity_Checks;
11196 -------------------------
11197 -- Get_Alignment_Value --
11198 -------------------------
11200 function Get_Alignment_Value (Expr : Node_Id) return Uint is
11201 Align : constant Uint := Static_Integer (Expr);
11204 if Align = No_Uint then
11207 elsif Align <= 0 then
11209 -- This error is suppressed in ASIS mode to allow for different ASIS
11210 -- back ends or ASIS-based tools to query the illegal clause.
11212 if not ASIS_Mode then
11213 Error_Msg_N ("alignment value must be positive", Expr);
11219 for J in Int range 0 .. 64 loop
11221 M : constant Uint := Uint_2 ** J;
11224 exit when M = Align;
11228 -- This error is suppressed in ASIS mode to allow for
11229 -- different ASIS back ends or ASIS-based tools to query the
11232 if not ASIS_Mode then
11233 Error_Msg_N ("alignment value must be power of 2", Expr);
11243 end Get_Alignment_Value;
11245 -------------------------------------
11246 -- Inherit_Aspects_At_Freeze_Point --
11247 -------------------------------------
11249 procedure Inherit_Aspects_At_Freeze_Point (Typ : Entity_Id) is
11250 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11251 (Rep_Item : Node_Id) return Boolean;
11252 -- This routine checks if Rep_Item is either a pragma or an aspect
11253 -- specification node whose correponding pragma (if any) is present in
11254 -- the Rep Item chain of the entity it has been specified to.
11256 --------------------------------------------------
11257 -- Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item --
11258 --------------------------------------------------
11260 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11261 (Rep_Item : Node_Id) return Boolean
11265 Nkind (Rep_Item) = N_Pragma
11266 or else Present_In_Rep_Item
11267 (Entity (Rep_Item), Aspect_Rep_Item (Rep_Item));
11268 end Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item;
11270 -- Start of processing for Inherit_Aspects_At_Freeze_Point
11273 -- A representation item is either subtype-specific (Size and Alignment
11274 -- clauses) or type-related (all others). Subtype-specific aspects may
11275 -- differ for different subtypes of the same type (RM 13.1.8).
11277 -- A derived type inherits each type-related representation aspect of
11278 -- its parent type that was directly specified before the declaration of
11279 -- the derived type (RM 13.1.15).
11281 -- A derived subtype inherits each subtype-specific representation
11282 -- aspect of its parent subtype that was directly specified before the
11283 -- declaration of the derived type (RM 13.1.15).
11285 -- The general processing involves inheriting a representation aspect
11286 -- from a parent type whenever the first rep item (aspect specification,
11287 -- attribute definition clause, pragma) corresponding to the given
11288 -- representation aspect in the rep item chain of Typ, if any, isn't
11289 -- directly specified to Typ but to one of its parents.
11291 -- ??? Note that, for now, just a limited number of representation
11292 -- aspects have been inherited here so far. Many of them are
11293 -- still inherited in Sem_Ch3. This will be fixed soon. Here is
11294 -- a non- exhaustive list of aspects that likely also need to
11295 -- be moved to this routine: Alignment, Component_Alignment,
11296 -- Component_Size, Machine_Radix, Object_Size, Pack, Predicates,
11297 -- Preelaborable_Initialization, RM_Size and Small.
11299 -- In addition, Convention must be propagated from base type to subtype,
11300 -- because the subtype may have been declared on an incomplete view.
11302 if Nkind (Parent (Typ)) = N_Private_Extension_Declaration then
11308 if not Has_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005, False)
11309 and then Has_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005)
11310 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11311 (Get_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005))
11313 Set_Is_Ada_2005_Only (Typ);
11318 if not Has_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012, False)
11319 and then Has_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012)
11320 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11321 (Get_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012))
11323 Set_Is_Ada_2012_Only (Typ);
11328 if not Has_Rep_Item (Typ, Name_Atomic, Name_Shared, False)
11329 and then Has_Rep_Pragma (Typ, Name_Atomic, Name_Shared)
11330 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11331 (Get_Rep_Item (Typ, Name_Atomic, Name_Shared))
11333 Set_Is_Atomic (Typ);
11334 Set_Is_Volatile (Typ);
11335 Set_Treat_As_Volatile (Typ);
11340 if Is_Record_Type (Typ)
11341 and then Typ /= Base_Type (Typ) and then Is_Frozen (Base_Type (Typ))
11343 Set_Convention (Typ, Convention (Base_Type (Typ)));
11346 -- Default_Component_Value
11348 -- Verify that there is no rep_item declared for the type, and there
11349 -- is one coming from an ancestor.
11351 if Is_Array_Type (Typ)
11352 and then Is_Base_Type (Typ)
11353 and then not Has_Rep_Item (Typ, Name_Default_Component_Value, False)
11354 and then Has_Rep_Item (Typ, Name_Default_Component_Value)
11356 Set_Default_Aspect_Component_Value (Typ,
11357 Default_Aspect_Component_Value
11358 (Entity (Get_Rep_Item (Typ, Name_Default_Component_Value))));
11363 if Is_Scalar_Type (Typ)
11364 and then Is_Base_Type (Typ)
11365 and then not Has_Rep_Item (Typ, Name_Default_Value, False)
11366 and then Has_Rep_Item (Typ, Name_Default_Value)
11368 Set_Has_Default_Aspect (Typ);
11369 Set_Default_Aspect_Value (Typ,
11370 Default_Aspect_Value
11371 (Entity (Get_Rep_Item (Typ, Name_Default_Value))));
11376 if not Has_Rep_Item (Typ, Name_Discard_Names, False)
11377 and then Has_Rep_Item (Typ, Name_Discard_Names)
11378 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11379 (Get_Rep_Item (Typ, Name_Discard_Names))
11381 Set_Discard_Names (Typ);
11386 if not Has_Rep_Item (Typ, Name_Volatile, False)
11387 and then Has_Rep_Item (Typ, Name_Volatile)
11388 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11389 (Get_Rep_Item (Typ, Name_Volatile))
11391 Set_Is_Volatile (Typ);
11392 Set_Treat_As_Volatile (Typ);
11395 -- Volatile_Full_Access
11397 if not Has_Rep_Item (Typ, Name_Volatile_Full_Access, False)
11398 and then Has_Rep_Pragma (Typ, Name_Volatile_Full_Access)
11399 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11400 (Get_Rep_Item (Typ, Name_Volatile_Full_Access))
11402 Set_Is_Volatile_Full_Access (Typ);
11403 Set_Is_Volatile (Typ);
11404 Set_Treat_As_Volatile (Typ);
11407 -- Inheritance for derived types only
11409 if Is_Derived_Type (Typ) then
11411 Bas_Typ : constant Entity_Id := Base_Type (Typ);
11412 Imp_Bas_Typ : constant Entity_Id := Implementation_Base_Type (Typ);
11415 -- Atomic_Components
11417 if not Has_Rep_Item (Typ, Name_Atomic_Components, False)
11418 and then Has_Rep_Item (Typ, Name_Atomic_Components)
11419 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11420 (Get_Rep_Item (Typ, Name_Atomic_Components))
11422 Set_Has_Atomic_Components (Imp_Bas_Typ);
11425 -- Volatile_Components
11427 if not Has_Rep_Item (Typ, Name_Volatile_Components, False)
11428 and then Has_Rep_Item (Typ, Name_Volatile_Components)
11429 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11430 (Get_Rep_Item (Typ, Name_Volatile_Components))
11432 Set_Has_Volatile_Components (Imp_Bas_Typ);
11435 -- Finalize_Storage_Only
11437 if not Has_Rep_Pragma (Typ, Name_Finalize_Storage_Only, False)
11438 and then Has_Rep_Pragma (Typ, Name_Finalize_Storage_Only)
11440 Set_Finalize_Storage_Only (Bas_Typ);
11443 -- Universal_Aliasing
11445 if not Has_Rep_Item (Typ, Name_Universal_Aliasing, False)
11446 and then Has_Rep_Item (Typ, Name_Universal_Aliasing)
11447 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11448 (Get_Rep_Item (Typ, Name_Universal_Aliasing))
11450 Set_Universal_Aliasing (Imp_Bas_Typ);
11455 if Is_Record_Type (Typ) then
11456 if not Has_Rep_Item (Typ, Name_Bit_Order, False)
11457 and then Has_Rep_Item (Typ, Name_Bit_Order)
11459 Set_Reverse_Bit_Order (Bas_Typ,
11460 Reverse_Bit_Order (Entity (Name
11461 (Get_Rep_Item (Typ, Name_Bit_Order)))));
11465 -- Scalar_Storage_Order
11467 -- Note: the aspect is specified on a first subtype, but recorded
11468 -- in a flag of the base type!
11470 if (Is_Record_Type (Typ) or else Is_Array_Type (Typ))
11471 and then Typ = Bas_Typ
11473 -- For a type extension, always inherit from parent; otherwise
11474 -- inherit if no default applies. Note: we do not check for
11475 -- an explicit rep item on the parent type when inheriting,
11476 -- because the parent SSO may itself have been set by default.
11478 if not Has_Rep_Item (First_Subtype (Typ),
11479 Name_Scalar_Storage_Order, False)
11480 and then (Is_Tagged_Type (Bas_Typ)
11481 or else not (SSO_Set_Low_By_Default (Bas_Typ)
11483 SSO_Set_High_By_Default (Bas_Typ)))
11485 Set_Reverse_Storage_Order (Bas_Typ,
11486 Reverse_Storage_Order
11487 (Implementation_Base_Type (Etype (Bas_Typ))));
11489 -- Clear default SSO indications, since the inherited aspect
11490 -- which was set explicitly overrides the default.
11492 Set_SSO_Set_Low_By_Default (Bas_Typ, False);
11493 Set_SSO_Set_High_By_Default (Bas_Typ, False);
11498 end Inherit_Aspects_At_Freeze_Point;
11504 procedure Initialize is
11506 Address_Clause_Checks.Init;
11507 Compile_Time_Warnings_Errors.Init;
11508 Unchecked_Conversions.Init;
11510 if AAMP_On_Target then
11511 Independence_Checks.Init;
11515 ---------------------------
11516 -- Install_Discriminants --
11517 ---------------------------
11519 procedure Install_Discriminants (E : Entity_Id) is
11523 Disc := First_Discriminant (E);
11524 while Present (Disc) loop
11525 Prev := Current_Entity (Disc);
11526 Set_Current_Entity (Disc);
11527 Set_Is_Immediately_Visible (Disc);
11528 Set_Homonym (Disc, Prev);
11529 Next_Discriminant (Disc);
11531 end Install_Discriminants;
11533 -------------------------
11534 -- Is_Operational_Item --
11535 -------------------------
11537 function Is_Operational_Item (N : Node_Id) return Boolean is
11539 if Nkind (N) /= N_Attribute_Definition_Clause then
11544 Id : constant Attribute_Id := Get_Attribute_Id (Chars (N));
11547 -- List of operational items is given in AARM 13.1(8.mm/1).
11548 -- It is clearly incomplete, as it does not include iterator
11549 -- aspects, among others.
11551 return Id = Attribute_Constant_Indexing
11552 or else Id = Attribute_Default_Iterator
11553 or else Id = Attribute_Implicit_Dereference
11554 or else Id = Attribute_Input
11555 or else Id = Attribute_Iterator_Element
11556 or else Id = Attribute_Iterable
11557 or else Id = Attribute_Output
11558 or else Id = Attribute_Read
11559 or else Id = Attribute_Variable_Indexing
11560 or else Id = Attribute_Write
11561 or else Id = Attribute_External_Tag;
11564 end Is_Operational_Item;
11566 -------------------------
11567 -- Is_Predicate_Static --
11568 -------------------------
11570 -- Note: the basic legality of the expression has already been checked, so
11571 -- we don't need to worry about cases or ranges on strings for example.
11573 function Is_Predicate_Static
11575 Nam : Name_Id) return Boolean
11577 function All_Static_Case_Alternatives (L : List_Id) return Boolean;
11578 -- Given a list of case expression alternatives, returns True if all
11579 -- the alternatives are static (have all static choices, and a static
11582 function All_Static_Choices (L : List_Id) return Boolean;
11583 -- Returns true if all elements of the list are OK static choices
11584 -- as defined below for Is_Static_Choice. Used for case expression
11585 -- alternatives and for the right operand of a membership test. An
11586 -- others_choice is static if the corresponding expression is static.
11587 -- The staticness of the bounds is checked separately.
11589 function Is_Static_Choice (N : Node_Id) return Boolean;
11590 -- Returns True if N represents a static choice (static subtype, or
11591 -- static subtype indication, or static expression, or static range).
11593 -- Note that this is a bit more inclusive than we actually need
11594 -- (in particular membership tests do not allow the use of subtype
11595 -- indications). But that doesn't matter, we have already checked
11596 -- that the construct is legal to get this far.
11598 function Is_Type_Ref (N : Node_Id) return Boolean;
11599 pragma Inline (Is_Type_Ref);
11600 -- Returns True if N is a reference to the type for the predicate in the
11601 -- expression (i.e. if it is an identifier whose Chars field matches the
11602 -- Nam given in the call). N must not be parenthesized, if the type name
11603 -- appears in parens, this routine will return False.
11605 -- The routine also returns True for function calls generated during the
11606 -- expansion of comparison operators on strings, which are intended to
11607 -- be legal in static predicates, and are converted into calls to array
11608 -- comparison routines in the body of the corresponding predicate
11611 ----------------------------------
11612 -- All_Static_Case_Alternatives --
11613 ----------------------------------
11615 function All_Static_Case_Alternatives (L : List_Id) return Boolean is
11620 while Present (N) loop
11621 if not (All_Static_Choices (Discrete_Choices (N))
11622 and then Is_OK_Static_Expression (Expression (N)))
11631 end All_Static_Case_Alternatives;
11633 ------------------------
11634 -- All_Static_Choices --
11635 ------------------------
11637 function All_Static_Choices (L : List_Id) return Boolean is
11642 while Present (N) loop
11643 if not Is_Static_Choice (N) then
11651 end All_Static_Choices;
11653 ----------------------
11654 -- Is_Static_Choice --
11655 ----------------------
11657 function Is_Static_Choice (N : Node_Id) return Boolean is
11659 return Nkind (N) = N_Others_Choice
11660 or else Is_OK_Static_Expression (N)
11661 or else (Is_Entity_Name (N) and then Is_Type (Entity (N))
11662 and then Is_OK_Static_Subtype (Entity (N)))
11663 or else (Nkind (N) = N_Subtype_Indication
11664 and then Is_OK_Static_Subtype (Entity (N)))
11665 or else (Nkind (N) = N_Range and then Is_OK_Static_Range (N));
11666 end Is_Static_Choice;
11672 function Is_Type_Ref (N : Node_Id) return Boolean is
11674 return (Nkind (N) = N_Identifier
11675 and then Chars (N) = Nam
11676 and then Paren_Count (N) = 0)
11677 or else Nkind (N) = N_Function_Call;
11680 -- Start of processing for Is_Predicate_Static
11683 -- Predicate_Static means one of the following holds. Numbers are the
11684 -- corresponding paragraph numbers in (RM 3.2.4(16-22)).
11686 -- 16: A static expression
11688 if Is_OK_Static_Expression (Expr) then
11691 -- 17: A membership test whose simple_expression is the current
11692 -- instance, and whose membership_choice_list meets the requirements
11693 -- for a static membership test.
11695 elsif Nkind (Expr) in N_Membership_Test
11696 and then ((Present (Right_Opnd (Expr))
11697 and then Is_Static_Choice (Right_Opnd (Expr)))
11699 (Present (Alternatives (Expr))
11700 and then All_Static_Choices (Alternatives (Expr))))
11704 -- 18. A case_expression whose selecting_expression is the current
11705 -- instance, and whose dependent expressions are static expressions.
11707 elsif Nkind (Expr) = N_Case_Expression
11708 and then Is_Type_Ref (Expression (Expr))
11709 and then All_Static_Case_Alternatives (Alternatives (Expr))
11713 -- 19. A call to a predefined equality or ordering operator, where one
11714 -- operand is the current instance, and the other is a static
11717 -- Note: the RM is clearly wrong here in not excluding string types.
11718 -- Without this exclusion, we would allow expressions like X > "ABC"
11719 -- to be considered as predicate-static, which is clearly not intended,
11720 -- since the idea is for predicate-static to be a subset of normal
11721 -- static expressions (and "DEF" > "ABC" is not a static expression).
11723 -- However, we do allow internally generated (not from source) equality
11724 -- and inequality operations to be valid on strings (this helps deal
11725 -- with cases where we transform A in "ABC" to A = "ABC).
11727 -- In fact, it appears that the intent of the ARG is to extend static
11728 -- predicates to strings, and that the extension should probably apply
11729 -- to static expressions themselves. The code below accepts comparison
11730 -- operators that apply to static strings.
11732 elsif Nkind (Expr) in N_Op_Compare
11733 and then ((Is_Type_Ref (Left_Opnd (Expr))
11734 and then Is_OK_Static_Expression (Right_Opnd (Expr)))
11736 (Is_Type_Ref (Right_Opnd (Expr))
11737 and then Is_OK_Static_Expression (Left_Opnd (Expr))))
11741 -- 20. A call to a predefined boolean logical operator, where each
11742 -- operand is predicate-static.
11744 elsif (Nkind_In (Expr, N_Op_And, N_Op_Or, N_Op_Xor)
11745 and then Is_Predicate_Static (Left_Opnd (Expr), Nam)
11746 and then Is_Predicate_Static (Right_Opnd (Expr), Nam))
11748 (Nkind (Expr) = N_Op_Not
11749 and then Is_Predicate_Static (Right_Opnd (Expr), Nam))
11753 -- 21. A short-circuit control form where both operands are
11754 -- predicate-static.
11756 elsif Nkind (Expr) in N_Short_Circuit
11757 and then Is_Predicate_Static (Left_Opnd (Expr), Nam)
11758 and then Is_Predicate_Static (Right_Opnd (Expr), Nam)
11762 -- 22. A parenthesized predicate-static expression. This does not
11763 -- require any special test, since we just ignore paren levels in
11764 -- all the cases above.
11766 -- One more test that is an implementation artifact caused by the fact
11767 -- that we are analyzing not the original expression, but the generated
11768 -- expression in the body of the predicate function. This can include
11769 -- references to inherited predicates, so that the expression we are
11770 -- processing looks like:
11772 -- xxPredicate (typ (Inns)) and then expression
11774 -- Where the call is to a Predicate function for an inherited predicate.
11775 -- We simply ignore such a call, which could be to either a dynamic or
11776 -- a static predicate. Note that if the parent predicate is dynamic then
11777 -- eventually this type will be marked as dynamic, but you are allowed
11778 -- to specify a static predicate for a subtype which is inheriting a
11779 -- dynamic predicate, so the static predicate validation here ignores
11780 -- the inherited predicate even if it is dynamic.
11781 -- In all cases, a static predicate can only apply to a scalar type.
11783 elsif Nkind (Expr) = N_Function_Call
11784 and then Is_Predicate_Function (Entity (Name (Expr)))
11785 and then Is_Scalar_Type (Etype (First_Entity (Entity (Name (Expr)))))
11789 -- That's an exhaustive list of tests, all other cases are not
11790 -- predicate-static, so we return False.
11795 end Is_Predicate_Static;
11797 ---------------------
11798 -- Kill_Rep_Clause --
11799 ---------------------
11801 procedure Kill_Rep_Clause (N : Node_Id) is
11803 pragma Assert (Ignore_Rep_Clauses);
11805 -- Note: we use Replace rather than Rewrite, because we don't want
11806 -- ASIS to be able to use Original_Node to dig out the (undecorated)
11807 -- rep clause that is being replaced.
11809 Replace (N, Make_Null_Statement (Sloc (N)));
11811 -- The null statement must be marked as not coming from source. This is
11812 -- so that ASIS ignores it, and also the back end does not expect bogus
11813 -- "from source" null statements in weird places (e.g. in declarative
11814 -- regions where such null statements are not allowed).
11816 Set_Comes_From_Source (N, False);
11817 end Kill_Rep_Clause;
11823 function Minimum_Size
11825 Biased : Boolean := False) return Nat
11827 Lo : Uint := No_Uint;
11828 Hi : Uint := No_Uint;
11829 LoR : Ureal := No_Ureal;
11830 HiR : Ureal := No_Ureal;
11831 LoSet : Boolean := False;
11832 HiSet : Boolean := False;
11835 Ancest : Entity_Id;
11836 R_Typ : constant Entity_Id := Root_Type (T);
11839 -- If bad type, return 0
11841 if T = Any_Type then
11844 -- For generic types, just return zero. There cannot be any legitimate
11845 -- need to know such a size, but this routine may be called with a
11846 -- generic type as part of normal processing.
11848 elsif Is_Generic_Type (R_Typ) or else R_Typ = Any_Type then
11851 -- Access types (cannot have size smaller than System.Address)
11853 elsif Is_Access_Type (T) then
11854 return System_Address_Size;
11856 -- Floating-point types
11858 elsif Is_Floating_Point_Type (T) then
11859 return UI_To_Int (Esize (R_Typ));
11863 elsif Is_Discrete_Type (T) then
11865 -- The following loop is looking for the nearest compile time known
11866 -- bounds following the ancestor subtype chain. The idea is to find
11867 -- the most restrictive known bounds information.
11871 if Ancest = Any_Type or else Etype (Ancest) = Any_Type then
11876 if Compile_Time_Known_Value (Type_Low_Bound (Ancest)) then
11877 Lo := Expr_Rep_Value (Type_Low_Bound (Ancest));
11884 if Compile_Time_Known_Value (Type_High_Bound (Ancest)) then
11885 Hi := Expr_Rep_Value (Type_High_Bound (Ancest));
11891 Ancest := Ancestor_Subtype (Ancest);
11893 if No (Ancest) then
11894 Ancest := Base_Type (T);
11896 if Is_Generic_Type (Ancest) then
11902 -- Fixed-point types. We can't simply use Expr_Value to get the
11903 -- Corresponding_Integer_Value values of the bounds, since these do not
11904 -- get set till the type is frozen, and this routine can be called
11905 -- before the type is frozen. Similarly the test for bounds being static
11906 -- needs to include the case where we have unanalyzed real literals for
11907 -- the same reason.
11909 elsif Is_Fixed_Point_Type (T) then
11911 -- The following loop is looking for the nearest compile time known
11912 -- bounds following the ancestor subtype chain. The idea is to find
11913 -- the most restrictive known bounds information.
11917 if Ancest = Any_Type or else Etype (Ancest) = Any_Type then
11921 -- Note: In the following two tests for LoSet and HiSet, it may
11922 -- seem redundant to test for N_Real_Literal here since normally
11923 -- one would assume that the test for the value being known at
11924 -- compile time includes this case. However, there is a glitch.
11925 -- If the real literal comes from folding a non-static expression,
11926 -- then we don't consider any non- static expression to be known
11927 -- at compile time if we are in configurable run time mode (needed
11928 -- in some cases to give a clearer definition of what is and what
11929 -- is not accepted). So the test is indeed needed. Without it, we
11930 -- would set neither Lo_Set nor Hi_Set and get an infinite loop.
11933 if Nkind (Type_Low_Bound (Ancest)) = N_Real_Literal
11934 or else Compile_Time_Known_Value (Type_Low_Bound (Ancest))
11936 LoR := Expr_Value_R (Type_Low_Bound (Ancest));
11943 if Nkind (Type_High_Bound (Ancest)) = N_Real_Literal
11944 or else Compile_Time_Known_Value (Type_High_Bound (Ancest))
11946 HiR := Expr_Value_R (Type_High_Bound (Ancest));
11952 Ancest := Ancestor_Subtype (Ancest);
11954 if No (Ancest) then
11955 Ancest := Base_Type (T);
11957 if Is_Generic_Type (Ancest) then
11963 Lo := UR_To_Uint (LoR / Small_Value (T));
11964 Hi := UR_To_Uint (HiR / Small_Value (T));
11966 -- No other types allowed
11969 raise Program_Error;
11972 -- Fall through with Hi and Lo set. Deal with biased case
11975 and then not Is_Fixed_Point_Type (T)
11976 and then not (Is_Enumeration_Type (T)
11977 and then Has_Non_Standard_Rep (T)))
11978 or else Has_Biased_Representation (T)
11984 -- Null range case, size is always zero. We only do this in the discrete
11985 -- type case, since that's the odd case that came up. Probably we should
11986 -- also do this in the fixed-point case, but doing so causes peculiar
11987 -- gigi failures, and it is not worth worrying about this incredibly
11988 -- marginal case (explicit null-range fixed-point type declarations)???
11990 if Lo > Hi and then Is_Discrete_Type (T) then
11993 -- Signed case. Note that we consider types like range 1 .. -1 to be
11994 -- signed for the purpose of computing the size, since the bounds have
11995 -- to be accommodated in the base type.
11997 elsif Lo < 0 or else Hi < 0 then
12001 -- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1))
12002 -- Note that we accommodate the case where the bounds cross. This
12003 -- can happen either because of the way the bounds are declared
12004 -- or because of the algorithm in Freeze_Fixed_Point_Type.
12018 -- If both bounds are positive, make sure that both are represen-
12019 -- table in the case where the bounds are crossed. This can happen
12020 -- either because of the way the bounds are declared, or because of
12021 -- the algorithm in Freeze_Fixed_Point_Type.
12027 -- S = size, (can accommodate 0 .. (2**size - 1))
12030 while Hi >= Uint_2 ** S loop
12038 ---------------------------
12039 -- New_Stream_Subprogram --
12040 ---------------------------
12042 procedure New_Stream_Subprogram
12046 Nam : TSS_Name_Type)
12048 Loc : constant Source_Ptr := Sloc (N);
12049 Sname : constant Name_Id := Make_TSS_Name (Base_Type (Ent), Nam);
12050 Subp_Id : Entity_Id;
12051 Subp_Decl : Node_Id;
12055 Defer_Declaration : constant Boolean :=
12056 Is_Tagged_Type (Ent) or else Is_Private_Type (Ent);
12057 -- For a tagged type, there is a declaration for each stream attribute
12058 -- at the freeze point, and we must generate only a completion of this
12059 -- declaration. We do the same for private types, because the full view
12060 -- might be tagged. Otherwise we generate a declaration at the point of
12061 -- the attribute definition clause. If the attribute definition comes
12062 -- from an aspect specification the declaration is part of the freeze
12063 -- actions of the type.
12065 function Build_Spec return Node_Id;
12066 -- Used for declaration and renaming declaration, so that this is
12067 -- treated as a renaming_as_body.
12073 function Build_Spec return Node_Id is
12074 Out_P : constant Boolean := (Nam = TSS_Stream_Read);
12077 T_Ref : constant Node_Id := New_Occurrence_Of (Etyp, Loc);
12080 Subp_Id := Make_Defining_Identifier (Loc, Sname);
12082 -- S : access Root_Stream_Type'Class
12084 Formals := New_List (
12085 Make_Parameter_Specification (Loc,
12086 Defining_Identifier =>
12087 Make_Defining_Identifier (Loc, Name_S),
12089 Make_Access_Definition (Loc,
12091 New_Occurrence_Of (
12092 Designated_Type (Etype (F)), Loc))));
12094 if Nam = TSS_Stream_Input then
12096 Make_Function_Specification (Loc,
12097 Defining_Unit_Name => Subp_Id,
12098 Parameter_Specifications => Formals,
12099 Result_Definition => T_Ref);
12103 Append_To (Formals,
12104 Make_Parameter_Specification (Loc,
12105 Defining_Identifier => Make_Defining_Identifier (Loc, Name_V),
12106 Out_Present => Out_P,
12107 Parameter_Type => T_Ref));
12110 Make_Procedure_Specification (Loc,
12111 Defining_Unit_Name => Subp_Id,
12112 Parameter_Specifications => Formals);
12118 -- Start of processing for New_Stream_Subprogram
12121 F := First_Formal (Subp);
12123 if Ekind (Subp) = E_Procedure then
12124 Etyp := Etype (Next_Formal (F));
12126 Etyp := Etype (Subp);
12129 -- Prepare subprogram declaration and insert it as an action on the
12130 -- clause node. The visibility for this entity is used to test for
12131 -- visibility of the attribute definition clause (in the sense of
12132 -- 8.3(23) as amended by AI-195).
12134 if not Defer_Declaration then
12136 Make_Subprogram_Declaration (Loc,
12137 Specification => Build_Spec);
12139 -- For a tagged type, there is always a visible declaration for each
12140 -- stream TSS (it is a predefined primitive operation), and the
12141 -- completion of this declaration occurs at the freeze point, which is
12142 -- not always visible at places where the attribute definition clause is
12143 -- visible. So, we create a dummy entity here for the purpose of
12144 -- tracking the visibility of the attribute definition clause itself.
12148 Make_Defining_Identifier (Loc, New_External_Name (Sname, 'V'));
12150 Make_Object_Declaration (Loc,
12151 Defining_Identifier => Subp_Id,
12152 Object_Definition => New_Occurrence_Of (Standard_Boolean, Loc));
12155 if not Defer_Declaration
12156 and then From_Aspect_Specification (N)
12157 and then Has_Delayed_Freeze (Ent)
12159 Append_Freeze_Action (Ent, Subp_Decl);
12162 Insert_Action (N, Subp_Decl);
12163 Set_Entity (N, Subp_Id);
12167 Make_Subprogram_Renaming_Declaration (Loc,
12168 Specification => Build_Spec,
12169 Name => New_Occurrence_Of (Subp, Loc));
12171 if Defer_Declaration then
12172 Set_TSS (Base_Type (Ent), Subp_Id);
12175 if From_Aspect_Specification (N) then
12176 Append_Freeze_Action (Ent, Subp_Decl);
12178 Insert_Action (N, Subp_Decl);
12181 Copy_TSS (Subp_Id, Base_Type (Ent));
12183 end New_Stream_Subprogram;
12185 ------------------------------------------
12186 -- Push_Scope_And_Install_Discriminants --
12187 ------------------------------------------
12189 procedure Push_Scope_And_Install_Discriminants (E : Entity_Id) is
12191 if Has_Discriminants (E) then
12194 -- Make the discriminants visible for type declarations and protected
12195 -- type declarations, not for subtype declarations (RM 13.1.1 (12/3))
12197 if Nkind (Parent (E)) /= N_Subtype_Declaration then
12198 Install_Discriminants (E);
12201 end Push_Scope_And_Install_Discriminants;
12203 ------------------------
12204 -- Rep_Item_Too_Early --
12205 ------------------------
12207 function Rep_Item_Too_Early (T : Entity_Id; N : Node_Id) return Boolean is
12209 -- Cannot apply non-operational rep items to generic types
12211 if Is_Operational_Item (N) then
12215 and then Is_Generic_Type (Root_Type (T))
12216 and then (Nkind (N) /= N_Pragma
12217 or else Get_Pragma_Id (N) /= Pragma_Convention)
12219 Error_Msg_N ("representation item not allowed for generic type", N);
12223 -- Otherwise check for incomplete type
12225 if Is_Incomplete_Or_Private_Type (T)
12226 and then No (Underlying_Type (T))
12228 (Nkind (N) /= N_Pragma
12229 or else Get_Pragma_Id (N) /= Pragma_Import)
12232 ("representation item must be after full type declaration", N);
12235 -- If the type has incomplete components, a representation clause is
12236 -- illegal but stream attributes and Convention pragmas are correct.
12238 elsif Has_Private_Component (T) then
12239 if Nkind (N) = N_Pragma then
12244 ("representation item must appear after type is fully defined",
12251 end Rep_Item_Too_Early;
12253 -----------------------
12254 -- Rep_Item_Too_Late --
12255 -----------------------
12257 function Rep_Item_Too_Late
12260 FOnly : Boolean := False) return Boolean
12263 Parent_Type : Entity_Id;
12265 procedure No_Type_Rep_Item;
12266 -- Output message indicating that no type-related aspects can be
12267 -- specified due to some property of the parent type.
12269 procedure Too_Late;
12270 -- Output message for an aspect being specified too late
12272 -- Note that neither of the above errors is considered a serious one,
12273 -- since the effect is simply that we ignore the representation clause
12275 -- Is this really true? In any case if we make this change we must
12276 -- document the requirement in the spec of Rep_Item_Too_Late that
12277 -- if True is returned, then the rep item must be completely ignored???
12279 ----------------------
12280 -- No_Type_Rep_Item --
12281 ----------------------
12283 procedure No_Type_Rep_Item is
12285 Error_Msg_N ("|type-related representation item not permitted!", N);
12286 end No_Type_Rep_Item;
12292 procedure Too_Late is
12294 -- Other compilers seem more relaxed about rep items appearing too
12295 -- late. Since analysis tools typically don't care about rep items
12296 -- anyway, no reason to be too strict about this.
12298 if not Relaxed_RM_Semantics then
12299 Error_Msg_N ("|representation item appears too late!", N);
12303 -- Start of processing for Rep_Item_Too_Late
12306 -- First make sure entity is not frozen (RM 13.1(9))
12310 -- Exclude imported types, which may be frozen if they appear in a
12311 -- representation clause for a local type.
12313 and then not From_Limited_With (T)
12315 -- Exclude generated entities (not coming from source). The common
12316 -- case is when we generate a renaming which prematurely freezes the
12317 -- renamed internal entity, but we still want to be able to set copies
12318 -- of attribute values such as Size/Alignment.
12320 and then Comes_From_Source (T)
12322 -- A self-referential aspect is illegal if it forces freezing the
12323 -- entity before the corresponding pragma has been analyzed.
12325 if Nkind_In (N, N_Attribute_Definition_Clause, N_Pragma)
12326 and then From_Aspect_Specification (N)
12329 ("aspect specification causes premature freezing of&", N, T);
12330 Set_Has_Delayed_Freeze (T, False);
12335 S := First_Subtype (T);
12337 if Present (Freeze_Node (S)) then
12338 if not Relaxed_RM_Semantics then
12340 ("??no more representation items for }", Freeze_Node (S), S);
12346 -- Check for case of untagged derived type whose parent either has
12347 -- primitive operations, or is a by reference type (RM 13.1(10)). In
12348 -- this case we do not output a Too_Late message, since there is no
12349 -- earlier point where the rep item could be placed to make it legal.
12353 and then Is_Derived_Type (T)
12354 and then not Is_Tagged_Type (T)
12356 Parent_Type := Etype (Base_Type (T));
12358 if Has_Primitive_Operations (Parent_Type) then
12361 if not Relaxed_RM_Semantics then
12363 ("\parent type & has primitive operations!", N, Parent_Type);
12368 elsif Is_By_Reference_Type (Parent_Type) then
12371 if not Relaxed_RM_Semantics then
12373 ("\parent type & is a by reference type!", N, Parent_Type);
12380 -- No error, but one more warning to consider. The RM (surprisingly)
12381 -- allows this pattern:
12384 -- primitive operations for S
12385 -- type R is new S;
12386 -- rep clause for S
12388 -- Meaning that calls on the primitive operations of S for values of
12389 -- type R may require possibly expensive implicit conversion operations.
12390 -- This is not an error, but is worth a warning.
12392 if not Relaxed_RM_Semantics and then Is_Type (T) then
12394 DTL : constant Entity_Id := Derived_Type_Link (Base_Type (T));
12398 and then Has_Primitive_Operations (Base_Type (T))
12400 -- For now, do not generate this warning for the case of aspect
12401 -- specification using Ada 2012 syntax, since we get wrong
12402 -- messages we do not understand. The whole business of derived
12403 -- types and rep items seems a bit confused when aspects are
12404 -- used, since the aspects are not evaluated till freeze time.
12406 and then not From_Aspect_Specification (N)
12408 Error_Msg_Sloc := Sloc (DTL);
12410 ("representation item for& appears after derived type "
12411 & "declaration#??", N);
12413 ("\may result in implicit conversions for primitive "
12414 & "operations of&??", N, T);
12416 ("\to change representations when called with arguments "
12417 & "of type&??", N, DTL);
12422 -- No error, link item into head of chain of rep items for the entity,
12423 -- but avoid chaining if we have an overloadable entity, and the pragma
12424 -- is one that can apply to multiple overloaded entities.
12426 if Is_Overloadable (T) and then Nkind (N) = N_Pragma then
12428 Pname : constant Name_Id := Pragma_Name (N);
12430 if Nam_In (Pname, Name_Convention, Name_Import, Name_Export,
12431 Name_External, Name_Interface)
12438 Record_Rep_Item (T, N);
12440 end Rep_Item_Too_Late;
12442 -------------------------------------
12443 -- Replace_Type_References_Generic --
12444 -------------------------------------
12446 procedure Replace_Type_References_Generic (N : Node_Id; T : Entity_Id) is
12447 TName : constant Name_Id := Chars (T);
12449 function Replace_Type_Ref (N : Node_Id) return Traverse_Result;
12450 -- Processes a single node in the traversal procedure below, checking
12451 -- if node N should be replaced, and if so, doing the replacement.
12453 function Visible_Component (Comp : Name_Id) return Entity_Id;
12454 -- Given an identifier in the expression, check whether there is a
12455 -- discriminant or component of the type that is directy visible, and
12456 -- rewrite it as the corresponding selected component of the formal of
12457 -- the subprogram. The entity is located by a sequential search, which
12458 -- seems acceptable given the typical size of component lists and check
12459 -- expressions. Possible optimization ???
12461 ----------------------
12462 -- Replace_Type_Ref --
12463 ----------------------
12465 function Replace_Type_Ref (N : Node_Id) return Traverse_Result is
12466 Loc : constant Source_Ptr := Sloc (N);
12468 procedure Add_Prefix (Ref : Node_Id; Comp : Entity_Id);
12469 -- Add the proper prefix to a reference to a component of the type
12470 -- when it is not already a selected component.
12476 procedure Add_Prefix (Ref : Node_Id; Comp : Entity_Id) is
12479 Make_Selected_Component (Loc,
12480 Prefix => New_Occurrence_Of (T, Loc),
12481 Selector_Name => New_Occurrence_Of (Comp, Loc)));
12482 Replace_Type_Reference (Prefix (Ref));
12491 -- Start of processing for Replace_Type_Ref
12494 if Nkind (N) = N_Identifier then
12496 -- If not the type name, check whether it is a reference to some
12497 -- other type, which must be frozen before the predicate function
12498 -- is analyzed, i.e. before the freeze node of the type to which
12499 -- the predicate applies.
12501 if Chars (N) /= TName then
12502 if Present (Current_Entity (N))
12503 and then Is_Type (Current_Entity (N))
12505 Freeze_Before (Freeze_Node (T), Current_Entity (N));
12508 -- The components of the type are directly visible and can
12509 -- be referenced without a prefix.
12511 if Nkind (Parent (N)) = N_Selected_Component then
12514 -- In expression C (I), C may be a directly visible function
12515 -- or a visible component that has an array type. Disambiguate
12516 -- by examining the component type.
12518 elsif Nkind (Parent (N)) = N_Indexed_Component
12519 and then N = Prefix (Parent (N))
12521 Comp := Visible_Component (Chars (N));
12523 if Present (Comp) and then Is_Array_Type (Etype (Comp)) then
12524 Add_Prefix (N, Comp);
12528 Comp := Visible_Component (Chars (N));
12530 if Present (Comp) then
12531 Add_Prefix (N, Comp);
12537 -- Otherwise do the replacement and we are done with this node
12540 Replace_Type_Reference (N);
12544 -- Case of selected component (which is what a qualification looks
12545 -- like in the unanalyzed tree, which is what we have.
12547 elsif Nkind (N) = N_Selected_Component then
12549 -- If selector name is not our type, keeping going (we might still
12550 -- have an occurrence of the type in the prefix).
12552 if Nkind (Selector_Name (N)) /= N_Identifier
12553 or else Chars (Selector_Name (N)) /= TName
12557 -- Selector name is our type, check qualification
12560 -- Loop through scopes and prefixes, doing comparison
12562 Scop := Current_Scope;
12563 Pref := Prefix (N);
12565 -- Continue if no more scopes or scope with no name
12567 if No (Scop) or else Nkind (Scop) not in N_Has_Chars then
12571 -- Do replace if prefix is an identifier matching the scope
12572 -- that we are currently looking at.
12574 if Nkind (Pref) = N_Identifier
12575 and then Chars (Pref) = Chars (Scop)
12577 Replace_Type_Reference (N);
12581 -- Go check scope above us if prefix is itself of the form
12582 -- of a selected component, whose selector matches the scope
12583 -- we are currently looking at.
12585 if Nkind (Pref) = N_Selected_Component
12586 and then Nkind (Selector_Name (Pref)) = N_Identifier
12587 and then Chars (Selector_Name (Pref)) = Chars (Scop)
12589 Scop := Scope (Scop);
12590 Pref := Prefix (Pref);
12592 -- For anything else, we don't have a match, so keep on
12593 -- going, there are still some weird cases where we may
12594 -- still have a replacement within the prefix.
12602 -- Continue for any other node kind
12607 end Replace_Type_Ref;
12609 procedure Replace_Type_Refs is new Traverse_Proc (Replace_Type_Ref);
12611 -----------------------
12612 -- Visible_Component --
12613 -----------------------
12615 function Visible_Component (Comp : Name_Id) return Entity_Id is
12619 -- Types with nameable components are records and discriminated
12622 if Ekind (T) = E_Record_Type
12623 or else (Is_Private_Type (T) and then Has_Discriminants (T))
12625 E := First_Entity (T);
12626 while Present (E) loop
12627 if Comes_From_Source (E) and then Chars (E) = Comp then
12635 -- Nothing by that name, or the type has no components
12638 end Visible_Component;
12640 -- Start of processing for Replace_Type_References_Generic
12643 Replace_Type_Refs (N);
12644 end Replace_Type_References_Generic;
12646 --------------------------------
12647 -- Resolve_Aspect_Expressions --
12648 --------------------------------
12650 procedure Resolve_Aspect_Expressions (E : Entity_Id) is
12655 function Resolve_Name (N : Node_Id) return Traverse_Result;
12656 -- Verify that all identifiers in the expression, with the exception
12657 -- of references to the current entity, denote visible entities. This
12658 -- is done only to detect visibility errors, as the expression will be
12659 -- properly analyzed/expanded during analysis of the predicate function
12660 -- body. We omit quantified expressions from this test, given that they
12661 -- introduce a local identifier that would require proper expansion to
12662 -- handle properly.
12664 -- In ASIS_Mode we preserve the entity in the source because there is
12665 -- no subsequent expansion to decorate the tree.
12671 function Resolve_Name (N : Node_Id) return Traverse_Result is
12673 if Nkind (N) = N_Selected_Component then
12674 if Nkind (Prefix (N)) = N_Identifier
12675 and then Chars (Prefix (N)) /= Chars (E)
12677 Find_Selected_Component (N);
12682 elsif Nkind (N) = N_Identifier and then Chars (N) /= Chars (E) then
12683 Find_Direct_Name (N);
12685 if not ASIS_Mode then
12686 Set_Entity (N, Empty);
12689 elsif Nkind (N) = N_Quantified_Expression then
12696 procedure Resolve_Aspect_Expression is new Traverse_Proc (Resolve_Name);
12698 -- Start of processing for Resolve_Aspect_Expressions
12701 ASN := First_Rep_Item (E);
12702 while Present (ASN) loop
12703 if Nkind (ASN) = N_Aspect_Specification and then Entity (ASN) = E then
12704 A_Id := Get_Aspect_Id (ASN);
12705 Expr := Expression (ASN);
12709 -- For now we only deal with aspects that do not generate
12710 -- subprograms, or that may mention current instances of
12711 -- types. These will require special handling (???TBD).
12713 when Aspect_Invariant
12715 | Aspect_Predicate_Failure
12719 when Aspect_Dynamic_Predicate
12720 | Aspect_Static_Predicate
12722 -- Build predicate function specification and preanalyze
12723 -- expression after type replacement.
12725 if No (Predicate_Function (E)) then
12727 FDecl : constant Node_Id :=
12728 Build_Predicate_Function_Declaration (E);
12729 pragma Unreferenced (FDecl);
12731 Resolve_Aspect_Expression (Expr);
12735 when Pre_Post_Aspects =>
12738 when Aspect_Iterable =>
12739 if Nkind (Expr) = N_Aggregate then
12744 Assoc := First (Component_Associations (Expr));
12745 while Present (Assoc) loop
12746 Find_Direct_Name (Expression (Assoc));
12753 if Present (Expr) then
12754 case Aspect_Argument (A_Id) is
12756 | Optional_Expression
12758 Analyze_And_Resolve (Expression (ASN));
12763 if Nkind (Expr) = N_Identifier then
12764 Find_Direct_Name (Expr);
12766 elsif Nkind (Expr) = N_Selected_Component then
12767 Find_Selected_Component (Expr);
12774 ASN := Next_Rep_Item (ASN);
12776 end Resolve_Aspect_Expressions;
12778 -------------------------
12779 -- Same_Representation --
12780 -------------------------
12782 function Same_Representation (Typ1, Typ2 : Entity_Id) return Boolean is
12783 T1 : constant Entity_Id := Underlying_Type (Typ1);
12784 T2 : constant Entity_Id := Underlying_Type (Typ2);
12787 -- A quick check, if base types are the same, then we definitely have
12788 -- the same representation, because the subtype specific representation
12789 -- attributes (Size and Alignment) do not affect representation from
12790 -- the point of view of this test.
12792 if Base_Type (T1) = Base_Type (T2) then
12795 elsif Is_Private_Type (Base_Type (T2))
12796 and then Base_Type (T1) = Full_View (Base_Type (T2))
12801 -- Tagged types never have differing representations
12803 if Is_Tagged_Type (T1) then
12807 -- Representations are definitely different if conventions differ
12809 if Convention (T1) /= Convention (T2) then
12813 -- Representations are different if component alignments or scalar
12814 -- storage orders differ.
12816 if (Is_Record_Type (T1) or else Is_Array_Type (T1))
12818 (Is_Record_Type (T2) or else Is_Array_Type (T2))
12820 (Component_Alignment (T1) /= Component_Alignment (T2)
12821 or else Reverse_Storage_Order (T1) /= Reverse_Storage_Order (T2))
12826 -- For arrays, the only real issue is component size. If we know the
12827 -- component size for both arrays, and it is the same, then that's
12828 -- good enough to know we don't have a change of representation.
12830 if Is_Array_Type (T1) then
12831 if Known_Component_Size (T1)
12832 and then Known_Component_Size (T2)
12833 and then Component_Size (T1) = Component_Size (T2)
12839 -- Types definitely have same representation if neither has non-standard
12840 -- representation since default representations are always consistent.
12841 -- If only one has non-standard representation, and the other does not,
12842 -- then we consider that they do not have the same representation. They
12843 -- might, but there is no way of telling early enough.
12845 if Has_Non_Standard_Rep (T1) then
12846 if not Has_Non_Standard_Rep (T2) then
12850 return not Has_Non_Standard_Rep (T2);
12853 -- Here the two types both have non-standard representation, and we need
12854 -- to determine if they have the same non-standard representation.
12856 -- For arrays, we simply need to test if the component sizes are the
12857 -- same. Pragma Pack is reflected in modified component sizes, so this
12858 -- check also deals with pragma Pack.
12860 if Is_Array_Type (T1) then
12861 return Component_Size (T1) = Component_Size (T2);
12863 -- Tagged types always have the same representation, because it is not
12864 -- possible to specify different representations for common fields.
12866 elsif Is_Tagged_Type (T1) then
12869 -- Case of record types
12871 elsif Is_Record_Type (T1) then
12873 -- Packed status must conform
12875 if Is_Packed (T1) /= Is_Packed (T2) then
12878 -- Otherwise we must check components. Typ2 maybe a constrained
12879 -- subtype with fewer components, so we compare the components
12880 -- of the base types.
12883 Record_Case : declare
12884 CD1, CD2 : Entity_Id;
12886 function Same_Rep return Boolean;
12887 -- CD1 and CD2 are either components or discriminants. This
12888 -- function tests whether they have the same representation.
12894 function Same_Rep return Boolean is
12896 if No (Component_Clause (CD1)) then
12897 return No (Component_Clause (CD2));
12899 -- Note: at this point, component clauses have been
12900 -- normalized to the default bit order, so that the
12901 -- comparison of Component_Bit_Offsets is meaningful.
12904 Present (Component_Clause (CD2))
12906 Component_Bit_Offset (CD1) = Component_Bit_Offset (CD2)
12908 Esize (CD1) = Esize (CD2);
12912 -- Start of processing for Record_Case
12915 if Has_Discriminants (T1) then
12917 -- The number of discriminants may be different if the
12918 -- derived type has fewer (constrained by values). The
12919 -- invisible discriminants retain the representation of
12920 -- the original, so the discrepancy does not per se
12921 -- indicate a different representation.
12923 CD1 := First_Discriminant (T1);
12924 CD2 := First_Discriminant (T2);
12925 while Present (CD1) and then Present (CD2) loop
12926 if not Same_Rep then
12929 Next_Discriminant (CD1);
12930 Next_Discriminant (CD2);
12935 CD1 := First_Component (Underlying_Type (Base_Type (T1)));
12936 CD2 := First_Component (Underlying_Type (Base_Type (T2)));
12937 while Present (CD1) loop
12938 if not Same_Rep then
12941 Next_Component (CD1);
12942 Next_Component (CD2);
12950 -- For enumeration types, we must check each literal to see if the
12951 -- representation is the same. Note that we do not permit enumeration
12952 -- representation clauses for Character and Wide_Character, so these
12953 -- cases were already dealt with.
12955 elsif Is_Enumeration_Type (T1) then
12956 Enumeration_Case : declare
12957 L1, L2 : Entity_Id;
12960 L1 := First_Literal (T1);
12961 L2 := First_Literal (T2);
12962 while Present (L1) loop
12963 if Enumeration_Rep (L1) /= Enumeration_Rep (L2) then
12972 end Enumeration_Case;
12974 -- Any other types have the same representation for these purposes
12979 end Same_Representation;
12981 --------------------------------
12982 -- Resolve_Iterable_Operation --
12983 --------------------------------
12985 procedure Resolve_Iterable_Operation
12987 Cursor : Entity_Id;
12996 if not Is_Overloaded (N) then
12997 if not Is_Entity_Name (N)
12998 or else Ekind (Entity (N)) /= E_Function
12999 or else Scope (Entity (N)) /= Scope (Typ)
13000 or else No (First_Formal (Entity (N)))
13001 or else Etype (First_Formal (Entity (N))) /= Typ
13003 Error_Msg_N ("iterable primitive must be local function name "
13004 & "whose first formal is an iterable type", N);
13009 F1 := First_Formal (Ent);
13010 if Nam = Name_First then
13012 -- First (Container) => Cursor
13014 if Etype (Ent) /= Cursor then
13015 Error_Msg_N ("primitive for First must yield a curosr", N);
13018 elsif Nam = Name_Next then
13020 -- Next (Container, Cursor) => Cursor
13022 F2 := Next_Formal (F1);
13024 if Etype (F2) /= Cursor
13025 or else Etype (Ent) /= Cursor
13026 or else Present (Next_Formal (F2))
13028 Error_Msg_N ("no match for Next iterable primitive", N);
13031 elsif Nam = Name_Has_Element then
13033 -- Has_Element (Container, Cursor) => Boolean
13035 F2 := Next_Formal (F1);
13036 if Etype (F2) /= Cursor
13037 or else Etype (Ent) /= Standard_Boolean
13038 or else Present (Next_Formal (F2))
13040 Error_Msg_N ("no match for Has_Element iterable primitive", N);
13043 elsif Nam = Name_Element then
13044 F2 := Next_Formal (F1);
13047 or else Etype (F2) /= Cursor
13048 or else Present (Next_Formal (F2))
13050 Error_Msg_N ("no match for Element iterable primitive", N);
13055 raise Program_Error;
13059 -- Overloaded case: find subprogram with proper signature.
13060 -- Caller will report error if no match is found.
13067 Get_First_Interp (N, I, It);
13068 while Present (It.Typ) loop
13069 if Ekind (It.Nam) = E_Function
13070 and then Scope (It.Nam) = Scope (Typ)
13071 and then Etype (First_Formal (It.Nam)) = Typ
13073 F1 := First_Formal (It.Nam);
13075 if Nam = Name_First then
13076 if Etype (It.Nam) = Cursor
13077 and then No (Next_Formal (F1))
13079 Set_Entity (N, It.Nam);
13083 elsif Nam = Name_Next then
13084 F2 := Next_Formal (F1);
13087 and then No (Next_Formal (F2))
13088 and then Etype (F2) = Cursor
13089 and then Etype (It.Nam) = Cursor
13091 Set_Entity (N, It.Nam);
13095 elsif Nam = Name_Has_Element then
13096 F2 := Next_Formal (F1);
13099 and then No (Next_Formal (F2))
13100 and then Etype (F2) = Cursor
13101 and then Etype (It.Nam) = Standard_Boolean
13103 Set_Entity (N, It.Nam);
13104 F2 := Next_Formal (F1);
13108 elsif Nam = Name_Element then
13109 F2 := Next_Formal (F1);
13112 and then No (Next_Formal (F2))
13113 and then Etype (F2) = Cursor
13115 Set_Entity (N, It.Nam);
13121 Get_Next_Interp (I, It);
13125 end Resolve_Iterable_Operation;
13131 procedure Set_Biased
13135 Biased : Boolean := True)
13139 Set_Has_Biased_Representation (E);
13141 if Warn_On_Biased_Representation then
13143 ("?B?" & Msg & " forces biased representation for&", N, E);
13148 --------------------
13149 -- Set_Enum_Esize --
13150 --------------------
13152 procedure Set_Enum_Esize (T : Entity_Id) is
13158 Init_Alignment (T);
13160 -- Find the minimum standard size (8,16,32,64) that fits
13162 Lo := Enumeration_Rep (Entity (Type_Low_Bound (T)));
13163 Hi := Enumeration_Rep (Entity (Type_High_Bound (T)));
13166 if Lo >= -Uint_2**07 and then Hi < Uint_2**07 then
13167 Sz := Standard_Character_Size; -- May be > 8 on some targets
13169 elsif Lo >= -Uint_2**15 and then Hi < Uint_2**15 then
13172 elsif Lo >= -Uint_2**31 and then Hi < Uint_2**31 then
13175 else pragma Assert (Lo >= -Uint_2**63 and then Hi < Uint_2**63);
13180 if Hi < Uint_2**08 then
13181 Sz := Standard_Character_Size; -- May be > 8 on some targets
13183 elsif Hi < Uint_2**16 then
13186 elsif Hi < Uint_2**32 then
13189 else pragma Assert (Hi < Uint_2**63);
13194 -- That minimum is the proper size unless we have a foreign convention
13195 -- and the size required is 32 or less, in which case we bump the size
13196 -- up to 32. This is required for C and C++ and seems reasonable for
13197 -- all other foreign conventions.
13199 if Has_Foreign_Convention (T)
13200 and then Esize (T) < Standard_Integer_Size
13202 -- Don't do this if Short_Enums on target
13204 and then not Target_Short_Enums
13206 Init_Esize (T, Standard_Integer_Size);
13208 Init_Esize (T, Sz);
13210 end Set_Enum_Esize;
13212 -----------------------------
13213 -- Uninstall_Discriminants --
13214 -----------------------------
13216 procedure Uninstall_Discriminants (E : Entity_Id) is
13222 -- Discriminants have been made visible for type declarations and
13223 -- protected type declarations, not for subtype declarations.
13225 if Nkind (Parent (E)) /= N_Subtype_Declaration then
13226 Disc := First_Discriminant (E);
13227 while Present (Disc) loop
13228 if Disc /= Current_Entity (Disc) then
13229 Prev := Current_Entity (Disc);
13230 while Present (Prev)
13231 and then Present (Homonym (Prev))
13232 and then Homonym (Prev) /= Disc
13234 Prev := Homonym (Prev);
13240 Set_Is_Immediately_Visible (Disc, False);
13242 Outer := Homonym (Disc);
13243 while Present (Outer) and then Scope (Outer) = E loop
13244 Outer := Homonym (Outer);
13247 -- Reset homonym link of other entities, but do not modify link
13248 -- between entities in current scope, so that the back end can
13249 -- have a proper count of local overloadings.
13252 Set_Name_Entity_Id (Chars (Disc), Outer);
13254 elsif Scope (Prev) /= Scope (Disc) then
13255 Set_Homonym (Prev, Outer);
13258 Next_Discriminant (Disc);
13261 end Uninstall_Discriminants;
13263 -------------------------------------------
13264 -- Uninstall_Discriminants_And_Pop_Scope --
13265 -------------------------------------------
13267 procedure Uninstall_Discriminants_And_Pop_Scope (E : Entity_Id) is
13269 if Has_Discriminants (E) then
13270 Uninstall_Discriminants (E);
13273 end Uninstall_Discriminants_And_Pop_Scope;
13275 ------------------------------
13276 -- Validate_Address_Clauses --
13277 ------------------------------
13279 procedure Validate_Address_Clauses is
13280 function Offset_Value (Expr : Node_Id) return Uint;
13281 -- Given an Address attribute reference, return the value in bits of its
13282 -- offset from the first bit of the underlying entity, or 0 if it is not
13283 -- known at compile time.
13289 function Offset_Value (Expr : Node_Id) return Uint is
13290 N : Node_Id := Prefix (Expr);
13292 Val : Uint := Uint_0;
13295 -- Climb the prefix chain and compute the cumulative offset
13298 if Is_Entity_Name (N) then
13301 elsif Nkind (N) = N_Selected_Component then
13302 Off := Component_Bit_Offset (Entity (Selector_Name (N)));
13303 if Off /= No_Uint and then Off >= Uint_0 then
13310 elsif Nkind (N) = N_Indexed_Component then
13311 Off := Indexed_Component_Bit_Offset (N);
13312 if Off /= No_Uint then
13325 -- Start of processing for Validate_Address_Clauses
13328 for J in Address_Clause_Checks.First .. Address_Clause_Checks.Last loop
13330 ACCR : Address_Clause_Check_Record
13331 renames Address_Clause_Checks.Table (J);
13335 X_Alignment : Uint;
13336 Y_Alignment : Uint;
13344 -- Skip processing of this entry if warning already posted
13346 if not Address_Warning_Posted (ACCR.N) then
13347 Expr := Original_Node (Expression (ACCR.N));
13349 -- Get alignments, sizes and offset, if any
13351 X_Alignment := Alignment (ACCR.X);
13352 X_Size := Esize (ACCR.X);
13354 if Present (ACCR.Y) then
13355 Y_Alignment := Alignment (ACCR.Y);
13356 Y_Size := Esize (ACCR.Y);
13360 and then Nkind (Expr) = N_Attribute_Reference
13361 and then Attribute_Name (Expr) = Name_Address
13363 X_Offs := Offset_Value (Expr);
13368 -- Check for known value not multiple of alignment
13370 if No (ACCR.Y) then
13371 if not Alignment_Checks_Suppressed (ACCR.X)
13372 and then X_Alignment /= 0
13373 and then ACCR.A mod X_Alignment /= 0
13376 ("??specified address for& is inconsistent with "
13377 & "alignment", ACCR.N, ACCR.X);
13379 ("\??program execution may be erroneous (RM 13.3(27))",
13382 Error_Msg_Uint_1 := X_Alignment;
13383 Error_Msg_NE ("\??alignment of & is ^", ACCR.N, ACCR.X);
13386 -- Check for large object overlaying smaller one
13388 elsif Y_Size > Uint_0
13389 and then X_Size > Uint_0
13390 and then X_Offs + X_Size > Y_Size
13392 Error_Msg_NE ("??& overlays smaller object", ACCR.N, ACCR.X);
13394 ("\??program execution may be erroneous", ACCR.N);
13396 Error_Msg_Uint_1 := X_Size;
13397 Error_Msg_NE ("\??size of & is ^", ACCR.N, ACCR.X);
13399 Error_Msg_Uint_1 := Y_Size;
13400 Error_Msg_NE ("\??size of & is ^", ACCR.N, ACCR.Y);
13402 if Y_Size >= X_Size then
13403 Error_Msg_Uint_1 := X_Offs;
13404 Error_Msg_NE ("\??but offset of & is ^", ACCR.N, ACCR.X);
13407 -- Check for inadequate alignment, both of the base object
13408 -- and of the offset, if any. We only do this check if the
13409 -- run-time Alignment_Check is active. No point in warning
13410 -- if this check has been suppressed (or is suppressed by
13411 -- default in the non-strict alignment machine case).
13413 -- Note: we do not check the alignment if we gave a size
13414 -- warning, since it would likely be redundant.
13416 elsif not Alignment_Checks_Suppressed (ACCR.X)
13417 and then Y_Alignment /= Uint_0
13419 (Y_Alignment < X_Alignment
13422 and then Nkind (Expr) = N_Attribute_Reference
13423 and then Attribute_Name (Expr) = Name_Address
13424 and then Has_Compatible_Alignment
13425 (ACCR.X, Prefix (Expr), True) /=
13429 ("??specified address for& may be inconsistent with "
13430 & "alignment", ACCR.N, ACCR.X);
13432 ("\??program execution may be erroneous (RM 13.3(27))",
13435 Error_Msg_Uint_1 := X_Alignment;
13436 Error_Msg_NE ("\??alignment of & is ^", ACCR.N, ACCR.X);
13438 Error_Msg_Uint_1 := Y_Alignment;
13439 Error_Msg_NE ("\??alignment of & is ^", ACCR.N, ACCR.Y);
13441 if Y_Alignment >= X_Alignment then
13443 ("\??but offset is not multiple of alignment", ACCR.N);
13449 end Validate_Address_Clauses;
13451 -----------------------------------------
13452 -- Validate_Compile_Time_Warning_Error --
13453 -----------------------------------------
13455 procedure Validate_Compile_Time_Warning_Error (N : Node_Id) is
13457 Compile_Time_Warnings_Errors.Append
13458 (New_Val => CTWE_Entry'(Eloc => Sloc (N),
13459 Scope => Current_Scope,
13461 end Validate_Compile_Time_Warning_Error;
13463 ------------------------------------------
13464 -- Validate_Compile_Time_Warning_Errors --
13465 ------------------------------------------
13467 procedure Validate_Compile_Time_Warning_Errors is
13468 procedure Set_Scope (S : Entity_Id);
13469 -- Install all enclosing scopes of S along with S itself
13471 procedure Unset_Scope (S : Entity_Id);
13472 -- Uninstall all enclosing scopes of S along with S itself
13478 procedure Set_Scope (S : Entity_Id) is
13480 if S /= Standard_Standard then
13481 Set_Scope (Scope (S));
13491 procedure Unset_Scope (S : Entity_Id) is
13493 if S /= Standard_Standard then
13494 Unset_Scope (Scope (S));
13500 -- Start of processing for Validate_Compile_Time_Warning_Errors
13503 Expander_Mode_Save_And_Set (False);
13504 In_Compile_Time_Warning_Or_Error := True;
13506 for N in Compile_Time_Warnings_Errors.First ..
13507 Compile_Time_Warnings_Errors.Last
13510 T : CTWE_Entry renames Compile_Time_Warnings_Errors.Table (N);
13513 Set_Scope (T.Scope);
13514 Reset_Analyzed_Flags (T.Prag);
13515 Process_Compile_Time_Warning_Or_Error (T.Prag, T.Eloc);
13516 Unset_Scope (T.Scope);
13520 In_Compile_Time_Warning_Or_Error := False;
13521 Expander_Mode_Restore;
13522 end Validate_Compile_Time_Warning_Errors;
13524 ---------------------------
13525 -- Validate_Independence --
13526 ---------------------------
13528 procedure Validate_Independence is
13529 SU : constant Uint := UI_From_Int (System_Storage_Unit);
13537 procedure Check_Array_Type (Atyp : Entity_Id);
13538 -- Checks if the array type Atyp has independent components, and
13539 -- if not, outputs an appropriate set of error messages.
13541 procedure No_Independence;
13542 -- Output message that independence cannot be guaranteed
13544 function OK_Component (C : Entity_Id) return Boolean;
13545 -- Checks one component to see if it is independently accessible, and
13546 -- if so yields True, otherwise yields False if independent access
13547 -- cannot be guaranteed. This is a conservative routine, it only
13548 -- returns True if it knows for sure, it returns False if it knows
13549 -- there is a problem, or it cannot be sure there is no problem.
13551 procedure Reason_Bad_Component (C : Entity_Id);
13552 -- Outputs continuation message if a reason can be determined for
13553 -- the component C being bad.
13555 ----------------------
13556 -- Check_Array_Type --
13557 ----------------------
13559 procedure Check_Array_Type (Atyp : Entity_Id) is
13560 Ctyp : constant Entity_Id := Component_Type (Atyp);
13563 -- OK if no alignment clause, no pack, and no component size
13565 if not Has_Component_Size_Clause (Atyp)
13566 and then not Has_Alignment_Clause (Atyp)
13567 and then not Is_Packed (Atyp)
13572 -- Case of component size is greater than or equal to 64 and the
13573 -- alignment of the array is at least as large as the alignment
13574 -- of the component. We are definitely OK in this situation.
13576 if Known_Component_Size (Atyp)
13577 and then Component_Size (Atyp) >= 64
13578 and then Known_Alignment (Atyp)
13579 and then Known_Alignment (Ctyp)
13580 and then Alignment (Atyp) >= Alignment (Ctyp)
13585 -- Check actual component size
13587 if not Known_Component_Size (Atyp)
13588 or else not (Addressable (Component_Size (Atyp))
13589 and then Component_Size (Atyp) < 64)
13590 or else Component_Size (Atyp) mod Esize (Ctyp) /= 0
13594 -- Bad component size, check reason
13596 if Has_Component_Size_Clause (Atyp) then
13597 P := Get_Attribute_Definition_Clause
13598 (Atyp, Attribute_Component_Size);
13600 if Present (P) then
13601 Error_Msg_Sloc := Sloc (P);
13602 Error_Msg_N ("\because of Component_Size clause#", N);
13607 if Is_Packed (Atyp) then
13608 P := Get_Rep_Pragma (Atyp, Name_Pack);
13610 if Present (P) then
13611 Error_Msg_Sloc := Sloc (P);
13612 Error_Msg_N ("\because of pragma Pack#", N);
13617 -- No reason found, just return
13622 -- Array type is OK independence-wise
13625 end Check_Array_Type;
13627 ---------------------
13628 -- No_Independence --
13629 ---------------------
13631 procedure No_Independence is
13633 if Pragma_Name (N) = Name_Independent then
13634 Error_Msg_NE ("independence cannot be guaranteed for&", N, E);
13637 ("independent components cannot be guaranteed for&", N, E);
13639 end No_Independence;
13645 function OK_Component (C : Entity_Id) return Boolean is
13646 Rec : constant Entity_Id := Scope (C);
13647 Ctyp : constant Entity_Id := Etype (C);
13650 -- OK if no component clause, no Pack, and no alignment clause
13652 if No (Component_Clause (C))
13653 and then not Is_Packed (Rec)
13654 and then not Has_Alignment_Clause (Rec)
13659 -- Here we look at the actual component layout. A component is
13660 -- addressable if its size is a multiple of the Esize of the
13661 -- component type, and its starting position in the record has
13662 -- appropriate alignment, and the record itself has appropriate
13663 -- alignment to guarantee the component alignment.
13665 -- Make sure sizes are static, always assume the worst for any
13666 -- cases where we cannot check static values.
13668 if not (Known_Static_Esize (C)
13670 Known_Static_Esize (Ctyp))
13675 -- Size of component must be addressable or greater than 64 bits
13676 -- and a multiple of bytes.
13678 if not Addressable (Esize (C)) and then Esize (C) < Uint_64 then
13682 -- Check size is proper multiple
13684 if Esize (C) mod Esize (Ctyp) /= 0 then
13688 -- Check alignment of component is OK
13690 if not Known_Component_Bit_Offset (C)
13691 or else Component_Bit_Offset (C) < Uint_0
13692 or else Component_Bit_Offset (C) mod Esize (Ctyp) /= 0
13697 -- Check alignment of record type is OK
13699 if not Known_Alignment (Rec)
13700 or else (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0
13705 -- All tests passed, component is addressable
13710 --------------------------
13711 -- Reason_Bad_Component --
13712 --------------------------
13714 procedure Reason_Bad_Component (C : Entity_Id) is
13715 Rec : constant Entity_Id := Scope (C);
13716 Ctyp : constant Entity_Id := Etype (C);
13719 -- If component clause present assume that's the problem
13721 if Present (Component_Clause (C)) then
13722 Error_Msg_Sloc := Sloc (Component_Clause (C));
13723 Error_Msg_N ("\because of Component_Clause#", N);
13727 -- If pragma Pack clause present, assume that's the problem
13729 if Is_Packed (Rec) then
13730 P := Get_Rep_Pragma (Rec, Name_Pack);
13732 if Present (P) then
13733 Error_Msg_Sloc := Sloc (P);
13734 Error_Msg_N ("\because of pragma Pack#", N);
13739 -- See if record has bad alignment clause
13741 if Has_Alignment_Clause (Rec)
13742 and then Known_Alignment (Rec)
13743 and then (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0
13745 P := Get_Attribute_Definition_Clause (Rec, Attribute_Alignment);
13747 if Present (P) then
13748 Error_Msg_Sloc := Sloc (P);
13749 Error_Msg_N ("\because of Alignment clause#", N);
13753 -- Couldn't find a reason, so return without a message
13756 end Reason_Bad_Component;
13758 -- Start of processing for Validate_Independence
13761 for J in Independence_Checks.First .. Independence_Checks.Last loop
13762 N := Independence_Checks.Table (J).N;
13763 E := Independence_Checks.Table (J).E;
13764 IC := Pragma_Name (N) = Name_Independent_Components;
13766 -- Deal with component case
13768 if Ekind (E) = E_Discriminant or else Ekind (E) = E_Component then
13769 if not OK_Component (E) then
13771 Reason_Bad_Component (E);
13776 -- Deal with record with Independent_Components
13778 if IC and then Is_Record_Type (E) then
13779 Comp := First_Component_Or_Discriminant (E);
13780 while Present (Comp) loop
13781 if not OK_Component (Comp) then
13783 Reason_Bad_Component (Comp);
13787 Next_Component_Or_Discriminant (Comp);
13791 -- Deal with address clause case
13793 if Is_Object (E) then
13794 Addr := Address_Clause (E);
13796 if Present (Addr) then
13798 Error_Msg_Sloc := Sloc (Addr);
13799 Error_Msg_N ("\because of Address clause#", N);
13804 -- Deal with independent components for array type
13806 if IC and then Is_Array_Type (E) then
13807 Check_Array_Type (E);
13810 -- Deal with independent components for array object
13812 if IC and then Is_Object (E) and then Is_Array_Type (Etype (E)) then
13813 Check_Array_Type (Etype (E));
13818 end Validate_Independence;
13820 ------------------------------
13821 -- Validate_Iterable_Aspect --
13822 ------------------------------
13824 procedure Validate_Iterable_Aspect (Typ : Entity_Id; ASN : Node_Id) is
13829 Cursor : constant Entity_Id := Get_Cursor_Type (ASN, Typ);
13831 First_Id : Entity_Id;
13832 Next_Id : Entity_Id;
13833 Has_Element_Id : Entity_Id;
13834 Element_Id : Entity_Id;
13837 -- If previous error aspect is unusable
13839 if Cursor = Any_Type then
13845 Has_Element_Id := Empty;
13846 Element_Id := Empty;
13848 -- Each expression must resolve to a function with the proper signature
13850 Assoc := First (Component_Associations (Expression (ASN)));
13851 while Present (Assoc) loop
13852 Expr := Expression (Assoc);
13855 Prim := First (Choices (Assoc));
13857 if Nkind (Prim) /= N_Identifier or else Present (Next (Prim)) then
13858 Error_Msg_N ("illegal name in association", Prim);
13860 elsif Chars (Prim) = Name_First then
13861 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_First);
13862 First_Id := Entity (Expr);
13864 elsif Chars (Prim) = Name_Next then
13865 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Next);
13866 Next_Id := Entity (Expr);
13868 elsif Chars (Prim) = Name_Has_Element then
13869 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Has_Element);
13870 Has_Element_Id := Entity (Expr);
13872 elsif Chars (Prim) = Name_Element then
13873 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Element);
13874 Element_Id := Entity (Expr);
13877 Error_Msg_N ("invalid name for iterable function", Prim);
13883 if No (First_Id) then
13884 Error_Msg_N ("match for First primitive not found", ASN);
13886 elsif No (Next_Id) then
13887 Error_Msg_N ("match for Next primitive not found", ASN);
13889 elsif No (Has_Element_Id) then
13890 Error_Msg_N ("match for Has_Element primitive not found", ASN);
13892 elsif No (Element_Id) then
13895 end Validate_Iterable_Aspect;
13897 -----------------------------------
13898 -- Validate_Unchecked_Conversion --
13899 -----------------------------------
13901 procedure Validate_Unchecked_Conversion
13903 Act_Unit : Entity_Id)
13905 Source : Entity_Id;
13906 Target : Entity_Id;
13910 -- Obtain source and target types. Note that we call Ancestor_Subtype
13911 -- here because the processing for generic instantiation always makes
13912 -- subtypes, and we want the original frozen actual types.
13914 -- If we are dealing with private types, then do the check on their
13915 -- fully declared counterparts if the full declarations have been
13916 -- encountered (they don't have to be visible, but they must exist).
13918 Source := Ancestor_Subtype (Etype (First_Formal (Act_Unit)));
13920 if Is_Private_Type (Source)
13921 and then Present (Underlying_Type (Source))
13923 Source := Underlying_Type (Source);
13926 Target := Ancestor_Subtype (Etype (Act_Unit));
13928 -- If either type is generic, the instantiation happens within a generic
13929 -- unit, and there is nothing to check. The proper check will happen
13930 -- when the enclosing generic is instantiated.
13932 if Is_Generic_Type (Source) or else Is_Generic_Type (Target) then
13936 if Is_Private_Type (Target)
13937 and then Present (Underlying_Type (Target))
13939 Target := Underlying_Type (Target);
13942 -- Source may be unconstrained array, but not target, except in relaxed
13945 if Is_Array_Type (Target)
13946 and then not Is_Constrained (Target)
13947 and then not Relaxed_RM_Semantics
13950 ("unchecked conversion to unconstrained array not allowed", N);
13954 -- Warn if conversion between two different convention pointers
13956 if Is_Access_Type (Target)
13957 and then Is_Access_Type (Source)
13958 and then Convention (Target) /= Convention (Source)
13959 and then Warn_On_Unchecked_Conversion
13961 -- Give warnings for subprogram pointers only on most targets
13963 if Is_Access_Subprogram_Type (Target)
13964 or else Is_Access_Subprogram_Type (Source)
13967 ("?z?conversion between pointers with different conventions!",
13972 -- Warn if one of the operands is Ada.Calendar.Time. Do not emit a
13973 -- warning when compiling GNAT-related sources.
13975 if Warn_On_Unchecked_Conversion
13976 and then not In_Predefined_Unit (N)
13977 and then RTU_Loaded (Ada_Calendar)
13978 and then (Chars (Source) = Name_Time
13980 Chars (Target) = Name_Time)
13982 -- If Ada.Calendar is loaded and the name of one of the operands is
13983 -- Time, there is a good chance that this is Ada.Calendar.Time.
13986 Calendar_Time : constant Entity_Id := Full_View (RTE (RO_CA_Time));
13988 pragma Assert (Present (Calendar_Time));
13990 if Source = Calendar_Time or else Target = Calendar_Time then
13992 ("?z?representation of 'Time values may change between "
13993 & "'G'N'A'T versions", N);
13998 -- Make entry in unchecked conversion table for later processing by
13999 -- Validate_Unchecked_Conversions, which will check sizes and alignments
14000 -- (using values set by the back end where possible). This is only done
14001 -- if the appropriate warning is active.
14003 if Warn_On_Unchecked_Conversion then
14004 Unchecked_Conversions.Append
14005 (New_Val => UC_Entry'(Eloc => Sloc (N),
14008 Act_Unit => Act_Unit));
14010 -- If both sizes are known statically now, then back-end annotation
14011 -- is not required to do a proper check but if either size is not
14012 -- known statically, then we need the annotation.
14014 if Known_Static_RM_Size (Source)
14016 Known_Static_RM_Size (Target)
14020 Back_Annotate_Rep_Info := True;
14024 -- If unchecked conversion to access type, and access type is declared
14025 -- in the same unit as the unchecked conversion, then set the flag
14026 -- No_Strict_Aliasing (no strict aliasing is implicit here)
14028 if Is_Access_Type (Target) and then
14029 In_Same_Source_Unit (Target, N)
14031 Set_No_Strict_Aliasing (Implementation_Base_Type (Target));
14034 -- Generate N_Validate_Unchecked_Conversion node for back end in case
14035 -- the back end needs to perform special validation checks.
14037 -- Shouldn't this be in Exp_Ch13, since the check only gets done if we
14038 -- have full expansion and the back end is called ???
14041 Make_Validate_Unchecked_Conversion (Sloc (N));
14042 Set_Source_Type (Vnode, Source);
14043 Set_Target_Type (Vnode, Target);
14045 -- If the unchecked conversion node is in a list, just insert before it.
14046 -- If not we have some strange case, not worth bothering about.
14048 if Is_List_Member (N) then
14049 Insert_After (N, Vnode);
14051 end Validate_Unchecked_Conversion;
14053 ------------------------------------
14054 -- Validate_Unchecked_Conversions --
14055 ------------------------------------
14057 procedure Validate_Unchecked_Conversions is
14059 for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop
14061 T : UC_Entry renames Unchecked_Conversions.Table (N);
14063 Act_Unit : constant Entity_Id := T.Act_Unit;
14064 Eloc : constant Source_Ptr := T.Eloc;
14065 Source : constant Entity_Id := T.Source;
14066 Target : constant Entity_Id := T.Target;
14072 -- Skip if function marked as warnings off
14074 if Warnings_Off (Act_Unit) then
14078 -- This validation check, which warns if we have unequal sizes for
14079 -- unchecked conversion, and thus potentially implementation
14080 -- dependent semantics, is one of the few occasions on which we
14081 -- use the official RM size instead of Esize. See description in
14082 -- Einfo "Handling of Type'Size Values" for details.
14084 if Serious_Errors_Detected = 0
14085 and then Known_Static_RM_Size (Source)
14086 and then Known_Static_RM_Size (Target)
14088 -- Don't do the check if warnings off for either type, note the
14089 -- deliberate use of OR here instead of OR ELSE to get the flag
14090 -- Warnings_Off_Used set for both types if appropriate.
14092 and then not (Has_Warnings_Off (Source)
14094 Has_Warnings_Off (Target))
14096 Source_Siz := RM_Size (Source);
14097 Target_Siz := RM_Size (Target);
14099 if Source_Siz /= Target_Siz then
14101 ("?z?types for unchecked conversion have different sizes!",
14104 if All_Errors_Mode then
14105 Error_Msg_Name_1 := Chars (Source);
14106 Error_Msg_Uint_1 := Source_Siz;
14107 Error_Msg_Name_2 := Chars (Target);
14108 Error_Msg_Uint_2 := Target_Siz;
14109 Error_Msg ("\size of % is ^, size of % is ^?z?", Eloc);
14111 Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz);
14113 if Is_Discrete_Type (Source)
14115 Is_Discrete_Type (Target)
14117 if Source_Siz > Target_Siz then
14119 ("\?z?^ high order bits of source will "
14120 & "be ignored!", Eloc);
14122 elsif Is_Unsigned_Type (Source) then
14124 ("\?z?source will be extended with ^ high order "
14125 & "zero bits!", Eloc);
14129 ("\?z?source will be extended with ^ high order "
14130 & "sign bits!", Eloc);
14133 elsif Source_Siz < Target_Siz then
14134 if Is_Discrete_Type (Target) then
14135 if Bytes_Big_Endian then
14137 ("\?z?target value will include ^ undefined "
14138 & "low order bits!", Eloc);
14141 ("\?z?target value will include ^ undefined "
14142 & "high order bits!", Eloc);
14147 ("\?z?^ trailing bits of target value will be "
14148 & "undefined!", Eloc);
14151 else pragma Assert (Source_Siz > Target_Siz);
14152 if Is_Discrete_Type (Source) then
14153 if Bytes_Big_Endian then
14155 ("\?z?^ low order bits of source will be "
14156 & "ignored!", Eloc);
14159 ("\?z?^ high order bits of source will be "
14160 & "ignored!", Eloc);
14165 ("\?z?^ trailing bits of source will be "
14166 & "ignored!", Eloc);
14173 -- If both types are access types, we need to check the alignment.
14174 -- If the alignment of both is specified, we can do it here.
14176 if Serious_Errors_Detected = 0
14177 and then Is_Access_Type (Source)
14178 and then Is_Access_Type (Target)
14179 and then Target_Strict_Alignment
14180 and then Present (Designated_Type (Source))
14181 and then Present (Designated_Type (Target))
14184 D_Source : constant Entity_Id := Designated_Type (Source);
14185 D_Target : constant Entity_Id := Designated_Type (Target);
14188 if Known_Alignment (D_Source)
14190 Known_Alignment (D_Target)
14193 Source_Align : constant Uint := Alignment (D_Source);
14194 Target_Align : constant Uint := Alignment (D_Target);
14197 if Source_Align < Target_Align
14198 and then not Is_Tagged_Type (D_Source)
14200 -- Suppress warning if warnings suppressed on either
14201 -- type or either designated type. Note the use of
14202 -- OR here instead of OR ELSE. That is intentional,
14203 -- we would like to set flag Warnings_Off_Used in
14204 -- all types for which warnings are suppressed.
14206 and then not (Has_Warnings_Off (D_Source)
14208 Has_Warnings_Off (D_Target)
14210 Has_Warnings_Off (Source)
14212 Has_Warnings_Off (Target))
14214 Error_Msg_Uint_1 := Target_Align;
14215 Error_Msg_Uint_2 := Source_Align;
14216 Error_Msg_Node_1 := D_Target;
14217 Error_Msg_Node_2 := D_Source;
14219 ("?z?alignment of & (^) is stricter than "
14220 & "alignment of & (^)!", Eloc);
14222 ("\?z?resulting access value may have invalid "
14223 & "alignment!", Eloc);
14234 end Validate_Unchecked_Conversions;