1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2015, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Aspects
; use Aspects
;
27 with Atree
; use Atree
;
28 with Checks
; use Checks
;
29 with Debug
; use Debug
;
30 with Einfo
; use Einfo
;
31 with Elists
; use Elists
;
32 with Errout
; use Errout
;
33 with Exp_Disp
; use Exp_Disp
;
34 with Exp_Tss
; use Exp_Tss
;
35 with Exp_Util
; use Exp_Util
;
36 with Freeze
; use Freeze
;
38 with Lib
.Xref
; use Lib
.Xref
;
39 with Namet
; use Namet
;
40 with Nlists
; use Nlists
;
41 with Nmake
; use Nmake
;
43 with Restrict
; use Restrict
;
44 with Rident
; use Rident
;
45 with Rtsfind
; use Rtsfind
;
47 with Sem_Aux
; use Sem_Aux
;
48 with Sem_Case
; use Sem_Case
;
49 with Sem_Ch3
; use Sem_Ch3
;
50 with Sem_Ch6
; use Sem_Ch6
;
51 with Sem_Ch8
; use Sem_Ch8
;
52 with Sem_Dim
; use Sem_Dim
;
53 with Sem_Disp
; use Sem_Disp
;
54 with Sem_Eval
; use Sem_Eval
;
55 with Sem_Prag
; use Sem_Prag
;
56 with Sem_Res
; use Sem_Res
;
57 with Sem_Type
; use Sem_Type
;
58 with Sem_Util
; use Sem_Util
;
59 with Sem_Warn
; use Sem_Warn
;
60 with Sinput
; use Sinput
;
61 with Snames
; use Snames
;
62 with Stand
; use Stand
;
63 with Sinfo
; use Sinfo
;
64 with Stringt
; use Stringt
;
65 with Targparm
; use Targparm
;
66 with Ttypes
; use Ttypes
;
67 with Tbuild
; use Tbuild
;
68 with Urealp
; use Urealp
;
69 with Warnsw
; use Warnsw
;
71 with GNAT
.Heap_Sort_G
;
73 package body Sem_Ch13
is
75 SSU
: constant Pos
:= System_Storage_Unit
;
76 -- Convenient short hand for commonly used constant
78 -----------------------
79 -- Local Subprograms --
80 -----------------------
82 procedure Alignment_Check_For_Size_Change
(Typ
: Entity_Id
; Size
: Uint
);
83 -- This routine is called after setting one of the sizes of type entity
84 -- Typ to Size. The purpose is to deal with the situation of a derived
85 -- type whose inherited alignment is no longer appropriate for the new
86 -- size value. In this case, we reset the Alignment to unknown.
88 procedure Build_Discrete_Static_Predicate
92 -- Given a predicated type Typ, where Typ is a discrete static subtype,
93 -- whose predicate expression is Expr, tests if Expr is a static predicate,
94 -- and if so, builds the predicate range list. Nam is the name of the one
95 -- argument to the predicate function. Occurrences of the type name in the
96 -- predicate expression have been replaced by identifier references to this
97 -- name, which is unique, so any identifier with Chars matching Nam must be
98 -- a reference to the type. If the predicate is non-static, this procedure
99 -- returns doing nothing. If the predicate is static, then the predicate
100 -- list is stored in Static_Discrete_Predicate (Typ), and the Expr is
101 -- rewritten as a canonicalized membership operation.
103 procedure Build_Predicate_Functions
(Typ
: Entity_Id
; N
: Node_Id
);
104 -- If Typ has predicates (indicated by Has_Predicates being set for Typ),
105 -- then either there are pragma Predicate entries on the rep chain for the
106 -- type (note that Predicate aspects are converted to pragma Predicate), or
107 -- there are inherited aspects from a parent type, or ancestor subtypes.
108 -- This procedure builds the spec and body for the Predicate function that
109 -- tests these predicates. N is the freeze node for the type. The spec of
110 -- the function is inserted before the freeze node, and the body of the
111 -- function is inserted after the freeze node. If the predicate expression
112 -- has at least one Raise_Expression, then this procedure also builds the
113 -- M version of the predicate function for use in membership tests.
115 procedure Check_Pool_Size_Clash
(Ent
: Entity_Id
; SP
, SS
: Node_Id
);
116 -- Called if both Storage_Pool and Storage_Size attribute definition
117 -- clauses (SP and SS) are present for entity Ent. Issue error message.
119 procedure Freeze_Entity_Checks
(N
: Node_Id
);
120 -- Called from Analyze_Freeze_Entity and Analyze_Generic_Freeze Entity
121 -- to generate appropriate semantic checks that are delayed until this
122 -- point (they had to be delayed this long for cases of delayed aspects,
123 -- e.g. analysis of statically predicated subtypes in choices, for which
124 -- we have to be sure the subtypes in question are frozen before checking.
126 function Get_Alignment_Value
(Expr
: Node_Id
) return Uint
;
127 -- Given the expression for an alignment value, returns the corresponding
128 -- Uint value. If the value is inappropriate, then error messages are
129 -- posted as required, and a value of No_Uint is returned.
131 function Is_Operational_Item
(N
: Node_Id
) return Boolean;
132 -- A specification for a stream attribute is allowed before the full type
133 -- is declared, as explained in AI-00137 and the corrigendum. Attributes
134 -- that do not specify a representation characteristic are operational
137 function Is_Predicate_Static
139 Nam
: Name_Id
) return Boolean;
140 -- Given predicate expression Expr, tests if Expr is predicate-static in
141 -- the sense of the rules in (RM 3.2.4 (15-24)). Occurrences of the type
142 -- name in the predicate expression have been replaced by references to
143 -- an identifier whose Chars field is Nam. This name is unique, so any
144 -- identifier with Chars matching Nam must be a reference to the type.
145 -- Returns True if the expression is predicate-static and False otherwise,
146 -- but is not in the business of setting flags or issuing error messages.
148 -- Only scalar types can have static predicates, so False is always
149 -- returned for non-scalar types.
151 -- Note: the RM seems to suggest that string types can also have static
152 -- predicates. But that really makes lttle sense as very few useful
153 -- predicates can be constructed for strings. Remember that:
157 -- is not a static expression. So even though the clearly faulty RM wording
158 -- allows the following:
160 -- subtype S is String with Static_Predicate => S < "DEF"
162 -- We can't allow this, otherwise we have predicate-static applying to a
163 -- larger class than static expressions, which was never intended.
165 procedure New_Stream_Subprogram
169 Nam
: TSS_Name_Type
);
170 -- Create a subprogram renaming of a given stream attribute to the
171 -- designated subprogram and then in the tagged case, provide this as a
172 -- primitive operation, or in the untagged case make an appropriate TSS
173 -- entry. This is more properly an expansion activity than just semantics,
174 -- but the presence of user-defined stream functions for limited types
175 -- is a legality check, which is why this takes place here rather than in
176 -- exp_ch13, where it was previously. Nam indicates the name of the TSS
177 -- function to be generated.
179 -- To avoid elaboration anomalies with freeze nodes, for untagged types
180 -- we generate both a subprogram declaration and a subprogram renaming
181 -- declaration, so that the attribute specification is handled as a
182 -- renaming_as_body. For tagged types, the specification is one of the
185 procedure Resolve_Iterable_Operation
190 -- If the name of a primitive operation for an Iterable aspect is
191 -- overloaded, resolve according to required signature.
197 Biased
: Boolean := True);
198 -- If Biased is True, sets Has_Biased_Representation flag for E, and
199 -- outputs a warning message at node N if Warn_On_Biased_Representation is
200 -- is True. This warning inserts the string Msg to describe the construct
203 ----------------------------------------------
204 -- Table for Validate_Unchecked_Conversions --
205 ----------------------------------------------
207 -- The following table collects unchecked conversions for validation.
208 -- Entries are made by Validate_Unchecked_Conversion and then the call
209 -- to Validate_Unchecked_Conversions does the actual error checking and
210 -- posting of warnings. The reason for this delayed processing is to take
211 -- advantage of back-annotations of size and alignment values performed by
214 -- Note: the reason we store a Source_Ptr value instead of a Node_Id is
215 -- that by the time Validate_Unchecked_Conversions is called, Sprint will
216 -- already have modified all Sloc values if the -gnatD option is set.
218 type UC_Entry
is record
219 Eloc
: Source_Ptr
; -- node used for posting warnings
220 Source
: Entity_Id
; -- source type for unchecked conversion
221 Target
: Entity_Id
; -- target type for unchecked conversion
222 Act_Unit
: Entity_Id
; -- actual function instantiated
225 package Unchecked_Conversions
is new Table
.Table
(
226 Table_Component_Type
=> UC_Entry
,
227 Table_Index_Type
=> Int
,
228 Table_Low_Bound
=> 1,
230 Table_Increment
=> 200,
231 Table_Name
=> "Unchecked_Conversions");
233 ----------------------------------------
234 -- Table for Validate_Address_Clauses --
235 ----------------------------------------
237 -- If an address clause has the form
239 -- for X'Address use Expr
241 -- where Expr is of the form Y'Address or recursively is a reference to a
242 -- constant of either of these forms, and X and Y are entities of objects,
243 -- then if Y has a smaller alignment than X, that merits a warning about
244 -- possible bad alignment. The following table collects address clauses of
245 -- this kind. We put these in a table so that they can be checked after the
246 -- back end has completed annotation of the alignments of objects, since we
247 -- can catch more cases that way.
249 type Address_Clause_Check_Record
is record
251 -- The address clause
254 -- The entity of the object overlaying Y
257 -- The entity of the object being overlaid
260 -- Whether the address is offset within Y
263 package Address_Clause_Checks
is new Table
.Table
(
264 Table_Component_Type
=> Address_Clause_Check_Record
,
265 Table_Index_Type
=> Int
,
266 Table_Low_Bound
=> 1,
268 Table_Increment
=> 200,
269 Table_Name
=> "Address_Clause_Checks");
271 -----------------------------------------
272 -- Adjust_Record_For_Reverse_Bit_Order --
273 -----------------------------------------
275 procedure Adjust_Record_For_Reverse_Bit_Order
(R
: Entity_Id
) is
280 -- Processing depends on version of Ada
282 -- For Ada 95, we just renumber bits within a storage unit. We do the
283 -- same for Ada 83 mode, since we recognize the Bit_Order attribute in
284 -- Ada 83, and are free to add this extension.
286 if Ada_Version
< Ada_2005
then
287 Comp
:= First_Component_Or_Discriminant
(R
);
288 while Present
(Comp
) loop
289 CC
:= Component_Clause
(Comp
);
291 -- If component clause is present, then deal with the non-default
292 -- bit order case for Ada 95 mode.
294 -- We only do this processing for the base type, and in fact that
295 -- is important, since otherwise if there are record subtypes, we
296 -- could reverse the bits once for each subtype, which is wrong.
298 if Present
(CC
) and then Ekind
(R
) = E_Record_Type
then
300 CFB
: constant Uint
:= Component_Bit_Offset
(Comp
);
301 CSZ
: constant Uint
:= Esize
(Comp
);
302 CLC
: constant Node_Id
:= Component_Clause
(Comp
);
303 Pos
: constant Node_Id
:= Position
(CLC
);
304 FB
: constant Node_Id
:= First_Bit
(CLC
);
306 Storage_Unit_Offset
: constant Uint
:=
307 CFB
/ System_Storage_Unit
;
309 Start_Bit
: constant Uint
:=
310 CFB
mod System_Storage_Unit
;
313 -- Cases where field goes over storage unit boundary
315 if Start_Bit
+ CSZ
> System_Storage_Unit
then
317 -- Allow multi-byte field but generate warning
319 if Start_Bit
mod System_Storage_Unit
= 0
320 and then CSZ
mod System_Storage_Unit
= 0
323 ("info: multi-byte field specified with "
324 & "non-standard Bit_Order?V?", CLC
);
326 if Bytes_Big_Endian
then
328 ("\bytes are not reversed "
329 & "(component is big-endian)?V?", CLC
);
332 ("\bytes are not reversed "
333 & "(component is little-endian)?V?", CLC
);
336 -- Do not allow non-contiguous field
340 ("attempt to specify non-contiguous field "
341 & "not permitted", CLC
);
343 ("\caused by non-standard Bit_Order "
346 ("\consider possibility of using "
347 & "Ada 2005 mode here", CLC
);
350 -- Case where field fits in one storage unit
353 -- Give warning if suspicious component clause
355 if Intval
(FB
) >= System_Storage_Unit
356 and then Warn_On_Reverse_Bit_Order
359 ("info: Bit_Order clause does not affect " &
360 "byte ordering?V?", Pos
);
362 Intval
(Pos
) + Intval
(FB
) /
365 ("info: position normalized to ^ before bit " &
366 "order interpreted?V?", Pos
);
369 -- Here is where we fix up the Component_Bit_Offset value
370 -- to account for the reverse bit order. Some examples of
371 -- what needs to be done are:
373 -- First_Bit .. Last_Bit Component_Bit_Offset
385 -- The rule is that the first bit is is obtained by
386 -- subtracting the old ending bit from storage_unit - 1.
388 Set_Component_Bit_Offset
390 (Storage_Unit_Offset
* System_Storage_Unit
) +
391 (System_Storage_Unit
- 1) -
392 (Start_Bit
+ CSZ
- 1));
394 Set_Normalized_First_Bit
396 Component_Bit_Offset
(Comp
) mod
397 System_Storage_Unit
);
402 Next_Component_Or_Discriminant
(Comp
);
405 -- For Ada 2005, we do machine scalar processing, as fully described In
406 -- AI-133. This involves gathering all components which start at the
407 -- same byte offset and processing them together. Same approach is still
408 -- valid in later versions including Ada 2012.
412 Max_Machine_Scalar_Size
: constant Uint
:=
414 (Standard_Long_Long_Integer_Size
);
415 -- We use this as the maximum machine scalar size
418 SSU
: constant Uint
:= UI_From_Int
(System_Storage_Unit
);
421 -- This first loop through components does two things. First it
422 -- deals with the case of components with component clauses whose
423 -- length is greater than the maximum machine scalar size (either
424 -- accepting them or rejecting as needed). Second, it counts the
425 -- number of components with component clauses whose length does
426 -- not exceed this maximum for later processing.
429 Comp
:= First_Component_Or_Discriminant
(R
);
430 while Present
(Comp
) loop
431 CC
:= Component_Clause
(Comp
);
435 Fbit
: constant Uint
:= Static_Integer
(First_Bit
(CC
));
436 Lbit
: constant Uint
:= Static_Integer
(Last_Bit
(CC
));
439 -- Case of component with last bit >= max machine scalar
441 if Lbit
>= Max_Machine_Scalar_Size
then
443 -- This is allowed only if first bit is zero, and
444 -- last bit + 1 is a multiple of storage unit size.
446 if Fbit
= 0 and then (Lbit
+ 1) mod SSU
= 0 then
448 -- This is the case to give a warning if enabled
450 if Warn_On_Reverse_Bit_Order
then
452 ("info: multi-byte field specified with "
453 & " non-standard Bit_Order?V?", CC
);
455 if Bytes_Big_Endian
then
457 ("\bytes are not reversed "
458 & "(component is big-endian)?V?", CC
);
461 ("\bytes are not reversed "
462 & "(component is little-endian)?V?", CC
);
466 -- Give error message for RM 13.5.1(10) violation
470 ("machine scalar rules not followed for&",
471 First_Bit
(CC
), Comp
);
473 Error_Msg_Uint_1
:= Lbit
;
474 Error_Msg_Uint_2
:= Max_Machine_Scalar_Size
;
476 ("\last bit (^) exceeds maximum machine "
480 if (Lbit
+ 1) mod SSU
/= 0 then
481 Error_Msg_Uint_1
:= SSU
;
483 ("\and is not a multiple of Storage_Unit (^) "
488 Error_Msg_Uint_1
:= Fbit
;
490 ("\and first bit (^) is non-zero "
496 -- OK case of machine scalar related component clause,
497 -- For now, just count them.
500 Num_CC
:= Num_CC
+ 1;
505 Next_Component_Or_Discriminant
(Comp
);
508 -- We need to sort the component clauses on the basis of the
509 -- Position values in the clause, so we can group clauses with
510 -- the same Position together to determine the relevant machine
514 Comps
: array (0 .. Num_CC
) of Entity_Id
;
515 -- Array to collect component and discriminant entities. The
516 -- data starts at index 1, the 0'th entry is for the sort
519 function CP_Lt
(Op1
, Op2
: Natural) return Boolean;
520 -- Compare routine for Sort
522 procedure CP_Move
(From
: Natural; To
: Natural);
523 -- Move routine for Sort
525 package Sorting
is new GNAT
.Heap_Sort_G
(CP_Move
, CP_Lt
);
529 -- Start and stop positions in the component list of the set of
530 -- components with the same starting position (that constitute
531 -- components in a single machine scalar).
534 -- Maximum last bit value of any component in this set
537 -- Corresponding machine scalar size
543 function CP_Lt
(Op1
, Op2
: Natural) return Boolean is
545 return Position
(Component_Clause
(Comps
(Op1
))) <
546 Position
(Component_Clause
(Comps
(Op2
)));
553 procedure CP_Move
(From
: Natural; To
: Natural) is
555 Comps
(To
) := Comps
(From
);
558 -- Start of processing for Sort_CC
561 -- Collect the machine scalar relevant component clauses
564 Comp
:= First_Component_Or_Discriminant
(R
);
565 while Present
(Comp
) loop
567 CC
: constant Node_Id
:= Component_Clause
(Comp
);
570 -- Collect only component clauses whose last bit is less
571 -- than machine scalar size. Any component clause whose
572 -- last bit exceeds this value does not take part in
573 -- machine scalar layout considerations. The test for
574 -- Error_Posted makes sure we exclude component clauses
575 -- for which we already posted an error.
578 and then not Error_Posted
(Last_Bit
(CC
))
579 and then Static_Integer
(Last_Bit
(CC
)) <
580 Max_Machine_Scalar_Size
582 Num_CC
:= Num_CC
+ 1;
583 Comps
(Num_CC
) := Comp
;
587 Next_Component_Or_Discriminant
(Comp
);
590 -- Sort by ascending position number
592 Sorting
.Sort
(Num_CC
);
594 -- We now have all the components whose size does not exceed
595 -- the max machine scalar value, sorted by starting position.
596 -- In this loop we gather groups of clauses starting at the
597 -- same position, to process them in accordance with AI-133.
600 while Stop
< Num_CC
loop
605 (Last_Bit
(Component_Clause
(Comps
(Start
))));
606 while Stop
< Num_CC
loop
608 (Position
(Component_Clause
(Comps
(Stop
+ 1)))) =
610 (Position
(Component_Clause
(Comps
(Stop
))))
618 (Component_Clause
(Comps
(Stop
)))));
624 -- Now we have a group of component clauses from Start to
625 -- Stop whose positions are identical, and MaxL is the
626 -- maximum last bit value of any of these components.
628 -- We need to determine the corresponding machine scalar
629 -- size. This loop assumes that machine scalar sizes are
630 -- even, and that each possible machine scalar has twice
631 -- as many bits as the next smaller one.
633 MSS
:= Max_Machine_Scalar_Size
;
635 and then (MSS
/ 2) >= SSU
636 and then (MSS
/ 2) > MaxL
641 -- Here is where we fix up the Component_Bit_Offset value
642 -- to account for the reverse bit order. Some examples of
643 -- what needs to be done for the case of a machine scalar
646 -- First_Bit .. Last_Bit Component_Bit_Offset
658 -- The rule is that the first bit is obtained by subtracting
659 -- the old ending bit from machine scalar size - 1.
661 for C
in Start
.. Stop
loop
663 Comp
: constant Entity_Id
:= Comps
(C
);
664 CC
: constant Node_Id
:= Component_Clause
(Comp
);
666 LB
: constant Uint
:= Static_Integer
(Last_Bit
(CC
));
667 NFB
: constant Uint
:= MSS
- Uint_1
- LB
;
668 NLB
: constant Uint
:= NFB
+ Esize
(Comp
) - 1;
669 Pos
: constant Uint
:= Static_Integer
(Position
(CC
));
672 if Warn_On_Reverse_Bit_Order
then
673 Error_Msg_Uint_1
:= MSS
;
675 ("info: reverse bit order in machine " &
676 "scalar of length^?V?", First_Bit
(CC
));
677 Error_Msg_Uint_1
:= NFB
;
678 Error_Msg_Uint_2
:= NLB
;
680 if Bytes_Big_Endian
then
682 ("\big-endian range for component "
683 & "& is ^ .. ^?V?", First_Bit
(CC
), Comp
);
686 ("\little-endian range for component"
687 & "& is ^ .. ^?V?", First_Bit
(CC
), Comp
);
691 Set_Component_Bit_Offset
(Comp
, Pos
* SSU
+ NFB
);
692 Set_Normalized_First_Bit
(Comp
, NFB
mod SSU
);
699 end Adjust_Record_For_Reverse_Bit_Order
;
701 -------------------------------------
702 -- Alignment_Check_For_Size_Change --
703 -------------------------------------
705 procedure Alignment_Check_For_Size_Change
(Typ
: Entity_Id
; Size
: Uint
) is
707 -- If the alignment is known, and not set by a rep clause, and is
708 -- inconsistent with the size being set, then reset it to unknown,
709 -- we assume in this case that the size overrides the inherited
710 -- alignment, and that the alignment must be recomputed.
712 if Known_Alignment
(Typ
)
713 and then not Has_Alignment_Clause
(Typ
)
714 and then Size
mod (Alignment
(Typ
) * SSU
) /= 0
716 Init_Alignment
(Typ
);
718 end Alignment_Check_For_Size_Change
;
720 -------------------------------------
721 -- Analyze_Aspects_At_Freeze_Point --
722 -------------------------------------
724 procedure Analyze_Aspects_At_Freeze_Point
(E
: Entity_Id
) is
729 procedure Analyze_Aspect_Default_Value
(ASN
: Node_Id
);
730 -- This routine analyzes an Aspect_Default_[Component_]Value denoted by
731 -- the aspect specification node ASN.
733 procedure Inherit_Delayed_Rep_Aspects
(ASN
: Node_Id
);
734 -- As discussed in the spec of Aspects (see Aspect_Delay declaration),
735 -- a derived type can inherit aspects from its parent which have been
736 -- specified at the time of the derivation using an aspect, as in:
738 -- type A is range 1 .. 10
739 -- with Size => Not_Defined_Yet;
743 -- Not_Defined_Yet : constant := 64;
745 -- In this example, the Size of A is considered to be specified prior
746 -- to the derivation, and thus inherited, even though the value is not
747 -- known at the time of derivation. To deal with this, we use two entity
748 -- flags. The flag Has_Derived_Rep_Aspects is set in the parent type (A
749 -- here), and then the flag May_Inherit_Delayed_Rep_Aspects is set in
750 -- the derived type (B here). If this flag is set when the derived type
751 -- is frozen, then this procedure is called to ensure proper inheritance
752 -- of all delayed aspects from the parent type. The derived type is E,
753 -- the argument to Analyze_Aspects_At_Freeze_Point. ASN is the first
754 -- aspect specification node in the Rep_Item chain for the parent type.
756 procedure Make_Pragma_From_Boolean_Aspect
(ASN
: Node_Id
);
757 -- Given an aspect specification node ASN whose expression is an
758 -- optional Boolean, this routines creates the corresponding pragma
759 -- at the freezing point.
761 ----------------------------------
762 -- Analyze_Aspect_Default_Value --
763 ----------------------------------
765 procedure Analyze_Aspect_Default_Value
(ASN
: Node_Id
) is
766 Ent
: constant Entity_Id
:= Entity
(ASN
);
767 Expr
: constant Node_Id
:= Expression
(ASN
);
768 Id
: constant Node_Id
:= Identifier
(ASN
);
771 Error_Msg_Name_1
:= Chars
(Id
);
773 if not Is_Type
(Ent
) then
774 Error_Msg_N
("aspect% can only apply to a type", Id
);
777 elsif not Is_First_Subtype
(Ent
) then
778 Error_Msg_N
("aspect% cannot apply to subtype", Id
);
781 elsif A_Id
= Aspect_Default_Value
782 and then not Is_Scalar_Type
(Ent
)
784 Error_Msg_N
("aspect% can only be applied to scalar type", Id
);
787 elsif A_Id
= Aspect_Default_Component_Value
then
788 if not Is_Array_Type
(Ent
) then
789 Error_Msg_N
("aspect% can only be applied to array type", Id
);
792 elsif not Is_Scalar_Type
(Component_Type
(Ent
)) then
793 Error_Msg_N
("aspect% requires scalar components", Id
);
798 Set_Has_Default_Aspect
(Base_Type
(Ent
));
800 if Is_Scalar_Type
(Ent
) then
801 Set_Default_Aspect_Value
(Base_Type
(Ent
), Expr
);
803 Set_Default_Aspect_Component_Value
(Base_Type
(Ent
), Expr
);
805 end Analyze_Aspect_Default_Value
;
807 ---------------------------------
808 -- Inherit_Delayed_Rep_Aspects --
809 ---------------------------------
811 procedure Inherit_Delayed_Rep_Aspects
(ASN
: Node_Id
) is
812 P
: constant Entity_Id
:= Entity
(ASN
);
813 -- Entithy for parent type
816 -- Item from Rep_Item chain
821 -- Loop through delayed aspects for the parent type
824 while Present
(N
) loop
825 if Nkind
(N
) = N_Aspect_Specification
then
826 exit when Entity
(N
) /= P
;
828 if Is_Delayed_Aspect
(N
) then
829 A
:= Get_Aspect_Id
(Chars
(Identifier
(N
)));
831 -- Process delayed rep aspect. For Boolean attributes it is
832 -- not possible to cancel an attribute once set (the attempt
833 -- to use an aspect with xxx => False is an error) for a
834 -- derived type. So for those cases, we do not have to check
835 -- if a clause has been given for the derived type, since it
836 -- is harmless to set it again if it is already set.
842 when Aspect_Alignment
=>
843 if not Has_Alignment_Clause
(E
) then
844 Set_Alignment
(E
, Alignment
(P
));
849 when Aspect_Atomic
=>
850 if Is_Atomic
(P
) then
856 when Aspect_Atomic_Components
=>
857 if Has_Atomic_Components
(P
) then
858 Set_Has_Atomic_Components
(Base_Type
(E
));
863 when Aspect_Bit_Order
=>
864 if Is_Record_Type
(E
)
865 and then No
(Get_Attribute_Definition_Clause
866 (E
, Attribute_Bit_Order
))
867 and then Reverse_Bit_Order
(P
)
869 Set_Reverse_Bit_Order
(Base_Type
(E
));
874 when Aspect_Component_Size
=>
876 and then not Has_Component_Size_Clause
(E
)
879 (Base_Type
(E
), Component_Size
(P
));
884 when Aspect_Machine_Radix
=>
885 if Is_Decimal_Fixed_Point_Type
(E
)
886 and then not Has_Machine_Radix_Clause
(E
)
888 Set_Machine_Radix_10
(E
, Machine_Radix_10
(P
));
891 -- Object_Size (also Size which also sets Object_Size)
893 when Aspect_Object_Size | Aspect_Size
=>
894 if not Has_Size_Clause
(E
)
896 No
(Get_Attribute_Definition_Clause
897 (E
, Attribute_Object_Size
))
899 Set_Esize
(E
, Esize
(P
));
905 if not Is_Packed
(E
) then
906 Set_Is_Packed
(Base_Type
(E
));
908 if Is_Bit_Packed_Array
(P
) then
909 Set_Is_Bit_Packed_Array
(Base_Type
(E
));
910 Set_Packed_Array_Impl_Type
911 (E
, Packed_Array_Impl_Type
(P
));
915 -- Scalar_Storage_Order
917 when Aspect_Scalar_Storage_Order
=>
918 if (Is_Record_Type
(E
) or else Is_Array_Type
(E
))
919 and then No
(Get_Attribute_Definition_Clause
920 (E
, Attribute_Scalar_Storage_Order
))
921 and then Reverse_Storage_Order
(P
)
923 Set_Reverse_Storage_Order
(Base_Type
(E
));
925 -- Clear default SSO indications, since the aspect
926 -- overrides the default.
928 Set_SSO_Set_Low_By_Default
(Base_Type
(E
), False);
929 Set_SSO_Set_High_By_Default
(Base_Type
(E
), False);
935 if Is_Fixed_Point_Type
(E
)
936 and then not Has_Small_Clause
(E
)
938 Set_Small_Value
(E
, Small_Value
(P
));
943 when Aspect_Storage_Size
=>
944 if (Is_Access_Type
(E
) or else Is_Task_Type
(E
))
945 and then not Has_Storage_Size_Clause
(E
)
947 Set_Storage_Size_Variable
948 (Base_Type
(E
), Storage_Size_Variable
(P
));
953 when Aspect_Value_Size
=>
955 -- Value_Size is never inherited, it is either set by
956 -- default, or it is explicitly set for the derived
957 -- type. So nothing to do here.
963 when Aspect_Volatile
=>
964 if Is_Volatile
(P
) then
968 -- Volatile_Components
970 when Aspect_Volatile_Components
=>
971 if Has_Volatile_Components
(P
) then
972 Set_Has_Volatile_Components
(Base_Type
(E
));
975 -- That should be all the Rep Aspects
978 pragma Assert
(Aspect_Delay
(A_Id
) /= Rep_Aspect
);
985 N
:= Next_Rep_Item
(N
);
987 end Inherit_Delayed_Rep_Aspects
;
989 -------------------------------------
990 -- Make_Pragma_From_Boolean_Aspect --
991 -------------------------------------
993 procedure Make_Pragma_From_Boolean_Aspect
(ASN
: Node_Id
) is
994 Ident
: constant Node_Id
:= Identifier
(ASN
);
995 A_Name
: constant Name_Id
:= Chars
(Ident
);
996 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(A_Name
);
997 Ent
: constant Entity_Id
:= Entity
(ASN
);
998 Expr
: constant Node_Id
:= Expression
(ASN
);
999 Loc
: constant Source_Ptr
:= Sloc
(ASN
);
1003 procedure Check_False_Aspect_For_Derived_Type
;
1004 -- This procedure checks for the case of a false aspect for a derived
1005 -- type, which improperly tries to cancel an aspect inherited from
1008 -----------------------------------------
1009 -- Check_False_Aspect_For_Derived_Type --
1010 -----------------------------------------
1012 procedure Check_False_Aspect_For_Derived_Type
is
1016 -- We are only checking derived types
1018 if not Is_Derived_Type
(E
) then
1022 Par
:= Nearest_Ancestor
(E
);
1025 when Aspect_Atomic | Aspect_Shared
=>
1026 if not Is_Atomic
(Par
) then
1030 when Aspect_Atomic_Components
=>
1031 if not Has_Atomic_Components
(Par
) then
1035 when Aspect_Discard_Names
=>
1036 if not Discard_Names
(Par
) then
1041 if not Is_Packed
(Par
) then
1045 when Aspect_Unchecked_Union
=>
1046 if not Is_Unchecked_Union
(Par
) then
1050 when Aspect_Volatile
=>
1051 if not Is_Volatile
(Par
) then
1055 when Aspect_Volatile_Components
=>
1056 if not Has_Volatile_Components
(Par
) then
1064 -- Fall through means we are canceling an inherited aspect
1066 Error_Msg_Name_1
:= A_Name
;
1068 ("derived type& inherits aspect%, cannot cancel", Expr
, E
);
1070 end Check_False_Aspect_For_Derived_Type
;
1072 -- Start of processing for Make_Pragma_From_Boolean_Aspect
1075 -- Note that we know Expr is present, because for a missing Expr
1076 -- argument, we knew it was True and did not need to delay the
1077 -- evaluation to the freeze point.
1079 if Is_False
(Static_Boolean
(Expr
)) then
1080 Check_False_Aspect_For_Derived_Type
;
1085 Pragma_Argument_Associations
=> New_List
(
1086 Make_Pragma_Argument_Association
(Sloc
(Ident
),
1087 Expression
=> New_Occurrence_Of
(Ent
, Sloc
(Ident
)))),
1089 Pragma_Identifier
=>
1090 Make_Identifier
(Sloc
(Ident
), Chars
(Ident
)));
1092 Set_From_Aspect_Specification
(Prag
, True);
1093 Set_Corresponding_Aspect
(Prag
, ASN
);
1094 Set_Aspect_Rep_Item
(ASN
, Prag
);
1095 Set_Is_Delayed_Aspect
(Prag
);
1096 Set_Parent
(Prag
, ASN
);
1098 end Make_Pragma_From_Boolean_Aspect
;
1100 -- Start of processing for Analyze_Aspects_At_Freeze_Point
1103 -- Must be visible in current scope
1105 if not Scope_Within_Or_Same
(Current_Scope
, Scope
(E
)) then
1109 -- Look for aspect specification entries for this entity
1111 ASN
:= First_Rep_Item
(E
);
1112 while Present
(ASN
) loop
1113 if Nkind
(ASN
) = N_Aspect_Specification
then
1114 exit when Entity
(ASN
) /= E
;
1116 if Is_Delayed_Aspect
(ASN
) then
1117 A_Id
:= Get_Aspect_Id
(ASN
);
1121 -- For aspects whose expression is an optional Boolean, make
1122 -- the corresponding pragma at the freeze point.
1124 when Boolean_Aspects |
1125 Library_Unit_Aspects
=>
1126 Make_Pragma_From_Boolean_Aspect
(ASN
);
1128 -- Special handling for aspects that don't correspond to
1129 -- pragmas/attributes.
1131 when Aspect_Default_Value |
1132 Aspect_Default_Component_Value
=>
1134 -- Do not inherit aspect for anonymous base type of a
1135 -- scalar or array type, because they apply to the first
1136 -- subtype of the type, and will be processed when that
1137 -- first subtype is frozen.
1139 if Is_Derived_Type
(E
)
1140 and then not Comes_From_Source
(E
)
1141 and then E
/= First_Subtype
(E
)
1145 Analyze_Aspect_Default_Value
(ASN
);
1148 -- Ditto for iterator aspects, because the corresponding
1149 -- attributes may not have been analyzed yet.
1151 when Aspect_Constant_Indexing |
1152 Aspect_Variable_Indexing |
1153 Aspect_Default_Iterator |
1154 Aspect_Iterator_Element
=>
1155 Analyze
(Expression
(ASN
));
1157 if Etype
(Expression
(ASN
)) = Any_Type
then
1159 ("\aspect must be fully defined before & is frozen",
1163 when Aspect_Iterable
=>
1164 Validate_Iterable_Aspect
(E
, ASN
);
1170 Ritem
:= Aspect_Rep_Item
(ASN
);
1172 if Present
(Ritem
) then
1178 Next_Rep_Item
(ASN
);
1181 -- This is where we inherit delayed rep aspects from our parent. Note
1182 -- that if we fell out of the above loop with ASN non-empty, it means
1183 -- we hit an aspect for an entity other than E, and it must be the
1184 -- type from which we were derived.
1186 if May_Inherit_Delayed_Rep_Aspects
(E
) then
1187 Inherit_Delayed_Rep_Aspects
(ASN
);
1189 end Analyze_Aspects_At_Freeze_Point
;
1191 -----------------------------------
1192 -- Analyze_Aspect_Specifications --
1193 -----------------------------------
1195 procedure Analyze_Aspect_Specifications
(N
: Node_Id
; E
: Entity_Id
) is
1196 procedure Decorate
(Asp
: Node_Id
; Prag
: Node_Id
);
1197 -- Establish linkages between an aspect and its corresponding
1200 procedure Insert_After_SPARK_Mode
1204 -- Subsidiary to the analysis of aspects Abstract_State, Ghost,
1205 -- Initializes, Initial_Condition and Refined_State. Insert node Prag
1206 -- before node Ins_Nod. If Ins_Nod is for pragma SPARK_Mode, then skip
1207 -- SPARK_Mode. Decls is the associated declarative list where Prag is to
1210 procedure Insert_Pragma
(Prag
: Node_Id
);
1211 -- Subsidiary to the analysis of aspects Attach_Handler, Contract_Cases,
1212 -- Depends, Global, Post, Pre, Refined_Depends and Refined_Global.
1213 -- Insert pragma Prag such that it mimics the placement of a source
1214 -- pragma of the same kind.
1216 -- procedure Proc (Formal : ...) with Global => ...;
1218 -- procedure Proc (Formal : ...);
1219 -- pragma Global (...);
1225 procedure Decorate
(Asp
: Node_Id
; Prag
: Node_Id
) is
1227 Set_Aspect_Rep_Item
(Asp
, Prag
);
1228 Set_Corresponding_Aspect
(Prag
, Asp
);
1229 Set_From_Aspect_Specification
(Prag
);
1230 Set_Parent
(Prag
, Asp
);
1233 -----------------------------
1234 -- Insert_After_SPARK_Mode --
1235 -----------------------------
1237 procedure Insert_After_SPARK_Mode
1242 Decl
: Node_Id
:= Ins_Nod
;
1248 and then Nkind
(Decl
) = N_Pragma
1249 and then Pragma_Name
(Decl
) = Name_SPARK_Mode
1251 Decl
:= Next
(Decl
);
1254 if Present
(Decl
) then
1255 Insert_Before
(Decl
, Prag
);
1257 -- Aitem acts as the last declaration
1260 Append_To
(Decls
, Prag
);
1262 end Insert_After_SPARK_Mode
;
1268 procedure Insert_Pragma
(Prag
: Node_Id
) is
1273 if Nkind
(N
) = N_Subprogram_Body
then
1274 if Present
(Declarations
(N
)) then
1276 -- Skip other internally generated pragmas from aspects to find
1277 -- the proper insertion point. As a result the order of pragmas
1278 -- is the same as the order of aspects.
1280 -- As precondition pragmas generated from conjuncts in the
1281 -- precondition aspect are presented in reverse order to
1282 -- Insert_Pragma, insert them in the correct order here by not
1283 -- skipping previously inserted precondition pragmas when the
1284 -- current pragma is a precondition.
1286 Decl
:= First
(Declarations
(N
));
1287 while Present
(Decl
) loop
1288 if Nkind
(Decl
) = N_Pragma
1289 and then From_Aspect_Specification
(Decl
)
1290 and then not (Get_Pragma_Id
(Decl
) = Pragma_Precondition
1292 Get_Pragma_Id
(Prag
) = Pragma_Precondition
)
1300 if Present
(Decl
) then
1301 Insert_Before
(Decl
, Prag
);
1303 Append
(Prag
, Declarations
(N
));
1306 Set_Declarations
(N
, New_List
(Prag
));
1309 -- When the context is a library unit, the pragma is added to the
1310 -- Pragmas_After list.
1312 elsif Nkind
(Parent
(N
)) = N_Compilation_Unit
then
1313 Aux
:= Aux_Decls_Node
(Parent
(N
));
1315 if No
(Pragmas_After
(Aux
)) then
1316 Set_Pragmas_After
(Aux
, New_List
);
1319 Prepend
(Prag
, Pragmas_After
(Aux
));
1324 Insert_After
(N
, Prag
);
1334 L
: constant List_Id
:= Aspect_Specifications
(N
);
1336 Ins_Node
: Node_Id
:= N
;
1337 -- Insert pragmas/attribute definition clause after this node when no
1338 -- delayed analysis is required.
1340 -- Start of processing for Analyze_Aspect_Specifications
1342 -- The general processing involves building an attribute definition
1343 -- clause or a pragma node that corresponds to the aspect. Then in order
1344 -- to delay the evaluation of this aspect to the freeze point, we attach
1345 -- the corresponding pragma/attribute definition clause to the aspect
1346 -- specification node, which is then placed in the Rep Item chain. In
1347 -- this case we mark the entity by setting the flag Has_Delayed_Aspects
1348 -- and we evaluate the rep item at the freeze point. When the aspect
1349 -- doesn't have a corresponding pragma/attribute definition clause, then
1350 -- its analysis is simply delayed at the freeze point.
1352 -- Some special cases don't require delay analysis, thus the aspect is
1353 -- analyzed right now.
1355 -- Note that there is a special handling for Pre, Post, Test_Case,
1356 -- Contract_Cases aspects. In these cases, we do not have to worry
1357 -- about delay issues, since the pragmas themselves deal with delay
1358 -- of visibility for the expression analysis. Thus, we just insert
1359 -- the pragma after the node N.
1362 pragma Assert
(Present
(L
));
1364 -- Loop through aspects
1366 Aspect
:= First
(L
);
1367 Aspect_Loop
: while Present
(Aspect
) loop
1368 Analyze_One_Aspect
: declare
1369 Expr
: constant Node_Id
:= Expression
(Aspect
);
1370 Id
: constant Node_Id
:= Identifier
(Aspect
);
1371 Loc
: constant Source_Ptr
:= Sloc
(Aspect
);
1372 Nam
: constant Name_Id
:= Chars
(Id
);
1373 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Nam
);
1376 Delay_Required
: Boolean;
1377 -- Set False if delay is not required
1379 Eloc
: Source_Ptr
:= No_Location
;
1380 -- Source location of expression, modified when we split PPC's. It
1381 -- is set below when Expr is present.
1383 procedure Analyze_Aspect_External_Or_Link_Name
;
1384 -- Perform analysis of the External_Name or Link_Name aspects
1386 procedure Analyze_Aspect_Implicit_Dereference
;
1387 -- Perform analysis of the Implicit_Dereference aspects
1389 procedure Make_Aitem_Pragma
1390 (Pragma_Argument_Associations
: List_Id
;
1391 Pragma_Name
: Name_Id
);
1392 -- This is a wrapper for Make_Pragma used for converting aspects
1393 -- to pragmas. It takes care of Sloc (set from Loc) and building
1394 -- the pragma identifier from the given name. In addition the
1395 -- flags Class_Present and Split_PPC are set from the aspect
1396 -- node, as well as Is_Ignored. This routine also sets the
1397 -- From_Aspect_Specification in the resulting pragma node to
1398 -- True, and sets Corresponding_Aspect to point to the aspect.
1399 -- The resulting pragma is assigned to Aitem.
1401 ------------------------------------------
1402 -- Analyze_Aspect_External_Or_Link_Name --
1403 ------------------------------------------
1405 procedure Analyze_Aspect_External_Or_Link_Name
is
1407 -- Verify that there is an Import/Export aspect defined for the
1408 -- entity. The processing of that aspect in turn checks that
1409 -- there is a Convention aspect declared. The pragma is
1410 -- constructed when processing the Convention aspect.
1417 while Present
(A
) loop
1418 exit when Nam_In
(Chars
(Identifier
(A
)), Name_Export
,
1425 ("missing Import/Export for Link/External name",
1429 end Analyze_Aspect_External_Or_Link_Name
;
1431 -----------------------------------------
1432 -- Analyze_Aspect_Implicit_Dereference --
1433 -----------------------------------------
1435 procedure Analyze_Aspect_Implicit_Dereference
is
1437 if not Is_Type
(E
) or else not Has_Discriminants
(E
) then
1439 ("aspect must apply to a type with discriminants", N
);
1446 Disc
:= First_Discriminant
(E
);
1447 while Present
(Disc
) loop
1448 if Chars
(Expr
) = Chars
(Disc
)
1449 and then Ekind
(Etype
(Disc
)) =
1450 E_Anonymous_Access_Type
1452 Set_Has_Implicit_Dereference
(E
);
1453 Set_Has_Implicit_Dereference
(Disc
);
1457 Next_Discriminant
(Disc
);
1460 -- Error if no proper access discriminant.
1463 ("not an access discriminant of&", Expr
, E
);
1466 end Analyze_Aspect_Implicit_Dereference
;
1468 -----------------------
1469 -- Make_Aitem_Pragma --
1470 -----------------------
1472 procedure Make_Aitem_Pragma
1473 (Pragma_Argument_Associations
: List_Id
;
1474 Pragma_Name
: Name_Id
)
1476 Args
: List_Id
:= Pragma_Argument_Associations
;
1479 -- We should never get here if aspect was disabled
1481 pragma Assert
(not Is_Disabled
(Aspect
));
1483 -- Certain aspects allow for an optional name or expression. Do
1484 -- not generate a pragma with empty argument association list.
1486 if No
(Args
) or else No
(Expression
(First
(Args
))) then
1494 Pragma_Argument_Associations
=> Args
,
1495 Pragma_Identifier
=>
1496 Make_Identifier
(Sloc
(Id
), Pragma_Name
),
1497 Class_Present
=> Class_Present
(Aspect
),
1498 Split_PPC
=> Split_PPC
(Aspect
));
1500 -- Set additional semantic fields
1502 if Is_Ignored
(Aspect
) then
1503 Set_Is_Ignored
(Aitem
);
1504 elsif Is_Checked
(Aspect
) then
1505 Set_Is_Checked
(Aitem
);
1508 Set_Corresponding_Aspect
(Aitem
, Aspect
);
1509 Set_From_Aspect_Specification
(Aitem
, True);
1510 end Make_Aitem_Pragma
;
1512 -- Start of processing for Analyze_One_Aspect
1515 -- Skip aspect if already analyzed, to avoid looping in some cases
1517 if Analyzed
(Aspect
) then
1521 -- Skip looking at aspect if it is totally disabled. Just mark it
1522 -- as such for later reference in the tree. This also sets the
1523 -- Is_Ignored and Is_Checked flags appropriately.
1525 Check_Applicable_Policy
(Aspect
);
1527 if Is_Disabled
(Aspect
) then
1531 -- Set the source location of expression, used in the case of
1532 -- a failed precondition/postcondition or invariant. Note that
1533 -- the source location of the expression is not usually the best
1534 -- choice here. For example, it gets located on the last AND
1535 -- keyword in a chain of boolean expressiond AND'ed together.
1536 -- It is best to put the message on the first character of the
1537 -- assertion, which is the effect of the First_Node call here.
1539 if Present
(Expr
) then
1540 Eloc
:= Sloc
(First_Node
(Expr
));
1543 -- Check restriction No_Implementation_Aspect_Specifications
1545 if Implementation_Defined_Aspect
(A_Id
) then
1547 (No_Implementation_Aspect_Specifications
, Aspect
);
1550 -- Check restriction No_Specification_Of_Aspect
1552 Check_Restriction_No_Specification_Of_Aspect
(Aspect
);
1554 -- Mark aspect analyzed (actual analysis is delayed till later)
1556 Set_Analyzed
(Aspect
);
1557 Set_Entity
(Aspect
, E
);
1558 Ent
:= New_Occurrence_Of
(E
, Sloc
(Id
));
1560 -- Check for duplicate aspect. Note that the Comes_From_Source
1561 -- test allows duplicate Pre/Post's that we generate internally
1562 -- to escape being flagged here.
1564 if No_Duplicates_Allowed
(A_Id
) then
1566 while Anod
/= Aspect
loop
1567 if Comes_From_Source
(Aspect
)
1568 and then Same_Aspect
(A_Id
, Get_Aspect_Id
(Anod
))
1570 Error_Msg_Name_1
:= Nam
;
1571 Error_Msg_Sloc
:= Sloc
(Anod
);
1573 -- Case of same aspect specified twice
1575 if Class_Present
(Anod
) = Class_Present
(Aspect
) then
1576 if not Class_Present
(Anod
) then
1578 ("aspect% for & previously given#",
1582 ("aspect `%''Class` for & previously given#",
1592 -- Check some general restrictions on language defined aspects
1594 if not Implementation_Defined_Aspect
(A_Id
) then
1595 Error_Msg_Name_1
:= Nam
;
1597 -- Not allowed for renaming declarations
1599 if Nkind
(N
) in N_Renaming_Declaration
then
1601 ("aspect % not allowed for renaming declaration",
1605 -- Not allowed for formal type declarations
1607 if Nkind
(N
) = N_Formal_Type_Declaration
then
1609 ("aspect % not allowed for formal type declaration",
1614 -- Copy expression for later processing by the procedures
1615 -- Check_Aspect_At_[Freeze_Point | End_Of_Declarations]
1617 Set_Entity
(Id
, New_Copy_Tree
(Expr
));
1619 -- Set Delay_Required as appropriate to aspect
1621 case Aspect_Delay
(A_Id
) is
1622 when Always_Delay
=>
1623 Delay_Required
:= True;
1626 Delay_Required
:= False;
1630 -- If expression has the form of an integer literal, then
1631 -- do not delay, since we know the value cannot change.
1632 -- This optimization catches most rep clause cases.
1634 -- For Boolean aspects, don't delay if no expression
1636 if A_Id
in Boolean_Aspects
and then No
(Expr
) then
1637 Delay_Required
:= False;
1639 -- For non-Boolean aspects, don't delay if integer literal
1641 elsif A_Id
not in Boolean_Aspects
1642 and then Present
(Expr
)
1643 and then Nkind
(Expr
) = N_Integer_Literal
1645 Delay_Required
:= False;
1647 -- All other cases are delayed
1650 Delay_Required
:= True;
1651 Set_Has_Delayed_Rep_Aspects
(E
);
1655 -- Processing based on specific aspect
1658 when Aspect_Unimplemented
=>
1659 null; -- ??? temp for now
1661 -- No_Aspect should be impossible
1664 raise Program_Error
;
1666 -- Case 1: Aspects corresponding to attribute definition
1669 when Aspect_Address |
1672 Aspect_Component_Size |
1673 Aspect_Constant_Indexing |
1674 Aspect_Default_Iterator |
1675 Aspect_Dispatching_Domain |
1676 Aspect_External_Tag |
1679 Aspect_Iterator_Element |
1680 Aspect_Machine_Radix |
1681 Aspect_Object_Size |
1684 Aspect_Scalar_Storage_Order |
1687 Aspect_Simple_Storage_Pool |
1688 Aspect_Storage_Pool |
1689 Aspect_Stream_Size |
1691 Aspect_Variable_Indexing |
1694 -- Indexing aspects apply only to tagged type
1696 if (A_Id
= Aspect_Constant_Indexing
1698 A_Id
= Aspect_Variable_Indexing
)
1699 and then not (Is_Type
(E
)
1700 and then Is_Tagged_Type
(E
))
1703 ("indexing aspect can only apply to a tagged type",
1708 -- For the case of aspect Address, we don't consider that we
1709 -- know the entity is never set in the source, since it is
1710 -- is likely aliasing is occurring.
1712 -- Note: one might think that the analysis of the resulting
1713 -- attribute definition clause would take care of that, but
1714 -- that's not the case since it won't be from source.
1716 if A_Id
= Aspect_Address
then
1717 Set_Never_Set_In_Source
(E
, False);
1720 -- Correctness of the profile of a stream operation is
1721 -- verified at the freeze point, but we must detect the
1722 -- illegal specification of this aspect for a subtype now,
1723 -- to prevent malformed rep_item chains.
1725 if A_Id
= Aspect_Input
or else
1726 A_Id
= Aspect_Output
or else
1727 A_Id
= Aspect_Read
or else
1730 if not Is_First_Subtype
(E
) then
1732 ("local name must be a first subtype", Aspect
);
1735 -- If stream aspect applies to the class-wide type,
1736 -- the generated attribute definition applies to the
1737 -- class-wide type as well.
1739 elsif Class_Present
(Aspect
) then
1741 Make_Attribute_Reference
(Loc
,
1743 Attribute_Name
=> Name_Class
);
1747 -- Construct the attribute definition clause
1750 Make_Attribute_Definition_Clause
(Loc
,
1752 Chars
=> Chars
(Id
),
1753 Expression
=> Relocate_Node
(Expr
));
1755 -- If the address is specified, then we treat the entity as
1756 -- referenced, to avoid spurious warnings. This is analogous
1757 -- to what is done with an attribute definition clause, but
1758 -- here we don't want to generate a reference because this
1759 -- is the point of definition of the entity.
1761 if A_Id
= Aspect_Address
then
1765 -- Case 2: Aspects corresponding to pragmas
1767 -- Case 2a: Aspects corresponding to pragmas with two
1768 -- arguments, where the first argument is a local name
1769 -- referring to the entity, and the second argument is the
1770 -- aspect definition expression.
1772 -- Linker_Section/Suppress/Unsuppress
1774 when Aspect_Linker_Section |
1776 Aspect_Unsuppress
=>
1779 (Pragma_Argument_Associations
=> New_List
(
1780 Make_Pragma_Argument_Association
(Loc
,
1781 Expression
=> New_Occurrence_Of
(E
, Loc
)),
1782 Make_Pragma_Argument_Association
(Sloc
(Expr
),
1783 Expression
=> Relocate_Node
(Expr
))),
1784 Pragma_Name
=> Chars
(Id
));
1788 -- Corresponds to pragma Implemented, construct the pragma
1790 when Aspect_Synchronization
=>
1792 (Pragma_Argument_Associations
=> New_List
(
1793 Make_Pragma_Argument_Association
(Loc
,
1794 Expression
=> New_Occurrence_Of
(E
, Loc
)),
1795 Make_Pragma_Argument_Association
(Sloc
(Expr
),
1796 Expression
=> Relocate_Node
(Expr
))),
1797 Pragma_Name
=> Name_Implemented
);
1801 when Aspect_Attach_Handler
=>
1803 (Pragma_Argument_Associations
=> New_List
(
1804 Make_Pragma_Argument_Association
(Sloc
(Ent
),
1806 Make_Pragma_Argument_Association
(Sloc
(Expr
),
1807 Expression
=> Relocate_Node
(Expr
))),
1808 Pragma_Name
=> Name_Attach_Handler
);
1810 -- We need to insert this pragma into the tree to get proper
1811 -- processing and to look valid from a placement viewpoint.
1813 Insert_Pragma
(Aitem
);
1816 -- Dynamic_Predicate, Predicate, Static_Predicate
1818 when Aspect_Dynamic_Predicate |
1820 Aspect_Static_Predicate
=>
1822 -- These aspects apply only to subtypes
1824 if not Is_Type
(E
) then
1826 ("predicate can only be specified for a subtype",
1830 elsif Is_Incomplete_Type
(E
) then
1832 ("predicate cannot apply to incomplete view", Aspect
);
1836 -- Construct the pragma (always a pragma Predicate, with
1837 -- flags recording whether it is static/dynamic). We also
1838 -- set flags recording this in the type itself.
1841 (Pragma_Argument_Associations
=> New_List
(
1842 Make_Pragma_Argument_Association
(Sloc
(Ent
),
1844 Make_Pragma_Argument_Association
(Sloc
(Expr
),
1845 Expression
=> Relocate_Node
(Expr
))),
1846 Pragma_Name
=> Name_Predicate
);
1848 -- Mark type has predicates, and remember what kind of
1849 -- aspect lead to this predicate (we need this to access
1850 -- the right set of check policies later on).
1852 Set_Has_Predicates
(E
);
1854 if A_Id
= Aspect_Dynamic_Predicate
then
1855 Set_Has_Dynamic_Predicate_Aspect
(E
);
1856 elsif A_Id
= Aspect_Static_Predicate
then
1857 Set_Has_Static_Predicate_Aspect
(E
);
1860 -- If the type is private, indicate that its completion
1861 -- has a freeze node, because that is the one that will
1862 -- be visible at freeze time.
1864 if Is_Private_Type
(E
) and then Present
(Full_View
(E
)) then
1865 Set_Has_Predicates
(Full_View
(E
));
1867 if A_Id
= Aspect_Dynamic_Predicate
then
1868 Set_Has_Dynamic_Predicate_Aspect
(Full_View
(E
));
1869 elsif A_Id
= Aspect_Static_Predicate
then
1870 Set_Has_Static_Predicate_Aspect
(Full_View
(E
));
1873 Set_Has_Delayed_Aspects
(Full_View
(E
));
1874 Ensure_Freeze_Node
(Full_View
(E
));
1877 -- Case 2b: Aspects corresponding to pragmas with two
1878 -- arguments, where the second argument is a local name
1879 -- referring to the entity, and the first argument is the
1880 -- aspect definition expression.
1884 when Aspect_Convention
=>
1886 -- The aspect may be part of the specification of an import
1887 -- or export pragma. Scan the aspect list to gather the
1888 -- other components, if any. The name of the generated
1889 -- pragma is one of Convention/Import/Export.
1892 Args
: constant List_Id
:= New_List
(
1893 Make_Pragma_Argument_Association
(Sloc
(Expr
),
1894 Expression
=> Relocate_Node
(Expr
)),
1895 Make_Pragma_Argument_Association
(Sloc
(Ent
),
1896 Expression
=> Ent
));
1898 Imp_Exp_Seen
: Boolean := False;
1899 -- Flag set when aspect Import or Export has been seen
1901 Imp_Seen
: Boolean := False;
1902 -- Flag set when aspect Import has been seen
1906 Extern_Arg
: Node_Id
;
1911 Extern_Arg
:= Empty
;
1913 Prag_Nam
:= Chars
(Id
);
1916 while Present
(Asp
) loop
1917 Asp_Nam
:= Chars
(Identifier
(Asp
));
1919 -- Aspects Import and Export take precedence over
1920 -- aspect Convention. As a result the generated pragma
1921 -- must carry the proper interfacing aspect's name.
1923 if Nam_In
(Asp_Nam
, Name_Import
, Name_Export
) then
1924 if Imp_Exp_Seen
then
1925 Error_Msg_N
("conflicting", Asp
);
1927 Imp_Exp_Seen
:= True;
1929 if Asp_Nam
= Name_Import
then
1934 Prag_Nam
:= Asp_Nam
;
1936 -- Aspect External_Name adds an extra argument to the
1937 -- generated pragma.
1939 elsif Asp_Nam
= Name_External_Name
then
1941 Make_Pragma_Argument_Association
(Loc
,
1943 Expression
=> Relocate_Node
(Expression
(Asp
)));
1945 -- Aspect Link_Name adds an extra argument to the
1946 -- generated pragma.
1948 elsif Asp_Nam
= Name_Link_Name
then
1950 Make_Pragma_Argument_Association
(Loc
,
1952 Expression
=> Relocate_Node
(Expression
(Asp
)));
1958 -- Assemble the full argument list
1960 if Present
(Extern_Arg
) then
1961 Append_To
(Args
, Extern_Arg
);
1964 if Present
(Link_Arg
) then
1965 Append_To
(Args
, Link_Arg
);
1969 (Pragma_Argument_Associations
=> Args
,
1970 Pragma_Name
=> Prag_Nam
);
1972 -- Store the generated pragma Import in the related
1975 if Imp_Seen
and then Is_Subprogram
(E
) then
1976 Set_Import_Pragma
(E
, Aitem
);
1980 -- CPU, Interrupt_Priority, Priority
1982 -- These three aspects can be specified for a subprogram spec
1983 -- or body, in which case we analyze the expression and export
1984 -- the value of the aspect.
1986 -- Previously, we generated an equivalent pragma for bodies
1987 -- (note that the specs cannot contain these pragmas). The
1988 -- pragma was inserted ahead of local declarations, rather than
1989 -- after the body. This leads to a certain duplication between
1990 -- the processing performed for the aspect and the pragma, but
1991 -- given the straightforward handling required it is simpler
1992 -- to duplicate than to translate the aspect in the spec into
1993 -- a pragma in the declarative part of the body.
1996 Aspect_Interrupt_Priority |
1999 if Nkind_In
(N
, N_Subprogram_Body
,
2000 N_Subprogram_Declaration
)
2002 -- Analyze the aspect expression
2004 Analyze_And_Resolve
(Expr
, Standard_Integer
);
2006 -- Interrupt_Priority aspect not allowed for main
2007 -- subprograms. ARM D.1 does not forbid this explicitly,
2008 -- but ARM J.15.11 (6/3) does not permit pragma
2009 -- Interrupt_Priority for subprograms.
2011 if A_Id
= Aspect_Interrupt_Priority
then
2013 ("Interrupt_Priority aspect cannot apply to "
2014 & "subprogram", Expr
);
2016 -- The expression must be static
2018 elsif not Is_OK_Static_Expression
(Expr
) then
2019 Flag_Non_Static_Expr
2020 ("aspect requires static expression!", Expr
);
2022 -- Check whether this is the main subprogram. Issue a
2023 -- warning only if it is obviously not a main program
2024 -- (when it has parameters or when the subprogram is
2025 -- within a package).
2027 elsif Present
(Parameter_Specifications
2028 (Specification
(N
)))
2029 or else not Is_Compilation_Unit
(Defining_Entity
(N
))
2031 -- See ARM D.1 (14/3) and D.16 (12/3)
2034 ("aspect applied to subprogram other than the "
2035 & "main subprogram has no effect??", Expr
);
2037 -- Otherwise check in range and export the value
2039 -- For the CPU aspect
2041 elsif A_Id
= Aspect_CPU
then
2042 if Is_In_Range
(Expr
, RTE
(RE_CPU_Range
)) then
2044 -- Value is correct so we export the value to make
2045 -- it available at execution time.
2048 (Main_Unit
, UI_To_Int
(Expr_Value
(Expr
)));
2052 ("main subprogram CPU is out of range", Expr
);
2055 -- For the Priority aspect
2057 elsif A_Id
= Aspect_Priority
then
2058 if Is_In_Range
(Expr
, RTE
(RE_Priority
)) then
2060 -- Value is correct so we export the value to make
2061 -- it available at execution time.
2064 (Main_Unit
, UI_To_Int
(Expr_Value
(Expr
)));
2066 -- Ignore pragma if Relaxed_RM_Semantics to support
2067 -- other targets/non GNAT compilers.
2069 elsif not Relaxed_RM_Semantics
then
2071 ("main subprogram priority is out of range",
2076 -- Load an arbitrary entity from System.Tasking.Stages
2077 -- or System.Tasking.Restricted.Stages (depending on
2078 -- the supported profile) to make sure that one of these
2079 -- packages is implicitly with'ed, since we need to have
2080 -- the tasking run time active for the pragma Priority to
2081 -- have any effect. Previously we with'ed the package
2082 -- System.Tasking, but this package does not trigger the
2083 -- required initialization of the run-time library.
2086 Discard
: Entity_Id
;
2088 if Restricted_Profile
then
2089 Discard
:= RTE
(RE_Activate_Restricted_Tasks
);
2091 Discard
:= RTE
(RE_Activate_Tasks
);
2095 -- Handling for these Aspects in subprograms is complete
2102 -- Pass the aspect as an attribute
2105 Make_Attribute_Definition_Clause
(Loc
,
2107 Chars
=> Chars
(Id
),
2108 Expression
=> Relocate_Node
(Expr
));
2113 when Aspect_Warnings
=>
2115 (Pragma_Argument_Associations
=> New_List
(
2116 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2117 Expression
=> Relocate_Node
(Expr
)),
2118 Make_Pragma_Argument_Association
(Loc
,
2119 Expression
=> New_Occurrence_Of
(E
, Loc
))),
2120 Pragma_Name
=> Chars
(Id
));
2122 -- Case 2c: Aspects corresponding to pragmas with three
2125 -- Invariant aspects have a first argument that references the
2126 -- entity, a second argument that is the expression and a third
2127 -- argument that is an appropriate message.
2129 -- Invariant, Type_Invariant
2131 when Aspect_Invariant |
2132 Aspect_Type_Invariant
=>
2134 -- Analysis of the pragma will verify placement legality:
2135 -- an invariant must apply to a private type, or appear in
2136 -- the private part of a spec and apply to a completion.
2139 (Pragma_Argument_Associations
=> New_List
(
2140 Make_Pragma_Argument_Association
(Sloc
(Ent
),
2142 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2143 Expression
=> Relocate_Node
(Expr
))),
2144 Pragma_Name
=> Name_Invariant
);
2146 -- Add message unless exception messages are suppressed
2148 if not Opt
.Exception_Locations_Suppressed
then
2149 Append_To
(Pragma_Argument_Associations
(Aitem
),
2150 Make_Pragma_Argument_Association
(Eloc
,
2151 Chars
=> Name_Message
,
2153 Make_String_Literal
(Eloc
,
2154 Strval
=> "failed invariant from "
2155 & Build_Location_String
(Eloc
))));
2158 -- For Invariant case, insert immediately after the entity
2159 -- declaration. We do not have to worry about delay issues
2160 -- since the pragma processing takes care of this.
2162 Delay_Required
:= False;
2164 -- Case 2d : Aspects that correspond to a pragma with one
2169 -- Aspect Abstract_State introduces implicit declarations for
2170 -- all state abstraction entities it defines. To emulate this
2171 -- behavior, insert the pragma at the beginning of the visible
2172 -- declarations of the related package so that it is analyzed
2175 when Aspect_Abstract_State
=> Abstract_State
: declare
2176 Context
: Node_Id
:= N
;
2181 -- When aspect Abstract_State appears on a generic package,
2182 -- it is propageted to the package instance. The context in
2183 -- this case is the instance spec.
2185 if Nkind
(Context
) = N_Package_Instantiation
then
2186 Context
:= Instance_Spec
(Context
);
2189 if Nkind_In
(Context
, N_Generic_Package_Declaration
,
2190 N_Package_Declaration
)
2193 (Pragma_Argument_Associations
=> New_List
(
2194 Make_Pragma_Argument_Association
(Loc
,
2195 Expression
=> Relocate_Node
(Expr
))),
2196 Pragma_Name
=> Name_Abstract_State
);
2197 Decorate
(Aspect
, Aitem
);
2199 Decls
:= Visible_Declarations
(Specification
(Context
));
2201 -- In general pragma Abstract_State must be at the top
2202 -- of the existing visible declarations to emulate its
2203 -- source counterpart. The only exception to this is a
2204 -- generic instance in which case the pragma must be
2205 -- inserted after the association renamings.
2207 if Present
(Decls
) then
2208 Decl
:= First
(Decls
);
2210 -- The visible declarations of a generic instance have
2211 -- the following structure:
2213 -- <renamings of generic formals>
2214 -- <renamings of internally-generated spec and body>
2215 -- <first source declaration>
2217 -- The pragma must be inserted before the first source
2218 -- declaration, skip the instance "header".
2220 if Is_Generic_Instance
(Defining_Entity
(Context
)) then
2221 while Present
(Decl
)
2222 and then not Comes_From_Source
(Decl
)
2224 Decl
:= Next
(Decl
);
2228 -- When aspects Abstract_State, Ghost,
2229 -- Initial_Condition and Initializes are out of order,
2230 -- ensure that pragma SPARK_Mode is always at the top
2231 -- of the declarations to properly enabled/suppress
2234 Insert_After_SPARK_Mode
2239 -- Otherwise the pragma forms a new declarative list
2242 Set_Visible_Declarations
2243 (Specification
(Context
), New_List
(Aitem
));
2248 ("aspect & must apply to a package declaration",
2255 -- Aspect Default_Internal_Condition is never delayed because
2256 -- it is equivalent to a source pragma which appears after the
2257 -- related private type. To deal with forward references, the
2258 -- generated pragma is stored in the rep chain of the related
2259 -- private type as types do not carry contracts. The pragma is
2260 -- wrapped inside of a procedure at the freeze point of the
2261 -- private type's full view.
2263 when Aspect_Default_Initial_Condition
=>
2265 (Pragma_Argument_Associations
=> New_List
(
2266 Make_Pragma_Argument_Association
(Loc
,
2267 Expression
=> Relocate_Node
(Expr
))),
2269 Name_Default_Initial_Condition
);
2271 Decorate
(Aspect
, Aitem
);
2272 Insert_Pragma
(Aitem
);
2275 -- Default_Storage_Pool
2277 when Aspect_Default_Storage_Pool
=>
2279 (Pragma_Argument_Associations
=> New_List
(
2280 Make_Pragma_Argument_Association
(Loc
,
2281 Expression
=> Relocate_Node
(Expr
))),
2283 Name_Default_Storage_Pool
);
2285 Decorate
(Aspect
, Aitem
);
2286 Insert_Pragma
(Aitem
);
2291 -- Aspect Depends is never delayed because it is equivalent to
2292 -- a source pragma which appears after the related subprogram.
2293 -- To deal with forward references, the generated pragma is
2294 -- stored in the contract of the related subprogram and later
2295 -- analyzed at the end of the declarative region. See routine
2296 -- Analyze_Depends_In_Decl_Part for details.
2298 when Aspect_Depends
=>
2300 (Pragma_Argument_Associations
=> New_List
(
2301 Make_Pragma_Argument_Association
(Loc
,
2302 Expression
=> Relocate_Node
(Expr
))),
2303 Pragma_Name
=> Name_Depends
);
2305 Decorate
(Aspect
, Aitem
);
2306 Insert_Pragma
(Aitem
);
2309 -- Aspect Extensions_Visible is never delayed because it is
2310 -- equivalent to a source pragma which appears after the
2311 -- related subprogram.
2313 when Aspect_Extensions_Visible
=>
2315 (Pragma_Argument_Associations
=> New_List
(
2316 Make_Pragma_Argument_Association
(Loc
,
2317 Expression
=> Relocate_Node
(Expr
))),
2318 Pragma_Name
=> Name_Extensions_Visible
);
2320 Decorate
(Aspect
, Aitem
);
2321 Insert_Pragma
(Aitem
);
2324 -- Aspect Ghost is never delayed because it is equivalent to a
2325 -- source pragma which appears at the top of [generic] package
2326 -- declarations or after an object, a [generic] subprogram, or
2327 -- a type declaration.
2329 when Aspect_Ghost
=> Ghost
: declare
2334 (Pragma_Argument_Associations
=> New_List
(
2335 Make_Pragma_Argument_Association
(Loc
,
2336 Expression
=> Relocate_Node
(Expr
))),
2337 Pragma_Name
=> Name_Ghost
);
2339 Decorate
(Aspect
, Aitem
);
2341 -- When the aspect applies to a [generic] package, insert
2342 -- the pragma at the top of the visible declarations. This
2343 -- emulates the placement of a source pragma.
2345 if Nkind_In
(N
, N_Generic_Package_Declaration
,
2346 N_Package_Declaration
)
2348 Decls
:= Visible_Declarations
(Specification
(N
));
2352 Set_Visible_Declarations
(N
, Decls
);
2355 -- When aspects Abstract_State, Ghost, Initial_Condition
2356 -- and Initializes are out of order, ensure that pragma
2357 -- SPARK_Mode is always at the top of the declarations to
2358 -- properly enabled/suppress errors.
2360 Insert_After_SPARK_Mode
2362 Ins_Nod
=> First
(Decls
),
2365 -- Otherwise the context is an object, [generic] subprogram
2366 -- or type declaration.
2369 Insert_Pragma
(Aitem
);
2377 -- Aspect Global is never delayed because it is equivalent to
2378 -- a source pragma which appears after the related subprogram.
2379 -- To deal with forward references, the generated pragma is
2380 -- stored in the contract of the related subprogram and later
2381 -- analyzed at the end of the declarative region. See routine
2382 -- Analyze_Global_In_Decl_Part for details.
2384 when Aspect_Global
=>
2386 (Pragma_Argument_Associations
=> New_List
(
2387 Make_Pragma_Argument_Association
(Loc
,
2388 Expression
=> Relocate_Node
(Expr
))),
2389 Pragma_Name
=> Name_Global
);
2391 Decorate
(Aspect
, Aitem
);
2392 Insert_Pragma
(Aitem
);
2395 -- Initial_Condition
2397 -- Aspect Initial_Condition is never delayed because it is
2398 -- equivalent to a source pragma which appears after the
2399 -- related package. To deal with forward references, the
2400 -- generated pragma is stored in the contract of the related
2401 -- package and later analyzed at the end of the declarative
2402 -- region. See routine Analyze_Initial_Condition_In_Decl_Part
2405 when Aspect_Initial_Condition
=> Initial_Condition
: declare
2406 Context
: Node_Id
:= N
;
2410 -- When aspect Initial_Condition appears on a generic
2411 -- package, it is propageted to the package instance. The
2412 -- context in this case is the instance spec.
2414 if Nkind
(Context
) = N_Package_Instantiation
then
2415 Context
:= Instance_Spec
(Context
);
2418 if Nkind_In
(Context
, N_Generic_Package_Declaration
,
2419 N_Package_Declaration
)
2421 Decls
:= Visible_Declarations
(Specification
(Context
));
2424 (Pragma_Argument_Associations
=> New_List
(
2425 Make_Pragma_Argument_Association
(Loc
,
2426 Expression
=> Relocate_Node
(Expr
))),
2428 Name_Initial_Condition
);
2429 Decorate
(Aspect
, Aitem
);
2433 Set_Visible_Declarations
(Context
, Decls
);
2436 -- When aspects Abstract_State, Ghost, Initial_Condition
2437 -- and Initializes are out of order, ensure that pragma
2438 -- SPARK_Mode is always at the top of the declarations to
2439 -- properly enabled/suppress errors.
2441 Insert_After_SPARK_Mode
2443 Ins_Nod
=> First
(Decls
),
2448 ("aspect & must apply to a package declaration",
2453 end Initial_Condition
;
2457 -- Aspect Initializes is never delayed because it is equivalent
2458 -- to a source pragma appearing after the related package. To
2459 -- deal with forward references, the generated pragma is stored
2460 -- in the contract of the related package and later analyzed at
2461 -- the end of the declarative region. For details, see routine
2462 -- Analyze_Initializes_In_Decl_Part.
2464 when Aspect_Initializes
=> Initializes
: declare
2465 Context
: Node_Id
:= N
;
2469 -- When aspect Initializes appears on a generic package,
2470 -- it is propageted to the package instance. The context
2471 -- in this case is the instance spec.
2473 if Nkind
(Context
) = N_Package_Instantiation
then
2474 Context
:= Instance_Spec
(Context
);
2477 if Nkind_In
(Context
, N_Generic_Package_Declaration
,
2478 N_Package_Declaration
)
2480 Decls
:= Visible_Declarations
(Specification
(Context
));
2483 (Pragma_Argument_Associations
=> New_List
(
2484 Make_Pragma_Argument_Association
(Loc
,
2485 Expression
=> Relocate_Node
(Expr
))),
2486 Pragma_Name
=> Name_Initializes
);
2487 Decorate
(Aspect
, Aitem
);
2491 Set_Visible_Declarations
(Context
, Decls
);
2494 -- When aspects Abstract_State, Ghost, Initial_Condition
2495 -- and Initializes are out of order, ensure that pragma
2496 -- SPARK_Mode is always at the top of the declarations to
2497 -- properly enabled/suppress errors.
2499 Insert_After_SPARK_Mode
2501 Ins_Nod
=> First
(Decls
),
2506 ("aspect & must apply to a package declaration",
2515 when Aspect_Obsolescent
=> declare
2523 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2524 Expression
=> Relocate_Node
(Expr
)));
2528 (Pragma_Argument_Associations
=> Args
,
2529 Pragma_Name
=> Chars
(Id
));
2534 when Aspect_Part_Of
=>
2535 if Nkind_In
(N
, N_Object_Declaration
,
2536 N_Package_Instantiation
)
2539 (Pragma_Argument_Associations
=> New_List
(
2540 Make_Pragma_Argument_Association
(Loc
,
2541 Expression
=> Relocate_Node
(Expr
))),
2542 Pragma_Name
=> Name_Part_Of
);
2546 ("aspect & must apply to a variable or package "
2547 & "instantiation", Aspect
, Id
);
2552 when Aspect_SPARK_Mode
=> SPARK_Mode
: declare
2557 (Pragma_Argument_Associations
=> New_List
(
2558 Make_Pragma_Argument_Association
(Loc
,
2559 Expression
=> Relocate_Node
(Expr
))),
2560 Pragma_Name
=> Name_SPARK_Mode
);
2562 -- When the aspect appears on a package or a subprogram
2563 -- body, insert the generated pragma at the top of the body
2564 -- declarations to emulate the behavior of a source pragma.
2566 if Nkind_In
(N
, N_Package_Body
, N_Subprogram_Body
) then
2567 Decorate
(Aspect
, Aitem
);
2569 Decls
:= Declarations
(N
);
2573 Set_Declarations
(N
, Decls
);
2576 Prepend_To
(Decls
, Aitem
);
2579 -- When the aspect is associated with a [generic] package
2580 -- declaration, insert the generated pragma at the top of
2581 -- the visible declarations to emulate the behavior of a
2584 elsif Nkind_In
(N
, N_Generic_Package_Declaration
,
2585 N_Package_Declaration
)
2587 Decorate
(Aspect
, Aitem
);
2589 Decls
:= Visible_Declarations
(Specification
(N
));
2593 Set_Visible_Declarations
(Specification
(N
), Decls
);
2596 Prepend_To
(Decls
, Aitem
);
2603 -- Aspect Refined_Depends is never delayed because it is
2604 -- equivalent to a source pragma which appears in the
2605 -- declarations of the related subprogram body. To deal with
2606 -- forward references, the generated pragma is stored in the
2607 -- contract of the related subprogram body and later analyzed
2608 -- at the end of the declarative region. For details, see
2609 -- routine Analyze_Refined_Depends_In_Decl_Part.
2611 when Aspect_Refined_Depends
=>
2613 (Pragma_Argument_Associations
=> New_List
(
2614 Make_Pragma_Argument_Association
(Loc
,
2615 Expression
=> Relocate_Node
(Expr
))),
2616 Pragma_Name
=> Name_Refined_Depends
);
2618 Decorate
(Aspect
, Aitem
);
2619 Insert_Pragma
(Aitem
);
2624 -- Aspect Refined_Global is never delayed because it is
2625 -- equivalent to a source pragma which appears in the
2626 -- declarations of the related subprogram body. To deal with
2627 -- forward references, the generated pragma is stored in the
2628 -- contract of the related subprogram body and later analyzed
2629 -- at the end of the declarative region. For details, see
2630 -- routine Analyze_Refined_Global_In_Decl_Part.
2632 when Aspect_Refined_Global
=>
2634 (Pragma_Argument_Associations
=> New_List
(
2635 Make_Pragma_Argument_Association
(Loc
,
2636 Expression
=> Relocate_Node
(Expr
))),
2637 Pragma_Name
=> Name_Refined_Global
);
2639 Decorate
(Aspect
, Aitem
);
2640 Insert_Pragma
(Aitem
);
2645 when Aspect_Refined_Post
=>
2647 (Pragma_Argument_Associations
=> New_List
(
2648 Make_Pragma_Argument_Association
(Loc
,
2649 Expression
=> Relocate_Node
(Expr
))),
2650 Pragma_Name
=> Name_Refined_Post
);
2654 when Aspect_Refined_State
=> Refined_State
: declare
2658 -- The corresponding pragma for Refined_State is inserted in
2659 -- the declarations of the related package body. This action
2660 -- synchronizes both the source and from-aspect versions of
2663 if Nkind
(N
) = N_Package_Body
then
2664 Decls
:= Declarations
(N
);
2667 (Pragma_Argument_Associations
=> New_List
(
2668 Make_Pragma_Argument_Association
(Loc
,
2669 Expression
=> Relocate_Node
(Expr
))),
2670 Pragma_Name
=> Name_Refined_State
);
2671 Decorate
(Aspect
, Aitem
);
2675 Set_Declarations
(N
, Decls
);
2678 -- Pragma Refined_State must be inserted after pragma
2679 -- SPARK_Mode in the tree. This ensures that any error
2680 -- messages dependent on SPARK_Mode will be properly
2681 -- enabled/suppressed.
2683 Insert_After_SPARK_Mode
2685 Ins_Nod
=> First
(Decls
),
2690 ("aspect & must apply to a package body", Aspect
, Id
);
2696 -- Relative_Deadline
2698 when Aspect_Relative_Deadline
=>
2700 (Pragma_Argument_Associations
=> New_List
(
2701 Make_Pragma_Argument_Association
(Loc
,
2702 Expression
=> Relocate_Node
(Expr
))),
2703 Pragma_Name
=> Name_Relative_Deadline
);
2705 -- If the aspect applies to a task, the corresponding pragma
2706 -- must appear within its declarations, not after.
2708 if Nkind
(N
) = N_Task_Type_Declaration
then
2714 if No
(Task_Definition
(N
)) then
2715 Set_Task_Definition
(N
,
2716 Make_Task_Definition
(Loc
,
2717 Visible_Declarations
=> New_List
,
2718 End_Label
=> Empty
));
2721 Def
:= Task_Definition
(N
);
2722 V
:= Visible_Declarations
(Def
);
2723 if not Is_Empty_List
(V
) then
2724 Insert_Before
(First
(V
), Aitem
);
2727 Set_Visible_Declarations
(Def
, New_List
(Aitem
));
2734 -- Case 2e: Annotate aspect
2736 when Aspect_Annotate
=>
2743 -- The argument can be a single identifier
2745 if Nkind
(Expr
) = N_Identifier
then
2747 -- One level of parens is allowed
2749 if Paren_Count
(Expr
) > 1 then
2750 Error_Msg_F
("extra parentheses ignored", Expr
);
2753 Set_Paren_Count
(Expr
, 0);
2755 -- Add the single item to the list
2757 Args
:= New_List
(Expr
);
2759 -- Otherwise we must have an aggregate
2761 elsif Nkind
(Expr
) = N_Aggregate
then
2763 -- Must be positional
2765 if Present
(Component_Associations
(Expr
)) then
2767 ("purely positional aggregate required", Expr
);
2771 -- Must not be parenthesized
2773 if Paren_Count
(Expr
) /= 0 then
2774 Error_Msg_F
("extra parentheses ignored", Expr
);
2777 -- List of arguments is list of aggregate expressions
2779 Args
:= Expressions
(Expr
);
2781 -- Anything else is illegal
2784 Error_Msg_F
("wrong form for Annotate aspect", Expr
);
2788 -- Prepare pragma arguments
2791 Arg
:= First
(Args
);
2792 while Present
(Arg
) loop
2794 Make_Pragma_Argument_Association
(Sloc
(Arg
),
2795 Expression
=> Relocate_Node
(Arg
)));
2800 Make_Pragma_Argument_Association
(Sloc
(Ent
),
2801 Chars
=> Name_Entity
,
2802 Expression
=> Ent
));
2805 (Pragma_Argument_Associations
=> Pargs
,
2806 Pragma_Name
=> Name_Annotate
);
2809 -- Case 3 : Aspects that don't correspond to pragma/attribute
2810 -- definition clause.
2812 -- Case 3a: The aspects listed below don't correspond to
2813 -- pragmas/attributes but do require delayed analysis.
2815 -- Default_Value can only apply to a scalar type
2817 when Aspect_Default_Value
=>
2818 if not Is_Scalar_Type
(E
) then
2820 ("aspect Default_Value must apply to a scalar type", N
);
2825 -- Default_Component_Value can only apply to an array type
2826 -- with scalar components.
2828 when Aspect_Default_Component_Value
=>
2829 if not (Is_Array_Type
(E
)
2830 and then Is_Scalar_Type
(Component_Type
(E
)))
2832 Error_Msg_N
("aspect Default_Component_Value can only "
2833 & "apply to an array of scalar components", N
);
2838 -- Case 3b: The aspects listed below don't correspond to
2839 -- pragmas/attributes and don't need delayed analysis.
2841 -- Implicit_Dereference
2843 -- For Implicit_Dereference, External_Name and Link_Name, only
2844 -- the legality checks are done during the analysis, thus no
2845 -- delay is required.
2847 when Aspect_Implicit_Dereference
=>
2848 Analyze_Aspect_Implicit_Dereference
;
2851 -- External_Name, Link_Name
2853 when Aspect_External_Name |
2855 Analyze_Aspect_External_Or_Link_Name
;
2860 when Aspect_Dimension
=>
2861 Analyze_Aspect_Dimension
(N
, Id
, Expr
);
2866 when Aspect_Dimension_System
=>
2867 Analyze_Aspect_Dimension_System
(N
, Id
, Expr
);
2870 -- Case 4: Aspects requiring special handling
2872 -- Pre/Post/Test_Case/Contract_Cases whose corresponding
2873 -- pragmas take care of the delay.
2877 -- Aspects Pre/Post generate Precondition/Postcondition pragmas
2878 -- with a first argument that is the expression, and a second
2879 -- argument that is an informative message if the test fails.
2880 -- This is inserted right after the declaration, to get the
2881 -- required pragma placement. The processing for the pragmas
2882 -- takes care of the required delay.
2884 when Pre_Post_Aspects
=> Pre_Post
: declare
2888 if A_Id
= Aspect_Pre
or else A_Id
= Aspect_Precondition
then
2889 Pname
:= Name_Precondition
;
2891 Pname
:= Name_Postcondition
;
2894 -- If the expressions is of the form A and then B, then
2895 -- we generate separate Pre/Post aspects for the separate
2896 -- clauses. Since we allow multiple pragmas, there is no
2897 -- problem in allowing multiple Pre/Post aspects internally.
2898 -- These should be treated in reverse order (B first and
2899 -- A second) since they are later inserted just after N in
2900 -- the order they are treated. This way, the pragma for A
2901 -- ends up preceding the pragma for B, which may have an
2902 -- importance for the error raised (either constraint error
2903 -- or precondition error).
2905 -- We do not do this for Pre'Class, since we have to put
2906 -- these conditions together in a complex OR expression.
2908 -- We do not do this in ASIS mode, as ASIS relies on the
2909 -- original node representing the complete expression, when
2910 -- retrieving it through the source aspect table.
2913 and then (Pname
= Name_Postcondition
2914 or else not Class_Present
(Aspect
))
2916 while Nkind
(Expr
) = N_And_Then
loop
2917 Insert_After
(Aspect
,
2918 Make_Aspect_Specification
(Sloc
(Left_Opnd
(Expr
)),
2919 Identifier
=> Identifier
(Aspect
),
2920 Expression
=> Relocate_Node
(Left_Opnd
(Expr
)),
2921 Class_Present
=> Class_Present
(Aspect
),
2922 Split_PPC
=> True));
2923 Rewrite
(Expr
, Relocate_Node
(Right_Opnd
(Expr
)));
2924 Eloc
:= Sloc
(Expr
);
2928 -- Build the precondition/postcondition pragma
2930 -- Add note about why we do NOT need Copy_Tree here???
2933 (Pragma_Argument_Associations
=> New_List
(
2934 Make_Pragma_Argument_Association
(Eloc
,
2935 Chars
=> Name_Check
,
2936 Expression
=> Relocate_Node
(Expr
))),
2937 Pragma_Name
=> Pname
);
2939 -- Add message unless exception messages are suppressed
2941 if not Opt
.Exception_Locations_Suppressed
then
2942 Append_To
(Pragma_Argument_Associations
(Aitem
),
2943 Make_Pragma_Argument_Association
(Eloc
,
2944 Chars
=> Name_Message
,
2946 Make_String_Literal
(Eloc
,
2948 & Get_Name_String
(Pname
)
2950 & Build_Location_String
(Eloc
))));
2953 Set_Is_Delayed_Aspect
(Aspect
);
2955 -- For Pre/Post cases, insert immediately after the entity
2956 -- declaration, since that is the required pragma placement.
2957 -- Note that for these aspects, we do not have to worry
2958 -- about delay issues, since the pragmas themselves deal
2959 -- with delay of visibility for the expression analysis.
2961 Insert_Pragma
(Aitem
);
2968 when Aspect_Test_Case
=> Test_Case
: declare
2970 Comp_Expr
: Node_Id
;
2971 Comp_Assn
: Node_Id
;
2977 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
2978 Error_Msg_Name_1
:= Nam
;
2979 Error_Msg_N
("incorrect placement of aspect `%`", E
);
2983 if Nkind
(Expr
) /= N_Aggregate
then
2984 Error_Msg_Name_1
:= Nam
;
2986 ("wrong syntax for aspect `%` for &", Id
, E
);
2990 -- Make pragma expressions refer to the original aspect
2991 -- expressions through the Original_Node link. This is used
2992 -- in semantic analysis for ASIS mode, so that the original
2993 -- expression also gets analyzed.
2995 Comp_Expr
:= First
(Expressions
(Expr
));
2996 while Present
(Comp_Expr
) loop
2997 New_Expr
:= Relocate_Node
(Comp_Expr
);
2999 Make_Pragma_Argument_Association
(Sloc
(Comp_Expr
),
3000 Expression
=> New_Expr
));
3004 Comp_Assn
:= First
(Component_Associations
(Expr
));
3005 while Present
(Comp_Assn
) loop
3006 if List_Length
(Choices
(Comp_Assn
)) /= 1
3008 Nkind
(First
(Choices
(Comp_Assn
))) /= N_Identifier
3010 Error_Msg_Name_1
:= Nam
;
3012 ("wrong syntax for aspect `%` for &", Id
, E
);
3017 Make_Pragma_Argument_Association
(Sloc
(Comp_Assn
),
3018 Chars
=> Chars
(First
(Choices
(Comp_Assn
))),
3020 Relocate_Node
(Expression
(Comp_Assn
))));
3024 -- Build the test-case pragma
3027 (Pragma_Argument_Associations
=> Args
,
3028 Pragma_Name
=> Nam
);
3033 when Aspect_Contract_Cases
=>
3035 (Pragma_Argument_Associations
=> New_List
(
3036 Make_Pragma_Argument_Association
(Loc
,
3037 Expression
=> Relocate_Node
(Expr
))),
3038 Pragma_Name
=> Nam
);
3040 Decorate
(Aspect
, Aitem
);
3041 Insert_Pragma
(Aitem
);
3044 -- Case 5: Special handling for aspects with an optional
3045 -- boolean argument.
3047 -- In the general case, the corresponding pragma cannot be
3048 -- generated yet because the evaluation of the boolean needs
3049 -- to be delayed till the freeze point.
3051 when Boolean_Aspects |
3052 Library_Unit_Aspects
=>
3054 Set_Is_Boolean_Aspect
(Aspect
);
3056 -- Lock_Free aspect only apply to protected objects
3058 if A_Id
= Aspect_Lock_Free
then
3059 if Ekind
(E
) /= E_Protected_Type
then
3060 Error_Msg_Name_1
:= Nam
;
3062 ("aspect % only applies to a protected object",
3066 -- Set the Uses_Lock_Free flag to True if there is no
3067 -- expression or if the expression is True. The
3068 -- evaluation of this aspect should be delayed to the
3069 -- freeze point (why???)
3072 or else Is_True
(Static_Boolean
(Expr
))
3074 Set_Uses_Lock_Free
(E
);
3077 Record_Rep_Item
(E
, Aspect
);
3082 elsif A_Id
= Aspect_Import
or else A_Id
= Aspect_Export
then
3084 -- For the case of aspects Import and Export, we don't
3085 -- consider that we know the entity is never set in the
3086 -- source, since it is is likely modified outside the
3089 -- Note: one might think that the analysis of the
3090 -- resulting pragma would take care of that, but
3091 -- that's not the case since it won't be from source.
3093 if Ekind
(E
) = E_Variable
then
3094 Set_Never_Set_In_Source
(E
, False);
3097 -- In older versions of Ada the corresponding pragmas
3098 -- specified a Convention. In Ada 2012 the convention is
3099 -- specified as a separate aspect, and it is optional,
3100 -- given that it defaults to Convention_Ada. The code
3101 -- that verifed that there was a matching convention
3104 -- Resolve the expression of an Import or Export here,
3105 -- and require it to be of type Boolean and static. This
3106 -- is not quite right, because in general this should be
3107 -- delayed, but that seems tricky for these, because
3108 -- normally Boolean aspects are replaced with pragmas at
3109 -- the freeze point (in Make_Pragma_From_Boolean_Aspect),
3110 -- but in the case of these aspects we can't generate
3111 -- a simple pragma with just the entity name. ???
3113 if not Present
(Expr
)
3114 or else Is_True
(Static_Boolean
(Expr
))
3116 if A_Id
= Aspect_Import
then
3117 Set_Is_Imported
(E
);
3119 -- An imported entity cannot have an explicit
3122 if Nkind
(N
) = N_Object_Declaration
3123 and then Present
(Expression
(N
))
3126 ("imported entities cannot be initialized "
3127 & "(RM B.1(24))", Expression
(N
));
3130 elsif A_Id
= Aspect_Export
then
3131 Set_Is_Exported
(E
);
3138 -- Library unit aspects require special handling in the case
3139 -- of a package declaration, the pragma needs to be inserted
3140 -- in the list of declarations for the associated package.
3141 -- There is no issue of visibility delay for these aspects.
3143 if A_Id
in Library_Unit_Aspects
3145 Nkind_In
(N
, N_Package_Declaration
,
3146 N_Generic_Package_Declaration
)
3147 and then Nkind
(Parent
(N
)) /= N_Compilation_Unit
3149 -- Aspect is legal on a local instantiation of a library-
3150 -- level generic unit.
3152 and then not Is_Generic_Instance
(Defining_Entity
(N
))
3155 ("incorrect context for library unit aspect&", Id
);
3159 -- External property aspects are Boolean by nature, but
3160 -- their pragmas must contain two arguments, the second
3161 -- being the optional Boolean expression.
3163 if A_Id
= Aspect_Async_Readers
or else
3164 A_Id
= Aspect_Async_Writers
or else
3165 A_Id
= Aspect_Effective_Reads
or else
3166 A_Id
= Aspect_Effective_Writes
3172 -- The first argument of the external property pragma
3173 -- is the related object.
3177 Make_Pragma_Argument_Association
(Sloc
(Ent
),
3178 Expression
=> Ent
));
3180 -- The second argument is the optional Boolean
3181 -- expression which must be propagated even if it
3182 -- evaluates to False as this has special semantic
3185 if Present
(Expr
) then
3187 Make_Pragma_Argument_Association
(Loc
,
3188 Expression
=> Relocate_Node
(Expr
)));
3192 (Pragma_Argument_Associations
=> Args
,
3193 Pragma_Name
=> Nam
);
3196 -- Cases where we do not delay, includes all cases where the
3197 -- expression is missing other than the above cases.
3199 elsif not Delay_Required
or else No
(Expr
) then
3201 (Pragma_Argument_Associations
=> New_List
(
3202 Make_Pragma_Argument_Association
(Sloc
(Ent
),
3203 Expression
=> Ent
)),
3204 Pragma_Name
=> Chars
(Id
));
3205 Delay_Required
:= False;
3207 -- In general cases, the corresponding pragma/attribute
3208 -- definition clause will be inserted later at the freezing
3209 -- point, and we do not need to build it now.
3217 -- This is special because for access types we need to generate
3218 -- an attribute definition clause. This also works for single
3219 -- task declarations, but it does not work for task type
3220 -- declarations, because we have the case where the expression
3221 -- references a discriminant of the task type. That can't use
3222 -- an attribute definition clause because we would not have
3223 -- visibility on the discriminant. For that case we must
3224 -- generate a pragma in the task definition.
3226 when Aspect_Storage_Size
=>
3230 if Ekind
(E
) = E_Task_Type
then
3232 Decl
: constant Node_Id
:= Declaration_Node
(E
);
3235 pragma Assert
(Nkind
(Decl
) = N_Task_Type_Declaration
);
3237 -- If no task definition, create one
3239 if No
(Task_Definition
(Decl
)) then
3240 Set_Task_Definition
(Decl
,
3241 Make_Task_Definition
(Loc
,
3242 Visible_Declarations
=> Empty_List
,
3243 End_Label
=> Empty
));
3246 -- Create a pragma and put it at the start of the task
3247 -- definition for the task type declaration.
3250 (Pragma_Argument_Associations
=> New_List
(
3251 Make_Pragma_Argument_Association
(Loc
,
3252 Expression
=> Relocate_Node
(Expr
))),
3253 Pragma_Name
=> Name_Storage_Size
);
3257 Visible_Declarations
(Task_Definition
(Decl
)));
3261 -- All other cases, generate attribute definition
3265 Make_Attribute_Definition_Clause
(Loc
,
3267 Chars
=> Chars
(Id
),
3268 Expression
=> Relocate_Node
(Expr
));
3272 -- Attach the corresponding pragma/attribute definition clause to
3273 -- the aspect specification node.
3275 if Present
(Aitem
) then
3276 Set_From_Aspect_Specification
(Aitem
);
3279 -- In the context of a compilation unit, we directly put the
3280 -- pragma in the Pragmas_After list of the N_Compilation_Unit_Aux
3281 -- node (no delay is required here) except for aspects on a
3282 -- subprogram body (see below) and a generic package, for which we
3283 -- need to introduce the pragma before building the generic copy
3284 -- (see sem_ch12), and for package instantiations, where the
3285 -- library unit pragmas are better handled early.
3287 if Nkind
(Parent
(N
)) = N_Compilation_Unit
3288 and then (Present
(Aitem
) or else Is_Boolean_Aspect
(Aspect
))
3291 Aux
: constant Node_Id
:= Aux_Decls_Node
(Parent
(N
));
3294 pragma Assert
(Nkind
(Aux
) = N_Compilation_Unit_Aux
);
3296 -- For a Boolean aspect, create the corresponding pragma if
3297 -- no expression or if the value is True.
3299 if Is_Boolean_Aspect
(Aspect
) and then No
(Aitem
) then
3300 if Is_True
(Static_Boolean
(Expr
)) then
3302 (Pragma_Argument_Associations
=> New_List
(
3303 Make_Pragma_Argument_Association
(Sloc
(Ent
),
3304 Expression
=> Ent
)),
3305 Pragma_Name
=> Chars
(Id
));
3307 Set_From_Aspect_Specification
(Aitem
, True);
3308 Set_Corresponding_Aspect
(Aitem
, Aspect
);
3315 -- If the aspect is on a subprogram body (relevant aspect
3316 -- is Inline), add the pragma in front of the declarations.
3318 if Nkind
(N
) = N_Subprogram_Body
then
3319 if No
(Declarations
(N
)) then
3320 Set_Declarations
(N
, New_List
);
3323 Prepend
(Aitem
, Declarations
(N
));
3325 elsif Nkind
(N
) = N_Generic_Package_Declaration
then
3326 if No
(Visible_Declarations
(Specification
(N
))) then
3327 Set_Visible_Declarations
(Specification
(N
), New_List
);
3331 Visible_Declarations
(Specification
(N
)));
3333 elsif Nkind
(N
) = N_Package_Instantiation
then
3335 Spec
: constant Node_Id
:=
3336 Specification
(Instance_Spec
(N
));
3338 if No
(Visible_Declarations
(Spec
)) then
3339 Set_Visible_Declarations
(Spec
, New_List
);
3342 Prepend
(Aitem
, Visible_Declarations
(Spec
));
3346 if No
(Pragmas_After
(Aux
)) then
3347 Set_Pragmas_After
(Aux
, New_List
);
3350 Append
(Aitem
, Pragmas_After
(Aux
));
3357 -- The evaluation of the aspect is delayed to the freezing point.
3358 -- The pragma or attribute clause if there is one is then attached
3359 -- to the aspect specification which is put in the rep item list.
3361 if Delay_Required
then
3362 if Present
(Aitem
) then
3363 Set_Is_Delayed_Aspect
(Aitem
);
3364 Set_Aspect_Rep_Item
(Aspect
, Aitem
);
3365 Set_Parent
(Aitem
, Aspect
);
3368 Set_Is_Delayed_Aspect
(Aspect
);
3370 -- In the case of Default_Value, link the aspect to base type
3371 -- as well, even though it appears on a first subtype. This is
3372 -- mandated by the semantics of the aspect. Do not establish
3373 -- the link when processing the base type itself as this leads
3374 -- to a rep item circularity. Verify that we are dealing with
3375 -- a scalar type to prevent cascaded errors.
3377 if A_Id
= Aspect_Default_Value
3378 and then Is_Scalar_Type
(E
)
3379 and then Base_Type
(E
) /= E
3381 Set_Has_Delayed_Aspects
(Base_Type
(E
));
3382 Record_Rep_Item
(Base_Type
(E
), Aspect
);
3385 Set_Has_Delayed_Aspects
(E
);
3386 Record_Rep_Item
(E
, Aspect
);
3388 -- When delay is not required and the context is a package or a
3389 -- subprogram body, insert the pragma in the body declarations.
3391 elsif Nkind_In
(N
, N_Package_Body
, N_Subprogram_Body
) then
3392 if No
(Declarations
(N
)) then
3393 Set_Declarations
(N
, New_List
);
3396 -- The pragma is added before source declarations
3398 Prepend_To
(Declarations
(N
), Aitem
);
3400 -- When delay is not required and the context is not a compilation
3401 -- unit, we simply insert the pragma/attribute definition clause
3405 Insert_After
(Ins_Node
, Aitem
);
3408 end Analyze_One_Aspect
;
3412 end loop Aspect_Loop
;
3414 if Has_Delayed_Aspects
(E
) then
3415 Ensure_Freeze_Node
(E
);
3417 end Analyze_Aspect_Specifications
;
3419 ---------------------------------------------------
3420 -- Analyze_Aspect_Specifications_On_Body_Or_Stub --
3421 ---------------------------------------------------
3423 procedure Analyze_Aspect_Specifications_On_Body_Or_Stub
(N
: Node_Id
) is
3424 Body_Id
: constant Entity_Id
:= Defining_Entity
(N
);
3426 procedure Diagnose_Misplaced_Aspects
(Spec_Id
: Entity_Id
);
3427 -- Subprogram body [stub] N has aspects, but they are not properly
3428 -- placed. Emit an error message depending on the aspects involved.
3429 -- Spec_Id is the entity of the corresponding spec.
3431 --------------------------------
3432 -- Diagnose_Misplaced_Aspects --
3433 --------------------------------
3435 procedure Diagnose_Misplaced_Aspects
(Spec_Id
: Entity_Id
) is
3436 procedure Misplaced_Aspect_Error
3439 -- Emit an error message concerning misplaced aspect Asp. Ref_Nam is
3440 -- the name of the refined version of the aspect.
3442 ----------------------------
3443 -- Misplaced_Aspect_Error --
3444 ----------------------------
3446 procedure Misplaced_Aspect_Error
3450 Asp_Nam
: constant Name_Id
:= Chars
(Identifier
(Asp
));
3451 Asp_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Asp_Nam
);
3454 -- The corresponding spec already contains the aspect in question
3455 -- and the one appearing on the body must be the refined form:
3457 -- procedure P with Global ...;
3458 -- procedure P with Global ... is ... end P;
3462 if Has_Aspect
(Spec_Id
, Asp_Id
) then
3463 Error_Msg_Name_1
:= Asp_Nam
;
3465 -- Subunits cannot carry aspects that apply to a subprogram
3468 if Nkind
(Parent
(N
)) = N_Subunit
then
3469 Error_Msg_N
("aspect % cannot apply to a subunit", Asp
);
3471 -- Otherwise suggest the refined form
3474 Error_Msg_Name_2
:= Ref_Nam
;
3475 Error_Msg_N
("aspect % should be %", Asp
);
3478 -- Otherwise the aspect must appear on the spec, not on the body
3481 -- procedure P with Global ... is ... end P;
3485 ("aspect specification must appear in subprogram declaration",
3488 end Misplaced_Aspect_Error
;
3495 -- Start of processing for Diagnose_Misplaced_Aspects
3498 -- Iterate over the aspect specifications and emit specific errors
3499 -- where applicable.
3501 Asp
:= First
(Aspect_Specifications
(N
));
3502 while Present
(Asp
) loop
3503 Asp_Nam
:= Chars
(Identifier
(Asp
));
3505 -- Do not emit errors on aspects that can appear on a subprogram
3506 -- body. This scenario occurs when the aspect specification list
3507 -- contains both misplaced and properly placed aspects.
3509 if Aspect_On_Body_Or_Stub_OK
(Get_Aspect_Id
(Asp_Nam
)) then
3512 -- Special diagnostics for SPARK aspects
3514 elsif Asp_Nam
= Name_Depends
then
3515 Misplaced_Aspect_Error
(Asp
, Name_Refined_Depends
);
3517 elsif Asp_Nam
= Name_Global
then
3518 Misplaced_Aspect_Error
(Asp
, Name_Refined_Global
);
3520 elsif Asp_Nam
= Name_Post
then
3521 Misplaced_Aspect_Error
(Asp
, Name_Refined_Post
);
3523 -- Otherwise a language-defined aspect is misplaced
3527 ("aspect specification must appear in subprogram declaration",
3533 end Diagnose_Misplaced_Aspects
;
3537 Spec_Id
: Entity_Id
;
3539 -- Start of processing for Analyze_Aspects_On_Body_Or_Stub
3542 if Nkind
(N
) = N_Subprogram_Body_Stub
then
3543 Spec_Id
:= Corresponding_Spec_Of_Stub
(N
);
3545 Spec_Id
:= Corresponding_Spec
(N
);
3548 -- Language-defined aspects cannot be associated with a subprogram body
3549 -- [stub] if the subprogram has a spec. Certain implementation defined
3550 -- aspects are allowed to break this rule (for all applicable cases, see
3551 -- table Aspects.Aspect_On_Body_Or_Stub_OK).
3553 if Present
(Spec_Id
) and then not Aspects_On_Body_Or_Stub_OK
(N
) then
3554 Diagnose_Misplaced_Aspects
(Spec_Id
);
3556 Analyze_Aspect_Specifications
(N
, Body_Id
);
3558 end Analyze_Aspect_Specifications_On_Body_Or_Stub
;
3560 -----------------------
3561 -- Analyze_At_Clause --
3562 -----------------------
3564 -- An at clause is replaced by the corresponding Address attribute
3565 -- definition clause that is the preferred approach in Ada 95.
3567 procedure Analyze_At_Clause
(N
: Node_Id
) is
3568 CS
: constant Boolean := Comes_From_Source
(N
);
3571 -- This is an obsolescent feature
3573 Check_Restriction
(No_Obsolescent_Features
, N
);
3575 if Warn_On_Obsolescent_Feature
then
3577 ("?j?at clause is an obsolescent feature (RM J.7(2))", N
);
3579 ("\?j?use address attribute definition clause instead", N
);
3582 -- Rewrite as address clause
3585 Make_Attribute_Definition_Clause
(Sloc
(N
),
3586 Name
=> Identifier
(N
),
3587 Chars
=> Name_Address
,
3588 Expression
=> Expression
(N
)));
3590 -- We preserve Comes_From_Source, since logically the clause still comes
3591 -- from the source program even though it is changed in form.
3593 Set_Comes_From_Source
(N
, CS
);
3595 -- Analyze rewritten clause
3597 Analyze_Attribute_Definition_Clause
(N
);
3598 end Analyze_At_Clause
;
3600 -----------------------------------------
3601 -- Analyze_Attribute_Definition_Clause --
3602 -----------------------------------------
3604 procedure Analyze_Attribute_Definition_Clause
(N
: Node_Id
) is
3605 Loc
: constant Source_Ptr
:= Sloc
(N
);
3606 Nam
: constant Node_Id
:= Name
(N
);
3607 Attr
: constant Name_Id
:= Chars
(N
);
3608 Expr
: constant Node_Id
:= Expression
(N
);
3609 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Attr
);
3612 -- The entity of Nam after it is analyzed. In the case of an incomplete
3613 -- type, this is the underlying type.
3616 -- The underlying entity to which the attribute applies. Generally this
3617 -- is the Underlying_Type of Ent, except in the case where the clause
3618 -- applies to full view of incomplete type or private type in which case
3619 -- U_Ent is just a copy of Ent.
3621 FOnly
: Boolean := False;
3622 -- Reset to True for subtype specific attribute (Alignment, Size)
3623 -- and for stream attributes, i.e. those cases where in the call to
3624 -- Rep_Item_Too_Late, FOnly is set True so that only the freezing rules
3625 -- are checked. Note that the case of stream attributes is not clear
3626 -- from the RM, but see AI95-00137. Also, the RM seems to disallow
3627 -- Storage_Size for derived task types, but that is also clearly
3630 procedure Analyze_Stream_TSS_Definition
(TSS_Nam
: TSS_Name_Type
);
3631 -- Common processing for 'Read, 'Write, 'Input and 'Output attribute
3632 -- definition clauses.
3634 function Duplicate_Clause
return Boolean;
3635 -- This routine checks if the aspect for U_Ent being given by attribute
3636 -- definition clause N is for an aspect that has already been specified,
3637 -- and if so gives an error message. If there is a duplicate, True is
3638 -- returned, otherwise if there is no error, False is returned.
3640 procedure Check_Indexing_Functions
;
3641 -- Check that the function in Constant_Indexing or Variable_Indexing
3642 -- attribute has the proper type structure. If the name is overloaded,
3643 -- check that some interpretation is legal.
3645 procedure Check_Iterator_Functions
;
3646 -- Check that there is a single function in Default_Iterator attribute
3647 -- has the proper type structure.
3649 function Check_Primitive_Function
(Subp
: Entity_Id
) return Boolean;
3650 -- Common legality check for the previous two
3652 -----------------------------------
3653 -- Analyze_Stream_TSS_Definition --
3654 -----------------------------------
3656 procedure Analyze_Stream_TSS_Definition
(TSS_Nam
: TSS_Name_Type
) is
3657 Subp
: Entity_Id
:= Empty
;
3662 Is_Read
: constant Boolean := (TSS_Nam
= TSS_Stream_Read
);
3663 -- True for Read attribute, false for other attributes
3665 function Has_Good_Profile
(Subp
: Entity_Id
) return Boolean;
3666 -- Return true if the entity is a subprogram with an appropriate
3667 -- profile for the attribute being defined.
3669 ----------------------
3670 -- Has_Good_Profile --
3671 ----------------------
3673 function Has_Good_Profile
(Subp
: Entity_Id
) return Boolean is
3675 Is_Function
: constant Boolean := (TSS_Nam
= TSS_Stream_Input
);
3676 Expected_Ekind
: constant array (Boolean) of Entity_Kind
:=
3677 (False => E_Procedure
, True => E_Function
);
3681 if Ekind
(Subp
) /= Expected_Ekind
(Is_Function
) then
3685 F
:= First_Formal
(Subp
);
3688 or else Ekind
(Etype
(F
)) /= E_Anonymous_Access_Type
3689 or else Designated_Type
(Etype
(F
)) /=
3690 Class_Wide_Type
(RTE
(RE_Root_Stream_Type
))
3695 if not Is_Function
then
3699 Expected_Mode
: constant array (Boolean) of Entity_Kind
:=
3700 (False => E_In_Parameter
,
3701 True => E_Out_Parameter
);
3703 if Parameter_Mode
(F
) /= Expected_Mode
(Is_Read
) then
3710 -- If the attribute specification comes from an aspect
3711 -- specification for a class-wide stream, the parameter must be
3712 -- a class-wide type of the entity to which the aspect applies.
3714 if From_Aspect_Specification
(N
)
3715 and then Class_Present
(Parent
(N
))
3716 and then Is_Class_Wide_Type
(Typ
)
3722 Typ
:= Etype
(Subp
);
3725 -- Verify that the prefix of the attribute and the local name for
3726 -- the type of the formal match, or one is the class-wide of the
3727 -- other, in the case of a class-wide stream operation.
3729 if Base_Type
(Typ
) = Base_Type
(Ent
)
3730 or else (Is_Class_Wide_Type
(Typ
)
3731 and then Typ
= Class_Wide_Type
(Base_Type
(Ent
)))
3732 or else (Is_Class_Wide_Type
(Ent
)
3733 and then Ent
= Class_Wide_Type
(Base_Type
(Typ
)))
3740 if Present
((Next_Formal
(F
)))
3744 elsif not Is_Scalar_Type
(Typ
)
3745 and then not Is_First_Subtype
(Typ
)
3746 and then not Is_Class_Wide_Type
(Typ
)
3753 end Has_Good_Profile
;
3755 -- Start of processing for Analyze_Stream_TSS_Definition
3760 if not Is_Type
(U_Ent
) then
3761 Error_Msg_N
("local name must be a subtype", Nam
);
3764 elsif not Is_First_Subtype
(U_Ent
) then
3765 Error_Msg_N
("local name must be a first subtype", Nam
);
3769 Pnam
:= TSS
(Base_Type
(U_Ent
), TSS_Nam
);
3771 -- If Pnam is present, it can be either inherited from an ancestor
3772 -- type (in which case it is legal to redefine it for this type), or
3773 -- be a previous definition of the attribute for the same type (in
3774 -- which case it is illegal).
3776 -- In the first case, it will have been analyzed already, and we
3777 -- can check that its profile does not match the expected profile
3778 -- for a stream attribute of U_Ent. In the second case, either Pnam
3779 -- has been analyzed (and has the expected profile), or it has not
3780 -- been analyzed yet (case of a type that has not been frozen yet
3781 -- and for which the stream attribute has been set using Set_TSS).
3784 and then (No
(First_Entity
(Pnam
)) or else Has_Good_Profile
(Pnam
))
3786 Error_Msg_Sloc
:= Sloc
(Pnam
);
3787 Error_Msg_Name_1
:= Attr
;
3788 Error_Msg_N
("% attribute already defined #", Nam
);
3794 if Is_Entity_Name
(Expr
) then
3795 if not Is_Overloaded
(Expr
) then
3796 if Has_Good_Profile
(Entity
(Expr
)) then
3797 Subp
:= Entity
(Expr
);
3801 Get_First_Interp
(Expr
, I
, It
);
3802 while Present
(It
.Nam
) loop
3803 if Has_Good_Profile
(It
.Nam
) then
3808 Get_Next_Interp
(I
, It
);
3813 if Present
(Subp
) then
3814 if Is_Abstract_Subprogram
(Subp
) then
3815 Error_Msg_N
("stream subprogram must not be abstract", Expr
);
3818 -- A stream subprogram for an interface type must be a null
3819 -- procedure (RM 13.13.2 (38/3)).
3821 elsif Is_Interface
(U_Ent
)
3822 and then not Is_Class_Wide_Type
(U_Ent
)
3823 and then not Inside_A_Generic
3825 (Ekind
(Subp
) = E_Function
3829 (Unit_Declaration_Node
(Ultimate_Alias
(Subp
)))))
3832 ("stream subprogram for interface type "
3833 & "must be null procedure", Expr
);
3836 Set_Entity
(Expr
, Subp
);
3837 Set_Etype
(Expr
, Etype
(Subp
));
3839 New_Stream_Subprogram
(N
, U_Ent
, Subp
, TSS_Nam
);
3842 Error_Msg_Name_1
:= Attr
;
3843 Error_Msg_N
("incorrect expression for% attribute", Expr
);
3845 end Analyze_Stream_TSS_Definition
;
3847 ------------------------------
3848 -- Check_Indexing_Functions --
3849 ------------------------------
3851 procedure Check_Indexing_Functions
is
3852 Indexing_Found
: Boolean := False;
3854 procedure Check_One_Function
(Subp
: Entity_Id
);
3855 -- Check one possible interpretation. Sets Indexing_Found True if a
3856 -- legal indexing function is found.
3858 procedure Illegal_Indexing
(Msg
: String);
3859 -- Diagnose illegal indexing function if not overloaded. In the
3860 -- overloaded case indicate that no legal interpretation exists.
3862 ------------------------
3863 -- Check_One_Function --
3864 ------------------------
3866 procedure Check_One_Function
(Subp
: Entity_Id
) is
3867 Default_Element
: Node_Id
;
3868 Ret_Type
: constant Entity_Id
:= Etype
(Subp
);
3871 if not Is_Overloadable
(Subp
) then
3872 Illegal_Indexing
("illegal indexing function for type&");
3875 elsif Scope
(Subp
) /= Scope
(Ent
) then
3876 if Nkind
(Expr
) = N_Expanded_Name
then
3878 -- Indexing function can't be declared elsewhere
3881 ("indexing function must be declared in scope of type&");
3886 elsif No
(First_Formal
(Subp
)) then
3888 ("Indexing requires a function that applies to type&");
3891 elsif No
(Next_Formal
(First_Formal
(Subp
))) then
3893 ("indexing function must have at least two parameters");
3896 elsif Is_Derived_Type
(Ent
) then
3898 Inherited
: Node_Id
;
3901 if Attr
= Name_Constant_Indexing
then
3903 Find_Aspect
(Etype
(Ent
), Aspect_Constant_Indexing
);
3904 elsif Attr
= Name_Variable_Indexing
then
3906 Find_Aspect
(Etype
(Ent
), Aspect_Variable_Indexing
);
3909 -- What if neither branch taken above ???
3911 if Present
(Inherited
) then
3912 if Debug_Flag_Dot_XX
then
3915 -- Indicate the operation that must be overridden,
3916 -- rather than redefining the indexing aspect
3920 ("indexing function already inherited "
3921 & "from parent type");
3923 ("!override& instead",
3924 N
, Entity
(Expression
(Inherited
)));
3931 if not Check_Primitive_Function
(Subp
) then
3933 ("Indexing aspect requires a function that applies to type&");
3937 -- If partial declaration exists, verify that it is not tagged.
3939 if Ekind
(Current_Scope
) = E_Package
3940 and then Has_Private_Declaration
(Ent
)
3941 and then From_Aspect_Specification
(N
)
3943 List_Containing
(Parent
(Ent
)) =
3944 Private_Declarations
3945 (Specification
(Unit_Declaration_Node
(Current_Scope
)))
3946 and then Nkind
(N
) = N_Attribute_Definition_Clause
3953 First
(Visible_Declarations
3955 (Unit_Declaration_Node
(Current_Scope
))));
3957 while Present
(Decl
) loop
3958 if Nkind
(Decl
) = N_Private_Type_Declaration
3959 and then Ent
= Full_View
(Defining_Identifier
(Decl
))
3960 and then Tagged_Present
(Decl
)
3961 and then No
(Aspect_Specifications
(Decl
))
3964 ("Indexing aspect cannot be specified on full view "
3965 & "if partial view is tagged");
3974 -- An indexing function must return either the default element of
3975 -- the container, or a reference type. For variable indexing it
3976 -- must be the latter.
3979 Find_Value_Of_Aspect
3980 (Etype
(First_Formal
(Subp
)), Aspect_Iterator_Element
);
3982 if Present
(Default_Element
) then
3983 Analyze
(Default_Element
);
3985 if Is_Entity_Name
(Default_Element
)
3986 and then not Covers
(Entity
(Default_Element
), Ret_Type
)
3990 ("wrong return type for indexing function");
3995 -- For variable_indexing the return type must be a reference type
3997 if Attr
= Name_Variable_Indexing
then
3998 if not Has_Implicit_Dereference
(Ret_Type
) then
4000 ("variable indexing must return a reference type");
4003 elsif Is_Access_Constant
4004 (Etype
(First_Discriminant
(Ret_Type
)))
4007 ("variable indexing must return an access to variable");
4012 if Has_Implicit_Dereference
(Ret_Type
)
4014 Is_Access_Constant
(Etype
(First_Discriminant
(Ret_Type
)))
4017 ("constant indexing must return an access to constant");
4020 elsif Is_Access_Type
(Etype
(First_Formal
(Subp
)))
4021 and then not Is_Access_Constant
(Etype
(First_Formal
(Subp
)))
4024 ("constant indexing must apply to an access to constant");
4029 -- All checks succeeded.
4031 Indexing_Found
:= True;
4032 end Check_One_Function
;
4034 -----------------------
4035 -- Illegal_Indexing --
4036 -----------------------
4038 procedure Illegal_Indexing
(Msg
: String) is
4040 Error_Msg_NE
(Msg
, N
, Ent
);
4041 end Illegal_Indexing
;
4043 -- Start of processing for Check_Indexing_Functions
4052 if not Is_Overloaded
(Expr
) then
4053 Check_One_Function
(Entity
(Expr
));
4061 Indexing_Found
:= False;
4062 Get_First_Interp
(Expr
, I
, It
);
4063 while Present
(It
.Nam
) loop
4065 -- Note that analysis will have added the interpretation
4066 -- that corresponds to the dereference. We only check the
4067 -- subprogram itself.
4069 if Is_Overloadable
(It
.Nam
) then
4070 Check_One_Function
(It
.Nam
);
4073 Get_Next_Interp
(I
, It
);
4078 if not Indexing_Found
and then not Error_Posted
(N
) then
4080 ("aspect Indexing requires a local function that "
4081 & "applies to type&", Expr
, Ent
);
4083 end Check_Indexing_Functions
;
4085 ------------------------------
4086 -- Check_Iterator_Functions --
4087 ------------------------------
4089 procedure Check_Iterator_Functions
is
4090 Default
: Entity_Id
;
4092 function Valid_Default_Iterator
(Subp
: Entity_Id
) return Boolean;
4093 -- Check one possible interpretation for validity
4095 ----------------------------
4096 -- Valid_Default_Iterator --
4097 ----------------------------
4099 function Valid_Default_Iterator
(Subp
: Entity_Id
) return Boolean is
4103 if not Check_Primitive_Function
(Subp
) then
4106 Formal
:= First_Formal
(Subp
);
4109 -- False if any subsequent formal has no default expression
4111 Formal
:= Next_Formal
(Formal
);
4112 while Present
(Formal
) loop
4113 if No
(Expression
(Parent
(Formal
))) then
4117 Next_Formal
(Formal
);
4120 -- True if all subsequent formals have default expressions
4123 end Valid_Default_Iterator
;
4125 -- Start of processing for Check_Iterator_Functions
4130 if not Is_Entity_Name
(Expr
) then
4131 Error_Msg_N
("aspect Iterator must be a function name", Expr
);
4134 if not Is_Overloaded
(Expr
) then
4135 if not Check_Primitive_Function
(Entity
(Expr
)) then
4137 ("aspect Indexing requires a function that applies to type&",
4138 Entity
(Expr
), Ent
);
4141 -- Flag the default_iterator as well as the denoted function.
4143 if not Valid_Default_Iterator
(Entity
(Expr
)) then
4144 Error_Msg_N
("improper function for default iterator!", Expr
);
4154 Get_First_Interp
(Expr
, I
, It
);
4155 while Present
(It
.Nam
) loop
4156 if not Check_Primitive_Function
(It
.Nam
)
4157 or else not Valid_Default_Iterator
(It
.Nam
)
4161 elsif Present
(Default
) then
4162 Error_Msg_N
("default iterator must be unique", Expr
);
4168 Get_Next_Interp
(I
, It
);
4172 if Present
(Default
) then
4173 Set_Entity
(Expr
, Default
);
4174 Set_Is_Overloaded
(Expr
, False);
4177 end Check_Iterator_Functions
;
4179 -------------------------------
4180 -- Check_Primitive_Function --
4181 -------------------------------
4183 function Check_Primitive_Function
(Subp
: Entity_Id
) return Boolean is
4187 if Ekind
(Subp
) /= E_Function
then
4191 if No
(First_Formal
(Subp
)) then
4194 Ctrl
:= Etype
(First_Formal
(Subp
));
4197 -- To be a primitive operation subprogram has to be in same scope.
4199 if Scope
(Ctrl
) /= Scope
(Subp
) then
4203 -- Type of formal may be the class-wide type, an access to such,
4204 -- or an incomplete view.
4207 or else Ctrl
= Class_Wide_Type
(Ent
)
4209 (Ekind
(Ctrl
) = E_Anonymous_Access_Type
4210 and then (Designated_Type
(Ctrl
) = Ent
4212 Designated_Type
(Ctrl
) = Class_Wide_Type
(Ent
)))
4214 (Ekind
(Ctrl
) = E_Incomplete_Type
4215 and then Full_View
(Ctrl
) = Ent
)
4223 end Check_Primitive_Function
;
4225 ----------------------
4226 -- Duplicate_Clause --
4227 ----------------------
4229 function Duplicate_Clause
return Boolean is
4233 -- Nothing to do if this attribute definition clause comes from
4234 -- an aspect specification, since we could not be duplicating an
4235 -- explicit clause, and we dealt with the case of duplicated aspects
4236 -- in Analyze_Aspect_Specifications.
4238 if From_Aspect_Specification
(N
) then
4242 -- Otherwise current clause may duplicate previous clause, or a
4243 -- previously given pragma or aspect specification for the same
4246 A
:= Get_Rep_Item
(U_Ent
, Chars
(N
), Check_Parents
=> False);
4249 Error_Msg_Name_1
:= Chars
(N
);
4250 Error_Msg_Sloc
:= Sloc
(A
);
4252 Error_Msg_NE
("aspect% for & previously given#", N
, U_Ent
);
4257 end Duplicate_Clause
;
4259 -- Start of processing for Analyze_Attribute_Definition_Clause
4262 -- The following code is a defense against recursion. Not clear that
4263 -- this can happen legitimately, but perhaps some error situations can
4264 -- cause it, and we did see this recursion during testing.
4266 if Analyzed
(N
) then
4269 Set_Analyzed
(N
, True);
4272 -- Ignore some selected attributes in CodePeer mode since they are not
4273 -- relevant in this context.
4275 if CodePeer_Mode
then
4278 -- Ignore Component_Size in CodePeer mode, to avoid changing the
4279 -- internal representation of types by implicitly packing them.
4281 when Attribute_Component_Size
=>
4282 Rewrite
(N
, Make_Null_Statement
(Sloc
(N
)));
4290 -- Process Ignore_Rep_Clauses option
4292 if Ignore_Rep_Clauses
then
4295 -- The following should be ignored. They do not affect legality
4296 -- and may be target dependent. The basic idea of -gnatI is to
4297 -- ignore any rep clauses that may be target dependent but do not
4298 -- affect legality (except possibly to be rejected because they
4299 -- are incompatible with the compilation target).
4301 when Attribute_Alignment |
4302 Attribute_Bit_Order |
4303 Attribute_Component_Size |
4304 Attribute_Machine_Radix |
4305 Attribute_Object_Size |
4308 Attribute_Stream_Size |
4309 Attribute_Value_Size
=>
4310 Kill_Rep_Clause
(N
);
4313 -- The following should not be ignored, because in the first place
4314 -- they are reasonably portable, and should not cause problems
4315 -- in compiling code from another target, and also they do affect
4316 -- legality, e.g. failing to provide a stream attribute for a type
4317 -- may make a program illegal.
4319 when Attribute_External_Tag |
4323 Attribute_Simple_Storage_Pool |
4324 Attribute_Storage_Pool |
4325 Attribute_Storage_Size |
4329 -- We do not do anything here with address clauses, they will be
4330 -- removed by Freeze later on, but for now, it works better to
4331 -- keep then in the tree.
4333 when Attribute_Address
=>
4336 -- Other cases are errors ("attribute& cannot be set with
4337 -- definition clause"), which will be caught below.
4345 Ent
:= Entity
(Nam
);
4347 if Rep_Item_Too_Early
(Ent
, N
) then
4351 -- Rep clause applies to full view of incomplete type or private type if
4352 -- we have one (if not, this is a premature use of the type). However,
4353 -- certain semantic checks need to be done on the specified entity (i.e.
4354 -- the private view), so we save it in Ent.
4356 if Is_Private_Type
(Ent
)
4357 and then Is_Derived_Type
(Ent
)
4358 and then not Is_Tagged_Type
(Ent
)
4359 and then No
(Full_View
(Ent
))
4361 -- If this is a private type whose completion is a derivation from
4362 -- another private type, there is no full view, and the attribute
4363 -- belongs to the type itself, not its underlying parent.
4367 elsif Ekind
(Ent
) = E_Incomplete_Type
then
4369 -- The attribute applies to the full view, set the entity of the
4370 -- attribute definition accordingly.
4372 Ent
:= Underlying_Type
(Ent
);
4374 Set_Entity
(Nam
, Ent
);
4377 U_Ent
:= Underlying_Type
(Ent
);
4380 -- Avoid cascaded error
4382 if Etype
(Nam
) = Any_Type
then
4385 -- Must be declared in current scope or in case of an aspect
4386 -- specification, must be visible in current scope.
4388 elsif Scope
(Ent
) /= Current_Scope
4390 not (From_Aspect_Specification
(N
)
4391 and then Scope_Within_Or_Same
(Current_Scope
, Scope
(Ent
)))
4393 Error_Msg_N
("entity must be declared in this scope", Nam
);
4396 -- Must not be a source renaming (we do have some cases where the
4397 -- expander generates a renaming, and those cases are OK, in such
4398 -- cases any attribute applies to the renamed object as well).
4400 elsif Is_Object
(Ent
)
4401 and then Present
(Renamed_Object
(Ent
))
4403 -- Case of renamed object from source, this is an error
4405 if Comes_From_Source
(Renamed_Object
(Ent
)) then
4406 Get_Name_String
(Chars
(N
));
4407 Error_Msg_Strlen
:= Name_Len
;
4408 Error_Msg_String
(1 .. Name_Len
) := Name_Buffer
(1 .. Name_Len
);
4410 ("~ clause not allowed for a renaming declaration "
4411 & "(RM 13.1(6))", Nam
);
4414 -- For the case of a compiler generated renaming, the attribute
4415 -- definition clause applies to the renamed object created by the
4416 -- expander. The easiest general way to handle this is to create a
4417 -- copy of the attribute definition clause for this object.
4419 elsif Is_Entity_Name
(Renamed_Object
(Ent
)) then
4421 Make_Attribute_Definition_Clause
(Loc
,
4423 New_Occurrence_Of
(Entity
(Renamed_Object
(Ent
)), Loc
),
4425 Expression
=> Duplicate_Subexpr
(Expression
(N
))));
4427 -- If the renamed object is not an entity, it must be a dereference
4428 -- of an unconstrained function call, and we must introduce a new
4429 -- declaration to capture the expression. This is needed in the case
4430 -- of 'Alignment, where the original declaration must be rewritten.
4434 (Nkind
(Renamed_Object
(Ent
)) = N_Explicit_Dereference
);
4438 -- If no underlying entity, use entity itself, applies to some
4439 -- previously detected error cases ???
4441 elsif No
(U_Ent
) then
4444 -- Cannot specify for a subtype (exception Object/Value_Size)
4446 elsif Is_Type
(U_Ent
)
4447 and then not Is_First_Subtype
(U_Ent
)
4448 and then Id
/= Attribute_Object_Size
4449 and then Id
/= Attribute_Value_Size
4450 and then not From_At_Mod
(N
)
4452 Error_Msg_N
("cannot specify attribute for subtype", Nam
);
4456 Set_Entity
(N
, U_Ent
);
4457 Check_Restriction_No_Use_Of_Attribute
(N
);
4459 -- Switch on particular attribute
4467 -- Address attribute definition clause
4469 when Attribute_Address
=> Address
: begin
4471 -- A little error check, catch for X'Address use X'Address;
4473 if Nkind
(Nam
) = N_Identifier
4474 and then Nkind
(Expr
) = N_Attribute_Reference
4475 and then Attribute_Name
(Expr
) = Name_Address
4476 and then Nkind
(Prefix
(Expr
)) = N_Identifier
4477 and then Chars
(Nam
) = Chars
(Prefix
(Expr
))
4480 ("address for & is self-referencing", Prefix
(Expr
), Ent
);
4484 -- Not that special case, carry on with analysis of expression
4486 Analyze_And_Resolve
(Expr
, RTE
(RE_Address
));
4488 -- Even when ignoring rep clauses we need to indicate that the
4489 -- entity has an address clause and thus it is legal to declare
4490 -- it imported. Freeze will get rid of the address clause later.
4492 if Ignore_Rep_Clauses
then
4493 if Ekind_In
(U_Ent
, E_Variable
, E_Constant
) then
4494 Record_Rep_Item
(U_Ent
, N
);
4500 if Duplicate_Clause
then
4503 -- Case of address clause for subprogram
4505 elsif Is_Subprogram
(U_Ent
) then
4506 if Has_Homonym
(U_Ent
) then
4508 ("address clause cannot be given " &
4509 "for overloaded subprogram",
4514 -- For subprograms, all address clauses are permitted, and we
4515 -- mark the subprogram as having a deferred freeze so that Gigi
4516 -- will not elaborate it too soon.
4518 -- Above needs more comments, what is too soon about???
4520 Set_Has_Delayed_Freeze
(U_Ent
);
4522 -- Case of address clause for entry
4524 elsif Ekind
(U_Ent
) = E_Entry
then
4525 if Nkind
(Parent
(N
)) = N_Task_Body
then
4527 ("entry address must be specified in task spec", Nam
);
4531 -- For entries, we require a constant address
4533 Check_Constant_Address_Clause
(Expr
, U_Ent
);
4535 -- Special checks for task types
4537 if Is_Task_Type
(Scope
(U_Ent
))
4538 and then Comes_From_Source
(Scope
(U_Ent
))
4541 ("??entry address declared for entry in task type", N
);
4543 ("\??only one task can be declared of this type", N
);
4546 -- Entry address clauses are obsolescent
4548 Check_Restriction
(No_Obsolescent_Features
, N
);
4550 if Warn_On_Obsolescent_Feature
then
4552 ("?j?attaching interrupt to task entry is an " &
4553 "obsolescent feature (RM J.7.1)", N
);
4555 ("\?j?use interrupt procedure instead", N
);
4558 -- Case of an address clause for a controlled object which we
4559 -- consider to be erroneous.
4561 elsif Is_Controlled
(Etype
(U_Ent
))
4562 or else Has_Controlled_Component
(Etype
(U_Ent
))
4565 ("??controlled object& must not be overlaid", Nam
, U_Ent
);
4567 ("\??Program_Error will be raised at run time", Nam
);
4568 Insert_Action
(Declaration_Node
(U_Ent
),
4569 Make_Raise_Program_Error
(Loc
,
4570 Reason
=> PE_Overlaid_Controlled_Object
));
4573 -- Case of address clause for a (non-controlled) object
4575 elsif Ekind_In
(U_Ent
, E_Variable
, E_Constant
) then
4577 Expr
: constant Node_Id
:= Expression
(N
);
4582 -- Exported variables cannot have an address clause, because
4583 -- this cancels the effect of the pragma Export.
4585 if Is_Exported
(U_Ent
) then
4587 ("cannot export object with address clause", Nam
);
4591 Find_Overlaid_Entity
(N
, O_Ent
, Off
);
4593 -- Overlaying controlled objects is erroneous
4596 and then (Has_Controlled_Component
(Etype
(O_Ent
))
4597 or else Is_Controlled
(Etype
(O_Ent
)))
4600 ("??cannot overlay with controlled object", Expr
);
4602 ("\??Program_Error will be raised at run time", Expr
);
4603 Insert_Action
(Declaration_Node
(U_Ent
),
4604 Make_Raise_Program_Error
(Loc
,
4605 Reason
=> PE_Overlaid_Controlled_Object
));
4608 elsif Present
(O_Ent
)
4609 and then Ekind
(U_Ent
) = E_Constant
4610 and then not Is_Constant_Object
(O_Ent
)
4612 Error_Msg_N
("??constant overlays a variable", Expr
);
4614 -- Imported variables can have an address clause, but then
4615 -- the import is pretty meaningless except to suppress
4616 -- initializations, so we do not need such variables to
4617 -- be statically allocated (and in fact it causes trouble
4618 -- if the address clause is a local value).
4620 elsif Is_Imported
(U_Ent
) then
4621 Set_Is_Statically_Allocated
(U_Ent
, False);
4624 -- We mark a possible modification of a variable with an
4625 -- address clause, since it is likely aliasing is occurring.
4627 Note_Possible_Modification
(Nam
, Sure
=> False);
4629 -- Here we are checking for explicit overlap of one variable
4630 -- by another, and if we find this then mark the overlapped
4631 -- variable as also being volatile to prevent unwanted
4632 -- optimizations. This is a significant pessimization so
4633 -- avoid it when there is an offset, i.e. when the object
4634 -- is composite; they cannot be optimized easily anyway.
4637 and then Is_Object
(O_Ent
)
4640 -- The following test is an expedient solution to what
4641 -- is really a problem in CodePeer. Suppressing the
4642 -- Set_Treat_As_Volatile call here prevents later
4643 -- generation (in some cases) of trees that CodePeer
4644 -- should, but currently does not, handle correctly.
4645 -- This test should probably be removed when CodePeer
4646 -- is improved, just because we want the tree CodePeer
4647 -- analyzes to match the tree for which we generate code
4648 -- as closely as is practical. ???
4650 and then not CodePeer_Mode
4652 -- ??? O_Ent might not be in current unit
4654 Set_Treat_As_Volatile
(O_Ent
);
4657 -- Legality checks on the address clause for initialized
4658 -- objects is deferred until the freeze point, because
4659 -- a subsequent pragma might indicate that the object
4660 -- is imported and thus not initialized. Also, the address
4661 -- clause might involve entities that have yet to be
4664 Set_Has_Delayed_Freeze
(U_Ent
);
4666 -- If an initialization call has been generated for this
4667 -- object, it needs to be deferred to after the freeze node
4668 -- we have just now added, otherwise GIGI will see a
4669 -- reference to the variable (as actual to the IP call)
4670 -- before its definition.
4673 Init_Call
: constant Node_Id
:=
4674 Remove_Init_Call
(U_Ent
, N
);
4677 if Present
(Init_Call
) then
4678 Append_Freeze_Action
(U_Ent
, Init_Call
);
4680 -- Reset Initialization_Statements pointer so that
4681 -- if there is a pragma Import further down, it can
4682 -- clear any default initialization.
4684 Set_Initialization_Statements
(U_Ent
, Init_Call
);
4688 if Is_Exported
(U_Ent
) then
4690 ("& cannot be exported if an address clause is given",
4693 ("\define and export a variable "
4694 & "that holds its address instead", Nam
);
4697 -- Entity has delayed freeze, so we will generate an
4698 -- alignment check at the freeze point unless suppressed.
4700 if not Range_Checks_Suppressed
(U_Ent
)
4701 and then not Alignment_Checks_Suppressed
(U_Ent
)
4703 Set_Check_Address_Alignment
(N
);
4706 -- Kill the size check code, since we are not allocating
4707 -- the variable, it is somewhere else.
4709 Kill_Size_Check_Code
(U_Ent
);
4711 -- If the address clause is of the form:
4713 -- for Y'Address use X'Address
4717 -- Const : constant Address := X'Address;
4719 -- for Y'Address use Const;
4721 -- then we make an entry in the table for checking the size
4722 -- and alignment of the overlaying variable. We defer this
4723 -- check till after code generation to take full advantage
4724 -- of the annotation done by the back end.
4726 -- If the entity has a generic type, the check will be
4727 -- performed in the instance if the actual type justifies
4728 -- it, and we do not insert the clause in the table to
4729 -- prevent spurious warnings.
4731 -- Note: we used to test Comes_From_Source and only give
4732 -- this warning for source entities, but we have removed
4733 -- this test. It really seems bogus to generate overlays
4734 -- that would trigger this warning in generated code.
4735 -- Furthermore, by removing the test, we handle the
4736 -- aspect case properly.
4738 if Address_Clause_Overlay_Warnings
4739 and then Present
(O_Ent
)
4740 and then Is_Object
(O_Ent
)
4742 if not Is_Generic_Type
(Etype
(U_Ent
)) then
4743 Address_Clause_Checks
.Append
((N
, U_Ent
, O_Ent
, Off
));
4746 -- If variable overlays a constant view, and we are
4747 -- warning on overlays, then mark the variable as
4748 -- overlaying a constant (we will give warnings later
4749 -- if this variable is assigned).
4751 if Is_Constant_Object
(O_Ent
)
4752 and then Ekind
(U_Ent
) = E_Variable
4754 Set_Overlays_Constant
(U_Ent
);
4759 -- Not a valid entity for an address clause
4762 Error_Msg_N
("address cannot be given for &", Nam
);
4770 -- Alignment attribute definition clause
4772 when Attribute_Alignment
=> Alignment
: declare
4773 Align
: constant Uint
:= Get_Alignment_Value
(Expr
);
4774 Max_Align
: constant Uint
:= UI_From_Int
(Maximum_Alignment
);
4779 if not Is_Type
(U_Ent
)
4780 and then Ekind
(U_Ent
) /= E_Variable
4781 and then Ekind
(U_Ent
) /= E_Constant
4783 Error_Msg_N
("alignment cannot be given for &", Nam
);
4785 elsif Duplicate_Clause
then
4788 elsif Align
/= No_Uint
then
4789 Set_Has_Alignment_Clause
(U_Ent
);
4791 -- Tagged type case, check for attempt to set alignment to a
4792 -- value greater than Max_Align, and reset if so.
4794 if Is_Tagged_Type
(U_Ent
) and then Align
> Max_Align
then
4796 ("alignment for & set to Maximum_Aligment??", Nam
);
4797 Set_Alignment
(U_Ent
, Max_Align
);
4802 Set_Alignment
(U_Ent
, Align
);
4805 -- For an array type, U_Ent is the first subtype. In that case,
4806 -- also set the alignment of the anonymous base type so that
4807 -- other subtypes (such as the itypes for aggregates of the
4808 -- type) also receive the expected alignment.
4810 if Is_Array_Type
(U_Ent
) then
4811 Set_Alignment
(Base_Type
(U_Ent
), Align
);
4820 -- Bit_Order attribute definition clause
4822 when Attribute_Bit_Order
=> Bit_Order
: declare
4824 if not Is_Record_Type
(U_Ent
) then
4826 ("Bit_Order can only be defined for record type", Nam
);
4828 elsif Duplicate_Clause
then
4832 Analyze_And_Resolve
(Expr
, RTE
(RE_Bit_Order
));
4834 if Etype
(Expr
) = Any_Type
then
4837 elsif not Is_OK_Static_Expression
(Expr
) then
4838 Flag_Non_Static_Expr
4839 ("Bit_Order requires static expression!", Expr
);
4842 if (Expr_Value
(Expr
) = 0) /= Bytes_Big_Endian
then
4843 Set_Reverse_Bit_Order
(Base_Type
(U_Ent
), True);
4849 --------------------
4850 -- Component_Size --
4851 --------------------
4853 -- Component_Size attribute definition clause
4855 when Attribute_Component_Size
=> Component_Size_Case
: declare
4856 Csize
: constant Uint
:= Static_Integer
(Expr
);
4860 New_Ctyp
: Entity_Id
;
4864 if not Is_Array_Type
(U_Ent
) then
4865 Error_Msg_N
("component size requires array type", Nam
);
4869 Btype
:= Base_Type
(U_Ent
);
4870 Ctyp
:= Component_Type
(Btype
);
4872 if Duplicate_Clause
then
4875 elsif Rep_Item_Too_Early
(Btype
, N
) then
4878 elsif Csize
/= No_Uint
then
4879 Check_Size
(Expr
, Ctyp
, Csize
, Biased
);
4881 -- For the biased case, build a declaration for a subtype that
4882 -- will be used to represent the biased subtype that reflects
4883 -- the biased representation of components. We need the subtype
4884 -- to get proper conversions on referencing elements of the
4885 -- array. Note: component size clauses are ignored in VM mode.
4887 if VM_Target
= No_VM
then
4890 Make_Defining_Identifier
(Loc
,
4892 New_External_Name
(Chars
(U_Ent
), 'C', 0, 'T'));
4895 Make_Subtype_Declaration
(Loc
,
4896 Defining_Identifier
=> New_Ctyp
,
4897 Subtype_Indication
=>
4898 New_Occurrence_Of
(Component_Type
(Btype
), Loc
));
4900 Set_Parent
(Decl
, N
);
4901 Analyze
(Decl
, Suppress
=> All_Checks
);
4903 Set_Has_Delayed_Freeze
(New_Ctyp
, False);
4904 Set_Esize
(New_Ctyp
, Csize
);
4905 Set_RM_Size
(New_Ctyp
, Csize
);
4906 Init_Alignment
(New_Ctyp
);
4907 Set_Is_Itype
(New_Ctyp
, True);
4908 Set_Associated_Node_For_Itype
(New_Ctyp
, U_Ent
);
4910 Set_Component_Type
(Btype
, New_Ctyp
);
4911 Set_Biased
(New_Ctyp
, N
, "component size clause");
4914 Set_Component_Size
(Btype
, Csize
);
4916 -- For VM case, we ignore component size clauses
4919 -- Give a warning unless we are in GNAT mode, in which case
4920 -- the warning is suppressed since it is not useful.
4922 if not GNAT_Mode
then
4924 ("component size ignored in this configuration??", N
);
4928 -- Deal with warning on overridden size
4930 if Warn_On_Overridden_Size
4931 and then Has_Size_Clause
(Ctyp
)
4932 and then RM_Size
(Ctyp
) /= Csize
4935 ("component size overrides size clause for&?S?", N
, Ctyp
);
4938 Set_Has_Component_Size_Clause
(Btype
, True);
4939 Set_Has_Non_Standard_Rep
(Btype
, True);
4941 end Component_Size_Case
;
4943 -----------------------
4944 -- Constant_Indexing --
4945 -----------------------
4947 when Attribute_Constant_Indexing
=>
4948 Check_Indexing_Functions
;
4954 when Attribute_CPU
=> CPU
:
4956 -- CPU attribute definition clause not allowed except from aspect
4959 if From_Aspect_Specification
(N
) then
4960 if not Is_Task_Type
(U_Ent
) then
4961 Error_Msg_N
("CPU can only be defined for task", Nam
);
4963 elsif Duplicate_Clause
then
4967 -- The expression must be analyzed in the special manner
4968 -- described in "Handling of Default and Per-Object
4969 -- Expressions" in sem.ads.
4971 -- The visibility to the discriminants must be restored
4973 Push_Scope_And_Install_Discriminants
(U_Ent
);
4974 Preanalyze_Spec_Expression
(Expr
, RTE
(RE_CPU_Range
));
4975 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
4977 if not Is_OK_Static_Expression
(Expr
) then
4978 Check_Restriction
(Static_Priorities
, Expr
);
4984 ("attribute& cannot be set with definition clause", N
);
4988 ----------------------
4989 -- Default_Iterator --
4990 ----------------------
4992 when Attribute_Default_Iterator
=> Default_Iterator
: declare
4997 -- If target type is untagged, further checks are irrelevant
4999 if not Is_Tagged_Type
(U_Ent
) then
5001 ("aspect Default_Iterator applies to tagged type", Nam
);
5005 Check_Iterator_Functions
;
5009 if not Is_Entity_Name
(Expr
)
5010 or else Ekind
(Entity
(Expr
)) /= E_Function
5012 Error_Msg_N
("aspect Iterator must be a function", Expr
);
5015 Func
:= Entity
(Expr
);
5018 -- The type of the first parameter must be T, T'class, or a
5019 -- corresponding access type (5.5.1 (8/3). If function is
5020 -- parameterless label type accordingly.
5022 if No
(First_Formal
(Func
)) then
5025 Typ
:= Etype
(First_Formal
(Func
));
5029 or else Typ
= Class_Wide_Type
(U_Ent
)
5030 or else (Is_Access_Type
(Typ
)
5031 and then Designated_Type
(Typ
) = U_Ent
)
5032 or else (Is_Access_Type
(Typ
)
5033 and then Designated_Type
(Typ
) =
5034 Class_Wide_Type
(U_Ent
))
5040 ("Default Iterator must be a primitive of&", Func
, U_Ent
);
5042 end Default_Iterator
;
5044 ------------------------
5045 -- Dispatching_Domain --
5046 ------------------------
5048 when Attribute_Dispatching_Domain
=> Dispatching_Domain
:
5050 -- Dispatching_Domain attribute definition clause not allowed
5051 -- except from aspect specification.
5053 if From_Aspect_Specification
(N
) then
5054 if not Is_Task_Type
(U_Ent
) then
5056 ("Dispatching_Domain can only be defined for task", Nam
);
5058 elsif Duplicate_Clause
then
5062 -- The expression must be analyzed in the special manner
5063 -- described in "Handling of Default and Per-Object
5064 -- Expressions" in sem.ads.
5066 -- The visibility to the discriminants must be restored
5068 Push_Scope_And_Install_Discriminants
(U_Ent
);
5070 Preanalyze_Spec_Expression
5071 (Expr
, RTE
(RE_Dispatching_Domain
));
5073 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
5078 ("attribute& cannot be set with definition clause", N
);
5080 end Dispatching_Domain
;
5086 when Attribute_External_Tag
=> External_Tag
:
5088 if not Is_Tagged_Type
(U_Ent
) then
5089 Error_Msg_N
("should be a tagged type", Nam
);
5092 if Duplicate_Clause
then
5096 Analyze_And_Resolve
(Expr
, Standard_String
);
5098 if not Is_OK_Static_Expression
(Expr
) then
5099 Flag_Non_Static_Expr
5100 ("static string required for tag name!", Nam
);
5103 if VM_Target
/= No_VM
then
5104 Error_Msg_Name_1
:= Attr
;
5106 ("% attribute unsupported in this configuration", Nam
);
5109 if not Is_Library_Level_Entity
(U_Ent
) then
5111 ("??non-unique external tag supplied for &", N
, U_Ent
);
5113 ("\??same external tag applies to all "
5114 & "subprogram calls", N
);
5116 ("\??corresponding internal tag cannot be obtained", N
);
5121 --------------------------
5122 -- Implicit_Dereference --
5123 --------------------------
5125 when Attribute_Implicit_Dereference
=>
5127 -- Legality checks already performed at the point of the type
5128 -- declaration, aspect is not delayed.
5136 when Attribute_Input
=>
5137 Analyze_Stream_TSS_Definition
(TSS_Stream_Input
);
5138 Set_Has_Specified_Stream_Input
(Ent
);
5140 ------------------------
5141 -- Interrupt_Priority --
5142 ------------------------
5144 when Attribute_Interrupt_Priority
=> Interrupt_Priority
:
5146 -- Interrupt_Priority attribute definition clause not allowed
5147 -- except from aspect specification.
5149 if From_Aspect_Specification
(N
) then
5150 if not Is_Concurrent_Type
(U_Ent
) then
5152 ("Interrupt_Priority can only be defined for task "
5153 & "and protected object", Nam
);
5155 elsif Duplicate_Clause
then
5159 -- The expression must be analyzed in the special manner
5160 -- described in "Handling of Default and Per-Object
5161 -- Expressions" in sem.ads.
5163 -- The visibility to the discriminants must be restored
5165 Push_Scope_And_Install_Discriminants
(U_Ent
);
5167 Preanalyze_Spec_Expression
5168 (Expr
, RTE
(RE_Interrupt_Priority
));
5170 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
5175 ("attribute& cannot be set with definition clause", N
);
5177 end Interrupt_Priority
;
5183 when Attribute_Iterable
=>
5186 if Nkind
(Expr
) /= N_Aggregate
then
5187 Error_Msg_N
("aspect Iterable must be an aggregate", Expr
);
5194 Assoc
:= First
(Component_Associations
(Expr
));
5195 while Present
(Assoc
) loop
5196 if not Is_Entity_Name
(Expression
(Assoc
)) then
5197 Error_Msg_N
("value must be a function", Assoc
);
5204 ----------------------
5205 -- Iterator_Element --
5206 ----------------------
5208 when Attribute_Iterator_Element
=>
5211 if not Is_Entity_Name
(Expr
)
5212 or else not Is_Type
(Entity
(Expr
))
5214 Error_Msg_N
("aspect Iterator_Element must be a type", Expr
);
5221 -- Machine radix attribute definition clause
5223 when Attribute_Machine_Radix
=> Machine_Radix
: declare
5224 Radix
: constant Uint
:= Static_Integer
(Expr
);
5227 if not Is_Decimal_Fixed_Point_Type
(U_Ent
) then
5228 Error_Msg_N
("decimal fixed-point type expected for &", Nam
);
5230 elsif Duplicate_Clause
then
5233 elsif Radix
/= No_Uint
then
5234 Set_Has_Machine_Radix_Clause
(U_Ent
);
5235 Set_Has_Non_Standard_Rep
(Base_Type
(U_Ent
));
5239 elsif Radix
= 10 then
5240 Set_Machine_Radix_10
(U_Ent
);
5242 Error_Msg_N
("machine radix value must be 2 or 10", Expr
);
5251 -- Object_Size attribute definition clause
5253 when Attribute_Object_Size
=> Object_Size
: declare
5254 Size
: constant Uint
:= Static_Integer
(Expr
);
5257 pragma Warnings
(Off
, Biased
);
5260 if not Is_Type
(U_Ent
) then
5261 Error_Msg_N
("Object_Size cannot be given for &", Nam
);
5263 elsif Duplicate_Clause
then
5267 Check_Size
(Expr
, U_Ent
, Size
, Biased
);
5269 if Is_Scalar_Type
(U_Ent
) then
5270 if Size
/= 8 and then Size
/= 16 and then Size
/= 32
5271 and then UI_Mod
(Size
, 64) /= 0
5274 ("Object_Size must be 8, 16, 32, or multiple of 64",
5278 elsif Size
mod 8 /= 0 then
5279 Error_Msg_N
("Object_Size must be a multiple of 8", Expr
);
5282 Set_Esize
(U_Ent
, Size
);
5283 Set_Has_Object_Size_Clause
(U_Ent
);
5284 Alignment_Check_For_Size_Change
(U_Ent
, Size
);
5292 when Attribute_Output
=>
5293 Analyze_Stream_TSS_Definition
(TSS_Stream_Output
);
5294 Set_Has_Specified_Stream_Output
(Ent
);
5300 when Attribute_Priority
=> Priority
:
5302 -- Priority attribute definition clause not allowed except from
5303 -- aspect specification.
5305 if From_Aspect_Specification
(N
) then
5306 if not (Is_Concurrent_Type
(U_Ent
)
5307 or else Ekind
(U_Ent
) = E_Procedure
)
5310 ("Priority can only be defined for task and protected "
5313 elsif Duplicate_Clause
then
5317 -- The expression must be analyzed in the special manner
5318 -- described in "Handling of Default and Per-Object
5319 -- Expressions" in sem.ads.
5321 -- The visibility to the discriminants must be restored
5323 Push_Scope_And_Install_Discriminants
(U_Ent
);
5324 Preanalyze_Spec_Expression
(Expr
, Standard_Integer
);
5325 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
5327 if not Is_OK_Static_Expression
(Expr
) then
5328 Check_Restriction
(Static_Priorities
, Expr
);
5334 ("attribute& cannot be set with definition clause", N
);
5342 when Attribute_Read
=>
5343 Analyze_Stream_TSS_Definition
(TSS_Stream_Read
);
5344 Set_Has_Specified_Stream_Read
(Ent
);
5346 --------------------------
5347 -- Scalar_Storage_Order --
5348 --------------------------
5350 -- Scalar_Storage_Order attribute definition clause
5352 when Attribute_Scalar_Storage_Order
=> Scalar_Storage_Order
: declare
5354 if not (Is_Record_Type
(U_Ent
) or else Is_Array_Type
(U_Ent
)) then
5356 ("Scalar_Storage_Order can only be defined for "
5357 & "record or array type", Nam
);
5359 elsif Duplicate_Clause
then
5363 Analyze_And_Resolve
(Expr
, RTE
(RE_Bit_Order
));
5365 if Etype
(Expr
) = Any_Type
then
5368 elsif not Is_OK_Static_Expression
(Expr
) then
5369 Flag_Non_Static_Expr
5370 ("Scalar_Storage_Order requires static expression!", Expr
);
5372 elsif (Expr_Value
(Expr
) = 0) /= Bytes_Big_Endian
then
5374 -- Here for the case of a non-default (i.e. non-confirming)
5375 -- Scalar_Storage_Order attribute definition.
5377 if Support_Nondefault_SSO_On_Target
then
5378 Set_Reverse_Storage_Order
(Base_Type
(U_Ent
), True);
5381 ("non-default Scalar_Storage_Order "
5382 & "not supported on target", Expr
);
5386 -- Clear SSO default indications since explicit setting of the
5387 -- order overrides the defaults.
5389 Set_SSO_Set_Low_By_Default
(Base_Type
(U_Ent
), False);
5390 Set_SSO_Set_High_By_Default
(Base_Type
(U_Ent
), False);
5392 end Scalar_Storage_Order
;
5398 -- Size attribute definition clause
5400 when Attribute_Size
=> Size
: declare
5401 Size
: constant Uint
:= Static_Integer
(Expr
);
5408 if Duplicate_Clause
then
5411 elsif not Is_Type
(U_Ent
)
5412 and then Ekind
(U_Ent
) /= E_Variable
5413 and then Ekind
(U_Ent
) /= E_Constant
5415 Error_Msg_N
("size cannot be given for &", Nam
);
5417 elsif Is_Array_Type
(U_Ent
)
5418 and then not Is_Constrained
(U_Ent
)
5421 ("size cannot be given for unconstrained array", Nam
);
5423 elsif Size
/= No_Uint
then
5424 if VM_Target
/= No_VM
and then not GNAT_Mode
then
5426 -- Size clause is not handled properly on VM targets.
5427 -- Display a warning unless we are in GNAT mode, in which
5428 -- case this is useless.
5431 ("size clauses are ignored in this configuration??", N
);
5434 if Is_Type
(U_Ent
) then
5437 Etyp
:= Etype
(U_Ent
);
5440 -- Check size, note that Gigi is in charge of checking that the
5441 -- size of an array or record type is OK. Also we do not check
5442 -- the size in the ordinary fixed-point case, since it is too
5443 -- early to do so (there may be subsequent small clause that
5444 -- affects the size). We can check the size if a small clause
5445 -- has already been given.
5447 if not Is_Ordinary_Fixed_Point_Type
(U_Ent
)
5448 or else Has_Small_Clause
(U_Ent
)
5450 Check_Size
(Expr
, Etyp
, Size
, Biased
);
5451 Set_Biased
(U_Ent
, N
, "size clause", Biased
);
5454 -- For types set RM_Size and Esize if possible
5456 if Is_Type
(U_Ent
) then
5457 Set_RM_Size
(U_Ent
, Size
);
5459 -- For elementary types, increase Object_Size to power of 2,
5460 -- but not less than a storage unit in any case (normally
5461 -- this means it will be byte addressable).
5463 -- For all other types, nothing else to do, we leave Esize
5464 -- (object size) unset, the back end will set it from the
5465 -- size and alignment in an appropriate manner.
5467 -- In both cases, we check whether the alignment must be
5468 -- reset in the wake of the size change.
5470 if Is_Elementary_Type
(U_Ent
) then
5471 if Size
<= System_Storage_Unit
then
5472 Init_Esize
(U_Ent
, System_Storage_Unit
);
5473 elsif Size
<= 16 then
5474 Init_Esize
(U_Ent
, 16);
5475 elsif Size
<= 32 then
5476 Init_Esize
(U_Ent
, 32);
5478 Set_Esize
(U_Ent
, (Size
+ 63) / 64 * 64);
5481 Alignment_Check_For_Size_Change
(U_Ent
, Esize
(U_Ent
));
5483 Alignment_Check_For_Size_Change
(U_Ent
, Size
);
5486 -- For objects, set Esize only
5489 if Is_Elementary_Type
(Etyp
) then
5490 if Size
/= System_Storage_Unit
5492 Size
/= System_Storage_Unit
* 2
5494 Size
/= System_Storage_Unit
* 4
5496 Size
/= System_Storage_Unit
* 8
5498 Error_Msg_Uint_1
:= UI_From_Int
(System_Storage_Unit
);
5499 Error_Msg_Uint_2
:= Error_Msg_Uint_1
* 8;
5501 ("size for primitive object must be a power of 2"
5502 & " in the range ^-^", N
);
5506 Set_Esize
(U_Ent
, Size
);
5509 Set_Has_Size_Clause
(U_Ent
);
5517 -- Small attribute definition clause
5519 when Attribute_Small
=> Small
: declare
5520 Implicit_Base
: constant Entity_Id
:= Base_Type
(U_Ent
);
5524 Analyze_And_Resolve
(Expr
, Any_Real
);
5526 if Etype
(Expr
) = Any_Type
then
5529 elsif not Is_OK_Static_Expression
(Expr
) then
5530 Flag_Non_Static_Expr
5531 ("small requires static expression!", Expr
);
5535 Small
:= Expr_Value_R
(Expr
);
5537 if Small
<= Ureal_0
then
5538 Error_Msg_N
("small value must be greater than zero", Expr
);
5544 if not Is_Ordinary_Fixed_Point_Type
(U_Ent
) then
5546 ("small requires an ordinary fixed point type", Nam
);
5548 elsif Has_Small_Clause
(U_Ent
) then
5549 Error_Msg_N
("small already given for &", Nam
);
5551 elsif Small
> Delta_Value
(U_Ent
) then
5553 ("small value must not be greater than delta value", Nam
);
5556 Set_Small_Value
(U_Ent
, Small
);
5557 Set_Small_Value
(Implicit_Base
, Small
);
5558 Set_Has_Small_Clause
(U_Ent
);
5559 Set_Has_Small_Clause
(Implicit_Base
);
5560 Set_Has_Non_Standard_Rep
(Implicit_Base
);
5568 -- Storage_Pool attribute definition clause
5570 when Attribute_Storage_Pool | Attribute_Simple_Storage_Pool
=> declare
5575 if Ekind
(U_Ent
) = E_Access_Subprogram_Type
then
5577 ("storage pool cannot be given for access-to-subprogram type",
5582 Ekind_In
(U_Ent
, E_Access_Type
, E_General_Access_Type
)
5585 ("storage pool can only be given for access types", Nam
);
5588 elsif Is_Derived_Type
(U_Ent
) then
5590 ("storage pool cannot be given for a derived access type",
5593 elsif Duplicate_Clause
then
5596 elsif Present
(Associated_Storage_Pool
(U_Ent
)) then
5597 Error_Msg_N
("storage pool already given for &", Nam
);
5601 -- Check for Storage_Size previously given
5604 SS
: constant Node_Id
:=
5605 Get_Attribute_Definition_Clause
5606 (U_Ent
, Attribute_Storage_Size
);
5608 if Present
(SS
) then
5609 Check_Pool_Size_Clash
(U_Ent
, N
, SS
);
5613 -- Storage_Pool case
5615 if Id
= Attribute_Storage_Pool
then
5617 (Expr
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
5619 -- In the Simple_Storage_Pool case, we allow a variable of any
5620 -- simple storage pool type, so we Resolve without imposing an
5624 Analyze_And_Resolve
(Expr
);
5626 if not Present
(Get_Rep_Pragma
5627 (Etype
(Expr
), Name_Simple_Storage_Pool_Type
))
5630 ("expression must be of a simple storage pool type", Expr
);
5634 if not Denotes_Variable
(Expr
) then
5635 Error_Msg_N
("storage pool must be a variable", Expr
);
5639 if Nkind
(Expr
) = N_Type_Conversion
then
5640 T
:= Etype
(Expression
(Expr
));
5645 -- The Stack_Bounded_Pool is used internally for implementing
5646 -- access types with a Storage_Size. Since it only work properly
5647 -- when used on one specific type, we need to check that it is not
5648 -- hijacked improperly:
5650 -- type T is access Integer;
5651 -- for T'Storage_Size use n;
5652 -- type Q is access Float;
5653 -- for Q'Storage_Size use T'Storage_Size; -- incorrect
5655 if RTE_Available
(RE_Stack_Bounded_Pool
)
5656 and then Base_Type
(T
) = RTE
(RE_Stack_Bounded_Pool
)
5658 Error_Msg_N
("non-shareable internal Pool", Expr
);
5662 -- If the argument is a name that is not an entity name, then
5663 -- we construct a renaming operation to define an entity of
5664 -- type storage pool.
5666 if not Is_Entity_Name
(Expr
)
5667 and then Is_Object_Reference
(Expr
)
5669 Pool
:= Make_Temporary
(Loc
, 'P', Expr
);
5672 Rnode
: constant Node_Id
:=
5673 Make_Object_Renaming_Declaration
(Loc
,
5674 Defining_Identifier
=> Pool
,
5676 New_Occurrence_Of
(Etype
(Expr
), Loc
),
5680 -- If the attribute definition clause comes from an aspect
5681 -- clause, then insert the renaming before the associated
5682 -- entity's declaration, since the attribute clause has
5683 -- not yet been appended to the declaration list.
5685 if From_Aspect_Specification
(N
) then
5686 Insert_Before
(Parent
(Entity
(N
)), Rnode
);
5688 Insert_Before
(N
, Rnode
);
5692 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
5695 elsif Is_Entity_Name
(Expr
) then
5696 Pool
:= Entity
(Expr
);
5698 -- If pool is a renamed object, get original one. This can
5699 -- happen with an explicit renaming, and within instances.
5701 while Present
(Renamed_Object
(Pool
))
5702 and then Is_Entity_Name
(Renamed_Object
(Pool
))
5704 Pool
:= Entity
(Renamed_Object
(Pool
));
5707 if Present
(Renamed_Object
(Pool
))
5708 and then Nkind
(Renamed_Object
(Pool
)) = N_Type_Conversion
5709 and then Is_Entity_Name
(Expression
(Renamed_Object
(Pool
)))
5711 Pool
:= Entity
(Expression
(Renamed_Object
(Pool
)));
5714 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
5716 elsif Nkind
(Expr
) = N_Type_Conversion
5717 and then Is_Entity_Name
(Expression
(Expr
))
5718 and then Nkind
(Original_Node
(Expr
)) = N_Attribute_Reference
5720 Pool
:= Entity
(Expression
(Expr
));
5721 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
5724 Error_Msg_N
("incorrect reference to a Storage Pool", Expr
);
5733 -- Storage_Size attribute definition clause
5735 when Attribute_Storage_Size
=> Storage_Size
: declare
5736 Btype
: constant Entity_Id
:= Base_Type
(U_Ent
);
5739 if Is_Task_Type
(U_Ent
) then
5741 -- Check obsolescent (but never obsolescent if from aspect)
5743 if not From_Aspect_Specification
(N
) then
5744 Check_Restriction
(No_Obsolescent_Features
, N
);
5746 if Warn_On_Obsolescent_Feature
then
5748 ("?j?storage size clause for task is an " &
5749 "obsolescent feature (RM J.9)", N
);
5750 Error_Msg_N
("\?j?use Storage_Size pragma instead", N
);
5757 if not Is_Access_Type
(U_Ent
)
5758 and then Ekind
(U_Ent
) /= E_Task_Type
5760 Error_Msg_N
("storage size cannot be given for &", Nam
);
5762 elsif Is_Access_Type
(U_Ent
) and Is_Derived_Type
(U_Ent
) then
5764 ("storage size cannot be given for a derived access type",
5767 elsif Duplicate_Clause
then
5771 Analyze_And_Resolve
(Expr
, Any_Integer
);
5773 if Is_Access_Type
(U_Ent
) then
5775 -- Check for Storage_Pool previously given
5778 SP
: constant Node_Id
:=
5779 Get_Attribute_Definition_Clause
5780 (U_Ent
, Attribute_Storage_Pool
);
5783 if Present
(SP
) then
5784 Check_Pool_Size_Clash
(U_Ent
, SP
, N
);
5788 -- Special case of for x'Storage_Size use 0
5790 if Is_OK_Static_Expression
(Expr
)
5791 and then Expr_Value
(Expr
) = 0
5793 Set_No_Pool_Assigned
(Btype
);
5797 Set_Has_Storage_Size_Clause
(Btype
);
5805 when Attribute_Stream_Size
=> Stream_Size
: declare
5806 Size
: constant Uint
:= Static_Integer
(Expr
);
5809 if Ada_Version
<= Ada_95
then
5810 Check_Restriction
(No_Implementation_Attributes
, N
);
5813 if Duplicate_Clause
then
5816 elsif Is_Elementary_Type
(U_Ent
) then
5817 if Size
/= System_Storage_Unit
5819 Size
/= System_Storage_Unit
* 2
5821 Size
/= System_Storage_Unit
* 4
5823 Size
/= System_Storage_Unit
* 8
5825 Error_Msg_Uint_1
:= UI_From_Int
(System_Storage_Unit
);
5827 ("stream size for elementary type must be a"
5828 & " power of 2 and at least ^", N
);
5830 elsif RM_Size
(U_Ent
) > Size
then
5831 Error_Msg_Uint_1
:= RM_Size
(U_Ent
);
5833 ("stream size for elementary type must be a"
5834 & " power of 2 and at least ^", N
);
5837 Set_Has_Stream_Size_Clause
(U_Ent
);
5840 Error_Msg_N
("Stream_Size cannot be given for &", Nam
);
5848 -- Value_Size attribute definition clause
5850 when Attribute_Value_Size
=> Value_Size
: declare
5851 Size
: constant Uint
:= Static_Integer
(Expr
);
5855 if not Is_Type
(U_Ent
) then
5856 Error_Msg_N
("Value_Size cannot be given for &", Nam
);
5858 elsif Duplicate_Clause
then
5861 elsif Is_Array_Type
(U_Ent
)
5862 and then not Is_Constrained
(U_Ent
)
5865 ("Value_Size cannot be given for unconstrained array", Nam
);
5868 if Is_Elementary_Type
(U_Ent
) then
5869 Check_Size
(Expr
, U_Ent
, Size
, Biased
);
5870 Set_Biased
(U_Ent
, N
, "value size clause", Biased
);
5873 Set_RM_Size
(U_Ent
, Size
);
5877 -----------------------
5878 -- Variable_Indexing --
5879 -----------------------
5881 when Attribute_Variable_Indexing
=>
5882 Check_Indexing_Functions
;
5888 when Attribute_Write
=>
5889 Analyze_Stream_TSS_Definition
(TSS_Stream_Write
);
5890 Set_Has_Specified_Stream_Write
(Ent
);
5892 -- All other attributes cannot be set
5896 ("attribute& cannot be set with definition clause", N
);
5899 -- The test for the type being frozen must be performed after any
5900 -- expression the clause has been analyzed since the expression itself
5901 -- might cause freezing that makes the clause illegal.
5903 if Rep_Item_Too_Late
(U_Ent
, N
, FOnly
) then
5906 end Analyze_Attribute_Definition_Clause
;
5908 ----------------------------
5909 -- Analyze_Code_Statement --
5910 ----------------------------
5912 procedure Analyze_Code_Statement
(N
: Node_Id
) is
5913 HSS
: constant Node_Id
:= Parent
(N
);
5914 SBody
: constant Node_Id
:= Parent
(HSS
);
5915 Subp
: constant Entity_Id
:= Current_Scope
;
5922 -- Analyze and check we get right type, note that this implements the
5923 -- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that
5924 -- is the only way that Asm_Insn could possibly be visible.
5926 Analyze_And_Resolve
(Expression
(N
));
5928 if Etype
(Expression
(N
)) = Any_Type
then
5930 elsif Etype
(Expression
(N
)) /= RTE
(RE_Asm_Insn
) then
5931 Error_Msg_N
("incorrect type for code statement", N
);
5935 Check_Code_Statement
(N
);
5937 -- Make sure we appear in the handled statement sequence of a
5938 -- subprogram (RM 13.8(3)).
5940 if Nkind
(HSS
) /= N_Handled_Sequence_Of_Statements
5941 or else Nkind
(SBody
) /= N_Subprogram_Body
5944 ("code statement can only appear in body of subprogram", N
);
5948 -- Do remaining checks (RM 13.8(3)) if not already done
5950 if not Is_Machine_Code_Subprogram
(Subp
) then
5951 Set_Is_Machine_Code_Subprogram
(Subp
);
5953 -- No exception handlers allowed
5955 if Present
(Exception_Handlers
(HSS
)) then
5957 ("exception handlers not permitted in machine code subprogram",
5958 First
(Exception_Handlers
(HSS
)));
5961 -- No declarations other than use clauses and pragmas (we allow
5962 -- certain internally generated declarations as well).
5964 Decl
:= First
(Declarations
(SBody
));
5965 while Present
(Decl
) loop
5966 DeclO
:= Original_Node
(Decl
);
5967 if Comes_From_Source
(DeclO
)
5968 and not Nkind_In
(DeclO
, N_Pragma
,
5969 N_Use_Package_Clause
,
5971 N_Implicit_Label_Declaration
)
5974 ("this declaration not allowed in machine code subprogram",
5981 -- No statements other than code statements, pragmas, and labels.
5982 -- Again we allow certain internally generated statements.
5984 -- In Ada 2012, qualified expressions are names, and the code
5985 -- statement is initially parsed as a procedure call.
5987 Stmt
:= First
(Statements
(HSS
));
5988 while Present
(Stmt
) loop
5989 StmtO
:= Original_Node
(Stmt
);
5991 -- A procedure call transformed into a code statement is OK.
5993 if Ada_Version
>= Ada_2012
5994 and then Nkind
(StmtO
) = N_Procedure_Call_Statement
5995 and then Nkind
(Name
(StmtO
)) = N_Qualified_Expression
5999 elsif Comes_From_Source
(StmtO
)
6000 and then not Nkind_In
(StmtO
, N_Pragma
,
6005 ("this statement is not allowed in machine code subprogram",
6012 end Analyze_Code_Statement
;
6014 -----------------------------------------------
6015 -- Analyze_Enumeration_Representation_Clause --
6016 -----------------------------------------------
6018 procedure Analyze_Enumeration_Representation_Clause
(N
: Node_Id
) is
6019 Ident
: constant Node_Id
:= Identifier
(N
);
6020 Aggr
: constant Node_Id
:= Array_Aggregate
(N
);
6021 Enumtype
: Entity_Id
;
6028 Err
: Boolean := False;
6029 -- Set True to avoid cascade errors and crashes on incorrect source code
6031 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Universal_Integer
));
6032 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(Universal_Integer
));
6033 -- Allowed range of universal integer (= allowed range of enum lit vals)
6037 -- Minimum and maximum values of entries
6040 -- Pointer to node for literal providing max value
6043 if Ignore_Rep_Clauses
then
6044 Kill_Rep_Clause
(N
);
6048 -- Ignore enumeration rep clauses by default in CodePeer mode,
6049 -- unless -gnatd.I is specified, as a work around for potential false
6050 -- positive messages.
6052 if CodePeer_Mode
and not Debug_Flag_Dot_II
then
6056 -- First some basic error checks
6059 Enumtype
:= Entity
(Ident
);
6061 if Enumtype
= Any_Type
6062 or else Rep_Item_Too_Early
(Enumtype
, N
)
6066 Enumtype
:= Underlying_Type
(Enumtype
);
6069 if not Is_Enumeration_Type
(Enumtype
) then
6071 ("enumeration type required, found}",
6072 Ident
, First_Subtype
(Enumtype
));
6076 -- Ignore rep clause on generic actual type. This will already have
6077 -- been flagged on the template as an error, and this is the safest
6078 -- way to ensure we don't get a junk cascaded message in the instance.
6080 if Is_Generic_Actual_Type
(Enumtype
) then
6083 -- Type must be in current scope
6085 elsif Scope
(Enumtype
) /= Current_Scope
then
6086 Error_Msg_N
("type must be declared in this scope", Ident
);
6089 -- Type must be a first subtype
6091 elsif not Is_First_Subtype
(Enumtype
) then
6092 Error_Msg_N
("cannot give enumeration rep clause for subtype", N
);
6095 -- Ignore duplicate rep clause
6097 elsif Has_Enumeration_Rep_Clause
(Enumtype
) then
6098 Error_Msg_N
("duplicate enumeration rep clause ignored", N
);
6101 -- Don't allow rep clause for standard [wide_[wide_]]character
6103 elsif Is_Standard_Character_Type
(Enumtype
) then
6104 Error_Msg_N
("enumeration rep clause not allowed for this type", N
);
6107 -- Check that the expression is a proper aggregate (no parentheses)
6109 elsif Paren_Count
(Aggr
) /= 0 then
6111 ("extra parentheses surrounding aggregate not allowed",
6115 -- All tests passed, so set rep clause in place
6118 Set_Has_Enumeration_Rep_Clause
(Enumtype
);
6119 Set_Has_Enumeration_Rep_Clause
(Base_Type
(Enumtype
));
6122 -- Now we process the aggregate. Note that we don't use the normal
6123 -- aggregate code for this purpose, because we don't want any of the
6124 -- normal expansion activities, and a number of special semantic
6125 -- rules apply (including the component type being any integer type)
6127 Elit
:= First_Literal
(Enumtype
);
6129 -- First the positional entries if any
6131 if Present
(Expressions
(Aggr
)) then
6132 Expr
:= First
(Expressions
(Aggr
));
6133 while Present
(Expr
) loop
6135 Error_Msg_N
("too many entries in aggregate", Expr
);
6139 Val
:= Static_Integer
(Expr
);
6141 -- Err signals that we found some incorrect entries processing
6142 -- the list. The final checks for completeness and ordering are
6143 -- skipped in this case.
6145 if Val
= No_Uint
then
6148 elsif Val
< Lo
or else Hi
< Val
then
6149 Error_Msg_N
("value outside permitted range", Expr
);
6153 Set_Enumeration_Rep
(Elit
, Val
);
6154 Set_Enumeration_Rep_Expr
(Elit
, Expr
);
6160 -- Now process the named entries if present
6162 if Present
(Component_Associations
(Aggr
)) then
6163 Assoc
:= First
(Component_Associations
(Aggr
));
6164 while Present
(Assoc
) loop
6165 Choice
:= First
(Choices
(Assoc
));
6167 if Present
(Next
(Choice
)) then
6169 ("multiple choice not allowed here", Next
(Choice
));
6173 if Nkind
(Choice
) = N_Others_Choice
then
6174 Error_Msg_N
("others choice not allowed here", Choice
);
6177 elsif Nkind
(Choice
) = N_Range
then
6179 -- ??? should allow zero/one element range here
6181 Error_Msg_N
("range not allowed here", Choice
);
6185 Analyze_And_Resolve
(Choice
, Enumtype
);
6187 if Error_Posted
(Choice
) then
6192 if Is_Entity_Name
(Choice
)
6193 and then Is_Type
(Entity
(Choice
))
6195 Error_Msg_N
("subtype name not allowed here", Choice
);
6198 -- ??? should allow static subtype with zero/one entry
6200 elsif Etype
(Choice
) = Base_Type
(Enumtype
) then
6201 if not Is_OK_Static_Expression
(Choice
) then
6202 Flag_Non_Static_Expr
6203 ("non-static expression used for choice!", Choice
);
6207 Elit
:= Expr_Value_E
(Choice
);
6209 if Present
(Enumeration_Rep_Expr
(Elit
)) then
6211 Sloc
(Enumeration_Rep_Expr
(Elit
));
6213 ("representation for& previously given#",
6218 Set_Enumeration_Rep_Expr
(Elit
, Expression
(Assoc
));
6220 Expr
:= Expression
(Assoc
);
6221 Val
:= Static_Integer
(Expr
);
6223 if Val
= No_Uint
then
6226 elsif Val
< Lo
or else Hi
< Val
then
6227 Error_Msg_N
("value outside permitted range", Expr
);
6231 Set_Enumeration_Rep
(Elit
, Val
);
6241 -- Aggregate is fully processed. Now we check that a full set of
6242 -- representations was given, and that they are in range and in order.
6243 -- These checks are only done if no other errors occurred.
6249 Elit
:= First_Literal
(Enumtype
);
6250 while Present
(Elit
) loop
6251 if No
(Enumeration_Rep_Expr
(Elit
)) then
6252 Error_Msg_NE
("missing representation for&!", N
, Elit
);
6255 Val
:= Enumeration_Rep
(Elit
);
6257 if Min
= No_Uint
then
6261 if Val
/= No_Uint
then
6262 if Max
/= No_Uint
and then Val
<= Max
then
6264 ("enumeration value for& not ordered!",
6265 Enumeration_Rep_Expr
(Elit
), Elit
);
6268 Max_Node
:= Enumeration_Rep_Expr
(Elit
);
6272 -- If there is at least one literal whose representation is not
6273 -- equal to the Pos value, then note that this enumeration type
6274 -- has a non-standard representation.
6276 if Val
/= Enumeration_Pos
(Elit
) then
6277 Set_Has_Non_Standard_Rep
(Base_Type
(Enumtype
));
6284 -- Now set proper size information
6287 Minsize
: Uint
:= UI_From_Int
(Minimum_Size
(Enumtype
));
6290 if Has_Size_Clause
(Enumtype
) then
6292 -- All OK, if size is OK now
6294 if RM_Size
(Enumtype
) >= Minsize
then
6298 -- Try if we can get by with biasing
6301 UI_From_Int
(Minimum_Size
(Enumtype
, Biased
=> True));
6303 -- Error message if even biasing does not work
6305 if RM_Size
(Enumtype
) < Minsize
then
6306 Error_Msg_Uint_1
:= RM_Size
(Enumtype
);
6307 Error_Msg_Uint_2
:= Max
;
6309 ("previously given size (^) is too small "
6310 & "for this value (^)", Max_Node
);
6312 -- If biasing worked, indicate that we now have biased rep
6316 (Enumtype
, Size_Clause
(Enumtype
), "size clause");
6321 Set_RM_Size
(Enumtype
, Minsize
);
6322 Set_Enum_Esize
(Enumtype
);
6325 Set_RM_Size
(Base_Type
(Enumtype
), RM_Size
(Enumtype
));
6326 Set_Esize
(Base_Type
(Enumtype
), Esize
(Enumtype
));
6327 Set_Alignment
(Base_Type
(Enumtype
), Alignment
(Enumtype
));
6331 -- We repeat the too late test in case it froze itself
6333 if Rep_Item_Too_Late
(Enumtype
, N
) then
6336 end Analyze_Enumeration_Representation_Clause
;
6338 ----------------------------
6339 -- Analyze_Free_Statement --
6340 ----------------------------
6342 procedure Analyze_Free_Statement
(N
: Node_Id
) is
6344 Analyze
(Expression
(N
));
6345 end Analyze_Free_Statement
;
6347 ---------------------------
6348 -- Analyze_Freeze_Entity --
6349 ---------------------------
6351 procedure Analyze_Freeze_Entity
(N
: Node_Id
) is
6353 Freeze_Entity_Checks
(N
);
6354 end Analyze_Freeze_Entity
;
6356 -----------------------------------
6357 -- Analyze_Freeze_Generic_Entity --
6358 -----------------------------------
6360 procedure Analyze_Freeze_Generic_Entity
(N
: Node_Id
) is
6362 Freeze_Entity_Checks
(N
);
6363 end Analyze_Freeze_Generic_Entity
;
6365 ------------------------------------------
6366 -- Analyze_Record_Representation_Clause --
6367 ------------------------------------------
6369 -- Note: we check as much as we can here, but we can't do any checks
6370 -- based on the position values (e.g. overlap checks) until freeze time
6371 -- because especially in Ada 2005 (machine scalar mode), the processing
6372 -- for non-standard bit order can substantially change the positions.
6373 -- See procedure Check_Record_Representation_Clause (called from Freeze)
6374 -- for the remainder of this processing.
6376 procedure Analyze_Record_Representation_Clause
(N
: Node_Id
) is
6377 Ident
: constant Node_Id
:= Identifier
(N
);
6382 Hbit
: Uint
:= Uint_0
;
6386 Rectype
: Entity_Id
;
6389 function Is_Inherited
(Comp
: Entity_Id
) return Boolean;
6390 -- True if Comp is an inherited component in a record extension
6396 function Is_Inherited
(Comp
: Entity_Id
) return Boolean is
6397 Comp_Base
: Entity_Id
;
6400 if Ekind
(Rectype
) = E_Record_Subtype
then
6401 Comp_Base
:= Original_Record_Component
(Comp
);
6406 return Comp_Base
/= Original_Record_Component
(Comp_Base
);
6411 Is_Record_Extension
: Boolean;
6412 -- True if Rectype is a record extension
6414 CR_Pragma
: Node_Id
:= Empty
;
6415 -- Points to N_Pragma node if Complete_Representation pragma present
6417 -- Start of processing for Analyze_Record_Representation_Clause
6420 if Ignore_Rep_Clauses
then
6421 Kill_Rep_Clause
(N
);
6426 Rectype
:= Entity
(Ident
);
6428 if Rectype
= Any_Type
or else Rep_Item_Too_Early
(Rectype
, N
) then
6431 Rectype
:= Underlying_Type
(Rectype
);
6434 -- First some basic error checks
6436 if not Is_Record_Type
(Rectype
) then
6438 ("record type required, found}", Ident
, First_Subtype
(Rectype
));
6441 elsif Scope
(Rectype
) /= Current_Scope
then
6442 Error_Msg_N
("type must be declared in this scope", N
);
6445 elsif not Is_First_Subtype
(Rectype
) then
6446 Error_Msg_N
("cannot give record rep clause for subtype", N
);
6449 elsif Has_Record_Rep_Clause
(Rectype
) then
6450 Error_Msg_N
("duplicate record rep clause ignored", N
);
6453 elsif Rep_Item_Too_Late
(Rectype
, N
) then
6457 -- We know we have a first subtype, now possibly go the the anonymous
6458 -- base type to determine whether Rectype is a record extension.
6460 Recdef
:= Type_Definition
(Declaration_Node
(Base_Type
(Rectype
)));
6461 Is_Record_Extension
:=
6462 Nkind
(Recdef
) = N_Derived_Type_Definition
6463 and then Present
(Record_Extension_Part
(Recdef
));
6465 if Present
(Mod_Clause
(N
)) then
6467 Loc
: constant Source_Ptr
:= Sloc
(N
);
6468 M
: constant Node_Id
:= Mod_Clause
(N
);
6469 P
: constant List_Id
:= Pragmas_Before
(M
);
6473 pragma Warnings
(Off
, Mod_Val
);
6476 Check_Restriction
(No_Obsolescent_Features
, Mod_Clause
(N
));
6478 if Warn_On_Obsolescent_Feature
then
6480 ("?j?mod clause is an obsolescent feature (RM J.8)", N
);
6482 ("\?j?use alignment attribute definition clause instead", N
);
6489 -- In ASIS_Mode mode, expansion is disabled, but we must convert
6490 -- the Mod clause into an alignment clause anyway, so that the
6491 -- back-end can compute and back-annotate properly the size and
6492 -- alignment of types that may include this record.
6494 -- This seems dubious, this destroys the source tree in a manner
6495 -- not detectable by ASIS ???
6497 if Operating_Mode
= Check_Semantics
and then ASIS_Mode
then
6499 Make_Attribute_Definition_Clause
(Loc
,
6500 Name
=> New_Occurrence_Of
(Base_Type
(Rectype
), Loc
),
6501 Chars
=> Name_Alignment
,
6502 Expression
=> Relocate_Node
(Expression
(M
)));
6504 Set_From_At_Mod
(AtM_Nod
);
6505 Insert_After
(N
, AtM_Nod
);
6506 Mod_Val
:= Get_Alignment_Value
(Expression
(AtM_Nod
));
6507 Set_Mod_Clause
(N
, Empty
);
6510 -- Get the alignment value to perform error checking
6512 Mod_Val
:= Get_Alignment_Value
(Expression
(M
));
6517 -- For untagged types, clear any existing component clauses for the
6518 -- type. If the type is derived, this is what allows us to override
6519 -- a rep clause for the parent. For type extensions, the representation
6520 -- of the inherited components is inherited, so we want to keep previous
6521 -- component clauses for completeness.
6523 if not Is_Tagged_Type
(Rectype
) then
6524 Comp
:= First_Component_Or_Discriminant
(Rectype
);
6525 while Present
(Comp
) loop
6526 Set_Component_Clause
(Comp
, Empty
);
6527 Next_Component_Or_Discriminant
(Comp
);
6531 -- All done if no component clauses
6533 CC
:= First
(Component_Clauses
(N
));
6539 -- A representation like this applies to the base type
6541 Set_Has_Record_Rep_Clause
(Base_Type
(Rectype
));
6542 Set_Has_Non_Standard_Rep
(Base_Type
(Rectype
));
6543 Set_Has_Specified_Layout
(Base_Type
(Rectype
));
6545 -- Process the component clauses
6547 while Present
(CC
) loop
6551 if Nkind
(CC
) = N_Pragma
then
6554 -- The only pragma of interest is Complete_Representation
6556 if Pragma_Name
(CC
) = Name_Complete_Representation
then
6560 -- Processing for real component clause
6563 Posit
:= Static_Integer
(Position
(CC
));
6564 Fbit
:= Static_Integer
(First_Bit
(CC
));
6565 Lbit
:= Static_Integer
(Last_Bit
(CC
));
6568 and then Fbit
/= No_Uint
6569 and then Lbit
/= No_Uint
6573 ("position cannot be negative", Position
(CC
));
6577 ("first bit cannot be negative", First_Bit
(CC
));
6579 -- The Last_Bit specified in a component clause must not be
6580 -- less than the First_Bit minus one (RM-13.5.1(10)).
6582 elsif Lbit
< Fbit
- 1 then
6584 ("last bit cannot be less than first bit minus one",
6587 -- Values look OK, so find the corresponding record component
6588 -- Even though the syntax allows an attribute reference for
6589 -- implementation-defined components, GNAT does not allow the
6590 -- tag to get an explicit position.
6592 elsif Nkind
(Component_Name
(CC
)) = N_Attribute_Reference
then
6593 if Attribute_Name
(Component_Name
(CC
)) = Name_Tag
then
6594 Error_Msg_N
("position of tag cannot be specified", CC
);
6596 Error_Msg_N
("illegal component name", CC
);
6600 Comp
:= First_Entity
(Rectype
);
6601 while Present
(Comp
) loop
6602 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
6608 -- Maybe component of base type that is absent from
6609 -- statically constrained first subtype.
6611 Comp
:= First_Entity
(Base_Type
(Rectype
));
6612 while Present
(Comp
) loop
6613 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
6620 ("component clause is for non-existent field", CC
);
6622 -- Ada 2012 (AI05-0026): Any name that denotes a
6623 -- discriminant of an object of an unchecked union type
6624 -- shall not occur within a record_representation_clause.
6626 -- The general restriction of using record rep clauses on
6627 -- Unchecked_Union types has now been lifted. Since it is
6628 -- possible to introduce a record rep clause which mentions
6629 -- the discriminant of an Unchecked_Union in non-Ada 2012
6630 -- code, this check is applied to all versions of the
6633 elsif Ekind
(Comp
) = E_Discriminant
6634 and then Is_Unchecked_Union
(Rectype
)
6637 ("cannot reference discriminant of unchecked union",
6638 Component_Name
(CC
));
6640 elsif Is_Record_Extension
and then Is_Inherited
(Comp
) then
6642 ("component clause not allowed for inherited "
6643 & "component&", CC
, Comp
);
6645 elsif Present
(Component_Clause
(Comp
)) then
6647 -- Diagnose duplicate rep clause, or check consistency
6648 -- if this is an inherited component. In a double fault,
6649 -- there may be a duplicate inconsistent clause for an
6650 -- inherited component.
6652 if Scope
(Original_Record_Component
(Comp
)) = Rectype
6653 or else Parent
(Component_Clause
(Comp
)) = N
6655 Error_Msg_Sloc
:= Sloc
(Component_Clause
(Comp
));
6656 Error_Msg_N
("component clause previously given#", CC
);
6660 Rep1
: constant Node_Id
:= Component_Clause
(Comp
);
6662 if Intval
(Position
(Rep1
)) /=
6663 Intval
(Position
(CC
))
6664 or else Intval
(First_Bit
(Rep1
)) /=
6665 Intval
(First_Bit
(CC
))
6666 or else Intval
(Last_Bit
(Rep1
)) /=
6667 Intval
(Last_Bit
(CC
))
6670 ("component clause inconsistent "
6671 & "with representation of ancestor", CC
);
6673 elsif Warn_On_Redundant_Constructs
then
6675 ("?r?redundant confirming component clause "
6676 & "for component!", CC
);
6681 -- Normal case where this is the first component clause we
6682 -- have seen for this entity, so set it up properly.
6685 -- Make reference for field in record rep clause and set
6686 -- appropriate entity field in the field identifier.
6689 (Comp
, Component_Name
(CC
), Set_Ref
=> False);
6690 Set_Entity
(Component_Name
(CC
), Comp
);
6692 -- Update Fbit and Lbit to the actual bit number
6694 Fbit
:= Fbit
+ UI_From_Int
(SSU
) * Posit
;
6695 Lbit
:= Lbit
+ UI_From_Int
(SSU
) * Posit
;
6697 if Has_Size_Clause
(Rectype
)
6698 and then RM_Size
(Rectype
) <= Lbit
6701 ("bit number out of range of specified size",
6704 Set_Component_Clause
(Comp
, CC
);
6705 Set_Component_Bit_Offset
(Comp
, Fbit
);
6706 Set_Esize
(Comp
, 1 + (Lbit
- Fbit
));
6707 Set_Normalized_First_Bit
(Comp
, Fbit
mod SSU
);
6708 Set_Normalized_Position
(Comp
, Fbit
/ SSU
);
6710 if Warn_On_Overridden_Size
6711 and then Has_Size_Clause
(Etype
(Comp
))
6712 and then RM_Size
(Etype
(Comp
)) /= Esize
(Comp
)
6715 ("?S?component size overrides size clause for&",
6716 Component_Name
(CC
), Etype
(Comp
));
6719 -- This information is also set in the corresponding
6720 -- component of the base type, found by accessing the
6721 -- Original_Record_Component link if it is present.
6723 Ocomp
:= Original_Record_Component
(Comp
);
6730 (Component_Name
(CC
),
6736 (Comp
, First_Node
(CC
), "component clause", Biased
);
6738 if Present
(Ocomp
) then
6739 Set_Component_Clause
(Ocomp
, CC
);
6740 Set_Component_Bit_Offset
(Ocomp
, Fbit
);
6741 Set_Normalized_First_Bit
(Ocomp
, Fbit
mod SSU
);
6742 Set_Normalized_Position
(Ocomp
, Fbit
/ SSU
);
6743 Set_Esize
(Ocomp
, 1 + (Lbit
- Fbit
));
6745 Set_Normalized_Position_Max
6746 (Ocomp
, Normalized_Position
(Ocomp
));
6748 -- Note: we don't use Set_Biased here, because we
6749 -- already gave a warning above if needed, and we
6750 -- would get a duplicate for the same name here.
6752 Set_Has_Biased_Representation
6753 (Ocomp
, Has_Biased_Representation
(Comp
));
6756 if Esize
(Comp
) < 0 then
6757 Error_Msg_N
("component size is negative", CC
);
6768 -- Check missing components if Complete_Representation pragma appeared
6770 if Present
(CR_Pragma
) then
6771 Comp
:= First_Component_Or_Discriminant
(Rectype
);
6772 while Present
(Comp
) loop
6773 if No
(Component_Clause
(Comp
)) then
6775 ("missing component clause for &", CR_Pragma
, Comp
);
6778 Next_Component_Or_Discriminant
(Comp
);
6781 -- Give missing components warning if required
6783 elsif Warn_On_Unrepped_Components
then
6785 Num_Repped_Components
: Nat
:= 0;
6786 Num_Unrepped_Components
: Nat
:= 0;
6789 -- First count number of repped and unrepped components
6791 Comp
:= First_Component_Or_Discriminant
(Rectype
);
6792 while Present
(Comp
) loop
6793 if Present
(Component_Clause
(Comp
)) then
6794 Num_Repped_Components
:= Num_Repped_Components
+ 1;
6796 Num_Unrepped_Components
:= Num_Unrepped_Components
+ 1;
6799 Next_Component_Or_Discriminant
(Comp
);
6802 -- We are only interested in the case where there is at least one
6803 -- unrepped component, and at least half the components have rep
6804 -- clauses. We figure that if less than half have them, then the
6805 -- partial rep clause is really intentional. If the component
6806 -- type has no underlying type set at this point (as for a generic
6807 -- formal type), we don't know enough to give a warning on the
6810 if Num_Unrepped_Components
> 0
6811 and then Num_Unrepped_Components
< Num_Repped_Components
6813 Comp
:= First_Component_Or_Discriminant
(Rectype
);
6814 while Present
(Comp
) loop
6815 if No
(Component_Clause
(Comp
))
6816 and then Comes_From_Source
(Comp
)
6817 and then Present
(Underlying_Type
(Etype
(Comp
)))
6818 and then (Is_Scalar_Type
(Underlying_Type
(Etype
(Comp
)))
6819 or else Size_Known_At_Compile_Time
6820 (Underlying_Type
(Etype
(Comp
))))
6821 and then not Has_Warnings_Off
(Rectype
)
6823 -- Ignore discriminant in unchecked union, since it is
6824 -- not there, and cannot have a component clause.
6826 and then (not Is_Unchecked_Union
(Rectype
)
6827 or else Ekind
(Comp
) /= E_Discriminant
)
6829 Error_Msg_Sloc
:= Sloc
(Comp
);
6831 ("?C?no component clause given for & declared #",
6835 Next_Component_Or_Discriminant
(Comp
);
6840 end Analyze_Record_Representation_Clause
;
6842 -------------------------------------
6843 -- Build_Discrete_Static_Predicate --
6844 -------------------------------------
6846 procedure Build_Discrete_Static_Predicate
6851 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
6853 Non_Static
: exception;
6854 -- Raised if something non-static is found
6856 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
6858 BLo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Btyp
));
6859 BHi
: constant Uint
:= Expr_Value
(Type_High_Bound
(Btyp
));
6860 -- Low bound and high bound value of base type of Typ
6864 -- Bounds for constructing the static predicate. We use the bound of the
6865 -- subtype if it is static, otherwise the corresponding base type bound.
6866 -- Note: a non-static subtype can have a static predicate.
6871 -- One entry in a Rlist value, a single REnt (range entry) value denotes
6872 -- one range from Lo to Hi. To represent a single value range Lo = Hi =
6875 type RList
is array (Nat
range <>) of REnt
;
6876 -- A list of ranges. The ranges are sorted in increasing order, and are
6877 -- disjoint (there is a gap of at least one value between each range in
6878 -- the table). A value is in the set of ranges in Rlist if it lies
6879 -- within one of these ranges.
6881 False_Range
: constant RList
:=
6882 RList
'(1 .. 0 => REnt'(No_Uint
, No_Uint
));
6883 -- An empty set of ranges represents a range list that can never be
6884 -- satisfied, since there are no ranges in which the value could lie,
6885 -- so it does not lie in any of them. False_Range is a canonical value
6886 -- for this empty set, but general processing should test for an Rlist
6887 -- with length zero (see Is_False predicate), since other null ranges
6888 -- may appear which must be treated as False.
6890 True_Range
: constant RList
:= RList
'(1 => REnt'(BLo
, BHi
));
6891 -- Range representing True, value must be in the base range
6893 function "and" (Left
: RList
; Right
: RList
) return RList
;
6894 -- And's together two range lists, returning a range list. This is a set
6895 -- intersection operation.
6897 function "or" (Left
: RList
; Right
: RList
) return RList
;
6898 -- Or's together two range lists, returning a range list. This is a set
6901 function "not" (Right
: RList
) return RList
;
6902 -- Returns complement of a given range list, i.e. a range list
6903 -- representing all the values in TLo .. THi that are not in the input
6906 function Build_Val
(V
: Uint
) return Node_Id
;
6907 -- Return an analyzed N_Identifier node referencing this value, suitable
6908 -- for use as an entry in the Static_Discrte_Predicate list. This node
6909 -- is typed with the base type.
6911 function Build_Range
(Lo
: Uint
; Hi
: Uint
) return Node_Id
;
6912 -- Return an analyzed N_Range node referencing this range, suitable for
6913 -- use as an entry in the Static_Discrete_Predicate list. This node is
6914 -- typed with the base type.
6916 function Get_RList
(Exp
: Node_Id
) return RList
;
6917 -- This is a recursive routine that converts the given expression into a
6918 -- list of ranges, suitable for use in building the static predicate.
6920 function Is_False
(R
: RList
) return Boolean;
6921 pragma Inline
(Is_False
);
6922 -- Returns True if the given range list is empty, and thus represents a
6923 -- False list of ranges that can never be satisfied.
6925 function Is_True
(R
: RList
) return Boolean;
6926 -- Returns True if R trivially represents the True predicate by having a
6927 -- single range from BLo to BHi.
6929 function Is_Type_Ref
(N
: Node_Id
) return Boolean;
6930 pragma Inline
(Is_Type_Ref
);
6931 -- Returns if True if N is a reference to the type for the predicate in
6932 -- the expression (i.e. if it is an identifier whose Chars field matches
6933 -- the Nam given in the call). N must not be parenthesized, if the type
6934 -- name appears in parens, this routine will return False.
6936 function Lo_Val
(N
: Node_Id
) return Uint
;
6937 -- Given an entry from a Static_Discrete_Predicate list that is either
6938 -- a static expression or static range, gets either the expression value
6939 -- or the low bound of the range.
6941 function Hi_Val
(N
: Node_Id
) return Uint
;
6942 -- Given an entry from a Static_Discrete_Predicate list that is either
6943 -- a static expression or static range, gets either the expression value
6944 -- or the high bound of the range.
6946 function Membership_Entry
(N
: Node_Id
) return RList
;
6947 -- Given a single membership entry (range, value, or subtype), returns
6948 -- the corresponding range list. Raises Static_Error if not static.
6950 function Membership_Entries
(N
: Node_Id
) return RList
;
6951 -- Given an element on an alternatives list of a membership operation,
6952 -- returns the range list corresponding to this entry and all following
6953 -- entries (i.e. returns the "or" of this list of values).
6955 function Stat_Pred
(Typ
: Entity_Id
) return RList
;
6956 -- Given a type, if it has a static predicate, then return the predicate
6957 -- as a range list, otherwise raise Non_Static.
6963 function "and" (Left
: RList
; Right
: RList
) return RList
is
6965 -- First range of result
6967 SLeft
: Nat
:= Left
'First;
6968 -- Start of rest of left entries
6970 SRight
: Nat
:= Right
'First;
6971 -- Start of rest of right entries
6974 -- If either range is True, return the other
6976 if Is_True
(Left
) then
6978 elsif Is_True
(Right
) then
6982 -- If either range is False, return False
6984 if Is_False
(Left
) or else Is_False
(Right
) then
6988 -- Loop to remove entries at start that are disjoint, and thus just
6989 -- get discarded from the result entirely.
6992 -- If no operands left in either operand, result is false
6994 if SLeft
> Left
'Last or else SRight
> Right
'Last then
6997 -- Discard first left operand entry if disjoint with right
6999 elsif Left
(SLeft
).Hi
< Right
(SRight
).Lo
then
7002 -- Discard first right operand entry if disjoint with left
7004 elsif Right
(SRight
).Hi
< Left
(SLeft
).Lo
then
7005 SRight
:= SRight
+ 1;
7007 -- Otherwise we have an overlapping entry
7014 -- Now we have two non-null operands, and first entries overlap. The
7015 -- first entry in the result will be the overlapping part of these
7018 FEnt
:= REnt
'(Lo => UI_Max (Left (SLeft).Lo, Right (SRight).Lo),
7019 Hi => UI_Min (Left (SLeft).Hi, Right (SRight).Hi));
7021 -- Now we can remove the entry that ended at a lower value, since its
7022 -- contribution is entirely contained in Fent.
7024 if Left (SLeft).Hi <= Right (SRight).Hi then
7027 SRight := SRight + 1;
7030 -- Compute result by concatenating this first entry with the "and" of
7031 -- the remaining parts of the left and right operands. Note that if
7032 -- either of these is empty, "and" will yield empty, so that we will
7033 -- end up with just Fent, which is what we want in that case.
7036 FEnt & (Left (SLeft .. Left'Last) and Right (SRight .. Right'Last));
7043 function "not" (Right : RList) return RList is
7045 -- Return True if False range
7047 if Is_False (Right) then
7051 -- Return False if True range
7053 if Is_True (Right) then
7057 -- Here if not trivial case
7060 Result : RList (1 .. Right'Length + 1);
7061 -- May need one more entry for gap at beginning and end
7064 -- Number of entries stored in Result
7069 if Right (Right'First).Lo > TLo then
7071 Result (Count) := REnt'(TLo
, Right
(Right
'First).Lo
- 1);
7074 -- Gaps between ranges
7076 for J
in Right
'First .. Right
'Last - 1 loop
7078 Result
(Count
) := REnt
'(Right (J).Hi + 1, Right (J + 1).Lo - 1);
7083 if Right (Right'Last).Hi < THi then
7085 Result (Count) := REnt'(Right
(Right
'Last).Hi
+ 1, THi
);
7088 return Result
(1 .. Count
);
7096 function "or" (Left
: RList
; Right
: RList
) return RList
is
7098 -- First range of result
7100 SLeft
: Nat
:= Left
'First;
7101 -- Start of rest of left entries
7103 SRight
: Nat
:= Right
'First;
7104 -- Start of rest of right entries
7107 -- If either range is True, return True
7109 if Is_True
(Left
) or else Is_True
(Right
) then
7113 -- If either range is False (empty), return the other
7115 if Is_False
(Left
) then
7117 elsif Is_False
(Right
) then
7121 -- Initialize result first entry from left or right operand depending
7122 -- on which starts with the lower range.
7124 if Left
(SLeft
).Lo
< Right
(SRight
).Lo
then
7125 FEnt
:= Left
(SLeft
);
7128 FEnt
:= Right
(SRight
);
7129 SRight
:= SRight
+ 1;
7132 -- This loop eats ranges from left and right operands that are
7133 -- contiguous with the first range we are gathering.
7136 -- Eat first entry in left operand if contiguous or overlapped by
7137 -- gathered first operand of result.
7139 if SLeft
<= Left
'Last
7140 and then Left
(SLeft
).Lo
<= FEnt
.Hi
+ 1
7142 FEnt
.Hi
:= UI_Max
(FEnt
.Hi
, Left
(SLeft
).Hi
);
7145 -- Eat first entry in right operand if contiguous or overlapped by
7146 -- gathered right operand of result.
7148 elsif SRight
<= Right
'Last
7149 and then Right
(SRight
).Lo
<= FEnt
.Hi
+ 1
7151 FEnt
.Hi
:= UI_Max
(FEnt
.Hi
, Right
(SRight
).Hi
);
7152 SRight
:= SRight
+ 1;
7154 -- All done if no more entries to eat
7161 -- Obtain result as the first entry we just computed, concatenated
7162 -- to the "or" of the remaining results (if one operand is empty,
7163 -- this will just concatenate with the other
7166 FEnt
& (Left
(SLeft
.. Left
'Last) or Right
(SRight
.. Right
'Last));
7173 function Build_Range
(Lo
: Uint
; Hi
: Uint
) return Node_Id
is
7178 Low_Bound
=> Build_Val
(Lo
),
7179 High_Bound
=> Build_Val
(Hi
));
7180 Set_Etype
(Result
, Btyp
);
7181 Set_Analyzed
(Result
);
7189 function Build_Val
(V
: Uint
) return Node_Id
is
7193 if Is_Enumeration_Type
(Typ
) then
7194 Result
:= Get_Enum_Lit_From_Pos
(Typ
, V
, Loc
);
7196 Result
:= Make_Integer_Literal
(Loc
, V
);
7199 Set_Etype
(Result
, Btyp
);
7200 Set_Is_Static_Expression
(Result
);
7201 Set_Analyzed
(Result
);
7209 function Get_RList
(Exp
: Node_Id
) return RList
is
7214 -- Static expression can only be true or false
7216 if Is_OK_Static_Expression
(Exp
) then
7217 if Expr_Value
(Exp
) = 0 then
7224 -- Otherwise test node type
7232 when N_Op_And | N_And_Then
=>
7233 return Get_RList
(Left_Opnd
(Exp
))
7235 Get_RList
(Right_Opnd
(Exp
));
7239 when N_Op_Or | N_Or_Else
=>
7240 return Get_RList
(Left_Opnd
(Exp
))
7242 Get_RList
(Right_Opnd
(Exp
));
7247 return not Get_RList
(Right_Opnd
(Exp
));
7249 -- Comparisons of type with static value
7251 when N_Op_Compare
=>
7253 -- Type is left operand
7255 if Is_Type_Ref
(Left_Opnd
(Exp
))
7256 and then Is_OK_Static_Expression
(Right_Opnd
(Exp
))
7258 Val
:= Expr_Value
(Right_Opnd
(Exp
));
7260 -- Typ is right operand
7262 elsif Is_Type_Ref
(Right_Opnd
(Exp
))
7263 and then Is_OK_Static_Expression
(Left_Opnd
(Exp
))
7265 Val
:= Expr_Value
(Left_Opnd
(Exp
));
7267 -- Invert sense of comparison
7270 when N_Op_Gt
=> Op
:= N_Op_Lt
;
7271 when N_Op_Lt
=> Op
:= N_Op_Gt
;
7272 when N_Op_Ge
=> Op
:= N_Op_Le
;
7273 when N_Op_Le
=> Op
:= N_Op_Ge
;
7274 when others => null;
7277 -- Other cases are non-static
7283 -- Construct range according to comparison operation
7287 return RList
'(1 => REnt'(Val
, Val
));
7290 return RList
'(1 => REnt'(Val
, BHi
));
7293 return RList
'(1 => REnt'(Val
+ 1, BHi
));
7296 return RList
'(1 => REnt'(BLo
, Val
));
7299 return RList
'(1 => REnt'(BLo
, Val
- 1));
7302 return RList
'(REnt'(BLo
, Val
- 1), REnt
'(Val + 1, BHi));
7305 raise Program_Error;
7311 if not Is_Type_Ref (Left_Opnd (Exp)) then
7315 if Present (Right_Opnd (Exp)) then
7316 return Membership_Entry (Right_Opnd (Exp));
7318 return Membership_Entries (First (Alternatives (Exp)));
7321 -- Negative membership (NOT IN)
7324 if not Is_Type_Ref (Left_Opnd (Exp)) then
7328 if Present (Right_Opnd (Exp)) then
7329 return not Membership_Entry (Right_Opnd (Exp));
7331 return not Membership_Entries (First (Alternatives (Exp)));
7334 -- Function call, may be call to static predicate
7336 when N_Function_Call =>
7337 if Is_Entity_Name (Name (Exp)) then
7339 Ent : constant Entity_Id := Entity (Name (Exp));
7341 if Is_Predicate_Function (Ent)
7343 Is_Predicate_Function_M (Ent)
7345 return Stat_Pred (Etype (First_Formal (Ent)));
7350 -- Other function call cases are non-static
7354 -- Qualified expression, dig out the expression
7356 when N_Qualified_Expression =>
7357 return Get_RList (Expression (Exp));
7359 when N_Case_Expression =>
7366 if not Is_Entity_Name (Expression (Expr))
7367 or else Etype (Expression (Expr)) /= Typ
7370 ("expression must denaote subtype", Expression (Expr));
7374 -- Collect discrete choices in all True alternatives
7376 Choices := New_List;
7377 Alt := First (Alternatives (Exp));
7378 while Present (Alt) loop
7379 Dep := Expression (Alt);
7381 if not Is_OK_Static_Expression (Dep) then
7384 elsif Is_True (Expr_Value (Dep)) then
7385 Append_List_To (Choices,
7386 New_Copy_List (Discrete_Choices (Alt)));
7392 return Membership_Entries (First (Choices));
7395 -- Expression with actions: if no actions, dig out expression
7397 when N_Expression_With_Actions =>
7398 if Is_Empty_List (Actions (Exp)) then
7399 return Get_RList (Expression (Exp));
7407 return (Get_RList (Left_Opnd (Exp))
7408 and not Get_RList (Right_Opnd (Exp)))
7409 or (Get_RList (Right_Opnd (Exp))
7410 and not Get_RList (Left_Opnd (Exp)));
7412 -- Any other node type is non-static
7423 function Hi_Val (N : Node_Id) return Uint is
7425 if Is_OK_Static_Expression (N) then
7426 return Expr_Value (N);
7428 pragma Assert (Nkind (N) = N_Range);
7429 return Expr_Value (High_Bound (N));
7437 function Is_False (R : RList) return Boolean is
7439 return R'Length = 0;
7446 function Is_True (R : RList) return Boolean is
7449 and then R (R'First).Lo = BLo
7450 and then R (R'First).Hi = BHi;
7457 function Is_Type_Ref (N : Node_Id) return Boolean is
7459 return Nkind (N) = N_Identifier
7460 and then Chars (N) = Nam
7461 and then Paren_Count (N) = 0;
7468 function Lo_Val (N : Node_Id) return Uint is
7470 if Is_OK_Static_Expression (N) then
7471 return Expr_Value (N);
7473 pragma Assert (Nkind (N) = N_Range);
7474 return Expr_Value (Low_Bound (N));
7478 ------------------------
7479 -- Membership_Entries --
7480 ------------------------
7482 function Membership_Entries (N : Node_Id) return RList is
7484 if No (Next (N)) then
7485 return Membership_Entry (N);
7487 return Membership_Entry (N) or Membership_Entries (Next (N));
7489 end Membership_Entries;
7491 ----------------------
7492 -- Membership_Entry --
7493 ----------------------
7495 function Membership_Entry (N : Node_Id) return RList is
7503 if Nkind (N) = N_Range then
7504 if not Is_OK_Static_Expression (Low_Bound (N))
7506 not Is_OK_Static_Expression (High_Bound (N))
7510 SLo := Expr_Value (Low_Bound (N));
7511 SHi := Expr_Value (High_Bound (N));
7512 return RList'(1 => REnt
'(SLo, SHi));
7515 -- Static expression case
7517 elsif Is_OK_Static_Expression (N) then
7518 Val := Expr_Value (N);
7519 return RList'(1 => REnt
'(Val, Val));
7521 -- Identifier (other than static expression) case
7523 else pragma Assert (Nkind (N) = N_Identifier);
7527 if Is_Type (Entity (N)) then
7529 -- If type has predicates, process them
7531 if Has_Predicates (Entity (N)) then
7532 return Stat_Pred (Entity (N));
7534 -- For static subtype without predicates, get range
7536 elsif Is_OK_Static_Subtype (Entity (N)) then
7537 SLo := Expr_Value (Type_Low_Bound (Entity (N)));
7538 SHi := Expr_Value (Type_High_Bound (Entity (N)));
7539 return RList'(1 => REnt
'(SLo, SHi));
7541 -- Any other type makes us non-static
7547 -- Any other kind of identifier in predicate (e.g. a non-static
7548 -- expression value) means this is not a static predicate.
7554 end Membership_Entry;
7560 function Stat_Pred (Typ : Entity_Id) return RList is
7562 -- Not static if type does not have static predicates
7564 if not Has_Static_Predicate (Typ) then
7568 -- Otherwise we convert the predicate list to a range list
7571 Spred : constant List_Id := Static_Discrete_Predicate (Typ);
7572 Result : RList (1 .. List_Length (Spred));
7576 P := First (Static_Discrete_Predicate (Typ));
7577 for J in Result'Range loop
7578 Result (J) := REnt'(Lo_Val
(P
), Hi_Val
(P
));
7586 -- Start of processing for Build_Discrete_Static_Predicate
7589 -- Establish bounds for the predicate
7591 if Compile_Time_Known_Value
(Type_Low_Bound
(Typ
)) then
7592 TLo
:= Expr_Value
(Type_Low_Bound
(Typ
));
7597 if Compile_Time_Known_Value
(Type_High_Bound
(Typ
)) then
7598 THi
:= Expr_Value
(Type_High_Bound
(Typ
));
7603 -- Analyze the expression to see if it is a static predicate
7606 Ranges
: constant RList
:= Get_RList
(Expr
);
7607 -- Range list from expression if it is static
7612 -- Convert range list into a form for the static predicate. In the
7613 -- Ranges array, we just have raw ranges, these must be converted
7614 -- to properly typed and analyzed static expressions or range nodes.
7616 -- Note: here we limit ranges to the ranges of the subtype, so that
7617 -- a predicate is always false for values outside the subtype. That
7618 -- seems fine, such values are invalid anyway, and considering them
7619 -- to fail the predicate seems allowed and friendly, and furthermore
7620 -- simplifies processing for case statements and loops.
7624 for J
in Ranges
'Range loop
7626 Lo
: Uint
:= Ranges
(J
).Lo
;
7627 Hi
: Uint
:= Ranges
(J
).Hi
;
7630 -- Ignore completely out of range entry
7632 if Hi
< TLo
or else Lo
> THi
then
7635 -- Otherwise process entry
7638 -- Adjust out of range value to subtype range
7648 -- Convert range into required form
7650 Append_To
(Plist
, Build_Range
(Lo
, Hi
));
7655 -- Processing was successful and all entries were static, so now we
7656 -- can store the result as the predicate list.
7658 Set_Static_Discrete_Predicate
(Typ
, Plist
);
7660 -- The processing for static predicates put the expression into
7661 -- canonical form as a series of ranges. It also eliminated
7662 -- duplicates and collapsed and combined ranges. We might as well
7663 -- replace the alternatives list of the right operand of the
7664 -- membership test with the static predicate list, which will
7665 -- usually be more efficient.
7668 New_Alts
: constant List_Id
:= New_List
;
7673 Old_Node
:= First
(Plist
);
7674 while Present
(Old_Node
) loop
7675 New_Node
:= New_Copy
(Old_Node
);
7677 if Nkind
(New_Node
) = N_Range
then
7678 Set_Low_Bound
(New_Node
, New_Copy
(Low_Bound
(Old_Node
)));
7679 Set_High_Bound
(New_Node
, New_Copy
(High_Bound
(Old_Node
)));
7682 Append_To
(New_Alts
, New_Node
);
7686 -- If empty list, replace by False
7688 if Is_Empty_List
(New_Alts
) then
7689 Rewrite
(Expr
, New_Occurrence_Of
(Standard_False
, Loc
));
7691 -- Else replace by set membership test
7696 Left_Opnd
=> Make_Identifier
(Loc
, Nam
),
7697 Right_Opnd
=> Empty
,
7698 Alternatives
=> New_Alts
));
7700 -- Resolve new expression in function context
7702 Install_Formals
(Predicate_Function
(Typ
));
7703 Push_Scope
(Predicate_Function
(Typ
));
7704 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
7710 -- If non-static, return doing nothing
7715 end Build_Discrete_Static_Predicate
;
7717 -------------------------------------------
7718 -- Build_Invariant_Procedure_Declaration --
7719 -------------------------------------------
7721 function Build_Invariant_Procedure_Declaration
7722 (Typ
: Entity_Id
) return Node_Id
7724 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
7725 Object_Entity
: constant Entity_Id
:=
7726 Make_Defining_Identifier
(Loc
, New_Internal_Name
('I'));
7731 Set_Etype
(Object_Entity
, Typ
);
7733 -- Check for duplicate definiations.
7735 if Has_Invariants
(Typ
) and then Present
(Invariant_Procedure
(Typ
)) then
7740 Make_Defining_Identifier
(Loc
,
7741 Chars
=> New_External_Name
(Chars
(Typ
), "Invariant"));
7742 Set_Has_Invariants
(Typ
);
7743 Set_Ekind
(SId
, E_Procedure
);
7744 Set_Etype
(SId
, Standard_Void_Type
);
7745 Set_Is_Invariant_Procedure
(SId
);
7746 Set_Invariant_Procedure
(Typ
, SId
);
7749 Make_Procedure_Specification
(Loc
,
7750 Defining_Unit_Name
=> SId
,
7751 Parameter_Specifications
=> New_List
(
7752 Make_Parameter_Specification
(Loc
,
7753 Defining_Identifier
=> Object_Entity
,
7754 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))));
7756 return Make_Subprogram_Declaration
(Loc
, Specification
=> Spec
);
7757 end Build_Invariant_Procedure_Declaration
;
7759 -------------------------------
7760 -- Build_Invariant_Procedure --
7761 -------------------------------
7763 -- The procedure that is constructed here has the form
7765 -- procedure typInvariant (Ixxx : typ) is
7767 -- pragma Check (Invariant, exp, "failed invariant from xxx");
7768 -- pragma Check (Invariant, exp, "failed invariant from xxx");
7770 -- pragma Check (Invariant, exp, "failed inherited invariant from xxx");
7772 -- end typInvariant;
7774 procedure Build_Invariant_Procedure
(Typ
: Entity_Id
; N
: Node_Id
) is
7775 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
7783 -- Name for Check pragma, usually Invariant, but might be Type_Invariant
7784 -- if we come from a Type_Invariant aspect, we make sure to build the
7785 -- Check pragma with the right name, so that Check_Policy works right.
7787 Visible_Decls
: constant List_Id
:= Visible_Declarations
(N
);
7788 Private_Decls
: constant List_Id
:= Private_Declarations
(N
);
7790 procedure Add_Invariants
(T
: Entity_Id
; Inherit
: Boolean);
7791 -- Appends statements to Stmts for any invariants in the rep item chain
7792 -- of the given type. If Inherit is False, then we only process entries
7793 -- on the chain for the type Typ. If Inherit is True, then we ignore any
7794 -- Invariant aspects, but we process all Invariant'Class aspects, adding
7795 -- "inherited" to the exception message and generating an informational
7796 -- message about the inheritance of an invariant.
7798 Object_Name
: Name_Id
;
7799 -- Name for argument of invariant procedure
7801 Object_Entity
: Node_Id
;
7802 -- The entity of the formal for the procedure
7804 --------------------
7805 -- Add_Invariants --
7806 --------------------
7808 procedure Add_Invariants
(T
: Entity_Id
; Inherit
: Boolean) is
7818 procedure Replace_Type_Reference
(N
: Node_Id
);
7819 -- Replace a single occurrence N of the subtype name with a reference
7820 -- to the formal of the predicate function. N can be an identifier
7821 -- referencing the subtype, or a selected component, representing an
7822 -- appropriately qualified occurrence of the subtype name.
7824 procedure Replace_Type_References
is
7825 new Replace_Type_References_Generic
(Replace_Type_Reference
);
7826 -- Traverse an expression replacing all occurrences of the subtype
7827 -- name with appropriate references to the object that is the formal
7828 -- parameter of the predicate function. Note that we must ensure
7829 -- that the type and entity information is properly set in the
7830 -- replacement node, since we will do a Preanalyze call of this
7831 -- expression without proper visibility of the procedure argument.
7833 ----------------------------
7834 -- Replace_Type_Reference --
7835 ----------------------------
7837 -- Note: See comments in Add_Predicates.Replace_Type_Reference
7838 -- regarding handling of Sloc and Comes_From_Source.
7840 procedure Replace_Type_Reference
(N
: Node_Id
) is
7843 -- Add semantic information to node to be rewritten, for ASIS
7844 -- navigation needs.
7846 if Nkind
(N
) = N_Identifier
then
7850 elsif Nkind
(N
) = N_Selected_Component
then
7851 Analyze
(Prefix
(N
));
7852 Set_Entity
(Selector_Name
(N
), T
);
7853 Set_Etype
(Selector_Name
(N
), T
);
7856 -- Invariant'Class, replace with T'Class (obj)
7857 -- In ASIS mode, an inherited item is analyzed already, and the
7858 -- replacement has been done, so do not repeat transformation
7859 -- to prevent ill-formed tree.
7861 if Class_Present
(Ritem
) then
7863 and then Nkind
(Parent
(N
)) = N_Attribute_Reference
7864 and then Attribute_Name
(Parent
(N
)) = Name_Class
7870 Make_Type_Conversion
(Sloc
(N
),
7872 Make_Attribute_Reference
(Sloc
(N
),
7873 Prefix
=> New_Occurrence_Of
(T
, Sloc
(N
)),
7874 Attribute_Name
=> Name_Class
),
7876 Make_Identifier
(Sloc
(N
), Object_Name
)));
7878 Set_Entity
(Expression
(N
), Object_Entity
);
7879 Set_Etype
(Expression
(N
), Typ
);
7882 -- Invariant, replace with obj
7885 Rewrite
(N
, Make_Identifier
(Sloc
(N
), Object_Name
));
7886 Set_Entity
(N
, Object_Entity
);
7890 Set_Comes_From_Source
(N
, True);
7891 end Replace_Type_Reference
;
7893 -- Start of processing for Add_Invariants
7896 Ritem
:= First_Rep_Item
(T
);
7897 while Present
(Ritem
) loop
7898 if Nkind
(Ritem
) = N_Pragma
7899 and then Pragma_Name
(Ritem
) = Name_Invariant
7901 Arg1
:= First
(Pragma_Argument_Associations
(Ritem
));
7902 Arg2
:= Next
(Arg1
);
7903 Arg3
:= Next
(Arg2
);
7905 Arg1
:= Get_Pragma_Arg
(Arg1
);
7906 Arg2
:= Get_Pragma_Arg
(Arg2
);
7908 -- For Inherit case, ignore Invariant, process only Class case
7911 if not Class_Present
(Ritem
) then
7915 -- For Inherit false, process only item for right type
7918 if Entity
(Arg1
) /= Typ
then
7924 Stmts
:= Empty_List
;
7927 Exp
:= New_Copy_Tree
(Arg2
);
7929 -- Preserve sloc of original pragma Invariant
7931 Loc
:= Sloc
(Ritem
);
7933 -- We need to replace any occurrences of the name of the type
7934 -- with references to the object, converted to type'Class in
7935 -- the case of Invariant'Class aspects.
7937 Replace_Type_References
(Exp
, T
);
7939 -- If this invariant comes from an aspect, find the aspect
7940 -- specification, and replace the saved expression because
7941 -- we need the subtype references replaced for the calls to
7942 -- Preanalyze_Spec_Expressin in Check_Aspect_At_Freeze_Point
7943 -- and Check_Aspect_At_End_Of_Declarations.
7945 if From_Aspect_Specification
(Ritem
) then
7950 -- Loop to find corresponding aspect, note that this
7951 -- must be present given the pragma is marked delayed.
7953 -- Note: in practice Next_Rep_Item (Ritem) is Empty so
7954 -- this loop does nothing. Furthermore, why isn't this
7955 -- simply Corresponding_Aspect ???
7957 Aitem
:= Next_Rep_Item
(Ritem
);
7958 while Present
(Aitem
) loop
7959 if Nkind
(Aitem
) = N_Aspect_Specification
7960 and then Aspect_Rep_Item
(Aitem
) = Ritem
7963 (Identifier
(Aitem
), New_Copy_Tree
(Exp
));
7967 Aitem
:= Next_Rep_Item
(Aitem
);
7972 -- Now we need to preanalyze the expression to properly capture
7973 -- the visibility in the visible part. The expression will not
7974 -- be analyzed for real until the body is analyzed, but that is
7975 -- at the end of the private part and has the wrong visibility.
7977 Set_Parent
(Exp
, N
);
7978 Preanalyze_Assert_Expression
(Exp
, Any_Boolean
);
7980 -- A class-wide invariant may be inherited in a separate unit,
7981 -- where the corresponding expression cannot be resolved by
7982 -- visibility, because it refers to a local function. Propagate
7983 -- semantic information to the original representation item, to
7984 -- be used when an invariant procedure for a derived type is
7987 -- Unclear how to handle class-wide invariants that are not
7988 -- function calls ???
7991 and then Class_Present
(Ritem
)
7992 and then Nkind
(Exp
) = N_Function_Call
7993 and then Nkind
(Arg2
) = N_Indexed_Component
7996 Make_Function_Call
(Loc
,
7998 New_Occurrence_Of
(Entity
(Name
(Exp
)), Loc
),
7999 Parameter_Associations
=>
8000 New_Copy_List
(Expressions
(Arg2
))));
8003 -- In ASIS mode, even if assertions are not enabled, we must
8004 -- analyze the original expression in the aspect specification
8005 -- because it is part of the original tree.
8007 if ASIS_Mode
and then From_Aspect_Specification
(Ritem
) then
8009 Inv
: constant Node_Id
:=
8010 Expression
(Corresponding_Aspect
(Ritem
));
8012 Replace_Type_References
(Inv
, T
);
8013 Preanalyze_Assert_Expression
(Inv
, Standard_Boolean
);
8017 -- Get name to be used for Check pragma
8019 if not From_Aspect_Specification
(Ritem
) then
8020 Nam
:= Name_Invariant
;
8022 Nam
:= Chars
(Identifier
(Corresponding_Aspect
(Ritem
)));
8025 -- Build first two arguments for Check pragma
8029 Make_Pragma_Argument_Association
(Loc
,
8030 Expression
=> Make_Identifier
(Loc
, Chars
=> Nam
)),
8031 Make_Pragma_Argument_Association
(Loc
,
8032 Expression
=> Exp
));
8034 -- Add message if present in Invariant pragma
8036 if Present
(Arg3
) then
8037 Str
:= Strval
(Get_Pragma_Arg
(Arg3
));
8039 -- If inherited case, and message starts "failed invariant",
8040 -- change it to be "failed inherited invariant".
8043 String_To_Name_Buffer
(Str
);
8045 if Name_Buffer
(1 .. 16) = "failed invariant" then
8046 Insert_Str_In_Name_Buffer
("inherited ", 8);
8047 Str
:= String_From_Name_Buffer
;
8052 Make_Pragma_Argument_Association
(Loc
,
8053 Expression
=> Make_String_Literal
(Loc
, Str
)));
8056 -- Add Check pragma to list of statements
8060 Pragma_Identifier
=>
8061 Make_Identifier
(Loc
, Name_Check
),
8062 Pragma_Argument_Associations
=> Assoc
));
8064 -- If Inherited case and option enabled, output info msg. Note
8065 -- that we know this is a case of Invariant'Class.
8067 if Inherit
and Opt
.List_Inherited_Aspects
then
8068 Error_Msg_Sloc
:= Sloc
(Ritem
);
8070 ("info: & inherits `Invariant''Class` aspect from #?L?",
8076 Next_Rep_Item
(Ritem
);
8080 -- Start of processing for Build_Invariant_Procedure
8088 -- If the aspect specification exists for some view of the type, the
8089 -- declaration for the procedure has been created.
8091 if Has_Invariants
(Typ
) then
8092 SId
:= Invariant_Procedure
(Typ
);
8095 -- If the body is already present, nothing to do. This will occur when
8096 -- the type is already frozen, which is the case when the invariant
8097 -- appears in a private part, and the freezing takes place before the
8098 -- final pass over full declarations.
8100 -- See Exp_Ch3.Insert_Component_Invariant_Checks for details.
8102 if Present
(SId
) then
8103 PDecl
:= Unit_Declaration_Node
(SId
);
8106 and then Nkind
(PDecl
) = N_Subprogram_Declaration
8107 and then Present
(Corresponding_Body
(PDecl
))
8113 PDecl
:= Build_Invariant_Procedure_Declaration
(Typ
);
8116 -- Recover formal of procedure, for use in the calls to invariant
8117 -- functions (including inherited ones).
8121 (First
(Parameter_Specifications
(Specification
(PDecl
))));
8122 Object_Name
:= Chars
(Object_Entity
);
8124 -- Add invariants for the current type
8126 Add_Invariants
(Typ
, Inherit
=> False);
8128 -- Add invariants for parent types
8131 Current_Typ
: Entity_Id
;
8132 Parent_Typ
: Entity_Id
;
8137 Parent_Typ
:= Etype
(Current_Typ
);
8139 if Is_Private_Type
(Parent_Typ
)
8140 and then Present
(Full_View
(Base_Type
(Parent_Typ
)))
8142 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
8145 exit when Parent_Typ
= Current_Typ
;
8147 Current_Typ
:= Parent_Typ
;
8148 Add_Invariants
(Current_Typ
, Inherit
=> True);
8152 -- Add invariants of progenitors
8154 if Is_Tagged_Type
(Typ
) and then not Is_Interface
(Typ
) then
8156 Ifaces_List
: Elist_Id
;
8161 Collect_Interfaces
(Typ
, Ifaces_List
);
8163 AI
:= First_Elmt
(Ifaces_List
);
8164 while Present
(AI
) loop
8167 if not Is_Ancestor
(Iface
, Typ
, Use_Full_View
=> True) then
8168 Add_Invariants
(Iface
, Inherit
=> True);
8176 -- Build the procedure if we generated at least one Check pragma
8178 if Stmts
/= No_List
then
8179 Spec
:= Copy_Separate_Tree
(Specification
(PDecl
));
8182 Make_Subprogram_Body
(Loc
,
8183 Specification
=> Spec
,
8184 Declarations
=> Empty_List
,
8185 Handled_Statement_Sequence
=>
8186 Make_Handled_Sequence_Of_Statements
(Loc
,
8187 Statements
=> Stmts
));
8189 -- Insert procedure declaration and spec at the appropriate points.
8190 -- If declaration is already analyzed, it was processed by the
8191 -- generated pragma.
8193 if Present
(Private_Decls
) then
8195 -- The spec goes at the end of visible declarations, but they have
8196 -- already been analyzed, so we need to explicitly do the analyze.
8198 if not Analyzed
(PDecl
) then
8199 Append_To
(Visible_Decls
, PDecl
);
8203 -- The body goes at the end of the private declarations, which we
8204 -- have not analyzed yet, so we do not need to perform an explicit
8205 -- analyze call. We skip this if there are no private declarations
8206 -- (this is an error that will be caught elsewhere);
8208 Append_To
(Private_Decls
, PBody
);
8210 -- If the invariant appears on the full view of a type, the
8211 -- analysis of the private part is complete, and we must
8212 -- analyze the new body explicitly.
8214 if In_Private_Part
(Current_Scope
) then
8218 -- If there are no private declarations this may be an error that
8219 -- will be diagnosed elsewhere. However, if this is a non-private
8220 -- type that inherits invariants, it needs no completion and there
8221 -- may be no private part. In this case insert invariant procedure
8222 -- at end of current declarative list, and analyze at once, given
8223 -- that the type is about to be frozen.
8225 elsif not Is_Private_Type
(Typ
) then
8226 Append_To
(Visible_Decls
, PDecl
);
8227 Append_To
(Visible_Decls
, PBody
);
8232 end Build_Invariant_Procedure
;
8234 -------------------------------
8235 -- Build_Predicate_Functions --
8236 -------------------------------
8238 -- The procedures that are constructed here have the form:
8240 -- function typPredicate (Ixxx : typ) return Boolean is
8243 -- exp1 and then exp2 and then ...
8244 -- and then typ1Predicate (typ1 (Ixxx))
8245 -- and then typ2Predicate (typ2 (Ixxx))
8247 -- end typPredicate;
8249 -- Here exp1, and exp2 are expressions from Predicate pragmas. Note that
8250 -- this is the point at which these expressions get analyzed, providing the
8251 -- required delay, and typ1, typ2, are entities from which predicates are
8252 -- inherited. Note that we do NOT generate Check pragmas, that's because we
8253 -- use this function even if checks are off, e.g. for membership tests.
8255 -- If the expression has at least one Raise_Expression, then we also build
8256 -- the typPredicateM version of the function, in which any occurrence of a
8257 -- Raise_Expression is converted to "return False".
8259 procedure Build_Predicate_Functions
(Typ
: Entity_Id
; N
: Node_Id
) is
8260 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
8263 -- This is the expression for the result of the function. It is
8264 -- is build by connecting the component predicates with AND THEN.
8267 -- This is the corresponding return expression for the Predicate_M
8268 -- function. It differs in that raise expressions are marked for
8269 -- special expansion (see Process_REs).
8271 Object_Name
: constant Name_Id
:= New_Internal_Name
('I');
8272 -- Name for argument of Predicate procedure. Note that we use the same
8273 -- name for both predicate functions. That way the reference within the
8274 -- predicate expression is the same in both functions.
8276 Object_Entity
: constant Entity_Id
:=
8277 Make_Defining_Identifier
(Loc
, Chars
=> Object_Name
);
8278 -- Entity for argument of Predicate procedure
8280 Object_Entity_M
: constant Entity_Id
:=
8281 Make_Defining_Identifier
(Loc
, Chars
=> Object_Name
);
8282 -- Entity for argument of Predicate_M procedure
8284 Raise_Expression_Present
: Boolean := False;
8285 -- Set True if Expr has at least one Raise_Expression
8287 procedure Add_Call
(T
: Entity_Id
);
8288 -- Includes a call to the predicate function for type T in Expr if T
8289 -- has predicates and Predicate_Function (T) is non-empty.
8291 procedure Add_Predicates
;
8292 -- Appends expressions for any Predicate pragmas in the rep item chain
8293 -- Typ to Expr. Note that we look only at items for this exact entity.
8294 -- Inheritance of predicates for the parent type is done by calling the
8295 -- Predicate_Function of the parent type, using Add_Call above.
8297 function Test_RE
(N
: Node_Id
) return Traverse_Result
;
8298 -- Used in Test_REs, tests one node for being a raise expression, and if
8299 -- so sets Raise_Expression_Present True.
8301 procedure Test_REs
is new Traverse_Proc
(Test_RE
);
8302 -- Tests to see if Expr contains any raise expressions
8304 function Process_RE
(N
: Node_Id
) return Traverse_Result
;
8305 -- Used in Process REs, tests if node N is a raise expression, and if
8306 -- so, marks it to be converted to return False.
8308 procedure Process_REs
is new Traverse_Proc
(Process_RE
);
8309 -- Marks any raise expressions in Expr_M to return False
8315 procedure Add_Call
(T
: Entity_Id
) is
8319 if Present
(T
) and then Present
(Predicate_Function
(T
)) then
8320 Set_Has_Predicates
(Typ
);
8322 -- Build the call to the predicate function of T
8326 (T
, Convert_To
(T
, Make_Identifier
(Loc
, Object_Name
)));
8328 -- Add call to evolving expression, using AND THEN if needed
8335 Make_And_Then
(Sloc
(Expr
),
8336 Left_Opnd
=> Relocate_Node
(Expr
),
8340 -- Output info message on inheritance if required. Note we do not
8341 -- give this information for generic actual types, since it is
8342 -- unwelcome noise in that case in instantiations. We also
8343 -- generally suppress the message in instantiations, and also
8344 -- if it involves internal names.
8346 if Opt
.List_Inherited_Aspects
8347 and then not Is_Generic_Actual_Type
(Typ
)
8348 and then Instantiation_Depth
(Sloc
(Typ
)) = 0
8349 and then not Is_Internal_Name
(Chars
(T
))
8350 and then not Is_Internal_Name
(Chars
(Typ
))
8352 Error_Msg_Sloc
:= Sloc
(Predicate_Function
(T
));
8353 Error_Msg_Node_2
:= T
;
8354 Error_Msg_N
("info: & inherits predicate from & #?L?", Typ
);
8359 --------------------
8360 -- Add_Predicates --
8361 --------------------
8363 procedure Add_Predicates
is
8368 procedure Replace_Type_Reference
(N
: Node_Id
);
8369 -- Replace a single occurrence N of the subtype name with a reference
8370 -- to the formal of the predicate function. N can be an identifier
8371 -- referencing the subtype, or a selected component, representing an
8372 -- appropriately qualified occurrence of the subtype name.
8374 procedure Replace_Type_References
is
8375 new Replace_Type_References_Generic
(Replace_Type_Reference
);
8376 -- Traverse an expression changing every occurrence of an identifier
8377 -- whose name matches the name of the subtype with a reference to
8378 -- the formal parameter of the predicate function.
8380 ----------------------------
8381 -- Replace_Type_Reference --
8382 ----------------------------
8384 procedure Replace_Type_Reference
(N
: Node_Id
) is
8386 Rewrite
(N
, Make_Identifier
(Sloc
(N
), Object_Name
));
8387 -- Use the Sloc of the usage name, not the defining name
8390 Set_Entity
(N
, Object_Entity
);
8392 -- We want to treat the node as if it comes from source, so that
8393 -- ASIS will not ignore it
8395 Set_Comes_From_Source
(N
, True);
8396 end Replace_Type_Reference
;
8398 -- Start of processing for Add_Predicates
8401 Ritem
:= First_Rep_Item
(Typ
);
8402 while Present
(Ritem
) loop
8403 if Nkind
(Ritem
) = N_Pragma
8404 and then Pragma_Name
(Ritem
) = Name_Predicate
8406 -- Acquire arguments
8408 Arg1
:= First
(Pragma_Argument_Associations
(Ritem
));
8409 Arg2
:= Next
(Arg1
);
8411 Arg1
:= Get_Pragma_Arg
(Arg1
);
8412 Arg2
:= Get_Pragma_Arg
(Arg2
);
8414 -- See if this predicate pragma is for the current type or for
8415 -- its full view. A predicate on a private completion is placed
8416 -- on the partial view beause this is the visible entity that
8419 if Entity
(Arg1
) = Typ
8420 or else Full_View
(Entity
(Arg1
)) = Typ
8422 -- We have a match, this entry is for our subtype
8424 -- We need to replace any occurrences of the name of the
8425 -- type with references to the object.
8427 Replace_Type_References
(Arg2
, Typ
);
8429 -- If this predicate comes from an aspect, find the aspect
8430 -- specification, and replace the saved expression because
8431 -- we need the subtype references replaced for the calls to
8432 -- Preanalyze_Spec_Expressin in Check_Aspect_At_Freeze_Point
8433 -- and Check_Aspect_At_End_Of_Declarations.
8435 if From_Aspect_Specification
(Ritem
) then
8440 -- Loop to find corresponding aspect, note that this
8441 -- must be present given the pragma is marked delayed.
8443 Aitem
:= Next_Rep_Item
(Ritem
);
8445 if Nkind
(Aitem
) = N_Aspect_Specification
8446 and then Aspect_Rep_Item
(Aitem
) = Ritem
8449 (Identifier
(Aitem
), New_Copy_Tree
(Arg2
));
8453 Aitem
:= Next_Rep_Item
(Aitem
);
8458 -- Now we can add the expression
8461 Expr
:= Relocate_Node
(Arg2
);
8463 -- There already was a predicate, so add to it
8468 Left_Opnd
=> Relocate_Node
(Expr
),
8469 Right_Opnd
=> Relocate_Node
(Arg2
));
8474 Next_Rep_Item
(Ritem
);
8482 function Process_RE
(N
: Node_Id
) return Traverse_Result
is
8484 if Nkind
(N
) = N_Raise_Expression
then
8485 Set_Convert_To_Return_False
(N
);
8496 function Test_RE
(N
: Node_Id
) return Traverse_Result
is
8498 if Nkind
(N
) = N_Raise_Expression
then
8499 Raise_Expression_Present
:= True;
8506 -- Start of processing for Build_Predicate_Functions
8509 -- Return if already built or if type does not have predicates
8511 if not Has_Predicates
(Typ
)
8512 or else Present
(Predicate_Function
(Typ
))
8517 -- Prepare to construct predicate expression
8521 -- Add Predicates for the current type
8525 -- Add predicates for ancestor if present
8528 Atyp
: constant Entity_Id
:= Nearest_Ancestor
(Typ
);
8530 if Present
(Atyp
) then
8535 -- Case where predicates are present
8537 if Present
(Expr
) then
8539 -- Test for raise expression present
8543 -- If raise expression is present, capture a copy of Expr for use
8544 -- in building the predicateM function version later on. For this
8545 -- copy we replace references to Object_Entity by Object_Entity_M.
8547 if Raise_Expression_Present
then
8549 Map
: constant Elist_Id
:= New_Elmt_List
;
8550 New_V
: Entity_Id
:= Empty
;
8552 -- The unanalyzed expression will be copied and appear in
8553 -- both functions. Normally expressions do not declare new
8554 -- entities, but quantified expressions do, so we need to
8555 -- create new entities for their bound variables, to prevent
8556 -- multiple definitions in gigi.
8558 function Reset_Loop_Variable
(N
: Node_Id
)
8559 return Traverse_Result
;
8561 procedure Collect_Loop_Variables
is
8562 new Traverse_Proc
(Reset_Loop_Variable
);
8564 ------------------------
8565 -- Reset_Loop_Variable --
8566 ------------------------
8568 function Reset_Loop_Variable
(N
: Node_Id
)
8569 return Traverse_Result
8572 if Nkind
(N
) = N_Iterator_Specification
then
8573 New_V
:= Make_Defining_Identifier
8574 (Sloc
(N
), Chars
(Defining_Identifier
(N
)));
8576 Set_Defining_Identifier
(N
, New_V
);
8580 end Reset_Loop_Variable
;
8583 Append_Elmt
(Object_Entity
, Map
);
8584 Append_Elmt
(Object_Entity_M
, Map
);
8585 Expr_M
:= New_Copy_Tree
(Expr
, Map
=> Map
);
8586 Collect_Loop_Variables
(Expr_M
);
8590 -- Build the main predicate function
8593 SId
: constant Entity_Id
:=
8594 Make_Defining_Identifier
(Loc
,
8595 Chars
=> New_External_Name
(Chars
(Typ
), "Predicate"));
8596 -- The entity for the the function spec
8598 SIdB
: constant Entity_Id
:=
8599 Make_Defining_Identifier
(Loc
,
8600 Chars
=> New_External_Name
(Chars
(Typ
), "Predicate"));
8601 -- The entity for the function body
8608 -- Build function declaration
8610 Set_Ekind
(SId
, E_Function
);
8611 Set_Is_Internal
(SId
);
8612 Set_Is_Predicate_Function
(SId
);
8613 Set_Predicate_Function
(Typ
, SId
);
8615 -- The predicate function is shared between views of a type
8617 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
8618 Set_Predicate_Function
(Full_View
(Typ
), SId
);
8622 Make_Function_Specification
(Loc
,
8623 Defining_Unit_Name
=> SId
,
8624 Parameter_Specifications
=> New_List
(
8625 Make_Parameter_Specification
(Loc
,
8626 Defining_Identifier
=> Object_Entity
,
8627 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))),
8628 Result_Definition
=>
8629 New_Occurrence_Of
(Standard_Boolean
, Loc
));
8632 Make_Subprogram_Declaration
(Loc
,
8633 Specification
=> Spec
);
8635 -- Build function body
8638 Make_Function_Specification
(Loc
,
8639 Defining_Unit_Name
=> SIdB
,
8640 Parameter_Specifications
=> New_List
(
8641 Make_Parameter_Specification
(Loc
,
8642 Defining_Identifier
=>
8643 Make_Defining_Identifier
(Loc
, Object_Name
),
8645 New_Occurrence_Of
(Typ
, Loc
))),
8646 Result_Definition
=>
8647 New_Occurrence_Of
(Standard_Boolean
, Loc
));
8650 Make_Subprogram_Body
(Loc
,
8651 Specification
=> Spec
,
8652 Declarations
=> Empty_List
,
8653 Handled_Statement_Sequence
=>
8654 Make_Handled_Sequence_Of_Statements
(Loc
,
8655 Statements
=> New_List
(
8656 Make_Simple_Return_Statement
(Loc
,
8657 Expression
=> Expr
))));
8659 -- Insert declaration before freeze node and body after
8661 Insert_Before_And_Analyze
(N
, FDecl
);
8662 Insert_After_And_Analyze
(N
, FBody
);
8665 -- Test for raise expressions present and if so build M version
8667 if Raise_Expression_Present
then
8669 SId
: constant Entity_Id
:=
8670 Make_Defining_Identifier
(Loc
,
8671 Chars
=> New_External_Name
(Chars
(Typ
), "PredicateM"));
8672 -- The entity for the the function spec
8674 SIdB
: constant Entity_Id
:=
8675 Make_Defining_Identifier
(Loc
,
8676 Chars
=> New_External_Name
(Chars
(Typ
), "PredicateM"));
8677 -- The entity for the function body
8685 -- Mark any raise expressions for special expansion
8687 Process_REs
(Expr_M
);
8689 -- Build function declaration
8691 Set_Ekind
(SId
, E_Function
);
8692 Set_Is_Predicate_Function_M
(SId
);
8693 Set_Predicate_Function_M
(Typ
, SId
);
8695 -- The predicate function is shared between views of a type
8697 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
8698 Set_Predicate_Function_M
(Full_View
(Typ
), SId
);
8702 Make_Function_Specification
(Loc
,
8703 Defining_Unit_Name
=> SId
,
8704 Parameter_Specifications
=> New_List
(
8705 Make_Parameter_Specification
(Loc
,
8706 Defining_Identifier
=> Object_Entity_M
,
8707 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))),
8708 Result_Definition
=>
8709 New_Occurrence_Of
(Standard_Boolean
, Loc
));
8712 Make_Subprogram_Declaration
(Loc
,
8713 Specification
=> Spec
);
8715 -- Build function body
8718 Make_Function_Specification
(Loc
,
8719 Defining_Unit_Name
=> SIdB
,
8720 Parameter_Specifications
=> New_List
(
8721 Make_Parameter_Specification
(Loc
,
8722 Defining_Identifier
=>
8723 Make_Defining_Identifier
(Loc
, Object_Name
),
8725 New_Occurrence_Of
(Typ
, Loc
))),
8726 Result_Definition
=>
8727 New_Occurrence_Of
(Standard_Boolean
, Loc
));
8729 -- Build the body, we declare the boolean expression before
8730 -- doing the return, because we are not really confident of
8731 -- what happens if a return appears within a return.
8734 Make_Defining_Identifier
(Loc
,
8735 Chars
=> New_Internal_Name
('B'));
8738 Make_Subprogram_Body
(Loc
,
8739 Specification
=> Spec
,
8741 Declarations
=> New_List
(
8742 Make_Object_Declaration
(Loc
,
8743 Defining_Identifier
=> BTemp
,
8744 Constant_Present
=> True,
8745 Object_Definition
=>
8746 New_Occurrence_Of
(Standard_Boolean
, Loc
),
8747 Expression
=> Expr_M
)),
8749 Handled_Statement_Sequence
=>
8750 Make_Handled_Sequence_Of_Statements
(Loc
,
8751 Statements
=> New_List
(
8752 Make_Simple_Return_Statement
(Loc
,
8753 Expression
=> New_Occurrence_Of
(BTemp
, Loc
)))));
8755 -- Insert declaration before freeze node and body after
8757 Insert_Before_And_Analyze
(N
, FDecl
);
8758 Insert_After_And_Analyze
(N
, FBody
);
8762 -- See if we have a static predicate. Note that the answer may be
8763 -- yes even if we have an explicit Dynamic_Predicate present.
8770 if not Is_Scalar_Type
(Typ
) and then not Is_String_Type
(Typ
) then
8773 PS
:= Is_Predicate_Static
(Expr
, Object_Name
);
8776 -- Case where we have a predicate-static aspect
8780 -- We don't set Has_Static_Predicate_Aspect, since we can have
8781 -- any of the three cases (Predicate, Dynamic_Predicate, or
8782 -- Static_Predicate) generating a predicate with an expression
8783 -- that is predicate-static. We just indicate that we have a
8784 -- predicate that can be treated as static.
8786 Set_Has_Static_Predicate
(Typ
);
8788 -- For discrete subtype, build the static predicate list
8790 if Is_Discrete_Type
(Typ
) then
8791 Build_Discrete_Static_Predicate
(Typ
, Expr
, Object_Name
);
8793 -- If we don't get a static predicate list, it means that we
8794 -- have a case where this is not possible, most typically in
8795 -- the case where we inherit a dynamic predicate. We do not
8796 -- consider this an error, we just leave the predicate as
8797 -- dynamic. But if we do succeed in building the list, then
8798 -- we mark the predicate as static.
8800 if No
(Static_Discrete_Predicate
(Typ
)) then
8801 Set_Has_Static_Predicate
(Typ
, False);
8804 -- For real or string subtype, save predicate expression
8806 elsif Is_Real_Type
(Typ
) or else Is_String_Type
(Typ
) then
8807 Set_Static_Real_Or_String_Predicate
(Typ
, Expr
);
8810 -- Case of dynamic predicate (expression is not predicate-static)
8813 -- Again, we don't set Has_Dynamic_Predicate_Aspect, since that
8814 -- is only set if we have an explicit Dynamic_Predicate aspect
8815 -- given. Here we may simply have a Predicate aspect where the
8816 -- expression happens not to be predicate-static.
8818 -- Emit an error when the predicate is categorized as static
8819 -- but its expression is not predicate-static.
8821 -- First a little fiddling to get a nice location for the
8822 -- message. If the expression is of the form (A and then B),
8823 -- then use the left operand for the Sloc. This avoids getting
8824 -- confused by a call to a higher-level predicate with a less
8825 -- convenient source location.
8828 while Nkind
(EN
) = N_And_Then
loop
8829 EN
:= Left_Opnd
(EN
);
8832 -- Now post appropriate message
8834 if Has_Static_Predicate_Aspect
(Typ
) then
8835 if Is_Scalar_Type
(Typ
) or else Is_String_Type
(Typ
) then
8837 ("expression is not predicate-static (RM 3.2.4(16-22))",
8841 ("static predicate requires scalar or string type", EN
);
8847 end Build_Predicate_Functions
;
8849 -----------------------------------------
8850 -- Check_Aspect_At_End_Of_Declarations --
8851 -----------------------------------------
8853 procedure Check_Aspect_At_End_Of_Declarations
(ASN
: Node_Id
) is
8854 Ent
: constant Entity_Id
:= Entity
(ASN
);
8855 Ident
: constant Node_Id
:= Identifier
(ASN
);
8856 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Chars
(Ident
));
8858 End_Decl_Expr
: constant Node_Id
:= Entity
(Ident
);
8859 -- Expression to be analyzed at end of declarations
8861 Freeze_Expr
: constant Node_Id
:= Expression
(ASN
);
8862 -- Expression from call to Check_Aspect_At_Freeze_Point
8864 T
: constant Entity_Id
:= Etype
(Freeze_Expr
);
8865 -- Type required for preanalyze call
8868 -- Set False if error
8870 -- On entry to this procedure, Entity (Ident) contains a copy of the
8871 -- original expression from the aspect, saved for this purpose, and
8872 -- but Expression (Ident) is a preanalyzed copy of the expression,
8873 -- preanalyzed just after the freeze point.
8875 procedure Check_Overloaded_Name
;
8876 -- For aspects whose expression is simply a name, this routine checks if
8877 -- the name is overloaded or not. If so, it verifies there is an
8878 -- interpretation that matches the entity obtained at the freeze point,
8879 -- otherwise the compiler complains.
8881 ---------------------------
8882 -- Check_Overloaded_Name --
8883 ---------------------------
8885 procedure Check_Overloaded_Name
is
8887 if not Is_Overloaded
(End_Decl_Expr
) then
8888 Err
:= not Is_Entity_Name
(End_Decl_Expr
)
8889 or else Entity
(End_Decl_Expr
) /= Entity
(Freeze_Expr
);
8895 Index
: Interp_Index
;
8899 Get_First_Interp
(End_Decl_Expr
, Index
, It
);
8900 while Present
(It
.Typ
) loop
8901 if It
.Nam
= Entity
(Freeze_Expr
) then
8906 Get_Next_Interp
(Index
, It
);
8910 end Check_Overloaded_Name
;
8912 -- Start of processing for Check_Aspect_At_End_Of_Declarations
8915 -- Case of aspects Dimension, Dimension_System and Synchronization
8917 if A_Id
= Aspect_Synchronization
then
8920 -- Case of stream attributes, just have to compare entities. However,
8921 -- the expression is just a name (possibly overloaded), and there may
8922 -- be stream operations declared for unrelated types, so we just need
8923 -- to verify that one of these interpretations is the one available at
8924 -- at the freeze point.
8926 elsif A_Id
= Aspect_Input
or else
8927 A_Id
= Aspect_Output
or else
8928 A_Id
= Aspect_Read
or else
8931 Analyze
(End_Decl_Expr
);
8932 Check_Overloaded_Name
;
8934 elsif A_Id
= Aspect_Variable_Indexing
or else
8935 A_Id
= Aspect_Constant_Indexing
or else
8936 A_Id
= Aspect_Default_Iterator
or else
8937 A_Id
= Aspect_Iterator_Element
8939 -- Make type unfrozen before analysis, to prevent spurious errors
8940 -- about late attributes.
8942 Set_Is_Frozen
(Ent
, False);
8943 Analyze
(End_Decl_Expr
);
8944 Set_Is_Frozen
(Ent
, True);
8946 -- If the end of declarations comes before any other freeze
8947 -- point, the Freeze_Expr is not analyzed: no check needed.
8949 if Analyzed
(Freeze_Expr
) and then not In_Instance
then
8950 Check_Overloaded_Name
;
8958 -- Indicate that the expression comes from an aspect specification,
8959 -- which is used in subsequent analysis even if expansion is off.
8961 Set_Parent
(End_Decl_Expr
, ASN
);
8963 -- In a generic context the aspect expressions have not been
8964 -- preanalyzed, so do it now. There are no conformance checks
8965 -- to perform in this case.
8968 Check_Aspect_At_Freeze_Point
(ASN
);
8971 -- The default values attributes may be defined in the private part,
8972 -- and the analysis of the expression may take place when only the
8973 -- partial view is visible. The expression must be scalar, so use
8974 -- the full view to resolve.
8976 elsif (A_Id
= Aspect_Default_Value
8978 A_Id
= Aspect_Default_Component_Value
)
8979 and then Is_Private_Type
(T
)
8981 Preanalyze_Spec_Expression
(End_Decl_Expr
, Full_View
(T
));
8984 Preanalyze_Spec_Expression
(End_Decl_Expr
, T
);
8987 Err
:= not Fully_Conformant_Expressions
(End_Decl_Expr
, Freeze_Expr
);
8990 -- Output error message if error. Force error on aspect specification
8991 -- even if there is an error on the expression itself.
8995 ("!visibility of aspect for& changes after freeze point",
8998 ("info: & is frozen here, aspects evaluated at this point??",
8999 Freeze_Node
(Ent
), Ent
);
9001 end Check_Aspect_At_End_Of_Declarations
;
9003 ----------------------------------
9004 -- Check_Aspect_At_Freeze_Point --
9005 ----------------------------------
9007 procedure Check_Aspect_At_Freeze_Point
(ASN
: Node_Id
) is
9008 Ident
: constant Node_Id
:= Identifier
(ASN
);
9009 -- Identifier (use Entity field to save expression)
9011 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Chars
(Ident
));
9013 T
: Entity_Id
:= Empty
;
9014 -- Type required for preanalyze call
9017 -- On entry to this procedure, Entity (Ident) contains a copy of the
9018 -- original expression from the aspect, saved for this purpose.
9020 -- On exit from this procedure Entity (Ident) is unchanged, still
9021 -- containing that copy, but Expression (Ident) is a preanalyzed copy
9022 -- of the expression, preanalyzed just after the freeze point.
9024 -- Make a copy of the expression to be preanalyzed
9026 Set_Expression
(ASN
, New_Copy_Tree
(Entity
(Ident
)));
9028 -- Find type for preanalyze call
9032 -- No_Aspect should be impossible
9035 raise Program_Error
;
9037 -- Aspects taking an optional boolean argument
9039 when Boolean_Aspects |
9040 Library_Unit_Aspects
=>
9042 T
:= Standard_Boolean
;
9044 -- Aspects corresponding to attribute definition clauses
9046 when Aspect_Address
=>
9047 T
:= RTE
(RE_Address
);
9049 when Aspect_Attach_Handler
=>
9050 T
:= RTE
(RE_Interrupt_ID
);
9052 when Aspect_Bit_Order | Aspect_Scalar_Storage_Order
=>
9053 T
:= RTE
(RE_Bit_Order
);
9055 when Aspect_Convention
=>
9059 T
:= RTE
(RE_CPU_Range
);
9061 -- Default_Component_Value is resolved with the component type
9063 when Aspect_Default_Component_Value
=>
9064 T
:= Component_Type
(Entity
(ASN
));
9066 when Aspect_Default_Storage_Pool
=>
9067 T
:= Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
));
9069 -- Default_Value is resolved with the type entity in question
9071 when Aspect_Default_Value
=>
9074 when Aspect_Dispatching_Domain
=>
9075 T
:= RTE
(RE_Dispatching_Domain
);
9077 when Aspect_External_Tag
=>
9078 T
:= Standard_String
;
9080 when Aspect_External_Name
=>
9081 T
:= Standard_String
;
9083 when Aspect_Link_Name
=>
9084 T
:= Standard_String
;
9086 when Aspect_Priority | Aspect_Interrupt_Priority
=>
9087 T
:= Standard_Integer
;
9089 when Aspect_Relative_Deadline
=>
9090 T
:= RTE
(RE_Time_Span
);
9092 when Aspect_Small
=>
9093 T
:= Universal_Real
;
9095 -- For a simple storage pool, we have to retrieve the type of the
9096 -- pool object associated with the aspect's corresponding attribute
9097 -- definition clause.
9099 when Aspect_Simple_Storage_Pool
=>
9100 T
:= Etype
(Expression
(Aspect_Rep_Item
(ASN
)));
9102 when Aspect_Storage_Pool
=>
9103 T
:= Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
));
9105 when Aspect_Alignment |
9106 Aspect_Component_Size |
9107 Aspect_Machine_Radix |
9108 Aspect_Object_Size |
9110 Aspect_Storage_Size |
9111 Aspect_Stream_Size |
9112 Aspect_Value_Size
=>
9115 when Aspect_Linker_Section
=>
9116 T
:= Standard_String
;
9118 when Aspect_Synchronization
=>
9121 -- Special case, the expression of these aspects is just an entity
9122 -- that does not need any resolution, so just analyze.
9131 Analyze
(Expression
(ASN
));
9134 -- Same for Iterator aspects, where the expression is a function
9135 -- name. Legality rules are checked separately.
9137 when Aspect_Constant_Indexing |
9138 Aspect_Default_Iterator |
9139 Aspect_Iterator_Element |
9140 Aspect_Variable_Indexing
=>
9141 Analyze
(Expression
(ASN
));
9144 -- Ditto for Iterable, legality checks in Validate_Iterable_Aspect.
9146 when Aspect_Iterable
=>
9150 Cursor
: constant Entity_Id
:= Get_Cursor_Type
(ASN
, T
);
9155 if Cursor
= Any_Type
then
9159 Assoc
:= First
(Component_Associations
(Expression
(ASN
)));
9160 while Present
(Assoc
) loop
9161 Expr
:= Expression
(Assoc
);
9164 if not Error_Posted
(Expr
) then
9165 Resolve_Iterable_Operation
9166 (Expr
, Cursor
, T
, Chars
(First
(Choices
(Assoc
))));
9175 -- Invariant/Predicate take boolean expressions
9177 when Aspect_Dynamic_Predicate |
9180 Aspect_Static_Predicate |
9181 Aspect_Type_Invariant
=>
9182 T
:= Standard_Boolean
;
9184 -- Here is the list of aspects that don't require delay analysis
9186 when Aspect_Abstract_State |
9188 Aspect_Contract_Cases |
9189 Aspect_Default_Initial_Condition |
9192 Aspect_Dimension_System |
9193 Aspect_Extensions_Visible |
9196 Aspect_Implicit_Dereference |
9197 Aspect_Initial_Condition |
9198 Aspect_Initializes |
9199 Aspect_Obsolescent |
9202 Aspect_Postcondition |
9204 Aspect_Precondition |
9205 Aspect_Refined_Depends |
9206 Aspect_Refined_Global |
9207 Aspect_Refined_Post |
9208 Aspect_Refined_State |
9211 Aspect_Unimplemented
=>
9212 raise Program_Error
;
9216 -- Do the preanalyze call
9218 Preanalyze_Spec_Expression
(Expression
(ASN
), T
);
9219 end Check_Aspect_At_Freeze_Point
;
9221 -----------------------------------
9222 -- Check_Constant_Address_Clause --
9223 -----------------------------------
9225 procedure Check_Constant_Address_Clause
9229 procedure Check_At_Constant_Address
(Nod
: Node_Id
);
9230 -- Checks that the given node N represents a name whose 'Address is
9231 -- constant (in the same sense as OK_Constant_Address_Clause, i.e. the
9232 -- address value is the same at the point of declaration of U_Ent and at
9233 -- the time of elaboration of the address clause.
9235 procedure Check_Expr_Constants
(Nod
: Node_Id
);
9236 -- Checks that Nod meets the requirements for a constant address clause
9237 -- in the sense of the enclosing procedure.
9239 procedure Check_List_Constants
(Lst
: List_Id
);
9240 -- Check that all elements of list Lst meet the requirements for a
9241 -- constant address clause in the sense of the enclosing procedure.
9243 -------------------------------
9244 -- Check_At_Constant_Address --
9245 -------------------------------
9247 procedure Check_At_Constant_Address
(Nod
: Node_Id
) is
9249 if Is_Entity_Name
(Nod
) then
9250 if Present
(Address_Clause
(Entity
((Nod
)))) then
9252 ("invalid address clause for initialized object &!",
9255 ("address for& cannot" &
9256 " depend on another address clause! (RM 13.1(22))!",
9259 elsif In_Same_Source_Unit
(Entity
(Nod
), U_Ent
)
9260 and then Sloc
(U_Ent
) < Sloc
(Entity
(Nod
))
9263 ("invalid address clause for initialized object &!",
9265 Error_Msg_Node_2
:= U_Ent
;
9267 ("\& must be defined before & (RM 13.1(22))!",
9271 elsif Nkind
(Nod
) = N_Selected_Component
then
9273 T
: constant Entity_Id
:= Etype
(Prefix
(Nod
));
9276 if (Is_Record_Type
(T
)
9277 and then Has_Discriminants
(T
))
9280 and then Is_Record_Type
(Designated_Type
(T
))
9281 and then Has_Discriminants
(Designated_Type
(T
)))
9284 ("invalid address clause for initialized object &!",
9287 ("\address cannot depend on component" &
9288 " of discriminated record (RM 13.1(22))!",
9291 Check_At_Constant_Address
(Prefix
(Nod
));
9295 elsif Nkind
(Nod
) = N_Indexed_Component
then
9296 Check_At_Constant_Address
(Prefix
(Nod
));
9297 Check_List_Constants
(Expressions
(Nod
));
9300 Check_Expr_Constants
(Nod
);
9302 end Check_At_Constant_Address
;
9304 --------------------------
9305 -- Check_Expr_Constants --
9306 --------------------------
9308 procedure Check_Expr_Constants
(Nod
: Node_Id
) is
9309 Loc_U_Ent
: constant Source_Ptr
:= Sloc
(U_Ent
);
9310 Ent
: Entity_Id
:= Empty
;
9313 if Nkind
(Nod
) in N_Has_Etype
9314 and then Etype
(Nod
) = Any_Type
9320 when N_Empty | N_Error
=>
9323 when N_Identifier | N_Expanded_Name
=>
9324 Ent
:= Entity
(Nod
);
9326 -- We need to look at the original node if it is different
9327 -- from the node, since we may have rewritten things and
9328 -- substituted an identifier representing the rewrite.
9330 if Original_Node
(Nod
) /= Nod
then
9331 Check_Expr_Constants
(Original_Node
(Nod
));
9333 -- If the node is an object declaration without initial
9334 -- value, some code has been expanded, and the expression
9335 -- is not constant, even if the constituents might be
9336 -- acceptable, as in A'Address + offset.
9338 if Ekind
(Ent
) = E_Variable
9340 Nkind
(Declaration_Node
(Ent
)) = N_Object_Declaration
9342 No
(Expression
(Declaration_Node
(Ent
)))
9345 ("invalid address clause for initialized object &!",
9348 -- If entity is constant, it may be the result of expanding
9349 -- a check. We must verify that its declaration appears
9350 -- before the object in question, else we also reject the
9353 elsif Ekind
(Ent
) = E_Constant
9354 and then In_Same_Source_Unit
(Ent
, U_Ent
)
9355 and then Sloc
(Ent
) > Loc_U_Ent
9358 ("invalid address clause for initialized object &!",
9365 -- Otherwise look at the identifier and see if it is OK
9367 if Ekind_In
(Ent
, E_Named_Integer
, E_Named_Real
)
9368 or else Is_Type
(Ent
)
9372 elsif Ekind_In
(Ent
, E_Constant
, E_In_Parameter
) then
9374 -- This is the case where we must have Ent defined before
9375 -- U_Ent. Clearly if they are in different units this
9376 -- requirement is met since the unit containing Ent is
9377 -- already processed.
9379 if not In_Same_Source_Unit
(Ent
, U_Ent
) then
9382 -- Otherwise location of Ent must be before the location
9383 -- of U_Ent, that's what prior defined means.
9385 elsif Sloc
(Ent
) < Loc_U_Ent
then
9390 ("invalid address clause for initialized object &!",
9392 Error_Msg_Node_2
:= U_Ent
;
9394 ("\& must be defined before & (RM 13.1(22))!",
9398 elsif Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
9399 Check_Expr_Constants
(Original_Node
(Nod
));
9403 ("invalid address clause for initialized object &!",
9406 if Comes_From_Source
(Ent
) then
9408 ("\reference to variable& not allowed"
9409 & " (RM 13.1(22))!", Nod
, Ent
);
9412 ("non-static expression not allowed"
9413 & " (RM 13.1(22))!", Nod
);
9417 when N_Integer_Literal
=>
9419 -- If this is a rewritten unchecked conversion, in a system
9420 -- where Address is an integer type, always use the base type
9421 -- for a literal value. This is user-friendly and prevents
9422 -- order-of-elaboration issues with instances of unchecked
9425 if Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
9426 Set_Etype
(Nod
, Base_Type
(Etype
(Nod
)));
9429 when N_Real_Literal |
9431 N_Character_Literal
=>
9435 Check_Expr_Constants
(Low_Bound
(Nod
));
9436 Check_Expr_Constants
(High_Bound
(Nod
));
9438 when N_Explicit_Dereference
=>
9439 Check_Expr_Constants
(Prefix
(Nod
));
9441 when N_Indexed_Component
=>
9442 Check_Expr_Constants
(Prefix
(Nod
));
9443 Check_List_Constants
(Expressions
(Nod
));
9446 Check_Expr_Constants
(Prefix
(Nod
));
9447 Check_Expr_Constants
(Discrete_Range
(Nod
));
9449 when N_Selected_Component
=>
9450 Check_Expr_Constants
(Prefix
(Nod
));
9452 when N_Attribute_Reference
=>
9453 if Nam_In
(Attribute_Name
(Nod
), Name_Address
,
9455 Name_Unchecked_Access
,
9456 Name_Unrestricted_Access
)
9458 Check_At_Constant_Address
(Prefix
(Nod
));
9461 Check_Expr_Constants
(Prefix
(Nod
));
9462 Check_List_Constants
(Expressions
(Nod
));
9466 Check_List_Constants
(Component_Associations
(Nod
));
9467 Check_List_Constants
(Expressions
(Nod
));
9469 when N_Component_Association
=>
9470 Check_Expr_Constants
(Expression
(Nod
));
9472 when N_Extension_Aggregate
=>
9473 Check_Expr_Constants
(Ancestor_Part
(Nod
));
9474 Check_List_Constants
(Component_Associations
(Nod
));
9475 Check_List_Constants
(Expressions
(Nod
));
9480 when N_Binary_Op | N_Short_Circuit | N_Membership_Test
=>
9481 Check_Expr_Constants
(Left_Opnd
(Nod
));
9482 Check_Expr_Constants
(Right_Opnd
(Nod
));
9485 Check_Expr_Constants
(Right_Opnd
(Nod
));
9487 when N_Type_Conversion |
9488 N_Qualified_Expression |
9490 N_Unchecked_Type_Conversion
=>
9491 Check_Expr_Constants
(Expression
(Nod
));
9493 when N_Function_Call
=>
9494 if not Is_Pure
(Entity
(Name
(Nod
))) then
9496 ("invalid address clause for initialized object &!",
9500 ("\function & is not pure (RM 13.1(22))!",
9501 Nod
, Entity
(Name
(Nod
)));
9504 Check_List_Constants
(Parameter_Associations
(Nod
));
9507 when N_Parameter_Association
=>
9508 Check_Expr_Constants
(Explicit_Actual_Parameter
(Nod
));
9512 ("invalid address clause for initialized object &!",
9515 ("\must be constant defined before& (RM 13.1(22))!",
9518 end Check_Expr_Constants
;
9520 --------------------------
9521 -- Check_List_Constants --
9522 --------------------------
9524 procedure Check_List_Constants
(Lst
: List_Id
) is
9528 if Present
(Lst
) then
9529 Nod1
:= First
(Lst
);
9530 while Present
(Nod1
) loop
9531 Check_Expr_Constants
(Nod1
);
9535 end Check_List_Constants
;
9537 -- Start of processing for Check_Constant_Address_Clause
9540 -- If rep_clauses are to be ignored, no need for legality checks. In
9541 -- particular, no need to pester user about rep clauses that violate the
9542 -- rule on constant addresses, given that these clauses will be removed
9543 -- by Freeze before they reach the back end. Similarly in CodePeer mode,
9544 -- we want to relax these checks.
9546 if not Ignore_Rep_Clauses
and not CodePeer_Mode
then
9547 Check_Expr_Constants
(Expr
);
9549 end Check_Constant_Address_Clause
;
9551 ---------------------------
9552 -- Check_Pool_Size_Clash --
9553 ---------------------------
9555 procedure Check_Pool_Size_Clash
(Ent
: Entity_Id
; SP
, SS
: Node_Id
) is
9559 -- We need to find out which one came first. Note that in the case of
9560 -- aspects mixed with pragmas there are cases where the processing order
9561 -- is reversed, which is why we do the check here.
9563 if Sloc
(SP
) < Sloc
(SS
) then
9564 Error_Msg_Sloc
:= Sloc
(SP
);
9566 Error_Msg_NE
("Storage_Pool previously given for&#", Post
, Ent
);
9569 Error_Msg_Sloc
:= Sloc
(SS
);
9571 Error_Msg_NE
("Storage_Size previously given for&#", Post
, Ent
);
9575 ("\cannot have Storage_Size and Storage_Pool (RM 13.11(3))", Post
);
9576 end Check_Pool_Size_Clash
;
9578 ----------------------------------------
9579 -- Check_Record_Representation_Clause --
9580 ----------------------------------------
9582 procedure Check_Record_Representation_Clause
(N
: Node_Id
) is
9583 Loc
: constant Source_Ptr
:= Sloc
(N
);
9584 Ident
: constant Node_Id
:= Identifier
(N
);
9585 Rectype
: Entity_Id
;
9590 Hbit
: Uint
:= Uint_0
;
9594 Max_Bit_So_Far
: Uint
;
9595 -- Records the maximum bit position so far. If all field positions
9596 -- are monotonically increasing, then we can skip the circuit for
9597 -- checking for overlap, since no overlap is possible.
9599 Tagged_Parent
: Entity_Id
:= Empty
;
9600 -- This is set in the case of a derived tagged type for which we have
9601 -- Is_Fully_Repped_Tagged_Type True (indicating that all components are
9602 -- positioned by record representation clauses). In this case we must
9603 -- check for overlap between components of this tagged type, and the
9604 -- components of its parent. Tagged_Parent will point to this parent
9605 -- type. For all other cases Tagged_Parent is left set to Empty.
9607 Parent_Last_Bit
: Uint
;
9608 -- Relevant only if Tagged_Parent is set, Parent_Last_Bit indicates the
9609 -- last bit position for any field in the parent type. We only need to
9610 -- check overlap for fields starting below this point.
9612 Overlap_Check_Required
: Boolean;
9613 -- Used to keep track of whether or not an overlap check is required
9615 Overlap_Detected
: Boolean := False;
9616 -- Set True if an overlap is detected
9618 Ccount
: Natural := 0;
9619 -- Number of component clauses in record rep clause
9621 procedure Check_Component_Overlap
(C1_Ent
, C2_Ent
: Entity_Id
);
9622 -- Given two entities for record components or discriminants, checks
9623 -- if they have overlapping component clauses and issues errors if so.
9625 procedure Find_Component
;
9626 -- Finds component entity corresponding to current component clause (in
9627 -- CC), and sets Comp to the entity, and Fbit/Lbit to the zero origin
9628 -- start/stop bits for the field. If there is no matching component or
9629 -- if the matching component does not have a component clause, then
9630 -- that's an error and Comp is set to Empty, but no error message is
9631 -- issued, since the message was already given. Comp is also set to
9632 -- Empty if the current "component clause" is in fact a pragma.
9634 -----------------------------
9635 -- Check_Component_Overlap --
9636 -----------------------------
9638 procedure Check_Component_Overlap
(C1_Ent
, C2_Ent
: Entity_Id
) is
9639 CC1
: constant Node_Id
:= Component_Clause
(C1_Ent
);
9640 CC2
: constant Node_Id
:= Component_Clause
(C2_Ent
);
9643 if Present
(CC1
) and then Present
(CC2
) then
9645 -- Exclude odd case where we have two tag components in the same
9646 -- record, both at location zero. This seems a bit strange, but
9647 -- it seems to happen in some circumstances, perhaps on an error.
9649 if Nam_In
(Chars
(C1_Ent
), Name_uTag
, Name_uTag
) then
9653 -- Here we check if the two fields overlap
9656 S1
: constant Uint
:= Component_Bit_Offset
(C1_Ent
);
9657 S2
: constant Uint
:= Component_Bit_Offset
(C2_Ent
);
9658 E1
: constant Uint
:= S1
+ Esize
(C1_Ent
);
9659 E2
: constant Uint
:= S2
+ Esize
(C2_Ent
);
9662 if E2
<= S1
or else E1
<= S2
then
9665 Error_Msg_Node_2
:= Component_Name
(CC2
);
9666 Error_Msg_Sloc
:= Sloc
(Error_Msg_Node_2
);
9667 Error_Msg_Node_1
:= Component_Name
(CC1
);
9669 ("component& overlaps & #", Component_Name
(CC1
));
9670 Overlap_Detected
:= True;
9674 end Check_Component_Overlap
;
9676 --------------------
9677 -- Find_Component --
9678 --------------------
9680 procedure Find_Component
is
9682 procedure Search_Component
(R
: Entity_Id
);
9683 -- Search components of R for a match. If found, Comp is set
9685 ----------------------
9686 -- Search_Component --
9687 ----------------------
9689 procedure Search_Component
(R
: Entity_Id
) is
9691 Comp
:= First_Component_Or_Discriminant
(R
);
9692 while Present
(Comp
) loop
9694 -- Ignore error of attribute name for component name (we
9695 -- already gave an error message for this, so no need to
9698 if Nkind
(Component_Name
(CC
)) = N_Attribute_Reference
then
9701 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
9704 Next_Component_Or_Discriminant
(Comp
);
9706 end Search_Component
;
9708 -- Start of processing for Find_Component
9711 -- Return with Comp set to Empty if we have a pragma
9713 if Nkind
(CC
) = N_Pragma
then
9718 -- Search current record for matching component
9720 Search_Component
(Rectype
);
9722 -- If not found, maybe component of base type discriminant that is
9723 -- absent from statically constrained first subtype.
9726 Search_Component
(Base_Type
(Rectype
));
9729 -- If no component, or the component does not reference the component
9730 -- clause in question, then there was some previous error for which
9731 -- we already gave a message, so just return with Comp Empty.
9733 if No
(Comp
) or else Component_Clause
(Comp
) /= CC
then
9734 Check_Error_Detected
;
9737 -- Normal case where we have a component clause
9740 Fbit
:= Component_Bit_Offset
(Comp
);
9741 Lbit
:= Fbit
+ Esize
(Comp
) - 1;
9745 -- Start of processing for Check_Record_Representation_Clause
9749 Rectype
:= Entity
(Ident
);
9751 if Rectype
= Any_Type
then
9754 Rectype
:= Underlying_Type
(Rectype
);
9757 -- See if we have a fully repped derived tagged type
9760 PS
: constant Entity_Id
:= Parent_Subtype
(Rectype
);
9763 if Present
(PS
) and then Is_Fully_Repped_Tagged_Type
(PS
) then
9764 Tagged_Parent
:= PS
;
9766 -- Find maximum bit of any component of the parent type
9768 Parent_Last_Bit
:= UI_From_Int
(System_Address_Size
- 1);
9769 Pcomp
:= First_Entity
(Tagged_Parent
);
9770 while Present
(Pcomp
) loop
9771 if Ekind_In
(Pcomp
, E_Discriminant
, E_Component
) then
9772 if Component_Bit_Offset
(Pcomp
) /= No_Uint
9773 and then Known_Static_Esize
(Pcomp
)
9778 Component_Bit_Offset
(Pcomp
) + Esize
(Pcomp
) - 1);
9781 Next_Entity
(Pcomp
);
9787 -- All done if no component clauses
9789 CC
:= First
(Component_Clauses
(N
));
9795 -- If a tag is present, then create a component clause that places it
9796 -- at the start of the record (otherwise gigi may place it after other
9797 -- fields that have rep clauses).
9799 Fent
:= First_Entity
(Rectype
);
9801 if Nkind
(Fent
) = N_Defining_Identifier
9802 and then Chars
(Fent
) = Name_uTag
9804 Set_Component_Bit_Offset
(Fent
, Uint_0
);
9805 Set_Normalized_Position
(Fent
, Uint_0
);
9806 Set_Normalized_First_Bit
(Fent
, Uint_0
);
9807 Set_Normalized_Position_Max
(Fent
, Uint_0
);
9808 Init_Esize
(Fent
, System_Address_Size
);
9810 Set_Component_Clause
(Fent
,
9811 Make_Component_Clause
(Loc
,
9812 Component_Name
=> Make_Identifier
(Loc
, Name_uTag
),
9814 Position
=> Make_Integer_Literal
(Loc
, Uint_0
),
9815 First_Bit
=> Make_Integer_Literal
(Loc
, Uint_0
),
9817 Make_Integer_Literal
(Loc
,
9818 UI_From_Int
(System_Address_Size
))));
9820 Ccount
:= Ccount
+ 1;
9823 Max_Bit_So_Far
:= Uint_Minus_1
;
9824 Overlap_Check_Required
:= False;
9826 -- Process the component clauses
9828 while Present
(CC
) loop
9831 if Present
(Comp
) then
9832 Ccount
:= Ccount
+ 1;
9834 -- We need a full overlap check if record positions non-monotonic
9836 if Fbit
<= Max_Bit_So_Far
then
9837 Overlap_Check_Required
:= True;
9840 Max_Bit_So_Far
:= Lbit
;
9842 -- Check bit position out of range of specified size
9844 if Has_Size_Clause
(Rectype
)
9845 and then RM_Size
(Rectype
) <= Lbit
9848 ("bit number out of range of specified size",
9851 -- Check for overlap with tag component
9854 if Is_Tagged_Type
(Rectype
)
9855 and then Fbit
< System_Address_Size
9858 ("component overlaps tag field of&",
9859 Component_Name
(CC
), Rectype
);
9860 Overlap_Detected
:= True;
9868 -- Check parent overlap if component might overlap parent field
9870 if Present
(Tagged_Parent
) and then Fbit
<= Parent_Last_Bit
then
9871 Pcomp
:= First_Component_Or_Discriminant
(Tagged_Parent
);
9872 while Present
(Pcomp
) loop
9873 if not Is_Tag
(Pcomp
)
9874 and then Chars
(Pcomp
) /= Name_uParent
9876 Check_Component_Overlap
(Comp
, Pcomp
);
9879 Next_Component_Or_Discriminant
(Pcomp
);
9887 -- Now that we have processed all the component clauses, check for
9888 -- overlap. We have to leave this till last, since the components can
9889 -- appear in any arbitrary order in the representation clause.
9891 -- We do not need this check if all specified ranges were monotonic,
9892 -- as recorded by Overlap_Check_Required being False at this stage.
9894 -- This first section checks if there are any overlapping entries at
9895 -- all. It does this by sorting all entries and then seeing if there are
9896 -- any overlaps. If there are none, then that is decisive, but if there
9897 -- are overlaps, they may still be OK (they may result from fields in
9898 -- different variants).
9900 if Overlap_Check_Required
then
9901 Overlap_Check1
: declare
9903 OC_Fbit
: array (0 .. Ccount
) of Uint
;
9904 -- First-bit values for component clauses, the value is the offset
9905 -- of the first bit of the field from start of record. The zero
9906 -- entry is for use in sorting.
9908 OC_Lbit
: array (0 .. Ccount
) of Uint
;
9909 -- Last-bit values for component clauses, the value is the offset
9910 -- of the last bit of the field from start of record. The zero
9911 -- entry is for use in sorting.
9913 OC_Count
: Natural := 0;
9914 -- Count of entries in OC_Fbit and OC_Lbit
9916 function OC_Lt
(Op1
, Op2
: Natural) return Boolean;
9917 -- Compare routine for Sort
9919 procedure OC_Move
(From
: Natural; To
: Natural);
9920 -- Move routine for Sort
9922 package Sorting
is new GNAT
.Heap_Sort_G
(OC_Move
, OC_Lt
);
9928 function OC_Lt
(Op1
, Op2
: Natural) return Boolean is
9930 return OC_Fbit
(Op1
) < OC_Fbit
(Op2
);
9937 procedure OC_Move
(From
: Natural; To
: Natural) is
9939 OC_Fbit
(To
) := OC_Fbit
(From
);
9940 OC_Lbit
(To
) := OC_Lbit
(From
);
9943 -- Start of processing for Overlap_Check
9946 CC
:= First
(Component_Clauses
(N
));
9947 while Present
(CC
) loop
9949 -- Exclude component clause already marked in error
9951 if not Error_Posted
(CC
) then
9954 if Present
(Comp
) then
9955 OC_Count
:= OC_Count
+ 1;
9956 OC_Fbit
(OC_Count
) := Fbit
;
9957 OC_Lbit
(OC_Count
) := Lbit
;
9964 Sorting
.Sort
(OC_Count
);
9966 Overlap_Check_Required
:= False;
9967 for J
in 1 .. OC_Count
- 1 loop
9968 if OC_Lbit
(J
) >= OC_Fbit
(J
+ 1) then
9969 Overlap_Check_Required
:= True;
9976 -- If Overlap_Check_Required is still True, then we have to do the full
9977 -- scale overlap check, since we have at least two fields that do
9978 -- overlap, and we need to know if that is OK since they are in
9979 -- different variant, or whether we have a definite problem.
9981 if Overlap_Check_Required
then
9982 Overlap_Check2
: declare
9983 C1_Ent
, C2_Ent
: Entity_Id
;
9984 -- Entities of components being checked for overlap
9987 -- Component_List node whose Component_Items are being checked
9990 -- Component declaration for component being checked
9993 C1_Ent
:= First_Entity
(Base_Type
(Rectype
));
9995 -- Loop through all components in record. For each component check
9996 -- for overlap with any of the preceding elements on the component
9997 -- list containing the component and also, if the component is in
9998 -- a variant, check against components outside the case structure.
9999 -- This latter test is repeated recursively up the variant tree.
10001 Main_Component_Loop
: while Present
(C1_Ent
) loop
10002 if not Ekind_In
(C1_Ent
, E_Component
, E_Discriminant
) then
10003 goto Continue_Main_Component_Loop
;
10006 -- Skip overlap check if entity has no declaration node. This
10007 -- happens with discriminants in constrained derived types.
10008 -- Possibly we are missing some checks as a result, but that
10009 -- does not seem terribly serious.
10011 if No
(Declaration_Node
(C1_Ent
)) then
10012 goto Continue_Main_Component_Loop
;
10015 Clist
:= Parent
(List_Containing
(Declaration_Node
(C1_Ent
)));
10017 -- Loop through component lists that need checking. Check the
10018 -- current component list and all lists in variants above us.
10020 Component_List_Loop
: loop
10022 -- If derived type definition, go to full declaration
10023 -- If at outer level, check discriminants if there are any.
10025 if Nkind
(Clist
) = N_Derived_Type_Definition
then
10026 Clist
:= Parent
(Clist
);
10029 -- Outer level of record definition, check discriminants
10031 if Nkind_In
(Clist
, N_Full_Type_Declaration
,
10032 N_Private_Type_Declaration
)
10034 if Has_Discriminants
(Defining_Identifier
(Clist
)) then
10036 First_Discriminant
(Defining_Identifier
(Clist
));
10037 while Present
(C2_Ent
) loop
10038 exit when C1_Ent
= C2_Ent
;
10039 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
10040 Next_Discriminant
(C2_Ent
);
10044 -- Record extension case
10046 elsif Nkind
(Clist
) = N_Derived_Type_Definition
then
10049 -- Otherwise check one component list
10052 Citem
:= First
(Component_Items
(Clist
));
10053 while Present
(Citem
) loop
10054 if Nkind
(Citem
) = N_Component_Declaration
then
10055 C2_Ent
:= Defining_Identifier
(Citem
);
10056 exit when C1_Ent
= C2_Ent
;
10057 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
10064 -- Check for variants above us (the parent of the Clist can
10065 -- be a variant, in which case its parent is a variant part,
10066 -- and the parent of the variant part is a component list
10067 -- whose components must all be checked against the current
10068 -- component for overlap).
10070 if Nkind
(Parent
(Clist
)) = N_Variant
then
10071 Clist
:= Parent
(Parent
(Parent
(Clist
)));
10073 -- Check for possible discriminant part in record, this
10074 -- is treated essentially as another level in the
10075 -- recursion. For this case the parent of the component
10076 -- list is the record definition, and its parent is the
10077 -- full type declaration containing the discriminant
10080 elsif Nkind
(Parent
(Clist
)) = N_Record_Definition
then
10081 Clist
:= Parent
(Parent
((Clist
)));
10083 -- If neither of these two cases, we are at the top of
10087 exit Component_List_Loop
;
10089 end loop Component_List_Loop
;
10091 <<Continue_Main_Component_Loop
>>
10092 Next_Entity
(C1_Ent
);
10094 end loop Main_Component_Loop
;
10095 end Overlap_Check2
;
10098 -- The following circuit deals with warning on record holes (gaps). We
10099 -- skip this check if overlap was detected, since it makes sense for the
10100 -- programmer to fix this illegality before worrying about warnings.
10102 if not Overlap_Detected
and Warn_On_Record_Holes
then
10103 Record_Hole_Check
: declare
10104 Decl
: constant Node_Id
:= Declaration_Node
(Base_Type
(Rectype
));
10105 -- Full declaration of record type
10107 procedure Check_Component_List
10111 -- Check component list CL for holes. The starting bit should be
10112 -- Sbit. which is zero for the main record component list and set
10113 -- appropriately for recursive calls for variants. DS is set to
10114 -- a list of discriminant specifications to be included in the
10115 -- consideration of components. It is No_List if none to consider.
10117 --------------------------
10118 -- Check_Component_List --
10119 --------------------------
10121 procedure Check_Component_List
10129 Compl
:= Integer (List_Length
(Component_Items
(CL
)));
10131 if DS
/= No_List
then
10132 Compl
:= Compl
+ Integer (List_Length
(DS
));
10136 Comps
: array (Natural range 0 .. Compl
) of Entity_Id
;
10137 -- Gather components (zero entry is for sort routine)
10139 Ncomps
: Natural := 0;
10140 -- Number of entries stored in Comps (starting at Comps (1))
10143 -- One component item or discriminant specification
10146 -- Starting bit for next component
10149 -- Component entity
10154 function Lt
(Op1
, Op2
: Natural) return Boolean;
10155 -- Compare routine for Sort
10157 procedure Move
(From
: Natural; To
: Natural);
10158 -- Move routine for Sort
10160 package Sorting
is new GNAT
.Heap_Sort_G
(Move
, Lt
);
10166 function Lt
(Op1
, Op2
: Natural) return Boolean is
10168 return Component_Bit_Offset
(Comps
(Op1
))
10170 Component_Bit_Offset
(Comps
(Op2
));
10177 procedure Move
(From
: Natural; To
: Natural) is
10179 Comps
(To
) := Comps
(From
);
10183 -- Gather discriminants into Comp
10185 if DS
/= No_List
then
10186 Citem
:= First
(DS
);
10187 while Present
(Citem
) loop
10188 if Nkind
(Citem
) = N_Discriminant_Specification
then
10190 Ent
: constant Entity_Id
:=
10191 Defining_Identifier
(Citem
);
10193 if Ekind
(Ent
) = E_Discriminant
then
10194 Ncomps
:= Ncomps
+ 1;
10195 Comps
(Ncomps
) := Ent
;
10204 -- Gather component entities into Comp
10206 Citem
:= First
(Component_Items
(CL
));
10207 while Present
(Citem
) loop
10208 if Nkind
(Citem
) = N_Component_Declaration
then
10209 Ncomps
:= Ncomps
+ 1;
10210 Comps
(Ncomps
) := Defining_Identifier
(Citem
);
10216 -- Now sort the component entities based on the first bit.
10217 -- Note we already know there are no overlapping components.
10219 Sorting
.Sort
(Ncomps
);
10221 -- Loop through entries checking for holes
10224 for J
in 1 .. Ncomps
loop
10226 Error_Msg_Uint_1
:= Component_Bit_Offset
(CEnt
) - Nbit
;
10228 if Error_Msg_Uint_1
> 0 then
10230 ("?H?^-bit gap before component&",
10231 Component_Name
(Component_Clause
(CEnt
)), CEnt
);
10234 Nbit
:= Component_Bit_Offset
(CEnt
) + Esize
(CEnt
);
10237 -- Process variant parts recursively if present
10239 if Present
(Variant_Part
(CL
)) then
10240 Variant
:= First
(Variants
(Variant_Part
(CL
)));
10241 while Present
(Variant
) loop
10242 Check_Component_List
10243 (Component_List
(Variant
), Nbit
, No_List
);
10248 end Check_Component_List
;
10250 -- Start of processing for Record_Hole_Check
10257 if Is_Tagged_Type
(Rectype
) then
10258 Sbit
:= UI_From_Int
(System_Address_Size
);
10263 if Nkind
(Decl
) = N_Full_Type_Declaration
10264 and then Nkind
(Type_Definition
(Decl
)) = N_Record_Definition
10266 Check_Component_List
10267 (Component_List
(Type_Definition
(Decl
)),
10269 Discriminant_Specifications
(Decl
));
10272 end Record_Hole_Check
;
10275 -- For records that have component clauses for all components, and whose
10276 -- size is less than or equal to 32, we need to know the size in the
10277 -- front end to activate possible packed array processing where the
10278 -- component type is a record.
10280 -- At this stage Hbit + 1 represents the first unused bit from all the
10281 -- component clauses processed, so if the component clauses are
10282 -- complete, then this is the length of the record.
10284 -- For records longer than System.Storage_Unit, and for those where not
10285 -- all components have component clauses, the back end determines the
10286 -- length (it may for example be appropriate to round up the size
10287 -- to some convenient boundary, based on alignment considerations, etc).
10289 if Unknown_RM_Size
(Rectype
) and then Hbit
+ 1 <= 32 then
10291 -- Nothing to do if at least one component has no component clause
10293 Comp
:= First_Component_Or_Discriminant
(Rectype
);
10294 while Present
(Comp
) loop
10295 exit when No
(Component_Clause
(Comp
));
10296 Next_Component_Or_Discriminant
(Comp
);
10299 -- If we fall out of loop, all components have component clauses
10300 -- and so we can set the size to the maximum value.
10303 Set_RM_Size
(Rectype
, Hbit
+ 1);
10306 end Check_Record_Representation_Clause
;
10312 procedure Check_Size
10316 Biased
: out Boolean)
10318 UT
: constant Entity_Id
:= Underlying_Type
(T
);
10324 -- Reject patently improper size values.
10326 if Is_Elementary_Type
(T
)
10327 and then Siz
> UI_From_Int
(Int
'Last)
10329 Error_Msg_N
("Size value too large for elementary type", N
);
10331 if Nkind
(Original_Node
(N
)) = N_Op_Expon
then
10333 ("\maybe '* was meant, rather than '*'*", Original_Node
(N
));
10337 -- Dismiss generic types
10339 if Is_Generic_Type
(T
)
10341 Is_Generic_Type
(UT
)
10343 Is_Generic_Type
(Root_Type
(UT
))
10347 -- Guard against previous errors
10349 elsif No
(UT
) or else UT
= Any_Type
then
10350 Check_Error_Detected
;
10353 -- Check case of bit packed array
10355 elsif Is_Array_Type
(UT
)
10356 and then Known_Static_Component_Size
(UT
)
10357 and then Is_Bit_Packed_Array
(UT
)
10365 Asiz
:= Component_Size
(UT
);
10366 Indx
:= First_Index
(UT
);
10368 Ityp
:= Etype
(Indx
);
10370 -- If non-static bound, then we are not in the business of
10371 -- trying to check the length, and indeed an error will be
10372 -- issued elsewhere, since sizes of non-static array types
10373 -- cannot be set implicitly or explicitly.
10375 if not Is_OK_Static_Subtype
(Ityp
) then
10379 -- Otherwise accumulate next dimension
10381 Asiz
:= Asiz
* (Expr_Value
(Type_High_Bound
(Ityp
)) -
10382 Expr_Value
(Type_Low_Bound
(Ityp
)) +
10386 exit when No
(Indx
);
10389 if Asiz
<= Siz
then
10393 Error_Msg_Uint_1
:= Asiz
;
10395 ("size for& too small, minimum allowed is ^", N
, T
);
10396 Set_Esize
(T
, Asiz
);
10397 Set_RM_Size
(T
, Asiz
);
10401 -- All other composite types are ignored
10403 elsif Is_Composite_Type
(UT
) then
10406 -- For fixed-point types, don't check minimum if type is not frozen,
10407 -- since we don't know all the characteristics of the type that can
10408 -- affect the size (e.g. a specified small) till freeze time.
10410 elsif Is_Fixed_Point_Type
(UT
)
10411 and then not Is_Frozen
(UT
)
10415 -- Cases for which a minimum check is required
10418 -- Ignore if specified size is correct for the type
10420 if Known_Esize
(UT
) and then Siz
= Esize
(UT
) then
10424 -- Otherwise get minimum size
10426 M
:= UI_From_Int
(Minimum_Size
(UT
));
10430 -- Size is less than minimum size, but one possibility remains
10431 -- that we can manage with the new size if we bias the type.
10433 M
:= UI_From_Int
(Minimum_Size
(UT
, Biased
=> True));
10436 Error_Msg_Uint_1
:= M
;
10438 ("size for& too small, minimum allowed is ^", N
, T
);
10440 Set_RM_Size
(T
, M
);
10448 --------------------------
10449 -- Freeze_Entity_Checks --
10450 --------------------------
10452 procedure Freeze_Entity_Checks
(N
: Node_Id
) is
10453 procedure Hide_Non_Overridden_Subprograms
(Typ
: Entity_Id
);
10454 -- Inspect the primitive operations of type Typ and hide all pairs of
10455 -- implicitly declared non-overridden non-fully conformant homographs
10456 -- (Ada RM 8.3 12.3/2).
10458 -------------------------------------
10459 -- Hide_Non_Overridden_Subprograms --
10460 -------------------------------------
10462 procedure Hide_Non_Overridden_Subprograms
(Typ
: Entity_Id
) is
10463 procedure Hide_Matching_Homographs
10464 (Subp_Id
: Entity_Id
;
10465 Start_Elmt
: Elmt_Id
);
10466 -- Inspect a list of primitive operations starting with Start_Elmt
10467 -- and find matching implicitly declared non-overridden non-fully
10468 -- conformant homographs of Subp_Id. If found, all matches along
10469 -- with Subp_Id are hidden from all visibility.
10471 function Is_Non_Overridden_Or_Null_Procedure
10472 (Subp_Id
: Entity_Id
) return Boolean;
10473 -- Determine whether subprogram Subp_Id is implicitly declared non-
10474 -- overridden subprogram or an implicitly declared null procedure.
10476 ------------------------------
10477 -- Hide_Matching_Homographs --
10478 ------------------------------
10480 procedure Hide_Matching_Homographs
10481 (Subp_Id
: Entity_Id
;
10482 Start_Elmt
: Elmt_Id
)
10485 Prim_Elmt
: Elmt_Id
;
10488 Prim_Elmt
:= Start_Elmt
;
10489 while Present
(Prim_Elmt
) loop
10490 Prim
:= Node
(Prim_Elmt
);
10492 -- The current primitive is implicitly declared non-overridden
10493 -- non-fully conformant homograph of Subp_Id. Both subprograms
10494 -- must be hidden from visibility.
10496 if Chars
(Prim
) = Chars
(Subp_Id
)
10497 and then Is_Non_Overridden_Or_Null_Procedure
(Prim
)
10498 and then not Fully_Conformant
(Prim
, Subp_Id
)
10500 Set_Is_Hidden_Non_Overridden_Subpgm
(Prim
);
10501 Set_Is_Immediately_Visible
(Prim
, False);
10502 Set_Is_Potentially_Use_Visible
(Prim
, False);
10504 Set_Is_Hidden_Non_Overridden_Subpgm
(Subp_Id
);
10505 Set_Is_Immediately_Visible
(Subp_Id
, False);
10506 Set_Is_Potentially_Use_Visible
(Subp_Id
, False);
10509 Next_Elmt
(Prim_Elmt
);
10511 end Hide_Matching_Homographs
;
10513 -----------------------------------------
10514 -- Is_Non_Overridden_Or_Null_Procedure --
10515 -----------------------------------------
10517 function Is_Non_Overridden_Or_Null_Procedure
10518 (Subp_Id
: Entity_Id
) return Boolean
10520 Alias_Id
: Entity_Id
;
10523 -- The subprogram is inherited (implicitly declared), it does not
10524 -- override and does not cover a primitive of an interface.
10526 if Ekind_In
(Subp_Id
, E_Function
, E_Procedure
)
10527 and then Present
(Alias
(Subp_Id
))
10528 and then No
(Interface_Alias
(Subp_Id
))
10529 and then No
(Overridden_Operation
(Subp_Id
))
10531 Alias_Id
:= Alias
(Subp_Id
);
10533 if Requires_Overriding
(Alias_Id
) then
10536 elsif Nkind
(Parent
(Alias_Id
)) = N_Procedure_Specification
10537 and then Null_Present
(Parent
(Alias_Id
))
10544 end Is_Non_Overridden_Or_Null_Procedure
;
10548 Prim_Ops
: constant Elist_Id
:= Direct_Primitive_Operations
(Typ
);
10550 Prim_Elmt
: Elmt_Id
;
10552 -- Start of processing for Hide_Non_Overridden_Subprograms
10555 -- Inspect the list of primitives looking for non-overridden
10558 if Present
(Prim_Ops
) then
10559 Prim_Elmt
:= First_Elmt
(Prim_Ops
);
10560 while Present
(Prim_Elmt
) loop
10561 Prim
:= Node
(Prim_Elmt
);
10562 Next_Elmt
(Prim_Elmt
);
10564 if Is_Non_Overridden_Or_Null_Procedure
(Prim
) then
10565 Hide_Matching_Homographs
10567 Start_Elmt
=> Prim_Elmt
);
10571 end Hide_Non_Overridden_Subprograms
;
10573 ---------------------
10574 -- Local variables --
10575 ---------------------
10577 E
: constant Entity_Id
:= Entity
(N
);
10579 Non_Generic_Case
: constant Boolean := Nkind
(N
) = N_Freeze_Entity
;
10580 -- True in non-generic case. Some of the processing here is skipped
10581 -- for the generic case since it is not needed. Basically in the
10582 -- generic case, we only need to do stuff that might generate error
10583 -- messages or warnings.
10585 -- Start of processing for Freeze_Entity_Checks
10588 -- Remember that we are processing a freezing entity. Required to
10589 -- ensure correct decoration of internal entities associated with
10590 -- interfaces (see New_Overloaded_Entity).
10592 Inside_Freezing_Actions
:= Inside_Freezing_Actions
+ 1;
10594 -- For tagged types covering interfaces add internal entities that link
10595 -- the primitives of the interfaces with the primitives that cover them.
10596 -- Note: These entities were originally generated only when generating
10597 -- code because their main purpose was to provide support to initialize
10598 -- the secondary dispatch tables. They are now generated also when
10599 -- compiling with no code generation to provide ASIS the relationship
10600 -- between interface primitives and tagged type primitives. They are
10601 -- also used to locate primitives covering interfaces when processing
10602 -- generics (see Derive_Subprograms).
10604 -- This is not needed in the generic case
10606 if Ada_Version
>= Ada_2005
10607 and then Non_Generic_Case
10608 and then Ekind
(E
) = E_Record_Type
10609 and then Is_Tagged_Type
(E
)
10610 and then not Is_Interface
(E
)
10611 and then Has_Interfaces
(E
)
10613 -- This would be a good common place to call the routine that checks
10614 -- overriding of interface primitives (and thus factorize calls to
10615 -- Check_Abstract_Overriding located at different contexts in the
10616 -- compiler). However, this is not possible because it causes
10617 -- spurious errors in case of late overriding.
10619 Add_Internal_Interface_Entities
(E
);
10622 -- After all forms of overriding have been resolved, a tagged type may
10623 -- be left with a set of implicitly declared and possibly erroneous
10624 -- abstract subprograms, null procedures and subprograms that require
10625 -- overriding. If this set contains fully conformat homographs, then one
10626 -- is chosen arbitrarily (already done during resolution), otherwise all
10627 -- remaining non-fully conformant homographs are hidden from visibility
10628 -- (Ada RM 8.3 12.3/2).
10630 if Is_Tagged_Type
(E
) then
10631 Hide_Non_Overridden_Subprograms
(E
);
10636 if Ekind
(E
) = E_Record_Type
10637 and then Is_CPP_Class
(E
)
10638 and then Is_Tagged_Type
(E
)
10639 and then Tagged_Type_Expansion
10641 if CPP_Num_Prims
(E
) = 0 then
10643 -- If the CPP type has user defined components then it must import
10644 -- primitives from C++. This is required because if the C++ class
10645 -- has no primitives then the C++ compiler does not added the _tag
10646 -- component to the type.
10648 if First_Entity
(E
) /= Last_Entity
(E
) then
10650 ("'C'P'P type must import at least one primitive from C++??",
10655 -- Check that all its primitives are abstract or imported from C++.
10656 -- Check also availability of the C++ constructor.
10659 Has_Constructors
: constant Boolean := Has_CPP_Constructors
(E
);
10661 Error_Reported
: Boolean := False;
10665 Elmt
:= First_Elmt
(Primitive_Operations
(E
));
10666 while Present
(Elmt
) loop
10667 Prim
:= Node
(Elmt
);
10669 if Comes_From_Source
(Prim
) then
10670 if Is_Abstract_Subprogram
(Prim
) then
10673 elsif not Is_Imported
(Prim
)
10674 or else Convention
(Prim
) /= Convention_CPP
10677 ("primitives of 'C'P'P types must be imported from C++ "
10678 & "or abstract??", Prim
);
10680 elsif not Has_Constructors
10681 and then not Error_Reported
10683 Error_Msg_Name_1
:= Chars
(E
);
10685 ("??'C'P'P constructor required for type %", Prim
);
10686 Error_Reported
:= True;
10695 -- Check Ada derivation of CPP type
10697 if Expander_Active
-- why? losing errors in -gnatc mode???
10698 and then Present
(Etype
(E
)) -- defend against errors
10699 and then Tagged_Type_Expansion
10700 and then Ekind
(E
) = E_Record_Type
10701 and then Etype
(E
) /= E
10702 and then Is_CPP_Class
(Etype
(E
))
10703 and then CPP_Num_Prims
(Etype
(E
)) > 0
10704 and then not Is_CPP_Class
(E
)
10705 and then not Has_CPP_Constructors
(Etype
(E
))
10707 -- If the parent has C++ primitives but it has no constructor then
10708 -- check that all the primitives are overridden in this derivation;
10709 -- otherwise the constructor of the parent is needed to build the
10717 Elmt
:= First_Elmt
(Primitive_Operations
(E
));
10718 while Present
(Elmt
) loop
10719 Prim
:= Node
(Elmt
);
10721 if not Is_Abstract_Subprogram
(Prim
)
10722 and then No
(Interface_Alias
(Prim
))
10723 and then Find_Dispatching_Type
(Ultimate_Alias
(Prim
)) /= E
10725 Error_Msg_Name_1
:= Chars
(Etype
(E
));
10727 ("'C'P'P constructor required for parent type %", E
);
10736 Inside_Freezing_Actions
:= Inside_Freezing_Actions
- 1;
10738 -- If we have a type with predicates, build predicate function. This
10739 -- is not needed in the generic case, and is not needed within TSS
10740 -- subprograms and other predefined primitives.
10742 if Non_Generic_Case
10743 and then Is_Type
(E
)
10744 and then Has_Predicates
(E
)
10745 and then not Within_Internal_Subprogram
10747 Build_Predicate_Functions
(E
, N
);
10750 -- If type has delayed aspects, this is where we do the preanalysis at
10751 -- the freeze point, as part of the consistent visibility check. Note
10752 -- that this must be done after calling Build_Predicate_Functions or
10753 -- Build_Invariant_Procedure since these subprograms fix occurrences of
10754 -- the subtype name in the saved expression so that they will not cause
10755 -- trouble in the preanalysis.
10757 -- This is also not needed in the generic case
10759 if Non_Generic_Case
10760 and then Has_Delayed_Aspects
(E
)
10761 and then Scope
(E
) = Current_Scope
10763 -- Retrieve the visibility to the discriminants in order to properly
10764 -- analyze the aspects.
10766 Push_Scope_And_Install_Discriminants
(E
);
10772 -- Look for aspect specification entries for this entity
10774 Ritem
:= First_Rep_Item
(E
);
10775 while Present
(Ritem
) loop
10776 if Nkind
(Ritem
) = N_Aspect_Specification
10777 and then Entity
(Ritem
) = E
10778 and then Is_Delayed_Aspect
(Ritem
)
10780 Check_Aspect_At_Freeze_Point
(Ritem
);
10783 Next_Rep_Item
(Ritem
);
10787 Uninstall_Discriminants_And_Pop_Scope
(E
);
10790 -- For a record type, deal with variant parts. This has to be delayed
10791 -- to this point, because of the issue of statically predicated
10792 -- subtypes, which we have to ensure are frozen before checking
10793 -- choices, since we need to have the static choice list set.
10795 if Is_Record_Type
(E
) then
10796 Check_Variant_Part
: declare
10797 D
: constant Node_Id
:= Declaration_Node
(E
);
10802 Others_Present
: Boolean;
10803 pragma Warnings
(Off
, Others_Present
);
10804 -- Indicates others present, not used in this case
10806 procedure Non_Static_Choice_Error
(Choice
: Node_Id
);
10807 -- Error routine invoked by the generic instantiation below when
10808 -- the variant part has a non static choice.
10810 procedure Process_Declarations
(Variant
: Node_Id
);
10811 -- Processes declarations associated with a variant. We analyzed
10812 -- the declarations earlier (in Sem_Ch3.Analyze_Variant_Part),
10813 -- but we still need the recursive call to Check_Choices for any
10814 -- nested variant to get its choices properly processed. This is
10815 -- also where we expand out the choices if expansion is active.
10817 package Variant_Choices_Processing
is new
10818 Generic_Check_Choices
10819 (Process_Empty_Choice
=> No_OP
,
10820 Process_Non_Static_Choice
=> Non_Static_Choice_Error
,
10821 Process_Associated_Node
=> Process_Declarations
);
10822 use Variant_Choices_Processing
;
10824 -----------------------------
10825 -- Non_Static_Choice_Error --
10826 -----------------------------
10828 procedure Non_Static_Choice_Error
(Choice
: Node_Id
) is
10830 Flag_Non_Static_Expr
10831 ("choice given in variant part is not static!", Choice
);
10832 end Non_Static_Choice_Error
;
10834 --------------------------
10835 -- Process_Declarations --
10836 --------------------------
10838 procedure Process_Declarations
(Variant
: Node_Id
) is
10839 CL
: constant Node_Id
:= Component_List
(Variant
);
10843 -- Check for static predicate present in this variant
10845 if Has_SP_Choice
(Variant
) then
10847 -- Here we expand. You might expect to find this call in
10848 -- Expand_N_Variant_Part, but that is called when we first
10849 -- see the variant part, and we cannot do this expansion
10850 -- earlier than the freeze point, since for statically
10851 -- predicated subtypes, the predicate is not known till
10852 -- the freeze point.
10854 -- Furthermore, we do this expansion even if the expander
10855 -- is not active, because other semantic processing, e.g.
10856 -- for aggregates, requires the expanded list of choices.
10858 -- If the expander is not active, then we can't just clobber
10859 -- the list since it would invalidate the ASIS -gnatct tree.
10860 -- So we have to rewrite the variant part with a Rewrite
10861 -- call that replaces it with a copy and clobber the copy.
10863 if not Expander_Active
then
10865 NewV
: constant Node_Id
:= New_Copy
(Variant
);
10867 Set_Discrete_Choices
10868 (NewV
, New_Copy_List
(Discrete_Choices
(Variant
)));
10869 Rewrite
(Variant
, NewV
);
10873 Expand_Static_Predicates_In_Choices
(Variant
);
10876 -- We don't need to worry about the declarations in the variant
10877 -- (since they were analyzed by Analyze_Choices when we first
10878 -- encountered the variant), but we do need to take care of
10879 -- expansion of any nested variants.
10881 if not Null_Present
(CL
) then
10882 VP
:= Variant_Part
(CL
);
10884 if Present
(VP
) then
10886 (VP
, Variants
(VP
), Etype
(Name
(VP
)), Others_Present
);
10889 end Process_Declarations
;
10891 -- Start of processing for Check_Variant_Part
10894 -- Find component list
10898 if Nkind
(D
) = N_Full_Type_Declaration
then
10899 T
:= Type_Definition
(D
);
10901 if Nkind
(T
) = N_Record_Definition
then
10902 C
:= Component_List
(T
);
10904 elsif Nkind
(T
) = N_Derived_Type_Definition
10905 and then Present
(Record_Extension_Part
(T
))
10907 C
:= Component_List
(Record_Extension_Part
(T
));
10911 -- Case of variant part present
10913 if Present
(C
) and then Present
(Variant_Part
(C
)) then
10914 VP
:= Variant_Part
(C
);
10919 (VP
, Variants
(VP
), Etype
(Name
(VP
)), Others_Present
);
10921 -- If the last variant does not contain the Others choice,
10922 -- replace it with an N_Others_Choice node since Gigi always
10923 -- wants an Others. Note that we do not bother to call Analyze
10924 -- on the modified variant part, since its only effect would be
10925 -- to compute the Others_Discrete_Choices node laboriously, and
10926 -- of course we already know the list of choices corresponding
10927 -- to the others choice (it's the list we're replacing).
10929 -- We only want to do this if the expander is active, since
10930 -- we do not want to clobber the ASIS tree.
10932 if Expander_Active
then
10934 Last_Var
: constant Node_Id
:=
10935 Last_Non_Pragma
(Variants
(VP
));
10937 Others_Node
: Node_Id
;
10940 if Nkind
(First
(Discrete_Choices
(Last_Var
))) /=
10943 Others_Node
:= Make_Others_Choice
(Sloc
(Last_Var
));
10944 Set_Others_Discrete_Choices
10945 (Others_Node
, Discrete_Choices
(Last_Var
));
10946 Set_Discrete_Choices
10947 (Last_Var
, New_List
(Others_Node
));
10952 end Check_Variant_Part
;
10954 end Freeze_Entity_Checks
;
10956 -------------------------
10957 -- Get_Alignment_Value --
10958 -------------------------
10960 function Get_Alignment_Value
(Expr
: Node_Id
) return Uint
is
10961 Align
: constant Uint
:= Static_Integer
(Expr
);
10964 if Align
= No_Uint
then
10967 elsif Align
<= 0 then
10968 Error_Msg_N
("alignment value must be positive", Expr
);
10972 for J
in Int
range 0 .. 64 loop
10974 M
: constant Uint
:= Uint_2
** J
;
10977 exit when M
= Align
;
10981 ("alignment value must be power of 2", Expr
);
10989 end Get_Alignment_Value
;
10991 -------------------------------------
10992 -- Inherit_Aspects_At_Freeze_Point --
10993 -------------------------------------
10995 procedure Inherit_Aspects_At_Freeze_Point
(Typ
: Entity_Id
) is
10996 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
10997 (Rep_Item
: Node_Id
) return Boolean;
10998 -- This routine checks if Rep_Item is either a pragma or an aspect
10999 -- specification node whose correponding pragma (if any) is present in
11000 -- the Rep Item chain of the entity it has been specified to.
11002 --------------------------------------------------
11003 -- Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item --
11004 --------------------------------------------------
11006 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11007 (Rep_Item
: Node_Id
) return Boolean
11011 Nkind
(Rep_Item
) = N_Pragma
11012 or else Present_In_Rep_Item
11013 (Entity
(Rep_Item
), Aspect_Rep_Item
(Rep_Item
));
11014 end Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
;
11016 -- Start of processing for Inherit_Aspects_At_Freeze_Point
11019 -- A representation item is either subtype-specific (Size and Alignment
11020 -- clauses) or type-related (all others). Subtype-specific aspects may
11021 -- differ for different subtypes of the same type (RM 13.1.8).
11023 -- A derived type inherits each type-related representation aspect of
11024 -- its parent type that was directly specified before the declaration of
11025 -- the derived type (RM 13.1.15).
11027 -- A derived subtype inherits each subtype-specific representation
11028 -- aspect of its parent subtype that was directly specified before the
11029 -- declaration of the derived type (RM 13.1.15).
11031 -- The general processing involves inheriting a representation aspect
11032 -- from a parent type whenever the first rep item (aspect specification,
11033 -- attribute definition clause, pragma) corresponding to the given
11034 -- representation aspect in the rep item chain of Typ, if any, isn't
11035 -- directly specified to Typ but to one of its parents.
11037 -- ??? Note that, for now, just a limited number of representation
11038 -- aspects have been inherited here so far. Many of them are
11039 -- still inherited in Sem_Ch3. This will be fixed soon. Here is
11040 -- a non- exhaustive list of aspects that likely also need to
11041 -- be moved to this routine: Alignment, Component_Alignment,
11042 -- Component_Size, Machine_Radix, Object_Size, Pack, Predicates,
11043 -- Preelaborable_Initialization, RM_Size and Small.
11045 -- In addition, Convention must be propagated from base type to subtype,
11046 -- because the subtype may have been declared on an incomplete view.
11048 if Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
then
11054 if not Has_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
, False)
11055 and then Has_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
)
11056 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11057 (Get_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
))
11059 Set_Is_Ada_2005_Only
(Typ
);
11064 if not Has_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
, False)
11065 and then Has_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
)
11066 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11067 (Get_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
))
11069 Set_Is_Ada_2012_Only
(Typ
);
11074 if not Has_Rep_Item
(Typ
, Name_Atomic
, Name_Shared
, False)
11075 and then Has_Rep_Pragma
(Typ
, Name_Atomic
, Name_Shared
)
11076 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11077 (Get_Rep_Item
(Typ
, Name_Atomic
, Name_Shared
))
11079 Set_Is_Atomic
(Typ
);
11080 Set_Treat_As_Volatile
(Typ
);
11081 Set_Is_Volatile
(Typ
);
11086 if Is_Record_Type
(Typ
)
11087 and then Typ
/= Base_Type
(Typ
) and then Is_Frozen
(Base_Type
(Typ
))
11089 Set_Convention
(Typ
, Convention
(Base_Type
(Typ
)));
11092 -- Default_Component_Value
11094 -- Verify that there is no rep_item declared for the type, and there
11095 -- is one coming from an ancestor.
11097 if Is_Array_Type
(Typ
)
11098 and then Is_Base_Type
(Typ
)
11099 and then not Has_Rep_Item
(Typ
, Name_Default_Component_Value
, False)
11100 and then Has_Rep_Item
(Typ
, Name_Default_Component_Value
)
11102 Set_Default_Aspect_Component_Value
(Typ
,
11103 Default_Aspect_Component_Value
11104 (Entity
(Get_Rep_Item
(Typ
, Name_Default_Component_Value
))));
11109 if Is_Scalar_Type
(Typ
)
11110 and then Is_Base_Type
(Typ
)
11111 and then not Has_Rep_Item
(Typ
, Name_Default_Value
, False)
11112 and then Has_Rep_Item
(Typ
, Name_Default_Value
)
11114 Set_Has_Default_Aspect
(Typ
);
11115 Set_Default_Aspect_Value
(Typ
,
11116 Default_Aspect_Value
11117 (Entity
(Get_Rep_Item
(Typ
, Name_Default_Value
))));
11122 if not Has_Rep_Item
(Typ
, Name_Discard_Names
, False)
11123 and then Has_Rep_Item
(Typ
, Name_Discard_Names
)
11124 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11125 (Get_Rep_Item
(Typ
, Name_Discard_Names
))
11127 Set_Discard_Names
(Typ
);
11132 if not Has_Rep_Item
(Typ
, Name_Invariant
, False)
11133 and then Has_Rep_Item
(Typ
, Name_Invariant
)
11134 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11135 (Get_Rep_Item
(Typ
, Name_Invariant
))
11137 Set_Has_Invariants
(Typ
);
11139 if Class_Present
(Get_Rep_Item
(Typ
, Name_Invariant
)) then
11140 Set_Has_Inheritable_Invariants
(Typ
);
11143 -- If we have a subtype with invariants, whose base type does not have
11144 -- invariants, copy these invariants to the base type. This happens for
11145 -- the case of implicit base types created for scalar and array types.
11147 elsif Has_Invariants
(Typ
)
11148 and then not Has_Invariants
(Base_Type
(Typ
))
11150 Set_Has_Invariants
(Base_Type
(Typ
));
11151 Set_Invariant_Procedure
(Base_Type
(Typ
), Invariant_Procedure
(Typ
));
11156 if not Has_Rep_Item
(Typ
, Name_Volatile
, False)
11157 and then Has_Rep_Item
(Typ
, Name_Volatile
)
11158 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11159 (Get_Rep_Item
(Typ
, Name_Volatile
))
11161 Set_Treat_As_Volatile
(Typ
);
11162 Set_Is_Volatile
(Typ
);
11165 -- Inheritance for derived types only
11167 if Is_Derived_Type
(Typ
) then
11169 Bas_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
11170 Imp_Bas_Typ
: constant Entity_Id
:= Implementation_Base_Type
(Typ
);
11173 -- Atomic_Components
11175 if not Has_Rep_Item
(Typ
, Name_Atomic_Components
, False)
11176 and then Has_Rep_Item
(Typ
, Name_Atomic_Components
)
11177 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11178 (Get_Rep_Item
(Typ
, Name_Atomic_Components
))
11180 Set_Has_Atomic_Components
(Imp_Bas_Typ
);
11183 -- Volatile_Components
11185 if not Has_Rep_Item
(Typ
, Name_Volatile_Components
, False)
11186 and then Has_Rep_Item
(Typ
, Name_Volatile_Components
)
11187 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11188 (Get_Rep_Item
(Typ
, Name_Volatile_Components
))
11190 Set_Has_Volatile_Components
(Imp_Bas_Typ
);
11193 -- Finalize_Storage_Only
11195 if not Has_Rep_Pragma
(Typ
, Name_Finalize_Storage_Only
, False)
11196 and then Has_Rep_Pragma
(Typ
, Name_Finalize_Storage_Only
)
11198 Set_Finalize_Storage_Only
(Bas_Typ
);
11201 -- Universal_Aliasing
11203 if not Has_Rep_Item
(Typ
, Name_Universal_Aliasing
, False)
11204 and then Has_Rep_Item
(Typ
, Name_Universal_Aliasing
)
11205 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11206 (Get_Rep_Item
(Typ
, Name_Universal_Aliasing
))
11208 Set_Universal_Aliasing
(Imp_Bas_Typ
);
11213 if Is_Record_Type
(Typ
) then
11214 if not Has_Rep_Item
(Typ
, Name_Bit_Order
, False)
11215 and then Has_Rep_Item
(Typ
, Name_Bit_Order
)
11217 Set_Reverse_Bit_Order
(Bas_Typ
,
11218 Reverse_Bit_Order
(Entity
(Name
11219 (Get_Rep_Item
(Typ
, Name_Bit_Order
)))));
11223 -- Scalar_Storage_Order
11225 -- Note: the aspect is specified on a first subtype, but recorded
11226 -- in a flag of the base type!
11228 if (Is_Record_Type
(Typ
) or else Is_Array_Type
(Typ
))
11229 and then Typ
= Bas_Typ
11231 -- For a type extension, always inherit from parent; otherwise
11232 -- inherit if no default applies. Note: we do not check for
11233 -- an explicit rep item on the parent type when inheriting,
11234 -- because the parent SSO may itself have been set by default.
11236 if not Has_Rep_Item
(First_Subtype
(Typ
),
11237 Name_Scalar_Storage_Order
, False)
11238 and then (Is_Tagged_Type
(Bas_Typ
)
11239 or else not (SSO_Set_Low_By_Default
(Bas_Typ
)
11241 SSO_Set_High_By_Default
(Bas_Typ
)))
11243 Set_Reverse_Storage_Order
(Bas_Typ
,
11244 Reverse_Storage_Order
11245 (Implementation_Base_Type
(Etype
(Bas_Typ
))));
11247 -- Clear default SSO indications, since the inherited aspect
11248 -- which was set explicitly overrides the default.
11250 Set_SSO_Set_Low_By_Default
(Bas_Typ
, False);
11251 Set_SSO_Set_High_By_Default
(Bas_Typ
, False);
11256 end Inherit_Aspects_At_Freeze_Point
;
11262 procedure Initialize
is
11264 Address_Clause_Checks
.Init
;
11265 Unchecked_Conversions
.Init
;
11267 if VM_Target
/= No_VM
or else AAMP_On_Target
then
11268 Independence_Checks
.Init
;
11272 ---------------------------
11273 -- Install_Discriminants --
11274 ---------------------------
11276 procedure Install_Discriminants
(E
: Entity_Id
) is
11280 Disc
:= First_Discriminant
(E
);
11281 while Present
(Disc
) loop
11282 Prev
:= Current_Entity
(Disc
);
11283 Set_Current_Entity
(Disc
);
11284 Set_Is_Immediately_Visible
(Disc
);
11285 Set_Homonym
(Disc
, Prev
);
11286 Next_Discriminant
(Disc
);
11288 end Install_Discriminants
;
11290 -------------------------
11291 -- Is_Operational_Item --
11292 -------------------------
11294 function Is_Operational_Item
(N
: Node_Id
) return Boolean is
11296 if Nkind
(N
) /= N_Attribute_Definition_Clause
then
11301 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Chars
(N
));
11303 return Id
= Attribute_Input
11304 or else Id
= Attribute_Output
11305 or else Id
= Attribute_Read
11306 or else Id
= Attribute_Write
11307 or else Id
= Attribute_External_Tag
;
11310 end Is_Operational_Item
;
11312 -------------------------
11313 -- Is_Predicate_Static --
11314 -------------------------
11316 -- Note: the basic legality of the expression has already been checked, so
11317 -- we don't need to worry about cases or ranges on strings for example.
11319 function Is_Predicate_Static
11321 Nam
: Name_Id
) return Boolean
11323 function All_Static_Case_Alternatives
(L
: List_Id
) return Boolean;
11324 -- Given a list of case expression alternatives, returns True if all
11325 -- the alternatives are static (have all static choices, and a static
11328 function All_Static_Choices
(L
: List_Id
) return Boolean;
11329 -- Returns true if all elements of the list are OK static choices
11330 -- as defined below for Is_Static_Choice. Used for case expression
11331 -- alternatives and for the right operand of a membership test. An
11332 -- others_choice is static if the corresponding expression is static.
11333 -- The staticness of the bounds is checked separately.
11335 function Is_Static_Choice
(N
: Node_Id
) return Boolean;
11336 -- Returns True if N represents a static choice (static subtype, or
11337 -- static subtype indication, or static expression, or static range).
11339 -- Note that this is a bit more inclusive than we actually need
11340 -- (in particular membership tests do not allow the use of subtype
11341 -- indications). But that doesn't matter, we have already checked
11342 -- that the construct is legal to get this far.
11344 function Is_Type_Ref
(N
: Node_Id
) return Boolean;
11345 pragma Inline
(Is_Type_Ref
);
11346 -- Returns True if N is a reference to the type for the predicate in the
11347 -- expression (i.e. if it is an identifier whose Chars field matches the
11348 -- Nam given in the call). N must not be parenthesized, if the type name
11349 -- appears in parens, this routine will return False.
11351 ----------------------------------
11352 -- All_Static_Case_Alternatives --
11353 ----------------------------------
11355 function All_Static_Case_Alternatives
(L
: List_Id
) return Boolean is
11360 while Present
(N
) loop
11361 if not (All_Static_Choices
(Discrete_Choices
(N
))
11362 and then Is_OK_Static_Expression
(Expression
(N
)))
11371 end All_Static_Case_Alternatives
;
11373 ------------------------
11374 -- All_Static_Choices --
11375 ------------------------
11377 function All_Static_Choices
(L
: List_Id
) return Boolean is
11382 while Present
(N
) loop
11383 if not Is_Static_Choice
(N
) then
11391 end All_Static_Choices
;
11393 ----------------------
11394 -- Is_Static_Choice --
11395 ----------------------
11397 function Is_Static_Choice
(N
: Node_Id
) return Boolean is
11399 return Nkind
(N
) = N_Others_Choice
11400 or else Is_OK_Static_Expression
(N
)
11401 or else (Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
))
11402 and then Is_OK_Static_Subtype
(Entity
(N
)))
11403 or else (Nkind
(N
) = N_Subtype_Indication
11404 and then Is_OK_Static_Subtype
(Entity
(N
)))
11405 or else (Nkind
(N
) = N_Range
and then Is_OK_Static_Range
(N
));
11406 end Is_Static_Choice
;
11412 function Is_Type_Ref
(N
: Node_Id
) return Boolean is
11414 return Nkind
(N
) = N_Identifier
11415 and then Chars
(N
) = Nam
11416 and then Paren_Count
(N
) = 0;
11419 -- Start of processing for Is_Predicate_Static
11422 -- Predicate_Static means one of the following holds. Numbers are the
11423 -- corresponding paragraph numbers in (RM 3.2.4(16-22)).
11425 -- 16: A static expression
11427 if Is_OK_Static_Expression
(Expr
) then
11430 -- 17: A membership test whose simple_expression is the current
11431 -- instance, and whose membership_choice_list meets the requirements
11432 -- for a static membership test.
11434 elsif Nkind
(Expr
) in N_Membership_Test
11435 and then ((Present
(Right_Opnd
(Expr
))
11436 and then Is_Static_Choice
(Right_Opnd
(Expr
)))
11438 (Present
(Alternatives
(Expr
))
11439 and then All_Static_Choices
(Alternatives
(Expr
))))
11443 -- 18. A case_expression whose selecting_expression is the current
11444 -- instance, and whose dependent expressions are static expressions.
11446 elsif Nkind
(Expr
) = N_Case_Expression
11447 and then Is_Type_Ref
(Expression
(Expr
))
11448 and then All_Static_Case_Alternatives
(Alternatives
(Expr
))
11452 -- 19. A call to a predefined equality or ordering operator, where one
11453 -- operand is the current instance, and the other is a static
11456 -- Note: the RM is clearly wrong here in not excluding string types.
11457 -- Without this exclusion, we would allow expressions like X > "ABC"
11458 -- to be considered as predicate-static, which is clearly not intended,
11459 -- since the idea is for predicate-static to be a subset of normal
11460 -- static expressions (and "DEF" > "ABC" is not a static expression).
11462 -- However, we do allow internally generated (not from source) equality
11463 -- and inequality operations to be valid on strings (this helps deal
11464 -- with cases where we transform A in "ABC" to A = "ABC).
11466 elsif Nkind
(Expr
) in N_Op_Compare
11467 and then ((not Is_String_Type
(Etype
(Left_Opnd
(Expr
))))
11468 or else (Nkind_In
(Expr
, N_Op_Eq
, N_Op_Ne
)
11469 and then not Comes_From_Source
(Expr
)))
11470 and then ((Is_Type_Ref
(Left_Opnd
(Expr
))
11471 and then Is_OK_Static_Expression
(Right_Opnd
(Expr
)))
11473 (Is_Type_Ref
(Right_Opnd
(Expr
))
11474 and then Is_OK_Static_Expression
(Left_Opnd
(Expr
))))
11478 -- 20. A call to a predefined boolean logical operator, where each
11479 -- operand is predicate-static.
11481 elsif (Nkind_In
(Expr
, N_Op_And
, N_Op_Or
, N_Op_Xor
)
11482 and then Is_Predicate_Static
(Left_Opnd
(Expr
), Nam
)
11483 and then Is_Predicate_Static
(Right_Opnd
(Expr
), Nam
))
11485 (Nkind
(Expr
) = N_Op_Not
11486 and then Is_Predicate_Static
(Right_Opnd
(Expr
), Nam
))
11490 -- 21. A short-circuit control form where both operands are
11491 -- predicate-static.
11493 elsif Nkind
(Expr
) in N_Short_Circuit
11494 and then Is_Predicate_Static
(Left_Opnd
(Expr
), Nam
)
11495 and then Is_Predicate_Static
(Right_Opnd
(Expr
), Nam
)
11499 -- 22. A parenthesized predicate-static expression. This does not
11500 -- require any special test, since we just ignore paren levels in
11501 -- all the cases above.
11503 -- One more test that is an implementation artifact caused by the fact
11504 -- that we are analyzing not the original expression, but the generated
11505 -- expression in the body of the predicate function. This can include
11506 -- references to inherited predicates, so that the expression we are
11507 -- processing looks like:
11509 -- expression and then xxPredicate (typ (Inns))
11511 -- Where the call is to a Predicate function for an inherited predicate.
11512 -- We simply ignore such a call, which could be to either a dynamic or
11513 -- a static predicate. Note that if the parent predicate is dynamic then
11514 -- eventually this type will be marked as dynamic, but you are allowed
11515 -- to specify a static predicate for a subtype which is inheriting a
11516 -- dynamic predicate, so the static predicate validation here ignores
11517 -- the inherited predicate even if it is dynamic.
11519 elsif Nkind
(Expr
) = N_Function_Call
11520 and then Is_Predicate_Function
(Entity
(Name
(Expr
)))
11524 -- That's an exhaustive list of tests, all other cases are not
11525 -- predicate-static, so we return False.
11530 end Is_Predicate_Static
;
11532 ---------------------
11533 -- Kill_Rep_Clause --
11534 ---------------------
11536 procedure Kill_Rep_Clause
(N
: Node_Id
) is
11538 pragma Assert
(Ignore_Rep_Clauses
);
11540 -- Note: we use Replace rather than Rewrite, because we don't want
11541 -- ASIS to be able to use Original_Node to dig out the (undecorated)
11542 -- rep clause that is being replaced.
11544 Replace
(N
, Make_Null_Statement
(Sloc
(N
)));
11546 -- The null statement must be marked as not coming from source. This is
11547 -- so that ASIS ignores it, and also the back end does not expect bogus
11548 -- "from source" null statements in weird places (e.g. in declarative
11549 -- regions where such null statements are not allowed).
11551 Set_Comes_From_Source
(N
, False);
11552 end Kill_Rep_Clause
;
11558 function Minimum_Size
11560 Biased
: Boolean := False) return Nat
11562 Lo
: Uint
:= No_Uint
;
11563 Hi
: Uint
:= No_Uint
;
11564 LoR
: Ureal
:= No_Ureal
;
11565 HiR
: Ureal
:= No_Ureal
;
11566 LoSet
: Boolean := False;
11567 HiSet
: Boolean := False;
11570 Ancest
: Entity_Id
;
11571 R_Typ
: constant Entity_Id
:= Root_Type
(T
);
11574 -- If bad type, return 0
11576 if T
= Any_Type
then
11579 -- For generic types, just return zero. There cannot be any legitimate
11580 -- need to know such a size, but this routine may be called with a
11581 -- generic type as part of normal processing.
11583 elsif Is_Generic_Type
(R_Typ
) or else R_Typ
= Any_Type
then
11586 -- Access types (cannot have size smaller than System.Address)
11588 elsif Is_Access_Type
(T
) then
11589 return System_Address_Size
;
11591 -- Floating-point types
11593 elsif Is_Floating_Point_Type
(T
) then
11594 return UI_To_Int
(Esize
(R_Typ
));
11598 elsif Is_Discrete_Type
(T
) then
11600 -- The following loop is looking for the nearest compile time known
11601 -- bounds following the ancestor subtype chain. The idea is to find
11602 -- the most restrictive known bounds information.
11606 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
11611 if Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
)) then
11612 Lo
:= Expr_Rep_Value
(Type_Low_Bound
(Ancest
));
11619 if Compile_Time_Known_Value
(Type_High_Bound
(Ancest
)) then
11620 Hi
:= Expr_Rep_Value
(Type_High_Bound
(Ancest
));
11626 Ancest
:= Ancestor_Subtype
(Ancest
);
11628 if No
(Ancest
) then
11629 Ancest
:= Base_Type
(T
);
11631 if Is_Generic_Type
(Ancest
) then
11637 -- Fixed-point types. We can't simply use Expr_Value to get the
11638 -- Corresponding_Integer_Value values of the bounds, since these do not
11639 -- get set till the type is frozen, and this routine can be called
11640 -- before the type is frozen. Similarly the test for bounds being static
11641 -- needs to include the case where we have unanalyzed real literals for
11642 -- the same reason.
11644 elsif Is_Fixed_Point_Type
(T
) then
11646 -- The following loop is looking for the nearest compile time known
11647 -- bounds following the ancestor subtype chain. The idea is to find
11648 -- the most restrictive known bounds information.
11652 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
11656 -- Note: In the following two tests for LoSet and HiSet, it may
11657 -- seem redundant to test for N_Real_Literal here since normally
11658 -- one would assume that the test for the value being known at
11659 -- compile time includes this case. However, there is a glitch.
11660 -- If the real literal comes from folding a non-static expression,
11661 -- then we don't consider any non- static expression to be known
11662 -- at compile time if we are in configurable run time mode (needed
11663 -- in some cases to give a clearer definition of what is and what
11664 -- is not accepted). So the test is indeed needed. Without it, we
11665 -- would set neither Lo_Set nor Hi_Set and get an infinite loop.
11668 if Nkind
(Type_Low_Bound
(Ancest
)) = N_Real_Literal
11669 or else Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
))
11671 LoR
:= Expr_Value_R
(Type_Low_Bound
(Ancest
));
11678 if Nkind
(Type_High_Bound
(Ancest
)) = N_Real_Literal
11679 or else Compile_Time_Known_Value
(Type_High_Bound
(Ancest
))
11681 HiR
:= Expr_Value_R
(Type_High_Bound
(Ancest
));
11687 Ancest
:= Ancestor_Subtype
(Ancest
);
11689 if No
(Ancest
) then
11690 Ancest
:= Base_Type
(T
);
11692 if Is_Generic_Type
(Ancest
) then
11698 Lo
:= UR_To_Uint
(LoR
/ Small_Value
(T
));
11699 Hi
:= UR_To_Uint
(HiR
/ Small_Value
(T
));
11701 -- No other types allowed
11704 raise Program_Error
;
11707 -- Fall through with Hi and Lo set. Deal with biased case
11710 and then not Is_Fixed_Point_Type
(T
)
11711 and then not (Is_Enumeration_Type
(T
)
11712 and then Has_Non_Standard_Rep
(T
)))
11713 or else Has_Biased_Representation
(T
)
11719 -- Signed case. Note that we consider types like range 1 .. -1 to be
11720 -- signed for the purpose of computing the size, since the bounds have
11721 -- to be accommodated in the base type.
11723 if Lo
< 0 or else Hi
< 0 then
11727 -- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1))
11728 -- Note that we accommodate the case where the bounds cross. This
11729 -- can happen either because of the way the bounds are declared
11730 -- or because of the algorithm in Freeze_Fixed_Point_Type.
11744 -- If both bounds are positive, make sure that both are represen-
11745 -- table in the case where the bounds are crossed. This can happen
11746 -- either because of the way the bounds are declared, or because of
11747 -- the algorithm in Freeze_Fixed_Point_Type.
11753 -- S = size, (can accommodate 0 .. (2**size - 1))
11756 while Hi
>= Uint_2
** S
loop
11764 ---------------------------
11765 -- New_Stream_Subprogram --
11766 ---------------------------
11768 procedure New_Stream_Subprogram
11772 Nam
: TSS_Name_Type
)
11774 Loc
: constant Source_Ptr
:= Sloc
(N
);
11775 Sname
: constant Name_Id
:= Make_TSS_Name
(Base_Type
(Ent
), Nam
);
11776 Subp_Id
: Entity_Id
;
11777 Subp_Decl
: Node_Id
;
11781 Defer_Declaration
: constant Boolean :=
11782 Is_Tagged_Type
(Ent
) or else Is_Private_Type
(Ent
);
11783 -- For a tagged type, there is a declaration for each stream attribute
11784 -- at the freeze point, and we must generate only a completion of this
11785 -- declaration. We do the same for private types, because the full view
11786 -- might be tagged. Otherwise we generate a declaration at the point of
11787 -- the attribute definition clause.
11789 function Build_Spec
return Node_Id
;
11790 -- Used for declaration and renaming declaration, so that this is
11791 -- treated as a renaming_as_body.
11797 function Build_Spec
return Node_Id
is
11798 Out_P
: constant Boolean := (Nam
= TSS_Stream_Read
);
11801 T_Ref
: constant Node_Id
:= New_Occurrence_Of
(Etyp
, Loc
);
11804 Subp_Id
:= Make_Defining_Identifier
(Loc
, Sname
);
11806 -- S : access Root_Stream_Type'Class
11808 Formals
:= New_List
(
11809 Make_Parameter_Specification
(Loc
,
11810 Defining_Identifier
=>
11811 Make_Defining_Identifier
(Loc
, Name_S
),
11813 Make_Access_Definition
(Loc
,
11815 New_Occurrence_Of
(
11816 Designated_Type
(Etype
(F
)), Loc
))));
11818 if Nam
= TSS_Stream_Input
then
11820 Make_Function_Specification
(Loc
,
11821 Defining_Unit_Name
=> Subp_Id
,
11822 Parameter_Specifications
=> Formals
,
11823 Result_Definition
=> T_Ref
);
11827 Append_To
(Formals
,
11828 Make_Parameter_Specification
(Loc
,
11829 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_V
),
11830 Out_Present
=> Out_P
,
11831 Parameter_Type
=> T_Ref
));
11834 Make_Procedure_Specification
(Loc
,
11835 Defining_Unit_Name
=> Subp_Id
,
11836 Parameter_Specifications
=> Formals
);
11842 -- Start of processing for New_Stream_Subprogram
11845 F
:= First_Formal
(Subp
);
11847 if Ekind
(Subp
) = E_Procedure
then
11848 Etyp
:= Etype
(Next_Formal
(F
));
11850 Etyp
:= Etype
(Subp
);
11853 -- Prepare subprogram declaration and insert it as an action on the
11854 -- clause node. The visibility for this entity is used to test for
11855 -- visibility of the attribute definition clause (in the sense of
11856 -- 8.3(23) as amended by AI-195).
11858 if not Defer_Declaration
then
11860 Make_Subprogram_Declaration
(Loc
,
11861 Specification
=> Build_Spec
);
11863 -- For a tagged type, there is always a visible declaration for each
11864 -- stream TSS (it is a predefined primitive operation), and the
11865 -- completion of this declaration occurs at the freeze point, which is
11866 -- not always visible at places where the attribute definition clause is
11867 -- visible. So, we create a dummy entity here for the purpose of
11868 -- tracking the visibility of the attribute definition clause itself.
11872 Make_Defining_Identifier
(Loc
, New_External_Name
(Sname
, 'V'));
11874 Make_Object_Declaration
(Loc
,
11875 Defining_Identifier
=> Subp_Id
,
11876 Object_Definition
=> New_Occurrence_Of
(Standard_Boolean
, Loc
));
11879 Insert_Action
(N
, Subp_Decl
);
11880 Set_Entity
(N
, Subp_Id
);
11883 Make_Subprogram_Renaming_Declaration
(Loc
,
11884 Specification
=> Build_Spec
,
11885 Name
=> New_Occurrence_Of
(Subp
, Loc
));
11887 if Defer_Declaration
then
11888 Set_TSS
(Base_Type
(Ent
), Subp_Id
);
11890 Insert_Action
(N
, Subp_Decl
);
11891 Copy_TSS
(Subp_Id
, Base_Type
(Ent
));
11893 end New_Stream_Subprogram
;
11895 ------------------------------------------
11896 -- Push_Scope_And_Install_Discriminants --
11897 ------------------------------------------
11899 procedure Push_Scope_And_Install_Discriminants
(E
: Entity_Id
) is
11901 if Has_Discriminants
(E
) then
11904 -- Make discriminants visible for type declarations and protected
11905 -- type declarations, not for subtype declarations (RM 13.1.1 (12/3))
11907 if Nkind
(Parent
(E
)) /= N_Subtype_Declaration
then
11908 Install_Discriminants
(E
);
11911 end Push_Scope_And_Install_Discriminants
;
11913 ------------------------
11914 -- Rep_Item_Too_Early --
11915 ------------------------
11917 function Rep_Item_Too_Early
(T
: Entity_Id
; N
: Node_Id
) return Boolean is
11919 -- Cannot apply non-operational rep items to generic types
11921 if Is_Operational_Item
(N
) then
11925 and then Is_Generic_Type
(Root_Type
(T
))
11926 and then (Nkind
(N
) /= N_Pragma
11927 or else Get_Pragma_Id
(N
) /= Pragma_Convention
)
11929 Error_Msg_N
("representation item not allowed for generic type", N
);
11933 -- Otherwise check for incomplete type
11935 if Is_Incomplete_Or_Private_Type
(T
)
11936 and then No
(Underlying_Type
(T
))
11938 (Nkind
(N
) /= N_Pragma
11939 or else Get_Pragma_Id
(N
) /= Pragma_Import
)
11942 ("representation item must be after full type declaration", N
);
11945 -- If the type has incomplete components, a representation clause is
11946 -- illegal but stream attributes and Convention pragmas are correct.
11948 elsif Has_Private_Component
(T
) then
11949 if Nkind
(N
) = N_Pragma
then
11954 ("representation item must appear after type is fully defined",
11961 end Rep_Item_Too_Early
;
11963 -----------------------
11964 -- Rep_Item_Too_Late --
11965 -----------------------
11967 function Rep_Item_Too_Late
11970 FOnly
: Boolean := False) return Boolean
11973 Parent_Type
: Entity_Id
;
11975 procedure No_Type_Rep_Item
;
11976 -- Output message indicating that no type-related aspects can be
11977 -- specified due to some property of the parent type.
11979 procedure Too_Late
;
11980 -- Output message for an aspect being specified too late
11982 -- Note that neither of the above errors is considered a serious one,
11983 -- since the effect is simply that we ignore the representation clause
11985 -- Is this really true? In any case if we make this change we must
11986 -- document the requirement in the spec of Rep_Item_Too_Late that
11987 -- if True is returned, then the rep item must be completely ignored???
11989 ----------------------
11990 -- No_Type_Rep_Item --
11991 ----------------------
11993 procedure No_Type_Rep_Item
is
11995 Error_Msg_N
("|type-related representation item not permitted!", N
);
11996 end No_Type_Rep_Item
;
12002 procedure Too_Late
is
12004 -- Other compilers seem more relaxed about rep items appearing too
12005 -- late. Since analysis tools typically don't care about rep items
12006 -- anyway, no reason to be too strict about this.
12008 if not Relaxed_RM_Semantics
then
12009 Error_Msg_N
("|representation item appears too late!", N
);
12013 -- Start of processing for Rep_Item_Too_Late
12016 -- First make sure entity is not frozen (RM 13.1(9))
12020 -- Exclude imported types, which may be frozen if they appear in a
12021 -- representation clause for a local type.
12023 and then not From_Limited_With
(T
)
12025 -- Exclude generated entities (not coming from source). The common
12026 -- case is when we generate a renaming which prematurely freezes the
12027 -- renamed internal entity, but we still want to be able to set copies
12028 -- of attribute values such as Size/Alignment.
12030 and then Comes_From_Source
(T
)
12033 S
:= First_Subtype
(T
);
12035 if Present
(Freeze_Node
(S
)) then
12036 if not Relaxed_RM_Semantics
then
12038 ("??no more representation items for }", Freeze_Node
(S
), S
);
12044 -- Check for case of untagged derived type whose parent either has
12045 -- primitive operations, or is a by reference type (RM 13.1(10)). In
12046 -- this case we do not output a Too_Late message, since there is no
12047 -- earlier point where the rep item could be placed to make it legal.
12051 and then Is_Derived_Type
(T
)
12052 and then not Is_Tagged_Type
(T
)
12054 Parent_Type
:= Etype
(Base_Type
(T
));
12056 if Has_Primitive_Operations
(Parent_Type
) then
12059 if not Relaxed_RM_Semantics
then
12061 ("\parent type & has primitive operations!", N
, Parent_Type
);
12066 elsif Is_By_Reference_Type
(Parent_Type
) then
12069 if not Relaxed_RM_Semantics
then
12071 ("\parent type & is a by reference type!", N
, Parent_Type
);
12078 -- No error, but one more warning to consider. The RM (surprisingly)
12079 -- allows this pattern:
12082 -- primitive operations for S
12083 -- type R is new S;
12084 -- rep clause for S
12086 -- Meaning that calls on the primitive operations of S for values of
12087 -- type R may require possibly expensive implicit conversion operations.
12088 -- This is not an error, but is worth a warning.
12090 if not Relaxed_RM_Semantics
and then Is_Type
(T
) then
12092 DTL
: constant Entity_Id
:= Derived_Type_Link
(Base_Type
(T
));
12096 and then Has_Primitive_Operations
(Base_Type
(T
))
12098 -- For now, do not generate this warning for the case of aspect
12099 -- specification using Ada 2012 syntax, since we get wrong
12100 -- messages we do not understand. The whole business of derived
12101 -- types and rep items seems a bit confused when aspects are
12102 -- used, since the aspects are not evaluated till freeze time.
12104 and then not From_Aspect_Specification
(N
)
12106 Error_Msg_Sloc
:= Sloc
(DTL
);
12108 ("representation item for& appears after derived type "
12109 & "declaration#??", N
);
12111 ("\may result in implicit conversions for primitive "
12112 & "operations of&??", N
, T
);
12114 ("\to change representations when called with arguments "
12115 & "of type&??", N
, DTL
);
12120 -- No error, link item into head of chain of rep items for the entity,
12121 -- but avoid chaining if we have an overloadable entity, and the pragma
12122 -- is one that can apply to multiple overloaded entities.
12124 if Is_Overloadable
(T
) and then Nkind
(N
) = N_Pragma
then
12126 Pname
: constant Name_Id
:= Pragma_Name
(N
);
12128 if Nam_In
(Pname
, Name_Convention
, Name_Import
, Name_Export
,
12129 Name_External
, Name_Interface
)
12136 Record_Rep_Item
(T
, N
);
12138 end Rep_Item_Too_Late
;
12140 -------------------------------------
12141 -- Replace_Type_References_Generic --
12142 -------------------------------------
12144 procedure Replace_Type_References_Generic
(N
: Node_Id
; T
: Entity_Id
) is
12145 TName
: constant Name_Id
:= Chars
(T
);
12147 function Replace_Node
(N
: Node_Id
) return Traverse_Result
;
12148 -- Processes a single node in the traversal procedure below, checking
12149 -- if node N should be replaced, and if so, doing the replacement.
12151 procedure Replace_Type_Refs
is new Traverse_Proc
(Replace_Node
);
12152 -- This instantiation provides the body of Replace_Type_References
12158 function Replace_Node
(N
: Node_Id
) return Traverse_Result
is
12163 -- Case of identifier
12165 if Nkind
(N
) = N_Identifier
then
12167 -- If not the type name, check whether it is a reference to
12168 -- some other type, which must be frozen before the predicate
12169 -- function is analyzed, i.e. before the freeze node of the
12170 -- type to which the predicate applies.
12172 if Chars
(N
) /= TName
then
12173 if Present
(Current_Entity
(N
))
12174 and then Is_Type
(Current_Entity
(N
))
12176 Freeze_Before
(Freeze_Node
(T
), Current_Entity
(N
));
12181 -- Otherwise do the replacement and we are done with this node
12184 Replace_Type_Reference
(N
);
12188 -- Case of selected component (which is what a qualification
12189 -- looks like in the unanalyzed tree, which is what we have.
12191 elsif Nkind
(N
) = N_Selected_Component
then
12193 -- If selector name is not our type, keeping going (we might
12194 -- still have an occurrence of the type in the prefix).
12196 if Nkind
(Selector_Name
(N
)) /= N_Identifier
12197 or else Chars
(Selector_Name
(N
)) /= TName
12201 -- Selector name is our type, check qualification
12204 -- Loop through scopes and prefixes, doing comparison
12206 S
:= Current_Scope
;
12209 -- Continue if no more scopes or scope with no name
12211 if No
(S
) or else Nkind
(S
) not in N_Has_Chars
then
12215 -- Do replace if prefix is an identifier matching the
12216 -- scope that we are currently looking at.
12218 if Nkind
(P
) = N_Identifier
12219 and then Chars
(P
) = Chars
(S
)
12221 Replace_Type_Reference
(N
);
12225 -- Go check scope above us if prefix is itself of the
12226 -- form of a selected component, whose selector matches
12227 -- the scope we are currently looking at.
12229 if Nkind
(P
) = N_Selected_Component
12230 and then Nkind
(Selector_Name
(P
)) = N_Identifier
12231 and then Chars
(Selector_Name
(P
)) = Chars
(S
)
12236 -- For anything else, we don't have a match, so keep on
12237 -- going, there are still some weird cases where we may
12238 -- still have a replacement within the prefix.
12246 -- Continue for any other node kind
12254 Replace_Type_Refs
(N
);
12255 end Replace_Type_References_Generic
;
12257 -------------------------
12258 -- Same_Representation --
12259 -------------------------
12261 function Same_Representation
(Typ1
, Typ2
: Entity_Id
) return Boolean is
12262 T1
: constant Entity_Id
:= Underlying_Type
(Typ1
);
12263 T2
: constant Entity_Id
:= Underlying_Type
(Typ2
);
12266 -- A quick check, if base types are the same, then we definitely have
12267 -- the same representation, because the subtype specific representation
12268 -- attributes (Size and Alignment) do not affect representation from
12269 -- the point of view of this test.
12271 if Base_Type
(T1
) = Base_Type
(T2
) then
12274 elsif Is_Private_Type
(Base_Type
(T2
))
12275 and then Base_Type
(T1
) = Full_View
(Base_Type
(T2
))
12280 -- Tagged types never have differing representations
12282 if Is_Tagged_Type
(T1
) then
12286 -- Representations are definitely different if conventions differ
12288 if Convention
(T1
) /= Convention
(T2
) then
12292 -- Representations are different if component alignments or scalar
12293 -- storage orders differ.
12295 if (Is_Record_Type
(T1
) or else Is_Array_Type
(T1
))
12297 (Is_Record_Type
(T2
) or else Is_Array_Type
(T2
))
12299 (Component_Alignment
(T1
) /= Component_Alignment
(T2
)
12300 or else Reverse_Storage_Order
(T1
) /= Reverse_Storage_Order
(T2
))
12305 -- For arrays, the only real issue is component size. If we know the
12306 -- component size for both arrays, and it is the same, then that's
12307 -- good enough to know we don't have a change of representation.
12309 if Is_Array_Type
(T1
) then
12310 if Known_Component_Size
(T1
)
12311 and then Known_Component_Size
(T2
)
12312 and then Component_Size
(T1
) = Component_Size
(T2
)
12314 if VM_Target
= No_VM
then
12317 -- In VM targets the representation of arrays with aliased
12318 -- components differs from arrays with non-aliased components
12321 return Has_Aliased_Components
(Base_Type
(T1
))
12323 Has_Aliased_Components
(Base_Type
(T2
));
12328 -- Types definitely have same representation if neither has non-standard
12329 -- representation since default representations are always consistent.
12330 -- If only one has non-standard representation, and the other does not,
12331 -- then we consider that they do not have the same representation. They
12332 -- might, but there is no way of telling early enough.
12334 if Has_Non_Standard_Rep
(T1
) then
12335 if not Has_Non_Standard_Rep
(T2
) then
12339 return not Has_Non_Standard_Rep
(T2
);
12342 -- Here the two types both have non-standard representation, and we need
12343 -- to determine if they have the same non-standard representation.
12345 -- For arrays, we simply need to test if the component sizes are the
12346 -- same. Pragma Pack is reflected in modified component sizes, so this
12347 -- check also deals with pragma Pack.
12349 if Is_Array_Type
(T1
) then
12350 return Component_Size
(T1
) = Component_Size
(T2
);
12352 -- Tagged types always have the same representation, because it is not
12353 -- possible to specify different representations for common fields.
12355 elsif Is_Tagged_Type
(T1
) then
12358 -- Case of record types
12360 elsif Is_Record_Type
(T1
) then
12362 -- Packed status must conform
12364 if Is_Packed
(T1
) /= Is_Packed
(T2
) then
12367 -- Otherwise we must check components. Typ2 maybe a constrained
12368 -- subtype with fewer components, so we compare the components
12369 -- of the base types.
12372 Record_Case
: declare
12373 CD1
, CD2
: Entity_Id
;
12375 function Same_Rep
return Boolean;
12376 -- CD1 and CD2 are either components or discriminants. This
12377 -- function tests whether they have the same representation.
12383 function Same_Rep
return Boolean is
12385 if No
(Component_Clause
(CD1
)) then
12386 return No
(Component_Clause
(CD2
));
12388 -- Note: at this point, component clauses have been
12389 -- normalized to the default bit order, so that the
12390 -- comparison of Component_Bit_Offsets is meaningful.
12393 Present
(Component_Clause
(CD2
))
12395 Component_Bit_Offset
(CD1
) = Component_Bit_Offset
(CD2
)
12397 Esize
(CD1
) = Esize
(CD2
);
12401 -- Start of processing for Record_Case
12404 if Has_Discriminants
(T1
) then
12406 -- The number of discriminants may be different if the
12407 -- derived type has fewer (constrained by values). The
12408 -- invisible discriminants retain the representation of
12409 -- the original, so the discrepancy does not per se
12410 -- indicate a different representation.
12412 CD1
:= First_Discriminant
(T1
);
12413 CD2
:= First_Discriminant
(T2
);
12414 while Present
(CD1
) and then Present
(CD2
) loop
12415 if not Same_Rep
then
12418 Next_Discriminant
(CD1
);
12419 Next_Discriminant
(CD2
);
12424 CD1
:= First_Component
(Underlying_Type
(Base_Type
(T1
)));
12425 CD2
:= First_Component
(Underlying_Type
(Base_Type
(T2
)));
12426 while Present
(CD1
) loop
12427 if not Same_Rep
then
12430 Next_Component
(CD1
);
12431 Next_Component
(CD2
);
12439 -- For enumeration types, we must check each literal to see if the
12440 -- representation is the same. Note that we do not permit enumeration
12441 -- representation clauses for Character and Wide_Character, so these
12442 -- cases were already dealt with.
12444 elsif Is_Enumeration_Type
(T1
) then
12445 Enumeration_Case
: declare
12446 L1
, L2
: Entity_Id
;
12449 L1
:= First_Literal
(T1
);
12450 L2
:= First_Literal
(T2
);
12451 while Present
(L1
) loop
12452 if Enumeration_Rep
(L1
) /= Enumeration_Rep
(L2
) then
12461 end Enumeration_Case
;
12463 -- Any other types have the same representation for these purposes
12468 end Same_Representation
;
12470 --------------------------------
12471 -- Resolve_Iterable_Operation --
12472 --------------------------------
12474 procedure Resolve_Iterable_Operation
12476 Cursor
: Entity_Id
;
12485 if not Is_Overloaded
(N
) then
12486 if not Is_Entity_Name
(N
)
12487 or else Ekind
(Entity
(N
)) /= E_Function
12488 or else Scope
(Entity
(N
)) /= Scope
(Typ
)
12489 or else No
(First_Formal
(Entity
(N
)))
12490 or else Etype
(First_Formal
(Entity
(N
))) /= Typ
12492 Error_Msg_N
("iterable primitive must be local function name "
12493 & "whose first formal is an iterable type", N
);
12498 F1
:= First_Formal
(Ent
);
12499 if Nam
= Name_First
then
12501 -- First (Container) => Cursor
12503 if Etype
(Ent
) /= Cursor
then
12504 Error_Msg_N
("primitive for First must yield a curosr", N
);
12507 elsif Nam
= Name_Next
then
12509 -- Next (Container, Cursor) => Cursor
12511 F2
:= Next_Formal
(F1
);
12513 if Etype
(F2
) /= Cursor
12514 or else Etype
(Ent
) /= Cursor
12515 or else Present
(Next_Formal
(F2
))
12517 Error_Msg_N
("no match for Next iterable primitive", N
);
12520 elsif Nam
= Name_Has_Element
then
12522 -- Has_Element (Container, Cursor) => Boolean
12524 F2
:= Next_Formal
(F1
);
12525 if Etype
(F2
) /= Cursor
12526 or else Etype
(Ent
) /= Standard_Boolean
12527 or else Present
(Next_Formal
(F2
))
12529 Error_Msg_N
("no match for Has_Element iterable primitive", N
);
12532 elsif Nam
= Name_Element
then
12533 F2
:= Next_Formal
(F1
);
12536 or else Etype
(F2
) /= Cursor
12537 or else Present
(Next_Formal
(F2
))
12539 Error_Msg_N
("no match for Element iterable primitive", N
);
12544 raise Program_Error
;
12548 -- Overloaded case: find subprogram with proper signature.
12549 -- Caller will report error if no match is found.
12556 Get_First_Interp
(N
, I
, It
);
12557 while Present
(It
.Typ
) loop
12558 if Ekind
(It
.Nam
) = E_Function
12559 and then Scope
(It
.Nam
) = Scope
(Typ
)
12560 and then Etype
(First_Formal
(It
.Nam
)) = Typ
12562 F1
:= First_Formal
(It
.Nam
);
12564 if Nam
= Name_First
then
12565 if Etype
(It
.Nam
) = Cursor
12566 and then No
(Next_Formal
(F1
))
12568 Set_Entity
(N
, It
.Nam
);
12572 elsif Nam
= Name_Next
then
12573 F2
:= Next_Formal
(F1
);
12576 and then No
(Next_Formal
(F2
))
12577 and then Etype
(F2
) = Cursor
12578 and then Etype
(It
.Nam
) = Cursor
12580 Set_Entity
(N
, It
.Nam
);
12584 elsif Nam
= Name_Has_Element
then
12585 F2
:= Next_Formal
(F1
);
12588 and then No
(Next_Formal
(F2
))
12589 and then Etype
(F2
) = Cursor
12590 and then Etype
(It
.Nam
) = Standard_Boolean
12592 Set_Entity
(N
, It
.Nam
);
12593 F2
:= Next_Formal
(F1
);
12597 elsif Nam
= Name_Element
then
12598 F2
:= Next_Formal
(F1
);
12601 and then No
(Next_Formal
(F2
))
12602 and then Etype
(F2
) = Cursor
12604 Set_Entity
(N
, It
.Nam
);
12610 Get_Next_Interp
(I
, It
);
12614 end Resolve_Iterable_Operation
;
12620 procedure Set_Biased
12624 Biased
: Boolean := True)
12628 Set_Has_Biased_Representation
(E
);
12630 if Warn_On_Biased_Representation
then
12632 ("?B?" & Msg
& " forces biased representation for&", N
, E
);
12637 --------------------
12638 -- Set_Enum_Esize --
12639 --------------------
12641 procedure Set_Enum_Esize
(T
: Entity_Id
) is
12647 Init_Alignment
(T
);
12649 -- Find the minimum standard size (8,16,32,64) that fits
12651 Lo
:= Enumeration_Rep
(Entity
(Type_Low_Bound
(T
)));
12652 Hi
:= Enumeration_Rep
(Entity
(Type_High_Bound
(T
)));
12655 if Lo
>= -Uint_2
**07 and then Hi
< Uint_2
**07 then
12656 Sz
:= Standard_Character_Size
; -- May be > 8 on some targets
12658 elsif Lo
>= -Uint_2
**15 and then Hi
< Uint_2
**15 then
12661 elsif Lo
>= -Uint_2
**31 and then Hi
< Uint_2
**31 then
12664 else pragma Assert
(Lo
>= -Uint_2
**63 and then Hi
< Uint_2
**63);
12669 if Hi
< Uint_2
**08 then
12670 Sz
:= Standard_Character_Size
; -- May be > 8 on some targets
12672 elsif Hi
< Uint_2
**16 then
12675 elsif Hi
< Uint_2
**32 then
12678 else pragma Assert
(Hi
< Uint_2
**63);
12683 -- That minimum is the proper size unless we have a foreign convention
12684 -- and the size required is 32 or less, in which case we bump the size
12685 -- up to 32. This is required for C and C++ and seems reasonable for
12686 -- all other foreign conventions.
12688 if Has_Foreign_Convention
(T
)
12689 and then Esize
(T
) < Standard_Integer_Size
12691 -- Don't do this if Short_Enums on target
12693 and then not Target_Short_Enums
12695 Init_Esize
(T
, Standard_Integer_Size
);
12697 Init_Esize
(T
, Sz
);
12699 end Set_Enum_Esize
;
12701 -----------------------------
12702 -- Uninstall_Discriminants --
12703 -----------------------------
12705 procedure Uninstall_Discriminants
(E
: Entity_Id
) is
12711 -- Discriminants have been made visible for type declarations and
12712 -- protected type declarations, not for subtype declarations.
12714 if Nkind
(Parent
(E
)) /= N_Subtype_Declaration
then
12715 Disc
:= First_Discriminant
(E
);
12716 while Present
(Disc
) loop
12717 if Disc
/= Current_Entity
(Disc
) then
12718 Prev
:= Current_Entity
(Disc
);
12719 while Present
(Prev
)
12720 and then Present
(Homonym
(Prev
))
12721 and then Homonym
(Prev
) /= Disc
12723 Prev
:= Homonym
(Prev
);
12729 Set_Is_Immediately_Visible
(Disc
, False);
12731 Outer
:= Homonym
(Disc
);
12732 while Present
(Outer
) and then Scope
(Outer
) = E
loop
12733 Outer
:= Homonym
(Outer
);
12736 -- Reset homonym link of other entities, but do not modify link
12737 -- between entities in current scope, so that the back-end can
12738 -- have a proper count of local overloadings.
12741 Set_Name_Entity_Id
(Chars
(Disc
), Outer
);
12743 elsif Scope
(Prev
) /= Scope
(Disc
) then
12744 Set_Homonym
(Prev
, Outer
);
12747 Next_Discriminant
(Disc
);
12750 end Uninstall_Discriminants
;
12752 -------------------------------------------
12753 -- Uninstall_Discriminants_And_Pop_Scope --
12754 -------------------------------------------
12756 procedure Uninstall_Discriminants_And_Pop_Scope
(E
: Entity_Id
) is
12758 if Has_Discriminants
(E
) then
12759 Uninstall_Discriminants
(E
);
12762 end Uninstall_Discriminants_And_Pop_Scope
;
12764 ------------------------------
12765 -- Validate_Address_Clauses --
12766 ------------------------------
12768 procedure Validate_Address_Clauses
is
12770 for J
in Address_Clause_Checks
.First
.. Address_Clause_Checks
.Last
loop
12772 ACCR
: Address_Clause_Check_Record
12773 renames Address_Clause_Checks
.Table
(J
);
12777 X_Alignment
: Uint
;
12778 Y_Alignment
: Uint
;
12784 -- Skip processing of this entry if warning already posted
12786 if not Address_Warning_Posted
(ACCR
.N
) then
12787 Expr
:= Original_Node
(Expression
(ACCR
.N
));
12791 X_Alignment
:= Alignment
(ACCR
.X
);
12792 Y_Alignment
:= Alignment
(ACCR
.Y
);
12794 -- Similarly obtain sizes
12796 X_Size
:= Esize
(ACCR
.X
);
12797 Y_Size
:= Esize
(ACCR
.Y
);
12799 -- Check for large object overlaying smaller one
12802 and then X_Size
> Uint_0
12803 and then X_Size
> Y_Size
12806 ("??& overlays smaller object", ACCR
.N
, ACCR
.X
);
12808 ("\??program execution may be erroneous", ACCR
.N
);
12809 Error_Msg_Uint_1
:= X_Size
;
12811 ("\??size of & is ^", ACCR
.N
, ACCR
.X
);
12812 Error_Msg_Uint_1
:= Y_Size
;
12814 ("\??size of & is ^", ACCR
.N
, ACCR
.Y
);
12816 -- Check for inadequate alignment, both of the base object
12817 -- and of the offset, if any. We only do this check if the
12818 -- run-time Alignment_Check is active. No point in warning
12819 -- if this check has been suppressed (or is suppressed by
12820 -- default in the non-strict alignment machine case).
12822 -- Note: we do not check the alignment if we gave a size
12823 -- warning, since it would likely be redundant.
12825 elsif not Alignment_Checks_Suppressed
(ACCR
.Y
)
12826 and then Y_Alignment
/= Uint_0
12827 and then (Y_Alignment
< X_Alignment
12830 Nkind
(Expr
) = N_Attribute_Reference
12832 Attribute_Name
(Expr
) = Name_Address
12834 Has_Compatible_Alignment
12835 (ACCR
.X
, Prefix
(Expr
))
12836 /= Known_Compatible
))
12839 ("??specified address for& may be inconsistent "
12840 & "with alignment", ACCR
.N
, ACCR
.X
);
12842 ("\??program execution may be erroneous (RM 13.3(27))",
12844 Error_Msg_Uint_1
:= X_Alignment
;
12846 ("\??alignment of & is ^", ACCR
.N
, ACCR
.X
);
12847 Error_Msg_Uint_1
:= Y_Alignment
;
12849 ("\??alignment of & is ^", ACCR
.N
, ACCR
.Y
);
12850 if Y_Alignment
>= X_Alignment
then
12852 ("\??but offset is not multiple of alignment", ACCR
.N
);
12858 end Validate_Address_Clauses
;
12860 ---------------------------
12861 -- Validate_Independence --
12862 ---------------------------
12864 procedure Validate_Independence
is
12865 SU
: constant Uint
:= UI_From_Int
(System_Storage_Unit
);
12873 procedure Check_Array_Type
(Atyp
: Entity_Id
);
12874 -- Checks if the array type Atyp has independent components, and
12875 -- if not, outputs an appropriate set of error messages.
12877 procedure No_Independence
;
12878 -- Output message that independence cannot be guaranteed
12880 function OK_Component
(C
: Entity_Id
) return Boolean;
12881 -- Checks one component to see if it is independently accessible, and
12882 -- if so yields True, otherwise yields False if independent access
12883 -- cannot be guaranteed. This is a conservative routine, it only
12884 -- returns True if it knows for sure, it returns False if it knows
12885 -- there is a problem, or it cannot be sure there is no problem.
12887 procedure Reason_Bad_Component
(C
: Entity_Id
);
12888 -- Outputs continuation message if a reason can be determined for
12889 -- the component C being bad.
12891 ----------------------
12892 -- Check_Array_Type --
12893 ----------------------
12895 procedure Check_Array_Type
(Atyp
: Entity_Id
) is
12896 Ctyp
: constant Entity_Id
:= Component_Type
(Atyp
);
12899 -- OK if no alignment clause, no pack, and no component size
12901 if not Has_Component_Size_Clause
(Atyp
)
12902 and then not Has_Alignment_Clause
(Atyp
)
12903 and then not Is_Packed
(Atyp
)
12908 -- Case of component size is greater than or equal to 64 and the
12909 -- alignment of the array is at least as large as the alignment
12910 -- of the component. We are definitely OK in this situation.
12912 if Known_Component_Size
(Atyp
)
12913 and then Component_Size
(Atyp
) >= 64
12914 and then Known_Alignment
(Atyp
)
12915 and then Known_Alignment
(Ctyp
)
12916 and then Alignment
(Atyp
) >= Alignment
(Ctyp
)
12921 -- Check actual component size
12923 if not Known_Component_Size
(Atyp
)
12924 or else not (Addressable
(Component_Size
(Atyp
))
12925 and then Component_Size
(Atyp
) < 64)
12926 or else Component_Size
(Atyp
) mod Esize
(Ctyp
) /= 0
12930 -- Bad component size, check reason
12932 if Has_Component_Size_Clause
(Atyp
) then
12933 P
:= Get_Attribute_Definition_Clause
12934 (Atyp
, Attribute_Component_Size
);
12936 if Present
(P
) then
12937 Error_Msg_Sloc
:= Sloc
(P
);
12938 Error_Msg_N
("\because of Component_Size clause#", N
);
12943 if Is_Packed
(Atyp
) then
12944 P
:= Get_Rep_Pragma
(Atyp
, Name_Pack
);
12946 if Present
(P
) then
12947 Error_Msg_Sloc
:= Sloc
(P
);
12948 Error_Msg_N
("\because of pragma Pack#", N
);
12953 -- No reason found, just return
12958 -- Array type is OK independence-wise
12961 end Check_Array_Type
;
12963 ---------------------
12964 -- No_Independence --
12965 ---------------------
12967 procedure No_Independence
is
12969 if Pragma_Name
(N
) = Name_Independent
then
12970 Error_Msg_NE
("independence cannot be guaranteed for&", N
, E
);
12973 ("independent components cannot be guaranteed for&", N
, E
);
12975 end No_Independence
;
12981 function OK_Component
(C
: Entity_Id
) return Boolean is
12982 Rec
: constant Entity_Id
:= Scope
(C
);
12983 Ctyp
: constant Entity_Id
:= Etype
(C
);
12986 -- OK if no component clause, no Pack, and no alignment clause
12988 if No
(Component_Clause
(C
))
12989 and then not Is_Packed
(Rec
)
12990 and then not Has_Alignment_Clause
(Rec
)
12995 -- Here we look at the actual component layout. A component is
12996 -- addressable if its size is a multiple of the Esize of the
12997 -- component type, and its starting position in the record has
12998 -- appropriate alignment, and the record itself has appropriate
12999 -- alignment to guarantee the component alignment.
13001 -- Make sure sizes are static, always assume the worst for any
13002 -- cases where we cannot check static values.
13004 if not (Known_Static_Esize
(C
)
13006 Known_Static_Esize
(Ctyp
))
13011 -- Size of component must be addressable or greater than 64 bits
13012 -- and a multiple of bytes.
13014 if not Addressable
(Esize
(C
)) and then Esize
(C
) < Uint_64
then
13018 -- Check size is proper multiple
13020 if Esize
(C
) mod Esize
(Ctyp
) /= 0 then
13024 -- Check alignment of component is OK
13026 if not Known_Component_Bit_Offset
(C
)
13027 or else Component_Bit_Offset
(C
) < Uint_0
13028 or else Component_Bit_Offset
(C
) mod Esize
(Ctyp
) /= 0
13033 -- Check alignment of record type is OK
13035 if not Known_Alignment
(Rec
)
13036 or else (Alignment
(Rec
) * SU
) mod Esize
(Ctyp
) /= 0
13041 -- All tests passed, component is addressable
13046 --------------------------
13047 -- Reason_Bad_Component --
13048 --------------------------
13050 procedure Reason_Bad_Component
(C
: Entity_Id
) is
13051 Rec
: constant Entity_Id
:= Scope
(C
);
13052 Ctyp
: constant Entity_Id
:= Etype
(C
);
13055 -- If component clause present assume that's the problem
13057 if Present
(Component_Clause
(C
)) then
13058 Error_Msg_Sloc
:= Sloc
(Component_Clause
(C
));
13059 Error_Msg_N
("\because of Component_Clause#", N
);
13063 -- If pragma Pack clause present, assume that's the problem
13065 if Is_Packed
(Rec
) then
13066 P
:= Get_Rep_Pragma
(Rec
, Name_Pack
);
13068 if Present
(P
) then
13069 Error_Msg_Sloc
:= Sloc
(P
);
13070 Error_Msg_N
("\because of pragma Pack#", N
);
13075 -- See if record has bad alignment clause
13077 if Has_Alignment_Clause
(Rec
)
13078 and then Known_Alignment
(Rec
)
13079 and then (Alignment
(Rec
) * SU
) mod Esize
(Ctyp
) /= 0
13081 P
:= Get_Attribute_Definition_Clause
(Rec
, Attribute_Alignment
);
13083 if Present
(P
) then
13084 Error_Msg_Sloc
:= Sloc
(P
);
13085 Error_Msg_N
("\because of Alignment clause#", N
);
13089 -- Couldn't find a reason, so return without a message
13092 end Reason_Bad_Component
;
13094 -- Start of processing for Validate_Independence
13097 for J
in Independence_Checks
.First
.. Independence_Checks
.Last
loop
13098 N
:= Independence_Checks
.Table
(J
).N
;
13099 E
:= Independence_Checks
.Table
(J
).E
;
13100 IC
:= Pragma_Name
(N
) = Name_Independent_Components
;
13102 -- Deal with component case
13104 if Ekind
(E
) = E_Discriminant
or else Ekind
(E
) = E_Component
then
13105 if not OK_Component
(E
) then
13107 Reason_Bad_Component
(E
);
13112 -- Deal with record with Independent_Components
13114 if IC
and then Is_Record_Type
(E
) then
13115 Comp
:= First_Component_Or_Discriminant
(E
);
13116 while Present
(Comp
) loop
13117 if not OK_Component
(Comp
) then
13119 Reason_Bad_Component
(Comp
);
13123 Next_Component_Or_Discriminant
(Comp
);
13127 -- Deal with address clause case
13129 if Is_Object
(E
) then
13130 Addr
:= Address_Clause
(E
);
13132 if Present
(Addr
) then
13134 Error_Msg_Sloc
:= Sloc
(Addr
);
13135 Error_Msg_N
("\because of Address clause#", N
);
13140 -- Deal with independent components for array type
13142 if IC
and then Is_Array_Type
(E
) then
13143 Check_Array_Type
(E
);
13146 -- Deal with independent components for array object
13148 if IC
and then Is_Object
(E
) and then Is_Array_Type
(Etype
(E
)) then
13149 Check_Array_Type
(Etype
(E
));
13154 end Validate_Independence
;
13156 ------------------------------
13157 -- Validate_Iterable_Aspect --
13158 ------------------------------
13160 procedure Validate_Iterable_Aspect
(Typ
: Entity_Id
; ASN
: Node_Id
) is
13165 Cursor
: constant Entity_Id
:= Get_Cursor_Type
(ASN
, Typ
);
13167 First_Id
: Entity_Id
;
13168 Next_Id
: Entity_Id
;
13169 Has_Element_Id
: Entity_Id
;
13170 Element_Id
: Entity_Id
;
13173 -- If previous error aspect is unusable
13175 if Cursor
= Any_Type
then
13181 Has_Element_Id
:= Empty
;
13182 Element_Id
:= Empty
;
13184 -- Each expression must resolve to a function with the proper signature
13186 Assoc
:= First
(Component_Associations
(Expression
(ASN
)));
13187 while Present
(Assoc
) loop
13188 Expr
:= Expression
(Assoc
);
13191 Prim
:= First
(Choices
(Assoc
));
13193 if Nkind
(Prim
) /= N_Identifier
or else Present
(Next
(Prim
)) then
13194 Error_Msg_N
("illegal name in association", Prim
);
13196 elsif Chars
(Prim
) = Name_First
then
13197 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_First
);
13198 First_Id
:= Entity
(Expr
);
13200 elsif Chars
(Prim
) = Name_Next
then
13201 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_Next
);
13202 Next_Id
:= Entity
(Expr
);
13204 elsif Chars
(Prim
) = Name_Has_Element
then
13205 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_Has_Element
);
13206 Has_Element_Id
:= Entity
(Expr
);
13208 elsif Chars
(Prim
) = Name_Element
then
13209 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_Element
);
13210 Element_Id
:= Entity
(Expr
);
13213 Error_Msg_N
("invalid name for iterable function", Prim
);
13219 if No
(First_Id
) then
13220 Error_Msg_N
("match for First primitive not found", ASN
);
13222 elsif No
(Next_Id
) then
13223 Error_Msg_N
("match for Next primitive not found", ASN
);
13225 elsif No
(Has_Element_Id
) then
13226 Error_Msg_N
("match for Has_Element primitive not found", ASN
);
13228 elsif No
(Element_Id
) then
13231 end Validate_Iterable_Aspect
;
13233 -----------------------------------
13234 -- Validate_Unchecked_Conversion --
13235 -----------------------------------
13237 procedure Validate_Unchecked_Conversion
13239 Act_Unit
: Entity_Id
)
13241 Source
: Entity_Id
;
13242 Target
: Entity_Id
;
13246 -- Obtain source and target types. Note that we call Ancestor_Subtype
13247 -- here because the processing for generic instantiation always makes
13248 -- subtypes, and we want the original frozen actual types.
13250 -- If we are dealing with private types, then do the check on their
13251 -- fully declared counterparts if the full declarations have been
13252 -- encountered (they don't have to be visible, but they must exist).
13254 Source
:= Ancestor_Subtype
(Etype
(First_Formal
(Act_Unit
)));
13256 if Is_Private_Type
(Source
)
13257 and then Present
(Underlying_Type
(Source
))
13259 Source
:= Underlying_Type
(Source
);
13262 Target
:= Ancestor_Subtype
(Etype
(Act_Unit
));
13264 -- If either type is generic, the instantiation happens within a generic
13265 -- unit, and there is nothing to check. The proper check will happen
13266 -- when the enclosing generic is instantiated.
13268 if Is_Generic_Type
(Source
) or else Is_Generic_Type
(Target
) then
13272 if Is_Private_Type
(Target
)
13273 and then Present
(Underlying_Type
(Target
))
13275 Target
:= Underlying_Type
(Target
);
13278 -- Source may be unconstrained array, but not target
13280 if Is_Array_Type
(Target
) and then not Is_Constrained
(Target
) then
13282 ("unchecked conversion to unconstrained array not allowed", N
);
13286 -- Warn if conversion between two different convention pointers
13288 if Is_Access_Type
(Target
)
13289 and then Is_Access_Type
(Source
)
13290 and then Convention
(Target
) /= Convention
(Source
)
13291 and then Warn_On_Unchecked_Conversion
13293 -- Give warnings for subprogram pointers only on most targets
13295 if Is_Access_Subprogram_Type
(Target
)
13296 or else Is_Access_Subprogram_Type
(Source
)
13299 ("?z?conversion between pointers with different conventions!",
13304 -- Warn if one of the operands is Ada.Calendar.Time. Do not emit a
13305 -- warning when compiling GNAT-related sources.
13307 if Warn_On_Unchecked_Conversion
13308 and then not In_Predefined_Unit
(N
)
13309 and then RTU_Loaded
(Ada_Calendar
)
13310 and then (Chars
(Source
) = Name_Time
13312 Chars
(Target
) = Name_Time
)
13314 -- If Ada.Calendar is loaded and the name of one of the operands is
13315 -- Time, there is a good chance that this is Ada.Calendar.Time.
13318 Calendar_Time
: constant Entity_Id
:= Full_View
(RTE
(RO_CA_Time
));
13320 pragma Assert
(Present
(Calendar_Time
));
13322 if Source
= Calendar_Time
or else Target
= Calendar_Time
then
13324 ("?z?representation of 'Time values may change between "
13325 & "'G'N'A'T versions", N
);
13330 -- Make entry in unchecked conversion table for later processing by
13331 -- Validate_Unchecked_Conversions, which will check sizes and alignments
13332 -- (using values set by the back-end where possible). This is only done
13333 -- if the appropriate warning is active.
13335 if Warn_On_Unchecked_Conversion
then
13336 Unchecked_Conversions
.Append
13337 (New_Val
=> UC_Entry
'(Eloc => Sloc (N),
13340 Act_Unit => Act_Unit));
13342 -- If both sizes are known statically now, then back end annotation
13343 -- is not required to do a proper check but if either size is not
13344 -- known statically, then we need the annotation.
13346 if Known_Static_RM_Size (Source)
13348 Known_Static_RM_Size (Target)
13352 Back_Annotate_Rep_Info := True;
13356 -- If unchecked conversion to access type, and access type is declared
13357 -- in the same unit as the unchecked conversion, then set the flag
13358 -- No_Strict_Aliasing (no strict aliasing is implicit here)
13360 if Is_Access_Type (Target) and then
13361 In_Same_Source_Unit (Target, N)
13363 Set_No_Strict_Aliasing (Implementation_Base_Type (Target));
13366 -- Generate N_Validate_Unchecked_Conversion node for back end in case
13367 -- the back end needs to perform special validation checks.
13369 -- Shouldn't this be in Exp_Ch13, since the check only gets done if we
13370 -- have full expansion and the back end is called ???
13373 Make_Validate_Unchecked_Conversion (Sloc (N));
13374 Set_Source_Type (Vnode, Source);
13375 Set_Target_Type (Vnode, Target);
13377 -- If the unchecked conversion node is in a list, just insert before it.
13378 -- If not we have some strange case, not worth bothering about.
13380 if Is_List_Member (N) then
13381 Insert_After (N, Vnode);
13383 end Validate_Unchecked_Conversion;
13385 ------------------------------------
13386 -- Validate_Unchecked_Conversions --
13387 ------------------------------------
13389 procedure Validate_Unchecked_Conversions is
13391 for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop
13393 T : UC_Entry renames Unchecked_Conversions.Table (N);
13395 Eloc : constant Source_Ptr := T.Eloc;
13396 Source : constant Entity_Id := T.Source;
13397 Target : constant Entity_Id := T.Target;
13398 Act_Unit : constant Entity_Id := T.Act_Unit;
13404 -- Skip if function marked as warnings off
13406 if Warnings_Off (Act_Unit) then
13410 -- This validation check, which warns if we have unequal sizes for
13411 -- unchecked conversion, and thus potentially implementation
13412 -- dependent semantics, is one of the few occasions on which we
13413 -- use the official RM size instead of Esize. See description in
13414 -- Einfo "Handling of Type'Size Values" for details.
13416 if Serious_Errors_Detected = 0
13417 and then Known_Static_RM_Size (Source)
13418 and then Known_Static_RM_Size (Target)
13420 -- Don't do the check if warnings off for either type, note the
13421 -- deliberate use of OR here instead of OR ELSE to get the flag
13422 -- Warnings_Off_Used set for both types if appropriate.
13424 and then not (Has_Warnings_Off (Source)
13426 Has_Warnings_Off (Target))
13428 Source_Siz := RM_Size (Source);
13429 Target_Siz := RM_Size (Target);
13431 if Source_Siz /= Target_Siz then
13433 ("?z?types for unchecked conversion have different sizes!",
13436 if All_Errors_Mode then
13437 Error_Msg_Name_1 := Chars (Source);
13438 Error_Msg_Uint_1 := Source_Siz;
13439 Error_Msg_Name_2 := Chars (Target);
13440 Error_Msg_Uint_2 := Target_Siz;
13441 Error_Msg ("\size of % is ^, size of % is ^?z?", Eloc);
13443 Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz);
13445 if Is_Discrete_Type (Source)
13447 Is_Discrete_Type (Target)
13449 if Source_Siz > Target_Siz then
13451 ("\?z?^ high order bits of source will "
13452 & "be ignored!", Eloc);
13454 elsif Is_Unsigned_Type (Source) then
13456 ("\?z?source will be extended with ^ high order "
13457 & "zero bits!", Eloc);
13461 ("\?z?source will be extended with ^ high order "
13462 & "sign bits!", Eloc);
13465 elsif Source_Siz < Target_Siz then
13466 if Is_Discrete_Type (Target) then
13467 if Bytes_Big_Endian then
13469 ("\?z?target value will include ^ undefined "
13470 & "low order bits!", Eloc);
13473 ("\?z?target value will include ^ undefined "
13474 & "high order bits!", Eloc);
13479 ("\?z?^ trailing bits of target value will be "
13480 & "undefined!", Eloc);
13483 else pragma Assert (Source_Siz > Target_Siz);
13485 ("\?z?^ trailing bits of source will be ignored!",
13492 -- If both types are access types, we need to check the alignment.
13493 -- If the alignment of both is specified, we can do it here.
13495 if Serious_Errors_Detected = 0
13496 and then Is_Access_Type (Source)
13497 and then Is_Access_Type (Target)
13498 and then Target_Strict_Alignment
13499 and then Present (Designated_Type (Source))
13500 and then Present (Designated_Type (Target))
13503 D_Source : constant Entity_Id := Designated_Type (Source);
13504 D_Target : constant Entity_Id := Designated_Type (Target);
13507 if Known_Alignment (D_Source)
13509 Known_Alignment (D_Target)
13512 Source_Align : constant Uint := Alignment (D_Source);
13513 Target_Align : constant Uint := Alignment (D_Target);
13516 if Source_Align < Target_Align
13517 and then not Is_Tagged_Type (D_Source)
13519 -- Suppress warning if warnings suppressed on either
13520 -- type or either designated type. Note the use of
13521 -- OR here instead of OR ELSE. That is intentional,
13522 -- we would like to set flag Warnings_Off_Used in
13523 -- all types for which warnings are suppressed.
13525 and then not (Has_Warnings_Off (D_Source)
13527 Has_Warnings_Off (D_Target)
13529 Has_Warnings_Off (Source)
13531 Has_Warnings_Off (Target))
13533 Error_Msg_Uint_1 := Target_Align;
13534 Error_Msg_Uint_2 := Source_Align;
13535 Error_Msg_Node_1 := D_Target;
13536 Error_Msg_Node_2 := D_Source;
13538 ("?z?alignment of & (^) is stricter than "
13539 & "alignment of & (^)!", Eloc);
13541 ("\?z?resulting access value may have invalid "
13542 & "alignment!", Eloc);
13553 end Validate_Unchecked_Conversions;