1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2016, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Aspects; use Aspects;
27 with Atree; use Atree;
28 with Checks; use Checks;
29 with Debug; use Debug;
30 with Einfo; use Einfo;
31 with Elists; use Elists;
32 with Errout; use Errout;
33 with 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 Restrict; use Restrict;
46 with Rident; use Rident;
47 with Rtsfind; use Rtsfind;
49 with Sem_Aux; use Sem_Aux;
50 with Sem_Case; use Sem_Case;
51 with Sem_Ch3; use Sem_Ch3;
52 with Sem_Ch6; use Sem_Ch6;
53 with Sem_Ch8; use Sem_Ch8;
54 with Sem_Dim; use Sem_Dim;
55 with Sem_Disp; use Sem_Disp;
56 with Sem_Eval; use Sem_Eval;
57 with Sem_Prag; use Sem_Prag;
58 with Sem_Res; use Sem_Res;
59 with Sem_Type; use Sem_Type;
60 with Sem_Util; use Sem_Util;
61 with Sem_Warn; use Sem_Warn;
62 with Sinput; use Sinput;
63 with Snames; use Snames;
64 with Stand; use Stand;
65 with Sinfo; use Sinfo;
66 with Targparm; use Targparm;
67 with Ttypes; use Ttypes;
68 with Tbuild; use Tbuild;
69 with Urealp; use Urealp;
70 with Warnsw; use Warnsw;
72 with GNAT.Heap_Sort_G;
74 package body Sem_Ch13 is
76 SSU : constant Pos := System_Storage_Unit;
77 -- Convenient short hand for commonly used constant
79 -----------------------
80 -- Local Subprograms --
81 -----------------------
83 procedure Alignment_Check_For_Size_Change (Typ : Entity_Id; Size : Uint);
84 -- This routine is called after setting one of the sizes of type entity
85 -- Typ to Size. The purpose is to deal with the situation of a derived
86 -- type whose inherited alignment is no longer appropriate for the new
87 -- size value. In this case, we reset the Alignment to unknown.
89 procedure Build_Discrete_Static_Predicate
93 -- Given a predicated type Typ, where Typ is a discrete static subtype,
94 -- whose predicate expression is Expr, tests if Expr is a static predicate,
95 -- and if so, builds the predicate range list. Nam is the name of the one
96 -- argument to the predicate function. Occurrences of the type name in the
97 -- predicate expression have been replaced by identifier references to this
98 -- name, which is unique, so any identifier with Chars matching Nam must be
99 -- a reference to the type. If the predicate is non-static, this procedure
100 -- returns doing nothing. If the predicate is static, then the predicate
101 -- list is stored in Static_Discrete_Predicate (Typ), and the Expr is
102 -- rewritten as a canonicalized membership operation.
104 function Build_Export_Import_Pragma
106 Id : Entity_Id) return Node_Id;
107 -- Create the corresponding pragma for aspect Export or Import denoted by
108 -- Asp. Id is the related entity subject to the aspect. Return Empty when
109 -- the expression of aspect Asp evaluates to False or is erroneous.
111 function Build_Predicate_Function_Declaration
112 (Typ : Entity_Id) return Node_Id;
113 -- Build the declaration for a predicate function. The declaration is built
114 -- at the end of the declarative part containing the type definition, which
115 -- may be before the freeze point of the type. The predicate expression is
116 -- pre-analyzed at this point, to catch visibility errors.
118 procedure Build_Predicate_Functions (Typ : Entity_Id; N : Node_Id);
119 -- If Typ has predicates (indicated by Has_Predicates being set for Typ),
120 -- then either there are pragma Predicate entries on the rep chain for the
121 -- type (note that Predicate aspects are converted to pragma Predicate), or
122 -- there are inherited aspects from a parent type, or ancestor subtypes.
123 -- This procedure builds body for the Predicate function that tests these
124 -- predicates. N is the freeze node for the type. The spec of the function
125 -- is inserted before the freeze node, and the body of the function is
126 -- inserted after the freeze node. If the predicate expression has a least
127 -- one Raise_Expression, then this procedure also builds the M version of
128 -- the predicate function for use in membership tests.
130 procedure Check_Pool_Size_Clash (Ent : Entity_Id; SP, SS : Node_Id);
131 -- Called if both Storage_Pool and Storage_Size attribute definition
132 -- clauses (SP and SS) are present for entity Ent. Issue error message.
134 procedure Freeze_Entity_Checks (N : Node_Id);
135 -- Called from Analyze_Freeze_Entity and Analyze_Generic_Freeze Entity
136 -- to generate appropriate semantic checks that are delayed until this
137 -- point (they had to be delayed this long for cases of delayed aspects,
138 -- e.g. analysis of statically predicated subtypes in choices, for which
139 -- we have to be sure the subtypes in question are frozen before checking).
141 function Get_Alignment_Value (Expr : Node_Id) return Uint;
142 -- Given the expression for an alignment value, returns the corresponding
143 -- Uint value. If the value is inappropriate, then error messages are
144 -- posted as required, and a value of No_Uint is returned.
146 procedure Get_Interfacing_Aspects
147 (Iface_Asp : Node_Id;
148 Conv_Asp : out Node_Id;
149 EN_Asp : out Node_Id;
150 Expo_Asp : out Node_Id;
151 Imp_Asp : out Node_Id;
152 LN_Asp : out Node_Id;
153 Do_Checks : Boolean := False);
154 -- Given a single interfacing aspect Iface_Asp, retrieve other interfacing
155 -- aspects that apply to the same related entity. The aspects considered by
156 -- this routine are as follows:
158 -- Conv_Asp - aspect Convention
159 -- EN_Asp - aspect External_Name
160 -- Expo_Asp - aspect Export
161 -- Imp_Asp - aspect Import
162 -- LN_Asp - aspect Link_Name
164 -- When flag Do_Checks is set, this routine will flag duplicate uses of
167 function Is_Operational_Item (N : Node_Id) return Boolean;
168 -- A specification for a stream attribute is allowed before the full type
169 -- is declared, as explained in AI-00137 and the corrigendum. Attributes
170 -- that do not specify a representation characteristic are operational
173 function Is_Predicate_Static
175 Nam : Name_Id) return Boolean;
176 -- Given predicate expression Expr, tests if Expr is predicate-static in
177 -- the sense of the rules in (RM 3.2.4 (15-24)). Occurrences of the type
178 -- name in the predicate expression have been replaced by references to
179 -- an identifier whose Chars field is Nam. This name is unique, so any
180 -- identifier with Chars matching Nam must be a reference to the type.
181 -- Returns True if the expression is predicate-static and False otherwise,
182 -- but is not in the business of setting flags or issuing error messages.
184 -- Only scalar types can have static predicates, so False is always
185 -- returned for non-scalar types.
187 -- Note: the RM seems to suggest that string types can also have static
188 -- predicates. But that really makes lttle sense as very few useful
189 -- predicates can be constructed for strings. Remember that:
193 -- is not a static expression. So even though the clearly faulty RM wording
194 -- allows the following:
196 -- subtype S is String with Static_Predicate => S < "DEF"
198 -- We can't allow this, otherwise we have predicate-static applying to a
199 -- larger class than static expressions, which was never intended.
201 procedure New_Stream_Subprogram
205 Nam : TSS_Name_Type);
206 -- Create a subprogram renaming of a given stream attribute to the
207 -- designated subprogram and then in the tagged case, provide this as a
208 -- primitive operation, or in the untagged case make an appropriate TSS
209 -- entry. This is more properly an expansion activity than just semantics,
210 -- but the presence of user-defined stream functions for limited types
211 -- is a legality check, which is why this takes place here rather than in
212 -- exp_ch13, where it was previously. Nam indicates the name of the TSS
213 -- function to be generated.
215 -- To avoid elaboration anomalies with freeze nodes, for untagged types
216 -- we generate both a subprogram declaration and a subprogram renaming
217 -- declaration, so that the attribute specification is handled as a
218 -- renaming_as_body. For tagged types, the specification is one of the
221 procedure Resolve_Iterable_Operation
226 -- If the name of a primitive operation for an Iterable aspect is
227 -- overloaded, resolve according to required signature.
233 Biased : Boolean := True);
234 -- If Biased is True, sets Has_Biased_Representation flag for E, and
235 -- outputs a warning message at node N if Warn_On_Biased_Representation is
236 -- is True. This warning inserts the string Msg to describe the construct
239 ---------------------------------------------------
240 -- Table for Validate_Compile_Time_Warning_Error --
241 ---------------------------------------------------
243 -- The following table collects pragmas Compile_Time_Error and Compile_
244 -- Time_Warning for validation. Entries are made by calls to subprogram
245 -- Validate_Compile_Time_Warning_Error, and the call to the procedure
246 -- Validate_Compile_Time_Warning_Errors does the actual error checking
247 -- and posting of warning and error messages. The reason for this delayed
248 -- processing is to take advantage of back-annotations of attributes size
249 -- and alignment values performed by the back end.
251 -- Note: the reason we store a Source_Ptr value instead of a Node_Id is
252 -- that by the time Validate_Unchecked_Conversions is called, Sprint will
253 -- already have modified all Sloc values if the -gnatD option is set.
255 type CTWE_Entry is record
257 -- Source location used in warnings and error messages
260 -- Pragma Compile_Time_Error or Compile_Time_Warning
263 -- The scope which encloses the pragma
266 package Compile_Time_Warnings_Errors is new Table.Table (
267 Table_Component_Type => CTWE_Entry,
268 Table_Index_Type => Int,
269 Table_Low_Bound => 1,
271 Table_Increment => 200,
272 Table_Name => "Compile_Time_Warnings_Errors");
274 ----------------------------------------------
275 -- Table for Validate_Unchecked_Conversions --
276 ----------------------------------------------
278 -- The following table collects unchecked conversions for validation.
279 -- Entries are made by Validate_Unchecked_Conversion and then the call
280 -- to Validate_Unchecked_Conversions does the actual error checking and
281 -- posting of warnings. The reason for this delayed processing is to take
282 -- advantage of back-annotations of size and alignment values performed by
285 -- Note: the reason we store a Source_Ptr value instead of a Node_Id is
286 -- that by the time Validate_Unchecked_Conversions is called, Sprint will
287 -- already have modified all Sloc values if the -gnatD option is set.
289 type UC_Entry is record
290 Eloc : Source_Ptr; -- node used for posting warnings
291 Source : Entity_Id; -- source type for unchecked conversion
292 Target : Entity_Id; -- target type for unchecked conversion
293 Act_Unit : Entity_Id; -- actual function instantiated
296 package Unchecked_Conversions is new Table.Table (
297 Table_Component_Type => UC_Entry,
298 Table_Index_Type => Int,
299 Table_Low_Bound => 1,
301 Table_Increment => 200,
302 Table_Name => "Unchecked_Conversions");
304 ----------------------------------------
305 -- Table for Validate_Address_Clauses --
306 ----------------------------------------
308 -- If an address clause has the form
310 -- for X'Address use Expr
312 -- where Expr has a value known at compile time or is of the form Y'Address
313 -- or recursively is a reference to a constant initialized with either of
314 -- these forms, and the value of Expr is not a multiple of X's alignment,
315 -- or if Y has a smaller alignment than X, then that merits a warning about
316 -- possible bad alignment. The following table collects address clauses of
317 -- this kind. We put these in a table so that they can be checked after the
318 -- back end has completed annotation of the alignments of objects, since we
319 -- can catch more cases that way.
321 type Address_Clause_Check_Record is record
323 -- The address clause
326 -- The entity of the object subject to the address clause
329 -- The value of the address in the first case
332 -- The entity of the object being overlaid in the second case
335 -- Whether the address is offset within Y in the second case
338 package Address_Clause_Checks is new Table.Table (
339 Table_Component_Type => Address_Clause_Check_Record,
340 Table_Index_Type => Int,
341 Table_Low_Bound => 1,
343 Table_Increment => 200,
344 Table_Name => "Address_Clause_Checks");
346 -----------------------------------------
347 -- Adjust_Record_For_Reverse_Bit_Order --
348 -----------------------------------------
350 procedure Adjust_Record_For_Reverse_Bit_Order (R : Entity_Id) is
355 -- Processing depends on version of Ada
357 -- For Ada 95, we just renumber bits within a storage unit. We do the
358 -- same for Ada 83 mode, since we recognize the Bit_Order attribute in
359 -- Ada 83, and are free to add this extension.
361 if Ada_Version < Ada_2005 then
362 Comp := First_Component_Or_Discriminant (R);
363 while Present (Comp) loop
364 CC := Component_Clause (Comp);
366 -- If component clause is present, then deal with the non-default
367 -- bit order case for Ada 95 mode.
369 -- We only do this processing for the base type, and in fact that
370 -- is important, since otherwise if there are record subtypes, we
371 -- could reverse the bits once for each subtype, which is wrong.
373 if Present (CC) and then Ekind (R) = E_Record_Type then
375 CFB : constant Uint := Component_Bit_Offset (Comp);
376 CSZ : constant Uint := Esize (Comp);
377 CLC : constant Node_Id := Component_Clause (Comp);
378 Pos : constant Node_Id := Position (CLC);
379 FB : constant Node_Id := First_Bit (CLC);
381 Storage_Unit_Offset : constant Uint :=
382 CFB / System_Storage_Unit;
384 Start_Bit : constant Uint :=
385 CFB mod System_Storage_Unit;
388 -- Cases where field goes over storage unit boundary
390 if Start_Bit + CSZ > System_Storage_Unit then
392 -- Allow multi-byte field but generate warning
394 if Start_Bit mod System_Storage_Unit = 0
395 and then CSZ mod System_Storage_Unit = 0
398 ("info: multi-byte field specified with "
399 & "non-standard Bit_Order?V?", CLC);
401 if Bytes_Big_Endian then
403 ("\bytes are not reversed "
404 & "(component is big-endian)?V?", CLC);
407 ("\bytes are not reversed "
408 & "(component is little-endian)?V?", CLC);
411 -- Do not allow non-contiguous field
415 ("attempt to specify non-contiguous field "
416 & "not permitted", CLC);
418 ("\caused by non-standard Bit_Order "
421 ("\consider possibility of using "
422 & "Ada 2005 mode here", CLC);
425 -- Case where field fits in one storage unit
428 -- Give warning if suspicious component clause
430 if Intval (FB) >= System_Storage_Unit
431 and then Warn_On_Reverse_Bit_Order
434 ("info: Bit_Order clause does not affect " &
435 "byte ordering?V?", Pos);
437 Intval (Pos) + Intval (FB) /
440 ("info: position normalized to ^ before bit " &
441 "order interpreted?V?", Pos);
444 -- Here is where we fix up the Component_Bit_Offset value
445 -- to account for the reverse bit order. Some examples of
446 -- what needs to be done are:
448 -- First_Bit .. Last_Bit Component_Bit_Offset
460 -- The rule is that the first bit is is obtained by
461 -- subtracting the old ending bit from storage_unit - 1.
463 Set_Component_Bit_Offset
465 (Storage_Unit_Offset * System_Storage_Unit) +
466 (System_Storage_Unit - 1) -
467 (Start_Bit + CSZ - 1));
469 Set_Normalized_First_Bit
471 Component_Bit_Offset (Comp) mod
472 System_Storage_Unit);
477 Next_Component_Or_Discriminant (Comp);
480 -- For Ada 2005, we do machine scalar processing, as fully described In
481 -- AI-133. This involves gathering all components which start at the
482 -- same byte offset and processing them together. Same approach is still
483 -- valid in later versions including Ada 2012.
487 Max_Machine_Scalar_Size : constant Uint :=
489 (Standard_Long_Long_Integer_Size);
490 -- We use this as the maximum machine scalar size
493 SSU : constant Uint := UI_From_Int (System_Storage_Unit);
496 -- This first loop through components does two things. First it
497 -- deals with the case of components with component clauses whose
498 -- length is greater than the maximum machine scalar size (either
499 -- accepting them or rejecting as needed). Second, it counts the
500 -- number of components with component clauses whose length does
501 -- not exceed this maximum for later processing.
504 Comp := First_Component_Or_Discriminant (R);
505 while Present (Comp) loop
506 CC := Component_Clause (Comp);
510 Fbit : constant Uint := Static_Integer (First_Bit (CC));
511 Lbit : constant Uint := Static_Integer (Last_Bit (CC));
514 -- Case of component with last bit >= max machine scalar
516 if Lbit >= Max_Machine_Scalar_Size then
518 -- This is allowed only if first bit is zero, and
519 -- last bit + 1 is a multiple of storage unit size.
521 if Fbit = 0 and then (Lbit + 1) mod SSU = 0 then
523 -- This is the case to give a warning if enabled
525 if Warn_On_Reverse_Bit_Order then
527 ("info: multi-byte field specified with "
528 & "non-standard Bit_Order?V?", CC);
530 if Bytes_Big_Endian then
532 ("\bytes are not reversed "
533 & "(component is big-endian)?V?", CC);
536 ("\bytes are not reversed "
537 & "(component is little-endian)?V?", CC);
541 -- Give error message for RM 13.5.1(10) violation
545 ("machine scalar rules not followed for&",
546 First_Bit (CC), Comp);
548 Error_Msg_Uint_1 := Lbit + 1;
549 Error_Msg_Uint_2 := Max_Machine_Scalar_Size;
551 ("\last bit + 1 (^) exceeds maximum machine "
555 if (Lbit + 1) mod SSU /= 0 then
556 Error_Msg_Uint_1 := SSU;
558 ("\and is not a multiple of Storage_Unit (^) "
563 Error_Msg_Uint_1 := Fbit;
565 ("\and first bit (^) is non-zero "
571 -- OK case of machine scalar related component clause,
572 -- For now, just count them.
575 Num_CC := Num_CC + 1;
580 Next_Component_Or_Discriminant (Comp);
583 -- We need to sort the component clauses on the basis of the
584 -- Position values in the clause, so we can group clauses with
585 -- the same Position together to determine the relevant machine
589 Comps : array (0 .. Num_CC) of Entity_Id;
590 -- Array to collect component and discriminant entities. The
591 -- data starts at index 1, the 0'th entry is for the sort
594 function CP_Lt (Op1, Op2 : Natural) return Boolean;
595 -- Compare routine for Sort
597 procedure CP_Move (From : Natural; To : Natural);
598 -- Move routine for Sort
600 package Sorting is new GNAT.Heap_Sort_G (CP_Move, CP_Lt);
604 -- Start and stop positions in the component list of the set of
605 -- components with the same starting position (that constitute
606 -- components in a single machine scalar).
609 -- Maximum last bit value of any component in this set
612 -- Corresponding machine scalar size
618 function CP_Lt (Op1, Op2 : Natural) return Boolean is
620 return Position (Component_Clause (Comps (Op1))) <
621 Position (Component_Clause (Comps (Op2)));
628 procedure CP_Move (From : Natural; To : Natural) is
630 Comps (To) := Comps (From);
633 -- Start of processing for Sort_CC
636 -- Collect the machine scalar relevant component clauses
639 Comp := First_Component_Or_Discriminant (R);
640 while Present (Comp) loop
642 CC : constant Node_Id := Component_Clause (Comp);
645 -- Collect only component clauses whose last bit is less
646 -- than machine scalar size. Any component clause whose
647 -- last bit exceeds this value does not take part in
648 -- machine scalar layout considerations. The test for
649 -- Error_Posted makes sure we exclude component clauses
650 -- for which we already posted an error.
653 and then not Error_Posted (Last_Bit (CC))
654 and then Static_Integer (Last_Bit (CC)) <
655 Max_Machine_Scalar_Size
657 Num_CC := Num_CC + 1;
658 Comps (Num_CC) := Comp;
662 Next_Component_Or_Discriminant (Comp);
665 -- Sort by ascending position number
667 Sorting.Sort (Num_CC);
669 -- We now have all the components whose size does not exceed
670 -- the max machine scalar value, sorted by starting position.
671 -- In this loop we gather groups of clauses starting at the
672 -- same position, to process them in accordance with AI-133.
675 while Stop < Num_CC loop
680 (Last_Bit (Component_Clause (Comps (Start))));
681 while Stop < Num_CC loop
683 (Position (Component_Clause (Comps (Stop + 1)))) =
685 (Position (Component_Clause (Comps (Stop))))
693 (Component_Clause (Comps (Stop)))));
699 -- Now we have a group of component clauses from Start to
700 -- Stop whose positions are identical, and MaxL is the
701 -- maximum last bit value of any of these components.
703 -- We need to determine the corresponding machine scalar
704 -- size. This loop assumes that machine scalar sizes are
705 -- even, and that each possible machine scalar has twice
706 -- as many bits as the next smaller one.
708 MSS := Max_Machine_Scalar_Size;
710 and then (MSS / 2) >= SSU
711 and then (MSS / 2) > MaxL
716 -- Here is where we fix up the Component_Bit_Offset value
717 -- to account for the reverse bit order. Some examples of
718 -- what needs to be done for the case of a machine scalar
721 -- First_Bit .. Last_Bit Component_Bit_Offset
733 -- The rule is that the first bit is obtained by subtracting
734 -- the old ending bit from machine scalar size - 1.
736 for C in Start .. Stop loop
738 Comp : constant Entity_Id := Comps (C);
739 CC : constant Node_Id := Component_Clause (Comp);
741 LB : constant Uint := Static_Integer (Last_Bit (CC));
742 NFB : constant Uint := MSS - Uint_1 - LB;
743 NLB : constant Uint := NFB + Esize (Comp) - 1;
744 Pos : constant Uint := Static_Integer (Position (CC));
747 if Warn_On_Reverse_Bit_Order then
748 Error_Msg_Uint_1 := MSS;
750 ("info: reverse bit order in machine " &
751 "scalar of length^?V?", First_Bit (CC));
752 Error_Msg_Uint_1 := NFB;
753 Error_Msg_Uint_2 := NLB;
755 if Bytes_Big_Endian then
757 ("\big-endian range for component "
758 & "& is ^ .. ^?V?", First_Bit (CC), Comp);
761 ("\little-endian range for component"
762 & "& is ^ .. ^?V?", First_Bit (CC), Comp);
766 Set_Component_Bit_Offset (Comp, Pos * SSU + NFB);
767 Set_Normalized_First_Bit (Comp, NFB mod SSU);
774 end Adjust_Record_For_Reverse_Bit_Order;
776 -------------------------------------
777 -- Alignment_Check_For_Size_Change --
778 -------------------------------------
780 procedure Alignment_Check_For_Size_Change (Typ : Entity_Id; Size : Uint) is
782 -- If the alignment is known, and not set by a rep clause, and is
783 -- inconsistent with the size being set, then reset it to unknown,
784 -- we assume in this case that the size overrides the inherited
785 -- alignment, and that the alignment must be recomputed.
787 if Known_Alignment (Typ)
788 and then not Has_Alignment_Clause (Typ)
789 and then Size mod (Alignment (Typ) * SSU) /= 0
791 Init_Alignment (Typ);
793 end Alignment_Check_For_Size_Change;
795 -------------------------------------
796 -- Analyze_Aspects_At_Freeze_Point --
797 -------------------------------------
799 procedure Analyze_Aspects_At_Freeze_Point (E : Entity_Id) is
800 procedure Analyze_Aspect_Default_Value (ASN : Node_Id);
801 -- This routine analyzes an Aspect_Default_[Component_]Value denoted by
802 -- the aspect specification node ASN.
804 procedure Inherit_Delayed_Rep_Aspects (ASN : Node_Id);
805 -- As discussed in the spec of Aspects (see Aspect_Delay declaration),
806 -- a derived type can inherit aspects from its parent which have been
807 -- specified at the time of the derivation using an aspect, as in:
809 -- type A is range 1 .. 10
810 -- with Size => Not_Defined_Yet;
814 -- Not_Defined_Yet : constant := 64;
816 -- In this example, the Size of A is considered to be specified prior
817 -- to the derivation, and thus inherited, even though the value is not
818 -- known at the time of derivation. To deal with this, we use two entity
819 -- flags. The flag Has_Derived_Rep_Aspects is set in the parent type (A
820 -- here), and then the flag May_Inherit_Delayed_Rep_Aspects is set in
821 -- the derived type (B here). If this flag is set when the derived type
822 -- is frozen, then this procedure is called to ensure proper inheritance
823 -- of all delayed aspects from the parent type. The derived type is E,
824 -- the argument to Analyze_Aspects_At_Freeze_Point. ASN is the first
825 -- aspect specification node in the Rep_Item chain for the parent type.
827 procedure Make_Pragma_From_Boolean_Aspect (ASN : Node_Id);
828 -- Given an aspect specification node ASN whose expression is an
829 -- optional Boolean, this routines creates the corresponding pragma
830 -- at the freezing point.
832 ----------------------------------
833 -- Analyze_Aspect_Default_Value --
834 ----------------------------------
836 procedure Analyze_Aspect_Default_Value (ASN : Node_Id) is
837 A_Id : constant Aspect_Id := Get_Aspect_Id (ASN);
838 Ent : constant Entity_Id := Entity (ASN);
839 Expr : constant Node_Id := Expression (ASN);
840 Id : constant Node_Id := Identifier (ASN);
843 Error_Msg_Name_1 := Chars (Id);
845 if not Is_Type (Ent) then
846 Error_Msg_N ("aspect% can only apply to a type", Id);
849 elsif not Is_First_Subtype (Ent) then
850 Error_Msg_N ("aspect% cannot apply to subtype", Id);
853 elsif A_Id = Aspect_Default_Value
854 and then not Is_Scalar_Type (Ent)
856 Error_Msg_N ("aspect% can only be applied to scalar type", Id);
859 elsif A_Id = Aspect_Default_Component_Value then
860 if not Is_Array_Type (Ent) then
861 Error_Msg_N ("aspect% can only be applied to array type", Id);
864 elsif not Is_Scalar_Type (Component_Type (Ent)) then
865 Error_Msg_N ("aspect% requires scalar components", Id);
870 Set_Has_Default_Aspect (Base_Type (Ent));
872 if Is_Scalar_Type (Ent) then
873 Set_Default_Aspect_Value (Base_Type (Ent), Expr);
875 Set_Default_Aspect_Component_Value (Base_Type (Ent), Expr);
877 end Analyze_Aspect_Default_Value;
879 ---------------------------------
880 -- Inherit_Delayed_Rep_Aspects --
881 ---------------------------------
883 procedure Inherit_Delayed_Rep_Aspects (ASN : Node_Id) is
884 A_Id : constant Aspect_Id := Get_Aspect_Id (ASN);
885 P : constant Entity_Id := Entity (ASN);
886 -- Entithy for parent type
889 -- Item from Rep_Item chain
894 -- Loop through delayed aspects for the parent type
897 while Present (N) loop
898 if Nkind (N) = N_Aspect_Specification then
899 exit when Entity (N) /= P;
901 if Is_Delayed_Aspect (N) then
902 A := Get_Aspect_Id (Chars (Identifier (N)));
904 -- Process delayed rep aspect. For Boolean attributes it is
905 -- not possible to cancel an attribute once set (the attempt
906 -- to use an aspect with xxx => False is an error) for a
907 -- derived type. So for those cases, we do not have to check
908 -- if a clause has been given for the derived type, since it
909 -- is harmless to set it again if it is already set.
915 when Aspect_Alignment =>
916 if not Has_Alignment_Clause (E) then
917 Set_Alignment (E, Alignment (P));
922 when Aspect_Atomic =>
923 if Is_Atomic (P) then
929 when Aspect_Atomic_Components =>
930 if Has_Atomic_Components (P) then
931 Set_Has_Atomic_Components (Base_Type (E));
936 when Aspect_Bit_Order =>
937 if Is_Record_Type (E)
938 and then No (Get_Attribute_Definition_Clause
939 (E, Attribute_Bit_Order))
940 and then Reverse_Bit_Order (P)
942 Set_Reverse_Bit_Order (Base_Type (E));
947 when Aspect_Component_Size =>
949 and then not Has_Component_Size_Clause (E)
952 (Base_Type (E), Component_Size (P));
957 when Aspect_Machine_Radix =>
958 if Is_Decimal_Fixed_Point_Type (E)
959 and then not Has_Machine_Radix_Clause (E)
961 Set_Machine_Radix_10 (E, Machine_Radix_10 (P));
964 -- Object_Size (also Size which also sets Object_Size)
966 when Aspect_Object_Size | Aspect_Size =>
967 if not Has_Size_Clause (E)
969 No (Get_Attribute_Definition_Clause
970 (E, Attribute_Object_Size))
972 Set_Esize (E, Esize (P));
978 if not Is_Packed (E) then
979 Set_Is_Packed (Base_Type (E));
981 if Is_Bit_Packed_Array (P) then
982 Set_Is_Bit_Packed_Array (Base_Type (E));
983 Set_Packed_Array_Impl_Type
984 (E, Packed_Array_Impl_Type (P));
988 -- Scalar_Storage_Order
990 when Aspect_Scalar_Storage_Order =>
991 if (Is_Record_Type (E) or else Is_Array_Type (E))
992 and then No (Get_Attribute_Definition_Clause
993 (E, Attribute_Scalar_Storage_Order))
994 and then Reverse_Storage_Order (P)
996 Set_Reverse_Storage_Order (Base_Type (E));
998 -- Clear default SSO indications, since the aspect
999 -- overrides the default.
1001 Set_SSO_Set_Low_By_Default (Base_Type (E), False);
1002 Set_SSO_Set_High_By_Default (Base_Type (E), False);
1007 when Aspect_Small =>
1008 if Is_Fixed_Point_Type (E)
1009 and then not Has_Small_Clause (E)
1011 Set_Small_Value (E, Small_Value (P));
1016 when Aspect_Storage_Size =>
1017 if (Is_Access_Type (E) or else Is_Task_Type (E))
1018 and then not Has_Storage_Size_Clause (E)
1020 Set_Storage_Size_Variable
1021 (Base_Type (E), Storage_Size_Variable (P));
1026 when Aspect_Value_Size =>
1028 -- Value_Size is never inherited, it is either set by
1029 -- default, or it is explicitly set for the derived
1030 -- type. So nothing to do here.
1036 when Aspect_Volatile =>
1037 if Is_Volatile (P) then
1038 Set_Is_Volatile (E);
1041 -- Volatile_Full_Access
1043 when Aspect_Volatile_Full_Access =>
1044 if Is_Volatile_Full_Access (P) then
1045 Set_Is_Volatile_Full_Access (E);
1048 -- Volatile_Components
1050 when Aspect_Volatile_Components =>
1051 if Has_Volatile_Components (P) then
1052 Set_Has_Volatile_Components (Base_Type (E));
1055 -- That should be all the Rep Aspects
1058 pragma Assert (Aspect_Delay (A_Id) /= Rep_Aspect);
1065 N := Next_Rep_Item (N);
1067 end Inherit_Delayed_Rep_Aspects;
1069 -------------------------------------
1070 -- Make_Pragma_From_Boolean_Aspect --
1071 -------------------------------------
1073 procedure Make_Pragma_From_Boolean_Aspect (ASN : Node_Id) is
1074 Ident : constant Node_Id := Identifier (ASN);
1075 A_Name : constant Name_Id := Chars (Ident);
1076 A_Id : constant Aspect_Id := Get_Aspect_Id (A_Name);
1077 Ent : constant Entity_Id := Entity (ASN);
1078 Expr : constant Node_Id := Expression (ASN);
1079 Loc : constant Source_Ptr := Sloc (ASN);
1081 procedure Check_False_Aspect_For_Derived_Type;
1082 -- This procedure checks for the case of a false aspect for a derived
1083 -- type, which improperly tries to cancel an aspect inherited from
1086 -----------------------------------------
1087 -- Check_False_Aspect_For_Derived_Type --
1088 -----------------------------------------
1090 procedure Check_False_Aspect_For_Derived_Type is
1094 -- We are only checking derived types
1096 if not Is_Derived_Type (E) then
1100 Par := Nearest_Ancestor (E);
1103 when Aspect_Atomic | Aspect_Shared =>
1104 if not Is_Atomic (Par) then
1108 when Aspect_Atomic_Components =>
1109 if not Has_Atomic_Components (Par) then
1113 when Aspect_Discard_Names =>
1114 if not Discard_Names (Par) then
1119 if not Is_Packed (Par) then
1123 when Aspect_Unchecked_Union =>
1124 if not Is_Unchecked_Union (Par) then
1128 when Aspect_Volatile =>
1129 if not Is_Volatile (Par) then
1133 when Aspect_Volatile_Components =>
1134 if not Has_Volatile_Components (Par) then
1138 when Aspect_Volatile_Full_Access =>
1139 if not Is_Volatile_Full_Access (Par) then
1147 -- Fall through means we are canceling an inherited aspect
1149 Error_Msg_Name_1 := A_Name;
1151 ("derived type& inherits aspect%, cannot cancel", Expr, E);
1152 end Check_False_Aspect_For_Derived_Type;
1158 -- Start of processing for Make_Pragma_From_Boolean_Aspect
1161 -- Note that we know Expr is present, because for a missing Expr
1162 -- argument, we knew it was True and did not need to delay the
1163 -- evaluation to the freeze point.
1165 if Is_False (Static_Boolean (Expr)) then
1166 Check_False_Aspect_For_Derived_Type;
1171 Pragma_Identifier =>
1172 Make_Identifier (Sloc (Ident), Chars (Ident)),
1173 Pragma_Argument_Associations => New_List (
1174 Make_Pragma_Argument_Association (Sloc (Ident),
1175 Expression => New_Occurrence_Of (Ent, Sloc (Ident)))));
1177 Set_From_Aspect_Specification (Prag, True);
1178 Set_Corresponding_Aspect (Prag, ASN);
1179 Set_Aspect_Rep_Item (ASN, Prag);
1180 Set_Is_Delayed_Aspect (Prag);
1181 Set_Parent (Prag, ASN);
1183 end Make_Pragma_From_Boolean_Aspect;
1191 -- Start of processing for Analyze_Aspects_At_Freeze_Point
1194 -- Must be visible in current scope
1196 if not Scope_Within_Or_Same (Current_Scope, Scope (E)) then
1200 -- Look for aspect specification entries for this entity
1202 ASN := First_Rep_Item (E);
1203 while Present (ASN) loop
1204 if Nkind (ASN) = N_Aspect_Specification then
1205 exit when Entity (ASN) /= E;
1207 if Is_Delayed_Aspect (ASN) then
1208 A_Id := Get_Aspect_Id (ASN);
1212 -- For aspects whose expression is an optional Boolean, make
1213 -- the corresponding pragma at the freeze point.
1215 when Boolean_Aspects |
1216 Library_Unit_Aspects =>
1218 -- Aspects Export and Import require special handling.
1219 -- Both are by definition Boolean and may benefit from
1220 -- forward references, however their expressions are
1221 -- treated as static. In addition, the syntax of their
1222 -- corresponding pragmas requires extra "pieces" which
1223 -- may also contain forward references. To account for
1224 -- all of this, the corresponding pragma is created by
1225 -- Analyze_Aspect_Export_Import, but is not analyzed as
1226 -- the complete analysis must happen now.
1228 if A_Id = Aspect_Export or else A_Id = Aspect_Import then
1231 -- Otherwise create a corresponding pragma
1234 Make_Pragma_From_Boolean_Aspect (ASN);
1237 -- Special handling for aspects that don't correspond to
1238 -- pragmas/attributes.
1240 when Aspect_Default_Value |
1241 Aspect_Default_Component_Value =>
1243 -- Do not inherit aspect for anonymous base type of a
1244 -- scalar or array type, because they apply to the first
1245 -- subtype of the type, and will be processed when that
1246 -- first subtype is frozen.
1248 if Is_Derived_Type (E)
1249 and then not Comes_From_Source (E)
1250 and then E /= First_Subtype (E)
1254 Analyze_Aspect_Default_Value (ASN);
1257 -- Ditto for iterator aspects, because the corresponding
1258 -- attributes may not have been analyzed yet.
1260 when Aspect_Constant_Indexing |
1261 Aspect_Variable_Indexing |
1262 Aspect_Default_Iterator |
1263 Aspect_Iterator_Element =>
1264 Analyze (Expression (ASN));
1266 if Etype (Expression (ASN)) = Any_Type then
1268 ("\aspect must be fully defined before & is frozen",
1272 when Aspect_Iterable =>
1273 Validate_Iterable_Aspect (E, ASN);
1279 Ritem := Aspect_Rep_Item (ASN);
1281 if Present (Ritem) then
1287 Next_Rep_Item (ASN);
1290 -- This is where we inherit delayed rep aspects from our parent. Note
1291 -- that if we fell out of the above loop with ASN non-empty, it means
1292 -- we hit an aspect for an entity other than E, and it must be the
1293 -- type from which we were derived.
1295 if May_Inherit_Delayed_Rep_Aspects (E) then
1296 Inherit_Delayed_Rep_Aspects (ASN);
1298 end Analyze_Aspects_At_Freeze_Point;
1300 -----------------------------------
1301 -- Analyze_Aspect_Specifications --
1302 -----------------------------------
1304 procedure Analyze_Aspect_Specifications (N : Node_Id; E : Entity_Id) is
1305 procedure Decorate (Asp : Node_Id; Prag : Node_Id);
1306 -- Establish linkages between an aspect and its corresponding pragma
1308 procedure Insert_Pragma
1310 Is_Instance : Boolean := False);
1311 -- Subsidiary to the analysis of aspects
1318 -- Initial_Condition
1327 -- Insert pragma Prag such that it mimics the placement of a source
1328 -- pragma of the same kind. Flag Is_Generic should be set when the
1329 -- context denotes a generic instance.
1335 procedure Decorate (Asp : Node_Id; Prag : Node_Id) is
1337 Set_Aspect_Rep_Item (Asp, Prag);
1338 Set_Corresponding_Aspect (Prag, Asp);
1339 Set_From_Aspect_Specification (Prag);
1340 Set_Parent (Prag, Asp);
1347 procedure Insert_Pragma
1349 Is_Instance : Boolean := False)
1355 Inserted : Boolean := False;
1358 -- When the aspect appears on an entry, package, protected unit,
1359 -- subprogram, or task unit body, insert the generated pragma at the
1360 -- top of the body declarations to emulate the behavior of a source
1363 -- package body Pack with Aspect is
1365 -- package body Pack is
1368 if Nkind_In (N, N_Entry_Body,
1374 Decls := Declarations (N);
1378 Set_Declarations (N, Decls);
1381 Prepend_To (Decls, Prag);
1383 -- When the aspect is associated with a [generic] package declaration
1384 -- insert the generated pragma at the top of the visible declarations
1385 -- to emulate the behavior of a source pragma.
1387 -- package Pack with Aspect is
1392 elsif Nkind_In (N, N_Generic_Package_Declaration,
1393 N_Package_Declaration)
1395 Decls := Visible_Declarations (Specification (N));
1399 Set_Visible_Declarations (Specification (N), Decls);
1402 -- The visible declarations of a generic instance have the
1403 -- following structure:
1405 -- <renamings of generic formals>
1406 -- <renamings of internally-generated spec and body>
1407 -- <first source declaration>
1409 -- Insert the pragma before the first source declaration by
1410 -- skipping the instance "header" to ensure proper visibility of
1414 Decl := First (Decls);
1415 while Present (Decl) loop
1416 if Comes_From_Source (Decl) then
1417 Insert_Before (Decl, Prag);
1425 -- The pragma is placed after the instance "header"
1427 if not Inserted then
1428 Append_To (Decls, Prag);
1431 -- Otherwise this is not a generic instance
1434 Prepend_To (Decls, Prag);
1437 -- When the aspect is associated with a protected unit declaration,
1438 -- insert the generated pragma at the top of the visible declarations
1439 -- the emulate the behavior of a source pragma.
1441 -- protected [type] Prot with Aspect is
1443 -- protected [type] Prot is
1446 elsif Nkind (N) = N_Protected_Type_Declaration then
1447 Def := Protected_Definition (N);
1451 Make_Protected_Definition (Sloc (N),
1452 Visible_Declarations => New_List,
1453 End_Label => Empty);
1455 Set_Protected_Definition (N, Def);
1458 Decls := Visible_Declarations (Def);
1462 Set_Visible_Declarations (Def, Decls);
1465 Prepend_To (Decls, Prag);
1467 -- When the aspect is associated with a task unit declaration, insert
1468 -- insert the generated pragma at the top of the visible declarations
1469 -- the emulate the behavior of a source pragma.
1471 -- task [type] Prot with Aspect is
1473 -- task [type] Prot is
1476 elsif Nkind (N) = N_Task_Type_Declaration then
1477 Def := Task_Definition (N);
1481 Make_Task_Definition (Sloc (N),
1482 Visible_Declarations => New_List,
1483 End_Label => Empty);
1485 Set_Task_Definition (N, Def);
1488 Decls := Visible_Declarations (Def);
1492 Set_Visible_Declarations (Def, Decls);
1495 Prepend_To (Decls, Prag);
1497 -- When the context is a library unit, the pragma is added to the
1498 -- Pragmas_After list.
1500 elsif Nkind (Parent (N)) = N_Compilation_Unit then
1501 Aux := Aux_Decls_Node (Parent (N));
1503 if No (Pragmas_After (Aux)) then
1504 Set_Pragmas_After (Aux, New_List);
1507 Prepend (Prag, Pragmas_After (Aux));
1509 -- Default, the pragma is inserted after the context
1512 Insert_After (N, Prag);
1522 L : constant List_Id := Aspect_Specifications (N);
1524 Ins_Node : Node_Id := N;
1525 -- Insert pragmas/attribute definition clause after this node when no
1526 -- delayed analysis is required.
1528 -- Start of processing for Analyze_Aspect_Specifications
1531 -- The general processing involves building an attribute definition
1532 -- clause or a pragma node that corresponds to the aspect. Then in order
1533 -- to delay the evaluation of this aspect to the freeze point, we attach
1534 -- the corresponding pragma/attribute definition clause to the aspect
1535 -- specification node, which is then placed in the Rep Item chain. In
1536 -- this case we mark the entity by setting the flag Has_Delayed_Aspects
1537 -- and we evaluate the rep item at the freeze point. When the aspect
1538 -- doesn't have a corresponding pragma/attribute definition clause, then
1539 -- its analysis is simply delayed at the freeze point.
1541 -- Some special cases don't require delay analysis, thus the aspect is
1542 -- analyzed right now.
1544 -- Note that there is a special handling for Pre, Post, Test_Case,
1545 -- Contract_Cases aspects. In these cases, we do not have to worry
1546 -- about delay issues, since the pragmas themselves deal with delay
1547 -- of visibility for the expression analysis. Thus, we just insert
1548 -- the pragma after the node N.
1550 pragma Assert (Present (L));
1552 -- Loop through aspects
1554 Aspect := First (L);
1555 Aspect_Loop : while Present (Aspect) loop
1556 Analyze_One_Aspect : declare
1557 Expr : constant Node_Id := Expression (Aspect);
1558 Id : constant Node_Id := Identifier (Aspect);
1559 Loc : constant Source_Ptr := Sloc (Aspect);
1560 Nam : constant Name_Id := Chars (Id);
1561 A_Id : constant Aspect_Id := Get_Aspect_Id (Nam);
1564 Delay_Required : Boolean;
1565 -- Set False if delay is not required
1567 Eloc : Source_Ptr := No_Location;
1568 -- Source location of expression, modified when we split PPC's. It
1569 -- is set below when Expr is present.
1571 procedure Analyze_Aspect_Convention;
1572 -- Perform analysis of aspect Convention
1574 procedure Analyze_Aspect_Export_Import;
1575 -- Perform analysis of aspects Export or Import
1577 procedure Analyze_Aspect_External_Link_Name;
1578 -- Perform analysis of aspects External_Name or Link_Name
1580 procedure Analyze_Aspect_Implicit_Dereference;
1581 -- Perform analysis of the Implicit_Dereference aspects
1583 procedure Make_Aitem_Pragma
1584 (Pragma_Argument_Associations : List_Id;
1585 Pragma_Name : Name_Id);
1586 -- This is a wrapper for Make_Pragma used for converting aspects
1587 -- to pragmas. It takes care of Sloc (set from Loc) and building
1588 -- the pragma identifier from the given name. In addition the
1589 -- flags Class_Present and Split_PPC are set from the aspect
1590 -- node, as well as Is_Ignored. This routine also sets the
1591 -- From_Aspect_Specification in the resulting pragma node to
1592 -- True, and sets Corresponding_Aspect to point to the aspect.
1593 -- The resulting pragma is assigned to Aitem.
1595 -------------------------------
1596 -- Analyze_Aspect_Convention --
1597 -------------------------------
1599 procedure Analyze_Aspect_Convention is
1608 -- Obtain all interfacing aspects that apply to the related
1611 Get_Interfacing_Aspects
1612 (Iface_Asp => Aspect,
1613 Conv_Asp => Dummy_1,
1620 -- The related entity is subject to aspect Export or Import.
1621 -- Do not process Convention now because it must be analysed
1622 -- as part of Export or Import.
1624 if Present (Expo) or else Present (Imp) then
1627 -- Otherwise Convention appears by itself
1630 -- The aspect specifies a particular convention
1632 if Present (Expr) then
1633 Conv := New_Copy_Tree (Expr);
1635 -- Otherwise assume convention Ada
1638 Conv := Make_Identifier (Loc, Name_Ada);
1642 -- pragma Convention (<Conv>, <E>);
1645 (Pragma_Name => Name_Convention,
1646 Pragma_Argument_Associations => New_List (
1647 Make_Pragma_Argument_Association (Loc,
1648 Expression => Conv),
1649 Make_Pragma_Argument_Association (Loc,
1650 Expression => New_Occurrence_Of (E, Loc))));
1652 Decorate (Aspect, Aitem);
1653 Insert_Pragma (Aitem);
1655 end Analyze_Aspect_Convention;
1657 ----------------------------------
1658 -- Analyze_Aspect_Export_Import --
1659 ----------------------------------
1661 procedure Analyze_Aspect_Export_Import is
1669 -- Obtain all interfacing aspects that apply to the related
1672 Get_Interfacing_Aspects
1673 (Iface_Asp => Aspect,
1674 Conv_Asp => Dummy_1,
1681 -- The related entity cannot be subject to both aspects Export
1684 if Present (Expo) and then Present (Imp) then
1686 ("incompatible interfacing aspects given for &", E);
1687 Error_Msg_Sloc := Sloc (Expo);
1688 Error_Msg_N ("\aspect `Export` #", E);
1689 Error_Msg_Sloc := Sloc (Imp);
1690 Error_Msg_N ("\aspect `Import` #", E);
1693 -- A variable is most likely modified from the outside. Take
1694 -- Take the optimistic approach to avoid spurious errors.
1696 if Ekind (E) = E_Variable then
1697 Set_Never_Set_In_Source (E, False);
1700 -- Resolve the expression of an Import or Export here, and
1701 -- require it to be of type Boolean and static. This is not
1702 -- quite right, because in general this should be delayed,
1703 -- but that seems tricky for these, because normally Boolean
1704 -- aspects are replaced with pragmas at the freeze point in
1705 -- Make_Pragma_From_Boolean_Aspect.
1707 if not Present (Expr)
1708 or else Is_True (Static_Boolean (Expr))
1710 if A_Id = Aspect_Import then
1711 Set_Has_Completion (E);
1712 Set_Is_Imported (E);
1714 -- An imported object cannot be explicitly initialized
1716 if Nkind (N) = N_Object_Declaration
1717 and then Present (Expression (N))
1720 ("imported entities cannot be initialized "
1721 & "(RM B.1(24))", Expression (N));
1725 pragma Assert (A_Id = Aspect_Export);
1726 Set_Is_Exported (E);
1729 -- Create the proper form of pragma Export or Import taking
1730 -- into account Conversion, External_Name, and Link_Name.
1732 Aitem := Build_Export_Import_Pragma (Aspect, E);
1734 -- Otherwise the expression is either False or erroneous. There
1735 -- is no corresponding pragma.
1740 end Analyze_Aspect_Export_Import;
1742 ---------------------------------------
1743 -- Analyze_Aspect_External_Link_Name --
1744 ---------------------------------------
1746 procedure Analyze_Aspect_External_Link_Name is
1754 -- Obtain all interfacing aspects that apply to the related
1757 Get_Interfacing_Aspects
1758 (Iface_Asp => Aspect,
1759 Conv_Asp => Dummy_1,
1766 -- Ensure that aspect External_Name applies to aspect Export or
1769 if A_Id = Aspect_External_Name then
1770 if No (Expo) and then No (Imp) then
1772 ("aspect `External_Name` requires aspect `Import` or "
1773 & "`Export`", Aspect);
1776 -- Otherwise ensure that aspect Link_Name applies to aspect
1777 -- Export or Import.
1780 pragma Assert (A_Id = Aspect_Link_Name);
1781 if No (Expo) and then No (Imp) then
1783 ("aspect `Link_Name` requires aspect `Import` or "
1784 & "`Export`", Aspect);
1787 end Analyze_Aspect_External_Link_Name;
1789 -----------------------------------------
1790 -- Analyze_Aspect_Implicit_Dereference --
1791 -----------------------------------------
1793 procedure Analyze_Aspect_Implicit_Dereference is
1795 Parent_Disc : Entity_Id;
1798 if not Is_Type (E) or else not Has_Discriminants (E) then
1800 ("aspect must apply to a type with discriminants", Expr);
1802 elsif not Is_Entity_Name (Expr) then
1804 ("aspect must name a discriminant of current type", Expr);
1807 Disc := First_Discriminant (E);
1808 while Present (Disc) loop
1809 if Chars (Expr) = Chars (Disc)
1810 and then Ekind (Etype (Disc)) =
1811 E_Anonymous_Access_Type
1813 Set_Has_Implicit_Dereference (E);
1814 Set_Has_Implicit_Dereference (Disc);
1818 Next_Discriminant (Disc);
1821 -- Error if no proper access discriminant
1824 Error_Msg_NE ("not an access discriminant of&", Expr, E);
1829 -- For a type extension, check whether parent has a
1830 -- reference discriminant, to verify that use is proper.
1832 if Is_Derived_Type (E)
1833 and then Has_Discriminants (Etype (E))
1835 Parent_Disc := Get_Reference_Discriminant (Etype (E));
1837 if Present (Parent_Disc)
1838 and then Corresponding_Discriminant (Disc) /= Parent_Disc
1841 ("reference discriminant does not match discriminant "
1842 & "of parent type", Expr);
1845 end Analyze_Aspect_Implicit_Dereference;
1847 -----------------------
1848 -- Make_Aitem_Pragma --
1849 -----------------------
1851 procedure Make_Aitem_Pragma
1852 (Pragma_Argument_Associations : List_Id;
1853 Pragma_Name : Name_Id)
1855 Args : List_Id := Pragma_Argument_Associations;
1858 -- We should never get here if aspect was disabled
1860 pragma Assert (not Is_Disabled (Aspect));
1862 -- Certain aspects allow for an optional name or expression. Do
1863 -- not generate a pragma with empty argument association list.
1865 if No (Args) or else No (Expression (First (Args))) then
1873 Pragma_Argument_Associations => Args,
1874 Pragma_Identifier =>
1875 Make_Identifier (Sloc (Id), Pragma_Name),
1876 Class_Present => Class_Present (Aspect),
1877 Split_PPC => Split_PPC (Aspect));
1879 -- Set additional semantic fields
1881 if Is_Ignored (Aspect) then
1882 Set_Is_Ignored (Aitem);
1883 elsif Is_Checked (Aspect) then
1884 Set_Is_Checked (Aitem);
1887 Set_Corresponding_Aspect (Aitem, Aspect);
1888 Set_From_Aspect_Specification (Aitem);
1889 end Make_Aitem_Pragma;
1891 -- Start of processing for Analyze_Aspect_Specifications
1894 -- Skip aspect if already analyzed, to avoid looping in some cases
1896 if Analyzed (Aspect) then
1900 -- Skip looking at aspect if it is totally disabled. Just mark it
1901 -- as such for later reference in the tree. This also sets the
1902 -- Is_Ignored and Is_Checked flags appropriately.
1904 Check_Applicable_Policy (Aspect);
1906 if Is_Disabled (Aspect) then
1910 -- Set the source location of expression, used in the case of
1911 -- a failed precondition/postcondition or invariant. Note that
1912 -- the source location of the expression is not usually the best
1913 -- choice here. For example, it gets located on the last AND
1914 -- keyword in a chain of boolean expressiond AND'ed together.
1915 -- It is best to put the message on the first character of the
1916 -- assertion, which is the effect of the First_Node call here.
1918 if Present (Expr) then
1919 Eloc := Sloc (First_Node (Expr));
1922 -- Check restriction No_Implementation_Aspect_Specifications
1924 if Implementation_Defined_Aspect (A_Id) then
1926 (No_Implementation_Aspect_Specifications, Aspect);
1929 -- Check restriction No_Specification_Of_Aspect
1931 Check_Restriction_No_Specification_Of_Aspect (Aspect);
1933 -- Mark aspect analyzed (actual analysis is delayed till later)
1935 Set_Analyzed (Aspect);
1936 Set_Entity (Aspect, E);
1937 Ent := New_Occurrence_Of (E, Sloc (Id));
1939 -- Check for duplicate aspect. Note that the Comes_From_Source
1940 -- test allows duplicate Pre/Post's that we generate internally
1941 -- to escape being flagged here.
1943 if No_Duplicates_Allowed (A_Id) then
1945 while Anod /= Aspect loop
1946 if Comes_From_Source (Aspect)
1947 and then Same_Aspect (A_Id, Get_Aspect_Id (Anod))
1949 Error_Msg_Name_1 := Nam;
1950 Error_Msg_Sloc := Sloc (Anod);
1952 -- Case of same aspect specified twice
1954 if Class_Present (Anod) = Class_Present (Aspect) then
1955 if not Class_Present (Anod) then
1957 ("aspect% for & previously given#",
1961 ("aspect `%''Class` for & previously given#",
1971 -- Check some general restrictions on language defined aspects
1973 if not Implementation_Defined_Aspect (A_Id) then
1974 Error_Msg_Name_1 := Nam;
1976 -- Not allowed for renaming declarations. Examine the original
1977 -- node because a subprogram renaming may have been rewritten
1980 if Nkind (Original_Node (N)) in N_Renaming_Declaration then
1982 ("aspect % not allowed for renaming declaration",
1986 -- Not allowed for formal type declarations
1988 if Nkind (N) = N_Formal_Type_Declaration then
1990 ("aspect % not allowed for formal type declaration",
1995 -- Copy expression for later processing by the procedures
1996 -- Check_Aspect_At_[Freeze_Point | End_Of_Declarations]
1998 Set_Entity (Id, New_Copy_Tree (Expr));
2000 -- Set Delay_Required as appropriate to aspect
2002 case Aspect_Delay (A_Id) is
2003 when Always_Delay =>
2004 Delay_Required := True;
2007 Delay_Required := False;
2011 -- If expression has the form of an integer literal, then
2012 -- do not delay, since we know the value cannot change.
2013 -- This optimization catches most rep clause cases.
2015 -- For Boolean aspects, don't delay if no expression
2017 if A_Id in Boolean_Aspects and then No (Expr) then
2018 Delay_Required := False;
2020 -- For non-Boolean aspects, don't delay if integer literal
2022 elsif A_Id not in Boolean_Aspects
2023 and then Present (Expr)
2024 and then Nkind (Expr) = N_Integer_Literal
2026 Delay_Required := False;
2028 -- All other cases are delayed
2031 Delay_Required := True;
2032 Set_Has_Delayed_Rep_Aspects (E);
2036 -- Processing based on specific aspect
2039 when Aspect_Unimplemented =>
2040 null; -- ??? temp for now
2042 -- No_Aspect should be impossible
2045 raise Program_Error;
2047 -- Case 1: Aspects corresponding to attribute definition
2050 when Aspect_Address |
2053 Aspect_Component_Size |
2054 Aspect_Constant_Indexing |
2055 Aspect_Default_Iterator |
2056 Aspect_Dispatching_Domain |
2057 Aspect_External_Tag |
2060 Aspect_Iterator_Element |
2061 Aspect_Machine_Radix |
2062 Aspect_Object_Size |
2065 Aspect_Scalar_Storage_Order |
2068 Aspect_Secondary_Stack_Size |
2069 Aspect_Simple_Storage_Pool |
2070 Aspect_Storage_Pool |
2071 Aspect_Stream_Size |
2073 Aspect_Variable_Indexing |
2076 -- Indexing aspects apply only to tagged type
2078 if (A_Id = Aspect_Constant_Indexing
2080 A_Id = Aspect_Variable_Indexing)
2081 and then not (Is_Type (E)
2082 and then Is_Tagged_Type (E))
2085 ("indexing aspect can only apply to a tagged type",
2090 -- For the case of aspect Address, we don't consider that we
2091 -- know the entity is never set in the source, since it is
2092 -- is likely aliasing is occurring.
2094 -- Note: one might think that the analysis of the resulting
2095 -- attribute definition clause would take care of that, but
2096 -- that's not the case since it won't be from source.
2098 if A_Id = Aspect_Address then
2099 Set_Never_Set_In_Source (E, False);
2102 -- Correctness of the profile of a stream operation is
2103 -- verified at the freeze point, but we must detect the
2104 -- illegal specification of this aspect for a subtype now,
2105 -- to prevent malformed rep_item chains.
2107 if A_Id = Aspect_Input or else
2108 A_Id = Aspect_Output or else
2109 A_Id = Aspect_Read or else
2112 if not Is_First_Subtype (E) then
2114 ("local name must be a first subtype", Aspect);
2117 -- If stream aspect applies to the class-wide type,
2118 -- the generated attribute definition applies to the
2119 -- class-wide type as well.
2121 elsif Class_Present (Aspect) then
2123 Make_Attribute_Reference (Loc,
2125 Attribute_Name => Name_Class);
2129 -- Construct the attribute definition clause
2132 Make_Attribute_Definition_Clause (Loc,
2134 Chars => Chars (Id),
2135 Expression => Relocate_Node (Expr));
2137 -- If the address is specified, then we treat the entity as
2138 -- referenced, to avoid spurious warnings. This is analogous
2139 -- to what is done with an attribute definition clause, but
2140 -- here we don't want to generate a reference because this
2141 -- is the point of definition of the entity.
2143 if A_Id = Aspect_Address then
2147 -- Case 2: Aspects corresponding to pragmas
2149 -- Case 2a: Aspects corresponding to pragmas with two
2150 -- arguments, where the first argument is a local name
2151 -- referring to the entity, and the second argument is the
2152 -- aspect definition expression.
2154 -- Linker_Section/Suppress/Unsuppress
2156 when Aspect_Linker_Section |
2158 Aspect_Unsuppress =>
2161 (Pragma_Argument_Associations => New_List (
2162 Make_Pragma_Argument_Association (Loc,
2163 Expression => New_Occurrence_Of (E, Loc)),
2164 Make_Pragma_Argument_Association (Sloc (Expr),
2165 Expression => Relocate_Node (Expr))),
2166 Pragma_Name => Chars (Id));
2170 -- Corresponds to pragma Implemented, construct the pragma
2172 when Aspect_Synchronization =>
2174 (Pragma_Argument_Associations => New_List (
2175 Make_Pragma_Argument_Association (Loc,
2176 Expression => New_Occurrence_Of (E, Loc)),
2177 Make_Pragma_Argument_Association (Sloc (Expr),
2178 Expression => Relocate_Node (Expr))),
2179 Pragma_Name => Name_Implemented);
2183 when Aspect_Attach_Handler =>
2185 (Pragma_Argument_Associations => New_List (
2186 Make_Pragma_Argument_Association (Sloc (Ent),
2188 Make_Pragma_Argument_Association (Sloc (Expr),
2189 Expression => Relocate_Node (Expr))),
2190 Pragma_Name => Name_Attach_Handler);
2192 -- We need to insert this pragma into the tree to get proper
2193 -- processing and to look valid from a placement viewpoint.
2195 Insert_Pragma (Aitem);
2198 -- Dynamic_Predicate, Predicate, Static_Predicate
2200 when Aspect_Dynamic_Predicate |
2202 Aspect_Static_Predicate =>
2204 -- These aspects apply only to subtypes
2206 if not Is_Type (E) then
2208 ("predicate can only be specified for a subtype",
2212 elsif Is_Incomplete_Type (E) then
2214 ("predicate cannot apply to incomplete view", Aspect);
2218 -- Construct the pragma (always a pragma Predicate, with
2219 -- flags recording whether it is static/dynamic). We also
2220 -- set flags recording this in the type itself.
2223 (Pragma_Argument_Associations => New_List (
2224 Make_Pragma_Argument_Association (Sloc (Ent),
2226 Make_Pragma_Argument_Association (Sloc (Expr),
2227 Expression => Relocate_Node (Expr))),
2228 Pragma_Name => Name_Predicate);
2230 -- Mark type has predicates, and remember what kind of
2231 -- aspect lead to this predicate (we need this to access
2232 -- the right set of check policies later on).
2234 Set_Has_Predicates (E);
2236 if A_Id = Aspect_Dynamic_Predicate then
2237 Set_Has_Dynamic_Predicate_Aspect (E);
2238 elsif A_Id = Aspect_Static_Predicate then
2239 Set_Has_Static_Predicate_Aspect (E);
2242 -- If the type is private, indicate that its completion
2243 -- has a freeze node, because that is the one that will
2244 -- be visible at freeze time.
2246 if Is_Private_Type (E) and then Present (Full_View (E)) then
2247 Set_Has_Predicates (Full_View (E));
2249 if A_Id = Aspect_Dynamic_Predicate then
2250 Set_Has_Dynamic_Predicate_Aspect (Full_View (E));
2251 elsif A_Id = Aspect_Static_Predicate then
2252 Set_Has_Static_Predicate_Aspect (Full_View (E));
2255 Set_Has_Delayed_Aspects (Full_View (E));
2256 Ensure_Freeze_Node (Full_View (E));
2259 -- Predicate_Failure
2261 when Aspect_Predicate_Failure =>
2263 -- This aspect applies only to subtypes
2265 if not Is_Type (E) then
2267 ("predicate can only be specified for a subtype",
2271 elsif Is_Incomplete_Type (E) then
2273 ("predicate cannot apply to incomplete view", Aspect);
2277 -- Construct the pragma
2280 (Pragma_Argument_Associations => New_List (
2281 Make_Pragma_Argument_Association (Sloc (Ent),
2283 Make_Pragma_Argument_Association (Sloc (Expr),
2284 Expression => Relocate_Node (Expr))),
2285 Pragma_Name => Name_Predicate_Failure);
2287 Set_Has_Predicates (E);
2289 -- If the type is private, indicate that its completion
2290 -- has a freeze node, because that is the one that will
2291 -- be visible at freeze time.
2293 if Is_Private_Type (E) and then Present (Full_View (E)) then
2294 Set_Has_Predicates (Full_View (E));
2295 Set_Has_Delayed_Aspects (Full_View (E));
2296 Ensure_Freeze_Node (Full_View (E));
2299 -- Case 2b: Aspects corresponding to pragmas with two
2300 -- arguments, where the second argument is a local name
2301 -- referring to the entity, and the first argument is the
2302 -- aspect definition expression.
2306 when Aspect_Convention =>
2307 Analyze_Aspect_Convention;
2310 -- External_Name, Link_Name
2312 when Aspect_External_Name |
2314 Analyze_Aspect_External_Link_Name;
2317 -- CPU, Interrupt_Priority, Priority
2319 -- These three aspects can be specified for a subprogram spec
2320 -- or body, in which case we analyze the expression and export
2321 -- the value of the aspect.
2323 -- Previously, we generated an equivalent pragma for bodies
2324 -- (note that the specs cannot contain these pragmas). The
2325 -- pragma was inserted ahead of local declarations, rather than
2326 -- after the body. This leads to a certain duplication between
2327 -- the processing performed for the aspect and the pragma, but
2328 -- given the straightforward handling required it is simpler
2329 -- to duplicate than to translate the aspect in the spec into
2330 -- a pragma in the declarative part of the body.
2333 Aspect_Interrupt_Priority |
2336 if Nkind_In (N, N_Subprogram_Body,
2337 N_Subprogram_Declaration)
2339 -- Analyze the aspect expression
2341 Analyze_And_Resolve (Expr, Standard_Integer);
2343 -- Interrupt_Priority aspect not allowed for main
2344 -- subprograms. RM D.1 does not forbid this explicitly,
2345 -- but RM J.15.11(6/3) does not permit pragma
2346 -- Interrupt_Priority for subprograms.
2348 if A_Id = Aspect_Interrupt_Priority then
2350 ("Interrupt_Priority aspect cannot apply to "
2351 & "subprogram", Expr);
2353 -- The expression must be static
2355 elsif not Is_OK_Static_Expression (Expr) then
2356 Flag_Non_Static_Expr
2357 ("aspect requires static expression!", Expr);
2359 -- Check whether this is the main subprogram. Issue a
2360 -- warning only if it is obviously not a main program
2361 -- (when it has parameters or when the subprogram is
2362 -- within a package).
2364 elsif Present (Parameter_Specifications
2365 (Specification (N)))
2366 or else not Is_Compilation_Unit (Defining_Entity (N))
2368 -- See RM D.1(14/3) and D.16(12/3)
2371 ("aspect applied to subprogram other than the "
2372 & "main subprogram has no effect??", Expr);
2374 -- Otherwise check in range and export the value
2376 -- For the CPU aspect
2378 elsif A_Id = Aspect_CPU then
2379 if Is_In_Range (Expr, RTE (RE_CPU_Range)) then
2381 -- Value is correct so we export the value to make
2382 -- it available at execution time.
2385 (Main_Unit, UI_To_Int (Expr_Value (Expr)));
2389 ("main subprogram CPU is out of range", Expr);
2392 -- For the Priority aspect
2394 elsif A_Id = Aspect_Priority then
2395 if Is_In_Range (Expr, RTE (RE_Priority)) then
2397 -- Value is correct so we export the value to make
2398 -- it available at execution time.
2401 (Main_Unit, UI_To_Int (Expr_Value (Expr)));
2403 -- Ignore pragma if Relaxed_RM_Semantics to support
2404 -- other targets/non GNAT compilers.
2406 elsif not Relaxed_RM_Semantics then
2408 ("main subprogram priority is out of range",
2413 -- Load an arbitrary entity from System.Tasking.Stages
2414 -- or System.Tasking.Restricted.Stages (depending on
2415 -- the supported profile) to make sure that one of these
2416 -- packages is implicitly with'ed, since we need to have
2417 -- the tasking run time active for the pragma Priority to
2418 -- have any effect. Previously we with'ed the package
2419 -- System.Tasking, but this package does not trigger the
2420 -- required initialization of the run-time library.
2423 Discard : Entity_Id;
2425 if Restricted_Profile then
2426 Discard := RTE (RE_Activate_Restricted_Tasks);
2428 Discard := RTE (RE_Activate_Tasks);
2432 -- Handling for these aspects in subprograms is complete
2436 -- For tasks pass the aspect as an attribute
2440 Make_Attribute_Definition_Clause (Loc,
2442 Chars => Chars (Id),
2443 Expression => Relocate_Node (Expr));
2448 when Aspect_Warnings =>
2450 (Pragma_Argument_Associations => New_List (
2451 Make_Pragma_Argument_Association (Sloc (Expr),
2452 Expression => Relocate_Node (Expr)),
2453 Make_Pragma_Argument_Association (Loc,
2454 Expression => New_Occurrence_Of (E, Loc))),
2455 Pragma_Name => Chars (Id));
2457 Decorate (Aspect, Aitem);
2458 Insert_Pragma (Aitem);
2461 -- Case 2c: Aspects corresponding to pragmas with three
2464 -- Invariant aspects have a first argument that references the
2465 -- entity, a second argument that is the expression and a third
2466 -- argument that is an appropriate message.
2468 -- Invariant, Type_Invariant
2470 when Aspect_Invariant |
2471 Aspect_Type_Invariant =>
2473 -- Analysis of the pragma will verify placement legality:
2474 -- an invariant must apply to a private type, or appear in
2475 -- the private part of a spec and apply to a completion.
2478 (Pragma_Argument_Associations => New_List (
2479 Make_Pragma_Argument_Association (Sloc (Ent),
2481 Make_Pragma_Argument_Association (Sloc (Expr),
2482 Expression => Relocate_Node (Expr))),
2483 Pragma_Name => Name_Invariant);
2485 -- Add message unless exception messages are suppressed
2487 if not Opt.Exception_Locations_Suppressed then
2488 Append_To (Pragma_Argument_Associations (Aitem),
2489 Make_Pragma_Argument_Association (Eloc,
2490 Chars => Name_Message,
2492 Make_String_Literal (Eloc,
2493 Strval => "failed invariant from "
2494 & Build_Location_String (Eloc))));
2497 -- For Invariant case, insert immediately after the entity
2498 -- declaration. We do not have to worry about delay issues
2499 -- since the pragma processing takes care of this.
2501 Delay_Required := False;
2503 -- Case 2d : Aspects that correspond to a pragma with one
2508 -- Aspect Abstract_State introduces implicit declarations for
2509 -- all state abstraction entities it defines. To emulate this
2510 -- behavior, insert the pragma at the beginning of the visible
2511 -- declarations of the related package so that it is analyzed
2514 when Aspect_Abstract_State => Abstract_State : declare
2515 Context : Node_Id := N;
2518 -- When aspect Abstract_State appears on a generic package,
2519 -- it is propageted to the package instance. The context in
2520 -- this case is the instance spec.
2522 if Nkind (Context) = N_Package_Instantiation then
2523 Context := Instance_Spec (Context);
2526 if Nkind_In (Context, N_Generic_Package_Declaration,
2527 N_Package_Declaration)
2530 (Pragma_Argument_Associations => New_List (
2531 Make_Pragma_Argument_Association (Loc,
2532 Expression => Relocate_Node (Expr))),
2533 Pragma_Name => Name_Abstract_State);
2535 Decorate (Aspect, Aitem);
2539 Is_Generic_Instance (Defining_Entity (Context)));
2543 ("aspect & must apply to a package declaration",
2550 -- Aspect Async_Readers is never delayed because it is
2551 -- equivalent to a source pragma which appears after the
2552 -- related object declaration.
2554 when Aspect_Async_Readers =>
2556 (Pragma_Argument_Associations => New_List (
2557 Make_Pragma_Argument_Association (Loc,
2558 Expression => Relocate_Node (Expr))),
2559 Pragma_Name => Name_Async_Readers);
2561 Decorate (Aspect, Aitem);
2562 Insert_Pragma (Aitem);
2565 -- Aspect Async_Writers is never delayed because it is
2566 -- equivalent to a source pragma which appears after the
2567 -- related object declaration.
2569 when Aspect_Async_Writers =>
2571 (Pragma_Argument_Associations => New_List (
2572 Make_Pragma_Argument_Association (Loc,
2573 Expression => Relocate_Node (Expr))),
2574 Pragma_Name => Name_Async_Writers);
2576 Decorate (Aspect, Aitem);
2577 Insert_Pragma (Aitem);
2580 -- Aspect Constant_After_Elaboration is never delayed because
2581 -- it is equivalent to a source pragma which appears after the
2582 -- related object declaration.
2584 when Aspect_Constant_After_Elaboration =>
2586 (Pragma_Argument_Associations => New_List (
2587 Make_Pragma_Argument_Association (Loc,
2588 Expression => Relocate_Node (Expr))),
2590 Name_Constant_After_Elaboration);
2592 Decorate (Aspect, Aitem);
2593 Insert_Pragma (Aitem);
2596 -- Aspect Default_Internal_Condition is never delayed because
2597 -- it is equivalent to a source pragma which appears after the
2598 -- related private type. To deal with forward references, the
2599 -- generated pragma is stored in the rep chain of the related
2600 -- private type as types do not carry contracts. The pragma is
2601 -- wrapped inside of a procedure at the freeze point of the
2602 -- private type's full view.
2604 when Aspect_Default_Initial_Condition =>
2606 (Pragma_Argument_Associations => New_List (
2607 Make_Pragma_Argument_Association (Loc,
2608 Expression => Relocate_Node (Expr))),
2610 Name_Default_Initial_Condition);
2612 Decorate (Aspect, Aitem);
2613 Insert_Pragma (Aitem);
2616 -- Default_Storage_Pool
2618 when Aspect_Default_Storage_Pool =>
2620 (Pragma_Argument_Associations => New_List (
2621 Make_Pragma_Argument_Association (Loc,
2622 Expression => Relocate_Node (Expr))),
2624 Name_Default_Storage_Pool);
2626 Decorate (Aspect, Aitem);
2627 Insert_Pragma (Aitem);
2632 -- Aspect Depends is never delayed because it is equivalent to
2633 -- a source pragma which appears after the related subprogram.
2634 -- To deal with forward references, the generated pragma is
2635 -- stored in the contract of the related subprogram and later
2636 -- analyzed at the end of the declarative region. See routine
2637 -- Analyze_Depends_In_Decl_Part for details.
2639 when Aspect_Depends =>
2641 (Pragma_Argument_Associations => New_List (
2642 Make_Pragma_Argument_Association (Loc,
2643 Expression => Relocate_Node (Expr))),
2644 Pragma_Name => Name_Depends);
2646 Decorate (Aspect, Aitem);
2647 Insert_Pragma (Aitem);
2650 -- Aspect Effecitve_Reads is never delayed because it is
2651 -- equivalent to a source pragma which appears after the
2652 -- related object declaration.
2654 when Aspect_Effective_Reads =>
2656 (Pragma_Argument_Associations => New_List (
2657 Make_Pragma_Argument_Association (Loc,
2658 Expression => Relocate_Node (Expr))),
2659 Pragma_Name => Name_Effective_Reads);
2661 Decorate (Aspect, Aitem);
2662 Insert_Pragma (Aitem);
2665 -- Aspect Effective_Writes is never delayed because it is
2666 -- equivalent to a source pragma which appears after the
2667 -- related object declaration.
2669 when Aspect_Effective_Writes =>
2671 (Pragma_Argument_Associations => New_List (
2672 Make_Pragma_Argument_Association (Loc,
2673 Expression => Relocate_Node (Expr))),
2674 Pragma_Name => Name_Effective_Writes);
2676 Decorate (Aspect, Aitem);
2677 Insert_Pragma (Aitem);
2680 -- Aspect Extensions_Visible is never delayed because it is
2681 -- equivalent to a source pragma which appears after the
2682 -- related subprogram.
2684 when Aspect_Extensions_Visible =>
2686 (Pragma_Argument_Associations => New_List (
2687 Make_Pragma_Argument_Association (Loc,
2688 Expression => Relocate_Node (Expr))),
2689 Pragma_Name => Name_Extensions_Visible);
2691 Decorate (Aspect, Aitem);
2692 Insert_Pragma (Aitem);
2695 -- Aspect Ghost is never delayed because it is equivalent to a
2696 -- source pragma which appears at the top of [generic] package
2697 -- declarations or after an object, a [generic] subprogram, or
2698 -- a type declaration.
2700 when Aspect_Ghost =>
2702 (Pragma_Argument_Associations => New_List (
2703 Make_Pragma_Argument_Association (Loc,
2704 Expression => Relocate_Node (Expr))),
2705 Pragma_Name => Name_Ghost);
2707 Decorate (Aspect, Aitem);
2708 Insert_Pragma (Aitem);
2713 -- Aspect Global is never delayed because it is equivalent to
2714 -- a source pragma which appears after the related subprogram.
2715 -- To deal with forward references, the generated pragma is
2716 -- stored in the contract of the related subprogram and later
2717 -- analyzed at the end of the declarative region. See routine
2718 -- Analyze_Global_In_Decl_Part for details.
2720 when Aspect_Global =>
2722 (Pragma_Argument_Associations => New_List (
2723 Make_Pragma_Argument_Association (Loc,
2724 Expression => Relocate_Node (Expr))),
2725 Pragma_Name => Name_Global);
2727 Decorate (Aspect, Aitem);
2728 Insert_Pragma (Aitem);
2731 -- Initial_Condition
2733 -- Aspect Initial_Condition is never delayed because it is
2734 -- equivalent to a source pragma which appears after the
2735 -- related package. To deal with forward references, the
2736 -- generated pragma is stored in the contract of the related
2737 -- package and later analyzed at the end of the declarative
2738 -- region. See routine Analyze_Initial_Condition_In_Decl_Part
2741 when Aspect_Initial_Condition => Initial_Condition : declare
2742 Context : Node_Id := N;
2745 -- When aspect Initial_Condition appears on a generic
2746 -- package, it is propageted to the package instance. The
2747 -- context in this case is the instance spec.
2749 if Nkind (Context) = N_Package_Instantiation then
2750 Context := Instance_Spec (Context);
2753 if Nkind_In (Context, N_Generic_Package_Declaration,
2754 N_Package_Declaration)
2757 (Pragma_Argument_Associations => New_List (
2758 Make_Pragma_Argument_Association (Loc,
2759 Expression => Relocate_Node (Expr))),
2761 Name_Initial_Condition);
2763 Decorate (Aspect, Aitem);
2767 Is_Generic_Instance (Defining_Entity (Context)));
2769 -- Otherwise the context is illegal
2773 ("aspect & must apply to a package declaration",
2778 end Initial_Condition;
2782 -- Aspect Initializes is never delayed because it is equivalent
2783 -- to a source pragma appearing after the related package. To
2784 -- deal with forward references, the generated pragma is stored
2785 -- in the contract of the related package and later analyzed at
2786 -- the end of the declarative region. For details, see routine
2787 -- Analyze_Initializes_In_Decl_Part.
2789 when Aspect_Initializes => Initializes : declare
2790 Context : Node_Id := N;
2793 -- When aspect Initializes appears on a generic package,
2794 -- it is propageted to the package instance. The context
2795 -- in this case is the instance spec.
2797 if Nkind (Context) = N_Package_Instantiation then
2798 Context := Instance_Spec (Context);
2801 if Nkind_In (Context, N_Generic_Package_Declaration,
2802 N_Package_Declaration)
2805 (Pragma_Argument_Associations => New_List (
2806 Make_Pragma_Argument_Association (Loc,
2807 Expression => Relocate_Node (Expr))),
2808 Pragma_Name => Name_Initializes);
2810 Decorate (Aspect, Aitem);
2814 Is_Generic_Instance (Defining_Entity (Context)));
2816 -- Otherwise the context is illegal
2820 ("aspect & must apply to a package declaration",
2829 when Aspect_Max_Queue_Length =>
2831 (Pragma_Argument_Associations => New_List (
2832 Make_Pragma_Argument_Association (Loc,
2833 Expression => Relocate_Node (Expr))),
2834 Pragma_Name => Name_Max_Queue_Length);
2836 Decorate (Aspect, Aitem);
2837 Insert_Pragma (Aitem);
2842 when Aspect_Obsolescent => declare
2850 Make_Pragma_Argument_Association (Sloc (Expr),
2851 Expression => Relocate_Node (Expr)));
2855 (Pragma_Argument_Associations => Args,
2856 Pragma_Name => Chars (Id));
2861 when Aspect_Part_Of =>
2862 if Nkind_In (N, N_Object_Declaration,
2863 N_Package_Instantiation)
2864 or else Is_Single_Concurrent_Type_Declaration (N)
2867 (Pragma_Argument_Associations => New_List (
2868 Make_Pragma_Argument_Association (Loc,
2869 Expression => Relocate_Node (Expr))),
2870 Pragma_Name => Name_Part_Of);
2872 Decorate (Aspect, Aitem);
2873 Insert_Pragma (Aitem);
2877 ("aspect & must apply to package instantiation, "
2878 & "object, single protected type or single task type",
2886 when Aspect_SPARK_Mode =>
2888 (Pragma_Argument_Associations => New_List (
2889 Make_Pragma_Argument_Association (Loc,
2890 Expression => Relocate_Node (Expr))),
2891 Pragma_Name => Name_SPARK_Mode);
2893 Decorate (Aspect, Aitem);
2894 Insert_Pragma (Aitem);
2899 -- Aspect Refined_Depends is never delayed because it is
2900 -- equivalent to a source pragma which appears in the
2901 -- declarations of the related subprogram body. To deal with
2902 -- forward references, the generated pragma is stored in the
2903 -- contract of the related subprogram body and later analyzed
2904 -- at the end of the declarative region. For details, see
2905 -- routine Analyze_Refined_Depends_In_Decl_Part.
2907 when Aspect_Refined_Depends =>
2909 (Pragma_Argument_Associations => New_List (
2910 Make_Pragma_Argument_Association (Loc,
2911 Expression => Relocate_Node (Expr))),
2912 Pragma_Name => Name_Refined_Depends);
2914 Decorate (Aspect, Aitem);
2915 Insert_Pragma (Aitem);
2920 -- Aspect Refined_Global is never delayed because it is
2921 -- equivalent to a source pragma which appears in the
2922 -- declarations of the related subprogram body. To deal with
2923 -- forward references, the generated pragma is stored in the
2924 -- contract of the related subprogram body and later analyzed
2925 -- at the end of the declarative region. For details, see
2926 -- routine Analyze_Refined_Global_In_Decl_Part.
2928 when Aspect_Refined_Global =>
2930 (Pragma_Argument_Associations => New_List (
2931 Make_Pragma_Argument_Association (Loc,
2932 Expression => Relocate_Node (Expr))),
2933 Pragma_Name => Name_Refined_Global);
2935 Decorate (Aspect, Aitem);
2936 Insert_Pragma (Aitem);
2941 when Aspect_Refined_Post =>
2943 (Pragma_Argument_Associations => New_List (
2944 Make_Pragma_Argument_Association (Loc,
2945 Expression => Relocate_Node (Expr))),
2946 Pragma_Name => Name_Refined_Post);
2948 Decorate (Aspect, Aitem);
2949 Insert_Pragma (Aitem);
2954 when Aspect_Refined_State =>
2956 -- The corresponding pragma for Refined_State is inserted in
2957 -- the declarations of the related package body. This action
2958 -- synchronizes both the source and from-aspect versions of
2961 if Nkind (N) = N_Package_Body then
2963 (Pragma_Argument_Associations => New_List (
2964 Make_Pragma_Argument_Association (Loc,
2965 Expression => Relocate_Node (Expr))),
2966 Pragma_Name => Name_Refined_State);
2968 Decorate (Aspect, Aitem);
2969 Insert_Pragma (Aitem);
2971 -- Otherwise the context is illegal
2975 ("aspect & must apply to a package body", Aspect, Id);
2980 -- Relative_Deadline
2982 when Aspect_Relative_Deadline =>
2984 (Pragma_Argument_Associations => New_List (
2985 Make_Pragma_Argument_Association (Loc,
2986 Expression => Relocate_Node (Expr))),
2987 Pragma_Name => Name_Relative_Deadline);
2989 -- If the aspect applies to a task, the corresponding pragma
2990 -- must appear within its declarations, not after.
2992 if Nkind (N) = N_Task_Type_Declaration then
2998 if No (Task_Definition (N)) then
2999 Set_Task_Definition (N,
3000 Make_Task_Definition (Loc,
3001 Visible_Declarations => New_List,
3002 End_Label => Empty));
3005 Def := Task_Definition (N);
3006 V := Visible_Declarations (Def);
3007 if not Is_Empty_List (V) then
3008 Insert_Before (First (V), Aitem);
3011 Set_Visible_Declarations (Def, New_List (Aitem));
3018 -- Aspect Volatile_Function is never delayed because it is
3019 -- equivalent to a source pragma which appears after the
3020 -- related subprogram.
3022 when Aspect_Volatile_Function =>
3024 (Pragma_Argument_Associations => New_List (
3025 Make_Pragma_Argument_Association (Loc,
3026 Expression => Relocate_Node (Expr))),
3027 Pragma_Name => Name_Volatile_Function);
3029 Decorate (Aspect, Aitem);
3030 Insert_Pragma (Aitem);
3033 -- Case 2e: Annotate aspect
3035 when Aspect_Annotate =>
3042 -- The argument can be a single identifier
3044 if Nkind (Expr) = N_Identifier then
3046 -- One level of parens is allowed
3048 if Paren_Count (Expr) > 1 then
3049 Error_Msg_F ("extra parentheses ignored", Expr);
3052 Set_Paren_Count (Expr, 0);
3054 -- Add the single item to the list
3056 Args := New_List (Expr);
3058 -- Otherwise we must have an aggregate
3060 elsif Nkind (Expr) = N_Aggregate then
3062 -- Must be positional
3064 if Present (Component_Associations (Expr)) then
3066 ("purely positional aggregate required", Expr);
3070 -- Must not be parenthesized
3072 if Paren_Count (Expr) /= 0 then
3073 Error_Msg_F ("extra parentheses ignored", Expr);
3076 -- List of arguments is list of aggregate expressions
3078 Args := Expressions (Expr);
3080 -- Anything else is illegal
3083 Error_Msg_F ("wrong form for Annotate aspect", Expr);
3087 -- Prepare pragma arguments
3090 Arg := First (Args);
3091 while Present (Arg) loop
3093 Make_Pragma_Argument_Association (Sloc (Arg),
3094 Expression => Relocate_Node (Arg)));
3099 Make_Pragma_Argument_Association (Sloc (Ent),
3100 Chars => Name_Entity,
3101 Expression => Ent));
3104 (Pragma_Argument_Associations => Pargs,
3105 Pragma_Name => Name_Annotate);
3108 -- Case 3 : Aspects that don't correspond to pragma/attribute
3109 -- definition clause.
3111 -- Case 3a: The aspects listed below don't correspond to
3112 -- pragmas/attributes but do require delayed analysis.
3114 -- Default_Value can only apply to a scalar type
3116 when Aspect_Default_Value =>
3117 if not Is_Scalar_Type (E) then
3119 ("aspect Default_Value must apply to a scalar type", N);
3124 -- Default_Component_Value can only apply to an array type
3125 -- with scalar components.
3127 when Aspect_Default_Component_Value =>
3128 if not (Is_Array_Type (E)
3129 and then Is_Scalar_Type (Component_Type (E)))
3132 ("aspect Default_Component_Value can only apply to an "
3133 & "array of scalar components", N);
3138 -- Case 3b: The aspects listed below don't correspond to
3139 -- pragmas/attributes and don't need delayed analysis.
3141 -- Implicit_Dereference
3143 -- For Implicit_Dereference, External_Name and Link_Name, only
3144 -- the legality checks are done during the analysis, thus no
3145 -- delay is required.
3147 when Aspect_Implicit_Dereference =>
3148 Analyze_Aspect_Implicit_Dereference;
3153 when Aspect_Dimension =>
3154 Analyze_Aspect_Dimension (N, Id, Expr);
3159 when Aspect_Dimension_System =>
3160 Analyze_Aspect_Dimension_System (N, Id, Expr);
3163 -- Case 4: Aspects requiring special handling
3165 -- Pre/Post/Test_Case/Contract_Cases whose corresponding
3166 -- pragmas take care of the delay.
3170 -- Aspects Pre/Post generate Precondition/Postcondition pragmas
3171 -- with a first argument that is the expression, and a second
3172 -- argument that is an informative message if the test fails.
3173 -- This is inserted right after the declaration, to get the
3174 -- required pragma placement. The processing for the pragmas
3175 -- takes care of the required delay.
3177 when Pre_Post_Aspects => Pre_Post : declare
3181 if A_Id = Aspect_Pre or else A_Id = Aspect_Precondition then
3182 Pname := Name_Precondition;
3184 Pname := Name_Postcondition;
3187 -- Check that the class-wide predicate cannot be applied to
3188 -- an operation of a synchronized type that is not a tagged
3189 -- type. Other legality checks are performed when analyzing
3190 -- the contract of the operation.
3192 if Class_Present (Aspect)
3193 and then Is_Concurrent_Type (Current_Scope)
3194 and then not Is_Tagged_Type (Current_Scope)
3195 and then Ekind_In (E, E_Entry, E_Function, E_Procedure)
3197 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (Aspect);
3199 ("aspect % can only be specified for a primitive "
3200 & "operation of a tagged type", Aspect);
3205 -- If the expressions is of the form A and then B, then
3206 -- we generate separate Pre/Post aspects for the separate
3207 -- clauses. Since we allow multiple pragmas, there is no
3208 -- problem in allowing multiple Pre/Post aspects internally.
3209 -- These should be treated in reverse order (B first and
3210 -- A second) since they are later inserted just after N in
3211 -- the order they are treated. This way, the pragma for A
3212 -- ends up preceding the pragma for B, which may have an
3213 -- importance for the error raised (either constraint error
3214 -- or precondition error).
3216 -- We do not do this for Pre'Class, since we have to put
3217 -- these conditions together in a complex OR expression.
3219 -- We do not do this in ASIS mode, as ASIS relies on the
3220 -- original node representing the complete expression, when
3221 -- retrieving it through the source aspect table.
3224 and then (Pname = Name_Postcondition
3225 or else not Class_Present (Aspect))
3227 while Nkind (Expr) = N_And_Then loop
3228 Insert_After (Aspect,
3229 Make_Aspect_Specification (Sloc (Left_Opnd (Expr)),
3230 Identifier => Identifier (Aspect),
3231 Expression => Relocate_Node (Left_Opnd (Expr)),
3232 Class_Present => Class_Present (Aspect),
3233 Split_PPC => True));
3234 Rewrite (Expr, Relocate_Node (Right_Opnd (Expr)));
3235 Eloc := Sloc (Expr);
3239 -- Build the precondition/postcondition pragma
3241 -- Add note about why we do NOT need Copy_Tree here???
3244 (Pragma_Argument_Associations => New_List (
3245 Make_Pragma_Argument_Association (Eloc,
3246 Chars => Name_Check,
3247 Expression => Relocate_Node (Expr))),
3248 Pragma_Name => Pname);
3250 -- Add message unless exception messages are suppressed
3252 if not Opt.Exception_Locations_Suppressed then
3253 Append_To (Pragma_Argument_Associations (Aitem),
3254 Make_Pragma_Argument_Association (Eloc,
3255 Chars => Name_Message,
3257 Make_String_Literal (Eloc,
3259 & Get_Name_String (Pname)
3261 & Build_Location_String (Eloc))));
3264 Set_Is_Delayed_Aspect (Aspect);
3266 -- For Pre/Post cases, insert immediately after the entity
3267 -- declaration, since that is the required pragma placement.
3268 -- Note that for these aspects, we do not have to worry
3269 -- about delay issues, since the pragmas themselves deal
3270 -- with delay of visibility for the expression analysis.
3272 Insert_Pragma (Aitem);
3279 when Aspect_Test_Case => Test_Case : declare
3281 Comp_Expr : Node_Id;
3282 Comp_Assn : Node_Id;
3288 if Nkind (Parent (N)) = N_Compilation_Unit then
3289 Error_Msg_Name_1 := Nam;
3290 Error_Msg_N ("incorrect placement of aspect `%`", E);
3294 if Nkind (Expr) /= N_Aggregate then
3295 Error_Msg_Name_1 := Nam;
3297 ("wrong syntax for aspect `%` for &", Id, E);
3301 -- Make pragma expressions refer to the original aspect
3302 -- expressions through the Original_Node link. This is used
3303 -- in semantic analysis for ASIS mode, so that the original
3304 -- expression also gets analyzed.
3306 Comp_Expr := First (Expressions (Expr));
3307 while Present (Comp_Expr) loop
3308 New_Expr := Relocate_Node (Comp_Expr);
3310 Make_Pragma_Argument_Association (Sloc (Comp_Expr),
3311 Expression => New_Expr));
3315 Comp_Assn := First (Component_Associations (Expr));
3316 while Present (Comp_Assn) loop
3317 if List_Length (Choices (Comp_Assn)) /= 1
3319 Nkind (First (Choices (Comp_Assn))) /= N_Identifier
3321 Error_Msg_Name_1 := Nam;
3323 ("wrong syntax for aspect `%` for &", Id, E);
3328 Make_Pragma_Argument_Association (Sloc (Comp_Assn),
3329 Chars => Chars (First (Choices (Comp_Assn))),
3331 Relocate_Node (Expression (Comp_Assn))));
3335 -- Build the test-case pragma
3338 (Pragma_Argument_Associations => Args,
3339 Pragma_Name => Nam);
3344 when Aspect_Contract_Cases =>
3346 (Pragma_Argument_Associations => New_List (
3347 Make_Pragma_Argument_Association (Loc,
3348 Expression => Relocate_Node (Expr))),
3349 Pragma_Name => Nam);
3351 Decorate (Aspect, Aitem);
3352 Insert_Pragma (Aitem);
3355 -- Case 5: Special handling for aspects with an optional
3356 -- boolean argument.
3358 -- In the delayed case, the corresponding pragma cannot be
3359 -- generated yet because the evaluation of the boolean needs
3360 -- to be delayed till the freeze point.
3362 when Boolean_Aspects |
3363 Library_Unit_Aspects =>
3365 Set_Is_Boolean_Aspect (Aspect);
3367 -- Lock_Free aspect only apply to protected objects
3369 if A_Id = Aspect_Lock_Free then
3370 if Ekind (E) /= E_Protected_Type then
3371 Error_Msg_Name_1 := Nam;
3373 ("aspect % only applies to a protected object",
3377 -- Set the Uses_Lock_Free flag to True if there is no
3378 -- expression or if the expression is True. The
3379 -- evaluation of this aspect should be delayed to the
3380 -- freeze point (why???)
3383 or else Is_True (Static_Boolean (Expr))
3385 Set_Uses_Lock_Free (E);
3388 Record_Rep_Item (E, Aspect);
3393 elsif A_Id = Aspect_Export or else A_Id = Aspect_Import then
3394 Analyze_Aspect_Export_Import;
3396 -- Disable_Controlled
3398 elsif A_Id = Aspect_Disable_Controlled then
3399 if Ekind (E) /= E_Record_Type
3400 or else not Is_Controlled (E)
3403 ("aspect % requires controlled record type", Aspect);
3407 -- If we're in a generic template, we don't want to try
3408 -- to disable controlled types, because typical usage is
3409 -- "Disable_Controlled => not <some_check>'Enabled", and
3410 -- the value of Enabled is not known until we see a
3411 -- particular instance. In such a context, we just need
3412 -- to preanalyze the expression for legality.
3414 if Expander_Active then
3415 Analyze_And_Resolve (Expr, Standard_Boolean);
3417 if not Present (Expr)
3418 or else Is_True (Static_Boolean (Expr))
3420 Set_Disable_Controlled (E);
3423 elsif Serious_Errors_Detected = 0 then
3424 Preanalyze_And_Resolve (Expr, Standard_Boolean);
3430 -- Library unit aspects require special handling in the case
3431 -- of a package declaration, the pragma needs to be inserted
3432 -- in the list of declarations for the associated package.
3433 -- There is no issue of visibility delay for these aspects.
3435 if A_Id in Library_Unit_Aspects
3437 Nkind_In (N, N_Package_Declaration,
3438 N_Generic_Package_Declaration)
3439 and then Nkind (Parent (N)) /= N_Compilation_Unit
3441 -- Aspect is legal on a local instantiation of a library-
3442 -- level generic unit.
3444 and then not Is_Generic_Instance (Defining_Entity (N))
3447 ("incorrect context for library unit aspect&", Id);
3451 -- Cases where we do not delay, includes all cases where the
3452 -- expression is missing other than the above cases.
3454 if not Delay_Required or else No (Expr) then
3456 -- Exclude aspects Export and Import because their pragma
3457 -- syntax does not map directly to a Boolean aspect.
3459 if A_Id /= Aspect_Export
3460 and then A_Id /= Aspect_Import
3463 (Pragma_Argument_Associations => New_List (
3464 Make_Pragma_Argument_Association (Sloc (Ent),
3465 Expression => Ent)),
3466 Pragma_Name => Chars (Id));
3469 Delay_Required := False;
3471 -- In general cases, the corresponding pragma/attribute
3472 -- definition clause will be inserted later at the freezing
3473 -- point, and we do not need to build it now.
3481 -- This is special because for access types we need to generate
3482 -- an attribute definition clause. This also works for single
3483 -- task declarations, but it does not work for task type
3484 -- declarations, because we have the case where the expression
3485 -- references a discriminant of the task type. That can't use
3486 -- an attribute definition clause because we would not have
3487 -- visibility on the discriminant. For that case we must
3488 -- generate a pragma in the task definition.
3490 when Aspect_Storage_Size =>
3494 if Ekind (E) = E_Task_Type then
3496 Decl : constant Node_Id := Declaration_Node (E);
3499 pragma Assert (Nkind (Decl) = N_Task_Type_Declaration);
3501 -- If no task definition, create one
3503 if No (Task_Definition (Decl)) then
3504 Set_Task_Definition (Decl,
3505 Make_Task_Definition (Loc,
3506 Visible_Declarations => Empty_List,
3507 End_Label => Empty));
3510 -- Create a pragma and put it at the start of the task
3511 -- definition for the task type declaration.
3514 (Pragma_Argument_Associations => New_List (
3515 Make_Pragma_Argument_Association (Loc,
3516 Expression => Relocate_Node (Expr))),
3517 Pragma_Name => Name_Storage_Size);
3521 Visible_Declarations (Task_Definition (Decl)));
3525 -- All other cases, generate attribute definition
3529 Make_Attribute_Definition_Clause (Loc,
3531 Chars => Chars (Id),
3532 Expression => Relocate_Node (Expr));
3536 -- Attach the corresponding pragma/attribute definition clause to
3537 -- the aspect specification node.
3539 if Present (Aitem) then
3540 Set_From_Aspect_Specification (Aitem);
3543 -- In the context of a compilation unit, we directly put the
3544 -- pragma in the Pragmas_After list of the N_Compilation_Unit_Aux
3545 -- node (no delay is required here) except for aspects on a
3546 -- subprogram body (see below) and a generic package, for which we
3547 -- need to introduce the pragma before building the generic copy
3548 -- (see sem_ch12), and for package instantiations, where the
3549 -- library unit pragmas are better handled early.
3551 if Nkind (Parent (N)) = N_Compilation_Unit
3552 and then (Present (Aitem) or else Is_Boolean_Aspect (Aspect))
3555 Aux : constant Node_Id := Aux_Decls_Node (Parent (N));
3558 pragma Assert (Nkind (Aux) = N_Compilation_Unit_Aux);
3560 -- For a Boolean aspect, create the corresponding pragma if
3561 -- no expression or if the value is True.
3563 if Is_Boolean_Aspect (Aspect) and then No (Aitem) then
3564 if Is_True (Static_Boolean (Expr)) then
3566 (Pragma_Argument_Associations => New_List (
3567 Make_Pragma_Argument_Association (Sloc (Ent),
3568 Expression => Ent)),
3569 Pragma_Name => Chars (Id));
3571 Set_From_Aspect_Specification (Aitem, True);
3572 Set_Corresponding_Aspect (Aitem, Aspect);
3579 -- If the aspect is on a subprogram body (relevant aspect
3580 -- is Inline), add the pragma in front of the declarations.
3582 if Nkind (N) = N_Subprogram_Body then
3583 if No (Declarations (N)) then
3584 Set_Declarations (N, New_List);
3587 Prepend (Aitem, Declarations (N));
3589 elsif Nkind (N) = N_Generic_Package_Declaration then
3590 if No (Visible_Declarations (Specification (N))) then
3591 Set_Visible_Declarations (Specification (N), New_List);
3595 Visible_Declarations (Specification (N)));
3597 elsif Nkind (N) = N_Package_Instantiation then
3599 Spec : constant Node_Id :=
3600 Specification (Instance_Spec (N));
3602 if No (Visible_Declarations (Spec)) then
3603 Set_Visible_Declarations (Spec, New_List);
3606 Prepend (Aitem, Visible_Declarations (Spec));
3610 if No (Pragmas_After (Aux)) then
3611 Set_Pragmas_After (Aux, New_List);
3614 Append (Aitem, Pragmas_After (Aux));
3621 -- The evaluation of the aspect is delayed to the freezing point.
3622 -- The pragma or attribute clause if there is one is then attached
3623 -- to the aspect specification which is put in the rep item list.
3625 if Delay_Required then
3626 if Present (Aitem) then
3627 Set_Is_Delayed_Aspect (Aitem);
3628 Set_Aspect_Rep_Item (Aspect, Aitem);
3629 Set_Parent (Aitem, Aspect);
3632 Set_Is_Delayed_Aspect (Aspect);
3634 -- In the case of Default_Value, link the aspect to base type
3635 -- as well, even though it appears on a first subtype. This is
3636 -- mandated by the semantics of the aspect. Do not establish
3637 -- the link when processing the base type itself as this leads
3638 -- to a rep item circularity. Verify that we are dealing with
3639 -- a scalar type to prevent cascaded errors.
3641 if A_Id = Aspect_Default_Value
3642 and then Is_Scalar_Type (E)
3643 and then Base_Type (E) /= E
3645 Set_Has_Delayed_Aspects (Base_Type (E));
3646 Record_Rep_Item (Base_Type (E), Aspect);
3649 Set_Has_Delayed_Aspects (E);
3650 Record_Rep_Item (E, Aspect);
3652 -- When delay is not required and the context is a package or a
3653 -- subprogram body, insert the pragma in the body declarations.
3655 elsif Nkind_In (N, N_Package_Body, N_Subprogram_Body) then
3656 if No (Declarations (N)) then
3657 Set_Declarations (N, New_List);
3660 -- The pragma is added before source declarations
3662 Prepend_To (Declarations (N), Aitem);
3664 -- When delay is not required and the context is not a compilation
3665 -- unit, we simply insert the pragma/attribute definition clause
3668 elsif Present (Aitem) then
3669 Insert_After (Ins_Node, Aitem);
3672 end Analyze_One_Aspect;
3676 end loop Aspect_Loop;
3678 if Has_Delayed_Aspects (E) then
3679 Ensure_Freeze_Node (E);
3681 end Analyze_Aspect_Specifications;
3683 ---------------------------------------------------
3684 -- Analyze_Aspect_Specifications_On_Body_Or_Stub --
3685 ---------------------------------------------------
3687 procedure Analyze_Aspect_Specifications_On_Body_Or_Stub (N : Node_Id) is
3688 Body_Id : constant Entity_Id := Defining_Entity (N);
3690 procedure Diagnose_Misplaced_Aspects (Spec_Id : Entity_Id);
3691 -- Body [stub] N has aspects, but they are not properly placed. Emit an
3692 -- error message depending on the aspects involved. Spec_Id denotes the
3693 -- entity of the corresponding spec.
3695 --------------------------------
3696 -- Diagnose_Misplaced_Aspects --
3697 --------------------------------
3699 procedure Diagnose_Misplaced_Aspects (Spec_Id : Entity_Id) is
3700 procedure Misplaced_Aspect_Error
3703 -- Emit an error message concerning misplaced aspect Asp. Ref_Nam is
3704 -- the name of the refined version of the aspect.
3706 ----------------------------
3707 -- Misplaced_Aspect_Error --
3708 ----------------------------
3710 procedure Misplaced_Aspect_Error
3714 Asp_Nam : constant Name_Id := Chars (Identifier (Asp));
3715 Asp_Id : constant Aspect_Id := Get_Aspect_Id (Asp_Nam);
3718 -- The corresponding spec already contains the aspect in question
3719 -- and the one appearing on the body must be the refined form:
3721 -- procedure P with Global ...;
3722 -- procedure P with Global ... is ... end P;
3726 if Has_Aspect (Spec_Id, Asp_Id) then
3727 Error_Msg_Name_1 := Asp_Nam;
3729 -- Subunits cannot carry aspects that apply to a subprogram
3732 if Nkind (Parent (N)) = N_Subunit then
3733 Error_Msg_N ("aspect % cannot apply to a subunit", Asp);
3735 -- Otherwise suggest the refined form
3738 Error_Msg_Name_2 := Ref_Nam;
3739 Error_Msg_N ("aspect % should be %", Asp);
3742 -- Otherwise the aspect must appear on the spec, not on the body
3745 -- procedure P with Global ... is ... end P;
3749 ("aspect specification must appear on initial declaration",
3752 end Misplaced_Aspect_Error;
3759 -- Start of processing for Diagnose_Misplaced_Aspects
3762 -- Iterate over the aspect specifications and emit specific errors
3763 -- where applicable.
3765 Asp := First (Aspect_Specifications (N));
3766 while Present (Asp) loop
3767 Asp_Nam := Chars (Identifier (Asp));
3769 -- Do not emit errors on aspects that can appear on a subprogram
3770 -- body. This scenario occurs when the aspect specification list
3771 -- contains both misplaced and properly placed aspects.
3773 if Aspect_On_Body_Or_Stub_OK (Get_Aspect_Id (Asp_Nam)) then
3776 -- Special diagnostics for SPARK aspects
3778 elsif Asp_Nam = Name_Depends then
3779 Misplaced_Aspect_Error (Asp, Name_Refined_Depends);
3781 elsif Asp_Nam = Name_Global then
3782 Misplaced_Aspect_Error (Asp, Name_Refined_Global);
3784 elsif Asp_Nam = Name_Post then
3785 Misplaced_Aspect_Error (Asp, Name_Refined_Post);
3787 -- Otherwise a language-defined aspect is misplaced
3791 ("aspect specification must appear on initial declaration",
3797 end Diagnose_Misplaced_Aspects;
3801 Spec_Id : constant Entity_Id := Unique_Defining_Entity (N);
3803 -- Start of processing for Analyze_Aspects_On_Body_Or_Stub
3806 -- Language-defined aspects cannot be associated with a subprogram body
3807 -- [stub] if the subprogram has a spec. Certain implementation defined
3808 -- aspects are allowed to break this rule (for all applicable cases, see
3809 -- table Aspects.Aspect_On_Body_Or_Stub_OK).
3811 if Spec_Id /= Body_Id and then not Aspects_On_Body_Or_Stub_OK (N) then
3812 Diagnose_Misplaced_Aspects (Spec_Id);
3814 Analyze_Aspect_Specifications (N, Body_Id);
3816 end Analyze_Aspect_Specifications_On_Body_Or_Stub;
3818 -----------------------
3819 -- Analyze_At_Clause --
3820 -----------------------
3822 -- An at clause is replaced by the corresponding Address attribute
3823 -- definition clause that is the preferred approach in Ada 95.
3825 procedure Analyze_At_Clause (N : Node_Id) is
3826 CS : constant Boolean := Comes_From_Source (N);
3829 -- This is an obsolescent feature
3831 Check_Restriction (No_Obsolescent_Features, N);
3833 if Warn_On_Obsolescent_Feature then
3835 ("?j?at clause is an obsolescent feature (RM J.7(2))", N);
3837 ("\?j?use address attribute definition clause instead", N);
3840 -- Rewrite as address clause
3843 Make_Attribute_Definition_Clause (Sloc (N),
3844 Name => Identifier (N),
3845 Chars => Name_Address,
3846 Expression => Expression (N)));
3848 -- We preserve Comes_From_Source, since logically the clause still comes
3849 -- from the source program even though it is changed in form.
3851 Set_Comes_From_Source (N, CS);
3853 -- Analyze rewritten clause
3855 Analyze_Attribute_Definition_Clause (N);
3856 end Analyze_At_Clause;
3858 -----------------------------------------
3859 -- Analyze_Attribute_Definition_Clause --
3860 -----------------------------------------
3862 procedure Analyze_Attribute_Definition_Clause (N : Node_Id) is
3863 Loc : constant Source_Ptr := Sloc (N);
3864 Nam : constant Node_Id := Name (N);
3865 Attr : constant Name_Id := Chars (N);
3866 Expr : constant Node_Id := Expression (N);
3867 Id : constant Attribute_Id := Get_Attribute_Id (Attr);
3870 -- The entity of Nam after it is analyzed. In the case of an incomplete
3871 -- type, this is the underlying type.
3874 -- The underlying entity to which the attribute applies. Generally this
3875 -- is the Underlying_Type of Ent, except in the case where the clause
3876 -- applies to the full view of an incomplete or private type, in which
3877 -- case U_Ent is just a copy of Ent.
3879 FOnly : Boolean := False;
3880 -- Reset to True for subtype specific attribute (Alignment, Size)
3881 -- and for stream attributes, i.e. those cases where in the call to
3882 -- Rep_Item_Too_Late, FOnly is set True so that only the freezing rules
3883 -- are checked. Note that the case of stream attributes is not clear
3884 -- from the RM, but see AI95-00137. Also, the RM seems to disallow
3885 -- Storage_Size for derived task types, but that is also clearly
3888 procedure Analyze_Stream_TSS_Definition (TSS_Nam : TSS_Name_Type);
3889 -- Common processing for 'Read, 'Write, 'Input and 'Output attribute
3890 -- definition clauses.
3892 function Duplicate_Clause return Boolean;
3893 -- This routine checks if the aspect for U_Ent being given by attribute
3894 -- definition clause N is for an aspect that has already been specified,
3895 -- and if so gives an error message. If there is a duplicate, True is
3896 -- returned, otherwise if there is no error, False is returned.
3898 procedure Check_Indexing_Functions;
3899 -- Check that the function in Constant_Indexing or Variable_Indexing
3900 -- attribute has the proper type structure. If the name is overloaded,
3901 -- check that some interpretation is legal.
3903 procedure Check_Iterator_Functions;
3904 -- Check that there is a single function in Default_Iterator attribute
3905 -- has the proper type structure.
3907 function Check_Primitive_Function (Subp : Entity_Id) return Boolean;
3908 -- Common legality check for the previous two
3910 -----------------------------------
3911 -- Analyze_Stream_TSS_Definition --
3912 -----------------------------------
3914 procedure Analyze_Stream_TSS_Definition (TSS_Nam : TSS_Name_Type) is
3915 Subp : Entity_Id := Empty;
3920 Is_Read : constant Boolean := (TSS_Nam = TSS_Stream_Read);
3921 -- True for Read attribute, False for other attributes
3923 function Has_Good_Profile
3925 Report : Boolean := False) return Boolean;
3926 -- Return true if the entity is a subprogram with an appropriate
3927 -- profile for the attribute being defined. If result is False and
3928 -- Report is True, function emits appropriate error.
3930 ----------------------
3931 -- Has_Good_Profile --
3932 ----------------------
3934 function Has_Good_Profile
3936 Report : Boolean := False) return Boolean
3938 Expected_Ekind : constant array (Boolean) of Entity_Kind :=
3939 (False => E_Procedure, True => E_Function);
3940 Is_Function : constant Boolean := (TSS_Nam = TSS_Stream_Input);
3945 if Ekind (Subp) /= Expected_Ekind (Is_Function) then
3949 F := First_Formal (Subp);
3952 or else Ekind (Etype (F)) /= E_Anonymous_Access_Type
3953 or else Designated_Type (Etype (F)) /=
3954 Class_Wide_Type (RTE (RE_Root_Stream_Type))
3959 if not Is_Function then
3963 Expected_Mode : constant array (Boolean) of Entity_Kind :=
3964 (False => E_In_Parameter,
3965 True => E_Out_Parameter);
3967 if Parameter_Mode (F) /= Expected_Mode (Is_Read) then
3974 -- If the attribute specification comes from an aspect
3975 -- specification for a class-wide stream, the parameter must be
3976 -- a class-wide type of the entity to which the aspect applies.
3978 if From_Aspect_Specification (N)
3979 and then Class_Present (Parent (N))
3980 and then Is_Class_Wide_Type (Typ)
3986 Typ := Etype (Subp);
3989 -- Verify that the prefix of the attribute and the local name for
3990 -- the type of the formal match, or one is the class-wide of the
3991 -- other, in the case of a class-wide stream operation.
3993 if Base_Type (Typ) = Base_Type (Ent)
3994 or else (Is_Class_Wide_Type (Typ)
3995 and then Typ = Class_Wide_Type (Base_Type (Ent)))
3996 or else (Is_Class_Wide_Type (Ent)
3997 and then Ent = Class_Wide_Type (Base_Type (Typ)))
4004 if Present (Next_Formal (F)) then
4007 elsif not Is_Scalar_Type (Typ)
4008 and then not Is_First_Subtype (Typ)
4009 and then not Is_Class_Wide_Type (Typ)
4011 if Report and not Is_First_Subtype (Typ) then
4013 ("subtype of formal in stream operation must be a first "
4014 & "subtype", Parameter_Type (Parent (F)));
4022 end Has_Good_Profile;
4024 -- Start of processing for Analyze_Stream_TSS_Definition
4029 if not Is_Type (U_Ent) then
4030 Error_Msg_N ("local name must be a subtype", Nam);
4033 elsif not Is_First_Subtype (U_Ent) then
4034 Error_Msg_N ("local name must be a first subtype", Nam);
4038 Pnam := TSS (Base_Type (U_Ent), TSS_Nam);
4040 -- If Pnam is present, it can be either inherited from an ancestor
4041 -- type (in which case it is legal to redefine it for this type), or
4042 -- be a previous definition of the attribute for the same type (in
4043 -- which case it is illegal).
4045 -- In the first case, it will have been analyzed already, and we
4046 -- can check that its profile does not match the expected profile
4047 -- for a stream attribute of U_Ent. In the second case, either Pnam
4048 -- has been analyzed (and has the expected profile), or it has not
4049 -- been analyzed yet (case of a type that has not been frozen yet
4050 -- and for which the stream attribute has been set using Set_TSS).
4053 and then (No (First_Entity (Pnam)) or else Has_Good_Profile (Pnam))
4055 Error_Msg_Sloc := Sloc (Pnam);
4056 Error_Msg_Name_1 := Attr;
4057 Error_Msg_N ("% attribute already defined #", Nam);
4063 if Is_Entity_Name (Expr) then
4064 if not Is_Overloaded (Expr) then
4065 if Has_Good_Profile (Entity (Expr), Report => True) then
4066 Subp := Entity (Expr);
4070 Get_First_Interp (Expr, I, It);
4071 while Present (It.Nam) loop
4072 if Has_Good_Profile (It.Nam) then
4077 Get_Next_Interp (I, It);
4082 if Present (Subp) then
4083 if Is_Abstract_Subprogram (Subp) then
4084 Error_Msg_N ("stream subprogram must not be abstract", Expr);
4087 -- A stream subprogram for an interface type must be a null
4088 -- procedure (RM 13.13.2 (38/3)). Note that the class-wide type
4089 -- of an interface is not an interface type (3.9.4 (6.b/2)).
4091 elsif Is_Interface (U_Ent)
4092 and then not Is_Class_Wide_Type (U_Ent)
4093 and then not Inside_A_Generic
4095 (Ekind (Subp) = E_Function
4099 (Unit_Declaration_Node (Ultimate_Alias (Subp)))))
4102 ("stream subprogram for interface type must be null "
4103 & "procedure", Expr);
4106 Set_Entity (Expr, Subp);
4107 Set_Etype (Expr, Etype (Subp));
4109 New_Stream_Subprogram (N, U_Ent, Subp, TSS_Nam);
4112 Error_Msg_Name_1 := Attr;
4113 Error_Msg_N ("incorrect expression for% attribute", Expr);
4115 end Analyze_Stream_TSS_Definition;
4117 ------------------------------
4118 -- Check_Indexing_Functions --
4119 ------------------------------
4121 procedure Check_Indexing_Functions is
4122 Indexing_Found : Boolean := False;
4124 procedure Check_Inherited_Indexing;
4125 -- For a derived type, check that no indexing aspect is specified
4126 -- for the type if it is also inherited
4128 procedure Check_One_Function (Subp : Entity_Id);
4129 -- Check one possible interpretation. Sets Indexing_Found True if a
4130 -- legal indexing function is found.
4132 procedure Illegal_Indexing (Msg : String);
4133 -- Diagnose illegal indexing function if not overloaded. In the
4134 -- overloaded case indicate that no legal interpretation exists.
4136 ------------------------------
4137 -- Check_Inherited_Indexing --
4138 ------------------------------
4140 procedure Check_Inherited_Indexing is
4141 Inherited : Node_Id;
4144 if Attr = Name_Constant_Indexing then
4146 Find_Aspect (Etype (Ent), Aspect_Constant_Indexing);
4147 else pragma Assert (Attr = Name_Variable_Indexing);
4149 Find_Aspect (Etype (Ent), Aspect_Variable_Indexing);
4152 if Present (Inherited) then
4153 if Debug_Flag_Dot_XX then
4156 -- OK if current attribute_definition_clause is expansion of
4157 -- inherited aspect.
4159 elsif Aspect_Rep_Item (Inherited) = N then
4162 -- Indicate the operation that must be overridden, rather than
4163 -- redefining the indexing aspect.
4167 ("indexing function already inherited from parent type");
4169 ("!override & instead",
4170 N, Entity (Expression (Inherited)));
4173 end Check_Inherited_Indexing;
4175 ------------------------
4176 -- Check_One_Function --
4177 ------------------------
4179 procedure Check_One_Function (Subp : Entity_Id) is
4180 Default_Element : Node_Id;
4181 Ret_Type : constant Entity_Id := Etype (Subp);
4184 if not Is_Overloadable (Subp) then
4185 Illegal_Indexing ("illegal indexing function for type&");
4188 elsif Scope (Subp) /= Scope (Ent) then
4189 if Nkind (Expr) = N_Expanded_Name then
4191 -- Indexing function can't be declared elsewhere
4194 ("indexing function must be declared in scope of type&");
4199 elsif No (First_Formal (Subp)) then
4201 ("Indexing requires a function that applies to type&");
4204 elsif No (Next_Formal (First_Formal (Subp))) then
4206 ("indexing function must have at least two parameters");
4209 elsif Is_Derived_Type (Ent) then
4210 Check_Inherited_Indexing;
4213 if not Check_Primitive_Function (Subp) then
4215 ("Indexing aspect requires a function that applies to type&");
4219 -- If partial declaration exists, verify that it is not tagged.
4221 if Ekind (Current_Scope) = E_Package
4222 and then Has_Private_Declaration (Ent)
4223 and then From_Aspect_Specification (N)
4225 List_Containing (Parent (Ent)) =
4226 Private_Declarations
4227 (Specification (Unit_Declaration_Node (Current_Scope)))
4228 and then Nkind (N) = N_Attribute_Definition_Clause
4235 First (Visible_Declarations
4237 (Unit_Declaration_Node (Current_Scope))));
4239 while Present (Decl) loop
4240 if Nkind (Decl) = N_Private_Type_Declaration
4241 and then Ent = Full_View (Defining_Identifier (Decl))
4242 and then Tagged_Present (Decl)
4243 and then No (Aspect_Specifications (Decl))
4246 ("Indexing aspect cannot be specified on full view "
4247 & "if partial view is tagged");
4256 -- An indexing function must return either the default element of
4257 -- the container, or a reference type. For variable indexing it
4258 -- must be the latter.
4261 Find_Value_Of_Aspect
4262 (Etype (First_Formal (Subp)), Aspect_Iterator_Element);
4264 if Present (Default_Element) then
4265 Analyze (Default_Element);
4267 if Is_Entity_Name (Default_Element)
4268 and then not Covers (Entity (Default_Element), Ret_Type)
4272 ("wrong return type for indexing function");
4277 -- For variable_indexing the return type must be a reference type
4279 if Attr = Name_Variable_Indexing then
4280 if not Has_Implicit_Dereference (Ret_Type) then
4282 ("variable indexing must return a reference type");
4285 elsif Is_Access_Constant
4286 (Etype (First_Discriminant (Ret_Type)))
4289 ("variable indexing must return an access to variable");
4294 if Has_Implicit_Dereference (Ret_Type)
4296 Is_Access_Constant (Etype (First_Discriminant (Ret_Type)))
4299 ("constant indexing must return an access to constant");
4302 elsif Is_Access_Type (Etype (First_Formal (Subp)))
4303 and then not Is_Access_Constant (Etype (First_Formal (Subp)))
4306 ("constant indexing must apply to an access to constant");
4311 -- All checks succeeded.
4313 Indexing_Found := True;
4314 end Check_One_Function;
4316 -----------------------
4317 -- Illegal_Indexing --
4318 -----------------------
4320 procedure Illegal_Indexing (Msg : String) is
4322 Error_Msg_NE (Msg, N, Ent);
4323 end Illegal_Indexing;
4325 -- Start of processing for Check_Indexing_Functions
4329 Check_Inherited_Indexing;
4334 if not Is_Overloaded (Expr) then
4335 Check_One_Function (Entity (Expr));
4343 Indexing_Found := False;
4344 Get_First_Interp (Expr, I, It);
4345 while Present (It.Nam) loop
4347 -- Note that analysis will have added the interpretation
4348 -- that corresponds to the dereference. We only check the
4349 -- subprogram itself.
4351 if Is_Overloadable (It.Nam) then
4352 Check_One_Function (It.Nam);
4355 Get_Next_Interp (I, It);
4360 if not Indexing_Found and then not Error_Posted (N) then
4362 ("aspect Indexing requires a local function that "
4363 & "applies to type&", Expr, Ent);
4365 end Check_Indexing_Functions;
4367 ------------------------------
4368 -- Check_Iterator_Functions --
4369 ------------------------------
4371 procedure Check_Iterator_Functions is
4372 function Valid_Default_Iterator (Subp : Entity_Id) return Boolean;
4373 -- Check one possible interpretation for validity
4375 ----------------------------
4376 -- Valid_Default_Iterator --
4377 ----------------------------
4379 function Valid_Default_Iterator (Subp : Entity_Id) return Boolean is
4380 Root_T : constant Entity_Id := Root_Type (Etype (Etype (Subp)));
4384 if not Check_Primitive_Function (Subp) then
4387 -- The return type must be derived from a type in an instance
4388 -- of Iterator.Interfaces, and thus its root type must have a
4391 elsif Chars (Root_T) /= Name_Forward_Iterator
4392 and then Chars (Root_T) /= Name_Reversible_Iterator
4397 Formal := First_Formal (Subp);
4400 -- False if any subsequent formal has no default expression
4402 Formal := Next_Formal (Formal);
4403 while Present (Formal) loop
4404 if No (Expression (Parent (Formal))) then
4408 Next_Formal (Formal);
4411 -- True if all subsequent formals have default expressions
4414 end Valid_Default_Iterator;
4416 -- Start of processing for Check_Iterator_Functions
4421 if not Is_Entity_Name (Expr) then
4422 Error_Msg_N ("aspect Iterator must be a function name", Expr);
4425 if not Is_Overloaded (Expr) then
4426 if not Check_Primitive_Function (Entity (Expr)) then
4428 ("aspect Indexing requires a function that applies to type&",
4429 Entity (Expr), Ent);
4432 -- Flag the default_iterator as well as the denoted function.
4434 if not Valid_Default_Iterator (Entity (Expr)) then
4435 Error_Msg_N ("improper function for default iterator!", Expr);
4440 Default : Entity_Id := Empty;
4445 Get_First_Interp (Expr, I, It);
4446 while Present (It.Nam) loop
4447 if not Check_Primitive_Function (It.Nam)
4448 or else not Valid_Default_Iterator (It.Nam)
4452 elsif Present (Default) then
4454 -- An explicit one should override an implicit one
4456 if Comes_From_Source (Default) =
4457 Comes_From_Source (It.Nam)
4459 Error_Msg_N ("default iterator must be unique", Expr);
4460 Error_Msg_Sloc := Sloc (Default);
4461 Error_Msg_N ("\\possible interpretation#", Expr);
4462 Error_Msg_Sloc := Sloc (It.Nam);
4463 Error_Msg_N ("\\possible interpretation#", Expr);
4465 elsif Comes_From_Source (It.Nam) then
4472 Get_Next_Interp (I, It);
4475 if Present (Default) then
4476 Set_Entity (Expr, Default);
4477 Set_Is_Overloaded (Expr, False);
4480 ("no interpretation is a valid default iterator!", Expr);
4484 end Check_Iterator_Functions;
4486 -------------------------------
4487 -- Check_Primitive_Function --
4488 -------------------------------
4490 function Check_Primitive_Function (Subp : Entity_Id) return Boolean is
4494 if Ekind (Subp) /= E_Function then
4498 if No (First_Formal (Subp)) then
4501 Ctrl := Etype (First_Formal (Subp));
4504 -- To be a primitive operation subprogram has to be in same scope.
4506 if Scope (Ctrl) /= Scope (Subp) then
4510 -- Type of formal may be the class-wide type, an access to such,
4511 -- or an incomplete view.
4514 or else Ctrl = Class_Wide_Type (Ent)
4516 (Ekind (Ctrl) = E_Anonymous_Access_Type
4517 and then (Designated_Type (Ctrl) = Ent
4519 Designated_Type (Ctrl) = Class_Wide_Type (Ent)))
4521 (Ekind (Ctrl) = E_Incomplete_Type
4522 and then Full_View (Ctrl) = Ent)
4530 end Check_Primitive_Function;
4532 ----------------------
4533 -- Duplicate_Clause --
4534 ----------------------
4536 function Duplicate_Clause return Boolean is
4540 -- Nothing to do if this attribute definition clause comes from
4541 -- an aspect specification, since we could not be duplicating an
4542 -- explicit clause, and we dealt with the case of duplicated aspects
4543 -- in Analyze_Aspect_Specifications.
4545 if From_Aspect_Specification (N) then
4549 -- Otherwise current clause may duplicate previous clause, or a
4550 -- previously given pragma or aspect specification for the same
4553 A := Get_Rep_Item (U_Ent, Chars (N), Check_Parents => False);
4556 Error_Msg_Name_1 := Chars (N);
4557 Error_Msg_Sloc := Sloc (A);
4559 Error_Msg_NE ("aspect% for & previously given#", N, U_Ent);
4564 end Duplicate_Clause;
4566 -- Start of processing for Analyze_Attribute_Definition_Clause
4569 -- The following code is a defense against recursion. Not clear that
4570 -- this can happen legitimately, but perhaps some error situations can
4571 -- cause it, and we did see this recursion during testing.
4573 if Analyzed (N) then
4576 Set_Analyzed (N, True);
4579 Check_Restriction_No_Use_Of_Attribute (N);
4581 -- Ignore some selected attributes in CodePeer mode since they are not
4582 -- relevant in this context.
4584 if CodePeer_Mode then
4587 -- Ignore Component_Size in CodePeer mode, to avoid changing the
4588 -- internal representation of types by implicitly packing them.
4590 when Attribute_Component_Size =>
4591 Rewrite (N, Make_Null_Statement (Sloc (N)));
4599 -- Process Ignore_Rep_Clauses option
4601 if Ignore_Rep_Clauses then
4604 -- The following should be ignored. They do not affect legality
4605 -- and may be target dependent. The basic idea of -gnatI is to
4606 -- ignore any rep clauses that may be target dependent but do not
4607 -- affect legality (except possibly to be rejected because they
4608 -- are incompatible with the compilation target).
4610 when Attribute_Alignment |
4611 Attribute_Bit_Order |
4612 Attribute_Component_Size |
4613 Attribute_Machine_Radix |
4614 Attribute_Object_Size |
4617 Attribute_Stream_Size |
4618 Attribute_Value_Size =>
4619 Kill_Rep_Clause (N);
4622 -- The following should not be ignored, because in the first place
4623 -- they are reasonably portable, and should not cause problems
4624 -- in compiling code from another target, and also they do affect
4625 -- legality, e.g. failing to provide a stream attribute for a type
4626 -- may make a program illegal.
4628 when Attribute_External_Tag |
4632 Attribute_Simple_Storage_Pool |
4633 Attribute_Storage_Pool |
4634 Attribute_Storage_Size |
4638 -- We do not do anything here with address clauses, they will be
4639 -- removed by Freeze later on, but for now, it works better to
4640 -- keep then in the tree.
4642 when Attribute_Address =>
4645 -- Other cases are errors ("attribute& cannot be set with
4646 -- definition clause"), which will be caught below.
4654 Ent := Entity (Nam);
4656 if Rep_Item_Too_Early (Ent, N) then
4660 -- Rep clause applies to full view of incomplete type or private type if
4661 -- we have one (if not, this is a premature use of the type). However,
4662 -- certain semantic checks need to be done on the specified entity (i.e.
4663 -- the private view), so we save it in Ent.
4665 if Is_Private_Type (Ent)
4666 and then Is_Derived_Type (Ent)
4667 and then not Is_Tagged_Type (Ent)
4668 and then No (Full_View (Ent))
4670 -- If this is a private type whose completion is a derivation from
4671 -- another private type, there is no full view, and the attribute
4672 -- belongs to the type itself, not its underlying parent.
4676 elsif Ekind (Ent) = E_Incomplete_Type then
4678 -- The attribute applies to the full view, set the entity of the
4679 -- attribute definition accordingly.
4681 Ent := Underlying_Type (Ent);
4683 Set_Entity (Nam, Ent);
4686 U_Ent := Underlying_Type (Ent);
4689 -- Avoid cascaded error
4691 if Etype (Nam) = Any_Type then
4694 -- Must be declared in current scope or in case of an aspect
4695 -- specification, must be visible in current scope.
4697 elsif Scope (Ent) /= Current_Scope
4699 not (From_Aspect_Specification (N)
4700 and then Scope_Within_Or_Same (Current_Scope, Scope (Ent)))
4702 Error_Msg_N ("entity must be declared in this scope", Nam);
4705 -- Must not be a source renaming (we do have some cases where the
4706 -- expander generates a renaming, and those cases are OK, in such
4707 -- cases any attribute applies to the renamed object as well).
4709 elsif Is_Object (Ent)
4710 and then Present (Renamed_Object (Ent))
4712 -- Case of renamed object from source, this is an error
4714 if Comes_From_Source (Renamed_Object (Ent)) then
4715 Get_Name_String (Chars (N));
4716 Error_Msg_Strlen := Name_Len;
4717 Error_Msg_String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len);
4719 ("~ clause not allowed for a renaming declaration "
4720 & "(RM 13.1(6))", Nam);
4723 -- For the case of a compiler generated renaming, the attribute
4724 -- definition clause applies to the renamed object created by the
4725 -- expander. The easiest general way to handle this is to create a
4726 -- copy of the attribute definition clause for this object.
4728 elsif Is_Entity_Name (Renamed_Object (Ent)) then
4730 Make_Attribute_Definition_Clause (Loc,
4732 New_Occurrence_Of (Entity (Renamed_Object (Ent)), Loc),
4734 Expression => Duplicate_Subexpr (Expression (N))));
4736 -- If the renamed object is not an entity, it must be a dereference
4737 -- of an unconstrained function call, and we must introduce a new
4738 -- declaration to capture the expression. This is needed in the case
4739 -- of 'Alignment, where the original declaration must be rewritten.
4743 (Nkind (Renamed_Object (Ent)) = N_Explicit_Dereference);
4747 -- If no underlying entity, use entity itself, applies to some
4748 -- previously detected error cases ???
4750 elsif No (U_Ent) then
4753 -- Cannot specify for a subtype (exception Object/Value_Size)
4755 elsif Is_Type (U_Ent)
4756 and then not Is_First_Subtype (U_Ent)
4757 and then Id /= Attribute_Object_Size
4758 and then Id /= Attribute_Value_Size
4759 and then not From_At_Mod (N)
4761 Error_Msg_N ("cannot specify attribute for subtype", Nam);
4765 Set_Entity (N, U_Ent);
4767 -- Switch on particular attribute
4775 -- Address attribute definition clause
4777 when Attribute_Address => Address : begin
4779 -- A little error check, catch for X'Address use X'Address;
4781 if Nkind (Nam) = N_Identifier
4782 and then Nkind (Expr) = N_Attribute_Reference
4783 and then Attribute_Name (Expr) = Name_Address
4784 and then Nkind (Prefix (Expr)) = N_Identifier
4785 and then Chars (Nam) = Chars (Prefix (Expr))
4788 ("address for & is self-referencing", Prefix (Expr), Ent);
4792 -- Not that special case, carry on with analysis of expression
4794 Analyze_And_Resolve (Expr, RTE (RE_Address));
4796 -- Even when ignoring rep clauses we need to indicate that the
4797 -- entity has an address clause and thus it is legal to declare
4798 -- it imported. Freeze will get rid of the address clause later.
4800 if Ignore_Rep_Clauses then
4801 if Ekind_In (U_Ent, E_Variable, E_Constant) then
4802 Record_Rep_Item (U_Ent, N);
4808 if Duplicate_Clause then
4811 -- Case of address clause for subprogram
4813 elsif Is_Subprogram (U_Ent) then
4814 if Has_Homonym (U_Ent) then
4816 ("address clause cannot be given for overloaded "
4817 & "subprogram", Nam);
4821 -- For subprograms, all address clauses are permitted, and we
4822 -- mark the subprogram as having a deferred freeze so that Gigi
4823 -- will not elaborate it too soon.
4825 -- Above needs more comments, what is too soon about???
4827 Set_Has_Delayed_Freeze (U_Ent);
4829 -- Case of address clause for entry
4831 elsif Ekind (U_Ent) = E_Entry then
4832 if Nkind (Parent (N)) = N_Task_Body then
4834 ("entry address must be specified in task spec", Nam);
4838 -- For entries, we require a constant address
4840 Check_Constant_Address_Clause (Expr, U_Ent);
4842 -- Special checks for task types
4844 if Is_Task_Type (Scope (U_Ent))
4845 and then Comes_From_Source (Scope (U_Ent))
4848 ("??entry address declared for entry in task type", N);
4850 ("\??only one task can be declared of this type", N);
4853 -- Entry address clauses are obsolescent
4855 Check_Restriction (No_Obsolescent_Features, N);
4857 if Warn_On_Obsolescent_Feature then
4859 ("?j?attaching interrupt to task entry is an obsolescent "
4860 & "feature (RM J.7.1)", N);
4862 ("\?j?use interrupt procedure instead", N);
4865 -- Case of an address clause for a controlled object which we
4866 -- consider to be erroneous.
4868 elsif Is_Controlled (Etype (U_Ent))
4869 or else Has_Controlled_Component (Etype (U_Ent))
4872 ("??controlled object& must not be overlaid", Nam, U_Ent);
4874 ("\??Program_Error will be raised at run time", Nam);
4875 Insert_Action (Declaration_Node (U_Ent),
4876 Make_Raise_Program_Error (Loc,
4877 Reason => PE_Overlaid_Controlled_Object));
4880 -- Case of address clause for a (non-controlled) object
4882 elsif Ekind_In (U_Ent, E_Variable, E_Constant) then
4884 Expr : constant Node_Id := Expression (N);
4889 -- Exported variables cannot have an address clause, because
4890 -- this cancels the effect of the pragma Export.
4892 if Is_Exported (U_Ent) then
4894 ("cannot export object with address clause", Nam);
4898 Find_Overlaid_Entity (N, O_Ent, Off);
4900 if Present (O_Ent) then
4902 -- If the object overlays a constant object, mark it so
4904 if Is_Constant_Object (O_Ent) then
4905 Set_Overlays_Constant (U_Ent);
4908 -- If the address clause is of the form:
4910 -- for X'Address use Y'Address;
4914 -- C : constant Address := Y'Address;
4916 -- for X'Address use C;
4918 -- then we make an entry in the table to check the size
4919 -- and alignment of the overlaying variable. But we defer
4920 -- this check till after code generation to take full
4921 -- advantage of the annotation done by the back end.
4923 -- If the entity has a generic type, the check will be
4924 -- performed in the instance if the actual type justifies
4925 -- it, and we do not insert the clause in the table to
4926 -- prevent spurious warnings.
4928 -- Note: we used to test Comes_From_Source and only give
4929 -- this warning for source entities, but we have removed
4930 -- this test. It really seems bogus to generate overlays
4931 -- that would trigger this warning in generated code.
4932 -- Furthermore, by removing the test, we handle the
4933 -- aspect case properly.
4935 if Is_Object (O_Ent)
4936 and then not Is_Generic_Type (Etype (U_Ent))
4937 and then Address_Clause_Overlay_Warnings
4939 Address_Clause_Checks.Append
4940 ((N, U_Ent, No_Uint, O_Ent, Off));
4943 -- If this is not an overlay, mark a variable as being
4944 -- volatile to prevent unwanted optimizations. It's a
4945 -- conservative interpretation of RM 13.3(19) for the
4946 -- cases where the compiler cannot detect potential
4947 -- aliasing issues easily and it also covers the case
4948 -- of an absolute address where the volatile aspect is
4949 -- kind of implicit.
4951 if Ekind (U_Ent) = E_Variable then
4952 Set_Treat_As_Volatile (U_Ent);
4955 -- Make an entry in the table for an absolute address as
4956 -- above to check that the value is compatible with the
4957 -- alignment of the object.
4960 Addr : constant Node_Id := Address_Value (Expr);
4962 if Compile_Time_Known_Value (Addr)
4963 and then Address_Clause_Overlay_Warnings
4965 Address_Clause_Checks.Append
4966 ((N, U_Ent, Expr_Value (Addr), Empty, False));
4971 -- Overlaying controlled objects is erroneous. Emit warning
4972 -- but continue analysis because program is itself legal,
4973 -- and back end must see address clause.
4976 and then (Has_Controlled_Component (Etype (O_Ent))
4977 or else Is_Controlled (Etype (O_Ent)))
4978 and then not Inside_A_Generic
4981 ("??cannot use overlays with controlled objects", Expr);
4983 ("\??Program_Error will be raised at run time", Expr);
4984 Insert_Action (Declaration_Node (U_Ent),
4985 Make_Raise_Program_Error (Loc,
4986 Reason => PE_Overlaid_Controlled_Object));
4988 -- Issue an unconditional warning for a constant overlaying
4989 -- a variable. For the reverse case, we will issue it only
4990 -- if the variable is modified.
4992 elsif Ekind (U_Ent) = E_Constant
4993 and then Present (O_Ent)
4994 and then not Overlays_Constant (U_Ent)
4995 and then Address_Clause_Overlay_Warnings
4997 Error_Msg_N ("??constant overlays a variable", Expr);
4999 -- Imported variables can have an address clause, but then
5000 -- the import is pretty meaningless except to suppress
5001 -- initializations, so we do not need such variables to
5002 -- be statically allocated (and in fact it causes trouble
5003 -- if the address clause is a local value).
5005 elsif Is_Imported (U_Ent) then
5006 Set_Is_Statically_Allocated (U_Ent, False);
5009 -- We mark a possible modification of a variable with an
5010 -- address clause, since it is likely aliasing is occurring.
5012 Note_Possible_Modification (Nam, Sure => False);
5014 -- Legality checks on the address clause for initialized
5015 -- objects is deferred until the freeze point, because
5016 -- a subsequent pragma might indicate that the object
5017 -- is imported and thus not initialized. Also, the address
5018 -- clause might involve entities that have yet to be
5021 Set_Has_Delayed_Freeze (U_Ent);
5023 -- If an initialization call has been generated for this
5024 -- object, it needs to be deferred to after the freeze node
5025 -- we have just now added, otherwise GIGI will see a
5026 -- reference to the variable (as actual to the IP call)
5027 -- before its definition.
5030 Init_Call : constant Node_Id :=
5031 Remove_Init_Call (U_Ent, N);
5034 if Present (Init_Call) then
5035 Append_Freeze_Action (U_Ent, Init_Call);
5037 -- Reset Initialization_Statements pointer so that
5038 -- if there is a pragma Import further down, it can
5039 -- clear any default initialization.
5041 Set_Initialization_Statements (U_Ent, Init_Call);
5045 -- Entity has delayed freeze, so we will generate an
5046 -- alignment check at the freeze point unless suppressed.
5048 if not Range_Checks_Suppressed (U_Ent)
5049 and then not Alignment_Checks_Suppressed (U_Ent)
5051 Set_Check_Address_Alignment (N);
5054 -- Kill the size check code, since we are not allocating
5055 -- the variable, it is somewhere else.
5057 Kill_Size_Check_Code (U_Ent);
5060 -- Not a valid entity for an address clause
5063 Error_Msg_N ("address cannot be given for &", Nam);
5071 -- Alignment attribute definition clause
5073 when Attribute_Alignment => Alignment : declare
5074 Align : constant Uint := Get_Alignment_Value (Expr);
5075 Max_Align : constant Uint := UI_From_Int (Maximum_Alignment);
5080 if not Is_Type (U_Ent)
5081 and then Ekind (U_Ent) /= E_Variable
5082 and then Ekind (U_Ent) /= E_Constant
5084 Error_Msg_N ("alignment cannot be given for &", Nam);
5086 elsif Duplicate_Clause then
5089 elsif Align /= No_Uint then
5090 Set_Has_Alignment_Clause (U_Ent);
5092 -- Tagged type case, check for attempt to set alignment to a
5093 -- value greater than Max_Align, and reset if so. This error
5094 -- is suppressed in ASIS mode to allow for different ASIS
5095 -- back ends or ASIS-based tools to query the illegal clause.
5097 if Is_Tagged_Type (U_Ent)
5098 and then Align > Max_Align
5099 and then not ASIS_Mode
5102 ("alignment for & set to Maximum_Aligment??", Nam);
5103 Set_Alignment (U_Ent, Max_Align);
5108 Set_Alignment (U_Ent, Align);
5111 -- For an array type, U_Ent is the first subtype. In that case,
5112 -- also set the alignment of the anonymous base type so that
5113 -- other subtypes (such as the itypes for aggregates of the
5114 -- type) also receive the expected alignment.
5116 if Is_Array_Type (U_Ent) then
5117 Set_Alignment (Base_Type (U_Ent), Align);
5126 -- Bit_Order attribute definition clause
5128 when Attribute_Bit_Order => Bit_Order : declare
5130 if not Is_Record_Type (U_Ent) then
5132 ("Bit_Order can only be defined for record type", Nam);
5134 elsif Duplicate_Clause then
5138 Analyze_And_Resolve (Expr, RTE (RE_Bit_Order));
5140 if Etype (Expr) = Any_Type then
5143 elsif not Is_OK_Static_Expression (Expr) then
5144 Flag_Non_Static_Expr
5145 ("Bit_Order requires static expression!", Expr);
5148 if (Expr_Value (Expr) = 0) /= Bytes_Big_Endian then
5149 Set_Reverse_Bit_Order (Base_Type (U_Ent), True);
5155 --------------------
5156 -- Component_Size --
5157 --------------------
5159 -- Component_Size attribute definition clause
5161 when Attribute_Component_Size => Component_Size_Case : declare
5162 Csize : constant Uint := Static_Integer (Expr);
5166 New_Ctyp : Entity_Id;
5170 if not Is_Array_Type (U_Ent) then
5171 Error_Msg_N ("component size requires array type", Nam);
5175 Btype := Base_Type (U_Ent);
5176 Ctyp := Component_Type (Btype);
5178 if Duplicate_Clause then
5181 elsif Rep_Item_Too_Early (Btype, N) then
5184 elsif Csize /= No_Uint then
5185 Check_Size (Expr, Ctyp, Csize, Biased);
5187 -- For the biased case, build a declaration for a subtype that
5188 -- will be used to represent the biased subtype that reflects
5189 -- the biased representation of components. We need the subtype
5190 -- to get proper conversions on referencing elements of the
5195 Make_Defining_Identifier (Loc,
5197 New_External_Name (Chars (U_Ent), 'C', 0, 'T'));
5200 Make_Subtype_Declaration (Loc,
5201 Defining_Identifier => New_Ctyp,
5202 Subtype_Indication =>
5203 New_Occurrence_Of (Component_Type (Btype), Loc));
5205 Set_Parent (Decl, N);
5206 Analyze (Decl, Suppress => All_Checks);
5208 Set_Has_Delayed_Freeze (New_Ctyp, False);
5209 Set_Esize (New_Ctyp, Csize);
5210 Set_RM_Size (New_Ctyp, Csize);
5211 Init_Alignment (New_Ctyp);
5212 Set_Is_Itype (New_Ctyp, True);
5213 Set_Associated_Node_For_Itype (New_Ctyp, U_Ent);
5215 Set_Component_Type (Btype, New_Ctyp);
5216 Set_Biased (New_Ctyp, N, "component size clause");
5219 Set_Component_Size (Btype, Csize);
5221 -- Deal with warning on overridden size
5223 if Warn_On_Overridden_Size
5224 and then Has_Size_Clause (Ctyp)
5225 and then RM_Size (Ctyp) /= Csize
5228 ("component size overrides size clause for&?S?", N, Ctyp);
5231 Set_Has_Component_Size_Clause (Btype, True);
5232 Set_Has_Non_Standard_Rep (Btype, True);
5234 end Component_Size_Case;
5236 -----------------------
5237 -- Constant_Indexing --
5238 -----------------------
5240 when Attribute_Constant_Indexing =>
5241 Check_Indexing_Functions;
5247 when Attribute_CPU => CPU :
5249 -- CPU attribute definition clause not allowed except from aspect
5252 if From_Aspect_Specification (N) then
5253 if not Is_Task_Type (U_Ent) then
5254 Error_Msg_N ("CPU can only be defined for task", Nam);
5256 elsif Duplicate_Clause then
5260 -- The expression must be analyzed in the special manner
5261 -- described in "Handling of Default and Per-Object
5262 -- Expressions" in sem.ads.
5264 -- The visibility to the discriminants must be restored
5266 Push_Scope_And_Install_Discriminants (U_Ent);
5267 Preanalyze_Spec_Expression (Expr, RTE (RE_CPU_Range));
5268 Uninstall_Discriminants_And_Pop_Scope (U_Ent);
5270 if not Is_OK_Static_Expression (Expr) then
5271 Check_Restriction (Static_Priorities, Expr);
5277 ("attribute& cannot be set with definition clause", N);
5281 ----------------------
5282 -- Default_Iterator --
5283 ----------------------
5285 when Attribute_Default_Iterator => Default_Iterator : declare
5290 -- If target type is untagged, further checks are irrelevant
5292 if not Is_Tagged_Type (U_Ent) then
5294 ("aspect Default_Iterator applies to tagged type", Nam);
5298 Check_Iterator_Functions;
5302 if not Is_Entity_Name (Expr)
5303 or else Ekind (Entity (Expr)) /= E_Function
5305 Error_Msg_N ("aspect Iterator must be a function", Expr);
5308 Func := Entity (Expr);
5311 -- The type of the first parameter must be T, T'class, or a
5312 -- corresponding access type (5.5.1 (8/3). If function is
5313 -- parameterless label type accordingly.
5315 if No (First_Formal (Func)) then
5318 Typ := Etype (First_Formal (Func));
5322 or else Typ = Class_Wide_Type (U_Ent)
5323 or else (Is_Access_Type (Typ)
5324 and then Designated_Type (Typ) = U_Ent)
5325 or else (Is_Access_Type (Typ)
5326 and then Designated_Type (Typ) =
5327 Class_Wide_Type (U_Ent))
5333 ("Default Iterator must be a primitive of&", Func, U_Ent);
5335 end Default_Iterator;
5337 ------------------------
5338 -- Dispatching_Domain --
5339 ------------------------
5341 when Attribute_Dispatching_Domain => Dispatching_Domain :
5343 -- Dispatching_Domain attribute definition clause not allowed
5344 -- except from aspect specification.
5346 if From_Aspect_Specification (N) then
5347 if not Is_Task_Type (U_Ent) then
5349 ("Dispatching_Domain can only be defined for task", Nam);
5351 elsif Duplicate_Clause then
5355 -- The expression must be analyzed in the special manner
5356 -- described in "Handling of Default and Per-Object
5357 -- Expressions" in sem.ads.
5359 -- The visibility to the discriminants must be restored
5361 Push_Scope_And_Install_Discriminants (U_Ent);
5363 Preanalyze_Spec_Expression
5364 (Expr, RTE (RE_Dispatching_Domain));
5366 Uninstall_Discriminants_And_Pop_Scope (U_Ent);
5371 ("attribute& cannot be set with definition clause", N);
5373 end Dispatching_Domain;
5379 when Attribute_External_Tag => External_Tag :
5381 if not Is_Tagged_Type (U_Ent) then
5382 Error_Msg_N ("should be a tagged type", Nam);
5385 if Duplicate_Clause then
5389 Analyze_And_Resolve (Expr, Standard_String);
5391 if not Is_OK_Static_Expression (Expr) then
5392 Flag_Non_Static_Expr
5393 ("static string required for tag name!", Nam);
5396 if not Is_Library_Level_Entity (U_Ent) then
5398 ("??non-unique external tag supplied for &", N, U_Ent);
5400 ("\??same external tag applies to all subprogram calls",
5403 ("\??corresponding internal tag cannot be obtained", N);
5408 --------------------------
5409 -- Implicit_Dereference --
5410 --------------------------
5412 when Attribute_Implicit_Dereference =>
5414 -- Legality checks already performed at the point of the type
5415 -- declaration, aspect is not delayed.
5423 when Attribute_Input =>
5424 Analyze_Stream_TSS_Definition (TSS_Stream_Input);
5425 Set_Has_Specified_Stream_Input (Ent);
5427 ------------------------
5428 -- Interrupt_Priority --
5429 ------------------------
5431 when Attribute_Interrupt_Priority => Interrupt_Priority :
5433 -- Interrupt_Priority attribute definition clause not allowed
5434 -- except from aspect specification.
5436 if From_Aspect_Specification (N) then
5437 if not Is_Concurrent_Type (U_Ent) then
5439 ("Interrupt_Priority can only be defined for task and "
5440 & "protected object", Nam);
5442 elsif Duplicate_Clause then
5446 -- The expression must be analyzed in the special manner
5447 -- described in "Handling of Default and Per-Object
5448 -- Expressions" in sem.ads.
5450 -- The visibility to the discriminants must be restored
5452 Push_Scope_And_Install_Discriminants (U_Ent);
5454 Preanalyze_Spec_Expression
5455 (Expr, RTE (RE_Interrupt_Priority));
5457 Uninstall_Discriminants_And_Pop_Scope (U_Ent);
5459 -- Check the No_Task_At_Interrupt_Priority restriction
5461 if Is_Task_Type (U_Ent) then
5462 Check_Restriction (No_Task_At_Interrupt_Priority, N);
5468 ("attribute& cannot be set with definition clause", N);
5470 end Interrupt_Priority;
5476 when Attribute_Iterable =>
5479 if Nkind (Expr) /= N_Aggregate then
5480 Error_Msg_N ("aspect Iterable must be an aggregate", Expr);
5487 Assoc := First (Component_Associations (Expr));
5488 while Present (Assoc) loop
5489 if not Is_Entity_Name (Expression (Assoc)) then
5490 Error_Msg_N ("value must be a function", Assoc);
5497 ----------------------
5498 -- Iterator_Element --
5499 ----------------------
5501 when Attribute_Iterator_Element =>
5504 if not Is_Entity_Name (Expr)
5505 or else not Is_Type (Entity (Expr))
5507 Error_Msg_N ("aspect Iterator_Element must be a type", Expr);
5514 -- Machine radix attribute definition clause
5516 when Attribute_Machine_Radix => Machine_Radix : declare
5517 Radix : constant Uint := Static_Integer (Expr);
5520 if not Is_Decimal_Fixed_Point_Type (U_Ent) then
5521 Error_Msg_N ("decimal fixed-point type expected for &", Nam);
5523 elsif Duplicate_Clause then
5526 elsif Radix /= No_Uint then
5527 Set_Has_Machine_Radix_Clause (U_Ent);
5528 Set_Has_Non_Standard_Rep (Base_Type (U_Ent));
5533 elsif Radix = 10 then
5534 Set_Machine_Radix_10 (U_Ent);
5536 -- The following error is suppressed in ASIS mode to allow for
5537 -- different ASIS back ends or ASIS-based tools to query the
5540 elsif not ASIS_Mode then
5541 Error_Msg_N ("machine radix value must be 2 or 10", Expr);
5550 -- Object_Size attribute definition clause
5552 when Attribute_Object_Size => Object_Size : declare
5553 Size : constant Uint := Static_Integer (Expr);
5556 pragma Warnings (Off, Biased);
5559 if not Is_Type (U_Ent) then
5560 Error_Msg_N ("Object_Size cannot be given for &", Nam);
5562 elsif Duplicate_Clause then
5566 Check_Size (Expr, U_Ent, Size, Biased);
5568 -- The following errors are suppressed in ASIS mode to allow
5569 -- for different ASIS back ends or ASIS-based tools to query
5570 -- the illegal clause.
5575 elsif Is_Scalar_Type (U_Ent) then
5576 if Size /= 8 and then Size /= 16 and then Size /= 32
5577 and then UI_Mod (Size, 64) /= 0
5580 ("Object_Size must be 8, 16, 32, or multiple of 64",
5584 elsif Size mod 8 /= 0 then
5585 Error_Msg_N ("Object_Size must be a multiple of 8", Expr);
5588 Set_Esize (U_Ent, Size);
5589 Set_Has_Object_Size_Clause (U_Ent);
5590 Alignment_Check_For_Size_Change (U_Ent, Size);
5598 when Attribute_Output =>
5599 Analyze_Stream_TSS_Definition (TSS_Stream_Output);
5600 Set_Has_Specified_Stream_Output (Ent);
5606 when Attribute_Priority => Priority :
5608 -- Priority attribute definition clause not allowed except from
5609 -- aspect specification.
5611 if From_Aspect_Specification (N) then
5612 if not (Is_Concurrent_Type (U_Ent)
5613 or else Ekind (U_Ent) = E_Procedure)
5616 ("Priority can only be defined for task and protected "
5619 elsif Duplicate_Clause then
5623 -- The expression must be analyzed in the special manner
5624 -- described in "Handling of Default and Per-Object
5625 -- Expressions" in sem.ads.
5627 -- The visibility to the discriminants must be restored
5629 Push_Scope_And_Install_Discriminants (U_Ent);
5630 Preanalyze_Spec_Expression (Expr, Standard_Integer);
5631 Uninstall_Discriminants_And_Pop_Scope (U_Ent);
5633 if not Is_OK_Static_Expression (Expr) then
5634 Check_Restriction (Static_Priorities, Expr);
5640 ("attribute& cannot be set with definition clause", N);
5648 when Attribute_Read =>
5649 Analyze_Stream_TSS_Definition (TSS_Stream_Read);
5650 Set_Has_Specified_Stream_Read (Ent);
5652 --------------------------
5653 -- Scalar_Storage_Order --
5654 --------------------------
5656 -- Scalar_Storage_Order attribute definition clause
5658 when Attribute_Scalar_Storage_Order => Scalar_Storage_Order : declare
5660 if not (Is_Record_Type (U_Ent) or else Is_Array_Type (U_Ent)) then
5662 ("Scalar_Storage_Order can only be defined for record or "
5663 & "array type", Nam);
5665 elsif Duplicate_Clause then
5669 Analyze_And_Resolve (Expr, RTE (RE_Bit_Order));
5671 if Etype (Expr) = Any_Type then
5674 elsif not Is_OK_Static_Expression (Expr) then
5675 Flag_Non_Static_Expr
5676 ("Scalar_Storage_Order requires static expression!", Expr);
5678 elsif (Expr_Value (Expr) = 0) /= Bytes_Big_Endian then
5680 -- Here for the case of a non-default (i.e. non-confirming)
5681 -- Scalar_Storage_Order attribute definition.
5683 if Support_Nondefault_SSO_On_Target then
5684 Set_Reverse_Storage_Order (Base_Type (U_Ent), True);
5687 ("non-default Scalar_Storage_Order not supported on "
5692 -- Clear SSO default indications since explicit setting of the
5693 -- order overrides the defaults.
5695 Set_SSO_Set_Low_By_Default (Base_Type (U_Ent), False);
5696 Set_SSO_Set_High_By_Default (Base_Type (U_Ent), False);
5698 end Scalar_Storage_Order;
5700 --------------------------
5701 -- Secondary_Stack_Size --
5702 --------------------------
5704 when Attribute_Secondary_Stack_Size => Secondary_Stack_Size :
5706 -- Secondary_Stack_Size attribute definition clause not allowed
5707 -- except from aspect specification.
5709 if From_Aspect_Specification (N) then
5710 if not Is_Task_Type (U_Ent) then
5711 Error_Msg_N ("Secondary Stack Size can only be " &
5712 "defined for task", Nam);
5714 elsif Duplicate_Clause then
5718 Check_Restriction (No_Secondary_Stack, Expr);
5720 -- The expression must be analyzed in the special manner
5721 -- described in "Handling of Default and Per-Object
5722 -- Expressions" in sem.ads.
5724 -- The visibility to the discriminants must be restored
5726 Push_Scope_And_Install_Discriminants (U_Ent);
5727 Preanalyze_Spec_Expression (Expr, Any_Integer);
5728 Uninstall_Discriminants_And_Pop_Scope (U_Ent);
5730 if not Is_OK_Static_Expression (Expr) then
5731 Check_Restriction (Static_Storage_Size, Expr);
5737 ("attribute& cannot be set with definition clause", N);
5739 end Secondary_Stack_Size;
5745 -- Size attribute definition clause
5747 when Attribute_Size => Size : declare
5748 Size : constant Uint := Static_Integer (Expr);
5755 if Duplicate_Clause then
5758 elsif not Is_Type (U_Ent)
5759 and then Ekind (U_Ent) /= E_Variable
5760 and then Ekind (U_Ent) /= E_Constant
5762 Error_Msg_N ("size cannot be given for &", Nam);
5764 elsif Is_Array_Type (U_Ent)
5765 and then not Is_Constrained (U_Ent)
5768 ("size cannot be given for unconstrained array", Nam);
5770 elsif Size /= No_Uint then
5771 if Is_Type (U_Ent) then
5774 Etyp := Etype (U_Ent);
5777 -- Check size, note that Gigi is in charge of checking that the
5778 -- size of an array or record type is OK. Also we do not check
5779 -- the size in the ordinary fixed-point case, since it is too
5780 -- early to do so (there may be subsequent small clause that
5781 -- affects the size). We can check the size if a small clause
5782 -- has already been given.
5784 if not Is_Ordinary_Fixed_Point_Type (U_Ent)
5785 or else Has_Small_Clause (U_Ent)
5787 Check_Size (Expr, Etyp, Size, Biased);
5788 Set_Biased (U_Ent, N, "size clause", Biased);
5791 -- For types set RM_Size and Esize if possible
5793 if Is_Type (U_Ent) then
5794 Set_RM_Size (U_Ent, Size);
5796 -- For elementary types, increase Object_Size to power of 2,
5797 -- but not less than a storage unit in any case (normally
5798 -- this means it will be byte addressable).
5800 -- For all other types, nothing else to do, we leave Esize
5801 -- (object size) unset, the back end will set it from the
5802 -- size and alignment in an appropriate manner.
5804 -- In both cases, we check whether the alignment must be
5805 -- reset in the wake of the size change.
5807 if Is_Elementary_Type (U_Ent) then
5808 if Size <= System_Storage_Unit then
5809 Init_Esize (U_Ent, System_Storage_Unit);
5810 elsif Size <= 16 then
5811 Init_Esize (U_Ent, 16);
5812 elsif Size <= 32 then
5813 Init_Esize (U_Ent, 32);
5815 Set_Esize (U_Ent, (Size + 63) / 64 * 64);
5818 Alignment_Check_For_Size_Change (U_Ent, Esize (U_Ent));
5820 Alignment_Check_For_Size_Change (U_Ent, Size);
5823 -- For objects, set Esize only
5826 -- The following error is suppressed in ASIS mode to allow
5827 -- for different ASIS back ends or ASIS-based tools to query
5828 -- the illegal clause.
5830 if Is_Elementary_Type (Etyp)
5831 and then Size /= System_Storage_Unit
5832 and then Size /= System_Storage_Unit * 2
5833 and then Size /= System_Storage_Unit * 4
5834 and then Size /= System_Storage_Unit * 8
5835 and then not ASIS_Mode
5837 Error_Msg_Uint_1 := UI_From_Int (System_Storage_Unit);
5838 Error_Msg_Uint_2 := Error_Msg_Uint_1 * 8;
5840 ("size for primitive object must be a power of 2 in "
5841 & "the range ^-^", N);
5844 Set_Esize (U_Ent, Size);
5847 Set_Has_Size_Clause (U_Ent);
5855 -- Small attribute definition clause
5857 when Attribute_Small => Small : declare
5858 Implicit_Base : constant Entity_Id := Base_Type (U_Ent);
5862 Analyze_And_Resolve (Expr, Any_Real);
5864 if Etype (Expr) = Any_Type then
5867 elsif not Is_OK_Static_Expression (Expr) then
5868 Flag_Non_Static_Expr
5869 ("small requires static expression!", Expr);
5873 Small := Expr_Value_R (Expr);
5875 if Small <= Ureal_0 then
5876 Error_Msg_N ("small value must be greater than zero", Expr);
5882 if not Is_Ordinary_Fixed_Point_Type (U_Ent) then
5884 ("small requires an ordinary fixed point type", Nam);
5886 elsif Has_Small_Clause (U_Ent) then
5887 Error_Msg_N ("small already given for &", Nam);
5889 elsif Small > Delta_Value (U_Ent) then
5891 ("small value must not be greater than delta value", Nam);
5894 Set_Small_Value (U_Ent, Small);
5895 Set_Small_Value (Implicit_Base, Small);
5896 Set_Has_Small_Clause (U_Ent);
5897 Set_Has_Small_Clause (Implicit_Base);
5898 Set_Has_Non_Standard_Rep (Implicit_Base);
5906 -- Storage_Pool attribute definition clause
5908 when Attribute_Storage_Pool | Attribute_Simple_Storage_Pool => declare
5913 if Ekind (U_Ent) = E_Access_Subprogram_Type then
5915 ("storage pool cannot be given for access-to-subprogram type",
5920 Ekind_In (U_Ent, E_Access_Type, E_General_Access_Type)
5923 ("storage pool can only be given for access types", Nam);
5926 elsif Is_Derived_Type (U_Ent) then
5928 ("storage pool cannot be given for a derived access type",
5931 elsif Duplicate_Clause then
5934 elsif Present (Associated_Storage_Pool (U_Ent)) then
5935 Error_Msg_N ("storage pool already given for &", Nam);
5939 -- Check for Storage_Size previously given
5942 SS : constant Node_Id :=
5943 Get_Attribute_Definition_Clause
5944 (U_Ent, Attribute_Storage_Size);
5946 if Present (SS) then
5947 Check_Pool_Size_Clash (U_Ent, N, SS);
5951 -- Storage_Pool case
5953 if Id = Attribute_Storage_Pool then
5955 (Expr, Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
5957 -- In the Simple_Storage_Pool case, we allow a variable of any
5958 -- simple storage pool type, so we Resolve without imposing an
5962 Analyze_And_Resolve (Expr);
5964 if not Present (Get_Rep_Pragma
5965 (Etype (Expr), Name_Simple_Storage_Pool_Type))
5968 ("expression must be of a simple storage pool type", Expr);
5972 if not Denotes_Variable (Expr) then
5973 Error_Msg_N ("storage pool must be a variable", Expr);
5977 if Nkind (Expr) = N_Type_Conversion then
5978 T := Etype (Expression (Expr));
5983 -- The Stack_Bounded_Pool is used internally for implementing
5984 -- access types with a Storage_Size. Since it only work properly
5985 -- when used on one specific type, we need to check that it is not
5986 -- hijacked improperly:
5988 -- type T is access Integer;
5989 -- for T'Storage_Size use n;
5990 -- type Q is access Float;
5991 -- for Q'Storage_Size use T'Storage_Size; -- incorrect
5993 if RTE_Available (RE_Stack_Bounded_Pool)
5994 and then Base_Type (T) = RTE (RE_Stack_Bounded_Pool)
5996 Error_Msg_N ("non-shareable internal Pool", Expr);
6000 -- If the argument is a name that is not an entity name, then
6001 -- we construct a renaming operation to define an entity of
6002 -- type storage pool.
6004 if not Is_Entity_Name (Expr)
6005 and then Is_Object_Reference (Expr)
6007 Pool := Make_Temporary (Loc, 'P', Expr);
6010 Rnode : constant Node_Id :=
6011 Make_Object_Renaming_Declaration (Loc,
6012 Defining_Identifier => Pool,
6014 New_Occurrence_Of (Etype (Expr), Loc),
6018 -- If the attribute definition clause comes from an aspect
6019 -- clause, then insert the renaming before the associated
6020 -- entity's declaration, since the attribute clause has
6021 -- not yet been appended to the declaration list.
6023 if From_Aspect_Specification (N) then
6024 Insert_Before (Parent (Entity (N)), Rnode);
6026 Insert_Before (N, Rnode);
6030 Set_Associated_Storage_Pool (U_Ent, Pool);
6033 elsif Is_Entity_Name (Expr) then
6034 Pool := Entity (Expr);
6036 -- If pool is a renamed object, get original one. This can
6037 -- happen with an explicit renaming, and within instances.
6039 while Present (Renamed_Object (Pool))
6040 and then Is_Entity_Name (Renamed_Object (Pool))
6042 Pool := Entity (Renamed_Object (Pool));
6045 if Present (Renamed_Object (Pool))
6046 and then Nkind (Renamed_Object (Pool)) = N_Type_Conversion
6047 and then Is_Entity_Name (Expression (Renamed_Object (Pool)))
6049 Pool := Entity (Expression (Renamed_Object (Pool)));
6052 Set_Associated_Storage_Pool (U_Ent, Pool);
6054 elsif Nkind (Expr) = N_Type_Conversion
6055 and then Is_Entity_Name (Expression (Expr))
6056 and then Nkind (Original_Node (Expr)) = N_Attribute_Reference
6058 Pool := Entity (Expression (Expr));
6059 Set_Associated_Storage_Pool (U_Ent, Pool);
6062 Error_Msg_N ("incorrect reference to a Storage Pool", Expr);
6071 -- Storage_Size attribute definition clause
6073 when Attribute_Storage_Size => Storage_Size : declare
6074 Btype : constant Entity_Id := Base_Type (U_Ent);
6077 if Is_Task_Type (U_Ent) then
6079 -- Check obsolescent (but never obsolescent if from aspect)
6081 if not From_Aspect_Specification (N) then
6082 Check_Restriction (No_Obsolescent_Features, N);
6084 if Warn_On_Obsolescent_Feature then
6086 ("?j?storage size clause for task is an obsolescent "
6087 & "feature (RM J.9)", N);
6088 Error_Msg_N ("\?j?use Storage_Size pragma instead", N);
6095 if not Is_Access_Type (U_Ent)
6096 and then Ekind (U_Ent) /= E_Task_Type
6098 Error_Msg_N ("storage size cannot be given for &", Nam);
6100 elsif Is_Access_Type (U_Ent) and Is_Derived_Type (U_Ent) then
6102 ("storage size cannot be given for a derived access type",
6105 elsif Duplicate_Clause then
6109 Analyze_And_Resolve (Expr, Any_Integer);
6111 if Is_Access_Type (U_Ent) then
6113 -- Check for Storage_Pool previously given
6116 SP : constant Node_Id :=
6117 Get_Attribute_Definition_Clause
6118 (U_Ent, Attribute_Storage_Pool);
6121 if Present (SP) then
6122 Check_Pool_Size_Clash (U_Ent, SP, N);
6126 -- Special case of for x'Storage_Size use 0
6128 if Is_OK_Static_Expression (Expr)
6129 and then Expr_Value (Expr) = 0
6131 Set_No_Pool_Assigned (Btype);
6135 Set_Has_Storage_Size_Clause (Btype);
6143 when Attribute_Stream_Size => Stream_Size : declare
6144 Size : constant Uint := Static_Integer (Expr);
6147 if Ada_Version <= Ada_95 then
6148 Check_Restriction (No_Implementation_Attributes, N);
6151 if Duplicate_Clause then
6154 elsif Is_Elementary_Type (U_Ent) then
6156 -- The following errors are suppressed in ASIS mode to allow
6157 -- for different ASIS back ends or ASIS-based tools to query
6158 -- the illegal clause.
6163 elsif Size /= System_Storage_Unit
6164 and then Size /= System_Storage_Unit * 2
6165 and then Size /= System_Storage_Unit * 4
6166 and then Size /= System_Storage_Unit * 8
6168 Error_Msg_Uint_1 := UI_From_Int (System_Storage_Unit);
6170 ("stream size for elementary type must be a power of 2 "
6171 & "and at least ^", N);
6173 elsif RM_Size (U_Ent) > Size then
6174 Error_Msg_Uint_1 := RM_Size (U_Ent);
6176 ("stream size for elementary type must be a power of 2 "
6177 & "and at least ^", N);
6180 Set_Has_Stream_Size_Clause (U_Ent);
6183 Error_Msg_N ("Stream_Size cannot be given for &", Nam);
6191 -- Value_Size attribute definition clause
6193 when Attribute_Value_Size => Value_Size : declare
6194 Size : constant Uint := Static_Integer (Expr);
6198 if not Is_Type (U_Ent) then
6199 Error_Msg_N ("Value_Size cannot be given for &", Nam);
6201 elsif Duplicate_Clause then
6204 elsif Is_Array_Type (U_Ent)
6205 and then not Is_Constrained (U_Ent)
6208 ("Value_Size cannot be given for unconstrained array", Nam);
6211 if Is_Elementary_Type (U_Ent) then
6212 Check_Size (Expr, U_Ent, Size, Biased);
6213 Set_Biased (U_Ent, N, "value size clause", Biased);
6216 Set_RM_Size (U_Ent, Size);
6220 -----------------------
6221 -- Variable_Indexing --
6222 -----------------------
6224 when Attribute_Variable_Indexing =>
6225 Check_Indexing_Functions;
6231 when Attribute_Write =>
6232 Analyze_Stream_TSS_Definition (TSS_Stream_Write);
6233 Set_Has_Specified_Stream_Write (Ent);
6235 -- All other attributes cannot be set
6239 ("attribute& cannot be set with definition clause", N);
6242 -- The test for the type being frozen must be performed after any
6243 -- expression the clause has been analyzed since the expression itself
6244 -- might cause freezing that makes the clause illegal.
6246 if Rep_Item_Too_Late (U_Ent, N, FOnly) then
6249 end Analyze_Attribute_Definition_Clause;
6251 ----------------------------
6252 -- Analyze_Code_Statement --
6253 ----------------------------
6255 procedure Analyze_Code_Statement (N : Node_Id) is
6256 HSS : constant Node_Id := Parent (N);
6257 SBody : constant Node_Id := Parent (HSS);
6258 Subp : constant Entity_Id := Current_Scope;
6265 -- Accept foreign code statements for CodePeer. The analysis is skipped
6266 -- to avoid rejecting unrecognized constructs.
6268 if CodePeer_Mode then
6273 -- Analyze and check we get right type, note that this implements the
6274 -- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that is
6275 -- the only way that Asm_Insn could possibly be visible.
6277 Analyze_And_Resolve (Expression (N));
6279 if Etype (Expression (N)) = Any_Type then
6281 elsif Etype (Expression (N)) /= RTE (RE_Asm_Insn) then
6282 Error_Msg_N ("incorrect type for code statement", N);
6286 Check_Code_Statement (N);
6288 -- Make sure we appear in the handled statement sequence of a subprogram
6291 if Nkind (HSS) /= N_Handled_Sequence_Of_Statements
6292 or else Nkind (SBody) /= N_Subprogram_Body
6295 ("code statement can only appear in body of subprogram", N);
6299 -- Do remaining checks (RM 13.8(3)) if not already done
6301 if not Is_Machine_Code_Subprogram (Subp) then
6302 Set_Is_Machine_Code_Subprogram (Subp);
6304 -- No exception handlers allowed
6306 if Present (Exception_Handlers (HSS)) then
6308 ("exception handlers not permitted in machine code subprogram",
6309 First (Exception_Handlers (HSS)));
6312 -- No declarations other than use clauses and pragmas (we allow
6313 -- certain internally generated declarations as well).
6315 Decl := First (Declarations (SBody));
6316 while Present (Decl) loop
6317 DeclO := Original_Node (Decl);
6318 if Comes_From_Source (DeclO)
6319 and not Nkind_In (DeclO, N_Pragma,
6320 N_Use_Package_Clause,
6322 N_Implicit_Label_Declaration)
6325 ("this declaration not allowed in machine code subprogram",
6332 -- No statements other than code statements, pragmas, and labels.
6333 -- Again we allow certain internally generated statements.
6335 -- In Ada 2012, qualified expressions are names, and the code
6336 -- statement is initially parsed as a procedure call.
6338 Stmt := First (Statements (HSS));
6339 while Present (Stmt) loop
6340 StmtO := Original_Node (Stmt);
6342 -- A procedure call transformed into a code statement is OK
6344 if Ada_Version >= Ada_2012
6345 and then Nkind (StmtO) = N_Procedure_Call_Statement
6346 and then Nkind (Name (StmtO)) = N_Qualified_Expression
6350 elsif Comes_From_Source (StmtO)
6351 and then not Nkind_In (StmtO, N_Pragma,
6356 ("this statement is not allowed in machine code subprogram",
6363 end Analyze_Code_Statement;
6365 -----------------------------------------------
6366 -- Analyze_Enumeration_Representation_Clause --
6367 -----------------------------------------------
6369 procedure Analyze_Enumeration_Representation_Clause (N : Node_Id) is
6370 Ident : constant Node_Id := Identifier (N);
6371 Aggr : constant Node_Id := Array_Aggregate (N);
6372 Enumtype : Entity_Id;
6379 Err : Boolean := False;
6380 -- Set True to avoid cascade errors and crashes on incorrect source code
6382 Lo : constant Uint := Expr_Value (Type_Low_Bound (Universal_Integer));
6383 Hi : constant Uint := Expr_Value (Type_High_Bound (Universal_Integer));
6384 -- Allowed range of universal integer (= allowed range of enum lit vals)
6388 -- Minimum and maximum values of entries
6391 -- Pointer to node for literal providing max value
6394 if Ignore_Rep_Clauses then
6395 Kill_Rep_Clause (N);
6399 -- Ignore enumeration rep clauses by default in CodePeer mode,
6400 -- unless -gnatd.I is specified, as a work around for potential false
6401 -- positive messages.
6403 if CodePeer_Mode and not Debug_Flag_Dot_II then
6407 -- First some basic error checks
6410 Enumtype := Entity (Ident);
6412 if Enumtype = Any_Type
6413 or else Rep_Item_Too_Early (Enumtype, N)
6417 Enumtype := Underlying_Type (Enumtype);
6420 if not Is_Enumeration_Type (Enumtype) then
6422 ("enumeration type required, found}",
6423 Ident, First_Subtype (Enumtype));
6427 -- Ignore rep clause on generic actual type. This will already have
6428 -- been flagged on the template as an error, and this is the safest
6429 -- way to ensure we don't get a junk cascaded message in the instance.
6431 if Is_Generic_Actual_Type (Enumtype) then
6434 -- Type must be in current scope
6436 elsif Scope (Enumtype) /= Current_Scope then
6437 Error_Msg_N ("type must be declared in this scope", Ident);
6440 -- Type must be a first subtype
6442 elsif not Is_First_Subtype (Enumtype) then
6443 Error_Msg_N ("cannot give enumeration rep clause for subtype", N);
6446 -- Ignore duplicate rep clause
6448 elsif Has_Enumeration_Rep_Clause (Enumtype) then
6449 Error_Msg_N ("duplicate enumeration rep clause ignored", N);
6452 -- Don't allow rep clause for standard [wide_[wide_]]character
6454 elsif Is_Standard_Character_Type (Enumtype) then
6455 Error_Msg_N ("enumeration rep clause not allowed for this type", N);
6458 -- Check that the expression is a proper aggregate (no parentheses)
6460 elsif Paren_Count (Aggr) /= 0 then
6462 ("extra parentheses surrounding aggregate not allowed",
6466 -- All tests passed, so set rep clause in place
6469 Set_Has_Enumeration_Rep_Clause (Enumtype);
6470 Set_Has_Enumeration_Rep_Clause (Base_Type (Enumtype));
6473 -- Now we process the aggregate. Note that we don't use the normal
6474 -- aggregate code for this purpose, because we don't want any of the
6475 -- normal expansion activities, and a number of special semantic
6476 -- rules apply (including the component type being any integer type)
6478 Elit := First_Literal (Enumtype);
6480 -- First the positional entries if any
6482 if Present (Expressions (Aggr)) then
6483 Expr := First (Expressions (Aggr));
6484 while Present (Expr) loop
6486 Error_Msg_N ("too many entries in aggregate", Expr);
6490 Val := Static_Integer (Expr);
6492 -- Err signals that we found some incorrect entries processing
6493 -- the list. The final checks for completeness and ordering are
6494 -- skipped in this case.
6496 if Val = No_Uint then
6499 elsif Val < Lo or else Hi < Val then
6500 Error_Msg_N ("value outside permitted range", Expr);
6504 Set_Enumeration_Rep (Elit, Val);
6505 Set_Enumeration_Rep_Expr (Elit, Expr);
6511 -- Now process the named entries if present
6513 if Present (Component_Associations (Aggr)) then
6514 Assoc := First (Component_Associations (Aggr));
6515 while Present (Assoc) loop
6516 Choice := First (Choices (Assoc));
6518 if Present (Next (Choice)) then
6520 ("multiple choice not allowed here", Next (Choice));
6524 if Nkind (Choice) = N_Others_Choice then
6525 Error_Msg_N ("others choice not allowed here", Choice);
6528 elsif Nkind (Choice) = N_Range then
6530 -- ??? should allow zero/one element range here
6532 Error_Msg_N ("range not allowed here", Choice);
6536 Analyze_And_Resolve (Choice, Enumtype);
6538 if Error_Posted (Choice) then
6543 if Is_Entity_Name (Choice)
6544 and then Is_Type (Entity (Choice))
6546 Error_Msg_N ("subtype name not allowed here", Choice);
6549 -- ??? should allow static subtype with zero/one entry
6551 elsif Etype (Choice) = Base_Type (Enumtype) then
6552 if not Is_OK_Static_Expression (Choice) then
6553 Flag_Non_Static_Expr
6554 ("non-static expression used for choice!", Choice);
6558 Elit := Expr_Value_E (Choice);
6560 if Present (Enumeration_Rep_Expr (Elit)) then
6562 Sloc (Enumeration_Rep_Expr (Elit));
6564 ("representation for& previously given#",
6569 Set_Enumeration_Rep_Expr (Elit, Expression (Assoc));
6571 Expr := Expression (Assoc);
6572 Val := Static_Integer (Expr);
6574 if Val = No_Uint then
6577 elsif Val < Lo or else Hi < Val then
6578 Error_Msg_N ("value outside permitted range", Expr);
6582 Set_Enumeration_Rep (Elit, Val);
6592 -- Aggregate is fully processed. Now we check that a full set of
6593 -- representations was given, and that they are in range and in order.
6594 -- These checks are only done if no other errors occurred.
6600 Elit := First_Literal (Enumtype);
6601 while Present (Elit) loop
6602 if No (Enumeration_Rep_Expr (Elit)) then
6603 Error_Msg_NE ("missing representation for&!", N, Elit);
6606 Val := Enumeration_Rep (Elit);
6608 if Min = No_Uint then
6612 if Val /= No_Uint then
6613 if Max /= No_Uint and then Val <= Max then
6615 ("enumeration value for& not ordered!",
6616 Enumeration_Rep_Expr (Elit), Elit);
6619 Max_Node := Enumeration_Rep_Expr (Elit);
6623 -- If there is at least one literal whose representation is not
6624 -- equal to the Pos value, then note that this enumeration type
6625 -- has a non-standard representation.
6627 if Val /= Enumeration_Pos (Elit) then
6628 Set_Has_Non_Standard_Rep (Base_Type (Enumtype));
6635 -- Now set proper size information
6638 Minsize : Uint := UI_From_Int (Minimum_Size (Enumtype));
6641 if Has_Size_Clause (Enumtype) then
6643 -- All OK, if size is OK now
6645 if RM_Size (Enumtype) >= Minsize then
6649 -- Try if we can get by with biasing
6652 UI_From_Int (Minimum_Size (Enumtype, Biased => True));
6654 -- Error message if even biasing does not work
6656 if RM_Size (Enumtype) < Minsize then
6657 Error_Msg_Uint_1 := RM_Size (Enumtype);
6658 Error_Msg_Uint_2 := Max;
6660 ("previously given size (^) is too small "
6661 & "for this value (^)", Max_Node);
6663 -- If biasing worked, indicate that we now have biased rep
6667 (Enumtype, Size_Clause (Enumtype), "size clause");
6672 Set_RM_Size (Enumtype, Minsize);
6673 Set_Enum_Esize (Enumtype);
6676 Set_RM_Size (Base_Type (Enumtype), RM_Size (Enumtype));
6677 Set_Esize (Base_Type (Enumtype), Esize (Enumtype));
6678 Set_Alignment (Base_Type (Enumtype), Alignment (Enumtype));
6682 -- We repeat the too late test in case it froze itself
6684 if Rep_Item_Too_Late (Enumtype, N) then
6687 end Analyze_Enumeration_Representation_Clause;
6689 ----------------------------
6690 -- Analyze_Free_Statement --
6691 ----------------------------
6693 procedure Analyze_Free_Statement (N : Node_Id) is
6695 Analyze (Expression (N));
6696 end Analyze_Free_Statement;
6698 ---------------------------
6699 -- Analyze_Freeze_Entity --
6700 ---------------------------
6702 procedure Analyze_Freeze_Entity (N : Node_Id) is
6704 Freeze_Entity_Checks (N);
6705 end Analyze_Freeze_Entity;
6707 -----------------------------------
6708 -- Analyze_Freeze_Generic_Entity --
6709 -----------------------------------
6711 procedure Analyze_Freeze_Generic_Entity (N : Node_Id) is
6712 E : constant Entity_Id := Entity (N);
6715 if not Is_Frozen (E) and then Has_Delayed_Aspects (E) then
6716 Analyze_Aspects_At_Freeze_Point (E);
6719 Freeze_Entity_Checks (N);
6720 end Analyze_Freeze_Generic_Entity;
6722 ------------------------------------------
6723 -- Analyze_Record_Representation_Clause --
6724 ------------------------------------------
6726 -- Note: we check as much as we can here, but we can't do any checks
6727 -- based on the position values (e.g. overlap checks) until freeze time
6728 -- because especially in Ada 2005 (machine scalar mode), the processing
6729 -- for non-standard bit order can substantially change the positions.
6730 -- See procedure Check_Record_Representation_Clause (called from Freeze)
6731 -- for the remainder of this processing.
6733 procedure Analyze_Record_Representation_Clause (N : Node_Id) is
6734 Ident : constant Node_Id := Identifier (N);
6739 Hbit : Uint := Uint_0;
6743 Rectype : Entity_Id;
6746 function Is_Inherited (Comp : Entity_Id) return Boolean;
6747 -- True if Comp is an inherited component in a record extension
6753 function Is_Inherited (Comp : Entity_Id) return Boolean is
6754 Comp_Base : Entity_Id;
6757 if Ekind (Rectype) = E_Record_Subtype then
6758 Comp_Base := Original_Record_Component (Comp);
6763 return Comp_Base /= Original_Record_Component (Comp_Base);
6768 Is_Record_Extension : Boolean;
6769 -- True if Rectype is a record extension
6771 CR_Pragma : Node_Id := Empty;
6772 -- Points to N_Pragma node if Complete_Representation pragma present
6774 -- Start of processing for Analyze_Record_Representation_Clause
6777 if Ignore_Rep_Clauses then
6778 Kill_Rep_Clause (N);
6783 Rectype := Entity (Ident);
6785 if Rectype = Any_Type or else Rep_Item_Too_Early (Rectype, N) then
6788 Rectype := Underlying_Type (Rectype);
6791 -- First some basic error checks
6793 if not Is_Record_Type (Rectype) then
6795 ("record type required, found}", Ident, First_Subtype (Rectype));
6798 elsif Scope (Rectype) /= Current_Scope then
6799 Error_Msg_N ("type must be declared in this scope", N);
6802 elsif not Is_First_Subtype (Rectype) then
6803 Error_Msg_N ("cannot give record rep clause for subtype", N);
6806 elsif Has_Record_Rep_Clause (Rectype) then
6807 Error_Msg_N ("duplicate record rep clause ignored", N);
6810 elsif Rep_Item_Too_Late (Rectype, N) then
6814 -- We know we have a first subtype, now possibly go to the anonymous
6815 -- base type to determine whether Rectype is a record extension.
6817 Recdef := Type_Definition (Declaration_Node (Base_Type (Rectype)));
6818 Is_Record_Extension :=
6819 Nkind (Recdef) = N_Derived_Type_Definition
6820 and then Present (Record_Extension_Part (Recdef));
6822 if Present (Mod_Clause (N)) then
6824 Loc : constant Source_Ptr := Sloc (N);
6825 M : constant Node_Id := Mod_Clause (N);
6826 P : constant List_Id := Pragmas_Before (M);
6830 pragma Warnings (Off, Mod_Val);
6833 Check_Restriction (No_Obsolescent_Features, Mod_Clause (N));
6835 if Warn_On_Obsolescent_Feature then
6837 ("?j?mod clause is an obsolescent feature (RM J.8)", N);
6839 ("\?j?use alignment attribute definition clause instead", N);
6846 -- In ASIS_Mode mode, expansion is disabled, but we must convert
6847 -- the Mod clause into an alignment clause anyway, so that the
6848 -- back end can compute and back-annotate properly the size and
6849 -- alignment of types that may include this record.
6851 -- This seems dubious, this destroys the source tree in a manner
6852 -- not detectable by ASIS ???
6854 if Operating_Mode = Check_Semantics and then ASIS_Mode then
6856 Make_Attribute_Definition_Clause (Loc,
6857 Name => New_Occurrence_Of (Base_Type (Rectype), Loc),
6858 Chars => Name_Alignment,
6859 Expression => Relocate_Node (Expression (M)));
6861 Set_From_At_Mod (AtM_Nod);
6862 Insert_After (N, AtM_Nod);
6863 Mod_Val := Get_Alignment_Value (Expression (AtM_Nod));
6864 Set_Mod_Clause (N, Empty);
6867 -- Get the alignment value to perform error checking
6869 Mod_Val := Get_Alignment_Value (Expression (M));
6874 -- For untagged types, clear any existing component clauses for the
6875 -- type. If the type is derived, this is what allows us to override
6876 -- a rep clause for the parent. For type extensions, the representation
6877 -- of the inherited components is inherited, so we want to keep previous
6878 -- component clauses for completeness.
6880 if not Is_Tagged_Type (Rectype) then
6881 Comp := First_Component_Or_Discriminant (Rectype);
6882 while Present (Comp) loop
6883 Set_Component_Clause (Comp, Empty);
6884 Next_Component_Or_Discriminant (Comp);
6888 -- All done if no component clauses
6890 CC := First (Component_Clauses (N));
6896 -- A representation like this applies to the base type
6898 Set_Has_Record_Rep_Clause (Base_Type (Rectype));
6899 Set_Has_Non_Standard_Rep (Base_Type (Rectype));
6900 Set_Has_Specified_Layout (Base_Type (Rectype));
6902 -- Process the component clauses
6904 while Present (CC) loop
6908 if Nkind (CC) = N_Pragma then
6911 -- The only pragma of interest is Complete_Representation
6913 if Pragma_Name (CC) = Name_Complete_Representation then
6917 -- Processing for real component clause
6920 Posit := Static_Integer (Position (CC));
6921 Fbit := Static_Integer (First_Bit (CC));
6922 Lbit := Static_Integer (Last_Bit (CC));
6925 and then Fbit /= No_Uint
6926 and then Lbit /= No_Uint
6929 Error_Msg_N ("position cannot be negative", Position (CC));
6932 Error_Msg_N ("first bit cannot be negative", First_Bit (CC));
6934 -- The Last_Bit specified in a component clause must not be
6935 -- less than the First_Bit minus one (RM-13.5.1(10)).
6937 elsif Lbit < Fbit - 1 then
6939 ("last bit cannot be less than first bit minus one",
6942 -- Values look OK, so find the corresponding record component
6943 -- Even though the syntax allows an attribute reference for
6944 -- implementation-defined components, GNAT does not allow the
6945 -- tag to get an explicit position.
6947 elsif Nkind (Component_Name (CC)) = N_Attribute_Reference then
6948 if Attribute_Name (Component_Name (CC)) = Name_Tag then
6949 Error_Msg_N ("position of tag cannot be specified", CC);
6951 Error_Msg_N ("illegal component name", CC);
6955 Comp := First_Entity (Rectype);
6956 while Present (Comp) loop
6957 exit when Chars (Comp) = Chars (Component_Name (CC));
6963 -- Maybe component of base type that is absent from
6964 -- statically constrained first subtype.
6966 Comp := First_Entity (Base_Type (Rectype));
6967 while Present (Comp) loop
6968 exit when Chars (Comp) = Chars (Component_Name (CC));
6975 ("component clause is for non-existent field", CC);
6977 -- Ada 2012 (AI05-0026): Any name that denotes a
6978 -- discriminant of an object of an unchecked union type
6979 -- shall not occur within a record_representation_clause.
6981 -- The general restriction of using record rep clauses on
6982 -- Unchecked_Union types has now been lifted. Since it is
6983 -- possible to introduce a record rep clause which mentions
6984 -- the discriminant of an Unchecked_Union in non-Ada 2012
6985 -- code, this check is applied to all versions of the
6988 elsif Ekind (Comp) = E_Discriminant
6989 and then Is_Unchecked_Union (Rectype)
6992 ("cannot reference discriminant of unchecked union",
6993 Component_Name (CC));
6995 elsif Is_Record_Extension and then Is_Inherited (Comp) then
6997 ("component clause not allowed for inherited "
6998 & "component&", CC, Comp);
7000 elsif Present (Component_Clause (Comp)) then
7002 -- Diagnose duplicate rep clause, or check consistency
7003 -- if this is an inherited component. In a double fault,
7004 -- there may be a duplicate inconsistent clause for an
7005 -- inherited component.
7007 if Scope (Original_Record_Component (Comp)) = Rectype
7008 or else Parent (Component_Clause (Comp)) = N
7010 Error_Msg_Sloc := Sloc (Component_Clause (Comp));
7011 Error_Msg_N ("component clause previously given#", CC);
7015 Rep1 : constant Node_Id := Component_Clause (Comp);
7017 if Intval (Position (Rep1)) /=
7018 Intval (Position (CC))
7019 or else Intval (First_Bit (Rep1)) /=
7020 Intval (First_Bit (CC))
7021 or else Intval (Last_Bit (Rep1)) /=
7022 Intval (Last_Bit (CC))
7025 ("component clause inconsistent with "
7026 & "representation of ancestor", CC);
7028 elsif Warn_On_Redundant_Constructs then
7030 ("?r?redundant confirming component clause "
7031 & "for component!", CC);
7036 -- Normal case where this is the first component clause we
7037 -- have seen for this entity, so set it up properly.
7040 -- Make reference for field in record rep clause and set
7041 -- appropriate entity field in the field identifier.
7044 (Comp, Component_Name (CC), Set_Ref => False);
7045 Set_Entity (Component_Name (CC), Comp);
7047 -- Update Fbit and Lbit to the actual bit number
7049 Fbit := Fbit + UI_From_Int (SSU) * Posit;
7050 Lbit := Lbit + UI_From_Int (SSU) * Posit;
7052 if Has_Size_Clause (Rectype)
7053 and then RM_Size (Rectype) <= Lbit
7056 ("bit number out of range of specified size",
7059 Set_Component_Clause (Comp, CC);
7060 Set_Component_Bit_Offset (Comp, Fbit);
7061 Set_Esize (Comp, 1 + (Lbit - Fbit));
7062 Set_Normalized_First_Bit (Comp, Fbit mod SSU);
7063 Set_Normalized_Position (Comp, Fbit / SSU);
7065 if Warn_On_Overridden_Size
7066 and then Has_Size_Clause (Etype (Comp))
7067 and then RM_Size (Etype (Comp)) /= Esize (Comp)
7070 ("?S?component size overrides size clause for&",
7071 Component_Name (CC), Etype (Comp));
7074 -- This information is also set in the corresponding
7075 -- component of the base type, found by accessing the
7076 -- Original_Record_Component link if it is present.
7078 Ocomp := Original_Record_Component (Comp);
7085 (Component_Name (CC),
7091 (Comp, First_Node (CC), "component clause", Biased);
7093 if Present (Ocomp) then
7094 Set_Component_Clause (Ocomp, CC);
7095 Set_Component_Bit_Offset (Ocomp, Fbit);
7096 Set_Normalized_First_Bit (Ocomp, Fbit mod SSU);
7097 Set_Normalized_Position (Ocomp, Fbit / SSU);
7098 Set_Esize (Ocomp, 1 + (Lbit - Fbit));
7100 Set_Normalized_Position_Max
7101 (Ocomp, Normalized_Position (Ocomp));
7103 -- Note: we don't use Set_Biased here, because we
7104 -- already gave a warning above if needed, and we
7105 -- would get a duplicate for the same name here.
7107 Set_Has_Biased_Representation
7108 (Ocomp, Has_Biased_Representation (Comp));
7111 if Esize (Comp) < 0 then
7112 Error_Msg_N ("component size is negative", CC);
7123 -- Check missing components if Complete_Representation pragma appeared
7125 if Present (CR_Pragma) then
7126 Comp := First_Component_Or_Discriminant (Rectype);
7127 while Present (Comp) loop
7128 if No (Component_Clause (Comp)) then
7130 ("missing component clause for &", CR_Pragma, Comp);
7133 Next_Component_Or_Discriminant (Comp);
7136 -- Give missing components warning if required
7138 elsif Warn_On_Unrepped_Components then
7140 Num_Repped_Components : Nat := 0;
7141 Num_Unrepped_Components : Nat := 0;
7144 -- First count number of repped and unrepped components
7146 Comp := First_Component_Or_Discriminant (Rectype);
7147 while Present (Comp) loop
7148 if Present (Component_Clause (Comp)) then
7149 Num_Repped_Components := Num_Repped_Components + 1;
7151 Num_Unrepped_Components := Num_Unrepped_Components + 1;
7154 Next_Component_Or_Discriminant (Comp);
7157 -- We are only interested in the case where there is at least one
7158 -- unrepped component, and at least half the components have rep
7159 -- clauses. We figure that if less than half have them, then the
7160 -- partial rep clause is really intentional. If the component
7161 -- type has no underlying type set at this point (as for a generic
7162 -- formal type), we don't know enough to give a warning on the
7165 if Num_Unrepped_Components > 0
7166 and then Num_Unrepped_Components < Num_Repped_Components
7168 Comp := First_Component_Or_Discriminant (Rectype);
7169 while Present (Comp) loop
7170 if No (Component_Clause (Comp))
7171 and then Comes_From_Source (Comp)
7172 and then Present (Underlying_Type (Etype (Comp)))
7173 and then (Is_Scalar_Type (Underlying_Type (Etype (Comp)))
7174 or else Size_Known_At_Compile_Time
7175 (Underlying_Type (Etype (Comp))))
7176 and then not Has_Warnings_Off (Rectype)
7178 -- Ignore discriminant in unchecked union, since it is
7179 -- not there, and cannot have a component clause.
7181 and then (not Is_Unchecked_Union (Rectype)
7182 or else Ekind (Comp) /= E_Discriminant)
7184 Error_Msg_Sloc := Sloc (Comp);
7186 ("?C?no component clause given for & declared #",
7190 Next_Component_Or_Discriminant (Comp);
7195 end Analyze_Record_Representation_Clause;
7197 -------------------------------------
7198 -- Build_Discrete_Static_Predicate --
7199 -------------------------------------
7201 procedure Build_Discrete_Static_Predicate
7206 Loc : constant Source_Ptr := Sloc (Expr);
7208 Non_Static : exception;
7209 -- Raised if something non-static is found
7211 Btyp : constant Entity_Id := Base_Type (Typ);
7213 BLo : constant Uint := Expr_Value (Type_Low_Bound (Btyp));
7214 BHi : constant Uint := Expr_Value (Type_High_Bound (Btyp));
7215 -- Low bound and high bound value of base type of Typ
7219 -- Bounds for constructing the static predicate. We use the bound of the
7220 -- subtype if it is static, otherwise the corresponding base type bound.
7221 -- Note: a non-static subtype can have a static predicate.
7226 -- One entry in a Rlist value, a single REnt (range entry) value denotes
7227 -- one range from Lo to Hi. To represent a single value range Lo = Hi =
7230 type RList is array (Nat range <>) of REnt;
7231 -- A list of ranges. The ranges are sorted in increasing order, and are
7232 -- disjoint (there is a gap of at least one value between each range in
7233 -- the table). A value is in the set of ranges in Rlist if it lies
7234 -- within one of these ranges.
7236 False_Range : constant RList :=
7237 RList'(1 .. 0 => REnt'(No_Uint, No_Uint));
7238 -- An empty set of ranges represents a range list that can never be
7239 -- satisfied, since there are no ranges in which the value could lie,
7240 -- so it does not lie in any of them. False_Range is a canonical value
7241 -- for this empty set, but general processing should test for an Rlist
7242 -- with length zero (see Is_False predicate), since other null ranges
7243 -- may appear which must be treated as False.
7245 True_Range : constant RList := RList'(1 => REnt'(BLo, BHi));
7246 -- Range representing True, value must be in the base range
7248 function "and" (Left : RList; Right : RList) return RList;
7249 -- And's together two range lists, returning a range list. This is a set
7250 -- intersection operation.
7252 function "or" (Left : RList; Right : RList) return RList;
7253 -- Or's together two range lists, returning a range list. This is a set
7256 function "not" (Right : RList) return RList;
7257 -- Returns complement of a given range list, i.e. a range list
7258 -- representing all the values in TLo .. THi that are not in the input
7261 function Build_Val (V : Uint) return Node_Id;
7262 -- Return an analyzed N_Identifier node referencing this value, suitable
7263 -- for use as an entry in the Static_Discrte_Predicate list. This node
7264 -- is typed with the base type.
7266 function Build_Range (Lo : Uint; Hi : Uint) return Node_Id;
7267 -- Return an analyzed N_Range node referencing this range, suitable for
7268 -- use as an entry in the Static_Discrete_Predicate list. This node is
7269 -- typed with the base type.
7271 function Get_RList (Exp : Node_Id) return RList;
7272 -- This is a recursive routine that converts the given expression into a
7273 -- list of ranges, suitable for use in building the static predicate.
7275 function Is_False (R : RList) return Boolean;
7276 pragma Inline (Is_False);
7277 -- Returns True if the given range list is empty, and thus represents a
7278 -- False list of ranges that can never be satisfied.
7280 function Is_True (R : RList) return Boolean;
7281 -- Returns True if R trivially represents the True predicate by having a
7282 -- single range from BLo to BHi.
7284 function Is_Type_Ref (N : Node_Id) return Boolean;
7285 pragma Inline (Is_Type_Ref);
7286 -- Returns if True if N is a reference to the type for the predicate in
7287 -- the expression (i.e. if it is an identifier whose Chars field matches
7288 -- the Nam given in the call). N must not be parenthesized, if the type
7289 -- name appears in parens, this routine will return False.
7291 function Lo_Val (N : Node_Id) return Uint;
7292 -- Given an entry from a Static_Discrete_Predicate list that is either
7293 -- a static expression or static range, gets either the expression value
7294 -- or the low bound of the range.
7296 function Hi_Val (N : Node_Id) return Uint;
7297 -- Given an entry from a Static_Discrete_Predicate list that is either
7298 -- a static expression or static range, gets either the expression value
7299 -- or the high bound of the range.
7301 function Membership_Entry (N : Node_Id) return RList;
7302 -- Given a single membership entry (range, value, or subtype), returns
7303 -- the corresponding range list. Raises Static_Error if not static.
7305 function Membership_Entries (N : Node_Id) return RList;
7306 -- Given an element on an alternatives list of a membership operation,
7307 -- returns the range list corresponding to this entry and all following
7308 -- entries (i.e. returns the "or" of this list of values).
7310 function Stat_Pred (Typ : Entity_Id) return RList;
7311 -- Given a type, if it has a static predicate, then return the predicate
7312 -- as a range list, otherwise raise Non_Static.
7318 function "and" (Left : RList; Right : RList) return RList is
7320 -- First range of result
7322 SLeft : Nat := Left'First;
7323 -- Start of rest of left entries
7325 SRight : Nat := Right'First;
7326 -- Start of rest of right entries
7329 -- If either range is True, return the other
7331 if Is_True (Left) then
7333 elsif Is_True (Right) then
7337 -- If either range is False, return False
7339 if Is_False (Left) or else Is_False (Right) then
7343 -- Loop to remove entries at start that are disjoint, and thus just
7344 -- get discarded from the result entirely.
7347 -- If no operands left in either operand, result is false
7349 if SLeft > Left'Last or else SRight > Right'Last then
7352 -- Discard first left operand entry if disjoint with right
7354 elsif Left (SLeft).Hi < Right (SRight).Lo then
7357 -- Discard first right operand entry if disjoint with left
7359 elsif Right (SRight).Hi < Left (SLeft).Lo then
7360 SRight := SRight + 1;
7362 -- Otherwise we have an overlapping entry
7369 -- Now we have two non-null operands, and first entries overlap. The
7370 -- first entry in the result will be the overlapping part of these
7373 FEnt := REnt'(Lo => UI_Max (Left (SLeft).Lo, Right (SRight).Lo),
7374 Hi => UI_Min (Left (SLeft).Hi, Right (SRight).Hi));
7376 -- Now we can remove the entry that ended at a lower value, since its
7377 -- contribution is entirely contained in Fent.
7379 if Left (SLeft).Hi <= Right (SRight).Hi then
7382 SRight := SRight + 1;
7385 -- Compute result by concatenating this first entry with the "and" of
7386 -- the remaining parts of the left and right operands. Note that if
7387 -- either of these is empty, "and" will yield empty, so that we will
7388 -- end up with just Fent, which is what we want in that case.
7391 FEnt & (Left (SLeft .. Left'Last) and Right (SRight .. Right'Last));
7398 function "not" (Right : RList) return RList is
7400 -- Return True if False range
7402 if Is_False (Right) then
7406 -- Return False if True range
7408 if Is_True (Right) then
7412 -- Here if not trivial case
7415 Result : RList (1 .. Right'Length + 1);
7416 -- May need one more entry for gap at beginning and end
7419 -- Number of entries stored in Result
7424 if Right (Right'First).Lo > TLo then
7426 Result (Count) := REnt'(TLo, Right (Right'First).Lo - 1);
7429 -- Gaps between ranges
7431 for J in Right'First .. Right'Last - 1 loop
7433 Result (Count) := REnt'(Right (J).Hi + 1, Right (J + 1).Lo - 1);
7438 if Right (Right'Last).Hi < THi then
7440 Result (Count) := REnt'(Right (Right'Last).Hi + 1, THi);
7443 return Result (1 .. Count);
7451 function "or" (Left : RList; Right : RList) return RList is
7453 -- First range of result
7455 SLeft : Nat := Left'First;
7456 -- Start of rest of left entries
7458 SRight : Nat := Right'First;
7459 -- Start of rest of right entries
7462 -- If either range is True, return True
7464 if Is_True (Left) or else Is_True (Right) then
7468 -- If either range is False (empty), return the other
7470 if Is_False (Left) then
7472 elsif Is_False (Right) then
7476 -- Initialize result first entry from left or right operand depending
7477 -- on which starts with the lower range.
7479 if Left (SLeft).Lo < Right (SRight).Lo then
7480 FEnt := Left (SLeft);
7483 FEnt := Right (SRight);
7484 SRight := SRight + 1;
7487 -- This loop eats ranges from left and right operands that are
7488 -- contiguous with the first range we are gathering.
7491 -- Eat first entry in left operand if contiguous or overlapped by
7492 -- gathered first operand of result.
7494 if SLeft <= Left'Last
7495 and then Left (SLeft).Lo <= FEnt.Hi + 1
7497 FEnt.Hi := UI_Max (FEnt.Hi, Left (SLeft).Hi);
7500 -- Eat first entry in right operand if contiguous or overlapped by
7501 -- gathered right operand of result.
7503 elsif SRight <= Right'Last
7504 and then Right (SRight).Lo <= FEnt.Hi + 1
7506 FEnt.Hi := UI_Max (FEnt.Hi, Right (SRight).Hi);
7507 SRight := SRight + 1;
7509 -- All done if no more entries to eat
7516 -- Obtain result as the first entry we just computed, concatenated
7517 -- to the "or" of the remaining results (if one operand is empty,
7518 -- this will just concatenate with the other
7521 FEnt & (Left (SLeft .. Left'Last) or Right (SRight .. Right'Last));
7528 function Build_Range (Lo : Uint; Hi : Uint) return Node_Id is
7533 Low_Bound => Build_Val (Lo),
7534 High_Bound => Build_Val (Hi));
7535 Set_Etype (Result, Btyp);
7536 Set_Analyzed (Result);
7544 function Build_Val (V : Uint) return Node_Id is
7548 if Is_Enumeration_Type (Typ) then
7549 Result := Get_Enum_Lit_From_Pos (Typ, V, Loc);
7551 Result := Make_Integer_Literal (Loc, V);
7554 Set_Etype (Result, Btyp);
7555 Set_Is_Static_Expression (Result);
7556 Set_Analyzed (Result);
7564 function Get_RList (Exp : Node_Id) return RList is
7569 -- Static expression can only be true or false
7571 if Is_OK_Static_Expression (Exp) then
7572 if Expr_Value (Exp) = 0 then
7579 -- Otherwise test node type
7587 when N_Op_And | N_And_Then =>
7588 return Get_RList (Left_Opnd (Exp))
7590 Get_RList (Right_Opnd (Exp));
7594 when N_Op_Or | N_Or_Else =>
7595 return Get_RList (Left_Opnd (Exp))
7597 Get_RList (Right_Opnd (Exp));
7602 return not Get_RList (Right_Opnd (Exp));
7604 -- Comparisons of type with static value
7606 when N_Op_Compare =>
7608 -- Type is left operand
7610 if Is_Type_Ref (Left_Opnd (Exp))
7611 and then Is_OK_Static_Expression (Right_Opnd (Exp))
7613 Val := Expr_Value (Right_Opnd (Exp));
7615 -- Typ is right operand
7617 elsif Is_Type_Ref (Right_Opnd (Exp))
7618 and then Is_OK_Static_Expression (Left_Opnd (Exp))
7620 Val := Expr_Value (Left_Opnd (Exp));
7622 -- Invert sense of comparison
7625 when N_Op_Gt => Op := N_Op_Lt;
7626 when N_Op_Lt => Op := N_Op_Gt;
7627 when N_Op_Ge => Op := N_Op_Le;
7628 when N_Op_Le => Op := N_Op_Ge;
7629 when others => null;
7632 -- Other cases are non-static
7638 -- Construct range according to comparison operation
7642 return RList'(1 => REnt'(Val, Val));
7645 return RList'(1 => REnt'(Val, BHi));
7648 return RList'(1 => REnt'(Val + 1, BHi));
7651 return RList'(1 => REnt'(BLo, Val));
7654 return RList'(1 => REnt'(BLo, Val - 1));
7657 return RList'(REnt'(BLo, Val - 1), REnt'(Val + 1, BHi));
7660 raise Program_Error;
7666 if not Is_Type_Ref (Left_Opnd (Exp)) then
7670 if Present (Right_Opnd (Exp)) then
7671 return Membership_Entry (Right_Opnd (Exp));
7673 return Membership_Entries (First (Alternatives (Exp)));
7676 -- Negative membership (NOT IN)
7679 if not Is_Type_Ref (Left_Opnd (Exp)) then
7683 if Present (Right_Opnd (Exp)) then
7684 return not Membership_Entry (Right_Opnd (Exp));
7686 return not Membership_Entries (First (Alternatives (Exp)));
7689 -- Function call, may be call to static predicate
7691 when N_Function_Call =>
7692 if Is_Entity_Name (Name (Exp)) then
7694 Ent : constant Entity_Id := Entity (Name (Exp));
7696 if Is_Predicate_Function (Ent)
7698 Is_Predicate_Function_M (Ent)
7700 return Stat_Pred (Etype (First_Formal (Ent)));
7705 -- Other function call cases are non-static
7709 -- Qualified expression, dig out the expression
7711 when N_Qualified_Expression =>
7712 return Get_RList (Expression (Exp));
7714 when N_Case_Expression =>
7721 if not Is_Entity_Name (Expression (Expr))
7722 or else Etype (Expression (Expr)) /= Typ
7725 ("expression must denaote subtype", Expression (Expr));
7729 -- Collect discrete choices in all True alternatives
7731 Choices := New_List;
7732 Alt := First (Alternatives (Exp));
7733 while Present (Alt) loop
7734 Dep := Expression (Alt);
7736 if not Is_OK_Static_Expression (Dep) then
7739 elsif Is_True (Expr_Value (Dep)) then
7740 Append_List_To (Choices,
7741 New_Copy_List (Discrete_Choices (Alt)));
7747 return Membership_Entries (First (Choices));
7750 -- Expression with actions: if no actions, dig out expression
7752 when N_Expression_With_Actions =>
7753 if Is_Empty_List (Actions (Exp)) then
7754 return Get_RList (Expression (Exp));
7762 return (Get_RList (Left_Opnd (Exp))
7763 and not Get_RList (Right_Opnd (Exp)))
7764 or (Get_RList (Right_Opnd (Exp))
7765 and not Get_RList (Left_Opnd (Exp)));
7767 -- Any other node type is non-static
7778 function Hi_Val (N : Node_Id) return Uint is
7780 if Is_OK_Static_Expression (N) then
7781 return Expr_Value (N);
7783 pragma Assert (Nkind (N) = N_Range);
7784 return Expr_Value (High_Bound (N));
7792 function Is_False (R : RList) return Boolean is
7794 return R'Length = 0;
7801 function Is_True (R : RList) return Boolean is
7804 and then R (R'First).Lo = BLo
7805 and then R (R'First).Hi = BHi;
7812 function Is_Type_Ref (N : Node_Id) return Boolean is
7814 return Nkind (N) = N_Identifier
7815 and then Chars (N) = Nam
7816 and then Paren_Count (N) = 0;
7823 function Lo_Val (N : Node_Id) return Uint is
7825 if Is_OK_Static_Expression (N) then
7826 return Expr_Value (N);
7828 pragma Assert (Nkind (N) = N_Range);
7829 return Expr_Value (Low_Bound (N));
7833 ------------------------
7834 -- Membership_Entries --
7835 ------------------------
7837 function Membership_Entries (N : Node_Id) return RList is
7839 if No (Next (N)) then
7840 return Membership_Entry (N);
7842 return Membership_Entry (N) or Membership_Entries (Next (N));
7844 end Membership_Entries;
7846 ----------------------
7847 -- Membership_Entry --
7848 ----------------------
7850 function Membership_Entry (N : Node_Id) return RList is
7858 if Nkind (N) = N_Range then
7859 if not Is_OK_Static_Expression (Low_Bound (N))
7861 not Is_OK_Static_Expression (High_Bound (N))
7865 SLo := Expr_Value (Low_Bound (N));
7866 SHi := Expr_Value (High_Bound (N));
7867 return RList'(1 => REnt'(SLo, SHi));
7870 -- Static expression case
7872 elsif Is_OK_Static_Expression (N) then
7873 Val := Expr_Value (N);
7874 return RList'(1 => REnt'(Val, Val));
7876 -- Identifier (other than static expression) case
7878 else pragma Assert (Nkind (N) = N_Identifier);
7882 if Is_Type (Entity (N)) then
7884 -- If type has predicates, process them
7886 if Has_Predicates (Entity (N)) then
7887 return Stat_Pred (Entity (N));
7889 -- For static subtype without predicates, get range
7891 elsif Is_OK_Static_Subtype (Entity (N)) then
7892 SLo := Expr_Value (Type_Low_Bound (Entity (N)));
7893 SHi := Expr_Value (Type_High_Bound (Entity (N)));
7894 return RList'(1 => REnt'(SLo, SHi));
7896 -- Any other type makes us non-static
7902 -- Any other kind of identifier in predicate (e.g. a non-static
7903 -- expression value) means this is not a static predicate.
7909 end Membership_Entry;
7915 function Stat_Pred (Typ : Entity_Id) return RList is
7917 -- Not static if type does not have static predicates
7919 if not Has_Static_Predicate (Typ) then
7923 -- Otherwise we convert the predicate list to a range list
7926 Spred : constant List_Id := Static_Discrete_Predicate (Typ);
7927 Result : RList (1 .. List_Length (Spred));
7931 P := First (Static_Discrete_Predicate (Typ));
7932 for J in Result'Range loop
7933 Result (J) := REnt'(Lo_Val (P), Hi_Val (P));
7941 -- Start of processing for Build_Discrete_Static_Predicate
7944 -- Establish bounds for the predicate
7946 if Compile_Time_Known_Value (Type_Low_Bound (Typ)) then
7947 TLo := Expr_Value (Type_Low_Bound (Typ));
7952 if Compile_Time_Known_Value (Type_High_Bound (Typ)) then
7953 THi := Expr_Value (Type_High_Bound (Typ));
7958 -- Analyze the expression to see if it is a static predicate
7961 Ranges : constant RList := Get_RList (Expr);
7962 -- Range list from expression if it is static
7967 -- Convert range list into a form for the static predicate. In the
7968 -- Ranges array, we just have raw ranges, these must be converted
7969 -- to properly typed and analyzed static expressions or range nodes.
7971 -- Note: here we limit ranges to the ranges of the subtype, so that
7972 -- a predicate is always false for values outside the subtype. That
7973 -- seems fine, such values are invalid anyway, and considering them
7974 -- to fail the predicate seems allowed and friendly, and furthermore
7975 -- simplifies processing for case statements and loops.
7979 for J in Ranges'Range loop
7981 Lo : Uint := Ranges (J).Lo;
7982 Hi : Uint := Ranges (J).Hi;
7985 -- Ignore completely out of range entry
7987 if Hi < TLo or else Lo > THi then
7990 -- Otherwise process entry
7993 -- Adjust out of range value to subtype range
8003 -- Convert range into required form
8005 Append_To (Plist, Build_Range (Lo, Hi));
8010 -- Processing was successful and all entries were static, so now we
8011 -- can store the result as the predicate list.
8013 Set_Static_Discrete_Predicate (Typ, Plist);
8015 -- The processing for static predicates put the expression into
8016 -- canonical form as a series of ranges. It also eliminated
8017 -- duplicates and collapsed and combined ranges. We might as well
8018 -- replace the alternatives list of the right operand of the
8019 -- membership test with the static predicate list, which will
8020 -- usually be more efficient.
8023 New_Alts : constant List_Id := New_List;
8028 Old_Node := First (Plist);
8029 while Present (Old_Node) loop
8030 New_Node := New_Copy (Old_Node);
8032 if Nkind (New_Node) = N_Range then
8033 Set_Low_Bound (New_Node, New_Copy (Low_Bound (Old_Node)));
8034 Set_High_Bound (New_Node, New_Copy (High_Bound (Old_Node)));
8037 Append_To (New_Alts, New_Node);
8041 -- If empty list, replace by False
8043 if Is_Empty_List (New_Alts) then
8044 Rewrite (Expr, New_Occurrence_Of (Standard_False, Loc));
8046 -- Else replace by set membership test
8051 Left_Opnd => Make_Identifier (Loc, Nam),
8052 Right_Opnd => Empty,
8053 Alternatives => New_Alts));
8055 -- Resolve new expression in function context
8057 Install_Formals (Predicate_Function (Typ));
8058 Push_Scope (Predicate_Function (Typ));
8059 Analyze_And_Resolve (Expr, Standard_Boolean);
8065 -- If non-static, return doing nothing
8070 end Build_Discrete_Static_Predicate;
8072 --------------------------------
8073 -- Build_Export_Import_Pragma --
8074 --------------------------------
8076 function Build_Export_Import_Pragma
8078 Id : Entity_Id) return Node_Id
8080 Asp_Id : constant Aspect_Id := Get_Aspect_Id (Asp);
8081 Expr : constant Node_Id := Expression (Asp);
8082 Loc : constant Source_Ptr := Sloc (Asp);
8093 Create_Pragma : Boolean := False;
8094 -- This flag is set when the aspect form is such that it warrants the
8095 -- creation of a corresponding pragma.
8098 if Present (Expr) then
8099 if Error_Posted (Expr) then
8102 elsif Is_True (Expr_Value (Expr)) then
8103 Create_Pragma := True;
8106 -- Otherwise the aspect defaults to True
8109 Create_Pragma := True;
8112 -- Nothing to do when the expression is False or is erroneous
8114 if not Create_Pragma then
8118 -- Obtain all interfacing aspects that apply to the related entity
8120 Get_Interfacing_Aspects
8124 Expo_Asp => Dummy_1,
8130 -- Handle the convention argument
8132 if Present (Conv) then
8133 Conv_Arg := New_Copy_Tree (Expression (Conv));
8135 -- Assume convention "Ada' when aspect Convention is missing
8138 Conv_Arg := Make_Identifier (Loc, Name_Ada);
8142 Make_Pragma_Argument_Association (Loc,
8143 Chars => Name_Convention,
8144 Expression => Conv_Arg));
8146 -- Handle the entity argument
8149 Make_Pragma_Argument_Association (Loc,
8150 Chars => Name_Entity,
8151 Expression => New_Occurrence_Of (Id, Loc)));
8153 -- Handle the External_Name argument
8155 if Present (EN) then
8157 Make_Pragma_Argument_Association (Loc,
8158 Chars => Name_External_Name,
8159 Expression => New_Copy_Tree (Expression (EN))));
8162 -- Handle the Link_Name argument
8164 if Present (LN) then
8166 Make_Pragma_Argument_Association (Loc,
8167 Chars => Name_Link_Name,
8168 Expression => New_Copy_Tree (Expression (LN))));
8172 -- pragma Export/Import
8173 -- (Convention => <Conv>/Ada,
8175 -- [External_Name => <EN>,]
8176 -- [Link_Name => <LN>]);
8180 Pragma_Identifier =>
8181 Make_Identifier (Loc, Chars (Identifier (Asp))),
8182 Pragma_Argument_Associations => Args);
8184 -- Decorate the relevant aspect and the pragma
8186 Set_Aspect_Rep_Item (Asp, Prag);
8188 Set_Corresponding_Aspect (Prag, Asp);
8189 Set_From_Aspect_Specification (Prag);
8190 Set_Parent (Prag, Asp);
8192 if Asp_Id = Aspect_Import and then Is_Subprogram (Id) then
8193 Set_Import_Pragma (Id, Prag);
8197 end Build_Export_Import_Pragma;
8199 -------------------------------
8200 -- Build_Predicate_Functions --
8201 -------------------------------
8203 -- The procedures that are constructed here have the form:
8205 -- function typPredicate (Ixxx : typ) return Boolean is
8208 -- typ1Predicate (typ1 (Ixxx))
8209 -- and then typ2Predicate (typ2 (Ixxx))
8211 -- exp1 and then exp2 and then ...
8212 -- end typPredicate;
8214 -- Here exp1, and exp2 are expressions from Predicate pragmas. Note that
8215 -- this is the point at which these expressions get analyzed, providing the
8216 -- required delay, and typ1, typ2, are entities from which predicates are
8217 -- inherited. Note that we do NOT generate Check pragmas, that's because we
8218 -- use this function even if checks are off, e.g. for membership tests.
8220 -- Note that the inherited predicates are evaluated first, as required by
8223 -- Note that Sem_Eval.Real_Or_String_Static_Predicate_Matches depends on
8224 -- the form of this return expression.
8226 -- If the expression has at least one Raise_Expression, then we also build
8227 -- the typPredicateM version of the function, in which any occurrence of a
8228 -- Raise_Expression is converted to "return False".
8230 procedure Build_Predicate_Functions (Typ : Entity_Id; N : Node_Id) is
8231 Loc : constant Source_Ptr := Sloc (Typ);
8234 -- This is the expression for the result of the function. It is
8235 -- is build by connecting the component predicates with AND THEN.
8238 -- This is the corresponding return expression for the Predicate_M
8239 -- function. It differs in that raise expressions are marked for
8240 -- special expansion (see Process_REs).
8242 Object_Name : Name_Id;
8243 -- Name for argument of Predicate procedure. Note that we use the same
8244 -- name for both predicate functions. That way the reference within the
8245 -- predicate expression is the same in both functions.
8247 Object_Entity : Entity_Id;
8248 -- Entity for argument of Predicate procedure
8250 Object_Entity_M : Entity_Id;
8251 -- Entity for argument of separate Predicate procedure when exceptions
8252 -- are present in expression.
8255 -- The function declaration
8260 Raise_Expression_Present : Boolean := False;
8261 -- Set True if Expr has at least one Raise_Expression
8263 procedure Add_Condition (Cond : Node_Id);
8264 -- Append Cond to Expr using "and then" (or just copy Cond to Expr if
8267 procedure Add_Predicates;
8268 -- Appends expressions for any Predicate pragmas in the rep item chain
8269 -- Typ to Expr. Note that we look only at items for this exact entity.
8270 -- Inheritance of predicates for the parent type is done by calling the
8271 -- Predicate_Function of the parent type, using Add_Call above.
8273 procedure Add_Call (T : Entity_Id);
8274 -- Includes a call to the predicate function for type T in Expr if T
8275 -- has predicates and Predicate_Function (T) is non-empty.
8277 function Process_RE (N : Node_Id) return Traverse_Result;
8278 -- Used in Process REs, tests if node N is a raise expression, and if
8279 -- so, marks it to be converted to return False.
8281 procedure Process_REs is new Traverse_Proc (Process_RE);
8282 -- Marks any raise expressions in Expr_M to return False
8284 function Test_RE (N : Node_Id) return Traverse_Result;
8285 -- Used in Test_REs, tests one node for being a raise expression, and if
8286 -- so sets Raise_Expression_Present True.
8288 procedure Test_REs is new Traverse_Proc (Test_RE);
8289 -- Tests to see if Expr contains any raise expressions
8295 procedure Add_Call (T : Entity_Id) is
8299 if Present (T) and then Present (Predicate_Function (T)) then
8300 Set_Has_Predicates (Typ);
8302 -- Build the call to the predicate function of T
8306 (T, Convert_To (T, Make_Identifier (Loc, Object_Name)));
8308 -- "and"-in the call to evolving expression
8310 Add_Condition (Exp);
8312 -- Output info message on inheritance if required. Note we do not
8313 -- give this information for generic actual types, since it is
8314 -- unwelcome noise in that case in instantiations. We also
8315 -- generally suppress the message in instantiations, and also
8316 -- if it involves internal names.
8318 if Opt.List_Inherited_Aspects
8319 and then not Is_Generic_Actual_Type (Typ)
8320 and then Instantiation_Depth (Sloc (Typ)) = 0
8321 and then not Is_Internal_Name (Chars (T))
8322 and then not Is_Internal_Name (Chars (Typ))
8324 Error_Msg_Sloc := Sloc (Predicate_Function (T));
8325 Error_Msg_Node_2 := T;
8326 Error_Msg_N ("info: & inherits predicate from & #?L?", Typ);
8335 procedure Add_Condition (Cond : Node_Id) is
8337 -- This is the first predicate expression
8342 -- Otherwise concatenate to the existing predicate expressions by
8343 -- using "and then".
8348 Left_Opnd => Relocate_Node (Expr),
8349 Right_Opnd => Cond);
8353 --------------------
8354 -- Add_Predicates --
8355 --------------------
8357 procedure Add_Predicates is
8358 procedure Add_Predicate (Prag : Node_Id);
8359 -- Concatenate the expression of predicate pragma Prag to Expr by
8360 -- using a short circuit "and then" operator.
8366 procedure Add_Predicate (Prag : Node_Id) is
8367 procedure Replace_Type_Reference (N : Node_Id);
8368 -- Replace a single occurrence N of the subtype name with a
8369 -- reference to the formal of the predicate function. N can be an
8370 -- identifier referencing the subtype, or a selected component,
8371 -- representing an appropriately qualified occurrence of the
8374 procedure Replace_Type_References is
8375 new Replace_Type_References_Generic (Replace_Type_Reference);
8376 -- Traverse an expression changing every occurrence of an
8377 -- identifier whose name matches the name of the subtype with a
8378 -- reference to the formal parameter of the predicate function.
8380 ----------------------------
8381 -- Replace_Type_Reference --
8382 ----------------------------
8384 procedure Replace_Type_Reference (N : Node_Id) is
8386 Rewrite (N, Make_Identifier (Sloc (N), Object_Name));
8387 -- Use the Sloc of the usage name, not the defining name
8390 Set_Entity (N, Object_Entity);
8392 -- We want to treat the node as if it comes from source, so
8393 -- that ASIS will not ignore it.
8395 Set_Comes_From_Source (N, True);
8396 end Replace_Type_Reference;
8400 Asp : constant Node_Id := Corresponding_Aspect (Prag);
8404 -- Start of processing for Add_Predicate
8407 -- Extract the arguments of the pragma. The expression itself
8408 -- is copied for use in the predicate function, to preserve the
8409 -- original version for ASIS use.
8411 Arg1 := First (Pragma_Argument_Associations (Prag));
8412 Arg2 := Next (Arg1);
8414 Arg1 := Get_Pragma_Arg (Arg1);
8415 Arg2 := New_Copy_Tree (Get_Pragma_Arg (Arg2));
8417 -- When the predicate pragma applies to the current type or its
8418 -- full view, replace all occurrences of the subtype name with
8419 -- references to the formal parameter of the predicate function.
8421 if Entity (Arg1) = Typ
8422 or else Full_View (Entity (Arg1)) = Typ
8424 Replace_Type_References (Arg2, Typ);
8426 -- If the predicate pragma comes from an aspect, replace the
8427 -- saved expression because we need the subtype references
8428 -- replaced for the calls to Preanalyze_Spec_Expression in
8429 -- Check_Aspect_At_xxx routines.
8431 if Present (Asp) then
8432 Set_Entity (Identifier (Asp), New_Copy_Tree (Arg2));
8435 -- "and"-in the Arg2 condition to evolving expression
8437 Add_Condition (Relocate_Node (Arg2));
8445 -- Start of processing for Add_Predicates
8448 Ritem := First_Rep_Item (Typ);
8449 while Present (Ritem) loop
8450 if Nkind (Ritem) = N_Pragma
8451 and then Pragma_Name (Ritem) = Name_Predicate
8453 Add_Predicate (Ritem);
8455 -- If the type is declared in an inner package it may be frozen
8456 -- outside of the package, and the generated pragma has not been
8457 -- analyzed yet, so capture the expression for the predicate
8458 -- function at this point.
8460 elsif Nkind (Ritem) = N_Aspect_Specification
8461 and then Present (Aspect_Rep_Item (Ritem))
8462 and then Scope (Typ) /= Current_Scope
8465 Prag : constant Node_Id := Aspect_Rep_Item (Ritem);
8468 if Nkind (Prag) = N_Pragma
8469 and then Pragma_Name (Prag) = Name_Predicate
8471 Add_Predicate (Prag);
8476 Next_Rep_Item (Ritem);
8484 function Process_RE (N : Node_Id) return Traverse_Result is
8486 if Nkind (N) = N_Raise_Expression then
8487 Set_Convert_To_Return_False (N);
8498 function Test_RE (N : Node_Id) return Traverse_Result is
8500 if Nkind (N) = N_Raise_Expression then
8501 Raise_Expression_Present := True;
8510 Save_Ghost_Mode : constant Ghost_Mode_Type := Ghost_Mode;
8512 -- Start of processing for Build_Predicate_Functions
8515 -- Return if already built or if type does not have predicates
8517 SId := Predicate_Function (Typ);
8518 if not Has_Predicates (Typ)
8519 or else (Present (SId) and then Has_Completion (SId))
8524 -- The related type may be subject to pragma Ghost. Set the mode now to
8525 -- ensure that the predicate functions are properly marked as Ghost.
8527 Set_Ghost_Mode_From_Entity (Typ);
8529 -- Prepare to construct predicate expression
8533 if Present (SId) then
8534 FDecl := Unit_Declaration_Node (SId);
8537 FDecl := Build_Predicate_Function_Declaration (Typ);
8538 SId := Defining_Entity (FDecl);
8541 -- Recover name of formal parameter of function that replaces references
8542 -- to the type in predicate expressions.
8546 (First (Parameter_Specifications (Specification (FDecl))));
8548 Object_Name := Chars (Object_Entity);
8549 Object_Entity_M := Make_Defining_Identifier (Loc, Chars => Object_Name);
8551 -- Add predicates for ancestor if present. These must come before the
8552 -- ones for the current type, as required by AI12-0071-1.
8555 Atyp : constant Entity_Id := Nearest_Ancestor (Typ);
8557 if Present (Atyp) then
8562 -- Add Predicates for the current type
8566 -- Case where predicates are present
8568 if Present (Expr) then
8570 -- Test for raise expression present
8574 -- If raise expression is present, capture a copy of Expr for use
8575 -- in building the predicateM function version later on. For this
8576 -- copy we replace references to Object_Entity by Object_Entity_M.
8578 if Raise_Expression_Present then
8580 Map : constant Elist_Id := New_Elmt_List;
8581 New_V : Entity_Id := Empty;
8583 -- The unanalyzed expression will be copied and appear in
8584 -- both functions. Normally expressions do not declare new
8585 -- entities, but quantified expressions do, so we need to
8586 -- create new entities for their bound variables, to prevent
8587 -- multiple definitions in gigi.
8589 function Reset_Loop_Variable (N : Node_Id)
8590 return Traverse_Result;
8592 procedure Collect_Loop_Variables is
8593 new Traverse_Proc (Reset_Loop_Variable);
8595 ------------------------
8596 -- Reset_Loop_Variable --
8597 ------------------------
8599 function Reset_Loop_Variable (N : Node_Id)
8600 return Traverse_Result
8603 if Nkind (N) = N_Iterator_Specification then
8604 New_V := Make_Defining_Identifier
8605 (Sloc (N), Chars (Defining_Identifier (N)));
8607 Set_Defining_Identifier (N, New_V);
8611 end Reset_Loop_Variable;
8614 Append_Elmt (Object_Entity, Map);
8615 Append_Elmt (Object_Entity_M, Map);
8616 Expr_M := New_Copy_Tree (Expr, Map => Map);
8617 Collect_Loop_Variables (Expr_M);
8621 -- Build the main predicate function
8624 SIdB : constant Entity_Id :=
8625 Make_Defining_Identifier (Loc,
8626 Chars => New_External_Name (Chars (Typ), "Predicate"));
8627 -- The entity for the function body
8634 -- The predicate function is shared between views of a type
8636 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
8637 Set_Predicate_Function (Full_View (Typ), SId);
8640 -- Mark the predicate function explicitly as Ghost because it does
8641 -- not come from source.
8643 if Ghost_Mode > None then
8644 Set_Is_Ghost_Entity (SId);
8647 -- Build function body
8650 Make_Function_Specification (Loc,
8651 Defining_Unit_Name => SIdB,
8652 Parameter_Specifications => New_List (
8653 Make_Parameter_Specification (Loc,
8654 Defining_Identifier =>
8655 Make_Defining_Identifier (Loc, Object_Name),
8657 New_Occurrence_Of (Typ, Loc))),
8658 Result_Definition =>
8659 New_Occurrence_Of (Standard_Boolean, Loc));
8662 Make_Subprogram_Body (Loc,
8663 Specification => Spec,
8664 Declarations => Empty_List,
8665 Handled_Statement_Sequence =>
8666 Make_Handled_Sequence_Of_Statements (Loc,
8667 Statements => New_List (
8668 Make_Simple_Return_Statement (Loc,
8669 Expression => Expr))));
8671 -- If declaration has not been analyzed yet, Insert declaration
8672 -- before freeze node. Insert body itself after freeze node.
8674 if not Analyzed (FDecl) then
8675 Insert_Before_And_Analyze (N, FDecl);
8678 Insert_After_And_Analyze (N, FBody);
8680 -- Static predicate functions are always side-effect free, and
8681 -- in most cases dynamic predicate functions are as well. Mark
8682 -- them as such whenever possible, so redundant predicate checks
8683 -- can be optimized. If there is a variable reference within the
8684 -- expression, the function is not pure.
8686 if Expander_Active then
8688 Side_Effect_Free (Expr, Variable_Ref => True));
8689 Set_Is_Inlined (SId);
8693 -- Test for raise expressions present and if so build M version
8695 if Raise_Expression_Present then
8697 SId : constant Entity_Id :=
8698 Make_Defining_Identifier (Loc,
8699 Chars => New_External_Name (Chars (Typ), "PredicateM"));
8700 -- The entity for the function spec
8702 SIdB : constant Entity_Id :=
8703 Make_Defining_Identifier (Loc,
8704 Chars => New_External_Name (Chars (Typ), "PredicateM"));
8705 -- The entity for the function body
8713 -- Mark any raise expressions for special expansion
8715 Process_REs (Expr_M);
8717 -- Build function declaration
8719 Set_Ekind (SId, E_Function);
8720 Set_Is_Predicate_Function_M (SId);
8721 Set_Predicate_Function_M (Typ, SId);
8723 -- The predicate function is shared between views of a type
8725 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
8726 Set_Predicate_Function_M (Full_View (Typ), SId);
8729 -- Mark the predicate function explicitly as Ghost because it
8730 -- does not come from source.
8732 if Ghost_Mode > None then
8733 Set_Is_Ghost_Entity (SId);
8737 Make_Function_Specification (Loc,
8738 Defining_Unit_Name => SId,
8739 Parameter_Specifications => New_List (
8740 Make_Parameter_Specification (Loc,
8741 Defining_Identifier => Object_Entity_M,
8742 Parameter_Type => New_Occurrence_Of (Typ, Loc))),
8743 Result_Definition =>
8744 New_Occurrence_Of (Standard_Boolean, Loc));
8747 Make_Subprogram_Declaration (Loc,
8748 Specification => Spec);
8750 -- Build function body
8753 Make_Function_Specification (Loc,
8754 Defining_Unit_Name => SIdB,
8755 Parameter_Specifications => New_List (
8756 Make_Parameter_Specification (Loc,
8757 Defining_Identifier =>
8758 Make_Defining_Identifier (Loc, Object_Name),
8760 New_Occurrence_Of (Typ, Loc))),
8761 Result_Definition =>
8762 New_Occurrence_Of (Standard_Boolean, Loc));
8764 -- Build the body, we declare the boolean expression before
8765 -- doing the return, because we are not really confident of
8766 -- what happens if a return appears within a return.
8769 Make_Defining_Identifier (Loc,
8770 Chars => New_Internal_Name ('B'));
8773 Make_Subprogram_Body (Loc,
8774 Specification => Spec,
8776 Declarations => New_List (
8777 Make_Object_Declaration (Loc,
8778 Defining_Identifier => BTemp,
8779 Constant_Present => True,
8780 Object_Definition =>
8781 New_Occurrence_Of (Standard_Boolean, Loc),
8782 Expression => Expr_M)),
8784 Handled_Statement_Sequence =>
8785 Make_Handled_Sequence_Of_Statements (Loc,
8786 Statements => New_List (
8787 Make_Simple_Return_Statement (Loc,
8788 Expression => New_Occurrence_Of (BTemp, Loc)))));
8790 -- Insert declaration before freeze node and body after
8792 Insert_Before_And_Analyze (N, FDecl);
8793 Insert_After_And_Analyze (N, FBody);
8797 -- See if we have a static predicate. Note that the answer may be
8798 -- yes even if we have an explicit Dynamic_Predicate present.
8805 if not Is_Scalar_Type (Typ) and then not Is_String_Type (Typ) then
8808 PS := Is_Predicate_Static (Expr, Object_Name);
8811 -- Case where we have a predicate-static aspect
8815 -- We don't set Has_Static_Predicate_Aspect, since we can have
8816 -- any of the three cases (Predicate, Dynamic_Predicate, or
8817 -- Static_Predicate) generating a predicate with an expression
8818 -- that is predicate-static. We just indicate that we have a
8819 -- predicate that can be treated as static.
8821 Set_Has_Static_Predicate (Typ);
8823 -- For discrete subtype, build the static predicate list
8825 if Is_Discrete_Type (Typ) then
8826 Build_Discrete_Static_Predicate (Typ, Expr, Object_Name);
8828 -- If we don't get a static predicate list, it means that we
8829 -- have a case where this is not possible, most typically in
8830 -- the case where we inherit a dynamic predicate. We do not
8831 -- consider this an error, we just leave the predicate as
8832 -- dynamic. But if we do succeed in building the list, then
8833 -- we mark the predicate as static.
8835 if No (Static_Discrete_Predicate (Typ)) then
8836 Set_Has_Static_Predicate (Typ, False);
8839 -- For real or string subtype, save predicate expression
8841 elsif Is_Real_Type (Typ) or else Is_String_Type (Typ) then
8842 Set_Static_Real_Or_String_Predicate (Typ, Expr);
8845 -- Case of dynamic predicate (expression is not predicate-static)
8848 -- Again, we don't set Has_Dynamic_Predicate_Aspect, since that
8849 -- is only set if we have an explicit Dynamic_Predicate aspect
8850 -- given. Here we may simply have a Predicate aspect where the
8851 -- expression happens not to be predicate-static.
8853 -- Emit an error when the predicate is categorized as static
8854 -- but its expression is not predicate-static.
8856 -- First a little fiddling to get a nice location for the
8857 -- message. If the expression is of the form (A and then B),
8858 -- where A is an inherited predicate, then use the right
8859 -- operand for the Sloc. This avoids getting confused by a call
8860 -- to an inherited predicate with a less convenient source
8864 while Nkind (EN) = N_And_Then
8865 and then Nkind (Left_Opnd (EN)) = N_Function_Call
8866 and then Is_Predicate_Function
8867 (Entity (Name (Left_Opnd (EN))))
8869 EN := Right_Opnd (EN);
8872 -- Now post appropriate message
8874 if Has_Static_Predicate_Aspect (Typ) then
8875 if Is_Scalar_Type (Typ) or else Is_String_Type (Typ) then
8877 ("expression is not predicate-static (RM 3.2.4(16-22))",
8881 ("static predicate requires scalar or string type", EN);
8888 Ghost_Mode := Save_Ghost_Mode;
8889 end Build_Predicate_Functions;
8891 ------------------------------------------
8892 -- Build_Predicate_Function_Declaration --
8893 ------------------------------------------
8895 function Build_Predicate_Function_Declaration
8896 (Typ : Entity_Id) return Node_Id
8898 Loc : constant Source_Ptr := Sloc (Typ);
8900 Object_Entity : constant Entity_Id :=
8901 Make_Defining_Identifier (Loc,
8902 Chars => New_Internal_Name ('I'));
8904 -- The formal parameter of the function
8906 SId : constant Entity_Id :=
8907 Make_Defining_Identifier (Loc,
8908 Chars => New_External_Name (Chars (Typ), "Predicate"));
8910 -- The entity for the function spec
8917 Make_Function_Specification (Loc,
8918 Defining_Unit_Name => SId,
8919 Parameter_Specifications => New_List (
8920 Make_Parameter_Specification (Loc,
8921 Defining_Identifier => Object_Entity,
8922 Parameter_Type => New_Occurrence_Of (Typ, Loc))),
8923 Result_Definition =>
8924 New_Occurrence_Of (Standard_Boolean, Loc));
8926 FDecl := Make_Subprogram_Declaration (Loc, Specification => Spec);
8928 Set_Ekind (SId, E_Function);
8929 Set_Etype (SId, Standard_Boolean);
8930 Set_Is_Internal (SId);
8931 Set_Is_Predicate_Function (SId);
8932 Set_Predicate_Function (Typ, SId);
8934 Insert_After (Parent (Typ), FDecl);
8939 end Build_Predicate_Function_Declaration;
8941 -----------------------------------------
8942 -- Check_Aspect_At_End_Of_Declarations --
8943 -----------------------------------------
8945 procedure Check_Aspect_At_End_Of_Declarations (ASN : Node_Id) is
8946 Ent : constant Entity_Id := Entity (ASN);
8947 Ident : constant Node_Id := Identifier (ASN);
8948 A_Id : constant Aspect_Id := Get_Aspect_Id (Chars (Ident));
8950 End_Decl_Expr : constant Node_Id := Entity (Ident);
8951 -- Expression to be analyzed at end of declarations
8953 Freeze_Expr : constant Node_Id := Expression (ASN);
8954 -- Expression from call to Check_Aspect_At_Freeze_Point
8956 T : constant Entity_Id := Etype (Freeze_Expr);
8957 -- Type required for preanalyze call
8960 -- Set False if error
8962 -- On entry to this procedure, Entity (Ident) contains a copy of the
8963 -- original expression from the aspect, saved for this purpose, and
8964 -- but Expression (Ident) is a preanalyzed copy of the expression,
8965 -- preanalyzed just after the freeze point.
8967 procedure Check_Overloaded_Name;
8968 -- For aspects whose expression is simply a name, this routine checks if
8969 -- the name is overloaded or not. If so, it verifies there is an
8970 -- interpretation that matches the entity obtained at the freeze point,
8971 -- otherwise the compiler complains.
8973 ---------------------------
8974 -- Check_Overloaded_Name --
8975 ---------------------------
8977 procedure Check_Overloaded_Name is
8979 if not Is_Overloaded (End_Decl_Expr) then
8980 Err := not Is_Entity_Name (End_Decl_Expr)
8981 or else Entity (End_Decl_Expr) /= Entity (Freeze_Expr);
8987 Index : Interp_Index;
8991 Get_First_Interp (End_Decl_Expr, Index, It);
8992 while Present (It.Typ) loop
8993 if It.Nam = Entity (Freeze_Expr) then
8998 Get_Next_Interp (Index, It);
9002 end Check_Overloaded_Name;
9004 -- Start of processing for Check_Aspect_At_End_Of_Declarations
9007 -- In an instance we do not perform the consistency check between freeze
9008 -- point and end of declarations, because it was done already in the
9009 -- analysis of the generic. Furthermore, the delayed analysis of an
9010 -- aspect of the instance may produce spurious errors when the generic
9011 -- is a child unit that references entities in the parent (which might
9012 -- not be in scope at the freeze point of the instance).
9017 -- Case of aspects Dimension, Dimension_System and Synchronization
9019 elsif A_Id = Aspect_Synchronization then
9022 -- Case of stream attributes, just have to compare entities. However,
9023 -- the expression is just a name (possibly overloaded), and there may
9024 -- be stream operations declared for unrelated types, so we just need
9025 -- to verify that one of these interpretations is the one available at
9026 -- at the freeze point.
9028 elsif A_Id = Aspect_Input or else
9029 A_Id = Aspect_Output or else
9030 A_Id = Aspect_Read or else
9033 Analyze (End_Decl_Expr);
9034 Check_Overloaded_Name;
9036 elsif A_Id = Aspect_Variable_Indexing or else
9037 A_Id = Aspect_Constant_Indexing or else
9038 A_Id = Aspect_Default_Iterator or else
9039 A_Id = Aspect_Iterator_Element
9041 -- Make type unfrozen before analysis, to prevent spurious errors
9042 -- about late attributes.
9044 Set_Is_Frozen (Ent, False);
9045 Analyze (End_Decl_Expr);
9046 Set_Is_Frozen (Ent, True);
9048 -- If the end of declarations comes before any other freeze
9049 -- point, the Freeze_Expr is not analyzed: no check needed.
9051 if Analyzed (Freeze_Expr) and then not In_Instance then
9052 Check_Overloaded_Name;
9060 -- Indicate that the expression comes from an aspect specification,
9061 -- which is used in subsequent analysis even if expansion is off.
9063 Set_Parent (End_Decl_Expr, ASN);
9065 -- In a generic context the aspect expressions have not been
9066 -- preanalyzed, so do it now. There are no conformance checks
9067 -- to perform in this case.
9070 Check_Aspect_At_Freeze_Point (ASN);
9073 -- The default values attributes may be defined in the private part,
9074 -- and the analysis of the expression may take place when only the
9075 -- partial view is visible. The expression must be scalar, so use
9076 -- the full view to resolve.
9078 elsif (A_Id = Aspect_Default_Value
9080 A_Id = Aspect_Default_Component_Value)
9081 and then Is_Private_Type (T)
9083 Preanalyze_Spec_Expression (End_Decl_Expr, Full_View (T));
9086 Preanalyze_Spec_Expression (End_Decl_Expr, T);
9089 Err := not Fully_Conformant_Expressions (End_Decl_Expr, Freeze_Expr);
9092 -- Output error message if error. Force error on aspect specification
9093 -- even if there is an error on the expression itself.
9097 ("!visibility of aspect for& changes after freeze point",
9100 ("info: & is frozen here, aspects evaluated at this point??",
9101 Freeze_Node (Ent), Ent);
9103 end Check_Aspect_At_End_Of_Declarations;
9105 ----------------------------------
9106 -- Check_Aspect_At_Freeze_Point --
9107 ----------------------------------
9109 procedure Check_Aspect_At_Freeze_Point (ASN : Node_Id) is
9110 Ident : constant Node_Id := Identifier (ASN);
9111 -- Identifier (use Entity field to save expression)
9113 A_Id : constant Aspect_Id := Get_Aspect_Id (Chars (Ident));
9115 T : Entity_Id := Empty;
9116 -- Type required for preanalyze call
9119 -- On entry to this procedure, Entity (Ident) contains a copy of the
9120 -- original expression from the aspect, saved for this purpose.
9122 -- On exit from this procedure Entity (Ident) is unchanged, still
9123 -- containing that copy, but Expression (Ident) is a preanalyzed copy
9124 -- of the expression, preanalyzed just after the freeze point.
9126 -- Make a copy of the expression to be preanalyzed
9128 Set_Expression (ASN, New_Copy_Tree (Entity (Ident)));
9130 -- Find type for preanalyze call
9134 -- No_Aspect should be impossible
9137 raise Program_Error;
9139 -- Aspects taking an optional boolean argument
9141 when Boolean_Aspects |
9142 Library_Unit_Aspects =>
9144 T := Standard_Boolean;
9146 -- Aspects corresponding to attribute definition clauses
9148 when Aspect_Address =>
9149 T := RTE (RE_Address);
9151 when Aspect_Attach_Handler =>
9152 T := RTE (RE_Interrupt_ID);
9154 when Aspect_Bit_Order | Aspect_Scalar_Storage_Order =>
9155 T := RTE (RE_Bit_Order);
9157 when Aspect_Convention =>
9161 T := RTE (RE_CPU_Range);
9163 -- Default_Component_Value is resolved with the component type
9165 when Aspect_Default_Component_Value =>
9166 T := Component_Type (Entity (ASN));
9168 when Aspect_Default_Storage_Pool =>
9169 T := Class_Wide_Type (RTE (RE_Root_Storage_Pool));
9171 -- Default_Value is resolved with the type entity in question
9173 when Aspect_Default_Value =>
9176 when Aspect_Dispatching_Domain =>
9177 T := RTE (RE_Dispatching_Domain);
9179 when Aspect_External_Tag =>
9180 T := Standard_String;
9182 when Aspect_External_Name =>
9183 T := Standard_String;
9185 when Aspect_Link_Name =>
9186 T := Standard_String;
9188 when Aspect_Priority | Aspect_Interrupt_Priority =>
9189 T := Standard_Integer;
9191 when Aspect_Relative_Deadline =>
9192 T := RTE (RE_Time_Span);
9194 when Aspect_Secondary_Stack_Size =>
9195 T := Standard_Integer;
9197 when Aspect_Small =>
9198 T := Universal_Real;
9200 -- For a simple storage pool, we have to retrieve the type of the
9201 -- pool object associated with the aspect's corresponding attribute
9202 -- definition clause.
9204 when Aspect_Simple_Storage_Pool =>
9205 T := Etype (Expression (Aspect_Rep_Item (ASN)));
9207 when Aspect_Storage_Pool =>
9208 T := Class_Wide_Type (RTE (RE_Root_Storage_Pool));
9210 when Aspect_Alignment |
9211 Aspect_Component_Size |
9212 Aspect_Machine_Radix |
9213 Aspect_Object_Size |
9215 Aspect_Storage_Size |
9216 Aspect_Stream_Size |
9217 Aspect_Value_Size =>
9220 when Aspect_Linker_Section =>
9221 T := Standard_String;
9223 when Aspect_Synchronization =>
9226 -- Special case, the expression of these aspects is just an entity
9227 -- that does not need any resolution, so just analyze.
9236 Analyze (Expression (ASN));
9239 -- Same for Iterator aspects, where the expression is a function
9240 -- name. Legality rules are checked separately.
9242 when Aspect_Constant_Indexing |
9243 Aspect_Default_Iterator |
9244 Aspect_Iterator_Element |
9245 Aspect_Variable_Indexing =>
9246 Analyze (Expression (ASN));
9249 -- Ditto for Iterable, legality checks in Validate_Iterable_Aspect.
9251 when Aspect_Iterable =>
9255 Cursor : constant Entity_Id := Get_Cursor_Type (ASN, T);
9260 if Cursor = Any_Type then
9264 Assoc := First (Component_Associations (Expression (ASN)));
9265 while Present (Assoc) loop
9266 Expr := Expression (Assoc);
9269 if not Error_Posted (Expr) then
9270 Resolve_Iterable_Operation
9271 (Expr, Cursor, T, Chars (First (Choices (Assoc))));
9280 -- Invariant/Predicate take boolean expressions
9282 when Aspect_Dynamic_Predicate |
9285 Aspect_Static_Predicate |
9286 Aspect_Type_Invariant =>
9287 T := Standard_Boolean;
9289 when Aspect_Predicate_Failure =>
9290 T := Standard_String;
9292 -- Here is the list of aspects that don't require delay analysis
9294 when Aspect_Abstract_State |
9296 Aspect_Async_Readers |
9297 Aspect_Async_Writers |
9298 Aspect_Constant_After_Elaboration |
9299 Aspect_Contract_Cases |
9300 Aspect_Default_Initial_Condition |
9303 Aspect_Dimension_System |
9304 Aspect_Effective_Reads |
9305 Aspect_Effective_Writes |
9306 Aspect_Extensions_Visible |
9309 Aspect_Implicit_Dereference |
9310 Aspect_Initial_Condition |
9311 Aspect_Initializes |
9312 Aspect_Max_Queue_Length |
9313 Aspect_Obsolescent |
9316 Aspect_Postcondition |
9318 Aspect_Precondition |
9319 Aspect_Refined_Depends |
9320 Aspect_Refined_Global |
9321 Aspect_Refined_Post |
9322 Aspect_Refined_State |
9325 Aspect_Unimplemented |
9326 Aspect_Volatile_Function =>
9327 raise Program_Error;
9331 -- Do the preanalyze call
9333 Preanalyze_Spec_Expression (Expression (ASN), T);
9334 end Check_Aspect_At_Freeze_Point;
9336 -----------------------------------
9337 -- Check_Constant_Address_Clause --
9338 -----------------------------------
9340 procedure Check_Constant_Address_Clause
9344 procedure Check_At_Constant_Address (Nod : Node_Id);
9345 -- Checks that the given node N represents a name whose 'Address is
9346 -- constant (in the same sense as OK_Constant_Address_Clause, i.e. the
9347 -- address value is the same at the point of declaration of U_Ent and at
9348 -- the time of elaboration of the address clause.
9350 procedure Check_Expr_Constants (Nod : Node_Id);
9351 -- Checks that Nod meets the requirements for a constant address clause
9352 -- in the sense of the enclosing procedure.
9354 procedure Check_List_Constants (Lst : List_Id);
9355 -- Check that all elements of list Lst meet the requirements for a
9356 -- constant address clause in the sense of the enclosing procedure.
9358 -------------------------------
9359 -- Check_At_Constant_Address --
9360 -------------------------------
9362 procedure Check_At_Constant_Address (Nod : Node_Id) is
9364 if Is_Entity_Name (Nod) then
9365 if Present (Address_Clause (Entity ((Nod)))) then
9367 ("invalid address clause for initialized object &!",
9370 ("address for& cannot" &
9371 " depend on another address clause! (RM 13.1(22))!",
9374 elsif In_Same_Source_Unit (Entity (Nod), U_Ent)
9375 and then Sloc (U_Ent) < Sloc (Entity (Nod))
9378 ("invalid address clause for initialized object &!",
9380 Error_Msg_Node_2 := U_Ent;
9382 ("\& must be defined before & (RM 13.1(22))!",
9386 elsif Nkind (Nod) = N_Selected_Component then
9388 T : constant Entity_Id := Etype (Prefix (Nod));
9391 if (Is_Record_Type (T)
9392 and then Has_Discriminants (T))
9395 and then Is_Record_Type (Designated_Type (T))
9396 and then Has_Discriminants (Designated_Type (T)))
9399 ("invalid address clause for initialized object &!",
9402 ("\address cannot depend on component" &
9403 " of discriminated record (RM 13.1(22))!",
9406 Check_At_Constant_Address (Prefix (Nod));
9410 elsif Nkind (Nod) = N_Indexed_Component then
9411 Check_At_Constant_Address (Prefix (Nod));
9412 Check_List_Constants (Expressions (Nod));
9415 Check_Expr_Constants (Nod);
9417 end Check_At_Constant_Address;
9419 --------------------------
9420 -- Check_Expr_Constants --
9421 --------------------------
9423 procedure Check_Expr_Constants (Nod : Node_Id) is
9424 Loc_U_Ent : constant Source_Ptr := Sloc (U_Ent);
9425 Ent : Entity_Id := Empty;
9428 if Nkind (Nod) in N_Has_Etype
9429 and then Etype (Nod) = Any_Type
9435 when N_Empty | N_Error =>
9438 when N_Identifier | N_Expanded_Name =>
9439 Ent := Entity (Nod);
9441 -- We need to look at the original node if it is different
9442 -- from the node, since we may have rewritten things and
9443 -- substituted an identifier representing the rewrite.
9445 if Original_Node (Nod) /= Nod then
9446 Check_Expr_Constants (Original_Node (Nod));
9448 -- If the node is an object declaration without initial
9449 -- value, some code has been expanded, and the expression
9450 -- is not constant, even if the constituents might be
9451 -- acceptable, as in A'Address + offset.
9453 if Ekind (Ent) = E_Variable
9455 Nkind (Declaration_Node (Ent)) = N_Object_Declaration
9457 No (Expression (Declaration_Node (Ent)))
9460 ("invalid address clause for initialized object &!",
9463 -- If entity is constant, it may be the result of expanding
9464 -- a check. We must verify that its declaration appears
9465 -- before the object in question, else we also reject the
9468 elsif Ekind (Ent) = E_Constant
9469 and then In_Same_Source_Unit (Ent, U_Ent)
9470 and then Sloc (Ent) > Loc_U_Ent
9473 ("invalid address clause for initialized object &!",
9480 -- Otherwise look at the identifier and see if it is OK
9482 if Ekind_In (Ent, E_Named_Integer, E_Named_Real)
9483 or else Is_Type (Ent)
9487 elsif Ekind_In (Ent, E_Constant, E_In_Parameter) then
9489 -- This is the case where we must have Ent defined before
9490 -- U_Ent. Clearly if they are in different units this
9491 -- requirement is met since the unit containing Ent is
9492 -- already processed.
9494 if not In_Same_Source_Unit (Ent, U_Ent) then
9497 -- Otherwise location of Ent must be before the location
9498 -- of U_Ent, that's what prior defined means.
9500 elsif Sloc (Ent) < Loc_U_Ent then
9505 ("invalid address clause for initialized object &!",
9507 Error_Msg_Node_2 := U_Ent;
9509 ("\& must be defined before & (RM 13.1(22))!",
9513 elsif Nkind (Original_Node (Nod)) = N_Function_Call then
9514 Check_Expr_Constants (Original_Node (Nod));
9518 ("invalid address clause for initialized object &!",
9521 if Comes_From_Source (Ent) then
9523 ("\reference to variable& not allowed"
9524 & " (RM 13.1(22))!", Nod, Ent);
9527 ("non-static expression not allowed"
9528 & " (RM 13.1(22))!", Nod);
9532 when N_Integer_Literal =>
9534 -- If this is a rewritten unchecked conversion, in a system
9535 -- where Address is an integer type, always use the base type
9536 -- for a literal value. This is user-friendly and prevents
9537 -- order-of-elaboration issues with instances of unchecked
9540 if Nkind (Original_Node (Nod)) = N_Function_Call then
9541 Set_Etype (Nod, Base_Type (Etype (Nod)));
9544 when N_Real_Literal |
9546 N_Character_Literal =>
9550 Check_Expr_Constants (Low_Bound (Nod));
9551 Check_Expr_Constants (High_Bound (Nod));
9553 when N_Explicit_Dereference =>
9554 Check_Expr_Constants (Prefix (Nod));
9556 when N_Indexed_Component =>
9557 Check_Expr_Constants (Prefix (Nod));
9558 Check_List_Constants (Expressions (Nod));
9561 Check_Expr_Constants (Prefix (Nod));
9562 Check_Expr_Constants (Discrete_Range (Nod));
9564 when N_Selected_Component =>
9565 Check_Expr_Constants (Prefix (Nod));
9567 when N_Attribute_Reference =>
9568 if Nam_In (Attribute_Name (Nod), Name_Address,
9570 Name_Unchecked_Access,
9571 Name_Unrestricted_Access)
9573 Check_At_Constant_Address (Prefix (Nod));
9576 Check_Expr_Constants (Prefix (Nod));
9577 Check_List_Constants (Expressions (Nod));
9581 Check_List_Constants (Component_Associations (Nod));
9582 Check_List_Constants (Expressions (Nod));
9584 when N_Component_Association =>
9585 Check_Expr_Constants (Expression (Nod));
9587 when N_Extension_Aggregate =>
9588 Check_Expr_Constants (Ancestor_Part (Nod));
9589 Check_List_Constants (Component_Associations (Nod));
9590 Check_List_Constants (Expressions (Nod));
9595 when N_Binary_Op | N_Short_Circuit | N_Membership_Test =>
9596 Check_Expr_Constants (Left_Opnd (Nod));
9597 Check_Expr_Constants (Right_Opnd (Nod));
9600 Check_Expr_Constants (Right_Opnd (Nod));
9602 when N_Type_Conversion |
9603 N_Qualified_Expression |
9605 N_Unchecked_Type_Conversion =>
9606 Check_Expr_Constants (Expression (Nod));
9608 when N_Function_Call =>
9609 if not Is_Pure (Entity (Name (Nod))) then
9611 ("invalid address clause for initialized object &!",
9615 ("\function & is not pure (RM 13.1(22))!",
9616 Nod, Entity (Name (Nod)));
9619 Check_List_Constants (Parameter_Associations (Nod));
9622 when N_Parameter_Association =>
9623 Check_Expr_Constants (Explicit_Actual_Parameter (Nod));
9627 ("invalid address clause for initialized object &!",
9630 ("\must be constant defined before& (RM 13.1(22))!",
9633 end Check_Expr_Constants;
9635 --------------------------
9636 -- Check_List_Constants --
9637 --------------------------
9639 procedure Check_List_Constants (Lst : List_Id) is
9643 if Present (Lst) then
9644 Nod1 := First (Lst);
9645 while Present (Nod1) loop
9646 Check_Expr_Constants (Nod1);
9650 end Check_List_Constants;
9652 -- Start of processing for Check_Constant_Address_Clause
9655 -- If rep_clauses are to be ignored, no need for legality checks. In
9656 -- particular, no need to pester user about rep clauses that violate the
9657 -- rule on constant addresses, given that these clauses will be removed
9658 -- by Freeze before they reach the back end. Similarly in CodePeer mode,
9659 -- we want to relax these checks.
9661 if not Ignore_Rep_Clauses and not CodePeer_Mode then
9662 Check_Expr_Constants (Expr);
9664 end Check_Constant_Address_Clause;
9666 ---------------------------
9667 -- Check_Pool_Size_Clash --
9668 ---------------------------
9670 procedure Check_Pool_Size_Clash (Ent : Entity_Id; SP, SS : Node_Id) is
9674 -- We need to find out which one came first. Note that in the case of
9675 -- aspects mixed with pragmas there are cases where the processing order
9676 -- is reversed, which is why we do the check here.
9678 if Sloc (SP) < Sloc (SS) then
9679 Error_Msg_Sloc := Sloc (SP);
9681 Error_Msg_NE ("Storage_Pool previously given for&#", Post, Ent);
9684 Error_Msg_Sloc := Sloc (SS);
9686 Error_Msg_NE ("Storage_Size previously given for&#", Post, Ent);
9690 ("\cannot have Storage_Size and Storage_Pool (RM 13.11(3))", Post);
9691 end Check_Pool_Size_Clash;
9693 ----------------------------------------
9694 -- Check_Record_Representation_Clause --
9695 ----------------------------------------
9697 procedure Check_Record_Representation_Clause (N : Node_Id) is
9698 Loc : constant Source_Ptr := Sloc (N);
9699 Ident : constant Node_Id := Identifier (N);
9700 Rectype : Entity_Id;
9705 Hbit : Uint := Uint_0;
9709 Max_Bit_So_Far : Uint;
9710 -- Records the maximum bit position so far. If all field positions
9711 -- are monotonically increasing, then we can skip the circuit for
9712 -- checking for overlap, since no overlap is possible.
9714 Tagged_Parent : Entity_Id := Empty;
9715 -- This is set in the case of a derived tagged type for which we have
9716 -- Is_Fully_Repped_Tagged_Type True (indicating that all components are
9717 -- positioned by record representation clauses). In this case we must
9718 -- check for overlap between components of this tagged type, and the
9719 -- components of its parent. Tagged_Parent will point to this parent
9720 -- type. For all other cases Tagged_Parent is left set to Empty.
9722 Parent_Last_Bit : Uint;
9723 -- Relevant only if Tagged_Parent is set, Parent_Last_Bit indicates the
9724 -- last bit position for any field in the parent type. We only need to
9725 -- check overlap for fields starting below this point.
9727 Overlap_Check_Required : Boolean;
9728 -- Used to keep track of whether or not an overlap check is required
9730 Overlap_Detected : Boolean := False;
9731 -- Set True if an overlap is detected
9733 Ccount : Natural := 0;
9734 -- Number of component clauses in record rep clause
9736 procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id);
9737 -- Given two entities for record components or discriminants, checks
9738 -- if they have overlapping component clauses and issues errors if so.
9740 procedure Find_Component;
9741 -- Finds component entity corresponding to current component clause (in
9742 -- CC), and sets Comp to the entity, and Fbit/Lbit to the zero origin
9743 -- start/stop bits for the field. If there is no matching component or
9744 -- if the matching component does not have a component clause, then
9745 -- that's an error and Comp is set to Empty, but no error message is
9746 -- issued, since the message was already given. Comp is also set to
9747 -- Empty if the current "component clause" is in fact a pragma.
9749 -----------------------------
9750 -- Check_Component_Overlap --
9751 -----------------------------
9753 procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id) is
9754 CC1 : constant Node_Id := Component_Clause (C1_Ent);
9755 CC2 : constant Node_Id := Component_Clause (C2_Ent);
9758 if Present (CC1) and then Present (CC2) then
9760 -- Exclude odd case where we have two tag components in the same
9761 -- record, both at location zero. This seems a bit strange, but
9762 -- it seems to happen in some circumstances, perhaps on an error.
9764 if Nam_In (Chars (C1_Ent), Name_uTag, Name_uTag) then
9768 -- Here we check if the two fields overlap
9771 S1 : constant Uint := Component_Bit_Offset (C1_Ent);
9772 S2 : constant Uint := Component_Bit_Offset (C2_Ent);
9773 E1 : constant Uint := S1 + Esize (C1_Ent);
9774 E2 : constant Uint := S2 + Esize (C2_Ent);
9777 if E2 <= S1 or else E1 <= S2 then
9780 Error_Msg_Node_2 := Component_Name (CC2);
9781 Error_Msg_Sloc := Sloc (Error_Msg_Node_2);
9782 Error_Msg_Node_1 := Component_Name (CC1);
9784 ("component& overlaps & #", Component_Name (CC1));
9785 Overlap_Detected := True;
9789 end Check_Component_Overlap;
9791 --------------------
9792 -- Find_Component --
9793 --------------------
9795 procedure Find_Component is
9797 procedure Search_Component (R : Entity_Id);
9798 -- Search components of R for a match. If found, Comp is set
9800 ----------------------
9801 -- Search_Component --
9802 ----------------------
9804 procedure Search_Component (R : Entity_Id) is
9806 Comp := First_Component_Or_Discriminant (R);
9807 while Present (Comp) loop
9809 -- Ignore error of attribute name for component name (we
9810 -- already gave an error message for this, so no need to
9813 if Nkind (Component_Name (CC)) = N_Attribute_Reference then
9816 exit when Chars (Comp) = Chars (Component_Name (CC));
9819 Next_Component_Or_Discriminant (Comp);
9821 end Search_Component;
9823 -- Start of processing for Find_Component
9826 -- Return with Comp set to Empty if we have a pragma
9828 if Nkind (CC) = N_Pragma then
9833 -- Search current record for matching component
9835 Search_Component (Rectype);
9837 -- If not found, maybe component of base type discriminant that is
9838 -- absent from statically constrained first subtype.
9841 Search_Component (Base_Type (Rectype));
9844 -- If no component, or the component does not reference the component
9845 -- clause in question, then there was some previous error for which
9846 -- we already gave a message, so just return with Comp Empty.
9848 if No (Comp) or else Component_Clause (Comp) /= CC then
9849 Check_Error_Detected;
9852 -- Normal case where we have a component clause
9855 Fbit := Component_Bit_Offset (Comp);
9856 Lbit := Fbit + Esize (Comp) - 1;
9860 -- Start of processing for Check_Record_Representation_Clause
9864 Rectype := Entity (Ident);
9866 if Rectype = Any_Type then
9869 Rectype := Underlying_Type (Rectype);
9872 -- See if we have a fully repped derived tagged type
9875 PS : constant Entity_Id := Parent_Subtype (Rectype);
9878 if Present (PS) and then Is_Fully_Repped_Tagged_Type (PS) then
9879 Tagged_Parent := PS;
9881 -- Find maximum bit of any component of the parent type
9883 Parent_Last_Bit := UI_From_Int (System_Address_Size - 1);
9884 Pcomp := First_Entity (Tagged_Parent);
9885 while Present (Pcomp) loop
9886 if Ekind_In (Pcomp, E_Discriminant, E_Component) then
9887 if Component_Bit_Offset (Pcomp) /= No_Uint
9888 and then Known_Static_Esize (Pcomp)
9893 Component_Bit_Offset (Pcomp) + Esize (Pcomp) - 1);
9897 -- Skip anonymous types generated for constrained array
9898 -- or record components.
9903 Next_Entity (Pcomp);
9908 -- All done if no component clauses
9910 CC := First (Component_Clauses (N));
9916 -- If a tag is present, then create a component clause that places it
9917 -- at the start of the record (otherwise gigi may place it after other
9918 -- fields that have rep clauses).
9920 Fent := First_Entity (Rectype);
9922 if Nkind (Fent) = N_Defining_Identifier
9923 and then Chars (Fent) = Name_uTag
9925 Set_Component_Bit_Offset (Fent, Uint_0);
9926 Set_Normalized_Position (Fent, Uint_0);
9927 Set_Normalized_First_Bit (Fent, Uint_0);
9928 Set_Normalized_Position_Max (Fent, Uint_0);
9929 Init_Esize (Fent, System_Address_Size);
9931 Set_Component_Clause (Fent,
9932 Make_Component_Clause (Loc,
9933 Component_Name => Make_Identifier (Loc, Name_uTag),
9935 Position => Make_Integer_Literal (Loc, Uint_0),
9936 First_Bit => Make_Integer_Literal (Loc, Uint_0),
9938 Make_Integer_Literal (Loc,
9939 UI_From_Int (System_Address_Size))));
9941 Ccount := Ccount + 1;
9944 Max_Bit_So_Far := Uint_Minus_1;
9945 Overlap_Check_Required := False;
9947 -- Process the component clauses
9949 while Present (CC) loop
9952 if Present (Comp) then
9953 Ccount := Ccount + 1;
9955 -- We need a full overlap check if record positions non-monotonic
9957 if Fbit <= Max_Bit_So_Far then
9958 Overlap_Check_Required := True;
9961 Max_Bit_So_Far := Lbit;
9963 -- Check bit position out of range of specified size
9965 if Has_Size_Clause (Rectype)
9966 and then RM_Size (Rectype) <= Lbit
9969 ("bit number out of range of specified size",
9972 -- Check for overlap with tag component
9975 if Is_Tagged_Type (Rectype)
9976 and then Fbit < System_Address_Size
9979 ("component overlaps tag field of&",
9980 Component_Name (CC), Rectype);
9981 Overlap_Detected := True;
9989 -- Check parent overlap if component might overlap parent field
9991 if Present (Tagged_Parent) and then Fbit <= Parent_Last_Bit then
9992 Pcomp := First_Component_Or_Discriminant (Tagged_Parent);
9993 while Present (Pcomp) loop
9994 if not Is_Tag (Pcomp)
9995 and then Chars (Pcomp) /= Name_uParent
9997 Check_Component_Overlap (Comp, Pcomp);
10000 Next_Component_Or_Discriminant (Pcomp);
10008 -- Now that we have processed all the component clauses, check for
10009 -- overlap. We have to leave this till last, since the components can
10010 -- appear in any arbitrary order in the representation clause.
10012 -- We do not need this check if all specified ranges were monotonic,
10013 -- as recorded by Overlap_Check_Required being False at this stage.
10015 -- This first section checks if there are any overlapping entries at
10016 -- all. It does this by sorting all entries and then seeing if there are
10017 -- any overlaps. If there are none, then that is decisive, but if there
10018 -- are overlaps, they may still be OK (they may result from fields in
10019 -- different variants).
10021 if Overlap_Check_Required then
10022 Overlap_Check1 : declare
10024 OC_Fbit : array (0 .. Ccount) of Uint;
10025 -- First-bit values for component clauses, the value is the offset
10026 -- of the first bit of the field from start of record. The zero
10027 -- entry is for use in sorting.
10029 OC_Lbit : array (0 .. Ccount) of Uint;
10030 -- Last-bit values for component clauses, the value is the offset
10031 -- of the last bit of the field from start of record. The zero
10032 -- entry is for use in sorting.
10034 OC_Count : Natural := 0;
10035 -- Count of entries in OC_Fbit and OC_Lbit
10037 function OC_Lt (Op1, Op2 : Natural) return Boolean;
10038 -- Compare routine for Sort
10040 procedure OC_Move (From : Natural; To : Natural);
10041 -- Move routine for Sort
10043 package Sorting is new GNAT.Heap_Sort_G (OC_Move, OC_Lt);
10049 function OC_Lt (Op1, Op2 : Natural) return Boolean is
10051 return OC_Fbit (Op1) < OC_Fbit (Op2);
10058 procedure OC_Move (From : Natural; To : Natural) is
10060 OC_Fbit (To) := OC_Fbit (From);
10061 OC_Lbit (To) := OC_Lbit (From);
10064 -- Start of processing for Overlap_Check
10067 CC := First (Component_Clauses (N));
10068 while Present (CC) loop
10070 -- Exclude component clause already marked in error
10072 if not Error_Posted (CC) then
10075 if Present (Comp) then
10076 OC_Count := OC_Count + 1;
10077 OC_Fbit (OC_Count) := Fbit;
10078 OC_Lbit (OC_Count) := Lbit;
10085 Sorting.Sort (OC_Count);
10087 Overlap_Check_Required := False;
10088 for J in 1 .. OC_Count - 1 loop
10089 if OC_Lbit (J) >= OC_Fbit (J + 1) then
10090 Overlap_Check_Required := True;
10094 end Overlap_Check1;
10097 -- If Overlap_Check_Required is still True, then we have to do the full
10098 -- scale overlap check, since we have at least two fields that do
10099 -- overlap, and we need to know if that is OK since they are in
10100 -- different variant, or whether we have a definite problem.
10102 if Overlap_Check_Required then
10103 Overlap_Check2 : declare
10104 C1_Ent, C2_Ent : Entity_Id;
10105 -- Entities of components being checked for overlap
10108 -- Component_List node whose Component_Items are being checked
10111 -- Component declaration for component being checked
10114 C1_Ent := First_Entity (Base_Type (Rectype));
10116 -- Loop through all components in record. For each component check
10117 -- for overlap with any of the preceding elements on the component
10118 -- list containing the component and also, if the component is in
10119 -- a variant, check against components outside the case structure.
10120 -- This latter test is repeated recursively up the variant tree.
10122 Main_Component_Loop : while Present (C1_Ent) loop
10123 if not Ekind_In (C1_Ent, E_Component, E_Discriminant) then
10124 goto Continue_Main_Component_Loop;
10127 -- Skip overlap check if entity has no declaration node. This
10128 -- happens with discriminants in constrained derived types.
10129 -- Possibly we are missing some checks as a result, but that
10130 -- does not seem terribly serious.
10132 if No (Declaration_Node (C1_Ent)) then
10133 goto Continue_Main_Component_Loop;
10136 Clist := Parent (List_Containing (Declaration_Node (C1_Ent)));
10138 -- Loop through component lists that need checking. Check the
10139 -- current component list and all lists in variants above us.
10141 Component_List_Loop : loop
10143 -- If derived type definition, go to full declaration
10144 -- If at outer level, check discriminants if there are any.
10146 if Nkind (Clist) = N_Derived_Type_Definition then
10147 Clist := Parent (Clist);
10150 -- Outer level of record definition, check discriminants
10152 if Nkind_In (Clist, N_Full_Type_Declaration,
10153 N_Private_Type_Declaration)
10155 if Has_Discriminants (Defining_Identifier (Clist)) then
10157 First_Discriminant (Defining_Identifier (Clist));
10158 while Present (C2_Ent) loop
10159 exit when C1_Ent = C2_Ent;
10160 Check_Component_Overlap (C1_Ent, C2_Ent);
10161 Next_Discriminant (C2_Ent);
10165 -- Record extension case
10167 elsif Nkind (Clist) = N_Derived_Type_Definition then
10170 -- Otherwise check one component list
10173 Citem := First (Component_Items (Clist));
10174 while Present (Citem) loop
10175 if Nkind (Citem) = N_Component_Declaration then
10176 C2_Ent := Defining_Identifier (Citem);
10177 exit when C1_Ent = C2_Ent;
10178 Check_Component_Overlap (C1_Ent, C2_Ent);
10185 -- Check for variants above us (the parent of the Clist can
10186 -- be a variant, in which case its parent is a variant part,
10187 -- and the parent of the variant part is a component list
10188 -- whose components must all be checked against the current
10189 -- component for overlap).
10191 if Nkind (Parent (Clist)) = N_Variant then
10192 Clist := Parent (Parent (Parent (Clist)));
10194 -- Check for possible discriminant part in record, this
10195 -- is treated essentially as another level in the
10196 -- recursion. For this case the parent of the component
10197 -- list is the record definition, and its parent is the
10198 -- full type declaration containing the discriminant
10201 elsif Nkind (Parent (Clist)) = N_Record_Definition then
10202 Clist := Parent (Parent ((Clist)));
10204 -- If neither of these two cases, we are at the top of
10208 exit Component_List_Loop;
10210 end loop Component_List_Loop;
10212 <<Continue_Main_Component_Loop>>
10213 Next_Entity (C1_Ent);
10215 end loop Main_Component_Loop;
10216 end Overlap_Check2;
10219 -- The following circuit deals with warning on record holes (gaps). We
10220 -- skip this check if overlap was detected, since it makes sense for the
10221 -- programmer to fix this illegality before worrying about warnings.
10223 if not Overlap_Detected and Warn_On_Record_Holes then
10224 Record_Hole_Check : declare
10225 Decl : constant Node_Id := Declaration_Node (Base_Type (Rectype));
10226 -- Full declaration of record type
10228 procedure Check_Component_List
10232 -- Check component list CL for holes. The starting bit should be
10233 -- Sbit. which is zero for the main record component list and set
10234 -- appropriately for recursive calls for variants. DS is set to
10235 -- a list of discriminant specifications to be included in the
10236 -- consideration of components. It is No_List if none to consider.
10238 --------------------------
10239 -- Check_Component_List --
10240 --------------------------
10242 procedure Check_Component_List
10250 Compl := Integer (List_Length (Component_Items (CL)));
10252 if DS /= No_List then
10253 Compl := Compl + Integer (List_Length (DS));
10257 Comps : array (Natural range 0 .. Compl) of Entity_Id;
10258 -- Gather components (zero entry is for sort routine)
10260 Ncomps : Natural := 0;
10261 -- Number of entries stored in Comps (starting at Comps (1))
10264 -- One component item or discriminant specification
10267 -- Starting bit for next component
10270 -- Component entity
10275 function Lt (Op1, Op2 : Natural) return Boolean;
10276 -- Compare routine for Sort
10278 procedure Move (From : Natural; To : Natural);
10279 -- Move routine for Sort
10281 package Sorting is new GNAT.Heap_Sort_G (Move, Lt);
10287 function Lt (Op1, Op2 : Natural) return Boolean is
10289 return Component_Bit_Offset (Comps (Op1))
10291 Component_Bit_Offset (Comps (Op2));
10298 procedure Move (From : Natural; To : Natural) is
10300 Comps (To) := Comps (From);
10304 -- Gather discriminants into Comp
10306 if DS /= No_List then
10307 Citem := First (DS);
10308 while Present (Citem) loop
10309 if Nkind (Citem) = N_Discriminant_Specification then
10311 Ent : constant Entity_Id :=
10312 Defining_Identifier (Citem);
10314 if Ekind (Ent) = E_Discriminant then
10315 Ncomps := Ncomps + 1;
10316 Comps (Ncomps) := Ent;
10325 -- Gather component entities into Comp
10327 Citem := First (Component_Items (CL));
10328 while Present (Citem) loop
10329 if Nkind (Citem) = N_Component_Declaration then
10330 Ncomps := Ncomps + 1;
10331 Comps (Ncomps) := Defining_Identifier (Citem);
10337 -- Now sort the component entities based on the first bit.
10338 -- Note we already know there are no overlapping components.
10340 Sorting.Sort (Ncomps);
10342 -- Loop through entries checking for holes
10345 for J in 1 .. Ncomps loop
10347 Error_Msg_Uint_1 := Component_Bit_Offset (CEnt) - Nbit;
10349 if Error_Msg_Uint_1 > 0 then
10351 ("?H?^-bit gap before component&",
10352 Component_Name (Component_Clause (CEnt)), CEnt);
10355 Nbit := Component_Bit_Offset (CEnt) + Esize (CEnt);
10358 -- Process variant parts recursively if present
10360 if Present (Variant_Part (CL)) then
10361 Variant := First (Variants (Variant_Part (CL)));
10362 while Present (Variant) loop
10363 Check_Component_List
10364 (Component_List (Variant), Nbit, No_List);
10369 end Check_Component_List;
10371 -- Start of processing for Record_Hole_Check
10378 if Is_Tagged_Type (Rectype) then
10379 Sbit := UI_From_Int (System_Address_Size);
10384 if Nkind (Decl) = N_Full_Type_Declaration
10385 and then Nkind (Type_Definition (Decl)) = N_Record_Definition
10387 Check_Component_List
10388 (Component_List (Type_Definition (Decl)),
10390 Discriminant_Specifications (Decl));
10393 end Record_Hole_Check;
10396 -- For records that have component clauses for all components, and whose
10397 -- size is less than or equal to 32, we need to know the size in the
10398 -- front end to activate possible packed array processing where the
10399 -- component type is a record.
10401 -- At this stage Hbit + 1 represents the first unused bit from all the
10402 -- component clauses processed, so if the component clauses are
10403 -- complete, then this is the length of the record.
10405 -- For records longer than System.Storage_Unit, and for those where not
10406 -- all components have component clauses, the back end determines the
10407 -- length (it may for example be appropriate to round up the size
10408 -- to some convenient boundary, based on alignment considerations, etc).
10410 if Unknown_RM_Size (Rectype) and then Hbit + 1 <= 32 then
10412 -- Nothing to do if at least one component has no component clause
10414 Comp := First_Component_Or_Discriminant (Rectype);
10415 while Present (Comp) loop
10416 exit when No (Component_Clause (Comp));
10417 Next_Component_Or_Discriminant (Comp);
10420 -- If we fall out of loop, all components have component clauses
10421 -- and so we can set the size to the maximum value.
10424 Set_RM_Size (Rectype, Hbit + 1);
10427 end Check_Record_Representation_Clause;
10433 procedure Check_Size
10437 Biased : out Boolean)
10439 procedure Size_Too_Small_Error (Min_Siz : Uint);
10440 -- Emit an error concerning illegal size Siz. Min_Siz denotes the
10443 --------------------------
10444 -- Size_Too_Small_Error --
10445 --------------------------
10447 procedure Size_Too_Small_Error (Min_Siz : Uint) is
10449 -- This error is suppressed in ASIS mode to allow for different ASIS
10450 -- back ends or ASIS-based tools to query the illegal clause.
10452 if not ASIS_Mode then
10453 Error_Msg_Uint_1 := Min_Siz;
10454 Error_Msg_NE ("size for& too small, minimum allowed is ^", N, T);
10456 end Size_Too_Small_Error;
10460 UT : constant Entity_Id := Underlying_Type (T);
10463 -- Start of processing for Check_Size
10468 -- Reject patently improper size values
10470 if Is_Elementary_Type (T)
10471 and then Siz > UI_From_Int (Int'Last)
10473 Error_Msg_N ("Size value too large for elementary type", N);
10475 if Nkind (Original_Node (N)) = N_Op_Expon then
10477 ("\maybe '* was meant, rather than '*'*", Original_Node (N));
10481 -- Dismiss generic types
10483 if Is_Generic_Type (T)
10485 Is_Generic_Type (UT)
10487 Is_Generic_Type (Root_Type (UT))
10491 -- Guard against previous errors
10493 elsif No (UT) or else UT = Any_Type then
10494 Check_Error_Detected;
10497 -- Check case of bit packed array
10499 elsif Is_Array_Type (UT)
10500 and then Known_Static_Component_Size (UT)
10501 and then Is_Bit_Packed_Array (UT)
10509 Asiz := Component_Size (UT);
10510 Indx := First_Index (UT);
10512 Ityp := Etype (Indx);
10514 -- If non-static bound, then we are not in the business of
10515 -- trying to check the length, and indeed an error will be
10516 -- issued elsewhere, since sizes of non-static array types
10517 -- cannot be set implicitly or explicitly.
10519 if not Is_OK_Static_Subtype (Ityp) then
10523 -- Otherwise accumulate next dimension
10525 Asiz := Asiz * (Expr_Value (Type_High_Bound (Ityp)) -
10526 Expr_Value (Type_Low_Bound (Ityp)) +
10530 exit when No (Indx);
10533 if Asiz <= Siz then
10537 Size_Too_Small_Error (Asiz);
10538 Set_Esize (T, Asiz);
10539 Set_RM_Size (T, Asiz);
10543 -- All other composite types are ignored
10545 elsif Is_Composite_Type (UT) then
10548 -- For fixed-point types, don't check minimum if type is not frozen,
10549 -- since we don't know all the characteristics of the type that can
10550 -- affect the size (e.g. a specified small) till freeze time.
10552 elsif Is_Fixed_Point_Type (UT) and then not Is_Frozen (UT) then
10555 -- Cases for which a minimum check is required
10558 -- Ignore if specified size is correct for the type
10560 if Known_Esize (UT) and then Siz = Esize (UT) then
10564 -- Otherwise get minimum size
10566 M := UI_From_Int (Minimum_Size (UT));
10570 -- Size is less than minimum size, but one possibility remains
10571 -- that we can manage with the new size if we bias the type.
10573 M := UI_From_Int (Minimum_Size (UT, Biased => True));
10576 Size_Too_Small_Error (M);
10578 Set_RM_Size (T, M);
10586 --------------------------
10587 -- Freeze_Entity_Checks --
10588 --------------------------
10590 procedure Freeze_Entity_Checks (N : Node_Id) is
10591 procedure Hide_Non_Overridden_Subprograms (Typ : Entity_Id);
10592 -- Inspect the primitive operations of type Typ and hide all pairs of
10593 -- implicitly declared non-overridden non-fully conformant homographs
10594 -- (Ada RM 8.3 12.3/2).
10596 -------------------------------------
10597 -- Hide_Non_Overridden_Subprograms --
10598 -------------------------------------
10600 procedure Hide_Non_Overridden_Subprograms (Typ : Entity_Id) is
10601 procedure Hide_Matching_Homographs
10602 (Subp_Id : Entity_Id;
10603 Start_Elmt : Elmt_Id);
10604 -- Inspect a list of primitive operations starting with Start_Elmt
10605 -- and find matching implicitly declared non-overridden non-fully
10606 -- conformant homographs of Subp_Id. If found, all matches along
10607 -- with Subp_Id are hidden from all visibility.
10609 function Is_Non_Overridden_Or_Null_Procedure
10610 (Subp_Id : Entity_Id) return Boolean;
10611 -- Determine whether subprogram Subp_Id is implicitly declared non-
10612 -- overridden subprogram or an implicitly declared null procedure.
10614 ------------------------------
10615 -- Hide_Matching_Homographs --
10616 ------------------------------
10618 procedure Hide_Matching_Homographs
10619 (Subp_Id : Entity_Id;
10620 Start_Elmt : Elmt_Id)
10623 Prim_Elmt : Elmt_Id;
10626 Prim_Elmt := Start_Elmt;
10627 while Present (Prim_Elmt) loop
10628 Prim := Node (Prim_Elmt);
10630 -- The current primitive is implicitly declared non-overridden
10631 -- non-fully conformant homograph of Subp_Id. Both subprograms
10632 -- must be hidden from visibility.
10634 if Chars (Prim) = Chars (Subp_Id)
10635 and then Is_Non_Overridden_Or_Null_Procedure (Prim)
10636 and then not Fully_Conformant (Prim, Subp_Id)
10638 Set_Is_Hidden_Non_Overridden_Subpgm (Prim);
10639 Set_Is_Immediately_Visible (Prim, False);
10640 Set_Is_Potentially_Use_Visible (Prim, False);
10642 Set_Is_Hidden_Non_Overridden_Subpgm (Subp_Id);
10643 Set_Is_Immediately_Visible (Subp_Id, False);
10644 Set_Is_Potentially_Use_Visible (Subp_Id, False);
10647 Next_Elmt (Prim_Elmt);
10649 end Hide_Matching_Homographs;
10651 -----------------------------------------
10652 -- Is_Non_Overridden_Or_Null_Procedure --
10653 -----------------------------------------
10655 function Is_Non_Overridden_Or_Null_Procedure
10656 (Subp_Id : Entity_Id) return Boolean
10658 Alias_Id : Entity_Id;
10661 -- The subprogram is inherited (implicitly declared), it does not
10662 -- override and does not cover a primitive of an interface.
10664 if Ekind_In (Subp_Id, E_Function, E_Procedure)
10665 and then Present (Alias (Subp_Id))
10666 and then No (Interface_Alias (Subp_Id))
10667 and then No (Overridden_Operation (Subp_Id))
10669 Alias_Id := Alias (Subp_Id);
10671 if Requires_Overriding (Alias_Id) then
10674 elsif Nkind (Parent (Alias_Id)) = N_Procedure_Specification
10675 and then Null_Present (Parent (Alias_Id))
10682 end Is_Non_Overridden_Or_Null_Procedure;
10686 Prim_Ops : constant Elist_Id := Direct_Primitive_Operations (Typ);
10688 Prim_Elmt : Elmt_Id;
10690 -- Start of processing for Hide_Non_Overridden_Subprograms
10693 -- Inspect the list of primitives looking for non-overridden
10696 if Present (Prim_Ops) then
10697 Prim_Elmt := First_Elmt (Prim_Ops);
10698 while Present (Prim_Elmt) loop
10699 Prim := Node (Prim_Elmt);
10700 Next_Elmt (Prim_Elmt);
10702 if Is_Non_Overridden_Or_Null_Procedure (Prim) then
10703 Hide_Matching_Homographs
10705 Start_Elmt => Prim_Elmt);
10709 end Hide_Non_Overridden_Subprograms;
10713 E : constant Entity_Id := Entity (N);
10715 Non_Generic_Case : constant Boolean := Nkind (N) = N_Freeze_Entity;
10716 -- True in non-generic case. Some of the processing here is skipped
10717 -- for the generic case since it is not needed. Basically in the
10718 -- generic case, we only need to do stuff that might generate error
10719 -- messages or warnings.
10721 -- Start of processing for Freeze_Entity_Checks
10724 -- Remember that we are processing a freezing entity. Required to
10725 -- ensure correct decoration of internal entities associated with
10726 -- interfaces (see New_Overloaded_Entity).
10728 Inside_Freezing_Actions := Inside_Freezing_Actions + 1;
10730 -- For tagged types covering interfaces add internal entities that link
10731 -- the primitives of the interfaces with the primitives that cover them.
10732 -- Note: These entities were originally generated only when generating
10733 -- code because their main purpose was to provide support to initialize
10734 -- the secondary dispatch tables. They are now generated also when
10735 -- compiling with no code generation to provide ASIS the relationship
10736 -- between interface primitives and tagged type primitives. They are
10737 -- also used to locate primitives covering interfaces when processing
10738 -- generics (see Derive_Subprograms).
10740 -- This is not needed in the generic case
10742 if Ada_Version >= Ada_2005
10743 and then Non_Generic_Case
10744 and then Ekind (E) = E_Record_Type
10745 and then Is_Tagged_Type (E)
10746 and then not Is_Interface (E)
10747 and then Has_Interfaces (E)
10749 -- This would be a good common place to call the routine that checks
10750 -- overriding of interface primitives (and thus factorize calls to
10751 -- Check_Abstract_Overriding located at different contexts in the
10752 -- compiler). However, this is not possible because it causes
10753 -- spurious errors in case of late overriding.
10755 Add_Internal_Interface_Entities (E);
10758 -- After all forms of overriding have been resolved, a tagged type may
10759 -- be left with a set of implicitly declared and possibly erroneous
10760 -- abstract subprograms, null procedures and subprograms that require
10761 -- overriding. If this set contains fully conformant homographs, then
10762 -- one is chosen arbitrarily (already done during resolution), otherwise
10763 -- all remaining non-fully conformant homographs are hidden from
10764 -- visibility (Ada RM 8.3 12.3/2).
10766 if Is_Tagged_Type (E) then
10767 Hide_Non_Overridden_Subprograms (E);
10772 if Ekind (E) = E_Record_Type
10773 and then Is_CPP_Class (E)
10774 and then Is_Tagged_Type (E)
10775 and then Tagged_Type_Expansion
10777 if CPP_Num_Prims (E) = 0 then
10779 -- If the CPP type has user defined components then it must import
10780 -- primitives from C++. This is required because if the C++ class
10781 -- has no primitives then the C++ compiler does not added the _tag
10782 -- component to the type.
10784 if First_Entity (E) /= Last_Entity (E) then
10786 ("'C'P'P type must import at least one primitive from C++??",
10791 -- Check that all its primitives are abstract or imported from C++.
10792 -- Check also availability of the C++ constructor.
10795 Has_Constructors : constant Boolean := Has_CPP_Constructors (E);
10797 Error_Reported : Boolean := False;
10801 Elmt := First_Elmt (Primitive_Operations (E));
10802 while Present (Elmt) loop
10803 Prim := Node (Elmt);
10805 if Comes_From_Source (Prim) then
10806 if Is_Abstract_Subprogram (Prim) then
10809 elsif not Is_Imported (Prim)
10810 or else Convention (Prim) /= Convention_CPP
10813 ("primitives of 'C'P'P types must be imported from C++ "
10814 & "or abstract??", Prim);
10816 elsif not Has_Constructors
10817 and then not Error_Reported
10819 Error_Msg_Name_1 := Chars (E);
10821 ("??'C'P'P constructor required for type %", Prim);
10822 Error_Reported := True;
10831 -- Check Ada derivation of CPP type
10833 if Expander_Active -- why? losing errors in -gnatc mode???
10834 and then Present (Etype (E)) -- defend against errors
10835 and then Tagged_Type_Expansion
10836 and then Ekind (E) = E_Record_Type
10837 and then Etype (E) /= E
10838 and then Is_CPP_Class (Etype (E))
10839 and then CPP_Num_Prims (Etype (E)) > 0
10840 and then not Is_CPP_Class (E)
10841 and then not Has_CPP_Constructors (Etype (E))
10843 -- If the parent has C++ primitives but it has no constructor then
10844 -- check that all the primitives are overridden in this derivation;
10845 -- otherwise the constructor of the parent is needed to build the
10853 Elmt := First_Elmt (Primitive_Operations (E));
10854 while Present (Elmt) loop
10855 Prim := Node (Elmt);
10857 if not Is_Abstract_Subprogram (Prim)
10858 and then No (Interface_Alias (Prim))
10859 and then Find_Dispatching_Type (Ultimate_Alias (Prim)) /= E
10861 Error_Msg_Name_1 := Chars (Etype (E));
10863 ("'C'P'P constructor required for parent type %", E);
10872 Inside_Freezing_Actions := Inside_Freezing_Actions - 1;
10874 -- If we have a type with predicates, build predicate function. This is
10875 -- not needed in the generic case, nor within TSS subprograms and other
10876 -- predefined primitives.
10879 and then Non_Generic_Case
10880 and then not Within_Internal_Subprogram
10881 and then Has_Predicates (E)
10883 Build_Predicate_Functions (E, N);
10886 -- If type has delayed aspects, this is where we do the preanalysis at
10887 -- the freeze point, as part of the consistent visibility check. Note
10888 -- that this must be done after calling Build_Predicate_Functions or
10889 -- Build_Invariant_Procedure since these subprograms fix occurrences of
10890 -- the subtype name in the saved expression so that they will not cause
10891 -- trouble in the preanalysis.
10893 -- This is also not needed in the generic case
10895 if Non_Generic_Case
10896 and then Has_Delayed_Aspects (E)
10897 and then Scope (E) = Current_Scope
10899 -- Retrieve the visibility to the discriminants in order to properly
10900 -- analyze the aspects.
10902 Push_Scope_And_Install_Discriminants (E);
10908 -- Look for aspect specification entries for this entity
10910 Ritem := First_Rep_Item (E);
10911 while Present (Ritem) loop
10912 if Nkind (Ritem) = N_Aspect_Specification
10913 and then Entity (Ritem) = E
10914 and then Is_Delayed_Aspect (Ritem)
10916 Check_Aspect_At_Freeze_Point (Ritem);
10919 Next_Rep_Item (Ritem);
10923 Uninstall_Discriminants_And_Pop_Scope (E);
10926 -- For a record type, deal with variant parts. This has to be delayed
10927 -- to this point, because of the issue of statically predicated
10928 -- subtypes, which we have to ensure are frozen before checking
10929 -- choices, since we need to have the static choice list set.
10931 if Is_Record_Type (E) then
10932 Check_Variant_Part : declare
10933 D : constant Node_Id := Declaration_Node (E);
10938 Others_Present : Boolean;
10939 pragma Warnings (Off, Others_Present);
10940 -- Indicates others present, not used in this case
10942 procedure Non_Static_Choice_Error (Choice : Node_Id);
10943 -- Error routine invoked by the generic instantiation below when
10944 -- the variant part has a non static choice.
10946 procedure Process_Declarations (Variant : Node_Id);
10947 -- Processes declarations associated with a variant. We analyzed
10948 -- the declarations earlier (in Sem_Ch3.Analyze_Variant_Part),
10949 -- but we still need the recursive call to Check_Choices for any
10950 -- nested variant to get its choices properly processed. This is
10951 -- also where we expand out the choices if expansion is active.
10953 package Variant_Choices_Processing is new
10954 Generic_Check_Choices
10955 (Process_Empty_Choice => No_OP,
10956 Process_Non_Static_Choice => Non_Static_Choice_Error,
10957 Process_Associated_Node => Process_Declarations);
10958 use Variant_Choices_Processing;
10960 -----------------------------
10961 -- Non_Static_Choice_Error --
10962 -----------------------------
10964 procedure Non_Static_Choice_Error (Choice : Node_Id) is
10966 Flag_Non_Static_Expr
10967 ("choice given in variant part is not static!", Choice);
10968 end Non_Static_Choice_Error;
10970 --------------------------
10971 -- Process_Declarations --
10972 --------------------------
10974 procedure Process_Declarations (Variant : Node_Id) is
10975 CL : constant Node_Id := Component_List (Variant);
10979 -- Check for static predicate present in this variant
10981 if Has_SP_Choice (Variant) then
10983 -- Here we expand. You might expect to find this call in
10984 -- Expand_N_Variant_Part, but that is called when we first
10985 -- see the variant part, and we cannot do this expansion
10986 -- earlier than the freeze point, since for statically
10987 -- predicated subtypes, the predicate is not known till
10988 -- the freeze point.
10990 -- Furthermore, we do this expansion even if the expander
10991 -- is not active, because other semantic processing, e.g.
10992 -- for aggregates, requires the expanded list of choices.
10994 -- If the expander is not active, then we can't just clobber
10995 -- the list since it would invalidate the ASIS -gnatct tree.
10996 -- So we have to rewrite the variant part with a Rewrite
10997 -- call that replaces it with a copy and clobber the copy.
10999 if not Expander_Active then
11001 NewV : constant Node_Id := New_Copy (Variant);
11003 Set_Discrete_Choices
11004 (NewV, New_Copy_List (Discrete_Choices (Variant)));
11005 Rewrite (Variant, NewV);
11009 Expand_Static_Predicates_In_Choices (Variant);
11012 -- We don't need to worry about the declarations in the variant
11013 -- (since they were analyzed by Analyze_Choices when we first
11014 -- encountered the variant), but we do need to take care of
11015 -- expansion of any nested variants.
11017 if not Null_Present (CL) then
11018 VP := Variant_Part (CL);
11020 if Present (VP) then
11022 (VP, Variants (VP), Etype (Name (VP)), Others_Present);
11025 end Process_Declarations;
11027 -- Start of processing for Check_Variant_Part
11030 -- Find component list
11034 if Nkind (D) = N_Full_Type_Declaration then
11035 T := Type_Definition (D);
11037 if Nkind (T) = N_Record_Definition then
11038 C := Component_List (T);
11040 elsif Nkind (T) = N_Derived_Type_Definition
11041 and then Present (Record_Extension_Part (T))
11043 C := Component_List (Record_Extension_Part (T));
11047 -- Case of variant part present
11049 if Present (C) and then Present (Variant_Part (C)) then
11050 VP := Variant_Part (C);
11055 (VP, Variants (VP), Etype (Name (VP)), Others_Present);
11057 -- If the last variant does not contain the Others choice,
11058 -- replace it with an N_Others_Choice node since Gigi always
11059 -- wants an Others. Note that we do not bother to call Analyze
11060 -- on the modified variant part, since its only effect would be
11061 -- to compute the Others_Discrete_Choices node laboriously, and
11062 -- of course we already know the list of choices corresponding
11063 -- to the others choice (it's the list we're replacing).
11065 -- We only want to do this if the expander is active, since
11066 -- we do not want to clobber the ASIS tree.
11068 if Expander_Active then
11070 Last_Var : constant Node_Id :=
11071 Last_Non_Pragma (Variants (VP));
11073 Others_Node : Node_Id;
11076 if Nkind (First (Discrete_Choices (Last_Var))) /=
11079 Others_Node := Make_Others_Choice (Sloc (Last_Var));
11080 Set_Others_Discrete_Choices
11081 (Others_Node, Discrete_Choices (Last_Var));
11082 Set_Discrete_Choices
11083 (Last_Var, New_List (Others_Node));
11088 end Check_Variant_Part;
11090 end Freeze_Entity_Checks;
11092 -------------------------
11093 -- Get_Alignment_Value --
11094 -------------------------
11096 function Get_Alignment_Value (Expr : Node_Id) return Uint is
11097 Align : constant Uint := Static_Integer (Expr);
11100 if Align = No_Uint then
11103 elsif Align <= 0 then
11105 -- This error is suppressed in ASIS mode to allow for different ASIS
11106 -- back ends or ASIS-based tools to query the illegal clause.
11108 if not ASIS_Mode then
11109 Error_Msg_N ("alignment value must be positive", Expr);
11115 for J in Int range 0 .. 64 loop
11117 M : constant Uint := Uint_2 ** J;
11120 exit when M = Align;
11124 -- This error is suppressed in ASIS mode to allow for
11125 -- different ASIS back ends or ASIS-based tools to query the
11128 if not ASIS_Mode then
11129 Error_Msg_N ("alignment value must be power of 2", Expr);
11139 end Get_Alignment_Value;
11141 -----------------------------
11142 -- Get_Interfacing_Aspects --
11143 -----------------------------
11145 procedure Get_Interfacing_Aspects
11146 (Iface_Asp : Node_Id;
11147 Conv_Asp : out Node_Id;
11148 EN_Asp : out Node_Id;
11149 Expo_Asp : out Node_Id;
11150 Imp_Asp : out Node_Id;
11151 LN_Asp : out Node_Id;
11152 Do_Checks : Boolean := False)
11154 procedure Save_Or_Duplication_Error
11156 To : in out Node_Id);
11157 -- Save the value of aspect Asp in node To. If To already has a value,
11158 -- then this is considered a duplicate use of aspect. Emit an error if
11159 -- flag Do_Checks is set.
11161 -------------------------------
11162 -- Save_Or_Duplication_Error --
11163 -------------------------------
11165 procedure Save_Or_Duplication_Error
11167 To : in out Node_Id)
11170 -- Detect an extra aspect and issue an error
11172 if Present (To) then
11174 Error_Msg_Name_1 := Chars (Identifier (Asp));
11175 Error_Msg_Sloc := Sloc (To);
11176 Error_Msg_N ("aspect % previously given #", Asp);
11179 -- Otherwise capture the aspect
11184 end Save_Or_Duplication_Error;
11189 Asp_Id : Aspect_Id;
11191 -- The following variables capture each individual aspect
11193 Conv : Node_Id := Empty;
11194 EN : Node_Id := Empty;
11195 Expo : Node_Id := Empty;
11196 Imp : Node_Id := Empty;
11197 LN : Node_Id := Empty;
11199 -- Start of processing for Get_Interfacing_Aspects
11202 -- The input interfacing aspect should reside in an aspect specification
11205 pragma Assert (Is_List_Member (Iface_Asp));
11207 -- Examine the aspect specifications of the related entity. Find and
11208 -- capture all interfacing aspects. Detect duplicates and emit errors
11211 Asp := First (List_Containing (Iface_Asp));
11212 while Present (Asp) loop
11213 Asp_Id := Get_Aspect_Id (Asp);
11215 if Asp_Id = Aspect_Convention then
11216 Save_Or_Duplication_Error (Asp, Conv);
11218 elsif Asp_Id = Aspect_External_Name then
11219 Save_Or_Duplication_Error (Asp, EN);
11221 elsif Asp_Id = Aspect_Export then
11222 Save_Or_Duplication_Error (Asp, Expo);
11224 elsif Asp_Id = Aspect_Import then
11225 Save_Or_Duplication_Error (Asp, Imp);
11227 elsif Asp_Id = Aspect_Link_Name then
11228 Save_Or_Duplication_Error (Asp, LN);
11239 end Get_Interfacing_Aspects;
11241 -------------------------------------
11242 -- Inherit_Aspects_At_Freeze_Point --
11243 -------------------------------------
11245 procedure Inherit_Aspects_At_Freeze_Point (Typ : Entity_Id) is
11246 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11247 (Rep_Item : Node_Id) return Boolean;
11248 -- This routine checks if Rep_Item is either a pragma or an aspect
11249 -- specification node whose correponding pragma (if any) is present in
11250 -- the Rep Item chain of the entity it has been specified to.
11252 --------------------------------------------------
11253 -- Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item --
11254 --------------------------------------------------
11256 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11257 (Rep_Item : Node_Id) return Boolean
11261 Nkind (Rep_Item) = N_Pragma
11262 or else Present_In_Rep_Item
11263 (Entity (Rep_Item), Aspect_Rep_Item (Rep_Item));
11264 end Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item;
11266 -- Start of processing for Inherit_Aspects_At_Freeze_Point
11269 -- A representation item is either subtype-specific (Size and Alignment
11270 -- clauses) or type-related (all others). Subtype-specific aspects may
11271 -- differ for different subtypes of the same type (RM 13.1.8).
11273 -- A derived type inherits each type-related representation aspect of
11274 -- its parent type that was directly specified before the declaration of
11275 -- the derived type (RM 13.1.15).
11277 -- A derived subtype inherits each subtype-specific representation
11278 -- aspect of its parent subtype that was directly specified before the
11279 -- declaration of the derived type (RM 13.1.15).
11281 -- The general processing involves inheriting a representation aspect
11282 -- from a parent type whenever the first rep item (aspect specification,
11283 -- attribute definition clause, pragma) corresponding to the given
11284 -- representation aspect in the rep item chain of Typ, if any, isn't
11285 -- directly specified to Typ but to one of its parents.
11287 -- ??? Note that, for now, just a limited number of representation
11288 -- aspects have been inherited here so far. Many of them are
11289 -- still inherited in Sem_Ch3. This will be fixed soon. Here is
11290 -- a non- exhaustive list of aspects that likely also need to
11291 -- be moved to this routine: Alignment, Component_Alignment,
11292 -- Component_Size, Machine_Radix, Object_Size, Pack, Predicates,
11293 -- Preelaborable_Initialization, RM_Size and Small.
11295 -- In addition, Convention must be propagated from base type to subtype,
11296 -- because the subtype may have been declared on an incomplete view.
11298 if Nkind (Parent (Typ)) = N_Private_Extension_Declaration then
11304 if not Has_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005, False)
11305 and then Has_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005)
11306 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11307 (Get_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005))
11309 Set_Is_Ada_2005_Only (Typ);
11314 if not Has_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012, False)
11315 and then Has_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012)
11316 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11317 (Get_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012))
11319 Set_Is_Ada_2012_Only (Typ);
11324 if not Has_Rep_Item (Typ, Name_Atomic, Name_Shared, False)
11325 and then Has_Rep_Pragma (Typ, Name_Atomic, Name_Shared)
11326 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11327 (Get_Rep_Item (Typ, Name_Atomic, Name_Shared))
11329 Set_Is_Atomic (Typ);
11330 Set_Is_Volatile (Typ);
11331 Set_Treat_As_Volatile (Typ);
11336 if Is_Record_Type (Typ)
11337 and then Typ /= Base_Type (Typ) and then Is_Frozen (Base_Type (Typ))
11339 Set_Convention (Typ, Convention (Base_Type (Typ)));
11342 -- Default_Component_Value
11344 -- Verify that there is no rep_item declared for the type, and there
11345 -- is one coming from an ancestor.
11347 if Is_Array_Type (Typ)
11348 and then Is_Base_Type (Typ)
11349 and then not Has_Rep_Item (Typ, Name_Default_Component_Value, False)
11350 and then Has_Rep_Item (Typ, Name_Default_Component_Value)
11352 Set_Default_Aspect_Component_Value (Typ,
11353 Default_Aspect_Component_Value
11354 (Entity (Get_Rep_Item (Typ, Name_Default_Component_Value))));
11359 if Is_Scalar_Type (Typ)
11360 and then Is_Base_Type (Typ)
11361 and then not Has_Rep_Item (Typ, Name_Default_Value, False)
11362 and then Has_Rep_Item (Typ, Name_Default_Value)
11364 Set_Has_Default_Aspect (Typ);
11365 Set_Default_Aspect_Value (Typ,
11366 Default_Aspect_Value
11367 (Entity (Get_Rep_Item (Typ, Name_Default_Value))));
11372 if not Has_Rep_Item (Typ, Name_Discard_Names, False)
11373 and then Has_Rep_Item (Typ, Name_Discard_Names)
11374 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11375 (Get_Rep_Item (Typ, Name_Discard_Names))
11377 Set_Discard_Names (Typ);
11382 if not Has_Rep_Item (Typ, Name_Volatile, False)
11383 and then Has_Rep_Item (Typ, Name_Volatile)
11384 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11385 (Get_Rep_Item (Typ, Name_Volatile))
11387 Set_Is_Volatile (Typ);
11388 Set_Treat_As_Volatile (Typ);
11391 -- Volatile_Full_Access
11393 if not Has_Rep_Item (Typ, Name_Volatile_Full_Access, False)
11394 and then Has_Rep_Pragma (Typ, Name_Volatile_Full_Access)
11395 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11396 (Get_Rep_Item (Typ, Name_Volatile_Full_Access))
11398 Set_Is_Volatile_Full_Access (Typ);
11399 Set_Is_Volatile (Typ);
11400 Set_Treat_As_Volatile (Typ);
11403 -- Inheritance for derived types only
11405 if Is_Derived_Type (Typ) then
11407 Bas_Typ : constant Entity_Id := Base_Type (Typ);
11408 Imp_Bas_Typ : constant Entity_Id := Implementation_Base_Type (Typ);
11411 -- Atomic_Components
11413 if not Has_Rep_Item (Typ, Name_Atomic_Components, False)
11414 and then Has_Rep_Item (Typ, Name_Atomic_Components)
11415 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11416 (Get_Rep_Item (Typ, Name_Atomic_Components))
11418 Set_Has_Atomic_Components (Imp_Bas_Typ);
11421 -- Volatile_Components
11423 if not Has_Rep_Item (Typ, Name_Volatile_Components, False)
11424 and then Has_Rep_Item (Typ, Name_Volatile_Components)
11425 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11426 (Get_Rep_Item (Typ, Name_Volatile_Components))
11428 Set_Has_Volatile_Components (Imp_Bas_Typ);
11431 -- Finalize_Storage_Only
11433 if not Has_Rep_Pragma (Typ, Name_Finalize_Storage_Only, False)
11434 and then Has_Rep_Pragma (Typ, Name_Finalize_Storage_Only)
11436 Set_Finalize_Storage_Only (Bas_Typ);
11439 -- Universal_Aliasing
11441 if not Has_Rep_Item (Typ, Name_Universal_Aliasing, False)
11442 and then Has_Rep_Item (Typ, Name_Universal_Aliasing)
11443 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11444 (Get_Rep_Item (Typ, Name_Universal_Aliasing))
11446 Set_Universal_Aliasing (Imp_Bas_Typ);
11451 if Is_Record_Type (Typ) then
11452 if not Has_Rep_Item (Typ, Name_Bit_Order, False)
11453 and then Has_Rep_Item (Typ, Name_Bit_Order)
11455 Set_Reverse_Bit_Order (Bas_Typ,
11456 Reverse_Bit_Order (Entity (Name
11457 (Get_Rep_Item (Typ, Name_Bit_Order)))));
11461 -- Scalar_Storage_Order
11463 -- Note: the aspect is specified on a first subtype, but recorded
11464 -- in a flag of the base type!
11466 if (Is_Record_Type (Typ) or else Is_Array_Type (Typ))
11467 and then Typ = Bas_Typ
11469 -- For a type extension, always inherit from parent; otherwise
11470 -- inherit if no default applies. Note: we do not check for
11471 -- an explicit rep item on the parent type when inheriting,
11472 -- because the parent SSO may itself have been set by default.
11474 if not Has_Rep_Item (First_Subtype (Typ),
11475 Name_Scalar_Storage_Order, False)
11476 and then (Is_Tagged_Type (Bas_Typ)
11477 or else not (SSO_Set_Low_By_Default (Bas_Typ)
11479 SSO_Set_High_By_Default (Bas_Typ)))
11481 Set_Reverse_Storage_Order (Bas_Typ,
11482 Reverse_Storage_Order
11483 (Implementation_Base_Type (Etype (Bas_Typ))));
11485 -- Clear default SSO indications, since the inherited aspect
11486 -- which was set explicitly overrides the default.
11488 Set_SSO_Set_Low_By_Default (Bas_Typ, False);
11489 Set_SSO_Set_High_By_Default (Bas_Typ, False);
11494 end Inherit_Aspects_At_Freeze_Point;
11500 procedure Initialize is
11502 Address_Clause_Checks.Init;
11503 Compile_Time_Warnings_Errors.Init;
11504 Unchecked_Conversions.Init;
11506 if AAMP_On_Target then
11507 Independence_Checks.Init;
11511 ---------------------------
11512 -- Install_Discriminants --
11513 ---------------------------
11515 procedure Install_Discriminants (E : Entity_Id) is
11519 Disc := First_Discriminant (E);
11520 while Present (Disc) loop
11521 Prev := Current_Entity (Disc);
11522 Set_Current_Entity (Disc);
11523 Set_Is_Immediately_Visible (Disc);
11524 Set_Homonym (Disc, Prev);
11525 Next_Discriminant (Disc);
11527 end Install_Discriminants;
11529 -------------------------
11530 -- Is_Operational_Item --
11531 -------------------------
11533 function Is_Operational_Item (N : Node_Id) return Boolean is
11535 if Nkind (N) /= N_Attribute_Definition_Clause then
11540 Id : constant Attribute_Id := Get_Attribute_Id (Chars (N));
11543 -- List of operational items is given in AARM 13.1(8.mm/1).
11544 -- It is clearly incomplete, as it does not include iterator
11545 -- aspects, among others.
11547 return Id = Attribute_Constant_Indexing
11548 or else Id = Attribute_Default_Iterator
11549 or else Id = Attribute_Implicit_Dereference
11550 or else Id = Attribute_Input
11551 or else Id = Attribute_Iterator_Element
11552 or else Id = Attribute_Iterable
11553 or else Id = Attribute_Output
11554 or else Id = Attribute_Read
11555 or else Id = Attribute_Variable_Indexing
11556 or else Id = Attribute_Write
11557 or else Id = Attribute_External_Tag;
11560 end Is_Operational_Item;
11562 -------------------------
11563 -- Is_Predicate_Static --
11564 -------------------------
11566 -- Note: the basic legality of the expression has already been checked, so
11567 -- we don't need to worry about cases or ranges on strings for example.
11569 function Is_Predicate_Static
11571 Nam : Name_Id) return Boolean
11573 function All_Static_Case_Alternatives (L : List_Id) return Boolean;
11574 -- Given a list of case expression alternatives, returns True if all
11575 -- the alternatives are static (have all static choices, and a static
11578 function All_Static_Choices (L : List_Id) return Boolean;
11579 -- Returns true if all elements of the list are OK static choices
11580 -- as defined below for Is_Static_Choice. Used for case expression
11581 -- alternatives and for the right operand of a membership test. An
11582 -- others_choice is static if the corresponding expression is static.
11583 -- The staticness of the bounds is checked separately.
11585 function Is_Static_Choice (N : Node_Id) return Boolean;
11586 -- Returns True if N represents a static choice (static subtype, or
11587 -- static subtype indication, or static expression, or static range).
11589 -- Note that this is a bit more inclusive than we actually need
11590 -- (in particular membership tests do not allow the use of subtype
11591 -- indications). But that doesn't matter, we have already checked
11592 -- that the construct is legal to get this far.
11594 function Is_Type_Ref (N : Node_Id) return Boolean;
11595 pragma Inline (Is_Type_Ref);
11596 -- Returns True if N is a reference to the type for the predicate in the
11597 -- expression (i.e. if it is an identifier whose Chars field matches the
11598 -- Nam given in the call). N must not be parenthesized, if the type name
11599 -- appears in parens, this routine will return False.
11601 ----------------------------------
11602 -- All_Static_Case_Alternatives --
11603 ----------------------------------
11605 function All_Static_Case_Alternatives (L : List_Id) return Boolean is
11610 while Present (N) loop
11611 if not (All_Static_Choices (Discrete_Choices (N))
11612 and then Is_OK_Static_Expression (Expression (N)))
11621 end All_Static_Case_Alternatives;
11623 ------------------------
11624 -- All_Static_Choices --
11625 ------------------------
11627 function All_Static_Choices (L : List_Id) return Boolean is
11632 while Present (N) loop
11633 if not Is_Static_Choice (N) then
11641 end All_Static_Choices;
11643 ----------------------
11644 -- Is_Static_Choice --
11645 ----------------------
11647 function Is_Static_Choice (N : Node_Id) return Boolean is
11649 return Nkind (N) = N_Others_Choice
11650 or else Is_OK_Static_Expression (N)
11651 or else (Is_Entity_Name (N) and then Is_Type (Entity (N))
11652 and then Is_OK_Static_Subtype (Entity (N)))
11653 or else (Nkind (N) = N_Subtype_Indication
11654 and then Is_OK_Static_Subtype (Entity (N)))
11655 or else (Nkind (N) = N_Range and then Is_OK_Static_Range (N));
11656 end Is_Static_Choice;
11662 function Is_Type_Ref (N : Node_Id) return Boolean is
11664 return Nkind (N) = N_Identifier
11665 and then Chars (N) = Nam
11666 and then Paren_Count (N) = 0;
11669 -- Start of processing for Is_Predicate_Static
11672 -- Predicate_Static means one of the following holds. Numbers are the
11673 -- corresponding paragraph numbers in (RM 3.2.4(16-22)).
11675 -- 16: A static expression
11677 if Is_OK_Static_Expression (Expr) then
11680 -- 17: A membership test whose simple_expression is the current
11681 -- instance, and whose membership_choice_list meets the requirements
11682 -- for a static membership test.
11684 elsif Nkind (Expr) in N_Membership_Test
11685 and then ((Present (Right_Opnd (Expr))
11686 and then Is_Static_Choice (Right_Opnd (Expr)))
11688 (Present (Alternatives (Expr))
11689 and then All_Static_Choices (Alternatives (Expr))))
11693 -- 18. A case_expression whose selecting_expression is the current
11694 -- instance, and whose dependent expressions are static expressions.
11696 elsif Nkind (Expr) = N_Case_Expression
11697 and then Is_Type_Ref (Expression (Expr))
11698 and then All_Static_Case_Alternatives (Alternatives (Expr))
11702 -- 19. A call to a predefined equality or ordering operator, where one
11703 -- operand is the current instance, and the other is a static
11706 -- Note: the RM is clearly wrong here in not excluding string types.
11707 -- Without this exclusion, we would allow expressions like X > "ABC"
11708 -- to be considered as predicate-static, which is clearly not intended,
11709 -- since the idea is for predicate-static to be a subset of normal
11710 -- static expressions (and "DEF" > "ABC" is not a static expression).
11712 -- However, we do allow internally generated (not from source) equality
11713 -- and inequality operations to be valid on strings (this helps deal
11714 -- with cases where we transform A in "ABC" to A = "ABC).
11716 elsif Nkind (Expr) in N_Op_Compare
11717 and then ((not Is_String_Type (Etype (Left_Opnd (Expr))))
11718 or else (Nkind_In (Expr, N_Op_Eq, N_Op_Ne)
11719 and then not Comes_From_Source (Expr)))
11720 and then ((Is_Type_Ref (Left_Opnd (Expr))
11721 and then Is_OK_Static_Expression (Right_Opnd (Expr)))
11723 (Is_Type_Ref (Right_Opnd (Expr))
11724 and then Is_OK_Static_Expression (Left_Opnd (Expr))))
11728 -- 20. A call to a predefined boolean logical operator, where each
11729 -- operand is predicate-static.
11731 elsif (Nkind_In (Expr, N_Op_And, N_Op_Or, N_Op_Xor)
11732 and then Is_Predicate_Static (Left_Opnd (Expr), Nam)
11733 and then Is_Predicate_Static (Right_Opnd (Expr), Nam))
11735 (Nkind (Expr) = N_Op_Not
11736 and then Is_Predicate_Static (Right_Opnd (Expr), Nam))
11740 -- 21. A short-circuit control form where both operands are
11741 -- predicate-static.
11743 elsif Nkind (Expr) in N_Short_Circuit
11744 and then Is_Predicate_Static (Left_Opnd (Expr), Nam)
11745 and then Is_Predicate_Static (Right_Opnd (Expr), Nam)
11749 -- 22. A parenthesized predicate-static expression. This does not
11750 -- require any special test, since we just ignore paren levels in
11751 -- all the cases above.
11753 -- One more test that is an implementation artifact caused by the fact
11754 -- that we are analyzing not the original expression, but the generated
11755 -- expression in the body of the predicate function. This can include
11756 -- references to inherited predicates, so that the expression we are
11757 -- processing looks like:
11759 -- xxPredicate (typ (Inns)) and then expression
11761 -- Where the call is to a Predicate function for an inherited predicate.
11762 -- We simply ignore such a call, which could be to either a dynamic or
11763 -- a static predicate. Note that if the parent predicate is dynamic then
11764 -- eventually this type will be marked as dynamic, but you are allowed
11765 -- to specify a static predicate for a subtype which is inheriting a
11766 -- dynamic predicate, so the static predicate validation here ignores
11767 -- the inherited predicate even if it is dynamic.
11768 -- In all cases, a static predicate can only apply to a scalar type.
11770 elsif Nkind (Expr) = N_Function_Call
11771 and then Is_Predicate_Function (Entity (Name (Expr)))
11772 and then Is_Scalar_Type (Etype (First_Entity (Entity (Name (Expr)))))
11776 -- That's an exhaustive list of tests, all other cases are not
11777 -- predicate-static, so we return False.
11782 end Is_Predicate_Static;
11784 ---------------------
11785 -- Kill_Rep_Clause --
11786 ---------------------
11788 procedure Kill_Rep_Clause (N : Node_Id) is
11790 pragma Assert (Ignore_Rep_Clauses);
11792 -- Note: we use Replace rather than Rewrite, because we don't want
11793 -- ASIS to be able to use Original_Node to dig out the (undecorated)
11794 -- rep clause that is being replaced.
11796 Replace (N, Make_Null_Statement (Sloc (N)));
11798 -- The null statement must be marked as not coming from source. This is
11799 -- so that ASIS ignores it, and also the back end does not expect bogus
11800 -- "from source" null statements in weird places (e.g. in declarative
11801 -- regions where such null statements are not allowed).
11803 Set_Comes_From_Source (N, False);
11804 end Kill_Rep_Clause;
11810 function Minimum_Size
11812 Biased : Boolean := False) return Nat
11814 Lo : Uint := No_Uint;
11815 Hi : Uint := No_Uint;
11816 LoR : Ureal := No_Ureal;
11817 HiR : Ureal := No_Ureal;
11818 LoSet : Boolean := False;
11819 HiSet : Boolean := False;
11822 Ancest : Entity_Id;
11823 R_Typ : constant Entity_Id := Root_Type (T);
11826 -- If bad type, return 0
11828 if T = Any_Type then
11831 -- For generic types, just return zero. There cannot be any legitimate
11832 -- need to know such a size, but this routine may be called with a
11833 -- generic type as part of normal processing.
11835 elsif Is_Generic_Type (R_Typ) or else R_Typ = Any_Type then
11838 -- Access types (cannot have size smaller than System.Address)
11840 elsif Is_Access_Type (T) then
11841 return System_Address_Size;
11843 -- Floating-point types
11845 elsif Is_Floating_Point_Type (T) then
11846 return UI_To_Int (Esize (R_Typ));
11850 elsif Is_Discrete_Type (T) then
11852 -- The following loop is looking for the nearest compile time known
11853 -- bounds following the ancestor subtype chain. The idea is to find
11854 -- the most restrictive known bounds information.
11858 if Ancest = Any_Type or else Etype (Ancest) = Any_Type then
11863 if Compile_Time_Known_Value (Type_Low_Bound (Ancest)) then
11864 Lo := Expr_Rep_Value (Type_Low_Bound (Ancest));
11871 if Compile_Time_Known_Value (Type_High_Bound (Ancest)) then
11872 Hi := Expr_Rep_Value (Type_High_Bound (Ancest));
11878 Ancest := Ancestor_Subtype (Ancest);
11880 if No (Ancest) then
11881 Ancest := Base_Type (T);
11883 if Is_Generic_Type (Ancest) then
11889 -- Fixed-point types. We can't simply use Expr_Value to get the
11890 -- Corresponding_Integer_Value values of the bounds, since these do not
11891 -- get set till the type is frozen, and this routine can be called
11892 -- before the type is frozen. Similarly the test for bounds being static
11893 -- needs to include the case where we have unanalyzed real literals for
11894 -- the same reason.
11896 elsif Is_Fixed_Point_Type (T) then
11898 -- The following loop is looking for the nearest compile time known
11899 -- bounds following the ancestor subtype chain. The idea is to find
11900 -- the most restrictive known bounds information.
11904 if Ancest = Any_Type or else Etype (Ancest) = Any_Type then
11908 -- Note: In the following two tests for LoSet and HiSet, it may
11909 -- seem redundant to test for N_Real_Literal here since normally
11910 -- one would assume that the test for the value being known at
11911 -- compile time includes this case. However, there is a glitch.
11912 -- If the real literal comes from folding a non-static expression,
11913 -- then we don't consider any non- static expression to be known
11914 -- at compile time if we are in configurable run time mode (needed
11915 -- in some cases to give a clearer definition of what is and what
11916 -- is not accepted). So the test is indeed needed. Without it, we
11917 -- would set neither Lo_Set nor Hi_Set and get an infinite loop.
11920 if Nkind (Type_Low_Bound (Ancest)) = N_Real_Literal
11921 or else Compile_Time_Known_Value (Type_Low_Bound (Ancest))
11923 LoR := Expr_Value_R (Type_Low_Bound (Ancest));
11930 if Nkind (Type_High_Bound (Ancest)) = N_Real_Literal
11931 or else Compile_Time_Known_Value (Type_High_Bound (Ancest))
11933 HiR := Expr_Value_R (Type_High_Bound (Ancest));
11939 Ancest := Ancestor_Subtype (Ancest);
11941 if No (Ancest) then
11942 Ancest := Base_Type (T);
11944 if Is_Generic_Type (Ancest) then
11950 Lo := UR_To_Uint (LoR / Small_Value (T));
11951 Hi := UR_To_Uint (HiR / Small_Value (T));
11953 -- No other types allowed
11956 raise Program_Error;
11959 -- Fall through with Hi and Lo set. Deal with biased case
11962 and then not Is_Fixed_Point_Type (T)
11963 and then not (Is_Enumeration_Type (T)
11964 and then Has_Non_Standard_Rep (T)))
11965 or else Has_Biased_Representation (T)
11971 -- Null range case, size is always zero. We only do this in the discrete
11972 -- type case, since that's the odd case that came up. Probably we should
11973 -- also do this in the fixed-point case, but doing so causes peculiar
11974 -- gigi failures, and it is not worth worrying about this incredibly
11975 -- marginal case (explicit null-range fixed-point type declarations)???
11977 if Lo > Hi and then Is_Discrete_Type (T) then
11980 -- Signed case. Note that we consider types like range 1 .. -1 to be
11981 -- signed for the purpose of computing the size, since the bounds have
11982 -- to be accommodated in the base type.
11984 elsif Lo < 0 or else Hi < 0 then
11988 -- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1))
11989 -- Note that we accommodate the case where the bounds cross. This
11990 -- can happen either because of the way the bounds are declared
11991 -- or because of the algorithm in Freeze_Fixed_Point_Type.
12005 -- If both bounds are positive, make sure that both are represen-
12006 -- table in the case where the bounds are crossed. This can happen
12007 -- either because of the way the bounds are declared, or because of
12008 -- the algorithm in Freeze_Fixed_Point_Type.
12014 -- S = size, (can accommodate 0 .. (2**size - 1))
12017 while Hi >= Uint_2 ** S loop
12025 ---------------------------
12026 -- New_Stream_Subprogram --
12027 ---------------------------
12029 procedure New_Stream_Subprogram
12033 Nam : TSS_Name_Type)
12035 Loc : constant Source_Ptr := Sloc (N);
12036 Sname : constant Name_Id := Make_TSS_Name (Base_Type (Ent), Nam);
12037 Subp_Id : Entity_Id;
12038 Subp_Decl : Node_Id;
12042 Defer_Declaration : constant Boolean :=
12043 Is_Tagged_Type (Ent) or else Is_Private_Type (Ent);
12044 -- For a tagged type, there is a declaration for each stream attribute
12045 -- at the freeze point, and we must generate only a completion of this
12046 -- declaration. We do the same for private types, because the full view
12047 -- might be tagged. Otherwise we generate a declaration at the point of
12048 -- the attribute definition clause. If the attribute definition comes
12049 -- from an aspect specification the declaration is part of the freeze
12050 -- actions of the type.
12052 function Build_Spec return Node_Id;
12053 -- Used for declaration and renaming declaration, so that this is
12054 -- treated as a renaming_as_body.
12060 function Build_Spec return Node_Id is
12061 Out_P : constant Boolean := (Nam = TSS_Stream_Read);
12064 T_Ref : constant Node_Id := New_Occurrence_Of (Etyp, Loc);
12067 Subp_Id := Make_Defining_Identifier (Loc, Sname);
12069 -- S : access Root_Stream_Type'Class
12071 Formals := New_List (
12072 Make_Parameter_Specification (Loc,
12073 Defining_Identifier =>
12074 Make_Defining_Identifier (Loc, Name_S),
12076 Make_Access_Definition (Loc,
12078 New_Occurrence_Of (
12079 Designated_Type (Etype (F)), Loc))));
12081 if Nam = TSS_Stream_Input then
12083 Make_Function_Specification (Loc,
12084 Defining_Unit_Name => Subp_Id,
12085 Parameter_Specifications => Formals,
12086 Result_Definition => T_Ref);
12090 Append_To (Formals,
12091 Make_Parameter_Specification (Loc,
12092 Defining_Identifier => Make_Defining_Identifier (Loc, Name_V),
12093 Out_Present => Out_P,
12094 Parameter_Type => T_Ref));
12097 Make_Procedure_Specification (Loc,
12098 Defining_Unit_Name => Subp_Id,
12099 Parameter_Specifications => Formals);
12105 -- Start of processing for New_Stream_Subprogram
12108 F := First_Formal (Subp);
12110 if Ekind (Subp) = E_Procedure then
12111 Etyp := Etype (Next_Formal (F));
12113 Etyp := Etype (Subp);
12116 -- Prepare subprogram declaration and insert it as an action on the
12117 -- clause node. The visibility for this entity is used to test for
12118 -- visibility of the attribute definition clause (in the sense of
12119 -- 8.3(23) as amended by AI-195).
12121 if not Defer_Declaration then
12123 Make_Subprogram_Declaration (Loc,
12124 Specification => Build_Spec);
12126 -- For a tagged type, there is always a visible declaration for each
12127 -- stream TSS (it is a predefined primitive operation), and the
12128 -- completion of this declaration occurs at the freeze point, which is
12129 -- not always visible at places where the attribute definition clause is
12130 -- visible. So, we create a dummy entity here for the purpose of
12131 -- tracking the visibility of the attribute definition clause itself.
12135 Make_Defining_Identifier (Loc, New_External_Name (Sname, 'V'));
12137 Make_Object_Declaration (Loc,
12138 Defining_Identifier => Subp_Id,
12139 Object_Definition => New_Occurrence_Of (Standard_Boolean, Loc));
12142 if not Defer_Declaration
12143 and then From_Aspect_Specification (N)
12144 and then Has_Delayed_Freeze (Ent)
12146 Append_Freeze_Action (Ent, Subp_Decl);
12149 Insert_Action (N, Subp_Decl);
12150 Set_Entity (N, Subp_Id);
12154 Make_Subprogram_Renaming_Declaration (Loc,
12155 Specification => Build_Spec,
12156 Name => New_Occurrence_Of (Subp, Loc));
12158 if Defer_Declaration then
12159 Set_TSS (Base_Type (Ent), Subp_Id);
12162 if From_Aspect_Specification (N) then
12163 Append_Freeze_Action (Ent, Subp_Decl);
12165 Insert_Action (N, Subp_Decl);
12168 Copy_TSS (Subp_Id, Base_Type (Ent));
12170 end New_Stream_Subprogram;
12172 ------------------------------------------
12173 -- Push_Scope_And_Install_Discriminants --
12174 ------------------------------------------
12176 procedure Push_Scope_And_Install_Discriminants (E : Entity_Id) is
12178 if Has_Discriminants (E) then
12181 -- Make the discriminants visible for type declarations and protected
12182 -- type declarations, not for subtype declarations (RM 13.1.1 (12/3))
12184 if Nkind (Parent (E)) /= N_Subtype_Declaration then
12185 Install_Discriminants (E);
12188 end Push_Scope_And_Install_Discriminants;
12190 ------------------------
12191 -- Rep_Item_Too_Early --
12192 ------------------------
12194 function Rep_Item_Too_Early (T : Entity_Id; N : Node_Id) return Boolean is
12196 -- Cannot apply non-operational rep items to generic types
12198 if Is_Operational_Item (N) then
12202 and then Is_Generic_Type (Root_Type (T))
12203 and then (Nkind (N) /= N_Pragma
12204 or else Get_Pragma_Id (N) /= Pragma_Convention)
12206 Error_Msg_N ("representation item not allowed for generic type", N);
12210 -- Otherwise check for incomplete type
12212 if Is_Incomplete_Or_Private_Type (T)
12213 and then No (Underlying_Type (T))
12215 (Nkind (N) /= N_Pragma
12216 or else Get_Pragma_Id (N) /= Pragma_Import)
12219 ("representation item must be after full type declaration", N);
12222 -- If the type has incomplete components, a representation clause is
12223 -- illegal but stream attributes and Convention pragmas are correct.
12225 elsif Has_Private_Component (T) then
12226 if Nkind (N) = N_Pragma then
12231 ("representation item must appear after type is fully defined",
12238 end Rep_Item_Too_Early;
12240 -----------------------
12241 -- Rep_Item_Too_Late --
12242 -----------------------
12244 function Rep_Item_Too_Late
12247 FOnly : Boolean := False) return Boolean
12250 Parent_Type : Entity_Id;
12252 procedure No_Type_Rep_Item;
12253 -- Output message indicating that no type-related aspects can be
12254 -- specified due to some property of the parent type.
12256 procedure Too_Late;
12257 -- Output message for an aspect being specified too late
12259 -- Note that neither of the above errors is considered a serious one,
12260 -- since the effect is simply that we ignore the representation clause
12262 -- Is this really true? In any case if we make this change we must
12263 -- document the requirement in the spec of Rep_Item_Too_Late that
12264 -- if True is returned, then the rep item must be completely ignored???
12266 ----------------------
12267 -- No_Type_Rep_Item --
12268 ----------------------
12270 procedure No_Type_Rep_Item is
12272 Error_Msg_N ("|type-related representation item not permitted!", N);
12273 end No_Type_Rep_Item;
12279 procedure Too_Late is
12281 -- Other compilers seem more relaxed about rep items appearing too
12282 -- late. Since analysis tools typically don't care about rep items
12283 -- anyway, no reason to be too strict about this.
12285 if not Relaxed_RM_Semantics then
12286 Error_Msg_N ("|representation item appears too late!", N);
12290 -- Start of processing for Rep_Item_Too_Late
12293 -- First make sure entity is not frozen (RM 13.1(9))
12297 -- Exclude imported types, which may be frozen if they appear in a
12298 -- representation clause for a local type.
12300 and then not From_Limited_With (T)
12302 -- Exclude generated entities (not coming from source). The common
12303 -- case is when we generate a renaming which prematurely freezes the
12304 -- renamed internal entity, but we still want to be able to set copies
12305 -- of attribute values such as Size/Alignment.
12307 and then Comes_From_Source (T)
12309 -- A self-referential aspect is illegal if it forces freezing the
12310 -- entity before the corresponding pragma has been analyzed.
12312 if Nkind_In (N, N_Attribute_Definition_Clause, N_Pragma)
12313 and then From_Aspect_Specification (N)
12316 ("aspect specification causes premature freezing of&", T, N);
12317 Set_Has_Delayed_Freeze (T, False);
12322 S := First_Subtype (T);
12324 if Present (Freeze_Node (S)) then
12325 if not Relaxed_RM_Semantics then
12327 ("??no more representation items for }", Freeze_Node (S), S);
12333 -- Check for case of untagged derived type whose parent either has
12334 -- primitive operations, or is a by reference type (RM 13.1(10)). In
12335 -- this case we do not output a Too_Late message, since there is no
12336 -- earlier point where the rep item could be placed to make it legal.
12340 and then Is_Derived_Type (T)
12341 and then not Is_Tagged_Type (T)
12343 Parent_Type := Etype (Base_Type (T));
12345 if Has_Primitive_Operations (Parent_Type) then
12348 if not Relaxed_RM_Semantics then
12350 ("\parent type & has primitive operations!", N, Parent_Type);
12355 elsif Is_By_Reference_Type (Parent_Type) then
12358 if not Relaxed_RM_Semantics then
12360 ("\parent type & is a by reference type!", N, Parent_Type);
12367 -- No error, but one more warning to consider. The RM (surprisingly)
12368 -- allows this pattern:
12371 -- primitive operations for S
12372 -- type R is new S;
12373 -- rep clause for S
12375 -- Meaning that calls on the primitive operations of S for values of
12376 -- type R may require possibly expensive implicit conversion operations.
12377 -- This is not an error, but is worth a warning.
12379 if not Relaxed_RM_Semantics and then Is_Type (T) then
12381 DTL : constant Entity_Id := Derived_Type_Link (Base_Type (T));
12385 and then Has_Primitive_Operations (Base_Type (T))
12387 -- For now, do not generate this warning for the case of aspect
12388 -- specification using Ada 2012 syntax, since we get wrong
12389 -- messages we do not understand. The whole business of derived
12390 -- types and rep items seems a bit confused when aspects are
12391 -- used, since the aspects are not evaluated till freeze time.
12393 and then not From_Aspect_Specification (N)
12395 Error_Msg_Sloc := Sloc (DTL);
12397 ("representation item for& appears after derived type "
12398 & "declaration#??", N);
12400 ("\may result in implicit conversions for primitive "
12401 & "operations of&??", N, T);
12403 ("\to change representations when called with arguments "
12404 & "of type&??", N, DTL);
12409 -- No error, link item into head of chain of rep items for the entity,
12410 -- but avoid chaining if we have an overloadable entity, and the pragma
12411 -- is one that can apply to multiple overloaded entities.
12413 if Is_Overloadable (T) and then Nkind (N) = N_Pragma then
12415 Pname : constant Name_Id := Pragma_Name (N);
12417 if Nam_In (Pname, Name_Convention, Name_Import, Name_Export,
12418 Name_External, Name_Interface)
12425 Record_Rep_Item (T, N);
12427 end Rep_Item_Too_Late;
12429 -------------------------------------
12430 -- Replace_Type_References_Generic --
12431 -------------------------------------
12433 procedure Replace_Type_References_Generic (N : Node_Id; T : Entity_Id) is
12434 TName : constant Name_Id := Chars (T);
12436 function Replace_Type_Ref (N : Node_Id) return Traverse_Result;
12437 -- Processes a single node in the traversal procedure below, checking
12438 -- if node N should be replaced, and if so, doing the replacement.
12440 function Visible_Component (Comp : Name_Id) return Entity_Id;
12441 -- Given an identifier in the expression, check whether there is a
12442 -- discriminant or component of the type that is directy visible, and
12443 -- rewrite it as the corresponding selected component of the formal of
12444 -- the subprogram. The entity is located by a sequential search, which
12445 -- seems acceptable given the typical size of component lists and check
12446 -- expressions. Possible optimization ???
12448 ----------------------
12449 -- Replace_Type_Ref --
12450 ----------------------
12452 function Replace_Type_Ref (N : Node_Id) return Traverse_Result is
12453 Loc : constant Source_Ptr := Sloc (N);
12455 procedure Add_Prefix (Ref : Node_Id; Comp : Entity_Id);
12456 -- Add the proper prefix to a reference to a component of the type
12457 -- when it is not already a selected component.
12463 procedure Add_Prefix (Ref : Node_Id; Comp : Entity_Id) is
12466 Make_Selected_Component (Loc,
12467 Prefix => New_Occurrence_Of (T, Loc),
12468 Selector_Name => New_Occurrence_Of (Comp, Loc)));
12469 Replace_Type_Reference (Prefix (Ref));
12478 -- Start of processing for Replace_Type_Ref
12481 if Nkind (N) = N_Identifier then
12483 -- If not the type name, check whether it is a reference to some
12484 -- other type, which must be frozen before the predicate function
12485 -- is analyzed, i.e. before the freeze node of the type to which
12486 -- the predicate applies.
12488 if Chars (N) /= TName then
12489 if Present (Current_Entity (N))
12490 and then Is_Type (Current_Entity (N))
12492 Freeze_Before (Freeze_Node (T), Current_Entity (N));
12495 -- The components of the type are directly visible and can
12496 -- be referenced without a prefix.
12498 if Nkind (Parent (N)) = N_Selected_Component then
12501 -- In expression C (I), C may be a directly visible function
12502 -- or a visible component that has an array type. Disambiguate
12503 -- by examining the component type.
12505 elsif Nkind (Parent (N)) = N_Indexed_Component
12506 and then N = Prefix (Parent (N))
12508 Comp := Visible_Component (Chars (N));
12510 if Present (Comp) and then Is_Array_Type (Etype (Comp)) then
12511 Add_Prefix (N, Comp);
12515 Comp := Visible_Component (Chars (N));
12517 if Present (Comp) then
12518 Add_Prefix (N, Comp);
12524 -- Otherwise do the replacement and we are done with this node
12527 Replace_Type_Reference (N);
12531 -- Case of selected component (which is what a qualification looks
12532 -- like in the unanalyzed tree, which is what we have.
12534 elsif Nkind (N) = N_Selected_Component then
12536 -- If selector name is not our type, keeping going (we might still
12537 -- have an occurrence of the type in the prefix).
12539 if Nkind (Selector_Name (N)) /= N_Identifier
12540 or else Chars (Selector_Name (N)) /= TName
12544 -- Selector name is our type, check qualification
12547 -- Loop through scopes and prefixes, doing comparison
12549 Scop := Current_Scope;
12550 Pref := Prefix (N);
12552 -- Continue if no more scopes or scope with no name
12554 if No (Scop) or else Nkind (Scop) not in N_Has_Chars then
12558 -- Do replace if prefix is an identifier matching the scope
12559 -- that we are currently looking at.
12561 if Nkind (Pref) = N_Identifier
12562 and then Chars (Pref) = Chars (Scop)
12564 Replace_Type_Reference (N);
12568 -- Go check scope above us if prefix is itself of the form
12569 -- of a selected component, whose selector matches the scope
12570 -- we are currently looking at.
12572 if Nkind (Pref) = N_Selected_Component
12573 and then Nkind (Selector_Name (Pref)) = N_Identifier
12574 and then Chars (Selector_Name (Pref)) = Chars (Scop)
12576 Scop := Scope (Scop);
12577 Pref := Prefix (Pref);
12579 -- For anything else, we don't have a match, so keep on
12580 -- going, there are still some weird cases where we may
12581 -- still have a replacement within the prefix.
12589 -- Continue for any other node kind
12594 end Replace_Type_Ref;
12596 procedure Replace_Type_Refs is new Traverse_Proc (Replace_Type_Ref);
12598 -----------------------
12599 -- Visible_Component --
12600 -----------------------
12602 function Visible_Component (Comp : Name_Id) return Entity_Id is
12606 if Ekind (T) /= E_Record_Type then
12610 E := First_Entity (T);
12611 while Present (E) loop
12612 if Comes_From_Source (E) and then Chars (E) = Comp then
12621 end Visible_Component;
12623 -- Start of processing for Replace_Type_References_Generic
12626 Replace_Type_Refs (N);
12627 end Replace_Type_References_Generic;
12629 --------------------------------
12630 -- Resolve_Aspect_Expressions --
12631 --------------------------------
12633 procedure Resolve_Aspect_Expressions (E : Entity_Id) is
12638 function Resolve_Name (N : Node_Id) return Traverse_Result;
12639 -- Verify that all identifiers in the expression, with the exception
12640 -- of references to the current entity, denote visible entities. This
12641 -- is done only to detect visibility errors, as the expression will be
12642 -- properly analyzed/expanded during analysis of the predicate function
12643 -- body. We omit quantified expressions from this test, given that they
12644 -- introduce a local identifier that would require proper expansion to
12645 -- handle properly.
12651 function Resolve_Name (N : Node_Id) return Traverse_Result is
12653 if Nkind (N) = N_Selected_Component then
12654 if Nkind (Prefix (N)) = N_Identifier
12655 and then Chars (Prefix (N)) /= Chars (E)
12657 Find_Selected_Component (N);
12662 elsif Nkind (N) = N_Identifier and then Chars (N) /= Chars (E) then
12663 Find_Direct_Name (N);
12664 Set_Entity (N, Empty);
12666 elsif Nkind (N) = N_Quantified_Expression then
12673 procedure Resolve_Aspect_Expression is new Traverse_Proc (Resolve_Name);
12675 -- Start of processing for Resolve_Aspect_Expressions
12678 ASN := First_Rep_Item (E);
12679 while Present (ASN) loop
12680 if Nkind (ASN) = N_Aspect_Specification and then Entity (ASN) = E then
12681 A_Id := Get_Aspect_Id (ASN);
12682 Expr := Expression (ASN);
12686 -- For now we only deal with aspects that do not generate
12687 -- subprograms, or that may mention current instances of
12688 -- types. These will require special handling (???TBD).
12690 when Aspect_Predicate |
12691 Aspect_Predicate_Failure |
12692 Aspect_Invariant =>
12695 when Aspect_Dynamic_Predicate |
12696 Aspect_Static_Predicate =>
12698 -- Build predicate function specification and preanalyze
12699 -- expression after type replacement.
12701 if No (Predicate_Function (E)) then
12703 FDecl : constant Node_Id :=
12704 Build_Predicate_Function_Declaration (E);
12705 pragma Unreferenced (FDecl);
12707 Resolve_Aspect_Expression (Expr);
12711 when Pre_Post_Aspects =>
12714 when Aspect_Iterable =>
12715 if Nkind (Expr) = N_Aggregate then
12720 Assoc := First (Component_Associations (Expr));
12721 while Present (Assoc) loop
12722 Find_Direct_Name (Expression (Assoc));
12729 if Present (Expr) then
12730 case Aspect_Argument (A_Id) is
12731 when Expression | Optional_Expression =>
12732 Analyze_And_Resolve (Expression (ASN));
12734 when Name | Optional_Name =>
12735 if Nkind (Expr) = N_Identifier then
12736 Find_Direct_Name (Expr);
12738 elsif Nkind (Expr) = N_Selected_Component then
12739 Find_Selected_Component (Expr);
12749 ASN := Next_Rep_Item (ASN);
12751 end Resolve_Aspect_Expressions;
12753 -------------------------
12754 -- Same_Representation --
12755 -------------------------
12757 function Same_Representation (Typ1, Typ2 : Entity_Id) return Boolean is
12758 T1 : constant Entity_Id := Underlying_Type (Typ1);
12759 T2 : constant Entity_Id := Underlying_Type (Typ2);
12762 -- A quick check, if base types are the same, then we definitely have
12763 -- the same representation, because the subtype specific representation
12764 -- attributes (Size and Alignment) do not affect representation from
12765 -- the point of view of this test.
12767 if Base_Type (T1) = Base_Type (T2) then
12770 elsif Is_Private_Type (Base_Type (T2))
12771 and then Base_Type (T1) = Full_View (Base_Type (T2))
12776 -- Tagged types never have differing representations
12778 if Is_Tagged_Type (T1) then
12782 -- Representations are definitely different if conventions differ
12784 if Convention (T1) /= Convention (T2) then
12788 -- Representations are different if component alignments or scalar
12789 -- storage orders differ.
12791 if (Is_Record_Type (T1) or else Is_Array_Type (T1))
12793 (Is_Record_Type (T2) or else Is_Array_Type (T2))
12795 (Component_Alignment (T1) /= Component_Alignment (T2)
12796 or else Reverse_Storage_Order (T1) /= Reverse_Storage_Order (T2))
12801 -- For arrays, the only real issue is component size. If we know the
12802 -- component size for both arrays, and it is the same, then that's
12803 -- good enough to know we don't have a change of representation.
12805 if Is_Array_Type (T1) then
12806 if Known_Component_Size (T1)
12807 and then Known_Component_Size (T2)
12808 and then Component_Size (T1) = Component_Size (T2)
12814 -- Types definitely have same representation if neither has non-standard
12815 -- representation since default representations are always consistent.
12816 -- If only one has non-standard representation, and the other does not,
12817 -- then we consider that they do not have the same representation. They
12818 -- might, but there is no way of telling early enough.
12820 if Has_Non_Standard_Rep (T1) then
12821 if not Has_Non_Standard_Rep (T2) then
12825 return not Has_Non_Standard_Rep (T2);
12828 -- Here the two types both have non-standard representation, and we need
12829 -- to determine if they have the same non-standard representation.
12831 -- For arrays, we simply need to test if the component sizes are the
12832 -- same. Pragma Pack is reflected in modified component sizes, so this
12833 -- check also deals with pragma Pack.
12835 if Is_Array_Type (T1) then
12836 return Component_Size (T1) = Component_Size (T2);
12838 -- Tagged types always have the same representation, because it is not
12839 -- possible to specify different representations for common fields.
12841 elsif Is_Tagged_Type (T1) then
12844 -- Case of record types
12846 elsif Is_Record_Type (T1) then
12848 -- Packed status must conform
12850 if Is_Packed (T1) /= Is_Packed (T2) then
12853 -- Otherwise we must check components. Typ2 maybe a constrained
12854 -- subtype with fewer components, so we compare the components
12855 -- of the base types.
12858 Record_Case : declare
12859 CD1, CD2 : Entity_Id;
12861 function Same_Rep return Boolean;
12862 -- CD1 and CD2 are either components or discriminants. This
12863 -- function tests whether they have the same representation.
12869 function Same_Rep return Boolean is
12871 if No (Component_Clause (CD1)) then
12872 return No (Component_Clause (CD2));
12874 -- Note: at this point, component clauses have been
12875 -- normalized to the default bit order, so that the
12876 -- comparison of Component_Bit_Offsets is meaningful.
12879 Present (Component_Clause (CD2))
12881 Component_Bit_Offset (CD1) = Component_Bit_Offset (CD2)
12883 Esize (CD1) = Esize (CD2);
12887 -- Start of processing for Record_Case
12890 if Has_Discriminants (T1) then
12892 -- The number of discriminants may be different if the
12893 -- derived type has fewer (constrained by values). The
12894 -- invisible discriminants retain the representation of
12895 -- the original, so the discrepancy does not per se
12896 -- indicate a different representation.
12898 CD1 := First_Discriminant (T1);
12899 CD2 := First_Discriminant (T2);
12900 while Present (CD1) and then Present (CD2) loop
12901 if not Same_Rep then
12904 Next_Discriminant (CD1);
12905 Next_Discriminant (CD2);
12910 CD1 := First_Component (Underlying_Type (Base_Type (T1)));
12911 CD2 := First_Component (Underlying_Type (Base_Type (T2)));
12912 while Present (CD1) loop
12913 if not Same_Rep then
12916 Next_Component (CD1);
12917 Next_Component (CD2);
12925 -- For enumeration types, we must check each literal to see if the
12926 -- representation is the same. Note that we do not permit enumeration
12927 -- representation clauses for Character and Wide_Character, so these
12928 -- cases were already dealt with.
12930 elsif Is_Enumeration_Type (T1) then
12931 Enumeration_Case : declare
12932 L1, L2 : Entity_Id;
12935 L1 := First_Literal (T1);
12936 L2 := First_Literal (T2);
12937 while Present (L1) loop
12938 if Enumeration_Rep (L1) /= Enumeration_Rep (L2) then
12947 end Enumeration_Case;
12949 -- Any other types have the same representation for these purposes
12954 end Same_Representation;
12956 --------------------------------
12957 -- Resolve_Iterable_Operation --
12958 --------------------------------
12960 procedure Resolve_Iterable_Operation
12962 Cursor : Entity_Id;
12971 if not Is_Overloaded (N) then
12972 if not Is_Entity_Name (N)
12973 or else Ekind (Entity (N)) /= E_Function
12974 or else Scope (Entity (N)) /= Scope (Typ)
12975 or else No (First_Formal (Entity (N)))
12976 or else Etype (First_Formal (Entity (N))) /= Typ
12978 Error_Msg_N ("iterable primitive must be local function name "
12979 & "whose first formal is an iterable type", N);
12984 F1 := First_Formal (Ent);
12985 if Nam = Name_First then
12987 -- First (Container) => Cursor
12989 if Etype (Ent) /= Cursor then
12990 Error_Msg_N ("primitive for First must yield a curosr", N);
12993 elsif Nam = Name_Next then
12995 -- Next (Container, Cursor) => Cursor
12997 F2 := Next_Formal (F1);
12999 if Etype (F2) /= Cursor
13000 or else Etype (Ent) /= Cursor
13001 or else Present (Next_Formal (F2))
13003 Error_Msg_N ("no match for Next iterable primitive", N);
13006 elsif Nam = Name_Has_Element then
13008 -- Has_Element (Container, Cursor) => Boolean
13010 F2 := Next_Formal (F1);
13011 if Etype (F2) /= Cursor
13012 or else Etype (Ent) /= Standard_Boolean
13013 or else Present (Next_Formal (F2))
13015 Error_Msg_N ("no match for Has_Element iterable primitive", N);
13018 elsif Nam = Name_Element then
13019 F2 := Next_Formal (F1);
13022 or else Etype (F2) /= Cursor
13023 or else Present (Next_Formal (F2))
13025 Error_Msg_N ("no match for Element iterable primitive", N);
13030 raise Program_Error;
13034 -- Overloaded case: find subprogram with proper signature.
13035 -- Caller will report error if no match is found.
13042 Get_First_Interp (N, I, It);
13043 while Present (It.Typ) loop
13044 if Ekind (It.Nam) = E_Function
13045 and then Scope (It.Nam) = Scope (Typ)
13046 and then Etype (First_Formal (It.Nam)) = Typ
13048 F1 := First_Formal (It.Nam);
13050 if Nam = Name_First then
13051 if Etype (It.Nam) = Cursor
13052 and then No (Next_Formal (F1))
13054 Set_Entity (N, It.Nam);
13058 elsif Nam = Name_Next then
13059 F2 := Next_Formal (F1);
13062 and then No (Next_Formal (F2))
13063 and then Etype (F2) = Cursor
13064 and then Etype (It.Nam) = Cursor
13066 Set_Entity (N, It.Nam);
13070 elsif Nam = Name_Has_Element then
13071 F2 := Next_Formal (F1);
13074 and then No (Next_Formal (F2))
13075 and then Etype (F2) = Cursor
13076 and then Etype (It.Nam) = Standard_Boolean
13078 Set_Entity (N, It.Nam);
13079 F2 := Next_Formal (F1);
13083 elsif Nam = Name_Element then
13084 F2 := Next_Formal (F1);
13087 and then No (Next_Formal (F2))
13088 and then Etype (F2) = Cursor
13090 Set_Entity (N, It.Nam);
13096 Get_Next_Interp (I, It);
13100 end Resolve_Iterable_Operation;
13106 procedure Set_Biased
13110 Biased : Boolean := True)
13114 Set_Has_Biased_Representation (E);
13116 if Warn_On_Biased_Representation then
13118 ("?B?" & Msg & " forces biased representation for&", N, E);
13123 --------------------
13124 -- Set_Enum_Esize --
13125 --------------------
13127 procedure Set_Enum_Esize (T : Entity_Id) is
13133 Init_Alignment (T);
13135 -- Find the minimum standard size (8,16,32,64) that fits
13137 Lo := Enumeration_Rep (Entity (Type_Low_Bound (T)));
13138 Hi := Enumeration_Rep (Entity (Type_High_Bound (T)));
13141 if Lo >= -Uint_2**07 and then Hi < Uint_2**07 then
13142 Sz := Standard_Character_Size; -- May be > 8 on some targets
13144 elsif Lo >= -Uint_2**15 and then Hi < Uint_2**15 then
13147 elsif Lo >= -Uint_2**31 and then Hi < Uint_2**31 then
13150 else pragma Assert (Lo >= -Uint_2**63 and then Hi < Uint_2**63);
13155 if Hi < Uint_2**08 then
13156 Sz := Standard_Character_Size; -- May be > 8 on some targets
13158 elsif Hi < Uint_2**16 then
13161 elsif Hi < Uint_2**32 then
13164 else pragma Assert (Hi < Uint_2**63);
13169 -- That minimum is the proper size unless we have a foreign convention
13170 -- and the size required is 32 or less, in which case we bump the size
13171 -- up to 32. This is required for C and C++ and seems reasonable for
13172 -- all other foreign conventions.
13174 if Has_Foreign_Convention (T)
13175 and then Esize (T) < Standard_Integer_Size
13177 -- Don't do this if Short_Enums on target
13179 and then not Target_Short_Enums
13181 Init_Esize (T, Standard_Integer_Size);
13183 Init_Esize (T, Sz);
13185 end Set_Enum_Esize;
13187 -----------------------------
13188 -- Uninstall_Discriminants --
13189 -----------------------------
13191 procedure Uninstall_Discriminants (E : Entity_Id) is
13197 -- Discriminants have been made visible for type declarations and
13198 -- protected type declarations, not for subtype declarations.
13200 if Nkind (Parent (E)) /= N_Subtype_Declaration then
13201 Disc := First_Discriminant (E);
13202 while Present (Disc) loop
13203 if Disc /= Current_Entity (Disc) then
13204 Prev := Current_Entity (Disc);
13205 while Present (Prev)
13206 and then Present (Homonym (Prev))
13207 and then Homonym (Prev) /= Disc
13209 Prev := Homonym (Prev);
13215 Set_Is_Immediately_Visible (Disc, False);
13217 Outer := Homonym (Disc);
13218 while Present (Outer) and then Scope (Outer) = E loop
13219 Outer := Homonym (Outer);
13222 -- Reset homonym link of other entities, but do not modify link
13223 -- between entities in current scope, so that the back end can
13224 -- have a proper count of local overloadings.
13227 Set_Name_Entity_Id (Chars (Disc), Outer);
13229 elsif Scope (Prev) /= Scope (Disc) then
13230 Set_Homonym (Prev, Outer);
13233 Next_Discriminant (Disc);
13236 end Uninstall_Discriminants;
13238 -------------------------------------------
13239 -- Uninstall_Discriminants_And_Pop_Scope --
13240 -------------------------------------------
13242 procedure Uninstall_Discriminants_And_Pop_Scope (E : Entity_Id) is
13244 if Has_Discriminants (E) then
13245 Uninstall_Discriminants (E);
13248 end Uninstall_Discriminants_And_Pop_Scope;
13250 ------------------------------
13251 -- Validate_Address_Clauses --
13252 ------------------------------
13254 procedure Validate_Address_Clauses is
13255 function Offset_Value (Expr : Node_Id) return Uint;
13256 -- Given an Address attribute reference, return the value in bits of its
13257 -- offset from the first bit of the underlying entity, or 0 if it is not
13258 -- known at compile time.
13264 function Offset_Value (Expr : Node_Id) return Uint is
13265 N : Node_Id := Prefix (Expr);
13267 Val : Uint := Uint_0;
13270 -- Climb the prefix chain and compute the cumulative offset
13273 if Is_Entity_Name (N) then
13276 elsif Nkind (N) = N_Selected_Component then
13277 Off := Component_Bit_Offset (Entity (Selector_Name (N)));
13278 if Off /= No_Uint and then Off >= Uint_0 then
13285 elsif Nkind (N) = N_Indexed_Component then
13286 Off := Indexed_Component_Bit_Offset (N);
13287 if Off /= No_Uint then
13300 -- Start of processing for Validate_Address_Clauses
13303 for J in Address_Clause_Checks.First .. Address_Clause_Checks.Last loop
13305 ACCR : Address_Clause_Check_Record
13306 renames Address_Clause_Checks.Table (J);
13310 X_Alignment : Uint;
13311 Y_Alignment : Uint;
13319 -- Skip processing of this entry if warning already posted
13321 if not Address_Warning_Posted (ACCR.N) then
13322 Expr := Original_Node (Expression (ACCR.N));
13324 -- Get alignments, sizes and offset, if any
13326 X_Alignment := Alignment (ACCR.X);
13327 X_Size := Esize (ACCR.X);
13329 if Present (ACCR.Y) then
13330 Y_Alignment := Alignment (ACCR.Y);
13331 Y_Size := Esize (ACCR.Y);
13335 and then Nkind (Expr) = N_Attribute_Reference
13336 and then Attribute_Name (Expr) = Name_Address
13338 X_Offs := Offset_Value (Expr);
13343 -- Check for known value not multiple of alignment
13345 if No (ACCR.Y) then
13346 if not Alignment_Checks_Suppressed (ACCR.X)
13347 and then X_Alignment /= 0
13348 and then ACCR.A mod X_Alignment /= 0
13351 ("??specified address for& is inconsistent with "
13352 & "alignment", ACCR.N, ACCR.X);
13354 ("\??program execution may be erroneous (RM 13.3(27))",
13357 Error_Msg_Uint_1 := X_Alignment;
13358 Error_Msg_NE ("\??alignment of & is ^", ACCR.N, ACCR.X);
13361 -- Check for large object overlaying smaller one
13363 elsif Y_Size > Uint_0
13364 and then X_Size > Uint_0
13365 and then X_Offs + X_Size > Y_Size
13367 Error_Msg_NE ("??& overlays smaller object", ACCR.N, ACCR.X);
13369 ("\??program execution may be erroneous", ACCR.N);
13371 Error_Msg_Uint_1 := X_Size;
13372 Error_Msg_NE ("\??size of & is ^", ACCR.N, ACCR.X);
13374 Error_Msg_Uint_1 := Y_Size;
13375 Error_Msg_NE ("\??size of & is ^", ACCR.N, ACCR.Y);
13377 if Y_Size >= X_Size then
13378 Error_Msg_Uint_1 := X_Offs;
13379 Error_Msg_NE ("\??but offset of & is ^", ACCR.N, ACCR.X);
13382 -- Check for inadequate alignment, both of the base object
13383 -- and of the offset, if any. We only do this check if the
13384 -- run-time Alignment_Check is active. No point in warning
13385 -- if this check has been suppressed (or is suppressed by
13386 -- default in the non-strict alignment machine case).
13388 -- Note: we do not check the alignment if we gave a size
13389 -- warning, since it would likely be redundant.
13391 elsif not Alignment_Checks_Suppressed (ACCR.X)
13392 and then Y_Alignment /= Uint_0
13394 (Y_Alignment < X_Alignment
13397 and then Nkind (Expr) = N_Attribute_Reference
13398 and then Attribute_Name (Expr) = Name_Address
13399 and then Has_Compatible_Alignment
13400 (ACCR.X, Prefix (Expr), True) /=
13404 ("??specified address for& may be inconsistent with "
13405 & "alignment", ACCR.N, ACCR.X);
13407 ("\??program execution may be erroneous (RM 13.3(27))",
13410 Error_Msg_Uint_1 := X_Alignment;
13411 Error_Msg_NE ("\??alignment of & is ^", ACCR.N, ACCR.X);
13413 Error_Msg_Uint_1 := Y_Alignment;
13414 Error_Msg_NE ("\??alignment of & is ^", ACCR.N, ACCR.Y);
13416 if Y_Alignment >= X_Alignment then
13418 ("\??but offset is not multiple of alignment", ACCR.N);
13424 end Validate_Address_Clauses;
13426 -----------------------------------------
13427 -- Validate_Compile_Time_Warning_Error --
13428 -----------------------------------------
13430 procedure Validate_Compile_Time_Warning_Error (N : Node_Id) is
13432 Compile_Time_Warnings_Errors.Append
13433 (New_Val => CTWE_Entry'(Eloc => Sloc (N),
13434 Scope => Current_Scope,
13436 end Validate_Compile_Time_Warning_Error;
13438 ------------------------------------------
13439 -- Validate_Compile_Time_Warning_Errors --
13440 ------------------------------------------
13442 procedure Validate_Compile_Time_Warning_Errors is
13443 procedure Set_Scope (S : Entity_Id);
13444 -- Install all enclosing scopes of S along with S itself
13446 procedure Unset_Scope (S : Entity_Id);
13447 -- Uninstall all enclosing scopes of S along with S itself
13453 procedure Set_Scope (S : Entity_Id) is
13455 if S /= Standard_Standard then
13456 Set_Scope (Scope (S));
13466 procedure Unset_Scope (S : Entity_Id) is
13468 if S /= Standard_Standard then
13469 Unset_Scope (Scope (S));
13475 -- Start of processing for Validate_Compile_Time_Warning_Errors
13478 Expander_Mode_Save_And_Set (False);
13479 In_Compile_Time_Warning_Or_Error := True;
13481 for N in Compile_Time_Warnings_Errors.First ..
13482 Compile_Time_Warnings_Errors.Last
13485 T : CTWE_Entry renames Compile_Time_Warnings_Errors.Table (N);
13488 Set_Scope (T.Scope);
13489 Reset_Analyzed_Flags (T.Prag);
13490 Process_Compile_Time_Warning_Or_Error (T.Prag, T.Eloc);
13491 Unset_Scope (T.Scope);
13495 In_Compile_Time_Warning_Or_Error := False;
13496 Expander_Mode_Restore;
13497 end Validate_Compile_Time_Warning_Errors;
13499 ---------------------------
13500 -- Validate_Independence --
13501 ---------------------------
13503 procedure Validate_Independence is
13504 SU : constant Uint := UI_From_Int (System_Storage_Unit);
13512 procedure Check_Array_Type (Atyp : Entity_Id);
13513 -- Checks if the array type Atyp has independent components, and
13514 -- if not, outputs an appropriate set of error messages.
13516 procedure No_Independence;
13517 -- Output message that independence cannot be guaranteed
13519 function OK_Component (C : Entity_Id) return Boolean;
13520 -- Checks one component to see if it is independently accessible, and
13521 -- if so yields True, otherwise yields False if independent access
13522 -- cannot be guaranteed. This is a conservative routine, it only
13523 -- returns True if it knows for sure, it returns False if it knows
13524 -- there is a problem, or it cannot be sure there is no problem.
13526 procedure Reason_Bad_Component (C : Entity_Id);
13527 -- Outputs continuation message if a reason can be determined for
13528 -- the component C being bad.
13530 ----------------------
13531 -- Check_Array_Type --
13532 ----------------------
13534 procedure Check_Array_Type (Atyp : Entity_Id) is
13535 Ctyp : constant Entity_Id := Component_Type (Atyp);
13538 -- OK if no alignment clause, no pack, and no component size
13540 if not Has_Component_Size_Clause (Atyp)
13541 and then not Has_Alignment_Clause (Atyp)
13542 and then not Is_Packed (Atyp)
13547 -- Case of component size is greater than or equal to 64 and the
13548 -- alignment of the array is at least as large as the alignment
13549 -- of the component. We are definitely OK in this situation.
13551 if Known_Component_Size (Atyp)
13552 and then Component_Size (Atyp) >= 64
13553 and then Known_Alignment (Atyp)
13554 and then Known_Alignment (Ctyp)
13555 and then Alignment (Atyp) >= Alignment (Ctyp)
13560 -- Check actual component size
13562 if not Known_Component_Size (Atyp)
13563 or else not (Addressable (Component_Size (Atyp))
13564 and then Component_Size (Atyp) < 64)
13565 or else Component_Size (Atyp) mod Esize (Ctyp) /= 0
13569 -- Bad component size, check reason
13571 if Has_Component_Size_Clause (Atyp) then
13572 P := Get_Attribute_Definition_Clause
13573 (Atyp, Attribute_Component_Size);
13575 if Present (P) then
13576 Error_Msg_Sloc := Sloc (P);
13577 Error_Msg_N ("\because of Component_Size clause#", N);
13582 if Is_Packed (Atyp) then
13583 P := Get_Rep_Pragma (Atyp, Name_Pack);
13585 if Present (P) then
13586 Error_Msg_Sloc := Sloc (P);
13587 Error_Msg_N ("\because of pragma Pack#", N);
13592 -- No reason found, just return
13597 -- Array type is OK independence-wise
13600 end Check_Array_Type;
13602 ---------------------
13603 -- No_Independence --
13604 ---------------------
13606 procedure No_Independence is
13608 if Pragma_Name (N) = Name_Independent then
13609 Error_Msg_NE ("independence cannot be guaranteed for&", N, E);
13612 ("independent components cannot be guaranteed for&", N, E);
13614 end No_Independence;
13620 function OK_Component (C : Entity_Id) return Boolean is
13621 Rec : constant Entity_Id := Scope (C);
13622 Ctyp : constant Entity_Id := Etype (C);
13625 -- OK if no component clause, no Pack, and no alignment clause
13627 if No (Component_Clause (C))
13628 and then not Is_Packed (Rec)
13629 and then not Has_Alignment_Clause (Rec)
13634 -- Here we look at the actual component layout. A component is
13635 -- addressable if its size is a multiple of the Esize of the
13636 -- component type, and its starting position in the record has
13637 -- appropriate alignment, and the record itself has appropriate
13638 -- alignment to guarantee the component alignment.
13640 -- Make sure sizes are static, always assume the worst for any
13641 -- cases where we cannot check static values.
13643 if not (Known_Static_Esize (C)
13645 Known_Static_Esize (Ctyp))
13650 -- Size of component must be addressable or greater than 64 bits
13651 -- and a multiple of bytes.
13653 if not Addressable (Esize (C)) and then Esize (C) < Uint_64 then
13657 -- Check size is proper multiple
13659 if Esize (C) mod Esize (Ctyp) /= 0 then
13663 -- Check alignment of component is OK
13665 if not Known_Component_Bit_Offset (C)
13666 or else Component_Bit_Offset (C) < Uint_0
13667 or else Component_Bit_Offset (C) mod Esize (Ctyp) /= 0
13672 -- Check alignment of record type is OK
13674 if not Known_Alignment (Rec)
13675 or else (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0
13680 -- All tests passed, component is addressable
13685 --------------------------
13686 -- Reason_Bad_Component --
13687 --------------------------
13689 procedure Reason_Bad_Component (C : Entity_Id) is
13690 Rec : constant Entity_Id := Scope (C);
13691 Ctyp : constant Entity_Id := Etype (C);
13694 -- If component clause present assume that's the problem
13696 if Present (Component_Clause (C)) then
13697 Error_Msg_Sloc := Sloc (Component_Clause (C));
13698 Error_Msg_N ("\because of Component_Clause#", N);
13702 -- If pragma Pack clause present, assume that's the problem
13704 if Is_Packed (Rec) then
13705 P := Get_Rep_Pragma (Rec, Name_Pack);
13707 if Present (P) then
13708 Error_Msg_Sloc := Sloc (P);
13709 Error_Msg_N ("\because of pragma Pack#", N);
13714 -- See if record has bad alignment clause
13716 if Has_Alignment_Clause (Rec)
13717 and then Known_Alignment (Rec)
13718 and then (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0
13720 P := Get_Attribute_Definition_Clause (Rec, Attribute_Alignment);
13722 if Present (P) then
13723 Error_Msg_Sloc := Sloc (P);
13724 Error_Msg_N ("\because of Alignment clause#", N);
13728 -- Couldn't find a reason, so return without a message
13731 end Reason_Bad_Component;
13733 -- Start of processing for Validate_Independence
13736 for J in Independence_Checks.First .. Independence_Checks.Last loop
13737 N := Independence_Checks.Table (J).N;
13738 E := Independence_Checks.Table (J).E;
13739 IC := Pragma_Name (N) = Name_Independent_Components;
13741 -- Deal with component case
13743 if Ekind (E) = E_Discriminant or else Ekind (E) = E_Component then
13744 if not OK_Component (E) then
13746 Reason_Bad_Component (E);
13751 -- Deal with record with Independent_Components
13753 if IC and then Is_Record_Type (E) then
13754 Comp := First_Component_Or_Discriminant (E);
13755 while Present (Comp) loop
13756 if not OK_Component (Comp) then
13758 Reason_Bad_Component (Comp);
13762 Next_Component_Or_Discriminant (Comp);
13766 -- Deal with address clause case
13768 if Is_Object (E) then
13769 Addr := Address_Clause (E);
13771 if Present (Addr) then
13773 Error_Msg_Sloc := Sloc (Addr);
13774 Error_Msg_N ("\because of Address clause#", N);
13779 -- Deal with independent components for array type
13781 if IC and then Is_Array_Type (E) then
13782 Check_Array_Type (E);
13785 -- Deal with independent components for array object
13787 if IC and then Is_Object (E) and then Is_Array_Type (Etype (E)) then
13788 Check_Array_Type (Etype (E));
13793 end Validate_Independence;
13795 ------------------------------
13796 -- Validate_Iterable_Aspect --
13797 ------------------------------
13799 procedure Validate_Iterable_Aspect (Typ : Entity_Id; ASN : Node_Id) is
13804 Cursor : constant Entity_Id := Get_Cursor_Type (ASN, Typ);
13806 First_Id : Entity_Id;
13807 Next_Id : Entity_Id;
13808 Has_Element_Id : Entity_Id;
13809 Element_Id : Entity_Id;
13812 -- If previous error aspect is unusable
13814 if Cursor = Any_Type then
13820 Has_Element_Id := Empty;
13821 Element_Id := Empty;
13823 -- Each expression must resolve to a function with the proper signature
13825 Assoc := First (Component_Associations (Expression (ASN)));
13826 while Present (Assoc) loop
13827 Expr := Expression (Assoc);
13830 Prim := First (Choices (Assoc));
13832 if Nkind (Prim) /= N_Identifier or else Present (Next (Prim)) then
13833 Error_Msg_N ("illegal name in association", Prim);
13835 elsif Chars (Prim) = Name_First then
13836 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_First);
13837 First_Id := Entity (Expr);
13839 elsif Chars (Prim) = Name_Next then
13840 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Next);
13841 Next_Id := Entity (Expr);
13843 elsif Chars (Prim) = Name_Has_Element then
13844 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Has_Element);
13845 Has_Element_Id := Entity (Expr);
13847 elsif Chars (Prim) = Name_Element then
13848 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Element);
13849 Element_Id := Entity (Expr);
13852 Error_Msg_N ("invalid name for iterable function", Prim);
13858 if No (First_Id) then
13859 Error_Msg_N ("match for First primitive not found", ASN);
13861 elsif No (Next_Id) then
13862 Error_Msg_N ("match for Next primitive not found", ASN);
13864 elsif No (Has_Element_Id) then
13865 Error_Msg_N ("match for Has_Element primitive not found", ASN);
13867 elsif No (Element_Id) then
13870 end Validate_Iterable_Aspect;
13872 -----------------------------------
13873 -- Validate_Unchecked_Conversion --
13874 -----------------------------------
13876 procedure Validate_Unchecked_Conversion
13878 Act_Unit : Entity_Id)
13880 Source : Entity_Id;
13881 Target : Entity_Id;
13885 -- Obtain source and target types. Note that we call Ancestor_Subtype
13886 -- here because the processing for generic instantiation always makes
13887 -- subtypes, and we want the original frozen actual types.
13889 -- If we are dealing with private types, then do the check on their
13890 -- fully declared counterparts if the full declarations have been
13891 -- encountered (they don't have to be visible, but they must exist).
13893 Source := Ancestor_Subtype (Etype (First_Formal (Act_Unit)));
13895 if Is_Private_Type (Source)
13896 and then Present (Underlying_Type (Source))
13898 Source := Underlying_Type (Source);
13901 Target := Ancestor_Subtype (Etype (Act_Unit));
13903 -- If either type is generic, the instantiation happens within a generic
13904 -- unit, and there is nothing to check. The proper check will happen
13905 -- when the enclosing generic is instantiated.
13907 if Is_Generic_Type (Source) or else Is_Generic_Type (Target) then
13911 if Is_Private_Type (Target)
13912 and then Present (Underlying_Type (Target))
13914 Target := Underlying_Type (Target);
13917 -- Source may be unconstrained array, but not target, except in relaxed
13920 if Is_Array_Type (Target)
13921 and then not Is_Constrained (Target)
13922 and then not Relaxed_RM_Semantics
13925 ("unchecked conversion to unconstrained array not allowed", N);
13929 -- Warn if conversion between two different convention pointers
13931 if Is_Access_Type (Target)
13932 and then Is_Access_Type (Source)
13933 and then Convention (Target) /= Convention (Source)
13934 and then Warn_On_Unchecked_Conversion
13936 -- Give warnings for subprogram pointers only on most targets
13938 if Is_Access_Subprogram_Type (Target)
13939 or else Is_Access_Subprogram_Type (Source)
13942 ("?z?conversion between pointers with different conventions!",
13947 -- Warn if one of the operands is Ada.Calendar.Time. Do not emit a
13948 -- warning when compiling GNAT-related sources.
13950 if Warn_On_Unchecked_Conversion
13951 and then not In_Predefined_Unit (N)
13952 and then RTU_Loaded (Ada_Calendar)
13953 and then (Chars (Source) = Name_Time
13955 Chars (Target) = Name_Time)
13957 -- If Ada.Calendar is loaded and the name of one of the operands is
13958 -- Time, there is a good chance that this is Ada.Calendar.Time.
13961 Calendar_Time : constant Entity_Id := Full_View (RTE (RO_CA_Time));
13963 pragma Assert (Present (Calendar_Time));
13965 if Source = Calendar_Time or else Target = Calendar_Time then
13967 ("?z?representation of 'Time values may change between "
13968 & "'G'N'A'T versions", N);
13973 -- Make entry in unchecked conversion table for later processing by
13974 -- Validate_Unchecked_Conversions, which will check sizes and alignments
13975 -- (using values set by the back end where possible). This is only done
13976 -- if the appropriate warning is active.
13978 if Warn_On_Unchecked_Conversion then
13979 Unchecked_Conversions.Append
13980 (New_Val => UC_Entry'(Eloc => Sloc (N),
13983 Act_Unit => Act_Unit));
13985 -- If both sizes are known statically now, then back-end annotation
13986 -- is not required to do a proper check but if either size is not
13987 -- known statically, then we need the annotation.
13989 if Known_Static_RM_Size (Source)
13991 Known_Static_RM_Size (Target)
13995 Back_Annotate_Rep_Info := True;
13999 -- If unchecked conversion to access type, and access type is declared
14000 -- in the same unit as the unchecked conversion, then set the flag
14001 -- No_Strict_Aliasing (no strict aliasing is implicit here)
14003 if Is_Access_Type (Target) and then
14004 In_Same_Source_Unit (Target, N)
14006 Set_No_Strict_Aliasing (Implementation_Base_Type (Target));
14009 -- Generate N_Validate_Unchecked_Conversion node for back end in case
14010 -- the back end needs to perform special validation checks.
14012 -- Shouldn't this be in Exp_Ch13, since the check only gets done if we
14013 -- have full expansion and the back end is called ???
14016 Make_Validate_Unchecked_Conversion (Sloc (N));
14017 Set_Source_Type (Vnode, Source);
14018 Set_Target_Type (Vnode, Target);
14020 -- If the unchecked conversion node is in a list, just insert before it.
14021 -- If not we have some strange case, not worth bothering about.
14023 if Is_List_Member (N) then
14024 Insert_After (N, Vnode);
14026 end Validate_Unchecked_Conversion;
14028 ------------------------------------
14029 -- Validate_Unchecked_Conversions --
14030 ------------------------------------
14032 procedure Validate_Unchecked_Conversions is
14034 for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop
14036 T : UC_Entry renames Unchecked_Conversions.Table (N);
14038 Act_Unit : constant Entity_Id := T.Act_Unit;
14039 Eloc : constant Source_Ptr := T.Eloc;
14040 Source : constant Entity_Id := T.Source;
14041 Target : constant Entity_Id := T.Target;
14047 -- Skip if function marked as warnings off
14049 if Warnings_Off (Act_Unit) then
14053 -- This validation check, which warns if we have unequal sizes for
14054 -- unchecked conversion, and thus potentially implementation
14055 -- dependent semantics, is one of the few occasions on which we
14056 -- use the official RM size instead of Esize. See description in
14057 -- Einfo "Handling of Type'Size Values" for details.
14059 if Serious_Errors_Detected = 0
14060 and then Known_Static_RM_Size (Source)
14061 and then Known_Static_RM_Size (Target)
14063 -- Don't do the check if warnings off for either type, note the
14064 -- deliberate use of OR here instead of OR ELSE to get the flag
14065 -- Warnings_Off_Used set for both types if appropriate.
14067 and then not (Has_Warnings_Off (Source)
14069 Has_Warnings_Off (Target))
14071 Source_Siz := RM_Size (Source);
14072 Target_Siz := RM_Size (Target);
14074 if Source_Siz /= Target_Siz then
14076 ("?z?types for unchecked conversion have different sizes!",
14079 if All_Errors_Mode then
14080 Error_Msg_Name_1 := Chars (Source);
14081 Error_Msg_Uint_1 := Source_Siz;
14082 Error_Msg_Name_2 := Chars (Target);
14083 Error_Msg_Uint_2 := Target_Siz;
14084 Error_Msg ("\size of % is ^, size of % is ^?z?", Eloc);
14086 Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz);
14088 if Is_Discrete_Type (Source)
14090 Is_Discrete_Type (Target)
14092 if Source_Siz > Target_Siz then
14094 ("\?z?^ high order bits of source will "
14095 & "be ignored!", Eloc);
14097 elsif Is_Unsigned_Type (Source) then
14099 ("\?z?source will be extended with ^ high order "
14100 & "zero bits!", Eloc);
14104 ("\?z?source will be extended with ^ high order "
14105 & "sign bits!", Eloc);
14108 elsif Source_Siz < Target_Siz then
14109 if Is_Discrete_Type (Target) then
14110 if Bytes_Big_Endian then
14112 ("\?z?target value will include ^ undefined "
14113 & "low order bits!", Eloc);
14116 ("\?z?target value will include ^ undefined "
14117 & "high order bits!", Eloc);
14122 ("\?z?^ trailing bits of target value will be "
14123 & "undefined!", Eloc);
14126 else pragma Assert (Source_Siz > Target_Siz);
14127 if Is_Discrete_Type (Source) then
14128 if Bytes_Big_Endian then
14130 ("\?z?^ low order bits of source will be "
14131 & "ignored!", Eloc);
14134 ("\?z?^ high order bits of source will be "
14135 & "ignored!", Eloc);
14140 ("\?z?^ trailing bits of source will be "
14141 & "ignored!", Eloc);
14148 -- If both types are access types, we need to check the alignment.
14149 -- If the alignment of both is specified, we can do it here.
14151 if Serious_Errors_Detected = 0
14152 and then Is_Access_Type (Source)
14153 and then Is_Access_Type (Target)
14154 and then Target_Strict_Alignment
14155 and then Present (Designated_Type (Source))
14156 and then Present (Designated_Type (Target))
14159 D_Source : constant Entity_Id := Designated_Type (Source);
14160 D_Target : constant Entity_Id := Designated_Type (Target);
14163 if Known_Alignment (D_Source)
14165 Known_Alignment (D_Target)
14168 Source_Align : constant Uint := Alignment (D_Source);
14169 Target_Align : constant Uint := Alignment (D_Target);
14172 if Source_Align < Target_Align
14173 and then not Is_Tagged_Type (D_Source)
14175 -- Suppress warning if warnings suppressed on either
14176 -- type or either designated type. Note the use of
14177 -- OR here instead of OR ELSE. That is intentional,
14178 -- we would like to set flag Warnings_Off_Used in
14179 -- all types for which warnings are suppressed.
14181 and then not (Has_Warnings_Off (D_Source)
14183 Has_Warnings_Off (D_Target)
14185 Has_Warnings_Off (Source)
14187 Has_Warnings_Off (Target))
14189 Error_Msg_Uint_1 := Target_Align;
14190 Error_Msg_Uint_2 := Source_Align;
14191 Error_Msg_Node_1 := D_Target;
14192 Error_Msg_Node_2 := D_Source;
14194 ("?z?alignment of & (^) is stricter than "
14195 & "alignment of & (^)!", Eloc);
14197 ("\?z?resulting access value may have invalid "
14198 & "alignment!", Eloc);
14209 end Validate_Unchecked_Conversions;