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
;
37 with Ghost
; use Ghost
;
39 with Lib
.Xref
; use Lib
.Xref
;
40 with Namet
; use Namet
;
41 with Nlists
; use Nlists
;
42 with Nmake
; use Nmake
;
44 with Restrict
; use Restrict
;
45 with Rident
; use Rident
;
46 with Rtsfind
; use Rtsfind
;
48 with Sem_Aux
; use Sem_Aux
;
49 with Sem_Case
; use Sem_Case
;
50 with Sem_Ch3
; use Sem_Ch3
;
51 with Sem_Ch6
; use Sem_Ch6
;
52 with Sem_Ch8
; use Sem_Ch8
;
53 with Sem_Dim
; use Sem_Dim
;
54 with Sem_Disp
; use Sem_Disp
;
55 with Sem_Eval
; use Sem_Eval
;
56 with Sem_Prag
; use Sem_Prag
;
57 with Sem_Res
; use Sem_Res
;
58 with Sem_Type
; use Sem_Type
;
59 with Sem_Util
; use Sem_Util
;
60 with Sem_Warn
; use Sem_Warn
;
61 with Sinput
; use Sinput
;
62 with Snames
; use Snames
;
63 with Stand
; use Stand
;
64 with Sinfo
; use Sinfo
;
65 with Stringt
; use Stringt
;
66 with Targparm
; use Targparm
;
67 with Ttypes
; use Ttypes
;
68 with Tbuild
; use Tbuild
;
69 with Urealp
; use Urealp
;
70 with Warnsw
; use Warnsw
;
72 with GNAT
.Heap_Sort_G
;
74 package body Sem_Ch13
is
76 SSU
: constant Pos
:= System_Storage_Unit
;
77 -- Convenient short hand for commonly used constant
79 -----------------------
80 -- Local Subprograms --
81 -----------------------
83 procedure Alignment_Check_For_Size_Change
(Typ
: Entity_Id
; Size
: Uint
);
84 -- This routine is called after setting one of the sizes of type entity
85 -- Typ to Size. The purpose is to deal with the situation of a derived
86 -- type whose inherited alignment is no longer appropriate for the new
87 -- size value. In this case, we reset the Alignment to unknown.
89 procedure Build_Discrete_Static_Predicate
93 -- Given a predicated type Typ, where Typ is a discrete static subtype,
94 -- whose predicate expression is Expr, tests if Expr is a static predicate,
95 -- and if so, builds the predicate range list. Nam is the name of the one
96 -- argument to the predicate function. Occurrences of the type name in the
97 -- predicate expression have been replaced by identifier references to this
98 -- name, which is unique, so any identifier with Chars matching Nam must be
99 -- a reference to the type. If the predicate is non-static, this procedure
100 -- returns doing nothing. If the predicate is static, then the predicate
101 -- list is stored in Static_Discrete_Predicate (Typ), and the Expr is
102 -- rewritten as a canonicalized membership operation.
104 procedure Build_Predicate_Functions
(Typ
: Entity_Id
; N
: Node_Id
);
105 -- If Typ has predicates (indicated by Has_Predicates being set for Typ),
106 -- then either there are pragma Predicate entries on the rep chain for the
107 -- type (note that Predicate aspects are converted to pragma Predicate), or
108 -- there are inherited aspects from a parent type, or ancestor subtypes.
109 -- This procedure builds the spec and body for the Predicate function that
110 -- tests these predicates. N is the freeze node for the type. The spec of
111 -- the function is inserted before the freeze node, and the body of the
112 -- function is inserted after the freeze node. If the predicate expression
113 -- has at least one Raise_Expression, then this procedure also builds the
114 -- M version of the predicate function for use in membership tests.
116 procedure Check_Pool_Size_Clash
(Ent
: Entity_Id
; SP
, SS
: Node_Id
);
117 -- Called if both Storage_Pool and Storage_Size attribute definition
118 -- clauses (SP and SS) are present for entity Ent. Issue error message.
120 procedure Freeze_Entity_Checks
(N
: Node_Id
);
121 -- Called from Analyze_Freeze_Entity and Analyze_Generic_Freeze Entity
122 -- to generate appropriate semantic checks that are delayed until this
123 -- point (they had to be delayed this long for cases of delayed aspects,
124 -- e.g. analysis of statically predicated subtypes in choices, for which
125 -- we have to be sure the subtypes in question are frozen before checking).
127 function Get_Alignment_Value
(Expr
: Node_Id
) return Uint
;
128 -- Given the expression for an alignment value, returns the corresponding
129 -- Uint value. If the value is inappropriate, then error messages are
130 -- posted as required, and a value of No_Uint is returned.
132 function Is_Operational_Item
(N
: Node_Id
) return Boolean;
133 -- A specification for a stream attribute is allowed before the full type
134 -- is declared, as explained in AI-00137 and the corrigendum. Attributes
135 -- that do not specify a representation characteristic are operational
138 function Is_Predicate_Static
140 Nam
: Name_Id
) return Boolean;
141 -- Given predicate expression Expr, tests if Expr is predicate-static in
142 -- the sense of the rules in (RM 3.2.4 (15-24)). Occurrences of the type
143 -- name in the predicate expression have been replaced by references to
144 -- an identifier whose Chars field is Nam. This name is unique, so any
145 -- identifier with Chars matching Nam must be a reference to the type.
146 -- Returns True if the expression is predicate-static and False otherwise,
147 -- but is not in the business of setting flags or issuing error messages.
149 -- Only scalar types can have static predicates, so False is always
150 -- returned for non-scalar types.
152 -- Note: the RM seems to suggest that string types can also have static
153 -- predicates. But that really makes lttle sense as very few useful
154 -- predicates can be constructed for strings. Remember that:
158 -- is not a static expression. So even though the clearly faulty RM wording
159 -- allows the following:
161 -- subtype S is String with Static_Predicate => S < "DEF"
163 -- We can't allow this, otherwise we have predicate-static applying to a
164 -- larger class than static expressions, which was never intended.
166 procedure New_Stream_Subprogram
170 Nam
: TSS_Name_Type
);
171 -- Create a subprogram renaming of a given stream attribute to the
172 -- designated subprogram and then in the tagged case, provide this as a
173 -- primitive operation, or in the untagged case make an appropriate TSS
174 -- entry. This is more properly an expansion activity than just semantics,
175 -- but the presence of user-defined stream functions for limited types
176 -- is a legality check, which is why this takes place here rather than in
177 -- exp_ch13, where it was previously. Nam indicates the name of the TSS
178 -- function to be generated.
180 -- To avoid elaboration anomalies with freeze nodes, for untagged types
181 -- we generate both a subprogram declaration and a subprogram renaming
182 -- declaration, so that the attribute specification is handled as a
183 -- renaming_as_body. For tagged types, the specification is one of the
186 procedure Resolve_Iterable_Operation
191 -- If the name of a primitive operation for an Iterable aspect is
192 -- overloaded, resolve according to required signature.
198 Biased
: Boolean := True);
199 -- If Biased is True, sets Has_Biased_Representation flag for E, and
200 -- outputs a warning message at node N if Warn_On_Biased_Representation is
201 -- is True. This warning inserts the string Msg to describe the construct
204 ----------------------------------------------
205 -- Table for Validate_Unchecked_Conversions --
206 ----------------------------------------------
208 -- The following table collects unchecked conversions for validation.
209 -- Entries are made by Validate_Unchecked_Conversion and then the call
210 -- to Validate_Unchecked_Conversions does the actual error checking and
211 -- posting of warnings. The reason for this delayed processing is to take
212 -- advantage of back-annotations of size and alignment values performed by
215 -- Note: the reason we store a Source_Ptr value instead of a Node_Id is
216 -- that by the time Validate_Unchecked_Conversions is called, Sprint will
217 -- already have modified all Sloc values if the -gnatD option is set.
219 type UC_Entry
is record
220 Eloc
: Source_Ptr
; -- node used for posting warnings
221 Source
: Entity_Id
; -- source type for unchecked conversion
222 Target
: Entity_Id
; -- target type for unchecked conversion
223 Act_Unit
: Entity_Id
; -- actual function instantiated
226 package Unchecked_Conversions
is new Table
.Table
(
227 Table_Component_Type
=> UC_Entry
,
228 Table_Index_Type
=> Int
,
229 Table_Low_Bound
=> 1,
231 Table_Increment
=> 200,
232 Table_Name
=> "Unchecked_Conversions");
234 ----------------------------------------
235 -- Table for Validate_Address_Clauses --
236 ----------------------------------------
238 -- If an address clause has the form
240 -- for X'Address use Expr
242 -- where Expr is of the form Y'Address or recursively is a reference to a
243 -- constant of either of these forms, and X and Y are entities of objects,
244 -- then if Y has a smaller alignment than X, that merits a warning about
245 -- possible bad alignment. The following table collects address clauses of
246 -- this kind. We put these in a table so that they can be checked after the
247 -- back end has completed annotation of the alignments of objects, since we
248 -- can catch more cases that way.
250 type Address_Clause_Check_Record
is record
252 -- The address clause
255 -- The entity of the object overlaying Y
258 -- The entity of the object being overlaid
261 -- Whether the address is offset within Y
264 package Address_Clause_Checks
is new Table
.Table
(
265 Table_Component_Type
=> Address_Clause_Check_Record
,
266 Table_Index_Type
=> Int
,
267 Table_Low_Bound
=> 1,
269 Table_Increment
=> 200,
270 Table_Name
=> "Address_Clause_Checks");
272 -----------------------------------------
273 -- Adjust_Record_For_Reverse_Bit_Order --
274 -----------------------------------------
276 procedure Adjust_Record_For_Reverse_Bit_Order
(R
: Entity_Id
) is
281 -- Processing depends on version of Ada
283 -- For Ada 95, we just renumber bits within a storage unit. We do the
284 -- same for Ada 83 mode, since we recognize the Bit_Order attribute in
285 -- Ada 83, and are free to add this extension.
287 if Ada_Version
< Ada_2005
then
288 Comp
:= First_Component_Or_Discriminant
(R
);
289 while Present
(Comp
) loop
290 CC
:= Component_Clause
(Comp
);
292 -- If component clause is present, then deal with the non-default
293 -- bit order case for Ada 95 mode.
295 -- We only do this processing for the base type, and in fact that
296 -- is important, since otherwise if there are record subtypes, we
297 -- could reverse the bits once for each subtype, which is wrong.
299 if Present
(CC
) and then Ekind
(R
) = E_Record_Type
then
301 CFB
: constant Uint
:= Component_Bit_Offset
(Comp
);
302 CSZ
: constant Uint
:= Esize
(Comp
);
303 CLC
: constant Node_Id
:= Component_Clause
(Comp
);
304 Pos
: constant Node_Id
:= Position
(CLC
);
305 FB
: constant Node_Id
:= First_Bit
(CLC
);
307 Storage_Unit_Offset
: constant Uint
:=
308 CFB
/ System_Storage_Unit
;
310 Start_Bit
: constant Uint
:=
311 CFB
mod System_Storage_Unit
;
314 -- Cases where field goes over storage unit boundary
316 if Start_Bit
+ CSZ
> System_Storage_Unit
then
318 -- Allow multi-byte field but generate warning
320 if Start_Bit
mod System_Storage_Unit
= 0
321 and then CSZ
mod System_Storage_Unit
= 0
324 ("info: multi-byte field specified with "
325 & "non-standard Bit_Order?V?", CLC
);
327 if Bytes_Big_Endian
then
329 ("\bytes are not reversed "
330 & "(component is big-endian)?V?", CLC
);
333 ("\bytes are not reversed "
334 & "(component is little-endian)?V?", CLC
);
337 -- Do not allow non-contiguous field
341 ("attempt to specify non-contiguous field "
342 & "not permitted", CLC
);
344 ("\caused by non-standard Bit_Order "
347 ("\consider possibility of using "
348 & "Ada 2005 mode here", CLC
);
351 -- Case where field fits in one storage unit
354 -- Give warning if suspicious component clause
356 if Intval
(FB
) >= System_Storage_Unit
357 and then Warn_On_Reverse_Bit_Order
360 ("info: Bit_Order clause does not affect " &
361 "byte ordering?V?", Pos
);
363 Intval
(Pos
) + Intval
(FB
) /
366 ("info: position normalized to ^ before bit " &
367 "order interpreted?V?", Pos
);
370 -- Here is where we fix up the Component_Bit_Offset value
371 -- to account for the reverse bit order. Some examples of
372 -- what needs to be done are:
374 -- First_Bit .. Last_Bit Component_Bit_Offset
386 -- The rule is that the first bit is is obtained by
387 -- subtracting the old ending bit from storage_unit - 1.
389 Set_Component_Bit_Offset
391 (Storage_Unit_Offset
* System_Storage_Unit
) +
392 (System_Storage_Unit
- 1) -
393 (Start_Bit
+ CSZ
- 1));
395 Set_Normalized_First_Bit
397 Component_Bit_Offset
(Comp
) mod
398 System_Storage_Unit
);
403 Next_Component_Or_Discriminant
(Comp
);
406 -- For Ada 2005, we do machine scalar processing, as fully described In
407 -- AI-133. This involves gathering all components which start at the
408 -- same byte offset and processing them together. Same approach is still
409 -- valid in later versions including Ada 2012.
413 Max_Machine_Scalar_Size
: constant Uint
:=
415 (Standard_Long_Long_Integer_Size
);
416 -- We use this as the maximum machine scalar size
419 SSU
: constant Uint
:= UI_From_Int
(System_Storage_Unit
);
422 -- This first loop through components does two things. First it
423 -- deals with the case of components with component clauses whose
424 -- length is greater than the maximum machine scalar size (either
425 -- accepting them or rejecting as needed). Second, it counts the
426 -- number of components with component clauses whose length does
427 -- not exceed this maximum for later processing.
430 Comp
:= First_Component_Or_Discriminant
(R
);
431 while Present
(Comp
) loop
432 CC
:= Component_Clause
(Comp
);
436 Fbit
: constant Uint
:= Static_Integer
(First_Bit
(CC
));
437 Lbit
: constant Uint
:= Static_Integer
(Last_Bit
(CC
));
440 -- Case of component with last bit >= max machine scalar
442 if Lbit
>= Max_Machine_Scalar_Size
then
444 -- This is allowed only if first bit is zero, and
445 -- last bit + 1 is a multiple of storage unit size.
447 if Fbit
= 0 and then (Lbit
+ 1) mod SSU
= 0 then
449 -- This is the case to give a warning if enabled
451 if Warn_On_Reverse_Bit_Order
then
453 ("info: multi-byte field specified with "
454 & " non-standard Bit_Order?V?", CC
);
456 if Bytes_Big_Endian
then
458 ("\bytes are not reversed "
459 & "(component is big-endian)?V?", CC
);
462 ("\bytes are not reversed "
463 & "(component is little-endian)?V?", CC
);
467 -- Give error message for RM 13.5.1(10) violation
471 ("machine scalar rules not followed for&",
472 First_Bit
(CC
), Comp
);
474 Error_Msg_Uint_1
:= Lbit
+ 1;
475 Error_Msg_Uint_2
:= Max_Machine_Scalar_Size
;
477 ("\last bit + 1 (^) exceeds maximum machine "
481 if (Lbit
+ 1) mod SSU
/= 0 then
482 Error_Msg_Uint_1
:= SSU
;
484 ("\and is not a multiple of Storage_Unit (^) "
489 Error_Msg_Uint_1
:= Fbit
;
491 ("\and first bit (^) is non-zero "
497 -- OK case of machine scalar related component clause,
498 -- For now, just count them.
501 Num_CC
:= Num_CC
+ 1;
506 Next_Component_Or_Discriminant
(Comp
);
509 -- We need to sort the component clauses on the basis of the
510 -- Position values in the clause, so we can group clauses with
511 -- the same Position together to determine the relevant machine
515 Comps
: array (0 .. Num_CC
) of Entity_Id
;
516 -- Array to collect component and discriminant entities. The
517 -- data starts at index 1, the 0'th entry is for the sort
520 function CP_Lt
(Op1
, Op2
: Natural) return Boolean;
521 -- Compare routine for Sort
523 procedure CP_Move
(From
: Natural; To
: Natural);
524 -- Move routine for Sort
526 package Sorting
is new GNAT
.Heap_Sort_G
(CP_Move
, CP_Lt
);
530 -- Start and stop positions in the component list of the set of
531 -- components with the same starting position (that constitute
532 -- components in a single machine scalar).
535 -- Maximum last bit value of any component in this set
538 -- Corresponding machine scalar size
544 function CP_Lt
(Op1
, Op2
: Natural) return Boolean is
546 return Position
(Component_Clause
(Comps
(Op1
))) <
547 Position
(Component_Clause
(Comps
(Op2
)));
554 procedure CP_Move
(From
: Natural; To
: Natural) is
556 Comps
(To
) := Comps
(From
);
559 -- Start of processing for Sort_CC
562 -- Collect the machine scalar relevant component clauses
565 Comp
:= First_Component_Or_Discriminant
(R
);
566 while Present
(Comp
) loop
568 CC
: constant Node_Id
:= Component_Clause
(Comp
);
571 -- Collect only component clauses whose last bit is less
572 -- than machine scalar size. Any component clause whose
573 -- last bit exceeds this value does not take part in
574 -- machine scalar layout considerations. The test for
575 -- Error_Posted makes sure we exclude component clauses
576 -- for which we already posted an error.
579 and then not Error_Posted
(Last_Bit
(CC
))
580 and then Static_Integer
(Last_Bit
(CC
)) <
581 Max_Machine_Scalar_Size
583 Num_CC
:= Num_CC
+ 1;
584 Comps
(Num_CC
) := Comp
;
588 Next_Component_Or_Discriminant
(Comp
);
591 -- Sort by ascending position number
593 Sorting
.Sort
(Num_CC
);
595 -- We now have all the components whose size does not exceed
596 -- the max machine scalar value, sorted by starting position.
597 -- In this loop we gather groups of clauses starting at the
598 -- same position, to process them in accordance with AI-133.
601 while Stop
< Num_CC
loop
606 (Last_Bit
(Component_Clause
(Comps
(Start
))));
607 while Stop
< Num_CC
loop
609 (Position
(Component_Clause
(Comps
(Stop
+ 1)))) =
611 (Position
(Component_Clause
(Comps
(Stop
))))
619 (Component_Clause
(Comps
(Stop
)))));
625 -- Now we have a group of component clauses from Start to
626 -- Stop whose positions are identical, and MaxL is the
627 -- maximum last bit value of any of these components.
629 -- We need to determine the corresponding machine scalar
630 -- size. This loop assumes that machine scalar sizes are
631 -- even, and that each possible machine scalar has twice
632 -- as many bits as the next smaller one.
634 MSS
:= Max_Machine_Scalar_Size
;
636 and then (MSS
/ 2) >= SSU
637 and then (MSS
/ 2) > MaxL
642 -- Here is where we fix up the Component_Bit_Offset value
643 -- to account for the reverse bit order. Some examples of
644 -- what needs to be done for the case of a machine scalar
647 -- First_Bit .. Last_Bit Component_Bit_Offset
659 -- The rule is that the first bit is obtained by subtracting
660 -- the old ending bit from machine scalar size - 1.
662 for C
in Start
.. Stop
loop
664 Comp
: constant Entity_Id
:= Comps
(C
);
665 CC
: constant Node_Id
:= Component_Clause
(Comp
);
667 LB
: constant Uint
:= Static_Integer
(Last_Bit
(CC
));
668 NFB
: constant Uint
:= MSS
- Uint_1
- LB
;
669 NLB
: constant Uint
:= NFB
+ Esize
(Comp
) - 1;
670 Pos
: constant Uint
:= Static_Integer
(Position
(CC
));
673 if Warn_On_Reverse_Bit_Order
then
674 Error_Msg_Uint_1
:= MSS
;
676 ("info: reverse bit order in machine " &
677 "scalar of length^?V?", First_Bit
(CC
));
678 Error_Msg_Uint_1
:= NFB
;
679 Error_Msg_Uint_2
:= NLB
;
681 if Bytes_Big_Endian
then
683 ("\big-endian range for component "
684 & "& is ^ .. ^?V?", First_Bit
(CC
), Comp
);
687 ("\little-endian range for component"
688 & "& is ^ .. ^?V?", First_Bit
(CC
), Comp
);
692 Set_Component_Bit_Offset
(Comp
, Pos
* SSU
+ NFB
);
693 Set_Normalized_First_Bit
(Comp
, NFB
mod SSU
);
700 end Adjust_Record_For_Reverse_Bit_Order
;
702 -------------------------------------
703 -- Alignment_Check_For_Size_Change --
704 -------------------------------------
706 procedure Alignment_Check_For_Size_Change
(Typ
: Entity_Id
; Size
: Uint
) is
708 -- If the alignment is known, and not set by a rep clause, and is
709 -- inconsistent with the size being set, then reset it to unknown,
710 -- we assume in this case that the size overrides the inherited
711 -- alignment, and that the alignment must be recomputed.
713 if Known_Alignment
(Typ
)
714 and then not Has_Alignment_Clause
(Typ
)
715 and then Size
mod (Alignment
(Typ
) * SSU
) /= 0
717 Init_Alignment
(Typ
);
719 end Alignment_Check_For_Size_Change
;
721 -------------------------------------
722 -- Analyze_Aspects_At_Freeze_Point --
723 -------------------------------------
725 procedure Analyze_Aspects_At_Freeze_Point
(E
: Entity_Id
) is
730 procedure Analyze_Aspect_Default_Value
(ASN
: Node_Id
);
731 -- This routine analyzes an Aspect_Default_[Component_]Value denoted by
732 -- the aspect specification node ASN.
734 procedure Inherit_Delayed_Rep_Aspects
(ASN
: Node_Id
);
735 -- As discussed in the spec of Aspects (see Aspect_Delay declaration),
736 -- a derived type can inherit aspects from its parent which have been
737 -- specified at the time of the derivation using an aspect, as in:
739 -- type A is range 1 .. 10
740 -- with Size => Not_Defined_Yet;
744 -- Not_Defined_Yet : constant := 64;
746 -- In this example, the Size of A is considered to be specified prior
747 -- to the derivation, and thus inherited, even though the value is not
748 -- known at the time of derivation. To deal with this, we use two entity
749 -- flags. The flag Has_Derived_Rep_Aspects is set in the parent type (A
750 -- here), and then the flag May_Inherit_Delayed_Rep_Aspects is set in
751 -- the derived type (B here). If this flag is set when the derived type
752 -- is frozen, then this procedure is called to ensure proper inheritance
753 -- of all delayed aspects from the parent type. The derived type is E,
754 -- the argument to Analyze_Aspects_At_Freeze_Point. ASN is the first
755 -- aspect specification node in the Rep_Item chain for the parent type.
757 procedure Make_Pragma_From_Boolean_Aspect
(ASN
: Node_Id
);
758 -- Given an aspect specification node ASN whose expression is an
759 -- optional Boolean, this routines creates the corresponding pragma
760 -- at the freezing point.
762 ----------------------------------
763 -- Analyze_Aspect_Default_Value --
764 ----------------------------------
766 procedure Analyze_Aspect_Default_Value
(ASN
: Node_Id
) is
767 Ent
: constant Entity_Id
:= Entity
(ASN
);
768 Expr
: constant Node_Id
:= Expression
(ASN
);
769 Id
: constant Node_Id
:= Identifier
(ASN
);
772 Error_Msg_Name_1
:= Chars
(Id
);
774 if not Is_Type
(Ent
) then
775 Error_Msg_N
("aspect% can only apply to a type", Id
);
778 elsif not Is_First_Subtype
(Ent
) then
779 Error_Msg_N
("aspect% cannot apply to subtype", Id
);
782 elsif A_Id
= Aspect_Default_Value
783 and then not Is_Scalar_Type
(Ent
)
785 Error_Msg_N
("aspect% can only be applied to scalar type", Id
);
788 elsif A_Id
= Aspect_Default_Component_Value
then
789 if not Is_Array_Type
(Ent
) then
790 Error_Msg_N
("aspect% can only be applied to array type", Id
);
793 elsif not Is_Scalar_Type
(Component_Type
(Ent
)) then
794 Error_Msg_N
("aspect% requires scalar components", Id
);
799 Set_Has_Default_Aspect
(Base_Type
(Ent
));
801 if Is_Scalar_Type
(Ent
) then
802 Set_Default_Aspect_Value
(Base_Type
(Ent
), Expr
);
804 Set_Default_Aspect_Component_Value
(Base_Type
(Ent
), Expr
);
806 end Analyze_Aspect_Default_Value
;
808 ---------------------------------
809 -- Inherit_Delayed_Rep_Aspects --
810 ---------------------------------
812 procedure Inherit_Delayed_Rep_Aspects
(ASN
: Node_Id
) is
813 P
: constant Entity_Id
:= Entity
(ASN
);
814 -- Entithy for parent type
817 -- Item from Rep_Item chain
822 -- Loop through delayed aspects for the parent type
825 while Present
(N
) loop
826 if Nkind
(N
) = N_Aspect_Specification
then
827 exit when Entity
(N
) /= P
;
829 if Is_Delayed_Aspect
(N
) then
830 A
:= Get_Aspect_Id
(Chars
(Identifier
(N
)));
832 -- Process delayed rep aspect. For Boolean attributes it is
833 -- not possible to cancel an attribute once set (the attempt
834 -- to use an aspect with xxx => False is an error) for a
835 -- derived type. So for those cases, we do not have to check
836 -- if a clause has been given for the derived type, since it
837 -- is harmless to set it again if it is already set.
843 when Aspect_Alignment
=>
844 if not Has_Alignment_Clause
(E
) then
845 Set_Alignment
(E
, Alignment
(P
));
850 when Aspect_Atomic
=>
851 if Is_Atomic
(P
) then
857 when Aspect_Atomic_Components
=>
858 if Has_Atomic_Components
(P
) then
859 Set_Has_Atomic_Components
(Base_Type
(E
));
864 when Aspect_Bit_Order
=>
865 if Is_Record_Type
(E
)
866 and then No
(Get_Attribute_Definition_Clause
867 (E
, Attribute_Bit_Order
))
868 and then Reverse_Bit_Order
(P
)
870 Set_Reverse_Bit_Order
(Base_Type
(E
));
875 when Aspect_Component_Size
=>
877 and then not Has_Component_Size_Clause
(E
)
880 (Base_Type
(E
), Component_Size
(P
));
885 when Aspect_Machine_Radix
=>
886 if Is_Decimal_Fixed_Point_Type
(E
)
887 and then not Has_Machine_Radix_Clause
(E
)
889 Set_Machine_Radix_10
(E
, Machine_Radix_10
(P
));
892 -- Object_Size (also Size which also sets Object_Size)
894 when Aspect_Object_Size | Aspect_Size
=>
895 if not Has_Size_Clause
(E
)
897 No
(Get_Attribute_Definition_Clause
898 (E
, Attribute_Object_Size
))
900 Set_Esize
(E
, Esize
(P
));
906 if not Is_Packed
(E
) then
907 Set_Is_Packed
(Base_Type
(E
));
909 if Is_Bit_Packed_Array
(P
) then
910 Set_Is_Bit_Packed_Array
(Base_Type
(E
));
911 Set_Packed_Array_Impl_Type
912 (E
, Packed_Array_Impl_Type
(P
));
916 -- Scalar_Storage_Order
918 when Aspect_Scalar_Storage_Order
=>
919 if (Is_Record_Type
(E
) or else Is_Array_Type
(E
))
920 and then No
(Get_Attribute_Definition_Clause
921 (E
, Attribute_Scalar_Storage_Order
))
922 and then Reverse_Storage_Order
(P
)
924 Set_Reverse_Storage_Order
(Base_Type
(E
));
926 -- Clear default SSO indications, since the aspect
927 -- overrides the default.
929 Set_SSO_Set_Low_By_Default
(Base_Type
(E
), False);
930 Set_SSO_Set_High_By_Default
(Base_Type
(E
), False);
936 if Is_Fixed_Point_Type
(E
)
937 and then not Has_Small_Clause
(E
)
939 Set_Small_Value
(E
, Small_Value
(P
));
944 when Aspect_Storage_Size
=>
945 if (Is_Access_Type
(E
) or else Is_Task_Type
(E
))
946 and then not Has_Storage_Size_Clause
(E
)
948 Set_Storage_Size_Variable
949 (Base_Type
(E
), Storage_Size_Variable
(P
));
954 when Aspect_Value_Size
=>
956 -- Value_Size is never inherited, it is either set by
957 -- default, or it is explicitly set for the derived
958 -- type. So nothing to do here.
964 when Aspect_Volatile
=>
965 if Is_Volatile
(P
) then
969 -- Volatile_Full_Access
971 when Aspect_Volatile_Full_Access
=>
972 if Is_Volatile_Full_Access
(P
) then
973 Set_Is_Volatile_Full_Access
(E
);
976 -- Volatile_Components
978 when Aspect_Volatile_Components
=>
979 if Has_Volatile_Components
(P
) then
980 Set_Has_Volatile_Components
(Base_Type
(E
));
983 -- That should be all the Rep Aspects
986 pragma Assert
(Aspect_Delay
(A_Id
) /= Rep_Aspect
);
993 N
:= Next_Rep_Item
(N
);
995 end Inherit_Delayed_Rep_Aspects
;
997 -------------------------------------
998 -- Make_Pragma_From_Boolean_Aspect --
999 -------------------------------------
1001 procedure Make_Pragma_From_Boolean_Aspect
(ASN
: Node_Id
) is
1002 Ident
: constant Node_Id
:= Identifier
(ASN
);
1003 A_Name
: constant Name_Id
:= Chars
(Ident
);
1004 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(A_Name
);
1005 Ent
: constant Entity_Id
:= Entity
(ASN
);
1006 Expr
: constant Node_Id
:= Expression
(ASN
);
1007 Loc
: constant Source_Ptr
:= Sloc
(ASN
);
1011 procedure Check_False_Aspect_For_Derived_Type
;
1012 -- This procedure checks for the case of a false aspect for a derived
1013 -- type, which improperly tries to cancel an aspect inherited from
1016 -----------------------------------------
1017 -- Check_False_Aspect_For_Derived_Type --
1018 -----------------------------------------
1020 procedure Check_False_Aspect_For_Derived_Type
is
1024 -- We are only checking derived types
1026 if not Is_Derived_Type
(E
) then
1030 Par
:= Nearest_Ancestor
(E
);
1033 when Aspect_Atomic | Aspect_Shared
=>
1034 if not Is_Atomic
(Par
) then
1038 when Aspect_Atomic_Components
=>
1039 if not Has_Atomic_Components
(Par
) then
1043 when Aspect_Discard_Names
=>
1044 if not Discard_Names
(Par
) then
1049 if not Is_Packed
(Par
) then
1053 when Aspect_Unchecked_Union
=>
1054 if not Is_Unchecked_Union
(Par
) then
1058 when Aspect_Volatile
=>
1059 if not Is_Volatile
(Par
) then
1063 when Aspect_Volatile_Components
=>
1064 if not Has_Volatile_Components
(Par
) then
1068 when Aspect_Volatile_Full_Access
=>
1069 if not Is_Volatile_Full_Access
(Par
) then
1077 -- Fall through means we are canceling an inherited aspect
1079 Error_Msg_Name_1
:= A_Name
;
1081 ("derived type& inherits aspect%, cannot cancel", Expr
, E
);
1082 end Check_False_Aspect_For_Derived_Type
;
1084 -- Start of processing for Make_Pragma_From_Boolean_Aspect
1087 -- Note that we know Expr is present, because for a missing Expr
1088 -- argument, we knew it was True and did not need to delay the
1089 -- evaluation to the freeze point.
1091 if Is_False
(Static_Boolean
(Expr
)) then
1092 Check_False_Aspect_For_Derived_Type
;
1097 Pragma_Argument_Associations
=> New_List
(
1098 Make_Pragma_Argument_Association
(Sloc
(Ident
),
1099 Expression
=> New_Occurrence_Of
(Ent
, Sloc
(Ident
)))),
1101 Pragma_Identifier
=>
1102 Make_Identifier
(Sloc
(Ident
), Chars
(Ident
)));
1104 Set_From_Aspect_Specification
(Prag
, True);
1105 Set_Corresponding_Aspect
(Prag
, ASN
);
1106 Set_Aspect_Rep_Item
(ASN
, Prag
);
1107 Set_Is_Delayed_Aspect
(Prag
);
1108 Set_Parent
(Prag
, ASN
);
1110 end Make_Pragma_From_Boolean_Aspect
;
1112 -- Start of processing for Analyze_Aspects_At_Freeze_Point
1115 -- Must be visible in current scope
1117 if not Scope_Within_Or_Same
(Current_Scope
, Scope
(E
)) then
1121 -- Look for aspect specification entries for this entity
1123 ASN
:= First_Rep_Item
(E
);
1124 while Present
(ASN
) loop
1125 if Nkind
(ASN
) = N_Aspect_Specification
then
1126 exit when Entity
(ASN
) /= E
;
1128 if Is_Delayed_Aspect
(ASN
) then
1129 A_Id
:= Get_Aspect_Id
(ASN
);
1133 -- For aspects whose expression is an optional Boolean, make
1134 -- the corresponding pragma at the freeze point.
1136 when Boolean_Aspects |
1137 Library_Unit_Aspects
=>
1138 Make_Pragma_From_Boolean_Aspect
(ASN
);
1140 -- Special handling for aspects that don't correspond to
1141 -- pragmas/attributes.
1143 when Aspect_Default_Value |
1144 Aspect_Default_Component_Value
=>
1146 -- Do not inherit aspect for anonymous base type of a
1147 -- scalar or array type, because they apply to the first
1148 -- subtype of the type, and will be processed when that
1149 -- first subtype is frozen.
1151 if Is_Derived_Type
(E
)
1152 and then not Comes_From_Source
(E
)
1153 and then E
/= First_Subtype
(E
)
1157 Analyze_Aspect_Default_Value
(ASN
);
1160 -- Ditto for iterator aspects, because the corresponding
1161 -- attributes may not have been analyzed yet.
1163 when Aspect_Constant_Indexing |
1164 Aspect_Variable_Indexing |
1165 Aspect_Default_Iterator |
1166 Aspect_Iterator_Element
=>
1167 Analyze
(Expression
(ASN
));
1169 if Etype
(Expression
(ASN
)) = Any_Type
then
1171 ("\aspect must be fully defined before & is frozen",
1175 when Aspect_Iterable
=>
1176 Validate_Iterable_Aspect
(E
, ASN
);
1182 Ritem
:= Aspect_Rep_Item
(ASN
);
1184 if Present
(Ritem
) then
1190 Next_Rep_Item
(ASN
);
1193 -- This is where we inherit delayed rep aspects from our parent. Note
1194 -- that if we fell out of the above loop with ASN non-empty, it means
1195 -- we hit an aspect for an entity other than E, and it must be the
1196 -- type from which we were derived.
1198 if May_Inherit_Delayed_Rep_Aspects
(E
) then
1199 Inherit_Delayed_Rep_Aspects
(ASN
);
1201 end Analyze_Aspects_At_Freeze_Point
;
1203 -----------------------------------
1204 -- Analyze_Aspect_Specifications --
1205 -----------------------------------
1207 procedure Analyze_Aspect_Specifications
(N
: Node_Id
; E
: Entity_Id
) is
1208 procedure Decorate
(Asp
: Node_Id
; Prag
: Node_Id
);
1209 -- Establish linkages between an aspect and its corresponding pragma
1211 procedure Insert_Pragma
1213 Is_Instance
: Boolean := False);
1214 -- Subsidiary to the analysis of aspects
1221 -- Initial_Condition
1230 -- Insert pragma Prag such that it mimics the placement of a source
1231 -- pragma of the same kind. Flag Is_Generic should be set when the
1232 -- context denotes a generic instance.
1238 procedure Decorate
(Asp
: Node_Id
; Prag
: Node_Id
) is
1240 Set_Aspect_Rep_Item
(Asp
, Prag
);
1241 Set_Corresponding_Aspect
(Prag
, Asp
);
1242 Set_From_Aspect_Specification
(Prag
);
1243 Set_Parent
(Prag
, Asp
);
1250 procedure Insert_Pragma
1252 Is_Instance
: Boolean := False)
1258 Inserted
: Boolean := False;
1261 -- When the aspect appears on an entry, package, protected unit,
1262 -- subprogram, or task unit body, insert the generated pragma at the
1263 -- top of the body declarations to emulate the behavior of a source
1266 -- package body Pack with Aspect is
1268 -- package body Pack is
1271 if Nkind_In
(N
, N_Entry_Body
,
1277 Decls
:= Declarations
(N
);
1281 Set_Declarations
(N
, Decls
);
1284 Prepend_To
(Decls
, Prag
);
1286 -- When the aspect is associated with a [generic] package declaration
1287 -- insert the generated pragma at the top of the visible declarations
1288 -- to emulate the behavior of a source pragma.
1290 -- package Pack with Aspect is
1295 elsif Nkind_In
(N
, N_Generic_Package_Declaration
,
1296 N_Package_Declaration
)
1298 Decls
:= Visible_Declarations
(Specification
(N
));
1302 Set_Visible_Declarations
(Specification
(N
), Decls
);
1305 -- The visible declarations of a generic instance have the
1306 -- following structure:
1308 -- <renamings of generic formals>
1309 -- <renamings of internally-generated spec and body>
1310 -- <first source declaration>
1312 -- Insert the pragma before the first source declaration by
1313 -- skipping the instance "header" to ensure proper visibility of
1317 Decl
:= First
(Decls
);
1318 while Present
(Decl
) loop
1319 if Comes_From_Source
(Decl
) then
1320 Insert_Before
(Decl
, Prag
);
1328 -- The pragma is placed after the instance "header"
1330 if not Inserted
then
1331 Append_To
(Decls
, Prag
);
1334 -- Otherwise this is not a generic instance
1337 Prepend_To
(Decls
, Prag
);
1340 -- When the aspect is associated with a protected unit declaration,
1341 -- insert the generated pragma at the top of the visible declarations
1342 -- the emulate the behavior of a source pragma.
1344 -- protected [type] Prot with Aspect is
1346 -- protected [type] Prot is
1349 elsif Nkind
(N
) = N_Protected_Type_Declaration
then
1350 Def
:= Protected_Definition
(N
);
1354 Make_Protected_Definition
(Sloc
(N
),
1355 Visible_Declarations
=> New_List
,
1356 End_Label
=> Empty
);
1358 Set_Protected_Definition
(N
, Def
);
1361 Decls
:= Visible_Declarations
(Def
);
1365 Set_Visible_Declarations
(Def
, Decls
);
1368 Prepend_To
(Decls
, Prag
);
1370 -- When the aspect is associated with a task unit declaration, insert
1371 -- insert the generated pragma at the top of the visible declarations
1372 -- the emulate the behavior of a source pragma.
1374 -- task [type] Prot with Aspect is
1376 -- task [type] Prot is
1379 elsif Nkind
(N
) = N_Task_Type_Declaration
then
1380 Def
:= Task_Definition
(N
);
1384 Make_Task_Definition
(Sloc
(N
),
1385 Visible_Declarations
=> New_List
,
1386 End_Label
=> Empty
);
1388 Set_Task_Definition
(N
, Def
);
1391 Decls
:= Visible_Declarations
(Def
);
1395 Set_Visible_Declarations
(Def
, Decls
);
1398 Prepend_To
(Decls
, Prag
);
1400 -- When the context is a library unit, the pragma is added to the
1401 -- Pragmas_After list.
1403 elsif Nkind
(Parent
(N
)) = N_Compilation_Unit
then
1404 Aux
:= Aux_Decls_Node
(Parent
(N
));
1406 if No
(Pragmas_After
(Aux
)) then
1407 Set_Pragmas_After
(Aux
, New_List
);
1410 Prepend
(Prag
, Pragmas_After
(Aux
));
1412 -- Default, the pragma is inserted after the context
1415 Insert_After
(N
, Prag
);
1425 L
: constant List_Id
:= Aspect_Specifications
(N
);
1427 Ins_Node
: Node_Id
:= N
;
1428 -- Insert pragmas/attribute definition clause after this node when no
1429 -- delayed analysis is required.
1431 -- Start of processing for Analyze_Aspect_Specifications
1433 -- The general processing involves building an attribute definition
1434 -- clause or a pragma node that corresponds to the aspect. Then in order
1435 -- to delay the evaluation of this aspect to the freeze point, we attach
1436 -- the corresponding pragma/attribute definition clause to the aspect
1437 -- specification node, which is then placed in the Rep Item chain. In
1438 -- this case we mark the entity by setting the flag Has_Delayed_Aspects
1439 -- and we evaluate the rep item at the freeze point. When the aspect
1440 -- doesn't have a corresponding pragma/attribute definition clause, then
1441 -- its analysis is simply delayed at the freeze point.
1443 -- Some special cases don't require delay analysis, thus the aspect is
1444 -- analyzed right now.
1446 -- Note that there is a special handling for Pre, Post, Test_Case,
1447 -- Contract_Cases aspects. In these cases, we do not have to worry
1448 -- about delay issues, since the pragmas themselves deal with delay
1449 -- of visibility for the expression analysis. Thus, we just insert
1450 -- the pragma after the node N.
1453 pragma Assert
(Present
(L
));
1455 -- Loop through aspects
1457 Aspect
:= First
(L
);
1458 Aspect_Loop
: while Present
(Aspect
) loop
1459 Analyze_One_Aspect
: declare
1460 Expr
: constant Node_Id
:= Expression
(Aspect
);
1461 Id
: constant Node_Id
:= Identifier
(Aspect
);
1462 Loc
: constant Source_Ptr
:= Sloc
(Aspect
);
1463 Nam
: constant Name_Id
:= Chars
(Id
);
1464 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Nam
);
1467 Delay_Required
: Boolean;
1468 -- Set False if delay is not required
1470 Eloc
: Source_Ptr
:= No_Location
;
1471 -- Source location of expression, modified when we split PPC's. It
1472 -- is set below when Expr is present.
1474 procedure Analyze_Aspect_External_Or_Link_Name
;
1475 -- Perform analysis of the External_Name or Link_Name aspects
1477 procedure Analyze_Aspect_Implicit_Dereference
;
1478 -- Perform analysis of the Implicit_Dereference aspects
1480 procedure Make_Aitem_Pragma
1481 (Pragma_Argument_Associations
: List_Id
;
1482 Pragma_Name
: Name_Id
);
1483 -- This is a wrapper for Make_Pragma used for converting aspects
1484 -- to pragmas. It takes care of Sloc (set from Loc) and building
1485 -- the pragma identifier from the given name. In addition the
1486 -- flags Class_Present and Split_PPC are set from the aspect
1487 -- node, as well as Is_Ignored. This routine also sets the
1488 -- From_Aspect_Specification in the resulting pragma node to
1489 -- True, and sets Corresponding_Aspect to point to the aspect.
1490 -- The resulting pragma is assigned to Aitem.
1492 ------------------------------------------
1493 -- Analyze_Aspect_External_Or_Link_Name --
1494 ------------------------------------------
1496 procedure Analyze_Aspect_External_Or_Link_Name
is
1498 -- Verify that there is an Import/Export aspect defined for the
1499 -- entity. The processing of that aspect in turn checks that
1500 -- there is a Convention aspect declared. The pragma is
1501 -- constructed when processing the Convention aspect.
1508 while Present
(A
) loop
1509 exit when Nam_In
(Chars
(Identifier
(A
)), Name_Export
,
1516 ("missing Import/Export for Link/External name",
1520 end Analyze_Aspect_External_Or_Link_Name
;
1522 -----------------------------------------
1523 -- Analyze_Aspect_Implicit_Dereference --
1524 -----------------------------------------
1526 procedure Analyze_Aspect_Implicit_Dereference
is
1528 Parent_Disc
: Entity_Id
;
1531 if not Is_Type
(E
) or else not Has_Discriminants
(E
) then
1533 ("aspect must apply to a type with discriminants", Expr
);
1535 elsif not Is_Entity_Name
(Expr
) then
1537 ("aspect must name a discriminant of current type", Expr
);
1540 Disc
:= First_Discriminant
(E
);
1541 while Present
(Disc
) loop
1542 if Chars
(Expr
) = Chars
(Disc
)
1543 and then Ekind
(Etype
(Disc
)) =
1544 E_Anonymous_Access_Type
1546 Set_Has_Implicit_Dereference
(E
);
1547 Set_Has_Implicit_Dereference
(Disc
);
1551 Next_Discriminant
(Disc
);
1554 -- Error if no proper access discriminant
1558 ("not an access discriminant of&", Expr
, E
);
1563 -- For a type extension, check whether parent has a
1564 -- reference discriminant, to verify that use is proper.
1566 if Is_Derived_Type
(E
)
1567 and then Has_Discriminants
(Etype
(E
))
1569 Parent_Disc
:= Get_Reference_Discriminant
(Etype
(E
));
1571 if Present
(Parent_Disc
)
1572 and then Corresponding_Discriminant
(Disc
) /= Parent_Disc
1574 Error_Msg_N
("reference discriminant does not match " &
1575 "discriminant of parent type", Expr
);
1578 end Analyze_Aspect_Implicit_Dereference
;
1580 -----------------------
1581 -- Make_Aitem_Pragma --
1582 -----------------------
1584 procedure Make_Aitem_Pragma
1585 (Pragma_Argument_Associations
: List_Id
;
1586 Pragma_Name
: Name_Id
)
1588 Args
: List_Id
:= Pragma_Argument_Associations
;
1591 -- We should never get here if aspect was disabled
1593 pragma Assert
(not Is_Disabled
(Aspect
));
1595 -- Certain aspects allow for an optional name or expression. Do
1596 -- not generate a pragma with empty argument association list.
1598 if No
(Args
) or else No
(Expression
(First
(Args
))) then
1606 Pragma_Argument_Associations
=> Args
,
1607 Pragma_Identifier
=>
1608 Make_Identifier
(Sloc
(Id
), Pragma_Name
),
1609 Class_Present
=> Class_Present
(Aspect
),
1610 Split_PPC
=> Split_PPC
(Aspect
));
1612 -- Set additional semantic fields
1614 if Is_Ignored
(Aspect
) then
1615 Set_Is_Ignored
(Aitem
);
1616 elsif Is_Checked
(Aspect
) then
1617 Set_Is_Checked
(Aitem
);
1620 Set_Corresponding_Aspect
(Aitem
, Aspect
);
1621 Set_From_Aspect_Specification
(Aitem
);
1622 end Make_Aitem_Pragma
;
1624 -- Start of processing for Analyze_One_Aspect
1627 -- Skip aspect if already analyzed, to avoid looping in some cases
1629 if Analyzed
(Aspect
) then
1633 -- Skip looking at aspect if it is totally disabled. Just mark it
1634 -- as such for later reference in the tree. This also sets the
1635 -- Is_Ignored and Is_Checked flags appropriately.
1637 Check_Applicable_Policy
(Aspect
);
1639 if Is_Disabled
(Aspect
) then
1643 -- Set the source location of expression, used in the case of
1644 -- a failed precondition/postcondition or invariant. Note that
1645 -- the source location of the expression is not usually the best
1646 -- choice here. For example, it gets located on the last AND
1647 -- keyword in a chain of boolean expressiond AND'ed together.
1648 -- It is best to put the message on the first character of the
1649 -- assertion, which is the effect of the First_Node call here.
1651 if Present
(Expr
) then
1652 Eloc
:= Sloc
(First_Node
(Expr
));
1655 -- Check restriction No_Implementation_Aspect_Specifications
1657 if Implementation_Defined_Aspect
(A_Id
) then
1659 (No_Implementation_Aspect_Specifications
, Aspect
);
1662 -- Check restriction No_Specification_Of_Aspect
1664 Check_Restriction_No_Specification_Of_Aspect
(Aspect
);
1666 -- Mark aspect analyzed (actual analysis is delayed till later)
1668 Set_Analyzed
(Aspect
);
1669 Set_Entity
(Aspect
, E
);
1670 Ent
:= New_Occurrence_Of
(E
, Sloc
(Id
));
1672 -- Check for duplicate aspect. Note that the Comes_From_Source
1673 -- test allows duplicate Pre/Post's that we generate internally
1674 -- to escape being flagged here.
1676 if No_Duplicates_Allowed
(A_Id
) then
1678 while Anod
/= Aspect
loop
1679 if Comes_From_Source
(Aspect
)
1680 and then Same_Aspect
(A_Id
, Get_Aspect_Id
(Anod
))
1682 Error_Msg_Name_1
:= Nam
;
1683 Error_Msg_Sloc
:= Sloc
(Anod
);
1685 -- Case of same aspect specified twice
1687 if Class_Present
(Anod
) = Class_Present
(Aspect
) then
1688 if not Class_Present
(Anod
) then
1690 ("aspect% for & previously given#",
1694 ("aspect `%''Class` for & previously given#",
1704 -- Check some general restrictions on language defined aspects
1706 if not Implementation_Defined_Aspect
(A_Id
) then
1707 Error_Msg_Name_1
:= Nam
;
1709 -- Not allowed for renaming declarations
1711 if Nkind
(N
) in N_Renaming_Declaration
then
1713 ("aspect % not allowed for renaming declaration",
1717 -- Not allowed for formal type declarations
1719 if Nkind
(N
) = N_Formal_Type_Declaration
then
1721 ("aspect % not allowed for formal type declaration",
1726 -- Copy expression for later processing by the procedures
1727 -- Check_Aspect_At_[Freeze_Point | End_Of_Declarations]
1729 Set_Entity
(Id
, New_Copy_Tree
(Expr
));
1731 -- Set Delay_Required as appropriate to aspect
1733 case Aspect_Delay
(A_Id
) is
1734 when Always_Delay
=>
1735 Delay_Required
:= True;
1738 Delay_Required
:= False;
1742 -- If expression has the form of an integer literal, then
1743 -- do not delay, since we know the value cannot change.
1744 -- This optimization catches most rep clause cases.
1746 -- For Boolean aspects, don't delay if no expression
1748 if A_Id
in Boolean_Aspects
and then No
(Expr
) then
1749 Delay_Required
:= False;
1751 -- For non-Boolean aspects, don't delay if integer literal
1753 elsif A_Id
not in Boolean_Aspects
1754 and then Present
(Expr
)
1755 and then Nkind
(Expr
) = N_Integer_Literal
1757 Delay_Required
:= False;
1759 -- All other cases are delayed
1762 Delay_Required
:= True;
1763 Set_Has_Delayed_Rep_Aspects
(E
);
1767 -- Processing based on specific aspect
1770 when Aspect_Unimplemented
=>
1771 null; -- ??? temp for now
1773 -- No_Aspect should be impossible
1776 raise Program_Error
;
1778 -- Case 1: Aspects corresponding to attribute definition
1781 when Aspect_Address |
1784 Aspect_Component_Size |
1785 Aspect_Constant_Indexing |
1786 Aspect_Default_Iterator |
1787 Aspect_Dispatching_Domain |
1788 Aspect_External_Tag |
1791 Aspect_Iterator_Element |
1792 Aspect_Machine_Radix |
1793 Aspect_Object_Size |
1796 Aspect_Scalar_Storage_Order |
1799 Aspect_Simple_Storage_Pool |
1800 Aspect_Storage_Pool |
1801 Aspect_Stream_Size |
1803 Aspect_Variable_Indexing |
1806 -- Indexing aspects apply only to tagged type
1808 if (A_Id
= Aspect_Constant_Indexing
1810 A_Id
= Aspect_Variable_Indexing
)
1811 and then not (Is_Type
(E
)
1812 and then Is_Tagged_Type
(E
))
1815 ("indexing aspect can only apply to a tagged type",
1820 -- For the case of aspect Address, we don't consider that we
1821 -- know the entity is never set in the source, since it is
1822 -- is likely aliasing is occurring.
1824 -- Note: one might think that the analysis of the resulting
1825 -- attribute definition clause would take care of that, but
1826 -- that's not the case since it won't be from source.
1828 if A_Id
= Aspect_Address
then
1829 Set_Never_Set_In_Source
(E
, False);
1832 -- Correctness of the profile of a stream operation is
1833 -- verified at the freeze point, but we must detect the
1834 -- illegal specification of this aspect for a subtype now,
1835 -- to prevent malformed rep_item chains.
1837 if A_Id
= Aspect_Input
or else
1838 A_Id
= Aspect_Output
or else
1839 A_Id
= Aspect_Read
or else
1842 if not Is_First_Subtype
(E
) then
1844 ("local name must be a first subtype", Aspect
);
1847 -- If stream aspect applies to the class-wide type,
1848 -- the generated attribute definition applies to the
1849 -- class-wide type as well.
1851 elsif Class_Present
(Aspect
) then
1853 Make_Attribute_Reference
(Loc
,
1855 Attribute_Name
=> Name_Class
);
1859 -- Construct the attribute definition clause
1862 Make_Attribute_Definition_Clause
(Loc
,
1864 Chars
=> Chars
(Id
),
1865 Expression
=> Relocate_Node
(Expr
));
1867 -- If the address is specified, then we treat the entity as
1868 -- referenced, to avoid spurious warnings. This is analogous
1869 -- to what is done with an attribute definition clause, but
1870 -- here we don't want to generate a reference because this
1871 -- is the point of definition of the entity.
1873 if A_Id
= Aspect_Address
then
1877 -- Case 2: Aspects corresponding to pragmas
1879 -- Case 2a: Aspects corresponding to pragmas with two
1880 -- arguments, where the first argument is a local name
1881 -- referring to the entity, and the second argument is the
1882 -- aspect definition expression.
1884 -- Linker_Section/Suppress/Unsuppress
1886 when Aspect_Linker_Section |
1888 Aspect_Unsuppress
=>
1891 (Pragma_Argument_Associations
=> New_List
(
1892 Make_Pragma_Argument_Association
(Loc
,
1893 Expression
=> New_Occurrence_Of
(E
, Loc
)),
1894 Make_Pragma_Argument_Association
(Sloc
(Expr
),
1895 Expression
=> Relocate_Node
(Expr
))),
1896 Pragma_Name
=> Chars
(Id
));
1900 -- Corresponds to pragma Implemented, construct the pragma
1902 when Aspect_Synchronization
=>
1904 (Pragma_Argument_Associations
=> New_List
(
1905 Make_Pragma_Argument_Association
(Loc
,
1906 Expression
=> New_Occurrence_Of
(E
, Loc
)),
1907 Make_Pragma_Argument_Association
(Sloc
(Expr
),
1908 Expression
=> Relocate_Node
(Expr
))),
1909 Pragma_Name
=> Name_Implemented
);
1913 when Aspect_Attach_Handler
=>
1915 (Pragma_Argument_Associations
=> New_List
(
1916 Make_Pragma_Argument_Association
(Sloc
(Ent
),
1918 Make_Pragma_Argument_Association
(Sloc
(Expr
),
1919 Expression
=> Relocate_Node
(Expr
))),
1920 Pragma_Name
=> Name_Attach_Handler
);
1922 -- We need to insert this pragma into the tree to get proper
1923 -- processing and to look valid from a placement viewpoint.
1925 Insert_Pragma
(Aitem
);
1928 -- Dynamic_Predicate, Predicate, Static_Predicate
1930 when Aspect_Dynamic_Predicate |
1932 Aspect_Static_Predicate
=>
1934 -- These aspects apply only to subtypes
1936 if not Is_Type
(E
) then
1938 ("predicate can only be specified for a subtype",
1942 elsif Is_Incomplete_Type
(E
) then
1944 ("predicate cannot apply to incomplete view", Aspect
);
1948 -- Construct the pragma (always a pragma Predicate, with
1949 -- flags recording whether it is static/dynamic). We also
1950 -- set flags recording this in the type itself.
1953 (Pragma_Argument_Associations
=> New_List
(
1954 Make_Pragma_Argument_Association
(Sloc
(Ent
),
1956 Make_Pragma_Argument_Association
(Sloc
(Expr
),
1957 Expression
=> Relocate_Node
(Expr
))),
1958 Pragma_Name
=> Name_Predicate
);
1960 -- Mark type has predicates, and remember what kind of
1961 -- aspect lead to this predicate (we need this to access
1962 -- the right set of check policies later on).
1964 Set_Has_Predicates
(E
);
1966 if A_Id
= Aspect_Dynamic_Predicate
then
1967 Set_Has_Dynamic_Predicate_Aspect
(E
);
1968 elsif A_Id
= Aspect_Static_Predicate
then
1969 Set_Has_Static_Predicate_Aspect
(E
);
1972 -- If the type is private, indicate that its completion
1973 -- has a freeze node, because that is the one that will
1974 -- be visible at freeze time.
1976 if Is_Private_Type
(E
) and then Present
(Full_View
(E
)) then
1977 Set_Has_Predicates
(Full_View
(E
));
1979 if A_Id
= Aspect_Dynamic_Predicate
then
1980 Set_Has_Dynamic_Predicate_Aspect
(Full_View
(E
));
1981 elsif A_Id
= Aspect_Static_Predicate
then
1982 Set_Has_Static_Predicate_Aspect
(Full_View
(E
));
1985 Set_Has_Delayed_Aspects
(Full_View
(E
));
1986 Ensure_Freeze_Node
(Full_View
(E
));
1989 -- Predicate_Failure
1991 when Aspect_Predicate_Failure
=>
1993 -- This aspect applies only to subtypes
1995 if not Is_Type
(E
) then
1997 ("predicate can only be specified for a subtype",
2001 elsif Is_Incomplete_Type
(E
) then
2003 ("predicate cannot apply to incomplete view", Aspect
);
2007 -- Construct the pragma
2010 (Pragma_Argument_Associations
=> New_List
(
2011 Make_Pragma_Argument_Association
(Sloc
(Ent
),
2013 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2014 Expression
=> Relocate_Node
(Expr
))),
2015 Pragma_Name
=> Name_Predicate_Failure
);
2017 Set_Has_Predicates
(E
);
2019 -- If the type is private, indicate that its completion
2020 -- has a freeze node, because that is the one that will
2021 -- be visible at freeze time.
2023 if Is_Private_Type
(E
) and then Present
(Full_View
(E
)) then
2024 Set_Has_Predicates
(Full_View
(E
));
2025 Set_Has_Delayed_Aspects
(Full_View
(E
));
2026 Ensure_Freeze_Node
(Full_View
(E
));
2029 -- Case 2b: Aspects corresponding to pragmas with two
2030 -- arguments, where the second argument is a local name
2031 -- referring to the entity, and the first argument is the
2032 -- aspect definition expression.
2036 when Aspect_Convention
=>
2038 -- The aspect may be part of the specification of an import
2039 -- or export pragma. Scan the aspect list to gather the
2040 -- other components, if any. The name of the generated
2041 -- pragma is one of Convention/Import/Export.
2044 Args
: constant List_Id
:= New_List
(
2045 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2046 Expression
=> Relocate_Node
(Expr
)),
2047 Make_Pragma_Argument_Association
(Sloc
(Ent
),
2048 Expression
=> Ent
));
2050 Imp_Exp_Seen
: Boolean := False;
2051 -- Flag set when aspect Import or Export has been seen
2053 Imp_Seen
: Boolean := False;
2054 -- Flag set when aspect Import has been seen
2058 Extern_Arg
: Node_Id
;
2063 Extern_Arg
:= Empty
;
2065 Prag_Nam
:= Chars
(Id
);
2068 while Present
(Asp
) loop
2069 Asp_Nam
:= Chars
(Identifier
(Asp
));
2071 -- Aspects Import and Export take precedence over
2072 -- aspect Convention. As a result the generated pragma
2073 -- must carry the proper interfacing aspect's name.
2075 if Nam_In
(Asp_Nam
, Name_Import
, Name_Export
) then
2076 if Imp_Exp_Seen
then
2077 Error_Msg_N
("conflicting", Asp
);
2079 Imp_Exp_Seen
:= True;
2081 if Asp_Nam
= Name_Import
then
2086 Prag_Nam
:= Asp_Nam
;
2088 -- Aspect External_Name adds an extra argument to the
2089 -- generated pragma.
2091 elsif Asp_Nam
= Name_External_Name
then
2093 Make_Pragma_Argument_Association
(Loc
,
2095 Expression
=> Relocate_Node
(Expression
(Asp
)));
2097 -- Aspect Link_Name adds an extra argument to the
2098 -- generated pragma.
2100 elsif Asp_Nam
= Name_Link_Name
then
2102 Make_Pragma_Argument_Association
(Loc
,
2104 Expression
=> Relocate_Node
(Expression
(Asp
)));
2110 -- Assemble the full argument list
2112 if Present
(Extern_Arg
) then
2113 Append_To
(Args
, Extern_Arg
);
2116 if Present
(Link_Arg
) then
2117 Append_To
(Args
, Link_Arg
);
2121 (Pragma_Argument_Associations
=> Args
,
2122 Pragma_Name
=> Prag_Nam
);
2124 -- Store the generated pragma Import in the related
2127 if Imp_Seen
and then Is_Subprogram
(E
) then
2128 Set_Import_Pragma
(E
, Aitem
);
2132 -- CPU, Interrupt_Priority, Priority
2134 -- These three aspects can be specified for a subprogram spec
2135 -- or body, in which case we analyze the expression and export
2136 -- the value of the aspect.
2138 -- Previously, we generated an equivalent pragma for bodies
2139 -- (note that the specs cannot contain these pragmas). The
2140 -- pragma was inserted ahead of local declarations, rather than
2141 -- after the body. This leads to a certain duplication between
2142 -- the processing performed for the aspect and the pragma, but
2143 -- given the straightforward handling required it is simpler
2144 -- to duplicate than to translate the aspect in the spec into
2145 -- a pragma in the declarative part of the body.
2148 Aspect_Interrupt_Priority |
2151 if Nkind_In
(N
, N_Subprogram_Body
,
2152 N_Subprogram_Declaration
)
2154 -- Analyze the aspect expression
2156 Analyze_And_Resolve
(Expr
, Standard_Integer
);
2158 -- Interrupt_Priority aspect not allowed for main
2159 -- subprograms. RM D.1 does not forbid this explicitly,
2160 -- but RM J.15.11(6/3) does not permit pragma
2161 -- Interrupt_Priority for subprograms.
2163 if A_Id
= Aspect_Interrupt_Priority
then
2165 ("Interrupt_Priority aspect cannot apply to "
2166 & "subprogram", Expr
);
2168 -- The expression must be static
2170 elsif not Is_OK_Static_Expression
(Expr
) then
2171 Flag_Non_Static_Expr
2172 ("aspect requires static expression!", Expr
);
2174 -- Check whether this is the main subprogram. Issue a
2175 -- warning only if it is obviously not a main program
2176 -- (when it has parameters or when the subprogram is
2177 -- within a package).
2179 elsif Present
(Parameter_Specifications
2180 (Specification
(N
)))
2181 or else not Is_Compilation_Unit
(Defining_Entity
(N
))
2183 -- See RM D.1(14/3) and D.16(12/3)
2186 ("aspect applied to subprogram other than the "
2187 & "main subprogram has no effect??", Expr
);
2189 -- Otherwise check in range and export the value
2191 -- For the CPU aspect
2193 elsif A_Id
= Aspect_CPU
then
2194 if Is_In_Range
(Expr
, RTE
(RE_CPU_Range
)) then
2196 -- Value is correct so we export the value to make
2197 -- it available at execution time.
2200 (Main_Unit
, UI_To_Int
(Expr_Value
(Expr
)));
2204 ("main subprogram CPU is out of range", Expr
);
2207 -- For the Priority aspect
2209 elsif A_Id
= Aspect_Priority
then
2210 if Is_In_Range
(Expr
, RTE
(RE_Priority
)) then
2212 -- Value is correct so we export the value to make
2213 -- it available at execution time.
2216 (Main_Unit
, UI_To_Int
(Expr_Value
(Expr
)));
2218 -- Ignore pragma if Relaxed_RM_Semantics to support
2219 -- other targets/non GNAT compilers.
2221 elsif not Relaxed_RM_Semantics
then
2223 ("main subprogram priority is out of range",
2228 -- Load an arbitrary entity from System.Tasking.Stages
2229 -- or System.Tasking.Restricted.Stages (depending on
2230 -- the supported profile) to make sure that one of these
2231 -- packages is implicitly with'ed, since we need to have
2232 -- the tasking run time active for the pragma Priority to
2233 -- have any effect. Previously we with'ed the package
2234 -- System.Tasking, but this package does not trigger the
2235 -- required initialization of the run-time library.
2238 Discard
: Entity_Id
;
2240 if Restricted_Profile
then
2241 Discard
:= RTE
(RE_Activate_Restricted_Tasks
);
2243 Discard
:= RTE
(RE_Activate_Tasks
);
2247 -- Handling for these Aspects in subprograms is complete
2251 -- For tasks pass the aspect as an attribute
2255 Make_Attribute_Definition_Clause
(Loc
,
2257 Chars
=> Chars
(Id
),
2258 Expression
=> Relocate_Node
(Expr
));
2263 when Aspect_Warnings
=>
2265 (Pragma_Argument_Associations
=> New_List
(
2266 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2267 Expression
=> Relocate_Node
(Expr
)),
2268 Make_Pragma_Argument_Association
(Loc
,
2269 Expression
=> New_Occurrence_Of
(E
, Loc
))),
2270 Pragma_Name
=> Chars
(Id
));
2272 Decorate
(Aspect
, Aitem
);
2273 Insert_Pragma
(Aitem
);
2276 -- Case 2c: Aspects corresponding to pragmas with three
2279 -- Invariant aspects have a first argument that references the
2280 -- entity, a second argument that is the expression and a third
2281 -- argument that is an appropriate message.
2283 -- Invariant, Type_Invariant
2285 when Aspect_Invariant |
2286 Aspect_Type_Invariant
=>
2288 -- Analysis of the pragma will verify placement legality:
2289 -- an invariant must apply to a private type, or appear in
2290 -- the private part of a spec and apply to a completion.
2293 (Pragma_Argument_Associations
=> New_List
(
2294 Make_Pragma_Argument_Association
(Sloc
(Ent
),
2296 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2297 Expression
=> Relocate_Node
(Expr
))),
2298 Pragma_Name
=> Name_Invariant
);
2300 -- Add message unless exception messages are suppressed
2302 if not Opt
.Exception_Locations_Suppressed
then
2303 Append_To
(Pragma_Argument_Associations
(Aitem
),
2304 Make_Pragma_Argument_Association
(Eloc
,
2305 Chars
=> Name_Message
,
2307 Make_String_Literal
(Eloc
,
2308 Strval
=> "failed invariant from "
2309 & Build_Location_String
(Eloc
))));
2312 -- For Invariant case, insert immediately after the entity
2313 -- declaration. We do not have to worry about delay issues
2314 -- since the pragma processing takes care of this.
2316 Delay_Required
:= False;
2318 -- Case 2d : Aspects that correspond to a pragma with one
2323 -- Aspect Abstract_State introduces implicit declarations for
2324 -- all state abstraction entities it defines. To emulate this
2325 -- behavior, insert the pragma at the beginning of the visible
2326 -- declarations of the related package so that it is analyzed
2329 when Aspect_Abstract_State
=> Abstract_State
: declare
2330 Context
: Node_Id
:= N
;
2333 -- When aspect Abstract_State appears on a generic package,
2334 -- it is propageted to the package instance. The context in
2335 -- this case is the instance spec.
2337 if Nkind
(Context
) = N_Package_Instantiation
then
2338 Context
:= Instance_Spec
(Context
);
2341 if Nkind_In
(Context
, N_Generic_Package_Declaration
,
2342 N_Package_Declaration
)
2345 (Pragma_Argument_Associations
=> New_List
(
2346 Make_Pragma_Argument_Association
(Loc
,
2347 Expression
=> Relocate_Node
(Expr
))),
2348 Pragma_Name
=> Name_Abstract_State
);
2350 Decorate
(Aspect
, Aitem
);
2354 Is_Generic_Instance
(Defining_Entity
(Context
)));
2358 ("aspect & must apply to a package declaration",
2365 -- Aspect Async_Readers is never delayed because it is
2366 -- equivalent to a source pragma which appears after the
2367 -- related object declaration.
2369 when Aspect_Async_Readers
=>
2371 (Pragma_Argument_Associations
=> New_List
(
2372 Make_Pragma_Argument_Association
(Loc
,
2373 Expression
=> Relocate_Node
(Expr
))),
2374 Pragma_Name
=> Name_Async_Readers
);
2376 Decorate
(Aspect
, Aitem
);
2377 Insert_Pragma
(Aitem
);
2380 -- Aspect Async_Writers is never delayed because it is
2381 -- equivalent to a source pragma which appears after the
2382 -- related object declaration.
2384 when Aspect_Async_Writers
=>
2386 (Pragma_Argument_Associations
=> New_List
(
2387 Make_Pragma_Argument_Association
(Loc
,
2388 Expression
=> Relocate_Node
(Expr
))),
2389 Pragma_Name
=> Name_Async_Writers
);
2391 Decorate
(Aspect
, Aitem
);
2392 Insert_Pragma
(Aitem
);
2395 -- Aspect Constant_After_Elaboration is never delayed because
2396 -- it is equivalent to a source pragma which appears after the
2397 -- related object declaration.
2399 when Aspect_Constant_After_Elaboration
=>
2401 (Pragma_Argument_Associations
=> New_List
(
2402 Make_Pragma_Argument_Association
(Loc
,
2403 Expression
=> Relocate_Node
(Expr
))),
2405 Name_Constant_After_Elaboration
);
2407 Decorate
(Aspect
, Aitem
);
2408 Insert_Pragma
(Aitem
);
2411 -- Aspect Default_Internal_Condition is never delayed because
2412 -- it is equivalent to a source pragma which appears after the
2413 -- related private type. To deal with forward references, the
2414 -- generated pragma is stored in the rep chain of the related
2415 -- private type as types do not carry contracts. The pragma is
2416 -- wrapped inside of a procedure at the freeze point of the
2417 -- private type's full view.
2419 when Aspect_Default_Initial_Condition
=>
2421 (Pragma_Argument_Associations
=> New_List
(
2422 Make_Pragma_Argument_Association
(Loc
,
2423 Expression
=> Relocate_Node
(Expr
))),
2425 Name_Default_Initial_Condition
);
2427 Decorate
(Aspect
, Aitem
);
2428 Insert_Pragma
(Aitem
);
2431 -- Default_Storage_Pool
2433 when Aspect_Default_Storage_Pool
=>
2435 (Pragma_Argument_Associations
=> New_List
(
2436 Make_Pragma_Argument_Association
(Loc
,
2437 Expression
=> Relocate_Node
(Expr
))),
2439 Name_Default_Storage_Pool
);
2441 Decorate
(Aspect
, Aitem
);
2442 Insert_Pragma
(Aitem
);
2447 -- Aspect Depends is never delayed because it is equivalent to
2448 -- a source pragma which appears after the related subprogram.
2449 -- To deal with forward references, the generated pragma is
2450 -- stored in the contract of the related subprogram and later
2451 -- analyzed at the end of the declarative region. See routine
2452 -- Analyze_Depends_In_Decl_Part for details.
2454 when Aspect_Depends
=>
2456 (Pragma_Argument_Associations
=> New_List
(
2457 Make_Pragma_Argument_Association
(Loc
,
2458 Expression
=> Relocate_Node
(Expr
))),
2459 Pragma_Name
=> Name_Depends
);
2461 Decorate
(Aspect
, Aitem
);
2462 Insert_Pragma
(Aitem
);
2465 -- Aspect Effecitve_Reads is never delayed because it is
2466 -- equivalent to a source pragma which appears after the
2467 -- related object declaration.
2469 when Aspect_Effective_Reads
=>
2471 (Pragma_Argument_Associations
=> New_List
(
2472 Make_Pragma_Argument_Association
(Loc
,
2473 Expression
=> Relocate_Node
(Expr
))),
2474 Pragma_Name
=> Name_Effective_Reads
);
2476 Decorate
(Aspect
, Aitem
);
2477 Insert_Pragma
(Aitem
);
2480 -- Aspect Effective_Writes is never delayed because it is
2481 -- equivalent to a source pragma which appears after the
2482 -- related object declaration.
2484 when Aspect_Effective_Writes
=>
2486 (Pragma_Argument_Associations
=> New_List
(
2487 Make_Pragma_Argument_Association
(Loc
,
2488 Expression
=> Relocate_Node
(Expr
))),
2489 Pragma_Name
=> Name_Effective_Writes
);
2491 Decorate
(Aspect
, Aitem
);
2492 Insert_Pragma
(Aitem
);
2495 -- Aspect Extensions_Visible is never delayed because it is
2496 -- equivalent to a source pragma which appears after the
2497 -- related subprogram.
2499 when Aspect_Extensions_Visible
=>
2501 (Pragma_Argument_Associations
=> New_List
(
2502 Make_Pragma_Argument_Association
(Loc
,
2503 Expression
=> Relocate_Node
(Expr
))),
2504 Pragma_Name
=> Name_Extensions_Visible
);
2506 Decorate
(Aspect
, Aitem
);
2507 Insert_Pragma
(Aitem
);
2510 -- Aspect Ghost is never delayed because it is equivalent to a
2511 -- source pragma which appears at the top of [generic] package
2512 -- declarations or after an object, a [generic] subprogram, or
2513 -- a type declaration.
2515 when Aspect_Ghost
=>
2517 (Pragma_Argument_Associations
=> New_List
(
2518 Make_Pragma_Argument_Association
(Loc
,
2519 Expression
=> Relocate_Node
(Expr
))),
2520 Pragma_Name
=> Name_Ghost
);
2522 Decorate
(Aspect
, Aitem
);
2523 Insert_Pragma
(Aitem
);
2528 -- Aspect Global is never delayed because it is equivalent to
2529 -- a source pragma which appears after the related subprogram.
2530 -- To deal with forward references, the generated pragma is
2531 -- stored in the contract of the related subprogram and later
2532 -- analyzed at the end of the declarative region. See routine
2533 -- Analyze_Global_In_Decl_Part for details.
2535 when Aspect_Global
=>
2537 (Pragma_Argument_Associations
=> New_List
(
2538 Make_Pragma_Argument_Association
(Loc
,
2539 Expression
=> Relocate_Node
(Expr
))),
2540 Pragma_Name
=> Name_Global
);
2542 Decorate
(Aspect
, Aitem
);
2543 Insert_Pragma
(Aitem
);
2546 -- Initial_Condition
2548 -- Aspect Initial_Condition is never delayed because it is
2549 -- equivalent to a source pragma which appears after the
2550 -- related package. To deal with forward references, the
2551 -- generated pragma is stored in the contract of the related
2552 -- package and later analyzed at the end of the declarative
2553 -- region. See routine Analyze_Initial_Condition_In_Decl_Part
2556 when Aspect_Initial_Condition
=> Initial_Condition
: declare
2557 Context
: Node_Id
:= N
;
2560 -- When aspect Initial_Condition appears on a generic
2561 -- package, it is propageted to the package instance. The
2562 -- context in this case is the instance spec.
2564 if Nkind
(Context
) = N_Package_Instantiation
then
2565 Context
:= Instance_Spec
(Context
);
2568 if Nkind_In
(Context
, N_Generic_Package_Declaration
,
2569 N_Package_Declaration
)
2572 (Pragma_Argument_Associations
=> New_List
(
2573 Make_Pragma_Argument_Association
(Loc
,
2574 Expression
=> Relocate_Node
(Expr
))),
2576 Name_Initial_Condition
);
2578 Decorate
(Aspect
, Aitem
);
2582 Is_Generic_Instance
(Defining_Entity
(Context
)));
2584 -- Otherwise the context is illegal
2588 ("aspect & must apply to a package declaration",
2593 end Initial_Condition
;
2597 -- Aspect Initializes is never delayed because it is equivalent
2598 -- to a source pragma appearing after the related package. To
2599 -- deal with forward references, the generated pragma is stored
2600 -- in the contract of the related package and later analyzed at
2601 -- the end of the declarative region. For details, see routine
2602 -- Analyze_Initializes_In_Decl_Part.
2604 when Aspect_Initializes
=> Initializes
: declare
2605 Context
: Node_Id
:= N
;
2608 -- When aspect Initializes appears on a generic package,
2609 -- it is propageted to the package instance. The context
2610 -- in this case is the instance spec.
2612 if Nkind
(Context
) = N_Package_Instantiation
then
2613 Context
:= Instance_Spec
(Context
);
2616 if Nkind_In
(Context
, N_Generic_Package_Declaration
,
2617 N_Package_Declaration
)
2620 (Pragma_Argument_Associations
=> New_List
(
2621 Make_Pragma_Argument_Association
(Loc
,
2622 Expression
=> Relocate_Node
(Expr
))),
2623 Pragma_Name
=> Name_Initializes
);
2625 Decorate
(Aspect
, Aitem
);
2629 Is_Generic_Instance
(Defining_Entity
(Context
)));
2631 -- Otherwise the context is illegal
2635 ("aspect & must apply to a package declaration",
2644 when Aspect_Obsolescent
=> declare
2652 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2653 Expression
=> Relocate_Node
(Expr
)));
2657 (Pragma_Argument_Associations
=> Args
,
2658 Pragma_Name
=> Chars
(Id
));
2663 when Aspect_Part_Of
=>
2664 if Nkind_In
(N
, N_Object_Declaration
,
2665 N_Package_Instantiation
)
2666 or else Is_Single_Concurrent_Type_Declaration
(N
)
2669 (Pragma_Argument_Associations
=> New_List
(
2670 Make_Pragma_Argument_Association
(Loc
,
2671 Expression
=> Relocate_Node
(Expr
))),
2672 Pragma_Name
=> Name_Part_Of
);
2674 Decorate
(Aspect
, Aitem
);
2675 Insert_Pragma
(Aitem
);
2679 ("aspect & must apply to package instantiation, "
2680 & "object, single protected type or single task type",
2688 when Aspect_SPARK_Mode
=>
2690 (Pragma_Argument_Associations
=> New_List
(
2691 Make_Pragma_Argument_Association
(Loc
,
2692 Expression
=> Relocate_Node
(Expr
))),
2693 Pragma_Name
=> Name_SPARK_Mode
);
2695 Decorate
(Aspect
, Aitem
);
2696 Insert_Pragma
(Aitem
);
2701 -- Aspect Refined_Depends is never delayed because it is
2702 -- equivalent to a source pragma which appears in the
2703 -- declarations of the related subprogram body. To deal with
2704 -- forward references, the generated pragma is stored in the
2705 -- contract of the related subprogram body and later analyzed
2706 -- at the end of the declarative region. For details, see
2707 -- routine Analyze_Refined_Depends_In_Decl_Part.
2709 when Aspect_Refined_Depends
=>
2711 (Pragma_Argument_Associations
=> New_List
(
2712 Make_Pragma_Argument_Association
(Loc
,
2713 Expression
=> Relocate_Node
(Expr
))),
2714 Pragma_Name
=> Name_Refined_Depends
);
2716 Decorate
(Aspect
, Aitem
);
2717 Insert_Pragma
(Aitem
);
2722 -- Aspect Refined_Global is never delayed because it is
2723 -- equivalent to a source pragma which appears in the
2724 -- declarations of the related subprogram body. To deal with
2725 -- forward references, the generated pragma is stored in the
2726 -- contract of the related subprogram body and later analyzed
2727 -- at the end of the declarative region. For details, see
2728 -- routine Analyze_Refined_Global_In_Decl_Part.
2730 when Aspect_Refined_Global
=>
2732 (Pragma_Argument_Associations
=> New_List
(
2733 Make_Pragma_Argument_Association
(Loc
,
2734 Expression
=> Relocate_Node
(Expr
))),
2735 Pragma_Name
=> Name_Refined_Global
);
2737 Decorate
(Aspect
, Aitem
);
2738 Insert_Pragma
(Aitem
);
2743 when Aspect_Refined_Post
=>
2745 (Pragma_Argument_Associations
=> New_List
(
2746 Make_Pragma_Argument_Association
(Loc
,
2747 Expression
=> Relocate_Node
(Expr
))),
2748 Pragma_Name
=> Name_Refined_Post
);
2750 Decorate
(Aspect
, Aitem
);
2751 Insert_Pragma
(Aitem
);
2756 when Aspect_Refined_State
=>
2758 -- The corresponding pragma for Refined_State is inserted in
2759 -- the declarations of the related package body. This action
2760 -- synchronizes both the source and from-aspect versions of
2763 if Nkind
(N
) = N_Package_Body
then
2765 (Pragma_Argument_Associations
=> New_List
(
2766 Make_Pragma_Argument_Association
(Loc
,
2767 Expression
=> Relocate_Node
(Expr
))),
2768 Pragma_Name
=> Name_Refined_State
);
2770 Decorate
(Aspect
, Aitem
);
2771 Insert_Pragma
(Aitem
);
2773 -- Otherwise the context is illegal
2777 ("aspect & must apply to a package body", Aspect
, Id
);
2782 -- Relative_Deadline
2784 when Aspect_Relative_Deadline
=>
2786 (Pragma_Argument_Associations
=> New_List
(
2787 Make_Pragma_Argument_Association
(Loc
,
2788 Expression
=> Relocate_Node
(Expr
))),
2789 Pragma_Name
=> Name_Relative_Deadline
);
2791 -- If the aspect applies to a task, the corresponding pragma
2792 -- must appear within its declarations, not after.
2794 if Nkind
(N
) = N_Task_Type_Declaration
then
2800 if No
(Task_Definition
(N
)) then
2801 Set_Task_Definition
(N
,
2802 Make_Task_Definition
(Loc
,
2803 Visible_Declarations
=> New_List
,
2804 End_Label
=> Empty
));
2807 Def
:= Task_Definition
(N
);
2808 V
:= Visible_Declarations
(Def
);
2809 if not Is_Empty_List
(V
) then
2810 Insert_Before
(First
(V
), Aitem
);
2813 Set_Visible_Declarations
(Def
, New_List
(Aitem
));
2820 -- Aspect Volatile_Function is never delayed because it is
2821 -- equivalent to a source pragma which appears after the
2822 -- related subprogram.
2824 when Aspect_Volatile_Function
=>
2826 (Pragma_Argument_Associations
=> New_List
(
2827 Make_Pragma_Argument_Association
(Loc
,
2828 Expression
=> Relocate_Node
(Expr
))),
2829 Pragma_Name
=> Name_Volatile_Function
);
2831 Decorate
(Aspect
, Aitem
);
2832 Insert_Pragma
(Aitem
);
2835 -- Case 2e: Annotate aspect
2837 when Aspect_Annotate
=>
2844 -- The argument can be a single identifier
2846 if Nkind
(Expr
) = N_Identifier
then
2848 -- One level of parens is allowed
2850 if Paren_Count
(Expr
) > 1 then
2851 Error_Msg_F
("extra parentheses ignored", Expr
);
2854 Set_Paren_Count
(Expr
, 0);
2856 -- Add the single item to the list
2858 Args
:= New_List
(Expr
);
2860 -- Otherwise we must have an aggregate
2862 elsif Nkind
(Expr
) = N_Aggregate
then
2864 -- Must be positional
2866 if Present
(Component_Associations
(Expr
)) then
2868 ("purely positional aggregate required", Expr
);
2872 -- Must not be parenthesized
2874 if Paren_Count
(Expr
) /= 0 then
2875 Error_Msg_F
("extra parentheses ignored", Expr
);
2878 -- List of arguments is list of aggregate expressions
2880 Args
:= Expressions
(Expr
);
2882 -- Anything else is illegal
2885 Error_Msg_F
("wrong form for Annotate aspect", Expr
);
2889 -- Prepare pragma arguments
2892 Arg
:= First
(Args
);
2893 while Present
(Arg
) loop
2895 Make_Pragma_Argument_Association
(Sloc
(Arg
),
2896 Expression
=> Relocate_Node
(Arg
)));
2901 Make_Pragma_Argument_Association
(Sloc
(Ent
),
2902 Chars
=> Name_Entity
,
2903 Expression
=> Ent
));
2906 (Pragma_Argument_Associations
=> Pargs
,
2907 Pragma_Name
=> Name_Annotate
);
2910 -- Case 3 : Aspects that don't correspond to pragma/attribute
2911 -- definition clause.
2913 -- Case 3a: The aspects listed below don't correspond to
2914 -- pragmas/attributes but do require delayed analysis.
2916 -- Default_Value can only apply to a scalar type
2918 when Aspect_Default_Value
=>
2919 if not Is_Scalar_Type
(E
) then
2921 ("aspect Default_Value must apply to a scalar type", N
);
2926 -- Default_Component_Value can only apply to an array type
2927 -- with scalar components.
2929 when Aspect_Default_Component_Value
=>
2930 if not (Is_Array_Type
(E
)
2931 and then Is_Scalar_Type
(Component_Type
(E
)))
2933 Error_Msg_N
("aspect Default_Component_Value can only "
2934 & "apply to an array of scalar components", N
);
2939 -- Case 3b: The aspects listed below don't correspond to
2940 -- pragmas/attributes and don't need delayed analysis.
2942 -- Implicit_Dereference
2944 -- For Implicit_Dereference, External_Name and Link_Name, only
2945 -- the legality checks are done during the analysis, thus no
2946 -- delay is required.
2948 when Aspect_Implicit_Dereference
=>
2949 Analyze_Aspect_Implicit_Dereference
;
2952 -- External_Name, Link_Name
2954 when Aspect_External_Name |
2956 Analyze_Aspect_External_Or_Link_Name
;
2961 when Aspect_Dimension
=>
2962 Analyze_Aspect_Dimension
(N
, Id
, Expr
);
2967 when Aspect_Dimension_System
=>
2968 Analyze_Aspect_Dimension_System
(N
, Id
, Expr
);
2971 -- Case 4: Aspects requiring special handling
2973 -- Pre/Post/Test_Case/Contract_Cases whose corresponding
2974 -- pragmas take care of the delay.
2978 -- Aspects Pre/Post generate Precondition/Postcondition pragmas
2979 -- with a first argument that is the expression, and a second
2980 -- argument that is an informative message if the test fails.
2981 -- This is inserted right after the declaration, to get the
2982 -- required pragma placement. The processing for the pragmas
2983 -- takes care of the required delay.
2985 when Pre_Post_Aspects
=> Pre_Post
: declare
2989 if A_Id
= Aspect_Pre
or else A_Id
= Aspect_Precondition
then
2990 Pname
:= Name_Precondition
;
2992 Pname
:= Name_Postcondition
;
2995 -- If the expressions is of the form A and then B, then
2996 -- we generate separate Pre/Post aspects for the separate
2997 -- clauses. Since we allow multiple pragmas, there is no
2998 -- problem in allowing multiple Pre/Post aspects internally.
2999 -- These should be treated in reverse order (B first and
3000 -- A second) since they are later inserted just after N in
3001 -- the order they are treated. This way, the pragma for A
3002 -- ends up preceding the pragma for B, which may have an
3003 -- importance for the error raised (either constraint error
3004 -- or precondition error).
3006 -- We do not do this for Pre'Class, since we have to put
3007 -- these conditions together in a complex OR expression.
3009 -- We do not do this in ASIS mode, as ASIS relies on the
3010 -- original node representing the complete expression, when
3011 -- retrieving it through the source aspect table.
3014 and then (Pname
= Name_Postcondition
3015 or else not Class_Present
(Aspect
))
3017 while Nkind
(Expr
) = N_And_Then
loop
3018 Insert_After
(Aspect
,
3019 Make_Aspect_Specification
(Sloc
(Left_Opnd
(Expr
)),
3020 Identifier
=> Identifier
(Aspect
),
3021 Expression
=> Relocate_Node
(Left_Opnd
(Expr
)),
3022 Class_Present
=> Class_Present
(Aspect
),
3023 Split_PPC
=> True));
3024 Rewrite
(Expr
, Relocate_Node
(Right_Opnd
(Expr
)));
3025 Eloc
:= Sloc
(Expr
);
3029 -- Build the precondition/postcondition pragma
3031 -- Add note about why we do NOT need Copy_Tree here???
3034 (Pragma_Argument_Associations
=> New_List
(
3035 Make_Pragma_Argument_Association
(Eloc
,
3036 Chars
=> Name_Check
,
3037 Expression
=> Relocate_Node
(Expr
))),
3038 Pragma_Name
=> Pname
);
3040 -- Add message unless exception messages are suppressed
3042 if not Opt
.Exception_Locations_Suppressed
then
3043 Append_To
(Pragma_Argument_Associations
(Aitem
),
3044 Make_Pragma_Argument_Association
(Eloc
,
3045 Chars
=> Name_Message
,
3047 Make_String_Literal
(Eloc
,
3049 & Get_Name_String
(Pname
)
3051 & Build_Location_String
(Eloc
))));
3054 Set_Is_Delayed_Aspect
(Aspect
);
3056 -- For Pre/Post cases, insert immediately after the entity
3057 -- declaration, since that is the required pragma placement.
3058 -- Note that for these aspects, we do not have to worry
3059 -- about delay issues, since the pragmas themselves deal
3060 -- with delay of visibility for the expression analysis.
3062 Insert_Pragma
(Aitem
);
3069 when Aspect_Test_Case
=> Test_Case
: declare
3071 Comp_Expr
: Node_Id
;
3072 Comp_Assn
: Node_Id
;
3078 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
3079 Error_Msg_Name_1
:= Nam
;
3080 Error_Msg_N
("incorrect placement of aspect `%`", E
);
3084 if Nkind
(Expr
) /= N_Aggregate
then
3085 Error_Msg_Name_1
:= Nam
;
3087 ("wrong syntax for aspect `%` for &", Id
, E
);
3091 -- Make pragma expressions refer to the original aspect
3092 -- expressions through the Original_Node link. This is used
3093 -- in semantic analysis for ASIS mode, so that the original
3094 -- expression also gets analyzed.
3096 Comp_Expr
:= First
(Expressions
(Expr
));
3097 while Present
(Comp_Expr
) loop
3098 New_Expr
:= Relocate_Node
(Comp_Expr
);
3100 Make_Pragma_Argument_Association
(Sloc
(Comp_Expr
),
3101 Expression
=> New_Expr
));
3105 Comp_Assn
:= First
(Component_Associations
(Expr
));
3106 while Present
(Comp_Assn
) loop
3107 if List_Length
(Choices
(Comp_Assn
)) /= 1
3109 Nkind
(First
(Choices
(Comp_Assn
))) /= N_Identifier
3111 Error_Msg_Name_1
:= Nam
;
3113 ("wrong syntax for aspect `%` for &", Id
, E
);
3118 Make_Pragma_Argument_Association
(Sloc
(Comp_Assn
),
3119 Chars
=> Chars
(First
(Choices
(Comp_Assn
))),
3121 Relocate_Node
(Expression
(Comp_Assn
))));
3125 -- Build the test-case pragma
3128 (Pragma_Argument_Associations
=> Args
,
3129 Pragma_Name
=> Nam
);
3134 when Aspect_Contract_Cases
=>
3136 (Pragma_Argument_Associations
=> New_List
(
3137 Make_Pragma_Argument_Association
(Loc
,
3138 Expression
=> Relocate_Node
(Expr
))),
3139 Pragma_Name
=> Nam
);
3141 Decorate
(Aspect
, Aitem
);
3142 Insert_Pragma
(Aitem
);
3145 -- Case 5: Special handling for aspects with an optional
3146 -- boolean argument.
3148 -- In the delayed case, the corresponding pragma cannot be
3149 -- generated yet because the evaluation of the boolean needs
3150 -- to be delayed till the freeze point.
3152 when Boolean_Aspects |
3153 Library_Unit_Aspects
=>
3155 Set_Is_Boolean_Aspect
(Aspect
);
3157 -- Lock_Free aspect only apply to protected objects
3159 if A_Id
= Aspect_Lock_Free
then
3160 if Ekind
(E
) /= E_Protected_Type
then
3161 Error_Msg_Name_1
:= Nam
;
3163 ("aspect % only applies to a protected object",
3167 -- Set the Uses_Lock_Free flag to True if there is no
3168 -- expression or if the expression is True. The
3169 -- evaluation of this aspect should be delayed to the
3170 -- freeze point (why???)
3173 or else Is_True
(Static_Boolean
(Expr
))
3175 Set_Uses_Lock_Free
(E
);
3178 Record_Rep_Item
(E
, Aspect
);
3183 elsif A_Id
= Aspect_Import
or else A_Id
= Aspect_Export
then
3185 -- For the case of aspects Import and Export, we don't
3186 -- consider that we know the entity is never set in the
3187 -- source, since it is is likely modified outside the
3190 -- Note: one might think that the analysis of the
3191 -- resulting pragma would take care of that, but
3192 -- that's not the case since it won't be from source.
3194 if Ekind
(E
) = E_Variable
then
3195 Set_Never_Set_In_Source
(E
, False);
3198 -- In older versions of Ada the corresponding pragmas
3199 -- specified a Convention. In Ada 2012 the convention is
3200 -- specified as a separate aspect, and it is optional,
3201 -- given that it defaults to Convention_Ada. The code
3202 -- that verifed that there was a matching convention
3205 -- Resolve the expression of an Import or Export here,
3206 -- and require it to be of type Boolean and static. This
3207 -- is not quite right, because in general this should be
3208 -- delayed, but that seems tricky for these, because
3209 -- normally Boolean aspects are replaced with pragmas at
3210 -- the freeze point (in Make_Pragma_From_Boolean_Aspect),
3211 -- but in the case of these aspects we can't generate
3212 -- a simple pragma with just the entity name. ???
3214 if not Present
(Expr
)
3215 or else Is_True
(Static_Boolean
(Expr
))
3217 if A_Id
= Aspect_Import
then
3218 Set_Is_Imported
(E
);
3219 Set_Has_Completion
(E
);
3221 -- An imported entity cannot have an explicit
3224 if Nkind
(N
) = N_Object_Declaration
3225 and then Present
(Expression
(N
))
3228 ("imported entities cannot be initialized "
3229 & "(RM B.1(24))", Expression
(N
));
3232 elsif A_Id
= Aspect_Export
then
3233 Set_Is_Exported
(E
);
3239 -- Disable_Controlled
3241 elsif A_Id
= Aspect_Disable_Controlled
then
3242 if Ekind
(E
) /= E_Record_Type
3243 or else not Is_Controlled
(E
)
3246 ("aspect % requires controlled record type", Aspect
);
3250 -- If we're in a generic template, we don't want to try
3251 -- to disable controlled types, because typical usage is
3252 -- "Disable_Controlled => not <some_check>'Enabled", and
3253 -- the value of Enabled is not known until we see a
3254 -- particular instance. In such a context, we just need
3255 -- to preanalyze the expression for legality.
3257 if Expander_Active
then
3258 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
3260 if not Present
(Expr
)
3261 or else Is_True
(Static_Boolean
(Expr
))
3263 Set_Disable_Controlled
(E
);
3266 elsif Serious_Errors_Detected
= 0 then
3267 Preanalyze_And_Resolve
(Expr
, Standard_Boolean
);
3273 -- Library unit aspects require special handling in the case
3274 -- of a package declaration, the pragma needs to be inserted
3275 -- in the list of declarations for the associated package.
3276 -- There is no issue of visibility delay for these aspects.
3278 if A_Id
in Library_Unit_Aspects
3280 Nkind_In
(N
, N_Package_Declaration
,
3281 N_Generic_Package_Declaration
)
3282 and then Nkind
(Parent
(N
)) /= N_Compilation_Unit
3284 -- Aspect is legal on a local instantiation of a library-
3285 -- level generic unit.
3287 and then not Is_Generic_Instance
(Defining_Entity
(N
))
3290 ("incorrect context for library unit aspect&", Id
);
3294 -- Cases where we do not delay, includes all cases where the
3295 -- expression is missing other than the above cases.
3297 if not Delay_Required
or else No
(Expr
) then
3299 (Pragma_Argument_Associations
=> New_List
(
3300 Make_Pragma_Argument_Association
(Sloc
(Ent
),
3301 Expression
=> Ent
)),
3302 Pragma_Name
=> Chars
(Id
));
3303 Delay_Required
:= False;
3305 -- In general cases, the corresponding pragma/attribute
3306 -- definition clause will be inserted later at the freezing
3307 -- point, and we do not need to build it now.
3315 -- This is special because for access types we need to generate
3316 -- an attribute definition clause. This also works for single
3317 -- task declarations, but it does not work for task type
3318 -- declarations, because we have the case where the expression
3319 -- references a discriminant of the task type. That can't use
3320 -- an attribute definition clause because we would not have
3321 -- visibility on the discriminant. For that case we must
3322 -- generate a pragma in the task definition.
3324 when Aspect_Storage_Size
=>
3328 if Ekind
(E
) = E_Task_Type
then
3330 Decl
: constant Node_Id
:= Declaration_Node
(E
);
3333 pragma Assert
(Nkind
(Decl
) = N_Task_Type_Declaration
);
3335 -- If no task definition, create one
3337 if No
(Task_Definition
(Decl
)) then
3338 Set_Task_Definition
(Decl
,
3339 Make_Task_Definition
(Loc
,
3340 Visible_Declarations
=> Empty_List
,
3341 End_Label
=> Empty
));
3344 -- Create a pragma and put it at the start of the task
3345 -- definition for the task type declaration.
3348 (Pragma_Argument_Associations
=> New_List
(
3349 Make_Pragma_Argument_Association
(Loc
,
3350 Expression
=> Relocate_Node
(Expr
))),
3351 Pragma_Name
=> Name_Storage_Size
);
3355 Visible_Declarations
(Task_Definition
(Decl
)));
3359 -- All other cases, generate attribute definition
3363 Make_Attribute_Definition_Clause
(Loc
,
3365 Chars
=> Chars
(Id
),
3366 Expression
=> Relocate_Node
(Expr
));
3370 -- Attach the corresponding pragma/attribute definition clause to
3371 -- the aspect specification node.
3373 if Present
(Aitem
) then
3374 Set_From_Aspect_Specification
(Aitem
);
3377 -- In the context of a compilation unit, we directly put the
3378 -- pragma in the Pragmas_After list of the N_Compilation_Unit_Aux
3379 -- node (no delay is required here) except for aspects on a
3380 -- subprogram body (see below) and a generic package, for which we
3381 -- need to introduce the pragma before building the generic copy
3382 -- (see sem_ch12), and for package instantiations, where the
3383 -- library unit pragmas are better handled early.
3385 if Nkind
(Parent
(N
)) = N_Compilation_Unit
3386 and then (Present
(Aitem
) or else Is_Boolean_Aspect
(Aspect
))
3389 Aux
: constant Node_Id
:= Aux_Decls_Node
(Parent
(N
));
3392 pragma Assert
(Nkind
(Aux
) = N_Compilation_Unit_Aux
);
3394 -- For a Boolean aspect, create the corresponding pragma if
3395 -- no expression or if the value is True.
3397 if Is_Boolean_Aspect
(Aspect
) and then No
(Aitem
) then
3398 if Is_True
(Static_Boolean
(Expr
)) then
3400 (Pragma_Argument_Associations
=> New_List
(
3401 Make_Pragma_Argument_Association
(Sloc
(Ent
),
3402 Expression
=> Ent
)),
3403 Pragma_Name
=> Chars
(Id
));
3405 Set_From_Aspect_Specification
(Aitem
, True);
3406 Set_Corresponding_Aspect
(Aitem
, Aspect
);
3413 -- If the aspect is on a subprogram body (relevant aspect
3414 -- is Inline), add the pragma in front of the declarations.
3416 if Nkind
(N
) = N_Subprogram_Body
then
3417 if No
(Declarations
(N
)) then
3418 Set_Declarations
(N
, New_List
);
3421 Prepend
(Aitem
, Declarations
(N
));
3423 elsif Nkind
(N
) = N_Generic_Package_Declaration
then
3424 if No
(Visible_Declarations
(Specification
(N
))) then
3425 Set_Visible_Declarations
(Specification
(N
), New_List
);
3429 Visible_Declarations
(Specification
(N
)));
3431 elsif Nkind
(N
) = N_Package_Instantiation
then
3433 Spec
: constant Node_Id
:=
3434 Specification
(Instance_Spec
(N
));
3436 if No
(Visible_Declarations
(Spec
)) then
3437 Set_Visible_Declarations
(Spec
, New_List
);
3440 Prepend
(Aitem
, Visible_Declarations
(Spec
));
3444 if No
(Pragmas_After
(Aux
)) then
3445 Set_Pragmas_After
(Aux
, New_List
);
3448 Append
(Aitem
, Pragmas_After
(Aux
));
3455 -- The evaluation of the aspect is delayed to the freezing point.
3456 -- The pragma or attribute clause if there is one is then attached
3457 -- to the aspect specification which is put in the rep item list.
3459 if Delay_Required
then
3460 if Present
(Aitem
) then
3461 Set_Is_Delayed_Aspect
(Aitem
);
3462 Set_Aspect_Rep_Item
(Aspect
, Aitem
);
3463 Set_Parent
(Aitem
, Aspect
);
3466 Set_Is_Delayed_Aspect
(Aspect
);
3468 -- In the case of Default_Value, link the aspect to base type
3469 -- as well, even though it appears on a first subtype. This is
3470 -- mandated by the semantics of the aspect. Do not establish
3471 -- the link when processing the base type itself as this leads
3472 -- to a rep item circularity. Verify that we are dealing with
3473 -- a scalar type to prevent cascaded errors.
3475 if A_Id
= Aspect_Default_Value
3476 and then Is_Scalar_Type
(E
)
3477 and then Base_Type
(E
) /= E
3479 Set_Has_Delayed_Aspects
(Base_Type
(E
));
3480 Record_Rep_Item
(Base_Type
(E
), Aspect
);
3483 Set_Has_Delayed_Aspects
(E
);
3484 Record_Rep_Item
(E
, Aspect
);
3486 -- When delay is not required and the context is a package or a
3487 -- subprogram body, insert the pragma in the body declarations.
3489 elsif Nkind_In
(N
, N_Package_Body
, N_Subprogram_Body
) then
3490 if No
(Declarations
(N
)) then
3491 Set_Declarations
(N
, New_List
);
3494 -- The pragma is added before source declarations
3496 Prepend_To
(Declarations
(N
), Aitem
);
3498 -- When delay is not required and the context is not a compilation
3499 -- unit, we simply insert the pragma/attribute definition clause
3503 Insert_After
(Ins_Node
, Aitem
);
3506 end Analyze_One_Aspect
;
3510 end loop Aspect_Loop
;
3512 if Has_Delayed_Aspects
(E
) then
3513 Ensure_Freeze_Node
(E
);
3515 end Analyze_Aspect_Specifications
;
3517 ---------------------------------------------------
3518 -- Analyze_Aspect_Specifications_On_Body_Or_Stub --
3519 ---------------------------------------------------
3521 procedure Analyze_Aspect_Specifications_On_Body_Or_Stub
(N
: Node_Id
) is
3522 Body_Id
: constant Entity_Id
:= Defining_Entity
(N
);
3524 procedure Diagnose_Misplaced_Aspects
(Spec_Id
: Entity_Id
);
3525 -- Body [stub] N has aspects, but they are not properly placed. Emit an
3526 -- error message depending on the aspects involved. Spec_Id denotes the
3527 -- entity of the corresponding spec.
3529 --------------------------------
3530 -- Diagnose_Misplaced_Aspects --
3531 --------------------------------
3533 procedure Diagnose_Misplaced_Aspects
(Spec_Id
: Entity_Id
) is
3534 procedure Misplaced_Aspect_Error
3537 -- Emit an error message concerning misplaced aspect Asp. Ref_Nam is
3538 -- the name of the refined version of the aspect.
3540 ----------------------------
3541 -- Misplaced_Aspect_Error --
3542 ----------------------------
3544 procedure Misplaced_Aspect_Error
3548 Asp_Nam
: constant Name_Id
:= Chars
(Identifier
(Asp
));
3549 Asp_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Asp_Nam
);
3552 -- The corresponding spec already contains the aspect in question
3553 -- and the one appearing on the body must be the refined form:
3555 -- procedure P with Global ...;
3556 -- procedure P with Global ... is ... end P;
3560 if Has_Aspect
(Spec_Id
, Asp_Id
) then
3561 Error_Msg_Name_1
:= Asp_Nam
;
3563 -- Subunits cannot carry aspects that apply to a subprogram
3566 if Nkind
(Parent
(N
)) = N_Subunit
then
3567 Error_Msg_N
("aspect % cannot apply to a subunit", Asp
);
3569 -- Otherwise suggest the refined form
3572 Error_Msg_Name_2
:= Ref_Nam
;
3573 Error_Msg_N
("aspect % should be %", Asp
);
3576 -- Otherwise the aspect must appear on the spec, not on the body
3579 -- procedure P with Global ... is ... end P;
3583 ("aspect specification must appear on initial declaration",
3586 end Misplaced_Aspect_Error
;
3593 -- Start of processing for Diagnose_Misplaced_Aspects
3596 -- Iterate over the aspect specifications and emit specific errors
3597 -- where applicable.
3599 Asp
:= First
(Aspect_Specifications
(N
));
3600 while Present
(Asp
) loop
3601 Asp_Nam
:= Chars
(Identifier
(Asp
));
3603 -- Do not emit errors on aspects that can appear on a subprogram
3604 -- body. This scenario occurs when the aspect specification list
3605 -- contains both misplaced and properly placed aspects.
3607 if Aspect_On_Body_Or_Stub_OK
(Get_Aspect_Id
(Asp_Nam
)) then
3610 -- Special diagnostics for SPARK aspects
3612 elsif Asp_Nam
= Name_Depends
then
3613 Misplaced_Aspect_Error
(Asp
, Name_Refined_Depends
);
3615 elsif Asp_Nam
= Name_Global
then
3616 Misplaced_Aspect_Error
(Asp
, Name_Refined_Global
);
3618 elsif Asp_Nam
= Name_Post
then
3619 Misplaced_Aspect_Error
(Asp
, Name_Refined_Post
);
3621 -- Otherwise a language-defined aspect is misplaced
3625 ("aspect specification must appear on initial declaration",
3631 end Diagnose_Misplaced_Aspects
;
3635 Spec_Id
: constant Entity_Id
:= Unique_Defining_Entity
(N
);
3637 -- Start of processing for Analyze_Aspects_On_Body_Or_Stub
3640 -- Language-defined aspects cannot be associated with a subprogram body
3641 -- [stub] if the subprogram has a spec. Certain implementation defined
3642 -- aspects are allowed to break this rule (for all applicable cases, see
3643 -- table Aspects.Aspect_On_Body_Or_Stub_OK).
3645 if Spec_Id
/= Body_Id
and then not Aspects_On_Body_Or_Stub_OK
(N
) then
3646 Diagnose_Misplaced_Aspects
(Spec_Id
);
3648 Analyze_Aspect_Specifications
(N
, Body_Id
);
3650 end Analyze_Aspect_Specifications_On_Body_Or_Stub
;
3652 -----------------------
3653 -- Analyze_At_Clause --
3654 -----------------------
3656 -- An at clause is replaced by the corresponding Address attribute
3657 -- definition clause that is the preferred approach in Ada 95.
3659 procedure Analyze_At_Clause
(N
: Node_Id
) is
3660 CS
: constant Boolean := Comes_From_Source
(N
);
3663 -- This is an obsolescent feature
3665 Check_Restriction
(No_Obsolescent_Features
, N
);
3667 if Warn_On_Obsolescent_Feature
then
3669 ("?j?at clause is an obsolescent feature (RM J.7(2))", N
);
3671 ("\?j?use address attribute definition clause instead", N
);
3674 -- Rewrite as address clause
3677 Make_Attribute_Definition_Clause
(Sloc
(N
),
3678 Name
=> Identifier
(N
),
3679 Chars
=> Name_Address
,
3680 Expression
=> Expression
(N
)));
3682 -- We preserve Comes_From_Source, since logically the clause still comes
3683 -- from the source program even though it is changed in form.
3685 Set_Comes_From_Source
(N
, CS
);
3687 -- Analyze rewritten clause
3689 Analyze_Attribute_Definition_Clause
(N
);
3690 end Analyze_At_Clause
;
3692 -----------------------------------------
3693 -- Analyze_Attribute_Definition_Clause --
3694 -----------------------------------------
3696 procedure Analyze_Attribute_Definition_Clause
(N
: Node_Id
) is
3697 Loc
: constant Source_Ptr
:= Sloc
(N
);
3698 Nam
: constant Node_Id
:= Name
(N
);
3699 Attr
: constant Name_Id
:= Chars
(N
);
3700 Expr
: constant Node_Id
:= Expression
(N
);
3701 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Attr
);
3704 -- The entity of Nam after it is analyzed. In the case of an incomplete
3705 -- type, this is the underlying type.
3708 -- The underlying entity to which the attribute applies. Generally this
3709 -- is the Underlying_Type of Ent, except in the case where the clause
3710 -- applies to full view of incomplete type or private type in which case
3711 -- U_Ent is just a copy of Ent.
3713 FOnly
: Boolean := False;
3714 -- Reset to True for subtype specific attribute (Alignment, Size)
3715 -- and for stream attributes, i.e. those cases where in the call to
3716 -- Rep_Item_Too_Late, FOnly is set True so that only the freezing rules
3717 -- are checked. Note that the case of stream attributes is not clear
3718 -- from the RM, but see AI95-00137. Also, the RM seems to disallow
3719 -- Storage_Size for derived task types, but that is also clearly
3722 procedure Analyze_Stream_TSS_Definition
(TSS_Nam
: TSS_Name_Type
);
3723 -- Common processing for 'Read, 'Write, 'Input and 'Output attribute
3724 -- definition clauses.
3726 function Duplicate_Clause
return Boolean;
3727 -- This routine checks if the aspect for U_Ent being given by attribute
3728 -- definition clause N is for an aspect that has already been specified,
3729 -- and if so gives an error message. If there is a duplicate, True is
3730 -- returned, otherwise if there is no error, False is returned.
3732 procedure Check_Indexing_Functions
;
3733 -- Check that the function in Constant_Indexing or Variable_Indexing
3734 -- attribute has the proper type structure. If the name is overloaded,
3735 -- check that some interpretation is legal.
3737 procedure Check_Iterator_Functions
;
3738 -- Check that there is a single function in Default_Iterator attribute
3739 -- has the proper type structure.
3741 function Check_Primitive_Function
(Subp
: Entity_Id
) return Boolean;
3742 -- Common legality check for the previous two
3744 -----------------------------------
3745 -- Analyze_Stream_TSS_Definition --
3746 -----------------------------------
3748 procedure Analyze_Stream_TSS_Definition
(TSS_Nam
: TSS_Name_Type
) is
3749 Subp
: Entity_Id
:= Empty
;
3754 Is_Read
: constant Boolean := (TSS_Nam
= TSS_Stream_Read
);
3755 -- True for Read attribute, false for other attributes
3757 function Has_Good_Profile
(Subp
: Entity_Id
) return Boolean;
3758 -- Return true if the entity is a subprogram with an appropriate
3759 -- profile for the attribute being defined.
3761 ----------------------
3762 -- Has_Good_Profile --
3763 ----------------------
3765 function Has_Good_Profile
(Subp
: Entity_Id
) return Boolean is
3767 Is_Function
: constant Boolean := (TSS_Nam
= TSS_Stream_Input
);
3768 Expected_Ekind
: constant array (Boolean) of Entity_Kind
:=
3769 (False => E_Procedure
, True => E_Function
);
3773 if Ekind
(Subp
) /= Expected_Ekind
(Is_Function
) then
3777 F
:= First_Formal
(Subp
);
3780 or else Ekind
(Etype
(F
)) /= E_Anonymous_Access_Type
3781 or else Designated_Type
(Etype
(F
)) /=
3782 Class_Wide_Type
(RTE
(RE_Root_Stream_Type
))
3787 if not Is_Function
then
3791 Expected_Mode
: constant array (Boolean) of Entity_Kind
:=
3792 (False => E_In_Parameter
,
3793 True => E_Out_Parameter
);
3795 if Parameter_Mode
(F
) /= Expected_Mode
(Is_Read
) then
3802 -- If the attribute specification comes from an aspect
3803 -- specification for a class-wide stream, the parameter must be
3804 -- a class-wide type of the entity to which the aspect applies.
3806 if From_Aspect_Specification
(N
)
3807 and then Class_Present
(Parent
(N
))
3808 and then Is_Class_Wide_Type
(Typ
)
3814 Typ
:= Etype
(Subp
);
3817 -- Verify that the prefix of the attribute and the local name for
3818 -- the type of the formal match, or one is the class-wide of the
3819 -- other, in the case of a class-wide stream operation.
3821 if Base_Type
(Typ
) = Base_Type
(Ent
)
3822 or else (Is_Class_Wide_Type
(Typ
)
3823 and then Typ
= Class_Wide_Type
(Base_Type
(Ent
)))
3824 or else (Is_Class_Wide_Type
(Ent
)
3825 and then Ent
= Class_Wide_Type
(Base_Type
(Typ
)))
3832 if Present
((Next_Formal
(F
)))
3836 elsif not Is_Scalar_Type
(Typ
)
3837 and then not Is_First_Subtype
(Typ
)
3838 and then not Is_Class_Wide_Type
(Typ
)
3845 end Has_Good_Profile
;
3847 -- Start of processing for Analyze_Stream_TSS_Definition
3852 if not Is_Type
(U_Ent
) then
3853 Error_Msg_N
("local name must be a subtype", Nam
);
3856 elsif not Is_First_Subtype
(U_Ent
) then
3857 Error_Msg_N
("local name must be a first subtype", Nam
);
3861 Pnam
:= TSS
(Base_Type
(U_Ent
), TSS_Nam
);
3863 -- If Pnam is present, it can be either inherited from an ancestor
3864 -- type (in which case it is legal to redefine it for this type), or
3865 -- be a previous definition of the attribute for the same type (in
3866 -- which case it is illegal).
3868 -- In the first case, it will have been analyzed already, and we
3869 -- can check that its profile does not match the expected profile
3870 -- for a stream attribute of U_Ent. In the second case, either Pnam
3871 -- has been analyzed (and has the expected profile), or it has not
3872 -- been analyzed yet (case of a type that has not been frozen yet
3873 -- and for which the stream attribute has been set using Set_TSS).
3876 and then (No
(First_Entity
(Pnam
)) or else Has_Good_Profile
(Pnam
))
3878 Error_Msg_Sloc
:= Sloc
(Pnam
);
3879 Error_Msg_Name_1
:= Attr
;
3880 Error_Msg_N
("% attribute already defined #", Nam
);
3886 if Is_Entity_Name
(Expr
) then
3887 if not Is_Overloaded
(Expr
) then
3888 if Has_Good_Profile
(Entity
(Expr
)) then
3889 Subp
:= Entity
(Expr
);
3893 Get_First_Interp
(Expr
, I
, It
);
3894 while Present
(It
.Nam
) loop
3895 if Has_Good_Profile
(It
.Nam
) then
3900 Get_Next_Interp
(I
, It
);
3905 if Present
(Subp
) then
3906 if Is_Abstract_Subprogram
(Subp
) then
3907 Error_Msg_N
("stream subprogram must not be abstract", Expr
);
3910 -- A stream subprogram for an interface type must be a null
3911 -- procedure (RM 13.13.2 (38/3)).
3913 elsif Is_Interface
(U_Ent
)
3914 and then not Is_Class_Wide_Type
(U_Ent
)
3915 and then not Inside_A_Generic
3917 (Ekind
(Subp
) = E_Function
3921 (Unit_Declaration_Node
(Ultimate_Alias
(Subp
)))))
3924 ("stream subprogram for interface type "
3925 & "must be null procedure", Expr
);
3928 Set_Entity
(Expr
, Subp
);
3929 Set_Etype
(Expr
, Etype
(Subp
));
3931 New_Stream_Subprogram
(N
, U_Ent
, Subp
, TSS_Nam
);
3934 Error_Msg_Name_1
:= Attr
;
3935 Error_Msg_N
("incorrect expression for% attribute", Expr
);
3937 end Analyze_Stream_TSS_Definition
;
3939 ------------------------------
3940 -- Check_Indexing_Functions --
3941 ------------------------------
3943 procedure Check_Indexing_Functions
is
3944 Indexing_Found
: Boolean := False;
3946 procedure Check_Inherited_Indexing
;
3947 -- For a derived type, check that no indexing aspect is specified
3948 -- for the type if it is also inherited
3950 procedure Check_One_Function
(Subp
: Entity_Id
);
3951 -- Check one possible interpretation. Sets Indexing_Found True if a
3952 -- legal indexing function is found.
3954 procedure Illegal_Indexing
(Msg
: String);
3955 -- Diagnose illegal indexing function if not overloaded. In the
3956 -- overloaded case indicate that no legal interpretation exists.
3958 ------------------------------
3959 -- Check_Inherited_Indexing --
3960 ------------------------------
3962 procedure Check_Inherited_Indexing
is
3963 Inherited
: Node_Id
;
3966 if Attr
= Name_Constant_Indexing
then
3968 Find_Aspect
(Etype
(Ent
), Aspect_Constant_Indexing
);
3969 else pragma Assert
(Attr
= Name_Variable_Indexing
);
3971 Find_Aspect
(Etype
(Ent
), Aspect_Variable_Indexing
);
3974 if Present
(Inherited
) then
3975 if Debug_Flag_Dot_XX
then
3978 -- OK if current attribute_definition_clause is expansion of
3979 -- inherited aspect.
3981 elsif Aspect_Rep_Item
(Inherited
) = N
then
3984 -- Indicate the operation that must be overridden, rather than
3985 -- redefining the indexing aspect.
3989 ("indexing function already inherited from parent type");
3991 ("!override & instead",
3992 N
, Entity
(Expression
(Inherited
)));
3995 end Check_Inherited_Indexing
;
3997 ------------------------
3998 -- Check_One_Function --
3999 ------------------------
4001 procedure Check_One_Function
(Subp
: Entity_Id
) is
4002 Default_Element
: Node_Id
;
4003 Ret_Type
: constant Entity_Id
:= Etype
(Subp
);
4006 if not Is_Overloadable
(Subp
) then
4007 Illegal_Indexing
("illegal indexing function for type&");
4010 elsif Scope
(Subp
) /= Scope
(Ent
) then
4011 if Nkind
(Expr
) = N_Expanded_Name
then
4013 -- Indexing function can't be declared elsewhere
4016 ("indexing function must be declared in scope of type&");
4021 elsif No
(First_Formal
(Subp
)) then
4023 ("Indexing requires a function that applies to type&");
4026 elsif No
(Next_Formal
(First_Formal
(Subp
))) then
4028 ("indexing function must have at least two parameters");
4031 elsif Is_Derived_Type
(Ent
) then
4032 Check_Inherited_Indexing
;
4035 if not Check_Primitive_Function
(Subp
) then
4037 ("Indexing aspect requires a function that applies to type&");
4041 -- If partial declaration exists, verify that it is not tagged.
4043 if Ekind
(Current_Scope
) = E_Package
4044 and then Has_Private_Declaration
(Ent
)
4045 and then From_Aspect_Specification
(N
)
4047 List_Containing
(Parent
(Ent
)) =
4048 Private_Declarations
4049 (Specification
(Unit_Declaration_Node
(Current_Scope
)))
4050 and then Nkind
(N
) = N_Attribute_Definition_Clause
4057 First
(Visible_Declarations
4059 (Unit_Declaration_Node
(Current_Scope
))));
4061 while Present
(Decl
) loop
4062 if Nkind
(Decl
) = N_Private_Type_Declaration
4063 and then Ent
= Full_View
(Defining_Identifier
(Decl
))
4064 and then Tagged_Present
(Decl
)
4065 and then No
(Aspect_Specifications
(Decl
))
4068 ("Indexing aspect cannot be specified on full view "
4069 & "if partial view is tagged");
4078 -- An indexing function must return either the default element of
4079 -- the container, or a reference type. For variable indexing it
4080 -- must be the latter.
4083 Find_Value_Of_Aspect
4084 (Etype
(First_Formal
(Subp
)), Aspect_Iterator_Element
);
4086 if Present
(Default_Element
) then
4087 Analyze
(Default_Element
);
4089 if Is_Entity_Name
(Default_Element
)
4090 and then not Covers
(Entity
(Default_Element
), Ret_Type
)
4094 ("wrong return type for indexing function");
4099 -- For variable_indexing the return type must be a reference type
4101 if Attr
= Name_Variable_Indexing
then
4102 if not Has_Implicit_Dereference
(Ret_Type
) then
4104 ("variable indexing must return a reference type");
4107 elsif Is_Access_Constant
4108 (Etype
(First_Discriminant
(Ret_Type
)))
4111 ("variable indexing must return an access to variable");
4116 if Has_Implicit_Dereference
(Ret_Type
)
4118 Is_Access_Constant
(Etype
(First_Discriminant
(Ret_Type
)))
4121 ("constant indexing must return an access to constant");
4124 elsif Is_Access_Type
(Etype
(First_Formal
(Subp
)))
4125 and then not Is_Access_Constant
(Etype
(First_Formal
(Subp
)))
4128 ("constant indexing must apply to an access to constant");
4133 -- All checks succeeded.
4135 Indexing_Found
:= True;
4136 end Check_One_Function
;
4138 -----------------------
4139 -- Illegal_Indexing --
4140 -----------------------
4142 procedure Illegal_Indexing
(Msg
: String) is
4144 Error_Msg_NE
(Msg
, N
, Ent
);
4145 end Illegal_Indexing
;
4147 -- Start of processing for Check_Indexing_Functions
4151 Check_Inherited_Indexing
;
4156 if not Is_Overloaded
(Expr
) then
4157 Check_One_Function
(Entity
(Expr
));
4165 Indexing_Found
:= False;
4166 Get_First_Interp
(Expr
, I
, It
);
4167 while Present
(It
.Nam
) loop
4169 -- Note that analysis will have added the interpretation
4170 -- that corresponds to the dereference. We only check the
4171 -- subprogram itself.
4173 if Is_Overloadable
(It
.Nam
) then
4174 Check_One_Function
(It
.Nam
);
4177 Get_Next_Interp
(I
, It
);
4182 if not Indexing_Found
and then not Error_Posted
(N
) then
4184 ("aspect Indexing requires a local function that "
4185 & "applies to type&", Expr
, Ent
);
4187 end Check_Indexing_Functions
;
4189 ------------------------------
4190 -- Check_Iterator_Functions --
4191 ------------------------------
4193 procedure Check_Iterator_Functions
is
4194 function Valid_Default_Iterator
(Subp
: Entity_Id
) return Boolean;
4195 -- Check one possible interpretation for validity
4197 ----------------------------
4198 -- Valid_Default_Iterator --
4199 ----------------------------
4201 function Valid_Default_Iterator
(Subp
: Entity_Id
) return Boolean is
4205 if not Check_Primitive_Function
(Subp
) then
4208 Formal
:= First_Formal
(Subp
);
4211 -- False if any subsequent formal has no default expression
4213 Formal
:= Next_Formal
(Formal
);
4214 while Present
(Formal
) loop
4215 if No
(Expression
(Parent
(Formal
))) then
4219 Next_Formal
(Formal
);
4222 -- True if all subsequent formals have default expressions
4225 end Valid_Default_Iterator
;
4227 -- Start of processing for Check_Iterator_Functions
4232 if not Is_Entity_Name
(Expr
) then
4233 Error_Msg_N
("aspect Iterator must be a function name", Expr
);
4236 if not Is_Overloaded
(Expr
) then
4237 if not Check_Primitive_Function
(Entity
(Expr
)) then
4239 ("aspect Indexing requires a function that applies to type&",
4240 Entity
(Expr
), Ent
);
4243 -- Flag the default_iterator as well as the denoted function.
4245 if not Valid_Default_Iterator
(Entity
(Expr
)) then
4246 Error_Msg_N
("improper function for default iterator!", Expr
);
4251 Default
: Entity_Id
:= Empty
;
4256 Get_First_Interp
(Expr
, I
, It
);
4257 while Present
(It
.Nam
) loop
4258 if not Check_Primitive_Function
(It
.Nam
)
4259 or else not Valid_Default_Iterator
(It
.Nam
)
4263 elsif Present
(Default
) then
4265 -- An explicit one should override an implicit one
4267 if Comes_From_Source
(Default
) =
4268 Comes_From_Source
(It
.Nam
)
4270 Error_Msg_N
("default iterator must be unique", Expr
);
4271 Error_Msg_Sloc
:= Sloc
(Default
);
4272 Error_Msg_N
("\\possible interpretation#", Expr
);
4273 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
4274 Error_Msg_N
("\\possible interpretation#", Expr
);
4276 elsif Comes_From_Source
(It
.Nam
) then
4283 Get_Next_Interp
(I
, It
);
4286 if Present
(Default
) then
4287 Set_Entity
(Expr
, Default
);
4288 Set_Is_Overloaded
(Expr
, False);
4292 end Check_Iterator_Functions
;
4294 -------------------------------
4295 -- Check_Primitive_Function --
4296 -------------------------------
4298 function Check_Primitive_Function
(Subp
: Entity_Id
) return Boolean is
4302 if Ekind
(Subp
) /= E_Function
then
4306 if No
(First_Formal
(Subp
)) then
4309 Ctrl
:= Etype
(First_Formal
(Subp
));
4312 -- To be a primitive operation subprogram has to be in same scope.
4314 if Scope
(Ctrl
) /= Scope
(Subp
) then
4318 -- Type of formal may be the class-wide type, an access to such,
4319 -- or an incomplete view.
4322 or else Ctrl
= Class_Wide_Type
(Ent
)
4324 (Ekind
(Ctrl
) = E_Anonymous_Access_Type
4325 and then (Designated_Type
(Ctrl
) = Ent
4327 Designated_Type
(Ctrl
) = Class_Wide_Type
(Ent
)))
4329 (Ekind
(Ctrl
) = E_Incomplete_Type
4330 and then Full_View
(Ctrl
) = Ent
)
4338 end Check_Primitive_Function
;
4340 ----------------------
4341 -- Duplicate_Clause --
4342 ----------------------
4344 function Duplicate_Clause
return Boolean is
4348 -- Nothing to do if this attribute definition clause comes from
4349 -- an aspect specification, since we could not be duplicating an
4350 -- explicit clause, and we dealt with the case of duplicated aspects
4351 -- in Analyze_Aspect_Specifications.
4353 if From_Aspect_Specification
(N
) then
4357 -- Otherwise current clause may duplicate previous clause, or a
4358 -- previously given pragma or aspect specification for the same
4361 A
:= Get_Rep_Item
(U_Ent
, Chars
(N
), Check_Parents
=> False);
4364 Error_Msg_Name_1
:= Chars
(N
);
4365 Error_Msg_Sloc
:= Sloc
(A
);
4367 Error_Msg_NE
("aspect% for & previously given#", N
, U_Ent
);
4372 end Duplicate_Clause
;
4374 -- Start of processing for Analyze_Attribute_Definition_Clause
4377 -- The following code is a defense against recursion. Not clear that
4378 -- this can happen legitimately, but perhaps some error situations can
4379 -- cause it, and we did see this recursion during testing.
4381 if Analyzed
(N
) then
4384 Set_Analyzed
(N
, True);
4387 -- Ignore some selected attributes in CodePeer mode since they are not
4388 -- relevant in this context.
4390 if CodePeer_Mode
then
4393 -- Ignore Component_Size in CodePeer mode, to avoid changing the
4394 -- internal representation of types by implicitly packing them.
4396 when Attribute_Component_Size
=>
4397 Rewrite
(N
, Make_Null_Statement
(Sloc
(N
)));
4405 -- Process Ignore_Rep_Clauses option
4407 if Ignore_Rep_Clauses
then
4410 -- The following should be ignored. They do not affect legality
4411 -- and may be target dependent. The basic idea of -gnatI is to
4412 -- ignore any rep clauses that may be target dependent but do not
4413 -- affect legality (except possibly to be rejected because they
4414 -- are incompatible with the compilation target).
4416 when Attribute_Alignment |
4417 Attribute_Bit_Order |
4418 Attribute_Component_Size |
4419 Attribute_Machine_Radix |
4420 Attribute_Object_Size |
4423 Attribute_Stream_Size |
4424 Attribute_Value_Size
=>
4425 Kill_Rep_Clause
(N
);
4428 -- The following should not be ignored, because in the first place
4429 -- they are reasonably portable, and should not cause problems
4430 -- in compiling code from another target, and also they do affect
4431 -- legality, e.g. failing to provide a stream attribute for a type
4432 -- may make a program illegal.
4434 when Attribute_External_Tag |
4438 Attribute_Simple_Storage_Pool |
4439 Attribute_Storage_Pool |
4440 Attribute_Storage_Size |
4444 -- We do not do anything here with address clauses, they will be
4445 -- removed by Freeze later on, but for now, it works better to
4446 -- keep then in the tree.
4448 when Attribute_Address
=>
4451 -- Other cases are errors ("attribute& cannot be set with
4452 -- definition clause"), which will be caught below.
4460 Ent
:= Entity
(Nam
);
4462 if Rep_Item_Too_Early
(Ent
, N
) then
4466 -- Rep clause applies to full view of incomplete type or private type if
4467 -- we have one (if not, this is a premature use of the type). However,
4468 -- certain semantic checks need to be done on the specified entity (i.e.
4469 -- the private view), so we save it in Ent.
4471 if Is_Private_Type
(Ent
)
4472 and then Is_Derived_Type
(Ent
)
4473 and then not Is_Tagged_Type
(Ent
)
4474 and then No
(Full_View
(Ent
))
4476 -- If this is a private type whose completion is a derivation from
4477 -- another private type, there is no full view, and the attribute
4478 -- belongs to the type itself, not its underlying parent.
4482 elsif Ekind
(Ent
) = E_Incomplete_Type
then
4484 -- The attribute applies to the full view, set the entity of the
4485 -- attribute definition accordingly.
4487 Ent
:= Underlying_Type
(Ent
);
4489 Set_Entity
(Nam
, Ent
);
4492 U_Ent
:= Underlying_Type
(Ent
);
4495 -- Avoid cascaded error
4497 if Etype
(Nam
) = Any_Type
then
4500 -- Must be declared in current scope or in case of an aspect
4501 -- specification, must be visible in current scope.
4503 elsif Scope
(Ent
) /= Current_Scope
4505 not (From_Aspect_Specification
(N
)
4506 and then Scope_Within_Or_Same
(Current_Scope
, Scope
(Ent
)))
4508 Error_Msg_N
("entity must be declared in this scope", Nam
);
4511 -- Must not be a source renaming (we do have some cases where the
4512 -- expander generates a renaming, and those cases are OK, in such
4513 -- cases any attribute applies to the renamed object as well).
4515 elsif Is_Object
(Ent
)
4516 and then Present
(Renamed_Object
(Ent
))
4518 -- Case of renamed object from source, this is an error
4520 if Comes_From_Source
(Renamed_Object
(Ent
)) then
4521 Get_Name_String
(Chars
(N
));
4522 Error_Msg_Strlen
:= Name_Len
;
4523 Error_Msg_String
(1 .. Name_Len
) := Name_Buffer
(1 .. Name_Len
);
4525 ("~ clause not allowed for a renaming declaration "
4526 & "(RM 13.1(6))", Nam
);
4529 -- For the case of a compiler generated renaming, the attribute
4530 -- definition clause applies to the renamed object created by the
4531 -- expander. The easiest general way to handle this is to create a
4532 -- copy of the attribute definition clause for this object.
4534 elsif Is_Entity_Name
(Renamed_Object
(Ent
)) then
4536 Make_Attribute_Definition_Clause
(Loc
,
4538 New_Occurrence_Of
(Entity
(Renamed_Object
(Ent
)), Loc
),
4540 Expression
=> Duplicate_Subexpr
(Expression
(N
))));
4542 -- If the renamed object is not an entity, it must be a dereference
4543 -- of an unconstrained function call, and we must introduce a new
4544 -- declaration to capture the expression. This is needed in the case
4545 -- of 'Alignment, where the original declaration must be rewritten.
4549 (Nkind
(Renamed_Object
(Ent
)) = N_Explicit_Dereference
);
4553 -- If no underlying entity, use entity itself, applies to some
4554 -- previously detected error cases ???
4556 elsif No
(U_Ent
) then
4559 -- Cannot specify for a subtype (exception Object/Value_Size)
4561 elsif Is_Type
(U_Ent
)
4562 and then not Is_First_Subtype
(U_Ent
)
4563 and then Id
/= Attribute_Object_Size
4564 and then Id
/= Attribute_Value_Size
4565 and then not From_At_Mod
(N
)
4567 Error_Msg_N
("cannot specify attribute for subtype", Nam
);
4571 Set_Entity
(N
, U_Ent
);
4572 Check_Restriction_No_Use_Of_Attribute
(N
);
4574 -- Switch on particular attribute
4582 -- Address attribute definition clause
4584 when Attribute_Address
=> Address
: begin
4586 -- A little error check, catch for X'Address use X'Address;
4588 if Nkind
(Nam
) = N_Identifier
4589 and then Nkind
(Expr
) = N_Attribute_Reference
4590 and then Attribute_Name
(Expr
) = Name_Address
4591 and then Nkind
(Prefix
(Expr
)) = N_Identifier
4592 and then Chars
(Nam
) = Chars
(Prefix
(Expr
))
4595 ("address for & is self-referencing", Prefix
(Expr
), Ent
);
4599 -- Not that special case, carry on with analysis of expression
4601 Analyze_And_Resolve
(Expr
, RTE
(RE_Address
));
4603 -- Even when ignoring rep clauses we need to indicate that the
4604 -- entity has an address clause and thus it is legal to declare
4605 -- it imported. Freeze will get rid of the address clause later.
4607 if Ignore_Rep_Clauses
then
4608 if Ekind_In
(U_Ent
, E_Variable
, E_Constant
) then
4609 Record_Rep_Item
(U_Ent
, N
);
4615 if Duplicate_Clause
then
4618 -- Case of address clause for subprogram
4620 elsif Is_Subprogram
(U_Ent
) then
4621 if Has_Homonym
(U_Ent
) then
4623 ("address clause cannot be given " &
4624 "for overloaded subprogram",
4629 -- For subprograms, all address clauses are permitted, and we
4630 -- mark the subprogram as having a deferred freeze so that Gigi
4631 -- will not elaborate it too soon.
4633 -- Above needs more comments, what is too soon about???
4635 Set_Has_Delayed_Freeze
(U_Ent
);
4637 -- Case of address clause for entry
4639 elsif Ekind
(U_Ent
) = E_Entry
then
4640 if Nkind
(Parent
(N
)) = N_Task_Body
then
4642 ("entry address must be specified in task spec", Nam
);
4646 -- For entries, we require a constant address
4648 Check_Constant_Address_Clause
(Expr
, U_Ent
);
4650 -- Special checks for task types
4652 if Is_Task_Type
(Scope
(U_Ent
))
4653 and then Comes_From_Source
(Scope
(U_Ent
))
4656 ("??entry address declared for entry in task type", N
);
4658 ("\??only one task can be declared of this type", N
);
4661 -- Entry address clauses are obsolescent
4663 Check_Restriction
(No_Obsolescent_Features
, N
);
4665 if Warn_On_Obsolescent_Feature
then
4667 ("?j?attaching interrupt to task entry is an " &
4668 "obsolescent feature (RM J.7.1)", N
);
4670 ("\?j?use interrupt procedure instead", N
);
4673 -- Case of an address clause for a controlled object which we
4674 -- consider to be erroneous.
4676 elsif Is_Controlled
(Etype
(U_Ent
))
4677 or else Has_Controlled_Component
(Etype
(U_Ent
))
4680 ("??controlled object& must not be overlaid", Nam
, U_Ent
);
4682 ("\??Program_Error will be raised at run time", Nam
);
4683 Insert_Action
(Declaration_Node
(U_Ent
),
4684 Make_Raise_Program_Error
(Loc
,
4685 Reason
=> PE_Overlaid_Controlled_Object
));
4688 -- Case of address clause for a (non-controlled) object
4690 elsif Ekind_In
(U_Ent
, E_Variable
, E_Constant
) then
4692 Expr
: constant Node_Id
:= Expression
(N
);
4697 -- Exported variables cannot have an address clause, because
4698 -- this cancels the effect of the pragma Export.
4700 if Is_Exported
(U_Ent
) then
4702 ("cannot export object with address clause", Nam
);
4706 Find_Overlaid_Entity
(N
, O_Ent
, Off
);
4708 if Present
(O_Ent
) then
4710 -- If the object overlays a constant object, mark it so
4712 if Is_Constant_Object
(O_Ent
) then
4713 Set_Overlays_Constant
(U_Ent
);
4717 -- If this is not an overlay, mark a variable as being
4718 -- volatile to prevent unwanted optimizations. It's a
4719 -- conservative interpretation of RM 13.3(19) for the
4720 -- cases where the compiler cannot detect potential
4721 -- aliasing issues easily and it also covers the case
4722 -- of an absolute address where the volatile aspect is
4723 -- kind of implicit.
4725 if Ekind
(U_Ent
) = E_Variable
then
4726 Set_Treat_As_Volatile
(U_Ent
);
4730 -- Overlaying controlled objects is erroneous. Emit warning
4731 -- but continue analysis because program is itself legal,
4732 -- and back end must see address clause.
4735 and then (Has_Controlled_Component
(Etype
(O_Ent
))
4736 or else Is_Controlled
(Etype
(O_Ent
)))
4737 and then not Inside_A_Generic
4740 ("??cannot use overlays with controlled objects", Expr
);
4742 ("\??Program_Error will be raised at run time", Expr
);
4743 Insert_Action
(Declaration_Node
(U_Ent
),
4744 Make_Raise_Program_Error
(Loc
,
4745 Reason
=> PE_Overlaid_Controlled_Object
));
4747 -- Issue an unconditional warning for a constant overlaying
4748 -- a variable. For the reverse case, we will issue it only
4749 -- if the variable is modified.
4751 elsif Ekind
(U_Ent
) = E_Constant
4752 and then Present
(O_Ent
)
4753 and then not Overlays_Constant
(U_Ent
)
4754 and then Address_Clause_Overlay_Warnings
4756 Error_Msg_N
("??constant overlays a variable", Expr
);
4758 -- Imported variables can have an address clause, but then
4759 -- the import is pretty meaningless except to suppress
4760 -- initializations, so we do not need such variables to
4761 -- be statically allocated (and in fact it causes trouble
4762 -- if the address clause is a local value).
4764 elsif Is_Imported
(U_Ent
) then
4765 Set_Is_Statically_Allocated
(U_Ent
, False);
4768 -- We mark a possible modification of a variable with an
4769 -- address clause, since it is likely aliasing is occurring.
4771 Note_Possible_Modification
(Nam
, Sure
=> False);
4773 -- Legality checks on the address clause for initialized
4774 -- objects is deferred until the freeze point, because
4775 -- a subsequent pragma might indicate that the object
4776 -- is imported and thus not initialized. Also, the address
4777 -- clause might involve entities that have yet to be
4780 Set_Has_Delayed_Freeze
(U_Ent
);
4782 -- If an initialization call has been generated for this
4783 -- object, it needs to be deferred to after the freeze node
4784 -- we have just now added, otherwise GIGI will see a
4785 -- reference to the variable (as actual to the IP call)
4786 -- before its definition.
4789 Init_Call
: constant Node_Id
:=
4790 Remove_Init_Call
(U_Ent
, N
);
4793 if Present
(Init_Call
) then
4794 Append_Freeze_Action
(U_Ent
, Init_Call
);
4796 -- Reset Initialization_Statements pointer so that
4797 -- if there is a pragma Import further down, it can
4798 -- clear any default initialization.
4800 Set_Initialization_Statements
(U_Ent
, Init_Call
);
4804 -- Entity has delayed freeze, so we will generate an
4805 -- alignment check at the freeze point unless suppressed.
4807 if not Range_Checks_Suppressed
(U_Ent
)
4808 and then not Alignment_Checks_Suppressed
(U_Ent
)
4810 Set_Check_Address_Alignment
(N
);
4813 -- Kill the size check code, since we are not allocating
4814 -- the variable, it is somewhere else.
4816 Kill_Size_Check_Code
(U_Ent
);
4818 -- If the address clause is of the form:
4820 -- for Y'Address use X'Address
4824 -- Const : constant Address := X'Address;
4826 -- for Y'Address use Const;
4828 -- then we make an entry in the table for checking the size
4829 -- and alignment of the overlaying variable. We defer this
4830 -- check till after code generation to take full advantage
4831 -- of the annotation done by the back end.
4833 -- If the entity has a generic type, the check will be
4834 -- performed in the instance if the actual type justifies
4835 -- it, and we do not insert the clause in the table to
4836 -- prevent spurious warnings.
4838 -- Note: we used to test Comes_From_Source and only give
4839 -- this warning for source entities, but we have removed
4840 -- this test. It really seems bogus to generate overlays
4841 -- that would trigger this warning in generated code.
4842 -- Furthermore, by removing the test, we handle the
4843 -- aspect case properly.
4846 and then Is_Object
(O_Ent
)
4847 and then not Is_Generic_Type
(Etype
(U_Ent
))
4848 and then Address_Clause_Overlay_Warnings
4850 Address_Clause_Checks
.Append
((N
, U_Ent
, O_Ent
, Off
));
4854 -- Not a valid entity for an address clause
4857 Error_Msg_N
("address cannot be given for &", Nam
);
4865 -- Alignment attribute definition clause
4867 when Attribute_Alignment
=> Alignment
: declare
4868 Align
: constant Uint
:= Get_Alignment_Value
(Expr
);
4869 Max_Align
: constant Uint
:= UI_From_Int
(Maximum_Alignment
);
4874 if not Is_Type
(U_Ent
)
4875 and then Ekind
(U_Ent
) /= E_Variable
4876 and then Ekind
(U_Ent
) /= E_Constant
4878 Error_Msg_N
("alignment cannot be given for &", Nam
);
4880 elsif Duplicate_Clause
then
4883 elsif Align
/= No_Uint
then
4884 Set_Has_Alignment_Clause
(U_Ent
);
4886 -- Tagged type case, check for attempt to set alignment to a
4887 -- value greater than Max_Align, and reset if so.
4889 if Is_Tagged_Type
(U_Ent
) and then Align
> Max_Align
then
4891 ("alignment for & set to Maximum_Aligment??", Nam
);
4892 Set_Alignment
(U_Ent
, Max_Align
);
4897 Set_Alignment
(U_Ent
, Align
);
4900 -- For an array type, U_Ent is the first subtype. In that case,
4901 -- also set the alignment of the anonymous base type so that
4902 -- other subtypes (such as the itypes for aggregates of the
4903 -- type) also receive the expected alignment.
4905 if Is_Array_Type
(U_Ent
) then
4906 Set_Alignment
(Base_Type
(U_Ent
), Align
);
4915 -- Bit_Order attribute definition clause
4917 when Attribute_Bit_Order
=> Bit_Order
: declare
4919 if not Is_Record_Type
(U_Ent
) then
4921 ("Bit_Order can only be defined for record type", Nam
);
4923 elsif Duplicate_Clause
then
4927 Analyze_And_Resolve
(Expr
, RTE
(RE_Bit_Order
));
4929 if Etype
(Expr
) = Any_Type
then
4932 elsif not Is_OK_Static_Expression
(Expr
) then
4933 Flag_Non_Static_Expr
4934 ("Bit_Order requires static expression!", Expr
);
4937 if (Expr_Value
(Expr
) = 0) /= Bytes_Big_Endian
then
4938 Set_Reverse_Bit_Order
(Base_Type
(U_Ent
), True);
4944 --------------------
4945 -- Component_Size --
4946 --------------------
4948 -- Component_Size attribute definition clause
4950 when Attribute_Component_Size
=> Component_Size_Case
: declare
4951 Csize
: constant Uint
:= Static_Integer
(Expr
);
4955 New_Ctyp
: Entity_Id
;
4959 if not Is_Array_Type
(U_Ent
) then
4960 Error_Msg_N
("component size requires array type", Nam
);
4964 Btype
:= Base_Type
(U_Ent
);
4965 Ctyp
:= Component_Type
(Btype
);
4967 if Duplicate_Clause
then
4970 elsif Rep_Item_Too_Early
(Btype
, N
) then
4973 elsif Csize
/= No_Uint
then
4974 Check_Size
(Expr
, Ctyp
, Csize
, Biased
);
4976 -- For the biased case, build a declaration for a subtype that
4977 -- will be used to represent the biased subtype that reflects
4978 -- the biased representation of components. We need the subtype
4979 -- to get proper conversions on referencing elements of the
4984 Make_Defining_Identifier
(Loc
,
4986 New_External_Name
(Chars
(U_Ent
), 'C', 0, 'T'));
4989 Make_Subtype_Declaration
(Loc
,
4990 Defining_Identifier
=> New_Ctyp
,
4991 Subtype_Indication
=>
4992 New_Occurrence_Of
(Component_Type
(Btype
), Loc
));
4994 Set_Parent
(Decl
, N
);
4995 Analyze
(Decl
, Suppress
=> All_Checks
);
4997 Set_Has_Delayed_Freeze
(New_Ctyp
, False);
4998 Set_Esize
(New_Ctyp
, Csize
);
4999 Set_RM_Size
(New_Ctyp
, Csize
);
5000 Init_Alignment
(New_Ctyp
);
5001 Set_Is_Itype
(New_Ctyp
, True);
5002 Set_Associated_Node_For_Itype
(New_Ctyp
, U_Ent
);
5004 Set_Component_Type
(Btype
, New_Ctyp
);
5005 Set_Biased
(New_Ctyp
, N
, "component size clause");
5008 Set_Component_Size
(Btype
, Csize
);
5010 -- Deal with warning on overridden size
5012 if Warn_On_Overridden_Size
5013 and then Has_Size_Clause
(Ctyp
)
5014 and then RM_Size
(Ctyp
) /= Csize
5017 ("component size overrides size clause for&?S?", N
, Ctyp
);
5020 Set_Has_Component_Size_Clause
(Btype
, True);
5021 Set_Has_Non_Standard_Rep
(Btype
, True);
5023 end Component_Size_Case
;
5025 -----------------------
5026 -- Constant_Indexing --
5027 -----------------------
5029 when Attribute_Constant_Indexing
=>
5030 Check_Indexing_Functions
;
5036 when Attribute_CPU
=> CPU
:
5038 -- CPU attribute definition clause not allowed except from aspect
5041 if From_Aspect_Specification
(N
) then
5042 if not Is_Task_Type
(U_Ent
) then
5043 Error_Msg_N
("CPU can only be defined for task", Nam
);
5045 elsif Duplicate_Clause
then
5049 -- The expression must be analyzed in the special manner
5050 -- described in "Handling of Default and Per-Object
5051 -- Expressions" in sem.ads.
5053 -- The visibility to the discriminants must be restored
5055 Push_Scope_And_Install_Discriminants
(U_Ent
);
5056 Preanalyze_Spec_Expression
(Expr
, RTE
(RE_CPU_Range
));
5057 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
5059 if not Is_OK_Static_Expression
(Expr
) then
5060 Check_Restriction
(Static_Priorities
, Expr
);
5066 ("attribute& cannot be set with definition clause", N
);
5070 ----------------------
5071 -- Default_Iterator --
5072 ----------------------
5074 when Attribute_Default_Iterator
=> Default_Iterator
: declare
5079 -- If target type is untagged, further checks are irrelevant
5081 if not Is_Tagged_Type
(U_Ent
) then
5083 ("aspect Default_Iterator applies to tagged type", Nam
);
5087 Check_Iterator_Functions
;
5091 if not Is_Entity_Name
(Expr
)
5092 or else Ekind
(Entity
(Expr
)) /= E_Function
5094 Error_Msg_N
("aspect Iterator must be a function", Expr
);
5097 Func
:= Entity
(Expr
);
5100 -- The type of the first parameter must be T, T'class, or a
5101 -- corresponding access type (5.5.1 (8/3). If function is
5102 -- parameterless label type accordingly.
5104 if No
(First_Formal
(Func
)) then
5107 Typ
:= Etype
(First_Formal
(Func
));
5111 or else Typ
= Class_Wide_Type
(U_Ent
)
5112 or else (Is_Access_Type
(Typ
)
5113 and then Designated_Type
(Typ
) = U_Ent
)
5114 or else (Is_Access_Type
(Typ
)
5115 and then Designated_Type
(Typ
) =
5116 Class_Wide_Type
(U_Ent
))
5122 ("Default Iterator must be a primitive of&", Func
, U_Ent
);
5124 end Default_Iterator
;
5126 ------------------------
5127 -- Dispatching_Domain --
5128 ------------------------
5130 when Attribute_Dispatching_Domain
=> Dispatching_Domain
:
5132 -- Dispatching_Domain attribute definition clause not allowed
5133 -- except from aspect specification.
5135 if From_Aspect_Specification
(N
) then
5136 if not Is_Task_Type
(U_Ent
) then
5138 ("Dispatching_Domain can only be defined for task", Nam
);
5140 elsif Duplicate_Clause
then
5144 -- The expression must be analyzed in the special manner
5145 -- described in "Handling of Default and Per-Object
5146 -- Expressions" in sem.ads.
5148 -- The visibility to the discriminants must be restored
5150 Push_Scope_And_Install_Discriminants
(U_Ent
);
5152 Preanalyze_Spec_Expression
5153 (Expr
, RTE
(RE_Dispatching_Domain
));
5155 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
5160 ("attribute& cannot be set with definition clause", N
);
5162 end Dispatching_Domain
;
5168 when Attribute_External_Tag
=> External_Tag
:
5170 if not Is_Tagged_Type
(U_Ent
) then
5171 Error_Msg_N
("should be a tagged type", Nam
);
5174 if Duplicate_Clause
then
5178 Analyze_And_Resolve
(Expr
, Standard_String
);
5180 if not Is_OK_Static_Expression
(Expr
) then
5181 Flag_Non_Static_Expr
5182 ("static string required for tag name!", Nam
);
5185 if not Is_Library_Level_Entity
(U_Ent
) then
5187 ("??non-unique external tag supplied for &", N
, U_Ent
);
5189 ("\??same external tag applies to all "
5190 & "subprogram calls", N
);
5192 ("\??corresponding internal tag cannot be obtained", N
);
5197 --------------------------
5198 -- Implicit_Dereference --
5199 --------------------------
5201 when Attribute_Implicit_Dereference
=>
5203 -- Legality checks already performed at the point of the type
5204 -- declaration, aspect is not delayed.
5212 when Attribute_Input
=>
5213 Analyze_Stream_TSS_Definition
(TSS_Stream_Input
);
5214 Set_Has_Specified_Stream_Input
(Ent
);
5216 ------------------------
5217 -- Interrupt_Priority --
5218 ------------------------
5220 when Attribute_Interrupt_Priority
=> Interrupt_Priority
:
5222 -- Interrupt_Priority attribute definition clause not allowed
5223 -- except from aspect specification.
5225 if From_Aspect_Specification
(N
) then
5226 if not Is_Concurrent_Type
(U_Ent
) then
5228 ("Interrupt_Priority can only be defined for task "
5229 & "and protected object", Nam
);
5231 elsif Duplicate_Clause
then
5235 -- The expression must be analyzed in the special manner
5236 -- described in "Handling of Default and Per-Object
5237 -- Expressions" in sem.ads.
5239 -- The visibility to the discriminants must be restored
5241 Push_Scope_And_Install_Discriminants
(U_Ent
);
5243 Preanalyze_Spec_Expression
5244 (Expr
, RTE
(RE_Interrupt_Priority
));
5246 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
5248 -- Check the No_Task_At_Interrupt_Priority restriction
5250 if Is_Task_Type
(U_Ent
) then
5251 Check_Restriction
(No_Task_At_Interrupt_Priority
, N
);
5257 ("attribute& cannot be set with definition clause", N
);
5259 end Interrupt_Priority
;
5265 when Attribute_Iterable
=>
5268 if Nkind
(Expr
) /= N_Aggregate
then
5269 Error_Msg_N
("aspect Iterable must be an aggregate", Expr
);
5276 Assoc
:= First
(Component_Associations
(Expr
));
5277 while Present
(Assoc
) loop
5278 if not Is_Entity_Name
(Expression
(Assoc
)) then
5279 Error_Msg_N
("value must be a function", Assoc
);
5286 ----------------------
5287 -- Iterator_Element --
5288 ----------------------
5290 when Attribute_Iterator_Element
=>
5293 if not Is_Entity_Name
(Expr
)
5294 or else not Is_Type
(Entity
(Expr
))
5296 Error_Msg_N
("aspect Iterator_Element must be a type", Expr
);
5303 -- Machine radix attribute definition clause
5305 when Attribute_Machine_Radix
=> Machine_Radix
: declare
5306 Radix
: constant Uint
:= Static_Integer
(Expr
);
5309 if not Is_Decimal_Fixed_Point_Type
(U_Ent
) then
5310 Error_Msg_N
("decimal fixed-point type expected for &", Nam
);
5312 elsif Duplicate_Clause
then
5315 elsif Radix
/= No_Uint
then
5316 Set_Has_Machine_Radix_Clause
(U_Ent
);
5317 Set_Has_Non_Standard_Rep
(Base_Type
(U_Ent
));
5321 elsif Radix
= 10 then
5322 Set_Machine_Radix_10
(U_Ent
);
5324 Error_Msg_N
("machine radix value must be 2 or 10", Expr
);
5333 -- Object_Size attribute definition clause
5335 when Attribute_Object_Size
=> Object_Size
: declare
5336 Size
: constant Uint
:= Static_Integer
(Expr
);
5339 pragma Warnings
(Off
, Biased
);
5342 if not Is_Type
(U_Ent
) then
5343 Error_Msg_N
("Object_Size cannot be given for &", Nam
);
5345 elsif Duplicate_Clause
then
5349 Check_Size
(Expr
, U_Ent
, Size
, Biased
);
5351 if Is_Scalar_Type
(U_Ent
) then
5352 if Size
/= 8 and then Size
/= 16 and then Size
/= 32
5353 and then UI_Mod
(Size
, 64) /= 0
5356 ("Object_Size must be 8, 16, 32, or multiple of 64",
5360 elsif Size
mod 8 /= 0 then
5361 Error_Msg_N
("Object_Size must be a multiple of 8", Expr
);
5364 Set_Esize
(U_Ent
, Size
);
5365 Set_Has_Object_Size_Clause
(U_Ent
);
5366 Alignment_Check_For_Size_Change
(U_Ent
, Size
);
5374 when Attribute_Output
=>
5375 Analyze_Stream_TSS_Definition
(TSS_Stream_Output
);
5376 Set_Has_Specified_Stream_Output
(Ent
);
5382 when Attribute_Priority
=> Priority
:
5384 -- Priority attribute definition clause not allowed except from
5385 -- aspect specification.
5387 if From_Aspect_Specification
(N
) then
5388 if not (Is_Concurrent_Type
(U_Ent
)
5389 or else Ekind
(U_Ent
) = E_Procedure
)
5392 ("Priority can only be defined for task and protected "
5395 elsif Duplicate_Clause
then
5399 -- The expression must be analyzed in the special manner
5400 -- described in "Handling of Default and Per-Object
5401 -- Expressions" in sem.ads.
5403 -- The visibility to the discriminants must be restored
5405 Push_Scope_And_Install_Discriminants
(U_Ent
);
5406 Preanalyze_Spec_Expression
(Expr
, Standard_Integer
);
5407 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
5409 if not Is_OK_Static_Expression
(Expr
) then
5410 Check_Restriction
(Static_Priorities
, Expr
);
5416 ("attribute& cannot be set with definition clause", N
);
5424 when Attribute_Read
=>
5425 Analyze_Stream_TSS_Definition
(TSS_Stream_Read
);
5426 Set_Has_Specified_Stream_Read
(Ent
);
5428 --------------------------
5429 -- Scalar_Storage_Order --
5430 --------------------------
5432 -- Scalar_Storage_Order attribute definition clause
5434 when Attribute_Scalar_Storage_Order
=> Scalar_Storage_Order
: declare
5436 if not (Is_Record_Type
(U_Ent
) or else Is_Array_Type
(U_Ent
)) then
5438 ("Scalar_Storage_Order can only be defined for "
5439 & "record or array type", Nam
);
5441 elsif Duplicate_Clause
then
5445 Analyze_And_Resolve
(Expr
, RTE
(RE_Bit_Order
));
5447 if Etype
(Expr
) = Any_Type
then
5450 elsif not Is_OK_Static_Expression
(Expr
) then
5451 Flag_Non_Static_Expr
5452 ("Scalar_Storage_Order requires static expression!", Expr
);
5454 elsif (Expr_Value
(Expr
) = 0) /= Bytes_Big_Endian
then
5456 -- Here for the case of a non-default (i.e. non-confirming)
5457 -- Scalar_Storage_Order attribute definition.
5459 if Support_Nondefault_SSO_On_Target
then
5460 Set_Reverse_Storage_Order
(Base_Type
(U_Ent
), True);
5463 ("non-default Scalar_Storage_Order "
5464 & "not supported on target", Expr
);
5468 -- Clear SSO default indications since explicit setting of the
5469 -- order overrides the defaults.
5471 Set_SSO_Set_Low_By_Default
(Base_Type
(U_Ent
), False);
5472 Set_SSO_Set_High_By_Default
(Base_Type
(U_Ent
), False);
5474 end Scalar_Storage_Order
;
5480 -- Size attribute definition clause
5482 when Attribute_Size
=> Size
: declare
5483 Size
: constant Uint
:= Static_Integer
(Expr
);
5490 if Duplicate_Clause
then
5493 elsif not Is_Type
(U_Ent
)
5494 and then Ekind
(U_Ent
) /= E_Variable
5495 and then Ekind
(U_Ent
) /= E_Constant
5497 Error_Msg_N
("size cannot be given for &", Nam
);
5499 elsif Is_Array_Type
(U_Ent
)
5500 and then not Is_Constrained
(U_Ent
)
5503 ("size cannot be given for unconstrained array", Nam
);
5505 elsif Size
/= No_Uint
then
5506 if Is_Type
(U_Ent
) then
5509 Etyp
:= Etype
(U_Ent
);
5512 -- Check size, note that Gigi is in charge of checking that the
5513 -- size of an array or record type is OK. Also we do not check
5514 -- the size in the ordinary fixed-point case, since it is too
5515 -- early to do so (there may be subsequent small clause that
5516 -- affects the size). We can check the size if a small clause
5517 -- has already been given.
5519 if not Is_Ordinary_Fixed_Point_Type
(U_Ent
)
5520 or else Has_Small_Clause
(U_Ent
)
5522 Check_Size
(Expr
, Etyp
, Size
, Biased
);
5523 Set_Biased
(U_Ent
, N
, "size clause", Biased
);
5526 -- For types set RM_Size and Esize if possible
5528 if Is_Type
(U_Ent
) then
5529 Set_RM_Size
(U_Ent
, Size
);
5531 -- For elementary types, increase Object_Size to power of 2,
5532 -- but not less than a storage unit in any case (normally
5533 -- this means it will be byte addressable).
5535 -- For all other types, nothing else to do, we leave Esize
5536 -- (object size) unset, the back end will set it from the
5537 -- size and alignment in an appropriate manner.
5539 -- In both cases, we check whether the alignment must be
5540 -- reset in the wake of the size change.
5542 if Is_Elementary_Type
(U_Ent
) then
5543 if Size
<= System_Storage_Unit
then
5544 Init_Esize
(U_Ent
, System_Storage_Unit
);
5545 elsif Size
<= 16 then
5546 Init_Esize
(U_Ent
, 16);
5547 elsif Size
<= 32 then
5548 Init_Esize
(U_Ent
, 32);
5550 Set_Esize
(U_Ent
, (Size
+ 63) / 64 * 64);
5553 Alignment_Check_For_Size_Change
(U_Ent
, Esize
(U_Ent
));
5555 Alignment_Check_For_Size_Change
(U_Ent
, Size
);
5558 -- For objects, set Esize only
5561 if Is_Elementary_Type
(Etyp
) then
5562 if Size
/= System_Storage_Unit
5564 Size
/= System_Storage_Unit
* 2
5566 Size
/= System_Storage_Unit
* 4
5568 Size
/= System_Storage_Unit
* 8
5570 Error_Msg_Uint_1
:= UI_From_Int
(System_Storage_Unit
);
5571 Error_Msg_Uint_2
:= Error_Msg_Uint_1
* 8;
5573 ("size for primitive object must be a power of 2"
5574 & " in the range ^-^", N
);
5578 Set_Esize
(U_Ent
, Size
);
5581 Set_Has_Size_Clause
(U_Ent
);
5589 -- Small attribute definition clause
5591 when Attribute_Small
=> Small
: declare
5592 Implicit_Base
: constant Entity_Id
:= Base_Type
(U_Ent
);
5596 Analyze_And_Resolve
(Expr
, Any_Real
);
5598 if Etype
(Expr
) = Any_Type
then
5601 elsif not Is_OK_Static_Expression
(Expr
) then
5602 Flag_Non_Static_Expr
5603 ("small requires static expression!", Expr
);
5607 Small
:= Expr_Value_R
(Expr
);
5609 if Small
<= Ureal_0
then
5610 Error_Msg_N
("small value must be greater than zero", Expr
);
5616 if not Is_Ordinary_Fixed_Point_Type
(U_Ent
) then
5618 ("small requires an ordinary fixed point type", Nam
);
5620 elsif Has_Small_Clause
(U_Ent
) then
5621 Error_Msg_N
("small already given for &", Nam
);
5623 elsif Small
> Delta_Value
(U_Ent
) then
5625 ("small value must not be greater than delta value", Nam
);
5628 Set_Small_Value
(U_Ent
, Small
);
5629 Set_Small_Value
(Implicit_Base
, Small
);
5630 Set_Has_Small_Clause
(U_Ent
);
5631 Set_Has_Small_Clause
(Implicit_Base
);
5632 Set_Has_Non_Standard_Rep
(Implicit_Base
);
5640 -- Storage_Pool attribute definition clause
5642 when Attribute_Storage_Pool | Attribute_Simple_Storage_Pool
=> declare
5647 if Ekind
(U_Ent
) = E_Access_Subprogram_Type
then
5649 ("storage pool cannot be given for access-to-subprogram type",
5654 Ekind_In
(U_Ent
, E_Access_Type
, E_General_Access_Type
)
5657 ("storage pool can only be given for access types", Nam
);
5660 elsif Is_Derived_Type
(U_Ent
) then
5662 ("storage pool cannot be given for a derived access type",
5665 elsif Duplicate_Clause
then
5668 elsif Present
(Associated_Storage_Pool
(U_Ent
)) then
5669 Error_Msg_N
("storage pool already given for &", Nam
);
5673 -- Check for Storage_Size previously given
5676 SS
: constant Node_Id
:=
5677 Get_Attribute_Definition_Clause
5678 (U_Ent
, Attribute_Storage_Size
);
5680 if Present
(SS
) then
5681 Check_Pool_Size_Clash
(U_Ent
, N
, SS
);
5685 -- Storage_Pool case
5687 if Id
= Attribute_Storage_Pool
then
5689 (Expr
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
5691 -- In the Simple_Storage_Pool case, we allow a variable of any
5692 -- simple storage pool type, so we Resolve without imposing an
5696 Analyze_And_Resolve
(Expr
);
5698 if not Present
(Get_Rep_Pragma
5699 (Etype
(Expr
), Name_Simple_Storage_Pool_Type
))
5702 ("expression must be of a simple storage pool type", Expr
);
5706 if not Denotes_Variable
(Expr
) then
5707 Error_Msg_N
("storage pool must be a variable", Expr
);
5711 if Nkind
(Expr
) = N_Type_Conversion
then
5712 T
:= Etype
(Expression
(Expr
));
5717 -- The Stack_Bounded_Pool is used internally for implementing
5718 -- access types with a Storage_Size. Since it only work properly
5719 -- when used on one specific type, we need to check that it is not
5720 -- hijacked improperly:
5722 -- type T is access Integer;
5723 -- for T'Storage_Size use n;
5724 -- type Q is access Float;
5725 -- for Q'Storage_Size use T'Storage_Size; -- incorrect
5727 if RTE_Available
(RE_Stack_Bounded_Pool
)
5728 and then Base_Type
(T
) = RTE
(RE_Stack_Bounded_Pool
)
5730 Error_Msg_N
("non-shareable internal Pool", Expr
);
5734 -- If the argument is a name that is not an entity name, then
5735 -- we construct a renaming operation to define an entity of
5736 -- type storage pool.
5738 if not Is_Entity_Name
(Expr
)
5739 and then Is_Object_Reference
(Expr
)
5741 Pool
:= Make_Temporary
(Loc
, 'P', Expr
);
5744 Rnode
: constant Node_Id
:=
5745 Make_Object_Renaming_Declaration
(Loc
,
5746 Defining_Identifier
=> Pool
,
5748 New_Occurrence_Of
(Etype
(Expr
), Loc
),
5752 -- If the attribute definition clause comes from an aspect
5753 -- clause, then insert the renaming before the associated
5754 -- entity's declaration, since the attribute clause has
5755 -- not yet been appended to the declaration list.
5757 if From_Aspect_Specification
(N
) then
5758 Insert_Before
(Parent
(Entity
(N
)), Rnode
);
5760 Insert_Before
(N
, Rnode
);
5764 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
5767 elsif Is_Entity_Name
(Expr
) then
5768 Pool
:= Entity
(Expr
);
5770 -- If pool is a renamed object, get original one. This can
5771 -- happen with an explicit renaming, and within instances.
5773 while Present
(Renamed_Object
(Pool
))
5774 and then Is_Entity_Name
(Renamed_Object
(Pool
))
5776 Pool
:= Entity
(Renamed_Object
(Pool
));
5779 if Present
(Renamed_Object
(Pool
))
5780 and then Nkind
(Renamed_Object
(Pool
)) = N_Type_Conversion
5781 and then Is_Entity_Name
(Expression
(Renamed_Object
(Pool
)))
5783 Pool
:= Entity
(Expression
(Renamed_Object
(Pool
)));
5786 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
5788 elsif Nkind
(Expr
) = N_Type_Conversion
5789 and then Is_Entity_Name
(Expression
(Expr
))
5790 and then Nkind
(Original_Node
(Expr
)) = N_Attribute_Reference
5792 Pool
:= Entity
(Expression
(Expr
));
5793 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
5796 Error_Msg_N
("incorrect reference to a Storage Pool", Expr
);
5805 -- Storage_Size attribute definition clause
5807 when Attribute_Storage_Size
=> Storage_Size
: declare
5808 Btype
: constant Entity_Id
:= Base_Type
(U_Ent
);
5811 if Is_Task_Type
(U_Ent
) then
5813 -- Check obsolescent (but never obsolescent if from aspect)
5815 if not From_Aspect_Specification
(N
) then
5816 Check_Restriction
(No_Obsolescent_Features
, N
);
5818 if Warn_On_Obsolescent_Feature
then
5820 ("?j?storage size clause for task is an " &
5821 "obsolescent feature (RM J.9)", N
);
5822 Error_Msg_N
("\?j?use Storage_Size pragma instead", N
);
5829 if not Is_Access_Type
(U_Ent
)
5830 and then Ekind
(U_Ent
) /= E_Task_Type
5832 Error_Msg_N
("storage size cannot be given for &", Nam
);
5834 elsif Is_Access_Type
(U_Ent
) and Is_Derived_Type
(U_Ent
) then
5836 ("storage size cannot be given for a derived access type",
5839 elsif Duplicate_Clause
then
5843 Analyze_And_Resolve
(Expr
, Any_Integer
);
5845 if Is_Access_Type
(U_Ent
) then
5847 -- Check for Storage_Pool previously given
5850 SP
: constant Node_Id
:=
5851 Get_Attribute_Definition_Clause
5852 (U_Ent
, Attribute_Storage_Pool
);
5855 if Present
(SP
) then
5856 Check_Pool_Size_Clash
(U_Ent
, SP
, N
);
5860 -- Special case of for x'Storage_Size use 0
5862 if Is_OK_Static_Expression
(Expr
)
5863 and then Expr_Value
(Expr
) = 0
5865 Set_No_Pool_Assigned
(Btype
);
5869 Set_Has_Storage_Size_Clause
(Btype
);
5877 when Attribute_Stream_Size
=> Stream_Size
: declare
5878 Size
: constant Uint
:= Static_Integer
(Expr
);
5881 if Ada_Version
<= Ada_95
then
5882 Check_Restriction
(No_Implementation_Attributes
, N
);
5885 if Duplicate_Clause
then
5888 elsif Is_Elementary_Type
(U_Ent
) then
5889 if Size
/= System_Storage_Unit
5891 Size
/= System_Storage_Unit
* 2
5893 Size
/= System_Storage_Unit
* 4
5895 Size
/= System_Storage_Unit
* 8
5897 Error_Msg_Uint_1
:= UI_From_Int
(System_Storage_Unit
);
5899 ("stream size for elementary type must be a"
5900 & " power of 2 and at least ^", N
);
5902 elsif RM_Size
(U_Ent
) > Size
then
5903 Error_Msg_Uint_1
:= RM_Size
(U_Ent
);
5905 ("stream size for elementary type must be a"
5906 & " power of 2 and at least ^", N
);
5909 Set_Has_Stream_Size_Clause
(U_Ent
);
5912 Error_Msg_N
("Stream_Size cannot be given for &", Nam
);
5920 -- Value_Size attribute definition clause
5922 when Attribute_Value_Size
=> Value_Size
: declare
5923 Size
: constant Uint
:= Static_Integer
(Expr
);
5927 if not Is_Type
(U_Ent
) then
5928 Error_Msg_N
("Value_Size cannot be given for &", Nam
);
5930 elsif Duplicate_Clause
then
5933 elsif Is_Array_Type
(U_Ent
)
5934 and then not Is_Constrained
(U_Ent
)
5937 ("Value_Size cannot be given for unconstrained array", Nam
);
5940 if Is_Elementary_Type
(U_Ent
) then
5941 Check_Size
(Expr
, U_Ent
, Size
, Biased
);
5942 Set_Biased
(U_Ent
, N
, "value size clause", Biased
);
5945 Set_RM_Size
(U_Ent
, Size
);
5949 -----------------------
5950 -- Variable_Indexing --
5951 -----------------------
5953 when Attribute_Variable_Indexing
=>
5954 Check_Indexing_Functions
;
5960 when Attribute_Write
=>
5961 Analyze_Stream_TSS_Definition
(TSS_Stream_Write
);
5962 Set_Has_Specified_Stream_Write
(Ent
);
5964 -- All other attributes cannot be set
5968 ("attribute& cannot be set with definition clause", N
);
5971 -- The test for the type being frozen must be performed after any
5972 -- expression the clause has been analyzed since the expression itself
5973 -- might cause freezing that makes the clause illegal.
5975 if Rep_Item_Too_Late
(U_Ent
, N
, FOnly
) then
5978 end Analyze_Attribute_Definition_Clause
;
5980 ----------------------------
5981 -- Analyze_Code_Statement --
5982 ----------------------------
5984 procedure Analyze_Code_Statement
(N
: Node_Id
) is
5985 HSS
: constant Node_Id
:= Parent
(N
);
5986 SBody
: constant Node_Id
:= Parent
(HSS
);
5987 Subp
: constant Entity_Id
:= Current_Scope
;
5994 -- Accept foreign code statements for CodePeer. The analysis is skipped
5995 -- to avoid rejecting unrecognized constructs.
5997 if CodePeer_Mode
then
6002 -- Analyze and check we get right type, note that this implements the
6003 -- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that is
6004 -- the only way that Asm_Insn could possibly be visible.
6006 Analyze_And_Resolve
(Expression
(N
));
6008 if Etype
(Expression
(N
)) = Any_Type
then
6010 elsif Etype
(Expression
(N
)) /= RTE
(RE_Asm_Insn
) then
6011 Error_Msg_N
("incorrect type for code statement", N
);
6015 Check_Code_Statement
(N
);
6017 -- Make sure we appear in the handled statement sequence of a subprogram
6020 if Nkind
(HSS
) /= N_Handled_Sequence_Of_Statements
6021 or else Nkind
(SBody
) /= N_Subprogram_Body
6024 ("code statement can only appear in body of subprogram", N
);
6028 -- Do remaining checks (RM 13.8(3)) if not already done
6030 if not Is_Machine_Code_Subprogram
(Subp
) then
6031 Set_Is_Machine_Code_Subprogram
(Subp
);
6033 -- No exception handlers allowed
6035 if Present
(Exception_Handlers
(HSS
)) then
6037 ("exception handlers not permitted in machine code subprogram",
6038 First
(Exception_Handlers
(HSS
)));
6041 -- No declarations other than use clauses and pragmas (we allow
6042 -- certain internally generated declarations as well).
6044 Decl
:= First
(Declarations
(SBody
));
6045 while Present
(Decl
) loop
6046 DeclO
:= Original_Node
(Decl
);
6047 if Comes_From_Source
(DeclO
)
6048 and not Nkind_In
(DeclO
, N_Pragma
,
6049 N_Use_Package_Clause
,
6051 N_Implicit_Label_Declaration
)
6054 ("this declaration not allowed in machine code subprogram",
6061 -- No statements other than code statements, pragmas, and labels.
6062 -- Again we allow certain internally generated statements.
6064 -- In Ada 2012, qualified expressions are names, and the code
6065 -- statement is initially parsed as a procedure call.
6067 Stmt
:= First
(Statements
(HSS
));
6068 while Present
(Stmt
) loop
6069 StmtO
:= Original_Node
(Stmt
);
6071 -- A procedure call transformed into a code statement is OK
6073 if Ada_Version
>= Ada_2012
6074 and then Nkind
(StmtO
) = N_Procedure_Call_Statement
6075 and then Nkind
(Name
(StmtO
)) = N_Qualified_Expression
6079 elsif Comes_From_Source
(StmtO
)
6080 and then not Nkind_In
(StmtO
, N_Pragma
,
6085 ("this statement is not allowed in machine code subprogram",
6092 end Analyze_Code_Statement
;
6094 -----------------------------------------------
6095 -- Analyze_Enumeration_Representation_Clause --
6096 -----------------------------------------------
6098 procedure Analyze_Enumeration_Representation_Clause
(N
: Node_Id
) is
6099 Ident
: constant Node_Id
:= Identifier
(N
);
6100 Aggr
: constant Node_Id
:= Array_Aggregate
(N
);
6101 Enumtype
: Entity_Id
;
6108 Err
: Boolean := False;
6109 -- Set True to avoid cascade errors and crashes on incorrect source code
6111 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Universal_Integer
));
6112 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(Universal_Integer
));
6113 -- Allowed range of universal integer (= allowed range of enum lit vals)
6117 -- Minimum and maximum values of entries
6120 -- Pointer to node for literal providing max value
6123 if Ignore_Rep_Clauses
then
6124 Kill_Rep_Clause
(N
);
6128 -- Ignore enumeration rep clauses by default in CodePeer mode,
6129 -- unless -gnatd.I is specified, as a work around for potential false
6130 -- positive messages.
6132 if CodePeer_Mode
and not Debug_Flag_Dot_II
then
6136 -- First some basic error checks
6139 Enumtype
:= Entity
(Ident
);
6141 if Enumtype
= Any_Type
6142 or else Rep_Item_Too_Early
(Enumtype
, N
)
6146 Enumtype
:= Underlying_Type
(Enumtype
);
6149 if not Is_Enumeration_Type
(Enumtype
) then
6151 ("enumeration type required, found}",
6152 Ident
, First_Subtype
(Enumtype
));
6156 -- Ignore rep clause on generic actual type. This will already have
6157 -- been flagged on the template as an error, and this is the safest
6158 -- way to ensure we don't get a junk cascaded message in the instance.
6160 if Is_Generic_Actual_Type
(Enumtype
) then
6163 -- Type must be in current scope
6165 elsif Scope
(Enumtype
) /= Current_Scope
then
6166 Error_Msg_N
("type must be declared in this scope", Ident
);
6169 -- Type must be a first subtype
6171 elsif not Is_First_Subtype
(Enumtype
) then
6172 Error_Msg_N
("cannot give enumeration rep clause for subtype", N
);
6175 -- Ignore duplicate rep clause
6177 elsif Has_Enumeration_Rep_Clause
(Enumtype
) then
6178 Error_Msg_N
("duplicate enumeration rep clause ignored", N
);
6181 -- Don't allow rep clause for standard [wide_[wide_]]character
6183 elsif Is_Standard_Character_Type
(Enumtype
) then
6184 Error_Msg_N
("enumeration rep clause not allowed for this type", N
);
6187 -- Check that the expression is a proper aggregate (no parentheses)
6189 elsif Paren_Count
(Aggr
) /= 0 then
6191 ("extra parentheses surrounding aggregate not allowed",
6195 -- All tests passed, so set rep clause in place
6198 Set_Has_Enumeration_Rep_Clause
(Enumtype
);
6199 Set_Has_Enumeration_Rep_Clause
(Base_Type
(Enumtype
));
6202 -- Now we process the aggregate. Note that we don't use the normal
6203 -- aggregate code for this purpose, because we don't want any of the
6204 -- normal expansion activities, and a number of special semantic
6205 -- rules apply (including the component type being any integer type)
6207 Elit
:= First_Literal
(Enumtype
);
6209 -- First the positional entries if any
6211 if Present
(Expressions
(Aggr
)) then
6212 Expr
:= First
(Expressions
(Aggr
));
6213 while Present
(Expr
) loop
6215 Error_Msg_N
("too many entries in aggregate", Expr
);
6219 Val
:= Static_Integer
(Expr
);
6221 -- Err signals that we found some incorrect entries processing
6222 -- the list. The final checks for completeness and ordering are
6223 -- skipped in this case.
6225 if Val
= No_Uint
then
6228 elsif Val
< Lo
or else Hi
< Val
then
6229 Error_Msg_N
("value outside permitted range", Expr
);
6233 Set_Enumeration_Rep
(Elit
, Val
);
6234 Set_Enumeration_Rep_Expr
(Elit
, Expr
);
6240 -- Now process the named entries if present
6242 if Present
(Component_Associations
(Aggr
)) then
6243 Assoc
:= First
(Component_Associations
(Aggr
));
6244 while Present
(Assoc
) loop
6245 Choice
:= First
(Choices
(Assoc
));
6247 if Present
(Next
(Choice
)) then
6249 ("multiple choice not allowed here", Next
(Choice
));
6253 if Nkind
(Choice
) = N_Others_Choice
then
6254 Error_Msg_N
("others choice not allowed here", Choice
);
6257 elsif Nkind
(Choice
) = N_Range
then
6259 -- ??? should allow zero/one element range here
6261 Error_Msg_N
("range not allowed here", Choice
);
6265 Analyze_And_Resolve
(Choice
, Enumtype
);
6267 if Error_Posted
(Choice
) then
6272 if Is_Entity_Name
(Choice
)
6273 and then Is_Type
(Entity
(Choice
))
6275 Error_Msg_N
("subtype name not allowed here", Choice
);
6278 -- ??? should allow static subtype with zero/one entry
6280 elsif Etype
(Choice
) = Base_Type
(Enumtype
) then
6281 if not Is_OK_Static_Expression
(Choice
) then
6282 Flag_Non_Static_Expr
6283 ("non-static expression used for choice!", Choice
);
6287 Elit
:= Expr_Value_E
(Choice
);
6289 if Present
(Enumeration_Rep_Expr
(Elit
)) then
6291 Sloc
(Enumeration_Rep_Expr
(Elit
));
6293 ("representation for& previously given#",
6298 Set_Enumeration_Rep_Expr
(Elit
, Expression
(Assoc
));
6300 Expr
:= Expression
(Assoc
);
6301 Val
:= Static_Integer
(Expr
);
6303 if Val
= No_Uint
then
6306 elsif Val
< Lo
or else Hi
< Val
then
6307 Error_Msg_N
("value outside permitted range", Expr
);
6311 Set_Enumeration_Rep
(Elit
, Val
);
6321 -- Aggregate is fully processed. Now we check that a full set of
6322 -- representations was given, and that they are in range and in order.
6323 -- These checks are only done if no other errors occurred.
6329 Elit
:= First_Literal
(Enumtype
);
6330 while Present
(Elit
) loop
6331 if No
(Enumeration_Rep_Expr
(Elit
)) then
6332 Error_Msg_NE
("missing representation for&!", N
, Elit
);
6335 Val
:= Enumeration_Rep
(Elit
);
6337 if Min
= No_Uint
then
6341 if Val
/= No_Uint
then
6342 if Max
/= No_Uint
and then Val
<= Max
then
6344 ("enumeration value for& not ordered!",
6345 Enumeration_Rep_Expr
(Elit
), Elit
);
6348 Max_Node
:= Enumeration_Rep_Expr
(Elit
);
6352 -- If there is at least one literal whose representation is not
6353 -- equal to the Pos value, then note that this enumeration type
6354 -- has a non-standard representation.
6356 if Val
/= Enumeration_Pos
(Elit
) then
6357 Set_Has_Non_Standard_Rep
(Base_Type
(Enumtype
));
6364 -- Now set proper size information
6367 Minsize
: Uint
:= UI_From_Int
(Minimum_Size
(Enumtype
));
6370 if Has_Size_Clause
(Enumtype
) then
6372 -- All OK, if size is OK now
6374 if RM_Size
(Enumtype
) >= Minsize
then
6378 -- Try if we can get by with biasing
6381 UI_From_Int
(Minimum_Size
(Enumtype
, Biased
=> True));
6383 -- Error message if even biasing does not work
6385 if RM_Size
(Enumtype
) < Minsize
then
6386 Error_Msg_Uint_1
:= RM_Size
(Enumtype
);
6387 Error_Msg_Uint_2
:= Max
;
6389 ("previously given size (^) is too small "
6390 & "for this value (^)", Max_Node
);
6392 -- If biasing worked, indicate that we now have biased rep
6396 (Enumtype
, Size_Clause
(Enumtype
), "size clause");
6401 Set_RM_Size
(Enumtype
, Minsize
);
6402 Set_Enum_Esize
(Enumtype
);
6405 Set_RM_Size
(Base_Type
(Enumtype
), RM_Size
(Enumtype
));
6406 Set_Esize
(Base_Type
(Enumtype
), Esize
(Enumtype
));
6407 Set_Alignment
(Base_Type
(Enumtype
), Alignment
(Enumtype
));
6411 -- We repeat the too late test in case it froze itself
6413 if Rep_Item_Too_Late
(Enumtype
, N
) then
6416 end Analyze_Enumeration_Representation_Clause
;
6418 ----------------------------
6419 -- Analyze_Free_Statement --
6420 ----------------------------
6422 procedure Analyze_Free_Statement
(N
: Node_Id
) is
6424 Analyze
(Expression
(N
));
6425 end Analyze_Free_Statement
;
6427 ---------------------------
6428 -- Analyze_Freeze_Entity --
6429 ---------------------------
6431 procedure Analyze_Freeze_Entity
(N
: Node_Id
) is
6433 Freeze_Entity_Checks
(N
);
6434 end Analyze_Freeze_Entity
;
6436 -----------------------------------
6437 -- Analyze_Freeze_Generic_Entity --
6438 -----------------------------------
6440 procedure Analyze_Freeze_Generic_Entity
(N
: Node_Id
) is
6442 Freeze_Entity_Checks
(N
);
6443 end Analyze_Freeze_Generic_Entity
;
6445 ------------------------------------------
6446 -- Analyze_Record_Representation_Clause --
6447 ------------------------------------------
6449 -- Note: we check as much as we can here, but we can't do any checks
6450 -- based on the position values (e.g. overlap checks) until freeze time
6451 -- because especially in Ada 2005 (machine scalar mode), the processing
6452 -- for non-standard bit order can substantially change the positions.
6453 -- See procedure Check_Record_Representation_Clause (called from Freeze)
6454 -- for the remainder of this processing.
6456 procedure Analyze_Record_Representation_Clause
(N
: Node_Id
) is
6457 Ident
: constant Node_Id
:= Identifier
(N
);
6462 Hbit
: Uint
:= Uint_0
;
6466 Rectype
: Entity_Id
;
6469 function Is_Inherited
(Comp
: Entity_Id
) return Boolean;
6470 -- True if Comp is an inherited component in a record extension
6476 function Is_Inherited
(Comp
: Entity_Id
) return Boolean is
6477 Comp_Base
: Entity_Id
;
6480 if Ekind
(Rectype
) = E_Record_Subtype
then
6481 Comp_Base
:= Original_Record_Component
(Comp
);
6486 return Comp_Base
/= Original_Record_Component
(Comp_Base
);
6491 Is_Record_Extension
: Boolean;
6492 -- True if Rectype is a record extension
6494 CR_Pragma
: Node_Id
:= Empty
;
6495 -- Points to N_Pragma node if Complete_Representation pragma present
6497 -- Start of processing for Analyze_Record_Representation_Clause
6500 if Ignore_Rep_Clauses
then
6501 Kill_Rep_Clause
(N
);
6506 Rectype
:= Entity
(Ident
);
6508 if Rectype
= Any_Type
or else Rep_Item_Too_Early
(Rectype
, N
) then
6511 Rectype
:= Underlying_Type
(Rectype
);
6514 -- First some basic error checks
6516 if not Is_Record_Type
(Rectype
) then
6518 ("record type required, found}", Ident
, First_Subtype
(Rectype
));
6521 elsif Scope
(Rectype
) /= Current_Scope
then
6522 Error_Msg_N
("type must be declared in this scope", N
);
6525 elsif not Is_First_Subtype
(Rectype
) then
6526 Error_Msg_N
("cannot give record rep clause for subtype", N
);
6529 elsif Has_Record_Rep_Clause
(Rectype
) then
6530 Error_Msg_N
("duplicate record rep clause ignored", N
);
6533 elsif Rep_Item_Too_Late
(Rectype
, N
) then
6537 -- We know we have a first subtype, now possibly go to the anonymous
6538 -- base type to determine whether Rectype is a record extension.
6540 Recdef
:= Type_Definition
(Declaration_Node
(Base_Type
(Rectype
)));
6541 Is_Record_Extension
:=
6542 Nkind
(Recdef
) = N_Derived_Type_Definition
6543 and then Present
(Record_Extension_Part
(Recdef
));
6545 if Present
(Mod_Clause
(N
)) then
6547 Loc
: constant Source_Ptr
:= Sloc
(N
);
6548 M
: constant Node_Id
:= Mod_Clause
(N
);
6549 P
: constant List_Id
:= Pragmas_Before
(M
);
6553 pragma Warnings
(Off
, Mod_Val
);
6556 Check_Restriction
(No_Obsolescent_Features
, Mod_Clause
(N
));
6558 if Warn_On_Obsolescent_Feature
then
6560 ("?j?mod clause is an obsolescent feature (RM J.8)", N
);
6562 ("\?j?use alignment attribute definition clause instead", N
);
6569 -- In ASIS_Mode mode, expansion is disabled, but we must convert
6570 -- the Mod clause into an alignment clause anyway, so that the
6571 -- back end can compute and back-annotate properly the size and
6572 -- alignment of types that may include this record.
6574 -- This seems dubious, this destroys the source tree in a manner
6575 -- not detectable by ASIS ???
6577 if Operating_Mode
= Check_Semantics
and then ASIS_Mode
then
6579 Make_Attribute_Definition_Clause
(Loc
,
6580 Name
=> New_Occurrence_Of
(Base_Type
(Rectype
), Loc
),
6581 Chars
=> Name_Alignment
,
6582 Expression
=> Relocate_Node
(Expression
(M
)));
6584 Set_From_At_Mod
(AtM_Nod
);
6585 Insert_After
(N
, AtM_Nod
);
6586 Mod_Val
:= Get_Alignment_Value
(Expression
(AtM_Nod
));
6587 Set_Mod_Clause
(N
, Empty
);
6590 -- Get the alignment value to perform error checking
6592 Mod_Val
:= Get_Alignment_Value
(Expression
(M
));
6597 -- For untagged types, clear any existing component clauses for the
6598 -- type. If the type is derived, this is what allows us to override
6599 -- a rep clause for the parent. For type extensions, the representation
6600 -- of the inherited components is inherited, so we want to keep previous
6601 -- component clauses for completeness.
6603 if not Is_Tagged_Type
(Rectype
) then
6604 Comp
:= First_Component_Or_Discriminant
(Rectype
);
6605 while Present
(Comp
) loop
6606 Set_Component_Clause
(Comp
, Empty
);
6607 Next_Component_Or_Discriminant
(Comp
);
6611 -- All done if no component clauses
6613 CC
:= First
(Component_Clauses
(N
));
6619 -- A representation like this applies to the base type
6621 Set_Has_Record_Rep_Clause
(Base_Type
(Rectype
));
6622 Set_Has_Non_Standard_Rep
(Base_Type
(Rectype
));
6623 Set_Has_Specified_Layout
(Base_Type
(Rectype
));
6625 -- Process the component clauses
6627 while Present
(CC
) loop
6631 if Nkind
(CC
) = N_Pragma
then
6634 -- The only pragma of interest is Complete_Representation
6636 if Pragma_Name
(CC
) = Name_Complete_Representation
then
6640 -- Processing for real component clause
6643 Posit
:= Static_Integer
(Position
(CC
));
6644 Fbit
:= Static_Integer
(First_Bit
(CC
));
6645 Lbit
:= Static_Integer
(Last_Bit
(CC
));
6648 and then Fbit
/= No_Uint
6649 and then Lbit
/= No_Uint
6653 ("position cannot be negative", Position
(CC
));
6657 ("first bit cannot be negative", First_Bit
(CC
));
6659 -- The Last_Bit specified in a component clause must not be
6660 -- less than the First_Bit minus one (RM-13.5.1(10)).
6662 elsif Lbit
< Fbit
- 1 then
6664 ("last bit cannot be less than first bit minus one",
6667 -- Values look OK, so find the corresponding record component
6668 -- Even though the syntax allows an attribute reference for
6669 -- implementation-defined components, GNAT does not allow the
6670 -- tag to get an explicit position.
6672 elsif Nkind
(Component_Name
(CC
)) = N_Attribute_Reference
then
6673 if Attribute_Name
(Component_Name
(CC
)) = Name_Tag
then
6674 Error_Msg_N
("position of tag cannot be specified", CC
);
6676 Error_Msg_N
("illegal component name", CC
);
6680 Comp
:= First_Entity
(Rectype
);
6681 while Present
(Comp
) loop
6682 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
6688 -- Maybe component of base type that is absent from
6689 -- statically constrained first subtype.
6691 Comp
:= First_Entity
(Base_Type
(Rectype
));
6692 while Present
(Comp
) loop
6693 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
6700 ("component clause is for non-existent field", CC
);
6702 -- Ada 2012 (AI05-0026): Any name that denotes a
6703 -- discriminant of an object of an unchecked union type
6704 -- shall not occur within a record_representation_clause.
6706 -- The general restriction of using record rep clauses on
6707 -- Unchecked_Union types has now been lifted. Since it is
6708 -- possible to introduce a record rep clause which mentions
6709 -- the discriminant of an Unchecked_Union in non-Ada 2012
6710 -- code, this check is applied to all versions of the
6713 elsif Ekind
(Comp
) = E_Discriminant
6714 and then Is_Unchecked_Union
(Rectype
)
6717 ("cannot reference discriminant of unchecked union",
6718 Component_Name
(CC
));
6720 elsif Is_Record_Extension
and then Is_Inherited
(Comp
) then
6722 ("component clause not allowed for inherited "
6723 & "component&", CC
, Comp
);
6725 elsif Present
(Component_Clause
(Comp
)) then
6727 -- Diagnose duplicate rep clause, or check consistency
6728 -- if this is an inherited component. In a double fault,
6729 -- there may be a duplicate inconsistent clause for an
6730 -- inherited component.
6732 if Scope
(Original_Record_Component
(Comp
)) = Rectype
6733 or else Parent
(Component_Clause
(Comp
)) = N
6735 Error_Msg_Sloc
:= Sloc
(Component_Clause
(Comp
));
6736 Error_Msg_N
("component clause previously given#", CC
);
6740 Rep1
: constant Node_Id
:= Component_Clause
(Comp
);
6742 if Intval
(Position
(Rep1
)) /=
6743 Intval
(Position
(CC
))
6744 or else Intval
(First_Bit
(Rep1
)) /=
6745 Intval
(First_Bit
(CC
))
6746 or else Intval
(Last_Bit
(Rep1
)) /=
6747 Intval
(Last_Bit
(CC
))
6750 ("component clause inconsistent "
6751 & "with representation of ancestor", CC
);
6753 elsif Warn_On_Redundant_Constructs
then
6755 ("?r?redundant confirming component clause "
6756 & "for component!", CC
);
6761 -- Normal case where this is the first component clause we
6762 -- have seen for this entity, so set it up properly.
6765 -- Make reference for field in record rep clause and set
6766 -- appropriate entity field in the field identifier.
6769 (Comp
, Component_Name
(CC
), Set_Ref
=> False);
6770 Set_Entity
(Component_Name
(CC
), Comp
);
6772 -- Update Fbit and Lbit to the actual bit number
6774 Fbit
:= Fbit
+ UI_From_Int
(SSU
) * Posit
;
6775 Lbit
:= Lbit
+ UI_From_Int
(SSU
) * Posit
;
6777 if Has_Size_Clause
(Rectype
)
6778 and then RM_Size
(Rectype
) <= Lbit
6781 ("bit number out of range of specified size",
6784 Set_Component_Clause
(Comp
, CC
);
6785 Set_Component_Bit_Offset
(Comp
, Fbit
);
6786 Set_Esize
(Comp
, 1 + (Lbit
- Fbit
));
6787 Set_Normalized_First_Bit
(Comp
, Fbit
mod SSU
);
6788 Set_Normalized_Position
(Comp
, Fbit
/ SSU
);
6790 if Warn_On_Overridden_Size
6791 and then Has_Size_Clause
(Etype
(Comp
))
6792 and then RM_Size
(Etype
(Comp
)) /= Esize
(Comp
)
6795 ("?S?component size overrides size clause for&",
6796 Component_Name
(CC
), Etype
(Comp
));
6799 -- This information is also set in the corresponding
6800 -- component of the base type, found by accessing the
6801 -- Original_Record_Component link if it is present.
6803 Ocomp
:= Original_Record_Component
(Comp
);
6810 (Component_Name
(CC
),
6816 (Comp
, First_Node
(CC
), "component clause", Biased
);
6818 if Present
(Ocomp
) then
6819 Set_Component_Clause
(Ocomp
, CC
);
6820 Set_Component_Bit_Offset
(Ocomp
, Fbit
);
6821 Set_Normalized_First_Bit
(Ocomp
, Fbit
mod SSU
);
6822 Set_Normalized_Position
(Ocomp
, Fbit
/ SSU
);
6823 Set_Esize
(Ocomp
, 1 + (Lbit
- Fbit
));
6825 Set_Normalized_Position_Max
6826 (Ocomp
, Normalized_Position
(Ocomp
));
6828 -- Note: we don't use Set_Biased here, because we
6829 -- already gave a warning above if needed, and we
6830 -- would get a duplicate for the same name here.
6832 Set_Has_Biased_Representation
6833 (Ocomp
, Has_Biased_Representation
(Comp
));
6836 if Esize
(Comp
) < 0 then
6837 Error_Msg_N
("component size is negative", CC
);
6848 -- Check missing components if Complete_Representation pragma appeared
6850 if Present
(CR_Pragma
) then
6851 Comp
:= First_Component_Or_Discriminant
(Rectype
);
6852 while Present
(Comp
) loop
6853 if No
(Component_Clause
(Comp
)) then
6855 ("missing component clause for &", CR_Pragma
, Comp
);
6858 Next_Component_Or_Discriminant
(Comp
);
6861 -- Give missing components warning if required
6863 elsif Warn_On_Unrepped_Components
then
6865 Num_Repped_Components
: Nat
:= 0;
6866 Num_Unrepped_Components
: Nat
:= 0;
6869 -- First count number of repped and unrepped components
6871 Comp
:= First_Component_Or_Discriminant
(Rectype
);
6872 while Present
(Comp
) loop
6873 if Present
(Component_Clause
(Comp
)) then
6874 Num_Repped_Components
:= Num_Repped_Components
+ 1;
6876 Num_Unrepped_Components
:= Num_Unrepped_Components
+ 1;
6879 Next_Component_Or_Discriminant
(Comp
);
6882 -- We are only interested in the case where there is at least one
6883 -- unrepped component, and at least half the components have rep
6884 -- clauses. We figure that if less than half have them, then the
6885 -- partial rep clause is really intentional. If the component
6886 -- type has no underlying type set at this point (as for a generic
6887 -- formal type), we don't know enough to give a warning on the
6890 if Num_Unrepped_Components
> 0
6891 and then Num_Unrepped_Components
< Num_Repped_Components
6893 Comp
:= First_Component_Or_Discriminant
(Rectype
);
6894 while Present
(Comp
) loop
6895 if No
(Component_Clause
(Comp
))
6896 and then Comes_From_Source
(Comp
)
6897 and then Present
(Underlying_Type
(Etype
(Comp
)))
6898 and then (Is_Scalar_Type
(Underlying_Type
(Etype
(Comp
)))
6899 or else Size_Known_At_Compile_Time
6900 (Underlying_Type
(Etype
(Comp
))))
6901 and then not Has_Warnings_Off
(Rectype
)
6903 -- Ignore discriminant in unchecked union, since it is
6904 -- not there, and cannot have a component clause.
6906 and then (not Is_Unchecked_Union
(Rectype
)
6907 or else Ekind
(Comp
) /= E_Discriminant
)
6909 Error_Msg_Sloc
:= Sloc
(Comp
);
6911 ("?C?no component clause given for & declared #",
6915 Next_Component_Or_Discriminant
(Comp
);
6920 end Analyze_Record_Representation_Clause
;
6922 -------------------------------------
6923 -- Build_Discrete_Static_Predicate --
6924 -------------------------------------
6926 procedure Build_Discrete_Static_Predicate
6931 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
6933 Non_Static
: exception;
6934 -- Raised if something non-static is found
6936 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
6938 BLo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Btyp
));
6939 BHi
: constant Uint
:= Expr_Value
(Type_High_Bound
(Btyp
));
6940 -- Low bound and high bound value of base type of Typ
6944 -- Bounds for constructing the static predicate. We use the bound of the
6945 -- subtype if it is static, otherwise the corresponding base type bound.
6946 -- Note: a non-static subtype can have a static predicate.
6951 -- One entry in a Rlist value, a single REnt (range entry) value denotes
6952 -- one range from Lo to Hi. To represent a single value range Lo = Hi =
6955 type RList
is array (Nat
range <>) of REnt
;
6956 -- A list of ranges. The ranges are sorted in increasing order, and are
6957 -- disjoint (there is a gap of at least one value between each range in
6958 -- the table). A value is in the set of ranges in Rlist if it lies
6959 -- within one of these ranges.
6961 False_Range
: constant RList
:=
6962 RList
'(1 .. 0 => REnt'(No_Uint
, No_Uint
));
6963 -- An empty set of ranges represents a range list that can never be
6964 -- satisfied, since there are no ranges in which the value could lie,
6965 -- so it does not lie in any of them. False_Range is a canonical value
6966 -- for this empty set, but general processing should test for an Rlist
6967 -- with length zero (see Is_False predicate), since other null ranges
6968 -- may appear which must be treated as False.
6970 True_Range
: constant RList
:= RList
'(1 => REnt'(BLo
, BHi
));
6971 -- Range representing True, value must be in the base range
6973 function "and" (Left
: RList
; Right
: RList
) return RList
;
6974 -- And's together two range lists, returning a range list. This is a set
6975 -- intersection operation.
6977 function "or" (Left
: RList
; Right
: RList
) return RList
;
6978 -- Or's together two range lists, returning a range list. This is a set
6981 function "not" (Right
: RList
) return RList
;
6982 -- Returns complement of a given range list, i.e. a range list
6983 -- representing all the values in TLo .. THi that are not in the input
6986 function Build_Val
(V
: Uint
) return Node_Id
;
6987 -- Return an analyzed N_Identifier node referencing this value, suitable
6988 -- for use as an entry in the Static_Discrte_Predicate list. This node
6989 -- is typed with the base type.
6991 function Build_Range
(Lo
: Uint
; Hi
: Uint
) return Node_Id
;
6992 -- Return an analyzed N_Range node referencing this range, suitable for
6993 -- use as an entry in the Static_Discrete_Predicate list. This node is
6994 -- typed with the base type.
6996 function Get_RList
(Exp
: Node_Id
) return RList
;
6997 -- This is a recursive routine that converts the given expression into a
6998 -- list of ranges, suitable for use in building the static predicate.
7000 function Is_False
(R
: RList
) return Boolean;
7001 pragma Inline
(Is_False
);
7002 -- Returns True if the given range list is empty, and thus represents a
7003 -- False list of ranges that can never be satisfied.
7005 function Is_True
(R
: RList
) return Boolean;
7006 -- Returns True if R trivially represents the True predicate by having a
7007 -- single range from BLo to BHi.
7009 function Is_Type_Ref
(N
: Node_Id
) return Boolean;
7010 pragma Inline
(Is_Type_Ref
);
7011 -- Returns if True if N is a reference to the type for the predicate in
7012 -- the expression (i.e. if it is an identifier whose Chars field matches
7013 -- the Nam given in the call). N must not be parenthesized, if the type
7014 -- name appears in parens, this routine will return False.
7016 function Lo_Val
(N
: Node_Id
) return Uint
;
7017 -- Given an entry from a Static_Discrete_Predicate list that is either
7018 -- a static expression or static range, gets either the expression value
7019 -- or the low bound of the range.
7021 function Hi_Val
(N
: Node_Id
) return Uint
;
7022 -- Given an entry from a Static_Discrete_Predicate list that is either
7023 -- a static expression or static range, gets either the expression value
7024 -- or the high bound of the range.
7026 function Membership_Entry
(N
: Node_Id
) return RList
;
7027 -- Given a single membership entry (range, value, or subtype), returns
7028 -- the corresponding range list. Raises Static_Error if not static.
7030 function Membership_Entries
(N
: Node_Id
) return RList
;
7031 -- Given an element on an alternatives list of a membership operation,
7032 -- returns the range list corresponding to this entry and all following
7033 -- entries (i.e. returns the "or" of this list of values).
7035 function Stat_Pred
(Typ
: Entity_Id
) return RList
;
7036 -- Given a type, if it has a static predicate, then return the predicate
7037 -- as a range list, otherwise raise Non_Static.
7043 function "and" (Left
: RList
; Right
: RList
) return RList
is
7045 -- First range of result
7047 SLeft
: Nat
:= Left
'First;
7048 -- Start of rest of left entries
7050 SRight
: Nat
:= Right
'First;
7051 -- Start of rest of right entries
7054 -- If either range is True, return the other
7056 if Is_True
(Left
) then
7058 elsif Is_True
(Right
) then
7062 -- If either range is False, return False
7064 if Is_False
(Left
) or else Is_False
(Right
) then
7068 -- Loop to remove entries at start that are disjoint, and thus just
7069 -- get discarded from the result entirely.
7072 -- If no operands left in either operand, result is false
7074 if SLeft
> Left
'Last or else SRight
> Right
'Last then
7077 -- Discard first left operand entry if disjoint with right
7079 elsif Left
(SLeft
).Hi
< Right
(SRight
).Lo
then
7082 -- Discard first right operand entry if disjoint with left
7084 elsif Right
(SRight
).Hi
< Left
(SLeft
).Lo
then
7085 SRight
:= SRight
+ 1;
7087 -- Otherwise we have an overlapping entry
7094 -- Now we have two non-null operands, and first entries overlap. The
7095 -- first entry in the result will be the overlapping part of these
7098 FEnt
:= REnt
'(Lo => UI_Max (Left (SLeft).Lo, Right (SRight).Lo),
7099 Hi => UI_Min (Left (SLeft).Hi, Right (SRight).Hi));
7101 -- Now we can remove the entry that ended at a lower value, since its
7102 -- contribution is entirely contained in Fent.
7104 if Left (SLeft).Hi <= Right (SRight).Hi then
7107 SRight := SRight + 1;
7110 -- Compute result by concatenating this first entry with the "and" of
7111 -- the remaining parts of the left and right operands. Note that if
7112 -- either of these is empty, "and" will yield empty, so that we will
7113 -- end up with just Fent, which is what we want in that case.
7116 FEnt & (Left (SLeft .. Left'Last) and Right (SRight .. Right'Last));
7123 function "not" (Right : RList) return RList is
7125 -- Return True if False range
7127 if Is_False (Right) then
7131 -- Return False if True range
7133 if Is_True (Right) then
7137 -- Here if not trivial case
7140 Result : RList (1 .. Right'Length + 1);
7141 -- May need one more entry for gap at beginning and end
7144 -- Number of entries stored in Result
7149 if Right (Right'First).Lo > TLo then
7151 Result (Count) := REnt'(TLo
, Right
(Right
'First).Lo
- 1);
7154 -- Gaps between ranges
7156 for J
in Right
'First .. Right
'Last - 1 loop
7158 Result
(Count
) := REnt
'(Right (J).Hi + 1, Right (J + 1).Lo - 1);
7163 if Right (Right'Last).Hi < THi then
7165 Result (Count) := REnt'(Right
(Right
'Last).Hi
+ 1, THi
);
7168 return Result
(1 .. Count
);
7176 function "or" (Left
: RList
; Right
: RList
) return RList
is
7178 -- First range of result
7180 SLeft
: Nat
:= Left
'First;
7181 -- Start of rest of left entries
7183 SRight
: Nat
:= Right
'First;
7184 -- Start of rest of right entries
7187 -- If either range is True, return True
7189 if Is_True
(Left
) or else Is_True
(Right
) then
7193 -- If either range is False (empty), return the other
7195 if Is_False
(Left
) then
7197 elsif Is_False
(Right
) then
7201 -- Initialize result first entry from left or right operand depending
7202 -- on which starts with the lower range.
7204 if Left
(SLeft
).Lo
< Right
(SRight
).Lo
then
7205 FEnt
:= Left
(SLeft
);
7208 FEnt
:= Right
(SRight
);
7209 SRight
:= SRight
+ 1;
7212 -- This loop eats ranges from left and right operands that are
7213 -- contiguous with the first range we are gathering.
7216 -- Eat first entry in left operand if contiguous or overlapped by
7217 -- gathered first operand of result.
7219 if SLeft
<= Left
'Last
7220 and then Left
(SLeft
).Lo
<= FEnt
.Hi
+ 1
7222 FEnt
.Hi
:= UI_Max
(FEnt
.Hi
, Left
(SLeft
).Hi
);
7225 -- Eat first entry in right operand if contiguous or overlapped by
7226 -- gathered right operand of result.
7228 elsif SRight
<= Right
'Last
7229 and then Right
(SRight
).Lo
<= FEnt
.Hi
+ 1
7231 FEnt
.Hi
:= UI_Max
(FEnt
.Hi
, Right
(SRight
).Hi
);
7232 SRight
:= SRight
+ 1;
7234 -- All done if no more entries to eat
7241 -- Obtain result as the first entry we just computed, concatenated
7242 -- to the "or" of the remaining results (if one operand is empty,
7243 -- this will just concatenate with the other
7246 FEnt
& (Left
(SLeft
.. Left
'Last) or Right
(SRight
.. Right
'Last));
7253 function Build_Range
(Lo
: Uint
; Hi
: Uint
) return Node_Id
is
7258 Low_Bound
=> Build_Val
(Lo
),
7259 High_Bound
=> Build_Val
(Hi
));
7260 Set_Etype
(Result
, Btyp
);
7261 Set_Analyzed
(Result
);
7269 function Build_Val
(V
: Uint
) return Node_Id
is
7273 if Is_Enumeration_Type
(Typ
) then
7274 Result
:= Get_Enum_Lit_From_Pos
(Typ
, V
, Loc
);
7276 Result
:= Make_Integer_Literal
(Loc
, V
);
7279 Set_Etype
(Result
, Btyp
);
7280 Set_Is_Static_Expression
(Result
);
7281 Set_Analyzed
(Result
);
7289 function Get_RList
(Exp
: Node_Id
) return RList
is
7294 -- Static expression can only be true or false
7296 if Is_OK_Static_Expression
(Exp
) then
7297 if Expr_Value
(Exp
) = 0 then
7304 -- Otherwise test node type
7312 when N_Op_And | N_And_Then
=>
7313 return Get_RList
(Left_Opnd
(Exp
))
7315 Get_RList
(Right_Opnd
(Exp
));
7319 when N_Op_Or | N_Or_Else
=>
7320 return Get_RList
(Left_Opnd
(Exp
))
7322 Get_RList
(Right_Opnd
(Exp
));
7327 return not Get_RList
(Right_Opnd
(Exp
));
7329 -- Comparisons of type with static value
7331 when N_Op_Compare
=>
7333 -- Type is left operand
7335 if Is_Type_Ref
(Left_Opnd
(Exp
))
7336 and then Is_OK_Static_Expression
(Right_Opnd
(Exp
))
7338 Val
:= Expr_Value
(Right_Opnd
(Exp
));
7340 -- Typ is right operand
7342 elsif Is_Type_Ref
(Right_Opnd
(Exp
))
7343 and then Is_OK_Static_Expression
(Left_Opnd
(Exp
))
7345 Val
:= Expr_Value
(Left_Opnd
(Exp
));
7347 -- Invert sense of comparison
7350 when N_Op_Gt
=> Op
:= N_Op_Lt
;
7351 when N_Op_Lt
=> Op
:= N_Op_Gt
;
7352 when N_Op_Ge
=> Op
:= N_Op_Le
;
7353 when N_Op_Le
=> Op
:= N_Op_Ge
;
7354 when others => null;
7357 -- Other cases are non-static
7363 -- Construct range according to comparison operation
7367 return RList
'(1 => REnt'(Val
, Val
));
7370 return RList
'(1 => REnt'(Val
, BHi
));
7373 return RList
'(1 => REnt'(Val
+ 1, BHi
));
7376 return RList
'(1 => REnt'(BLo
, Val
));
7379 return RList
'(1 => REnt'(BLo
, Val
- 1));
7382 return RList
'(REnt'(BLo
, Val
- 1), REnt
'(Val + 1, BHi));
7385 raise Program_Error;
7391 if not Is_Type_Ref (Left_Opnd (Exp)) then
7395 if Present (Right_Opnd (Exp)) then
7396 return Membership_Entry (Right_Opnd (Exp));
7398 return Membership_Entries (First (Alternatives (Exp)));
7401 -- Negative membership (NOT IN)
7404 if not Is_Type_Ref (Left_Opnd (Exp)) then
7408 if Present (Right_Opnd (Exp)) then
7409 return not Membership_Entry (Right_Opnd (Exp));
7411 return not Membership_Entries (First (Alternatives (Exp)));
7414 -- Function call, may be call to static predicate
7416 when N_Function_Call =>
7417 if Is_Entity_Name (Name (Exp)) then
7419 Ent : constant Entity_Id := Entity (Name (Exp));
7421 if Is_Predicate_Function (Ent)
7423 Is_Predicate_Function_M (Ent)
7425 return Stat_Pred (Etype (First_Formal (Ent)));
7430 -- Other function call cases are non-static
7434 -- Qualified expression, dig out the expression
7436 when N_Qualified_Expression =>
7437 return Get_RList (Expression (Exp));
7439 when N_Case_Expression =>
7446 if not Is_Entity_Name (Expression (Expr))
7447 or else Etype (Expression (Expr)) /= Typ
7450 ("expression must denaote subtype", Expression (Expr));
7454 -- Collect discrete choices in all True alternatives
7456 Choices := New_List;
7457 Alt := First (Alternatives (Exp));
7458 while Present (Alt) loop
7459 Dep := Expression (Alt);
7461 if not Is_OK_Static_Expression (Dep) then
7464 elsif Is_True (Expr_Value (Dep)) then
7465 Append_List_To (Choices,
7466 New_Copy_List (Discrete_Choices (Alt)));
7472 return Membership_Entries (First (Choices));
7475 -- Expression with actions: if no actions, dig out expression
7477 when N_Expression_With_Actions =>
7478 if Is_Empty_List (Actions (Exp)) then
7479 return Get_RList (Expression (Exp));
7487 return (Get_RList (Left_Opnd (Exp))
7488 and not Get_RList (Right_Opnd (Exp)))
7489 or (Get_RList (Right_Opnd (Exp))
7490 and not Get_RList (Left_Opnd (Exp)));
7492 -- Any other node type is non-static
7503 function Hi_Val (N : Node_Id) return Uint is
7505 if Is_OK_Static_Expression (N) then
7506 return Expr_Value (N);
7508 pragma Assert (Nkind (N) = N_Range);
7509 return Expr_Value (High_Bound (N));
7517 function Is_False (R : RList) return Boolean is
7519 return R'Length = 0;
7526 function Is_True (R : RList) return Boolean is
7529 and then R (R'First).Lo = BLo
7530 and then R (R'First).Hi = BHi;
7537 function Is_Type_Ref (N : Node_Id) return Boolean is
7539 return Nkind (N) = N_Identifier
7540 and then Chars (N) = Nam
7541 and then Paren_Count (N) = 0;
7548 function Lo_Val (N : Node_Id) return Uint is
7550 if Is_OK_Static_Expression (N) then
7551 return Expr_Value (N);
7553 pragma Assert (Nkind (N) = N_Range);
7554 return Expr_Value (Low_Bound (N));
7558 ------------------------
7559 -- Membership_Entries --
7560 ------------------------
7562 function Membership_Entries (N : Node_Id) return RList is
7564 if No (Next (N)) then
7565 return Membership_Entry (N);
7567 return Membership_Entry (N) or Membership_Entries (Next (N));
7569 end Membership_Entries;
7571 ----------------------
7572 -- Membership_Entry --
7573 ----------------------
7575 function Membership_Entry (N : Node_Id) return RList is
7583 if Nkind (N) = N_Range then
7584 if not Is_OK_Static_Expression (Low_Bound (N))
7586 not Is_OK_Static_Expression (High_Bound (N))
7590 SLo := Expr_Value (Low_Bound (N));
7591 SHi := Expr_Value (High_Bound (N));
7592 return RList'(1 => REnt
'(SLo, SHi));
7595 -- Static expression case
7597 elsif Is_OK_Static_Expression (N) then
7598 Val := Expr_Value (N);
7599 return RList'(1 => REnt
'(Val, Val));
7601 -- Identifier (other than static expression) case
7603 else pragma Assert (Nkind (N) = N_Identifier);
7607 if Is_Type (Entity (N)) then
7609 -- If type has predicates, process them
7611 if Has_Predicates (Entity (N)) then
7612 return Stat_Pred (Entity (N));
7614 -- For static subtype without predicates, get range
7616 elsif Is_OK_Static_Subtype (Entity (N)) then
7617 SLo := Expr_Value (Type_Low_Bound (Entity (N)));
7618 SHi := Expr_Value (Type_High_Bound (Entity (N)));
7619 return RList'(1 => REnt
'(SLo, SHi));
7621 -- Any other type makes us non-static
7627 -- Any other kind of identifier in predicate (e.g. a non-static
7628 -- expression value) means this is not a static predicate.
7634 end Membership_Entry;
7640 function Stat_Pred (Typ : Entity_Id) return RList is
7642 -- Not static if type does not have static predicates
7644 if not Has_Static_Predicate (Typ) then
7648 -- Otherwise we convert the predicate list to a range list
7651 Spred : constant List_Id := Static_Discrete_Predicate (Typ);
7652 Result : RList (1 .. List_Length (Spred));
7656 P := First (Static_Discrete_Predicate (Typ));
7657 for J in Result'Range loop
7658 Result (J) := REnt'(Lo_Val
(P
), Hi_Val
(P
));
7666 -- Start of processing for Build_Discrete_Static_Predicate
7669 -- Establish bounds for the predicate
7671 if Compile_Time_Known_Value
(Type_Low_Bound
(Typ
)) then
7672 TLo
:= Expr_Value
(Type_Low_Bound
(Typ
));
7677 if Compile_Time_Known_Value
(Type_High_Bound
(Typ
)) then
7678 THi
:= Expr_Value
(Type_High_Bound
(Typ
));
7683 -- Analyze the expression to see if it is a static predicate
7686 Ranges
: constant RList
:= Get_RList
(Expr
);
7687 -- Range list from expression if it is static
7692 -- Convert range list into a form for the static predicate. In the
7693 -- Ranges array, we just have raw ranges, these must be converted
7694 -- to properly typed and analyzed static expressions or range nodes.
7696 -- Note: here we limit ranges to the ranges of the subtype, so that
7697 -- a predicate is always false for values outside the subtype. That
7698 -- seems fine, such values are invalid anyway, and considering them
7699 -- to fail the predicate seems allowed and friendly, and furthermore
7700 -- simplifies processing for case statements and loops.
7704 for J
in Ranges
'Range loop
7706 Lo
: Uint
:= Ranges
(J
).Lo
;
7707 Hi
: Uint
:= Ranges
(J
).Hi
;
7710 -- Ignore completely out of range entry
7712 if Hi
< TLo
or else Lo
> THi
then
7715 -- Otherwise process entry
7718 -- Adjust out of range value to subtype range
7728 -- Convert range into required form
7730 Append_To
(Plist
, Build_Range
(Lo
, Hi
));
7735 -- Processing was successful and all entries were static, so now we
7736 -- can store the result as the predicate list.
7738 Set_Static_Discrete_Predicate
(Typ
, Plist
);
7740 -- The processing for static predicates put the expression into
7741 -- canonical form as a series of ranges. It also eliminated
7742 -- duplicates and collapsed and combined ranges. We might as well
7743 -- replace the alternatives list of the right operand of the
7744 -- membership test with the static predicate list, which will
7745 -- usually be more efficient.
7748 New_Alts
: constant List_Id
:= New_List
;
7753 Old_Node
:= First
(Plist
);
7754 while Present
(Old_Node
) loop
7755 New_Node
:= New_Copy
(Old_Node
);
7757 if Nkind
(New_Node
) = N_Range
then
7758 Set_Low_Bound
(New_Node
, New_Copy
(Low_Bound
(Old_Node
)));
7759 Set_High_Bound
(New_Node
, New_Copy
(High_Bound
(Old_Node
)));
7762 Append_To
(New_Alts
, New_Node
);
7766 -- If empty list, replace by False
7768 if Is_Empty_List
(New_Alts
) then
7769 Rewrite
(Expr
, New_Occurrence_Of
(Standard_False
, Loc
));
7771 -- Else replace by set membership test
7776 Left_Opnd
=> Make_Identifier
(Loc
, Nam
),
7777 Right_Opnd
=> Empty
,
7778 Alternatives
=> New_Alts
));
7780 -- Resolve new expression in function context
7782 Install_Formals
(Predicate_Function
(Typ
));
7783 Push_Scope
(Predicate_Function
(Typ
));
7784 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
7790 -- If non-static, return doing nothing
7795 end Build_Discrete_Static_Predicate
;
7797 -------------------------------------------
7798 -- Build_Invariant_Procedure_Declaration --
7799 -------------------------------------------
7801 function Build_Invariant_Procedure_Declaration
7802 (Typ
: Entity_Id
) return Node_Id
7804 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
7809 Save_Ghost_Mode
: constant Ghost_Mode_Type
:= Ghost_Mode
;
7812 -- Check for duplicate definitions
7814 if Has_Invariants
(Typ
) and then Present
(Invariant_Procedure
(Typ
)) then
7818 -- The related type may be subject to pragma Ghost. Set the mode now to
7819 -- ensure that the invariant procedure is properly marked as Ghost.
7821 Set_Ghost_Mode_From_Entity
(Typ
);
7824 Make_Defining_Identifier
(Loc
,
7825 Chars
=> New_External_Name
(Chars
(Typ
), "Invariant"));
7826 Set_Has_Invariants
(Typ
);
7827 Set_Ekind
(SId
, E_Procedure
);
7828 Set_Etype
(SId
, Standard_Void_Type
);
7829 Set_Is_Invariant_Procedure
(SId
);
7830 Set_Invariant_Procedure
(Typ
, SId
);
7832 -- Mark the invariant procedure explicitly as Ghost because it does not
7833 -- come from source.
7835 if Ghost_Mode
> None
then
7836 Set_Is_Ghost_Entity
(SId
);
7839 Obj_Id
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('I'));
7840 Set_Etype
(Obj_Id
, Typ
);
7843 Make_Subprogram_Declaration
(Loc
,
7844 Make_Procedure_Specification
(Loc
,
7845 Defining_Unit_Name
=> SId
,
7846 Parameter_Specifications
=> New_List
(
7847 Make_Parameter_Specification
(Loc
,
7848 Defining_Identifier
=> Obj_Id
,
7849 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)))));
7851 Ghost_Mode
:= Save_Ghost_Mode
;
7854 end Build_Invariant_Procedure_Declaration
;
7856 -------------------------------
7857 -- Build_Invariant_Procedure --
7858 -------------------------------
7860 -- The procedure that is constructed here has the form
7862 -- procedure typInvariant (Ixxx : typ) is
7864 -- pragma Check (Invariant, exp, "failed invariant from xxx");
7865 -- pragma Check (Invariant, exp, "failed invariant from xxx");
7867 -- pragma Check (Invariant, exp, "failed inherited invariant from xxx");
7869 -- end typInvariant;
7871 procedure Build_Invariant_Procedure
(Typ
: Entity_Id
; N
: Node_Id
) is
7872 procedure Add_Invariants
7875 Stmts
: in out List_Id
;
7877 -- Appends statements to Stmts for any invariants in the rep item chain
7878 -- of the given type. If Inherit is False, then we only process entries
7879 -- on the chain for the type Typ. If Inherit is True, then we ignore any
7880 -- Invariant aspects, but we process all Invariant'Class aspects, adding
7881 -- "inherited" to the exception message and generating an informational
7882 -- message about the inheritance of an invariant.
7884 --------------------
7885 -- Add_Invariants --
7886 --------------------
7888 procedure Add_Invariants
7891 Stmts
: in out List_Id
;
7894 procedure Add_Invariant
(Prag
: Node_Id
);
7895 -- Create a runtime check to verify the exression of invariant pragma
7896 -- Prag. All generated code is added to list Stmts.
7902 procedure Add_Invariant
(Prag
: Node_Id
) is
7903 procedure Replace_Type_Reference
(N
: Node_Id
);
7904 -- Replace a single occurrence N of the subtype name with a
7905 -- reference to the formal of the predicate function. N can be an
7906 -- identifier referencing the subtype, or a selected component,
7907 -- representing an appropriately qualified occurrence of the
7910 procedure Replace_Type_References
is
7911 new Replace_Type_References_Generic
(Replace_Type_Reference
);
7912 -- Traverse an expression replacing all occurrences of the subtype
7913 -- name with appropriate references to the formal of the predicate
7914 -- function. Note that we must ensure that the type and entity
7915 -- information is properly set in the replacement node, since we
7916 -- will do a Preanalyze call of this expression without proper
7917 -- visibility of the procedure argument.
7919 ----------------------------
7920 -- Replace_Type_Reference --
7921 ----------------------------
7923 -- Note: See comments in Add_Predicates.Replace_Type_Reference
7924 -- regarding handling of Sloc and Comes_From_Source.
7926 procedure Replace_Type_Reference
(N
: Node_Id
) is
7927 Nloc
: constant Source_Ptr
:= Sloc
(N
);
7930 -- Add semantic information to node to be rewritten, for ASIS
7931 -- navigation needs.
7933 if Nkind
(N
) = N_Identifier
then
7937 elsif Nkind
(N
) = N_Selected_Component
then
7938 Analyze
(Prefix
(N
));
7939 Set_Entity
(Selector_Name
(N
), T
);
7940 Set_Etype
(Selector_Name
(N
), T
);
7943 -- Invariant'Class, replace with T'Class (obj)
7945 if Class_Present
(Prag
) then
7947 -- In ASIS mode, an inherited item is already analyzed,
7948 -- and the replacement has been done, so do not repeat
7949 -- the transformation to prevent a malformed tree.
7952 and then Nkind
(Parent
(N
)) = N_Attribute_Reference
7953 and then Attribute_Name
(Parent
(N
)) = Name_Class
7959 Make_Type_Conversion
(Nloc
,
7961 Make_Attribute_Reference
(Nloc
,
7962 Prefix
=> New_Occurrence_Of
(T
, Nloc
),
7963 Attribute_Name
=> Name_Class
),
7965 Make_Identifier
(Nloc
, Chars
(Obj_Id
))));
7967 Set_Entity
(Expression
(N
), Obj_Id
);
7968 Set_Etype
(Expression
(N
), Typ
);
7971 -- Invariant, replace with obj
7974 Rewrite
(N
, Make_Identifier
(Nloc
, Chars
(Obj_Id
)));
7975 Set_Entity
(N
, Obj_Id
);
7979 Set_Comes_From_Source
(N
, True);
7980 end Replace_Type_Reference
;
7984 Asp
: constant Node_Id
:= Corresponding_Aspect
(Prag
);
7985 Nam
: constant Name_Id
:= Original_Aspect_Pragma_Name
(Prag
);
7986 Ploc
: constant Source_Ptr
:= Sloc
(Prag
);
7994 -- Start of processing for Add_Invariant
7997 -- Extract the arguments of the invariant pragma
7999 Arg1
:= First
(Pragma_Argument_Associations
(Prag
));
8000 Arg2
:= Next
(Arg1
);
8001 Arg3
:= Next
(Arg2
);
8003 Arg1
:= Get_Pragma_Arg
(Arg1
);
8004 Arg2
:= Get_Pragma_Arg
(Arg2
);
8006 -- The caller requests processing of all Invariant'Class pragmas,
8007 -- but the current pragma does not fall in this category. Return
8008 -- as there is nothing left to do.
8011 if not Class_Present
(Prag
) then
8015 -- Otherwise the pragma must apply to the current type
8017 elsif Entity
(Arg1
) /= T
then
8021 Expr
:= New_Copy_Tree
(Arg2
);
8023 -- Replace all occurrences of the type's name with references to
8024 -- the formal parameter of the invariant procedure.
8026 Replace_Type_References
(Expr
, T
);
8028 -- If the invariant pragma comes from an aspect, replace the saved
8029 -- expression because we need the subtype references replaced for
8030 -- the calls to Preanalyze_Spec_Expression in Check_Aspect_At_xxx
8033 if Present
(Asp
) then
8034 Set_Entity
(Identifier
(Asp
), New_Copy_Tree
(Expr
));
8037 -- Preanalyze the invariant expression to capture the visibility
8038 -- of the proper package part. In general the expression is not
8039 -- fully analyzed until the body of the invariant procedure is
8040 -- analyzed at the end of the private part, but that yields the
8041 -- wrong visibility.
8043 -- Historical note: we used to set N as the parent, but a package
8044 -- specification as the parent of an expression is bizarre.
8046 Set_Parent
(Expr
, Parent
(Arg2
));
8047 Preanalyze_Assert_Expression
(Expr
, Any_Boolean
);
8049 -- A class-wide invariant may be inherited in a separate unit,
8050 -- where the corresponding expression cannot be resolved by
8051 -- visibility, because it refers to a local function. Propagate
8052 -- semantic information to the original representation item, to
8053 -- be used when an invariant procedure for a derived type is
8056 -- ??? Unclear how to handle class-wide invariants that are not
8060 and then Class_Present
(Prag
)
8061 and then Nkind
(Expr
) = N_Function_Call
8062 and then Nkind
(Arg2
) = N_Indexed_Component
8065 Make_Function_Call
(Ploc
,
8067 New_Occurrence_Of
(Entity
(Name
(Expr
)), Ploc
),
8068 Parameter_Associations
=>
8069 New_Copy_List
(Expressions
(Arg2
))));
8072 -- In ASIS mode, even if assertions are not enabled, we must
8073 -- analyze the original expression in the aspect specification
8074 -- because it is part of the original tree.
8076 if ASIS_Mode
and then Present
(Asp
) then
8078 Orig_Expr
: constant Node_Id
:= Expression
(Asp
);
8080 Replace_Type_References
(Orig_Expr
, T
);
8081 Preanalyze_Assert_Expression
(Orig_Expr
, Any_Boolean
);
8085 -- An ignored invariant must not generate a runtime check. Add a
8086 -- null statement to ensure that the invariant procedure does get
8087 -- a completing body.
8090 Stmts
:= Empty_List
;
8093 if Is_Ignored
(Prag
) then
8094 Append_To
(Stmts
, Make_Null_Statement
(Ploc
));
8096 -- Otherwise the invariant is checked. Build a Check pragma to
8097 -- verify the expression at runtime.
8101 Make_Pragma_Argument_Association
(Ploc
,
8102 Expression
=> Make_Identifier
(Ploc
, Nam
)),
8103 Make_Pragma_Argument_Association
(Ploc
,
8104 Expression
=> Expr
));
8106 -- Handle the String argument (if any)
8108 if Present
(Arg3
) then
8109 Str
:= Strval
(Get_Pragma_Arg
(Arg3
));
8111 -- When inheriting an invariant, modify the message from
8112 -- "failed invariant" to "failed inherited invariant".
8115 String_To_Name_Buffer
(Str
);
8117 if Name_Buffer
(1 .. 16) = "failed invariant" then
8118 Insert_Str_In_Name_Buffer
("inherited ", 8);
8119 Str
:= String_From_Name_Buffer
;
8124 Make_Pragma_Argument_Association
(Ploc
,
8125 Expression
=> Make_String_Literal
(Ploc
, Str
)));
8129 -- pragma Check (Nam, Expr, Str);
8133 Pragma_Identifier
=>
8134 Make_Identifier
(Ploc
, Name_Check
),
8135 Pragma_Argument_Associations
=> Assoc
));
8138 -- Output an info message when inheriting an invariant and the
8139 -- listing option is enabled.
8141 if Inherit
and Opt
.List_Inherited_Aspects
then
8142 Error_Msg_Sloc
:= Sloc
(Prag
);
8144 ("info: & inherits `Invariant''Class` aspect from #?L?", Typ
);
8152 -- Start of processing for Add_Invariants
8155 Ritem
:= First_Rep_Item
(T
);
8156 while Present
(Ritem
) loop
8157 if Nkind
(Ritem
) = N_Pragma
8158 and then Pragma_Name
(Ritem
) = Name_Invariant
8160 Add_Invariant
(Ritem
);
8163 Next_Rep_Item
(Ritem
);
8169 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
8170 Priv_Decls
: constant List_Id
:= Private_Declarations
(N
);
8171 Vis_Decls
: constant List_Id
:= Visible_Declarations
(N
);
8173 Save_Ghost_Mode
: constant Ghost_Mode_Type
:= Ghost_Mode
;
8182 -- The entity of the formal for the procedure
8184 -- Start of processing for Build_Invariant_Procedure
8187 -- The related type may be subject to pragma Ghost. Set the mode now to
8188 -- ensure that the invariant procedure is properly marked as Ghost.
8190 Set_Ghost_Mode_From_Entity
(Typ
);
8197 -- If the aspect specification exists for some view of the type, the
8198 -- declaration for the procedure has been created.
8200 if Has_Invariants
(Typ
) then
8201 SId
:= Invariant_Procedure
(Typ
);
8204 -- If the body is already present, nothing to do. This will occur when
8205 -- the type is already frozen, which is the case when the invariant
8206 -- appears in a private part, and the freezing takes place before the
8207 -- final pass over full declarations.
8209 -- See Exp_Ch3.Insert_Component_Invariant_Checks for details.
8211 if Present
(SId
) then
8212 PDecl
:= Unit_Declaration_Node
(SId
);
8215 and then Nkind
(PDecl
) = N_Subprogram_Declaration
8216 and then Present
(Corresponding_Body
(PDecl
))
8218 Ghost_Mode
:= Save_Ghost_Mode
;
8223 PDecl
:= Build_Invariant_Procedure_Declaration
(Typ
);
8226 -- Recover formal of procedure, for use in the calls to invariant
8227 -- functions (including inherited ones).
8231 (First
(Parameter_Specifications
(Specification
(PDecl
))));
8233 -- Add invariants for the current type
8241 -- Add invariants for parent types
8244 Current_Typ
: Entity_Id
;
8245 Parent_Typ
: Entity_Id
;
8250 Parent_Typ
:= Etype
(Current_Typ
);
8252 if Is_Private_Type
(Parent_Typ
)
8253 and then Present
(Full_View
(Base_Type
(Parent_Typ
)))
8255 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
8258 exit when Parent_Typ
= Current_Typ
;
8260 Current_Typ
:= Parent_Typ
;
8269 -- Add invariants of progenitors
8271 if Is_Tagged_Type
(Typ
) and then not Is_Interface
(Typ
) then
8273 Ifaces_List
: Elist_Id
;
8278 Collect_Interfaces
(Typ
, Ifaces_List
);
8280 AI
:= First_Elmt
(Ifaces_List
);
8281 while Present
(AI
) loop
8284 if not Is_Ancestor
(Iface
, Typ
, Use_Full_View
=> True) then
8297 -- Build the procedure if we generated at least one Check pragma
8299 if Stmts
/= No_List
then
8300 Spec
:= Copy_Separate_Tree
(Specification
(PDecl
));
8303 Make_Subprogram_Body
(Loc
,
8304 Specification
=> Spec
,
8305 Declarations
=> Empty_List
,
8306 Handled_Statement_Sequence
=>
8307 Make_Handled_Sequence_Of_Statements
(Loc
,
8308 Statements
=> Stmts
));
8310 -- Insert procedure declaration and spec at the appropriate points.
8311 -- If declaration is already analyzed, it was processed by the
8312 -- generated pragma.
8314 if Present
(Priv_Decls
) then
8316 -- The spec goes at the end of visible declarations, but they have
8317 -- already been analyzed, so we need to explicitly do the analyze.
8319 if not Analyzed
(PDecl
) then
8320 Append_To
(Vis_Decls
, PDecl
);
8324 -- The body goes at the end of the private declarations, which we
8325 -- have not analyzed yet, so we do not need to perform an explicit
8326 -- analyze call. We skip this if there are no private declarations
8327 -- (this is an error that will be caught elsewhere);
8329 Append_To
(Priv_Decls
, PBody
);
8331 -- If the invariant appears on the full view of a type, the
8332 -- analysis of the private part is complete, and we must
8333 -- analyze the new body explicitly.
8335 if In_Private_Part
(Current_Scope
) then
8339 -- If there are no private declarations this may be an error that
8340 -- will be diagnosed elsewhere. However, if this is a non-private
8341 -- type that inherits invariants, it needs no completion and there
8342 -- may be no private part. In this case insert invariant procedure
8343 -- at end of current declarative list, and analyze at once, given
8344 -- that the type is about to be frozen.
8346 elsif not Is_Private_Type
(Typ
) then
8347 Append_To
(Vis_Decls
, PDecl
);
8348 Append_To
(Vis_Decls
, PBody
);
8354 Ghost_Mode
:= Save_Ghost_Mode
;
8355 end Build_Invariant_Procedure
;
8357 -------------------------------
8358 -- Build_Predicate_Functions --
8359 -------------------------------
8361 -- The procedures that are constructed here have the form:
8363 -- function typPredicate (Ixxx : typ) return Boolean is
8366 -- typ1Predicate (typ1 (Ixxx))
8367 -- and then typ2Predicate (typ2 (Ixxx))
8369 -- exp1 and then exp2 and then ...
8370 -- end typPredicate;
8372 -- Here exp1, and exp2 are expressions from Predicate pragmas. Note that
8373 -- this is the point at which these expressions get analyzed, providing the
8374 -- required delay, and typ1, typ2, are entities from which predicates are
8375 -- inherited. Note that we do NOT generate Check pragmas, that's because we
8376 -- use this function even if checks are off, e.g. for membership tests.
8378 -- Note that the inherited predicates are evaluated first, as required by
8381 -- Note that Sem_Eval.Real_Or_String_Static_Predicate_Matches depends on
8382 -- the form of this return expression.
8384 -- If the expression has at least one Raise_Expression, then we also build
8385 -- the typPredicateM version of the function, in which any occurrence of a
8386 -- Raise_Expression is converted to "return False".
8388 procedure Build_Predicate_Functions
(Typ
: Entity_Id
; N
: Node_Id
) is
8389 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
8392 -- This is the expression for the result of the function. It is
8393 -- is build by connecting the component predicates with AND THEN.
8396 -- This is the corresponding return expression for the Predicate_M
8397 -- function. It differs in that raise expressions are marked for
8398 -- special expansion (see Process_REs).
8400 Object_Name
: constant Name_Id
:= New_Internal_Name
('I');
8401 -- Name for argument of Predicate procedure. Note that we use the same
8402 -- name for both predicate functions. That way the reference within the
8403 -- predicate expression is the same in both functions.
8405 Object_Entity
: constant Entity_Id
:=
8406 Make_Defining_Identifier
(Loc
, Chars
=> Object_Name
);
8407 -- Entity for argument of Predicate procedure
8409 Object_Entity_M
: constant Entity_Id
:=
8410 Make_Defining_Identifier
(Loc
, Chars
=> Object_Name
);
8411 -- Entity for argument of Predicate_M procedure
8413 Raise_Expression_Present
: Boolean := False;
8414 -- Set True if Expr has at least one Raise_Expression
8416 procedure Add_Condition
(Cond
: Node_Id
);
8417 -- Append Cond to Expr using "and then" (or just copy Cond to Expr if
8420 procedure Add_Predicates
;
8421 -- Appends expressions for any Predicate pragmas in the rep item chain
8422 -- Typ to Expr. Note that we look only at items for this exact entity.
8423 -- Inheritance of predicates for the parent type is done by calling the
8424 -- Predicate_Function of the parent type, using Add_Call above.
8426 procedure Add_Call
(T
: Entity_Id
);
8427 -- Includes a call to the predicate function for type T in Expr if T
8428 -- has predicates and Predicate_Function (T) is non-empty.
8430 function Process_RE
(N
: Node_Id
) return Traverse_Result
;
8431 -- Used in Process REs, tests if node N is a raise expression, and if
8432 -- so, marks it to be converted to return False.
8434 procedure Process_REs
is new Traverse_Proc
(Process_RE
);
8435 -- Marks any raise expressions in Expr_M to return False
8437 function Test_RE
(N
: Node_Id
) return Traverse_Result
;
8438 -- Used in Test_REs, tests one node for being a raise expression, and if
8439 -- so sets Raise_Expression_Present True.
8441 procedure Test_REs
is new Traverse_Proc
(Test_RE
);
8442 -- Tests to see if Expr contains any raise expressions
8448 procedure Add_Call
(T
: Entity_Id
) is
8452 if Present
(T
) and then Present
(Predicate_Function
(T
)) then
8453 Set_Has_Predicates
(Typ
);
8455 -- Build the call to the predicate function of T
8459 (T
, Convert_To
(T
, Make_Identifier
(Loc
, Object_Name
)));
8461 -- "and"-in the call to evolving expression
8463 Add_Condition
(Exp
);
8465 -- Output info message on inheritance if required. Note we do not
8466 -- give this information for generic actual types, since it is
8467 -- unwelcome noise in that case in instantiations. We also
8468 -- generally suppress the message in instantiations, and also
8469 -- if it involves internal names.
8471 if Opt
.List_Inherited_Aspects
8472 and then not Is_Generic_Actual_Type
(Typ
)
8473 and then Instantiation_Depth
(Sloc
(Typ
)) = 0
8474 and then not Is_Internal_Name
(Chars
(T
))
8475 and then not Is_Internal_Name
(Chars
(Typ
))
8477 Error_Msg_Sloc
:= Sloc
(Predicate_Function
(T
));
8478 Error_Msg_Node_2
:= T
;
8479 Error_Msg_N
("info: & inherits predicate from & #?L?", Typ
);
8488 procedure Add_Condition
(Cond
: Node_Id
) is
8490 -- This is the first predicate expression
8495 -- Otherwise concatenate to the existing predicate expressions by
8496 -- using "and then".
8501 Left_Opnd
=> Relocate_Node
(Expr
),
8502 Right_Opnd
=> Cond
);
8506 --------------------
8507 -- Add_Predicates --
8508 --------------------
8510 procedure Add_Predicates
is
8511 procedure Add_Predicate
(Prag
: Node_Id
);
8512 -- Concatenate the expression of predicate pragma Prag to Expr by
8513 -- using a short circuit "and then" operator.
8519 procedure Add_Predicate
(Prag
: Node_Id
) is
8520 procedure Replace_Type_Reference
(N
: Node_Id
);
8521 -- Replace a single occurrence N of the subtype name with a
8522 -- reference to the formal of the predicate function. N can be an
8523 -- identifier referencing the subtype, or a selected component,
8524 -- representing an appropriately qualified occurrence of the
8527 procedure Replace_Type_References
is
8528 new Replace_Type_References_Generic
(Replace_Type_Reference
);
8529 -- Traverse an expression changing every occurrence of an
8530 -- identifier whose name matches the name of the subtype with a
8531 -- reference to the formal parameter of the predicate function.
8533 ----------------------------
8534 -- Replace_Type_Reference --
8535 ----------------------------
8537 procedure Replace_Type_Reference
(N
: Node_Id
) is
8539 Rewrite
(N
, Make_Identifier
(Sloc
(N
), Object_Name
));
8540 -- Use the Sloc of the usage name, not the defining name
8543 Set_Entity
(N
, Object_Entity
);
8545 -- We want to treat the node as if it comes from source, so
8546 -- that ASIS will not ignore it.
8548 Set_Comes_From_Source
(N
, True);
8549 end Replace_Type_Reference
;
8553 Asp
: constant Node_Id
:= Corresponding_Aspect
(Prag
);
8557 -- Start of processing for Add_Predicate
8560 -- Extract the arguments of the pragma. The expression itself
8561 -- is copied for use in the predicate function, to preserve the
8562 -- original version for ASIS use.
8564 Arg1
:= First
(Pragma_Argument_Associations
(Prag
));
8565 Arg2
:= Next
(Arg1
);
8567 Arg1
:= Get_Pragma_Arg
(Arg1
);
8568 Arg2
:= New_Copy_Tree
(Get_Pragma_Arg
(Arg2
));
8570 -- When the predicate pragma applies to the current type or its
8571 -- full view, replace all occurrences of the subtype name with
8572 -- references to the formal parameter of the predicate function.
8574 if Entity
(Arg1
) = Typ
8575 or else Full_View
(Entity
(Arg1
)) = Typ
8577 Replace_Type_References
(Arg2
, Typ
);
8579 -- If the predicate pragma comes from an aspect, replace the
8580 -- saved expression because we need the subtype references
8581 -- replaced for the calls to Preanalyze_Spec_Expression in
8582 -- Check_Aspect_At_xxx routines.
8584 if Present
(Asp
) then
8585 Set_Entity
(Identifier
(Asp
), New_Copy_Tree
(Arg2
));
8588 -- "and"-in the Arg2 condition to evolving expression
8590 Add_Condition
(Relocate_Node
(Arg2
));
8598 -- Start of processing for Add_Predicates
8601 Ritem
:= First_Rep_Item
(Typ
);
8602 while Present
(Ritem
) loop
8603 if Nkind
(Ritem
) = N_Pragma
8604 and then Pragma_Name
(Ritem
) = Name_Predicate
8606 Add_Predicate
(Ritem
);
8609 Next_Rep_Item
(Ritem
);
8617 function Process_RE
(N
: Node_Id
) return Traverse_Result
is
8619 if Nkind
(N
) = N_Raise_Expression
then
8620 Set_Convert_To_Return_False
(N
);
8631 function Test_RE
(N
: Node_Id
) return Traverse_Result
is
8633 if Nkind
(N
) = N_Raise_Expression
then
8634 Raise_Expression_Present
:= True;
8643 Save_Ghost_Mode
: constant Ghost_Mode_Type
:= Ghost_Mode
;
8645 -- Start of processing for Build_Predicate_Functions
8648 -- Return if already built or if type does not have predicates
8650 if not Has_Predicates
(Typ
)
8651 or else Present
(Predicate_Function
(Typ
))
8656 -- The related type may be subject to pragma Ghost. Set the mode now to
8657 -- ensure that the predicate functions are properly marked as Ghost.
8659 Set_Ghost_Mode_From_Entity
(Typ
);
8661 -- Prepare to construct predicate expression
8665 -- Add predicates for ancestor if present. These must come before the
8666 -- ones for the current type, as required by AI12-0071-1.
8669 Atyp
: constant Entity_Id
:= Nearest_Ancestor
(Typ
);
8671 if Present
(Atyp
) then
8676 -- Add Predicates for the current type
8680 -- Case where predicates are present
8682 if Present
(Expr
) then
8684 -- Test for raise expression present
8688 -- If raise expression is present, capture a copy of Expr for use
8689 -- in building the predicateM function version later on. For this
8690 -- copy we replace references to Object_Entity by Object_Entity_M.
8692 if Raise_Expression_Present
then
8694 Map
: constant Elist_Id
:= New_Elmt_List
;
8695 New_V
: Entity_Id
:= Empty
;
8697 -- The unanalyzed expression will be copied and appear in
8698 -- both functions. Normally expressions do not declare new
8699 -- entities, but quantified expressions do, so we need to
8700 -- create new entities for their bound variables, to prevent
8701 -- multiple definitions in gigi.
8703 function Reset_Loop_Variable
(N
: Node_Id
)
8704 return Traverse_Result
;
8706 procedure Collect_Loop_Variables
is
8707 new Traverse_Proc
(Reset_Loop_Variable
);
8709 ------------------------
8710 -- Reset_Loop_Variable --
8711 ------------------------
8713 function Reset_Loop_Variable
(N
: Node_Id
)
8714 return Traverse_Result
8717 if Nkind
(N
) = N_Iterator_Specification
then
8718 New_V
:= Make_Defining_Identifier
8719 (Sloc
(N
), Chars
(Defining_Identifier
(N
)));
8721 Set_Defining_Identifier
(N
, New_V
);
8725 end Reset_Loop_Variable
;
8728 Append_Elmt
(Object_Entity
, Map
);
8729 Append_Elmt
(Object_Entity_M
, Map
);
8730 Expr_M
:= New_Copy_Tree
(Expr
, Map
=> Map
);
8731 Collect_Loop_Variables
(Expr_M
);
8735 -- Build the main predicate function
8738 SId
: constant Entity_Id
:=
8739 Make_Defining_Identifier
(Loc
,
8740 Chars
=> New_External_Name
(Chars
(Typ
), "Predicate"));
8741 -- The entity for the function spec
8743 SIdB
: constant Entity_Id
:=
8744 Make_Defining_Identifier
(Loc
,
8745 Chars
=> New_External_Name
(Chars
(Typ
), "Predicate"));
8746 -- The entity for the function body
8753 -- Build function declaration
8755 Set_Ekind
(SId
, E_Function
);
8756 Set_Is_Internal
(SId
);
8757 Set_Is_Predicate_Function
(SId
);
8758 Set_Predicate_Function
(Typ
, SId
);
8760 -- The predicate function is shared between views of a type
8762 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
8763 Set_Predicate_Function
(Full_View
(Typ
), SId
);
8766 -- Mark the predicate function explicitly as Ghost because it does
8767 -- not come from source.
8769 if Ghost_Mode
> None
then
8770 Set_Is_Ghost_Entity
(SId
);
8774 Make_Function_Specification
(Loc
,
8775 Defining_Unit_Name
=> SId
,
8776 Parameter_Specifications
=> New_List
(
8777 Make_Parameter_Specification
(Loc
,
8778 Defining_Identifier
=> Object_Entity
,
8779 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))),
8780 Result_Definition
=>
8781 New_Occurrence_Of
(Standard_Boolean
, Loc
));
8784 Make_Subprogram_Declaration
(Loc
,
8785 Specification
=> Spec
);
8787 -- Build function body
8790 Make_Function_Specification
(Loc
,
8791 Defining_Unit_Name
=> SIdB
,
8792 Parameter_Specifications
=> New_List
(
8793 Make_Parameter_Specification
(Loc
,
8794 Defining_Identifier
=>
8795 Make_Defining_Identifier
(Loc
, Object_Name
),
8797 New_Occurrence_Of
(Typ
, Loc
))),
8798 Result_Definition
=>
8799 New_Occurrence_Of
(Standard_Boolean
, Loc
));
8802 Make_Subprogram_Body
(Loc
,
8803 Specification
=> Spec
,
8804 Declarations
=> Empty_List
,
8805 Handled_Statement_Sequence
=>
8806 Make_Handled_Sequence_Of_Statements
(Loc
,
8807 Statements
=> New_List
(
8808 Make_Simple_Return_Statement
(Loc
,
8809 Expression
=> Expr
))));
8811 -- Insert declaration before freeze node and body after
8813 Insert_Before_And_Analyze
(N
, FDecl
);
8814 Insert_After_And_Analyze
(N
, FBody
);
8816 -- Static predicate functions are always side-effect free, and
8817 -- in most cases dynamic predicate functions are as well. Mark
8818 -- them as such whenever possible, so redundant predicate checks
8819 -- can be optimized. If there is a variable reference within the
8820 -- expression, the function is not pure.
8822 if Expander_Active
then
8824 Side_Effect_Free
(Expr
, Variable_Ref
=> True));
8825 Set_Is_Inlined
(SId
);
8829 -- Test for raise expressions present and if so build M version
8831 if Raise_Expression_Present
then
8833 SId
: constant Entity_Id
:=
8834 Make_Defining_Identifier
(Loc
,
8835 Chars
=> New_External_Name
(Chars
(Typ
), "PredicateM"));
8836 -- The entity for the function spec
8838 SIdB
: constant Entity_Id
:=
8839 Make_Defining_Identifier
(Loc
,
8840 Chars
=> New_External_Name
(Chars
(Typ
), "PredicateM"));
8841 -- The entity for the function body
8849 -- Mark any raise expressions for special expansion
8851 Process_REs
(Expr_M
);
8853 -- Build function declaration
8855 Set_Ekind
(SId
, E_Function
);
8856 Set_Is_Predicate_Function_M
(SId
);
8857 Set_Predicate_Function_M
(Typ
, SId
);
8859 -- The predicate function is shared between views of a type
8861 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
8862 Set_Predicate_Function_M
(Full_View
(Typ
), SId
);
8865 -- Mark the predicate function explicitly as Ghost because it
8866 -- does not come from source.
8868 if Ghost_Mode
> None
then
8869 Set_Is_Ghost_Entity
(SId
);
8873 Make_Function_Specification
(Loc
,
8874 Defining_Unit_Name
=> SId
,
8875 Parameter_Specifications
=> New_List
(
8876 Make_Parameter_Specification
(Loc
,
8877 Defining_Identifier
=> Object_Entity_M
,
8878 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))),
8879 Result_Definition
=>
8880 New_Occurrence_Of
(Standard_Boolean
, Loc
));
8883 Make_Subprogram_Declaration
(Loc
,
8884 Specification
=> Spec
);
8886 -- Build function body
8889 Make_Function_Specification
(Loc
,
8890 Defining_Unit_Name
=> SIdB
,
8891 Parameter_Specifications
=> New_List
(
8892 Make_Parameter_Specification
(Loc
,
8893 Defining_Identifier
=>
8894 Make_Defining_Identifier
(Loc
, Object_Name
),
8896 New_Occurrence_Of
(Typ
, Loc
))),
8897 Result_Definition
=>
8898 New_Occurrence_Of
(Standard_Boolean
, Loc
));
8900 -- Build the body, we declare the boolean expression before
8901 -- doing the return, because we are not really confident of
8902 -- what happens if a return appears within a return.
8905 Make_Defining_Identifier
(Loc
,
8906 Chars
=> New_Internal_Name
('B'));
8909 Make_Subprogram_Body
(Loc
,
8910 Specification
=> Spec
,
8912 Declarations
=> New_List
(
8913 Make_Object_Declaration
(Loc
,
8914 Defining_Identifier
=> BTemp
,
8915 Constant_Present
=> True,
8916 Object_Definition
=>
8917 New_Occurrence_Of
(Standard_Boolean
, Loc
),
8918 Expression
=> Expr_M
)),
8920 Handled_Statement_Sequence
=>
8921 Make_Handled_Sequence_Of_Statements
(Loc
,
8922 Statements
=> New_List
(
8923 Make_Simple_Return_Statement
(Loc
,
8924 Expression
=> New_Occurrence_Of
(BTemp
, Loc
)))));
8926 -- Insert declaration before freeze node and body after
8928 Insert_Before_And_Analyze
(N
, FDecl
);
8929 Insert_After_And_Analyze
(N
, FBody
);
8933 -- See if we have a static predicate. Note that the answer may be
8934 -- yes even if we have an explicit Dynamic_Predicate present.
8941 if not Is_Scalar_Type
(Typ
) and then not Is_String_Type
(Typ
) then
8944 PS
:= Is_Predicate_Static
(Expr
, Object_Name
);
8947 -- Case where we have a predicate-static aspect
8951 -- We don't set Has_Static_Predicate_Aspect, since we can have
8952 -- any of the three cases (Predicate, Dynamic_Predicate, or
8953 -- Static_Predicate) generating a predicate with an expression
8954 -- that is predicate-static. We just indicate that we have a
8955 -- predicate that can be treated as static.
8957 Set_Has_Static_Predicate
(Typ
);
8959 -- For discrete subtype, build the static predicate list
8961 if Is_Discrete_Type
(Typ
) then
8962 Build_Discrete_Static_Predicate
(Typ
, Expr
, Object_Name
);
8964 -- If we don't get a static predicate list, it means that we
8965 -- have a case where this is not possible, most typically in
8966 -- the case where we inherit a dynamic predicate. We do not
8967 -- consider this an error, we just leave the predicate as
8968 -- dynamic. But if we do succeed in building the list, then
8969 -- we mark the predicate as static.
8971 if No
(Static_Discrete_Predicate
(Typ
)) then
8972 Set_Has_Static_Predicate
(Typ
, False);
8975 -- For real or string subtype, save predicate expression
8977 elsif Is_Real_Type
(Typ
) or else Is_String_Type
(Typ
) then
8978 Set_Static_Real_Or_String_Predicate
(Typ
, Expr
);
8981 -- Case of dynamic predicate (expression is not predicate-static)
8984 -- Again, we don't set Has_Dynamic_Predicate_Aspect, since that
8985 -- is only set if we have an explicit Dynamic_Predicate aspect
8986 -- given. Here we may simply have a Predicate aspect where the
8987 -- expression happens not to be predicate-static.
8989 -- Emit an error when the predicate is categorized as static
8990 -- but its expression is not predicate-static.
8992 -- First a little fiddling to get a nice location for the
8993 -- message. If the expression is of the form (A and then B),
8994 -- where A is an inherited predicate, then use the right
8995 -- operand for the Sloc. This avoids getting confused by a call
8996 -- to an inherited predicate with a less convenient source
9000 while Nkind
(EN
) = N_And_Then
9001 and then Nkind
(Left_Opnd
(EN
)) = N_Function_Call
9002 and then Is_Predicate_Function
9003 (Entity
(Name
(Left_Opnd
(EN
))))
9005 EN
:= Right_Opnd
(EN
);
9008 -- Now post appropriate message
9010 if Has_Static_Predicate_Aspect
(Typ
) then
9011 if Is_Scalar_Type
(Typ
) or else Is_String_Type
(Typ
) then
9013 ("expression is not predicate-static (RM 3.2.4(16-22))",
9017 ("static predicate requires scalar or string type", EN
);
9024 Ghost_Mode
:= Save_Ghost_Mode
;
9025 end Build_Predicate_Functions
;
9027 -----------------------------------------
9028 -- Check_Aspect_At_End_Of_Declarations --
9029 -----------------------------------------
9031 procedure Check_Aspect_At_End_Of_Declarations
(ASN
: Node_Id
) is
9032 Ent
: constant Entity_Id
:= Entity
(ASN
);
9033 Ident
: constant Node_Id
:= Identifier
(ASN
);
9034 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Chars
(Ident
));
9036 End_Decl_Expr
: constant Node_Id
:= Entity
(Ident
);
9037 -- Expression to be analyzed at end of declarations
9039 Freeze_Expr
: constant Node_Id
:= Expression
(ASN
);
9040 -- Expression from call to Check_Aspect_At_Freeze_Point
9042 T
: constant Entity_Id
:= Etype
(Freeze_Expr
);
9043 -- Type required for preanalyze call
9046 -- Set False if error
9048 -- On entry to this procedure, Entity (Ident) contains a copy of the
9049 -- original expression from the aspect, saved for this purpose, and
9050 -- but Expression (Ident) is a preanalyzed copy of the expression,
9051 -- preanalyzed just after the freeze point.
9053 procedure Check_Overloaded_Name
;
9054 -- For aspects whose expression is simply a name, this routine checks if
9055 -- the name is overloaded or not. If so, it verifies there is an
9056 -- interpretation that matches the entity obtained at the freeze point,
9057 -- otherwise the compiler complains.
9059 ---------------------------
9060 -- Check_Overloaded_Name --
9061 ---------------------------
9063 procedure Check_Overloaded_Name
is
9065 if not Is_Overloaded
(End_Decl_Expr
) then
9066 Err
:= not Is_Entity_Name
(End_Decl_Expr
)
9067 or else Entity
(End_Decl_Expr
) /= Entity
(Freeze_Expr
);
9073 Index
: Interp_Index
;
9077 Get_First_Interp
(End_Decl_Expr
, Index
, It
);
9078 while Present
(It
.Typ
) loop
9079 if It
.Nam
= Entity
(Freeze_Expr
) then
9084 Get_Next_Interp
(Index
, It
);
9088 end Check_Overloaded_Name
;
9090 -- Start of processing for Check_Aspect_At_End_Of_Declarations
9093 -- In an instance we do not perform the consistency check between freeze
9094 -- point and end of declarations, because it was done already in the
9095 -- analysis of the generic. Furthermore, the delayed analysis of an
9096 -- aspect of the instance may produce spurious errors when the generic
9097 -- is a child unit that references entities in the parent (which might
9098 -- not be in scope at the freeze point of the instance).
9103 -- Case of aspects Dimension, Dimension_System and Synchronization
9105 elsif A_Id
= Aspect_Synchronization
then
9108 -- Case of stream attributes, just have to compare entities. However,
9109 -- the expression is just a name (possibly overloaded), and there may
9110 -- be stream operations declared for unrelated types, so we just need
9111 -- to verify that one of these interpretations is the one available at
9112 -- at the freeze point.
9114 elsif A_Id
= Aspect_Input
or else
9115 A_Id
= Aspect_Output
or else
9116 A_Id
= Aspect_Read
or else
9119 Analyze
(End_Decl_Expr
);
9120 Check_Overloaded_Name
;
9122 elsif A_Id
= Aspect_Variable_Indexing
or else
9123 A_Id
= Aspect_Constant_Indexing
or else
9124 A_Id
= Aspect_Default_Iterator
or else
9125 A_Id
= Aspect_Iterator_Element
9127 -- Make type unfrozen before analysis, to prevent spurious errors
9128 -- about late attributes.
9130 Set_Is_Frozen
(Ent
, False);
9131 Analyze
(End_Decl_Expr
);
9132 Set_Is_Frozen
(Ent
, True);
9134 -- If the end of declarations comes before any other freeze
9135 -- point, the Freeze_Expr is not analyzed: no check needed.
9137 if Analyzed
(Freeze_Expr
) and then not In_Instance
then
9138 Check_Overloaded_Name
;
9146 -- Indicate that the expression comes from an aspect specification,
9147 -- which is used in subsequent analysis even if expansion is off.
9149 Set_Parent
(End_Decl_Expr
, ASN
);
9151 -- In a generic context the aspect expressions have not been
9152 -- preanalyzed, so do it now. There are no conformance checks
9153 -- to perform in this case.
9156 Check_Aspect_At_Freeze_Point
(ASN
);
9159 -- The default values attributes may be defined in the private part,
9160 -- and the analysis of the expression may take place when only the
9161 -- partial view is visible. The expression must be scalar, so use
9162 -- the full view to resolve.
9164 elsif (A_Id
= Aspect_Default_Value
9166 A_Id
= Aspect_Default_Component_Value
)
9167 and then Is_Private_Type
(T
)
9169 Preanalyze_Spec_Expression
(End_Decl_Expr
, Full_View
(T
));
9172 Preanalyze_Spec_Expression
(End_Decl_Expr
, T
);
9175 Err
:= not Fully_Conformant_Expressions
(End_Decl_Expr
, Freeze_Expr
);
9178 -- Output error message if error. Force error on aspect specification
9179 -- even if there is an error on the expression itself.
9183 ("!visibility of aspect for& changes after freeze point",
9186 ("info: & is frozen here, aspects evaluated at this point??",
9187 Freeze_Node
(Ent
), Ent
);
9189 end Check_Aspect_At_End_Of_Declarations
;
9191 ----------------------------------
9192 -- Check_Aspect_At_Freeze_Point --
9193 ----------------------------------
9195 procedure Check_Aspect_At_Freeze_Point
(ASN
: Node_Id
) is
9196 Ident
: constant Node_Id
:= Identifier
(ASN
);
9197 -- Identifier (use Entity field to save expression)
9199 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Chars
(Ident
));
9201 T
: Entity_Id
:= Empty
;
9202 -- Type required for preanalyze call
9205 -- On entry to this procedure, Entity (Ident) contains a copy of the
9206 -- original expression from the aspect, saved for this purpose.
9208 -- On exit from this procedure Entity (Ident) is unchanged, still
9209 -- containing that copy, but Expression (Ident) is a preanalyzed copy
9210 -- of the expression, preanalyzed just after the freeze point.
9212 -- Make a copy of the expression to be preanalyzed
9214 Set_Expression
(ASN
, New_Copy_Tree
(Entity
(Ident
)));
9216 -- Find type for preanalyze call
9220 -- No_Aspect should be impossible
9223 raise Program_Error
;
9225 -- Aspects taking an optional boolean argument
9227 when Boolean_Aspects |
9228 Library_Unit_Aspects
=>
9230 T
:= Standard_Boolean
;
9232 -- Aspects corresponding to attribute definition clauses
9234 when Aspect_Address
=>
9235 T
:= RTE
(RE_Address
);
9237 when Aspect_Attach_Handler
=>
9238 T
:= RTE
(RE_Interrupt_ID
);
9240 when Aspect_Bit_Order | Aspect_Scalar_Storage_Order
=>
9241 T
:= RTE
(RE_Bit_Order
);
9243 when Aspect_Convention
=>
9247 T
:= RTE
(RE_CPU_Range
);
9249 -- Default_Component_Value is resolved with the component type
9251 when Aspect_Default_Component_Value
=>
9252 T
:= Component_Type
(Entity
(ASN
));
9254 when Aspect_Default_Storage_Pool
=>
9255 T
:= Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
));
9257 -- Default_Value is resolved with the type entity in question
9259 when Aspect_Default_Value
=>
9262 when Aspect_Dispatching_Domain
=>
9263 T
:= RTE
(RE_Dispatching_Domain
);
9265 when Aspect_External_Tag
=>
9266 T
:= Standard_String
;
9268 when Aspect_External_Name
=>
9269 T
:= Standard_String
;
9271 when Aspect_Link_Name
=>
9272 T
:= Standard_String
;
9274 when Aspect_Priority | Aspect_Interrupt_Priority
=>
9275 T
:= Standard_Integer
;
9277 when Aspect_Relative_Deadline
=>
9278 T
:= RTE
(RE_Time_Span
);
9280 when Aspect_Small
=>
9281 T
:= Universal_Real
;
9283 -- For a simple storage pool, we have to retrieve the type of the
9284 -- pool object associated with the aspect's corresponding attribute
9285 -- definition clause.
9287 when Aspect_Simple_Storage_Pool
=>
9288 T
:= Etype
(Expression
(Aspect_Rep_Item
(ASN
)));
9290 when Aspect_Storage_Pool
=>
9291 T
:= Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
));
9293 when Aspect_Alignment |
9294 Aspect_Component_Size |
9295 Aspect_Machine_Radix |
9296 Aspect_Object_Size |
9298 Aspect_Storage_Size |
9299 Aspect_Stream_Size |
9300 Aspect_Value_Size
=>
9303 when Aspect_Linker_Section
=>
9304 T
:= Standard_String
;
9306 when Aspect_Synchronization
=>
9309 -- Special case, the expression of these aspects is just an entity
9310 -- that does not need any resolution, so just analyze.
9319 Analyze
(Expression
(ASN
));
9322 -- Same for Iterator aspects, where the expression is a function
9323 -- name. Legality rules are checked separately.
9325 when Aspect_Constant_Indexing |
9326 Aspect_Default_Iterator |
9327 Aspect_Iterator_Element |
9328 Aspect_Variable_Indexing
=>
9329 Analyze
(Expression
(ASN
));
9332 -- Ditto for Iterable, legality checks in Validate_Iterable_Aspect.
9334 when Aspect_Iterable
=>
9338 Cursor
: constant Entity_Id
:= Get_Cursor_Type
(ASN
, T
);
9343 if Cursor
= Any_Type
then
9347 Assoc
:= First
(Component_Associations
(Expression
(ASN
)));
9348 while Present
(Assoc
) loop
9349 Expr
:= Expression
(Assoc
);
9352 if not Error_Posted
(Expr
) then
9353 Resolve_Iterable_Operation
9354 (Expr
, Cursor
, T
, Chars
(First
(Choices
(Assoc
))));
9363 -- Invariant/Predicate take boolean expressions
9365 when Aspect_Dynamic_Predicate |
9368 Aspect_Static_Predicate |
9369 Aspect_Type_Invariant
=>
9370 T
:= Standard_Boolean
;
9372 when Aspect_Predicate_Failure
=>
9373 T
:= Standard_String
;
9375 -- Here is the list of aspects that don't require delay analysis
9377 when Aspect_Abstract_State |
9379 Aspect_Async_Readers |
9380 Aspect_Async_Writers |
9381 Aspect_Constant_After_Elaboration |
9382 Aspect_Contract_Cases |
9383 Aspect_Default_Initial_Condition |
9386 Aspect_Dimension_System |
9387 Aspect_Effective_Reads |
9388 Aspect_Effective_Writes |
9389 Aspect_Extensions_Visible |
9392 Aspect_Implicit_Dereference |
9393 Aspect_Initial_Condition |
9394 Aspect_Initializes |
9395 Aspect_Obsolescent |
9398 Aspect_Postcondition |
9400 Aspect_Precondition |
9401 Aspect_Refined_Depends |
9402 Aspect_Refined_Global |
9403 Aspect_Refined_Post |
9404 Aspect_Refined_State |
9407 Aspect_Unimplemented |
9408 Aspect_Volatile_Function
=>
9409 raise Program_Error
;
9413 -- Do the preanalyze call
9415 Preanalyze_Spec_Expression
(Expression
(ASN
), T
);
9416 end Check_Aspect_At_Freeze_Point
;
9418 -----------------------------------
9419 -- Check_Constant_Address_Clause --
9420 -----------------------------------
9422 procedure Check_Constant_Address_Clause
9426 procedure Check_At_Constant_Address
(Nod
: Node_Id
);
9427 -- Checks that the given node N represents a name whose 'Address is
9428 -- constant (in the same sense as OK_Constant_Address_Clause, i.e. the
9429 -- address value is the same at the point of declaration of U_Ent and at
9430 -- the time of elaboration of the address clause.
9432 procedure Check_Expr_Constants
(Nod
: Node_Id
);
9433 -- Checks that Nod meets the requirements for a constant address clause
9434 -- in the sense of the enclosing procedure.
9436 procedure Check_List_Constants
(Lst
: List_Id
);
9437 -- Check that all elements of list Lst meet the requirements for a
9438 -- constant address clause in the sense of the enclosing procedure.
9440 -------------------------------
9441 -- Check_At_Constant_Address --
9442 -------------------------------
9444 procedure Check_At_Constant_Address
(Nod
: Node_Id
) is
9446 if Is_Entity_Name
(Nod
) then
9447 if Present
(Address_Clause
(Entity
((Nod
)))) then
9449 ("invalid address clause for initialized object &!",
9452 ("address for& cannot" &
9453 " depend on another address clause! (RM 13.1(22))!",
9456 elsif In_Same_Source_Unit
(Entity
(Nod
), U_Ent
)
9457 and then Sloc
(U_Ent
) < Sloc
(Entity
(Nod
))
9460 ("invalid address clause for initialized object &!",
9462 Error_Msg_Node_2
:= U_Ent
;
9464 ("\& must be defined before & (RM 13.1(22))!",
9468 elsif Nkind
(Nod
) = N_Selected_Component
then
9470 T
: constant Entity_Id
:= Etype
(Prefix
(Nod
));
9473 if (Is_Record_Type
(T
)
9474 and then Has_Discriminants
(T
))
9477 and then Is_Record_Type
(Designated_Type
(T
))
9478 and then Has_Discriminants
(Designated_Type
(T
)))
9481 ("invalid address clause for initialized object &!",
9484 ("\address cannot depend on component" &
9485 " of discriminated record (RM 13.1(22))!",
9488 Check_At_Constant_Address
(Prefix
(Nod
));
9492 elsif Nkind
(Nod
) = N_Indexed_Component
then
9493 Check_At_Constant_Address
(Prefix
(Nod
));
9494 Check_List_Constants
(Expressions
(Nod
));
9497 Check_Expr_Constants
(Nod
);
9499 end Check_At_Constant_Address
;
9501 --------------------------
9502 -- Check_Expr_Constants --
9503 --------------------------
9505 procedure Check_Expr_Constants
(Nod
: Node_Id
) is
9506 Loc_U_Ent
: constant Source_Ptr
:= Sloc
(U_Ent
);
9507 Ent
: Entity_Id
:= Empty
;
9510 if Nkind
(Nod
) in N_Has_Etype
9511 and then Etype
(Nod
) = Any_Type
9517 when N_Empty | N_Error
=>
9520 when N_Identifier | N_Expanded_Name
=>
9521 Ent
:= Entity
(Nod
);
9523 -- We need to look at the original node if it is different
9524 -- from the node, since we may have rewritten things and
9525 -- substituted an identifier representing the rewrite.
9527 if Original_Node
(Nod
) /= Nod
then
9528 Check_Expr_Constants
(Original_Node
(Nod
));
9530 -- If the node is an object declaration without initial
9531 -- value, some code has been expanded, and the expression
9532 -- is not constant, even if the constituents might be
9533 -- acceptable, as in A'Address + offset.
9535 if Ekind
(Ent
) = E_Variable
9537 Nkind
(Declaration_Node
(Ent
)) = N_Object_Declaration
9539 No
(Expression
(Declaration_Node
(Ent
)))
9542 ("invalid address clause for initialized object &!",
9545 -- If entity is constant, it may be the result of expanding
9546 -- a check. We must verify that its declaration appears
9547 -- before the object in question, else we also reject the
9550 elsif Ekind
(Ent
) = E_Constant
9551 and then In_Same_Source_Unit
(Ent
, U_Ent
)
9552 and then Sloc
(Ent
) > Loc_U_Ent
9555 ("invalid address clause for initialized object &!",
9562 -- Otherwise look at the identifier and see if it is OK
9564 if Ekind_In
(Ent
, E_Named_Integer
, E_Named_Real
)
9565 or else Is_Type
(Ent
)
9569 elsif Ekind_In
(Ent
, E_Constant
, E_In_Parameter
) then
9571 -- This is the case where we must have Ent defined before
9572 -- U_Ent. Clearly if they are in different units this
9573 -- requirement is met since the unit containing Ent is
9574 -- already processed.
9576 if not In_Same_Source_Unit
(Ent
, U_Ent
) then
9579 -- Otherwise location of Ent must be before the location
9580 -- of U_Ent, that's what prior defined means.
9582 elsif Sloc
(Ent
) < Loc_U_Ent
then
9587 ("invalid address clause for initialized object &!",
9589 Error_Msg_Node_2
:= U_Ent
;
9591 ("\& must be defined before & (RM 13.1(22))!",
9595 elsif Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
9596 Check_Expr_Constants
(Original_Node
(Nod
));
9600 ("invalid address clause for initialized object &!",
9603 if Comes_From_Source
(Ent
) then
9605 ("\reference to variable& not allowed"
9606 & " (RM 13.1(22))!", Nod
, Ent
);
9609 ("non-static expression not allowed"
9610 & " (RM 13.1(22))!", Nod
);
9614 when N_Integer_Literal
=>
9616 -- If this is a rewritten unchecked conversion, in a system
9617 -- where Address is an integer type, always use the base type
9618 -- for a literal value. This is user-friendly and prevents
9619 -- order-of-elaboration issues with instances of unchecked
9622 if Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
9623 Set_Etype
(Nod
, Base_Type
(Etype
(Nod
)));
9626 when N_Real_Literal |
9628 N_Character_Literal
=>
9632 Check_Expr_Constants
(Low_Bound
(Nod
));
9633 Check_Expr_Constants
(High_Bound
(Nod
));
9635 when N_Explicit_Dereference
=>
9636 Check_Expr_Constants
(Prefix
(Nod
));
9638 when N_Indexed_Component
=>
9639 Check_Expr_Constants
(Prefix
(Nod
));
9640 Check_List_Constants
(Expressions
(Nod
));
9643 Check_Expr_Constants
(Prefix
(Nod
));
9644 Check_Expr_Constants
(Discrete_Range
(Nod
));
9646 when N_Selected_Component
=>
9647 Check_Expr_Constants
(Prefix
(Nod
));
9649 when N_Attribute_Reference
=>
9650 if Nam_In
(Attribute_Name
(Nod
), Name_Address
,
9652 Name_Unchecked_Access
,
9653 Name_Unrestricted_Access
)
9655 Check_At_Constant_Address
(Prefix
(Nod
));
9658 Check_Expr_Constants
(Prefix
(Nod
));
9659 Check_List_Constants
(Expressions
(Nod
));
9663 Check_List_Constants
(Component_Associations
(Nod
));
9664 Check_List_Constants
(Expressions
(Nod
));
9666 when N_Component_Association
=>
9667 Check_Expr_Constants
(Expression
(Nod
));
9669 when N_Extension_Aggregate
=>
9670 Check_Expr_Constants
(Ancestor_Part
(Nod
));
9671 Check_List_Constants
(Component_Associations
(Nod
));
9672 Check_List_Constants
(Expressions
(Nod
));
9677 when N_Binary_Op | N_Short_Circuit | N_Membership_Test
=>
9678 Check_Expr_Constants
(Left_Opnd
(Nod
));
9679 Check_Expr_Constants
(Right_Opnd
(Nod
));
9682 Check_Expr_Constants
(Right_Opnd
(Nod
));
9684 when N_Type_Conversion |
9685 N_Qualified_Expression |
9687 N_Unchecked_Type_Conversion
=>
9688 Check_Expr_Constants
(Expression
(Nod
));
9690 when N_Function_Call
=>
9691 if not Is_Pure
(Entity
(Name
(Nod
))) then
9693 ("invalid address clause for initialized object &!",
9697 ("\function & is not pure (RM 13.1(22))!",
9698 Nod
, Entity
(Name
(Nod
)));
9701 Check_List_Constants
(Parameter_Associations
(Nod
));
9704 when N_Parameter_Association
=>
9705 Check_Expr_Constants
(Explicit_Actual_Parameter
(Nod
));
9709 ("invalid address clause for initialized object &!",
9712 ("\must be constant defined before& (RM 13.1(22))!",
9715 end Check_Expr_Constants
;
9717 --------------------------
9718 -- Check_List_Constants --
9719 --------------------------
9721 procedure Check_List_Constants
(Lst
: List_Id
) is
9725 if Present
(Lst
) then
9726 Nod1
:= First
(Lst
);
9727 while Present
(Nod1
) loop
9728 Check_Expr_Constants
(Nod1
);
9732 end Check_List_Constants
;
9734 -- Start of processing for Check_Constant_Address_Clause
9737 -- If rep_clauses are to be ignored, no need for legality checks. In
9738 -- particular, no need to pester user about rep clauses that violate the
9739 -- rule on constant addresses, given that these clauses will be removed
9740 -- by Freeze before they reach the back end. Similarly in CodePeer mode,
9741 -- we want to relax these checks.
9743 if not Ignore_Rep_Clauses
and not CodePeer_Mode
then
9744 Check_Expr_Constants
(Expr
);
9746 end Check_Constant_Address_Clause
;
9748 ---------------------------
9749 -- Check_Pool_Size_Clash --
9750 ---------------------------
9752 procedure Check_Pool_Size_Clash
(Ent
: Entity_Id
; SP
, SS
: Node_Id
) is
9756 -- We need to find out which one came first. Note that in the case of
9757 -- aspects mixed with pragmas there are cases where the processing order
9758 -- is reversed, which is why we do the check here.
9760 if Sloc
(SP
) < Sloc
(SS
) then
9761 Error_Msg_Sloc
:= Sloc
(SP
);
9763 Error_Msg_NE
("Storage_Pool previously given for&#", Post
, Ent
);
9766 Error_Msg_Sloc
:= Sloc
(SS
);
9768 Error_Msg_NE
("Storage_Size previously given for&#", Post
, Ent
);
9772 ("\cannot have Storage_Size and Storage_Pool (RM 13.11(3))", Post
);
9773 end Check_Pool_Size_Clash
;
9775 ----------------------------------------
9776 -- Check_Record_Representation_Clause --
9777 ----------------------------------------
9779 procedure Check_Record_Representation_Clause
(N
: Node_Id
) is
9780 Loc
: constant Source_Ptr
:= Sloc
(N
);
9781 Ident
: constant Node_Id
:= Identifier
(N
);
9782 Rectype
: Entity_Id
;
9787 Hbit
: Uint
:= Uint_0
;
9791 Max_Bit_So_Far
: Uint
;
9792 -- Records the maximum bit position so far. If all field positions
9793 -- are monotonically increasing, then we can skip the circuit for
9794 -- checking for overlap, since no overlap is possible.
9796 Tagged_Parent
: Entity_Id
:= Empty
;
9797 -- This is set in the case of a derived tagged type for which we have
9798 -- Is_Fully_Repped_Tagged_Type True (indicating that all components are
9799 -- positioned by record representation clauses). In this case we must
9800 -- check for overlap between components of this tagged type, and the
9801 -- components of its parent. Tagged_Parent will point to this parent
9802 -- type. For all other cases Tagged_Parent is left set to Empty.
9804 Parent_Last_Bit
: Uint
;
9805 -- Relevant only if Tagged_Parent is set, Parent_Last_Bit indicates the
9806 -- last bit position for any field in the parent type. We only need to
9807 -- check overlap for fields starting below this point.
9809 Overlap_Check_Required
: Boolean;
9810 -- Used to keep track of whether or not an overlap check is required
9812 Overlap_Detected
: Boolean := False;
9813 -- Set True if an overlap is detected
9815 Ccount
: Natural := 0;
9816 -- Number of component clauses in record rep clause
9818 procedure Check_Component_Overlap
(C1_Ent
, C2_Ent
: Entity_Id
);
9819 -- Given two entities for record components or discriminants, checks
9820 -- if they have overlapping component clauses and issues errors if so.
9822 procedure Find_Component
;
9823 -- Finds component entity corresponding to current component clause (in
9824 -- CC), and sets Comp to the entity, and Fbit/Lbit to the zero origin
9825 -- start/stop bits for the field. If there is no matching component or
9826 -- if the matching component does not have a component clause, then
9827 -- that's an error and Comp is set to Empty, but no error message is
9828 -- issued, since the message was already given. Comp is also set to
9829 -- Empty if the current "component clause" is in fact a pragma.
9831 -----------------------------
9832 -- Check_Component_Overlap --
9833 -----------------------------
9835 procedure Check_Component_Overlap
(C1_Ent
, C2_Ent
: Entity_Id
) is
9836 CC1
: constant Node_Id
:= Component_Clause
(C1_Ent
);
9837 CC2
: constant Node_Id
:= Component_Clause
(C2_Ent
);
9840 if Present
(CC1
) and then Present
(CC2
) then
9842 -- Exclude odd case where we have two tag components in the same
9843 -- record, both at location zero. This seems a bit strange, but
9844 -- it seems to happen in some circumstances, perhaps on an error.
9846 if Nam_In
(Chars
(C1_Ent
), Name_uTag
, Name_uTag
) then
9850 -- Here we check if the two fields overlap
9853 S1
: constant Uint
:= Component_Bit_Offset
(C1_Ent
);
9854 S2
: constant Uint
:= Component_Bit_Offset
(C2_Ent
);
9855 E1
: constant Uint
:= S1
+ Esize
(C1_Ent
);
9856 E2
: constant Uint
:= S2
+ Esize
(C2_Ent
);
9859 if E2
<= S1
or else E1
<= S2
then
9862 Error_Msg_Node_2
:= Component_Name
(CC2
);
9863 Error_Msg_Sloc
:= Sloc
(Error_Msg_Node_2
);
9864 Error_Msg_Node_1
:= Component_Name
(CC1
);
9866 ("component& overlaps & #", Component_Name
(CC1
));
9867 Overlap_Detected
:= True;
9871 end Check_Component_Overlap
;
9873 --------------------
9874 -- Find_Component --
9875 --------------------
9877 procedure Find_Component
is
9879 procedure Search_Component
(R
: Entity_Id
);
9880 -- Search components of R for a match. If found, Comp is set
9882 ----------------------
9883 -- Search_Component --
9884 ----------------------
9886 procedure Search_Component
(R
: Entity_Id
) is
9888 Comp
:= First_Component_Or_Discriminant
(R
);
9889 while Present
(Comp
) loop
9891 -- Ignore error of attribute name for component name (we
9892 -- already gave an error message for this, so no need to
9895 if Nkind
(Component_Name
(CC
)) = N_Attribute_Reference
then
9898 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
9901 Next_Component_Or_Discriminant
(Comp
);
9903 end Search_Component
;
9905 -- Start of processing for Find_Component
9908 -- Return with Comp set to Empty if we have a pragma
9910 if Nkind
(CC
) = N_Pragma
then
9915 -- Search current record for matching component
9917 Search_Component
(Rectype
);
9919 -- If not found, maybe component of base type discriminant that is
9920 -- absent from statically constrained first subtype.
9923 Search_Component
(Base_Type
(Rectype
));
9926 -- If no component, or the component does not reference the component
9927 -- clause in question, then there was some previous error for which
9928 -- we already gave a message, so just return with Comp Empty.
9930 if No
(Comp
) or else Component_Clause
(Comp
) /= CC
then
9931 Check_Error_Detected
;
9934 -- Normal case where we have a component clause
9937 Fbit
:= Component_Bit_Offset
(Comp
);
9938 Lbit
:= Fbit
+ Esize
(Comp
) - 1;
9942 -- Start of processing for Check_Record_Representation_Clause
9946 Rectype
:= Entity
(Ident
);
9948 if Rectype
= Any_Type
then
9951 Rectype
:= Underlying_Type
(Rectype
);
9954 -- See if we have a fully repped derived tagged type
9957 PS
: constant Entity_Id
:= Parent_Subtype
(Rectype
);
9960 if Present
(PS
) and then Is_Fully_Repped_Tagged_Type
(PS
) then
9961 Tagged_Parent
:= PS
;
9963 -- Find maximum bit of any component of the parent type
9965 Parent_Last_Bit
:= UI_From_Int
(System_Address_Size
- 1);
9966 Pcomp
:= First_Entity
(Tagged_Parent
);
9967 while Present
(Pcomp
) loop
9968 if Ekind_In
(Pcomp
, E_Discriminant
, E_Component
) then
9969 if Component_Bit_Offset
(Pcomp
) /= No_Uint
9970 and then Known_Static_Esize
(Pcomp
)
9975 Component_Bit_Offset
(Pcomp
) + Esize
(Pcomp
) - 1);
9979 -- Skip anonymous types generated for constrained array
9980 -- or record components.
9985 Next_Entity
(Pcomp
);
9990 -- All done if no component clauses
9992 CC
:= First
(Component_Clauses
(N
));
9998 -- If a tag is present, then create a component clause that places it
9999 -- at the start of the record (otherwise gigi may place it after other
10000 -- fields that have rep clauses).
10002 Fent
:= First_Entity
(Rectype
);
10004 if Nkind
(Fent
) = N_Defining_Identifier
10005 and then Chars
(Fent
) = Name_uTag
10007 Set_Component_Bit_Offset
(Fent
, Uint_0
);
10008 Set_Normalized_Position
(Fent
, Uint_0
);
10009 Set_Normalized_First_Bit
(Fent
, Uint_0
);
10010 Set_Normalized_Position_Max
(Fent
, Uint_0
);
10011 Init_Esize
(Fent
, System_Address_Size
);
10013 Set_Component_Clause
(Fent
,
10014 Make_Component_Clause
(Loc
,
10015 Component_Name
=> Make_Identifier
(Loc
, Name_uTag
),
10017 Position
=> Make_Integer_Literal
(Loc
, Uint_0
),
10018 First_Bit
=> Make_Integer_Literal
(Loc
, Uint_0
),
10020 Make_Integer_Literal
(Loc
,
10021 UI_From_Int
(System_Address_Size
))));
10023 Ccount
:= Ccount
+ 1;
10026 Max_Bit_So_Far
:= Uint_Minus_1
;
10027 Overlap_Check_Required
:= False;
10029 -- Process the component clauses
10031 while Present
(CC
) loop
10034 if Present
(Comp
) then
10035 Ccount
:= Ccount
+ 1;
10037 -- We need a full overlap check if record positions non-monotonic
10039 if Fbit
<= Max_Bit_So_Far
then
10040 Overlap_Check_Required
:= True;
10043 Max_Bit_So_Far
:= Lbit
;
10045 -- Check bit position out of range of specified size
10047 if Has_Size_Clause
(Rectype
)
10048 and then RM_Size
(Rectype
) <= Lbit
10051 ("bit number out of range of specified size",
10054 -- Check for overlap with tag component
10057 if Is_Tagged_Type
(Rectype
)
10058 and then Fbit
< System_Address_Size
10061 ("component overlaps tag field of&",
10062 Component_Name
(CC
), Rectype
);
10063 Overlap_Detected
:= True;
10066 if Hbit
< Lbit
then
10071 -- Check parent overlap if component might overlap parent field
10073 if Present
(Tagged_Parent
) and then Fbit
<= Parent_Last_Bit
then
10074 Pcomp
:= First_Component_Or_Discriminant
(Tagged_Parent
);
10075 while Present
(Pcomp
) loop
10076 if not Is_Tag
(Pcomp
)
10077 and then Chars
(Pcomp
) /= Name_uParent
10079 Check_Component_Overlap
(Comp
, Pcomp
);
10082 Next_Component_Or_Discriminant
(Pcomp
);
10090 -- Now that we have processed all the component clauses, check for
10091 -- overlap. We have to leave this till last, since the components can
10092 -- appear in any arbitrary order in the representation clause.
10094 -- We do not need this check if all specified ranges were monotonic,
10095 -- as recorded by Overlap_Check_Required being False at this stage.
10097 -- This first section checks if there are any overlapping entries at
10098 -- all. It does this by sorting all entries and then seeing if there are
10099 -- any overlaps. If there are none, then that is decisive, but if there
10100 -- are overlaps, they may still be OK (they may result from fields in
10101 -- different variants).
10103 if Overlap_Check_Required
then
10104 Overlap_Check1
: declare
10106 OC_Fbit
: array (0 .. Ccount
) of Uint
;
10107 -- First-bit values for component clauses, the value is the offset
10108 -- of the first bit of the field from start of record. The zero
10109 -- entry is for use in sorting.
10111 OC_Lbit
: array (0 .. Ccount
) of Uint
;
10112 -- Last-bit values for component clauses, the value is the offset
10113 -- of the last bit of the field from start of record. The zero
10114 -- entry is for use in sorting.
10116 OC_Count
: Natural := 0;
10117 -- Count of entries in OC_Fbit and OC_Lbit
10119 function OC_Lt
(Op1
, Op2
: Natural) return Boolean;
10120 -- Compare routine for Sort
10122 procedure OC_Move
(From
: Natural; To
: Natural);
10123 -- Move routine for Sort
10125 package Sorting
is new GNAT
.Heap_Sort_G
(OC_Move
, OC_Lt
);
10131 function OC_Lt
(Op1
, Op2
: Natural) return Boolean is
10133 return OC_Fbit
(Op1
) < OC_Fbit
(Op2
);
10140 procedure OC_Move
(From
: Natural; To
: Natural) is
10142 OC_Fbit
(To
) := OC_Fbit
(From
);
10143 OC_Lbit
(To
) := OC_Lbit
(From
);
10146 -- Start of processing for Overlap_Check
10149 CC
:= First
(Component_Clauses
(N
));
10150 while Present
(CC
) loop
10152 -- Exclude component clause already marked in error
10154 if not Error_Posted
(CC
) then
10157 if Present
(Comp
) then
10158 OC_Count
:= OC_Count
+ 1;
10159 OC_Fbit
(OC_Count
) := Fbit
;
10160 OC_Lbit
(OC_Count
) := Lbit
;
10167 Sorting
.Sort
(OC_Count
);
10169 Overlap_Check_Required
:= False;
10170 for J
in 1 .. OC_Count
- 1 loop
10171 if OC_Lbit
(J
) >= OC_Fbit
(J
+ 1) then
10172 Overlap_Check_Required
:= True;
10176 end Overlap_Check1
;
10179 -- If Overlap_Check_Required is still True, then we have to do the full
10180 -- scale overlap check, since we have at least two fields that do
10181 -- overlap, and we need to know if that is OK since they are in
10182 -- different variant, or whether we have a definite problem.
10184 if Overlap_Check_Required
then
10185 Overlap_Check2
: declare
10186 C1_Ent
, C2_Ent
: Entity_Id
;
10187 -- Entities of components being checked for overlap
10190 -- Component_List node whose Component_Items are being checked
10193 -- Component declaration for component being checked
10196 C1_Ent
:= First_Entity
(Base_Type
(Rectype
));
10198 -- Loop through all components in record. For each component check
10199 -- for overlap with any of the preceding elements on the component
10200 -- list containing the component and also, if the component is in
10201 -- a variant, check against components outside the case structure.
10202 -- This latter test is repeated recursively up the variant tree.
10204 Main_Component_Loop
: while Present
(C1_Ent
) loop
10205 if not Ekind_In
(C1_Ent
, E_Component
, E_Discriminant
) then
10206 goto Continue_Main_Component_Loop
;
10209 -- Skip overlap check if entity has no declaration node. This
10210 -- happens with discriminants in constrained derived types.
10211 -- Possibly we are missing some checks as a result, but that
10212 -- does not seem terribly serious.
10214 if No
(Declaration_Node
(C1_Ent
)) then
10215 goto Continue_Main_Component_Loop
;
10218 Clist
:= Parent
(List_Containing
(Declaration_Node
(C1_Ent
)));
10220 -- Loop through component lists that need checking. Check the
10221 -- current component list and all lists in variants above us.
10223 Component_List_Loop
: loop
10225 -- If derived type definition, go to full declaration
10226 -- If at outer level, check discriminants if there are any.
10228 if Nkind
(Clist
) = N_Derived_Type_Definition
then
10229 Clist
:= Parent
(Clist
);
10232 -- Outer level of record definition, check discriminants
10234 if Nkind_In
(Clist
, N_Full_Type_Declaration
,
10235 N_Private_Type_Declaration
)
10237 if Has_Discriminants
(Defining_Identifier
(Clist
)) then
10239 First_Discriminant
(Defining_Identifier
(Clist
));
10240 while Present
(C2_Ent
) loop
10241 exit when C1_Ent
= C2_Ent
;
10242 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
10243 Next_Discriminant
(C2_Ent
);
10247 -- Record extension case
10249 elsif Nkind
(Clist
) = N_Derived_Type_Definition
then
10252 -- Otherwise check one component list
10255 Citem
:= First
(Component_Items
(Clist
));
10256 while Present
(Citem
) loop
10257 if Nkind
(Citem
) = N_Component_Declaration
then
10258 C2_Ent
:= Defining_Identifier
(Citem
);
10259 exit when C1_Ent
= C2_Ent
;
10260 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
10267 -- Check for variants above us (the parent of the Clist can
10268 -- be a variant, in which case its parent is a variant part,
10269 -- and the parent of the variant part is a component list
10270 -- whose components must all be checked against the current
10271 -- component for overlap).
10273 if Nkind
(Parent
(Clist
)) = N_Variant
then
10274 Clist
:= Parent
(Parent
(Parent
(Clist
)));
10276 -- Check for possible discriminant part in record, this
10277 -- is treated essentially as another level in the
10278 -- recursion. For this case the parent of the component
10279 -- list is the record definition, and its parent is the
10280 -- full type declaration containing the discriminant
10283 elsif Nkind
(Parent
(Clist
)) = N_Record_Definition
then
10284 Clist
:= Parent
(Parent
((Clist
)));
10286 -- If neither of these two cases, we are at the top of
10290 exit Component_List_Loop
;
10292 end loop Component_List_Loop
;
10294 <<Continue_Main_Component_Loop
>>
10295 Next_Entity
(C1_Ent
);
10297 end loop Main_Component_Loop
;
10298 end Overlap_Check2
;
10301 -- The following circuit deals with warning on record holes (gaps). We
10302 -- skip this check if overlap was detected, since it makes sense for the
10303 -- programmer to fix this illegality before worrying about warnings.
10305 if not Overlap_Detected
and Warn_On_Record_Holes
then
10306 Record_Hole_Check
: declare
10307 Decl
: constant Node_Id
:= Declaration_Node
(Base_Type
(Rectype
));
10308 -- Full declaration of record type
10310 procedure Check_Component_List
10314 -- Check component list CL for holes. The starting bit should be
10315 -- Sbit. which is zero for the main record component list and set
10316 -- appropriately for recursive calls for variants. DS is set to
10317 -- a list of discriminant specifications to be included in the
10318 -- consideration of components. It is No_List if none to consider.
10320 --------------------------
10321 -- Check_Component_List --
10322 --------------------------
10324 procedure Check_Component_List
10332 Compl
:= Integer (List_Length
(Component_Items
(CL
)));
10334 if DS
/= No_List
then
10335 Compl
:= Compl
+ Integer (List_Length
(DS
));
10339 Comps
: array (Natural range 0 .. Compl
) of Entity_Id
;
10340 -- Gather components (zero entry is for sort routine)
10342 Ncomps
: Natural := 0;
10343 -- Number of entries stored in Comps (starting at Comps (1))
10346 -- One component item or discriminant specification
10349 -- Starting bit for next component
10352 -- Component entity
10357 function Lt
(Op1
, Op2
: Natural) return Boolean;
10358 -- Compare routine for Sort
10360 procedure Move
(From
: Natural; To
: Natural);
10361 -- Move routine for Sort
10363 package Sorting
is new GNAT
.Heap_Sort_G
(Move
, Lt
);
10369 function Lt
(Op1
, Op2
: Natural) return Boolean is
10371 return Component_Bit_Offset
(Comps
(Op1
))
10373 Component_Bit_Offset
(Comps
(Op2
));
10380 procedure Move
(From
: Natural; To
: Natural) is
10382 Comps
(To
) := Comps
(From
);
10386 -- Gather discriminants into Comp
10388 if DS
/= No_List
then
10389 Citem
:= First
(DS
);
10390 while Present
(Citem
) loop
10391 if Nkind
(Citem
) = N_Discriminant_Specification
then
10393 Ent
: constant Entity_Id
:=
10394 Defining_Identifier
(Citem
);
10396 if Ekind
(Ent
) = E_Discriminant
then
10397 Ncomps
:= Ncomps
+ 1;
10398 Comps
(Ncomps
) := Ent
;
10407 -- Gather component entities into Comp
10409 Citem
:= First
(Component_Items
(CL
));
10410 while Present
(Citem
) loop
10411 if Nkind
(Citem
) = N_Component_Declaration
then
10412 Ncomps
:= Ncomps
+ 1;
10413 Comps
(Ncomps
) := Defining_Identifier
(Citem
);
10419 -- Now sort the component entities based on the first bit.
10420 -- Note we already know there are no overlapping components.
10422 Sorting
.Sort
(Ncomps
);
10424 -- Loop through entries checking for holes
10427 for J
in 1 .. Ncomps
loop
10429 Error_Msg_Uint_1
:= Component_Bit_Offset
(CEnt
) - Nbit
;
10431 if Error_Msg_Uint_1
> 0 then
10433 ("?H?^-bit gap before component&",
10434 Component_Name
(Component_Clause
(CEnt
)), CEnt
);
10437 Nbit
:= Component_Bit_Offset
(CEnt
) + Esize
(CEnt
);
10440 -- Process variant parts recursively if present
10442 if Present
(Variant_Part
(CL
)) then
10443 Variant
:= First
(Variants
(Variant_Part
(CL
)));
10444 while Present
(Variant
) loop
10445 Check_Component_List
10446 (Component_List
(Variant
), Nbit
, No_List
);
10451 end Check_Component_List
;
10453 -- Start of processing for Record_Hole_Check
10460 if Is_Tagged_Type
(Rectype
) then
10461 Sbit
:= UI_From_Int
(System_Address_Size
);
10466 if Nkind
(Decl
) = N_Full_Type_Declaration
10467 and then Nkind
(Type_Definition
(Decl
)) = N_Record_Definition
10469 Check_Component_List
10470 (Component_List
(Type_Definition
(Decl
)),
10472 Discriminant_Specifications
(Decl
));
10475 end Record_Hole_Check
;
10478 -- For records that have component clauses for all components, and whose
10479 -- size is less than or equal to 32, we need to know the size in the
10480 -- front end to activate possible packed array processing where the
10481 -- component type is a record.
10483 -- At this stage Hbit + 1 represents the first unused bit from all the
10484 -- component clauses processed, so if the component clauses are
10485 -- complete, then this is the length of the record.
10487 -- For records longer than System.Storage_Unit, and for those where not
10488 -- all components have component clauses, the back end determines the
10489 -- length (it may for example be appropriate to round up the size
10490 -- to some convenient boundary, based on alignment considerations, etc).
10492 if Unknown_RM_Size
(Rectype
) and then Hbit
+ 1 <= 32 then
10494 -- Nothing to do if at least one component has no component clause
10496 Comp
:= First_Component_Or_Discriminant
(Rectype
);
10497 while Present
(Comp
) loop
10498 exit when No
(Component_Clause
(Comp
));
10499 Next_Component_Or_Discriminant
(Comp
);
10502 -- If we fall out of loop, all components have component clauses
10503 -- and so we can set the size to the maximum value.
10506 Set_RM_Size
(Rectype
, Hbit
+ 1);
10509 end Check_Record_Representation_Clause
;
10515 procedure Check_Size
10519 Biased
: out Boolean)
10521 UT
: constant Entity_Id
:= Underlying_Type
(T
);
10527 -- Reject patently improper size values.
10529 if Is_Elementary_Type
(T
)
10530 and then Siz
> UI_From_Int
(Int
'Last)
10532 Error_Msg_N
("Size value too large for elementary type", N
);
10534 if Nkind
(Original_Node
(N
)) = N_Op_Expon
then
10536 ("\maybe '* was meant, rather than '*'*", Original_Node
(N
));
10540 -- Dismiss generic types
10542 if Is_Generic_Type
(T
)
10544 Is_Generic_Type
(UT
)
10546 Is_Generic_Type
(Root_Type
(UT
))
10550 -- Guard against previous errors
10552 elsif No
(UT
) or else UT
= Any_Type
then
10553 Check_Error_Detected
;
10556 -- Check case of bit packed array
10558 elsif Is_Array_Type
(UT
)
10559 and then Known_Static_Component_Size
(UT
)
10560 and then Is_Bit_Packed_Array
(UT
)
10568 Asiz
:= Component_Size
(UT
);
10569 Indx
:= First_Index
(UT
);
10571 Ityp
:= Etype
(Indx
);
10573 -- If non-static bound, then we are not in the business of
10574 -- trying to check the length, and indeed an error will be
10575 -- issued elsewhere, since sizes of non-static array types
10576 -- cannot be set implicitly or explicitly.
10578 if not Is_OK_Static_Subtype
(Ityp
) then
10582 -- Otherwise accumulate next dimension
10584 Asiz
:= Asiz
* (Expr_Value
(Type_High_Bound
(Ityp
)) -
10585 Expr_Value
(Type_Low_Bound
(Ityp
)) +
10589 exit when No
(Indx
);
10592 if Asiz
<= Siz
then
10596 Error_Msg_Uint_1
:= Asiz
;
10598 ("size for& too small, minimum allowed is ^", N
, T
);
10599 Set_Esize
(T
, Asiz
);
10600 Set_RM_Size
(T
, Asiz
);
10604 -- All other composite types are ignored
10606 elsif Is_Composite_Type
(UT
) then
10609 -- For fixed-point types, don't check minimum if type is not frozen,
10610 -- since we don't know all the characteristics of the type that can
10611 -- affect the size (e.g. a specified small) till freeze time.
10613 elsif Is_Fixed_Point_Type
(UT
)
10614 and then not Is_Frozen
(UT
)
10618 -- Cases for which a minimum check is required
10621 -- Ignore if specified size is correct for the type
10623 if Known_Esize
(UT
) and then Siz
= Esize
(UT
) then
10627 -- Otherwise get minimum size
10629 M
:= UI_From_Int
(Minimum_Size
(UT
));
10633 -- Size is less than minimum size, but one possibility remains
10634 -- that we can manage with the new size if we bias the type.
10636 M
:= UI_From_Int
(Minimum_Size
(UT
, Biased
=> True));
10639 Error_Msg_Uint_1
:= M
;
10641 ("size for& too small, minimum allowed is ^", N
, T
);
10643 Set_RM_Size
(T
, M
);
10651 --------------------------
10652 -- Freeze_Entity_Checks --
10653 --------------------------
10655 procedure Freeze_Entity_Checks
(N
: Node_Id
) is
10656 procedure Hide_Non_Overridden_Subprograms
(Typ
: Entity_Id
);
10657 -- Inspect the primitive operations of type Typ and hide all pairs of
10658 -- implicitly declared non-overridden non-fully conformant homographs
10659 -- (Ada RM 8.3 12.3/2).
10661 -------------------------------------
10662 -- Hide_Non_Overridden_Subprograms --
10663 -------------------------------------
10665 procedure Hide_Non_Overridden_Subprograms
(Typ
: Entity_Id
) is
10666 procedure Hide_Matching_Homographs
10667 (Subp_Id
: Entity_Id
;
10668 Start_Elmt
: Elmt_Id
);
10669 -- Inspect a list of primitive operations starting with Start_Elmt
10670 -- and find matching implicitly declared non-overridden non-fully
10671 -- conformant homographs of Subp_Id. If found, all matches along
10672 -- with Subp_Id are hidden from all visibility.
10674 function Is_Non_Overridden_Or_Null_Procedure
10675 (Subp_Id
: Entity_Id
) return Boolean;
10676 -- Determine whether subprogram Subp_Id is implicitly declared non-
10677 -- overridden subprogram or an implicitly declared null procedure.
10679 ------------------------------
10680 -- Hide_Matching_Homographs --
10681 ------------------------------
10683 procedure Hide_Matching_Homographs
10684 (Subp_Id
: Entity_Id
;
10685 Start_Elmt
: Elmt_Id
)
10688 Prim_Elmt
: Elmt_Id
;
10691 Prim_Elmt
:= Start_Elmt
;
10692 while Present
(Prim_Elmt
) loop
10693 Prim
:= Node
(Prim_Elmt
);
10695 -- The current primitive is implicitly declared non-overridden
10696 -- non-fully conformant homograph of Subp_Id. Both subprograms
10697 -- must be hidden from visibility.
10699 if Chars
(Prim
) = Chars
(Subp_Id
)
10700 and then Is_Non_Overridden_Or_Null_Procedure
(Prim
)
10701 and then not Fully_Conformant
(Prim
, Subp_Id
)
10703 Set_Is_Hidden_Non_Overridden_Subpgm
(Prim
);
10704 Set_Is_Immediately_Visible
(Prim
, False);
10705 Set_Is_Potentially_Use_Visible
(Prim
, False);
10707 Set_Is_Hidden_Non_Overridden_Subpgm
(Subp_Id
);
10708 Set_Is_Immediately_Visible
(Subp_Id
, False);
10709 Set_Is_Potentially_Use_Visible
(Subp_Id
, False);
10712 Next_Elmt
(Prim_Elmt
);
10714 end Hide_Matching_Homographs
;
10716 -----------------------------------------
10717 -- Is_Non_Overridden_Or_Null_Procedure --
10718 -----------------------------------------
10720 function Is_Non_Overridden_Or_Null_Procedure
10721 (Subp_Id
: Entity_Id
) return Boolean
10723 Alias_Id
: Entity_Id
;
10726 -- The subprogram is inherited (implicitly declared), it does not
10727 -- override and does not cover a primitive of an interface.
10729 if Ekind_In
(Subp_Id
, E_Function
, E_Procedure
)
10730 and then Present
(Alias
(Subp_Id
))
10731 and then No
(Interface_Alias
(Subp_Id
))
10732 and then No
(Overridden_Operation
(Subp_Id
))
10734 Alias_Id
:= Alias
(Subp_Id
);
10736 if Requires_Overriding
(Alias_Id
) then
10739 elsif Nkind
(Parent
(Alias_Id
)) = N_Procedure_Specification
10740 and then Null_Present
(Parent
(Alias_Id
))
10747 end Is_Non_Overridden_Or_Null_Procedure
;
10751 Prim_Ops
: constant Elist_Id
:= Direct_Primitive_Operations
(Typ
);
10753 Prim_Elmt
: Elmt_Id
;
10755 -- Start of processing for Hide_Non_Overridden_Subprograms
10758 -- Inspect the list of primitives looking for non-overridden
10761 if Present
(Prim_Ops
) then
10762 Prim_Elmt
:= First_Elmt
(Prim_Ops
);
10763 while Present
(Prim_Elmt
) loop
10764 Prim
:= Node
(Prim_Elmt
);
10765 Next_Elmt
(Prim_Elmt
);
10767 if Is_Non_Overridden_Or_Null_Procedure
(Prim
) then
10768 Hide_Matching_Homographs
10770 Start_Elmt
=> Prim_Elmt
);
10774 end Hide_Non_Overridden_Subprograms
;
10776 ---------------------
10777 -- Local variables --
10778 ---------------------
10780 E
: constant Entity_Id
:= Entity
(N
);
10782 Non_Generic_Case
: constant Boolean := Nkind
(N
) = N_Freeze_Entity
;
10783 -- True in non-generic case. Some of the processing here is skipped
10784 -- for the generic case since it is not needed. Basically in the
10785 -- generic case, we only need to do stuff that might generate error
10786 -- messages or warnings.
10788 -- Start of processing for Freeze_Entity_Checks
10791 -- Remember that we are processing a freezing entity. Required to
10792 -- ensure correct decoration of internal entities associated with
10793 -- interfaces (see New_Overloaded_Entity).
10795 Inside_Freezing_Actions
:= Inside_Freezing_Actions
+ 1;
10797 -- For tagged types covering interfaces add internal entities that link
10798 -- the primitives of the interfaces with the primitives that cover them.
10799 -- Note: These entities were originally generated only when generating
10800 -- code because their main purpose was to provide support to initialize
10801 -- the secondary dispatch tables. They are now generated also when
10802 -- compiling with no code generation to provide ASIS the relationship
10803 -- between interface primitives and tagged type primitives. They are
10804 -- also used to locate primitives covering interfaces when processing
10805 -- generics (see Derive_Subprograms).
10807 -- This is not needed in the generic case
10809 if Ada_Version
>= Ada_2005
10810 and then Non_Generic_Case
10811 and then Ekind
(E
) = E_Record_Type
10812 and then Is_Tagged_Type
(E
)
10813 and then not Is_Interface
(E
)
10814 and then Has_Interfaces
(E
)
10816 -- This would be a good common place to call the routine that checks
10817 -- overriding of interface primitives (and thus factorize calls to
10818 -- Check_Abstract_Overriding located at different contexts in the
10819 -- compiler). However, this is not possible because it causes
10820 -- spurious errors in case of late overriding.
10822 Add_Internal_Interface_Entities
(E
);
10825 -- After all forms of overriding have been resolved, a tagged type may
10826 -- be left with a set of implicitly declared and possibly erroneous
10827 -- abstract subprograms, null procedures and subprograms that require
10828 -- overriding. If this set contains fully conformat homographs, then one
10829 -- is chosen arbitrarily (already done during resolution), otherwise all
10830 -- remaining non-fully conformant homographs are hidden from visibility
10831 -- (Ada RM 8.3 12.3/2).
10833 if Is_Tagged_Type
(E
) then
10834 Hide_Non_Overridden_Subprograms
(E
);
10839 if Ekind
(E
) = E_Record_Type
10840 and then Is_CPP_Class
(E
)
10841 and then Is_Tagged_Type
(E
)
10842 and then Tagged_Type_Expansion
10844 if CPP_Num_Prims
(E
) = 0 then
10846 -- If the CPP type has user defined components then it must import
10847 -- primitives from C++. This is required because if the C++ class
10848 -- has no primitives then the C++ compiler does not added the _tag
10849 -- component to the type.
10851 if First_Entity
(E
) /= Last_Entity
(E
) then
10853 ("'C'P'P type must import at least one primitive from C++??",
10858 -- Check that all its primitives are abstract or imported from C++.
10859 -- Check also availability of the C++ constructor.
10862 Has_Constructors
: constant Boolean := Has_CPP_Constructors
(E
);
10864 Error_Reported
: Boolean := False;
10868 Elmt
:= First_Elmt
(Primitive_Operations
(E
));
10869 while Present
(Elmt
) loop
10870 Prim
:= Node
(Elmt
);
10872 if Comes_From_Source
(Prim
) then
10873 if Is_Abstract_Subprogram
(Prim
) then
10876 elsif not Is_Imported
(Prim
)
10877 or else Convention
(Prim
) /= Convention_CPP
10880 ("primitives of 'C'P'P types must be imported from C++ "
10881 & "or abstract??", Prim
);
10883 elsif not Has_Constructors
10884 and then not Error_Reported
10886 Error_Msg_Name_1
:= Chars
(E
);
10888 ("??'C'P'P constructor required for type %", Prim
);
10889 Error_Reported
:= True;
10898 -- Check Ada derivation of CPP type
10900 if Expander_Active
-- why? losing errors in -gnatc mode???
10901 and then Present
(Etype
(E
)) -- defend against errors
10902 and then Tagged_Type_Expansion
10903 and then Ekind
(E
) = E_Record_Type
10904 and then Etype
(E
) /= E
10905 and then Is_CPP_Class
(Etype
(E
))
10906 and then CPP_Num_Prims
(Etype
(E
)) > 0
10907 and then not Is_CPP_Class
(E
)
10908 and then not Has_CPP_Constructors
(Etype
(E
))
10910 -- If the parent has C++ primitives but it has no constructor then
10911 -- check that all the primitives are overridden in this derivation;
10912 -- otherwise the constructor of the parent is needed to build the
10920 Elmt
:= First_Elmt
(Primitive_Operations
(E
));
10921 while Present
(Elmt
) loop
10922 Prim
:= Node
(Elmt
);
10924 if not Is_Abstract_Subprogram
(Prim
)
10925 and then No
(Interface_Alias
(Prim
))
10926 and then Find_Dispatching_Type
(Ultimate_Alias
(Prim
)) /= E
10928 Error_Msg_Name_1
:= Chars
(Etype
(E
));
10930 ("'C'P'P constructor required for parent type %", E
);
10939 Inside_Freezing_Actions
:= Inside_Freezing_Actions
- 1;
10941 -- If we have a type with predicates, build predicate function. This
10942 -- is not needed in the generic case, and is not needed within TSS
10943 -- subprograms and other predefined primitives.
10945 if Non_Generic_Case
10946 and then Is_Type
(E
)
10947 and then Has_Predicates
(E
)
10948 and then not Within_Internal_Subprogram
10950 Build_Predicate_Functions
(E
, N
);
10953 -- If type has delayed aspects, this is where we do the preanalysis at
10954 -- the freeze point, as part of the consistent visibility check. Note
10955 -- that this must be done after calling Build_Predicate_Functions or
10956 -- Build_Invariant_Procedure since these subprograms fix occurrences of
10957 -- the subtype name in the saved expression so that they will not cause
10958 -- trouble in the preanalysis.
10960 -- This is also not needed in the generic case
10962 if Non_Generic_Case
10963 and then Has_Delayed_Aspects
(E
)
10964 and then Scope
(E
) = Current_Scope
10966 -- Retrieve the visibility to the discriminants in order to properly
10967 -- analyze the aspects.
10969 Push_Scope_And_Install_Discriminants
(E
);
10975 -- Look for aspect specification entries for this entity
10977 Ritem
:= First_Rep_Item
(E
);
10978 while Present
(Ritem
) loop
10979 if Nkind
(Ritem
) = N_Aspect_Specification
10980 and then Entity
(Ritem
) = E
10981 and then Is_Delayed_Aspect
(Ritem
)
10983 Check_Aspect_At_Freeze_Point
(Ritem
);
10986 Next_Rep_Item
(Ritem
);
10990 Uninstall_Discriminants_And_Pop_Scope
(E
);
10993 -- For a record type, deal with variant parts. This has to be delayed
10994 -- to this point, because of the issue of statically predicated
10995 -- subtypes, which we have to ensure are frozen before checking
10996 -- choices, since we need to have the static choice list set.
10998 if Is_Record_Type
(E
) then
10999 Check_Variant_Part
: declare
11000 D
: constant Node_Id
:= Declaration_Node
(E
);
11005 Others_Present
: Boolean;
11006 pragma Warnings
(Off
, Others_Present
);
11007 -- Indicates others present, not used in this case
11009 procedure Non_Static_Choice_Error
(Choice
: Node_Id
);
11010 -- Error routine invoked by the generic instantiation below when
11011 -- the variant part has a non static choice.
11013 procedure Process_Declarations
(Variant
: Node_Id
);
11014 -- Processes declarations associated with a variant. We analyzed
11015 -- the declarations earlier (in Sem_Ch3.Analyze_Variant_Part),
11016 -- but we still need the recursive call to Check_Choices for any
11017 -- nested variant to get its choices properly processed. This is
11018 -- also where we expand out the choices if expansion is active.
11020 package Variant_Choices_Processing
is new
11021 Generic_Check_Choices
11022 (Process_Empty_Choice
=> No_OP
,
11023 Process_Non_Static_Choice
=> Non_Static_Choice_Error
,
11024 Process_Associated_Node
=> Process_Declarations
);
11025 use Variant_Choices_Processing
;
11027 -----------------------------
11028 -- Non_Static_Choice_Error --
11029 -----------------------------
11031 procedure Non_Static_Choice_Error
(Choice
: Node_Id
) is
11033 Flag_Non_Static_Expr
11034 ("choice given in variant part is not static!", Choice
);
11035 end Non_Static_Choice_Error
;
11037 --------------------------
11038 -- Process_Declarations --
11039 --------------------------
11041 procedure Process_Declarations
(Variant
: Node_Id
) is
11042 CL
: constant Node_Id
:= Component_List
(Variant
);
11046 -- Check for static predicate present in this variant
11048 if Has_SP_Choice
(Variant
) then
11050 -- Here we expand. You might expect to find this call in
11051 -- Expand_N_Variant_Part, but that is called when we first
11052 -- see the variant part, and we cannot do this expansion
11053 -- earlier than the freeze point, since for statically
11054 -- predicated subtypes, the predicate is not known till
11055 -- the freeze point.
11057 -- Furthermore, we do this expansion even if the expander
11058 -- is not active, because other semantic processing, e.g.
11059 -- for aggregates, requires the expanded list of choices.
11061 -- If the expander is not active, then we can't just clobber
11062 -- the list since it would invalidate the ASIS -gnatct tree.
11063 -- So we have to rewrite the variant part with a Rewrite
11064 -- call that replaces it with a copy and clobber the copy.
11066 if not Expander_Active
then
11068 NewV
: constant Node_Id
:= New_Copy
(Variant
);
11070 Set_Discrete_Choices
11071 (NewV
, New_Copy_List
(Discrete_Choices
(Variant
)));
11072 Rewrite
(Variant
, NewV
);
11076 Expand_Static_Predicates_In_Choices
(Variant
);
11079 -- We don't need to worry about the declarations in the variant
11080 -- (since they were analyzed by Analyze_Choices when we first
11081 -- encountered the variant), but we do need to take care of
11082 -- expansion of any nested variants.
11084 if not Null_Present
(CL
) then
11085 VP
:= Variant_Part
(CL
);
11087 if Present
(VP
) then
11089 (VP
, Variants
(VP
), Etype
(Name
(VP
)), Others_Present
);
11092 end Process_Declarations
;
11094 -- Start of processing for Check_Variant_Part
11097 -- Find component list
11101 if Nkind
(D
) = N_Full_Type_Declaration
then
11102 T
:= Type_Definition
(D
);
11104 if Nkind
(T
) = N_Record_Definition
then
11105 C
:= Component_List
(T
);
11107 elsif Nkind
(T
) = N_Derived_Type_Definition
11108 and then Present
(Record_Extension_Part
(T
))
11110 C
:= Component_List
(Record_Extension_Part
(T
));
11114 -- Case of variant part present
11116 if Present
(C
) and then Present
(Variant_Part
(C
)) then
11117 VP
:= Variant_Part
(C
);
11122 (VP
, Variants
(VP
), Etype
(Name
(VP
)), Others_Present
);
11124 -- If the last variant does not contain the Others choice,
11125 -- replace it with an N_Others_Choice node since Gigi always
11126 -- wants an Others. Note that we do not bother to call Analyze
11127 -- on the modified variant part, since its only effect would be
11128 -- to compute the Others_Discrete_Choices node laboriously, and
11129 -- of course we already know the list of choices corresponding
11130 -- to the others choice (it's the list we're replacing).
11132 -- We only want to do this if the expander is active, since
11133 -- we do not want to clobber the ASIS tree.
11135 if Expander_Active
then
11137 Last_Var
: constant Node_Id
:=
11138 Last_Non_Pragma
(Variants
(VP
));
11140 Others_Node
: Node_Id
;
11143 if Nkind
(First
(Discrete_Choices
(Last_Var
))) /=
11146 Others_Node
:= Make_Others_Choice
(Sloc
(Last_Var
));
11147 Set_Others_Discrete_Choices
11148 (Others_Node
, Discrete_Choices
(Last_Var
));
11149 Set_Discrete_Choices
11150 (Last_Var
, New_List
(Others_Node
));
11155 end Check_Variant_Part
;
11157 end Freeze_Entity_Checks
;
11159 -------------------------
11160 -- Get_Alignment_Value --
11161 -------------------------
11163 function Get_Alignment_Value
(Expr
: Node_Id
) return Uint
is
11164 Align
: constant Uint
:= Static_Integer
(Expr
);
11167 if Align
= No_Uint
then
11170 elsif Align
<= 0 then
11171 Error_Msg_N
("alignment value must be positive", Expr
);
11175 for J
in Int
range 0 .. 64 loop
11177 M
: constant Uint
:= Uint_2
** J
;
11180 exit when M
= Align
;
11184 ("alignment value must be power of 2", Expr
);
11192 end Get_Alignment_Value
;
11194 -------------------------------------
11195 -- Inherit_Aspects_At_Freeze_Point --
11196 -------------------------------------
11198 procedure Inherit_Aspects_At_Freeze_Point
(Typ
: Entity_Id
) is
11199 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11200 (Rep_Item
: Node_Id
) return Boolean;
11201 -- This routine checks if Rep_Item is either a pragma or an aspect
11202 -- specification node whose correponding pragma (if any) is present in
11203 -- the Rep Item chain of the entity it has been specified to.
11205 --------------------------------------------------
11206 -- Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item --
11207 --------------------------------------------------
11209 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11210 (Rep_Item
: Node_Id
) return Boolean
11214 Nkind
(Rep_Item
) = N_Pragma
11215 or else Present_In_Rep_Item
11216 (Entity
(Rep_Item
), Aspect_Rep_Item
(Rep_Item
));
11217 end Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
;
11219 -- Start of processing for Inherit_Aspects_At_Freeze_Point
11222 -- A representation item is either subtype-specific (Size and Alignment
11223 -- clauses) or type-related (all others). Subtype-specific aspects may
11224 -- differ for different subtypes of the same type (RM 13.1.8).
11226 -- A derived type inherits each type-related representation aspect of
11227 -- its parent type that was directly specified before the declaration of
11228 -- the derived type (RM 13.1.15).
11230 -- A derived subtype inherits each subtype-specific representation
11231 -- aspect of its parent subtype that was directly specified before the
11232 -- declaration of the derived type (RM 13.1.15).
11234 -- The general processing involves inheriting a representation aspect
11235 -- from a parent type whenever the first rep item (aspect specification,
11236 -- attribute definition clause, pragma) corresponding to the given
11237 -- representation aspect in the rep item chain of Typ, if any, isn't
11238 -- directly specified to Typ but to one of its parents.
11240 -- ??? Note that, for now, just a limited number of representation
11241 -- aspects have been inherited here so far. Many of them are
11242 -- still inherited in Sem_Ch3. This will be fixed soon. Here is
11243 -- a non- exhaustive list of aspects that likely also need to
11244 -- be moved to this routine: Alignment, Component_Alignment,
11245 -- Component_Size, Machine_Radix, Object_Size, Pack, Predicates,
11246 -- Preelaborable_Initialization, RM_Size and Small.
11248 -- In addition, Convention must be propagated from base type to subtype,
11249 -- because the subtype may have been declared on an incomplete view.
11251 if Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
then
11257 if not Has_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
, False)
11258 and then Has_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
)
11259 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11260 (Get_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
))
11262 Set_Is_Ada_2005_Only
(Typ
);
11267 if not Has_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
, False)
11268 and then Has_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
)
11269 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11270 (Get_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
))
11272 Set_Is_Ada_2012_Only
(Typ
);
11277 if not Has_Rep_Item
(Typ
, Name_Atomic
, Name_Shared
, False)
11278 and then Has_Rep_Pragma
(Typ
, Name_Atomic
, Name_Shared
)
11279 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11280 (Get_Rep_Item
(Typ
, Name_Atomic
, Name_Shared
))
11282 Set_Is_Atomic
(Typ
);
11283 Set_Is_Volatile
(Typ
);
11284 Set_Treat_As_Volatile
(Typ
);
11289 if Is_Record_Type
(Typ
)
11290 and then Typ
/= Base_Type
(Typ
) and then Is_Frozen
(Base_Type
(Typ
))
11292 Set_Convention
(Typ
, Convention
(Base_Type
(Typ
)));
11295 -- Default_Component_Value
11297 -- Verify that there is no rep_item declared for the type, and there
11298 -- is one coming from an ancestor.
11300 if Is_Array_Type
(Typ
)
11301 and then Is_Base_Type
(Typ
)
11302 and then not Has_Rep_Item
(Typ
, Name_Default_Component_Value
, False)
11303 and then Has_Rep_Item
(Typ
, Name_Default_Component_Value
)
11305 Set_Default_Aspect_Component_Value
(Typ
,
11306 Default_Aspect_Component_Value
11307 (Entity
(Get_Rep_Item
(Typ
, Name_Default_Component_Value
))));
11312 if Is_Scalar_Type
(Typ
)
11313 and then Is_Base_Type
(Typ
)
11314 and then not Has_Rep_Item
(Typ
, Name_Default_Value
, False)
11315 and then Has_Rep_Item
(Typ
, Name_Default_Value
)
11317 Set_Has_Default_Aspect
(Typ
);
11318 Set_Default_Aspect_Value
(Typ
,
11319 Default_Aspect_Value
11320 (Entity
(Get_Rep_Item
(Typ
, Name_Default_Value
))));
11325 if not Has_Rep_Item
(Typ
, Name_Discard_Names
, False)
11326 and then Has_Rep_Item
(Typ
, Name_Discard_Names
)
11327 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11328 (Get_Rep_Item
(Typ
, Name_Discard_Names
))
11330 Set_Discard_Names
(Typ
);
11335 if not Has_Rep_Item
(Typ
, Name_Invariant
, False)
11336 and then Has_Rep_Item
(Typ
, Name_Invariant
)
11337 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11338 (Get_Rep_Item
(Typ
, Name_Invariant
))
11340 Set_Has_Invariants
(Typ
);
11342 if Class_Present
(Get_Rep_Item
(Typ
, Name_Invariant
)) then
11343 Set_Has_Inheritable_Invariants
(Typ
);
11346 -- If we have a subtype with invariants, whose base type does not have
11347 -- invariants, copy these invariants to the base type. This happens for
11348 -- the case of implicit base types created for scalar and array types.
11350 elsif Has_Invariants
(Typ
)
11351 and then not Has_Invariants
(Base_Type
(Typ
))
11353 Set_Has_Invariants
(Base_Type
(Typ
));
11354 Set_Invariant_Procedure
(Base_Type
(Typ
), Invariant_Procedure
(Typ
));
11359 if not Has_Rep_Item
(Typ
, Name_Volatile
, False)
11360 and then Has_Rep_Item
(Typ
, Name_Volatile
)
11361 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11362 (Get_Rep_Item
(Typ
, Name_Volatile
))
11364 Set_Is_Volatile
(Typ
);
11365 Set_Treat_As_Volatile
(Typ
);
11368 -- Volatile_Full_Access
11370 if not Has_Rep_Item
(Typ
, Name_Volatile_Full_Access
, False)
11371 and then Has_Rep_Pragma
(Typ
, Name_Volatile_Full_Access
)
11372 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11373 (Get_Rep_Item
(Typ
, Name_Volatile_Full_Access
))
11375 Set_Is_Volatile_Full_Access
(Typ
);
11376 Set_Is_Volatile
(Typ
);
11377 Set_Treat_As_Volatile
(Typ
);
11380 -- Inheritance for derived types only
11382 if Is_Derived_Type
(Typ
) then
11384 Bas_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
11385 Imp_Bas_Typ
: constant Entity_Id
:= Implementation_Base_Type
(Typ
);
11388 -- Atomic_Components
11390 if not Has_Rep_Item
(Typ
, Name_Atomic_Components
, False)
11391 and then Has_Rep_Item
(Typ
, Name_Atomic_Components
)
11392 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11393 (Get_Rep_Item
(Typ
, Name_Atomic_Components
))
11395 Set_Has_Atomic_Components
(Imp_Bas_Typ
);
11398 -- Volatile_Components
11400 if not Has_Rep_Item
(Typ
, Name_Volatile_Components
, False)
11401 and then Has_Rep_Item
(Typ
, Name_Volatile_Components
)
11402 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11403 (Get_Rep_Item
(Typ
, Name_Volatile_Components
))
11405 Set_Has_Volatile_Components
(Imp_Bas_Typ
);
11408 -- Finalize_Storage_Only
11410 if not Has_Rep_Pragma
(Typ
, Name_Finalize_Storage_Only
, False)
11411 and then Has_Rep_Pragma
(Typ
, Name_Finalize_Storage_Only
)
11413 Set_Finalize_Storage_Only
(Bas_Typ
);
11416 -- Universal_Aliasing
11418 if not Has_Rep_Item
(Typ
, Name_Universal_Aliasing
, False)
11419 and then Has_Rep_Item
(Typ
, Name_Universal_Aliasing
)
11420 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11421 (Get_Rep_Item
(Typ
, Name_Universal_Aliasing
))
11423 Set_Universal_Aliasing
(Imp_Bas_Typ
);
11428 if Is_Record_Type
(Typ
) then
11429 if not Has_Rep_Item
(Typ
, Name_Bit_Order
, False)
11430 and then Has_Rep_Item
(Typ
, Name_Bit_Order
)
11432 Set_Reverse_Bit_Order
(Bas_Typ
,
11433 Reverse_Bit_Order
(Entity
(Name
11434 (Get_Rep_Item
(Typ
, Name_Bit_Order
)))));
11438 -- Scalar_Storage_Order
11440 -- Note: the aspect is specified on a first subtype, but recorded
11441 -- in a flag of the base type!
11443 if (Is_Record_Type
(Typ
) or else Is_Array_Type
(Typ
))
11444 and then Typ
= Bas_Typ
11446 -- For a type extension, always inherit from parent; otherwise
11447 -- inherit if no default applies. Note: we do not check for
11448 -- an explicit rep item on the parent type when inheriting,
11449 -- because the parent SSO may itself have been set by default.
11451 if not Has_Rep_Item
(First_Subtype
(Typ
),
11452 Name_Scalar_Storage_Order
, False)
11453 and then (Is_Tagged_Type
(Bas_Typ
)
11454 or else not (SSO_Set_Low_By_Default
(Bas_Typ
)
11456 SSO_Set_High_By_Default
(Bas_Typ
)))
11458 Set_Reverse_Storage_Order
(Bas_Typ
,
11459 Reverse_Storage_Order
11460 (Implementation_Base_Type
(Etype
(Bas_Typ
))));
11462 -- Clear default SSO indications, since the inherited aspect
11463 -- which was set explicitly overrides the default.
11465 Set_SSO_Set_Low_By_Default
(Bas_Typ
, False);
11466 Set_SSO_Set_High_By_Default
(Bas_Typ
, False);
11471 end Inherit_Aspects_At_Freeze_Point
;
11477 procedure Initialize
is
11479 Address_Clause_Checks
.Init
;
11480 Unchecked_Conversions
.Init
;
11482 if AAMP_On_Target
then
11483 Independence_Checks
.Init
;
11487 ---------------------------
11488 -- Install_Discriminants --
11489 ---------------------------
11491 procedure Install_Discriminants
(E
: Entity_Id
) is
11495 Disc
:= First_Discriminant
(E
);
11496 while Present
(Disc
) loop
11497 Prev
:= Current_Entity
(Disc
);
11498 Set_Current_Entity
(Disc
);
11499 Set_Is_Immediately_Visible
(Disc
);
11500 Set_Homonym
(Disc
, Prev
);
11501 Next_Discriminant
(Disc
);
11503 end Install_Discriminants
;
11505 -------------------------
11506 -- Is_Operational_Item --
11507 -------------------------
11509 function Is_Operational_Item
(N
: Node_Id
) return Boolean is
11511 if Nkind
(N
) /= N_Attribute_Definition_Clause
then
11516 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Chars
(N
));
11519 -- List of operational items is given in AARM 13.1(8.mm/1).
11520 -- It is clearly incomplete, as it does not include iterator
11521 -- aspects, among others.
11523 return Id
= Attribute_Constant_Indexing
11524 or else Id
= Attribute_Default_Iterator
11525 or else Id
= Attribute_Implicit_Dereference
11526 or else Id
= Attribute_Input
11527 or else Id
= Attribute_Iterator_Element
11528 or else Id
= Attribute_Iterable
11529 or else Id
= Attribute_Output
11530 or else Id
= Attribute_Read
11531 or else Id
= Attribute_Variable_Indexing
11532 or else Id
= Attribute_Write
11533 or else Id
= Attribute_External_Tag
;
11536 end Is_Operational_Item
;
11538 -------------------------
11539 -- Is_Predicate_Static --
11540 -------------------------
11542 -- Note: the basic legality of the expression has already been checked, so
11543 -- we don't need to worry about cases or ranges on strings for example.
11545 function Is_Predicate_Static
11547 Nam
: Name_Id
) return Boolean
11549 function All_Static_Case_Alternatives
(L
: List_Id
) return Boolean;
11550 -- Given a list of case expression alternatives, returns True if all
11551 -- the alternatives are static (have all static choices, and a static
11554 function All_Static_Choices
(L
: List_Id
) return Boolean;
11555 -- Returns true if all elements of the list are OK static choices
11556 -- as defined below for Is_Static_Choice. Used for case expression
11557 -- alternatives and for the right operand of a membership test. An
11558 -- others_choice is static if the corresponding expression is static.
11559 -- The staticness of the bounds is checked separately.
11561 function Is_Static_Choice
(N
: Node_Id
) return Boolean;
11562 -- Returns True if N represents a static choice (static subtype, or
11563 -- static subtype indication, or static expression, or static range).
11565 -- Note that this is a bit more inclusive than we actually need
11566 -- (in particular membership tests do not allow the use of subtype
11567 -- indications). But that doesn't matter, we have already checked
11568 -- that the construct is legal to get this far.
11570 function Is_Type_Ref
(N
: Node_Id
) return Boolean;
11571 pragma Inline
(Is_Type_Ref
);
11572 -- Returns True if N is a reference to the type for the predicate in the
11573 -- expression (i.e. if it is an identifier whose Chars field matches the
11574 -- Nam given in the call). N must not be parenthesized, if the type name
11575 -- appears in parens, this routine will return False.
11577 ----------------------------------
11578 -- All_Static_Case_Alternatives --
11579 ----------------------------------
11581 function All_Static_Case_Alternatives
(L
: List_Id
) return Boolean is
11586 while Present
(N
) loop
11587 if not (All_Static_Choices
(Discrete_Choices
(N
))
11588 and then Is_OK_Static_Expression
(Expression
(N
)))
11597 end All_Static_Case_Alternatives
;
11599 ------------------------
11600 -- All_Static_Choices --
11601 ------------------------
11603 function All_Static_Choices
(L
: List_Id
) return Boolean is
11608 while Present
(N
) loop
11609 if not Is_Static_Choice
(N
) then
11617 end All_Static_Choices
;
11619 ----------------------
11620 -- Is_Static_Choice --
11621 ----------------------
11623 function Is_Static_Choice
(N
: Node_Id
) return Boolean is
11625 return Nkind
(N
) = N_Others_Choice
11626 or else Is_OK_Static_Expression
(N
)
11627 or else (Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
))
11628 and then Is_OK_Static_Subtype
(Entity
(N
)))
11629 or else (Nkind
(N
) = N_Subtype_Indication
11630 and then Is_OK_Static_Subtype
(Entity
(N
)))
11631 or else (Nkind
(N
) = N_Range
and then Is_OK_Static_Range
(N
));
11632 end Is_Static_Choice
;
11638 function Is_Type_Ref
(N
: Node_Id
) return Boolean is
11640 return Nkind
(N
) = N_Identifier
11641 and then Chars
(N
) = Nam
11642 and then Paren_Count
(N
) = 0;
11645 -- Start of processing for Is_Predicate_Static
11648 -- Predicate_Static means one of the following holds. Numbers are the
11649 -- corresponding paragraph numbers in (RM 3.2.4(16-22)).
11651 -- 16: A static expression
11653 if Is_OK_Static_Expression
(Expr
) then
11656 -- 17: A membership test whose simple_expression is the current
11657 -- instance, and whose membership_choice_list meets the requirements
11658 -- for a static membership test.
11660 elsif Nkind
(Expr
) in N_Membership_Test
11661 and then ((Present
(Right_Opnd
(Expr
))
11662 and then Is_Static_Choice
(Right_Opnd
(Expr
)))
11664 (Present
(Alternatives
(Expr
))
11665 and then All_Static_Choices
(Alternatives
(Expr
))))
11669 -- 18. A case_expression whose selecting_expression is the current
11670 -- instance, and whose dependent expressions are static expressions.
11672 elsif Nkind
(Expr
) = N_Case_Expression
11673 and then Is_Type_Ref
(Expression
(Expr
))
11674 and then All_Static_Case_Alternatives
(Alternatives
(Expr
))
11678 -- 19. A call to a predefined equality or ordering operator, where one
11679 -- operand is the current instance, and the other is a static
11682 -- Note: the RM is clearly wrong here in not excluding string types.
11683 -- Without this exclusion, we would allow expressions like X > "ABC"
11684 -- to be considered as predicate-static, which is clearly not intended,
11685 -- since the idea is for predicate-static to be a subset of normal
11686 -- static expressions (and "DEF" > "ABC" is not a static expression).
11688 -- However, we do allow internally generated (not from source) equality
11689 -- and inequality operations to be valid on strings (this helps deal
11690 -- with cases where we transform A in "ABC" to A = "ABC).
11692 elsif Nkind
(Expr
) in N_Op_Compare
11693 and then ((not Is_String_Type
(Etype
(Left_Opnd
(Expr
))))
11694 or else (Nkind_In
(Expr
, N_Op_Eq
, N_Op_Ne
)
11695 and then not Comes_From_Source
(Expr
)))
11696 and then ((Is_Type_Ref
(Left_Opnd
(Expr
))
11697 and then Is_OK_Static_Expression
(Right_Opnd
(Expr
)))
11699 (Is_Type_Ref
(Right_Opnd
(Expr
))
11700 and then Is_OK_Static_Expression
(Left_Opnd
(Expr
))))
11704 -- 20. A call to a predefined boolean logical operator, where each
11705 -- operand is predicate-static.
11707 elsif (Nkind_In
(Expr
, N_Op_And
, N_Op_Or
, N_Op_Xor
)
11708 and then Is_Predicate_Static
(Left_Opnd
(Expr
), Nam
)
11709 and then Is_Predicate_Static
(Right_Opnd
(Expr
), Nam
))
11711 (Nkind
(Expr
) = N_Op_Not
11712 and then Is_Predicate_Static
(Right_Opnd
(Expr
), Nam
))
11716 -- 21. A short-circuit control form where both operands are
11717 -- predicate-static.
11719 elsif Nkind
(Expr
) in N_Short_Circuit
11720 and then Is_Predicate_Static
(Left_Opnd
(Expr
), Nam
)
11721 and then Is_Predicate_Static
(Right_Opnd
(Expr
), Nam
)
11725 -- 22. A parenthesized predicate-static expression. This does not
11726 -- require any special test, since we just ignore paren levels in
11727 -- all the cases above.
11729 -- One more test that is an implementation artifact caused by the fact
11730 -- that we are analyzing not the original expression, but the generated
11731 -- expression in the body of the predicate function. This can include
11732 -- references to inherited predicates, so that the expression we are
11733 -- processing looks like:
11735 -- xxPredicate (typ (Inns)) and then expression
11737 -- Where the call is to a Predicate function for an inherited predicate.
11738 -- We simply ignore such a call, which could be to either a dynamic or
11739 -- a static predicate. Note that if the parent predicate is dynamic then
11740 -- eventually this type will be marked as dynamic, but you are allowed
11741 -- to specify a static predicate for a subtype which is inheriting a
11742 -- dynamic predicate, so the static predicate validation here ignores
11743 -- the inherited predicate even if it is dynamic.
11745 elsif Nkind
(Expr
) = N_Function_Call
11746 and then Is_Predicate_Function
(Entity
(Name
(Expr
)))
11750 -- That's an exhaustive list of tests, all other cases are not
11751 -- predicate-static, so we return False.
11756 end Is_Predicate_Static
;
11758 ---------------------
11759 -- Kill_Rep_Clause --
11760 ---------------------
11762 procedure Kill_Rep_Clause
(N
: Node_Id
) is
11764 pragma Assert
(Ignore_Rep_Clauses
);
11766 -- Note: we use Replace rather than Rewrite, because we don't want
11767 -- ASIS to be able to use Original_Node to dig out the (undecorated)
11768 -- rep clause that is being replaced.
11770 Replace
(N
, Make_Null_Statement
(Sloc
(N
)));
11772 -- The null statement must be marked as not coming from source. This is
11773 -- so that ASIS ignores it, and also the back end does not expect bogus
11774 -- "from source" null statements in weird places (e.g. in declarative
11775 -- regions where such null statements are not allowed).
11777 Set_Comes_From_Source
(N
, False);
11778 end Kill_Rep_Clause
;
11784 function Minimum_Size
11786 Biased
: Boolean := False) return Nat
11788 Lo
: Uint
:= No_Uint
;
11789 Hi
: Uint
:= No_Uint
;
11790 LoR
: Ureal
:= No_Ureal
;
11791 HiR
: Ureal
:= No_Ureal
;
11792 LoSet
: Boolean := False;
11793 HiSet
: Boolean := False;
11796 Ancest
: Entity_Id
;
11797 R_Typ
: constant Entity_Id
:= Root_Type
(T
);
11800 -- If bad type, return 0
11802 if T
= Any_Type
then
11805 -- For generic types, just return zero. There cannot be any legitimate
11806 -- need to know such a size, but this routine may be called with a
11807 -- generic type as part of normal processing.
11809 elsif Is_Generic_Type
(R_Typ
) or else R_Typ
= Any_Type
then
11812 -- Access types (cannot have size smaller than System.Address)
11814 elsif Is_Access_Type
(T
) then
11815 return System_Address_Size
;
11817 -- Floating-point types
11819 elsif Is_Floating_Point_Type
(T
) then
11820 return UI_To_Int
(Esize
(R_Typ
));
11824 elsif Is_Discrete_Type
(T
) then
11826 -- The following loop is looking for the nearest compile time known
11827 -- bounds following the ancestor subtype chain. The idea is to find
11828 -- the most restrictive known bounds information.
11832 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
11837 if Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
)) then
11838 Lo
:= Expr_Rep_Value
(Type_Low_Bound
(Ancest
));
11845 if Compile_Time_Known_Value
(Type_High_Bound
(Ancest
)) then
11846 Hi
:= Expr_Rep_Value
(Type_High_Bound
(Ancest
));
11852 Ancest
:= Ancestor_Subtype
(Ancest
);
11854 if No
(Ancest
) then
11855 Ancest
:= Base_Type
(T
);
11857 if Is_Generic_Type
(Ancest
) then
11863 -- Fixed-point types. We can't simply use Expr_Value to get the
11864 -- Corresponding_Integer_Value values of the bounds, since these do not
11865 -- get set till the type is frozen, and this routine can be called
11866 -- before the type is frozen. Similarly the test for bounds being static
11867 -- needs to include the case where we have unanalyzed real literals for
11868 -- the same reason.
11870 elsif Is_Fixed_Point_Type
(T
) then
11872 -- The following loop is looking for the nearest compile time known
11873 -- bounds following the ancestor subtype chain. The idea is to find
11874 -- the most restrictive known bounds information.
11878 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
11882 -- Note: In the following two tests for LoSet and HiSet, it may
11883 -- seem redundant to test for N_Real_Literal here since normally
11884 -- one would assume that the test for the value being known at
11885 -- compile time includes this case. However, there is a glitch.
11886 -- If the real literal comes from folding a non-static expression,
11887 -- then we don't consider any non- static expression to be known
11888 -- at compile time if we are in configurable run time mode (needed
11889 -- in some cases to give a clearer definition of what is and what
11890 -- is not accepted). So the test is indeed needed. Without it, we
11891 -- would set neither Lo_Set nor Hi_Set and get an infinite loop.
11894 if Nkind
(Type_Low_Bound
(Ancest
)) = N_Real_Literal
11895 or else Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
))
11897 LoR
:= Expr_Value_R
(Type_Low_Bound
(Ancest
));
11904 if Nkind
(Type_High_Bound
(Ancest
)) = N_Real_Literal
11905 or else Compile_Time_Known_Value
(Type_High_Bound
(Ancest
))
11907 HiR
:= Expr_Value_R
(Type_High_Bound
(Ancest
));
11913 Ancest
:= Ancestor_Subtype
(Ancest
);
11915 if No
(Ancest
) then
11916 Ancest
:= Base_Type
(T
);
11918 if Is_Generic_Type
(Ancest
) then
11924 Lo
:= UR_To_Uint
(LoR
/ Small_Value
(T
));
11925 Hi
:= UR_To_Uint
(HiR
/ Small_Value
(T
));
11927 -- No other types allowed
11930 raise Program_Error
;
11933 -- Fall through with Hi and Lo set. Deal with biased case
11936 and then not Is_Fixed_Point_Type
(T
)
11937 and then not (Is_Enumeration_Type
(T
)
11938 and then Has_Non_Standard_Rep
(T
)))
11939 or else Has_Biased_Representation
(T
)
11945 -- Null range case, size is always zero. We only do this in the discrete
11946 -- type case, since that's the odd case that came up. Probably we should
11947 -- also do this in the fixed-point case, but doing so causes peculiar
11948 -- gigi failures, and it is not worth worrying about this incredibly
11949 -- marginal case (explicit null-range fixed-point type declarations)???
11951 if Lo
> Hi
and then Is_Discrete_Type
(T
) then
11954 -- Signed case. Note that we consider types like range 1 .. -1 to be
11955 -- signed for the purpose of computing the size, since the bounds have
11956 -- to be accommodated in the base type.
11958 elsif Lo
< 0 or else Hi
< 0 then
11962 -- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1))
11963 -- Note that we accommodate the case where the bounds cross. This
11964 -- can happen either because of the way the bounds are declared
11965 -- or because of the algorithm in Freeze_Fixed_Point_Type.
11979 -- If both bounds are positive, make sure that both are represen-
11980 -- table in the case where the bounds are crossed. This can happen
11981 -- either because of the way the bounds are declared, or because of
11982 -- the algorithm in Freeze_Fixed_Point_Type.
11988 -- S = size, (can accommodate 0 .. (2**size - 1))
11991 while Hi
>= Uint_2
** S
loop
11999 ---------------------------
12000 -- New_Stream_Subprogram --
12001 ---------------------------
12003 procedure New_Stream_Subprogram
12007 Nam
: TSS_Name_Type
)
12009 Loc
: constant Source_Ptr
:= Sloc
(N
);
12010 Sname
: constant Name_Id
:= Make_TSS_Name
(Base_Type
(Ent
), Nam
);
12011 Subp_Id
: Entity_Id
;
12012 Subp_Decl
: Node_Id
;
12016 Defer_Declaration
: constant Boolean :=
12017 Is_Tagged_Type
(Ent
) or else Is_Private_Type
(Ent
);
12018 -- For a tagged type, there is a declaration for each stream attribute
12019 -- at the freeze point, and we must generate only a completion of this
12020 -- declaration. We do the same for private types, because the full view
12021 -- might be tagged. Otherwise we generate a declaration at the point of
12022 -- the attribute definition clause.
12024 function Build_Spec
return Node_Id
;
12025 -- Used for declaration and renaming declaration, so that this is
12026 -- treated as a renaming_as_body.
12032 function Build_Spec
return Node_Id
is
12033 Out_P
: constant Boolean := (Nam
= TSS_Stream_Read
);
12036 T_Ref
: constant Node_Id
:= New_Occurrence_Of
(Etyp
, Loc
);
12039 Subp_Id
:= Make_Defining_Identifier
(Loc
, Sname
);
12041 -- S : access Root_Stream_Type'Class
12043 Formals
:= New_List
(
12044 Make_Parameter_Specification
(Loc
,
12045 Defining_Identifier
=>
12046 Make_Defining_Identifier
(Loc
, Name_S
),
12048 Make_Access_Definition
(Loc
,
12050 New_Occurrence_Of
(
12051 Designated_Type
(Etype
(F
)), Loc
))));
12053 if Nam
= TSS_Stream_Input
then
12055 Make_Function_Specification
(Loc
,
12056 Defining_Unit_Name
=> Subp_Id
,
12057 Parameter_Specifications
=> Formals
,
12058 Result_Definition
=> T_Ref
);
12062 Append_To
(Formals
,
12063 Make_Parameter_Specification
(Loc
,
12064 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_V
),
12065 Out_Present
=> Out_P
,
12066 Parameter_Type
=> T_Ref
));
12069 Make_Procedure_Specification
(Loc
,
12070 Defining_Unit_Name
=> Subp_Id
,
12071 Parameter_Specifications
=> Formals
);
12077 -- Start of processing for New_Stream_Subprogram
12080 F
:= First_Formal
(Subp
);
12082 if Ekind
(Subp
) = E_Procedure
then
12083 Etyp
:= Etype
(Next_Formal
(F
));
12085 Etyp
:= Etype
(Subp
);
12088 -- Prepare subprogram declaration and insert it as an action on the
12089 -- clause node. The visibility for this entity is used to test for
12090 -- visibility of the attribute definition clause (in the sense of
12091 -- 8.3(23) as amended by AI-195).
12093 if not Defer_Declaration
then
12095 Make_Subprogram_Declaration
(Loc
,
12096 Specification
=> Build_Spec
);
12098 -- For a tagged type, there is always a visible declaration for each
12099 -- stream TSS (it is a predefined primitive operation), and the
12100 -- completion of this declaration occurs at the freeze point, which is
12101 -- not always visible at places where the attribute definition clause is
12102 -- visible. So, we create a dummy entity here for the purpose of
12103 -- tracking the visibility of the attribute definition clause itself.
12107 Make_Defining_Identifier
(Loc
, New_External_Name
(Sname
, 'V'));
12109 Make_Object_Declaration
(Loc
,
12110 Defining_Identifier
=> Subp_Id
,
12111 Object_Definition
=> New_Occurrence_Of
(Standard_Boolean
, Loc
));
12114 Insert_Action
(N
, Subp_Decl
);
12115 Set_Entity
(N
, Subp_Id
);
12118 Make_Subprogram_Renaming_Declaration
(Loc
,
12119 Specification
=> Build_Spec
,
12120 Name
=> New_Occurrence_Of
(Subp
, Loc
));
12122 if Defer_Declaration
then
12123 Set_TSS
(Base_Type
(Ent
), Subp_Id
);
12125 Insert_Action
(N
, Subp_Decl
);
12126 Copy_TSS
(Subp_Id
, Base_Type
(Ent
));
12128 end New_Stream_Subprogram
;
12130 ------------------------------------------
12131 -- Push_Scope_And_Install_Discriminants --
12132 ------------------------------------------
12134 procedure Push_Scope_And_Install_Discriminants
(E
: Entity_Id
) is
12136 if Has_Discriminants
(E
) then
12139 -- Make discriminants visible for type declarations and protected
12140 -- type declarations, not for subtype declarations (RM 13.1.1 (12/3))
12142 if Nkind
(Parent
(E
)) /= N_Subtype_Declaration
then
12143 Install_Discriminants
(E
);
12146 end Push_Scope_And_Install_Discriminants
;
12148 ------------------------
12149 -- Rep_Item_Too_Early --
12150 ------------------------
12152 function Rep_Item_Too_Early
(T
: Entity_Id
; N
: Node_Id
) return Boolean is
12154 -- Cannot apply non-operational rep items to generic types
12156 if Is_Operational_Item
(N
) then
12160 and then Is_Generic_Type
(Root_Type
(T
))
12161 and then (Nkind
(N
) /= N_Pragma
12162 or else Get_Pragma_Id
(N
) /= Pragma_Convention
)
12164 Error_Msg_N
("representation item not allowed for generic type", N
);
12168 -- Otherwise check for incomplete type
12170 if Is_Incomplete_Or_Private_Type
(T
)
12171 and then No
(Underlying_Type
(T
))
12173 (Nkind
(N
) /= N_Pragma
12174 or else Get_Pragma_Id
(N
) /= Pragma_Import
)
12177 ("representation item must be after full type declaration", N
);
12180 -- If the type has incomplete components, a representation clause is
12181 -- illegal but stream attributes and Convention pragmas are correct.
12183 elsif Has_Private_Component
(T
) then
12184 if Nkind
(N
) = N_Pragma
then
12189 ("representation item must appear after type is fully defined",
12196 end Rep_Item_Too_Early
;
12198 -----------------------
12199 -- Rep_Item_Too_Late --
12200 -----------------------
12202 function Rep_Item_Too_Late
12205 FOnly
: Boolean := False) return Boolean
12208 Parent_Type
: Entity_Id
;
12210 procedure No_Type_Rep_Item
;
12211 -- Output message indicating that no type-related aspects can be
12212 -- specified due to some property of the parent type.
12214 procedure Too_Late
;
12215 -- Output message for an aspect being specified too late
12217 -- Note that neither of the above errors is considered a serious one,
12218 -- since the effect is simply that we ignore the representation clause
12220 -- Is this really true? In any case if we make this change we must
12221 -- document the requirement in the spec of Rep_Item_Too_Late that
12222 -- if True is returned, then the rep item must be completely ignored???
12224 ----------------------
12225 -- No_Type_Rep_Item --
12226 ----------------------
12228 procedure No_Type_Rep_Item
is
12230 Error_Msg_N
("|type-related representation item not permitted!", N
);
12231 end No_Type_Rep_Item
;
12237 procedure Too_Late
is
12239 -- Other compilers seem more relaxed about rep items appearing too
12240 -- late. Since analysis tools typically don't care about rep items
12241 -- anyway, no reason to be too strict about this.
12243 if not Relaxed_RM_Semantics
then
12244 Error_Msg_N
("|representation item appears too late!", N
);
12248 -- Start of processing for Rep_Item_Too_Late
12251 -- First make sure entity is not frozen (RM 13.1(9))
12255 -- Exclude imported types, which may be frozen if they appear in a
12256 -- representation clause for a local type.
12258 and then not From_Limited_With
(T
)
12260 -- Exclude generated entities (not coming from source). The common
12261 -- case is when we generate a renaming which prematurely freezes the
12262 -- renamed internal entity, but we still want to be able to set copies
12263 -- of attribute values such as Size/Alignment.
12265 and then Comes_From_Source
(T
)
12268 S
:= First_Subtype
(T
);
12270 if Present
(Freeze_Node
(S
)) then
12271 if not Relaxed_RM_Semantics
then
12273 ("??no more representation items for }", Freeze_Node
(S
), S
);
12279 -- Check for case of untagged derived type whose parent either has
12280 -- primitive operations, or is a by reference type (RM 13.1(10)). In
12281 -- this case we do not output a Too_Late message, since there is no
12282 -- earlier point where the rep item could be placed to make it legal.
12286 and then Is_Derived_Type
(T
)
12287 and then not Is_Tagged_Type
(T
)
12289 Parent_Type
:= Etype
(Base_Type
(T
));
12291 if Has_Primitive_Operations
(Parent_Type
) then
12294 if not Relaxed_RM_Semantics
then
12296 ("\parent type & has primitive operations!", N
, Parent_Type
);
12301 elsif Is_By_Reference_Type
(Parent_Type
) then
12304 if not Relaxed_RM_Semantics
then
12306 ("\parent type & is a by reference type!", N
, Parent_Type
);
12313 -- No error, but one more warning to consider. The RM (surprisingly)
12314 -- allows this pattern:
12317 -- primitive operations for S
12318 -- type R is new S;
12319 -- rep clause for S
12321 -- Meaning that calls on the primitive operations of S for values of
12322 -- type R may require possibly expensive implicit conversion operations.
12323 -- This is not an error, but is worth a warning.
12325 if not Relaxed_RM_Semantics
and then Is_Type
(T
) then
12327 DTL
: constant Entity_Id
:= Derived_Type_Link
(Base_Type
(T
));
12331 and then Has_Primitive_Operations
(Base_Type
(T
))
12333 -- For now, do not generate this warning for the case of aspect
12334 -- specification using Ada 2012 syntax, since we get wrong
12335 -- messages we do not understand. The whole business of derived
12336 -- types and rep items seems a bit confused when aspects are
12337 -- used, since the aspects are not evaluated till freeze time.
12339 and then not From_Aspect_Specification
(N
)
12341 Error_Msg_Sloc
:= Sloc
(DTL
);
12343 ("representation item for& appears after derived type "
12344 & "declaration#??", N
);
12346 ("\may result in implicit conversions for primitive "
12347 & "operations of&??", N
, T
);
12349 ("\to change representations when called with arguments "
12350 & "of type&??", N
, DTL
);
12355 -- No error, link item into head of chain of rep items for the entity,
12356 -- but avoid chaining if we have an overloadable entity, and the pragma
12357 -- is one that can apply to multiple overloaded entities.
12359 if Is_Overloadable
(T
) and then Nkind
(N
) = N_Pragma
then
12361 Pname
: constant Name_Id
:= Pragma_Name
(N
);
12363 if Nam_In
(Pname
, Name_Convention
, Name_Import
, Name_Export
,
12364 Name_External
, Name_Interface
)
12371 Record_Rep_Item
(T
, N
);
12373 end Rep_Item_Too_Late
;
12375 -------------------------------------
12376 -- Replace_Type_References_Generic --
12377 -------------------------------------
12379 procedure Replace_Type_References_Generic
(N
: Node_Id
; T
: Entity_Id
) is
12380 TName
: constant Name_Id
:= Chars
(T
);
12382 function Replace_Node
(N
: Node_Id
) return Traverse_Result
;
12383 -- Processes a single node in the traversal procedure below, checking
12384 -- if node N should be replaced, and if so, doing the replacement.
12386 procedure Replace_Type_Refs
is new Traverse_Proc
(Replace_Node
);
12387 -- This instantiation provides the body of Replace_Type_References
12393 function Replace_Node
(N
: Node_Id
) return Traverse_Result
is
12398 -- Case of identifier
12400 if Nkind
(N
) = N_Identifier
then
12402 -- If not the type name, check whether it is a reference to
12403 -- some other type, which must be frozen before the predicate
12404 -- function is analyzed, i.e. before the freeze node of the
12405 -- type to which the predicate applies.
12407 if Chars
(N
) /= TName
then
12408 if Present
(Current_Entity
(N
))
12409 and then Is_Type
(Current_Entity
(N
))
12411 Freeze_Before
(Freeze_Node
(T
), Current_Entity
(N
));
12416 -- Otherwise do the replacement and we are done with this node
12419 Replace_Type_Reference
(N
);
12423 -- Case of selected component (which is what a qualification
12424 -- looks like in the unanalyzed tree, which is what we have.
12426 elsif Nkind
(N
) = N_Selected_Component
then
12428 -- If selector name is not our type, keeping going (we might
12429 -- still have an occurrence of the type in the prefix).
12431 if Nkind
(Selector_Name
(N
)) /= N_Identifier
12432 or else Chars
(Selector_Name
(N
)) /= TName
12436 -- Selector name is our type, check qualification
12439 -- Loop through scopes and prefixes, doing comparison
12441 S
:= Current_Scope
;
12444 -- Continue if no more scopes or scope with no name
12446 if No
(S
) or else Nkind
(S
) not in N_Has_Chars
then
12450 -- Do replace if prefix is an identifier matching the
12451 -- scope that we are currently looking at.
12453 if Nkind
(P
) = N_Identifier
12454 and then Chars
(P
) = Chars
(S
)
12456 Replace_Type_Reference
(N
);
12460 -- Go check scope above us if prefix is itself of the
12461 -- form of a selected component, whose selector matches
12462 -- the scope we are currently looking at.
12464 if Nkind
(P
) = N_Selected_Component
12465 and then Nkind
(Selector_Name
(P
)) = N_Identifier
12466 and then Chars
(Selector_Name
(P
)) = Chars
(S
)
12471 -- For anything else, we don't have a match, so keep on
12472 -- going, there are still some weird cases where we may
12473 -- still have a replacement within the prefix.
12481 -- Continue for any other node kind
12489 Replace_Type_Refs
(N
);
12490 end Replace_Type_References_Generic
;
12492 --------------------------------
12493 -- Resolve_Aspect_Expressions --
12494 --------------------------------
12496 procedure Resolve_Aspect_Expressions
(E
: Entity_Id
) is
12502 ASN
:= First_Rep_Item
(E
);
12503 while Present
(ASN
) loop
12504 if Nkind
(ASN
) = N_Aspect_Specification
and then Entity
(ASN
) = E
then
12505 A_Id
:= Get_Aspect_Id
(ASN
);
12506 Expr
:= Expression
(ASN
);
12509 -- For now we only deal with aspects that do not generate
12510 -- subprograms, or that may mention current instances of
12511 -- types. These will require special handling (???TBD).
12513 when Aspect_Predicate |
12514 Aspect_Predicate_Failure |
12516 Aspect_Static_Predicate |
12517 Aspect_Dynamic_Predicate
=>
12520 when Pre_Post_Aspects
=>
12523 when Aspect_Iterable
=>
12524 if Nkind
(Expr
) = N_Aggregate
then
12529 Assoc
:= First
(Component_Associations
(Expr
));
12530 while Present
(Assoc
) loop
12531 Find_Direct_Name
(Expression
(Assoc
));
12538 if Present
(Expr
) then
12539 case Aspect_Argument
(A_Id
) is
12540 when Expression | Optional_Expression
=>
12541 Analyze_And_Resolve
(Expression
(ASN
));
12543 when Name | Optional_Name
=>
12544 if Nkind
(Expr
) = N_Identifier
then
12545 Find_Direct_Name
(Expr
);
12547 elsif Nkind
(Expr
) = N_Selected_Component
then
12548 Find_Selected_Component
(Expr
);
12558 ASN
:= Next_Rep_Item
(ASN
);
12560 end Resolve_Aspect_Expressions
;
12562 -------------------------
12563 -- Same_Representation --
12564 -------------------------
12566 function Same_Representation
(Typ1
, Typ2
: Entity_Id
) return Boolean is
12567 T1
: constant Entity_Id
:= Underlying_Type
(Typ1
);
12568 T2
: constant Entity_Id
:= Underlying_Type
(Typ2
);
12571 -- A quick check, if base types are the same, then we definitely have
12572 -- the same representation, because the subtype specific representation
12573 -- attributes (Size and Alignment) do not affect representation from
12574 -- the point of view of this test.
12576 if Base_Type
(T1
) = Base_Type
(T2
) then
12579 elsif Is_Private_Type
(Base_Type
(T2
))
12580 and then Base_Type
(T1
) = Full_View
(Base_Type
(T2
))
12585 -- Tagged types never have differing representations
12587 if Is_Tagged_Type
(T1
) then
12591 -- Representations are definitely different if conventions differ
12593 if Convention
(T1
) /= Convention
(T2
) then
12597 -- Representations are different if component alignments or scalar
12598 -- storage orders differ.
12600 if (Is_Record_Type
(T1
) or else Is_Array_Type
(T1
))
12602 (Is_Record_Type
(T2
) or else Is_Array_Type
(T2
))
12604 (Component_Alignment
(T1
) /= Component_Alignment
(T2
)
12605 or else Reverse_Storage_Order
(T1
) /= Reverse_Storage_Order
(T2
))
12610 -- For arrays, the only real issue is component size. If we know the
12611 -- component size for both arrays, and it is the same, then that's
12612 -- good enough to know we don't have a change of representation.
12614 if Is_Array_Type
(T1
) then
12615 if Known_Component_Size
(T1
)
12616 and then Known_Component_Size
(T2
)
12617 and then Component_Size
(T1
) = Component_Size
(T2
)
12623 -- Types definitely have same representation if neither has non-standard
12624 -- representation since default representations are always consistent.
12625 -- If only one has non-standard representation, and the other does not,
12626 -- then we consider that they do not have the same representation. They
12627 -- might, but there is no way of telling early enough.
12629 if Has_Non_Standard_Rep
(T1
) then
12630 if not Has_Non_Standard_Rep
(T2
) then
12634 return not Has_Non_Standard_Rep
(T2
);
12637 -- Here the two types both have non-standard representation, and we need
12638 -- to determine if they have the same non-standard representation.
12640 -- For arrays, we simply need to test if the component sizes are the
12641 -- same. Pragma Pack is reflected in modified component sizes, so this
12642 -- check also deals with pragma Pack.
12644 if Is_Array_Type
(T1
) then
12645 return Component_Size
(T1
) = Component_Size
(T2
);
12647 -- Tagged types always have the same representation, because it is not
12648 -- possible to specify different representations for common fields.
12650 elsif Is_Tagged_Type
(T1
) then
12653 -- Case of record types
12655 elsif Is_Record_Type
(T1
) then
12657 -- Packed status must conform
12659 if Is_Packed
(T1
) /= Is_Packed
(T2
) then
12662 -- Otherwise we must check components. Typ2 maybe a constrained
12663 -- subtype with fewer components, so we compare the components
12664 -- of the base types.
12667 Record_Case
: declare
12668 CD1
, CD2
: Entity_Id
;
12670 function Same_Rep
return Boolean;
12671 -- CD1 and CD2 are either components or discriminants. This
12672 -- function tests whether they have the same representation.
12678 function Same_Rep
return Boolean is
12680 if No
(Component_Clause
(CD1
)) then
12681 return No
(Component_Clause
(CD2
));
12683 -- Note: at this point, component clauses have been
12684 -- normalized to the default bit order, so that the
12685 -- comparison of Component_Bit_Offsets is meaningful.
12688 Present
(Component_Clause
(CD2
))
12690 Component_Bit_Offset
(CD1
) = Component_Bit_Offset
(CD2
)
12692 Esize
(CD1
) = Esize
(CD2
);
12696 -- Start of processing for Record_Case
12699 if Has_Discriminants
(T1
) then
12701 -- The number of discriminants may be different if the
12702 -- derived type has fewer (constrained by values). The
12703 -- invisible discriminants retain the representation of
12704 -- the original, so the discrepancy does not per se
12705 -- indicate a different representation.
12707 CD1
:= First_Discriminant
(T1
);
12708 CD2
:= First_Discriminant
(T2
);
12709 while Present
(CD1
) and then Present
(CD2
) loop
12710 if not Same_Rep
then
12713 Next_Discriminant
(CD1
);
12714 Next_Discriminant
(CD2
);
12719 CD1
:= First_Component
(Underlying_Type
(Base_Type
(T1
)));
12720 CD2
:= First_Component
(Underlying_Type
(Base_Type
(T2
)));
12721 while Present
(CD1
) loop
12722 if not Same_Rep
then
12725 Next_Component
(CD1
);
12726 Next_Component
(CD2
);
12734 -- For enumeration types, we must check each literal to see if the
12735 -- representation is the same. Note that we do not permit enumeration
12736 -- representation clauses for Character and Wide_Character, so these
12737 -- cases were already dealt with.
12739 elsif Is_Enumeration_Type
(T1
) then
12740 Enumeration_Case
: declare
12741 L1
, L2
: Entity_Id
;
12744 L1
:= First_Literal
(T1
);
12745 L2
:= First_Literal
(T2
);
12746 while Present
(L1
) loop
12747 if Enumeration_Rep
(L1
) /= Enumeration_Rep
(L2
) then
12756 end Enumeration_Case
;
12758 -- Any other types have the same representation for these purposes
12763 end Same_Representation
;
12765 --------------------------------
12766 -- Resolve_Iterable_Operation --
12767 --------------------------------
12769 procedure Resolve_Iterable_Operation
12771 Cursor
: Entity_Id
;
12780 if not Is_Overloaded
(N
) then
12781 if not Is_Entity_Name
(N
)
12782 or else Ekind
(Entity
(N
)) /= E_Function
12783 or else Scope
(Entity
(N
)) /= Scope
(Typ
)
12784 or else No
(First_Formal
(Entity
(N
)))
12785 or else Etype
(First_Formal
(Entity
(N
))) /= Typ
12787 Error_Msg_N
("iterable primitive must be local function name "
12788 & "whose first formal is an iterable type", N
);
12793 F1
:= First_Formal
(Ent
);
12794 if Nam
= Name_First
then
12796 -- First (Container) => Cursor
12798 if Etype
(Ent
) /= Cursor
then
12799 Error_Msg_N
("primitive for First must yield a curosr", N
);
12802 elsif Nam
= Name_Next
then
12804 -- Next (Container, Cursor) => Cursor
12806 F2
:= Next_Formal
(F1
);
12808 if Etype
(F2
) /= Cursor
12809 or else Etype
(Ent
) /= Cursor
12810 or else Present
(Next_Formal
(F2
))
12812 Error_Msg_N
("no match for Next iterable primitive", N
);
12815 elsif Nam
= Name_Has_Element
then
12817 -- Has_Element (Container, Cursor) => Boolean
12819 F2
:= Next_Formal
(F1
);
12820 if Etype
(F2
) /= Cursor
12821 or else Etype
(Ent
) /= Standard_Boolean
12822 or else Present
(Next_Formal
(F2
))
12824 Error_Msg_N
("no match for Has_Element iterable primitive", N
);
12827 elsif Nam
= Name_Element
then
12828 F2
:= Next_Formal
(F1
);
12831 or else Etype
(F2
) /= Cursor
12832 or else Present
(Next_Formal
(F2
))
12834 Error_Msg_N
("no match for Element iterable primitive", N
);
12839 raise Program_Error
;
12843 -- Overloaded case: find subprogram with proper signature.
12844 -- Caller will report error if no match is found.
12851 Get_First_Interp
(N
, I
, It
);
12852 while Present
(It
.Typ
) loop
12853 if Ekind
(It
.Nam
) = E_Function
12854 and then Scope
(It
.Nam
) = Scope
(Typ
)
12855 and then Etype
(First_Formal
(It
.Nam
)) = Typ
12857 F1
:= First_Formal
(It
.Nam
);
12859 if Nam
= Name_First
then
12860 if Etype
(It
.Nam
) = Cursor
12861 and then No
(Next_Formal
(F1
))
12863 Set_Entity
(N
, It
.Nam
);
12867 elsif Nam
= Name_Next
then
12868 F2
:= Next_Formal
(F1
);
12871 and then No
(Next_Formal
(F2
))
12872 and then Etype
(F2
) = Cursor
12873 and then Etype
(It
.Nam
) = Cursor
12875 Set_Entity
(N
, It
.Nam
);
12879 elsif Nam
= Name_Has_Element
then
12880 F2
:= Next_Formal
(F1
);
12883 and then No
(Next_Formal
(F2
))
12884 and then Etype
(F2
) = Cursor
12885 and then Etype
(It
.Nam
) = Standard_Boolean
12887 Set_Entity
(N
, It
.Nam
);
12888 F2
:= Next_Formal
(F1
);
12892 elsif Nam
= Name_Element
then
12893 F2
:= Next_Formal
(F1
);
12896 and then No
(Next_Formal
(F2
))
12897 and then Etype
(F2
) = Cursor
12899 Set_Entity
(N
, It
.Nam
);
12905 Get_Next_Interp
(I
, It
);
12909 end Resolve_Iterable_Operation
;
12915 procedure Set_Biased
12919 Biased
: Boolean := True)
12923 Set_Has_Biased_Representation
(E
);
12925 if Warn_On_Biased_Representation
then
12927 ("?B?" & Msg
& " forces biased representation for&", N
, E
);
12932 --------------------
12933 -- Set_Enum_Esize --
12934 --------------------
12936 procedure Set_Enum_Esize
(T
: Entity_Id
) is
12942 Init_Alignment
(T
);
12944 -- Find the minimum standard size (8,16,32,64) that fits
12946 Lo
:= Enumeration_Rep
(Entity
(Type_Low_Bound
(T
)));
12947 Hi
:= Enumeration_Rep
(Entity
(Type_High_Bound
(T
)));
12950 if Lo
>= -Uint_2
**07 and then Hi
< Uint_2
**07 then
12951 Sz
:= Standard_Character_Size
; -- May be > 8 on some targets
12953 elsif Lo
>= -Uint_2
**15 and then Hi
< Uint_2
**15 then
12956 elsif Lo
>= -Uint_2
**31 and then Hi
< Uint_2
**31 then
12959 else pragma Assert
(Lo
>= -Uint_2
**63 and then Hi
< Uint_2
**63);
12964 if Hi
< Uint_2
**08 then
12965 Sz
:= Standard_Character_Size
; -- May be > 8 on some targets
12967 elsif Hi
< Uint_2
**16 then
12970 elsif Hi
< Uint_2
**32 then
12973 else pragma Assert
(Hi
< Uint_2
**63);
12978 -- That minimum is the proper size unless we have a foreign convention
12979 -- and the size required is 32 or less, in which case we bump the size
12980 -- up to 32. This is required for C and C++ and seems reasonable for
12981 -- all other foreign conventions.
12983 if Has_Foreign_Convention
(T
)
12984 and then Esize
(T
) < Standard_Integer_Size
12986 -- Don't do this if Short_Enums on target
12988 and then not Target_Short_Enums
12990 Init_Esize
(T
, Standard_Integer_Size
);
12992 Init_Esize
(T
, Sz
);
12994 end Set_Enum_Esize
;
12996 -----------------------------
12997 -- Uninstall_Discriminants --
12998 -----------------------------
13000 procedure Uninstall_Discriminants
(E
: Entity_Id
) is
13006 -- Discriminants have been made visible for type declarations and
13007 -- protected type declarations, not for subtype declarations.
13009 if Nkind
(Parent
(E
)) /= N_Subtype_Declaration
then
13010 Disc
:= First_Discriminant
(E
);
13011 while Present
(Disc
) loop
13012 if Disc
/= Current_Entity
(Disc
) then
13013 Prev
:= Current_Entity
(Disc
);
13014 while Present
(Prev
)
13015 and then Present
(Homonym
(Prev
))
13016 and then Homonym
(Prev
) /= Disc
13018 Prev
:= Homonym
(Prev
);
13024 Set_Is_Immediately_Visible
(Disc
, False);
13026 Outer
:= Homonym
(Disc
);
13027 while Present
(Outer
) and then Scope
(Outer
) = E
loop
13028 Outer
:= Homonym
(Outer
);
13031 -- Reset homonym link of other entities, but do not modify link
13032 -- between entities in current scope, so that the back end can
13033 -- have a proper count of local overloadings.
13036 Set_Name_Entity_Id
(Chars
(Disc
), Outer
);
13038 elsif Scope
(Prev
) /= Scope
(Disc
) then
13039 Set_Homonym
(Prev
, Outer
);
13042 Next_Discriminant
(Disc
);
13045 end Uninstall_Discriminants
;
13047 -------------------------------------------
13048 -- Uninstall_Discriminants_And_Pop_Scope --
13049 -------------------------------------------
13051 procedure Uninstall_Discriminants_And_Pop_Scope
(E
: Entity_Id
) is
13053 if Has_Discriminants
(E
) then
13054 Uninstall_Discriminants
(E
);
13057 end Uninstall_Discriminants_And_Pop_Scope
;
13059 ------------------------------
13060 -- Validate_Address_Clauses --
13061 ------------------------------
13063 procedure Validate_Address_Clauses
is
13065 for J
in Address_Clause_Checks
.First
.. Address_Clause_Checks
.Last
loop
13067 ACCR
: Address_Clause_Check_Record
13068 renames Address_Clause_Checks
.Table
(J
);
13072 X_Alignment
: Uint
;
13073 Y_Alignment
: Uint
;
13079 -- Skip processing of this entry if warning already posted
13081 if not Address_Warning_Posted
(ACCR
.N
) then
13082 Expr
:= Original_Node
(Expression
(ACCR
.N
));
13086 X_Alignment
:= Alignment
(ACCR
.X
);
13087 Y_Alignment
:= Alignment
(ACCR
.Y
);
13089 -- Similarly obtain sizes
13091 X_Size
:= Esize
(ACCR
.X
);
13092 Y_Size
:= Esize
(ACCR
.Y
);
13094 -- Check for large object overlaying smaller one
13097 and then X_Size
> Uint_0
13098 and then X_Size
> Y_Size
13100 Error_Msg_NE
("??& overlays smaller object", ACCR
.N
, ACCR
.X
);
13102 ("\??program execution may be erroneous", ACCR
.N
);
13104 Error_Msg_Uint_1
:= X_Size
;
13105 Error_Msg_NE
("\??size of & is ^", ACCR
.N
, ACCR
.X
);
13107 Error_Msg_Uint_1
:= Y_Size
;
13108 Error_Msg_NE
("\??size of & is ^", ACCR
.N
, ACCR
.Y
);
13110 -- Check for inadequate alignment, both of the base object
13111 -- and of the offset, if any. We only do this check if the
13112 -- run-time Alignment_Check is active. No point in warning
13113 -- if this check has been suppressed (or is suppressed by
13114 -- default in the non-strict alignment machine case).
13116 -- Note: we do not check the alignment if we gave a size
13117 -- warning, since it would likely be redundant.
13119 elsif not Alignment_Checks_Suppressed
(ACCR
.Y
)
13120 and then Y_Alignment
/= Uint_0
13122 (Y_Alignment
< X_Alignment
13125 and then Nkind
(Expr
) = N_Attribute_Reference
13126 and then Attribute_Name
(Expr
) = Name_Address
13127 and then Has_Compatible_Alignment
13128 (ACCR
.X
, Prefix
(Expr
), True) /=
13132 ("??specified address for& may be inconsistent with "
13133 & "alignment", ACCR
.N
, ACCR
.X
);
13135 ("\??program execution may be erroneous (RM 13.3(27))",
13138 Error_Msg_Uint_1
:= X_Alignment
;
13139 Error_Msg_NE
("\??alignment of & is ^", ACCR
.N
, ACCR
.X
);
13141 Error_Msg_Uint_1
:= Y_Alignment
;
13142 Error_Msg_NE
("\??alignment of & is ^", ACCR
.N
, ACCR
.Y
);
13144 if Y_Alignment
>= X_Alignment
then
13146 ("\??but offset is not multiple of alignment", ACCR
.N
);
13152 end Validate_Address_Clauses
;
13154 ---------------------------
13155 -- Validate_Independence --
13156 ---------------------------
13158 procedure Validate_Independence
is
13159 SU
: constant Uint
:= UI_From_Int
(System_Storage_Unit
);
13167 procedure Check_Array_Type
(Atyp
: Entity_Id
);
13168 -- Checks if the array type Atyp has independent components, and
13169 -- if not, outputs an appropriate set of error messages.
13171 procedure No_Independence
;
13172 -- Output message that independence cannot be guaranteed
13174 function OK_Component
(C
: Entity_Id
) return Boolean;
13175 -- Checks one component to see if it is independently accessible, and
13176 -- if so yields True, otherwise yields False if independent access
13177 -- cannot be guaranteed. This is a conservative routine, it only
13178 -- returns True if it knows for sure, it returns False if it knows
13179 -- there is a problem, or it cannot be sure there is no problem.
13181 procedure Reason_Bad_Component
(C
: Entity_Id
);
13182 -- Outputs continuation message if a reason can be determined for
13183 -- the component C being bad.
13185 ----------------------
13186 -- Check_Array_Type --
13187 ----------------------
13189 procedure Check_Array_Type
(Atyp
: Entity_Id
) is
13190 Ctyp
: constant Entity_Id
:= Component_Type
(Atyp
);
13193 -- OK if no alignment clause, no pack, and no component size
13195 if not Has_Component_Size_Clause
(Atyp
)
13196 and then not Has_Alignment_Clause
(Atyp
)
13197 and then not Is_Packed
(Atyp
)
13202 -- Case of component size is greater than or equal to 64 and the
13203 -- alignment of the array is at least as large as the alignment
13204 -- of the component. We are definitely OK in this situation.
13206 if Known_Component_Size
(Atyp
)
13207 and then Component_Size
(Atyp
) >= 64
13208 and then Known_Alignment
(Atyp
)
13209 and then Known_Alignment
(Ctyp
)
13210 and then Alignment
(Atyp
) >= Alignment
(Ctyp
)
13215 -- Check actual component size
13217 if not Known_Component_Size
(Atyp
)
13218 or else not (Addressable
(Component_Size
(Atyp
))
13219 and then Component_Size
(Atyp
) < 64)
13220 or else Component_Size
(Atyp
) mod Esize
(Ctyp
) /= 0
13224 -- Bad component size, check reason
13226 if Has_Component_Size_Clause
(Atyp
) then
13227 P
:= Get_Attribute_Definition_Clause
13228 (Atyp
, Attribute_Component_Size
);
13230 if Present
(P
) then
13231 Error_Msg_Sloc
:= Sloc
(P
);
13232 Error_Msg_N
("\because of Component_Size clause#", N
);
13237 if Is_Packed
(Atyp
) then
13238 P
:= Get_Rep_Pragma
(Atyp
, Name_Pack
);
13240 if Present
(P
) then
13241 Error_Msg_Sloc
:= Sloc
(P
);
13242 Error_Msg_N
("\because of pragma Pack#", N
);
13247 -- No reason found, just return
13252 -- Array type is OK independence-wise
13255 end Check_Array_Type
;
13257 ---------------------
13258 -- No_Independence --
13259 ---------------------
13261 procedure No_Independence
is
13263 if Pragma_Name
(N
) = Name_Independent
then
13264 Error_Msg_NE
("independence cannot be guaranteed for&", N
, E
);
13267 ("independent components cannot be guaranteed for&", N
, E
);
13269 end No_Independence
;
13275 function OK_Component
(C
: Entity_Id
) return Boolean is
13276 Rec
: constant Entity_Id
:= Scope
(C
);
13277 Ctyp
: constant Entity_Id
:= Etype
(C
);
13280 -- OK if no component clause, no Pack, and no alignment clause
13282 if No
(Component_Clause
(C
))
13283 and then not Is_Packed
(Rec
)
13284 and then not Has_Alignment_Clause
(Rec
)
13289 -- Here we look at the actual component layout. A component is
13290 -- addressable if its size is a multiple of the Esize of the
13291 -- component type, and its starting position in the record has
13292 -- appropriate alignment, and the record itself has appropriate
13293 -- alignment to guarantee the component alignment.
13295 -- Make sure sizes are static, always assume the worst for any
13296 -- cases where we cannot check static values.
13298 if not (Known_Static_Esize
(C
)
13300 Known_Static_Esize
(Ctyp
))
13305 -- Size of component must be addressable or greater than 64 bits
13306 -- and a multiple of bytes.
13308 if not Addressable
(Esize
(C
)) and then Esize
(C
) < Uint_64
then
13312 -- Check size is proper multiple
13314 if Esize
(C
) mod Esize
(Ctyp
) /= 0 then
13318 -- Check alignment of component is OK
13320 if not Known_Component_Bit_Offset
(C
)
13321 or else Component_Bit_Offset
(C
) < Uint_0
13322 or else Component_Bit_Offset
(C
) mod Esize
(Ctyp
) /= 0
13327 -- Check alignment of record type is OK
13329 if not Known_Alignment
(Rec
)
13330 or else (Alignment
(Rec
) * SU
) mod Esize
(Ctyp
) /= 0
13335 -- All tests passed, component is addressable
13340 --------------------------
13341 -- Reason_Bad_Component --
13342 --------------------------
13344 procedure Reason_Bad_Component
(C
: Entity_Id
) is
13345 Rec
: constant Entity_Id
:= Scope
(C
);
13346 Ctyp
: constant Entity_Id
:= Etype
(C
);
13349 -- If component clause present assume that's the problem
13351 if Present
(Component_Clause
(C
)) then
13352 Error_Msg_Sloc
:= Sloc
(Component_Clause
(C
));
13353 Error_Msg_N
("\because of Component_Clause#", N
);
13357 -- If pragma Pack clause present, assume that's the problem
13359 if Is_Packed
(Rec
) then
13360 P
:= Get_Rep_Pragma
(Rec
, Name_Pack
);
13362 if Present
(P
) then
13363 Error_Msg_Sloc
:= Sloc
(P
);
13364 Error_Msg_N
("\because of pragma Pack#", N
);
13369 -- See if record has bad alignment clause
13371 if Has_Alignment_Clause
(Rec
)
13372 and then Known_Alignment
(Rec
)
13373 and then (Alignment
(Rec
) * SU
) mod Esize
(Ctyp
) /= 0
13375 P
:= Get_Attribute_Definition_Clause
(Rec
, Attribute_Alignment
);
13377 if Present
(P
) then
13378 Error_Msg_Sloc
:= Sloc
(P
);
13379 Error_Msg_N
("\because of Alignment clause#", N
);
13383 -- Couldn't find a reason, so return without a message
13386 end Reason_Bad_Component
;
13388 -- Start of processing for Validate_Independence
13391 for J
in Independence_Checks
.First
.. Independence_Checks
.Last
loop
13392 N
:= Independence_Checks
.Table
(J
).N
;
13393 E
:= Independence_Checks
.Table
(J
).E
;
13394 IC
:= Pragma_Name
(N
) = Name_Independent_Components
;
13396 -- Deal with component case
13398 if Ekind
(E
) = E_Discriminant
or else Ekind
(E
) = E_Component
then
13399 if not OK_Component
(E
) then
13401 Reason_Bad_Component
(E
);
13406 -- Deal with record with Independent_Components
13408 if IC
and then Is_Record_Type
(E
) then
13409 Comp
:= First_Component_Or_Discriminant
(E
);
13410 while Present
(Comp
) loop
13411 if not OK_Component
(Comp
) then
13413 Reason_Bad_Component
(Comp
);
13417 Next_Component_Or_Discriminant
(Comp
);
13421 -- Deal with address clause case
13423 if Is_Object
(E
) then
13424 Addr
:= Address_Clause
(E
);
13426 if Present
(Addr
) then
13428 Error_Msg_Sloc
:= Sloc
(Addr
);
13429 Error_Msg_N
("\because of Address clause#", N
);
13434 -- Deal with independent components for array type
13436 if IC
and then Is_Array_Type
(E
) then
13437 Check_Array_Type
(E
);
13440 -- Deal with independent components for array object
13442 if IC
and then Is_Object
(E
) and then Is_Array_Type
(Etype
(E
)) then
13443 Check_Array_Type
(Etype
(E
));
13448 end Validate_Independence
;
13450 ------------------------------
13451 -- Validate_Iterable_Aspect --
13452 ------------------------------
13454 procedure Validate_Iterable_Aspect
(Typ
: Entity_Id
; ASN
: Node_Id
) is
13459 Cursor
: constant Entity_Id
:= Get_Cursor_Type
(ASN
, Typ
);
13461 First_Id
: Entity_Id
;
13462 Next_Id
: Entity_Id
;
13463 Has_Element_Id
: Entity_Id
;
13464 Element_Id
: Entity_Id
;
13467 -- If previous error aspect is unusable
13469 if Cursor
= Any_Type
then
13475 Has_Element_Id
:= Empty
;
13476 Element_Id
:= Empty
;
13478 -- Each expression must resolve to a function with the proper signature
13480 Assoc
:= First
(Component_Associations
(Expression
(ASN
)));
13481 while Present
(Assoc
) loop
13482 Expr
:= Expression
(Assoc
);
13485 Prim
:= First
(Choices
(Assoc
));
13487 if Nkind
(Prim
) /= N_Identifier
or else Present
(Next
(Prim
)) then
13488 Error_Msg_N
("illegal name in association", Prim
);
13490 elsif Chars
(Prim
) = Name_First
then
13491 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_First
);
13492 First_Id
:= Entity
(Expr
);
13494 elsif Chars
(Prim
) = Name_Next
then
13495 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_Next
);
13496 Next_Id
:= Entity
(Expr
);
13498 elsif Chars
(Prim
) = Name_Has_Element
then
13499 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_Has_Element
);
13500 Has_Element_Id
:= Entity
(Expr
);
13502 elsif Chars
(Prim
) = Name_Element
then
13503 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_Element
);
13504 Element_Id
:= Entity
(Expr
);
13507 Error_Msg_N
("invalid name for iterable function", Prim
);
13513 if No
(First_Id
) then
13514 Error_Msg_N
("match for First primitive not found", ASN
);
13516 elsif No
(Next_Id
) then
13517 Error_Msg_N
("match for Next primitive not found", ASN
);
13519 elsif No
(Has_Element_Id
) then
13520 Error_Msg_N
("match for Has_Element primitive not found", ASN
);
13522 elsif No
(Element_Id
) then
13525 end Validate_Iterable_Aspect
;
13527 -----------------------------------
13528 -- Validate_Unchecked_Conversion --
13529 -----------------------------------
13531 procedure Validate_Unchecked_Conversion
13533 Act_Unit
: Entity_Id
)
13535 Source
: Entity_Id
;
13536 Target
: Entity_Id
;
13540 -- Obtain source and target types. Note that we call Ancestor_Subtype
13541 -- here because the processing for generic instantiation always makes
13542 -- subtypes, and we want the original frozen actual types.
13544 -- If we are dealing with private types, then do the check on their
13545 -- fully declared counterparts if the full declarations have been
13546 -- encountered (they don't have to be visible, but they must exist).
13548 Source
:= Ancestor_Subtype
(Etype
(First_Formal
(Act_Unit
)));
13550 if Is_Private_Type
(Source
)
13551 and then Present
(Underlying_Type
(Source
))
13553 Source
:= Underlying_Type
(Source
);
13556 Target
:= Ancestor_Subtype
(Etype
(Act_Unit
));
13558 -- If either type is generic, the instantiation happens within a generic
13559 -- unit, and there is nothing to check. The proper check will happen
13560 -- when the enclosing generic is instantiated.
13562 if Is_Generic_Type
(Source
) or else Is_Generic_Type
(Target
) then
13566 if Is_Private_Type
(Target
)
13567 and then Present
(Underlying_Type
(Target
))
13569 Target
:= Underlying_Type
(Target
);
13572 -- Source may be unconstrained array, but not target, except in relaxed
13575 if Is_Array_Type
(Target
)
13576 and then not Is_Constrained
(Target
)
13577 and then not Relaxed_RM_Semantics
13580 ("unchecked conversion to unconstrained array not allowed", N
);
13584 -- Warn if conversion between two different convention pointers
13586 if Is_Access_Type
(Target
)
13587 and then Is_Access_Type
(Source
)
13588 and then Convention
(Target
) /= Convention
(Source
)
13589 and then Warn_On_Unchecked_Conversion
13591 -- Give warnings for subprogram pointers only on most targets
13593 if Is_Access_Subprogram_Type
(Target
)
13594 or else Is_Access_Subprogram_Type
(Source
)
13597 ("?z?conversion between pointers with different conventions!",
13602 -- Warn if one of the operands is Ada.Calendar.Time. Do not emit a
13603 -- warning when compiling GNAT-related sources.
13605 if Warn_On_Unchecked_Conversion
13606 and then not In_Predefined_Unit
(N
)
13607 and then RTU_Loaded
(Ada_Calendar
)
13608 and then (Chars
(Source
) = Name_Time
13610 Chars
(Target
) = Name_Time
)
13612 -- If Ada.Calendar is loaded and the name of one of the operands is
13613 -- Time, there is a good chance that this is Ada.Calendar.Time.
13616 Calendar_Time
: constant Entity_Id
:= Full_View
(RTE
(RO_CA_Time
));
13618 pragma Assert
(Present
(Calendar_Time
));
13620 if Source
= Calendar_Time
or else Target
= Calendar_Time
then
13622 ("?z?representation of 'Time values may change between "
13623 & "'G'N'A'T versions", N
);
13628 -- Make entry in unchecked conversion table for later processing by
13629 -- Validate_Unchecked_Conversions, which will check sizes and alignments
13630 -- (using values set by the back end where possible). This is only done
13631 -- if the appropriate warning is active.
13633 if Warn_On_Unchecked_Conversion
then
13634 Unchecked_Conversions
.Append
13635 (New_Val
=> UC_Entry
'(Eloc => Sloc (N),
13638 Act_Unit => Act_Unit));
13640 -- If both sizes are known statically now, then back end annotation
13641 -- is not required to do a proper check but if either size is not
13642 -- known statically, then we need the annotation.
13644 if Known_Static_RM_Size (Source)
13646 Known_Static_RM_Size (Target)
13650 Back_Annotate_Rep_Info := True;
13654 -- If unchecked conversion to access type, and access type is declared
13655 -- in the same unit as the unchecked conversion, then set the flag
13656 -- No_Strict_Aliasing (no strict aliasing is implicit here)
13658 if Is_Access_Type (Target) and then
13659 In_Same_Source_Unit (Target, N)
13661 Set_No_Strict_Aliasing (Implementation_Base_Type (Target));
13664 -- Generate N_Validate_Unchecked_Conversion node for back end in case
13665 -- the back end needs to perform special validation checks.
13667 -- Shouldn't this be in Exp_Ch13, since the check only gets done if we
13668 -- have full expansion and the back end is called ???
13671 Make_Validate_Unchecked_Conversion (Sloc (N));
13672 Set_Source_Type (Vnode, Source);
13673 Set_Target_Type (Vnode, Target);
13675 -- If the unchecked conversion node is in a list, just insert before it.
13676 -- If not we have some strange case, not worth bothering about.
13678 if Is_List_Member (N) then
13679 Insert_After (N, Vnode);
13681 end Validate_Unchecked_Conversion;
13683 ------------------------------------
13684 -- Validate_Unchecked_Conversions --
13685 ------------------------------------
13687 procedure Validate_Unchecked_Conversions is
13689 for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop
13691 T : UC_Entry renames Unchecked_Conversions.Table (N);
13693 Eloc : constant Source_Ptr := T.Eloc;
13694 Source : constant Entity_Id := T.Source;
13695 Target : constant Entity_Id := T.Target;
13696 Act_Unit : constant Entity_Id := T.Act_Unit;
13702 -- Skip if function marked as warnings off
13704 if Warnings_Off (Act_Unit) then
13708 -- This validation check, which warns if we have unequal sizes for
13709 -- unchecked conversion, and thus potentially implementation
13710 -- dependent semantics, is one of the few occasions on which we
13711 -- use the official RM size instead of Esize. See description in
13712 -- Einfo "Handling of Type'Size Values" for details.
13714 if Serious_Errors_Detected = 0
13715 and then Known_Static_RM_Size (Source)
13716 and then Known_Static_RM_Size (Target)
13718 -- Don't do the check if warnings off for either type, note the
13719 -- deliberate use of OR here instead of OR ELSE to get the flag
13720 -- Warnings_Off_Used set for both types if appropriate.
13722 and then not (Has_Warnings_Off (Source)
13724 Has_Warnings_Off (Target))
13726 Source_Siz := RM_Size (Source);
13727 Target_Siz := RM_Size (Target);
13729 if Source_Siz /= Target_Siz then
13731 ("?z?types for unchecked conversion have different sizes!",
13734 if All_Errors_Mode then
13735 Error_Msg_Name_1 := Chars (Source);
13736 Error_Msg_Uint_1 := Source_Siz;
13737 Error_Msg_Name_2 := Chars (Target);
13738 Error_Msg_Uint_2 := Target_Siz;
13739 Error_Msg ("\size of % is ^, size of % is ^?z?", Eloc);
13741 Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz);
13743 if Is_Discrete_Type (Source)
13745 Is_Discrete_Type (Target)
13747 if Source_Siz > Target_Siz then
13749 ("\?z?^ high order bits of source will "
13750 & "be ignored!", Eloc);
13752 elsif Is_Unsigned_Type (Source) then
13754 ("\?z?source will be extended with ^ high order "
13755 & "zero bits!", Eloc);
13759 ("\?z?source will be extended with ^ high order "
13760 & "sign bits!", Eloc);
13763 elsif Source_Siz < Target_Siz then
13764 if Is_Discrete_Type (Target) then
13765 if Bytes_Big_Endian then
13767 ("\?z?target value will include ^ undefined "
13768 & "low order bits!", Eloc);
13771 ("\?z?target value will include ^ undefined "
13772 & "high order bits!", Eloc);
13777 ("\?z?^ trailing bits of target value will be "
13778 & "undefined!", Eloc);
13781 else pragma Assert (Source_Siz > Target_Siz);
13782 if Is_Discrete_Type (Source) then
13783 if Bytes_Big_Endian then
13785 ("\?z?^ low order bits of source will be "
13786 & "ignored!", Eloc);
13789 ("\?z?^ high order bits of source will be "
13790 & "ignored!", Eloc);
13795 ("\?z?^ trailing bits of source will be "
13796 & "ignored!", Eloc);
13803 -- If both types are access types, we need to check the alignment.
13804 -- If the alignment of both is specified, we can do it here.
13806 if Serious_Errors_Detected = 0
13807 and then Is_Access_Type (Source)
13808 and then Is_Access_Type (Target)
13809 and then Target_Strict_Alignment
13810 and then Present (Designated_Type (Source))
13811 and then Present (Designated_Type (Target))
13814 D_Source : constant Entity_Id := Designated_Type (Source);
13815 D_Target : constant Entity_Id := Designated_Type (Target);
13818 if Known_Alignment (D_Source)
13820 Known_Alignment (D_Target)
13823 Source_Align : constant Uint := Alignment (D_Source);
13824 Target_Align : constant Uint := Alignment (D_Target);
13827 if Source_Align < Target_Align
13828 and then not Is_Tagged_Type (D_Source)
13830 -- Suppress warning if warnings suppressed on either
13831 -- type or either designated type. Note the use of
13832 -- OR here instead of OR ELSE. That is intentional,
13833 -- we would like to set flag Warnings_Off_Used in
13834 -- all types for which warnings are suppressed.
13836 and then not (Has_Warnings_Off (D_Source)
13838 Has_Warnings_Off (D_Target)
13840 Has_Warnings_Off (Source)
13842 Has_Warnings_Off (Target))
13844 Error_Msg_Uint_1 := Target_Align;
13845 Error_Msg_Uint_2 := Source_Align;
13846 Error_Msg_Node_1 := D_Target;
13847 Error_Msg_Node_2 := D_Source;
13849 ("?z?alignment of & (^) is stricter than "
13850 & "alignment of & (^)!", Eloc);
13852 ("\?z?resulting access value may have invalid "
13853 & "alignment!", Eloc);
13864 end Validate_Unchecked_Conversions;