1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2012, 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 Einfo
; use Einfo
;
30 with Elists
; use Elists
;
31 with Errout
; use Errout
;
32 with Exp_Disp
; use Exp_Disp
;
33 with Exp_Tss
; use Exp_Tss
;
34 with Exp_Util
; use Exp_Util
;
36 with Lib
.Xref
; use Lib
.Xref
;
37 with Namet
; use Namet
;
38 with Nlists
; use Nlists
;
39 with Nmake
; use Nmake
;
41 with Restrict
; use Restrict
;
42 with Rident
; use Rident
;
43 with Rtsfind
; use Rtsfind
;
45 with Sem_Aux
; use Sem_Aux
;
46 with Sem_Ch3
; use Sem_Ch3
;
47 with Sem_Ch6
; use Sem_Ch6
;
48 with Sem_Ch8
; use Sem_Ch8
;
49 with Sem_Ch9
; use Sem_Ch9
;
50 with Sem_Dim
; use Sem_Dim
;
51 with Sem_Disp
; use Sem_Disp
;
52 with Sem_Eval
; use Sem_Eval
;
53 with Sem_Res
; use Sem_Res
;
54 with Sem_Type
; use Sem_Type
;
55 with Sem_Util
; use Sem_Util
;
56 with Sem_Warn
; use Sem_Warn
;
57 with Sinput
; use Sinput
;
58 with Snames
; use Snames
;
59 with Stand
; use Stand
;
60 with Sinfo
; use Sinfo
;
61 with Stringt
; use Stringt
;
62 with Targparm
; use Targparm
;
63 with Ttypes
; use Ttypes
;
64 with Tbuild
; use Tbuild
;
65 with Urealp
; use Urealp
;
66 with Warnsw
; use Warnsw
;
68 with GNAT
.Heap_Sort_G
;
70 package body Sem_Ch13
is
72 SSU
: constant Pos
:= System_Storage_Unit
;
73 -- Convenient short hand for commonly used constant
75 -----------------------
76 -- Local Subprograms --
77 -----------------------
79 procedure Alignment_Check_For_Size_Change
(Typ
: Entity_Id
; Size
: Uint
);
80 -- This routine is called after setting one of the sizes of type entity
81 -- Typ to Size. The purpose is to deal with the situation of a derived
82 -- type whose inherited alignment is no longer appropriate for the new
83 -- size value. In this case, we reset the Alignment to unknown.
85 procedure Build_Predicate_Function
(Typ
: Entity_Id
; N
: Node_Id
);
86 -- If Typ has predicates (indicated by Has_Predicates being set for Typ,
87 -- then either there are pragma Invariant entries on the rep chain for the
88 -- type (note that Predicate aspects are converted to pragma Predicate), or
89 -- there are inherited aspects from a parent type, or ancestor subtypes.
90 -- This procedure builds the spec and body for the Predicate function that
91 -- tests these predicates. N is the freeze node for the type. The spec of
92 -- the function is inserted before the freeze node, and the body of the
93 -- function is inserted after the freeze node.
95 procedure Build_Static_Predicate
99 -- Given a predicated type Typ, where Typ is a discrete static subtype,
100 -- whose predicate expression is Expr, tests if Expr is a static predicate,
101 -- and if so, builds the predicate range list. Nam is the name of the one
102 -- argument to the predicate function. Occurrences of the type name in the
103 -- predicate expression have been replaced by identifier references to this
104 -- name, which is unique, so any identifier with Chars matching Nam must be
105 -- a reference to the type. If the predicate is non-static, this procedure
106 -- returns doing nothing. If the predicate is static, then the predicate
107 -- list is stored in Static_Predicate (Typ), and the Expr is rewritten as
108 -- a canonicalized membership operation.
110 function Get_Alignment_Value
(Expr
: Node_Id
) return Uint
;
111 -- Given the expression for an alignment value, returns the corresponding
112 -- Uint value. If the value is inappropriate, then error messages are
113 -- posted as required, and a value of No_Uint is returned.
115 function Is_Operational_Item
(N
: Node_Id
) return Boolean;
116 -- A specification for a stream attribute is allowed before the full type
117 -- is declared, as explained in AI-00137 and the corrigendum. Attributes
118 -- that do not specify a representation characteristic are operational
121 procedure New_Stream_Subprogram
125 Nam
: TSS_Name_Type
);
126 -- Create a subprogram renaming of a given stream attribute to the
127 -- designated subprogram and then in the tagged case, provide this as a
128 -- primitive operation, or in the non-tagged case make an appropriate TSS
129 -- entry. This is more properly an expansion activity than just semantics,
130 -- but the presence of user-defined stream functions for limited types is a
131 -- legality check, which is why this takes place here rather than in
132 -- exp_ch13, where it was previously. Nam indicates the name of the TSS
133 -- function to be generated.
135 -- To avoid elaboration anomalies with freeze nodes, for untagged types
136 -- we generate both a subprogram declaration and a subprogram renaming
137 -- declaration, so that the attribute specification is handled as a
138 -- renaming_as_body. For tagged types, the specification is one of the
142 with procedure Replace_Type_Reference
(N
: Node_Id
);
143 procedure Replace_Type_References_Generic
(N
: Node_Id
; TName
: Name_Id
);
144 -- This is used to scan an expression for a predicate or invariant aspect
145 -- replacing occurrences of the name TName (the name of the subtype to
146 -- which the aspect applies) with appropriate references to the parameter
147 -- of the predicate function or invariant procedure. The procedure passed
148 -- as a generic parameter does the actual replacement of node N, which is
149 -- either a simple direct reference to TName, or a selected component that
150 -- represents an appropriately qualified occurrence of TName.
156 Biased
: Boolean := True);
157 -- If Biased is True, sets Has_Biased_Representation flag for E, and
158 -- outputs a warning message at node N if Warn_On_Biased_Representation is
159 -- is True. This warning inserts the string Msg to describe the construct
162 ----------------------------------------------
163 -- Table for Validate_Unchecked_Conversions --
164 ----------------------------------------------
166 -- The following table collects unchecked conversions for validation.
167 -- Entries are made by Validate_Unchecked_Conversion and then the call
168 -- to Validate_Unchecked_Conversions does the actual error checking and
169 -- posting of warnings. The reason for this delayed processing is to take
170 -- advantage of back-annotations of size and alignment values performed by
173 -- Note: the reason we store a Source_Ptr value instead of a Node_Id is
174 -- that by the time Validate_Unchecked_Conversions is called, Sprint will
175 -- already have modified all Sloc values if the -gnatD option is set.
177 type UC_Entry
is record
178 Eloc
: Source_Ptr
; -- node used for posting warnings
179 Source
: Entity_Id
; -- source type for unchecked conversion
180 Target
: Entity_Id
; -- target type for unchecked conversion
183 package Unchecked_Conversions
is new Table
.Table
(
184 Table_Component_Type
=> UC_Entry
,
185 Table_Index_Type
=> Int
,
186 Table_Low_Bound
=> 1,
188 Table_Increment
=> 200,
189 Table_Name
=> "Unchecked_Conversions");
191 ----------------------------------------
192 -- Table for Validate_Address_Clauses --
193 ----------------------------------------
195 -- If an address clause has the form
197 -- for X'Address use Expr
199 -- where Expr is of the form Y'Address or recursively is a reference to a
200 -- constant of either of these forms, and X and Y are entities of objects,
201 -- then if Y has a smaller alignment than X, that merits a warning about
202 -- possible bad alignment. The following table collects address clauses of
203 -- this kind. We put these in a table so that they can be checked after the
204 -- back end has completed annotation of the alignments of objects, since we
205 -- can catch more cases that way.
207 type Address_Clause_Check_Record
is record
209 -- The address clause
212 -- The entity of the object overlaying Y
215 -- The entity of the object being overlaid
218 -- Whether the address is offset within Y
221 package Address_Clause_Checks
is new Table
.Table
(
222 Table_Component_Type
=> Address_Clause_Check_Record
,
223 Table_Index_Type
=> Int
,
224 Table_Low_Bound
=> 1,
226 Table_Increment
=> 200,
227 Table_Name
=> "Address_Clause_Checks");
229 -----------------------------------------
230 -- Adjust_Record_For_Reverse_Bit_Order --
231 -----------------------------------------
233 procedure Adjust_Record_For_Reverse_Bit_Order
(R
: Entity_Id
) is
238 -- Processing depends on version of Ada
240 -- For Ada 95, we just renumber bits within a storage unit. We do the
241 -- same for Ada 83 mode, since we recognize the Bit_Order attribute in
242 -- Ada 83, and are free to add this extension.
244 if Ada_Version
< Ada_2005
then
245 Comp
:= First_Component_Or_Discriminant
(R
);
246 while Present
(Comp
) loop
247 CC
:= Component_Clause
(Comp
);
249 -- If component clause is present, then deal with the non-default
250 -- bit order case for Ada 95 mode.
252 -- We only do this processing for the base type, and in fact that
253 -- is important, since otherwise if there are record subtypes, we
254 -- could reverse the bits once for each subtype, which is wrong.
257 and then Ekind
(R
) = E_Record_Type
260 CFB
: constant Uint
:= Component_Bit_Offset
(Comp
);
261 CSZ
: constant Uint
:= Esize
(Comp
);
262 CLC
: constant Node_Id
:= Component_Clause
(Comp
);
263 Pos
: constant Node_Id
:= Position
(CLC
);
264 FB
: constant Node_Id
:= First_Bit
(CLC
);
266 Storage_Unit_Offset
: constant Uint
:=
267 CFB
/ System_Storage_Unit
;
269 Start_Bit
: constant Uint
:=
270 CFB
mod System_Storage_Unit
;
273 -- Cases where field goes over storage unit boundary
275 if Start_Bit
+ CSZ
> System_Storage_Unit
then
277 -- Allow multi-byte field but generate warning
279 if Start_Bit
mod System_Storage_Unit
= 0
280 and then CSZ
mod System_Storage_Unit
= 0
283 ("multi-byte field specified with non-standard"
284 & " Bit_Order?", CLC
);
286 if Bytes_Big_Endian
then
288 ("bytes are not reversed "
289 & "(component is big-endian)?", CLC
);
292 ("bytes are not reversed "
293 & "(component is little-endian)?", CLC
);
296 -- Do not allow non-contiguous field
300 ("attempt to specify non-contiguous field "
301 & "not permitted", CLC
);
303 ("\caused by non-standard Bit_Order "
306 ("\consider possibility of using "
307 & "Ada 2005 mode here", CLC
);
310 -- Case where field fits in one storage unit
313 -- Give warning if suspicious component clause
315 if Intval
(FB
) >= System_Storage_Unit
316 and then Warn_On_Reverse_Bit_Order
319 ("?Bit_Order clause does not affect " &
320 "byte ordering", Pos
);
322 Intval
(Pos
) + Intval
(FB
) /
325 ("?position normalized to ^ before bit " &
326 "order interpreted", Pos
);
329 -- Here is where we fix up the Component_Bit_Offset value
330 -- to account for the reverse bit order. Some examples of
331 -- what needs to be done are:
333 -- First_Bit .. Last_Bit Component_Bit_Offset
345 -- The rule is that the first bit is is obtained by
346 -- subtracting the old ending bit from storage_unit - 1.
348 Set_Component_Bit_Offset
350 (Storage_Unit_Offset
* System_Storage_Unit
) +
351 (System_Storage_Unit
- 1) -
352 (Start_Bit
+ CSZ
- 1));
354 Set_Normalized_First_Bit
356 Component_Bit_Offset
(Comp
) mod
357 System_Storage_Unit
);
362 Next_Component_Or_Discriminant
(Comp
);
365 -- For Ada 2005, we do machine scalar processing, as fully described In
366 -- AI-133. This involves gathering all components which start at the
367 -- same byte offset and processing them together. Same approach is still
368 -- valid in later versions including Ada 2012.
372 Max_Machine_Scalar_Size
: constant Uint
:=
374 (Standard_Long_Long_Integer_Size
);
375 -- We use this as the maximum machine scalar size
378 SSU
: constant Uint
:= UI_From_Int
(System_Storage_Unit
);
381 -- This first loop through components does two things. First it
382 -- deals with the case of components with component clauses whose
383 -- length is greater than the maximum machine scalar size (either
384 -- accepting them or rejecting as needed). Second, it counts the
385 -- number of components with component clauses whose length does
386 -- not exceed this maximum for later processing.
389 Comp
:= First_Component_Or_Discriminant
(R
);
390 while Present
(Comp
) loop
391 CC
:= Component_Clause
(Comp
);
395 Fbit
: constant Uint
:=
396 Static_Integer
(First_Bit
(CC
));
397 Lbit
: constant Uint
:=
398 Static_Integer
(Last_Bit
(CC
));
401 -- Case of component with last bit >= max machine scalar
403 if Lbit
>= Max_Machine_Scalar_Size
then
405 -- This is allowed only if first bit is zero, and
406 -- last bit + 1 is a multiple of storage unit size.
408 if Fbit
= 0 and then (Lbit
+ 1) mod SSU
= 0 then
410 -- This is the case to give a warning if enabled
412 if Warn_On_Reverse_Bit_Order
then
414 ("multi-byte field specified with "
415 & " non-standard Bit_Order?", CC
);
417 if Bytes_Big_Endian
then
419 ("\bytes are not reversed "
420 & "(component is big-endian)?", CC
);
423 ("\bytes are not reversed "
424 & "(component is little-endian)?", CC
);
428 -- Give error message for RM 13.5.1(10) violation
432 ("machine scalar rules not followed for&",
433 First_Bit
(CC
), Comp
);
435 Error_Msg_Uint_1
:= Lbit
;
436 Error_Msg_Uint_2
:= Max_Machine_Scalar_Size
;
438 ("\last bit (^) exceeds maximum machine "
442 if (Lbit
+ 1) mod SSU
/= 0 then
443 Error_Msg_Uint_1
:= SSU
;
445 ("\and is not a multiple of Storage_Unit (^) "
450 Error_Msg_Uint_1
:= Fbit
;
452 ("\and first bit (^) is non-zero "
458 -- OK case of machine scalar related component clause,
459 -- For now, just count them.
462 Num_CC
:= Num_CC
+ 1;
467 Next_Component_Or_Discriminant
(Comp
);
470 -- We need to sort the component clauses on the basis of the
471 -- Position values in the clause, so we can group clauses with
472 -- the same Position. together to determine the relevant machine
476 Comps
: array (0 .. Num_CC
) of Entity_Id
;
477 -- Array to collect component and discriminant entities. The
478 -- data starts at index 1, the 0'th entry is for the sort
481 function CP_Lt
(Op1
, Op2
: Natural) return Boolean;
482 -- Compare routine for Sort
484 procedure CP_Move
(From
: Natural; To
: Natural);
485 -- Move routine for Sort
487 package Sorting
is new GNAT
.Heap_Sort_G
(CP_Move
, CP_Lt
);
491 -- Start and stop positions in the component list of the set of
492 -- components with the same starting position (that constitute
493 -- components in a single machine scalar).
496 -- Maximum last bit value of any component in this set
499 -- Corresponding machine scalar size
505 function CP_Lt
(Op1
, Op2
: Natural) return Boolean is
507 return Position
(Component_Clause
(Comps
(Op1
))) <
508 Position
(Component_Clause
(Comps
(Op2
)));
515 procedure CP_Move
(From
: Natural; To
: Natural) is
517 Comps
(To
) := Comps
(From
);
520 -- Start of processing for Sort_CC
523 -- Collect the machine scalar relevant component clauses
526 Comp
:= First_Component_Or_Discriminant
(R
);
527 while Present
(Comp
) loop
529 CC
: constant Node_Id
:= Component_Clause
(Comp
);
532 -- Collect only component clauses whose last bit is less
533 -- than machine scalar size. Any component clause whose
534 -- last bit exceeds this value does not take part in
535 -- machine scalar layout considerations. The test for
536 -- Error_Posted makes sure we exclude component clauses
537 -- for which we already posted an error.
540 and then not Error_Posted
(Last_Bit
(CC
))
541 and then Static_Integer
(Last_Bit
(CC
)) <
542 Max_Machine_Scalar_Size
544 Num_CC
:= Num_CC
+ 1;
545 Comps
(Num_CC
) := Comp
;
549 Next_Component_Or_Discriminant
(Comp
);
552 -- Sort by ascending position number
554 Sorting
.Sort
(Num_CC
);
556 -- We now have all the components whose size does not exceed
557 -- the max machine scalar value, sorted by starting position.
558 -- In this loop we gather groups of clauses starting at the
559 -- same position, to process them in accordance with AI-133.
562 while Stop
< Num_CC
loop
567 (Last_Bit
(Component_Clause
(Comps
(Start
))));
568 while Stop
< Num_CC
loop
570 (Position
(Component_Clause
(Comps
(Stop
+ 1)))) =
572 (Position
(Component_Clause
(Comps
(Stop
))))
580 (Component_Clause
(Comps
(Stop
)))));
586 -- Now we have a group of component clauses from Start to
587 -- Stop whose positions are identical, and MaxL is the
588 -- maximum last bit value of any of these components.
590 -- We need to determine the corresponding machine scalar
591 -- size. This loop assumes that machine scalar sizes are
592 -- even, and that each possible machine scalar has twice
593 -- as many bits as the next smaller one.
595 MSS
:= Max_Machine_Scalar_Size
;
597 and then (MSS
/ 2) >= SSU
598 and then (MSS
/ 2) > MaxL
603 -- Here is where we fix up the Component_Bit_Offset value
604 -- to account for the reverse bit order. Some examples of
605 -- what needs to be done for the case of a machine scalar
608 -- First_Bit .. Last_Bit Component_Bit_Offset
620 -- The rule is that the first bit is obtained by subtracting
621 -- the old ending bit from machine scalar size - 1.
623 for C
in Start
.. Stop
loop
625 Comp
: constant Entity_Id
:= Comps
(C
);
626 CC
: constant Node_Id
:=
627 Component_Clause
(Comp
);
628 LB
: constant Uint
:=
629 Static_Integer
(Last_Bit
(CC
));
630 NFB
: constant Uint
:= MSS
- Uint_1
- LB
;
631 NLB
: constant Uint
:= NFB
+ Esize
(Comp
) - 1;
632 Pos
: constant Uint
:=
633 Static_Integer
(Position
(CC
));
636 if Warn_On_Reverse_Bit_Order
then
637 Error_Msg_Uint_1
:= MSS
;
639 ("info: reverse bit order in machine " &
640 "scalar of length^?", First_Bit
(CC
));
641 Error_Msg_Uint_1
:= NFB
;
642 Error_Msg_Uint_2
:= NLB
;
644 if Bytes_Big_Endian
then
646 ("?\info: big-endian range for "
647 & "component & is ^ .. ^",
648 First_Bit
(CC
), Comp
);
651 ("?\info: little-endian range "
652 & "for component & is ^ .. ^",
653 First_Bit
(CC
), Comp
);
657 Set_Component_Bit_Offset
(Comp
, Pos
* SSU
+ NFB
);
658 Set_Normalized_First_Bit
(Comp
, NFB
mod SSU
);
665 end Adjust_Record_For_Reverse_Bit_Order
;
667 -------------------------------------
668 -- Alignment_Check_For_Size_Change --
669 -------------------------------------
671 procedure Alignment_Check_For_Size_Change
(Typ
: Entity_Id
; Size
: Uint
) is
673 -- If the alignment is known, and not set by a rep clause, and is
674 -- inconsistent with the size being set, then reset it to unknown,
675 -- we assume in this case that the size overrides the inherited
676 -- alignment, and that the alignment must be recomputed.
678 if Known_Alignment
(Typ
)
679 and then not Has_Alignment_Clause
(Typ
)
680 and then Size
mod (Alignment
(Typ
) * SSU
) /= 0
682 Init_Alignment
(Typ
);
684 end Alignment_Check_For_Size_Change
;
686 -------------------------------------
687 -- Analyze_Aspects_At_Freeze_Point --
688 -------------------------------------
690 procedure Analyze_Aspects_At_Freeze_Point
(E
: Entity_Id
) is
695 procedure Analyze_Aspect_Default_Value
(ASN
: Node_Id
);
696 -- This routine analyzes an Aspect_Default_[Component_]Value denoted by
697 -- the aspect specification node ASN.
699 procedure Make_Pragma_From_Boolean_Aspect
(ASN
: Node_Id
);
700 -- Given an aspect specification node ASN whose expression is an
701 -- optional Boolean, this routines creates the corresponding pragma
702 -- at the freezing point.
704 ----------------------------------
705 -- Analyze_Aspect_Default_Value --
706 ----------------------------------
708 procedure Analyze_Aspect_Default_Value
(ASN
: Node_Id
) is
709 Ent
: constant Entity_Id
:= Entity
(ASN
);
710 Expr
: constant Node_Id
:= Expression
(ASN
);
711 Id
: constant Node_Id
:= Identifier
(ASN
);
714 Error_Msg_Name_1
:= Chars
(Id
);
716 if not Is_Type
(Ent
) then
717 Error_Msg_N
("aspect% can only apply to a type", Id
);
720 elsif not Is_First_Subtype
(Ent
) then
721 Error_Msg_N
("aspect% cannot apply to subtype", Id
);
724 elsif A_Id
= Aspect_Default_Value
725 and then not Is_Scalar_Type
(Ent
)
727 Error_Msg_N
("aspect% can only be applied to scalar type", Id
);
730 elsif A_Id
= Aspect_Default_Component_Value
then
731 if not Is_Array_Type
(Ent
) then
732 Error_Msg_N
("aspect% can only be applied to array type", Id
);
735 elsif not Is_Scalar_Type
(Component_Type
(Ent
)) then
736 Error_Msg_N
("aspect% requires scalar components", Id
);
741 Set_Has_Default_Aspect
(Base_Type
(Ent
));
743 if Is_Scalar_Type
(Ent
) then
744 Set_Default_Aspect_Value
(Ent
, Expr
);
746 Set_Default_Aspect_Component_Value
(Ent
, Expr
);
748 end Analyze_Aspect_Default_Value
;
750 -------------------------------------
751 -- Make_Pragma_From_Boolean_Aspect --
752 -------------------------------------
754 procedure Make_Pragma_From_Boolean_Aspect
(ASN
: Node_Id
) is
755 Ident
: constant Node_Id
:= Identifier
(ASN
);
756 A_Name
: constant Name_Id
:= Chars
(Ident
);
757 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(A_Name
);
758 Ent
: constant Entity_Id
:= Entity
(ASN
);
759 Expr
: constant Node_Id
:= Expression
(ASN
);
760 Loc
: constant Source_Ptr
:= Sloc
(ASN
);
764 procedure Check_False_Aspect_For_Derived_Type
;
765 -- This procedure checks for the case of a false aspect for a derived
766 -- type, which improperly tries to cancel an aspect inherited from
769 -----------------------------------------
770 -- Check_False_Aspect_For_Derived_Type --
771 -----------------------------------------
773 procedure Check_False_Aspect_For_Derived_Type
is
777 -- We are only checking derived types
779 if not Is_Derived_Type
(E
) then
783 Par
:= Nearest_Ancestor
(E
);
786 when Aspect_Atomic | Aspect_Shared
=>
787 if not Is_Atomic
(Par
) then
791 when Aspect_Atomic_Components
=>
792 if not Has_Atomic_Components
(Par
) then
796 when Aspect_Discard_Names
=>
797 if not Discard_Names
(Par
) then
802 if not Is_Packed
(Par
) then
806 when Aspect_Unchecked_Union
=>
807 if not Is_Unchecked_Union
(Par
) then
811 when Aspect_Volatile
=>
812 if not Is_Volatile
(Par
) then
816 when Aspect_Volatile_Components
=>
817 if not Has_Volatile_Components
(Par
) then
825 -- Fall through means we are canceling an inherited aspect
827 Error_Msg_Name_1
:= A_Name
;
828 Error_Msg_NE
("derived type& inherits aspect%, cannot cancel",
832 end Check_False_Aspect_For_Derived_Type
;
834 -- Start of processing for Make_Pragma_From_Boolean_Aspect
837 if Is_False
(Static_Boolean
(Expr
)) then
838 Check_False_Aspect_For_Derived_Type
;
843 Pragma_Argument_Associations
=> New_List
(
844 New_Occurrence_Of
(Ent
, Sloc
(Ident
))),
846 Make_Identifier
(Sloc
(Ident
), Chars
(Ident
)));
848 Set_From_Aspect_Specification
(Prag
, True);
849 Set_Corresponding_Aspect
(Prag
, ASN
);
850 Set_Aspect_Rep_Item
(ASN
, Prag
);
851 Set_Is_Delayed_Aspect
(Prag
);
852 Set_Parent
(Prag
, ASN
);
854 end Make_Pragma_From_Boolean_Aspect
;
856 -- Start of processing for Analyze_Aspects_At_Freeze_Point
859 -- Must be visible in current scope.
861 if not Scope_Within_Or_Same
(Current_Scope
, Scope
(E
)) then
865 -- Look for aspect specification entries for this entity
867 ASN
:= First_Rep_Item
(E
);
868 while Present
(ASN
) loop
869 if Nkind
(ASN
) = N_Aspect_Specification
870 and then Entity
(ASN
) = E
871 and then Is_Delayed_Aspect
(ASN
)
873 A_Id
:= Get_Aspect_Id
(Chars
(Identifier
(ASN
)));
877 -- For aspects whose expression is an optional Boolean, make
878 -- the corresponding pragma at the freezing point.
880 when Boolean_Aspects |
881 Library_Unit_Aspects
=>
882 Make_Pragma_From_Boolean_Aspect
(ASN
);
884 -- Special handling for aspects that don't correspond to
885 -- pragmas/attributes.
887 when Aspect_Default_Value |
888 Aspect_Default_Component_Value
=>
889 Analyze_Aspect_Default_Value
(ASN
);
895 Ritem
:= Aspect_Rep_Item
(ASN
);
897 if Present
(Ritem
) then
904 end Analyze_Aspects_At_Freeze_Point
;
906 -----------------------------------
907 -- Analyze_Aspect_Specifications --
908 -----------------------------------
910 procedure Analyze_Aspect_Specifications
(N
: Node_Id
; E
: Entity_Id
) is
915 L
: constant List_Id
:= Aspect_Specifications
(N
);
917 Ins_Node
: Node_Id
:= N
;
918 -- Insert pragmas/attribute definition clause after this node when no
919 -- delayed analysis is required.
921 -- The general processing involves building an attribute definition
922 -- clause or a pragma node that corresponds to the aspect. Then in order
923 -- to delay the evaluation of this aspect to the freeze point, we attach
924 -- the corresponding pragma/attribute definition clause to the aspect
925 -- specification node, which is then placed in the Rep Item chain. In
926 -- this case we mark the entity by setting the flag Has_Delayed_Aspects
927 -- and we evaluate the rep item at the freeze point. When the aspect
928 -- doesn't have a corresponding pragma/attribute definition clause, then
929 -- its analysis is simply delayed at the freeze point.
931 -- Some special cases don't require delay analysis, thus the aspect is
932 -- analyzed right now.
934 -- Note that there is a special handling for
935 -- Pre/Post/Test_Case/Contract_Case aspects. In this case, we do not
936 -- have to worry about delay issues, since the pragmas themselves deal
937 -- with delay of visibility for the expression analysis. Thus, we just
938 -- insert the pragma after the node N.
941 pragma Assert
(Present
(L
));
943 -- Loop through aspects
946 Aspect_Loop
: while Present
(Aspect
) loop
948 Expr
: constant Node_Id
:= Expression
(Aspect
);
949 Id
: constant Node_Id
:= Identifier
(Aspect
);
950 Loc
: constant Source_Ptr
:= Sloc
(Aspect
);
951 Nam
: constant Name_Id
:= Chars
(Id
);
952 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Nam
);
955 Delay_Required
: Boolean := True;
956 -- Set False if delay is not required
958 Eloc
: Source_Ptr
:= No_Location
;
959 -- Source location of expression, modified when we split PPC's. It
960 -- is set below when Expr is present.
962 procedure Analyze_Aspect_External_Or_Link_Name
;
963 -- This routine performs the analysis of the External_Name or
964 -- Link_Name aspects.
966 procedure Analyze_Aspect_Implicit_Dereference
;
967 -- This routine performs the analysis of the Implicit_Dereference
970 ------------------------------------------
971 -- Analyze_Aspect_External_Or_Link_Name --
972 ------------------------------------------
974 procedure Analyze_Aspect_External_Or_Link_Name
is
976 -- Verify that there is an Import/Export aspect defined for the
977 -- entity. The processing of that aspect in turn checks that
978 -- there is a Convention aspect declared. The pragma is
979 -- constructed when processing the Convention aspect.
986 while Present
(A
) loop
987 exit when Chars
(Identifier
(A
)) = Name_Export
988 or else Chars
(Identifier
(A
)) = Name_Import
;
994 ("Missing Import/Export for Link/External name",
998 end Analyze_Aspect_External_Or_Link_Name
;
1000 -----------------------------------------
1001 -- Analyze_Aspect_Implicit_Dereference --
1002 -----------------------------------------
1004 procedure Analyze_Aspect_Implicit_Dereference
is
1007 or else not Has_Discriminants
(E
)
1010 ("Aspect must apply to a type with discriminants", N
);
1017 Disc
:= First_Discriminant
(E
);
1018 while Present
(Disc
) loop
1019 if Chars
(Expr
) = Chars
(Disc
)
1020 and then Ekind
(Etype
(Disc
)) =
1021 E_Anonymous_Access_Type
1023 Set_Has_Implicit_Dereference
(E
);
1024 Set_Has_Implicit_Dereference
(Disc
);
1028 Next_Discriminant
(Disc
);
1031 -- Error if no proper access discriminant.
1034 ("not an access discriminant of&", Expr
, E
);
1037 end Analyze_Aspect_Implicit_Dereference
;
1040 -- Skip aspect if already analyzed (not clear if this is needed)
1042 if Analyzed
(Aspect
) then
1046 -- Set the source location of expression, used in the case of
1047 -- a failed precondition/postcondition or invariant. Note that
1048 -- the source location of the expression is not usually the best
1049 -- choice here. For example, it gets located on the last AND
1050 -- keyword in a chain of boolean expressiond AND'ed together.
1051 -- It is best to put the message on the first character of the
1052 -- assertion, which is the effect of the First_Node call here.
1054 if Present
(Expr
) then
1055 Eloc
:= Sloc
(First_Node
(Expr
));
1058 -- Check restriction No_Implementation_Aspect_Specifications
1060 if Impl_Defined_Aspects
(A_Id
) then
1062 (No_Implementation_Aspect_Specifications
, Aspect
);
1065 -- Check restriction No_Specification_Of_Aspect
1067 Check_Restriction_No_Specification_Of_Aspect
(Aspect
);
1069 -- Analyze this aspect
1071 Set_Analyzed
(Aspect
);
1072 Set_Entity
(Aspect
, E
);
1073 Ent
:= New_Occurrence_Of
(E
, Sloc
(Id
));
1075 -- Check for duplicate aspect. Note that the Comes_From_Source
1076 -- test allows duplicate Pre/Post's that we generate internally
1077 -- to escape being flagged here.
1079 if No_Duplicates_Allowed
(A_Id
) then
1081 while Anod
/= Aspect
loop
1083 (A_Id
, Get_Aspect_Id
(Chars
(Identifier
(Anod
))))
1084 and then Comes_From_Source
(Aspect
)
1086 Error_Msg_Name_1
:= Nam
;
1087 Error_Msg_Sloc
:= Sloc
(Anod
);
1089 -- Case of same aspect specified twice
1091 if Class_Present
(Anod
) = Class_Present
(Aspect
) then
1092 if not Class_Present
(Anod
) then
1094 ("aspect% for & previously given#",
1098 ("aspect `%''Class` for & previously given#",
1108 -- Check some general restrictions on language defined aspects
1110 if not Impl_Defined_Aspects
(A_Id
) then
1111 Error_Msg_Name_1
:= Nam
;
1113 -- Not allowed for renaming declarations
1115 if Nkind
(N
) in N_Renaming_Declaration
then
1117 ("aspect % not allowed for renaming declaration",
1121 -- Not allowed for formal type declarations
1123 if Nkind
(N
) = N_Formal_Type_Declaration
then
1125 ("aspect % not allowed for formal type declaration",
1130 -- Copy expression for later processing by the procedures
1131 -- Check_Aspect_At_[Freeze_Point | End_Of_Declarations]
1133 Set_Entity
(Id
, New_Copy_Tree
(Expr
));
1135 -- Processing based on specific aspect
1139 -- No_Aspect should be impossible
1142 raise Program_Error
;
1144 -- Case 1: Aspects corresponding to attribute definition
1147 when Aspect_Address |
1150 Aspect_Component_Size |
1151 Aspect_Constant_Indexing |
1152 Aspect_Default_Iterator |
1153 Aspect_Dispatching_Domain |
1154 Aspect_External_Tag |
1156 Aspect_Iterator_Element |
1157 Aspect_Machine_Radix |
1158 Aspect_Object_Size |
1161 Aspect_Scalar_Storage_Order |
1164 Aspect_Simple_Storage_Pool |
1165 Aspect_Storage_Pool |
1166 Aspect_Storage_Size |
1167 Aspect_Stream_Size |
1169 Aspect_Variable_Indexing |
1172 -- Indexing aspects apply only to tagged type
1174 if (A_Id
= Aspect_Constant_Indexing
1175 or else A_Id
= Aspect_Variable_Indexing
)
1176 and then not (Is_Type
(E
)
1177 and then Is_Tagged_Type
(E
))
1179 Error_Msg_N
("indexing applies to a tagged type", N
);
1183 -- Construct the attribute definition clause
1186 Make_Attribute_Definition_Clause
(Loc
,
1188 Chars
=> Chars
(Id
),
1189 Expression
=> Relocate_Node
(Expr
));
1191 -- Case 2: Aspects cooresponding to pragmas
1193 -- Case 2a: Aspects corresponding to pragmas with two
1194 -- arguments, where the first argument is a local name
1195 -- referring to the entity, and the second argument is the
1196 -- aspect definition expression.
1198 when Aspect_Suppress |
1199 Aspect_Unsuppress
=>
1201 -- Construct the pragma
1205 Pragma_Argument_Associations
=> New_List
(
1206 New_Occurrence_Of
(E
, Loc
),
1207 Relocate_Node
(Expr
)),
1208 Pragma_Identifier
=>
1209 Make_Identifier
(Sloc
(Id
), Chars
(Id
)));
1211 when Aspect_Synchronization
=>
1213 -- The aspect corresponds to pragma Implemented.
1214 -- Construct the pragma
1218 Pragma_Argument_Associations
=> New_List
(
1219 New_Occurrence_Of
(E
, Loc
),
1220 Relocate_Node
(Expr
)),
1221 Pragma_Identifier
=>
1222 Make_Identifier
(Sloc
(Id
), Name_Implemented
));
1224 -- No delay is required since the only values are: By_Entry
1225 -- | By_Protected_Procedure | By_Any | Optional which don't
1226 -- get analyzed anyway.
1228 Delay_Required
:= False;
1230 when Aspect_Attach_Handler
=>
1233 Pragma_Identifier
=>
1234 Make_Identifier
(Sloc
(Id
), Name_Attach_Handler
),
1235 Pragma_Argument_Associations
=>
1236 New_List
(Ent
, Relocate_Node
(Expr
)));
1238 when Aspect_Dynamic_Predicate |
1240 Aspect_Static_Predicate
=>
1242 -- Construct the pragma (always a pragma Predicate, with
1243 -- flags recording whether it is static/dynamic).
1247 Pragma_Argument_Associations
=>
1248 New_List
(Ent
, Relocate_Node
(Expr
)),
1249 Class_Present
=> Class_Present
(Aspect
),
1250 Pragma_Identifier
=>
1251 Make_Identifier
(Sloc
(Id
), Name_Predicate
));
1253 -- If the type is private, indicate that its completion
1254 -- has a freeze node, because that is the one that will be
1255 -- visible at freeze time.
1257 Set_Has_Predicates
(E
);
1259 if Is_Private_Type
(E
)
1260 and then Present
(Full_View
(E
))
1262 Set_Has_Predicates
(Full_View
(E
));
1263 Set_Has_Delayed_Aspects
(Full_View
(E
));
1264 Ensure_Freeze_Node
(Full_View
(E
));
1267 -- Case 2b: Aspects corresponding to pragmas with two
1268 -- arguments, where the second argument is a local name
1269 -- referring to the entity, and the first argument is the
1270 -- aspect definition expression.
1272 when Aspect_Convention
=>
1274 -- The aspect may be part of the specification of an import
1275 -- or export pragma. Scan the aspect list to gather the
1276 -- other components, if any. The name of the generated
1277 -- pragma is one of Convention/Import/Export.
1289 P_Name
:= Chars
(Id
);
1291 Arg_List
:= New_List
;
1296 while Present
(A
) loop
1297 A_Name
:= Chars
(Identifier
(A
));
1299 if A_Name
= Name_Import
1300 or else A_Name
= Name_Export
1303 Error_Msg_N
("conflicting", A
);
1310 elsif A_Name
= Name_Link_Name
then
1311 L_Assoc
:= Make_Pragma_Argument_Association
(Loc
,
1313 Expression
=> Relocate_Node
(Expression
(A
)));
1315 elsif A_Name
= Name_External_Name
then
1316 E_Assoc
:= Make_Pragma_Argument_Association
(Loc
,
1318 Expression
=> Relocate_Node
(Expression
(A
)));
1324 Arg_List
:= New_List
(Relocate_Node
(Expr
), Ent
);
1325 if Present
(L_Assoc
) then
1326 Append_To
(Arg_List
, L_Assoc
);
1329 if Present
(E_Assoc
) then
1330 Append_To
(Arg_List
, E_Assoc
);
1335 Pragma_Argument_Associations
=> Arg_List
,
1336 Pragma_Identifier
=>
1337 Make_Identifier
(Loc
, P_Name
));
1340 -- The following three aspects can be specified for a
1341 -- subprogram body, in which case we generate pragmas for them
1342 -- and insert them ahead of local declarations, rather than
1346 Aspect_Interrupt_Priority |
1348 if Nkind
(N
) = N_Subprogram_Body
then
1351 Pragma_Argument_Associations
=>
1352 New_List
(Relocate_Node
(Expr
)),
1353 Pragma_Identifier
=>
1354 Make_Identifier
(Sloc
(Id
), Chars
(Id
)));
1357 Make_Attribute_Definition_Clause
(Loc
,
1359 Chars
=> Chars
(Id
),
1360 Expression
=> Relocate_Node
(Expr
));
1363 when Aspect_Warnings
=>
1365 -- Construct the pragma
1369 Pragma_Argument_Associations
=> New_List
(
1370 Relocate_Node
(Expr
),
1371 New_Occurrence_Of
(E
, Loc
)),
1372 Pragma_Identifier
=>
1373 Make_Identifier
(Sloc
(Id
), Chars
(Id
)),
1374 Class_Present
=> Class_Present
(Aspect
));
1376 -- We don't have to play the delay game here, since the only
1377 -- values are ON/OFF which don't get analyzed anyway.
1379 Delay_Required
:= False;
1381 -- Case 2c: Aspects corresponding to pragmas with three
1384 -- Invariant aspects have a first argument that references the
1385 -- entity, a second argument that is the expression and a third
1386 -- argument that is an appropriate message.
1388 when Aspect_Invariant |
1389 Aspect_Type_Invariant
=>
1391 -- Analysis of the pragma will verify placement legality:
1392 -- an invariant must apply to a private type, or appear in
1393 -- the private part of a spec and apply to a completion.
1395 -- Construct the pragma
1399 Pragma_Argument_Associations
=>
1400 New_List
(Ent
, Relocate_Node
(Expr
)),
1401 Class_Present
=> Class_Present
(Aspect
),
1402 Pragma_Identifier
=>
1403 Make_Identifier
(Sloc
(Id
), Name_Invariant
));
1405 -- Add message unless exception messages are suppressed
1407 if not Opt
.Exception_Locations_Suppressed
then
1408 Append_To
(Pragma_Argument_Associations
(Aitem
),
1409 Make_Pragma_Argument_Association
(Eloc
,
1410 Chars
=> Name_Message
,
1412 Make_String_Literal
(Eloc
,
1413 Strval
=> "failed invariant from "
1414 & Build_Location_String
(Eloc
))));
1417 -- For Invariant case, insert immediately after the entity
1418 -- declaration. We do not have to worry about delay issues
1419 -- since the pragma processing takes care of this.
1421 Delay_Required
:= False;
1423 -- Case 3 : Aspects that don't correspond to pragma/attribute
1424 -- definition clause.
1426 -- Case 3a: The aspects listed below don't correspond to
1427 -- pragmas/attributes but do require delayed analysis.
1429 when Aspect_Default_Value |
1430 Aspect_Default_Component_Value
=>
1433 -- Case 3b: The aspects listed below don't correspond to
1434 -- pragmas/attributes and don't need delayed analysis.
1436 -- For Implicit_Dereference, External_Name and Link_Name, only
1437 -- the legality checks are done during the analysis, thus no
1438 -- delay is required.
1440 when Aspect_Implicit_Dereference
=>
1441 Analyze_Aspect_Implicit_Dereference
;
1444 when Aspect_External_Name |
1446 Analyze_Aspect_External_Or_Link_Name
;
1449 when Aspect_Dimension
=>
1450 Analyze_Aspect_Dimension
(N
, Id
, Expr
);
1453 when Aspect_Dimension_System
=>
1454 Analyze_Aspect_Dimension_System
(N
, Id
, Expr
);
1457 -- Case 4: Special handling for aspects
1458 -- Pre/Post/Test_Case/Contract_Case whose corresponding pragmas
1459 -- take care of the delay.
1461 -- Aspects Pre/Post generate Precondition/Postcondition pragmas
1462 -- with a first argument that is the expression, and a second
1463 -- argument that is an informative message if the test fails.
1464 -- This is inserted right after the declaration, to get the
1465 -- required pragma placement. The processing for the pragmas
1466 -- takes care of the required delay.
1468 when Pre_Post_Aspects
=> declare
1472 if A_Id
= Aspect_Pre
or else A_Id
= Aspect_Precondition
then
1473 Pname
:= Name_Precondition
;
1475 Pname
:= Name_Postcondition
;
1478 -- If the expressions is of the form A and then B, then
1479 -- we generate separate Pre/Post aspects for the separate
1480 -- clauses. Since we allow multiple pragmas, there is no
1481 -- problem in allowing multiple Pre/Post aspects internally.
1482 -- These should be treated in reverse order (B first and
1483 -- A second) since they are later inserted just after N in
1484 -- the order they are treated. This way, the pragma for A
1485 -- ends up preceding the pragma for B, which may have an
1486 -- importance for the error raised (either constraint error
1487 -- or precondition error).
1489 -- We do not do this for Pre'Class, since we have to put
1490 -- these conditions together in a complex OR expression
1492 -- We do not do this in ASIS mode, as ASIS relies on the
1493 -- original node representing the complete expression, when
1494 -- retrieving it through the source aspect table.
1497 and then (Pname
= Name_Postcondition
1498 or else not Class_Present
(Aspect
))
1500 while Nkind
(Expr
) = N_And_Then
loop
1501 Insert_After
(Aspect
,
1502 Make_Aspect_Specification
(Sloc
(Left_Opnd
(Expr
)),
1503 Identifier
=> Identifier
(Aspect
),
1504 Expression
=> Relocate_Node
(Left_Opnd
(Expr
)),
1505 Class_Present
=> Class_Present
(Aspect
),
1506 Split_PPC
=> True));
1507 Rewrite
(Expr
, Relocate_Node
(Right_Opnd
(Expr
)));
1508 Eloc
:= Sloc
(Expr
);
1512 -- Build the precondition/postcondition pragma
1516 Pragma_Identifier
=>
1517 Make_Identifier
(Sloc
(Id
), Pname
),
1518 Class_Present
=> Class_Present
(Aspect
),
1519 Split_PPC
=> Split_PPC
(Aspect
),
1520 Pragma_Argument_Associations
=> New_List
(
1521 Make_Pragma_Argument_Association
(Eloc
,
1522 Chars
=> Name_Check
,
1523 Expression
=> Relocate_Node
(Expr
))));
1525 -- Add message unless exception messages are suppressed
1527 if not Opt
.Exception_Locations_Suppressed
then
1528 Append_To
(Pragma_Argument_Associations
(Aitem
),
1529 Make_Pragma_Argument_Association
(Eloc
,
1530 Chars
=> Name_Message
,
1532 Make_String_Literal
(Eloc
,
1534 & Get_Name_String
(Pname
)
1536 & Build_Location_String
(Eloc
))));
1539 Set_From_Aspect_Specification
(Aitem
, True);
1540 Set_Corresponding_Aspect
(Aitem
, Aspect
);
1541 Set_Is_Delayed_Aspect
(Aspect
);
1543 -- For Pre/Post cases, insert immediately after the entity
1544 -- declaration, since that is the required pragma placement.
1545 -- Note that for these aspects, we do not have to worry
1546 -- about delay issues, since the pragmas themselves deal
1547 -- with delay of visibility for the expression analysis.
1549 -- If the entity is a library-level subprogram, the pre/
1550 -- postconditions must be treated as late pragmas.
1552 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
1553 Add_Global_Declaration
(Aitem
);
1555 Insert_After
(N
, Aitem
);
1561 when Aspect_Contract_Case |
1565 Comp_Expr
: Node_Id
;
1566 Comp_Assn
: Node_Id
;
1572 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
1573 Error_Msg_Name_1
:= Nam
;
1574 Error_Msg_N
("incorrect placement of aspect `%`", E
);
1578 if Nkind
(Expr
) /= N_Aggregate
then
1579 Error_Msg_Name_1
:= Nam
;
1581 ("wrong syntax for aspect `%` for &", Id
, E
);
1585 -- Make pragma expressions refer to the original aspect
1586 -- expressions through the Original_Node link. This is
1587 -- used in semantic analysis for ASIS mode, so that the
1588 -- original expression also gets analyzed.
1590 Comp_Expr
:= First
(Expressions
(Expr
));
1591 while Present
(Comp_Expr
) loop
1592 New_Expr
:= Relocate_Node
(Comp_Expr
);
1593 Set_Original_Node
(New_Expr
, Comp_Expr
);
1595 (Make_Pragma_Argument_Association
(Sloc
(Comp_Expr
),
1596 Expression
=> New_Expr
),
1601 Comp_Assn
:= First
(Component_Associations
(Expr
));
1602 while Present
(Comp_Assn
) loop
1603 if List_Length
(Choices
(Comp_Assn
)) /= 1
1605 Nkind
(First
(Choices
(Comp_Assn
))) /= N_Identifier
1607 Error_Msg_Name_1
:= Nam
;
1609 ("wrong syntax for aspect `%` for &", Id
, E
);
1613 New_Expr
:= Relocate_Node
(Expression
(Comp_Assn
));
1614 Set_Original_Node
(New_Expr
, Expression
(Comp_Assn
));
1615 Append
(Make_Pragma_Argument_Association
(
1616 Sloc
=> Sloc
(Comp_Assn
),
1617 Chars
=> Chars
(First
(Choices
(Comp_Assn
))),
1618 Expression
=> New_Expr
),
1623 -- Build the contract-case or test-case pragma
1627 Pragma_Identifier
=>
1628 Make_Identifier
(Sloc
(Id
), Nam
),
1629 Pragma_Argument_Associations
=>
1632 Delay_Required
:= False;
1635 -- Case 5: Special handling for aspects with an optional
1636 -- boolean argument.
1638 -- In the general case, the corresponding pragma cannot be
1639 -- generated yet because the evaluation of the boolean needs to
1640 -- be delayed til the freeze point.
1642 when Boolean_Aspects |
1643 Library_Unit_Aspects
=>
1645 Set_Is_Boolean_Aspect
(Aspect
);
1647 -- Lock_Free aspect only apply to protected objects
1649 if A_Id
= Aspect_Lock_Free
then
1650 if Ekind
(E
) /= E_Protected_Type
then
1651 Error_Msg_Name_1
:= Nam
;
1653 ("aspect % only applies to a protected object",
1657 -- Set the Uses_Lock_Free flag to True if there is no
1658 -- expression or if the expression is True. ??? The
1659 -- evaluation of this aspect should be delayed to the
1663 or else Is_True
(Static_Boolean
(Expr
))
1665 Set_Uses_Lock_Free
(E
);
1668 Record_Rep_Item
(E
, Aspect
);
1673 elsif A_Id
= Aspect_Import
or else A_Id
= Aspect_Export
then
1675 -- Verify that there is an aspect Convention that will
1676 -- incorporate the Import/Export aspect, and eventual
1677 -- Link/External names.
1684 while Present
(A
) loop
1685 exit when Chars
(Identifier
(A
)) = Name_Convention
;
1691 ("missing Convention aspect for Export/Import",
1699 -- This requires special handling in the case of a package
1700 -- declaration, the pragma needs to be inserted in the list
1701 -- of declarations for the associated package. There is no
1702 -- issue of visibility delay for these aspects.
1704 if A_Id
in Library_Unit_Aspects
1705 and then Nkind
(N
) = N_Package_Declaration
1706 and then Nkind
(Parent
(N
)) /= N_Compilation_Unit
1709 ("incorrect context for library unit aspect&", Id
);
1713 -- Special handling when the aspect has no expression. In
1714 -- this case the value is considered to be True. Thus, we
1715 -- simply insert the pragma, no delay is required.
1720 Pragma_Argument_Associations
=> New_List
(Ent
),
1721 Pragma_Identifier
=>
1722 Make_Identifier
(Sloc
(Id
), Chars
(Id
)));
1724 Delay_Required
:= False;
1726 -- In general cases, the corresponding pragma/attribute
1727 -- definition clause will be inserted later at the freezing
1735 -- Attach the corresponding pragma/attribute definition clause to
1736 -- the aspect specification node.
1738 if Present
(Aitem
) then
1739 Set_From_Aspect_Specification
(Aitem
, True);
1741 if Nkind
(Aitem
) = N_Pragma
then
1742 Set_Corresponding_Aspect
(Aitem
, Aspect
);
1746 -- In the context of a compilation unit, we directly put the
1747 -- pragma in the Pragmas_After list of the
1748 -- N_Compilation_Unit_Aux node (No delay is required here)
1749 -- except for aspects on a subprogram body (see below).
1751 if Nkind
(Parent
(N
)) = N_Compilation_Unit
1752 and then (Present
(Aitem
) or else Is_Boolean_Aspect
(Aspect
))
1755 Aux
: constant Node_Id
:= Aux_Decls_Node
(Parent
(N
));
1758 pragma Assert
(Nkind
(Aux
) = N_Compilation_Unit_Aux
);
1760 -- For a Boolean aspect, create the corresponding pragma if
1761 -- no expression or if the value is True.
1763 if Is_Boolean_Aspect
(Aspect
)
1766 if Is_True
(Static_Boolean
(Expr
)) then
1769 Pragma_Argument_Associations
=> New_List
(Ent
),
1770 Pragma_Identifier
=>
1771 Make_Identifier
(Sloc
(Id
), Chars
(Id
)));
1773 Set_From_Aspect_Specification
(Aitem
, True);
1774 Set_Corresponding_Aspect
(Aitem
, Aspect
);
1781 -- If the aspect is on a subprogram body (relevant aspects
1782 -- are Inline and Priority), add the pragma in front of
1783 -- the declarations.
1785 if Nkind
(N
) = N_Subprogram_Body
then
1786 if No
(Declarations
(N
)) then
1787 Set_Declarations
(N
, New_List
);
1790 Prepend
(Aitem
, Declarations
(N
));
1793 if No
(Pragmas_After
(Aux
)) then
1794 Set_Pragmas_After
(Aux
, Empty_List
);
1797 Append
(Aitem
, Pragmas_After
(Aux
));
1804 -- The evaluation of the aspect is delayed to the freezing point.
1805 -- The pragma or attribute clause if there is one is then attached
1806 -- to the aspect specification which is placed in the rep item
1809 if Delay_Required
then
1810 if Present
(Aitem
) then
1811 Set_Is_Delayed_Aspect
(Aitem
);
1812 Set_Aspect_Rep_Item
(Aspect
, Aitem
);
1813 Set_Parent
(Aitem
, Aspect
);
1816 Set_Is_Delayed_Aspect
(Aspect
);
1817 Set_Has_Delayed_Aspects
(E
);
1818 Record_Rep_Item
(E
, Aspect
);
1820 -- When delay is not required and the context is not a compilation
1821 -- unit, we simply insert the pragma/attribute definition clause
1825 Insert_After
(Ins_Node
, Aitem
);
1832 end loop Aspect_Loop
;
1834 if Has_Delayed_Aspects
(E
) then
1835 Ensure_Freeze_Node
(E
);
1837 end Analyze_Aspect_Specifications
;
1839 -----------------------
1840 -- Analyze_At_Clause --
1841 -----------------------
1843 -- An at clause is replaced by the corresponding Address attribute
1844 -- definition clause that is the preferred approach in Ada 95.
1846 procedure Analyze_At_Clause
(N
: Node_Id
) is
1847 CS
: constant Boolean := Comes_From_Source
(N
);
1850 -- This is an obsolescent feature
1852 Check_Restriction
(No_Obsolescent_Features
, N
);
1854 if Warn_On_Obsolescent_Feature
then
1856 ("at clause is an obsolescent feature (RM J.7(2))?", N
);
1858 ("\use address attribute definition clause instead?", N
);
1861 -- Rewrite as address clause
1864 Make_Attribute_Definition_Clause
(Sloc
(N
),
1865 Name
=> Identifier
(N
),
1866 Chars
=> Name_Address
,
1867 Expression
=> Expression
(N
)));
1869 -- We preserve Comes_From_Source, since logically the clause still comes
1870 -- from the source program even though it is changed in form.
1872 Set_Comes_From_Source
(N
, CS
);
1874 -- Analyze rewritten clause
1876 Analyze_Attribute_Definition_Clause
(N
);
1877 end Analyze_At_Clause
;
1879 -----------------------------------------
1880 -- Analyze_Attribute_Definition_Clause --
1881 -----------------------------------------
1883 procedure Analyze_Attribute_Definition_Clause
(N
: Node_Id
) is
1884 Loc
: constant Source_Ptr
:= Sloc
(N
);
1885 Nam
: constant Node_Id
:= Name
(N
);
1886 Attr
: constant Name_Id
:= Chars
(N
);
1887 Expr
: constant Node_Id
:= Expression
(N
);
1888 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Attr
);
1891 -- The entity of Nam after it is analyzed. In the case of an incomplete
1892 -- type, this is the underlying type.
1895 -- The underlying entity to which the attribute applies. Generally this
1896 -- is the Underlying_Type of Ent, except in the case where the clause
1897 -- applies to full view of incomplete type or private type in which case
1898 -- U_Ent is just a copy of Ent.
1900 FOnly
: Boolean := False;
1901 -- Reset to True for subtype specific attribute (Alignment, Size)
1902 -- and for stream attributes, i.e. those cases where in the call
1903 -- to Rep_Item_Too_Late, FOnly is set True so that only the freezing
1904 -- rules are checked. Note that the case of stream attributes is not
1905 -- clear from the RM, but see AI95-00137. Also, the RM seems to
1906 -- disallow Storage_Size for derived task types, but that is also
1907 -- clearly unintentional.
1909 procedure Analyze_Stream_TSS_Definition
(TSS_Nam
: TSS_Name_Type
);
1910 -- Common processing for 'Read, 'Write, 'Input and 'Output attribute
1911 -- definition clauses.
1913 function Duplicate_Clause
return Boolean;
1914 -- This routine checks if the aspect for U_Ent being given by attribute
1915 -- definition clause N is for an aspect that has already been specified,
1916 -- and if so gives an error message. If there is a duplicate, True is
1917 -- returned, otherwise if there is no error, False is returned.
1919 procedure Check_Indexing_Functions
;
1920 -- Check that the function in Constant_Indexing or Variable_Indexing
1921 -- attribute has the proper type structure. If the name is overloaded,
1922 -- check that all interpretations are legal.
1924 procedure Check_Iterator_Functions
;
1925 -- Check that there is a single function in Default_Iterator attribute
1926 -- has the proper type structure.
1928 function Check_Primitive_Function
(Subp
: Entity_Id
) return Boolean;
1929 -- Common legality check for the previous two
1931 -----------------------------------
1932 -- Analyze_Stream_TSS_Definition --
1933 -----------------------------------
1935 procedure Analyze_Stream_TSS_Definition
(TSS_Nam
: TSS_Name_Type
) is
1936 Subp
: Entity_Id
:= Empty
;
1941 Is_Read
: constant Boolean := (TSS_Nam
= TSS_Stream_Read
);
1942 -- True for Read attribute, false for other attributes
1944 function Has_Good_Profile
(Subp
: Entity_Id
) return Boolean;
1945 -- Return true if the entity is a subprogram with an appropriate
1946 -- profile for the attribute being defined.
1948 ----------------------
1949 -- Has_Good_Profile --
1950 ----------------------
1952 function Has_Good_Profile
(Subp
: Entity_Id
) return Boolean is
1954 Is_Function
: constant Boolean := (TSS_Nam
= TSS_Stream_Input
);
1955 Expected_Ekind
: constant array (Boolean) of Entity_Kind
:=
1956 (False => E_Procedure
, True => E_Function
);
1960 if Ekind
(Subp
) /= Expected_Ekind
(Is_Function
) then
1964 F
:= First_Formal
(Subp
);
1967 or else Ekind
(Etype
(F
)) /= E_Anonymous_Access_Type
1968 or else Designated_Type
(Etype
(F
)) /=
1969 Class_Wide_Type
(RTE
(RE_Root_Stream_Type
))
1974 if not Is_Function
then
1978 Expected_Mode
: constant array (Boolean) of Entity_Kind
:=
1979 (False => E_In_Parameter
,
1980 True => E_Out_Parameter
);
1982 if Parameter_Mode
(F
) /= Expected_Mode
(Is_Read
) then
1990 Typ
:= Etype
(Subp
);
1993 return Base_Type
(Typ
) = Base_Type
(Ent
)
1994 and then No
(Next_Formal
(F
));
1995 end Has_Good_Profile
;
1997 -- Start of processing for Analyze_Stream_TSS_Definition
2002 if not Is_Type
(U_Ent
) then
2003 Error_Msg_N
("local name must be a subtype", Nam
);
2007 Pnam
:= TSS
(Base_Type
(U_Ent
), TSS_Nam
);
2009 -- If Pnam is present, it can be either inherited from an ancestor
2010 -- type (in which case it is legal to redefine it for this type), or
2011 -- be a previous definition of the attribute for the same type (in
2012 -- which case it is illegal).
2014 -- In the first case, it will have been analyzed already, and we
2015 -- can check that its profile does not match the expected profile
2016 -- for a stream attribute of U_Ent. In the second case, either Pnam
2017 -- has been analyzed (and has the expected profile), or it has not
2018 -- been analyzed yet (case of a type that has not been frozen yet
2019 -- and for which the stream attribute has been set using Set_TSS).
2022 and then (No
(First_Entity
(Pnam
)) or else Has_Good_Profile
(Pnam
))
2024 Error_Msg_Sloc
:= Sloc
(Pnam
);
2025 Error_Msg_Name_1
:= Attr
;
2026 Error_Msg_N
("% attribute already defined #", Nam
);
2032 if Is_Entity_Name
(Expr
) then
2033 if not Is_Overloaded
(Expr
) then
2034 if Has_Good_Profile
(Entity
(Expr
)) then
2035 Subp
:= Entity
(Expr
);
2039 Get_First_Interp
(Expr
, I
, It
);
2040 while Present
(It
.Nam
) loop
2041 if Has_Good_Profile
(It
.Nam
) then
2046 Get_Next_Interp
(I
, It
);
2051 if Present
(Subp
) then
2052 if Is_Abstract_Subprogram
(Subp
) then
2053 Error_Msg_N
("stream subprogram must not be abstract", Expr
);
2057 Set_Entity
(Expr
, Subp
);
2058 Set_Etype
(Expr
, Etype
(Subp
));
2060 New_Stream_Subprogram
(N
, U_Ent
, Subp
, TSS_Nam
);
2063 Error_Msg_Name_1
:= Attr
;
2064 Error_Msg_N
("incorrect expression for% attribute", Expr
);
2066 end Analyze_Stream_TSS_Definition
;
2068 ------------------------------
2069 -- Check_Indexing_Functions --
2070 ------------------------------
2072 procedure Check_Indexing_Functions
is
2074 procedure Check_One_Function
(Subp
: Entity_Id
);
2075 -- Check one possible interpretation
2077 ------------------------
2078 -- Check_One_Function --
2079 ------------------------
2081 procedure Check_One_Function
(Subp
: Entity_Id
) is
2082 Default_Element
: constant Node_Id
:=
2084 (Etype
(First_Formal
(Subp
)),
2085 Aspect_Iterator_Element
);
2088 if not Check_Primitive_Function
(Subp
) then
2090 ("aspect Indexing requires a function that applies to type&",
2094 -- An indexing function must return either the default element of
2095 -- the container, or a reference type.
2097 if Present
(Default_Element
) then
2098 Analyze
(Default_Element
);
2099 if Is_Entity_Name
(Default_Element
)
2100 and then Covers
(Entity
(Default_Element
), Etype
(Subp
))
2106 -- Otherwise the return type must be a reference type.
2108 if not Has_Implicit_Dereference
(Etype
(Subp
)) then
2110 ("function for indexing must return a reference type", Subp
);
2112 end Check_One_Function
;
2114 -- Start of processing for Check_Indexing_Functions
2123 if not Is_Overloaded
(Expr
) then
2124 Check_One_Function
(Entity
(Expr
));
2132 Get_First_Interp
(Expr
, I
, It
);
2133 while Present
(It
.Nam
) loop
2135 -- Note that analysis will have added the interpretation
2136 -- that corresponds to the dereference. We only check the
2137 -- subprogram itself.
2139 if Is_Overloadable
(It
.Nam
) then
2140 Check_One_Function
(It
.Nam
);
2143 Get_Next_Interp
(I
, It
);
2147 end Check_Indexing_Functions
;
2149 ------------------------------
2150 -- Check_Iterator_Functions --
2151 ------------------------------
2153 procedure Check_Iterator_Functions
is
2154 Default
: Entity_Id
;
2156 function Valid_Default_Iterator
(Subp
: Entity_Id
) return Boolean;
2157 -- Check one possible interpretation for validity
2159 ----------------------------
2160 -- Valid_Default_Iterator --
2161 ----------------------------
2163 function Valid_Default_Iterator
(Subp
: Entity_Id
) return Boolean is
2167 if not Check_Primitive_Function
(Subp
) then
2170 Formal
:= First_Formal
(Subp
);
2173 -- False if any subsequent formal has no default expression
2175 Formal
:= Next_Formal
(Formal
);
2176 while Present
(Formal
) loop
2177 if No
(Expression
(Parent
(Formal
))) then
2181 Next_Formal
(Formal
);
2184 -- True if all subsequent formals have default expressions
2187 end Valid_Default_Iterator
;
2189 -- Start of processing for Check_Iterator_Functions
2194 if not Is_Entity_Name
(Expr
) then
2195 Error_Msg_N
("aspect Iterator must be a function name", Expr
);
2198 if not Is_Overloaded
(Expr
) then
2199 if not Check_Primitive_Function
(Entity
(Expr
)) then
2201 ("aspect Indexing requires a function that applies to type&",
2202 Entity
(Expr
), Ent
);
2205 if not Valid_Default_Iterator
(Entity
(Expr
)) then
2206 Error_Msg_N
("improper function for default iterator", Expr
);
2216 Get_First_Interp
(Expr
, I
, It
);
2217 while Present
(It
.Nam
) loop
2218 if not Check_Primitive_Function
(It
.Nam
)
2219 or else not Valid_Default_Iterator
(It
.Nam
)
2223 elsif Present
(Default
) then
2224 Error_Msg_N
("default iterator must be unique", Expr
);
2230 Get_Next_Interp
(I
, It
);
2234 if Present
(Default
) then
2235 Set_Entity
(Expr
, Default
);
2236 Set_Is_Overloaded
(Expr
, False);
2239 end Check_Iterator_Functions
;
2241 -------------------------------
2242 -- Check_Primitive_Function --
2243 -------------------------------
2245 function Check_Primitive_Function
(Subp
: Entity_Id
) return Boolean is
2249 if Ekind
(Subp
) /= E_Function
then
2253 if No
(First_Formal
(Subp
)) then
2256 Ctrl
:= Etype
(First_Formal
(Subp
));
2260 or else Ctrl
= Class_Wide_Type
(Ent
)
2262 (Ekind
(Ctrl
) = E_Anonymous_Access_Type
2264 (Designated_Type
(Ctrl
) = Ent
2265 or else Designated_Type
(Ctrl
) = Class_Wide_Type
(Ent
)))
2274 end Check_Primitive_Function
;
2276 ----------------------
2277 -- Duplicate_Clause --
2278 ----------------------
2280 function Duplicate_Clause
return Boolean is
2284 -- Nothing to do if this attribute definition clause comes from
2285 -- an aspect specification, since we could not be duplicating an
2286 -- explicit clause, and we dealt with the case of duplicated aspects
2287 -- in Analyze_Aspect_Specifications.
2289 if From_Aspect_Specification
(N
) then
2293 -- Otherwise current clause may duplicate previous clause, or a
2294 -- previously given pragma or aspect specification for the same
2297 A
:= Get_Rep_Item
(U_Ent
, Chars
(N
), Check_Parents
=> False);
2300 Error_Msg_Name_1
:= Chars
(N
);
2301 Error_Msg_Sloc
:= Sloc
(A
);
2303 Error_Msg_NE
("aspect% for & previously given#", N
, U_Ent
);
2308 end Duplicate_Clause
;
2310 -- Start of processing for Analyze_Attribute_Definition_Clause
2313 -- The following code is a defense against recursion. Not clear that
2314 -- this can happen legitimately, but perhaps some error situations
2315 -- can cause it, and we did see this recursion during testing.
2317 if Analyzed
(N
) then
2320 Set_Analyzed
(N
, True);
2323 -- Ignore some selected attributes in CodePeer mode since they are not
2324 -- relevant in this context.
2326 if CodePeer_Mode
then
2329 -- Ignore Component_Size in CodePeer mode, to avoid changing the
2330 -- internal representation of types by implicitly packing them.
2332 when Attribute_Component_Size
=>
2333 Rewrite
(N
, Make_Null_Statement
(Sloc
(N
)));
2341 -- Process Ignore_Rep_Clauses option
2343 if Ignore_Rep_Clauses
then
2346 -- The following should be ignored. They do not affect legality
2347 -- and may be target dependent. The basic idea of -gnatI is to
2348 -- ignore any rep clauses that may be target dependent but do not
2349 -- affect legality (except possibly to be rejected because they
2350 -- are incompatible with the compilation target).
2352 when Attribute_Alignment |
2353 Attribute_Bit_Order |
2354 Attribute_Component_Size |
2355 Attribute_Machine_Radix |
2356 Attribute_Object_Size |
2358 Attribute_Stream_Size |
2359 Attribute_Value_Size
=>
2360 Rewrite
(N
, Make_Null_Statement
(Sloc
(N
)));
2363 -- Perhaps 'Small should not be ignored by Ignore_Rep_Clauses ???
2365 when Attribute_Small
=>
2366 if Ignore_Rep_Clauses
then
2367 Rewrite
(N
, Make_Null_Statement
(Sloc
(N
)));
2371 -- The following should not be ignored, because in the first place
2372 -- they are reasonably portable, and should not cause problems in
2373 -- compiling code from another target, and also they do affect
2374 -- legality, e.g. failing to provide a stream attribute for a
2375 -- type may make a program illegal.
2377 when Attribute_External_Tag |
2381 Attribute_Simple_Storage_Pool |
2382 Attribute_Storage_Pool |
2383 Attribute_Storage_Size |
2387 -- Other cases are errors ("attribute& cannot be set with
2388 -- definition clause"), which will be caught below.
2396 Ent
:= Entity
(Nam
);
2398 if Rep_Item_Too_Early
(Ent
, N
) then
2402 -- Rep clause applies to full view of incomplete type or private type if
2403 -- we have one (if not, this is a premature use of the type). However,
2404 -- certain semantic checks need to be done on the specified entity (i.e.
2405 -- the private view), so we save it in Ent.
2407 if Is_Private_Type
(Ent
)
2408 and then Is_Derived_Type
(Ent
)
2409 and then not Is_Tagged_Type
(Ent
)
2410 and then No
(Full_View
(Ent
))
2412 -- If this is a private type whose completion is a derivation from
2413 -- another private type, there is no full view, and the attribute
2414 -- belongs to the type itself, not its underlying parent.
2418 elsif Ekind
(Ent
) = E_Incomplete_Type
then
2420 -- The attribute applies to the full view, set the entity of the
2421 -- attribute definition accordingly.
2423 Ent
:= Underlying_Type
(Ent
);
2425 Set_Entity
(Nam
, Ent
);
2428 U_Ent
:= Underlying_Type
(Ent
);
2431 -- Avoid cascaded error
2433 if Etype
(Nam
) = Any_Type
then
2436 -- Must be declared in current scope or in case of an aspect
2437 -- specification, must be visible in current scope.
2439 elsif Scope
(Ent
) /= Current_Scope
2441 not (From_Aspect_Specification
(N
)
2442 and then Scope_Within_Or_Same
(Current_Scope
, Scope
(Ent
)))
2444 Error_Msg_N
("entity must be declared in this scope", Nam
);
2447 -- Must not be a source renaming (we do have some cases where the
2448 -- expander generates a renaming, and those cases are OK, in such
2449 -- cases any attribute applies to the renamed object as well).
2451 elsif Is_Object
(Ent
)
2452 and then Present
(Renamed_Object
(Ent
))
2454 -- Case of renamed object from source, this is an error
2456 if Comes_From_Source
(Renamed_Object
(Ent
)) then
2457 Get_Name_String
(Chars
(N
));
2458 Error_Msg_Strlen
:= Name_Len
;
2459 Error_Msg_String
(1 .. Name_Len
) := Name_Buffer
(1 .. Name_Len
);
2461 ("~ clause not allowed for a renaming declaration "
2462 & "(RM 13.1(6))", Nam
);
2465 -- For the case of a compiler generated renaming, the attribute
2466 -- definition clause applies to the renamed object created by the
2467 -- expander. The easiest general way to handle this is to create a
2468 -- copy of the attribute definition clause for this object.
2472 Make_Attribute_Definition_Clause
(Loc
,
2474 New_Occurrence_Of
(Entity
(Renamed_Object
(Ent
)), Loc
),
2476 Expression
=> Duplicate_Subexpr
(Expression
(N
))));
2479 -- If no underlying entity, use entity itself, applies to some
2480 -- previously detected error cases ???
2482 elsif No
(U_Ent
) then
2485 -- Cannot specify for a subtype (exception Object/Value_Size)
2487 elsif Is_Type
(U_Ent
)
2488 and then not Is_First_Subtype
(U_Ent
)
2489 and then Id
/= Attribute_Object_Size
2490 and then Id
/= Attribute_Value_Size
2491 and then not From_At_Mod
(N
)
2493 Error_Msg_N
("cannot specify attribute for subtype", Nam
);
2497 Set_Entity
(N
, U_Ent
);
2499 -- Switch on particular attribute
2507 -- Address attribute definition clause
2509 when Attribute_Address
=> Address
: begin
2511 -- A little error check, catch for X'Address use X'Address;
2513 if Nkind
(Nam
) = N_Identifier
2514 and then Nkind
(Expr
) = N_Attribute_Reference
2515 and then Attribute_Name
(Expr
) = Name_Address
2516 and then Nkind
(Prefix
(Expr
)) = N_Identifier
2517 and then Chars
(Nam
) = Chars
(Prefix
(Expr
))
2520 ("address for & is self-referencing", Prefix
(Expr
), Ent
);
2524 -- Not that special case, carry on with analysis of expression
2526 Analyze_And_Resolve
(Expr
, RTE
(RE_Address
));
2528 -- Even when ignoring rep clauses we need to indicate that the
2529 -- entity has an address clause and thus it is legal to declare
2532 if Ignore_Rep_Clauses
then
2533 if Ekind_In
(U_Ent
, E_Variable
, E_Constant
) then
2534 Record_Rep_Item
(U_Ent
, N
);
2540 if Duplicate_Clause
then
2543 -- Case of address clause for subprogram
2545 elsif Is_Subprogram
(U_Ent
) then
2546 if Has_Homonym
(U_Ent
) then
2548 ("address clause cannot be given " &
2549 "for overloaded subprogram",
2554 -- For subprograms, all address clauses are permitted, and we
2555 -- mark the subprogram as having a deferred freeze so that Gigi
2556 -- will not elaborate it too soon.
2558 -- Above needs more comments, what is too soon about???
2560 Set_Has_Delayed_Freeze
(U_Ent
);
2562 -- Case of address clause for entry
2564 elsif Ekind
(U_Ent
) = E_Entry
then
2565 if Nkind
(Parent
(N
)) = N_Task_Body
then
2567 ("entry address must be specified in task spec", Nam
);
2571 -- For entries, we require a constant address
2573 Check_Constant_Address_Clause
(Expr
, U_Ent
);
2575 -- Special checks for task types
2577 if Is_Task_Type
(Scope
(U_Ent
))
2578 and then Comes_From_Source
(Scope
(U_Ent
))
2581 ("?entry address declared for entry in task type", N
);
2583 ("\?only one task can be declared of this type", N
);
2586 -- Entry address clauses are obsolescent
2588 Check_Restriction
(No_Obsolescent_Features
, N
);
2590 if Warn_On_Obsolescent_Feature
then
2592 ("attaching interrupt to task entry is an " &
2593 "obsolescent feature (RM J.7.1)?", N
);
2595 ("\use interrupt procedure instead?", N
);
2598 -- Case of an address clause for a controlled object which we
2599 -- consider to be erroneous.
2601 elsif Is_Controlled
(Etype
(U_Ent
))
2602 or else Has_Controlled_Component
(Etype
(U_Ent
))
2605 ("?controlled object& must not be overlaid", Nam
, U_Ent
);
2607 ("\?Program_Error will be raised at run time", Nam
);
2608 Insert_Action
(Declaration_Node
(U_Ent
),
2609 Make_Raise_Program_Error
(Loc
,
2610 Reason
=> PE_Overlaid_Controlled_Object
));
2613 -- Case of address clause for a (non-controlled) object
2616 Ekind
(U_Ent
) = E_Variable
2618 Ekind
(U_Ent
) = E_Constant
2621 Expr
: constant Node_Id
:= Expression
(N
);
2626 -- Exported variables cannot have an address clause, because
2627 -- this cancels the effect of the pragma Export.
2629 if Is_Exported
(U_Ent
) then
2631 ("cannot export object with address clause", Nam
);
2635 Find_Overlaid_Entity
(N
, O_Ent
, Off
);
2637 -- Overlaying controlled objects is erroneous
2640 and then (Has_Controlled_Component
(Etype
(O_Ent
))
2641 or else Is_Controlled
(Etype
(O_Ent
)))
2644 ("?cannot overlay with controlled object", Expr
);
2646 ("\?Program_Error will be raised at run time", Expr
);
2647 Insert_Action
(Declaration_Node
(U_Ent
),
2648 Make_Raise_Program_Error
(Loc
,
2649 Reason
=> PE_Overlaid_Controlled_Object
));
2652 elsif Present
(O_Ent
)
2653 and then Ekind
(U_Ent
) = E_Constant
2654 and then not Is_Constant_Object
(O_Ent
)
2656 Error_Msg_N
("constant overlays a variable?", Expr
);
2658 -- Imported variables can have an address clause, but then
2659 -- the import is pretty meaningless except to suppress
2660 -- initializations, so we do not need such variables to
2661 -- be statically allocated (and in fact it causes trouble
2662 -- if the address clause is a local value).
2664 elsif Is_Imported
(U_Ent
) then
2665 Set_Is_Statically_Allocated
(U_Ent
, False);
2668 -- We mark a possible modification of a variable with an
2669 -- address clause, since it is likely aliasing is occurring.
2671 Note_Possible_Modification
(Nam
, Sure
=> False);
2673 -- Here we are checking for explicit overlap of one variable
2674 -- by another, and if we find this then mark the overlapped
2675 -- variable as also being volatile to prevent unwanted
2676 -- optimizations. This is a significant pessimization so
2677 -- avoid it when there is an offset, i.e. when the object
2678 -- is composite; they cannot be optimized easily anyway.
2681 and then Is_Object
(O_Ent
)
2684 Set_Treat_As_Volatile
(O_Ent
);
2687 -- Legality checks on the address clause for initialized
2688 -- objects is deferred until the freeze point, because
2689 -- a subsequent pragma might indicate that the object
2690 -- is imported and thus not initialized.
2692 Set_Has_Delayed_Freeze
(U_Ent
);
2694 -- If an initialization call has been generated for this
2695 -- object, it needs to be deferred to after the freeze node
2696 -- we have just now added, otherwise GIGI will see a
2697 -- reference to the variable (as actual to the IP call)
2698 -- before its definition.
2701 Init_Call
: constant Node_Id
:= Find_Init_Call
(U_Ent
, N
);
2703 if Present
(Init_Call
) then
2705 Append_Freeze_Action
(U_Ent
, Init_Call
);
2709 if Is_Exported
(U_Ent
) then
2711 ("& cannot be exported if an address clause is given",
2714 ("\define and export a variable " &
2715 "that holds its address instead",
2719 -- Entity has delayed freeze, so we will generate an
2720 -- alignment check at the freeze point unless suppressed.
2722 if not Range_Checks_Suppressed
(U_Ent
)
2723 and then not Alignment_Checks_Suppressed
(U_Ent
)
2725 Set_Check_Address_Alignment
(N
);
2728 -- Kill the size check code, since we are not allocating
2729 -- the variable, it is somewhere else.
2731 Kill_Size_Check_Code
(U_Ent
);
2733 -- If the address clause is of the form:
2735 -- for Y'Address use X'Address
2739 -- Const : constant Address := X'Address;
2741 -- for Y'Address use Const;
2743 -- then we make an entry in the table for checking the size
2744 -- and alignment of the overlaying variable. We defer this
2745 -- check till after code generation to take full advantage
2746 -- of the annotation done by the back end. This entry is
2747 -- only made if the address clause comes from source.
2749 -- If the entity has a generic type, the check will be
2750 -- performed in the instance if the actual type justifies
2751 -- it, and we do not insert the clause in the table to
2752 -- prevent spurious warnings.
2754 if Address_Clause_Overlay_Warnings
2755 and then Comes_From_Source
(N
)
2756 and then Present
(O_Ent
)
2757 and then Is_Object
(O_Ent
)
2759 if not Is_Generic_Type
(Etype
(U_Ent
)) then
2760 Address_Clause_Checks
.Append
((N
, U_Ent
, O_Ent
, Off
));
2763 -- If variable overlays a constant view, and we are
2764 -- warning on overlays, then mark the variable as
2765 -- overlaying a constant (we will give warnings later
2766 -- if this variable is assigned).
2768 if Is_Constant_Object
(O_Ent
)
2769 and then Ekind
(U_Ent
) = E_Variable
2771 Set_Overlays_Constant
(U_Ent
);
2776 -- Not a valid entity for an address clause
2779 Error_Msg_N
("address cannot be given for &", Nam
);
2787 -- Alignment attribute definition clause
2789 when Attribute_Alignment
=> Alignment
: declare
2790 Align
: constant Uint
:= Get_Alignment_Value
(Expr
);
2791 Max_Align
: constant Uint
:= UI_From_Int
(Maximum_Alignment
);
2796 if not Is_Type
(U_Ent
)
2797 and then Ekind
(U_Ent
) /= E_Variable
2798 and then Ekind
(U_Ent
) /= E_Constant
2800 Error_Msg_N
("alignment cannot be given for &", Nam
);
2802 elsif Duplicate_Clause
then
2805 elsif Align
/= No_Uint
then
2806 Set_Has_Alignment_Clause
(U_Ent
);
2808 -- Tagged type case, check for attempt to set alignment to a
2809 -- value greater than Max_Align, and reset if so.
2811 if Is_Tagged_Type
(U_Ent
) and then Align
> Max_Align
then
2813 ("?alignment for & set to Maximum_Aligment", Nam
);
2814 Set_Alignment
(U_Ent
, Max_Align
);
2819 Set_Alignment
(U_Ent
, Align
);
2822 -- For an array type, U_Ent is the first subtype. In that case,
2823 -- also set the alignment of the anonymous base type so that
2824 -- other subtypes (such as the itypes for aggregates of the
2825 -- type) also receive the expected alignment.
2827 if Is_Array_Type
(U_Ent
) then
2828 Set_Alignment
(Base_Type
(U_Ent
), Align
);
2837 -- Bit_Order attribute definition clause
2839 when Attribute_Bit_Order
=> Bit_Order
: declare
2841 if not Is_Record_Type
(U_Ent
) then
2843 ("Bit_Order can only be defined for record type", Nam
);
2845 elsif Duplicate_Clause
then
2849 Analyze_And_Resolve
(Expr
, RTE
(RE_Bit_Order
));
2851 if Etype
(Expr
) = Any_Type
then
2854 elsif not Is_Static_Expression
(Expr
) then
2855 Flag_Non_Static_Expr
2856 ("Bit_Order requires static expression!", Expr
);
2859 if (Expr_Value
(Expr
) = 0) /= Bytes_Big_Endian
then
2860 Set_Reverse_Bit_Order
(U_Ent
, True);
2866 --------------------
2867 -- Component_Size --
2868 --------------------
2870 -- Component_Size attribute definition clause
2872 when Attribute_Component_Size
=> Component_Size_Case
: declare
2873 Csize
: constant Uint
:= Static_Integer
(Expr
);
2877 New_Ctyp
: Entity_Id
;
2881 if not Is_Array_Type
(U_Ent
) then
2882 Error_Msg_N
("component size requires array type", Nam
);
2886 Btype
:= Base_Type
(U_Ent
);
2887 Ctyp
:= Component_Type
(Btype
);
2889 if Duplicate_Clause
then
2892 elsif Rep_Item_Too_Early
(Btype
, N
) then
2895 elsif Csize
/= No_Uint
then
2896 Check_Size
(Expr
, Ctyp
, Csize
, Biased
);
2898 -- For the biased case, build a declaration for a subtype that
2899 -- will be used to represent the biased subtype that reflects
2900 -- the biased representation of components. We need the subtype
2901 -- to get proper conversions on referencing elements of the
2902 -- array. Note: component size clauses are ignored in VM mode.
2904 if VM_Target
= No_VM
then
2907 Make_Defining_Identifier
(Loc
,
2909 New_External_Name
(Chars
(U_Ent
), 'C', 0, 'T'));
2912 Make_Subtype_Declaration
(Loc
,
2913 Defining_Identifier
=> New_Ctyp
,
2914 Subtype_Indication
=>
2915 New_Occurrence_Of
(Component_Type
(Btype
), Loc
));
2917 Set_Parent
(Decl
, N
);
2918 Analyze
(Decl
, Suppress
=> All_Checks
);
2920 Set_Has_Delayed_Freeze
(New_Ctyp
, False);
2921 Set_Esize
(New_Ctyp
, Csize
);
2922 Set_RM_Size
(New_Ctyp
, Csize
);
2923 Init_Alignment
(New_Ctyp
);
2924 Set_Is_Itype
(New_Ctyp
, True);
2925 Set_Associated_Node_For_Itype
(New_Ctyp
, U_Ent
);
2927 Set_Component_Type
(Btype
, New_Ctyp
);
2928 Set_Biased
(New_Ctyp
, N
, "component size clause");
2931 Set_Component_Size
(Btype
, Csize
);
2933 -- For VM case, we ignore component size clauses
2936 -- Give a warning unless we are in GNAT mode, in which case
2937 -- the warning is suppressed since it is not useful.
2939 if not GNAT_Mode
then
2941 ("?component size ignored in this configuration", N
);
2945 -- Deal with warning on overridden size
2947 if Warn_On_Overridden_Size
2948 and then Has_Size_Clause
(Ctyp
)
2949 and then RM_Size
(Ctyp
) /= Csize
2952 ("?component size overrides size clause for&",
2956 Set_Has_Component_Size_Clause
(Btype
, True);
2957 Set_Has_Non_Standard_Rep
(Btype
, True);
2959 end Component_Size_Case
;
2961 -----------------------
2962 -- Constant_Indexing --
2963 -----------------------
2965 when Attribute_Constant_Indexing
=>
2966 Check_Indexing_Functions
;
2972 when Attribute_CPU
=> CPU
:
2974 -- CPU attribute definition clause not allowed except from aspect
2977 if From_Aspect_Specification
(N
) then
2978 if not Is_Task_Type
(U_Ent
) then
2979 Error_Msg_N
("CPU can only be defined for task", Nam
);
2981 elsif Duplicate_Clause
then
2985 -- The expression must be analyzed in the special manner
2986 -- described in "Handling of Default and Per-Object
2987 -- Expressions" in sem.ads.
2989 -- The visibility to the discriminants must be restored
2991 Push_Scope_And_Install_Discriminants
(U_Ent
);
2992 Preanalyze_Spec_Expression
(Expr
, RTE
(RE_CPU_Range
));
2993 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
2995 if not Is_Static_Expression
(Expr
) then
2996 Check_Restriction
(Static_Priorities
, Expr
);
3002 ("attribute& cannot be set with definition clause", N
);
3006 ----------------------
3007 -- Default_Iterator --
3008 ----------------------
3010 when Attribute_Default_Iterator
=> Default_Iterator
: declare
3014 if not Is_Tagged_Type
(U_Ent
) then
3016 ("aspect Default_Iterator applies to tagged type", Nam
);
3019 Check_Iterator_Functions
;
3023 if not Is_Entity_Name
(Expr
)
3024 or else Ekind
(Entity
(Expr
)) /= E_Function
3026 Error_Msg_N
("aspect Iterator must be a function", Expr
);
3028 Func
:= Entity
(Expr
);
3031 if No
(First_Formal
(Func
))
3032 or else Etype
(First_Formal
(Func
)) /= U_Ent
3035 ("Default Iterator must be a primitive of&", Func
, U_Ent
);
3037 end Default_Iterator
;
3039 ------------------------
3040 -- Dispatching_Domain --
3041 ------------------------
3043 when Attribute_Dispatching_Domain
=> Dispatching_Domain
:
3045 -- Dispatching_Domain attribute definition clause not allowed
3046 -- except from aspect specification.
3048 if From_Aspect_Specification
(N
) then
3049 if not Is_Task_Type
(U_Ent
) then
3050 Error_Msg_N
("Dispatching_Domain can only be defined" &
3054 elsif Duplicate_Clause
then
3058 -- The expression must be analyzed in the special manner
3059 -- described in "Handling of Default and Per-Object
3060 -- Expressions" in sem.ads.
3062 -- The visibility to the discriminants must be restored
3064 Push_Scope_And_Install_Discriminants
(U_Ent
);
3066 Preanalyze_Spec_Expression
3067 (Expr
, RTE
(RE_Dispatching_Domain
));
3069 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
3074 ("attribute& cannot be set with definition clause", N
);
3076 end Dispatching_Domain
;
3082 when Attribute_External_Tag
=> External_Tag
:
3084 if not Is_Tagged_Type
(U_Ent
) then
3085 Error_Msg_N
("should be a tagged type", Nam
);
3088 if Duplicate_Clause
then
3092 Analyze_And_Resolve
(Expr
, Standard_String
);
3094 if not Is_Static_Expression
(Expr
) then
3095 Flag_Non_Static_Expr
3096 ("static string required for tag name!", Nam
);
3099 if VM_Target
= No_VM
then
3100 Set_Has_External_Tag_Rep_Clause
(U_Ent
);
3102 Error_Msg_Name_1
:= Attr
;
3104 ("% attribute unsupported in this configuration", Nam
);
3107 if not Is_Library_Level_Entity
(U_Ent
) then
3109 ("?non-unique external tag supplied for &", N
, U_Ent
);
3111 ("?\same external tag applies to all subprogram calls", N
);
3113 ("?\corresponding internal tag cannot be obtained", N
);
3118 --------------------------
3119 -- Implicit_Dereference --
3120 --------------------------
3122 when Attribute_Implicit_Dereference
=>
3124 -- Legality checks already performed at the point of the type
3125 -- declaration, aspect is not delayed.
3133 when Attribute_Input
=>
3134 Analyze_Stream_TSS_Definition
(TSS_Stream_Input
);
3135 Set_Has_Specified_Stream_Input
(Ent
);
3137 ------------------------
3138 -- Interrupt_Priority --
3139 ------------------------
3141 when Attribute_Interrupt_Priority
=> Interrupt_Priority
:
3143 -- Interrupt_Priority attribute definition clause not allowed
3144 -- except from aspect specification.
3146 if From_Aspect_Specification
(N
) then
3147 if not (Is_Protected_Type
(U_Ent
)
3148 or else Is_Task_Type
(U_Ent
))
3151 ("Interrupt_Priority can only be defined for task" &
3152 "and protected object",
3155 elsif Duplicate_Clause
then
3159 -- The expression must be analyzed in the special manner
3160 -- described in "Handling of Default and Per-Object
3161 -- Expressions" in sem.ads.
3163 -- The visibility to the discriminants must be restored
3165 Push_Scope_And_Install_Discriminants
(U_Ent
);
3167 Preanalyze_Spec_Expression
3168 (Expr
, RTE
(RE_Interrupt_Priority
));
3170 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
3175 ("attribute& cannot be set with definition clause", N
);
3177 end Interrupt_Priority
;
3179 ----------------------
3180 -- Iterator_Element --
3181 ----------------------
3183 when Attribute_Iterator_Element
=>
3186 if not Is_Entity_Name
(Expr
)
3187 or else not Is_Type
(Entity
(Expr
))
3189 Error_Msg_N
("aspect Iterator_Element must be a type", Expr
);
3196 -- Machine radix attribute definition clause
3198 when Attribute_Machine_Radix
=> Machine_Radix
: declare
3199 Radix
: constant Uint
:= Static_Integer
(Expr
);
3202 if not Is_Decimal_Fixed_Point_Type
(U_Ent
) then
3203 Error_Msg_N
("decimal fixed-point type expected for &", Nam
);
3205 elsif Duplicate_Clause
then
3208 elsif Radix
/= No_Uint
then
3209 Set_Has_Machine_Radix_Clause
(U_Ent
);
3210 Set_Has_Non_Standard_Rep
(Base_Type
(U_Ent
));
3214 elsif Radix
= 10 then
3215 Set_Machine_Radix_10
(U_Ent
);
3217 Error_Msg_N
("machine radix value must be 2 or 10", Expr
);
3226 -- Object_Size attribute definition clause
3228 when Attribute_Object_Size
=> Object_Size
: declare
3229 Size
: constant Uint
:= Static_Integer
(Expr
);
3232 pragma Warnings
(Off
, Biased
);
3235 if not Is_Type
(U_Ent
) then
3236 Error_Msg_N
("Object_Size cannot be given for &", Nam
);
3238 elsif Duplicate_Clause
then
3242 Check_Size
(Expr
, U_Ent
, Size
, Biased
);
3250 UI_Mod
(Size
, 64) /= 0
3253 ("Object_Size must be 8, 16, 32, or multiple of 64",
3257 Set_Esize
(U_Ent
, Size
);
3258 Set_Has_Object_Size_Clause
(U_Ent
);
3259 Alignment_Check_For_Size_Change
(U_Ent
, Size
);
3267 when Attribute_Output
=>
3268 Analyze_Stream_TSS_Definition
(TSS_Stream_Output
);
3269 Set_Has_Specified_Stream_Output
(Ent
);
3275 when Attribute_Priority
=> Priority
:
3277 -- Priority attribute definition clause not allowed except from
3278 -- aspect specification.
3280 if From_Aspect_Specification
(N
) then
3281 if not (Is_Protected_Type
(U_Ent
)
3282 or else Is_Task_Type
(U_Ent
)
3283 or else Ekind
(U_Ent
) = E_Procedure
)
3286 ("Priority can only be defined for task and protected " &
3290 elsif Duplicate_Clause
then
3294 -- The expression must be analyzed in the special manner
3295 -- described in "Handling of Default and Per-Object
3296 -- Expressions" in sem.ads.
3298 -- The visibility to the discriminants must be restored
3300 Push_Scope_And_Install_Discriminants
(U_Ent
);
3301 Preanalyze_Spec_Expression
(Expr
, Standard_Integer
);
3302 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
3304 if not Is_Static_Expression
(Expr
) then
3305 Check_Restriction
(Static_Priorities
, Expr
);
3311 ("attribute& cannot be set with definition clause", N
);
3319 when Attribute_Read
=>
3320 Analyze_Stream_TSS_Definition
(TSS_Stream_Read
);
3321 Set_Has_Specified_Stream_Read
(Ent
);
3323 --------------------------
3324 -- Scalar_Storage_Order --
3325 --------------------------
3327 -- Scalar_Storage_Order attribute definition clause
3329 when Attribute_Scalar_Storage_Order
=> Scalar_Storage_Order
: declare
3331 if not (Is_Record_Type
(U_Ent
) or else Is_Array_Type
(U_Ent
)) then
3333 ("Scalar_Storage_Order can only be defined for "
3334 & "record or array type", Nam
);
3336 elsif Duplicate_Clause
then
3340 Analyze_And_Resolve
(Expr
, RTE
(RE_Bit_Order
));
3342 if Etype
(Expr
) = Any_Type
then
3345 elsif not Is_Static_Expression
(Expr
) then
3346 Flag_Non_Static_Expr
3347 ("Scalar_Storage_Order requires static expression!", Expr
);
3350 if (Expr_Value
(Expr
) = 0) /= Bytes_Big_Endian
then
3351 Set_Reverse_Storage_Order
(Base_Type
(U_Ent
), True);
3355 end Scalar_Storage_Order
;
3361 -- Size attribute definition clause
3363 when Attribute_Size
=> Size
: declare
3364 Size
: constant Uint
:= Static_Integer
(Expr
);
3371 if Duplicate_Clause
then
3374 elsif not Is_Type
(U_Ent
)
3375 and then Ekind
(U_Ent
) /= E_Variable
3376 and then Ekind
(U_Ent
) /= E_Constant
3378 Error_Msg_N
("size cannot be given for &", Nam
);
3380 elsif Is_Array_Type
(U_Ent
)
3381 and then not Is_Constrained
(U_Ent
)
3384 ("size cannot be given for unconstrained array", Nam
);
3386 elsif Size
/= No_Uint
then
3387 if VM_Target
/= No_VM
and then not GNAT_Mode
then
3389 -- Size clause is not handled properly on VM targets.
3390 -- Display a warning unless we are in GNAT mode, in which
3391 -- case this is useless.
3394 ("?size clauses are ignored in this configuration", N
);
3397 if Is_Type
(U_Ent
) then
3400 Etyp
:= Etype
(U_Ent
);
3403 -- Check size, note that Gigi is in charge of checking that the
3404 -- size of an array or record type is OK. Also we do not check
3405 -- the size in the ordinary fixed-point case, since it is too
3406 -- early to do so (there may be subsequent small clause that
3407 -- affects the size). We can check the size if a small clause
3408 -- has already been given.
3410 if not Is_Ordinary_Fixed_Point_Type
(U_Ent
)
3411 or else Has_Small_Clause
(U_Ent
)
3413 Check_Size
(Expr
, Etyp
, Size
, Biased
);
3414 Set_Biased
(U_Ent
, N
, "size clause", Biased
);
3417 -- For types set RM_Size and Esize if possible
3419 if Is_Type
(U_Ent
) then
3420 Set_RM_Size
(U_Ent
, Size
);
3422 -- For elementary types, increase Object_Size to power of 2,
3423 -- but not less than a storage unit in any case (normally
3424 -- this means it will be byte addressable).
3426 -- For all other types, nothing else to do, we leave Esize
3427 -- (object size) unset, the back end will set it from the
3428 -- size and alignment in an appropriate manner.
3430 -- In both cases, we check whether the alignment must be
3431 -- reset in the wake of the size change.
3433 if Is_Elementary_Type
(U_Ent
) then
3434 if Size
<= System_Storage_Unit
then
3435 Init_Esize
(U_Ent
, System_Storage_Unit
);
3436 elsif Size
<= 16 then
3437 Init_Esize
(U_Ent
, 16);
3438 elsif Size
<= 32 then
3439 Init_Esize
(U_Ent
, 32);
3441 Set_Esize
(U_Ent
, (Size
+ 63) / 64 * 64);
3444 Alignment_Check_For_Size_Change
(U_Ent
, Esize
(U_Ent
));
3446 Alignment_Check_For_Size_Change
(U_Ent
, Size
);
3449 -- For objects, set Esize only
3452 if Is_Elementary_Type
(Etyp
) then
3453 if Size
/= System_Storage_Unit
3455 Size
/= System_Storage_Unit
* 2
3457 Size
/= System_Storage_Unit
* 4
3459 Size
/= System_Storage_Unit
* 8
3461 Error_Msg_Uint_1
:= UI_From_Int
(System_Storage_Unit
);
3462 Error_Msg_Uint_2
:= Error_Msg_Uint_1
* 8;
3464 ("size for primitive object must be a power of 2"
3465 & " in the range ^-^", N
);
3469 Set_Esize
(U_Ent
, Size
);
3472 Set_Has_Size_Clause
(U_Ent
);
3480 -- Small attribute definition clause
3482 when Attribute_Small
=> Small
: declare
3483 Implicit_Base
: constant Entity_Id
:= Base_Type
(U_Ent
);
3487 Analyze_And_Resolve
(Expr
, Any_Real
);
3489 if Etype
(Expr
) = Any_Type
then
3492 elsif not Is_Static_Expression
(Expr
) then
3493 Flag_Non_Static_Expr
3494 ("small requires static expression!", Expr
);
3498 Small
:= Expr_Value_R
(Expr
);
3500 if Small
<= Ureal_0
then
3501 Error_Msg_N
("small value must be greater than zero", Expr
);
3507 if not Is_Ordinary_Fixed_Point_Type
(U_Ent
) then
3509 ("small requires an ordinary fixed point type", Nam
);
3511 elsif Has_Small_Clause
(U_Ent
) then
3512 Error_Msg_N
("small already given for &", Nam
);
3514 elsif Small
> Delta_Value
(U_Ent
) then
3516 ("small value must not be greater than delta value", Nam
);
3519 Set_Small_Value
(U_Ent
, Small
);
3520 Set_Small_Value
(Implicit_Base
, Small
);
3521 Set_Has_Small_Clause
(U_Ent
);
3522 Set_Has_Small_Clause
(Implicit_Base
);
3523 Set_Has_Non_Standard_Rep
(Implicit_Base
);
3531 -- Storage_Pool attribute definition clause
3533 when Attribute_Storage_Pool | Attribute_Simple_Storage_Pool
=> declare
3538 if Ekind
(U_Ent
) = E_Access_Subprogram_Type
then
3540 ("storage pool cannot be given for access-to-subprogram type",
3545 Ekind_In
(U_Ent
, E_Access_Type
, E_General_Access_Type
)
3548 ("storage pool can only be given for access types", Nam
);
3551 elsif Is_Derived_Type
(U_Ent
) then
3553 ("storage pool cannot be given for a derived access type",
3556 elsif Duplicate_Clause
then
3559 elsif Present
(Associated_Storage_Pool
(U_Ent
)) then
3560 Error_Msg_N
("storage pool already given for &", Nam
);
3564 if Id
= Attribute_Storage_Pool
then
3566 (Expr
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
3568 -- In the Simple_Storage_Pool case, we allow a variable of any
3569 -- simple storage pool type, so we Resolve without imposing an
3573 Analyze_And_Resolve
(Expr
);
3575 if not Present
(Get_Rep_Pragma
3576 (Etype
(Expr
), Name_Simple_Storage_Pool_Type
))
3579 ("expression must be of a simple storage pool type", Expr
);
3583 if not Denotes_Variable
(Expr
) then
3584 Error_Msg_N
("storage pool must be a variable", Expr
);
3588 if Nkind
(Expr
) = N_Type_Conversion
then
3589 T
:= Etype
(Expression
(Expr
));
3594 -- The Stack_Bounded_Pool is used internally for implementing
3595 -- access types with a Storage_Size. Since it only work properly
3596 -- when used on one specific type, we need to check that it is not
3597 -- hijacked improperly:
3599 -- type T is access Integer;
3600 -- for T'Storage_Size use n;
3601 -- type Q is access Float;
3602 -- for Q'Storage_Size use T'Storage_Size; -- incorrect
3604 if RTE_Available
(RE_Stack_Bounded_Pool
)
3605 and then Base_Type
(T
) = RTE
(RE_Stack_Bounded_Pool
)
3607 Error_Msg_N
("non-shareable internal Pool", Expr
);
3611 -- If the argument is a name that is not an entity name, then
3612 -- we construct a renaming operation to define an entity of
3613 -- type storage pool.
3615 if not Is_Entity_Name
(Expr
)
3616 and then Is_Object_Reference
(Expr
)
3618 Pool
:= Make_Temporary
(Loc
, 'P', Expr
);
3621 Rnode
: constant Node_Id
:=
3622 Make_Object_Renaming_Declaration
(Loc
,
3623 Defining_Identifier
=> Pool
,
3625 New_Occurrence_Of
(Etype
(Expr
), Loc
),
3629 Insert_Before
(N
, Rnode
);
3631 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
3634 elsif Is_Entity_Name
(Expr
) then
3635 Pool
:= Entity
(Expr
);
3637 -- If pool is a renamed object, get original one. This can
3638 -- happen with an explicit renaming, and within instances.
3640 while Present
(Renamed_Object
(Pool
))
3641 and then Is_Entity_Name
(Renamed_Object
(Pool
))
3643 Pool
:= Entity
(Renamed_Object
(Pool
));
3646 if Present
(Renamed_Object
(Pool
))
3647 and then Nkind
(Renamed_Object
(Pool
)) = N_Type_Conversion
3648 and then Is_Entity_Name
(Expression
(Renamed_Object
(Pool
)))
3650 Pool
:= Entity
(Expression
(Renamed_Object
(Pool
)));
3653 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
3655 elsif Nkind
(Expr
) = N_Type_Conversion
3656 and then Is_Entity_Name
(Expression
(Expr
))
3657 and then Nkind
(Original_Node
(Expr
)) = N_Attribute_Reference
3659 Pool
:= Entity
(Expression
(Expr
));
3660 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
3663 Error_Msg_N
("incorrect reference to a Storage Pool", Expr
);
3672 -- Storage_Size attribute definition clause
3674 when Attribute_Storage_Size
=> Storage_Size
: declare
3675 Btype
: constant Entity_Id
:= Base_Type
(U_Ent
);
3678 if Is_Task_Type
(U_Ent
) then
3679 Check_Restriction
(No_Obsolescent_Features
, N
);
3681 if Warn_On_Obsolescent_Feature
then
3683 ("storage size clause for task is an " &
3684 "obsolescent feature (RM J.9)?", N
);
3685 Error_Msg_N
("\use Storage_Size pragma instead?", N
);
3691 if not Is_Access_Type
(U_Ent
)
3692 and then Ekind
(U_Ent
) /= E_Task_Type
3694 Error_Msg_N
("storage size cannot be given for &", Nam
);
3696 elsif Is_Access_Type
(U_Ent
) and Is_Derived_Type
(U_Ent
) then
3698 ("storage size cannot be given for a derived access type",
3701 elsif Duplicate_Clause
then
3705 Analyze_And_Resolve
(Expr
, Any_Integer
);
3707 if Is_Access_Type
(U_Ent
) then
3708 if Present
(Associated_Storage_Pool
(U_Ent
)) then
3709 Error_Msg_N
("storage pool already given for &", Nam
);
3713 if Is_OK_Static_Expression
(Expr
)
3714 and then Expr_Value
(Expr
) = 0
3716 Set_No_Pool_Assigned
(Btype
);
3720 Set_Has_Storage_Size_Clause
(Btype
);
3728 when Attribute_Stream_Size
=> Stream_Size
: declare
3729 Size
: constant Uint
:= Static_Integer
(Expr
);
3732 if Ada_Version
<= Ada_95
then
3733 Check_Restriction
(No_Implementation_Attributes
, N
);
3736 if Duplicate_Clause
then
3739 elsif Is_Elementary_Type
(U_Ent
) then
3740 if Size
/= System_Storage_Unit
3742 Size
/= System_Storage_Unit
* 2
3744 Size
/= System_Storage_Unit
* 4
3746 Size
/= System_Storage_Unit
* 8
3748 Error_Msg_Uint_1
:= UI_From_Int
(System_Storage_Unit
);
3750 ("stream size for elementary type must be a"
3751 & " power of 2 and at least ^", N
);
3753 elsif RM_Size
(U_Ent
) > Size
then
3754 Error_Msg_Uint_1
:= RM_Size
(U_Ent
);
3756 ("stream size for elementary type must be a"
3757 & " power of 2 and at least ^", N
);
3760 Set_Has_Stream_Size_Clause
(U_Ent
);
3763 Error_Msg_N
("Stream_Size cannot be given for &", Nam
);
3771 -- Value_Size attribute definition clause
3773 when Attribute_Value_Size
=> Value_Size
: declare
3774 Size
: constant Uint
:= Static_Integer
(Expr
);
3778 if not Is_Type
(U_Ent
) then
3779 Error_Msg_N
("Value_Size cannot be given for &", Nam
);
3781 elsif Duplicate_Clause
then
3784 elsif Is_Array_Type
(U_Ent
)
3785 and then not Is_Constrained
(U_Ent
)
3788 ("Value_Size cannot be given for unconstrained array", Nam
);
3791 if Is_Elementary_Type
(U_Ent
) then
3792 Check_Size
(Expr
, U_Ent
, Size
, Biased
);
3793 Set_Biased
(U_Ent
, N
, "value size clause", Biased
);
3796 Set_RM_Size
(U_Ent
, Size
);
3800 -----------------------
3801 -- Variable_Indexing --
3802 -----------------------
3804 when Attribute_Variable_Indexing
=>
3805 Check_Indexing_Functions
;
3811 when Attribute_Write
=>
3812 Analyze_Stream_TSS_Definition
(TSS_Stream_Write
);
3813 Set_Has_Specified_Stream_Write
(Ent
);
3815 -- All other attributes cannot be set
3819 ("attribute& cannot be set with definition clause", N
);
3822 -- The test for the type being frozen must be performed after any
3823 -- expression the clause has been analyzed since the expression itself
3824 -- might cause freezing that makes the clause illegal.
3826 if Rep_Item_Too_Late
(U_Ent
, N
, FOnly
) then
3829 end Analyze_Attribute_Definition_Clause
;
3831 ----------------------------
3832 -- Analyze_Code_Statement --
3833 ----------------------------
3835 procedure Analyze_Code_Statement
(N
: Node_Id
) is
3836 HSS
: constant Node_Id
:= Parent
(N
);
3837 SBody
: constant Node_Id
:= Parent
(HSS
);
3838 Subp
: constant Entity_Id
:= Current_Scope
;
3845 -- Analyze and check we get right type, note that this implements the
3846 -- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that
3847 -- is the only way that Asm_Insn could possibly be visible.
3849 Analyze_And_Resolve
(Expression
(N
));
3851 if Etype
(Expression
(N
)) = Any_Type
then
3853 elsif Etype
(Expression
(N
)) /= RTE
(RE_Asm_Insn
) then
3854 Error_Msg_N
("incorrect type for code statement", N
);
3858 Check_Code_Statement
(N
);
3860 -- Make sure we appear in the handled statement sequence of a
3861 -- subprogram (RM 13.8(3)).
3863 if Nkind
(HSS
) /= N_Handled_Sequence_Of_Statements
3864 or else Nkind
(SBody
) /= N_Subprogram_Body
3867 ("code statement can only appear in body of subprogram", N
);
3871 -- Do remaining checks (RM 13.8(3)) if not already done
3873 if not Is_Machine_Code_Subprogram
(Subp
) then
3874 Set_Is_Machine_Code_Subprogram
(Subp
);
3876 -- No exception handlers allowed
3878 if Present
(Exception_Handlers
(HSS
)) then
3880 ("exception handlers not permitted in machine code subprogram",
3881 First
(Exception_Handlers
(HSS
)));
3884 -- No declarations other than use clauses and pragmas (we allow
3885 -- certain internally generated declarations as well).
3887 Decl
:= First
(Declarations
(SBody
));
3888 while Present
(Decl
) loop
3889 DeclO
:= Original_Node
(Decl
);
3890 if Comes_From_Source
(DeclO
)
3891 and not Nkind_In
(DeclO
, N_Pragma
,
3892 N_Use_Package_Clause
,
3894 N_Implicit_Label_Declaration
)
3897 ("this declaration not allowed in machine code subprogram",
3904 -- No statements other than code statements, pragmas, and labels.
3905 -- Again we allow certain internally generated statements.
3907 -- In Ada 2012, qualified expressions are names, and the code
3908 -- statement is initially parsed as a procedure call.
3910 Stmt
:= First
(Statements
(HSS
));
3911 while Present
(Stmt
) loop
3912 StmtO
:= Original_Node
(Stmt
);
3914 -- A procedure call transformed into a code statement is OK.
3916 if Ada_Version
>= Ada_2012
3917 and then Nkind
(StmtO
) = N_Procedure_Call_Statement
3918 and then Nkind
(Name
(StmtO
)) = N_Qualified_Expression
3922 elsif Comes_From_Source
(StmtO
)
3923 and then not Nkind_In
(StmtO
, N_Pragma
,
3928 ("this statement is not allowed in machine code subprogram",
3935 end Analyze_Code_Statement
;
3937 -----------------------------------------------
3938 -- Analyze_Enumeration_Representation_Clause --
3939 -----------------------------------------------
3941 procedure Analyze_Enumeration_Representation_Clause
(N
: Node_Id
) is
3942 Ident
: constant Node_Id
:= Identifier
(N
);
3943 Aggr
: constant Node_Id
:= Array_Aggregate
(N
);
3944 Enumtype
: Entity_Id
;
3951 Err
: Boolean := False;
3952 -- Set True to avoid cascade errors and crashes on incorrect source code
3954 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Universal_Integer
));
3955 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(Universal_Integer
));
3956 -- Allowed range of universal integer (= allowed range of enum lit vals)
3960 -- Minimum and maximum values of entries
3963 -- Pointer to node for literal providing max value
3966 if Ignore_Rep_Clauses
then
3970 -- First some basic error checks
3973 Enumtype
:= Entity
(Ident
);
3975 if Enumtype
= Any_Type
3976 or else Rep_Item_Too_Early
(Enumtype
, N
)
3980 Enumtype
:= Underlying_Type
(Enumtype
);
3983 if not Is_Enumeration_Type
(Enumtype
) then
3985 ("enumeration type required, found}",
3986 Ident
, First_Subtype
(Enumtype
));
3990 -- Ignore rep clause on generic actual type. This will already have
3991 -- been flagged on the template as an error, and this is the safest
3992 -- way to ensure we don't get a junk cascaded message in the instance.
3994 if Is_Generic_Actual_Type
(Enumtype
) then
3997 -- Type must be in current scope
3999 elsif Scope
(Enumtype
) /= Current_Scope
then
4000 Error_Msg_N
("type must be declared in this scope", Ident
);
4003 -- Type must be a first subtype
4005 elsif not Is_First_Subtype
(Enumtype
) then
4006 Error_Msg_N
("cannot give enumeration rep clause for subtype", N
);
4009 -- Ignore duplicate rep clause
4011 elsif Has_Enumeration_Rep_Clause
(Enumtype
) then
4012 Error_Msg_N
("duplicate enumeration rep clause ignored", N
);
4015 -- Don't allow rep clause for standard [wide_[wide_]]character
4017 elsif Is_Standard_Character_Type
(Enumtype
) then
4018 Error_Msg_N
("enumeration rep clause not allowed for this type", N
);
4021 -- Check that the expression is a proper aggregate (no parentheses)
4023 elsif Paren_Count
(Aggr
) /= 0 then
4025 ("extra parentheses surrounding aggregate not allowed",
4029 -- All tests passed, so set rep clause in place
4032 Set_Has_Enumeration_Rep_Clause
(Enumtype
);
4033 Set_Has_Enumeration_Rep_Clause
(Base_Type
(Enumtype
));
4036 -- Now we process the aggregate. Note that we don't use the normal
4037 -- aggregate code for this purpose, because we don't want any of the
4038 -- normal expansion activities, and a number of special semantic
4039 -- rules apply (including the component type being any integer type)
4041 Elit
:= First_Literal
(Enumtype
);
4043 -- First the positional entries if any
4045 if Present
(Expressions
(Aggr
)) then
4046 Expr
:= First
(Expressions
(Aggr
));
4047 while Present
(Expr
) loop
4049 Error_Msg_N
("too many entries in aggregate", Expr
);
4053 Val
:= Static_Integer
(Expr
);
4055 -- Err signals that we found some incorrect entries processing
4056 -- the list. The final checks for completeness and ordering are
4057 -- skipped in this case.
4059 if Val
= No_Uint
then
4061 elsif Val
< Lo
or else Hi
< Val
then
4062 Error_Msg_N
("value outside permitted range", Expr
);
4066 Set_Enumeration_Rep
(Elit
, Val
);
4067 Set_Enumeration_Rep_Expr
(Elit
, Expr
);
4073 -- Now process the named entries if present
4075 if Present
(Component_Associations
(Aggr
)) then
4076 Assoc
:= First
(Component_Associations
(Aggr
));
4077 while Present
(Assoc
) loop
4078 Choice
:= First
(Choices
(Assoc
));
4080 if Present
(Next
(Choice
)) then
4082 ("multiple choice not allowed here", Next
(Choice
));
4086 if Nkind
(Choice
) = N_Others_Choice
then
4087 Error_Msg_N
("others choice not allowed here", Choice
);
4090 elsif Nkind
(Choice
) = N_Range
then
4092 -- ??? should allow zero/one element range here
4094 Error_Msg_N
("range not allowed here", Choice
);
4098 Analyze_And_Resolve
(Choice
, Enumtype
);
4100 if Error_Posted
(Choice
) then
4105 if Is_Entity_Name
(Choice
)
4106 and then Is_Type
(Entity
(Choice
))
4108 Error_Msg_N
("subtype name not allowed here", Choice
);
4111 -- ??? should allow static subtype with zero/one entry
4113 elsif Etype
(Choice
) = Base_Type
(Enumtype
) then
4114 if not Is_Static_Expression
(Choice
) then
4115 Flag_Non_Static_Expr
4116 ("non-static expression used for choice!", Choice
);
4120 Elit
:= Expr_Value_E
(Choice
);
4122 if Present
(Enumeration_Rep_Expr
(Elit
)) then
4124 Sloc
(Enumeration_Rep_Expr
(Elit
));
4126 ("representation for& previously given#",
4131 Set_Enumeration_Rep_Expr
(Elit
, Expression
(Assoc
));
4133 Expr
:= Expression
(Assoc
);
4134 Val
:= Static_Integer
(Expr
);
4136 if Val
= No_Uint
then
4139 elsif Val
< Lo
or else Hi
< Val
then
4140 Error_Msg_N
("value outside permitted range", Expr
);
4144 Set_Enumeration_Rep
(Elit
, Val
);
4154 -- Aggregate is fully processed. Now we check that a full set of
4155 -- representations was given, and that they are in range and in order.
4156 -- These checks are only done if no other errors occurred.
4162 Elit
:= First_Literal
(Enumtype
);
4163 while Present
(Elit
) loop
4164 if No
(Enumeration_Rep_Expr
(Elit
)) then
4165 Error_Msg_NE
("missing representation for&!", N
, Elit
);
4168 Val
:= Enumeration_Rep
(Elit
);
4170 if Min
= No_Uint
then
4174 if Val
/= No_Uint
then
4175 if Max
/= No_Uint
and then Val
<= Max
then
4177 ("enumeration value for& not ordered!",
4178 Enumeration_Rep_Expr
(Elit
), Elit
);
4181 Max_Node
:= Enumeration_Rep_Expr
(Elit
);
4185 -- If there is at least one literal whose representation is not
4186 -- equal to the Pos value, then note that this enumeration type
4187 -- has a non-standard representation.
4189 if Val
/= Enumeration_Pos
(Elit
) then
4190 Set_Has_Non_Standard_Rep
(Base_Type
(Enumtype
));
4197 -- Now set proper size information
4200 Minsize
: Uint
:= UI_From_Int
(Minimum_Size
(Enumtype
));
4203 if Has_Size_Clause
(Enumtype
) then
4205 -- All OK, if size is OK now
4207 if RM_Size
(Enumtype
) >= Minsize
then
4211 -- Try if we can get by with biasing
4214 UI_From_Int
(Minimum_Size
(Enumtype
, Biased
=> True));
4216 -- Error message if even biasing does not work
4218 if RM_Size
(Enumtype
) < Minsize
then
4219 Error_Msg_Uint_1
:= RM_Size
(Enumtype
);
4220 Error_Msg_Uint_2
:= Max
;
4222 ("previously given size (^) is too small "
4223 & "for this value (^)", Max_Node
);
4225 -- If biasing worked, indicate that we now have biased rep
4229 (Enumtype
, Size_Clause
(Enumtype
), "size clause");
4234 Set_RM_Size
(Enumtype
, Minsize
);
4235 Set_Enum_Esize
(Enumtype
);
4238 Set_RM_Size
(Base_Type
(Enumtype
), RM_Size
(Enumtype
));
4239 Set_Esize
(Base_Type
(Enumtype
), Esize
(Enumtype
));
4240 Set_Alignment
(Base_Type
(Enumtype
), Alignment
(Enumtype
));
4244 -- We repeat the too late test in case it froze itself!
4246 if Rep_Item_Too_Late
(Enumtype
, N
) then
4249 end Analyze_Enumeration_Representation_Clause
;
4251 ----------------------------
4252 -- Analyze_Free_Statement --
4253 ----------------------------
4255 procedure Analyze_Free_Statement
(N
: Node_Id
) is
4257 Analyze
(Expression
(N
));
4258 end Analyze_Free_Statement
;
4260 ---------------------------
4261 -- Analyze_Freeze_Entity --
4262 ---------------------------
4264 procedure Analyze_Freeze_Entity
(N
: Node_Id
) is
4265 E
: constant Entity_Id
:= Entity
(N
);
4268 -- Remember that we are processing a freezing entity. Required to
4269 -- ensure correct decoration of internal entities associated with
4270 -- interfaces (see New_Overloaded_Entity).
4272 Inside_Freezing_Actions
:= Inside_Freezing_Actions
+ 1;
4274 -- For tagged types covering interfaces add internal entities that link
4275 -- the primitives of the interfaces with the primitives that cover them.
4276 -- Note: These entities were originally generated only when generating
4277 -- code because their main purpose was to provide support to initialize
4278 -- the secondary dispatch tables. They are now generated also when
4279 -- compiling with no code generation to provide ASIS the relationship
4280 -- between interface primitives and tagged type primitives. They are
4281 -- also used to locate primitives covering interfaces when processing
4282 -- generics (see Derive_Subprograms).
4284 if Ada_Version
>= Ada_2005
4285 and then Ekind
(E
) = E_Record_Type
4286 and then Is_Tagged_Type
(E
)
4287 and then not Is_Interface
(E
)
4288 and then Has_Interfaces
(E
)
4290 -- This would be a good common place to call the routine that checks
4291 -- overriding of interface primitives (and thus factorize calls to
4292 -- Check_Abstract_Overriding located at different contexts in the
4293 -- compiler). However, this is not possible because it causes
4294 -- spurious errors in case of late overriding.
4296 Add_Internal_Interface_Entities
(E
);
4301 if Ekind
(E
) = E_Record_Type
4302 and then Is_CPP_Class
(E
)
4303 and then Is_Tagged_Type
(E
)
4304 and then Tagged_Type_Expansion
4305 and then Expander_Active
4307 if CPP_Num_Prims
(E
) = 0 then
4309 -- If the CPP type has user defined components then it must import
4310 -- primitives from C++. This is required because if the C++ class
4311 -- has no primitives then the C++ compiler does not added the _tag
4312 -- component to the type.
4314 pragma Assert
(Chars
(First_Entity
(E
)) = Name_uTag
);
4316 if First_Entity
(E
) /= Last_Entity
(E
) then
4318 ("?'C'P'P type must import at least one primitive from C++",
4323 -- Check that all its primitives are abstract or imported from C++.
4324 -- Check also availability of the C++ constructor.
4327 Has_Constructors
: constant Boolean := Has_CPP_Constructors
(E
);
4329 Error_Reported
: Boolean := False;
4333 Elmt
:= First_Elmt
(Primitive_Operations
(E
));
4334 while Present
(Elmt
) loop
4335 Prim
:= Node
(Elmt
);
4337 if Comes_From_Source
(Prim
) then
4338 if Is_Abstract_Subprogram
(Prim
) then
4341 elsif not Is_Imported
(Prim
)
4342 or else Convention
(Prim
) /= Convention_CPP
4345 ("?primitives of 'C'P'P types must be imported from C++"
4346 & " or abstract", Prim
);
4348 elsif not Has_Constructors
4349 and then not Error_Reported
4351 Error_Msg_Name_1
:= Chars
(E
);
4353 ("?'C'P'P constructor required for type %", Prim
);
4354 Error_Reported
:= True;
4363 -- Check Ada derivation of CPP type
4366 and then Tagged_Type_Expansion
4367 and then Ekind
(E
) = E_Record_Type
4368 and then Etype
(E
) /= E
4369 and then Is_CPP_Class
(Etype
(E
))
4370 and then CPP_Num_Prims
(Etype
(E
)) > 0
4371 and then not Is_CPP_Class
(E
)
4372 and then not Has_CPP_Constructors
(Etype
(E
))
4374 -- If the parent has C++ primitives but it has no constructor then
4375 -- check that all the primitives are overridden in this derivation;
4376 -- otherwise the constructor of the parent is needed to build the
4384 Elmt
:= First_Elmt
(Primitive_Operations
(E
));
4385 while Present
(Elmt
) loop
4386 Prim
:= Node
(Elmt
);
4388 if not Is_Abstract_Subprogram
(Prim
)
4389 and then No
(Interface_Alias
(Prim
))
4390 and then Find_Dispatching_Type
(Ultimate_Alias
(Prim
)) /= E
4392 Error_Msg_Name_1
:= Chars
(Etype
(E
));
4394 ("'C'P'P constructor required for parent type %", E
);
4403 Inside_Freezing_Actions
:= Inside_Freezing_Actions
- 1;
4405 -- If we have a type with predicates, build predicate function
4407 if Is_Type
(E
) and then Has_Predicates
(E
) then
4408 Build_Predicate_Function
(E
, N
);
4411 -- If type has delayed aspects, this is where we do the preanalysis at
4412 -- the freeze point, as part of the consistent visibility check. Note
4413 -- that this must be done after calling Build_Predicate_Function or
4414 -- Build_Invariant_Procedure since these subprograms fix occurrences of
4415 -- the subtype name in the saved expression so that they will not cause
4416 -- trouble in the preanalysis.
4418 if Has_Delayed_Aspects
(E
)
4419 and then Scope
(E
) = Current_Scope
4421 -- Retrieve the visibility to the discriminants in order to properly
4422 -- analyze the aspects.
4424 Push_Scope_And_Install_Discriminants
(E
);
4430 -- Look for aspect specification entries for this entity
4432 Ritem
:= First_Rep_Item
(E
);
4433 while Present
(Ritem
) loop
4434 if Nkind
(Ritem
) = N_Aspect_Specification
4435 and then Entity
(Ritem
) = E
4436 and then Is_Delayed_Aspect
(Ritem
)
4438 Check_Aspect_At_Freeze_Point
(Ritem
);
4441 Next_Rep_Item
(Ritem
);
4445 Uninstall_Discriminants_And_Pop_Scope
(E
);
4447 end Analyze_Freeze_Entity
;
4449 ------------------------------------------
4450 -- Analyze_Record_Representation_Clause --
4451 ------------------------------------------
4453 -- Note: we check as much as we can here, but we can't do any checks
4454 -- based on the position values (e.g. overlap checks) until freeze time
4455 -- because especially in Ada 2005 (machine scalar mode), the processing
4456 -- for non-standard bit order can substantially change the positions.
4457 -- See procedure Check_Record_Representation_Clause (called from Freeze)
4458 -- for the remainder of this processing.
4460 procedure Analyze_Record_Representation_Clause
(N
: Node_Id
) is
4461 Ident
: constant Node_Id
:= Identifier
(N
);
4466 Hbit
: Uint
:= Uint_0
;
4470 Rectype
: Entity_Id
;
4472 CR_Pragma
: Node_Id
:= Empty
;
4473 -- Points to N_Pragma node if Complete_Representation pragma present
4476 if Ignore_Rep_Clauses
then
4481 Rectype
:= Entity
(Ident
);
4483 if Rectype
= Any_Type
4484 or else Rep_Item_Too_Early
(Rectype
, N
)
4488 Rectype
:= Underlying_Type
(Rectype
);
4491 -- First some basic error checks
4493 if not Is_Record_Type
(Rectype
) then
4495 ("record type required, found}", Ident
, First_Subtype
(Rectype
));
4498 elsif Scope
(Rectype
) /= Current_Scope
then
4499 Error_Msg_N
("type must be declared in this scope", N
);
4502 elsif not Is_First_Subtype
(Rectype
) then
4503 Error_Msg_N
("cannot give record rep clause for subtype", N
);
4506 elsif Has_Record_Rep_Clause
(Rectype
) then
4507 Error_Msg_N
("duplicate record rep clause ignored", N
);
4510 elsif Rep_Item_Too_Late
(Rectype
, N
) then
4514 if Present
(Mod_Clause
(N
)) then
4516 Loc
: constant Source_Ptr
:= Sloc
(N
);
4517 M
: constant Node_Id
:= Mod_Clause
(N
);
4518 P
: constant List_Id
:= Pragmas_Before
(M
);
4522 pragma Warnings
(Off
, Mod_Val
);
4525 Check_Restriction
(No_Obsolescent_Features
, Mod_Clause
(N
));
4527 if Warn_On_Obsolescent_Feature
then
4529 ("mod clause is an obsolescent feature (RM J.8)?", N
);
4531 ("\use alignment attribute definition clause instead?", N
);
4538 -- In ASIS_Mode mode, expansion is disabled, but we must convert
4539 -- the Mod clause into an alignment clause anyway, so that the
4540 -- back-end can compute and back-annotate properly the size and
4541 -- alignment of types that may include this record.
4543 -- This seems dubious, this destroys the source tree in a manner
4544 -- not detectable by ASIS ???
4546 if Operating_Mode
= Check_Semantics
and then ASIS_Mode
then
4548 Make_Attribute_Definition_Clause
(Loc
,
4549 Name
=> New_Reference_To
(Base_Type
(Rectype
), Loc
),
4550 Chars
=> Name_Alignment
,
4551 Expression
=> Relocate_Node
(Expression
(M
)));
4553 Set_From_At_Mod
(AtM_Nod
);
4554 Insert_After
(N
, AtM_Nod
);
4555 Mod_Val
:= Get_Alignment_Value
(Expression
(AtM_Nod
));
4556 Set_Mod_Clause
(N
, Empty
);
4559 -- Get the alignment value to perform error checking
4561 Mod_Val
:= Get_Alignment_Value
(Expression
(M
));
4566 -- For untagged types, clear any existing component clauses for the
4567 -- type. If the type is derived, this is what allows us to override
4568 -- a rep clause for the parent. For type extensions, the representation
4569 -- of the inherited components is inherited, so we want to keep previous
4570 -- component clauses for completeness.
4572 if not Is_Tagged_Type
(Rectype
) then
4573 Comp
:= First_Component_Or_Discriminant
(Rectype
);
4574 while Present
(Comp
) loop
4575 Set_Component_Clause
(Comp
, Empty
);
4576 Next_Component_Or_Discriminant
(Comp
);
4580 -- All done if no component clauses
4582 CC
:= First
(Component_Clauses
(N
));
4588 -- A representation like this applies to the base type
4590 Set_Has_Record_Rep_Clause
(Base_Type
(Rectype
));
4591 Set_Has_Non_Standard_Rep
(Base_Type
(Rectype
));
4592 Set_Has_Specified_Layout
(Base_Type
(Rectype
));
4594 -- Process the component clauses
4596 while Present
(CC
) loop
4600 if Nkind
(CC
) = N_Pragma
then
4603 -- The only pragma of interest is Complete_Representation
4605 if Pragma_Name
(CC
) = Name_Complete_Representation
then
4609 -- Processing for real component clause
4612 Posit
:= Static_Integer
(Position
(CC
));
4613 Fbit
:= Static_Integer
(First_Bit
(CC
));
4614 Lbit
:= Static_Integer
(Last_Bit
(CC
));
4617 and then Fbit
/= No_Uint
4618 and then Lbit
/= No_Uint
4622 ("position cannot be negative", Position
(CC
));
4626 ("first bit cannot be negative", First_Bit
(CC
));
4628 -- The Last_Bit specified in a component clause must not be
4629 -- less than the First_Bit minus one (RM-13.5.1(10)).
4631 elsif Lbit
< Fbit
- 1 then
4633 ("last bit cannot be less than first bit minus one",
4636 -- Values look OK, so find the corresponding record component
4637 -- Even though the syntax allows an attribute reference for
4638 -- implementation-defined components, GNAT does not allow the
4639 -- tag to get an explicit position.
4641 elsif Nkind
(Component_Name
(CC
)) = N_Attribute_Reference
then
4642 if Attribute_Name
(Component_Name
(CC
)) = Name_Tag
then
4643 Error_Msg_N
("position of tag cannot be specified", CC
);
4645 Error_Msg_N
("illegal component name", CC
);
4649 Comp
:= First_Entity
(Rectype
);
4650 while Present
(Comp
) loop
4651 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
4657 -- Maybe component of base type that is absent from
4658 -- statically constrained first subtype.
4660 Comp
:= First_Entity
(Base_Type
(Rectype
));
4661 while Present
(Comp
) loop
4662 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
4669 ("component clause is for non-existent field", CC
);
4671 -- Ada 2012 (AI05-0026): Any name that denotes a
4672 -- discriminant of an object of an unchecked union type
4673 -- shall not occur within a record_representation_clause.
4675 -- The general restriction of using record rep clauses on
4676 -- Unchecked_Union types has now been lifted. Since it is
4677 -- possible to introduce a record rep clause which mentions
4678 -- the discriminant of an Unchecked_Union in non-Ada 2012
4679 -- code, this check is applied to all versions of the
4682 elsif Ekind
(Comp
) = E_Discriminant
4683 and then Is_Unchecked_Union
(Rectype
)
4686 ("cannot reference discriminant of unchecked union",
4687 Component_Name
(CC
));
4689 elsif Present
(Component_Clause
(Comp
)) then
4691 -- Diagnose duplicate rep clause, or check consistency
4692 -- if this is an inherited component. In a double fault,
4693 -- there may be a duplicate inconsistent clause for an
4694 -- inherited component.
4696 if Scope
(Original_Record_Component
(Comp
)) = Rectype
4697 or else Parent
(Component_Clause
(Comp
)) = N
4699 Error_Msg_Sloc
:= Sloc
(Component_Clause
(Comp
));
4700 Error_Msg_N
("component clause previously given#", CC
);
4704 Rep1
: constant Node_Id
:= Component_Clause
(Comp
);
4706 if Intval
(Position
(Rep1
)) /=
4707 Intval
(Position
(CC
))
4708 or else Intval
(First_Bit
(Rep1
)) /=
4709 Intval
(First_Bit
(CC
))
4710 or else Intval
(Last_Bit
(Rep1
)) /=
4711 Intval
(Last_Bit
(CC
))
4713 Error_Msg_N
("component clause inconsistent "
4714 & "with representation of ancestor", CC
);
4715 elsif Warn_On_Redundant_Constructs
then
4716 Error_Msg_N
("?redundant component clause "
4717 & "for inherited component!", CC
);
4722 -- Normal case where this is the first component clause we
4723 -- have seen for this entity, so set it up properly.
4726 -- Make reference for field in record rep clause and set
4727 -- appropriate entity field in the field identifier.
4730 (Comp
, Component_Name
(CC
), Set_Ref
=> False);
4731 Set_Entity
(Component_Name
(CC
), Comp
);
4733 -- Update Fbit and Lbit to the actual bit number
4735 Fbit
:= Fbit
+ UI_From_Int
(SSU
) * Posit
;
4736 Lbit
:= Lbit
+ UI_From_Int
(SSU
) * Posit
;
4738 if Has_Size_Clause
(Rectype
)
4739 and then RM_Size
(Rectype
) <= Lbit
4742 ("bit number out of range of specified size",
4745 Set_Component_Clause
(Comp
, CC
);
4746 Set_Component_Bit_Offset
(Comp
, Fbit
);
4747 Set_Esize
(Comp
, 1 + (Lbit
- Fbit
));
4748 Set_Normalized_First_Bit
(Comp
, Fbit
mod SSU
);
4749 Set_Normalized_Position
(Comp
, Fbit
/ SSU
);
4751 if Warn_On_Overridden_Size
4752 and then Has_Size_Clause
(Etype
(Comp
))
4753 and then RM_Size
(Etype
(Comp
)) /= Esize
(Comp
)
4756 ("?component size overrides size clause for&",
4757 Component_Name
(CC
), Etype
(Comp
));
4760 -- This information is also set in the corresponding
4761 -- component of the base type, found by accessing the
4762 -- Original_Record_Component link if it is present.
4764 Ocomp
:= Original_Record_Component
(Comp
);
4771 (Component_Name
(CC
),
4777 (Comp
, First_Node
(CC
), "component clause", Biased
);
4779 if Present
(Ocomp
) then
4780 Set_Component_Clause
(Ocomp
, CC
);
4781 Set_Component_Bit_Offset
(Ocomp
, Fbit
);
4782 Set_Normalized_First_Bit
(Ocomp
, Fbit
mod SSU
);
4783 Set_Normalized_Position
(Ocomp
, Fbit
/ SSU
);
4784 Set_Esize
(Ocomp
, 1 + (Lbit
- Fbit
));
4786 Set_Normalized_Position_Max
4787 (Ocomp
, Normalized_Position
(Ocomp
));
4789 -- Note: we don't use Set_Biased here, because we
4790 -- already gave a warning above if needed, and we
4791 -- would get a duplicate for the same name here.
4793 Set_Has_Biased_Representation
4794 (Ocomp
, Has_Biased_Representation
(Comp
));
4797 if Esize
(Comp
) < 0 then
4798 Error_Msg_N
("component size is negative", CC
);
4809 -- Check missing components if Complete_Representation pragma appeared
4811 if Present
(CR_Pragma
) then
4812 Comp
:= First_Component_Or_Discriminant
(Rectype
);
4813 while Present
(Comp
) loop
4814 if No
(Component_Clause
(Comp
)) then
4816 ("missing component clause for &", CR_Pragma
, Comp
);
4819 Next_Component_Or_Discriminant
(Comp
);
4822 -- If no Complete_Representation pragma, warn if missing components
4824 elsif Warn_On_Unrepped_Components
then
4826 Num_Repped_Components
: Nat
:= 0;
4827 Num_Unrepped_Components
: Nat
:= 0;
4830 -- First count number of repped and unrepped components
4832 Comp
:= First_Component_Or_Discriminant
(Rectype
);
4833 while Present
(Comp
) loop
4834 if Present
(Component_Clause
(Comp
)) then
4835 Num_Repped_Components
:= Num_Repped_Components
+ 1;
4837 Num_Unrepped_Components
:= Num_Unrepped_Components
+ 1;
4840 Next_Component_Or_Discriminant
(Comp
);
4843 -- We are only interested in the case where there is at least one
4844 -- unrepped component, and at least half the components have rep
4845 -- clauses. We figure that if less than half have them, then the
4846 -- partial rep clause is really intentional. If the component
4847 -- type has no underlying type set at this point (as for a generic
4848 -- formal type), we don't know enough to give a warning on the
4851 if Num_Unrepped_Components
> 0
4852 and then Num_Unrepped_Components
< Num_Repped_Components
4854 Comp
:= First_Component_Or_Discriminant
(Rectype
);
4855 while Present
(Comp
) loop
4856 if No
(Component_Clause
(Comp
))
4857 and then Comes_From_Source
(Comp
)
4858 and then Present
(Underlying_Type
(Etype
(Comp
)))
4859 and then (Is_Scalar_Type
(Underlying_Type
(Etype
(Comp
)))
4860 or else Size_Known_At_Compile_Time
4861 (Underlying_Type
(Etype
(Comp
))))
4862 and then not Has_Warnings_Off
(Rectype
)
4864 Error_Msg_Sloc
:= Sloc
(Comp
);
4866 ("?no component clause given for & declared #",
4870 Next_Component_Or_Discriminant
(Comp
);
4875 end Analyze_Record_Representation_Clause
;
4877 -------------------------------
4878 -- Build_Invariant_Procedure --
4879 -------------------------------
4881 -- The procedure that is constructed here has the form
4883 -- procedure typInvariant (Ixxx : typ) is
4885 -- pragma Check (Invariant, exp, "failed invariant from xxx");
4886 -- pragma Check (Invariant, exp, "failed invariant from xxx");
4888 -- pragma Check (Invariant, exp, "failed inherited invariant from xxx");
4890 -- end typInvariant;
4892 procedure Build_Invariant_Procedure
(Typ
: Entity_Id
; N
: Node_Id
) is
4893 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
4900 Visible_Decls
: constant List_Id
:= Visible_Declarations
(N
);
4901 Private_Decls
: constant List_Id
:= Private_Declarations
(N
);
4903 procedure Add_Invariants
(T
: Entity_Id
; Inherit
: Boolean);
4904 -- Appends statements to Stmts for any invariants in the rep item chain
4905 -- of the given type. If Inherit is False, then we only process entries
4906 -- on the chain for the type Typ. If Inherit is True, then we ignore any
4907 -- Invariant aspects, but we process all Invariant'Class aspects, adding
4908 -- "inherited" to the exception message and generating an informational
4909 -- message about the inheritance of an invariant.
4911 Object_Name
: constant Name_Id
:= New_Internal_Name
('I');
4912 -- Name for argument of invariant procedure
4914 Object_Entity
: constant Node_Id
:=
4915 Make_Defining_Identifier
(Loc
, Object_Name
);
4916 -- The procedure declaration entity for the argument
4918 --------------------
4919 -- Add_Invariants --
4920 --------------------
4922 procedure Add_Invariants
(T
: Entity_Id
; Inherit
: Boolean) is
4932 procedure Replace_Type_Reference
(N
: Node_Id
);
4933 -- Replace a single occurrence N of the subtype name with a reference
4934 -- to the formal of the predicate function. N can be an identifier
4935 -- referencing the subtype, or a selected component, representing an
4936 -- appropriately qualified occurrence of the subtype name.
4938 procedure Replace_Type_References
is
4939 new Replace_Type_References_Generic
(Replace_Type_Reference
);
4940 -- Traverse an expression replacing all occurrences of the subtype
4941 -- name with appropriate references to the object that is the formal
4942 -- parameter of the predicate function. Note that we must ensure
4943 -- that the type and entity information is properly set in the
4944 -- replacement node, since we will do a Preanalyze call of this
4945 -- expression without proper visibility of the procedure argument.
4947 ----------------------------
4948 -- Replace_Type_Reference --
4949 ----------------------------
4951 procedure Replace_Type_Reference
(N
: Node_Id
) is
4953 -- Invariant'Class, replace with T'Class (obj)
4955 if Class_Present
(Ritem
) then
4957 Make_Type_Conversion
(Loc
,
4959 Make_Attribute_Reference
(Loc
,
4960 Prefix
=> New_Occurrence_Of
(T
, Loc
),
4961 Attribute_Name
=> Name_Class
),
4962 Expression
=> Make_Identifier
(Loc
, Object_Name
)));
4964 Set_Entity
(Expression
(N
), Object_Entity
);
4965 Set_Etype
(Expression
(N
), Typ
);
4967 -- Invariant, replace with obj
4970 Rewrite
(N
, Make_Identifier
(Loc
, Object_Name
));
4971 Set_Entity
(N
, Object_Entity
);
4974 end Replace_Type_Reference
;
4976 -- Start of processing for Add_Invariants
4979 Ritem
:= First_Rep_Item
(T
);
4980 while Present
(Ritem
) loop
4981 if Nkind
(Ritem
) = N_Pragma
4982 and then Pragma_Name
(Ritem
) = Name_Invariant
4984 Arg1
:= First
(Pragma_Argument_Associations
(Ritem
));
4985 Arg2
:= Next
(Arg1
);
4986 Arg3
:= Next
(Arg2
);
4988 Arg1
:= Get_Pragma_Arg
(Arg1
);
4989 Arg2
:= Get_Pragma_Arg
(Arg2
);
4991 -- For Inherit case, ignore Invariant, process only Class case
4994 if not Class_Present
(Ritem
) then
4998 -- For Inherit false, process only item for right type
5001 if Entity
(Arg1
) /= Typ
then
5007 Stmts
:= Empty_List
;
5010 Exp
:= New_Copy_Tree
(Arg2
);
5013 -- We need to replace any occurrences of the name of the type
5014 -- with references to the object, converted to type'Class in
5015 -- the case of Invariant'Class aspects.
5017 Replace_Type_References
(Exp
, Chars
(T
));
5019 -- If this invariant comes from an aspect, find the aspect
5020 -- specification, and replace the saved expression because
5021 -- we need the subtype references replaced for the calls to
5022 -- Preanalyze_Spec_Expressin in Check_Aspect_At_Freeze_Point
5023 -- and Check_Aspect_At_End_Of_Declarations.
5025 if From_Aspect_Specification
(Ritem
) then
5030 -- Loop to find corresponding aspect, note that this
5031 -- must be present given the pragma is marked delayed.
5033 Aitem
:= Next_Rep_Item
(Ritem
);
5034 while Present
(Aitem
) loop
5035 if Nkind
(Aitem
) = N_Aspect_Specification
5036 and then Aspect_Rep_Item
(Aitem
) = Ritem
5039 (Identifier
(Aitem
), New_Copy_Tree
(Exp
));
5043 Aitem
:= Next_Rep_Item
(Aitem
);
5048 -- Now we need to preanalyze the expression to properly capture
5049 -- the visibility in the visible part. The expression will not
5050 -- be analyzed for real until the body is analyzed, but that is
5051 -- at the end of the private part and has the wrong visibility.
5053 Set_Parent
(Exp
, N
);
5054 Preanalyze_Spec_Expression
(Exp
, Standard_Boolean
);
5056 -- Build first two arguments for Check pragma
5059 Make_Pragma_Argument_Association
(Loc
,
5060 Expression
=> Make_Identifier
(Loc
, Name_Invariant
)),
5061 Make_Pragma_Argument_Association
(Loc
, Expression
=> Exp
));
5063 -- Add message if present in Invariant pragma
5065 if Present
(Arg3
) then
5066 Str
:= Strval
(Get_Pragma_Arg
(Arg3
));
5068 -- If inherited case, and message starts "failed invariant",
5069 -- change it to be "failed inherited invariant".
5072 String_To_Name_Buffer
(Str
);
5074 if Name_Buffer
(1 .. 16) = "failed invariant" then
5075 Insert_Str_In_Name_Buffer
("inherited ", 8);
5076 Str
:= String_From_Name_Buffer
;
5081 Make_Pragma_Argument_Association
(Loc
,
5082 Expression
=> Make_String_Literal
(Loc
, Str
)));
5085 -- Add Check pragma to list of statements
5089 Pragma_Identifier
=>
5090 Make_Identifier
(Loc
, Name_Check
),
5091 Pragma_Argument_Associations
=> Assoc
));
5093 -- If Inherited case and option enabled, output info msg. Note
5094 -- that we know this is a case of Invariant'Class.
5096 if Inherit
and Opt
.List_Inherited_Aspects
then
5097 Error_Msg_Sloc
:= Sloc
(Ritem
);
5099 ("?info: & inherits `Invariant''Class` aspect from #",
5105 Next_Rep_Item
(Ritem
);
5109 -- Start of processing for Build_Invariant_Procedure
5115 Set_Etype
(Object_Entity
, Typ
);
5117 -- Add invariants for the current type
5119 Add_Invariants
(Typ
, Inherit
=> False);
5121 -- Add invariants for parent types
5124 Current_Typ
: Entity_Id
;
5125 Parent_Typ
: Entity_Id
;
5130 Parent_Typ
:= Etype
(Current_Typ
);
5132 if Is_Private_Type
(Parent_Typ
)
5133 and then Present
(Full_View
(Base_Type
(Parent_Typ
)))
5135 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
5138 exit when Parent_Typ
= Current_Typ
;
5140 Current_Typ
:= Parent_Typ
;
5141 Add_Invariants
(Current_Typ
, Inherit
=> True);
5145 -- Build the procedure if we generated at least one Check pragma
5147 if Stmts
/= No_List
then
5149 -- Build procedure declaration
5152 Make_Defining_Identifier
(Loc
,
5153 Chars
=> New_External_Name
(Chars
(Typ
), "Invariant"));
5154 Set_Has_Invariants
(SId
);
5155 Set_Invariant_Procedure
(Typ
, SId
);
5158 Make_Procedure_Specification
(Loc
,
5159 Defining_Unit_Name
=> SId
,
5160 Parameter_Specifications
=> New_List
(
5161 Make_Parameter_Specification
(Loc
,
5162 Defining_Identifier
=> Object_Entity
,
5163 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))));
5165 PDecl
:= Make_Subprogram_Declaration
(Loc
, Specification
=> Spec
);
5167 -- Build procedure body
5170 Make_Defining_Identifier
(Loc
,
5171 Chars
=> New_External_Name
(Chars
(Typ
), "Invariant"));
5174 Make_Procedure_Specification
(Loc
,
5175 Defining_Unit_Name
=> SId
,
5176 Parameter_Specifications
=> New_List
(
5177 Make_Parameter_Specification
(Loc
,
5178 Defining_Identifier
=>
5179 Make_Defining_Identifier
(Loc
, Object_Name
),
5180 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))));
5183 Make_Subprogram_Body
(Loc
,
5184 Specification
=> Spec
,
5185 Declarations
=> Empty_List
,
5186 Handled_Statement_Sequence
=>
5187 Make_Handled_Sequence_Of_Statements
(Loc
,
5188 Statements
=> Stmts
));
5190 -- Insert procedure declaration and spec at the appropriate points.
5191 -- Skip this if there are no private declarations (that's an error
5192 -- that will be diagnosed elsewhere, and there is no point in having
5193 -- an invariant procedure set if the full declaration is missing).
5195 if Present
(Private_Decls
) then
5197 -- The spec goes at the end of visible declarations, but they have
5198 -- already been analyzed, so we need to explicitly do the analyze.
5200 Append_To
(Visible_Decls
, PDecl
);
5203 -- The body goes at the end of the private declarations, which we
5204 -- have not analyzed yet, so we do not need to perform an explicit
5205 -- analyze call. We skip this if there are no private declarations
5206 -- (this is an error that will be caught elsewhere);
5208 Append_To
(Private_Decls
, PBody
);
5210 -- If the invariant appears on the full view of a type, the
5211 -- analysis of the private part is complete, and we must
5212 -- analyze the new body explicitly.
5214 if In_Private_Part
(Current_Scope
) then
5219 end Build_Invariant_Procedure
;
5221 ------------------------------
5222 -- Build_Predicate_Function --
5223 ------------------------------
5225 -- The procedure that is constructed here has the form
5227 -- function typPredicate (Ixxx : typ) return Boolean is
5230 -- exp1 and then exp2 and then ...
5231 -- and then typ1Predicate (typ1 (Ixxx))
5232 -- and then typ2Predicate (typ2 (Ixxx))
5234 -- end typPredicate;
5236 -- Here exp1, and exp2 are expressions from Predicate pragmas. Note that
5237 -- this is the point at which these expressions get analyzed, providing the
5238 -- required delay, and typ1, typ2, are entities from which predicates are
5239 -- inherited. Note that we do NOT generate Check pragmas, that's because we
5240 -- use this function even if checks are off, e.g. for membership tests.
5242 procedure Build_Predicate_Function
(Typ
: Entity_Id
; N
: Node_Id
) is
5243 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
5250 -- This is the expression for the return statement in the function. It
5251 -- is build by connecting the component predicates with AND THEN.
5253 procedure Add_Call
(T
: Entity_Id
);
5254 -- Includes a call to the predicate function for type T in Expr if T
5255 -- has predicates and Predicate_Function (T) is non-empty.
5257 procedure Add_Predicates
;
5258 -- Appends expressions for any Predicate pragmas in the rep item chain
5259 -- Typ to Expr. Note that we look only at items for this exact entity.
5260 -- Inheritance of predicates for the parent type is done by calling the
5261 -- Predicate_Function of the parent type, using Add_Call above.
5263 Object_Name
: constant Name_Id
:= New_Internal_Name
('I');
5264 -- Name for argument of Predicate procedure
5266 Object_Entity
: constant Entity_Id
:=
5267 Make_Defining_Identifier
(Loc
, Object_Name
);
5268 -- The entity for the spec entity for the argument
5270 Dynamic_Predicate_Present
: Boolean := False;
5271 -- Set True if a dynamic predicate is present, results in the entire
5272 -- predicate being considered dynamic even if it looks static
5274 Static_Predicate_Present
: Node_Id
:= Empty
;
5275 -- Set to N_Pragma node for a static predicate if one is encountered.
5281 procedure Add_Call
(T
: Entity_Id
) is
5285 if Present
(T
) and then Present
(Predicate_Function
(T
)) then
5286 Set_Has_Predicates
(Typ
);
5288 -- Build the call to the predicate function of T
5292 (T
, Convert_To
(T
, Make_Identifier
(Loc
, Object_Name
)));
5294 -- Add call to evolving expression, using AND THEN if needed
5301 Left_Opnd
=> Relocate_Node
(Expr
),
5305 -- Output info message on inheritance if required. Note we do not
5306 -- give this information for generic actual types, since it is
5307 -- unwelcome noise in that case in instantiations. We also
5308 -- generally suppress the message in instantiations, and also
5309 -- if it involves internal names.
5311 if Opt
.List_Inherited_Aspects
5312 and then not Is_Generic_Actual_Type
(Typ
)
5313 and then Instantiation_Depth
(Sloc
(Typ
)) = 0
5314 and then not Is_Internal_Name
(Chars
(T
))
5315 and then not Is_Internal_Name
(Chars
(Typ
))
5317 Error_Msg_Sloc
:= Sloc
(Predicate_Function
(T
));
5318 Error_Msg_Node_2
:= T
;
5319 Error_Msg_N
("?info: & inherits predicate from & #", Typ
);
5324 --------------------
5325 -- Add_Predicates --
5326 --------------------
5328 procedure Add_Predicates
is
5333 procedure Replace_Type_Reference
(N
: Node_Id
);
5334 -- Replace a single occurrence N of the subtype name with a reference
5335 -- to the formal of the predicate function. N can be an identifier
5336 -- referencing the subtype, or a selected component, representing an
5337 -- appropriately qualified occurrence of the subtype name.
5339 procedure Replace_Type_References
is
5340 new Replace_Type_References_Generic
(Replace_Type_Reference
);
5341 -- Traverse an expression changing every occurrence of an identifier
5342 -- whose name matches the name of the subtype with a reference to
5343 -- the formal parameter of the predicate function.
5345 ----------------------------
5346 -- Replace_Type_Reference --
5347 ----------------------------
5349 procedure Replace_Type_Reference
(N
: Node_Id
) is
5351 Rewrite
(N
, Make_Identifier
(Loc
, Object_Name
));
5352 Set_Entity
(N
, Object_Entity
);
5354 end Replace_Type_Reference
;
5356 -- Start of processing for Add_Predicates
5359 Ritem
:= First_Rep_Item
(Typ
);
5360 while Present
(Ritem
) loop
5361 if Nkind
(Ritem
) = N_Pragma
5362 and then Pragma_Name
(Ritem
) = Name_Predicate
5364 if Present
(Corresponding_Aspect
(Ritem
)) then
5365 case Chars
(Identifier
(Corresponding_Aspect
(Ritem
))) is
5366 when Name_Dynamic_Predicate
=>
5367 Dynamic_Predicate_Present
:= True;
5368 when Name_Static_Predicate
=>
5369 Static_Predicate_Present
:= Ritem
;
5375 -- Acquire arguments
5377 Arg1
:= First
(Pragma_Argument_Associations
(Ritem
));
5378 Arg2
:= Next
(Arg1
);
5380 Arg1
:= Get_Pragma_Arg
(Arg1
);
5381 Arg2
:= Get_Pragma_Arg
(Arg2
);
5383 -- See if this predicate pragma is for the current type or for
5384 -- its full view. A predicate on a private completion is placed
5385 -- on the partial view beause this is the visible entity that
5388 if Entity
(Arg1
) = Typ
5389 or else Full_View
(Entity
(Arg1
)) = Typ
5392 -- We have a match, this entry is for our subtype
5394 -- We need to replace any occurrences of the name of the
5395 -- type with references to the object.
5397 Replace_Type_References
(Arg2
, Chars
(Typ
));
5399 -- If this predicate comes from an aspect, find the aspect
5400 -- specification, and replace the saved expression because
5401 -- we need the subtype references replaced for the calls to
5402 -- Preanalyze_Spec_Expressin in Check_Aspect_At_Freeze_Point
5403 -- and Check_Aspect_At_End_Of_Declarations.
5405 if From_Aspect_Specification
(Ritem
) then
5410 -- Loop to find corresponding aspect, note that this
5411 -- must be present given the pragma is marked delayed.
5413 Aitem
:= Next_Rep_Item
(Ritem
);
5415 if Nkind
(Aitem
) = N_Aspect_Specification
5416 and then Aspect_Rep_Item
(Aitem
) = Ritem
5419 (Identifier
(Aitem
), New_Copy_Tree
(Arg2
));
5423 Aitem
:= Next_Rep_Item
(Aitem
);
5428 -- Now we can add the expression
5431 Expr
:= Relocate_Node
(Arg2
);
5433 -- There already was a predicate, so add to it
5438 Left_Opnd
=> Relocate_Node
(Expr
),
5439 Right_Opnd
=> Relocate_Node
(Arg2
));
5444 Next_Rep_Item
(Ritem
);
5448 -- Start of processing for Build_Predicate_Function
5451 -- Initialize for construction of statement list
5455 -- Return if already built or if type does not have predicates
5457 if not Has_Predicates
(Typ
)
5458 or else Present
(Predicate_Function
(Typ
))
5463 -- Add Predicates for the current type
5467 -- Add predicates for ancestor if present
5470 Atyp
: constant Entity_Id
:= Nearest_Ancestor
(Typ
);
5472 if Present
(Atyp
) then
5477 -- If we have predicates, build the function
5479 if Present
(Expr
) then
5481 -- Build function declaration
5483 pragma Assert
(Has_Predicates
(Typ
));
5485 Make_Defining_Identifier
(Loc
,
5486 Chars
=> New_External_Name
(Chars
(Typ
), "Predicate"));
5487 Set_Has_Predicates
(SId
);
5488 Set_Predicate_Function
(Typ
, SId
);
5490 -- The predicate function is shared between views of a type.
5492 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
5493 Set_Predicate_Function
(Full_View
(Typ
), SId
);
5497 Make_Function_Specification
(Loc
,
5498 Defining_Unit_Name
=> SId
,
5499 Parameter_Specifications
=> New_List
(
5500 Make_Parameter_Specification
(Loc
,
5501 Defining_Identifier
=> Object_Entity
,
5502 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))),
5503 Result_Definition
=>
5504 New_Occurrence_Of
(Standard_Boolean
, Loc
));
5506 FDecl
:= Make_Subprogram_Declaration
(Loc
, Specification
=> Spec
);
5508 -- Build function body
5511 Make_Defining_Identifier
(Loc
,
5512 Chars
=> New_External_Name
(Chars
(Typ
), "Predicate"));
5515 Make_Function_Specification
(Loc
,
5516 Defining_Unit_Name
=> SId
,
5517 Parameter_Specifications
=> New_List
(
5518 Make_Parameter_Specification
(Loc
,
5519 Defining_Identifier
=>
5520 Make_Defining_Identifier
(Loc
, Object_Name
),
5522 New_Occurrence_Of
(Typ
, Loc
))),
5523 Result_Definition
=>
5524 New_Occurrence_Of
(Standard_Boolean
, Loc
));
5527 Make_Subprogram_Body
(Loc
,
5528 Specification
=> Spec
,
5529 Declarations
=> Empty_List
,
5530 Handled_Statement_Sequence
=>
5531 Make_Handled_Sequence_Of_Statements
(Loc
,
5532 Statements
=> New_List
(
5533 Make_Simple_Return_Statement
(Loc
,
5534 Expression
=> Expr
))));
5536 -- Insert declaration before freeze node and body after
5538 Insert_Before_And_Analyze
(N
, FDecl
);
5539 Insert_After_And_Analyze
(N
, FBody
);
5541 -- Deal with static predicate case
5543 if Ekind_In
(Typ
, E_Enumeration_Subtype
,
5544 E_Modular_Integer_Subtype
,
5545 E_Signed_Integer_Subtype
)
5546 and then Is_Static_Subtype
(Typ
)
5547 and then not Dynamic_Predicate_Present
5549 Build_Static_Predicate
(Typ
, Expr
, Object_Name
);
5551 if Present
(Static_Predicate_Present
)
5552 and No
(Static_Predicate
(Typ
))
5555 ("expression does not have required form for "
5556 & "static predicate",
5557 Next
(First
(Pragma_Argument_Associations
5558 (Static_Predicate_Present
))));
5562 end Build_Predicate_Function
;
5564 ----------------------------
5565 -- Build_Static_Predicate --
5566 ----------------------------
5568 procedure Build_Static_Predicate
5573 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
5575 Non_Static
: exception;
5576 -- Raised if something non-static is found
5578 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
5580 BLo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Btyp
));
5581 BHi
: constant Uint
:= Expr_Value
(Type_High_Bound
(Btyp
));
5582 -- Low bound and high bound value of base type of Typ
5584 TLo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Typ
));
5585 THi
: constant Uint
:= Expr_Value
(Type_High_Bound
(Typ
));
5586 -- Low bound and high bound values of static subtype Typ
5591 -- One entry in a Rlist value, a single REnt (range entry) value
5592 -- denotes one range from Lo to Hi. To represent a single value
5593 -- range Lo = Hi = value.
5595 type RList
is array (Nat
range <>) of REnt
;
5596 -- A list of ranges. The ranges are sorted in increasing order,
5597 -- and are disjoint (there is a gap of at least one value between
5598 -- each range in the table). A value is in the set of ranges in
5599 -- Rlist if it lies within one of these ranges
5601 False_Range
: constant RList
:=
5602 RList
'(1 .. 0 => REnt'(No_Uint
, No_Uint
));
5603 -- An empty set of ranges represents a range list that can never be
5604 -- satisfied, since there are no ranges in which the value could lie,
5605 -- so it does not lie in any of them. False_Range is a canonical value
5606 -- for this empty set, but general processing should test for an Rlist
5607 -- with length zero (see Is_False predicate), since other null ranges
5608 -- may appear which must be treated as False.
5610 True_Range
: constant RList
:= RList
'(1 => REnt'(BLo
, BHi
));
5611 -- Range representing True, value must be in the base range
5613 function "and" (Left
, Right
: RList
) return RList
;
5614 -- And's together two range lists, returning a range list. This is
5615 -- a set intersection operation.
5617 function "or" (Left
, Right
: RList
) return RList
;
5618 -- Or's together two range lists, returning a range list. This is a
5619 -- set union operation.
5621 function "not" (Right
: RList
) return RList
;
5622 -- Returns complement of a given range list, i.e. a range list
5623 -- representing all the values in TLo .. THi that are not in the
5624 -- input operand Right.
5626 function Build_Val
(V
: Uint
) return Node_Id
;
5627 -- Return an analyzed N_Identifier node referencing this value, suitable
5628 -- for use as an entry in the Static_Predicate list. This node is typed
5629 -- with the base type.
5631 function Build_Range
(Lo
, Hi
: Uint
) return Node_Id
;
5632 -- Return an analyzed N_Range node referencing this range, suitable
5633 -- for use as an entry in the Static_Predicate list. This node is typed
5634 -- with the base type.
5636 function Get_RList
(Exp
: Node_Id
) return RList
;
5637 -- This is a recursive routine that converts the given expression into
5638 -- a list of ranges, suitable for use in building the static predicate.
5640 function Is_False
(R
: RList
) return Boolean;
5641 pragma Inline
(Is_False
);
5642 -- Returns True if the given range list is empty, and thus represents
5643 -- a False list of ranges that can never be satisfied.
5645 function Is_True
(R
: RList
) return Boolean;
5646 -- Returns True if R trivially represents the True predicate by having
5647 -- a single range from BLo to BHi.
5649 function Is_Type_Ref
(N
: Node_Id
) return Boolean;
5650 pragma Inline
(Is_Type_Ref
);
5651 -- Returns if True if N is a reference to the type for the predicate in
5652 -- the expression (i.e. if it is an identifier whose Chars field matches
5653 -- the Nam given in the call).
5655 function Lo_Val
(N
: Node_Id
) return Uint
;
5656 -- Given static expression or static range from a Static_Predicate list,
5657 -- gets expression value or low bound of range.
5659 function Hi_Val
(N
: Node_Id
) return Uint
;
5660 -- Given static expression or static range from a Static_Predicate list,
5661 -- gets expression value of high bound of range.
5663 function Membership_Entry
(N
: Node_Id
) return RList
;
5664 -- Given a single membership entry (range, value, or subtype), returns
5665 -- the corresponding range list. Raises Static_Error if not static.
5667 function Membership_Entries
(N
: Node_Id
) return RList
;
5668 -- Given an element on an alternatives list of a membership operation,
5669 -- returns the range list corresponding to this entry and all following
5670 -- entries (i.e. returns the "or" of this list of values).
5672 function Stat_Pred
(Typ
: Entity_Id
) return RList
;
5673 -- Given a type, if it has a static predicate, then return the predicate
5674 -- as a range list, otherwise raise Non_Static.
5680 function "and" (Left
, Right
: RList
) return RList
is
5682 -- First range of result
5684 SLeft
: Nat
:= Left
'First;
5685 -- Start of rest of left entries
5687 SRight
: Nat
:= Right
'First;
5688 -- Start of rest of right entries
5691 -- If either range is True, return the other
5693 if Is_True
(Left
) then
5695 elsif Is_True
(Right
) then
5699 -- If either range is False, return False
5701 if Is_False
(Left
) or else Is_False
(Right
) then
5705 -- Loop to remove entries at start that are disjoint, and thus
5706 -- just get discarded from the result entirely.
5709 -- If no operands left in either operand, result is false
5711 if SLeft
> Left
'Last or else SRight
> Right
'Last then
5714 -- Discard first left operand entry if disjoint with right
5716 elsif Left
(SLeft
).Hi
< Right
(SRight
).Lo
then
5719 -- Discard first right operand entry if disjoint with left
5721 elsif Right
(SRight
).Hi
< Left
(SLeft
).Lo
then
5722 SRight
:= SRight
+ 1;
5724 -- Otherwise we have an overlapping entry
5731 -- Now we have two non-null operands, and first entries overlap.
5732 -- The first entry in the result will be the overlapping part of
5733 -- these two entries.
5735 FEnt
:= REnt
'(Lo => UI_Max (Left (SLeft).Lo, Right (SRight).Lo),
5736 Hi => UI_Min (Left (SLeft).Hi, Right (SRight).Hi));
5738 -- Now we can remove the entry that ended at a lower value, since
5739 -- its contribution is entirely contained in Fent.
5741 if Left (SLeft).Hi <= Right (SRight).Hi then
5744 SRight := SRight + 1;
5747 -- Compute result by concatenating this first entry with the "and"
5748 -- of the remaining parts of the left and right operands. Note that
5749 -- if either of these is empty, "and" will yield empty, so that we
5750 -- will end up with just Fent, which is what we want in that case.
5753 FEnt & (Left (SLeft .. Left'Last) and Right (SRight .. Right'Last));
5760 function "not" (Right : RList) return RList is
5762 -- Return True if False range
5764 if Is_False (Right) then
5768 -- Return False if True range
5770 if Is_True (Right) then
5774 -- Here if not trivial case
5777 Result : RList (1 .. Right'Length + 1);
5778 -- May need one more entry for gap at beginning and end
5781 -- Number of entries stored in Result
5786 if Right (Right'First).Lo > TLo then
5788 Result (Count) := REnt'(TLo
, Right
(Right
'First).Lo
- 1);
5791 -- Gaps between ranges
5793 for J
in Right
'First .. Right
'Last - 1 loop
5796 REnt
'(Right (J).Hi + 1, Right (J + 1).Lo - 1);
5801 if Right (Right'Last).Hi < THi then
5803 Result (Count) := REnt'(Right
(Right
'Last).Hi
+ 1, THi
);
5806 return Result
(1 .. Count
);
5814 function "or" (Left
, Right
: RList
) return RList
is
5816 -- First range of result
5818 SLeft
: Nat
:= Left
'First;
5819 -- Start of rest of left entries
5821 SRight
: Nat
:= Right
'First;
5822 -- Start of rest of right entries
5825 -- If either range is True, return True
5827 if Is_True
(Left
) or else Is_True
(Right
) then
5831 -- If either range is False (empty), return the other
5833 if Is_False
(Left
) then
5835 elsif Is_False
(Right
) then
5839 -- Initialize result first entry from left or right operand
5840 -- depending on which starts with the lower range.
5842 if Left
(SLeft
).Lo
< Right
(SRight
).Lo
then
5843 FEnt
:= Left
(SLeft
);
5846 FEnt
:= Right
(SRight
);
5847 SRight
:= SRight
+ 1;
5850 -- This loop eats ranges from left and right operands that
5851 -- are contiguous with the first range we are gathering.
5854 -- Eat first entry in left operand if contiguous or
5855 -- overlapped by gathered first operand of result.
5857 if SLeft
<= Left
'Last
5858 and then Left
(SLeft
).Lo
<= FEnt
.Hi
+ 1
5860 FEnt
.Hi
:= UI_Max
(FEnt
.Hi
, Left
(SLeft
).Hi
);
5863 -- Eat first entry in right operand if contiguous or
5864 -- overlapped by gathered right operand of result.
5866 elsif SRight
<= Right
'Last
5867 and then Right
(SRight
).Lo
<= FEnt
.Hi
+ 1
5869 FEnt
.Hi
:= UI_Max
(FEnt
.Hi
, Right
(SRight
).Hi
);
5870 SRight
:= SRight
+ 1;
5872 -- All done if no more entries to eat!
5879 -- Obtain result as the first entry we just computed, concatenated
5880 -- to the "or" of the remaining results (if one operand is empty,
5881 -- this will just concatenate with the other
5884 FEnt
& (Left
(SLeft
.. Left
'Last) or Right
(SRight
.. Right
'Last));
5891 function Build_Range
(Lo
, Hi
: Uint
) return Node_Id
is
5895 return Build_Val
(Hi
);
5899 Low_Bound
=> Build_Val
(Lo
),
5900 High_Bound
=> Build_Val
(Hi
));
5901 Set_Etype
(Result
, Btyp
);
5902 Set_Analyzed
(Result
);
5911 function Build_Val
(V
: Uint
) return Node_Id
is
5915 if Is_Enumeration_Type
(Typ
) then
5916 Result
:= Get_Enum_Lit_From_Pos
(Typ
, V
, Loc
);
5918 Result
:= Make_Integer_Literal
(Loc
, V
);
5921 Set_Etype
(Result
, Btyp
);
5922 Set_Is_Static_Expression
(Result
);
5923 Set_Analyzed
(Result
);
5931 function Get_RList
(Exp
: Node_Id
) return RList
is
5936 -- Static expression can only be true or false
5938 if Is_OK_Static_Expression
(Exp
) then
5942 if Expr_Value
(Exp
) = 0 then
5949 -- Otherwise test node type
5957 when N_Op_And | N_And_Then
=>
5958 return Get_RList
(Left_Opnd
(Exp
))
5960 Get_RList
(Right_Opnd
(Exp
));
5964 when N_Op_Or | N_Or_Else
=>
5965 return Get_RList
(Left_Opnd
(Exp
))
5967 Get_RList
(Right_Opnd
(Exp
));
5972 return not Get_RList
(Right_Opnd
(Exp
));
5974 -- Comparisons of type with static value
5976 when N_Op_Compare
=>
5977 -- Type is left operand
5979 if Is_Type_Ref
(Left_Opnd
(Exp
))
5980 and then Is_OK_Static_Expression
(Right_Opnd
(Exp
))
5982 Val
:= Expr_Value
(Right_Opnd
(Exp
));
5984 -- Typ is right operand
5986 elsif Is_Type_Ref
(Right_Opnd
(Exp
))
5987 and then Is_OK_Static_Expression
(Left_Opnd
(Exp
))
5989 Val
:= Expr_Value
(Left_Opnd
(Exp
));
5991 -- Invert sense of comparison
5994 when N_Op_Gt
=> Op
:= N_Op_Lt
;
5995 when N_Op_Lt
=> Op
:= N_Op_Gt
;
5996 when N_Op_Ge
=> Op
:= N_Op_Le
;
5997 when N_Op_Le
=> Op
:= N_Op_Ge
;
5998 when others => null;
6001 -- Other cases are non-static
6007 -- Construct range according to comparison operation
6011 return RList
'(1 => REnt'(Val
, Val
));
6014 return RList
'(1 => REnt'(Val
, BHi
));
6017 return RList
'(1 => REnt'(Val
+ 1, BHi
));
6020 return RList
'(1 => REnt'(BLo
, Val
));
6023 return RList
'(1 => REnt'(BLo
, Val
- 1));
6026 return RList
'(REnt'(BLo
, Val
- 1),
6027 REnt
'(Val + 1, BHi));
6030 raise Program_Error;
6036 if not Is_Type_Ref (Left_Opnd (Exp)) then
6040 if Present (Right_Opnd (Exp)) then
6041 return Membership_Entry (Right_Opnd (Exp));
6043 return Membership_Entries (First (Alternatives (Exp)));
6046 -- Negative membership (NOT IN)
6049 if not Is_Type_Ref (Left_Opnd (Exp)) then
6053 if Present (Right_Opnd (Exp)) then
6054 return not Membership_Entry (Right_Opnd (Exp));
6056 return not Membership_Entries (First (Alternatives (Exp)));
6059 -- Function call, may be call to static predicate
6061 when N_Function_Call =>
6062 if Is_Entity_Name (Name (Exp)) then
6064 Ent : constant Entity_Id := Entity (Name (Exp));
6066 if Has_Predicates (Ent) then
6067 return Stat_Pred (Etype (First_Formal (Ent)));
6072 -- Other function call cases are non-static
6076 -- Qualified expression, dig out the expression
6078 when N_Qualified_Expression =>
6079 return Get_RList (Expression (Exp));
6084 return (Get_RList (Left_Opnd (Exp))
6085 and not Get_RList (Right_Opnd (Exp)))
6086 or (Get_RList (Right_Opnd (Exp))
6087 and not Get_RList (Left_Opnd (Exp)));
6089 -- Any other node type is non-static
6100 function Hi_Val (N : Node_Id) return Uint is
6102 if Is_Static_Expression (N) then
6103 return Expr_Value (N);
6105 pragma Assert (Nkind (N) = N_Range);
6106 return Expr_Value (High_Bound (N));
6114 function Is_False (R : RList) return Boolean is
6116 return R'Length = 0;
6123 function Is_True (R : RList) return Boolean is
6126 and then R (R'First).Lo = BLo
6127 and then R (R'First).Hi = BHi;
6134 function Is_Type_Ref (N : Node_Id) return Boolean is
6136 return Nkind (N) = N_Identifier and then Chars (N) = Nam;
6143 function Lo_Val (N : Node_Id) return Uint is
6145 if Is_Static_Expression (N) then
6146 return Expr_Value (N);
6148 pragma Assert (Nkind (N) = N_Range);
6149 return Expr_Value (Low_Bound (N));
6153 ------------------------
6154 -- Membership_Entries --
6155 ------------------------
6157 function Membership_Entries (N : Node_Id) return RList is
6159 if No (Next (N)) then
6160 return Membership_Entry (N);
6162 return Membership_Entry (N) or Membership_Entries (Next (N));
6164 end Membership_Entries;
6166 ----------------------
6167 -- Membership_Entry --
6168 ----------------------
6170 function Membership_Entry (N : Node_Id) return RList is
6178 if Nkind (N) = N_Range then
6179 if not Is_Static_Expression (Low_Bound (N))
6181 not Is_Static_Expression (High_Bound (N))
6185 SLo := Expr_Value (Low_Bound (N));
6186 SHi := Expr_Value (High_Bound (N));
6187 return RList'(1 => REnt
'(SLo, SHi));
6190 -- Static expression case
6192 elsif Is_Static_Expression (N) then
6193 Val := Expr_Value (N);
6194 return RList'(1 => REnt
'(Val, Val));
6196 -- Identifier (other than static expression) case
6198 else pragma Assert (Nkind (N) = N_Identifier);
6202 if Is_Type (Entity (N)) then
6204 -- If type has predicates, process them
6206 if Has_Predicates (Entity (N)) then
6207 return Stat_Pred (Entity (N));
6209 -- For static subtype without predicates, get range
6211 elsif Is_Static_Subtype (Entity (N)) then
6212 SLo := Expr_Value (Type_Low_Bound (Entity (N)));
6213 SHi := Expr_Value (Type_High_Bound (Entity (N)));
6214 return RList'(1 => REnt
'(SLo, SHi));
6216 -- Any other type makes us non-static
6222 -- Any other kind of identifier in predicate (e.g. a non-static
6223 -- expression value) means this is not a static predicate.
6229 end Membership_Entry;
6235 function Stat_Pred (Typ : Entity_Id) return RList is
6237 -- Not static if type does not have static predicates
6239 if not Has_Predicates (Typ)
6240 or else No (Static_Predicate (Typ))
6245 -- Otherwise we convert the predicate list to a range list
6248 Result : RList (1 .. List_Length (Static_Predicate (Typ)));
6252 P := First (Static_Predicate (Typ));
6253 for J in Result'Range loop
6254 Result (J) := REnt'(Lo_Val
(P
), Hi_Val
(P
));
6262 -- Start of processing for Build_Static_Predicate
6265 -- Now analyze the expression to see if it is a static predicate
6268 Ranges
: constant RList
:= Get_RList
(Expr
);
6269 -- Range list from expression if it is static
6274 -- Convert range list into a form for the static predicate. In the
6275 -- Ranges array, we just have raw ranges, these must be converted
6276 -- to properly typed and analyzed static expressions or range nodes.
6278 -- Note: here we limit ranges to the ranges of the subtype, so that
6279 -- a predicate is always false for values outside the subtype. That
6280 -- seems fine, such values are invalid anyway, and considering them
6281 -- to fail the predicate seems allowed and friendly, and furthermore
6282 -- simplifies processing for case statements and loops.
6286 for J
in Ranges
'Range loop
6288 Lo
: Uint
:= Ranges
(J
).Lo
;
6289 Hi
: Uint
:= Ranges
(J
).Hi
;
6292 -- Ignore completely out of range entry
6294 if Hi
< TLo
or else Lo
> THi
then
6297 -- Otherwise process entry
6300 -- Adjust out of range value to subtype range
6310 -- Convert range into required form
6313 Append_To
(Plist
, Build_Val
(Lo
));
6315 Append_To
(Plist
, Build_Range
(Lo
, Hi
));
6321 -- Processing was successful and all entries were static, so now we
6322 -- can store the result as the predicate list.
6324 Set_Static_Predicate
(Typ
, Plist
);
6326 -- The processing for static predicates put the expression into
6327 -- canonical form as a series of ranges. It also eliminated
6328 -- duplicates and collapsed and combined ranges. We might as well
6329 -- replace the alternatives list of the right operand of the
6330 -- membership test with the static predicate list, which will
6331 -- usually be more efficient.
6334 New_Alts
: constant List_Id
:= New_List
;
6339 Old_Node
:= First
(Plist
);
6340 while Present
(Old_Node
) loop
6341 New_Node
:= New_Copy
(Old_Node
);
6343 if Nkind
(New_Node
) = N_Range
then
6344 Set_Low_Bound
(New_Node
, New_Copy
(Low_Bound
(Old_Node
)));
6345 Set_High_Bound
(New_Node
, New_Copy
(High_Bound
(Old_Node
)));
6348 Append_To
(New_Alts
, New_Node
);
6352 -- If empty list, replace by False
6354 if Is_Empty_List
(New_Alts
) then
6355 Rewrite
(Expr
, New_Occurrence_Of
(Standard_False
, Loc
));
6357 -- Else replace by set membership test
6362 Left_Opnd
=> Make_Identifier
(Loc
, Nam
),
6363 Right_Opnd
=> Empty
,
6364 Alternatives
=> New_Alts
));
6366 -- Resolve new expression in function context
6368 Install_Formals
(Predicate_Function
(Typ
));
6369 Push_Scope
(Predicate_Function
(Typ
));
6370 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
6376 -- If non-static, return doing nothing
6381 end Build_Static_Predicate
;
6383 -----------------------------------------
6384 -- Check_Aspect_At_End_Of_Declarations --
6385 -----------------------------------------
6387 procedure Check_Aspect_At_End_Of_Declarations
(ASN
: Node_Id
) is
6388 Ent
: constant Entity_Id
:= Entity
(ASN
);
6389 Ident
: constant Node_Id
:= Identifier
(ASN
);
6390 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Chars
(Ident
));
6392 End_Decl_Expr
: constant Node_Id
:= Entity
(Ident
);
6393 -- Expression to be analyzed at end of declarations
6395 Freeze_Expr
: constant Node_Id
:= Expression
(ASN
);
6396 -- Expression from call to Check_Aspect_At_Freeze_Point
6398 T
: constant Entity_Id
:= Etype
(Freeze_Expr
);
6399 -- Type required for preanalyze call
6402 -- Set False if error
6404 -- On entry to this procedure, Entity (Ident) contains a copy of the
6405 -- original expression from the aspect, saved for this purpose, and
6406 -- but Expression (Ident) is a preanalyzed copy of the expression,
6407 -- preanalyzed just after the freeze point.
6409 procedure Check_Overloaded_Name
;
6410 -- For aspects whose expression is simply a name, this routine checks if
6411 -- the name is overloaded or not. If so, it verifies there is an
6412 -- interpretation that matches the entity obtained at the freeze point,
6413 -- otherwise the compiler complains.
6415 ---------------------------
6416 -- Check_Overloaded_Name --
6417 ---------------------------
6419 procedure Check_Overloaded_Name
is
6421 if not Is_Overloaded
(End_Decl_Expr
) then
6422 Err
:= Entity
(End_Decl_Expr
) /= Entity
(Freeze_Expr
);
6428 Index
: Interp_Index
;
6432 Get_First_Interp
(End_Decl_Expr
, Index
, It
);
6433 while Present
(It
.Typ
) loop
6434 if It
.Nam
= Entity
(Freeze_Expr
) then
6439 Get_Next_Interp
(Index
, It
);
6443 end Check_Overloaded_Name
;
6445 -- Start of processing for Check_Aspect_At_End_Of_Declarations
6448 -- Case of aspects Dimension, Dimension_System and Synchronization
6450 if A_Id
= Aspect_Synchronization
then
6453 -- Case of stream attributes, just have to compare entities. However,
6454 -- the expression is just a name (possibly overloaded), and there may
6455 -- be stream operations declared for unrelated types, so we just need
6456 -- to verify that one of these interpretations is the one available at
6457 -- at the freeze point.
6459 elsif A_Id
= Aspect_Input
or else
6460 A_Id
= Aspect_Output
or else
6461 A_Id
= Aspect_Read
or else
6464 Analyze
(End_Decl_Expr
);
6465 Check_Overloaded_Name
;
6467 elsif A_Id
= Aspect_Variable_Indexing
or else
6468 A_Id
= Aspect_Constant_Indexing
or else
6469 A_Id
= Aspect_Default_Iterator
or else
6470 A_Id
= Aspect_Iterator_Element
6472 -- Make type unfrozen before analysis, to prevent spurious errors
6473 -- about late attributes.
6475 Set_Is_Frozen
(Ent
, False);
6476 Analyze
(End_Decl_Expr
);
6477 Set_Is_Frozen
(Ent
, True);
6479 -- If the end of declarations comes before any other freeze
6480 -- point, the Freeze_Expr is not analyzed: no check needed.
6482 if Analyzed
(Freeze_Expr
) and then not In_Instance
then
6483 Check_Overloaded_Name
;
6491 -- In a generic context the aspect expressions have not been
6492 -- preanalyzed, so do it now. There are no conformance checks
6493 -- to perform in this case.
6496 Check_Aspect_At_Freeze_Point
(ASN
);
6499 -- The default values attributes may be defined in the private part,
6500 -- and the analysis of the expression may take place when only the
6501 -- partial view is visible. The expression must be scalar, so use
6502 -- the full view to resolve.
6504 elsif (A_Id
= Aspect_Default_Value
6506 A_Id
= Aspect_Default_Component_Value
)
6507 and then Is_Private_Type
(T
)
6509 Preanalyze_Spec_Expression
(End_Decl_Expr
, Full_View
(T
));
6511 Preanalyze_Spec_Expression
(End_Decl_Expr
, T
);
6514 Err
:= not Fully_Conformant_Expressions
(End_Decl_Expr
, Freeze_Expr
);
6517 -- Output error message if error
6521 ("visibility of aspect for& changes after freeze point",
6524 ("?info: & is frozen here, aspects evaluated at this point",
6525 Freeze_Node
(Ent
), Ent
);
6527 end Check_Aspect_At_End_Of_Declarations
;
6529 ----------------------------------
6530 -- Check_Aspect_At_Freeze_Point --
6531 ----------------------------------
6533 procedure Check_Aspect_At_Freeze_Point
(ASN
: Node_Id
) is
6534 Ident
: constant Node_Id
:= Identifier
(ASN
);
6535 -- Identifier (use Entity field to save expression)
6537 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Chars
(Ident
));
6539 T
: Entity_Id
:= Empty
;
6540 -- Type required for preanalyze call
6543 -- On entry to this procedure, Entity (Ident) contains a copy of the
6544 -- original expression from the aspect, saved for this purpose.
6546 -- On exit from this procedure Entity (Ident) is unchanged, still
6547 -- containing that copy, but Expression (Ident) is a preanalyzed copy
6548 -- of the expression, preanalyzed just after the freeze point.
6550 -- Make a copy of the expression to be preanalyed
6552 Set_Expression
(ASN
, New_Copy_Tree
(Entity
(Ident
)));
6554 -- Find type for preanalyze call
6558 -- No_Aspect should be impossible
6561 raise Program_Error
;
6563 -- Aspects taking an optional boolean argument
6565 when Boolean_Aspects |
6566 Library_Unit_Aspects
=>
6567 T
:= Standard_Boolean
;
6569 when Aspect_Attach_Handler
=>
6570 T
:= RTE
(RE_Interrupt_ID
);
6572 when Aspect_Convention
=>
6575 -- Default_Value is resolved with the type entity in question
6577 when Aspect_Default_Value
=>
6580 -- Default_Component_Value is resolved with the component type
6582 when Aspect_Default_Component_Value
=>
6583 T
:= Component_Type
(Entity
(ASN
));
6585 -- Aspects corresponding to attribute definition clauses
6587 when Aspect_Address
=>
6588 T
:= RTE
(RE_Address
);
6590 when Aspect_Bit_Order | Aspect_Scalar_Storage_Order
=>
6591 T
:= RTE
(RE_Bit_Order
);
6594 T
:= RTE
(RE_CPU_Range
);
6596 when Aspect_Dispatching_Domain
=>
6597 T
:= RTE
(RE_Dispatching_Domain
);
6599 when Aspect_External_Tag
=>
6600 T
:= Standard_String
;
6602 when Aspect_External_Name
=>
6603 T
:= Standard_String
;
6605 when Aspect_Link_Name
=>
6606 T
:= Standard_String
;
6608 when Aspect_Priority | Aspect_Interrupt_Priority
=>
6609 T
:= Standard_Integer
;
6611 when Aspect_Small
=>
6612 T
:= Universal_Real
;
6614 -- For a simple storage pool, we have to retrieve the type of the
6615 -- pool object associated with the aspect's corresponding attribute
6616 -- definition clause.
6618 when Aspect_Simple_Storage_Pool
=>
6619 T
:= Etype
(Expression
(Aspect_Rep_Item
(ASN
)));
6621 when Aspect_Storage_Pool
=>
6622 T
:= Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
));
6624 when Aspect_Alignment |
6625 Aspect_Component_Size |
6626 Aspect_Machine_Radix |
6627 Aspect_Object_Size |
6629 Aspect_Storage_Size |
6630 Aspect_Stream_Size |
6631 Aspect_Value_Size
=>
6634 when Aspect_Synchronization
=>
6637 -- Special case, the expression of these aspects is just an entity
6638 -- that does not need any resolution, so just analyze.
6647 Analyze
(Expression
(ASN
));
6650 -- Same for Iterator aspects, where the expression is a function
6651 -- name. Legality rules are checked separately.
6653 when Aspect_Constant_Indexing |
6654 Aspect_Default_Iterator |
6655 Aspect_Iterator_Element |
6656 Aspect_Variable_Indexing
=>
6657 Analyze
(Expression
(ASN
));
6660 -- Invariant/Predicate take boolean expressions
6662 when Aspect_Dynamic_Predicate |
6665 Aspect_Static_Predicate |
6666 Aspect_Type_Invariant
=>
6667 T
:= Standard_Boolean
;
6669 -- Here is the list of aspects that don't require delay analysis.
6671 when Aspect_Contract_Case |
6673 Aspect_Dimension_System |
6674 Aspect_Implicit_Dereference |
6676 Aspect_Postcondition |
6678 Aspect_Precondition |
6680 raise Program_Error
;
6684 -- Do the preanalyze call
6686 Preanalyze_Spec_Expression
(Expression
(ASN
), T
);
6687 end Check_Aspect_At_Freeze_Point
;
6689 -----------------------------------
6690 -- Check_Constant_Address_Clause --
6691 -----------------------------------
6693 procedure Check_Constant_Address_Clause
6697 procedure Check_At_Constant_Address
(Nod
: Node_Id
);
6698 -- Checks that the given node N represents a name whose 'Address is
6699 -- constant (in the same sense as OK_Constant_Address_Clause, i.e. the
6700 -- address value is the same at the point of declaration of U_Ent and at
6701 -- the time of elaboration of the address clause.
6703 procedure Check_Expr_Constants
(Nod
: Node_Id
);
6704 -- Checks that Nod meets the requirements for a constant address clause
6705 -- in the sense of the enclosing procedure.
6707 procedure Check_List_Constants
(Lst
: List_Id
);
6708 -- Check that all elements of list Lst meet the requirements for a
6709 -- constant address clause in the sense of the enclosing procedure.
6711 -------------------------------
6712 -- Check_At_Constant_Address --
6713 -------------------------------
6715 procedure Check_At_Constant_Address
(Nod
: Node_Id
) is
6717 if Is_Entity_Name
(Nod
) then
6718 if Present
(Address_Clause
(Entity
((Nod
)))) then
6720 ("invalid address clause for initialized object &!",
6723 ("address for& cannot" &
6724 " depend on another address clause! (RM 13.1(22))!",
6727 elsif In_Same_Source_Unit
(Entity
(Nod
), U_Ent
)
6728 and then Sloc
(U_Ent
) < Sloc
(Entity
(Nod
))
6731 ("invalid address clause for initialized object &!",
6733 Error_Msg_Node_2
:= U_Ent
;
6735 ("\& must be defined before & (RM 13.1(22))!",
6739 elsif Nkind
(Nod
) = N_Selected_Component
then
6741 T
: constant Entity_Id
:= Etype
(Prefix
(Nod
));
6744 if (Is_Record_Type
(T
)
6745 and then Has_Discriminants
(T
))
6748 and then Is_Record_Type
(Designated_Type
(T
))
6749 and then Has_Discriminants
(Designated_Type
(T
)))
6752 ("invalid address clause for initialized object &!",
6755 ("\address cannot depend on component" &
6756 " of discriminated record (RM 13.1(22))!",
6759 Check_At_Constant_Address
(Prefix
(Nod
));
6763 elsif Nkind
(Nod
) = N_Indexed_Component
then
6764 Check_At_Constant_Address
(Prefix
(Nod
));
6765 Check_List_Constants
(Expressions
(Nod
));
6768 Check_Expr_Constants
(Nod
);
6770 end Check_At_Constant_Address
;
6772 --------------------------
6773 -- Check_Expr_Constants --
6774 --------------------------
6776 procedure Check_Expr_Constants
(Nod
: Node_Id
) is
6777 Loc_U_Ent
: constant Source_Ptr
:= Sloc
(U_Ent
);
6778 Ent
: Entity_Id
:= Empty
;
6781 if Nkind
(Nod
) in N_Has_Etype
6782 and then Etype
(Nod
) = Any_Type
6788 when N_Empty | N_Error
=>
6791 when N_Identifier | N_Expanded_Name
=>
6792 Ent
:= Entity
(Nod
);
6794 -- We need to look at the original node if it is different
6795 -- from the node, since we may have rewritten things and
6796 -- substituted an identifier representing the rewrite.
6798 if Original_Node
(Nod
) /= Nod
then
6799 Check_Expr_Constants
(Original_Node
(Nod
));
6801 -- If the node is an object declaration without initial
6802 -- value, some code has been expanded, and the expression
6803 -- is not constant, even if the constituents might be
6804 -- acceptable, as in A'Address + offset.
6806 if Ekind
(Ent
) = E_Variable
6808 Nkind
(Declaration_Node
(Ent
)) = N_Object_Declaration
6810 No
(Expression
(Declaration_Node
(Ent
)))
6813 ("invalid address clause for initialized object &!",
6816 -- If entity is constant, it may be the result of expanding
6817 -- a check. We must verify that its declaration appears
6818 -- before the object in question, else we also reject the
6821 elsif Ekind
(Ent
) = E_Constant
6822 and then In_Same_Source_Unit
(Ent
, U_Ent
)
6823 and then Sloc
(Ent
) > Loc_U_Ent
6826 ("invalid address clause for initialized object &!",
6833 -- Otherwise look at the identifier and see if it is OK
6835 if Ekind_In
(Ent
, E_Named_Integer
, E_Named_Real
)
6836 or else Is_Type
(Ent
)
6841 Ekind
(Ent
) = E_Constant
6843 Ekind
(Ent
) = E_In_Parameter
6845 -- This is the case where we must have Ent defined before
6846 -- U_Ent. Clearly if they are in different units this
6847 -- requirement is met since the unit containing Ent is
6848 -- already processed.
6850 if not In_Same_Source_Unit
(Ent
, U_Ent
) then
6853 -- Otherwise location of Ent must be before the location
6854 -- of U_Ent, that's what prior defined means.
6856 elsif Sloc
(Ent
) < Loc_U_Ent
then
6861 ("invalid address clause for initialized object &!",
6863 Error_Msg_Node_2
:= U_Ent
;
6865 ("\& must be defined before & (RM 13.1(22))!",
6869 elsif Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
6870 Check_Expr_Constants
(Original_Node
(Nod
));
6874 ("invalid address clause for initialized object &!",
6877 if Comes_From_Source
(Ent
) then
6879 ("\reference to variable& not allowed"
6880 & " (RM 13.1(22))!", Nod
, Ent
);
6883 ("non-static expression not allowed"
6884 & " (RM 13.1(22))!", Nod
);
6888 when N_Integer_Literal
=>
6890 -- If this is a rewritten unchecked conversion, in a system
6891 -- where Address is an integer type, always use the base type
6892 -- for a literal value. This is user-friendly and prevents
6893 -- order-of-elaboration issues with instances of unchecked
6896 if Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
6897 Set_Etype
(Nod
, Base_Type
(Etype
(Nod
)));
6900 when N_Real_Literal |
6902 N_Character_Literal
=>
6906 Check_Expr_Constants
(Low_Bound
(Nod
));
6907 Check_Expr_Constants
(High_Bound
(Nod
));
6909 when N_Explicit_Dereference
=>
6910 Check_Expr_Constants
(Prefix
(Nod
));
6912 when N_Indexed_Component
=>
6913 Check_Expr_Constants
(Prefix
(Nod
));
6914 Check_List_Constants
(Expressions
(Nod
));
6917 Check_Expr_Constants
(Prefix
(Nod
));
6918 Check_Expr_Constants
(Discrete_Range
(Nod
));
6920 when N_Selected_Component
=>
6921 Check_Expr_Constants
(Prefix
(Nod
));
6923 when N_Attribute_Reference
=>
6924 if Attribute_Name
(Nod
) = Name_Address
6926 Attribute_Name
(Nod
) = Name_Access
6928 Attribute_Name
(Nod
) = Name_Unchecked_Access
6930 Attribute_Name
(Nod
) = Name_Unrestricted_Access
6932 Check_At_Constant_Address
(Prefix
(Nod
));
6935 Check_Expr_Constants
(Prefix
(Nod
));
6936 Check_List_Constants
(Expressions
(Nod
));
6940 Check_List_Constants
(Component_Associations
(Nod
));
6941 Check_List_Constants
(Expressions
(Nod
));
6943 when N_Component_Association
=>
6944 Check_Expr_Constants
(Expression
(Nod
));
6946 when N_Extension_Aggregate
=>
6947 Check_Expr_Constants
(Ancestor_Part
(Nod
));
6948 Check_List_Constants
(Component_Associations
(Nod
));
6949 Check_List_Constants
(Expressions
(Nod
));
6954 when N_Binary_Op | N_Short_Circuit | N_Membership_Test
=>
6955 Check_Expr_Constants
(Left_Opnd
(Nod
));
6956 Check_Expr_Constants
(Right_Opnd
(Nod
));
6959 Check_Expr_Constants
(Right_Opnd
(Nod
));
6961 when N_Type_Conversion |
6962 N_Qualified_Expression |
6964 Check_Expr_Constants
(Expression
(Nod
));
6966 when N_Unchecked_Type_Conversion
=>
6967 Check_Expr_Constants
(Expression
(Nod
));
6969 -- If this is a rewritten unchecked conversion, subtypes in
6970 -- this node are those created within the instance. To avoid
6971 -- order of elaboration issues, replace them with their base
6972 -- types. Note that address clauses can cause order of
6973 -- elaboration problems because they are elaborated by the
6974 -- back-end at the point of definition, and may mention
6975 -- entities declared in between (as long as everything is
6976 -- static). It is user-friendly to allow unchecked conversions
6979 if Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
6980 Set_Etype
(Expression
(Nod
),
6981 Base_Type
(Etype
(Expression
(Nod
))));
6982 Set_Etype
(Nod
, Base_Type
(Etype
(Nod
)));
6985 when N_Function_Call
=>
6986 if not Is_Pure
(Entity
(Name
(Nod
))) then
6988 ("invalid address clause for initialized object &!",
6992 ("\function & is not pure (RM 13.1(22))!",
6993 Nod
, Entity
(Name
(Nod
)));
6996 Check_List_Constants
(Parameter_Associations
(Nod
));
6999 when N_Parameter_Association
=>
7000 Check_Expr_Constants
(Explicit_Actual_Parameter
(Nod
));
7004 ("invalid address clause for initialized object &!",
7007 ("\must be constant defined before& (RM 13.1(22))!",
7010 end Check_Expr_Constants
;
7012 --------------------------
7013 -- Check_List_Constants --
7014 --------------------------
7016 procedure Check_List_Constants
(Lst
: List_Id
) is
7020 if Present
(Lst
) then
7021 Nod1
:= First
(Lst
);
7022 while Present
(Nod1
) loop
7023 Check_Expr_Constants
(Nod1
);
7027 end Check_List_Constants
;
7029 -- Start of processing for Check_Constant_Address_Clause
7032 -- If rep_clauses are to be ignored, no need for legality checks. In
7033 -- particular, no need to pester user about rep clauses that violate
7034 -- the rule on constant addresses, given that these clauses will be
7035 -- removed by Freeze before they reach the back end.
7037 if not Ignore_Rep_Clauses
then
7038 Check_Expr_Constants
(Expr
);
7040 end Check_Constant_Address_Clause
;
7042 ----------------------------------------
7043 -- Check_Record_Representation_Clause --
7044 ----------------------------------------
7046 procedure Check_Record_Representation_Clause
(N
: Node_Id
) is
7047 Loc
: constant Source_Ptr
:= Sloc
(N
);
7048 Ident
: constant Node_Id
:= Identifier
(N
);
7049 Rectype
: Entity_Id
;
7054 Hbit
: Uint
:= Uint_0
;
7058 Max_Bit_So_Far
: Uint
;
7059 -- Records the maximum bit position so far. If all field positions
7060 -- are monotonically increasing, then we can skip the circuit for
7061 -- checking for overlap, since no overlap is possible.
7063 Tagged_Parent
: Entity_Id
:= Empty
;
7064 -- This is set in the case of a derived tagged type for which we have
7065 -- Is_Fully_Repped_Tagged_Type True (indicating that all components are
7066 -- positioned by record representation clauses). In this case we must
7067 -- check for overlap between components of this tagged type, and the
7068 -- components of its parent. Tagged_Parent will point to this parent
7069 -- type. For all other cases Tagged_Parent is left set to Empty.
7071 Parent_Last_Bit
: Uint
;
7072 -- Relevant only if Tagged_Parent is set, Parent_Last_Bit indicates the
7073 -- last bit position for any field in the parent type. We only need to
7074 -- check overlap for fields starting below this point.
7076 Overlap_Check_Required
: Boolean;
7077 -- Used to keep track of whether or not an overlap check is required
7079 Overlap_Detected
: Boolean := False;
7080 -- Set True if an overlap is detected
7082 Ccount
: Natural := 0;
7083 -- Number of component clauses in record rep clause
7085 procedure Check_Component_Overlap
(C1_Ent
, C2_Ent
: Entity_Id
);
7086 -- Given two entities for record components or discriminants, checks
7087 -- if they have overlapping component clauses and issues errors if so.
7089 procedure Find_Component
;
7090 -- Finds component entity corresponding to current component clause (in
7091 -- CC), and sets Comp to the entity, and Fbit/Lbit to the zero origin
7092 -- start/stop bits for the field. If there is no matching component or
7093 -- if the matching component does not have a component clause, then
7094 -- that's an error and Comp is set to Empty, but no error message is
7095 -- issued, since the message was already given. Comp is also set to
7096 -- Empty if the current "component clause" is in fact a pragma.
7098 -----------------------------
7099 -- Check_Component_Overlap --
7100 -----------------------------
7102 procedure Check_Component_Overlap
(C1_Ent
, C2_Ent
: Entity_Id
) is
7103 CC1
: constant Node_Id
:= Component_Clause
(C1_Ent
);
7104 CC2
: constant Node_Id
:= Component_Clause
(C2_Ent
);
7107 if Present
(CC1
) and then Present
(CC2
) then
7109 -- Exclude odd case where we have two tag fields in the same
7110 -- record, both at location zero. This seems a bit strange, but
7111 -- it seems to happen in some circumstances, perhaps on an error.
7113 if Chars
(C1_Ent
) = Name_uTag
7115 Chars
(C2_Ent
) = Name_uTag
7120 -- Here we check if the two fields overlap
7123 S1
: constant Uint
:= Component_Bit_Offset
(C1_Ent
);
7124 S2
: constant Uint
:= Component_Bit_Offset
(C2_Ent
);
7125 E1
: constant Uint
:= S1
+ Esize
(C1_Ent
);
7126 E2
: constant Uint
:= S2
+ Esize
(C2_Ent
);
7129 if E2
<= S1
or else E1
<= S2
then
7132 Error_Msg_Node_2
:= Component_Name
(CC2
);
7133 Error_Msg_Sloc
:= Sloc
(Error_Msg_Node_2
);
7134 Error_Msg_Node_1
:= Component_Name
(CC1
);
7136 ("component& overlaps & #", Component_Name
(CC1
));
7137 Overlap_Detected
:= True;
7141 end Check_Component_Overlap
;
7143 --------------------
7144 -- Find_Component --
7145 --------------------
7147 procedure Find_Component
is
7149 procedure Search_Component
(R
: Entity_Id
);
7150 -- Search components of R for a match. If found, Comp is set.
7152 ----------------------
7153 -- Search_Component --
7154 ----------------------
7156 procedure Search_Component
(R
: Entity_Id
) is
7158 Comp
:= First_Component_Or_Discriminant
(R
);
7159 while Present
(Comp
) loop
7161 -- Ignore error of attribute name for component name (we
7162 -- already gave an error message for this, so no need to
7165 if Nkind
(Component_Name
(CC
)) = N_Attribute_Reference
then
7168 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
7171 Next_Component_Or_Discriminant
(Comp
);
7173 end Search_Component
;
7175 -- Start of processing for Find_Component
7178 -- Return with Comp set to Empty if we have a pragma
7180 if Nkind
(CC
) = N_Pragma
then
7185 -- Search current record for matching component
7187 Search_Component
(Rectype
);
7189 -- If not found, maybe component of base type that is absent from
7190 -- statically constrained first subtype.
7193 Search_Component
(Base_Type
(Rectype
));
7196 -- If no component, or the component does not reference the component
7197 -- clause in question, then there was some previous error for which
7198 -- we already gave a message, so just return with Comp Empty.
7201 or else Component_Clause
(Comp
) /= CC
7205 -- Normal case where we have a component clause
7208 Fbit
:= Component_Bit_Offset
(Comp
);
7209 Lbit
:= Fbit
+ Esize
(Comp
) - 1;
7213 -- Start of processing for Check_Record_Representation_Clause
7217 Rectype
:= Entity
(Ident
);
7219 if Rectype
= Any_Type
then
7222 Rectype
:= Underlying_Type
(Rectype
);
7225 -- See if we have a fully repped derived tagged type
7228 PS
: constant Entity_Id
:= Parent_Subtype
(Rectype
);
7231 if Present
(PS
) and then Is_Fully_Repped_Tagged_Type
(PS
) then
7232 Tagged_Parent
:= PS
;
7234 -- Find maximum bit of any component of the parent type
7236 Parent_Last_Bit
:= UI_From_Int
(System_Address_Size
- 1);
7237 Pcomp
:= First_Entity
(Tagged_Parent
);
7238 while Present
(Pcomp
) loop
7239 if Ekind_In
(Pcomp
, E_Discriminant
, E_Component
) then
7240 if Component_Bit_Offset
(Pcomp
) /= No_Uint
7241 and then Known_Static_Esize
(Pcomp
)
7246 Component_Bit_Offset
(Pcomp
) + Esize
(Pcomp
) - 1);
7249 Next_Entity
(Pcomp
);
7255 -- All done if no component clauses
7257 CC
:= First
(Component_Clauses
(N
));
7263 -- If a tag is present, then create a component clause that places it
7264 -- at the start of the record (otherwise gigi may place it after other
7265 -- fields that have rep clauses).
7267 Fent
:= First_Entity
(Rectype
);
7269 if Nkind
(Fent
) = N_Defining_Identifier
7270 and then Chars
(Fent
) = Name_uTag
7272 Set_Component_Bit_Offset
(Fent
, Uint_0
);
7273 Set_Normalized_Position
(Fent
, Uint_0
);
7274 Set_Normalized_First_Bit
(Fent
, Uint_0
);
7275 Set_Normalized_Position_Max
(Fent
, Uint_0
);
7276 Init_Esize
(Fent
, System_Address_Size
);
7278 Set_Component_Clause
(Fent
,
7279 Make_Component_Clause
(Loc
,
7280 Component_Name
=> Make_Identifier
(Loc
, Name_uTag
),
7282 Position
=> Make_Integer_Literal
(Loc
, Uint_0
),
7283 First_Bit
=> Make_Integer_Literal
(Loc
, Uint_0
),
7285 Make_Integer_Literal
(Loc
,
7286 UI_From_Int
(System_Address_Size
))));
7288 Ccount
:= Ccount
+ 1;
7291 Max_Bit_So_Far
:= Uint_Minus_1
;
7292 Overlap_Check_Required
:= False;
7294 -- Process the component clauses
7296 while Present
(CC
) loop
7299 if Present
(Comp
) then
7300 Ccount
:= Ccount
+ 1;
7302 -- We need a full overlap check if record positions non-monotonic
7304 if Fbit
<= Max_Bit_So_Far
then
7305 Overlap_Check_Required
:= True;
7308 Max_Bit_So_Far
:= Lbit
;
7310 -- Check bit position out of range of specified size
7312 if Has_Size_Clause
(Rectype
)
7313 and then RM_Size
(Rectype
) <= Lbit
7316 ("bit number out of range of specified size",
7319 -- Check for overlap with tag field
7322 if Is_Tagged_Type
(Rectype
)
7323 and then Fbit
< System_Address_Size
7326 ("component overlaps tag field of&",
7327 Component_Name
(CC
), Rectype
);
7328 Overlap_Detected
:= True;
7336 -- Check parent overlap if component might overlap parent field
7338 if Present
(Tagged_Parent
)
7339 and then Fbit
<= Parent_Last_Bit
7341 Pcomp
:= First_Component_Or_Discriminant
(Tagged_Parent
);
7342 while Present
(Pcomp
) loop
7343 if not Is_Tag
(Pcomp
)
7344 and then Chars
(Pcomp
) /= Name_uParent
7346 Check_Component_Overlap
(Comp
, Pcomp
);
7349 Next_Component_Or_Discriminant
(Pcomp
);
7357 -- Now that we have processed all the component clauses, check for
7358 -- overlap. We have to leave this till last, since the components can
7359 -- appear in any arbitrary order in the representation clause.
7361 -- We do not need this check if all specified ranges were monotonic,
7362 -- as recorded by Overlap_Check_Required being False at this stage.
7364 -- This first section checks if there are any overlapping entries at
7365 -- all. It does this by sorting all entries and then seeing if there are
7366 -- any overlaps. If there are none, then that is decisive, but if there
7367 -- are overlaps, they may still be OK (they may result from fields in
7368 -- different variants).
7370 if Overlap_Check_Required
then
7371 Overlap_Check1
: declare
7373 OC_Fbit
: array (0 .. Ccount
) of Uint
;
7374 -- First-bit values for component clauses, the value is the offset
7375 -- of the first bit of the field from start of record. The zero
7376 -- entry is for use in sorting.
7378 OC_Lbit
: array (0 .. Ccount
) of Uint
;
7379 -- Last-bit values for component clauses, the value is the offset
7380 -- of the last bit of the field from start of record. The zero
7381 -- entry is for use in sorting.
7383 OC_Count
: Natural := 0;
7384 -- Count of entries in OC_Fbit and OC_Lbit
7386 function OC_Lt
(Op1
, Op2
: Natural) return Boolean;
7387 -- Compare routine for Sort
7389 procedure OC_Move
(From
: Natural; To
: Natural);
7390 -- Move routine for Sort
7392 package Sorting
is new GNAT
.Heap_Sort_G
(OC_Move
, OC_Lt
);
7398 function OC_Lt
(Op1
, Op2
: Natural) return Boolean is
7400 return OC_Fbit
(Op1
) < OC_Fbit
(Op2
);
7407 procedure OC_Move
(From
: Natural; To
: Natural) is
7409 OC_Fbit
(To
) := OC_Fbit
(From
);
7410 OC_Lbit
(To
) := OC_Lbit
(From
);
7413 -- Start of processing for Overlap_Check
7416 CC
:= First
(Component_Clauses
(N
));
7417 while Present
(CC
) loop
7419 -- Exclude component clause already marked in error
7421 if not Error_Posted
(CC
) then
7424 if Present
(Comp
) then
7425 OC_Count
:= OC_Count
+ 1;
7426 OC_Fbit
(OC_Count
) := Fbit
;
7427 OC_Lbit
(OC_Count
) := Lbit
;
7434 Sorting
.Sort
(OC_Count
);
7436 Overlap_Check_Required
:= False;
7437 for J
in 1 .. OC_Count
- 1 loop
7438 if OC_Lbit
(J
) >= OC_Fbit
(J
+ 1) then
7439 Overlap_Check_Required
:= True;
7446 -- If Overlap_Check_Required is still True, then we have to do the full
7447 -- scale overlap check, since we have at least two fields that do
7448 -- overlap, and we need to know if that is OK since they are in
7449 -- different variant, or whether we have a definite problem.
7451 if Overlap_Check_Required
then
7452 Overlap_Check2
: declare
7453 C1_Ent
, C2_Ent
: Entity_Id
;
7454 -- Entities of components being checked for overlap
7457 -- Component_List node whose Component_Items are being checked
7460 -- Component declaration for component being checked
7463 C1_Ent
:= First_Entity
(Base_Type
(Rectype
));
7465 -- Loop through all components in record. For each component check
7466 -- for overlap with any of the preceding elements on the component
7467 -- list containing the component and also, if the component is in
7468 -- a variant, check against components outside the case structure.
7469 -- This latter test is repeated recursively up the variant tree.
7471 Main_Component_Loop
: while Present
(C1_Ent
) loop
7472 if not Ekind_In
(C1_Ent
, E_Component
, E_Discriminant
) then
7473 goto Continue_Main_Component_Loop
;
7476 -- Skip overlap check if entity has no declaration node. This
7477 -- happens with discriminants in constrained derived types.
7478 -- Possibly we are missing some checks as a result, but that
7479 -- does not seem terribly serious.
7481 if No
(Declaration_Node
(C1_Ent
)) then
7482 goto Continue_Main_Component_Loop
;
7485 Clist
:= Parent
(List_Containing
(Declaration_Node
(C1_Ent
)));
7487 -- Loop through component lists that need checking. Check the
7488 -- current component list and all lists in variants above us.
7490 Component_List_Loop
: loop
7492 -- If derived type definition, go to full declaration
7493 -- If at outer level, check discriminants if there are any.
7495 if Nkind
(Clist
) = N_Derived_Type_Definition
then
7496 Clist
:= Parent
(Clist
);
7499 -- Outer level of record definition, check discriminants
7501 if Nkind_In
(Clist
, N_Full_Type_Declaration
,
7502 N_Private_Type_Declaration
)
7504 if Has_Discriminants
(Defining_Identifier
(Clist
)) then
7506 First_Discriminant
(Defining_Identifier
(Clist
));
7507 while Present
(C2_Ent
) loop
7508 exit when C1_Ent
= C2_Ent
;
7509 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
7510 Next_Discriminant
(C2_Ent
);
7514 -- Record extension case
7516 elsif Nkind
(Clist
) = N_Derived_Type_Definition
then
7519 -- Otherwise check one component list
7522 Citem
:= First
(Component_Items
(Clist
));
7523 while Present
(Citem
) loop
7524 if Nkind
(Citem
) = N_Component_Declaration
then
7525 C2_Ent
:= Defining_Identifier
(Citem
);
7526 exit when C1_Ent
= C2_Ent
;
7527 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
7534 -- Check for variants above us (the parent of the Clist can
7535 -- be a variant, in which case its parent is a variant part,
7536 -- and the parent of the variant part is a component list
7537 -- whose components must all be checked against the current
7538 -- component for overlap).
7540 if Nkind
(Parent
(Clist
)) = N_Variant
then
7541 Clist
:= Parent
(Parent
(Parent
(Clist
)));
7543 -- Check for possible discriminant part in record, this
7544 -- is treated essentially as another level in the
7545 -- recursion. For this case the parent of the component
7546 -- list is the record definition, and its parent is the
7547 -- full type declaration containing the discriminant
7550 elsif Nkind
(Parent
(Clist
)) = N_Record_Definition
then
7551 Clist
:= Parent
(Parent
((Clist
)));
7553 -- If neither of these two cases, we are at the top of
7557 exit Component_List_Loop
;
7559 end loop Component_List_Loop
;
7561 <<Continue_Main_Component_Loop
>>
7562 Next_Entity
(C1_Ent
);
7564 end loop Main_Component_Loop
;
7568 -- The following circuit deals with warning on record holes (gaps). We
7569 -- skip this check if overlap was detected, since it makes sense for the
7570 -- programmer to fix this illegality before worrying about warnings.
7572 if not Overlap_Detected
and Warn_On_Record_Holes
then
7573 Record_Hole_Check
: declare
7574 Decl
: constant Node_Id
:= Declaration_Node
(Base_Type
(Rectype
));
7575 -- Full declaration of record type
7577 procedure Check_Component_List
7581 -- Check component list CL for holes. The starting bit should be
7582 -- Sbit. which is zero for the main record component list and set
7583 -- appropriately for recursive calls for variants. DS is set to
7584 -- a list of discriminant specifications to be included in the
7585 -- consideration of components. It is No_List if none to consider.
7587 --------------------------
7588 -- Check_Component_List --
7589 --------------------------
7591 procedure Check_Component_List
7599 Compl
:= Integer (List_Length
(Component_Items
(CL
)));
7601 if DS
/= No_List
then
7602 Compl
:= Compl
+ Integer (List_Length
(DS
));
7606 Comps
: array (Natural range 0 .. Compl
) of Entity_Id
;
7607 -- Gather components (zero entry is for sort routine)
7609 Ncomps
: Natural := 0;
7610 -- Number of entries stored in Comps (starting at Comps (1))
7613 -- One component item or discriminant specification
7616 -- Starting bit for next component
7624 function Lt
(Op1
, Op2
: Natural) return Boolean;
7625 -- Compare routine for Sort
7627 procedure Move
(From
: Natural; To
: Natural);
7628 -- Move routine for Sort
7630 package Sorting
is new GNAT
.Heap_Sort_G
(Move
, Lt
);
7636 function Lt
(Op1
, Op2
: Natural) return Boolean is
7638 return Component_Bit_Offset
(Comps
(Op1
))
7640 Component_Bit_Offset
(Comps
(Op2
));
7647 procedure Move
(From
: Natural; To
: Natural) is
7649 Comps
(To
) := Comps
(From
);
7653 -- Gather discriminants into Comp
7655 if DS
/= No_List
then
7656 Citem
:= First
(DS
);
7657 while Present
(Citem
) loop
7658 if Nkind
(Citem
) = N_Discriminant_Specification
then
7660 Ent
: constant Entity_Id
:=
7661 Defining_Identifier
(Citem
);
7663 if Ekind
(Ent
) = E_Discriminant
then
7664 Ncomps
:= Ncomps
+ 1;
7665 Comps
(Ncomps
) := Ent
;
7674 -- Gather component entities into Comp
7676 Citem
:= First
(Component_Items
(CL
));
7677 while Present
(Citem
) loop
7678 if Nkind
(Citem
) = N_Component_Declaration
then
7679 Ncomps
:= Ncomps
+ 1;
7680 Comps
(Ncomps
) := Defining_Identifier
(Citem
);
7686 -- Now sort the component entities based on the first bit.
7687 -- Note we already know there are no overlapping components.
7689 Sorting
.Sort
(Ncomps
);
7691 -- Loop through entries checking for holes
7694 for J
in 1 .. Ncomps
loop
7696 Error_Msg_Uint_1
:= Component_Bit_Offset
(CEnt
) - Nbit
;
7698 if Error_Msg_Uint_1
> 0 then
7700 ("?^-bit gap before component&",
7701 Component_Name
(Component_Clause
(CEnt
)), CEnt
);
7704 Nbit
:= Component_Bit_Offset
(CEnt
) + Esize
(CEnt
);
7707 -- Process variant parts recursively if present
7709 if Present
(Variant_Part
(CL
)) then
7710 Variant
:= First
(Variants
(Variant_Part
(CL
)));
7711 while Present
(Variant
) loop
7712 Check_Component_List
7713 (Component_List
(Variant
), Nbit
, No_List
);
7718 end Check_Component_List
;
7720 -- Start of processing for Record_Hole_Check
7727 if Is_Tagged_Type
(Rectype
) then
7728 Sbit
:= UI_From_Int
(System_Address_Size
);
7733 if Nkind
(Decl
) = N_Full_Type_Declaration
7734 and then Nkind
(Type_Definition
(Decl
)) = N_Record_Definition
7736 Check_Component_List
7737 (Component_List
(Type_Definition
(Decl
)),
7739 Discriminant_Specifications
(Decl
));
7742 end Record_Hole_Check
;
7745 -- For records that have component clauses for all components, and whose
7746 -- size is less than or equal to 32, we need to know the size in the
7747 -- front end to activate possible packed array processing where the
7748 -- component type is a record.
7750 -- At this stage Hbit + 1 represents the first unused bit from all the
7751 -- component clauses processed, so if the component clauses are
7752 -- complete, then this is the length of the record.
7754 -- For records longer than System.Storage_Unit, and for those where not
7755 -- all components have component clauses, the back end determines the
7756 -- length (it may for example be appropriate to round up the size
7757 -- to some convenient boundary, based on alignment considerations, etc).
7759 if Unknown_RM_Size
(Rectype
) and then Hbit
+ 1 <= 32 then
7761 -- Nothing to do if at least one component has no component clause
7763 Comp
:= First_Component_Or_Discriminant
(Rectype
);
7764 while Present
(Comp
) loop
7765 exit when No
(Component_Clause
(Comp
));
7766 Next_Component_Or_Discriminant
(Comp
);
7769 -- If we fall out of loop, all components have component clauses
7770 -- and so we can set the size to the maximum value.
7773 Set_RM_Size
(Rectype
, Hbit
+ 1);
7776 end Check_Record_Representation_Clause
;
7782 procedure Check_Size
7786 Biased
: out Boolean)
7788 UT
: constant Entity_Id
:= Underlying_Type
(T
);
7794 -- Reject patently improper size values.
7796 if Is_Elementary_Type
(T
)
7797 and then Siz
> UI_From_Int
(Int
'Last)
7799 Error_Msg_N
("Size value too large for elementary type", N
);
7801 if Nkind
(Original_Node
(N
)) = N_Op_Expon
then
7803 ("\maybe '* was meant, rather than '*'*", Original_Node
(N
));
7807 -- Dismiss cases for generic types or types with previous errors
7810 or else UT
= Any_Type
7811 or else Is_Generic_Type
(UT
)
7812 or else Is_Generic_Type
(Root_Type
(UT
))
7816 -- Check case of bit packed array
7818 elsif Is_Array_Type
(UT
)
7819 and then Known_Static_Component_Size
(UT
)
7820 and then Is_Bit_Packed_Array
(UT
)
7828 Asiz
:= Component_Size
(UT
);
7829 Indx
:= First_Index
(UT
);
7831 Ityp
:= Etype
(Indx
);
7833 -- If non-static bound, then we are not in the business of
7834 -- trying to check the length, and indeed an error will be
7835 -- issued elsewhere, since sizes of non-static array types
7836 -- cannot be set implicitly or explicitly.
7838 if not Is_Static_Subtype
(Ityp
) then
7842 -- Otherwise accumulate next dimension
7844 Asiz
:= Asiz
* (Expr_Value
(Type_High_Bound
(Ityp
)) -
7845 Expr_Value
(Type_Low_Bound
(Ityp
)) +
7849 exit when No
(Indx
);
7855 Error_Msg_Uint_1
:= Asiz
;
7857 ("size for& too small, minimum allowed is ^", N
, T
);
7858 Set_Esize
(T
, Asiz
);
7859 Set_RM_Size
(T
, Asiz
);
7863 -- All other composite types are ignored
7865 elsif Is_Composite_Type
(UT
) then
7868 -- For fixed-point types, don't check minimum if type is not frozen,
7869 -- since we don't know all the characteristics of the type that can
7870 -- affect the size (e.g. a specified small) till freeze time.
7872 elsif Is_Fixed_Point_Type
(UT
)
7873 and then not Is_Frozen
(UT
)
7877 -- Cases for which a minimum check is required
7880 -- Ignore if specified size is correct for the type
7882 if Known_Esize
(UT
) and then Siz
= Esize
(UT
) then
7886 -- Otherwise get minimum size
7888 M
:= UI_From_Int
(Minimum_Size
(UT
));
7892 -- Size is less than minimum size, but one possibility remains
7893 -- that we can manage with the new size if we bias the type.
7895 M
:= UI_From_Int
(Minimum_Size
(UT
, Biased
=> True));
7898 Error_Msg_Uint_1
:= M
;
7900 ("size for& too small, minimum allowed is ^", N
, T
);
7910 -------------------------
7911 -- Get_Alignment_Value --
7912 -------------------------
7914 function Get_Alignment_Value
(Expr
: Node_Id
) return Uint
is
7915 Align
: constant Uint
:= Static_Integer
(Expr
);
7918 if Align
= No_Uint
then
7921 elsif Align
<= 0 then
7922 Error_Msg_N
("alignment value must be positive", Expr
);
7926 for J
in Int
range 0 .. 64 loop
7928 M
: constant Uint
:= Uint_2
** J
;
7931 exit when M
= Align
;
7935 ("alignment value must be power of 2", Expr
);
7943 end Get_Alignment_Value
;
7945 -------------------------------------
7946 -- Inherit_Aspects_At_Freeze_Point --
7947 -------------------------------------
7949 procedure Inherit_Aspects_At_Freeze_Point
(Typ
: Entity_Id
) is
7950 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
7951 (Rep_Item
: Node_Id
) return Boolean;
7952 -- This routine checks if Rep_Item is either a pragma or an aspect
7953 -- specification node whose correponding pragma (if any) is present in
7954 -- the Rep Item chain of the entity it has been specified to.
7956 --------------------------------------------------
7957 -- Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item --
7958 --------------------------------------------------
7960 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
7961 (Rep_Item
: Node_Id
) return Boolean
7964 return Nkind
(Rep_Item
) = N_Pragma
7965 or else Present_In_Rep_Item
7966 (Entity
(Rep_Item
), Aspect_Rep_Item
(Rep_Item
));
7967 end Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
;
7970 -- A representation item is either subtype-specific (Size and Alignment
7971 -- clauses) or type-related (all others). Subtype-specific aspects may
7972 -- differ for different subtypes of the same type.(RM 13.1.8)
7974 -- A derived type inherits each type-related representation aspect of
7975 -- its parent type that was directly specified before the declaration of
7976 -- the derived type. (RM 13.1.15)
7978 -- A derived subtype inherits each subtype-specific representation
7979 -- aspect of its parent subtype that was directly specified before the
7980 -- declaration of the derived type .(RM 13.1.15)
7982 -- The general processing involves inheriting a representation aspect
7983 -- from a parent type whenever the first rep item (aspect specification,
7984 -- attribute definition clause, pragma) corresponding to the given
7985 -- representation aspect in the rep item chain of Typ, if any, isn't
7986 -- directly specified to Typ but to one of its parents.
7988 -- ??? Note that, for now, just a limited number of representation
7989 -- aspects have been inherited here so far. Many of them are still
7990 -- inherited in Sem_Ch3. This will be fixed soon. Here is a
7991 -- non-exhaustive list of aspects that likely also need to be moved to
7992 -- this routine: Alignment, Component_Alignment, Component_Size,
7993 -- Machine_Radix, Object_Size, Pack, Predicates,
7994 -- Preelaborable_Initialization, RM_Size and Small.
7996 if Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
then
8002 if not Has_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
, False)
8003 and then Has_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
)
8004 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
8005 (Get_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
))
8007 Set_Is_Ada_2005_Only
(Typ
);
8012 if not Has_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
, False)
8013 and then Has_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
)
8014 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
8015 (Get_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
))
8017 Set_Is_Ada_2012_Only
(Typ
);
8022 if not Has_Rep_Item
(Typ
, Name_Atomic
, Name_Shared
, False)
8023 and then Has_Rep_Pragma
(Typ
, Name_Atomic
, Name_Shared
)
8024 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
8025 (Get_Rep_Item
(Typ
, Name_Atomic
, Name_Shared
))
8027 Set_Is_Atomic
(Typ
);
8028 Set_Treat_As_Volatile
(Typ
);
8029 Set_Is_Volatile
(Typ
);
8032 -- Default_Component_Value.
8034 if Is_Array_Type
(Typ
)
8035 and then Has_Rep_Item
(Typ
, Name_Default_Component_Value
, False)
8036 and then Has_Rep_Item
(Typ
, Name_Default_Component_Value
)
8038 Set_Default_Aspect_Component_Value
(Typ
,
8039 Default_Aspect_Component_Value
8040 (Entity
(Get_Rep_Item
(Typ
, Name_Default_Component_Value
))));
8045 if Is_Scalar_Type
(Typ
)
8046 and then Has_Rep_Item
(Typ
, Name_Default_Value
, False)
8047 and then Has_Rep_Item
(Typ
, Name_Default_Value
)
8049 Set_Default_Aspect_Value
(Typ
,
8050 Default_Aspect_Value
8051 (Entity
(Get_Rep_Item
(Typ
, Name_Default_Value
))));
8056 if not Has_Rep_Item
(Typ
, Name_Discard_Names
, False)
8057 and then Has_Rep_Item
(Typ
, Name_Discard_Names
)
8058 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
8059 (Get_Rep_Item
(Typ
, Name_Discard_Names
))
8061 Set_Discard_Names
(Typ
);
8066 if not Has_Rep_Item
(Typ
, Name_Invariant
, False)
8067 and then Has_Rep_Item
(Typ
, Name_Invariant
)
8068 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
8069 (Get_Rep_Item
(Typ
, Name_Invariant
))
8071 Set_Has_Invariants
(Typ
);
8073 if Class_Present
(Get_Rep_Item
(Typ
, Name_Invariant
)) then
8074 Set_Has_Inheritable_Invariants
(Typ
);
8080 if not Has_Rep_Item
(Typ
, Name_Volatile
, False)
8081 and then Has_Rep_Item
(Typ
, Name_Volatile
)
8082 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
8083 (Get_Rep_Item
(Typ
, Name_Volatile
))
8085 Set_Treat_As_Volatile
(Typ
);
8086 Set_Is_Volatile
(Typ
);
8089 -- Inheritance for derived types only
8091 if Is_Derived_Type
(Typ
) then
8093 Bas_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
8094 Imp_Bas_Typ
: constant Entity_Id
:= Implementation_Base_Type
(Typ
);
8097 -- Atomic_Components
8099 if not Has_Rep_Item
(Typ
, Name_Atomic_Components
, False)
8100 and then Has_Rep_Item
(Typ
, Name_Atomic_Components
)
8101 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
8102 (Get_Rep_Item
(Typ
, Name_Atomic_Components
))
8104 Set_Has_Atomic_Components
(Imp_Bas_Typ
);
8107 -- Volatile_Components
8109 if not Has_Rep_Item
(Typ
, Name_Volatile_Components
, False)
8110 and then Has_Rep_Item
(Typ
, Name_Volatile_Components
)
8111 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
8112 (Get_Rep_Item
(Typ
, Name_Volatile_Components
))
8114 Set_Has_Volatile_Components
(Imp_Bas_Typ
);
8117 -- Finalize_Storage_Only.
8119 if not Has_Rep_Pragma
(Typ
, Name_Finalize_Storage_Only
, False)
8120 and then Has_Rep_Pragma
(Typ
, Name_Finalize_Storage_Only
)
8122 Set_Finalize_Storage_Only
(Bas_Typ
);
8125 -- Universal_Aliasing
8127 if not Has_Rep_Item
(Typ
, Name_Universal_Aliasing
, False)
8128 and then Has_Rep_Item
(Typ
, Name_Universal_Aliasing
)
8129 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
8130 (Get_Rep_Item
(Typ
, Name_Universal_Aliasing
))
8132 Set_Universal_Aliasing
(Imp_Bas_Typ
);
8135 -- Record type specific aspects
8137 if Is_Record_Type
(Typ
) then
8140 if not Has_Rep_Item
(Typ
, Name_Bit_Order
, False)
8141 and then Has_Rep_Item
(Typ
, Name_Bit_Order
)
8143 Set_Reverse_Bit_Order
(Bas_Typ
,
8144 Reverse_Bit_Order
(Entity
(Name
8145 (Get_Rep_Item
(Typ
, Name_Bit_Order
)))));
8148 -- Scalar_Storage_Order
8150 if not Has_Rep_Item
(Typ
, Name_Scalar_Storage_Order
, False)
8151 and then Has_Rep_Item
(Typ
, Name_Scalar_Storage_Order
)
8153 Set_Reverse_Storage_Order
(Bas_Typ
,
8154 Reverse_Storage_Order
(Entity
(Name
8155 (Get_Rep_Item
(Typ
, Name_Scalar_Storage_Order
)))));
8160 end Inherit_Aspects_At_Freeze_Point
;
8166 procedure Initialize
is
8168 Address_Clause_Checks
.Init
;
8169 Independence_Checks
.Init
;
8170 Unchecked_Conversions
.Init
;
8173 -------------------------
8174 -- Is_Operational_Item --
8175 -------------------------
8177 function Is_Operational_Item
(N
: Node_Id
) return Boolean is
8179 if Nkind
(N
) /= N_Attribute_Definition_Clause
then
8183 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Chars
(N
));
8185 return Id
= Attribute_Input
8186 or else Id
= Attribute_Output
8187 or else Id
= Attribute_Read
8188 or else Id
= Attribute_Write
8189 or else Id
= Attribute_External_Tag
;
8192 end Is_Operational_Item
;
8198 function Minimum_Size
8200 Biased
: Boolean := False) return Nat
8202 Lo
: Uint
:= No_Uint
;
8203 Hi
: Uint
:= No_Uint
;
8204 LoR
: Ureal
:= No_Ureal
;
8205 HiR
: Ureal
:= No_Ureal
;
8206 LoSet
: Boolean := False;
8207 HiSet
: Boolean := False;
8211 R_Typ
: constant Entity_Id
:= Root_Type
(T
);
8214 -- If bad type, return 0
8216 if T
= Any_Type
then
8219 -- For generic types, just return zero. There cannot be any legitimate
8220 -- need to know such a size, but this routine may be called with a
8221 -- generic type as part of normal processing.
8223 elsif Is_Generic_Type
(R_Typ
)
8224 or else R_Typ
= Any_Type
8228 -- Access types. Normally an access type cannot have a size smaller
8229 -- than the size of System.Address. The exception is on VMS, where
8230 -- we have short and long addresses, and it is possible for an access
8231 -- type to have a short address size (and thus be less than the size
8232 -- of System.Address itself). We simply skip the check for VMS, and
8233 -- leave it to the back end to do the check.
8235 elsif Is_Access_Type
(T
) then
8236 if OpenVMS_On_Target
then
8239 return System_Address_Size
;
8242 -- Floating-point types
8244 elsif Is_Floating_Point_Type
(T
) then
8245 return UI_To_Int
(Esize
(R_Typ
));
8249 elsif Is_Discrete_Type
(T
) then
8251 -- The following loop is looking for the nearest compile time known
8252 -- bounds following the ancestor subtype chain. The idea is to find
8253 -- the most restrictive known bounds information.
8257 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
8262 if Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
)) then
8263 Lo
:= Expr_Rep_Value
(Type_Low_Bound
(Ancest
));
8270 if Compile_Time_Known_Value
(Type_High_Bound
(Ancest
)) then
8271 Hi
:= Expr_Rep_Value
(Type_High_Bound
(Ancest
));
8277 Ancest
:= Ancestor_Subtype
(Ancest
);
8280 Ancest
:= Base_Type
(T
);
8282 if Is_Generic_Type
(Ancest
) then
8288 -- Fixed-point types. We can't simply use Expr_Value to get the
8289 -- Corresponding_Integer_Value values of the bounds, since these do not
8290 -- get set till the type is frozen, and this routine can be called
8291 -- before the type is frozen. Similarly the test for bounds being static
8292 -- needs to include the case where we have unanalyzed real literals for
8295 elsif Is_Fixed_Point_Type
(T
) then
8297 -- The following loop is looking for the nearest compile time known
8298 -- bounds following the ancestor subtype chain. The idea is to find
8299 -- the most restrictive known bounds information.
8303 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
8307 -- Note: In the following two tests for LoSet and HiSet, it may
8308 -- seem redundant to test for N_Real_Literal here since normally
8309 -- one would assume that the test for the value being known at
8310 -- compile time includes this case. However, there is a glitch.
8311 -- If the real literal comes from folding a non-static expression,
8312 -- then we don't consider any non- static expression to be known
8313 -- at compile time if we are in configurable run time mode (needed
8314 -- in some cases to give a clearer definition of what is and what
8315 -- is not accepted). So the test is indeed needed. Without it, we
8316 -- would set neither Lo_Set nor Hi_Set and get an infinite loop.
8319 if Nkind
(Type_Low_Bound
(Ancest
)) = N_Real_Literal
8320 or else Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
))
8322 LoR
:= Expr_Value_R
(Type_Low_Bound
(Ancest
));
8329 if Nkind
(Type_High_Bound
(Ancest
)) = N_Real_Literal
8330 or else Compile_Time_Known_Value
(Type_High_Bound
(Ancest
))
8332 HiR
:= Expr_Value_R
(Type_High_Bound
(Ancest
));
8338 Ancest
:= Ancestor_Subtype
(Ancest
);
8341 Ancest
:= Base_Type
(T
);
8343 if Is_Generic_Type
(Ancest
) then
8349 Lo
:= UR_To_Uint
(LoR
/ Small_Value
(T
));
8350 Hi
:= UR_To_Uint
(HiR
/ Small_Value
(T
));
8352 -- No other types allowed
8355 raise Program_Error
;
8358 -- Fall through with Hi and Lo set. Deal with biased case
8361 and then not Is_Fixed_Point_Type
(T
)
8362 and then not (Is_Enumeration_Type
(T
)
8363 and then Has_Non_Standard_Rep
(T
)))
8364 or else Has_Biased_Representation
(T
)
8370 -- Signed case. Note that we consider types like range 1 .. -1 to be
8371 -- signed for the purpose of computing the size, since the bounds have
8372 -- to be accommodated in the base type.
8374 if Lo
< 0 or else Hi
< 0 then
8378 -- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1))
8379 -- Note that we accommodate the case where the bounds cross. This
8380 -- can happen either because of the way the bounds are declared
8381 -- or because of the algorithm in Freeze_Fixed_Point_Type.
8395 -- If both bounds are positive, make sure that both are represen-
8396 -- table in the case where the bounds are crossed. This can happen
8397 -- either because of the way the bounds are declared, or because of
8398 -- the algorithm in Freeze_Fixed_Point_Type.
8404 -- S = size, (can accommodate 0 .. (2**size - 1))
8407 while Hi
>= Uint_2
** S
loop
8415 ---------------------------
8416 -- New_Stream_Subprogram --
8417 ---------------------------
8419 procedure New_Stream_Subprogram
8423 Nam
: TSS_Name_Type
)
8425 Loc
: constant Source_Ptr
:= Sloc
(N
);
8426 Sname
: constant Name_Id
:= Make_TSS_Name
(Base_Type
(Ent
), Nam
);
8427 Subp_Id
: Entity_Id
;
8428 Subp_Decl
: Node_Id
;
8432 Defer_Declaration
: constant Boolean :=
8433 Is_Tagged_Type
(Ent
) or else Is_Private_Type
(Ent
);
8434 -- For a tagged type, there is a declaration for each stream attribute
8435 -- at the freeze point, and we must generate only a completion of this
8436 -- declaration. We do the same for private types, because the full view
8437 -- might be tagged. Otherwise we generate a declaration at the point of
8438 -- the attribute definition clause.
8440 function Build_Spec
return Node_Id
;
8441 -- Used for declaration and renaming declaration, so that this is
8442 -- treated as a renaming_as_body.
8448 function Build_Spec
return Node_Id
is
8449 Out_P
: constant Boolean := (Nam
= TSS_Stream_Read
);
8452 T_Ref
: constant Node_Id
:= New_Reference_To
(Etyp
, Loc
);
8455 Subp_Id
:= Make_Defining_Identifier
(Loc
, Sname
);
8457 -- S : access Root_Stream_Type'Class
8459 Formals
:= New_List
(
8460 Make_Parameter_Specification
(Loc
,
8461 Defining_Identifier
=>
8462 Make_Defining_Identifier
(Loc
, Name_S
),
8464 Make_Access_Definition
(Loc
,
8467 Designated_Type
(Etype
(F
)), Loc
))));
8469 if Nam
= TSS_Stream_Input
then
8470 Spec
:= Make_Function_Specification
(Loc
,
8471 Defining_Unit_Name
=> Subp_Id
,
8472 Parameter_Specifications
=> Formals
,
8473 Result_Definition
=> T_Ref
);
8478 Make_Parameter_Specification
(Loc
,
8479 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_V
),
8480 Out_Present
=> Out_P
,
8481 Parameter_Type
=> T_Ref
));
8484 Make_Procedure_Specification
(Loc
,
8485 Defining_Unit_Name
=> Subp_Id
,
8486 Parameter_Specifications
=> Formals
);
8492 -- Start of processing for New_Stream_Subprogram
8495 F
:= First_Formal
(Subp
);
8497 if Ekind
(Subp
) = E_Procedure
then
8498 Etyp
:= Etype
(Next_Formal
(F
));
8500 Etyp
:= Etype
(Subp
);
8503 -- Prepare subprogram declaration and insert it as an action on the
8504 -- clause node. The visibility for this entity is used to test for
8505 -- visibility of the attribute definition clause (in the sense of
8506 -- 8.3(23) as amended by AI-195).
8508 if not Defer_Declaration
then
8510 Make_Subprogram_Declaration
(Loc
,
8511 Specification
=> Build_Spec
);
8513 -- For a tagged type, there is always a visible declaration for each
8514 -- stream TSS (it is a predefined primitive operation), and the
8515 -- completion of this declaration occurs at the freeze point, which is
8516 -- not always visible at places where the attribute definition clause is
8517 -- visible. So, we create a dummy entity here for the purpose of
8518 -- tracking the visibility of the attribute definition clause itself.
8522 Make_Defining_Identifier
(Loc
, New_External_Name
(Sname
, 'V'));
8524 Make_Object_Declaration
(Loc
,
8525 Defining_Identifier
=> Subp_Id
,
8526 Object_Definition
=> New_Occurrence_Of
(Standard_Boolean
, Loc
));
8529 Insert_Action
(N
, Subp_Decl
);
8530 Set_Entity
(N
, Subp_Id
);
8533 Make_Subprogram_Renaming_Declaration
(Loc
,
8534 Specification
=> Build_Spec
,
8535 Name
=> New_Reference_To
(Subp
, Loc
));
8537 if Defer_Declaration
then
8538 Set_TSS
(Base_Type
(Ent
), Subp_Id
);
8540 Insert_Action
(N
, Subp_Decl
);
8541 Copy_TSS
(Subp_Id
, Base_Type
(Ent
));
8543 end New_Stream_Subprogram
;
8545 ------------------------
8546 -- Rep_Item_Too_Early --
8547 ------------------------
8549 function Rep_Item_Too_Early
(T
: Entity_Id
; N
: Node_Id
) return Boolean is
8551 -- Cannot apply non-operational rep items to generic types
8553 if Is_Operational_Item
(N
) then
8557 and then Is_Generic_Type
(Root_Type
(T
))
8559 Error_Msg_N
("representation item not allowed for generic type", N
);
8563 -- Otherwise check for incomplete type
8565 if Is_Incomplete_Or_Private_Type
(T
)
8566 and then No
(Underlying_Type
(T
))
8568 (Nkind
(N
) /= N_Pragma
8569 or else Get_Pragma_Id
(N
) /= Pragma_Import
)
8572 ("representation item must be after full type declaration", N
);
8575 -- If the type has incomplete components, a representation clause is
8576 -- illegal but stream attributes and Convention pragmas are correct.
8578 elsif Has_Private_Component
(T
) then
8579 if Nkind
(N
) = N_Pragma
then
8583 ("representation item must appear after type is fully defined",
8590 end Rep_Item_Too_Early
;
8592 -----------------------
8593 -- Rep_Item_Too_Late --
8594 -----------------------
8596 function Rep_Item_Too_Late
8599 FOnly
: Boolean := False) return Boolean
8602 Parent_Type
: Entity_Id
;
8605 -- Output the too late message. Note that this is not considered a
8606 -- serious error, since the effect is simply that we ignore the
8607 -- representation clause in this case.
8613 procedure Too_Late
is
8615 Error_Msg_N
("|representation item appears too late!", N
);
8618 -- Start of processing for Rep_Item_Too_Late
8621 -- First make sure entity is not frozen (RM 13.1(9))
8625 -- Exclude imported types, which may be frozen if they appear in a
8626 -- representation clause for a local type.
8628 and then not From_With_Type
(T
)
8630 -- Exclude generated entitiesa (not coming from source). The common
8631 -- case is when we generate a renaming which prematurely freezes the
8632 -- renamed internal entity, but we still want to be able to set copies
8633 -- of attribute values such as Size/Alignment.
8635 and then Comes_From_Source
(T
)
8638 S
:= First_Subtype
(T
);
8640 if Present
(Freeze_Node
(S
)) then
8642 ("?no more representation items for }", Freeze_Node
(S
), S
);
8647 -- Check for case of non-tagged derived type whose parent either has
8648 -- primitive operations, or is a by reference type (RM 13.1(10)).
8652 and then Is_Derived_Type
(T
)
8653 and then not Is_Tagged_Type
(T
)
8655 Parent_Type
:= Etype
(Base_Type
(T
));
8657 if Has_Primitive_Operations
(Parent_Type
) then
8660 ("primitive operations already defined for&!", N
, Parent_Type
);
8663 elsif Is_By_Reference_Type
(Parent_Type
) then
8666 ("parent type & is a by reference type!", N
, Parent_Type
);
8671 -- No error, link item into head of chain of rep items for the entity,
8672 -- but avoid chaining if we have an overloadable entity, and the pragma
8673 -- is one that can apply to multiple overloaded entities.
8675 if Is_Overloadable
(T
)
8676 and then Nkind
(N
) = N_Pragma
8679 Pname
: constant Name_Id
:= Pragma_Name
(N
);
8681 if Pname
= Name_Convention
or else
8682 Pname
= Name_Import
or else
8683 Pname
= Name_Export
or else
8684 Pname
= Name_External
or else
8685 Pname
= Name_Interface
8692 Record_Rep_Item
(T
, N
);
8694 end Rep_Item_Too_Late
;
8696 -------------------------------------
8697 -- Replace_Type_References_Generic --
8698 -------------------------------------
8700 procedure Replace_Type_References_Generic
(N
: Node_Id
; TName
: Name_Id
) is
8702 function Replace_Node
(N
: Node_Id
) return Traverse_Result
;
8703 -- Processes a single node in the traversal procedure below, checking
8704 -- if node N should be replaced, and if so, doing the replacement.
8706 procedure Replace_Type_Refs
is new Traverse_Proc
(Replace_Node
);
8707 -- This instantiation provides the body of Replace_Type_References
8713 function Replace_Node
(N
: Node_Id
) return Traverse_Result
is
8718 -- Case of identifier
8720 if Nkind
(N
) = N_Identifier
then
8722 -- If not the type name, all done with this node
8724 if Chars
(N
) /= TName
then
8727 -- Otherwise do the replacement and we are done with this node
8730 Replace_Type_Reference
(N
);
8734 -- Case of selected component (which is what a qualification
8735 -- looks like in the unanalyzed tree, which is what we have.
8737 elsif Nkind
(N
) = N_Selected_Component
then
8739 -- If selector name is not our type, keeping going (we might
8740 -- still have an occurrence of the type in the prefix).
8742 if Nkind
(Selector_Name
(N
)) /= N_Identifier
8743 or else Chars
(Selector_Name
(N
)) /= TName
8747 -- Selector name is our type, check qualification
8750 -- Loop through scopes and prefixes, doing comparison
8755 -- Continue if no more scopes or scope with no name
8757 if No
(S
) or else Nkind
(S
) not in N_Has_Chars
then
8761 -- Do replace if prefix is an identifier matching the
8762 -- scope that we are currently looking at.
8764 if Nkind
(P
) = N_Identifier
8765 and then Chars
(P
) = Chars
(S
)
8767 Replace_Type_Reference
(N
);
8771 -- Go check scope above us if prefix is itself of the
8772 -- form of a selected component, whose selector matches
8773 -- the scope we are currently looking at.
8775 if Nkind
(P
) = N_Selected_Component
8776 and then Nkind
(Selector_Name
(P
)) = N_Identifier
8777 and then Chars
(Selector_Name
(P
)) = Chars
(S
)
8782 -- For anything else, we don't have a match, so keep on
8783 -- going, there are still some weird cases where we may
8784 -- still have a replacement within the prefix.
8792 -- Continue for any other node kind
8800 Replace_Type_Refs
(N
);
8801 end Replace_Type_References_Generic
;
8803 -------------------------
8804 -- Same_Representation --
8805 -------------------------
8807 function Same_Representation
(Typ1
, Typ2
: Entity_Id
) return Boolean is
8808 T1
: constant Entity_Id
:= Underlying_Type
(Typ1
);
8809 T2
: constant Entity_Id
:= Underlying_Type
(Typ2
);
8812 -- A quick check, if base types are the same, then we definitely have
8813 -- the same representation, because the subtype specific representation
8814 -- attributes (Size and Alignment) do not affect representation from
8815 -- the point of view of this test.
8817 if Base_Type
(T1
) = Base_Type
(T2
) then
8820 elsif Is_Private_Type
(Base_Type
(T2
))
8821 and then Base_Type
(T1
) = Full_View
(Base_Type
(T2
))
8826 -- Tagged types never have differing representations
8828 if Is_Tagged_Type
(T1
) then
8832 -- Representations are definitely different if conventions differ
8834 if Convention
(T1
) /= Convention
(T2
) then
8838 -- Representations are different if component alignments differ
8840 if (Is_Record_Type
(T1
) or else Is_Array_Type
(T1
))
8842 (Is_Record_Type
(T2
) or else Is_Array_Type
(T2
))
8843 and then Component_Alignment
(T1
) /= Component_Alignment
(T2
)
8848 -- For arrays, the only real issue is component size. If we know the
8849 -- component size for both arrays, and it is the same, then that's
8850 -- good enough to know we don't have a change of representation.
8852 if Is_Array_Type
(T1
) then
8853 if Known_Component_Size
(T1
)
8854 and then Known_Component_Size
(T2
)
8855 and then Component_Size
(T1
) = Component_Size
(T2
)
8857 if VM_Target
= No_VM
then
8860 -- In VM targets the representation of arrays with aliased
8861 -- components differs from arrays with non-aliased components
8864 return Has_Aliased_Components
(Base_Type
(T1
))
8866 Has_Aliased_Components
(Base_Type
(T2
));
8871 -- Types definitely have same representation if neither has non-standard
8872 -- representation since default representations are always consistent.
8873 -- If only one has non-standard representation, and the other does not,
8874 -- then we consider that they do not have the same representation. They
8875 -- might, but there is no way of telling early enough.
8877 if Has_Non_Standard_Rep
(T1
) then
8878 if not Has_Non_Standard_Rep
(T2
) then
8882 return not Has_Non_Standard_Rep
(T2
);
8885 -- Here the two types both have non-standard representation, and we need
8886 -- to determine if they have the same non-standard representation.
8888 -- For arrays, we simply need to test if the component sizes are the
8889 -- same. Pragma Pack is reflected in modified component sizes, so this
8890 -- check also deals with pragma Pack.
8892 if Is_Array_Type
(T1
) then
8893 return Component_Size
(T1
) = Component_Size
(T2
);
8895 -- Tagged types always have the same representation, because it is not
8896 -- possible to specify different representations for common fields.
8898 elsif Is_Tagged_Type
(T1
) then
8901 -- Case of record types
8903 elsif Is_Record_Type
(T1
) then
8905 -- Packed status must conform
8907 if Is_Packed
(T1
) /= Is_Packed
(T2
) then
8910 -- Otherwise we must check components. Typ2 maybe a constrained
8911 -- subtype with fewer components, so we compare the components
8912 -- of the base types.
8915 Record_Case
: declare
8916 CD1
, CD2
: Entity_Id
;
8918 function Same_Rep
return Boolean;
8919 -- CD1 and CD2 are either components or discriminants. This
8920 -- function tests whether the two have the same representation
8926 function Same_Rep
return Boolean is
8928 if No
(Component_Clause
(CD1
)) then
8929 return No
(Component_Clause
(CD2
));
8933 Present
(Component_Clause
(CD2
))
8935 Component_Bit_Offset
(CD1
) = Component_Bit_Offset
(CD2
)
8937 Esize
(CD1
) = Esize
(CD2
);
8941 -- Start of processing for Record_Case
8944 if Has_Discriminants
(T1
) then
8945 CD1
:= First_Discriminant
(T1
);
8946 CD2
:= First_Discriminant
(T2
);
8948 -- The number of discriminants may be different if the
8949 -- derived type has fewer (constrained by values). The
8950 -- invisible discriminants retain the representation of
8951 -- the original, so the discrepancy does not per se
8952 -- indicate a different representation.
8955 and then Present
(CD2
)
8957 if not Same_Rep
then
8960 Next_Discriminant
(CD1
);
8961 Next_Discriminant
(CD2
);
8966 CD1
:= First_Component
(Underlying_Type
(Base_Type
(T1
)));
8967 CD2
:= First_Component
(Underlying_Type
(Base_Type
(T2
)));
8969 while Present
(CD1
) loop
8970 if not Same_Rep
then
8973 Next_Component
(CD1
);
8974 Next_Component
(CD2
);
8982 -- For enumeration types, we must check each literal to see if the
8983 -- representation is the same. Note that we do not permit enumeration
8984 -- representation clauses for Character and Wide_Character, so these
8985 -- cases were already dealt with.
8987 elsif Is_Enumeration_Type
(T1
) then
8988 Enumeration_Case
: declare
8992 L1
:= First_Literal
(T1
);
8993 L2
:= First_Literal
(T2
);
8995 while Present
(L1
) loop
8996 if Enumeration_Rep
(L1
) /= Enumeration_Rep
(L2
) then
9006 end Enumeration_Case
;
9008 -- Any other types have the same representation for these purposes
9013 end Same_Representation
;
9019 procedure Set_Biased
9023 Biased
: Boolean := True)
9027 Set_Has_Biased_Representation
(E
);
9029 if Warn_On_Biased_Representation
then
9031 ("?" & Msg
& " forces biased representation for&", N
, E
);
9036 --------------------
9037 -- Set_Enum_Esize --
9038 --------------------
9040 procedure Set_Enum_Esize
(T
: Entity_Id
) is
9048 -- Find the minimum standard size (8,16,32,64) that fits
9050 Lo
:= Enumeration_Rep
(Entity
(Type_Low_Bound
(T
)));
9051 Hi
:= Enumeration_Rep
(Entity
(Type_High_Bound
(T
)));
9054 if Lo
>= -Uint_2
**07 and then Hi
< Uint_2
**07 then
9055 Sz
:= Standard_Character_Size
; -- May be > 8 on some targets
9057 elsif Lo
>= -Uint_2
**15 and then Hi
< Uint_2
**15 then
9060 elsif Lo
>= -Uint_2
**31 and then Hi
< Uint_2
**31 then
9063 else pragma Assert
(Lo
>= -Uint_2
**63 and then Hi
< Uint_2
**63);
9068 if Hi
< Uint_2
**08 then
9069 Sz
:= Standard_Character_Size
; -- May be > 8 on some targets
9071 elsif Hi
< Uint_2
**16 then
9074 elsif Hi
< Uint_2
**32 then
9077 else pragma Assert
(Hi
< Uint_2
**63);
9082 -- That minimum is the proper size unless we have a foreign convention
9083 -- and the size required is 32 or less, in which case we bump the size
9084 -- up to 32. This is required for C and C++ and seems reasonable for
9085 -- all other foreign conventions.
9087 if Has_Foreign_Convention
(T
)
9088 and then Esize
(T
) < Standard_Integer_Size
9090 Init_Esize
(T
, Standard_Integer_Size
);
9096 ------------------------------
9097 -- Validate_Address_Clauses --
9098 ------------------------------
9100 procedure Validate_Address_Clauses
is
9102 for J
in Address_Clause_Checks
.First
.. Address_Clause_Checks
.Last
loop
9104 ACCR
: Address_Clause_Check_Record
9105 renames Address_Clause_Checks
.Table
(J
);
9116 -- Skip processing of this entry if warning already posted
9118 if not Address_Warning_Posted
(ACCR
.N
) then
9120 Expr
:= Original_Node
(Expression
(ACCR
.N
));
9124 X_Alignment
:= Alignment
(ACCR
.X
);
9125 Y_Alignment
:= Alignment
(ACCR
.Y
);
9127 -- Similarly obtain sizes
9129 X_Size
:= Esize
(ACCR
.X
);
9130 Y_Size
:= Esize
(ACCR
.Y
);
9132 -- Check for large object overlaying smaller one
9135 and then X_Size
> Uint_0
9136 and then X_Size
> Y_Size
9139 ("?& overlays smaller object", ACCR
.N
, ACCR
.X
);
9141 ("\?program execution may be erroneous", ACCR
.N
);
9142 Error_Msg_Uint_1
:= X_Size
;
9144 ("\?size of & is ^", ACCR
.N
, ACCR
.X
);
9145 Error_Msg_Uint_1
:= Y_Size
;
9147 ("\?size of & is ^", ACCR
.N
, ACCR
.Y
);
9149 -- Check for inadequate alignment, both of the base object
9150 -- and of the offset, if any.
9152 -- Note: we do not check the alignment if we gave a size
9153 -- warning, since it would likely be redundant.
9155 elsif Y_Alignment
/= Uint_0
9156 and then (Y_Alignment
< X_Alignment
9159 Nkind
(Expr
) = N_Attribute_Reference
9161 Attribute_Name
(Expr
) = Name_Address
9163 Has_Compatible_Alignment
9164 (ACCR
.X
, Prefix
(Expr
))
9165 /= Known_Compatible
))
9168 ("?specified address for& may be inconsistent "
9172 ("\?program execution may be erroneous (RM 13.3(27))",
9174 Error_Msg_Uint_1
:= X_Alignment
;
9176 ("\?alignment of & is ^",
9178 Error_Msg_Uint_1
:= Y_Alignment
;
9180 ("\?alignment of & is ^",
9182 if Y_Alignment
>= X_Alignment
then
9184 ("\?but offset is not multiple of alignment",
9191 end Validate_Address_Clauses
;
9193 ---------------------------
9194 -- Validate_Independence --
9195 ---------------------------
9197 procedure Validate_Independence
is
9198 SU
: constant Uint
:= UI_From_Int
(System_Storage_Unit
);
9206 procedure Check_Array_Type
(Atyp
: Entity_Id
);
9207 -- Checks if the array type Atyp has independent components, and
9208 -- if not, outputs an appropriate set of error messages.
9210 procedure No_Independence
;
9211 -- Output message that independence cannot be guaranteed
9213 function OK_Component
(C
: Entity_Id
) return Boolean;
9214 -- Checks one component to see if it is independently accessible, and
9215 -- if so yields True, otherwise yields False if independent access
9216 -- cannot be guaranteed. This is a conservative routine, it only
9217 -- returns True if it knows for sure, it returns False if it knows
9218 -- there is a problem, or it cannot be sure there is no problem.
9220 procedure Reason_Bad_Component
(C
: Entity_Id
);
9221 -- Outputs continuation message if a reason can be determined for
9222 -- the component C being bad.
9224 ----------------------
9225 -- Check_Array_Type --
9226 ----------------------
9228 procedure Check_Array_Type
(Atyp
: Entity_Id
) is
9229 Ctyp
: constant Entity_Id
:= Component_Type
(Atyp
);
9232 -- OK if no alignment clause, no pack, and no component size
9234 if not Has_Component_Size_Clause
(Atyp
)
9235 and then not Has_Alignment_Clause
(Atyp
)
9236 and then not Is_Packed
(Atyp
)
9241 -- Check actual component size
9243 if not Known_Component_Size
(Atyp
)
9244 or else not (Addressable
(Component_Size
(Atyp
))
9245 and then Component_Size
(Atyp
) < 64)
9246 or else Component_Size
(Atyp
) mod Esize
(Ctyp
) /= 0
9250 -- Bad component size, check reason
9252 if Has_Component_Size_Clause
(Atyp
) then
9254 Get_Attribute_Definition_Clause
9255 (Atyp
, Attribute_Component_Size
);
9258 Error_Msg_Sloc
:= Sloc
(P
);
9259 Error_Msg_N
("\because of Component_Size clause#", N
);
9264 if Is_Packed
(Atyp
) then
9265 P
:= Get_Rep_Pragma
(Atyp
, Name_Pack
);
9268 Error_Msg_Sloc
:= Sloc
(P
);
9269 Error_Msg_N
("\because of pragma Pack#", N
);
9274 -- No reason found, just return
9279 -- Array type is OK independence-wise
9282 end Check_Array_Type
;
9284 ---------------------
9285 -- No_Independence --
9286 ---------------------
9288 procedure No_Independence
is
9290 if Pragma_Name
(N
) = Name_Independent
then
9292 ("independence cannot be guaranteed for&", N
, E
);
9295 ("independent components cannot be guaranteed for&", N
, E
);
9297 end No_Independence
;
9303 function OK_Component
(C
: Entity_Id
) return Boolean is
9304 Rec
: constant Entity_Id
:= Scope
(C
);
9305 Ctyp
: constant Entity_Id
:= Etype
(C
);
9308 -- OK if no component clause, no Pack, and no alignment clause
9310 if No
(Component_Clause
(C
))
9311 and then not Is_Packed
(Rec
)
9312 and then not Has_Alignment_Clause
(Rec
)
9317 -- Here we look at the actual component layout. A component is
9318 -- addressable if its size is a multiple of the Esize of the
9319 -- component type, and its starting position in the record has
9320 -- appropriate alignment, and the record itself has appropriate
9321 -- alignment to guarantee the component alignment.
9323 -- Make sure sizes are static, always assume the worst for any
9324 -- cases where we cannot check static values.
9326 if not (Known_Static_Esize
(C
)
9327 and then Known_Static_Esize
(Ctyp
))
9332 -- Size of component must be addressable or greater than 64 bits
9333 -- and a multiple of bytes.
9335 if not Addressable
(Esize
(C
))
9336 and then Esize
(C
) < Uint_64
9341 -- Check size is proper multiple
9343 if Esize
(C
) mod Esize
(Ctyp
) /= 0 then
9347 -- Check alignment of component is OK
9349 if not Known_Component_Bit_Offset
(C
)
9350 or else Component_Bit_Offset
(C
) < Uint_0
9351 or else Component_Bit_Offset
(C
) mod Esize
(Ctyp
) /= 0
9356 -- Check alignment of record type is OK
9358 if not Known_Alignment
(Rec
)
9359 or else (Alignment
(Rec
) * SU
) mod Esize
(Ctyp
) /= 0
9364 -- All tests passed, component is addressable
9369 --------------------------
9370 -- Reason_Bad_Component --
9371 --------------------------
9373 procedure Reason_Bad_Component
(C
: Entity_Id
) is
9374 Rec
: constant Entity_Id
:= Scope
(C
);
9375 Ctyp
: constant Entity_Id
:= Etype
(C
);
9378 -- If component clause present assume that's the problem
9380 if Present
(Component_Clause
(C
)) then
9381 Error_Msg_Sloc
:= Sloc
(Component_Clause
(C
));
9382 Error_Msg_N
("\because of Component_Clause#", N
);
9386 -- If pragma Pack clause present, assume that's the problem
9388 if Is_Packed
(Rec
) then
9389 P
:= Get_Rep_Pragma
(Rec
, Name_Pack
);
9392 Error_Msg_Sloc
:= Sloc
(P
);
9393 Error_Msg_N
("\because of pragma Pack#", N
);
9398 -- See if record has bad alignment clause
9400 if Has_Alignment_Clause
(Rec
)
9401 and then Known_Alignment
(Rec
)
9402 and then (Alignment
(Rec
) * SU
) mod Esize
(Ctyp
) /= 0
9404 P
:= Get_Attribute_Definition_Clause
(Rec
, Attribute_Alignment
);
9407 Error_Msg_Sloc
:= Sloc
(P
);
9408 Error_Msg_N
("\because of Alignment clause#", N
);
9412 -- Couldn't find a reason, so return without a message
9415 end Reason_Bad_Component
;
9417 -- Start of processing for Validate_Independence
9420 for J
in Independence_Checks
.First
.. Independence_Checks
.Last
loop
9421 N
:= Independence_Checks
.Table
(J
).N
;
9422 E
:= Independence_Checks
.Table
(J
).E
;
9423 IC
:= Pragma_Name
(N
) = Name_Independent_Components
;
9425 -- Deal with component case
9427 if Ekind
(E
) = E_Discriminant
or else Ekind
(E
) = E_Component
then
9428 if not OK_Component
(E
) then
9430 Reason_Bad_Component
(E
);
9435 -- Deal with record with Independent_Components
9437 if IC
and then Is_Record_Type
(E
) then
9438 Comp
:= First_Component_Or_Discriminant
(E
);
9439 while Present
(Comp
) loop
9440 if not OK_Component
(Comp
) then
9442 Reason_Bad_Component
(Comp
);
9446 Next_Component_Or_Discriminant
(Comp
);
9450 -- Deal with address clause case
9452 if Is_Object
(E
) then
9453 Addr
:= Address_Clause
(E
);
9455 if Present
(Addr
) then
9457 Error_Msg_Sloc
:= Sloc
(Addr
);
9458 Error_Msg_N
("\because of Address clause#", N
);
9463 -- Deal with independent components for array type
9465 if IC
and then Is_Array_Type
(E
) then
9466 Check_Array_Type
(E
);
9469 -- Deal with independent components for array object
9471 if IC
and then Is_Object
(E
) and then Is_Array_Type
(Etype
(E
)) then
9472 Check_Array_Type
(Etype
(E
));
9477 end Validate_Independence
;
9479 -----------------------------------
9480 -- Validate_Unchecked_Conversion --
9481 -----------------------------------
9483 procedure Validate_Unchecked_Conversion
9485 Act_Unit
: Entity_Id
)
9492 -- Obtain source and target types. Note that we call Ancestor_Subtype
9493 -- here because the processing for generic instantiation always makes
9494 -- subtypes, and we want the original frozen actual types.
9496 -- If we are dealing with private types, then do the check on their
9497 -- fully declared counterparts if the full declarations have been
9498 -- encountered (they don't have to be visible, but they must exist!)
9500 Source
:= Ancestor_Subtype
(Etype
(First_Formal
(Act_Unit
)));
9502 if Is_Private_Type
(Source
)
9503 and then Present
(Underlying_Type
(Source
))
9505 Source
:= Underlying_Type
(Source
);
9508 Target
:= Ancestor_Subtype
(Etype
(Act_Unit
));
9510 -- If either type is generic, the instantiation happens within a generic
9511 -- unit, and there is nothing to check. The proper check will happen
9512 -- when the enclosing generic is instantiated.
9514 if Is_Generic_Type
(Source
) or else Is_Generic_Type
(Target
) then
9518 if Is_Private_Type
(Target
)
9519 and then Present
(Underlying_Type
(Target
))
9521 Target
:= Underlying_Type
(Target
);
9524 -- Source may be unconstrained array, but not target
9526 if Is_Array_Type
(Target
)
9527 and then not Is_Constrained
(Target
)
9530 ("unchecked conversion to unconstrained array not allowed", N
);
9534 -- Warn if conversion between two different convention pointers
9536 if Is_Access_Type
(Target
)
9537 and then Is_Access_Type
(Source
)
9538 and then Convention
(Target
) /= Convention
(Source
)
9539 and then Warn_On_Unchecked_Conversion
9541 -- Give warnings for subprogram pointers only on most targets. The
9542 -- exception is VMS, where data pointers can have different lengths
9543 -- depending on the pointer convention.
9545 if Is_Access_Subprogram_Type
(Target
)
9546 or else Is_Access_Subprogram_Type
(Source
)
9547 or else OpenVMS_On_Target
9550 ("?conversion between pointers with different conventions!", N
);
9554 -- Warn if one of the operands is Ada.Calendar.Time. Do not emit a
9555 -- warning when compiling GNAT-related sources.
9557 if Warn_On_Unchecked_Conversion
9558 and then not In_Predefined_Unit
(N
)
9559 and then RTU_Loaded
(Ada_Calendar
)
9561 (Chars
(Source
) = Name_Time
9563 Chars
(Target
) = Name_Time
)
9565 -- If Ada.Calendar is loaded and the name of one of the operands is
9566 -- Time, there is a good chance that this is Ada.Calendar.Time.
9569 Calendar_Time
: constant Entity_Id
:=
9570 Full_View
(RTE
(RO_CA_Time
));
9572 pragma Assert
(Present
(Calendar_Time
));
9574 if Source
= Calendar_Time
9575 or else Target
= Calendar_Time
9578 ("?representation of 'Time values may change between " &
9579 "'G'N'A'T versions", N
);
9584 -- Make entry in unchecked conversion table for later processing by
9585 -- Validate_Unchecked_Conversions, which will check sizes and alignments
9586 -- (using values set by the back-end where possible). This is only done
9587 -- if the appropriate warning is active.
9589 if Warn_On_Unchecked_Conversion
then
9590 Unchecked_Conversions
.Append
9591 (New_Val
=> UC_Entry
'
9596 -- If both sizes are known statically now, then back end annotation
9597 -- is not required to do a proper check but if either size is not
9598 -- known statically, then we need the annotation.
9600 if Known_Static_RM_Size (Source)
9601 and then Known_Static_RM_Size (Target)
9605 Back_Annotate_Rep_Info := True;
9609 -- If unchecked conversion to access type, and access type is declared
9610 -- in the same unit as the unchecked conversion, then set the flag
9611 -- No_Strict_Aliasing (no strict aliasing is implicit here)
9613 if Is_Access_Type (Target) and then
9614 In_Same_Source_Unit (Target, N)
9616 Set_No_Strict_Aliasing (Implementation_Base_Type (Target));
9619 -- Generate N_Validate_Unchecked_Conversion node for back end in case
9620 -- the back end needs to perform special validation checks.
9622 -- Shouldn't this be in Exp_Ch13, since the check only gets done if we
9623 -- have full expansion and the back end is called ???
9626 Make_Validate_Unchecked_Conversion (Sloc (N));
9627 Set_Source_Type (Vnode, Source);
9628 Set_Target_Type (Vnode, Target);
9630 -- If the unchecked conversion node is in a list, just insert before it.
9631 -- If not we have some strange case, not worth bothering about.
9633 if Is_List_Member (N) then
9634 Insert_After (N, Vnode);
9636 end Validate_Unchecked_Conversion;
9638 ------------------------------------
9639 -- Validate_Unchecked_Conversions --
9640 ------------------------------------
9642 procedure Validate_Unchecked_Conversions is
9644 for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop
9646 T : UC_Entry renames Unchecked_Conversions.Table (N);
9648 Eloc : constant Source_Ptr := T.Eloc;
9649 Source : constant Entity_Id := T.Source;
9650 Target : constant Entity_Id := T.Target;
9656 -- This validation check, which warns if we have unequal sizes for
9657 -- unchecked conversion, and thus potentially implementation
9658 -- dependent semantics, is one of the few occasions on which we
9659 -- use the official RM size instead of Esize. See description in
9660 -- Einfo "Handling of Type'Size Values" for details.
9662 if Serious_Errors_Detected = 0
9663 and then Known_Static_RM_Size (Source)
9664 and then Known_Static_RM_Size (Target)
9666 -- Don't do the check if warnings off for either type, note the
9667 -- deliberate use of OR here instead of OR ELSE to get the flag
9668 -- Warnings_Off_Used set for both types if appropriate.
9670 and then not (Has_Warnings_Off (Source)
9672 Has_Warnings_Off (Target))
9674 Source_Siz := RM_Size (Source);
9675 Target_Siz := RM_Size (Target);
9677 if Source_Siz /= Target_Siz then
9679 ("?types for unchecked conversion have different sizes!",
9682 if All_Errors_Mode then
9683 Error_Msg_Name_1 := Chars (Source);
9684 Error_Msg_Uint_1 := Source_Siz;
9685 Error_Msg_Name_2 := Chars (Target);
9686 Error_Msg_Uint_2 := Target_Siz;
9687 Error_Msg ("\size of % is ^, size of % is ^?", Eloc);
9689 Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz);
9691 if Is_Discrete_Type (Source)
9692 and then Is_Discrete_Type (Target)
9694 if Source_Siz > Target_Siz then
9696 ("\?^ high order bits of source will be ignored!",
9699 elsif Is_Unsigned_Type (Source) then
9701 ("\?source will be extended with ^ high order " &
9702 "zero bits?!", Eloc);
9706 ("\?source will be extended with ^ high order " &
9711 elsif Source_Siz < Target_Siz then
9712 if Is_Discrete_Type (Target) then
9713 if Bytes_Big_Endian then
9715 ("\?target value will include ^ undefined " &
9720 ("\?target value will include ^ undefined " &
9727 ("\?^ trailing bits of target value will be " &
9728 "undefined!", Eloc);
9731 else pragma Assert (Source_Siz > Target_Siz);
9733 ("\?^ trailing bits of source will be ignored!",
9740 -- If both types are access types, we need to check the alignment.
9741 -- If the alignment of both is specified, we can do it here.
9743 if Serious_Errors_Detected = 0
9744 and then Ekind (Source) in Access_Kind
9745 and then Ekind (Target) in Access_Kind
9746 and then Target_Strict_Alignment
9747 and then Present (Designated_Type (Source))
9748 and then Present (Designated_Type (Target))
9751 D_Source : constant Entity_Id := Designated_Type (Source);
9752 D_Target : constant Entity_Id := Designated_Type (Target);
9755 if Known_Alignment (D_Source)
9756 and then Known_Alignment (D_Target)
9759 Source_Align : constant Uint := Alignment (D_Source);
9760 Target_Align : constant Uint := Alignment (D_Target);
9763 if Source_Align < Target_Align
9764 and then not Is_Tagged_Type (D_Source)
9766 -- Suppress warning if warnings suppressed on either
9767 -- type or either designated type. Note the use of
9768 -- OR here instead of OR ELSE. That is intentional,
9769 -- we would like to set flag Warnings_Off_Used in
9770 -- all types for which warnings are suppressed.
9772 and then not (Has_Warnings_Off (D_Source)
9774 Has_Warnings_Off (D_Target)
9776 Has_Warnings_Off (Source)
9778 Has_Warnings_Off (Target))
9780 Error_Msg_Uint_1 := Target_Align;
9781 Error_Msg_Uint_2 := Source_Align;
9782 Error_Msg_Node_1 := D_Target;
9783 Error_Msg_Node_2 := D_Source;
9785 ("?alignment of & (^) is stricter than " &
9786 "alignment of & (^)!", Eloc);
9788 ("\?resulting access value may have invalid " &
9789 "alignment!", Eloc);
9797 end Validate_Unchecked_Conversions;