1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2015, 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 freeze 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
=>
1134 -- Do not inherit aspect for anonymous base type of a
1135 -- scalar or array type, because they apply to the first
1136 -- subtype of the type, and will be processed when that
1137 -- first subtype is frozen.
1139 if Is_Derived_Type
(E
)
1140 and then not Comes_From_Source
(E
)
1141 and then E
/= First_Subtype
(E
)
1145 Analyze_Aspect_Default_Value
(ASN
);
1148 -- Ditto for iterator aspects, because the corresponding
1149 -- attributes may not have been analyzed yet.
1151 when Aspect_Constant_Indexing |
1152 Aspect_Variable_Indexing |
1153 Aspect_Default_Iterator |
1154 Aspect_Iterator_Element
=>
1155 Analyze
(Expression
(ASN
));
1157 if Etype
(Expression
(ASN
)) = Any_Type
then
1159 ("\aspect must be fully defined before & is frozen",
1163 when Aspect_Iterable
=>
1164 Validate_Iterable_Aspect
(E
, ASN
);
1170 Ritem
:= Aspect_Rep_Item
(ASN
);
1172 if Present
(Ritem
) then
1178 Next_Rep_Item
(ASN
);
1181 -- This is where we inherit delayed rep aspects from our parent. Note
1182 -- that if we fell out of the above loop with ASN non-empty, it means
1183 -- we hit an aspect for an entity other than E, and it must be the
1184 -- type from which we were derived.
1186 if May_Inherit_Delayed_Rep_Aspects
(E
) then
1187 Inherit_Delayed_Rep_Aspects
(ASN
);
1189 end Analyze_Aspects_At_Freeze_Point
;
1191 -----------------------------------
1192 -- Analyze_Aspect_Specifications --
1193 -----------------------------------
1195 procedure Analyze_Aspect_Specifications
(N
: Node_Id
; E
: Entity_Id
) is
1196 procedure Decorate
(Asp
: Node_Id
; Prag
: Node_Id
);
1197 -- Establish linkages between an aspect and its corresponding
1200 procedure Insert_After_SPARK_Mode
1204 -- Subsidiary to the analysis of aspects Abstract_State, Ghost,
1205 -- Initializes, Initial_Condition and Refined_State. Insert node Prag
1206 -- before node Ins_Nod. If Ins_Nod is for pragma SPARK_Mode, then skip
1207 -- SPARK_Mode. Decls is the associated declarative list where Prag is to
1210 procedure Insert_Pragma
(Prag
: Node_Id
);
1211 -- Subsidiary to the analysis of aspects Attach_Handler, Contract_Cases,
1212 -- Depends, Global, Post, Pre, Refined_Depends and Refined_Global.
1213 -- Insert pragma Prag such that it mimics the placement of a source
1214 -- pragma of the same kind.
1216 -- procedure Proc (Formal : ...) with Global => ...;
1218 -- procedure Proc (Formal : ...);
1219 -- pragma Global (...);
1225 procedure Decorate
(Asp
: Node_Id
; Prag
: Node_Id
) is
1227 Set_Aspect_Rep_Item
(Asp
, Prag
);
1228 Set_Corresponding_Aspect
(Prag
, Asp
);
1229 Set_From_Aspect_Specification
(Prag
);
1230 Set_Parent
(Prag
, Asp
);
1233 -----------------------------
1234 -- Insert_After_SPARK_Mode --
1235 -----------------------------
1237 procedure Insert_After_SPARK_Mode
1242 Decl
: Node_Id
:= Ins_Nod
;
1248 and then Nkind
(Decl
) = N_Pragma
1249 and then Pragma_Name
(Decl
) = Name_SPARK_Mode
1251 Decl
:= Next
(Decl
);
1254 if Present
(Decl
) then
1255 Insert_Before
(Decl
, Prag
);
1257 -- Aitem acts as the last declaration
1260 Append_To
(Decls
, Prag
);
1262 end Insert_After_SPARK_Mode
;
1268 procedure Insert_Pragma
(Prag
: Node_Id
) is
1273 if Nkind
(N
) = N_Subprogram_Body
then
1274 if Present
(Declarations
(N
)) then
1276 -- Skip other internally generated pragmas from aspects to find
1277 -- the proper insertion point. As a result the order of pragmas
1278 -- is the same as the order of aspects.
1280 -- As precondition pragmas generated from conjuncts in the
1281 -- precondition aspect are presented in reverse order to
1282 -- Insert_Pragma, insert them in the correct order here by not
1283 -- skipping previously inserted precondition pragmas when the
1284 -- current pragma is a precondition.
1286 Decl
:= First
(Declarations
(N
));
1287 while Present
(Decl
) loop
1288 if Nkind
(Decl
) = N_Pragma
1289 and then From_Aspect_Specification
(Decl
)
1290 and then not (Get_Pragma_Id
(Decl
) = Pragma_Precondition
1292 Get_Pragma_Id
(Prag
) = Pragma_Precondition
)
1300 if Present
(Decl
) then
1301 Insert_Before
(Decl
, Prag
);
1303 Append
(Prag
, Declarations
(N
));
1306 Set_Declarations
(N
, New_List
(Prag
));
1309 -- When the context is a library unit, the pragma is added to the
1310 -- Pragmas_After list.
1312 elsif Nkind
(Parent
(N
)) = N_Compilation_Unit
then
1313 Aux
:= Aux_Decls_Node
(Parent
(N
));
1315 if No
(Pragmas_After
(Aux
)) then
1316 Set_Pragmas_After
(Aux
, New_List
);
1319 Prepend
(Prag
, Pragmas_After
(Aux
));
1324 Insert_After
(N
, Prag
);
1334 L
: constant List_Id
:= Aspect_Specifications
(N
);
1336 Ins_Node
: Node_Id
:= N
;
1337 -- Insert pragmas/attribute definition clause after this node when no
1338 -- delayed analysis is required.
1340 -- Start of processing for Analyze_Aspect_Specifications
1342 -- The general processing involves building an attribute definition
1343 -- clause or a pragma node that corresponds to the aspect. Then in order
1344 -- to delay the evaluation of this aspect to the freeze point, we attach
1345 -- the corresponding pragma/attribute definition clause to the aspect
1346 -- specification node, which is then placed in the Rep Item chain. In
1347 -- this case we mark the entity by setting the flag Has_Delayed_Aspects
1348 -- and we evaluate the rep item at the freeze point. When the aspect
1349 -- doesn't have a corresponding pragma/attribute definition clause, then
1350 -- its analysis is simply delayed at the freeze point.
1352 -- Some special cases don't require delay analysis, thus the aspect is
1353 -- analyzed right now.
1355 -- Note that there is a special handling for Pre, Post, Test_Case,
1356 -- Contract_Cases aspects. In these cases, we do not have to worry
1357 -- about delay issues, since the pragmas themselves deal with delay
1358 -- of visibility for the expression analysis. Thus, we just insert
1359 -- the pragma after the node N.
1362 pragma Assert
(Present
(L
));
1364 -- Loop through aspects
1366 Aspect
:= First
(L
);
1367 Aspect_Loop
: while Present
(Aspect
) loop
1368 Analyze_One_Aspect
: declare
1369 Expr
: constant Node_Id
:= Expression
(Aspect
);
1370 Id
: constant Node_Id
:= Identifier
(Aspect
);
1371 Loc
: constant Source_Ptr
:= Sloc
(Aspect
);
1372 Nam
: constant Name_Id
:= Chars
(Id
);
1373 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Nam
);
1376 Delay_Required
: Boolean;
1377 -- Set False if delay is not required
1379 Eloc
: Source_Ptr
:= No_Location
;
1380 -- Source location of expression, modified when we split PPC's. It
1381 -- is set below when Expr is present.
1383 procedure Analyze_Aspect_External_Or_Link_Name
;
1384 -- Perform analysis of the External_Name or Link_Name aspects
1386 procedure Analyze_Aspect_Implicit_Dereference
;
1387 -- Perform analysis of the Implicit_Dereference aspects
1389 procedure Make_Aitem_Pragma
1390 (Pragma_Argument_Associations
: List_Id
;
1391 Pragma_Name
: Name_Id
);
1392 -- This is a wrapper for Make_Pragma used for converting aspects
1393 -- to pragmas. It takes care of Sloc (set from Loc) and building
1394 -- the pragma identifier from the given name. In addition the
1395 -- flags Class_Present and Split_PPC are set from the aspect
1396 -- node, as well as Is_Ignored. This routine also sets the
1397 -- From_Aspect_Specification in the resulting pragma node to
1398 -- True, and sets Corresponding_Aspect to point to the aspect.
1399 -- The resulting pragma is assigned to Aitem.
1401 ------------------------------------------
1402 -- Analyze_Aspect_External_Or_Link_Name --
1403 ------------------------------------------
1405 procedure Analyze_Aspect_External_Or_Link_Name
is
1407 -- Verify that there is an Import/Export aspect defined for the
1408 -- entity. The processing of that aspect in turn checks that
1409 -- there is a Convention aspect declared. The pragma is
1410 -- constructed when processing the Convention aspect.
1417 while Present
(A
) loop
1418 exit when Nam_In
(Chars
(Identifier
(A
)), Name_Export
,
1425 ("missing Import/Export for Link/External name",
1429 end Analyze_Aspect_External_Or_Link_Name
;
1431 -----------------------------------------
1432 -- Analyze_Aspect_Implicit_Dereference --
1433 -----------------------------------------
1435 procedure Analyze_Aspect_Implicit_Dereference
is
1437 if not Is_Type
(E
) or else not Has_Discriminants
(E
) then
1439 ("aspect must apply to a type with discriminants", N
);
1446 Disc
:= First_Discriminant
(E
);
1447 while Present
(Disc
) loop
1448 if Chars
(Expr
) = Chars
(Disc
)
1449 and then Ekind
(Etype
(Disc
)) =
1450 E_Anonymous_Access_Type
1452 Set_Has_Implicit_Dereference
(E
);
1453 Set_Has_Implicit_Dereference
(Disc
);
1457 Next_Discriminant
(Disc
);
1460 -- Error if no proper access discriminant.
1463 ("not an access discriminant of&", Expr
, E
);
1466 end Analyze_Aspect_Implicit_Dereference
;
1468 -----------------------
1469 -- Make_Aitem_Pragma --
1470 -----------------------
1472 procedure Make_Aitem_Pragma
1473 (Pragma_Argument_Associations
: List_Id
;
1474 Pragma_Name
: Name_Id
)
1476 Args
: List_Id
:= Pragma_Argument_Associations
;
1479 -- We should never get here if aspect was disabled
1481 pragma Assert
(not Is_Disabled
(Aspect
));
1483 -- Certain aspects allow for an optional name or expression. Do
1484 -- not generate a pragma with empty argument association list.
1486 if No
(Args
) or else No
(Expression
(First
(Args
))) then
1494 Pragma_Argument_Associations
=> Args
,
1495 Pragma_Identifier
=>
1496 Make_Identifier
(Sloc
(Id
), Pragma_Name
),
1497 Class_Present
=> Class_Present
(Aspect
),
1498 Split_PPC
=> Split_PPC
(Aspect
));
1500 -- Set additional semantic fields
1502 if Is_Ignored
(Aspect
) then
1503 Set_Is_Ignored
(Aitem
);
1504 elsif Is_Checked
(Aspect
) then
1505 Set_Is_Checked
(Aitem
);
1508 Set_Corresponding_Aspect
(Aitem
, Aspect
);
1509 Set_From_Aspect_Specification
(Aitem
, True);
1510 end Make_Aitem_Pragma
;
1512 -- Start of processing for Analyze_One_Aspect
1515 -- Skip aspect if already analyzed, to avoid looping in some cases
1517 if Analyzed
(Aspect
) then
1521 -- Skip looking at aspect if it is totally disabled. Just mark it
1522 -- as such for later reference in the tree. This also sets the
1523 -- Is_Ignored and Is_Checked flags appropriately.
1525 Check_Applicable_Policy
(Aspect
);
1527 if Is_Disabled
(Aspect
) then
1531 -- Set the source location of expression, used in the case of
1532 -- a failed precondition/postcondition or invariant. Note that
1533 -- the source location of the expression is not usually the best
1534 -- choice here. For example, it gets located on the last AND
1535 -- keyword in a chain of boolean expressiond AND'ed together.
1536 -- It is best to put the message on the first character of the
1537 -- assertion, which is the effect of the First_Node call here.
1539 if Present
(Expr
) then
1540 Eloc
:= Sloc
(First_Node
(Expr
));
1543 -- Check restriction No_Implementation_Aspect_Specifications
1545 if Implementation_Defined_Aspect
(A_Id
) then
1547 (No_Implementation_Aspect_Specifications
, Aspect
);
1550 -- Check restriction No_Specification_Of_Aspect
1552 Check_Restriction_No_Specification_Of_Aspect
(Aspect
);
1554 -- Mark aspect analyzed (actual analysis is delayed till later)
1556 Set_Analyzed
(Aspect
);
1557 Set_Entity
(Aspect
, E
);
1558 Ent
:= New_Occurrence_Of
(E
, Sloc
(Id
));
1560 -- Check for duplicate aspect. Note that the Comes_From_Source
1561 -- test allows duplicate Pre/Post's that we generate internally
1562 -- to escape being flagged here.
1564 if No_Duplicates_Allowed
(A_Id
) then
1566 while Anod
/= Aspect
loop
1567 if Comes_From_Source
(Aspect
)
1568 and then Same_Aspect
(A_Id
, Get_Aspect_Id
(Anod
))
1570 Error_Msg_Name_1
:= Nam
;
1571 Error_Msg_Sloc
:= Sloc
(Anod
);
1573 -- Case of same aspect specified twice
1575 if Class_Present
(Anod
) = Class_Present
(Aspect
) then
1576 if not Class_Present
(Anod
) then
1578 ("aspect% for & previously given#",
1582 ("aspect `%''Class` for & previously given#",
1592 -- Check some general restrictions on language defined aspects
1594 if not Implementation_Defined_Aspect
(A_Id
) then
1595 Error_Msg_Name_1
:= Nam
;
1597 -- Not allowed for renaming declarations
1599 if Nkind
(N
) in N_Renaming_Declaration
then
1601 ("aspect % not allowed for renaming declaration",
1605 -- Not allowed for formal type declarations
1607 if Nkind
(N
) = N_Formal_Type_Declaration
then
1609 ("aspect % not allowed for formal type declaration",
1614 -- Copy expression for later processing by the procedures
1615 -- Check_Aspect_At_[Freeze_Point | End_Of_Declarations]
1617 Set_Entity
(Id
, New_Copy_Tree
(Expr
));
1619 -- Set Delay_Required as appropriate to aspect
1621 case Aspect_Delay
(A_Id
) is
1622 when Always_Delay
=>
1623 Delay_Required
:= True;
1626 Delay_Required
:= False;
1630 -- If expression has the form of an integer literal, then
1631 -- do not delay, since we know the value cannot change.
1632 -- This optimization catches most rep clause cases.
1634 -- For Boolean aspects, don't delay if no expression
1636 if A_Id
in Boolean_Aspects
and then No
(Expr
) then
1637 Delay_Required
:= False;
1639 -- For non-Boolean aspects, don't delay if integer literal
1641 elsif A_Id
not in Boolean_Aspects
1642 and then Present
(Expr
)
1643 and then Nkind
(Expr
) = N_Integer_Literal
1645 Delay_Required
:= False;
1647 -- All other cases are delayed
1650 Delay_Required
:= True;
1651 Set_Has_Delayed_Rep_Aspects
(E
);
1655 -- Processing based on specific aspect
1658 when Aspect_Unimplemented
=>
1659 null; -- ??? temp for now
1661 -- No_Aspect should be impossible
1664 raise Program_Error
;
1666 -- Case 1: Aspects corresponding to attribute definition
1669 when Aspect_Address |
1672 Aspect_Component_Size |
1673 Aspect_Constant_Indexing |
1674 Aspect_Default_Iterator |
1675 Aspect_Dispatching_Domain |
1676 Aspect_External_Tag |
1679 Aspect_Iterator_Element |
1680 Aspect_Machine_Radix |
1681 Aspect_Object_Size |
1684 Aspect_Scalar_Storage_Order |
1687 Aspect_Simple_Storage_Pool |
1688 Aspect_Storage_Pool |
1689 Aspect_Stream_Size |
1691 Aspect_Variable_Indexing |
1694 -- Indexing aspects apply only to tagged type
1696 if (A_Id
= Aspect_Constant_Indexing
1698 A_Id
= Aspect_Variable_Indexing
)
1699 and then not (Is_Type
(E
)
1700 and then Is_Tagged_Type
(E
))
1703 ("indexing aspect can only apply to a tagged type",
1708 -- For the case of aspect Address, we don't consider that we
1709 -- know the entity is never set in the source, since it is
1710 -- is likely aliasing is occurring.
1712 -- Note: one might think that the analysis of the resulting
1713 -- attribute definition clause would take care of that, but
1714 -- that's not the case since it won't be from source.
1716 if A_Id
= Aspect_Address
then
1717 Set_Never_Set_In_Source
(E
, False);
1720 -- Correctness of the profile of a stream operation is
1721 -- verified at the freeze point, but we must detect the
1722 -- illegal specification of this aspect for a subtype now,
1723 -- to prevent malformed rep_item chains.
1725 if A_Id
= Aspect_Input
or else
1726 A_Id
= Aspect_Output
or else
1727 A_Id
= Aspect_Read
or else
1730 if not Is_First_Subtype
(E
) then
1732 ("local name must be a first subtype", Aspect
);
1735 -- If stream aspect applies to the class-wide type,
1736 -- the generated attribute definition applies to the
1737 -- class-wide type as well.
1739 elsif Class_Present
(Aspect
) then
1741 Make_Attribute_Reference
(Loc
,
1743 Attribute_Name
=> Name_Class
);
1747 -- Construct the attribute definition clause
1750 Make_Attribute_Definition_Clause
(Loc
,
1752 Chars
=> Chars
(Id
),
1753 Expression
=> Relocate_Node
(Expr
));
1755 -- If the address is specified, then we treat the entity as
1756 -- referenced, to avoid spurious warnings. This is analogous
1757 -- to what is done with an attribute definition clause, but
1758 -- here we don't want to generate a reference because this
1759 -- is the point of definition of the entity.
1761 if A_Id
= Aspect_Address
then
1765 -- Case 2: Aspects corresponding to pragmas
1767 -- Case 2a: Aspects corresponding to pragmas with two
1768 -- arguments, where the first argument is a local name
1769 -- referring to the entity, and the second argument is the
1770 -- aspect definition expression.
1772 -- Linker_Section/Suppress/Unsuppress
1774 when Aspect_Linker_Section |
1776 Aspect_Unsuppress
=>
1779 (Pragma_Argument_Associations
=> New_List
(
1780 Make_Pragma_Argument_Association
(Loc
,
1781 Expression
=> New_Occurrence_Of
(E
, Loc
)),
1782 Make_Pragma_Argument_Association
(Sloc
(Expr
),
1783 Expression
=> Relocate_Node
(Expr
))),
1784 Pragma_Name
=> Chars
(Id
));
1788 -- Corresponds to pragma Implemented, construct the pragma
1790 when Aspect_Synchronization
=>
1792 (Pragma_Argument_Associations
=> New_List
(
1793 Make_Pragma_Argument_Association
(Loc
,
1794 Expression
=> New_Occurrence_Of
(E
, Loc
)),
1795 Make_Pragma_Argument_Association
(Sloc
(Expr
),
1796 Expression
=> Relocate_Node
(Expr
))),
1797 Pragma_Name
=> Name_Implemented
);
1801 when Aspect_Attach_Handler
=>
1803 (Pragma_Argument_Associations
=> New_List
(
1804 Make_Pragma_Argument_Association
(Sloc
(Ent
),
1806 Make_Pragma_Argument_Association
(Sloc
(Expr
),
1807 Expression
=> Relocate_Node
(Expr
))),
1808 Pragma_Name
=> Name_Attach_Handler
);
1810 -- We need to insert this pragma into the tree to get proper
1811 -- processing and to look valid from a placement viewpoint.
1813 Insert_Pragma
(Aitem
);
1816 -- Dynamic_Predicate, Predicate, Static_Predicate
1818 when Aspect_Dynamic_Predicate |
1820 Aspect_Static_Predicate
=>
1822 -- These aspects apply only to subtypes
1824 if not Is_Type
(E
) then
1826 ("predicate can only be specified for a subtype",
1830 elsif Is_Incomplete_Type
(E
) then
1832 ("predicate cannot apply to incomplete view", Aspect
);
1836 -- Construct the pragma (always a pragma Predicate, with
1837 -- flags recording whether it is static/dynamic). We also
1838 -- set flags recording this in the type itself.
1841 (Pragma_Argument_Associations
=> New_List
(
1842 Make_Pragma_Argument_Association
(Sloc
(Ent
),
1844 Make_Pragma_Argument_Association
(Sloc
(Expr
),
1845 Expression
=> Relocate_Node
(Expr
))),
1846 Pragma_Name
=> Name_Predicate
);
1848 -- Mark type has predicates, and remember what kind of
1849 -- aspect lead to this predicate (we need this to access
1850 -- the right set of check policies later on).
1852 Set_Has_Predicates
(E
);
1854 if A_Id
= Aspect_Dynamic_Predicate
then
1855 Set_Has_Dynamic_Predicate_Aspect
(E
);
1856 elsif A_Id
= Aspect_Static_Predicate
then
1857 Set_Has_Static_Predicate_Aspect
(E
);
1860 -- If the type is private, indicate that its completion
1861 -- has a freeze node, because that is the one that will
1862 -- be visible at freeze time.
1864 if Is_Private_Type
(E
) and then Present
(Full_View
(E
)) then
1865 Set_Has_Predicates
(Full_View
(E
));
1867 if A_Id
= Aspect_Dynamic_Predicate
then
1868 Set_Has_Dynamic_Predicate_Aspect
(Full_View
(E
));
1869 elsif A_Id
= Aspect_Static_Predicate
then
1870 Set_Has_Static_Predicate_Aspect
(Full_View
(E
));
1873 Set_Has_Delayed_Aspects
(Full_View
(E
));
1874 Ensure_Freeze_Node
(Full_View
(E
));
1877 -- Case 2b: Aspects corresponding to pragmas with two
1878 -- arguments, where the second argument is a local name
1879 -- referring to the entity, and the first argument is the
1880 -- aspect definition expression.
1884 when Aspect_Convention
=>
1886 -- The aspect may be part of the specification of an import
1887 -- or export pragma. Scan the aspect list to gather the
1888 -- other components, if any. The name of the generated
1889 -- pragma is one of Convention/Import/Export.
1892 Args
: constant List_Id
:= New_List
(
1893 Make_Pragma_Argument_Association
(Sloc
(Expr
),
1894 Expression
=> Relocate_Node
(Expr
)),
1895 Make_Pragma_Argument_Association
(Sloc
(Ent
),
1896 Expression
=> Ent
));
1898 Imp_Exp_Seen
: Boolean := False;
1899 -- Flag set when aspect Import or Export has been seen
1901 Imp_Seen
: Boolean := False;
1902 -- Flag set when aspect Import has been seen
1906 Extern_Arg
: Node_Id
;
1911 Extern_Arg
:= Empty
;
1913 Prag_Nam
:= Chars
(Id
);
1916 while Present
(Asp
) loop
1917 Asp_Nam
:= Chars
(Identifier
(Asp
));
1919 -- Aspects Import and Export take precedence over
1920 -- aspect Convention. As a result the generated pragma
1921 -- must carry the proper interfacing aspect's name.
1923 if Nam_In
(Asp_Nam
, Name_Import
, Name_Export
) then
1924 if Imp_Exp_Seen
then
1925 Error_Msg_N
("conflicting", Asp
);
1927 Imp_Exp_Seen
:= True;
1929 if Asp_Nam
= Name_Import
then
1934 Prag_Nam
:= Asp_Nam
;
1936 -- Aspect External_Name adds an extra argument to the
1937 -- generated pragma.
1939 elsif Asp_Nam
= Name_External_Name
then
1941 Make_Pragma_Argument_Association
(Loc
,
1943 Expression
=> Relocate_Node
(Expression
(Asp
)));
1945 -- Aspect Link_Name adds an extra argument to the
1946 -- generated pragma.
1948 elsif Asp_Nam
= Name_Link_Name
then
1950 Make_Pragma_Argument_Association
(Loc
,
1952 Expression
=> Relocate_Node
(Expression
(Asp
)));
1958 -- Assemble the full argument list
1960 if Present
(Extern_Arg
) then
1961 Append_To
(Args
, Extern_Arg
);
1964 if Present
(Link_Arg
) then
1965 Append_To
(Args
, Link_Arg
);
1969 (Pragma_Argument_Associations
=> Args
,
1970 Pragma_Name
=> Prag_Nam
);
1972 -- Store the generated pragma Import in the related
1975 if Imp_Seen
and then Is_Subprogram
(E
) then
1976 Set_Import_Pragma
(E
, Aitem
);
1980 -- CPU, Interrupt_Priority, Priority
1982 -- These three aspects can be specified for a subprogram spec
1983 -- or body, in which case we analyze the expression and export
1984 -- the value of the aspect.
1986 -- Previously, we generated an equivalent pragma for bodies
1987 -- (note that the specs cannot contain these pragmas). The
1988 -- pragma was inserted ahead of local declarations, rather than
1989 -- after the body. This leads to a certain duplication between
1990 -- the processing performed for the aspect and the pragma, but
1991 -- given the straightforward handling required it is simpler
1992 -- to duplicate than to translate the aspect in the spec into
1993 -- a pragma in the declarative part of the body.
1996 Aspect_Interrupt_Priority |
1999 if Nkind_In
(N
, N_Subprogram_Body
,
2000 N_Subprogram_Declaration
)
2002 -- Analyze the aspect expression
2004 Analyze_And_Resolve
(Expr
, Standard_Integer
);
2006 -- Interrupt_Priority aspect not allowed for main
2007 -- subprograms. ARM D.1 does not forbid this explicitly,
2008 -- but ARM J.15.11 (6/3) does not permit pragma
2009 -- Interrupt_Priority for subprograms.
2011 if A_Id
= Aspect_Interrupt_Priority
then
2013 ("Interrupt_Priority aspect cannot apply to "
2014 & "subprogram", Expr
);
2016 -- The expression must be static
2018 elsif not Is_OK_Static_Expression
(Expr
) then
2019 Flag_Non_Static_Expr
2020 ("aspect requires static expression!", Expr
);
2022 -- Check whether this is the main subprogram. Issue a
2023 -- warning only if it is obviously not a main program
2024 -- (when it has parameters or when the subprogram is
2025 -- within a package).
2027 elsif Present
(Parameter_Specifications
2028 (Specification
(N
)))
2029 or else not Is_Compilation_Unit
(Defining_Entity
(N
))
2031 -- See ARM D.1 (14/3) and D.16 (12/3)
2034 ("aspect applied to subprogram other than the "
2035 & "main subprogram has no effect??", Expr
);
2037 -- Otherwise check in range and export the value
2039 -- For the CPU aspect
2041 elsif A_Id
= Aspect_CPU
then
2042 if Is_In_Range
(Expr
, RTE
(RE_CPU_Range
)) then
2044 -- Value is correct so we export the value to make
2045 -- it available at execution time.
2048 (Main_Unit
, UI_To_Int
(Expr_Value
(Expr
)));
2052 ("main subprogram CPU is out of range", Expr
);
2055 -- For the Priority aspect
2057 elsif A_Id
= Aspect_Priority
then
2058 if Is_In_Range
(Expr
, RTE
(RE_Priority
)) then
2060 -- Value is correct so we export the value to make
2061 -- it available at execution time.
2064 (Main_Unit
, UI_To_Int
(Expr_Value
(Expr
)));
2066 -- Ignore pragma if Relaxed_RM_Semantics to support
2067 -- other targets/non GNAT compilers.
2069 elsif not Relaxed_RM_Semantics
then
2071 ("main subprogram priority is out of range",
2076 -- Load an arbitrary entity from System.Tasking.Stages
2077 -- or System.Tasking.Restricted.Stages (depending on
2078 -- the supported profile) to make sure that one of these
2079 -- packages is implicitly with'ed, since we need to have
2080 -- the tasking run time active for the pragma Priority to
2081 -- have any effect. Previously we with'ed the package
2082 -- System.Tasking, but this package does not trigger the
2083 -- required initialization of the run-time library.
2086 Discard
: Entity_Id
;
2088 if Restricted_Profile
then
2089 Discard
:= RTE
(RE_Activate_Restricted_Tasks
);
2091 Discard
:= RTE
(RE_Activate_Tasks
);
2095 -- Handling for these Aspects in subprograms is complete
2102 -- Pass the aspect as an attribute
2105 Make_Attribute_Definition_Clause
(Loc
,
2107 Chars
=> Chars
(Id
),
2108 Expression
=> Relocate_Node
(Expr
));
2113 when Aspect_Warnings
=>
2115 (Pragma_Argument_Associations
=> New_List
(
2116 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2117 Expression
=> Relocate_Node
(Expr
)),
2118 Make_Pragma_Argument_Association
(Loc
,
2119 Expression
=> New_Occurrence_Of
(E
, Loc
))),
2120 Pragma_Name
=> Chars
(Id
));
2122 -- Case 2c: Aspects corresponding to pragmas with three
2125 -- Invariant aspects have a first argument that references the
2126 -- entity, a second argument that is the expression and a third
2127 -- argument that is an appropriate message.
2129 -- Invariant, Type_Invariant
2131 when Aspect_Invariant |
2132 Aspect_Type_Invariant
=>
2134 -- Analysis of the pragma will verify placement legality:
2135 -- an invariant must apply to a private type, or appear in
2136 -- the private part of a spec and apply to a completion.
2139 (Pragma_Argument_Associations
=> New_List
(
2140 Make_Pragma_Argument_Association
(Sloc
(Ent
),
2142 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2143 Expression
=> Relocate_Node
(Expr
))),
2144 Pragma_Name
=> Name_Invariant
);
2146 -- Add message unless exception messages are suppressed
2148 if not Opt
.Exception_Locations_Suppressed
then
2149 Append_To
(Pragma_Argument_Associations
(Aitem
),
2150 Make_Pragma_Argument_Association
(Eloc
,
2151 Chars
=> Name_Message
,
2153 Make_String_Literal
(Eloc
,
2154 Strval
=> "failed invariant from "
2155 & Build_Location_String
(Eloc
))));
2158 -- For Invariant case, insert immediately after the entity
2159 -- declaration. We do not have to worry about delay issues
2160 -- since the pragma processing takes care of this.
2162 Delay_Required
:= False;
2164 -- Case 2d : Aspects that correspond to a pragma with one
2169 -- Aspect Abstract_State introduces implicit declarations for
2170 -- all state abstraction entities it defines. To emulate this
2171 -- behavior, insert the pragma at the beginning of the visible
2172 -- declarations of the related package so that it is analyzed
2175 when Aspect_Abstract_State
=> Abstract_State
: declare
2176 Context
: Node_Id
:= N
;
2181 -- When aspect Abstract_State appears on a generic package,
2182 -- it is propageted to the package instance. The context in
2183 -- this case is the instance spec.
2185 if Nkind
(Context
) = N_Package_Instantiation
then
2186 Context
:= Instance_Spec
(Context
);
2189 if Nkind_In
(Context
, N_Generic_Package_Declaration
,
2190 N_Package_Declaration
)
2193 (Pragma_Argument_Associations
=> New_List
(
2194 Make_Pragma_Argument_Association
(Loc
,
2195 Expression
=> Relocate_Node
(Expr
))),
2196 Pragma_Name
=> Name_Abstract_State
);
2197 Decorate
(Aspect
, Aitem
);
2199 Decls
:= Visible_Declarations
(Specification
(Context
));
2201 -- In general pragma Abstract_State must be at the top
2202 -- of the existing visible declarations to emulate its
2203 -- source counterpart. The only exception to this is a
2204 -- generic instance in which case the pragma must be
2205 -- inserted after the association renamings.
2207 if Present
(Decls
) then
2208 Decl
:= First
(Decls
);
2210 -- The visible declarations of a generic instance have
2211 -- the following structure:
2213 -- <renamings of generic formals>
2214 -- <renamings of internally-generated spec and body>
2215 -- <first source declaration>
2217 -- The pragma must be inserted before the first source
2218 -- declaration, skip the instance "header".
2220 if Is_Generic_Instance
(Defining_Entity
(Context
)) then
2221 while Present
(Decl
)
2222 and then not Comes_From_Source
(Decl
)
2224 Decl
:= Next
(Decl
);
2228 -- When aspects Abstract_State, Ghost,
2229 -- Initial_Condition and Initializes are out of order,
2230 -- ensure that pragma SPARK_Mode is always at the top
2231 -- of the declarations to properly enabled/suppress
2234 Insert_After_SPARK_Mode
2239 -- Otherwise the pragma forms a new declarative list
2242 Set_Visible_Declarations
2243 (Specification
(Context
), New_List
(Aitem
));
2248 ("aspect & must apply to a package declaration",
2255 -- Aspect Default_Internal_Condition is never delayed because
2256 -- it is equivalent to a source pragma which appears after the
2257 -- related private type. To deal with forward references, the
2258 -- generated pragma is stored in the rep chain of the related
2259 -- private type as types do not carry contracts. The pragma is
2260 -- wrapped inside of a procedure at the freeze point of the
2261 -- private type's full view.
2263 when Aspect_Default_Initial_Condition
=>
2265 (Pragma_Argument_Associations
=> New_List
(
2266 Make_Pragma_Argument_Association
(Loc
,
2267 Expression
=> Relocate_Node
(Expr
))),
2269 Name_Default_Initial_Condition
);
2271 Decorate
(Aspect
, Aitem
);
2272 Insert_Pragma
(Aitem
);
2275 -- Default_Storage_Pool
2277 when Aspect_Default_Storage_Pool
=>
2279 (Pragma_Argument_Associations
=> New_List
(
2280 Make_Pragma_Argument_Association
(Loc
,
2281 Expression
=> Relocate_Node
(Expr
))),
2283 Name_Default_Storage_Pool
);
2285 Decorate
(Aspect
, Aitem
);
2286 Insert_Pragma
(Aitem
);
2291 -- Aspect Depends is never delayed because it is equivalent to
2292 -- a source pragma which appears after the related subprogram.
2293 -- To deal with forward references, the generated pragma is
2294 -- stored in the contract of the related subprogram and later
2295 -- analyzed at the end of the declarative region. See routine
2296 -- Analyze_Depends_In_Decl_Part for details.
2298 when Aspect_Depends
=>
2300 (Pragma_Argument_Associations
=> New_List
(
2301 Make_Pragma_Argument_Association
(Loc
,
2302 Expression
=> Relocate_Node
(Expr
))),
2303 Pragma_Name
=> Name_Depends
);
2305 Decorate
(Aspect
, Aitem
);
2306 Insert_Pragma
(Aitem
);
2309 -- Aspect Extensions_Visible is never delayed because it is
2310 -- equivalent to a source pragma which appears after the
2311 -- related subprogram.
2313 when Aspect_Extensions_Visible
=>
2315 (Pragma_Argument_Associations
=> New_List
(
2316 Make_Pragma_Argument_Association
(Loc
,
2317 Expression
=> Relocate_Node
(Expr
))),
2318 Pragma_Name
=> Name_Extensions_Visible
);
2320 Decorate
(Aspect
, Aitem
);
2321 Insert_Pragma
(Aitem
);
2324 -- Aspect Ghost is never delayed because it is equivalent to a
2325 -- source pragma which appears at the top of [generic] package
2326 -- declarations or after an object, a [generic] subprogram, or
2327 -- a type declaration.
2329 when Aspect_Ghost
=> Ghost
: declare
2334 (Pragma_Argument_Associations
=> New_List
(
2335 Make_Pragma_Argument_Association
(Loc
,
2336 Expression
=> Relocate_Node
(Expr
))),
2337 Pragma_Name
=> Name_Ghost
);
2339 Decorate
(Aspect
, Aitem
);
2341 -- When the aspect applies to a [generic] package, insert
2342 -- the pragma at the top of the visible declarations. This
2343 -- emulates the placement of a source pragma.
2345 if Nkind_In
(N
, N_Generic_Package_Declaration
,
2346 N_Package_Declaration
)
2348 Decls
:= Visible_Declarations
(Specification
(N
));
2352 Set_Visible_Declarations
(N
, Decls
);
2355 -- When aspects Abstract_State, Ghost, Initial_Condition
2356 -- and Initializes are out of order, ensure that pragma
2357 -- SPARK_Mode is always at the top of the declarations to
2358 -- properly enabled/suppress errors.
2360 Insert_After_SPARK_Mode
2362 Ins_Nod
=> First
(Decls
),
2365 -- Otherwise the context is an object, [generic] subprogram
2366 -- or type declaration.
2369 Insert_Pragma
(Aitem
);
2377 -- Aspect Global is never delayed because it is equivalent to
2378 -- a source pragma which appears after the related subprogram.
2379 -- To deal with forward references, the generated pragma is
2380 -- stored in the contract of the related subprogram and later
2381 -- analyzed at the end of the declarative region. See routine
2382 -- Analyze_Global_In_Decl_Part for details.
2384 when Aspect_Global
=>
2386 (Pragma_Argument_Associations
=> New_List
(
2387 Make_Pragma_Argument_Association
(Loc
,
2388 Expression
=> Relocate_Node
(Expr
))),
2389 Pragma_Name
=> Name_Global
);
2391 Decorate
(Aspect
, Aitem
);
2392 Insert_Pragma
(Aitem
);
2395 -- Initial_Condition
2397 -- Aspect Initial_Condition is never delayed because it is
2398 -- equivalent to a source pragma which appears after the
2399 -- related package. To deal with forward references, the
2400 -- generated pragma is stored in the contract of the related
2401 -- package and later analyzed at the end of the declarative
2402 -- region. See routine Analyze_Initial_Condition_In_Decl_Part
2405 when Aspect_Initial_Condition
=> Initial_Condition
: declare
2406 Context
: Node_Id
:= N
;
2410 -- When aspect Initial_Condition appears on a generic
2411 -- package, it is propageted to the package instance. The
2412 -- context in this case is the instance spec.
2414 if Nkind
(Context
) = N_Package_Instantiation
then
2415 Context
:= Instance_Spec
(Context
);
2418 if Nkind_In
(Context
, N_Generic_Package_Declaration
,
2419 N_Package_Declaration
)
2421 Decls
:= Visible_Declarations
(Specification
(Context
));
2424 (Pragma_Argument_Associations
=> New_List
(
2425 Make_Pragma_Argument_Association
(Loc
,
2426 Expression
=> Relocate_Node
(Expr
))),
2428 Name_Initial_Condition
);
2429 Decorate
(Aspect
, Aitem
);
2433 Set_Visible_Declarations
(Context
, Decls
);
2436 -- When aspects Abstract_State, Ghost, Initial_Condition
2437 -- and Initializes are out of order, ensure that pragma
2438 -- SPARK_Mode is always at the top of the declarations to
2439 -- properly enabled/suppress errors.
2441 Insert_After_SPARK_Mode
2443 Ins_Nod
=> First
(Decls
),
2448 ("aspect & must apply to a package declaration",
2453 end Initial_Condition
;
2457 -- Aspect Initializes is never delayed because it is equivalent
2458 -- to a source pragma appearing after the related package. To
2459 -- deal with forward references, the generated pragma is stored
2460 -- in the contract of the related package and later analyzed at
2461 -- the end of the declarative region. For details, see routine
2462 -- Analyze_Initializes_In_Decl_Part.
2464 when Aspect_Initializes
=> Initializes
: declare
2465 Context
: Node_Id
:= N
;
2469 -- When aspect Initializes appears on a generic package,
2470 -- it is propageted to the package instance. The context
2471 -- in this case is the instance spec.
2473 if Nkind
(Context
) = N_Package_Instantiation
then
2474 Context
:= Instance_Spec
(Context
);
2477 if Nkind_In
(Context
, N_Generic_Package_Declaration
,
2478 N_Package_Declaration
)
2480 Decls
:= Visible_Declarations
(Specification
(Context
));
2483 (Pragma_Argument_Associations
=> New_List
(
2484 Make_Pragma_Argument_Association
(Loc
,
2485 Expression
=> Relocate_Node
(Expr
))),
2486 Pragma_Name
=> Name_Initializes
);
2487 Decorate
(Aspect
, Aitem
);
2491 Set_Visible_Declarations
(Context
, Decls
);
2494 -- When aspects Abstract_State, Ghost, Initial_Condition
2495 -- and Initializes are out of order, ensure that pragma
2496 -- SPARK_Mode is always at the top of the declarations to
2497 -- properly enabled/suppress errors.
2499 Insert_After_SPARK_Mode
2501 Ins_Nod
=> First
(Decls
),
2506 ("aspect & must apply to a package declaration",
2515 when Aspect_Obsolescent
=> declare
2523 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2524 Expression
=> Relocate_Node
(Expr
)));
2528 (Pragma_Argument_Associations
=> Args
,
2529 Pragma_Name
=> Chars
(Id
));
2534 when Aspect_Part_Of
=>
2535 if Nkind_In
(N
, N_Object_Declaration
,
2536 N_Package_Instantiation
)
2539 (Pragma_Argument_Associations
=> New_List
(
2540 Make_Pragma_Argument_Association
(Loc
,
2541 Expression
=> Relocate_Node
(Expr
))),
2542 Pragma_Name
=> Name_Part_Of
);
2546 ("aspect & must apply to a variable or package "
2547 & "instantiation", Aspect
, Id
);
2552 when Aspect_SPARK_Mode
=> SPARK_Mode
: declare
2557 (Pragma_Argument_Associations
=> New_List
(
2558 Make_Pragma_Argument_Association
(Loc
,
2559 Expression
=> Relocate_Node
(Expr
))),
2560 Pragma_Name
=> Name_SPARK_Mode
);
2562 -- When the aspect appears on a package or a subprogram
2563 -- body, insert the generated pragma at the top of the body
2564 -- declarations to emulate the behavior of a source pragma.
2566 if Nkind_In
(N
, N_Package_Body
, N_Subprogram_Body
) then
2567 Decorate
(Aspect
, Aitem
);
2569 Decls
:= Declarations
(N
);
2573 Set_Declarations
(N
, Decls
);
2576 Prepend_To
(Decls
, Aitem
);
2579 -- When the aspect is associated with a [generic] package
2580 -- declaration, insert the generated pragma at the top of
2581 -- the visible declarations to emulate the behavior of a
2584 elsif Nkind_In
(N
, N_Generic_Package_Declaration
,
2585 N_Package_Declaration
)
2587 Decorate
(Aspect
, Aitem
);
2589 Decls
:= Visible_Declarations
(Specification
(N
));
2593 Set_Visible_Declarations
(Specification
(N
), Decls
);
2596 Prepend_To
(Decls
, Aitem
);
2603 -- Aspect Refined_Depends is never delayed because it is
2604 -- equivalent to a source pragma which appears in the
2605 -- declarations of the related subprogram body. To deal with
2606 -- forward references, the generated pragma is stored in the
2607 -- contract of the related subprogram body and later analyzed
2608 -- at the end of the declarative region. For details, see
2609 -- routine Analyze_Refined_Depends_In_Decl_Part.
2611 when Aspect_Refined_Depends
=>
2613 (Pragma_Argument_Associations
=> New_List
(
2614 Make_Pragma_Argument_Association
(Loc
,
2615 Expression
=> Relocate_Node
(Expr
))),
2616 Pragma_Name
=> Name_Refined_Depends
);
2618 Decorate
(Aspect
, Aitem
);
2619 Insert_Pragma
(Aitem
);
2624 -- Aspect Refined_Global is never delayed because it is
2625 -- equivalent to a source pragma which appears in the
2626 -- declarations of the related subprogram body. To deal with
2627 -- forward references, the generated pragma is stored in the
2628 -- contract of the related subprogram body and later analyzed
2629 -- at the end of the declarative region. For details, see
2630 -- routine Analyze_Refined_Global_In_Decl_Part.
2632 when Aspect_Refined_Global
=>
2634 (Pragma_Argument_Associations
=> New_List
(
2635 Make_Pragma_Argument_Association
(Loc
,
2636 Expression
=> Relocate_Node
(Expr
))),
2637 Pragma_Name
=> Name_Refined_Global
);
2639 Decorate
(Aspect
, Aitem
);
2640 Insert_Pragma
(Aitem
);
2645 when Aspect_Refined_Post
=>
2647 (Pragma_Argument_Associations
=> New_List
(
2648 Make_Pragma_Argument_Association
(Loc
,
2649 Expression
=> Relocate_Node
(Expr
))),
2650 Pragma_Name
=> Name_Refined_Post
);
2654 when Aspect_Refined_State
=> Refined_State
: declare
2658 -- The corresponding pragma for Refined_State is inserted in
2659 -- the declarations of the related package body. This action
2660 -- synchronizes both the source and from-aspect versions of
2663 if Nkind
(N
) = N_Package_Body
then
2664 Decls
:= Declarations
(N
);
2667 (Pragma_Argument_Associations
=> New_List
(
2668 Make_Pragma_Argument_Association
(Loc
,
2669 Expression
=> Relocate_Node
(Expr
))),
2670 Pragma_Name
=> Name_Refined_State
);
2671 Decorate
(Aspect
, Aitem
);
2675 Set_Declarations
(N
, Decls
);
2678 -- Pragma Refined_State must be inserted after pragma
2679 -- SPARK_Mode in the tree. This ensures that any error
2680 -- messages dependent on SPARK_Mode will be properly
2681 -- enabled/suppressed.
2683 Insert_After_SPARK_Mode
2685 Ins_Nod
=> First
(Decls
),
2690 ("aspect & must apply to a package body", Aspect
, Id
);
2696 -- Relative_Deadline
2698 when Aspect_Relative_Deadline
=>
2700 (Pragma_Argument_Associations
=> New_List
(
2701 Make_Pragma_Argument_Association
(Loc
,
2702 Expression
=> Relocate_Node
(Expr
))),
2703 Pragma_Name
=> Name_Relative_Deadline
);
2705 -- If the aspect applies to a task, the corresponding pragma
2706 -- must appear within its declarations, not after.
2708 if Nkind
(N
) = N_Task_Type_Declaration
then
2714 if No
(Task_Definition
(N
)) then
2715 Set_Task_Definition
(N
,
2716 Make_Task_Definition
(Loc
,
2717 Visible_Declarations
=> New_List
,
2718 End_Label
=> Empty
));
2721 Def
:= Task_Definition
(N
);
2722 V
:= Visible_Declarations
(Def
);
2723 if not Is_Empty_List
(V
) then
2724 Insert_Before
(First
(V
), Aitem
);
2727 Set_Visible_Declarations
(Def
, New_List
(Aitem
));
2734 -- Case 2e: Annotate aspect
2736 when Aspect_Annotate
=>
2743 -- The argument can be a single identifier
2745 if Nkind
(Expr
) = N_Identifier
then
2747 -- One level of parens is allowed
2749 if Paren_Count
(Expr
) > 1 then
2750 Error_Msg_F
("extra parentheses ignored", Expr
);
2753 Set_Paren_Count
(Expr
, 0);
2755 -- Add the single item to the list
2757 Args
:= New_List
(Expr
);
2759 -- Otherwise we must have an aggregate
2761 elsif Nkind
(Expr
) = N_Aggregate
then
2763 -- Must be positional
2765 if Present
(Component_Associations
(Expr
)) then
2767 ("purely positional aggregate required", Expr
);
2771 -- Must not be parenthesized
2773 if Paren_Count
(Expr
) /= 0 then
2774 Error_Msg_F
("extra parentheses ignored", Expr
);
2777 -- List of arguments is list of aggregate expressions
2779 Args
:= Expressions
(Expr
);
2781 -- Anything else is illegal
2784 Error_Msg_F
("wrong form for Annotate aspect", Expr
);
2788 -- Prepare pragma arguments
2791 Arg
:= First
(Args
);
2792 while Present
(Arg
) loop
2794 Make_Pragma_Argument_Association
(Sloc
(Arg
),
2795 Expression
=> Relocate_Node
(Arg
)));
2800 Make_Pragma_Argument_Association
(Sloc
(Ent
),
2801 Chars
=> Name_Entity
,
2802 Expression
=> Ent
));
2805 (Pragma_Argument_Associations
=> Pargs
,
2806 Pragma_Name
=> Name_Annotate
);
2809 -- Case 3 : Aspects that don't correspond to pragma/attribute
2810 -- definition clause.
2812 -- Case 3a: The aspects listed below don't correspond to
2813 -- pragmas/attributes but do require delayed analysis.
2815 -- Default_Value can only apply to a scalar type
2817 when Aspect_Default_Value
=>
2818 if not Is_Scalar_Type
(E
) then
2820 ("aspect Default_Value must apply to a scalar type", N
);
2825 -- Default_Component_Value can only apply to an array type
2826 -- with scalar components.
2828 when Aspect_Default_Component_Value
=>
2829 if not (Is_Array_Type
(E
)
2830 and then Is_Scalar_Type
(Component_Type
(E
)))
2832 Error_Msg_N
("aspect Default_Component_Value can only "
2833 & "apply to an array of scalar components", N
);
2838 -- Case 3b: The aspects listed below don't correspond to
2839 -- pragmas/attributes and don't need delayed analysis.
2841 -- Implicit_Dereference
2843 -- For Implicit_Dereference, External_Name and Link_Name, only
2844 -- the legality checks are done during the analysis, thus no
2845 -- delay is required.
2847 when Aspect_Implicit_Dereference
=>
2848 Analyze_Aspect_Implicit_Dereference
;
2851 -- External_Name, Link_Name
2853 when Aspect_External_Name |
2855 Analyze_Aspect_External_Or_Link_Name
;
2860 when Aspect_Dimension
=>
2861 Analyze_Aspect_Dimension
(N
, Id
, Expr
);
2866 when Aspect_Dimension_System
=>
2867 Analyze_Aspect_Dimension_System
(N
, Id
, Expr
);
2870 -- Case 4: Aspects requiring special handling
2872 -- Pre/Post/Test_Case/Contract_Cases whose corresponding
2873 -- pragmas take care of the delay.
2877 -- Aspects Pre/Post generate Precondition/Postcondition pragmas
2878 -- with a first argument that is the expression, and a second
2879 -- argument that is an informative message if the test fails.
2880 -- This is inserted right after the declaration, to get the
2881 -- required pragma placement. The processing for the pragmas
2882 -- takes care of the required delay.
2884 when Pre_Post_Aspects
=> Pre_Post
: declare
2888 if A_Id
= Aspect_Pre
or else A_Id
= Aspect_Precondition
then
2889 Pname
:= Name_Precondition
;
2891 Pname
:= Name_Postcondition
;
2894 -- If the expressions is of the form A and then B, then
2895 -- we generate separate Pre/Post aspects for the separate
2896 -- clauses. Since we allow multiple pragmas, there is no
2897 -- problem in allowing multiple Pre/Post aspects internally.
2898 -- These should be treated in reverse order (B first and
2899 -- A second) since they are later inserted just after N in
2900 -- the order they are treated. This way, the pragma for A
2901 -- ends up preceding the pragma for B, which may have an
2902 -- importance for the error raised (either constraint error
2903 -- or precondition error).
2905 -- We do not do this for Pre'Class, since we have to put
2906 -- these conditions together in a complex OR expression.
2908 -- We do not do this in ASIS mode, as ASIS relies on the
2909 -- original node representing the complete expression, when
2910 -- retrieving it through the source aspect table.
2913 and then (Pname
= Name_Postcondition
2914 or else not Class_Present
(Aspect
))
2916 while Nkind
(Expr
) = N_And_Then
loop
2917 Insert_After
(Aspect
,
2918 Make_Aspect_Specification
(Sloc
(Left_Opnd
(Expr
)),
2919 Identifier
=> Identifier
(Aspect
),
2920 Expression
=> Relocate_Node
(Left_Opnd
(Expr
)),
2921 Class_Present
=> Class_Present
(Aspect
),
2922 Split_PPC
=> True));
2923 Rewrite
(Expr
, Relocate_Node
(Right_Opnd
(Expr
)));
2924 Eloc
:= Sloc
(Expr
);
2928 -- Build the precondition/postcondition pragma
2930 -- Add note about why we do NOT need Copy_Tree here???
2933 (Pragma_Argument_Associations
=> New_List
(
2934 Make_Pragma_Argument_Association
(Eloc
,
2935 Chars
=> Name_Check
,
2936 Expression
=> Relocate_Node
(Expr
))),
2937 Pragma_Name
=> Pname
);
2939 -- Add message unless exception messages are suppressed
2941 if not Opt
.Exception_Locations_Suppressed
then
2942 Append_To
(Pragma_Argument_Associations
(Aitem
),
2943 Make_Pragma_Argument_Association
(Eloc
,
2944 Chars
=> Name_Message
,
2946 Make_String_Literal
(Eloc
,
2948 & Get_Name_String
(Pname
)
2950 & Build_Location_String
(Eloc
))));
2953 Set_Is_Delayed_Aspect
(Aspect
);
2955 -- For Pre/Post cases, insert immediately after the entity
2956 -- declaration, since that is the required pragma placement.
2957 -- Note that for these aspects, we do not have to worry
2958 -- about delay issues, since the pragmas themselves deal
2959 -- with delay of visibility for the expression analysis.
2961 Insert_Pragma
(Aitem
);
2968 when Aspect_Test_Case
=> Test_Case
: declare
2970 Comp_Expr
: Node_Id
;
2971 Comp_Assn
: Node_Id
;
2977 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
2978 Error_Msg_Name_1
:= Nam
;
2979 Error_Msg_N
("incorrect placement of aspect `%`", E
);
2983 if Nkind
(Expr
) /= N_Aggregate
then
2984 Error_Msg_Name_1
:= Nam
;
2986 ("wrong syntax for aspect `%` for &", Id
, E
);
2990 -- Make pragma expressions refer to the original aspect
2991 -- expressions through the Original_Node link. This is used
2992 -- in semantic analysis for ASIS mode, so that the original
2993 -- expression also gets analyzed.
2995 Comp_Expr
:= First
(Expressions
(Expr
));
2996 while Present
(Comp_Expr
) loop
2997 New_Expr
:= Relocate_Node
(Comp_Expr
);
2999 Make_Pragma_Argument_Association
(Sloc
(Comp_Expr
),
3000 Expression
=> New_Expr
));
3004 Comp_Assn
:= First
(Component_Associations
(Expr
));
3005 while Present
(Comp_Assn
) loop
3006 if List_Length
(Choices
(Comp_Assn
)) /= 1
3008 Nkind
(First
(Choices
(Comp_Assn
))) /= N_Identifier
3010 Error_Msg_Name_1
:= Nam
;
3012 ("wrong syntax for aspect `%` for &", Id
, E
);
3017 Make_Pragma_Argument_Association
(Sloc
(Comp_Assn
),
3018 Chars
=> Chars
(First
(Choices
(Comp_Assn
))),
3020 Relocate_Node
(Expression
(Comp_Assn
))));
3024 -- Build the test-case pragma
3027 (Pragma_Argument_Associations
=> Args
,
3028 Pragma_Name
=> Nam
);
3033 when Aspect_Contract_Cases
=>
3035 (Pragma_Argument_Associations
=> New_List
(
3036 Make_Pragma_Argument_Association
(Loc
,
3037 Expression
=> Relocate_Node
(Expr
))),
3038 Pragma_Name
=> Nam
);
3040 Decorate
(Aspect
, Aitem
);
3041 Insert_Pragma
(Aitem
);
3044 -- Case 5: Special handling for aspects with an optional
3045 -- boolean argument.
3047 -- In the general case, the corresponding pragma cannot be
3048 -- generated yet because the evaluation of the boolean needs
3049 -- to be delayed till the freeze point.
3051 when Boolean_Aspects |
3052 Library_Unit_Aspects
=>
3054 Set_Is_Boolean_Aspect
(Aspect
);
3056 -- Lock_Free aspect only apply to protected objects
3058 if A_Id
= Aspect_Lock_Free
then
3059 if Ekind
(E
) /= E_Protected_Type
then
3060 Error_Msg_Name_1
:= Nam
;
3062 ("aspect % only applies to a protected object",
3066 -- Set the Uses_Lock_Free flag to True if there is no
3067 -- expression or if the expression is True. The
3068 -- evaluation of this aspect should be delayed to the
3069 -- freeze point (why???)
3072 or else Is_True
(Static_Boolean
(Expr
))
3074 Set_Uses_Lock_Free
(E
);
3077 Record_Rep_Item
(E
, Aspect
);
3082 elsif A_Id
= Aspect_Import
or else A_Id
= Aspect_Export
then
3084 -- For the case of aspects Import and Export, we don't
3085 -- consider that we know the entity is never set in the
3086 -- source, since it is is likely modified outside the
3089 -- Note: one might think that the analysis of the
3090 -- resulting pragma would take care of that, but
3091 -- that's not the case since it won't be from source.
3093 if Ekind
(E
) = E_Variable
then
3094 Set_Never_Set_In_Source
(E
, False);
3097 -- In older versions of Ada the corresponding pragmas
3098 -- specified a Convention. In Ada 2012 the convention is
3099 -- specified as a separate aspect, and it is optional,
3100 -- given that it defaults to Convention_Ada. The code
3101 -- that verifed that there was a matching convention
3104 -- Resolve the expression of an Import or Export here,
3105 -- and require it to be of type Boolean and static. This
3106 -- is not quite right, because in general this should be
3107 -- delayed, but that seems tricky for these, because
3108 -- normally Boolean aspects are replaced with pragmas at
3109 -- the freeze point (in Make_Pragma_From_Boolean_Aspect),
3110 -- but in the case of these aspects we can't generate
3111 -- a simple pragma with just the entity name. ???
3113 if not Present
(Expr
)
3114 or else Is_True
(Static_Boolean
(Expr
))
3116 if A_Id
= Aspect_Import
then
3117 Set_Is_Imported
(E
);
3119 -- An imported entity cannot have an explicit
3122 if Nkind
(N
) = N_Object_Declaration
3123 and then Present
(Expression
(N
))
3126 ("imported entities cannot be initialized "
3127 & "(RM B.1(24))", Expression
(N
));
3130 elsif A_Id
= Aspect_Export
then
3131 Set_Is_Exported
(E
);
3138 -- Library unit aspects require special handling in the case
3139 -- of a package declaration, the pragma needs to be inserted
3140 -- in the list of declarations for the associated package.
3141 -- There is no issue of visibility delay for these aspects.
3143 if A_Id
in Library_Unit_Aspects
3145 Nkind_In
(N
, N_Package_Declaration
,
3146 N_Generic_Package_Declaration
)
3147 and then Nkind
(Parent
(N
)) /= N_Compilation_Unit
3149 -- Aspect is legal on a local instantiation of a library-
3150 -- level generic unit.
3152 and then not Is_Generic_Instance
(Defining_Entity
(N
))
3155 ("incorrect context for library unit aspect&", Id
);
3159 -- External property aspects are Boolean by nature, but
3160 -- their pragmas must contain two arguments, the second
3161 -- being the optional Boolean expression.
3163 if A_Id
= Aspect_Async_Readers
or else
3164 A_Id
= Aspect_Async_Writers
or else
3165 A_Id
= Aspect_Effective_Reads
or else
3166 A_Id
= Aspect_Effective_Writes
3172 -- The first argument of the external property pragma
3173 -- is the related object.
3177 Make_Pragma_Argument_Association
(Sloc
(Ent
),
3178 Expression
=> Ent
));
3180 -- The second argument is the optional Boolean
3181 -- expression which must be propagated even if it
3182 -- evaluates to False as this has special semantic
3185 if Present
(Expr
) then
3187 Make_Pragma_Argument_Association
(Loc
,
3188 Expression
=> Relocate_Node
(Expr
)));
3192 (Pragma_Argument_Associations
=> Args
,
3193 Pragma_Name
=> Nam
);
3196 -- Cases where we do not delay, includes all cases where the
3197 -- expression is missing other than the above cases.
3199 elsif not Delay_Required
or else No
(Expr
) then
3201 (Pragma_Argument_Associations
=> New_List
(
3202 Make_Pragma_Argument_Association
(Sloc
(Ent
),
3203 Expression
=> Ent
)),
3204 Pragma_Name
=> Chars
(Id
));
3205 Delay_Required
:= False;
3207 -- In general cases, the corresponding pragma/attribute
3208 -- definition clause will be inserted later at the freezing
3209 -- point, and we do not need to build it now.
3217 -- This is special because for access types we need to generate
3218 -- an attribute definition clause. This also works for single
3219 -- task declarations, but it does not work for task type
3220 -- declarations, because we have the case where the expression
3221 -- references a discriminant of the task type. That can't use
3222 -- an attribute definition clause because we would not have
3223 -- visibility on the discriminant. For that case we must
3224 -- generate a pragma in the task definition.
3226 when Aspect_Storage_Size
=>
3230 if Ekind
(E
) = E_Task_Type
then
3232 Decl
: constant Node_Id
:= Declaration_Node
(E
);
3235 pragma Assert
(Nkind
(Decl
) = N_Task_Type_Declaration
);
3237 -- If no task definition, create one
3239 if No
(Task_Definition
(Decl
)) then
3240 Set_Task_Definition
(Decl
,
3241 Make_Task_Definition
(Loc
,
3242 Visible_Declarations
=> Empty_List
,
3243 End_Label
=> Empty
));
3246 -- Create a pragma and put it at the start of the task
3247 -- definition for the task type declaration.
3250 (Pragma_Argument_Associations
=> New_List
(
3251 Make_Pragma_Argument_Association
(Loc
,
3252 Expression
=> Relocate_Node
(Expr
))),
3253 Pragma_Name
=> Name_Storage_Size
);
3257 Visible_Declarations
(Task_Definition
(Decl
)));
3261 -- All other cases, generate attribute definition
3265 Make_Attribute_Definition_Clause
(Loc
,
3267 Chars
=> Chars
(Id
),
3268 Expression
=> Relocate_Node
(Expr
));
3272 -- Attach the corresponding pragma/attribute definition clause to
3273 -- the aspect specification node.
3275 if Present
(Aitem
) then
3276 Set_From_Aspect_Specification
(Aitem
);
3279 -- In the context of a compilation unit, we directly put the
3280 -- pragma in the Pragmas_After list of the N_Compilation_Unit_Aux
3281 -- node (no delay is required here) except for aspects on a
3282 -- subprogram body (see below) and a generic package, for which we
3283 -- need to introduce the pragma before building the generic copy
3284 -- (see sem_ch12), and for package instantiations, where the
3285 -- library unit pragmas are better handled early.
3287 if Nkind
(Parent
(N
)) = N_Compilation_Unit
3288 and then (Present
(Aitem
) or else Is_Boolean_Aspect
(Aspect
))
3291 Aux
: constant Node_Id
:= Aux_Decls_Node
(Parent
(N
));
3294 pragma Assert
(Nkind
(Aux
) = N_Compilation_Unit_Aux
);
3296 -- For a Boolean aspect, create the corresponding pragma if
3297 -- no expression or if the value is True.
3299 if Is_Boolean_Aspect
(Aspect
) and then No
(Aitem
) then
3300 if Is_True
(Static_Boolean
(Expr
)) then
3302 (Pragma_Argument_Associations
=> New_List
(
3303 Make_Pragma_Argument_Association
(Sloc
(Ent
),
3304 Expression
=> Ent
)),
3305 Pragma_Name
=> Chars
(Id
));
3307 Set_From_Aspect_Specification
(Aitem
, True);
3308 Set_Corresponding_Aspect
(Aitem
, Aspect
);
3315 -- If the aspect is on a subprogram body (relevant aspect
3316 -- is Inline), add the pragma in front of the declarations.
3318 if Nkind
(N
) = N_Subprogram_Body
then
3319 if No
(Declarations
(N
)) then
3320 Set_Declarations
(N
, New_List
);
3323 Prepend
(Aitem
, Declarations
(N
));
3325 elsif Nkind
(N
) = N_Generic_Package_Declaration
then
3326 if No
(Visible_Declarations
(Specification
(N
))) then
3327 Set_Visible_Declarations
(Specification
(N
), New_List
);
3331 Visible_Declarations
(Specification
(N
)));
3333 elsif Nkind
(N
) = N_Package_Instantiation
then
3335 Spec
: constant Node_Id
:=
3336 Specification
(Instance_Spec
(N
));
3338 if No
(Visible_Declarations
(Spec
)) then
3339 Set_Visible_Declarations
(Spec
, New_List
);
3342 Prepend
(Aitem
, Visible_Declarations
(Spec
));
3346 if No
(Pragmas_After
(Aux
)) then
3347 Set_Pragmas_After
(Aux
, New_List
);
3350 Append
(Aitem
, Pragmas_After
(Aux
));
3357 -- The evaluation of the aspect is delayed to the freezing point.
3358 -- The pragma or attribute clause if there is one is then attached
3359 -- to the aspect specification which is put in the rep item list.
3361 if Delay_Required
then
3362 if Present
(Aitem
) then
3363 Set_Is_Delayed_Aspect
(Aitem
);
3364 Set_Aspect_Rep_Item
(Aspect
, Aitem
);
3365 Set_Parent
(Aitem
, Aspect
);
3368 Set_Is_Delayed_Aspect
(Aspect
);
3370 -- In the case of Default_Value, link the aspect to base type
3371 -- as well, even though it appears on a first subtype. This is
3372 -- mandated by the semantics of the aspect. Do not establish
3373 -- the link when processing the base type itself as this leads
3374 -- to a rep item circularity. Verify that we are dealing with
3375 -- a scalar type to prevent cascaded errors.
3377 if A_Id
= Aspect_Default_Value
3378 and then Is_Scalar_Type
(E
)
3379 and then Base_Type
(E
) /= E
3381 Set_Has_Delayed_Aspects
(Base_Type
(E
));
3382 Record_Rep_Item
(Base_Type
(E
), Aspect
);
3385 Set_Has_Delayed_Aspects
(E
);
3386 Record_Rep_Item
(E
, Aspect
);
3388 -- When delay is not required and the context is a package or a
3389 -- subprogram body, insert the pragma in the body declarations.
3391 elsif Nkind_In
(N
, N_Package_Body
, N_Subprogram_Body
) then
3392 if No
(Declarations
(N
)) then
3393 Set_Declarations
(N
, New_List
);
3396 -- The pragma is added before source declarations
3398 Prepend_To
(Declarations
(N
), Aitem
);
3400 -- When delay is not required and the context is not a compilation
3401 -- unit, we simply insert the pragma/attribute definition clause
3405 Insert_After
(Ins_Node
, Aitem
);
3408 end Analyze_One_Aspect
;
3412 end loop Aspect_Loop
;
3414 if Has_Delayed_Aspects
(E
) then
3415 Ensure_Freeze_Node
(E
);
3417 end Analyze_Aspect_Specifications
;
3419 -----------------------
3420 -- Analyze_At_Clause --
3421 -----------------------
3423 -- An at clause is replaced by the corresponding Address attribute
3424 -- definition clause that is the preferred approach in Ada 95.
3426 procedure Analyze_At_Clause
(N
: Node_Id
) is
3427 CS
: constant Boolean := Comes_From_Source
(N
);
3430 -- This is an obsolescent feature
3432 Check_Restriction
(No_Obsolescent_Features
, N
);
3434 if Warn_On_Obsolescent_Feature
then
3436 ("?j?at clause is an obsolescent feature (RM J.7(2))", N
);
3438 ("\?j?use address attribute definition clause instead", N
);
3441 -- Rewrite as address clause
3444 Make_Attribute_Definition_Clause
(Sloc
(N
),
3445 Name
=> Identifier
(N
),
3446 Chars
=> Name_Address
,
3447 Expression
=> Expression
(N
)));
3449 -- We preserve Comes_From_Source, since logically the clause still comes
3450 -- from the source program even though it is changed in form.
3452 Set_Comes_From_Source
(N
, CS
);
3454 -- Analyze rewritten clause
3456 Analyze_Attribute_Definition_Clause
(N
);
3457 end Analyze_At_Clause
;
3459 -----------------------------------------
3460 -- Analyze_Attribute_Definition_Clause --
3461 -----------------------------------------
3463 procedure Analyze_Attribute_Definition_Clause
(N
: Node_Id
) is
3464 Loc
: constant Source_Ptr
:= Sloc
(N
);
3465 Nam
: constant Node_Id
:= Name
(N
);
3466 Attr
: constant Name_Id
:= Chars
(N
);
3467 Expr
: constant Node_Id
:= Expression
(N
);
3468 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Attr
);
3471 -- The entity of Nam after it is analyzed. In the case of an incomplete
3472 -- type, this is the underlying type.
3475 -- The underlying entity to which the attribute applies. Generally this
3476 -- is the Underlying_Type of Ent, except in the case where the clause
3477 -- applies to full view of incomplete type or private type in which case
3478 -- U_Ent is just a copy of Ent.
3480 FOnly
: Boolean := False;
3481 -- Reset to True for subtype specific attribute (Alignment, Size)
3482 -- and for stream attributes, i.e. those cases where in the call to
3483 -- Rep_Item_Too_Late, FOnly is set True so that only the freezing rules
3484 -- are checked. Note that the case of stream attributes is not clear
3485 -- from the RM, but see AI95-00137. Also, the RM seems to disallow
3486 -- Storage_Size for derived task types, but that is also clearly
3489 procedure Analyze_Stream_TSS_Definition
(TSS_Nam
: TSS_Name_Type
);
3490 -- Common processing for 'Read, 'Write, 'Input and 'Output attribute
3491 -- definition clauses.
3493 function Duplicate_Clause
return Boolean;
3494 -- This routine checks if the aspect for U_Ent being given by attribute
3495 -- definition clause N is for an aspect that has already been specified,
3496 -- and if so gives an error message. If there is a duplicate, True is
3497 -- returned, otherwise if there is no error, False is returned.
3499 procedure Check_Indexing_Functions
;
3500 -- Check that the function in Constant_Indexing or Variable_Indexing
3501 -- attribute has the proper type structure. If the name is overloaded,
3502 -- check that some interpretation is legal.
3504 procedure Check_Iterator_Functions
;
3505 -- Check that there is a single function in Default_Iterator attribute
3506 -- has the proper type structure.
3508 function Check_Primitive_Function
(Subp
: Entity_Id
) return Boolean;
3509 -- Common legality check for the previous two
3511 -----------------------------------
3512 -- Analyze_Stream_TSS_Definition --
3513 -----------------------------------
3515 procedure Analyze_Stream_TSS_Definition
(TSS_Nam
: TSS_Name_Type
) is
3516 Subp
: Entity_Id
:= Empty
;
3521 Is_Read
: constant Boolean := (TSS_Nam
= TSS_Stream_Read
);
3522 -- True for Read attribute, false for other attributes
3524 function Has_Good_Profile
(Subp
: Entity_Id
) return Boolean;
3525 -- Return true if the entity is a subprogram with an appropriate
3526 -- profile for the attribute being defined.
3528 ----------------------
3529 -- Has_Good_Profile --
3530 ----------------------
3532 function Has_Good_Profile
(Subp
: Entity_Id
) return Boolean is
3534 Is_Function
: constant Boolean := (TSS_Nam
= TSS_Stream_Input
);
3535 Expected_Ekind
: constant array (Boolean) of Entity_Kind
:=
3536 (False => E_Procedure
, True => E_Function
);
3540 if Ekind
(Subp
) /= Expected_Ekind
(Is_Function
) then
3544 F
:= First_Formal
(Subp
);
3547 or else Ekind
(Etype
(F
)) /= E_Anonymous_Access_Type
3548 or else Designated_Type
(Etype
(F
)) /=
3549 Class_Wide_Type
(RTE
(RE_Root_Stream_Type
))
3554 if not Is_Function
then
3558 Expected_Mode
: constant array (Boolean) of Entity_Kind
:=
3559 (False => E_In_Parameter
,
3560 True => E_Out_Parameter
);
3562 if Parameter_Mode
(F
) /= Expected_Mode
(Is_Read
) then
3569 -- If the attribute specification comes from an aspect
3570 -- specification for a class-wide stream, the parameter must be
3571 -- a class-wide type of the entity to which the aspect applies.
3573 if From_Aspect_Specification
(N
)
3574 and then Class_Present
(Parent
(N
))
3575 and then Is_Class_Wide_Type
(Typ
)
3581 Typ
:= Etype
(Subp
);
3584 -- Verify that the prefix of the attribute and the local name for
3585 -- the type of the formal match, or one is the class-wide of the
3586 -- other, in the case of a class-wide stream operation.
3588 if Base_Type
(Typ
) = Base_Type
(Ent
)
3589 or else (Is_Class_Wide_Type
(Typ
)
3590 and then Typ
= Class_Wide_Type
(Base_Type
(Ent
)))
3591 or else (Is_Class_Wide_Type
(Ent
)
3592 and then Ent
= Class_Wide_Type
(Base_Type
(Typ
)))
3599 if Present
((Next_Formal
(F
)))
3603 elsif not Is_Scalar_Type
(Typ
)
3604 and then not Is_First_Subtype
(Typ
)
3605 and then not Is_Class_Wide_Type
(Typ
)
3612 end Has_Good_Profile
;
3614 -- Start of processing for Analyze_Stream_TSS_Definition
3619 if not Is_Type
(U_Ent
) then
3620 Error_Msg_N
("local name must be a subtype", Nam
);
3623 elsif not Is_First_Subtype
(U_Ent
) then
3624 Error_Msg_N
("local name must be a first subtype", Nam
);
3628 Pnam
:= TSS
(Base_Type
(U_Ent
), TSS_Nam
);
3630 -- If Pnam is present, it can be either inherited from an ancestor
3631 -- type (in which case it is legal to redefine it for this type), or
3632 -- be a previous definition of the attribute for the same type (in
3633 -- which case it is illegal).
3635 -- In the first case, it will have been analyzed already, and we
3636 -- can check that its profile does not match the expected profile
3637 -- for a stream attribute of U_Ent. In the second case, either Pnam
3638 -- has been analyzed (and has the expected profile), or it has not
3639 -- been analyzed yet (case of a type that has not been frozen yet
3640 -- and for which the stream attribute has been set using Set_TSS).
3643 and then (No
(First_Entity
(Pnam
)) or else Has_Good_Profile
(Pnam
))
3645 Error_Msg_Sloc
:= Sloc
(Pnam
);
3646 Error_Msg_Name_1
:= Attr
;
3647 Error_Msg_N
("% attribute already defined #", Nam
);
3653 if Is_Entity_Name
(Expr
) then
3654 if not Is_Overloaded
(Expr
) then
3655 if Has_Good_Profile
(Entity
(Expr
)) then
3656 Subp
:= Entity
(Expr
);
3660 Get_First_Interp
(Expr
, I
, It
);
3661 while Present
(It
.Nam
) loop
3662 if Has_Good_Profile
(It
.Nam
) then
3667 Get_Next_Interp
(I
, It
);
3672 if Present
(Subp
) then
3673 if Is_Abstract_Subprogram
(Subp
) then
3674 Error_Msg_N
("stream subprogram must not be abstract", Expr
);
3677 -- A stream subprogram for an interface type must be a null
3678 -- procedure (RM 13.13.2 (38/3)).
3680 elsif Is_Interface
(U_Ent
)
3681 and then not Is_Class_Wide_Type
(U_Ent
)
3682 and then not Inside_A_Generic
3684 (Ekind
(Subp
) = E_Function
3688 (Unit_Declaration_Node
(Ultimate_Alias
(Subp
)))))
3691 ("stream subprogram for interface type "
3692 & "must be null procedure", Expr
);
3695 Set_Entity
(Expr
, Subp
);
3696 Set_Etype
(Expr
, Etype
(Subp
));
3698 New_Stream_Subprogram
(N
, U_Ent
, Subp
, TSS_Nam
);
3701 Error_Msg_Name_1
:= Attr
;
3702 Error_Msg_N
("incorrect expression for% attribute", Expr
);
3704 end Analyze_Stream_TSS_Definition
;
3706 ------------------------------
3707 -- Check_Indexing_Functions --
3708 ------------------------------
3710 procedure Check_Indexing_Functions
is
3711 Indexing_Found
: Boolean := False;
3713 procedure Check_One_Function
(Subp
: Entity_Id
);
3714 -- Check one possible interpretation. Sets Indexing_Found True if a
3715 -- legal indexing function is found.
3717 procedure Illegal_Indexing
(Msg
: String);
3718 -- Diagnose illegal indexing function if not overloaded. In the
3719 -- overloaded case indicate that no legal interpretation exists.
3721 ------------------------
3722 -- Check_One_Function --
3723 ------------------------
3725 procedure Check_One_Function
(Subp
: Entity_Id
) is
3726 Default_Element
: Node_Id
;
3727 Ret_Type
: constant Entity_Id
:= Etype
(Subp
);
3730 if not Is_Overloadable
(Subp
) then
3731 Illegal_Indexing
("illegal indexing function for type&");
3734 elsif Scope
(Subp
) /= Scope
(Ent
) then
3735 if Nkind
(Expr
) = N_Expanded_Name
then
3737 -- Indexing function can't be declared elsewhere
3740 ("indexing function must be declared in scope of type&");
3745 elsif No
(First_Formal
(Subp
)) then
3747 ("Indexing requires a function that applies to type&");
3750 elsif No
(Next_Formal
(First_Formal
(Subp
))) then
3752 ("indexing function must have at least two parameters");
3755 elsif Is_Derived_Type
(Ent
) then
3756 if (Attr
= Name_Constant_Indexing
3758 (Find_Aspect
(Etype
(Ent
), Aspect_Constant_Indexing
)))
3760 (Attr
= Name_Variable_Indexing
3762 (Find_Aspect
(Etype
(Ent
), Aspect_Variable_Indexing
)))
3764 if Debug_Flag_Dot_XX
then
3769 ("indexing function already inherited "
3770 & "from parent type");
3776 if not Check_Primitive_Function
(Subp
) then
3778 ("Indexing aspect requires a function that applies to type&");
3782 -- If partial declaration exists, verify that it is not tagged.
3784 if Ekind
(Current_Scope
) = E_Package
3785 and then Has_Private_Declaration
(Ent
)
3786 and then From_Aspect_Specification
(N
)
3788 List_Containing
(Parent
(Ent
)) =
3789 Private_Declarations
3790 (Specification
(Unit_Declaration_Node
(Current_Scope
)))
3791 and then Nkind
(N
) = N_Attribute_Definition_Clause
3798 First
(Visible_Declarations
3800 (Unit_Declaration_Node
(Current_Scope
))));
3802 while Present
(Decl
) loop
3803 if Nkind
(Decl
) = N_Private_Type_Declaration
3804 and then Ent
= Full_View
(Defining_Identifier
(Decl
))
3805 and then Tagged_Present
(Decl
)
3806 and then No
(Aspect_Specifications
(Decl
))
3809 ("Indexing aspect cannot be specified on full view "
3810 & "if partial view is tagged");
3819 -- An indexing function must return either the default element of
3820 -- the container, or a reference type. For variable indexing it
3821 -- must be the latter.
3824 Find_Value_Of_Aspect
3825 (Etype
(First_Formal
(Subp
)), Aspect_Iterator_Element
);
3827 if Present
(Default_Element
) then
3828 Analyze
(Default_Element
);
3830 if Is_Entity_Name
(Default_Element
)
3831 and then not Covers
(Entity
(Default_Element
), Ret_Type
)
3835 ("wrong return type for indexing function");
3840 -- For variable_indexing the return type must be a reference type
3842 if Attr
= Name_Variable_Indexing
then
3843 if not Has_Implicit_Dereference
(Ret_Type
) then
3845 ("variable indexing must return a reference type");
3848 elsif Is_Access_Constant
3849 (Etype
(First_Discriminant
(Ret_Type
)))
3852 ("variable indexing must return an access to variable");
3857 if Has_Implicit_Dereference
(Ret_Type
)
3859 Is_Access_Constant
(Etype
(First_Discriminant
(Ret_Type
)))
3862 ("constant indexing must return an access to constant");
3865 elsif Is_Access_Type
(Etype
(First_Formal
(Subp
)))
3866 and then not Is_Access_Constant
(Etype
(First_Formal
(Subp
)))
3869 ("constant indexing must apply to an access to constant");
3874 -- All checks succeeded.
3876 Indexing_Found
:= True;
3877 end Check_One_Function
;
3879 -----------------------
3880 -- Illegal_Indexing --
3881 -----------------------
3883 procedure Illegal_Indexing
(Msg
: String) is
3885 Error_Msg_NE
(Msg
, N
, Ent
);
3886 end Illegal_Indexing
;
3888 -- Start of processing for Check_Indexing_Functions
3897 if not Is_Overloaded
(Expr
) then
3898 Check_One_Function
(Entity
(Expr
));
3906 Indexing_Found
:= False;
3907 Get_First_Interp
(Expr
, I
, It
);
3908 while Present
(It
.Nam
) loop
3910 -- Note that analysis will have added the interpretation
3911 -- that corresponds to the dereference. We only check the
3912 -- subprogram itself.
3914 if Is_Overloadable
(It
.Nam
) then
3915 Check_One_Function
(It
.Nam
);
3918 Get_Next_Interp
(I
, It
);
3923 if not Indexing_Found
and then not Error_Posted
(N
) then
3925 ("aspect Indexing requires a local function that "
3926 & "applies to type&", Expr
, Ent
);
3928 end Check_Indexing_Functions
;
3930 ------------------------------
3931 -- Check_Iterator_Functions --
3932 ------------------------------
3934 procedure Check_Iterator_Functions
is
3935 Default
: Entity_Id
;
3937 function Valid_Default_Iterator
(Subp
: Entity_Id
) return Boolean;
3938 -- Check one possible interpretation for validity
3940 ----------------------------
3941 -- Valid_Default_Iterator --
3942 ----------------------------
3944 function Valid_Default_Iterator
(Subp
: Entity_Id
) return Boolean is
3948 if not Check_Primitive_Function
(Subp
) then
3951 Formal
:= First_Formal
(Subp
);
3954 -- False if any subsequent formal has no default expression
3956 Formal
:= Next_Formal
(Formal
);
3957 while Present
(Formal
) loop
3958 if No
(Expression
(Parent
(Formal
))) then
3962 Next_Formal
(Formal
);
3965 -- True if all subsequent formals have default expressions
3968 end Valid_Default_Iterator
;
3970 -- Start of processing for Check_Iterator_Functions
3975 if not Is_Entity_Name
(Expr
) then
3976 Error_Msg_N
("aspect Iterator must be a function name", Expr
);
3979 if not Is_Overloaded
(Expr
) then
3980 if not Check_Primitive_Function
(Entity
(Expr
)) then
3982 ("aspect Indexing requires a function that applies to type&",
3983 Entity
(Expr
), Ent
);
3986 if not Valid_Default_Iterator
(Entity
(Expr
)) then
3987 Error_Msg_N
("improper function for default iterator", Expr
);
3997 Get_First_Interp
(Expr
, I
, It
);
3998 while Present
(It
.Nam
) loop
3999 if not Check_Primitive_Function
(It
.Nam
)
4000 or else not Valid_Default_Iterator
(It
.Nam
)
4004 elsif Present
(Default
) then
4005 Error_Msg_N
("default iterator must be unique", Expr
);
4011 Get_Next_Interp
(I
, It
);
4015 if Present
(Default
) then
4016 Set_Entity
(Expr
, Default
);
4017 Set_Is_Overloaded
(Expr
, False);
4020 end Check_Iterator_Functions
;
4022 -------------------------------
4023 -- Check_Primitive_Function --
4024 -------------------------------
4026 function Check_Primitive_Function
(Subp
: Entity_Id
) return Boolean is
4030 if Ekind
(Subp
) /= E_Function
then
4034 if No
(First_Formal
(Subp
)) then
4037 Ctrl
:= Etype
(First_Formal
(Subp
));
4040 -- Type of formal may be the class-wide type, an access to such,
4041 -- or an incomplete view.
4044 or else Ctrl
= Class_Wide_Type
(Ent
)
4046 (Ekind
(Ctrl
) = E_Anonymous_Access_Type
4047 and then (Designated_Type
(Ctrl
) = Ent
4049 Designated_Type
(Ctrl
) = Class_Wide_Type
(Ent
)))
4051 (Ekind
(Ctrl
) = E_Incomplete_Type
4052 and then Full_View
(Ctrl
) = Ent
)
4060 end Check_Primitive_Function
;
4062 ----------------------
4063 -- Duplicate_Clause --
4064 ----------------------
4066 function Duplicate_Clause
return Boolean is
4070 -- Nothing to do if this attribute definition clause comes from
4071 -- an aspect specification, since we could not be duplicating an
4072 -- explicit clause, and we dealt with the case of duplicated aspects
4073 -- in Analyze_Aspect_Specifications.
4075 if From_Aspect_Specification
(N
) then
4079 -- Otherwise current clause may duplicate previous clause, or a
4080 -- previously given pragma or aspect specification for the same
4083 A
:= Get_Rep_Item
(U_Ent
, Chars
(N
), Check_Parents
=> False);
4086 Error_Msg_Name_1
:= Chars
(N
);
4087 Error_Msg_Sloc
:= Sloc
(A
);
4089 Error_Msg_NE
("aspect% for & previously given#", N
, U_Ent
);
4094 end Duplicate_Clause
;
4096 -- Start of processing for Analyze_Attribute_Definition_Clause
4099 -- The following code is a defense against recursion. Not clear that
4100 -- this can happen legitimately, but perhaps some error situations can
4101 -- cause it, and we did see this recursion during testing.
4103 if Analyzed
(N
) then
4106 Set_Analyzed
(N
, True);
4109 -- Ignore some selected attributes in CodePeer mode since they are not
4110 -- relevant in this context.
4112 if CodePeer_Mode
then
4115 -- Ignore Component_Size in CodePeer mode, to avoid changing the
4116 -- internal representation of types by implicitly packing them.
4118 when Attribute_Component_Size
=>
4119 Rewrite
(N
, Make_Null_Statement
(Sloc
(N
)));
4127 -- Process Ignore_Rep_Clauses option
4129 if Ignore_Rep_Clauses
then
4132 -- The following should be ignored. They do not affect legality
4133 -- and may be target dependent. The basic idea of -gnatI is to
4134 -- ignore any rep clauses that may be target dependent but do not
4135 -- affect legality (except possibly to be rejected because they
4136 -- are incompatible with the compilation target).
4138 when Attribute_Alignment |
4139 Attribute_Bit_Order |
4140 Attribute_Component_Size |
4141 Attribute_Machine_Radix |
4142 Attribute_Object_Size |
4145 Attribute_Stream_Size |
4146 Attribute_Value_Size
=>
4147 Kill_Rep_Clause
(N
);
4150 -- The following should not be ignored, because in the first place
4151 -- they are reasonably portable, and should not cause problems
4152 -- in compiling code from another target, and also they do affect
4153 -- legality, e.g. failing to provide a stream attribute for a type
4154 -- may make a program illegal.
4156 when Attribute_External_Tag |
4160 Attribute_Simple_Storage_Pool |
4161 Attribute_Storage_Pool |
4162 Attribute_Storage_Size |
4166 -- We do not do anything here with address clauses, they will be
4167 -- removed by Freeze later on, but for now, it works better to
4168 -- keep then in the tree.
4170 when Attribute_Address
=>
4173 -- Other cases are errors ("attribute& cannot be set with
4174 -- definition clause"), which will be caught below.
4182 Ent
:= Entity
(Nam
);
4184 if Rep_Item_Too_Early
(Ent
, N
) then
4188 -- Rep clause applies to full view of incomplete type or private type if
4189 -- we have one (if not, this is a premature use of the type). However,
4190 -- certain semantic checks need to be done on the specified entity (i.e.
4191 -- the private view), so we save it in Ent.
4193 if Is_Private_Type
(Ent
)
4194 and then Is_Derived_Type
(Ent
)
4195 and then not Is_Tagged_Type
(Ent
)
4196 and then No
(Full_View
(Ent
))
4198 -- If this is a private type whose completion is a derivation from
4199 -- another private type, there is no full view, and the attribute
4200 -- belongs to the type itself, not its underlying parent.
4204 elsif Ekind
(Ent
) = E_Incomplete_Type
then
4206 -- The attribute applies to the full view, set the entity of the
4207 -- attribute definition accordingly.
4209 Ent
:= Underlying_Type
(Ent
);
4211 Set_Entity
(Nam
, Ent
);
4214 U_Ent
:= Underlying_Type
(Ent
);
4217 -- Avoid cascaded error
4219 if Etype
(Nam
) = Any_Type
then
4222 -- Must be declared in current scope or in case of an aspect
4223 -- specification, must be visible in current scope.
4225 elsif Scope
(Ent
) /= Current_Scope
4227 not (From_Aspect_Specification
(N
)
4228 and then Scope_Within_Or_Same
(Current_Scope
, Scope
(Ent
)))
4230 Error_Msg_N
("entity must be declared in this scope", Nam
);
4233 -- Must not be a source renaming (we do have some cases where the
4234 -- expander generates a renaming, and those cases are OK, in such
4235 -- cases any attribute applies to the renamed object as well).
4237 elsif Is_Object
(Ent
)
4238 and then Present
(Renamed_Object
(Ent
))
4240 -- Case of renamed object from source, this is an error
4242 if Comes_From_Source
(Renamed_Object
(Ent
)) then
4243 Get_Name_String
(Chars
(N
));
4244 Error_Msg_Strlen
:= Name_Len
;
4245 Error_Msg_String
(1 .. Name_Len
) := Name_Buffer
(1 .. Name_Len
);
4247 ("~ clause not allowed for a renaming declaration "
4248 & "(RM 13.1(6))", Nam
);
4251 -- For the case of a compiler generated renaming, the attribute
4252 -- definition clause applies to the renamed object created by the
4253 -- expander. The easiest general way to handle this is to create a
4254 -- copy of the attribute definition clause for this object.
4256 elsif Is_Entity_Name
(Renamed_Object
(Ent
)) then
4258 Make_Attribute_Definition_Clause
(Loc
,
4260 New_Occurrence_Of
(Entity
(Renamed_Object
(Ent
)), Loc
),
4262 Expression
=> Duplicate_Subexpr
(Expression
(N
))));
4264 -- If the renamed object is not an entity, it must be a dereference
4265 -- of an unconstrained function call, and we must introduce a new
4266 -- declaration to capture the expression. This is needed in the case
4267 -- of 'Alignment, where the original declaration must be rewritten.
4271 (Nkind
(Renamed_Object
(Ent
)) = N_Explicit_Dereference
);
4275 -- If no underlying entity, use entity itself, applies to some
4276 -- previously detected error cases ???
4278 elsif No
(U_Ent
) then
4281 -- Cannot specify for a subtype (exception Object/Value_Size)
4283 elsif Is_Type
(U_Ent
)
4284 and then not Is_First_Subtype
(U_Ent
)
4285 and then Id
/= Attribute_Object_Size
4286 and then Id
/= Attribute_Value_Size
4287 and then not From_At_Mod
(N
)
4289 Error_Msg_N
("cannot specify attribute for subtype", Nam
);
4293 Set_Entity
(N
, U_Ent
);
4294 Check_Restriction_No_Use_Of_Attribute
(N
);
4296 -- Switch on particular attribute
4304 -- Address attribute definition clause
4306 when Attribute_Address
=> Address
: begin
4308 -- A little error check, catch for X'Address use X'Address;
4310 if Nkind
(Nam
) = N_Identifier
4311 and then Nkind
(Expr
) = N_Attribute_Reference
4312 and then Attribute_Name
(Expr
) = Name_Address
4313 and then Nkind
(Prefix
(Expr
)) = N_Identifier
4314 and then Chars
(Nam
) = Chars
(Prefix
(Expr
))
4317 ("address for & is self-referencing", Prefix
(Expr
), Ent
);
4321 -- Not that special case, carry on with analysis of expression
4323 Analyze_And_Resolve
(Expr
, RTE
(RE_Address
));
4325 -- Even when ignoring rep clauses we need to indicate that the
4326 -- entity has an address clause and thus it is legal to declare
4327 -- it imported. Freeze will get rid of the address clause later.
4329 if Ignore_Rep_Clauses
then
4330 if Ekind_In
(U_Ent
, E_Variable
, E_Constant
) then
4331 Record_Rep_Item
(U_Ent
, N
);
4337 if Duplicate_Clause
then
4340 -- Case of address clause for subprogram
4342 elsif Is_Subprogram
(U_Ent
) then
4343 if Has_Homonym
(U_Ent
) then
4345 ("address clause cannot be given " &
4346 "for overloaded subprogram",
4351 -- For subprograms, all address clauses are permitted, and we
4352 -- mark the subprogram as having a deferred freeze so that Gigi
4353 -- will not elaborate it too soon.
4355 -- Above needs more comments, what is too soon about???
4357 Set_Has_Delayed_Freeze
(U_Ent
);
4359 -- Case of address clause for entry
4361 elsif Ekind
(U_Ent
) = E_Entry
then
4362 if Nkind
(Parent
(N
)) = N_Task_Body
then
4364 ("entry address must be specified in task spec", Nam
);
4368 -- For entries, we require a constant address
4370 Check_Constant_Address_Clause
(Expr
, U_Ent
);
4372 -- Special checks for task types
4374 if Is_Task_Type
(Scope
(U_Ent
))
4375 and then Comes_From_Source
(Scope
(U_Ent
))
4378 ("??entry address declared for entry in task type", N
);
4380 ("\??only one task can be declared of this type", N
);
4383 -- Entry address clauses are obsolescent
4385 Check_Restriction
(No_Obsolescent_Features
, N
);
4387 if Warn_On_Obsolescent_Feature
then
4389 ("?j?attaching interrupt to task entry is an " &
4390 "obsolescent feature (RM J.7.1)", N
);
4392 ("\?j?use interrupt procedure instead", N
);
4395 -- Case of an address clause for a controlled object which we
4396 -- consider to be erroneous.
4398 elsif Is_Controlled
(Etype
(U_Ent
))
4399 or else Has_Controlled_Component
(Etype
(U_Ent
))
4402 ("??controlled object& must not be overlaid", Nam
, U_Ent
);
4404 ("\??Program_Error will be raised at run time", Nam
);
4405 Insert_Action
(Declaration_Node
(U_Ent
),
4406 Make_Raise_Program_Error
(Loc
,
4407 Reason
=> PE_Overlaid_Controlled_Object
));
4410 -- Case of address clause for a (non-controlled) object
4412 elsif Ekind_In
(U_Ent
, E_Variable
, E_Constant
) then
4414 Expr
: constant Node_Id
:= Expression
(N
);
4419 -- Exported variables cannot have an address clause, because
4420 -- this cancels the effect of the pragma Export.
4422 if Is_Exported
(U_Ent
) then
4424 ("cannot export object with address clause", Nam
);
4428 Find_Overlaid_Entity
(N
, O_Ent
, Off
);
4430 -- Overlaying controlled objects is erroneous
4433 and then (Has_Controlled_Component
(Etype
(O_Ent
))
4434 or else Is_Controlled
(Etype
(O_Ent
)))
4437 ("??cannot overlay with controlled object", Expr
);
4439 ("\??Program_Error will be raised at run time", Expr
);
4440 Insert_Action
(Declaration_Node
(U_Ent
),
4441 Make_Raise_Program_Error
(Loc
,
4442 Reason
=> PE_Overlaid_Controlled_Object
));
4445 elsif Present
(O_Ent
)
4446 and then Ekind
(U_Ent
) = E_Constant
4447 and then not Is_Constant_Object
(O_Ent
)
4449 Error_Msg_N
("??constant overlays a variable", Expr
);
4451 -- Imported variables can have an address clause, but then
4452 -- the import is pretty meaningless except to suppress
4453 -- initializations, so we do not need such variables to
4454 -- be statically allocated (and in fact it causes trouble
4455 -- if the address clause is a local value).
4457 elsif Is_Imported
(U_Ent
) then
4458 Set_Is_Statically_Allocated
(U_Ent
, False);
4461 -- We mark a possible modification of a variable with an
4462 -- address clause, since it is likely aliasing is occurring.
4464 Note_Possible_Modification
(Nam
, Sure
=> False);
4466 -- Here we are checking for explicit overlap of one variable
4467 -- by another, and if we find this then mark the overlapped
4468 -- variable as also being volatile to prevent unwanted
4469 -- optimizations. This is a significant pessimization so
4470 -- avoid it when there is an offset, i.e. when the object
4471 -- is composite; they cannot be optimized easily anyway.
4474 and then Is_Object
(O_Ent
)
4477 -- The following test is an expedient solution to what
4478 -- is really a problem in CodePeer. Suppressing the
4479 -- Set_Treat_As_Volatile call here prevents later
4480 -- generation (in some cases) of trees that CodePeer
4481 -- should, but currently does not, handle correctly.
4482 -- This test should probably be removed when CodePeer
4483 -- is improved, just because we want the tree CodePeer
4484 -- analyzes to match the tree for which we generate code
4485 -- as closely as is practical. ???
4487 and then not CodePeer_Mode
4489 -- ??? O_Ent might not be in current unit
4491 Set_Treat_As_Volatile
(O_Ent
);
4494 -- Legality checks on the address clause for initialized
4495 -- objects is deferred until the freeze point, because
4496 -- a subsequent pragma might indicate that the object
4497 -- is imported and thus not initialized. Also, the address
4498 -- clause might involve entities that have yet to be
4501 Set_Has_Delayed_Freeze
(U_Ent
);
4503 -- If an initialization call has been generated for this
4504 -- object, it needs to be deferred to after the freeze node
4505 -- we have just now added, otherwise GIGI will see a
4506 -- reference to the variable (as actual to the IP call)
4507 -- before its definition.
4510 Init_Call
: constant Node_Id
:=
4511 Remove_Init_Call
(U_Ent
, N
);
4514 if Present
(Init_Call
) then
4515 Append_Freeze_Action
(U_Ent
, Init_Call
);
4517 -- Reset Initialization_Statements pointer so that
4518 -- if there is a pragma Import further down, it can
4519 -- clear any default initialization.
4521 Set_Initialization_Statements
(U_Ent
, Init_Call
);
4525 if Is_Exported
(U_Ent
) then
4527 ("& cannot be exported if an address clause is given",
4530 ("\define and export a variable "
4531 & "that holds its address instead", Nam
);
4534 -- Entity has delayed freeze, so we will generate an
4535 -- alignment check at the freeze point unless suppressed.
4537 if not Range_Checks_Suppressed
(U_Ent
)
4538 and then not Alignment_Checks_Suppressed
(U_Ent
)
4540 Set_Check_Address_Alignment
(N
);
4543 -- Kill the size check code, since we are not allocating
4544 -- the variable, it is somewhere else.
4546 Kill_Size_Check_Code
(U_Ent
);
4548 -- If the address clause is of the form:
4550 -- for Y'Address use X'Address
4554 -- Const : constant Address := X'Address;
4556 -- for Y'Address use Const;
4558 -- then we make an entry in the table for checking the size
4559 -- and alignment of the overlaying variable. We defer this
4560 -- check till after code generation to take full advantage
4561 -- of the annotation done by the back end.
4563 -- If the entity has a generic type, the check will be
4564 -- performed in the instance if the actual type justifies
4565 -- it, and we do not insert the clause in the table to
4566 -- prevent spurious warnings.
4568 -- Note: we used to test Comes_From_Source and only give
4569 -- this warning for source entities, but we have removed
4570 -- this test. It really seems bogus to generate overlays
4571 -- that would trigger this warning in generated code.
4572 -- Furthermore, by removing the test, we handle the
4573 -- aspect case properly.
4575 if Address_Clause_Overlay_Warnings
4576 and then Present
(O_Ent
)
4577 and then Is_Object
(O_Ent
)
4579 if not Is_Generic_Type
(Etype
(U_Ent
)) then
4580 Address_Clause_Checks
.Append
((N
, U_Ent
, O_Ent
, Off
));
4583 -- If variable overlays a constant view, and we are
4584 -- warning on overlays, then mark the variable as
4585 -- overlaying a constant (we will give warnings later
4586 -- if this variable is assigned).
4588 if Is_Constant_Object
(O_Ent
)
4589 and then Ekind
(U_Ent
) = E_Variable
4591 Set_Overlays_Constant
(U_Ent
);
4596 -- Not a valid entity for an address clause
4599 Error_Msg_N
("address cannot be given for &", Nam
);
4607 -- Alignment attribute definition clause
4609 when Attribute_Alignment
=> Alignment
: declare
4610 Align
: constant Uint
:= Get_Alignment_Value
(Expr
);
4611 Max_Align
: constant Uint
:= UI_From_Int
(Maximum_Alignment
);
4616 if not Is_Type
(U_Ent
)
4617 and then Ekind
(U_Ent
) /= E_Variable
4618 and then Ekind
(U_Ent
) /= E_Constant
4620 Error_Msg_N
("alignment cannot be given for &", Nam
);
4622 elsif Duplicate_Clause
then
4625 elsif Align
/= No_Uint
then
4626 Set_Has_Alignment_Clause
(U_Ent
);
4628 -- Tagged type case, check for attempt to set alignment to a
4629 -- value greater than Max_Align, and reset if so.
4631 if Is_Tagged_Type
(U_Ent
) and then Align
> Max_Align
then
4633 ("alignment for & set to Maximum_Aligment??", Nam
);
4634 Set_Alignment
(U_Ent
, Max_Align
);
4639 Set_Alignment
(U_Ent
, Align
);
4642 -- For an array type, U_Ent is the first subtype. In that case,
4643 -- also set the alignment of the anonymous base type so that
4644 -- other subtypes (such as the itypes for aggregates of the
4645 -- type) also receive the expected alignment.
4647 if Is_Array_Type
(U_Ent
) then
4648 Set_Alignment
(Base_Type
(U_Ent
), Align
);
4657 -- Bit_Order attribute definition clause
4659 when Attribute_Bit_Order
=> Bit_Order
: declare
4661 if not Is_Record_Type
(U_Ent
) then
4663 ("Bit_Order can only be defined for record type", Nam
);
4665 elsif Duplicate_Clause
then
4669 Analyze_And_Resolve
(Expr
, RTE
(RE_Bit_Order
));
4671 if Etype
(Expr
) = Any_Type
then
4674 elsif not Is_OK_Static_Expression
(Expr
) then
4675 Flag_Non_Static_Expr
4676 ("Bit_Order requires static expression!", Expr
);
4679 if (Expr_Value
(Expr
) = 0) /= Bytes_Big_Endian
then
4680 Set_Reverse_Bit_Order
(Base_Type
(U_Ent
), True);
4686 --------------------
4687 -- Component_Size --
4688 --------------------
4690 -- Component_Size attribute definition clause
4692 when Attribute_Component_Size
=> Component_Size_Case
: declare
4693 Csize
: constant Uint
:= Static_Integer
(Expr
);
4697 New_Ctyp
: Entity_Id
;
4701 if not Is_Array_Type
(U_Ent
) then
4702 Error_Msg_N
("component size requires array type", Nam
);
4706 Btype
:= Base_Type
(U_Ent
);
4707 Ctyp
:= Component_Type
(Btype
);
4709 if Duplicate_Clause
then
4712 elsif Rep_Item_Too_Early
(Btype
, N
) then
4715 elsif Csize
/= No_Uint
then
4716 Check_Size
(Expr
, Ctyp
, Csize
, Biased
);
4718 -- For the biased case, build a declaration for a subtype that
4719 -- will be used to represent the biased subtype that reflects
4720 -- the biased representation of components. We need the subtype
4721 -- to get proper conversions on referencing elements of the
4722 -- array. Note: component size clauses are ignored in VM mode.
4724 if VM_Target
= No_VM
then
4727 Make_Defining_Identifier
(Loc
,
4729 New_External_Name
(Chars
(U_Ent
), 'C', 0, 'T'));
4732 Make_Subtype_Declaration
(Loc
,
4733 Defining_Identifier
=> New_Ctyp
,
4734 Subtype_Indication
=>
4735 New_Occurrence_Of
(Component_Type
(Btype
), Loc
));
4737 Set_Parent
(Decl
, N
);
4738 Analyze
(Decl
, Suppress
=> All_Checks
);
4740 Set_Has_Delayed_Freeze
(New_Ctyp
, False);
4741 Set_Esize
(New_Ctyp
, Csize
);
4742 Set_RM_Size
(New_Ctyp
, Csize
);
4743 Init_Alignment
(New_Ctyp
);
4744 Set_Is_Itype
(New_Ctyp
, True);
4745 Set_Associated_Node_For_Itype
(New_Ctyp
, U_Ent
);
4747 Set_Component_Type
(Btype
, New_Ctyp
);
4748 Set_Biased
(New_Ctyp
, N
, "component size clause");
4751 Set_Component_Size
(Btype
, Csize
);
4753 -- For VM case, we ignore component size clauses
4756 -- Give a warning unless we are in GNAT mode, in which case
4757 -- the warning is suppressed since it is not useful.
4759 if not GNAT_Mode
then
4761 ("component size ignored in this configuration??", N
);
4765 -- Deal with warning on overridden size
4767 if Warn_On_Overridden_Size
4768 and then Has_Size_Clause
(Ctyp
)
4769 and then RM_Size
(Ctyp
) /= Csize
4772 ("component size overrides size clause for&?S?", N
, Ctyp
);
4775 Set_Has_Component_Size_Clause
(Btype
, True);
4776 Set_Has_Non_Standard_Rep
(Btype
, True);
4778 end Component_Size_Case
;
4780 -----------------------
4781 -- Constant_Indexing --
4782 -----------------------
4784 when Attribute_Constant_Indexing
=>
4785 Check_Indexing_Functions
;
4791 when Attribute_CPU
=> CPU
:
4793 -- CPU attribute definition clause not allowed except from aspect
4796 if From_Aspect_Specification
(N
) then
4797 if not Is_Task_Type
(U_Ent
) then
4798 Error_Msg_N
("CPU can only be defined for task", Nam
);
4800 elsif Duplicate_Clause
then
4804 -- The expression must be analyzed in the special manner
4805 -- described in "Handling of Default and Per-Object
4806 -- Expressions" in sem.ads.
4808 -- The visibility to the discriminants must be restored
4810 Push_Scope_And_Install_Discriminants
(U_Ent
);
4811 Preanalyze_Spec_Expression
(Expr
, RTE
(RE_CPU_Range
));
4812 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
4814 if not Is_OK_Static_Expression
(Expr
) then
4815 Check_Restriction
(Static_Priorities
, Expr
);
4821 ("attribute& cannot be set with definition clause", N
);
4825 ----------------------
4826 -- Default_Iterator --
4827 ----------------------
4829 when Attribute_Default_Iterator
=> Default_Iterator
: declare
4834 if not Is_Tagged_Type
(U_Ent
) then
4836 ("aspect Default_Iterator applies to tagged type", Nam
);
4839 Check_Iterator_Functions
;
4843 if not Is_Entity_Name
(Expr
)
4844 or else Ekind
(Entity
(Expr
)) /= E_Function
4846 Error_Msg_N
("aspect Iterator must be a function", Expr
);
4848 Func
:= Entity
(Expr
);
4851 -- The type of the first parameter must be T, T'class, or a
4852 -- corresponding access type (5.5.1 (8/3)
4854 if No
(First_Formal
(Func
)) then
4857 Typ
:= Etype
(First_Formal
(Func
));
4861 or else Typ
= Class_Wide_Type
(U_Ent
)
4862 or else (Is_Access_Type
(Typ
)
4863 and then Designated_Type
(Typ
) = U_Ent
)
4864 or else (Is_Access_Type
(Typ
)
4865 and then Designated_Type
(Typ
) =
4866 Class_Wide_Type
(U_Ent
))
4872 ("Default Iterator must be a primitive of&", Func
, U_Ent
);
4874 end Default_Iterator
;
4876 ------------------------
4877 -- Dispatching_Domain --
4878 ------------------------
4880 when Attribute_Dispatching_Domain
=> Dispatching_Domain
:
4882 -- Dispatching_Domain attribute definition clause not allowed
4883 -- except from aspect specification.
4885 if From_Aspect_Specification
(N
) then
4886 if not Is_Task_Type
(U_Ent
) then
4888 ("Dispatching_Domain can only be defined for task", Nam
);
4890 elsif Duplicate_Clause
then
4894 -- The expression must be analyzed in the special manner
4895 -- described in "Handling of Default and Per-Object
4896 -- Expressions" in sem.ads.
4898 -- The visibility to the discriminants must be restored
4900 Push_Scope_And_Install_Discriminants
(U_Ent
);
4902 Preanalyze_Spec_Expression
4903 (Expr
, RTE
(RE_Dispatching_Domain
));
4905 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
4910 ("attribute& cannot be set with definition clause", N
);
4912 end Dispatching_Domain
;
4918 when Attribute_External_Tag
=> External_Tag
:
4920 if not Is_Tagged_Type
(U_Ent
) then
4921 Error_Msg_N
("should be a tagged type", Nam
);
4924 if Duplicate_Clause
then
4928 Analyze_And_Resolve
(Expr
, Standard_String
);
4930 if not Is_OK_Static_Expression
(Expr
) then
4931 Flag_Non_Static_Expr
4932 ("static string required for tag name!", Nam
);
4935 if VM_Target
/= No_VM
then
4936 Error_Msg_Name_1
:= Attr
;
4938 ("% attribute unsupported in this configuration", Nam
);
4941 if not Is_Library_Level_Entity
(U_Ent
) then
4943 ("??non-unique external tag supplied for &", N
, U_Ent
);
4945 ("\??same external tag applies to all "
4946 & "subprogram calls", N
);
4948 ("\??corresponding internal tag cannot be obtained", N
);
4953 --------------------------
4954 -- Implicit_Dereference --
4955 --------------------------
4957 when Attribute_Implicit_Dereference
=>
4959 -- Legality checks already performed at the point of the type
4960 -- declaration, aspect is not delayed.
4968 when Attribute_Input
=>
4969 Analyze_Stream_TSS_Definition
(TSS_Stream_Input
);
4970 Set_Has_Specified_Stream_Input
(Ent
);
4972 ------------------------
4973 -- Interrupt_Priority --
4974 ------------------------
4976 when Attribute_Interrupt_Priority
=> Interrupt_Priority
:
4978 -- Interrupt_Priority attribute definition clause not allowed
4979 -- except from aspect specification.
4981 if From_Aspect_Specification
(N
) then
4982 if not Is_Concurrent_Type
(U_Ent
) then
4984 ("Interrupt_Priority can only be defined for task "
4985 & "and protected object", Nam
);
4987 elsif Duplicate_Clause
then
4991 -- The expression must be analyzed in the special manner
4992 -- described in "Handling of Default and Per-Object
4993 -- Expressions" in sem.ads.
4995 -- The visibility to the discriminants must be restored
4997 Push_Scope_And_Install_Discriminants
(U_Ent
);
4999 Preanalyze_Spec_Expression
5000 (Expr
, RTE
(RE_Interrupt_Priority
));
5002 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
5007 ("attribute& cannot be set with definition clause", N
);
5009 end Interrupt_Priority
;
5015 when Attribute_Iterable
=>
5018 if Nkind
(Expr
) /= N_Aggregate
then
5019 Error_Msg_N
("aspect Iterable must be an aggregate", Expr
);
5026 Assoc
:= First
(Component_Associations
(Expr
));
5027 while Present
(Assoc
) loop
5028 if not Is_Entity_Name
(Expression
(Assoc
)) then
5029 Error_Msg_N
("value must be a function", Assoc
);
5036 ----------------------
5037 -- Iterator_Element --
5038 ----------------------
5040 when Attribute_Iterator_Element
=>
5043 if not Is_Entity_Name
(Expr
)
5044 or else not Is_Type
(Entity
(Expr
))
5046 Error_Msg_N
("aspect Iterator_Element must be a type", Expr
);
5053 -- Machine radix attribute definition clause
5055 when Attribute_Machine_Radix
=> Machine_Radix
: declare
5056 Radix
: constant Uint
:= Static_Integer
(Expr
);
5059 if not Is_Decimal_Fixed_Point_Type
(U_Ent
) then
5060 Error_Msg_N
("decimal fixed-point type expected for &", Nam
);
5062 elsif Duplicate_Clause
then
5065 elsif Radix
/= No_Uint
then
5066 Set_Has_Machine_Radix_Clause
(U_Ent
);
5067 Set_Has_Non_Standard_Rep
(Base_Type
(U_Ent
));
5071 elsif Radix
= 10 then
5072 Set_Machine_Radix_10
(U_Ent
);
5074 Error_Msg_N
("machine radix value must be 2 or 10", Expr
);
5083 -- Object_Size attribute definition clause
5085 when Attribute_Object_Size
=> Object_Size
: declare
5086 Size
: constant Uint
:= Static_Integer
(Expr
);
5089 pragma Warnings
(Off
, Biased
);
5092 if not Is_Type
(U_Ent
) then
5093 Error_Msg_N
("Object_Size cannot be given for &", Nam
);
5095 elsif Duplicate_Clause
then
5099 Check_Size
(Expr
, U_Ent
, Size
, Biased
);
5101 if Is_Scalar_Type
(U_Ent
) then
5102 if Size
/= 8 and then Size
/= 16 and then Size
/= 32
5103 and then UI_Mod
(Size
, 64) /= 0
5106 ("Object_Size must be 8, 16, 32, or multiple of 64",
5110 elsif Size
mod 8 /= 0 then
5111 Error_Msg_N
("Object_Size must be a multiple of 8", Expr
);
5114 Set_Esize
(U_Ent
, Size
);
5115 Set_Has_Object_Size_Clause
(U_Ent
);
5116 Alignment_Check_For_Size_Change
(U_Ent
, Size
);
5124 when Attribute_Output
=>
5125 Analyze_Stream_TSS_Definition
(TSS_Stream_Output
);
5126 Set_Has_Specified_Stream_Output
(Ent
);
5132 when Attribute_Priority
=> Priority
:
5134 -- Priority attribute definition clause not allowed except from
5135 -- aspect specification.
5137 if From_Aspect_Specification
(N
) then
5138 if not (Is_Concurrent_Type
(U_Ent
)
5139 or else Ekind
(U_Ent
) = E_Procedure
)
5142 ("Priority can only be defined for task and protected "
5145 elsif Duplicate_Clause
then
5149 -- The expression must be analyzed in the special manner
5150 -- described in "Handling of Default and Per-Object
5151 -- Expressions" in sem.ads.
5153 -- The visibility to the discriminants must be restored
5155 Push_Scope_And_Install_Discriminants
(U_Ent
);
5156 Preanalyze_Spec_Expression
(Expr
, Standard_Integer
);
5157 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
5159 if not Is_OK_Static_Expression
(Expr
) then
5160 Check_Restriction
(Static_Priorities
, Expr
);
5166 ("attribute& cannot be set with definition clause", N
);
5174 when Attribute_Read
=>
5175 Analyze_Stream_TSS_Definition
(TSS_Stream_Read
);
5176 Set_Has_Specified_Stream_Read
(Ent
);
5178 --------------------------
5179 -- Scalar_Storage_Order --
5180 --------------------------
5182 -- Scalar_Storage_Order attribute definition clause
5184 when Attribute_Scalar_Storage_Order
=> Scalar_Storage_Order
: declare
5186 if not (Is_Record_Type
(U_Ent
) or else Is_Array_Type
(U_Ent
)) then
5188 ("Scalar_Storage_Order can only be defined for "
5189 & "record or array type", Nam
);
5191 elsif Duplicate_Clause
then
5195 Analyze_And_Resolve
(Expr
, RTE
(RE_Bit_Order
));
5197 if Etype
(Expr
) = Any_Type
then
5200 elsif not Is_OK_Static_Expression
(Expr
) then
5201 Flag_Non_Static_Expr
5202 ("Scalar_Storage_Order requires static expression!", Expr
);
5204 elsif (Expr_Value
(Expr
) = 0) /= Bytes_Big_Endian
then
5206 -- Here for the case of a non-default (i.e. non-confirming)
5207 -- Scalar_Storage_Order attribute definition.
5209 if Support_Nondefault_SSO_On_Target
then
5210 Set_Reverse_Storage_Order
(Base_Type
(U_Ent
), True);
5213 ("non-default Scalar_Storage_Order "
5214 & "not supported on target", Expr
);
5218 -- Clear SSO default indications since explicit setting of the
5219 -- order overrides the defaults.
5221 Set_SSO_Set_Low_By_Default
(Base_Type
(U_Ent
), False);
5222 Set_SSO_Set_High_By_Default
(Base_Type
(U_Ent
), False);
5224 end Scalar_Storage_Order
;
5230 -- Size attribute definition clause
5232 when Attribute_Size
=> Size
: declare
5233 Size
: constant Uint
:= Static_Integer
(Expr
);
5240 if Duplicate_Clause
then
5243 elsif not Is_Type
(U_Ent
)
5244 and then Ekind
(U_Ent
) /= E_Variable
5245 and then Ekind
(U_Ent
) /= E_Constant
5247 Error_Msg_N
("size cannot be given for &", Nam
);
5249 elsif Is_Array_Type
(U_Ent
)
5250 and then not Is_Constrained
(U_Ent
)
5253 ("size cannot be given for unconstrained array", Nam
);
5255 elsif Size
/= No_Uint
then
5256 if VM_Target
/= No_VM
and then not GNAT_Mode
then
5258 -- Size clause is not handled properly on VM targets.
5259 -- Display a warning unless we are in GNAT mode, in which
5260 -- case this is useless.
5263 ("size clauses are ignored in this configuration??", N
);
5266 if Is_Type
(U_Ent
) then
5269 Etyp
:= Etype
(U_Ent
);
5272 -- Check size, note that Gigi is in charge of checking that the
5273 -- size of an array or record type is OK. Also we do not check
5274 -- the size in the ordinary fixed-point case, since it is too
5275 -- early to do so (there may be subsequent small clause that
5276 -- affects the size). We can check the size if a small clause
5277 -- has already been given.
5279 if not Is_Ordinary_Fixed_Point_Type
(U_Ent
)
5280 or else Has_Small_Clause
(U_Ent
)
5282 Check_Size
(Expr
, Etyp
, Size
, Biased
);
5283 Set_Biased
(U_Ent
, N
, "size clause", Biased
);
5286 -- For types set RM_Size and Esize if possible
5288 if Is_Type
(U_Ent
) then
5289 Set_RM_Size
(U_Ent
, Size
);
5291 -- For elementary types, increase Object_Size to power of 2,
5292 -- but not less than a storage unit in any case (normally
5293 -- this means it will be byte addressable).
5295 -- For all other types, nothing else to do, we leave Esize
5296 -- (object size) unset, the back end will set it from the
5297 -- size and alignment in an appropriate manner.
5299 -- In both cases, we check whether the alignment must be
5300 -- reset in the wake of the size change.
5302 if Is_Elementary_Type
(U_Ent
) then
5303 if Size
<= System_Storage_Unit
then
5304 Init_Esize
(U_Ent
, System_Storage_Unit
);
5305 elsif Size
<= 16 then
5306 Init_Esize
(U_Ent
, 16);
5307 elsif Size
<= 32 then
5308 Init_Esize
(U_Ent
, 32);
5310 Set_Esize
(U_Ent
, (Size
+ 63) / 64 * 64);
5313 Alignment_Check_For_Size_Change
(U_Ent
, Esize
(U_Ent
));
5315 Alignment_Check_For_Size_Change
(U_Ent
, Size
);
5318 -- For objects, set Esize only
5321 if Is_Elementary_Type
(Etyp
) then
5322 if Size
/= System_Storage_Unit
5324 Size
/= System_Storage_Unit
* 2
5326 Size
/= System_Storage_Unit
* 4
5328 Size
/= System_Storage_Unit
* 8
5330 Error_Msg_Uint_1
:= UI_From_Int
(System_Storage_Unit
);
5331 Error_Msg_Uint_2
:= Error_Msg_Uint_1
* 8;
5333 ("size for primitive object must be a power of 2"
5334 & " in the range ^-^", N
);
5338 Set_Esize
(U_Ent
, Size
);
5341 Set_Has_Size_Clause
(U_Ent
);
5349 -- Small attribute definition clause
5351 when Attribute_Small
=> Small
: declare
5352 Implicit_Base
: constant Entity_Id
:= Base_Type
(U_Ent
);
5356 Analyze_And_Resolve
(Expr
, Any_Real
);
5358 if Etype
(Expr
) = Any_Type
then
5361 elsif not Is_OK_Static_Expression
(Expr
) then
5362 Flag_Non_Static_Expr
5363 ("small requires static expression!", Expr
);
5367 Small
:= Expr_Value_R
(Expr
);
5369 if Small
<= Ureal_0
then
5370 Error_Msg_N
("small value must be greater than zero", Expr
);
5376 if not Is_Ordinary_Fixed_Point_Type
(U_Ent
) then
5378 ("small requires an ordinary fixed point type", Nam
);
5380 elsif Has_Small_Clause
(U_Ent
) then
5381 Error_Msg_N
("small already given for &", Nam
);
5383 elsif Small
> Delta_Value
(U_Ent
) then
5385 ("small value must not be greater than delta value", Nam
);
5388 Set_Small_Value
(U_Ent
, Small
);
5389 Set_Small_Value
(Implicit_Base
, Small
);
5390 Set_Has_Small_Clause
(U_Ent
);
5391 Set_Has_Small_Clause
(Implicit_Base
);
5392 Set_Has_Non_Standard_Rep
(Implicit_Base
);
5400 -- Storage_Pool attribute definition clause
5402 when Attribute_Storage_Pool | Attribute_Simple_Storage_Pool
=> declare
5407 if Ekind
(U_Ent
) = E_Access_Subprogram_Type
then
5409 ("storage pool cannot be given for access-to-subprogram type",
5414 Ekind_In
(U_Ent
, E_Access_Type
, E_General_Access_Type
)
5417 ("storage pool can only be given for access types", Nam
);
5420 elsif Is_Derived_Type
(U_Ent
) then
5422 ("storage pool cannot be given for a derived access type",
5425 elsif Duplicate_Clause
then
5428 elsif Present
(Associated_Storage_Pool
(U_Ent
)) then
5429 Error_Msg_N
("storage pool already given for &", Nam
);
5433 -- Check for Storage_Size previously given
5436 SS
: constant Node_Id
:=
5437 Get_Attribute_Definition_Clause
5438 (U_Ent
, Attribute_Storage_Size
);
5440 if Present
(SS
) then
5441 Check_Pool_Size_Clash
(U_Ent
, N
, SS
);
5445 -- Storage_Pool case
5447 if Id
= Attribute_Storage_Pool
then
5449 (Expr
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
5451 -- In the Simple_Storage_Pool case, we allow a variable of any
5452 -- simple storage pool type, so we Resolve without imposing an
5456 Analyze_And_Resolve
(Expr
);
5458 if not Present
(Get_Rep_Pragma
5459 (Etype
(Expr
), Name_Simple_Storage_Pool_Type
))
5462 ("expression must be of a simple storage pool type", Expr
);
5466 if not Denotes_Variable
(Expr
) then
5467 Error_Msg_N
("storage pool must be a variable", Expr
);
5471 if Nkind
(Expr
) = N_Type_Conversion
then
5472 T
:= Etype
(Expression
(Expr
));
5477 -- The Stack_Bounded_Pool is used internally for implementing
5478 -- access types with a Storage_Size. Since it only work properly
5479 -- when used on one specific type, we need to check that it is not
5480 -- hijacked improperly:
5482 -- type T is access Integer;
5483 -- for T'Storage_Size use n;
5484 -- type Q is access Float;
5485 -- for Q'Storage_Size use T'Storage_Size; -- incorrect
5487 if RTE_Available
(RE_Stack_Bounded_Pool
)
5488 and then Base_Type
(T
) = RTE
(RE_Stack_Bounded_Pool
)
5490 Error_Msg_N
("non-shareable internal Pool", Expr
);
5494 -- If the argument is a name that is not an entity name, then
5495 -- we construct a renaming operation to define an entity of
5496 -- type storage pool.
5498 if not Is_Entity_Name
(Expr
)
5499 and then Is_Object_Reference
(Expr
)
5501 Pool
:= Make_Temporary
(Loc
, 'P', Expr
);
5504 Rnode
: constant Node_Id
:=
5505 Make_Object_Renaming_Declaration
(Loc
,
5506 Defining_Identifier
=> Pool
,
5508 New_Occurrence_Of
(Etype
(Expr
), Loc
),
5512 -- If the attribute definition clause comes from an aspect
5513 -- clause, then insert the renaming before the associated
5514 -- entity's declaration, since the attribute clause has
5515 -- not yet been appended to the declaration list.
5517 if From_Aspect_Specification
(N
) then
5518 Insert_Before
(Parent
(Entity
(N
)), Rnode
);
5520 Insert_Before
(N
, Rnode
);
5524 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
5527 elsif Is_Entity_Name
(Expr
) then
5528 Pool
:= Entity
(Expr
);
5530 -- If pool is a renamed object, get original one. This can
5531 -- happen with an explicit renaming, and within instances.
5533 while Present
(Renamed_Object
(Pool
))
5534 and then Is_Entity_Name
(Renamed_Object
(Pool
))
5536 Pool
:= Entity
(Renamed_Object
(Pool
));
5539 if Present
(Renamed_Object
(Pool
))
5540 and then Nkind
(Renamed_Object
(Pool
)) = N_Type_Conversion
5541 and then Is_Entity_Name
(Expression
(Renamed_Object
(Pool
)))
5543 Pool
:= Entity
(Expression
(Renamed_Object
(Pool
)));
5546 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
5548 elsif Nkind
(Expr
) = N_Type_Conversion
5549 and then Is_Entity_Name
(Expression
(Expr
))
5550 and then Nkind
(Original_Node
(Expr
)) = N_Attribute_Reference
5552 Pool
:= Entity
(Expression
(Expr
));
5553 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
5556 Error_Msg_N
("incorrect reference to a Storage Pool", Expr
);
5565 -- Storage_Size attribute definition clause
5567 when Attribute_Storage_Size
=> Storage_Size
: declare
5568 Btype
: constant Entity_Id
:= Base_Type
(U_Ent
);
5571 if Is_Task_Type
(U_Ent
) then
5573 -- Check obsolescent (but never obsolescent if from aspect)
5575 if not From_Aspect_Specification
(N
) then
5576 Check_Restriction
(No_Obsolescent_Features
, N
);
5578 if Warn_On_Obsolescent_Feature
then
5580 ("?j?storage size clause for task is an " &
5581 "obsolescent feature (RM J.9)", N
);
5582 Error_Msg_N
("\?j?use Storage_Size pragma instead", N
);
5589 if not Is_Access_Type
(U_Ent
)
5590 and then Ekind
(U_Ent
) /= E_Task_Type
5592 Error_Msg_N
("storage size cannot be given for &", Nam
);
5594 elsif Is_Access_Type
(U_Ent
) and Is_Derived_Type
(U_Ent
) then
5596 ("storage size cannot be given for a derived access type",
5599 elsif Duplicate_Clause
then
5603 Analyze_And_Resolve
(Expr
, Any_Integer
);
5605 if Is_Access_Type
(U_Ent
) then
5607 -- Check for Storage_Pool previously given
5610 SP
: constant Node_Id
:=
5611 Get_Attribute_Definition_Clause
5612 (U_Ent
, Attribute_Storage_Pool
);
5615 if Present
(SP
) then
5616 Check_Pool_Size_Clash
(U_Ent
, SP
, N
);
5620 -- Special case of for x'Storage_Size use 0
5622 if Is_OK_Static_Expression
(Expr
)
5623 and then Expr_Value
(Expr
) = 0
5625 Set_No_Pool_Assigned
(Btype
);
5629 Set_Has_Storage_Size_Clause
(Btype
);
5637 when Attribute_Stream_Size
=> Stream_Size
: declare
5638 Size
: constant Uint
:= Static_Integer
(Expr
);
5641 if Ada_Version
<= Ada_95
then
5642 Check_Restriction
(No_Implementation_Attributes
, N
);
5645 if Duplicate_Clause
then
5648 elsif Is_Elementary_Type
(U_Ent
) then
5649 if Size
/= System_Storage_Unit
5651 Size
/= System_Storage_Unit
* 2
5653 Size
/= System_Storage_Unit
* 4
5655 Size
/= System_Storage_Unit
* 8
5657 Error_Msg_Uint_1
:= UI_From_Int
(System_Storage_Unit
);
5659 ("stream size for elementary type must be a"
5660 & " power of 2 and at least ^", N
);
5662 elsif RM_Size
(U_Ent
) > Size
then
5663 Error_Msg_Uint_1
:= RM_Size
(U_Ent
);
5665 ("stream size for elementary type must be a"
5666 & " power of 2 and at least ^", N
);
5669 Set_Has_Stream_Size_Clause
(U_Ent
);
5672 Error_Msg_N
("Stream_Size cannot be given for &", Nam
);
5680 -- Value_Size attribute definition clause
5682 when Attribute_Value_Size
=> Value_Size
: declare
5683 Size
: constant Uint
:= Static_Integer
(Expr
);
5687 if not Is_Type
(U_Ent
) then
5688 Error_Msg_N
("Value_Size cannot be given for &", Nam
);
5690 elsif Duplicate_Clause
then
5693 elsif Is_Array_Type
(U_Ent
)
5694 and then not Is_Constrained
(U_Ent
)
5697 ("Value_Size cannot be given for unconstrained array", Nam
);
5700 if Is_Elementary_Type
(U_Ent
) then
5701 Check_Size
(Expr
, U_Ent
, Size
, Biased
);
5702 Set_Biased
(U_Ent
, N
, "value size clause", Biased
);
5705 Set_RM_Size
(U_Ent
, Size
);
5709 -----------------------
5710 -- Variable_Indexing --
5711 -----------------------
5713 when Attribute_Variable_Indexing
=>
5714 Check_Indexing_Functions
;
5720 when Attribute_Write
=>
5721 Analyze_Stream_TSS_Definition
(TSS_Stream_Write
);
5722 Set_Has_Specified_Stream_Write
(Ent
);
5724 -- All other attributes cannot be set
5728 ("attribute& cannot be set with definition clause", N
);
5731 -- The test for the type being frozen must be performed after any
5732 -- expression the clause has been analyzed since the expression itself
5733 -- might cause freezing that makes the clause illegal.
5735 if Rep_Item_Too_Late
(U_Ent
, N
, FOnly
) then
5738 end Analyze_Attribute_Definition_Clause
;
5740 ----------------------------
5741 -- Analyze_Code_Statement --
5742 ----------------------------
5744 procedure Analyze_Code_Statement
(N
: Node_Id
) is
5745 HSS
: constant Node_Id
:= Parent
(N
);
5746 SBody
: constant Node_Id
:= Parent
(HSS
);
5747 Subp
: constant Entity_Id
:= Current_Scope
;
5754 -- Analyze and check we get right type, note that this implements the
5755 -- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that
5756 -- is the only way that Asm_Insn could possibly be visible.
5758 Analyze_And_Resolve
(Expression
(N
));
5760 if Etype
(Expression
(N
)) = Any_Type
then
5762 elsif Etype
(Expression
(N
)) /= RTE
(RE_Asm_Insn
) then
5763 Error_Msg_N
("incorrect type for code statement", N
);
5767 Check_Code_Statement
(N
);
5769 -- Make sure we appear in the handled statement sequence of a
5770 -- subprogram (RM 13.8(3)).
5772 if Nkind
(HSS
) /= N_Handled_Sequence_Of_Statements
5773 or else Nkind
(SBody
) /= N_Subprogram_Body
5776 ("code statement can only appear in body of subprogram", N
);
5780 -- Do remaining checks (RM 13.8(3)) if not already done
5782 if not Is_Machine_Code_Subprogram
(Subp
) then
5783 Set_Is_Machine_Code_Subprogram
(Subp
);
5785 -- No exception handlers allowed
5787 if Present
(Exception_Handlers
(HSS
)) then
5789 ("exception handlers not permitted in machine code subprogram",
5790 First
(Exception_Handlers
(HSS
)));
5793 -- No declarations other than use clauses and pragmas (we allow
5794 -- certain internally generated declarations as well).
5796 Decl
:= First
(Declarations
(SBody
));
5797 while Present
(Decl
) loop
5798 DeclO
:= Original_Node
(Decl
);
5799 if Comes_From_Source
(DeclO
)
5800 and not Nkind_In
(DeclO
, N_Pragma
,
5801 N_Use_Package_Clause
,
5803 N_Implicit_Label_Declaration
)
5806 ("this declaration not allowed in machine code subprogram",
5813 -- No statements other than code statements, pragmas, and labels.
5814 -- Again we allow certain internally generated statements.
5816 -- In Ada 2012, qualified expressions are names, and the code
5817 -- statement is initially parsed as a procedure call.
5819 Stmt
:= First
(Statements
(HSS
));
5820 while Present
(Stmt
) loop
5821 StmtO
:= Original_Node
(Stmt
);
5823 -- A procedure call transformed into a code statement is OK.
5825 if Ada_Version
>= Ada_2012
5826 and then Nkind
(StmtO
) = N_Procedure_Call_Statement
5827 and then Nkind
(Name
(StmtO
)) = N_Qualified_Expression
5831 elsif Comes_From_Source
(StmtO
)
5832 and then not Nkind_In
(StmtO
, N_Pragma
,
5837 ("this statement is not allowed in machine code subprogram",
5844 end Analyze_Code_Statement
;
5846 -----------------------------------------------
5847 -- Analyze_Enumeration_Representation_Clause --
5848 -----------------------------------------------
5850 procedure Analyze_Enumeration_Representation_Clause
(N
: Node_Id
) is
5851 Ident
: constant Node_Id
:= Identifier
(N
);
5852 Aggr
: constant Node_Id
:= Array_Aggregate
(N
);
5853 Enumtype
: Entity_Id
;
5860 Err
: Boolean := False;
5861 -- Set True to avoid cascade errors and crashes on incorrect source code
5863 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Universal_Integer
));
5864 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(Universal_Integer
));
5865 -- Allowed range of universal integer (= allowed range of enum lit vals)
5869 -- Minimum and maximum values of entries
5872 -- Pointer to node for literal providing max value
5875 if Ignore_Rep_Clauses
then
5876 Kill_Rep_Clause
(N
);
5880 -- Ignore enumeration rep clauses by default in CodePeer mode,
5881 -- unless -gnatd.I is specified, as a work around for potential false
5882 -- positive messages.
5884 if CodePeer_Mode
and not Debug_Flag_Dot_II
then
5888 -- First some basic error checks
5891 Enumtype
:= Entity
(Ident
);
5893 if Enumtype
= Any_Type
5894 or else Rep_Item_Too_Early
(Enumtype
, N
)
5898 Enumtype
:= Underlying_Type
(Enumtype
);
5901 if not Is_Enumeration_Type
(Enumtype
) then
5903 ("enumeration type required, found}",
5904 Ident
, First_Subtype
(Enumtype
));
5908 -- Ignore rep clause on generic actual type. This will already have
5909 -- been flagged on the template as an error, and this is the safest
5910 -- way to ensure we don't get a junk cascaded message in the instance.
5912 if Is_Generic_Actual_Type
(Enumtype
) then
5915 -- Type must be in current scope
5917 elsif Scope
(Enumtype
) /= Current_Scope
then
5918 Error_Msg_N
("type must be declared in this scope", Ident
);
5921 -- Type must be a first subtype
5923 elsif not Is_First_Subtype
(Enumtype
) then
5924 Error_Msg_N
("cannot give enumeration rep clause for subtype", N
);
5927 -- Ignore duplicate rep clause
5929 elsif Has_Enumeration_Rep_Clause
(Enumtype
) then
5930 Error_Msg_N
("duplicate enumeration rep clause ignored", N
);
5933 -- Don't allow rep clause for standard [wide_[wide_]]character
5935 elsif Is_Standard_Character_Type
(Enumtype
) then
5936 Error_Msg_N
("enumeration rep clause not allowed for this type", N
);
5939 -- Check that the expression is a proper aggregate (no parentheses)
5941 elsif Paren_Count
(Aggr
) /= 0 then
5943 ("extra parentheses surrounding aggregate not allowed",
5947 -- All tests passed, so set rep clause in place
5950 Set_Has_Enumeration_Rep_Clause
(Enumtype
);
5951 Set_Has_Enumeration_Rep_Clause
(Base_Type
(Enumtype
));
5954 -- Now we process the aggregate. Note that we don't use the normal
5955 -- aggregate code for this purpose, because we don't want any of the
5956 -- normal expansion activities, and a number of special semantic
5957 -- rules apply (including the component type being any integer type)
5959 Elit
:= First_Literal
(Enumtype
);
5961 -- First the positional entries if any
5963 if Present
(Expressions
(Aggr
)) then
5964 Expr
:= First
(Expressions
(Aggr
));
5965 while Present
(Expr
) loop
5967 Error_Msg_N
("too many entries in aggregate", Expr
);
5971 Val
:= Static_Integer
(Expr
);
5973 -- Err signals that we found some incorrect entries processing
5974 -- the list. The final checks for completeness and ordering are
5975 -- skipped in this case.
5977 if Val
= No_Uint
then
5980 elsif Val
< Lo
or else Hi
< Val
then
5981 Error_Msg_N
("value outside permitted range", Expr
);
5985 Set_Enumeration_Rep
(Elit
, Val
);
5986 Set_Enumeration_Rep_Expr
(Elit
, Expr
);
5992 -- Now process the named entries if present
5994 if Present
(Component_Associations
(Aggr
)) then
5995 Assoc
:= First
(Component_Associations
(Aggr
));
5996 while Present
(Assoc
) loop
5997 Choice
:= First
(Choices
(Assoc
));
5999 if Present
(Next
(Choice
)) then
6001 ("multiple choice not allowed here", Next
(Choice
));
6005 if Nkind
(Choice
) = N_Others_Choice
then
6006 Error_Msg_N
("others choice not allowed here", Choice
);
6009 elsif Nkind
(Choice
) = N_Range
then
6011 -- ??? should allow zero/one element range here
6013 Error_Msg_N
("range not allowed here", Choice
);
6017 Analyze_And_Resolve
(Choice
, Enumtype
);
6019 if Error_Posted
(Choice
) then
6024 if Is_Entity_Name
(Choice
)
6025 and then Is_Type
(Entity
(Choice
))
6027 Error_Msg_N
("subtype name not allowed here", Choice
);
6030 -- ??? should allow static subtype with zero/one entry
6032 elsif Etype
(Choice
) = Base_Type
(Enumtype
) then
6033 if not Is_OK_Static_Expression
(Choice
) then
6034 Flag_Non_Static_Expr
6035 ("non-static expression used for choice!", Choice
);
6039 Elit
:= Expr_Value_E
(Choice
);
6041 if Present
(Enumeration_Rep_Expr
(Elit
)) then
6043 Sloc
(Enumeration_Rep_Expr
(Elit
));
6045 ("representation for& previously given#",
6050 Set_Enumeration_Rep_Expr
(Elit
, Expression
(Assoc
));
6052 Expr
:= Expression
(Assoc
);
6053 Val
:= Static_Integer
(Expr
);
6055 if Val
= No_Uint
then
6058 elsif Val
< Lo
or else Hi
< Val
then
6059 Error_Msg_N
("value outside permitted range", Expr
);
6063 Set_Enumeration_Rep
(Elit
, Val
);
6073 -- Aggregate is fully processed. Now we check that a full set of
6074 -- representations was given, and that they are in range and in order.
6075 -- These checks are only done if no other errors occurred.
6081 Elit
:= First_Literal
(Enumtype
);
6082 while Present
(Elit
) loop
6083 if No
(Enumeration_Rep_Expr
(Elit
)) then
6084 Error_Msg_NE
("missing representation for&!", N
, Elit
);
6087 Val
:= Enumeration_Rep
(Elit
);
6089 if Min
= No_Uint
then
6093 if Val
/= No_Uint
then
6094 if Max
/= No_Uint
and then Val
<= Max
then
6096 ("enumeration value for& not ordered!",
6097 Enumeration_Rep_Expr
(Elit
), Elit
);
6100 Max_Node
:= Enumeration_Rep_Expr
(Elit
);
6104 -- If there is at least one literal whose representation is not
6105 -- equal to the Pos value, then note that this enumeration type
6106 -- has a non-standard representation.
6108 if Val
/= Enumeration_Pos
(Elit
) then
6109 Set_Has_Non_Standard_Rep
(Base_Type
(Enumtype
));
6116 -- Now set proper size information
6119 Minsize
: Uint
:= UI_From_Int
(Minimum_Size
(Enumtype
));
6122 if Has_Size_Clause
(Enumtype
) then
6124 -- All OK, if size is OK now
6126 if RM_Size
(Enumtype
) >= Minsize
then
6130 -- Try if we can get by with biasing
6133 UI_From_Int
(Minimum_Size
(Enumtype
, Biased
=> True));
6135 -- Error message if even biasing does not work
6137 if RM_Size
(Enumtype
) < Minsize
then
6138 Error_Msg_Uint_1
:= RM_Size
(Enumtype
);
6139 Error_Msg_Uint_2
:= Max
;
6141 ("previously given size (^) is too small "
6142 & "for this value (^)", Max_Node
);
6144 -- If biasing worked, indicate that we now have biased rep
6148 (Enumtype
, Size_Clause
(Enumtype
), "size clause");
6153 Set_RM_Size
(Enumtype
, Minsize
);
6154 Set_Enum_Esize
(Enumtype
);
6157 Set_RM_Size
(Base_Type
(Enumtype
), RM_Size
(Enumtype
));
6158 Set_Esize
(Base_Type
(Enumtype
), Esize
(Enumtype
));
6159 Set_Alignment
(Base_Type
(Enumtype
), Alignment
(Enumtype
));
6163 -- We repeat the too late test in case it froze itself
6165 if Rep_Item_Too_Late
(Enumtype
, N
) then
6168 end Analyze_Enumeration_Representation_Clause
;
6170 ----------------------------
6171 -- Analyze_Free_Statement --
6172 ----------------------------
6174 procedure Analyze_Free_Statement
(N
: Node_Id
) is
6176 Analyze
(Expression
(N
));
6177 end Analyze_Free_Statement
;
6179 ---------------------------
6180 -- Analyze_Freeze_Entity --
6181 ---------------------------
6183 procedure Analyze_Freeze_Entity
(N
: Node_Id
) is
6185 Freeze_Entity_Checks
(N
);
6186 end Analyze_Freeze_Entity
;
6188 -----------------------------------
6189 -- Analyze_Freeze_Generic_Entity --
6190 -----------------------------------
6192 procedure Analyze_Freeze_Generic_Entity
(N
: Node_Id
) is
6194 Freeze_Entity_Checks
(N
);
6195 end Analyze_Freeze_Generic_Entity
;
6197 ------------------------------------------
6198 -- Analyze_Record_Representation_Clause --
6199 ------------------------------------------
6201 -- Note: we check as much as we can here, but we can't do any checks
6202 -- based on the position values (e.g. overlap checks) until freeze time
6203 -- because especially in Ada 2005 (machine scalar mode), the processing
6204 -- for non-standard bit order can substantially change the positions.
6205 -- See procedure Check_Record_Representation_Clause (called from Freeze)
6206 -- for the remainder of this processing.
6208 procedure Analyze_Record_Representation_Clause
(N
: Node_Id
) is
6209 Ident
: constant Node_Id
:= Identifier
(N
);
6214 Hbit
: Uint
:= Uint_0
;
6218 Rectype
: Entity_Id
;
6221 function Is_Inherited
(Comp
: Entity_Id
) return Boolean;
6222 -- True if Comp is an inherited component in a record extension
6228 function Is_Inherited
(Comp
: Entity_Id
) return Boolean is
6229 Comp_Base
: Entity_Id
;
6232 if Ekind
(Rectype
) = E_Record_Subtype
then
6233 Comp_Base
:= Original_Record_Component
(Comp
);
6238 return Comp_Base
/= Original_Record_Component
(Comp_Base
);
6243 Is_Record_Extension
: Boolean;
6244 -- True if Rectype is a record extension
6246 CR_Pragma
: Node_Id
:= Empty
;
6247 -- Points to N_Pragma node if Complete_Representation pragma present
6249 -- Start of processing for Analyze_Record_Representation_Clause
6252 if Ignore_Rep_Clauses
then
6253 Kill_Rep_Clause
(N
);
6258 Rectype
:= Entity
(Ident
);
6260 if Rectype
= Any_Type
or else Rep_Item_Too_Early
(Rectype
, N
) then
6263 Rectype
:= Underlying_Type
(Rectype
);
6266 -- First some basic error checks
6268 if not Is_Record_Type
(Rectype
) then
6270 ("record type required, found}", Ident
, First_Subtype
(Rectype
));
6273 elsif Scope
(Rectype
) /= Current_Scope
then
6274 Error_Msg_N
("type must be declared in this scope", N
);
6277 elsif not Is_First_Subtype
(Rectype
) then
6278 Error_Msg_N
("cannot give record rep clause for subtype", N
);
6281 elsif Has_Record_Rep_Clause
(Rectype
) then
6282 Error_Msg_N
("duplicate record rep clause ignored", N
);
6285 elsif Rep_Item_Too_Late
(Rectype
, N
) then
6289 -- We know we have a first subtype, now possibly go the the anonymous
6290 -- base type to determine whether Rectype is a record extension.
6292 Recdef
:= Type_Definition
(Declaration_Node
(Base_Type
(Rectype
)));
6293 Is_Record_Extension
:=
6294 Nkind
(Recdef
) = N_Derived_Type_Definition
6295 and then Present
(Record_Extension_Part
(Recdef
));
6297 if Present
(Mod_Clause
(N
)) then
6299 Loc
: constant Source_Ptr
:= Sloc
(N
);
6300 M
: constant Node_Id
:= Mod_Clause
(N
);
6301 P
: constant List_Id
:= Pragmas_Before
(M
);
6305 pragma Warnings
(Off
, Mod_Val
);
6308 Check_Restriction
(No_Obsolescent_Features
, Mod_Clause
(N
));
6310 if Warn_On_Obsolescent_Feature
then
6312 ("?j?mod clause is an obsolescent feature (RM J.8)", N
);
6314 ("\?j?use alignment attribute definition clause instead", N
);
6321 -- In ASIS_Mode mode, expansion is disabled, but we must convert
6322 -- the Mod clause into an alignment clause anyway, so that the
6323 -- back-end can compute and back-annotate properly the size and
6324 -- alignment of types that may include this record.
6326 -- This seems dubious, this destroys the source tree in a manner
6327 -- not detectable by ASIS ???
6329 if Operating_Mode
= Check_Semantics
and then ASIS_Mode
then
6331 Make_Attribute_Definition_Clause
(Loc
,
6332 Name
=> New_Occurrence_Of
(Base_Type
(Rectype
), Loc
),
6333 Chars
=> Name_Alignment
,
6334 Expression
=> Relocate_Node
(Expression
(M
)));
6336 Set_From_At_Mod
(AtM_Nod
);
6337 Insert_After
(N
, AtM_Nod
);
6338 Mod_Val
:= Get_Alignment_Value
(Expression
(AtM_Nod
));
6339 Set_Mod_Clause
(N
, Empty
);
6342 -- Get the alignment value to perform error checking
6344 Mod_Val
:= Get_Alignment_Value
(Expression
(M
));
6349 -- For untagged types, clear any existing component clauses for the
6350 -- type. If the type is derived, this is what allows us to override
6351 -- a rep clause for the parent. For type extensions, the representation
6352 -- of the inherited components is inherited, so we want to keep previous
6353 -- component clauses for completeness.
6355 if not Is_Tagged_Type
(Rectype
) then
6356 Comp
:= First_Component_Or_Discriminant
(Rectype
);
6357 while Present
(Comp
) loop
6358 Set_Component_Clause
(Comp
, Empty
);
6359 Next_Component_Or_Discriminant
(Comp
);
6363 -- All done if no component clauses
6365 CC
:= First
(Component_Clauses
(N
));
6371 -- A representation like this applies to the base type
6373 Set_Has_Record_Rep_Clause
(Base_Type
(Rectype
));
6374 Set_Has_Non_Standard_Rep
(Base_Type
(Rectype
));
6375 Set_Has_Specified_Layout
(Base_Type
(Rectype
));
6377 -- Process the component clauses
6379 while Present
(CC
) loop
6383 if Nkind
(CC
) = N_Pragma
then
6386 -- The only pragma of interest is Complete_Representation
6388 if Pragma_Name
(CC
) = Name_Complete_Representation
then
6392 -- Processing for real component clause
6395 Posit
:= Static_Integer
(Position
(CC
));
6396 Fbit
:= Static_Integer
(First_Bit
(CC
));
6397 Lbit
:= Static_Integer
(Last_Bit
(CC
));
6400 and then Fbit
/= No_Uint
6401 and then Lbit
/= No_Uint
6405 ("position cannot be negative", Position
(CC
));
6409 ("first bit cannot be negative", First_Bit
(CC
));
6411 -- The Last_Bit specified in a component clause must not be
6412 -- less than the First_Bit minus one (RM-13.5.1(10)).
6414 elsif Lbit
< Fbit
- 1 then
6416 ("last bit cannot be less than first bit minus one",
6419 -- Values look OK, so find the corresponding record component
6420 -- Even though the syntax allows an attribute reference for
6421 -- implementation-defined components, GNAT does not allow the
6422 -- tag to get an explicit position.
6424 elsif Nkind
(Component_Name
(CC
)) = N_Attribute_Reference
then
6425 if Attribute_Name
(Component_Name
(CC
)) = Name_Tag
then
6426 Error_Msg_N
("position of tag cannot be specified", CC
);
6428 Error_Msg_N
("illegal component name", CC
);
6432 Comp
:= First_Entity
(Rectype
);
6433 while Present
(Comp
) loop
6434 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
6440 -- Maybe component of base type that is absent from
6441 -- statically constrained first subtype.
6443 Comp
:= First_Entity
(Base_Type
(Rectype
));
6444 while Present
(Comp
) loop
6445 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
6452 ("component clause is for non-existent field", CC
);
6454 -- Ada 2012 (AI05-0026): Any name that denotes a
6455 -- discriminant of an object of an unchecked union type
6456 -- shall not occur within a record_representation_clause.
6458 -- The general restriction of using record rep clauses on
6459 -- Unchecked_Union types has now been lifted. Since it is
6460 -- possible to introduce a record rep clause which mentions
6461 -- the discriminant of an Unchecked_Union in non-Ada 2012
6462 -- code, this check is applied to all versions of the
6465 elsif Ekind
(Comp
) = E_Discriminant
6466 and then Is_Unchecked_Union
(Rectype
)
6469 ("cannot reference discriminant of unchecked union",
6470 Component_Name
(CC
));
6472 elsif Is_Record_Extension
and then Is_Inherited
(Comp
) then
6474 ("component clause not allowed for inherited "
6475 & "component&", CC
, Comp
);
6477 elsif Present
(Component_Clause
(Comp
)) then
6479 -- Diagnose duplicate rep clause, or check consistency
6480 -- if this is an inherited component. In a double fault,
6481 -- there may be a duplicate inconsistent clause for an
6482 -- inherited component.
6484 if Scope
(Original_Record_Component
(Comp
)) = Rectype
6485 or else Parent
(Component_Clause
(Comp
)) = N
6487 Error_Msg_Sloc
:= Sloc
(Component_Clause
(Comp
));
6488 Error_Msg_N
("component clause previously given#", CC
);
6492 Rep1
: constant Node_Id
:= Component_Clause
(Comp
);
6494 if Intval
(Position
(Rep1
)) /=
6495 Intval
(Position
(CC
))
6496 or else Intval
(First_Bit
(Rep1
)) /=
6497 Intval
(First_Bit
(CC
))
6498 or else Intval
(Last_Bit
(Rep1
)) /=
6499 Intval
(Last_Bit
(CC
))
6502 ("component clause inconsistent "
6503 & "with representation of ancestor", CC
);
6505 elsif Warn_On_Redundant_Constructs
then
6507 ("?r?redundant confirming component clause "
6508 & "for component!", CC
);
6513 -- Normal case where this is the first component clause we
6514 -- have seen for this entity, so set it up properly.
6517 -- Make reference for field in record rep clause and set
6518 -- appropriate entity field in the field identifier.
6521 (Comp
, Component_Name
(CC
), Set_Ref
=> False);
6522 Set_Entity
(Component_Name
(CC
), Comp
);
6524 -- Update Fbit and Lbit to the actual bit number
6526 Fbit
:= Fbit
+ UI_From_Int
(SSU
) * Posit
;
6527 Lbit
:= Lbit
+ UI_From_Int
(SSU
) * Posit
;
6529 if Has_Size_Clause
(Rectype
)
6530 and then RM_Size
(Rectype
) <= Lbit
6533 ("bit number out of range of specified size",
6536 Set_Component_Clause
(Comp
, CC
);
6537 Set_Component_Bit_Offset
(Comp
, Fbit
);
6538 Set_Esize
(Comp
, 1 + (Lbit
- Fbit
));
6539 Set_Normalized_First_Bit
(Comp
, Fbit
mod SSU
);
6540 Set_Normalized_Position
(Comp
, Fbit
/ SSU
);
6542 if Warn_On_Overridden_Size
6543 and then Has_Size_Clause
(Etype
(Comp
))
6544 and then RM_Size
(Etype
(Comp
)) /= Esize
(Comp
)
6547 ("?S?component size overrides size clause for&",
6548 Component_Name
(CC
), Etype
(Comp
));
6551 -- This information is also set in the corresponding
6552 -- component of the base type, found by accessing the
6553 -- Original_Record_Component link if it is present.
6555 Ocomp
:= Original_Record_Component
(Comp
);
6562 (Component_Name
(CC
),
6568 (Comp
, First_Node
(CC
), "component clause", Biased
);
6570 if Present
(Ocomp
) then
6571 Set_Component_Clause
(Ocomp
, CC
);
6572 Set_Component_Bit_Offset
(Ocomp
, Fbit
);
6573 Set_Normalized_First_Bit
(Ocomp
, Fbit
mod SSU
);
6574 Set_Normalized_Position
(Ocomp
, Fbit
/ SSU
);
6575 Set_Esize
(Ocomp
, 1 + (Lbit
- Fbit
));
6577 Set_Normalized_Position_Max
6578 (Ocomp
, Normalized_Position
(Ocomp
));
6580 -- Note: we don't use Set_Biased here, because we
6581 -- already gave a warning above if needed, and we
6582 -- would get a duplicate for the same name here.
6584 Set_Has_Biased_Representation
6585 (Ocomp
, Has_Biased_Representation
(Comp
));
6588 if Esize
(Comp
) < 0 then
6589 Error_Msg_N
("component size is negative", CC
);
6600 -- Check missing components if Complete_Representation pragma appeared
6602 if Present
(CR_Pragma
) then
6603 Comp
:= First_Component_Or_Discriminant
(Rectype
);
6604 while Present
(Comp
) loop
6605 if No
(Component_Clause
(Comp
)) then
6607 ("missing component clause for &", CR_Pragma
, Comp
);
6610 Next_Component_Or_Discriminant
(Comp
);
6613 -- Give missing components warning if required
6615 elsif Warn_On_Unrepped_Components
then
6617 Num_Repped_Components
: Nat
:= 0;
6618 Num_Unrepped_Components
: Nat
:= 0;
6621 -- First count number of repped and unrepped components
6623 Comp
:= First_Component_Or_Discriminant
(Rectype
);
6624 while Present
(Comp
) loop
6625 if Present
(Component_Clause
(Comp
)) then
6626 Num_Repped_Components
:= Num_Repped_Components
+ 1;
6628 Num_Unrepped_Components
:= Num_Unrepped_Components
+ 1;
6631 Next_Component_Or_Discriminant
(Comp
);
6634 -- We are only interested in the case where there is at least one
6635 -- unrepped component, and at least half the components have rep
6636 -- clauses. We figure that if less than half have them, then the
6637 -- partial rep clause is really intentional. If the component
6638 -- type has no underlying type set at this point (as for a generic
6639 -- formal type), we don't know enough to give a warning on the
6642 if Num_Unrepped_Components
> 0
6643 and then Num_Unrepped_Components
< Num_Repped_Components
6645 Comp
:= First_Component_Or_Discriminant
(Rectype
);
6646 while Present
(Comp
) loop
6647 if No
(Component_Clause
(Comp
))
6648 and then Comes_From_Source
(Comp
)
6649 and then Present
(Underlying_Type
(Etype
(Comp
)))
6650 and then (Is_Scalar_Type
(Underlying_Type
(Etype
(Comp
)))
6651 or else Size_Known_At_Compile_Time
6652 (Underlying_Type
(Etype
(Comp
))))
6653 and then not Has_Warnings_Off
(Rectype
)
6655 -- Ignore discriminant in unchecked union, since it is
6656 -- not there, and cannot have a component clause.
6658 and then (not Is_Unchecked_Union
(Rectype
)
6659 or else Ekind
(Comp
) /= E_Discriminant
)
6661 Error_Msg_Sloc
:= Sloc
(Comp
);
6663 ("?C?no component clause given for & declared #",
6667 Next_Component_Or_Discriminant
(Comp
);
6672 end Analyze_Record_Representation_Clause
;
6674 -------------------------------------
6675 -- Build_Discrete_Static_Predicate --
6676 -------------------------------------
6678 procedure Build_Discrete_Static_Predicate
6683 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
6685 Non_Static
: exception;
6686 -- Raised if something non-static is found
6688 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
6690 BLo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Btyp
));
6691 BHi
: constant Uint
:= Expr_Value
(Type_High_Bound
(Btyp
));
6692 -- Low bound and high bound value of base type of Typ
6696 -- Bounds for constructing the static predicate. We use the bound of the
6697 -- subtype if it is static, otherwise the corresponding base type bound.
6698 -- Note: a non-static subtype can have a static predicate.
6703 -- One entry in a Rlist value, a single REnt (range entry) value denotes
6704 -- one range from Lo to Hi. To represent a single value range Lo = Hi =
6707 type RList
is array (Nat
range <>) of REnt
;
6708 -- A list of ranges. The ranges are sorted in increasing order, and are
6709 -- disjoint (there is a gap of at least one value between each range in
6710 -- the table). A value is in the set of ranges in Rlist if it lies
6711 -- within one of these ranges.
6713 False_Range
: constant RList
:=
6714 RList
'(1 .. 0 => REnt'(No_Uint
, No_Uint
));
6715 -- An empty set of ranges represents a range list that can never be
6716 -- satisfied, since there are no ranges in which the value could lie,
6717 -- so it does not lie in any of them. False_Range is a canonical value
6718 -- for this empty set, but general processing should test for an Rlist
6719 -- with length zero (see Is_False predicate), since other null ranges
6720 -- may appear which must be treated as False.
6722 True_Range
: constant RList
:= RList
'(1 => REnt'(BLo
, BHi
));
6723 -- Range representing True, value must be in the base range
6725 function "and" (Left
: RList
; Right
: RList
) return RList
;
6726 -- And's together two range lists, returning a range list. This is a set
6727 -- intersection operation.
6729 function "or" (Left
: RList
; Right
: RList
) return RList
;
6730 -- Or's together two range lists, returning a range list. This is a set
6733 function "not" (Right
: RList
) return RList
;
6734 -- Returns complement of a given range list, i.e. a range list
6735 -- representing all the values in TLo .. THi that are not in the input
6738 function Build_Val
(V
: Uint
) return Node_Id
;
6739 -- Return an analyzed N_Identifier node referencing this value, suitable
6740 -- for use as an entry in the Static_Discrte_Predicate list. This node
6741 -- is typed with the base type.
6743 function Build_Range
(Lo
: Uint
; Hi
: Uint
) return Node_Id
;
6744 -- Return an analyzed N_Range node referencing this range, suitable for
6745 -- use as an entry in the Static_Discrete_Predicate list. This node is
6746 -- typed with the base type.
6748 function Get_RList
(Exp
: Node_Id
) return RList
;
6749 -- This is a recursive routine that converts the given expression into a
6750 -- list of ranges, suitable for use in building the static predicate.
6752 function Is_False
(R
: RList
) return Boolean;
6753 pragma Inline
(Is_False
);
6754 -- Returns True if the given range list is empty, and thus represents a
6755 -- False list of ranges that can never be satisfied.
6757 function Is_True
(R
: RList
) return Boolean;
6758 -- Returns True if R trivially represents the True predicate by having a
6759 -- single range from BLo to BHi.
6761 function Is_Type_Ref
(N
: Node_Id
) return Boolean;
6762 pragma Inline
(Is_Type_Ref
);
6763 -- Returns if True if N is a reference to the type for the predicate in
6764 -- the expression (i.e. if it is an identifier whose Chars field matches
6765 -- the Nam given in the call). N must not be parenthesized, if the type
6766 -- name appears in parens, this routine will return False.
6768 function Lo_Val
(N
: Node_Id
) return Uint
;
6769 -- Given an entry from a Static_Discrete_Predicate list that is either
6770 -- a static expression or static range, gets either the expression value
6771 -- or the low bound of the range.
6773 function Hi_Val
(N
: Node_Id
) return Uint
;
6774 -- Given an entry from a Static_Discrete_Predicate list that is either
6775 -- a static expression or static range, gets either the expression value
6776 -- or the high bound of the range.
6778 function Membership_Entry
(N
: Node_Id
) return RList
;
6779 -- Given a single membership entry (range, value, or subtype), returns
6780 -- the corresponding range list. Raises Static_Error if not static.
6782 function Membership_Entries
(N
: Node_Id
) return RList
;
6783 -- Given an element on an alternatives list of a membership operation,
6784 -- returns the range list corresponding to this entry and all following
6785 -- entries (i.e. returns the "or" of this list of values).
6787 function Stat_Pred
(Typ
: Entity_Id
) return RList
;
6788 -- Given a type, if it has a static predicate, then return the predicate
6789 -- as a range list, otherwise raise Non_Static.
6795 function "and" (Left
: RList
; Right
: RList
) return RList
is
6797 -- First range of result
6799 SLeft
: Nat
:= Left
'First;
6800 -- Start of rest of left entries
6802 SRight
: Nat
:= Right
'First;
6803 -- Start of rest of right entries
6806 -- If either range is True, return the other
6808 if Is_True
(Left
) then
6810 elsif Is_True
(Right
) then
6814 -- If either range is False, return False
6816 if Is_False
(Left
) or else Is_False
(Right
) then
6820 -- Loop to remove entries at start that are disjoint, and thus just
6821 -- get discarded from the result entirely.
6824 -- If no operands left in either operand, result is false
6826 if SLeft
> Left
'Last or else SRight
> Right
'Last then
6829 -- Discard first left operand entry if disjoint with right
6831 elsif Left
(SLeft
).Hi
< Right
(SRight
).Lo
then
6834 -- Discard first right operand entry if disjoint with left
6836 elsif Right
(SRight
).Hi
< Left
(SLeft
).Lo
then
6837 SRight
:= SRight
+ 1;
6839 -- Otherwise we have an overlapping entry
6846 -- Now we have two non-null operands, and first entries overlap. The
6847 -- first entry in the result will be the overlapping part of these
6850 FEnt
:= REnt
'(Lo => UI_Max (Left (SLeft).Lo, Right (SRight).Lo),
6851 Hi => UI_Min (Left (SLeft).Hi, Right (SRight).Hi));
6853 -- Now we can remove the entry that ended at a lower value, since its
6854 -- contribution is entirely contained in Fent.
6856 if Left (SLeft).Hi <= Right (SRight).Hi then
6859 SRight := SRight + 1;
6862 -- Compute result by concatenating this first entry with the "and" of
6863 -- the remaining parts of the left and right operands. Note that if
6864 -- either of these is empty, "and" will yield empty, so that we will
6865 -- end up with just Fent, which is what we want in that case.
6868 FEnt & (Left (SLeft .. Left'Last) and Right (SRight .. Right'Last));
6875 function "not" (Right : RList) return RList is
6877 -- Return True if False range
6879 if Is_False (Right) then
6883 -- Return False if True range
6885 if Is_True (Right) then
6889 -- Here if not trivial case
6892 Result : RList (1 .. Right'Length + 1);
6893 -- May need one more entry for gap at beginning and end
6896 -- Number of entries stored in Result
6901 if Right (Right'First).Lo > TLo then
6903 Result (Count) := REnt'(TLo
, Right
(Right
'First).Lo
- 1);
6906 -- Gaps between ranges
6908 for J
in Right
'First .. Right
'Last - 1 loop
6910 Result
(Count
) := REnt
'(Right (J).Hi + 1, Right (J + 1).Lo - 1);
6915 if Right (Right'Last).Hi < THi then
6917 Result (Count) := REnt'(Right
(Right
'Last).Hi
+ 1, THi
);
6920 return Result
(1 .. Count
);
6928 function "or" (Left
: RList
; Right
: RList
) return RList
is
6930 -- First range of result
6932 SLeft
: Nat
:= Left
'First;
6933 -- Start of rest of left entries
6935 SRight
: Nat
:= Right
'First;
6936 -- Start of rest of right entries
6939 -- If either range is True, return True
6941 if Is_True
(Left
) or else Is_True
(Right
) then
6945 -- If either range is False (empty), return the other
6947 if Is_False
(Left
) then
6949 elsif Is_False
(Right
) then
6953 -- Initialize result first entry from left or right operand depending
6954 -- on which starts with the lower range.
6956 if Left
(SLeft
).Lo
< Right
(SRight
).Lo
then
6957 FEnt
:= Left
(SLeft
);
6960 FEnt
:= Right
(SRight
);
6961 SRight
:= SRight
+ 1;
6964 -- This loop eats ranges from left and right operands that are
6965 -- contiguous with the first range we are gathering.
6968 -- Eat first entry in left operand if contiguous or overlapped by
6969 -- gathered first operand of result.
6971 if SLeft
<= Left
'Last
6972 and then Left
(SLeft
).Lo
<= FEnt
.Hi
+ 1
6974 FEnt
.Hi
:= UI_Max
(FEnt
.Hi
, Left
(SLeft
).Hi
);
6977 -- Eat first entry in right operand if contiguous or overlapped by
6978 -- gathered right operand of result.
6980 elsif SRight
<= Right
'Last
6981 and then Right
(SRight
).Lo
<= FEnt
.Hi
+ 1
6983 FEnt
.Hi
:= UI_Max
(FEnt
.Hi
, Right
(SRight
).Hi
);
6984 SRight
:= SRight
+ 1;
6986 -- All done if no more entries to eat
6993 -- Obtain result as the first entry we just computed, concatenated
6994 -- to the "or" of the remaining results (if one operand is empty,
6995 -- this will just concatenate with the other
6998 FEnt
& (Left
(SLeft
.. Left
'Last) or Right
(SRight
.. Right
'Last));
7005 function Build_Range
(Lo
: Uint
; Hi
: Uint
) return Node_Id
is
7010 Low_Bound
=> Build_Val
(Lo
),
7011 High_Bound
=> Build_Val
(Hi
));
7012 Set_Etype
(Result
, Btyp
);
7013 Set_Analyzed
(Result
);
7021 function Build_Val
(V
: Uint
) return Node_Id
is
7025 if Is_Enumeration_Type
(Typ
) then
7026 Result
:= Get_Enum_Lit_From_Pos
(Typ
, V
, Loc
);
7028 Result
:= Make_Integer_Literal
(Loc
, V
);
7031 Set_Etype
(Result
, Btyp
);
7032 Set_Is_Static_Expression
(Result
);
7033 Set_Analyzed
(Result
);
7041 function Get_RList
(Exp
: Node_Id
) return RList
is
7046 -- Static expression can only be true or false
7048 if Is_OK_Static_Expression
(Exp
) then
7049 if Expr_Value
(Exp
) = 0 then
7056 -- Otherwise test node type
7064 when N_Op_And | N_And_Then
=>
7065 return Get_RList
(Left_Opnd
(Exp
))
7067 Get_RList
(Right_Opnd
(Exp
));
7071 when N_Op_Or | N_Or_Else
=>
7072 return Get_RList
(Left_Opnd
(Exp
))
7074 Get_RList
(Right_Opnd
(Exp
));
7079 return not Get_RList
(Right_Opnd
(Exp
));
7081 -- Comparisons of type with static value
7083 when N_Op_Compare
=>
7085 -- Type is left operand
7087 if Is_Type_Ref
(Left_Opnd
(Exp
))
7088 and then Is_OK_Static_Expression
(Right_Opnd
(Exp
))
7090 Val
:= Expr_Value
(Right_Opnd
(Exp
));
7092 -- Typ is right operand
7094 elsif Is_Type_Ref
(Right_Opnd
(Exp
))
7095 and then Is_OK_Static_Expression
(Left_Opnd
(Exp
))
7097 Val
:= Expr_Value
(Left_Opnd
(Exp
));
7099 -- Invert sense of comparison
7102 when N_Op_Gt
=> Op
:= N_Op_Lt
;
7103 when N_Op_Lt
=> Op
:= N_Op_Gt
;
7104 when N_Op_Ge
=> Op
:= N_Op_Le
;
7105 when N_Op_Le
=> Op
:= N_Op_Ge
;
7106 when others => null;
7109 -- Other cases are non-static
7115 -- Construct range according to comparison operation
7119 return RList
'(1 => REnt'(Val
, Val
));
7122 return RList
'(1 => REnt'(Val
, BHi
));
7125 return RList
'(1 => REnt'(Val
+ 1, BHi
));
7128 return RList
'(1 => REnt'(BLo
, Val
));
7131 return RList
'(1 => REnt'(BLo
, Val
- 1));
7134 return RList
'(REnt'(BLo
, Val
- 1), REnt
'(Val + 1, BHi));
7137 raise Program_Error;
7143 if not Is_Type_Ref (Left_Opnd (Exp)) then
7147 if Present (Right_Opnd (Exp)) then
7148 return Membership_Entry (Right_Opnd (Exp));
7150 return Membership_Entries (First (Alternatives (Exp)));
7153 -- Negative membership (NOT IN)
7156 if not Is_Type_Ref (Left_Opnd (Exp)) then
7160 if Present (Right_Opnd (Exp)) then
7161 return not Membership_Entry (Right_Opnd (Exp));
7163 return not Membership_Entries (First (Alternatives (Exp)));
7166 -- Function call, may be call to static predicate
7168 when N_Function_Call =>
7169 if Is_Entity_Name (Name (Exp)) then
7171 Ent : constant Entity_Id := Entity (Name (Exp));
7173 if Is_Predicate_Function (Ent)
7175 Is_Predicate_Function_M (Ent)
7177 return Stat_Pred (Etype (First_Formal (Ent)));
7182 -- Other function call cases are non-static
7186 -- Qualified expression, dig out the expression
7188 when N_Qualified_Expression =>
7189 return Get_RList (Expression (Exp));
7191 when N_Case_Expression =>
7198 if not Is_Entity_Name (Expression (Expr))
7199 or else Etype (Expression (Expr)) /= Typ
7202 ("expression must denaote subtype", Expression (Expr));
7206 -- Collect discrete choices in all True alternatives
7208 Choices := New_List;
7209 Alt := First (Alternatives (Exp));
7210 while Present (Alt) loop
7211 Dep := Expression (Alt);
7213 if not Is_OK_Static_Expression (Dep) then
7216 elsif Is_True (Expr_Value (Dep)) then
7217 Append_List_To (Choices,
7218 New_Copy_List (Discrete_Choices (Alt)));
7224 return Membership_Entries (First (Choices));
7227 -- Expression with actions: if no actions, dig out expression
7229 when N_Expression_With_Actions =>
7230 if Is_Empty_List (Actions (Exp)) then
7231 return Get_RList (Expression (Exp));
7239 return (Get_RList (Left_Opnd (Exp))
7240 and not Get_RList (Right_Opnd (Exp)))
7241 or (Get_RList (Right_Opnd (Exp))
7242 and not Get_RList (Left_Opnd (Exp)));
7244 -- Any other node type is non-static
7255 function Hi_Val (N : Node_Id) return Uint is
7257 if Is_OK_Static_Expression (N) then
7258 return Expr_Value (N);
7260 pragma Assert (Nkind (N) = N_Range);
7261 return Expr_Value (High_Bound (N));
7269 function Is_False (R : RList) return Boolean is
7271 return R'Length = 0;
7278 function Is_True (R : RList) return Boolean is
7281 and then R (R'First).Lo = BLo
7282 and then R (R'First).Hi = BHi;
7289 function Is_Type_Ref (N : Node_Id) return Boolean is
7291 return Nkind (N) = N_Identifier
7292 and then Chars (N) = Nam
7293 and then Paren_Count (N) = 0;
7300 function Lo_Val (N : Node_Id) return Uint is
7302 if Is_OK_Static_Expression (N) then
7303 return Expr_Value (N);
7305 pragma Assert (Nkind (N) = N_Range);
7306 return Expr_Value (Low_Bound (N));
7310 ------------------------
7311 -- Membership_Entries --
7312 ------------------------
7314 function Membership_Entries (N : Node_Id) return RList is
7316 if No (Next (N)) then
7317 return Membership_Entry (N);
7319 return Membership_Entry (N) or Membership_Entries (Next (N));
7321 end Membership_Entries;
7323 ----------------------
7324 -- Membership_Entry --
7325 ----------------------
7327 function Membership_Entry (N : Node_Id) return RList is
7335 if Nkind (N) = N_Range then
7336 if not Is_OK_Static_Expression (Low_Bound (N))
7338 not Is_OK_Static_Expression (High_Bound (N))
7342 SLo := Expr_Value (Low_Bound (N));
7343 SHi := Expr_Value (High_Bound (N));
7344 return RList'(1 => REnt
'(SLo, SHi));
7347 -- Static expression case
7349 elsif Is_OK_Static_Expression (N) then
7350 Val := Expr_Value (N);
7351 return RList'(1 => REnt
'(Val, Val));
7353 -- Identifier (other than static expression) case
7355 else pragma Assert (Nkind (N) = N_Identifier);
7359 if Is_Type (Entity (N)) then
7361 -- If type has predicates, process them
7363 if Has_Predicates (Entity (N)) then
7364 return Stat_Pred (Entity (N));
7366 -- For static subtype without predicates, get range
7368 elsif Is_OK_Static_Subtype (Entity (N)) then
7369 SLo := Expr_Value (Type_Low_Bound (Entity (N)));
7370 SHi := Expr_Value (Type_High_Bound (Entity (N)));
7371 return RList'(1 => REnt
'(SLo, SHi));
7373 -- Any other type makes us non-static
7379 -- Any other kind of identifier in predicate (e.g. a non-static
7380 -- expression value) means this is not a static predicate.
7386 end Membership_Entry;
7392 function Stat_Pred (Typ : Entity_Id) return RList is
7394 -- Not static if type does not have static predicates
7396 if not Has_Static_Predicate (Typ) then
7400 -- Otherwise we convert the predicate list to a range list
7403 Spred : constant List_Id := Static_Discrete_Predicate (Typ);
7404 Result : RList (1 .. List_Length (Spred));
7408 P := First (Static_Discrete_Predicate (Typ));
7409 for J in Result'Range loop
7410 Result (J) := REnt'(Lo_Val
(P
), Hi_Val
(P
));
7418 -- Start of processing for Build_Discrete_Static_Predicate
7421 -- Establish bounds for the predicate
7423 if Compile_Time_Known_Value
(Type_Low_Bound
(Typ
)) then
7424 TLo
:= Expr_Value
(Type_Low_Bound
(Typ
));
7429 if Compile_Time_Known_Value
(Type_High_Bound
(Typ
)) then
7430 THi
:= Expr_Value
(Type_High_Bound
(Typ
));
7435 -- Analyze the expression to see if it is a static predicate
7438 Ranges
: constant RList
:= Get_RList
(Expr
);
7439 -- Range list from expression if it is static
7444 -- Convert range list into a form for the static predicate. In the
7445 -- Ranges array, we just have raw ranges, these must be converted
7446 -- to properly typed and analyzed static expressions or range nodes.
7448 -- Note: here we limit ranges to the ranges of the subtype, so that
7449 -- a predicate is always false for values outside the subtype. That
7450 -- seems fine, such values are invalid anyway, and considering them
7451 -- to fail the predicate seems allowed and friendly, and furthermore
7452 -- simplifies processing for case statements and loops.
7456 for J
in Ranges
'Range loop
7458 Lo
: Uint
:= Ranges
(J
).Lo
;
7459 Hi
: Uint
:= Ranges
(J
).Hi
;
7462 -- Ignore completely out of range entry
7464 if Hi
< TLo
or else Lo
> THi
then
7467 -- Otherwise process entry
7470 -- Adjust out of range value to subtype range
7480 -- Convert range into required form
7482 Append_To
(Plist
, Build_Range
(Lo
, Hi
));
7487 -- Processing was successful and all entries were static, so now we
7488 -- can store the result as the predicate list.
7490 Set_Static_Discrete_Predicate
(Typ
, Plist
);
7492 -- The processing for static predicates put the expression into
7493 -- canonical form as a series of ranges. It also eliminated
7494 -- duplicates and collapsed and combined ranges. We might as well
7495 -- replace the alternatives list of the right operand of the
7496 -- membership test with the static predicate list, which will
7497 -- usually be more efficient.
7500 New_Alts
: constant List_Id
:= New_List
;
7505 Old_Node
:= First
(Plist
);
7506 while Present
(Old_Node
) loop
7507 New_Node
:= New_Copy
(Old_Node
);
7509 if Nkind
(New_Node
) = N_Range
then
7510 Set_Low_Bound
(New_Node
, New_Copy
(Low_Bound
(Old_Node
)));
7511 Set_High_Bound
(New_Node
, New_Copy
(High_Bound
(Old_Node
)));
7514 Append_To
(New_Alts
, New_Node
);
7518 -- If empty list, replace by False
7520 if Is_Empty_List
(New_Alts
) then
7521 Rewrite
(Expr
, New_Occurrence_Of
(Standard_False
, Loc
));
7523 -- Else replace by set membership test
7528 Left_Opnd
=> Make_Identifier
(Loc
, Nam
),
7529 Right_Opnd
=> Empty
,
7530 Alternatives
=> New_Alts
));
7532 -- Resolve new expression in function context
7534 Install_Formals
(Predicate_Function
(Typ
));
7535 Push_Scope
(Predicate_Function
(Typ
));
7536 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
7542 -- If non-static, return doing nothing
7547 end Build_Discrete_Static_Predicate
;
7549 -------------------------------------------
7550 -- Build_Invariant_Procedure_Declaration --
7551 -------------------------------------------
7553 function Build_Invariant_Procedure_Declaration
7554 (Typ
: Entity_Id
) return Node_Id
7556 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
7557 Object_Entity
: constant Entity_Id
:=
7558 Make_Defining_Identifier
(Loc
, New_Internal_Name
('I'));
7563 Set_Etype
(Object_Entity
, Typ
);
7565 -- Check for duplicate definiations.
7567 if Has_Invariants
(Typ
) and then Present
(Invariant_Procedure
(Typ
)) then
7572 Make_Defining_Identifier
(Loc
,
7573 Chars
=> New_External_Name
(Chars
(Typ
), "Invariant"));
7574 Set_Has_Invariants
(Typ
);
7575 Set_Ekind
(SId
, E_Procedure
);
7576 Set_Etype
(SId
, Standard_Void_Type
);
7577 Set_Is_Invariant_Procedure
(SId
);
7578 Set_Invariant_Procedure
(Typ
, SId
);
7581 Make_Procedure_Specification
(Loc
,
7582 Defining_Unit_Name
=> SId
,
7583 Parameter_Specifications
=> New_List
(
7584 Make_Parameter_Specification
(Loc
,
7585 Defining_Identifier
=> Object_Entity
,
7586 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))));
7588 return Make_Subprogram_Declaration
(Loc
, Specification
=> Spec
);
7589 end Build_Invariant_Procedure_Declaration
;
7591 -------------------------------
7592 -- Build_Invariant_Procedure --
7593 -------------------------------
7595 -- The procedure that is constructed here has the form
7597 -- procedure typInvariant (Ixxx : typ) is
7599 -- pragma Check (Invariant, exp, "failed invariant from xxx");
7600 -- pragma Check (Invariant, exp, "failed invariant from xxx");
7602 -- pragma Check (Invariant, exp, "failed inherited invariant from xxx");
7604 -- end typInvariant;
7606 procedure Build_Invariant_Procedure
(Typ
: Entity_Id
; N
: Node_Id
) is
7607 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
7615 -- Name for Check pragma, usually Invariant, but might be Type_Invariant
7616 -- if we come from a Type_Invariant aspect, we make sure to build the
7617 -- Check pragma with the right name, so that Check_Policy works right.
7619 Visible_Decls
: constant List_Id
:= Visible_Declarations
(N
);
7620 Private_Decls
: constant List_Id
:= Private_Declarations
(N
);
7622 procedure Add_Invariants
(T
: Entity_Id
; Inherit
: Boolean);
7623 -- Appends statements to Stmts for any invariants in the rep item chain
7624 -- of the given type. If Inherit is False, then we only process entries
7625 -- on the chain for the type Typ. If Inherit is True, then we ignore any
7626 -- Invariant aspects, but we process all Invariant'Class aspects, adding
7627 -- "inherited" to the exception message and generating an informational
7628 -- message about the inheritance of an invariant.
7630 Object_Name
: Name_Id
;
7631 -- Name for argument of invariant procedure
7633 Object_Entity
: Node_Id
;
7634 -- The entity of the formal for the procedure
7636 --------------------
7637 -- Add_Invariants --
7638 --------------------
7640 procedure Add_Invariants
(T
: Entity_Id
; Inherit
: Boolean) is
7650 procedure Replace_Type_Reference
(N
: Node_Id
);
7651 -- Replace a single occurrence N of the subtype name with a reference
7652 -- to the formal of the predicate function. N can be an identifier
7653 -- referencing the subtype, or a selected component, representing an
7654 -- appropriately qualified occurrence of the subtype name.
7656 procedure Replace_Type_References
is
7657 new Replace_Type_References_Generic
(Replace_Type_Reference
);
7658 -- Traverse an expression replacing all occurrences of the subtype
7659 -- name with appropriate references to the object that is the formal
7660 -- parameter of the predicate function. Note that we must ensure
7661 -- that the type and entity information is properly set in the
7662 -- replacement node, since we will do a Preanalyze call of this
7663 -- expression without proper visibility of the procedure argument.
7665 ----------------------------
7666 -- Replace_Type_Reference --
7667 ----------------------------
7669 -- Note: See comments in Add_Predicates.Replace_Type_Reference
7670 -- regarding handling of Sloc and Comes_From_Source.
7672 procedure Replace_Type_Reference
(N
: Node_Id
) is
7675 -- Add semantic information to node to be rewritten, for ASIS
7676 -- navigation needs.
7678 if Nkind
(N
) = N_Identifier
then
7682 elsif Nkind
(N
) = N_Selected_Component
then
7683 Analyze
(Prefix
(N
));
7684 Set_Entity
(Selector_Name
(N
), T
);
7685 Set_Etype
(Selector_Name
(N
), T
);
7688 -- Invariant'Class, replace with T'Class (obj)
7689 -- In ASIS mode, an inherited item is analyzed already, and the
7690 -- replacement has been done, so do not repeat transformation
7691 -- to prevent ill-formed tree.
7693 if Class_Present
(Ritem
) then
7695 and then Nkind
(Parent
(N
)) = N_Attribute_Reference
7696 and then Attribute_Name
(Parent
(N
)) = Name_Class
7702 Make_Type_Conversion
(Sloc
(N
),
7704 Make_Attribute_Reference
(Sloc
(N
),
7705 Prefix
=> New_Occurrence_Of
(T
, Sloc
(N
)),
7706 Attribute_Name
=> Name_Class
),
7708 Make_Identifier
(Sloc
(N
), Object_Name
)));
7710 Set_Entity
(Expression
(N
), Object_Entity
);
7711 Set_Etype
(Expression
(N
), Typ
);
7714 -- Invariant, replace with obj
7717 Rewrite
(N
, Make_Identifier
(Sloc
(N
), Object_Name
));
7718 Set_Entity
(N
, Object_Entity
);
7722 Set_Comes_From_Source
(N
, True);
7723 end Replace_Type_Reference
;
7725 -- Start of processing for Add_Invariants
7728 Ritem
:= First_Rep_Item
(T
);
7729 while Present
(Ritem
) loop
7730 if Nkind
(Ritem
) = N_Pragma
7731 and then Pragma_Name
(Ritem
) = Name_Invariant
7733 Arg1
:= First
(Pragma_Argument_Associations
(Ritem
));
7734 Arg2
:= Next
(Arg1
);
7735 Arg3
:= Next
(Arg2
);
7737 Arg1
:= Get_Pragma_Arg
(Arg1
);
7738 Arg2
:= Get_Pragma_Arg
(Arg2
);
7740 -- For Inherit case, ignore Invariant, process only Class case
7743 if not Class_Present
(Ritem
) then
7747 -- For Inherit false, process only item for right type
7750 if Entity
(Arg1
) /= Typ
then
7756 Stmts
:= Empty_List
;
7759 Exp
:= New_Copy_Tree
(Arg2
);
7761 -- Preserve sloc of original pragma Invariant
7763 Loc
:= Sloc
(Ritem
);
7765 -- We need to replace any occurrences of the name of the type
7766 -- with references to the object, converted to type'Class in
7767 -- the case of Invariant'Class aspects.
7769 Replace_Type_References
(Exp
, T
);
7771 -- If this invariant comes from an aspect, find the aspect
7772 -- specification, and replace the saved expression because
7773 -- we need the subtype references replaced for the calls to
7774 -- Preanalyze_Spec_Expressin in Check_Aspect_At_Freeze_Point
7775 -- and Check_Aspect_At_End_Of_Declarations.
7777 if From_Aspect_Specification
(Ritem
) then
7782 -- Loop to find corresponding aspect, note that this
7783 -- must be present given the pragma is marked delayed.
7785 -- Note: in practice Next_Rep_Item (Ritem) is Empty so
7786 -- this loop does nothing. Furthermore, why isn't this
7787 -- simply Corresponding_Aspect ???
7789 Aitem
:= Next_Rep_Item
(Ritem
);
7790 while Present
(Aitem
) loop
7791 if Nkind
(Aitem
) = N_Aspect_Specification
7792 and then Aspect_Rep_Item
(Aitem
) = Ritem
7795 (Identifier
(Aitem
), New_Copy_Tree
(Exp
));
7799 Aitem
:= Next_Rep_Item
(Aitem
);
7804 -- Now we need to preanalyze the expression to properly capture
7805 -- the visibility in the visible part. The expression will not
7806 -- be analyzed for real until the body is analyzed, but that is
7807 -- at the end of the private part and has the wrong visibility.
7809 Set_Parent
(Exp
, N
);
7810 Preanalyze_Assert_Expression
(Exp
, Any_Boolean
);
7812 -- A class-wide invariant may be inherited in a separate unit,
7813 -- where the corresponding expression cannot be resolved by
7814 -- visibility, because it refers to a local function. Propagate
7815 -- semantic information to the original representation item, to
7816 -- be used when an invariant procedure for a derived type is
7819 -- Unclear how to handle class-wide invariants that are not
7820 -- function calls ???
7823 and then Class_Present
(Ritem
)
7824 and then Nkind
(Exp
) = N_Function_Call
7825 and then Nkind
(Arg2
) = N_Indexed_Component
7828 Make_Function_Call
(Loc
,
7830 New_Occurrence_Of
(Entity
(Name
(Exp
)), Loc
),
7831 Parameter_Associations
=>
7832 New_Copy_List
(Expressions
(Arg2
))));
7835 -- In ASIS mode, even if assertions are not enabled, we must
7836 -- analyze the original expression in the aspect specification
7837 -- because it is part of the original tree.
7839 if ASIS_Mode
and then From_Aspect_Specification
(Ritem
) then
7841 Inv
: constant Node_Id
:=
7842 Expression
(Corresponding_Aspect
(Ritem
));
7844 Replace_Type_References
(Inv
, T
);
7845 Preanalyze_Assert_Expression
(Inv
, Standard_Boolean
);
7849 -- Get name to be used for Check pragma
7851 if not From_Aspect_Specification
(Ritem
) then
7852 Nam
:= Name_Invariant
;
7854 Nam
:= Chars
(Identifier
(Corresponding_Aspect
(Ritem
)));
7857 -- Build first two arguments for Check pragma
7861 Make_Pragma_Argument_Association
(Loc
,
7862 Expression
=> Make_Identifier
(Loc
, Chars
=> Nam
)),
7863 Make_Pragma_Argument_Association
(Loc
,
7864 Expression
=> Exp
));
7866 -- Add message if present in Invariant pragma
7868 if Present
(Arg3
) then
7869 Str
:= Strval
(Get_Pragma_Arg
(Arg3
));
7871 -- If inherited case, and message starts "failed invariant",
7872 -- change it to be "failed inherited invariant".
7875 String_To_Name_Buffer
(Str
);
7877 if Name_Buffer
(1 .. 16) = "failed invariant" then
7878 Insert_Str_In_Name_Buffer
("inherited ", 8);
7879 Str
:= String_From_Name_Buffer
;
7884 Make_Pragma_Argument_Association
(Loc
,
7885 Expression
=> Make_String_Literal
(Loc
, Str
)));
7888 -- Add Check pragma to list of statements
7892 Pragma_Identifier
=>
7893 Make_Identifier
(Loc
, Name_Check
),
7894 Pragma_Argument_Associations
=> Assoc
));
7896 -- If Inherited case and option enabled, output info msg. Note
7897 -- that we know this is a case of Invariant'Class.
7899 if Inherit
and Opt
.List_Inherited_Aspects
then
7900 Error_Msg_Sloc
:= Sloc
(Ritem
);
7902 ("info: & inherits `Invariant''Class` aspect from #?L?",
7908 Next_Rep_Item
(Ritem
);
7912 -- Start of processing for Build_Invariant_Procedure
7920 -- If the aspect specification exists for some view of the type, the
7921 -- declaration for the procedure has been created.
7923 if Has_Invariants
(Typ
) then
7924 SId
:= Invariant_Procedure
(Typ
);
7927 -- If the body is already present, nothing to do. This will occur when
7928 -- the type is already frozen, which is the case when the invariant
7929 -- appears in a private part, and the freezing takes place before the
7930 -- final pass over full declarations.
7932 -- See Exp_Ch3.Insert_Component_Invariant_Checks for details.
7934 if Present
(SId
) then
7935 PDecl
:= Unit_Declaration_Node
(SId
);
7938 and then Nkind
(PDecl
) = N_Subprogram_Declaration
7939 and then Present
(Corresponding_Body
(PDecl
))
7945 PDecl
:= Build_Invariant_Procedure_Declaration
(Typ
);
7948 -- Recover formal of procedure, for use in the calls to invariant
7949 -- functions (including inherited ones).
7953 (First
(Parameter_Specifications
(Specification
(PDecl
))));
7954 Object_Name
:= Chars
(Object_Entity
);
7956 -- Add invariants for the current type
7958 Add_Invariants
(Typ
, Inherit
=> False);
7960 -- Add invariants for parent types
7963 Current_Typ
: Entity_Id
;
7964 Parent_Typ
: Entity_Id
;
7969 Parent_Typ
:= Etype
(Current_Typ
);
7971 if Is_Private_Type
(Parent_Typ
)
7972 and then Present
(Full_View
(Base_Type
(Parent_Typ
)))
7974 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
7977 exit when Parent_Typ
= Current_Typ
;
7979 Current_Typ
:= Parent_Typ
;
7980 Add_Invariants
(Current_Typ
, Inherit
=> True);
7984 -- Add invariants of progenitors
7986 if Is_Tagged_Type
(Typ
) and then not Is_Interface
(Typ
) then
7988 Ifaces_List
: Elist_Id
;
7993 Collect_Interfaces
(Typ
, Ifaces_List
);
7995 AI
:= First_Elmt
(Ifaces_List
);
7996 while Present
(AI
) loop
7999 if not Is_Ancestor
(Iface
, Typ
, Use_Full_View
=> True) then
8000 Add_Invariants
(Iface
, Inherit
=> True);
8008 -- Build the procedure if we generated at least one Check pragma
8010 if Stmts
/= No_List
then
8011 Spec
:= Copy_Separate_Tree
(Specification
(PDecl
));
8014 Make_Subprogram_Body
(Loc
,
8015 Specification
=> Spec
,
8016 Declarations
=> Empty_List
,
8017 Handled_Statement_Sequence
=>
8018 Make_Handled_Sequence_Of_Statements
(Loc
,
8019 Statements
=> Stmts
));
8021 -- Insert procedure declaration and spec at the appropriate points.
8022 -- If declaration is already analyzed, it was processed by the
8023 -- generated pragma.
8025 if Present
(Private_Decls
) then
8027 -- The spec goes at the end of visible declarations, but they have
8028 -- already been analyzed, so we need to explicitly do the analyze.
8030 if not Analyzed
(PDecl
) then
8031 Append_To
(Visible_Decls
, PDecl
);
8035 -- The body goes at the end of the private declarations, which we
8036 -- have not analyzed yet, so we do not need to perform an explicit
8037 -- analyze call. We skip this if there are no private declarations
8038 -- (this is an error that will be caught elsewhere);
8040 Append_To
(Private_Decls
, PBody
);
8042 -- If the invariant appears on the full view of a type, the
8043 -- analysis of the private part is complete, and we must
8044 -- analyze the new body explicitly.
8046 if In_Private_Part
(Current_Scope
) then
8050 -- If there are no private declarations this may be an error that
8051 -- will be diagnosed elsewhere. However, if this is a non-private
8052 -- type that inherits invariants, it needs no completion and there
8053 -- may be no private part. In this case insert invariant procedure
8054 -- at end of current declarative list, and analyze at once, given
8055 -- that the type is about to be frozen.
8057 elsif not Is_Private_Type
(Typ
) then
8058 Append_To
(Visible_Decls
, PDecl
);
8059 Append_To
(Visible_Decls
, PBody
);
8064 end Build_Invariant_Procedure
;
8066 -------------------------------
8067 -- Build_Predicate_Functions --
8068 -------------------------------
8070 -- The procedures that are constructed here have the form:
8072 -- function typPredicate (Ixxx : typ) return Boolean is
8075 -- exp1 and then exp2 and then ...
8076 -- and then typ1Predicate (typ1 (Ixxx))
8077 -- and then typ2Predicate (typ2 (Ixxx))
8079 -- end typPredicate;
8081 -- Here exp1, and exp2 are expressions from Predicate pragmas. Note that
8082 -- this is the point at which these expressions get analyzed, providing the
8083 -- required delay, and typ1, typ2, are entities from which predicates are
8084 -- inherited. Note that we do NOT generate Check pragmas, that's because we
8085 -- use this function even if checks are off, e.g. for membership tests.
8087 -- If the expression has at least one Raise_Expression, then we also build
8088 -- the typPredicateM version of the function, in which any occurrence of a
8089 -- Raise_Expression is converted to "return False".
8091 procedure Build_Predicate_Functions
(Typ
: Entity_Id
; N
: Node_Id
) is
8092 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
8095 -- This is the expression for the result of the function. It is
8096 -- is build by connecting the component predicates with AND THEN.
8099 -- This is the corresponding return expression for the Predicate_M
8100 -- function. It differs in that raise expressions are marked for
8101 -- special expansion (see Process_REs).
8103 Object_Name
: constant Name_Id
:= New_Internal_Name
('I');
8104 -- Name for argument of Predicate procedure. Note that we use the same
8105 -- name for both predicate functions. That way the reference within the
8106 -- predicate expression is the same in both functions.
8108 Object_Entity
: constant Entity_Id
:=
8109 Make_Defining_Identifier
(Loc
, Chars
=> Object_Name
);
8110 -- Entity for argument of Predicate procedure
8112 Object_Entity_M
: constant Entity_Id
:=
8113 Make_Defining_Identifier
(Loc
, Chars
=> Object_Name
);
8114 -- Entity for argument of Predicate_M procedure
8116 Raise_Expression_Present
: Boolean := False;
8117 -- Set True if Expr has at least one Raise_Expression
8119 procedure Add_Call
(T
: Entity_Id
);
8120 -- Includes a call to the predicate function for type T in Expr if T
8121 -- has predicates and Predicate_Function (T) is non-empty.
8123 procedure Add_Predicates
;
8124 -- Appends expressions for any Predicate pragmas in the rep item chain
8125 -- Typ to Expr. Note that we look only at items for this exact entity.
8126 -- Inheritance of predicates for the parent type is done by calling the
8127 -- Predicate_Function of the parent type, using Add_Call above.
8129 function Test_RE
(N
: Node_Id
) return Traverse_Result
;
8130 -- Used in Test_REs, tests one node for being a raise expression, and if
8131 -- so sets Raise_Expression_Present True.
8133 procedure Test_REs
is new Traverse_Proc
(Test_RE
);
8134 -- Tests to see if Expr contains any raise expressions
8136 function Process_RE
(N
: Node_Id
) return Traverse_Result
;
8137 -- Used in Process REs, tests if node N is a raise expression, and if
8138 -- so, marks it to be converted to return False.
8140 procedure Process_REs
is new Traverse_Proc
(Process_RE
);
8141 -- Marks any raise expressions in Expr_M to return False
8147 procedure Add_Call
(T
: Entity_Id
) is
8151 if Present
(T
) and then Present
(Predicate_Function
(T
)) then
8152 Set_Has_Predicates
(Typ
);
8154 -- Build the call to the predicate function of T
8158 (T
, Convert_To
(T
, Make_Identifier
(Loc
, Object_Name
)));
8160 -- Add call to evolving expression, using AND THEN if needed
8167 Make_And_Then
(Sloc
(Expr
),
8168 Left_Opnd
=> Relocate_Node
(Expr
),
8172 -- Output info message on inheritance if required. Note we do not
8173 -- give this information for generic actual types, since it is
8174 -- unwelcome noise in that case in instantiations. We also
8175 -- generally suppress the message in instantiations, and also
8176 -- if it involves internal names.
8178 if Opt
.List_Inherited_Aspects
8179 and then not Is_Generic_Actual_Type
(Typ
)
8180 and then Instantiation_Depth
(Sloc
(Typ
)) = 0
8181 and then not Is_Internal_Name
(Chars
(T
))
8182 and then not Is_Internal_Name
(Chars
(Typ
))
8184 Error_Msg_Sloc
:= Sloc
(Predicate_Function
(T
));
8185 Error_Msg_Node_2
:= T
;
8186 Error_Msg_N
("info: & inherits predicate from & #?L?", Typ
);
8191 --------------------
8192 -- Add_Predicates --
8193 --------------------
8195 procedure Add_Predicates
is
8200 procedure Replace_Type_Reference
(N
: Node_Id
);
8201 -- Replace a single occurrence N of the subtype name with a reference
8202 -- to the formal of the predicate function. N can be an identifier
8203 -- referencing the subtype, or a selected component, representing an
8204 -- appropriately qualified occurrence of the subtype name.
8206 procedure Replace_Type_References
is
8207 new Replace_Type_References_Generic
(Replace_Type_Reference
);
8208 -- Traverse an expression changing every occurrence of an identifier
8209 -- whose name matches the name of the subtype with a reference to
8210 -- the formal parameter of the predicate function.
8212 ----------------------------
8213 -- Replace_Type_Reference --
8214 ----------------------------
8216 procedure Replace_Type_Reference
(N
: Node_Id
) is
8218 Rewrite
(N
, Make_Identifier
(Sloc
(N
), Object_Name
));
8219 -- Use the Sloc of the usage name, not the defining name
8222 Set_Entity
(N
, Object_Entity
);
8224 -- We want to treat the node as if it comes from source, so that
8225 -- ASIS will not ignore it
8227 Set_Comes_From_Source
(N
, True);
8228 end Replace_Type_Reference
;
8230 -- Start of processing for Add_Predicates
8233 Ritem
:= First_Rep_Item
(Typ
);
8234 while Present
(Ritem
) loop
8235 if Nkind
(Ritem
) = N_Pragma
8236 and then Pragma_Name
(Ritem
) = Name_Predicate
8238 -- Acquire arguments
8240 Arg1
:= First
(Pragma_Argument_Associations
(Ritem
));
8241 Arg2
:= Next
(Arg1
);
8243 Arg1
:= Get_Pragma_Arg
(Arg1
);
8244 Arg2
:= Get_Pragma_Arg
(Arg2
);
8246 -- See if this predicate pragma is for the current type or for
8247 -- its full view. A predicate on a private completion is placed
8248 -- on the partial view beause this is the visible entity that
8251 if Entity
(Arg1
) = Typ
8252 or else Full_View
(Entity
(Arg1
)) = Typ
8254 -- We have a match, this entry is for our subtype
8256 -- We need to replace any occurrences of the name of the
8257 -- type with references to the object.
8259 Replace_Type_References
(Arg2
, Typ
);
8261 -- If this predicate comes from an aspect, find the aspect
8262 -- specification, and replace the saved expression because
8263 -- we need the subtype references replaced for the calls to
8264 -- Preanalyze_Spec_Expressin in Check_Aspect_At_Freeze_Point
8265 -- and Check_Aspect_At_End_Of_Declarations.
8267 if From_Aspect_Specification
(Ritem
) then
8272 -- Loop to find corresponding aspect, note that this
8273 -- must be present given the pragma is marked delayed.
8275 Aitem
:= Next_Rep_Item
(Ritem
);
8277 if Nkind
(Aitem
) = N_Aspect_Specification
8278 and then Aspect_Rep_Item
(Aitem
) = Ritem
8281 (Identifier
(Aitem
), New_Copy_Tree
(Arg2
));
8285 Aitem
:= Next_Rep_Item
(Aitem
);
8290 -- Now we can add the expression
8293 Expr
:= Relocate_Node
(Arg2
);
8295 -- There already was a predicate, so add to it
8300 Left_Opnd
=> Relocate_Node
(Expr
),
8301 Right_Opnd
=> Relocate_Node
(Arg2
));
8306 Next_Rep_Item
(Ritem
);
8314 function Process_RE
(N
: Node_Id
) return Traverse_Result
is
8316 if Nkind
(N
) = N_Raise_Expression
then
8317 Set_Convert_To_Return_False
(N
);
8328 function Test_RE
(N
: Node_Id
) return Traverse_Result
is
8330 if Nkind
(N
) = N_Raise_Expression
then
8331 Raise_Expression_Present
:= True;
8338 -- Start of processing for Build_Predicate_Functions
8341 -- Return if already built or if type does not have predicates
8343 if not Has_Predicates
(Typ
)
8344 or else Present
(Predicate_Function
(Typ
))
8349 -- Prepare to construct predicate expression
8353 -- Add Predicates for the current type
8357 -- Add predicates for ancestor if present
8360 Atyp
: constant Entity_Id
:= Nearest_Ancestor
(Typ
);
8362 if Present
(Atyp
) then
8367 -- Case where predicates are present
8369 if Present
(Expr
) then
8371 -- Test for raise expression present
8375 -- If raise expression is present, capture a copy of Expr for use
8376 -- in building the predicateM function version later on. For this
8377 -- copy we replace references to Object_Entity by Object_Entity_M.
8379 if Raise_Expression_Present
then
8381 Map
: constant Elist_Id
:= New_Elmt_List
;
8382 New_V
: Entity_Id
:= Empty
;
8384 -- The unanalyzed expression will be copied and appear in
8385 -- both functions. Normally expressions do not declare new
8386 -- entities, but quantified expressions do, so we need to
8387 -- create new entities for their bound variables, to prevent
8388 -- multiple definitions in gigi.
8390 function Reset_Loop_Variable
(N
: Node_Id
)
8391 return Traverse_Result
;
8393 procedure Collect_Loop_Variables
is
8394 new Traverse_Proc
(Reset_Loop_Variable
);
8396 ------------------------
8397 -- Reset_Loop_Variable --
8398 ------------------------
8400 function Reset_Loop_Variable
(N
: Node_Id
)
8401 return Traverse_Result
8404 if Nkind
(N
) = N_Iterator_Specification
then
8405 New_V
:= Make_Defining_Identifier
8406 (Sloc
(N
), Chars
(Defining_Identifier
(N
)));
8408 Set_Defining_Identifier
(N
, New_V
);
8412 end Reset_Loop_Variable
;
8415 Append_Elmt
(Object_Entity
, Map
);
8416 Append_Elmt
(Object_Entity_M
, Map
);
8417 Expr_M
:= New_Copy_Tree
(Expr
, Map
=> Map
);
8418 Collect_Loop_Variables
(Expr_M
);
8422 -- Build the main predicate function
8425 SId
: constant Entity_Id
:=
8426 Make_Defining_Identifier
(Loc
,
8427 Chars
=> New_External_Name
(Chars
(Typ
), "Predicate"));
8428 -- The entity for the the function spec
8430 SIdB
: constant Entity_Id
:=
8431 Make_Defining_Identifier
(Loc
,
8432 Chars
=> New_External_Name
(Chars
(Typ
), "Predicate"));
8433 -- The entity for the function body
8440 -- Build function declaration
8442 Set_Ekind
(SId
, E_Function
);
8443 Set_Is_Internal
(SId
);
8444 Set_Is_Predicate_Function
(SId
);
8445 Set_Predicate_Function
(Typ
, SId
);
8447 -- The predicate function is shared between views of a type
8449 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
8450 Set_Predicate_Function
(Full_View
(Typ
), SId
);
8454 Make_Function_Specification
(Loc
,
8455 Defining_Unit_Name
=> SId
,
8456 Parameter_Specifications
=> New_List
(
8457 Make_Parameter_Specification
(Loc
,
8458 Defining_Identifier
=> Object_Entity
,
8459 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))),
8460 Result_Definition
=>
8461 New_Occurrence_Of
(Standard_Boolean
, Loc
));
8464 Make_Subprogram_Declaration
(Loc
,
8465 Specification
=> Spec
);
8467 -- Build function body
8470 Make_Function_Specification
(Loc
,
8471 Defining_Unit_Name
=> SIdB
,
8472 Parameter_Specifications
=> New_List
(
8473 Make_Parameter_Specification
(Loc
,
8474 Defining_Identifier
=>
8475 Make_Defining_Identifier
(Loc
, Object_Name
),
8477 New_Occurrence_Of
(Typ
, Loc
))),
8478 Result_Definition
=>
8479 New_Occurrence_Of
(Standard_Boolean
, Loc
));
8482 Make_Subprogram_Body
(Loc
,
8483 Specification
=> Spec
,
8484 Declarations
=> Empty_List
,
8485 Handled_Statement_Sequence
=>
8486 Make_Handled_Sequence_Of_Statements
(Loc
,
8487 Statements
=> New_List
(
8488 Make_Simple_Return_Statement
(Loc
,
8489 Expression
=> Expr
))));
8491 -- Insert declaration before freeze node and body after
8493 Insert_Before_And_Analyze
(N
, FDecl
);
8494 Insert_After_And_Analyze
(N
, FBody
);
8497 -- Test for raise expressions present and if so build M version
8499 if Raise_Expression_Present
then
8501 SId
: constant Entity_Id
:=
8502 Make_Defining_Identifier
(Loc
,
8503 Chars
=> New_External_Name
(Chars
(Typ
), "PredicateM"));
8504 -- The entity for the the function spec
8506 SIdB
: constant Entity_Id
:=
8507 Make_Defining_Identifier
(Loc
,
8508 Chars
=> New_External_Name
(Chars
(Typ
), "PredicateM"));
8509 -- The entity for the function body
8517 -- Mark any raise expressions for special expansion
8519 Process_REs
(Expr_M
);
8521 -- Build function declaration
8523 Set_Ekind
(SId
, E_Function
);
8524 Set_Is_Predicate_Function_M
(SId
);
8525 Set_Predicate_Function_M
(Typ
, SId
);
8527 -- The predicate function is shared between views of a type
8529 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
8530 Set_Predicate_Function_M
(Full_View
(Typ
), SId
);
8534 Make_Function_Specification
(Loc
,
8535 Defining_Unit_Name
=> SId
,
8536 Parameter_Specifications
=> New_List
(
8537 Make_Parameter_Specification
(Loc
,
8538 Defining_Identifier
=> Object_Entity_M
,
8539 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))),
8540 Result_Definition
=>
8541 New_Occurrence_Of
(Standard_Boolean
, Loc
));
8544 Make_Subprogram_Declaration
(Loc
,
8545 Specification
=> Spec
);
8547 -- Build function body
8550 Make_Function_Specification
(Loc
,
8551 Defining_Unit_Name
=> SIdB
,
8552 Parameter_Specifications
=> New_List
(
8553 Make_Parameter_Specification
(Loc
,
8554 Defining_Identifier
=>
8555 Make_Defining_Identifier
(Loc
, Object_Name
),
8557 New_Occurrence_Of
(Typ
, Loc
))),
8558 Result_Definition
=>
8559 New_Occurrence_Of
(Standard_Boolean
, Loc
));
8561 -- Build the body, we declare the boolean expression before
8562 -- doing the return, because we are not really confident of
8563 -- what happens if a return appears within a return.
8566 Make_Defining_Identifier
(Loc
,
8567 Chars
=> New_Internal_Name
('B'));
8570 Make_Subprogram_Body
(Loc
,
8571 Specification
=> Spec
,
8573 Declarations
=> New_List
(
8574 Make_Object_Declaration
(Loc
,
8575 Defining_Identifier
=> BTemp
,
8576 Constant_Present
=> True,
8577 Object_Definition
=>
8578 New_Occurrence_Of
(Standard_Boolean
, Loc
),
8579 Expression
=> Expr_M
)),
8581 Handled_Statement_Sequence
=>
8582 Make_Handled_Sequence_Of_Statements
(Loc
,
8583 Statements
=> New_List
(
8584 Make_Simple_Return_Statement
(Loc
,
8585 Expression
=> New_Occurrence_Of
(BTemp
, Loc
)))));
8587 -- Insert declaration before freeze node and body after
8589 Insert_Before_And_Analyze
(N
, FDecl
);
8590 Insert_After_And_Analyze
(N
, FBody
);
8594 -- See if we have a static predicate. Note that the answer may be
8595 -- yes even if we have an explicit Dynamic_Predicate present.
8602 if not Is_Scalar_Type
(Typ
) and then not Is_String_Type
(Typ
) then
8605 PS
:= Is_Predicate_Static
(Expr
, Object_Name
);
8608 -- Case where we have a predicate-static aspect
8612 -- We don't set Has_Static_Predicate_Aspect, since we can have
8613 -- any of the three cases (Predicate, Dynamic_Predicate, or
8614 -- Static_Predicate) generating a predicate with an expression
8615 -- that is predicate-static. We just indicate that we have a
8616 -- predicate that can be treated as static.
8618 Set_Has_Static_Predicate
(Typ
);
8620 -- For discrete subtype, build the static predicate list
8622 if Is_Discrete_Type
(Typ
) then
8623 Build_Discrete_Static_Predicate
(Typ
, Expr
, Object_Name
);
8625 -- If we don't get a static predicate list, it means that we
8626 -- have a case where this is not possible, most typically in
8627 -- the case where we inherit a dynamic predicate. We do not
8628 -- consider this an error, we just leave the predicate as
8629 -- dynamic. But if we do succeed in building the list, then
8630 -- we mark the predicate as static.
8632 if No
(Static_Discrete_Predicate
(Typ
)) then
8633 Set_Has_Static_Predicate
(Typ
, False);
8636 -- For real or string subtype, save predicate expression
8638 elsif Is_Real_Type
(Typ
) or else Is_String_Type
(Typ
) then
8639 Set_Static_Real_Or_String_Predicate
(Typ
, Expr
);
8642 -- Case of dynamic predicate (expression is not predicate-static)
8645 -- Again, we don't set Has_Dynamic_Predicate_Aspect, since that
8646 -- is only set if we have an explicit Dynamic_Predicate aspect
8647 -- given. Here we may simply have a Predicate aspect where the
8648 -- expression happens not to be predicate-static.
8650 -- Emit an error when the predicate is categorized as static
8651 -- but its expression is not predicate-static.
8653 -- First a little fiddling to get a nice location for the
8654 -- message. If the expression is of the form (A and then B),
8655 -- then use the left operand for the Sloc. This avoids getting
8656 -- confused by a call to a higher-level predicate with a less
8657 -- convenient source location.
8660 while Nkind
(EN
) = N_And_Then
loop
8661 EN
:= Left_Opnd
(EN
);
8664 -- Now post appropriate message
8666 if Has_Static_Predicate_Aspect
(Typ
) then
8667 if Is_Scalar_Type
(Typ
) or else Is_String_Type
(Typ
) then
8669 ("expression is not predicate-static (RM 3.2.4(16-22))",
8673 ("static predicate requires scalar or string type", EN
);
8679 end Build_Predicate_Functions
;
8681 -----------------------------------------
8682 -- Check_Aspect_At_End_Of_Declarations --
8683 -----------------------------------------
8685 procedure Check_Aspect_At_End_Of_Declarations
(ASN
: Node_Id
) is
8686 Ent
: constant Entity_Id
:= Entity
(ASN
);
8687 Ident
: constant Node_Id
:= Identifier
(ASN
);
8688 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Chars
(Ident
));
8690 End_Decl_Expr
: constant Node_Id
:= Entity
(Ident
);
8691 -- Expression to be analyzed at end of declarations
8693 Freeze_Expr
: constant Node_Id
:= Expression
(ASN
);
8694 -- Expression from call to Check_Aspect_At_Freeze_Point
8696 T
: constant Entity_Id
:= Etype
(Freeze_Expr
);
8697 -- Type required for preanalyze call
8700 -- Set False if error
8702 -- On entry to this procedure, Entity (Ident) contains a copy of the
8703 -- original expression from the aspect, saved for this purpose, and
8704 -- but Expression (Ident) is a preanalyzed copy of the expression,
8705 -- preanalyzed just after the freeze point.
8707 procedure Check_Overloaded_Name
;
8708 -- For aspects whose expression is simply a name, this routine checks if
8709 -- the name is overloaded or not. If so, it verifies there is an
8710 -- interpretation that matches the entity obtained at the freeze point,
8711 -- otherwise the compiler complains.
8713 ---------------------------
8714 -- Check_Overloaded_Name --
8715 ---------------------------
8717 procedure Check_Overloaded_Name
is
8719 if not Is_Overloaded
(End_Decl_Expr
) then
8720 Err
:= not Is_Entity_Name
(End_Decl_Expr
)
8721 or else Entity
(End_Decl_Expr
) /= Entity
(Freeze_Expr
);
8727 Index
: Interp_Index
;
8731 Get_First_Interp
(End_Decl_Expr
, Index
, It
);
8732 while Present
(It
.Typ
) loop
8733 if It
.Nam
= Entity
(Freeze_Expr
) then
8738 Get_Next_Interp
(Index
, It
);
8742 end Check_Overloaded_Name
;
8744 -- Start of processing for Check_Aspect_At_End_Of_Declarations
8747 -- Case of aspects Dimension, Dimension_System and Synchronization
8749 if A_Id
= Aspect_Synchronization
then
8752 -- Case of stream attributes, just have to compare entities. However,
8753 -- the expression is just a name (possibly overloaded), and there may
8754 -- be stream operations declared for unrelated types, so we just need
8755 -- to verify that one of these interpretations is the one available at
8756 -- at the freeze point.
8758 elsif A_Id
= Aspect_Input
or else
8759 A_Id
= Aspect_Output
or else
8760 A_Id
= Aspect_Read
or else
8763 Analyze
(End_Decl_Expr
);
8764 Check_Overloaded_Name
;
8766 elsif A_Id
= Aspect_Variable_Indexing
or else
8767 A_Id
= Aspect_Constant_Indexing
or else
8768 A_Id
= Aspect_Default_Iterator
or else
8769 A_Id
= Aspect_Iterator_Element
8771 -- Make type unfrozen before analysis, to prevent spurious errors
8772 -- about late attributes.
8774 Set_Is_Frozen
(Ent
, False);
8775 Analyze
(End_Decl_Expr
);
8776 Set_Is_Frozen
(Ent
, True);
8778 -- If the end of declarations comes before any other freeze
8779 -- point, the Freeze_Expr is not analyzed: no check needed.
8781 if Analyzed
(Freeze_Expr
) and then not In_Instance
then
8782 Check_Overloaded_Name
;
8790 -- Indicate that the expression comes from an aspect specification,
8791 -- which is used in subsequent analysis even if expansion is off.
8793 Set_Parent
(End_Decl_Expr
, ASN
);
8795 -- In a generic context the aspect expressions have not been
8796 -- preanalyzed, so do it now. There are no conformance checks
8797 -- to perform in this case.
8800 Check_Aspect_At_Freeze_Point
(ASN
);
8803 -- The default values attributes may be defined in the private part,
8804 -- and the analysis of the expression may take place when only the
8805 -- partial view is visible. The expression must be scalar, so use
8806 -- the full view to resolve.
8808 elsif (A_Id
= Aspect_Default_Value
8810 A_Id
= Aspect_Default_Component_Value
)
8811 and then Is_Private_Type
(T
)
8813 Preanalyze_Spec_Expression
(End_Decl_Expr
, Full_View
(T
));
8816 Preanalyze_Spec_Expression
(End_Decl_Expr
, T
);
8819 Err
:= not Fully_Conformant_Expressions
(End_Decl_Expr
, Freeze_Expr
);
8822 -- Output error message if error. Force error on aspect specification
8823 -- even if there is an error on the expression itself.
8827 ("!visibility of aspect for& changes after freeze point",
8830 ("info: & is frozen here, aspects evaluated at this point??",
8831 Freeze_Node
(Ent
), Ent
);
8833 end Check_Aspect_At_End_Of_Declarations
;
8835 ----------------------------------
8836 -- Check_Aspect_At_Freeze_Point --
8837 ----------------------------------
8839 procedure Check_Aspect_At_Freeze_Point
(ASN
: Node_Id
) is
8840 Ident
: constant Node_Id
:= Identifier
(ASN
);
8841 -- Identifier (use Entity field to save expression)
8843 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Chars
(Ident
));
8845 T
: Entity_Id
:= Empty
;
8846 -- Type required for preanalyze call
8849 -- On entry to this procedure, Entity (Ident) contains a copy of the
8850 -- original expression from the aspect, saved for this purpose.
8852 -- On exit from this procedure Entity (Ident) is unchanged, still
8853 -- containing that copy, but Expression (Ident) is a preanalyzed copy
8854 -- of the expression, preanalyzed just after the freeze point.
8856 -- Make a copy of the expression to be preanalyzed
8858 Set_Expression
(ASN
, New_Copy_Tree
(Entity
(Ident
)));
8860 -- Find type for preanalyze call
8864 -- No_Aspect should be impossible
8867 raise Program_Error
;
8869 -- Aspects taking an optional boolean argument
8871 when Boolean_Aspects |
8872 Library_Unit_Aspects
=>
8874 T
:= Standard_Boolean
;
8876 -- Aspects corresponding to attribute definition clauses
8878 when Aspect_Address
=>
8879 T
:= RTE
(RE_Address
);
8881 when Aspect_Attach_Handler
=>
8882 T
:= RTE
(RE_Interrupt_ID
);
8884 when Aspect_Bit_Order | Aspect_Scalar_Storage_Order
=>
8885 T
:= RTE
(RE_Bit_Order
);
8887 when Aspect_Convention
=>
8891 T
:= RTE
(RE_CPU_Range
);
8893 -- Default_Component_Value is resolved with the component type
8895 when Aspect_Default_Component_Value
=>
8896 T
:= Component_Type
(Entity
(ASN
));
8898 when Aspect_Default_Storage_Pool
=>
8899 T
:= Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
));
8901 -- Default_Value is resolved with the type entity in question
8903 when Aspect_Default_Value
=>
8906 when Aspect_Dispatching_Domain
=>
8907 T
:= RTE
(RE_Dispatching_Domain
);
8909 when Aspect_External_Tag
=>
8910 T
:= Standard_String
;
8912 when Aspect_External_Name
=>
8913 T
:= Standard_String
;
8915 when Aspect_Link_Name
=>
8916 T
:= Standard_String
;
8918 when Aspect_Priority | Aspect_Interrupt_Priority
=>
8919 T
:= Standard_Integer
;
8921 when Aspect_Relative_Deadline
=>
8922 T
:= RTE
(RE_Time_Span
);
8924 when Aspect_Small
=>
8925 T
:= Universal_Real
;
8927 -- For a simple storage pool, we have to retrieve the type of the
8928 -- pool object associated with the aspect's corresponding attribute
8929 -- definition clause.
8931 when Aspect_Simple_Storage_Pool
=>
8932 T
:= Etype
(Expression
(Aspect_Rep_Item
(ASN
)));
8934 when Aspect_Storage_Pool
=>
8935 T
:= Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
));
8937 when Aspect_Alignment |
8938 Aspect_Component_Size |
8939 Aspect_Machine_Radix |
8940 Aspect_Object_Size |
8942 Aspect_Storage_Size |
8943 Aspect_Stream_Size |
8944 Aspect_Value_Size
=>
8947 when Aspect_Linker_Section
=>
8948 T
:= Standard_String
;
8950 when Aspect_Synchronization
=>
8953 -- Special case, the expression of these aspects is just an entity
8954 -- that does not need any resolution, so just analyze.
8963 Analyze
(Expression
(ASN
));
8966 -- Same for Iterator aspects, where the expression is a function
8967 -- name. Legality rules are checked separately.
8969 when Aspect_Constant_Indexing |
8970 Aspect_Default_Iterator |
8971 Aspect_Iterator_Element |
8972 Aspect_Variable_Indexing
=>
8973 Analyze
(Expression
(ASN
));
8976 -- Ditto for Iterable, legality checks in Validate_Iterable_Aspect.
8978 when Aspect_Iterable
=>
8982 Cursor
: constant Entity_Id
:= Get_Cursor_Type
(ASN
, T
);
8987 if Cursor
= Any_Type
then
8991 Assoc
:= First
(Component_Associations
(Expression
(ASN
)));
8992 while Present
(Assoc
) loop
8993 Expr
:= Expression
(Assoc
);
8996 if not Error_Posted
(Expr
) then
8997 Resolve_Iterable_Operation
8998 (Expr
, Cursor
, T
, Chars
(First
(Choices
(Assoc
))));
9007 -- Invariant/Predicate take boolean expressions
9009 when Aspect_Dynamic_Predicate |
9012 Aspect_Static_Predicate |
9013 Aspect_Type_Invariant
=>
9014 T
:= Standard_Boolean
;
9016 -- Here is the list of aspects that don't require delay analysis
9018 when Aspect_Abstract_State |
9020 Aspect_Contract_Cases |
9021 Aspect_Default_Initial_Condition |
9024 Aspect_Dimension_System |
9025 Aspect_Extensions_Visible |
9028 Aspect_Implicit_Dereference |
9029 Aspect_Initial_Condition |
9030 Aspect_Initializes |
9031 Aspect_Obsolescent |
9034 Aspect_Postcondition |
9036 Aspect_Precondition |
9037 Aspect_Refined_Depends |
9038 Aspect_Refined_Global |
9039 Aspect_Refined_Post |
9040 Aspect_Refined_State |
9043 Aspect_Unimplemented
=>
9044 raise Program_Error
;
9048 -- Do the preanalyze call
9050 Preanalyze_Spec_Expression
(Expression
(ASN
), T
);
9051 end Check_Aspect_At_Freeze_Point
;
9053 -----------------------------------
9054 -- Check_Constant_Address_Clause --
9055 -----------------------------------
9057 procedure Check_Constant_Address_Clause
9061 procedure Check_At_Constant_Address
(Nod
: Node_Id
);
9062 -- Checks that the given node N represents a name whose 'Address is
9063 -- constant (in the same sense as OK_Constant_Address_Clause, i.e. the
9064 -- address value is the same at the point of declaration of U_Ent and at
9065 -- the time of elaboration of the address clause.
9067 procedure Check_Expr_Constants
(Nod
: Node_Id
);
9068 -- Checks that Nod meets the requirements for a constant address clause
9069 -- in the sense of the enclosing procedure.
9071 procedure Check_List_Constants
(Lst
: List_Id
);
9072 -- Check that all elements of list Lst meet the requirements for a
9073 -- constant address clause in the sense of the enclosing procedure.
9075 -------------------------------
9076 -- Check_At_Constant_Address --
9077 -------------------------------
9079 procedure Check_At_Constant_Address
(Nod
: Node_Id
) is
9081 if Is_Entity_Name
(Nod
) then
9082 if Present
(Address_Clause
(Entity
((Nod
)))) then
9084 ("invalid address clause for initialized object &!",
9087 ("address for& cannot" &
9088 " depend on another address clause! (RM 13.1(22))!",
9091 elsif In_Same_Source_Unit
(Entity
(Nod
), U_Ent
)
9092 and then Sloc
(U_Ent
) < Sloc
(Entity
(Nod
))
9095 ("invalid address clause for initialized object &!",
9097 Error_Msg_Node_2
:= U_Ent
;
9099 ("\& must be defined before & (RM 13.1(22))!",
9103 elsif Nkind
(Nod
) = N_Selected_Component
then
9105 T
: constant Entity_Id
:= Etype
(Prefix
(Nod
));
9108 if (Is_Record_Type
(T
)
9109 and then Has_Discriminants
(T
))
9112 and then Is_Record_Type
(Designated_Type
(T
))
9113 and then Has_Discriminants
(Designated_Type
(T
)))
9116 ("invalid address clause for initialized object &!",
9119 ("\address cannot depend on component" &
9120 " of discriminated record (RM 13.1(22))!",
9123 Check_At_Constant_Address
(Prefix
(Nod
));
9127 elsif Nkind
(Nod
) = N_Indexed_Component
then
9128 Check_At_Constant_Address
(Prefix
(Nod
));
9129 Check_List_Constants
(Expressions
(Nod
));
9132 Check_Expr_Constants
(Nod
);
9134 end Check_At_Constant_Address
;
9136 --------------------------
9137 -- Check_Expr_Constants --
9138 --------------------------
9140 procedure Check_Expr_Constants
(Nod
: Node_Id
) is
9141 Loc_U_Ent
: constant Source_Ptr
:= Sloc
(U_Ent
);
9142 Ent
: Entity_Id
:= Empty
;
9145 if Nkind
(Nod
) in N_Has_Etype
9146 and then Etype
(Nod
) = Any_Type
9152 when N_Empty | N_Error
=>
9155 when N_Identifier | N_Expanded_Name
=>
9156 Ent
:= Entity
(Nod
);
9158 -- We need to look at the original node if it is different
9159 -- from the node, since we may have rewritten things and
9160 -- substituted an identifier representing the rewrite.
9162 if Original_Node
(Nod
) /= Nod
then
9163 Check_Expr_Constants
(Original_Node
(Nod
));
9165 -- If the node is an object declaration without initial
9166 -- value, some code has been expanded, and the expression
9167 -- is not constant, even if the constituents might be
9168 -- acceptable, as in A'Address + offset.
9170 if Ekind
(Ent
) = E_Variable
9172 Nkind
(Declaration_Node
(Ent
)) = N_Object_Declaration
9174 No
(Expression
(Declaration_Node
(Ent
)))
9177 ("invalid address clause for initialized object &!",
9180 -- If entity is constant, it may be the result of expanding
9181 -- a check. We must verify that its declaration appears
9182 -- before the object in question, else we also reject the
9185 elsif Ekind
(Ent
) = E_Constant
9186 and then In_Same_Source_Unit
(Ent
, U_Ent
)
9187 and then Sloc
(Ent
) > Loc_U_Ent
9190 ("invalid address clause for initialized object &!",
9197 -- Otherwise look at the identifier and see if it is OK
9199 if Ekind_In
(Ent
, E_Named_Integer
, E_Named_Real
)
9200 or else Is_Type
(Ent
)
9204 elsif Ekind_In
(Ent
, E_Constant
, E_In_Parameter
) then
9206 -- This is the case where we must have Ent defined before
9207 -- U_Ent. Clearly if they are in different units this
9208 -- requirement is met since the unit containing Ent is
9209 -- already processed.
9211 if not In_Same_Source_Unit
(Ent
, U_Ent
) then
9214 -- Otherwise location of Ent must be before the location
9215 -- of U_Ent, that's what prior defined means.
9217 elsif Sloc
(Ent
) < Loc_U_Ent
then
9222 ("invalid address clause for initialized object &!",
9224 Error_Msg_Node_2
:= U_Ent
;
9226 ("\& must be defined before & (RM 13.1(22))!",
9230 elsif Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
9231 Check_Expr_Constants
(Original_Node
(Nod
));
9235 ("invalid address clause for initialized object &!",
9238 if Comes_From_Source
(Ent
) then
9240 ("\reference to variable& not allowed"
9241 & " (RM 13.1(22))!", Nod
, Ent
);
9244 ("non-static expression not allowed"
9245 & " (RM 13.1(22))!", Nod
);
9249 when N_Integer_Literal
=>
9251 -- If this is a rewritten unchecked conversion, in a system
9252 -- where Address is an integer type, always use the base type
9253 -- for a literal value. This is user-friendly and prevents
9254 -- order-of-elaboration issues with instances of unchecked
9257 if Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
9258 Set_Etype
(Nod
, Base_Type
(Etype
(Nod
)));
9261 when N_Real_Literal |
9263 N_Character_Literal
=>
9267 Check_Expr_Constants
(Low_Bound
(Nod
));
9268 Check_Expr_Constants
(High_Bound
(Nod
));
9270 when N_Explicit_Dereference
=>
9271 Check_Expr_Constants
(Prefix
(Nod
));
9273 when N_Indexed_Component
=>
9274 Check_Expr_Constants
(Prefix
(Nod
));
9275 Check_List_Constants
(Expressions
(Nod
));
9278 Check_Expr_Constants
(Prefix
(Nod
));
9279 Check_Expr_Constants
(Discrete_Range
(Nod
));
9281 when N_Selected_Component
=>
9282 Check_Expr_Constants
(Prefix
(Nod
));
9284 when N_Attribute_Reference
=>
9285 if Nam_In
(Attribute_Name
(Nod
), Name_Address
,
9287 Name_Unchecked_Access
,
9288 Name_Unrestricted_Access
)
9290 Check_At_Constant_Address
(Prefix
(Nod
));
9293 Check_Expr_Constants
(Prefix
(Nod
));
9294 Check_List_Constants
(Expressions
(Nod
));
9298 Check_List_Constants
(Component_Associations
(Nod
));
9299 Check_List_Constants
(Expressions
(Nod
));
9301 when N_Component_Association
=>
9302 Check_Expr_Constants
(Expression
(Nod
));
9304 when N_Extension_Aggregate
=>
9305 Check_Expr_Constants
(Ancestor_Part
(Nod
));
9306 Check_List_Constants
(Component_Associations
(Nod
));
9307 Check_List_Constants
(Expressions
(Nod
));
9312 when N_Binary_Op | N_Short_Circuit | N_Membership_Test
=>
9313 Check_Expr_Constants
(Left_Opnd
(Nod
));
9314 Check_Expr_Constants
(Right_Opnd
(Nod
));
9317 Check_Expr_Constants
(Right_Opnd
(Nod
));
9319 when N_Type_Conversion |
9320 N_Qualified_Expression |
9322 N_Unchecked_Type_Conversion
=>
9323 Check_Expr_Constants
(Expression
(Nod
));
9325 when N_Function_Call
=>
9326 if not Is_Pure
(Entity
(Name
(Nod
))) then
9328 ("invalid address clause for initialized object &!",
9332 ("\function & is not pure (RM 13.1(22))!",
9333 Nod
, Entity
(Name
(Nod
)));
9336 Check_List_Constants
(Parameter_Associations
(Nod
));
9339 when N_Parameter_Association
=>
9340 Check_Expr_Constants
(Explicit_Actual_Parameter
(Nod
));
9344 ("invalid address clause for initialized object &!",
9347 ("\must be constant defined before& (RM 13.1(22))!",
9350 end Check_Expr_Constants
;
9352 --------------------------
9353 -- Check_List_Constants --
9354 --------------------------
9356 procedure Check_List_Constants
(Lst
: List_Id
) is
9360 if Present
(Lst
) then
9361 Nod1
:= First
(Lst
);
9362 while Present
(Nod1
) loop
9363 Check_Expr_Constants
(Nod1
);
9367 end Check_List_Constants
;
9369 -- Start of processing for Check_Constant_Address_Clause
9372 -- If rep_clauses are to be ignored, no need for legality checks. In
9373 -- particular, no need to pester user about rep clauses that violate the
9374 -- rule on constant addresses, given that these clauses will be removed
9375 -- by Freeze before they reach the back end. Similarly in CodePeer mode,
9376 -- we want to relax these checks.
9378 if not Ignore_Rep_Clauses
and not CodePeer_Mode
then
9379 Check_Expr_Constants
(Expr
);
9381 end Check_Constant_Address_Clause
;
9383 ---------------------------
9384 -- Check_Pool_Size_Clash --
9385 ---------------------------
9387 procedure Check_Pool_Size_Clash
(Ent
: Entity_Id
; SP
, SS
: Node_Id
) is
9391 -- We need to find out which one came first. Note that in the case of
9392 -- aspects mixed with pragmas there are cases where the processing order
9393 -- is reversed, which is why we do the check here.
9395 if Sloc
(SP
) < Sloc
(SS
) then
9396 Error_Msg_Sloc
:= Sloc
(SP
);
9398 Error_Msg_NE
("Storage_Pool previously given for&#", Post
, Ent
);
9401 Error_Msg_Sloc
:= Sloc
(SS
);
9403 Error_Msg_NE
("Storage_Size previously given for&#", Post
, Ent
);
9407 ("\cannot have Storage_Size and Storage_Pool (RM 13.11(3))", Post
);
9408 end Check_Pool_Size_Clash
;
9410 ----------------------------------------
9411 -- Check_Record_Representation_Clause --
9412 ----------------------------------------
9414 procedure Check_Record_Representation_Clause
(N
: Node_Id
) is
9415 Loc
: constant Source_Ptr
:= Sloc
(N
);
9416 Ident
: constant Node_Id
:= Identifier
(N
);
9417 Rectype
: Entity_Id
;
9422 Hbit
: Uint
:= Uint_0
;
9426 Max_Bit_So_Far
: Uint
;
9427 -- Records the maximum bit position so far. If all field positions
9428 -- are monotonically increasing, then we can skip the circuit for
9429 -- checking for overlap, since no overlap is possible.
9431 Tagged_Parent
: Entity_Id
:= Empty
;
9432 -- This is set in the case of a derived tagged type for which we have
9433 -- Is_Fully_Repped_Tagged_Type True (indicating that all components are
9434 -- positioned by record representation clauses). In this case we must
9435 -- check for overlap between components of this tagged type, and the
9436 -- components of its parent. Tagged_Parent will point to this parent
9437 -- type. For all other cases Tagged_Parent is left set to Empty.
9439 Parent_Last_Bit
: Uint
;
9440 -- Relevant only if Tagged_Parent is set, Parent_Last_Bit indicates the
9441 -- last bit position for any field in the parent type. We only need to
9442 -- check overlap for fields starting below this point.
9444 Overlap_Check_Required
: Boolean;
9445 -- Used to keep track of whether or not an overlap check is required
9447 Overlap_Detected
: Boolean := False;
9448 -- Set True if an overlap is detected
9450 Ccount
: Natural := 0;
9451 -- Number of component clauses in record rep clause
9453 procedure Check_Component_Overlap
(C1_Ent
, C2_Ent
: Entity_Id
);
9454 -- Given two entities for record components or discriminants, checks
9455 -- if they have overlapping component clauses and issues errors if so.
9457 procedure Find_Component
;
9458 -- Finds component entity corresponding to current component clause (in
9459 -- CC), and sets Comp to the entity, and Fbit/Lbit to the zero origin
9460 -- start/stop bits for the field. If there is no matching component or
9461 -- if the matching component does not have a component clause, then
9462 -- that's an error and Comp is set to Empty, but no error message is
9463 -- issued, since the message was already given. Comp is also set to
9464 -- Empty if the current "component clause" is in fact a pragma.
9466 -----------------------------
9467 -- Check_Component_Overlap --
9468 -----------------------------
9470 procedure Check_Component_Overlap
(C1_Ent
, C2_Ent
: Entity_Id
) is
9471 CC1
: constant Node_Id
:= Component_Clause
(C1_Ent
);
9472 CC2
: constant Node_Id
:= Component_Clause
(C2_Ent
);
9475 if Present
(CC1
) and then Present
(CC2
) then
9477 -- Exclude odd case where we have two tag components in the same
9478 -- record, both at location zero. This seems a bit strange, but
9479 -- it seems to happen in some circumstances, perhaps on an error.
9481 if Nam_In
(Chars
(C1_Ent
), Name_uTag
, Name_uTag
) then
9485 -- Here we check if the two fields overlap
9488 S1
: constant Uint
:= Component_Bit_Offset
(C1_Ent
);
9489 S2
: constant Uint
:= Component_Bit_Offset
(C2_Ent
);
9490 E1
: constant Uint
:= S1
+ Esize
(C1_Ent
);
9491 E2
: constant Uint
:= S2
+ Esize
(C2_Ent
);
9494 if E2
<= S1
or else E1
<= S2
then
9497 Error_Msg_Node_2
:= Component_Name
(CC2
);
9498 Error_Msg_Sloc
:= Sloc
(Error_Msg_Node_2
);
9499 Error_Msg_Node_1
:= Component_Name
(CC1
);
9501 ("component& overlaps & #", Component_Name
(CC1
));
9502 Overlap_Detected
:= True;
9506 end Check_Component_Overlap
;
9508 --------------------
9509 -- Find_Component --
9510 --------------------
9512 procedure Find_Component
is
9514 procedure Search_Component
(R
: Entity_Id
);
9515 -- Search components of R for a match. If found, Comp is set
9517 ----------------------
9518 -- Search_Component --
9519 ----------------------
9521 procedure Search_Component
(R
: Entity_Id
) is
9523 Comp
:= First_Component_Or_Discriminant
(R
);
9524 while Present
(Comp
) loop
9526 -- Ignore error of attribute name for component name (we
9527 -- already gave an error message for this, so no need to
9530 if Nkind
(Component_Name
(CC
)) = N_Attribute_Reference
then
9533 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
9536 Next_Component_Or_Discriminant
(Comp
);
9538 end Search_Component
;
9540 -- Start of processing for Find_Component
9543 -- Return with Comp set to Empty if we have a pragma
9545 if Nkind
(CC
) = N_Pragma
then
9550 -- Search current record for matching component
9552 Search_Component
(Rectype
);
9554 -- If not found, maybe component of base type discriminant that is
9555 -- absent from statically constrained first subtype.
9558 Search_Component
(Base_Type
(Rectype
));
9561 -- If no component, or the component does not reference the component
9562 -- clause in question, then there was some previous error for which
9563 -- we already gave a message, so just return with Comp Empty.
9565 if No
(Comp
) or else Component_Clause
(Comp
) /= CC
then
9566 Check_Error_Detected
;
9569 -- Normal case where we have a component clause
9572 Fbit
:= Component_Bit_Offset
(Comp
);
9573 Lbit
:= Fbit
+ Esize
(Comp
) - 1;
9577 -- Start of processing for Check_Record_Representation_Clause
9581 Rectype
:= Entity
(Ident
);
9583 if Rectype
= Any_Type
then
9586 Rectype
:= Underlying_Type
(Rectype
);
9589 -- See if we have a fully repped derived tagged type
9592 PS
: constant Entity_Id
:= Parent_Subtype
(Rectype
);
9595 if Present
(PS
) and then Is_Fully_Repped_Tagged_Type
(PS
) then
9596 Tagged_Parent
:= PS
;
9598 -- Find maximum bit of any component of the parent type
9600 Parent_Last_Bit
:= UI_From_Int
(System_Address_Size
- 1);
9601 Pcomp
:= First_Entity
(Tagged_Parent
);
9602 while Present
(Pcomp
) loop
9603 if Ekind_In
(Pcomp
, E_Discriminant
, E_Component
) then
9604 if Component_Bit_Offset
(Pcomp
) /= No_Uint
9605 and then Known_Static_Esize
(Pcomp
)
9610 Component_Bit_Offset
(Pcomp
) + Esize
(Pcomp
) - 1);
9613 Next_Entity
(Pcomp
);
9619 -- All done if no component clauses
9621 CC
:= First
(Component_Clauses
(N
));
9627 -- If a tag is present, then create a component clause that places it
9628 -- at the start of the record (otherwise gigi may place it after other
9629 -- fields that have rep clauses).
9631 Fent
:= First_Entity
(Rectype
);
9633 if Nkind
(Fent
) = N_Defining_Identifier
9634 and then Chars
(Fent
) = Name_uTag
9636 Set_Component_Bit_Offset
(Fent
, Uint_0
);
9637 Set_Normalized_Position
(Fent
, Uint_0
);
9638 Set_Normalized_First_Bit
(Fent
, Uint_0
);
9639 Set_Normalized_Position_Max
(Fent
, Uint_0
);
9640 Init_Esize
(Fent
, System_Address_Size
);
9642 Set_Component_Clause
(Fent
,
9643 Make_Component_Clause
(Loc
,
9644 Component_Name
=> Make_Identifier
(Loc
, Name_uTag
),
9646 Position
=> Make_Integer_Literal
(Loc
, Uint_0
),
9647 First_Bit
=> Make_Integer_Literal
(Loc
, Uint_0
),
9649 Make_Integer_Literal
(Loc
,
9650 UI_From_Int
(System_Address_Size
))));
9652 Ccount
:= Ccount
+ 1;
9655 Max_Bit_So_Far
:= Uint_Minus_1
;
9656 Overlap_Check_Required
:= False;
9658 -- Process the component clauses
9660 while Present
(CC
) loop
9663 if Present
(Comp
) then
9664 Ccount
:= Ccount
+ 1;
9666 -- We need a full overlap check if record positions non-monotonic
9668 if Fbit
<= Max_Bit_So_Far
then
9669 Overlap_Check_Required
:= True;
9672 Max_Bit_So_Far
:= Lbit
;
9674 -- Check bit position out of range of specified size
9676 if Has_Size_Clause
(Rectype
)
9677 and then RM_Size
(Rectype
) <= Lbit
9680 ("bit number out of range of specified size",
9683 -- Check for overlap with tag component
9686 if Is_Tagged_Type
(Rectype
)
9687 and then Fbit
< System_Address_Size
9690 ("component overlaps tag field of&",
9691 Component_Name
(CC
), Rectype
);
9692 Overlap_Detected
:= True;
9700 -- Check parent overlap if component might overlap parent field
9702 if Present
(Tagged_Parent
) and then Fbit
<= Parent_Last_Bit
then
9703 Pcomp
:= First_Component_Or_Discriminant
(Tagged_Parent
);
9704 while Present
(Pcomp
) loop
9705 if not Is_Tag
(Pcomp
)
9706 and then Chars
(Pcomp
) /= Name_uParent
9708 Check_Component_Overlap
(Comp
, Pcomp
);
9711 Next_Component_Or_Discriminant
(Pcomp
);
9719 -- Now that we have processed all the component clauses, check for
9720 -- overlap. We have to leave this till last, since the components can
9721 -- appear in any arbitrary order in the representation clause.
9723 -- We do not need this check if all specified ranges were monotonic,
9724 -- as recorded by Overlap_Check_Required being False at this stage.
9726 -- This first section checks if there are any overlapping entries at
9727 -- all. It does this by sorting all entries and then seeing if there are
9728 -- any overlaps. If there are none, then that is decisive, but if there
9729 -- are overlaps, they may still be OK (they may result from fields in
9730 -- different variants).
9732 if Overlap_Check_Required
then
9733 Overlap_Check1
: declare
9735 OC_Fbit
: array (0 .. Ccount
) of Uint
;
9736 -- First-bit values for component clauses, the value is the offset
9737 -- of the first bit of the field from start of record. The zero
9738 -- entry is for use in sorting.
9740 OC_Lbit
: array (0 .. Ccount
) of Uint
;
9741 -- Last-bit values for component clauses, the value is the offset
9742 -- of the last bit of the field from start of record. The zero
9743 -- entry is for use in sorting.
9745 OC_Count
: Natural := 0;
9746 -- Count of entries in OC_Fbit and OC_Lbit
9748 function OC_Lt
(Op1
, Op2
: Natural) return Boolean;
9749 -- Compare routine for Sort
9751 procedure OC_Move
(From
: Natural; To
: Natural);
9752 -- Move routine for Sort
9754 package Sorting
is new GNAT
.Heap_Sort_G
(OC_Move
, OC_Lt
);
9760 function OC_Lt
(Op1
, Op2
: Natural) return Boolean is
9762 return OC_Fbit
(Op1
) < OC_Fbit
(Op2
);
9769 procedure OC_Move
(From
: Natural; To
: Natural) is
9771 OC_Fbit
(To
) := OC_Fbit
(From
);
9772 OC_Lbit
(To
) := OC_Lbit
(From
);
9775 -- Start of processing for Overlap_Check
9778 CC
:= First
(Component_Clauses
(N
));
9779 while Present
(CC
) loop
9781 -- Exclude component clause already marked in error
9783 if not Error_Posted
(CC
) then
9786 if Present
(Comp
) then
9787 OC_Count
:= OC_Count
+ 1;
9788 OC_Fbit
(OC_Count
) := Fbit
;
9789 OC_Lbit
(OC_Count
) := Lbit
;
9796 Sorting
.Sort
(OC_Count
);
9798 Overlap_Check_Required
:= False;
9799 for J
in 1 .. OC_Count
- 1 loop
9800 if OC_Lbit
(J
) >= OC_Fbit
(J
+ 1) then
9801 Overlap_Check_Required
:= True;
9808 -- If Overlap_Check_Required is still True, then we have to do the full
9809 -- scale overlap check, since we have at least two fields that do
9810 -- overlap, and we need to know if that is OK since they are in
9811 -- different variant, or whether we have a definite problem.
9813 if Overlap_Check_Required
then
9814 Overlap_Check2
: declare
9815 C1_Ent
, C2_Ent
: Entity_Id
;
9816 -- Entities of components being checked for overlap
9819 -- Component_List node whose Component_Items are being checked
9822 -- Component declaration for component being checked
9825 C1_Ent
:= First_Entity
(Base_Type
(Rectype
));
9827 -- Loop through all components in record. For each component check
9828 -- for overlap with any of the preceding elements on the component
9829 -- list containing the component and also, if the component is in
9830 -- a variant, check against components outside the case structure.
9831 -- This latter test is repeated recursively up the variant tree.
9833 Main_Component_Loop
: while Present
(C1_Ent
) loop
9834 if not Ekind_In
(C1_Ent
, E_Component
, E_Discriminant
) then
9835 goto Continue_Main_Component_Loop
;
9838 -- Skip overlap check if entity has no declaration node. This
9839 -- happens with discriminants in constrained derived types.
9840 -- Possibly we are missing some checks as a result, but that
9841 -- does not seem terribly serious.
9843 if No
(Declaration_Node
(C1_Ent
)) then
9844 goto Continue_Main_Component_Loop
;
9847 Clist
:= Parent
(List_Containing
(Declaration_Node
(C1_Ent
)));
9849 -- Loop through component lists that need checking. Check the
9850 -- current component list and all lists in variants above us.
9852 Component_List_Loop
: loop
9854 -- If derived type definition, go to full declaration
9855 -- If at outer level, check discriminants if there are any.
9857 if Nkind
(Clist
) = N_Derived_Type_Definition
then
9858 Clist
:= Parent
(Clist
);
9861 -- Outer level of record definition, check discriminants
9863 if Nkind_In
(Clist
, N_Full_Type_Declaration
,
9864 N_Private_Type_Declaration
)
9866 if Has_Discriminants
(Defining_Identifier
(Clist
)) then
9868 First_Discriminant
(Defining_Identifier
(Clist
));
9869 while Present
(C2_Ent
) loop
9870 exit when C1_Ent
= C2_Ent
;
9871 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
9872 Next_Discriminant
(C2_Ent
);
9876 -- Record extension case
9878 elsif Nkind
(Clist
) = N_Derived_Type_Definition
then
9881 -- Otherwise check one component list
9884 Citem
:= First
(Component_Items
(Clist
));
9885 while Present
(Citem
) loop
9886 if Nkind
(Citem
) = N_Component_Declaration
then
9887 C2_Ent
:= Defining_Identifier
(Citem
);
9888 exit when C1_Ent
= C2_Ent
;
9889 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
9896 -- Check for variants above us (the parent of the Clist can
9897 -- be a variant, in which case its parent is a variant part,
9898 -- and the parent of the variant part is a component list
9899 -- whose components must all be checked against the current
9900 -- component for overlap).
9902 if Nkind
(Parent
(Clist
)) = N_Variant
then
9903 Clist
:= Parent
(Parent
(Parent
(Clist
)));
9905 -- Check for possible discriminant part in record, this
9906 -- is treated essentially as another level in the
9907 -- recursion. For this case the parent of the component
9908 -- list is the record definition, and its parent is the
9909 -- full type declaration containing the discriminant
9912 elsif Nkind
(Parent
(Clist
)) = N_Record_Definition
then
9913 Clist
:= Parent
(Parent
((Clist
)));
9915 -- If neither of these two cases, we are at the top of
9919 exit Component_List_Loop
;
9921 end loop Component_List_Loop
;
9923 <<Continue_Main_Component_Loop
>>
9924 Next_Entity
(C1_Ent
);
9926 end loop Main_Component_Loop
;
9930 -- The following circuit deals with warning on record holes (gaps). We
9931 -- skip this check if overlap was detected, since it makes sense for the
9932 -- programmer to fix this illegality before worrying about warnings.
9934 if not Overlap_Detected
and Warn_On_Record_Holes
then
9935 Record_Hole_Check
: declare
9936 Decl
: constant Node_Id
:= Declaration_Node
(Base_Type
(Rectype
));
9937 -- Full declaration of record type
9939 procedure Check_Component_List
9943 -- Check component list CL for holes. The starting bit should be
9944 -- Sbit. which is zero for the main record component list and set
9945 -- appropriately for recursive calls for variants. DS is set to
9946 -- a list of discriminant specifications to be included in the
9947 -- consideration of components. It is No_List if none to consider.
9949 --------------------------
9950 -- Check_Component_List --
9951 --------------------------
9953 procedure Check_Component_List
9961 Compl
:= Integer (List_Length
(Component_Items
(CL
)));
9963 if DS
/= No_List
then
9964 Compl
:= Compl
+ Integer (List_Length
(DS
));
9968 Comps
: array (Natural range 0 .. Compl
) of Entity_Id
;
9969 -- Gather components (zero entry is for sort routine)
9971 Ncomps
: Natural := 0;
9972 -- Number of entries stored in Comps (starting at Comps (1))
9975 -- One component item or discriminant specification
9978 -- Starting bit for next component
9986 function Lt
(Op1
, Op2
: Natural) return Boolean;
9987 -- Compare routine for Sort
9989 procedure Move
(From
: Natural; To
: Natural);
9990 -- Move routine for Sort
9992 package Sorting
is new GNAT
.Heap_Sort_G
(Move
, Lt
);
9998 function Lt
(Op1
, Op2
: Natural) return Boolean is
10000 return Component_Bit_Offset
(Comps
(Op1
))
10002 Component_Bit_Offset
(Comps
(Op2
));
10009 procedure Move
(From
: Natural; To
: Natural) is
10011 Comps
(To
) := Comps
(From
);
10015 -- Gather discriminants into Comp
10017 if DS
/= No_List
then
10018 Citem
:= First
(DS
);
10019 while Present
(Citem
) loop
10020 if Nkind
(Citem
) = N_Discriminant_Specification
then
10022 Ent
: constant Entity_Id
:=
10023 Defining_Identifier
(Citem
);
10025 if Ekind
(Ent
) = E_Discriminant
then
10026 Ncomps
:= Ncomps
+ 1;
10027 Comps
(Ncomps
) := Ent
;
10036 -- Gather component entities into Comp
10038 Citem
:= First
(Component_Items
(CL
));
10039 while Present
(Citem
) loop
10040 if Nkind
(Citem
) = N_Component_Declaration
then
10041 Ncomps
:= Ncomps
+ 1;
10042 Comps
(Ncomps
) := Defining_Identifier
(Citem
);
10048 -- Now sort the component entities based on the first bit.
10049 -- Note we already know there are no overlapping components.
10051 Sorting
.Sort
(Ncomps
);
10053 -- Loop through entries checking for holes
10056 for J
in 1 .. Ncomps
loop
10058 Error_Msg_Uint_1
:= Component_Bit_Offset
(CEnt
) - Nbit
;
10060 if Error_Msg_Uint_1
> 0 then
10062 ("?H?^-bit gap before component&",
10063 Component_Name
(Component_Clause
(CEnt
)), CEnt
);
10066 Nbit
:= Component_Bit_Offset
(CEnt
) + Esize
(CEnt
);
10069 -- Process variant parts recursively if present
10071 if Present
(Variant_Part
(CL
)) then
10072 Variant
:= First
(Variants
(Variant_Part
(CL
)));
10073 while Present
(Variant
) loop
10074 Check_Component_List
10075 (Component_List
(Variant
), Nbit
, No_List
);
10080 end Check_Component_List
;
10082 -- Start of processing for Record_Hole_Check
10089 if Is_Tagged_Type
(Rectype
) then
10090 Sbit
:= UI_From_Int
(System_Address_Size
);
10095 if Nkind
(Decl
) = N_Full_Type_Declaration
10096 and then Nkind
(Type_Definition
(Decl
)) = N_Record_Definition
10098 Check_Component_List
10099 (Component_List
(Type_Definition
(Decl
)),
10101 Discriminant_Specifications
(Decl
));
10104 end Record_Hole_Check
;
10107 -- For records that have component clauses for all components, and whose
10108 -- size is less than or equal to 32, we need to know the size in the
10109 -- front end to activate possible packed array processing where the
10110 -- component type is a record.
10112 -- At this stage Hbit + 1 represents the first unused bit from all the
10113 -- component clauses processed, so if the component clauses are
10114 -- complete, then this is the length of the record.
10116 -- For records longer than System.Storage_Unit, and for those where not
10117 -- all components have component clauses, the back end determines the
10118 -- length (it may for example be appropriate to round up the size
10119 -- to some convenient boundary, based on alignment considerations, etc).
10121 if Unknown_RM_Size
(Rectype
) and then Hbit
+ 1 <= 32 then
10123 -- Nothing to do if at least one component has no component clause
10125 Comp
:= First_Component_Or_Discriminant
(Rectype
);
10126 while Present
(Comp
) loop
10127 exit when No
(Component_Clause
(Comp
));
10128 Next_Component_Or_Discriminant
(Comp
);
10131 -- If we fall out of loop, all components have component clauses
10132 -- and so we can set the size to the maximum value.
10135 Set_RM_Size
(Rectype
, Hbit
+ 1);
10138 end Check_Record_Representation_Clause
;
10144 procedure Check_Size
10148 Biased
: out Boolean)
10150 UT
: constant Entity_Id
:= Underlying_Type
(T
);
10156 -- Reject patently improper size values.
10158 if Is_Elementary_Type
(T
)
10159 and then Siz
> UI_From_Int
(Int
'Last)
10161 Error_Msg_N
("Size value too large for elementary type", N
);
10163 if Nkind
(Original_Node
(N
)) = N_Op_Expon
then
10165 ("\maybe '* was meant, rather than '*'*", Original_Node
(N
));
10169 -- Dismiss generic types
10171 if Is_Generic_Type
(T
)
10173 Is_Generic_Type
(UT
)
10175 Is_Generic_Type
(Root_Type
(UT
))
10179 -- Guard against previous errors
10181 elsif No
(UT
) or else UT
= Any_Type
then
10182 Check_Error_Detected
;
10185 -- Check case of bit packed array
10187 elsif Is_Array_Type
(UT
)
10188 and then Known_Static_Component_Size
(UT
)
10189 and then Is_Bit_Packed_Array
(UT
)
10197 Asiz
:= Component_Size
(UT
);
10198 Indx
:= First_Index
(UT
);
10200 Ityp
:= Etype
(Indx
);
10202 -- If non-static bound, then we are not in the business of
10203 -- trying to check the length, and indeed an error will be
10204 -- issued elsewhere, since sizes of non-static array types
10205 -- cannot be set implicitly or explicitly.
10207 if not Is_OK_Static_Subtype
(Ityp
) then
10211 -- Otherwise accumulate next dimension
10213 Asiz
:= Asiz
* (Expr_Value
(Type_High_Bound
(Ityp
)) -
10214 Expr_Value
(Type_Low_Bound
(Ityp
)) +
10218 exit when No
(Indx
);
10221 if Asiz
<= Siz
then
10225 Error_Msg_Uint_1
:= Asiz
;
10227 ("size for& too small, minimum allowed is ^", N
, T
);
10228 Set_Esize
(T
, Asiz
);
10229 Set_RM_Size
(T
, Asiz
);
10233 -- All other composite types are ignored
10235 elsif Is_Composite_Type
(UT
) then
10238 -- For fixed-point types, don't check minimum if type is not frozen,
10239 -- since we don't know all the characteristics of the type that can
10240 -- affect the size (e.g. a specified small) till freeze time.
10242 elsif Is_Fixed_Point_Type
(UT
)
10243 and then not Is_Frozen
(UT
)
10247 -- Cases for which a minimum check is required
10250 -- Ignore if specified size is correct for the type
10252 if Known_Esize
(UT
) and then Siz
= Esize
(UT
) then
10256 -- Otherwise get minimum size
10258 M
:= UI_From_Int
(Minimum_Size
(UT
));
10262 -- Size is less than minimum size, but one possibility remains
10263 -- that we can manage with the new size if we bias the type.
10265 M
:= UI_From_Int
(Minimum_Size
(UT
, Biased
=> True));
10268 Error_Msg_Uint_1
:= M
;
10270 ("size for& too small, minimum allowed is ^", N
, T
);
10272 Set_RM_Size
(T
, M
);
10280 --------------------------
10281 -- Freeze_Entity_Checks --
10282 --------------------------
10284 procedure Freeze_Entity_Checks
(N
: Node_Id
) is
10285 procedure Hide_Non_Overridden_Subprograms
(Typ
: Entity_Id
);
10286 -- Inspect the primitive operations of type Typ and hide all pairs of
10287 -- implicitly declared non-overridden non-fully conformant homographs
10288 -- (Ada RM 8.3 12.3/2).
10290 -------------------------------------
10291 -- Hide_Non_Overridden_Subprograms --
10292 -------------------------------------
10294 procedure Hide_Non_Overridden_Subprograms
(Typ
: Entity_Id
) is
10295 procedure Hide_Matching_Homographs
10296 (Subp_Id
: Entity_Id
;
10297 Start_Elmt
: Elmt_Id
);
10298 -- Inspect a list of primitive operations starting with Start_Elmt
10299 -- and find matching implicitly declared non-overridden non-fully
10300 -- conformant homographs of Subp_Id. If found, all matches along
10301 -- with Subp_Id are hidden from all visibility.
10303 function Is_Non_Overridden_Or_Null_Procedure
10304 (Subp_Id
: Entity_Id
) return Boolean;
10305 -- Determine whether subprogram Subp_Id is implicitly declared non-
10306 -- overridden subprogram or an implicitly declared null procedure.
10308 ------------------------------
10309 -- Hide_Matching_Homographs --
10310 ------------------------------
10312 procedure Hide_Matching_Homographs
10313 (Subp_Id
: Entity_Id
;
10314 Start_Elmt
: Elmt_Id
)
10317 Prim_Elmt
: Elmt_Id
;
10320 Prim_Elmt
:= Start_Elmt
;
10321 while Present
(Prim_Elmt
) loop
10322 Prim
:= Node
(Prim_Elmt
);
10324 -- The current primitive is implicitly declared non-overridden
10325 -- non-fully conformant homograph of Subp_Id. Both subprograms
10326 -- must be hidden from visibility.
10328 if Chars
(Prim
) = Chars
(Subp_Id
)
10329 and then Is_Non_Overridden_Or_Null_Procedure
(Prim
)
10330 and then not Fully_Conformant
(Prim
, Subp_Id
)
10332 Set_Is_Hidden_Non_Overridden_Subpgm
(Prim
);
10333 Set_Is_Immediately_Visible
(Prim
, False);
10334 Set_Is_Potentially_Use_Visible
(Prim
, False);
10336 Set_Is_Hidden_Non_Overridden_Subpgm
(Subp_Id
);
10337 Set_Is_Immediately_Visible
(Subp_Id
, False);
10338 Set_Is_Potentially_Use_Visible
(Subp_Id
, False);
10341 Next_Elmt
(Prim_Elmt
);
10343 end Hide_Matching_Homographs
;
10345 -----------------------------------------
10346 -- Is_Non_Overridden_Or_Null_Procedure --
10347 -----------------------------------------
10349 function Is_Non_Overridden_Or_Null_Procedure
10350 (Subp_Id
: Entity_Id
) return Boolean
10352 Alias_Id
: Entity_Id
;
10355 -- The subprogram is inherited (implicitly declared), it does not
10356 -- override and does not cover a primitive of an interface.
10358 if Ekind_In
(Subp_Id
, E_Function
, E_Procedure
)
10359 and then Present
(Alias
(Subp_Id
))
10360 and then No
(Interface_Alias
(Subp_Id
))
10361 and then No
(Overridden_Operation
(Subp_Id
))
10363 Alias_Id
:= Alias
(Subp_Id
);
10365 if Requires_Overriding
(Alias_Id
) then
10368 elsif Nkind
(Parent
(Alias_Id
)) = N_Procedure_Specification
10369 and then Null_Present
(Parent
(Alias_Id
))
10376 end Is_Non_Overridden_Or_Null_Procedure
;
10380 Prim_Ops
: constant Elist_Id
:= Direct_Primitive_Operations
(Typ
);
10382 Prim_Elmt
: Elmt_Id
;
10384 -- Start of processing for Hide_Non_Overridden_Subprograms
10387 -- Inspect the list of primitives looking for non-overridden
10390 if Present
(Prim_Ops
) then
10391 Prim_Elmt
:= First_Elmt
(Prim_Ops
);
10392 while Present
(Prim_Elmt
) loop
10393 Prim
:= Node
(Prim_Elmt
);
10394 Next_Elmt
(Prim_Elmt
);
10396 if Is_Non_Overridden_Or_Null_Procedure
(Prim
) then
10397 Hide_Matching_Homographs
10399 Start_Elmt
=> Prim_Elmt
);
10403 end Hide_Non_Overridden_Subprograms
;
10405 ---------------------
10406 -- Local variables --
10407 ---------------------
10409 E
: constant Entity_Id
:= Entity
(N
);
10411 Non_Generic_Case
: constant Boolean := Nkind
(N
) = N_Freeze_Entity
;
10412 -- True in non-generic case. Some of the processing here is skipped
10413 -- for the generic case since it is not needed. Basically in the
10414 -- generic case, we only need to do stuff that might generate error
10415 -- messages or warnings.
10417 -- Start of processing for Freeze_Entity_Checks
10420 -- Remember that we are processing a freezing entity. Required to
10421 -- ensure correct decoration of internal entities associated with
10422 -- interfaces (see New_Overloaded_Entity).
10424 Inside_Freezing_Actions
:= Inside_Freezing_Actions
+ 1;
10426 -- For tagged types covering interfaces add internal entities that link
10427 -- the primitives of the interfaces with the primitives that cover them.
10428 -- Note: These entities were originally generated only when generating
10429 -- code because their main purpose was to provide support to initialize
10430 -- the secondary dispatch tables. They are now generated also when
10431 -- compiling with no code generation to provide ASIS the relationship
10432 -- between interface primitives and tagged type primitives. They are
10433 -- also used to locate primitives covering interfaces when processing
10434 -- generics (see Derive_Subprograms).
10436 -- This is not needed in the generic case
10438 if Ada_Version
>= Ada_2005
10439 and then Non_Generic_Case
10440 and then Ekind
(E
) = E_Record_Type
10441 and then Is_Tagged_Type
(E
)
10442 and then not Is_Interface
(E
)
10443 and then Has_Interfaces
(E
)
10445 -- This would be a good common place to call the routine that checks
10446 -- overriding of interface primitives (and thus factorize calls to
10447 -- Check_Abstract_Overriding located at different contexts in the
10448 -- compiler). However, this is not possible because it causes
10449 -- spurious errors in case of late overriding.
10451 Add_Internal_Interface_Entities
(E
);
10454 -- After all forms of overriding have been resolved, a tagged type may
10455 -- be left with a set of implicitly declared and possibly erroneous
10456 -- abstract subprograms, null procedures and subprograms that require
10457 -- overriding. If this set contains fully conformat homographs, then one
10458 -- is chosen arbitrarily (already done during resolution), otherwise all
10459 -- remaining non-fully conformant homographs are hidden from visibility
10460 -- (Ada RM 8.3 12.3/2).
10462 if Is_Tagged_Type
(E
) then
10463 Hide_Non_Overridden_Subprograms
(E
);
10468 if Ekind
(E
) = E_Record_Type
10469 and then Is_CPP_Class
(E
)
10470 and then Is_Tagged_Type
(E
)
10471 and then Tagged_Type_Expansion
10473 if CPP_Num_Prims
(E
) = 0 then
10475 -- If the CPP type has user defined components then it must import
10476 -- primitives from C++. This is required because if the C++ class
10477 -- has no primitives then the C++ compiler does not added the _tag
10478 -- component to the type.
10480 if First_Entity
(E
) /= Last_Entity
(E
) then
10482 ("'C'P'P type must import at least one primitive from C++??",
10487 -- Check that all its primitives are abstract or imported from C++.
10488 -- Check also availability of the C++ constructor.
10491 Has_Constructors
: constant Boolean := Has_CPP_Constructors
(E
);
10493 Error_Reported
: Boolean := False;
10497 Elmt
:= First_Elmt
(Primitive_Operations
(E
));
10498 while Present
(Elmt
) loop
10499 Prim
:= Node
(Elmt
);
10501 if Comes_From_Source
(Prim
) then
10502 if Is_Abstract_Subprogram
(Prim
) then
10505 elsif not Is_Imported
(Prim
)
10506 or else Convention
(Prim
) /= Convention_CPP
10509 ("primitives of 'C'P'P types must be imported from C++ "
10510 & "or abstract??", Prim
);
10512 elsif not Has_Constructors
10513 and then not Error_Reported
10515 Error_Msg_Name_1
:= Chars
(E
);
10517 ("??'C'P'P constructor required for type %", Prim
);
10518 Error_Reported
:= True;
10527 -- Check Ada derivation of CPP type
10529 if Expander_Active
-- why? losing errors in -gnatc mode???
10530 and then Present
(Etype
(E
)) -- defend against errors
10531 and then Tagged_Type_Expansion
10532 and then Ekind
(E
) = E_Record_Type
10533 and then Etype
(E
) /= E
10534 and then Is_CPP_Class
(Etype
(E
))
10535 and then CPP_Num_Prims
(Etype
(E
)) > 0
10536 and then not Is_CPP_Class
(E
)
10537 and then not Has_CPP_Constructors
(Etype
(E
))
10539 -- If the parent has C++ primitives but it has no constructor then
10540 -- check that all the primitives are overridden in this derivation;
10541 -- otherwise the constructor of the parent is needed to build the
10549 Elmt
:= First_Elmt
(Primitive_Operations
(E
));
10550 while Present
(Elmt
) loop
10551 Prim
:= Node
(Elmt
);
10553 if not Is_Abstract_Subprogram
(Prim
)
10554 and then No
(Interface_Alias
(Prim
))
10555 and then Find_Dispatching_Type
(Ultimate_Alias
(Prim
)) /= E
10557 Error_Msg_Name_1
:= Chars
(Etype
(E
));
10559 ("'C'P'P constructor required for parent type %", E
);
10568 Inside_Freezing_Actions
:= Inside_Freezing_Actions
- 1;
10570 -- If we have a type with predicates, build predicate function. This
10571 -- is not needed in the generic case, and is not needed within TSS
10572 -- subprograms and other predefined primitives.
10574 if Non_Generic_Case
10575 and then Is_Type
(E
)
10576 and then Has_Predicates
(E
)
10577 and then not Within_Internal_Subprogram
10579 Build_Predicate_Functions
(E
, N
);
10582 -- If type has delayed aspects, this is where we do the preanalysis at
10583 -- the freeze point, as part of the consistent visibility check. Note
10584 -- that this must be done after calling Build_Predicate_Functions or
10585 -- Build_Invariant_Procedure since these subprograms fix occurrences of
10586 -- the subtype name in the saved expression so that they will not cause
10587 -- trouble in the preanalysis.
10589 -- This is also not needed in the generic case
10591 if Non_Generic_Case
10592 and then Has_Delayed_Aspects
(E
)
10593 and then Scope
(E
) = Current_Scope
10595 -- Retrieve the visibility to the discriminants in order to properly
10596 -- analyze the aspects.
10598 Push_Scope_And_Install_Discriminants
(E
);
10604 -- Look for aspect specification entries for this entity
10606 Ritem
:= First_Rep_Item
(E
);
10607 while Present
(Ritem
) loop
10608 if Nkind
(Ritem
) = N_Aspect_Specification
10609 and then Entity
(Ritem
) = E
10610 and then Is_Delayed_Aspect
(Ritem
)
10612 Check_Aspect_At_Freeze_Point
(Ritem
);
10615 Next_Rep_Item
(Ritem
);
10619 Uninstall_Discriminants_And_Pop_Scope
(E
);
10622 -- For a record type, deal with variant parts. This has to be delayed
10623 -- to this point, because of the issue of statically predicated
10624 -- subtypes, which we have to ensure are frozen before checking
10625 -- choices, since we need to have the static choice list set.
10627 if Is_Record_Type
(E
) then
10628 Check_Variant_Part
: declare
10629 D
: constant Node_Id
:= Declaration_Node
(E
);
10634 Others_Present
: Boolean;
10635 pragma Warnings
(Off
, Others_Present
);
10636 -- Indicates others present, not used in this case
10638 procedure Non_Static_Choice_Error
(Choice
: Node_Id
);
10639 -- Error routine invoked by the generic instantiation below when
10640 -- the variant part has a non static choice.
10642 procedure Process_Declarations
(Variant
: Node_Id
);
10643 -- Processes declarations associated with a variant. We analyzed
10644 -- the declarations earlier (in Sem_Ch3.Analyze_Variant_Part),
10645 -- but we still need the recursive call to Check_Choices for any
10646 -- nested variant to get its choices properly processed. This is
10647 -- also where we expand out the choices if expansion is active.
10649 package Variant_Choices_Processing
is new
10650 Generic_Check_Choices
10651 (Process_Empty_Choice
=> No_OP
,
10652 Process_Non_Static_Choice
=> Non_Static_Choice_Error
,
10653 Process_Associated_Node
=> Process_Declarations
);
10654 use Variant_Choices_Processing
;
10656 -----------------------------
10657 -- Non_Static_Choice_Error --
10658 -----------------------------
10660 procedure Non_Static_Choice_Error
(Choice
: Node_Id
) is
10662 Flag_Non_Static_Expr
10663 ("choice given in variant part is not static!", Choice
);
10664 end Non_Static_Choice_Error
;
10666 --------------------------
10667 -- Process_Declarations --
10668 --------------------------
10670 procedure Process_Declarations
(Variant
: Node_Id
) is
10671 CL
: constant Node_Id
:= Component_List
(Variant
);
10675 -- Check for static predicate present in this variant
10677 if Has_SP_Choice
(Variant
) then
10679 -- Here we expand. You might expect to find this call in
10680 -- Expand_N_Variant_Part, but that is called when we first
10681 -- see the variant part, and we cannot do this expansion
10682 -- earlier than the freeze point, since for statically
10683 -- predicated subtypes, the predicate is not known till
10684 -- the freeze point.
10686 -- Furthermore, we do this expansion even if the expander
10687 -- is not active, because other semantic processing, e.g.
10688 -- for aggregates, requires the expanded list of choices.
10690 -- If the expander is not active, then we can't just clobber
10691 -- the list since it would invalidate the ASIS -gnatct tree.
10692 -- So we have to rewrite the variant part with a Rewrite
10693 -- call that replaces it with a copy and clobber the copy.
10695 if not Expander_Active
then
10697 NewV
: constant Node_Id
:= New_Copy
(Variant
);
10699 Set_Discrete_Choices
10700 (NewV
, New_Copy_List
(Discrete_Choices
(Variant
)));
10701 Rewrite
(Variant
, NewV
);
10705 Expand_Static_Predicates_In_Choices
(Variant
);
10708 -- We don't need to worry about the declarations in the variant
10709 -- (since they were analyzed by Analyze_Choices when we first
10710 -- encountered the variant), but we do need to take care of
10711 -- expansion of any nested variants.
10713 if not Null_Present
(CL
) then
10714 VP
:= Variant_Part
(CL
);
10716 if Present
(VP
) then
10718 (VP
, Variants
(VP
), Etype
(Name
(VP
)), Others_Present
);
10721 end Process_Declarations
;
10723 -- Start of processing for Check_Variant_Part
10726 -- Find component list
10730 if Nkind
(D
) = N_Full_Type_Declaration
then
10731 T
:= Type_Definition
(D
);
10733 if Nkind
(T
) = N_Record_Definition
then
10734 C
:= Component_List
(T
);
10736 elsif Nkind
(T
) = N_Derived_Type_Definition
10737 and then Present
(Record_Extension_Part
(T
))
10739 C
:= Component_List
(Record_Extension_Part
(T
));
10743 -- Case of variant part present
10745 if Present
(C
) and then Present
(Variant_Part
(C
)) then
10746 VP
:= Variant_Part
(C
);
10751 (VP
, Variants
(VP
), Etype
(Name
(VP
)), Others_Present
);
10753 -- If the last variant does not contain the Others choice,
10754 -- replace it with an N_Others_Choice node since Gigi always
10755 -- wants an Others. Note that we do not bother to call Analyze
10756 -- on the modified variant part, since its only effect would be
10757 -- to compute the Others_Discrete_Choices node laboriously, and
10758 -- of course we already know the list of choices corresponding
10759 -- to the others choice (it's the list we're replacing).
10761 -- We only want to do this if the expander is active, since
10762 -- we do not want to clobber the ASIS tree.
10764 if Expander_Active
then
10766 Last_Var
: constant Node_Id
:=
10767 Last_Non_Pragma
(Variants
(VP
));
10769 Others_Node
: Node_Id
;
10772 if Nkind
(First
(Discrete_Choices
(Last_Var
))) /=
10775 Others_Node
:= Make_Others_Choice
(Sloc
(Last_Var
));
10776 Set_Others_Discrete_Choices
10777 (Others_Node
, Discrete_Choices
(Last_Var
));
10778 Set_Discrete_Choices
10779 (Last_Var
, New_List
(Others_Node
));
10784 end Check_Variant_Part
;
10786 end Freeze_Entity_Checks
;
10788 -------------------------
10789 -- Get_Alignment_Value --
10790 -------------------------
10792 function Get_Alignment_Value
(Expr
: Node_Id
) return Uint
is
10793 Align
: constant Uint
:= Static_Integer
(Expr
);
10796 if Align
= No_Uint
then
10799 elsif Align
<= 0 then
10800 Error_Msg_N
("alignment value must be positive", Expr
);
10804 for J
in Int
range 0 .. 64 loop
10806 M
: constant Uint
:= Uint_2
** J
;
10809 exit when M
= Align
;
10813 ("alignment value must be power of 2", Expr
);
10821 end Get_Alignment_Value
;
10823 -------------------------------------
10824 -- Inherit_Aspects_At_Freeze_Point --
10825 -------------------------------------
10827 procedure Inherit_Aspects_At_Freeze_Point
(Typ
: Entity_Id
) is
10828 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
10829 (Rep_Item
: Node_Id
) return Boolean;
10830 -- This routine checks if Rep_Item is either a pragma or an aspect
10831 -- specification node whose correponding pragma (if any) is present in
10832 -- the Rep Item chain of the entity it has been specified to.
10834 --------------------------------------------------
10835 -- Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item --
10836 --------------------------------------------------
10838 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
10839 (Rep_Item
: Node_Id
) return Boolean
10843 Nkind
(Rep_Item
) = N_Pragma
10844 or else Present_In_Rep_Item
10845 (Entity
(Rep_Item
), Aspect_Rep_Item
(Rep_Item
));
10846 end Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
;
10848 -- Start of processing for Inherit_Aspects_At_Freeze_Point
10851 -- A representation item is either subtype-specific (Size and Alignment
10852 -- clauses) or type-related (all others). Subtype-specific aspects may
10853 -- differ for different subtypes of the same type (RM 13.1.8).
10855 -- A derived type inherits each type-related representation aspect of
10856 -- its parent type that was directly specified before the declaration of
10857 -- the derived type (RM 13.1.15).
10859 -- A derived subtype inherits each subtype-specific representation
10860 -- aspect of its parent subtype that was directly specified before the
10861 -- declaration of the derived type (RM 13.1.15).
10863 -- The general processing involves inheriting a representation aspect
10864 -- from a parent type whenever the first rep item (aspect specification,
10865 -- attribute definition clause, pragma) corresponding to the given
10866 -- representation aspect in the rep item chain of Typ, if any, isn't
10867 -- directly specified to Typ but to one of its parents.
10869 -- ??? Note that, for now, just a limited number of representation
10870 -- aspects have been inherited here so far. Many of them are
10871 -- still inherited in Sem_Ch3. This will be fixed soon. Here is
10872 -- a non- exhaustive list of aspects that likely also need to
10873 -- be moved to this routine: Alignment, Component_Alignment,
10874 -- Component_Size, Machine_Radix, Object_Size, Pack, Predicates,
10875 -- Preelaborable_Initialization, RM_Size and Small.
10877 -- In addition, Convention must be propagated from base type to subtype,
10878 -- because the subtype may have been declared on an incomplete view.
10880 if Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
then
10886 if not Has_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
, False)
10887 and then Has_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
)
10888 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
10889 (Get_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
))
10891 Set_Is_Ada_2005_Only
(Typ
);
10896 if not Has_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
, False)
10897 and then Has_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
)
10898 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
10899 (Get_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
))
10901 Set_Is_Ada_2012_Only
(Typ
);
10906 if not Has_Rep_Item
(Typ
, Name_Atomic
, Name_Shared
, False)
10907 and then Has_Rep_Pragma
(Typ
, Name_Atomic
, Name_Shared
)
10908 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
10909 (Get_Rep_Item
(Typ
, Name_Atomic
, Name_Shared
))
10911 Set_Is_Atomic
(Typ
);
10912 Set_Treat_As_Volatile
(Typ
);
10913 Set_Is_Volatile
(Typ
);
10918 if Is_Record_Type
(Typ
)
10919 and then Typ
/= Base_Type
(Typ
) and then Is_Frozen
(Base_Type
(Typ
))
10921 Set_Convention
(Typ
, Convention
(Base_Type
(Typ
)));
10924 -- Default_Component_Value
10926 -- Verify that there is no rep_item declared for the type, and there
10927 -- is one coming from an ancestor.
10929 if Is_Array_Type
(Typ
)
10930 and then Is_Base_Type
(Typ
)
10931 and then not Has_Rep_Item
(Typ
, Name_Default_Component_Value
, False)
10932 and then Has_Rep_Item
(Typ
, Name_Default_Component_Value
)
10934 Set_Default_Aspect_Component_Value
(Typ
,
10935 Default_Aspect_Component_Value
10936 (Entity
(Get_Rep_Item
(Typ
, Name_Default_Component_Value
))));
10941 if Is_Scalar_Type
(Typ
)
10942 and then Is_Base_Type
(Typ
)
10943 and then not Has_Rep_Item
(Typ
, Name_Default_Value
, False)
10944 and then Has_Rep_Item
(Typ
, Name_Default_Value
)
10946 Set_Has_Default_Aspect
(Typ
);
10947 Set_Default_Aspect_Value
(Typ
,
10948 Default_Aspect_Value
10949 (Entity
(Get_Rep_Item
(Typ
, Name_Default_Value
))));
10954 if not Has_Rep_Item
(Typ
, Name_Discard_Names
, False)
10955 and then Has_Rep_Item
(Typ
, Name_Discard_Names
)
10956 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
10957 (Get_Rep_Item
(Typ
, Name_Discard_Names
))
10959 Set_Discard_Names
(Typ
);
10964 if not Has_Rep_Item
(Typ
, Name_Invariant
, False)
10965 and then Has_Rep_Item
(Typ
, Name_Invariant
)
10966 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
10967 (Get_Rep_Item
(Typ
, Name_Invariant
))
10969 Set_Has_Invariants
(Typ
);
10971 if Class_Present
(Get_Rep_Item
(Typ
, Name_Invariant
)) then
10972 Set_Has_Inheritable_Invariants
(Typ
);
10975 -- If we have a subtype with invariants, whose base type does not have
10976 -- invariants, copy these invariants to the base type. This happens for
10977 -- the case of implicit base types created for scalar and array types.
10979 elsif Has_Invariants
(Typ
)
10980 and then not Has_Invariants
(Base_Type
(Typ
))
10982 Set_Has_Invariants
(Base_Type
(Typ
));
10983 Set_Invariant_Procedure
(Base_Type
(Typ
), Invariant_Procedure
(Typ
));
10988 if not Has_Rep_Item
(Typ
, Name_Volatile
, False)
10989 and then Has_Rep_Item
(Typ
, Name_Volatile
)
10990 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
10991 (Get_Rep_Item
(Typ
, Name_Volatile
))
10993 Set_Treat_As_Volatile
(Typ
);
10994 Set_Is_Volatile
(Typ
);
10997 -- Inheritance for derived types only
10999 if Is_Derived_Type
(Typ
) then
11001 Bas_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
11002 Imp_Bas_Typ
: constant Entity_Id
:= Implementation_Base_Type
(Typ
);
11005 -- Atomic_Components
11007 if not Has_Rep_Item
(Typ
, Name_Atomic_Components
, False)
11008 and then Has_Rep_Item
(Typ
, Name_Atomic_Components
)
11009 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11010 (Get_Rep_Item
(Typ
, Name_Atomic_Components
))
11012 Set_Has_Atomic_Components
(Imp_Bas_Typ
);
11015 -- Volatile_Components
11017 if not Has_Rep_Item
(Typ
, Name_Volatile_Components
, False)
11018 and then Has_Rep_Item
(Typ
, Name_Volatile_Components
)
11019 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11020 (Get_Rep_Item
(Typ
, Name_Volatile_Components
))
11022 Set_Has_Volatile_Components
(Imp_Bas_Typ
);
11025 -- Finalize_Storage_Only
11027 if not Has_Rep_Pragma
(Typ
, Name_Finalize_Storage_Only
, False)
11028 and then Has_Rep_Pragma
(Typ
, Name_Finalize_Storage_Only
)
11030 Set_Finalize_Storage_Only
(Bas_Typ
);
11033 -- Universal_Aliasing
11035 if not Has_Rep_Item
(Typ
, Name_Universal_Aliasing
, False)
11036 and then Has_Rep_Item
(Typ
, Name_Universal_Aliasing
)
11037 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11038 (Get_Rep_Item
(Typ
, Name_Universal_Aliasing
))
11040 Set_Universal_Aliasing
(Imp_Bas_Typ
);
11045 if Is_Record_Type
(Typ
) then
11046 if not Has_Rep_Item
(Typ
, Name_Bit_Order
, False)
11047 and then Has_Rep_Item
(Typ
, Name_Bit_Order
)
11049 Set_Reverse_Bit_Order
(Bas_Typ
,
11050 Reverse_Bit_Order
(Entity
(Name
11051 (Get_Rep_Item
(Typ
, Name_Bit_Order
)))));
11055 -- Scalar_Storage_Order
11057 -- Note: the aspect is specified on a first subtype, but recorded
11058 -- in a flag of the base type!
11060 if (Is_Record_Type
(Typ
) or else Is_Array_Type
(Typ
))
11061 and then Typ
= Bas_Typ
11063 -- For a type extension, always inherit from parent; otherwise
11064 -- inherit if no default applies. Note: we do not check for
11065 -- an explicit rep item on the parent type when inheriting,
11066 -- because the parent SSO may itself have been set by default.
11068 if not Has_Rep_Item
(First_Subtype
(Typ
),
11069 Name_Scalar_Storage_Order
, False)
11070 and then (Is_Tagged_Type
(Bas_Typ
)
11071 or else not (SSO_Set_Low_By_Default
(Bas_Typ
)
11073 SSO_Set_High_By_Default
(Bas_Typ
)))
11075 Set_Reverse_Storage_Order
(Bas_Typ
,
11076 Reverse_Storage_Order
11077 (Implementation_Base_Type
(Etype
(Bas_Typ
))));
11079 -- Clear default SSO indications, since the inherited aspect
11080 -- which was set explicitly overrides the default.
11082 Set_SSO_Set_Low_By_Default
(Bas_Typ
, False);
11083 Set_SSO_Set_High_By_Default
(Bas_Typ
, False);
11088 end Inherit_Aspects_At_Freeze_Point
;
11094 procedure Initialize
is
11096 Address_Clause_Checks
.Init
;
11097 Unchecked_Conversions
.Init
;
11099 if VM_Target
/= No_VM
or else AAMP_On_Target
then
11100 Independence_Checks
.Init
;
11104 ---------------------------
11105 -- Install_Discriminants --
11106 ---------------------------
11108 procedure Install_Discriminants
(E
: Entity_Id
) is
11112 Disc
:= First_Discriminant
(E
);
11113 while Present
(Disc
) loop
11114 Prev
:= Current_Entity
(Disc
);
11115 Set_Current_Entity
(Disc
);
11116 Set_Is_Immediately_Visible
(Disc
);
11117 Set_Homonym
(Disc
, Prev
);
11118 Next_Discriminant
(Disc
);
11120 end Install_Discriminants
;
11122 -------------------------
11123 -- Is_Operational_Item --
11124 -------------------------
11126 function Is_Operational_Item
(N
: Node_Id
) return Boolean is
11128 if Nkind
(N
) /= N_Attribute_Definition_Clause
then
11133 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Chars
(N
));
11135 return Id
= Attribute_Input
11136 or else Id
= Attribute_Output
11137 or else Id
= Attribute_Read
11138 or else Id
= Attribute_Write
11139 or else Id
= Attribute_External_Tag
;
11142 end Is_Operational_Item
;
11144 -------------------------
11145 -- Is_Predicate_Static --
11146 -------------------------
11148 -- Note: the basic legality of the expression has already been checked, so
11149 -- we don't need to worry about cases or ranges on strings for example.
11151 function Is_Predicate_Static
11153 Nam
: Name_Id
) return Boolean
11155 function All_Static_Case_Alternatives
(L
: List_Id
) return Boolean;
11156 -- Given a list of case expression alternatives, returns True if all
11157 -- the alternatives are static (have all static choices, and a static
11160 function All_Static_Choices
(L
: List_Id
) return Boolean;
11161 -- Returns true if all elements of the list are OK static choices
11162 -- as defined below for Is_Static_Choice. Used for case expression
11163 -- alternatives and for the right operand of a membership test. An
11164 -- others_choice is static if the corresponding expression is static.
11165 -- The staticness of the bounds is checked separately.
11167 function Is_Static_Choice
(N
: Node_Id
) return Boolean;
11168 -- Returns True if N represents a static choice (static subtype, or
11169 -- static subtype indication, or static expression, or static range).
11171 -- Note that this is a bit more inclusive than we actually need
11172 -- (in particular membership tests do not allow the use of subtype
11173 -- indications). But that doesn't matter, we have already checked
11174 -- that the construct is legal to get this far.
11176 function Is_Type_Ref
(N
: Node_Id
) return Boolean;
11177 pragma Inline
(Is_Type_Ref
);
11178 -- Returns True if N is a reference to the type for the predicate in the
11179 -- expression (i.e. if it is an identifier whose Chars field matches the
11180 -- Nam given in the call). N must not be parenthesized, if the type name
11181 -- appears in parens, this routine will return False.
11183 ----------------------------------
11184 -- All_Static_Case_Alternatives --
11185 ----------------------------------
11187 function All_Static_Case_Alternatives
(L
: List_Id
) return Boolean is
11192 while Present
(N
) loop
11193 if not (All_Static_Choices
(Discrete_Choices
(N
))
11194 and then Is_OK_Static_Expression
(Expression
(N
)))
11203 end All_Static_Case_Alternatives
;
11205 ------------------------
11206 -- All_Static_Choices --
11207 ------------------------
11209 function All_Static_Choices
(L
: List_Id
) return Boolean is
11214 while Present
(N
) loop
11215 if not Is_Static_Choice
(N
) then
11223 end All_Static_Choices
;
11225 ----------------------
11226 -- Is_Static_Choice --
11227 ----------------------
11229 function Is_Static_Choice
(N
: Node_Id
) return Boolean is
11231 return Nkind
(N
) = N_Others_Choice
11232 or else Is_OK_Static_Expression
(N
)
11233 or else (Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
))
11234 and then Is_OK_Static_Subtype
(Entity
(N
)))
11235 or else (Nkind
(N
) = N_Subtype_Indication
11236 and then Is_OK_Static_Subtype
(Entity
(N
)))
11237 or else (Nkind
(N
) = N_Range
and then Is_OK_Static_Range
(N
));
11238 end Is_Static_Choice
;
11244 function Is_Type_Ref
(N
: Node_Id
) return Boolean is
11246 return Nkind
(N
) = N_Identifier
11247 and then Chars
(N
) = Nam
11248 and then Paren_Count
(N
) = 0;
11251 -- Start of processing for Is_Predicate_Static
11254 -- Predicate_Static means one of the following holds. Numbers are the
11255 -- corresponding paragraph numbers in (RM 3.2.4(16-22)).
11257 -- 16: A static expression
11259 if Is_OK_Static_Expression
(Expr
) then
11262 -- 17: A membership test whose simple_expression is the current
11263 -- instance, and whose membership_choice_list meets the requirements
11264 -- for a static membership test.
11266 elsif Nkind
(Expr
) in N_Membership_Test
11267 and then ((Present
(Right_Opnd
(Expr
))
11268 and then Is_Static_Choice
(Right_Opnd
(Expr
)))
11270 (Present
(Alternatives
(Expr
))
11271 and then All_Static_Choices
(Alternatives
(Expr
))))
11275 -- 18. A case_expression whose selecting_expression is the current
11276 -- instance, and whose dependent expressions are static expressions.
11278 elsif Nkind
(Expr
) = N_Case_Expression
11279 and then Is_Type_Ref
(Expression
(Expr
))
11280 and then All_Static_Case_Alternatives
(Alternatives
(Expr
))
11284 -- 19. A call to a predefined equality or ordering operator, where one
11285 -- operand is the current instance, and the other is a static
11288 -- Note: the RM is clearly wrong here in not excluding string types.
11289 -- Without this exclusion, we would allow expressions like X > "ABC"
11290 -- to be considered as predicate-static, which is clearly not intended,
11291 -- since the idea is for predicate-static to be a subset of normal
11292 -- static expressions (and "DEF" > "ABC" is not a static expression).
11294 -- However, we do allow internally generated (not from source) equality
11295 -- and inequality operations to be valid on strings (this helps deal
11296 -- with cases where we transform A in "ABC" to A = "ABC).
11298 elsif Nkind
(Expr
) in N_Op_Compare
11299 and then ((not Is_String_Type
(Etype
(Left_Opnd
(Expr
))))
11300 or else (Nkind_In
(Expr
, N_Op_Eq
, N_Op_Ne
)
11301 and then not Comes_From_Source
(Expr
)))
11302 and then ((Is_Type_Ref
(Left_Opnd
(Expr
))
11303 and then Is_OK_Static_Expression
(Right_Opnd
(Expr
)))
11305 (Is_Type_Ref
(Right_Opnd
(Expr
))
11306 and then Is_OK_Static_Expression
(Left_Opnd
(Expr
))))
11310 -- 20. A call to a predefined boolean logical operator, where each
11311 -- operand is predicate-static.
11313 elsif (Nkind_In
(Expr
, N_Op_And
, N_Op_Or
, N_Op_Xor
)
11314 and then Is_Predicate_Static
(Left_Opnd
(Expr
), Nam
)
11315 and then Is_Predicate_Static
(Right_Opnd
(Expr
), Nam
))
11317 (Nkind
(Expr
) = N_Op_Not
11318 and then Is_Predicate_Static
(Right_Opnd
(Expr
), Nam
))
11322 -- 21. A short-circuit control form where both operands are
11323 -- predicate-static.
11325 elsif Nkind
(Expr
) in N_Short_Circuit
11326 and then Is_Predicate_Static
(Left_Opnd
(Expr
), Nam
)
11327 and then Is_Predicate_Static
(Right_Opnd
(Expr
), Nam
)
11331 -- 22. A parenthesized predicate-static expression. This does not
11332 -- require any special test, since we just ignore paren levels in
11333 -- all the cases above.
11335 -- One more test that is an implementation artifact caused by the fact
11336 -- that we are analyzing not the original expression, but the generated
11337 -- expression in the body of the predicate function. This can include
11338 -- references to inherited predicates, so that the expression we are
11339 -- processing looks like:
11341 -- expression and then xxPredicate (typ (Inns))
11343 -- Where the call is to a Predicate function for an inherited predicate.
11344 -- We simply ignore such a call, which could be to either a dynamic or
11345 -- a static predicate. Note that if the parent predicate is dynamic then
11346 -- eventually this type will be marked as dynamic, but you are allowed
11347 -- to specify a static predicate for a subtype which is inheriting a
11348 -- dynamic predicate, so the static predicate validation here ignores
11349 -- the inherited predicate even if it is dynamic.
11351 elsif Nkind
(Expr
) = N_Function_Call
11352 and then Is_Predicate_Function
(Entity
(Name
(Expr
)))
11356 -- That's an exhaustive list of tests, all other cases are not
11357 -- predicate-static, so we return False.
11362 end Is_Predicate_Static
;
11364 ---------------------
11365 -- Kill_Rep_Clause --
11366 ---------------------
11368 procedure Kill_Rep_Clause
(N
: Node_Id
) is
11370 pragma Assert
(Ignore_Rep_Clauses
);
11372 -- Note: we use Replace rather than Rewrite, because we don't want
11373 -- ASIS to be able to use Original_Node to dig out the (undecorated)
11374 -- rep clause that is being replaced.
11376 Replace
(N
, Make_Null_Statement
(Sloc
(N
)));
11378 -- The null statement must be marked as not coming from source. This is
11379 -- so that ASIS ignores it, and also the back end does not expect bogus
11380 -- "from source" null statements in weird places (e.g. in declarative
11381 -- regions where such null statements are not allowed).
11383 Set_Comes_From_Source
(N
, False);
11384 end Kill_Rep_Clause
;
11390 function Minimum_Size
11392 Biased
: Boolean := False) return Nat
11394 Lo
: Uint
:= No_Uint
;
11395 Hi
: Uint
:= No_Uint
;
11396 LoR
: Ureal
:= No_Ureal
;
11397 HiR
: Ureal
:= No_Ureal
;
11398 LoSet
: Boolean := False;
11399 HiSet
: Boolean := False;
11402 Ancest
: Entity_Id
;
11403 R_Typ
: constant Entity_Id
:= Root_Type
(T
);
11406 -- If bad type, return 0
11408 if T
= Any_Type
then
11411 -- For generic types, just return zero. There cannot be any legitimate
11412 -- need to know such a size, but this routine may be called with a
11413 -- generic type as part of normal processing.
11415 elsif Is_Generic_Type
(R_Typ
) or else R_Typ
= Any_Type
then
11418 -- Access types (cannot have size smaller than System.Address)
11420 elsif Is_Access_Type
(T
) then
11421 return System_Address_Size
;
11423 -- Floating-point types
11425 elsif Is_Floating_Point_Type
(T
) then
11426 return UI_To_Int
(Esize
(R_Typ
));
11430 elsif Is_Discrete_Type
(T
) then
11432 -- The following loop is looking for the nearest compile time known
11433 -- bounds following the ancestor subtype chain. The idea is to find
11434 -- the most restrictive known bounds information.
11438 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
11443 if Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
)) then
11444 Lo
:= Expr_Rep_Value
(Type_Low_Bound
(Ancest
));
11451 if Compile_Time_Known_Value
(Type_High_Bound
(Ancest
)) then
11452 Hi
:= Expr_Rep_Value
(Type_High_Bound
(Ancest
));
11458 Ancest
:= Ancestor_Subtype
(Ancest
);
11460 if No
(Ancest
) then
11461 Ancest
:= Base_Type
(T
);
11463 if Is_Generic_Type
(Ancest
) then
11469 -- Fixed-point types. We can't simply use Expr_Value to get the
11470 -- Corresponding_Integer_Value values of the bounds, since these do not
11471 -- get set till the type is frozen, and this routine can be called
11472 -- before the type is frozen. Similarly the test for bounds being static
11473 -- needs to include the case where we have unanalyzed real literals for
11474 -- the same reason.
11476 elsif Is_Fixed_Point_Type
(T
) then
11478 -- The following loop is looking for the nearest compile time known
11479 -- bounds following the ancestor subtype chain. The idea is to find
11480 -- the most restrictive known bounds information.
11484 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
11488 -- Note: In the following two tests for LoSet and HiSet, it may
11489 -- seem redundant to test for N_Real_Literal here since normally
11490 -- one would assume that the test for the value being known at
11491 -- compile time includes this case. However, there is a glitch.
11492 -- If the real literal comes from folding a non-static expression,
11493 -- then we don't consider any non- static expression to be known
11494 -- at compile time if we are in configurable run time mode (needed
11495 -- in some cases to give a clearer definition of what is and what
11496 -- is not accepted). So the test is indeed needed. Without it, we
11497 -- would set neither Lo_Set nor Hi_Set and get an infinite loop.
11500 if Nkind
(Type_Low_Bound
(Ancest
)) = N_Real_Literal
11501 or else Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
))
11503 LoR
:= Expr_Value_R
(Type_Low_Bound
(Ancest
));
11510 if Nkind
(Type_High_Bound
(Ancest
)) = N_Real_Literal
11511 or else Compile_Time_Known_Value
(Type_High_Bound
(Ancest
))
11513 HiR
:= Expr_Value_R
(Type_High_Bound
(Ancest
));
11519 Ancest
:= Ancestor_Subtype
(Ancest
);
11521 if No
(Ancest
) then
11522 Ancest
:= Base_Type
(T
);
11524 if Is_Generic_Type
(Ancest
) then
11530 Lo
:= UR_To_Uint
(LoR
/ Small_Value
(T
));
11531 Hi
:= UR_To_Uint
(HiR
/ Small_Value
(T
));
11533 -- No other types allowed
11536 raise Program_Error
;
11539 -- Fall through with Hi and Lo set. Deal with biased case
11542 and then not Is_Fixed_Point_Type
(T
)
11543 and then not (Is_Enumeration_Type
(T
)
11544 and then Has_Non_Standard_Rep
(T
)))
11545 or else Has_Biased_Representation
(T
)
11551 -- Signed case. Note that we consider types like range 1 .. -1 to be
11552 -- signed for the purpose of computing the size, since the bounds have
11553 -- to be accommodated in the base type.
11555 if Lo
< 0 or else Hi
< 0 then
11559 -- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1))
11560 -- Note that we accommodate the case where the bounds cross. This
11561 -- can happen either because of the way the bounds are declared
11562 -- or because of the algorithm in Freeze_Fixed_Point_Type.
11576 -- If both bounds are positive, make sure that both are represen-
11577 -- table in the case where the bounds are crossed. This can happen
11578 -- either because of the way the bounds are declared, or because of
11579 -- the algorithm in Freeze_Fixed_Point_Type.
11585 -- S = size, (can accommodate 0 .. (2**size - 1))
11588 while Hi
>= Uint_2
** S
loop
11596 ---------------------------
11597 -- New_Stream_Subprogram --
11598 ---------------------------
11600 procedure New_Stream_Subprogram
11604 Nam
: TSS_Name_Type
)
11606 Loc
: constant Source_Ptr
:= Sloc
(N
);
11607 Sname
: constant Name_Id
:= Make_TSS_Name
(Base_Type
(Ent
), Nam
);
11608 Subp_Id
: Entity_Id
;
11609 Subp_Decl
: Node_Id
;
11613 Defer_Declaration
: constant Boolean :=
11614 Is_Tagged_Type
(Ent
) or else Is_Private_Type
(Ent
);
11615 -- For a tagged type, there is a declaration for each stream attribute
11616 -- at the freeze point, and we must generate only a completion of this
11617 -- declaration. We do the same for private types, because the full view
11618 -- might be tagged. Otherwise we generate a declaration at the point of
11619 -- the attribute definition clause.
11621 function Build_Spec
return Node_Id
;
11622 -- Used for declaration and renaming declaration, so that this is
11623 -- treated as a renaming_as_body.
11629 function Build_Spec
return Node_Id
is
11630 Out_P
: constant Boolean := (Nam
= TSS_Stream_Read
);
11633 T_Ref
: constant Node_Id
:= New_Occurrence_Of
(Etyp
, Loc
);
11636 Subp_Id
:= Make_Defining_Identifier
(Loc
, Sname
);
11638 -- S : access Root_Stream_Type'Class
11640 Formals
:= New_List
(
11641 Make_Parameter_Specification
(Loc
,
11642 Defining_Identifier
=>
11643 Make_Defining_Identifier
(Loc
, Name_S
),
11645 Make_Access_Definition
(Loc
,
11647 New_Occurrence_Of
(
11648 Designated_Type
(Etype
(F
)), Loc
))));
11650 if Nam
= TSS_Stream_Input
then
11652 Make_Function_Specification
(Loc
,
11653 Defining_Unit_Name
=> Subp_Id
,
11654 Parameter_Specifications
=> Formals
,
11655 Result_Definition
=> T_Ref
);
11659 Append_To
(Formals
,
11660 Make_Parameter_Specification
(Loc
,
11661 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_V
),
11662 Out_Present
=> Out_P
,
11663 Parameter_Type
=> T_Ref
));
11666 Make_Procedure_Specification
(Loc
,
11667 Defining_Unit_Name
=> Subp_Id
,
11668 Parameter_Specifications
=> Formals
);
11674 -- Start of processing for New_Stream_Subprogram
11677 F
:= First_Formal
(Subp
);
11679 if Ekind
(Subp
) = E_Procedure
then
11680 Etyp
:= Etype
(Next_Formal
(F
));
11682 Etyp
:= Etype
(Subp
);
11685 -- Prepare subprogram declaration and insert it as an action on the
11686 -- clause node. The visibility for this entity is used to test for
11687 -- visibility of the attribute definition clause (in the sense of
11688 -- 8.3(23) as amended by AI-195).
11690 if not Defer_Declaration
then
11692 Make_Subprogram_Declaration
(Loc
,
11693 Specification
=> Build_Spec
);
11695 -- For a tagged type, there is always a visible declaration for each
11696 -- stream TSS (it is a predefined primitive operation), and the
11697 -- completion of this declaration occurs at the freeze point, which is
11698 -- not always visible at places where the attribute definition clause is
11699 -- visible. So, we create a dummy entity here for the purpose of
11700 -- tracking the visibility of the attribute definition clause itself.
11704 Make_Defining_Identifier
(Loc
, New_External_Name
(Sname
, 'V'));
11706 Make_Object_Declaration
(Loc
,
11707 Defining_Identifier
=> Subp_Id
,
11708 Object_Definition
=> New_Occurrence_Of
(Standard_Boolean
, Loc
));
11711 Insert_Action
(N
, Subp_Decl
);
11712 Set_Entity
(N
, Subp_Id
);
11715 Make_Subprogram_Renaming_Declaration
(Loc
,
11716 Specification
=> Build_Spec
,
11717 Name
=> New_Occurrence_Of
(Subp
, Loc
));
11719 if Defer_Declaration
then
11720 Set_TSS
(Base_Type
(Ent
), Subp_Id
);
11722 Insert_Action
(N
, Subp_Decl
);
11723 Copy_TSS
(Subp_Id
, Base_Type
(Ent
));
11725 end New_Stream_Subprogram
;
11727 ------------------------------------------
11728 -- Push_Scope_And_Install_Discriminants --
11729 ------------------------------------------
11731 procedure Push_Scope_And_Install_Discriminants
(E
: Entity_Id
) is
11733 if Has_Discriminants
(E
) then
11736 -- Make discriminants visible for type declarations and protected
11737 -- type declarations, not for subtype declarations (RM 13.1.1 (12/3))
11739 if Nkind
(Parent
(E
)) /= N_Subtype_Declaration
then
11740 Install_Discriminants
(E
);
11743 end Push_Scope_And_Install_Discriminants
;
11745 ------------------------
11746 -- Rep_Item_Too_Early --
11747 ------------------------
11749 function Rep_Item_Too_Early
(T
: Entity_Id
; N
: Node_Id
) return Boolean is
11751 -- Cannot apply non-operational rep items to generic types
11753 if Is_Operational_Item
(N
) then
11757 and then Is_Generic_Type
(Root_Type
(T
))
11758 and then (Nkind
(N
) /= N_Pragma
11759 or else Get_Pragma_Id
(N
) /= Pragma_Convention
)
11761 Error_Msg_N
("representation item not allowed for generic type", N
);
11765 -- Otherwise check for incomplete type
11767 if Is_Incomplete_Or_Private_Type
(T
)
11768 and then No
(Underlying_Type
(T
))
11770 (Nkind
(N
) /= N_Pragma
11771 or else Get_Pragma_Id
(N
) /= Pragma_Import
)
11774 ("representation item must be after full type declaration", N
);
11777 -- If the type has incomplete components, a representation clause is
11778 -- illegal but stream attributes and Convention pragmas are correct.
11780 elsif Has_Private_Component
(T
) then
11781 if Nkind
(N
) = N_Pragma
then
11786 ("representation item must appear after type is fully defined",
11793 end Rep_Item_Too_Early
;
11795 -----------------------
11796 -- Rep_Item_Too_Late --
11797 -----------------------
11799 function Rep_Item_Too_Late
11802 FOnly
: Boolean := False) return Boolean
11805 Parent_Type
: Entity_Id
;
11807 procedure No_Type_Rep_Item
;
11808 -- Output message indicating that no type-related aspects can be
11809 -- specified due to some property of the parent type.
11811 procedure Too_Late
;
11812 -- Output message for an aspect being specified too late
11814 -- Note that neither of the above errors is considered a serious one,
11815 -- since the effect is simply that we ignore the representation clause
11817 -- Is this really true? In any case if we make this change we must
11818 -- document the requirement in the spec of Rep_Item_Too_Late that
11819 -- if True is returned, then the rep item must be completely ignored???
11821 ----------------------
11822 -- No_Type_Rep_Item --
11823 ----------------------
11825 procedure No_Type_Rep_Item
is
11827 Error_Msg_N
("|type-related representation item not permitted!", N
);
11828 end No_Type_Rep_Item
;
11834 procedure Too_Late
is
11836 -- Other compilers seem more relaxed about rep items appearing too
11837 -- late. Since analysis tools typically don't care about rep items
11838 -- anyway, no reason to be too strict about this.
11840 if not Relaxed_RM_Semantics
then
11841 Error_Msg_N
("|representation item appears too late!", N
);
11845 -- Start of processing for Rep_Item_Too_Late
11848 -- First make sure entity is not frozen (RM 13.1(9))
11852 -- Exclude imported types, which may be frozen if they appear in a
11853 -- representation clause for a local type.
11855 and then not From_Limited_With
(T
)
11857 -- Exclude generated entities (not coming from source). The common
11858 -- case is when we generate a renaming which prematurely freezes the
11859 -- renamed internal entity, but we still want to be able to set copies
11860 -- of attribute values such as Size/Alignment.
11862 and then Comes_From_Source
(T
)
11865 S
:= First_Subtype
(T
);
11867 if Present
(Freeze_Node
(S
)) then
11868 if not Relaxed_RM_Semantics
then
11870 ("??no more representation items for }", Freeze_Node
(S
), S
);
11876 -- Check for case of untagged derived type whose parent either has
11877 -- primitive operations, or is a by reference type (RM 13.1(10)). In
11878 -- this case we do not output a Too_Late message, since there is no
11879 -- earlier point where the rep item could be placed to make it legal.
11883 and then Is_Derived_Type
(T
)
11884 and then not Is_Tagged_Type
(T
)
11886 Parent_Type
:= Etype
(Base_Type
(T
));
11888 if Has_Primitive_Operations
(Parent_Type
) then
11891 if not Relaxed_RM_Semantics
then
11893 ("\parent type & has primitive operations!", N
, Parent_Type
);
11898 elsif Is_By_Reference_Type
(Parent_Type
) then
11901 if not Relaxed_RM_Semantics
then
11903 ("\parent type & is a by reference type!", N
, Parent_Type
);
11910 -- No error, but one more warning to consider. The RM (surprisingly)
11911 -- allows this pattern:
11914 -- primitive operations for S
11915 -- type R is new S;
11916 -- rep clause for S
11918 -- Meaning that calls on the primitive operations of S for values of
11919 -- type R may require possibly expensive implicit conversion operations.
11920 -- This is not an error, but is worth a warning.
11922 if not Relaxed_RM_Semantics
and then Is_Type
(T
) then
11924 DTL
: constant Entity_Id
:= Derived_Type_Link
(Base_Type
(T
));
11928 and then Has_Primitive_Operations
(Base_Type
(T
))
11930 -- For now, do not generate this warning for the case of aspect
11931 -- specification using Ada 2012 syntax, since we get wrong
11932 -- messages we do not understand. The whole business of derived
11933 -- types and rep items seems a bit confused when aspects are
11934 -- used, since the aspects are not evaluated till freeze time.
11936 and then not From_Aspect_Specification
(N
)
11938 Error_Msg_Sloc
:= Sloc
(DTL
);
11940 ("representation item for& appears after derived type "
11941 & "declaration#??", N
);
11943 ("\may result in implicit conversions for primitive "
11944 & "operations of&??", N
, T
);
11946 ("\to change representations when called with arguments "
11947 & "of type&??", N
, DTL
);
11952 -- No error, link item into head of chain of rep items for the entity,
11953 -- but avoid chaining if we have an overloadable entity, and the pragma
11954 -- is one that can apply to multiple overloaded entities.
11956 if Is_Overloadable
(T
) and then Nkind
(N
) = N_Pragma
then
11958 Pname
: constant Name_Id
:= Pragma_Name
(N
);
11960 if Nam_In
(Pname
, Name_Convention
, Name_Import
, Name_Export
,
11961 Name_External
, Name_Interface
)
11968 Record_Rep_Item
(T
, N
);
11970 end Rep_Item_Too_Late
;
11972 -------------------------------------
11973 -- Replace_Type_References_Generic --
11974 -------------------------------------
11976 procedure Replace_Type_References_Generic
(N
: Node_Id
; T
: Entity_Id
) is
11977 TName
: constant Name_Id
:= Chars
(T
);
11979 function Replace_Node
(N
: Node_Id
) return Traverse_Result
;
11980 -- Processes a single node in the traversal procedure below, checking
11981 -- if node N should be replaced, and if so, doing the replacement.
11983 procedure Replace_Type_Refs
is new Traverse_Proc
(Replace_Node
);
11984 -- This instantiation provides the body of Replace_Type_References
11990 function Replace_Node
(N
: Node_Id
) return Traverse_Result
is
11995 -- Case of identifier
11997 if Nkind
(N
) = N_Identifier
then
11999 -- If not the type name, check whether it is a reference to
12000 -- some other type, which must be frozen before the predicate
12001 -- function is analyzed, i.e. before the freeze node of the
12002 -- type to which the predicate applies.
12004 if Chars
(N
) /= TName
then
12005 if Present
(Current_Entity
(N
))
12006 and then Is_Type
(Current_Entity
(N
))
12008 Freeze_Before
(Freeze_Node
(T
), Current_Entity
(N
));
12013 -- Otherwise do the replacement and we are done with this node
12016 Replace_Type_Reference
(N
);
12020 -- Case of selected component (which is what a qualification
12021 -- looks like in the unanalyzed tree, which is what we have.
12023 elsif Nkind
(N
) = N_Selected_Component
then
12025 -- If selector name is not our type, keeping going (we might
12026 -- still have an occurrence of the type in the prefix).
12028 if Nkind
(Selector_Name
(N
)) /= N_Identifier
12029 or else Chars
(Selector_Name
(N
)) /= TName
12033 -- Selector name is our type, check qualification
12036 -- Loop through scopes and prefixes, doing comparison
12038 S
:= Current_Scope
;
12041 -- Continue if no more scopes or scope with no name
12043 if No
(S
) or else Nkind
(S
) not in N_Has_Chars
then
12047 -- Do replace if prefix is an identifier matching the
12048 -- scope that we are currently looking at.
12050 if Nkind
(P
) = N_Identifier
12051 and then Chars
(P
) = Chars
(S
)
12053 Replace_Type_Reference
(N
);
12057 -- Go check scope above us if prefix is itself of the
12058 -- form of a selected component, whose selector matches
12059 -- the scope we are currently looking at.
12061 if Nkind
(P
) = N_Selected_Component
12062 and then Nkind
(Selector_Name
(P
)) = N_Identifier
12063 and then Chars
(Selector_Name
(P
)) = Chars
(S
)
12068 -- For anything else, we don't have a match, so keep on
12069 -- going, there are still some weird cases where we may
12070 -- still have a replacement within the prefix.
12078 -- Continue for any other node kind
12086 Replace_Type_Refs
(N
);
12087 end Replace_Type_References_Generic
;
12089 -------------------------
12090 -- Same_Representation --
12091 -------------------------
12093 function Same_Representation
(Typ1
, Typ2
: Entity_Id
) return Boolean is
12094 T1
: constant Entity_Id
:= Underlying_Type
(Typ1
);
12095 T2
: constant Entity_Id
:= Underlying_Type
(Typ2
);
12098 -- A quick check, if base types are the same, then we definitely have
12099 -- the same representation, because the subtype specific representation
12100 -- attributes (Size and Alignment) do not affect representation from
12101 -- the point of view of this test.
12103 if Base_Type
(T1
) = Base_Type
(T2
) then
12106 elsif Is_Private_Type
(Base_Type
(T2
))
12107 and then Base_Type
(T1
) = Full_View
(Base_Type
(T2
))
12112 -- Tagged types never have differing representations
12114 if Is_Tagged_Type
(T1
) then
12118 -- Representations are definitely different if conventions differ
12120 if Convention
(T1
) /= Convention
(T2
) then
12124 -- Representations are different if component alignments or scalar
12125 -- storage orders differ.
12127 if (Is_Record_Type
(T1
) or else Is_Array_Type
(T1
))
12129 (Is_Record_Type
(T2
) or else Is_Array_Type
(T2
))
12131 (Component_Alignment
(T1
) /= Component_Alignment
(T2
)
12132 or else Reverse_Storage_Order
(T1
) /= Reverse_Storage_Order
(T2
))
12137 -- For arrays, the only real issue is component size. If we know the
12138 -- component size for both arrays, and it is the same, then that's
12139 -- good enough to know we don't have a change of representation.
12141 if Is_Array_Type
(T1
) then
12142 if Known_Component_Size
(T1
)
12143 and then Known_Component_Size
(T2
)
12144 and then Component_Size
(T1
) = Component_Size
(T2
)
12146 if VM_Target
= No_VM
then
12149 -- In VM targets the representation of arrays with aliased
12150 -- components differs from arrays with non-aliased components
12153 return Has_Aliased_Components
(Base_Type
(T1
))
12155 Has_Aliased_Components
(Base_Type
(T2
));
12160 -- Types definitely have same representation if neither has non-standard
12161 -- representation since default representations are always consistent.
12162 -- If only one has non-standard representation, and the other does not,
12163 -- then we consider that they do not have the same representation. They
12164 -- might, but there is no way of telling early enough.
12166 if Has_Non_Standard_Rep
(T1
) then
12167 if not Has_Non_Standard_Rep
(T2
) then
12171 return not Has_Non_Standard_Rep
(T2
);
12174 -- Here the two types both have non-standard representation, and we need
12175 -- to determine if they have the same non-standard representation.
12177 -- For arrays, we simply need to test if the component sizes are the
12178 -- same. Pragma Pack is reflected in modified component sizes, so this
12179 -- check also deals with pragma Pack.
12181 if Is_Array_Type
(T1
) then
12182 return Component_Size
(T1
) = Component_Size
(T2
);
12184 -- Tagged types always have the same representation, because it is not
12185 -- possible to specify different representations for common fields.
12187 elsif Is_Tagged_Type
(T1
) then
12190 -- Case of record types
12192 elsif Is_Record_Type
(T1
) then
12194 -- Packed status must conform
12196 if Is_Packed
(T1
) /= Is_Packed
(T2
) then
12199 -- Otherwise we must check components. Typ2 maybe a constrained
12200 -- subtype with fewer components, so we compare the components
12201 -- of the base types.
12204 Record_Case
: declare
12205 CD1
, CD2
: Entity_Id
;
12207 function Same_Rep
return Boolean;
12208 -- CD1 and CD2 are either components or discriminants. This
12209 -- function tests whether they have the same representation.
12215 function Same_Rep
return Boolean is
12217 if No
(Component_Clause
(CD1
)) then
12218 return No
(Component_Clause
(CD2
));
12220 -- Note: at this point, component clauses have been
12221 -- normalized to the default bit order, so that the
12222 -- comparison of Component_Bit_Offsets is meaningful.
12225 Present
(Component_Clause
(CD2
))
12227 Component_Bit_Offset
(CD1
) = Component_Bit_Offset
(CD2
)
12229 Esize
(CD1
) = Esize
(CD2
);
12233 -- Start of processing for Record_Case
12236 if Has_Discriminants
(T1
) then
12238 -- The number of discriminants may be different if the
12239 -- derived type has fewer (constrained by values). The
12240 -- invisible discriminants retain the representation of
12241 -- the original, so the discrepancy does not per se
12242 -- indicate a different representation.
12244 CD1
:= First_Discriminant
(T1
);
12245 CD2
:= First_Discriminant
(T2
);
12246 while Present
(CD1
) and then Present
(CD2
) loop
12247 if not Same_Rep
then
12250 Next_Discriminant
(CD1
);
12251 Next_Discriminant
(CD2
);
12256 CD1
:= First_Component
(Underlying_Type
(Base_Type
(T1
)));
12257 CD2
:= First_Component
(Underlying_Type
(Base_Type
(T2
)));
12258 while Present
(CD1
) loop
12259 if not Same_Rep
then
12262 Next_Component
(CD1
);
12263 Next_Component
(CD2
);
12271 -- For enumeration types, we must check each literal to see if the
12272 -- representation is the same. Note that we do not permit enumeration
12273 -- representation clauses for Character and Wide_Character, so these
12274 -- cases were already dealt with.
12276 elsif Is_Enumeration_Type
(T1
) then
12277 Enumeration_Case
: declare
12278 L1
, L2
: Entity_Id
;
12281 L1
:= First_Literal
(T1
);
12282 L2
:= First_Literal
(T2
);
12283 while Present
(L1
) loop
12284 if Enumeration_Rep
(L1
) /= Enumeration_Rep
(L2
) then
12293 end Enumeration_Case
;
12295 -- Any other types have the same representation for these purposes
12300 end Same_Representation
;
12302 --------------------------------
12303 -- Resolve_Iterable_Operation --
12304 --------------------------------
12306 procedure Resolve_Iterable_Operation
12308 Cursor
: Entity_Id
;
12317 if not Is_Overloaded
(N
) then
12318 if not Is_Entity_Name
(N
)
12319 or else Ekind
(Entity
(N
)) /= E_Function
12320 or else Scope
(Entity
(N
)) /= Scope
(Typ
)
12321 or else No
(First_Formal
(Entity
(N
)))
12322 or else Etype
(First_Formal
(Entity
(N
))) /= Typ
12324 Error_Msg_N
("iterable primitive must be local function name "
12325 & "whose first formal is an iterable type", N
);
12330 F1
:= First_Formal
(Ent
);
12331 if Nam
= Name_First
then
12333 -- First (Container) => Cursor
12335 if Etype
(Ent
) /= Cursor
then
12336 Error_Msg_N
("primitive for First must yield a curosr", N
);
12339 elsif Nam
= Name_Next
then
12341 -- Next (Container, Cursor) => Cursor
12343 F2
:= Next_Formal
(F1
);
12345 if Etype
(F2
) /= Cursor
12346 or else Etype
(Ent
) /= Cursor
12347 or else Present
(Next_Formal
(F2
))
12349 Error_Msg_N
("no match for Next iterable primitive", N
);
12352 elsif Nam
= Name_Has_Element
then
12354 -- Has_Element (Container, Cursor) => Boolean
12356 F2
:= Next_Formal
(F1
);
12357 if Etype
(F2
) /= Cursor
12358 or else Etype
(Ent
) /= Standard_Boolean
12359 or else Present
(Next_Formal
(F2
))
12361 Error_Msg_N
("no match for Has_Element iterable primitive", N
);
12364 elsif Nam
= Name_Element
then
12365 F2
:= Next_Formal
(F1
);
12368 or else Etype
(F2
) /= Cursor
12369 or else Present
(Next_Formal
(F2
))
12371 Error_Msg_N
("no match for Element iterable primitive", N
);
12376 raise Program_Error
;
12380 -- Overloaded case: find subprogram with proper signature.
12381 -- Caller will report error if no match is found.
12388 Get_First_Interp
(N
, I
, It
);
12389 while Present
(It
.Typ
) loop
12390 if Ekind
(It
.Nam
) = E_Function
12391 and then Scope
(It
.Nam
) = Scope
(Typ
)
12392 and then Etype
(First_Formal
(It
.Nam
)) = Typ
12394 F1
:= First_Formal
(It
.Nam
);
12396 if Nam
= Name_First
then
12397 if Etype
(It
.Nam
) = Cursor
12398 and then No
(Next_Formal
(F1
))
12400 Set_Entity
(N
, It
.Nam
);
12404 elsif Nam
= Name_Next
then
12405 F2
:= Next_Formal
(F1
);
12408 and then No
(Next_Formal
(F2
))
12409 and then Etype
(F2
) = Cursor
12410 and then Etype
(It
.Nam
) = Cursor
12412 Set_Entity
(N
, It
.Nam
);
12416 elsif Nam
= Name_Has_Element
then
12417 F2
:= Next_Formal
(F1
);
12420 and then No
(Next_Formal
(F2
))
12421 and then Etype
(F2
) = Cursor
12422 and then Etype
(It
.Nam
) = Standard_Boolean
12424 Set_Entity
(N
, It
.Nam
);
12425 F2
:= Next_Formal
(F1
);
12429 elsif Nam
= Name_Element
then
12430 F2
:= Next_Formal
(F1
);
12433 and then No
(Next_Formal
(F2
))
12434 and then Etype
(F2
) = Cursor
12436 Set_Entity
(N
, It
.Nam
);
12442 Get_Next_Interp
(I
, It
);
12446 end Resolve_Iterable_Operation
;
12452 procedure Set_Biased
12456 Biased
: Boolean := True)
12460 Set_Has_Biased_Representation
(E
);
12462 if Warn_On_Biased_Representation
then
12464 ("?B?" & Msg
& " forces biased representation for&", N
, E
);
12469 --------------------
12470 -- Set_Enum_Esize --
12471 --------------------
12473 procedure Set_Enum_Esize
(T
: Entity_Id
) is
12479 Init_Alignment
(T
);
12481 -- Find the minimum standard size (8,16,32,64) that fits
12483 Lo
:= Enumeration_Rep
(Entity
(Type_Low_Bound
(T
)));
12484 Hi
:= Enumeration_Rep
(Entity
(Type_High_Bound
(T
)));
12487 if Lo
>= -Uint_2
**07 and then Hi
< Uint_2
**07 then
12488 Sz
:= Standard_Character_Size
; -- May be > 8 on some targets
12490 elsif Lo
>= -Uint_2
**15 and then Hi
< Uint_2
**15 then
12493 elsif Lo
>= -Uint_2
**31 and then Hi
< Uint_2
**31 then
12496 else pragma Assert
(Lo
>= -Uint_2
**63 and then Hi
< Uint_2
**63);
12501 if Hi
< Uint_2
**08 then
12502 Sz
:= Standard_Character_Size
; -- May be > 8 on some targets
12504 elsif Hi
< Uint_2
**16 then
12507 elsif Hi
< Uint_2
**32 then
12510 else pragma Assert
(Hi
< Uint_2
**63);
12515 -- That minimum is the proper size unless we have a foreign convention
12516 -- and the size required is 32 or less, in which case we bump the size
12517 -- up to 32. This is required for C and C++ and seems reasonable for
12518 -- all other foreign conventions.
12520 if Has_Foreign_Convention
(T
)
12521 and then Esize
(T
) < Standard_Integer_Size
12523 -- Don't do this if Short_Enums on target
12525 and then not Target_Short_Enums
12527 Init_Esize
(T
, Standard_Integer_Size
);
12529 Init_Esize
(T
, Sz
);
12531 end Set_Enum_Esize
;
12533 -----------------------------
12534 -- Uninstall_Discriminants --
12535 -----------------------------
12537 procedure Uninstall_Discriminants
(E
: Entity_Id
) is
12543 -- Discriminants have been made visible for type declarations and
12544 -- protected type declarations, not for subtype declarations.
12546 if Nkind
(Parent
(E
)) /= N_Subtype_Declaration
then
12547 Disc
:= First_Discriminant
(E
);
12548 while Present
(Disc
) loop
12549 if Disc
/= Current_Entity
(Disc
) then
12550 Prev
:= Current_Entity
(Disc
);
12551 while Present
(Prev
)
12552 and then Present
(Homonym
(Prev
))
12553 and then Homonym
(Prev
) /= Disc
12555 Prev
:= Homonym
(Prev
);
12561 Set_Is_Immediately_Visible
(Disc
, False);
12563 Outer
:= Homonym
(Disc
);
12564 while Present
(Outer
) and then Scope
(Outer
) = E
loop
12565 Outer
:= Homonym
(Outer
);
12568 -- Reset homonym link of other entities, but do not modify link
12569 -- between entities in current scope, so that the back-end can
12570 -- have a proper count of local overloadings.
12573 Set_Name_Entity_Id
(Chars
(Disc
), Outer
);
12575 elsif Scope
(Prev
) /= Scope
(Disc
) then
12576 Set_Homonym
(Prev
, Outer
);
12579 Next_Discriminant
(Disc
);
12582 end Uninstall_Discriminants
;
12584 -------------------------------------------
12585 -- Uninstall_Discriminants_And_Pop_Scope --
12586 -------------------------------------------
12588 procedure Uninstall_Discriminants_And_Pop_Scope
(E
: Entity_Id
) is
12590 if Has_Discriminants
(E
) then
12591 Uninstall_Discriminants
(E
);
12594 end Uninstall_Discriminants_And_Pop_Scope
;
12596 ------------------------------
12597 -- Validate_Address_Clauses --
12598 ------------------------------
12600 procedure Validate_Address_Clauses
is
12602 for J
in Address_Clause_Checks
.First
.. Address_Clause_Checks
.Last
loop
12604 ACCR
: Address_Clause_Check_Record
12605 renames Address_Clause_Checks
.Table
(J
);
12609 X_Alignment
: Uint
;
12610 Y_Alignment
: Uint
;
12616 -- Skip processing of this entry if warning already posted
12618 if not Address_Warning_Posted
(ACCR
.N
) then
12619 Expr
:= Original_Node
(Expression
(ACCR
.N
));
12623 X_Alignment
:= Alignment
(ACCR
.X
);
12624 Y_Alignment
:= Alignment
(ACCR
.Y
);
12626 -- Similarly obtain sizes
12628 X_Size
:= Esize
(ACCR
.X
);
12629 Y_Size
:= Esize
(ACCR
.Y
);
12631 -- Check for large object overlaying smaller one
12634 and then X_Size
> Uint_0
12635 and then X_Size
> Y_Size
12638 ("??& overlays smaller object", ACCR
.N
, ACCR
.X
);
12640 ("\??program execution may be erroneous", ACCR
.N
);
12641 Error_Msg_Uint_1
:= X_Size
;
12643 ("\??size of & is ^", ACCR
.N
, ACCR
.X
);
12644 Error_Msg_Uint_1
:= Y_Size
;
12646 ("\??size of & is ^", ACCR
.N
, ACCR
.Y
);
12648 -- Check for inadequate alignment, both of the base object
12649 -- and of the offset, if any.
12651 -- Note: we do not check the alignment if we gave a size
12652 -- warning, since it would likely be redundant.
12654 elsif Y_Alignment
/= Uint_0
12655 and then (Y_Alignment
< X_Alignment
12658 Nkind
(Expr
) = N_Attribute_Reference
12660 Attribute_Name
(Expr
) = Name_Address
12662 Has_Compatible_Alignment
12663 (ACCR
.X
, Prefix
(Expr
))
12664 /= Known_Compatible
))
12667 ("??specified address for& may be inconsistent "
12668 & "with alignment", ACCR
.N
, ACCR
.X
);
12670 ("\??program execution may be erroneous (RM 13.3(27))",
12672 Error_Msg_Uint_1
:= X_Alignment
;
12674 ("\??alignment of & is ^", ACCR
.N
, ACCR
.X
);
12675 Error_Msg_Uint_1
:= Y_Alignment
;
12677 ("\??alignment of & is ^", ACCR
.N
, ACCR
.Y
);
12678 if Y_Alignment
>= X_Alignment
then
12680 ("\??but offset is not multiple of alignment", ACCR
.N
);
12686 end Validate_Address_Clauses
;
12688 ---------------------------
12689 -- Validate_Independence --
12690 ---------------------------
12692 procedure Validate_Independence
is
12693 SU
: constant Uint
:= UI_From_Int
(System_Storage_Unit
);
12701 procedure Check_Array_Type
(Atyp
: Entity_Id
);
12702 -- Checks if the array type Atyp has independent components, and
12703 -- if not, outputs an appropriate set of error messages.
12705 procedure No_Independence
;
12706 -- Output message that independence cannot be guaranteed
12708 function OK_Component
(C
: Entity_Id
) return Boolean;
12709 -- Checks one component to see if it is independently accessible, and
12710 -- if so yields True, otherwise yields False if independent access
12711 -- cannot be guaranteed. This is a conservative routine, it only
12712 -- returns True if it knows for sure, it returns False if it knows
12713 -- there is a problem, or it cannot be sure there is no problem.
12715 procedure Reason_Bad_Component
(C
: Entity_Id
);
12716 -- Outputs continuation message if a reason can be determined for
12717 -- the component C being bad.
12719 ----------------------
12720 -- Check_Array_Type --
12721 ----------------------
12723 procedure Check_Array_Type
(Atyp
: Entity_Id
) is
12724 Ctyp
: constant Entity_Id
:= Component_Type
(Atyp
);
12727 -- OK if no alignment clause, no pack, and no component size
12729 if not Has_Component_Size_Clause
(Atyp
)
12730 and then not Has_Alignment_Clause
(Atyp
)
12731 and then not Is_Packed
(Atyp
)
12736 -- Case of component size is greater than or equal to 64 and the
12737 -- alignment of the array is at least as large as the alignment
12738 -- of the component. We are definitely OK in this situation.
12740 if Known_Component_Size
(Atyp
)
12741 and then Component_Size
(Atyp
) >= 64
12742 and then Known_Alignment
(Atyp
)
12743 and then Known_Alignment
(Ctyp
)
12744 and then Alignment
(Atyp
) >= Alignment
(Ctyp
)
12749 -- Check actual component size
12751 if not Known_Component_Size
(Atyp
)
12752 or else not (Addressable
(Component_Size
(Atyp
))
12753 and then Component_Size
(Atyp
) < 64)
12754 or else Component_Size
(Atyp
) mod Esize
(Ctyp
) /= 0
12758 -- Bad component size, check reason
12760 if Has_Component_Size_Clause
(Atyp
) then
12761 P
:= Get_Attribute_Definition_Clause
12762 (Atyp
, Attribute_Component_Size
);
12764 if Present
(P
) then
12765 Error_Msg_Sloc
:= Sloc
(P
);
12766 Error_Msg_N
("\because of Component_Size clause#", N
);
12771 if Is_Packed
(Atyp
) then
12772 P
:= Get_Rep_Pragma
(Atyp
, Name_Pack
);
12774 if Present
(P
) then
12775 Error_Msg_Sloc
:= Sloc
(P
);
12776 Error_Msg_N
("\because of pragma Pack#", N
);
12781 -- No reason found, just return
12786 -- Array type is OK independence-wise
12789 end Check_Array_Type
;
12791 ---------------------
12792 -- No_Independence --
12793 ---------------------
12795 procedure No_Independence
is
12797 if Pragma_Name
(N
) = Name_Independent
then
12798 Error_Msg_NE
("independence cannot be guaranteed for&", N
, E
);
12801 ("independent components cannot be guaranteed for&", N
, E
);
12803 end No_Independence
;
12809 function OK_Component
(C
: Entity_Id
) return Boolean is
12810 Rec
: constant Entity_Id
:= Scope
(C
);
12811 Ctyp
: constant Entity_Id
:= Etype
(C
);
12814 -- OK if no component clause, no Pack, and no alignment clause
12816 if No
(Component_Clause
(C
))
12817 and then not Is_Packed
(Rec
)
12818 and then not Has_Alignment_Clause
(Rec
)
12823 -- Here we look at the actual component layout. A component is
12824 -- addressable if its size is a multiple of the Esize of the
12825 -- component type, and its starting position in the record has
12826 -- appropriate alignment, and the record itself has appropriate
12827 -- alignment to guarantee the component alignment.
12829 -- Make sure sizes are static, always assume the worst for any
12830 -- cases where we cannot check static values.
12832 if not (Known_Static_Esize
(C
)
12834 Known_Static_Esize
(Ctyp
))
12839 -- Size of component must be addressable or greater than 64 bits
12840 -- and a multiple of bytes.
12842 if not Addressable
(Esize
(C
)) and then Esize
(C
) < Uint_64
then
12846 -- Check size is proper multiple
12848 if Esize
(C
) mod Esize
(Ctyp
) /= 0 then
12852 -- Check alignment of component is OK
12854 if not Known_Component_Bit_Offset
(C
)
12855 or else Component_Bit_Offset
(C
) < Uint_0
12856 or else Component_Bit_Offset
(C
) mod Esize
(Ctyp
) /= 0
12861 -- Check alignment of record type is OK
12863 if not Known_Alignment
(Rec
)
12864 or else (Alignment
(Rec
) * SU
) mod Esize
(Ctyp
) /= 0
12869 -- All tests passed, component is addressable
12874 --------------------------
12875 -- Reason_Bad_Component --
12876 --------------------------
12878 procedure Reason_Bad_Component
(C
: Entity_Id
) is
12879 Rec
: constant Entity_Id
:= Scope
(C
);
12880 Ctyp
: constant Entity_Id
:= Etype
(C
);
12883 -- If component clause present assume that's the problem
12885 if Present
(Component_Clause
(C
)) then
12886 Error_Msg_Sloc
:= Sloc
(Component_Clause
(C
));
12887 Error_Msg_N
("\because of Component_Clause#", N
);
12891 -- If pragma Pack clause present, assume that's the problem
12893 if Is_Packed
(Rec
) then
12894 P
:= Get_Rep_Pragma
(Rec
, Name_Pack
);
12896 if Present
(P
) then
12897 Error_Msg_Sloc
:= Sloc
(P
);
12898 Error_Msg_N
("\because of pragma Pack#", N
);
12903 -- See if record has bad alignment clause
12905 if Has_Alignment_Clause
(Rec
)
12906 and then Known_Alignment
(Rec
)
12907 and then (Alignment
(Rec
) * SU
) mod Esize
(Ctyp
) /= 0
12909 P
:= Get_Attribute_Definition_Clause
(Rec
, Attribute_Alignment
);
12911 if Present
(P
) then
12912 Error_Msg_Sloc
:= Sloc
(P
);
12913 Error_Msg_N
("\because of Alignment clause#", N
);
12917 -- Couldn't find a reason, so return without a message
12920 end Reason_Bad_Component
;
12922 -- Start of processing for Validate_Independence
12925 for J
in Independence_Checks
.First
.. Independence_Checks
.Last
loop
12926 N
:= Independence_Checks
.Table
(J
).N
;
12927 E
:= Independence_Checks
.Table
(J
).E
;
12928 IC
:= Pragma_Name
(N
) = Name_Independent_Components
;
12930 -- Deal with component case
12932 if Ekind
(E
) = E_Discriminant
or else Ekind
(E
) = E_Component
then
12933 if not OK_Component
(E
) then
12935 Reason_Bad_Component
(E
);
12940 -- Deal with record with Independent_Components
12942 if IC
and then Is_Record_Type
(E
) then
12943 Comp
:= First_Component_Or_Discriminant
(E
);
12944 while Present
(Comp
) loop
12945 if not OK_Component
(Comp
) then
12947 Reason_Bad_Component
(Comp
);
12951 Next_Component_Or_Discriminant
(Comp
);
12955 -- Deal with address clause case
12957 if Is_Object
(E
) then
12958 Addr
:= Address_Clause
(E
);
12960 if Present
(Addr
) then
12962 Error_Msg_Sloc
:= Sloc
(Addr
);
12963 Error_Msg_N
("\because of Address clause#", N
);
12968 -- Deal with independent components for array type
12970 if IC
and then Is_Array_Type
(E
) then
12971 Check_Array_Type
(E
);
12974 -- Deal with independent components for array object
12976 if IC
and then Is_Object
(E
) and then Is_Array_Type
(Etype
(E
)) then
12977 Check_Array_Type
(Etype
(E
));
12982 end Validate_Independence
;
12984 ------------------------------
12985 -- Validate_Iterable_Aspect --
12986 ------------------------------
12988 procedure Validate_Iterable_Aspect
(Typ
: Entity_Id
; ASN
: Node_Id
) is
12993 Cursor
: constant Entity_Id
:= Get_Cursor_Type
(ASN
, Typ
);
12995 First_Id
: Entity_Id
;
12996 Next_Id
: Entity_Id
;
12997 Has_Element_Id
: Entity_Id
;
12998 Element_Id
: Entity_Id
;
13001 -- If previous error aspect is unusable
13003 if Cursor
= Any_Type
then
13009 Has_Element_Id
:= Empty
;
13010 Element_Id
:= Empty
;
13012 -- Each expression must resolve to a function with the proper signature
13014 Assoc
:= First
(Component_Associations
(Expression
(ASN
)));
13015 while Present
(Assoc
) loop
13016 Expr
:= Expression
(Assoc
);
13019 Prim
:= First
(Choices
(Assoc
));
13021 if Nkind
(Prim
) /= N_Identifier
or else Present
(Next
(Prim
)) then
13022 Error_Msg_N
("illegal name in association", Prim
);
13024 elsif Chars
(Prim
) = Name_First
then
13025 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_First
);
13026 First_Id
:= Entity
(Expr
);
13028 elsif Chars
(Prim
) = Name_Next
then
13029 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_Next
);
13030 Next_Id
:= Entity
(Expr
);
13032 elsif Chars
(Prim
) = Name_Has_Element
then
13033 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_Has_Element
);
13034 Has_Element_Id
:= Entity
(Expr
);
13036 elsif Chars
(Prim
) = Name_Element
then
13037 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_Element
);
13038 Element_Id
:= Entity
(Expr
);
13041 Error_Msg_N
("invalid name for iterable function", Prim
);
13047 if No
(First_Id
) then
13048 Error_Msg_N
("match for First primitive not found", ASN
);
13050 elsif No
(Next_Id
) then
13051 Error_Msg_N
("match for Next primitive not found", ASN
);
13053 elsif No
(Has_Element_Id
) then
13054 Error_Msg_N
("match for Has_Element primitive not found", ASN
);
13056 elsif No
(Element_Id
) then
13059 end Validate_Iterable_Aspect
;
13061 -----------------------------------
13062 -- Validate_Unchecked_Conversion --
13063 -----------------------------------
13065 procedure Validate_Unchecked_Conversion
13067 Act_Unit
: Entity_Id
)
13069 Source
: Entity_Id
;
13070 Target
: Entity_Id
;
13074 -- Obtain source and target types. Note that we call Ancestor_Subtype
13075 -- here because the processing for generic instantiation always makes
13076 -- subtypes, and we want the original frozen actual types.
13078 -- If we are dealing with private types, then do the check on their
13079 -- fully declared counterparts if the full declarations have been
13080 -- encountered (they don't have to be visible, but they must exist).
13082 Source
:= Ancestor_Subtype
(Etype
(First_Formal
(Act_Unit
)));
13084 if Is_Private_Type
(Source
)
13085 and then Present
(Underlying_Type
(Source
))
13087 Source
:= Underlying_Type
(Source
);
13090 Target
:= Ancestor_Subtype
(Etype
(Act_Unit
));
13092 -- If either type is generic, the instantiation happens within a generic
13093 -- unit, and there is nothing to check. The proper check will happen
13094 -- when the enclosing generic is instantiated.
13096 if Is_Generic_Type
(Source
) or else Is_Generic_Type
(Target
) then
13100 if Is_Private_Type
(Target
)
13101 and then Present
(Underlying_Type
(Target
))
13103 Target
:= Underlying_Type
(Target
);
13106 -- Source may be unconstrained array, but not target
13108 if Is_Array_Type
(Target
) and then not Is_Constrained
(Target
) then
13110 ("unchecked conversion to unconstrained array not allowed", N
);
13114 -- Warn if conversion between two different convention pointers
13116 if Is_Access_Type
(Target
)
13117 and then Is_Access_Type
(Source
)
13118 and then Convention
(Target
) /= Convention
(Source
)
13119 and then Warn_On_Unchecked_Conversion
13121 -- Give warnings for subprogram pointers only on most targets
13123 if Is_Access_Subprogram_Type
(Target
)
13124 or else Is_Access_Subprogram_Type
(Source
)
13127 ("?z?conversion between pointers with different conventions!",
13132 -- Warn if one of the operands is Ada.Calendar.Time. Do not emit a
13133 -- warning when compiling GNAT-related sources.
13135 if Warn_On_Unchecked_Conversion
13136 and then not In_Predefined_Unit
(N
)
13137 and then RTU_Loaded
(Ada_Calendar
)
13138 and then (Chars
(Source
) = Name_Time
13140 Chars
(Target
) = Name_Time
)
13142 -- If Ada.Calendar is loaded and the name of one of the operands is
13143 -- Time, there is a good chance that this is Ada.Calendar.Time.
13146 Calendar_Time
: constant Entity_Id
:= Full_View
(RTE
(RO_CA_Time
));
13148 pragma Assert
(Present
(Calendar_Time
));
13150 if Source
= Calendar_Time
or else Target
= Calendar_Time
then
13152 ("?z?representation of 'Time values may change between "
13153 & "'G'N'A'T versions", N
);
13158 -- Make entry in unchecked conversion table for later processing by
13159 -- Validate_Unchecked_Conversions, which will check sizes and alignments
13160 -- (using values set by the back-end where possible). This is only done
13161 -- if the appropriate warning is active.
13163 if Warn_On_Unchecked_Conversion
then
13164 Unchecked_Conversions
.Append
13165 (New_Val
=> UC_Entry
'(Eloc => Sloc (N),
13168 Act_Unit => Act_Unit));
13170 -- If both sizes are known statically now, then back end annotation
13171 -- is not required to do a proper check but if either size is not
13172 -- known statically, then we need the annotation.
13174 if Known_Static_RM_Size (Source)
13176 Known_Static_RM_Size (Target)
13180 Back_Annotate_Rep_Info := True;
13184 -- If unchecked conversion to access type, and access type is declared
13185 -- in the same unit as the unchecked conversion, then set the flag
13186 -- No_Strict_Aliasing (no strict aliasing is implicit here)
13188 if Is_Access_Type (Target) and then
13189 In_Same_Source_Unit (Target, N)
13191 Set_No_Strict_Aliasing (Implementation_Base_Type (Target));
13194 -- Generate N_Validate_Unchecked_Conversion node for back end in case
13195 -- the back end needs to perform special validation checks.
13197 -- Shouldn't this be in Exp_Ch13, since the check only gets done if we
13198 -- have full expansion and the back end is called ???
13201 Make_Validate_Unchecked_Conversion (Sloc (N));
13202 Set_Source_Type (Vnode, Source);
13203 Set_Target_Type (Vnode, Target);
13205 -- If the unchecked conversion node is in a list, just insert before it.
13206 -- If not we have some strange case, not worth bothering about.
13208 if Is_List_Member (N) then
13209 Insert_After (N, Vnode);
13211 end Validate_Unchecked_Conversion;
13213 ------------------------------------
13214 -- Validate_Unchecked_Conversions --
13215 ------------------------------------
13217 procedure Validate_Unchecked_Conversions is
13219 for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop
13221 T : UC_Entry renames Unchecked_Conversions.Table (N);
13223 Eloc : constant Source_Ptr := T.Eloc;
13224 Source : constant Entity_Id := T.Source;
13225 Target : constant Entity_Id := T.Target;
13226 Act_Unit : constant Entity_Id := T.Act_Unit;
13232 -- Skip if function marked as warnings off
13234 if Warnings_Off (Act_Unit) then
13238 -- This validation check, which warns if we have unequal sizes for
13239 -- unchecked conversion, and thus potentially implementation
13240 -- dependent semantics, is one of the few occasions on which we
13241 -- use the official RM size instead of Esize. See description in
13242 -- Einfo "Handling of Type'Size Values" for details.
13244 if Serious_Errors_Detected = 0
13245 and then Known_Static_RM_Size (Source)
13246 and then Known_Static_RM_Size (Target)
13248 -- Don't do the check if warnings off for either type, note the
13249 -- deliberate use of OR here instead of OR ELSE to get the flag
13250 -- Warnings_Off_Used set for both types if appropriate.
13252 and then not (Has_Warnings_Off (Source)
13254 Has_Warnings_Off (Target))
13256 Source_Siz := RM_Size (Source);
13257 Target_Siz := RM_Size (Target);
13259 if Source_Siz /= Target_Siz then
13261 ("?z?types for unchecked conversion have different sizes!",
13264 if All_Errors_Mode then
13265 Error_Msg_Name_1 := Chars (Source);
13266 Error_Msg_Uint_1 := Source_Siz;
13267 Error_Msg_Name_2 := Chars (Target);
13268 Error_Msg_Uint_2 := Target_Siz;
13269 Error_Msg ("\size of % is ^, size of % is ^?z?", Eloc);
13271 Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz);
13273 if Is_Discrete_Type (Source)
13275 Is_Discrete_Type (Target)
13277 if Source_Siz > Target_Siz then
13279 ("\?z?^ high order bits of source will "
13280 & "be ignored!", Eloc);
13282 elsif Is_Unsigned_Type (Source) then
13284 ("\?z?source will be extended with ^ high order "
13285 & "zero bits!", Eloc);
13289 ("\?z?source will be extended with ^ high order "
13290 & "sign bits!", Eloc);
13293 elsif Source_Siz < Target_Siz then
13294 if Is_Discrete_Type (Target) then
13295 if Bytes_Big_Endian then
13297 ("\?z?target value will include ^ undefined "
13298 & "low order bits!", Eloc);
13301 ("\?z?target value will include ^ undefined "
13302 & "high order bits!", Eloc);
13307 ("\?z?^ trailing bits of target value will be "
13308 & "undefined!", Eloc);
13311 else pragma Assert (Source_Siz > Target_Siz);
13313 ("\?z?^ trailing bits of source will be ignored!",
13320 -- If both types are access types, we need to check the alignment.
13321 -- If the alignment of both is specified, we can do it here.
13323 if Serious_Errors_Detected = 0
13324 and then Is_Access_Type (Source)
13325 and then Is_Access_Type (Target)
13326 and then Target_Strict_Alignment
13327 and then Present (Designated_Type (Source))
13328 and then Present (Designated_Type (Target))
13331 D_Source : constant Entity_Id := Designated_Type (Source);
13332 D_Target : constant Entity_Id := Designated_Type (Target);
13335 if Known_Alignment (D_Source)
13337 Known_Alignment (D_Target)
13340 Source_Align : constant Uint := Alignment (D_Source);
13341 Target_Align : constant Uint := Alignment (D_Target);
13344 if Source_Align < Target_Align
13345 and then not Is_Tagged_Type (D_Source)
13347 -- Suppress warning if warnings suppressed on either
13348 -- type or either designated type. Note the use of
13349 -- OR here instead of OR ELSE. That is intentional,
13350 -- we would like to set flag Warnings_Off_Used in
13351 -- all types for which warnings are suppressed.
13353 and then not (Has_Warnings_Off (D_Source)
13355 Has_Warnings_Off (D_Target)
13357 Has_Warnings_Off (Source)
13359 Has_Warnings_Off (Target))
13361 Error_Msg_Uint_1 := Target_Align;
13362 Error_Msg_Uint_2 := Source_Align;
13363 Error_Msg_Node_1 := D_Target;
13364 Error_Msg_Node_2 := D_Source;
13366 ("?z?alignment of & (^) is stricter than "
13367 & "alignment of & (^)!", Eloc);
13369 ("\?z?resulting access value may have invalid "
13370 & "alignment!", Eloc);
13381 end Validate_Unchecked_Conversions;