1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2014, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Aspects
; use Aspects
;
27 with Atree
; use Atree
;
28 with Checks
; use Checks
;
29 with Debug
; use Debug
;
30 with Einfo
; use Einfo
;
31 with Elists
; use Elists
;
32 with Errout
; use Errout
;
33 with Exp_Disp
; use Exp_Disp
;
34 with Exp_Tss
; use Exp_Tss
;
35 with Exp_Util
; use Exp_Util
;
36 with Freeze
; use Freeze
;
38 with Lib
.Xref
; use Lib
.Xref
;
39 with Namet
; use Namet
;
40 with Nlists
; use Nlists
;
41 with Nmake
; use Nmake
;
43 with Restrict
; use Restrict
;
44 with Rident
; use Rident
;
45 with Rtsfind
; use Rtsfind
;
47 with Sem_Aux
; use Sem_Aux
;
48 with Sem_Case
; use Sem_Case
;
49 with Sem_Ch3
; use Sem_Ch3
;
50 with Sem_Ch6
; use Sem_Ch6
;
51 with Sem_Ch8
; use Sem_Ch8
;
52 with Sem_Dim
; use Sem_Dim
;
53 with Sem_Disp
; use Sem_Disp
;
54 with Sem_Eval
; use Sem_Eval
;
55 with Sem_Prag
; use Sem_Prag
;
56 with Sem_Res
; use Sem_Res
;
57 with Sem_Type
; use Sem_Type
;
58 with Sem_Util
; use Sem_Util
;
59 with Sem_Warn
; use Sem_Warn
;
60 with Sinput
; use Sinput
;
61 with Snames
; use Snames
;
62 with Stand
; use Stand
;
63 with Sinfo
; use Sinfo
;
64 with Stringt
; use Stringt
;
65 with Targparm
; use Targparm
;
66 with Ttypes
; use Ttypes
;
67 with Tbuild
; use Tbuild
;
68 with Urealp
; use Urealp
;
69 with Warnsw
; use Warnsw
;
71 with GNAT
.Heap_Sort_G
;
73 package body Sem_Ch13
is
75 SSU
: constant Pos
:= System_Storage_Unit
;
76 -- Convenient short hand for commonly used constant
78 -----------------------
79 -- Local Subprograms --
80 -----------------------
82 procedure Alignment_Check_For_Size_Change
(Typ
: Entity_Id
; Size
: Uint
);
83 -- This routine is called after setting one of the sizes of type entity
84 -- Typ to Size. The purpose is to deal with the situation of a derived
85 -- type whose inherited alignment is no longer appropriate for the new
86 -- size value. In this case, we reset the Alignment to unknown.
88 procedure Build_Discrete_Static_Predicate
92 -- Given a predicated type Typ, where Typ is a discrete static subtype,
93 -- whose predicate expression is Expr, tests if Expr is a static predicate,
94 -- and if so, builds the predicate range list. Nam is the name of the one
95 -- argument to the predicate function. Occurrences of the type name in the
96 -- predicate expression have been replaced by identifier references to this
97 -- name, which is unique, so any identifier with Chars matching Nam must be
98 -- a reference to the type. If the predicate is non-static, this procedure
99 -- returns doing nothing. If the predicate is static, then the predicate
100 -- list is stored in Static_Discrete_Predicate (Typ), and the Expr is
101 -- rewritten as a canonicalized membership operation.
103 procedure Build_Predicate_Functions
(Typ
: Entity_Id
; N
: Node_Id
);
104 -- If Typ has predicates (indicated by Has_Predicates being set for Typ),
105 -- then either there are pragma Predicate entries on the rep chain for the
106 -- type (note that Predicate aspects are converted to pragma Predicate), or
107 -- there are inherited aspects from a parent type, or ancestor subtypes.
108 -- This procedure builds the spec and body for the Predicate function that
109 -- tests these predicates. N is the freeze node for the type. The spec of
110 -- the function is inserted before the freeze node, and the body of the
111 -- function is inserted after the freeze node. If the predicate expression
112 -- has at least one Raise_Expression, then this procedure also builds the
113 -- M version of the predicate function for use in membership tests.
115 procedure Check_Pool_Size_Clash
(Ent
: Entity_Id
; SP
, SS
: Node_Id
);
116 -- Called if both Storage_Pool and Storage_Size attribute definition
117 -- clauses (SP and SS) are present for entity Ent. Issue error message.
119 procedure Freeze_Entity_Checks
(N
: Node_Id
);
120 -- Called from Analyze_Freeze_Entity and Analyze_Generic_Freeze Entity
121 -- to generate appropriate semantic checks that are delayed until this
122 -- point (they had to be delayed this long for cases of delayed aspects,
123 -- e.g. analysis of statically predicated subtypes in choices, for which
124 -- we have to be sure the subtypes in question are frozen before checking.
126 function Get_Alignment_Value
(Expr
: Node_Id
) return Uint
;
127 -- Given the expression for an alignment value, returns the corresponding
128 -- Uint value. If the value is inappropriate, then error messages are
129 -- posted as required, and a value of No_Uint is returned.
131 function Is_Operational_Item
(N
: Node_Id
) return Boolean;
132 -- A specification for a stream attribute is allowed before the full type
133 -- is declared, as explained in AI-00137 and the corrigendum. Attributes
134 -- that do not specify a representation characteristic are operational
137 function Is_Predicate_Static
139 Nam
: Name_Id
) return Boolean;
140 -- Given predicate expression Expr, tests if Expr is predicate-static in
141 -- the sense of the rules in (RM 3.2.4 (15-24)). Occurrences of the type
142 -- name in the predicate expression have been replaced by references to
143 -- an identifier whose Chars field is Nam. This name is unique, so any
144 -- identifier with Chars matching Nam must be a reference to the type.
145 -- Returns True if the expression is predicate-static and False otherwise,
146 -- but is not in the business of setting flags or issuing error messages.
148 -- Only scalar types can have static predicates, so False is always
149 -- returned for non-scalar types.
151 -- Note: the RM seems to suggest that string types can also have static
152 -- predicates. But that really makes lttle sense as very few useful
153 -- predicates can be constructed for strings. Remember that:
157 -- is not a static expression. So even though the clearly faulty RM wording
158 -- allows the following:
160 -- subtype S is String with Static_Predicate => S < "DEF"
162 -- We can't allow this, otherwise we have predicate-static applying to a
163 -- larger class than static expressions, which was never intended.
165 procedure New_Stream_Subprogram
169 Nam
: TSS_Name_Type
);
170 -- Create a subprogram renaming of a given stream attribute to the
171 -- designated subprogram and then in the tagged case, provide this as a
172 -- primitive operation, or in the untagged case make an appropriate TSS
173 -- entry. This is more properly an expansion activity than just semantics,
174 -- but the presence of user-defined stream functions for limited types
175 -- is a legality check, which is why this takes place here rather than in
176 -- exp_ch13, where it was previously. Nam indicates the name of the TSS
177 -- function to be generated.
179 -- To avoid elaboration anomalies with freeze nodes, for untagged types
180 -- we generate both a subprogram declaration and a subprogram renaming
181 -- declaration, so that the attribute specification is handled as a
182 -- renaming_as_body. For tagged types, the specification is one of the
185 procedure Resolve_Iterable_Operation
190 -- If the name of a primitive operation for an Iterable aspect is
191 -- overloaded, resolve according to required signature.
197 Biased
: Boolean := True);
198 -- If Biased is True, sets Has_Biased_Representation flag for E, and
199 -- outputs a warning message at node N if Warn_On_Biased_Representation is
200 -- is True. This warning inserts the string Msg to describe the construct
203 ----------------------------------------------
204 -- Table for Validate_Unchecked_Conversions --
205 ----------------------------------------------
207 -- The following table collects unchecked conversions for validation.
208 -- Entries are made by Validate_Unchecked_Conversion and then the call
209 -- to Validate_Unchecked_Conversions does the actual error checking and
210 -- posting of warnings. The reason for this delayed processing is to take
211 -- advantage of back-annotations of size and alignment values performed by
214 -- Note: the reason we store a Source_Ptr value instead of a Node_Id is
215 -- that by the time Validate_Unchecked_Conversions is called, Sprint will
216 -- already have modified all Sloc values if the -gnatD option is set.
218 type UC_Entry
is record
219 Eloc
: Source_Ptr
; -- node used for posting warnings
220 Source
: Entity_Id
; -- source type for unchecked conversion
221 Target
: Entity_Id
; -- target type for unchecked conversion
222 Act_Unit
: Entity_Id
; -- actual function instantiated
225 package Unchecked_Conversions
is new Table
.Table
(
226 Table_Component_Type
=> UC_Entry
,
227 Table_Index_Type
=> Int
,
228 Table_Low_Bound
=> 1,
230 Table_Increment
=> 200,
231 Table_Name
=> "Unchecked_Conversions");
233 ----------------------------------------
234 -- Table for Validate_Address_Clauses --
235 ----------------------------------------
237 -- If an address clause has the form
239 -- for X'Address use Expr
241 -- where Expr is of the form Y'Address or recursively is a reference to a
242 -- constant of either of these forms, and X and Y are entities of objects,
243 -- then if Y has a smaller alignment than X, that merits a warning about
244 -- possible bad alignment. The following table collects address clauses of
245 -- this kind. We put these in a table so that they can be checked after the
246 -- back end has completed annotation of the alignments of objects, since we
247 -- can catch more cases that way.
249 type Address_Clause_Check_Record
is record
251 -- The address clause
254 -- The entity of the object overlaying Y
257 -- The entity of the object being overlaid
260 -- Whether the address is offset within Y
263 package Address_Clause_Checks
is new Table
.Table
(
264 Table_Component_Type
=> Address_Clause_Check_Record
,
265 Table_Index_Type
=> Int
,
266 Table_Low_Bound
=> 1,
268 Table_Increment
=> 200,
269 Table_Name
=> "Address_Clause_Checks");
271 -----------------------------------------
272 -- Adjust_Record_For_Reverse_Bit_Order --
273 -----------------------------------------
275 procedure Adjust_Record_For_Reverse_Bit_Order
(R
: Entity_Id
) is
280 -- Processing depends on version of Ada
282 -- For Ada 95, we just renumber bits within a storage unit. We do the
283 -- same for Ada 83 mode, since we recognize the Bit_Order attribute in
284 -- Ada 83, and are free to add this extension.
286 if Ada_Version
< Ada_2005
then
287 Comp
:= First_Component_Or_Discriminant
(R
);
288 while Present
(Comp
) loop
289 CC
:= Component_Clause
(Comp
);
291 -- If component clause is present, then deal with the non-default
292 -- bit order case for Ada 95 mode.
294 -- We only do this processing for the base type, and in fact that
295 -- is important, since otherwise if there are record subtypes, we
296 -- could reverse the bits once for each subtype, which is wrong.
298 if Present
(CC
) and then Ekind
(R
) = E_Record_Type
then
300 CFB
: constant Uint
:= Component_Bit_Offset
(Comp
);
301 CSZ
: constant Uint
:= Esize
(Comp
);
302 CLC
: constant Node_Id
:= Component_Clause
(Comp
);
303 Pos
: constant Node_Id
:= Position
(CLC
);
304 FB
: constant Node_Id
:= First_Bit
(CLC
);
306 Storage_Unit_Offset
: constant Uint
:=
307 CFB
/ System_Storage_Unit
;
309 Start_Bit
: constant Uint
:=
310 CFB
mod System_Storage_Unit
;
313 -- Cases where field goes over storage unit boundary
315 if Start_Bit
+ CSZ
> System_Storage_Unit
then
317 -- Allow multi-byte field but generate warning
319 if Start_Bit
mod System_Storage_Unit
= 0
320 and then CSZ
mod System_Storage_Unit
= 0
323 ("info: multi-byte field specified with "
324 & "non-standard Bit_Order?V?", CLC
);
326 if Bytes_Big_Endian
then
328 ("\bytes are not reversed "
329 & "(component is big-endian)?V?", CLC
);
332 ("\bytes are not reversed "
333 & "(component is little-endian)?V?", CLC
);
336 -- Do not allow non-contiguous field
340 ("attempt to specify non-contiguous field "
341 & "not permitted", CLC
);
343 ("\caused by non-standard Bit_Order "
346 ("\consider possibility of using "
347 & "Ada 2005 mode here", CLC
);
350 -- Case where field fits in one storage unit
353 -- Give warning if suspicious component clause
355 if Intval
(FB
) >= System_Storage_Unit
356 and then Warn_On_Reverse_Bit_Order
359 ("info: Bit_Order clause does not affect " &
360 "byte ordering?V?", Pos
);
362 Intval
(Pos
) + Intval
(FB
) /
365 ("info: position normalized to ^ before bit " &
366 "order interpreted?V?", Pos
);
369 -- Here is where we fix up the Component_Bit_Offset value
370 -- to account for the reverse bit order. Some examples of
371 -- what needs to be done are:
373 -- First_Bit .. Last_Bit Component_Bit_Offset
385 -- The rule is that the first bit is is obtained by
386 -- subtracting the old ending bit from storage_unit - 1.
388 Set_Component_Bit_Offset
390 (Storage_Unit_Offset
* System_Storage_Unit
) +
391 (System_Storage_Unit
- 1) -
392 (Start_Bit
+ CSZ
- 1));
394 Set_Normalized_First_Bit
396 Component_Bit_Offset
(Comp
) mod
397 System_Storage_Unit
);
402 Next_Component_Or_Discriminant
(Comp
);
405 -- For Ada 2005, we do machine scalar processing, as fully described In
406 -- AI-133. This involves gathering all components which start at the
407 -- same byte offset and processing them together. Same approach is still
408 -- valid in later versions including Ada 2012.
412 Max_Machine_Scalar_Size
: constant Uint
:=
414 (Standard_Long_Long_Integer_Size
);
415 -- We use this as the maximum machine scalar size
418 SSU
: constant Uint
:= UI_From_Int
(System_Storage_Unit
);
421 -- This first loop through components does two things. First it
422 -- deals with the case of components with component clauses whose
423 -- length is greater than the maximum machine scalar size (either
424 -- accepting them or rejecting as needed). Second, it counts the
425 -- number of components with component clauses whose length does
426 -- not exceed this maximum for later processing.
429 Comp
:= First_Component_Or_Discriminant
(R
);
430 while Present
(Comp
) loop
431 CC
:= Component_Clause
(Comp
);
435 Fbit
: constant Uint
:= Static_Integer
(First_Bit
(CC
));
436 Lbit
: constant Uint
:= Static_Integer
(Last_Bit
(CC
));
439 -- Case of component with last bit >= max machine scalar
441 if Lbit
>= Max_Machine_Scalar_Size
then
443 -- This is allowed only if first bit is zero, and
444 -- last bit + 1 is a multiple of storage unit size.
446 if Fbit
= 0 and then (Lbit
+ 1) mod SSU
= 0 then
448 -- This is the case to give a warning if enabled
450 if Warn_On_Reverse_Bit_Order
then
452 ("info: multi-byte field specified with "
453 & " non-standard Bit_Order?V?", CC
);
455 if Bytes_Big_Endian
then
457 ("\bytes are not reversed "
458 & "(component is big-endian)?V?", CC
);
461 ("\bytes are not reversed "
462 & "(component is little-endian)?V?", CC
);
466 -- Give error message for RM 13.5.1(10) violation
470 ("machine scalar rules not followed for&",
471 First_Bit
(CC
), Comp
);
473 Error_Msg_Uint_1
:= Lbit
;
474 Error_Msg_Uint_2
:= Max_Machine_Scalar_Size
;
476 ("\last bit (^) exceeds maximum machine "
480 if (Lbit
+ 1) mod SSU
/= 0 then
481 Error_Msg_Uint_1
:= SSU
;
483 ("\and is not a multiple of Storage_Unit (^) "
488 Error_Msg_Uint_1
:= Fbit
;
490 ("\and first bit (^) is non-zero "
496 -- OK case of machine scalar related component clause,
497 -- For now, just count them.
500 Num_CC
:= Num_CC
+ 1;
505 Next_Component_Or_Discriminant
(Comp
);
508 -- We need to sort the component clauses on the basis of the
509 -- Position values in the clause, so we can group clauses with
510 -- the same Position together to determine the relevant machine
514 Comps
: array (0 .. Num_CC
) of Entity_Id
;
515 -- Array to collect component and discriminant entities. The
516 -- data starts at index 1, the 0'th entry is for the sort
519 function CP_Lt
(Op1
, Op2
: Natural) return Boolean;
520 -- Compare routine for Sort
522 procedure CP_Move
(From
: Natural; To
: Natural);
523 -- Move routine for Sort
525 package Sorting
is new GNAT
.Heap_Sort_G
(CP_Move
, CP_Lt
);
529 -- Start and stop positions in the component list of the set of
530 -- components with the same starting position (that constitute
531 -- components in a single machine scalar).
534 -- Maximum last bit value of any component in this set
537 -- Corresponding machine scalar size
543 function CP_Lt
(Op1
, Op2
: Natural) return Boolean is
545 return Position
(Component_Clause
(Comps
(Op1
))) <
546 Position
(Component_Clause
(Comps
(Op2
)));
553 procedure CP_Move
(From
: Natural; To
: Natural) is
555 Comps
(To
) := Comps
(From
);
558 -- Start of processing for Sort_CC
561 -- Collect the machine scalar relevant component clauses
564 Comp
:= First_Component_Or_Discriminant
(R
);
565 while Present
(Comp
) loop
567 CC
: constant Node_Id
:= Component_Clause
(Comp
);
570 -- Collect only component clauses whose last bit is less
571 -- than machine scalar size. Any component clause whose
572 -- last bit exceeds this value does not take part in
573 -- machine scalar layout considerations. The test for
574 -- Error_Posted makes sure we exclude component clauses
575 -- for which we already posted an error.
578 and then not Error_Posted
(Last_Bit
(CC
))
579 and then Static_Integer
(Last_Bit
(CC
)) <
580 Max_Machine_Scalar_Size
582 Num_CC
:= Num_CC
+ 1;
583 Comps
(Num_CC
) := Comp
;
587 Next_Component_Or_Discriminant
(Comp
);
590 -- Sort by ascending position number
592 Sorting
.Sort
(Num_CC
);
594 -- We now have all the components whose size does not exceed
595 -- the max machine scalar value, sorted by starting position.
596 -- In this loop we gather groups of clauses starting at the
597 -- same position, to process them in accordance with AI-133.
600 while Stop
< Num_CC
loop
605 (Last_Bit
(Component_Clause
(Comps
(Start
))));
606 while Stop
< Num_CC
loop
608 (Position
(Component_Clause
(Comps
(Stop
+ 1)))) =
610 (Position
(Component_Clause
(Comps
(Stop
))))
618 (Component_Clause
(Comps
(Stop
)))));
624 -- Now we have a group of component clauses from Start to
625 -- Stop whose positions are identical, and MaxL is the
626 -- maximum last bit value of any of these components.
628 -- We need to determine the corresponding machine scalar
629 -- size. This loop assumes that machine scalar sizes are
630 -- even, and that each possible machine scalar has twice
631 -- as many bits as the next smaller one.
633 MSS
:= Max_Machine_Scalar_Size
;
635 and then (MSS
/ 2) >= SSU
636 and then (MSS
/ 2) > MaxL
641 -- Here is where we fix up the Component_Bit_Offset value
642 -- to account for the reverse bit order. Some examples of
643 -- what needs to be done for the case of a machine scalar
646 -- First_Bit .. Last_Bit Component_Bit_Offset
658 -- The rule is that the first bit is obtained by subtracting
659 -- the old ending bit from machine scalar size - 1.
661 for C
in Start
.. Stop
loop
663 Comp
: constant Entity_Id
:= Comps
(C
);
664 CC
: constant Node_Id
:= Component_Clause
(Comp
);
666 LB
: constant Uint
:= Static_Integer
(Last_Bit
(CC
));
667 NFB
: constant Uint
:= MSS
- Uint_1
- LB
;
668 NLB
: constant Uint
:= NFB
+ Esize
(Comp
) - 1;
669 Pos
: constant Uint
:= Static_Integer
(Position
(CC
));
672 if Warn_On_Reverse_Bit_Order
then
673 Error_Msg_Uint_1
:= MSS
;
675 ("info: reverse bit order in machine " &
676 "scalar of length^?V?", First_Bit
(CC
));
677 Error_Msg_Uint_1
:= NFB
;
678 Error_Msg_Uint_2
:= NLB
;
680 if Bytes_Big_Endian
then
682 ("\big-endian range for component "
683 & "& is ^ .. ^?V?", First_Bit
(CC
), Comp
);
686 ("\little-endian range for component"
687 & "& is ^ .. ^?V?", First_Bit
(CC
), Comp
);
691 Set_Component_Bit_Offset
(Comp
, Pos
* SSU
+ NFB
);
692 Set_Normalized_First_Bit
(Comp
, NFB
mod SSU
);
699 end Adjust_Record_For_Reverse_Bit_Order
;
701 -------------------------------------
702 -- Alignment_Check_For_Size_Change --
703 -------------------------------------
705 procedure Alignment_Check_For_Size_Change
(Typ
: Entity_Id
; Size
: Uint
) is
707 -- If the alignment is known, and not set by a rep clause, and is
708 -- inconsistent with the size being set, then reset it to unknown,
709 -- we assume in this case that the size overrides the inherited
710 -- alignment, and that the alignment must be recomputed.
712 if Known_Alignment
(Typ
)
713 and then not Has_Alignment_Clause
(Typ
)
714 and then Size
mod (Alignment
(Typ
) * SSU
) /= 0
716 Init_Alignment
(Typ
);
718 end Alignment_Check_For_Size_Change
;
720 -------------------------------------
721 -- Analyze_Aspects_At_Freeze_Point --
722 -------------------------------------
724 procedure Analyze_Aspects_At_Freeze_Point
(E
: Entity_Id
) is
729 procedure Analyze_Aspect_Default_Value
(ASN
: Node_Id
);
730 -- This routine analyzes an Aspect_Default_[Component_]Value denoted by
731 -- the aspect specification node ASN.
733 procedure Inherit_Delayed_Rep_Aspects
(ASN
: Node_Id
);
734 -- As discussed in the spec of Aspects (see Aspect_Delay declaration),
735 -- a derived type can inherit aspects from its parent which have been
736 -- specified at the time of the derivation using an aspect, as in:
738 -- type A is range 1 .. 10
739 -- with Size => Not_Defined_Yet;
743 -- Not_Defined_Yet : constant := 64;
745 -- In this example, the Size of A is considered to be specified prior
746 -- to the derivation, and thus inherited, even though the value is not
747 -- known at the time of derivation. To deal with this, we use two entity
748 -- flags. The flag Has_Derived_Rep_Aspects is set in the parent type (A
749 -- here), and then the flag May_Inherit_Delayed_Rep_Aspects is set in
750 -- the derived type (B here). If this flag is set when the derived type
751 -- is frozen, then this procedure is called to ensure proper inheritance
752 -- of all delayed aspects from the parent type. The derived type is E,
753 -- the argument to Analyze_Aspects_At_Freeze_Point. ASN is the first
754 -- aspect specification node in the Rep_Item chain for the parent type.
756 procedure Make_Pragma_From_Boolean_Aspect
(ASN
: Node_Id
);
757 -- Given an aspect specification node ASN whose expression is an
758 -- optional Boolean, this routines creates the corresponding pragma
759 -- at the freezing point.
761 ----------------------------------
762 -- Analyze_Aspect_Default_Value --
763 ----------------------------------
765 procedure Analyze_Aspect_Default_Value
(ASN
: Node_Id
) is
766 Ent
: constant Entity_Id
:= Entity
(ASN
);
767 Expr
: constant Node_Id
:= Expression
(ASN
);
768 Id
: constant Node_Id
:= Identifier
(ASN
);
771 Error_Msg_Name_1
:= Chars
(Id
);
773 if not Is_Type
(Ent
) then
774 Error_Msg_N
("aspect% can only apply to a type", Id
);
777 elsif not Is_First_Subtype
(Ent
) then
778 Error_Msg_N
("aspect% cannot apply to subtype", Id
);
781 elsif A_Id
= Aspect_Default_Value
782 and then not Is_Scalar_Type
(Ent
)
784 Error_Msg_N
("aspect% can only be applied to scalar type", Id
);
787 elsif A_Id
= Aspect_Default_Component_Value
then
788 if not Is_Array_Type
(Ent
) then
789 Error_Msg_N
("aspect% can only be applied to array type", Id
);
792 elsif not Is_Scalar_Type
(Component_Type
(Ent
)) then
793 Error_Msg_N
("aspect% requires scalar components", Id
);
798 Set_Has_Default_Aspect
(Base_Type
(Ent
));
800 if Is_Scalar_Type
(Ent
) then
801 Set_Default_Aspect_Value
(Base_Type
(Ent
), Expr
);
803 Set_Default_Aspect_Component_Value
(Base_Type
(Ent
), Expr
);
805 end Analyze_Aspect_Default_Value
;
807 ---------------------------------
808 -- Inherit_Delayed_Rep_Aspects --
809 ---------------------------------
811 procedure Inherit_Delayed_Rep_Aspects
(ASN
: Node_Id
) is
812 P
: constant Entity_Id
:= Entity
(ASN
);
813 -- Entithy for parent type
816 -- Item from Rep_Item chain
821 -- Loop through delayed aspects for the parent type
824 while Present
(N
) loop
825 if Nkind
(N
) = N_Aspect_Specification
then
826 exit when Entity
(N
) /= P
;
828 if Is_Delayed_Aspect
(N
) then
829 A
:= Get_Aspect_Id
(Chars
(Identifier
(N
)));
831 -- Process delayed rep aspect. For Boolean attributes it is
832 -- not possible to cancel an attribute once set (the attempt
833 -- to use an aspect with xxx => False is an error) for a
834 -- derived type. So for those cases, we do not have to check
835 -- if a clause has been given for the derived type, since it
836 -- is harmless to set it again if it is already set.
842 when Aspect_Alignment
=>
843 if not Has_Alignment_Clause
(E
) then
844 Set_Alignment
(E
, Alignment
(P
));
849 when Aspect_Atomic
=>
850 if Is_Atomic
(P
) then
856 when Aspect_Atomic_Components
=>
857 if Has_Atomic_Components
(P
) then
858 Set_Has_Atomic_Components
(Base_Type
(E
));
863 when Aspect_Bit_Order
=>
864 if Is_Record_Type
(E
)
865 and then No
(Get_Attribute_Definition_Clause
866 (E
, Attribute_Bit_Order
))
867 and then Reverse_Bit_Order
(P
)
869 Set_Reverse_Bit_Order
(Base_Type
(E
));
874 when Aspect_Component_Size
=>
876 and then not Has_Component_Size_Clause
(E
)
879 (Base_Type
(E
), Component_Size
(P
));
884 when Aspect_Machine_Radix
=>
885 if Is_Decimal_Fixed_Point_Type
(E
)
886 and then not Has_Machine_Radix_Clause
(E
)
888 Set_Machine_Radix_10
(E
, Machine_Radix_10
(P
));
891 -- Object_Size (also Size which also sets Object_Size)
893 when Aspect_Object_Size | Aspect_Size
=>
894 if not Has_Size_Clause
(E
)
896 No
(Get_Attribute_Definition_Clause
897 (E
, Attribute_Object_Size
))
899 Set_Esize
(E
, Esize
(P
));
905 if not Is_Packed
(E
) then
906 Set_Is_Packed
(Base_Type
(E
));
908 if Is_Bit_Packed_Array
(P
) then
909 Set_Is_Bit_Packed_Array
(Base_Type
(E
));
910 Set_Packed_Array_Impl_Type
911 (E
, Packed_Array_Impl_Type
(P
));
915 -- Scalar_Storage_Order
917 when Aspect_Scalar_Storage_Order
=>
918 if (Is_Record_Type
(E
) or else Is_Array_Type
(E
))
919 and then No
(Get_Attribute_Definition_Clause
920 (E
, Attribute_Scalar_Storage_Order
))
921 and then Reverse_Storage_Order
(P
)
923 Set_Reverse_Storage_Order
(Base_Type
(E
));
925 -- Clear default SSO indications, since the aspect
926 -- overrides the default.
928 Set_SSO_Set_Low_By_Default
(Base_Type
(E
), False);
929 Set_SSO_Set_High_By_Default
(Base_Type
(E
), False);
935 if Is_Fixed_Point_Type
(E
)
936 and then not Has_Small_Clause
(E
)
938 Set_Small_Value
(E
, Small_Value
(P
));
943 when Aspect_Storage_Size
=>
944 if (Is_Access_Type
(E
) or else Is_Task_Type
(E
))
945 and then not Has_Storage_Size_Clause
(E
)
947 Set_Storage_Size_Variable
948 (Base_Type
(E
), Storage_Size_Variable
(P
));
953 when Aspect_Value_Size
=>
955 -- Value_Size is never inherited, it is either set by
956 -- default, or it is explicitly set for the derived
957 -- type. So nothing to do here.
963 when Aspect_Volatile
=>
964 if Is_Volatile
(P
) then
968 -- Volatile_Components
970 when Aspect_Volatile_Components
=>
971 if Has_Volatile_Components
(P
) then
972 Set_Has_Volatile_Components
(Base_Type
(E
));
975 -- That should be all the Rep Aspects
978 pragma Assert
(Aspect_Delay
(A_Id
) /= Rep_Aspect
);
985 N
:= Next_Rep_Item
(N
);
987 end Inherit_Delayed_Rep_Aspects
;
989 -------------------------------------
990 -- Make_Pragma_From_Boolean_Aspect --
991 -------------------------------------
993 procedure Make_Pragma_From_Boolean_Aspect
(ASN
: Node_Id
) is
994 Ident
: constant Node_Id
:= Identifier
(ASN
);
995 A_Name
: constant Name_Id
:= Chars
(Ident
);
996 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(A_Name
);
997 Ent
: constant Entity_Id
:= Entity
(ASN
);
998 Expr
: constant Node_Id
:= Expression
(ASN
);
999 Loc
: constant Source_Ptr
:= Sloc
(ASN
);
1003 procedure Check_False_Aspect_For_Derived_Type
;
1004 -- This procedure checks for the case of a false aspect for a derived
1005 -- type, which improperly tries to cancel an aspect inherited from
1008 -----------------------------------------
1009 -- Check_False_Aspect_For_Derived_Type --
1010 -----------------------------------------
1012 procedure Check_False_Aspect_For_Derived_Type
is
1016 -- We are only checking derived types
1018 if not Is_Derived_Type
(E
) then
1022 Par
:= Nearest_Ancestor
(E
);
1025 when Aspect_Atomic | Aspect_Shared
=>
1026 if not Is_Atomic
(Par
) then
1030 when Aspect_Atomic_Components
=>
1031 if not Has_Atomic_Components
(Par
) then
1035 when Aspect_Discard_Names
=>
1036 if not Discard_Names
(Par
) then
1041 if not Is_Packed
(Par
) then
1045 when Aspect_Unchecked_Union
=>
1046 if not Is_Unchecked_Union
(Par
) then
1050 when Aspect_Volatile
=>
1051 if not Is_Volatile
(Par
) then
1055 when Aspect_Volatile_Components
=>
1056 if not Has_Volatile_Components
(Par
) then
1064 -- Fall through means we are canceling an inherited aspect
1066 Error_Msg_Name_1
:= A_Name
;
1068 ("derived type& inherits aspect%, cannot cancel", Expr
, E
);
1070 end Check_False_Aspect_For_Derived_Type
;
1072 -- Start of processing for Make_Pragma_From_Boolean_Aspect
1075 -- Note that we know Expr is present, because for a missing Expr
1076 -- argument, we knew it was True and did not need to delay the
1077 -- evaluation to the freeze point.
1079 if Is_False
(Static_Boolean
(Expr
)) then
1080 Check_False_Aspect_For_Derived_Type
;
1085 Pragma_Argument_Associations
=> New_List
(
1086 Make_Pragma_Argument_Association
(Sloc
(Ident
),
1087 Expression
=> New_Occurrence_Of
(Ent
, Sloc
(Ident
)))),
1089 Pragma_Identifier
=>
1090 Make_Identifier
(Sloc
(Ident
), Chars
(Ident
)));
1092 Set_From_Aspect_Specification
(Prag
, True);
1093 Set_Corresponding_Aspect
(Prag
, ASN
);
1094 Set_Aspect_Rep_Item
(ASN
, Prag
);
1095 Set_Is_Delayed_Aspect
(Prag
);
1096 Set_Parent
(Prag
, ASN
);
1098 end Make_Pragma_From_Boolean_Aspect
;
1100 -- Start of processing for Analyze_Aspects_At_Freeze_Point
1103 -- Must be visible in current scope
1105 if not Scope_Within_Or_Same
(Current_Scope
, Scope
(E
)) then
1109 -- Look for aspect specification entries for this entity
1111 ASN
:= First_Rep_Item
(E
);
1112 while Present
(ASN
) loop
1113 if Nkind
(ASN
) = N_Aspect_Specification
then
1114 exit when Entity
(ASN
) /= E
;
1116 if Is_Delayed_Aspect
(ASN
) then
1117 A_Id
:= Get_Aspect_Id
(ASN
);
1121 -- For aspects whose expression is an optional Boolean, make
1122 -- the corresponding pragma at the 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
=>
1133 Analyze_Aspect_Default_Value
(ASN
);
1135 -- Ditto for iterator aspects, because the corresponding
1136 -- attributes may not have been analyzed yet.
1138 when Aspect_Constant_Indexing |
1139 Aspect_Variable_Indexing |
1140 Aspect_Default_Iterator |
1141 Aspect_Iterator_Element
=>
1142 Analyze
(Expression
(ASN
));
1144 if Etype
(Expression
(ASN
)) = Any_Type
then
1146 ("\aspect must be fully defined before & is frozen",
1150 when Aspect_Iterable
=>
1151 Validate_Iterable_Aspect
(E
, ASN
);
1157 Ritem
:= Aspect_Rep_Item
(ASN
);
1159 if Present
(Ritem
) then
1165 Next_Rep_Item
(ASN
);
1168 -- This is where we inherit delayed rep aspects from our parent. Note
1169 -- that if we fell out of the above loop with ASN non-empty, it means
1170 -- we hit an aspect for an entity other than E, and it must be the
1171 -- type from which we were derived.
1173 if May_Inherit_Delayed_Rep_Aspects
(E
) then
1174 Inherit_Delayed_Rep_Aspects
(ASN
);
1176 end Analyze_Aspects_At_Freeze_Point
;
1178 -----------------------------------
1179 -- Analyze_Aspect_Specifications --
1180 -----------------------------------
1182 procedure Analyze_Aspect_Specifications
(N
: Node_Id
; E
: Entity_Id
) is
1183 procedure Decorate
(Asp
: Node_Id
; Prag
: Node_Id
);
1184 -- Establish linkages between an aspect and its corresponding
1187 procedure Insert_After_SPARK_Mode
1191 -- Subsidiary to the analysis of aspects Abstract_State, Ghost,
1192 -- Initializes, Initial_Condition and Refined_State. Insert node Prag
1193 -- before node Ins_Nod. If Ins_Nod is for pragma SPARK_Mode, then skip
1194 -- SPARK_Mode. Decls is the associated declarative list where Prag is to
1197 procedure Insert_Pragma
(Prag
: Node_Id
);
1198 -- Subsidiary to the analysis of aspects Attach_Handler, Contract_Cases,
1199 -- Depends, Global, Post, Pre, Refined_Depends and Refined_Global.
1200 -- Insert pragma Prag such that it mimics the placement of a source
1201 -- pragma of the same kind.
1203 -- procedure Proc (Formal : ...) with Global => ...;
1205 -- procedure Proc (Formal : ...);
1206 -- pragma Global (...);
1212 procedure Decorate
(Asp
: Node_Id
; Prag
: Node_Id
) is
1214 Set_Aspect_Rep_Item
(Asp
, Prag
);
1215 Set_Corresponding_Aspect
(Prag
, Asp
);
1216 Set_From_Aspect_Specification
(Prag
);
1217 Set_Parent
(Prag
, Asp
);
1220 -----------------------------
1221 -- Insert_After_SPARK_Mode --
1222 -----------------------------
1224 procedure Insert_After_SPARK_Mode
1229 Decl
: Node_Id
:= Ins_Nod
;
1235 and then Nkind
(Decl
) = N_Pragma
1236 and then Pragma_Name
(Decl
) = Name_SPARK_Mode
1238 Decl
:= Next
(Decl
);
1241 if Present
(Decl
) then
1242 Insert_Before
(Decl
, Prag
);
1244 -- Aitem acts as the last declaration
1247 Append_To
(Decls
, Prag
);
1249 end Insert_After_SPARK_Mode
;
1255 procedure Insert_Pragma
(Prag
: Node_Id
) is
1260 -- When the context is a library unit, the pragma is added to the
1261 -- Pragmas_After list.
1263 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
1264 Aux
:= Aux_Decls_Node
(Parent
(N
));
1266 if No
(Pragmas_After
(Aux
)) then
1267 Set_Pragmas_After
(Aux
, New_List
);
1270 Prepend
(Prag
, Pragmas_After
(Aux
));
1272 -- Pragmas associated with subprogram bodies are inserted in the
1273 -- declarative part.
1275 elsif Nkind
(N
) = N_Subprogram_Body
then
1276 if Present
(Declarations
(N
)) then
1278 -- Skip other internally generated pragmas from aspects to find
1279 -- the proper insertion point. As a result the order of pragmas
1280 -- is the same as the order of aspects.
1282 -- As precondition pragmas generated from conjuncts in the
1283 -- precondition aspect are presented in reverse order to
1284 -- Insert_Pragma, insert them in the correct order here by not
1285 -- skipping previously inserted precondition pragmas when the
1286 -- current pragma is a precondition.
1288 Decl
:= First
(Declarations
(N
));
1289 while Present
(Decl
) loop
1290 if Nkind
(Decl
) = N_Pragma
1291 and then From_Aspect_Specification
(Decl
)
1292 and then not (Get_Pragma_Id
(Decl
) = Pragma_Precondition
1294 Get_Pragma_Id
(Prag
) = Pragma_Precondition
)
1302 if Present
(Decl
) then
1303 Insert_Before
(Decl
, Prag
);
1305 Append
(Prag
, Declarations
(N
));
1308 Set_Declarations
(N
, New_List
(Prag
));
1314 Insert_After
(N
, Prag
);
1324 L
: constant List_Id
:= Aspect_Specifications
(N
);
1326 Ins_Node
: Node_Id
:= N
;
1327 -- Insert pragmas/attribute definition clause after this node when no
1328 -- delayed analysis is required.
1330 -- Start of processing for Analyze_Aspect_Specifications
1332 -- The general processing involves building an attribute definition
1333 -- clause or a pragma node that corresponds to the aspect. Then in order
1334 -- to delay the evaluation of this aspect to the freeze point, we attach
1335 -- the corresponding pragma/attribute definition clause to the aspect
1336 -- specification node, which is then placed in the Rep Item chain. In
1337 -- this case we mark the entity by setting the flag Has_Delayed_Aspects
1338 -- and we evaluate the rep item at the freeze point. When the aspect
1339 -- doesn't have a corresponding pragma/attribute definition clause, then
1340 -- its analysis is simply delayed at the freeze point.
1342 -- Some special cases don't require delay analysis, thus the aspect is
1343 -- analyzed right now.
1345 -- Note that there is a special handling for Pre, Post, Test_Case,
1346 -- Contract_Cases aspects. In these cases, we do not have to worry
1347 -- about delay issues, since the pragmas themselves deal with delay
1348 -- of visibility for the expression analysis. Thus, we just insert
1349 -- the pragma after the node N.
1352 pragma Assert
(Present
(L
));
1354 -- Loop through aspects
1356 Aspect
:= First
(L
);
1357 Aspect_Loop
: while Present
(Aspect
) loop
1358 Analyze_One_Aspect
: declare
1359 Expr
: constant Node_Id
:= Expression
(Aspect
);
1360 Id
: constant Node_Id
:= Identifier
(Aspect
);
1361 Loc
: constant Source_Ptr
:= Sloc
(Aspect
);
1362 Nam
: constant Name_Id
:= Chars
(Id
);
1363 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Nam
);
1366 Delay_Required
: Boolean;
1367 -- Set False if delay is not required
1369 Eloc
: Source_Ptr
:= No_Location
;
1370 -- Source location of expression, modified when we split PPC's. It
1371 -- is set below when Expr is present.
1373 procedure Analyze_Aspect_External_Or_Link_Name
;
1374 -- Perform analysis of the External_Name or Link_Name aspects
1376 procedure Analyze_Aspect_Implicit_Dereference
;
1377 -- Perform analysis of the Implicit_Dereference aspects
1379 procedure Make_Aitem_Pragma
1380 (Pragma_Argument_Associations
: List_Id
;
1381 Pragma_Name
: Name_Id
);
1382 -- This is a wrapper for Make_Pragma used for converting aspects
1383 -- to pragmas. It takes care of Sloc (set from Loc) and building
1384 -- the pragma identifier from the given name. In addition the
1385 -- flags Class_Present and Split_PPC are set from the aspect
1386 -- node, as well as Is_Ignored. This routine also sets the
1387 -- From_Aspect_Specification in the resulting pragma node to
1388 -- True, and sets Corresponding_Aspect to point to the aspect.
1389 -- The resulting pragma is assigned to Aitem.
1391 ------------------------------------------
1392 -- Analyze_Aspect_External_Or_Link_Name --
1393 ------------------------------------------
1395 procedure Analyze_Aspect_External_Or_Link_Name
is
1397 -- Verify that there is an Import/Export aspect defined for the
1398 -- entity. The processing of that aspect in turn checks that
1399 -- there is a Convention aspect declared. The pragma is
1400 -- constructed when processing the Convention aspect.
1407 while Present
(A
) loop
1408 exit when Nam_In
(Chars
(Identifier
(A
)), Name_Export
,
1415 ("missing Import/Export for Link/External name",
1419 end Analyze_Aspect_External_Or_Link_Name
;
1421 -----------------------------------------
1422 -- Analyze_Aspect_Implicit_Dereference --
1423 -----------------------------------------
1425 procedure Analyze_Aspect_Implicit_Dereference
is
1427 if not Is_Type
(E
) or else not Has_Discriminants
(E
) then
1429 ("aspect must apply to a type with discriminants", N
);
1436 Disc
:= First_Discriminant
(E
);
1437 while Present
(Disc
) loop
1438 if Chars
(Expr
) = Chars
(Disc
)
1439 and then Ekind
(Etype
(Disc
)) =
1440 E_Anonymous_Access_Type
1442 Set_Has_Implicit_Dereference
(E
);
1443 Set_Has_Implicit_Dereference
(Disc
);
1447 Next_Discriminant
(Disc
);
1450 -- Error if no proper access discriminant.
1453 ("not an access discriminant of&", Expr
, E
);
1456 end Analyze_Aspect_Implicit_Dereference
;
1458 -----------------------
1459 -- Make_Aitem_Pragma --
1460 -----------------------
1462 procedure Make_Aitem_Pragma
1463 (Pragma_Argument_Associations
: List_Id
;
1464 Pragma_Name
: Name_Id
)
1466 Args
: List_Id
:= Pragma_Argument_Associations
;
1469 -- We should never get here if aspect was disabled
1471 pragma Assert
(not Is_Disabled
(Aspect
));
1473 -- Certain aspects allow for an optional name or expression. Do
1474 -- not generate a pragma with empty argument association list.
1476 if No
(Args
) or else No
(Expression
(First
(Args
))) then
1484 Pragma_Argument_Associations
=> Args
,
1485 Pragma_Identifier
=>
1486 Make_Identifier
(Sloc
(Id
), Pragma_Name
),
1487 Class_Present
=> Class_Present
(Aspect
),
1488 Split_PPC
=> Split_PPC
(Aspect
));
1490 -- Set additional semantic fields
1492 if Is_Ignored
(Aspect
) then
1493 Set_Is_Ignored
(Aitem
);
1494 elsif Is_Checked
(Aspect
) then
1495 Set_Is_Checked
(Aitem
);
1498 Set_Corresponding_Aspect
(Aitem
, Aspect
);
1499 Set_From_Aspect_Specification
(Aitem
, True);
1500 end Make_Aitem_Pragma
;
1502 -- Start of processing for Analyze_One_Aspect
1505 -- Skip aspect if already analyzed, to avoid looping in some cases
1507 if Analyzed
(Aspect
) then
1511 -- Skip looking at aspect if it is totally disabled. Just mark it
1512 -- as such for later reference in the tree. This also sets the
1513 -- Is_Ignored and Is_Checked flags appropriately.
1515 Check_Applicable_Policy
(Aspect
);
1517 if Is_Disabled
(Aspect
) then
1521 -- Set the source location of expression, used in the case of
1522 -- a failed precondition/postcondition or invariant. Note that
1523 -- the source location of the expression is not usually the best
1524 -- choice here. For example, it gets located on the last AND
1525 -- keyword in a chain of boolean expressiond AND'ed together.
1526 -- It is best to put the message on the first character of the
1527 -- assertion, which is the effect of the First_Node call here.
1529 if Present
(Expr
) then
1530 Eloc
:= Sloc
(First_Node
(Expr
));
1533 -- Check restriction No_Implementation_Aspect_Specifications
1535 if Implementation_Defined_Aspect
(A_Id
) then
1537 (No_Implementation_Aspect_Specifications
, Aspect
);
1540 -- Check restriction No_Specification_Of_Aspect
1542 Check_Restriction_No_Specification_Of_Aspect
(Aspect
);
1544 -- Mark aspect analyzed (actual analysis is delayed till later)
1546 Set_Analyzed
(Aspect
);
1547 Set_Entity
(Aspect
, E
);
1548 Ent
:= New_Occurrence_Of
(E
, Sloc
(Id
));
1550 -- Check for duplicate aspect. Note that the Comes_From_Source
1551 -- test allows duplicate Pre/Post's that we generate internally
1552 -- to escape being flagged here.
1554 if No_Duplicates_Allowed
(A_Id
) then
1556 while Anod
/= Aspect
loop
1557 if Comes_From_Source
(Aspect
)
1558 and then Same_Aspect
(A_Id
, Get_Aspect_Id
(Anod
))
1560 Error_Msg_Name_1
:= Nam
;
1561 Error_Msg_Sloc
:= Sloc
(Anod
);
1563 -- Case of same aspect specified twice
1565 if Class_Present
(Anod
) = Class_Present
(Aspect
) then
1566 if not Class_Present
(Anod
) then
1568 ("aspect% for & previously given#",
1572 ("aspect `%''Class` for & previously given#",
1582 -- Check some general restrictions on language defined aspects
1584 if not Implementation_Defined_Aspect
(A_Id
) then
1585 Error_Msg_Name_1
:= Nam
;
1587 -- Not allowed for renaming declarations
1589 if Nkind
(N
) in N_Renaming_Declaration
then
1591 ("aspect % not allowed for renaming declaration",
1595 -- Not allowed for formal type declarations
1597 if Nkind
(N
) = N_Formal_Type_Declaration
then
1599 ("aspect % not allowed for formal type declaration",
1604 -- Copy expression for later processing by the procedures
1605 -- Check_Aspect_At_[Freeze_Point | End_Of_Declarations]
1607 Set_Entity
(Id
, New_Copy_Tree
(Expr
));
1609 -- Set Delay_Required as appropriate to aspect
1611 case Aspect_Delay
(A_Id
) is
1612 when Always_Delay
=>
1613 Delay_Required
:= True;
1616 Delay_Required
:= False;
1620 -- If expression has the form of an integer literal, then
1621 -- do not delay, since we know the value cannot change.
1622 -- This optimization catches most rep clause cases.
1624 if (Present
(Expr
) and then Nkind
(Expr
) = N_Integer_Literal
)
1625 or else (A_Id
in Boolean_Aspects
and then No
(Expr
))
1627 Delay_Required
:= False;
1629 Delay_Required
:= True;
1630 Set_Has_Delayed_Rep_Aspects
(E
);
1634 -- Processing based on specific aspect
1638 -- No_Aspect should be impossible
1641 raise Program_Error
;
1643 -- Case 1: Aspects corresponding to attribute definition
1646 when Aspect_Address |
1649 Aspect_Component_Size |
1650 Aspect_Constant_Indexing |
1651 Aspect_Default_Iterator |
1652 Aspect_Dispatching_Domain |
1653 Aspect_External_Tag |
1656 Aspect_Iterator_Element |
1657 Aspect_Machine_Radix |
1658 Aspect_Object_Size |
1661 Aspect_Scalar_Storage_Order |
1664 Aspect_Simple_Storage_Pool |
1665 Aspect_Storage_Pool |
1666 Aspect_Stream_Size |
1668 Aspect_Variable_Indexing |
1671 -- Indexing aspects apply only to tagged type
1673 if (A_Id
= Aspect_Constant_Indexing
1675 A_Id
= Aspect_Variable_Indexing
)
1676 and then not (Is_Type
(E
)
1677 and then Is_Tagged_Type
(E
))
1680 ("indexing aspect can only apply to a tagged type",
1685 -- For the case of aspect Address, we don't consider that we
1686 -- know the entity is never set in the source, since it is
1687 -- is likely aliasing is occurring.
1689 -- Note: one might think that the analysis of the resulting
1690 -- attribute definition clause would take care of that, but
1691 -- that's not the case since it won't be from source.
1693 if A_Id
= Aspect_Address
then
1694 Set_Never_Set_In_Source
(E
, False);
1697 -- Correctness of the profile of a stream operation is
1698 -- verified at the freeze point, but we must detect the
1699 -- illegal specification of this aspect for a subtype now,
1700 -- to prevent malformed rep_item chains.
1702 if (A_Id
= Aspect_Input
or else
1703 A_Id
= Aspect_Output
or else
1704 A_Id
= Aspect_Read
or else
1705 A_Id
= Aspect_Write
)
1706 and not Is_First_Subtype
(E
)
1709 ("local name must be a first subtype", Aspect
);
1713 -- Construct the attribute definition clause
1716 Make_Attribute_Definition_Clause
(Loc
,
1718 Chars
=> Chars
(Id
),
1719 Expression
=> Relocate_Node
(Expr
));
1721 -- If the address is specified, then we treat the entity as
1722 -- referenced, to avoid spurious warnings. This is analogous
1723 -- to what is done with an attribute definition clause, but
1724 -- here we don't want to generate a reference because this
1725 -- is the point of definition of the entity.
1727 if A_Id
= Aspect_Address
then
1731 -- Case 2: Aspects corresponding to pragmas
1733 -- Case 2a: Aspects corresponding to pragmas with two
1734 -- arguments, where the first argument is a local name
1735 -- referring to the entity, and the second argument is the
1736 -- aspect definition expression.
1738 -- Linker_Section/Suppress/Unsuppress
1740 when Aspect_Linker_Section |
1742 Aspect_Unsuppress
=>
1745 (Pragma_Argument_Associations
=> New_List
(
1746 Make_Pragma_Argument_Association
(Loc
,
1747 Expression
=> New_Occurrence_Of
(E
, Loc
)),
1748 Make_Pragma_Argument_Association
(Sloc
(Expr
),
1749 Expression
=> Relocate_Node
(Expr
))),
1750 Pragma_Name
=> Chars
(Id
));
1754 -- Corresponds to pragma Implemented, construct the pragma
1756 when Aspect_Synchronization
=>
1758 (Pragma_Argument_Associations
=> New_List
(
1759 Make_Pragma_Argument_Association
(Loc
,
1760 Expression
=> New_Occurrence_Of
(E
, Loc
)),
1761 Make_Pragma_Argument_Association
(Sloc
(Expr
),
1762 Expression
=> Relocate_Node
(Expr
))),
1763 Pragma_Name
=> Name_Implemented
);
1767 when Aspect_Attach_Handler
=>
1769 (Pragma_Argument_Associations
=> New_List
(
1770 Make_Pragma_Argument_Association
(Sloc
(Ent
),
1772 Make_Pragma_Argument_Association
(Sloc
(Expr
),
1773 Expression
=> Relocate_Node
(Expr
))),
1774 Pragma_Name
=> Name_Attach_Handler
);
1776 -- We need to insert this pragma into the tree to get proper
1777 -- processing and to look valid from a placement viewpoint.
1779 Insert_Pragma
(Aitem
);
1782 -- Dynamic_Predicate, Predicate, Static_Predicate
1784 when Aspect_Dynamic_Predicate |
1786 Aspect_Static_Predicate
=>
1788 -- These aspects apply only to subtypes
1790 if not Is_Type
(E
) then
1792 ("predicate can only be specified for a subtype",
1796 elsif Is_Incomplete_Type
(E
) then
1798 ("predicate cannot apply to incomplete view", Aspect
);
1802 -- Construct the pragma (always a pragma Predicate, with
1803 -- flags recording whether it is static/dynamic). We also
1804 -- set flags recording this in the type itself.
1807 (Pragma_Argument_Associations
=> New_List
(
1808 Make_Pragma_Argument_Association
(Sloc
(Ent
),
1810 Make_Pragma_Argument_Association
(Sloc
(Expr
),
1811 Expression
=> Relocate_Node
(Expr
))),
1812 Pragma_Name
=> Name_Predicate
);
1814 -- Mark type has predicates, and remember what kind of
1815 -- aspect lead to this predicate (we need this to access
1816 -- the right set of check policies later on).
1818 Set_Has_Predicates
(E
);
1820 if A_Id
= Aspect_Dynamic_Predicate
then
1821 Set_Has_Dynamic_Predicate_Aspect
(E
);
1822 elsif A_Id
= Aspect_Static_Predicate
then
1823 Set_Has_Static_Predicate_Aspect
(E
);
1826 -- If the type is private, indicate that its completion
1827 -- has a freeze node, because that is the one that will
1828 -- be visible at freeze time.
1830 if Is_Private_Type
(E
) and then Present
(Full_View
(E
)) then
1831 Set_Has_Predicates
(Full_View
(E
));
1833 if A_Id
= Aspect_Dynamic_Predicate
then
1834 Set_Has_Dynamic_Predicate_Aspect
(Full_View
(E
));
1835 elsif A_Id
= Aspect_Static_Predicate
then
1836 Set_Has_Static_Predicate_Aspect
(Full_View
(E
));
1839 Set_Has_Delayed_Aspects
(Full_View
(E
));
1840 Ensure_Freeze_Node
(Full_View
(E
));
1843 -- Case 2b: Aspects corresponding to pragmas with two
1844 -- arguments, where the second argument is a local name
1845 -- referring to the entity, and the first argument is the
1846 -- aspect definition expression.
1850 when Aspect_Convention
=>
1852 -- The aspect may be part of the specification of an import
1853 -- or export pragma. Scan the aspect list to gather the
1854 -- other components, if any. The name of the generated
1855 -- pragma is one of Convention/Import/Export.
1858 Args
: constant List_Id
:= New_List
(
1859 Make_Pragma_Argument_Association
(Sloc
(Expr
),
1860 Expression
=> Relocate_Node
(Expr
)),
1861 Make_Pragma_Argument_Association
(Sloc
(Ent
),
1862 Expression
=> Ent
));
1864 Imp_Exp_Seen
: Boolean := False;
1865 -- Flag set when aspect Import or Export has been seen
1867 Imp_Seen
: Boolean := False;
1868 -- Flag set when aspect Import has been seen
1872 Extern_Arg
: Node_Id
;
1877 Extern_Arg
:= Empty
;
1879 Prag_Nam
:= Chars
(Id
);
1882 while Present
(Asp
) loop
1883 Asp_Nam
:= Chars
(Identifier
(Asp
));
1885 -- Aspects Import and Export take precedence over
1886 -- aspect Convention. As a result the generated pragma
1887 -- must carry the proper interfacing aspect's name.
1889 if Nam_In
(Asp_Nam
, Name_Import
, Name_Export
) then
1890 if Imp_Exp_Seen
then
1891 Error_Msg_N
("conflicting", Asp
);
1893 Imp_Exp_Seen
:= True;
1895 if Asp_Nam
= Name_Import
then
1900 Prag_Nam
:= Asp_Nam
;
1902 -- Aspect External_Name adds an extra argument to the
1903 -- generated pragma.
1905 elsif Asp_Nam
= Name_External_Name
then
1907 Make_Pragma_Argument_Association
(Loc
,
1909 Expression
=> Relocate_Node
(Expression
(Asp
)));
1911 -- Aspect Link_Name adds an extra argument to the
1912 -- generated pragma.
1914 elsif Asp_Nam
= Name_Link_Name
then
1916 Make_Pragma_Argument_Association
(Loc
,
1918 Expression
=> Relocate_Node
(Expression
(Asp
)));
1924 -- Assemble the full argument list
1926 if Present
(Extern_Arg
) then
1927 Append_To
(Args
, Extern_Arg
);
1930 if Present
(Link_Arg
) then
1931 Append_To
(Args
, Link_Arg
);
1935 (Pragma_Argument_Associations
=> Args
,
1936 Pragma_Name
=> Prag_Nam
);
1938 -- Store the generated pragma Import in the related
1941 if Imp_Seen
and then Is_Subprogram
(E
) then
1942 Set_Import_Pragma
(E
, Aitem
);
1946 -- CPU, Interrupt_Priority, Priority
1948 -- These three aspects can be specified for a subprogram spec
1949 -- or body, in which case we analyze the expression and export
1950 -- the value of the aspect.
1952 -- Previously, we generated an equivalent pragma for bodies
1953 -- (note that the specs cannot contain these pragmas). The
1954 -- pragma was inserted ahead of local declarations, rather than
1955 -- after the body. This leads to a certain duplication between
1956 -- the processing performed for the aspect and the pragma, but
1957 -- given the straightforward handling required it is simpler
1958 -- to duplicate than to translate the aspect in the spec into
1959 -- a pragma in the declarative part of the body.
1962 Aspect_Interrupt_Priority |
1965 if Nkind_In
(N
, N_Subprogram_Body
,
1966 N_Subprogram_Declaration
)
1968 -- Analyze the aspect expression
1970 Analyze_And_Resolve
(Expr
, Standard_Integer
);
1972 -- Interrupt_Priority aspect not allowed for main
1973 -- subprograms. ARM D.1 does not forbid this explicitly,
1974 -- but ARM J.15.11 (6/3) does not permit pragma
1975 -- Interrupt_Priority for subprograms.
1977 if A_Id
= Aspect_Interrupt_Priority
then
1979 ("Interrupt_Priority aspect cannot apply to "
1980 & "subprogram", Expr
);
1982 -- The expression must be static
1984 elsif not Is_OK_Static_Expression
(Expr
) then
1985 Flag_Non_Static_Expr
1986 ("aspect requires static expression!", Expr
);
1988 -- Check whether this is the main subprogram. Issue a
1989 -- warning only if it is obviously not a main program
1990 -- (when it has parameters or when the subprogram is
1991 -- within a package).
1993 elsif Present
(Parameter_Specifications
1994 (Specification
(N
)))
1995 or else not Is_Compilation_Unit
(Defining_Entity
(N
))
1997 -- See ARM D.1 (14/3) and D.16 (12/3)
2000 ("aspect applied to subprogram other than the "
2001 & "main subprogram has no effect??", Expr
);
2003 -- Otherwise check in range and export the value
2005 -- For the CPU aspect
2007 elsif A_Id
= Aspect_CPU
then
2008 if Is_In_Range
(Expr
, RTE
(RE_CPU_Range
)) then
2010 -- Value is correct so we export the value to make
2011 -- it available at execution time.
2014 (Main_Unit
, UI_To_Int
(Expr_Value
(Expr
)));
2018 ("main subprogram CPU is out of range", Expr
);
2021 -- For the Priority aspect
2023 elsif A_Id
= Aspect_Priority
then
2024 if Is_In_Range
(Expr
, RTE
(RE_Priority
)) then
2026 -- Value is correct so we export the value to make
2027 -- it available at execution time.
2030 (Main_Unit
, UI_To_Int
(Expr_Value
(Expr
)));
2032 -- Ignore pragma if Relaxed_RM_Semantics to support
2033 -- other targets/non GNAT compilers.
2035 elsif not Relaxed_RM_Semantics
then
2037 ("main subprogram priority is out of range",
2042 -- Load an arbitrary entity from System.Tasking.Stages
2043 -- or System.Tasking.Restricted.Stages (depending on
2044 -- the supported profile) to make sure that one of these
2045 -- packages is implicitly with'ed, since we need to have
2046 -- the tasking run time active for the pragma Priority to
2047 -- have any effect. Previously we with'ed the package
2048 -- System.Tasking, but this package does not trigger the
2049 -- required initialization of the run-time library.
2052 Discard
: Entity_Id
;
2054 if Restricted_Profile
then
2055 Discard
:= RTE
(RE_Activate_Restricted_Tasks
);
2057 Discard
:= RTE
(RE_Activate_Tasks
);
2061 -- Handling for these Aspects in subprograms is complete
2068 -- Pass the aspect as an attribute
2071 Make_Attribute_Definition_Clause
(Loc
,
2073 Chars
=> Chars
(Id
),
2074 Expression
=> Relocate_Node
(Expr
));
2079 when Aspect_Warnings
=>
2081 (Pragma_Argument_Associations
=> New_List
(
2082 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2083 Expression
=> Relocate_Node
(Expr
)),
2084 Make_Pragma_Argument_Association
(Loc
,
2085 Expression
=> New_Occurrence_Of
(E
, Loc
))),
2086 Pragma_Name
=> Chars
(Id
));
2088 -- Case 2c: Aspects corresponding to pragmas with three
2091 -- Invariant aspects have a first argument that references the
2092 -- entity, a second argument that is the expression and a third
2093 -- argument that is an appropriate message.
2095 -- Invariant, Type_Invariant
2097 when Aspect_Invariant |
2098 Aspect_Type_Invariant
=>
2100 -- Analysis of the pragma will verify placement legality:
2101 -- an invariant must apply to a private type, or appear in
2102 -- the private part of a spec and apply to a completion.
2105 (Pragma_Argument_Associations
=> New_List
(
2106 Make_Pragma_Argument_Association
(Sloc
(Ent
),
2108 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2109 Expression
=> Relocate_Node
(Expr
))),
2110 Pragma_Name
=> Name_Invariant
);
2112 -- Add message unless exception messages are suppressed
2114 if not Opt
.Exception_Locations_Suppressed
then
2115 Append_To
(Pragma_Argument_Associations
(Aitem
),
2116 Make_Pragma_Argument_Association
(Eloc
,
2117 Chars
=> Name_Message
,
2119 Make_String_Literal
(Eloc
,
2120 Strval
=> "failed invariant from "
2121 & Build_Location_String
(Eloc
))));
2124 -- For Invariant case, insert immediately after the entity
2125 -- declaration. We do not have to worry about delay issues
2126 -- since the pragma processing takes care of this.
2128 Delay_Required
:= False;
2130 -- Case 2d : Aspects that correspond to a pragma with one
2135 -- Aspect Abstract_State introduces implicit declarations for
2136 -- all state abstraction entities it defines. To emulate this
2137 -- behavior, insert the pragma at the beginning of the visible
2138 -- declarations of the related package so that it is analyzed
2141 when Aspect_Abstract_State
=> Abstract_State
: declare
2142 Context
: Node_Id
:= N
;
2147 -- When aspect Abstract_State appears on a generic package,
2148 -- it is propageted to the package instance. The context in
2149 -- this case is the instance spec.
2151 if Nkind
(Context
) = N_Package_Instantiation
then
2152 Context
:= Instance_Spec
(Context
);
2155 if Nkind_In
(Context
, N_Generic_Package_Declaration
,
2156 N_Package_Declaration
)
2159 (Pragma_Argument_Associations
=> New_List
(
2160 Make_Pragma_Argument_Association
(Loc
,
2161 Expression
=> Relocate_Node
(Expr
))),
2162 Pragma_Name
=> Name_Abstract_State
);
2163 Decorate
(Aspect
, Aitem
);
2165 Decls
:= Visible_Declarations
(Specification
(Context
));
2167 -- In general pragma Abstract_State must be at the top
2168 -- of the existing visible declarations to emulate its
2169 -- source counterpart. The only exception to this is a
2170 -- generic instance in which case the pragma must be
2171 -- inserted after the association renamings.
2173 if Present
(Decls
) then
2174 Decl
:= First
(Decls
);
2176 -- The visible declarations of a generic instance have
2177 -- the following structure:
2179 -- <renamings of generic formals>
2180 -- <renamings of internally-generated spec and body>
2181 -- <first source declaration>
2183 -- The pragma must be inserted before the first source
2184 -- declaration, skip the instance "header".
2186 if Is_Generic_Instance
(Defining_Entity
(Context
)) then
2187 while Present
(Decl
)
2188 and then not Comes_From_Source
(Decl
)
2190 Decl
:= Next
(Decl
);
2194 -- When aspects Abstract_State, Ghost,
2195 -- Initial_Condition and Initializes are out of order,
2196 -- ensure that pragma SPARK_Mode is always at the top
2197 -- of the declarations to properly enabled/suppress
2200 Insert_After_SPARK_Mode
2205 -- Otherwise the pragma forms a new declarative list
2208 Set_Visible_Declarations
2209 (Specification
(Context
), New_List
(Aitem
));
2214 ("aspect & must apply to a package declaration",
2221 -- Aspect Default_Internal_Condition is never delayed because
2222 -- it is equivalent to a source pragma which appears after the
2223 -- related private type. To deal with forward references, the
2224 -- generated pragma is stored in the rep chain of the related
2225 -- private type as types do not carry contracts. The pragma is
2226 -- wrapped inside of a procedure at the freeze point of the
2227 -- private type's full view.
2229 when Aspect_Default_Initial_Condition
=>
2231 (Pragma_Argument_Associations
=> New_List
(
2232 Make_Pragma_Argument_Association
(Loc
,
2233 Expression
=> Relocate_Node
(Expr
))),
2235 Name_Default_Initial_Condition
);
2237 Decorate
(Aspect
, Aitem
);
2238 Insert_Pragma
(Aitem
);
2241 -- Default_Storage_Pool
2243 when Aspect_Default_Storage_Pool
=>
2245 (Pragma_Argument_Associations
=> New_List
(
2246 Make_Pragma_Argument_Association
(Loc
,
2247 Expression
=> Relocate_Node
(Expr
))),
2249 Name_Default_Storage_Pool
);
2251 Decorate
(Aspect
, Aitem
);
2252 Insert_Pragma
(Aitem
);
2257 -- Aspect Depends is never delayed because it is equivalent to
2258 -- a source pragma which appears after the related subprogram.
2259 -- To deal with forward references, the generated pragma is
2260 -- stored in the contract of the related subprogram and later
2261 -- analyzed at the end of the declarative region. See routine
2262 -- Analyze_Depends_In_Decl_Part for details.
2264 when Aspect_Depends
=>
2266 (Pragma_Argument_Associations
=> New_List
(
2267 Make_Pragma_Argument_Association
(Loc
,
2268 Expression
=> Relocate_Node
(Expr
))),
2269 Pragma_Name
=> Name_Depends
);
2271 Decorate
(Aspect
, Aitem
);
2272 Insert_Pragma
(Aitem
);
2275 -- Aspect Extensions_Visible is never delayed because it is
2276 -- equivalent to a source pragma which appears after the
2277 -- related subprogram.
2279 when Aspect_Extensions_Visible
=>
2281 (Pragma_Argument_Associations
=> New_List
(
2282 Make_Pragma_Argument_Association
(Loc
,
2283 Expression
=> Relocate_Node
(Expr
))),
2284 Pragma_Name
=> Name_Extensions_Visible
);
2286 Decorate
(Aspect
, Aitem
);
2287 Insert_Pragma
(Aitem
);
2290 -- Aspect Ghost is never delayed because it is equivalent to a
2291 -- source pragma which appears at the top of [generic] package
2292 -- declarations or after an object, a [generic] subprogram, or
2293 -- a type declaration.
2295 when Aspect_Ghost
=> Ghost
: declare
2300 (Pragma_Argument_Associations
=> New_List
(
2301 Make_Pragma_Argument_Association
(Loc
,
2302 Expression
=> Relocate_Node
(Expr
))),
2303 Pragma_Name
=> Name_Ghost
);
2305 Decorate
(Aspect
, Aitem
);
2307 -- When the aspect applies to a [generic] package, insert
2308 -- the pragma at the top of the visible declarations. This
2309 -- emulates the placement of a source pragma.
2311 if Nkind_In
(N
, N_Generic_Package_Declaration
,
2312 N_Package_Declaration
)
2314 Decls
:= Visible_Declarations
(Specification
(N
));
2318 Set_Visible_Declarations
(N
, Decls
);
2321 -- When aspects Abstract_State, Ghost, Initial_Condition
2322 -- and Initializes are out of order, ensure that pragma
2323 -- SPARK_Mode is always at the top of the declarations to
2324 -- properly enabled/suppress errors.
2326 Insert_After_SPARK_Mode
2328 Ins_Nod
=> First
(Decls
),
2331 -- Otherwise the context is an object, [generic] subprogram
2332 -- or type declaration.
2335 Insert_Pragma
(Aitem
);
2343 -- Aspect Global is never delayed because it is equivalent to
2344 -- a source pragma which appears after the related subprogram.
2345 -- To deal with forward references, the generated pragma is
2346 -- stored in the contract of the related subprogram and later
2347 -- analyzed at the end of the declarative region. See routine
2348 -- Analyze_Global_In_Decl_Part for details.
2350 when Aspect_Global
=>
2352 (Pragma_Argument_Associations
=> New_List
(
2353 Make_Pragma_Argument_Association
(Loc
,
2354 Expression
=> Relocate_Node
(Expr
))),
2355 Pragma_Name
=> Name_Global
);
2357 Decorate
(Aspect
, Aitem
);
2358 Insert_Pragma
(Aitem
);
2361 -- Initial_Condition
2363 -- Aspect Initial_Condition is never delayed because it is
2364 -- equivalent to a source pragma which appears after the
2365 -- related package. To deal with forward references, the
2366 -- generated pragma is stored in the contract of the related
2367 -- package and later analyzed at the end of the declarative
2368 -- region. See routine Analyze_Initial_Condition_In_Decl_Part
2371 when Aspect_Initial_Condition
=> Initial_Condition
: declare
2372 Context
: Node_Id
:= N
;
2376 -- When aspect Initial_Condition appears on a generic
2377 -- package, it is propageted to the package instance. The
2378 -- context in this case is the instance spec.
2380 if Nkind
(Context
) = N_Package_Instantiation
then
2381 Context
:= Instance_Spec
(Context
);
2384 if Nkind_In
(Context
, N_Generic_Package_Declaration
,
2385 N_Package_Declaration
)
2387 Decls
:= Visible_Declarations
(Specification
(Context
));
2390 (Pragma_Argument_Associations
=> New_List
(
2391 Make_Pragma_Argument_Association
(Loc
,
2392 Expression
=> Relocate_Node
(Expr
))),
2394 Name_Initial_Condition
);
2395 Decorate
(Aspect
, Aitem
);
2399 Set_Visible_Declarations
(Context
, Decls
);
2402 -- When aspects Abstract_State, Ghost, Initial_Condition
2403 -- and Initializes are out of order, ensure that pragma
2404 -- SPARK_Mode is always at the top of the declarations to
2405 -- properly enabled/suppress errors.
2407 Insert_After_SPARK_Mode
2409 Ins_Nod
=> First
(Decls
),
2414 ("aspect & must apply to a package declaration",
2419 end Initial_Condition
;
2423 -- Aspect Initializes is never delayed because it is equivalent
2424 -- to a source pragma appearing after the related package. To
2425 -- deal with forward references, the generated pragma is stored
2426 -- in the contract of the related package and later analyzed at
2427 -- the end of the declarative region. For details, see routine
2428 -- Analyze_Initializes_In_Decl_Part.
2430 when Aspect_Initializes
=> Initializes
: declare
2431 Context
: Node_Id
:= N
;
2435 -- When aspect Initializes appears on a generic package,
2436 -- it is propageted to the package instance. The context
2437 -- in this case is the instance spec.
2439 if Nkind
(Context
) = N_Package_Instantiation
then
2440 Context
:= Instance_Spec
(Context
);
2443 if Nkind_In
(Context
, N_Generic_Package_Declaration
,
2444 N_Package_Declaration
)
2446 Decls
:= Visible_Declarations
(Specification
(Context
));
2449 (Pragma_Argument_Associations
=> New_List
(
2450 Make_Pragma_Argument_Association
(Loc
,
2451 Expression
=> Relocate_Node
(Expr
))),
2452 Pragma_Name
=> Name_Initializes
);
2453 Decorate
(Aspect
, Aitem
);
2457 Set_Visible_Declarations
(Context
, Decls
);
2460 -- When aspects Abstract_State, Ghost, Initial_Condition
2461 -- and Initializes are out of order, ensure that pragma
2462 -- SPARK_Mode is always at the top of the declarations to
2463 -- properly enabled/suppress errors.
2465 Insert_After_SPARK_Mode
2467 Ins_Nod
=> First
(Decls
),
2472 ("aspect & must apply to a package declaration",
2481 when Aspect_Obsolescent
=> declare
2489 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2490 Expression
=> Relocate_Node
(Expr
)));
2494 (Pragma_Argument_Associations
=> Args
,
2495 Pragma_Name
=> Chars
(Id
));
2500 when Aspect_Part_Of
=>
2501 if Nkind_In
(N
, N_Object_Declaration
,
2502 N_Package_Instantiation
)
2505 (Pragma_Argument_Associations
=> New_List
(
2506 Make_Pragma_Argument_Association
(Loc
,
2507 Expression
=> Relocate_Node
(Expr
))),
2508 Pragma_Name
=> Name_Part_Of
);
2512 ("aspect & must apply to a variable or package "
2513 & "instantiation", Aspect
, Id
);
2518 when Aspect_SPARK_Mode
=> SPARK_Mode
: declare
2523 (Pragma_Argument_Associations
=> New_List
(
2524 Make_Pragma_Argument_Association
(Loc
,
2525 Expression
=> Relocate_Node
(Expr
))),
2526 Pragma_Name
=> Name_SPARK_Mode
);
2528 -- When the aspect appears on a package or a subprogram
2529 -- body, insert the generated pragma at the top of the body
2530 -- declarations to emulate the behavior of a source pragma.
2532 if Nkind_In
(N
, N_Package_Body
, N_Subprogram_Body
) then
2533 Decorate
(Aspect
, Aitem
);
2535 Decls
:= Declarations
(N
);
2539 Set_Declarations
(N
, Decls
);
2542 Prepend_To
(Decls
, Aitem
);
2545 -- When the aspect is associated with a [generic] package
2546 -- declaration, insert the generated pragma at the top of
2547 -- the visible declarations to emulate the behavior of a
2550 elsif Nkind_In
(N
, N_Generic_Package_Declaration
,
2551 N_Package_Declaration
)
2553 Decorate
(Aspect
, Aitem
);
2555 Decls
:= Visible_Declarations
(Specification
(N
));
2559 Set_Visible_Declarations
(Specification
(N
), Decls
);
2562 Prepend_To
(Decls
, Aitem
);
2569 -- Aspect Refined_Depends is never delayed because it is
2570 -- equivalent to a source pragma which appears in the
2571 -- declarations of the related subprogram body. To deal with
2572 -- forward references, the generated pragma is stored in the
2573 -- contract of the related subprogram body and later analyzed
2574 -- at the end of the declarative region. For details, see
2575 -- routine Analyze_Refined_Depends_In_Decl_Part.
2577 when Aspect_Refined_Depends
=>
2579 (Pragma_Argument_Associations
=> New_List
(
2580 Make_Pragma_Argument_Association
(Loc
,
2581 Expression
=> Relocate_Node
(Expr
))),
2582 Pragma_Name
=> Name_Refined_Depends
);
2584 Decorate
(Aspect
, Aitem
);
2585 Insert_Pragma
(Aitem
);
2590 -- Aspect Refined_Global is never delayed because it is
2591 -- equivalent to a source pragma which appears in the
2592 -- declarations of the related subprogram body. To deal with
2593 -- forward references, the generated pragma is stored in the
2594 -- contract of the related subprogram body and later analyzed
2595 -- at the end of the declarative region. For details, see
2596 -- routine Analyze_Refined_Global_In_Decl_Part.
2598 when Aspect_Refined_Global
=>
2600 (Pragma_Argument_Associations
=> New_List
(
2601 Make_Pragma_Argument_Association
(Loc
,
2602 Expression
=> Relocate_Node
(Expr
))),
2603 Pragma_Name
=> Name_Refined_Global
);
2605 Decorate
(Aspect
, Aitem
);
2606 Insert_Pragma
(Aitem
);
2611 when Aspect_Refined_Post
=>
2613 (Pragma_Argument_Associations
=> New_List
(
2614 Make_Pragma_Argument_Association
(Loc
,
2615 Expression
=> Relocate_Node
(Expr
))),
2616 Pragma_Name
=> Name_Refined_Post
);
2620 when Aspect_Refined_State
=> Refined_State
: declare
2624 -- The corresponding pragma for Refined_State is inserted in
2625 -- the declarations of the related package body. This action
2626 -- synchronizes both the source and from-aspect versions of
2629 if Nkind
(N
) = N_Package_Body
then
2630 Decls
:= Declarations
(N
);
2633 (Pragma_Argument_Associations
=> New_List
(
2634 Make_Pragma_Argument_Association
(Loc
,
2635 Expression
=> Relocate_Node
(Expr
))),
2636 Pragma_Name
=> Name_Refined_State
);
2637 Decorate
(Aspect
, Aitem
);
2641 Set_Declarations
(N
, Decls
);
2644 -- Pragma Refined_State must be inserted after pragma
2645 -- SPARK_Mode in the tree. This ensures that any error
2646 -- messages dependent on SPARK_Mode will be properly
2647 -- enabled/suppressed.
2649 Insert_After_SPARK_Mode
2651 Ins_Nod
=> First
(Decls
),
2656 ("aspect & must apply to a package body", Aspect
, Id
);
2662 -- Relative_Deadline
2664 when Aspect_Relative_Deadline
=>
2666 (Pragma_Argument_Associations
=> New_List
(
2667 Make_Pragma_Argument_Association
(Loc
,
2668 Expression
=> Relocate_Node
(Expr
))),
2669 Pragma_Name
=> Name_Relative_Deadline
);
2671 -- If the aspect applies to a task, the corresponding pragma
2672 -- must appear within its declarations, not after.
2674 if Nkind
(N
) = N_Task_Type_Declaration
then
2680 if No
(Task_Definition
(N
)) then
2681 Set_Task_Definition
(N
,
2682 Make_Task_Definition
(Loc
,
2683 Visible_Declarations
=> New_List
,
2684 End_Label
=> Empty
));
2687 Def
:= Task_Definition
(N
);
2688 V
:= Visible_Declarations
(Def
);
2689 if not Is_Empty_List
(V
) then
2690 Insert_Before
(First
(V
), Aitem
);
2693 Set_Visible_Declarations
(Def
, New_List
(Aitem
));
2700 -- Case 2e: Annotate aspect
2702 when Aspect_Annotate
=>
2709 -- The argument can be a single identifier
2711 if Nkind
(Expr
) = N_Identifier
then
2713 -- One level of parens is allowed
2715 if Paren_Count
(Expr
) > 1 then
2716 Error_Msg_F
("extra parentheses ignored", Expr
);
2719 Set_Paren_Count
(Expr
, 0);
2721 -- Add the single item to the list
2723 Args
:= New_List
(Expr
);
2725 -- Otherwise we must have an aggregate
2727 elsif Nkind
(Expr
) = N_Aggregate
then
2729 -- Must be positional
2731 if Present
(Component_Associations
(Expr
)) then
2733 ("purely positional aggregate required", Expr
);
2737 -- Must not be parenthesized
2739 if Paren_Count
(Expr
) /= 0 then
2740 Error_Msg_F
("extra parentheses ignored", Expr
);
2743 -- List of arguments is list of aggregate expressions
2745 Args
:= Expressions
(Expr
);
2747 -- Anything else is illegal
2750 Error_Msg_F
("wrong form for Annotate aspect", Expr
);
2754 -- Prepare pragma arguments
2757 Arg
:= First
(Args
);
2758 while Present
(Arg
) loop
2760 Make_Pragma_Argument_Association
(Sloc
(Arg
),
2761 Expression
=> Relocate_Node
(Arg
)));
2766 Make_Pragma_Argument_Association
(Sloc
(Ent
),
2767 Chars
=> Name_Entity
,
2768 Expression
=> Ent
));
2771 (Pragma_Argument_Associations
=> Pargs
,
2772 Pragma_Name
=> Name_Annotate
);
2775 -- Case 3 : Aspects that don't correspond to pragma/attribute
2776 -- definition clause.
2778 -- Case 3a: The aspects listed below don't correspond to
2779 -- pragmas/attributes but do require delayed analysis.
2781 -- Default_Value can only apply to a scalar type
2783 when Aspect_Default_Value
=>
2784 if not Is_Scalar_Type
(E
) then
2786 ("aspect Default_Value must apply to a scalar type", N
);
2791 -- Default_Component_Value can only apply to an array type
2792 -- with scalar components.
2794 when Aspect_Default_Component_Value
=>
2795 if not (Is_Array_Type
(E
)
2796 and then Is_Scalar_Type
(Component_Type
(E
)))
2798 Error_Msg_N
("aspect Default_Component_Value can only "
2799 & "apply to an array of scalar components", N
);
2804 -- Case 3b: The aspects listed below don't correspond to
2805 -- pragmas/attributes and don't need delayed analysis.
2807 -- Implicit_Dereference
2809 -- For Implicit_Dereference, External_Name and Link_Name, only
2810 -- the legality checks are done during the analysis, thus no
2811 -- delay is required.
2813 when Aspect_Implicit_Dereference
=>
2814 Analyze_Aspect_Implicit_Dereference
;
2817 -- External_Name, Link_Name
2819 when Aspect_External_Name |
2821 Analyze_Aspect_External_Or_Link_Name
;
2826 when Aspect_Dimension
=>
2827 Analyze_Aspect_Dimension
(N
, Id
, Expr
);
2832 when Aspect_Dimension_System
=>
2833 Analyze_Aspect_Dimension_System
(N
, Id
, Expr
);
2836 -- Case 4: Aspects requiring special handling
2838 -- Pre/Post/Test_Case/Contract_Cases whose corresponding
2839 -- pragmas take care of the delay.
2843 -- Aspects Pre/Post generate Precondition/Postcondition pragmas
2844 -- with a first argument that is the expression, and a second
2845 -- argument that is an informative message if the test fails.
2846 -- This is inserted right after the declaration, to get the
2847 -- required pragma placement. The processing for the pragmas
2848 -- takes care of the required delay.
2850 when Pre_Post_Aspects
=> Pre_Post
: declare
2854 if A_Id
= Aspect_Pre
or else A_Id
= Aspect_Precondition
then
2855 Pname
:= Name_Precondition
;
2857 Pname
:= Name_Postcondition
;
2860 -- If the expressions is of the form A and then B, then
2861 -- we generate separate Pre/Post aspects for the separate
2862 -- clauses. Since we allow multiple pragmas, there is no
2863 -- problem in allowing multiple Pre/Post aspects internally.
2864 -- These should be treated in reverse order (B first and
2865 -- A second) since they are later inserted just after N in
2866 -- the order they are treated. This way, the pragma for A
2867 -- ends up preceding the pragma for B, which may have an
2868 -- importance for the error raised (either constraint error
2869 -- or precondition error).
2871 -- We do not do this for Pre'Class, since we have to put
2872 -- these conditions together in a complex OR expression.
2874 -- We do not do this in ASIS mode, as ASIS relies on the
2875 -- original node representing the complete expression, when
2876 -- retrieving it through the source aspect table.
2879 and then (Pname
= Name_Postcondition
2880 or else not Class_Present
(Aspect
))
2882 while Nkind
(Expr
) = N_And_Then
loop
2883 Insert_After
(Aspect
,
2884 Make_Aspect_Specification
(Sloc
(Left_Opnd
(Expr
)),
2885 Identifier
=> Identifier
(Aspect
),
2886 Expression
=> Relocate_Node
(Left_Opnd
(Expr
)),
2887 Class_Present
=> Class_Present
(Aspect
),
2888 Split_PPC
=> True));
2889 Rewrite
(Expr
, Relocate_Node
(Right_Opnd
(Expr
)));
2890 Eloc
:= Sloc
(Expr
);
2894 -- Build the precondition/postcondition pragma
2896 -- Add note about why we do NOT need Copy_Tree here???
2899 (Pragma_Argument_Associations
=> New_List
(
2900 Make_Pragma_Argument_Association
(Eloc
,
2901 Chars
=> Name_Check
,
2902 Expression
=> Relocate_Node
(Expr
))),
2903 Pragma_Name
=> Pname
);
2905 -- Add message unless exception messages are suppressed
2907 if not Opt
.Exception_Locations_Suppressed
then
2908 Append_To
(Pragma_Argument_Associations
(Aitem
),
2909 Make_Pragma_Argument_Association
(Eloc
,
2910 Chars
=> Name_Message
,
2912 Make_String_Literal
(Eloc
,
2914 & Get_Name_String
(Pname
)
2916 & Build_Location_String
(Eloc
))));
2919 Set_Is_Delayed_Aspect
(Aspect
);
2921 -- For Pre/Post cases, insert immediately after the entity
2922 -- declaration, since that is the required pragma placement.
2923 -- Note that for these aspects, we do not have to worry
2924 -- about delay issues, since the pragmas themselves deal
2925 -- with delay of visibility for the expression analysis.
2927 Insert_Pragma
(Aitem
);
2933 when Aspect_Test_Case
=> Test_Case
: declare
2935 Comp_Expr
: Node_Id
;
2936 Comp_Assn
: Node_Id
;
2942 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
2943 Error_Msg_Name_1
:= Nam
;
2944 Error_Msg_N
("incorrect placement of aspect `%`", E
);
2948 if Nkind
(Expr
) /= N_Aggregate
then
2949 Error_Msg_Name_1
:= Nam
;
2951 ("wrong syntax for aspect `%` for &", Id
, E
);
2955 -- Make pragma expressions refer to the original aspect
2956 -- expressions through the Original_Node link. This is used
2957 -- in semantic analysis for ASIS mode, so that the original
2958 -- expression also gets analyzed.
2960 Comp_Expr
:= First
(Expressions
(Expr
));
2961 while Present
(Comp_Expr
) loop
2962 New_Expr
:= Relocate_Node
(Comp_Expr
);
2963 Set_Original_Node
(New_Expr
, Comp_Expr
);
2965 Make_Pragma_Argument_Association
(Sloc
(Comp_Expr
),
2966 Expression
=> New_Expr
));
2970 Comp_Assn
:= First
(Component_Associations
(Expr
));
2971 while Present
(Comp_Assn
) loop
2972 if List_Length
(Choices
(Comp_Assn
)) /= 1
2974 Nkind
(First
(Choices
(Comp_Assn
))) /= N_Identifier
2976 Error_Msg_Name_1
:= Nam
;
2978 ("wrong syntax for aspect `%` for &", Id
, E
);
2982 New_Expr
:= Relocate_Node
(Expression
(Comp_Assn
));
2983 Set_Original_Node
(New_Expr
, Expression
(Comp_Assn
));
2985 Make_Pragma_Argument_Association
(Sloc
(Comp_Assn
),
2986 Chars
=> Chars
(First
(Choices
(Comp_Assn
))),
2987 Expression
=> New_Expr
));
2991 -- Build the test-case pragma
2994 (Pragma_Argument_Associations
=> Args
,
2995 Pragma_Name
=> Nam
);
3000 when Aspect_Contract_Cases
=>
3002 (Pragma_Argument_Associations
=> New_List
(
3003 Make_Pragma_Argument_Association
(Loc
,
3004 Expression
=> Relocate_Node
(Expr
))),
3005 Pragma_Name
=> Nam
);
3007 Decorate
(Aspect
, Aitem
);
3008 Insert_Pragma
(Aitem
);
3011 -- Case 5: Special handling for aspects with an optional
3012 -- boolean argument.
3014 -- In the general case, the corresponding pragma cannot be
3015 -- generated yet because the evaluation of the boolean needs
3016 -- to be delayed till the freeze point.
3018 when Boolean_Aspects |
3019 Library_Unit_Aspects
=>
3021 Set_Is_Boolean_Aspect
(Aspect
);
3023 -- Lock_Free aspect only apply to protected objects
3025 if A_Id
= Aspect_Lock_Free
then
3026 if Ekind
(E
) /= E_Protected_Type
then
3027 Error_Msg_Name_1
:= Nam
;
3029 ("aspect % only applies to a protected object",
3033 -- Set the Uses_Lock_Free flag to True if there is no
3034 -- expression or if the expression is True. The
3035 -- evaluation of this aspect should be delayed to the
3036 -- freeze point (why???)
3039 or else Is_True
(Static_Boolean
(Expr
))
3041 Set_Uses_Lock_Free
(E
);
3044 Record_Rep_Item
(E
, Aspect
);
3049 elsif A_Id
= Aspect_Import
or else A_Id
= Aspect_Export
then
3051 -- For the case of aspects Import and Export, we don't
3052 -- consider that we know the entity is never set in the
3053 -- source, since it is is likely modified outside the
3056 -- Note: one might think that the analysis of the
3057 -- resulting pragma would take care of that, but
3058 -- that's not the case since it won't be from source.
3060 if Ekind
(E
) = E_Variable
then
3061 Set_Never_Set_In_Source
(E
, False);
3064 -- In older versions of Ada the corresponding pragmas
3065 -- specified a Convention. In Ada 2012 the convention is
3066 -- specified as a separate aspect, and it is optional,
3067 -- given that it defaults to Convention_Ada. The code
3068 -- that verifed that there was a matching convention
3071 -- Resolve the expression of an Import or Export here,
3072 -- and require it to be of type Boolean and static. This
3073 -- is not quite right, because in general this should be
3074 -- delayed, but that seems tricky for these, because
3075 -- normally Boolean aspects are replaced with pragmas at
3076 -- the freeze point (in Make_Pragma_From_Boolean_Aspect),
3077 -- but in the case of these aspects we can't generate
3078 -- a simple pragma with just the entity name. ???
3080 if not Present
(Expr
)
3081 or else Is_True
(Static_Boolean
(Expr
))
3083 if A_Id
= Aspect_Import
then
3084 Set_Is_Imported
(E
);
3086 -- An imported entity cannot have an explicit
3089 if Nkind
(N
) = N_Object_Declaration
3090 and then Present
(Expression
(N
))
3093 ("imported entities cannot be initialized "
3094 & "(RM B.1(24))", Expression
(N
));
3097 elsif A_Id
= Aspect_Export
then
3098 Set_Is_Exported
(E
);
3105 -- Library unit aspects require special handling in the case
3106 -- of a package declaration, the pragma needs to be inserted
3107 -- in the list of declarations for the associated package.
3108 -- There is no issue of visibility delay for these aspects.
3110 if A_Id
in Library_Unit_Aspects
3112 Nkind_In
(N
, N_Package_Declaration
,
3113 N_Generic_Package_Declaration
)
3114 and then Nkind
(Parent
(N
)) /= N_Compilation_Unit
3116 -- Aspect is legal on a local instantiation of a library-
3117 -- level generic unit.
3119 and then not Is_Generic_Instance
(Defining_Entity
(N
))
3122 ("incorrect context for library unit aspect&", Id
);
3126 -- External property aspects are Boolean by nature, but
3127 -- their pragmas must contain two arguments, the second
3128 -- being the optional Boolean expression.
3130 if A_Id
= Aspect_Async_Readers
or else
3131 A_Id
= Aspect_Async_Writers
or else
3132 A_Id
= Aspect_Effective_Reads
or else
3133 A_Id
= Aspect_Effective_Writes
3139 -- The first argument of the external property pragma
3140 -- is the related object.
3144 Make_Pragma_Argument_Association
(Sloc
(Ent
),
3145 Expression
=> Ent
));
3147 -- The second argument is the optional Boolean
3148 -- expression which must be propagated even if it
3149 -- evaluates to False as this has special semantic
3152 if Present
(Expr
) then
3154 Make_Pragma_Argument_Association
(Loc
,
3155 Expression
=> Relocate_Node
(Expr
)));
3159 (Pragma_Argument_Associations
=> Args
,
3160 Pragma_Name
=> Nam
);
3163 -- Cases where we do not delay, includes all cases where the
3164 -- expression is missing other than the above cases.
3166 elsif not Delay_Required
or else No
(Expr
) then
3168 (Pragma_Argument_Associations
=> New_List
(
3169 Make_Pragma_Argument_Association
(Sloc
(Ent
),
3170 Expression
=> Ent
)),
3171 Pragma_Name
=> Chars
(Id
));
3172 Delay_Required
:= False;
3174 -- In general cases, the corresponding pragma/attribute
3175 -- definition clause will be inserted later at the freezing
3176 -- point, and we do not need to build it now.
3184 -- This is special because for access types we need to generate
3185 -- an attribute definition clause. This also works for single
3186 -- task declarations, but it does not work for task type
3187 -- declarations, because we have the case where the expression
3188 -- references a discriminant of the task type. That can't use
3189 -- an attribute definition clause because we would not have
3190 -- visibility on the discriminant. For that case we must
3191 -- generate a pragma in the task definition.
3193 when Aspect_Storage_Size
=>
3197 if Ekind
(E
) = E_Task_Type
then
3199 Decl
: constant Node_Id
:= Declaration_Node
(E
);
3202 pragma Assert
(Nkind
(Decl
) = N_Task_Type_Declaration
);
3204 -- If no task definition, create one
3206 if No
(Task_Definition
(Decl
)) then
3207 Set_Task_Definition
(Decl
,
3208 Make_Task_Definition
(Loc
,
3209 Visible_Declarations
=> Empty_List
,
3210 End_Label
=> Empty
));
3213 -- Create a pragma and put it at the start of the task
3214 -- definition for the task type declaration.
3217 (Pragma_Argument_Associations
=> New_List
(
3218 Make_Pragma_Argument_Association
(Loc
,
3219 Expression
=> Relocate_Node
(Expr
))),
3220 Pragma_Name
=> Name_Storage_Size
);
3224 Visible_Declarations
(Task_Definition
(Decl
)));
3228 -- All other cases, generate attribute definition
3232 Make_Attribute_Definition_Clause
(Loc
,
3234 Chars
=> Chars
(Id
),
3235 Expression
=> Relocate_Node
(Expr
));
3239 -- Attach the corresponding pragma/attribute definition clause to
3240 -- the aspect specification node.
3242 if Present
(Aitem
) then
3243 Set_From_Aspect_Specification
(Aitem
);
3246 -- In the context of a compilation unit, we directly put the
3247 -- pragma in the Pragmas_After list of the N_Compilation_Unit_Aux
3248 -- node (no delay is required here) except for aspects on a
3249 -- subprogram body (see below) and a generic package, for which we
3250 -- need to introduce the pragma before building the generic copy
3251 -- (see sem_ch12), and for package instantiations, where the
3252 -- library unit pragmas are better handled early.
3254 if Nkind
(Parent
(N
)) = N_Compilation_Unit
3255 and then (Present
(Aitem
) or else Is_Boolean_Aspect
(Aspect
))
3258 Aux
: constant Node_Id
:= Aux_Decls_Node
(Parent
(N
));
3261 pragma Assert
(Nkind
(Aux
) = N_Compilation_Unit_Aux
);
3263 -- For a Boolean aspect, create the corresponding pragma if
3264 -- no expression or if the value is True.
3266 if Is_Boolean_Aspect
(Aspect
) and then No
(Aitem
) then
3267 if Is_True
(Static_Boolean
(Expr
)) then
3269 (Pragma_Argument_Associations
=> New_List
(
3270 Make_Pragma_Argument_Association
(Sloc
(Ent
),
3271 Expression
=> Ent
)),
3272 Pragma_Name
=> Chars
(Id
));
3274 Set_From_Aspect_Specification
(Aitem
, True);
3275 Set_Corresponding_Aspect
(Aitem
, Aspect
);
3282 -- If the aspect is on a subprogram body (relevant aspect
3283 -- is Inline), add the pragma in front of the declarations.
3285 if Nkind
(N
) = N_Subprogram_Body
then
3286 if No
(Declarations
(N
)) then
3287 Set_Declarations
(N
, New_List
);
3290 Prepend
(Aitem
, Declarations
(N
));
3292 elsif Nkind
(N
) = N_Generic_Package_Declaration
then
3293 if No
(Visible_Declarations
(Specification
(N
))) then
3294 Set_Visible_Declarations
(Specification
(N
), New_List
);
3298 Visible_Declarations
(Specification
(N
)));
3300 elsif Nkind
(N
) = N_Package_Instantiation
then
3302 Spec
: constant Node_Id
:=
3303 Specification
(Instance_Spec
(N
));
3305 if No
(Visible_Declarations
(Spec
)) then
3306 Set_Visible_Declarations
(Spec
, New_List
);
3309 Prepend
(Aitem
, Visible_Declarations
(Spec
));
3313 if No
(Pragmas_After
(Aux
)) then
3314 Set_Pragmas_After
(Aux
, New_List
);
3317 Append
(Aitem
, Pragmas_After
(Aux
));
3324 -- The evaluation of the aspect is delayed to the freezing point.
3325 -- The pragma or attribute clause if there is one is then attached
3326 -- to the aspect specification which is put in the rep item list.
3328 if Delay_Required
then
3329 if Present
(Aitem
) then
3330 Set_Is_Delayed_Aspect
(Aitem
);
3331 Set_Aspect_Rep_Item
(Aspect
, Aitem
);
3332 Set_Parent
(Aitem
, Aspect
);
3335 Set_Is_Delayed_Aspect
(Aspect
);
3337 -- In the case of Default_Value, link the aspect to base type
3338 -- as well, even though it appears on a first subtype. This is
3339 -- mandated by the semantics of the aspect. Do not establish
3340 -- the link when processing the base type itself as this leads
3341 -- to a rep item circularity. Verify that we are dealing with
3342 -- a scalar type to prevent cascaded errors.
3344 if A_Id
= Aspect_Default_Value
3345 and then Is_Scalar_Type
(E
)
3346 and then Base_Type
(E
) /= E
3348 Set_Has_Delayed_Aspects
(Base_Type
(E
));
3349 Record_Rep_Item
(Base_Type
(E
), Aspect
);
3352 Set_Has_Delayed_Aspects
(E
);
3353 Record_Rep_Item
(E
, Aspect
);
3355 -- When delay is not required and the context is a package or a
3356 -- subprogram body, insert the pragma in the body declarations.
3358 elsif Nkind_In
(N
, N_Package_Body
, N_Subprogram_Body
) then
3359 if No
(Declarations
(N
)) then
3360 Set_Declarations
(N
, New_List
);
3363 -- The pragma is added before source declarations
3365 Prepend_To
(Declarations
(N
), Aitem
);
3367 -- When delay is not required and the context is not a compilation
3368 -- unit, we simply insert the pragma/attribute definition clause
3372 Insert_After
(Ins_Node
, Aitem
);
3375 end Analyze_One_Aspect
;
3379 end loop Aspect_Loop
;
3381 if Has_Delayed_Aspects
(E
) then
3382 Ensure_Freeze_Node
(E
);
3384 end Analyze_Aspect_Specifications
;
3386 -----------------------
3387 -- Analyze_At_Clause --
3388 -----------------------
3390 -- An at clause is replaced by the corresponding Address attribute
3391 -- definition clause that is the preferred approach in Ada 95.
3393 procedure Analyze_At_Clause
(N
: Node_Id
) is
3394 CS
: constant Boolean := Comes_From_Source
(N
);
3397 -- This is an obsolescent feature
3399 Check_Restriction
(No_Obsolescent_Features
, N
);
3401 if Warn_On_Obsolescent_Feature
then
3403 ("?j?at clause is an obsolescent feature (RM J.7(2))", N
);
3405 ("\?j?use address attribute definition clause instead", N
);
3408 -- Rewrite as address clause
3411 Make_Attribute_Definition_Clause
(Sloc
(N
),
3412 Name
=> Identifier
(N
),
3413 Chars
=> Name_Address
,
3414 Expression
=> Expression
(N
)));
3416 -- We preserve Comes_From_Source, since logically the clause still comes
3417 -- from the source program even though it is changed in form.
3419 Set_Comes_From_Source
(N
, CS
);
3421 -- Analyze rewritten clause
3423 Analyze_Attribute_Definition_Clause
(N
);
3424 end Analyze_At_Clause
;
3426 -----------------------------------------
3427 -- Analyze_Attribute_Definition_Clause --
3428 -----------------------------------------
3430 procedure Analyze_Attribute_Definition_Clause
(N
: Node_Id
) is
3431 Loc
: constant Source_Ptr
:= Sloc
(N
);
3432 Nam
: constant Node_Id
:= Name
(N
);
3433 Attr
: constant Name_Id
:= Chars
(N
);
3434 Expr
: constant Node_Id
:= Expression
(N
);
3435 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Attr
);
3438 -- The entity of Nam after it is analyzed. In the case of an incomplete
3439 -- type, this is the underlying type.
3442 -- The underlying entity to which the attribute applies. Generally this
3443 -- is the Underlying_Type of Ent, except in the case where the clause
3444 -- applies to full view of incomplete type or private type in which case
3445 -- U_Ent is just a copy of Ent.
3447 FOnly
: Boolean := False;
3448 -- Reset to True for subtype specific attribute (Alignment, Size)
3449 -- and for stream attributes, i.e. those cases where in the call to
3450 -- Rep_Item_Too_Late, FOnly is set True so that only the freezing rules
3451 -- are checked. Note that the case of stream attributes is not clear
3452 -- from the RM, but see AI95-00137. Also, the RM seems to disallow
3453 -- Storage_Size for derived task types, but that is also clearly
3456 procedure Analyze_Stream_TSS_Definition
(TSS_Nam
: TSS_Name_Type
);
3457 -- Common processing for 'Read, 'Write, 'Input and 'Output attribute
3458 -- definition clauses.
3460 function Duplicate_Clause
return Boolean;
3461 -- This routine checks if the aspect for U_Ent being given by attribute
3462 -- definition clause N is for an aspect that has already been specified,
3463 -- and if so gives an error message. If there is a duplicate, True is
3464 -- returned, otherwise if there is no error, False is returned.
3466 procedure Check_Indexing_Functions
;
3467 -- Check that the function in Constant_Indexing or Variable_Indexing
3468 -- attribute has the proper type structure. If the name is overloaded,
3469 -- check that some interpretation is legal.
3471 procedure Check_Iterator_Functions
;
3472 -- Check that there is a single function in Default_Iterator attribute
3473 -- has the proper type structure.
3475 function Check_Primitive_Function
(Subp
: Entity_Id
) return Boolean;
3476 -- Common legality check for the previous two
3478 -----------------------------------
3479 -- Analyze_Stream_TSS_Definition --
3480 -----------------------------------
3482 procedure Analyze_Stream_TSS_Definition
(TSS_Nam
: TSS_Name_Type
) is
3483 Subp
: Entity_Id
:= Empty
;
3488 Is_Read
: constant Boolean := (TSS_Nam
= TSS_Stream_Read
);
3489 -- True for Read attribute, false for other attributes
3491 function Has_Good_Profile
(Subp
: Entity_Id
) return Boolean;
3492 -- Return true if the entity is a subprogram with an appropriate
3493 -- profile for the attribute being defined.
3495 ----------------------
3496 -- Has_Good_Profile --
3497 ----------------------
3499 function Has_Good_Profile
(Subp
: Entity_Id
) return Boolean is
3501 Is_Function
: constant Boolean := (TSS_Nam
= TSS_Stream_Input
);
3502 Expected_Ekind
: constant array (Boolean) of Entity_Kind
:=
3503 (False => E_Procedure
, True => E_Function
);
3507 if Ekind
(Subp
) /= Expected_Ekind
(Is_Function
) then
3511 F
:= First_Formal
(Subp
);
3514 or else Ekind
(Etype
(F
)) /= E_Anonymous_Access_Type
3515 or else Designated_Type
(Etype
(F
)) /=
3516 Class_Wide_Type
(RTE
(RE_Root_Stream_Type
))
3521 if not Is_Function
then
3525 Expected_Mode
: constant array (Boolean) of Entity_Kind
:=
3526 (False => E_In_Parameter
,
3527 True => E_Out_Parameter
);
3529 if Parameter_Mode
(F
) /= Expected_Mode
(Is_Read
) then
3536 -- If the attribute specification comes from an aspect
3537 -- specification for a class-wide stream, the parameter must be
3538 -- a class-wide type of the entity to which the aspect applies.
3540 if From_Aspect_Specification
(N
)
3541 and then Class_Present
(Parent
(N
))
3542 and then Is_Class_Wide_Type
(Typ
)
3548 Typ
:= Etype
(Subp
);
3551 -- Verify that the prefix of the attribute and the local name for
3552 -- the type of the formal match.
3554 if Base_Type
(Typ
) /= Base_Type
(Ent
)
3555 or else Present
((Next_Formal
(F
)))
3559 elsif not Is_Scalar_Type
(Typ
)
3560 and then not Is_First_Subtype
(Typ
)
3561 and then not Is_Class_Wide_Type
(Typ
)
3568 end Has_Good_Profile
;
3570 -- Start of processing for Analyze_Stream_TSS_Definition
3575 if not Is_Type
(U_Ent
) then
3576 Error_Msg_N
("local name must be a subtype", Nam
);
3579 elsif not Is_First_Subtype
(U_Ent
) then
3580 Error_Msg_N
("local name must be a first subtype", Nam
);
3584 Pnam
:= TSS
(Base_Type
(U_Ent
), TSS_Nam
);
3586 -- If Pnam is present, it can be either inherited from an ancestor
3587 -- type (in which case it is legal to redefine it for this type), or
3588 -- be a previous definition of the attribute for the same type (in
3589 -- which case it is illegal).
3591 -- In the first case, it will have been analyzed already, and we
3592 -- can check that its profile does not match the expected profile
3593 -- for a stream attribute of U_Ent. In the second case, either Pnam
3594 -- has been analyzed (and has the expected profile), or it has not
3595 -- been analyzed yet (case of a type that has not been frozen yet
3596 -- and for which the stream attribute has been set using Set_TSS).
3599 and then (No
(First_Entity
(Pnam
)) or else Has_Good_Profile
(Pnam
))
3601 Error_Msg_Sloc
:= Sloc
(Pnam
);
3602 Error_Msg_Name_1
:= Attr
;
3603 Error_Msg_N
("% attribute already defined #", Nam
);
3609 if Is_Entity_Name
(Expr
) then
3610 if not Is_Overloaded
(Expr
) then
3611 if Has_Good_Profile
(Entity
(Expr
)) then
3612 Subp
:= Entity
(Expr
);
3616 Get_First_Interp
(Expr
, I
, It
);
3617 while Present
(It
.Nam
) loop
3618 if Has_Good_Profile
(It
.Nam
) then
3623 Get_Next_Interp
(I
, It
);
3628 if Present
(Subp
) then
3629 if Is_Abstract_Subprogram
(Subp
) then
3630 Error_Msg_N
("stream subprogram must not be abstract", Expr
);
3633 -- Test for stream subprogram for interface type being non-null
3635 elsif Is_Interface
(U_Ent
)
3636 and then not Inside_A_Generic
3637 and then Ekind
(Subp
) = E_Procedure
3641 (Unit_Declaration_Node
(Ultimate_Alias
(Subp
))))
3644 ("stream subprogram for interface type "
3645 & "must be null procedure", Expr
);
3648 Set_Entity
(Expr
, Subp
);
3649 Set_Etype
(Expr
, Etype
(Subp
));
3651 New_Stream_Subprogram
(N
, U_Ent
, Subp
, TSS_Nam
);
3654 Error_Msg_Name_1
:= Attr
;
3655 Error_Msg_N
("incorrect expression for% attribute", Expr
);
3657 end Analyze_Stream_TSS_Definition
;
3659 ------------------------------
3660 -- Check_Indexing_Functions --
3661 ------------------------------
3663 procedure Check_Indexing_Functions
is
3664 Indexing_Found
: Boolean := False;
3666 procedure Check_One_Function
(Subp
: Entity_Id
);
3667 -- Check one possible interpretation. Sets Indexing_Found True if a
3668 -- legal indexing function is found.
3670 procedure Illegal_Indexing
(Msg
: String);
3671 -- Diagnose illegal indexing function if not overloaded. In the
3672 -- overloaded case indicate that no legal interpretation exists.
3674 ------------------------
3675 -- Check_One_Function --
3676 ------------------------
3678 procedure Check_One_Function
(Subp
: Entity_Id
) is
3679 Default_Element
: Node_Id
;
3680 Ret_Type
: constant Entity_Id
:= Etype
(Subp
);
3683 if not Is_Overloadable
(Subp
) then
3684 Illegal_Indexing
("illegal indexing function for type&");
3687 elsif Scope
(Subp
) /= Scope
(Ent
) then
3688 if Nkind
(Expr
) = N_Expanded_Name
then
3690 -- Indexing function can't be declared elsewhere
3693 ("indexing function must be declared in scope of type&");
3698 elsif No
(First_Formal
(Subp
)) then
3700 ("Indexing requires a function that applies to type&");
3703 elsif No
(Next_Formal
(First_Formal
(Subp
))) then
3705 ("indexing function must have at least two parameters");
3708 elsif Is_Derived_Type
(Ent
) then
3709 if (Attr
= Name_Constant_Indexing
3711 (Find_Aspect
(Etype
(Ent
), Aspect_Constant_Indexing
)))
3713 (Attr
= Name_Variable_Indexing
3715 (Find_Aspect
(Etype
(Ent
), Aspect_Variable_Indexing
)))
3717 if Debug_Flag_Dot_XX
then
3722 ("indexing function already inherited "
3723 & "from parent type");
3729 if not Check_Primitive_Function
(Subp
) then
3731 ("Indexing aspect requires a function that applies to type&");
3735 -- If partial declaration exists, verify that it is not tagged.
3737 if Ekind
(Current_Scope
) = E_Package
3738 and then Has_Private_Declaration
(Ent
)
3739 and then From_Aspect_Specification
(N
)
3741 List_Containing
(Parent
(Ent
)) =
3742 Private_Declarations
3743 (Specification
(Unit_Declaration_Node
(Current_Scope
)))
3744 and then Nkind
(N
) = N_Attribute_Definition_Clause
3751 First
(Visible_Declarations
3753 (Unit_Declaration_Node
(Current_Scope
))));
3755 while Present
(Decl
) loop
3756 if Nkind
(Decl
) = N_Private_Type_Declaration
3757 and then Ent
= Full_View
(Defining_Identifier
(Decl
))
3758 and then Tagged_Present
(Decl
)
3759 and then No
(Aspect_Specifications
(Decl
))
3762 ("Indexing aspect cannot be specified on full view "
3763 & "if partial view is tagged");
3772 -- An indexing function must return either the default element of
3773 -- the container, or a reference type. For variable indexing it
3774 -- must be the latter.
3777 Find_Value_Of_Aspect
3778 (Etype
(First_Formal
(Subp
)), Aspect_Iterator_Element
);
3780 if Present
(Default_Element
) then
3781 Analyze
(Default_Element
);
3783 if Is_Entity_Name
(Default_Element
)
3784 and then not Covers
(Entity
(Default_Element
), Ret_Type
)
3788 ("wrong return type for indexing function");
3793 -- For variable_indexing the return type must be a reference type
3795 if Attr
= Name_Variable_Indexing
then
3796 if not Has_Implicit_Dereference
(Ret_Type
) then
3798 ("variable indexing must return a reference type");
3801 elsif Is_Access_Constant
3802 (Etype
(First_Discriminant
(Ret_Type
)))
3805 ("variable indexing must return an access to variable");
3810 if Has_Implicit_Dereference
(Ret_Type
)
3812 Is_Access_Constant
(Etype
(First_Discriminant
(Ret_Type
)))
3815 ("constant indexing must return an access to constant");
3818 elsif Is_Access_Type
(Etype
(First_Formal
(Subp
)))
3819 and then not Is_Access_Constant
(Etype
(First_Formal
(Subp
)))
3822 ("constant indexing must apply to an access to constant");
3827 -- All checks succeeded.
3829 Indexing_Found
:= True;
3830 end Check_One_Function
;
3832 -----------------------
3833 -- Illegal_Indexing --
3834 -----------------------
3836 procedure Illegal_Indexing
(Msg
: String) is
3838 Error_Msg_NE
(Msg
, N
, Ent
);
3839 end Illegal_Indexing
;
3841 -- Start of processing for Check_Indexing_Functions
3850 if not Is_Overloaded
(Expr
) then
3851 Check_One_Function
(Entity
(Expr
));
3859 Indexing_Found
:= False;
3860 Get_First_Interp
(Expr
, I
, It
);
3861 while Present
(It
.Nam
) loop
3863 -- Note that analysis will have added the interpretation
3864 -- that corresponds to the dereference. We only check the
3865 -- subprogram itself.
3867 if Is_Overloadable
(It
.Nam
) then
3868 Check_One_Function
(It
.Nam
);
3871 Get_Next_Interp
(I
, It
);
3876 if not Indexing_Found
and then not Error_Posted
(N
) then
3878 ("aspect Indexing requires a local function that "
3879 & "applies to type&", Expr
, Ent
);
3881 end Check_Indexing_Functions
;
3883 ------------------------------
3884 -- Check_Iterator_Functions --
3885 ------------------------------
3887 procedure Check_Iterator_Functions
is
3888 Default
: Entity_Id
;
3890 function Valid_Default_Iterator
(Subp
: Entity_Id
) return Boolean;
3891 -- Check one possible interpretation for validity
3893 ----------------------------
3894 -- Valid_Default_Iterator --
3895 ----------------------------
3897 function Valid_Default_Iterator
(Subp
: Entity_Id
) return Boolean is
3901 if not Check_Primitive_Function
(Subp
) then
3904 Formal
:= First_Formal
(Subp
);
3907 -- False if any subsequent formal has no default expression
3909 Formal
:= Next_Formal
(Formal
);
3910 while Present
(Formal
) loop
3911 if No
(Expression
(Parent
(Formal
))) then
3915 Next_Formal
(Formal
);
3918 -- True if all subsequent formals have default expressions
3921 end Valid_Default_Iterator
;
3923 -- Start of processing for Check_Iterator_Functions
3928 if not Is_Entity_Name
(Expr
) then
3929 Error_Msg_N
("aspect Iterator must be a function name", Expr
);
3932 if not Is_Overloaded
(Expr
) then
3933 if not Check_Primitive_Function
(Entity
(Expr
)) then
3935 ("aspect Indexing requires a function that applies to type&",
3936 Entity
(Expr
), Ent
);
3939 if not Valid_Default_Iterator
(Entity
(Expr
)) then
3940 Error_Msg_N
("improper function for default iterator", Expr
);
3950 Get_First_Interp
(Expr
, I
, It
);
3951 while Present
(It
.Nam
) loop
3952 if not Check_Primitive_Function
(It
.Nam
)
3953 or else not Valid_Default_Iterator
(It
.Nam
)
3957 elsif Present
(Default
) then
3958 Error_Msg_N
("default iterator must be unique", Expr
);
3964 Get_Next_Interp
(I
, It
);
3968 if Present
(Default
) then
3969 Set_Entity
(Expr
, Default
);
3970 Set_Is_Overloaded
(Expr
, False);
3973 end Check_Iterator_Functions
;
3975 -------------------------------
3976 -- Check_Primitive_Function --
3977 -------------------------------
3979 function Check_Primitive_Function
(Subp
: Entity_Id
) return Boolean is
3983 if Ekind
(Subp
) /= E_Function
then
3987 if No
(First_Formal
(Subp
)) then
3990 Ctrl
:= Etype
(First_Formal
(Subp
));
3993 -- Type of formal may be the class-wide type, an access to such,
3994 -- or an incomplete view.
3997 or else Ctrl
= Class_Wide_Type
(Ent
)
3999 (Ekind
(Ctrl
) = E_Anonymous_Access_Type
4000 and then (Designated_Type
(Ctrl
) = Ent
4002 Designated_Type
(Ctrl
) = Class_Wide_Type
(Ent
)))
4004 (Ekind
(Ctrl
) = E_Incomplete_Type
4005 and then Full_View
(Ctrl
) = Ent
)
4013 end Check_Primitive_Function
;
4015 ----------------------
4016 -- Duplicate_Clause --
4017 ----------------------
4019 function Duplicate_Clause
return Boolean is
4023 -- Nothing to do if this attribute definition clause comes from
4024 -- an aspect specification, since we could not be duplicating an
4025 -- explicit clause, and we dealt with the case of duplicated aspects
4026 -- in Analyze_Aspect_Specifications.
4028 if From_Aspect_Specification
(N
) then
4032 -- Otherwise current clause may duplicate previous clause, or a
4033 -- previously given pragma or aspect specification for the same
4036 A
:= Get_Rep_Item
(U_Ent
, Chars
(N
), Check_Parents
=> False);
4039 Error_Msg_Name_1
:= Chars
(N
);
4040 Error_Msg_Sloc
:= Sloc
(A
);
4042 Error_Msg_NE
("aspect% for & previously given#", N
, U_Ent
);
4047 end Duplicate_Clause
;
4049 -- Start of processing for Analyze_Attribute_Definition_Clause
4052 -- The following code is a defense against recursion. Not clear that
4053 -- this can happen legitimately, but perhaps some error situations can
4054 -- cause it, and we did see this recursion during testing.
4056 if Analyzed
(N
) then
4059 Set_Analyzed
(N
, True);
4062 -- Ignore some selected attributes in CodePeer mode since they are not
4063 -- relevant in this context.
4065 if CodePeer_Mode
then
4068 -- Ignore Component_Size in CodePeer mode, to avoid changing the
4069 -- internal representation of types by implicitly packing them.
4071 when Attribute_Component_Size
=>
4072 Rewrite
(N
, Make_Null_Statement
(Sloc
(N
)));
4080 -- Process Ignore_Rep_Clauses option
4082 if Ignore_Rep_Clauses
then
4085 -- The following should be ignored. They do not affect legality
4086 -- and may be target dependent. The basic idea of -gnatI is to
4087 -- ignore any rep clauses that may be target dependent but do not
4088 -- affect legality (except possibly to be rejected because they
4089 -- are incompatible with the compilation target).
4091 when Attribute_Alignment |
4092 Attribute_Bit_Order |
4093 Attribute_Component_Size |
4094 Attribute_Machine_Radix |
4095 Attribute_Object_Size |
4098 Attribute_Stream_Size |
4099 Attribute_Value_Size
=>
4100 Kill_Rep_Clause
(N
);
4103 -- The following should not be ignored, because in the first place
4104 -- they are reasonably portable, and should not cause problems
4105 -- in compiling code from another target, and also they do affect
4106 -- legality, e.g. failing to provide a stream attribute for a type
4107 -- may make a program illegal.
4109 when Attribute_External_Tag |
4113 Attribute_Simple_Storage_Pool |
4114 Attribute_Storage_Pool |
4115 Attribute_Storage_Size |
4119 -- We do not do anything here with address clauses, they will be
4120 -- removed by Freeze later on, but for now, it works better to
4121 -- keep then in the tree.
4123 when Attribute_Address
=>
4126 -- Other cases are errors ("attribute& cannot be set with
4127 -- definition clause"), which will be caught below.
4135 Ent
:= Entity
(Nam
);
4137 if Rep_Item_Too_Early
(Ent
, N
) then
4141 -- Rep clause applies to full view of incomplete type or private type if
4142 -- we have one (if not, this is a premature use of the type). However,
4143 -- certain semantic checks need to be done on the specified entity (i.e.
4144 -- the private view), so we save it in Ent.
4146 if Is_Private_Type
(Ent
)
4147 and then Is_Derived_Type
(Ent
)
4148 and then not Is_Tagged_Type
(Ent
)
4149 and then No
(Full_View
(Ent
))
4151 -- If this is a private type whose completion is a derivation from
4152 -- another private type, there is no full view, and the attribute
4153 -- belongs to the type itself, not its underlying parent.
4157 elsif Ekind
(Ent
) = E_Incomplete_Type
then
4159 -- The attribute applies to the full view, set the entity of the
4160 -- attribute definition accordingly.
4162 Ent
:= Underlying_Type
(Ent
);
4164 Set_Entity
(Nam
, Ent
);
4167 U_Ent
:= Underlying_Type
(Ent
);
4170 -- Avoid cascaded error
4172 if Etype
(Nam
) = Any_Type
then
4175 -- Must be declared in current scope or in case of an aspect
4176 -- specification, must be visible in current scope.
4178 elsif Scope
(Ent
) /= Current_Scope
4180 not (From_Aspect_Specification
(N
)
4181 and then Scope_Within_Or_Same
(Current_Scope
, Scope
(Ent
)))
4183 Error_Msg_N
("entity must be declared in this scope", Nam
);
4186 -- Must not be a source renaming (we do have some cases where the
4187 -- expander generates a renaming, and those cases are OK, in such
4188 -- cases any attribute applies to the renamed object as well).
4190 elsif Is_Object
(Ent
)
4191 and then Present
(Renamed_Object
(Ent
))
4193 -- Case of renamed object from source, this is an error
4195 if Comes_From_Source
(Renamed_Object
(Ent
)) then
4196 Get_Name_String
(Chars
(N
));
4197 Error_Msg_Strlen
:= Name_Len
;
4198 Error_Msg_String
(1 .. Name_Len
) := Name_Buffer
(1 .. Name_Len
);
4200 ("~ clause not allowed for a renaming declaration "
4201 & "(RM 13.1(6))", Nam
);
4204 -- For the case of a compiler generated renaming, the attribute
4205 -- definition clause applies to the renamed object created by the
4206 -- expander. The easiest general way to handle this is to create a
4207 -- copy of the attribute definition clause for this object.
4209 elsif Is_Entity_Name
(Renamed_Object
(Ent
)) then
4211 Make_Attribute_Definition_Clause
(Loc
,
4213 New_Occurrence_Of
(Entity
(Renamed_Object
(Ent
)), Loc
),
4215 Expression
=> Duplicate_Subexpr
(Expression
(N
))));
4217 -- If the renamed object is not an entity, it must be a dereference
4218 -- of an unconstrained function call, and we must introduce a new
4219 -- declaration to capture the expression. This is needed in the case
4220 -- of 'Alignment, where the original declaration must be rewritten.
4224 (Nkind
(Renamed_Object
(Ent
)) = N_Explicit_Dereference
);
4228 -- If no underlying entity, use entity itself, applies to some
4229 -- previously detected error cases ???
4231 elsif No
(U_Ent
) then
4234 -- Cannot specify for a subtype (exception Object/Value_Size)
4236 elsif Is_Type
(U_Ent
)
4237 and then not Is_First_Subtype
(U_Ent
)
4238 and then Id
/= Attribute_Object_Size
4239 and then Id
/= Attribute_Value_Size
4240 and then not From_At_Mod
(N
)
4242 Error_Msg_N
("cannot specify attribute for subtype", Nam
);
4246 Set_Entity
(N
, U_Ent
);
4247 Check_Restriction_No_Use_Of_Attribute
(N
);
4249 -- Switch on particular attribute
4257 -- Address attribute definition clause
4259 when Attribute_Address
=> Address
: begin
4261 -- A little error check, catch for X'Address use X'Address;
4263 if Nkind
(Nam
) = N_Identifier
4264 and then Nkind
(Expr
) = N_Attribute_Reference
4265 and then Attribute_Name
(Expr
) = Name_Address
4266 and then Nkind
(Prefix
(Expr
)) = N_Identifier
4267 and then Chars
(Nam
) = Chars
(Prefix
(Expr
))
4270 ("address for & is self-referencing", Prefix
(Expr
), Ent
);
4274 -- Not that special case, carry on with analysis of expression
4276 Analyze_And_Resolve
(Expr
, RTE
(RE_Address
));
4278 -- Even when ignoring rep clauses we need to indicate that the
4279 -- entity has an address clause and thus it is legal to declare
4280 -- it imported. Freeze will get rid of the address clause later.
4282 if Ignore_Rep_Clauses
then
4283 if Ekind_In
(U_Ent
, E_Variable
, E_Constant
) then
4284 Record_Rep_Item
(U_Ent
, N
);
4290 if Duplicate_Clause
then
4293 -- Case of address clause for subprogram
4295 elsif Is_Subprogram
(U_Ent
) then
4296 if Has_Homonym
(U_Ent
) then
4298 ("address clause cannot be given " &
4299 "for overloaded subprogram",
4304 -- For subprograms, all address clauses are permitted, and we
4305 -- mark the subprogram as having a deferred freeze so that Gigi
4306 -- will not elaborate it too soon.
4308 -- Above needs more comments, what is too soon about???
4310 Set_Has_Delayed_Freeze
(U_Ent
);
4312 -- Case of address clause for entry
4314 elsif Ekind
(U_Ent
) = E_Entry
then
4315 if Nkind
(Parent
(N
)) = N_Task_Body
then
4317 ("entry address must be specified in task spec", Nam
);
4321 -- For entries, we require a constant address
4323 Check_Constant_Address_Clause
(Expr
, U_Ent
);
4325 -- Special checks for task types
4327 if Is_Task_Type
(Scope
(U_Ent
))
4328 and then Comes_From_Source
(Scope
(U_Ent
))
4331 ("??entry address declared for entry in task type", N
);
4333 ("\??only one task can be declared of this type", N
);
4336 -- Entry address clauses are obsolescent
4338 Check_Restriction
(No_Obsolescent_Features
, N
);
4340 if Warn_On_Obsolescent_Feature
then
4342 ("?j?attaching interrupt to task entry is an " &
4343 "obsolescent feature (RM J.7.1)", N
);
4345 ("\?j?use interrupt procedure instead", N
);
4348 -- Case of an address clause for a controlled object which we
4349 -- consider to be erroneous.
4351 elsif Is_Controlled
(Etype
(U_Ent
))
4352 or else Has_Controlled_Component
(Etype
(U_Ent
))
4355 ("??controlled object& must not be overlaid", Nam
, U_Ent
);
4357 ("\??Program_Error will be raised at run time", Nam
);
4358 Insert_Action
(Declaration_Node
(U_Ent
),
4359 Make_Raise_Program_Error
(Loc
,
4360 Reason
=> PE_Overlaid_Controlled_Object
));
4363 -- Case of address clause for a (non-controlled) object
4365 elsif Ekind_In
(U_Ent
, E_Variable
, E_Constant
) then
4367 Expr
: constant Node_Id
:= Expression
(N
);
4372 -- Exported variables cannot have an address clause, because
4373 -- this cancels the effect of the pragma Export.
4375 if Is_Exported
(U_Ent
) then
4377 ("cannot export object with address clause", Nam
);
4381 Find_Overlaid_Entity
(N
, O_Ent
, Off
);
4383 -- Overlaying controlled objects is erroneous
4386 and then (Has_Controlled_Component
(Etype
(O_Ent
))
4387 or else Is_Controlled
(Etype
(O_Ent
)))
4390 ("??cannot overlay with controlled object", Expr
);
4392 ("\??Program_Error will be raised at run time", Expr
);
4393 Insert_Action
(Declaration_Node
(U_Ent
),
4394 Make_Raise_Program_Error
(Loc
,
4395 Reason
=> PE_Overlaid_Controlled_Object
));
4398 elsif Present
(O_Ent
)
4399 and then Ekind
(U_Ent
) = E_Constant
4400 and then not Is_Constant_Object
(O_Ent
)
4402 Error_Msg_N
("??constant overlays a variable", Expr
);
4404 -- Imported variables can have an address clause, but then
4405 -- the import is pretty meaningless except to suppress
4406 -- initializations, so we do not need such variables to
4407 -- be statically allocated (and in fact it causes trouble
4408 -- if the address clause is a local value).
4410 elsif Is_Imported
(U_Ent
) then
4411 Set_Is_Statically_Allocated
(U_Ent
, False);
4414 -- We mark a possible modification of a variable with an
4415 -- address clause, since it is likely aliasing is occurring.
4417 Note_Possible_Modification
(Nam
, Sure
=> False);
4419 -- Here we are checking for explicit overlap of one variable
4420 -- by another, and if we find this then mark the overlapped
4421 -- variable as also being volatile to prevent unwanted
4422 -- optimizations. This is a significant pessimization so
4423 -- avoid it when there is an offset, i.e. when the object
4424 -- is composite; they cannot be optimized easily anyway.
4427 and then Is_Object
(O_Ent
)
4430 -- The following test is an expedient solution to what
4431 -- is really a problem in CodePeer. Suppressing the
4432 -- Set_Treat_As_Volatile call here prevents later
4433 -- generation (in some cases) of trees that CodePeer
4434 -- should, but currently does not, handle correctly.
4435 -- This test should probably be removed when CodePeer
4436 -- is improved, just because we want the tree CodePeer
4437 -- analyzes to match the tree for which we generate code
4438 -- as closely as is practical. ???
4440 and then not CodePeer_Mode
4442 -- ??? O_Ent might not be in current unit
4444 Set_Treat_As_Volatile
(O_Ent
);
4447 -- Legality checks on the address clause for initialized
4448 -- objects is deferred until the freeze point, because
4449 -- a subsequent pragma might indicate that the object
4450 -- is imported and thus not initialized. Also, the address
4451 -- clause might involve entities that have yet to be
4454 Set_Has_Delayed_Freeze
(U_Ent
);
4456 -- If an initialization call has been generated for this
4457 -- object, it needs to be deferred to after the freeze node
4458 -- we have just now added, otherwise GIGI will see a
4459 -- reference to the variable (as actual to the IP call)
4460 -- before its definition.
4463 Init_Call
: constant Node_Id
:=
4464 Remove_Init_Call
(U_Ent
, N
);
4467 if Present
(Init_Call
) then
4468 Append_Freeze_Action
(U_Ent
, Init_Call
);
4470 -- Reset Initialization_Statements pointer so that
4471 -- if there is a pragma Import further down, it can
4472 -- clear any default initialization.
4474 Set_Initialization_Statements
(U_Ent
, Init_Call
);
4478 if Is_Exported
(U_Ent
) then
4480 ("& cannot be exported if an address clause is given",
4483 ("\define and export a variable "
4484 & "that holds its address instead", Nam
);
4487 -- Entity has delayed freeze, so we will generate an
4488 -- alignment check at the freeze point unless suppressed.
4490 if not Range_Checks_Suppressed
(U_Ent
)
4491 and then not Alignment_Checks_Suppressed
(U_Ent
)
4493 Set_Check_Address_Alignment
(N
);
4496 -- Kill the size check code, since we are not allocating
4497 -- the variable, it is somewhere else.
4499 Kill_Size_Check_Code
(U_Ent
);
4501 -- If the address clause is of the form:
4503 -- for Y'Address use X'Address
4507 -- Const : constant Address := X'Address;
4509 -- for Y'Address use Const;
4511 -- then we make an entry in the table for checking the size
4512 -- and alignment of the overlaying variable. We defer this
4513 -- check till after code generation to take full advantage
4514 -- of the annotation done by the back end.
4516 -- If the entity has a generic type, the check will be
4517 -- performed in the instance if the actual type justifies
4518 -- it, and we do not insert the clause in the table to
4519 -- prevent spurious warnings.
4521 -- Note: we used to test Comes_From_Source and only give
4522 -- this warning for source entities, but we have removed
4523 -- this test. It really seems bogus to generate overlays
4524 -- that would trigger this warning in generated code.
4525 -- Furthermore, by removing the test, we handle the
4526 -- aspect case properly.
4528 if Address_Clause_Overlay_Warnings
4529 and then Present
(O_Ent
)
4530 and then Is_Object
(O_Ent
)
4532 if not Is_Generic_Type
(Etype
(U_Ent
)) then
4533 Address_Clause_Checks
.Append
((N
, U_Ent
, O_Ent
, Off
));
4536 -- If variable overlays a constant view, and we are
4537 -- warning on overlays, then mark the variable as
4538 -- overlaying a constant (we will give warnings later
4539 -- if this variable is assigned).
4541 if Is_Constant_Object
(O_Ent
)
4542 and then Ekind
(U_Ent
) = E_Variable
4544 Set_Overlays_Constant
(U_Ent
);
4549 -- Not a valid entity for an address clause
4552 Error_Msg_N
("address cannot be given for &", Nam
);
4560 -- Alignment attribute definition clause
4562 when Attribute_Alignment
=> Alignment
: declare
4563 Align
: constant Uint
:= Get_Alignment_Value
(Expr
);
4564 Max_Align
: constant Uint
:= UI_From_Int
(Maximum_Alignment
);
4569 if not Is_Type
(U_Ent
)
4570 and then Ekind
(U_Ent
) /= E_Variable
4571 and then Ekind
(U_Ent
) /= E_Constant
4573 Error_Msg_N
("alignment cannot be given for &", Nam
);
4575 elsif Duplicate_Clause
then
4578 elsif Align
/= No_Uint
then
4579 Set_Has_Alignment_Clause
(U_Ent
);
4581 -- Tagged type case, check for attempt to set alignment to a
4582 -- value greater than Max_Align, and reset if so.
4584 if Is_Tagged_Type
(U_Ent
) and then Align
> Max_Align
then
4586 ("alignment for & set to Maximum_Aligment??", Nam
);
4587 Set_Alignment
(U_Ent
, Max_Align
);
4592 Set_Alignment
(U_Ent
, Align
);
4595 -- For an array type, U_Ent is the first subtype. In that case,
4596 -- also set the alignment of the anonymous base type so that
4597 -- other subtypes (such as the itypes for aggregates of the
4598 -- type) also receive the expected alignment.
4600 if Is_Array_Type
(U_Ent
) then
4601 Set_Alignment
(Base_Type
(U_Ent
), Align
);
4610 -- Bit_Order attribute definition clause
4612 when Attribute_Bit_Order
=> Bit_Order
: declare
4614 if not Is_Record_Type
(U_Ent
) then
4616 ("Bit_Order can only be defined for record type", Nam
);
4618 elsif Duplicate_Clause
then
4622 Analyze_And_Resolve
(Expr
, RTE
(RE_Bit_Order
));
4624 if Etype
(Expr
) = Any_Type
then
4627 elsif not Is_OK_Static_Expression
(Expr
) then
4628 Flag_Non_Static_Expr
4629 ("Bit_Order requires static expression!", Expr
);
4632 if (Expr_Value
(Expr
) = 0) /= Bytes_Big_Endian
then
4633 Set_Reverse_Bit_Order
(Base_Type
(U_Ent
), True);
4639 --------------------
4640 -- Component_Size --
4641 --------------------
4643 -- Component_Size attribute definition clause
4645 when Attribute_Component_Size
=> Component_Size_Case
: declare
4646 Csize
: constant Uint
:= Static_Integer
(Expr
);
4650 New_Ctyp
: Entity_Id
;
4654 if not Is_Array_Type
(U_Ent
) then
4655 Error_Msg_N
("component size requires array type", Nam
);
4659 Btype
:= Base_Type
(U_Ent
);
4660 Ctyp
:= Component_Type
(Btype
);
4662 if Duplicate_Clause
then
4665 elsif Rep_Item_Too_Early
(Btype
, N
) then
4668 elsif Csize
/= No_Uint
then
4669 Check_Size
(Expr
, Ctyp
, Csize
, Biased
);
4671 -- For the biased case, build a declaration for a subtype that
4672 -- will be used to represent the biased subtype that reflects
4673 -- the biased representation of components. We need the subtype
4674 -- to get proper conversions on referencing elements of the
4675 -- array. Note: component size clauses are ignored in VM mode.
4677 if VM_Target
= No_VM
then
4680 Make_Defining_Identifier
(Loc
,
4682 New_External_Name
(Chars
(U_Ent
), 'C', 0, 'T'));
4685 Make_Subtype_Declaration
(Loc
,
4686 Defining_Identifier
=> New_Ctyp
,
4687 Subtype_Indication
=>
4688 New_Occurrence_Of
(Component_Type
(Btype
), Loc
));
4690 Set_Parent
(Decl
, N
);
4691 Analyze
(Decl
, Suppress
=> All_Checks
);
4693 Set_Has_Delayed_Freeze
(New_Ctyp
, False);
4694 Set_Esize
(New_Ctyp
, Csize
);
4695 Set_RM_Size
(New_Ctyp
, Csize
);
4696 Init_Alignment
(New_Ctyp
);
4697 Set_Is_Itype
(New_Ctyp
, True);
4698 Set_Associated_Node_For_Itype
(New_Ctyp
, U_Ent
);
4700 Set_Component_Type
(Btype
, New_Ctyp
);
4701 Set_Biased
(New_Ctyp
, N
, "component size clause");
4704 Set_Component_Size
(Btype
, Csize
);
4706 -- For VM case, we ignore component size clauses
4709 -- Give a warning unless we are in GNAT mode, in which case
4710 -- the warning is suppressed since it is not useful.
4712 if not GNAT_Mode
then
4714 ("component size ignored in this configuration??", N
);
4718 -- Deal with warning on overridden size
4720 if Warn_On_Overridden_Size
4721 and then Has_Size_Clause
(Ctyp
)
4722 and then RM_Size
(Ctyp
) /= Csize
4725 ("component size overrides size clause for&?S?", N
, Ctyp
);
4728 Set_Has_Component_Size_Clause
(Btype
, True);
4729 Set_Has_Non_Standard_Rep
(Btype
, True);
4731 end Component_Size_Case
;
4733 -----------------------
4734 -- Constant_Indexing --
4735 -----------------------
4737 when Attribute_Constant_Indexing
=>
4738 Check_Indexing_Functions
;
4744 when Attribute_CPU
=> CPU
:
4746 -- CPU attribute definition clause not allowed except from aspect
4749 if From_Aspect_Specification
(N
) then
4750 if not Is_Task_Type
(U_Ent
) then
4751 Error_Msg_N
("CPU can only be defined for task", Nam
);
4753 elsif Duplicate_Clause
then
4757 -- The expression must be analyzed in the special manner
4758 -- described in "Handling of Default and Per-Object
4759 -- Expressions" in sem.ads.
4761 -- The visibility to the discriminants must be restored
4763 Push_Scope_And_Install_Discriminants
(U_Ent
);
4764 Preanalyze_Spec_Expression
(Expr
, RTE
(RE_CPU_Range
));
4765 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
4767 if not Is_OK_Static_Expression
(Expr
) then
4768 Check_Restriction
(Static_Priorities
, Expr
);
4774 ("attribute& cannot be set with definition clause", N
);
4778 ----------------------
4779 -- Default_Iterator --
4780 ----------------------
4782 when Attribute_Default_Iterator
=> Default_Iterator
: declare
4786 if not Is_Tagged_Type
(U_Ent
) then
4788 ("aspect Default_Iterator applies to tagged type", Nam
);
4791 Check_Iterator_Functions
;
4795 if not Is_Entity_Name
(Expr
)
4796 or else Ekind
(Entity
(Expr
)) /= E_Function
4798 Error_Msg_N
("aspect Iterator must be a function", Expr
);
4800 Func
:= Entity
(Expr
);
4803 if No
(First_Formal
(Func
))
4804 or else Etype
(First_Formal
(Func
)) /= U_Ent
4807 ("Default Iterator must be a primitive of&", Func
, U_Ent
);
4809 end Default_Iterator
;
4811 ------------------------
4812 -- Dispatching_Domain --
4813 ------------------------
4815 when Attribute_Dispatching_Domain
=> Dispatching_Domain
:
4817 -- Dispatching_Domain attribute definition clause not allowed
4818 -- except from aspect specification.
4820 if From_Aspect_Specification
(N
) then
4821 if not Is_Task_Type
(U_Ent
) then
4822 Error_Msg_N
("Dispatching_Domain can only be defined" &
4826 elsif Duplicate_Clause
then
4830 -- The expression must be analyzed in the special manner
4831 -- described in "Handling of Default and Per-Object
4832 -- Expressions" in sem.ads.
4834 -- The visibility to the discriminants must be restored
4836 Push_Scope_And_Install_Discriminants
(U_Ent
);
4838 Preanalyze_Spec_Expression
4839 (Expr
, RTE
(RE_Dispatching_Domain
));
4841 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
4846 ("attribute& cannot be set with definition clause", N
);
4848 end Dispatching_Domain
;
4854 when Attribute_External_Tag
=> External_Tag
:
4856 if not Is_Tagged_Type
(U_Ent
) then
4857 Error_Msg_N
("should be a tagged type", Nam
);
4860 if Duplicate_Clause
then
4864 Analyze_And_Resolve
(Expr
, Standard_String
);
4866 if not Is_OK_Static_Expression
(Expr
) then
4867 Flag_Non_Static_Expr
4868 ("static string required for tag name!", Nam
);
4871 if VM_Target
/= No_VM
then
4872 Error_Msg_Name_1
:= Attr
;
4874 ("% attribute unsupported in this configuration", Nam
);
4877 if not Is_Library_Level_Entity
(U_Ent
) then
4879 ("??non-unique external tag supplied for &", N
, U_Ent
);
4881 ("\??same external tag applies to all "
4882 & "subprogram calls", N
);
4884 ("\??corresponding internal tag cannot be obtained", N
);
4889 --------------------------
4890 -- Implicit_Dereference --
4891 --------------------------
4893 when Attribute_Implicit_Dereference
=>
4895 -- Legality checks already performed at the point of the type
4896 -- declaration, aspect is not delayed.
4904 when Attribute_Input
=>
4905 Analyze_Stream_TSS_Definition
(TSS_Stream_Input
);
4906 Set_Has_Specified_Stream_Input
(Ent
);
4908 ------------------------
4909 -- Interrupt_Priority --
4910 ------------------------
4912 when Attribute_Interrupt_Priority
=> Interrupt_Priority
:
4914 -- Interrupt_Priority attribute definition clause not allowed
4915 -- except from aspect specification.
4917 if From_Aspect_Specification
(N
) then
4918 if not Is_Concurrent_Type
(U_Ent
) then
4920 ("Interrupt_Priority can only be defined for task "
4921 & "and protected object", Nam
);
4923 elsif Duplicate_Clause
then
4927 -- The expression must be analyzed in the special manner
4928 -- described in "Handling of Default and Per-Object
4929 -- Expressions" in sem.ads.
4931 -- The visibility to the discriminants must be restored
4933 Push_Scope_And_Install_Discriminants
(U_Ent
);
4935 Preanalyze_Spec_Expression
4936 (Expr
, RTE
(RE_Interrupt_Priority
));
4938 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
4943 ("attribute& cannot be set with definition clause", N
);
4945 end Interrupt_Priority
;
4951 when Attribute_Iterable
=>
4954 if Nkind
(Expr
) /= N_Aggregate
then
4955 Error_Msg_N
("aspect Iterable must be an aggregate", Expr
);
4962 Assoc
:= First
(Component_Associations
(Expr
));
4963 while Present
(Assoc
) loop
4964 if not Is_Entity_Name
(Expression
(Assoc
)) then
4965 Error_Msg_N
("value must be a function", Assoc
);
4972 ----------------------
4973 -- Iterator_Element --
4974 ----------------------
4976 when Attribute_Iterator_Element
=>
4979 if not Is_Entity_Name
(Expr
)
4980 or else not Is_Type
(Entity
(Expr
))
4982 Error_Msg_N
("aspect Iterator_Element must be a type", Expr
);
4989 -- Machine radix attribute definition clause
4991 when Attribute_Machine_Radix
=> Machine_Radix
: declare
4992 Radix
: constant Uint
:= Static_Integer
(Expr
);
4995 if not Is_Decimal_Fixed_Point_Type
(U_Ent
) then
4996 Error_Msg_N
("decimal fixed-point type expected for &", Nam
);
4998 elsif Duplicate_Clause
then
5001 elsif Radix
/= No_Uint
then
5002 Set_Has_Machine_Radix_Clause
(U_Ent
);
5003 Set_Has_Non_Standard_Rep
(Base_Type
(U_Ent
));
5007 elsif Radix
= 10 then
5008 Set_Machine_Radix_10
(U_Ent
);
5010 Error_Msg_N
("machine radix value must be 2 or 10", Expr
);
5019 -- Object_Size attribute definition clause
5021 when Attribute_Object_Size
=> Object_Size
: declare
5022 Size
: constant Uint
:= Static_Integer
(Expr
);
5025 pragma Warnings
(Off
, Biased
);
5028 if not Is_Type
(U_Ent
) then
5029 Error_Msg_N
("Object_Size cannot be given for &", Nam
);
5031 elsif Duplicate_Clause
then
5035 Check_Size
(Expr
, U_Ent
, Size
, Biased
);
5037 if Is_Scalar_Type
(U_Ent
) then
5038 if Size
/= 8 and then Size
/= 16 and then Size
/= 32
5039 and then UI_Mod
(Size
, 64) /= 0
5042 ("Object_Size must be 8, 16, 32, or multiple of 64",
5046 elsif Size
mod 8 /= 0 then
5047 Error_Msg_N
("Object_Size must be a multiple of 8", Expr
);
5050 Set_Esize
(U_Ent
, Size
);
5051 Set_Has_Object_Size_Clause
(U_Ent
);
5052 Alignment_Check_For_Size_Change
(U_Ent
, Size
);
5060 when Attribute_Output
=>
5061 Analyze_Stream_TSS_Definition
(TSS_Stream_Output
);
5062 Set_Has_Specified_Stream_Output
(Ent
);
5068 when Attribute_Priority
=> Priority
:
5070 -- Priority attribute definition clause not allowed except from
5071 -- aspect specification.
5073 if From_Aspect_Specification
(N
) then
5074 if not (Is_Concurrent_Type
(U_Ent
)
5075 or else Ekind
(U_Ent
) = E_Procedure
)
5078 ("Priority can only be defined for task and protected "
5081 elsif Duplicate_Clause
then
5085 -- The expression must be analyzed in the special manner
5086 -- described in "Handling of Default and Per-Object
5087 -- Expressions" in sem.ads.
5089 -- The visibility to the discriminants must be restored
5091 Push_Scope_And_Install_Discriminants
(U_Ent
);
5092 Preanalyze_Spec_Expression
(Expr
, Standard_Integer
);
5093 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
5095 if not Is_OK_Static_Expression
(Expr
) then
5096 Check_Restriction
(Static_Priorities
, Expr
);
5102 ("attribute& cannot be set with definition clause", N
);
5110 when Attribute_Read
=>
5111 Analyze_Stream_TSS_Definition
(TSS_Stream_Read
);
5112 Set_Has_Specified_Stream_Read
(Ent
);
5114 --------------------------
5115 -- Scalar_Storage_Order --
5116 --------------------------
5118 -- Scalar_Storage_Order attribute definition clause
5120 when Attribute_Scalar_Storage_Order
=> Scalar_Storage_Order
: declare
5122 if not (Is_Record_Type
(U_Ent
) or else Is_Array_Type
(U_Ent
)) then
5124 ("Scalar_Storage_Order can only be defined for "
5125 & "record or array type", Nam
);
5127 elsif Duplicate_Clause
then
5131 Analyze_And_Resolve
(Expr
, RTE
(RE_Bit_Order
));
5133 if Etype
(Expr
) = Any_Type
then
5136 elsif not Is_OK_Static_Expression
(Expr
) then
5137 Flag_Non_Static_Expr
5138 ("Scalar_Storage_Order requires static expression!", Expr
);
5140 elsif (Expr_Value
(Expr
) = 0) /= Bytes_Big_Endian
then
5142 -- Here for the case of a non-default (i.e. non-confirming)
5143 -- Scalar_Storage_Order attribute definition.
5145 if Support_Nondefault_SSO_On_Target
then
5146 Set_Reverse_Storage_Order
(Base_Type
(U_Ent
), True);
5149 ("non-default Scalar_Storage_Order "
5150 & "not supported on target", Expr
);
5154 -- Clear SSO default indications since explicit setting of the
5155 -- order overrides the defaults.
5157 Set_SSO_Set_Low_By_Default
(Base_Type
(U_Ent
), False);
5158 Set_SSO_Set_High_By_Default
(Base_Type
(U_Ent
), False);
5160 end Scalar_Storage_Order
;
5166 -- Size attribute definition clause
5168 when Attribute_Size
=> Size
: declare
5169 Size
: constant Uint
:= Static_Integer
(Expr
);
5176 if Duplicate_Clause
then
5179 elsif not Is_Type
(U_Ent
)
5180 and then Ekind
(U_Ent
) /= E_Variable
5181 and then Ekind
(U_Ent
) /= E_Constant
5183 Error_Msg_N
("size cannot be given for &", Nam
);
5185 elsif Is_Array_Type
(U_Ent
)
5186 and then not Is_Constrained
(U_Ent
)
5189 ("size cannot be given for unconstrained array", Nam
);
5191 elsif Size
/= No_Uint
then
5192 if VM_Target
/= No_VM
and then not GNAT_Mode
then
5194 -- Size clause is not handled properly on VM targets.
5195 -- Display a warning unless we are in GNAT mode, in which
5196 -- case this is useless.
5199 ("size clauses are ignored in this configuration??", N
);
5202 if Is_Type
(U_Ent
) then
5205 Etyp
:= Etype
(U_Ent
);
5208 -- Check size, note that Gigi is in charge of checking that the
5209 -- size of an array or record type is OK. Also we do not check
5210 -- the size in the ordinary fixed-point case, since it is too
5211 -- early to do so (there may be subsequent small clause that
5212 -- affects the size). We can check the size if a small clause
5213 -- has already been given.
5215 if not Is_Ordinary_Fixed_Point_Type
(U_Ent
)
5216 or else Has_Small_Clause
(U_Ent
)
5218 Check_Size
(Expr
, Etyp
, Size
, Biased
);
5219 Set_Biased
(U_Ent
, N
, "size clause", Biased
);
5222 -- For types set RM_Size and Esize if possible
5224 if Is_Type
(U_Ent
) then
5225 Set_RM_Size
(U_Ent
, Size
);
5227 -- For elementary types, increase Object_Size to power of 2,
5228 -- but not less than a storage unit in any case (normally
5229 -- this means it will be byte addressable).
5231 -- For all other types, nothing else to do, we leave Esize
5232 -- (object size) unset, the back end will set it from the
5233 -- size and alignment in an appropriate manner.
5235 -- In both cases, we check whether the alignment must be
5236 -- reset in the wake of the size change.
5238 if Is_Elementary_Type
(U_Ent
) then
5239 if Size
<= System_Storage_Unit
then
5240 Init_Esize
(U_Ent
, System_Storage_Unit
);
5241 elsif Size
<= 16 then
5242 Init_Esize
(U_Ent
, 16);
5243 elsif Size
<= 32 then
5244 Init_Esize
(U_Ent
, 32);
5246 Set_Esize
(U_Ent
, (Size
+ 63) / 64 * 64);
5249 Alignment_Check_For_Size_Change
(U_Ent
, Esize
(U_Ent
));
5251 Alignment_Check_For_Size_Change
(U_Ent
, Size
);
5254 -- For objects, set Esize only
5257 if Is_Elementary_Type
(Etyp
) then
5258 if Size
/= System_Storage_Unit
5260 Size
/= System_Storage_Unit
* 2
5262 Size
/= System_Storage_Unit
* 4
5264 Size
/= System_Storage_Unit
* 8
5266 Error_Msg_Uint_1
:= UI_From_Int
(System_Storage_Unit
);
5267 Error_Msg_Uint_2
:= Error_Msg_Uint_1
* 8;
5269 ("size for primitive object must be a power of 2"
5270 & " in the range ^-^", N
);
5274 Set_Esize
(U_Ent
, Size
);
5277 Set_Has_Size_Clause
(U_Ent
);
5285 -- Small attribute definition clause
5287 when Attribute_Small
=> Small
: declare
5288 Implicit_Base
: constant Entity_Id
:= Base_Type
(U_Ent
);
5292 Analyze_And_Resolve
(Expr
, Any_Real
);
5294 if Etype
(Expr
) = Any_Type
then
5297 elsif not Is_OK_Static_Expression
(Expr
) then
5298 Flag_Non_Static_Expr
5299 ("small requires static expression!", Expr
);
5303 Small
:= Expr_Value_R
(Expr
);
5305 if Small
<= Ureal_0
then
5306 Error_Msg_N
("small value must be greater than zero", Expr
);
5312 if not Is_Ordinary_Fixed_Point_Type
(U_Ent
) then
5314 ("small requires an ordinary fixed point type", Nam
);
5316 elsif Has_Small_Clause
(U_Ent
) then
5317 Error_Msg_N
("small already given for &", Nam
);
5319 elsif Small
> Delta_Value
(U_Ent
) then
5321 ("small value must not be greater than delta value", Nam
);
5324 Set_Small_Value
(U_Ent
, Small
);
5325 Set_Small_Value
(Implicit_Base
, Small
);
5326 Set_Has_Small_Clause
(U_Ent
);
5327 Set_Has_Small_Clause
(Implicit_Base
);
5328 Set_Has_Non_Standard_Rep
(Implicit_Base
);
5336 -- Storage_Pool attribute definition clause
5338 when Attribute_Storage_Pool | Attribute_Simple_Storage_Pool
=> declare
5343 if Ekind
(U_Ent
) = E_Access_Subprogram_Type
then
5345 ("storage pool cannot be given for access-to-subprogram type",
5350 Ekind_In
(U_Ent
, E_Access_Type
, E_General_Access_Type
)
5353 ("storage pool can only be given for access types", Nam
);
5356 elsif Is_Derived_Type
(U_Ent
) then
5358 ("storage pool cannot be given for a derived access type",
5361 elsif Duplicate_Clause
then
5364 elsif Present
(Associated_Storage_Pool
(U_Ent
)) then
5365 Error_Msg_N
("storage pool already given for &", Nam
);
5369 -- Check for Storage_Size previously given
5372 SS
: constant Node_Id
:=
5373 Get_Attribute_Definition_Clause
5374 (U_Ent
, Attribute_Storage_Size
);
5376 if Present
(SS
) then
5377 Check_Pool_Size_Clash
(U_Ent
, N
, SS
);
5381 -- Storage_Pool case
5383 if Id
= Attribute_Storage_Pool
then
5385 (Expr
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
5387 -- In the Simple_Storage_Pool case, we allow a variable of any
5388 -- simple storage pool type, so we Resolve without imposing an
5392 Analyze_And_Resolve
(Expr
);
5394 if not Present
(Get_Rep_Pragma
5395 (Etype
(Expr
), Name_Simple_Storage_Pool_Type
))
5398 ("expression must be of a simple storage pool type", Expr
);
5402 if not Denotes_Variable
(Expr
) then
5403 Error_Msg_N
("storage pool must be a variable", Expr
);
5407 if Nkind
(Expr
) = N_Type_Conversion
then
5408 T
:= Etype
(Expression
(Expr
));
5413 -- The Stack_Bounded_Pool is used internally for implementing
5414 -- access types with a Storage_Size. Since it only work properly
5415 -- when used on one specific type, we need to check that it is not
5416 -- hijacked improperly:
5418 -- type T is access Integer;
5419 -- for T'Storage_Size use n;
5420 -- type Q is access Float;
5421 -- for Q'Storage_Size use T'Storage_Size; -- incorrect
5423 if RTE_Available
(RE_Stack_Bounded_Pool
)
5424 and then Base_Type
(T
) = RTE
(RE_Stack_Bounded_Pool
)
5426 Error_Msg_N
("non-shareable internal Pool", Expr
);
5430 -- If the argument is a name that is not an entity name, then
5431 -- we construct a renaming operation to define an entity of
5432 -- type storage pool.
5434 if not Is_Entity_Name
(Expr
)
5435 and then Is_Object_Reference
(Expr
)
5437 Pool
:= Make_Temporary
(Loc
, 'P', Expr
);
5440 Rnode
: constant Node_Id
:=
5441 Make_Object_Renaming_Declaration
(Loc
,
5442 Defining_Identifier
=> Pool
,
5444 New_Occurrence_Of
(Etype
(Expr
), Loc
),
5448 -- If the attribute definition clause comes from an aspect
5449 -- clause, then insert the renaming before the associated
5450 -- entity's declaration, since the attribute clause has
5451 -- not yet been appended to the declaration list.
5453 if From_Aspect_Specification
(N
) then
5454 Insert_Before
(Parent
(Entity
(N
)), Rnode
);
5456 Insert_Before
(N
, Rnode
);
5460 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
5463 elsif Is_Entity_Name
(Expr
) then
5464 Pool
:= Entity
(Expr
);
5466 -- If pool is a renamed object, get original one. This can
5467 -- happen with an explicit renaming, and within instances.
5469 while Present
(Renamed_Object
(Pool
))
5470 and then Is_Entity_Name
(Renamed_Object
(Pool
))
5472 Pool
:= Entity
(Renamed_Object
(Pool
));
5475 if Present
(Renamed_Object
(Pool
))
5476 and then Nkind
(Renamed_Object
(Pool
)) = N_Type_Conversion
5477 and then Is_Entity_Name
(Expression
(Renamed_Object
(Pool
)))
5479 Pool
:= Entity
(Expression
(Renamed_Object
(Pool
)));
5482 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
5484 elsif Nkind
(Expr
) = N_Type_Conversion
5485 and then Is_Entity_Name
(Expression
(Expr
))
5486 and then Nkind
(Original_Node
(Expr
)) = N_Attribute_Reference
5488 Pool
:= Entity
(Expression
(Expr
));
5489 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
5492 Error_Msg_N
("incorrect reference to a Storage Pool", Expr
);
5501 -- Storage_Size attribute definition clause
5503 when Attribute_Storage_Size
=> Storage_Size
: declare
5504 Btype
: constant Entity_Id
:= Base_Type
(U_Ent
);
5507 if Is_Task_Type
(U_Ent
) then
5509 -- Check obsolescent (but never obsolescent if from aspect)
5511 if not From_Aspect_Specification
(N
) then
5512 Check_Restriction
(No_Obsolescent_Features
, N
);
5514 if Warn_On_Obsolescent_Feature
then
5516 ("?j?storage size clause for task is an " &
5517 "obsolescent feature (RM J.9)", N
);
5518 Error_Msg_N
("\?j?use Storage_Size pragma instead", N
);
5525 if not Is_Access_Type
(U_Ent
)
5526 and then Ekind
(U_Ent
) /= E_Task_Type
5528 Error_Msg_N
("storage size cannot be given for &", Nam
);
5530 elsif Is_Access_Type
(U_Ent
) and Is_Derived_Type
(U_Ent
) then
5532 ("storage size cannot be given for a derived access type",
5535 elsif Duplicate_Clause
then
5539 Analyze_And_Resolve
(Expr
, Any_Integer
);
5541 if Is_Access_Type
(U_Ent
) then
5543 -- Check for Storage_Pool previously given
5546 SP
: constant Node_Id
:=
5547 Get_Attribute_Definition_Clause
5548 (U_Ent
, Attribute_Storage_Pool
);
5551 if Present
(SP
) then
5552 Check_Pool_Size_Clash
(U_Ent
, SP
, N
);
5556 -- Special case of for x'Storage_Size use 0
5558 if Is_OK_Static_Expression
(Expr
)
5559 and then Expr_Value
(Expr
) = 0
5561 Set_No_Pool_Assigned
(Btype
);
5565 Set_Has_Storage_Size_Clause
(Btype
);
5573 when Attribute_Stream_Size
=> Stream_Size
: declare
5574 Size
: constant Uint
:= Static_Integer
(Expr
);
5577 if Ada_Version
<= Ada_95
then
5578 Check_Restriction
(No_Implementation_Attributes
, N
);
5581 if Duplicate_Clause
then
5584 elsif Is_Elementary_Type
(U_Ent
) then
5585 if Size
/= System_Storage_Unit
5587 Size
/= System_Storage_Unit
* 2
5589 Size
/= System_Storage_Unit
* 4
5591 Size
/= System_Storage_Unit
* 8
5593 Error_Msg_Uint_1
:= UI_From_Int
(System_Storage_Unit
);
5595 ("stream size for elementary type must be a"
5596 & " power of 2 and at least ^", N
);
5598 elsif RM_Size
(U_Ent
) > Size
then
5599 Error_Msg_Uint_1
:= RM_Size
(U_Ent
);
5601 ("stream size for elementary type must be a"
5602 & " power of 2 and at least ^", N
);
5605 Set_Has_Stream_Size_Clause
(U_Ent
);
5608 Error_Msg_N
("Stream_Size cannot be given for &", Nam
);
5616 -- Value_Size attribute definition clause
5618 when Attribute_Value_Size
=> Value_Size
: declare
5619 Size
: constant Uint
:= Static_Integer
(Expr
);
5623 if not Is_Type
(U_Ent
) then
5624 Error_Msg_N
("Value_Size cannot be given for &", Nam
);
5626 elsif Duplicate_Clause
then
5629 elsif Is_Array_Type
(U_Ent
)
5630 and then not Is_Constrained
(U_Ent
)
5633 ("Value_Size cannot be given for unconstrained array", Nam
);
5636 if Is_Elementary_Type
(U_Ent
) then
5637 Check_Size
(Expr
, U_Ent
, Size
, Biased
);
5638 Set_Biased
(U_Ent
, N
, "value size clause", Biased
);
5641 Set_RM_Size
(U_Ent
, Size
);
5645 -----------------------
5646 -- Variable_Indexing --
5647 -----------------------
5649 when Attribute_Variable_Indexing
=>
5650 Check_Indexing_Functions
;
5656 when Attribute_Write
=>
5657 Analyze_Stream_TSS_Definition
(TSS_Stream_Write
);
5658 Set_Has_Specified_Stream_Write
(Ent
);
5660 -- All other attributes cannot be set
5664 ("attribute& cannot be set with definition clause", N
);
5667 -- The test for the type being frozen must be performed after any
5668 -- expression the clause has been analyzed since the expression itself
5669 -- might cause freezing that makes the clause illegal.
5671 if Rep_Item_Too_Late
(U_Ent
, N
, FOnly
) then
5674 end Analyze_Attribute_Definition_Clause
;
5676 ----------------------------
5677 -- Analyze_Code_Statement --
5678 ----------------------------
5680 procedure Analyze_Code_Statement
(N
: Node_Id
) is
5681 HSS
: constant Node_Id
:= Parent
(N
);
5682 SBody
: constant Node_Id
:= Parent
(HSS
);
5683 Subp
: constant Entity_Id
:= Current_Scope
;
5690 -- Analyze and check we get right type, note that this implements the
5691 -- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that
5692 -- is the only way that Asm_Insn could possibly be visible.
5694 Analyze_And_Resolve
(Expression
(N
));
5696 if Etype
(Expression
(N
)) = Any_Type
then
5698 elsif Etype
(Expression
(N
)) /= RTE
(RE_Asm_Insn
) then
5699 Error_Msg_N
("incorrect type for code statement", N
);
5703 Check_Code_Statement
(N
);
5705 -- Make sure we appear in the handled statement sequence of a
5706 -- subprogram (RM 13.8(3)).
5708 if Nkind
(HSS
) /= N_Handled_Sequence_Of_Statements
5709 or else Nkind
(SBody
) /= N_Subprogram_Body
5712 ("code statement can only appear in body of subprogram", N
);
5716 -- Do remaining checks (RM 13.8(3)) if not already done
5718 if not Is_Machine_Code_Subprogram
(Subp
) then
5719 Set_Is_Machine_Code_Subprogram
(Subp
);
5721 -- No exception handlers allowed
5723 if Present
(Exception_Handlers
(HSS
)) then
5725 ("exception handlers not permitted in machine code subprogram",
5726 First
(Exception_Handlers
(HSS
)));
5729 -- No declarations other than use clauses and pragmas (we allow
5730 -- certain internally generated declarations as well).
5732 Decl
:= First
(Declarations
(SBody
));
5733 while Present
(Decl
) loop
5734 DeclO
:= Original_Node
(Decl
);
5735 if Comes_From_Source
(DeclO
)
5736 and not Nkind_In
(DeclO
, N_Pragma
,
5737 N_Use_Package_Clause
,
5739 N_Implicit_Label_Declaration
)
5742 ("this declaration not allowed in machine code subprogram",
5749 -- No statements other than code statements, pragmas, and labels.
5750 -- Again we allow certain internally generated statements.
5752 -- In Ada 2012, qualified expressions are names, and the code
5753 -- statement is initially parsed as a procedure call.
5755 Stmt
:= First
(Statements
(HSS
));
5756 while Present
(Stmt
) loop
5757 StmtO
:= Original_Node
(Stmt
);
5759 -- A procedure call transformed into a code statement is OK.
5761 if Ada_Version
>= Ada_2012
5762 and then Nkind
(StmtO
) = N_Procedure_Call_Statement
5763 and then Nkind
(Name
(StmtO
)) = N_Qualified_Expression
5767 elsif Comes_From_Source
(StmtO
)
5768 and then not Nkind_In
(StmtO
, N_Pragma
,
5773 ("this statement is not allowed in machine code subprogram",
5780 end Analyze_Code_Statement
;
5782 -----------------------------------------------
5783 -- Analyze_Enumeration_Representation_Clause --
5784 -----------------------------------------------
5786 procedure Analyze_Enumeration_Representation_Clause
(N
: Node_Id
) is
5787 Ident
: constant Node_Id
:= Identifier
(N
);
5788 Aggr
: constant Node_Id
:= Array_Aggregate
(N
);
5789 Enumtype
: Entity_Id
;
5796 Err
: Boolean := False;
5797 -- Set True to avoid cascade errors and crashes on incorrect source code
5799 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Universal_Integer
));
5800 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(Universal_Integer
));
5801 -- Allowed range of universal integer (= allowed range of enum lit vals)
5805 -- Minimum and maximum values of entries
5808 -- Pointer to node for literal providing max value
5811 if Ignore_Rep_Clauses
then
5812 Kill_Rep_Clause
(N
);
5816 -- Ignore enumeration rep clauses by default in CodePeer mode,
5817 -- unless -gnatd.I is specified, as a work around for potential false
5818 -- positive messages.
5820 if CodePeer_Mode
and not Debug_Flag_Dot_II
then
5824 -- First some basic error checks
5827 Enumtype
:= Entity
(Ident
);
5829 if Enumtype
= Any_Type
5830 or else Rep_Item_Too_Early
(Enumtype
, N
)
5834 Enumtype
:= Underlying_Type
(Enumtype
);
5837 if not Is_Enumeration_Type
(Enumtype
) then
5839 ("enumeration type required, found}",
5840 Ident
, First_Subtype
(Enumtype
));
5844 -- Ignore rep clause on generic actual type. This will already have
5845 -- been flagged on the template as an error, and this is the safest
5846 -- way to ensure we don't get a junk cascaded message in the instance.
5848 if Is_Generic_Actual_Type
(Enumtype
) then
5851 -- Type must be in current scope
5853 elsif Scope
(Enumtype
) /= Current_Scope
then
5854 Error_Msg_N
("type must be declared in this scope", Ident
);
5857 -- Type must be a first subtype
5859 elsif not Is_First_Subtype
(Enumtype
) then
5860 Error_Msg_N
("cannot give enumeration rep clause for subtype", N
);
5863 -- Ignore duplicate rep clause
5865 elsif Has_Enumeration_Rep_Clause
(Enumtype
) then
5866 Error_Msg_N
("duplicate enumeration rep clause ignored", N
);
5869 -- Don't allow rep clause for standard [wide_[wide_]]character
5871 elsif Is_Standard_Character_Type
(Enumtype
) then
5872 Error_Msg_N
("enumeration rep clause not allowed for this type", N
);
5875 -- Check that the expression is a proper aggregate (no parentheses)
5877 elsif Paren_Count
(Aggr
) /= 0 then
5879 ("extra parentheses surrounding aggregate not allowed",
5883 -- All tests passed, so set rep clause in place
5886 Set_Has_Enumeration_Rep_Clause
(Enumtype
);
5887 Set_Has_Enumeration_Rep_Clause
(Base_Type
(Enumtype
));
5890 -- Now we process the aggregate. Note that we don't use the normal
5891 -- aggregate code for this purpose, because we don't want any of the
5892 -- normal expansion activities, and a number of special semantic
5893 -- rules apply (including the component type being any integer type)
5895 Elit
:= First_Literal
(Enumtype
);
5897 -- First the positional entries if any
5899 if Present
(Expressions
(Aggr
)) then
5900 Expr
:= First
(Expressions
(Aggr
));
5901 while Present
(Expr
) loop
5903 Error_Msg_N
("too many entries in aggregate", Expr
);
5907 Val
:= Static_Integer
(Expr
);
5909 -- Err signals that we found some incorrect entries processing
5910 -- the list. The final checks for completeness and ordering are
5911 -- skipped in this case.
5913 if Val
= No_Uint
then
5916 elsif Val
< Lo
or else Hi
< Val
then
5917 Error_Msg_N
("value outside permitted range", Expr
);
5921 Set_Enumeration_Rep
(Elit
, Val
);
5922 Set_Enumeration_Rep_Expr
(Elit
, Expr
);
5928 -- Now process the named entries if present
5930 if Present
(Component_Associations
(Aggr
)) then
5931 Assoc
:= First
(Component_Associations
(Aggr
));
5932 while Present
(Assoc
) loop
5933 Choice
:= First
(Choices
(Assoc
));
5935 if Present
(Next
(Choice
)) then
5937 ("multiple choice not allowed here", Next
(Choice
));
5941 if Nkind
(Choice
) = N_Others_Choice
then
5942 Error_Msg_N
("others choice not allowed here", Choice
);
5945 elsif Nkind
(Choice
) = N_Range
then
5947 -- ??? should allow zero/one element range here
5949 Error_Msg_N
("range not allowed here", Choice
);
5953 Analyze_And_Resolve
(Choice
, Enumtype
);
5955 if Error_Posted
(Choice
) then
5960 if Is_Entity_Name
(Choice
)
5961 and then Is_Type
(Entity
(Choice
))
5963 Error_Msg_N
("subtype name not allowed here", Choice
);
5966 -- ??? should allow static subtype with zero/one entry
5968 elsif Etype
(Choice
) = Base_Type
(Enumtype
) then
5969 if not Is_OK_Static_Expression
(Choice
) then
5970 Flag_Non_Static_Expr
5971 ("non-static expression used for choice!", Choice
);
5975 Elit
:= Expr_Value_E
(Choice
);
5977 if Present
(Enumeration_Rep_Expr
(Elit
)) then
5979 Sloc
(Enumeration_Rep_Expr
(Elit
));
5981 ("representation for& previously given#",
5986 Set_Enumeration_Rep_Expr
(Elit
, Expression
(Assoc
));
5988 Expr
:= Expression
(Assoc
);
5989 Val
:= Static_Integer
(Expr
);
5991 if Val
= No_Uint
then
5994 elsif Val
< Lo
or else Hi
< Val
then
5995 Error_Msg_N
("value outside permitted range", Expr
);
5999 Set_Enumeration_Rep
(Elit
, Val
);
6009 -- Aggregate is fully processed. Now we check that a full set of
6010 -- representations was given, and that they are in range and in order.
6011 -- These checks are only done if no other errors occurred.
6017 Elit
:= First_Literal
(Enumtype
);
6018 while Present
(Elit
) loop
6019 if No
(Enumeration_Rep_Expr
(Elit
)) then
6020 Error_Msg_NE
("missing representation for&!", N
, Elit
);
6023 Val
:= Enumeration_Rep
(Elit
);
6025 if Min
= No_Uint
then
6029 if Val
/= No_Uint
then
6030 if Max
/= No_Uint
and then Val
<= Max
then
6032 ("enumeration value for& not ordered!",
6033 Enumeration_Rep_Expr
(Elit
), Elit
);
6036 Max_Node
:= Enumeration_Rep_Expr
(Elit
);
6040 -- If there is at least one literal whose representation is not
6041 -- equal to the Pos value, then note that this enumeration type
6042 -- has a non-standard representation.
6044 if Val
/= Enumeration_Pos
(Elit
) then
6045 Set_Has_Non_Standard_Rep
(Base_Type
(Enumtype
));
6052 -- Now set proper size information
6055 Minsize
: Uint
:= UI_From_Int
(Minimum_Size
(Enumtype
));
6058 if Has_Size_Clause
(Enumtype
) then
6060 -- All OK, if size is OK now
6062 if RM_Size
(Enumtype
) >= Minsize
then
6066 -- Try if we can get by with biasing
6069 UI_From_Int
(Minimum_Size
(Enumtype
, Biased
=> True));
6071 -- Error message if even biasing does not work
6073 if RM_Size
(Enumtype
) < Minsize
then
6074 Error_Msg_Uint_1
:= RM_Size
(Enumtype
);
6075 Error_Msg_Uint_2
:= Max
;
6077 ("previously given size (^) is too small "
6078 & "for this value (^)", Max_Node
);
6080 -- If biasing worked, indicate that we now have biased rep
6084 (Enumtype
, Size_Clause
(Enumtype
), "size clause");
6089 Set_RM_Size
(Enumtype
, Minsize
);
6090 Set_Enum_Esize
(Enumtype
);
6093 Set_RM_Size
(Base_Type
(Enumtype
), RM_Size
(Enumtype
));
6094 Set_Esize
(Base_Type
(Enumtype
), Esize
(Enumtype
));
6095 Set_Alignment
(Base_Type
(Enumtype
), Alignment
(Enumtype
));
6099 -- We repeat the too late test in case it froze itself
6101 if Rep_Item_Too_Late
(Enumtype
, N
) then
6104 end Analyze_Enumeration_Representation_Clause
;
6106 ----------------------------
6107 -- Analyze_Free_Statement --
6108 ----------------------------
6110 procedure Analyze_Free_Statement
(N
: Node_Id
) is
6112 Analyze
(Expression
(N
));
6113 end Analyze_Free_Statement
;
6115 ---------------------------
6116 -- Analyze_Freeze_Entity --
6117 ---------------------------
6119 procedure Analyze_Freeze_Entity
(N
: Node_Id
) is
6121 Freeze_Entity_Checks
(N
);
6122 end Analyze_Freeze_Entity
;
6124 -----------------------------------
6125 -- Analyze_Freeze_Generic_Entity --
6126 -----------------------------------
6128 procedure Analyze_Freeze_Generic_Entity
(N
: Node_Id
) is
6130 Freeze_Entity_Checks
(N
);
6131 end Analyze_Freeze_Generic_Entity
;
6133 ------------------------------------------
6134 -- Analyze_Record_Representation_Clause --
6135 ------------------------------------------
6137 -- Note: we check as much as we can here, but we can't do any checks
6138 -- based on the position values (e.g. overlap checks) until freeze time
6139 -- because especially in Ada 2005 (machine scalar mode), the processing
6140 -- for non-standard bit order can substantially change the positions.
6141 -- See procedure Check_Record_Representation_Clause (called from Freeze)
6142 -- for the remainder of this processing.
6144 procedure Analyze_Record_Representation_Clause
(N
: Node_Id
) is
6145 Ident
: constant Node_Id
:= Identifier
(N
);
6150 Hbit
: Uint
:= Uint_0
;
6154 Rectype
: Entity_Id
;
6157 function Is_Inherited
(Comp
: Entity_Id
) return Boolean;
6158 -- True if Comp is an inherited component in a record extension
6164 function Is_Inherited
(Comp
: Entity_Id
) return Boolean is
6165 Comp_Base
: Entity_Id
;
6168 if Ekind
(Rectype
) = E_Record_Subtype
then
6169 Comp_Base
:= Original_Record_Component
(Comp
);
6174 return Comp_Base
/= Original_Record_Component
(Comp_Base
);
6179 Is_Record_Extension
: Boolean;
6180 -- True if Rectype is a record extension
6182 CR_Pragma
: Node_Id
:= Empty
;
6183 -- Points to N_Pragma node if Complete_Representation pragma present
6185 -- Start of processing for Analyze_Record_Representation_Clause
6188 if Ignore_Rep_Clauses
then
6189 Kill_Rep_Clause
(N
);
6194 Rectype
:= Entity
(Ident
);
6196 if Rectype
= Any_Type
or else Rep_Item_Too_Early
(Rectype
, N
) then
6199 Rectype
:= Underlying_Type
(Rectype
);
6202 -- First some basic error checks
6204 if not Is_Record_Type
(Rectype
) then
6206 ("record type required, found}", Ident
, First_Subtype
(Rectype
));
6209 elsif Scope
(Rectype
) /= Current_Scope
then
6210 Error_Msg_N
("type must be declared in this scope", N
);
6213 elsif not Is_First_Subtype
(Rectype
) then
6214 Error_Msg_N
("cannot give record rep clause for subtype", N
);
6217 elsif Has_Record_Rep_Clause
(Rectype
) then
6218 Error_Msg_N
("duplicate record rep clause ignored", N
);
6221 elsif Rep_Item_Too_Late
(Rectype
, N
) then
6225 -- We know we have a first subtype, now possibly go the the anonymous
6226 -- base type to determine whether Rectype is a record extension.
6228 Recdef
:= Type_Definition
(Declaration_Node
(Base_Type
(Rectype
)));
6229 Is_Record_Extension
:=
6230 Nkind
(Recdef
) = N_Derived_Type_Definition
6231 and then Present
(Record_Extension_Part
(Recdef
));
6233 if Present
(Mod_Clause
(N
)) then
6235 Loc
: constant Source_Ptr
:= Sloc
(N
);
6236 M
: constant Node_Id
:= Mod_Clause
(N
);
6237 P
: constant List_Id
:= Pragmas_Before
(M
);
6241 pragma Warnings
(Off
, Mod_Val
);
6244 Check_Restriction
(No_Obsolescent_Features
, Mod_Clause
(N
));
6246 if Warn_On_Obsolescent_Feature
then
6248 ("?j?mod clause is an obsolescent feature (RM J.8)", N
);
6250 ("\?j?use alignment attribute definition clause instead", N
);
6257 -- In ASIS_Mode mode, expansion is disabled, but we must convert
6258 -- the Mod clause into an alignment clause anyway, so that the
6259 -- back-end can compute and back-annotate properly the size and
6260 -- alignment of types that may include this record.
6262 -- This seems dubious, this destroys the source tree in a manner
6263 -- not detectable by ASIS ???
6265 if Operating_Mode
= Check_Semantics
and then ASIS_Mode
then
6267 Make_Attribute_Definition_Clause
(Loc
,
6268 Name
=> New_Occurrence_Of
(Base_Type
(Rectype
), Loc
),
6269 Chars
=> Name_Alignment
,
6270 Expression
=> Relocate_Node
(Expression
(M
)));
6272 Set_From_At_Mod
(AtM_Nod
);
6273 Insert_After
(N
, AtM_Nod
);
6274 Mod_Val
:= Get_Alignment_Value
(Expression
(AtM_Nod
));
6275 Set_Mod_Clause
(N
, Empty
);
6278 -- Get the alignment value to perform error checking
6280 Mod_Val
:= Get_Alignment_Value
(Expression
(M
));
6285 -- For untagged types, clear any existing component clauses for the
6286 -- type. If the type is derived, this is what allows us to override
6287 -- a rep clause for the parent. For type extensions, the representation
6288 -- of the inherited components is inherited, so we want to keep previous
6289 -- component clauses for completeness.
6291 if not Is_Tagged_Type
(Rectype
) then
6292 Comp
:= First_Component_Or_Discriminant
(Rectype
);
6293 while Present
(Comp
) loop
6294 Set_Component_Clause
(Comp
, Empty
);
6295 Next_Component_Or_Discriminant
(Comp
);
6299 -- All done if no component clauses
6301 CC
:= First
(Component_Clauses
(N
));
6307 -- A representation like this applies to the base type
6309 Set_Has_Record_Rep_Clause
(Base_Type
(Rectype
));
6310 Set_Has_Non_Standard_Rep
(Base_Type
(Rectype
));
6311 Set_Has_Specified_Layout
(Base_Type
(Rectype
));
6313 -- Process the component clauses
6315 while Present
(CC
) loop
6319 if Nkind
(CC
) = N_Pragma
then
6322 -- The only pragma of interest is Complete_Representation
6324 if Pragma_Name
(CC
) = Name_Complete_Representation
then
6328 -- Processing for real component clause
6331 Posit
:= Static_Integer
(Position
(CC
));
6332 Fbit
:= Static_Integer
(First_Bit
(CC
));
6333 Lbit
:= Static_Integer
(Last_Bit
(CC
));
6336 and then Fbit
/= No_Uint
6337 and then Lbit
/= No_Uint
6341 ("position cannot be negative", Position
(CC
));
6345 ("first bit cannot be negative", First_Bit
(CC
));
6347 -- The Last_Bit specified in a component clause must not be
6348 -- less than the First_Bit minus one (RM-13.5.1(10)).
6350 elsif Lbit
< Fbit
- 1 then
6352 ("last bit cannot be less than first bit minus one",
6355 -- Values look OK, so find the corresponding record component
6356 -- Even though the syntax allows an attribute reference for
6357 -- implementation-defined components, GNAT does not allow the
6358 -- tag to get an explicit position.
6360 elsif Nkind
(Component_Name
(CC
)) = N_Attribute_Reference
then
6361 if Attribute_Name
(Component_Name
(CC
)) = Name_Tag
then
6362 Error_Msg_N
("position of tag cannot be specified", CC
);
6364 Error_Msg_N
("illegal component name", CC
);
6368 Comp
:= First_Entity
(Rectype
);
6369 while Present
(Comp
) loop
6370 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
6376 -- Maybe component of base type that is absent from
6377 -- statically constrained first subtype.
6379 Comp
:= First_Entity
(Base_Type
(Rectype
));
6380 while Present
(Comp
) loop
6381 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
6388 ("component clause is for non-existent field", CC
);
6390 -- Ada 2012 (AI05-0026): Any name that denotes a
6391 -- discriminant of an object of an unchecked union type
6392 -- shall not occur within a record_representation_clause.
6394 -- The general restriction of using record rep clauses on
6395 -- Unchecked_Union types has now been lifted. Since it is
6396 -- possible to introduce a record rep clause which mentions
6397 -- the discriminant of an Unchecked_Union in non-Ada 2012
6398 -- code, this check is applied to all versions of the
6401 elsif Ekind
(Comp
) = E_Discriminant
6402 and then Is_Unchecked_Union
(Rectype
)
6405 ("cannot reference discriminant of unchecked union",
6406 Component_Name
(CC
));
6408 elsif Is_Record_Extension
and then Is_Inherited
(Comp
) then
6410 ("component clause not allowed for inherited "
6411 & "component&", CC
, Comp
);
6413 elsif Present
(Component_Clause
(Comp
)) then
6415 -- Diagnose duplicate rep clause, or check consistency
6416 -- if this is an inherited component. In a double fault,
6417 -- there may be a duplicate inconsistent clause for an
6418 -- inherited component.
6420 if Scope
(Original_Record_Component
(Comp
)) = Rectype
6421 or else Parent
(Component_Clause
(Comp
)) = N
6423 Error_Msg_Sloc
:= Sloc
(Component_Clause
(Comp
));
6424 Error_Msg_N
("component clause previously given#", CC
);
6428 Rep1
: constant Node_Id
:= Component_Clause
(Comp
);
6430 if Intval
(Position
(Rep1
)) /=
6431 Intval
(Position
(CC
))
6432 or else Intval
(First_Bit
(Rep1
)) /=
6433 Intval
(First_Bit
(CC
))
6434 or else Intval
(Last_Bit
(Rep1
)) /=
6435 Intval
(Last_Bit
(CC
))
6438 ("component clause inconsistent "
6439 & "with representation of ancestor", CC
);
6441 elsif Warn_On_Redundant_Constructs
then
6443 ("?r?redundant confirming component clause "
6444 & "for component!", CC
);
6449 -- Normal case where this is the first component clause we
6450 -- have seen for this entity, so set it up properly.
6453 -- Make reference for field in record rep clause and set
6454 -- appropriate entity field in the field identifier.
6457 (Comp
, Component_Name
(CC
), Set_Ref
=> False);
6458 Set_Entity
(Component_Name
(CC
), Comp
);
6460 -- Update Fbit and Lbit to the actual bit number
6462 Fbit
:= Fbit
+ UI_From_Int
(SSU
) * Posit
;
6463 Lbit
:= Lbit
+ UI_From_Int
(SSU
) * Posit
;
6465 if Has_Size_Clause
(Rectype
)
6466 and then RM_Size
(Rectype
) <= Lbit
6469 ("bit number out of range of specified size",
6472 Set_Component_Clause
(Comp
, CC
);
6473 Set_Component_Bit_Offset
(Comp
, Fbit
);
6474 Set_Esize
(Comp
, 1 + (Lbit
- Fbit
));
6475 Set_Normalized_First_Bit
(Comp
, Fbit
mod SSU
);
6476 Set_Normalized_Position
(Comp
, Fbit
/ SSU
);
6478 if Warn_On_Overridden_Size
6479 and then Has_Size_Clause
(Etype
(Comp
))
6480 and then RM_Size
(Etype
(Comp
)) /= Esize
(Comp
)
6483 ("?S?component size overrides size clause for&",
6484 Component_Name
(CC
), Etype
(Comp
));
6487 -- This information is also set in the corresponding
6488 -- component of the base type, found by accessing the
6489 -- Original_Record_Component link if it is present.
6491 Ocomp
:= Original_Record_Component
(Comp
);
6498 (Component_Name
(CC
),
6504 (Comp
, First_Node
(CC
), "component clause", Biased
);
6506 if Present
(Ocomp
) then
6507 Set_Component_Clause
(Ocomp
, CC
);
6508 Set_Component_Bit_Offset
(Ocomp
, Fbit
);
6509 Set_Normalized_First_Bit
(Ocomp
, Fbit
mod SSU
);
6510 Set_Normalized_Position
(Ocomp
, Fbit
/ SSU
);
6511 Set_Esize
(Ocomp
, 1 + (Lbit
- Fbit
));
6513 Set_Normalized_Position_Max
6514 (Ocomp
, Normalized_Position
(Ocomp
));
6516 -- Note: we don't use Set_Biased here, because we
6517 -- already gave a warning above if needed, and we
6518 -- would get a duplicate for the same name here.
6520 Set_Has_Biased_Representation
6521 (Ocomp
, Has_Biased_Representation
(Comp
));
6524 if Esize
(Comp
) < 0 then
6525 Error_Msg_N
("component size is negative", CC
);
6536 -- Check missing components if Complete_Representation pragma appeared
6538 if Present
(CR_Pragma
) then
6539 Comp
:= First_Component_Or_Discriminant
(Rectype
);
6540 while Present
(Comp
) loop
6541 if No
(Component_Clause
(Comp
)) then
6543 ("missing component clause for &", CR_Pragma
, Comp
);
6546 Next_Component_Or_Discriminant
(Comp
);
6549 -- Give missing components warning if required
6551 elsif Warn_On_Unrepped_Components
then
6553 Num_Repped_Components
: Nat
:= 0;
6554 Num_Unrepped_Components
: Nat
:= 0;
6557 -- First count number of repped and unrepped components
6559 Comp
:= First_Component_Or_Discriminant
(Rectype
);
6560 while Present
(Comp
) loop
6561 if Present
(Component_Clause
(Comp
)) then
6562 Num_Repped_Components
:= Num_Repped_Components
+ 1;
6564 Num_Unrepped_Components
:= Num_Unrepped_Components
+ 1;
6567 Next_Component_Or_Discriminant
(Comp
);
6570 -- We are only interested in the case where there is at least one
6571 -- unrepped component, and at least half the components have rep
6572 -- clauses. We figure that if less than half have them, then the
6573 -- partial rep clause is really intentional. If the component
6574 -- type has no underlying type set at this point (as for a generic
6575 -- formal type), we don't know enough to give a warning on the
6578 if Num_Unrepped_Components
> 0
6579 and then Num_Unrepped_Components
< Num_Repped_Components
6581 Comp
:= First_Component_Or_Discriminant
(Rectype
);
6582 while Present
(Comp
) loop
6583 if No
(Component_Clause
(Comp
))
6584 and then Comes_From_Source
(Comp
)
6585 and then Present
(Underlying_Type
(Etype
(Comp
)))
6586 and then (Is_Scalar_Type
(Underlying_Type
(Etype
(Comp
)))
6587 or else Size_Known_At_Compile_Time
6588 (Underlying_Type
(Etype
(Comp
))))
6589 and then not Has_Warnings_Off
(Rectype
)
6591 Error_Msg_Sloc
:= Sloc
(Comp
);
6593 ("?C?no component clause given for & declared #",
6597 Next_Component_Or_Discriminant
(Comp
);
6602 end Analyze_Record_Representation_Clause
;
6604 -------------------------------------
6605 -- Build_Discrete_Static_Predicate --
6606 -------------------------------------
6608 procedure Build_Discrete_Static_Predicate
6613 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
6615 Non_Static
: exception;
6616 -- Raised if something non-static is found
6618 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
6620 BLo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Btyp
));
6621 BHi
: constant Uint
:= Expr_Value
(Type_High_Bound
(Btyp
));
6622 -- Low bound and high bound value of base type of Typ
6624 TLo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Typ
));
6625 THi
: constant Uint
:= Expr_Value
(Type_High_Bound
(Typ
));
6626 -- Low bound and high bound values of static subtype Typ
6631 -- One entry in a Rlist value, a single REnt (range entry) value denotes
6632 -- one range from Lo to Hi. To represent a single value range Lo = Hi =
6635 type RList
is array (Nat
range <>) of REnt
;
6636 -- A list of ranges. The ranges are sorted in increasing order, and are
6637 -- disjoint (there is a gap of at least one value between each range in
6638 -- the table). A value is in the set of ranges in Rlist if it lies
6639 -- within one of these ranges.
6641 False_Range
: constant RList
:=
6642 RList
'(1 .. 0 => REnt'(No_Uint
, No_Uint
));
6643 -- An empty set of ranges represents a range list that can never be
6644 -- satisfied, since there are no ranges in which the value could lie,
6645 -- so it does not lie in any of them. False_Range is a canonical value
6646 -- for this empty set, but general processing should test for an Rlist
6647 -- with length zero (see Is_False predicate), since other null ranges
6648 -- may appear which must be treated as False.
6650 True_Range
: constant RList
:= RList
'(1 => REnt'(BLo
, BHi
));
6651 -- Range representing True, value must be in the base range
6653 function "and" (Left
: RList
; Right
: RList
) return RList
;
6654 -- And's together two range lists, returning a range list. This is a set
6655 -- intersection operation.
6657 function "or" (Left
: RList
; Right
: RList
) return RList
;
6658 -- Or's together two range lists, returning a range list. This is a set
6661 function "not" (Right
: RList
) return RList
;
6662 -- Returns complement of a given range list, i.e. a range list
6663 -- representing all the values in TLo .. THi that are not in the input
6666 function Build_Val
(V
: Uint
) return Node_Id
;
6667 -- Return an analyzed N_Identifier node referencing this value, suitable
6668 -- for use as an entry in the Static_Discrte_Predicate list. This node
6669 -- is typed with the base type.
6671 function Build_Range
(Lo
: Uint
; Hi
: Uint
) return Node_Id
;
6672 -- Return an analyzed N_Range node referencing this range, suitable for
6673 -- use as an entry in the Static_Discrete_Predicate list. This node is
6674 -- typed with the base type.
6676 function Get_RList
(Exp
: Node_Id
) return RList
;
6677 -- This is a recursive routine that converts the given expression into a
6678 -- list of ranges, suitable for use in building the static predicate.
6680 function Is_False
(R
: RList
) return Boolean;
6681 pragma Inline
(Is_False
);
6682 -- Returns True if the given range list is empty, and thus represents a
6683 -- False list of ranges that can never be satisfied.
6685 function Is_True
(R
: RList
) return Boolean;
6686 -- Returns True if R trivially represents the True predicate by having a
6687 -- single range from BLo to BHi.
6689 function Is_Type_Ref
(N
: Node_Id
) return Boolean;
6690 pragma Inline
(Is_Type_Ref
);
6691 -- Returns if True if N is a reference to the type for the predicate in
6692 -- the expression (i.e. if it is an identifier whose Chars field matches
6693 -- the Nam given in the call). N must not be parenthesized, if the type
6694 -- name appears in parens, this routine will return False.
6696 function Lo_Val
(N
: Node_Id
) return Uint
;
6697 -- Given an entry from a Static_Discrete_Predicate list that is either
6698 -- a static expression or static range, gets either the expression value
6699 -- or the low bound of the range.
6701 function Hi_Val
(N
: Node_Id
) return Uint
;
6702 -- Given an entry from a Static_Discrete_Predicate list that is either
6703 -- a static expression or static range, gets either the expression value
6704 -- or the high bound of the range.
6706 function Membership_Entry
(N
: Node_Id
) return RList
;
6707 -- Given a single membership entry (range, value, or subtype), returns
6708 -- the corresponding range list. Raises Static_Error if not static.
6710 function Membership_Entries
(N
: Node_Id
) return RList
;
6711 -- Given an element on an alternatives list of a membership operation,
6712 -- returns the range list corresponding to this entry and all following
6713 -- entries (i.e. returns the "or" of this list of values).
6715 function Stat_Pred
(Typ
: Entity_Id
) return RList
;
6716 -- Given a type, if it has a static predicate, then return the predicate
6717 -- as a range list, otherwise raise Non_Static.
6723 function "and" (Left
: RList
; Right
: RList
) return RList
is
6725 -- First range of result
6727 SLeft
: Nat
:= Left
'First;
6728 -- Start of rest of left entries
6730 SRight
: Nat
:= Right
'First;
6731 -- Start of rest of right entries
6734 -- If either range is True, return the other
6736 if Is_True
(Left
) then
6738 elsif Is_True
(Right
) then
6742 -- If either range is False, return False
6744 if Is_False
(Left
) or else Is_False
(Right
) then
6748 -- Loop to remove entries at start that are disjoint, and thus just
6749 -- get discarded from the result entirely.
6752 -- If no operands left in either operand, result is false
6754 if SLeft
> Left
'Last or else SRight
> Right
'Last then
6757 -- Discard first left operand entry if disjoint with right
6759 elsif Left
(SLeft
).Hi
< Right
(SRight
).Lo
then
6762 -- Discard first right operand entry if disjoint with left
6764 elsif Right
(SRight
).Hi
< Left
(SLeft
).Lo
then
6765 SRight
:= SRight
+ 1;
6767 -- Otherwise we have an overlapping entry
6774 -- Now we have two non-null operands, and first entries overlap. The
6775 -- first entry in the result will be the overlapping part of these
6778 FEnt
:= REnt
'(Lo => UI_Max (Left (SLeft).Lo, Right (SRight).Lo),
6779 Hi => UI_Min (Left (SLeft).Hi, Right (SRight).Hi));
6781 -- Now we can remove the entry that ended at a lower value, since its
6782 -- contribution is entirely contained in Fent.
6784 if Left (SLeft).Hi <= Right (SRight).Hi then
6787 SRight := SRight + 1;
6790 -- Compute result by concatenating this first entry with the "and" of
6791 -- the remaining parts of the left and right operands. Note that if
6792 -- either of these is empty, "and" will yield empty, so that we will
6793 -- end up with just Fent, which is what we want in that case.
6796 FEnt & (Left (SLeft .. Left'Last) and Right (SRight .. Right'Last));
6803 function "not" (Right : RList) return RList is
6805 -- Return True if False range
6807 if Is_False (Right) then
6811 -- Return False if True range
6813 if Is_True (Right) then
6817 -- Here if not trivial case
6820 Result : RList (1 .. Right'Length + 1);
6821 -- May need one more entry for gap at beginning and end
6824 -- Number of entries stored in Result
6829 if Right (Right'First).Lo > TLo then
6831 Result (Count) := REnt'(TLo
, Right
(Right
'First).Lo
- 1);
6834 -- Gaps between ranges
6836 for J
in Right
'First .. Right
'Last - 1 loop
6838 Result
(Count
) := REnt
'(Right (J).Hi + 1, Right (J + 1).Lo - 1);
6843 if Right (Right'Last).Hi < THi then
6845 Result (Count) := REnt'(Right
(Right
'Last).Hi
+ 1, THi
);
6848 return Result
(1 .. Count
);
6856 function "or" (Left
: RList
; Right
: RList
) return RList
is
6858 -- First range of result
6860 SLeft
: Nat
:= Left
'First;
6861 -- Start of rest of left entries
6863 SRight
: Nat
:= Right
'First;
6864 -- Start of rest of right entries
6867 -- If either range is True, return True
6869 if Is_True
(Left
) or else Is_True
(Right
) then
6873 -- If either range is False (empty), return the other
6875 if Is_False
(Left
) then
6877 elsif Is_False
(Right
) then
6881 -- Initialize result first entry from left or right operand depending
6882 -- on which starts with the lower range.
6884 if Left
(SLeft
).Lo
< Right
(SRight
).Lo
then
6885 FEnt
:= Left
(SLeft
);
6888 FEnt
:= Right
(SRight
);
6889 SRight
:= SRight
+ 1;
6892 -- This loop eats ranges from left and right operands that are
6893 -- contiguous with the first range we are gathering.
6896 -- Eat first entry in left operand if contiguous or overlapped by
6897 -- gathered first operand of result.
6899 if SLeft
<= Left
'Last
6900 and then Left
(SLeft
).Lo
<= FEnt
.Hi
+ 1
6902 FEnt
.Hi
:= UI_Max
(FEnt
.Hi
, Left
(SLeft
).Hi
);
6905 -- Eat first entry in right operand if contiguous or overlapped by
6906 -- gathered right operand of result.
6908 elsif SRight
<= Right
'Last
6909 and then Right
(SRight
).Lo
<= FEnt
.Hi
+ 1
6911 FEnt
.Hi
:= UI_Max
(FEnt
.Hi
, Right
(SRight
).Hi
);
6912 SRight
:= SRight
+ 1;
6914 -- All done if no more entries to eat
6921 -- Obtain result as the first entry we just computed, concatenated
6922 -- to the "or" of the remaining results (if one operand is empty,
6923 -- this will just concatenate with the other
6926 FEnt
& (Left
(SLeft
.. Left
'Last) or Right
(SRight
.. Right
'Last));
6933 function Build_Range
(Lo
: Uint
; Hi
: Uint
) return Node_Id
is
6938 Low_Bound
=> Build_Val
(Lo
),
6939 High_Bound
=> Build_Val
(Hi
));
6940 Set_Etype
(Result
, Btyp
);
6941 Set_Analyzed
(Result
);
6949 function Build_Val
(V
: Uint
) return Node_Id
is
6953 if Is_Enumeration_Type
(Typ
) then
6954 Result
:= Get_Enum_Lit_From_Pos
(Typ
, V
, Loc
);
6956 Result
:= Make_Integer_Literal
(Loc
, V
);
6959 Set_Etype
(Result
, Btyp
);
6960 Set_Is_Static_Expression
(Result
);
6961 Set_Analyzed
(Result
);
6969 function Get_RList
(Exp
: Node_Id
) return RList
is
6974 -- Static expression can only be true or false
6976 if Is_OK_Static_Expression
(Exp
) then
6977 if Expr_Value
(Exp
) = 0 then
6984 -- Otherwise test node type
6992 when N_Op_And | N_And_Then
=>
6993 return Get_RList
(Left_Opnd
(Exp
))
6995 Get_RList
(Right_Opnd
(Exp
));
6999 when N_Op_Or | N_Or_Else
=>
7000 return Get_RList
(Left_Opnd
(Exp
))
7002 Get_RList
(Right_Opnd
(Exp
));
7007 return not Get_RList
(Right_Opnd
(Exp
));
7009 -- Comparisons of type with static value
7011 when N_Op_Compare
=>
7013 -- Type is left operand
7015 if Is_Type_Ref
(Left_Opnd
(Exp
))
7016 and then Is_OK_Static_Expression
(Right_Opnd
(Exp
))
7018 Val
:= Expr_Value
(Right_Opnd
(Exp
));
7020 -- Typ is right operand
7022 elsif Is_Type_Ref
(Right_Opnd
(Exp
))
7023 and then Is_OK_Static_Expression
(Left_Opnd
(Exp
))
7025 Val
:= Expr_Value
(Left_Opnd
(Exp
));
7027 -- Invert sense of comparison
7030 when N_Op_Gt
=> Op
:= N_Op_Lt
;
7031 when N_Op_Lt
=> Op
:= N_Op_Gt
;
7032 when N_Op_Ge
=> Op
:= N_Op_Le
;
7033 when N_Op_Le
=> Op
:= N_Op_Ge
;
7034 when others => null;
7037 -- Other cases are non-static
7043 -- Construct range according to comparison operation
7047 return RList
'(1 => REnt'(Val
, Val
));
7050 return RList
'(1 => REnt'(Val
, BHi
));
7053 return RList
'(1 => REnt'(Val
+ 1, BHi
));
7056 return RList
'(1 => REnt'(BLo
, Val
));
7059 return RList
'(1 => REnt'(BLo
, Val
- 1));
7062 return RList
'(REnt'(BLo
, Val
- 1), REnt
'(Val + 1, BHi));
7065 raise Program_Error;
7071 if not Is_Type_Ref (Left_Opnd (Exp)) then
7075 if Present (Right_Opnd (Exp)) then
7076 return Membership_Entry (Right_Opnd (Exp));
7078 return Membership_Entries (First (Alternatives (Exp)));
7081 -- Negative membership (NOT IN)
7084 if not Is_Type_Ref (Left_Opnd (Exp)) then
7088 if Present (Right_Opnd (Exp)) then
7089 return not Membership_Entry (Right_Opnd (Exp));
7091 return not Membership_Entries (First (Alternatives (Exp)));
7094 -- Function call, may be call to static predicate
7096 when N_Function_Call =>
7097 if Is_Entity_Name (Name (Exp)) then
7099 Ent : constant Entity_Id := Entity (Name (Exp));
7101 if Is_Predicate_Function (Ent)
7103 Is_Predicate_Function_M (Ent)
7105 return Stat_Pred (Etype (First_Formal (Ent)));
7110 -- Other function call cases are non-static
7114 -- Qualified expression, dig out the expression
7116 when N_Qualified_Expression =>
7117 return Get_RList (Expression (Exp));
7119 when N_Case_Expression =>
7126 if not Is_Entity_Name (Expression (Expr))
7127 or else Etype (Expression (Expr)) /= Typ
7130 ("expression must denaote subtype", Expression (Expr));
7134 -- Collect discrete choices in all True alternatives
7136 Choices := New_List;
7137 Alt := First (Alternatives (Exp));
7138 while Present (Alt) loop
7139 Dep := Expression (Alt);
7141 if not Is_OK_Static_Expression (Dep) then
7144 elsif Is_True (Expr_Value (Dep)) then
7145 Append_List_To (Choices,
7146 New_Copy_List (Discrete_Choices (Alt)));
7152 return Membership_Entries (First (Choices));
7155 -- Expression with actions: if no actions, dig out expression
7157 when N_Expression_With_Actions =>
7158 if Is_Empty_List (Actions (Exp)) then
7159 return Get_RList (Expression (Exp));
7167 return (Get_RList (Left_Opnd (Exp))
7168 and not Get_RList (Right_Opnd (Exp)))
7169 or (Get_RList (Right_Opnd (Exp))
7170 and not Get_RList (Left_Opnd (Exp)));
7172 -- Any other node type is non-static
7183 function Hi_Val (N : Node_Id) return Uint is
7185 if Is_OK_Static_Expression (N) then
7186 return Expr_Value (N);
7188 pragma Assert (Nkind (N) = N_Range);
7189 return Expr_Value (High_Bound (N));
7197 function Is_False (R : RList) return Boolean is
7199 return R'Length = 0;
7206 function Is_True (R : RList) return Boolean is
7209 and then R (R'First).Lo = BLo
7210 and then R (R'First).Hi = BHi;
7217 function Is_Type_Ref (N : Node_Id) return Boolean is
7219 return Nkind (N) = N_Identifier
7220 and then Chars (N) = Nam
7221 and then Paren_Count (N) = 0;
7228 function Lo_Val (N : Node_Id) return Uint is
7230 if Is_OK_Static_Expression (N) then
7231 return Expr_Value (N);
7233 pragma Assert (Nkind (N) = N_Range);
7234 return Expr_Value (Low_Bound (N));
7238 ------------------------
7239 -- Membership_Entries --
7240 ------------------------
7242 function Membership_Entries (N : Node_Id) return RList is
7244 if No (Next (N)) then
7245 return Membership_Entry (N);
7247 return Membership_Entry (N) or Membership_Entries (Next (N));
7249 end Membership_Entries;
7251 ----------------------
7252 -- Membership_Entry --
7253 ----------------------
7255 function Membership_Entry (N : Node_Id) return RList is
7263 if Nkind (N) = N_Range then
7264 if not Is_OK_Static_Expression (Low_Bound (N))
7266 not Is_OK_Static_Expression (High_Bound (N))
7270 SLo := Expr_Value (Low_Bound (N));
7271 SHi := Expr_Value (High_Bound (N));
7272 return RList'(1 => REnt
'(SLo, SHi));
7275 -- Static expression case
7277 elsif Is_OK_Static_Expression (N) then
7278 Val := Expr_Value (N);
7279 return RList'(1 => REnt
'(Val, Val));
7281 -- Identifier (other than static expression) case
7283 else pragma Assert (Nkind (N) = N_Identifier);
7287 if Is_Type (Entity (N)) then
7289 -- If type has predicates, process them
7291 if Has_Predicates (Entity (N)) then
7292 return Stat_Pred (Entity (N));
7294 -- For static subtype without predicates, get range
7296 elsif Is_OK_Static_Subtype (Entity (N)) then
7297 SLo := Expr_Value (Type_Low_Bound (Entity (N)));
7298 SHi := Expr_Value (Type_High_Bound (Entity (N)));
7299 return RList'(1 => REnt
'(SLo, SHi));
7301 -- Any other type makes us non-static
7307 -- Any other kind of identifier in predicate (e.g. a non-static
7308 -- expression value) means this is not a static predicate.
7314 end Membership_Entry;
7320 function Stat_Pred (Typ : Entity_Id) return RList is
7322 -- Not static if type does not have static predicates
7324 if not Has_Static_Predicate (Typ) then
7328 -- Otherwise we convert the predicate list to a range list
7331 Spred : constant List_Id := Static_Discrete_Predicate (Typ);
7332 Result : RList (1 .. List_Length (Spred));
7336 P := First (Static_Discrete_Predicate (Typ));
7337 for J in Result'Range loop
7338 Result (J) := REnt'(Lo_Val
(P
), Hi_Val
(P
));
7346 -- Start of processing for Build_Discrete_Static_Predicate
7349 -- Analyze the expression to see if it is a static predicate
7352 Ranges
: constant RList
:= Get_RList
(Expr
);
7353 -- Range list from expression if it is static
7358 -- Convert range list into a form for the static predicate. In the
7359 -- Ranges array, we just have raw ranges, these must be converted
7360 -- to properly typed and analyzed static expressions or range nodes.
7362 -- Note: here we limit ranges to the ranges of the subtype, so that
7363 -- a predicate is always false for values outside the subtype. That
7364 -- seems fine, such values are invalid anyway, and considering them
7365 -- to fail the predicate seems allowed and friendly, and furthermore
7366 -- simplifies processing for case statements and loops.
7370 for J
in Ranges
'Range loop
7372 Lo
: Uint
:= Ranges
(J
).Lo
;
7373 Hi
: Uint
:= Ranges
(J
).Hi
;
7376 -- Ignore completely out of range entry
7378 if Hi
< TLo
or else Lo
> THi
then
7381 -- Otherwise process entry
7384 -- Adjust out of range value to subtype range
7394 -- Convert range into required form
7396 Append_To
(Plist
, Build_Range
(Lo
, Hi
));
7401 -- Processing was successful and all entries were static, so now we
7402 -- can store the result as the predicate list.
7404 Set_Static_Discrete_Predicate
(Typ
, Plist
);
7406 -- The processing for static predicates put the expression into
7407 -- canonical form as a series of ranges. It also eliminated
7408 -- duplicates and collapsed and combined ranges. We might as well
7409 -- replace the alternatives list of the right operand of the
7410 -- membership test with the static predicate list, which will
7411 -- usually be more efficient.
7414 New_Alts
: constant List_Id
:= New_List
;
7419 Old_Node
:= First
(Plist
);
7420 while Present
(Old_Node
) loop
7421 New_Node
:= New_Copy
(Old_Node
);
7423 if Nkind
(New_Node
) = N_Range
then
7424 Set_Low_Bound
(New_Node
, New_Copy
(Low_Bound
(Old_Node
)));
7425 Set_High_Bound
(New_Node
, New_Copy
(High_Bound
(Old_Node
)));
7428 Append_To
(New_Alts
, New_Node
);
7432 -- If empty list, replace by False
7434 if Is_Empty_List
(New_Alts
) then
7435 Rewrite
(Expr
, New_Occurrence_Of
(Standard_False
, Loc
));
7437 -- Else replace by set membership test
7442 Left_Opnd
=> Make_Identifier
(Loc
, Nam
),
7443 Right_Opnd
=> Empty
,
7444 Alternatives
=> New_Alts
));
7446 -- Resolve new expression in function context
7448 Install_Formals
(Predicate_Function
(Typ
));
7449 Push_Scope
(Predicate_Function
(Typ
));
7450 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
7456 -- If non-static, return doing nothing
7461 end Build_Discrete_Static_Predicate
;
7463 -------------------------------------------
7464 -- Build_Invariant_Procedure_Declaration --
7465 -------------------------------------------
7467 function Build_Invariant_Procedure_Declaration
7468 (Typ
: Entity_Id
) return Node_Id
7470 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
7471 Object_Entity
: constant Entity_Id
:=
7472 Make_Defining_Identifier
(Loc
, New_Internal_Name
('I'));
7477 Set_Etype
(Object_Entity
, Typ
);
7479 -- Check for duplicate definiations.
7481 if Has_Invariants
(Typ
) and then Present
(Invariant_Procedure
(Typ
)) then
7486 Make_Defining_Identifier
(Loc
,
7487 Chars
=> New_External_Name
(Chars
(Typ
), "Invariant"));
7488 Set_Has_Invariants
(Typ
);
7489 Set_Ekind
(SId
, E_Procedure
);
7490 Set_Etype
(SId
, Standard_Void_Type
);
7491 Set_Is_Invariant_Procedure
(SId
);
7492 Set_Invariant_Procedure
(Typ
, SId
);
7495 Make_Procedure_Specification
(Loc
,
7496 Defining_Unit_Name
=> SId
,
7497 Parameter_Specifications
=> New_List
(
7498 Make_Parameter_Specification
(Loc
,
7499 Defining_Identifier
=> Object_Entity
,
7500 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))));
7502 return Make_Subprogram_Declaration
(Loc
, Specification
=> Spec
);
7503 end Build_Invariant_Procedure_Declaration
;
7505 -------------------------------
7506 -- Build_Invariant_Procedure --
7507 -------------------------------
7509 -- The procedure that is constructed here has the form
7511 -- procedure typInvariant (Ixxx : typ) is
7513 -- pragma Check (Invariant, exp, "failed invariant from xxx");
7514 -- pragma Check (Invariant, exp, "failed invariant from xxx");
7516 -- pragma Check (Invariant, exp, "failed inherited invariant from xxx");
7518 -- end typInvariant;
7520 procedure Build_Invariant_Procedure
(Typ
: Entity_Id
; N
: Node_Id
) is
7521 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
7529 -- Name for Check pragma, usually Invariant, but might be Type_Invariant
7530 -- if we come from a Type_Invariant aspect, we make sure to build the
7531 -- Check pragma with the right name, so that Check_Policy works right.
7533 Visible_Decls
: constant List_Id
:= Visible_Declarations
(N
);
7534 Private_Decls
: constant List_Id
:= Private_Declarations
(N
);
7536 procedure Add_Invariants
(T
: Entity_Id
; Inherit
: Boolean);
7537 -- Appends statements to Stmts for any invariants in the rep item chain
7538 -- of the given type. If Inherit is False, then we only process entries
7539 -- on the chain for the type Typ. If Inherit is True, then we ignore any
7540 -- Invariant aspects, but we process all Invariant'Class aspects, adding
7541 -- "inherited" to the exception message and generating an informational
7542 -- message about the inheritance of an invariant.
7544 Object_Name
: Name_Id
;
7545 -- Name for argument of invariant procedure
7547 Object_Entity
: Node_Id
;
7548 -- The entity of the formal for the procedure
7550 --------------------
7551 -- Add_Invariants --
7552 --------------------
7554 procedure Add_Invariants
(T
: Entity_Id
; Inherit
: Boolean) is
7564 procedure Replace_Type_Reference
(N
: Node_Id
);
7565 -- Replace a single occurrence N of the subtype name with a reference
7566 -- to the formal of the predicate function. N can be an identifier
7567 -- referencing the subtype, or a selected component, representing an
7568 -- appropriately qualified occurrence of the subtype name.
7570 procedure Replace_Type_References
is
7571 new Replace_Type_References_Generic
(Replace_Type_Reference
);
7572 -- Traverse an expression replacing all occurrences of the subtype
7573 -- name with appropriate references to the object that is the formal
7574 -- parameter of the predicate function. Note that we must ensure
7575 -- that the type and entity information is properly set in the
7576 -- replacement node, since we will do a Preanalyze call of this
7577 -- expression without proper visibility of the procedure argument.
7579 ----------------------------
7580 -- Replace_Type_Reference --
7581 ----------------------------
7583 -- Note: See comments in Add_Predicates.Replace_Type_Reference
7584 -- regarding handling of Sloc and Comes_From_Source.
7586 procedure Replace_Type_Reference
(N
: Node_Id
) is
7589 -- Add semantic information to node to be rewritten, for ASIS
7590 -- navigation needs.
7592 if Nkind
(N
) = N_Identifier
then
7596 elsif Nkind
(N
) = N_Selected_Component
then
7597 Analyze
(Prefix
(N
));
7598 Set_Entity
(Selector_Name
(N
), T
);
7599 Set_Etype
(Selector_Name
(N
), T
);
7602 -- Invariant'Class, replace with T'Class (obj)
7603 -- In ASIS mode, an inherited item is analyzed already, and the
7604 -- replacement has been done, so do not repeat transformation
7605 -- to prevent ill-formed tree.
7607 if Class_Present
(Ritem
) then
7609 and then Nkind
(Parent
(N
)) = N_Attribute_Reference
7610 and then Attribute_Name
(Parent
(N
)) = Name_Class
7616 Make_Type_Conversion
(Sloc
(N
),
7618 Make_Attribute_Reference
(Sloc
(N
),
7619 Prefix
=> New_Occurrence_Of
(T
, Sloc
(N
)),
7620 Attribute_Name
=> Name_Class
),
7622 Make_Identifier
(Sloc
(N
), Object_Name
)));
7624 Set_Entity
(Expression
(N
), Object_Entity
);
7625 Set_Etype
(Expression
(N
), Typ
);
7628 -- Invariant, replace with obj
7631 Rewrite
(N
, Make_Identifier
(Sloc
(N
), Object_Name
));
7632 Set_Entity
(N
, Object_Entity
);
7636 Set_Comes_From_Source
(N
, True);
7637 end Replace_Type_Reference
;
7639 -- Start of processing for Add_Invariants
7642 Ritem
:= First_Rep_Item
(T
);
7643 while Present
(Ritem
) loop
7644 if Nkind
(Ritem
) = N_Pragma
7645 and then Pragma_Name
(Ritem
) = Name_Invariant
7647 Arg1
:= First
(Pragma_Argument_Associations
(Ritem
));
7648 Arg2
:= Next
(Arg1
);
7649 Arg3
:= Next
(Arg2
);
7651 Arg1
:= Get_Pragma_Arg
(Arg1
);
7652 Arg2
:= Get_Pragma_Arg
(Arg2
);
7654 -- For Inherit case, ignore Invariant, process only Class case
7657 if not Class_Present
(Ritem
) then
7661 -- For Inherit false, process only item for right type
7664 if Entity
(Arg1
) /= Typ
then
7670 Stmts
:= Empty_List
;
7673 Exp
:= New_Copy_Tree
(Arg2
);
7675 -- Preserve sloc of original pragma Invariant
7677 Loc
:= Sloc
(Ritem
);
7679 -- We need to replace any occurrences of the name of the type
7680 -- with references to the object, converted to type'Class in
7681 -- the case of Invariant'Class aspects.
7683 Replace_Type_References
(Exp
, T
);
7685 -- If this invariant comes from an aspect, find the aspect
7686 -- specification, and replace the saved expression because
7687 -- we need the subtype references replaced for the calls to
7688 -- Preanalyze_Spec_Expressin in Check_Aspect_At_Freeze_Point
7689 -- and Check_Aspect_At_End_Of_Declarations.
7691 if From_Aspect_Specification
(Ritem
) then
7696 -- Loop to find corresponding aspect, note that this
7697 -- must be present given the pragma is marked delayed.
7699 -- Note: in practice Next_Rep_Item (Ritem) is Empty so
7700 -- this loop does nothing. Furthermore, why isn't this
7701 -- simply Corresponding_Aspect ???
7703 Aitem
:= Next_Rep_Item
(Ritem
);
7704 while Present
(Aitem
) loop
7705 if Nkind
(Aitem
) = N_Aspect_Specification
7706 and then Aspect_Rep_Item
(Aitem
) = Ritem
7709 (Identifier
(Aitem
), New_Copy_Tree
(Exp
));
7713 Aitem
:= Next_Rep_Item
(Aitem
);
7718 -- Now we need to preanalyze the expression to properly capture
7719 -- the visibility in the visible part. The expression will not
7720 -- be analyzed for real until the body is analyzed, but that is
7721 -- at the end of the private part and has the wrong visibility.
7723 Set_Parent
(Exp
, N
);
7724 Preanalyze_Assert_Expression
(Exp
, Standard_Boolean
);
7726 -- A class-wide invariant may be inherited in a separate unit,
7727 -- where the corresponding expression cannot be resolved by
7728 -- visibility, because it refers to a local function. Propagate
7729 -- semantic information to the original representation item, to
7730 -- be used when an invariant procedure for a derived type is
7733 -- Unclear how to handle class-wide invariants that are not
7734 -- function calls ???
7737 and then Class_Present
(Ritem
)
7738 and then Nkind
(Exp
) = N_Function_Call
7739 and then Nkind
(Arg2
) = N_Indexed_Component
7742 Make_Function_Call
(Loc
,
7744 New_Occurrence_Of
(Entity
(Name
(Exp
)), Loc
),
7745 Parameter_Associations
=>
7746 New_Copy_List
(Expressions
(Arg2
))));
7749 -- In ASIS mode, even if assertions are not enabled, we must
7750 -- analyze the original expression in the aspect specification
7751 -- because it is part of the original tree.
7753 if ASIS_Mode
and then From_Aspect_Specification
(Ritem
) then
7755 Inv
: constant Node_Id
:=
7756 Expression
(Corresponding_Aspect
(Ritem
));
7758 Replace_Type_References
(Inv
, T
);
7759 Preanalyze_Assert_Expression
(Inv
, Standard_Boolean
);
7763 -- Get name to be used for Check pragma
7765 if not From_Aspect_Specification
(Ritem
) then
7766 Nam
:= Name_Invariant
;
7768 Nam
:= Chars
(Identifier
(Corresponding_Aspect
(Ritem
)));
7771 -- Build first two arguments for Check pragma
7775 Make_Pragma_Argument_Association
(Loc
,
7776 Expression
=> Make_Identifier
(Loc
, Chars
=> Nam
)),
7777 Make_Pragma_Argument_Association
(Loc
,
7778 Expression
=> Exp
));
7780 -- Add message if present in Invariant pragma
7782 if Present
(Arg3
) then
7783 Str
:= Strval
(Get_Pragma_Arg
(Arg3
));
7785 -- If inherited case, and message starts "failed invariant",
7786 -- change it to be "failed inherited invariant".
7789 String_To_Name_Buffer
(Str
);
7791 if Name_Buffer
(1 .. 16) = "failed invariant" then
7792 Insert_Str_In_Name_Buffer
("inherited ", 8);
7793 Str
:= String_From_Name_Buffer
;
7798 Make_Pragma_Argument_Association
(Loc
,
7799 Expression
=> Make_String_Literal
(Loc
, Str
)));
7802 -- Add Check pragma to list of statements
7806 Pragma_Identifier
=>
7807 Make_Identifier
(Loc
, Name_Check
),
7808 Pragma_Argument_Associations
=> Assoc
));
7810 -- If Inherited case and option enabled, output info msg. Note
7811 -- that we know this is a case of Invariant'Class.
7813 if Inherit
and Opt
.List_Inherited_Aspects
then
7814 Error_Msg_Sloc
:= Sloc
(Ritem
);
7816 ("info: & inherits `Invariant''Class` aspect from #?L?",
7822 Next_Rep_Item
(Ritem
);
7826 -- Start of processing for Build_Invariant_Procedure
7834 -- If the aspect specification exists for some view of the type, the
7835 -- declaration for the procedure has been created.
7837 if Has_Invariants
(Typ
) then
7838 SId
:= Invariant_Procedure
(Typ
);
7841 -- If the body is already present, nothing to do. This will occur when
7842 -- the type is already frozen, which is the case when the invariant
7843 -- appears in a private part, and the freezing takes place before the
7844 -- final pass over full declarations.
7846 -- See Exp_Ch3.Insert_Component_Invariant_Checks for details.
7848 if Present
(SId
) then
7849 PDecl
:= Unit_Declaration_Node
(SId
);
7852 and then Nkind
(PDecl
) = N_Subprogram_Declaration
7853 and then Present
(Corresponding_Body
(PDecl
))
7859 PDecl
:= Build_Invariant_Procedure_Declaration
(Typ
);
7862 -- Recover formal of procedure, for use in the calls to invariant
7863 -- functions (including inherited ones).
7867 (First
(Parameter_Specifications
(Specification
(PDecl
))));
7868 Object_Name
:= Chars
(Object_Entity
);
7870 -- Add invariants for the current type
7872 Add_Invariants
(Typ
, Inherit
=> False);
7874 -- Add invariants for parent types
7877 Current_Typ
: Entity_Id
;
7878 Parent_Typ
: Entity_Id
;
7883 Parent_Typ
:= Etype
(Current_Typ
);
7885 if Is_Private_Type
(Parent_Typ
)
7886 and then Present
(Full_View
(Base_Type
(Parent_Typ
)))
7888 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
7891 exit when Parent_Typ
= Current_Typ
;
7893 Current_Typ
:= Parent_Typ
;
7894 Add_Invariants
(Current_Typ
, Inherit
=> True);
7898 -- Build the procedure if we generated at least one Check pragma
7900 if Stmts
/= No_List
then
7901 Spec
:= Copy_Separate_Tree
(Specification
(PDecl
));
7904 Make_Subprogram_Body
(Loc
,
7905 Specification
=> Spec
,
7906 Declarations
=> Empty_List
,
7907 Handled_Statement_Sequence
=>
7908 Make_Handled_Sequence_Of_Statements
(Loc
,
7909 Statements
=> Stmts
));
7911 -- Insert procedure declaration and spec at the appropriate points.
7912 -- If declaration is already analyzed, it was processed by the
7913 -- generated pragma.
7915 if Present
(Private_Decls
) then
7917 -- The spec goes at the end of visible declarations, but they have
7918 -- already been analyzed, so we need to explicitly do the analyze.
7920 if not Analyzed
(PDecl
) then
7921 Append_To
(Visible_Decls
, PDecl
);
7925 -- The body goes at the end of the private declarations, which we
7926 -- have not analyzed yet, so we do not need to perform an explicit
7927 -- analyze call. We skip this if there are no private declarations
7928 -- (this is an error that will be caught elsewhere);
7930 Append_To
(Private_Decls
, PBody
);
7932 -- If the invariant appears on the full view of a type, the
7933 -- analysis of the private part is complete, and we must
7934 -- analyze the new body explicitly.
7936 if In_Private_Part
(Current_Scope
) then
7940 -- If there are no private declarations this may be an error that
7941 -- will be diagnosed elsewhere. However, if this is a non-private
7942 -- type that inherits invariants, it needs no completion and there
7943 -- may be no private part. In this case insert invariant procedure
7944 -- at end of current declarative list, and analyze at once, given
7945 -- that the type is about to be frozen.
7947 elsif not Is_Private_Type
(Typ
) then
7948 Append_To
(Visible_Decls
, PDecl
);
7949 Append_To
(Visible_Decls
, PBody
);
7954 end Build_Invariant_Procedure
;
7956 -------------------------------
7957 -- Build_Predicate_Functions --
7958 -------------------------------
7960 -- The procedures that are constructed here have the form:
7962 -- function typPredicate (Ixxx : typ) return Boolean is
7965 -- exp1 and then exp2 and then ...
7966 -- and then typ1Predicate (typ1 (Ixxx))
7967 -- and then typ2Predicate (typ2 (Ixxx))
7969 -- end typPredicate;
7971 -- Here exp1, and exp2 are expressions from Predicate pragmas. Note that
7972 -- this is the point at which these expressions get analyzed, providing the
7973 -- required delay, and typ1, typ2, are entities from which predicates are
7974 -- inherited. Note that we do NOT generate Check pragmas, that's because we
7975 -- use this function even if checks are off, e.g. for membership tests.
7977 -- If the expression has at least one Raise_Expression, then we also build
7978 -- the typPredicateM version of the function, in which any occurrence of a
7979 -- Raise_Expression is converted to "return False".
7981 procedure Build_Predicate_Functions
(Typ
: Entity_Id
; N
: Node_Id
) is
7982 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
7985 -- This is the expression for the result of the function. It is
7986 -- is build by connecting the component predicates with AND THEN.
7989 -- This is the corresponding return expression for the Predicate_M
7990 -- function. It differs in that raise expressions are marked for
7991 -- special expansion (see Process_REs).
7993 Object_Name
: constant Name_Id
:= New_Internal_Name
('I');
7994 -- Name for argument of Predicate procedure. Note that we use the same
7995 -- name for both predicate functions. That way the reference within the
7996 -- predicate expression is the same in both functions.
7998 Object_Entity
: constant Entity_Id
:=
7999 Make_Defining_Identifier
(Loc
, Chars
=> Object_Name
);
8000 -- Entity for argument of Predicate procedure
8002 Object_Entity_M
: constant Entity_Id
:=
8003 Make_Defining_Identifier
(Loc
, Chars
=> Object_Name
);
8004 -- Entity for argument of Predicate_M procedure
8006 Raise_Expression_Present
: Boolean := False;
8007 -- Set True if Expr has at least one Raise_Expression
8009 procedure Add_Call
(T
: Entity_Id
);
8010 -- Includes a call to the predicate function for type T in Expr if T
8011 -- has predicates and Predicate_Function (T) is non-empty.
8013 procedure Add_Predicates
;
8014 -- Appends expressions for any Predicate pragmas in the rep item chain
8015 -- Typ to Expr. Note that we look only at items for this exact entity.
8016 -- Inheritance of predicates for the parent type is done by calling the
8017 -- Predicate_Function of the parent type, using Add_Call above.
8019 function Test_RE
(N
: Node_Id
) return Traverse_Result
;
8020 -- Used in Test_REs, tests one node for being a raise expression, and if
8021 -- so sets Raise_Expression_Present True.
8023 procedure Test_REs
is new Traverse_Proc
(Test_RE
);
8024 -- Tests to see if Expr contains any raise expressions
8026 function Process_RE
(N
: Node_Id
) return Traverse_Result
;
8027 -- Used in Process REs, tests if node N is a raise expression, and if
8028 -- so, marks it to be converted to return False.
8030 procedure Process_REs
is new Traverse_Proc
(Process_RE
);
8031 -- Marks any raise expressions in Expr_M to return False
8037 procedure Add_Call
(T
: Entity_Id
) is
8041 if Present
(T
) and then Present
(Predicate_Function
(T
)) then
8042 Set_Has_Predicates
(Typ
);
8044 -- Build the call to the predicate function of T
8048 (T
, Convert_To
(T
, Make_Identifier
(Loc
, Object_Name
)));
8050 -- Add call to evolving expression, using AND THEN if needed
8057 Make_And_Then
(Sloc
(Expr
),
8058 Left_Opnd
=> Relocate_Node
(Expr
),
8062 -- Output info message on inheritance if required. Note we do not
8063 -- give this information for generic actual types, since it is
8064 -- unwelcome noise in that case in instantiations. We also
8065 -- generally suppress the message in instantiations, and also
8066 -- if it involves internal names.
8068 if Opt
.List_Inherited_Aspects
8069 and then not Is_Generic_Actual_Type
(Typ
)
8070 and then Instantiation_Depth
(Sloc
(Typ
)) = 0
8071 and then not Is_Internal_Name
(Chars
(T
))
8072 and then not Is_Internal_Name
(Chars
(Typ
))
8074 Error_Msg_Sloc
:= Sloc
(Predicate_Function
(T
));
8075 Error_Msg_Node_2
:= T
;
8076 Error_Msg_N
("info: & inherits predicate from & #?L?", Typ
);
8081 --------------------
8082 -- Add_Predicates --
8083 --------------------
8085 procedure Add_Predicates
is
8090 procedure Replace_Type_Reference
(N
: Node_Id
);
8091 -- Replace a single occurrence N of the subtype name with a reference
8092 -- to the formal of the predicate function. N can be an identifier
8093 -- referencing the subtype, or a selected component, representing an
8094 -- appropriately qualified occurrence of the subtype name.
8096 procedure Replace_Type_References
is
8097 new Replace_Type_References_Generic
(Replace_Type_Reference
);
8098 -- Traverse an expression changing every occurrence of an identifier
8099 -- whose name matches the name of the subtype with a reference to
8100 -- the formal parameter of the predicate function.
8102 ----------------------------
8103 -- Replace_Type_Reference --
8104 ----------------------------
8106 procedure Replace_Type_Reference
(N
: Node_Id
) is
8108 Rewrite
(N
, Make_Identifier
(Sloc
(N
), Object_Name
));
8109 -- Use the Sloc of the usage name, not the defining name
8112 Set_Entity
(N
, Object_Entity
);
8114 -- We want to treat the node as if it comes from source, so that
8115 -- ASIS will not ignore it
8117 Set_Comes_From_Source
(N
, True);
8118 end Replace_Type_Reference
;
8120 -- Start of processing for Add_Predicates
8123 Ritem
:= First_Rep_Item
(Typ
);
8124 while Present
(Ritem
) loop
8125 if Nkind
(Ritem
) = N_Pragma
8126 and then Pragma_Name
(Ritem
) = Name_Predicate
8128 -- Acquire arguments
8130 Arg1
:= First
(Pragma_Argument_Associations
(Ritem
));
8131 Arg2
:= Next
(Arg1
);
8133 Arg1
:= Get_Pragma_Arg
(Arg1
);
8134 Arg2
:= Get_Pragma_Arg
(Arg2
);
8136 -- See if this predicate pragma is for the current type or for
8137 -- its full view. A predicate on a private completion is placed
8138 -- on the partial view beause this is the visible entity that
8141 if Entity
(Arg1
) = Typ
8142 or else Full_View
(Entity
(Arg1
)) = Typ
8144 -- We have a match, this entry is for our subtype
8146 -- We need to replace any occurrences of the name of the
8147 -- type with references to the object.
8149 Replace_Type_References
(Arg2
, Typ
);
8151 -- If this predicate comes from an aspect, find the aspect
8152 -- specification, and replace the saved expression because
8153 -- we need the subtype references replaced for the calls to
8154 -- Preanalyze_Spec_Expressin in Check_Aspect_At_Freeze_Point
8155 -- and Check_Aspect_At_End_Of_Declarations.
8157 if From_Aspect_Specification
(Ritem
) then
8162 -- Loop to find corresponding aspect, note that this
8163 -- must be present given the pragma is marked delayed.
8165 Aitem
:= Next_Rep_Item
(Ritem
);
8167 if Nkind
(Aitem
) = N_Aspect_Specification
8168 and then Aspect_Rep_Item
(Aitem
) = Ritem
8171 (Identifier
(Aitem
), New_Copy_Tree
(Arg2
));
8175 Aitem
:= Next_Rep_Item
(Aitem
);
8180 -- Now we can add the expression
8183 Expr
:= Relocate_Node
(Arg2
);
8185 -- There already was a predicate, so add to it
8190 Left_Opnd
=> Relocate_Node
(Expr
),
8191 Right_Opnd
=> Relocate_Node
(Arg2
));
8196 Next_Rep_Item
(Ritem
);
8204 function Process_RE
(N
: Node_Id
) return Traverse_Result
is
8206 if Nkind
(N
) = N_Raise_Expression
then
8207 Set_Convert_To_Return_False
(N
);
8218 function Test_RE
(N
: Node_Id
) return Traverse_Result
is
8220 if Nkind
(N
) = N_Raise_Expression
then
8221 Raise_Expression_Present
:= True;
8228 -- Start of processing for Build_Predicate_Functions
8231 -- Return if already built or if type does not have predicates
8233 if not Has_Predicates
(Typ
)
8234 or else Present
(Predicate_Function
(Typ
))
8239 -- Prepare to construct predicate expression
8243 -- Add Predicates for the current type
8247 -- Add predicates for ancestor if present
8250 Atyp
: constant Entity_Id
:= Nearest_Ancestor
(Typ
);
8252 if Present
(Atyp
) then
8257 -- Case where predicates are present
8259 if Present
(Expr
) then
8261 -- Test for raise expression present
8265 -- If raise expression is present, capture a copy of Expr for use
8266 -- in building the predicateM function version later on. For this
8267 -- copy we replace references to Object_Entity by Object_Entity_M.
8269 if Raise_Expression_Present
then
8271 Map
: constant Elist_Id
:= New_Elmt_List
;
8273 Append_Elmt
(Object_Entity
, Map
);
8274 Append_Elmt
(Object_Entity_M
, Map
);
8275 Expr_M
:= New_Copy_Tree
(Expr
, Map
=> Map
);
8279 -- Build the main predicate function
8282 SId
: constant Entity_Id
:=
8283 Make_Defining_Identifier
(Loc
,
8284 Chars
=> New_External_Name
(Chars
(Typ
), "Predicate"));
8285 -- The entity for the the function spec
8287 SIdB
: constant Entity_Id
:=
8288 Make_Defining_Identifier
(Loc
,
8289 Chars
=> New_External_Name
(Chars
(Typ
), "Predicate"));
8290 -- The entity for the function body
8297 -- Build function declaration
8299 Set_Ekind
(SId
, E_Function
);
8300 Set_Is_Internal
(SId
);
8301 Set_Is_Predicate_Function
(SId
);
8302 Set_Predicate_Function
(Typ
, SId
);
8304 -- The predicate function is shared between views of a type
8306 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
8307 Set_Predicate_Function
(Full_View
(Typ
), SId
);
8311 Make_Function_Specification
(Loc
,
8312 Defining_Unit_Name
=> SId
,
8313 Parameter_Specifications
=> New_List
(
8314 Make_Parameter_Specification
(Loc
,
8315 Defining_Identifier
=> Object_Entity
,
8316 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))),
8317 Result_Definition
=>
8318 New_Occurrence_Of
(Standard_Boolean
, Loc
));
8321 Make_Subprogram_Declaration
(Loc
,
8322 Specification
=> Spec
);
8324 -- Build function body
8327 Make_Function_Specification
(Loc
,
8328 Defining_Unit_Name
=> SIdB
,
8329 Parameter_Specifications
=> New_List
(
8330 Make_Parameter_Specification
(Loc
,
8331 Defining_Identifier
=>
8332 Make_Defining_Identifier
(Loc
, Object_Name
),
8334 New_Occurrence_Of
(Typ
, Loc
))),
8335 Result_Definition
=>
8336 New_Occurrence_Of
(Standard_Boolean
, Loc
));
8339 Make_Subprogram_Body
(Loc
,
8340 Specification
=> Spec
,
8341 Declarations
=> Empty_List
,
8342 Handled_Statement_Sequence
=>
8343 Make_Handled_Sequence_Of_Statements
(Loc
,
8344 Statements
=> New_List
(
8345 Make_Simple_Return_Statement
(Loc
,
8346 Expression
=> Expr
))));
8348 -- Insert declaration before freeze node and body after
8350 Insert_Before_And_Analyze
(N
, FDecl
);
8351 Insert_After_And_Analyze
(N
, FBody
);
8354 -- Test for raise expressions present and if so build M version
8356 if Raise_Expression_Present
then
8358 SId
: constant Entity_Id
:=
8359 Make_Defining_Identifier
(Loc
,
8360 Chars
=> New_External_Name
(Chars
(Typ
), "PredicateM"));
8361 -- The entity for the the function spec
8363 SIdB
: constant Entity_Id
:=
8364 Make_Defining_Identifier
(Loc
,
8365 Chars
=> New_External_Name
(Chars
(Typ
), "PredicateM"));
8366 -- The entity for the function body
8374 -- Mark any raise expressions for special expansion
8376 Process_REs
(Expr_M
);
8378 -- Build function declaration
8380 Set_Ekind
(SId
, E_Function
);
8381 Set_Is_Predicate_Function_M
(SId
);
8382 Set_Predicate_Function_M
(Typ
, SId
);
8384 -- The predicate function is shared between views of a type
8386 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
8387 Set_Predicate_Function_M
(Full_View
(Typ
), SId
);
8391 Make_Function_Specification
(Loc
,
8392 Defining_Unit_Name
=> SId
,
8393 Parameter_Specifications
=> New_List
(
8394 Make_Parameter_Specification
(Loc
,
8395 Defining_Identifier
=> Object_Entity_M
,
8396 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))),
8397 Result_Definition
=>
8398 New_Occurrence_Of
(Standard_Boolean
, Loc
));
8401 Make_Subprogram_Declaration
(Loc
,
8402 Specification
=> Spec
);
8404 -- Build function body
8407 Make_Function_Specification
(Loc
,
8408 Defining_Unit_Name
=> SIdB
,
8409 Parameter_Specifications
=> New_List
(
8410 Make_Parameter_Specification
(Loc
,
8411 Defining_Identifier
=>
8412 Make_Defining_Identifier
(Loc
, Object_Name
),
8414 New_Occurrence_Of
(Typ
, Loc
))),
8415 Result_Definition
=>
8416 New_Occurrence_Of
(Standard_Boolean
, Loc
));
8418 -- Build the body, we declare the boolean expression before
8419 -- doing the return, because we are not really confident of
8420 -- what happens if a return appears within a return.
8423 Make_Defining_Identifier
(Loc
,
8424 Chars
=> New_Internal_Name
('B'));
8427 Make_Subprogram_Body
(Loc
,
8428 Specification
=> Spec
,
8430 Declarations
=> New_List
(
8431 Make_Object_Declaration
(Loc
,
8432 Defining_Identifier
=> BTemp
,
8433 Constant_Present
=> True,
8434 Object_Definition
=>
8435 New_Occurrence_Of
(Standard_Boolean
, Loc
),
8436 Expression
=> Expr_M
)),
8438 Handled_Statement_Sequence
=>
8439 Make_Handled_Sequence_Of_Statements
(Loc
,
8440 Statements
=> New_List
(
8441 Make_Simple_Return_Statement
(Loc
,
8442 Expression
=> New_Occurrence_Of
(BTemp
, Loc
)))));
8444 -- Insert declaration before freeze node and body after
8446 Insert_Before_And_Analyze
(N
, FDecl
);
8447 Insert_After_And_Analyze
(N
, FBody
);
8451 -- See if we have a static predicate. Note that the answer may be
8452 -- yes even if we have an explicit Dynamic_Predicate present.
8459 if not Is_Scalar_Type
(Typ
) and then not Is_String_Type
(Typ
) then
8462 PS
:= Is_Predicate_Static
(Expr
, Object_Name
);
8465 -- Case where we have a predicate-static aspect
8469 -- We don't set Has_Static_Predicate_Aspect, since we can have
8470 -- any of the three cases (Predicate, Dynamic_Predicate, or
8471 -- Static_Predicate) generating a predicate with an expression
8472 -- that is predicate-static. We just indicate that we have a
8473 -- predicate that can be treated as static.
8475 Set_Has_Static_Predicate
(Typ
);
8477 -- For discrete subtype, build the static predicate list
8479 if Is_Discrete_Type
(Typ
) then
8480 if not Is_Static_Subtype
(Typ
) then
8482 -- This can only happen in the presence of previous
8485 pragma Assert
(Serious_Errors_Detected
> 0);
8489 Build_Discrete_Static_Predicate
(Typ
, Expr
, Object_Name
);
8491 -- If we don't get a static predicate list, it means that we
8492 -- have a case where this is not possible, most typically in
8493 -- the case where we inherit a dynamic predicate. We do not
8494 -- consider this an error, we just leave the predicate as
8495 -- dynamic. But if we do succeed in building the list, then
8496 -- we mark the predicate as static.
8498 if No
(Static_Discrete_Predicate
(Typ
)) then
8499 Set_Has_Static_Predicate
(Typ
, False);
8502 -- For real or string subtype, save predicate expression
8504 elsif Is_Real_Type
(Typ
) or else Is_String_Type
(Typ
) then
8505 Set_Static_Real_Or_String_Predicate
(Typ
, Expr
);
8508 -- Case of dynamic predicate (expression is not predicate-static)
8511 -- Again, we don't set Has_Dynamic_Predicate_Aspect, since that
8512 -- is only set if we have an explicit Dynamic_Predicate aspect
8513 -- given. Here we may simply have a Predicate aspect where the
8514 -- expression happens not to be predicate-static.
8516 -- Emit an error when the predicate is categorized as static
8517 -- but its expression is not predicate-static.
8519 -- First a little fiddling to get a nice location for the
8520 -- message. If the expression is of the form (A and then B),
8521 -- then use the left operand for the Sloc. This avoids getting
8522 -- confused by a call to a higher-level predicate with a less
8523 -- convenient source location.
8526 while Nkind
(EN
) = N_And_Then
loop
8527 EN
:= Left_Opnd
(EN
);
8530 -- Now post appropriate message
8532 if Has_Static_Predicate_Aspect
(Typ
) then
8533 if Is_Scalar_Type
(Typ
) or else Is_String_Type
(Typ
) then
8535 ("expression is not predicate-static (RM 3.2.4(16-22))",
8539 ("static predicate requires scalar or string type", EN
);
8545 end Build_Predicate_Functions
;
8547 -----------------------------------------
8548 -- Check_Aspect_At_End_Of_Declarations --
8549 -----------------------------------------
8551 procedure Check_Aspect_At_End_Of_Declarations
(ASN
: Node_Id
) is
8552 Ent
: constant Entity_Id
:= Entity
(ASN
);
8553 Ident
: constant Node_Id
:= Identifier
(ASN
);
8554 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Chars
(Ident
));
8556 End_Decl_Expr
: constant Node_Id
:= Entity
(Ident
);
8557 -- Expression to be analyzed at end of declarations
8559 Freeze_Expr
: constant Node_Id
:= Expression
(ASN
);
8560 -- Expression from call to Check_Aspect_At_Freeze_Point
8562 T
: constant Entity_Id
:= Etype
(Freeze_Expr
);
8563 -- Type required for preanalyze call
8566 -- Set False if error
8568 -- On entry to this procedure, Entity (Ident) contains a copy of the
8569 -- original expression from the aspect, saved for this purpose, and
8570 -- but Expression (Ident) is a preanalyzed copy of the expression,
8571 -- preanalyzed just after the freeze point.
8573 procedure Check_Overloaded_Name
;
8574 -- For aspects whose expression is simply a name, this routine checks if
8575 -- the name is overloaded or not. If so, it verifies there is an
8576 -- interpretation that matches the entity obtained at the freeze point,
8577 -- otherwise the compiler complains.
8579 ---------------------------
8580 -- Check_Overloaded_Name --
8581 ---------------------------
8583 procedure Check_Overloaded_Name
is
8585 if not Is_Overloaded
(End_Decl_Expr
) then
8586 Err
:= not Is_Entity_Name
(End_Decl_Expr
)
8587 or else Entity
(End_Decl_Expr
) /= Entity
(Freeze_Expr
);
8593 Index
: Interp_Index
;
8597 Get_First_Interp
(End_Decl_Expr
, Index
, It
);
8598 while Present
(It
.Typ
) loop
8599 if It
.Nam
= Entity
(Freeze_Expr
) then
8604 Get_Next_Interp
(Index
, It
);
8608 end Check_Overloaded_Name
;
8610 -- Start of processing for Check_Aspect_At_End_Of_Declarations
8613 -- Case of aspects Dimension, Dimension_System and Synchronization
8615 if A_Id
= Aspect_Synchronization
then
8618 -- Case of stream attributes, just have to compare entities. However,
8619 -- the expression is just a name (possibly overloaded), and there may
8620 -- be stream operations declared for unrelated types, so we just need
8621 -- to verify that one of these interpretations is the one available at
8622 -- at the freeze point.
8624 elsif A_Id
= Aspect_Input
or else
8625 A_Id
= Aspect_Output
or else
8626 A_Id
= Aspect_Read
or else
8629 Analyze
(End_Decl_Expr
);
8630 Check_Overloaded_Name
;
8632 elsif A_Id
= Aspect_Variable_Indexing
or else
8633 A_Id
= Aspect_Constant_Indexing
or else
8634 A_Id
= Aspect_Default_Iterator
or else
8635 A_Id
= Aspect_Iterator_Element
8637 -- Make type unfrozen before analysis, to prevent spurious errors
8638 -- about late attributes.
8640 Set_Is_Frozen
(Ent
, False);
8641 Analyze
(End_Decl_Expr
);
8642 Set_Is_Frozen
(Ent
, True);
8644 -- If the end of declarations comes before any other freeze
8645 -- point, the Freeze_Expr is not analyzed: no check needed.
8647 if Analyzed
(Freeze_Expr
) and then not In_Instance
then
8648 Check_Overloaded_Name
;
8656 -- Indicate that the expression comes from an aspect specification,
8657 -- which is used in subsequent analysis even if expansion is off.
8659 Set_Parent
(End_Decl_Expr
, ASN
);
8661 -- In a generic context the aspect expressions have not been
8662 -- preanalyzed, so do it now. There are no conformance checks
8663 -- to perform in this case.
8666 Check_Aspect_At_Freeze_Point
(ASN
);
8669 -- The default values attributes may be defined in the private part,
8670 -- and the analysis of the expression may take place when only the
8671 -- partial view is visible. The expression must be scalar, so use
8672 -- the full view to resolve.
8674 elsif (A_Id
= Aspect_Default_Value
8676 A_Id
= Aspect_Default_Component_Value
)
8677 and then Is_Private_Type
(T
)
8679 Preanalyze_Spec_Expression
(End_Decl_Expr
, Full_View
(T
));
8682 Preanalyze_Spec_Expression
(End_Decl_Expr
, T
);
8685 Err
:= not Fully_Conformant_Expressions
(End_Decl_Expr
, Freeze_Expr
);
8688 -- Output error message if error. Force error on aspect specification
8689 -- even if there is an error on the expression itself.
8693 ("!visibility of aspect for& changes after freeze point",
8696 ("info: & is frozen here, aspects evaluated at this point??",
8697 Freeze_Node
(Ent
), Ent
);
8699 end Check_Aspect_At_End_Of_Declarations
;
8701 ----------------------------------
8702 -- Check_Aspect_At_Freeze_Point --
8703 ----------------------------------
8705 procedure Check_Aspect_At_Freeze_Point
(ASN
: Node_Id
) is
8706 Ident
: constant Node_Id
:= Identifier
(ASN
);
8707 -- Identifier (use Entity field to save expression)
8709 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Chars
(Ident
));
8711 T
: Entity_Id
:= Empty
;
8712 -- Type required for preanalyze call
8715 -- On entry to this procedure, Entity (Ident) contains a copy of the
8716 -- original expression from the aspect, saved for this purpose.
8718 -- On exit from this procedure Entity (Ident) is unchanged, still
8719 -- containing that copy, but Expression (Ident) is a preanalyzed copy
8720 -- of the expression, preanalyzed just after the freeze point.
8722 -- Make a copy of the expression to be preanalyzed
8724 Set_Expression
(ASN
, New_Copy_Tree
(Entity
(Ident
)));
8726 -- Find type for preanalyze call
8730 -- No_Aspect should be impossible
8733 raise Program_Error
;
8735 -- Aspects taking an optional boolean argument
8737 when Boolean_Aspects |
8738 Library_Unit_Aspects
=>
8740 T
:= Standard_Boolean
;
8742 -- Aspects corresponding to attribute definition clauses
8744 when Aspect_Address
=>
8745 T
:= RTE
(RE_Address
);
8747 when Aspect_Attach_Handler
=>
8748 T
:= RTE
(RE_Interrupt_ID
);
8750 when Aspect_Bit_Order | Aspect_Scalar_Storage_Order
=>
8751 T
:= RTE
(RE_Bit_Order
);
8753 when Aspect_Convention
=>
8757 T
:= RTE
(RE_CPU_Range
);
8759 -- Default_Component_Value is resolved with the component type
8761 when Aspect_Default_Component_Value
=>
8762 T
:= Component_Type
(Entity
(ASN
));
8764 when Aspect_Default_Storage_Pool
=>
8765 T
:= Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
));
8767 -- Default_Value is resolved with the type entity in question
8769 when Aspect_Default_Value
=>
8772 when Aspect_Dispatching_Domain
=>
8773 T
:= RTE
(RE_Dispatching_Domain
);
8775 when Aspect_External_Tag
=>
8776 T
:= Standard_String
;
8778 when Aspect_External_Name
=>
8779 T
:= Standard_String
;
8781 when Aspect_Link_Name
=>
8782 T
:= Standard_String
;
8784 when Aspect_Priority | Aspect_Interrupt_Priority
=>
8785 T
:= Standard_Integer
;
8787 when Aspect_Relative_Deadline
=>
8788 T
:= RTE
(RE_Time_Span
);
8790 when Aspect_Small
=>
8791 T
:= Universal_Real
;
8793 -- For a simple storage pool, we have to retrieve the type of the
8794 -- pool object associated with the aspect's corresponding attribute
8795 -- definition clause.
8797 when Aspect_Simple_Storage_Pool
=>
8798 T
:= Etype
(Expression
(Aspect_Rep_Item
(ASN
)));
8800 when Aspect_Storage_Pool
=>
8801 T
:= Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
));
8803 when Aspect_Alignment |
8804 Aspect_Component_Size |
8805 Aspect_Machine_Radix |
8806 Aspect_Object_Size |
8808 Aspect_Storage_Size |
8809 Aspect_Stream_Size |
8810 Aspect_Value_Size
=>
8813 when Aspect_Linker_Section
=>
8814 T
:= Standard_String
;
8816 when Aspect_Synchronization
=>
8819 -- Special case, the expression of these aspects is just an entity
8820 -- that does not need any resolution, so just analyze.
8829 Analyze
(Expression
(ASN
));
8832 -- Same for Iterator aspects, where the expression is a function
8833 -- name. Legality rules are checked separately.
8835 when Aspect_Constant_Indexing |
8836 Aspect_Default_Iterator |
8837 Aspect_Iterator_Element |
8838 Aspect_Variable_Indexing
=>
8839 Analyze
(Expression
(ASN
));
8842 -- Ditto for Iterable, legality checks in Validate_Iterable_Aspect.
8844 when Aspect_Iterable
=>
8848 Cursor
: constant Entity_Id
:= Get_Cursor_Type
(ASN
, T
);
8853 if Cursor
= Any_Type
then
8857 Assoc
:= First
(Component_Associations
(Expression
(ASN
)));
8858 while Present
(Assoc
) loop
8859 Expr
:= Expression
(Assoc
);
8862 if not Error_Posted
(Expr
) then
8863 Resolve_Iterable_Operation
8864 (Expr
, Cursor
, T
, Chars
(First
(Choices
(Assoc
))));
8873 -- Invariant/Predicate take boolean expressions
8875 when Aspect_Dynamic_Predicate |
8878 Aspect_Static_Predicate |
8879 Aspect_Type_Invariant
=>
8880 T
:= Standard_Boolean
;
8882 -- Here is the list of aspects that don't require delay analysis
8884 when Aspect_Abstract_State |
8886 Aspect_Contract_Cases |
8887 Aspect_Default_Initial_Condition |
8890 Aspect_Dimension_System |
8891 Aspect_Extensions_Visible |
8894 Aspect_Implicit_Dereference |
8895 Aspect_Initial_Condition |
8896 Aspect_Initializes |
8897 Aspect_Obsolescent |
8900 Aspect_Postcondition |
8902 Aspect_Precondition |
8903 Aspect_Refined_Depends |
8904 Aspect_Refined_Global |
8905 Aspect_Refined_Post |
8906 Aspect_Refined_State |
8909 raise Program_Error
;
8913 -- Do the preanalyze call
8915 Preanalyze_Spec_Expression
(Expression
(ASN
), T
);
8916 end Check_Aspect_At_Freeze_Point
;
8918 -----------------------------------
8919 -- Check_Constant_Address_Clause --
8920 -----------------------------------
8922 procedure Check_Constant_Address_Clause
8926 procedure Check_At_Constant_Address
(Nod
: Node_Id
);
8927 -- Checks that the given node N represents a name whose 'Address is
8928 -- constant (in the same sense as OK_Constant_Address_Clause, i.e. the
8929 -- address value is the same at the point of declaration of U_Ent and at
8930 -- the time of elaboration of the address clause.
8932 procedure Check_Expr_Constants
(Nod
: Node_Id
);
8933 -- Checks that Nod meets the requirements for a constant address clause
8934 -- in the sense of the enclosing procedure.
8936 procedure Check_List_Constants
(Lst
: List_Id
);
8937 -- Check that all elements of list Lst meet the requirements for a
8938 -- constant address clause in the sense of the enclosing procedure.
8940 -------------------------------
8941 -- Check_At_Constant_Address --
8942 -------------------------------
8944 procedure Check_At_Constant_Address
(Nod
: Node_Id
) is
8946 if Is_Entity_Name
(Nod
) then
8947 if Present
(Address_Clause
(Entity
((Nod
)))) then
8949 ("invalid address clause for initialized object &!",
8952 ("address for& cannot" &
8953 " depend on another address clause! (RM 13.1(22))!",
8956 elsif In_Same_Source_Unit
(Entity
(Nod
), U_Ent
)
8957 and then Sloc
(U_Ent
) < Sloc
(Entity
(Nod
))
8960 ("invalid address clause for initialized object &!",
8962 Error_Msg_Node_2
:= U_Ent
;
8964 ("\& must be defined before & (RM 13.1(22))!",
8968 elsif Nkind
(Nod
) = N_Selected_Component
then
8970 T
: constant Entity_Id
:= Etype
(Prefix
(Nod
));
8973 if (Is_Record_Type
(T
)
8974 and then Has_Discriminants
(T
))
8977 and then Is_Record_Type
(Designated_Type
(T
))
8978 and then Has_Discriminants
(Designated_Type
(T
)))
8981 ("invalid address clause for initialized object &!",
8984 ("\address cannot depend on component" &
8985 " of discriminated record (RM 13.1(22))!",
8988 Check_At_Constant_Address
(Prefix
(Nod
));
8992 elsif Nkind
(Nod
) = N_Indexed_Component
then
8993 Check_At_Constant_Address
(Prefix
(Nod
));
8994 Check_List_Constants
(Expressions
(Nod
));
8997 Check_Expr_Constants
(Nod
);
8999 end Check_At_Constant_Address
;
9001 --------------------------
9002 -- Check_Expr_Constants --
9003 --------------------------
9005 procedure Check_Expr_Constants
(Nod
: Node_Id
) is
9006 Loc_U_Ent
: constant Source_Ptr
:= Sloc
(U_Ent
);
9007 Ent
: Entity_Id
:= Empty
;
9010 if Nkind
(Nod
) in N_Has_Etype
9011 and then Etype
(Nod
) = Any_Type
9017 when N_Empty | N_Error
=>
9020 when N_Identifier | N_Expanded_Name
=>
9021 Ent
:= Entity
(Nod
);
9023 -- We need to look at the original node if it is different
9024 -- from the node, since we may have rewritten things and
9025 -- substituted an identifier representing the rewrite.
9027 if Original_Node
(Nod
) /= Nod
then
9028 Check_Expr_Constants
(Original_Node
(Nod
));
9030 -- If the node is an object declaration without initial
9031 -- value, some code has been expanded, and the expression
9032 -- is not constant, even if the constituents might be
9033 -- acceptable, as in A'Address + offset.
9035 if Ekind
(Ent
) = E_Variable
9037 Nkind
(Declaration_Node
(Ent
)) = N_Object_Declaration
9039 No
(Expression
(Declaration_Node
(Ent
)))
9042 ("invalid address clause for initialized object &!",
9045 -- If entity is constant, it may be the result of expanding
9046 -- a check. We must verify that its declaration appears
9047 -- before the object in question, else we also reject the
9050 elsif Ekind
(Ent
) = E_Constant
9051 and then In_Same_Source_Unit
(Ent
, U_Ent
)
9052 and then Sloc
(Ent
) > Loc_U_Ent
9055 ("invalid address clause for initialized object &!",
9062 -- Otherwise look at the identifier and see if it is OK
9064 if Ekind_In
(Ent
, E_Named_Integer
, E_Named_Real
)
9065 or else Is_Type
(Ent
)
9069 elsif Ekind_In
(Ent
, E_Constant
, E_In_Parameter
) then
9071 -- This is the case where we must have Ent defined before
9072 -- U_Ent. Clearly if they are in different units this
9073 -- requirement is met since the unit containing Ent is
9074 -- already processed.
9076 if not In_Same_Source_Unit
(Ent
, U_Ent
) then
9079 -- Otherwise location of Ent must be before the location
9080 -- of U_Ent, that's what prior defined means.
9082 elsif Sloc
(Ent
) < Loc_U_Ent
then
9087 ("invalid address clause for initialized object &!",
9089 Error_Msg_Node_2
:= U_Ent
;
9091 ("\& must be defined before & (RM 13.1(22))!",
9095 elsif Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
9096 Check_Expr_Constants
(Original_Node
(Nod
));
9100 ("invalid address clause for initialized object &!",
9103 if Comes_From_Source
(Ent
) then
9105 ("\reference to variable& not allowed"
9106 & " (RM 13.1(22))!", Nod
, Ent
);
9109 ("non-static expression not allowed"
9110 & " (RM 13.1(22))!", Nod
);
9114 when N_Integer_Literal
=>
9116 -- If this is a rewritten unchecked conversion, in a system
9117 -- where Address is an integer type, always use the base type
9118 -- for a literal value. This is user-friendly and prevents
9119 -- order-of-elaboration issues with instances of unchecked
9122 if Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
9123 Set_Etype
(Nod
, Base_Type
(Etype
(Nod
)));
9126 when N_Real_Literal |
9128 N_Character_Literal
=>
9132 Check_Expr_Constants
(Low_Bound
(Nod
));
9133 Check_Expr_Constants
(High_Bound
(Nod
));
9135 when N_Explicit_Dereference
=>
9136 Check_Expr_Constants
(Prefix
(Nod
));
9138 when N_Indexed_Component
=>
9139 Check_Expr_Constants
(Prefix
(Nod
));
9140 Check_List_Constants
(Expressions
(Nod
));
9143 Check_Expr_Constants
(Prefix
(Nod
));
9144 Check_Expr_Constants
(Discrete_Range
(Nod
));
9146 when N_Selected_Component
=>
9147 Check_Expr_Constants
(Prefix
(Nod
));
9149 when N_Attribute_Reference
=>
9150 if Nam_In
(Attribute_Name
(Nod
), Name_Address
,
9152 Name_Unchecked_Access
,
9153 Name_Unrestricted_Access
)
9155 Check_At_Constant_Address
(Prefix
(Nod
));
9158 Check_Expr_Constants
(Prefix
(Nod
));
9159 Check_List_Constants
(Expressions
(Nod
));
9163 Check_List_Constants
(Component_Associations
(Nod
));
9164 Check_List_Constants
(Expressions
(Nod
));
9166 when N_Component_Association
=>
9167 Check_Expr_Constants
(Expression
(Nod
));
9169 when N_Extension_Aggregate
=>
9170 Check_Expr_Constants
(Ancestor_Part
(Nod
));
9171 Check_List_Constants
(Component_Associations
(Nod
));
9172 Check_List_Constants
(Expressions
(Nod
));
9177 when N_Binary_Op | N_Short_Circuit | N_Membership_Test
=>
9178 Check_Expr_Constants
(Left_Opnd
(Nod
));
9179 Check_Expr_Constants
(Right_Opnd
(Nod
));
9182 Check_Expr_Constants
(Right_Opnd
(Nod
));
9184 when N_Type_Conversion |
9185 N_Qualified_Expression |
9187 N_Unchecked_Type_Conversion
=>
9188 Check_Expr_Constants
(Expression
(Nod
));
9190 when N_Function_Call
=>
9191 if not Is_Pure
(Entity
(Name
(Nod
))) then
9193 ("invalid address clause for initialized object &!",
9197 ("\function & is not pure (RM 13.1(22))!",
9198 Nod
, Entity
(Name
(Nod
)));
9201 Check_List_Constants
(Parameter_Associations
(Nod
));
9204 when N_Parameter_Association
=>
9205 Check_Expr_Constants
(Explicit_Actual_Parameter
(Nod
));
9209 ("invalid address clause for initialized object &!",
9212 ("\must be constant defined before& (RM 13.1(22))!",
9215 end Check_Expr_Constants
;
9217 --------------------------
9218 -- Check_List_Constants --
9219 --------------------------
9221 procedure Check_List_Constants
(Lst
: List_Id
) is
9225 if Present
(Lst
) then
9226 Nod1
:= First
(Lst
);
9227 while Present
(Nod1
) loop
9228 Check_Expr_Constants
(Nod1
);
9232 end Check_List_Constants
;
9234 -- Start of processing for Check_Constant_Address_Clause
9237 -- If rep_clauses are to be ignored, no need for legality checks. In
9238 -- particular, no need to pester user about rep clauses that violate the
9239 -- rule on constant addresses, given that these clauses will be removed
9240 -- by Freeze before they reach the back end. Similarly in CodePeer mode,
9241 -- we want to relax these checks.
9243 if not Ignore_Rep_Clauses
and not CodePeer_Mode
then
9244 Check_Expr_Constants
(Expr
);
9246 end Check_Constant_Address_Clause
;
9248 ---------------------------
9249 -- Check_Pool_Size_Clash --
9250 ---------------------------
9252 procedure Check_Pool_Size_Clash
(Ent
: Entity_Id
; SP
, SS
: Node_Id
) is
9256 -- We need to find out which one came first. Note that in the case of
9257 -- aspects mixed with pragmas there are cases where the processing order
9258 -- is reversed, which is why we do the check here.
9260 if Sloc
(SP
) < Sloc
(SS
) then
9261 Error_Msg_Sloc
:= Sloc
(SP
);
9263 Error_Msg_NE
("Storage_Pool previously given for&#", Post
, Ent
);
9266 Error_Msg_Sloc
:= Sloc
(SS
);
9268 Error_Msg_NE
("Storage_Size previously given for&#", Post
, Ent
);
9272 ("\cannot have Storage_Size and Storage_Pool (RM 13.11(3))", Post
);
9273 end Check_Pool_Size_Clash
;
9275 ----------------------------------------
9276 -- Check_Record_Representation_Clause --
9277 ----------------------------------------
9279 procedure Check_Record_Representation_Clause
(N
: Node_Id
) is
9280 Loc
: constant Source_Ptr
:= Sloc
(N
);
9281 Ident
: constant Node_Id
:= Identifier
(N
);
9282 Rectype
: Entity_Id
;
9287 Hbit
: Uint
:= Uint_0
;
9291 Max_Bit_So_Far
: Uint
;
9292 -- Records the maximum bit position so far. If all field positions
9293 -- are monotonically increasing, then we can skip the circuit for
9294 -- checking for overlap, since no overlap is possible.
9296 Tagged_Parent
: Entity_Id
:= Empty
;
9297 -- This is set in the case of a derived tagged type for which we have
9298 -- Is_Fully_Repped_Tagged_Type True (indicating that all components are
9299 -- positioned by record representation clauses). In this case we must
9300 -- check for overlap between components of this tagged type, and the
9301 -- components of its parent. Tagged_Parent will point to this parent
9302 -- type. For all other cases Tagged_Parent is left set to Empty.
9304 Parent_Last_Bit
: Uint
;
9305 -- Relevant only if Tagged_Parent is set, Parent_Last_Bit indicates the
9306 -- last bit position for any field in the parent type. We only need to
9307 -- check overlap for fields starting below this point.
9309 Overlap_Check_Required
: Boolean;
9310 -- Used to keep track of whether or not an overlap check is required
9312 Overlap_Detected
: Boolean := False;
9313 -- Set True if an overlap is detected
9315 Ccount
: Natural := 0;
9316 -- Number of component clauses in record rep clause
9318 procedure Check_Component_Overlap
(C1_Ent
, C2_Ent
: Entity_Id
);
9319 -- Given two entities for record components or discriminants, checks
9320 -- if they have overlapping component clauses and issues errors if so.
9322 procedure Find_Component
;
9323 -- Finds component entity corresponding to current component clause (in
9324 -- CC), and sets Comp to the entity, and Fbit/Lbit to the zero origin
9325 -- start/stop bits for the field. If there is no matching component or
9326 -- if the matching component does not have a component clause, then
9327 -- that's an error and Comp is set to Empty, but no error message is
9328 -- issued, since the message was already given. Comp is also set to
9329 -- Empty if the current "component clause" is in fact a pragma.
9331 -----------------------------
9332 -- Check_Component_Overlap --
9333 -----------------------------
9335 procedure Check_Component_Overlap
(C1_Ent
, C2_Ent
: Entity_Id
) is
9336 CC1
: constant Node_Id
:= Component_Clause
(C1_Ent
);
9337 CC2
: constant Node_Id
:= Component_Clause
(C2_Ent
);
9340 if Present
(CC1
) and then Present
(CC2
) then
9342 -- Exclude odd case where we have two tag components in the same
9343 -- record, both at location zero. This seems a bit strange, but
9344 -- it seems to happen in some circumstances, perhaps on an error.
9346 if Nam_In
(Chars
(C1_Ent
), Name_uTag
, Name_uTag
) then
9350 -- Here we check if the two fields overlap
9353 S1
: constant Uint
:= Component_Bit_Offset
(C1_Ent
);
9354 S2
: constant Uint
:= Component_Bit_Offset
(C2_Ent
);
9355 E1
: constant Uint
:= S1
+ Esize
(C1_Ent
);
9356 E2
: constant Uint
:= S2
+ Esize
(C2_Ent
);
9359 if E2
<= S1
or else E1
<= S2
then
9362 Error_Msg_Node_2
:= Component_Name
(CC2
);
9363 Error_Msg_Sloc
:= Sloc
(Error_Msg_Node_2
);
9364 Error_Msg_Node_1
:= Component_Name
(CC1
);
9366 ("component& overlaps & #", Component_Name
(CC1
));
9367 Overlap_Detected
:= True;
9371 end Check_Component_Overlap
;
9373 --------------------
9374 -- Find_Component --
9375 --------------------
9377 procedure Find_Component
is
9379 procedure Search_Component
(R
: Entity_Id
);
9380 -- Search components of R for a match. If found, Comp is set
9382 ----------------------
9383 -- Search_Component --
9384 ----------------------
9386 procedure Search_Component
(R
: Entity_Id
) is
9388 Comp
:= First_Component_Or_Discriminant
(R
);
9389 while Present
(Comp
) loop
9391 -- Ignore error of attribute name for component name (we
9392 -- already gave an error message for this, so no need to
9395 if Nkind
(Component_Name
(CC
)) = N_Attribute_Reference
then
9398 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
9401 Next_Component_Or_Discriminant
(Comp
);
9403 end Search_Component
;
9405 -- Start of processing for Find_Component
9408 -- Return with Comp set to Empty if we have a pragma
9410 if Nkind
(CC
) = N_Pragma
then
9415 -- Search current record for matching component
9417 Search_Component
(Rectype
);
9419 -- If not found, maybe component of base type discriminant that is
9420 -- absent from statically constrained first subtype.
9423 Search_Component
(Base_Type
(Rectype
));
9426 -- If no component, or the component does not reference the component
9427 -- clause in question, then there was some previous error for which
9428 -- we already gave a message, so just return with Comp Empty.
9430 if No
(Comp
) or else Component_Clause
(Comp
) /= CC
then
9431 Check_Error_Detected
;
9434 -- Normal case where we have a component clause
9437 Fbit
:= Component_Bit_Offset
(Comp
);
9438 Lbit
:= Fbit
+ Esize
(Comp
) - 1;
9442 -- Start of processing for Check_Record_Representation_Clause
9446 Rectype
:= Entity
(Ident
);
9448 if Rectype
= Any_Type
then
9451 Rectype
:= Underlying_Type
(Rectype
);
9454 -- See if we have a fully repped derived tagged type
9457 PS
: constant Entity_Id
:= Parent_Subtype
(Rectype
);
9460 if Present
(PS
) and then Is_Fully_Repped_Tagged_Type
(PS
) then
9461 Tagged_Parent
:= PS
;
9463 -- Find maximum bit of any component of the parent type
9465 Parent_Last_Bit
:= UI_From_Int
(System_Address_Size
- 1);
9466 Pcomp
:= First_Entity
(Tagged_Parent
);
9467 while Present
(Pcomp
) loop
9468 if Ekind_In
(Pcomp
, E_Discriminant
, E_Component
) then
9469 if Component_Bit_Offset
(Pcomp
) /= No_Uint
9470 and then Known_Static_Esize
(Pcomp
)
9475 Component_Bit_Offset
(Pcomp
) + Esize
(Pcomp
) - 1);
9478 Next_Entity
(Pcomp
);
9484 -- All done if no component clauses
9486 CC
:= First
(Component_Clauses
(N
));
9492 -- If a tag is present, then create a component clause that places it
9493 -- at the start of the record (otherwise gigi may place it after other
9494 -- fields that have rep clauses).
9496 Fent
:= First_Entity
(Rectype
);
9498 if Nkind
(Fent
) = N_Defining_Identifier
9499 and then Chars
(Fent
) = Name_uTag
9501 Set_Component_Bit_Offset
(Fent
, Uint_0
);
9502 Set_Normalized_Position
(Fent
, Uint_0
);
9503 Set_Normalized_First_Bit
(Fent
, Uint_0
);
9504 Set_Normalized_Position_Max
(Fent
, Uint_0
);
9505 Init_Esize
(Fent
, System_Address_Size
);
9507 Set_Component_Clause
(Fent
,
9508 Make_Component_Clause
(Loc
,
9509 Component_Name
=> Make_Identifier
(Loc
, Name_uTag
),
9511 Position
=> Make_Integer_Literal
(Loc
, Uint_0
),
9512 First_Bit
=> Make_Integer_Literal
(Loc
, Uint_0
),
9514 Make_Integer_Literal
(Loc
,
9515 UI_From_Int
(System_Address_Size
))));
9517 Ccount
:= Ccount
+ 1;
9520 Max_Bit_So_Far
:= Uint_Minus_1
;
9521 Overlap_Check_Required
:= False;
9523 -- Process the component clauses
9525 while Present
(CC
) loop
9528 if Present
(Comp
) then
9529 Ccount
:= Ccount
+ 1;
9531 -- We need a full overlap check if record positions non-monotonic
9533 if Fbit
<= Max_Bit_So_Far
then
9534 Overlap_Check_Required
:= True;
9537 Max_Bit_So_Far
:= Lbit
;
9539 -- Check bit position out of range of specified size
9541 if Has_Size_Clause
(Rectype
)
9542 and then RM_Size
(Rectype
) <= Lbit
9545 ("bit number out of range of specified size",
9548 -- Check for overlap with tag component
9551 if Is_Tagged_Type
(Rectype
)
9552 and then Fbit
< System_Address_Size
9555 ("component overlaps tag field of&",
9556 Component_Name
(CC
), Rectype
);
9557 Overlap_Detected
:= True;
9565 -- Check parent overlap if component might overlap parent field
9567 if Present
(Tagged_Parent
) and then Fbit
<= Parent_Last_Bit
then
9568 Pcomp
:= First_Component_Or_Discriminant
(Tagged_Parent
);
9569 while Present
(Pcomp
) loop
9570 if not Is_Tag
(Pcomp
)
9571 and then Chars
(Pcomp
) /= Name_uParent
9573 Check_Component_Overlap
(Comp
, Pcomp
);
9576 Next_Component_Or_Discriminant
(Pcomp
);
9584 -- Now that we have processed all the component clauses, check for
9585 -- overlap. We have to leave this till last, since the components can
9586 -- appear in any arbitrary order in the representation clause.
9588 -- We do not need this check if all specified ranges were monotonic,
9589 -- as recorded by Overlap_Check_Required being False at this stage.
9591 -- This first section checks if there are any overlapping entries at
9592 -- all. It does this by sorting all entries and then seeing if there are
9593 -- any overlaps. If there are none, then that is decisive, but if there
9594 -- are overlaps, they may still be OK (they may result from fields in
9595 -- different variants).
9597 if Overlap_Check_Required
then
9598 Overlap_Check1
: declare
9600 OC_Fbit
: array (0 .. Ccount
) of Uint
;
9601 -- First-bit values for component clauses, the value is the offset
9602 -- of the first bit of the field from start of record. The zero
9603 -- entry is for use in sorting.
9605 OC_Lbit
: array (0 .. Ccount
) of Uint
;
9606 -- Last-bit values for component clauses, the value is the offset
9607 -- of the last bit of the field from start of record. The zero
9608 -- entry is for use in sorting.
9610 OC_Count
: Natural := 0;
9611 -- Count of entries in OC_Fbit and OC_Lbit
9613 function OC_Lt
(Op1
, Op2
: Natural) return Boolean;
9614 -- Compare routine for Sort
9616 procedure OC_Move
(From
: Natural; To
: Natural);
9617 -- Move routine for Sort
9619 package Sorting
is new GNAT
.Heap_Sort_G
(OC_Move
, OC_Lt
);
9625 function OC_Lt
(Op1
, Op2
: Natural) return Boolean is
9627 return OC_Fbit
(Op1
) < OC_Fbit
(Op2
);
9634 procedure OC_Move
(From
: Natural; To
: Natural) is
9636 OC_Fbit
(To
) := OC_Fbit
(From
);
9637 OC_Lbit
(To
) := OC_Lbit
(From
);
9640 -- Start of processing for Overlap_Check
9643 CC
:= First
(Component_Clauses
(N
));
9644 while Present
(CC
) loop
9646 -- Exclude component clause already marked in error
9648 if not Error_Posted
(CC
) then
9651 if Present
(Comp
) then
9652 OC_Count
:= OC_Count
+ 1;
9653 OC_Fbit
(OC_Count
) := Fbit
;
9654 OC_Lbit
(OC_Count
) := Lbit
;
9661 Sorting
.Sort
(OC_Count
);
9663 Overlap_Check_Required
:= False;
9664 for J
in 1 .. OC_Count
- 1 loop
9665 if OC_Lbit
(J
) >= OC_Fbit
(J
+ 1) then
9666 Overlap_Check_Required
:= True;
9673 -- If Overlap_Check_Required is still True, then we have to do the full
9674 -- scale overlap check, since we have at least two fields that do
9675 -- overlap, and we need to know if that is OK since they are in
9676 -- different variant, or whether we have a definite problem.
9678 if Overlap_Check_Required
then
9679 Overlap_Check2
: declare
9680 C1_Ent
, C2_Ent
: Entity_Id
;
9681 -- Entities of components being checked for overlap
9684 -- Component_List node whose Component_Items are being checked
9687 -- Component declaration for component being checked
9690 C1_Ent
:= First_Entity
(Base_Type
(Rectype
));
9692 -- Loop through all components in record. For each component check
9693 -- for overlap with any of the preceding elements on the component
9694 -- list containing the component and also, if the component is in
9695 -- a variant, check against components outside the case structure.
9696 -- This latter test is repeated recursively up the variant tree.
9698 Main_Component_Loop
: while Present
(C1_Ent
) loop
9699 if not Ekind_In
(C1_Ent
, E_Component
, E_Discriminant
) then
9700 goto Continue_Main_Component_Loop
;
9703 -- Skip overlap check if entity has no declaration node. This
9704 -- happens with discriminants in constrained derived types.
9705 -- Possibly we are missing some checks as a result, but that
9706 -- does not seem terribly serious.
9708 if No
(Declaration_Node
(C1_Ent
)) then
9709 goto Continue_Main_Component_Loop
;
9712 Clist
:= Parent
(List_Containing
(Declaration_Node
(C1_Ent
)));
9714 -- Loop through component lists that need checking. Check the
9715 -- current component list and all lists in variants above us.
9717 Component_List_Loop
: loop
9719 -- If derived type definition, go to full declaration
9720 -- If at outer level, check discriminants if there are any.
9722 if Nkind
(Clist
) = N_Derived_Type_Definition
then
9723 Clist
:= Parent
(Clist
);
9726 -- Outer level of record definition, check discriminants
9728 if Nkind_In
(Clist
, N_Full_Type_Declaration
,
9729 N_Private_Type_Declaration
)
9731 if Has_Discriminants
(Defining_Identifier
(Clist
)) then
9733 First_Discriminant
(Defining_Identifier
(Clist
));
9734 while Present
(C2_Ent
) loop
9735 exit when C1_Ent
= C2_Ent
;
9736 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
9737 Next_Discriminant
(C2_Ent
);
9741 -- Record extension case
9743 elsif Nkind
(Clist
) = N_Derived_Type_Definition
then
9746 -- Otherwise check one component list
9749 Citem
:= First
(Component_Items
(Clist
));
9750 while Present
(Citem
) loop
9751 if Nkind
(Citem
) = N_Component_Declaration
then
9752 C2_Ent
:= Defining_Identifier
(Citem
);
9753 exit when C1_Ent
= C2_Ent
;
9754 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
9761 -- Check for variants above us (the parent of the Clist can
9762 -- be a variant, in which case its parent is a variant part,
9763 -- and the parent of the variant part is a component list
9764 -- whose components must all be checked against the current
9765 -- component for overlap).
9767 if Nkind
(Parent
(Clist
)) = N_Variant
then
9768 Clist
:= Parent
(Parent
(Parent
(Clist
)));
9770 -- Check for possible discriminant part in record, this
9771 -- is treated essentially as another level in the
9772 -- recursion. For this case the parent of the component
9773 -- list is the record definition, and its parent is the
9774 -- full type declaration containing the discriminant
9777 elsif Nkind
(Parent
(Clist
)) = N_Record_Definition
then
9778 Clist
:= Parent
(Parent
((Clist
)));
9780 -- If neither of these two cases, we are at the top of
9784 exit Component_List_Loop
;
9786 end loop Component_List_Loop
;
9788 <<Continue_Main_Component_Loop
>>
9789 Next_Entity
(C1_Ent
);
9791 end loop Main_Component_Loop
;
9795 -- The following circuit deals with warning on record holes (gaps). We
9796 -- skip this check if overlap was detected, since it makes sense for the
9797 -- programmer to fix this illegality before worrying about warnings.
9799 if not Overlap_Detected
and Warn_On_Record_Holes
then
9800 Record_Hole_Check
: declare
9801 Decl
: constant Node_Id
:= Declaration_Node
(Base_Type
(Rectype
));
9802 -- Full declaration of record type
9804 procedure Check_Component_List
9808 -- Check component list CL for holes. The starting bit should be
9809 -- Sbit. which is zero for the main record component list and set
9810 -- appropriately for recursive calls for variants. DS is set to
9811 -- a list of discriminant specifications to be included in the
9812 -- consideration of components. It is No_List if none to consider.
9814 --------------------------
9815 -- Check_Component_List --
9816 --------------------------
9818 procedure Check_Component_List
9826 Compl
:= Integer (List_Length
(Component_Items
(CL
)));
9828 if DS
/= No_List
then
9829 Compl
:= Compl
+ Integer (List_Length
(DS
));
9833 Comps
: array (Natural range 0 .. Compl
) of Entity_Id
;
9834 -- Gather components (zero entry is for sort routine)
9836 Ncomps
: Natural := 0;
9837 -- Number of entries stored in Comps (starting at Comps (1))
9840 -- One component item or discriminant specification
9843 -- Starting bit for next component
9851 function Lt
(Op1
, Op2
: Natural) return Boolean;
9852 -- Compare routine for Sort
9854 procedure Move
(From
: Natural; To
: Natural);
9855 -- Move routine for Sort
9857 package Sorting
is new GNAT
.Heap_Sort_G
(Move
, Lt
);
9863 function Lt
(Op1
, Op2
: Natural) return Boolean is
9865 return Component_Bit_Offset
(Comps
(Op1
))
9867 Component_Bit_Offset
(Comps
(Op2
));
9874 procedure Move
(From
: Natural; To
: Natural) is
9876 Comps
(To
) := Comps
(From
);
9880 -- Gather discriminants into Comp
9882 if DS
/= No_List
then
9883 Citem
:= First
(DS
);
9884 while Present
(Citem
) loop
9885 if Nkind
(Citem
) = N_Discriminant_Specification
then
9887 Ent
: constant Entity_Id
:=
9888 Defining_Identifier
(Citem
);
9890 if Ekind
(Ent
) = E_Discriminant
then
9891 Ncomps
:= Ncomps
+ 1;
9892 Comps
(Ncomps
) := Ent
;
9901 -- Gather component entities into Comp
9903 Citem
:= First
(Component_Items
(CL
));
9904 while Present
(Citem
) loop
9905 if Nkind
(Citem
) = N_Component_Declaration
then
9906 Ncomps
:= Ncomps
+ 1;
9907 Comps
(Ncomps
) := Defining_Identifier
(Citem
);
9913 -- Now sort the component entities based on the first bit.
9914 -- Note we already know there are no overlapping components.
9916 Sorting
.Sort
(Ncomps
);
9918 -- Loop through entries checking for holes
9921 for J
in 1 .. Ncomps
loop
9923 Error_Msg_Uint_1
:= Component_Bit_Offset
(CEnt
) - Nbit
;
9925 if Error_Msg_Uint_1
> 0 then
9927 ("?H?^-bit gap before component&",
9928 Component_Name
(Component_Clause
(CEnt
)), CEnt
);
9931 Nbit
:= Component_Bit_Offset
(CEnt
) + Esize
(CEnt
);
9934 -- Process variant parts recursively if present
9936 if Present
(Variant_Part
(CL
)) then
9937 Variant
:= First
(Variants
(Variant_Part
(CL
)));
9938 while Present
(Variant
) loop
9939 Check_Component_List
9940 (Component_List
(Variant
), Nbit
, No_List
);
9945 end Check_Component_List
;
9947 -- Start of processing for Record_Hole_Check
9954 if Is_Tagged_Type
(Rectype
) then
9955 Sbit
:= UI_From_Int
(System_Address_Size
);
9960 if Nkind
(Decl
) = N_Full_Type_Declaration
9961 and then Nkind
(Type_Definition
(Decl
)) = N_Record_Definition
9963 Check_Component_List
9964 (Component_List
(Type_Definition
(Decl
)),
9966 Discriminant_Specifications
(Decl
));
9969 end Record_Hole_Check
;
9972 -- For records that have component clauses for all components, and whose
9973 -- size is less than or equal to 32, we need to know the size in the
9974 -- front end to activate possible packed array processing where the
9975 -- component type is a record.
9977 -- At this stage Hbit + 1 represents the first unused bit from all the
9978 -- component clauses processed, so if the component clauses are
9979 -- complete, then this is the length of the record.
9981 -- For records longer than System.Storage_Unit, and for those where not
9982 -- all components have component clauses, the back end determines the
9983 -- length (it may for example be appropriate to round up the size
9984 -- to some convenient boundary, based on alignment considerations, etc).
9986 if Unknown_RM_Size
(Rectype
) and then Hbit
+ 1 <= 32 then
9988 -- Nothing to do if at least one component has no component clause
9990 Comp
:= First_Component_Or_Discriminant
(Rectype
);
9991 while Present
(Comp
) loop
9992 exit when No
(Component_Clause
(Comp
));
9993 Next_Component_Or_Discriminant
(Comp
);
9996 -- If we fall out of loop, all components have component clauses
9997 -- and so we can set the size to the maximum value.
10000 Set_RM_Size
(Rectype
, Hbit
+ 1);
10003 end Check_Record_Representation_Clause
;
10009 procedure Check_Size
10013 Biased
: out Boolean)
10015 UT
: constant Entity_Id
:= Underlying_Type
(T
);
10021 -- Reject patently improper size values.
10023 if Is_Elementary_Type
(T
)
10024 and then Siz
> UI_From_Int
(Int
'Last)
10026 Error_Msg_N
("Size value too large for elementary type", N
);
10028 if Nkind
(Original_Node
(N
)) = N_Op_Expon
then
10030 ("\maybe '* was meant, rather than '*'*", Original_Node
(N
));
10034 -- Dismiss generic types
10036 if Is_Generic_Type
(T
)
10038 Is_Generic_Type
(UT
)
10040 Is_Generic_Type
(Root_Type
(UT
))
10044 -- Guard against previous errors
10046 elsif No
(UT
) or else UT
= Any_Type
then
10047 Check_Error_Detected
;
10050 -- Check case of bit packed array
10052 elsif Is_Array_Type
(UT
)
10053 and then Known_Static_Component_Size
(UT
)
10054 and then Is_Bit_Packed_Array
(UT
)
10062 Asiz
:= Component_Size
(UT
);
10063 Indx
:= First_Index
(UT
);
10065 Ityp
:= Etype
(Indx
);
10067 -- If non-static bound, then we are not in the business of
10068 -- trying to check the length, and indeed an error will be
10069 -- issued elsewhere, since sizes of non-static array types
10070 -- cannot be set implicitly or explicitly.
10072 if not Is_OK_Static_Subtype
(Ityp
) then
10076 -- Otherwise accumulate next dimension
10078 Asiz
:= Asiz
* (Expr_Value
(Type_High_Bound
(Ityp
)) -
10079 Expr_Value
(Type_Low_Bound
(Ityp
)) +
10083 exit when No
(Indx
);
10086 if Asiz
<= Siz
then
10090 Error_Msg_Uint_1
:= Asiz
;
10092 ("size for& too small, minimum allowed is ^", N
, T
);
10093 Set_Esize
(T
, Asiz
);
10094 Set_RM_Size
(T
, Asiz
);
10098 -- All other composite types are ignored
10100 elsif Is_Composite_Type
(UT
) then
10103 -- For fixed-point types, don't check minimum if type is not frozen,
10104 -- since we don't know all the characteristics of the type that can
10105 -- affect the size (e.g. a specified small) till freeze time.
10107 elsif Is_Fixed_Point_Type
(UT
)
10108 and then not Is_Frozen
(UT
)
10112 -- Cases for which a minimum check is required
10115 -- Ignore if specified size is correct for the type
10117 if Known_Esize
(UT
) and then Siz
= Esize
(UT
) then
10121 -- Otherwise get minimum size
10123 M
:= UI_From_Int
(Minimum_Size
(UT
));
10127 -- Size is less than minimum size, but one possibility remains
10128 -- that we can manage with the new size if we bias the type.
10130 M
:= UI_From_Int
(Minimum_Size
(UT
, Biased
=> True));
10133 Error_Msg_Uint_1
:= M
;
10135 ("size for& too small, minimum allowed is ^", N
, T
);
10137 Set_RM_Size
(T
, M
);
10145 --------------------------
10146 -- Freeze_Entity_Checks --
10147 --------------------------
10149 procedure Freeze_Entity_Checks
(N
: Node_Id
) is
10150 procedure Hide_Non_Overridden_Subprograms
(Typ
: Entity_Id
);
10151 -- Inspect the primitive operations of type Typ and hide all pairs of
10152 -- implicitly declared non-overridden non-fully conformant homographs
10153 -- (Ada RM 8.3 12.3/2).
10155 -------------------------------------
10156 -- Hide_Non_Overridden_Subprograms --
10157 -------------------------------------
10159 procedure Hide_Non_Overridden_Subprograms
(Typ
: Entity_Id
) is
10160 procedure Hide_Matching_Homographs
10161 (Subp_Id
: Entity_Id
;
10162 Start_Elmt
: Elmt_Id
);
10163 -- Inspect a list of primitive operations starting with Start_Elmt
10164 -- and find matching implicitly declared non-overridden non-fully
10165 -- conformant homographs of Subp_Id. If found, all matches along
10166 -- with Subp_Id are hidden from all visibility.
10168 function Is_Non_Overridden_Or_Null_Procedure
10169 (Subp_Id
: Entity_Id
) return Boolean;
10170 -- Determine whether subprogram Subp_Id is implicitly declared non-
10171 -- overridden subprogram or an implicitly declared null procedure.
10173 ------------------------------
10174 -- Hide_Matching_Homographs --
10175 ------------------------------
10177 procedure Hide_Matching_Homographs
10178 (Subp_Id
: Entity_Id
;
10179 Start_Elmt
: Elmt_Id
)
10182 Prim_Elmt
: Elmt_Id
;
10185 Prim_Elmt
:= Start_Elmt
;
10186 while Present
(Prim_Elmt
) loop
10187 Prim
:= Node
(Prim_Elmt
);
10189 -- The current primitive is implicitly declared non-overridden
10190 -- non-fully conformant homograph of Subp_Id. Both subprograms
10191 -- must be hidden from visibility.
10193 if Chars
(Prim
) = Chars
(Subp_Id
)
10194 and then Is_Non_Overridden_Or_Null_Procedure
(Prim
)
10195 and then not Fully_Conformant
(Prim
, Subp_Id
)
10197 Set_Is_Hidden_Non_Overridden_Subpgm
(Prim
);
10198 Set_Is_Immediately_Visible
(Prim
, False);
10199 Set_Is_Potentially_Use_Visible
(Prim
, False);
10201 Set_Is_Hidden_Non_Overridden_Subpgm
(Subp_Id
);
10202 Set_Is_Immediately_Visible
(Subp_Id
, False);
10203 Set_Is_Potentially_Use_Visible
(Subp_Id
, False);
10206 Next_Elmt
(Prim_Elmt
);
10208 end Hide_Matching_Homographs
;
10210 -----------------------------------------
10211 -- Is_Non_Overridden_Or_Null_Procedure --
10212 -----------------------------------------
10214 function Is_Non_Overridden_Or_Null_Procedure
10215 (Subp_Id
: Entity_Id
) return Boolean
10217 Alias_Id
: Entity_Id
;
10220 -- The subprogram is inherited (implicitly declared), it does not
10221 -- override and does not cover a primitive of an interface.
10223 if Ekind_In
(Subp_Id
, E_Function
, E_Procedure
)
10224 and then Present
(Alias
(Subp_Id
))
10225 and then No
(Interface_Alias
(Subp_Id
))
10226 and then No
(Overridden_Operation
(Subp_Id
))
10228 Alias_Id
:= Alias
(Subp_Id
);
10230 if Requires_Overriding
(Alias_Id
) then
10233 elsif Nkind
(Parent
(Alias_Id
)) = N_Procedure_Specification
10234 and then Null_Present
(Parent
(Alias_Id
))
10241 end Is_Non_Overridden_Or_Null_Procedure
;
10245 Prim_Ops
: constant Elist_Id
:= Direct_Primitive_Operations
(Typ
);
10247 Prim_Elmt
: Elmt_Id
;
10249 -- Start of processing for Hide_Non_Overridden_Subprograms
10252 -- Inspect the list of primitives looking for non-overridden
10255 if Present
(Prim_Ops
) then
10256 Prim_Elmt
:= First_Elmt
(Prim_Ops
);
10257 while Present
(Prim_Elmt
) loop
10258 Prim
:= Node
(Prim_Elmt
);
10259 Next_Elmt
(Prim_Elmt
);
10261 if Is_Non_Overridden_Or_Null_Procedure
(Prim
) then
10262 Hide_Matching_Homographs
10264 Start_Elmt
=> Prim_Elmt
);
10268 end Hide_Non_Overridden_Subprograms
;
10270 ---------------------
10271 -- Local variables --
10272 ---------------------
10274 E
: constant Entity_Id
:= Entity
(N
);
10276 Non_Generic_Case
: constant Boolean := Nkind
(N
) = N_Freeze_Entity
;
10277 -- True in non-generic case. Some of the processing here is skipped
10278 -- for the generic case since it is not needed. Basically in the
10279 -- generic case, we only need to do stuff that might generate error
10280 -- messages or warnings.
10282 -- Start of processing for Freeze_Entity_Checks
10285 -- Remember that we are processing a freezing entity. Required to
10286 -- ensure correct decoration of internal entities associated with
10287 -- interfaces (see New_Overloaded_Entity).
10289 Inside_Freezing_Actions
:= Inside_Freezing_Actions
+ 1;
10291 -- For tagged types covering interfaces add internal entities that link
10292 -- the primitives of the interfaces with the primitives that cover them.
10293 -- Note: These entities were originally generated only when generating
10294 -- code because their main purpose was to provide support to initialize
10295 -- the secondary dispatch tables. They are now generated also when
10296 -- compiling with no code generation to provide ASIS the relationship
10297 -- between interface primitives and tagged type primitives. They are
10298 -- also used to locate primitives covering interfaces when processing
10299 -- generics (see Derive_Subprograms).
10301 -- This is not needed in the generic case
10303 if Ada_Version
>= Ada_2005
10304 and then Non_Generic_Case
10305 and then Ekind
(E
) = E_Record_Type
10306 and then Is_Tagged_Type
(E
)
10307 and then not Is_Interface
(E
)
10308 and then Has_Interfaces
(E
)
10310 -- This would be a good common place to call the routine that checks
10311 -- overriding of interface primitives (and thus factorize calls to
10312 -- Check_Abstract_Overriding located at different contexts in the
10313 -- compiler). However, this is not possible because it causes
10314 -- spurious errors in case of late overriding.
10316 Add_Internal_Interface_Entities
(E
);
10319 -- After all forms of overriding have been resolved, a tagged type may
10320 -- be left with a set of implicitly declared and possibly erroneous
10321 -- abstract subprograms, null procedures and subprograms that require
10322 -- overriding. If this set contains fully conformat homographs, then one
10323 -- is chosen arbitrarily (already done during resolution), otherwise all
10324 -- remaining non-fully conformant homographs are hidden from visibility
10325 -- (Ada RM 8.3 12.3/2).
10327 if Is_Tagged_Type
(E
) then
10328 Hide_Non_Overridden_Subprograms
(E
);
10333 if Ekind
(E
) = E_Record_Type
10334 and then Is_CPP_Class
(E
)
10335 and then Is_Tagged_Type
(E
)
10336 and then Tagged_Type_Expansion
10338 if CPP_Num_Prims
(E
) = 0 then
10340 -- If the CPP type has user defined components then it must import
10341 -- primitives from C++. This is required because if the C++ class
10342 -- has no primitives then the C++ compiler does not added the _tag
10343 -- component to the type.
10345 if First_Entity
(E
) /= Last_Entity
(E
) then
10347 ("'C'P'P type must import at least one primitive from C++??",
10352 -- Check that all its primitives are abstract or imported from C++.
10353 -- Check also availability of the C++ constructor.
10356 Has_Constructors
: constant Boolean := Has_CPP_Constructors
(E
);
10358 Error_Reported
: Boolean := False;
10362 Elmt
:= First_Elmt
(Primitive_Operations
(E
));
10363 while Present
(Elmt
) loop
10364 Prim
:= Node
(Elmt
);
10366 if Comes_From_Source
(Prim
) then
10367 if Is_Abstract_Subprogram
(Prim
) then
10370 elsif not Is_Imported
(Prim
)
10371 or else Convention
(Prim
) /= Convention_CPP
10374 ("primitives of 'C'P'P types must be imported from C++ "
10375 & "or abstract??", Prim
);
10377 elsif not Has_Constructors
10378 and then not Error_Reported
10380 Error_Msg_Name_1
:= Chars
(E
);
10382 ("??'C'P'P constructor required for type %", Prim
);
10383 Error_Reported
:= True;
10392 -- Check Ada derivation of CPP type
10394 if Expander_Active
-- why? losing errors in -gnatc mode???
10395 and then Present
(Etype
(E
)) -- defend against errors
10396 and then Tagged_Type_Expansion
10397 and then Ekind
(E
) = E_Record_Type
10398 and then Etype
(E
) /= E
10399 and then Is_CPP_Class
(Etype
(E
))
10400 and then CPP_Num_Prims
(Etype
(E
)) > 0
10401 and then not Is_CPP_Class
(E
)
10402 and then not Has_CPP_Constructors
(Etype
(E
))
10404 -- If the parent has C++ primitives but it has no constructor then
10405 -- check that all the primitives are overridden in this derivation;
10406 -- otherwise the constructor of the parent is needed to build the
10414 Elmt
:= First_Elmt
(Primitive_Operations
(E
));
10415 while Present
(Elmt
) loop
10416 Prim
:= Node
(Elmt
);
10418 if not Is_Abstract_Subprogram
(Prim
)
10419 and then No
(Interface_Alias
(Prim
))
10420 and then Find_Dispatching_Type
(Ultimate_Alias
(Prim
)) /= E
10422 Error_Msg_Name_1
:= Chars
(Etype
(E
));
10424 ("'C'P'P constructor required for parent type %", E
);
10433 Inside_Freezing_Actions
:= Inside_Freezing_Actions
- 1;
10435 -- If we have a type with predicates, build predicate function. This
10436 -- is not needed in the generic case, and is not needed within TSS
10437 -- subprograms and other predefined primitives.
10439 if Non_Generic_Case
10440 and then Is_Type
(E
)
10441 and then Has_Predicates
(E
)
10442 and then not Within_Internal_Subprogram
10444 Build_Predicate_Functions
(E
, N
);
10447 -- If type has delayed aspects, this is where we do the preanalysis at
10448 -- the freeze point, as part of the consistent visibility check. Note
10449 -- that this must be done after calling Build_Predicate_Functions or
10450 -- Build_Invariant_Procedure since these subprograms fix occurrences of
10451 -- the subtype name in the saved expression so that they will not cause
10452 -- trouble in the preanalysis.
10454 -- This is also not needed in the generic case
10456 if Non_Generic_Case
10457 and then Has_Delayed_Aspects
(E
)
10458 and then Scope
(E
) = Current_Scope
10460 -- Retrieve the visibility to the discriminants in order to properly
10461 -- analyze the aspects.
10463 Push_Scope_And_Install_Discriminants
(E
);
10469 -- Look for aspect specification entries for this entity
10471 Ritem
:= First_Rep_Item
(E
);
10472 while Present
(Ritem
) loop
10473 if Nkind
(Ritem
) = N_Aspect_Specification
10474 and then Entity
(Ritem
) = E
10475 and then Is_Delayed_Aspect
(Ritem
)
10477 Check_Aspect_At_Freeze_Point
(Ritem
);
10480 Next_Rep_Item
(Ritem
);
10484 Uninstall_Discriminants_And_Pop_Scope
(E
);
10487 -- For a record type, deal with variant parts. This has to be delayed
10488 -- to this point, because of the issue of statically predicated
10489 -- subtypes, which we have to ensure are frozen before checking
10490 -- choices, since we need to have the static choice list set.
10492 if Is_Record_Type
(E
) then
10493 Check_Variant_Part
: declare
10494 D
: constant Node_Id
:= Declaration_Node
(E
);
10499 Others_Present
: Boolean;
10500 pragma Warnings
(Off
, Others_Present
);
10501 -- Indicates others present, not used in this case
10503 procedure Non_Static_Choice_Error
(Choice
: Node_Id
);
10504 -- Error routine invoked by the generic instantiation below when
10505 -- the variant part has a non static choice.
10507 procedure Process_Declarations
(Variant
: Node_Id
);
10508 -- Processes declarations associated with a variant. We analyzed
10509 -- the declarations earlier (in Sem_Ch3.Analyze_Variant_Part),
10510 -- but we still need the recursive call to Check_Choices for any
10511 -- nested variant to get its choices properly processed. This is
10512 -- also where we expand out the choices if expansion is active.
10514 package Variant_Choices_Processing
is new
10515 Generic_Check_Choices
10516 (Process_Empty_Choice
=> No_OP
,
10517 Process_Non_Static_Choice
=> Non_Static_Choice_Error
,
10518 Process_Associated_Node
=> Process_Declarations
);
10519 use Variant_Choices_Processing
;
10521 -----------------------------
10522 -- Non_Static_Choice_Error --
10523 -----------------------------
10525 procedure Non_Static_Choice_Error
(Choice
: Node_Id
) is
10527 Flag_Non_Static_Expr
10528 ("choice given in variant part is not static!", Choice
);
10529 end Non_Static_Choice_Error
;
10531 --------------------------
10532 -- Process_Declarations --
10533 --------------------------
10535 procedure Process_Declarations
(Variant
: Node_Id
) is
10536 CL
: constant Node_Id
:= Component_List
(Variant
);
10540 -- Check for static predicate present in this variant
10542 if Has_SP_Choice
(Variant
) then
10544 -- Here we expand. You might expect to find this call in
10545 -- Expand_N_Variant_Part, but that is called when we first
10546 -- see the variant part, and we cannot do this expansion
10547 -- earlier than the freeze point, since for statically
10548 -- predicated subtypes, the predicate is not known till
10549 -- the freeze point.
10551 -- Furthermore, we do this expansion even if the expander
10552 -- is not active, because other semantic processing, e.g.
10553 -- for aggregates, requires the expanded list of choices.
10555 -- If the expander is not active, then we can't just clobber
10556 -- the list since it would invalidate the ASIS -gnatct tree.
10557 -- So we have to rewrite the variant part with a Rewrite
10558 -- call that replaces it with a copy and clobber the copy.
10560 if not Expander_Active
then
10562 NewV
: constant Node_Id
:= New_Copy
(Variant
);
10564 Set_Discrete_Choices
10565 (NewV
, New_Copy_List
(Discrete_Choices
(Variant
)));
10566 Rewrite
(Variant
, NewV
);
10570 Expand_Static_Predicates_In_Choices
(Variant
);
10573 -- We don't need to worry about the declarations in the variant
10574 -- (since they were analyzed by Analyze_Choices when we first
10575 -- encountered the variant), but we do need to take care of
10576 -- expansion of any nested variants.
10578 if not Null_Present
(CL
) then
10579 VP
:= Variant_Part
(CL
);
10581 if Present
(VP
) then
10583 (VP
, Variants
(VP
), Etype
(Name
(VP
)), Others_Present
);
10586 end Process_Declarations
;
10588 -- Start of processing for Check_Variant_Part
10591 -- Find component list
10595 if Nkind
(D
) = N_Full_Type_Declaration
then
10596 T
:= Type_Definition
(D
);
10598 if Nkind
(T
) = N_Record_Definition
then
10599 C
:= Component_List
(T
);
10601 elsif Nkind
(T
) = N_Derived_Type_Definition
10602 and then Present
(Record_Extension_Part
(T
))
10604 C
:= Component_List
(Record_Extension_Part
(T
));
10608 -- Case of variant part present
10610 if Present
(C
) and then Present
(Variant_Part
(C
)) then
10611 VP
:= Variant_Part
(C
);
10616 (VP
, Variants
(VP
), Etype
(Name
(VP
)), Others_Present
);
10618 -- If the last variant does not contain the Others choice,
10619 -- replace it with an N_Others_Choice node since Gigi always
10620 -- wants an Others. Note that we do not bother to call Analyze
10621 -- on the modified variant part, since its only effect would be
10622 -- to compute the Others_Discrete_Choices node laboriously, and
10623 -- of course we already know the list of choices corresponding
10624 -- to the others choice (it's the list we're replacing).
10626 -- We only want to do this if the expander is active, since
10627 -- we do not want to clobber the ASIS tree.
10629 if Expander_Active
then
10631 Last_Var
: constant Node_Id
:=
10632 Last_Non_Pragma
(Variants
(VP
));
10634 Others_Node
: Node_Id
;
10637 if Nkind
(First
(Discrete_Choices
(Last_Var
))) /=
10640 Others_Node
:= Make_Others_Choice
(Sloc
(Last_Var
));
10641 Set_Others_Discrete_Choices
10642 (Others_Node
, Discrete_Choices
(Last_Var
));
10643 Set_Discrete_Choices
10644 (Last_Var
, New_List
(Others_Node
));
10649 end Check_Variant_Part
;
10651 end Freeze_Entity_Checks
;
10653 -------------------------
10654 -- Get_Alignment_Value --
10655 -------------------------
10657 function Get_Alignment_Value
(Expr
: Node_Id
) return Uint
is
10658 Align
: constant Uint
:= Static_Integer
(Expr
);
10661 if Align
= No_Uint
then
10664 elsif Align
<= 0 then
10665 Error_Msg_N
("alignment value must be positive", Expr
);
10669 for J
in Int
range 0 .. 64 loop
10671 M
: constant Uint
:= Uint_2
** J
;
10674 exit when M
= Align
;
10678 ("alignment value must be power of 2", Expr
);
10686 end Get_Alignment_Value
;
10688 -------------------------------------
10689 -- Inherit_Aspects_At_Freeze_Point --
10690 -------------------------------------
10692 procedure Inherit_Aspects_At_Freeze_Point
(Typ
: Entity_Id
) is
10693 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
10694 (Rep_Item
: Node_Id
) return Boolean;
10695 -- This routine checks if Rep_Item is either a pragma or an aspect
10696 -- specification node whose correponding pragma (if any) is present in
10697 -- the Rep Item chain of the entity it has been specified to.
10699 --------------------------------------------------
10700 -- Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item --
10701 --------------------------------------------------
10703 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
10704 (Rep_Item
: Node_Id
) return Boolean
10708 Nkind
(Rep_Item
) = N_Pragma
10709 or else Present_In_Rep_Item
10710 (Entity
(Rep_Item
), Aspect_Rep_Item
(Rep_Item
));
10711 end Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
;
10713 -- Start of processing for Inherit_Aspects_At_Freeze_Point
10716 -- A representation item is either subtype-specific (Size and Alignment
10717 -- clauses) or type-related (all others). Subtype-specific aspects may
10718 -- differ for different subtypes of the same type (RM 13.1.8).
10720 -- A derived type inherits each type-related representation aspect of
10721 -- its parent type that was directly specified before the declaration of
10722 -- the derived type (RM 13.1.15).
10724 -- A derived subtype inherits each subtype-specific representation
10725 -- aspect of its parent subtype that was directly specified before the
10726 -- declaration of the derived type (RM 13.1.15).
10728 -- The general processing involves inheriting a representation aspect
10729 -- from a parent type whenever the first rep item (aspect specification,
10730 -- attribute definition clause, pragma) corresponding to the given
10731 -- representation aspect in the rep item chain of Typ, if any, isn't
10732 -- directly specified to Typ but to one of its parents.
10734 -- ??? Note that, for now, just a limited number of representation
10735 -- aspects have been inherited here so far. Many of them are
10736 -- still inherited in Sem_Ch3. This will be fixed soon. Here is
10737 -- a non- exhaustive list of aspects that likely also need to
10738 -- be moved to this routine: Alignment, Component_Alignment,
10739 -- Component_Size, Machine_Radix, Object_Size, Pack, Predicates,
10740 -- Preelaborable_Initialization, RM_Size and Small.
10742 -- In addition, Convention must be propagated from base type to subtype,
10743 -- because the subtype may have been declared on an incomplete view.
10745 if Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
then
10751 if not Has_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
, False)
10752 and then Has_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
)
10753 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
10754 (Get_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
))
10756 Set_Is_Ada_2005_Only
(Typ
);
10761 if not Has_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
, False)
10762 and then Has_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
)
10763 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
10764 (Get_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
))
10766 Set_Is_Ada_2012_Only
(Typ
);
10771 if not Has_Rep_Item
(Typ
, Name_Atomic
, Name_Shared
, False)
10772 and then Has_Rep_Pragma
(Typ
, Name_Atomic
, Name_Shared
)
10773 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
10774 (Get_Rep_Item
(Typ
, Name_Atomic
, Name_Shared
))
10776 Set_Is_Atomic
(Typ
);
10777 Set_Treat_As_Volatile
(Typ
);
10778 Set_Is_Volatile
(Typ
);
10783 if Is_Record_Type
(Typ
)
10784 and then Typ
/= Base_Type
(Typ
) and then Is_Frozen
(Base_Type
(Typ
))
10786 Set_Convention
(Typ
, Convention
(Base_Type
(Typ
)));
10789 -- Default_Component_Value
10791 if Is_Array_Type
(Typ
)
10792 and then Is_Base_Type
(Typ
)
10793 and then Has_Rep_Item
(Typ
, Name_Default_Component_Value
, False)
10794 and then Has_Rep_Item
(Typ
, Name_Default_Component_Value
)
10796 Set_Default_Aspect_Component_Value
(Typ
,
10797 Default_Aspect_Component_Value
10798 (Entity
(Get_Rep_Item
(Typ
, Name_Default_Component_Value
))));
10803 if Is_Scalar_Type
(Typ
)
10804 and then Is_Base_Type
(Typ
)
10805 and then Has_Rep_Item
(Typ
, Name_Default_Value
, False)
10806 and then Has_Rep_Item
(Typ
, Name_Default_Value
)
10808 Set_Default_Aspect_Value
(Typ
,
10809 Default_Aspect_Value
10810 (Entity
(Get_Rep_Item
(Typ
, Name_Default_Value
))));
10815 if not Has_Rep_Item
(Typ
, Name_Discard_Names
, False)
10816 and then Has_Rep_Item
(Typ
, Name_Discard_Names
)
10817 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
10818 (Get_Rep_Item
(Typ
, Name_Discard_Names
))
10820 Set_Discard_Names
(Typ
);
10825 if not Has_Rep_Item
(Typ
, Name_Invariant
, False)
10826 and then Has_Rep_Item
(Typ
, Name_Invariant
)
10827 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
10828 (Get_Rep_Item
(Typ
, Name_Invariant
))
10830 Set_Has_Invariants
(Typ
);
10832 if Class_Present
(Get_Rep_Item
(Typ
, Name_Invariant
)) then
10833 Set_Has_Inheritable_Invariants
(Typ
);
10836 -- If we have a subtype with invariants, whose base type does not have
10837 -- invariants, copy these invariants to the base type. This happens for
10838 -- the case of implicit base types created for scalar and array types.
10840 elsif Has_Invariants
(Typ
)
10841 and then not Has_Invariants
(Base_Type
(Typ
))
10843 Set_Has_Invariants
(Base_Type
(Typ
));
10844 Set_Invariant_Procedure
(Base_Type
(Typ
), Invariant_Procedure
(Typ
));
10849 if not Has_Rep_Item
(Typ
, Name_Volatile
, False)
10850 and then Has_Rep_Item
(Typ
, Name_Volatile
)
10851 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
10852 (Get_Rep_Item
(Typ
, Name_Volatile
))
10854 Set_Treat_As_Volatile
(Typ
);
10855 Set_Is_Volatile
(Typ
);
10858 -- Inheritance for derived types only
10860 if Is_Derived_Type
(Typ
) then
10862 Bas_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
10863 Imp_Bas_Typ
: constant Entity_Id
:= Implementation_Base_Type
(Typ
);
10866 -- Atomic_Components
10868 if not Has_Rep_Item
(Typ
, Name_Atomic_Components
, False)
10869 and then Has_Rep_Item
(Typ
, Name_Atomic_Components
)
10870 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
10871 (Get_Rep_Item
(Typ
, Name_Atomic_Components
))
10873 Set_Has_Atomic_Components
(Imp_Bas_Typ
);
10876 -- Volatile_Components
10878 if not Has_Rep_Item
(Typ
, Name_Volatile_Components
, False)
10879 and then Has_Rep_Item
(Typ
, Name_Volatile_Components
)
10880 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
10881 (Get_Rep_Item
(Typ
, Name_Volatile_Components
))
10883 Set_Has_Volatile_Components
(Imp_Bas_Typ
);
10886 -- Finalize_Storage_Only
10888 if not Has_Rep_Pragma
(Typ
, Name_Finalize_Storage_Only
, False)
10889 and then Has_Rep_Pragma
(Typ
, Name_Finalize_Storage_Only
)
10891 Set_Finalize_Storage_Only
(Bas_Typ
);
10894 -- Universal_Aliasing
10896 if not Has_Rep_Item
(Typ
, Name_Universal_Aliasing
, False)
10897 and then Has_Rep_Item
(Typ
, Name_Universal_Aliasing
)
10898 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
10899 (Get_Rep_Item
(Typ
, Name_Universal_Aliasing
))
10901 Set_Universal_Aliasing
(Imp_Bas_Typ
);
10906 if Is_Record_Type
(Typ
) then
10907 if not Has_Rep_Item
(Typ
, Name_Bit_Order
, False)
10908 and then Has_Rep_Item
(Typ
, Name_Bit_Order
)
10910 Set_Reverse_Bit_Order
(Bas_Typ
,
10911 Reverse_Bit_Order
(Entity
(Name
10912 (Get_Rep_Item
(Typ
, Name_Bit_Order
)))));
10916 -- Scalar_Storage_Order
10918 -- Note: the aspect is specified on a first subtype, but recorded
10919 -- in a flag of the base type!
10921 if (Is_Record_Type
(Typ
) or else Is_Array_Type
(Typ
))
10926 -- For a type extension, always inherit from parent; otherwise
10927 -- inherit if no default applies. Note: we do not check for
10928 -- an explicit rep item on the parent type when inheriting,
10929 -- because the parent SSO may itself have been set by default.
10931 if not Has_Rep_Item
(First_Subtype
(Typ
),
10932 Name_Scalar_Storage_Order
, False)
10933 and then (Is_Tagged_Type
(Bas_Typ
)
10935 not (SSO_Set_Low_By_Default
(Bas_Typ
)
10937 SSO_Set_High_By_Default
(Bas_Typ
)))
10939 Set_Reverse_Storage_Order
(Bas_Typ
,
10940 Reverse_Storage_Order
10941 (Implementation_Base_Type
(Etype
(Bas_Typ
))));
10943 -- Clear default SSO indications, since the inherited aspect
10944 -- which was set explicitly overrides the default.
10946 Set_SSO_Set_Low_By_Default
(Bas_Typ
, False);
10947 Set_SSO_Set_High_By_Default
(Bas_Typ
, False);
10952 end Inherit_Aspects_At_Freeze_Point
;
10958 procedure Initialize
is
10960 Address_Clause_Checks
.Init
;
10961 Independence_Checks
.Init
;
10962 Unchecked_Conversions
.Init
;
10965 ---------------------------
10966 -- Install_Discriminants --
10967 ---------------------------
10969 procedure Install_Discriminants
(E
: Entity_Id
) is
10973 Disc
:= First_Discriminant
(E
);
10974 while Present
(Disc
) loop
10975 Prev
:= Current_Entity
(Disc
);
10976 Set_Current_Entity
(Disc
);
10977 Set_Is_Immediately_Visible
(Disc
);
10978 Set_Homonym
(Disc
, Prev
);
10979 Next_Discriminant
(Disc
);
10981 end Install_Discriminants
;
10983 -------------------------
10984 -- Is_Operational_Item --
10985 -------------------------
10987 function Is_Operational_Item
(N
: Node_Id
) return Boolean is
10989 if Nkind
(N
) /= N_Attribute_Definition_Clause
then
10994 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Chars
(N
));
10996 return Id
= Attribute_Input
10997 or else Id
= Attribute_Output
10998 or else Id
= Attribute_Read
10999 or else Id
= Attribute_Write
11000 or else Id
= Attribute_External_Tag
;
11003 end Is_Operational_Item
;
11005 -------------------------
11006 -- Is_Predicate_Static --
11007 -------------------------
11009 -- Note: the basic legality of the expression has already been checked, so
11010 -- we don't need to worry about cases or ranges on strings for example.
11012 function Is_Predicate_Static
11014 Nam
: Name_Id
) return Boolean
11016 function All_Static_Case_Alternatives
(L
: List_Id
) return Boolean;
11017 -- Given a list of case expression alternatives, returns True if all
11018 -- the alternatives are static (have all static choices, and a static
11021 function All_Static_Choices
(L
: List_Id
) return Boolean;
11022 -- Returns true if all elements of the list are OK static choices
11023 -- as defined below for Is_Static_Choice. Used for case expression
11024 -- alternatives and for the right operand of a membership test. An
11025 -- others_choice is static if the corresponding expression is static.
11026 -- The staticness of the bounds is checked separately.
11028 function Is_Static_Choice
(N
: Node_Id
) return Boolean;
11029 -- Returns True if N represents a static choice (static subtype, or
11030 -- static subtype indication, or static expression, or static range).
11032 -- Note that this is a bit more inclusive than we actually need
11033 -- (in particular membership tests do not allow the use of subtype
11034 -- indications). But that doesn't matter, we have already checked
11035 -- that the construct is legal to get this far.
11037 function Is_Type_Ref
(N
: Node_Id
) return Boolean;
11038 pragma Inline
(Is_Type_Ref
);
11039 -- Returns True if N is a reference to the type for the predicate in the
11040 -- expression (i.e. if it is an identifier whose Chars field matches the
11041 -- Nam given in the call). N must not be parenthesized, if the type name
11042 -- appears in parens, this routine will return False.
11044 ----------------------------------
11045 -- All_Static_Case_Alternatives --
11046 ----------------------------------
11048 function All_Static_Case_Alternatives
(L
: List_Id
) return Boolean is
11053 while Present
(N
) loop
11054 if not (All_Static_Choices
(Discrete_Choices
(N
))
11055 and then Is_OK_Static_Expression
(Expression
(N
)))
11064 end All_Static_Case_Alternatives
;
11066 ------------------------
11067 -- All_Static_Choices --
11068 ------------------------
11070 function All_Static_Choices
(L
: List_Id
) return Boolean is
11075 while Present
(N
) loop
11076 if not Is_Static_Choice
(N
) then
11084 end All_Static_Choices
;
11086 ----------------------
11087 -- Is_Static_Choice --
11088 ----------------------
11090 function Is_Static_Choice
(N
: Node_Id
) return Boolean is
11092 return Nkind
(N
) = N_Others_Choice
11093 or else Is_OK_Static_Expression
(N
)
11094 or else (Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
))
11095 and then Is_OK_Static_Subtype
(Entity
(N
)))
11096 or else (Nkind
(N
) = N_Subtype_Indication
11097 and then Is_OK_Static_Subtype
(Entity
(N
)))
11098 or else (Nkind
(N
) = N_Range
and then Is_OK_Static_Range
(N
));
11099 end Is_Static_Choice
;
11105 function Is_Type_Ref
(N
: Node_Id
) return Boolean is
11107 return Nkind
(N
) = N_Identifier
11108 and then Chars
(N
) = Nam
11109 and then Paren_Count
(N
) = 0;
11112 -- Start of processing for Is_Predicate_Static
11115 -- Predicate_Static means one of the following holds. Numbers are the
11116 -- corresponding paragraph numbers in (RM 3.2.4(16-22)).
11118 -- 16: A static expression
11120 if Is_OK_Static_Expression
(Expr
) then
11123 -- 17: A membership test whose simple_expression is the current
11124 -- instance, and whose membership_choice_list meets the requirements
11125 -- for a static membership test.
11127 elsif Nkind
(Expr
) in N_Membership_Test
11128 and then ((Present
(Right_Opnd
(Expr
))
11129 and then Is_Static_Choice
(Right_Opnd
(Expr
)))
11131 (Present
(Alternatives
(Expr
))
11132 and then All_Static_Choices
(Alternatives
(Expr
))))
11136 -- 18. A case_expression whose selecting_expression is the current
11137 -- instance, and whose dependent expressions are static expressions.
11139 elsif Nkind
(Expr
) = N_Case_Expression
11140 and then Is_Type_Ref
(Expression
(Expr
))
11141 and then All_Static_Case_Alternatives
(Alternatives
(Expr
))
11145 -- 19. A call to a predefined equality or ordering operator, where one
11146 -- operand is the current instance, and the other is a static
11149 -- Note: the RM is clearly wrong here in not excluding string types.
11150 -- Without this exclusion, we would allow expressions like X > "ABC"
11151 -- to be considered as predicate-static, which is clearly not intended,
11152 -- since the idea is for predicate-static to be a subset of normal
11153 -- static expressions (and "DEF" > "ABC" is not a static expression).
11155 -- However, we do allow internally generated (not from source) equality
11156 -- and inequality operations to be valid on strings (this helps deal
11157 -- with cases where we transform A in "ABC" to A = "ABC).
11159 elsif Nkind
(Expr
) in N_Op_Compare
11160 and then ((not Is_String_Type
(Etype
(Left_Opnd
(Expr
))))
11161 or else (Nkind_In
(Expr
, N_Op_Eq
, N_Op_Ne
)
11162 and then not Comes_From_Source
(Expr
)))
11163 and then ((Is_Type_Ref
(Left_Opnd
(Expr
))
11164 and then Is_OK_Static_Expression
(Right_Opnd
(Expr
)))
11166 (Is_Type_Ref
(Right_Opnd
(Expr
))
11167 and then Is_OK_Static_Expression
(Left_Opnd
(Expr
))))
11171 -- 20. A call to a predefined boolean logical operator, where each
11172 -- operand is predicate-static.
11174 elsif (Nkind_In
(Expr
, N_Op_And
, N_Op_Or
, N_Op_Xor
)
11175 and then Is_Predicate_Static
(Left_Opnd
(Expr
), Nam
)
11176 and then Is_Predicate_Static
(Right_Opnd
(Expr
), Nam
))
11178 (Nkind
(Expr
) = N_Op_Not
11179 and then Is_Predicate_Static
(Right_Opnd
(Expr
), Nam
))
11183 -- 21. A short-circuit control form where both operands are
11184 -- predicate-static.
11186 elsif Nkind
(Expr
) in N_Short_Circuit
11187 and then Is_Predicate_Static
(Left_Opnd
(Expr
), Nam
)
11188 and then Is_Predicate_Static
(Right_Opnd
(Expr
), Nam
)
11192 -- 22. A parenthesized predicate-static expression. This does not
11193 -- require any special test, since we just ignore paren levels in
11194 -- all the cases above.
11196 -- One more test that is an implementation artifact caused by the fact
11197 -- that we are analyzing not the original expression, but the generated
11198 -- expression in the body of the predicate function. This can include
11199 -- references to inherited predicates, so that the expression we are
11200 -- processing looks like:
11202 -- expression and then xxPredicate (typ (Inns))
11204 -- Where the call is to a Predicate function for an inherited predicate.
11205 -- We simply ignore such a call (which could be to either a dynamic or
11206 -- a static predicate, but remember that we can have a Static_Predicate
11207 -- for a non-static subtype).
11209 elsif Nkind
(Expr
) = N_Function_Call
11210 and then Is_Predicate_Function
(Entity
(Name
(Expr
)))
11214 -- That's an exhaustive list of tests, all other cases are not
11215 -- predicate-static, so we return False.
11220 end Is_Predicate_Static
;
11222 ---------------------
11223 -- Kill_Rep_Clause --
11224 ---------------------
11226 procedure Kill_Rep_Clause
(N
: Node_Id
) is
11228 pragma Assert
(Ignore_Rep_Clauses
);
11230 -- Note: we use Replace rather than Rewrite, because we don't want
11231 -- ASIS to be able to use Original_Node to dig out the (undecorated)
11232 -- rep clause that is being replaced.
11234 Replace
(N
, Make_Null_Statement
(Sloc
(N
)));
11236 -- The null statement must be marked as not coming from source. This is
11237 -- so that ASIS ignores it, and also the back end does not expect bogus
11238 -- "from source" null statements in weird places (e.g. in declarative
11239 -- regions where such null statements are not allowed).
11241 Set_Comes_From_Source
(N
, False);
11242 end Kill_Rep_Clause
;
11248 function Minimum_Size
11250 Biased
: Boolean := False) return Nat
11252 Lo
: Uint
:= No_Uint
;
11253 Hi
: Uint
:= No_Uint
;
11254 LoR
: Ureal
:= No_Ureal
;
11255 HiR
: Ureal
:= No_Ureal
;
11256 LoSet
: Boolean := False;
11257 HiSet
: Boolean := False;
11260 Ancest
: Entity_Id
;
11261 R_Typ
: constant Entity_Id
:= Root_Type
(T
);
11264 -- If bad type, return 0
11266 if T
= Any_Type
then
11269 -- For generic types, just return zero. There cannot be any legitimate
11270 -- need to know such a size, but this routine may be called with a
11271 -- generic type as part of normal processing.
11273 elsif Is_Generic_Type
(R_Typ
) or else R_Typ
= Any_Type
then
11276 -- Access types (cannot have size smaller than System.Address)
11278 elsif Is_Access_Type
(T
) then
11279 return System_Address_Size
;
11281 -- Floating-point types
11283 elsif Is_Floating_Point_Type
(T
) then
11284 return UI_To_Int
(Esize
(R_Typ
));
11288 elsif Is_Discrete_Type
(T
) then
11290 -- The following loop is looking for the nearest compile time known
11291 -- bounds following the ancestor subtype chain. The idea is to find
11292 -- the most restrictive known bounds information.
11296 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
11301 if Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
)) then
11302 Lo
:= Expr_Rep_Value
(Type_Low_Bound
(Ancest
));
11309 if Compile_Time_Known_Value
(Type_High_Bound
(Ancest
)) then
11310 Hi
:= Expr_Rep_Value
(Type_High_Bound
(Ancest
));
11316 Ancest
:= Ancestor_Subtype
(Ancest
);
11318 if No
(Ancest
) then
11319 Ancest
:= Base_Type
(T
);
11321 if Is_Generic_Type
(Ancest
) then
11327 -- Fixed-point types. We can't simply use Expr_Value to get the
11328 -- Corresponding_Integer_Value values of the bounds, since these do not
11329 -- get set till the type is frozen, and this routine can be called
11330 -- before the type is frozen. Similarly the test for bounds being static
11331 -- needs to include the case where we have unanalyzed real literals for
11332 -- the same reason.
11334 elsif Is_Fixed_Point_Type
(T
) then
11336 -- The following loop is looking for the nearest compile time known
11337 -- bounds following the ancestor subtype chain. The idea is to find
11338 -- the most restrictive known bounds information.
11342 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
11346 -- Note: In the following two tests for LoSet and HiSet, it may
11347 -- seem redundant to test for N_Real_Literal here since normally
11348 -- one would assume that the test for the value being known at
11349 -- compile time includes this case. However, there is a glitch.
11350 -- If the real literal comes from folding a non-static expression,
11351 -- then we don't consider any non- static expression to be known
11352 -- at compile time if we are in configurable run time mode (needed
11353 -- in some cases to give a clearer definition of what is and what
11354 -- is not accepted). So the test is indeed needed. Without it, we
11355 -- would set neither Lo_Set nor Hi_Set and get an infinite loop.
11358 if Nkind
(Type_Low_Bound
(Ancest
)) = N_Real_Literal
11359 or else Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
))
11361 LoR
:= Expr_Value_R
(Type_Low_Bound
(Ancest
));
11368 if Nkind
(Type_High_Bound
(Ancest
)) = N_Real_Literal
11369 or else Compile_Time_Known_Value
(Type_High_Bound
(Ancest
))
11371 HiR
:= Expr_Value_R
(Type_High_Bound
(Ancest
));
11377 Ancest
:= Ancestor_Subtype
(Ancest
);
11379 if No
(Ancest
) then
11380 Ancest
:= Base_Type
(T
);
11382 if Is_Generic_Type
(Ancest
) then
11388 Lo
:= UR_To_Uint
(LoR
/ Small_Value
(T
));
11389 Hi
:= UR_To_Uint
(HiR
/ Small_Value
(T
));
11391 -- No other types allowed
11394 raise Program_Error
;
11397 -- Fall through with Hi and Lo set. Deal with biased case
11400 and then not Is_Fixed_Point_Type
(T
)
11401 and then not (Is_Enumeration_Type
(T
)
11402 and then Has_Non_Standard_Rep
(T
)))
11403 or else Has_Biased_Representation
(T
)
11409 -- Signed case. Note that we consider types like range 1 .. -1 to be
11410 -- signed for the purpose of computing the size, since the bounds have
11411 -- to be accommodated in the base type.
11413 if Lo
< 0 or else Hi
< 0 then
11417 -- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1))
11418 -- Note that we accommodate the case where the bounds cross. This
11419 -- can happen either because of the way the bounds are declared
11420 -- or because of the algorithm in Freeze_Fixed_Point_Type.
11434 -- If both bounds are positive, make sure that both are represen-
11435 -- table in the case where the bounds are crossed. This can happen
11436 -- either because of the way the bounds are declared, or because of
11437 -- the algorithm in Freeze_Fixed_Point_Type.
11443 -- S = size, (can accommodate 0 .. (2**size - 1))
11446 while Hi
>= Uint_2
** S
loop
11454 ---------------------------
11455 -- New_Stream_Subprogram --
11456 ---------------------------
11458 procedure New_Stream_Subprogram
11462 Nam
: TSS_Name_Type
)
11464 Loc
: constant Source_Ptr
:= Sloc
(N
);
11465 Sname
: constant Name_Id
:= Make_TSS_Name
(Base_Type
(Ent
), Nam
);
11466 Subp_Id
: Entity_Id
;
11467 Subp_Decl
: Node_Id
;
11471 Defer_Declaration
: constant Boolean :=
11472 Is_Tagged_Type
(Ent
) or else Is_Private_Type
(Ent
);
11473 -- For a tagged type, there is a declaration for each stream attribute
11474 -- at the freeze point, and we must generate only a completion of this
11475 -- declaration. We do the same for private types, because the full view
11476 -- might be tagged. Otherwise we generate a declaration at the point of
11477 -- the attribute definition clause.
11479 function Build_Spec
return Node_Id
;
11480 -- Used for declaration and renaming declaration, so that this is
11481 -- treated as a renaming_as_body.
11487 function Build_Spec
return Node_Id
is
11488 Out_P
: constant Boolean := (Nam
= TSS_Stream_Read
);
11491 T_Ref
: constant Node_Id
:= New_Occurrence_Of
(Etyp
, Loc
);
11494 Subp_Id
:= Make_Defining_Identifier
(Loc
, Sname
);
11496 -- S : access Root_Stream_Type'Class
11498 Formals
:= New_List
(
11499 Make_Parameter_Specification
(Loc
,
11500 Defining_Identifier
=>
11501 Make_Defining_Identifier
(Loc
, Name_S
),
11503 Make_Access_Definition
(Loc
,
11505 New_Occurrence_Of
(
11506 Designated_Type
(Etype
(F
)), Loc
))));
11508 if Nam
= TSS_Stream_Input
then
11510 Make_Function_Specification
(Loc
,
11511 Defining_Unit_Name
=> Subp_Id
,
11512 Parameter_Specifications
=> Formals
,
11513 Result_Definition
=> T_Ref
);
11517 Append_To
(Formals
,
11518 Make_Parameter_Specification
(Loc
,
11519 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_V
),
11520 Out_Present
=> Out_P
,
11521 Parameter_Type
=> T_Ref
));
11524 Make_Procedure_Specification
(Loc
,
11525 Defining_Unit_Name
=> Subp_Id
,
11526 Parameter_Specifications
=> Formals
);
11532 -- Start of processing for New_Stream_Subprogram
11535 F
:= First_Formal
(Subp
);
11537 if Ekind
(Subp
) = E_Procedure
then
11538 Etyp
:= Etype
(Next_Formal
(F
));
11540 Etyp
:= Etype
(Subp
);
11543 -- Prepare subprogram declaration and insert it as an action on the
11544 -- clause node. The visibility for this entity is used to test for
11545 -- visibility of the attribute definition clause (in the sense of
11546 -- 8.3(23) as amended by AI-195).
11548 if not Defer_Declaration
then
11550 Make_Subprogram_Declaration
(Loc
,
11551 Specification
=> Build_Spec
);
11553 -- For a tagged type, there is always a visible declaration for each
11554 -- stream TSS (it is a predefined primitive operation), and the
11555 -- completion of this declaration occurs at the freeze point, which is
11556 -- not always visible at places where the attribute definition clause is
11557 -- visible. So, we create a dummy entity here for the purpose of
11558 -- tracking the visibility of the attribute definition clause itself.
11562 Make_Defining_Identifier
(Loc
, New_External_Name
(Sname
, 'V'));
11564 Make_Object_Declaration
(Loc
,
11565 Defining_Identifier
=> Subp_Id
,
11566 Object_Definition
=> New_Occurrence_Of
(Standard_Boolean
, Loc
));
11569 Insert_Action
(N
, Subp_Decl
);
11570 Set_Entity
(N
, Subp_Id
);
11573 Make_Subprogram_Renaming_Declaration
(Loc
,
11574 Specification
=> Build_Spec
,
11575 Name
=> New_Occurrence_Of
(Subp
, Loc
));
11577 if Defer_Declaration
then
11578 Set_TSS
(Base_Type
(Ent
), Subp_Id
);
11580 Insert_Action
(N
, Subp_Decl
);
11581 Copy_TSS
(Subp_Id
, Base_Type
(Ent
));
11583 end New_Stream_Subprogram
;
11585 ------------------------------------------
11586 -- Push_Scope_And_Install_Discriminants --
11587 ------------------------------------------
11589 procedure Push_Scope_And_Install_Discriminants
(E
: Entity_Id
) is
11591 if Has_Discriminants
(E
) then
11594 -- Make discriminants visible for type declarations and protected
11595 -- type declarations, not for subtype declarations (RM 13.1.1 (12/3))
11597 if Nkind
(Parent
(E
)) /= N_Subtype_Declaration
then
11598 Install_Discriminants
(E
);
11601 end Push_Scope_And_Install_Discriminants
;
11603 ------------------------
11604 -- Rep_Item_Too_Early --
11605 ------------------------
11607 function Rep_Item_Too_Early
(T
: Entity_Id
; N
: Node_Id
) return Boolean is
11609 -- Cannot apply non-operational rep items to generic types
11611 if Is_Operational_Item
(N
) then
11615 and then Is_Generic_Type
(Root_Type
(T
))
11617 Error_Msg_N
("representation item not allowed for generic type", N
);
11621 -- Otherwise check for incomplete type
11623 if Is_Incomplete_Or_Private_Type
(T
)
11624 and then No
(Underlying_Type
(T
))
11626 (Nkind
(N
) /= N_Pragma
11627 or else Get_Pragma_Id
(N
) /= Pragma_Import
)
11630 ("representation item must be after full type declaration", N
);
11633 -- If the type has incomplete components, a representation clause is
11634 -- illegal but stream attributes and Convention pragmas are correct.
11636 elsif Has_Private_Component
(T
) then
11637 if Nkind
(N
) = N_Pragma
then
11642 ("representation item must appear after type is fully defined",
11649 end Rep_Item_Too_Early
;
11651 -----------------------
11652 -- Rep_Item_Too_Late --
11653 -----------------------
11655 function Rep_Item_Too_Late
11658 FOnly
: Boolean := False) return Boolean
11661 Parent_Type
: Entity_Id
;
11663 procedure No_Type_Rep_Item
;
11664 -- Output message indicating that no type-related aspects can be
11665 -- specified due to some property of the parent type.
11667 procedure Too_Late
;
11668 -- Output message for an aspect being specified too late
11670 -- Note that neither of the above errors is considered a serious one,
11671 -- since the effect is simply that we ignore the representation clause
11673 -- Is this really true? In any case if we make this change we must
11674 -- document the requirement in the spec of Rep_Item_Too_Late that
11675 -- if True is returned, then the rep item must be completely ignored???
11677 ----------------------
11678 -- No_Type_Rep_Item --
11679 ----------------------
11681 procedure No_Type_Rep_Item
is
11683 Error_Msg_N
("|type-related representation item not permitted!", N
);
11684 end No_Type_Rep_Item
;
11690 procedure Too_Late
is
11692 -- Other compilers seem more relaxed about rep items appearing too
11693 -- late. Since analysis tools typically don't care about rep items
11694 -- anyway, no reason to be too strict about this.
11696 if not Relaxed_RM_Semantics
then
11697 Error_Msg_N
("|representation item appears too late!", N
);
11701 -- Start of processing for Rep_Item_Too_Late
11704 -- First make sure entity is not frozen (RM 13.1(9))
11708 -- Exclude imported types, which may be frozen if they appear in a
11709 -- representation clause for a local type.
11711 and then not From_Limited_With
(T
)
11713 -- Exclude generated entities (not coming from source). The common
11714 -- case is when we generate a renaming which prematurely freezes the
11715 -- renamed internal entity, but we still want to be able to set copies
11716 -- of attribute values such as Size/Alignment.
11718 and then Comes_From_Source
(T
)
11721 S
:= First_Subtype
(T
);
11723 if Present
(Freeze_Node
(S
)) then
11724 if not Relaxed_RM_Semantics
then
11726 ("??no more representation items for }", Freeze_Node
(S
), S
);
11732 -- Check for case of untagged derived type whose parent either has
11733 -- primitive operations, or is a by reference type (RM 13.1(10)). In
11734 -- this case we do not output a Too_Late message, since there is no
11735 -- earlier point where the rep item could be placed to make it legal.
11739 and then Is_Derived_Type
(T
)
11740 and then not Is_Tagged_Type
(T
)
11742 Parent_Type
:= Etype
(Base_Type
(T
));
11744 if Has_Primitive_Operations
(Parent_Type
) then
11747 if not Relaxed_RM_Semantics
then
11749 ("\parent type & has primitive operations!", N
, Parent_Type
);
11754 elsif Is_By_Reference_Type
(Parent_Type
) then
11757 if not Relaxed_RM_Semantics
then
11759 ("\parent type & is a by reference type!", N
, Parent_Type
);
11766 -- No error, but one more warning to consider. The RM (surprisingly)
11767 -- allows this pattern:
11770 -- primitive operations for S
11771 -- type R is new S;
11772 -- rep clause for S
11774 -- Meaning that calls on the primitive operations of S for values of
11775 -- type R may require possibly expensive implicit conversion operations.
11776 -- This is not an error, but is worth a warning.
11778 if not Relaxed_RM_Semantics
and then Is_Type
(T
) then
11780 DTL
: constant Entity_Id
:= Derived_Type_Link
(Base_Type
(T
));
11784 and then Has_Primitive_Operations
(Base_Type
(T
))
11786 -- For now, do not generate this warning for the case of aspect
11787 -- specification using Ada 2012 syntax, since we get wrong
11788 -- messages we do not understand. The whole business of derived
11789 -- types and rep items seems a bit confused when aspects are
11790 -- used, since the aspects are not evaluated till freeze time.
11792 and then not From_Aspect_Specification
(N
)
11794 Error_Msg_Sloc
:= Sloc
(DTL
);
11796 ("representation item for& appears after derived type "
11797 & "declaration#??", N
);
11799 ("\may result in implicit conversions for primitive "
11800 & "operations of&??", N
, T
);
11802 ("\to change representations when called with arguments "
11803 & "of type&??", N
, DTL
);
11808 -- No error, link item into head of chain of rep items for the entity,
11809 -- but avoid chaining if we have an overloadable entity, and the pragma
11810 -- is one that can apply to multiple overloaded entities.
11812 if Is_Overloadable
(T
) and then Nkind
(N
) = N_Pragma
then
11814 Pname
: constant Name_Id
:= Pragma_Name
(N
);
11816 if Nam_In
(Pname
, Name_Convention
, Name_Import
, Name_Export
,
11817 Name_External
, Name_Interface
)
11824 Record_Rep_Item
(T
, N
);
11826 end Rep_Item_Too_Late
;
11828 -------------------------------------
11829 -- Replace_Type_References_Generic --
11830 -------------------------------------
11832 procedure Replace_Type_References_Generic
(N
: Node_Id
; T
: Entity_Id
) is
11833 TName
: constant Name_Id
:= Chars
(T
);
11835 function Replace_Node
(N
: Node_Id
) return Traverse_Result
;
11836 -- Processes a single node in the traversal procedure below, checking
11837 -- if node N should be replaced, and if so, doing the replacement.
11839 procedure Replace_Type_Refs
is new Traverse_Proc
(Replace_Node
);
11840 -- This instantiation provides the body of Replace_Type_References
11846 function Replace_Node
(N
: Node_Id
) return Traverse_Result
is
11851 -- Case of identifier
11853 if Nkind
(N
) = N_Identifier
then
11855 -- If not the type name, check whether it is a reference to
11856 -- some other type, which must be frozen before the predicate
11857 -- function is analyzed, i.e. before the freeze node of the
11858 -- type to which the predicate applies.
11860 if Chars
(N
) /= TName
then
11861 if Present
(Current_Entity
(N
))
11862 and then Is_Type
(Current_Entity
(N
))
11864 Freeze_Before
(Freeze_Node
(T
), Current_Entity
(N
));
11869 -- Otherwise do the replacement and we are done with this node
11872 Replace_Type_Reference
(N
);
11876 -- Case of selected component (which is what a qualification
11877 -- looks like in the unanalyzed tree, which is what we have.
11879 elsif Nkind
(N
) = N_Selected_Component
then
11881 -- If selector name is not our type, keeping going (we might
11882 -- still have an occurrence of the type in the prefix).
11884 if Nkind
(Selector_Name
(N
)) /= N_Identifier
11885 or else Chars
(Selector_Name
(N
)) /= TName
11889 -- Selector name is our type, check qualification
11892 -- Loop through scopes and prefixes, doing comparison
11894 S
:= Current_Scope
;
11897 -- Continue if no more scopes or scope with no name
11899 if No
(S
) or else Nkind
(S
) not in N_Has_Chars
then
11903 -- Do replace if prefix is an identifier matching the
11904 -- scope that we are currently looking at.
11906 if Nkind
(P
) = N_Identifier
11907 and then Chars
(P
) = Chars
(S
)
11909 Replace_Type_Reference
(N
);
11913 -- Go check scope above us if prefix is itself of the
11914 -- form of a selected component, whose selector matches
11915 -- the scope we are currently looking at.
11917 if Nkind
(P
) = N_Selected_Component
11918 and then Nkind
(Selector_Name
(P
)) = N_Identifier
11919 and then Chars
(Selector_Name
(P
)) = Chars
(S
)
11924 -- For anything else, we don't have a match, so keep on
11925 -- going, there are still some weird cases where we may
11926 -- still have a replacement within the prefix.
11934 -- Continue for any other node kind
11942 Replace_Type_Refs
(N
);
11943 end Replace_Type_References_Generic
;
11945 -------------------------
11946 -- Same_Representation --
11947 -------------------------
11949 function Same_Representation
(Typ1
, Typ2
: Entity_Id
) return Boolean is
11950 T1
: constant Entity_Id
:= Underlying_Type
(Typ1
);
11951 T2
: constant Entity_Id
:= Underlying_Type
(Typ2
);
11954 -- A quick check, if base types are the same, then we definitely have
11955 -- the same representation, because the subtype specific representation
11956 -- attributes (Size and Alignment) do not affect representation from
11957 -- the point of view of this test.
11959 if Base_Type
(T1
) = Base_Type
(T2
) then
11962 elsif Is_Private_Type
(Base_Type
(T2
))
11963 and then Base_Type
(T1
) = Full_View
(Base_Type
(T2
))
11968 -- Tagged types never have differing representations
11970 if Is_Tagged_Type
(T1
) then
11974 -- Representations are definitely different if conventions differ
11976 if Convention
(T1
) /= Convention
(T2
) then
11980 -- Representations are different if component alignments or scalar
11981 -- storage orders differ.
11983 if (Is_Record_Type
(T1
) or else Is_Array_Type
(T1
))
11985 (Is_Record_Type
(T2
) or else Is_Array_Type
(T2
))
11987 (Component_Alignment
(T1
) /= Component_Alignment
(T2
)
11988 or else Reverse_Storage_Order
(T1
) /= Reverse_Storage_Order
(T2
))
11993 -- For arrays, the only real issue is component size. If we know the
11994 -- component size for both arrays, and it is the same, then that's
11995 -- good enough to know we don't have a change of representation.
11997 if Is_Array_Type
(T1
) then
11998 if Known_Component_Size
(T1
)
11999 and then Known_Component_Size
(T2
)
12000 and then Component_Size
(T1
) = Component_Size
(T2
)
12002 if VM_Target
= No_VM
then
12005 -- In VM targets the representation of arrays with aliased
12006 -- components differs from arrays with non-aliased components
12009 return Has_Aliased_Components
(Base_Type
(T1
))
12011 Has_Aliased_Components
(Base_Type
(T2
));
12016 -- Types definitely have same representation if neither has non-standard
12017 -- representation since default representations are always consistent.
12018 -- If only one has non-standard representation, and the other does not,
12019 -- then we consider that they do not have the same representation. They
12020 -- might, but there is no way of telling early enough.
12022 if Has_Non_Standard_Rep
(T1
) then
12023 if not Has_Non_Standard_Rep
(T2
) then
12027 return not Has_Non_Standard_Rep
(T2
);
12030 -- Here the two types both have non-standard representation, and we need
12031 -- to determine if they have the same non-standard representation.
12033 -- For arrays, we simply need to test if the component sizes are the
12034 -- same. Pragma Pack is reflected in modified component sizes, so this
12035 -- check also deals with pragma Pack.
12037 if Is_Array_Type
(T1
) then
12038 return Component_Size
(T1
) = Component_Size
(T2
);
12040 -- Tagged types always have the same representation, because it is not
12041 -- possible to specify different representations for common fields.
12043 elsif Is_Tagged_Type
(T1
) then
12046 -- Case of record types
12048 elsif Is_Record_Type
(T1
) then
12050 -- Packed status must conform
12052 if Is_Packed
(T1
) /= Is_Packed
(T2
) then
12055 -- Otherwise we must check components. Typ2 maybe a constrained
12056 -- subtype with fewer components, so we compare the components
12057 -- of the base types.
12060 Record_Case
: declare
12061 CD1
, CD2
: Entity_Id
;
12063 function Same_Rep
return Boolean;
12064 -- CD1 and CD2 are either components or discriminants. This
12065 -- function tests whether they have the same representation.
12071 function Same_Rep
return Boolean is
12073 if No
(Component_Clause
(CD1
)) then
12074 return No
(Component_Clause
(CD2
));
12076 -- Note: at this point, component clauses have been
12077 -- normalized to the default bit order, so that the
12078 -- comparison of Component_Bit_Offsets is meaningful.
12081 Present
(Component_Clause
(CD2
))
12083 Component_Bit_Offset
(CD1
) = Component_Bit_Offset
(CD2
)
12085 Esize
(CD1
) = Esize
(CD2
);
12089 -- Start of processing for Record_Case
12092 if Has_Discriminants
(T1
) then
12094 -- The number of discriminants may be different if the
12095 -- derived type has fewer (constrained by values). The
12096 -- invisible discriminants retain the representation of
12097 -- the original, so the discrepancy does not per se
12098 -- indicate a different representation.
12100 CD1
:= First_Discriminant
(T1
);
12101 CD2
:= First_Discriminant
(T2
);
12102 while Present
(CD1
) and then Present
(CD2
) loop
12103 if not Same_Rep
then
12106 Next_Discriminant
(CD1
);
12107 Next_Discriminant
(CD2
);
12112 CD1
:= First_Component
(Underlying_Type
(Base_Type
(T1
)));
12113 CD2
:= First_Component
(Underlying_Type
(Base_Type
(T2
)));
12114 while Present
(CD1
) loop
12115 if not Same_Rep
then
12118 Next_Component
(CD1
);
12119 Next_Component
(CD2
);
12127 -- For enumeration types, we must check each literal to see if the
12128 -- representation is the same. Note that we do not permit enumeration
12129 -- representation clauses for Character and Wide_Character, so these
12130 -- cases were already dealt with.
12132 elsif Is_Enumeration_Type
(T1
) then
12133 Enumeration_Case
: declare
12134 L1
, L2
: Entity_Id
;
12137 L1
:= First_Literal
(T1
);
12138 L2
:= First_Literal
(T2
);
12139 while Present
(L1
) loop
12140 if Enumeration_Rep
(L1
) /= Enumeration_Rep
(L2
) then
12149 end Enumeration_Case
;
12151 -- Any other types have the same representation for these purposes
12156 end Same_Representation
;
12158 --------------------------------
12159 -- Resolve_Iterable_Operation --
12160 --------------------------------
12162 procedure Resolve_Iterable_Operation
12164 Cursor
: Entity_Id
;
12173 if not Is_Overloaded
(N
) then
12174 if not Is_Entity_Name
(N
)
12175 or else Ekind
(Entity
(N
)) /= E_Function
12176 or else Scope
(Entity
(N
)) /= Scope
(Typ
)
12177 or else No
(First_Formal
(Entity
(N
)))
12178 or else Etype
(First_Formal
(Entity
(N
))) /= Typ
12180 Error_Msg_N
("iterable primitive must be local function name "
12181 & "whose first formal is an iterable type", N
);
12186 F1
:= First_Formal
(Ent
);
12187 if Nam
= Name_First
then
12189 -- First (Container) => Cursor
12191 if Etype
(Ent
) /= Cursor
then
12192 Error_Msg_N
("primitive for First must yield a curosr", N
);
12195 elsif Nam
= Name_Next
then
12197 -- Next (Container, Cursor) => Cursor
12199 F2
:= Next_Formal
(F1
);
12201 if Etype
(F2
) /= Cursor
12202 or else Etype
(Ent
) /= Cursor
12203 or else Present
(Next_Formal
(F2
))
12205 Error_Msg_N
("no match for Next iterable primitive", N
);
12208 elsif Nam
= Name_Has_Element
then
12210 -- Has_Element (Container, Cursor) => Boolean
12212 F2
:= Next_Formal
(F1
);
12213 if Etype
(F2
) /= Cursor
12214 or else Etype
(Ent
) /= Standard_Boolean
12215 or else Present
(Next_Formal
(F2
))
12217 Error_Msg_N
("no match for Has_Element iterable primitive", N
);
12220 elsif Nam
= Name_Element
then
12221 F2
:= Next_Formal
(F1
);
12224 or else Etype
(F2
) /= Cursor
12225 or else Present
(Next_Formal
(F2
))
12227 Error_Msg_N
("no match for Element iterable primitive", N
);
12232 raise Program_Error
;
12236 -- Overloaded case: find subprogram with proper signature.
12237 -- Caller will report error if no match is found.
12244 Get_First_Interp
(N
, I
, It
);
12245 while Present
(It
.Typ
) loop
12246 if Ekind
(It
.Nam
) = E_Function
12247 and then Scope
(It
.Nam
) = Scope
(Typ
)
12248 and then Etype
(First_Formal
(It
.Nam
)) = Typ
12250 F1
:= First_Formal
(It
.Nam
);
12252 if Nam
= Name_First
then
12253 if Etype
(It
.Nam
) = Cursor
12254 and then No
(Next_Formal
(F1
))
12256 Set_Entity
(N
, It
.Nam
);
12260 elsif Nam
= Name_Next
then
12261 F2
:= Next_Formal
(F1
);
12264 and then No
(Next_Formal
(F2
))
12265 and then Etype
(F2
) = Cursor
12266 and then Etype
(It
.Nam
) = Cursor
12268 Set_Entity
(N
, It
.Nam
);
12272 elsif Nam
= Name_Has_Element
then
12273 F2
:= Next_Formal
(F1
);
12276 and then No
(Next_Formal
(F2
))
12277 and then Etype
(F2
) = Cursor
12278 and then Etype
(It
.Nam
) = Standard_Boolean
12280 Set_Entity
(N
, It
.Nam
);
12281 F2
:= Next_Formal
(F1
);
12285 elsif Nam
= Name_Element
then
12286 F2
:= Next_Formal
(F1
);
12289 and then No
(Next_Formal
(F2
))
12290 and then Etype
(F2
) = Cursor
12292 Set_Entity
(N
, It
.Nam
);
12298 Get_Next_Interp
(I
, It
);
12302 end Resolve_Iterable_Operation
;
12308 procedure Set_Biased
12312 Biased
: Boolean := True)
12316 Set_Has_Biased_Representation
(E
);
12318 if Warn_On_Biased_Representation
then
12320 ("?B?" & Msg
& " forces biased representation for&", N
, E
);
12325 --------------------
12326 -- Set_Enum_Esize --
12327 --------------------
12329 procedure Set_Enum_Esize
(T
: Entity_Id
) is
12335 Init_Alignment
(T
);
12337 -- Find the minimum standard size (8,16,32,64) that fits
12339 Lo
:= Enumeration_Rep
(Entity
(Type_Low_Bound
(T
)));
12340 Hi
:= Enumeration_Rep
(Entity
(Type_High_Bound
(T
)));
12343 if Lo
>= -Uint_2
**07 and then Hi
< Uint_2
**07 then
12344 Sz
:= Standard_Character_Size
; -- May be > 8 on some targets
12346 elsif Lo
>= -Uint_2
**15 and then Hi
< Uint_2
**15 then
12349 elsif Lo
>= -Uint_2
**31 and then Hi
< Uint_2
**31 then
12352 else pragma Assert
(Lo
>= -Uint_2
**63 and then Hi
< Uint_2
**63);
12357 if Hi
< Uint_2
**08 then
12358 Sz
:= Standard_Character_Size
; -- May be > 8 on some targets
12360 elsif Hi
< Uint_2
**16 then
12363 elsif Hi
< Uint_2
**32 then
12366 else pragma Assert
(Hi
< Uint_2
**63);
12371 -- That minimum is the proper size unless we have a foreign convention
12372 -- and the size required is 32 or less, in which case we bump the size
12373 -- up to 32. This is required for C and C++ and seems reasonable for
12374 -- all other foreign conventions.
12376 if Has_Foreign_Convention
(T
)
12377 and then Esize
(T
) < Standard_Integer_Size
12379 -- Don't do this if Short_Enums on target
12381 and then not Target_Short_Enums
12383 Init_Esize
(T
, Standard_Integer_Size
);
12385 Init_Esize
(T
, Sz
);
12387 end Set_Enum_Esize
;
12389 -----------------------------
12390 -- Uninstall_Discriminants --
12391 -----------------------------
12393 procedure Uninstall_Discriminants
(E
: Entity_Id
) is
12399 -- Discriminants have been made visible for type declarations and
12400 -- protected type declarations, not for subtype declarations.
12402 if Nkind
(Parent
(E
)) /= N_Subtype_Declaration
then
12403 Disc
:= First_Discriminant
(E
);
12404 while Present
(Disc
) loop
12405 if Disc
/= Current_Entity
(Disc
) then
12406 Prev
:= Current_Entity
(Disc
);
12407 while Present
(Prev
)
12408 and then Present
(Homonym
(Prev
))
12409 and then Homonym
(Prev
) /= Disc
12411 Prev
:= Homonym
(Prev
);
12417 Set_Is_Immediately_Visible
(Disc
, False);
12419 Outer
:= Homonym
(Disc
);
12420 while Present
(Outer
) and then Scope
(Outer
) = E
loop
12421 Outer
:= Homonym
(Outer
);
12424 -- Reset homonym link of other entities, but do not modify link
12425 -- between entities in current scope, so that the back-end can
12426 -- have a proper count of local overloadings.
12429 Set_Name_Entity_Id
(Chars
(Disc
), Outer
);
12431 elsif Scope
(Prev
) /= Scope
(Disc
) then
12432 Set_Homonym
(Prev
, Outer
);
12435 Next_Discriminant
(Disc
);
12438 end Uninstall_Discriminants
;
12440 -------------------------------------------
12441 -- Uninstall_Discriminants_And_Pop_Scope --
12442 -------------------------------------------
12444 procedure Uninstall_Discriminants_And_Pop_Scope
(E
: Entity_Id
) is
12446 if Has_Discriminants
(E
) then
12447 Uninstall_Discriminants
(E
);
12450 end Uninstall_Discriminants_And_Pop_Scope
;
12452 ------------------------------
12453 -- Validate_Address_Clauses --
12454 ------------------------------
12456 procedure Validate_Address_Clauses
is
12458 for J
in Address_Clause_Checks
.First
.. Address_Clause_Checks
.Last
loop
12460 ACCR
: Address_Clause_Check_Record
12461 renames Address_Clause_Checks
.Table
(J
);
12465 X_Alignment
: Uint
;
12466 Y_Alignment
: Uint
;
12472 -- Skip processing of this entry if warning already posted
12474 if not Address_Warning_Posted
(ACCR
.N
) then
12475 Expr
:= Original_Node
(Expression
(ACCR
.N
));
12479 X_Alignment
:= Alignment
(ACCR
.X
);
12480 Y_Alignment
:= Alignment
(ACCR
.Y
);
12482 -- Similarly obtain sizes
12484 X_Size
:= Esize
(ACCR
.X
);
12485 Y_Size
:= Esize
(ACCR
.Y
);
12487 -- Check for large object overlaying smaller one
12490 and then X_Size
> Uint_0
12491 and then X_Size
> Y_Size
12494 ("??& overlays smaller object", ACCR
.N
, ACCR
.X
);
12496 ("\??program execution may be erroneous", ACCR
.N
);
12497 Error_Msg_Uint_1
:= X_Size
;
12499 ("\??size of & is ^", ACCR
.N
, ACCR
.X
);
12500 Error_Msg_Uint_1
:= Y_Size
;
12502 ("\??size of & is ^", ACCR
.N
, ACCR
.Y
);
12504 -- Check for inadequate alignment, both of the base object
12505 -- and of the offset, if any.
12507 -- Note: we do not check the alignment if we gave a size
12508 -- warning, since it would likely be redundant.
12510 elsif Y_Alignment
/= Uint_0
12511 and then (Y_Alignment
< X_Alignment
12514 Nkind
(Expr
) = N_Attribute_Reference
12516 Attribute_Name
(Expr
) = Name_Address
12518 Has_Compatible_Alignment
12519 (ACCR
.X
, Prefix
(Expr
))
12520 /= Known_Compatible
))
12523 ("??specified address for& may be inconsistent "
12524 & "with alignment", ACCR
.N
, ACCR
.X
);
12526 ("\??program execution may be erroneous (RM 13.3(27))",
12528 Error_Msg_Uint_1
:= X_Alignment
;
12530 ("\??alignment of & is ^", ACCR
.N
, ACCR
.X
);
12531 Error_Msg_Uint_1
:= Y_Alignment
;
12533 ("\??alignment of & is ^", ACCR
.N
, ACCR
.Y
);
12534 if Y_Alignment
>= X_Alignment
then
12536 ("\??but offset is not multiple of alignment", ACCR
.N
);
12542 end Validate_Address_Clauses
;
12544 ---------------------------
12545 -- Validate_Independence --
12546 ---------------------------
12548 procedure Validate_Independence
is
12549 SU
: constant Uint
:= UI_From_Int
(System_Storage_Unit
);
12557 procedure Check_Array_Type
(Atyp
: Entity_Id
);
12558 -- Checks if the array type Atyp has independent components, and
12559 -- if not, outputs an appropriate set of error messages.
12561 procedure No_Independence
;
12562 -- Output message that independence cannot be guaranteed
12564 function OK_Component
(C
: Entity_Id
) return Boolean;
12565 -- Checks one component to see if it is independently accessible, and
12566 -- if so yields True, otherwise yields False if independent access
12567 -- cannot be guaranteed. This is a conservative routine, it only
12568 -- returns True if it knows for sure, it returns False if it knows
12569 -- there is a problem, or it cannot be sure there is no problem.
12571 procedure Reason_Bad_Component
(C
: Entity_Id
);
12572 -- Outputs continuation message if a reason can be determined for
12573 -- the component C being bad.
12575 ----------------------
12576 -- Check_Array_Type --
12577 ----------------------
12579 procedure Check_Array_Type
(Atyp
: Entity_Id
) is
12580 Ctyp
: constant Entity_Id
:= Component_Type
(Atyp
);
12583 -- OK if no alignment clause, no pack, and no component size
12585 if not Has_Component_Size_Clause
(Atyp
)
12586 and then not Has_Alignment_Clause
(Atyp
)
12587 and then not Is_Packed
(Atyp
)
12592 -- Case of component size is greater than or equal to 64 and the
12593 -- alignment of the array is at least as large as the alignment
12594 -- of the component. We are definitely OK in this situation.
12596 if Known_Component_Size
(Atyp
)
12597 and then Component_Size
(Atyp
) >= 64
12598 and then Known_Alignment
(Atyp
)
12599 and then Known_Alignment
(Ctyp
)
12600 and then Alignment
(Atyp
) >= Alignment
(Ctyp
)
12605 -- Check actual component size
12607 if not Known_Component_Size
(Atyp
)
12608 or else not (Addressable
(Component_Size
(Atyp
))
12609 and then Component_Size
(Atyp
) < 64)
12610 or else Component_Size
(Atyp
) mod Esize
(Ctyp
) /= 0
12614 -- Bad component size, check reason
12616 if Has_Component_Size_Clause
(Atyp
) then
12617 P
:= Get_Attribute_Definition_Clause
12618 (Atyp
, Attribute_Component_Size
);
12620 if Present
(P
) then
12621 Error_Msg_Sloc
:= Sloc
(P
);
12622 Error_Msg_N
("\because of Component_Size clause#", N
);
12627 if Is_Packed
(Atyp
) then
12628 P
:= Get_Rep_Pragma
(Atyp
, Name_Pack
);
12630 if Present
(P
) then
12631 Error_Msg_Sloc
:= Sloc
(P
);
12632 Error_Msg_N
("\because of pragma Pack#", N
);
12637 -- No reason found, just return
12642 -- Array type is OK independence-wise
12645 end Check_Array_Type
;
12647 ---------------------
12648 -- No_Independence --
12649 ---------------------
12651 procedure No_Independence
is
12653 if Pragma_Name
(N
) = Name_Independent
then
12654 Error_Msg_NE
("independence cannot be guaranteed for&", N
, E
);
12657 ("independent components cannot be guaranteed for&", N
, E
);
12659 end No_Independence
;
12665 function OK_Component
(C
: Entity_Id
) return Boolean is
12666 Rec
: constant Entity_Id
:= Scope
(C
);
12667 Ctyp
: constant Entity_Id
:= Etype
(C
);
12670 -- OK if no component clause, no Pack, and no alignment clause
12672 if No
(Component_Clause
(C
))
12673 and then not Is_Packed
(Rec
)
12674 and then not Has_Alignment_Clause
(Rec
)
12679 -- Here we look at the actual component layout. A component is
12680 -- addressable if its size is a multiple of the Esize of the
12681 -- component type, and its starting position in the record has
12682 -- appropriate alignment, and the record itself has appropriate
12683 -- alignment to guarantee the component alignment.
12685 -- Make sure sizes are static, always assume the worst for any
12686 -- cases where we cannot check static values.
12688 if not (Known_Static_Esize
(C
)
12690 Known_Static_Esize
(Ctyp
))
12695 -- Size of component must be addressable or greater than 64 bits
12696 -- and a multiple of bytes.
12698 if not Addressable
(Esize
(C
)) and then Esize
(C
) < Uint_64
then
12702 -- Check size is proper multiple
12704 if Esize
(C
) mod Esize
(Ctyp
) /= 0 then
12708 -- Check alignment of component is OK
12710 if not Known_Component_Bit_Offset
(C
)
12711 or else Component_Bit_Offset
(C
) < Uint_0
12712 or else Component_Bit_Offset
(C
) mod Esize
(Ctyp
) /= 0
12717 -- Check alignment of record type is OK
12719 if not Known_Alignment
(Rec
)
12720 or else (Alignment
(Rec
) * SU
) mod Esize
(Ctyp
) /= 0
12725 -- All tests passed, component is addressable
12730 --------------------------
12731 -- Reason_Bad_Component --
12732 --------------------------
12734 procedure Reason_Bad_Component
(C
: Entity_Id
) is
12735 Rec
: constant Entity_Id
:= Scope
(C
);
12736 Ctyp
: constant Entity_Id
:= Etype
(C
);
12739 -- If component clause present assume that's the problem
12741 if Present
(Component_Clause
(C
)) then
12742 Error_Msg_Sloc
:= Sloc
(Component_Clause
(C
));
12743 Error_Msg_N
("\because of Component_Clause#", N
);
12747 -- If pragma Pack clause present, assume that's the problem
12749 if Is_Packed
(Rec
) then
12750 P
:= Get_Rep_Pragma
(Rec
, Name_Pack
);
12752 if Present
(P
) then
12753 Error_Msg_Sloc
:= Sloc
(P
);
12754 Error_Msg_N
("\because of pragma Pack#", N
);
12759 -- See if record has bad alignment clause
12761 if Has_Alignment_Clause
(Rec
)
12762 and then Known_Alignment
(Rec
)
12763 and then (Alignment
(Rec
) * SU
) mod Esize
(Ctyp
) /= 0
12765 P
:= Get_Attribute_Definition_Clause
(Rec
, Attribute_Alignment
);
12767 if Present
(P
) then
12768 Error_Msg_Sloc
:= Sloc
(P
);
12769 Error_Msg_N
("\because of Alignment clause#", N
);
12773 -- Couldn't find a reason, so return without a message
12776 end Reason_Bad_Component
;
12778 -- Start of processing for Validate_Independence
12781 for J
in Independence_Checks
.First
.. Independence_Checks
.Last
loop
12782 N
:= Independence_Checks
.Table
(J
).N
;
12783 E
:= Independence_Checks
.Table
(J
).E
;
12784 IC
:= Pragma_Name
(N
) = Name_Independent_Components
;
12786 -- Deal with component case
12788 if Ekind
(E
) = E_Discriminant
or else Ekind
(E
) = E_Component
then
12789 if not OK_Component
(E
) then
12791 Reason_Bad_Component
(E
);
12796 -- Deal with record with Independent_Components
12798 if IC
and then Is_Record_Type
(E
) then
12799 Comp
:= First_Component_Or_Discriminant
(E
);
12800 while Present
(Comp
) loop
12801 if not OK_Component
(Comp
) then
12803 Reason_Bad_Component
(Comp
);
12807 Next_Component_Or_Discriminant
(Comp
);
12811 -- Deal with address clause case
12813 if Is_Object
(E
) then
12814 Addr
:= Address_Clause
(E
);
12816 if Present
(Addr
) then
12818 Error_Msg_Sloc
:= Sloc
(Addr
);
12819 Error_Msg_N
("\because of Address clause#", N
);
12824 -- Deal with independent components for array type
12826 if IC
and then Is_Array_Type
(E
) then
12827 Check_Array_Type
(E
);
12830 -- Deal with independent components for array object
12832 if IC
and then Is_Object
(E
) and then Is_Array_Type
(Etype
(E
)) then
12833 Check_Array_Type
(Etype
(E
));
12838 end Validate_Independence
;
12840 ------------------------------
12841 -- Validate_Iterable_Aspect --
12842 ------------------------------
12844 procedure Validate_Iterable_Aspect
(Typ
: Entity_Id
; ASN
: Node_Id
) is
12849 Cursor
: constant Entity_Id
:= Get_Cursor_Type
(ASN
, Typ
);
12851 First_Id
: Entity_Id
;
12852 Next_Id
: Entity_Id
;
12853 Has_Element_Id
: Entity_Id
;
12854 Element_Id
: Entity_Id
;
12857 -- If previous error aspect is unusable
12859 if Cursor
= Any_Type
then
12865 Has_Element_Id
:= Empty
;
12866 Element_Id
:= Empty
;
12868 -- Each expression must resolve to a function with the proper signature
12870 Assoc
:= First
(Component_Associations
(Expression
(ASN
)));
12871 while Present
(Assoc
) loop
12872 Expr
:= Expression
(Assoc
);
12875 Prim
:= First
(Choices
(Assoc
));
12877 if Nkind
(Prim
) /= N_Identifier
or else Present
(Next
(Prim
)) then
12878 Error_Msg_N
("illegal name in association", Prim
);
12880 elsif Chars
(Prim
) = Name_First
then
12881 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_First
);
12882 First_Id
:= Entity
(Expr
);
12884 elsif Chars
(Prim
) = Name_Next
then
12885 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_Next
);
12886 Next_Id
:= Entity
(Expr
);
12888 elsif Chars
(Prim
) = Name_Has_Element
then
12889 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_Has_Element
);
12890 Has_Element_Id
:= Entity
(Expr
);
12892 elsif Chars
(Prim
) = Name_Element
then
12893 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_Element
);
12894 Element_Id
:= Entity
(Expr
);
12897 Error_Msg_N
("invalid name for iterable function", Prim
);
12903 if No
(First_Id
) then
12904 Error_Msg_N
("match for First primitive not found", ASN
);
12906 elsif No
(Next_Id
) then
12907 Error_Msg_N
("match for Next primitive not found", ASN
);
12909 elsif No
(Has_Element_Id
) then
12910 Error_Msg_N
("match for Has_Element primitive not found", ASN
);
12912 elsif No
(Element_Id
) then
12915 end Validate_Iterable_Aspect
;
12917 -----------------------------------
12918 -- Validate_Unchecked_Conversion --
12919 -----------------------------------
12921 procedure Validate_Unchecked_Conversion
12923 Act_Unit
: Entity_Id
)
12925 Source
: Entity_Id
;
12926 Target
: Entity_Id
;
12930 -- Obtain source and target types. Note that we call Ancestor_Subtype
12931 -- here because the processing for generic instantiation always makes
12932 -- subtypes, and we want the original frozen actual types.
12934 -- If we are dealing with private types, then do the check on their
12935 -- fully declared counterparts if the full declarations have been
12936 -- encountered (they don't have to be visible, but they must exist).
12938 Source
:= Ancestor_Subtype
(Etype
(First_Formal
(Act_Unit
)));
12940 if Is_Private_Type
(Source
)
12941 and then Present
(Underlying_Type
(Source
))
12943 Source
:= Underlying_Type
(Source
);
12946 Target
:= Ancestor_Subtype
(Etype
(Act_Unit
));
12948 -- If either type is generic, the instantiation happens within a generic
12949 -- unit, and there is nothing to check. The proper check will happen
12950 -- when the enclosing generic is instantiated.
12952 if Is_Generic_Type
(Source
) or else Is_Generic_Type
(Target
) then
12956 if Is_Private_Type
(Target
)
12957 and then Present
(Underlying_Type
(Target
))
12959 Target
:= Underlying_Type
(Target
);
12962 -- Source may be unconstrained array, but not target
12964 if Is_Array_Type
(Target
) and then not Is_Constrained
(Target
) then
12966 ("unchecked conversion to unconstrained array not allowed", N
);
12970 -- Warn if conversion between two different convention pointers
12972 if Is_Access_Type
(Target
)
12973 and then Is_Access_Type
(Source
)
12974 and then Convention
(Target
) /= Convention
(Source
)
12975 and then Warn_On_Unchecked_Conversion
12977 -- Give warnings for subprogram pointers only on most targets
12979 if Is_Access_Subprogram_Type
(Target
)
12980 or else Is_Access_Subprogram_Type
(Source
)
12983 ("?z?conversion between pointers with different conventions!",
12988 -- Warn if one of the operands is Ada.Calendar.Time. Do not emit a
12989 -- warning when compiling GNAT-related sources.
12991 if Warn_On_Unchecked_Conversion
12992 and then not In_Predefined_Unit
(N
)
12993 and then RTU_Loaded
(Ada_Calendar
)
12994 and then (Chars
(Source
) = Name_Time
12996 Chars
(Target
) = Name_Time
)
12998 -- If Ada.Calendar is loaded and the name of one of the operands is
12999 -- Time, there is a good chance that this is Ada.Calendar.Time.
13002 Calendar_Time
: constant Entity_Id
:= Full_View
(RTE
(RO_CA_Time
));
13004 pragma Assert
(Present
(Calendar_Time
));
13006 if Source
= Calendar_Time
or else Target
= Calendar_Time
then
13008 ("?z?representation of 'Time values may change between "
13009 & "'G'N'A'T versions", N
);
13014 -- Make entry in unchecked conversion table for later processing by
13015 -- Validate_Unchecked_Conversions, which will check sizes and alignments
13016 -- (using values set by the back-end where possible). This is only done
13017 -- if the appropriate warning is active.
13019 if Warn_On_Unchecked_Conversion
then
13020 Unchecked_Conversions
.Append
13021 (New_Val
=> UC_Entry
'(Eloc => Sloc (N),
13024 Act_Unit => Act_Unit));
13026 -- If both sizes are known statically now, then back end annotation
13027 -- is not required to do a proper check but if either size is not
13028 -- known statically, then we need the annotation.
13030 if Known_Static_RM_Size (Source)
13032 Known_Static_RM_Size (Target)
13036 Back_Annotate_Rep_Info := True;
13040 -- If unchecked conversion to access type, and access type is declared
13041 -- in the same unit as the unchecked conversion, then set the flag
13042 -- No_Strict_Aliasing (no strict aliasing is implicit here)
13044 if Is_Access_Type (Target) and then
13045 In_Same_Source_Unit (Target, N)
13047 Set_No_Strict_Aliasing (Implementation_Base_Type (Target));
13050 -- Generate N_Validate_Unchecked_Conversion node for back end in case
13051 -- the back end needs to perform special validation checks.
13053 -- Shouldn't this be in Exp_Ch13, since the check only gets done if we
13054 -- have full expansion and the back end is called ???
13057 Make_Validate_Unchecked_Conversion (Sloc (N));
13058 Set_Source_Type (Vnode, Source);
13059 Set_Target_Type (Vnode, Target);
13061 -- If the unchecked conversion node is in a list, just insert before it.
13062 -- If not we have some strange case, not worth bothering about.
13064 if Is_List_Member (N) then
13065 Insert_After (N, Vnode);
13067 end Validate_Unchecked_Conversion;
13069 ------------------------------------
13070 -- Validate_Unchecked_Conversions --
13071 ------------------------------------
13073 procedure Validate_Unchecked_Conversions is
13075 for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop
13077 T : UC_Entry renames Unchecked_Conversions.Table (N);
13079 Eloc : constant Source_Ptr := T.Eloc;
13080 Source : constant Entity_Id := T.Source;
13081 Target : constant Entity_Id := T.Target;
13082 Act_Unit : constant Entity_Id := T.Act_Unit;
13088 -- Skip if function marked as warnings off
13090 if Warnings_Off (Act_Unit) then
13094 -- This validation check, which warns if we have unequal sizes for
13095 -- unchecked conversion, and thus potentially implementation
13096 -- dependent semantics, is one of the few occasions on which we
13097 -- use the official RM size instead of Esize. See description in
13098 -- Einfo "Handling of Type'Size Values" for details.
13100 if Serious_Errors_Detected = 0
13101 and then Known_Static_RM_Size (Source)
13102 and then Known_Static_RM_Size (Target)
13104 -- Don't do the check if warnings off for either type, note the
13105 -- deliberate use of OR here instead of OR ELSE to get the flag
13106 -- Warnings_Off_Used set for both types if appropriate.
13108 and then not (Has_Warnings_Off (Source)
13110 Has_Warnings_Off (Target))
13112 Source_Siz := RM_Size (Source);
13113 Target_Siz := RM_Size (Target);
13115 if Source_Siz /= Target_Siz then
13117 ("?z?types for unchecked conversion have different sizes!",
13120 if All_Errors_Mode then
13121 Error_Msg_Name_1 := Chars (Source);
13122 Error_Msg_Uint_1 := Source_Siz;
13123 Error_Msg_Name_2 := Chars (Target);
13124 Error_Msg_Uint_2 := Target_Siz;
13125 Error_Msg ("\size of % is ^, size of % is ^?z?", Eloc);
13127 Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz);
13129 if Is_Discrete_Type (Source)
13131 Is_Discrete_Type (Target)
13133 if Source_Siz > Target_Siz then
13135 ("\?z?^ high order bits of source will "
13136 & "be ignored!", Eloc);
13138 elsif Is_Unsigned_Type (Source) then
13140 ("\?z?source will be extended with ^ high order "
13141 & "zero bits!", Eloc);
13145 ("\?z?source will be extended with ^ high order "
13146 & "sign bits!", Eloc);
13149 elsif Source_Siz < Target_Siz then
13150 if Is_Discrete_Type (Target) then
13151 if Bytes_Big_Endian then
13153 ("\?z?target value will include ^ undefined "
13154 & "low order bits!", Eloc);
13157 ("\?z?target value will include ^ undefined "
13158 & "high order bits!", Eloc);
13163 ("\?z?^ trailing bits of target value will be "
13164 & "undefined!", Eloc);
13167 else pragma Assert (Source_Siz > Target_Siz);
13169 ("\?z?^ trailing bits of source will be ignored!",
13176 -- If both types are access types, we need to check the alignment.
13177 -- If the alignment of both is specified, we can do it here.
13179 if Serious_Errors_Detected = 0
13180 and then Is_Access_Type (Source)
13181 and then Is_Access_Type (Target)
13182 and then Target_Strict_Alignment
13183 and then Present (Designated_Type (Source))
13184 and then Present (Designated_Type (Target))
13187 D_Source : constant Entity_Id := Designated_Type (Source);
13188 D_Target : constant Entity_Id := Designated_Type (Target);
13191 if Known_Alignment (D_Source)
13193 Known_Alignment (D_Target)
13196 Source_Align : constant Uint := Alignment (D_Source);
13197 Target_Align : constant Uint := Alignment (D_Target);
13200 if Source_Align < Target_Align
13201 and then not Is_Tagged_Type (D_Source)
13203 -- Suppress warning if warnings suppressed on either
13204 -- type or either designated type. Note the use of
13205 -- OR here instead of OR ELSE. That is intentional,
13206 -- we would like to set flag Warnings_Off_Used in
13207 -- all types for which warnings are suppressed.
13209 and then not (Has_Warnings_Off (D_Source)
13211 Has_Warnings_Off (D_Target)
13213 Has_Warnings_Off (Source)
13215 Has_Warnings_Off (Target))
13217 Error_Msg_Uint_1 := Target_Align;
13218 Error_Msg_Uint_2 := Source_Align;
13219 Error_Msg_Node_1 := D_Target;
13220 Error_Msg_Node_2 := D_Source;
13222 ("?z?alignment of & (^) is stricter than "
13223 & "alignment of & (^)!", Eloc);
13225 ("\?z?resulting access value may have invalid "
13226 & "alignment!", Eloc);
13237 end Validate_Unchecked_Conversions;