1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2014, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Aspects
; use Aspects
;
27 with Atree
; use Atree
;
28 with Checks
; use Checks
;
29 with Debug
; use Debug
;
30 with Einfo
; use Einfo
;
31 with Elists
; use Elists
;
32 with Errout
; use Errout
;
33 with Exp_Disp
; use Exp_Disp
;
34 with Exp_Tss
; use Exp_Tss
;
35 with Exp_Util
; use Exp_Util
;
36 with Freeze
; use Freeze
;
38 with Lib
.Xref
; use Lib
.Xref
;
39 with Namet
; use Namet
;
40 with Nlists
; use Nlists
;
41 with Nmake
; use Nmake
;
43 with Restrict
; use Restrict
;
44 with Rident
; use Rident
;
45 with Rtsfind
; use Rtsfind
;
47 with Sem_Aux
; use Sem_Aux
;
48 with Sem_Case
; use Sem_Case
;
49 with Sem_Ch3
; use Sem_Ch3
;
50 with Sem_Ch6
; use Sem_Ch6
;
51 with Sem_Ch8
; use Sem_Ch8
;
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_Discrete_Static_Predicate
92 -- Given a predicated type Typ, where Typ is a discrete static subtype,
93 -- whose predicate expression is Expr, tests if Expr is a static predicate,
94 -- and if so, builds the predicate range list. Nam is the name of the one
95 -- argument to the predicate function. Occurrences of the type name in the
96 -- predicate expression have been replaced by identifier references to this
97 -- name, which is unique, so any identifier with Chars matching Nam must be
98 -- a reference to the type. If the predicate is non-static, this procedure
99 -- returns doing nothing. If the predicate is static, then the predicate
100 -- list is stored in Static_Discrete_Predicate (Typ), and the Expr is
101 -- rewritten as a canonicalized membership operation.
103 procedure Build_Predicate_Functions
(Typ
: Entity_Id
; N
: Node_Id
);
104 -- If Typ has predicates (indicated by Has_Predicates being set for Typ),
105 -- then either there are pragma Predicate entries on the rep chain for the
106 -- type (note that Predicate aspects are converted to pragma Predicate), or
107 -- there are inherited aspects from a parent type, or ancestor subtypes.
108 -- This procedure builds the spec and body for the Predicate function that
109 -- tests these predicates. N is the freeze node for the type. The spec of
110 -- the function is inserted before the freeze node, and the body of the
111 -- function is inserted after the freeze node. If the predicate expression
112 -- has at least one Raise_Expression, then this procedure also builds the
113 -- M version of the predicate function for use in membership tests.
115 procedure Check_Pool_Size_Clash
(Ent
: Entity_Id
; SP
, SS
: Node_Id
);
116 -- Called if both Storage_Pool and Storage_Size attribute definition
117 -- clauses (SP and SS) are present for entity Ent. Issue error message.
119 procedure Freeze_Entity_Checks
(N
: Node_Id
);
120 -- Called from Analyze_Freeze_Entity and Analyze_Generic_Freeze Entity
121 -- to generate appropriate semantic checks that are delayed until this
122 -- point (they had to be delayed this long for cases of delayed aspects,
123 -- e.g. analysis of statically predicated subtypes in choices, for which
124 -- we have to be sure the subtypes in question are frozen before checking.
126 function Get_Alignment_Value
(Expr
: Node_Id
) return Uint
;
127 -- Given the expression for an alignment value, returns the corresponding
128 -- Uint value. If the value is inappropriate, then error messages are
129 -- posted as required, and a value of No_Uint is returned.
131 function Is_Operational_Item
(N
: Node_Id
) return Boolean;
132 -- A specification for a stream attribute is allowed before the full type
133 -- is declared, as explained in AI-00137 and the corrigendum. Attributes
134 -- that do not specify a representation characteristic are operational
137 function Is_Predicate_Static
139 Nam
: Name_Id
) return Boolean;
140 -- Given predicate expression Expr, tests if Expr is predicate-static in
141 -- the sense of the rules in (RM 3.2.4 (15-24)). Occurrences of the type
142 -- name in the predicate expression have been replaced by references to
143 -- an identifier whose Chars field is Nam. This name is unique, so any
144 -- identifier with Chars matching Nam must be a reference to the type.
145 -- Returns True if the expression is predicate-static and False otherwise,
146 -- but is not in the business of setting flags or issuing error messages.
148 -- Only scalar types can have static predicates, so False is always
149 -- returned for non-scalar types.
151 -- Note: the RM seems to suggest that string types can also have static
152 -- predicates. But that really makes lttle sense as very few useful
153 -- predicates can be constructed for strings. Remember that:
157 -- is not a static expression. So even though the clearly faulty RM wording
158 -- allows the following:
160 -- subtype S is String with Static_Predicate => S < "DEF"
162 -- We can't allow this, otherwise we have predicate-static applying to a
163 -- larger class than static expressions, which was never intended.
165 procedure New_Stream_Subprogram
169 Nam
: TSS_Name_Type
);
170 -- Create a subprogram renaming of a given stream attribute to the
171 -- designated subprogram and then in the tagged case, provide this as a
172 -- primitive operation, or in the untagged case make an appropriate TSS
173 -- entry. This is more properly an expansion activity than just semantics,
174 -- but the presence of user-defined stream functions for limited types
175 -- is a legality check, which is why this takes place here rather than in
176 -- exp_ch13, where it was previously. Nam indicates the name of the TSS
177 -- function to be generated.
179 -- To avoid elaboration anomalies with freeze nodes, for untagged types
180 -- we generate both a subprogram declaration and a subprogram renaming
181 -- declaration, so that the attribute specification is handled as a
182 -- renaming_as_body. For tagged types, the specification is one of the
185 procedure Resolve_Iterable_Operation
190 -- If the name of a primitive operation for an Iterable aspect is
191 -- overloaded, resolve according to required signature.
197 Biased
: Boolean := True);
198 -- If Biased is True, sets Has_Biased_Representation flag for E, and
199 -- outputs a warning message at node N if Warn_On_Biased_Representation is
200 -- is True. This warning inserts the string Msg to describe the construct
203 ----------------------------------------------
204 -- Table for Validate_Unchecked_Conversions --
205 ----------------------------------------------
207 -- The following table collects unchecked conversions for validation.
208 -- Entries are made by Validate_Unchecked_Conversion and then the call
209 -- to Validate_Unchecked_Conversions does the actual error checking and
210 -- posting of warnings. The reason for this delayed processing is to take
211 -- advantage of back-annotations of size and alignment values performed by
214 -- Note: the reason we store a Source_Ptr value instead of a Node_Id is
215 -- that by the time Validate_Unchecked_Conversions is called, Sprint will
216 -- already have modified all Sloc values if the -gnatD option is set.
218 type UC_Entry
is record
219 Eloc
: Source_Ptr
; -- node used for posting warnings
220 Source
: Entity_Id
; -- source type for unchecked conversion
221 Target
: Entity_Id
; -- target type for unchecked conversion
222 Act_Unit
: Entity_Id
; -- actual function instantiated
225 package Unchecked_Conversions
is new Table
.Table
(
226 Table_Component_Type
=> UC_Entry
,
227 Table_Index_Type
=> Int
,
228 Table_Low_Bound
=> 1,
230 Table_Increment
=> 200,
231 Table_Name
=> "Unchecked_Conversions");
233 ----------------------------------------
234 -- Table for Validate_Address_Clauses --
235 ----------------------------------------
237 -- If an address clause has the form
239 -- for X'Address use Expr
241 -- where Expr is of the form Y'Address or recursively is a reference to a
242 -- constant of either of these forms, and X and Y are entities of objects,
243 -- then if Y has a smaller alignment than X, that merits a warning about
244 -- possible bad alignment. The following table collects address clauses of
245 -- this kind. We put these in a table so that they can be checked after the
246 -- back end has completed annotation of the alignments of objects, since we
247 -- can catch more cases that way.
249 type Address_Clause_Check_Record
is record
251 -- The address clause
254 -- The entity of the object overlaying Y
257 -- The entity of the object being overlaid
260 -- Whether the address is offset within Y
263 package Address_Clause_Checks
is new Table
.Table
(
264 Table_Component_Type
=> Address_Clause_Check_Record
,
265 Table_Index_Type
=> Int
,
266 Table_Low_Bound
=> 1,
268 Table_Increment
=> 200,
269 Table_Name
=> "Address_Clause_Checks");
271 -----------------------------------------
272 -- Adjust_Record_For_Reverse_Bit_Order --
273 -----------------------------------------
275 procedure Adjust_Record_For_Reverse_Bit_Order
(R
: Entity_Id
) is
280 -- Processing depends on version of Ada
282 -- For Ada 95, we just renumber bits within a storage unit. We do the
283 -- same for Ada 83 mode, since we recognize the Bit_Order attribute in
284 -- Ada 83, and are free to add this extension.
286 if Ada_Version
< Ada_2005
then
287 Comp
:= First_Component_Or_Discriminant
(R
);
288 while Present
(Comp
) loop
289 CC
:= Component_Clause
(Comp
);
291 -- If component clause is present, then deal with the non-default
292 -- bit order case for Ada 95 mode.
294 -- We only do this processing for the base type, and in fact that
295 -- is important, since otherwise if there are record subtypes, we
296 -- could reverse the bits once for each subtype, which is wrong.
298 if Present
(CC
) and then Ekind
(R
) = E_Record_Type
then
300 CFB
: constant Uint
:= Component_Bit_Offset
(Comp
);
301 CSZ
: constant Uint
:= Esize
(Comp
);
302 CLC
: constant Node_Id
:= Component_Clause
(Comp
);
303 Pos
: constant Node_Id
:= Position
(CLC
);
304 FB
: constant Node_Id
:= First_Bit
(CLC
);
306 Storage_Unit_Offset
: constant Uint
:=
307 CFB
/ System_Storage_Unit
;
309 Start_Bit
: constant Uint
:=
310 CFB
mod System_Storage_Unit
;
313 -- Cases where field goes over storage unit boundary
315 if Start_Bit
+ CSZ
> System_Storage_Unit
then
317 -- Allow multi-byte field but generate warning
319 if Start_Bit
mod System_Storage_Unit
= 0
320 and then CSZ
mod System_Storage_Unit
= 0
323 ("info: multi-byte field specified with "
324 & "non-standard Bit_Order?V?", CLC
);
326 if Bytes_Big_Endian
then
328 ("\bytes are not reversed "
329 & "(component is big-endian)?V?", CLC
);
332 ("\bytes are not reversed "
333 & "(component is little-endian)?V?", CLC
);
336 -- Do not allow non-contiguous field
340 ("attempt to specify non-contiguous field "
341 & "not permitted", CLC
);
343 ("\caused by non-standard Bit_Order "
346 ("\consider possibility of using "
347 & "Ada 2005 mode here", CLC
);
350 -- Case where field fits in one storage unit
353 -- Give warning if suspicious component clause
355 if Intval
(FB
) >= System_Storage_Unit
356 and then Warn_On_Reverse_Bit_Order
359 ("info: Bit_Order clause does not affect " &
360 "byte ordering?V?", Pos
);
362 Intval
(Pos
) + Intval
(FB
) /
365 ("info: position normalized to ^ before bit " &
366 "order interpreted?V?", Pos
);
369 -- Here is where we fix up the Component_Bit_Offset value
370 -- to account for the reverse bit order. Some examples of
371 -- what needs to be done are:
373 -- First_Bit .. Last_Bit Component_Bit_Offset
385 -- The rule is that the first bit is is obtained by
386 -- subtracting the old ending bit from storage_unit - 1.
388 Set_Component_Bit_Offset
390 (Storage_Unit_Offset
* System_Storage_Unit
) +
391 (System_Storage_Unit
- 1) -
392 (Start_Bit
+ CSZ
- 1));
394 Set_Normalized_First_Bit
396 Component_Bit_Offset
(Comp
) mod
397 System_Storage_Unit
);
402 Next_Component_Or_Discriminant
(Comp
);
405 -- For Ada 2005, we do machine scalar processing, as fully described In
406 -- AI-133. This involves gathering all components which start at the
407 -- same byte offset and processing them together. Same approach is still
408 -- valid in later versions including Ada 2012.
412 Max_Machine_Scalar_Size
: constant Uint
:=
414 (Standard_Long_Long_Integer_Size
);
415 -- We use this as the maximum machine scalar size
418 SSU
: constant Uint
:= UI_From_Int
(System_Storage_Unit
);
421 -- This first loop through components does two things. First it
422 -- deals with the case of components with component clauses whose
423 -- length is greater than the maximum machine scalar size (either
424 -- accepting them or rejecting as needed). Second, it counts the
425 -- number of components with component clauses whose length does
426 -- not exceed this maximum for later processing.
429 Comp
:= First_Component_Or_Discriminant
(R
);
430 while Present
(Comp
) loop
431 CC
:= Component_Clause
(Comp
);
435 Fbit
: constant Uint
:= Static_Integer
(First_Bit
(CC
));
436 Lbit
: constant Uint
:= Static_Integer
(Last_Bit
(CC
));
439 -- Case of component with last bit >= max machine scalar
441 if Lbit
>= Max_Machine_Scalar_Size
then
443 -- This is allowed only if first bit is zero, and
444 -- last bit + 1 is a multiple of storage unit size.
446 if Fbit
= 0 and then (Lbit
+ 1) mod SSU
= 0 then
448 -- This is the case to give a warning if enabled
450 if Warn_On_Reverse_Bit_Order
then
452 ("info: multi-byte field specified with "
453 & " non-standard Bit_Order?V?", CC
);
455 if Bytes_Big_Endian
then
457 ("\bytes are not reversed "
458 & "(component is big-endian)?V?", CC
);
461 ("\bytes are not reversed "
462 & "(component is little-endian)?V?", CC
);
466 -- Give error message for RM 13.5.1(10) violation
470 ("machine scalar rules not followed for&",
471 First_Bit
(CC
), Comp
);
473 Error_Msg_Uint_1
:= Lbit
;
474 Error_Msg_Uint_2
:= Max_Machine_Scalar_Size
;
476 ("\last bit (^) exceeds maximum machine "
480 if (Lbit
+ 1) mod SSU
/= 0 then
481 Error_Msg_Uint_1
:= SSU
;
483 ("\and is not a multiple of Storage_Unit (^) "
488 Error_Msg_Uint_1
:= Fbit
;
490 ("\and first bit (^) is non-zero "
496 -- OK case of machine scalar related component clause,
497 -- For now, just count them.
500 Num_CC
:= Num_CC
+ 1;
505 Next_Component_Or_Discriminant
(Comp
);
508 -- We need to sort the component clauses on the basis of the
509 -- Position values in the clause, so we can group clauses with
510 -- the same Position together to determine the relevant machine
514 Comps
: array (0 .. Num_CC
) of Entity_Id
;
515 -- Array to collect component and discriminant entities. The
516 -- data starts at index 1, the 0'th entry is for the sort
519 function CP_Lt
(Op1
, Op2
: Natural) return Boolean;
520 -- Compare routine for Sort
522 procedure CP_Move
(From
: Natural; To
: Natural);
523 -- Move routine for Sort
525 package Sorting
is new GNAT
.Heap_Sort_G
(CP_Move
, CP_Lt
);
529 -- Start and stop positions in the component list of the set of
530 -- components with the same starting position (that constitute
531 -- components in a single machine scalar).
534 -- Maximum last bit value of any component in this set
537 -- Corresponding machine scalar size
543 function CP_Lt
(Op1
, Op2
: Natural) return Boolean is
545 return Position
(Component_Clause
(Comps
(Op1
))) <
546 Position
(Component_Clause
(Comps
(Op2
)));
553 procedure CP_Move
(From
: Natural; To
: Natural) is
555 Comps
(To
) := Comps
(From
);
558 -- Start of processing for Sort_CC
561 -- Collect the machine scalar relevant component clauses
564 Comp
:= First_Component_Or_Discriminant
(R
);
565 while Present
(Comp
) loop
567 CC
: constant Node_Id
:= Component_Clause
(Comp
);
570 -- Collect only component clauses whose last bit is less
571 -- than machine scalar size. Any component clause whose
572 -- last bit exceeds this value does not take part in
573 -- machine scalar layout considerations. The test for
574 -- Error_Posted makes sure we exclude component clauses
575 -- for which we already posted an error.
578 and then not Error_Posted
(Last_Bit
(CC
))
579 and then Static_Integer
(Last_Bit
(CC
)) <
580 Max_Machine_Scalar_Size
582 Num_CC
:= Num_CC
+ 1;
583 Comps
(Num_CC
) := Comp
;
587 Next_Component_Or_Discriminant
(Comp
);
590 -- Sort by ascending position number
592 Sorting
.Sort
(Num_CC
);
594 -- We now have all the components whose size does not exceed
595 -- the max machine scalar value, sorted by starting position.
596 -- In this loop we gather groups of clauses starting at the
597 -- same position, to process them in accordance with AI-133.
600 while Stop
< Num_CC
loop
605 (Last_Bit
(Component_Clause
(Comps
(Start
))));
606 while Stop
< Num_CC
loop
608 (Position
(Component_Clause
(Comps
(Stop
+ 1)))) =
610 (Position
(Component_Clause
(Comps
(Stop
))))
618 (Component_Clause
(Comps
(Stop
)))));
624 -- Now we have a group of component clauses from Start to
625 -- Stop whose positions are identical, and MaxL is the
626 -- maximum last bit value of any of these components.
628 -- We need to determine the corresponding machine scalar
629 -- size. This loop assumes that machine scalar sizes are
630 -- even, and that each possible machine scalar has twice
631 -- as many bits as the next smaller one.
633 MSS
:= Max_Machine_Scalar_Size
;
635 and then (MSS
/ 2) >= SSU
636 and then (MSS
/ 2) > MaxL
641 -- Here is where we fix up the Component_Bit_Offset value
642 -- to account for the reverse bit order. Some examples of
643 -- what needs to be done for the case of a machine scalar
646 -- First_Bit .. Last_Bit Component_Bit_Offset
658 -- The rule is that the first bit is obtained by subtracting
659 -- the old ending bit from machine scalar size - 1.
661 for C
in Start
.. Stop
loop
663 Comp
: constant Entity_Id
:= Comps
(C
);
664 CC
: constant Node_Id
:= Component_Clause
(Comp
);
666 LB
: constant Uint
:= Static_Integer
(Last_Bit
(CC
));
667 NFB
: constant Uint
:= MSS
- Uint_1
- LB
;
668 NLB
: constant Uint
:= NFB
+ Esize
(Comp
) - 1;
669 Pos
: constant Uint
:= Static_Integer
(Position
(CC
));
672 if Warn_On_Reverse_Bit_Order
then
673 Error_Msg_Uint_1
:= MSS
;
675 ("info: reverse bit order in machine " &
676 "scalar of length^?V?", First_Bit
(CC
));
677 Error_Msg_Uint_1
:= NFB
;
678 Error_Msg_Uint_2
:= NLB
;
680 if Bytes_Big_Endian
then
682 ("\big-endian range for component "
683 & "& is ^ .. ^?V?", First_Bit
(CC
), Comp
);
686 ("\little-endian range for component"
687 & "& is ^ .. ^?V?", First_Bit
(CC
), Comp
);
691 Set_Component_Bit_Offset
(Comp
, Pos
* SSU
+ NFB
);
692 Set_Normalized_First_Bit
(Comp
, NFB
mod SSU
);
699 end Adjust_Record_For_Reverse_Bit_Order
;
701 -------------------------------------
702 -- Alignment_Check_For_Size_Change --
703 -------------------------------------
705 procedure Alignment_Check_For_Size_Change
(Typ
: Entity_Id
; Size
: Uint
) is
707 -- If the alignment is known, and not set by a rep clause, and is
708 -- inconsistent with the size being set, then reset it to unknown,
709 -- we assume in this case that the size overrides the inherited
710 -- alignment, and that the alignment must be recomputed.
712 if Known_Alignment
(Typ
)
713 and then not Has_Alignment_Clause
(Typ
)
714 and then Size
mod (Alignment
(Typ
) * SSU
) /= 0
716 Init_Alignment
(Typ
);
718 end Alignment_Check_For_Size_Change
;
720 -------------------------------------
721 -- Analyze_Aspects_At_Freeze_Point --
722 -------------------------------------
724 procedure Analyze_Aspects_At_Freeze_Point
(E
: Entity_Id
) is
729 procedure Analyze_Aspect_Default_Value
(ASN
: Node_Id
);
730 -- This routine analyzes an Aspect_Default_[Component_]Value denoted by
731 -- the aspect specification node ASN.
733 procedure Inherit_Delayed_Rep_Aspects
(ASN
: Node_Id
);
734 -- As discussed in the spec of Aspects (see Aspect_Delay declaration),
735 -- a derived type can inherit aspects from its parent which have been
736 -- specified at the time of the derivation using an aspect, as in:
738 -- type A is range 1 .. 10
739 -- with Size => Not_Defined_Yet;
743 -- Not_Defined_Yet : constant := 64;
745 -- In this example, the Size of A is considered to be specified prior
746 -- to the derivation, and thus inherited, even though the value is not
747 -- known at the time of derivation. To deal with this, we use two entity
748 -- flags. The flag Has_Derived_Rep_Aspects is set in the parent type (A
749 -- here), and then the flag May_Inherit_Delayed_Rep_Aspects is set in
750 -- the derived type (B here). If this flag is set when the derived type
751 -- is frozen, then this procedure is called to ensure proper inheritance
752 -- of all delayed aspects from the parent type. The derived type is E,
753 -- the argument to Analyze_Aspects_At_Freeze_Point. ASN is the first
754 -- aspect specification node in the Rep_Item chain for the parent type.
756 procedure Make_Pragma_From_Boolean_Aspect
(ASN
: Node_Id
);
757 -- Given an aspect specification node ASN whose expression is an
758 -- optional Boolean, this routines creates the corresponding pragma
759 -- at the freezing point.
761 ----------------------------------
762 -- Analyze_Aspect_Default_Value --
763 ----------------------------------
765 procedure Analyze_Aspect_Default_Value
(ASN
: Node_Id
) is
766 Ent
: constant Entity_Id
:= Entity
(ASN
);
767 Expr
: constant Node_Id
:= Expression
(ASN
);
768 Id
: constant Node_Id
:= Identifier
(ASN
);
771 Error_Msg_Name_1
:= Chars
(Id
);
773 if not Is_Type
(Ent
) then
774 Error_Msg_N
("aspect% can only apply to a type", Id
);
777 elsif not Is_First_Subtype
(Ent
) then
778 Error_Msg_N
("aspect% cannot apply to subtype", Id
);
781 elsif A_Id
= Aspect_Default_Value
782 and then not Is_Scalar_Type
(Ent
)
784 Error_Msg_N
("aspect% can only be applied to scalar type", Id
);
787 elsif A_Id
= Aspect_Default_Component_Value
then
788 if not Is_Array_Type
(Ent
) then
789 Error_Msg_N
("aspect% can only be applied to array type", Id
);
792 elsif not Is_Scalar_Type
(Component_Type
(Ent
)) then
793 Error_Msg_N
("aspect% requires scalar components", Id
);
798 Set_Has_Default_Aspect
(Base_Type
(Ent
));
800 if Is_Scalar_Type
(Ent
) then
801 Set_Default_Aspect_Value
(Base_Type
(Ent
), Expr
);
803 Set_Default_Aspect_Component_Value
(Base_Type
(Ent
), Expr
);
805 end Analyze_Aspect_Default_Value
;
807 ---------------------------------
808 -- Inherit_Delayed_Rep_Aspects --
809 ---------------------------------
811 procedure Inherit_Delayed_Rep_Aspects
(ASN
: Node_Id
) is
812 P
: constant Entity_Id
:= Entity
(ASN
);
813 -- Entithy for parent type
816 -- Item from Rep_Item chain
821 -- Loop through delayed aspects for the parent type
824 while Present
(N
) loop
825 if Nkind
(N
) = N_Aspect_Specification
then
826 exit when Entity
(N
) /= P
;
828 if Is_Delayed_Aspect
(N
) then
829 A
:= Get_Aspect_Id
(Chars
(Identifier
(N
)));
831 -- Process delayed rep aspect. For Boolean attributes it is
832 -- not possible to cancel an attribute once set (the attempt
833 -- to use an aspect with xxx => False is an error) for a
834 -- derived type. So for those cases, we do not have to check
835 -- if a clause has been given for the derived type, since it
836 -- is harmless to set it again if it is already set.
842 when Aspect_Alignment
=>
843 if not Has_Alignment_Clause
(E
) then
844 Set_Alignment
(E
, Alignment
(P
));
849 when Aspect_Atomic
=>
850 if Is_Atomic
(P
) then
856 when Aspect_Atomic_Components
=>
857 if Has_Atomic_Components
(P
) then
858 Set_Has_Atomic_Components
(Base_Type
(E
));
863 when Aspect_Bit_Order
=>
864 if Is_Record_Type
(E
)
865 and then No
(Get_Attribute_Definition_Clause
866 (E
, Attribute_Bit_Order
))
867 and then Reverse_Bit_Order
(P
)
869 Set_Reverse_Bit_Order
(Base_Type
(E
));
874 when Aspect_Component_Size
=>
876 and then not Has_Component_Size_Clause
(E
)
879 (Base_Type
(E
), Component_Size
(P
));
884 when Aspect_Machine_Radix
=>
885 if Is_Decimal_Fixed_Point_Type
(E
)
886 and then not Has_Machine_Radix_Clause
(E
)
888 Set_Machine_Radix_10
(E
, Machine_Radix_10
(P
));
891 -- Object_Size (also Size which also sets Object_Size)
893 when Aspect_Object_Size | Aspect_Size
=>
894 if not Has_Size_Clause
(E
)
896 No
(Get_Attribute_Definition_Clause
897 (E
, Attribute_Object_Size
))
899 Set_Esize
(E
, Esize
(P
));
905 if not Is_Packed
(E
) then
906 Set_Is_Packed
(Base_Type
(E
));
908 if Is_Bit_Packed_Array
(P
) then
909 Set_Is_Bit_Packed_Array
(Base_Type
(E
));
910 Set_Packed_Array_Impl_Type
911 (E
, Packed_Array_Impl_Type
(P
));
915 -- Scalar_Storage_Order
917 when Aspect_Scalar_Storage_Order
=>
918 if (Is_Record_Type
(E
) or else Is_Array_Type
(E
))
919 and then No
(Get_Attribute_Definition_Clause
920 (E
, Attribute_Scalar_Storage_Order
))
921 and then Reverse_Storage_Order
(P
)
923 Set_Reverse_Storage_Order
(Base_Type
(E
));
925 -- Clear default SSO indications, since the aspect
926 -- overrides the default.
928 Set_SSO_Set_Low_By_Default
(Base_Type
(E
), False);
929 Set_SSO_Set_High_By_Default
(Base_Type
(E
), False);
935 if Is_Fixed_Point_Type
(E
)
936 and then not Has_Small_Clause
(E
)
938 Set_Small_Value
(E
, Small_Value
(P
));
943 when Aspect_Storage_Size
=>
944 if (Is_Access_Type
(E
) or else Is_Task_Type
(E
))
945 and then not Has_Storage_Size_Clause
(E
)
947 Set_Storage_Size_Variable
948 (Base_Type
(E
), Storage_Size_Variable
(P
));
953 when Aspect_Value_Size
=>
955 -- Value_Size is never inherited, it is either set by
956 -- default, or it is explicitly set for the derived
957 -- type. So nothing to do here.
963 when Aspect_Volatile
=>
964 if Is_Volatile
(P
) then
968 -- Volatile_Components
970 when Aspect_Volatile_Components
=>
971 if Has_Volatile_Components
(P
) then
972 Set_Has_Volatile_Components
(Base_Type
(E
));
975 -- That should be all the Rep Aspects
978 pragma Assert
(Aspect_Delay
(A_Id
) /= Rep_Aspect
);
985 N
:= Next_Rep_Item
(N
);
987 end Inherit_Delayed_Rep_Aspects
;
989 -------------------------------------
990 -- Make_Pragma_From_Boolean_Aspect --
991 -------------------------------------
993 procedure Make_Pragma_From_Boolean_Aspect
(ASN
: Node_Id
) is
994 Ident
: constant Node_Id
:= Identifier
(ASN
);
995 A_Name
: constant Name_Id
:= Chars
(Ident
);
996 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(A_Name
);
997 Ent
: constant Entity_Id
:= Entity
(ASN
);
998 Expr
: constant Node_Id
:= Expression
(ASN
);
999 Loc
: constant Source_Ptr
:= Sloc
(ASN
);
1003 procedure Check_False_Aspect_For_Derived_Type
;
1004 -- This procedure checks for the case of a false aspect for a derived
1005 -- type, which improperly tries to cancel an aspect inherited from
1008 -----------------------------------------
1009 -- Check_False_Aspect_For_Derived_Type --
1010 -----------------------------------------
1012 procedure Check_False_Aspect_For_Derived_Type
is
1016 -- We are only checking derived types
1018 if not Is_Derived_Type
(E
) then
1022 Par
:= Nearest_Ancestor
(E
);
1025 when Aspect_Atomic | Aspect_Shared
=>
1026 if not Is_Atomic
(Par
) then
1030 when Aspect_Atomic_Components
=>
1031 if not Has_Atomic_Components
(Par
) then
1035 when Aspect_Discard_Names
=>
1036 if not Discard_Names
(Par
) then
1041 if not Is_Packed
(Par
) then
1045 when Aspect_Unchecked_Union
=>
1046 if not Is_Unchecked_Union
(Par
) then
1050 when Aspect_Volatile
=>
1051 if not Is_Volatile
(Par
) then
1055 when Aspect_Volatile_Components
=>
1056 if not Has_Volatile_Components
(Par
) then
1064 -- Fall through means we are canceling an inherited aspect
1066 Error_Msg_Name_1
:= A_Name
;
1068 ("derived type& inherits aspect%, cannot cancel", Expr
, E
);
1070 end Check_False_Aspect_For_Derived_Type
;
1072 -- Start of processing for Make_Pragma_From_Boolean_Aspect
1075 -- Note that we know Expr is present, because for a missing Expr
1076 -- argument, we knew it was True and did not need to delay the
1077 -- evaluation to the freeze point.
1079 if Is_False
(Static_Boolean
(Expr
)) then
1080 Check_False_Aspect_For_Derived_Type
;
1085 Pragma_Argument_Associations
=> New_List
(
1086 Make_Pragma_Argument_Association
(Sloc
(Ident
),
1087 Expression
=> New_Occurrence_Of
(Ent
, Sloc
(Ident
)))),
1089 Pragma_Identifier
=>
1090 Make_Identifier
(Sloc
(Ident
), Chars
(Ident
)));
1092 Set_From_Aspect_Specification
(Prag
, True);
1093 Set_Corresponding_Aspect
(Prag
, ASN
);
1094 Set_Aspect_Rep_Item
(ASN
, Prag
);
1095 Set_Is_Delayed_Aspect
(Prag
);
1096 Set_Parent
(Prag
, ASN
);
1098 end Make_Pragma_From_Boolean_Aspect
;
1100 -- Start of processing for Analyze_Aspects_At_Freeze_Point
1103 -- Must be visible in current scope
1105 if not Scope_Within_Or_Same
(Current_Scope
, Scope
(E
)) then
1109 -- Look for aspect specification entries for this entity
1111 ASN
:= First_Rep_Item
(E
);
1112 while Present
(ASN
) loop
1113 if Nkind
(ASN
) = N_Aspect_Specification
then
1114 exit when Entity
(ASN
) /= E
;
1116 if Is_Delayed_Aspect
(ASN
) then
1117 A_Id
:= Get_Aspect_Id
(ASN
);
1121 -- For aspects whose expression is an optional Boolean, make
1122 -- the corresponding pragma at the freezing point.
1124 when Boolean_Aspects |
1125 Library_Unit_Aspects
=>
1126 Make_Pragma_From_Boolean_Aspect
(ASN
);
1128 -- Special handling for aspects that don't correspond to
1129 -- pragmas/attributes.
1131 when Aspect_Default_Value |
1132 Aspect_Default_Component_Value
=>
1133 Analyze_Aspect_Default_Value
(ASN
);
1135 -- Ditto for iterator aspects, because the corresponding
1136 -- attributes may not have been analyzed yet.
1138 when Aspect_Constant_Indexing |
1139 Aspect_Variable_Indexing |
1140 Aspect_Default_Iterator |
1141 Aspect_Iterator_Element
=>
1142 Analyze
(Expression
(ASN
));
1144 when Aspect_Iterable
=>
1145 Validate_Iterable_Aspect
(E
, ASN
);
1151 Ritem
:= Aspect_Rep_Item
(ASN
);
1153 if Present
(Ritem
) then
1159 Next_Rep_Item
(ASN
);
1162 -- This is where we inherit delayed rep aspects from our parent. Note
1163 -- that if we fell out of the above loop with ASN non-empty, it means
1164 -- we hit an aspect for an entity other than E, and it must be the
1165 -- type from which we were derived.
1167 if May_Inherit_Delayed_Rep_Aspects
(E
) then
1168 Inherit_Delayed_Rep_Aspects
(ASN
);
1170 end Analyze_Aspects_At_Freeze_Point
;
1172 -----------------------------------
1173 -- Analyze_Aspect_Specifications --
1174 -----------------------------------
1176 procedure Analyze_Aspect_Specifications
(N
: Node_Id
; E
: Entity_Id
) is
1177 procedure Decorate
(Asp
: Node_Id
; Prag
: Node_Id
);
1178 -- Establish linkages between an aspect and its corresponding
1181 procedure Insert_After_SPARK_Mode
1185 -- Subsidiary to the analysis of aspects Abstract_State, Initializes,
1186 -- Initial_Condition and Refined_State. Insert node Prag before node
1187 -- Ins_Nod. If Ins_Nod is for pragma SPARK_Mode, then skip SPARK_Mode.
1188 -- Decls is the associated declarative list where Prag is to reside.
1190 procedure Insert_Pragma
(Prag
: Node_Id
);
1191 -- Subsidiary to the analysis of aspects Attach_Handler, Contract_Cases,
1192 -- Depends, Global, Post, Pre, Refined_Depends and Refined_Global.
1193 -- Insert pragma Prag such that it mimics the placement of a source
1194 -- pragma of the same kind.
1196 -- procedure Proc (Formal : ...) with Global => ...;
1198 -- procedure Proc (Formal : ...);
1199 -- pragma Global (...);
1205 procedure Decorate
(Asp
: Node_Id
; Prag
: Node_Id
) is
1207 Set_Aspect_Rep_Item
(Asp
, Prag
);
1208 Set_Corresponding_Aspect
(Prag
, Asp
);
1209 Set_From_Aspect_Specification
(Prag
);
1210 Set_Parent
(Prag
, Asp
);
1213 -----------------------------
1214 -- Insert_After_SPARK_Mode --
1215 -----------------------------
1217 procedure Insert_After_SPARK_Mode
1222 Decl
: Node_Id
:= Ins_Nod
;
1228 and then Nkind
(Decl
) = N_Pragma
1229 and then Pragma_Name
(Decl
) = Name_SPARK_Mode
1231 Decl
:= Next
(Decl
);
1234 if Present
(Decl
) then
1235 Insert_Before
(Decl
, Prag
);
1237 -- Aitem acts as the last declaration
1240 Append_To
(Decls
, Prag
);
1242 end Insert_After_SPARK_Mode
;
1248 procedure Insert_Pragma
(Prag
: Node_Id
) is
1253 -- When the context is a library unit, the pragma is added to the
1254 -- Pragmas_After list.
1256 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
1257 Aux
:= Aux_Decls_Node
(Parent
(N
));
1259 if No
(Pragmas_After
(Aux
)) then
1260 Set_Pragmas_After
(Aux
, New_List
);
1263 Prepend
(Prag
, Pragmas_After
(Aux
));
1265 -- Pragmas associated with subprogram bodies are inserted in the
1266 -- declarative part.
1268 elsif Nkind
(N
) = N_Subprogram_Body
then
1269 if Present
(Declarations
(N
)) then
1271 -- Skip other internally generated pragmas from aspects to find
1272 -- the proper insertion point. As a result the order of pragmas
1273 -- is the same as the order of aspects.
1275 -- As precondition pragmas generated from conjuncts in the
1276 -- precondition aspect are presented in reverse order to
1277 -- Insert_Pragma, insert them in the correct order here by not
1278 -- skipping previously inserted precondition pragmas when the
1279 -- current pragma is a precondition.
1281 Decl
:= First
(Declarations
(N
));
1282 while Present
(Decl
) loop
1283 if Nkind
(Decl
) = N_Pragma
1284 and then From_Aspect_Specification
(Decl
)
1285 and then not (Get_Pragma_Id
(Decl
) = Pragma_Precondition
1287 Get_Pragma_Id
(Prag
) = Pragma_Precondition
)
1295 if Present
(Decl
) then
1296 Insert_Before
(Decl
, Prag
);
1298 Append
(Prag
, Declarations
(N
));
1301 Set_Declarations
(N
, New_List
(Prag
));
1307 Insert_After
(N
, Prag
);
1317 L
: constant List_Id
:= Aspect_Specifications
(N
);
1319 Ins_Node
: Node_Id
:= N
;
1320 -- Insert pragmas/attribute definition clause after this node when no
1321 -- delayed analysis is required.
1323 -- Start of processing for Analyze_Aspect_Specifications
1325 -- The general processing involves building an attribute definition
1326 -- clause or a pragma node that corresponds to the aspect. Then in order
1327 -- to delay the evaluation of this aspect to the freeze point, we attach
1328 -- the corresponding pragma/attribute definition clause to the aspect
1329 -- specification node, which is then placed in the Rep Item chain. In
1330 -- this case we mark the entity by setting the flag Has_Delayed_Aspects
1331 -- and we evaluate the rep item at the freeze point. When the aspect
1332 -- doesn't have a corresponding pragma/attribute definition clause, then
1333 -- its analysis is simply delayed at the freeze point.
1335 -- Some special cases don't require delay analysis, thus the aspect is
1336 -- analyzed right now.
1338 -- Note that there is a special handling for Pre, Post, Test_Case,
1339 -- Contract_Cases aspects. In these cases, we do not have to worry
1340 -- about delay issues, since the pragmas themselves deal with delay
1341 -- of visibility for the expression analysis. Thus, we just insert
1342 -- the pragma after the node N.
1345 pragma Assert
(Present
(L
));
1347 -- Loop through aspects
1349 Aspect
:= First
(L
);
1350 Aspect_Loop
: while Present
(Aspect
) loop
1351 Analyze_One_Aspect
: declare
1352 Expr
: constant Node_Id
:= Expression
(Aspect
);
1353 Id
: constant Node_Id
:= Identifier
(Aspect
);
1354 Loc
: constant Source_Ptr
:= Sloc
(Aspect
);
1355 Nam
: constant Name_Id
:= Chars
(Id
);
1356 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Nam
);
1359 Delay_Required
: Boolean;
1360 -- Set False if delay is not required
1362 Eloc
: Source_Ptr
:= No_Location
;
1363 -- Source location of expression, modified when we split PPC's. It
1364 -- is set below when Expr is present.
1366 procedure Analyze_Aspect_External_Or_Link_Name
;
1367 -- Perform analysis of the External_Name or Link_Name aspects
1369 procedure Analyze_Aspect_Implicit_Dereference
;
1370 -- Perform analysis of the Implicit_Dereference aspects
1372 procedure Make_Aitem_Pragma
1373 (Pragma_Argument_Associations
: List_Id
;
1374 Pragma_Name
: Name_Id
);
1375 -- This is a wrapper for Make_Pragma used for converting aspects
1376 -- to pragmas. It takes care of Sloc (set from Loc) and building
1377 -- the pragma identifier from the given name. In addition the
1378 -- flags Class_Present and Split_PPC are set from the aspect
1379 -- node, as well as Is_Ignored. This routine also sets the
1380 -- From_Aspect_Specification in the resulting pragma node to
1381 -- True, and sets Corresponding_Aspect to point to the aspect.
1382 -- The resulting pragma is assigned to Aitem.
1384 ------------------------------------------
1385 -- Analyze_Aspect_External_Or_Link_Name --
1386 ------------------------------------------
1388 procedure Analyze_Aspect_External_Or_Link_Name
is
1390 -- Verify that there is an Import/Export aspect defined for the
1391 -- entity. The processing of that aspect in turn checks that
1392 -- there is a Convention aspect declared. The pragma is
1393 -- constructed when processing the Convention aspect.
1400 while Present
(A
) loop
1401 exit when Nam_In
(Chars
(Identifier
(A
)), Name_Export
,
1408 ("missing Import/Export for Link/External name",
1412 end Analyze_Aspect_External_Or_Link_Name
;
1414 -----------------------------------------
1415 -- Analyze_Aspect_Implicit_Dereference --
1416 -----------------------------------------
1418 procedure Analyze_Aspect_Implicit_Dereference
is
1420 if not Is_Type
(E
) or else not Has_Discriminants
(E
) then
1422 ("aspect must apply to a type with discriminants", N
);
1429 Disc
:= First_Discriminant
(E
);
1430 while Present
(Disc
) loop
1431 if Chars
(Expr
) = Chars
(Disc
)
1432 and then Ekind
(Etype
(Disc
)) =
1433 E_Anonymous_Access_Type
1435 Set_Has_Implicit_Dereference
(E
);
1436 Set_Has_Implicit_Dereference
(Disc
);
1440 Next_Discriminant
(Disc
);
1443 -- Error if no proper access discriminant.
1446 ("not an access discriminant of&", Expr
, E
);
1449 end Analyze_Aspect_Implicit_Dereference
;
1451 -----------------------
1452 -- Make_Aitem_Pragma --
1453 -----------------------
1455 procedure Make_Aitem_Pragma
1456 (Pragma_Argument_Associations
: List_Id
;
1457 Pragma_Name
: Name_Id
)
1459 Args
: List_Id
:= Pragma_Argument_Associations
;
1462 -- We should never get here if aspect was disabled
1464 pragma Assert
(not Is_Disabled
(Aspect
));
1466 -- Certain aspects allow for an optional name or expression. Do
1467 -- not generate a pragma with empty argument association list.
1469 if No
(Args
) or else No
(Expression
(First
(Args
))) then
1477 Pragma_Argument_Associations
=> Args
,
1478 Pragma_Identifier
=>
1479 Make_Identifier
(Sloc
(Id
), Pragma_Name
),
1480 Class_Present
=> Class_Present
(Aspect
),
1481 Split_PPC
=> Split_PPC
(Aspect
));
1483 -- Set additional semantic fields
1485 if Is_Ignored
(Aspect
) then
1486 Set_Is_Ignored
(Aitem
);
1487 elsif Is_Checked
(Aspect
) then
1488 Set_Is_Checked
(Aitem
);
1491 Set_Corresponding_Aspect
(Aitem
, Aspect
);
1492 Set_From_Aspect_Specification
(Aitem
, True);
1493 end Make_Aitem_Pragma
;
1495 -- Start of processing for Analyze_One_Aspect
1498 -- Skip aspect if already analyzed, to avoid looping in some cases
1500 if Analyzed
(Aspect
) then
1504 -- Skip looking at aspect if it is totally disabled. Just mark it
1505 -- as such for later reference in the tree. This also sets the
1506 -- Is_Ignored and Is_Checked flags appropriately.
1508 Check_Applicable_Policy
(Aspect
);
1510 if Is_Disabled
(Aspect
) then
1514 -- Set the source location of expression, used in the case of
1515 -- a failed precondition/postcondition or invariant. Note that
1516 -- the source location of the expression is not usually the best
1517 -- choice here. For example, it gets located on the last AND
1518 -- keyword in a chain of boolean expressiond AND'ed together.
1519 -- It is best to put the message on the first character of the
1520 -- assertion, which is the effect of the First_Node call here.
1522 if Present
(Expr
) then
1523 Eloc
:= Sloc
(First_Node
(Expr
));
1526 -- Check restriction No_Implementation_Aspect_Specifications
1528 if Implementation_Defined_Aspect
(A_Id
) then
1530 (No_Implementation_Aspect_Specifications
, Aspect
);
1533 -- Check restriction No_Specification_Of_Aspect
1535 Check_Restriction_No_Specification_Of_Aspect
(Aspect
);
1537 -- Mark aspect analyzed (actual analysis is delayed till later)
1539 Set_Analyzed
(Aspect
);
1540 Set_Entity
(Aspect
, E
);
1541 Ent
:= New_Occurrence_Of
(E
, Sloc
(Id
));
1543 -- Check for duplicate aspect. Note that the Comes_From_Source
1544 -- test allows duplicate Pre/Post's that we generate internally
1545 -- to escape being flagged here.
1547 if No_Duplicates_Allowed
(A_Id
) then
1549 while Anod
/= Aspect
loop
1550 if Comes_From_Source
(Aspect
)
1551 and then Same_Aspect
(A_Id
, Get_Aspect_Id
(Anod
))
1553 Error_Msg_Name_1
:= Nam
;
1554 Error_Msg_Sloc
:= Sloc
(Anod
);
1556 -- Case of same aspect specified twice
1558 if Class_Present
(Anod
) = Class_Present
(Aspect
) then
1559 if not Class_Present
(Anod
) then
1561 ("aspect% for & previously given#",
1565 ("aspect `%''Class` for & previously given#",
1575 -- Check some general restrictions on language defined aspects
1577 if not Implementation_Defined_Aspect
(A_Id
) then
1578 Error_Msg_Name_1
:= Nam
;
1580 -- Not allowed for renaming declarations
1582 if Nkind
(N
) in N_Renaming_Declaration
then
1584 ("aspect % not allowed for renaming declaration",
1588 -- Not allowed for formal type declarations
1590 if Nkind
(N
) = N_Formal_Type_Declaration
then
1592 ("aspect % not allowed for formal type declaration",
1597 -- Copy expression for later processing by the procedures
1598 -- Check_Aspect_At_[Freeze_Point | End_Of_Declarations]
1600 Set_Entity
(Id
, New_Copy_Tree
(Expr
));
1602 -- Set Delay_Required as appropriate to aspect
1604 case Aspect_Delay
(A_Id
) is
1605 when Always_Delay
=>
1606 Delay_Required
:= True;
1609 Delay_Required
:= False;
1613 -- If expression has the form of an integer literal, then
1614 -- do not delay, since we know the value cannot change.
1615 -- This optimization catches most rep clause cases.
1617 if (Present
(Expr
) and then Nkind
(Expr
) = N_Integer_Literal
)
1618 or else (A_Id
in Boolean_Aspects
and then No
(Expr
))
1620 Delay_Required
:= False;
1622 Delay_Required
:= True;
1623 Set_Has_Delayed_Rep_Aspects
(E
);
1627 -- Processing based on specific aspect
1631 -- No_Aspect should be impossible
1634 raise Program_Error
;
1636 -- Case 1: Aspects corresponding to attribute definition
1639 when Aspect_Address |
1642 Aspect_Component_Size |
1643 Aspect_Constant_Indexing |
1644 Aspect_Default_Iterator |
1645 Aspect_Dispatching_Domain |
1646 Aspect_External_Tag |
1649 Aspect_Iterator_Element |
1650 Aspect_Machine_Radix |
1651 Aspect_Object_Size |
1654 Aspect_Scalar_Storage_Order |
1657 Aspect_Simple_Storage_Pool |
1658 Aspect_Storage_Pool |
1659 Aspect_Stream_Size |
1661 Aspect_Variable_Indexing |
1664 -- Indexing aspects apply only to tagged type
1666 if (A_Id
= Aspect_Constant_Indexing
1668 A_Id
= Aspect_Variable_Indexing
)
1669 and then not (Is_Type
(E
)
1670 and then Is_Tagged_Type
(E
))
1673 ("indexing aspect can only apply to a tagged type",
1678 -- For the case of aspect Address, we don't consider that we
1679 -- know the entity is never set in the source, since it is
1680 -- is likely aliasing is occurring.
1682 -- Note: one might think that the analysis of the resulting
1683 -- attribute definition clause would take care of that, but
1684 -- that's not the case since it won't be from source.
1686 if A_Id
= Aspect_Address
then
1687 Set_Never_Set_In_Source
(E
, False);
1690 -- Correctness of the profile of a stream operation is
1691 -- verified at the freeze point, but we must detect the
1692 -- illegal specification of this aspect for a subtype now,
1693 -- to prevent malformed rep_item chains.
1695 if (A_Id
= Aspect_Input
or else
1696 A_Id
= Aspect_Output
or else
1697 A_Id
= Aspect_Read
or else
1698 A_Id
= Aspect_Write
)
1699 and not Is_First_Subtype
(E
)
1702 ("local name must be a first subtype", Aspect
);
1706 -- Construct the attribute definition clause
1709 Make_Attribute_Definition_Clause
(Loc
,
1711 Chars
=> Chars
(Id
),
1712 Expression
=> Relocate_Node
(Expr
));
1714 -- If the address is specified, then we treat the entity as
1715 -- referenced, to avoid spurious warnings. This is analogous
1716 -- to what is done with an attribute definition clause, but
1717 -- here we don't want to generate a reference because this
1718 -- is the point of definition of the entity.
1720 if A_Id
= Aspect_Address
then
1724 -- Case 2: Aspects corresponding to pragmas
1726 -- Case 2a: Aspects corresponding to pragmas with two
1727 -- arguments, where the first argument is a local name
1728 -- referring to the entity, and the second argument is the
1729 -- aspect definition expression.
1731 -- Linker_Section/Suppress/Unsuppress
1733 when Aspect_Linker_Section |
1735 Aspect_Unsuppress
=>
1738 (Pragma_Argument_Associations
=> New_List
(
1739 Make_Pragma_Argument_Association
(Loc
,
1740 Expression
=> New_Occurrence_Of
(E
, Loc
)),
1741 Make_Pragma_Argument_Association
(Sloc
(Expr
),
1742 Expression
=> Relocate_Node
(Expr
))),
1743 Pragma_Name
=> Chars
(Id
));
1747 -- Corresponds to pragma Implemented, construct the pragma
1749 when Aspect_Synchronization
=>
1751 (Pragma_Argument_Associations
=> New_List
(
1752 Make_Pragma_Argument_Association
(Loc
,
1753 Expression
=> New_Occurrence_Of
(E
, Loc
)),
1754 Make_Pragma_Argument_Association
(Sloc
(Expr
),
1755 Expression
=> Relocate_Node
(Expr
))),
1756 Pragma_Name
=> Name_Implemented
);
1760 when Aspect_Attach_Handler
=>
1762 (Pragma_Argument_Associations
=> New_List
(
1763 Make_Pragma_Argument_Association
(Sloc
(Ent
),
1765 Make_Pragma_Argument_Association
(Sloc
(Expr
),
1766 Expression
=> Relocate_Node
(Expr
))),
1767 Pragma_Name
=> Name_Attach_Handler
);
1769 -- We need to insert this pragma into the tree to get proper
1770 -- processing and to look valid from a placement viewpoint.
1772 Insert_Pragma
(Aitem
);
1775 -- Dynamic_Predicate, Predicate, Static_Predicate
1777 when Aspect_Dynamic_Predicate |
1779 Aspect_Static_Predicate
=>
1781 -- These aspects apply only to subtypes
1783 if not Is_Type
(E
) then
1785 ("predicate can only be specified for a subtype",
1789 elsif Is_Incomplete_Type
(E
) then
1791 ("predicate cannot apply to incomplete view", Aspect
);
1795 -- Construct the pragma (always a pragma Predicate, with
1796 -- flags recording whether it is static/dynamic). We also
1797 -- set flags recording this in the type itself.
1800 (Pragma_Argument_Associations
=> New_List
(
1801 Make_Pragma_Argument_Association
(Sloc
(Ent
),
1803 Make_Pragma_Argument_Association
(Sloc
(Expr
),
1804 Expression
=> Relocate_Node
(Expr
))),
1805 Pragma_Name
=> Name_Predicate
);
1807 -- Mark type has predicates, and remember what kind of
1808 -- aspect lead to this predicate (we need this to access
1809 -- the right set of check policies later on).
1811 Set_Has_Predicates
(E
);
1813 if A_Id
= Aspect_Dynamic_Predicate
then
1814 Set_Has_Dynamic_Predicate_Aspect
(E
);
1815 elsif A_Id
= Aspect_Static_Predicate
then
1816 Set_Has_Static_Predicate_Aspect
(E
);
1819 -- If the type is private, indicate that its completion
1820 -- has a freeze node, because that is the one that will
1821 -- be visible at freeze time.
1823 if Is_Private_Type
(E
) and then Present
(Full_View
(E
)) then
1824 Set_Has_Predicates
(Full_View
(E
));
1826 if A_Id
= Aspect_Dynamic_Predicate
then
1827 Set_Has_Dynamic_Predicate_Aspect
(Full_View
(E
));
1828 elsif A_Id
= Aspect_Static_Predicate
then
1829 Set_Has_Static_Predicate_Aspect
(Full_View
(E
));
1832 Set_Has_Delayed_Aspects
(Full_View
(E
));
1833 Ensure_Freeze_Node
(Full_View
(E
));
1836 -- Case 2b: Aspects corresponding to pragmas with two
1837 -- arguments, where the second argument is a local name
1838 -- referring to the entity, and the first argument is the
1839 -- aspect definition expression.
1843 when Aspect_Convention
=>
1845 -- The aspect may be part of the specification of an import
1846 -- or export pragma. Scan the aspect list to gather the
1847 -- other components, if any. The name of the generated
1848 -- pragma is one of Convention/Import/Export.
1851 Args
: constant List_Id
:= New_List
(
1852 Make_Pragma_Argument_Association
(Sloc
(Expr
),
1853 Expression
=> Relocate_Node
(Expr
)),
1854 Make_Pragma_Argument_Association
(Sloc
(Ent
),
1855 Expression
=> Ent
));
1857 Imp_Exp_Seen
: Boolean := False;
1858 -- Flag set when aspect Import or Export has been seen
1860 Imp_Seen
: Boolean := False;
1861 -- Flag set when aspect Import has been seen
1865 Extern_Arg
: Node_Id
;
1870 Extern_Arg
:= Empty
;
1872 Prag_Nam
:= Chars
(Id
);
1875 while Present
(Asp
) loop
1876 Asp_Nam
:= Chars
(Identifier
(Asp
));
1878 -- Aspects Import and Export take precedence over
1879 -- aspect Convention. As a result the generated pragma
1880 -- must carry the proper interfacing aspect's name.
1882 if Nam_In
(Asp_Nam
, Name_Import
, Name_Export
) then
1883 if Imp_Exp_Seen
then
1884 Error_Msg_N
("conflicting", Asp
);
1886 Imp_Exp_Seen
:= True;
1888 if Asp_Nam
= Name_Import
then
1893 Prag_Nam
:= Asp_Nam
;
1895 -- Aspect External_Name adds an extra argument to the
1896 -- generated pragma.
1898 elsif Asp_Nam
= Name_External_Name
then
1900 Make_Pragma_Argument_Association
(Loc
,
1902 Expression
=> Relocate_Node
(Expression
(Asp
)));
1904 -- Aspect Link_Name adds an extra argument to the
1905 -- generated pragma.
1907 elsif Asp_Nam
= Name_Link_Name
then
1909 Make_Pragma_Argument_Association
(Loc
,
1911 Expression
=> Relocate_Node
(Expression
(Asp
)));
1917 -- Assemble the full argument list
1919 if Present
(Extern_Arg
) then
1920 Append_To
(Args
, Extern_Arg
);
1923 if Present
(Link_Arg
) then
1924 Append_To
(Args
, Link_Arg
);
1928 (Pragma_Argument_Associations
=> Args
,
1929 Pragma_Name
=> Prag_Nam
);
1931 -- Store the generated pragma Import in the related
1934 if Imp_Seen
and then Is_Subprogram
(E
) then
1935 Set_Import_Pragma
(E
, Aitem
);
1939 -- CPU, Interrupt_Priority, Priority
1941 -- These three aspects can be specified for a subprogram spec
1942 -- or body, in which case we analyze the expression and export
1943 -- the value of the aspect.
1945 -- Previously, we generated an equivalent pragma for bodies
1946 -- (note that the specs cannot contain these pragmas). The
1947 -- pragma was inserted ahead of local declarations, rather than
1948 -- after the body. This leads to a certain duplication between
1949 -- the processing performed for the aspect and the pragma, but
1950 -- given the straightforward handling required it is simpler
1951 -- to duplicate than to translate the aspect in the spec into
1952 -- a pragma in the declarative part of the body.
1955 Aspect_Interrupt_Priority |
1958 if Nkind_In
(N
, N_Subprogram_Body
,
1959 N_Subprogram_Declaration
)
1961 -- Analyze the aspect expression
1963 Analyze_And_Resolve
(Expr
, Standard_Integer
);
1965 -- Interrupt_Priority aspect not allowed for main
1966 -- subprograms. ARM D.1 does not forbid this explicitly,
1967 -- but ARM J.15.11 (6/3) does not permit pragma
1968 -- Interrupt_Priority for subprograms.
1970 if A_Id
= Aspect_Interrupt_Priority
then
1972 ("Interrupt_Priority aspect cannot apply to "
1973 & "subprogram", Expr
);
1975 -- The expression must be static
1977 elsif not Is_OK_Static_Expression
(Expr
) then
1978 Flag_Non_Static_Expr
1979 ("aspect requires static expression!", Expr
);
1981 -- Check whether this is the main subprogram. Issue a
1982 -- warning only if it is obviously not a main program
1983 -- (when it has parameters or when the subprogram is
1984 -- within a package).
1986 elsif Present
(Parameter_Specifications
1987 (Specification
(N
)))
1988 or else not Is_Compilation_Unit
(Defining_Entity
(N
))
1990 -- See ARM D.1 (14/3) and D.16 (12/3)
1993 ("aspect applied to subprogram other than the "
1994 & "main subprogram has no effect??", Expr
);
1996 -- Otherwise check in range and export the value
1998 -- For the CPU aspect
2000 elsif A_Id
= Aspect_CPU
then
2001 if Is_In_Range
(Expr
, RTE
(RE_CPU_Range
)) then
2003 -- Value is correct so we export the value to make
2004 -- it available at execution time.
2007 (Main_Unit
, UI_To_Int
(Expr_Value
(Expr
)));
2011 ("main subprogram CPU is out of range", Expr
);
2014 -- For the Priority aspect
2016 elsif A_Id
= Aspect_Priority
then
2017 if Is_In_Range
(Expr
, RTE
(RE_Priority
)) then
2019 -- Value is correct so we export the value to make
2020 -- it available at execution time.
2023 (Main_Unit
, UI_To_Int
(Expr_Value
(Expr
)));
2025 -- Ignore pragma if Relaxed_RM_Semantics to support
2026 -- other targets/non GNAT compilers.
2028 elsif not Relaxed_RM_Semantics
then
2030 ("main subprogram priority is out of range",
2035 -- Load an arbitrary entity from System.Tasking.Stages
2036 -- or System.Tasking.Restricted.Stages (depending on
2037 -- the supported profile) to make sure that one of these
2038 -- packages is implicitly with'ed, since we need to have
2039 -- the tasking run time active for the pragma Priority to
2040 -- have any effect. Previously we with'ed the package
2041 -- System.Tasking, but this package does not trigger the
2042 -- required initialization of the run-time library.
2045 Discard
: Entity_Id
;
2047 if Restricted_Profile
then
2048 Discard
:= RTE
(RE_Activate_Restricted_Tasks
);
2050 Discard
:= RTE
(RE_Activate_Tasks
);
2054 -- Handling for these Aspects in subprograms is complete
2061 -- Pass the aspect as an attribute
2064 Make_Attribute_Definition_Clause
(Loc
,
2066 Chars
=> Chars
(Id
),
2067 Expression
=> Relocate_Node
(Expr
));
2072 when Aspect_Warnings
=>
2074 (Pragma_Argument_Associations
=> New_List
(
2075 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2076 Expression
=> Relocate_Node
(Expr
)),
2077 Make_Pragma_Argument_Association
(Loc
,
2078 Expression
=> New_Occurrence_Of
(E
, Loc
))),
2079 Pragma_Name
=> Chars
(Id
));
2081 -- Case 2c: Aspects corresponding to pragmas with three
2084 -- Invariant aspects have a first argument that references the
2085 -- entity, a second argument that is the expression and a third
2086 -- argument that is an appropriate message.
2088 -- Invariant, Type_Invariant
2090 when Aspect_Invariant |
2091 Aspect_Type_Invariant
=>
2093 -- Analysis of the pragma will verify placement legality:
2094 -- an invariant must apply to a private type, or appear in
2095 -- the private part of a spec and apply to a completion.
2098 (Pragma_Argument_Associations
=> New_List
(
2099 Make_Pragma_Argument_Association
(Sloc
(Ent
),
2101 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2102 Expression
=> Relocate_Node
(Expr
))),
2103 Pragma_Name
=> Name_Invariant
);
2105 -- Add message unless exception messages are suppressed
2107 if not Opt
.Exception_Locations_Suppressed
then
2108 Append_To
(Pragma_Argument_Associations
(Aitem
),
2109 Make_Pragma_Argument_Association
(Eloc
,
2110 Chars
=> Name_Message
,
2112 Make_String_Literal
(Eloc
,
2113 Strval
=> "failed invariant from "
2114 & Build_Location_String
(Eloc
))));
2117 -- For Invariant case, insert immediately after the entity
2118 -- declaration. We do not have to worry about delay issues
2119 -- since the pragma processing takes care of this.
2121 Delay_Required
:= False;
2123 -- Case 2d : Aspects that correspond to a pragma with one
2128 -- Aspect Abstract_State introduces implicit declarations for
2129 -- all state abstraction entities it defines. To emulate this
2130 -- behavior, insert the pragma at the beginning of the visible
2131 -- declarations of the related package so that it is analyzed
2134 when Aspect_Abstract_State
=> Abstract_State
: declare
2135 Context
: Node_Id
:= N
;
2140 -- When aspect Abstract_State appears on a generic package,
2141 -- it is propageted to the package instance. The context in
2142 -- this case is the instance spec.
2144 if Nkind
(Context
) = N_Package_Instantiation
then
2145 Context
:= Instance_Spec
(Context
);
2148 if Nkind_In
(Context
, N_Generic_Package_Declaration
,
2149 N_Package_Declaration
)
2152 (Pragma_Argument_Associations
=> New_List
(
2153 Make_Pragma_Argument_Association
(Loc
,
2154 Expression
=> Relocate_Node
(Expr
))),
2155 Pragma_Name
=> Name_Abstract_State
);
2156 Decorate
(Aspect
, Aitem
);
2158 Decls
:= Visible_Declarations
(Specification
(Context
));
2160 -- In general pragma Abstract_State must be at the top
2161 -- of the existing visible declarations to emulate its
2162 -- source counterpart. The only exception to this is a
2163 -- generic instance in which case the pragma must be
2164 -- inserted after the association renamings.
2166 if Present
(Decls
) then
2167 Decl
:= First
(Decls
);
2169 -- The visible declarations of a generic instance have
2170 -- the following structure:
2172 -- <renamings of generic formals>
2173 -- <renamings of internally-generated spec and body>
2174 -- <first source declaration>
2176 -- The pragma must be inserted before the first source
2177 -- declaration, skip the instance "header".
2179 if Is_Generic_Instance
(Defining_Entity
(Context
)) then
2180 while Present
(Decl
)
2181 and then not Comes_From_Source
(Decl
)
2183 Decl
:= Next
(Decl
);
2187 -- Pragma Abstract_State must be inserted after pragma
2188 -- SPARK_Mode in the tree. This ensures that any error
2189 -- messages dependent on SPARK_Mode will be properly
2190 -- enabled/suppressed.
2192 Insert_After_SPARK_Mode
2197 -- Otherwise the pragma forms a new declarative list
2200 Set_Visible_Declarations
2201 (Specification
(Context
), New_List
(Aitem
));
2206 ("aspect & must apply to a package declaration",
2213 -- Aspect Default_Internal_Condition is never delayed because
2214 -- it is equivalent to a source pragma which appears after the
2215 -- related private type. To deal with forward references, the
2216 -- generated pragma is stored in the rep chain of the related
2217 -- private type as types do not carry contracts. The pragma is
2218 -- wrapped inside of a procedure at the freeze point of the
2219 -- private type's full view.
2221 when Aspect_Default_Initial_Condition
=>
2223 (Pragma_Argument_Associations
=> New_List
(
2224 Make_Pragma_Argument_Association
(Loc
,
2225 Expression
=> Relocate_Node
(Expr
))),
2227 Name_Default_Initial_Condition
);
2229 Decorate
(Aspect
, Aitem
);
2230 Insert_Pragma
(Aitem
);
2235 -- Aspect Depends is never delayed because it is equivalent to
2236 -- a source pragma which appears after the related subprogram.
2237 -- To deal with forward references, the generated pragma is
2238 -- stored in the contract of the related subprogram and later
2239 -- analyzed at the end of the declarative region. See routine
2240 -- Analyze_Depends_In_Decl_Part for details.
2242 when Aspect_Depends
=>
2244 (Pragma_Argument_Associations
=> New_List
(
2245 Make_Pragma_Argument_Association
(Loc
,
2246 Expression
=> Relocate_Node
(Expr
))),
2247 Pragma_Name
=> Name_Depends
);
2249 Decorate
(Aspect
, Aitem
);
2250 Insert_Pragma
(Aitem
);
2255 -- Aspect Global is never delayed because it is equivalent to
2256 -- a source pragma which appears after the related subprogram.
2257 -- To deal with forward references, the generated pragma is
2258 -- stored in the contract of the related subprogram and later
2259 -- analyzed at the end of the declarative region. See routine
2260 -- Analyze_Global_In_Decl_Part for details.
2262 when Aspect_Global
=>
2264 (Pragma_Argument_Associations
=> New_List
(
2265 Make_Pragma_Argument_Association
(Loc
,
2266 Expression
=> Relocate_Node
(Expr
))),
2267 Pragma_Name
=> Name_Global
);
2269 Decorate
(Aspect
, Aitem
);
2270 Insert_Pragma
(Aitem
);
2273 -- Initial_Condition
2275 -- Aspect Initial_Condition is never delayed because it is
2276 -- equivalent to a source pragma which appears after the
2277 -- related package. To deal with forward references, the
2278 -- generated pragma is stored in the contract of the related
2279 -- package and later analyzed at the end of the declarative
2280 -- region. See routine Analyze_Initial_Condition_In_Decl_Part
2283 when Aspect_Initial_Condition
=> Initial_Condition
: declare
2284 Context
: Node_Id
:= N
;
2288 -- When aspect Initial_Condition appears on a generic
2289 -- package, it is propageted to the package instance. The
2290 -- context in this case is the instance spec.
2292 if Nkind
(Context
) = N_Package_Instantiation
then
2293 Context
:= Instance_Spec
(Context
);
2296 if Nkind_In
(Context
, N_Generic_Package_Declaration
,
2297 N_Package_Declaration
)
2299 Decls
:= Visible_Declarations
(Specification
(Context
));
2302 (Pragma_Argument_Associations
=> New_List
(
2303 Make_Pragma_Argument_Association
(Loc
,
2304 Expression
=> Relocate_Node
(Expr
))),
2306 Name_Initial_Condition
);
2307 Decorate
(Aspect
, Aitem
);
2311 Set_Visible_Declarations
(Context
, Decls
);
2314 -- When aspects Abstract_State, Initial_Condition and
2315 -- Initializes are out of order, ensure that pragma
2316 -- SPARK_Mode is always at the top of the declarative
2317 -- list to properly enable/suppress errors.
2319 Insert_After_SPARK_Mode
2321 Ins_Nod
=> First
(Decls
),
2326 ("aspect & must apply to a package declaration",
2331 end Initial_Condition
;
2335 -- Aspect Initializes is never delayed because it is equivalent
2336 -- to a source pragma appearing after the related package. To
2337 -- deal with forward references, the generated pragma is stored
2338 -- in the contract of the related package and later analyzed at
2339 -- the end of the declarative region. For details, see routine
2340 -- Analyze_Initializes_In_Decl_Part.
2342 when Aspect_Initializes
=> Initializes
: declare
2343 Context
: Node_Id
:= N
;
2347 -- When aspect Initializes appears on a generic package,
2348 -- it is propageted to the package instance. The context
2349 -- in this case is the instance spec.
2351 if Nkind
(Context
) = N_Package_Instantiation
then
2352 Context
:= Instance_Spec
(Context
);
2355 if Nkind_In
(Context
, N_Generic_Package_Declaration
,
2356 N_Package_Declaration
)
2358 Decls
:= Visible_Declarations
(Specification
(Context
));
2361 (Pragma_Argument_Associations
=> New_List
(
2362 Make_Pragma_Argument_Association
(Loc
,
2363 Expression
=> Relocate_Node
(Expr
))),
2364 Pragma_Name
=> Name_Initializes
);
2365 Decorate
(Aspect
, Aitem
);
2369 Set_Visible_Declarations
(Context
, Decls
);
2372 -- When aspects Abstract_State, Initial_Condition and
2373 -- Initializes are out of order, ensure that pragma
2374 -- SPARK_Mode is always at the top of the declarative
2375 -- list to properly enable/suppress errors.
2377 Insert_After_SPARK_Mode
2379 Ins_Nod
=> First
(Decls
),
2384 ("aspect & must apply to a package declaration",
2393 when Aspect_Obsolescent
=> declare
2401 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2402 Expression
=> Relocate_Node
(Expr
)));
2406 (Pragma_Argument_Associations
=> Args
,
2407 Pragma_Name
=> Chars
(Id
));
2412 when Aspect_Part_Of
=>
2413 if Nkind_In
(N
, N_Object_Declaration
,
2414 N_Package_Instantiation
)
2417 (Pragma_Argument_Associations
=> New_List
(
2418 Make_Pragma_Argument_Association
(Loc
,
2419 Expression
=> Relocate_Node
(Expr
))),
2420 Pragma_Name
=> Name_Part_Of
);
2424 ("aspect & must apply to a variable or package "
2425 & "instantiation", Aspect
, Id
);
2430 when Aspect_SPARK_Mode
=> SPARK_Mode
: declare
2435 (Pragma_Argument_Associations
=> New_List
(
2436 Make_Pragma_Argument_Association
(Loc
,
2437 Expression
=> Relocate_Node
(Expr
))),
2438 Pragma_Name
=> Name_SPARK_Mode
);
2440 -- When the aspect appears on a package or a subprogram
2441 -- body, insert the generated pragma at the top of the body
2442 -- declarations to emulate the behavior of a source pragma.
2444 if Nkind_In
(N
, N_Package_Body
, N_Subprogram_Body
) then
2445 Decorate
(Aspect
, Aitem
);
2447 Decls
:= Declarations
(N
);
2451 Set_Declarations
(N
, Decls
);
2454 Prepend_To
(Decls
, Aitem
);
2457 -- When the aspect is associated with a [generic] package
2458 -- declaration, insert the generated pragma at the top of
2459 -- the visible declarations to emulate the behavior of a
2462 elsif Nkind_In
(N
, N_Generic_Package_Declaration
,
2463 N_Package_Declaration
)
2465 Decorate
(Aspect
, Aitem
);
2467 Decls
:= Visible_Declarations
(Specification
(N
));
2471 Set_Visible_Declarations
(Specification
(N
), Decls
);
2474 Prepend_To
(Decls
, Aitem
);
2481 -- Aspect Refined_Depends is never delayed because it is
2482 -- equivalent to a source pragma which appears in the
2483 -- declarations of the related subprogram body. To deal with
2484 -- forward references, the generated pragma is stored in the
2485 -- contract of the related subprogram body and later analyzed
2486 -- at the end of the declarative region. For details, see
2487 -- routine Analyze_Refined_Depends_In_Decl_Part.
2489 when Aspect_Refined_Depends
=>
2491 (Pragma_Argument_Associations
=> New_List
(
2492 Make_Pragma_Argument_Association
(Loc
,
2493 Expression
=> Relocate_Node
(Expr
))),
2494 Pragma_Name
=> Name_Refined_Depends
);
2496 Decorate
(Aspect
, Aitem
);
2497 Insert_Pragma
(Aitem
);
2502 -- Aspect Refined_Global is never delayed because it is
2503 -- equivalent to a source pragma which appears in the
2504 -- declarations of the related subprogram body. To deal with
2505 -- forward references, the generated pragma is stored in the
2506 -- contract of the related subprogram body and later analyzed
2507 -- at the end of the declarative region. For details, see
2508 -- routine Analyze_Refined_Global_In_Decl_Part.
2510 when Aspect_Refined_Global
=>
2512 (Pragma_Argument_Associations
=> New_List
(
2513 Make_Pragma_Argument_Association
(Loc
,
2514 Expression
=> Relocate_Node
(Expr
))),
2515 Pragma_Name
=> Name_Refined_Global
);
2517 Decorate
(Aspect
, Aitem
);
2518 Insert_Pragma
(Aitem
);
2523 when Aspect_Refined_Post
=>
2525 (Pragma_Argument_Associations
=> New_List
(
2526 Make_Pragma_Argument_Association
(Loc
,
2527 Expression
=> Relocate_Node
(Expr
))),
2528 Pragma_Name
=> Name_Refined_Post
);
2532 when Aspect_Refined_State
=> Refined_State
: declare
2536 -- The corresponding pragma for Refined_State is inserted in
2537 -- the declarations of the related package body. This action
2538 -- synchronizes both the source and from-aspect versions of
2541 if Nkind
(N
) = N_Package_Body
then
2542 Decls
:= Declarations
(N
);
2545 (Pragma_Argument_Associations
=> New_List
(
2546 Make_Pragma_Argument_Association
(Loc
,
2547 Expression
=> Relocate_Node
(Expr
))),
2548 Pragma_Name
=> Name_Refined_State
);
2549 Decorate
(Aspect
, Aitem
);
2553 Set_Declarations
(N
, Decls
);
2556 -- Pragma Refined_State must be inserted after pragma
2557 -- SPARK_Mode in the tree. This ensures that any error
2558 -- messages dependent on SPARK_Mode will be properly
2559 -- enabled/suppressed.
2561 Insert_After_SPARK_Mode
2563 Ins_Nod
=> First
(Decls
),
2568 ("aspect & must apply to a package body", Aspect
, Id
);
2574 -- Relative_Deadline
2576 when Aspect_Relative_Deadline
=>
2578 (Pragma_Argument_Associations
=> New_List
(
2579 Make_Pragma_Argument_Association
(Loc
,
2580 Expression
=> Relocate_Node
(Expr
))),
2581 Pragma_Name
=> Name_Relative_Deadline
);
2583 -- If the aspect applies to a task, the corresponding pragma
2584 -- must appear within its declarations, not after.
2586 if Nkind
(N
) = N_Task_Type_Declaration
then
2592 if No
(Task_Definition
(N
)) then
2593 Set_Task_Definition
(N
,
2594 Make_Task_Definition
(Loc
,
2595 Visible_Declarations
=> New_List
,
2596 End_Label
=> Empty
));
2599 Def
:= Task_Definition
(N
);
2600 V
:= Visible_Declarations
(Def
);
2601 if not Is_Empty_List
(V
) then
2602 Insert_Before
(First
(V
), Aitem
);
2605 Set_Visible_Declarations
(Def
, New_List
(Aitem
));
2612 -- Case 2e: Annotate aspect
2614 when Aspect_Annotate
=>
2621 -- The argument can be a single identifier
2623 if Nkind
(Expr
) = N_Identifier
then
2625 -- One level of parens is allowed
2627 if Paren_Count
(Expr
) > 1 then
2628 Error_Msg_F
("extra parentheses ignored", Expr
);
2631 Set_Paren_Count
(Expr
, 0);
2633 -- Add the single item to the list
2635 Args
:= New_List
(Expr
);
2637 -- Otherwise we must have an aggregate
2639 elsif Nkind
(Expr
) = N_Aggregate
then
2641 -- Must be positional
2643 if Present
(Component_Associations
(Expr
)) then
2645 ("purely positional aggregate required", Expr
);
2649 -- Must not be parenthesized
2651 if Paren_Count
(Expr
) /= 0 then
2652 Error_Msg_F
("extra parentheses ignored", Expr
);
2655 -- List of arguments is list of aggregate expressions
2657 Args
:= Expressions
(Expr
);
2659 -- Anything else is illegal
2662 Error_Msg_F
("wrong form for Annotate aspect", Expr
);
2666 -- Prepare pragma arguments
2669 Arg
:= First
(Args
);
2670 while Present
(Arg
) loop
2672 Make_Pragma_Argument_Association
(Sloc
(Arg
),
2673 Expression
=> Relocate_Node
(Arg
)));
2678 Make_Pragma_Argument_Association
(Sloc
(Ent
),
2679 Chars
=> Name_Entity
,
2680 Expression
=> Ent
));
2683 (Pragma_Argument_Associations
=> Pargs
,
2684 Pragma_Name
=> Name_Annotate
);
2687 -- Case 3 : Aspects that don't correspond to pragma/attribute
2688 -- definition clause.
2690 -- Case 3a: The aspects listed below don't correspond to
2691 -- pragmas/attributes but do require delayed analysis.
2693 -- Default_Value can only apply to a scalar type
2695 when Aspect_Default_Value
=>
2696 if not Is_Scalar_Type
(E
) then
2698 ("aspect Default_Value must apply to a scalar_Type", N
);
2703 -- Default_Component_Value can only apply to an array type
2704 -- with scalar components.
2706 when Aspect_Default_Component_Value
=>
2707 if not (Is_Array_Type
(E
)
2708 and then Is_Scalar_Type
(Component_Type
(E
)))
2710 Error_Msg_N
("aspect Default_Component_Value can only "
2711 & "apply to an array of scalar components", N
);
2716 -- Case 3b: The aspects listed below don't correspond to
2717 -- pragmas/attributes and don't need delayed analysis.
2719 -- Implicit_Dereference
2721 -- For Implicit_Dereference, External_Name and Link_Name, only
2722 -- the legality checks are done during the analysis, thus no
2723 -- delay is required.
2725 when Aspect_Implicit_Dereference
=>
2726 Analyze_Aspect_Implicit_Dereference
;
2729 -- External_Name, Link_Name
2731 when Aspect_External_Name |
2733 Analyze_Aspect_External_Or_Link_Name
;
2738 when Aspect_Dimension
=>
2739 Analyze_Aspect_Dimension
(N
, Id
, Expr
);
2744 when Aspect_Dimension_System
=>
2745 Analyze_Aspect_Dimension_System
(N
, Id
, Expr
);
2748 -- Case 4: Aspects requiring special handling
2750 -- Pre/Post/Test_Case/Contract_Cases whose corresponding
2751 -- pragmas take care of the delay.
2755 -- Aspects Pre/Post generate Precondition/Postcondition pragmas
2756 -- with a first argument that is the expression, and a second
2757 -- argument that is an informative message if the test fails.
2758 -- This is inserted right after the declaration, to get the
2759 -- required pragma placement. The processing for the pragmas
2760 -- takes care of the required delay.
2762 when Pre_Post_Aspects
=> Pre_Post
: declare
2766 if A_Id
= Aspect_Pre
or else A_Id
= Aspect_Precondition
then
2767 Pname
:= Name_Precondition
;
2769 Pname
:= Name_Postcondition
;
2772 -- If the expressions is of the form A and then B, then
2773 -- we generate separate Pre/Post aspects for the separate
2774 -- clauses. Since we allow multiple pragmas, there is no
2775 -- problem in allowing multiple Pre/Post aspects internally.
2776 -- These should be treated in reverse order (B first and
2777 -- A second) since they are later inserted just after N in
2778 -- the order they are treated. This way, the pragma for A
2779 -- ends up preceding the pragma for B, which may have an
2780 -- importance for the error raised (either constraint error
2781 -- or precondition error).
2783 -- We do not do this for Pre'Class, since we have to put
2784 -- these conditions together in a complex OR expression.
2786 -- We do not do this in ASIS mode, as ASIS relies on the
2787 -- original node representing the complete expression, when
2788 -- retrieving it through the source aspect table.
2791 and then (Pname
= Name_Postcondition
2792 or else not Class_Present
(Aspect
))
2794 while Nkind
(Expr
) = N_And_Then
loop
2795 Insert_After
(Aspect
,
2796 Make_Aspect_Specification
(Sloc
(Left_Opnd
(Expr
)),
2797 Identifier
=> Identifier
(Aspect
),
2798 Expression
=> Relocate_Node
(Left_Opnd
(Expr
)),
2799 Class_Present
=> Class_Present
(Aspect
),
2800 Split_PPC
=> True));
2801 Rewrite
(Expr
, Relocate_Node
(Right_Opnd
(Expr
)));
2802 Eloc
:= Sloc
(Expr
);
2806 -- Build the precondition/postcondition pragma
2808 -- Add note about why we do NOT need Copy_Tree here???
2811 (Pragma_Argument_Associations
=> New_List
(
2812 Make_Pragma_Argument_Association
(Eloc
,
2813 Chars
=> Name_Check
,
2814 Expression
=> Relocate_Node
(Expr
))),
2815 Pragma_Name
=> Pname
);
2817 -- Add message unless exception messages are suppressed
2819 if not Opt
.Exception_Locations_Suppressed
then
2820 Append_To
(Pragma_Argument_Associations
(Aitem
),
2821 Make_Pragma_Argument_Association
(Eloc
,
2822 Chars
=> Name_Message
,
2824 Make_String_Literal
(Eloc
,
2826 & Get_Name_String
(Pname
)
2828 & Build_Location_String
(Eloc
))));
2831 Set_Is_Delayed_Aspect
(Aspect
);
2833 -- For Pre/Post cases, insert immediately after the entity
2834 -- declaration, since that is the required pragma placement.
2835 -- Note that for these aspects, we do not have to worry
2836 -- about delay issues, since the pragmas themselves deal
2837 -- with delay of visibility for the expression analysis.
2839 Insert_Pragma
(Aitem
);
2845 when Aspect_Test_Case
=> Test_Case
: declare
2847 Comp_Expr
: Node_Id
;
2848 Comp_Assn
: Node_Id
;
2854 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
2855 Error_Msg_Name_1
:= Nam
;
2856 Error_Msg_N
("incorrect placement of aspect `%`", E
);
2860 if Nkind
(Expr
) /= N_Aggregate
then
2861 Error_Msg_Name_1
:= Nam
;
2863 ("wrong syntax for aspect `%` for &", Id
, E
);
2867 -- Make pragma expressions refer to the original aspect
2868 -- expressions through the Original_Node link. This is used
2869 -- in semantic analysis for ASIS mode, so that the original
2870 -- expression also gets analyzed.
2872 Comp_Expr
:= First
(Expressions
(Expr
));
2873 while Present
(Comp_Expr
) loop
2874 New_Expr
:= Relocate_Node
(Comp_Expr
);
2875 Set_Original_Node
(New_Expr
, Comp_Expr
);
2877 Make_Pragma_Argument_Association
(Sloc
(Comp_Expr
),
2878 Expression
=> New_Expr
));
2882 Comp_Assn
:= First
(Component_Associations
(Expr
));
2883 while Present
(Comp_Assn
) loop
2884 if List_Length
(Choices
(Comp_Assn
)) /= 1
2886 Nkind
(First
(Choices
(Comp_Assn
))) /= N_Identifier
2888 Error_Msg_Name_1
:= Nam
;
2890 ("wrong syntax for aspect `%` for &", Id
, E
);
2894 New_Expr
:= Relocate_Node
(Expression
(Comp_Assn
));
2895 Set_Original_Node
(New_Expr
, Expression
(Comp_Assn
));
2897 Make_Pragma_Argument_Association
(Sloc
(Comp_Assn
),
2898 Chars
=> Chars
(First
(Choices
(Comp_Assn
))),
2899 Expression
=> New_Expr
));
2903 -- Build the test-case pragma
2906 (Pragma_Argument_Associations
=> Args
,
2907 Pragma_Name
=> Nam
);
2912 when Aspect_Contract_Cases
=>
2914 (Pragma_Argument_Associations
=> New_List
(
2915 Make_Pragma_Argument_Association
(Loc
,
2916 Expression
=> Relocate_Node
(Expr
))),
2917 Pragma_Name
=> Nam
);
2919 Decorate
(Aspect
, Aitem
);
2920 Insert_Pragma
(Aitem
);
2923 -- Case 5: Special handling for aspects with an optional
2924 -- boolean argument.
2926 -- In the general case, the corresponding pragma cannot be
2927 -- generated yet because the evaluation of the boolean needs
2928 -- to be delayed till the freeze point.
2930 when Boolean_Aspects |
2931 Library_Unit_Aspects
=>
2933 Set_Is_Boolean_Aspect
(Aspect
);
2935 -- Lock_Free aspect only apply to protected objects
2937 if A_Id
= Aspect_Lock_Free
then
2938 if Ekind
(E
) /= E_Protected_Type
then
2939 Error_Msg_Name_1
:= Nam
;
2941 ("aspect % only applies to a protected object",
2945 -- Set the Uses_Lock_Free flag to True if there is no
2946 -- expression or if the expression is True. The
2947 -- evaluation of this aspect should be delayed to the
2948 -- freeze point (why???)
2951 or else Is_True
(Static_Boolean
(Expr
))
2953 Set_Uses_Lock_Free
(E
);
2956 Record_Rep_Item
(E
, Aspect
);
2961 elsif A_Id
= Aspect_Import
or else A_Id
= Aspect_Export
then
2963 -- For the case of aspects Import and Export, we don't
2964 -- consider that we know the entity is never set in the
2965 -- source, since it is is likely modified outside the
2968 -- Note: one might think that the analysis of the
2969 -- resulting pragma would take care of that, but
2970 -- that's not the case since it won't be from source.
2972 if Ekind
(E
) = E_Variable
then
2973 Set_Never_Set_In_Source
(E
, False);
2976 -- In older versions of Ada the corresponding pragmas
2977 -- specified a Convention. In Ada 2012 the convention is
2978 -- specified as a separate aspect, and it is optional,
2979 -- given that it defaults to Convention_Ada. The code
2980 -- that verifed that there was a matching convention
2983 -- Resolve the expression of an Import or Export here,
2984 -- and require it to be of type Boolean and static. This
2985 -- is not quite right, because in general this should be
2986 -- delayed, but that seems tricky for these, because
2987 -- normally Boolean aspects are replaced with pragmas at
2988 -- the freeze point (in Make_Pragma_From_Boolean_Aspect),
2989 -- but in the case of these aspects we can't generate
2990 -- a simple pragma with just the entity name. ???
2992 if not Present
(Expr
)
2993 or else Is_True
(Static_Boolean
(Expr
))
2995 if A_Id
= Aspect_Import
then
2996 Set_Is_Imported
(E
);
2998 -- An imported entity cannot have an explicit
3001 if Nkind
(N
) = N_Object_Declaration
3002 and then Present
(Expression
(N
))
3005 ("imported entities cannot be initialized "
3006 & "(RM B.1(24))", Expression
(N
));
3009 elsif A_Id
= Aspect_Export
then
3010 Set_Is_Exported
(E
);
3017 -- Library unit aspects require special handling in the case
3018 -- of a package declaration, the pragma needs to be inserted
3019 -- in the list of declarations for the associated package.
3020 -- There is no issue of visibility delay for these aspects.
3022 if A_Id
in Library_Unit_Aspects
3024 Nkind_In
(N
, N_Package_Declaration
,
3025 N_Generic_Package_Declaration
)
3026 and then Nkind
(Parent
(N
)) /= N_Compilation_Unit
3029 ("incorrect context for library unit aspect&", Id
);
3033 -- External property aspects are Boolean by nature, but
3034 -- their pragmas must contain two arguments, the second
3035 -- being the optional Boolean expression.
3037 if A_Id
= Aspect_Async_Readers
or else
3038 A_Id
= Aspect_Async_Writers
or else
3039 A_Id
= Aspect_Effective_Reads
or else
3040 A_Id
= Aspect_Effective_Writes
3046 -- The first argument of the external property pragma
3047 -- is the related object.
3051 Make_Pragma_Argument_Association
(Sloc
(Ent
),
3052 Expression
=> Ent
));
3054 -- The second argument is the optional Boolean
3055 -- expression which must be propagated even if it
3056 -- evaluates to False as this has special semantic
3059 if Present
(Expr
) then
3061 Make_Pragma_Argument_Association
(Loc
,
3062 Expression
=> Relocate_Node
(Expr
)));
3066 (Pragma_Argument_Associations
=> Args
,
3067 Pragma_Name
=> Nam
);
3070 -- Cases where we do not delay, includes all cases where the
3071 -- expression is missing other than the above cases.
3073 elsif not Delay_Required
or else No
(Expr
) then
3075 (Pragma_Argument_Associations
=> New_List
(
3076 Make_Pragma_Argument_Association
(Sloc
(Ent
),
3077 Expression
=> Ent
)),
3078 Pragma_Name
=> Chars
(Id
));
3079 Delay_Required
:= False;
3081 -- In general cases, the corresponding pragma/attribute
3082 -- definition clause will be inserted later at the freezing
3083 -- point, and we do not need to build it now.
3091 -- This is special because for access types we need to generate
3092 -- an attribute definition clause. This also works for single
3093 -- task declarations, but it does not work for task type
3094 -- declarations, because we have the case where the expression
3095 -- references a discriminant of the task type. That can't use
3096 -- an attribute definition clause because we would not have
3097 -- visibility on the discriminant. For that case we must
3098 -- generate a pragma in the task definition.
3100 when Aspect_Storage_Size
=>
3104 if Ekind
(E
) = E_Task_Type
then
3106 Decl
: constant Node_Id
:= Declaration_Node
(E
);
3109 pragma Assert
(Nkind
(Decl
) = N_Task_Type_Declaration
);
3111 -- If no task definition, create one
3113 if No
(Task_Definition
(Decl
)) then
3114 Set_Task_Definition
(Decl
,
3115 Make_Task_Definition
(Loc
,
3116 Visible_Declarations
=> Empty_List
,
3117 End_Label
=> Empty
));
3120 -- Create a pragma and put it at the start of the task
3121 -- definition for the task type declaration.
3124 (Pragma_Argument_Associations
=> New_List
(
3125 Make_Pragma_Argument_Association
(Loc
,
3126 Expression
=> Relocate_Node
(Expr
))),
3127 Pragma_Name
=> Name_Storage_Size
);
3131 Visible_Declarations
(Task_Definition
(Decl
)));
3135 -- All other cases, generate attribute definition
3139 Make_Attribute_Definition_Clause
(Loc
,
3141 Chars
=> Chars
(Id
),
3142 Expression
=> Relocate_Node
(Expr
));
3146 -- Attach the corresponding pragma/attribute definition clause to
3147 -- the aspect specification node.
3149 if Present
(Aitem
) then
3150 Set_From_Aspect_Specification
(Aitem
);
3153 -- In the context of a compilation unit, we directly put the
3154 -- pragma in the Pragmas_After list of the N_Compilation_Unit_Aux
3155 -- node (no delay is required here) except for aspects on a
3156 -- subprogram body (see below) and a generic package, for which we
3157 -- need to introduce the pragma before building the generic copy
3158 -- (see sem_ch12), and for package instantiations, where the
3159 -- library unit pragmas are better handled early.
3161 if Nkind
(Parent
(N
)) = N_Compilation_Unit
3162 and then (Present
(Aitem
) or else Is_Boolean_Aspect
(Aspect
))
3165 Aux
: constant Node_Id
:= Aux_Decls_Node
(Parent
(N
));
3168 pragma Assert
(Nkind
(Aux
) = N_Compilation_Unit_Aux
);
3170 -- For a Boolean aspect, create the corresponding pragma if
3171 -- no expression or if the value is True.
3173 if Is_Boolean_Aspect
(Aspect
) and then No
(Aitem
) then
3174 if Is_True
(Static_Boolean
(Expr
)) then
3176 (Pragma_Argument_Associations
=> New_List
(
3177 Make_Pragma_Argument_Association
(Sloc
(Ent
),
3178 Expression
=> Ent
)),
3179 Pragma_Name
=> Chars
(Id
));
3181 Set_From_Aspect_Specification
(Aitem
, True);
3182 Set_Corresponding_Aspect
(Aitem
, Aspect
);
3189 -- If the aspect is on a subprogram body (relevant aspect
3190 -- is Inline), add the pragma in front of the declarations.
3192 if Nkind
(N
) = N_Subprogram_Body
then
3193 if No
(Declarations
(N
)) then
3194 Set_Declarations
(N
, New_List
);
3197 Prepend
(Aitem
, Declarations
(N
));
3199 elsif Nkind
(N
) = N_Generic_Package_Declaration
then
3200 if No
(Visible_Declarations
(Specification
(N
))) then
3201 Set_Visible_Declarations
(Specification
(N
), New_List
);
3205 Visible_Declarations
(Specification
(N
)));
3207 elsif Nkind
(N
) = N_Package_Instantiation
then
3209 Spec
: constant Node_Id
:=
3210 Specification
(Instance_Spec
(N
));
3212 if No
(Visible_Declarations
(Spec
)) then
3213 Set_Visible_Declarations
(Spec
, New_List
);
3216 Prepend
(Aitem
, Visible_Declarations
(Spec
));
3220 if No
(Pragmas_After
(Aux
)) then
3221 Set_Pragmas_After
(Aux
, New_List
);
3224 Append
(Aitem
, Pragmas_After
(Aux
));
3231 -- The evaluation of the aspect is delayed to the freezing point.
3232 -- The pragma or attribute clause if there is one is then attached
3233 -- to the aspect specification which is put in the rep item list.
3235 if Delay_Required
then
3236 if Present
(Aitem
) then
3237 Set_Is_Delayed_Aspect
(Aitem
);
3238 Set_Aspect_Rep_Item
(Aspect
, Aitem
);
3239 Set_Parent
(Aitem
, Aspect
);
3242 Set_Is_Delayed_Aspect
(Aspect
);
3244 -- In the case of Default_Value, link the aspect to base type
3245 -- as well, even though it appears on a first subtype. This is
3246 -- mandated by the semantics of the aspect. Do not establish
3247 -- the link when processing the base type itself as this leads
3248 -- to a rep item circularity. Verify that we are dealing with
3249 -- a scalar type to prevent cascaded errors.
3251 if A_Id
= Aspect_Default_Value
3252 and then Is_Scalar_Type
(E
)
3253 and then Base_Type
(E
) /= E
3255 Set_Has_Delayed_Aspects
(Base_Type
(E
));
3256 Record_Rep_Item
(Base_Type
(E
), Aspect
);
3259 Set_Has_Delayed_Aspects
(E
);
3260 Record_Rep_Item
(E
, Aspect
);
3262 -- When delay is not required and the context is a package or a
3263 -- subprogram body, insert the pragma in the body declarations.
3265 elsif Nkind_In
(N
, N_Package_Body
, N_Subprogram_Body
) then
3266 if No
(Declarations
(N
)) then
3267 Set_Declarations
(N
, New_List
);
3270 -- The pragma is added before source declarations
3272 Prepend_To
(Declarations
(N
), Aitem
);
3274 -- When delay is not required and the context is not a compilation
3275 -- unit, we simply insert the pragma/attribute definition clause
3279 Insert_After
(Ins_Node
, Aitem
);
3282 end Analyze_One_Aspect
;
3286 end loop Aspect_Loop
;
3288 if Has_Delayed_Aspects
(E
) then
3289 Ensure_Freeze_Node
(E
);
3291 end Analyze_Aspect_Specifications
;
3293 -----------------------
3294 -- Analyze_At_Clause --
3295 -----------------------
3297 -- An at clause is replaced by the corresponding Address attribute
3298 -- definition clause that is the preferred approach in Ada 95.
3300 procedure Analyze_At_Clause
(N
: Node_Id
) is
3301 CS
: constant Boolean := Comes_From_Source
(N
);
3304 -- This is an obsolescent feature
3306 Check_Restriction
(No_Obsolescent_Features
, N
);
3308 if Warn_On_Obsolescent_Feature
then
3310 ("?j?at clause is an obsolescent feature (RM J.7(2))", N
);
3312 ("\?j?use address attribute definition clause instead", N
);
3315 -- Rewrite as address clause
3318 Make_Attribute_Definition_Clause
(Sloc
(N
),
3319 Name
=> Identifier
(N
),
3320 Chars
=> Name_Address
,
3321 Expression
=> Expression
(N
)));
3323 -- We preserve Comes_From_Source, since logically the clause still comes
3324 -- from the source program even though it is changed in form.
3326 Set_Comes_From_Source
(N
, CS
);
3328 -- Analyze rewritten clause
3330 Analyze_Attribute_Definition_Clause
(N
);
3331 end Analyze_At_Clause
;
3333 -----------------------------------------
3334 -- Analyze_Attribute_Definition_Clause --
3335 -----------------------------------------
3337 procedure Analyze_Attribute_Definition_Clause
(N
: Node_Id
) is
3338 Loc
: constant Source_Ptr
:= Sloc
(N
);
3339 Nam
: constant Node_Id
:= Name
(N
);
3340 Attr
: constant Name_Id
:= Chars
(N
);
3341 Expr
: constant Node_Id
:= Expression
(N
);
3342 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Attr
);
3345 -- The entity of Nam after it is analyzed. In the case of an incomplete
3346 -- type, this is the underlying type.
3349 -- The underlying entity to which the attribute applies. Generally this
3350 -- is the Underlying_Type of Ent, except in the case where the clause
3351 -- applies to full view of incomplete type or private type in which case
3352 -- U_Ent is just a copy of Ent.
3354 FOnly
: Boolean := False;
3355 -- Reset to True for subtype specific attribute (Alignment, Size)
3356 -- and for stream attributes, i.e. those cases where in the call to
3357 -- Rep_Item_Too_Late, FOnly is set True so that only the freezing rules
3358 -- are checked. Note that the case of stream attributes is not clear
3359 -- from the RM, but see AI95-00137. Also, the RM seems to disallow
3360 -- Storage_Size for derived task types, but that is also clearly
3363 procedure Analyze_Stream_TSS_Definition
(TSS_Nam
: TSS_Name_Type
);
3364 -- Common processing for 'Read, 'Write, 'Input and 'Output attribute
3365 -- definition clauses.
3367 function Duplicate_Clause
return Boolean;
3368 -- This routine checks if the aspect for U_Ent being given by attribute
3369 -- definition clause N is for an aspect that has already been specified,
3370 -- and if so gives an error message. If there is a duplicate, True is
3371 -- returned, otherwise if there is no error, False is returned.
3373 procedure Check_Indexing_Functions
;
3374 -- Check that the function in Constant_Indexing or Variable_Indexing
3375 -- attribute has the proper type structure. If the name is overloaded,
3376 -- check that some interpretation is legal.
3378 procedure Check_Iterator_Functions
;
3379 -- Check that there is a single function in Default_Iterator attribute
3380 -- has the proper type structure.
3382 function Check_Primitive_Function
(Subp
: Entity_Id
) return Boolean;
3383 -- Common legality check for the previous two
3385 -----------------------------------
3386 -- Analyze_Stream_TSS_Definition --
3387 -----------------------------------
3389 procedure Analyze_Stream_TSS_Definition
(TSS_Nam
: TSS_Name_Type
) is
3390 Subp
: Entity_Id
:= Empty
;
3395 Is_Read
: constant Boolean := (TSS_Nam
= TSS_Stream_Read
);
3396 -- True for Read attribute, false for other attributes
3398 function Has_Good_Profile
(Subp
: Entity_Id
) return Boolean;
3399 -- Return true if the entity is a subprogram with an appropriate
3400 -- profile for the attribute being defined.
3402 ----------------------
3403 -- Has_Good_Profile --
3404 ----------------------
3406 function Has_Good_Profile
(Subp
: Entity_Id
) return Boolean is
3408 Is_Function
: constant Boolean := (TSS_Nam
= TSS_Stream_Input
);
3409 Expected_Ekind
: constant array (Boolean) of Entity_Kind
:=
3410 (False => E_Procedure
, True => E_Function
);
3414 if Ekind
(Subp
) /= Expected_Ekind
(Is_Function
) then
3418 F
:= First_Formal
(Subp
);
3421 or else Ekind
(Etype
(F
)) /= E_Anonymous_Access_Type
3422 or else Designated_Type
(Etype
(F
)) /=
3423 Class_Wide_Type
(RTE
(RE_Root_Stream_Type
))
3428 if not Is_Function
then
3432 Expected_Mode
: constant array (Boolean) of Entity_Kind
:=
3433 (False => E_In_Parameter
,
3434 True => E_Out_Parameter
);
3436 if Parameter_Mode
(F
) /= Expected_Mode
(Is_Read
) then
3443 -- If the attribute specification comes from an aspect
3444 -- specification for a class-wide stream, the parameter must be
3445 -- a class-wide type of the entity to which the aspect applies.
3447 if From_Aspect_Specification
(N
)
3448 and then Class_Present
(Parent
(N
))
3449 and then Is_Class_Wide_Type
(Typ
)
3455 Typ
:= Etype
(Subp
);
3458 -- Verify that the prefix of the attribute and the local name for
3459 -- the type of the formal match.
3461 if Base_Type
(Typ
) /= Base_Type
(Ent
)
3462 or else Present
((Next_Formal
(F
)))
3466 elsif not Is_Scalar_Type
(Typ
)
3467 and then not Is_First_Subtype
(Typ
)
3468 and then not Is_Class_Wide_Type
(Typ
)
3475 end Has_Good_Profile
;
3477 -- Start of processing for Analyze_Stream_TSS_Definition
3482 if not Is_Type
(U_Ent
) then
3483 Error_Msg_N
("local name must be a subtype", Nam
);
3486 elsif not Is_First_Subtype
(U_Ent
) then
3487 Error_Msg_N
("local name must be a first subtype", Nam
);
3491 Pnam
:= TSS
(Base_Type
(U_Ent
), TSS_Nam
);
3493 -- If Pnam is present, it can be either inherited from an ancestor
3494 -- type (in which case it is legal to redefine it for this type), or
3495 -- be a previous definition of the attribute for the same type (in
3496 -- which case it is illegal).
3498 -- In the first case, it will have been analyzed already, and we
3499 -- can check that its profile does not match the expected profile
3500 -- for a stream attribute of U_Ent. In the second case, either Pnam
3501 -- has been analyzed (and has the expected profile), or it has not
3502 -- been analyzed yet (case of a type that has not been frozen yet
3503 -- and for which the stream attribute has been set using Set_TSS).
3506 and then (No
(First_Entity
(Pnam
)) or else Has_Good_Profile
(Pnam
))
3508 Error_Msg_Sloc
:= Sloc
(Pnam
);
3509 Error_Msg_Name_1
:= Attr
;
3510 Error_Msg_N
("% attribute already defined #", Nam
);
3516 if Is_Entity_Name
(Expr
) then
3517 if not Is_Overloaded
(Expr
) then
3518 if Has_Good_Profile
(Entity
(Expr
)) then
3519 Subp
:= Entity
(Expr
);
3523 Get_First_Interp
(Expr
, I
, It
);
3524 while Present
(It
.Nam
) loop
3525 if Has_Good_Profile
(It
.Nam
) then
3530 Get_Next_Interp
(I
, It
);
3535 if Present
(Subp
) then
3536 if Is_Abstract_Subprogram
(Subp
) then
3537 Error_Msg_N
("stream subprogram must not be abstract", Expr
);
3540 -- Test for stream subprogram for interface type being non-null
3542 elsif Is_Interface
(U_Ent
)
3543 and then not Inside_A_Generic
3544 and then Ekind
(Subp
) = E_Procedure
3548 (Unit_Declaration_Node
(Ultimate_Alias
(Subp
))))
3551 ("stream subprogram for interface type "
3552 & "must be null procedure", Expr
);
3555 Set_Entity
(Expr
, Subp
);
3556 Set_Etype
(Expr
, Etype
(Subp
));
3558 New_Stream_Subprogram
(N
, U_Ent
, Subp
, TSS_Nam
);
3561 Error_Msg_Name_1
:= Attr
;
3562 Error_Msg_N
("incorrect expression for% attribute", Expr
);
3564 end Analyze_Stream_TSS_Definition
;
3566 ------------------------------
3567 -- Check_Indexing_Functions --
3568 ------------------------------
3570 procedure Check_Indexing_Functions
is
3571 Indexing_Found
: Boolean := False;
3573 procedure Check_One_Function
(Subp
: Entity_Id
);
3574 -- Check one possible interpretation. Sets Indexing_Found True if a
3575 -- legal indexing function is found.
3577 procedure Illegal_Indexing
(Msg
: String);
3578 -- Diagnose illegal indexing function if not overloaded. In the
3579 -- overloaded case indicate that no legal interpretation exists.
3581 ------------------------
3582 -- Check_One_Function --
3583 ------------------------
3585 procedure Check_One_Function
(Subp
: Entity_Id
) is
3586 Default_Element
: Node_Id
;
3587 Ret_Type
: constant Entity_Id
:= Etype
(Subp
);
3590 if not Is_Overloadable
(Subp
) then
3591 Illegal_Indexing
("illegal indexing function for type&");
3594 elsif Scope
(Subp
) /= Scope
(Ent
) then
3595 if Nkind
(Expr
) = N_Expanded_Name
then
3597 -- Indexing function can't be declared elsewhere
3600 ("indexing function must be declared in scope of type&");
3605 elsif No
(First_Formal
(Subp
)) then
3607 ("Indexing requires a function that applies to type&");
3610 elsif No
(Next_Formal
(First_Formal
(Subp
))) then
3612 ("indexing function must have at least two parameters");
3615 elsif Is_Derived_Type
(Ent
) then
3616 if (Attr
= Name_Constant_Indexing
3618 (Find_Aspect
(Etype
(Ent
), Aspect_Constant_Indexing
)))
3620 or else (Attr
= Name_Variable_Indexing
3622 (Find_Aspect
(Etype
(Ent
), Aspect_Variable_Indexing
)))
3624 if Debug_Flag_Dot_XX
then
3629 ("indexing function already inherited "
3630 & "from parent type");
3636 if not Check_Primitive_Function
(Subp
)
3639 ("Indexing aspect requires a function that applies to type&");
3643 -- If partial declaration exists, verify that it is not tagged.
3645 if Ekind
(Current_Scope
) = E_Package
3646 and then Has_Private_Declaration
(Ent
)
3647 and then From_Aspect_Specification
(N
)
3649 List_Containing
(Parent
(Ent
)) =
3650 Private_Declarations
3651 (Specification
(Unit_Declaration_Node
(Current_Scope
)))
3652 and then Nkind
(N
) = N_Attribute_Definition_Clause
3659 First
(Visible_Declarations
3661 (Unit_Declaration_Node
(Current_Scope
))));
3663 while Present
(Decl
) loop
3664 if Nkind
(Decl
) = N_Private_Type_Declaration
3665 and then Ent
= Full_View
(Defining_Identifier
(Decl
))
3666 and then Tagged_Present
(Decl
)
3667 and then No
(Aspect_Specifications
(Decl
))
3670 ("Indexing aspect cannot be specified on full view "
3671 & "if partial view is tagged");
3680 -- An indexing function must return either the default element of
3681 -- the container, or a reference type. For variable indexing it
3682 -- must be the latter.
3685 Find_Value_Of_Aspect
3686 (Etype
(First_Formal
(Subp
)), Aspect_Iterator_Element
);
3688 if Present
(Default_Element
) then
3689 Analyze
(Default_Element
);
3691 if Is_Entity_Name
(Default_Element
)
3692 and then not Covers
(Entity
(Default_Element
), Ret_Type
)
3696 ("wrong return type for indexing function");
3701 -- For variable_indexing the return type must be a reference type
3703 if Attr
= Name_Variable_Indexing
then
3704 if not Has_Implicit_Dereference
(Ret_Type
) then
3706 ("variable indexing must return a reference type");
3709 elsif Is_Access_Constant
(Etype
(First_Discriminant
(Ret_Type
)))
3712 ("variable indexing must return an access to variable");
3717 if Has_Implicit_Dereference
(Ret_Type
)
3719 Is_Access_Constant
(Etype
(First_Discriminant
(Ret_Type
)))
3722 ("constant indexing must return an access to constant");
3725 elsif Is_Access_Type
(Etype
(First_Formal
(Subp
)))
3726 and then not Is_Access_Constant
(Etype
(First_Formal
(Subp
)))
3729 ("constant indexing must apply to an access to constant");
3734 -- All checks succeeded.
3736 Indexing_Found
:= True;
3737 end Check_One_Function
;
3739 -----------------------
3740 -- Illegal_Indexing --
3741 -----------------------
3743 procedure Illegal_Indexing
(Msg
: String) is
3745 Error_Msg_NE
(Msg
, N
, Ent
);
3746 end Illegal_Indexing
;
3748 -- Start of processing for Check_Indexing_Functions
3757 if not Is_Overloaded
(Expr
) then
3758 Check_One_Function
(Entity
(Expr
));
3766 Indexing_Found
:= False;
3767 Get_First_Interp
(Expr
, I
, It
);
3768 while Present
(It
.Nam
) loop
3770 -- Note that analysis will have added the interpretation
3771 -- that corresponds to the dereference. We only check the
3772 -- subprogram itself.
3774 if Is_Overloadable
(It
.Nam
) then
3775 Check_One_Function
(It
.Nam
);
3778 Get_Next_Interp
(I
, It
);
3783 if not Indexing_Found
and then not Error_Posted
(N
) then
3785 ("aspect Indexing requires a local function that "
3786 & "applies to type&", Expr
, Ent
);
3788 end Check_Indexing_Functions
;
3790 ------------------------------
3791 -- Check_Iterator_Functions --
3792 ------------------------------
3794 procedure Check_Iterator_Functions
is
3795 Default
: Entity_Id
;
3797 function Valid_Default_Iterator
(Subp
: Entity_Id
) return Boolean;
3798 -- Check one possible interpretation for validity
3800 ----------------------------
3801 -- Valid_Default_Iterator --
3802 ----------------------------
3804 function Valid_Default_Iterator
(Subp
: Entity_Id
) return Boolean is
3808 if not Check_Primitive_Function
(Subp
) then
3811 Formal
:= First_Formal
(Subp
);
3814 -- False if any subsequent formal has no default expression
3816 Formal
:= Next_Formal
(Formal
);
3817 while Present
(Formal
) loop
3818 if No
(Expression
(Parent
(Formal
))) then
3822 Next_Formal
(Formal
);
3825 -- True if all subsequent formals have default expressions
3828 end Valid_Default_Iterator
;
3830 -- Start of processing for Check_Iterator_Functions
3835 if not Is_Entity_Name
(Expr
) then
3836 Error_Msg_N
("aspect Iterator must be a function name", Expr
);
3839 if not Is_Overloaded
(Expr
) then
3840 if not Check_Primitive_Function
(Entity
(Expr
)) then
3842 ("aspect Indexing requires a function that applies to type&",
3843 Entity
(Expr
), Ent
);
3846 if not Valid_Default_Iterator
(Entity
(Expr
)) then
3847 Error_Msg_N
("improper function for default iterator", Expr
);
3857 Get_First_Interp
(Expr
, I
, It
);
3858 while Present
(It
.Nam
) loop
3859 if not Check_Primitive_Function
(It
.Nam
)
3860 or else not Valid_Default_Iterator
(It
.Nam
)
3864 elsif Present
(Default
) then
3865 Error_Msg_N
("default iterator must be unique", Expr
);
3871 Get_Next_Interp
(I
, It
);
3875 if Present
(Default
) then
3876 Set_Entity
(Expr
, Default
);
3877 Set_Is_Overloaded
(Expr
, False);
3880 end Check_Iterator_Functions
;
3882 -------------------------------
3883 -- Check_Primitive_Function --
3884 -------------------------------
3886 function Check_Primitive_Function
(Subp
: Entity_Id
) return Boolean is
3890 if Ekind
(Subp
) /= E_Function
then
3894 if No
(First_Formal
(Subp
)) then
3897 Ctrl
:= Etype
(First_Formal
(Subp
));
3901 or else Ctrl
= Class_Wide_Type
(Ent
)
3903 (Ekind
(Ctrl
) = E_Anonymous_Access_Type
3905 (Designated_Type
(Ctrl
) = Ent
3906 or else Designated_Type
(Ctrl
) = Class_Wide_Type
(Ent
)))
3915 end Check_Primitive_Function
;
3917 ----------------------
3918 -- Duplicate_Clause --
3919 ----------------------
3921 function Duplicate_Clause
return Boolean is
3925 -- Nothing to do if this attribute definition clause comes from
3926 -- an aspect specification, since we could not be duplicating an
3927 -- explicit clause, and we dealt with the case of duplicated aspects
3928 -- in Analyze_Aspect_Specifications.
3930 if From_Aspect_Specification
(N
) then
3934 -- Otherwise current clause may duplicate previous clause, or a
3935 -- previously given pragma or aspect specification for the same
3938 A
:= Get_Rep_Item
(U_Ent
, Chars
(N
), Check_Parents
=> False);
3941 Error_Msg_Name_1
:= Chars
(N
);
3942 Error_Msg_Sloc
:= Sloc
(A
);
3944 Error_Msg_NE
("aspect% for & previously given#", N
, U_Ent
);
3949 end Duplicate_Clause
;
3951 -- Start of processing for Analyze_Attribute_Definition_Clause
3954 -- The following code is a defense against recursion. Not clear that
3955 -- this can happen legitimately, but perhaps some error situations can
3956 -- cause it, and we did see this recursion during testing.
3958 if Analyzed
(N
) then
3961 Set_Analyzed
(N
, True);
3964 -- Ignore some selected attributes in CodePeer mode since they are not
3965 -- relevant in this context.
3967 if CodePeer_Mode
then
3970 -- Ignore Component_Size in CodePeer mode, to avoid changing the
3971 -- internal representation of types by implicitly packing them.
3973 when Attribute_Component_Size
=>
3974 Rewrite
(N
, Make_Null_Statement
(Sloc
(N
)));
3982 -- Process Ignore_Rep_Clauses option
3984 if Ignore_Rep_Clauses
then
3987 -- The following should be ignored. They do not affect legality
3988 -- and may be target dependent. The basic idea of -gnatI is to
3989 -- ignore any rep clauses that may be target dependent but do not
3990 -- affect legality (except possibly to be rejected because they
3991 -- are incompatible with the compilation target).
3993 when Attribute_Alignment |
3994 Attribute_Bit_Order |
3995 Attribute_Component_Size |
3996 Attribute_Machine_Radix |
3997 Attribute_Object_Size |
4000 Attribute_Stream_Size |
4001 Attribute_Value_Size
=>
4002 Kill_Rep_Clause
(N
);
4005 -- The following should not be ignored, because in the first place
4006 -- they are reasonably portable, and should not cause problems
4007 -- in compiling code from another target, and also they do affect
4008 -- legality, e.g. failing to provide a stream attribute for a type
4009 -- may make a program illegal.
4011 when Attribute_External_Tag |
4015 Attribute_Simple_Storage_Pool |
4016 Attribute_Storage_Pool |
4017 Attribute_Storage_Size |
4021 -- We do not do anything here with address clauses, they will be
4022 -- removed by Freeze later on, but for now, it works better to
4023 -- keep then in the tree.
4025 when Attribute_Address
=>
4028 -- Other cases are errors ("attribute& cannot be set with
4029 -- definition clause"), which will be caught below.
4037 Ent
:= Entity
(Nam
);
4039 if Rep_Item_Too_Early
(Ent
, N
) then
4043 -- Rep clause applies to full view of incomplete type or private type if
4044 -- we have one (if not, this is a premature use of the type). However,
4045 -- certain semantic checks need to be done on the specified entity (i.e.
4046 -- the private view), so we save it in Ent.
4048 if Is_Private_Type
(Ent
)
4049 and then Is_Derived_Type
(Ent
)
4050 and then not Is_Tagged_Type
(Ent
)
4051 and then No
(Full_View
(Ent
))
4053 -- If this is a private type whose completion is a derivation from
4054 -- another private type, there is no full view, and the attribute
4055 -- belongs to the type itself, not its underlying parent.
4059 elsif Ekind
(Ent
) = E_Incomplete_Type
then
4061 -- The attribute applies to the full view, set the entity of the
4062 -- attribute definition accordingly.
4064 Ent
:= Underlying_Type
(Ent
);
4066 Set_Entity
(Nam
, Ent
);
4069 U_Ent
:= Underlying_Type
(Ent
);
4072 -- Avoid cascaded error
4074 if Etype
(Nam
) = Any_Type
then
4077 -- Must be declared in current scope or in case of an aspect
4078 -- specification, must be visible in current scope.
4080 elsif Scope
(Ent
) /= Current_Scope
4082 not (From_Aspect_Specification
(N
)
4083 and then Scope_Within_Or_Same
(Current_Scope
, Scope
(Ent
)))
4085 Error_Msg_N
("entity must be declared in this scope", Nam
);
4088 -- Must not be a source renaming (we do have some cases where the
4089 -- expander generates a renaming, and those cases are OK, in such
4090 -- cases any attribute applies to the renamed object as well).
4092 elsif Is_Object
(Ent
)
4093 and then Present
(Renamed_Object
(Ent
))
4095 -- Case of renamed object from source, this is an error
4097 if Comes_From_Source
(Renamed_Object
(Ent
)) then
4098 Get_Name_String
(Chars
(N
));
4099 Error_Msg_Strlen
:= Name_Len
;
4100 Error_Msg_String
(1 .. Name_Len
) := Name_Buffer
(1 .. Name_Len
);
4102 ("~ clause not allowed for a renaming declaration "
4103 & "(RM 13.1(6))", Nam
);
4106 -- For the case of a compiler generated renaming, the attribute
4107 -- definition clause applies to the renamed object created by the
4108 -- expander. The easiest general way to handle this is to create a
4109 -- copy of the attribute definition clause for this object.
4111 elsif Is_Entity_Name
(Renamed_Object
(Ent
)) then
4113 Make_Attribute_Definition_Clause
(Loc
,
4115 New_Occurrence_Of
(Entity
(Renamed_Object
(Ent
)), Loc
),
4117 Expression
=> Duplicate_Subexpr
(Expression
(N
))));
4119 -- If the renamed object is not an entity, it must be a dereference
4120 -- of an unconstrained function call, and we must introduce a new
4121 -- declaration to capture the expression. This is needed in the case
4122 -- of 'Alignment, where the original declaration must be rewritten.
4126 (Nkind
(Renamed_Object
(Ent
)) = N_Explicit_Dereference
);
4130 -- If no underlying entity, use entity itself, applies to some
4131 -- previously detected error cases ???
4133 elsif No
(U_Ent
) then
4136 -- Cannot specify for a subtype (exception Object/Value_Size)
4138 elsif Is_Type
(U_Ent
)
4139 and then not Is_First_Subtype
(U_Ent
)
4140 and then Id
/= Attribute_Object_Size
4141 and then Id
/= Attribute_Value_Size
4142 and then not From_At_Mod
(N
)
4144 Error_Msg_N
("cannot specify attribute for subtype", Nam
);
4148 Set_Entity
(N
, U_Ent
);
4149 Check_Restriction_No_Use_Of_Attribute
(N
);
4151 -- Switch on particular attribute
4159 -- Address attribute definition clause
4161 when Attribute_Address
=> Address
: begin
4163 -- A little error check, catch for X'Address use X'Address;
4165 if Nkind
(Nam
) = N_Identifier
4166 and then Nkind
(Expr
) = N_Attribute_Reference
4167 and then Attribute_Name
(Expr
) = Name_Address
4168 and then Nkind
(Prefix
(Expr
)) = N_Identifier
4169 and then Chars
(Nam
) = Chars
(Prefix
(Expr
))
4172 ("address for & is self-referencing", Prefix
(Expr
), Ent
);
4176 -- Not that special case, carry on with analysis of expression
4178 Analyze_And_Resolve
(Expr
, RTE
(RE_Address
));
4180 -- Even when ignoring rep clauses we need to indicate that the
4181 -- entity has an address clause and thus it is legal to declare
4182 -- it imported. Freeze will get rid of the address clause later.
4184 if Ignore_Rep_Clauses
then
4185 if Ekind_In
(U_Ent
, E_Variable
, E_Constant
) then
4186 Record_Rep_Item
(U_Ent
, N
);
4192 if Duplicate_Clause
then
4195 -- Case of address clause for subprogram
4197 elsif Is_Subprogram
(U_Ent
) then
4198 if Has_Homonym
(U_Ent
) then
4200 ("address clause cannot be given " &
4201 "for overloaded subprogram",
4206 -- For subprograms, all address clauses are permitted, and we
4207 -- mark the subprogram as having a deferred freeze so that Gigi
4208 -- will not elaborate it too soon.
4210 -- Above needs more comments, what is too soon about???
4212 Set_Has_Delayed_Freeze
(U_Ent
);
4214 -- Case of address clause for entry
4216 elsif Ekind
(U_Ent
) = E_Entry
then
4217 if Nkind
(Parent
(N
)) = N_Task_Body
then
4219 ("entry address must be specified in task spec", Nam
);
4223 -- For entries, we require a constant address
4225 Check_Constant_Address_Clause
(Expr
, U_Ent
);
4227 -- Special checks for task types
4229 if Is_Task_Type
(Scope
(U_Ent
))
4230 and then Comes_From_Source
(Scope
(U_Ent
))
4233 ("??entry address declared for entry in task type", N
);
4235 ("\??only one task can be declared of this type", N
);
4238 -- Entry address clauses are obsolescent
4240 Check_Restriction
(No_Obsolescent_Features
, N
);
4242 if Warn_On_Obsolescent_Feature
then
4244 ("?j?attaching interrupt to task entry is an " &
4245 "obsolescent feature (RM J.7.1)", N
);
4247 ("\?j?use interrupt procedure instead", N
);
4250 -- Case of an address clause for a controlled object which we
4251 -- consider to be erroneous.
4253 elsif Is_Controlled
(Etype
(U_Ent
))
4254 or else Has_Controlled_Component
(Etype
(U_Ent
))
4257 ("??controlled object& must not be overlaid", Nam
, U_Ent
);
4259 ("\??Program_Error will be raised at run time", Nam
);
4260 Insert_Action
(Declaration_Node
(U_Ent
),
4261 Make_Raise_Program_Error
(Loc
,
4262 Reason
=> PE_Overlaid_Controlled_Object
));
4265 -- Case of address clause for a (non-controlled) object
4268 Ekind
(U_Ent
) = E_Variable
4270 Ekind
(U_Ent
) = E_Constant
4273 Expr
: constant Node_Id
:= Expression
(N
);
4278 -- Exported variables cannot have an address clause, because
4279 -- this cancels the effect of the pragma Export.
4281 if Is_Exported
(U_Ent
) then
4283 ("cannot export object with address clause", Nam
);
4287 Find_Overlaid_Entity
(N
, O_Ent
, Off
);
4289 -- Overlaying controlled objects is erroneous
4292 and then (Has_Controlled_Component
(Etype
(O_Ent
))
4293 or else Is_Controlled
(Etype
(O_Ent
)))
4296 ("??cannot overlay with controlled object", Expr
);
4298 ("\??Program_Error will be raised at run time", Expr
);
4299 Insert_Action
(Declaration_Node
(U_Ent
),
4300 Make_Raise_Program_Error
(Loc
,
4301 Reason
=> PE_Overlaid_Controlled_Object
));
4304 elsif Present
(O_Ent
)
4305 and then Ekind
(U_Ent
) = E_Constant
4306 and then not Is_Constant_Object
(O_Ent
)
4308 Error_Msg_N
("??constant overlays a variable", Expr
);
4310 -- Imported variables can have an address clause, but then
4311 -- the import is pretty meaningless except to suppress
4312 -- initializations, so we do not need such variables to
4313 -- be statically allocated (and in fact it causes trouble
4314 -- if the address clause is a local value).
4316 elsif Is_Imported
(U_Ent
) then
4317 Set_Is_Statically_Allocated
(U_Ent
, False);
4320 -- We mark a possible modification of a variable with an
4321 -- address clause, since it is likely aliasing is occurring.
4323 Note_Possible_Modification
(Nam
, Sure
=> False);
4325 -- Here we are checking for explicit overlap of one variable
4326 -- by another, and if we find this then mark the overlapped
4327 -- variable as also being volatile to prevent unwanted
4328 -- optimizations. This is a significant pessimization so
4329 -- avoid it when there is an offset, i.e. when the object
4330 -- is composite; they cannot be optimized easily anyway.
4333 and then Is_Object
(O_Ent
)
4336 -- The following test is an expedient solution to what
4337 -- is really a problem in CodePeer. Suppressing the
4338 -- Set_Treat_As_Volatile call here prevents later
4339 -- generation (in some cases) of trees that CodePeer
4340 -- should, but currently does not, handle correctly.
4341 -- This test should probably be removed when CodePeer
4342 -- is improved, just because we want the tree CodePeer
4343 -- analyzes to match the tree for which we generate code
4344 -- as closely as is practical. ???
4346 and then not CodePeer_Mode
4348 -- ??? O_Ent might not be in current unit
4350 Set_Treat_As_Volatile
(O_Ent
);
4353 -- Legality checks on the address clause for initialized
4354 -- objects is deferred until the freeze point, because
4355 -- a subsequent pragma might indicate that the object
4356 -- is imported and thus not initialized. Also, the address
4357 -- clause might involve entities that have yet to be
4360 Set_Has_Delayed_Freeze
(U_Ent
);
4362 -- If an initialization call has been generated for this
4363 -- object, it needs to be deferred to after the freeze node
4364 -- we have just now added, otherwise GIGI will see a
4365 -- reference to the variable (as actual to the IP call)
4366 -- before its definition.
4369 Init_Call
: constant Node_Id
:=
4370 Remove_Init_Call
(U_Ent
, N
);
4373 if Present
(Init_Call
) then
4374 Append_Freeze_Action
(U_Ent
, Init_Call
);
4376 -- Reset Initialization_Statements pointer so that
4377 -- if there is a pragma Import further down, it can
4378 -- clear any default initialization.
4380 Set_Initialization_Statements
(U_Ent
, Init_Call
);
4384 if Is_Exported
(U_Ent
) then
4386 ("& cannot be exported if an address clause is given",
4389 ("\define and export a variable "
4390 & "that holds its address instead", Nam
);
4393 -- Entity has delayed freeze, so we will generate an
4394 -- alignment check at the freeze point unless suppressed.
4396 if not Range_Checks_Suppressed
(U_Ent
)
4397 and then not Alignment_Checks_Suppressed
(U_Ent
)
4399 Set_Check_Address_Alignment
(N
);
4402 -- Kill the size check code, since we are not allocating
4403 -- the variable, it is somewhere else.
4405 Kill_Size_Check_Code
(U_Ent
);
4407 -- If the address clause is of the form:
4409 -- for Y'Address use X'Address
4413 -- Const : constant Address := X'Address;
4415 -- for Y'Address use Const;
4417 -- then we make an entry in the table for checking the size
4418 -- and alignment of the overlaying variable. We defer this
4419 -- check till after code generation to take full advantage
4420 -- of the annotation done by the back end.
4422 -- If the entity has a generic type, the check will be
4423 -- performed in the instance if the actual type justifies
4424 -- it, and we do not insert the clause in the table to
4425 -- prevent spurious warnings.
4427 -- Note: we used to test Comes_From_Source and only give
4428 -- this warning for source entities, but we have removed
4429 -- this test. It really seems bogus to generate overlays
4430 -- that would trigger this warning in generated code.
4431 -- Furthermore, by removing the test, we handle the
4432 -- aspect case properly.
4434 if Address_Clause_Overlay_Warnings
4435 and then Present
(O_Ent
)
4436 and then Is_Object
(O_Ent
)
4438 if not Is_Generic_Type
(Etype
(U_Ent
)) then
4439 Address_Clause_Checks
.Append
((N
, U_Ent
, O_Ent
, Off
));
4442 -- If variable overlays a constant view, and we are
4443 -- warning on overlays, then mark the variable as
4444 -- overlaying a constant (we will give warnings later
4445 -- if this variable is assigned).
4447 if Is_Constant_Object
(O_Ent
)
4448 and then Ekind
(U_Ent
) = E_Variable
4450 Set_Overlays_Constant
(U_Ent
);
4455 -- Not a valid entity for an address clause
4458 Error_Msg_N
("address cannot be given for &", Nam
);
4466 -- Alignment attribute definition clause
4468 when Attribute_Alignment
=> Alignment
: declare
4469 Align
: constant Uint
:= Get_Alignment_Value
(Expr
);
4470 Max_Align
: constant Uint
:= UI_From_Int
(Maximum_Alignment
);
4475 if not Is_Type
(U_Ent
)
4476 and then Ekind
(U_Ent
) /= E_Variable
4477 and then Ekind
(U_Ent
) /= E_Constant
4479 Error_Msg_N
("alignment cannot be given for &", Nam
);
4481 elsif Duplicate_Clause
then
4484 elsif Align
/= No_Uint
then
4485 Set_Has_Alignment_Clause
(U_Ent
);
4487 -- Tagged type case, check for attempt to set alignment to a
4488 -- value greater than Max_Align, and reset if so.
4490 if Is_Tagged_Type
(U_Ent
) and then Align
> Max_Align
then
4492 ("alignment for & set to Maximum_Aligment??", Nam
);
4493 Set_Alignment
(U_Ent
, Max_Align
);
4498 Set_Alignment
(U_Ent
, Align
);
4501 -- For an array type, U_Ent is the first subtype. In that case,
4502 -- also set the alignment of the anonymous base type so that
4503 -- other subtypes (such as the itypes for aggregates of the
4504 -- type) also receive the expected alignment.
4506 if Is_Array_Type
(U_Ent
) then
4507 Set_Alignment
(Base_Type
(U_Ent
), Align
);
4516 -- Bit_Order attribute definition clause
4518 when Attribute_Bit_Order
=> Bit_Order
: declare
4520 if not Is_Record_Type
(U_Ent
) then
4522 ("Bit_Order can only be defined for record type", Nam
);
4524 elsif Duplicate_Clause
then
4528 Analyze_And_Resolve
(Expr
, RTE
(RE_Bit_Order
));
4530 if Etype
(Expr
) = Any_Type
then
4533 elsif not Is_OK_Static_Expression
(Expr
) then
4534 Flag_Non_Static_Expr
4535 ("Bit_Order requires static expression!", Expr
);
4538 if (Expr_Value
(Expr
) = 0) /= Bytes_Big_Endian
then
4539 Set_Reverse_Bit_Order
(Base_Type
(U_Ent
), True);
4545 --------------------
4546 -- Component_Size --
4547 --------------------
4549 -- Component_Size attribute definition clause
4551 when Attribute_Component_Size
=> Component_Size_Case
: declare
4552 Csize
: constant Uint
:= Static_Integer
(Expr
);
4556 New_Ctyp
: Entity_Id
;
4560 if not Is_Array_Type
(U_Ent
) then
4561 Error_Msg_N
("component size requires array type", Nam
);
4565 Btype
:= Base_Type
(U_Ent
);
4566 Ctyp
:= Component_Type
(Btype
);
4568 if Duplicate_Clause
then
4571 elsif Rep_Item_Too_Early
(Btype
, N
) then
4574 elsif Csize
/= No_Uint
then
4575 Check_Size
(Expr
, Ctyp
, Csize
, Biased
);
4577 -- For the biased case, build a declaration for a subtype that
4578 -- will be used to represent the biased subtype that reflects
4579 -- the biased representation of components. We need the subtype
4580 -- to get proper conversions on referencing elements of the
4581 -- array. Note: component size clauses are ignored in VM mode.
4583 if VM_Target
= No_VM
then
4586 Make_Defining_Identifier
(Loc
,
4588 New_External_Name
(Chars
(U_Ent
), 'C', 0, 'T'));
4591 Make_Subtype_Declaration
(Loc
,
4592 Defining_Identifier
=> New_Ctyp
,
4593 Subtype_Indication
=>
4594 New_Occurrence_Of
(Component_Type
(Btype
), Loc
));
4596 Set_Parent
(Decl
, N
);
4597 Analyze
(Decl
, Suppress
=> All_Checks
);
4599 Set_Has_Delayed_Freeze
(New_Ctyp
, False);
4600 Set_Esize
(New_Ctyp
, Csize
);
4601 Set_RM_Size
(New_Ctyp
, Csize
);
4602 Init_Alignment
(New_Ctyp
);
4603 Set_Is_Itype
(New_Ctyp
, True);
4604 Set_Associated_Node_For_Itype
(New_Ctyp
, U_Ent
);
4606 Set_Component_Type
(Btype
, New_Ctyp
);
4607 Set_Biased
(New_Ctyp
, N
, "component size clause");
4610 Set_Component_Size
(Btype
, Csize
);
4612 -- For VM case, we ignore component size clauses
4615 -- Give a warning unless we are in GNAT mode, in which case
4616 -- the warning is suppressed since it is not useful.
4618 if not GNAT_Mode
then
4620 ("component size ignored in this configuration??", N
);
4624 -- Deal with warning on overridden size
4626 if Warn_On_Overridden_Size
4627 and then Has_Size_Clause
(Ctyp
)
4628 and then RM_Size
(Ctyp
) /= Csize
4631 ("component size overrides size clause for&?S?", N
, Ctyp
);
4634 Set_Has_Component_Size_Clause
(Btype
, True);
4635 Set_Has_Non_Standard_Rep
(Btype
, True);
4637 end Component_Size_Case
;
4639 -----------------------
4640 -- Constant_Indexing --
4641 -----------------------
4643 when Attribute_Constant_Indexing
=>
4644 Check_Indexing_Functions
;
4650 when Attribute_CPU
=> CPU
:
4652 -- CPU attribute definition clause not allowed except from aspect
4655 if From_Aspect_Specification
(N
) then
4656 if not Is_Task_Type
(U_Ent
) then
4657 Error_Msg_N
("CPU can only be defined for task", Nam
);
4659 elsif Duplicate_Clause
then
4663 -- The expression must be analyzed in the special manner
4664 -- described in "Handling of Default and Per-Object
4665 -- Expressions" in sem.ads.
4667 -- The visibility to the discriminants must be restored
4669 Push_Scope_And_Install_Discriminants
(U_Ent
);
4670 Preanalyze_Spec_Expression
(Expr
, RTE
(RE_CPU_Range
));
4671 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
4673 if not Is_OK_Static_Expression
(Expr
) then
4674 Check_Restriction
(Static_Priorities
, Expr
);
4680 ("attribute& cannot be set with definition clause", N
);
4684 ----------------------
4685 -- Default_Iterator --
4686 ----------------------
4688 when Attribute_Default_Iterator
=> Default_Iterator
: declare
4692 if not Is_Tagged_Type
(U_Ent
) then
4694 ("aspect Default_Iterator applies to tagged type", Nam
);
4697 Check_Iterator_Functions
;
4701 if not Is_Entity_Name
(Expr
)
4702 or else Ekind
(Entity
(Expr
)) /= E_Function
4704 Error_Msg_N
("aspect Iterator must be a function", Expr
);
4706 Func
:= Entity
(Expr
);
4709 if No
(First_Formal
(Func
))
4710 or else Etype
(First_Formal
(Func
)) /= U_Ent
4713 ("Default Iterator must be a primitive of&", Func
, U_Ent
);
4715 end Default_Iterator
;
4717 ------------------------
4718 -- Dispatching_Domain --
4719 ------------------------
4721 when Attribute_Dispatching_Domain
=> Dispatching_Domain
:
4723 -- Dispatching_Domain attribute definition clause not allowed
4724 -- except from aspect specification.
4726 if From_Aspect_Specification
(N
) then
4727 if not Is_Task_Type
(U_Ent
) then
4728 Error_Msg_N
("Dispatching_Domain can only be defined" &
4732 elsif Duplicate_Clause
then
4736 -- The expression must be analyzed in the special manner
4737 -- described in "Handling of Default and Per-Object
4738 -- Expressions" in sem.ads.
4740 -- The visibility to the discriminants must be restored
4742 Push_Scope_And_Install_Discriminants
(U_Ent
);
4744 Preanalyze_Spec_Expression
4745 (Expr
, RTE
(RE_Dispatching_Domain
));
4747 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
4752 ("attribute& cannot be set with definition clause", N
);
4754 end Dispatching_Domain
;
4760 when Attribute_External_Tag
=> External_Tag
:
4762 if not Is_Tagged_Type
(U_Ent
) then
4763 Error_Msg_N
("should be a tagged type", Nam
);
4766 if Duplicate_Clause
then
4770 Analyze_And_Resolve
(Expr
, Standard_String
);
4772 if not Is_OK_Static_Expression
(Expr
) then
4773 Flag_Non_Static_Expr
4774 ("static string required for tag name!", Nam
);
4777 if VM_Target
/= No_VM
then
4778 Error_Msg_Name_1
:= Attr
;
4780 ("% attribute unsupported in this configuration", Nam
);
4783 if not Is_Library_Level_Entity
(U_Ent
) then
4785 ("??non-unique external tag supplied for &", N
, U_Ent
);
4787 ("\??same external tag applies to all "
4788 & "subprogram calls", N
);
4790 ("\??corresponding internal tag cannot be obtained", N
);
4795 --------------------------
4796 -- Implicit_Dereference --
4797 --------------------------
4799 when Attribute_Implicit_Dereference
=>
4801 -- Legality checks already performed at the point of the type
4802 -- declaration, aspect is not delayed.
4810 when Attribute_Input
=>
4811 Analyze_Stream_TSS_Definition
(TSS_Stream_Input
);
4812 Set_Has_Specified_Stream_Input
(Ent
);
4814 ------------------------
4815 -- Interrupt_Priority --
4816 ------------------------
4818 when Attribute_Interrupt_Priority
=> Interrupt_Priority
:
4820 -- Interrupt_Priority attribute definition clause not allowed
4821 -- except from aspect specification.
4823 if From_Aspect_Specification
(N
) then
4824 if not (Is_Protected_Type
(U_Ent
)
4825 or else Is_Task_Type
(U_Ent
))
4828 ("Interrupt_Priority can only be defined for task" &
4829 "and protected object",
4832 elsif Duplicate_Clause
then
4836 -- The expression must be analyzed in the special manner
4837 -- described in "Handling of Default and Per-Object
4838 -- Expressions" in sem.ads.
4840 -- The visibility to the discriminants must be restored
4842 Push_Scope_And_Install_Discriminants
(U_Ent
);
4844 Preanalyze_Spec_Expression
4845 (Expr
, RTE
(RE_Interrupt_Priority
));
4847 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
4852 ("attribute& cannot be set with definition clause", N
);
4854 end Interrupt_Priority
;
4860 when Attribute_Iterable
=>
4863 if Nkind
(Expr
) /= N_Aggregate
then
4864 Error_Msg_N
("aspect Iterable must be an aggregate", Expr
);
4871 Assoc
:= First
(Component_Associations
(Expr
));
4872 while Present
(Assoc
) loop
4873 if not Is_Entity_Name
(Expression
(Assoc
)) then
4874 Error_Msg_N
("value must be a function", Assoc
);
4881 ----------------------
4882 -- Iterator_Element --
4883 ----------------------
4885 when Attribute_Iterator_Element
=>
4888 if not Is_Entity_Name
(Expr
)
4889 or else not Is_Type
(Entity
(Expr
))
4891 Error_Msg_N
("aspect Iterator_Element must be a type", Expr
);
4898 -- Machine radix attribute definition clause
4900 when Attribute_Machine_Radix
=> Machine_Radix
: declare
4901 Radix
: constant Uint
:= Static_Integer
(Expr
);
4904 if not Is_Decimal_Fixed_Point_Type
(U_Ent
) then
4905 Error_Msg_N
("decimal fixed-point type expected for &", Nam
);
4907 elsif Duplicate_Clause
then
4910 elsif Radix
/= No_Uint
then
4911 Set_Has_Machine_Radix_Clause
(U_Ent
);
4912 Set_Has_Non_Standard_Rep
(Base_Type
(U_Ent
));
4916 elsif Radix
= 10 then
4917 Set_Machine_Radix_10
(U_Ent
);
4919 Error_Msg_N
("machine radix value must be 2 or 10", Expr
);
4928 -- Object_Size attribute definition clause
4930 when Attribute_Object_Size
=> Object_Size
: declare
4931 Size
: constant Uint
:= Static_Integer
(Expr
);
4934 pragma Warnings
(Off
, Biased
);
4937 if not Is_Type
(U_Ent
) then
4938 Error_Msg_N
("Object_Size cannot be given for &", Nam
);
4940 elsif Duplicate_Clause
then
4944 Check_Size
(Expr
, U_Ent
, Size
, Biased
);
4946 if Is_Scalar_Type
(U_Ent
) then
4947 if Size
/= 8 and then Size
/= 16 and then Size
/= 32
4948 and then UI_Mod
(Size
, 64) /= 0
4951 ("Object_Size must be 8, 16, 32, or multiple of 64",
4955 elsif Size
mod 8 /= 0 then
4956 Error_Msg_N
("Object_Size must be a multiple of 8", Expr
);
4959 Set_Esize
(U_Ent
, Size
);
4960 Set_Has_Object_Size_Clause
(U_Ent
);
4961 Alignment_Check_For_Size_Change
(U_Ent
, Size
);
4969 when Attribute_Output
=>
4970 Analyze_Stream_TSS_Definition
(TSS_Stream_Output
);
4971 Set_Has_Specified_Stream_Output
(Ent
);
4977 when Attribute_Priority
=> Priority
:
4979 -- Priority attribute definition clause not allowed except from
4980 -- aspect specification.
4982 if From_Aspect_Specification
(N
) then
4983 if not (Is_Protected_Type
(U_Ent
)
4984 or else Is_Task_Type
(U_Ent
)
4985 or else Ekind
(U_Ent
) = E_Procedure
)
4988 ("Priority can only be defined for task and protected " &
4992 elsif Duplicate_Clause
then
4996 -- The expression must be analyzed in the special manner
4997 -- described in "Handling of Default and Per-Object
4998 -- Expressions" in sem.ads.
5000 -- The visibility to the discriminants must be restored
5002 Push_Scope_And_Install_Discriminants
(U_Ent
);
5003 Preanalyze_Spec_Expression
(Expr
, Standard_Integer
);
5004 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
5006 if not Is_OK_Static_Expression
(Expr
) then
5007 Check_Restriction
(Static_Priorities
, Expr
);
5013 ("attribute& cannot be set with definition clause", N
);
5021 when Attribute_Read
=>
5022 Analyze_Stream_TSS_Definition
(TSS_Stream_Read
);
5023 Set_Has_Specified_Stream_Read
(Ent
);
5025 --------------------------
5026 -- Scalar_Storage_Order --
5027 --------------------------
5029 -- Scalar_Storage_Order attribute definition clause
5031 when Attribute_Scalar_Storage_Order
=> Scalar_Storage_Order
: declare
5033 if not (Is_Record_Type
(U_Ent
) or else Is_Array_Type
(U_Ent
)) then
5035 ("Scalar_Storage_Order can only be defined for "
5036 & "record or array type", Nam
);
5038 elsif Duplicate_Clause
then
5042 Analyze_And_Resolve
(Expr
, RTE
(RE_Bit_Order
));
5044 if Etype
(Expr
) = Any_Type
then
5047 elsif not Is_OK_Static_Expression
(Expr
) then
5048 Flag_Non_Static_Expr
5049 ("Scalar_Storage_Order requires static expression!", Expr
);
5051 elsif (Expr_Value
(Expr
) = 0) /= Bytes_Big_Endian
then
5053 -- Here for the case of a non-default (i.e. non-confirming)
5054 -- Scalar_Storage_Order attribute definition.
5056 if Support_Nondefault_SSO_On_Target
then
5057 Set_Reverse_Storage_Order
(Base_Type
(U_Ent
), True);
5060 ("non-default Scalar_Storage_Order "
5061 & "not supported on target", Expr
);
5065 -- Clear SSO default indications since explicit setting of the
5066 -- order overrides the defaults.
5068 Set_SSO_Set_Low_By_Default
(Base_Type
(U_Ent
), False);
5069 Set_SSO_Set_High_By_Default
(Base_Type
(U_Ent
), False);
5071 end Scalar_Storage_Order
;
5077 -- Size attribute definition clause
5079 when Attribute_Size
=> Size
: declare
5080 Size
: constant Uint
:= Static_Integer
(Expr
);
5087 if Duplicate_Clause
then
5090 elsif not Is_Type
(U_Ent
)
5091 and then Ekind
(U_Ent
) /= E_Variable
5092 and then Ekind
(U_Ent
) /= E_Constant
5094 Error_Msg_N
("size cannot be given for &", Nam
);
5096 elsif Is_Array_Type
(U_Ent
)
5097 and then not Is_Constrained
(U_Ent
)
5100 ("size cannot be given for unconstrained array", Nam
);
5102 elsif Size
/= No_Uint
then
5103 if VM_Target
/= No_VM
and then not GNAT_Mode
then
5105 -- Size clause is not handled properly on VM targets.
5106 -- Display a warning unless we are in GNAT mode, in which
5107 -- case this is useless.
5110 ("size clauses are ignored in this configuration??", N
);
5113 if Is_Type
(U_Ent
) then
5116 Etyp
:= Etype
(U_Ent
);
5119 -- Check size, note that Gigi is in charge of checking that the
5120 -- size of an array or record type is OK. Also we do not check
5121 -- the size in the ordinary fixed-point case, since it is too
5122 -- early to do so (there may be subsequent small clause that
5123 -- affects the size). We can check the size if a small clause
5124 -- has already been given.
5126 if not Is_Ordinary_Fixed_Point_Type
(U_Ent
)
5127 or else Has_Small_Clause
(U_Ent
)
5129 Check_Size
(Expr
, Etyp
, Size
, Biased
);
5130 Set_Biased
(U_Ent
, N
, "size clause", Biased
);
5133 -- For types set RM_Size and Esize if possible
5135 if Is_Type
(U_Ent
) then
5136 Set_RM_Size
(U_Ent
, Size
);
5138 -- For elementary types, increase Object_Size to power of 2,
5139 -- but not less than a storage unit in any case (normally
5140 -- this means it will be byte addressable).
5142 -- For all other types, nothing else to do, we leave Esize
5143 -- (object size) unset, the back end will set it from the
5144 -- size and alignment in an appropriate manner.
5146 -- In both cases, we check whether the alignment must be
5147 -- reset in the wake of the size change.
5149 if Is_Elementary_Type
(U_Ent
) then
5150 if Size
<= System_Storage_Unit
then
5151 Init_Esize
(U_Ent
, System_Storage_Unit
);
5152 elsif Size
<= 16 then
5153 Init_Esize
(U_Ent
, 16);
5154 elsif Size
<= 32 then
5155 Init_Esize
(U_Ent
, 32);
5157 Set_Esize
(U_Ent
, (Size
+ 63) / 64 * 64);
5160 Alignment_Check_For_Size_Change
(U_Ent
, Esize
(U_Ent
));
5162 Alignment_Check_For_Size_Change
(U_Ent
, Size
);
5165 -- For objects, set Esize only
5168 if Is_Elementary_Type
(Etyp
) then
5169 if Size
/= System_Storage_Unit
5171 Size
/= System_Storage_Unit
* 2
5173 Size
/= System_Storage_Unit
* 4
5175 Size
/= System_Storage_Unit
* 8
5177 Error_Msg_Uint_1
:= UI_From_Int
(System_Storage_Unit
);
5178 Error_Msg_Uint_2
:= Error_Msg_Uint_1
* 8;
5180 ("size for primitive object must be a power of 2"
5181 & " in the range ^-^", N
);
5185 Set_Esize
(U_Ent
, Size
);
5188 Set_Has_Size_Clause
(U_Ent
);
5196 -- Small attribute definition clause
5198 when Attribute_Small
=> Small
: declare
5199 Implicit_Base
: constant Entity_Id
:= Base_Type
(U_Ent
);
5203 Analyze_And_Resolve
(Expr
, Any_Real
);
5205 if Etype
(Expr
) = Any_Type
then
5208 elsif not Is_OK_Static_Expression
(Expr
) then
5209 Flag_Non_Static_Expr
5210 ("small requires static expression!", Expr
);
5214 Small
:= Expr_Value_R
(Expr
);
5216 if Small
<= Ureal_0
then
5217 Error_Msg_N
("small value must be greater than zero", Expr
);
5223 if not Is_Ordinary_Fixed_Point_Type
(U_Ent
) then
5225 ("small requires an ordinary fixed point type", Nam
);
5227 elsif Has_Small_Clause
(U_Ent
) then
5228 Error_Msg_N
("small already given for &", Nam
);
5230 elsif Small
> Delta_Value
(U_Ent
) then
5232 ("small value must not be greater than delta value", Nam
);
5235 Set_Small_Value
(U_Ent
, Small
);
5236 Set_Small_Value
(Implicit_Base
, Small
);
5237 Set_Has_Small_Clause
(U_Ent
);
5238 Set_Has_Small_Clause
(Implicit_Base
);
5239 Set_Has_Non_Standard_Rep
(Implicit_Base
);
5247 -- Storage_Pool attribute definition clause
5249 when Attribute_Storage_Pool | Attribute_Simple_Storage_Pool
=> declare
5254 if Ekind
(U_Ent
) = E_Access_Subprogram_Type
then
5256 ("storage pool cannot be given for access-to-subprogram type",
5261 Ekind_In
(U_Ent
, E_Access_Type
, E_General_Access_Type
)
5264 ("storage pool can only be given for access types", Nam
);
5267 elsif Is_Derived_Type
(U_Ent
) then
5269 ("storage pool cannot be given for a derived access type",
5272 elsif Duplicate_Clause
then
5275 elsif Present
(Associated_Storage_Pool
(U_Ent
)) then
5276 Error_Msg_N
("storage pool already given for &", Nam
);
5280 -- Check for Storage_Size previously given
5283 SS
: constant Node_Id
:=
5284 Get_Attribute_Definition_Clause
5285 (U_Ent
, Attribute_Storage_Size
);
5287 if Present
(SS
) then
5288 Check_Pool_Size_Clash
(U_Ent
, N
, SS
);
5292 -- Storage_Pool case
5294 if Id
= Attribute_Storage_Pool
then
5296 (Expr
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
5298 -- In the Simple_Storage_Pool case, we allow a variable of any
5299 -- simple storage pool type, so we Resolve without imposing an
5303 Analyze_And_Resolve
(Expr
);
5305 if not Present
(Get_Rep_Pragma
5306 (Etype
(Expr
), Name_Simple_Storage_Pool_Type
))
5309 ("expression must be of a simple storage pool type", Expr
);
5313 if not Denotes_Variable
(Expr
) then
5314 Error_Msg_N
("storage pool must be a variable", Expr
);
5318 if Nkind
(Expr
) = N_Type_Conversion
then
5319 T
:= Etype
(Expression
(Expr
));
5324 -- The Stack_Bounded_Pool is used internally for implementing
5325 -- access types with a Storage_Size. Since it only work properly
5326 -- when used on one specific type, we need to check that it is not
5327 -- hijacked improperly:
5329 -- type T is access Integer;
5330 -- for T'Storage_Size use n;
5331 -- type Q is access Float;
5332 -- for Q'Storage_Size use T'Storage_Size; -- incorrect
5334 if RTE_Available
(RE_Stack_Bounded_Pool
)
5335 and then Base_Type
(T
) = RTE
(RE_Stack_Bounded_Pool
)
5337 Error_Msg_N
("non-shareable internal Pool", Expr
);
5341 -- If the argument is a name that is not an entity name, then
5342 -- we construct a renaming operation to define an entity of
5343 -- type storage pool.
5345 if not Is_Entity_Name
(Expr
)
5346 and then Is_Object_Reference
(Expr
)
5348 Pool
:= Make_Temporary
(Loc
, 'P', Expr
);
5351 Rnode
: constant Node_Id
:=
5352 Make_Object_Renaming_Declaration
(Loc
,
5353 Defining_Identifier
=> Pool
,
5355 New_Occurrence_Of
(Etype
(Expr
), Loc
),
5359 -- If the attribute definition clause comes from an aspect
5360 -- clause, then insert the renaming before the associated
5361 -- entity's declaration, since the attribute clause has
5362 -- not yet been appended to the declaration list.
5364 if From_Aspect_Specification
(N
) then
5365 Insert_Before
(Parent
(Entity
(N
)), Rnode
);
5367 Insert_Before
(N
, Rnode
);
5371 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
5374 elsif Is_Entity_Name
(Expr
) then
5375 Pool
:= Entity
(Expr
);
5377 -- If pool is a renamed object, get original one. This can
5378 -- happen with an explicit renaming, and within instances.
5380 while Present
(Renamed_Object
(Pool
))
5381 and then Is_Entity_Name
(Renamed_Object
(Pool
))
5383 Pool
:= Entity
(Renamed_Object
(Pool
));
5386 if Present
(Renamed_Object
(Pool
))
5387 and then Nkind
(Renamed_Object
(Pool
)) = N_Type_Conversion
5388 and then Is_Entity_Name
(Expression
(Renamed_Object
(Pool
)))
5390 Pool
:= Entity
(Expression
(Renamed_Object
(Pool
)));
5393 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
5395 elsif Nkind
(Expr
) = N_Type_Conversion
5396 and then Is_Entity_Name
(Expression
(Expr
))
5397 and then Nkind
(Original_Node
(Expr
)) = N_Attribute_Reference
5399 Pool
:= Entity
(Expression
(Expr
));
5400 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
5403 Error_Msg_N
("incorrect reference to a Storage Pool", Expr
);
5412 -- Storage_Size attribute definition clause
5414 when Attribute_Storage_Size
=> Storage_Size
: declare
5415 Btype
: constant Entity_Id
:= Base_Type
(U_Ent
);
5418 if Is_Task_Type
(U_Ent
) then
5420 -- Check obsolescent (but never obsolescent if from aspect)
5422 if not From_Aspect_Specification
(N
) then
5423 Check_Restriction
(No_Obsolescent_Features
, N
);
5425 if Warn_On_Obsolescent_Feature
then
5427 ("?j?storage size clause for task is an " &
5428 "obsolescent feature (RM J.9)", N
);
5429 Error_Msg_N
("\?j?use Storage_Size pragma instead", N
);
5436 if not Is_Access_Type
(U_Ent
)
5437 and then Ekind
(U_Ent
) /= E_Task_Type
5439 Error_Msg_N
("storage size cannot be given for &", Nam
);
5441 elsif Is_Access_Type
(U_Ent
) and Is_Derived_Type
(U_Ent
) then
5443 ("storage size cannot be given for a derived access type",
5446 elsif Duplicate_Clause
then
5450 Analyze_And_Resolve
(Expr
, Any_Integer
);
5452 if Is_Access_Type
(U_Ent
) then
5454 -- Check for Storage_Pool previously given
5457 SP
: constant Node_Id
:=
5458 Get_Attribute_Definition_Clause
5459 (U_Ent
, Attribute_Storage_Pool
);
5462 if Present
(SP
) then
5463 Check_Pool_Size_Clash
(U_Ent
, SP
, N
);
5467 -- Special case of for x'Storage_Size use 0
5469 if Is_OK_Static_Expression
(Expr
)
5470 and then Expr_Value
(Expr
) = 0
5472 Set_No_Pool_Assigned
(Btype
);
5476 Set_Has_Storage_Size_Clause
(Btype
);
5484 when Attribute_Stream_Size
=> Stream_Size
: declare
5485 Size
: constant Uint
:= Static_Integer
(Expr
);
5488 if Ada_Version
<= Ada_95
then
5489 Check_Restriction
(No_Implementation_Attributes
, N
);
5492 if Duplicate_Clause
then
5495 elsif Is_Elementary_Type
(U_Ent
) then
5496 if Size
/= System_Storage_Unit
5498 Size
/= System_Storage_Unit
* 2
5500 Size
/= System_Storage_Unit
* 4
5502 Size
/= System_Storage_Unit
* 8
5504 Error_Msg_Uint_1
:= UI_From_Int
(System_Storage_Unit
);
5506 ("stream size for elementary type must be a"
5507 & " power of 2 and at least ^", N
);
5509 elsif RM_Size
(U_Ent
) > Size
then
5510 Error_Msg_Uint_1
:= RM_Size
(U_Ent
);
5512 ("stream size for elementary type must be a"
5513 & " power of 2 and at least ^", N
);
5516 Set_Has_Stream_Size_Clause
(U_Ent
);
5519 Error_Msg_N
("Stream_Size cannot be given for &", Nam
);
5527 -- Value_Size attribute definition clause
5529 when Attribute_Value_Size
=> Value_Size
: declare
5530 Size
: constant Uint
:= Static_Integer
(Expr
);
5534 if not Is_Type
(U_Ent
) then
5535 Error_Msg_N
("Value_Size cannot be given for &", Nam
);
5537 elsif Duplicate_Clause
then
5540 elsif Is_Array_Type
(U_Ent
)
5541 and then not Is_Constrained
(U_Ent
)
5544 ("Value_Size cannot be given for unconstrained array", Nam
);
5547 if Is_Elementary_Type
(U_Ent
) then
5548 Check_Size
(Expr
, U_Ent
, Size
, Biased
);
5549 Set_Biased
(U_Ent
, N
, "value size clause", Biased
);
5552 Set_RM_Size
(U_Ent
, Size
);
5556 -----------------------
5557 -- Variable_Indexing --
5558 -----------------------
5560 when Attribute_Variable_Indexing
=>
5561 Check_Indexing_Functions
;
5567 when Attribute_Write
=>
5568 Analyze_Stream_TSS_Definition
(TSS_Stream_Write
);
5569 Set_Has_Specified_Stream_Write
(Ent
);
5571 -- All other attributes cannot be set
5575 ("attribute& cannot be set with definition clause", N
);
5578 -- The test for the type being frozen must be performed after any
5579 -- expression the clause has been analyzed since the expression itself
5580 -- might cause freezing that makes the clause illegal.
5582 if Rep_Item_Too_Late
(U_Ent
, N
, FOnly
) then
5585 end Analyze_Attribute_Definition_Clause
;
5587 ----------------------------
5588 -- Analyze_Code_Statement --
5589 ----------------------------
5591 procedure Analyze_Code_Statement
(N
: Node_Id
) is
5592 HSS
: constant Node_Id
:= Parent
(N
);
5593 SBody
: constant Node_Id
:= Parent
(HSS
);
5594 Subp
: constant Entity_Id
:= Current_Scope
;
5601 -- Analyze and check we get right type, note that this implements the
5602 -- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that
5603 -- is the only way that Asm_Insn could possibly be visible.
5605 Analyze_And_Resolve
(Expression
(N
));
5607 if Etype
(Expression
(N
)) = Any_Type
then
5609 elsif Etype
(Expression
(N
)) /= RTE
(RE_Asm_Insn
) then
5610 Error_Msg_N
("incorrect type for code statement", N
);
5614 Check_Code_Statement
(N
);
5616 -- Make sure we appear in the handled statement sequence of a
5617 -- subprogram (RM 13.8(3)).
5619 if Nkind
(HSS
) /= N_Handled_Sequence_Of_Statements
5620 or else Nkind
(SBody
) /= N_Subprogram_Body
5623 ("code statement can only appear in body of subprogram", N
);
5627 -- Do remaining checks (RM 13.8(3)) if not already done
5629 if not Is_Machine_Code_Subprogram
(Subp
) then
5630 Set_Is_Machine_Code_Subprogram
(Subp
);
5632 -- No exception handlers allowed
5634 if Present
(Exception_Handlers
(HSS
)) then
5636 ("exception handlers not permitted in machine code subprogram",
5637 First
(Exception_Handlers
(HSS
)));
5640 -- No declarations other than use clauses and pragmas (we allow
5641 -- certain internally generated declarations as well).
5643 Decl
:= First
(Declarations
(SBody
));
5644 while Present
(Decl
) loop
5645 DeclO
:= Original_Node
(Decl
);
5646 if Comes_From_Source
(DeclO
)
5647 and not Nkind_In
(DeclO
, N_Pragma
,
5648 N_Use_Package_Clause
,
5650 N_Implicit_Label_Declaration
)
5653 ("this declaration not allowed in machine code subprogram",
5660 -- No statements other than code statements, pragmas, and labels.
5661 -- Again we allow certain internally generated statements.
5663 -- In Ada 2012, qualified expressions are names, and the code
5664 -- statement is initially parsed as a procedure call.
5666 Stmt
:= First
(Statements
(HSS
));
5667 while Present
(Stmt
) loop
5668 StmtO
:= Original_Node
(Stmt
);
5670 -- A procedure call transformed into a code statement is OK.
5672 if Ada_Version
>= Ada_2012
5673 and then Nkind
(StmtO
) = N_Procedure_Call_Statement
5674 and then Nkind
(Name
(StmtO
)) = N_Qualified_Expression
5678 elsif Comes_From_Source
(StmtO
)
5679 and then not Nkind_In
(StmtO
, N_Pragma
,
5684 ("this statement is not allowed in machine code subprogram",
5691 end Analyze_Code_Statement
;
5693 -----------------------------------------------
5694 -- Analyze_Enumeration_Representation_Clause --
5695 -----------------------------------------------
5697 procedure Analyze_Enumeration_Representation_Clause
(N
: Node_Id
) is
5698 Ident
: constant Node_Id
:= Identifier
(N
);
5699 Aggr
: constant Node_Id
:= Array_Aggregate
(N
);
5700 Enumtype
: Entity_Id
;
5707 Err
: Boolean := False;
5708 -- Set True to avoid cascade errors and crashes on incorrect source code
5710 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Universal_Integer
));
5711 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(Universal_Integer
));
5712 -- Allowed range of universal integer (= allowed range of enum lit vals)
5716 -- Minimum and maximum values of entries
5719 -- Pointer to node for literal providing max value
5722 if Ignore_Rep_Clauses
then
5723 Kill_Rep_Clause
(N
);
5727 -- Ignore enumeration rep clauses by default in CodePeer mode,
5728 -- unless -gnatd.I is specified, as a work around for potential false
5729 -- positive messages.
5731 if CodePeer_Mode
and not Debug_Flag_Dot_II
then
5735 -- First some basic error checks
5738 Enumtype
:= Entity
(Ident
);
5740 if Enumtype
= Any_Type
5741 or else Rep_Item_Too_Early
(Enumtype
, N
)
5745 Enumtype
:= Underlying_Type
(Enumtype
);
5748 if not Is_Enumeration_Type
(Enumtype
) then
5750 ("enumeration type required, found}",
5751 Ident
, First_Subtype
(Enumtype
));
5755 -- Ignore rep clause on generic actual type. This will already have
5756 -- been flagged on the template as an error, and this is the safest
5757 -- way to ensure we don't get a junk cascaded message in the instance.
5759 if Is_Generic_Actual_Type
(Enumtype
) then
5762 -- Type must be in current scope
5764 elsif Scope
(Enumtype
) /= Current_Scope
then
5765 Error_Msg_N
("type must be declared in this scope", Ident
);
5768 -- Type must be a first subtype
5770 elsif not Is_First_Subtype
(Enumtype
) then
5771 Error_Msg_N
("cannot give enumeration rep clause for subtype", N
);
5774 -- Ignore duplicate rep clause
5776 elsif Has_Enumeration_Rep_Clause
(Enumtype
) then
5777 Error_Msg_N
("duplicate enumeration rep clause ignored", N
);
5780 -- Don't allow rep clause for standard [wide_[wide_]]character
5782 elsif Is_Standard_Character_Type
(Enumtype
) then
5783 Error_Msg_N
("enumeration rep clause not allowed for this type", N
);
5786 -- Check that the expression is a proper aggregate (no parentheses)
5788 elsif Paren_Count
(Aggr
) /= 0 then
5790 ("extra parentheses surrounding aggregate not allowed",
5794 -- All tests passed, so set rep clause in place
5797 Set_Has_Enumeration_Rep_Clause
(Enumtype
);
5798 Set_Has_Enumeration_Rep_Clause
(Base_Type
(Enumtype
));
5801 -- Now we process the aggregate. Note that we don't use the normal
5802 -- aggregate code for this purpose, because we don't want any of the
5803 -- normal expansion activities, and a number of special semantic
5804 -- rules apply (including the component type being any integer type)
5806 Elit
:= First_Literal
(Enumtype
);
5808 -- First the positional entries if any
5810 if Present
(Expressions
(Aggr
)) then
5811 Expr
:= First
(Expressions
(Aggr
));
5812 while Present
(Expr
) loop
5814 Error_Msg_N
("too many entries in aggregate", Expr
);
5818 Val
:= Static_Integer
(Expr
);
5820 -- Err signals that we found some incorrect entries processing
5821 -- the list. The final checks for completeness and ordering are
5822 -- skipped in this case.
5824 if Val
= No_Uint
then
5826 elsif Val
< Lo
or else Hi
< Val
then
5827 Error_Msg_N
("value outside permitted range", Expr
);
5831 Set_Enumeration_Rep
(Elit
, Val
);
5832 Set_Enumeration_Rep_Expr
(Elit
, Expr
);
5838 -- Now process the named entries if present
5840 if Present
(Component_Associations
(Aggr
)) then
5841 Assoc
:= First
(Component_Associations
(Aggr
));
5842 while Present
(Assoc
) loop
5843 Choice
:= First
(Choices
(Assoc
));
5845 if Present
(Next
(Choice
)) then
5847 ("multiple choice not allowed here", Next
(Choice
));
5851 if Nkind
(Choice
) = N_Others_Choice
then
5852 Error_Msg_N
("others choice not allowed here", Choice
);
5855 elsif Nkind
(Choice
) = N_Range
then
5857 -- ??? should allow zero/one element range here
5859 Error_Msg_N
("range not allowed here", Choice
);
5863 Analyze_And_Resolve
(Choice
, Enumtype
);
5865 if Error_Posted
(Choice
) then
5870 if Is_Entity_Name
(Choice
)
5871 and then Is_Type
(Entity
(Choice
))
5873 Error_Msg_N
("subtype name not allowed here", Choice
);
5876 -- ??? should allow static subtype with zero/one entry
5878 elsif Etype
(Choice
) = Base_Type
(Enumtype
) then
5879 if not Is_OK_Static_Expression
(Choice
) then
5880 Flag_Non_Static_Expr
5881 ("non-static expression used for choice!", Choice
);
5885 Elit
:= Expr_Value_E
(Choice
);
5887 if Present
(Enumeration_Rep_Expr
(Elit
)) then
5889 Sloc
(Enumeration_Rep_Expr
(Elit
));
5891 ("representation for& previously given#",
5896 Set_Enumeration_Rep_Expr
(Elit
, Expression
(Assoc
));
5898 Expr
:= Expression
(Assoc
);
5899 Val
:= Static_Integer
(Expr
);
5901 if Val
= No_Uint
then
5904 elsif Val
< Lo
or else Hi
< Val
then
5905 Error_Msg_N
("value outside permitted range", Expr
);
5909 Set_Enumeration_Rep
(Elit
, Val
);
5919 -- Aggregate is fully processed. Now we check that a full set of
5920 -- representations was given, and that they are in range and in order.
5921 -- These checks are only done if no other errors occurred.
5927 Elit
:= First_Literal
(Enumtype
);
5928 while Present
(Elit
) loop
5929 if No
(Enumeration_Rep_Expr
(Elit
)) then
5930 Error_Msg_NE
("missing representation for&!", N
, Elit
);
5933 Val
:= Enumeration_Rep
(Elit
);
5935 if Min
= No_Uint
then
5939 if Val
/= No_Uint
then
5940 if Max
/= No_Uint
and then Val
<= Max
then
5942 ("enumeration value for& not ordered!",
5943 Enumeration_Rep_Expr
(Elit
), Elit
);
5946 Max_Node
:= Enumeration_Rep_Expr
(Elit
);
5950 -- If there is at least one literal whose representation is not
5951 -- equal to the Pos value, then note that this enumeration type
5952 -- has a non-standard representation.
5954 if Val
/= Enumeration_Pos
(Elit
) then
5955 Set_Has_Non_Standard_Rep
(Base_Type
(Enumtype
));
5962 -- Now set proper size information
5965 Minsize
: Uint
:= UI_From_Int
(Minimum_Size
(Enumtype
));
5968 if Has_Size_Clause
(Enumtype
) then
5970 -- All OK, if size is OK now
5972 if RM_Size
(Enumtype
) >= Minsize
then
5976 -- Try if we can get by with biasing
5979 UI_From_Int
(Minimum_Size
(Enumtype
, Biased
=> True));
5981 -- Error message if even biasing does not work
5983 if RM_Size
(Enumtype
) < Minsize
then
5984 Error_Msg_Uint_1
:= RM_Size
(Enumtype
);
5985 Error_Msg_Uint_2
:= Max
;
5987 ("previously given size (^) is too small "
5988 & "for this value (^)", Max_Node
);
5990 -- If biasing worked, indicate that we now have biased rep
5994 (Enumtype
, Size_Clause
(Enumtype
), "size clause");
5999 Set_RM_Size
(Enumtype
, Minsize
);
6000 Set_Enum_Esize
(Enumtype
);
6003 Set_RM_Size
(Base_Type
(Enumtype
), RM_Size
(Enumtype
));
6004 Set_Esize
(Base_Type
(Enumtype
), Esize
(Enumtype
));
6005 Set_Alignment
(Base_Type
(Enumtype
), Alignment
(Enumtype
));
6009 -- We repeat the too late test in case it froze itself
6011 if Rep_Item_Too_Late
(Enumtype
, N
) then
6014 end Analyze_Enumeration_Representation_Clause
;
6016 ----------------------------
6017 -- Analyze_Free_Statement --
6018 ----------------------------
6020 procedure Analyze_Free_Statement
(N
: Node_Id
) is
6022 Analyze
(Expression
(N
));
6023 end Analyze_Free_Statement
;
6025 ---------------------------
6026 -- Analyze_Freeze_Entity --
6027 ---------------------------
6029 procedure Analyze_Freeze_Entity
(N
: Node_Id
) is
6031 Freeze_Entity_Checks
(N
);
6032 end Analyze_Freeze_Entity
;
6034 -----------------------------------
6035 -- Analyze_Freeze_Generic_Entity --
6036 -----------------------------------
6038 procedure Analyze_Freeze_Generic_Entity
(N
: Node_Id
) is
6040 Freeze_Entity_Checks
(N
);
6041 end Analyze_Freeze_Generic_Entity
;
6043 ------------------------------------------
6044 -- Analyze_Record_Representation_Clause --
6045 ------------------------------------------
6047 -- Note: we check as much as we can here, but we can't do any checks
6048 -- based on the position values (e.g. overlap checks) until freeze time
6049 -- because especially in Ada 2005 (machine scalar mode), the processing
6050 -- for non-standard bit order can substantially change the positions.
6051 -- See procedure Check_Record_Representation_Clause (called from Freeze)
6052 -- for the remainder of this processing.
6054 procedure Analyze_Record_Representation_Clause
(N
: Node_Id
) is
6055 Ident
: constant Node_Id
:= Identifier
(N
);
6060 Hbit
: Uint
:= Uint_0
;
6064 Rectype
: Entity_Id
;
6067 function Is_Inherited
(Comp
: Entity_Id
) return Boolean;
6068 -- True if Comp is an inherited component in a record extension
6074 function Is_Inherited
(Comp
: Entity_Id
) return Boolean is
6075 Comp_Base
: Entity_Id
;
6078 if Ekind
(Rectype
) = E_Record_Subtype
then
6079 Comp_Base
:= Original_Record_Component
(Comp
);
6084 return Comp_Base
/= Original_Record_Component
(Comp_Base
);
6089 Is_Record_Extension
: Boolean;
6090 -- True if Rectype is a record extension
6092 CR_Pragma
: Node_Id
:= Empty
;
6093 -- Points to N_Pragma node if Complete_Representation pragma present
6095 -- Start of processing for Analyze_Record_Representation_Clause
6098 if Ignore_Rep_Clauses
then
6099 Kill_Rep_Clause
(N
);
6104 Rectype
:= Entity
(Ident
);
6106 if Rectype
= Any_Type
or else Rep_Item_Too_Early
(Rectype
, N
) then
6109 Rectype
:= Underlying_Type
(Rectype
);
6112 -- First some basic error checks
6114 if not Is_Record_Type
(Rectype
) then
6116 ("record type required, found}", Ident
, First_Subtype
(Rectype
));
6119 elsif Scope
(Rectype
) /= Current_Scope
then
6120 Error_Msg_N
("type must be declared in this scope", N
);
6123 elsif not Is_First_Subtype
(Rectype
) then
6124 Error_Msg_N
("cannot give record rep clause for subtype", N
);
6127 elsif Has_Record_Rep_Clause
(Rectype
) then
6128 Error_Msg_N
("duplicate record rep clause ignored", N
);
6131 elsif Rep_Item_Too_Late
(Rectype
, N
) then
6135 -- We know we have a first subtype, now possibly go the the anonymous
6136 -- base type to determine whether Rectype is a record extension.
6138 Recdef
:= Type_Definition
(Declaration_Node
(Base_Type
(Rectype
)));
6139 Is_Record_Extension
:=
6140 Nkind
(Recdef
) = N_Derived_Type_Definition
6141 and then Present
(Record_Extension_Part
(Recdef
));
6143 if Present
(Mod_Clause
(N
)) then
6145 Loc
: constant Source_Ptr
:= Sloc
(N
);
6146 M
: constant Node_Id
:= Mod_Clause
(N
);
6147 P
: constant List_Id
:= Pragmas_Before
(M
);
6151 pragma Warnings
(Off
, Mod_Val
);
6154 Check_Restriction
(No_Obsolescent_Features
, Mod_Clause
(N
));
6156 if Warn_On_Obsolescent_Feature
then
6158 ("?j?mod clause is an obsolescent feature (RM J.8)", N
);
6160 ("\?j?use alignment attribute definition clause instead", N
);
6167 -- In ASIS_Mode mode, expansion is disabled, but we must convert
6168 -- the Mod clause into an alignment clause anyway, so that the
6169 -- back-end can compute and back-annotate properly the size and
6170 -- alignment of types that may include this record.
6172 -- This seems dubious, this destroys the source tree in a manner
6173 -- not detectable by ASIS ???
6175 if Operating_Mode
= Check_Semantics
and then ASIS_Mode
then
6177 Make_Attribute_Definition_Clause
(Loc
,
6178 Name
=> New_Occurrence_Of
(Base_Type
(Rectype
), Loc
),
6179 Chars
=> Name_Alignment
,
6180 Expression
=> Relocate_Node
(Expression
(M
)));
6182 Set_From_At_Mod
(AtM_Nod
);
6183 Insert_After
(N
, AtM_Nod
);
6184 Mod_Val
:= Get_Alignment_Value
(Expression
(AtM_Nod
));
6185 Set_Mod_Clause
(N
, Empty
);
6188 -- Get the alignment value to perform error checking
6190 Mod_Val
:= Get_Alignment_Value
(Expression
(M
));
6195 -- For untagged types, clear any existing component clauses for the
6196 -- type. If the type is derived, this is what allows us to override
6197 -- a rep clause for the parent. For type extensions, the representation
6198 -- of the inherited components is inherited, so we want to keep previous
6199 -- component clauses for completeness.
6201 if not Is_Tagged_Type
(Rectype
) then
6202 Comp
:= First_Component_Or_Discriminant
(Rectype
);
6203 while Present
(Comp
) loop
6204 Set_Component_Clause
(Comp
, Empty
);
6205 Next_Component_Or_Discriminant
(Comp
);
6209 -- All done if no component clauses
6211 CC
:= First
(Component_Clauses
(N
));
6217 -- A representation like this applies to the base type
6219 Set_Has_Record_Rep_Clause
(Base_Type
(Rectype
));
6220 Set_Has_Non_Standard_Rep
(Base_Type
(Rectype
));
6221 Set_Has_Specified_Layout
(Base_Type
(Rectype
));
6223 -- Process the component clauses
6225 while Present
(CC
) loop
6229 if Nkind
(CC
) = N_Pragma
then
6232 -- The only pragma of interest is Complete_Representation
6234 if Pragma_Name
(CC
) = Name_Complete_Representation
then
6238 -- Processing for real component clause
6241 Posit
:= Static_Integer
(Position
(CC
));
6242 Fbit
:= Static_Integer
(First_Bit
(CC
));
6243 Lbit
:= Static_Integer
(Last_Bit
(CC
));
6246 and then Fbit
/= No_Uint
6247 and then Lbit
/= No_Uint
6251 ("position cannot be negative", Position
(CC
));
6255 ("first bit cannot be negative", First_Bit
(CC
));
6257 -- The Last_Bit specified in a component clause must not be
6258 -- less than the First_Bit minus one (RM-13.5.1(10)).
6260 elsif Lbit
< Fbit
- 1 then
6262 ("last bit cannot be less than first bit minus one",
6265 -- Values look OK, so find the corresponding record component
6266 -- Even though the syntax allows an attribute reference for
6267 -- implementation-defined components, GNAT does not allow the
6268 -- tag to get an explicit position.
6270 elsif Nkind
(Component_Name
(CC
)) = N_Attribute_Reference
then
6271 if Attribute_Name
(Component_Name
(CC
)) = Name_Tag
then
6272 Error_Msg_N
("position of tag cannot be specified", CC
);
6274 Error_Msg_N
("illegal component name", CC
);
6278 Comp
:= First_Entity
(Rectype
);
6279 while Present
(Comp
) loop
6280 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
6286 -- Maybe component of base type that is absent from
6287 -- statically constrained first subtype.
6289 Comp
:= First_Entity
(Base_Type
(Rectype
));
6290 while Present
(Comp
) loop
6291 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
6298 ("component clause is for non-existent field", CC
);
6300 -- Ada 2012 (AI05-0026): Any name that denotes a
6301 -- discriminant of an object of an unchecked union type
6302 -- shall not occur within a record_representation_clause.
6304 -- The general restriction of using record rep clauses on
6305 -- Unchecked_Union types has now been lifted. Since it is
6306 -- possible to introduce a record rep clause which mentions
6307 -- the discriminant of an Unchecked_Union in non-Ada 2012
6308 -- code, this check is applied to all versions of the
6311 elsif Ekind
(Comp
) = E_Discriminant
6312 and then Is_Unchecked_Union
(Rectype
)
6315 ("cannot reference discriminant of unchecked union",
6316 Component_Name
(CC
));
6318 elsif Is_Record_Extension
and then Is_Inherited
(Comp
) then
6320 ("component clause not allowed for inherited "
6321 & "component&", CC
, Comp
);
6323 elsif Present
(Component_Clause
(Comp
)) then
6325 -- Diagnose duplicate rep clause, or check consistency
6326 -- if this is an inherited component. In a double fault,
6327 -- there may be a duplicate inconsistent clause for an
6328 -- inherited component.
6330 if Scope
(Original_Record_Component
(Comp
)) = Rectype
6331 or else Parent
(Component_Clause
(Comp
)) = N
6333 Error_Msg_Sloc
:= Sloc
(Component_Clause
(Comp
));
6334 Error_Msg_N
("component clause previously given#", CC
);
6338 Rep1
: constant Node_Id
:= Component_Clause
(Comp
);
6340 if Intval
(Position
(Rep1
)) /=
6341 Intval
(Position
(CC
))
6342 or else Intval
(First_Bit
(Rep1
)) /=
6343 Intval
(First_Bit
(CC
))
6344 or else Intval
(Last_Bit
(Rep1
)) /=
6345 Intval
(Last_Bit
(CC
))
6348 ("component clause inconsistent "
6349 & "with representation of ancestor", CC
);
6351 elsif Warn_On_Redundant_Constructs
then
6353 ("?r?redundant confirming component clause "
6354 & "for component!", CC
);
6359 -- Normal case where this is the first component clause we
6360 -- have seen for this entity, so set it up properly.
6363 -- Make reference for field in record rep clause and set
6364 -- appropriate entity field in the field identifier.
6367 (Comp
, Component_Name
(CC
), Set_Ref
=> False);
6368 Set_Entity
(Component_Name
(CC
), Comp
);
6370 -- Update Fbit and Lbit to the actual bit number
6372 Fbit
:= Fbit
+ UI_From_Int
(SSU
) * Posit
;
6373 Lbit
:= Lbit
+ UI_From_Int
(SSU
) * Posit
;
6375 if Has_Size_Clause
(Rectype
)
6376 and then RM_Size
(Rectype
) <= Lbit
6379 ("bit number out of range of specified size",
6382 Set_Component_Clause
(Comp
, CC
);
6383 Set_Component_Bit_Offset
(Comp
, Fbit
);
6384 Set_Esize
(Comp
, 1 + (Lbit
- Fbit
));
6385 Set_Normalized_First_Bit
(Comp
, Fbit
mod SSU
);
6386 Set_Normalized_Position
(Comp
, Fbit
/ SSU
);
6388 if Warn_On_Overridden_Size
6389 and then Has_Size_Clause
(Etype
(Comp
))
6390 and then RM_Size
(Etype
(Comp
)) /= Esize
(Comp
)
6393 ("?S?component size overrides size clause for&",
6394 Component_Name
(CC
), Etype
(Comp
));
6397 -- This information is also set in the corresponding
6398 -- component of the base type, found by accessing the
6399 -- Original_Record_Component link if it is present.
6401 Ocomp
:= Original_Record_Component
(Comp
);
6408 (Component_Name
(CC
),
6414 (Comp
, First_Node
(CC
), "component clause", Biased
);
6416 if Present
(Ocomp
) then
6417 Set_Component_Clause
(Ocomp
, CC
);
6418 Set_Component_Bit_Offset
(Ocomp
, Fbit
);
6419 Set_Normalized_First_Bit
(Ocomp
, Fbit
mod SSU
);
6420 Set_Normalized_Position
(Ocomp
, Fbit
/ SSU
);
6421 Set_Esize
(Ocomp
, 1 + (Lbit
- Fbit
));
6423 Set_Normalized_Position_Max
6424 (Ocomp
, Normalized_Position
(Ocomp
));
6426 -- Note: we don't use Set_Biased here, because we
6427 -- already gave a warning above if needed, and we
6428 -- would get a duplicate for the same name here.
6430 Set_Has_Biased_Representation
6431 (Ocomp
, Has_Biased_Representation
(Comp
));
6434 if Esize
(Comp
) < 0 then
6435 Error_Msg_N
("component size is negative", CC
);
6446 -- Check missing components if Complete_Representation pragma appeared
6448 if Present
(CR_Pragma
) then
6449 Comp
:= First_Component_Or_Discriminant
(Rectype
);
6450 while Present
(Comp
) loop
6451 if No
(Component_Clause
(Comp
)) then
6453 ("missing component clause for &", CR_Pragma
, Comp
);
6456 Next_Component_Or_Discriminant
(Comp
);
6459 -- Give missing components warning if required
6461 elsif Warn_On_Unrepped_Components
then
6463 Num_Repped_Components
: Nat
:= 0;
6464 Num_Unrepped_Components
: Nat
:= 0;
6467 -- First count number of repped and unrepped components
6469 Comp
:= First_Component_Or_Discriminant
(Rectype
);
6470 while Present
(Comp
) loop
6471 if Present
(Component_Clause
(Comp
)) then
6472 Num_Repped_Components
:= Num_Repped_Components
+ 1;
6474 Num_Unrepped_Components
:= Num_Unrepped_Components
+ 1;
6477 Next_Component_Or_Discriminant
(Comp
);
6480 -- We are only interested in the case where there is at least one
6481 -- unrepped component, and at least half the components have rep
6482 -- clauses. We figure that if less than half have them, then the
6483 -- partial rep clause is really intentional. If the component
6484 -- type has no underlying type set at this point (as for a generic
6485 -- formal type), we don't know enough to give a warning on the
6488 if Num_Unrepped_Components
> 0
6489 and then Num_Unrepped_Components
< Num_Repped_Components
6491 Comp
:= First_Component_Or_Discriminant
(Rectype
);
6492 while Present
(Comp
) loop
6493 if No
(Component_Clause
(Comp
))
6494 and then Comes_From_Source
(Comp
)
6495 and then Present
(Underlying_Type
(Etype
(Comp
)))
6496 and then (Is_Scalar_Type
(Underlying_Type
(Etype
(Comp
)))
6497 or else Size_Known_At_Compile_Time
6498 (Underlying_Type
(Etype
(Comp
))))
6499 and then not Has_Warnings_Off
(Rectype
)
6501 Error_Msg_Sloc
:= Sloc
(Comp
);
6503 ("?C?no component clause given for & declared #",
6507 Next_Component_Or_Discriminant
(Comp
);
6512 end Analyze_Record_Representation_Clause
;
6514 -------------------------------------
6515 -- Build_Discrete_Static_Predicate --
6516 -------------------------------------
6518 procedure Build_Discrete_Static_Predicate
6523 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
6525 Non_Static
: exception;
6526 -- Raised if something non-static is found
6528 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
6530 BLo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Btyp
));
6531 BHi
: constant Uint
:= Expr_Value
(Type_High_Bound
(Btyp
));
6532 -- Low bound and high bound value of base type of Typ
6534 TLo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Typ
));
6535 THi
: constant Uint
:= Expr_Value
(Type_High_Bound
(Typ
));
6536 -- Low bound and high bound values of static subtype Typ
6541 -- One entry in a Rlist value, a single REnt (range entry) value denotes
6542 -- one range from Lo to Hi. To represent a single value range Lo = Hi =
6545 type RList
is array (Nat
range <>) of REnt
;
6546 -- A list of ranges. The ranges are sorted in increasing order, and are
6547 -- disjoint (there is a gap of at least one value between each range in
6548 -- the table). A value is in the set of ranges in Rlist if it lies
6549 -- within one of these ranges.
6551 False_Range
: constant RList
:=
6552 RList
'(1 .. 0 => REnt'(No_Uint
, No_Uint
));
6553 -- An empty set of ranges represents a range list that can never be
6554 -- satisfied, since there are no ranges in which the value could lie,
6555 -- so it does not lie in any of them. False_Range is a canonical value
6556 -- for this empty set, but general processing should test for an Rlist
6557 -- with length zero (see Is_False predicate), since other null ranges
6558 -- may appear which must be treated as False.
6560 True_Range
: constant RList
:= RList
'(1 => REnt'(BLo
, BHi
));
6561 -- Range representing True, value must be in the base range
6563 function "and" (Left
: RList
; Right
: RList
) return RList
;
6564 -- And's together two range lists, returning a range list. This is a set
6565 -- intersection operation.
6567 function "or" (Left
: RList
; Right
: RList
) return RList
;
6568 -- Or's together two range lists, returning a range list. This is a set
6571 function "not" (Right
: RList
) return RList
;
6572 -- Returns complement of a given range list, i.e. a range list
6573 -- representing all the values in TLo .. THi that are not in the input
6576 function Build_Val
(V
: Uint
) return Node_Id
;
6577 -- Return an analyzed N_Identifier node referencing this value, suitable
6578 -- for use as an entry in the Static_Discrte_Predicate list. This node
6579 -- is typed with the base type.
6581 function Build_Range
(Lo
: Uint
; Hi
: Uint
) return Node_Id
;
6582 -- Return an analyzed N_Range node referencing this range, suitable for
6583 -- use as an entry in the Static_Discrete_Predicate list. This node is
6584 -- typed with the base type.
6586 function Get_RList
(Exp
: Node_Id
) return RList
;
6587 -- This is a recursive routine that converts the given expression into a
6588 -- list of ranges, suitable for use in building the static predicate.
6590 function Is_False
(R
: RList
) return Boolean;
6591 pragma Inline
(Is_False
);
6592 -- Returns True if the given range list is empty, and thus represents a
6593 -- False list of ranges that can never be satisfied.
6595 function Is_True
(R
: RList
) return Boolean;
6596 -- Returns True if R trivially represents the True predicate by having a
6597 -- single range from BLo to BHi.
6599 function Is_Type_Ref
(N
: Node_Id
) return Boolean;
6600 pragma Inline
(Is_Type_Ref
);
6601 -- Returns if True if N is a reference to the type for the predicate in
6602 -- the expression (i.e. if it is an identifier whose Chars field matches
6603 -- the Nam given in the call). N must not be parenthesized, if the type
6604 -- name appears in parens, this routine will return False.
6606 function Lo_Val
(N
: Node_Id
) return Uint
;
6607 -- Given an entry from a Static_Discrete_Predicate list that is either
6608 -- a static expression or static range, gets either the expression value
6609 -- or the low bound of the range.
6611 function Hi_Val
(N
: Node_Id
) return Uint
;
6612 -- Given an entry from a Static_Discrete_Predicate list that is either
6613 -- a static expression or static range, gets either the expression value
6614 -- or the high bound of the range.
6616 function Membership_Entry
(N
: Node_Id
) return RList
;
6617 -- Given a single membership entry (range, value, or subtype), returns
6618 -- the corresponding range list. Raises Static_Error if not static.
6620 function Membership_Entries
(N
: Node_Id
) return RList
;
6621 -- Given an element on an alternatives list of a membership operation,
6622 -- returns the range list corresponding to this entry and all following
6623 -- entries (i.e. returns the "or" of this list of values).
6625 function Stat_Pred
(Typ
: Entity_Id
) return RList
;
6626 -- Given a type, if it has a static predicate, then return the predicate
6627 -- as a range list, otherwise raise Non_Static.
6633 function "and" (Left
: RList
; Right
: RList
) return RList
is
6635 -- First range of result
6637 SLeft
: Nat
:= Left
'First;
6638 -- Start of rest of left entries
6640 SRight
: Nat
:= Right
'First;
6641 -- Start of rest of right entries
6644 -- If either range is True, return the other
6646 if Is_True
(Left
) then
6648 elsif Is_True
(Right
) then
6652 -- If either range is False, return False
6654 if Is_False
(Left
) or else Is_False
(Right
) then
6658 -- Loop to remove entries at start that are disjoint, and thus just
6659 -- get discarded from the result entirely.
6662 -- If no operands left in either operand, result is false
6664 if SLeft
> Left
'Last or else SRight
> Right
'Last then
6667 -- Discard first left operand entry if disjoint with right
6669 elsif Left
(SLeft
).Hi
< Right
(SRight
).Lo
then
6672 -- Discard first right operand entry if disjoint with left
6674 elsif Right
(SRight
).Hi
< Left
(SLeft
).Lo
then
6675 SRight
:= SRight
+ 1;
6677 -- Otherwise we have an overlapping entry
6684 -- Now we have two non-null operands, and first entries overlap. The
6685 -- first entry in the result will be the overlapping part of these
6688 FEnt
:= REnt
'(Lo => UI_Max (Left (SLeft).Lo, Right (SRight).Lo),
6689 Hi => UI_Min (Left (SLeft).Hi, Right (SRight).Hi));
6691 -- Now we can remove the entry that ended at a lower value, since its
6692 -- contribution is entirely contained in Fent.
6694 if Left (SLeft).Hi <= Right (SRight).Hi then
6697 SRight := SRight + 1;
6700 -- Compute result by concatenating this first entry with the "and" of
6701 -- the remaining parts of the left and right operands. Note that if
6702 -- either of these is empty, "and" will yield empty, so that we will
6703 -- end up with just Fent, which is what we want in that case.
6706 FEnt & (Left (SLeft .. Left'Last) and Right (SRight .. Right'Last));
6713 function "not" (Right : RList) return RList is
6715 -- Return True if False range
6717 if Is_False (Right) then
6721 -- Return False if True range
6723 if Is_True (Right) then
6727 -- Here if not trivial case
6730 Result : RList (1 .. Right'Length + 1);
6731 -- May need one more entry for gap at beginning and end
6734 -- Number of entries stored in Result
6739 if Right (Right'First).Lo > TLo then
6741 Result (Count) := REnt'(TLo
, Right
(Right
'First).Lo
- 1);
6744 -- Gaps between ranges
6746 for J
in Right
'First .. Right
'Last - 1 loop
6748 Result
(Count
) := REnt
'(Right (J).Hi + 1, Right (J + 1).Lo - 1);
6753 if Right (Right'Last).Hi < THi then
6755 Result (Count) := REnt'(Right
(Right
'Last).Hi
+ 1, THi
);
6758 return Result
(1 .. Count
);
6766 function "or" (Left
: RList
; Right
: RList
) return RList
is
6768 -- First range of result
6770 SLeft
: Nat
:= Left
'First;
6771 -- Start of rest of left entries
6773 SRight
: Nat
:= Right
'First;
6774 -- Start of rest of right entries
6777 -- If either range is True, return True
6779 if Is_True
(Left
) or else Is_True
(Right
) then
6783 -- If either range is False (empty), return the other
6785 if Is_False
(Left
) then
6787 elsif Is_False
(Right
) then
6791 -- Initialize result first entry from left or right operand depending
6792 -- on which starts with the lower range.
6794 if Left
(SLeft
).Lo
< Right
(SRight
).Lo
then
6795 FEnt
:= Left
(SLeft
);
6798 FEnt
:= Right
(SRight
);
6799 SRight
:= SRight
+ 1;
6802 -- This loop eats ranges from left and right operands that are
6803 -- contiguous with the first range we are gathering.
6806 -- Eat first entry in left operand if contiguous or overlapped by
6807 -- gathered first operand of result.
6809 if SLeft
<= Left
'Last
6810 and then Left
(SLeft
).Lo
<= FEnt
.Hi
+ 1
6812 FEnt
.Hi
:= UI_Max
(FEnt
.Hi
, Left
(SLeft
).Hi
);
6815 -- Eat first entry in right operand if contiguous or overlapped by
6816 -- gathered right operand of result.
6818 elsif SRight
<= Right
'Last
6819 and then Right
(SRight
).Lo
<= FEnt
.Hi
+ 1
6821 FEnt
.Hi
:= UI_Max
(FEnt
.Hi
, Right
(SRight
).Hi
);
6822 SRight
:= SRight
+ 1;
6824 -- All done if no more entries to eat
6831 -- Obtain result as the first entry we just computed, concatenated
6832 -- to the "or" of the remaining results (if one operand is empty,
6833 -- this will just concatenate with the other
6836 FEnt
& (Left
(SLeft
.. Left
'Last) or Right
(SRight
.. Right
'Last));
6843 function Build_Range
(Lo
: Uint
; Hi
: Uint
) return Node_Id
is
6848 Low_Bound
=> Build_Val
(Lo
),
6849 High_Bound
=> Build_Val
(Hi
));
6850 Set_Etype
(Result
, Btyp
);
6851 Set_Analyzed
(Result
);
6859 function Build_Val
(V
: Uint
) return Node_Id
is
6863 if Is_Enumeration_Type
(Typ
) then
6864 Result
:= Get_Enum_Lit_From_Pos
(Typ
, V
, Loc
);
6866 Result
:= Make_Integer_Literal
(Loc
, V
);
6869 Set_Etype
(Result
, Btyp
);
6870 Set_Is_Static_Expression
(Result
);
6871 Set_Analyzed
(Result
);
6879 function Get_RList
(Exp
: Node_Id
) return RList
is
6884 -- Static expression can only be true or false
6886 if Is_OK_Static_Expression
(Exp
) then
6887 if Expr_Value
(Exp
) = 0 then
6894 -- Otherwise test node type
6902 when N_Op_And | N_And_Then
=>
6903 return Get_RList
(Left_Opnd
(Exp
))
6905 Get_RList
(Right_Opnd
(Exp
));
6909 when N_Op_Or | N_Or_Else
=>
6910 return Get_RList
(Left_Opnd
(Exp
))
6912 Get_RList
(Right_Opnd
(Exp
));
6917 return not Get_RList
(Right_Opnd
(Exp
));
6919 -- Comparisons of type with static value
6921 when N_Op_Compare
=>
6923 -- Type is left operand
6925 if Is_Type_Ref
(Left_Opnd
(Exp
))
6926 and then Is_OK_Static_Expression
(Right_Opnd
(Exp
))
6928 Val
:= Expr_Value
(Right_Opnd
(Exp
));
6930 -- Typ is right operand
6932 elsif Is_Type_Ref
(Right_Opnd
(Exp
))
6933 and then Is_OK_Static_Expression
(Left_Opnd
(Exp
))
6935 Val
:= Expr_Value
(Left_Opnd
(Exp
));
6937 -- Invert sense of comparison
6940 when N_Op_Gt
=> Op
:= N_Op_Lt
;
6941 when N_Op_Lt
=> Op
:= N_Op_Gt
;
6942 when N_Op_Ge
=> Op
:= N_Op_Le
;
6943 when N_Op_Le
=> Op
:= N_Op_Ge
;
6944 when others => null;
6947 -- Other cases are non-static
6953 -- Construct range according to comparison operation
6957 return RList
'(1 => REnt'(Val
, Val
));
6960 return RList
'(1 => REnt'(Val
, BHi
));
6963 return RList
'(1 => REnt'(Val
+ 1, BHi
));
6966 return RList
'(1 => REnt'(BLo
, Val
));
6969 return RList
'(1 => REnt'(BLo
, Val
- 1));
6972 return RList
'(REnt'(BLo
, Val
- 1), REnt
'(Val + 1, BHi));
6975 raise Program_Error;
6981 if not Is_Type_Ref (Left_Opnd (Exp)) then
6985 if Present (Right_Opnd (Exp)) then
6986 return Membership_Entry (Right_Opnd (Exp));
6988 return Membership_Entries (First (Alternatives (Exp)));
6991 -- Negative membership (NOT IN)
6994 if not Is_Type_Ref (Left_Opnd (Exp)) then
6998 if Present (Right_Opnd (Exp)) then
6999 return not Membership_Entry (Right_Opnd (Exp));
7001 return not Membership_Entries (First (Alternatives (Exp)));
7004 -- Function call, may be call to static predicate
7006 when N_Function_Call =>
7007 if Is_Entity_Name (Name (Exp)) then
7009 Ent : constant Entity_Id := Entity (Name (Exp));
7011 if Is_Predicate_Function (Ent)
7013 Is_Predicate_Function_M (Ent)
7015 return Stat_Pred (Etype (First_Formal (Ent)));
7020 -- Other function call cases are non-static
7024 -- Qualified expression, dig out the expression
7026 when N_Qualified_Expression =>
7027 return Get_RList (Expression (Exp));
7029 when N_Case_Expression =>
7036 if not Is_Entity_Name (Expression (Expr))
7037 or else Etype (Expression (Expr)) /= Typ
7040 ("expression must denaote subtype", Expression (Expr));
7044 -- Collect discrete choices in all True alternatives
7046 Choices := New_List;
7047 Alt := First (Alternatives (Exp));
7048 while Present (Alt) loop
7049 Dep := Expression (Alt);
7051 if not Is_OK_Static_Expression (Dep) then
7054 elsif Is_True (Expr_Value (Dep)) then
7055 Append_List_To (Choices,
7056 New_Copy_List (Discrete_Choices (Alt)));
7062 return Membership_Entries (First (Choices));
7065 -- Expression with actions: if no actions, dig out expression
7067 when N_Expression_With_Actions =>
7068 if Is_Empty_List (Actions (Exp)) then
7069 return Get_RList (Expression (Exp));
7077 return (Get_RList (Left_Opnd (Exp))
7078 and not Get_RList (Right_Opnd (Exp)))
7079 or (Get_RList (Right_Opnd (Exp))
7080 and not Get_RList (Left_Opnd (Exp)));
7082 -- Any other node type is non-static
7093 function Hi_Val (N : Node_Id) return Uint is
7095 if Is_OK_Static_Expression (N) then
7096 return Expr_Value (N);
7098 pragma Assert (Nkind (N) = N_Range);
7099 return Expr_Value (High_Bound (N));
7107 function Is_False (R : RList) return Boolean is
7109 return R'Length = 0;
7116 function Is_True (R : RList) return Boolean is
7119 and then R (R'First).Lo = BLo
7120 and then R (R'First).Hi = BHi;
7127 function Is_Type_Ref (N : Node_Id) return Boolean is
7129 return Nkind (N) = N_Identifier
7130 and then Chars (N) = Nam
7131 and then Paren_Count (N) = 0;
7138 function Lo_Val (N : Node_Id) return Uint is
7140 if Is_OK_Static_Expression (N) then
7141 return Expr_Value (N);
7143 pragma Assert (Nkind (N) = N_Range);
7144 return Expr_Value (Low_Bound (N));
7148 ------------------------
7149 -- Membership_Entries --
7150 ------------------------
7152 function Membership_Entries (N : Node_Id) return RList is
7154 if No (Next (N)) then
7155 return Membership_Entry (N);
7157 return Membership_Entry (N) or Membership_Entries (Next (N));
7159 end Membership_Entries;
7161 ----------------------
7162 -- Membership_Entry --
7163 ----------------------
7165 function Membership_Entry (N : Node_Id) return RList is
7173 if Nkind (N) = N_Range then
7174 if not Is_OK_Static_Expression (Low_Bound (N))
7176 not Is_OK_Static_Expression (High_Bound (N))
7180 SLo := Expr_Value (Low_Bound (N));
7181 SHi := Expr_Value (High_Bound (N));
7182 return RList'(1 => REnt
'(SLo, SHi));
7185 -- Static expression case
7187 elsif Is_OK_Static_Expression (N) then
7188 Val := Expr_Value (N);
7189 return RList'(1 => REnt
'(Val, Val));
7191 -- Identifier (other than static expression) case
7193 else pragma Assert (Nkind (N) = N_Identifier);
7197 if Is_Type (Entity (N)) then
7199 -- If type has predicates, process them
7201 if Has_Predicates (Entity (N)) then
7202 return Stat_Pred (Entity (N));
7204 -- For static subtype without predicates, get range
7206 elsif Is_OK_Static_Subtype (Entity (N)) then
7207 SLo := Expr_Value (Type_Low_Bound (Entity (N)));
7208 SHi := Expr_Value (Type_High_Bound (Entity (N)));
7209 return RList'(1 => REnt
'(SLo, SHi));
7211 -- Any other type makes us non-static
7217 -- Any other kind of identifier in predicate (e.g. a non-static
7218 -- expression value) means this is not a static predicate.
7224 end Membership_Entry;
7230 function Stat_Pred (Typ : Entity_Id) return RList is
7232 -- Not static if type does not have static predicates
7234 if not Has_Static_Predicate (Typ) then
7238 -- Otherwise we convert the predicate list to a range list
7241 Spred : constant List_Id := Static_Discrete_Predicate (Typ);
7242 Result : RList (1 .. List_Length (Spred));
7246 P := First (Static_Discrete_Predicate (Typ));
7247 for J in Result'Range loop
7248 Result (J) := REnt'(Lo_Val
(P
), Hi_Val
(P
));
7256 -- Start of processing for Build_Discrete_Static_Predicate
7259 -- Analyze the expression to see if it is a static predicate
7262 Ranges
: constant RList
:= Get_RList
(Expr
);
7263 -- Range list from expression if it is static
7268 -- Convert range list into a form for the static predicate. In the
7269 -- Ranges array, we just have raw ranges, these must be converted
7270 -- to properly typed and analyzed static expressions or range nodes.
7272 -- Note: here we limit ranges to the ranges of the subtype, so that
7273 -- a predicate is always false for values outside the subtype. That
7274 -- seems fine, such values are invalid anyway, and considering them
7275 -- to fail the predicate seems allowed and friendly, and furthermore
7276 -- simplifies processing for case statements and loops.
7280 for J
in Ranges
'Range loop
7282 Lo
: Uint
:= Ranges
(J
).Lo
;
7283 Hi
: Uint
:= Ranges
(J
).Hi
;
7286 -- Ignore completely out of range entry
7288 if Hi
< TLo
or else Lo
> THi
then
7291 -- Otherwise process entry
7294 -- Adjust out of range value to subtype range
7304 -- Convert range into required form
7306 Append_To
(Plist
, Build_Range
(Lo
, Hi
));
7311 -- Processing was successful and all entries were static, so now we
7312 -- can store the result as the predicate list.
7314 Set_Static_Discrete_Predicate
(Typ
, Plist
);
7316 -- The processing for static predicates put the expression into
7317 -- canonical form as a series of ranges. It also eliminated
7318 -- duplicates and collapsed and combined ranges. We might as well
7319 -- replace the alternatives list of the right operand of the
7320 -- membership test with the static predicate list, which will
7321 -- usually be more efficient.
7324 New_Alts
: constant List_Id
:= New_List
;
7329 Old_Node
:= First
(Plist
);
7330 while Present
(Old_Node
) loop
7331 New_Node
:= New_Copy
(Old_Node
);
7333 if Nkind
(New_Node
) = N_Range
then
7334 Set_Low_Bound
(New_Node
, New_Copy
(Low_Bound
(Old_Node
)));
7335 Set_High_Bound
(New_Node
, New_Copy
(High_Bound
(Old_Node
)));
7338 Append_To
(New_Alts
, New_Node
);
7342 -- If empty list, replace by False
7344 if Is_Empty_List
(New_Alts
) then
7345 Rewrite
(Expr
, New_Occurrence_Of
(Standard_False
, Loc
));
7347 -- Else replace by set membership test
7352 Left_Opnd
=> Make_Identifier
(Loc
, Nam
),
7353 Right_Opnd
=> Empty
,
7354 Alternatives
=> New_Alts
));
7356 -- Resolve new expression in function context
7358 Install_Formals
(Predicate_Function
(Typ
));
7359 Push_Scope
(Predicate_Function
(Typ
));
7360 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
7366 -- If non-static, return doing nothing
7371 end Build_Discrete_Static_Predicate
;
7373 -------------------------------------------
7374 -- Build_Invariant_Procedure_Declaration --
7375 -------------------------------------------
7377 function Build_Invariant_Procedure_Declaration
7378 (Typ
: Entity_Id
) return Node_Id
7380 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
7381 Object_Entity
: constant Entity_Id
:=
7382 Make_Defining_Identifier
(Loc
, New_Internal_Name
('I'));
7387 Set_Etype
(Object_Entity
, Typ
);
7389 -- Check for duplicate definiations.
7391 if Has_Invariants
(Typ
) and then Present
(Invariant_Procedure
(Typ
)) then
7396 Make_Defining_Identifier
(Loc
,
7397 Chars
=> New_External_Name
(Chars
(Typ
), "Invariant"));
7398 Set_Has_Invariants
(Typ
);
7399 Set_Ekind
(SId
, E_Procedure
);
7400 Set_Is_Invariant_Procedure
(SId
);
7401 Set_Invariant_Procedure
(Typ
, SId
);
7404 Make_Procedure_Specification
(Loc
,
7405 Defining_Unit_Name
=> SId
,
7406 Parameter_Specifications
=> New_List
(
7407 Make_Parameter_Specification
(Loc
,
7408 Defining_Identifier
=> Object_Entity
,
7409 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))));
7411 return Make_Subprogram_Declaration
(Loc
, Specification
=> Spec
);
7412 end Build_Invariant_Procedure_Declaration
;
7414 -------------------------------
7415 -- Build_Invariant_Procedure --
7416 -------------------------------
7418 -- The procedure that is constructed here has the form
7420 -- procedure typInvariant (Ixxx : typ) is
7422 -- pragma Check (Invariant, exp, "failed invariant from xxx");
7423 -- pragma Check (Invariant, exp, "failed invariant from xxx");
7425 -- pragma Check (Invariant, exp, "failed inherited invariant from xxx");
7427 -- end typInvariant;
7429 procedure Build_Invariant_Procedure
(Typ
: Entity_Id
; N
: Node_Id
) is
7430 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
7438 -- Name for Check pragma, usually Invariant, but might be Type_Invariant
7439 -- if we come from a Type_Invariant aspect, we make sure to build the
7440 -- Check pragma with the right name, so that Check_Policy works right.
7442 Visible_Decls
: constant List_Id
:= Visible_Declarations
(N
);
7443 Private_Decls
: constant List_Id
:= Private_Declarations
(N
);
7445 procedure Add_Invariants
(T
: Entity_Id
; Inherit
: Boolean);
7446 -- Appends statements to Stmts for any invariants in the rep item chain
7447 -- of the given type. If Inherit is False, then we only process entries
7448 -- on the chain for the type Typ. If Inherit is True, then we ignore any
7449 -- Invariant aspects, but we process all Invariant'Class aspects, adding
7450 -- "inherited" to the exception message and generating an informational
7451 -- message about the inheritance of an invariant.
7453 Object_Name
: Name_Id
;
7454 -- Name for argument of invariant procedure
7456 Object_Entity
: Node_Id
;
7457 -- The entity of the formal for the procedure
7459 --------------------
7460 -- Add_Invariants --
7461 --------------------
7463 procedure Add_Invariants
(T
: Entity_Id
; Inherit
: Boolean) is
7473 procedure Replace_Type_Reference
(N
: Node_Id
);
7474 -- Replace a single occurrence N of the subtype name with a reference
7475 -- to the formal of the predicate function. N can be an identifier
7476 -- referencing the subtype, or a selected component, representing an
7477 -- appropriately qualified occurrence of the subtype name.
7479 procedure Replace_Type_References
is
7480 new Replace_Type_References_Generic
(Replace_Type_Reference
);
7481 -- Traverse an expression replacing all occurrences of the subtype
7482 -- name with appropriate references to the object that is the formal
7483 -- parameter of the predicate function. Note that we must ensure
7484 -- that the type and entity information is properly set in the
7485 -- replacement node, since we will do a Preanalyze call of this
7486 -- expression without proper visibility of the procedure argument.
7488 ----------------------------
7489 -- Replace_Type_Reference --
7490 ----------------------------
7492 -- Note: See comments in Add_Predicates.Replace_Type_Reference
7493 -- regarding handling of Sloc and Comes_From_Source.
7495 procedure Replace_Type_Reference
(N
: Node_Id
) is
7498 -- Add semantic information to node to be rewritten, for ASIS
7499 -- navigation needs.
7501 if Nkind
(N
) = N_Identifier
then
7505 elsif Nkind
(N
) = N_Selected_Component
then
7506 Analyze
(Prefix
(N
));
7507 Set_Entity
(Selector_Name
(N
), T
);
7508 Set_Etype
(Selector_Name
(N
), T
);
7511 -- Invariant'Class, replace with T'Class (obj)
7513 if Class_Present
(Ritem
) then
7515 Make_Type_Conversion
(Sloc
(N
),
7517 Make_Attribute_Reference
(Sloc
(N
),
7518 Prefix
=> New_Occurrence_Of
(T
, Sloc
(N
)),
7519 Attribute_Name
=> Name_Class
),
7520 Expression
=> Make_Identifier
(Sloc
(N
), Object_Name
)));
7522 Set_Entity
(Expression
(N
), Object_Entity
);
7523 Set_Etype
(Expression
(N
), Typ
);
7525 -- Invariant, replace with obj
7528 Rewrite
(N
, Make_Identifier
(Sloc
(N
), Object_Name
));
7529 Set_Entity
(N
, Object_Entity
);
7533 Set_Comes_From_Source
(N
, True);
7534 end Replace_Type_Reference
;
7536 -- Start of processing for Add_Invariants
7539 Ritem
:= First_Rep_Item
(T
);
7540 while Present
(Ritem
) loop
7541 if Nkind
(Ritem
) = N_Pragma
7542 and then Pragma_Name
(Ritem
) = Name_Invariant
7544 Arg1
:= First
(Pragma_Argument_Associations
(Ritem
));
7545 Arg2
:= Next
(Arg1
);
7546 Arg3
:= Next
(Arg2
);
7548 Arg1
:= Get_Pragma_Arg
(Arg1
);
7549 Arg2
:= Get_Pragma_Arg
(Arg2
);
7551 -- For Inherit case, ignore Invariant, process only Class case
7554 if not Class_Present
(Ritem
) then
7558 -- For Inherit false, process only item for right type
7561 if Entity
(Arg1
) /= Typ
then
7567 Stmts
:= Empty_List
;
7570 Exp
:= New_Copy_Tree
(Arg2
);
7572 -- Preserve sloc of original pragma Invariant
7574 Loc
:= Sloc
(Ritem
);
7576 -- We need to replace any occurrences of the name of the type
7577 -- with references to the object, converted to type'Class in
7578 -- the case of Invariant'Class aspects.
7580 Replace_Type_References
(Exp
, T
);
7582 -- If this invariant comes from an aspect, find the aspect
7583 -- specification, and replace the saved expression because
7584 -- we need the subtype references replaced for the calls to
7585 -- Preanalyze_Spec_Expressin in Check_Aspect_At_Freeze_Point
7586 -- and Check_Aspect_At_End_Of_Declarations.
7588 if From_Aspect_Specification
(Ritem
) then
7593 -- Loop to find corresponding aspect, note that this
7594 -- must be present given the pragma is marked delayed.
7596 -- Note: in practice Next_Rep_Item (Ritem) is Empty so
7597 -- this loop does nothing. Furthermore, why isn't this
7598 -- simply Corresponding_Aspect ???
7600 Aitem
:= Next_Rep_Item
(Ritem
);
7601 while Present
(Aitem
) loop
7602 if Nkind
(Aitem
) = N_Aspect_Specification
7603 and then Aspect_Rep_Item
(Aitem
) = Ritem
7606 (Identifier
(Aitem
), New_Copy_Tree
(Exp
));
7610 Aitem
:= Next_Rep_Item
(Aitem
);
7615 -- Now we need to preanalyze the expression to properly capture
7616 -- the visibility in the visible part. The expression will not
7617 -- be analyzed for real until the body is analyzed, but that is
7618 -- at the end of the private part and has the wrong visibility.
7620 Set_Parent
(Exp
, N
);
7621 Preanalyze_Assert_Expression
(Exp
, Standard_Boolean
);
7623 -- In ASIS mode, even if assertions are not enabled, we must
7624 -- analyze the original expression in the aspect specification
7625 -- because it is part of the original tree.
7627 if ASIS_Mode
and then From_Aspect_Specification
(Ritem
) then
7629 Inv
: constant Node_Id
:=
7630 Expression
(Corresponding_Aspect
(Ritem
));
7632 Replace_Type_References
(Inv
, T
);
7633 Preanalyze_Assert_Expression
(Inv
, Standard_Boolean
);
7637 -- Get name to be used for Check pragma
7639 if not From_Aspect_Specification
(Ritem
) then
7640 Nam
:= Name_Invariant
;
7642 Nam
:= Chars
(Identifier
(Corresponding_Aspect
(Ritem
)));
7645 -- Build first two arguments for Check pragma
7649 Make_Pragma_Argument_Association
(Loc
,
7650 Expression
=> Make_Identifier
(Loc
, Chars
=> Nam
)),
7651 Make_Pragma_Argument_Association
(Loc
,
7652 Expression
=> Exp
));
7654 -- Add message if present in Invariant pragma
7656 if Present
(Arg3
) then
7657 Str
:= Strval
(Get_Pragma_Arg
(Arg3
));
7659 -- If inherited case, and message starts "failed invariant",
7660 -- change it to be "failed inherited invariant".
7663 String_To_Name_Buffer
(Str
);
7665 if Name_Buffer
(1 .. 16) = "failed invariant" then
7666 Insert_Str_In_Name_Buffer
("inherited ", 8);
7667 Str
:= String_From_Name_Buffer
;
7672 Make_Pragma_Argument_Association
(Loc
,
7673 Expression
=> Make_String_Literal
(Loc
, Str
)));
7676 -- Add Check pragma to list of statements
7680 Pragma_Identifier
=>
7681 Make_Identifier
(Loc
, Name_Check
),
7682 Pragma_Argument_Associations
=> Assoc
));
7684 -- If Inherited case and option enabled, output info msg. Note
7685 -- that we know this is a case of Invariant'Class.
7687 if Inherit
and Opt
.List_Inherited_Aspects
then
7688 Error_Msg_Sloc
:= Sloc
(Ritem
);
7690 ("info: & inherits `Invariant''Class` aspect from #?L?",
7696 Next_Rep_Item
(Ritem
);
7700 -- Start of processing for Build_Invariant_Procedure
7708 -- If the aspect specification exists for some view of the type, the
7709 -- declaration for the procedure has been created.
7711 if Has_Invariants
(Typ
) then
7712 SId
:= Invariant_Procedure
(Typ
);
7715 -- If the body is already present, nothing to do. This will occur when
7716 -- the type is already frozen, which is the case when the invariant
7717 -- appears in a private part, and the freezing takes place before the
7718 -- final pass over full declarations.
7720 -- See Exp_Ch3.Insert_Component_Invariant_Checks for details.
7722 if Present
(SId
) then
7723 PDecl
:= Unit_Declaration_Node
(SId
);
7726 and then Nkind
(PDecl
) = N_Subprogram_Declaration
7727 and then Present
(Corresponding_Body
(PDecl
))
7733 PDecl
:= Build_Invariant_Procedure_Declaration
(Typ
);
7736 -- Recover formal of procedure, for use in the calls to invariant
7737 -- functions (including inherited ones).
7741 (First
(Parameter_Specifications
(Specification
(PDecl
))));
7742 Object_Name
:= Chars
(Object_Entity
);
7744 -- Add invariants for the current type
7746 Add_Invariants
(Typ
, Inherit
=> False);
7748 -- Add invariants for parent types
7751 Current_Typ
: Entity_Id
;
7752 Parent_Typ
: Entity_Id
;
7757 Parent_Typ
:= Etype
(Current_Typ
);
7759 if Is_Private_Type
(Parent_Typ
)
7760 and then Present
(Full_View
(Base_Type
(Parent_Typ
)))
7762 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
7765 exit when Parent_Typ
= Current_Typ
;
7767 Current_Typ
:= Parent_Typ
;
7768 Add_Invariants
(Current_Typ
, Inherit
=> True);
7772 -- Build the procedure if we generated at least one Check pragma
7774 if Stmts
/= No_List
then
7775 Spec
:= Copy_Separate_Tree
(Specification
(PDecl
));
7778 Make_Subprogram_Body
(Loc
,
7779 Specification
=> Spec
,
7780 Declarations
=> Empty_List
,
7781 Handled_Statement_Sequence
=>
7782 Make_Handled_Sequence_Of_Statements
(Loc
,
7783 Statements
=> Stmts
));
7785 -- Insert procedure declaration and spec at the appropriate points.
7786 -- If declaration is already analyzed, it was processed by the
7787 -- generated pragma.
7789 if Present
(Private_Decls
) then
7791 -- The spec goes at the end of visible declarations, but they have
7792 -- already been analyzed, so we need to explicitly do the analyze.
7794 if not Analyzed
(PDecl
) then
7795 Append_To
(Visible_Decls
, PDecl
);
7799 -- The body goes at the end of the private declarations, which we
7800 -- have not analyzed yet, so we do not need to perform an explicit
7801 -- analyze call. We skip this if there are no private declarations
7802 -- (this is an error that will be caught elsewhere);
7804 Append_To
(Private_Decls
, PBody
);
7806 -- If the invariant appears on the full view of a type, the
7807 -- analysis of the private part is complete, and we must
7808 -- analyze the new body explicitly.
7810 if In_Private_Part
(Current_Scope
) then
7814 -- If there are no private declarations this may be an error that
7815 -- will be diagnosed elsewhere. However, if this is a non-private
7816 -- type that inherits invariants, it needs no completion and there
7817 -- may be no private part. In this case insert invariant procedure
7818 -- at end of current declarative list, and analyze at once, given
7819 -- that the type is about to be frozen.
7821 elsif not Is_Private_Type
(Typ
) then
7822 Append_To
(Visible_Decls
, PDecl
);
7823 Append_To
(Visible_Decls
, PBody
);
7828 end Build_Invariant_Procedure
;
7830 -------------------------------
7831 -- Build_Predicate_Functions --
7832 -------------------------------
7834 -- The procedures that are constructed here have the form:
7836 -- function typPredicate (Ixxx : typ) return Boolean is
7839 -- exp1 and then exp2 and then ...
7840 -- and then typ1Predicate (typ1 (Ixxx))
7841 -- and then typ2Predicate (typ2 (Ixxx))
7843 -- end typPredicate;
7845 -- Here exp1, and exp2 are expressions from Predicate pragmas. Note that
7846 -- this is the point at which these expressions get analyzed, providing the
7847 -- required delay, and typ1, typ2, are entities from which predicates are
7848 -- inherited. Note that we do NOT generate Check pragmas, that's because we
7849 -- use this function even if checks are off, e.g. for membership tests.
7851 -- If the expression has at least one Raise_Expression, then we also build
7852 -- the typPredicateM version of the function, in which any occurrence of a
7853 -- Raise_Expression is converted to "return False".
7855 procedure Build_Predicate_Functions
(Typ
: Entity_Id
; N
: Node_Id
) is
7856 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
7859 -- This is the expression for the result of the function. It is
7860 -- is build by connecting the component predicates with AND THEN.
7863 -- This is the corresponding return expression for the Predicate_M
7864 -- function. It differs in that raise expressions are marked for
7865 -- special expansion (see Process_REs).
7867 Object_Name
: constant Name_Id
:= New_Internal_Name
('I');
7868 -- Name for argument of Predicate procedure. Note that we use the same
7869 -- name for both predicate functions. That way the reference within the
7870 -- predicate expression is the same in both functions.
7872 Object_Entity
: constant Entity_Id
:=
7873 Make_Defining_Identifier
(Loc
, Chars
=> Object_Name
);
7874 -- Entity for argument of Predicate procedure
7876 Object_Entity_M
: constant Entity_Id
:=
7877 Make_Defining_Identifier
(Loc
, Chars
=> Object_Name
);
7878 -- Entity for argument of Predicate_M procedure
7880 Raise_Expression_Present
: Boolean := False;
7881 -- Set True if Expr has at least one Raise_Expression
7883 procedure Add_Call
(T
: Entity_Id
);
7884 -- Includes a call to the predicate function for type T in Expr if T
7885 -- has predicates and Predicate_Function (T) is non-empty.
7887 procedure Add_Predicates
;
7888 -- Appends expressions for any Predicate pragmas in the rep item chain
7889 -- Typ to Expr. Note that we look only at items for this exact entity.
7890 -- Inheritance of predicates for the parent type is done by calling the
7891 -- Predicate_Function of the parent type, using Add_Call above.
7893 function Test_RE
(N
: Node_Id
) return Traverse_Result
;
7894 -- Used in Test_REs, tests one node for being a raise expression, and if
7895 -- so sets Raise_Expression_Present True.
7897 procedure Test_REs
is new Traverse_Proc
(Test_RE
);
7898 -- Tests to see if Expr contains any raise expressions
7900 function Process_RE
(N
: Node_Id
) return Traverse_Result
;
7901 -- Used in Process REs, tests if node N is a raise expression, and if
7902 -- so, marks it to be converted to return False.
7904 procedure Process_REs
is new Traverse_Proc
(Process_RE
);
7905 -- Marks any raise expressions in Expr_M to return False
7911 procedure Add_Call
(T
: Entity_Id
) is
7915 if Present
(T
) and then Present
(Predicate_Function
(T
)) then
7916 Set_Has_Predicates
(Typ
);
7918 -- Build the call to the predicate function of T
7922 (T
, Convert_To
(T
, Make_Identifier
(Loc
, Object_Name
)));
7924 -- Add call to evolving expression, using AND THEN if needed
7931 Make_And_Then
(Sloc
(Expr
),
7932 Left_Opnd
=> Relocate_Node
(Expr
),
7936 -- Output info message on inheritance if required. Note we do not
7937 -- give this information for generic actual types, since it is
7938 -- unwelcome noise in that case in instantiations. We also
7939 -- generally suppress the message in instantiations, and also
7940 -- if it involves internal names.
7942 if Opt
.List_Inherited_Aspects
7943 and then not Is_Generic_Actual_Type
(Typ
)
7944 and then Instantiation_Depth
(Sloc
(Typ
)) = 0
7945 and then not Is_Internal_Name
(Chars
(T
))
7946 and then not Is_Internal_Name
(Chars
(Typ
))
7948 Error_Msg_Sloc
:= Sloc
(Predicate_Function
(T
));
7949 Error_Msg_Node_2
:= T
;
7950 Error_Msg_N
("info: & inherits predicate from & #?L?", Typ
);
7955 --------------------
7956 -- Add_Predicates --
7957 --------------------
7959 procedure Add_Predicates
is
7964 procedure Replace_Type_Reference
(N
: Node_Id
);
7965 -- Replace a single occurrence N of the subtype name with a reference
7966 -- to the formal of the predicate function. N can be an identifier
7967 -- referencing the subtype, or a selected component, representing an
7968 -- appropriately qualified occurrence of the subtype name.
7970 procedure Replace_Type_References
is
7971 new Replace_Type_References_Generic
(Replace_Type_Reference
);
7972 -- Traverse an expression changing every occurrence of an identifier
7973 -- whose name matches the name of the subtype with a reference to
7974 -- the formal parameter of the predicate function.
7976 ----------------------------
7977 -- Replace_Type_Reference --
7978 ----------------------------
7980 procedure Replace_Type_Reference
(N
: Node_Id
) is
7982 Rewrite
(N
, Make_Identifier
(Sloc
(N
), Object_Name
));
7983 -- Use the Sloc of the usage name, not the defining name
7986 Set_Entity
(N
, Object_Entity
);
7988 -- We want to treat the node as if it comes from source, so that
7989 -- ASIS will not ignore it
7991 Set_Comes_From_Source
(N
, True);
7992 end Replace_Type_Reference
;
7994 -- Start of processing for Add_Predicates
7997 Ritem
:= First_Rep_Item
(Typ
);
7998 while Present
(Ritem
) loop
7999 if Nkind
(Ritem
) = N_Pragma
8000 and then Pragma_Name
(Ritem
) = Name_Predicate
8002 -- Acquire arguments
8004 Arg1
:= First
(Pragma_Argument_Associations
(Ritem
));
8005 Arg2
:= Next
(Arg1
);
8007 Arg1
:= Get_Pragma_Arg
(Arg1
);
8008 Arg2
:= Get_Pragma_Arg
(Arg2
);
8010 -- See if this predicate pragma is for the current type or for
8011 -- its full view. A predicate on a private completion is placed
8012 -- on the partial view beause this is the visible entity that
8015 if Entity
(Arg1
) = Typ
8016 or else Full_View
(Entity
(Arg1
)) = Typ
8018 -- We have a match, this entry is for our subtype
8020 -- We need to replace any occurrences of the name of the
8021 -- type with references to the object.
8023 Replace_Type_References
(Arg2
, Typ
);
8025 -- If this predicate comes from an aspect, find the aspect
8026 -- specification, and replace the saved expression because
8027 -- we need the subtype references replaced for the calls to
8028 -- Preanalyze_Spec_Expressin in Check_Aspect_At_Freeze_Point
8029 -- and Check_Aspect_At_End_Of_Declarations.
8031 if From_Aspect_Specification
(Ritem
) then
8036 -- Loop to find corresponding aspect, note that this
8037 -- must be present given the pragma is marked delayed.
8039 Aitem
:= Next_Rep_Item
(Ritem
);
8041 if Nkind
(Aitem
) = N_Aspect_Specification
8042 and then Aspect_Rep_Item
(Aitem
) = Ritem
8045 (Identifier
(Aitem
), New_Copy_Tree
(Arg2
));
8049 Aitem
:= Next_Rep_Item
(Aitem
);
8054 -- Now we can add the expression
8057 Expr
:= Relocate_Node
(Arg2
);
8059 -- There already was a predicate, so add to it
8064 Left_Opnd
=> Relocate_Node
(Expr
),
8065 Right_Opnd
=> Relocate_Node
(Arg2
));
8070 Next_Rep_Item
(Ritem
);
8078 function Process_RE
(N
: Node_Id
) return Traverse_Result
is
8080 if Nkind
(N
) = N_Raise_Expression
then
8081 Set_Convert_To_Return_False
(N
);
8092 function Test_RE
(N
: Node_Id
) return Traverse_Result
is
8094 if Nkind
(N
) = N_Raise_Expression
then
8095 Raise_Expression_Present
:= True;
8102 -- Start of processing for Build_Predicate_Functions
8105 -- Return if already built or if type does not have predicates
8107 if not Has_Predicates
(Typ
)
8108 or else Present
(Predicate_Function
(Typ
))
8113 -- Prepare to construct predicate expression
8117 -- Add Predicates for the current type
8121 -- Add predicates for ancestor if present
8124 Atyp
: constant Entity_Id
:= Nearest_Ancestor
(Typ
);
8126 if Present
(Atyp
) then
8131 -- Case where predicates are present
8133 if Present
(Expr
) then
8135 -- Test for raise expression present
8139 -- If raise expression is present, capture a copy of Expr for use
8140 -- in building the predicateM function version later on. For this
8141 -- copy we replace references to Object_Entity by Object_Entity_M.
8143 if Raise_Expression_Present
then
8145 Map
: constant Elist_Id
:= New_Elmt_List
;
8147 Append_Elmt
(Object_Entity
, Map
);
8148 Append_Elmt
(Object_Entity_M
, Map
);
8149 Expr_M
:= New_Copy_Tree
(Expr
, Map
=> Map
);
8153 -- Build the main predicate function
8156 SId
: constant Entity_Id
:=
8157 Make_Defining_Identifier
(Loc
,
8158 Chars
=> New_External_Name
(Chars
(Typ
), "Predicate"));
8159 -- The entity for the the function spec
8161 SIdB
: constant Entity_Id
:=
8162 Make_Defining_Identifier
(Loc
,
8163 Chars
=> New_External_Name
(Chars
(Typ
), "Predicate"));
8164 -- The entity for the function body
8171 -- Build function declaration
8173 Set_Ekind
(SId
, E_Function
);
8174 Set_Is_Internal
(SId
);
8175 Set_Is_Predicate_Function
(SId
);
8176 Set_Predicate_Function
(Typ
, SId
);
8178 -- The predicate function is shared between views of a type
8180 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
8181 Set_Predicate_Function
(Full_View
(Typ
), SId
);
8185 Make_Function_Specification
(Loc
,
8186 Defining_Unit_Name
=> SId
,
8187 Parameter_Specifications
=> New_List
(
8188 Make_Parameter_Specification
(Loc
,
8189 Defining_Identifier
=> Object_Entity
,
8190 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))),
8191 Result_Definition
=>
8192 New_Occurrence_Of
(Standard_Boolean
, Loc
));
8195 Make_Subprogram_Declaration
(Loc
,
8196 Specification
=> Spec
);
8198 -- Build function body
8201 Make_Function_Specification
(Loc
,
8202 Defining_Unit_Name
=> SIdB
,
8203 Parameter_Specifications
=> New_List
(
8204 Make_Parameter_Specification
(Loc
,
8205 Defining_Identifier
=>
8206 Make_Defining_Identifier
(Loc
, Object_Name
),
8208 New_Occurrence_Of
(Typ
, Loc
))),
8209 Result_Definition
=>
8210 New_Occurrence_Of
(Standard_Boolean
, Loc
));
8213 Make_Subprogram_Body
(Loc
,
8214 Specification
=> Spec
,
8215 Declarations
=> Empty_List
,
8216 Handled_Statement_Sequence
=>
8217 Make_Handled_Sequence_Of_Statements
(Loc
,
8218 Statements
=> New_List
(
8219 Make_Simple_Return_Statement
(Loc
,
8220 Expression
=> Expr
))));
8222 -- Insert declaration before freeze node and body after
8224 Insert_Before_And_Analyze
(N
, FDecl
);
8225 Insert_After_And_Analyze
(N
, FBody
);
8228 -- Test for raise expressions present and if so build M version
8230 if Raise_Expression_Present
then
8232 SId
: constant Entity_Id
:=
8233 Make_Defining_Identifier
(Loc
,
8234 Chars
=> New_External_Name
(Chars
(Typ
), "PredicateM"));
8235 -- The entity for the the function spec
8237 SIdB
: constant Entity_Id
:=
8238 Make_Defining_Identifier
(Loc
,
8239 Chars
=> New_External_Name
(Chars
(Typ
), "PredicateM"));
8240 -- The entity for the function body
8248 -- Mark any raise expressions for special expansion
8250 Process_REs
(Expr_M
);
8252 -- Build function declaration
8254 Set_Ekind
(SId
, E_Function
);
8255 Set_Is_Predicate_Function_M
(SId
);
8256 Set_Predicate_Function_M
(Typ
, SId
);
8258 -- The predicate function is shared between views of a type
8260 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
8261 Set_Predicate_Function_M
(Full_View
(Typ
), SId
);
8265 Make_Function_Specification
(Loc
,
8266 Defining_Unit_Name
=> SId
,
8267 Parameter_Specifications
=> New_List
(
8268 Make_Parameter_Specification
(Loc
,
8269 Defining_Identifier
=> Object_Entity_M
,
8270 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))),
8271 Result_Definition
=>
8272 New_Occurrence_Of
(Standard_Boolean
, Loc
));
8275 Make_Subprogram_Declaration
(Loc
,
8276 Specification
=> Spec
);
8278 -- Build function body
8281 Make_Function_Specification
(Loc
,
8282 Defining_Unit_Name
=> SIdB
,
8283 Parameter_Specifications
=> New_List
(
8284 Make_Parameter_Specification
(Loc
,
8285 Defining_Identifier
=>
8286 Make_Defining_Identifier
(Loc
, Object_Name
),
8288 New_Occurrence_Of
(Typ
, Loc
))),
8289 Result_Definition
=>
8290 New_Occurrence_Of
(Standard_Boolean
, Loc
));
8292 -- Build the body, we declare the boolean expression before
8293 -- doing the return, because we are not really confident of
8294 -- what happens if a return appears within a return.
8297 Make_Defining_Identifier
(Loc
,
8298 Chars
=> New_Internal_Name
('B'));
8301 Make_Subprogram_Body
(Loc
,
8302 Specification
=> Spec
,
8304 Declarations
=> New_List
(
8305 Make_Object_Declaration
(Loc
,
8306 Defining_Identifier
=> BTemp
,
8307 Constant_Present
=> True,
8308 Object_Definition
=>
8309 New_Occurrence_Of
(Standard_Boolean
, Loc
),
8310 Expression
=> Expr_M
)),
8312 Handled_Statement_Sequence
=>
8313 Make_Handled_Sequence_Of_Statements
(Loc
,
8314 Statements
=> New_List
(
8315 Make_Simple_Return_Statement
(Loc
,
8316 Expression
=> New_Occurrence_Of
(BTemp
, Loc
)))));
8318 -- Insert declaration before freeze node and body after
8320 Insert_Before_And_Analyze
(N
, FDecl
);
8321 Insert_After_And_Analyze
(N
, FBody
);
8325 -- See if we have a static predicate. Note that the answer may be
8326 -- yes even if we have an explicit Dynamic_Predicate present.
8333 if not Is_Scalar_Type
(Typ
) and then not Is_String_Type
(Typ
) then
8336 PS
:= Is_Predicate_Static
(Expr
, Object_Name
);
8339 -- Case where we have a predicate-static aspect
8343 -- We don't set Has_Static_Predicate_Aspect, since we can have
8344 -- any of the three cases (Predicate, Dynamic_Predicate, or
8345 -- Static_Predicate) generating a predicate with an expression
8346 -- that is predicate-static. We just indicate that we have a
8347 -- predicate that can be treated as static.
8349 Set_Has_Static_Predicate
(Typ
);
8351 -- For discrete subtype, build the static predicate list
8353 if Is_Discrete_Type
(Typ
) then
8354 if not Is_Static_Subtype
(Typ
) then
8356 -- This can only happen in the presence of previous
8359 pragma Assert
(Serious_Errors_Detected
> 0);
8363 Build_Discrete_Static_Predicate
(Typ
, Expr
, Object_Name
);
8365 -- If we don't get a static predicate list, it means that we
8366 -- have a case where this is not possible, most typically in
8367 -- the case where we inherit a dynamic predicate. We do not
8368 -- consider this an error, we just leave the predicate as
8369 -- dynamic. But if we do succeed in building the list, then
8370 -- we mark the predicate as static.
8372 if No
(Static_Discrete_Predicate
(Typ
)) then
8373 Set_Has_Static_Predicate
(Typ
, False);
8376 -- For real or string subtype, save predicate expression
8378 elsif Is_Real_Type
(Typ
) or else Is_String_Type
(Typ
) then
8379 Set_Static_Real_Or_String_Predicate
(Typ
, Expr
);
8382 -- Case of dynamic predicate (expression is not predicate-static)
8385 -- Again, we don't set Has_Dynamic_Predicate_Aspect, since that
8386 -- is only set if we have an explicit Dynamic_Predicate aspect
8387 -- given. Here we may simply have a Predicate aspect where the
8388 -- expression happens not to be predicate-static.
8390 -- Emit an error when the predicate is categorized as static
8391 -- but its expression is not predicate-static.
8393 -- First a little fiddling to get a nice location for the
8394 -- message. If the expression is of the form (A and then B),
8395 -- then use the left operand for the Sloc. This avoids getting
8396 -- confused by a call to a higher-level predicate with a less
8397 -- convenient source location.
8400 while Nkind
(EN
) = N_And_Then
loop
8401 EN
:= Left_Opnd
(EN
);
8404 -- Now post appropriate message
8406 if Has_Static_Predicate_Aspect
(Typ
) then
8407 if Is_Scalar_Type
(Typ
) or else Is_String_Type
(Typ
) then
8409 ("expression is not predicate-static (RM 3.2.4(16-22))",
8413 ("static predicate requires scalar or string type", EN
);
8419 end Build_Predicate_Functions
;
8421 -----------------------------------------
8422 -- Check_Aspect_At_End_Of_Declarations --
8423 -----------------------------------------
8425 procedure Check_Aspect_At_End_Of_Declarations
(ASN
: Node_Id
) is
8426 Ent
: constant Entity_Id
:= Entity
(ASN
);
8427 Ident
: constant Node_Id
:= Identifier
(ASN
);
8428 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Chars
(Ident
));
8430 End_Decl_Expr
: constant Node_Id
:= Entity
(Ident
);
8431 -- Expression to be analyzed at end of declarations
8433 Freeze_Expr
: constant Node_Id
:= Expression
(ASN
);
8434 -- Expression from call to Check_Aspect_At_Freeze_Point
8436 T
: constant Entity_Id
:= Etype
(Freeze_Expr
);
8437 -- Type required for preanalyze call
8440 -- Set False if error
8442 -- On entry to this procedure, Entity (Ident) contains a copy of the
8443 -- original expression from the aspect, saved for this purpose, and
8444 -- but Expression (Ident) is a preanalyzed copy of the expression,
8445 -- preanalyzed just after the freeze point.
8447 procedure Check_Overloaded_Name
;
8448 -- For aspects whose expression is simply a name, this routine checks if
8449 -- the name is overloaded or not. If so, it verifies there is an
8450 -- interpretation that matches the entity obtained at the freeze point,
8451 -- otherwise the compiler complains.
8453 ---------------------------
8454 -- Check_Overloaded_Name --
8455 ---------------------------
8457 procedure Check_Overloaded_Name
is
8459 if not Is_Overloaded
(End_Decl_Expr
) then
8460 Err
:= not Is_Entity_Name
(End_Decl_Expr
)
8461 or else Entity
(End_Decl_Expr
) /= Entity
(Freeze_Expr
);
8467 Index
: Interp_Index
;
8471 Get_First_Interp
(End_Decl_Expr
, Index
, It
);
8472 while Present
(It
.Typ
) loop
8473 if It
.Nam
= Entity
(Freeze_Expr
) then
8478 Get_Next_Interp
(Index
, It
);
8482 end Check_Overloaded_Name
;
8484 -- Start of processing for Check_Aspect_At_End_Of_Declarations
8487 -- Case of aspects Dimension, Dimension_System and Synchronization
8489 if A_Id
= Aspect_Synchronization
then
8492 -- Case of stream attributes, just have to compare entities. However,
8493 -- the expression is just a name (possibly overloaded), and there may
8494 -- be stream operations declared for unrelated types, so we just need
8495 -- to verify that one of these interpretations is the one available at
8496 -- at the freeze point.
8498 elsif A_Id
= Aspect_Input
or else
8499 A_Id
= Aspect_Output
or else
8500 A_Id
= Aspect_Read
or else
8503 Analyze
(End_Decl_Expr
);
8504 Check_Overloaded_Name
;
8506 elsif A_Id
= Aspect_Variable_Indexing
or else
8507 A_Id
= Aspect_Constant_Indexing
or else
8508 A_Id
= Aspect_Default_Iterator
or else
8509 A_Id
= Aspect_Iterator_Element
8511 -- Make type unfrozen before analysis, to prevent spurious errors
8512 -- about late attributes.
8514 Set_Is_Frozen
(Ent
, False);
8515 Analyze
(End_Decl_Expr
);
8516 Set_Is_Frozen
(Ent
, True);
8518 -- If the end of declarations comes before any other freeze
8519 -- point, the Freeze_Expr is not analyzed: no check needed.
8521 if Analyzed
(Freeze_Expr
) and then not In_Instance
then
8522 Check_Overloaded_Name
;
8530 -- Indicate that the expression comes from an aspect specification,
8531 -- which is used in subsequent analysis even if expansion is off.
8533 Set_Parent
(End_Decl_Expr
, ASN
);
8535 -- In a generic context the aspect expressions have not been
8536 -- preanalyzed, so do it now. There are no conformance checks
8537 -- to perform in this case.
8540 Check_Aspect_At_Freeze_Point
(ASN
);
8543 -- The default values attributes may be defined in the private part,
8544 -- and the analysis of the expression may take place when only the
8545 -- partial view is visible. The expression must be scalar, so use
8546 -- the full view to resolve.
8548 elsif (A_Id
= Aspect_Default_Value
8550 A_Id
= Aspect_Default_Component_Value
)
8551 and then Is_Private_Type
(T
)
8553 Preanalyze_Spec_Expression
(End_Decl_Expr
, Full_View
(T
));
8556 Preanalyze_Spec_Expression
(End_Decl_Expr
, T
);
8559 Err
:= not Fully_Conformant_Expressions
(End_Decl_Expr
, Freeze_Expr
);
8562 -- Output error message if error. Force error on aspect specification
8563 -- even if there is an error on the expression itself.
8567 ("!visibility of aspect for& changes after freeze point",
8570 ("info: & is frozen here, aspects evaluated at this point??",
8571 Freeze_Node
(Ent
), Ent
);
8573 end Check_Aspect_At_End_Of_Declarations
;
8575 ----------------------------------
8576 -- Check_Aspect_At_Freeze_Point --
8577 ----------------------------------
8579 procedure Check_Aspect_At_Freeze_Point
(ASN
: Node_Id
) is
8580 Ident
: constant Node_Id
:= Identifier
(ASN
);
8581 -- Identifier (use Entity field to save expression)
8583 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Chars
(Ident
));
8585 T
: Entity_Id
:= Empty
;
8586 -- Type required for preanalyze call
8589 -- On entry to this procedure, Entity (Ident) contains a copy of the
8590 -- original expression from the aspect, saved for this purpose.
8592 -- On exit from this procedure Entity (Ident) is unchanged, still
8593 -- containing that copy, but Expression (Ident) is a preanalyzed copy
8594 -- of the expression, preanalyzed just after the freeze point.
8596 -- Make a copy of the expression to be preanalyzed
8598 Set_Expression
(ASN
, New_Copy_Tree
(Entity
(Ident
)));
8600 -- Find type for preanalyze call
8604 -- No_Aspect should be impossible
8607 raise Program_Error
;
8609 -- Aspects taking an optional boolean argument
8611 when Boolean_Aspects |
8612 Library_Unit_Aspects
=>
8614 T
:= Standard_Boolean
;
8616 -- Aspects corresponding to attribute definition clauses
8618 when Aspect_Address
=>
8619 T
:= RTE
(RE_Address
);
8621 when Aspect_Attach_Handler
=>
8622 T
:= RTE
(RE_Interrupt_ID
);
8624 when Aspect_Bit_Order | Aspect_Scalar_Storage_Order
=>
8625 T
:= RTE
(RE_Bit_Order
);
8627 when Aspect_Convention
=>
8631 T
:= RTE
(RE_CPU_Range
);
8633 -- Default_Component_Value is resolved with the component type
8635 when Aspect_Default_Component_Value
=>
8636 T
:= Component_Type
(Entity
(ASN
));
8638 -- Default_Value is resolved with the type entity in question
8640 when Aspect_Default_Value
=>
8643 -- Depends is a delayed aspect because it mentiones names first
8644 -- introduced by aspect Global which is already delayed. There is
8645 -- no action to be taken with respect to the aspect itself as the
8646 -- analysis is done by the corresponding pragma.
8648 when Aspect_Depends
=>
8651 when Aspect_Dispatching_Domain
=>
8652 T
:= RTE
(RE_Dispatching_Domain
);
8654 when Aspect_External_Tag
=>
8655 T
:= Standard_String
;
8657 when Aspect_External_Name
=>
8658 T
:= Standard_String
;
8660 -- Global is a delayed aspect because it may reference names that
8661 -- have not been declared yet. There is no action to be taken with
8662 -- respect to the aspect itself as the reference checking is done
8663 -- on the corresponding pragma.
8665 when Aspect_Global
=>
8668 when Aspect_Link_Name
=>
8669 T
:= Standard_String
;
8671 when Aspect_Priority | Aspect_Interrupt_Priority
=>
8672 T
:= Standard_Integer
;
8674 when Aspect_Relative_Deadline
=>
8675 T
:= RTE
(RE_Time_Span
);
8677 when Aspect_Small
=>
8678 T
:= Universal_Real
;
8680 -- For a simple storage pool, we have to retrieve the type of the
8681 -- pool object associated with the aspect's corresponding attribute
8682 -- definition clause.
8684 when Aspect_Simple_Storage_Pool
=>
8685 T
:= Etype
(Expression
(Aspect_Rep_Item
(ASN
)));
8687 when Aspect_Storage_Pool
=>
8688 T
:= Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
));
8690 when Aspect_Alignment |
8691 Aspect_Component_Size |
8692 Aspect_Machine_Radix |
8693 Aspect_Object_Size |
8695 Aspect_Storage_Size |
8696 Aspect_Stream_Size |
8697 Aspect_Value_Size
=>
8700 when Aspect_Linker_Section
=>
8701 T
:= Standard_String
;
8703 when Aspect_Synchronization
=>
8706 -- Special case, the expression of these aspects is just an entity
8707 -- that does not need any resolution, so just analyze.
8716 Analyze
(Expression
(ASN
));
8719 -- Same for Iterator aspects, where the expression is a function
8720 -- name. Legality rules are checked separately.
8722 when Aspect_Constant_Indexing |
8723 Aspect_Default_Iterator |
8724 Aspect_Iterator_Element |
8725 Aspect_Variable_Indexing
=>
8726 Analyze
(Expression
(ASN
));
8729 -- Ditto for Iterable, legality checks in Validate_Iterable_Aspect.
8731 when Aspect_Iterable
=>
8735 Cursor
: constant Entity_Id
:= Get_Cursor_Type
(ASN
, T
);
8740 if Cursor
= Any_Type
then
8744 Assoc
:= First
(Component_Associations
(Expression
(ASN
)));
8745 while Present
(Assoc
) loop
8746 Expr
:= Expression
(Assoc
);
8749 if not Error_Posted
(Expr
) then
8750 Resolve_Iterable_Operation
8751 (Expr
, Cursor
, T
, Chars
(First
(Choices
(Assoc
))));
8760 -- Invariant/Predicate take boolean expressions
8762 when Aspect_Dynamic_Predicate |
8765 Aspect_Static_Predicate |
8766 Aspect_Type_Invariant
=>
8767 T
:= Standard_Boolean
;
8769 -- Here is the list of aspects that don't require delay analysis
8771 when Aspect_Abstract_State |
8773 Aspect_Contract_Cases |
8774 Aspect_Default_Initial_Condition |
8776 Aspect_Dimension_System |
8777 Aspect_Implicit_Dereference |
8778 Aspect_Initial_Condition |
8779 Aspect_Initializes |
8780 Aspect_Obsolescent |
8783 Aspect_Postcondition |
8785 Aspect_Precondition |
8786 Aspect_Refined_Depends |
8787 Aspect_Refined_Global |
8788 Aspect_Refined_Post |
8789 Aspect_Refined_State |
8792 raise Program_Error
;
8796 -- Do the preanalyze call
8798 Preanalyze_Spec_Expression
(Expression
(ASN
), T
);
8799 end Check_Aspect_At_Freeze_Point
;
8801 -----------------------------------
8802 -- Check_Constant_Address_Clause --
8803 -----------------------------------
8805 procedure Check_Constant_Address_Clause
8809 procedure Check_At_Constant_Address
(Nod
: Node_Id
);
8810 -- Checks that the given node N represents a name whose 'Address is
8811 -- constant (in the same sense as OK_Constant_Address_Clause, i.e. the
8812 -- address value is the same at the point of declaration of U_Ent and at
8813 -- the time of elaboration of the address clause.
8815 procedure Check_Expr_Constants
(Nod
: Node_Id
);
8816 -- Checks that Nod meets the requirements for a constant address clause
8817 -- in the sense of the enclosing procedure.
8819 procedure Check_List_Constants
(Lst
: List_Id
);
8820 -- Check that all elements of list Lst meet the requirements for a
8821 -- constant address clause in the sense of the enclosing procedure.
8823 -------------------------------
8824 -- Check_At_Constant_Address --
8825 -------------------------------
8827 procedure Check_At_Constant_Address
(Nod
: Node_Id
) is
8829 if Is_Entity_Name
(Nod
) then
8830 if Present
(Address_Clause
(Entity
((Nod
)))) then
8832 ("invalid address clause for initialized object &!",
8835 ("address for& cannot" &
8836 " depend on another address clause! (RM 13.1(22))!",
8839 elsif In_Same_Source_Unit
(Entity
(Nod
), U_Ent
)
8840 and then Sloc
(U_Ent
) < Sloc
(Entity
(Nod
))
8843 ("invalid address clause for initialized object &!",
8845 Error_Msg_Node_2
:= U_Ent
;
8847 ("\& must be defined before & (RM 13.1(22))!",
8851 elsif Nkind
(Nod
) = N_Selected_Component
then
8853 T
: constant Entity_Id
:= Etype
(Prefix
(Nod
));
8856 if (Is_Record_Type
(T
)
8857 and then Has_Discriminants
(T
))
8860 and then Is_Record_Type
(Designated_Type
(T
))
8861 and then Has_Discriminants
(Designated_Type
(T
)))
8864 ("invalid address clause for initialized object &!",
8867 ("\address cannot depend on component" &
8868 " of discriminated record (RM 13.1(22))!",
8871 Check_At_Constant_Address
(Prefix
(Nod
));
8875 elsif Nkind
(Nod
) = N_Indexed_Component
then
8876 Check_At_Constant_Address
(Prefix
(Nod
));
8877 Check_List_Constants
(Expressions
(Nod
));
8880 Check_Expr_Constants
(Nod
);
8882 end Check_At_Constant_Address
;
8884 --------------------------
8885 -- Check_Expr_Constants --
8886 --------------------------
8888 procedure Check_Expr_Constants
(Nod
: Node_Id
) is
8889 Loc_U_Ent
: constant Source_Ptr
:= Sloc
(U_Ent
);
8890 Ent
: Entity_Id
:= Empty
;
8893 if Nkind
(Nod
) in N_Has_Etype
8894 and then Etype
(Nod
) = Any_Type
8900 when N_Empty | N_Error
=>
8903 when N_Identifier | N_Expanded_Name
=>
8904 Ent
:= Entity
(Nod
);
8906 -- We need to look at the original node if it is different
8907 -- from the node, since we may have rewritten things and
8908 -- substituted an identifier representing the rewrite.
8910 if Original_Node
(Nod
) /= Nod
then
8911 Check_Expr_Constants
(Original_Node
(Nod
));
8913 -- If the node is an object declaration without initial
8914 -- value, some code has been expanded, and the expression
8915 -- is not constant, even if the constituents might be
8916 -- acceptable, as in A'Address + offset.
8918 if Ekind
(Ent
) = E_Variable
8920 Nkind
(Declaration_Node
(Ent
)) = N_Object_Declaration
8922 No
(Expression
(Declaration_Node
(Ent
)))
8925 ("invalid address clause for initialized object &!",
8928 -- If entity is constant, it may be the result of expanding
8929 -- a check. We must verify that its declaration appears
8930 -- before the object in question, else we also reject the
8933 elsif Ekind
(Ent
) = E_Constant
8934 and then In_Same_Source_Unit
(Ent
, U_Ent
)
8935 and then Sloc
(Ent
) > Loc_U_Ent
8938 ("invalid address clause for initialized object &!",
8945 -- Otherwise look at the identifier and see if it is OK
8947 if Ekind_In
(Ent
, E_Named_Integer
, E_Named_Real
)
8948 or else Is_Type
(Ent
)
8953 Ekind
(Ent
) = E_Constant
8955 Ekind
(Ent
) = E_In_Parameter
8957 -- This is the case where we must have Ent defined before
8958 -- U_Ent. Clearly if they are in different units this
8959 -- requirement is met since the unit containing Ent is
8960 -- already processed.
8962 if not In_Same_Source_Unit
(Ent
, U_Ent
) then
8965 -- Otherwise location of Ent must be before the location
8966 -- of U_Ent, that's what prior defined means.
8968 elsif Sloc
(Ent
) < Loc_U_Ent
then
8973 ("invalid address clause for initialized object &!",
8975 Error_Msg_Node_2
:= U_Ent
;
8977 ("\& must be defined before & (RM 13.1(22))!",
8981 elsif Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
8982 Check_Expr_Constants
(Original_Node
(Nod
));
8986 ("invalid address clause for initialized object &!",
8989 if Comes_From_Source
(Ent
) then
8991 ("\reference to variable& not allowed"
8992 & " (RM 13.1(22))!", Nod
, Ent
);
8995 ("non-static expression not allowed"
8996 & " (RM 13.1(22))!", Nod
);
9000 when N_Integer_Literal
=>
9002 -- If this is a rewritten unchecked conversion, in a system
9003 -- where Address is an integer type, always use the base type
9004 -- for a literal value. This is user-friendly and prevents
9005 -- order-of-elaboration issues with instances of unchecked
9008 if Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
9009 Set_Etype
(Nod
, Base_Type
(Etype
(Nod
)));
9012 when N_Real_Literal |
9014 N_Character_Literal
=>
9018 Check_Expr_Constants
(Low_Bound
(Nod
));
9019 Check_Expr_Constants
(High_Bound
(Nod
));
9021 when N_Explicit_Dereference
=>
9022 Check_Expr_Constants
(Prefix
(Nod
));
9024 when N_Indexed_Component
=>
9025 Check_Expr_Constants
(Prefix
(Nod
));
9026 Check_List_Constants
(Expressions
(Nod
));
9029 Check_Expr_Constants
(Prefix
(Nod
));
9030 Check_Expr_Constants
(Discrete_Range
(Nod
));
9032 when N_Selected_Component
=>
9033 Check_Expr_Constants
(Prefix
(Nod
));
9035 when N_Attribute_Reference
=>
9036 if Nam_In
(Attribute_Name
(Nod
), Name_Address
,
9038 Name_Unchecked_Access
,
9039 Name_Unrestricted_Access
)
9041 Check_At_Constant_Address
(Prefix
(Nod
));
9044 Check_Expr_Constants
(Prefix
(Nod
));
9045 Check_List_Constants
(Expressions
(Nod
));
9049 Check_List_Constants
(Component_Associations
(Nod
));
9050 Check_List_Constants
(Expressions
(Nod
));
9052 when N_Component_Association
=>
9053 Check_Expr_Constants
(Expression
(Nod
));
9055 when N_Extension_Aggregate
=>
9056 Check_Expr_Constants
(Ancestor_Part
(Nod
));
9057 Check_List_Constants
(Component_Associations
(Nod
));
9058 Check_List_Constants
(Expressions
(Nod
));
9063 when N_Binary_Op | N_Short_Circuit | N_Membership_Test
=>
9064 Check_Expr_Constants
(Left_Opnd
(Nod
));
9065 Check_Expr_Constants
(Right_Opnd
(Nod
));
9068 Check_Expr_Constants
(Right_Opnd
(Nod
));
9070 when N_Type_Conversion |
9071 N_Qualified_Expression |
9073 N_Unchecked_Type_Conversion
=>
9074 Check_Expr_Constants
(Expression
(Nod
));
9076 when N_Function_Call
=>
9077 if not Is_Pure
(Entity
(Name
(Nod
))) then
9079 ("invalid address clause for initialized object &!",
9083 ("\function & is not pure (RM 13.1(22))!",
9084 Nod
, Entity
(Name
(Nod
)));
9087 Check_List_Constants
(Parameter_Associations
(Nod
));
9090 when N_Parameter_Association
=>
9091 Check_Expr_Constants
(Explicit_Actual_Parameter
(Nod
));
9095 ("invalid address clause for initialized object &!",
9098 ("\must be constant defined before& (RM 13.1(22))!",
9101 end Check_Expr_Constants
;
9103 --------------------------
9104 -- Check_List_Constants --
9105 --------------------------
9107 procedure Check_List_Constants
(Lst
: List_Id
) is
9111 if Present
(Lst
) then
9112 Nod1
:= First
(Lst
);
9113 while Present
(Nod1
) loop
9114 Check_Expr_Constants
(Nod1
);
9118 end Check_List_Constants
;
9120 -- Start of processing for Check_Constant_Address_Clause
9123 -- If rep_clauses are to be ignored, no need for legality checks. In
9124 -- particular, no need to pester user about rep clauses that violate
9125 -- the rule on constant addresses, given that these clauses will be
9126 -- removed by Freeze before they reach the back end.
9128 if not Ignore_Rep_Clauses
then
9129 Check_Expr_Constants
(Expr
);
9131 end Check_Constant_Address_Clause
;
9133 ---------------------------
9134 -- Check_Pool_Size_Clash --
9135 ---------------------------
9137 procedure Check_Pool_Size_Clash
(Ent
: Entity_Id
; SP
, SS
: Node_Id
) is
9141 -- We need to find out which one came first. Note that in the case of
9142 -- aspects mixed with pragmas there are cases where the processing order
9143 -- is reversed, which is why we do the check here.
9145 if Sloc
(SP
) < Sloc
(SS
) then
9146 Error_Msg_Sloc
:= Sloc
(SP
);
9148 Error_Msg_NE
("Storage_Pool previously given for&#", Post
, Ent
);
9151 Error_Msg_Sloc
:= Sloc
(SS
);
9153 Error_Msg_NE
("Storage_Size previously given for&#", Post
, Ent
);
9157 ("\cannot have Storage_Size and Storage_Pool (RM 13.11(3))", Post
);
9158 end Check_Pool_Size_Clash
;
9160 ----------------------------------------
9161 -- Check_Record_Representation_Clause --
9162 ----------------------------------------
9164 procedure Check_Record_Representation_Clause
(N
: Node_Id
) is
9165 Loc
: constant Source_Ptr
:= Sloc
(N
);
9166 Ident
: constant Node_Id
:= Identifier
(N
);
9167 Rectype
: Entity_Id
;
9172 Hbit
: Uint
:= Uint_0
;
9176 Max_Bit_So_Far
: Uint
;
9177 -- Records the maximum bit position so far. If all field positions
9178 -- are monotonically increasing, then we can skip the circuit for
9179 -- checking for overlap, since no overlap is possible.
9181 Tagged_Parent
: Entity_Id
:= Empty
;
9182 -- This is set in the case of a derived tagged type for which we have
9183 -- Is_Fully_Repped_Tagged_Type True (indicating that all components are
9184 -- positioned by record representation clauses). In this case we must
9185 -- check for overlap between components of this tagged type, and the
9186 -- components of its parent. Tagged_Parent will point to this parent
9187 -- type. For all other cases Tagged_Parent is left set to Empty.
9189 Parent_Last_Bit
: Uint
;
9190 -- Relevant only if Tagged_Parent is set, Parent_Last_Bit indicates the
9191 -- last bit position for any field in the parent type. We only need to
9192 -- check overlap for fields starting below this point.
9194 Overlap_Check_Required
: Boolean;
9195 -- Used to keep track of whether or not an overlap check is required
9197 Overlap_Detected
: Boolean := False;
9198 -- Set True if an overlap is detected
9200 Ccount
: Natural := 0;
9201 -- Number of component clauses in record rep clause
9203 procedure Check_Component_Overlap
(C1_Ent
, C2_Ent
: Entity_Id
);
9204 -- Given two entities for record components or discriminants, checks
9205 -- if they have overlapping component clauses and issues errors if so.
9207 procedure Find_Component
;
9208 -- Finds component entity corresponding to current component clause (in
9209 -- CC), and sets Comp to the entity, and Fbit/Lbit to the zero origin
9210 -- start/stop bits for the field. If there is no matching component or
9211 -- if the matching component does not have a component clause, then
9212 -- that's an error and Comp is set to Empty, but no error message is
9213 -- issued, since the message was already given. Comp is also set to
9214 -- Empty if the current "component clause" is in fact a pragma.
9216 -----------------------------
9217 -- Check_Component_Overlap --
9218 -----------------------------
9220 procedure Check_Component_Overlap
(C1_Ent
, C2_Ent
: Entity_Id
) is
9221 CC1
: constant Node_Id
:= Component_Clause
(C1_Ent
);
9222 CC2
: constant Node_Id
:= Component_Clause
(C2_Ent
);
9225 if Present
(CC1
) and then Present
(CC2
) then
9227 -- Exclude odd case where we have two tag components in the same
9228 -- record, both at location zero. This seems a bit strange, but
9229 -- it seems to happen in some circumstances, perhaps on an error.
9231 if Nam_In
(Chars
(C1_Ent
), Name_uTag
, Name_uTag
) then
9235 -- Here we check if the two fields overlap
9238 S1
: constant Uint
:= Component_Bit_Offset
(C1_Ent
);
9239 S2
: constant Uint
:= Component_Bit_Offset
(C2_Ent
);
9240 E1
: constant Uint
:= S1
+ Esize
(C1_Ent
);
9241 E2
: constant Uint
:= S2
+ Esize
(C2_Ent
);
9244 if E2
<= S1
or else E1
<= S2
then
9247 Error_Msg_Node_2
:= Component_Name
(CC2
);
9248 Error_Msg_Sloc
:= Sloc
(Error_Msg_Node_2
);
9249 Error_Msg_Node_1
:= Component_Name
(CC1
);
9251 ("component& overlaps & #", Component_Name
(CC1
));
9252 Overlap_Detected
:= True;
9256 end Check_Component_Overlap
;
9258 --------------------
9259 -- Find_Component --
9260 --------------------
9262 procedure Find_Component
is
9264 procedure Search_Component
(R
: Entity_Id
);
9265 -- Search components of R for a match. If found, Comp is set
9267 ----------------------
9268 -- Search_Component --
9269 ----------------------
9271 procedure Search_Component
(R
: Entity_Id
) is
9273 Comp
:= First_Component_Or_Discriminant
(R
);
9274 while Present
(Comp
) loop
9276 -- Ignore error of attribute name for component name (we
9277 -- already gave an error message for this, so no need to
9280 if Nkind
(Component_Name
(CC
)) = N_Attribute_Reference
then
9283 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
9286 Next_Component_Or_Discriminant
(Comp
);
9288 end Search_Component
;
9290 -- Start of processing for Find_Component
9293 -- Return with Comp set to Empty if we have a pragma
9295 if Nkind
(CC
) = N_Pragma
then
9300 -- Search current record for matching component
9302 Search_Component
(Rectype
);
9304 -- If not found, maybe component of base type discriminant that is
9305 -- absent from statically constrained first subtype.
9308 Search_Component
(Base_Type
(Rectype
));
9311 -- If no component, or the component does not reference the component
9312 -- clause in question, then there was some previous error for which
9313 -- we already gave a message, so just return with Comp Empty.
9315 if No
(Comp
) or else Component_Clause
(Comp
) /= CC
then
9316 Check_Error_Detected
;
9319 -- Normal case where we have a component clause
9322 Fbit
:= Component_Bit_Offset
(Comp
);
9323 Lbit
:= Fbit
+ Esize
(Comp
) - 1;
9327 -- Start of processing for Check_Record_Representation_Clause
9331 Rectype
:= Entity
(Ident
);
9333 if Rectype
= Any_Type
then
9336 Rectype
:= Underlying_Type
(Rectype
);
9339 -- See if we have a fully repped derived tagged type
9342 PS
: constant Entity_Id
:= Parent_Subtype
(Rectype
);
9345 if Present
(PS
) and then Is_Fully_Repped_Tagged_Type
(PS
) then
9346 Tagged_Parent
:= PS
;
9348 -- Find maximum bit of any component of the parent type
9350 Parent_Last_Bit
:= UI_From_Int
(System_Address_Size
- 1);
9351 Pcomp
:= First_Entity
(Tagged_Parent
);
9352 while Present
(Pcomp
) loop
9353 if Ekind_In
(Pcomp
, E_Discriminant
, E_Component
) then
9354 if Component_Bit_Offset
(Pcomp
) /= No_Uint
9355 and then Known_Static_Esize
(Pcomp
)
9360 Component_Bit_Offset
(Pcomp
) + Esize
(Pcomp
) - 1);
9363 Next_Entity
(Pcomp
);
9369 -- All done if no component clauses
9371 CC
:= First
(Component_Clauses
(N
));
9377 -- If a tag is present, then create a component clause that places it
9378 -- at the start of the record (otherwise gigi may place it after other
9379 -- fields that have rep clauses).
9381 Fent
:= First_Entity
(Rectype
);
9383 if Nkind
(Fent
) = N_Defining_Identifier
9384 and then Chars
(Fent
) = Name_uTag
9386 Set_Component_Bit_Offset
(Fent
, Uint_0
);
9387 Set_Normalized_Position
(Fent
, Uint_0
);
9388 Set_Normalized_First_Bit
(Fent
, Uint_0
);
9389 Set_Normalized_Position_Max
(Fent
, Uint_0
);
9390 Init_Esize
(Fent
, System_Address_Size
);
9392 Set_Component_Clause
(Fent
,
9393 Make_Component_Clause
(Loc
,
9394 Component_Name
=> Make_Identifier
(Loc
, Name_uTag
),
9396 Position
=> Make_Integer_Literal
(Loc
, Uint_0
),
9397 First_Bit
=> Make_Integer_Literal
(Loc
, Uint_0
),
9399 Make_Integer_Literal
(Loc
,
9400 UI_From_Int
(System_Address_Size
))));
9402 Ccount
:= Ccount
+ 1;
9405 Max_Bit_So_Far
:= Uint_Minus_1
;
9406 Overlap_Check_Required
:= False;
9408 -- Process the component clauses
9410 while Present
(CC
) loop
9413 if Present
(Comp
) then
9414 Ccount
:= Ccount
+ 1;
9416 -- We need a full overlap check if record positions non-monotonic
9418 if Fbit
<= Max_Bit_So_Far
then
9419 Overlap_Check_Required
:= True;
9422 Max_Bit_So_Far
:= Lbit
;
9424 -- Check bit position out of range of specified size
9426 if Has_Size_Clause
(Rectype
)
9427 and then RM_Size
(Rectype
) <= Lbit
9430 ("bit number out of range of specified size",
9433 -- Check for overlap with tag component
9436 if Is_Tagged_Type
(Rectype
)
9437 and then Fbit
< System_Address_Size
9440 ("component overlaps tag field of&",
9441 Component_Name
(CC
), Rectype
);
9442 Overlap_Detected
:= True;
9450 -- Check parent overlap if component might overlap parent field
9452 if Present
(Tagged_Parent
) and then Fbit
<= Parent_Last_Bit
then
9453 Pcomp
:= First_Component_Or_Discriminant
(Tagged_Parent
);
9454 while Present
(Pcomp
) loop
9455 if not Is_Tag
(Pcomp
)
9456 and then Chars
(Pcomp
) /= Name_uParent
9458 Check_Component_Overlap
(Comp
, Pcomp
);
9461 Next_Component_Or_Discriminant
(Pcomp
);
9469 -- Now that we have processed all the component clauses, check for
9470 -- overlap. We have to leave this till last, since the components can
9471 -- appear in any arbitrary order in the representation clause.
9473 -- We do not need this check if all specified ranges were monotonic,
9474 -- as recorded by Overlap_Check_Required being False at this stage.
9476 -- This first section checks if there are any overlapping entries at
9477 -- all. It does this by sorting all entries and then seeing if there are
9478 -- any overlaps. If there are none, then that is decisive, but if there
9479 -- are overlaps, they may still be OK (they may result from fields in
9480 -- different variants).
9482 if Overlap_Check_Required
then
9483 Overlap_Check1
: declare
9485 OC_Fbit
: array (0 .. Ccount
) of Uint
;
9486 -- First-bit values for component clauses, the value is the offset
9487 -- of the first bit of the field from start of record. The zero
9488 -- entry is for use in sorting.
9490 OC_Lbit
: array (0 .. Ccount
) of Uint
;
9491 -- Last-bit values for component clauses, the value is the offset
9492 -- of the last bit of the field from start of record. The zero
9493 -- entry is for use in sorting.
9495 OC_Count
: Natural := 0;
9496 -- Count of entries in OC_Fbit and OC_Lbit
9498 function OC_Lt
(Op1
, Op2
: Natural) return Boolean;
9499 -- Compare routine for Sort
9501 procedure OC_Move
(From
: Natural; To
: Natural);
9502 -- Move routine for Sort
9504 package Sorting
is new GNAT
.Heap_Sort_G
(OC_Move
, OC_Lt
);
9510 function OC_Lt
(Op1
, Op2
: Natural) return Boolean is
9512 return OC_Fbit
(Op1
) < OC_Fbit
(Op2
);
9519 procedure OC_Move
(From
: Natural; To
: Natural) is
9521 OC_Fbit
(To
) := OC_Fbit
(From
);
9522 OC_Lbit
(To
) := OC_Lbit
(From
);
9525 -- Start of processing for Overlap_Check
9528 CC
:= First
(Component_Clauses
(N
));
9529 while Present
(CC
) loop
9531 -- Exclude component clause already marked in error
9533 if not Error_Posted
(CC
) then
9536 if Present
(Comp
) then
9537 OC_Count
:= OC_Count
+ 1;
9538 OC_Fbit
(OC_Count
) := Fbit
;
9539 OC_Lbit
(OC_Count
) := Lbit
;
9546 Sorting
.Sort
(OC_Count
);
9548 Overlap_Check_Required
:= False;
9549 for J
in 1 .. OC_Count
- 1 loop
9550 if OC_Lbit
(J
) >= OC_Fbit
(J
+ 1) then
9551 Overlap_Check_Required
:= True;
9558 -- If Overlap_Check_Required is still True, then we have to do the full
9559 -- scale overlap check, since we have at least two fields that do
9560 -- overlap, and we need to know if that is OK since they are in
9561 -- different variant, or whether we have a definite problem.
9563 if Overlap_Check_Required
then
9564 Overlap_Check2
: declare
9565 C1_Ent
, C2_Ent
: Entity_Id
;
9566 -- Entities of components being checked for overlap
9569 -- Component_List node whose Component_Items are being checked
9572 -- Component declaration for component being checked
9575 C1_Ent
:= First_Entity
(Base_Type
(Rectype
));
9577 -- Loop through all components in record. For each component check
9578 -- for overlap with any of the preceding elements on the component
9579 -- list containing the component and also, if the component is in
9580 -- a variant, check against components outside the case structure.
9581 -- This latter test is repeated recursively up the variant tree.
9583 Main_Component_Loop
: while Present
(C1_Ent
) loop
9584 if not Ekind_In
(C1_Ent
, E_Component
, E_Discriminant
) then
9585 goto Continue_Main_Component_Loop
;
9588 -- Skip overlap check if entity has no declaration node. This
9589 -- happens with discriminants in constrained derived types.
9590 -- Possibly we are missing some checks as a result, but that
9591 -- does not seem terribly serious.
9593 if No
(Declaration_Node
(C1_Ent
)) then
9594 goto Continue_Main_Component_Loop
;
9597 Clist
:= Parent
(List_Containing
(Declaration_Node
(C1_Ent
)));
9599 -- Loop through component lists that need checking. Check the
9600 -- current component list and all lists in variants above us.
9602 Component_List_Loop
: loop
9604 -- If derived type definition, go to full declaration
9605 -- If at outer level, check discriminants if there are any.
9607 if Nkind
(Clist
) = N_Derived_Type_Definition
then
9608 Clist
:= Parent
(Clist
);
9611 -- Outer level of record definition, check discriminants
9613 if Nkind_In
(Clist
, N_Full_Type_Declaration
,
9614 N_Private_Type_Declaration
)
9616 if Has_Discriminants
(Defining_Identifier
(Clist
)) then
9618 First_Discriminant
(Defining_Identifier
(Clist
));
9619 while Present
(C2_Ent
) loop
9620 exit when C1_Ent
= C2_Ent
;
9621 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
9622 Next_Discriminant
(C2_Ent
);
9626 -- Record extension case
9628 elsif Nkind
(Clist
) = N_Derived_Type_Definition
then
9631 -- Otherwise check one component list
9634 Citem
:= First
(Component_Items
(Clist
));
9635 while Present
(Citem
) loop
9636 if Nkind
(Citem
) = N_Component_Declaration
then
9637 C2_Ent
:= Defining_Identifier
(Citem
);
9638 exit when C1_Ent
= C2_Ent
;
9639 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
9646 -- Check for variants above us (the parent of the Clist can
9647 -- be a variant, in which case its parent is a variant part,
9648 -- and the parent of the variant part is a component list
9649 -- whose components must all be checked against the current
9650 -- component for overlap).
9652 if Nkind
(Parent
(Clist
)) = N_Variant
then
9653 Clist
:= Parent
(Parent
(Parent
(Clist
)));
9655 -- Check for possible discriminant part in record, this
9656 -- is treated essentially as another level in the
9657 -- recursion. For this case the parent of the component
9658 -- list is the record definition, and its parent is the
9659 -- full type declaration containing the discriminant
9662 elsif Nkind
(Parent
(Clist
)) = N_Record_Definition
then
9663 Clist
:= Parent
(Parent
((Clist
)));
9665 -- If neither of these two cases, we are at the top of
9669 exit Component_List_Loop
;
9671 end loop Component_List_Loop
;
9673 <<Continue_Main_Component_Loop
>>
9674 Next_Entity
(C1_Ent
);
9676 end loop Main_Component_Loop
;
9680 -- The following circuit deals with warning on record holes (gaps). We
9681 -- skip this check if overlap was detected, since it makes sense for the
9682 -- programmer to fix this illegality before worrying about warnings.
9684 if not Overlap_Detected
and Warn_On_Record_Holes
then
9685 Record_Hole_Check
: declare
9686 Decl
: constant Node_Id
:= Declaration_Node
(Base_Type
(Rectype
));
9687 -- Full declaration of record type
9689 procedure Check_Component_List
9693 -- Check component list CL for holes. The starting bit should be
9694 -- Sbit. which is zero for the main record component list and set
9695 -- appropriately for recursive calls for variants. DS is set to
9696 -- a list of discriminant specifications to be included in the
9697 -- consideration of components. It is No_List if none to consider.
9699 --------------------------
9700 -- Check_Component_List --
9701 --------------------------
9703 procedure Check_Component_List
9711 Compl
:= Integer (List_Length
(Component_Items
(CL
)));
9713 if DS
/= No_List
then
9714 Compl
:= Compl
+ Integer (List_Length
(DS
));
9718 Comps
: array (Natural range 0 .. Compl
) of Entity_Id
;
9719 -- Gather components (zero entry is for sort routine)
9721 Ncomps
: Natural := 0;
9722 -- Number of entries stored in Comps (starting at Comps (1))
9725 -- One component item or discriminant specification
9728 -- Starting bit for next component
9736 function Lt
(Op1
, Op2
: Natural) return Boolean;
9737 -- Compare routine for Sort
9739 procedure Move
(From
: Natural; To
: Natural);
9740 -- Move routine for Sort
9742 package Sorting
is new GNAT
.Heap_Sort_G
(Move
, Lt
);
9748 function Lt
(Op1
, Op2
: Natural) return Boolean is
9750 return Component_Bit_Offset
(Comps
(Op1
))
9752 Component_Bit_Offset
(Comps
(Op2
));
9759 procedure Move
(From
: Natural; To
: Natural) is
9761 Comps
(To
) := Comps
(From
);
9765 -- Gather discriminants into Comp
9767 if DS
/= No_List
then
9768 Citem
:= First
(DS
);
9769 while Present
(Citem
) loop
9770 if Nkind
(Citem
) = N_Discriminant_Specification
then
9772 Ent
: constant Entity_Id
:=
9773 Defining_Identifier
(Citem
);
9775 if Ekind
(Ent
) = E_Discriminant
then
9776 Ncomps
:= Ncomps
+ 1;
9777 Comps
(Ncomps
) := Ent
;
9786 -- Gather component entities into Comp
9788 Citem
:= First
(Component_Items
(CL
));
9789 while Present
(Citem
) loop
9790 if Nkind
(Citem
) = N_Component_Declaration
then
9791 Ncomps
:= Ncomps
+ 1;
9792 Comps
(Ncomps
) := Defining_Identifier
(Citem
);
9798 -- Now sort the component entities based on the first bit.
9799 -- Note we already know there are no overlapping components.
9801 Sorting
.Sort
(Ncomps
);
9803 -- Loop through entries checking for holes
9806 for J
in 1 .. Ncomps
loop
9808 Error_Msg_Uint_1
:= Component_Bit_Offset
(CEnt
) - Nbit
;
9810 if Error_Msg_Uint_1
> 0 then
9812 ("?H?^-bit gap before component&",
9813 Component_Name
(Component_Clause
(CEnt
)), CEnt
);
9816 Nbit
:= Component_Bit_Offset
(CEnt
) + Esize
(CEnt
);
9819 -- Process variant parts recursively if present
9821 if Present
(Variant_Part
(CL
)) then
9822 Variant
:= First
(Variants
(Variant_Part
(CL
)));
9823 while Present
(Variant
) loop
9824 Check_Component_List
9825 (Component_List
(Variant
), Nbit
, No_List
);
9830 end Check_Component_List
;
9832 -- Start of processing for Record_Hole_Check
9839 if Is_Tagged_Type
(Rectype
) then
9840 Sbit
:= UI_From_Int
(System_Address_Size
);
9845 if Nkind
(Decl
) = N_Full_Type_Declaration
9846 and then Nkind
(Type_Definition
(Decl
)) = N_Record_Definition
9848 Check_Component_List
9849 (Component_List
(Type_Definition
(Decl
)),
9851 Discriminant_Specifications
(Decl
));
9854 end Record_Hole_Check
;
9857 -- For records that have component clauses for all components, and whose
9858 -- size is less than or equal to 32, we need to know the size in the
9859 -- front end to activate possible packed array processing where the
9860 -- component type is a record.
9862 -- At this stage Hbit + 1 represents the first unused bit from all the
9863 -- component clauses processed, so if the component clauses are
9864 -- complete, then this is the length of the record.
9866 -- For records longer than System.Storage_Unit, and for those where not
9867 -- all components have component clauses, the back end determines the
9868 -- length (it may for example be appropriate to round up the size
9869 -- to some convenient boundary, based on alignment considerations, etc).
9871 if Unknown_RM_Size
(Rectype
) and then Hbit
+ 1 <= 32 then
9873 -- Nothing to do if at least one component has no component clause
9875 Comp
:= First_Component_Or_Discriminant
(Rectype
);
9876 while Present
(Comp
) loop
9877 exit when No
(Component_Clause
(Comp
));
9878 Next_Component_Or_Discriminant
(Comp
);
9881 -- If we fall out of loop, all components have component clauses
9882 -- and so we can set the size to the maximum value.
9885 Set_RM_Size
(Rectype
, Hbit
+ 1);
9888 end Check_Record_Representation_Clause
;
9894 procedure Check_Size
9898 Biased
: out Boolean)
9900 UT
: constant Entity_Id
:= Underlying_Type
(T
);
9906 -- Reject patently improper size values.
9908 if Is_Elementary_Type
(T
)
9909 and then Siz
> UI_From_Int
(Int
'Last)
9911 Error_Msg_N
("Size value too large for elementary type", N
);
9913 if Nkind
(Original_Node
(N
)) = N_Op_Expon
then
9915 ("\maybe '* was meant, rather than '*'*", Original_Node
(N
));
9919 -- Dismiss generic types
9921 if Is_Generic_Type
(T
)
9923 Is_Generic_Type
(UT
)
9925 Is_Generic_Type
(Root_Type
(UT
))
9929 -- Guard against previous errors
9931 elsif No
(UT
) or else UT
= Any_Type
then
9932 Check_Error_Detected
;
9935 -- Check case of bit packed array
9937 elsif Is_Array_Type
(UT
)
9938 and then Known_Static_Component_Size
(UT
)
9939 and then Is_Bit_Packed_Array
(UT
)
9947 Asiz
:= Component_Size
(UT
);
9948 Indx
:= First_Index
(UT
);
9950 Ityp
:= Etype
(Indx
);
9952 -- If non-static bound, then we are not in the business of
9953 -- trying to check the length, and indeed an error will be
9954 -- issued elsewhere, since sizes of non-static array types
9955 -- cannot be set implicitly or explicitly.
9957 if not Is_OK_Static_Subtype
(Ityp
) then
9961 -- Otherwise accumulate next dimension
9963 Asiz
:= Asiz
* (Expr_Value
(Type_High_Bound
(Ityp
)) -
9964 Expr_Value
(Type_Low_Bound
(Ityp
)) +
9968 exit when No
(Indx
);
9975 Error_Msg_Uint_1
:= Asiz
;
9977 ("size for& too small, minimum allowed is ^", N
, T
);
9978 Set_Esize
(T
, Asiz
);
9979 Set_RM_Size
(T
, Asiz
);
9983 -- All other composite types are ignored
9985 elsif Is_Composite_Type
(UT
) then
9988 -- For fixed-point types, don't check minimum if type is not frozen,
9989 -- since we don't know all the characteristics of the type that can
9990 -- affect the size (e.g. a specified small) till freeze time.
9992 elsif Is_Fixed_Point_Type
(UT
)
9993 and then not Is_Frozen
(UT
)
9997 -- Cases for which a minimum check is required
10000 -- Ignore if specified size is correct for the type
10002 if Known_Esize
(UT
) and then Siz
= Esize
(UT
) then
10006 -- Otherwise get minimum size
10008 M
:= UI_From_Int
(Minimum_Size
(UT
));
10012 -- Size is less than minimum size, but one possibility remains
10013 -- that we can manage with the new size if we bias the type.
10015 M
:= UI_From_Int
(Minimum_Size
(UT
, Biased
=> True));
10018 Error_Msg_Uint_1
:= M
;
10020 ("size for& too small, minimum allowed is ^", N
, T
);
10022 Set_RM_Size
(T
, M
);
10030 --------------------------
10031 -- Freeze_Entity_Checks --
10032 --------------------------
10034 procedure Freeze_Entity_Checks
(N
: Node_Id
) is
10035 procedure Hide_Non_Overridden_Subprograms
(Typ
: Entity_Id
);
10036 -- Inspect the primitive operations of type Typ and hide all pairs of
10037 -- implicitly declared non-overridden non-fully conformant homographs
10038 -- (Ada RM 8.3 12.3/2).
10040 -------------------------------------
10041 -- Hide_Non_Overridden_Subprograms --
10042 -------------------------------------
10044 procedure Hide_Non_Overridden_Subprograms
(Typ
: Entity_Id
) is
10045 procedure Hide_Matching_Homographs
10046 (Subp_Id
: Entity_Id
;
10047 Start_Elmt
: Elmt_Id
);
10048 -- Inspect a list of primitive operations starting with Start_Elmt
10049 -- and find matching implicitly declared non-overridden non-fully
10050 -- conformant homographs of Subp_Id. If found, all matches along
10051 -- with Subp_Id are hidden from all visibility.
10053 function Is_Non_Overridden_Or_Null_Procedure
10054 (Subp_Id
: Entity_Id
) return Boolean;
10055 -- Determine whether subprogram Subp_Id is implicitly declared non-
10056 -- overridden subprogram or an implicitly declared null procedure.
10058 ------------------------------
10059 -- Hide_Matching_Homographs --
10060 ------------------------------
10062 procedure Hide_Matching_Homographs
10063 (Subp_Id
: Entity_Id
;
10064 Start_Elmt
: Elmt_Id
)
10067 Prim_Elmt
: Elmt_Id
;
10070 Prim_Elmt
:= Start_Elmt
;
10071 while Present
(Prim_Elmt
) loop
10072 Prim
:= Node
(Prim_Elmt
);
10074 -- The current primitive is implicitly declared non-overridden
10075 -- non-fully conformant homograph of Subp_Id. Both subprograms
10076 -- must be hidden from visibility.
10078 if Chars
(Prim
) = Chars
(Subp_Id
)
10079 and then Is_Non_Overridden_Or_Null_Procedure
(Prim
)
10080 and then not Fully_Conformant
(Prim
, Subp_Id
)
10082 Set_Is_Hidden_Non_Overridden_Subpgm
(Prim
);
10083 Set_Is_Immediately_Visible
(Prim
, False);
10084 Set_Is_Potentially_Use_Visible
(Prim
, False);
10086 Set_Is_Hidden_Non_Overridden_Subpgm
(Subp_Id
);
10087 Set_Is_Immediately_Visible
(Subp_Id
, False);
10088 Set_Is_Potentially_Use_Visible
(Subp_Id
, False);
10091 Next_Elmt
(Prim_Elmt
);
10093 end Hide_Matching_Homographs
;
10095 -----------------------------------------
10096 -- Is_Non_Overridden_Or_Null_Procedure --
10097 -----------------------------------------
10099 function Is_Non_Overridden_Or_Null_Procedure
10100 (Subp_Id
: Entity_Id
) return Boolean
10102 Alias_Id
: Entity_Id
;
10105 -- The subprogram is inherited (implicitly declared), it does not
10106 -- override and does not cover a primitive of an interface.
10108 if Ekind_In
(Subp_Id
, E_Function
, E_Procedure
)
10109 and then Present
(Alias
(Subp_Id
))
10110 and then No
(Interface_Alias
(Subp_Id
))
10111 and then No
(Overridden_Operation
(Subp_Id
))
10113 Alias_Id
:= Alias
(Subp_Id
);
10115 if Requires_Overriding
(Alias_Id
) then
10118 elsif Nkind
(Parent
(Alias_Id
)) = N_Procedure_Specification
10119 and then Null_Present
(Parent
(Alias_Id
))
10126 end Is_Non_Overridden_Or_Null_Procedure
;
10130 Prim_Ops
: constant Elist_Id
:= Direct_Primitive_Operations
(Typ
);
10132 Prim_Elmt
: Elmt_Id
;
10134 -- Start of processing for Hide_Non_Overridden_Subprograms
10137 -- Inspect the list of primitives looking for non-overridden
10140 if Present
(Prim_Ops
) then
10141 Prim_Elmt
:= First_Elmt
(Prim_Ops
);
10142 while Present
(Prim_Elmt
) loop
10143 Prim
:= Node
(Prim_Elmt
);
10144 Next_Elmt
(Prim_Elmt
);
10146 if Is_Non_Overridden_Or_Null_Procedure
(Prim
) then
10147 Hide_Matching_Homographs
10149 Start_Elmt
=> Prim_Elmt
);
10153 end Hide_Non_Overridden_Subprograms
;
10155 ---------------------
10156 -- Local variables --
10157 ---------------------
10159 E
: constant Entity_Id
:= Entity
(N
);
10161 Non_Generic_Case
: constant Boolean := Nkind
(N
) = N_Freeze_Entity
;
10162 -- True in non-generic case. Some of the processing here is skipped
10163 -- for the generic case since it is not needed. Basically in the
10164 -- generic case, we only need to do stuff that might generate error
10165 -- messages or warnings.
10167 -- Start of processing for Freeze_Entity_Checks
10170 -- Remember that we are processing a freezing entity. Required to
10171 -- ensure correct decoration of internal entities associated with
10172 -- interfaces (see New_Overloaded_Entity).
10174 Inside_Freezing_Actions
:= Inside_Freezing_Actions
+ 1;
10176 -- For tagged types covering interfaces add internal entities that link
10177 -- the primitives of the interfaces with the primitives that cover them.
10178 -- Note: These entities were originally generated only when generating
10179 -- code because their main purpose was to provide support to initialize
10180 -- the secondary dispatch tables. They are now generated also when
10181 -- compiling with no code generation to provide ASIS the relationship
10182 -- between interface primitives and tagged type primitives. They are
10183 -- also used to locate primitives covering interfaces when processing
10184 -- generics (see Derive_Subprograms).
10186 -- This is not needed in the generic case
10188 if Ada_Version
>= Ada_2005
10189 and then Non_Generic_Case
10190 and then Ekind
(E
) = E_Record_Type
10191 and then Is_Tagged_Type
(E
)
10192 and then not Is_Interface
(E
)
10193 and then Has_Interfaces
(E
)
10195 -- This would be a good common place to call the routine that checks
10196 -- overriding of interface primitives (and thus factorize calls to
10197 -- Check_Abstract_Overriding located at different contexts in the
10198 -- compiler). However, this is not possible because it causes
10199 -- spurious errors in case of late overriding.
10201 Add_Internal_Interface_Entities
(E
);
10204 -- After all forms of overriding have been resolved, a tagged type may
10205 -- be left with a set of implicitly declared and possibly erroneous
10206 -- abstract subprograms, null procedures and subprograms that require
10207 -- overriding. If this set contains fully conformat homographs, then one
10208 -- is chosen arbitrarily (already done during resolution), otherwise all
10209 -- remaining non-fully conformant homographs are hidden from visibility
10210 -- (Ada RM 8.3 12.3/2).
10212 if Is_Tagged_Type
(E
) then
10213 Hide_Non_Overridden_Subprograms
(E
);
10218 if Ekind
(E
) = E_Record_Type
10219 and then Is_CPP_Class
(E
)
10220 and then Is_Tagged_Type
(E
)
10221 and then Tagged_Type_Expansion
10223 if CPP_Num_Prims
(E
) = 0 then
10225 -- If the CPP type has user defined components then it must import
10226 -- primitives from C++. This is required because if the C++ class
10227 -- has no primitives then the C++ compiler does not added the _tag
10228 -- component to the type.
10230 if First_Entity
(E
) /= Last_Entity
(E
) then
10232 ("'C'P'P type must import at least one primitive from C++??",
10237 -- Check that all its primitives are abstract or imported from C++.
10238 -- Check also availability of the C++ constructor.
10241 Has_Constructors
: constant Boolean := Has_CPP_Constructors
(E
);
10243 Error_Reported
: Boolean := False;
10247 Elmt
:= First_Elmt
(Primitive_Operations
(E
));
10248 while Present
(Elmt
) loop
10249 Prim
:= Node
(Elmt
);
10251 if Comes_From_Source
(Prim
) then
10252 if Is_Abstract_Subprogram
(Prim
) then
10255 elsif not Is_Imported
(Prim
)
10256 or else Convention
(Prim
) /= Convention_CPP
10259 ("primitives of 'C'P'P types must be imported from C++ "
10260 & "or abstract??", Prim
);
10262 elsif not Has_Constructors
10263 and then not Error_Reported
10265 Error_Msg_Name_1
:= Chars
(E
);
10267 ("??'C'P'P constructor required for type %", Prim
);
10268 Error_Reported
:= True;
10277 -- Check Ada derivation of CPP type
10279 if Expander_Active
-- why? losing errors in -gnatc mode???
10280 and then Tagged_Type_Expansion
10281 and then Ekind
(E
) = E_Record_Type
10282 and then Etype
(E
) /= E
10283 and then Is_CPP_Class
(Etype
(E
))
10284 and then CPP_Num_Prims
(Etype
(E
)) > 0
10285 and then not Is_CPP_Class
(E
)
10286 and then not Has_CPP_Constructors
(Etype
(E
))
10288 -- If the parent has C++ primitives but it has no constructor then
10289 -- check that all the primitives are overridden in this derivation;
10290 -- otherwise the constructor of the parent is needed to build the
10298 Elmt
:= First_Elmt
(Primitive_Operations
(E
));
10299 while Present
(Elmt
) loop
10300 Prim
:= Node
(Elmt
);
10302 if not Is_Abstract_Subprogram
(Prim
)
10303 and then No
(Interface_Alias
(Prim
))
10304 and then Find_Dispatching_Type
(Ultimate_Alias
(Prim
)) /= E
10306 Error_Msg_Name_1
:= Chars
(Etype
(E
));
10308 ("'C'P'P constructor required for parent type %", E
);
10317 Inside_Freezing_Actions
:= Inside_Freezing_Actions
- 1;
10319 -- If we have a type with predicates, build predicate function. This
10320 -- is not needed in the generic case, and is not needed within TSS
10321 -- subprograms and other predefined primitives.
10323 if Non_Generic_Case
10324 and then Is_Type
(E
)
10325 and then Has_Predicates
(E
)
10326 and then not Within_Internal_Subprogram
10328 Build_Predicate_Functions
(E
, N
);
10331 -- If type has delayed aspects, this is where we do the preanalysis at
10332 -- the freeze point, as part of the consistent visibility check. Note
10333 -- that this must be done after calling Build_Predicate_Functions or
10334 -- Build_Invariant_Procedure since these subprograms fix occurrences of
10335 -- the subtype name in the saved expression so that they will not cause
10336 -- trouble in the preanalysis.
10338 -- This is also not needed in the generic case
10340 if Non_Generic_Case
10341 and then Has_Delayed_Aspects
(E
)
10342 and then Scope
(E
) = Current_Scope
10344 -- Retrieve the visibility to the discriminants in order to properly
10345 -- analyze the aspects.
10347 Push_Scope_And_Install_Discriminants
(E
);
10353 -- Look for aspect specification entries for this entity
10355 Ritem
:= First_Rep_Item
(E
);
10356 while Present
(Ritem
) loop
10357 if Nkind
(Ritem
) = N_Aspect_Specification
10358 and then Entity
(Ritem
) = E
10359 and then Is_Delayed_Aspect
(Ritem
)
10361 Check_Aspect_At_Freeze_Point
(Ritem
);
10364 Next_Rep_Item
(Ritem
);
10368 Uninstall_Discriminants_And_Pop_Scope
(E
);
10371 -- For a record type, deal with variant parts. This has to be delayed
10372 -- to this point, because of the issue of statically predicated
10373 -- subtypes, which we have to ensure are frozen before checking
10374 -- choices, since we need to have the static choice list set.
10376 if Is_Record_Type
(E
) then
10377 Check_Variant_Part
: declare
10378 D
: constant Node_Id
:= Declaration_Node
(E
);
10383 Others_Present
: Boolean;
10384 pragma Warnings
(Off
, Others_Present
);
10385 -- Indicates others present, not used in this case
10387 procedure Non_Static_Choice_Error
(Choice
: Node_Id
);
10388 -- Error routine invoked by the generic instantiation below when
10389 -- the variant part has a non static choice.
10391 procedure Process_Declarations
(Variant
: Node_Id
);
10392 -- Processes declarations associated with a variant. We analyzed
10393 -- the declarations earlier (in Sem_Ch3.Analyze_Variant_Part),
10394 -- but we still need the recursive call to Check_Choices for any
10395 -- nested variant to get its choices properly processed. This is
10396 -- also where we expand out the choices if expansion is active.
10398 package Variant_Choices_Processing
is new
10399 Generic_Check_Choices
10400 (Process_Empty_Choice
=> No_OP
,
10401 Process_Non_Static_Choice
=> Non_Static_Choice_Error
,
10402 Process_Associated_Node
=> Process_Declarations
);
10403 use Variant_Choices_Processing
;
10405 -----------------------------
10406 -- Non_Static_Choice_Error --
10407 -----------------------------
10409 procedure Non_Static_Choice_Error
(Choice
: Node_Id
) is
10411 Flag_Non_Static_Expr
10412 ("choice given in variant part is not static!", Choice
);
10413 end Non_Static_Choice_Error
;
10415 --------------------------
10416 -- Process_Declarations --
10417 --------------------------
10419 procedure Process_Declarations
(Variant
: Node_Id
) is
10420 CL
: constant Node_Id
:= Component_List
(Variant
);
10424 -- Check for static predicate present in this variant
10426 if Has_SP_Choice
(Variant
) then
10428 -- Here we expand. You might expect to find this call in
10429 -- Expand_N_Variant_Part, but that is called when we first
10430 -- see the variant part, and we cannot do this expansion
10431 -- earlier than the freeze point, since for statically
10432 -- predicated subtypes, the predicate is not known till
10433 -- the freeze point.
10435 -- Furthermore, we do this expansion even if the expander
10436 -- is not active, because other semantic processing, e.g.
10437 -- for aggregates, requires the expanded list of choices.
10439 -- If the expander is not active, then we can't just clobber
10440 -- the list since it would invalidate the ASIS -gnatct tree.
10441 -- So we have to rewrite the variant part with a Rewrite
10442 -- call that replaces it with a copy and clobber the copy.
10444 if not Expander_Active
then
10446 NewV
: constant Node_Id
:= New_Copy
(Variant
);
10448 Set_Discrete_Choices
10449 (NewV
, New_Copy_List
(Discrete_Choices
(Variant
)));
10450 Rewrite
(Variant
, NewV
);
10454 Expand_Static_Predicates_In_Choices
(Variant
);
10457 -- We don't need to worry about the declarations in the variant
10458 -- (since they were analyzed by Analyze_Choices when we first
10459 -- encountered the variant), but we do need to take care of
10460 -- expansion of any nested variants.
10462 if not Null_Present
(CL
) then
10463 VP
:= Variant_Part
(CL
);
10465 if Present
(VP
) then
10467 (VP
, Variants
(VP
), Etype
(Name
(VP
)), Others_Present
);
10470 end Process_Declarations
;
10472 -- Start of processing for Check_Variant_Part
10475 -- Find component list
10479 if Nkind
(D
) = N_Full_Type_Declaration
then
10480 T
:= Type_Definition
(D
);
10482 if Nkind
(T
) = N_Record_Definition
then
10483 C
:= Component_List
(T
);
10485 elsif Nkind
(T
) = N_Derived_Type_Definition
10486 and then Present
(Record_Extension_Part
(T
))
10488 C
:= Component_List
(Record_Extension_Part
(T
));
10492 -- Case of variant part present
10494 if Present
(C
) and then Present
(Variant_Part
(C
)) then
10495 VP
:= Variant_Part
(C
);
10500 (VP
, Variants
(VP
), Etype
(Name
(VP
)), Others_Present
);
10502 -- If the last variant does not contain the Others choice,
10503 -- replace it with an N_Others_Choice node since Gigi always
10504 -- wants an Others. Note that we do not bother to call Analyze
10505 -- on the modified variant part, since its only effect would be
10506 -- to compute the Others_Discrete_Choices node laboriously, and
10507 -- of course we already know the list of choices corresponding
10508 -- to the others choice (it's the list we're replacing).
10510 -- We only want to do this if the expander is active, since
10511 -- we do not want to clobber the ASIS tree.
10513 if Expander_Active
then
10515 Last_Var
: constant Node_Id
:=
10516 Last_Non_Pragma
(Variants
(VP
));
10518 Others_Node
: Node_Id
;
10521 if Nkind
(First
(Discrete_Choices
(Last_Var
))) /=
10524 Others_Node
:= Make_Others_Choice
(Sloc
(Last_Var
));
10525 Set_Others_Discrete_Choices
10526 (Others_Node
, Discrete_Choices
(Last_Var
));
10527 Set_Discrete_Choices
10528 (Last_Var
, New_List
(Others_Node
));
10533 end Check_Variant_Part
;
10535 end Freeze_Entity_Checks
;
10537 -------------------------
10538 -- Get_Alignment_Value --
10539 -------------------------
10541 function Get_Alignment_Value
(Expr
: Node_Id
) return Uint
is
10542 Align
: constant Uint
:= Static_Integer
(Expr
);
10545 if Align
= No_Uint
then
10548 elsif Align
<= 0 then
10549 Error_Msg_N
("alignment value must be positive", Expr
);
10553 for J
in Int
range 0 .. 64 loop
10555 M
: constant Uint
:= Uint_2
** J
;
10558 exit when M
= Align
;
10562 ("alignment value must be power of 2", Expr
);
10570 end Get_Alignment_Value
;
10572 -------------------------------------
10573 -- Inherit_Aspects_At_Freeze_Point --
10574 -------------------------------------
10576 procedure Inherit_Aspects_At_Freeze_Point
(Typ
: Entity_Id
) is
10577 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
10578 (Rep_Item
: Node_Id
) return Boolean;
10579 -- This routine checks if Rep_Item is either a pragma or an aspect
10580 -- specification node whose correponding pragma (if any) is present in
10581 -- the Rep Item chain of the entity it has been specified to.
10583 --------------------------------------------------
10584 -- Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item --
10585 --------------------------------------------------
10587 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
10588 (Rep_Item
: Node_Id
) return Boolean
10592 Nkind
(Rep_Item
) = N_Pragma
10593 or else Present_In_Rep_Item
10594 (Entity
(Rep_Item
), Aspect_Rep_Item
(Rep_Item
));
10595 end Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
;
10597 -- Start of processing for Inherit_Aspects_At_Freeze_Point
10600 -- A representation item is either subtype-specific (Size and Alignment
10601 -- clauses) or type-related (all others). Subtype-specific aspects may
10602 -- differ for different subtypes of the same type (RM 13.1.8).
10604 -- A derived type inherits each type-related representation aspect of
10605 -- its parent type that was directly specified before the declaration of
10606 -- the derived type (RM 13.1.15).
10608 -- A derived subtype inherits each subtype-specific representation
10609 -- aspect of its parent subtype that was directly specified before the
10610 -- declaration of the derived type (RM 13.1.15).
10612 -- The general processing involves inheriting a representation aspect
10613 -- from a parent type whenever the first rep item (aspect specification,
10614 -- attribute definition clause, pragma) corresponding to the given
10615 -- representation aspect in the rep item chain of Typ, if any, isn't
10616 -- directly specified to Typ but to one of its parents.
10618 -- ??? Note that, for now, just a limited number of representation
10619 -- aspects have been inherited here so far. Many of them are
10620 -- still inherited in Sem_Ch3. This will be fixed soon. Here is
10621 -- a non- exhaustive list of aspects that likely also need to
10622 -- be moved to this routine: Alignment, Component_Alignment,
10623 -- Component_Size, Machine_Radix, Object_Size, Pack, Predicates,
10624 -- Preelaborable_Initialization, RM_Size and Small.
10626 if Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
then
10632 if not Has_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
, False)
10633 and then Has_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
)
10634 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
10635 (Get_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
))
10637 Set_Is_Ada_2005_Only
(Typ
);
10642 if not Has_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
, False)
10643 and then Has_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
)
10644 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
10645 (Get_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
))
10647 Set_Is_Ada_2012_Only
(Typ
);
10652 if not Has_Rep_Item
(Typ
, Name_Atomic
, Name_Shared
, False)
10653 and then Has_Rep_Pragma
(Typ
, Name_Atomic
, Name_Shared
)
10654 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
10655 (Get_Rep_Item
(Typ
, Name_Atomic
, Name_Shared
))
10657 Set_Is_Atomic
(Typ
);
10658 Set_Treat_As_Volatile
(Typ
);
10659 Set_Is_Volatile
(Typ
);
10662 -- Default_Component_Value
10664 if Is_Array_Type
(Typ
)
10665 and then Is_Base_Type
(Typ
)
10666 and then Has_Rep_Item
(Typ
, Name_Default_Component_Value
, False)
10667 and then Has_Rep_Item
(Typ
, Name_Default_Component_Value
)
10669 Set_Default_Aspect_Component_Value
(Typ
,
10670 Default_Aspect_Component_Value
10671 (Entity
(Get_Rep_Item
(Typ
, Name_Default_Component_Value
))));
10676 if Is_Scalar_Type
(Typ
)
10677 and then Is_Base_Type
(Typ
)
10678 and then Has_Rep_Item
(Typ
, Name_Default_Value
, False)
10679 and then Has_Rep_Item
(Typ
, Name_Default_Value
)
10681 Set_Default_Aspect_Value
(Typ
,
10682 Default_Aspect_Value
10683 (Entity
(Get_Rep_Item
(Typ
, Name_Default_Value
))));
10688 if not Has_Rep_Item
(Typ
, Name_Discard_Names
, False)
10689 and then Has_Rep_Item
(Typ
, Name_Discard_Names
)
10690 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
10691 (Get_Rep_Item
(Typ
, Name_Discard_Names
))
10693 Set_Discard_Names
(Typ
);
10698 if not Has_Rep_Item
(Typ
, Name_Invariant
, False)
10699 and then Has_Rep_Item
(Typ
, Name_Invariant
)
10700 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
10701 (Get_Rep_Item
(Typ
, Name_Invariant
))
10703 Set_Has_Invariants
(Typ
);
10705 if Class_Present
(Get_Rep_Item
(Typ
, Name_Invariant
)) then
10706 Set_Has_Inheritable_Invariants
(Typ
);
10712 if not Has_Rep_Item
(Typ
, Name_Volatile
, False)
10713 and then Has_Rep_Item
(Typ
, Name_Volatile
)
10714 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
10715 (Get_Rep_Item
(Typ
, Name_Volatile
))
10717 Set_Treat_As_Volatile
(Typ
);
10718 Set_Is_Volatile
(Typ
);
10721 -- Inheritance for derived types only
10723 if Is_Derived_Type
(Typ
) then
10725 Bas_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
10726 Imp_Bas_Typ
: constant Entity_Id
:= Implementation_Base_Type
(Typ
);
10729 -- Atomic_Components
10731 if not Has_Rep_Item
(Typ
, Name_Atomic_Components
, False)
10732 and then Has_Rep_Item
(Typ
, Name_Atomic_Components
)
10733 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
10734 (Get_Rep_Item
(Typ
, Name_Atomic_Components
))
10736 Set_Has_Atomic_Components
(Imp_Bas_Typ
);
10739 -- Volatile_Components
10741 if not Has_Rep_Item
(Typ
, Name_Volatile_Components
, False)
10742 and then Has_Rep_Item
(Typ
, Name_Volatile_Components
)
10743 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
10744 (Get_Rep_Item
(Typ
, Name_Volatile_Components
))
10746 Set_Has_Volatile_Components
(Imp_Bas_Typ
);
10749 -- Finalize_Storage_Only.
10751 if not Has_Rep_Pragma
(Typ
, Name_Finalize_Storage_Only
, False)
10752 and then Has_Rep_Pragma
(Typ
, Name_Finalize_Storage_Only
)
10754 Set_Finalize_Storage_Only
(Bas_Typ
);
10757 -- Universal_Aliasing
10759 if not Has_Rep_Item
(Typ
, Name_Universal_Aliasing
, False)
10760 and then Has_Rep_Item
(Typ
, Name_Universal_Aliasing
)
10761 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
10762 (Get_Rep_Item
(Typ
, Name_Universal_Aliasing
))
10764 Set_Universal_Aliasing
(Imp_Bas_Typ
);
10767 -- Record type specific aspects
10769 if Is_Record_Type
(Typ
) then
10773 if not Has_Rep_Item
(Typ
, Name_Bit_Order
, False)
10774 and then Has_Rep_Item
(Typ
, Name_Bit_Order
)
10776 Set_Reverse_Bit_Order
(Bas_Typ
,
10777 Reverse_Bit_Order
(Entity
(Name
10778 (Get_Rep_Item
(Typ
, Name_Bit_Order
)))));
10781 -- Scalar_Storage_Order
10783 if not Has_Rep_Item
(Typ
, Name_Scalar_Storage_Order
, False)
10784 and then Has_Rep_Item
(Typ
, Name_Scalar_Storage_Order
)
10786 Set_Reverse_Storage_Order
(Bas_Typ
,
10787 Reverse_Storage_Order
(Entity
(Name
10788 (Get_Rep_Item
(Typ
, Name_Scalar_Storage_Order
)))));
10790 -- Clear default SSO indications, since the inherited aspect
10791 -- which was set explicitly overrides the default.
10793 Set_SSO_Set_Low_By_Default
(Bas_Typ
, False);
10794 Set_SSO_Set_High_By_Default
(Bas_Typ
, False);
10799 end Inherit_Aspects_At_Freeze_Point
;
10805 procedure Initialize
is
10807 Address_Clause_Checks
.Init
;
10808 Independence_Checks
.Init
;
10809 Unchecked_Conversions
.Init
;
10812 ---------------------------
10813 -- Install_Discriminants --
10814 ---------------------------
10816 procedure Install_Discriminants
(E
: Entity_Id
) is
10820 Disc
:= First_Discriminant
(E
);
10821 while Present
(Disc
) loop
10822 Prev
:= Current_Entity
(Disc
);
10823 Set_Current_Entity
(Disc
);
10824 Set_Is_Immediately_Visible
(Disc
);
10825 Set_Homonym
(Disc
, Prev
);
10826 Next_Discriminant
(Disc
);
10828 end Install_Discriminants
;
10830 -------------------------
10831 -- Is_Operational_Item --
10832 -------------------------
10834 function Is_Operational_Item
(N
: Node_Id
) return Boolean is
10836 if Nkind
(N
) /= N_Attribute_Definition_Clause
then
10841 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Chars
(N
));
10843 return Id
= Attribute_Input
10844 or else Id
= Attribute_Output
10845 or else Id
= Attribute_Read
10846 or else Id
= Attribute_Write
10847 or else Id
= Attribute_External_Tag
;
10850 end Is_Operational_Item
;
10852 -------------------------
10853 -- Is_Predicate_Static --
10854 -------------------------
10856 -- Note: the basic legality of the expression has already been checked, so
10857 -- we don't need to worry about cases or ranges on strings for example.
10859 function Is_Predicate_Static
10861 Nam
: Name_Id
) return Boolean
10863 function All_Static_Case_Alternatives
(L
: List_Id
) return Boolean;
10864 -- Given a list of case expression alternatives, returns True if all
10865 -- the alternatives are static (have all static choices, and a static
10868 function All_Static_Choices
(L
: List_Id
) return Boolean;
10869 -- Returns true if all elements of the list are OK static choices
10870 -- as defined below for Is_Static_Choice. Used for case expression
10871 -- alternatives and for the right operand of a membership test. An
10872 -- others_choice is static if the corresponding expression is static.
10873 -- The staticness of the bounds is checked separately.
10875 function Is_Static_Choice
(N
: Node_Id
) return Boolean;
10876 -- Returns True if N represents a static choice (static subtype, or
10877 -- static subtype indication, or static expression, or static range).
10879 -- Note that this is a bit more inclusive than we actually need
10880 -- (in particular membership tests do not allow the use of subtype
10881 -- indications). But that doesn't matter, we have already checked
10882 -- that the construct is legal to get this far.
10884 function Is_Type_Ref
(N
: Node_Id
) return Boolean;
10885 pragma Inline
(Is_Type_Ref
);
10886 -- Returns True if N is a reference to the type for the predicate in the
10887 -- expression (i.e. if it is an identifier whose Chars field matches the
10888 -- Nam given in the call). N must not be parenthesized, if the type name
10889 -- appears in parens, this routine will return False.
10891 ----------------------------------
10892 -- All_Static_Case_Alternatives --
10893 ----------------------------------
10895 function All_Static_Case_Alternatives
(L
: List_Id
) return Boolean is
10900 while Present
(N
) loop
10901 if not (All_Static_Choices
(Discrete_Choices
(N
))
10902 and then Is_OK_Static_Expression
(Expression
(N
)))
10911 end All_Static_Case_Alternatives
;
10913 ------------------------
10914 -- All_Static_Choices --
10915 ------------------------
10917 function All_Static_Choices
(L
: List_Id
) return Boolean is
10922 while Present
(N
) loop
10923 if not Is_Static_Choice
(N
) then
10931 end All_Static_Choices
;
10933 ----------------------
10934 -- Is_Static_Choice --
10935 ----------------------
10937 function Is_Static_Choice
(N
: Node_Id
) return Boolean is
10939 return Nkind
(N
) = N_Others_Choice
10940 or else Is_OK_Static_Expression
(N
)
10941 or else (Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
))
10942 and then Is_OK_Static_Subtype
(Entity
(N
)))
10943 or else (Nkind
(N
) = N_Subtype_Indication
10944 and then Is_OK_Static_Subtype
(Entity
(N
)))
10945 or else (Nkind
(N
) = N_Range
and then Is_OK_Static_Range
(N
));
10946 end Is_Static_Choice
;
10952 function Is_Type_Ref
(N
: Node_Id
) return Boolean is
10954 return Nkind
(N
) = N_Identifier
10955 and then Chars
(N
) = Nam
10956 and then Paren_Count
(N
) = 0;
10959 -- Start of processing for Is_Predicate_Static
10962 -- Predicate_Static means one of the following holds. Numbers are the
10963 -- corresponding paragraph numbers in (RM 3.2.4(16-22)).
10965 -- 16: A static expression
10967 if Is_OK_Static_Expression
(Expr
) then
10970 -- 17: A membership test whose simple_expression is the current
10971 -- instance, and whose membership_choice_list meets the requirements
10972 -- for a static membership test.
10974 elsif Nkind
(Expr
) in N_Membership_Test
10975 and then ((Present
(Right_Opnd
(Expr
))
10976 and then Is_Static_Choice
(Right_Opnd
(Expr
)))
10978 (Present
(Alternatives
(Expr
))
10979 and then All_Static_Choices
(Alternatives
(Expr
))))
10983 -- 18. A case_expression whose selecting_expression is the current
10984 -- instance, and whose dependent expressions are static expressions.
10986 elsif Nkind
(Expr
) = N_Case_Expression
10987 and then Is_Type_Ref
(Expression
(Expr
))
10988 and then All_Static_Case_Alternatives
(Alternatives
(Expr
))
10992 -- 19. A call to a predefined equality or ordering operator, where one
10993 -- operand is the current instance, and the other is a static
10996 -- Note: the RM is clearly wrong here in not excluding string types.
10997 -- Without this exclusion, we would allow expressions like X > "ABC"
10998 -- to be considered as predicate-static, which is clearly not intended,
10999 -- since the idea is for predicate-static to be a subset of normal
11000 -- static expressions (and "DEF" > "ABC" is not a static expression).
11002 -- However, we do allow internally generated (not from source) equality
11003 -- and inequality operations to be valid on strings (this helps deal
11004 -- with cases where we transform A in "ABC" to A = "ABC).
11006 elsif Nkind
(Expr
) in N_Op_Compare
11007 and then ((not Is_String_Type
(Etype
(Left_Opnd
(Expr
))))
11008 or else (Nkind_In
(Expr
, N_Op_Eq
, N_Op_Ne
)
11009 and then not Comes_From_Source
(Expr
)))
11010 and then ((Is_Type_Ref
(Left_Opnd
(Expr
))
11011 and then Is_OK_Static_Expression
(Right_Opnd
(Expr
)))
11013 (Is_Type_Ref
(Right_Opnd
(Expr
))
11014 and then Is_OK_Static_Expression
(Left_Opnd
(Expr
))))
11018 -- 20. A call to a predefined boolean logical operator, where each
11019 -- operand is predicate-static.
11021 elsif (Nkind_In
(Expr
, N_Op_And
, N_Op_Or
, N_Op_Xor
)
11022 and then Is_Predicate_Static
(Left_Opnd
(Expr
), Nam
)
11023 and then Is_Predicate_Static
(Right_Opnd
(Expr
), Nam
))
11025 (Nkind
(Expr
) = N_Op_Not
11026 and then Is_Predicate_Static
(Right_Opnd
(Expr
), Nam
))
11030 -- 21. A short-circuit control form where both operands are
11031 -- predicate-static.
11033 elsif Nkind
(Expr
) in N_Short_Circuit
11034 and then Is_Predicate_Static
(Left_Opnd
(Expr
), Nam
)
11035 and then Is_Predicate_Static
(Right_Opnd
(Expr
), Nam
)
11039 -- 22. A parenthesized predicate-static expression. This does not
11040 -- require any special test, since we just ignore paren levels in
11041 -- all the cases above.
11043 -- One more test that is an implementation artifact caused by the fact
11044 -- that we are analyzing not the original expression, but the generated
11045 -- expression in the body of the predicate function. This can include
11046 -- references to inherited predicates, so that the expression we are
11047 -- processing looks like:
11049 -- expression and then xxPredicate (typ (Inns))
11051 -- Where the call is to a Predicate function for an inherited predicate.
11052 -- We simply ignore such a call (which could be to either a dynamic or
11053 -- a static predicate, but remember that we can have a Static_Predicate
11054 -- for a non-static subtype).
11056 elsif Nkind
(Expr
) = N_Function_Call
11057 and then Is_Predicate_Function
(Entity
(Name
(Expr
)))
11061 -- That's an exhaustive list of tests, all other cases are not
11062 -- predicate-static, so we return False.
11067 end Is_Predicate_Static
;
11069 ---------------------
11070 -- Kill_Rep_Clause --
11071 ---------------------
11073 procedure Kill_Rep_Clause
(N
: Node_Id
) is
11075 pragma Assert
(Ignore_Rep_Clauses
);
11077 -- Note: we use Replace rather than Rewrite, because we don't want
11078 -- ASIS to be able to use Original_Node to dig out the (undecorated)
11079 -- rep clause that is being replaced.
11081 Replace
(N
, Make_Null_Statement
(Sloc
(N
)));
11083 -- The null statement must be marked as not coming from source. This is
11084 -- so that ASIS ignores it, and also the back end does not expect bogus
11085 -- "from source" null statements in weird places (e.g. in declarative
11086 -- regions where such null statements are not allowed).
11088 Set_Comes_From_Source
(N
, False);
11089 end Kill_Rep_Clause
;
11095 function Minimum_Size
11097 Biased
: Boolean := False) return Nat
11099 Lo
: Uint
:= No_Uint
;
11100 Hi
: Uint
:= No_Uint
;
11101 LoR
: Ureal
:= No_Ureal
;
11102 HiR
: Ureal
:= No_Ureal
;
11103 LoSet
: Boolean := False;
11104 HiSet
: Boolean := False;
11107 Ancest
: Entity_Id
;
11108 R_Typ
: constant Entity_Id
:= Root_Type
(T
);
11111 -- If bad type, return 0
11113 if T
= Any_Type
then
11116 -- For generic types, just return zero. There cannot be any legitimate
11117 -- need to know such a size, but this routine may be called with a
11118 -- generic type as part of normal processing.
11120 elsif Is_Generic_Type
(R_Typ
)
11121 or else R_Typ
= Any_Type
11125 -- Access types (cannot have size smaller than System.Address)
11127 elsif Is_Access_Type
(T
) then
11128 return System_Address_Size
;
11130 -- Floating-point types
11132 elsif Is_Floating_Point_Type
(T
) then
11133 return UI_To_Int
(Esize
(R_Typ
));
11137 elsif Is_Discrete_Type
(T
) then
11139 -- The following loop is looking for the nearest compile time known
11140 -- bounds following the ancestor subtype chain. The idea is to find
11141 -- the most restrictive known bounds information.
11145 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
11150 if Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
)) then
11151 Lo
:= Expr_Rep_Value
(Type_Low_Bound
(Ancest
));
11158 if Compile_Time_Known_Value
(Type_High_Bound
(Ancest
)) then
11159 Hi
:= Expr_Rep_Value
(Type_High_Bound
(Ancest
));
11165 Ancest
:= Ancestor_Subtype
(Ancest
);
11167 if No
(Ancest
) then
11168 Ancest
:= Base_Type
(T
);
11170 if Is_Generic_Type
(Ancest
) then
11176 -- Fixed-point types. We can't simply use Expr_Value to get the
11177 -- Corresponding_Integer_Value values of the bounds, since these do not
11178 -- get set till the type is frozen, and this routine can be called
11179 -- before the type is frozen. Similarly the test for bounds being static
11180 -- needs to include the case where we have unanalyzed real literals for
11181 -- the same reason.
11183 elsif Is_Fixed_Point_Type
(T
) then
11185 -- The following loop is looking for the nearest compile time known
11186 -- bounds following the ancestor subtype chain. The idea is to find
11187 -- the most restrictive known bounds information.
11191 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
11195 -- Note: In the following two tests for LoSet and HiSet, it may
11196 -- seem redundant to test for N_Real_Literal here since normally
11197 -- one would assume that the test for the value being known at
11198 -- compile time includes this case. However, there is a glitch.
11199 -- If the real literal comes from folding a non-static expression,
11200 -- then we don't consider any non- static expression to be known
11201 -- at compile time if we are in configurable run time mode (needed
11202 -- in some cases to give a clearer definition of what is and what
11203 -- is not accepted). So the test is indeed needed. Without it, we
11204 -- would set neither Lo_Set nor Hi_Set and get an infinite loop.
11207 if Nkind
(Type_Low_Bound
(Ancest
)) = N_Real_Literal
11208 or else Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
))
11210 LoR
:= Expr_Value_R
(Type_Low_Bound
(Ancest
));
11217 if Nkind
(Type_High_Bound
(Ancest
)) = N_Real_Literal
11218 or else Compile_Time_Known_Value
(Type_High_Bound
(Ancest
))
11220 HiR
:= Expr_Value_R
(Type_High_Bound
(Ancest
));
11226 Ancest
:= Ancestor_Subtype
(Ancest
);
11228 if No
(Ancest
) then
11229 Ancest
:= Base_Type
(T
);
11231 if Is_Generic_Type
(Ancest
) then
11237 Lo
:= UR_To_Uint
(LoR
/ Small_Value
(T
));
11238 Hi
:= UR_To_Uint
(HiR
/ Small_Value
(T
));
11240 -- No other types allowed
11243 raise Program_Error
;
11246 -- Fall through with Hi and Lo set. Deal with biased case
11249 and then not Is_Fixed_Point_Type
(T
)
11250 and then not (Is_Enumeration_Type
(T
)
11251 and then Has_Non_Standard_Rep
(T
)))
11252 or else Has_Biased_Representation
(T
)
11258 -- Signed case. Note that we consider types like range 1 .. -1 to be
11259 -- signed for the purpose of computing the size, since the bounds have
11260 -- to be accommodated in the base type.
11262 if Lo
< 0 or else Hi
< 0 then
11266 -- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1))
11267 -- Note that we accommodate the case where the bounds cross. This
11268 -- can happen either because of the way the bounds are declared
11269 -- or because of the algorithm in Freeze_Fixed_Point_Type.
11283 -- If both bounds are positive, make sure that both are represen-
11284 -- table in the case where the bounds are crossed. This can happen
11285 -- either because of the way the bounds are declared, or because of
11286 -- the algorithm in Freeze_Fixed_Point_Type.
11292 -- S = size, (can accommodate 0 .. (2**size - 1))
11295 while Hi
>= Uint_2
** S
loop
11303 ---------------------------
11304 -- New_Stream_Subprogram --
11305 ---------------------------
11307 procedure New_Stream_Subprogram
11311 Nam
: TSS_Name_Type
)
11313 Loc
: constant Source_Ptr
:= Sloc
(N
);
11314 Sname
: constant Name_Id
:= Make_TSS_Name
(Base_Type
(Ent
), Nam
);
11315 Subp_Id
: Entity_Id
;
11316 Subp_Decl
: Node_Id
;
11320 Defer_Declaration
: constant Boolean :=
11321 Is_Tagged_Type
(Ent
) or else Is_Private_Type
(Ent
);
11322 -- For a tagged type, there is a declaration for each stream attribute
11323 -- at the freeze point, and we must generate only a completion of this
11324 -- declaration. We do the same for private types, because the full view
11325 -- might be tagged. Otherwise we generate a declaration at the point of
11326 -- the attribute definition clause.
11328 function Build_Spec
return Node_Id
;
11329 -- Used for declaration and renaming declaration, so that this is
11330 -- treated as a renaming_as_body.
11336 function Build_Spec
return Node_Id
is
11337 Out_P
: constant Boolean := (Nam
= TSS_Stream_Read
);
11340 T_Ref
: constant Node_Id
:= New_Occurrence_Of
(Etyp
, Loc
);
11343 Subp_Id
:= Make_Defining_Identifier
(Loc
, Sname
);
11345 -- S : access Root_Stream_Type'Class
11347 Formals
:= New_List
(
11348 Make_Parameter_Specification
(Loc
,
11349 Defining_Identifier
=>
11350 Make_Defining_Identifier
(Loc
, Name_S
),
11352 Make_Access_Definition
(Loc
,
11354 New_Occurrence_Of
(
11355 Designated_Type
(Etype
(F
)), Loc
))));
11357 if Nam
= TSS_Stream_Input
then
11359 Make_Function_Specification
(Loc
,
11360 Defining_Unit_Name
=> Subp_Id
,
11361 Parameter_Specifications
=> Formals
,
11362 Result_Definition
=> T_Ref
);
11366 Append_To
(Formals
,
11367 Make_Parameter_Specification
(Loc
,
11368 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_V
),
11369 Out_Present
=> Out_P
,
11370 Parameter_Type
=> T_Ref
));
11373 Make_Procedure_Specification
(Loc
,
11374 Defining_Unit_Name
=> Subp_Id
,
11375 Parameter_Specifications
=> Formals
);
11381 -- Start of processing for New_Stream_Subprogram
11384 F
:= First_Formal
(Subp
);
11386 if Ekind
(Subp
) = E_Procedure
then
11387 Etyp
:= Etype
(Next_Formal
(F
));
11389 Etyp
:= Etype
(Subp
);
11392 -- Prepare subprogram declaration and insert it as an action on the
11393 -- clause node. The visibility for this entity is used to test for
11394 -- visibility of the attribute definition clause (in the sense of
11395 -- 8.3(23) as amended by AI-195).
11397 if not Defer_Declaration
then
11399 Make_Subprogram_Declaration
(Loc
,
11400 Specification
=> Build_Spec
);
11402 -- For a tagged type, there is always a visible declaration for each
11403 -- stream TSS (it is a predefined primitive operation), and the
11404 -- completion of this declaration occurs at the freeze point, which is
11405 -- not always visible at places where the attribute definition clause is
11406 -- visible. So, we create a dummy entity here for the purpose of
11407 -- tracking the visibility of the attribute definition clause itself.
11411 Make_Defining_Identifier
(Loc
, New_External_Name
(Sname
, 'V'));
11413 Make_Object_Declaration
(Loc
,
11414 Defining_Identifier
=> Subp_Id
,
11415 Object_Definition
=> New_Occurrence_Of
(Standard_Boolean
, Loc
));
11418 Insert_Action
(N
, Subp_Decl
);
11419 Set_Entity
(N
, Subp_Id
);
11422 Make_Subprogram_Renaming_Declaration
(Loc
,
11423 Specification
=> Build_Spec
,
11424 Name
=> New_Occurrence_Of
(Subp
, Loc
));
11426 if Defer_Declaration
then
11427 Set_TSS
(Base_Type
(Ent
), Subp_Id
);
11429 Insert_Action
(N
, Subp_Decl
);
11430 Copy_TSS
(Subp_Id
, Base_Type
(Ent
));
11432 end New_Stream_Subprogram
;
11434 ------------------------------------------
11435 -- Push_Scope_And_Install_Discriminants --
11436 ------------------------------------------
11438 procedure Push_Scope_And_Install_Discriminants
(E
: Entity_Id
) is
11440 if Has_Discriminants
(E
) then
11443 -- Make discriminants visible for type declarations and protected
11444 -- type declarations, not for subtype declarations (RM 13.1.1 (12/3))
11446 if Nkind
(Parent
(E
)) /= N_Subtype_Declaration
then
11447 Install_Discriminants
(E
);
11450 end Push_Scope_And_Install_Discriminants
;
11452 ------------------------
11453 -- Rep_Item_Too_Early --
11454 ------------------------
11456 function Rep_Item_Too_Early
(T
: Entity_Id
; N
: Node_Id
) return Boolean is
11458 -- Cannot apply non-operational rep items to generic types
11460 if Is_Operational_Item
(N
) then
11464 and then Is_Generic_Type
(Root_Type
(T
))
11466 Error_Msg_N
("representation item not allowed for generic type", N
);
11470 -- Otherwise check for incomplete type
11472 if Is_Incomplete_Or_Private_Type
(T
)
11473 and then No
(Underlying_Type
(T
))
11475 (Nkind
(N
) /= N_Pragma
11476 or else Get_Pragma_Id
(N
) /= Pragma_Import
)
11479 ("representation item must be after full type declaration", N
);
11482 -- If the type has incomplete components, a representation clause is
11483 -- illegal but stream attributes and Convention pragmas are correct.
11485 elsif Has_Private_Component
(T
) then
11486 if Nkind
(N
) = N_Pragma
then
11491 ("representation item must appear after type is fully defined",
11498 end Rep_Item_Too_Early
;
11500 -----------------------
11501 -- Rep_Item_Too_Late --
11502 -----------------------
11504 function Rep_Item_Too_Late
11507 FOnly
: Boolean := False) return Boolean
11510 Parent_Type
: Entity_Id
;
11512 procedure No_Type_Rep_Item
;
11513 -- Output message indicating that no type-related aspects can be
11514 -- specified due to some property of the parent type.
11516 procedure Too_Late
;
11517 -- Output message for an aspect being specified too late
11519 -- Note that neither of the above errors is considered a serious one,
11520 -- since the effect is simply that we ignore the representation clause
11522 -- Is this really true? In any case if we make this change we must
11523 -- document the requirement in the spec of Rep_Item_Too_Late that
11524 -- if True is returned, then the rep item must be completely ignored???
11526 ----------------------
11527 -- No_Type_Rep_Item --
11528 ----------------------
11530 procedure No_Type_Rep_Item
is
11532 Error_Msg_N
("|type-related representation item not permitted!", N
);
11533 end No_Type_Rep_Item
;
11539 procedure Too_Late
is
11541 -- Other compilers seem more relaxed about rep items appearing too
11542 -- late. Since analysis tools typically don't care about rep items
11543 -- anyway, no reason to be too strict about this.
11545 if not Relaxed_RM_Semantics
then
11546 Error_Msg_N
("|representation item appears too late!", N
);
11550 -- Start of processing for Rep_Item_Too_Late
11553 -- First make sure entity is not frozen (RM 13.1(9))
11557 -- Exclude imported types, which may be frozen if they appear in a
11558 -- representation clause for a local type.
11560 and then not From_Limited_With
(T
)
11562 -- Exclude generated entities (not coming from source). The common
11563 -- case is when we generate a renaming which prematurely freezes the
11564 -- renamed internal entity, but we still want to be able to set copies
11565 -- of attribute values such as Size/Alignment.
11567 and then Comes_From_Source
(T
)
11570 S
:= First_Subtype
(T
);
11572 if Present
(Freeze_Node
(S
)) then
11573 if not Relaxed_RM_Semantics
then
11575 ("??no more representation items for }", Freeze_Node
(S
), S
);
11581 -- Check for case of untagged derived type whose parent either has
11582 -- primitive operations, or is a by reference type (RM 13.1(10)). In
11583 -- this case we do not output a Too_Late message, since there is no
11584 -- earlier point where the rep item could be placed to make it legal.
11588 and then Is_Derived_Type
(T
)
11589 and then not Is_Tagged_Type
(T
)
11591 Parent_Type
:= Etype
(Base_Type
(T
));
11593 if Has_Primitive_Operations
(Parent_Type
) then
11596 if not Relaxed_RM_Semantics
then
11598 ("\parent type & has primitive operations!", N
, Parent_Type
);
11603 elsif Is_By_Reference_Type
(Parent_Type
) then
11606 if not Relaxed_RM_Semantics
then
11608 ("\parent type & is a by reference type!", N
, Parent_Type
);
11615 -- No error, but one more warning to consider. The RM (surprisingly)
11616 -- allows this pattern:
11619 -- primitive operations for S
11620 -- type R is new S;
11621 -- rep clause for S
11623 -- Meaning that calls on the primitive operations of S for values of
11624 -- type R may require possibly expensive implicit conversion operations.
11625 -- This is not an error, but is worth a warning.
11627 if not Relaxed_RM_Semantics
and then Is_Type
(T
) then
11629 DTL
: constant Entity_Id
:= Derived_Type_Link
(Base_Type
(T
));
11633 and then Has_Primitive_Operations
(Base_Type
(T
))
11635 -- For now, do not generate this warning for the case of aspect
11636 -- specification using Ada 2012 syntax, since we get wrong
11637 -- messages we do not understand. The whole business of derived
11638 -- types and rep items seems a bit confused when aspects are
11639 -- used, since the aspects are not evaluated till freeze time.
11641 and then not From_Aspect_Specification
(N
)
11643 Error_Msg_Sloc
:= Sloc
(DTL
);
11645 ("representation item for& appears after derived type "
11646 & "declaration#??", N
);
11648 ("\may result in implicit conversions for primitive "
11649 & "operations of&??", N
, T
);
11651 ("\to change representations when called with arguments "
11652 & "of type&??", N
, DTL
);
11657 -- No error, link item into head of chain of rep items for the entity,
11658 -- but avoid chaining if we have an overloadable entity, and the pragma
11659 -- is one that can apply to multiple overloaded entities.
11661 if Is_Overloadable
(T
) and then Nkind
(N
) = N_Pragma
then
11663 Pname
: constant Name_Id
:= Pragma_Name
(N
);
11665 if Nam_In
(Pname
, Name_Convention
, Name_Import
, Name_Export
,
11666 Name_External
, Name_Interface
)
11673 Record_Rep_Item
(T
, N
);
11675 end Rep_Item_Too_Late
;
11677 -------------------------------------
11678 -- Replace_Type_References_Generic --
11679 -------------------------------------
11681 procedure Replace_Type_References_Generic
(N
: Node_Id
; T
: Entity_Id
) is
11682 TName
: constant Name_Id
:= Chars
(T
);
11684 function Replace_Node
(N
: Node_Id
) return Traverse_Result
;
11685 -- Processes a single node in the traversal procedure below, checking
11686 -- if node N should be replaced, and if so, doing the replacement.
11688 procedure Replace_Type_Refs
is new Traverse_Proc
(Replace_Node
);
11689 -- This instantiation provides the body of Replace_Type_References
11695 function Replace_Node
(N
: Node_Id
) return Traverse_Result
is
11700 -- Case of identifier
11702 if Nkind
(N
) = N_Identifier
then
11704 -- If not the type name, check whether it is a reference to
11705 -- some other type, which must be frozen before the predicate
11706 -- function is analyzed, i.e. before the freeze node of the
11707 -- type to which the predicate applies.
11709 if Chars
(N
) /= TName
then
11710 if Present
(Current_Entity
(N
))
11711 and then Is_Type
(Current_Entity
(N
))
11713 Freeze_Before
(Freeze_Node
(T
), Current_Entity
(N
));
11718 -- Otherwise do the replacement and we are done with this node
11721 Replace_Type_Reference
(N
);
11725 -- Case of selected component (which is what a qualification
11726 -- looks like in the unanalyzed tree, which is what we have.
11728 elsif Nkind
(N
) = N_Selected_Component
then
11730 -- If selector name is not our type, keeping going (we might
11731 -- still have an occurrence of the type in the prefix).
11733 if Nkind
(Selector_Name
(N
)) /= N_Identifier
11734 or else Chars
(Selector_Name
(N
)) /= TName
11738 -- Selector name is our type, check qualification
11741 -- Loop through scopes and prefixes, doing comparison
11743 S
:= Current_Scope
;
11746 -- Continue if no more scopes or scope with no name
11748 if No
(S
) or else Nkind
(S
) not in N_Has_Chars
then
11752 -- Do replace if prefix is an identifier matching the
11753 -- scope that we are currently looking at.
11755 if Nkind
(P
) = N_Identifier
11756 and then Chars
(P
) = Chars
(S
)
11758 Replace_Type_Reference
(N
);
11762 -- Go check scope above us if prefix is itself of the
11763 -- form of a selected component, whose selector matches
11764 -- the scope we are currently looking at.
11766 if Nkind
(P
) = N_Selected_Component
11767 and then Nkind
(Selector_Name
(P
)) = N_Identifier
11768 and then Chars
(Selector_Name
(P
)) = Chars
(S
)
11773 -- For anything else, we don't have a match, so keep on
11774 -- going, there are still some weird cases where we may
11775 -- still have a replacement within the prefix.
11783 -- Continue for any other node kind
11791 Replace_Type_Refs
(N
);
11792 end Replace_Type_References_Generic
;
11794 -------------------------
11795 -- Same_Representation --
11796 -------------------------
11798 function Same_Representation
(Typ1
, Typ2
: Entity_Id
) return Boolean is
11799 T1
: constant Entity_Id
:= Underlying_Type
(Typ1
);
11800 T2
: constant Entity_Id
:= Underlying_Type
(Typ2
);
11803 -- A quick check, if base types are the same, then we definitely have
11804 -- the same representation, because the subtype specific representation
11805 -- attributes (Size and Alignment) do not affect representation from
11806 -- the point of view of this test.
11808 if Base_Type
(T1
) = Base_Type
(T2
) then
11811 elsif Is_Private_Type
(Base_Type
(T2
))
11812 and then Base_Type
(T1
) = Full_View
(Base_Type
(T2
))
11817 -- Tagged types never have differing representations
11819 if Is_Tagged_Type
(T1
) then
11823 -- Representations are definitely different if conventions differ
11825 if Convention
(T1
) /= Convention
(T2
) then
11829 -- Representations are different if component alignments or scalar
11830 -- storage orders differ.
11832 if (Is_Record_Type
(T1
) or else Is_Array_Type
(T1
))
11834 (Is_Record_Type
(T2
) or else Is_Array_Type
(T2
))
11836 (Component_Alignment
(T1
) /= Component_Alignment
(T2
)
11838 Reverse_Storage_Order
(T1
) /= Reverse_Storage_Order
(T2
))
11843 -- For arrays, the only real issue is component size. If we know the
11844 -- component size for both arrays, and it is the same, then that's
11845 -- good enough to know we don't have a change of representation.
11847 if Is_Array_Type
(T1
) then
11848 if Known_Component_Size
(T1
)
11849 and then Known_Component_Size
(T2
)
11850 and then Component_Size
(T1
) = Component_Size
(T2
)
11852 if VM_Target
= No_VM
then
11855 -- In VM targets the representation of arrays with aliased
11856 -- components differs from arrays with non-aliased components
11859 return Has_Aliased_Components
(Base_Type
(T1
))
11861 Has_Aliased_Components
(Base_Type
(T2
));
11866 -- Types definitely have same representation if neither has non-standard
11867 -- representation since default representations are always consistent.
11868 -- If only one has non-standard representation, and the other does not,
11869 -- then we consider that they do not have the same representation. They
11870 -- might, but there is no way of telling early enough.
11872 if Has_Non_Standard_Rep
(T1
) then
11873 if not Has_Non_Standard_Rep
(T2
) then
11877 return not Has_Non_Standard_Rep
(T2
);
11880 -- Here the two types both have non-standard representation, and we need
11881 -- to determine if they have the same non-standard representation.
11883 -- For arrays, we simply need to test if the component sizes are the
11884 -- same. Pragma Pack is reflected in modified component sizes, so this
11885 -- check also deals with pragma Pack.
11887 if Is_Array_Type
(T1
) then
11888 return Component_Size
(T1
) = Component_Size
(T2
);
11890 -- Tagged types always have the same representation, because it is not
11891 -- possible to specify different representations for common fields.
11893 elsif Is_Tagged_Type
(T1
) then
11896 -- Case of record types
11898 elsif Is_Record_Type
(T1
) then
11900 -- Packed status must conform
11902 if Is_Packed
(T1
) /= Is_Packed
(T2
) then
11905 -- Otherwise we must check components. Typ2 maybe a constrained
11906 -- subtype with fewer components, so we compare the components
11907 -- of the base types.
11910 Record_Case
: declare
11911 CD1
, CD2
: Entity_Id
;
11913 function Same_Rep
return Boolean;
11914 -- CD1 and CD2 are either components or discriminants. This
11915 -- function tests whether they have the same representation.
11921 function Same_Rep
return Boolean is
11923 if No
(Component_Clause
(CD1
)) then
11924 return No
(Component_Clause
(CD2
));
11926 -- Note: at this point, component clauses have been
11927 -- normalized to the default bit order, so that the
11928 -- comparison of Component_Bit_Offsets is meaningful.
11931 Present
(Component_Clause
(CD2
))
11933 Component_Bit_Offset
(CD1
) = Component_Bit_Offset
(CD2
)
11935 Esize
(CD1
) = Esize
(CD2
);
11939 -- Start of processing for Record_Case
11942 if Has_Discriminants
(T1
) then
11944 -- The number of discriminants may be different if the
11945 -- derived type has fewer (constrained by values). The
11946 -- invisible discriminants retain the representation of
11947 -- the original, so the discrepancy does not per se
11948 -- indicate a different representation.
11950 CD1
:= First_Discriminant
(T1
);
11951 CD2
:= First_Discriminant
(T2
);
11952 while Present
(CD1
) and then Present
(CD2
) loop
11953 if not Same_Rep
then
11956 Next_Discriminant
(CD1
);
11957 Next_Discriminant
(CD2
);
11962 CD1
:= First_Component
(Underlying_Type
(Base_Type
(T1
)));
11963 CD2
:= First_Component
(Underlying_Type
(Base_Type
(T2
)));
11964 while Present
(CD1
) loop
11965 if not Same_Rep
then
11968 Next_Component
(CD1
);
11969 Next_Component
(CD2
);
11977 -- For enumeration types, we must check each literal to see if the
11978 -- representation is the same. Note that we do not permit enumeration
11979 -- representation clauses for Character and Wide_Character, so these
11980 -- cases were already dealt with.
11982 elsif Is_Enumeration_Type
(T1
) then
11983 Enumeration_Case
: declare
11984 L1
, L2
: Entity_Id
;
11987 L1
:= First_Literal
(T1
);
11988 L2
:= First_Literal
(T2
);
11989 while Present
(L1
) loop
11990 if Enumeration_Rep
(L1
) /= Enumeration_Rep
(L2
) then
11999 end Enumeration_Case
;
12001 -- Any other types have the same representation for these purposes
12006 end Same_Representation
;
12008 --------------------------------
12009 -- Resolve_Iterable_Operation --
12010 --------------------------------
12012 procedure Resolve_Iterable_Operation
12014 Cursor
: Entity_Id
;
12023 if not Is_Overloaded
(N
) then
12024 if not Is_Entity_Name
(N
)
12025 or else Ekind
(Entity
(N
)) /= E_Function
12026 or else Scope
(Entity
(N
)) /= Scope
(Typ
)
12027 or else No
(First_Formal
(Entity
(N
)))
12028 or else Etype
(First_Formal
(Entity
(N
))) /= Typ
12030 Error_Msg_N
("iterable primitive must be local function name "
12031 & "whose first formal is an iterable type", N
);
12036 F1
:= First_Formal
(Ent
);
12037 if Nam
= Name_First
then
12039 -- First (Container) => Cursor
12041 if Etype
(Ent
) /= Cursor
then
12042 Error_Msg_N
("primitive for First must yield a curosr", N
);
12045 elsif Nam
= Name_Next
then
12047 -- Next (Container, Cursor) => Cursor
12049 F2
:= Next_Formal
(F1
);
12051 if Etype
(F2
) /= Cursor
12052 or else Etype
(Ent
) /= Cursor
12053 or else Present
(Next_Formal
(F2
))
12055 Error_Msg_N
("no match for Next iterable primitive", N
);
12058 elsif Nam
= Name_Has_Element
then
12060 -- Has_Element (Container, Cursor) => Boolean
12062 F2
:= Next_Formal
(F1
);
12063 if Etype
(F2
) /= Cursor
12064 or else Etype
(Ent
) /= Standard_Boolean
12065 or else Present
(Next_Formal
(F2
))
12067 Error_Msg_N
("no match for Has_Element iterable primitive", N
);
12070 elsif Nam
= Name_Element
then
12071 F2
:= Next_Formal
(F1
);
12074 or else Etype
(F2
) /= Cursor
12075 or else Present
(Next_Formal
(F2
))
12077 Error_Msg_N
("no match for Element iterable primitive", N
);
12082 raise Program_Error
;
12086 -- Overloaded case: find subprogram with proper signature.
12087 -- Caller will report error if no match is found.
12094 Get_First_Interp
(N
, I
, It
);
12095 while Present
(It
.Typ
) loop
12096 if Ekind
(It
.Nam
) = E_Function
12097 and then Scope
(It
.Nam
) = Scope
(Typ
)
12098 and then Etype
(First_Formal
(It
.Nam
)) = Typ
12100 F1
:= First_Formal
(It
.Nam
);
12102 if Nam
= Name_First
then
12103 if Etype
(It
.Nam
) = Cursor
12104 and then No
(Next_Formal
(F1
))
12106 Set_Entity
(N
, It
.Nam
);
12110 elsif Nam
= Name_Next
then
12111 F2
:= Next_Formal
(F1
);
12114 and then No
(Next_Formal
(F2
))
12115 and then Etype
(F2
) = Cursor
12116 and then Etype
(It
.Nam
) = Cursor
12118 Set_Entity
(N
, It
.Nam
);
12122 elsif Nam
= Name_Has_Element
then
12123 F2
:= Next_Formal
(F1
);
12126 and then No
(Next_Formal
(F2
))
12127 and then Etype
(F2
) = Cursor
12128 and then Etype
(It
.Nam
) = Standard_Boolean
12130 Set_Entity
(N
, It
.Nam
);
12131 F2
:= Next_Formal
(F1
);
12135 elsif Nam
= Name_Element
then
12136 F2
:= Next_Formal
(F1
);
12139 and then No
(Next_Formal
(F2
))
12140 and then Etype
(F2
) = Cursor
12142 Set_Entity
(N
, It
.Nam
);
12148 Get_Next_Interp
(I
, It
);
12152 end Resolve_Iterable_Operation
;
12158 procedure Set_Biased
12162 Biased
: Boolean := True)
12166 Set_Has_Biased_Representation
(E
);
12168 if Warn_On_Biased_Representation
then
12170 ("?B?" & Msg
& " forces biased representation for&", N
, E
);
12175 --------------------
12176 -- Set_Enum_Esize --
12177 --------------------
12179 procedure Set_Enum_Esize
(T
: Entity_Id
) is
12185 Init_Alignment
(T
);
12187 -- Find the minimum standard size (8,16,32,64) that fits
12189 Lo
:= Enumeration_Rep
(Entity
(Type_Low_Bound
(T
)));
12190 Hi
:= Enumeration_Rep
(Entity
(Type_High_Bound
(T
)));
12193 if Lo
>= -Uint_2
**07 and then Hi
< Uint_2
**07 then
12194 Sz
:= Standard_Character_Size
; -- May be > 8 on some targets
12196 elsif Lo
>= -Uint_2
**15 and then Hi
< Uint_2
**15 then
12199 elsif Lo
>= -Uint_2
**31 and then Hi
< Uint_2
**31 then
12202 else pragma Assert
(Lo
>= -Uint_2
**63 and then Hi
< Uint_2
**63);
12207 if Hi
< Uint_2
**08 then
12208 Sz
:= Standard_Character_Size
; -- May be > 8 on some targets
12210 elsif Hi
< Uint_2
**16 then
12213 elsif Hi
< Uint_2
**32 then
12216 else pragma Assert
(Hi
< Uint_2
**63);
12221 -- That minimum is the proper size unless we have a foreign convention
12222 -- and the size required is 32 or less, in which case we bump the size
12223 -- up to 32. This is required for C and C++ and seems reasonable for
12224 -- all other foreign conventions.
12226 if Has_Foreign_Convention
(T
)
12227 and then Esize
(T
) < Standard_Integer_Size
12229 -- Don't do this if Short_Enums on target
12231 and then not Target_Short_Enums
12233 Init_Esize
(T
, Standard_Integer_Size
);
12235 Init_Esize
(T
, Sz
);
12237 end Set_Enum_Esize
;
12239 -----------------------------
12240 -- Uninstall_Discriminants --
12241 -----------------------------
12243 procedure Uninstall_Discriminants
(E
: Entity_Id
) is
12249 -- Discriminants have been made visible for type declarations and
12250 -- protected type declarations, not for subtype declarations.
12252 if Nkind
(Parent
(E
)) /= N_Subtype_Declaration
then
12253 Disc
:= First_Discriminant
(E
);
12254 while Present
(Disc
) loop
12255 if Disc
/= Current_Entity
(Disc
) then
12256 Prev
:= Current_Entity
(Disc
);
12257 while Present
(Prev
)
12258 and then Present
(Homonym
(Prev
))
12259 and then Homonym
(Prev
) /= Disc
12261 Prev
:= Homonym
(Prev
);
12267 Set_Is_Immediately_Visible
(Disc
, False);
12269 Outer
:= Homonym
(Disc
);
12270 while Present
(Outer
) and then Scope
(Outer
) = E
loop
12271 Outer
:= Homonym
(Outer
);
12274 -- Reset homonym link of other entities, but do not modify link
12275 -- between entities in current scope, so that the back-end can
12276 -- have a proper count of local overloadings.
12279 Set_Name_Entity_Id
(Chars
(Disc
), Outer
);
12281 elsif Scope
(Prev
) /= Scope
(Disc
) then
12282 Set_Homonym
(Prev
, Outer
);
12285 Next_Discriminant
(Disc
);
12288 end Uninstall_Discriminants
;
12290 -------------------------------------------
12291 -- Uninstall_Discriminants_And_Pop_Scope --
12292 -------------------------------------------
12294 procedure Uninstall_Discriminants_And_Pop_Scope
(E
: Entity_Id
) is
12296 if Has_Discriminants
(E
) then
12297 Uninstall_Discriminants
(E
);
12300 end Uninstall_Discriminants_And_Pop_Scope
;
12302 ------------------------------
12303 -- Validate_Address_Clauses --
12304 ------------------------------
12306 procedure Validate_Address_Clauses
is
12308 for J
in Address_Clause_Checks
.First
.. Address_Clause_Checks
.Last
loop
12310 ACCR
: Address_Clause_Check_Record
12311 renames Address_Clause_Checks
.Table
(J
);
12315 X_Alignment
: Uint
;
12316 Y_Alignment
: Uint
;
12322 -- Skip processing of this entry if warning already posted
12324 if not Address_Warning_Posted
(ACCR
.N
) then
12325 Expr
:= Original_Node
(Expression
(ACCR
.N
));
12329 X_Alignment
:= Alignment
(ACCR
.X
);
12330 Y_Alignment
:= Alignment
(ACCR
.Y
);
12332 -- Similarly obtain sizes
12334 X_Size
:= Esize
(ACCR
.X
);
12335 Y_Size
:= Esize
(ACCR
.Y
);
12337 -- Check for large object overlaying smaller one
12340 and then X_Size
> Uint_0
12341 and then X_Size
> Y_Size
12344 ("??& overlays smaller object", ACCR
.N
, ACCR
.X
);
12346 ("\??program execution may be erroneous", ACCR
.N
);
12347 Error_Msg_Uint_1
:= X_Size
;
12349 ("\??size of & is ^", ACCR
.N
, ACCR
.X
);
12350 Error_Msg_Uint_1
:= Y_Size
;
12352 ("\??size of & is ^", ACCR
.N
, ACCR
.Y
);
12354 -- Check for inadequate alignment, both of the base object
12355 -- and of the offset, if any.
12357 -- Note: we do not check the alignment if we gave a size
12358 -- warning, since it would likely be redundant.
12360 elsif Y_Alignment
/= Uint_0
12361 and then (Y_Alignment
< X_Alignment
12364 Nkind
(Expr
) = N_Attribute_Reference
12366 Attribute_Name
(Expr
) = Name_Address
12368 Has_Compatible_Alignment
12369 (ACCR
.X
, Prefix
(Expr
))
12370 /= Known_Compatible
))
12373 ("??specified address for& may be inconsistent "
12374 & "with alignment", ACCR
.N
, ACCR
.X
);
12376 ("\??program execution may be erroneous (RM 13.3(27))",
12378 Error_Msg_Uint_1
:= X_Alignment
;
12380 ("\??alignment of & is ^", ACCR
.N
, ACCR
.X
);
12381 Error_Msg_Uint_1
:= Y_Alignment
;
12383 ("\??alignment of & is ^", ACCR
.N
, ACCR
.Y
);
12384 if Y_Alignment
>= X_Alignment
then
12386 ("\??but offset is not multiple of alignment", ACCR
.N
);
12392 end Validate_Address_Clauses
;
12394 ---------------------------
12395 -- Validate_Independence --
12396 ---------------------------
12398 procedure Validate_Independence
is
12399 SU
: constant Uint
:= UI_From_Int
(System_Storage_Unit
);
12407 procedure Check_Array_Type
(Atyp
: Entity_Id
);
12408 -- Checks if the array type Atyp has independent components, and
12409 -- if not, outputs an appropriate set of error messages.
12411 procedure No_Independence
;
12412 -- Output message that independence cannot be guaranteed
12414 function OK_Component
(C
: Entity_Id
) return Boolean;
12415 -- Checks one component to see if it is independently accessible, and
12416 -- if so yields True, otherwise yields False if independent access
12417 -- cannot be guaranteed. This is a conservative routine, it only
12418 -- returns True if it knows for sure, it returns False if it knows
12419 -- there is a problem, or it cannot be sure there is no problem.
12421 procedure Reason_Bad_Component
(C
: Entity_Id
);
12422 -- Outputs continuation message if a reason can be determined for
12423 -- the component C being bad.
12425 ----------------------
12426 -- Check_Array_Type --
12427 ----------------------
12429 procedure Check_Array_Type
(Atyp
: Entity_Id
) is
12430 Ctyp
: constant Entity_Id
:= Component_Type
(Atyp
);
12433 -- OK if no alignment clause, no pack, and no component size
12435 if not Has_Component_Size_Clause
(Atyp
)
12436 and then not Has_Alignment_Clause
(Atyp
)
12437 and then not Is_Packed
(Atyp
)
12442 -- Case of component size is greater than or equal to 64 and the
12443 -- alignment of the array is at least as large as the alignment
12444 -- of the component. We are definitely OK in this situation.
12446 if Known_Component_Size
(Atyp
)
12447 and then Component_Size
(Atyp
) >= 64
12448 and then Known_Alignment
(Atyp
)
12449 and then Known_Alignment
(Ctyp
)
12450 and then Alignment
(Atyp
) >= Alignment
(Ctyp
)
12455 -- Check actual component size
12457 if not Known_Component_Size
(Atyp
)
12458 or else not (Addressable
(Component_Size
(Atyp
))
12459 and then Component_Size
(Atyp
) < 64)
12460 or else Component_Size
(Atyp
) mod Esize
(Ctyp
) /= 0
12464 -- Bad component size, check reason
12466 if Has_Component_Size_Clause
(Atyp
) then
12467 P
:= Get_Attribute_Definition_Clause
12468 (Atyp
, Attribute_Component_Size
);
12470 if Present
(P
) then
12471 Error_Msg_Sloc
:= Sloc
(P
);
12472 Error_Msg_N
("\because of Component_Size clause#", N
);
12477 if Is_Packed
(Atyp
) then
12478 P
:= Get_Rep_Pragma
(Atyp
, Name_Pack
);
12480 if Present
(P
) then
12481 Error_Msg_Sloc
:= Sloc
(P
);
12482 Error_Msg_N
("\because of pragma Pack#", N
);
12487 -- No reason found, just return
12492 -- Array type is OK independence-wise
12495 end Check_Array_Type
;
12497 ---------------------
12498 -- No_Independence --
12499 ---------------------
12501 procedure No_Independence
is
12503 if Pragma_Name
(N
) = Name_Independent
then
12504 Error_Msg_NE
("independence cannot be guaranteed for&", N
, E
);
12507 ("independent components cannot be guaranteed for&", N
, E
);
12509 end No_Independence
;
12515 function OK_Component
(C
: Entity_Id
) return Boolean is
12516 Rec
: constant Entity_Id
:= Scope
(C
);
12517 Ctyp
: constant Entity_Id
:= Etype
(C
);
12520 -- OK if no component clause, no Pack, and no alignment clause
12522 if No
(Component_Clause
(C
))
12523 and then not Is_Packed
(Rec
)
12524 and then not Has_Alignment_Clause
(Rec
)
12529 -- Here we look at the actual component layout. A component is
12530 -- addressable if its size is a multiple of the Esize of the
12531 -- component type, and its starting position in the record has
12532 -- appropriate alignment, and the record itself has appropriate
12533 -- alignment to guarantee the component alignment.
12535 -- Make sure sizes are static, always assume the worst for any
12536 -- cases where we cannot check static values.
12538 if not (Known_Static_Esize
(C
)
12540 Known_Static_Esize
(Ctyp
))
12545 -- Size of component must be addressable or greater than 64 bits
12546 -- and a multiple of bytes.
12548 if not Addressable
(Esize
(C
)) and then Esize
(C
) < Uint_64
then
12552 -- Check size is proper multiple
12554 if Esize
(C
) mod Esize
(Ctyp
) /= 0 then
12558 -- Check alignment of component is OK
12560 if not Known_Component_Bit_Offset
(C
)
12561 or else Component_Bit_Offset
(C
) < Uint_0
12562 or else Component_Bit_Offset
(C
) mod Esize
(Ctyp
) /= 0
12567 -- Check alignment of record type is OK
12569 if not Known_Alignment
(Rec
)
12570 or else (Alignment
(Rec
) * SU
) mod Esize
(Ctyp
) /= 0
12575 -- All tests passed, component is addressable
12580 --------------------------
12581 -- Reason_Bad_Component --
12582 --------------------------
12584 procedure Reason_Bad_Component
(C
: Entity_Id
) is
12585 Rec
: constant Entity_Id
:= Scope
(C
);
12586 Ctyp
: constant Entity_Id
:= Etype
(C
);
12589 -- If component clause present assume that's the problem
12591 if Present
(Component_Clause
(C
)) then
12592 Error_Msg_Sloc
:= Sloc
(Component_Clause
(C
));
12593 Error_Msg_N
("\because of Component_Clause#", N
);
12597 -- If pragma Pack clause present, assume that's the problem
12599 if Is_Packed
(Rec
) then
12600 P
:= Get_Rep_Pragma
(Rec
, Name_Pack
);
12602 if Present
(P
) then
12603 Error_Msg_Sloc
:= Sloc
(P
);
12604 Error_Msg_N
("\because of pragma Pack#", N
);
12609 -- See if record has bad alignment clause
12611 if Has_Alignment_Clause
(Rec
)
12612 and then Known_Alignment
(Rec
)
12613 and then (Alignment
(Rec
) * SU
) mod Esize
(Ctyp
) /= 0
12615 P
:= Get_Attribute_Definition_Clause
(Rec
, Attribute_Alignment
);
12617 if Present
(P
) then
12618 Error_Msg_Sloc
:= Sloc
(P
);
12619 Error_Msg_N
("\because of Alignment clause#", N
);
12623 -- Couldn't find a reason, so return without a message
12626 end Reason_Bad_Component
;
12628 -- Start of processing for Validate_Independence
12631 for J
in Independence_Checks
.First
.. Independence_Checks
.Last
loop
12632 N
:= Independence_Checks
.Table
(J
).N
;
12633 E
:= Independence_Checks
.Table
(J
).E
;
12634 IC
:= Pragma_Name
(N
) = Name_Independent_Components
;
12636 -- Deal with component case
12638 if Ekind
(E
) = E_Discriminant
or else Ekind
(E
) = E_Component
then
12639 if not OK_Component
(E
) then
12641 Reason_Bad_Component
(E
);
12646 -- Deal with record with Independent_Components
12648 if IC
and then Is_Record_Type
(E
) then
12649 Comp
:= First_Component_Or_Discriminant
(E
);
12650 while Present
(Comp
) loop
12651 if not OK_Component
(Comp
) then
12653 Reason_Bad_Component
(Comp
);
12657 Next_Component_Or_Discriminant
(Comp
);
12661 -- Deal with address clause case
12663 if Is_Object
(E
) then
12664 Addr
:= Address_Clause
(E
);
12666 if Present
(Addr
) then
12668 Error_Msg_Sloc
:= Sloc
(Addr
);
12669 Error_Msg_N
("\because of Address clause#", N
);
12674 -- Deal with independent components for array type
12676 if IC
and then Is_Array_Type
(E
) then
12677 Check_Array_Type
(E
);
12680 -- Deal with independent components for array object
12682 if IC
and then Is_Object
(E
) and then Is_Array_Type
(Etype
(E
)) then
12683 Check_Array_Type
(Etype
(E
));
12688 end Validate_Independence
;
12690 ------------------------------
12691 -- Validate_Iterable_Aspect --
12692 ------------------------------
12694 procedure Validate_Iterable_Aspect
(Typ
: Entity_Id
; ASN
: Node_Id
) is
12699 Cursor
: constant Entity_Id
:= Get_Cursor_Type
(ASN
, Typ
);
12701 First_Id
: Entity_Id
;
12702 Next_Id
: Entity_Id
;
12703 Has_Element_Id
: Entity_Id
;
12704 Element_Id
: Entity_Id
;
12707 -- If previous error aspect is unusable
12709 if Cursor
= Any_Type
then
12715 Has_Element_Id
:= Empty
;
12716 Element_Id
:= Empty
;
12718 -- Each expression must resolve to a function with the proper signature
12720 Assoc
:= First
(Component_Associations
(Expression
(ASN
)));
12721 while Present
(Assoc
) loop
12722 Expr
:= Expression
(Assoc
);
12725 Prim
:= First
(Choices
(Assoc
));
12727 if Nkind
(Prim
) /= N_Identifier
12728 or else Present
(Next
(Prim
))
12730 Error_Msg_N
("illegal name in association", Prim
);
12732 elsif Chars
(Prim
) = Name_First
then
12733 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_First
);
12734 First_Id
:= Entity
(Expr
);
12736 elsif Chars
(Prim
) = Name_Next
then
12737 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_Next
);
12738 Next_Id
:= Entity
(Expr
);
12740 elsif Chars
(Prim
) = Name_Has_Element
then
12741 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_Has_Element
);
12742 Has_Element_Id
:= Entity
(Expr
);
12744 elsif Chars
(Prim
) = Name_Element
then
12745 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_Element
);
12746 Element_Id
:= Entity
(Expr
);
12749 Error_Msg_N
("invalid name for iterable function", Prim
);
12755 if No
(First_Id
) then
12756 Error_Msg_N
("match for First primitive not found", ASN
);
12758 elsif No
(Next_Id
) then
12759 Error_Msg_N
("match for Next primitive not found", ASN
);
12761 elsif No
(Has_Element_Id
) then
12762 Error_Msg_N
("match for Has_Element primitive not found", ASN
);
12764 elsif No
(Element_Id
) then
12767 end Validate_Iterable_Aspect
;
12769 -----------------------------------
12770 -- Validate_Unchecked_Conversion --
12771 -----------------------------------
12773 procedure Validate_Unchecked_Conversion
12775 Act_Unit
: Entity_Id
)
12777 Source
: Entity_Id
;
12778 Target
: Entity_Id
;
12782 -- Obtain source and target types. Note that we call Ancestor_Subtype
12783 -- here because the processing for generic instantiation always makes
12784 -- subtypes, and we want the original frozen actual types.
12786 -- If we are dealing with private types, then do the check on their
12787 -- fully declared counterparts if the full declarations have been
12788 -- encountered (they don't have to be visible, but they must exist).
12790 Source
:= Ancestor_Subtype
(Etype
(First_Formal
(Act_Unit
)));
12792 if Is_Private_Type
(Source
)
12793 and then Present
(Underlying_Type
(Source
))
12795 Source
:= Underlying_Type
(Source
);
12798 Target
:= Ancestor_Subtype
(Etype
(Act_Unit
));
12800 -- If either type is generic, the instantiation happens within a generic
12801 -- unit, and there is nothing to check. The proper check will happen
12802 -- when the enclosing generic is instantiated.
12804 if Is_Generic_Type
(Source
) or else Is_Generic_Type
(Target
) then
12808 if Is_Private_Type
(Target
)
12809 and then Present
(Underlying_Type
(Target
))
12811 Target
:= Underlying_Type
(Target
);
12814 -- Source may be unconstrained array, but not target
12816 if Is_Array_Type
(Target
) and then not Is_Constrained
(Target
) then
12818 ("unchecked conversion to unconstrained array not allowed", N
);
12822 -- Warn if conversion between two different convention pointers
12824 if Is_Access_Type
(Target
)
12825 and then Is_Access_Type
(Source
)
12826 and then Convention
(Target
) /= Convention
(Source
)
12827 and then Warn_On_Unchecked_Conversion
12829 -- Give warnings for subprogram pointers only on most targets
12831 if Is_Access_Subprogram_Type
(Target
)
12832 or else Is_Access_Subprogram_Type
(Source
)
12835 ("?z?conversion between pointers with different conventions!",
12840 -- Warn if one of the operands is Ada.Calendar.Time. Do not emit a
12841 -- warning when compiling GNAT-related sources.
12843 if Warn_On_Unchecked_Conversion
12844 and then not In_Predefined_Unit
(N
)
12845 and then RTU_Loaded
(Ada_Calendar
)
12847 (Chars
(Source
) = Name_Time
12849 Chars
(Target
) = Name_Time
)
12851 -- If Ada.Calendar is loaded and the name of one of the operands is
12852 -- Time, there is a good chance that this is Ada.Calendar.Time.
12855 Calendar_Time
: constant Entity_Id
:=
12856 Full_View
(RTE
(RO_CA_Time
));
12858 pragma Assert
(Present
(Calendar_Time
));
12860 if Source
= Calendar_Time
or else Target
= Calendar_Time
then
12862 ("?z?representation of 'Time values may change between " &
12863 "'G'N'A'T versions", N
);
12868 -- Make entry in unchecked conversion table for later processing by
12869 -- Validate_Unchecked_Conversions, which will check sizes and alignments
12870 -- (using values set by the back-end where possible). This is only done
12871 -- if the appropriate warning is active.
12873 if Warn_On_Unchecked_Conversion
then
12874 Unchecked_Conversions
.Append
12875 (New_Val
=> UC_Entry
'(Eloc => Sloc (N),
12878 Act_Unit => Act_Unit));
12880 -- If both sizes are known statically now, then back end annotation
12881 -- is not required to do a proper check but if either size is not
12882 -- known statically, then we need the annotation.
12884 if Known_Static_RM_Size (Source)
12886 Known_Static_RM_Size (Target)
12890 Back_Annotate_Rep_Info := True;
12894 -- If unchecked conversion to access type, and access type is declared
12895 -- in the same unit as the unchecked conversion, then set the flag
12896 -- No_Strict_Aliasing (no strict aliasing is implicit here)
12898 if Is_Access_Type (Target) and then
12899 In_Same_Source_Unit (Target, N)
12901 Set_No_Strict_Aliasing (Implementation_Base_Type (Target));
12904 -- Generate N_Validate_Unchecked_Conversion node for back end in case
12905 -- the back end needs to perform special validation checks.
12907 -- Shouldn't this be in Exp_Ch13, since the check only gets done if we
12908 -- have full expansion and the back end is called ???
12911 Make_Validate_Unchecked_Conversion (Sloc (N));
12912 Set_Source_Type (Vnode, Source);
12913 Set_Target_Type (Vnode, Target);
12915 -- If the unchecked conversion node is in a list, just insert before it.
12916 -- If not we have some strange case, not worth bothering about.
12918 if Is_List_Member (N) then
12919 Insert_After (N, Vnode);
12921 end Validate_Unchecked_Conversion;
12923 ------------------------------------
12924 -- Validate_Unchecked_Conversions --
12925 ------------------------------------
12927 procedure Validate_Unchecked_Conversions is
12929 for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop
12931 T : UC_Entry renames Unchecked_Conversions.Table (N);
12933 Eloc : constant Source_Ptr := T.Eloc;
12934 Source : constant Entity_Id := T.Source;
12935 Target : constant Entity_Id := T.Target;
12936 Act_Unit : constant Entity_Id := T.Act_Unit;
12942 -- Skip if function marked as warnings off
12944 if Warnings_Off (Act_Unit) then
12948 -- This validation check, which warns if we have unequal sizes for
12949 -- unchecked conversion, and thus potentially implementation
12950 -- dependent semantics, is one of the few occasions on which we
12951 -- use the official RM size instead of Esize. See description in
12952 -- Einfo "Handling of Type'Size Values" for details.
12954 if Serious_Errors_Detected = 0
12955 and then Known_Static_RM_Size (Source)
12956 and then Known_Static_RM_Size (Target)
12958 -- Don't do the check if warnings off for either type, note the
12959 -- deliberate use of OR here instead of OR ELSE to get the flag
12960 -- Warnings_Off_Used set for both types if appropriate.
12962 and then not (Has_Warnings_Off (Source)
12964 Has_Warnings_Off (Target))
12966 Source_Siz := RM_Size (Source);
12967 Target_Siz := RM_Size (Target);
12969 if Source_Siz /= Target_Siz then
12971 ("?z?types for unchecked conversion have different sizes!",
12974 if All_Errors_Mode then
12975 Error_Msg_Name_1 := Chars (Source);
12976 Error_Msg_Uint_1 := Source_Siz;
12977 Error_Msg_Name_2 := Chars (Target);
12978 Error_Msg_Uint_2 := Target_Siz;
12979 Error_Msg ("\size of % is ^, size of % is ^?z?", Eloc);
12981 Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz);
12983 if Is_Discrete_Type (Source)
12985 Is_Discrete_Type (Target)
12987 if Source_Siz > Target_Siz then
12989 ("\?z?^ high order bits of source will "
12990 & "be ignored!", Eloc);
12992 elsif Is_Unsigned_Type (Source) then
12994 ("\?z?source will be extended with ^ high order "
12995 & "zero bits!", Eloc);
12999 ("\?z?source will be extended with ^ high order "
13000 & "sign bits!", Eloc);
13003 elsif Source_Siz < Target_Siz then
13004 if Is_Discrete_Type (Target) then
13005 if Bytes_Big_Endian then
13007 ("\?z?target value will include ^ undefined "
13008 & "low order bits!", Eloc);
13011 ("\?z?target value will include ^ undefined "
13012 & "high order bits!", Eloc);
13017 ("\?z?^ trailing bits of target value will be "
13018 & "undefined!", Eloc);
13021 else pragma Assert (Source_Siz > Target_Siz);
13023 ("\?z?^ trailing bits of source will be ignored!",
13030 -- If both types are access types, we need to check the alignment.
13031 -- If the alignment of both is specified, we can do it here.
13033 if Serious_Errors_Detected = 0
13034 and then Is_Access_Type (Source)
13035 and then Is_Access_Type (Target)
13036 and then Target_Strict_Alignment
13037 and then Present (Designated_Type (Source))
13038 and then Present (Designated_Type (Target))
13041 D_Source : constant Entity_Id := Designated_Type (Source);
13042 D_Target : constant Entity_Id := Designated_Type (Target);
13045 if Known_Alignment (D_Source)
13047 Known_Alignment (D_Target)
13050 Source_Align : constant Uint := Alignment (D_Source);
13051 Target_Align : constant Uint := Alignment (D_Target);
13054 if Source_Align < Target_Align
13055 and then not Is_Tagged_Type (D_Source)
13057 -- Suppress warning if warnings suppressed on either
13058 -- type or either designated type. Note the use of
13059 -- OR here instead of OR ELSE. That is intentional,
13060 -- we would like to set flag Warnings_Off_Used in
13061 -- all types for which warnings are suppressed.
13063 and then not (Has_Warnings_Off (D_Source)
13065 Has_Warnings_Off (D_Target)
13067 Has_Warnings_Off (Source)
13069 Has_Warnings_Off (Target))
13071 Error_Msg_Uint_1 := Target_Align;
13072 Error_Msg_Uint_2 := Source_Align;
13073 Error_Msg_Node_1 := D_Target;
13074 Error_Msg_Node_2 := D_Source;
13076 ("?z?alignment of & (^) is stricter than "
13077 & "alignment of & (^)!", Eloc);
13079 ("\?z?resulting access value may have invalid "
13080 & "alignment!", Eloc);
13091 end Validate_Unchecked_Conversions;