1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2013, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Aspects
; use Aspects
;
27 with Atree
; use Atree
;
28 with Checks
; use Checks
;
29 with Debug
; use Debug
;
30 with Einfo
; use Einfo
;
31 with Elists
; use Elists
;
32 with Errout
; use Errout
;
33 with Exp_Disp
; use Exp_Disp
;
34 with Exp_Tss
; use Exp_Tss
;
35 with Exp_Util
; use Exp_Util
;
37 with Lib
.Xref
; use Lib
.Xref
;
38 with Namet
; use Namet
;
39 with Nlists
; use Nlists
;
40 with Nmake
; use Nmake
;
42 with Restrict
; use Restrict
;
43 with Rident
; use Rident
;
44 with Rtsfind
; use Rtsfind
;
46 with Sem_Aux
; use Sem_Aux
;
47 with Sem_Case
; use Sem_Case
;
48 with Sem_Ch3
; use Sem_Ch3
;
49 with Sem_Ch6
; use Sem_Ch6
;
50 with Sem_Ch8
; use Sem_Ch8
;
51 with Sem_Ch9
; use Sem_Ch9
;
52 with Sem_Dim
; use Sem_Dim
;
53 with Sem_Disp
; use Sem_Disp
;
54 with Sem_Eval
; use Sem_Eval
;
55 with Sem_Prag
; use Sem_Prag
;
56 with Sem_Res
; use Sem_Res
;
57 with Sem_Type
; use Sem_Type
;
58 with Sem_Util
; use Sem_Util
;
59 with Sem_Warn
; use Sem_Warn
;
60 with Sinput
; use Sinput
;
61 with Snames
; use Snames
;
62 with Stand
; use Stand
;
63 with Sinfo
; use Sinfo
;
64 with Stringt
; use Stringt
;
65 with Targparm
; use Targparm
;
66 with Ttypes
; use Ttypes
;
67 with Tbuild
; use Tbuild
;
68 with Urealp
; use Urealp
;
69 with Warnsw
; use Warnsw
;
71 with GNAT
.Heap_Sort_G
;
73 package body Sem_Ch13
is
75 SSU
: constant Pos
:= System_Storage_Unit
;
76 -- Convenient short hand for commonly used constant
78 -----------------------
79 -- Local Subprograms --
80 -----------------------
82 procedure Alignment_Check_For_Size_Change
(Typ
: Entity_Id
; Size
: Uint
);
83 -- This routine is called after setting one of the sizes of type entity
84 -- Typ to Size. The purpose is to deal with the situation of a derived
85 -- type whose inherited alignment is no longer appropriate for the new
86 -- size value. In this case, we reset the Alignment to unknown.
88 procedure Build_Predicate_Functions
(Typ
: Entity_Id
; N
: Node_Id
);
89 -- If Typ has predicates (indicated by Has_Predicates being set for Typ,
90 -- then either there are pragma Predicate entries on the rep chain for the
91 -- type (note that Predicate aspects are converted to pragma Predicate), or
92 -- there are inherited aspects from a parent type, or ancestor subtypes.
93 -- This procedure builds the spec and body for the Predicate function that
94 -- tests these predicates. N is the freeze node for the type. The spec of
95 -- the function is inserted before the freeze node, and the body of the
96 -- function is inserted after the freeze node. If the predicate expression
97 -- has at least one Raise_Expression, then this procedure also builds the
98 -- M version of the predicate function for use in membership tests.
100 procedure Build_Static_Predicate
104 -- Given a predicated type Typ, where Typ is a discrete static subtype,
105 -- whose predicate expression is Expr, tests if Expr is a static predicate,
106 -- and if so, builds the predicate range list. Nam is the name of the one
107 -- argument to the predicate function. Occurrences of the type name in the
108 -- predicate expression have been replaced by identifier references to this
109 -- name, which is unique, so any identifier with Chars matching Nam must be
110 -- a reference to the type. If the predicate is non-static, this procedure
111 -- returns doing nothing. If the predicate is static, then the predicate
112 -- list is stored in Static_Predicate (Typ), and the Expr is rewritten as
113 -- a canonicalized membership operation.
115 procedure Freeze_Entity_Checks
(N
: Node_Id
);
116 -- Called from Analyze_Freeze_Entity and Analyze_Generic_Freeze Entity
117 -- to generate appropriate semantic checks that are delayed until this
118 -- point (they had to be delayed this long for cases of delayed aspects,
119 -- e.g. analysis of statically predicated subtypes in choices, for which
120 -- we have to be sure the subtypes in question are frozen before checking.
122 function Get_Alignment_Value
(Expr
: Node_Id
) return Uint
;
123 -- Given the expression for an alignment value, returns the corresponding
124 -- Uint value. If the value is inappropriate, then error messages are
125 -- posted as required, and a value of No_Uint is returned.
127 function Is_Operational_Item
(N
: Node_Id
) return Boolean;
128 -- A specification for a stream attribute is allowed before the full type
129 -- is declared, as explained in AI-00137 and the corrigendum. Attributes
130 -- that do not specify a representation characteristic are operational
133 procedure New_Stream_Subprogram
137 Nam
: TSS_Name_Type
);
138 -- Create a subprogram renaming of a given stream attribute to the
139 -- designated subprogram and then in the tagged case, provide this as a
140 -- primitive operation, or in the non-tagged case make an appropriate TSS
141 -- entry. This is more properly an expansion activity than just semantics,
142 -- but the presence of user-defined stream functions for limited types is a
143 -- legality check, which is why this takes place here rather than in
144 -- exp_ch13, where it was previously. Nam indicates the name of the TSS
145 -- function to be generated.
147 -- To avoid elaboration anomalies with freeze nodes, for untagged types
148 -- we generate both a subprogram declaration and a subprogram renaming
149 -- declaration, so that the attribute specification is handled as a
150 -- renaming_as_body. For tagged types, the specification is one of the
154 with procedure Replace_Type_Reference
(N
: Node_Id
);
155 procedure Replace_Type_References_Generic
(N
: Node_Id
; TName
: Name_Id
);
156 -- This is used to scan an expression for a predicate or invariant aspect
157 -- replacing occurrences of the name TName (the name of the subtype to
158 -- which the aspect applies) with appropriate references to the parameter
159 -- of the predicate function or invariant procedure. The procedure passed
160 -- as a generic parameter does the actual replacement of node N, which is
161 -- either a simple direct reference to TName, or a selected component that
162 -- represents an appropriately qualified occurrence of TName.
168 Biased
: Boolean := True);
169 -- If Biased is True, sets Has_Biased_Representation flag for E, and
170 -- outputs a warning message at node N if Warn_On_Biased_Representation is
171 -- is True. This warning inserts the string Msg to describe the construct
174 ----------------------------------------------
175 -- Table for Validate_Unchecked_Conversions --
176 ----------------------------------------------
178 -- The following table collects unchecked conversions for validation.
179 -- Entries are made by Validate_Unchecked_Conversion and then the call
180 -- to Validate_Unchecked_Conversions does the actual error checking and
181 -- posting of warnings. The reason for this delayed processing is to take
182 -- advantage of back-annotations of size and alignment values performed by
185 -- Note: the reason we store a Source_Ptr value instead of a Node_Id is
186 -- that by the time Validate_Unchecked_Conversions is called, Sprint will
187 -- already have modified all Sloc values if the -gnatD option is set.
189 type UC_Entry
is record
190 Eloc
: Source_Ptr
; -- node used for posting warnings
191 Source
: Entity_Id
; -- source type for unchecked conversion
192 Target
: Entity_Id
; -- target type for unchecked conversion
195 package Unchecked_Conversions
is new Table
.Table
(
196 Table_Component_Type
=> UC_Entry
,
197 Table_Index_Type
=> Int
,
198 Table_Low_Bound
=> 1,
200 Table_Increment
=> 200,
201 Table_Name
=> "Unchecked_Conversions");
203 ----------------------------------------
204 -- Table for Validate_Address_Clauses --
205 ----------------------------------------
207 -- If an address clause has the form
209 -- for X'Address use Expr
211 -- where Expr is of the form Y'Address or recursively is a reference to a
212 -- constant of either of these forms, and X and Y are entities of objects,
213 -- then if Y has a smaller alignment than X, that merits a warning about
214 -- possible bad alignment. The following table collects address clauses of
215 -- this kind. We put these in a table so that they can be checked after the
216 -- back end has completed annotation of the alignments of objects, since we
217 -- can catch more cases that way.
219 type Address_Clause_Check_Record
is record
221 -- The address clause
224 -- The entity of the object overlaying Y
227 -- The entity of the object being overlaid
230 -- Whether the address is offset within Y
233 package Address_Clause_Checks
is new Table
.Table
(
234 Table_Component_Type
=> Address_Clause_Check_Record
,
235 Table_Index_Type
=> Int
,
236 Table_Low_Bound
=> 1,
238 Table_Increment
=> 200,
239 Table_Name
=> "Address_Clause_Checks");
241 -----------------------------------------
242 -- Adjust_Record_For_Reverse_Bit_Order --
243 -----------------------------------------
245 procedure Adjust_Record_For_Reverse_Bit_Order
(R
: Entity_Id
) is
250 -- Processing depends on version of Ada
252 -- For Ada 95, we just renumber bits within a storage unit. We do the
253 -- same for Ada 83 mode, since we recognize the Bit_Order attribute in
254 -- Ada 83, and are free to add this extension.
256 if Ada_Version
< Ada_2005
then
257 Comp
:= First_Component_Or_Discriminant
(R
);
258 while Present
(Comp
) loop
259 CC
:= Component_Clause
(Comp
);
261 -- If component clause is present, then deal with the non-default
262 -- bit order case for Ada 95 mode.
264 -- We only do this processing for the base type, and in fact that
265 -- is important, since otherwise if there are record subtypes, we
266 -- could reverse the bits once for each subtype, which is wrong.
268 if Present
(CC
) and then Ekind
(R
) = E_Record_Type
then
270 CFB
: constant Uint
:= Component_Bit_Offset
(Comp
);
271 CSZ
: constant Uint
:= Esize
(Comp
);
272 CLC
: constant Node_Id
:= Component_Clause
(Comp
);
273 Pos
: constant Node_Id
:= Position
(CLC
);
274 FB
: constant Node_Id
:= First_Bit
(CLC
);
276 Storage_Unit_Offset
: constant Uint
:=
277 CFB
/ System_Storage_Unit
;
279 Start_Bit
: constant Uint
:=
280 CFB
mod System_Storage_Unit
;
283 -- Cases where field goes over storage unit boundary
285 if Start_Bit
+ CSZ
> System_Storage_Unit
then
287 -- Allow multi-byte field but generate warning
289 if Start_Bit
mod System_Storage_Unit
= 0
290 and then CSZ
mod System_Storage_Unit
= 0
293 ("multi-byte field specified with non-standard"
294 & " Bit_Order??", CLC
);
296 if Bytes_Big_Endian
then
298 ("bytes are not reversed "
299 & "(component is big-endian)??", CLC
);
302 ("bytes are not reversed "
303 & "(component is little-endian)??", CLC
);
306 -- Do not allow non-contiguous field
310 ("attempt to specify non-contiguous field "
311 & "not permitted", CLC
);
313 ("\caused by non-standard Bit_Order "
316 ("\consider possibility of using "
317 & "Ada 2005 mode here", CLC
);
320 -- Case where field fits in one storage unit
323 -- Give warning if suspicious component clause
325 if Intval
(FB
) >= System_Storage_Unit
326 and then Warn_On_Reverse_Bit_Order
329 ("Bit_Order clause does not affect " &
330 "byte ordering?V?", Pos
);
332 Intval
(Pos
) + Intval
(FB
) /
335 ("position normalized to ^ before bit " &
336 "order interpreted?V?", Pos
);
339 -- Here is where we fix up the Component_Bit_Offset value
340 -- to account for the reverse bit order. Some examples of
341 -- what needs to be done are:
343 -- First_Bit .. Last_Bit Component_Bit_Offset
355 -- The rule is that the first bit is is obtained by
356 -- subtracting the old ending bit from storage_unit - 1.
358 Set_Component_Bit_Offset
360 (Storage_Unit_Offset
* System_Storage_Unit
) +
361 (System_Storage_Unit
- 1) -
362 (Start_Bit
+ CSZ
- 1));
364 Set_Normalized_First_Bit
366 Component_Bit_Offset
(Comp
) mod
367 System_Storage_Unit
);
372 Next_Component_Or_Discriminant
(Comp
);
375 -- For Ada 2005, we do machine scalar processing, as fully described In
376 -- AI-133. This involves gathering all components which start at the
377 -- same byte offset and processing them together. Same approach is still
378 -- valid in later versions including Ada 2012.
382 Max_Machine_Scalar_Size
: constant Uint
:=
384 (Standard_Long_Long_Integer_Size
);
385 -- We use this as the maximum machine scalar size
388 SSU
: constant Uint
:= UI_From_Int
(System_Storage_Unit
);
391 -- This first loop through components does two things. First it
392 -- deals with the case of components with component clauses whose
393 -- length is greater than the maximum machine scalar size (either
394 -- accepting them or rejecting as needed). Second, it counts the
395 -- number of components with component clauses whose length does
396 -- not exceed this maximum for later processing.
399 Comp
:= First_Component_Or_Discriminant
(R
);
400 while Present
(Comp
) loop
401 CC
:= Component_Clause
(Comp
);
405 Fbit
: constant Uint
:= Static_Integer
(First_Bit
(CC
));
406 Lbit
: constant Uint
:= Static_Integer
(Last_Bit
(CC
));
409 -- Case of component with last bit >= max machine scalar
411 if Lbit
>= Max_Machine_Scalar_Size
then
413 -- This is allowed only if first bit is zero, and
414 -- last bit + 1 is a multiple of storage unit size.
416 if Fbit
= 0 and then (Lbit
+ 1) mod SSU
= 0 then
418 -- This is the case to give a warning if enabled
420 if Warn_On_Reverse_Bit_Order
then
422 ("multi-byte field specified with "
423 & " non-standard Bit_Order?V?", CC
);
425 if Bytes_Big_Endian
then
427 ("\bytes are not reversed "
428 & "(component is big-endian)?V?", CC
);
431 ("\bytes are not reversed "
432 & "(component is little-endian)?V?", CC
);
436 -- Give error message for RM 13.5.1(10) violation
440 ("machine scalar rules not followed for&",
441 First_Bit
(CC
), Comp
);
443 Error_Msg_Uint_1
:= Lbit
;
444 Error_Msg_Uint_2
:= Max_Machine_Scalar_Size
;
446 ("\last bit (^) exceeds maximum machine "
450 if (Lbit
+ 1) mod SSU
/= 0 then
451 Error_Msg_Uint_1
:= SSU
;
453 ("\and is not a multiple of Storage_Unit (^) "
458 Error_Msg_Uint_1
:= Fbit
;
460 ("\and first bit (^) is non-zero "
466 -- OK case of machine scalar related component clause,
467 -- For now, just count them.
470 Num_CC
:= Num_CC
+ 1;
475 Next_Component_Or_Discriminant
(Comp
);
478 -- We need to sort the component clauses on the basis of the
479 -- Position values in the clause, so we can group clauses with
480 -- the same Position. together to determine the relevant machine
484 Comps
: array (0 .. Num_CC
) of Entity_Id
;
485 -- Array to collect component and discriminant entities. The
486 -- data starts at index 1, the 0'th entry is for the sort
489 function CP_Lt
(Op1
, Op2
: Natural) return Boolean;
490 -- Compare routine for Sort
492 procedure CP_Move
(From
: Natural; To
: Natural);
493 -- Move routine for Sort
495 package Sorting
is new GNAT
.Heap_Sort_G
(CP_Move
, CP_Lt
);
499 -- Start and stop positions in the component list of the set of
500 -- components with the same starting position (that constitute
501 -- components in a single machine scalar).
504 -- Maximum last bit value of any component in this set
507 -- Corresponding machine scalar size
513 function CP_Lt
(Op1
, Op2
: Natural) return Boolean is
515 return Position
(Component_Clause
(Comps
(Op1
))) <
516 Position
(Component_Clause
(Comps
(Op2
)));
523 procedure CP_Move
(From
: Natural; To
: Natural) is
525 Comps
(To
) := Comps
(From
);
528 -- Start of processing for Sort_CC
531 -- Collect the machine scalar relevant component clauses
534 Comp
:= First_Component_Or_Discriminant
(R
);
535 while Present
(Comp
) loop
537 CC
: constant Node_Id
:= Component_Clause
(Comp
);
540 -- Collect only component clauses whose last bit is less
541 -- than machine scalar size. Any component clause whose
542 -- last bit exceeds this value does not take part in
543 -- machine scalar layout considerations. The test for
544 -- Error_Posted makes sure we exclude component clauses
545 -- for which we already posted an error.
548 and then not Error_Posted
(Last_Bit
(CC
))
549 and then Static_Integer
(Last_Bit
(CC
)) <
550 Max_Machine_Scalar_Size
552 Num_CC
:= Num_CC
+ 1;
553 Comps
(Num_CC
) := Comp
;
557 Next_Component_Or_Discriminant
(Comp
);
560 -- Sort by ascending position number
562 Sorting
.Sort
(Num_CC
);
564 -- We now have all the components whose size does not exceed
565 -- the max machine scalar value, sorted by starting position.
566 -- In this loop we gather groups of clauses starting at the
567 -- same position, to process them in accordance with AI-133.
570 while Stop
< Num_CC
loop
575 (Last_Bit
(Component_Clause
(Comps
(Start
))));
576 while Stop
< Num_CC
loop
578 (Position
(Component_Clause
(Comps
(Stop
+ 1)))) =
580 (Position
(Component_Clause
(Comps
(Stop
))))
588 (Component_Clause
(Comps
(Stop
)))));
594 -- Now we have a group of component clauses from Start to
595 -- Stop whose positions are identical, and MaxL is the
596 -- maximum last bit value of any of these components.
598 -- We need to determine the corresponding machine scalar
599 -- size. This loop assumes that machine scalar sizes are
600 -- even, and that each possible machine scalar has twice
601 -- as many bits as the next smaller one.
603 MSS
:= Max_Machine_Scalar_Size
;
605 and then (MSS
/ 2) >= SSU
606 and then (MSS
/ 2) > MaxL
611 -- Here is where we fix up the Component_Bit_Offset value
612 -- to account for the reverse bit order. Some examples of
613 -- what needs to be done for the case of a machine scalar
616 -- First_Bit .. Last_Bit Component_Bit_Offset
628 -- The rule is that the first bit is obtained by subtracting
629 -- the old ending bit from machine scalar size - 1.
631 for C
in Start
.. Stop
loop
633 Comp
: constant Entity_Id
:= Comps
(C
);
634 CC
: constant Node_Id
:= Component_Clause
(Comp
);
636 LB
: constant Uint
:= Static_Integer
(Last_Bit
(CC
));
637 NFB
: constant Uint
:= MSS
- Uint_1
- LB
;
638 NLB
: constant Uint
:= NFB
+ Esize
(Comp
) - 1;
639 Pos
: constant Uint
:= Static_Integer
(Position
(CC
));
642 if Warn_On_Reverse_Bit_Order
then
643 Error_Msg_Uint_1
:= MSS
;
645 ("info: reverse bit order in machine " &
646 "scalar of length^?V?", First_Bit
(CC
));
647 Error_Msg_Uint_1
:= NFB
;
648 Error_Msg_Uint_2
:= NLB
;
650 if Bytes_Big_Endian
then
652 ("\info: big-endian range for "
653 & "component & is ^ .. ^?V?",
654 First_Bit
(CC
), Comp
);
657 ("\info: little-endian range "
658 & "for component & is ^ .. ^?V?",
659 First_Bit
(CC
), Comp
);
663 Set_Component_Bit_Offset
(Comp
, Pos
* SSU
+ NFB
);
664 Set_Normalized_First_Bit
(Comp
, NFB
mod SSU
);
671 end Adjust_Record_For_Reverse_Bit_Order
;
673 -------------------------------------
674 -- Alignment_Check_For_Size_Change --
675 -------------------------------------
677 procedure Alignment_Check_For_Size_Change
(Typ
: Entity_Id
; Size
: Uint
) is
679 -- If the alignment is known, and not set by a rep clause, and is
680 -- inconsistent with the size being set, then reset it to unknown,
681 -- we assume in this case that the size overrides the inherited
682 -- alignment, and that the alignment must be recomputed.
684 if Known_Alignment
(Typ
)
685 and then not Has_Alignment_Clause
(Typ
)
686 and then Size
mod (Alignment
(Typ
) * SSU
) /= 0
688 Init_Alignment
(Typ
);
690 end Alignment_Check_For_Size_Change
;
692 -------------------------------------
693 -- Analyze_Aspects_At_Freeze_Point --
694 -------------------------------------
696 procedure Analyze_Aspects_At_Freeze_Point
(E
: Entity_Id
) is
701 procedure Analyze_Aspect_Default_Value
(ASN
: Node_Id
);
702 -- This routine analyzes an Aspect_Default_[Component_]Value denoted by
703 -- the aspect specification node ASN.
705 procedure Inherit_Delayed_Rep_Aspects
(ASN
: Node_Id
);
706 -- As discussed in the spec of Aspects (see Aspect_Delay declaration),
707 -- a derived type can inherit aspects from its parent which have been
708 -- specified at the time of the derivation using an aspect, as in:
710 -- type A is range 1 .. 10
711 -- with Size => Not_Defined_Yet;
715 -- Not_Defined_Yet : constant := 64;
717 -- In this example, the Size of A is considered to be specified prior
718 -- to the derivation, and thus inherited, even though the value is not
719 -- known at the time of derivation. To deal with this, we use two entity
720 -- flags. The flag Has_Derived_Rep_Aspects is set in the parent type (A
721 -- here), and then the flag May_Inherit_Delayed_Rep_Aspects is set in
722 -- the derived type (B here). If this flag is set when the derived type
723 -- is frozen, then this procedure is called to ensure proper inheritance
724 -- of all delayed aspects from the parent type. The derived type is E,
725 -- the argument to Analyze_Aspects_At_Freeze_Point. ASN is the first
726 -- aspect specification node in the Rep_Item chain for the parent type.
728 procedure Make_Pragma_From_Boolean_Aspect
(ASN
: Node_Id
);
729 -- Given an aspect specification node ASN whose expression is an
730 -- optional Boolean, this routines creates the corresponding pragma
731 -- at the freezing point.
733 ----------------------------------
734 -- Analyze_Aspect_Default_Value --
735 ----------------------------------
737 procedure Analyze_Aspect_Default_Value
(ASN
: Node_Id
) is
738 Ent
: constant Entity_Id
:= Entity
(ASN
);
739 Expr
: constant Node_Id
:= Expression
(ASN
);
740 Id
: constant Node_Id
:= Identifier
(ASN
);
743 Error_Msg_Name_1
:= Chars
(Id
);
745 if not Is_Type
(Ent
) then
746 Error_Msg_N
("aspect% can only apply to a type", Id
);
749 elsif not Is_First_Subtype
(Ent
) then
750 Error_Msg_N
("aspect% cannot apply to subtype", Id
);
753 elsif A_Id
= Aspect_Default_Value
754 and then not Is_Scalar_Type
(Ent
)
756 Error_Msg_N
("aspect% can only be applied to scalar type", Id
);
759 elsif A_Id
= Aspect_Default_Component_Value
then
760 if not Is_Array_Type
(Ent
) then
761 Error_Msg_N
("aspect% can only be applied to array type", Id
);
764 elsif not Is_Scalar_Type
(Component_Type
(Ent
)) then
765 Error_Msg_N
("aspect% requires scalar components", Id
);
770 Set_Has_Default_Aspect
(Base_Type
(Ent
));
772 if Is_Scalar_Type
(Ent
) then
773 Set_Default_Aspect_Value
(Base_Type
(Ent
), Expr
);
775 Set_Default_Aspect_Component_Value
(Base_Type
(Ent
), Expr
);
777 end Analyze_Aspect_Default_Value
;
779 ---------------------------------
780 -- Inherit_Delayed_Rep_Aspects --
781 ---------------------------------
783 procedure Inherit_Delayed_Rep_Aspects
(ASN
: Node_Id
) is
784 P
: constant Entity_Id
:= Entity
(ASN
);
785 -- Entithy for parent type
788 -- Item from Rep_Item chain
793 -- Loop through delayed aspects for the parent type
796 while Present
(N
) loop
797 if Nkind
(N
) = N_Aspect_Specification
then
798 exit when Entity
(N
) /= P
;
800 if Is_Delayed_Aspect
(N
) then
801 A
:= Get_Aspect_Id
(Chars
(Identifier
(N
)));
803 -- Process delayed rep aspect. For Boolean attributes it is
804 -- not possible to cancel an attribute once set (the attempt
805 -- to use an aspect with xxx => False is an error) for a
806 -- derived type. So for those cases, we do not have to check
807 -- if a clause has been given for the derived type, since it
808 -- is harmless to set it again if it is already set.
814 when Aspect_Alignment
=>
815 if not Has_Alignment_Clause
(E
) then
816 Set_Alignment
(E
, Alignment
(P
));
821 when Aspect_Atomic
=>
822 if Is_Atomic
(P
) then
828 when Aspect_Atomic_Components
=>
829 if Has_Atomic_Components
(P
) then
830 Set_Has_Atomic_Components
(Base_Type
(E
));
835 when Aspect_Bit_Order
=>
836 if Is_Record_Type
(E
)
837 and then No
(Get_Attribute_Definition_Clause
838 (E
, Attribute_Bit_Order
))
839 and then Reverse_Bit_Order
(P
)
841 Set_Reverse_Bit_Order
(Base_Type
(E
));
846 when Aspect_Component_Size
=>
848 and then not Has_Component_Size_Clause
(E
)
851 (Base_Type
(E
), Component_Size
(P
));
856 when Aspect_Machine_Radix
=>
857 if Is_Decimal_Fixed_Point_Type
(E
)
858 and then not Has_Machine_Radix_Clause
(E
)
860 Set_Machine_Radix_10
(E
, Machine_Radix_10
(P
));
863 -- Object_Size (also Size which also sets Object_Size)
865 when Aspect_Object_Size | Aspect_Size
=>
866 if not Has_Size_Clause
(E
)
868 No
(Get_Attribute_Definition_Clause
869 (E
, Attribute_Object_Size
))
871 Set_Esize
(E
, Esize
(P
));
877 if not Is_Packed
(E
) then
878 Set_Is_Packed
(Base_Type
(E
));
880 if Is_Bit_Packed_Array
(P
) then
881 Set_Is_Bit_Packed_Array
(Base_Type
(E
));
882 Set_Packed_Array_Type
(E
, Packed_Array_Type
(P
));
886 -- Scalar_Storage_Order
888 when Aspect_Scalar_Storage_Order
=>
889 if (Is_Record_Type
(E
) or else Is_Array_Type
(E
))
890 and then No
(Get_Attribute_Definition_Clause
891 (E
, Attribute_Scalar_Storage_Order
))
892 and then Reverse_Storage_Order
(P
)
894 Set_Reverse_Storage_Order
(Base_Type
(E
));
900 if Is_Fixed_Point_Type
(E
)
901 and then not Has_Small_Clause
(E
)
903 Set_Small_Value
(E
, Small_Value
(P
));
908 when Aspect_Storage_Size
=>
909 if (Is_Access_Type
(E
) or else Is_Task_Type
(E
))
910 and then not Has_Storage_Size_Clause
(E
)
912 Set_Storage_Size_Variable
913 (Base_Type
(E
), Storage_Size_Variable
(P
));
918 when Aspect_Value_Size
=>
920 -- Value_Size is never inherited, it is either set by
921 -- default, or it is explicitly set for the derived
922 -- type. So nothing to do here.
928 when Aspect_Volatile
=>
929 if Is_Volatile
(P
) then
933 -- Volatile_Components
935 when Aspect_Volatile_Components
=>
936 if Has_Volatile_Components
(P
) then
937 Set_Has_Volatile_Components
(Base_Type
(E
));
940 -- That should be all the Rep Aspects
943 pragma Assert
(Aspect_Delay
(A_Id
) /= Rep_Aspect
);
950 N
:= Next_Rep_Item
(N
);
952 end Inherit_Delayed_Rep_Aspects
;
954 -------------------------------------
955 -- Make_Pragma_From_Boolean_Aspect --
956 -------------------------------------
958 procedure Make_Pragma_From_Boolean_Aspect
(ASN
: Node_Id
) is
959 Ident
: constant Node_Id
:= Identifier
(ASN
);
960 A_Name
: constant Name_Id
:= Chars
(Ident
);
961 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(A_Name
);
962 Ent
: constant Entity_Id
:= Entity
(ASN
);
963 Expr
: constant Node_Id
:= Expression
(ASN
);
964 Loc
: constant Source_Ptr
:= Sloc
(ASN
);
968 procedure Check_False_Aspect_For_Derived_Type
;
969 -- This procedure checks for the case of a false aspect for a derived
970 -- type, which improperly tries to cancel an aspect inherited from
973 -----------------------------------------
974 -- Check_False_Aspect_For_Derived_Type --
975 -----------------------------------------
977 procedure Check_False_Aspect_For_Derived_Type
is
981 -- We are only checking derived types
983 if not Is_Derived_Type
(E
) then
987 Par
:= Nearest_Ancestor
(E
);
990 when Aspect_Atomic | Aspect_Shared
=>
991 if not Is_Atomic
(Par
) then
995 when Aspect_Atomic_Components
=>
996 if not Has_Atomic_Components
(Par
) then
1000 when Aspect_Discard_Names
=>
1001 if not Discard_Names
(Par
) then
1006 if not Is_Packed
(Par
) then
1010 when Aspect_Unchecked_Union
=>
1011 if not Is_Unchecked_Union
(Par
) then
1015 when Aspect_Volatile
=>
1016 if not Is_Volatile
(Par
) then
1020 when Aspect_Volatile_Components
=>
1021 if not Has_Volatile_Components
(Par
) then
1029 -- Fall through means we are canceling an inherited aspect
1031 Error_Msg_Name_1
:= A_Name
;
1033 ("derived type& inherits aspect%, cannot cancel", Expr
, E
);
1035 end Check_False_Aspect_For_Derived_Type
;
1037 -- Start of processing for Make_Pragma_From_Boolean_Aspect
1040 -- Note that we know Expr is present, because for a missing Expr
1041 -- argument, we knew it was True and did not need to delay the
1042 -- evaluation to the freeze point.
1044 if Is_False
(Static_Boolean
(Expr
)) then
1045 Check_False_Aspect_For_Derived_Type
;
1050 Pragma_Argument_Associations
=> New_List
(
1051 Make_Pragma_Argument_Association
(Sloc
(Ident
),
1052 Expression
=> New_Occurrence_Of
(Ent
, Sloc
(Ident
)))),
1054 Pragma_Identifier
=>
1055 Make_Identifier
(Sloc
(Ident
), Chars
(Ident
)));
1057 Set_From_Aspect_Specification
(Prag
, True);
1058 Set_Corresponding_Aspect
(Prag
, ASN
);
1059 Set_Aspect_Rep_Item
(ASN
, Prag
);
1060 Set_Is_Delayed_Aspect
(Prag
);
1061 Set_Parent
(Prag
, ASN
);
1063 end Make_Pragma_From_Boolean_Aspect
;
1065 -- Start of processing for Analyze_Aspects_At_Freeze_Point
1068 -- Must be visible in current scope
1070 if not Scope_Within_Or_Same
(Current_Scope
, Scope
(E
)) then
1074 -- Look for aspect specification entries for this entity
1076 ASN
:= First_Rep_Item
(E
);
1077 while Present
(ASN
) loop
1078 if Nkind
(ASN
) = N_Aspect_Specification
then
1079 exit when Entity
(ASN
) /= E
;
1081 if Is_Delayed_Aspect
(ASN
) then
1082 A_Id
:= Get_Aspect_Id
(ASN
);
1086 -- For aspects whose expression is an optional Boolean, make
1087 -- the corresponding pragma at the freezing point.
1089 when Boolean_Aspects |
1090 Library_Unit_Aspects
=>
1091 Make_Pragma_From_Boolean_Aspect
(ASN
);
1093 -- Special handling for aspects that don't correspond to
1094 -- pragmas/attributes.
1096 when Aspect_Default_Value |
1097 Aspect_Default_Component_Value
=>
1098 Analyze_Aspect_Default_Value
(ASN
);
1100 -- Ditto for iterator aspects, because the corresponding
1101 -- attributes may not have been analyzed yet.
1103 when Aspect_Constant_Indexing |
1104 Aspect_Variable_Indexing |
1105 Aspect_Default_Iterator |
1106 Aspect_Iterator_Element
=>
1107 Analyze
(Expression
(ASN
));
1113 Ritem
:= Aspect_Rep_Item
(ASN
);
1115 if Present
(Ritem
) then
1121 Next_Rep_Item
(ASN
);
1124 -- This is where we inherit delayed rep aspects from our parent. Note
1125 -- that if we fell out of the above loop with ASN non-empty, it means
1126 -- we hit an aspect for an entity other than E, and it must be the
1127 -- type from which we were derived.
1129 if May_Inherit_Delayed_Rep_Aspects
(E
) then
1130 Inherit_Delayed_Rep_Aspects
(ASN
);
1132 end Analyze_Aspects_At_Freeze_Point
;
1134 -----------------------------------
1135 -- Analyze_Aspect_Specifications --
1136 -----------------------------------
1138 procedure Analyze_Aspect_Specifications
(N
: Node_Id
; E
: Entity_Id
) is
1139 procedure Decorate_Delayed_Aspect_And_Pragma
1142 -- Establish the linkages between a delayed aspect and its corresponding
1143 -- pragma. Set all delay-related flags on both constructs.
1145 procedure Insert_Delayed_Pragma
(Prag
: Node_Id
);
1146 -- Insert a postcondition-like pragma into the tree depending on the
1147 -- context. Prag must denote one of the following: Pre, Post, Depends,
1148 -- Global or Contract_Cases.
1150 ----------------------------------------
1151 -- Decorate_Delayed_Aspect_And_Pragma --
1152 ----------------------------------------
1154 procedure Decorate_Delayed_Aspect_And_Pragma
1159 Set_Aspect_Rep_Item
(Asp
, Prag
);
1160 Set_Corresponding_Aspect
(Prag
, Asp
);
1161 Set_From_Aspect_Specification
(Prag
);
1162 Set_Is_Delayed_Aspect
(Prag
);
1163 Set_Is_Delayed_Aspect
(Asp
);
1164 Set_Parent
(Prag
, Asp
);
1165 end Decorate_Delayed_Aspect_And_Pragma
;
1167 ---------------------------
1168 -- Insert_Delayed_Pragma --
1169 ---------------------------
1171 procedure Insert_Delayed_Pragma
(Prag
: Node_Id
) is
1175 -- When the context is a library unit, the pragma is added to the
1176 -- Pragmas_After list.
1178 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
1179 Aux
:= Aux_Decls_Node
(Parent
(N
));
1181 if No
(Pragmas_After
(Aux
)) then
1182 Set_Pragmas_After
(Aux
, New_List
);
1185 Prepend
(Prag
, Pragmas_After
(Aux
));
1187 -- Pragmas associated with subprogram bodies are inserted in the
1188 -- declarative part.
1190 elsif Nkind
(N
) = N_Subprogram_Body
then
1191 if No
(Declarations
(N
)) then
1192 Set_Declarations
(N
, New_List
(Prag
));
1198 -- There may be several aspects associated with the body;
1199 -- preserve the ordering of the corresponding pragmas.
1201 D
:= First
(Declarations
(N
));
1202 while Present
(D
) loop
1203 exit when Nkind
(D
) /= N_Pragma
1204 or else not From_Aspect_Specification
(D
);
1209 Append
(Prag
, Declarations
(N
));
1211 Insert_Before
(D
, Prag
);
1219 Insert_After
(N
, Prag
);
1221 -- Analyze the pragma before analyzing the proper body of a stub.
1222 -- This ensures that the pragma will appear on the proper contract
1223 -- list (see N_Contract).
1225 if Nkind
(N
) = N_Subprogram_Body_Stub
then
1229 end Insert_Delayed_Pragma
;
1237 L
: constant List_Id
:= Aspect_Specifications
(N
);
1239 Ins_Node
: Node_Id
:= N
;
1240 -- Insert pragmas/attribute definition clause after this node when no
1241 -- delayed analysis is required.
1243 -- Start of processing for Analyze_Aspect_Specifications
1245 -- The general processing involves building an attribute definition
1246 -- clause or a pragma node that corresponds to the aspect. Then in order
1247 -- to delay the evaluation of this aspect to the freeze point, we attach
1248 -- the corresponding pragma/attribute definition clause to the aspect
1249 -- specification node, which is then placed in the Rep Item chain. In
1250 -- this case we mark the entity by setting the flag Has_Delayed_Aspects
1251 -- and we evaluate the rep item at the freeze point. When the aspect
1252 -- doesn't have a corresponding pragma/attribute definition clause, then
1253 -- its analysis is simply delayed at the freeze point.
1255 -- Some special cases don't require delay analysis, thus the aspect is
1256 -- analyzed right now.
1258 -- Note that there is a special handling for Pre, Post, Test_Case,
1259 -- Contract_Cases aspects. In these cases, we do not have to worry
1260 -- about delay issues, since the pragmas themselves deal with delay
1261 -- of visibility for the expression analysis. Thus, we just insert
1262 -- the pragma after the node N.
1265 pragma Assert
(Present
(L
));
1267 -- Loop through aspects
1269 Aspect
:= First
(L
);
1270 Aspect_Loop
: while Present
(Aspect
) loop
1271 Analyze_One_Aspect
: declare
1272 Expr
: constant Node_Id
:= Expression
(Aspect
);
1273 Id
: constant Node_Id
:= Identifier
(Aspect
);
1274 Loc
: constant Source_Ptr
:= Sloc
(Aspect
);
1275 Nam
: constant Name_Id
:= Chars
(Id
);
1276 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Nam
);
1279 Delay_Required
: Boolean;
1280 -- Set False if delay is not required
1282 Eloc
: Source_Ptr
:= No_Location
;
1283 -- Source location of expression, modified when we split PPC's. It
1284 -- is set below when Expr is present.
1286 procedure Analyze_Aspect_External_Or_Link_Name
;
1287 -- Perform analysis of the External_Name or Link_Name aspects
1289 procedure Analyze_Aspect_Implicit_Dereference
;
1290 -- Perform analysis of the Implicit_Dereference aspects
1292 procedure Make_Aitem_Pragma
1293 (Pragma_Argument_Associations
: List_Id
;
1294 Pragma_Name
: Name_Id
);
1295 -- This is a wrapper for Make_Pragma used for converting aspects
1296 -- to pragmas. It takes care of Sloc (set from Loc) and building
1297 -- the pragma identifier from the given name. In addition the
1298 -- flags Class_Present and Split_PPC are set from the aspect
1299 -- node, as well as Is_Ignored. This routine also sets the
1300 -- From_Aspect_Specification in the resulting pragma node to
1301 -- True, and sets Corresponding_Aspect to point to the aspect.
1302 -- The resulting pragma is assigned to Aitem.
1304 ------------------------------------------
1305 -- Analyze_Aspect_External_Or_Link_Name --
1306 ------------------------------------------
1308 procedure Analyze_Aspect_External_Or_Link_Name
is
1310 -- Verify that there is an Import/Export aspect defined for the
1311 -- entity. The processing of that aspect in turn checks that
1312 -- there is a Convention aspect declared. The pragma is
1313 -- constructed when processing the Convention aspect.
1320 while Present
(A
) loop
1321 exit when Nam_In
(Chars
(Identifier
(A
)), Name_Export
,
1328 ("missing Import/Export for Link/External name",
1332 end Analyze_Aspect_External_Or_Link_Name
;
1334 -----------------------------------------
1335 -- Analyze_Aspect_Implicit_Dereference --
1336 -----------------------------------------
1338 procedure Analyze_Aspect_Implicit_Dereference
is
1340 if not Is_Type
(E
) or else not Has_Discriminants
(E
) then
1342 ("aspect must apply to a type with discriminants", N
);
1349 Disc
:= First_Discriminant
(E
);
1350 while Present
(Disc
) loop
1351 if Chars
(Expr
) = Chars
(Disc
)
1352 and then Ekind
(Etype
(Disc
)) =
1353 E_Anonymous_Access_Type
1355 Set_Has_Implicit_Dereference
(E
);
1356 Set_Has_Implicit_Dereference
(Disc
);
1360 Next_Discriminant
(Disc
);
1363 -- Error if no proper access discriminant.
1366 ("not an access discriminant of&", Expr
, E
);
1369 end Analyze_Aspect_Implicit_Dereference
;
1371 -----------------------
1372 -- Make_Aitem_Pragma --
1373 -----------------------
1375 procedure Make_Aitem_Pragma
1376 (Pragma_Argument_Associations
: List_Id
;
1377 Pragma_Name
: Name_Id
)
1379 Args
: List_Id
:= Pragma_Argument_Associations
;
1382 -- We should never get here if aspect was disabled
1384 pragma Assert
(not Is_Disabled
(Aspect
));
1386 -- Certain aspects allow for an optional name or expression. Do
1387 -- not generate a pragma with empty argument association list.
1389 if No
(Args
) or else No
(Expression
(First
(Args
))) then
1397 Pragma_Argument_Associations
=> Args
,
1398 Pragma_Identifier
=>
1399 Make_Identifier
(Sloc
(Id
), Pragma_Name
),
1400 Class_Present
=> Class_Present
(Aspect
),
1401 Split_PPC
=> Split_PPC
(Aspect
));
1403 -- Set additional semantic fields
1405 if Is_Ignored
(Aspect
) then
1406 Set_Is_Ignored
(Aitem
);
1407 elsif Is_Checked
(Aspect
) then
1408 Set_Is_Checked
(Aitem
);
1411 Set_Corresponding_Aspect
(Aitem
, Aspect
);
1412 Set_From_Aspect_Specification
(Aitem
, True);
1413 end Make_Aitem_Pragma
;
1415 -- Start of processing for Analyze_One_Aspect
1418 -- Skip aspect if already analyzed (not clear if this is needed)
1420 if Analyzed
(Aspect
) then
1424 -- Skip looking at aspect if it is totally disabled. Just mark it
1425 -- as such for later reference in the tree. This also sets the
1426 -- Is_Ignored and Is_Checked flags appropriately.
1428 Check_Applicable_Policy
(Aspect
);
1430 if Is_Disabled
(Aspect
) then
1434 -- Set the source location of expression, used in the case of
1435 -- a failed precondition/postcondition or invariant. Note that
1436 -- the source location of the expression is not usually the best
1437 -- choice here. For example, it gets located on the last AND
1438 -- keyword in a chain of boolean expressiond AND'ed together.
1439 -- It is best to put the message on the first character of the
1440 -- assertion, which is the effect of the First_Node call here.
1442 if Present
(Expr
) then
1443 Eloc
:= Sloc
(First_Node
(Expr
));
1446 -- Check restriction No_Implementation_Aspect_Specifications
1448 if Implementation_Defined_Aspect
(A_Id
) then
1450 (No_Implementation_Aspect_Specifications
, Aspect
);
1453 -- Check restriction No_Specification_Of_Aspect
1455 Check_Restriction_No_Specification_Of_Aspect
(Aspect
);
1457 -- Analyze this aspect (actual analysis is delayed till later)
1459 Set_Analyzed
(Aspect
);
1460 Set_Entity
(Aspect
, E
);
1461 Ent
:= New_Occurrence_Of
(E
, Sloc
(Id
));
1463 -- Check for duplicate aspect. Note that the Comes_From_Source
1464 -- test allows duplicate Pre/Post's that we generate internally
1465 -- to escape being flagged here.
1467 if No_Duplicates_Allowed
(A_Id
) then
1469 while Anod
/= Aspect
loop
1470 if Comes_From_Source
(Aspect
)
1471 and then Same_Aspect
(A_Id
, Get_Aspect_Id
(Anod
))
1473 Error_Msg_Name_1
:= Nam
;
1474 Error_Msg_Sloc
:= Sloc
(Anod
);
1476 -- Case of same aspect specified twice
1478 if Class_Present
(Anod
) = Class_Present
(Aspect
) then
1479 if not Class_Present
(Anod
) then
1481 ("aspect% for & previously given#",
1485 ("aspect `%''Class` for & previously given#",
1495 -- Check some general restrictions on language defined aspects
1497 if not Implementation_Defined_Aspect
(A_Id
) then
1498 Error_Msg_Name_1
:= Nam
;
1500 -- Not allowed for renaming declarations
1502 if Nkind
(N
) in N_Renaming_Declaration
then
1504 ("aspect % not allowed for renaming declaration",
1508 -- Not allowed for formal type declarations
1510 if Nkind
(N
) = N_Formal_Type_Declaration
then
1512 ("aspect % not allowed for formal type declaration",
1517 -- Copy expression for later processing by the procedures
1518 -- Check_Aspect_At_[Freeze_Point | End_Of_Declarations]
1520 Set_Entity
(Id
, New_Copy_Tree
(Expr
));
1522 -- Set Delay_Required as appropriate to aspect
1524 case Aspect_Delay
(A_Id
) is
1525 when Always_Delay
=>
1526 Delay_Required
:= True;
1529 Delay_Required
:= False;
1533 -- If expression has the form of an integer literal, then
1534 -- do not delay, since we know the value cannot change.
1535 -- This optimization catches most rep clause cases.
1537 if (Present
(Expr
) and then Nkind
(Expr
) = N_Integer_Literal
)
1538 or else (A_Id
in Boolean_Aspects
and then No
(Expr
))
1540 Delay_Required
:= False;
1542 Delay_Required
:= True;
1543 Set_Has_Delayed_Rep_Aspects
(E
);
1547 -- Processing based on specific aspect
1551 -- No_Aspect should be impossible
1554 raise Program_Error
;
1556 -- Case 1: Aspects corresponding to attribute definition
1559 when Aspect_Address |
1562 Aspect_Component_Size |
1563 Aspect_Constant_Indexing |
1564 Aspect_Default_Iterator |
1565 Aspect_Dispatching_Domain |
1566 Aspect_External_Tag |
1568 Aspect_Iterator_Element |
1569 Aspect_Machine_Radix |
1570 Aspect_Object_Size |
1573 Aspect_Scalar_Storage_Order |
1576 Aspect_Simple_Storage_Pool |
1577 Aspect_Storage_Pool |
1578 Aspect_Stream_Size |
1580 Aspect_Variable_Indexing |
1583 -- Indexing aspects apply only to tagged type
1585 if (A_Id
= Aspect_Constant_Indexing
1587 A_Id
= Aspect_Variable_Indexing
)
1588 and then not (Is_Type
(E
)
1589 and then Is_Tagged_Type
(E
))
1591 Error_Msg_N
("indexing applies to a tagged type", N
);
1595 -- For case of address aspect, we don't consider that we
1596 -- know the entity is never set in the source, since it is
1597 -- is likely aliasing is occurring.
1599 -- Note: one might think that the analysis of the resulting
1600 -- attribute definition clause would take care of that, but
1601 -- that's not the case since it won't be from source.
1603 if A_Id
= Aspect_Address
then
1604 Set_Never_Set_In_Source
(E
, False);
1607 -- Construct the attribute definition clause
1610 Make_Attribute_Definition_Clause
(Loc
,
1612 Chars
=> Chars
(Id
),
1613 Expression
=> Relocate_Node
(Expr
));
1615 -- If the address is specified, then we treat the entity as
1616 -- referenced, to avoid spurious warnings. This is analogous
1617 -- to what is done with an attribute definition clause, but
1618 -- here we don't want to generate a reference because this
1619 -- is the point of definition of the entity.
1621 if A_Id
= Aspect_Address
then
1625 -- Case 2: Aspects corresponding to pragmas
1627 -- Case 2a: Aspects corresponding to pragmas with two
1628 -- arguments, where the first argument is a local name
1629 -- referring to the entity, and the second argument is the
1630 -- aspect definition expression.
1632 -- Suppress/Unsuppress
1634 when Aspect_Suppress |
1635 Aspect_Unsuppress
=>
1638 (Pragma_Argument_Associations
=> New_List
(
1639 Make_Pragma_Argument_Association
(Loc
,
1640 Expression
=> New_Occurrence_Of
(E
, Loc
)),
1641 Make_Pragma_Argument_Association
(Sloc
(Expr
),
1642 Expression
=> Relocate_Node
(Expr
))),
1643 Pragma_Name
=> Chars
(Id
));
1647 -- Corresponds to pragma Implemented, construct the pragma
1649 when Aspect_Synchronization
=>
1652 (Pragma_Argument_Associations
=> New_List
(
1653 Make_Pragma_Argument_Association
(Loc
,
1654 Expression
=> New_Occurrence_Of
(E
, Loc
)),
1655 Make_Pragma_Argument_Association
(Sloc
(Expr
),
1656 Expression
=> Relocate_Node
(Expr
))),
1657 Pragma_Name
=> Name_Implemented
);
1661 when Aspect_Attach_Handler
=>
1663 (Pragma_Argument_Associations
=> New_List
(
1664 Make_Pragma_Argument_Association
(Sloc
(Ent
),
1666 Make_Pragma_Argument_Association
(Sloc
(Expr
),
1667 Expression
=> Relocate_Node
(Expr
))),
1668 Pragma_Name
=> Name_Attach_Handler
);
1670 -- Dynamic_Predicate, Predicate, Static_Predicate
1672 when Aspect_Dynamic_Predicate |
1674 Aspect_Static_Predicate
=>
1676 -- Construct the pragma (always a pragma Predicate, with
1677 -- flags recording whether it is static/dynamic). We also
1678 -- set flags recording this in the type itself.
1681 (Pragma_Argument_Associations
=> New_List
(
1682 Make_Pragma_Argument_Association
(Sloc
(Ent
),
1684 Make_Pragma_Argument_Association
(Sloc
(Expr
),
1685 Expression
=> Relocate_Node
(Expr
))),
1686 Pragma_Name
=> Name_Predicate
);
1688 -- Mark type has predicates, and remember what kind of
1689 -- aspect lead to this predicate (we need this to access
1690 -- the right set of check policies later on).
1692 Set_Has_Predicates
(E
);
1694 if A_Id
= Aspect_Dynamic_Predicate
then
1695 Set_Has_Dynamic_Predicate_Aspect
(E
);
1696 elsif A_Id
= Aspect_Static_Predicate
then
1697 Set_Has_Static_Predicate_Aspect
(E
);
1700 -- If the type is private, indicate that its completion
1701 -- has a freeze node, because that is the one that will be
1702 -- visible at freeze time.
1704 if Is_Private_Type
(E
) and then Present
(Full_View
(E
)) then
1705 Set_Has_Predicates
(Full_View
(E
));
1707 if A_Id
= Aspect_Dynamic_Predicate
then
1708 Set_Has_Dynamic_Predicate_Aspect
(Full_View
(E
));
1709 elsif A_Id
= Aspect_Static_Predicate
then
1710 Set_Has_Static_Predicate_Aspect
(Full_View
(E
));
1713 Set_Has_Delayed_Aspects
(Full_View
(E
));
1714 Ensure_Freeze_Node
(Full_View
(E
));
1717 -- Case 2b: Aspects corresponding to pragmas with two
1718 -- arguments, where the second argument is a local name
1719 -- referring to the entity, and the first argument is the
1720 -- aspect definition expression.
1724 when Aspect_Convention
=>
1726 -- The aspect may be part of the specification of an import
1727 -- or export pragma. Scan the aspect list to gather the
1728 -- other components, if any. The name of the generated
1729 -- pragma is one of Convention/Import/Export.
1741 P_Name
:= Chars
(Id
);
1743 Arg_List
:= New_List
;
1748 while Present
(A
) loop
1749 A_Name
:= Chars
(Identifier
(A
));
1751 if Nam_In
(A_Name
, Name_Import
, Name_Export
) then
1753 Error_Msg_N
("conflicting", A
);
1760 elsif A_Name
= Name_Link_Name
then
1762 Make_Pragma_Argument_Association
(Loc
,
1764 Expression
=> Relocate_Node
(Expression
(A
)));
1766 elsif A_Name
= Name_External_Name
then
1768 Make_Pragma_Argument_Association
(Loc
,
1770 Expression
=> Relocate_Node
(Expression
(A
)));
1776 Arg_List
:= New_List
(
1777 Make_Pragma_Argument_Association
(Sloc
(Expr
),
1778 Expression
=> Relocate_Node
(Expr
)),
1779 Make_Pragma_Argument_Association
(Sloc
(Ent
),
1780 Expression
=> Ent
));
1782 if Present
(L_Assoc
) then
1783 Append_To
(Arg_List
, L_Assoc
);
1786 if Present
(E_Assoc
) then
1787 Append_To
(Arg_List
, E_Assoc
);
1791 (Pragma_Argument_Associations
=> Arg_List
,
1792 Pragma_Name
=> P_Name
);
1795 -- CPU, Interrupt_Priority, Priority
1797 -- These three aspects can be specified for a subprogram spec
1798 -- or body, in which case we analyze the expression and export
1799 -- the value of the aspect.
1801 -- Previously, we generated an equivalent pragma for bodies
1802 -- (note that the specs cannot contain these pragmas). The
1803 -- pragma was inserted ahead of local declarations, rather than
1804 -- after the body. This leads to a certain duplication between
1805 -- the processing performed for the aspect and the pragma, but
1806 -- given the straightforward handling required it is simpler
1807 -- to duplicate than to translate the aspect in the spec into
1808 -- a pragma in the declarative part of the body.
1811 Aspect_Interrupt_Priority |
1814 if Nkind_In
(N
, N_Subprogram_Body
,
1815 N_Subprogram_Declaration
)
1817 -- Analyze the aspect expression
1819 Analyze_And_Resolve
(Expr
, Standard_Integer
);
1821 -- Interrupt_Priority aspect not allowed for main
1822 -- subprograms. ARM D.1 does not forbid this explicitly,
1823 -- but ARM J.15.11 (6/3) does not permit pragma
1824 -- Interrupt_Priority for subprograms.
1826 if A_Id
= Aspect_Interrupt_Priority
then
1828 ("Interrupt_Priority aspect cannot apply to "
1829 & "subprogram", Expr
);
1831 -- The expression must be static
1833 elsif not Is_Static_Expression
(Expr
) then
1834 Flag_Non_Static_Expr
1835 ("aspect requires static expression!", Expr
);
1837 -- Check whether this is the main subprogram. Issue a
1838 -- warning only if it is obviously not a main program
1839 -- (when it has parameters or when the subprogram is
1840 -- within a package).
1842 elsif Present
(Parameter_Specifications
1843 (Specification
(N
)))
1844 or else not Is_Compilation_Unit
(Defining_Entity
(N
))
1846 -- See ARM D.1 (14/3) and D.16 (12/3)
1849 ("aspect applied to subprogram other than the "
1850 & "main subprogram has no effect??", Expr
);
1852 -- Otherwise check in range and export the value
1854 -- For the CPU aspect
1856 elsif A_Id
= Aspect_CPU
then
1857 if Is_In_Range
(Expr
, RTE
(RE_CPU_Range
)) then
1859 -- Value is correct so we export the value to make
1860 -- it available at execution time.
1863 (Main_Unit
, UI_To_Int
(Expr_Value
(Expr
)));
1867 ("main subprogram CPU is out of range", Expr
);
1870 -- For the Priority aspect
1872 elsif A_Id
= Aspect_Priority
then
1873 if Is_In_Range
(Expr
, RTE
(RE_Priority
)) then
1875 -- Value is correct so we export the value to make
1876 -- it available at execution time.
1879 (Main_Unit
, UI_To_Int
(Expr_Value
(Expr
)));
1883 ("main subprogram priority is out of range",
1888 -- Load an arbitrary entity from System.Tasking.Stages
1889 -- or System.Tasking.Restricted.Stages (depending on
1890 -- the supported profile) to make sure that one of these
1891 -- packages is implicitly with'ed, since we need to have
1892 -- the tasking run time active for the pragma Priority to
1893 -- have any effect. Previously with with'ed the package
1894 -- System.Tasking, but this package does not trigger the
1895 -- required initialization of the run-time library.
1898 Discard
: Entity_Id
;
1899 pragma Warnings
(Off
, Discard
);
1901 if Restricted_Profile
then
1902 Discard
:= RTE
(RE_Activate_Restricted_Tasks
);
1904 Discard
:= RTE
(RE_Activate_Tasks
);
1908 -- Handling for these Aspects in subprograms is complete
1915 -- Pass the aspect as an attribute
1918 Make_Attribute_Definition_Clause
(Loc
,
1920 Chars
=> Chars
(Id
),
1921 Expression
=> Relocate_Node
(Expr
));
1926 when Aspect_Warnings
=>
1928 (Pragma_Argument_Associations
=> New_List
(
1929 Make_Pragma_Argument_Association
(Sloc
(Expr
),
1930 Expression
=> Relocate_Node
(Expr
)),
1931 Make_Pragma_Argument_Association
(Loc
,
1932 Expression
=> New_Occurrence_Of
(E
, Loc
))),
1933 Pragma_Name
=> Chars
(Id
));
1935 -- Case 2c: Aspects corresponding to pragmas with three
1938 -- Invariant aspects have a first argument that references the
1939 -- entity, a second argument that is the expression and a third
1940 -- argument that is an appropriate message.
1942 -- Invariant, Type_Invariant
1944 when Aspect_Invariant |
1945 Aspect_Type_Invariant
=>
1947 -- Analysis of the pragma will verify placement legality:
1948 -- an invariant must apply to a private type, or appear in
1949 -- the private part of a spec and apply to a completion.
1952 (Pragma_Argument_Associations
=> New_List
(
1953 Make_Pragma_Argument_Association
(Sloc
(Ent
),
1955 Make_Pragma_Argument_Association
(Sloc
(Expr
),
1956 Expression
=> Relocate_Node
(Expr
))),
1957 Pragma_Name
=> Name_Invariant
);
1959 -- Add message unless exception messages are suppressed
1961 if not Opt
.Exception_Locations_Suppressed
then
1962 Append_To
(Pragma_Argument_Associations
(Aitem
),
1963 Make_Pragma_Argument_Association
(Eloc
,
1964 Chars
=> Name_Message
,
1966 Make_String_Literal
(Eloc
,
1967 Strval
=> "failed invariant from "
1968 & Build_Location_String
(Eloc
))));
1971 -- For Invariant case, insert immediately after the entity
1972 -- declaration. We do not have to worry about delay issues
1973 -- since the pragma processing takes care of this.
1975 Delay_Required
:= False;
1977 -- Case 2d : Aspects that correspond to a pragma with one
1982 -- Aspect Abstract_State introduces implicit declarations for
1983 -- all state abstraction entities it defines. To emulate this
1984 -- behavior, insert the pragma at the beginning of the visible
1985 -- declarations of the related package so that it is analyzed
1988 when Aspect_Abstract_State
=> Abstract_State
: declare
1992 if Nkind_In
(N
, N_Generic_Package_Declaration
,
1993 N_Package_Declaration
)
1995 Decls
:= Visible_Declarations
(Specification
(N
));
1998 (Pragma_Argument_Associations
=> New_List
(
1999 Make_Pragma_Argument_Association
(Loc
,
2000 Expression
=> Relocate_Node
(Expr
))),
2001 Pragma_Name
=> Name_Abstract_State
);
2002 Decorate_Delayed_Aspect_And_Pragma
(Aspect
, Aitem
);
2006 Set_Visible_Declarations
(N
, Decls
);
2009 Prepend_To
(Decls
, Aitem
);
2013 ("aspect & must apply to a package declaration",
2022 -- Aspect Depends must be delayed because it mentions names
2023 -- of inputs and output that are classified by aspect Global.
2024 -- The aspect and pragma are treated the same way as a post
2027 when Aspect_Depends
=>
2029 (Pragma_Argument_Associations
=> New_List
(
2030 Make_Pragma_Argument_Association
(Loc
,
2031 Expression
=> Relocate_Node
(Expr
))),
2032 Pragma_Name
=> Name_Depends
);
2034 Decorate_Delayed_Aspect_And_Pragma
(Aspect
, Aitem
);
2035 Insert_Delayed_Pragma
(Aitem
);
2040 -- Aspect Global must be delayed because it can mention names
2041 -- and benefit from the forward visibility rules applicable to
2042 -- aspects of subprograms. The aspect and pragma are treated
2043 -- the same way as a post condition.
2045 when Aspect_Global
=>
2047 (Pragma_Argument_Associations
=> New_List
(
2048 Make_Pragma_Argument_Association
(Loc
,
2049 Expression
=> Relocate_Node
(Expr
))),
2050 Pragma_Name
=> Name_Global
);
2052 Decorate_Delayed_Aspect_And_Pragma
(Aspect
, Aitem
);
2053 Insert_Delayed_Pragma
(Aitem
);
2056 -- Initial_Condition
2058 -- Aspect Initial_Condition covers the visible declarations of
2059 -- a package and all hidden states through functions. As such,
2060 -- it must be evaluated at the end of the said declarations.
2062 when Aspect_Initial_Condition
=> Initial_Condition
: declare
2066 if Nkind_In
(N
, N_Generic_Package_Declaration
,
2067 N_Package_Declaration
)
2069 Decls
:= Visible_Declarations
(Specification
(N
));
2072 (Pragma_Argument_Associations
=> New_List
(
2073 Make_Pragma_Argument_Association
(Loc
,
2074 Expression
=> Relocate_Node
(Expr
))),
2076 Name_Initial_Condition
);
2077 Decorate_Delayed_Aspect_And_Pragma
(Aspect
, Aitem
);
2081 Set_Visible_Declarations
(N
, Decls
);
2084 Prepend_To
(Decls
, Aitem
);
2088 ("aspect & must apply to a package declaration",
2093 end Initial_Condition
;
2097 -- Aspect Initializes coverts the visible declarations of a
2098 -- package. As such, it must be evaluated at the end of the
2099 -- said declarations.
2101 when Aspect_Initializes
=> Initializes
: declare
2105 if Nkind_In
(N
, N_Generic_Package_Declaration
,
2106 N_Package_Declaration
)
2108 Decls
:= Visible_Declarations
(Specification
(N
));
2111 (Pragma_Argument_Associations
=> New_List
(
2112 Make_Pragma_Argument_Association
(Loc
,
2113 Expression
=> Relocate_Node
(Expr
))),
2114 Pragma_Name
=> Name_Initializes
);
2115 Decorate_Delayed_Aspect_And_Pragma
(Aspect
, Aitem
);
2119 Set_Visible_Declarations
(N
, Decls
);
2122 Prepend_To
(Decls
, Aitem
);
2126 ("aspect & must apply to a package declaration",
2135 when Aspect_SPARK_Mode
=>
2137 (Pragma_Argument_Associations
=> New_List
(
2138 Make_Pragma_Argument_Association
(Loc
,
2139 Expression
=> Relocate_Node
(Expr
))),
2140 Pragma_Name
=> Name_SPARK_Mode
);
2144 -- Aspect Refined_Depends must be delayed because it can
2145 -- mention state refinements introduced by aspect Refined_State
2146 -- and further classified by aspect Refined_Global. Since both
2147 -- those aspects are delayed, so is Refined_Depends.
2149 when Aspect_Refined_Depends
=>
2151 (Pragma_Argument_Associations
=> New_List
(
2152 Make_Pragma_Argument_Association
(Loc
,
2153 Expression
=> Relocate_Node
(Expr
))),
2154 Pragma_Name
=> Name_Refined_Depends
);
2156 Decorate_Delayed_Aspect_And_Pragma
(Aspect
, Aitem
);
2157 Insert_Delayed_Pragma
(Aitem
);
2162 -- Aspect Refined_Global must be delayed because it can mention
2163 -- state refinements introduced by aspect Refined_State. Since
2164 -- Refined_State is already delayed due to forward references,
2165 -- so is Refined_Global.
2167 when Aspect_Refined_Global
=>
2169 (Pragma_Argument_Associations
=> New_List
(
2170 Make_Pragma_Argument_Association
(Loc
,
2171 Expression
=> Relocate_Node
(Expr
))),
2172 Pragma_Name
=> Name_Refined_Global
);
2174 Decorate_Delayed_Aspect_And_Pragma
(Aspect
, Aitem
);
2175 Insert_Delayed_Pragma
(Aitem
);
2180 when Aspect_Refined_Post
=>
2182 (Pragma_Argument_Associations
=> New_List
(
2183 Make_Pragma_Argument_Association
(Loc
,
2184 Expression
=> Relocate_Node
(Expr
))),
2185 Pragma_Name
=> Name_Refined_Post
);
2189 when Aspect_Refined_State
=> Refined_State
: declare
2193 -- The corresponding pragma for Refined_State is inserted in
2194 -- the declarations of the related package body. This action
2195 -- synchronizes both the source and from-aspect versions of
2198 if Nkind
(N
) = N_Package_Body
then
2199 Decls
:= Declarations
(N
);
2202 (Pragma_Argument_Associations
=> New_List
(
2203 Make_Pragma_Argument_Association
(Loc
,
2204 Expression
=> Relocate_Node
(Expr
))),
2205 Pragma_Name
=> Name_Refined_State
);
2206 Decorate_Delayed_Aspect_And_Pragma
(Aspect
, Aitem
);
2210 Set_Declarations
(N
, Decls
);
2213 Prepend_To
(Decls
, Aitem
);
2217 ("aspect & must apply to a package body", Aspect
, Id
);
2223 -- Relative_Deadline
2225 when Aspect_Relative_Deadline
=>
2227 (Pragma_Argument_Associations
=> New_List
(
2228 Make_Pragma_Argument_Association
(Loc
,
2229 Expression
=> Relocate_Node
(Expr
))),
2230 Pragma_Name
=> Name_Relative_Deadline
);
2232 -- If the aspect applies to a task, the corresponding pragma
2233 -- must appear within its declarations, not after.
2235 if Nkind
(N
) = N_Task_Type_Declaration
then
2241 if No
(Task_Definition
(N
)) then
2242 Set_Task_Definition
(N
,
2243 Make_Task_Definition
(Loc
,
2244 Visible_Declarations
=> New_List
,
2245 End_Label
=> Empty
));
2248 Def
:= Task_Definition
(N
);
2249 V
:= Visible_Declarations
(Def
);
2250 if not Is_Empty_List
(V
) then
2251 Insert_Before
(First
(V
), Aitem
);
2254 Set_Visible_Declarations
(Def
, New_List
(Aitem
));
2261 -- Case 3 : Aspects that don't correspond to pragma/attribute
2262 -- definition clause.
2264 -- Case 3a: The aspects listed below don't correspond to
2265 -- pragmas/attributes but do require delayed analysis.
2267 -- Default_Value, Default_Component_Value
2269 when Aspect_Default_Value |
2270 Aspect_Default_Component_Value
=>
2273 -- Case 3b: The aspects listed below don't correspond to
2274 -- pragmas/attributes and don't need delayed analysis.
2276 -- Implicit_Dereference
2278 -- For Implicit_Dereference, External_Name and Link_Name, only
2279 -- the legality checks are done during the analysis, thus no
2280 -- delay is required.
2282 when Aspect_Implicit_Dereference
=>
2283 Analyze_Aspect_Implicit_Dereference
;
2286 -- External_Name, Link_Name
2288 when Aspect_External_Name |
2290 Analyze_Aspect_External_Or_Link_Name
;
2295 when Aspect_Dimension
=>
2296 Analyze_Aspect_Dimension
(N
, Id
, Expr
);
2301 when Aspect_Dimension_System
=>
2302 Analyze_Aspect_Dimension_System
(N
, Id
, Expr
);
2305 -- Case 4: Aspects requiring special handling
2307 -- Pre/Post/Test_Case/Contract_Cases whose corresponding
2308 -- pragmas take care of the delay.
2312 -- Aspects Pre/Post generate Precondition/Postcondition pragmas
2313 -- with a first argument that is the expression, and a second
2314 -- argument that is an informative message if the test fails.
2315 -- This is inserted right after the declaration, to get the
2316 -- required pragma placement. The processing for the pragmas
2317 -- takes care of the required delay.
2319 when Pre_Post_Aspects
=> Pre_Post
: declare
2323 if A_Id
= Aspect_Pre
or else A_Id
= Aspect_Precondition
then
2324 Pname
:= Name_Precondition
;
2326 Pname
:= Name_Postcondition
;
2329 -- If the expressions is of the form A and then B, then
2330 -- we generate separate Pre/Post aspects for the separate
2331 -- clauses. Since we allow multiple pragmas, there is no
2332 -- problem in allowing multiple Pre/Post aspects internally.
2333 -- These should be treated in reverse order (B first and
2334 -- A second) since they are later inserted just after N in
2335 -- the order they are treated. This way, the pragma for A
2336 -- ends up preceding the pragma for B, which may have an
2337 -- importance for the error raised (either constraint error
2338 -- or precondition error).
2340 -- We do not do this for Pre'Class, since we have to put
2341 -- these conditions together in a complex OR expression
2343 -- We do not do this in ASIS mode, as ASIS relies on the
2344 -- original node representing the complete expression, when
2345 -- retrieving it through the source aspect table.
2348 and then (Pname
= Name_Postcondition
2349 or else not Class_Present
(Aspect
))
2351 while Nkind
(Expr
) = N_And_Then
loop
2352 Insert_After
(Aspect
,
2353 Make_Aspect_Specification
(Sloc
(Left_Opnd
(Expr
)),
2354 Identifier
=> Identifier
(Aspect
),
2355 Expression
=> Relocate_Node
(Left_Opnd
(Expr
)),
2356 Class_Present
=> Class_Present
(Aspect
),
2357 Split_PPC
=> True));
2358 Rewrite
(Expr
, Relocate_Node
(Right_Opnd
(Expr
)));
2359 Eloc
:= Sloc
(Expr
);
2363 -- Build the precondition/postcondition pragma
2365 -- Add note about why we do NOT need Copy_Tree here ???
2368 (Pragma_Argument_Associations
=> New_List
(
2369 Make_Pragma_Argument_Association
(Eloc
,
2370 Chars
=> Name_Check
,
2371 Expression
=> Relocate_Node
(Expr
))),
2372 Pragma_Name
=> Pname
);
2374 -- Add message unless exception messages are suppressed
2376 if not Opt
.Exception_Locations_Suppressed
then
2377 Append_To
(Pragma_Argument_Associations
(Aitem
),
2378 Make_Pragma_Argument_Association
(Eloc
,
2379 Chars
=> Name_Message
,
2381 Make_String_Literal
(Eloc
,
2383 & Get_Name_String
(Pname
)
2385 & Build_Location_String
(Eloc
))));
2388 Set_Is_Delayed_Aspect
(Aspect
);
2390 -- For Pre/Post cases, insert immediately after the entity
2391 -- declaration, since that is the required pragma placement.
2392 -- Note that for these aspects, we do not have to worry
2393 -- about delay issues, since the pragmas themselves deal
2394 -- with delay of visibility for the expression analysis.
2396 Insert_Delayed_Pragma
(Aitem
);
2402 when Aspect_Test_Case
=> Test_Case
: declare
2404 Comp_Expr
: Node_Id
;
2405 Comp_Assn
: Node_Id
;
2411 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
2412 Error_Msg_Name_1
:= Nam
;
2413 Error_Msg_N
("incorrect placement of aspect `%`", E
);
2417 if Nkind
(Expr
) /= N_Aggregate
then
2418 Error_Msg_Name_1
:= Nam
;
2420 ("wrong syntax for aspect `%` for &", Id
, E
);
2424 -- Make pragma expressions refer to the original aspect
2425 -- expressions through the Original_Node link. This is
2426 -- used in semantic analysis for ASIS mode, so that the
2427 -- original expression also gets analyzed.
2429 Comp_Expr
:= First
(Expressions
(Expr
));
2430 while Present
(Comp_Expr
) loop
2431 New_Expr
:= Relocate_Node
(Comp_Expr
);
2432 Set_Original_Node
(New_Expr
, Comp_Expr
);
2434 Make_Pragma_Argument_Association
(Sloc
(Comp_Expr
),
2435 Expression
=> New_Expr
));
2439 Comp_Assn
:= First
(Component_Associations
(Expr
));
2440 while Present
(Comp_Assn
) loop
2441 if List_Length
(Choices
(Comp_Assn
)) /= 1
2443 Nkind
(First
(Choices
(Comp_Assn
))) /= N_Identifier
2445 Error_Msg_Name_1
:= Nam
;
2447 ("wrong syntax for aspect `%` for &", Id
, E
);
2451 New_Expr
:= Relocate_Node
(Expression
(Comp_Assn
));
2452 Set_Original_Node
(New_Expr
, Expression
(Comp_Assn
));
2454 Make_Pragma_Argument_Association
(Sloc
(Comp_Assn
),
2455 Chars
=> Chars
(First
(Choices
(Comp_Assn
))),
2456 Expression
=> New_Expr
));
2460 -- Build the test-case pragma
2463 (Pragma_Argument_Associations
=> Args
,
2464 Pragma_Name
=> Nam
);
2469 when Aspect_Contract_Cases
=>
2471 (Pragma_Argument_Associations
=> New_List
(
2472 Make_Pragma_Argument_Association
(Loc
,
2473 Expression
=> Relocate_Node
(Expr
))),
2474 Pragma_Name
=> Nam
);
2476 Decorate_Delayed_Aspect_And_Pragma
(Aspect
, Aitem
);
2477 Insert_Delayed_Pragma
(Aitem
);
2480 -- Case 5: Special handling for aspects with an optional
2481 -- boolean argument.
2483 -- In the general case, the corresponding pragma cannot be
2484 -- generated yet because the evaluation of the boolean needs
2485 -- to be delayed till the freeze point.
2487 when Boolean_Aspects |
2488 Library_Unit_Aspects
=>
2490 Set_Is_Boolean_Aspect
(Aspect
);
2492 -- Lock_Free aspect only apply to protected objects
2494 if A_Id
= Aspect_Lock_Free
then
2495 if Ekind
(E
) /= E_Protected_Type
then
2496 Error_Msg_Name_1
:= Nam
;
2498 ("aspect % only applies to a protected object",
2502 -- Set the Uses_Lock_Free flag to True if there is no
2503 -- expression or if the expression is True. The
2504 -- evaluation of this aspect should be delayed to the
2505 -- freeze point (why???)
2508 or else Is_True
(Static_Boolean
(Expr
))
2510 Set_Uses_Lock_Free
(E
);
2513 Record_Rep_Item
(E
, Aspect
);
2518 elsif A_Id
= Aspect_Import
or else A_Id
= Aspect_Export
then
2520 -- Verify that there is an aspect Convention that will
2521 -- incorporate the Import/Export aspect, and eventual
2522 -- Link/External names.
2529 while Present
(A
) loop
2530 exit when Chars
(Identifier
(A
)) = Name_Convention
;
2534 -- It is legal to specify Import for a variable, in
2535 -- order to suppress initialization for it, without
2536 -- specifying explicitly its convention. However this
2537 -- is only legal if the convention of the object type
2538 -- is Ada or similar.
2541 if Ekind
(E
) = E_Variable
2542 and then A_Id
= Aspect_Import
2545 C
: constant Convention_Id
:=
2546 Convention
(Etype
(E
));
2548 if C
= Convention_Ada
or else
2549 C
= Convention_Ada_Pass_By_Copy
or else
2550 C
= Convention_Ada_Pass_By_Reference
2557 -- Otherwise, Convention must be specified
2560 ("missing Convention aspect for Export/Import",
2568 -- Library unit aspects require special handling in the case
2569 -- of a package declaration, the pragma needs to be inserted
2570 -- in the list of declarations for the associated package.
2571 -- There is no issue of visibility delay for these aspects.
2573 if A_Id
in Library_Unit_Aspects
2575 Nkind_In
(N
, N_Package_Declaration
,
2576 N_Generic_Package_Declaration
)
2577 and then Nkind
(Parent
(N
)) /= N_Compilation_Unit
2580 ("incorrect context for library unit aspect&", Id
);
2584 -- Cases where we do not delay, includes all cases where
2585 -- the expression is missing other than the above cases.
2587 if not Delay_Required
or else No
(Expr
) then
2589 (Pragma_Argument_Associations
=> New_List
(
2590 Make_Pragma_Argument_Association
(Sloc
(Ent
),
2591 Expression
=> Ent
)),
2592 Pragma_Name
=> Chars
(Id
));
2593 Delay_Required
:= False;
2595 -- In general cases, the corresponding pragma/attribute
2596 -- definition clause will be inserted later at the freezing
2597 -- point, and we do not need to build it now
2605 -- This is special because for access types we need to generate
2606 -- an attribute definition clause. This also works for single
2607 -- task declarations, but it does not work for task type
2608 -- declarations, because we have the case where the expression
2609 -- references a discriminant of the task type. That can't use
2610 -- an attribute definition clause because we would not have
2611 -- visibility on the discriminant. For that case we must
2612 -- generate a pragma in the task definition.
2614 when Aspect_Storage_Size
=>
2618 if Ekind
(E
) = E_Task_Type
then
2620 Decl
: constant Node_Id
:= Declaration_Node
(E
);
2623 pragma Assert
(Nkind
(Decl
) = N_Task_Type_Declaration
);
2625 -- If no task definition, create one
2627 if No
(Task_Definition
(Decl
)) then
2628 Set_Task_Definition
(Decl
,
2629 Make_Task_Definition
(Loc
,
2630 Visible_Declarations
=> Empty_List
,
2631 End_Label
=> Empty
));
2634 -- Create a pragma and put it at the start of the
2635 -- task definition for the task type declaration.
2638 (Pragma_Argument_Associations
=> New_List
(
2639 Make_Pragma_Argument_Association
(Loc
,
2640 Expression
=> Relocate_Node
(Expr
))),
2641 Pragma_Name
=> Name_Storage_Size
);
2645 Visible_Declarations
(Task_Definition
(Decl
)));
2649 -- All other cases, generate attribute definition
2653 Make_Attribute_Definition_Clause
(Loc
,
2655 Chars
=> Chars
(Id
),
2656 Expression
=> Relocate_Node
(Expr
));
2660 -- Attach the corresponding pragma/attribute definition clause to
2661 -- the aspect specification node.
2663 if Present
(Aitem
) then
2664 Set_From_Aspect_Specification
(Aitem
, True);
2667 -- In the context of a compilation unit, we directly put the
2668 -- pragma in the Pragmas_After list of the N_Compilation_Unit_Aux
2669 -- node (no delay is required here) except for aspects on a
2670 -- subprogram body (see below) and a generic package, for which
2671 -- we need to introduce the pragma before building the generic
2672 -- copy (see sem_ch12), and for package instantiations, where
2673 -- the library unit pragmas are better handled early.
2675 if Nkind
(Parent
(N
)) = N_Compilation_Unit
2676 and then (Present
(Aitem
) or else Is_Boolean_Aspect
(Aspect
))
2679 Aux
: constant Node_Id
:= Aux_Decls_Node
(Parent
(N
));
2682 pragma Assert
(Nkind
(Aux
) = N_Compilation_Unit_Aux
);
2684 -- For a Boolean aspect, create the corresponding pragma if
2685 -- no expression or if the value is True.
2687 if Is_Boolean_Aspect
(Aspect
) and then No
(Aitem
) then
2688 if Is_True
(Static_Boolean
(Expr
)) then
2690 (Pragma_Argument_Associations
=> New_List
(
2691 Make_Pragma_Argument_Association
(Sloc
(Ent
),
2692 Expression
=> Ent
)),
2693 Pragma_Name
=> Chars
(Id
));
2695 Set_From_Aspect_Specification
(Aitem
, True);
2696 Set_Corresponding_Aspect
(Aitem
, Aspect
);
2703 -- If the aspect is on a subprogram body (relevant aspect
2704 -- is Inline), add the pragma in front of the declarations.
2706 if Nkind
(N
) = N_Subprogram_Body
then
2707 if No
(Declarations
(N
)) then
2708 Set_Declarations
(N
, New_List
);
2711 Prepend
(Aitem
, Declarations
(N
));
2713 elsif Nkind
(N
) = N_Generic_Package_Declaration
then
2714 if No
(Visible_Declarations
(Specification
(N
))) then
2715 Set_Visible_Declarations
(Specification
(N
), New_List
);
2719 Visible_Declarations
(Specification
(N
)));
2721 elsif Nkind
(N
) = N_Package_Instantiation
then
2723 Spec
: constant Node_Id
:=
2724 Specification
(Instance_Spec
(N
));
2726 if No
(Visible_Declarations
(Spec
)) then
2727 Set_Visible_Declarations
(Spec
, New_List
);
2730 Prepend
(Aitem
, Visible_Declarations
(Spec
));
2734 if No
(Pragmas_After
(Aux
)) then
2735 Set_Pragmas_After
(Aux
, New_List
);
2738 Append
(Aitem
, Pragmas_After
(Aux
));
2745 -- The evaluation of the aspect is delayed to the freezing point.
2746 -- The pragma or attribute clause if there is one is then attached
2747 -- to the aspect specification which is put in the rep item list.
2749 if Delay_Required
then
2750 if Present
(Aitem
) then
2751 Set_Is_Delayed_Aspect
(Aitem
);
2752 Set_Aspect_Rep_Item
(Aspect
, Aitem
);
2753 Set_Parent
(Aitem
, Aspect
);
2756 Set_Is_Delayed_Aspect
(Aspect
);
2758 -- In the case of Default_Value, link the aspect to base type
2759 -- as well, even though it appears on a first subtype. This is
2760 -- mandated by the semantics of the aspect. Do not establish
2761 -- the link when processing the base type itself as this leads
2762 -- to a rep item circularity. Verify that we are dealing with
2763 -- a scalar type to prevent cascaded errors.
2765 if A_Id
= Aspect_Default_Value
2766 and then Is_Scalar_Type
(E
)
2767 and then Base_Type
(E
) /= E
2769 Set_Has_Delayed_Aspects
(Base_Type
(E
));
2770 Record_Rep_Item
(Base_Type
(E
), Aspect
);
2773 Set_Has_Delayed_Aspects
(E
);
2774 Record_Rep_Item
(E
, Aspect
);
2776 -- When delay is not required and the context is a package or a
2777 -- subprogram body, insert the pragma in the body declarations.
2779 elsif Nkind_In
(N
, N_Package_Body
, N_Subprogram_Body
) then
2780 if No
(Declarations
(N
)) then
2781 Set_Declarations
(N
, New_List
);
2784 -- The pragma is added before source declarations
2786 Prepend_To
(Declarations
(N
), Aitem
);
2788 -- When delay is not required and the context is not a compilation
2789 -- unit, we simply insert the pragma/attribute definition clause
2793 Insert_After
(Ins_Node
, Aitem
);
2796 end Analyze_One_Aspect
;
2800 end loop Aspect_Loop
;
2802 if Has_Delayed_Aspects
(E
) then
2803 Ensure_Freeze_Node
(E
);
2805 end Analyze_Aspect_Specifications
;
2807 -----------------------
2808 -- Analyze_At_Clause --
2809 -----------------------
2811 -- An at clause is replaced by the corresponding Address attribute
2812 -- definition clause that is the preferred approach in Ada 95.
2814 procedure Analyze_At_Clause
(N
: Node_Id
) is
2815 CS
: constant Boolean := Comes_From_Source
(N
);
2818 -- This is an obsolescent feature
2820 Check_Restriction
(No_Obsolescent_Features
, N
);
2822 if Warn_On_Obsolescent_Feature
then
2824 ("?j?at clause is an obsolescent feature (RM J.7(2))", N
);
2826 ("\?j?use address attribute definition clause instead", N
);
2829 -- Rewrite as address clause
2832 Make_Attribute_Definition_Clause
(Sloc
(N
),
2833 Name
=> Identifier
(N
),
2834 Chars
=> Name_Address
,
2835 Expression
=> Expression
(N
)));
2837 -- We preserve Comes_From_Source, since logically the clause still comes
2838 -- from the source program even though it is changed in form.
2840 Set_Comes_From_Source
(N
, CS
);
2842 -- Analyze rewritten clause
2844 Analyze_Attribute_Definition_Clause
(N
);
2845 end Analyze_At_Clause
;
2847 -----------------------------------------
2848 -- Analyze_Attribute_Definition_Clause --
2849 -----------------------------------------
2851 procedure Analyze_Attribute_Definition_Clause
(N
: Node_Id
) is
2852 Loc
: constant Source_Ptr
:= Sloc
(N
);
2853 Nam
: constant Node_Id
:= Name
(N
);
2854 Attr
: constant Name_Id
:= Chars
(N
);
2855 Expr
: constant Node_Id
:= Expression
(N
);
2856 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Attr
);
2859 -- The entity of Nam after it is analyzed. In the case of an incomplete
2860 -- type, this is the underlying type.
2863 -- The underlying entity to which the attribute applies. Generally this
2864 -- is the Underlying_Type of Ent, except in the case where the clause
2865 -- applies to full view of incomplete type or private type in which case
2866 -- U_Ent is just a copy of Ent.
2868 FOnly
: Boolean := False;
2869 -- Reset to True for subtype specific attribute (Alignment, Size)
2870 -- and for stream attributes, i.e. those cases where in the call
2871 -- to Rep_Item_Too_Late, FOnly is set True so that only the freezing
2872 -- rules are checked. Note that the case of stream attributes is not
2873 -- clear from the RM, but see AI95-00137. Also, the RM seems to
2874 -- disallow Storage_Size for derived task types, but that is also
2875 -- clearly unintentional.
2877 procedure Analyze_Stream_TSS_Definition
(TSS_Nam
: TSS_Name_Type
);
2878 -- Common processing for 'Read, 'Write, 'Input and 'Output attribute
2879 -- definition clauses.
2881 function Duplicate_Clause
return Boolean;
2882 -- This routine checks if the aspect for U_Ent being given by attribute
2883 -- definition clause N is for an aspect that has already been specified,
2884 -- and if so gives an error message. If there is a duplicate, True is
2885 -- returned, otherwise if there is no error, False is returned.
2887 procedure Check_Indexing_Functions
;
2888 -- Check that the function in Constant_Indexing or Variable_Indexing
2889 -- attribute has the proper type structure. If the name is overloaded,
2890 -- check that some interpretation is legal.
2892 procedure Check_Iterator_Functions
;
2893 -- Check that there is a single function in Default_Iterator attribute
2894 -- has the proper type structure.
2896 function Check_Primitive_Function
(Subp
: Entity_Id
) return Boolean;
2897 -- Common legality check for the previous two
2899 -----------------------------------
2900 -- Analyze_Stream_TSS_Definition --
2901 -----------------------------------
2903 procedure Analyze_Stream_TSS_Definition
(TSS_Nam
: TSS_Name_Type
) is
2904 Subp
: Entity_Id
:= Empty
;
2909 Is_Read
: constant Boolean := (TSS_Nam
= TSS_Stream_Read
);
2910 -- True for Read attribute, false for other attributes
2912 function Has_Good_Profile
(Subp
: Entity_Id
) return Boolean;
2913 -- Return true if the entity is a subprogram with an appropriate
2914 -- profile for the attribute being defined.
2916 ----------------------
2917 -- Has_Good_Profile --
2918 ----------------------
2920 function Has_Good_Profile
(Subp
: Entity_Id
) return Boolean is
2922 Is_Function
: constant Boolean := (TSS_Nam
= TSS_Stream_Input
);
2923 Expected_Ekind
: constant array (Boolean) of Entity_Kind
:=
2924 (False => E_Procedure
, True => E_Function
);
2928 if Ekind
(Subp
) /= Expected_Ekind
(Is_Function
) then
2932 F
:= First_Formal
(Subp
);
2935 or else Ekind
(Etype
(F
)) /= E_Anonymous_Access_Type
2936 or else Designated_Type
(Etype
(F
)) /=
2937 Class_Wide_Type
(RTE
(RE_Root_Stream_Type
))
2942 if not Is_Function
then
2946 Expected_Mode
: constant array (Boolean) of Entity_Kind
:=
2947 (False => E_In_Parameter
,
2948 True => E_Out_Parameter
);
2950 if Parameter_Mode
(F
) /= Expected_Mode
(Is_Read
) then
2958 Typ
:= Etype
(Subp
);
2961 return Base_Type
(Typ
) = Base_Type
(Ent
)
2962 and then No
(Next_Formal
(F
));
2963 end Has_Good_Profile
;
2965 -- Start of processing for Analyze_Stream_TSS_Definition
2970 if not Is_Type
(U_Ent
) then
2971 Error_Msg_N
("local name must be a subtype", Nam
);
2975 Pnam
:= TSS
(Base_Type
(U_Ent
), TSS_Nam
);
2977 -- If Pnam is present, it can be either inherited from an ancestor
2978 -- type (in which case it is legal to redefine it for this type), or
2979 -- be a previous definition of the attribute for the same type (in
2980 -- which case it is illegal).
2982 -- In the first case, it will have been analyzed already, and we
2983 -- can check that its profile does not match the expected profile
2984 -- for a stream attribute of U_Ent. In the second case, either Pnam
2985 -- has been analyzed (and has the expected profile), or it has not
2986 -- been analyzed yet (case of a type that has not been frozen yet
2987 -- and for which the stream attribute has been set using Set_TSS).
2990 and then (No
(First_Entity
(Pnam
)) or else Has_Good_Profile
(Pnam
))
2992 Error_Msg_Sloc
:= Sloc
(Pnam
);
2993 Error_Msg_Name_1
:= Attr
;
2994 Error_Msg_N
("% attribute already defined #", Nam
);
3000 if Is_Entity_Name
(Expr
) then
3001 if not Is_Overloaded
(Expr
) then
3002 if Has_Good_Profile
(Entity
(Expr
)) then
3003 Subp
:= Entity
(Expr
);
3007 Get_First_Interp
(Expr
, I
, It
);
3008 while Present
(It
.Nam
) loop
3009 if Has_Good_Profile
(It
.Nam
) then
3014 Get_Next_Interp
(I
, It
);
3019 if Present
(Subp
) then
3020 if Is_Abstract_Subprogram
(Subp
) then
3021 Error_Msg_N
("stream subprogram must not be abstract", Expr
);
3025 Set_Entity
(Expr
, Subp
);
3026 Set_Etype
(Expr
, Etype
(Subp
));
3028 New_Stream_Subprogram
(N
, U_Ent
, Subp
, TSS_Nam
);
3031 Error_Msg_Name_1
:= Attr
;
3032 Error_Msg_N
("incorrect expression for% attribute", Expr
);
3034 end Analyze_Stream_TSS_Definition
;
3036 ------------------------------
3037 -- Check_Indexing_Functions --
3038 ------------------------------
3040 procedure Check_Indexing_Functions
is
3041 Indexing_Found
: Boolean;
3043 procedure Check_One_Function
(Subp
: Entity_Id
);
3044 -- Check one possible interpretation. Sets Indexing_Found True if an
3045 -- indexing function is found.
3047 ------------------------
3048 -- Check_One_Function --
3049 ------------------------
3051 procedure Check_One_Function
(Subp
: Entity_Id
) is
3052 Default_Element
: constant Node_Id
:=
3053 Find_Value_Of_Aspect
3054 (Etype
(First_Formal
(Subp
)),
3055 Aspect_Iterator_Element
);
3058 if not Check_Primitive_Function
(Subp
)
3059 and then not Is_Overloaded
(Expr
)
3062 ("aspect Indexing requires a function that applies to type&",
3066 -- An indexing function must return either the default element of
3067 -- the container, or a reference type. For variable indexing it
3068 -- must be the latter.
3070 if Present
(Default_Element
) then
3071 Analyze
(Default_Element
);
3073 if Is_Entity_Name
(Default_Element
)
3074 and then Covers
(Entity
(Default_Element
), Etype
(Subp
))
3076 Indexing_Found
:= True;
3081 -- For variable_indexing the return type must be a reference type
3083 if Attr
= Name_Variable_Indexing
3084 and then not Has_Implicit_Dereference
(Etype
(Subp
))
3087 ("function for indexing must return a reference type", Subp
);
3090 Indexing_Found
:= True;
3092 end Check_One_Function
;
3094 -- Start of processing for Check_Indexing_Functions
3103 if not Is_Overloaded
(Expr
) then
3104 Check_One_Function
(Entity
(Expr
));
3112 Indexing_Found
:= False;
3113 Get_First_Interp
(Expr
, I
, It
);
3114 while Present
(It
.Nam
) loop
3116 -- Note that analysis will have added the interpretation
3117 -- that corresponds to the dereference. We only check the
3118 -- subprogram itself.
3120 if Is_Overloadable
(It
.Nam
) then
3121 Check_One_Function
(It
.Nam
);
3124 Get_Next_Interp
(I
, It
);
3127 if not Indexing_Found
then
3129 ("aspect Indexing requires a function that "
3130 & "applies to type&", Expr
, Ent
);
3134 end Check_Indexing_Functions
;
3136 ------------------------------
3137 -- Check_Iterator_Functions --
3138 ------------------------------
3140 procedure Check_Iterator_Functions
is
3141 Default
: Entity_Id
;
3143 function Valid_Default_Iterator
(Subp
: Entity_Id
) return Boolean;
3144 -- Check one possible interpretation for validity
3146 ----------------------------
3147 -- Valid_Default_Iterator --
3148 ----------------------------
3150 function Valid_Default_Iterator
(Subp
: Entity_Id
) return Boolean is
3154 if not Check_Primitive_Function
(Subp
) then
3157 Formal
:= First_Formal
(Subp
);
3160 -- False if any subsequent formal has no default expression
3162 Formal
:= Next_Formal
(Formal
);
3163 while Present
(Formal
) loop
3164 if No
(Expression
(Parent
(Formal
))) then
3168 Next_Formal
(Formal
);
3171 -- True if all subsequent formals have default expressions
3174 end Valid_Default_Iterator
;
3176 -- Start of processing for Check_Iterator_Functions
3181 if not Is_Entity_Name
(Expr
) then
3182 Error_Msg_N
("aspect Iterator must be a function name", Expr
);
3185 if not Is_Overloaded
(Expr
) then
3186 if not Check_Primitive_Function
(Entity
(Expr
)) then
3188 ("aspect Indexing requires a function that applies to type&",
3189 Entity
(Expr
), Ent
);
3192 if not Valid_Default_Iterator
(Entity
(Expr
)) then
3193 Error_Msg_N
("improper function for default iterator", Expr
);
3203 Get_First_Interp
(Expr
, I
, It
);
3204 while Present
(It
.Nam
) loop
3205 if not Check_Primitive_Function
(It
.Nam
)
3206 or else not Valid_Default_Iterator
(It
.Nam
)
3210 elsif Present
(Default
) then
3211 Error_Msg_N
("default iterator must be unique", Expr
);
3217 Get_Next_Interp
(I
, It
);
3221 if Present
(Default
) then
3222 Set_Entity
(Expr
, Default
);
3223 Set_Is_Overloaded
(Expr
, False);
3226 end Check_Iterator_Functions
;
3228 -------------------------------
3229 -- Check_Primitive_Function --
3230 -------------------------------
3232 function Check_Primitive_Function
(Subp
: Entity_Id
) return Boolean is
3236 if Ekind
(Subp
) /= E_Function
then
3240 if No
(First_Formal
(Subp
)) then
3243 Ctrl
:= Etype
(First_Formal
(Subp
));
3247 or else Ctrl
= Class_Wide_Type
(Ent
)
3249 (Ekind
(Ctrl
) = E_Anonymous_Access_Type
3251 (Designated_Type
(Ctrl
) = Ent
3252 or else Designated_Type
(Ctrl
) = Class_Wide_Type
(Ent
)))
3261 end Check_Primitive_Function
;
3263 ----------------------
3264 -- Duplicate_Clause --
3265 ----------------------
3267 function Duplicate_Clause
return Boolean is
3271 -- Nothing to do if this attribute definition clause comes from
3272 -- an aspect specification, since we could not be duplicating an
3273 -- explicit clause, and we dealt with the case of duplicated aspects
3274 -- in Analyze_Aspect_Specifications.
3276 if From_Aspect_Specification
(N
) then
3280 -- Otherwise current clause may duplicate previous clause, or a
3281 -- previously given pragma or aspect specification for the same
3284 A
:= Get_Rep_Item
(U_Ent
, Chars
(N
), Check_Parents
=> False);
3287 Error_Msg_Name_1
:= Chars
(N
);
3288 Error_Msg_Sloc
:= Sloc
(A
);
3290 Error_Msg_NE
("aspect% for & previously given#", N
, U_Ent
);
3295 end Duplicate_Clause
;
3297 -- Start of processing for Analyze_Attribute_Definition_Clause
3300 -- The following code is a defense against recursion. Not clear that
3301 -- this can happen legitimately, but perhaps some error situations
3302 -- can cause it, and we did see this recursion during testing.
3304 if Analyzed
(N
) then
3307 Set_Analyzed
(N
, True);
3310 -- Ignore some selected attributes in CodePeer mode since they are not
3311 -- relevant in this context.
3313 if CodePeer_Mode
then
3316 -- Ignore Component_Size in CodePeer mode, to avoid changing the
3317 -- internal representation of types by implicitly packing them.
3319 when Attribute_Component_Size
=>
3320 Rewrite
(N
, Make_Null_Statement
(Sloc
(N
)));
3328 -- Process Ignore_Rep_Clauses option
3330 if Ignore_Rep_Clauses
then
3333 -- The following should be ignored. They do not affect legality
3334 -- and may be target dependent. The basic idea of -gnatI is to
3335 -- ignore any rep clauses that may be target dependent but do not
3336 -- affect legality (except possibly to be rejected because they
3337 -- are incompatible with the compilation target).
3339 when Attribute_Alignment |
3340 Attribute_Bit_Order |
3341 Attribute_Component_Size |
3342 Attribute_Machine_Radix |
3343 Attribute_Object_Size |
3345 Attribute_Stream_Size |
3346 Attribute_Value_Size
=>
3347 Rewrite
(N
, Make_Null_Statement
(Sloc
(N
)));
3350 -- Perhaps 'Small should not be ignored by Ignore_Rep_Clauses ???
3352 when Attribute_Small
=>
3353 if Ignore_Rep_Clauses
then
3354 Rewrite
(N
, Make_Null_Statement
(Sloc
(N
)));
3358 -- The following should not be ignored, because in the first place
3359 -- they are reasonably portable, and should not cause problems in
3360 -- compiling code from another target, and also they do affect
3361 -- legality, e.g. failing to provide a stream attribute for a
3362 -- type may make a program illegal.
3364 when Attribute_External_Tag |
3368 Attribute_Simple_Storage_Pool |
3369 Attribute_Storage_Pool |
3370 Attribute_Storage_Size |
3374 -- Other cases are errors ("attribute& cannot be set with
3375 -- definition clause"), which will be caught below.
3383 Ent
:= Entity
(Nam
);
3385 if Rep_Item_Too_Early
(Ent
, N
) then
3389 -- Rep clause applies to full view of incomplete type or private type if
3390 -- we have one (if not, this is a premature use of the type). However,
3391 -- certain semantic checks need to be done on the specified entity (i.e.
3392 -- the private view), so we save it in Ent.
3394 if Is_Private_Type
(Ent
)
3395 and then Is_Derived_Type
(Ent
)
3396 and then not Is_Tagged_Type
(Ent
)
3397 and then No
(Full_View
(Ent
))
3399 -- If this is a private type whose completion is a derivation from
3400 -- another private type, there is no full view, and the attribute
3401 -- belongs to the type itself, not its underlying parent.
3405 elsif Ekind
(Ent
) = E_Incomplete_Type
then
3407 -- The attribute applies to the full view, set the entity of the
3408 -- attribute definition accordingly.
3410 Ent
:= Underlying_Type
(Ent
);
3412 Set_Entity
(Nam
, Ent
);
3415 U_Ent
:= Underlying_Type
(Ent
);
3418 -- Avoid cascaded error
3420 if Etype
(Nam
) = Any_Type
then
3423 -- Must be declared in current scope or in case of an aspect
3424 -- specification, must be visible in current scope.
3426 elsif Scope
(Ent
) /= Current_Scope
3428 not (From_Aspect_Specification
(N
)
3429 and then Scope_Within_Or_Same
(Current_Scope
, Scope
(Ent
)))
3431 Error_Msg_N
("entity must be declared in this scope", Nam
);
3434 -- Must not be a source renaming (we do have some cases where the
3435 -- expander generates a renaming, and those cases are OK, in such
3436 -- cases any attribute applies to the renamed object as well).
3438 elsif Is_Object
(Ent
)
3439 and then Present
(Renamed_Object
(Ent
))
3441 -- Case of renamed object from source, this is an error
3443 if Comes_From_Source
(Renamed_Object
(Ent
)) then
3444 Get_Name_String
(Chars
(N
));
3445 Error_Msg_Strlen
:= Name_Len
;
3446 Error_Msg_String
(1 .. Name_Len
) := Name_Buffer
(1 .. Name_Len
);
3448 ("~ clause not allowed for a renaming declaration "
3449 & "(RM 13.1(6))", Nam
);
3452 -- For the case of a compiler generated renaming, the attribute
3453 -- definition clause applies to the renamed object created by the
3454 -- expander. The easiest general way to handle this is to create a
3455 -- copy of the attribute definition clause for this object.
3459 Make_Attribute_Definition_Clause
(Loc
,
3461 New_Occurrence_Of
(Entity
(Renamed_Object
(Ent
)), Loc
),
3463 Expression
=> Duplicate_Subexpr
(Expression
(N
))));
3466 -- If no underlying entity, use entity itself, applies to some
3467 -- previously detected error cases ???
3469 elsif No
(U_Ent
) then
3472 -- Cannot specify for a subtype (exception Object/Value_Size)
3474 elsif Is_Type
(U_Ent
)
3475 and then not Is_First_Subtype
(U_Ent
)
3476 and then Id
/= Attribute_Object_Size
3477 and then Id
/= Attribute_Value_Size
3478 and then not From_At_Mod
(N
)
3480 Error_Msg_N
("cannot specify attribute for subtype", Nam
);
3484 Set_Entity
(N
, U_Ent
);
3485 Check_Restriction_No_Use_Of_Attribute
(N
);
3487 -- Switch on particular attribute
3495 -- Address attribute definition clause
3497 when Attribute_Address
=> Address
: begin
3499 -- A little error check, catch for X'Address use X'Address;
3501 if Nkind
(Nam
) = N_Identifier
3502 and then Nkind
(Expr
) = N_Attribute_Reference
3503 and then Attribute_Name
(Expr
) = Name_Address
3504 and then Nkind
(Prefix
(Expr
)) = N_Identifier
3505 and then Chars
(Nam
) = Chars
(Prefix
(Expr
))
3508 ("address for & is self-referencing", Prefix
(Expr
), Ent
);
3512 -- Not that special case, carry on with analysis of expression
3514 Analyze_And_Resolve
(Expr
, RTE
(RE_Address
));
3516 -- Even when ignoring rep clauses we need to indicate that the
3517 -- entity has an address clause and thus it is legal to declare
3520 if Ignore_Rep_Clauses
then
3521 if Ekind_In
(U_Ent
, E_Variable
, E_Constant
) then
3522 Record_Rep_Item
(U_Ent
, N
);
3528 if Duplicate_Clause
then
3531 -- Case of address clause for subprogram
3533 elsif Is_Subprogram
(U_Ent
) then
3534 if Has_Homonym
(U_Ent
) then
3536 ("address clause cannot be given " &
3537 "for overloaded subprogram",
3542 -- For subprograms, all address clauses are permitted, and we
3543 -- mark the subprogram as having a deferred freeze so that Gigi
3544 -- will not elaborate it too soon.
3546 -- Above needs more comments, what is too soon about???
3548 Set_Has_Delayed_Freeze
(U_Ent
);
3550 -- Case of address clause for entry
3552 elsif Ekind
(U_Ent
) = E_Entry
then
3553 if Nkind
(Parent
(N
)) = N_Task_Body
then
3555 ("entry address must be specified in task spec", Nam
);
3559 -- For entries, we require a constant address
3561 Check_Constant_Address_Clause
(Expr
, U_Ent
);
3563 -- Special checks for task types
3565 if Is_Task_Type
(Scope
(U_Ent
))
3566 and then Comes_From_Source
(Scope
(U_Ent
))
3569 ("??entry address declared for entry in task type", N
);
3571 ("\??only one task can be declared of this type", N
);
3574 -- Entry address clauses are obsolescent
3576 Check_Restriction
(No_Obsolescent_Features
, N
);
3578 if Warn_On_Obsolescent_Feature
then
3580 ("?j?attaching interrupt to task entry is an " &
3581 "obsolescent feature (RM J.7.1)", N
);
3583 ("\?j?use interrupt procedure instead", N
);
3586 -- Case of an address clause for a controlled object which we
3587 -- consider to be erroneous.
3589 elsif Is_Controlled
(Etype
(U_Ent
))
3590 or else Has_Controlled_Component
(Etype
(U_Ent
))
3593 ("??controlled object& must not be overlaid", Nam
, U_Ent
);
3595 ("\??Program_Error will be raised at run time", Nam
);
3596 Insert_Action
(Declaration_Node
(U_Ent
),
3597 Make_Raise_Program_Error
(Loc
,
3598 Reason
=> PE_Overlaid_Controlled_Object
));
3601 -- Case of address clause for a (non-controlled) object
3604 Ekind
(U_Ent
) = E_Variable
3606 Ekind
(U_Ent
) = E_Constant
3609 Expr
: constant Node_Id
:= Expression
(N
);
3614 -- Exported variables cannot have an address clause, because
3615 -- this cancels the effect of the pragma Export.
3617 if Is_Exported
(U_Ent
) then
3619 ("cannot export object with address clause", Nam
);
3623 Find_Overlaid_Entity
(N
, O_Ent
, Off
);
3625 -- Overlaying controlled objects is erroneous
3628 and then (Has_Controlled_Component
(Etype
(O_Ent
))
3629 or else Is_Controlled
(Etype
(O_Ent
)))
3632 ("??cannot overlay with controlled object", Expr
);
3634 ("\??Program_Error will be raised at run time", Expr
);
3635 Insert_Action
(Declaration_Node
(U_Ent
),
3636 Make_Raise_Program_Error
(Loc
,
3637 Reason
=> PE_Overlaid_Controlled_Object
));
3640 elsif Present
(O_Ent
)
3641 and then Ekind
(U_Ent
) = E_Constant
3642 and then not Is_Constant_Object
(O_Ent
)
3644 Error_Msg_N
("??constant overlays a variable", Expr
);
3646 -- Imported variables can have an address clause, but then
3647 -- the import is pretty meaningless except to suppress
3648 -- initializations, so we do not need such variables to
3649 -- be statically allocated (and in fact it causes trouble
3650 -- if the address clause is a local value).
3652 elsif Is_Imported
(U_Ent
) then
3653 Set_Is_Statically_Allocated
(U_Ent
, False);
3656 -- We mark a possible modification of a variable with an
3657 -- address clause, since it is likely aliasing is occurring.
3659 Note_Possible_Modification
(Nam
, Sure
=> False);
3661 -- Here we are checking for explicit overlap of one variable
3662 -- by another, and if we find this then mark the overlapped
3663 -- variable as also being volatile to prevent unwanted
3664 -- optimizations. This is a significant pessimization so
3665 -- avoid it when there is an offset, i.e. when the object
3666 -- is composite; they cannot be optimized easily anyway.
3669 and then Is_Object
(O_Ent
)
3672 -- The following test is an expedient solution to what
3673 -- is really a problem in CodePeer. Suppressing the
3674 -- Set_Treat_As_Volatile call here prevents later
3675 -- generation (in some cases) of trees that CodePeer
3676 -- should, but currently does not, handle correctly.
3677 -- This test should probably be removed when CodePeer
3678 -- is improved, just because we want the tree CodePeer
3679 -- analyzes to match the tree for which we generate code
3680 -- as closely as is practical. ???
3682 and then not CodePeer_Mode
3684 -- ??? O_Ent might not be in current unit
3686 Set_Treat_As_Volatile
(O_Ent
);
3689 -- Legality checks on the address clause for initialized
3690 -- objects is deferred until the freeze point, because
3691 -- a subsequent pragma might indicate that the object
3692 -- is imported and thus not initialized. Also, the address
3693 -- clause might involve entities that have yet to be
3696 Set_Has_Delayed_Freeze
(U_Ent
);
3698 -- If an initialization call has been generated for this
3699 -- object, it needs to be deferred to after the freeze node
3700 -- we have just now added, otherwise GIGI will see a
3701 -- reference to the variable (as actual to the IP call)
3702 -- before its definition.
3705 Init_Call
: constant Node_Id
:=
3706 Remove_Init_Call
(U_Ent
, N
);
3709 if Present
(Init_Call
) then
3711 -- If the init call is an expression with actions with
3712 -- null expression, just extract the actions.
3714 if Nkind
(Init_Call
) = N_Expression_With_Actions
3716 Nkind
(Expression
(Init_Call
)) = N_Null_Statement
3718 Append_Freeze_Actions
(U_Ent
, Actions
(Init_Call
));
3720 -- General case: move Init_Call to freeze actions
3723 Append_Freeze_Action
(U_Ent
, Init_Call
);
3728 if Is_Exported
(U_Ent
) then
3730 ("& cannot be exported if an address clause is given",
3733 ("\define and export a variable "
3734 & "that holds its address instead", Nam
);
3737 -- Entity has delayed freeze, so we will generate an
3738 -- alignment check at the freeze point unless suppressed.
3740 if not Range_Checks_Suppressed
(U_Ent
)
3741 and then not Alignment_Checks_Suppressed
(U_Ent
)
3743 Set_Check_Address_Alignment
(N
);
3746 -- Kill the size check code, since we are not allocating
3747 -- the variable, it is somewhere else.
3749 Kill_Size_Check_Code
(U_Ent
);
3751 -- If the address clause is of the form:
3753 -- for Y'Address use X'Address
3757 -- Const : constant Address := X'Address;
3759 -- for Y'Address use Const;
3761 -- then we make an entry in the table for checking the size
3762 -- and alignment of the overlaying variable. We defer this
3763 -- check till after code generation to take full advantage
3764 -- of the annotation done by the back end.
3766 -- If the entity has a generic type, the check will be
3767 -- performed in the instance if the actual type justifies
3768 -- it, and we do not insert the clause in the table to
3769 -- prevent spurious warnings.
3771 -- Note: we used to test Comes_From_Source and only give
3772 -- this warning for source entities, but we have removed
3773 -- this test. It really seems bogus to generate overlays
3774 -- that would trigger this warning in generated code.
3775 -- Furthermore, by removing the test, we handle the
3776 -- aspect case properly.
3778 if Address_Clause_Overlay_Warnings
3779 and then Present
(O_Ent
)
3780 and then Is_Object
(O_Ent
)
3782 if not Is_Generic_Type
(Etype
(U_Ent
)) then
3783 Address_Clause_Checks
.Append
((N
, U_Ent
, O_Ent
, Off
));
3786 -- If variable overlays a constant view, and we are
3787 -- warning on overlays, then mark the variable as
3788 -- overlaying a constant (we will give warnings later
3789 -- if this variable is assigned).
3791 if Is_Constant_Object
(O_Ent
)
3792 and then Ekind
(U_Ent
) = E_Variable
3794 Set_Overlays_Constant
(U_Ent
);
3799 -- Not a valid entity for an address clause
3802 Error_Msg_N
("address cannot be given for &", Nam
);
3810 -- Alignment attribute definition clause
3812 when Attribute_Alignment
=> Alignment
: declare
3813 Align
: constant Uint
:= Get_Alignment_Value
(Expr
);
3814 Max_Align
: constant Uint
:= UI_From_Int
(Maximum_Alignment
);
3819 if not Is_Type
(U_Ent
)
3820 and then Ekind
(U_Ent
) /= E_Variable
3821 and then Ekind
(U_Ent
) /= E_Constant
3823 Error_Msg_N
("alignment cannot be given for &", Nam
);
3825 elsif Duplicate_Clause
then
3828 elsif Align
/= No_Uint
then
3829 Set_Has_Alignment_Clause
(U_Ent
);
3831 -- Tagged type case, check for attempt to set alignment to a
3832 -- value greater than Max_Align, and reset if so.
3834 if Is_Tagged_Type
(U_Ent
) and then Align
> Max_Align
then
3836 ("alignment for & set to Maximum_Aligment??", Nam
);
3837 Set_Alignment
(U_Ent
, Max_Align
);
3842 Set_Alignment
(U_Ent
, Align
);
3845 -- For an array type, U_Ent is the first subtype. In that case,
3846 -- also set the alignment of the anonymous base type so that
3847 -- other subtypes (such as the itypes for aggregates of the
3848 -- type) also receive the expected alignment.
3850 if Is_Array_Type
(U_Ent
) then
3851 Set_Alignment
(Base_Type
(U_Ent
), Align
);
3860 -- Bit_Order attribute definition clause
3862 when Attribute_Bit_Order
=> Bit_Order
: declare
3864 if not Is_Record_Type
(U_Ent
) then
3866 ("Bit_Order can only be defined for record type", Nam
);
3868 elsif Duplicate_Clause
then
3872 Analyze_And_Resolve
(Expr
, RTE
(RE_Bit_Order
));
3874 if Etype
(Expr
) = Any_Type
then
3877 elsif not Is_Static_Expression
(Expr
) then
3878 Flag_Non_Static_Expr
3879 ("Bit_Order requires static expression!", Expr
);
3882 if (Expr_Value
(Expr
) = 0) /= Bytes_Big_Endian
then
3883 Set_Reverse_Bit_Order
(U_Ent
, True);
3889 --------------------
3890 -- Component_Size --
3891 --------------------
3893 -- Component_Size attribute definition clause
3895 when Attribute_Component_Size
=> Component_Size_Case
: declare
3896 Csize
: constant Uint
:= Static_Integer
(Expr
);
3900 New_Ctyp
: Entity_Id
;
3904 if not Is_Array_Type
(U_Ent
) then
3905 Error_Msg_N
("component size requires array type", Nam
);
3909 Btype
:= Base_Type
(U_Ent
);
3910 Ctyp
:= Component_Type
(Btype
);
3912 if Duplicate_Clause
then
3915 elsif Rep_Item_Too_Early
(Btype
, N
) then
3918 elsif Csize
/= No_Uint
then
3919 Check_Size
(Expr
, Ctyp
, Csize
, Biased
);
3921 -- For the biased case, build a declaration for a subtype that
3922 -- will be used to represent the biased subtype that reflects
3923 -- the biased representation of components. We need the subtype
3924 -- to get proper conversions on referencing elements of the
3925 -- array. Note: component size clauses are ignored in VM mode.
3927 if VM_Target
= No_VM
then
3930 Make_Defining_Identifier
(Loc
,
3932 New_External_Name
(Chars
(U_Ent
), 'C', 0, 'T'));
3935 Make_Subtype_Declaration
(Loc
,
3936 Defining_Identifier
=> New_Ctyp
,
3937 Subtype_Indication
=>
3938 New_Occurrence_Of
(Component_Type
(Btype
), Loc
));
3940 Set_Parent
(Decl
, N
);
3941 Analyze
(Decl
, Suppress
=> All_Checks
);
3943 Set_Has_Delayed_Freeze
(New_Ctyp
, False);
3944 Set_Esize
(New_Ctyp
, Csize
);
3945 Set_RM_Size
(New_Ctyp
, Csize
);
3946 Init_Alignment
(New_Ctyp
);
3947 Set_Is_Itype
(New_Ctyp
, True);
3948 Set_Associated_Node_For_Itype
(New_Ctyp
, U_Ent
);
3950 Set_Component_Type
(Btype
, New_Ctyp
);
3951 Set_Biased
(New_Ctyp
, N
, "component size clause");
3954 Set_Component_Size
(Btype
, Csize
);
3956 -- For VM case, we ignore component size clauses
3959 -- Give a warning unless we are in GNAT mode, in which case
3960 -- the warning is suppressed since it is not useful.
3962 if not GNAT_Mode
then
3964 ("component size ignored in this configuration??", N
);
3968 -- Deal with warning on overridden size
3970 if Warn_On_Overridden_Size
3971 and then Has_Size_Clause
(Ctyp
)
3972 and then RM_Size
(Ctyp
) /= Csize
3975 ("component size overrides size clause for&?S?", N
, Ctyp
);
3978 Set_Has_Component_Size_Clause
(Btype
, True);
3979 Set_Has_Non_Standard_Rep
(Btype
, True);
3981 end Component_Size_Case
;
3983 -----------------------
3984 -- Constant_Indexing --
3985 -----------------------
3987 when Attribute_Constant_Indexing
=>
3988 Check_Indexing_Functions
;
3994 when Attribute_CPU
=> CPU
:
3996 -- CPU attribute definition clause not allowed except from aspect
3999 if From_Aspect_Specification
(N
) then
4000 if not Is_Task_Type
(U_Ent
) then
4001 Error_Msg_N
("CPU can only be defined for task", Nam
);
4003 elsif Duplicate_Clause
then
4007 -- The expression must be analyzed in the special manner
4008 -- described in "Handling of Default and Per-Object
4009 -- Expressions" in sem.ads.
4011 -- The visibility to the discriminants must be restored
4013 Push_Scope_And_Install_Discriminants
(U_Ent
);
4014 Preanalyze_Spec_Expression
(Expr
, RTE
(RE_CPU_Range
));
4015 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
4017 if not Is_Static_Expression
(Expr
) then
4018 Check_Restriction
(Static_Priorities
, Expr
);
4024 ("attribute& cannot be set with definition clause", N
);
4028 ----------------------
4029 -- Default_Iterator --
4030 ----------------------
4032 when Attribute_Default_Iterator
=> Default_Iterator
: declare
4036 if not Is_Tagged_Type
(U_Ent
) then
4038 ("aspect Default_Iterator applies to tagged type", Nam
);
4041 Check_Iterator_Functions
;
4045 if not Is_Entity_Name
(Expr
)
4046 or else Ekind
(Entity
(Expr
)) /= E_Function
4048 Error_Msg_N
("aspect Iterator must be a function", Expr
);
4050 Func
:= Entity
(Expr
);
4053 if No
(First_Formal
(Func
))
4054 or else Etype
(First_Formal
(Func
)) /= U_Ent
4057 ("Default Iterator must be a primitive of&", Func
, U_Ent
);
4059 end Default_Iterator
;
4061 ------------------------
4062 -- Dispatching_Domain --
4063 ------------------------
4065 when Attribute_Dispatching_Domain
=> Dispatching_Domain
:
4067 -- Dispatching_Domain attribute definition clause not allowed
4068 -- except from aspect specification.
4070 if From_Aspect_Specification
(N
) then
4071 if not Is_Task_Type
(U_Ent
) then
4072 Error_Msg_N
("Dispatching_Domain can only be defined" &
4076 elsif Duplicate_Clause
then
4080 -- The expression must be analyzed in the special manner
4081 -- described in "Handling of Default and Per-Object
4082 -- Expressions" in sem.ads.
4084 -- The visibility to the discriminants must be restored
4086 Push_Scope_And_Install_Discriminants
(U_Ent
);
4088 Preanalyze_Spec_Expression
4089 (Expr
, RTE
(RE_Dispatching_Domain
));
4091 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
4096 ("attribute& cannot be set with definition clause", N
);
4098 end Dispatching_Domain
;
4104 when Attribute_External_Tag
=> External_Tag
:
4106 if not Is_Tagged_Type
(U_Ent
) then
4107 Error_Msg_N
("should be a tagged type", Nam
);
4110 if Duplicate_Clause
then
4114 Analyze_And_Resolve
(Expr
, Standard_String
);
4116 if not Is_Static_Expression
(Expr
) then
4117 Flag_Non_Static_Expr
4118 ("static string required for tag name!", Nam
);
4121 if VM_Target
= No_VM
then
4122 Set_Has_External_Tag_Rep_Clause
(U_Ent
);
4124 Error_Msg_Name_1
:= Attr
;
4126 ("% attribute unsupported in this configuration", Nam
);
4129 if not Is_Library_Level_Entity
(U_Ent
) then
4131 ("??non-unique external tag supplied for &", N
, U_Ent
);
4133 ("\??same external tag applies to all "
4134 & "subprogram calls", N
);
4136 ("\??corresponding internal tag cannot be obtained", N
);
4141 --------------------------
4142 -- Implicit_Dereference --
4143 --------------------------
4145 when Attribute_Implicit_Dereference
=>
4147 -- Legality checks already performed at the point of the type
4148 -- declaration, aspect is not delayed.
4156 when Attribute_Input
=>
4157 Analyze_Stream_TSS_Definition
(TSS_Stream_Input
);
4158 Set_Has_Specified_Stream_Input
(Ent
);
4160 ------------------------
4161 -- Interrupt_Priority --
4162 ------------------------
4164 when Attribute_Interrupt_Priority
=> Interrupt_Priority
:
4166 -- Interrupt_Priority attribute definition clause not allowed
4167 -- except from aspect specification.
4169 if From_Aspect_Specification
(N
) then
4170 if not (Is_Protected_Type
(U_Ent
)
4171 or else Is_Task_Type
(U_Ent
))
4174 ("Interrupt_Priority can only be defined for task" &
4175 "and protected object",
4178 elsif Duplicate_Clause
then
4182 -- The expression must be analyzed in the special manner
4183 -- described in "Handling of Default and Per-Object
4184 -- Expressions" in sem.ads.
4186 -- The visibility to the discriminants must be restored
4188 Push_Scope_And_Install_Discriminants
(U_Ent
);
4190 Preanalyze_Spec_Expression
4191 (Expr
, RTE
(RE_Interrupt_Priority
));
4193 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
4198 ("attribute& cannot be set with definition clause", N
);
4200 end Interrupt_Priority
;
4202 ----------------------
4203 -- Iterator_Element --
4204 ----------------------
4206 when Attribute_Iterator_Element
=>
4209 if not Is_Entity_Name
(Expr
)
4210 or else not Is_Type
(Entity
(Expr
))
4212 Error_Msg_N
("aspect Iterator_Element must be a type", Expr
);
4219 -- Machine radix attribute definition clause
4221 when Attribute_Machine_Radix
=> Machine_Radix
: declare
4222 Radix
: constant Uint
:= Static_Integer
(Expr
);
4225 if not Is_Decimal_Fixed_Point_Type
(U_Ent
) then
4226 Error_Msg_N
("decimal fixed-point type expected for &", Nam
);
4228 elsif Duplicate_Clause
then
4231 elsif Radix
/= No_Uint
then
4232 Set_Has_Machine_Radix_Clause
(U_Ent
);
4233 Set_Has_Non_Standard_Rep
(Base_Type
(U_Ent
));
4237 elsif Radix
= 10 then
4238 Set_Machine_Radix_10
(U_Ent
);
4240 Error_Msg_N
("machine radix value must be 2 or 10", Expr
);
4249 -- Object_Size attribute definition clause
4251 when Attribute_Object_Size
=> Object_Size
: declare
4252 Size
: constant Uint
:= Static_Integer
(Expr
);
4255 pragma Warnings
(Off
, Biased
);
4258 if not Is_Type
(U_Ent
) then
4259 Error_Msg_N
("Object_Size cannot be given for &", Nam
);
4261 elsif Duplicate_Clause
then
4265 Check_Size
(Expr
, U_Ent
, Size
, Biased
);
4273 UI_Mod
(Size
, 64) /= 0
4276 ("Object_Size must be 8, 16, 32, or multiple of 64",
4280 Set_Esize
(U_Ent
, Size
);
4281 Set_Has_Object_Size_Clause
(U_Ent
);
4282 Alignment_Check_For_Size_Change
(U_Ent
, Size
);
4290 when Attribute_Output
=>
4291 Analyze_Stream_TSS_Definition
(TSS_Stream_Output
);
4292 Set_Has_Specified_Stream_Output
(Ent
);
4298 when Attribute_Priority
=> Priority
:
4300 -- Priority attribute definition clause not allowed except from
4301 -- aspect specification.
4303 if From_Aspect_Specification
(N
) then
4304 if not (Is_Protected_Type
(U_Ent
)
4305 or else Is_Task_Type
(U_Ent
)
4306 or else Ekind
(U_Ent
) = E_Procedure
)
4309 ("Priority can only be defined for task and protected " &
4313 elsif Duplicate_Clause
then
4317 -- The expression must be analyzed in the special manner
4318 -- described in "Handling of Default and Per-Object
4319 -- Expressions" in sem.ads.
4321 -- The visibility to the discriminants must be restored
4323 Push_Scope_And_Install_Discriminants
(U_Ent
);
4324 Preanalyze_Spec_Expression
(Expr
, Standard_Integer
);
4325 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
4327 if not Is_Static_Expression
(Expr
) then
4328 Check_Restriction
(Static_Priorities
, Expr
);
4334 ("attribute& cannot be set with definition clause", N
);
4342 when Attribute_Read
=>
4343 Analyze_Stream_TSS_Definition
(TSS_Stream_Read
);
4344 Set_Has_Specified_Stream_Read
(Ent
);
4346 --------------------------
4347 -- Scalar_Storage_Order --
4348 --------------------------
4350 -- Scalar_Storage_Order attribute definition clause
4352 when Attribute_Scalar_Storage_Order
=> Scalar_Storage_Order
: declare
4354 if not (Is_Record_Type
(U_Ent
) or else Is_Array_Type
(U_Ent
)) then
4356 ("Scalar_Storage_Order can only be defined for "
4357 & "record or array type", Nam
);
4359 elsif Duplicate_Clause
then
4363 Analyze_And_Resolve
(Expr
, RTE
(RE_Bit_Order
));
4365 if Etype
(Expr
) = Any_Type
then
4368 elsif not Is_Static_Expression
(Expr
) then
4369 Flag_Non_Static_Expr
4370 ("Scalar_Storage_Order requires static expression!", Expr
);
4372 elsif (Expr_Value
(Expr
) = 0) /= Bytes_Big_Endian
then
4374 -- Here for the case of a non-default (i.e. non-confirming)
4375 -- Scalar_Storage_Order attribute definition.
4377 if Support_Nondefault_SSO_On_Target
then
4378 Set_Reverse_Storage_Order
(Base_Type
(U_Ent
), True);
4381 ("non-default Scalar_Storage_Order "
4382 & "not supported on target", Expr
);
4386 end Scalar_Storage_Order
;
4392 -- Size attribute definition clause
4394 when Attribute_Size
=> Size
: declare
4395 Size
: constant Uint
:= Static_Integer
(Expr
);
4402 if Duplicate_Clause
then
4405 elsif not Is_Type
(U_Ent
)
4406 and then Ekind
(U_Ent
) /= E_Variable
4407 and then Ekind
(U_Ent
) /= E_Constant
4409 Error_Msg_N
("size cannot be given for &", Nam
);
4411 elsif Is_Array_Type
(U_Ent
)
4412 and then not Is_Constrained
(U_Ent
)
4415 ("size cannot be given for unconstrained array", Nam
);
4417 elsif Size
/= No_Uint
then
4418 if VM_Target
/= No_VM
and then not GNAT_Mode
then
4420 -- Size clause is not handled properly on VM targets.
4421 -- Display a warning unless we are in GNAT mode, in which
4422 -- case this is useless.
4425 ("size clauses are ignored in this configuration??", N
);
4428 if Is_Type
(U_Ent
) then
4431 Etyp
:= Etype
(U_Ent
);
4434 -- Check size, note that Gigi is in charge of checking that the
4435 -- size of an array or record type is OK. Also we do not check
4436 -- the size in the ordinary fixed-point case, since it is too
4437 -- early to do so (there may be subsequent small clause that
4438 -- affects the size). We can check the size if a small clause
4439 -- has already been given.
4441 if not Is_Ordinary_Fixed_Point_Type
(U_Ent
)
4442 or else Has_Small_Clause
(U_Ent
)
4444 Check_Size
(Expr
, Etyp
, Size
, Biased
);
4445 Set_Biased
(U_Ent
, N
, "size clause", Biased
);
4448 -- For types set RM_Size and Esize if possible
4450 if Is_Type
(U_Ent
) then
4451 Set_RM_Size
(U_Ent
, Size
);
4453 -- For elementary types, increase Object_Size to power of 2,
4454 -- but not less than a storage unit in any case (normally
4455 -- this means it will be byte addressable).
4457 -- For all other types, nothing else to do, we leave Esize
4458 -- (object size) unset, the back end will set it from the
4459 -- size and alignment in an appropriate manner.
4461 -- In both cases, we check whether the alignment must be
4462 -- reset in the wake of the size change.
4464 if Is_Elementary_Type
(U_Ent
) then
4465 if Size
<= System_Storage_Unit
then
4466 Init_Esize
(U_Ent
, System_Storage_Unit
);
4467 elsif Size
<= 16 then
4468 Init_Esize
(U_Ent
, 16);
4469 elsif Size
<= 32 then
4470 Init_Esize
(U_Ent
, 32);
4472 Set_Esize
(U_Ent
, (Size
+ 63) / 64 * 64);
4475 Alignment_Check_For_Size_Change
(U_Ent
, Esize
(U_Ent
));
4477 Alignment_Check_For_Size_Change
(U_Ent
, Size
);
4480 -- For objects, set Esize only
4483 if Is_Elementary_Type
(Etyp
) then
4484 if Size
/= System_Storage_Unit
4486 Size
/= System_Storage_Unit
* 2
4488 Size
/= System_Storage_Unit
* 4
4490 Size
/= System_Storage_Unit
* 8
4492 Error_Msg_Uint_1
:= UI_From_Int
(System_Storage_Unit
);
4493 Error_Msg_Uint_2
:= Error_Msg_Uint_1
* 8;
4495 ("size for primitive object must be a power of 2"
4496 & " in the range ^-^", N
);
4500 Set_Esize
(U_Ent
, Size
);
4503 Set_Has_Size_Clause
(U_Ent
);
4511 -- Small attribute definition clause
4513 when Attribute_Small
=> Small
: declare
4514 Implicit_Base
: constant Entity_Id
:= Base_Type
(U_Ent
);
4518 Analyze_And_Resolve
(Expr
, Any_Real
);
4520 if Etype
(Expr
) = Any_Type
then
4523 elsif not Is_Static_Expression
(Expr
) then
4524 Flag_Non_Static_Expr
4525 ("small requires static expression!", Expr
);
4529 Small
:= Expr_Value_R
(Expr
);
4531 if Small
<= Ureal_0
then
4532 Error_Msg_N
("small value must be greater than zero", Expr
);
4538 if not Is_Ordinary_Fixed_Point_Type
(U_Ent
) then
4540 ("small requires an ordinary fixed point type", Nam
);
4542 elsif Has_Small_Clause
(U_Ent
) then
4543 Error_Msg_N
("small already given for &", Nam
);
4545 elsif Small
> Delta_Value
(U_Ent
) then
4547 ("small value must not be greater than delta value", Nam
);
4550 Set_Small_Value
(U_Ent
, Small
);
4551 Set_Small_Value
(Implicit_Base
, Small
);
4552 Set_Has_Small_Clause
(U_Ent
);
4553 Set_Has_Small_Clause
(Implicit_Base
);
4554 Set_Has_Non_Standard_Rep
(Implicit_Base
);
4562 -- Storage_Pool attribute definition clause
4564 when Attribute_Storage_Pool | Attribute_Simple_Storage_Pool
=> declare
4569 if Ekind
(U_Ent
) = E_Access_Subprogram_Type
then
4571 ("storage pool cannot be given for access-to-subprogram type",
4576 Ekind_In
(U_Ent
, E_Access_Type
, E_General_Access_Type
)
4579 ("storage pool can only be given for access types", Nam
);
4582 elsif Is_Derived_Type
(U_Ent
) then
4584 ("storage pool cannot be given for a derived access type",
4587 elsif Duplicate_Clause
then
4590 elsif Present
(Associated_Storage_Pool
(U_Ent
)) then
4591 Error_Msg_N
("storage pool already given for &", Nam
);
4595 if Id
= Attribute_Storage_Pool
then
4597 (Expr
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
4599 -- In the Simple_Storage_Pool case, we allow a variable of any
4600 -- simple storage pool type, so we Resolve without imposing an
4604 Analyze_And_Resolve
(Expr
);
4606 if not Present
(Get_Rep_Pragma
4607 (Etype
(Expr
), Name_Simple_Storage_Pool_Type
))
4610 ("expression must be of a simple storage pool type", Expr
);
4614 if not Denotes_Variable
(Expr
) then
4615 Error_Msg_N
("storage pool must be a variable", Expr
);
4619 if Nkind
(Expr
) = N_Type_Conversion
then
4620 T
:= Etype
(Expression
(Expr
));
4625 -- The Stack_Bounded_Pool is used internally for implementing
4626 -- access types with a Storage_Size. Since it only work properly
4627 -- when used on one specific type, we need to check that it is not
4628 -- hijacked improperly:
4630 -- type T is access Integer;
4631 -- for T'Storage_Size use n;
4632 -- type Q is access Float;
4633 -- for Q'Storage_Size use T'Storage_Size; -- incorrect
4635 if RTE_Available
(RE_Stack_Bounded_Pool
)
4636 and then Base_Type
(T
) = RTE
(RE_Stack_Bounded_Pool
)
4638 Error_Msg_N
("non-shareable internal Pool", Expr
);
4642 -- If the argument is a name that is not an entity name, then
4643 -- we construct a renaming operation to define an entity of
4644 -- type storage pool.
4646 if not Is_Entity_Name
(Expr
)
4647 and then Is_Object_Reference
(Expr
)
4649 Pool
:= Make_Temporary
(Loc
, 'P', Expr
);
4652 Rnode
: constant Node_Id
:=
4653 Make_Object_Renaming_Declaration
(Loc
,
4654 Defining_Identifier
=> Pool
,
4656 New_Occurrence_Of
(Etype
(Expr
), Loc
),
4660 -- If the attribute definition clause comes from an aspect
4661 -- clause, then insert the renaming before the associated
4662 -- entity's declaration, since the attribute clause has
4663 -- not yet been appended to the declaration list.
4665 if From_Aspect_Specification
(N
) then
4666 Insert_Before
(Parent
(Entity
(N
)), Rnode
);
4668 Insert_Before
(N
, Rnode
);
4672 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
4675 elsif Is_Entity_Name
(Expr
) then
4676 Pool
:= Entity
(Expr
);
4678 -- If pool is a renamed object, get original one. This can
4679 -- happen with an explicit renaming, and within instances.
4681 while Present
(Renamed_Object
(Pool
))
4682 and then Is_Entity_Name
(Renamed_Object
(Pool
))
4684 Pool
:= Entity
(Renamed_Object
(Pool
));
4687 if Present
(Renamed_Object
(Pool
))
4688 and then Nkind
(Renamed_Object
(Pool
)) = N_Type_Conversion
4689 and then Is_Entity_Name
(Expression
(Renamed_Object
(Pool
)))
4691 Pool
:= Entity
(Expression
(Renamed_Object
(Pool
)));
4694 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
4696 elsif Nkind
(Expr
) = N_Type_Conversion
4697 and then Is_Entity_Name
(Expression
(Expr
))
4698 and then Nkind
(Original_Node
(Expr
)) = N_Attribute_Reference
4700 Pool
:= Entity
(Expression
(Expr
));
4701 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
4704 Error_Msg_N
("incorrect reference to a Storage Pool", Expr
);
4713 -- Storage_Size attribute definition clause
4715 when Attribute_Storage_Size
=> Storage_Size
: declare
4716 Btype
: constant Entity_Id
:= Base_Type
(U_Ent
);
4719 if Is_Task_Type
(U_Ent
) then
4721 -- Check obsolescent (but never obsolescent if from aspect!)
4723 if not From_Aspect_Specification
(N
) then
4724 Check_Restriction
(No_Obsolescent_Features
, N
);
4726 if Warn_On_Obsolescent_Feature
then
4728 ("?j?storage size clause for task is an " &
4729 "obsolescent feature (RM J.9)", N
);
4730 Error_Msg_N
("\?j?use Storage_Size pragma instead", N
);
4737 if not Is_Access_Type
(U_Ent
)
4738 and then Ekind
(U_Ent
) /= E_Task_Type
4740 Error_Msg_N
("storage size cannot be given for &", Nam
);
4742 elsif Is_Access_Type
(U_Ent
) and Is_Derived_Type
(U_Ent
) then
4744 ("storage size cannot be given for a derived access type",
4747 elsif Duplicate_Clause
then
4751 Analyze_And_Resolve
(Expr
, Any_Integer
);
4753 if Is_Access_Type
(U_Ent
) then
4754 if Present
(Associated_Storage_Pool
(U_Ent
)) then
4755 Error_Msg_N
("storage pool already given for &", Nam
);
4759 if Is_OK_Static_Expression
(Expr
)
4760 and then Expr_Value
(Expr
) = 0
4762 Set_No_Pool_Assigned
(Btype
);
4766 Set_Has_Storage_Size_Clause
(Btype
);
4774 when Attribute_Stream_Size
=> Stream_Size
: declare
4775 Size
: constant Uint
:= Static_Integer
(Expr
);
4778 if Ada_Version
<= Ada_95
then
4779 Check_Restriction
(No_Implementation_Attributes
, N
);
4782 if Duplicate_Clause
then
4785 elsif Is_Elementary_Type
(U_Ent
) then
4786 if Size
/= System_Storage_Unit
4788 Size
/= System_Storage_Unit
* 2
4790 Size
/= System_Storage_Unit
* 4
4792 Size
/= System_Storage_Unit
* 8
4794 Error_Msg_Uint_1
:= UI_From_Int
(System_Storage_Unit
);
4796 ("stream size for elementary type must be a"
4797 & " power of 2 and at least ^", N
);
4799 elsif RM_Size
(U_Ent
) > Size
then
4800 Error_Msg_Uint_1
:= RM_Size
(U_Ent
);
4802 ("stream size for elementary type must be a"
4803 & " power of 2 and at least ^", N
);
4806 Set_Has_Stream_Size_Clause
(U_Ent
);
4809 Error_Msg_N
("Stream_Size cannot be given for &", Nam
);
4817 -- Value_Size attribute definition clause
4819 when Attribute_Value_Size
=> Value_Size
: declare
4820 Size
: constant Uint
:= Static_Integer
(Expr
);
4824 if not Is_Type
(U_Ent
) then
4825 Error_Msg_N
("Value_Size cannot be given for &", Nam
);
4827 elsif Duplicate_Clause
then
4830 elsif Is_Array_Type
(U_Ent
)
4831 and then not Is_Constrained
(U_Ent
)
4834 ("Value_Size cannot be given for unconstrained array", Nam
);
4837 if Is_Elementary_Type
(U_Ent
) then
4838 Check_Size
(Expr
, U_Ent
, Size
, Biased
);
4839 Set_Biased
(U_Ent
, N
, "value size clause", Biased
);
4842 Set_RM_Size
(U_Ent
, Size
);
4846 -----------------------
4847 -- Variable_Indexing --
4848 -----------------------
4850 when Attribute_Variable_Indexing
=>
4851 Check_Indexing_Functions
;
4857 when Attribute_Write
=>
4858 Analyze_Stream_TSS_Definition
(TSS_Stream_Write
);
4859 Set_Has_Specified_Stream_Write
(Ent
);
4861 -- All other attributes cannot be set
4865 ("attribute& cannot be set with definition clause", N
);
4868 -- The test for the type being frozen must be performed after any
4869 -- expression the clause has been analyzed since the expression itself
4870 -- might cause freezing that makes the clause illegal.
4872 if Rep_Item_Too_Late
(U_Ent
, N
, FOnly
) then
4875 end Analyze_Attribute_Definition_Clause
;
4877 ----------------------------
4878 -- Analyze_Code_Statement --
4879 ----------------------------
4881 procedure Analyze_Code_Statement
(N
: Node_Id
) is
4882 HSS
: constant Node_Id
:= Parent
(N
);
4883 SBody
: constant Node_Id
:= Parent
(HSS
);
4884 Subp
: constant Entity_Id
:= Current_Scope
;
4891 -- Analyze and check we get right type, note that this implements the
4892 -- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that
4893 -- is the only way that Asm_Insn could possibly be visible.
4895 Analyze_And_Resolve
(Expression
(N
));
4897 if Etype
(Expression
(N
)) = Any_Type
then
4899 elsif Etype
(Expression
(N
)) /= RTE
(RE_Asm_Insn
) then
4900 Error_Msg_N
("incorrect type for code statement", N
);
4904 Check_Code_Statement
(N
);
4906 -- Make sure we appear in the handled statement sequence of a
4907 -- subprogram (RM 13.8(3)).
4909 if Nkind
(HSS
) /= N_Handled_Sequence_Of_Statements
4910 or else Nkind
(SBody
) /= N_Subprogram_Body
4913 ("code statement can only appear in body of subprogram", N
);
4917 -- Do remaining checks (RM 13.8(3)) if not already done
4919 if not Is_Machine_Code_Subprogram
(Subp
) then
4920 Set_Is_Machine_Code_Subprogram
(Subp
);
4922 -- No exception handlers allowed
4924 if Present
(Exception_Handlers
(HSS
)) then
4926 ("exception handlers not permitted in machine code subprogram",
4927 First
(Exception_Handlers
(HSS
)));
4930 -- No declarations other than use clauses and pragmas (we allow
4931 -- certain internally generated declarations as well).
4933 Decl
:= First
(Declarations
(SBody
));
4934 while Present
(Decl
) loop
4935 DeclO
:= Original_Node
(Decl
);
4936 if Comes_From_Source
(DeclO
)
4937 and not Nkind_In
(DeclO
, N_Pragma
,
4938 N_Use_Package_Clause
,
4940 N_Implicit_Label_Declaration
)
4943 ("this declaration not allowed in machine code subprogram",
4950 -- No statements other than code statements, pragmas, and labels.
4951 -- Again we allow certain internally generated statements.
4953 -- In Ada 2012, qualified expressions are names, and the code
4954 -- statement is initially parsed as a procedure call.
4956 Stmt
:= First
(Statements
(HSS
));
4957 while Present
(Stmt
) loop
4958 StmtO
:= Original_Node
(Stmt
);
4960 -- A procedure call transformed into a code statement is OK.
4962 if Ada_Version
>= Ada_2012
4963 and then Nkind
(StmtO
) = N_Procedure_Call_Statement
4964 and then Nkind
(Name
(StmtO
)) = N_Qualified_Expression
4968 elsif Comes_From_Source
(StmtO
)
4969 and then not Nkind_In
(StmtO
, N_Pragma
,
4974 ("this statement is not allowed in machine code subprogram",
4981 end Analyze_Code_Statement
;
4983 -----------------------------------------------
4984 -- Analyze_Enumeration_Representation_Clause --
4985 -----------------------------------------------
4987 procedure Analyze_Enumeration_Representation_Clause
(N
: Node_Id
) is
4988 Ident
: constant Node_Id
:= Identifier
(N
);
4989 Aggr
: constant Node_Id
:= Array_Aggregate
(N
);
4990 Enumtype
: Entity_Id
;
4997 Err
: Boolean := False;
4998 -- Set True to avoid cascade errors and crashes on incorrect source code
5000 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Universal_Integer
));
5001 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(Universal_Integer
));
5002 -- Allowed range of universal integer (= allowed range of enum lit vals)
5006 -- Minimum and maximum values of entries
5009 -- Pointer to node for literal providing max value
5012 if Ignore_Rep_Clauses
then
5016 -- Ignore enumeration rep clauses by default in CodePeer mode,
5017 -- unless -gnatd.I is specified, as a work around for potential false
5018 -- positive messages.
5020 if CodePeer_Mode
and not Debug_Flag_Dot_II
then
5024 -- First some basic error checks
5027 Enumtype
:= Entity
(Ident
);
5029 if Enumtype
= Any_Type
5030 or else Rep_Item_Too_Early
(Enumtype
, N
)
5034 Enumtype
:= Underlying_Type
(Enumtype
);
5037 if not Is_Enumeration_Type
(Enumtype
) then
5039 ("enumeration type required, found}",
5040 Ident
, First_Subtype
(Enumtype
));
5044 -- Ignore rep clause on generic actual type. This will already have
5045 -- been flagged on the template as an error, and this is the safest
5046 -- way to ensure we don't get a junk cascaded message in the instance.
5048 if Is_Generic_Actual_Type
(Enumtype
) then
5051 -- Type must be in current scope
5053 elsif Scope
(Enumtype
) /= Current_Scope
then
5054 Error_Msg_N
("type must be declared in this scope", Ident
);
5057 -- Type must be a first subtype
5059 elsif not Is_First_Subtype
(Enumtype
) then
5060 Error_Msg_N
("cannot give enumeration rep clause for subtype", N
);
5063 -- Ignore duplicate rep clause
5065 elsif Has_Enumeration_Rep_Clause
(Enumtype
) then
5066 Error_Msg_N
("duplicate enumeration rep clause ignored", N
);
5069 -- Don't allow rep clause for standard [wide_[wide_]]character
5071 elsif Is_Standard_Character_Type
(Enumtype
) then
5072 Error_Msg_N
("enumeration rep clause not allowed for this type", N
);
5075 -- Check that the expression is a proper aggregate (no parentheses)
5077 elsif Paren_Count
(Aggr
) /= 0 then
5079 ("extra parentheses surrounding aggregate not allowed",
5083 -- All tests passed, so set rep clause in place
5086 Set_Has_Enumeration_Rep_Clause
(Enumtype
);
5087 Set_Has_Enumeration_Rep_Clause
(Base_Type
(Enumtype
));
5090 -- Now we process the aggregate. Note that we don't use the normal
5091 -- aggregate code for this purpose, because we don't want any of the
5092 -- normal expansion activities, and a number of special semantic
5093 -- rules apply (including the component type being any integer type)
5095 Elit
:= First_Literal
(Enumtype
);
5097 -- First the positional entries if any
5099 if Present
(Expressions
(Aggr
)) then
5100 Expr
:= First
(Expressions
(Aggr
));
5101 while Present
(Expr
) loop
5103 Error_Msg_N
("too many entries in aggregate", Expr
);
5107 Val
:= Static_Integer
(Expr
);
5109 -- Err signals that we found some incorrect entries processing
5110 -- the list. The final checks for completeness and ordering are
5111 -- skipped in this case.
5113 if Val
= No_Uint
then
5115 elsif Val
< Lo
or else Hi
< Val
then
5116 Error_Msg_N
("value outside permitted range", Expr
);
5120 Set_Enumeration_Rep
(Elit
, Val
);
5121 Set_Enumeration_Rep_Expr
(Elit
, Expr
);
5127 -- Now process the named entries if present
5129 if Present
(Component_Associations
(Aggr
)) then
5130 Assoc
:= First
(Component_Associations
(Aggr
));
5131 while Present
(Assoc
) loop
5132 Choice
:= First
(Choices
(Assoc
));
5134 if Present
(Next
(Choice
)) then
5136 ("multiple choice not allowed here", Next
(Choice
));
5140 if Nkind
(Choice
) = N_Others_Choice
then
5141 Error_Msg_N
("others choice not allowed here", Choice
);
5144 elsif Nkind
(Choice
) = N_Range
then
5146 -- ??? should allow zero/one element range here
5148 Error_Msg_N
("range not allowed here", Choice
);
5152 Analyze_And_Resolve
(Choice
, Enumtype
);
5154 if Error_Posted
(Choice
) then
5159 if Is_Entity_Name
(Choice
)
5160 and then Is_Type
(Entity
(Choice
))
5162 Error_Msg_N
("subtype name not allowed here", Choice
);
5165 -- ??? should allow static subtype with zero/one entry
5167 elsif Etype
(Choice
) = Base_Type
(Enumtype
) then
5168 if not Is_Static_Expression
(Choice
) then
5169 Flag_Non_Static_Expr
5170 ("non-static expression used for choice!", Choice
);
5174 Elit
:= Expr_Value_E
(Choice
);
5176 if Present
(Enumeration_Rep_Expr
(Elit
)) then
5178 Sloc
(Enumeration_Rep_Expr
(Elit
));
5180 ("representation for& previously given#",
5185 Set_Enumeration_Rep_Expr
(Elit
, Expression
(Assoc
));
5187 Expr
:= Expression
(Assoc
);
5188 Val
:= Static_Integer
(Expr
);
5190 if Val
= No_Uint
then
5193 elsif Val
< Lo
or else Hi
< Val
then
5194 Error_Msg_N
("value outside permitted range", Expr
);
5198 Set_Enumeration_Rep
(Elit
, Val
);
5208 -- Aggregate is fully processed. Now we check that a full set of
5209 -- representations was given, and that they are in range and in order.
5210 -- These checks are only done if no other errors occurred.
5216 Elit
:= First_Literal
(Enumtype
);
5217 while Present
(Elit
) loop
5218 if No
(Enumeration_Rep_Expr
(Elit
)) then
5219 Error_Msg_NE
("missing representation for&!", N
, Elit
);
5222 Val
:= Enumeration_Rep
(Elit
);
5224 if Min
= No_Uint
then
5228 if Val
/= No_Uint
then
5229 if Max
/= No_Uint
and then Val
<= Max
then
5231 ("enumeration value for& not ordered!",
5232 Enumeration_Rep_Expr
(Elit
), Elit
);
5235 Max_Node
:= Enumeration_Rep_Expr
(Elit
);
5239 -- If there is at least one literal whose representation is not
5240 -- equal to the Pos value, then note that this enumeration type
5241 -- has a non-standard representation.
5243 if Val
/= Enumeration_Pos
(Elit
) then
5244 Set_Has_Non_Standard_Rep
(Base_Type
(Enumtype
));
5251 -- Now set proper size information
5254 Minsize
: Uint
:= UI_From_Int
(Minimum_Size
(Enumtype
));
5257 if Has_Size_Clause
(Enumtype
) then
5259 -- All OK, if size is OK now
5261 if RM_Size
(Enumtype
) >= Minsize
then
5265 -- Try if we can get by with biasing
5268 UI_From_Int
(Minimum_Size
(Enumtype
, Biased
=> True));
5270 -- Error message if even biasing does not work
5272 if RM_Size
(Enumtype
) < Minsize
then
5273 Error_Msg_Uint_1
:= RM_Size
(Enumtype
);
5274 Error_Msg_Uint_2
:= Max
;
5276 ("previously given size (^) is too small "
5277 & "for this value (^)", Max_Node
);
5279 -- If biasing worked, indicate that we now have biased rep
5283 (Enumtype
, Size_Clause
(Enumtype
), "size clause");
5288 Set_RM_Size
(Enumtype
, Minsize
);
5289 Set_Enum_Esize
(Enumtype
);
5292 Set_RM_Size
(Base_Type
(Enumtype
), RM_Size
(Enumtype
));
5293 Set_Esize
(Base_Type
(Enumtype
), Esize
(Enumtype
));
5294 Set_Alignment
(Base_Type
(Enumtype
), Alignment
(Enumtype
));
5298 -- We repeat the too late test in case it froze itself!
5300 if Rep_Item_Too_Late
(Enumtype
, N
) then
5303 end Analyze_Enumeration_Representation_Clause
;
5305 ----------------------------
5306 -- Analyze_Free_Statement --
5307 ----------------------------
5309 procedure Analyze_Free_Statement
(N
: Node_Id
) is
5311 Analyze
(Expression
(N
));
5312 end Analyze_Free_Statement
;
5314 ---------------------------
5315 -- Analyze_Freeze_Entity --
5316 ---------------------------
5318 procedure Analyze_Freeze_Entity
(N
: Node_Id
) is
5320 Freeze_Entity_Checks
(N
);
5321 end Analyze_Freeze_Entity
;
5323 -----------------------------------
5324 -- Analyze_Freeze_Generic_Entity --
5325 -----------------------------------
5327 procedure Analyze_Freeze_Generic_Entity
(N
: Node_Id
) is
5329 Freeze_Entity_Checks
(N
);
5330 end Analyze_Freeze_Generic_Entity
;
5332 ------------------------------------------
5333 -- Analyze_Record_Representation_Clause --
5334 ------------------------------------------
5336 -- Note: we check as much as we can here, but we can't do any checks
5337 -- based on the position values (e.g. overlap checks) until freeze time
5338 -- because especially in Ada 2005 (machine scalar mode), the processing
5339 -- for non-standard bit order can substantially change the positions.
5340 -- See procedure Check_Record_Representation_Clause (called from Freeze)
5341 -- for the remainder of this processing.
5343 procedure Analyze_Record_Representation_Clause
(N
: Node_Id
) is
5344 Ident
: constant Node_Id
:= Identifier
(N
);
5349 Hbit
: Uint
:= Uint_0
;
5353 Rectype
: Entity_Id
;
5356 function Is_Inherited
(Comp
: Entity_Id
) return Boolean;
5357 -- True if Comp is an inherited component in a record extension
5363 function Is_Inherited
(Comp
: Entity_Id
) return Boolean is
5364 Comp_Base
: Entity_Id
;
5367 if Ekind
(Rectype
) = E_Record_Subtype
then
5368 Comp_Base
:= Original_Record_Component
(Comp
);
5373 return Comp_Base
/= Original_Record_Component
(Comp_Base
);
5378 Is_Record_Extension
: Boolean;
5379 -- True if Rectype is a record extension
5381 CR_Pragma
: Node_Id
:= Empty
;
5382 -- Points to N_Pragma node if Complete_Representation pragma present
5384 -- Start of processing for Analyze_Record_Representation_Clause
5387 if Ignore_Rep_Clauses
then
5392 Rectype
:= Entity
(Ident
);
5394 if Rectype
= Any_Type
or else Rep_Item_Too_Early
(Rectype
, N
) then
5397 Rectype
:= Underlying_Type
(Rectype
);
5400 -- First some basic error checks
5402 if not Is_Record_Type
(Rectype
) then
5404 ("record type required, found}", Ident
, First_Subtype
(Rectype
));
5407 elsif Scope
(Rectype
) /= Current_Scope
then
5408 Error_Msg_N
("type must be declared in this scope", N
);
5411 elsif not Is_First_Subtype
(Rectype
) then
5412 Error_Msg_N
("cannot give record rep clause for subtype", N
);
5415 elsif Has_Record_Rep_Clause
(Rectype
) then
5416 Error_Msg_N
("duplicate record rep clause ignored", N
);
5419 elsif Rep_Item_Too_Late
(Rectype
, N
) then
5423 -- We know we have a first subtype, now possibly go the the anonymous
5424 -- base type to determine whether Rectype is a record extension.
5426 Recdef
:= Type_Definition
(Declaration_Node
(Base_Type
(Rectype
)));
5427 Is_Record_Extension
:=
5428 Nkind
(Recdef
) = N_Derived_Type_Definition
5429 and then Present
(Record_Extension_Part
(Recdef
));
5431 if Present
(Mod_Clause
(N
)) then
5433 Loc
: constant Source_Ptr
:= Sloc
(N
);
5434 M
: constant Node_Id
:= Mod_Clause
(N
);
5435 P
: constant List_Id
:= Pragmas_Before
(M
);
5439 pragma Warnings
(Off
, Mod_Val
);
5442 Check_Restriction
(No_Obsolescent_Features
, Mod_Clause
(N
));
5444 if Warn_On_Obsolescent_Feature
then
5446 ("?j?mod clause is an obsolescent feature (RM J.8)", N
);
5448 ("\?j?use alignment attribute definition clause instead", N
);
5455 -- In ASIS_Mode mode, expansion is disabled, but we must convert
5456 -- the Mod clause into an alignment clause anyway, so that the
5457 -- back-end can compute and back-annotate properly the size and
5458 -- alignment of types that may include this record.
5460 -- This seems dubious, this destroys the source tree in a manner
5461 -- not detectable by ASIS ???
5463 if Operating_Mode
= Check_Semantics
and then ASIS_Mode
then
5465 Make_Attribute_Definition_Clause
(Loc
,
5466 Name
=> New_Reference_To
(Base_Type
(Rectype
), Loc
),
5467 Chars
=> Name_Alignment
,
5468 Expression
=> Relocate_Node
(Expression
(M
)));
5470 Set_From_At_Mod
(AtM_Nod
);
5471 Insert_After
(N
, AtM_Nod
);
5472 Mod_Val
:= Get_Alignment_Value
(Expression
(AtM_Nod
));
5473 Set_Mod_Clause
(N
, Empty
);
5476 -- Get the alignment value to perform error checking
5478 Mod_Val
:= Get_Alignment_Value
(Expression
(M
));
5483 -- For untagged types, clear any existing component clauses for the
5484 -- type. If the type is derived, this is what allows us to override
5485 -- a rep clause for the parent. For type extensions, the representation
5486 -- of the inherited components is inherited, so we want to keep previous
5487 -- component clauses for completeness.
5489 if not Is_Tagged_Type
(Rectype
) then
5490 Comp
:= First_Component_Or_Discriminant
(Rectype
);
5491 while Present
(Comp
) loop
5492 Set_Component_Clause
(Comp
, Empty
);
5493 Next_Component_Or_Discriminant
(Comp
);
5497 -- All done if no component clauses
5499 CC
:= First
(Component_Clauses
(N
));
5505 -- A representation like this applies to the base type
5507 Set_Has_Record_Rep_Clause
(Base_Type
(Rectype
));
5508 Set_Has_Non_Standard_Rep
(Base_Type
(Rectype
));
5509 Set_Has_Specified_Layout
(Base_Type
(Rectype
));
5511 -- Process the component clauses
5513 while Present
(CC
) loop
5517 if Nkind
(CC
) = N_Pragma
then
5520 -- The only pragma of interest is Complete_Representation
5522 if Pragma_Name
(CC
) = Name_Complete_Representation
then
5526 -- Processing for real component clause
5529 Posit
:= Static_Integer
(Position
(CC
));
5530 Fbit
:= Static_Integer
(First_Bit
(CC
));
5531 Lbit
:= Static_Integer
(Last_Bit
(CC
));
5534 and then Fbit
/= No_Uint
5535 and then Lbit
/= No_Uint
5539 ("position cannot be negative", Position
(CC
));
5543 ("first bit cannot be negative", First_Bit
(CC
));
5545 -- The Last_Bit specified in a component clause must not be
5546 -- less than the First_Bit minus one (RM-13.5.1(10)).
5548 elsif Lbit
< Fbit
- 1 then
5550 ("last bit cannot be less than first bit minus one",
5553 -- Values look OK, so find the corresponding record component
5554 -- Even though the syntax allows an attribute reference for
5555 -- implementation-defined components, GNAT does not allow the
5556 -- tag to get an explicit position.
5558 elsif Nkind
(Component_Name
(CC
)) = N_Attribute_Reference
then
5559 if Attribute_Name
(Component_Name
(CC
)) = Name_Tag
then
5560 Error_Msg_N
("position of tag cannot be specified", CC
);
5562 Error_Msg_N
("illegal component name", CC
);
5566 Comp
:= First_Entity
(Rectype
);
5567 while Present
(Comp
) loop
5568 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
5574 -- Maybe component of base type that is absent from
5575 -- statically constrained first subtype.
5577 Comp
:= First_Entity
(Base_Type
(Rectype
));
5578 while Present
(Comp
) loop
5579 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
5586 ("component clause is for non-existent field", CC
);
5588 -- Ada 2012 (AI05-0026): Any name that denotes a
5589 -- discriminant of an object of an unchecked union type
5590 -- shall not occur within a record_representation_clause.
5592 -- The general restriction of using record rep clauses on
5593 -- Unchecked_Union types has now been lifted. Since it is
5594 -- possible to introduce a record rep clause which mentions
5595 -- the discriminant of an Unchecked_Union in non-Ada 2012
5596 -- code, this check is applied to all versions of the
5599 elsif Ekind
(Comp
) = E_Discriminant
5600 and then Is_Unchecked_Union
(Rectype
)
5603 ("cannot reference discriminant of unchecked union",
5604 Component_Name
(CC
));
5606 elsif Is_Record_Extension
and then Is_Inherited
(Comp
) then
5608 ("component clause not allowed for inherited "
5609 & "component&", CC
, Comp
);
5611 elsif Present
(Component_Clause
(Comp
)) then
5613 -- Diagnose duplicate rep clause, or check consistency
5614 -- if this is an inherited component. In a double fault,
5615 -- there may be a duplicate inconsistent clause for an
5616 -- inherited component.
5618 if Scope
(Original_Record_Component
(Comp
)) = Rectype
5619 or else Parent
(Component_Clause
(Comp
)) = N
5621 Error_Msg_Sloc
:= Sloc
(Component_Clause
(Comp
));
5622 Error_Msg_N
("component clause previously given#", CC
);
5626 Rep1
: constant Node_Id
:= Component_Clause
(Comp
);
5628 if Intval
(Position
(Rep1
)) /=
5629 Intval
(Position
(CC
))
5630 or else Intval
(First_Bit
(Rep1
)) /=
5631 Intval
(First_Bit
(CC
))
5632 or else Intval
(Last_Bit
(Rep1
)) /=
5633 Intval
(Last_Bit
(CC
))
5636 ("component clause inconsistent "
5637 & "with representation of ancestor", CC
);
5639 elsif Warn_On_Redundant_Constructs
then
5641 ("?r?redundant confirming component clause "
5642 & "for component!", CC
);
5647 -- Normal case where this is the first component clause we
5648 -- have seen for this entity, so set it up properly.
5651 -- Make reference for field in record rep clause and set
5652 -- appropriate entity field in the field identifier.
5655 (Comp
, Component_Name
(CC
), Set_Ref
=> False);
5656 Set_Entity
(Component_Name
(CC
), Comp
);
5658 -- Update Fbit and Lbit to the actual bit number
5660 Fbit
:= Fbit
+ UI_From_Int
(SSU
) * Posit
;
5661 Lbit
:= Lbit
+ UI_From_Int
(SSU
) * Posit
;
5663 if Has_Size_Clause
(Rectype
)
5664 and then RM_Size
(Rectype
) <= Lbit
5667 ("bit number out of range of specified size",
5670 Set_Component_Clause
(Comp
, CC
);
5671 Set_Component_Bit_Offset
(Comp
, Fbit
);
5672 Set_Esize
(Comp
, 1 + (Lbit
- Fbit
));
5673 Set_Normalized_First_Bit
(Comp
, Fbit
mod SSU
);
5674 Set_Normalized_Position
(Comp
, Fbit
/ SSU
);
5676 if Warn_On_Overridden_Size
5677 and then Has_Size_Clause
(Etype
(Comp
))
5678 and then RM_Size
(Etype
(Comp
)) /= Esize
(Comp
)
5681 ("?S?component size overrides size clause for&",
5682 Component_Name
(CC
), Etype
(Comp
));
5685 -- This information is also set in the corresponding
5686 -- component of the base type, found by accessing the
5687 -- Original_Record_Component link if it is present.
5689 Ocomp
:= Original_Record_Component
(Comp
);
5696 (Component_Name
(CC
),
5702 (Comp
, First_Node
(CC
), "component clause", Biased
);
5704 if Present
(Ocomp
) then
5705 Set_Component_Clause
(Ocomp
, CC
);
5706 Set_Component_Bit_Offset
(Ocomp
, Fbit
);
5707 Set_Normalized_First_Bit
(Ocomp
, Fbit
mod SSU
);
5708 Set_Normalized_Position
(Ocomp
, Fbit
/ SSU
);
5709 Set_Esize
(Ocomp
, 1 + (Lbit
- Fbit
));
5711 Set_Normalized_Position_Max
5712 (Ocomp
, Normalized_Position
(Ocomp
));
5714 -- Note: we don't use Set_Biased here, because we
5715 -- already gave a warning above if needed, and we
5716 -- would get a duplicate for the same name here.
5718 Set_Has_Biased_Representation
5719 (Ocomp
, Has_Biased_Representation
(Comp
));
5722 if Esize
(Comp
) < 0 then
5723 Error_Msg_N
("component size is negative", CC
);
5734 -- Check missing components if Complete_Representation pragma appeared
5736 if Present
(CR_Pragma
) then
5737 Comp
:= First_Component_Or_Discriminant
(Rectype
);
5738 while Present
(Comp
) loop
5739 if No
(Component_Clause
(Comp
)) then
5741 ("missing component clause for &", CR_Pragma
, Comp
);
5744 Next_Component_Or_Discriminant
(Comp
);
5747 -- Give missing components warning if required
5749 elsif Warn_On_Unrepped_Components
then
5751 Num_Repped_Components
: Nat
:= 0;
5752 Num_Unrepped_Components
: Nat
:= 0;
5755 -- First count number of repped and unrepped components
5757 Comp
:= First_Component_Or_Discriminant
(Rectype
);
5758 while Present
(Comp
) loop
5759 if Present
(Component_Clause
(Comp
)) then
5760 Num_Repped_Components
:= Num_Repped_Components
+ 1;
5762 Num_Unrepped_Components
:= Num_Unrepped_Components
+ 1;
5765 Next_Component_Or_Discriminant
(Comp
);
5768 -- We are only interested in the case where there is at least one
5769 -- unrepped component, and at least half the components have rep
5770 -- clauses. We figure that if less than half have them, then the
5771 -- partial rep clause is really intentional. If the component
5772 -- type has no underlying type set at this point (as for a generic
5773 -- formal type), we don't know enough to give a warning on the
5776 if Num_Unrepped_Components
> 0
5777 and then Num_Unrepped_Components
< Num_Repped_Components
5779 Comp
:= First_Component_Or_Discriminant
(Rectype
);
5780 while Present
(Comp
) loop
5781 if No
(Component_Clause
(Comp
))
5782 and then Comes_From_Source
(Comp
)
5783 and then Present
(Underlying_Type
(Etype
(Comp
)))
5784 and then (Is_Scalar_Type
(Underlying_Type
(Etype
(Comp
)))
5785 or else Size_Known_At_Compile_Time
5786 (Underlying_Type
(Etype
(Comp
))))
5787 and then not Has_Warnings_Off
(Rectype
)
5789 Error_Msg_Sloc
:= Sloc
(Comp
);
5791 ("?C?no component clause given for & declared #",
5795 Next_Component_Or_Discriminant
(Comp
);
5800 end Analyze_Record_Representation_Clause
;
5802 -------------------------------------------
5803 -- Build_Invariant_Procedure_Declaration --
5804 -------------------------------------------
5806 function Build_Invariant_Procedure_Declaration
5807 (Typ
: Entity_Id
) return Node_Id
5809 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
5810 Object_Entity
: constant Entity_Id
:=
5811 Make_Defining_Identifier
(Loc
, New_Internal_Name
('I'));
5816 Set_Etype
(Object_Entity
, Typ
);
5818 -- Check for duplicate definiations.
5820 if Has_Invariants
(Typ
) and then Present
(Invariant_Procedure
(Typ
)) then
5825 Make_Defining_Identifier
(Loc
,
5826 Chars
=> New_External_Name
(Chars
(Typ
), "Invariant"));
5827 Set_Has_Invariants
(Typ
);
5828 Set_Ekind
(SId
, E_Procedure
);
5829 Set_Is_Invariant_Procedure
(SId
);
5830 Set_Invariant_Procedure
(Typ
, SId
);
5833 Make_Procedure_Specification
(Loc
,
5834 Defining_Unit_Name
=> SId
,
5835 Parameter_Specifications
=> New_List
(
5836 Make_Parameter_Specification
(Loc
,
5837 Defining_Identifier
=> Object_Entity
,
5838 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))));
5840 return Make_Subprogram_Declaration
(Loc
, Specification
=> Spec
);
5841 end Build_Invariant_Procedure_Declaration
;
5843 -------------------------------
5844 -- Build_Invariant_Procedure --
5845 -------------------------------
5847 -- The procedure that is constructed here has the form
5849 -- procedure typInvariant (Ixxx : typ) is
5851 -- pragma Check (Invariant, exp, "failed invariant from xxx");
5852 -- pragma Check (Invariant, exp, "failed invariant from xxx");
5854 -- pragma Check (Invariant, exp, "failed inherited invariant from xxx");
5856 -- end typInvariant;
5858 procedure Build_Invariant_Procedure
(Typ
: Entity_Id
; N
: Node_Id
) is
5859 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
5866 Visible_Decls
: constant List_Id
:= Visible_Declarations
(N
);
5867 Private_Decls
: constant List_Id
:= Private_Declarations
(N
);
5869 procedure Add_Invariants
(T
: Entity_Id
; Inherit
: Boolean);
5870 -- Appends statements to Stmts for any invariants in the rep item chain
5871 -- of the given type. If Inherit is False, then we only process entries
5872 -- on the chain for the type Typ. If Inherit is True, then we ignore any
5873 -- Invariant aspects, but we process all Invariant'Class aspects, adding
5874 -- "inherited" to the exception message and generating an informational
5875 -- message about the inheritance of an invariant.
5877 Object_Name
: Name_Id
;
5878 -- Name for argument of invariant procedure
5880 Object_Entity
: Node_Id
;
5881 -- The entity of the formal for the procedure
5883 --------------------
5884 -- Add_Invariants --
5885 --------------------
5887 procedure Add_Invariants
(T
: Entity_Id
; Inherit
: Boolean) is
5897 procedure Replace_Type_Reference
(N
: Node_Id
);
5898 -- Replace a single occurrence N of the subtype name with a reference
5899 -- to the formal of the predicate function. N can be an identifier
5900 -- referencing the subtype, or a selected component, representing an
5901 -- appropriately qualified occurrence of the subtype name.
5903 procedure Replace_Type_References
is
5904 new Replace_Type_References_Generic
(Replace_Type_Reference
);
5905 -- Traverse an expression replacing all occurrences of the subtype
5906 -- name with appropriate references to the object that is the formal
5907 -- parameter of the predicate function. Note that we must ensure
5908 -- that the type and entity information is properly set in the
5909 -- replacement node, since we will do a Preanalyze call of this
5910 -- expression without proper visibility of the procedure argument.
5912 ----------------------------
5913 -- Replace_Type_Reference --
5914 ----------------------------
5916 -- Note: See comments in Add_Predicates.Replace_Type_Reference
5917 -- regarding handling of Sloc and Comes_From_Source.
5919 procedure Replace_Type_Reference
(N
: Node_Id
) is
5921 -- Invariant'Class, replace with T'Class (obj)
5923 if Class_Present
(Ritem
) then
5925 Make_Type_Conversion
(Sloc
(N
),
5927 Make_Attribute_Reference
(Sloc
(N
),
5928 Prefix
=> New_Occurrence_Of
(T
, Sloc
(N
)),
5929 Attribute_Name
=> Name_Class
),
5930 Expression
=> Make_Identifier
(Sloc
(N
), Object_Name
)));
5932 Set_Entity
(Expression
(N
), Object_Entity
);
5933 Set_Etype
(Expression
(N
), Typ
);
5935 -- Invariant, replace with obj
5938 Rewrite
(N
, Make_Identifier
(Sloc
(N
), Object_Name
));
5939 Set_Entity
(N
, Object_Entity
);
5943 Set_Comes_From_Source
(N
, True);
5944 end Replace_Type_Reference
;
5946 -- Start of processing for Add_Invariants
5949 Ritem
:= First_Rep_Item
(T
);
5950 while Present
(Ritem
) loop
5951 if Nkind
(Ritem
) = N_Pragma
5952 and then Pragma_Name
(Ritem
) = Name_Invariant
5954 Arg1
:= First
(Pragma_Argument_Associations
(Ritem
));
5955 Arg2
:= Next
(Arg1
);
5956 Arg3
:= Next
(Arg2
);
5958 Arg1
:= Get_Pragma_Arg
(Arg1
);
5959 Arg2
:= Get_Pragma_Arg
(Arg2
);
5961 -- For Inherit case, ignore Invariant, process only Class case
5964 if not Class_Present
(Ritem
) then
5968 -- For Inherit false, process only item for right type
5971 if Entity
(Arg1
) /= Typ
then
5977 Stmts
:= Empty_List
;
5980 Exp
:= New_Copy_Tree
(Arg2
);
5982 -- Preserve sloc of original pragma Invariant
5984 Loc
:= Sloc
(Ritem
);
5986 -- We need to replace any occurrences of the name of the type
5987 -- with references to the object, converted to type'Class in
5988 -- the case of Invariant'Class aspects.
5990 Replace_Type_References
(Exp
, Chars
(T
));
5992 -- If this invariant comes from an aspect, find the aspect
5993 -- specification, and replace the saved expression because
5994 -- we need the subtype references replaced for the calls to
5995 -- Preanalyze_Spec_Expressin in Check_Aspect_At_Freeze_Point
5996 -- and Check_Aspect_At_End_Of_Declarations.
5998 if From_Aspect_Specification
(Ritem
) then
6003 -- Loop to find corresponding aspect, note that this
6004 -- must be present given the pragma is marked delayed.
6006 Aitem
:= Next_Rep_Item
(Ritem
);
6007 while Present
(Aitem
) loop
6008 if Nkind
(Aitem
) = N_Aspect_Specification
6009 and then Aspect_Rep_Item
(Aitem
) = Ritem
6012 (Identifier
(Aitem
), New_Copy_Tree
(Exp
));
6016 Aitem
:= Next_Rep_Item
(Aitem
);
6021 -- Now we need to preanalyze the expression to properly capture
6022 -- the visibility in the visible part. The expression will not
6023 -- be analyzed for real until the body is analyzed, but that is
6024 -- at the end of the private part and has the wrong visibility.
6026 Set_Parent
(Exp
, N
);
6027 Preanalyze_Assert_Expression
(Exp
, Standard_Boolean
);
6029 -- Build first two arguments for Check pragma
6032 Make_Pragma_Argument_Association
(Loc
,
6033 Expression
=> Make_Identifier
(Loc
, Name_Invariant
)),
6034 Make_Pragma_Argument_Association
(Loc
,
6035 Expression
=> Exp
));
6037 -- Add message if present in Invariant pragma
6039 if Present
(Arg3
) then
6040 Str
:= Strval
(Get_Pragma_Arg
(Arg3
));
6042 -- If inherited case, and message starts "failed invariant",
6043 -- change it to be "failed inherited invariant".
6046 String_To_Name_Buffer
(Str
);
6048 if Name_Buffer
(1 .. 16) = "failed invariant" then
6049 Insert_Str_In_Name_Buffer
("inherited ", 8);
6050 Str
:= String_From_Name_Buffer
;
6055 Make_Pragma_Argument_Association
(Loc
,
6056 Expression
=> Make_String_Literal
(Loc
, Str
)));
6059 -- Add Check pragma to list of statements
6063 Pragma_Identifier
=>
6064 Make_Identifier
(Loc
, Name_Check
),
6065 Pragma_Argument_Associations
=> Assoc
));
6067 -- If Inherited case and option enabled, output info msg. Note
6068 -- that we know this is a case of Invariant'Class.
6070 if Inherit
and Opt
.List_Inherited_Aspects
then
6071 Error_Msg_Sloc
:= Sloc
(Ritem
);
6073 ("?L?info: & inherits `Invariant''Class` aspect from #",
6079 Next_Rep_Item
(Ritem
);
6083 -- Start of processing for Build_Invariant_Procedure
6091 -- If the aspect specification exists for some view of the type, the
6092 -- declaration for the procedure has been created.
6094 if Has_Invariants
(Typ
) then
6095 SId
:= Invariant_Procedure
(Typ
);
6098 if Present
(SId
) then
6099 PDecl
:= Unit_Declaration_Node
(SId
);
6101 PDecl
:= Build_Invariant_Procedure_Declaration
(Typ
);
6104 -- Recover formal of procedure, for use in the calls to invariant
6105 -- functions (including inherited ones).
6109 (First
(Parameter_Specifications
(Specification
(PDecl
))));
6110 Object_Name
:= Chars
(Object_Entity
);
6112 -- Add invariants for the current type
6114 Add_Invariants
(Typ
, Inherit
=> False);
6116 -- Add invariants for parent types
6119 Current_Typ
: Entity_Id
;
6120 Parent_Typ
: Entity_Id
;
6125 Parent_Typ
:= Etype
(Current_Typ
);
6127 if Is_Private_Type
(Parent_Typ
)
6128 and then Present
(Full_View
(Base_Type
(Parent_Typ
)))
6130 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
6133 exit when Parent_Typ
= Current_Typ
;
6135 Current_Typ
:= Parent_Typ
;
6136 Add_Invariants
(Current_Typ
, Inherit
=> True);
6140 -- Build the procedure if we generated at least one Check pragma
6142 if Stmts
/= No_List
then
6143 Spec
:= Copy_Separate_Tree
(Specification
(PDecl
));
6146 Make_Subprogram_Body
(Loc
,
6147 Specification
=> Spec
,
6148 Declarations
=> Empty_List
,
6149 Handled_Statement_Sequence
=>
6150 Make_Handled_Sequence_Of_Statements
(Loc
,
6151 Statements
=> Stmts
));
6153 -- Insert procedure declaration and spec at the appropriate points.
6154 -- If declaration is already analyzed, it was processed by the
6155 -- generated pragma.
6157 if Present
(Private_Decls
) then
6159 -- The spec goes at the end of visible declarations, but they have
6160 -- already been analyzed, so we need to explicitly do the analyze.
6162 if not Analyzed
(PDecl
) then
6163 Append_To
(Visible_Decls
, PDecl
);
6167 -- The body goes at the end of the private declarations, which we
6168 -- have not analyzed yet, so we do not need to perform an explicit
6169 -- analyze call. We skip this if there are no private declarations
6170 -- (this is an error that will be caught elsewhere);
6172 Append_To
(Private_Decls
, PBody
);
6174 -- If the invariant appears on the full view of a type, the
6175 -- analysis of the private part is complete, and we must
6176 -- analyze the new body explicitly.
6178 if In_Private_Part
(Current_Scope
) then
6182 -- If there are no private declarations this may be an error that
6183 -- will be diagnosed elsewhere. However, if this is a non-private
6184 -- type that inherits invariants, it needs no completion and there
6185 -- may be no private part. In this case insert invariant procedure
6186 -- at end of current declarative list, and analyze at once, given
6187 -- that the type is about to be frozen.
6189 elsif not Is_Private_Type
(Typ
) then
6190 Append_To
(Visible_Decls
, PDecl
);
6191 Append_To
(Visible_Decls
, PBody
);
6196 end Build_Invariant_Procedure
;
6198 -------------------------------
6199 -- Build_Predicate_Functions --
6200 -------------------------------
6202 -- The procedures that are constructed here have the form:
6204 -- function typPredicate (Ixxx : typ) return Boolean is
6207 -- exp1 and then exp2 and then ...
6208 -- and then typ1Predicate (typ1 (Ixxx))
6209 -- and then typ2Predicate (typ2 (Ixxx))
6211 -- end typPredicate;
6213 -- Here exp1, and exp2 are expressions from Predicate pragmas. Note that
6214 -- this is the point at which these expressions get analyzed, providing the
6215 -- required delay, and typ1, typ2, are entities from which predicates are
6216 -- inherited. Note that we do NOT generate Check pragmas, that's because we
6217 -- use this function even if checks are off, e.g. for membership tests.
6219 -- If the expression has at least one Raise_Expression, then we also build
6220 -- the typPredicateM version of the function, in which any occurrence of a
6221 -- Raise_Expression is converted to "return False".
6223 procedure Build_Predicate_Functions
(Typ
: Entity_Id
; N
: Node_Id
) is
6224 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
6227 -- This is the expression for the result of the function. It is
6228 -- is build by connecting the component predicates with AND THEN.
6231 -- This is the corresponding return expression for the Predicate_M
6232 -- function. It differs in that raise expressions are marked for
6233 -- special expansion (see Process_REs).
6235 Object_Name
: constant Name_Id
:= New_Internal_Name
('I');
6236 -- Name for argument of Predicate procedure. Note that we use the same
6237 -- name for both predicate procedure. That way the reference within the
6238 -- predicate expression is the same in both functions.
6240 Object_Entity
: constant Entity_Id
:=
6241 Make_Defining_Identifier
(Loc
, Chars
=> Object_Name
);
6242 -- Entity for argument of Predicate procedure
6244 Object_Entity_M
: constant Entity_Id
:=
6245 Make_Defining_Identifier
(Loc
, Chars
=> Object_Name
);
6246 -- Entity for argument of Predicate_M procedure
6248 Raise_Expression_Present
: Boolean := False;
6249 -- Set True if Expr has at least one Raise_Expression
6251 Static_Predic
: Node_Id
:= Empty
;
6252 -- Set to N_Pragma node for a static predicate if one is encountered
6254 procedure Add_Call
(T
: Entity_Id
);
6255 -- Includes a call to the predicate function for type T in Expr if T
6256 -- has predicates and Predicate_Function (T) is non-empty.
6258 procedure Add_Predicates
;
6259 -- Appends expressions for any Predicate pragmas in the rep item chain
6260 -- Typ to Expr. Note that we look only at items for this exact entity.
6261 -- Inheritance of predicates for the parent type is done by calling the
6262 -- Predicate_Function of the parent type, using Add_Call above.
6264 function Test_RE
(N
: Node_Id
) return Traverse_Result
;
6265 -- Used in Test_REs, tests one node for being a raise expression, and if
6266 -- so sets Raise_Expression_Present True.
6268 procedure Test_REs
is new Traverse_Proc
(Test_RE
);
6269 -- Tests to see if Expr contains any raise expressions
6271 function Process_RE
(N
: Node_Id
) return Traverse_Result
;
6272 -- Used in Process REs, tests if node N is a raise expression, and if
6273 -- so, marks it to be converted to return False.
6275 procedure Process_REs
is new Traverse_Proc
(Process_RE
);
6276 -- Marks any raise expressions in Expr_M to return False
6282 procedure Add_Call
(T
: Entity_Id
) is
6286 if Present
(T
) and then Present
(Predicate_Function
(T
)) then
6287 Set_Has_Predicates
(Typ
);
6289 -- Build the call to the predicate function of T
6293 (T
, Convert_To
(T
, Make_Identifier
(Loc
, Object_Name
)));
6295 -- Add call to evolving expression, using AND THEN if needed
6302 Left_Opnd
=> Relocate_Node
(Expr
),
6306 -- Output info message on inheritance if required. Note we do not
6307 -- give this information for generic actual types, since it is
6308 -- unwelcome noise in that case in instantiations. We also
6309 -- generally suppress the message in instantiations, and also
6310 -- if it involves internal names.
6312 if Opt
.List_Inherited_Aspects
6313 and then not Is_Generic_Actual_Type
(Typ
)
6314 and then Instantiation_Depth
(Sloc
(Typ
)) = 0
6315 and then not Is_Internal_Name
(Chars
(T
))
6316 and then not Is_Internal_Name
(Chars
(Typ
))
6318 Error_Msg_Sloc
:= Sloc
(Predicate_Function
(T
));
6319 Error_Msg_Node_2
:= T
;
6320 Error_Msg_N
("info: & inherits predicate from & #?L?", Typ
);
6325 --------------------
6326 -- Add_Predicates --
6327 --------------------
6329 procedure Add_Predicates
is
6334 procedure Replace_Type_Reference
(N
: Node_Id
);
6335 -- Replace a single occurrence N of the subtype name with a reference
6336 -- to the formal of the predicate function. N can be an identifier
6337 -- referencing the subtype, or a selected component, representing an
6338 -- appropriately qualified occurrence of the subtype name.
6340 procedure Replace_Type_References
is
6341 new Replace_Type_References_Generic
(Replace_Type_Reference
);
6342 -- Traverse an expression changing every occurrence of an identifier
6343 -- whose name matches the name of the subtype with a reference to
6344 -- the formal parameter of the predicate function.
6346 ----------------------------
6347 -- Replace_Type_Reference --
6348 ----------------------------
6350 procedure Replace_Type_Reference
(N
: Node_Id
) is
6352 Rewrite
(N
, Make_Identifier
(Sloc
(N
), Object_Name
));
6353 -- Use the Sloc of the usage name, not the defining name
6356 Set_Entity
(N
, Object_Entity
);
6358 -- We want to treat the node as if it comes from source, so that
6359 -- ASIS will not ignore it
6361 Set_Comes_From_Source
(N
, True);
6362 end Replace_Type_Reference
;
6364 -- Start of processing for Add_Predicates
6367 Ritem
:= First_Rep_Item
(Typ
);
6368 while Present
(Ritem
) loop
6369 if Nkind
(Ritem
) = N_Pragma
6370 and then Pragma_Name
(Ritem
) = Name_Predicate
6372 -- Save the static predicate of the type for diagnostics and
6373 -- error reporting purposes.
6375 if Present
(Corresponding_Aspect
(Ritem
))
6376 and then Chars
(Identifier
(Corresponding_Aspect
(Ritem
))) =
6377 Name_Static_Predicate
6379 Static_Predic
:= Ritem
;
6382 -- Acquire arguments
6384 Arg1
:= First
(Pragma_Argument_Associations
(Ritem
));
6385 Arg2
:= Next
(Arg1
);
6387 Arg1
:= Get_Pragma_Arg
(Arg1
);
6388 Arg2
:= Get_Pragma_Arg
(Arg2
);
6390 -- See if this predicate pragma is for the current type or for
6391 -- its full view. A predicate on a private completion is placed
6392 -- on the partial view beause this is the visible entity that
6395 if Entity
(Arg1
) = Typ
6396 or else Full_View
(Entity
(Arg1
)) = Typ
6398 -- We have a match, this entry is for our subtype
6400 -- We need to replace any occurrences of the name of the
6401 -- type with references to the object.
6403 Replace_Type_References
(Arg2
, Chars
(Typ
));
6405 -- If this predicate comes from an aspect, find the aspect
6406 -- specification, and replace the saved expression because
6407 -- we need the subtype references replaced for the calls to
6408 -- Preanalyze_Spec_Expressin in Check_Aspect_At_Freeze_Point
6409 -- and Check_Aspect_At_End_Of_Declarations.
6411 if From_Aspect_Specification
(Ritem
) then
6416 -- Loop to find corresponding aspect, note that this
6417 -- must be present given the pragma is marked delayed.
6419 Aitem
:= Next_Rep_Item
(Ritem
);
6421 if Nkind
(Aitem
) = N_Aspect_Specification
6422 and then Aspect_Rep_Item
(Aitem
) = Ritem
6425 (Identifier
(Aitem
), New_Copy_Tree
(Arg2
));
6429 Aitem
:= Next_Rep_Item
(Aitem
);
6434 -- Now we can add the expression
6437 Expr
:= Relocate_Node
(Arg2
);
6439 -- There already was a predicate, so add to it
6444 Left_Opnd
=> Relocate_Node
(Expr
),
6445 Right_Opnd
=> Relocate_Node
(Arg2
));
6450 Next_Rep_Item
(Ritem
);
6458 function Process_RE
(N
: Node_Id
) return Traverse_Result
is
6460 if Nkind
(N
) = N_Raise_Expression
then
6461 Set_Convert_To_Return_False
(N
);
6472 function Test_RE
(N
: Node_Id
) return Traverse_Result
is
6474 if Nkind
(N
) = N_Raise_Expression
then
6475 Raise_Expression_Present
:= True;
6482 -- Start of processing for Build_Predicate_Functions
6485 -- Return if already built or if type does not have predicates
6487 if not Has_Predicates
(Typ
)
6488 or else Present
(Predicate_Function
(Typ
))
6493 -- Prepare to construct predicate expression
6497 -- Add Predicates for the current type
6501 -- Add predicates for ancestor if present
6504 Atyp
: constant Entity_Id
:= Nearest_Ancestor
(Typ
);
6506 if Present
(Atyp
) then
6511 -- Case where predicates are present
6513 if Present
(Expr
) then
6515 -- Test for raise expression present
6519 -- If raise expression is present, capture a copy of Expr for use
6520 -- in building the predicateM function version later on. For this
6521 -- copy we replace references to Object_Entity by Object_Entity_M.
6523 if Raise_Expression_Present
then
6525 Map
: constant Elist_Id
:= New_Elmt_List
;
6527 Append_Elmt
(Object_Entity
, Map
);
6528 Append_Elmt
(Object_Entity_M
, Map
);
6529 Expr_M
:= New_Copy_Tree
(Expr
, Map
=> Map
);
6533 -- Build the main predicate function
6536 SId
: constant Entity_Id
:=
6537 Make_Defining_Identifier
(Loc
,
6538 Chars
=> New_External_Name
(Chars
(Typ
), "Predicate"));
6539 -- The entity for the the function spec
6541 SIdB
: constant Entity_Id
:=
6542 Make_Defining_Identifier
(Loc
,
6543 Chars
=> New_External_Name
(Chars
(Typ
), "Predicate"));
6544 -- The entity for the function body
6551 -- Build function declaration
6553 Set_Ekind
(SId
, E_Function
);
6554 Set_Is_Predicate_Function
(SId
);
6555 Set_Predicate_Function
(Typ
, SId
);
6557 -- The predicate function is shared between views of a type
6559 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
6560 Set_Predicate_Function
(Full_View
(Typ
), SId
);
6564 Make_Function_Specification
(Loc
,
6565 Defining_Unit_Name
=> SId
,
6566 Parameter_Specifications
=> New_List
(
6567 Make_Parameter_Specification
(Loc
,
6568 Defining_Identifier
=> Object_Entity
,
6569 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))),
6570 Result_Definition
=>
6571 New_Occurrence_Of
(Standard_Boolean
, Loc
));
6574 Make_Subprogram_Declaration
(Loc
,
6575 Specification
=> Spec
);
6577 -- Build function body
6580 Make_Function_Specification
(Loc
,
6581 Defining_Unit_Name
=> SIdB
,
6582 Parameter_Specifications
=> New_List
(
6583 Make_Parameter_Specification
(Loc
,
6584 Defining_Identifier
=>
6585 Make_Defining_Identifier
(Loc
, Object_Name
),
6587 New_Occurrence_Of
(Typ
, Loc
))),
6588 Result_Definition
=>
6589 New_Occurrence_Of
(Standard_Boolean
, Loc
));
6592 Make_Subprogram_Body
(Loc
,
6593 Specification
=> Spec
,
6594 Declarations
=> Empty_List
,
6595 Handled_Statement_Sequence
=>
6596 Make_Handled_Sequence_Of_Statements
(Loc
,
6597 Statements
=> New_List
(
6598 Make_Simple_Return_Statement
(Loc
,
6599 Expression
=> Expr
))));
6601 -- Insert declaration before freeze node and body after
6603 Insert_Before_And_Analyze
(N
, FDecl
);
6604 Insert_After_And_Analyze
(N
, FBody
);
6607 -- Test for raise expressions present and if so build M version
6609 if Raise_Expression_Present
then
6611 SId
: constant Entity_Id
:=
6612 Make_Defining_Identifier
(Loc
,
6613 Chars
=> New_External_Name
(Chars
(Typ
), "PredicateM"));
6614 -- The entity for the the function spec
6616 SIdB
: constant Entity_Id
:=
6617 Make_Defining_Identifier
(Loc
,
6618 Chars
=> New_External_Name
(Chars
(Typ
), "PredicateM"));
6619 -- The entity for the function body
6627 -- Mark any raise expressions for special expansion
6629 Process_REs
(Expr_M
);
6631 -- Build function declaration
6633 Set_Ekind
(SId
, E_Function
);
6634 Set_Is_Predicate_Function_M
(SId
);
6635 Set_Predicate_Function_M
(Typ
, SId
);
6637 -- The predicate function is shared between views of a type
6639 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
6640 Set_Predicate_Function_M
(Full_View
(Typ
), SId
);
6644 Make_Function_Specification
(Loc
,
6645 Defining_Unit_Name
=> SId
,
6646 Parameter_Specifications
=> New_List
(
6647 Make_Parameter_Specification
(Loc
,
6648 Defining_Identifier
=> Object_Entity_M
,
6649 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))),
6650 Result_Definition
=>
6651 New_Occurrence_Of
(Standard_Boolean
, Loc
));
6654 Make_Subprogram_Declaration
(Loc
,
6655 Specification
=> Spec
);
6657 -- Build function body
6660 Make_Function_Specification
(Loc
,
6661 Defining_Unit_Name
=> SIdB
,
6662 Parameter_Specifications
=> New_List
(
6663 Make_Parameter_Specification
(Loc
,
6664 Defining_Identifier
=>
6665 Make_Defining_Identifier
(Loc
, Object_Name
),
6667 New_Occurrence_Of
(Typ
, Loc
))),
6668 Result_Definition
=>
6669 New_Occurrence_Of
(Standard_Boolean
, Loc
));
6671 -- Build the body, we declare the boolean expression before
6672 -- doing the return, because we are not really confident of
6673 -- what happens if a return appears within a return!
6676 Make_Defining_Identifier
(Loc
,
6677 Chars
=> New_Internal_Name
('B'));
6680 Make_Subprogram_Body
(Loc
,
6681 Specification
=> Spec
,
6683 Declarations
=> New_List
(
6684 Make_Object_Declaration
(Loc
,
6685 Defining_Identifier
=> BTemp
,
6686 Constant_Present
=> True,
6687 Object_Definition
=>
6688 New_Reference_To
(Standard_Boolean
, Loc
),
6689 Expression
=> Expr_M
)),
6691 Handled_Statement_Sequence
=>
6692 Make_Handled_Sequence_Of_Statements
(Loc
,
6693 Statements
=> New_List
(
6694 Make_Simple_Return_Statement
(Loc
,
6695 Expression
=> New_Reference_To
(BTemp
, Loc
)))));
6697 -- Insert declaration before freeze node and body after
6699 Insert_Before_And_Analyze
(N
, FDecl
);
6700 Insert_After_And_Analyze
(N
, FBody
);
6704 if Is_Scalar_Type
(Typ
) then
6706 -- Attempt to build a static predicate for a discrete or a real
6707 -- subtype. This action may fail because the actual expression may
6708 -- not be static. Note that the presence of an inherited or
6709 -- explicitly declared dynamic predicate is orthogonal to this
6710 -- check because we are only interested in the static predicate.
6712 if Ekind_In
(Typ
, E_Decimal_Fixed_Point_Subtype
,
6713 E_Enumeration_Subtype
,
6714 E_Floating_Point_Subtype
,
6715 E_Modular_Integer_Subtype
,
6716 E_Ordinary_Fixed_Point_Subtype
,
6717 E_Signed_Integer_Subtype
)
6719 Build_Static_Predicate
(Typ
, Expr
, Object_Name
);
6721 -- Emit an error when the predicate is categorized as static
6722 -- but its expression is dynamic.
6724 if Present
(Static_Predic
)
6725 and then No
(Static_Predicate
(Typ
))
6728 ("expression does not have required form for "
6729 & "static predicate",
6730 Next
(First
(Pragma_Argument_Associations
6735 -- If a static predicate applies on other types, that's an error:
6736 -- either the type is scalar but non-static, or it's not even a
6737 -- scalar type. We do not issue an error on generated types, as
6738 -- these may be duplicates of the same error on a source type.
6740 elsif Present
(Static_Predic
) and then Comes_From_Source
(Typ
) then
6741 if Is_Scalar_Type
(Typ
) then
6743 ("static predicate not allowed for non-static type&",
6747 ("static predicate not allowed for non-scalar type&",
6752 end Build_Predicate_Functions
;
6754 ----------------------------
6755 -- Build_Static_Predicate --
6756 ----------------------------
6758 procedure Build_Static_Predicate
6763 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
6765 Non_Static
: exception;
6766 -- Raised if something non-static is found
6768 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
6770 BLo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Btyp
));
6771 BHi
: constant Uint
:= Expr_Value
(Type_High_Bound
(Btyp
));
6772 -- Low bound and high bound value of base type of Typ
6774 TLo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Typ
));
6775 THi
: constant Uint
:= Expr_Value
(Type_High_Bound
(Typ
));
6776 -- Low bound and high bound values of static subtype Typ
6781 -- One entry in a Rlist value, a single REnt (range entry) value denotes
6782 -- one range from Lo to Hi. To represent a single value range Lo = Hi =
6785 type RList
is array (Nat
range <>) of REnt
;
6786 -- A list of ranges. The ranges are sorted in increasing order, and are
6787 -- disjoint (there is a gap of at least one value between each range in
6788 -- the table). A value is in the set of ranges in Rlist if it lies
6789 -- within one of these ranges.
6791 False_Range
: constant RList
:=
6792 RList
'(1 .. 0 => REnt'(No_Uint
, No_Uint
));
6793 -- An empty set of ranges represents a range list that can never be
6794 -- satisfied, since there are no ranges in which the value could lie,
6795 -- so it does not lie in any of them. False_Range is a canonical value
6796 -- for this empty set, but general processing should test for an Rlist
6797 -- with length zero (see Is_False predicate), since other null ranges
6798 -- may appear which must be treated as False.
6800 True_Range
: constant RList
:= RList
'(1 => REnt'(BLo
, BHi
));
6801 -- Range representing True, value must be in the base range
6803 function "and" (Left
: RList
; Right
: RList
) return RList
;
6804 -- And's together two range lists, returning a range list. This is a set
6805 -- intersection operation.
6807 function "or" (Left
: RList
; Right
: RList
) return RList
;
6808 -- Or's together two range lists, returning a range list. This is a set
6811 function "not" (Right
: RList
) return RList
;
6812 -- Returns complement of a given range list, i.e. a range list
6813 -- representing all the values in TLo .. THi that are not in the input
6816 function Build_Val
(V
: Uint
) return Node_Id
;
6817 -- Return an analyzed N_Identifier node referencing this value, suitable
6818 -- for use as an entry in the Static_Predicate list. This node is typed
6819 -- with the base type.
6821 function Build_Range
(Lo
: Uint
; Hi
: Uint
) return Node_Id
;
6822 -- Return an analyzed N_Range node referencing this range, suitable for
6823 -- use as an entry in the Static_Predicate list. This node is typed with
6826 function Get_RList
(Exp
: Node_Id
) return RList
;
6827 -- This is a recursive routine that converts the given expression into a
6828 -- list of ranges, suitable for use in building the static predicate.
6830 function Is_False
(R
: RList
) return Boolean;
6831 pragma Inline
(Is_False
);
6832 -- Returns True if the given range list is empty, and thus represents a
6833 -- False list of ranges that can never be satisfied.
6835 function Is_True
(R
: RList
) return Boolean;
6836 -- Returns True if R trivially represents the True predicate by having a
6837 -- single range from BLo to BHi.
6839 function Is_Type_Ref
(N
: Node_Id
) return Boolean;
6840 pragma Inline
(Is_Type_Ref
);
6841 -- Returns if True if N is a reference to the type for the predicate in
6842 -- the expression (i.e. if it is an identifier whose Chars field matches
6843 -- the Nam given in the call).
6845 function Lo_Val
(N
: Node_Id
) return Uint
;
6846 -- Given static expression or static range from a Static_Predicate list,
6847 -- gets expression value or low bound of range.
6849 function Hi_Val
(N
: Node_Id
) return Uint
;
6850 -- Given static expression or static range from a Static_Predicate list,
6851 -- gets expression value of high bound of range.
6853 function Membership_Entry
(N
: Node_Id
) return RList
;
6854 -- Given a single membership entry (range, value, or subtype), returns
6855 -- the corresponding range list. Raises Static_Error if not static.
6857 function Membership_Entries
(N
: Node_Id
) return RList
;
6858 -- Given an element on an alternatives list of a membership operation,
6859 -- returns the range list corresponding to this entry and all following
6860 -- entries (i.e. returns the "or" of this list of values).
6862 function Stat_Pred
(Typ
: Entity_Id
) return RList
;
6863 -- Given a type, if it has a static predicate, then return the predicate
6864 -- as a range list, otherwise raise Non_Static.
6870 function "and" (Left
: RList
; Right
: RList
) return RList
is
6872 -- First range of result
6874 SLeft
: Nat
:= Left
'First;
6875 -- Start of rest of left entries
6877 SRight
: Nat
:= Right
'First;
6878 -- Start of rest of right entries
6881 -- If either range is True, return the other
6883 if Is_True
(Left
) then
6885 elsif Is_True
(Right
) then
6889 -- If either range is False, return False
6891 if Is_False
(Left
) or else Is_False
(Right
) then
6895 -- Loop to remove entries at start that are disjoint, and thus just
6896 -- get discarded from the result entirely.
6899 -- If no operands left in either operand, result is false
6901 if SLeft
> Left
'Last or else SRight
> Right
'Last then
6904 -- Discard first left operand entry if disjoint with right
6906 elsif Left
(SLeft
).Hi
< Right
(SRight
).Lo
then
6909 -- Discard first right operand entry if disjoint with left
6911 elsif Right
(SRight
).Hi
< Left
(SLeft
).Lo
then
6912 SRight
:= SRight
+ 1;
6914 -- Otherwise we have an overlapping entry
6921 -- Now we have two non-null operands, and first entries overlap. The
6922 -- first entry in the result will be the overlapping part of these
6925 FEnt
:= REnt
'(Lo => UI_Max (Left (SLeft).Lo, Right (SRight).Lo),
6926 Hi => UI_Min (Left (SLeft).Hi, Right (SRight).Hi));
6928 -- Now we can remove the entry that ended at a lower value, since its
6929 -- contribution is entirely contained in Fent.
6931 if Left (SLeft).Hi <= Right (SRight).Hi then
6934 SRight := SRight + 1;
6937 -- Compute result by concatenating this first entry with the "and" of
6938 -- the remaining parts of the left and right operands. Note that if
6939 -- either of these is empty, "and" will yield empty, so that we will
6940 -- end up with just Fent, which is what we want in that case.
6943 FEnt & (Left (SLeft .. Left'Last) and Right (SRight .. Right'Last));
6950 function "not" (Right : RList) return RList is
6952 -- Return True if False range
6954 if Is_False (Right) then
6958 -- Return False if True range
6960 if Is_True (Right) then
6964 -- Here if not trivial case
6967 Result : RList (1 .. Right'Length + 1);
6968 -- May need one more entry for gap at beginning and end
6971 -- Number of entries stored in Result
6976 if Right (Right'First).Lo > TLo then
6978 Result (Count) := REnt'(TLo
, Right
(Right
'First).Lo
- 1);
6981 -- Gaps between ranges
6983 for J
in Right
'First .. Right
'Last - 1 loop
6986 REnt
'(Right (J).Hi + 1, Right (J + 1).Lo - 1);
6991 if Right (Right'Last).Hi < THi then
6993 Result (Count) := REnt'(Right
(Right
'Last).Hi
+ 1, THi
);
6996 return Result
(1 .. Count
);
7004 function "or" (Left
: RList
; Right
: RList
) return RList
is
7006 -- First range of result
7008 SLeft
: Nat
:= Left
'First;
7009 -- Start of rest of left entries
7011 SRight
: Nat
:= Right
'First;
7012 -- Start of rest of right entries
7015 -- If either range is True, return True
7017 if Is_True
(Left
) or else Is_True
(Right
) then
7021 -- If either range is False (empty), return the other
7023 if Is_False
(Left
) then
7025 elsif Is_False
(Right
) then
7029 -- Initialize result first entry from left or right operand depending
7030 -- on which starts with the lower range.
7032 if Left
(SLeft
).Lo
< Right
(SRight
).Lo
then
7033 FEnt
:= Left
(SLeft
);
7036 FEnt
:= Right
(SRight
);
7037 SRight
:= SRight
+ 1;
7040 -- This loop eats ranges from left and right operands that are
7041 -- contiguous with the first range we are gathering.
7044 -- Eat first entry in left operand if contiguous or overlapped by
7045 -- gathered first operand of result.
7047 if SLeft
<= Left
'Last
7048 and then Left
(SLeft
).Lo
<= FEnt
.Hi
+ 1
7050 FEnt
.Hi
:= UI_Max
(FEnt
.Hi
, Left
(SLeft
).Hi
);
7053 -- Eat first entry in right operand if contiguous or overlapped by
7054 -- gathered right operand of result.
7056 elsif SRight
<= Right
'Last
7057 and then Right
(SRight
).Lo
<= FEnt
.Hi
+ 1
7059 FEnt
.Hi
:= UI_Max
(FEnt
.Hi
, Right
(SRight
).Hi
);
7060 SRight
:= SRight
+ 1;
7062 -- All done if no more entries to eat
7069 -- Obtain result as the first entry we just computed, concatenated
7070 -- to the "or" of the remaining results (if one operand is empty,
7071 -- this will just concatenate with the other
7074 FEnt
& (Left
(SLeft
.. Left
'Last) or Right
(SRight
.. Right
'Last));
7081 function Build_Range
(Lo
: Uint
; Hi
: Uint
) return Node_Id
is
7087 Low_Bound
=> Build_Val
(Lo
),
7088 High_Bound
=> Build_Val
(Hi
));
7089 Set_Etype
(Result
, Btyp
);
7090 Set_Analyzed
(Result
);
7099 function Build_Val
(V
: Uint
) return Node_Id
is
7103 if Is_Enumeration_Type
(Typ
) then
7104 Result
:= Get_Enum_Lit_From_Pos
(Typ
, V
, Loc
);
7106 Result
:= Make_Integer_Literal
(Loc
, V
);
7109 Set_Etype
(Result
, Btyp
);
7110 Set_Is_Static_Expression
(Result
);
7111 Set_Analyzed
(Result
);
7119 function Get_RList
(Exp
: Node_Id
) return RList
is
7124 -- Static expression can only be true or false
7126 if Is_OK_Static_Expression
(Exp
) then
7130 if Expr_Value
(Exp
) = 0 then
7137 -- Otherwise test node type
7145 when N_Op_And | N_And_Then
=>
7146 return Get_RList
(Left_Opnd
(Exp
))
7148 Get_RList
(Right_Opnd
(Exp
));
7152 when N_Op_Or | N_Or_Else
=>
7153 return Get_RList
(Left_Opnd
(Exp
))
7155 Get_RList
(Right_Opnd
(Exp
));
7160 return not Get_RList
(Right_Opnd
(Exp
));
7162 -- Comparisons of type with static value
7164 when N_Op_Compare
=>
7166 -- Type is left operand
7168 if Is_Type_Ref
(Left_Opnd
(Exp
))
7169 and then Is_OK_Static_Expression
(Right_Opnd
(Exp
))
7171 Val
:= Expr_Value
(Right_Opnd
(Exp
));
7173 -- Typ is right operand
7175 elsif Is_Type_Ref
(Right_Opnd
(Exp
))
7176 and then Is_OK_Static_Expression
(Left_Opnd
(Exp
))
7178 Val
:= Expr_Value
(Left_Opnd
(Exp
));
7180 -- Invert sense of comparison
7183 when N_Op_Gt
=> Op
:= N_Op_Lt
;
7184 when N_Op_Lt
=> Op
:= N_Op_Gt
;
7185 when N_Op_Ge
=> Op
:= N_Op_Le
;
7186 when N_Op_Le
=> Op
:= N_Op_Ge
;
7187 when others => null;
7190 -- Other cases are non-static
7196 -- Construct range according to comparison operation
7200 return RList
'(1 => REnt'(Val
, Val
));
7203 return RList
'(1 => REnt'(Val
, BHi
));
7206 return RList
'(1 => REnt'(Val
+ 1, BHi
));
7209 return RList
'(1 => REnt'(BLo
, Val
));
7212 return RList
'(1 => REnt'(BLo
, Val
- 1));
7215 return RList
'(REnt'(BLo
, Val
- 1),
7216 REnt
'(Val + 1, BHi));
7219 raise Program_Error;
7225 if not Is_Type_Ref (Left_Opnd (Exp)) then
7229 if Present (Right_Opnd (Exp)) then
7230 return Membership_Entry (Right_Opnd (Exp));
7232 return Membership_Entries (First (Alternatives (Exp)));
7235 -- Negative membership (NOT IN)
7238 if not Is_Type_Ref (Left_Opnd (Exp)) then
7242 if Present (Right_Opnd (Exp)) then
7243 return not Membership_Entry (Right_Opnd (Exp));
7245 return not Membership_Entries (First (Alternatives (Exp)));
7248 -- Function call, may be call to static predicate
7250 when N_Function_Call =>
7251 if Is_Entity_Name (Name (Exp)) then
7253 Ent : constant Entity_Id := Entity (Name (Exp));
7255 if Is_Predicate_Function (Ent)
7257 Is_Predicate_Function_M (Ent)
7259 return Stat_Pred (Etype (First_Formal (Ent)));
7264 -- Other function call cases are non-static
7268 -- Qualified expression, dig out the expression
7270 when N_Qualified_Expression =>
7271 return Get_RList (Expression (Exp));
7273 -- Expression with actions: if no actions, dig out expression
7275 when N_Expression_With_Actions =>
7276 if Is_Empty_List (Actions (Exp)) then
7277 return Get_RList (Expression (Exp));
7286 return (Get_RList (Left_Opnd (Exp))
7287 and not Get_RList (Right_Opnd (Exp)))
7288 or (Get_RList (Right_Opnd (Exp))
7289 and not Get_RList (Left_Opnd (Exp)));
7291 -- Any other node type is non-static
7302 function Hi_Val (N : Node_Id) return Uint is
7304 if Is_Static_Expression (N) then
7305 return Expr_Value (N);
7307 pragma Assert (Nkind (N) = N_Range);
7308 return Expr_Value (High_Bound (N));
7316 function Is_False (R : RList) return Boolean is
7318 return R'Length = 0;
7325 function Is_True (R : RList) return Boolean is
7328 and then R (R'First).Lo = BLo
7329 and then R (R'First).Hi = BHi;
7336 function Is_Type_Ref (N : Node_Id) return Boolean is
7338 return Nkind (N) = N_Identifier and then Chars (N) = Nam;
7345 function Lo_Val (N : Node_Id) return Uint is
7347 if Is_Static_Expression (N) then
7348 return Expr_Value (N);
7350 pragma Assert (Nkind (N) = N_Range);
7351 return Expr_Value (Low_Bound (N));
7355 ------------------------
7356 -- Membership_Entries --
7357 ------------------------
7359 function Membership_Entries (N : Node_Id) return RList is
7361 if No (Next (N)) then
7362 return Membership_Entry (N);
7364 return Membership_Entry (N) or Membership_Entries (Next (N));
7366 end Membership_Entries;
7368 ----------------------
7369 -- Membership_Entry --
7370 ----------------------
7372 function Membership_Entry (N : Node_Id) return RList is
7380 if Nkind (N) = N_Range then
7381 if not Is_Static_Expression (Low_Bound (N))
7383 not Is_Static_Expression (High_Bound (N))
7387 SLo := Expr_Value (Low_Bound (N));
7388 SHi := Expr_Value (High_Bound (N));
7389 return RList'(1 => REnt
'(SLo, SHi));
7392 -- Static expression case
7394 elsif Is_Static_Expression (N) then
7395 Val := Expr_Value (N);
7396 return RList'(1 => REnt
'(Val, Val));
7398 -- Identifier (other than static expression) case
7400 else pragma Assert (Nkind (N) = N_Identifier);
7404 if Is_Type (Entity (N)) then
7406 -- If type has predicates, process them
7408 if Has_Predicates (Entity (N)) then
7409 return Stat_Pred (Entity (N));
7411 -- For static subtype without predicates, get range
7413 elsif Is_Static_Subtype (Entity (N)) then
7414 SLo := Expr_Value (Type_Low_Bound (Entity (N)));
7415 SHi := Expr_Value (Type_High_Bound (Entity (N)));
7416 return RList'(1 => REnt
'(SLo, SHi));
7418 -- Any other type makes us non-static
7424 -- Any other kind of identifier in predicate (e.g. a non-static
7425 -- expression value) means this is not a static predicate.
7431 end Membership_Entry;
7437 function Stat_Pred (Typ : Entity_Id) return RList is
7439 -- Not static if type does not have static predicates
7441 if not Has_Predicates (Typ) or else No (Static_Predicate (Typ)) then
7445 -- Otherwise we convert the predicate list to a range list
7448 Result : RList (1 .. List_Length (Static_Predicate (Typ)));
7452 P := First (Static_Predicate (Typ));
7453 for J in Result'Range loop
7454 Result (J) := REnt'(Lo_Val
(P
), Hi_Val
(P
));
7462 -- Start of processing for Build_Static_Predicate
7465 -- Now analyze the expression to see if it is a static predicate
7468 Ranges
: constant RList
:= Get_RList
(Expr
);
7469 -- Range list from expression if it is static
7474 -- Convert range list into a form for the static predicate. In the
7475 -- Ranges array, we just have raw ranges, these must be converted
7476 -- to properly typed and analyzed static expressions or range nodes.
7478 -- Note: here we limit ranges to the ranges of the subtype, so that
7479 -- a predicate is always false for values outside the subtype. That
7480 -- seems fine, such values are invalid anyway, and considering them
7481 -- to fail the predicate seems allowed and friendly, and furthermore
7482 -- simplifies processing for case statements and loops.
7486 for J
in Ranges
'Range loop
7488 Lo
: Uint
:= Ranges
(J
).Lo
;
7489 Hi
: Uint
:= Ranges
(J
).Hi
;
7492 -- Ignore completely out of range entry
7494 if Hi
< TLo
or else Lo
> THi
then
7497 -- Otherwise process entry
7500 -- Adjust out of range value to subtype range
7510 -- Convert range into required form
7512 Append_To
(Plist
, Build_Range
(Lo
, Hi
));
7517 -- Processing was successful and all entries were static, so now we
7518 -- can store the result as the predicate list.
7520 Set_Static_Predicate
(Typ
, Plist
);
7522 -- The processing for static predicates put the expression into
7523 -- canonical form as a series of ranges. It also eliminated
7524 -- duplicates and collapsed and combined ranges. We might as well
7525 -- replace the alternatives list of the right operand of the
7526 -- membership test with the static predicate list, which will
7527 -- usually be more efficient.
7530 New_Alts
: constant List_Id
:= New_List
;
7535 Old_Node
:= First
(Plist
);
7536 while Present
(Old_Node
) loop
7537 New_Node
:= New_Copy
(Old_Node
);
7539 if Nkind
(New_Node
) = N_Range
then
7540 Set_Low_Bound
(New_Node
, New_Copy
(Low_Bound
(Old_Node
)));
7541 Set_High_Bound
(New_Node
, New_Copy
(High_Bound
(Old_Node
)));
7544 Append_To
(New_Alts
, New_Node
);
7548 -- If empty list, replace by False
7550 if Is_Empty_List
(New_Alts
) then
7551 Rewrite
(Expr
, New_Occurrence_Of
(Standard_False
, Loc
));
7553 -- Else replace by set membership test
7558 Left_Opnd
=> Make_Identifier
(Loc
, Nam
),
7559 Right_Opnd
=> Empty
,
7560 Alternatives
=> New_Alts
));
7562 -- Resolve new expression in function context
7564 Install_Formals
(Predicate_Function
(Typ
));
7565 Push_Scope
(Predicate_Function
(Typ
));
7566 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
7572 -- If non-static, return doing nothing
7577 end Build_Static_Predicate
;
7579 -----------------------------------------
7580 -- Check_Aspect_At_End_Of_Declarations --
7581 -----------------------------------------
7583 procedure Check_Aspect_At_End_Of_Declarations
(ASN
: Node_Id
) is
7584 Ent
: constant Entity_Id
:= Entity
(ASN
);
7585 Ident
: constant Node_Id
:= Identifier
(ASN
);
7586 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Chars
(Ident
));
7588 End_Decl_Expr
: constant Node_Id
:= Entity
(Ident
);
7589 -- Expression to be analyzed at end of declarations
7591 Freeze_Expr
: constant Node_Id
:= Expression
(ASN
);
7592 -- Expression from call to Check_Aspect_At_Freeze_Point
7594 T
: constant Entity_Id
:= Etype
(Freeze_Expr
);
7595 -- Type required for preanalyze call
7598 -- Set False if error
7600 -- On entry to this procedure, Entity (Ident) contains a copy of the
7601 -- original expression from the aspect, saved for this purpose, and
7602 -- but Expression (Ident) is a preanalyzed copy of the expression,
7603 -- preanalyzed just after the freeze point.
7605 procedure Check_Overloaded_Name
;
7606 -- For aspects whose expression is simply a name, this routine checks if
7607 -- the name is overloaded or not. If so, it verifies there is an
7608 -- interpretation that matches the entity obtained at the freeze point,
7609 -- otherwise the compiler complains.
7611 ---------------------------
7612 -- Check_Overloaded_Name --
7613 ---------------------------
7615 procedure Check_Overloaded_Name
is
7617 if not Is_Overloaded
(End_Decl_Expr
) then
7618 Err
:= Entity
(End_Decl_Expr
) /= Entity
(Freeze_Expr
);
7624 Index
: Interp_Index
;
7628 Get_First_Interp
(End_Decl_Expr
, Index
, It
);
7629 while Present
(It
.Typ
) loop
7630 if It
.Nam
= Entity
(Freeze_Expr
) then
7635 Get_Next_Interp
(Index
, It
);
7639 end Check_Overloaded_Name
;
7641 -- Start of processing for Check_Aspect_At_End_Of_Declarations
7644 -- Case of aspects Dimension, Dimension_System and Synchronization
7646 if A_Id
= Aspect_Synchronization
then
7649 -- Case of stream attributes, just have to compare entities. However,
7650 -- the expression is just a name (possibly overloaded), and there may
7651 -- be stream operations declared for unrelated types, so we just need
7652 -- to verify that one of these interpretations is the one available at
7653 -- at the freeze point.
7655 elsif A_Id
= Aspect_Input
or else
7656 A_Id
= Aspect_Output
or else
7657 A_Id
= Aspect_Read
or else
7660 Analyze
(End_Decl_Expr
);
7661 Check_Overloaded_Name
;
7663 elsif A_Id
= Aspect_Variable_Indexing
or else
7664 A_Id
= Aspect_Constant_Indexing
or else
7665 A_Id
= Aspect_Default_Iterator
or else
7666 A_Id
= Aspect_Iterator_Element
7668 -- Make type unfrozen before analysis, to prevent spurious errors
7669 -- about late attributes.
7671 Set_Is_Frozen
(Ent
, False);
7672 Analyze
(End_Decl_Expr
);
7673 Set_Is_Frozen
(Ent
, True);
7675 -- If the end of declarations comes before any other freeze
7676 -- point, the Freeze_Expr is not analyzed: no check needed.
7678 if Analyzed
(Freeze_Expr
) and then not In_Instance
then
7679 Check_Overloaded_Name
;
7687 -- In a generic context the aspect expressions have not been
7688 -- preanalyzed, so do it now. There are no conformance checks
7689 -- to perform in this case.
7692 Check_Aspect_At_Freeze_Point
(ASN
);
7695 -- The default values attributes may be defined in the private part,
7696 -- and the analysis of the expression may take place when only the
7697 -- partial view is visible. The expression must be scalar, so use
7698 -- the full view to resolve.
7700 elsif (A_Id
= Aspect_Default_Value
7702 A_Id
= Aspect_Default_Component_Value
)
7703 and then Is_Private_Type
(T
)
7705 Preanalyze_Spec_Expression
(End_Decl_Expr
, Full_View
(T
));
7707 Preanalyze_Spec_Expression
(End_Decl_Expr
, T
);
7710 Err
:= not Fully_Conformant_Expressions
(End_Decl_Expr
, Freeze_Expr
);
7713 -- Output error message if error
7717 ("visibility of aspect for& changes after freeze point",
7720 ("info: & is frozen here, aspects evaluated at this point??",
7721 Freeze_Node
(Ent
), Ent
);
7723 end Check_Aspect_At_End_Of_Declarations
;
7725 ----------------------------------
7726 -- Check_Aspect_At_Freeze_Point --
7727 ----------------------------------
7729 procedure Check_Aspect_At_Freeze_Point
(ASN
: Node_Id
) is
7730 Ident
: constant Node_Id
:= Identifier
(ASN
);
7731 -- Identifier (use Entity field to save expression)
7733 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Chars
(Ident
));
7735 T
: Entity_Id
:= Empty
;
7736 -- Type required for preanalyze call
7739 -- On entry to this procedure, Entity (Ident) contains a copy of the
7740 -- original expression from the aspect, saved for this purpose.
7742 -- On exit from this procedure Entity (Ident) is unchanged, still
7743 -- containing that copy, but Expression (Ident) is a preanalyzed copy
7744 -- of the expression, preanalyzed just after the freeze point.
7746 -- Make a copy of the expression to be preanalyzed
7748 Set_Expression
(ASN
, New_Copy_Tree
(Entity
(Ident
)));
7750 -- Find type for preanalyze call
7754 -- No_Aspect should be impossible
7757 raise Program_Error
;
7759 -- Aspects taking an optional boolean argument
7761 when Boolean_Aspects |
7762 Library_Unit_Aspects
=>
7764 T
:= Standard_Boolean
;
7766 -- Aspects corresponding to attribute definition clauses
7768 when Aspect_Address
=>
7769 T
:= RTE
(RE_Address
);
7771 when Aspect_Attach_Handler
=>
7772 T
:= RTE
(RE_Interrupt_ID
);
7774 when Aspect_Bit_Order | Aspect_Scalar_Storage_Order
=>
7775 T
:= RTE
(RE_Bit_Order
);
7777 when Aspect_Convention
=>
7781 T
:= RTE
(RE_CPU_Range
);
7783 -- Default_Component_Value is resolved with the component type
7785 when Aspect_Default_Component_Value
=>
7786 T
:= Component_Type
(Entity
(ASN
));
7788 -- Default_Value is resolved with the type entity in question
7790 when Aspect_Default_Value
=>
7793 -- Depends is a delayed aspect because it mentiones names first
7794 -- introduced by aspect Global which is already delayed. There is
7795 -- no action to be taken with respect to the aspect itself as the
7796 -- analysis is done by the corresponding pragma.
7798 when Aspect_Depends
=>
7801 when Aspect_Dispatching_Domain
=>
7802 T
:= RTE
(RE_Dispatching_Domain
);
7804 when Aspect_External_Tag
=>
7805 T
:= Standard_String
;
7807 when Aspect_External_Name
=>
7808 T
:= Standard_String
;
7810 -- Global is a delayed aspect because it may reference names that
7811 -- have not been declared yet. There is no action to be taken with
7812 -- respect to the aspect itself as the reference checking is done
7813 -- on the corresponding pragma.
7815 when Aspect_Global
=>
7818 when Aspect_Link_Name
=>
7819 T
:= Standard_String
;
7821 when Aspect_Priority | Aspect_Interrupt_Priority
=>
7822 T
:= Standard_Integer
;
7824 when Aspect_Relative_Deadline
=>
7825 T
:= RTE
(RE_Time_Span
);
7827 when Aspect_Small
=>
7828 T
:= Universal_Real
;
7830 -- For a simple storage pool, we have to retrieve the type of the
7831 -- pool object associated with the aspect's corresponding attribute
7832 -- definition clause.
7834 when Aspect_Simple_Storage_Pool
=>
7835 T
:= Etype
(Expression
(Aspect_Rep_Item
(ASN
)));
7837 when Aspect_Storage_Pool
=>
7838 T
:= Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
));
7840 when Aspect_Alignment |
7841 Aspect_Component_Size |
7842 Aspect_Machine_Radix |
7843 Aspect_Object_Size |
7845 Aspect_Storage_Size |
7846 Aspect_Stream_Size |
7847 Aspect_Value_Size
=>
7850 when Aspect_Synchronization
=>
7853 -- Special case, the expression of these aspects is just an entity
7854 -- that does not need any resolution, so just analyze.
7863 Analyze
(Expression
(ASN
));
7866 -- Same for Iterator aspects, where the expression is a function
7867 -- name. Legality rules are checked separately.
7869 when Aspect_Constant_Indexing |
7870 Aspect_Default_Iterator |
7871 Aspect_Iterator_Element |
7872 Aspect_Variable_Indexing
=>
7873 Analyze
(Expression
(ASN
));
7876 -- Invariant/Predicate take boolean expressions
7878 when Aspect_Dynamic_Predicate |
7881 Aspect_Static_Predicate |
7882 Aspect_Type_Invariant
=>
7883 T
:= Standard_Boolean
;
7885 -- Here is the list of aspects that don't require delay analysis
7887 when Aspect_Abstract_State |
7888 Aspect_Contract_Cases |
7890 Aspect_Dimension_System |
7891 Aspect_Implicit_Dereference |
7892 Aspect_Initial_Condition |
7893 Aspect_Initializes |
7895 Aspect_Postcondition |
7897 Aspect_Precondition |
7898 Aspect_Refined_Depends |
7899 Aspect_Refined_Global |
7900 Aspect_Refined_Post |
7901 Aspect_Refined_State |
7904 raise Program_Error
;
7908 -- Do the preanalyze call
7910 Preanalyze_Spec_Expression
(Expression
(ASN
), T
);
7911 end Check_Aspect_At_Freeze_Point
;
7913 -----------------------------------
7914 -- Check_Constant_Address_Clause --
7915 -----------------------------------
7917 procedure Check_Constant_Address_Clause
7921 procedure Check_At_Constant_Address
(Nod
: Node_Id
);
7922 -- Checks that the given node N represents a name whose 'Address is
7923 -- constant (in the same sense as OK_Constant_Address_Clause, i.e. the
7924 -- address value is the same at the point of declaration of U_Ent and at
7925 -- the time of elaboration of the address clause.
7927 procedure Check_Expr_Constants
(Nod
: Node_Id
);
7928 -- Checks that Nod meets the requirements for a constant address clause
7929 -- in the sense of the enclosing procedure.
7931 procedure Check_List_Constants
(Lst
: List_Id
);
7932 -- Check that all elements of list Lst meet the requirements for a
7933 -- constant address clause in the sense of the enclosing procedure.
7935 -------------------------------
7936 -- Check_At_Constant_Address --
7937 -------------------------------
7939 procedure Check_At_Constant_Address
(Nod
: Node_Id
) is
7941 if Is_Entity_Name
(Nod
) then
7942 if Present
(Address_Clause
(Entity
((Nod
)))) then
7944 ("invalid address clause for initialized object &!",
7947 ("address for& cannot" &
7948 " depend on another address clause! (RM 13.1(22))!",
7951 elsif In_Same_Source_Unit
(Entity
(Nod
), U_Ent
)
7952 and then Sloc
(U_Ent
) < Sloc
(Entity
(Nod
))
7955 ("invalid address clause for initialized object &!",
7957 Error_Msg_Node_2
:= U_Ent
;
7959 ("\& must be defined before & (RM 13.1(22))!",
7963 elsif Nkind
(Nod
) = N_Selected_Component
then
7965 T
: constant Entity_Id
:= Etype
(Prefix
(Nod
));
7968 if (Is_Record_Type
(T
)
7969 and then Has_Discriminants
(T
))
7972 and then Is_Record_Type
(Designated_Type
(T
))
7973 and then Has_Discriminants
(Designated_Type
(T
)))
7976 ("invalid address clause for initialized object &!",
7979 ("\address cannot depend on component" &
7980 " of discriminated record (RM 13.1(22))!",
7983 Check_At_Constant_Address
(Prefix
(Nod
));
7987 elsif Nkind
(Nod
) = N_Indexed_Component
then
7988 Check_At_Constant_Address
(Prefix
(Nod
));
7989 Check_List_Constants
(Expressions
(Nod
));
7992 Check_Expr_Constants
(Nod
);
7994 end Check_At_Constant_Address
;
7996 --------------------------
7997 -- Check_Expr_Constants --
7998 --------------------------
8000 procedure Check_Expr_Constants
(Nod
: Node_Id
) is
8001 Loc_U_Ent
: constant Source_Ptr
:= Sloc
(U_Ent
);
8002 Ent
: Entity_Id
:= Empty
;
8005 if Nkind
(Nod
) in N_Has_Etype
8006 and then Etype
(Nod
) = Any_Type
8012 when N_Empty | N_Error
=>
8015 when N_Identifier | N_Expanded_Name
=>
8016 Ent
:= Entity
(Nod
);
8018 -- We need to look at the original node if it is different
8019 -- from the node, since we may have rewritten things and
8020 -- substituted an identifier representing the rewrite.
8022 if Original_Node
(Nod
) /= Nod
then
8023 Check_Expr_Constants
(Original_Node
(Nod
));
8025 -- If the node is an object declaration without initial
8026 -- value, some code has been expanded, and the expression
8027 -- is not constant, even if the constituents might be
8028 -- acceptable, as in A'Address + offset.
8030 if Ekind
(Ent
) = E_Variable
8032 Nkind
(Declaration_Node
(Ent
)) = N_Object_Declaration
8034 No
(Expression
(Declaration_Node
(Ent
)))
8037 ("invalid address clause for initialized object &!",
8040 -- If entity is constant, it may be the result of expanding
8041 -- a check. We must verify that its declaration appears
8042 -- before the object in question, else we also reject the
8045 elsif Ekind
(Ent
) = E_Constant
8046 and then In_Same_Source_Unit
(Ent
, U_Ent
)
8047 and then Sloc
(Ent
) > Loc_U_Ent
8050 ("invalid address clause for initialized object &!",
8057 -- Otherwise look at the identifier and see if it is OK
8059 if Ekind_In
(Ent
, E_Named_Integer
, E_Named_Real
)
8060 or else Is_Type
(Ent
)
8065 Ekind
(Ent
) = E_Constant
8067 Ekind
(Ent
) = E_In_Parameter
8069 -- This is the case where we must have Ent defined before
8070 -- U_Ent. Clearly if they are in different units this
8071 -- requirement is met since the unit containing Ent is
8072 -- already processed.
8074 if not In_Same_Source_Unit
(Ent
, U_Ent
) then
8077 -- Otherwise location of Ent must be before the location
8078 -- of U_Ent, that's what prior defined means.
8080 elsif Sloc
(Ent
) < Loc_U_Ent
then
8085 ("invalid address clause for initialized object &!",
8087 Error_Msg_Node_2
:= U_Ent
;
8089 ("\& must be defined before & (RM 13.1(22))!",
8093 elsif Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
8094 Check_Expr_Constants
(Original_Node
(Nod
));
8098 ("invalid address clause for initialized object &!",
8101 if Comes_From_Source
(Ent
) then
8103 ("\reference to variable& not allowed"
8104 & " (RM 13.1(22))!", Nod
, Ent
);
8107 ("non-static expression not allowed"
8108 & " (RM 13.1(22))!", Nod
);
8112 when N_Integer_Literal
=>
8114 -- If this is a rewritten unchecked conversion, in a system
8115 -- where Address is an integer type, always use the base type
8116 -- for a literal value. This is user-friendly and prevents
8117 -- order-of-elaboration issues with instances of unchecked
8120 if Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
8121 Set_Etype
(Nod
, Base_Type
(Etype
(Nod
)));
8124 when N_Real_Literal |
8126 N_Character_Literal
=>
8130 Check_Expr_Constants
(Low_Bound
(Nod
));
8131 Check_Expr_Constants
(High_Bound
(Nod
));
8133 when N_Explicit_Dereference
=>
8134 Check_Expr_Constants
(Prefix
(Nod
));
8136 when N_Indexed_Component
=>
8137 Check_Expr_Constants
(Prefix
(Nod
));
8138 Check_List_Constants
(Expressions
(Nod
));
8141 Check_Expr_Constants
(Prefix
(Nod
));
8142 Check_Expr_Constants
(Discrete_Range
(Nod
));
8144 when N_Selected_Component
=>
8145 Check_Expr_Constants
(Prefix
(Nod
));
8147 when N_Attribute_Reference
=>
8148 if Nam_In
(Attribute_Name
(Nod
), Name_Address
,
8150 Name_Unchecked_Access
,
8151 Name_Unrestricted_Access
)
8153 Check_At_Constant_Address
(Prefix
(Nod
));
8156 Check_Expr_Constants
(Prefix
(Nod
));
8157 Check_List_Constants
(Expressions
(Nod
));
8161 Check_List_Constants
(Component_Associations
(Nod
));
8162 Check_List_Constants
(Expressions
(Nod
));
8164 when N_Component_Association
=>
8165 Check_Expr_Constants
(Expression
(Nod
));
8167 when N_Extension_Aggregate
=>
8168 Check_Expr_Constants
(Ancestor_Part
(Nod
));
8169 Check_List_Constants
(Component_Associations
(Nod
));
8170 Check_List_Constants
(Expressions
(Nod
));
8175 when N_Binary_Op | N_Short_Circuit | N_Membership_Test
=>
8176 Check_Expr_Constants
(Left_Opnd
(Nod
));
8177 Check_Expr_Constants
(Right_Opnd
(Nod
));
8180 Check_Expr_Constants
(Right_Opnd
(Nod
));
8182 when N_Type_Conversion |
8183 N_Qualified_Expression |
8185 N_Unchecked_Type_Conversion
=>
8186 Check_Expr_Constants
(Expression
(Nod
));
8188 when N_Function_Call
=>
8189 if not Is_Pure
(Entity
(Name
(Nod
))) then
8191 ("invalid address clause for initialized object &!",
8195 ("\function & is not pure (RM 13.1(22))!",
8196 Nod
, Entity
(Name
(Nod
)));
8199 Check_List_Constants
(Parameter_Associations
(Nod
));
8202 when N_Parameter_Association
=>
8203 Check_Expr_Constants
(Explicit_Actual_Parameter
(Nod
));
8207 ("invalid address clause for initialized object &!",
8210 ("\must be constant defined before& (RM 13.1(22))!",
8213 end Check_Expr_Constants
;
8215 --------------------------
8216 -- Check_List_Constants --
8217 --------------------------
8219 procedure Check_List_Constants
(Lst
: List_Id
) is
8223 if Present
(Lst
) then
8224 Nod1
:= First
(Lst
);
8225 while Present
(Nod1
) loop
8226 Check_Expr_Constants
(Nod1
);
8230 end Check_List_Constants
;
8232 -- Start of processing for Check_Constant_Address_Clause
8235 -- If rep_clauses are to be ignored, no need for legality checks. In
8236 -- particular, no need to pester user about rep clauses that violate
8237 -- the rule on constant addresses, given that these clauses will be
8238 -- removed by Freeze before they reach the back end.
8240 if not Ignore_Rep_Clauses
then
8241 Check_Expr_Constants
(Expr
);
8243 end Check_Constant_Address_Clause
;
8245 ----------------------------------------
8246 -- Check_Record_Representation_Clause --
8247 ----------------------------------------
8249 procedure Check_Record_Representation_Clause
(N
: Node_Id
) is
8250 Loc
: constant Source_Ptr
:= Sloc
(N
);
8251 Ident
: constant Node_Id
:= Identifier
(N
);
8252 Rectype
: Entity_Id
;
8257 Hbit
: Uint
:= Uint_0
;
8261 Max_Bit_So_Far
: Uint
;
8262 -- Records the maximum bit position so far. If all field positions
8263 -- are monotonically increasing, then we can skip the circuit for
8264 -- checking for overlap, since no overlap is possible.
8266 Tagged_Parent
: Entity_Id
:= Empty
;
8267 -- This is set in the case of a derived tagged type for which we have
8268 -- Is_Fully_Repped_Tagged_Type True (indicating that all components are
8269 -- positioned by record representation clauses). In this case we must
8270 -- check for overlap between components of this tagged type, and the
8271 -- components of its parent. Tagged_Parent will point to this parent
8272 -- type. For all other cases Tagged_Parent is left set to Empty.
8274 Parent_Last_Bit
: Uint
;
8275 -- Relevant only if Tagged_Parent is set, Parent_Last_Bit indicates the
8276 -- last bit position for any field in the parent type. We only need to
8277 -- check overlap for fields starting below this point.
8279 Overlap_Check_Required
: Boolean;
8280 -- Used to keep track of whether or not an overlap check is required
8282 Overlap_Detected
: Boolean := False;
8283 -- Set True if an overlap is detected
8285 Ccount
: Natural := 0;
8286 -- Number of component clauses in record rep clause
8288 procedure Check_Component_Overlap
(C1_Ent
, C2_Ent
: Entity_Id
);
8289 -- Given two entities for record components or discriminants, checks
8290 -- if they have overlapping component clauses and issues errors if so.
8292 procedure Find_Component
;
8293 -- Finds component entity corresponding to current component clause (in
8294 -- CC), and sets Comp to the entity, and Fbit/Lbit to the zero origin
8295 -- start/stop bits for the field. If there is no matching component or
8296 -- if the matching component does not have a component clause, then
8297 -- that's an error and Comp is set to Empty, but no error message is
8298 -- issued, since the message was already given. Comp is also set to
8299 -- Empty if the current "component clause" is in fact a pragma.
8301 -----------------------------
8302 -- Check_Component_Overlap --
8303 -----------------------------
8305 procedure Check_Component_Overlap
(C1_Ent
, C2_Ent
: Entity_Id
) is
8306 CC1
: constant Node_Id
:= Component_Clause
(C1_Ent
);
8307 CC2
: constant Node_Id
:= Component_Clause
(C2_Ent
);
8310 if Present
(CC1
) and then Present
(CC2
) then
8312 -- Exclude odd case where we have two tag components in the same
8313 -- record, both at location zero. This seems a bit strange, but
8314 -- it seems to happen in some circumstances, perhaps on an error.
8316 if Nam_In
(Chars
(C1_Ent
), Name_uTag
, Name_uTag
) then
8320 -- Here we check if the two fields overlap
8323 S1
: constant Uint
:= Component_Bit_Offset
(C1_Ent
);
8324 S2
: constant Uint
:= Component_Bit_Offset
(C2_Ent
);
8325 E1
: constant Uint
:= S1
+ Esize
(C1_Ent
);
8326 E2
: constant Uint
:= S2
+ Esize
(C2_Ent
);
8329 if E2
<= S1
or else E1
<= S2
then
8332 Error_Msg_Node_2
:= Component_Name
(CC2
);
8333 Error_Msg_Sloc
:= Sloc
(Error_Msg_Node_2
);
8334 Error_Msg_Node_1
:= Component_Name
(CC1
);
8336 ("component& overlaps & #", Component_Name
(CC1
));
8337 Overlap_Detected
:= True;
8341 end Check_Component_Overlap
;
8343 --------------------
8344 -- Find_Component --
8345 --------------------
8347 procedure Find_Component
is
8349 procedure Search_Component
(R
: Entity_Id
);
8350 -- Search components of R for a match. If found, Comp is set
8352 ----------------------
8353 -- Search_Component --
8354 ----------------------
8356 procedure Search_Component
(R
: Entity_Id
) is
8358 Comp
:= First_Component_Or_Discriminant
(R
);
8359 while Present
(Comp
) loop
8361 -- Ignore error of attribute name for component name (we
8362 -- already gave an error message for this, so no need to
8365 if Nkind
(Component_Name
(CC
)) = N_Attribute_Reference
then
8368 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
8371 Next_Component_Or_Discriminant
(Comp
);
8373 end Search_Component
;
8375 -- Start of processing for Find_Component
8378 -- Return with Comp set to Empty if we have a pragma
8380 if Nkind
(CC
) = N_Pragma
then
8385 -- Search current record for matching component
8387 Search_Component
(Rectype
);
8389 -- If not found, maybe component of base type discriminant that is
8390 -- absent from statically constrained first subtype.
8393 Search_Component
(Base_Type
(Rectype
));
8396 -- If no component, or the component does not reference the component
8397 -- clause in question, then there was some previous error for which
8398 -- we already gave a message, so just return with Comp Empty.
8400 if No
(Comp
) or else Component_Clause
(Comp
) /= CC
then
8401 Check_Error_Detected
;
8404 -- Normal case where we have a component clause
8407 Fbit
:= Component_Bit_Offset
(Comp
);
8408 Lbit
:= Fbit
+ Esize
(Comp
) - 1;
8412 -- Start of processing for Check_Record_Representation_Clause
8416 Rectype
:= Entity
(Ident
);
8418 if Rectype
= Any_Type
then
8421 Rectype
:= Underlying_Type
(Rectype
);
8424 -- See if we have a fully repped derived tagged type
8427 PS
: constant Entity_Id
:= Parent_Subtype
(Rectype
);
8430 if Present
(PS
) and then Is_Fully_Repped_Tagged_Type
(PS
) then
8431 Tagged_Parent
:= PS
;
8433 -- Find maximum bit of any component of the parent type
8435 Parent_Last_Bit
:= UI_From_Int
(System_Address_Size
- 1);
8436 Pcomp
:= First_Entity
(Tagged_Parent
);
8437 while Present
(Pcomp
) loop
8438 if Ekind_In
(Pcomp
, E_Discriminant
, E_Component
) then
8439 if Component_Bit_Offset
(Pcomp
) /= No_Uint
8440 and then Known_Static_Esize
(Pcomp
)
8445 Component_Bit_Offset
(Pcomp
) + Esize
(Pcomp
) - 1);
8448 Next_Entity
(Pcomp
);
8454 -- All done if no component clauses
8456 CC
:= First
(Component_Clauses
(N
));
8462 -- If a tag is present, then create a component clause that places it
8463 -- at the start of the record (otherwise gigi may place it after other
8464 -- fields that have rep clauses).
8466 Fent
:= First_Entity
(Rectype
);
8468 if Nkind
(Fent
) = N_Defining_Identifier
8469 and then Chars
(Fent
) = Name_uTag
8471 Set_Component_Bit_Offset
(Fent
, Uint_0
);
8472 Set_Normalized_Position
(Fent
, Uint_0
);
8473 Set_Normalized_First_Bit
(Fent
, Uint_0
);
8474 Set_Normalized_Position_Max
(Fent
, Uint_0
);
8475 Init_Esize
(Fent
, System_Address_Size
);
8477 Set_Component_Clause
(Fent
,
8478 Make_Component_Clause
(Loc
,
8479 Component_Name
=> Make_Identifier
(Loc
, Name_uTag
),
8481 Position
=> Make_Integer_Literal
(Loc
, Uint_0
),
8482 First_Bit
=> Make_Integer_Literal
(Loc
, Uint_0
),
8484 Make_Integer_Literal
(Loc
,
8485 UI_From_Int
(System_Address_Size
))));
8487 Ccount
:= Ccount
+ 1;
8490 Max_Bit_So_Far
:= Uint_Minus_1
;
8491 Overlap_Check_Required
:= False;
8493 -- Process the component clauses
8495 while Present
(CC
) loop
8498 if Present
(Comp
) then
8499 Ccount
:= Ccount
+ 1;
8501 -- We need a full overlap check if record positions non-monotonic
8503 if Fbit
<= Max_Bit_So_Far
then
8504 Overlap_Check_Required
:= True;
8507 Max_Bit_So_Far
:= Lbit
;
8509 -- Check bit position out of range of specified size
8511 if Has_Size_Clause
(Rectype
)
8512 and then RM_Size
(Rectype
) <= Lbit
8515 ("bit number out of range of specified size",
8518 -- Check for overlap with tag component
8521 if Is_Tagged_Type
(Rectype
)
8522 and then Fbit
< System_Address_Size
8525 ("component overlaps tag field of&",
8526 Component_Name
(CC
), Rectype
);
8527 Overlap_Detected
:= True;
8535 -- Check parent overlap if component might overlap parent field
8537 if Present
(Tagged_Parent
) and then Fbit
<= Parent_Last_Bit
then
8538 Pcomp
:= First_Component_Or_Discriminant
(Tagged_Parent
);
8539 while Present
(Pcomp
) loop
8540 if not Is_Tag
(Pcomp
)
8541 and then Chars
(Pcomp
) /= Name_uParent
8543 Check_Component_Overlap
(Comp
, Pcomp
);
8546 Next_Component_Or_Discriminant
(Pcomp
);
8554 -- Now that we have processed all the component clauses, check for
8555 -- overlap. We have to leave this till last, since the components can
8556 -- appear in any arbitrary order in the representation clause.
8558 -- We do not need this check if all specified ranges were monotonic,
8559 -- as recorded by Overlap_Check_Required being False at this stage.
8561 -- This first section checks if there are any overlapping entries at
8562 -- all. It does this by sorting all entries and then seeing if there are
8563 -- any overlaps. If there are none, then that is decisive, but if there
8564 -- are overlaps, they may still be OK (they may result from fields in
8565 -- different variants).
8567 if Overlap_Check_Required
then
8568 Overlap_Check1
: declare
8570 OC_Fbit
: array (0 .. Ccount
) of Uint
;
8571 -- First-bit values for component clauses, the value is the offset
8572 -- of the first bit of the field from start of record. The zero
8573 -- entry is for use in sorting.
8575 OC_Lbit
: array (0 .. Ccount
) of Uint
;
8576 -- Last-bit values for component clauses, the value is the offset
8577 -- of the last bit of the field from start of record. The zero
8578 -- entry is for use in sorting.
8580 OC_Count
: Natural := 0;
8581 -- Count of entries in OC_Fbit and OC_Lbit
8583 function OC_Lt
(Op1
, Op2
: Natural) return Boolean;
8584 -- Compare routine for Sort
8586 procedure OC_Move
(From
: Natural; To
: Natural);
8587 -- Move routine for Sort
8589 package Sorting
is new GNAT
.Heap_Sort_G
(OC_Move
, OC_Lt
);
8595 function OC_Lt
(Op1
, Op2
: Natural) return Boolean is
8597 return OC_Fbit
(Op1
) < OC_Fbit
(Op2
);
8604 procedure OC_Move
(From
: Natural; To
: Natural) is
8606 OC_Fbit
(To
) := OC_Fbit
(From
);
8607 OC_Lbit
(To
) := OC_Lbit
(From
);
8610 -- Start of processing for Overlap_Check
8613 CC
:= First
(Component_Clauses
(N
));
8614 while Present
(CC
) loop
8616 -- Exclude component clause already marked in error
8618 if not Error_Posted
(CC
) then
8621 if Present
(Comp
) then
8622 OC_Count
:= OC_Count
+ 1;
8623 OC_Fbit
(OC_Count
) := Fbit
;
8624 OC_Lbit
(OC_Count
) := Lbit
;
8631 Sorting
.Sort
(OC_Count
);
8633 Overlap_Check_Required
:= False;
8634 for J
in 1 .. OC_Count
- 1 loop
8635 if OC_Lbit
(J
) >= OC_Fbit
(J
+ 1) then
8636 Overlap_Check_Required
:= True;
8643 -- If Overlap_Check_Required is still True, then we have to do the full
8644 -- scale overlap check, since we have at least two fields that do
8645 -- overlap, and we need to know if that is OK since they are in
8646 -- different variant, or whether we have a definite problem.
8648 if Overlap_Check_Required
then
8649 Overlap_Check2
: declare
8650 C1_Ent
, C2_Ent
: Entity_Id
;
8651 -- Entities of components being checked for overlap
8654 -- Component_List node whose Component_Items are being checked
8657 -- Component declaration for component being checked
8660 C1_Ent
:= First_Entity
(Base_Type
(Rectype
));
8662 -- Loop through all components in record. For each component check
8663 -- for overlap with any of the preceding elements on the component
8664 -- list containing the component and also, if the component is in
8665 -- a variant, check against components outside the case structure.
8666 -- This latter test is repeated recursively up the variant tree.
8668 Main_Component_Loop
: while Present
(C1_Ent
) loop
8669 if not Ekind_In
(C1_Ent
, E_Component
, E_Discriminant
) then
8670 goto Continue_Main_Component_Loop
;
8673 -- Skip overlap check if entity has no declaration node. This
8674 -- happens with discriminants in constrained derived types.
8675 -- Possibly we are missing some checks as a result, but that
8676 -- does not seem terribly serious.
8678 if No
(Declaration_Node
(C1_Ent
)) then
8679 goto Continue_Main_Component_Loop
;
8682 Clist
:= Parent
(List_Containing
(Declaration_Node
(C1_Ent
)));
8684 -- Loop through component lists that need checking. Check the
8685 -- current component list and all lists in variants above us.
8687 Component_List_Loop
: loop
8689 -- If derived type definition, go to full declaration
8690 -- If at outer level, check discriminants if there are any.
8692 if Nkind
(Clist
) = N_Derived_Type_Definition
then
8693 Clist
:= Parent
(Clist
);
8696 -- Outer level of record definition, check discriminants
8698 if Nkind_In
(Clist
, N_Full_Type_Declaration
,
8699 N_Private_Type_Declaration
)
8701 if Has_Discriminants
(Defining_Identifier
(Clist
)) then
8703 First_Discriminant
(Defining_Identifier
(Clist
));
8704 while Present
(C2_Ent
) loop
8705 exit when C1_Ent
= C2_Ent
;
8706 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
8707 Next_Discriminant
(C2_Ent
);
8711 -- Record extension case
8713 elsif Nkind
(Clist
) = N_Derived_Type_Definition
then
8716 -- Otherwise check one component list
8719 Citem
:= First
(Component_Items
(Clist
));
8720 while Present
(Citem
) loop
8721 if Nkind
(Citem
) = N_Component_Declaration
then
8722 C2_Ent
:= Defining_Identifier
(Citem
);
8723 exit when C1_Ent
= C2_Ent
;
8724 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
8731 -- Check for variants above us (the parent of the Clist can
8732 -- be a variant, in which case its parent is a variant part,
8733 -- and the parent of the variant part is a component list
8734 -- whose components must all be checked against the current
8735 -- component for overlap).
8737 if Nkind
(Parent
(Clist
)) = N_Variant
then
8738 Clist
:= Parent
(Parent
(Parent
(Clist
)));
8740 -- Check for possible discriminant part in record, this
8741 -- is treated essentially as another level in the
8742 -- recursion. For this case the parent of the component
8743 -- list is the record definition, and its parent is the
8744 -- full type declaration containing the discriminant
8747 elsif Nkind
(Parent
(Clist
)) = N_Record_Definition
then
8748 Clist
:= Parent
(Parent
((Clist
)));
8750 -- If neither of these two cases, we are at the top of
8754 exit Component_List_Loop
;
8756 end loop Component_List_Loop
;
8758 <<Continue_Main_Component_Loop
>>
8759 Next_Entity
(C1_Ent
);
8761 end loop Main_Component_Loop
;
8765 -- The following circuit deals with warning on record holes (gaps). We
8766 -- skip this check if overlap was detected, since it makes sense for the
8767 -- programmer to fix this illegality before worrying about warnings.
8769 if not Overlap_Detected
and Warn_On_Record_Holes
then
8770 Record_Hole_Check
: declare
8771 Decl
: constant Node_Id
:= Declaration_Node
(Base_Type
(Rectype
));
8772 -- Full declaration of record type
8774 procedure Check_Component_List
8778 -- Check component list CL for holes. The starting bit should be
8779 -- Sbit. which is zero for the main record component list and set
8780 -- appropriately for recursive calls for variants. DS is set to
8781 -- a list of discriminant specifications to be included in the
8782 -- consideration of components. It is No_List if none to consider.
8784 --------------------------
8785 -- Check_Component_List --
8786 --------------------------
8788 procedure Check_Component_List
8796 Compl
:= Integer (List_Length
(Component_Items
(CL
)));
8798 if DS
/= No_List
then
8799 Compl
:= Compl
+ Integer (List_Length
(DS
));
8803 Comps
: array (Natural range 0 .. Compl
) of Entity_Id
;
8804 -- Gather components (zero entry is for sort routine)
8806 Ncomps
: Natural := 0;
8807 -- Number of entries stored in Comps (starting at Comps (1))
8810 -- One component item or discriminant specification
8813 -- Starting bit for next component
8821 function Lt
(Op1
, Op2
: Natural) return Boolean;
8822 -- Compare routine for Sort
8824 procedure Move
(From
: Natural; To
: Natural);
8825 -- Move routine for Sort
8827 package Sorting
is new GNAT
.Heap_Sort_G
(Move
, Lt
);
8833 function Lt
(Op1
, Op2
: Natural) return Boolean is
8835 return Component_Bit_Offset
(Comps
(Op1
))
8837 Component_Bit_Offset
(Comps
(Op2
));
8844 procedure Move
(From
: Natural; To
: Natural) is
8846 Comps
(To
) := Comps
(From
);
8850 -- Gather discriminants into Comp
8852 if DS
/= No_List
then
8853 Citem
:= First
(DS
);
8854 while Present
(Citem
) loop
8855 if Nkind
(Citem
) = N_Discriminant_Specification
then
8857 Ent
: constant Entity_Id
:=
8858 Defining_Identifier
(Citem
);
8860 if Ekind
(Ent
) = E_Discriminant
then
8861 Ncomps
:= Ncomps
+ 1;
8862 Comps
(Ncomps
) := Ent
;
8871 -- Gather component entities into Comp
8873 Citem
:= First
(Component_Items
(CL
));
8874 while Present
(Citem
) loop
8875 if Nkind
(Citem
) = N_Component_Declaration
then
8876 Ncomps
:= Ncomps
+ 1;
8877 Comps
(Ncomps
) := Defining_Identifier
(Citem
);
8883 -- Now sort the component entities based on the first bit.
8884 -- Note we already know there are no overlapping components.
8886 Sorting
.Sort
(Ncomps
);
8888 -- Loop through entries checking for holes
8891 for J
in 1 .. Ncomps
loop
8893 Error_Msg_Uint_1
:= Component_Bit_Offset
(CEnt
) - Nbit
;
8895 if Error_Msg_Uint_1
> 0 then
8897 ("?H?^-bit gap before component&",
8898 Component_Name
(Component_Clause
(CEnt
)), CEnt
);
8901 Nbit
:= Component_Bit_Offset
(CEnt
) + Esize
(CEnt
);
8904 -- Process variant parts recursively if present
8906 if Present
(Variant_Part
(CL
)) then
8907 Variant
:= First
(Variants
(Variant_Part
(CL
)));
8908 while Present
(Variant
) loop
8909 Check_Component_List
8910 (Component_List
(Variant
), Nbit
, No_List
);
8915 end Check_Component_List
;
8917 -- Start of processing for Record_Hole_Check
8924 if Is_Tagged_Type
(Rectype
) then
8925 Sbit
:= UI_From_Int
(System_Address_Size
);
8930 if Nkind
(Decl
) = N_Full_Type_Declaration
8931 and then Nkind
(Type_Definition
(Decl
)) = N_Record_Definition
8933 Check_Component_List
8934 (Component_List
(Type_Definition
(Decl
)),
8936 Discriminant_Specifications
(Decl
));
8939 end Record_Hole_Check
;
8942 -- For records that have component clauses for all components, and whose
8943 -- size is less than or equal to 32, we need to know the size in the
8944 -- front end to activate possible packed array processing where the
8945 -- component type is a record.
8947 -- At this stage Hbit + 1 represents the first unused bit from all the
8948 -- component clauses processed, so if the component clauses are
8949 -- complete, then this is the length of the record.
8951 -- For records longer than System.Storage_Unit, and for those where not
8952 -- all components have component clauses, the back end determines the
8953 -- length (it may for example be appropriate to round up the size
8954 -- to some convenient boundary, based on alignment considerations, etc).
8956 if Unknown_RM_Size
(Rectype
) and then Hbit
+ 1 <= 32 then
8958 -- Nothing to do if at least one component has no component clause
8960 Comp
:= First_Component_Or_Discriminant
(Rectype
);
8961 while Present
(Comp
) loop
8962 exit when No
(Component_Clause
(Comp
));
8963 Next_Component_Or_Discriminant
(Comp
);
8966 -- If we fall out of loop, all components have component clauses
8967 -- and so we can set the size to the maximum value.
8970 Set_RM_Size
(Rectype
, Hbit
+ 1);
8973 end Check_Record_Representation_Clause
;
8979 procedure Check_Size
8983 Biased
: out Boolean)
8985 UT
: constant Entity_Id
:= Underlying_Type
(T
);
8991 -- Reject patently improper size values.
8993 if Is_Elementary_Type
(T
)
8994 and then Siz
> UI_From_Int
(Int
'Last)
8996 Error_Msg_N
("Size value too large for elementary type", N
);
8998 if Nkind
(Original_Node
(N
)) = N_Op_Expon
then
9000 ("\maybe '* was meant, rather than '*'*", Original_Node
(N
));
9004 -- Dismiss generic types
9006 if Is_Generic_Type
(T
)
9008 Is_Generic_Type
(UT
)
9010 Is_Generic_Type
(Root_Type
(UT
))
9014 -- Guard against previous errors
9016 elsif No
(UT
) or else UT
= Any_Type
then
9017 Check_Error_Detected
;
9020 -- Check case of bit packed array
9022 elsif Is_Array_Type
(UT
)
9023 and then Known_Static_Component_Size
(UT
)
9024 and then Is_Bit_Packed_Array
(UT
)
9032 Asiz
:= Component_Size
(UT
);
9033 Indx
:= First_Index
(UT
);
9035 Ityp
:= Etype
(Indx
);
9037 -- If non-static bound, then we are not in the business of
9038 -- trying to check the length, and indeed an error will be
9039 -- issued elsewhere, since sizes of non-static array types
9040 -- cannot be set implicitly or explicitly.
9042 if not Is_Static_Subtype
(Ityp
) then
9046 -- Otherwise accumulate next dimension
9048 Asiz
:= Asiz
* (Expr_Value
(Type_High_Bound
(Ityp
)) -
9049 Expr_Value
(Type_Low_Bound
(Ityp
)) +
9053 exit when No
(Indx
);
9060 Error_Msg_Uint_1
:= Asiz
;
9062 ("size for& too small, minimum allowed is ^", N
, T
);
9063 Set_Esize
(T
, Asiz
);
9064 Set_RM_Size
(T
, Asiz
);
9068 -- All other composite types are ignored
9070 elsif Is_Composite_Type
(UT
) then
9073 -- For fixed-point types, don't check minimum if type is not frozen,
9074 -- since we don't know all the characteristics of the type that can
9075 -- affect the size (e.g. a specified small) till freeze time.
9077 elsif Is_Fixed_Point_Type
(UT
)
9078 and then not Is_Frozen
(UT
)
9082 -- Cases for which a minimum check is required
9085 -- Ignore if specified size is correct for the type
9087 if Known_Esize
(UT
) and then Siz
= Esize
(UT
) then
9091 -- Otherwise get minimum size
9093 M
:= UI_From_Int
(Minimum_Size
(UT
));
9097 -- Size is less than minimum size, but one possibility remains
9098 -- that we can manage with the new size if we bias the type.
9100 M
:= UI_From_Int
(Minimum_Size
(UT
, Biased
=> True));
9103 Error_Msg_Uint_1
:= M
;
9105 ("size for& too small, minimum allowed is ^", N
, T
);
9115 --------------------------
9116 -- Freeze_Entity_Checks --
9117 --------------------------
9119 procedure Freeze_Entity_Checks
(N
: Node_Id
) is
9120 E
: constant Entity_Id
:= Entity
(N
);
9122 Non_Generic_Case
: constant Boolean := Nkind
(N
) = N_Freeze_Entity
;
9123 -- True in non-generic case. Some of the processing here is skipped
9124 -- for the generic case since it is not needed. Basically in the
9125 -- generic case, we only need to do stuff that might generate error
9126 -- messages or warnings.
9128 -- Remember that we are processing a freezing entity. Required to
9129 -- ensure correct decoration of internal entities associated with
9130 -- interfaces (see New_Overloaded_Entity).
9132 Inside_Freezing_Actions
:= Inside_Freezing_Actions
+ 1;
9134 -- For tagged types covering interfaces add internal entities that link
9135 -- the primitives of the interfaces with the primitives that cover them.
9136 -- Note: These entities were originally generated only when generating
9137 -- code because their main purpose was to provide support to initialize
9138 -- the secondary dispatch tables. They are now generated also when
9139 -- compiling with no code generation to provide ASIS the relationship
9140 -- between interface primitives and tagged type primitives. They are
9141 -- also used to locate primitives covering interfaces when processing
9142 -- generics (see Derive_Subprograms).
9144 -- This is not needed in the generic case
9146 if Ada_Version
>= Ada_2005
9147 and then Non_Generic_Case
9148 and then Ekind
(E
) = E_Record_Type
9149 and then Is_Tagged_Type
(E
)
9150 and then not Is_Interface
(E
)
9151 and then Has_Interfaces
(E
)
9153 -- This would be a good common place to call the routine that checks
9154 -- overriding of interface primitives (and thus factorize calls to
9155 -- Check_Abstract_Overriding located at different contexts in the
9156 -- compiler). However, this is not possible because it causes
9157 -- spurious errors in case of late overriding.
9159 Add_Internal_Interface_Entities
(E
);
9164 if Ekind
(E
) = E_Record_Type
9165 and then Is_CPP_Class
(E
)
9166 and then Is_Tagged_Type
(E
)
9167 and then Tagged_Type_Expansion
9169 if CPP_Num_Prims
(E
) = 0 then
9171 -- If the CPP type has user defined components then it must import
9172 -- primitives from C++. This is required because if the C++ class
9173 -- has no primitives then the C++ compiler does not added the _tag
9174 -- component to the type.
9176 if First_Entity
(E
) /= Last_Entity
(E
) then
9178 ("'C'P'P type must import at least one primitive from C++??",
9183 -- Check that all its primitives are abstract or imported from C++.
9184 -- Check also availability of the C++ constructor.
9187 Has_Constructors
: constant Boolean := Has_CPP_Constructors
(E
);
9189 Error_Reported
: Boolean := False;
9193 Elmt
:= First_Elmt
(Primitive_Operations
(E
));
9194 while Present
(Elmt
) loop
9195 Prim
:= Node
(Elmt
);
9197 if Comes_From_Source
(Prim
) then
9198 if Is_Abstract_Subprogram
(Prim
) then
9201 elsif not Is_Imported
(Prim
)
9202 or else Convention
(Prim
) /= Convention_CPP
9205 ("primitives of 'C'P'P types must be imported from C++ "
9206 & "or abstract??", Prim
);
9208 elsif not Has_Constructors
9209 and then not Error_Reported
9211 Error_Msg_Name_1
:= Chars
(E
);
9213 ("??'C'P'P constructor required for type %", Prim
);
9214 Error_Reported
:= True;
9223 -- Check Ada derivation of CPP type
9225 if Expander_Active
-- why? losing errors in -gnatc mode???
9226 and then Tagged_Type_Expansion
9227 and then Ekind
(E
) = E_Record_Type
9228 and then Etype
(E
) /= E
9229 and then Is_CPP_Class
(Etype
(E
))
9230 and then CPP_Num_Prims
(Etype
(E
)) > 0
9231 and then not Is_CPP_Class
(E
)
9232 and then not Has_CPP_Constructors
(Etype
(E
))
9234 -- If the parent has C++ primitives but it has no constructor then
9235 -- check that all the primitives are overridden in this derivation;
9236 -- otherwise the constructor of the parent is needed to build the
9244 Elmt
:= First_Elmt
(Primitive_Operations
(E
));
9245 while Present
(Elmt
) loop
9246 Prim
:= Node
(Elmt
);
9248 if not Is_Abstract_Subprogram
(Prim
)
9249 and then No
(Interface_Alias
(Prim
))
9250 and then Find_Dispatching_Type
(Ultimate_Alias
(Prim
)) /= E
9252 Error_Msg_Name_1
:= Chars
(Etype
(E
));
9254 ("'C'P'P constructor required for parent type %", E
);
9263 Inside_Freezing_Actions
:= Inside_Freezing_Actions
- 1;
9265 -- If we have a type with predicates, build predicate function. This
9266 -- is not needed in the generic casee
9268 if Non_Generic_Case
and then Is_Type
(E
) and then Has_Predicates
(E
) then
9269 Build_Predicate_Functions
(E
, N
);
9272 -- If type has delayed aspects, this is where we do the preanalysis at
9273 -- the freeze point, as part of the consistent visibility check. Note
9274 -- that this must be done after calling Build_Predicate_Functions or
9275 -- Build_Invariant_Procedure since these subprograms fix occurrences of
9276 -- the subtype name in the saved expression so that they will not cause
9277 -- trouble in the preanalysis.
9279 -- This is also not needed in the generic case
9282 and then Has_Delayed_Aspects
(E
)
9283 and then Scope
(E
) = Current_Scope
9285 -- Retrieve the visibility to the discriminants in order to properly
9286 -- analyze the aspects.
9288 Push_Scope_And_Install_Discriminants
(E
);
9294 -- Look for aspect specification entries for this entity
9296 Ritem
:= First_Rep_Item
(E
);
9297 while Present
(Ritem
) loop
9298 if Nkind
(Ritem
) = N_Aspect_Specification
9299 and then Entity
(Ritem
) = E
9300 and then Is_Delayed_Aspect
(Ritem
)
9302 Check_Aspect_At_Freeze_Point
(Ritem
);
9305 Next_Rep_Item
(Ritem
);
9309 Uninstall_Discriminants_And_Pop_Scope
(E
);
9312 -- For a record type, deal with variant parts. This has to be delayed
9313 -- to this point, because of the issue of statically precicated
9314 -- subtypes, which we have to ensure are frozen before checking
9315 -- choices, since we need to have the static choice list set.
9317 if Is_Record_Type
(E
) then
9318 Check_Variant_Part
: declare
9319 D
: constant Node_Id
:= Declaration_Node
(E
);
9324 Others_Present
: Boolean;
9325 pragma Warnings
(Off
, Others_Present
);
9326 -- Indicates others present, not used in this case
9328 procedure Non_Static_Choice_Error
(Choice
: Node_Id
);
9329 -- Error routine invoked by the generic instantiation below when
9330 -- the variant part has a non static choice.
9332 procedure Process_Declarations
(Variant
: Node_Id
);
9333 -- Processes declarations associated with a variant. We analyzed
9334 -- the declarations earlier (in Sem_Ch3.Analyze_Variant_Part),
9335 -- but we still need the recursive call to Check_Choices for any
9336 -- nested variant to get its choices properly processed. This is
9337 -- also where we expand out the choices if expansion is active.
9339 package Variant_Choices_Processing
is new
9340 Generic_Check_Choices
9341 (Process_Empty_Choice
=> No_OP
,
9342 Process_Non_Static_Choice
=> Non_Static_Choice_Error
,
9343 Process_Associated_Node
=> Process_Declarations
);
9344 use Variant_Choices_Processing
;
9346 -----------------------------
9347 -- Non_Static_Choice_Error --
9348 -----------------------------
9350 procedure Non_Static_Choice_Error
(Choice
: Node_Id
) is
9352 Flag_Non_Static_Expr
9353 ("choice given in variant part is not static!", Choice
);
9354 end Non_Static_Choice_Error
;
9356 --------------------------
9357 -- Process_Declarations --
9358 --------------------------
9360 procedure Process_Declarations
(Variant
: Node_Id
) is
9361 CL
: constant Node_Id
:= Component_List
(Variant
);
9365 -- Check for static predicate present in this variant
9367 if Has_SP_Choice
(Variant
) then
9369 -- Here we expand. You might expect to find this call in
9370 -- Expand_N_Variant_Part, but that is called when we first
9371 -- see the variant part, and we cannot do this expansion
9372 -- earlier than the freeze point, since for statically
9373 -- predicated subtypes, the predicate is not known till
9374 -- the freeze point.
9376 -- Furthermore, we do this expansion even if the expander
9377 -- is not active, because other semantic processing, e.g.
9378 -- for aggregates, requires the expanded list of choices.
9380 -- If the expander is not active, then we can't just clobber
9381 -- the list since it would invalidate the ASIS -gnatct tree.
9382 -- So we have to rewrite the variant part with a Rewrite
9383 -- call that replaces it with a copy and clobber the copy.
9385 if not Expander_Active
then
9387 NewV
: constant Node_Id
:= New_Copy
(Variant
);
9389 Set_Discrete_Choices
9390 (NewV
, New_Copy_List
(Discrete_Choices
(Variant
)));
9391 Rewrite
(Variant
, NewV
);
9395 Expand_Static_Predicates_In_Choices
(Variant
);
9398 -- We don't need to worry about the declarations in the variant
9399 -- (since they were analyzed by Analyze_Choices when we first
9400 -- encountered the variant), but we do need to take care of
9401 -- expansion of any nested variants.
9403 if not Null_Present
(CL
) then
9404 VP
:= Variant_Part
(CL
);
9406 if Present
(VP
) then
9408 (VP
, Variants
(VP
), Etype
(Name
(VP
)), Others_Present
);
9411 end Process_Declarations
;
9413 -- Start of processing for Check_Variant_Part
9416 -- Find component list
9420 if Nkind
(D
) = N_Full_Type_Declaration
then
9421 T
:= Type_Definition
(D
);
9423 if Nkind
(T
) = N_Record_Definition
then
9424 C
:= Component_List
(T
);
9426 elsif Nkind
(T
) = N_Derived_Type_Definition
9427 and then Present
(Record_Extension_Part
(T
))
9429 C
:= Component_List
(Record_Extension_Part
(T
));
9433 -- Case of variant part present
9435 if Present
(C
) and then Present
(Variant_Part
(C
)) then
9436 VP
:= Variant_Part
(C
);
9441 (VP
, Variants
(VP
), Etype
(Name
(VP
)), Others_Present
);
9443 -- If the last variant does not contain the Others choice,
9444 -- replace it with an N_Others_Choice node since Gigi always
9445 -- wants an Others. Note that we do not bother to call Analyze
9446 -- on the modified variant part, since its only effect would be
9447 -- to compute the Others_Discrete_Choices node laboriously, and
9448 -- of course we already know the list of choices corresponding
9449 -- to the others choice (it's the list we're replacing!)
9451 -- We only want to do this if the expander is active, since
9452 -- we do not want to clobber the ASIS tree!
9454 if Expander_Active
then
9456 Last_Var
: constant Node_Id
:=
9457 Last_Non_Pragma
(Variants
(VP
));
9459 Others_Node
: Node_Id
;
9462 if Nkind
(First
(Discrete_Choices
(Last_Var
))) /=
9465 Others_Node
:= Make_Others_Choice
(Sloc
(Last_Var
));
9466 Set_Others_Discrete_Choices
9467 (Others_Node
, Discrete_Choices
(Last_Var
));
9468 Set_Discrete_Choices
9469 (Last_Var
, New_List
(Others_Node
));
9474 end Check_Variant_Part
;
9476 end Freeze_Entity_Checks
;
9478 -------------------------
9479 -- Get_Alignment_Value --
9480 -------------------------
9482 function Get_Alignment_Value
(Expr
: Node_Id
) return Uint
is
9483 Align
: constant Uint
:= Static_Integer
(Expr
);
9486 if Align
= No_Uint
then
9489 elsif Align
<= 0 then
9490 Error_Msg_N
("alignment value must be positive", Expr
);
9494 for J
in Int
range 0 .. 64 loop
9496 M
: constant Uint
:= Uint_2
** J
;
9499 exit when M
= Align
;
9503 ("alignment value must be power of 2", Expr
);
9511 end Get_Alignment_Value
;
9513 -------------------------------------
9514 -- Inherit_Aspects_At_Freeze_Point --
9515 -------------------------------------
9517 procedure Inherit_Aspects_At_Freeze_Point
(Typ
: Entity_Id
) is
9519 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9520 (Rep_Item
: Node_Id
) return Boolean;
9521 -- This routine checks if Rep_Item is either a pragma or an aspect
9522 -- specification node whose correponding pragma (if any) is present in
9523 -- the Rep Item chain of the entity it has been specified to.
9525 --------------------------------------------------
9526 -- Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item --
9527 --------------------------------------------------
9529 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9530 (Rep_Item
: Node_Id
) return Boolean
9533 return Nkind
(Rep_Item
) = N_Pragma
9534 or else Present_In_Rep_Item
9535 (Entity
(Rep_Item
), Aspect_Rep_Item
(Rep_Item
));
9536 end Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
;
9538 -- Start of processing for Inherit_Aspects_At_Freeze_Point
9541 -- A representation item is either subtype-specific (Size and Alignment
9542 -- clauses) or type-related (all others). Subtype-specific aspects may
9543 -- differ for different subtypes of the same type (RM 13.1.8).
9545 -- A derived type inherits each type-related representation aspect of
9546 -- its parent type that was directly specified before the declaration of
9547 -- the derived type (RM 13.1.15).
9549 -- A derived subtype inherits each subtype-specific representation
9550 -- aspect of its parent subtype that was directly specified before the
9551 -- declaration of the derived type (RM 13.1.15).
9553 -- The general processing involves inheriting a representation aspect
9554 -- from a parent type whenever the first rep item (aspect specification,
9555 -- attribute definition clause, pragma) corresponding to the given
9556 -- representation aspect in the rep item chain of Typ, if any, isn't
9557 -- directly specified to Typ but to one of its parents.
9559 -- ??? Note that, for now, just a limited number of representation
9560 -- aspects have been inherited here so far. Many of them are
9561 -- still inherited in Sem_Ch3. This will be fixed soon. Here is
9562 -- a non- exhaustive list of aspects that likely also need to
9563 -- be moved to this routine: Alignment, Component_Alignment,
9564 -- Component_Size, Machine_Radix, Object_Size, Pack, Predicates,
9565 -- Preelaborable_Initialization, RM_Size and Small.
9567 if Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
then
9573 if not Has_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
, False)
9574 and then Has_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
)
9575 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9576 (Get_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
))
9578 Set_Is_Ada_2005_Only
(Typ
);
9583 if not Has_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
, False)
9584 and then Has_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
)
9585 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9586 (Get_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
))
9588 Set_Is_Ada_2012_Only
(Typ
);
9593 if not Has_Rep_Item
(Typ
, Name_Atomic
, Name_Shared
, False)
9594 and then Has_Rep_Pragma
(Typ
, Name_Atomic
, Name_Shared
)
9595 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9596 (Get_Rep_Item
(Typ
, Name_Atomic
, Name_Shared
))
9598 Set_Is_Atomic
(Typ
);
9599 Set_Treat_As_Volatile
(Typ
);
9600 Set_Is_Volatile
(Typ
);
9603 -- Default_Component_Value
9605 if Is_Array_Type
(Typ
)
9606 and then Is_Base_Type
(Typ
)
9607 and then Has_Rep_Item
(Typ
, Name_Default_Component_Value
, False)
9608 and then Has_Rep_Item
(Typ
, Name_Default_Component_Value
)
9610 Set_Default_Aspect_Component_Value
(Typ
,
9611 Default_Aspect_Component_Value
9612 (Entity
(Get_Rep_Item
(Typ
, Name_Default_Component_Value
))));
9617 if Is_Scalar_Type
(Typ
)
9618 and then Is_Base_Type
(Typ
)
9619 and then Has_Rep_Item
(Typ
, Name_Default_Value
, False)
9620 and then Has_Rep_Item
(Typ
, Name_Default_Value
)
9622 Set_Default_Aspect_Value
(Typ
,
9623 Default_Aspect_Value
9624 (Entity
(Get_Rep_Item
(Typ
, Name_Default_Value
))));
9629 if not Has_Rep_Item
(Typ
, Name_Discard_Names
, False)
9630 and then Has_Rep_Item
(Typ
, Name_Discard_Names
)
9631 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9632 (Get_Rep_Item
(Typ
, Name_Discard_Names
))
9634 Set_Discard_Names
(Typ
);
9639 if not Has_Rep_Item
(Typ
, Name_Invariant
, False)
9640 and then Has_Rep_Item
(Typ
, Name_Invariant
)
9641 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9642 (Get_Rep_Item
(Typ
, Name_Invariant
))
9644 Set_Has_Invariants
(Typ
);
9646 if Class_Present
(Get_Rep_Item
(Typ
, Name_Invariant
)) then
9647 Set_Has_Inheritable_Invariants
(Typ
);
9653 if not Has_Rep_Item
(Typ
, Name_Volatile
, False)
9654 and then Has_Rep_Item
(Typ
, Name_Volatile
)
9655 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9656 (Get_Rep_Item
(Typ
, Name_Volatile
))
9658 Set_Treat_As_Volatile
(Typ
);
9659 Set_Is_Volatile
(Typ
);
9662 -- Inheritance for derived types only
9664 if Is_Derived_Type
(Typ
) then
9666 Bas_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
9667 Imp_Bas_Typ
: constant Entity_Id
:= Implementation_Base_Type
(Typ
);
9670 -- Atomic_Components
9672 if not Has_Rep_Item
(Typ
, Name_Atomic_Components
, False)
9673 and then Has_Rep_Item
(Typ
, Name_Atomic_Components
)
9674 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9675 (Get_Rep_Item
(Typ
, Name_Atomic_Components
))
9677 Set_Has_Atomic_Components
(Imp_Bas_Typ
);
9680 -- Volatile_Components
9682 if not Has_Rep_Item
(Typ
, Name_Volatile_Components
, False)
9683 and then Has_Rep_Item
(Typ
, Name_Volatile_Components
)
9684 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9685 (Get_Rep_Item
(Typ
, Name_Volatile_Components
))
9687 Set_Has_Volatile_Components
(Imp_Bas_Typ
);
9690 -- Finalize_Storage_Only.
9692 if not Has_Rep_Pragma
(Typ
, Name_Finalize_Storage_Only
, False)
9693 and then Has_Rep_Pragma
(Typ
, Name_Finalize_Storage_Only
)
9695 Set_Finalize_Storage_Only
(Bas_Typ
);
9698 -- Universal_Aliasing
9700 if not Has_Rep_Item
(Typ
, Name_Universal_Aliasing
, False)
9701 and then Has_Rep_Item
(Typ
, Name_Universal_Aliasing
)
9702 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9703 (Get_Rep_Item
(Typ
, Name_Universal_Aliasing
))
9705 Set_Universal_Aliasing
(Imp_Bas_Typ
);
9708 -- Record type specific aspects
9710 if Is_Record_Type
(Typ
) then
9714 if not Has_Rep_Item
(Typ
, Name_Bit_Order
, False)
9715 and then Has_Rep_Item
(Typ
, Name_Bit_Order
)
9717 Set_Reverse_Bit_Order
(Bas_Typ
,
9718 Reverse_Bit_Order
(Entity
(Name
9719 (Get_Rep_Item
(Typ
, Name_Bit_Order
)))));
9722 -- Scalar_Storage_Order
9724 if not Has_Rep_Item
(Typ
, Name_Scalar_Storage_Order
, False)
9725 and then Has_Rep_Item
(Typ
, Name_Scalar_Storage_Order
)
9727 Set_Reverse_Storage_Order
(Bas_Typ
,
9728 Reverse_Storage_Order
(Entity
(Name
9729 (Get_Rep_Item
(Typ
, Name_Scalar_Storage_Order
)))));
9734 end Inherit_Aspects_At_Freeze_Point
;
9740 procedure Initialize
is
9742 Address_Clause_Checks
.Init
;
9743 Independence_Checks
.Init
;
9744 Unchecked_Conversions
.Init
;
9747 -------------------------
9748 -- Is_Operational_Item --
9749 -------------------------
9751 function Is_Operational_Item
(N
: Node_Id
) return Boolean is
9753 if Nkind
(N
) /= N_Attribute_Definition_Clause
then
9758 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Chars
(N
));
9760 return Id
= Attribute_Input
9761 or else Id
= Attribute_Output
9762 or else Id
= Attribute_Read
9763 or else Id
= Attribute_Write
9764 or else Id
= Attribute_External_Tag
;
9767 end Is_Operational_Item
;
9773 function Minimum_Size
9775 Biased
: Boolean := False) return Nat
9777 Lo
: Uint
:= No_Uint
;
9778 Hi
: Uint
:= No_Uint
;
9779 LoR
: Ureal
:= No_Ureal
;
9780 HiR
: Ureal
:= No_Ureal
;
9781 LoSet
: Boolean := False;
9782 HiSet
: Boolean := False;
9786 R_Typ
: constant Entity_Id
:= Root_Type
(T
);
9789 -- If bad type, return 0
9791 if T
= Any_Type
then
9794 -- For generic types, just return zero. There cannot be any legitimate
9795 -- need to know such a size, but this routine may be called with a
9796 -- generic type as part of normal processing.
9798 elsif Is_Generic_Type
(R_Typ
)
9799 or else R_Typ
= Any_Type
9803 -- Access types. Normally an access type cannot have a size smaller
9804 -- than the size of System.Address. The exception is on VMS, where
9805 -- we have short and long addresses, and it is possible for an access
9806 -- type to have a short address size (and thus be less than the size
9807 -- of System.Address itself). We simply skip the check for VMS, and
9808 -- leave it to the back end to do the check.
9810 elsif Is_Access_Type
(T
) then
9811 if OpenVMS_On_Target
then
9814 return System_Address_Size
;
9817 -- Floating-point types
9819 elsif Is_Floating_Point_Type
(T
) then
9820 return UI_To_Int
(Esize
(R_Typ
));
9824 elsif Is_Discrete_Type
(T
) then
9826 -- The following loop is looking for the nearest compile time known
9827 -- bounds following the ancestor subtype chain. The idea is to find
9828 -- the most restrictive known bounds information.
9832 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
9837 if Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
)) then
9838 Lo
:= Expr_Rep_Value
(Type_Low_Bound
(Ancest
));
9845 if Compile_Time_Known_Value
(Type_High_Bound
(Ancest
)) then
9846 Hi
:= Expr_Rep_Value
(Type_High_Bound
(Ancest
));
9852 Ancest
:= Ancestor_Subtype
(Ancest
);
9855 Ancest
:= Base_Type
(T
);
9857 if Is_Generic_Type
(Ancest
) then
9863 -- Fixed-point types. We can't simply use Expr_Value to get the
9864 -- Corresponding_Integer_Value values of the bounds, since these do not
9865 -- get set till the type is frozen, and this routine can be called
9866 -- before the type is frozen. Similarly the test for bounds being static
9867 -- needs to include the case where we have unanalyzed real literals for
9870 elsif Is_Fixed_Point_Type
(T
) then
9872 -- The following loop is looking for the nearest compile time known
9873 -- bounds following the ancestor subtype chain. The idea is to find
9874 -- the most restrictive known bounds information.
9878 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
9882 -- Note: In the following two tests for LoSet and HiSet, it may
9883 -- seem redundant to test for N_Real_Literal here since normally
9884 -- one would assume that the test for the value being known at
9885 -- compile time includes this case. However, there is a glitch.
9886 -- If the real literal comes from folding a non-static expression,
9887 -- then we don't consider any non- static expression to be known
9888 -- at compile time if we are in configurable run time mode (needed
9889 -- in some cases to give a clearer definition of what is and what
9890 -- is not accepted). So the test is indeed needed. Without it, we
9891 -- would set neither Lo_Set nor Hi_Set and get an infinite loop.
9894 if Nkind
(Type_Low_Bound
(Ancest
)) = N_Real_Literal
9895 or else Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
))
9897 LoR
:= Expr_Value_R
(Type_Low_Bound
(Ancest
));
9904 if Nkind
(Type_High_Bound
(Ancest
)) = N_Real_Literal
9905 or else Compile_Time_Known_Value
(Type_High_Bound
(Ancest
))
9907 HiR
:= Expr_Value_R
(Type_High_Bound
(Ancest
));
9913 Ancest
:= Ancestor_Subtype
(Ancest
);
9916 Ancest
:= Base_Type
(T
);
9918 if Is_Generic_Type
(Ancest
) then
9924 Lo
:= UR_To_Uint
(LoR
/ Small_Value
(T
));
9925 Hi
:= UR_To_Uint
(HiR
/ Small_Value
(T
));
9927 -- No other types allowed
9930 raise Program_Error
;
9933 -- Fall through with Hi and Lo set. Deal with biased case
9936 and then not Is_Fixed_Point_Type
(T
)
9937 and then not (Is_Enumeration_Type
(T
)
9938 and then Has_Non_Standard_Rep
(T
)))
9939 or else Has_Biased_Representation
(T
)
9945 -- Signed case. Note that we consider types like range 1 .. -1 to be
9946 -- signed for the purpose of computing the size, since the bounds have
9947 -- to be accommodated in the base type.
9949 if Lo
< 0 or else Hi
< 0 then
9953 -- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1))
9954 -- Note that we accommodate the case where the bounds cross. This
9955 -- can happen either because of the way the bounds are declared
9956 -- or because of the algorithm in Freeze_Fixed_Point_Type.
9970 -- If both bounds are positive, make sure that both are represen-
9971 -- table in the case where the bounds are crossed. This can happen
9972 -- either because of the way the bounds are declared, or because of
9973 -- the algorithm in Freeze_Fixed_Point_Type.
9979 -- S = size, (can accommodate 0 .. (2**size - 1))
9982 while Hi
>= Uint_2
** S
loop
9990 ---------------------------
9991 -- New_Stream_Subprogram --
9992 ---------------------------
9994 procedure New_Stream_Subprogram
9998 Nam
: TSS_Name_Type
)
10000 Loc
: constant Source_Ptr
:= Sloc
(N
);
10001 Sname
: constant Name_Id
:= Make_TSS_Name
(Base_Type
(Ent
), Nam
);
10002 Subp_Id
: Entity_Id
;
10003 Subp_Decl
: Node_Id
;
10007 Defer_Declaration
: constant Boolean :=
10008 Is_Tagged_Type
(Ent
) or else Is_Private_Type
(Ent
);
10009 -- For a tagged type, there is a declaration for each stream attribute
10010 -- at the freeze point, and we must generate only a completion of this
10011 -- declaration. We do the same for private types, because the full view
10012 -- might be tagged. Otherwise we generate a declaration at the point of
10013 -- the attribute definition clause.
10015 function Build_Spec
return Node_Id
;
10016 -- Used for declaration and renaming declaration, so that this is
10017 -- treated as a renaming_as_body.
10023 function Build_Spec
return Node_Id
is
10024 Out_P
: constant Boolean := (Nam
= TSS_Stream_Read
);
10027 T_Ref
: constant Node_Id
:= New_Reference_To
(Etyp
, Loc
);
10030 Subp_Id
:= Make_Defining_Identifier
(Loc
, Sname
);
10032 -- S : access Root_Stream_Type'Class
10034 Formals
:= New_List
(
10035 Make_Parameter_Specification
(Loc
,
10036 Defining_Identifier
=>
10037 Make_Defining_Identifier
(Loc
, Name_S
),
10039 Make_Access_Definition
(Loc
,
10042 Designated_Type
(Etype
(F
)), Loc
))));
10044 if Nam
= TSS_Stream_Input
then
10046 Make_Function_Specification
(Loc
,
10047 Defining_Unit_Name
=> Subp_Id
,
10048 Parameter_Specifications
=> Formals
,
10049 Result_Definition
=> T_Ref
);
10053 Append_To
(Formals
,
10054 Make_Parameter_Specification
(Loc
,
10055 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_V
),
10056 Out_Present
=> Out_P
,
10057 Parameter_Type
=> T_Ref
));
10060 Make_Procedure_Specification
(Loc
,
10061 Defining_Unit_Name
=> Subp_Id
,
10062 Parameter_Specifications
=> Formals
);
10068 -- Start of processing for New_Stream_Subprogram
10071 F
:= First_Formal
(Subp
);
10073 if Ekind
(Subp
) = E_Procedure
then
10074 Etyp
:= Etype
(Next_Formal
(F
));
10076 Etyp
:= Etype
(Subp
);
10079 -- Prepare subprogram declaration and insert it as an action on the
10080 -- clause node. The visibility for this entity is used to test for
10081 -- visibility of the attribute definition clause (in the sense of
10082 -- 8.3(23) as amended by AI-195).
10084 if not Defer_Declaration
then
10086 Make_Subprogram_Declaration
(Loc
,
10087 Specification
=> Build_Spec
);
10089 -- For a tagged type, there is always a visible declaration for each
10090 -- stream TSS (it is a predefined primitive operation), and the
10091 -- completion of this declaration occurs at the freeze point, which is
10092 -- not always visible at places where the attribute definition clause is
10093 -- visible. So, we create a dummy entity here for the purpose of
10094 -- tracking the visibility of the attribute definition clause itself.
10098 Make_Defining_Identifier
(Loc
, New_External_Name
(Sname
, 'V'));
10100 Make_Object_Declaration
(Loc
,
10101 Defining_Identifier
=> Subp_Id
,
10102 Object_Definition
=> New_Occurrence_Of
(Standard_Boolean
, Loc
));
10105 Insert_Action
(N
, Subp_Decl
);
10106 Set_Entity
(N
, Subp_Id
);
10109 Make_Subprogram_Renaming_Declaration
(Loc
,
10110 Specification
=> Build_Spec
,
10111 Name
=> New_Reference_To
(Subp
, Loc
));
10113 if Defer_Declaration
then
10114 Set_TSS
(Base_Type
(Ent
), Subp_Id
);
10116 Insert_Action
(N
, Subp_Decl
);
10117 Copy_TSS
(Subp_Id
, Base_Type
(Ent
));
10119 end New_Stream_Subprogram
;
10121 ------------------------
10122 -- Rep_Item_Too_Early --
10123 ------------------------
10125 function Rep_Item_Too_Early
(T
: Entity_Id
; N
: Node_Id
) return Boolean is
10127 -- Cannot apply non-operational rep items to generic types
10129 if Is_Operational_Item
(N
) then
10133 and then Is_Generic_Type
(Root_Type
(T
))
10135 Error_Msg_N
("representation item not allowed for generic type", N
);
10139 -- Otherwise check for incomplete type
10141 if Is_Incomplete_Or_Private_Type
(T
)
10142 and then No
(Underlying_Type
(T
))
10144 (Nkind
(N
) /= N_Pragma
10145 or else Get_Pragma_Id
(N
) /= Pragma_Import
)
10148 ("representation item must be after full type declaration", N
);
10151 -- If the type has incomplete components, a representation clause is
10152 -- illegal but stream attributes and Convention pragmas are correct.
10154 elsif Has_Private_Component
(T
) then
10155 if Nkind
(N
) = N_Pragma
then
10160 ("representation item must appear after type is fully defined",
10167 end Rep_Item_Too_Early
;
10169 -----------------------
10170 -- Rep_Item_Too_Late --
10171 -----------------------
10173 function Rep_Item_Too_Late
10176 FOnly
: Boolean := False) return Boolean
10179 Parent_Type
: Entity_Id
;
10181 procedure Too_Late
;
10182 -- Output the too late message. Note that this is not considered a
10183 -- serious error, since the effect is simply that we ignore the
10184 -- representation clause in this case.
10190 procedure Too_Late
is
10192 -- Other compilers seem more relaxed about rep items appearing too
10193 -- late. Since analysis tools typically don't care about rep items
10194 -- anyway, no reason to be too strict about this.
10196 if not Relaxed_RM_Semantics
then
10197 Error_Msg_N
("|representation item appears too late!", N
);
10201 -- Start of processing for Rep_Item_Too_Late
10204 -- First make sure entity is not frozen (RM 13.1(9))
10208 -- Exclude imported types, which may be frozen if they appear in a
10209 -- representation clause for a local type.
10211 and then not From_Limited_With
(T
)
10213 -- Exclude generated entities (not coming from source). The common
10214 -- case is when we generate a renaming which prematurely freezes the
10215 -- renamed internal entity, but we still want to be able to set copies
10216 -- of attribute values such as Size/Alignment.
10218 and then Comes_From_Source
(T
)
10221 S
:= First_Subtype
(T
);
10223 if Present
(Freeze_Node
(S
)) then
10225 ("??no more representation items for }", Freeze_Node
(S
), S
);
10230 -- Check for case of non-tagged derived type whose parent either has
10231 -- primitive operations, or is a by reference type (RM 13.1(10)).
10235 and then Is_Derived_Type
(T
)
10236 and then not Is_Tagged_Type
(T
)
10238 Parent_Type
:= Etype
(Base_Type
(T
));
10240 if Has_Primitive_Operations
(Parent_Type
) then
10243 ("primitive operations already defined for&!", N
, Parent_Type
);
10246 elsif Is_By_Reference_Type
(Parent_Type
) then
10249 ("parent type & is a by reference type!", N
, Parent_Type
);
10254 -- No error, link item into head of chain of rep items for the entity,
10255 -- but avoid chaining if we have an overloadable entity, and the pragma
10256 -- is one that can apply to multiple overloaded entities.
10258 if Is_Overloadable
(T
) and then Nkind
(N
) = N_Pragma
then
10260 Pname
: constant Name_Id
:= Pragma_Name
(N
);
10262 if Nam_In
(Pname
, Name_Convention
, Name_Import
, Name_Export
,
10263 Name_External
, Name_Interface
)
10270 Record_Rep_Item
(T
, N
);
10272 end Rep_Item_Too_Late
;
10274 -------------------------------------
10275 -- Replace_Type_References_Generic --
10276 -------------------------------------
10278 procedure Replace_Type_References_Generic
(N
: Node_Id
; TName
: Name_Id
) is
10280 function Replace_Node
(N
: Node_Id
) return Traverse_Result
;
10281 -- Processes a single node in the traversal procedure below, checking
10282 -- if node N should be replaced, and if so, doing the replacement.
10284 procedure Replace_Type_Refs
is new Traverse_Proc
(Replace_Node
);
10285 -- This instantiation provides the body of Replace_Type_References
10291 function Replace_Node
(N
: Node_Id
) return Traverse_Result
is
10296 -- Case of identifier
10298 if Nkind
(N
) = N_Identifier
then
10300 -- If not the type name, all done with this node
10302 if Chars
(N
) /= TName
then
10305 -- Otherwise do the replacement and we are done with this node
10308 Replace_Type_Reference
(N
);
10312 -- Case of selected component (which is what a qualification
10313 -- looks like in the unanalyzed tree, which is what we have.
10315 elsif Nkind
(N
) = N_Selected_Component
then
10317 -- If selector name is not our type, keeping going (we might
10318 -- still have an occurrence of the type in the prefix).
10320 if Nkind
(Selector_Name
(N
)) /= N_Identifier
10321 or else Chars
(Selector_Name
(N
)) /= TName
10325 -- Selector name is our type, check qualification
10328 -- Loop through scopes and prefixes, doing comparison
10330 S
:= Current_Scope
;
10333 -- Continue if no more scopes or scope with no name
10335 if No
(S
) or else Nkind
(S
) not in N_Has_Chars
then
10339 -- Do replace if prefix is an identifier matching the
10340 -- scope that we are currently looking at.
10342 if Nkind
(P
) = N_Identifier
10343 and then Chars
(P
) = Chars
(S
)
10345 Replace_Type_Reference
(N
);
10349 -- Go check scope above us if prefix is itself of the
10350 -- form of a selected component, whose selector matches
10351 -- the scope we are currently looking at.
10353 if Nkind
(P
) = N_Selected_Component
10354 and then Nkind
(Selector_Name
(P
)) = N_Identifier
10355 and then Chars
(Selector_Name
(P
)) = Chars
(S
)
10360 -- For anything else, we don't have a match, so keep on
10361 -- going, there are still some weird cases where we may
10362 -- still have a replacement within the prefix.
10370 -- Continue for any other node kind
10378 Replace_Type_Refs
(N
);
10379 end Replace_Type_References_Generic
;
10381 -------------------------
10382 -- Same_Representation --
10383 -------------------------
10385 function Same_Representation
(Typ1
, Typ2
: Entity_Id
) return Boolean is
10386 T1
: constant Entity_Id
:= Underlying_Type
(Typ1
);
10387 T2
: constant Entity_Id
:= Underlying_Type
(Typ2
);
10390 -- A quick check, if base types are the same, then we definitely have
10391 -- the same representation, because the subtype specific representation
10392 -- attributes (Size and Alignment) do not affect representation from
10393 -- the point of view of this test.
10395 if Base_Type
(T1
) = Base_Type
(T2
) then
10398 elsif Is_Private_Type
(Base_Type
(T2
))
10399 and then Base_Type
(T1
) = Full_View
(Base_Type
(T2
))
10404 -- Tagged types never have differing representations
10406 if Is_Tagged_Type
(T1
) then
10410 -- Representations are definitely different if conventions differ
10412 if Convention
(T1
) /= Convention
(T2
) then
10416 -- Representations are different if component alignments or scalar
10417 -- storage orders differ.
10419 if (Is_Record_Type
(T1
) or else Is_Array_Type
(T1
))
10421 (Is_Record_Type
(T2
) or else Is_Array_Type
(T2
))
10423 (Component_Alignment
(T1
) /= Component_Alignment
(T2
)
10425 Reverse_Storage_Order
(T1
) /= Reverse_Storage_Order
(T2
))
10430 -- For arrays, the only real issue is component size. If we know the
10431 -- component size for both arrays, and it is the same, then that's
10432 -- good enough to know we don't have a change of representation.
10434 if Is_Array_Type
(T1
) then
10435 if Known_Component_Size
(T1
)
10436 and then Known_Component_Size
(T2
)
10437 and then Component_Size
(T1
) = Component_Size
(T2
)
10439 if VM_Target
= No_VM
then
10442 -- In VM targets the representation of arrays with aliased
10443 -- components differs from arrays with non-aliased components
10446 return Has_Aliased_Components
(Base_Type
(T1
))
10448 Has_Aliased_Components
(Base_Type
(T2
));
10453 -- Types definitely have same representation if neither has non-standard
10454 -- representation since default representations are always consistent.
10455 -- If only one has non-standard representation, and the other does not,
10456 -- then we consider that they do not have the same representation. They
10457 -- might, but there is no way of telling early enough.
10459 if Has_Non_Standard_Rep
(T1
) then
10460 if not Has_Non_Standard_Rep
(T2
) then
10464 return not Has_Non_Standard_Rep
(T2
);
10467 -- Here the two types both have non-standard representation, and we need
10468 -- to determine if they have the same non-standard representation.
10470 -- For arrays, we simply need to test if the component sizes are the
10471 -- same. Pragma Pack is reflected in modified component sizes, so this
10472 -- check also deals with pragma Pack.
10474 if Is_Array_Type
(T1
) then
10475 return Component_Size
(T1
) = Component_Size
(T2
);
10477 -- Tagged types always have the same representation, because it is not
10478 -- possible to specify different representations for common fields.
10480 elsif Is_Tagged_Type
(T1
) then
10483 -- Case of record types
10485 elsif Is_Record_Type
(T1
) then
10487 -- Packed status must conform
10489 if Is_Packed
(T1
) /= Is_Packed
(T2
) then
10492 -- Otherwise we must check components. Typ2 maybe a constrained
10493 -- subtype with fewer components, so we compare the components
10494 -- of the base types.
10497 Record_Case
: declare
10498 CD1
, CD2
: Entity_Id
;
10500 function Same_Rep
return Boolean;
10501 -- CD1 and CD2 are either components or discriminants. This
10502 -- function tests whether they have the same representation.
10508 function Same_Rep
return Boolean is
10510 if No
(Component_Clause
(CD1
)) then
10511 return No
(Component_Clause
(CD2
));
10513 -- Note: at this point, component clauses have been
10514 -- normalized to the default bit order, so that the
10515 -- comparison of Component_Bit_Offsets is meaningful.
10518 Present
(Component_Clause
(CD2
))
10520 Component_Bit_Offset
(CD1
) = Component_Bit_Offset
(CD2
)
10522 Esize
(CD1
) = Esize
(CD2
);
10526 -- Start of processing for Record_Case
10529 if Has_Discriminants
(T1
) then
10531 -- The number of discriminants may be different if the
10532 -- derived type has fewer (constrained by values). The
10533 -- invisible discriminants retain the representation of
10534 -- the original, so the discrepancy does not per se
10535 -- indicate a different representation.
10537 CD1
:= First_Discriminant
(T1
);
10538 CD2
:= First_Discriminant
(T2
);
10539 while Present
(CD1
) and then Present
(CD2
) loop
10540 if not Same_Rep
then
10543 Next_Discriminant
(CD1
);
10544 Next_Discriminant
(CD2
);
10549 CD1
:= First_Component
(Underlying_Type
(Base_Type
(T1
)));
10550 CD2
:= First_Component
(Underlying_Type
(Base_Type
(T2
)));
10551 while Present
(CD1
) loop
10552 if not Same_Rep
then
10555 Next_Component
(CD1
);
10556 Next_Component
(CD2
);
10564 -- For enumeration types, we must check each literal to see if the
10565 -- representation is the same. Note that we do not permit enumeration
10566 -- representation clauses for Character and Wide_Character, so these
10567 -- cases were already dealt with.
10569 elsif Is_Enumeration_Type
(T1
) then
10570 Enumeration_Case
: declare
10571 L1
, L2
: Entity_Id
;
10574 L1
:= First_Literal
(T1
);
10575 L2
:= First_Literal
(T2
);
10576 while Present
(L1
) loop
10577 if Enumeration_Rep
(L1
) /= Enumeration_Rep
(L2
) then
10586 end Enumeration_Case
;
10588 -- Any other types have the same representation for these purposes
10593 end Same_Representation
;
10599 procedure Set_Biased
10603 Biased
: Boolean := True)
10607 Set_Has_Biased_Representation
(E
);
10609 if Warn_On_Biased_Representation
then
10611 ("?B?" & Msg
& " forces biased representation for&", N
, E
);
10616 --------------------
10617 -- Set_Enum_Esize --
10618 --------------------
10620 procedure Set_Enum_Esize
(T
: Entity_Id
) is
10626 Init_Alignment
(T
);
10628 -- Find the minimum standard size (8,16,32,64) that fits
10630 Lo
:= Enumeration_Rep
(Entity
(Type_Low_Bound
(T
)));
10631 Hi
:= Enumeration_Rep
(Entity
(Type_High_Bound
(T
)));
10634 if Lo
>= -Uint_2
**07 and then Hi
< Uint_2
**07 then
10635 Sz
:= Standard_Character_Size
; -- May be > 8 on some targets
10637 elsif Lo
>= -Uint_2
**15 and then Hi
< Uint_2
**15 then
10640 elsif Lo
>= -Uint_2
**31 and then Hi
< Uint_2
**31 then
10643 else pragma Assert
(Lo
>= -Uint_2
**63 and then Hi
< Uint_2
**63);
10648 if Hi
< Uint_2
**08 then
10649 Sz
:= Standard_Character_Size
; -- May be > 8 on some targets
10651 elsif Hi
< Uint_2
**16 then
10654 elsif Hi
< Uint_2
**32 then
10657 else pragma Assert
(Hi
< Uint_2
**63);
10662 -- That minimum is the proper size unless we have a foreign convention
10663 -- and the size required is 32 or less, in which case we bump the size
10664 -- up to 32. This is required for C and C++ and seems reasonable for
10665 -- all other foreign conventions.
10667 if Has_Foreign_Convention
(T
)
10668 and then Esize
(T
) < Standard_Integer_Size
10670 Init_Esize
(T
, Standard_Integer_Size
);
10672 Init_Esize
(T
, Sz
);
10674 end Set_Enum_Esize
;
10676 ------------------------------
10677 -- Validate_Address_Clauses --
10678 ------------------------------
10680 procedure Validate_Address_Clauses
is
10682 for J
in Address_Clause_Checks
.First
.. Address_Clause_Checks
.Last
loop
10684 ACCR
: Address_Clause_Check_Record
10685 renames Address_Clause_Checks
.Table
(J
);
10689 X_Alignment
: Uint
;
10690 Y_Alignment
: Uint
;
10696 -- Skip processing of this entry if warning already posted
10698 if not Address_Warning_Posted
(ACCR
.N
) then
10699 Expr
:= Original_Node
(Expression
(ACCR
.N
));
10703 X_Alignment
:= Alignment
(ACCR
.X
);
10704 Y_Alignment
:= Alignment
(ACCR
.Y
);
10706 -- Similarly obtain sizes
10708 X_Size
:= Esize
(ACCR
.X
);
10709 Y_Size
:= Esize
(ACCR
.Y
);
10711 -- Check for large object overlaying smaller one
10714 and then X_Size
> Uint_0
10715 and then X_Size
> Y_Size
10718 ("?& overlays smaller object", ACCR
.N
, ACCR
.X
);
10720 ("\??program execution may be erroneous", ACCR
.N
);
10721 Error_Msg_Uint_1
:= X_Size
;
10723 ("\??size of & is ^", ACCR
.N
, ACCR
.X
);
10724 Error_Msg_Uint_1
:= Y_Size
;
10726 ("\??size of & is ^", ACCR
.N
, ACCR
.Y
);
10728 -- Check for inadequate alignment, both of the base object
10729 -- and of the offset, if any.
10731 -- Note: we do not check the alignment if we gave a size
10732 -- warning, since it would likely be redundant.
10734 elsif Y_Alignment
/= Uint_0
10735 and then (Y_Alignment
< X_Alignment
10738 Nkind
(Expr
) = N_Attribute_Reference
10740 Attribute_Name
(Expr
) = Name_Address
10742 Has_Compatible_Alignment
10743 (ACCR
.X
, Prefix
(Expr
))
10744 /= Known_Compatible
))
10747 ("??specified address for& may be inconsistent "
10748 & "with alignment", ACCR
.N
, ACCR
.X
);
10750 ("\??program execution may be erroneous (RM 13.3(27))",
10752 Error_Msg_Uint_1
:= X_Alignment
;
10754 ("\??alignment of & is ^", ACCR
.N
, ACCR
.X
);
10755 Error_Msg_Uint_1
:= Y_Alignment
;
10757 ("\??alignment of & is ^", ACCR
.N
, ACCR
.Y
);
10758 if Y_Alignment
>= X_Alignment
then
10760 ("\??but offset is not multiple of alignment", ACCR
.N
);
10766 end Validate_Address_Clauses
;
10768 ---------------------------
10769 -- Validate_Independence --
10770 ---------------------------
10772 procedure Validate_Independence
is
10773 SU
: constant Uint
:= UI_From_Int
(System_Storage_Unit
);
10781 procedure Check_Array_Type
(Atyp
: Entity_Id
);
10782 -- Checks if the array type Atyp has independent components, and
10783 -- if not, outputs an appropriate set of error messages.
10785 procedure No_Independence
;
10786 -- Output message that independence cannot be guaranteed
10788 function OK_Component
(C
: Entity_Id
) return Boolean;
10789 -- Checks one component to see if it is independently accessible, and
10790 -- if so yields True, otherwise yields False if independent access
10791 -- cannot be guaranteed. This is a conservative routine, it only
10792 -- returns True if it knows for sure, it returns False if it knows
10793 -- there is a problem, or it cannot be sure there is no problem.
10795 procedure Reason_Bad_Component
(C
: Entity_Id
);
10796 -- Outputs continuation message if a reason can be determined for
10797 -- the component C being bad.
10799 ----------------------
10800 -- Check_Array_Type --
10801 ----------------------
10803 procedure Check_Array_Type
(Atyp
: Entity_Id
) is
10804 Ctyp
: constant Entity_Id
:= Component_Type
(Atyp
);
10807 -- OK if no alignment clause, no pack, and no component size
10809 if not Has_Component_Size_Clause
(Atyp
)
10810 and then not Has_Alignment_Clause
(Atyp
)
10811 and then not Is_Packed
(Atyp
)
10816 -- Check actual component size
10818 if not Known_Component_Size
(Atyp
)
10819 or else not (Addressable
(Component_Size
(Atyp
))
10820 and then Component_Size
(Atyp
) < 64)
10821 or else Component_Size
(Atyp
) mod Esize
(Ctyp
) /= 0
10825 -- Bad component size, check reason
10827 if Has_Component_Size_Clause
(Atyp
) then
10828 P
:= Get_Attribute_Definition_Clause
10829 (Atyp
, Attribute_Component_Size
);
10831 if Present
(P
) then
10832 Error_Msg_Sloc
:= Sloc
(P
);
10833 Error_Msg_N
("\because of Component_Size clause#", N
);
10838 if Is_Packed
(Atyp
) then
10839 P
:= Get_Rep_Pragma
(Atyp
, Name_Pack
);
10841 if Present
(P
) then
10842 Error_Msg_Sloc
:= Sloc
(P
);
10843 Error_Msg_N
("\because of pragma Pack#", N
);
10848 -- No reason found, just return
10853 -- Array type is OK independence-wise
10856 end Check_Array_Type
;
10858 ---------------------
10859 -- No_Independence --
10860 ---------------------
10862 procedure No_Independence
is
10864 if Pragma_Name
(N
) = Name_Independent
then
10865 Error_Msg_NE
("independence cannot be guaranteed for&", N
, E
);
10868 ("independent components cannot be guaranteed for&", N
, E
);
10870 end No_Independence
;
10876 function OK_Component
(C
: Entity_Id
) return Boolean is
10877 Rec
: constant Entity_Id
:= Scope
(C
);
10878 Ctyp
: constant Entity_Id
:= Etype
(C
);
10881 -- OK if no component clause, no Pack, and no alignment clause
10883 if No
(Component_Clause
(C
))
10884 and then not Is_Packed
(Rec
)
10885 and then not Has_Alignment_Clause
(Rec
)
10890 -- Here we look at the actual component layout. A component is
10891 -- addressable if its size is a multiple of the Esize of the
10892 -- component type, and its starting position in the record has
10893 -- appropriate alignment, and the record itself has appropriate
10894 -- alignment to guarantee the component alignment.
10896 -- Make sure sizes are static, always assume the worst for any
10897 -- cases where we cannot check static values.
10899 if not (Known_Static_Esize
(C
)
10901 Known_Static_Esize
(Ctyp
))
10906 -- Size of component must be addressable or greater than 64 bits
10907 -- and a multiple of bytes.
10909 if not Addressable
(Esize
(C
)) and then Esize
(C
) < Uint_64
then
10913 -- Check size is proper multiple
10915 if Esize
(C
) mod Esize
(Ctyp
) /= 0 then
10919 -- Check alignment of component is OK
10921 if not Known_Component_Bit_Offset
(C
)
10922 or else Component_Bit_Offset
(C
) < Uint_0
10923 or else Component_Bit_Offset
(C
) mod Esize
(Ctyp
) /= 0
10928 -- Check alignment of record type is OK
10930 if not Known_Alignment
(Rec
)
10931 or else (Alignment
(Rec
) * SU
) mod Esize
(Ctyp
) /= 0
10936 -- All tests passed, component is addressable
10941 --------------------------
10942 -- Reason_Bad_Component --
10943 --------------------------
10945 procedure Reason_Bad_Component
(C
: Entity_Id
) is
10946 Rec
: constant Entity_Id
:= Scope
(C
);
10947 Ctyp
: constant Entity_Id
:= Etype
(C
);
10950 -- If component clause present assume that's the problem
10952 if Present
(Component_Clause
(C
)) then
10953 Error_Msg_Sloc
:= Sloc
(Component_Clause
(C
));
10954 Error_Msg_N
("\because of Component_Clause#", N
);
10958 -- If pragma Pack clause present, assume that's the problem
10960 if Is_Packed
(Rec
) then
10961 P
:= Get_Rep_Pragma
(Rec
, Name_Pack
);
10963 if Present
(P
) then
10964 Error_Msg_Sloc
:= Sloc
(P
);
10965 Error_Msg_N
("\because of pragma Pack#", N
);
10970 -- See if record has bad alignment clause
10972 if Has_Alignment_Clause
(Rec
)
10973 and then Known_Alignment
(Rec
)
10974 and then (Alignment
(Rec
) * SU
) mod Esize
(Ctyp
) /= 0
10976 P
:= Get_Attribute_Definition_Clause
(Rec
, Attribute_Alignment
);
10978 if Present
(P
) then
10979 Error_Msg_Sloc
:= Sloc
(P
);
10980 Error_Msg_N
("\because of Alignment clause#", N
);
10984 -- Couldn't find a reason, so return without a message
10987 end Reason_Bad_Component
;
10989 -- Start of processing for Validate_Independence
10992 for J
in Independence_Checks
.First
.. Independence_Checks
.Last
loop
10993 N
:= Independence_Checks
.Table
(J
).N
;
10994 E
:= Independence_Checks
.Table
(J
).E
;
10995 IC
:= Pragma_Name
(N
) = Name_Independent_Components
;
10997 -- Deal with component case
10999 if Ekind
(E
) = E_Discriminant
or else Ekind
(E
) = E_Component
then
11000 if not OK_Component
(E
) then
11002 Reason_Bad_Component
(E
);
11007 -- Deal with record with Independent_Components
11009 if IC
and then Is_Record_Type
(E
) then
11010 Comp
:= First_Component_Or_Discriminant
(E
);
11011 while Present
(Comp
) loop
11012 if not OK_Component
(Comp
) then
11014 Reason_Bad_Component
(Comp
);
11018 Next_Component_Or_Discriminant
(Comp
);
11022 -- Deal with address clause case
11024 if Is_Object
(E
) then
11025 Addr
:= Address_Clause
(E
);
11027 if Present
(Addr
) then
11029 Error_Msg_Sloc
:= Sloc
(Addr
);
11030 Error_Msg_N
("\because of Address clause#", N
);
11035 -- Deal with independent components for array type
11037 if IC
and then Is_Array_Type
(E
) then
11038 Check_Array_Type
(E
);
11041 -- Deal with independent components for array object
11043 if IC
and then Is_Object
(E
) and then Is_Array_Type
(Etype
(E
)) then
11044 Check_Array_Type
(Etype
(E
));
11049 end Validate_Independence
;
11051 -----------------------------------
11052 -- Validate_Unchecked_Conversion --
11053 -----------------------------------
11055 procedure Validate_Unchecked_Conversion
11057 Act_Unit
: Entity_Id
)
11059 Source
: Entity_Id
;
11060 Target
: Entity_Id
;
11064 -- Obtain source and target types. Note that we call Ancestor_Subtype
11065 -- here because the processing for generic instantiation always makes
11066 -- subtypes, and we want the original frozen actual types.
11068 -- If we are dealing with private types, then do the check on their
11069 -- fully declared counterparts if the full declarations have been
11070 -- encountered (they don't have to be visible, but they must exist!)
11072 Source
:= Ancestor_Subtype
(Etype
(First_Formal
(Act_Unit
)));
11074 if Is_Private_Type
(Source
)
11075 and then Present
(Underlying_Type
(Source
))
11077 Source
:= Underlying_Type
(Source
);
11080 Target
:= Ancestor_Subtype
(Etype
(Act_Unit
));
11082 -- If either type is generic, the instantiation happens within a generic
11083 -- unit, and there is nothing to check. The proper check will happen
11084 -- when the enclosing generic is instantiated.
11086 if Is_Generic_Type
(Source
) or else Is_Generic_Type
(Target
) then
11090 if Is_Private_Type
(Target
)
11091 and then Present
(Underlying_Type
(Target
))
11093 Target
:= Underlying_Type
(Target
);
11096 -- Source may be unconstrained array, but not target
11098 if Is_Array_Type
(Target
) and then not Is_Constrained
(Target
) then
11100 ("unchecked conversion to unconstrained array not allowed", N
);
11104 -- Warn if conversion between two different convention pointers
11106 if Is_Access_Type
(Target
)
11107 and then Is_Access_Type
(Source
)
11108 and then Convention
(Target
) /= Convention
(Source
)
11109 and then Warn_On_Unchecked_Conversion
11111 -- Give warnings for subprogram pointers only on most targets. The
11112 -- exception is VMS, where data pointers can have different lengths
11113 -- depending on the pointer convention.
11115 if Is_Access_Subprogram_Type
(Target
)
11116 or else Is_Access_Subprogram_Type
(Source
)
11117 or else OpenVMS_On_Target
11120 ("?z?conversion between pointers with different conventions!",
11125 -- Warn if one of the operands is Ada.Calendar.Time. Do not emit a
11126 -- warning when compiling GNAT-related sources.
11128 if Warn_On_Unchecked_Conversion
11129 and then not In_Predefined_Unit
(N
)
11130 and then RTU_Loaded
(Ada_Calendar
)
11132 (Chars
(Source
) = Name_Time
11134 Chars
(Target
) = Name_Time
)
11136 -- If Ada.Calendar is loaded and the name of one of the operands is
11137 -- Time, there is a good chance that this is Ada.Calendar.Time.
11140 Calendar_Time
: constant Entity_Id
:=
11141 Full_View
(RTE
(RO_CA_Time
));
11143 pragma Assert
(Present
(Calendar_Time
));
11145 if Source
= Calendar_Time
or else Target
= Calendar_Time
then
11147 ("?z?representation of 'Time values may change between " &
11148 "'G'N'A'T versions", N
);
11153 -- Make entry in unchecked conversion table for later processing by
11154 -- Validate_Unchecked_Conversions, which will check sizes and alignments
11155 -- (using values set by the back-end where possible). This is only done
11156 -- if the appropriate warning is active.
11158 if Warn_On_Unchecked_Conversion
then
11159 Unchecked_Conversions
.Append
11160 (New_Val
=> UC_Entry
'(Eloc => Sloc (N),
11162 Target => Target));
11164 -- If both sizes are known statically now, then back end annotation
11165 -- is not required to do a proper check but if either size is not
11166 -- known statically, then we need the annotation.
11168 if Known_Static_RM_Size (Source)
11170 Known_Static_RM_Size (Target)
11174 Back_Annotate_Rep_Info := True;
11178 -- If unchecked conversion to access type, and access type is declared
11179 -- in the same unit as the unchecked conversion, then set the flag
11180 -- No_Strict_Aliasing (no strict aliasing is implicit here)
11182 if Is_Access_Type (Target) and then
11183 In_Same_Source_Unit (Target, N)
11185 Set_No_Strict_Aliasing (Implementation_Base_Type (Target));
11188 -- Generate N_Validate_Unchecked_Conversion node for back end in case
11189 -- the back end needs to perform special validation checks.
11191 -- Shouldn't this be in Exp_Ch13, since the check only gets done if we
11192 -- have full expansion and the back end is called ???
11195 Make_Validate_Unchecked_Conversion (Sloc (N));
11196 Set_Source_Type (Vnode, Source);
11197 Set_Target_Type (Vnode, Target);
11199 -- If the unchecked conversion node is in a list, just insert before it.
11200 -- If not we have some strange case, not worth bothering about.
11202 if Is_List_Member (N) then
11203 Insert_After (N, Vnode);
11205 end Validate_Unchecked_Conversion;
11207 ------------------------------------
11208 -- Validate_Unchecked_Conversions --
11209 ------------------------------------
11211 procedure Validate_Unchecked_Conversions is
11213 for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop
11215 T : UC_Entry renames Unchecked_Conversions.Table (N);
11217 Eloc : constant Source_Ptr := T.Eloc;
11218 Source : constant Entity_Id := T.Source;
11219 Target : constant Entity_Id := T.Target;
11225 -- This validation check, which warns if we have unequal sizes for
11226 -- unchecked conversion, and thus potentially implementation
11227 -- dependent semantics, is one of the few occasions on which we
11228 -- use the official RM size instead of Esize. See description in
11229 -- Einfo "Handling of Type'Size Values" for details.
11231 if Serious_Errors_Detected = 0
11232 and then Known_Static_RM_Size (Source)
11233 and then Known_Static_RM_Size (Target)
11235 -- Don't do the check if warnings off for either type, note the
11236 -- deliberate use of OR here instead of OR ELSE to get the flag
11237 -- Warnings_Off_Used set for both types if appropriate.
11239 and then not (Has_Warnings_Off (Source)
11241 Has_Warnings_Off (Target))
11243 Source_Siz := RM_Size (Source);
11244 Target_Siz := RM_Size (Target);
11246 if Source_Siz /= Target_Siz then
11248 ("?z?types for unchecked conversion have different sizes!",
11251 if All_Errors_Mode then
11252 Error_Msg_Name_1 := Chars (Source);
11253 Error_Msg_Uint_1 := Source_Siz;
11254 Error_Msg_Name_2 := Chars (Target);
11255 Error_Msg_Uint_2 := Target_Siz;
11256 Error_Msg ("\size of % is ^, size of % is ^?z?", Eloc);
11258 Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz);
11260 if Is_Discrete_Type (Source)
11262 Is_Discrete_Type (Target)
11264 if Source_Siz > Target_Siz then
11266 ("\?z?^ high order bits of source will "
11267 & "be ignored!", Eloc);
11269 elsif Is_Unsigned_Type (Source) then
11271 ("\?z?source will be extended with ^ high order "
11272 & "zero bits?!", Eloc);
11276 ("\?z?source will be extended with ^ high order "
11277 & "sign bits!", Eloc);
11280 elsif Source_Siz < Target_Siz then
11281 if Is_Discrete_Type (Target) then
11282 if Bytes_Big_Endian then
11284 ("\?z?target value will include ^ undefined "
11285 & "low order bits!", Eloc);
11288 ("\?z?target value will include ^ undefined "
11289 & "high order bits!", Eloc);
11294 ("\?z?^ trailing bits of target value will be "
11295 & "undefined!", Eloc);
11298 else pragma Assert (Source_Siz > Target_Siz);
11300 ("\?z?^ trailing bits of source will be ignored!",
11307 -- If both types are access types, we need to check the alignment.
11308 -- If the alignment of both is specified, we can do it here.
11310 if Serious_Errors_Detected = 0
11311 and then Ekind (Source) in Access_Kind
11312 and then Ekind (Target) in Access_Kind
11313 and then Target_Strict_Alignment
11314 and then Present (Designated_Type (Source))
11315 and then Present (Designated_Type (Target))
11318 D_Source : constant Entity_Id := Designated_Type (Source);
11319 D_Target : constant Entity_Id := Designated_Type (Target);
11322 if Known_Alignment (D_Source)
11324 Known_Alignment (D_Target)
11327 Source_Align : constant Uint := Alignment (D_Source);
11328 Target_Align : constant Uint := Alignment (D_Target);
11331 if Source_Align < Target_Align
11332 and then not Is_Tagged_Type (D_Source)
11334 -- Suppress warning if warnings suppressed on either
11335 -- type or either designated type. Note the use of
11336 -- OR here instead of OR ELSE. That is intentional,
11337 -- we would like to set flag Warnings_Off_Used in
11338 -- all types for which warnings are suppressed.
11340 and then not (Has_Warnings_Off (D_Source)
11342 Has_Warnings_Off (D_Target)
11344 Has_Warnings_Off (Source)
11346 Has_Warnings_Off (Target))
11348 Error_Msg_Uint_1 := Target_Align;
11349 Error_Msg_Uint_2 := Source_Align;
11350 Error_Msg_Node_1 := D_Target;
11351 Error_Msg_Node_2 := D_Source;
11353 ("?z?alignment of & (^) is stricter than "
11354 & "alignment of & (^)!", Eloc);
11356 ("\?z?resulting access value may have invalid "
11357 & "alignment!", Eloc);
11365 end Validate_Unchecked_Conversions;