1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2013, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Aspects
; use Aspects
;
27 with Atree
; use Atree
;
28 with Checks
; use Checks
;
29 with Debug
; use Debug
;
30 with Einfo
; use Einfo
;
31 with Elists
; use Elists
;
32 with Errout
; use Errout
;
33 with Exp_Disp
; use Exp_Disp
;
34 with Exp_Tss
; use Exp_Tss
;
35 with Exp_Util
; use Exp_Util
;
37 with Lib
.Xref
; use Lib
.Xref
;
38 with Namet
; use Namet
;
39 with Nlists
; use Nlists
;
40 with Nmake
; use Nmake
;
42 with Restrict
; use Restrict
;
43 with Rident
; use Rident
;
44 with Rtsfind
; use Rtsfind
;
46 with Sem_Aux
; use Sem_Aux
;
47 with Sem_Case
; use Sem_Case
;
48 with Sem_Ch3
; use Sem_Ch3
;
49 with Sem_Ch6
; use Sem_Ch6
;
50 with Sem_Ch8
; use Sem_Ch8
;
51 with Sem_Ch9
; use Sem_Ch9
;
52 with Sem_Dim
; use Sem_Dim
;
53 with Sem_Disp
; use Sem_Disp
;
54 with Sem_Eval
; use Sem_Eval
;
55 with Sem_Prag
; use Sem_Prag
;
56 with Sem_Res
; use Sem_Res
;
57 with Sem_Type
; use Sem_Type
;
58 with Sem_Util
; use Sem_Util
;
59 with Sem_Warn
; use Sem_Warn
;
60 with Sinput
; use Sinput
;
61 with Snames
; use Snames
;
62 with Stand
; use Stand
;
63 with Sinfo
; use Sinfo
;
64 with Stringt
; use Stringt
;
65 with Targparm
; use Targparm
;
66 with Ttypes
; use Ttypes
;
67 with Tbuild
; use Tbuild
;
68 with Urealp
; use Urealp
;
69 with Warnsw
; use Warnsw
;
71 with GNAT
.Heap_Sort_G
;
73 package body Sem_Ch13
is
75 SSU
: constant Pos
:= System_Storage_Unit
;
76 -- Convenient short hand for commonly used constant
78 -----------------------
79 -- Local Subprograms --
80 -----------------------
82 procedure Alignment_Check_For_Size_Change
(Typ
: Entity_Id
; Size
: Uint
);
83 -- This routine is called after setting one of the sizes of type entity
84 -- Typ to Size. The purpose is to deal with the situation of a derived
85 -- type whose inherited alignment is no longer appropriate for the new
86 -- size value. In this case, we reset the Alignment to unknown.
88 procedure Build_Predicate_Functions
(Typ
: Entity_Id
; N
: Node_Id
);
89 -- If Typ has predicates (indicated by Has_Predicates being set for Typ,
90 -- then either there are pragma Predicate entries on the rep chain for the
91 -- type (note that Predicate aspects are converted to pragma Predicate), or
92 -- there are inherited aspects from a parent type, or ancestor subtypes.
93 -- This procedure builds the spec and body for the Predicate function that
94 -- tests these predicates. N is the freeze node for the type. The spec of
95 -- the function is inserted before the freeze node, and the body of the
96 -- function is inserted after the freeze node. If the predicate expression
97 -- has at least one Raise_Expression, then this procedure also builds the
98 -- M version of the predicate function for use in membership tests.
100 procedure Build_Static_Predicate
104 -- Given a predicated type Typ, where Typ is a discrete static subtype,
105 -- whose predicate expression is Expr, tests if Expr is a static predicate,
106 -- and if so, builds the predicate range list. Nam is the name of the one
107 -- argument to the predicate function. Occurrences of the type name in the
108 -- predicate expression have been replaced by identifier references to this
109 -- name, which is unique, so any identifier with Chars matching Nam must be
110 -- a reference to the type. If the predicate is non-static, this procedure
111 -- returns doing nothing. If the predicate is static, then the predicate
112 -- list is stored in Static_Predicate (Typ), and the Expr is rewritten as
113 -- a canonicalized membership operation.
115 procedure Check_Pool_Size_Clash
(Ent
: Entity_Id
; SP
, SS
: Node_Id
);
116 -- Called if both Storage_Pool and Storage_Size attribute definition
117 -- clauses (SP and SS) are present for entity Ent. Issue error message.
119 procedure Freeze_Entity_Checks
(N
: Node_Id
);
120 -- Called from Analyze_Freeze_Entity and Analyze_Generic_Freeze Entity
121 -- to generate appropriate semantic checks that are delayed until this
122 -- point (they had to be delayed this long for cases of delayed aspects,
123 -- e.g. analysis of statically predicated subtypes in choices, for which
124 -- we have to be sure the subtypes in question are frozen before checking.
126 function Get_Alignment_Value
(Expr
: Node_Id
) return Uint
;
127 -- Given the expression for an alignment value, returns the corresponding
128 -- Uint value. If the value is inappropriate, then error messages are
129 -- posted as required, and a value of No_Uint is returned.
131 function Is_Operational_Item
(N
: Node_Id
) return Boolean;
132 -- A specification for a stream attribute is allowed before the full type
133 -- is declared, as explained in AI-00137 and the corrigendum. Attributes
134 -- that do not specify a representation characteristic are operational
137 procedure New_Stream_Subprogram
141 Nam
: TSS_Name_Type
);
142 -- Create a subprogram renaming of a given stream attribute to the
143 -- designated subprogram and then in the tagged case, provide this as a
144 -- primitive operation, or in the non-tagged case make an appropriate TSS
145 -- entry. This is more properly an expansion activity than just semantics,
146 -- but the presence of user-defined stream functions for limited types is a
147 -- legality check, which is why this takes place here rather than in
148 -- exp_ch13, where it was previously. Nam indicates the name of the TSS
149 -- function to be generated.
151 -- To avoid elaboration anomalies with freeze nodes, for untagged types
152 -- we generate both a subprogram declaration and a subprogram renaming
153 -- declaration, so that the attribute specification is handled as a
154 -- renaming_as_body. For tagged types, the specification is one of the
158 with procedure Replace_Type_Reference
(N
: Node_Id
);
159 procedure Replace_Type_References_Generic
(N
: Node_Id
; TName
: Name_Id
);
160 -- This is used to scan an expression for a predicate or invariant aspect
161 -- replacing occurrences of the name TName (the name of the subtype to
162 -- which the aspect applies) with appropriate references to the parameter
163 -- of the predicate function or invariant procedure. The procedure passed
164 -- as a generic parameter does the actual replacement of node N, which is
165 -- either a simple direct reference to TName, or a selected component that
166 -- represents an appropriately qualified occurrence of TName.
172 Biased
: Boolean := True);
173 -- If Biased is True, sets Has_Biased_Representation flag for E, and
174 -- outputs a warning message at node N if Warn_On_Biased_Representation is
175 -- is True. This warning inserts the string Msg to describe the construct
178 ----------------------------------------------
179 -- Table for Validate_Unchecked_Conversions --
180 ----------------------------------------------
182 -- The following table collects unchecked conversions for validation.
183 -- Entries are made by Validate_Unchecked_Conversion and then the call
184 -- to Validate_Unchecked_Conversions does the actual error checking and
185 -- posting of warnings. The reason for this delayed processing is to take
186 -- advantage of back-annotations of size and alignment values performed by
189 -- Note: the reason we store a Source_Ptr value instead of a Node_Id is
190 -- that by the time Validate_Unchecked_Conversions is called, Sprint will
191 -- already have modified all Sloc values if the -gnatD option is set.
193 type UC_Entry
is record
194 Eloc
: Source_Ptr
; -- node used for posting warnings
195 Source
: Entity_Id
; -- source type for unchecked conversion
196 Target
: Entity_Id
; -- target type for unchecked conversion
199 package Unchecked_Conversions
is new Table
.Table
(
200 Table_Component_Type
=> UC_Entry
,
201 Table_Index_Type
=> Int
,
202 Table_Low_Bound
=> 1,
204 Table_Increment
=> 200,
205 Table_Name
=> "Unchecked_Conversions");
207 ----------------------------------------
208 -- Table for Validate_Address_Clauses --
209 ----------------------------------------
211 -- If an address clause has the form
213 -- for X'Address use Expr
215 -- where Expr is of the form Y'Address or recursively is a reference to a
216 -- constant of either of these forms, and X and Y are entities of objects,
217 -- then if Y has a smaller alignment than X, that merits a warning about
218 -- possible bad alignment. The following table collects address clauses of
219 -- this kind. We put these in a table so that they can be checked after the
220 -- back end has completed annotation of the alignments of objects, since we
221 -- can catch more cases that way.
223 type Address_Clause_Check_Record
is record
225 -- The address clause
228 -- The entity of the object overlaying Y
231 -- The entity of the object being overlaid
234 -- Whether the address is offset within Y
237 package Address_Clause_Checks
is new Table
.Table
(
238 Table_Component_Type
=> Address_Clause_Check_Record
,
239 Table_Index_Type
=> Int
,
240 Table_Low_Bound
=> 1,
242 Table_Increment
=> 200,
243 Table_Name
=> "Address_Clause_Checks");
245 -----------------------------------------
246 -- Adjust_Record_For_Reverse_Bit_Order --
247 -----------------------------------------
249 procedure Adjust_Record_For_Reverse_Bit_Order
(R
: Entity_Id
) is
254 -- Processing depends on version of Ada
256 -- For Ada 95, we just renumber bits within a storage unit. We do the
257 -- same for Ada 83 mode, since we recognize the Bit_Order attribute in
258 -- Ada 83, and are free to add this extension.
260 if Ada_Version
< Ada_2005
then
261 Comp
:= First_Component_Or_Discriminant
(R
);
262 while Present
(Comp
) loop
263 CC
:= Component_Clause
(Comp
);
265 -- If component clause is present, then deal with the non-default
266 -- bit order case for Ada 95 mode.
268 -- We only do this processing for the base type, and in fact that
269 -- is important, since otherwise if there are record subtypes, we
270 -- could reverse the bits once for each subtype, which is wrong.
272 if Present
(CC
) and then Ekind
(R
) = E_Record_Type
then
274 CFB
: constant Uint
:= Component_Bit_Offset
(Comp
);
275 CSZ
: constant Uint
:= Esize
(Comp
);
276 CLC
: constant Node_Id
:= Component_Clause
(Comp
);
277 Pos
: constant Node_Id
:= Position
(CLC
);
278 FB
: constant Node_Id
:= First_Bit
(CLC
);
280 Storage_Unit_Offset
: constant Uint
:=
281 CFB
/ System_Storage_Unit
;
283 Start_Bit
: constant Uint
:=
284 CFB
mod System_Storage_Unit
;
287 -- Cases where field goes over storage unit boundary
289 if Start_Bit
+ CSZ
> System_Storage_Unit
then
291 -- Allow multi-byte field but generate warning
293 if Start_Bit
mod System_Storage_Unit
= 0
294 and then CSZ
mod System_Storage_Unit
= 0
297 ("multi-byte field specified with non-standard"
298 & " Bit_Order??", CLC
);
300 if Bytes_Big_Endian
then
302 ("bytes are not reversed "
303 & "(component is big-endian)??", CLC
);
306 ("bytes are not reversed "
307 & "(component is little-endian)??", CLC
);
310 -- Do not allow non-contiguous field
314 ("attempt to specify non-contiguous field "
315 & "not permitted", CLC
);
317 ("\caused by non-standard Bit_Order "
320 ("\consider possibility of using "
321 & "Ada 2005 mode here", CLC
);
324 -- Case where field fits in one storage unit
327 -- Give warning if suspicious component clause
329 if Intval
(FB
) >= System_Storage_Unit
330 and then Warn_On_Reverse_Bit_Order
333 ("Bit_Order clause does not affect " &
334 "byte ordering?V?", Pos
);
336 Intval
(Pos
) + Intval
(FB
) /
339 ("position normalized to ^ before bit " &
340 "order interpreted?V?", Pos
);
343 -- Here is where we fix up the Component_Bit_Offset value
344 -- to account for the reverse bit order. Some examples of
345 -- what needs to be done are:
347 -- First_Bit .. Last_Bit Component_Bit_Offset
359 -- The rule is that the first bit is is obtained by
360 -- subtracting the old ending bit from storage_unit - 1.
362 Set_Component_Bit_Offset
364 (Storage_Unit_Offset
* System_Storage_Unit
) +
365 (System_Storage_Unit
- 1) -
366 (Start_Bit
+ CSZ
- 1));
368 Set_Normalized_First_Bit
370 Component_Bit_Offset
(Comp
) mod
371 System_Storage_Unit
);
376 Next_Component_Or_Discriminant
(Comp
);
379 -- For Ada 2005, we do machine scalar processing, as fully described In
380 -- AI-133. This involves gathering all components which start at the
381 -- same byte offset and processing them together. Same approach is still
382 -- valid in later versions including Ada 2012.
386 Max_Machine_Scalar_Size
: constant Uint
:=
388 (Standard_Long_Long_Integer_Size
);
389 -- We use this as the maximum machine scalar size
392 SSU
: constant Uint
:= UI_From_Int
(System_Storage_Unit
);
395 -- This first loop through components does two things. First it
396 -- deals with the case of components with component clauses whose
397 -- length is greater than the maximum machine scalar size (either
398 -- accepting them or rejecting as needed). Second, it counts the
399 -- number of components with component clauses whose length does
400 -- not exceed this maximum for later processing.
403 Comp
:= First_Component_Or_Discriminant
(R
);
404 while Present
(Comp
) loop
405 CC
:= Component_Clause
(Comp
);
409 Fbit
: constant Uint
:= Static_Integer
(First_Bit
(CC
));
410 Lbit
: constant Uint
:= Static_Integer
(Last_Bit
(CC
));
413 -- Case of component with last bit >= max machine scalar
415 if Lbit
>= Max_Machine_Scalar_Size
then
417 -- This is allowed only if first bit is zero, and
418 -- last bit + 1 is a multiple of storage unit size.
420 if Fbit
= 0 and then (Lbit
+ 1) mod SSU
= 0 then
422 -- This is the case to give a warning if enabled
424 if Warn_On_Reverse_Bit_Order
then
426 ("multi-byte field specified with "
427 & " non-standard Bit_Order?V?", CC
);
429 if Bytes_Big_Endian
then
431 ("\bytes are not reversed "
432 & "(component is big-endian)?V?", CC
);
435 ("\bytes are not reversed "
436 & "(component is little-endian)?V?", CC
);
440 -- Give error message for RM 13.5.1(10) violation
444 ("machine scalar rules not followed for&",
445 First_Bit
(CC
), Comp
);
447 Error_Msg_Uint_1
:= Lbit
;
448 Error_Msg_Uint_2
:= Max_Machine_Scalar_Size
;
450 ("\last bit (^) exceeds maximum machine "
454 if (Lbit
+ 1) mod SSU
/= 0 then
455 Error_Msg_Uint_1
:= SSU
;
457 ("\and is not a multiple of Storage_Unit (^) "
462 Error_Msg_Uint_1
:= Fbit
;
464 ("\and first bit (^) is non-zero "
470 -- OK case of machine scalar related component clause,
471 -- For now, just count them.
474 Num_CC
:= Num_CC
+ 1;
479 Next_Component_Or_Discriminant
(Comp
);
482 -- We need to sort the component clauses on the basis of the
483 -- Position values in the clause, so we can group clauses with
484 -- the same Position. together to determine the relevant machine
488 Comps
: array (0 .. Num_CC
) of Entity_Id
;
489 -- Array to collect component and discriminant entities. The
490 -- data starts at index 1, the 0'th entry is for the sort
493 function CP_Lt
(Op1
, Op2
: Natural) return Boolean;
494 -- Compare routine for Sort
496 procedure CP_Move
(From
: Natural; To
: Natural);
497 -- Move routine for Sort
499 package Sorting
is new GNAT
.Heap_Sort_G
(CP_Move
, CP_Lt
);
503 -- Start and stop positions in the component list of the set of
504 -- components with the same starting position (that constitute
505 -- components in a single machine scalar).
508 -- Maximum last bit value of any component in this set
511 -- Corresponding machine scalar size
517 function CP_Lt
(Op1
, Op2
: Natural) return Boolean is
519 return Position
(Component_Clause
(Comps
(Op1
))) <
520 Position
(Component_Clause
(Comps
(Op2
)));
527 procedure CP_Move
(From
: Natural; To
: Natural) is
529 Comps
(To
) := Comps
(From
);
532 -- Start of processing for Sort_CC
535 -- Collect the machine scalar relevant component clauses
538 Comp
:= First_Component_Or_Discriminant
(R
);
539 while Present
(Comp
) loop
541 CC
: constant Node_Id
:= Component_Clause
(Comp
);
544 -- Collect only component clauses whose last bit is less
545 -- than machine scalar size. Any component clause whose
546 -- last bit exceeds this value does not take part in
547 -- machine scalar layout considerations. The test for
548 -- Error_Posted makes sure we exclude component clauses
549 -- for which we already posted an error.
552 and then not Error_Posted
(Last_Bit
(CC
))
553 and then Static_Integer
(Last_Bit
(CC
)) <
554 Max_Machine_Scalar_Size
556 Num_CC
:= Num_CC
+ 1;
557 Comps
(Num_CC
) := Comp
;
561 Next_Component_Or_Discriminant
(Comp
);
564 -- Sort by ascending position number
566 Sorting
.Sort
(Num_CC
);
568 -- We now have all the components whose size does not exceed
569 -- the max machine scalar value, sorted by starting position.
570 -- In this loop we gather groups of clauses starting at the
571 -- same position, to process them in accordance with AI-133.
574 while Stop
< Num_CC
loop
579 (Last_Bit
(Component_Clause
(Comps
(Start
))));
580 while Stop
< Num_CC
loop
582 (Position
(Component_Clause
(Comps
(Stop
+ 1)))) =
584 (Position
(Component_Clause
(Comps
(Stop
))))
592 (Component_Clause
(Comps
(Stop
)))));
598 -- Now we have a group of component clauses from Start to
599 -- Stop whose positions are identical, and MaxL is the
600 -- maximum last bit value of any of these components.
602 -- We need to determine the corresponding machine scalar
603 -- size. This loop assumes that machine scalar sizes are
604 -- even, and that each possible machine scalar has twice
605 -- as many bits as the next smaller one.
607 MSS
:= Max_Machine_Scalar_Size
;
609 and then (MSS
/ 2) >= SSU
610 and then (MSS
/ 2) > MaxL
615 -- Here is where we fix up the Component_Bit_Offset value
616 -- to account for the reverse bit order. Some examples of
617 -- what needs to be done for the case of a machine scalar
620 -- First_Bit .. Last_Bit Component_Bit_Offset
632 -- The rule is that the first bit is obtained by subtracting
633 -- the old ending bit from machine scalar size - 1.
635 for C
in Start
.. Stop
loop
637 Comp
: constant Entity_Id
:= Comps
(C
);
638 CC
: constant Node_Id
:= Component_Clause
(Comp
);
640 LB
: constant Uint
:= Static_Integer
(Last_Bit
(CC
));
641 NFB
: constant Uint
:= MSS
- Uint_1
- LB
;
642 NLB
: constant Uint
:= NFB
+ Esize
(Comp
) - 1;
643 Pos
: constant Uint
:= Static_Integer
(Position
(CC
));
646 if Warn_On_Reverse_Bit_Order
then
647 Error_Msg_Uint_1
:= MSS
;
649 ("info: reverse bit order in machine " &
650 "scalar of length^?V?", First_Bit
(CC
));
651 Error_Msg_Uint_1
:= NFB
;
652 Error_Msg_Uint_2
:= NLB
;
654 if Bytes_Big_Endian
then
656 ("\info: big-endian range for "
657 & "component & is ^ .. ^?V?",
658 First_Bit
(CC
), Comp
);
661 ("\info: little-endian range "
662 & "for component & is ^ .. ^?V?",
663 First_Bit
(CC
), Comp
);
667 Set_Component_Bit_Offset
(Comp
, Pos
* SSU
+ NFB
);
668 Set_Normalized_First_Bit
(Comp
, NFB
mod SSU
);
675 end Adjust_Record_For_Reverse_Bit_Order
;
677 -------------------------------------
678 -- Alignment_Check_For_Size_Change --
679 -------------------------------------
681 procedure Alignment_Check_For_Size_Change
(Typ
: Entity_Id
; Size
: Uint
) is
683 -- If the alignment is known, and not set by a rep clause, and is
684 -- inconsistent with the size being set, then reset it to unknown,
685 -- we assume in this case that the size overrides the inherited
686 -- alignment, and that the alignment must be recomputed.
688 if Known_Alignment
(Typ
)
689 and then not Has_Alignment_Clause
(Typ
)
690 and then Size
mod (Alignment
(Typ
) * SSU
) /= 0
692 Init_Alignment
(Typ
);
694 end Alignment_Check_For_Size_Change
;
696 -------------------------------------
697 -- Analyze_Aspects_At_Freeze_Point --
698 -------------------------------------
700 procedure Analyze_Aspects_At_Freeze_Point
(E
: Entity_Id
) is
705 procedure Analyze_Aspect_Default_Value
(ASN
: Node_Id
);
706 -- This routine analyzes an Aspect_Default_[Component_]Value denoted by
707 -- the aspect specification node ASN.
709 procedure Inherit_Delayed_Rep_Aspects
(ASN
: Node_Id
);
710 -- As discussed in the spec of Aspects (see Aspect_Delay declaration),
711 -- a derived type can inherit aspects from its parent which have been
712 -- specified at the time of the derivation using an aspect, as in:
714 -- type A is range 1 .. 10
715 -- with Size => Not_Defined_Yet;
719 -- Not_Defined_Yet : constant := 64;
721 -- In this example, the Size of A is considered to be specified prior
722 -- to the derivation, and thus inherited, even though the value is not
723 -- known at the time of derivation. To deal with this, we use two entity
724 -- flags. The flag Has_Derived_Rep_Aspects is set in the parent type (A
725 -- here), and then the flag May_Inherit_Delayed_Rep_Aspects is set in
726 -- the derived type (B here). If this flag is set when the derived type
727 -- is frozen, then this procedure is called to ensure proper inheritance
728 -- of all delayed aspects from the parent type. The derived type is E,
729 -- the argument to Analyze_Aspects_At_Freeze_Point. ASN is the first
730 -- aspect specification node in the Rep_Item chain for the parent type.
732 procedure Make_Pragma_From_Boolean_Aspect
(ASN
: Node_Id
);
733 -- Given an aspect specification node ASN whose expression is an
734 -- optional Boolean, this routines creates the corresponding pragma
735 -- at the freezing point.
737 ----------------------------------
738 -- Analyze_Aspect_Default_Value --
739 ----------------------------------
741 procedure Analyze_Aspect_Default_Value
(ASN
: Node_Id
) is
742 Ent
: constant Entity_Id
:= Entity
(ASN
);
743 Expr
: constant Node_Id
:= Expression
(ASN
);
744 Id
: constant Node_Id
:= Identifier
(ASN
);
747 Error_Msg_Name_1
:= Chars
(Id
);
749 if not Is_Type
(Ent
) then
750 Error_Msg_N
("aspect% can only apply to a type", Id
);
753 elsif not Is_First_Subtype
(Ent
) then
754 Error_Msg_N
("aspect% cannot apply to subtype", Id
);
757 elsif A_Id
= Aspect_Default_Value
758 and then not Is_Scalar_Type
(Ent
)
760 Error_Msg_N
("aspect% can only be applied to scalar type", Id
);
763 elsif A_Id
= Aspect_Default_Component_Value
then
764 if not Is_Array_Type
(Ent
) then
765 Error_Msg_N
("aspect% can only be applied to array type", Id
);
768 elsif not Is_Scalar_Type
(Component_Type
(Ent
)) then
769 Error_Msg_N
("aspect% requires scalar components", Id
);
774 Set_Has_Default_Aspect
(Base_Type
(Ent
));
776 if Is_Scalar_Type
(Ent
) then
777 Set_Default_Aspect_Value
(Base_Type
(Ent
), Expr
);
779 Set_Default_Aspect_Component_Value
(Base_Type
(Ent
), Expr
);
781 end Analyze_Aspect_Default_Value
;
783 ---------------------------------
784 -- Inherit_Delayed_Rep_Aspects --
785 ---------------------------------
787 procedure Inherit_Delayed_Rep_Aspects
(ASN
: Node_Id
) is
788 P
: constant Entity_Id
:= Entity
(ASN
);
789 -- Entithy for parent type
792 -- Item from Rep_Item chain
797 -- Loop through delayed aspects for the parent type
800 while Present
(N
) loop
801 if Nkind
(N
) = N_Aspect_Specification
then
802 exit when Entity
(N
) /= P
;
804 if Is_Delayed_Aspect
(N
) then
805 A
:= Get_Aspect_Id
(Chars
(Identifier
(N
)));
807 -- Process delayed rep aspect. For Boolean attributes it is
808 -- not possible to cancel an attribute once set (the attempt
809 -- to use an aspect with xxx => False is an error) for a
810 -- derived type. So for those cases, we do not have to check
811 -- if a clause has been given for the derived type, since it
812 -- is harmless to set it again if it is already set.
818 when Aspect_Alignment
=>
819 if not Has_Alignment_Clause
(E
) then
820 Set_Alignment
(E
, Alignment
(P
));
825 when Aspect_Atomic
=>
826 if Is_Atomic
(P
) then
832 when Aspect_Atomic_Components
=>
833 if Has_Atomic_Components
(P
) then
834 Set_Has_Atomic_Components
(Base_Type
(E
));
839 when Aspect_Bit_Order
=>
840 if Is_Record_Type
(E
)
841 and then No
(Get_Attribute_Definition_Clause
842 (E
, Attribute_Bit_Order
))
843 and then Reverse_Bit_Order
(P
)
845 Set_Reverse_Bit_Order
(Base_Type
(E
));
850 when Aspect_Component_Size
=>
852 and then not Has_Component_Size_Clause
(E
)
855 (Base_Type
(E
), Component_Size
(P
));
860 when Aspect_Machine_Radix
=>
861 if Is_Decimal_Fixed_Point_Type
(E
)
862 and then not Has_Machine_Radix_Clause
(E
)
864 Set_Machine_Radix_10
(E
, Machine_Radix_10
(P
));
867 -- Object_Size (also Size which also sets Object_Size)
869 when Aspect_Object_Size | Aspect_Size
=>
870 if not Has_Size_Clause
(E
)
872 No
(Get_Attribute_Definition_Clause
873 (E
, Attribute_Object_Size
))
875 Set_Esize
(E
, Esize
(P
));
881 if not Is_Packed
(E
) then
882 Set_Is_Packed
(Base_Type
(E
));
884 if Is_Bit_Packed_Array
(P
) then
885 Set_Is_Bit_Packed_Array
(Base_Type
(E
));
886 Set_Packed_Array_Type
(E
, Packed_Array_Type
(P
));
890 -- Scalar_Storage_Order
892 when Aspect_Scalar_Storage_Order
=>
893 if (Is_Record_Type
(E
) or else Is_Array_Type
(E
))
894 and then No
(Get_Attribute_Definition_Clause
895 (E
, Attribute_Scalar_Storage_Order
))
896 and then Reverse_Storage_Order
(P
)
898 Set_Reverse_Storage_Order
(Base_Type
(E
));
904 if Is_Fixed_Point_Type
(E
)
905 and then not Has_Small_Clause
(E
)
907 Set_Small_Value
(E
, Small_Value
(P
));
912 when Aspect_Storage_Size
=>
913 if (Is_Access_Type
(E
) or else Is_Task_Type
(E
))
914 and then not Has_Storage_Size_Clause
(E
)
916 Set_Storage_Size_Variable
917 (Base_Type
(E
), Storage_Size_Variable
(P
));
922 when Aspect_Value_Size
=>
924 -- Value_Size is never inherited, it is either set by
925 -- default, or it is explicitly set for the derived
926 -- type. So nothing to do here.
932 when Aspect_Volatile
=>
933 if Is_Volatile
(P
) then
937 -- Volatile_Components
939 when Aspect_Volatile_Components
=>
940 if Has_Volatile_Components
(P
) then
941 Set_Has_Volatile_Components
(Base_Type
(E
));
944 -- That should be all the Rep Aspects
947 pragma Assert
(Aspect_Delay
(A_Id
) /= Rep_Aspect
);
954 N
:= Next_Rep_Item
(N
);
956 end Inherit_Delayed_Rep_Aspects
;
958 -------------------------------------
959 -- Make_Pragma_From_Boolean_Aspect --
960 -------------------------------------
962 procedure Make_Pragma_From_Boolean_Aspect
(ASN
: Node_Id
) is
963 Ident
: constant Node_Id
:= Identifier
(ASN
);
964 A_Name
: constant Name_Id
:= Chars
(Ident
);
965 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(A_Name
);
966 Ent
: constant Entity_Id
:= Entity
(ASN
);
967 Expr
: constant Node_Id
:= Expression
(ASN
);
968 Loc
: constant Source_Ptr
:= Sloc
(ASN
);
972 procedure Check_False_Aspect_For_Derived_Type
;
973 -- This procedure checks for the case of a false aspect for a derived
974 -- type, which improperly tries to cancel an aspect inherited from
977 -----------------------------------------
978 -- Check_False_Aspect_For_Derived_Type --
979 -----------------------------------------
981 procedure Check_False_Aspect_For_Derived_Type
is
985 -- We are only checking derived types
987 if not Is_Derived_Type
(E
) then
991 Par
:= Nearest_Ancestor
(E
);
994 when Aspect_Atomic | Aspect_Shared
=>
995 if not Is_Atomic
(Par
) then
999 when Aspect_Atomic_Components
=>
1000 if not Has_Atomic_Components
(Par
) then
1004 when Aspect_Discard_Names
=>
1005 if not Discard_Names
(Par
) then
1010 if not Is_Packed
(Par
) then
1014 when Aspect_Unchecked_Union
=>
1015 if not Is_Unchecked_Union
(Par
) then
1019 when Aspect_Volatile
=>
1020 if not Is_Volatile
(Par
) then
1024 when Aspect_Volatile_Components
=>
1025 if not Has_Volatile_Components
(Par
) then
1033 -- Fall through means we are canceling an inherited aspect
1035 Error_Msg_Name_1
:= A_Name
;
1037 ("derived type& inherits aspect%, cannot cancel", Expr
, E
);
1039 end Check_False_Aspect_For_Derived_Type
;
1041 -- Start of processing for Make_Pragma_From_Boolean_Aspect
1044 -- Note that we know Expr is present, because for a missing Expr
1045 -- argument, we knew it was True and did not need to delay the
1046 -- evaluation to the freeze point.
1048 if Is_False
(Static_Boolean
(Expr
)) then
1049 Check_False_Aspect_For_Derived_Type
;
1054 Pragma_Argument_Associations
=> New_List
(
1055 Make_Pragma_Argument_Association
(Sloc
(Ident
),
1056 Expression
=> New_Occurrence_Of
(Ent
, Sloc
(Ident
)))),
1058 Pragma_Identifier
=>
1059 Make_Identifier
(Sloc
(Ident
), Chars
(Ident
)));
1061 Set_From_Aspect_Specification
(Prag
, True);
1062 Set_Corresponding_Aspect
(Prag
, ASN
);
1063 Set_Aspect_Rep_Item
(ASN
, Prag
);
1064 Set_Is_Delayed_Aspect
(Prag
);
1065 Set_Parent
(Prag
, ASN
);
1067 end Make_Pragma_From_Boolean_Aspect
;
1069 -- Start of processing for Analyze_Aspects_At_Freeze_Point
1072 -- Must be visible in current scope
1074 if not Scope_Within_Or_Same
(Current_Scope
, Scope
(E
)) then
1078 -- Look for aspect specification entries for this entity
1080 ASN
:= First_Rep_Item
(E
);
1081 while Present
(ASN
) loop
1082 if Nkind
(ASN
) = N_Aspect_Specification
then
1083 exit when Entity
(ASN
) /= E
;
1085 if Is_Delayed_Aspect
(ASN
) then
1086 A_Id
:= Get_Aspect_Id
(ASN
);
1090 -- For aspects whose expression is an optional Boolean, make
1091 -- the corresponding pragma at the freezing point.
1093 when Boolean_Aspects |
1094 Library_Unit_Aspects
=>
1095 Make_Pragma_From_Boolean_Aspect
(ASN
);
1097 -- Special handling for aspects that don't correspond to
1098 -- pragmas/attributes.
1100 when Aspect_Default_Value |
1101 Aspect_Default_Component_Value
=>
1102 Analyze_Aspect_Default_Value
(ASN
);
1104 -- Ditto for iterator aspects, because the corresponding
1105 -- attributes may not have been analyzed yet.
1107 when Aspect_Constant_Indexing |
1108 Aspect_Variable_Indexing |
1109 Aspect_Default_Iterator |
1110 Aspect_Iterator_Element
=>
1111 Analyze
(Expression
(ASN
));
1117 Ritem
:= Aspect_Rep_Item
(ASN
);
1119 if Present
(Ritem
) then
1125 Next_Rep_Item
(ASN
);
1128 -- This is where we inherit delayed rep aspects from our parent. Note
1129 -- that if we fell out of the above loop with ASN non-empty, it means
1130 -- we hit an aspect for an entity other than E, and it must be the
1131 -- type from which we were derived.
1133 if May_Inherit_Delayed_Rep_Aspects
(E
) then
1134 Inherit_Delayed_Rep_Aspects
(ASN
);
1136 end Analyze_Aspects_At_Freeze_Point
;
1138 -----------------------------------
1139 -- Analyze_Aspect_Specifications --
1140 -----------------------------------
1142 procedure Analyze_Aspect_Specifications
(N
: Node_Id
; E
: Entity_Id
) is
1143 procedure Decorate_Aspect_And_Pragma
1146 Delayed
: Boolean := False);
1147 -- Establish the linkages between an aspect and its corresponding
1148 -- pragma. Flag Delayed should be set when both constructs are delayed.
1150 procedure Insert_Delayed_Pragma
(Prag
: Node_Id
);
1151 -- Insert a postcondition-like pragma into the tree depending on the
1152 -- context. Prag must denote one of the following: Pre, Post, Depends,
1153 -- Global or Contract_Cases.
1155 --------------------------------
1156 -- Decorate_Aspect_And_Pragma --
1157 --------------------------------
1159 procedure Decorate_Aspect_And_Pragma
1162 Delayed
: Boolean := False)
1165 Set_Aspect_Rep_Item
(Asp
, Prag
);
1166 Set_Corresponding_Aspect
(Prag
, Asp
);
1167 Set_From_Aspect_Specification
(Prag
);
1168 Set_Is_Delayed_Aspect
(Prag
, Delayed
);
1169 Set_Is_Delayed_Aspect
(Asp
, Delayed
);
1170 Set_Parent
(Prag
, Asp
);
1171 end Decorate_Aspect_And_Pragma
;
1173 ---------------------------
1174 -- Insert_Delayed_Pragma --
1175 ---------------------------
1177 procedure Insert_Delayed_Pragma
(Prag
: Node_Id
) is
1181 -- When the context is a library unit, the pragma is added to the
1182 -- Pragmas_After list.
1184 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
1185 Aux
:= Aux_Decls_Node
(Parent
(N
));
1187 if No
(Pragmas_After
(Aux
)) then
1188 Set_Pragmas_After
(Aux
, New_List
);
1191 Prepend
(Prag
, Pragmas_After
(Aux
));
1193 -- Pragmas associated with subprogram bodies are inserted in the
1194 -- declarative part.
1196 elsif Nkind
(N
) = N_Subprogram_Body
then
1197 if No
(Declarations
(N
)) then
1198 Set_Declarations
(N
, New_List
(Prag
));
1204 -- There may be several aspects associated with the body;
1205 -- preserve the ordering of the corresponding pragmas.
1207 D
:= First
(Declarations
(N
));
1208 while Present
(D
) loop
1209 exit when Nkind
(D
) /= N_Pragma
1210 or else not From_Aspect_Specification
(D
);
1215 Append
(Prag
, Declarations
(N
));
1217 Insert_Before
(D
, Prag
);
1225 Insert_After
(N
, Prag
);
1227 -- Analyze the pragma before analyzing the proper body of a stub.
1228 -- This ensures that the pragma will appear on the proper contract
1229 -- list (see N_Contract).
1231 if Nkind
(N
) = N_Subprogram_Body_Stub
then
1235 end Insert_Delayed_Pragma
;
1243 L
: constant List_Id
:= Aspect_Specifications
(N
);
1245 Ins_Node
: Node_Id
:= N
;
1246 -- Insert pragmas/attribute definition clause after this node when no
1247 -- delayed analysis is required.
1249 -- Start of processing for Analyze_Aspect_Specifications
1251 -- The general processing involves building an attribute definition
1252 -- clause or a pragma node that corresponds to the aspect. Then in order
1253 -- to delay the evaluation of this aspect to the freeze point, we attach
1254 -- the corresponding pragma/attribute definition clause to the aspect
1255 -- specification node, which is then placed in the Rep Item chain. In
1256 -- this case we mark the entity by setting the flag Has_Delayed_Aspects
1257 -- and we evaluate the rep item at the freeze point. When the aspect
1258 -- doesn't have a corresponding pragma/attribute definition clause, then
1259 -- its analysis is simply delayed at the freeze point.
1261 -- Some special cases don't require delay analysis, thus the aspect is
1262 -- analyzed right now.
1264 -- Note that there is a special handling for Pre, Post, Test_Case,
1265 -- Contract_Cases aspects. In these cases, we do not have to worry
1266 -- about delay issues, since the pragmas themselves deal with delay
1267 -- of visibility for the expression analysis. Thus, we just insert
1268 -- the pragma after the node N.
1271 pragma Assert
(Present
(L
));
1273 -- Loop through aspects
1275 Aspect
:= First
(L
);
1276 Aspect_Loop
: while Present
(Aspect
) loop
1277 Analyze_One_Aspect
: declare
1278 Expr
: constant Node_Id
:= Expression
(Aspect
);
1279 Id
: constant Node_Id
:= Identifier
(Aspect
);
1280 Loc
: constant Source_Ptr
:= Sloc
(Aspect
);
1281 Nam
: constant Name_Id
:= Chars
(Id
);
1282 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Nam
);
1285 Delay_Required
: Boolean;
1286 -- Set False if delay is not required
1288 Eloc
: Source_Ptr
:= No_Location
;
1289 -- Source location of expression, modified when we split PPC's. It
1290 -- is set below when Expr is present.
1292 procedure Analyze_Aspect_External_Or_Link_Name
;
1293 -- Perform analysis of the External_Name or Link_Name aspects
1295 procedure Analyze_Aspect_Implicit_Dereference
;
1296 -- Perform analysis of the Implicit_Dereference aspects
1298 procedure Make_Aitem_Pragma
1299 (Pragma_Argument_Associations
: List_Id
;
1300 Pragma_Name
: Name_Id
);
1301 -- This is a wrapper for Make_Pragma used for converting aspects
1302 -- to pragmas. It takes care of Sloc (set from Loc) and building
1303 -- the pragma identifier from the given name. In addition the
1304 -- flags Class_Present and Split_PPC are set from the aspect
1305 -- node, as well as Is_Ignored. This routine also sets the
1306 -- From_Aspect_Specification in the resulting pragma node to
1307 -- True, and sets Corresponding_Aspect to point to the aspect.
1308 -- The resulting pragma is assigned to Aitem.
1310 ------------------------------------------
1311 -- Analyze_Aspect_External_Or_Link_Name --
1312 ------------------------------------------
1314 procedure Analyze_Aspect_External_Or_Link_Name
is
1316 -- Verify that there is an Import/Export aspect defined for the
1317 -- entity. The processing of that aspect in turn checks that
1318 -- there is a Convention aspect declared. The pragma is
1319 -- constructed when processing the Convention aspect.
1326 while Present
(A
) loop
1327 exit when Nam_In
(Chars
(Identifier
(A
)), Name_Export
,
1334 ("missing Import/Export for Link/External name",
1338 end Analyze_Aspect_External_Or_Link_Name
;
1340 -----------------------------------------
1341 -- Analyze_Aspect_Implicit_Dereference --
1342 -----------------------------------------
1344 procedure Analyze_Aspect_Implicit_Dereference
is
1346 if not Is_Type
(E
) or else not Has_Discriminants
(E
) then
1348 ("aspect must apply to a type with discriminants", N
);
1355 Disc
:= First_Discriminant
(E
);
1356 while Present
(Disc
) loop
1357 if Chars
(Expr
) = Chars
(Disc
)
1358 and then Ekind
(Etype
(Disc
)) =
1359 E_Anonymous_Access_Type
1361 Set_Has_Implicit_Dereference
(E
);
1362 Set_Has_Implicit_Dereference
(Disc
);
1366 Next_Discriminant
(Disc
);
1369 -- Error if no proper access discriminant.
1372 ("not an access discriminant of&", Expr
, E
);
1375 end Analyze_Aspect_Implicit_Dereference
;
1377 -----------------------
1378 -- Make_Aitem_Pragma --
1379 -----------------------
1381 procedure Make_Aitem_Pragma
1382 (Pragma_Argument_Associations
: List_Id
;
1383 Pragma_Name
: Name_Id
)
1385 Args
: List_Id
:= Pragma_Argument_Associations
;
1388 -- We should never get here if aspect was disabled
1390 pragma Assert
(not Is_Disabled
(Aspect
));
1392 -- Certain aspects allow for an optional name or expression. Do
1393 -- not generate a pragma with empty argument association list.
1395 if No
(Args
) or else No
(Expression
(First
(Args
))) then
1403 Pragma_Argument_Associations
=> Args
,
1404 Pragma_Identifier
=>
1405 Make_Identifier
(Sloc
(Id
), Pragma_Name
),
1406 Class_Present
=> Class_Present
(Aspect
),
1407 Split_PPC
=> Split_PPC
(Aspect
));
1409 -- Set additional semantic fields
1411 if Is_Ignored
(Aspect
) then
1412 Set_Is_Ignored
(Aitem
);
1413 elsif Is_Checked
(Aspect
) then
1414 Set_Is_Checked
(Aitem
);
1417 Set_Corresponding_Aspect
(Aitem
, Aspect
);
1418 Set_From_Aspect_Specification
(Aitem
, True);
1419 end Make_Aitem_Pragma
;
1421 -- Start of processing for Analyze_One_Aspect
1424 -- Skip aspect if already analyzed (not clear if this is needed)
1426 if Analyzed
(Aspect
) then
1430 -- Skip looking at aspect if it is totally disabled. Just mark it
1431 -- as such for later reference in the tree. This also sets the
1432 -- Is_Ignored and Is_Checked flags appropriately.
1434 Check_Applicable_Policy
(Aspect
);
1436 if Is_Disabled
(Aspect
) then
1440 -- Set the source location of expression, used in the case of
1441 -- a failed precondition/postcondition or invariant. Note that
1442 -- the source location of the expression is not usually the best
1443 -- choice here. For example, it gets located on the last AND
1444 -- keyword in a chain of boolean expressiond AND'ed together.
1445 -- It is best to put the message on the first character of the
1446 -- assertion, which is the effect of the First_Node call here.
1448 if Present
(Expr
) then
1449 Eloc
:= Sloc
(First_Node
(Expr
));
1452 -- Check restriction No_Implementation_Aspect_Specifications
1454 if Implementation_Defined_Aspect
(A_Id
) then
1456 (No_Implementation_Aspect_Specifications
, Aspect
);
1459 -- Check restriction No_Specification_Of_Aspect
1461 Check_Restriction_No_Specification_Of_Aspect
(Aspect
);
1463 -- Analyze this aspect (actual analysis is delayed till later)
1465 Set_Analyzed
(Aspect
);
1466 Set_Entity
(Aspect
, E
);
1467 Ent
:= New_Occurrence_Of
(E
, Sloc
(Id
));
1469 -- Check for duplicate aspect. Note that the Comes_From_Source
1470 -- test allows duplicate Pre/Post's that we generate internally
1471 -- to escape being flagged here.
1473 if No_Duplicates_Allowed
(A_Id
) then
1475 while Anod
/= Aspect
loop
1476 if Comes_From_Source
(Aspect
)
1477 and then Same_Aspect
(A_Id
, Get_Aspect_Id
(Anod
))
1479 Error_Msg_Name_1
:= Nam
;
1480 Error_Msg_Sloc
:= Sloc
(Anod
);
1482 -- Case of same aspect specified twice
1484 if Class_Present
(Anod
) = Class_Present
(Aspect
) then
1485 if not Class_Present
(Anod
) then
1487 ("aspect% for & previously given#",
1491 ("aspect `%''Class` for & previously given#",
1501 -- Check some general restrictions on language defined aspects
1503 if not Implementation_Defined_Aspect
(A_Id
) then
1504 Error_Msg_Name_1
:= Nam
;
1506 -- Not allowed for renaming declarations
1508 if Nkind
(N
) in N_Renaming_Declaration
then
1510 ("aspect % not allowed for renaming declaration",
1514 -- Not allowed for formal type declarations
1516 if Nkind
(N
) = N_Formal_Type_Declaration
then
1518 ("aspect % not allowed for formal type declaration",
1523 -- Copy expression for later processing by the procedures
1524 -- Check_Aspect_At_[Freeze_Point | End_Of_Declarations]
1526 Set_Entity
(Id
, New_Copy_Tree
(Expr
));
1528 -- Set Delay_Required as appropriate to aspect
1530 case Aspect_Delay
(A_Id
) is
1531 when Always_Delay
=>
1532 Delay_Required
:= True;
1535 Delay_Required
:= False;
1539 -- If expression has the form of an integer literal, then
1540 -- do not delay, since we know the value cannot change.
1541 -- This optimization catches most rep clause cases.
1543 if (Present
(Expr
) and then Nkind
(Expr
) = N_Integer_Literal
)
1544 or else (A_Id
in Boolean_Aspects
and then No
(Expr
))
1546 Delay_Required
:= False;
1548 Delay_Required
:= True;
1549 Set_Has_Delayed_Rep_Aspects
(E
);
1553 -- Processing based on specific aspect
1557 -- No_Aspect should be impossible
1560 raise Program_Error
;
1562 -- Case 1: Aspects corresponding to attribute definition
1565 when Aspect_Address |
1568 Aspect_Component_Size |
1569 Aspect_Constant_Indexing |
1570 Aspect_Default_Iterator |
1571 Aspect_Dispatching_Domain |
1572 Aspect_External_Tag |
1574 Aspect_Iterator_Element |
1575 Aspect_Machine_Radix |
1576 Aspect_Object_Size |
1579 Aspect_Scalar_Storage_Order |
1582 Aspect_Simple_Storage_Pool |
1583 Aspect_Storage_Pool |
1584 Aspect_Stream_Size |
1586 Aspect_Variable_Indexing |
1589 -- Indexing aspects apply only to tagged type
1591 if (A_Id
= Aspect_Constant_Indexing
1593 A_Id
= Aspect_Variable_Indexing
)
1594 and then not (Is_Type
(E
)
1595 and then Is_Tagged_Type
(E
))
1597 Error_Msg_N
("indexing applies to a tagged type", N
);
1601 -- For case of address aspect, we don't consider that we
1602 -- know the entity is never set in the source, since it is
1603 -- is likely aliasing is occurring.
1605 -- Note: one might think that the analysis of the resulting
1606 -- attribute definition clause would take care of that, but
1607 -- that's not the case since it won't be from source.
1609 if A_Id
= Aspect_Address
then
1610 Set_Never_Set_In_Source
(E
, False);
1613 -- Construct the attribute definition clause
1616 Make_Attribute_Definition_Clause
(Loc
,
1618 Chars
=> Chars
(Id
),
1619 Expression
=> Relocate_Node
(Expr
));
1621 -- If the address is specified, then we treat the entity as
1622 -- referenced, to avoid spurious warnings. This is analogous
1623 -- to what is done with an attribute definition clause, but
1624 -- here we don't want to generate a reference because this
1625 -- is the point of definition of the entity.
1627 if A_Id
= Aspect_Address
then
1631 -- Case 2: Aspects corresponding to pragmas
1633 -- Case 2a: Aspects corresponding to pragmas with two
1634 -- arguments, where the first argument is a local name
1635 -- referring to the entity, and the second argument is the
1636 -- aspect definition expression.
1638 -- Linker_Section/Suppress/Unsuppress
1640 when Aspect_Linker_Section |
1642 Aspect_Unsuppress
=>
1645 (Pragma_Argument_Associations
=> New_List
(
1646 Make_Pragma_Argument_Association
(Loc
,
1647 Expression
=> New_Occurrence_Of
(E
, Loc
)),
1648 Make_Pragma_Argument_Association
(Sloc
(Expr
),
1649 Expression
=> Relocate_Node
(Expr
))),
1650 Pragma_Name
=> Chars
(Id
));
1654 -- Corresponds to pragma Implemented, construct the pragma
1656 when Aspect_Synchronization
=>
1659 (Pragma_Argument_Associations
=> New_List
(
1660 Make_Pragma_Argument_Association
(Loc
,
1661 Expression
=> New_Occurrence_Of
(E
, Loc
)),
1662 Make_Pragma_Argument_Association
(Sloc
(Expr
),
1663 Expression
=> Relocate_Node
(Expr
))),
1664 Pragma_Name
=> Name_Implemented
);
1668 when Aspect_Attach_Handler
=>
1670 (Pragma_Argument_Associations
=> New_List
(
1671 Make_Pragma_Argument_Association
(Sloc
(Ent
),
1673 Make_Pragma_Argument_Association
(Sloc
(Expr
),
1674 Expression
=> Relocate_Node
(Expr
))),
1675 Pragma_Name
=> Name_Attach_Handler
);
1677 -- Dynamic_Predicate, Predicate, Static_Predicate
1679 when Aspect_Dynamic_Predicate |
1681 Aspect_Static_Predicate
=>
1683 -- Construct the pragma (always a pragma Predicate, with
1684 -- flags recording whether it is static/dynamic). We also
1685 -- set flags recording this in the type itself.
1688 (Pragma_Argument_Associations
=> New_List
(
1689 Make_Pragma_Argument_Association
(Sloc
(Ent
),
1691 Make_Pragma_Argument_Association
(Sloc
(Expr
),
1692 Expression
=> Relocate_Node
(Expr
))),
1693 Pragma_Name
=> Name_Predicate
);
1695 -- Mark type has predicates, and remember what kind of
1696 -- aspect lead to this predicate (we need this to access
1697 -- the right set of check policies later on).
1699 Set_Has_Predicates
(E
);
1701 if A_Id
= Aspect_Dynamic_Predicate
then
1702 Set_Has_Dynamic_Predicate_Aspect
(E
);
1703 elsif A_Id
= Aspect_Static_Predicate
then
1704 Set_Has_Static_Predicate_Aspect
(E
);
1707 -- If the type is private, indicate that its completion
1708 -- has a freeze node, because that is the one that will
1709 -- be visible at freeze time.
1711 if Is_Private_Type
(E
) and then Present
(Full_View
(E
)) then
1712 Set_Has_Predicates
(Full_View
(E
));
1714 if A_Id
= Aspect_Dynamic_Predicate
then
1715 Set_Has_Dynamic_Predicate_Aspect
(Full_View
(E
));
1716 elsif A_Id
= Aspect_Static_Predicate
then
1717 Set_Has_Static_Predicate_Aspect
(Full_View
(E
));
1720 Set_Has_Delayed_Aspects
(Full_View
(E
));
1721 Ensure_Freeze_Node
(Full_View
(E
));
1724 -- Case 2b: Aspects corresponding to pragmas with two
1725 -- arguments, where the second argument is a local name
1726 -- referring to the entity, and the first argument is the
1727 -- aspect definition expression.
1731 when Aspect_Convention
=>
1733 -- The aspect may be part of the specification of an import
1734 -- or export pragma. Scan the aspect list to gather the
1735 -- other components, if any. The name of the generated
1736 -- pragma is one of Convention/Import/Export.
1748 P_Name
:= Chars
(Id
);
1750 Arg_List
:= New_List
;
1755 while Present
(A
) loop
1756 A_Name
:= Chars
(Identifier
(A
));
1758 if Nam_In
(A_Name
, Name_Import
, Name_Export
) then
1760 Error_Msg_N
("conflicting", A
);
1767 elsif A_Name
= Name_Link_Name
then
1769 Make_Pragma_Argument_Association
(Loc
,
1771 Expression
=> Relocate_Node
(Expression
(A
)));
1773 elsif A_Name
= Name_External_Name
then
1775 Make_Pragma_Argument_Association
(Loc
,
1777 Expression
=> Relocate_Node
(Expression
(A
)));
1783 Arg_List
:= New_List
(
1784 Make_Pragma_Argument_Association
(Sloc
(Expr
),
1785 Expression
=> Relocate_Node
(Expr
)),
1786 Make_Pragma_Argument_Association
(Sloc
(Ent
),
1787 Expression
=> Ent
));
1789 if Present
(L_Assoc
) then
1790 Append_To
(Arg_List
, L_Assoc
);
1793 if Present
(E_Assoc
) then
1794 Append_To
(Arg_List
, E_Assoc
);
1798 (Pragma_Argument_Associations
=> Arg_List
,
1799 Pragma_Name
=> P_Name
);
1802 -- CPU, Interrupt_Priority, Priority
1804 -- These three aspects can be specified for a subprogram spec
1805 -- or body, in which case we analyze the expression and export
1806 -- the value of the aspect.
1808 -- Previously, we generated an equivalent pragma for bodies
1809 -- (note that the specs cannot contain these pragmas). The
1810 -- pragma was inserted ahead of local declarations, rather than
1811 -- after the body. This leads to a certain duplication between
1812 -- the processing performed for the aspect and the pragma, but
1813 -- given the straightforward handling required it is simpler
1814 -- to duplicate than to translate the aspect in the spec into
1815 -- a pragma in the declarative part of the body.
1818 Aspect_Interrupt_Priority |
1821 if Nkind_In
(N
, N_Subprogram_Body
,
1822 N_Subprogram_Declaration
)
1824 -- Analyze the aspect expression
1826 Analyze_And_Resolve
(Expr
, Standard_Integer
);
1828 -- Interrupt_Priority aspect not allowed for main
1829 -- subprograms. ARM D.1 does not forbid this explicitly,
1830 -- but ARM J.15.11 (6/3) does not permit pragma
1831 -- Interrupt_Priority for subprograms.
1833 if A_Id
= Aspect_Interrupt_Priority
then
1835 ("Interrupt_Priority aspect cannot apply to "
1836 & "subprogram", Expr
);
1838 -- The expression must be static
1840 elsif not Is_Static_Expression
(Expr
) then
1841 Flag_Non_Static_Expr
1842 ("aspect requires static expression!", Expr
);
1844 -- Check whether this is the main subprogram. Issue a
1845 -- warning only if it is obviously not a main program
1846 -- (when it has parameters or when the subprogram is
1847 -- within a package).
1849 elsif Present
(Parameter_Specifications
1850 (Specification
(N
)))
1851 or else not Is_Compilation_Unit
(Defining_Entity
(N
))
1853 -- See ARM D.1 (14/3) and D.16 (12/3)
1856 ("aspect applied to subprogram other than the "
1857 & "main subprogram has no effect??", Expr
);
1859 -- Otherwise check in range and export the value
1861 -- For the CPU aspect
1863 elsif A_Id
= Aspect_CPU
then
1864 if Is_In_Range
(Expr
, RTE
(RE_CPU_Range
)) then
1866 -- Value is correct so we export the value to make
1867 -- it available at execution time.
1870 (Main_Unit
, UI_To_Int
(Expr_Value
(Expr
)));
1874 ("main subprogram CPU is out of range", Expr
);
1877 -- For the Priority aspect
1879 elsif A_Id
= Aspect_Priority
then
1880 if Is_In_Range
(Expr
, RTE
(RE_Priority
)) then
1882 -- Value is correct so we export the value to make
1883 -- it available at execution time.
1886 (Main_Unit
, UI_To_Int
(Expr_Value
(Expr
)));
1890 ("main subprogram priority is out of range",
1895 -- Load an arbitrary entity from System.Tasking.Stages
1896 -- or System.Tasking.Restricted.Stages (depending on
1897 -- the supported profile) to make sure that one of these
1898 -- packages is implicitly with'ed, since we need to have
1899 -- the tasking run time active for the pragma Priority to
1900 -- have any effect. Previously with with'ed the package
1901 -- System.Tasking, but this package does not trigger the
1902 -- required initialization of the run-time library.
1905 Discard
: Entity_Id
;
1906 pragma Warnings
(Off
, Discard
);
1908 if Restricted_Profile
then
1909 Discard
:= RTE
(RE_Activate_Restricted_Tasks
);
1911 Discard
:= RTE
(RE_Activate_Tasks
);
1915 -- Handling for these Aspects in subprograms is complete
1922 -- Pass the aspect as an attribute
1925 Make_Attribute_Definition_Clause
(Loc
,
1927 Chars
=> Chars
(Id
),
1928 Expression
=> Relocate_Node
(Expr
));
1933 when Aspect_Warnings
=>
1935 (Pragma_Argument_Associations
=> New_List
(
1936 Make_Pragma_Argument_Association
(Sloc
(Expr
),
1937 Expression
=> Relocate_Node
(Expr
)),
1938 Make_Pragma_Argument_Association
(Loc
,
1939 Expression
=> New_Occurrence_Of
(E
, Loc
))),
1940 Pragma_Name
=> Chars
(Id
));
1942 -- Case 2c: Aspects corresponding to pragmas with three
1945 -- Invariant aspects have a first argument that references the
1946 -- entity, a second argument that is the expression and a third
1947 -- argument that is an appropriate message.
1949 -- Invariant, Type_Invariant
1951 when Aspect_Invariant |
1952 Aspect_Type_Invariant
=>
1954 -- Analysis of the pragma will verify placement legality:
1955 -- an invariant must apply to a private type, or appear in
1956 -- the private part of a spec and apply to a completion.
1959 (Pragma_Argument_Associations
=> New_List
(
1960 Make_Pragma_Argument_Association
(Sloc
(Ent
),
1962 Make_Pragma_Argument_Association
(Sloc
(Expr
),
1963 Expression
=> Relocate_Node
(Expr
))),
1964 Pragma_Name
=> Name_Invariant
);
1966 -- Add message unless exception messages are suppressed
1968 if not Opt
.Exception_Locations_Suppressed
then
1969 Append_To
(Pragma_Argument_Associations
(Aitem
),
1970 Make_Pragma_Argument_Association
(Eloc
,
1971 Chars
=> Name_Message
,
1973 Make_String_Literal
(Eloc
,
1974 Strval
=> "failed invariant from "
1975 & Build_Location_String
(Eloc
))));
1978 -- For Invariant case, insert immediately after the entity
1979 -- declaration. We do not have to worry about delay issues
1980 -- since the pragma processing takes care of this.
1982 Delay_Required
:= False;
1984 -- Case 2d : Aspects that correspond to a pragma with one
1989 -- Aspect Abstract_State introduces implicit declarations for
1990 -- all state abstraction entities it defines. To emulate this
1991 -- behavior, insert the pragma at the beginning of the visible
1992 -- declarations of the related package so that it is analyzed
1995 when Aspect_Abstract_State
=> Abstract_State
: declare
1999 if Nkind_In
(N
, N_Generic_Package_Declaration
,
2000 N_Package_Declaration
)
2002 Decls
:= Visible_Declarations
(Specification
(N
));
2005 (Pragma_Argument_Associations
=> New_List
(
2006 Make_Pragma_Argument_Association
(Loc
,
2007 Expression
=> Relocate_Node
(Expr
))),
2008 Pragma_Name
=> Name_Abstract_State
);
2009 Decorate_Aspect_And_Pragma
(Aspect
, Aitem
);
2013 Set_Visible_Declarations
(N
, Decls
);
2016 Prepend_To
(Decls
, Aitem
);
2020 ("aspect & must apply to a package declaration",
2029 -- Aspect Depends must be delayed because it mentions names
2030 -- of inputs and output that are classified by aspect Global.
2031 -- The aspect and pragma are treated the same way as a post
2034 when Aspect_Depends
=>
2036 (Pragma_Argument_Associations
=> New_List
(
2037 Make_Pragma_Argument_Association
(Loc
,
2038 Expression
=> Relocate_Node
(Expr
))),
2039 Pragma_Name
=> Name_Depends
);
2041 Decorate_Aspect_And_Pragma
2042 (Aspect
, Aitem
, Delayed
=> True);
2043 Insert_Delayed_Pragma
(Aitem
);
2048 -- Aspect Global must be delayed because it can mention names
2049 -- and benefit from the forward visibility rules applicable to
2050 -- aspects of subprograms. The aspect and pragma are treated
2051 -- the same way as a post condition.
2053 when Aspect_Global
=>
2055 (Pragma_Argument_Associations
=> New_List
(
2056 Make_Pragma_Argument_Association
(Loc
,
2057 Expression
=> Relocate_Node
(Expr
))),
2058 Pragma_Name
=> Name_Global
);
2060 Decorate_Aspect_And_Pragma
2061 (Aspect
, Aitem
, Delayed
=> True);
2062 Insert_Delayed_Pragma
(Aitem
);
2065 -- Initial_Condition
2067 -- Aspect Initial_Condition covers the visible declarations of
2068 -- a package and all hidden states through functions. As such,
2069 -- it must be evaluated at the end of the said declarations.
2071 when Aspect_Initial_Condition
=> Initial_Condition
: declare
2075 if Nkind_In
(N
, N_Generic_Package_Declaration
,
2076 N_Package_Declaration
)
2078 Decls
:= Visible_Declarations
(Specification
(N
));
2081 (Pragma_Argument_Associations
=> New_List
(
2082 Make_Pragma_Argument_Association
(Loc
,
2083 Expression
=> Relocate_Node
(Expr
))),
2085 Name_Initial_Condition
);
2087 Decorate_Aspect_And_Pragma
2088 (Aspect
, Aitem
, Delayed
=> True);
2092 Set_Visible_Declarations
(N
, Decls
);
2095 Prepend_To
(Decls
, Aitem
);
2099 ("aspect & must apply to a package declaration",
2104 end Initial_Condition
;
2108 -- Aspect Initializes coverts the visible declarations of a
2109 -- package. As such, it must be evaluated at the end of the
2110 -- said declarations.
2112 when Aspect_Initializes
=> Initializes
: declare
2116 if Nkind_In
(N
, N_Generic_Package_Declaration
,
2117 N_Package_Declaration
)
2119 Decls
:= Visible_Declarations
(Specification
(N
));
2122 (Pragma_Argument_Associations
=> New_List
(
2123 Make_Pragma_Argument_Association
(Loc
,
2124 Expression
=> Relocate_Node
(Expr
))),
2125 Pragma_Name
=> Name_Initializes
);
2127 Decorate_Aspect_And_Pragma
2128 (Aspect
, Aitem
, Delayed
=> True);
2132 Set_Visible_Declarations
(N
, Decls
);
2135 Prepend_To
(Decls
, Aitem
);
2139 ("aspect & must apply to a package declaration",
2148 when Aspect_Part_Of
=>
2149 if Nkind_In
(N
, N_Object_Declaration
,
2150 N_Package_Instantiation
)
2153 (Pragma_Argument_Associations
=> New_List
(
2154 Make_Pragma_Argument_Association
(Loc
,
2155 Expression
=> Relocate_Node
(Expr
))),
2156 Pragma_Name
=> Name_Part_Of
);
2160 ("aspect & must apply to a variable or package "
2161 & "instantiation", Aspect
, Id
);
2166 when Aspect_SPARK_Mode
=> SPARK_Mode
: declare
2171 (Pragma_Argument_Associations
=> New_List
(
2172 Make_Pragma_Argument_Association
(Loc
,
2173 Expression
=> Relocate_Node
(Expr
))),
2174 Pragma_Name
=> Name_SPARK_Mode
);
2176 -- When the aspect appears on a package body, insert the
2177 -- generated pragma at the top of the body declarations to
2178 -- emulate the behavior of a source pragma.
2180 if Nkind
(N
) = N_Package_Body
then
2181 Decorate_Aspect_And_Pragma
(Aspect
, Aitem
);
2183 Decls
:= Declarations
(N
);
2187 Set_Declarations
(N
, Decls
);
2190 Prepend_To
(Decls
, Aitem
);
2193 -- When the aspect is associated with package declaration,
2194 -- insert the generated pragma at the top of the visible
2195 -- declarations to emulate the behavior of a source pragma.
2197 elsif Nkind
(N
) = N_Package_Declaration
then
2198 Decorate_Aspect_And_Pragma
(Aspect
, Aitem
);
2200 Decls
:= Visible_Declarations
(Specification
(N
));
2204 Set_Visible_Declarations
(Specification
(N
), Decls
);
2207 Prepend_To
(Decls
, Aitem
);
2214 -- Aspect Refined_Depends must be delayed because it can
2215 -- mention state refinements introduced by aspect Refined_State
2216 -- and further classified by aspect Refined_Global. Since both
2217 -- those aspects are delayed, so is Refined_Depends.
2219 when Aspect_Refined_Depends
=>
2221 (Pragma_Argument_Associations
=> New_List
(
2222 Make_Pragma_Argument_Association
(Loc
,
2223 Expression
=> Relocate_Node
(Expr
))),
2224 Pragma_Name
=> Name_Refined_Depends
);
2226 Decorate_Aspect_And_Pragma
2227 (Aspect
, Aitem
, Delayed
=> True);
2228 Insert_Delayed_Pragma
(Aitem
);
2233 -- Aspect Refined_Global must be delayed because it can mention
2234 -- state refinements introduced by aspect Refined_State. Since
2235 -- Refined_State is already delayed due to forward references,
2236 -- so is Refined_Global.
2238 when Aspect_Refined_Global
=>
2240 (Pragma_Argument_Associations
=> New_List
(
2241 Make_Pragma_Argument_Association
(Loc
,
2242 Expression
=> Relocate_Node
(Expr
))),
2243 Pragma_Name
=> Name_Refined_Global
);
2245 Decorate_Aspect_And_Pragma
(Aspect
, Aitem
, Delayed
=> True);
2246 Insert_Delayed_Pragma
(Aitem
);
2251 when Aspect_Refined_Post
=>
2253 (Pragma_Argument_Associations
=> New_List
(
2254 Make_Pragma_Argument_Association
(Loc
,
2255 Expression
=> Relocate_Node
(Expr
))),
2256 Pragma_Name
=> Name_Refined_Post
);
2260 when Aspect_Refined_State
=> Refined_State
: declare
2264 -- The corresponding pragma for Refined_State is inserted in
2265 -- the declarations of the related package body. This action
2266 -- synchronizes both the source and from-aspect versions of
2269 if Nkind
(N
) = N_Package_Body
then
2270 Decls
:= Declarations
(N
);
2273 (Pragma_Argument_Associations
=> New_List
(
2274 Make_Pragma_Argument_Association
(Loc
,
2275 Expression
=> Relocate_Node
(Expr
))),
2276 Pragma_Name
=> Name_Refined_State
);
2277 Decorate_Aspect_And_Pragma
(Aspect
, Aitem
);
2281 Set_Declarations
(N
, Decls
);
2284 Prepend_To
(Decls
, Aitem
);
2288 ("aspect & must apply to a package body", Aspect
, Id
);
2294 -- Relative_Deadline
2296 when Aspect_Relative_Deadline
=>
2298 (Pragma_Argument_Associations
=> New_List
(
2299 Make_Pragma_Argument_Association
(Loc
,
2300 Expression
=> Relocate_Node
(Expr
))),
2301 Pragma_Name
=> Name_Relative_Deadline
);
2303 -- If the aspect applies to a task, the corresponding pragma
2304 -- must appear within its declarations, not after.
2306 if Nkind
(N
) = N_Task_Type_Declaration
then
2312 if No
(Task_Definition
(N
)) then
2313 Set_Task_Definition
(N
,
2314 Make_Task_Definition
(Loc
,
2315 Visible_Declarations
=> New_List
,
2316 End_Label
=> Empty
));
2319 Def
:= Task_Definition
(N
);
2320 V
:= Visible_Declarations
(Def
);
2321 if not Is_Empty_List
(V
) then
2322 Insert_Before
(First
(V
), Aitem
);
2325 Set_Visible_Declarations
(Def
, New_List
(Aitem
));
2332 -- Case 3 : Aspects that don't correspond to pragma/attribute
2333 -- definition clause.
2335 -- Case 3a: The aspects listed below don't correspond to
2336 -- pragmas/attributes but do require delayed analysis.
2338 -- Default_Value, Default_Component_Value
2340 when Aspect_Default_Value |
2341 Aspect_Default_Component_Value
=>
2344 -- Case 3b: The aspects listed below don't correspond to
2345 -- pragmas/attributes and don't need delayed analysis.
2347 -- Implicit_Dereference
2349 -- For Implicit_Dereference, External_Name and Link_Name, only
2350 -- the legality checks are done during the analysis, thus no
2351 -- delay is required.
2353 when Aspect_Implicit_Dereference
=>
2354 Analyze_Aspect_Implicit_Dereference
;
2357 -- External_Name, Link_Name
2359 when Aspect_External_Name |
2361 Analyze_Aspect_External_Or_Link_Name
;
2366 when Aspect_Dimension
=>
2367 Analyze_Aspect_Dimension
(N
, Id
, Expr
);
2372 when Aspect_Dimension_System
=>
2373 Analyze_Aspect_Dimension_System
(N
, Id
, Expr
);
2376 -- Case 4: Aspects requiring special handling
2378 -- Pre/Post/Test_Case/Contract_Cases whose corresponding
2379 -- pragmas take care of the delay.
2383 -- Aspects Pre/Post generate Precondition/Postcondition pragmas
2384 -- with a first argument that is the expression, and a second
2385 -- argument that is an informative message if the test fails.
2386 -- This is inserted right after the declaration, to get the
2387 -- required pragma placement. The processing for the pragmas
2388 -- takes care of the required delay.
2390 when Pre_Post_Aspects
=> Pre_Post
: declare
2394 if A_Id
= Aspect_Pre
or else A_Id
= Aspect_Precondition
then
2395 Pname
:= Name_Precondition
;
2397 Pname
:= Name_Postcondition
;
2400 -- If the expressions is of the form A and then B, then
2401 -- we generate separate Pre/Post aspects for the separate
2402 -- clauses. Since we allow multiple pragmas, there is no
2403 -- problem in allowing multiple Pre/Post aspects internally.
2404 -- These should be treated in reverse order (B first and
2405 -- A second) since they are later inserted just after N in
2406 -- the order they are treated. This way, the pragma for A
2407 -- ends up preceding the pragma for B, which may have an
2408 -- importance for the error raised (either constraint error
2409 -- or precondition error).
2411 -- We do not do this for Pre'Class, since we have to put
2412 -- these conditions together in a complex OR expression
2414 -- We do not do this in ASIS mode, as ASIS relies on the
2415 -- original node representing the complete expression, when
2416 -- retrieving it through the source aspect table.
2419 and then (Pname
= Name_Postcondition
2420 or else not Class_Present
(Aspect
))
2422 while Nkind
(Expr
) = N_And_Then
loop
2423 Insert_After
(Aspect
,
2424 Make_Aspect_Specification
(Sloc
(Left_Opnd
(Expr
)),
2425 Identifier
=> Identifier
(Aspect
),
2426 Expression
=> Relocate_Node
(Left_Opnd
(Expr
)),
2427 Class_Present
=> Class_Present
(Aspect
),
2428 Split_PPC
=> True));
2429 Rewrite
(Expr
, Relocate_Node
(Right_Opnd
(Expr
)));
2430 Eloc
:= Sloc
(Expr
);
2434 -- Build the precondition/postcondition pragma
2436 -- Add note about why we do NOT need Copy_Tree here ???
2439 (Pragma_Argument_Associations
=> New_List
(
2440 Make_Pragma_Argument_Association
(Eloc
,
2441 Chars
=> Name_Check
,
2442 Expression
=> Relocate_Node
(Expr
))),
2443 Pragma_Name
=> Pname
);
2445 -- Add message unless exception messages are suppressed
2447 if not Opt
.Exception_Locations_Suppressed
then
2448 Append_To
(Pragma_Argument_Associations
(Aitem
),
2449 Make_Pragma_Argument_Association
(Eloc
,
2450 Chars
=> Name_Message
,
2452 Make_String_Literal
(Eloc
,
2454 & Get_Name_String
(Pname
)
2456 & Build_Location_String
(Eloc
))));
2459 Set_Is_Delayed_Aspect
(Aspect
);
2461 -- For Pre/Post cases, insert immediately after the entity
2462 -- declaration, since that is the required pragma placement.
2463 -- Note that for these aspects, we do not have to worry
2464 -- about delay issues, since the pragmas themselves deal
2465 -- with delay of visibility for the expression analysis.
2467 Insert_Delayed_Pragma
(Aitem
);
2473 when Aspect_Test_Case
=> Test_Case
: declare
2475 Comp_Expr
: Node_Id
;
2476 Comp_Assn
: Node_Id
;
2482 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
2483 Error_Msg_Name_1
:= Nam
;
2484 Error_Msg_N
("incorrect placement of aspect `%`", E
);
2488 if Nkind
(Expr
) /= N_Aggregate
then
2489 Error_Msg_Name_1
:= Nam
;
2491 ("wrong syntax for aspect `%` for &", Id
, E
);
2495 -- Make pragma expressions refer to the original aspect
2496 -- expressions through the Original_Node link. This is
2497 -- used in semantic analysis for ASIS mode, so that the
2498 -- original expression also gets analyzed.
2500 Comp_Expr
:= First
(Expressions
(Expr
));
2501 while Present
(Comp_Expr
) loop
2502 New_Expr
:= Relocate_Node
(Comp_Expr
);
2503 Set_Original_Node
(New_Expr
, Comp_Expr
);
2505 Make_Pragma_Argument_Association
(Sloc
(Comp_Expr
),
2506 Expression
=> New_Expr
));
2510 Comp_Assn
:= First
(Component_Associations
(Expr
));
2511 while Present
(Comp_Assn
) loop
2512 if List_Length
(Choices
(Comp_Assn
)) /= 1
2514 Nkind
(First
(Choices
(Comp_Assn
))) /= N_Identifier
2516 Error_Msg_Name_1
:= Nam
;
2518 ("wrong syntax for aspect `%` for &", Id
, E
);
2522 New_Expr
:= Relocate_Node
(Expression
(Comp_Assn
));
2523 Set_Original_Node
(New_Expr
, Expression
(Comp_Assn
));
2525 Make_Pragma_Argument_Association
(Sloc
(Comp_Assn
),
2526 Chars
=> Chars
(First
(Choices
(Comp_Assn
))),
2527 Expression
=> New_Expr
));
2531 -- Build the test-case pragma
2534 (Pragma_Argument_Associations
=> Args
,
2535 Pragma_Name
=> Nam
);
2540 when Aspect_Contract_Cases
=>
2542 (Pragma_Argument_Associations
=> New_List
(
2543 Make_Pragma_Argument_Association
(Loc
,
2544 Expression
=> Relocate_Node
(Expr
))),
2545 Pragma_Name
=> Nam
);
2547 Decorate_Aspect_And_Pragma
2548 (Aspect
, Aitem
, Delayed
=> True);
2549 Insert_Delayed_Pragma
(Aitem
);
2552 -- Case 5: Special handling for aspects with an optional
2553 -- boolean argument.
2555 -- In the general case, the corresponding pragma cannot be
2556 -- generated yet because the evaluation of the boolean needs
2557 -- to be delayed till the freeze point.
2559 when Boolean_Aspects |
2560 Library_Unit_Aspects
=>
2562 Set_Is_Boolean_Aspect
(Aspect
);
2564 -- Lock_Free aspect only apply to protected objects
2566 if A_Id
= Aspect_Lock_Free
then
2567 if Ekind
(E
) /= E_Protected_Type
then
2568 Error_Msg_Name_1
:= Nam
;
2570 ("aspect % only applies to a protected object",
2574 -- Set the Uses_Lock_Free flag to True if there is no
2575 -- expression or if the expression is True. The
2576 -- evaluation of this aspect should be delayed to the
2577 -- freeze point (why???)
2580 or else Is_True
(Static_Boolean
(Expr
))
2582 Set_Uses_Lock_Free
(E
);
2585 Record_Rep_Item
(E
, Aspect
);
2590 elsif A_Id
= Aspect_Import
or else A_Id
= Aspect_Export
then
2592 -- Verify that there is an aspect Convention that will
2593 -- incorporate the Import/Export aspect, and eventual
2594 -- Link/External names.
2601 while Present
(A
) loop
2602 exit when Chars
(Identifier
(A
)) = Name_Convention
;
2606 -- It is legal to specify Import for a variable, in
2607 -- order to suppress initialization for it, without
2608 -- specifying explicitly its convention. However this
2609 -- is only legal if the convention of the object type
2610 -- is Ada or similar.
2613 if Ekind
(E
) = E_Variable
2614 and then A_Id
= Aspect_Import
2617 C
: constant Convention_Id
:=
2618 Convention
(Etype
(E
));
2620 if C
= Convention_Ada
or else
2621 C
= Convention_Ada_Pass_By_Copy
or else
2622 C
= Convention_Ada_Pass_By_Reference
2629 -- Otherwise, Convention must be specified
2632 ("missing Convention aspect for Export/Import",
2640 -- Library unit aspects require special handling in the case
2641 -- of a package declaration, the pragma needs to be inserted
2642 -- in the list of declarations for the associated package.
2643 -- There is no issue of visibility delay for these aspects.
2645 if A_Id
in Library_Unit_Aspects
2647 Nkind_In
(N
, N_Package_Declaration
,
2648 N_Generic_Package_Declaration
)
2649 and then Nkind
(Parent
(N
)) /= N_Compilation_Unit
2652 ("incorrect context for library unit aspect&", Id
);
2656 -- Cases where we do not delay, includes all cases where
2657 -- the expression is missing other than the above cases.
2659 if not Delay_Required
or else No
(Expr
) then
2661 (Pragma_Argument_Associations
=> New_List
(
2662 Make_Pragma_Argument_Association
(Sloc
(Ent
),
2663 Expression
=> Ent
)),
2664 Pragma_Name
=> Chars
(Id
));
2665 Delay_Required
:= False;
2667 -- In general cases, the corresponding pragma/attribute
2668 -- definition clause will be inserted later at the freezing
2669 -- point, and we do not need to build it now
2677 -- This is special because for access types we need to generate
2678 -- an attribute definition clause. This also works for single
2679 -- task declarations, but it does not work for task type
2680 -- declarations, because we have the case where the expression
2681 -- references a discriminant of the task type. That can't use
2682 -- an attribute definition clause because we would not have
2683 -- visibility on the discriminant. For that case we must
2684 -- generate a pragma in the task definition.
2686 when Aspect_Storage_Size
=>
2690 if Ekind
(E
) = E_Task_Type
then
2692 Decl
: constant Node_Id
:= Declaration_Node
(E
);
2695 pragma Assert
(Nkind
(Decl
) = N_Task_Type_Declaration
);
2697 -- If no task definition, create one
2699 if No
(Task_Definition
(Decl
)) then
2700 Set_Task_Definition
(Decl
,
2701 Make_Task_Definition
(Loc
,
2702 Visible_Declarations
=> Empty_List
,
2703 End_Label
=> Empty
));
2706 -- Create a pragma and put it at the start of the
2707 -- task definition for the task type declaration.
2710 (Pragma_Argument_Associations
=> New_List
(
2711 Make_Pragma_Argument_Association
(Loc
,
2712 Expression
=> Relocate_Node
(Expr
))),
2713 Pragma_Name
=> Name_Storage_Size
);
2717 Visible_Declarations
(Task_Definition
(Decl
)));
2721 -- All other cases, generate attribute definition
2725 Make_Attribute_Definition_Clause
(Loc
,
2727 Chars
=> Chars
(Id
),
2728 Expression
=> Relocate_Node
(Expr
));
2732 -- Attach the corresponding pragma/attribute definition clause to
2733 -- the aspect specification node.
2735 if Present
(Aitem
) then
2736 Set_From_Aspect_Specification
(Aitem
, True);
2739 -- In the context of a compilation unit, we directly put the
2740 -- pragma in the Pragmas_After list of the N_Compilation_Unit_Aux
2741 -- node (no delay is required here) except for aspects on a
2742 -- subprogram body (see below) and a generic package, for which
2743 -- we need to introduce the pragma before building the generic
2744 -- copy (see sem_ch12), and for package instantiations, where
2745 -- the library unit pragmas are better handled early.
2747 if Nkind
(Parent
(N
)) = N_Compilation_Unit
2748 and then (Present
(Aitem
) or else Is_Boolean_Aspect
(Aspect
))
2751 Aux
: constant Node_Id
:= Aux_Decls_Node
(Parent
(N
));
2754 pragma Assert
(Nkind
(Aux
) = N_Compilation_Unit_Aux
);
2756 -- For a Boolean aspect, create the corresponding pragma if
2757 -- no expression or if the value is True.
2759 if Is_Boolean_Aspect
(Aspect
) and then No
(Aitem
) then
2760 if Is_True
(Static_Boolean
(Expr
)) then
2762 (Pragma_Argument_Associations
=> New_List
(
2763 Make_Pragma_Argument_Association
(Sloc
(Ent
),
2764 Expression
=> Ent
)),
2765 Pragma_Name
=> Chars
(Id
));
2767 Set_From_Aspect_Specification
(Aitem
, True);
2768 Set_Corresponding_Aspect
(Aitem
, Aspect
);
2775 -- If the aspect is on a subprogram body (relevant aspect
2776 -- is Inline), add the pragma in front of the declarations.
2778 if Nkind
(N
) = N_Subprogram_Body
then
2779 if No
(Declarations
(N
)) then
2780 Set_Declarations
(N
, New_List
);
2783 Prepend
(Aitem
, Declarations
(N
));
2785 elsif Nkind
(N
) = N_Generic_Package_Declaration
then
2786 if No
(Visible_Declarations
(Specification
(N
))) then
2787 Set_Visible_Declarations
(Specification
(N
), New_List
);
2791 Visible_Declarations
(Specification
(N
)));
2793 elsif Nkind
(N
) = N_Package_Instantiation
then
2795 Spec
: constant Node_Id
:=
2796 Specification
(Instance_Spec
(N
));
2798 if No
(Visible_Declarations
(Spec
)) then
2799 Set_Visible_Declarations
(Spec
, New_List
);
2802 Prepend
(Aitem
, Visible_Declarations
(Spec
));
2806 if No
(Pragmas_After
(Aux
)) then
2807 Set_Pragmas_After
(Aux
, New_List
);
2810 Append
(Aitem
, Pragmas_After
(Aux
));
2817 -- The evaluation of the aspect is delayed to the freezing point.
2818 -- The pragma or attribute clause if there is one is then attached
2819 -- to the aspect specification which is put in the rep item list.
2821 if Delay_Required
then
2822 if Present
(Aitem
) then
2823 Set_Is_Delayed_Aspect
(Aitem
);
2824 Set_Aspect_Rep_Item
(Aspect
, Aitem
);
2825 Set_Parent
(Aitem
, Aspect
);
2828 Set_Is_Delayed_Aspect
(Aspect
);
2830 -- In the case of Default_Value, link the aspect to base type
2831 -- as well, even though it appears on a first subtype. This is
2832 -- mandated by the semantics of the aspect. Do not establish
2833 -- the link when processing the base type itself as this leads
2834 -- to a rep item circularity. Verify that we are dealing with
2835 -- a scalar type to prevent cascaded errors.
2837 if A_Id
= Aspect_Default_Value
2838 and then Is_Scalar_Type
(E
)
2839 and then Base_Type
(E
) /= E
2841 Set_Has_Delayed_Aspects
(Base_Type
(E
));
2842 Record_Rep_Item
(Base_Type
(E
), Aspect
);
2845 Set_Has_Delayed_Aspects
(E
);
2846 Record_Rep_Item
(E
, Aspect
);
2848 -- When delay is not required and the context is a package or a
2849 -- subprogram body, insert the pragma in the body declarations.
2851 elsif Nkind_In
(N
, N_Package_Body
, N_Subprogram_Body
) then
2852 if No
(Declarations
(N
)) then
2853 Set_Declarations
(N
, New_List
);
2856 -- The pragma is added before source declarations
2858 Prepend_To
(Declarations
(N
), Aitem
);
2860 -- When delay is not required and the context is not a compilation
2861 -- unit, we simply insert the pragma/attribute definition clause
2865 Insert_After
(Ins_Node
, Aitem
);
2868 end Analyze_One_Aspect
;
2872 end loop Aspect_Loop
;
2874 if Has_Delayed_Aspects
(E
) then
2875 Ensure_Freeze_Node
(E
);
2877 end Analyze_Aspect_Specifications
;
2879 -----------------------
2880 -- Analyze_At_Clause --
2881 -----------------------
2883 -- An at clause is replaced by the corresponding Address attribute
2884 -- definition clause that is the preferred approach in Ada 95.
2886 procedure Analyze_At_Clause
(N
: Node_Id
) is
2887 CS
: constant Boolean := Comes_From_Source
(N
);
2890 -- This is an obsolescent feature
2892 Check_Restriction
(No_Obsolescent_Features
, N
);
2894 if Warn_On_Obsolescent_Feature
then
2896 ("?j?at clause is an obsolescent feature (RM J.7(2))", N
);
2898 ("\?j?use address attribute definition clause instead", N
);
2901 -- Rewrite as address clause
2904 Make_Attribute_Definition_Clause
(Sloc
(N
),
2905 Name
=> Identifier
(N
),
2906 Chars
=> Name_Address
,
2907 Expression
=> Expression
(N
)));
2909 -- We preserve Comes_From_Source, since logically the clause still comes
2910 -- from the source program even though it is changed in form.
2912 Set_Comes_From_Source
(N
, CS
);
2914 -- Analyze rewritten clause
2916 Analyze_Attribute_Definition_Clause
(N
);
2917 end Analyze_At_Clause
;
2919 -----------------------------------------
2920 -- Analyze_Attribute_Definition_Clause --
2921 -----------------------------------------
2923 procedure Analyze_Attribute_Definition_Clause
(N
: Node_Id
) is
2924 Loc
: constant Source_Ptr
:= Sloc
(N
);
2925 Nam
: constant Node_Id
:= Name
(N
);
2926 Attr
: constant Name_Id
:= Chars
(N
);
2927 Expr
: constant Node_Id
:= Expression
(N
);
2928 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Attr
);
2931 -- The entity of Nam after it is analyzed. In the case of an incomplete
2932 -- type, this is the underlying type.
2935 -- The underlying entity to which the attribute applies. Generally this
2936 -- is the Underlying_Type of Ent, except in the case where the clause
2937 -- applies to full view of incomplete type or private type in which case
2938 -- U_Ent is just a copy of Ent.
2940 FOnly
: Boolean := False;
2941 -- Reset to True for subtype specific attribute (Alignment, Size)
2942 -- and for stream attributes, i.e. those cases where in the call
2943 -- to Rep_Item_Too_Late, FOnly is set True so that only the freezing
2944 -- rules are checked. Note that the case of stream attributes is not
2945 -- clear from the RM, but see AI95-00137. Also, the RM seems to
2946 -- disallow Storage_Size for derived task types, but that is also
2947 -- clearly unintentional.
2949 procedure Analyze_Stream_TSS_Definition
(TSS_Nam
: TSS_Name_Type
);
2950 -- Common processing for 'Read, 'Write, 'Input and 'Output attribute
2951 -- definition clauses.
2953 function Duplicate_Clause
return Boolean;
2954 -- This routine checks if the aspect for U_Ent being given by attribute
2955 -- definition clause N is for an aspect that has already been specified,
2956 -- and if so gives an error message. If there is a duplicate, True is
2957 -- returned, otherwise if there is no error, False is returned.
2959 procedure Check_Indexing_Functions
;
2960 -- Check that the function in Constant_Indexing or Variable_Indexing
2961 -- attribute has the proper type structure. If the name is overloaded,
2962 -- check that some interpretation is legal.
2964 procedure Check_Iterator_Functions
;
2965 -- Check that there is a single function in Default_Iterator attribute
2966 -- has the proper type structure.
2968 function Check_Primitive_Function
(Subp
: Entity_Id
) return Boolean;
2969 -- Common legality check for the previous two
2971 -----------------------------------
2972 -- Analyze_Stream_TSS_Definition --
2973 -----------------------------------
2975 procedure Analyze_Stream_TSS_Definition
(TSS_Nam
: TSS_Name_Type
) is
2976 Subp
: Entity_Id
:= Empty
;
2981 Is_Read
: constant Boolean := (TSS_Nam
= TSS_Stream_Read
);
2982 -- True for Read attribute, false for other attributes
2984 function Has_Good_Profile
(Subp
: Entity_Id
) return Boolean;
2985 -- Return true if the entity is a subprogram with an appropriate
2986 -- profile for the attribute being defined.
2988 ----------------------
2989 -- Has_Good_Profile --
2990 ----------------------
2992 function Has_Good_Profile
(Subp
: Entity_Id
) return Boolean is
2994 Is_Function
: constant Boolean := (TSS_Nam
= TSS_Stream_Input
);
2995 Expected_Ekind
: constant array (Boolean) of Entity_Kind
:=
2996 (False => E_Procedure
, True => E_Function
);
3000 if Ekind
(Subp
) /= Expected_Ekind
(Is_Function
) then
3004 F
:= First_Formal
(Subp
);
3007 or else Ekind
(Etype
(F
)) /= E_Anonymous_Access_Type
3008 or else Designated_Type
(Etype
(F
)) /=
3009 Class_Wide_Type
(RTE
(RE_Root_Stream_Type
))
3014 if not Is_Function
then
3018 Expected_Mode
: constant array (Boolean) of Entity_Kind
:=
3019 (False => E_In_Parameter
,
3020 True => E_Out_Parameter
);
3022 if Parameter_Mode
(F
) /= Expected_Mode
(Is_Read
) then
3030 Typ
:= Etype
(Subp
);
3033 return Base_Type
(Typ
) = Base_Type
(Ent
)
3034 and then No
(Next_Formal
(F
));
3035 end Has_Good_Profile
;
3037 -- Start of processing for Analyze_Stream_TSS_Definition
3042 if not Is_Type
(U_Ent
) then
3043 Error_Msg_N
("local name must be a subtype", Nam
);
3047 Pnam
:= TSS
(Base_Type
(U_Ent
), TSS_Nam
);
3049 -- If Pnam is present, it can be either inherited from an ancestor
3050 -- type (in which case it is legal to redefine it for this type), or
3051 -- be a previous definition of the attribute for the same type (in
3052 -- which case it is illegal).
3054 -- In the first case, it will have been analyzed already, and we
3055 -- can check that its profile does not match the expected profile
3056 -- for a stream attribute of U_Ent. In the second case, either Pnam
3057 -- has been analyzed (and has the expected profile), or it has not
3058 -- been analyzed yet (case of a type that has not been frozen yet
3059 -- and for which the stream attribute has been set using Set_TSS).
3062 and then (No
(First_Entity
(Pnam
)) or else Has_Good_Profile
(Pnam
))
3064 Error_Msg_Sloc
:= Sloc
(Pnam
);
3065 Error_Msg_Name_1
:= Attr
;
3066 Error_Msg_N
("% attribute already defined #", Nam
);
3072 if Is_Entity_Name
(Expr
) then
3073 if not Is_Overloaded
(Expr
) then
3074 if Has_Good_Profile
(Entity
(Expr
)) then
3075 Subp
:= Entity
(Expr
);
3079 Get_First_Interp
(Expr
, I
, It
);
3080 while Present
(It
.Nam
) loop
3081 if Has_Good_Profile
(It
.Nam
) then
3086 Get_Next_Interp
(I
, It
);
3091 if Present
(Subp
) then
3092 if Is_Abstract_Subprogram
(Subp
) then
3093 Error_Msg_N
("stream subprogram must not be abstract", Expr
);
3097 Set_Entity
(Expr
, Subp
);
3098 Set_Etype
(Expr
, Etype
(Subp
));
3100 New_Stream_Subprogram
(N
, U_Ent
, Subp
, TSS_Nam
);
3103 Error_Msg_Name_1
:= Attr
;
3104 Error_Msg_N
("incorrect expression for% attribute", Expr
);
3106 end Analyze_Stream_TSS_Definition
;
3108 ------------------------------
3109 -- Check_Indexing_Functions --
3110 ------------------------------
3112 procedure Check_Indexing_Functions
is
3113 Indexing_Found
: Boolean;
3115 procedure Check_One_Function
(Subp
: Entity_Id
);
3116 -- Check one possible interpretation. Sets Indexing_Found True if an
3117 -- indexing function is found.
3119 ------------------------
3120 -- Check_One_Function --
3121 ------------------------
3123 procedure Check_One_Function
(Subp
: Entity_Id
) is
3124 Default_Element
: constant Node_Id
:=
3125 Find_Value_Of_Aspect
3126 (Etype
(First_Formal
(Subp
)),
3127 Aspect_Iterator_Element
);
3130 if not Check_Primitive_Function
(Subp
)
3131 and then not Is_Overloaded
(Expr
)
3134 ("aspect Indexing requires a function that applies to type&",
3138 -- An indexing function must return either the default element of
3139 -- the container, or a reference type. For variable indexing it
3140 -- must be the latter.
3142 if Present
(Default_Element
) then
3143 Analyze
(Default_Element
);
3145 if Is_Entity_Name
(Default_Element
)
3146 and then Covers
(Entity
(Default_Element
), Etype
(Subp
))
3148 Indexing_Found
:= True;
3153 -- For variable_indexing the return type must be a reference type
3155 if Attr
= Name_Variable_Indexing
3156 and then not Has_Implicit_Dereference
(Etype
(Subp
))
3159 ("function for indexing must return a reference type", Subp
);
3162 Indexing_Found
:= True;
3164 end Check_One_Function
;
3166 -- Start of processing for Check_Indexing_Functions
3175 if not Is_Overloaded
(Expr
) then
3176 Check_One_Function
(Entity
(Expr
));
3184 Indexing_Found
:= False;
3185 Get_First_Interp
(Expr
, I
, It
);
3186 while Present
(It
.Nam
) loop
3188 -- Note that analysis will have added the interpretation
3189 -- that corresponds to the dereference. We only check the
3190 -- subprogram itself.
3192 if Is_Overloadable
(It
.Nam
) then
3193 Check_One_Function
(It
.Nam
);
3196 Get_Next_Interp
(I
, It
);
3199 if not Indexing_Found
then
3201 ("aspect Indexing requires a function that "
3202 & "applies to type&", Expr
, Ent
);
3206 end Check_Indexing_Functions
;
3208 ------------------------------
3209 -- Check_Iterator_Functions --
3210 ------------------------------
3212 procedure Check_Iterator_Functions
is
3213 Default
: Entity_Id
;
3215 function Valid_Default_Iterator
(Subp
: Entity_Id
) return Boolean;
3216 -- Check one possible interpretation for validity
3218 ----------------------------
3219 -- Valid_Default_Iterator --
3220 ----------------------------
3222 function Valid_Default_Iterator
(Subp
: Entity_Id
) return Boolean is
3226 if not Check_Primitive_Function
(Subp
) then
3229 Formal
:= First_Formal
(Subp
);
3232 -- False if any subsequent formal has no default expression
3234 Formal
:= Next_Formal
(Formal
);
3235 while Present
(Formal
) loop
3236 if No
(Expression
(Parent
(Formal
))) then
3240 Next_Formal
(Formal
);
3243 -- True if all subsequent formals have default expressions
3246 end Valid_Default_Iterator
;
3248 -- Start of processing for Check_Iterator_Functions
3253 if not Is_Entity_Name
(Expr
) then
3254 Error_Msg_N
("aspect Iterator must be a function name", Expr
);
3257 if not Is_Overloaded
(Expr
) then
3258 if not Check_Primitive_Function
(Entity
(Expr
)) then
3260 ("aspect Indexing requires a function that applies to type&",
3261 Entity
(Expr
), Ent
);
3264 if not Valid_Default_Iterator
(Entity
(Expr
)) then
3265 Error_Msg_N
("improper function for default iterator", Expr
);
3275 Get_First_Interp
(Expr
, I
, It
);
3276 while Present
(It
.Nam
) loop
3277 if not Check_Primitive_Function
(It
.Nam
)
3278 or else not Valid_Default_Iterator
(It
.Nam
)
3282 elsif Present
(Default
) then
3283 Error_Msg_N
("default iterator must be unique", Expr
);
3289 Get_Next_Interp
(I
, It
);
3293 if Present
(Default
) then
3294 Set_Entity
(Expr
, Default
);
3295 Set_Is_Overloaded
(Expr
, False);
3298 end Check_Iterator_Functions
;
3300 -------------------------------
3301 -- Check_Primitive_Function --
3302 -------------------------------
3304 function Check_Primitive_Function
(Subp
: Entity_Id
) return Boolean is
3308 if Ekind
(Subp
) /= E_Function
then
3312 if No
(First_Formal
(Subp
)) then
3315 Ctrl
:= Etype
(First_Formal
(Subp
));
3319 or else Ctrl
= Class_Wide_Type
(Ent
)
3321 (Ekind
(Ctrl
) = E_Anonymous_Access_Type
3323 (Designated_Type
(Ctrl
) = Ent
3324 or else Designated_Type
(Ctrl
) = Class_Wide_Type
(Ent
)))
3333 end Check_Primitive_Function
;
3335 ----------------------
3336 -- Duplicate_Clause --
3337 ----------------------
3339 function Duplicate_Clause
return Boolean is
3343 -- Nothing to do if this attribute definition clause comes from
3344 -- an aspect specification, since we could not be duplicating an
3345 -- explicit clause, and we dealt with the case of duplicated aspects
3346 -- in Analyze_Aspect_Specifications.
3348 if From_Aspect_Specification
(N
) then
3352 -- Otherwise current clause may duplicate previous clause, or a
3353 -- previously given pragma or aspect specification for the same
3356 A
:= Get_Rep_Item
(U_Ent
, Chars
(N
), Check_Parents
=> False);
3359 Error_Msg_Name_1
:= Chars
(N
);
3360 Error_Msg_Sloc
:= Sloc
(A
);
3362 Error_Msg_NE
("aspect% for & previously given#", N
, U_Ent
);
3367 end Duplicate_Clause
;
3369 -- Start of processing for Analyze_Attribute_Definition_Clause
3372 -- The following code is a defense against recursion. Not clear that
3373 -- this can happen legitimately, but perhaps some error situations
3374 -- can cause it, and we did see this recursion during testing.
3376 if Analyzed
(N
) then
3379 Set_Analyzed
(N
, True);
3382 -- Ignore some selected attributes in CodePeer mode since they are not
3383 -- relevant in this context.
3385 if CodePeer_Mode
then
3388 -- Ignore Component_Size in CodePeer mode, to avoid changing the
3389 -- internal representation of types by implicitly packing them.
3391 when Attribute_Component_Size
=>
3392 Rewrite
(N
, Make_Null_Statement
(Sloc
(N
)));
3400 -- Process Ignore_Rep_Clauses option
3402 if Ignore_Rep_Clauses
then
3405 -- The following should be ignored. They do not affect legality
3406 -- and may be target dependent. The basic idea of -gnatI is to
3407 -- ignore any rep clauses that may be target dependent but do not
3408 -- affect legality (except possibly to be rejected because they
3409 -- are incompatible with the compilation target).
3411 when Attribute_Alignment |
3412 Attribute_Bit_Order |
3413 Attribute_Component_Size |
3414 Attribute_Machine_Radix |
3415 Attribute_Object_Size |
3417 Attribute_Stream_Size |
3418 Attribute_Value_Size
=>
3419 Rewrite
(N
, Make_Null_Statement
(Sloc
(N
)));
3422 -- Perhaps 'Small should not be ignored by Ignore_Rep_Clauses ???
3424 when Attribute_Small
=>
3425 if Ignore_Rep_Clauses
then
3426 Rewrite
(N
, Make_Null_Statement
(Sloc
(N
)));
3430 -- The following should not be ignored, because in the first place
3431 -- they are reasonably portable, and should not cause problems in
3432 -- compiling code from another target, and also they do affect
3433 -- legality, e.g. failing to provide a stream attribute for a
3434 -- type may make a program illegal.
3436 when Attribute_External_Tag |
3440 Attribute_Simple_Storage_Pool |
3441 Attribute_Storage_Pool |
3442 Attribute_Storage_Size |
3446 -- Other cases are errors ("attribute& cannot be set with
3447 -- definition clause"), which will be caught below.
3455 Ent
:= Entity
(Nam
);
3457 if Rep_Item_Too_Early
(Ent
, N
) then
3461 -- Rep clause applies to full view of incomplete type or private type if
3462 -- we have one (if not, this is a premature use of the type). However,
3463 -- certain semantic checks need to be done on the specified entity (i.e.
3464 -- the private view), so we save it in Ent.
3466 if Is_Private_Type
(Ent
)
3467 and then Is_Derived_Type
(Ent
)
3468 and then not Is_Tagged_Type
(Ent
)
3469 and then No
(Full_View
(Ent
))
3471 -- If this is a private type whose completion is a derivation from
3472 -- another private type, there is no full view, and the attribute
3473 -- belongs to the type itself, not its underlying parent.
3477 elsif Ekind
(Ent
) = E_Incomplete_Type
then
3479 -- The attribute applies to the full view, set the entity of the
3480 -- attribute definition accordingly.
3482 Ent
:= Underlying_Type
(Ent
);
3484 Set_Entity
(Nam
, Ent
);
3487 U_Ent
:= Underlying_Type
(Ent
);
3490 -- Avoid cascaded error
3492 if Etype
(Nam
) = Any_Type
then
3495 -- Must be declared in current scope or in case of an aspect
3496 -- specification, must be visible in current scope.
3498 elsif Scope
(Ent
) /= Current_Scope
3500 not (From_Aspect_Specification
(N
)
3501 and then Scope_Within_Or_Same
(Current_Scope
, Scope
(Ent
)))
3503 Error_Msg_N
("entity must be declared in this scope", Nam
);
3506 -- Must not be a source renaming (we do have some cases where the
3507 -- expander generates a renaming, and those cases are OK, in such
3508 -- cases any attribute applies to the renamed object as well).
3510 elsif Is_Object
(Ent
)
3511 and then Present
(Renamed_Object
(Ent
))
3513 -- Case of renamed object from source, this is an error
3515 if Comes_From_Source
(Renamed_Object
(Ent
)) then
3516 Get_Name_String
(Chars
(N
));
3517 Error_Msg_Strlen
:= Name_Len
;
3518 Error_Msg_String
(1 .. Name_Len
) := Name_Buffer
(1 .. Name_Len
);
3520 ("~ clause not allowed for a renaming declaration "
3521 & "(RM 13.1(6))", Nam
);
3524 -- For the case of a compiler generated renaming, the attribute
3525 -- definition clause applies to the renamed object created by the
3526 -- expander. The easiest general way to handle this is to create a
3527 -- copy of the attribute definition clause for this object.
3531 Make_Attribute_Definition_Clause
(Loc
,
3533 New_Occurrence_Of
(Entity
(Renamed_Object
(Ent
)), Loc
),
3535 Expression
=> Duplicate_Subexpr
(Expression
(N
))));
3538 -- If no underlying entity, use entity itself, applies to some
3539 -- previously detected error cases ???
3541 elsif No
(U_Ent
) then
3544 -- Cannot specify for a subtype (exception Object/Value_Size)
3546 elsif Is_Type
(U_Ent
)
3547 and then not Is_First_Subtype
(U_Ent
)
3548 and then Id
/= Attribute_Object_Size
3549 and then Id
/= Attribute_Value_Size
3550 and then not From_At_Mod
(N
)
3552 Error_Msg_N
("cannot specify attribute for subtype", Nam
);
3556 Set_Entity
(N
, U_Ent
);
3557 Check_Restriction_No_Use_Of_Attribute
(N
);
3559 -- Switch on particular attribute
3567 -- Address attribute definition clause
3569 when Attribute_Address
=> Address
: begin
3571 -- A little error check, catch for X'Address use X'Address;
3573 if Nkind
(Nam
) = N_Identifier
3574 and then Nkind
(Expr
) = N_Attribute_Reference
3575 and then Attribute_Name
(Expr
) = Name_Address
3576 and then Nkind
(Prefix
(Expr
)) = N_Identifier
3577 and then Chars
(Nam
) = Chars
(Prefix
(Expr
))
3580 ("address for & is self-referencing", Prefix
(Expr
), Ent
);
3584 -- Not that special case, carry on with analysis of expression
3586 Analyze_And_Resolve
(Expr
, RTE
(RE_Address
));
3588 -- Even when ignoring rep clauses we need to indicate that the
3589 -- entity has an address clause and thus it is legal to declare
3592 if Ignore_Rep_Clauses
then
3593 if Ekind_In
(U_Ent
, E_Variable
, E_Constant
) then
3594 Record_Rep_Item
(U_Ent
, N
);
3600 if Duplicate_Clause
then
3603 -- Case of address clause for subprogram
3605 elsif Is_Subprogram
(U_Ent
) then
3606 if Has_Homonym
(U_Ent
) then
3608 ("address clause cannot be given " &
3609 "for overloaded subprogram",
3614 -- For subprograms, all address clauses are permitted, and we
3615 -- mark the subprogram as having a deferred freeze so that Gigi
3616 -- will not elaborate it too soon.
3618 -- Above needs more comments, what is too soon about???
3620 Set_Has_Delayed_Freeze
(U_Ent
);
3622 -- Case of address clause for entry
3624 elsif Ekind
(U_Ent
) = E_Entry
then
3625 if Nkind
(Parent
(N
)) = N_Task_Body
then
3627 ("entry address must be specified in task spec", Nam
);
3631 -- For entries, we require a constant address
3633 Check_Constant_Address_Clause
(Expr
, U_Ent
);
3635 -- Special checks for task types
3637 if Is_Task_Type
(Scope
(U_Ent
))
3638 and then Comes_From_Source
(Scope
(U_Ent
))
3641 ("??entry address declared for entry in task type", N
);
3643 ("\??only one task can be declared of this type", N
);
3646 -- Entry address clauses are obsolescent
3648 Check_Restriction
(No_Obsolescent_Features
, N
);
3650 if Warn_On_Obsolescent_Feature
then
3652 ("?j?attaching interrupt to task entry is an " &
3653 "obsolescent feature (RM J.7.1)", N
);
3655 ("\?j?use interrupt procedure instead", N
);
3658 -- Case of an address clause for a controlled object which we
3659 -- consider to be erroneous.
3661 elsif Is_Controlled
(Etype
(U_Ent
))
3662 or else Has_Controlled_Component
(Etype
(U_Ent
))
3665 ("??controlled object& must not be overlaid", Nam
, U_Ent
);
3667 ("\??Program_Error will be raised at run time", Nam
);
3668 Insert_Action
(Declaration_Node
(U_Ent
),
3669 Make_Raise_Program_Error
(Loc
,
3670 Reason
=> PE_Overlaid_Controlled_Object
));
3673 -- Case of address clause for a (non-controlled) object
3676 Ekind
(U_Ent
) = E_Variable
3678 Ekind
(U_Ent
) = E_Constant
3681 Expr
: constant Node_Id
:= Expression
(N
);
3686 -- Exported variables cannot have an address clause, because
3687 -- this cancels the effect of the pragma Export.
3689 if Is_Exported
(U_Ent
) then
3691 ("cannot export object with address clause", Nam
);
3695 Find_Overlaid_Entity
(N
, O_Ent
, Off
);
3697 -- Overlaying controlled objects is erroneous
3700 and then (Has_Controlled_Component
(Etype
(O_Ent
))
3701 or else Is_Controlled
(Etype
(O_Ent
)))
3704 ("??cannot overlay with controlled object", Expr
);
3706 ("\??Program_Error will be raised at run time", Expr
);
3707 Insert_Action
(Declaration_Node
(U_Ent
),
3708 Make_Raise_Program_Error
(Loc
,
3709 Reason
=> PE_Overlaid_Controlled_Object
));
3712 elsif Present
(O_Ent
)
3713 and then Ekind
(U_Ent
) = E_Constant
3714 and then not Is_Constant_Object
(O_Ent
)
3716 Error_Msg_N
("??constant overlays a variable", Expr
);
3718 -- Imported variables can have an address clause, but then
3719 -- the import is pretty meaningless except to suppress
3720 -- initializations, so we do not need such variables to
3721 -- be statically allocated (and in fact it causes trouble
3722 -- if the address clause is a local value).
3724 elsif Is_Imported
(U_Ent
) then
3725 Set_Is_Statically_Allocated
(U_Ent
, False);
3728 -- We mark a possible modification of a variable with an
3729 -- address clause, since it is likely aliasing is occurring.
3731 Note_Possible_Modification
(Nam
, Sure
=> False);
3733 -- Here we are checking for explicit overlap of one variable
3734 -- by another, and if we find this then mark the overlapped
3735 -- variable as also being volatile to prevent unwanted
3736 -- optimizations. This is a significant pessimization so
3737 -- avoid it when there is an offset, i.e. when the object
3738 -- is composite; they cannot be optimized easily anyway.
3741 and then Is_Object
(O_Ent
)
3744 -- The following test is an expedient solution to what
3745 -- is really a problem in CodePeer. Suppressing the
3746 -- Set_Treat_As_Volatile call here prevents later
3747 -- generation (in some cases) of trees that CodePeer
3748 -- should, but currently does not, handle correctly.
3749 -- This test should probably be removed when CodePeer
3750 -- is improved, just because we want the tree CodePeer
3751 -- analyzes to match the tree for which we generate code
3752 -- as closely as is practical. ???
3754 and then not CodePeer_Mode
3756 -- ??? O_Ent might not be in current unit
3758 Set_Treat_As_Volatile
(O_Ent
);
3761 -- Legality checks on the address clause for initialized
3762 -- objects is deferred until the freeze point, because
3763 -- a subsequent pragma might indicate that the object
3764 -- is imported and thus not initialized. Also, the address
3765 -- clause might involve entities that have yet to be
3768 Set_Has_Delayed_Freeze
(U_Ent
);
3770 -- If an initialization call has been generated for this
3771 -- object, it needs to be deferred to after the freeze node
3772 -- we have just now added, otherwise GIGI will see a
3773 -- reference to the variable (as actual to the IP call)
3774 -- before its definition.
3777 Init_Call
: constant Node_Id
:=
3778 Remove_Init_Call
(U_Ent
, N
);
3781 if Present
(Init_Call
) then
3783 -- If the init call is an expression with actions with
3784 -- null expression, just extract the actions.
3786 if Nkind
(Init_Call
) = N_Expression_With_Actions
3788 Nkind
(Expression
(Init_Call
)) = N_Null_Statement
3790 Append_Freeze_Actions
(U_Ent
, Actions
(Init_Call
));
3792 -- General case: move Init_Call to freeze actions
3795 Append_Freeze_Action
(U_Ent
, Init_Call
);
3800 if Is_Exported
(U_Ent
) then
3802 ("& cannot be exported if an address clause is given",
3805 ("\define and export a variable "
3806 & "that holds its address instead", Nam
);
3809 -- Entity has delayed freeze, so we will generate an
3810 -- alignment check at the freeze point unless suppressed.
3812 if not Range_Checks_Suppressed
(U_Ent
)
3813 and then not Alignment_Checks_Suppressed
(U_Ent
)
3815 Set_Check_Address_Alignment
(N
);
3818 -- Kill the size check code, since we are not allocating
3819 -- the variable, it is somewhere else.
3821 Kill_Size_Check_Code
(U_Ent
);
3823 -- If the address clause is of the form:
3825 -- for Y'Address use X'Address
3829 -- Const : constant Address := X'Address;
3831 -- for Y'Address use Const;
3833 -- then we make an entry in the table for checking the size
3834 -- and alignment of the overlaying variable. We defer this
3835 -- check till after code generation to take full advantage
3836 -- of the annotation done by the back end.
3838 -- If the entity has a generic type, the check will be
3839 -- performed in the instance if the actual type justifies
3840 -- it, and we do not insert the clause in the table to
3841 -- prevent spurious warnings.
3843 -- Note: we used to test Comes_From_Source and only give
3844 -- this warning for source entities, but we have removed
3845 -- this test. It really seems bogus to generate overlays
3846 -- that would trigger this warning in generated code.
3847 -- Furthermore, by removing the test, we handle the
3848 -- aspect case properly.
3850 if Address_Clause_Overlay_Warnings
3851 and then Present
(O_Ent
)
3852 and then Is_Object
(O_Ent
)
3854 if not Is_Generic_Type
(Etype
(U_Ent
)) then
3855 Address_Clause_Checks
.Append
((N
, U_Ent
, O_Ent
, Off
));
3858 -- If variable overlays a constant view, and we are
3859 -- warning on overlays, then mark the variable as
3860 -- overlaying a constant (we will give warnings later
3861 -- if this variable is assigned).
3863 if Is_Constant_Object
(O_Ent
)
3864 and then Ekind
(U_Ent
) = E_Variable
3866 Set_Overlays_Constant
(U_Ent
);
3871 -- Not a valid entity for an address clause
3874 Error_Msg_N
("address cannot be given for &", Nam
);
3882 -- Alignment attribute definition clause
3884 when Attribute_Alignment
=> Alignment
: declare
3885 Align
: constant Uint
:= Get_Alignment_Value
(Expr
);
3886 Max_Align
: constant Uint
:= UI_From_Int
(Maximum_Alignment
);
3891 if not Is_Type
(U_Ent
)
3892 and then Ekind
(U_Ent
) /= E_Variable
3893 and then Ekind
(U_Ent
) /= E_Constant
3895 Error_Msg_N
("alignment cannot be given for &", Nam
);
3897 elsif Duplicate_Clause
then
3900 elsif Align
/= No_Uint
then
3901 Set_Has_Alignment_Clause
(U_Ent
);
3903 -- Tagged type case, check for attempt to set alignment to a
3904 -- value greater than Max_Align, and reset if so.
3906 if Is_Tagged_Type
(U_Ent
) and then Align
> Max_Align
then
3908 ("alignment for & set to Maximum_Aligment??", Nam
);
3909 Set_Alignment
(U_Ent
, Max_Align
);
3914 Set_Alignment
(U_Ent
, Align
);
3917 -- For an array type, U_Ent is the first subtype. In that case,
3918 -- also set the alignment of the anonymous base type so that
3919 -- other subtypes (such as the itypes for aggregates of the
3920 -- type) also receive the expected alignment.
3922 if Is_Array_Type
(U_Ent
) then
3923 Set_Alignment
(Base_Type
(U_Ent
), Align
);
3932 -- Bit_Order attribute definition clause
3934 when Attribute_Bit_Order
=> Bit_Order
: declare
3936 if not Is_Record_Type
(U_Ent
) then
3938 ("Bit_Order can only be defined for record type", Nam
);
3940 elsif Duplicate_Clause
then
3944 Analyze_And_Resolve
(Expr
, RTE
(RE_Bit_Order
));
3946 if Etype
(Expr
) = Any_Type
then
3949 elsif not Is_Static_Expression
(Expr
) then
3950 Flag_Non_Static_Expr
3951 ("Bit_Order requires static expression!", Expr
);
3954 if (Expr_Value
(Expr
) = 0) /= Bytes_Big_Endian
then
3955 Set_Reverse_Bit_Order
(U_Ent
, True);
3961 --------------------
3962 -- Component_Size --
3963 --------------------
3965 -- Component_Size attribute definition clause
3967 when Attribute_Component_Size
=> Component_Size_Case
: declare
3968 Csize
: constant Uint
:= Static_Integer
(Expr
);
3972 New_Ctyp
: Entity_Id
;
3976 if not Is_Array_Type
(U_Ent
) then
3977 Error_Msg_N
("component size requires array type", Nam
);
3981 Btype
:= Base_Type
(U_Ent
);
3982 Ctyp
:= Component_Type
(Btype
);
3984 if Duplicate_Clause
then
3987 elsif Rep_Item_Too_Early
(Btype
, N
) then
3990 elsif Csize
/= No_Uint
then
3991 Check_Size
(Expr
, Ctyp
, Csize
, Biased
);
3993 -- For the biased case, build a declaration for a subtype that
3994 -- will be used to represent the biased subtype that reflects
3995 -- the biased representation of components. We need the subtype
3996 -- to get proper conversions on referencing elements of the
3997 -- array. Note: component size clauses are ignored in VM mode.
3999 if VM_Target
= No_VM
then
4002 Make_Defining_Identifier
(Loc
,
4004 New_External_Name
(Chars
(U_Ent
), 'C', 0, 'T'));
4007 Make_Subtype_Declaration
(Loc
,
4008 Defining_Identifier
=> New_Ctyp
,
4009 Subtype_Indication
=>
4010 New_Occurrence_Of
(Component_Type
(Btype
), Loc
));
4012 Set_Parent
(Decl
, N
);
4013 Analyze
(Decl
, Suppress
=> All_Checks
);
4015 Set_Has_Delayed_Freeze
(New_Ctyp
, False);
4016 Set_Esize
(New_Ctyp
, Csize
);
4017 Set_RM_Size
(New_Ctyp
, Csize
);
4018 Init_Alignment
(New_Ctyp
);
4019 Set_Is_Itype
(New_Ctyp
, True);
4020 Set_Associated_Node_For_Itype
(New_Ctyp
, U_Ent
);
4022 Set_Component_Type
(Btype
, New_Ctyp
);
4023 Set_Biased
(New_Ctyp
, N
, "component size clause");
4026 Set_Component_Size
(Btype
, Csize
);
4028 -- For VM case, we ignore component size clauses
4031 -- Give a warning unless we are in GNAT mode, in which case
4032 -- the warning is suppressed since it is not useful.
4034 if not GNAT_Mode
then
4036 ("component size ignored in this configuration??", N
);
4040 -- Deal with warning on overridden size
4042 if Warn_On_Overridden_Size
4043 and then Has_Size_Clause
(Ctyp
)
4044 and then RM_Size
(Ctyp
) /= Csize
4047 ("component size overrides size clause for&?S?", N
, Ctyp
);
4050 Set_Has_Component_Size_Clause
(Btype
, True);
4051 Set_Has_Non_Standard_Rep
(Btype
, True);
4053 end Component_Size_Case
;
4055 -----------------------
4056 -- Constant_Indexing --
4057 -----------------------
4059 when Attribute_Constant_Indexing
=>
4060 Check_Indexing_Functions
;
4066 when Attribute_CPU
=> CPU
:
4068 -- CPU attribute definition clause not allowed except from aspect
4071 if From_Aspect_Specification
(N
) then
4072 if not Is_Task_Type
(U_Ent
) then
4073 Error_Msg_N
("CPU can only be defined for task", Nam
);
4075 elsif Duplicate_Clause
then
4079 -- The expression must be analyzed in the special manner
4080 -- described in "Handling of Default and Per-Object
4081 -- Expressions" in sem.ads.
4083 -- The visibility to the discriminants must be restored
4085 Push_Scope_And_Install_Discriminants
(U_Ent
);
4086 Preanalyze_Spec_Expression
(Expr
, RTE
(RE_CPU_Range
));
4087 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
4089 if not Is_Static_Expression
(Expr
) then
4090 Check_Restriction
(Static_Priorities
, Expr
);
4096 ("attribute& cannot be set with definition clause", N
);
4100 ----------------------
4101 -- Default_Iterator --
4102 ----------------------
4104 when Attribute_Default_Iterator
=> Default_Iterator
: declare
4108 if not Is_Tagged_Type
(U_Ent
) then
4110 ("aspect Default_Iterator applies to tagged type", Nam
);
4113 Check_Iterator_Functions
;
4117 if not Is_Entity_Name
(Expr
)
4118 or else Ekind
(Entity
(Expr
)) /= E_Function
4120 Error_Msg_N
("aspect Iterator must be a function", Expr
);
4122 Func
:= Entity
(Expr
);
4125 if No
(First_Formal
(Func
))
4126 or else Etype
(First_Formal
(Func
)) /= U_Ent
4129 ("Default Iterator must be a primitive of&", Func
, U_Ent
);
4131 end Default_Iterator
;
4133 ------------------------
4134 -- Dispatching_Domain --
4135 ------------------------
4137 when Attribute_Dispatching_Domain
=> Dispatching_Domain
:
4139 -- Dispatching_Domain attribute definition clause not allowed
4140 -- except from aspect specification.
4142 if From_Aspect_Specification
(N
) then
4143 if not Is_Task_Type
(U_Ent
) then
4144 Error_Msg_N
("Dispatching_Domain can only be defined" &
4148 elsif Duplicate_Clause
then
4152 -- The expression must be analyzed in the special manner
4153 -- described in "Handling of Default and Per-Object
4154 -- Expressions" in sem.ads.
4156 -- The visibility to the discriminants must be restored
4158 Push_Scope_And_Install_Discriminants
(U_Ent
);
4160 Preanalyze_Spec_Expression
4161 (Expr
, RTE
(RE_Dispatching_Domain
));
4163 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
4168 ("attribute& cannot be set with definition clause", N
);
4170 end Dispatching_Domain
;
4176 when Attribute_External_Tag
=> External_Tag
:
4178 if not Is_Tagged_Type
(U_Ent
) then
4179 Error_Msg_N
("should be a tagged type", Nam
);
4182 if Duplicate_Clause
then
4186 Analyze_And_Resolve
(Expr
, Standard_String
);
4188 if not Is_Static_Expression
(Expr
) then
4189 Flag_Non_Static_Expr
4190 ("static string required for tag name!", Nam
);
4193 if VM_Target
= No_VM
then
4194 Set_Has_External_Tag_Rep_Clause
(U_Ent
);
4196 Error_Msg_Name_1
:= Attr
;
4198 ("% attribute unsupported in this configuration", Nam
);
4201 if not Is_Library_Level_Entity
(U_Ent
) then
4203 ("??non-unique external tag supplied for &", N
, U_Ent
);
4205 ("\??same external tag applies to all "
4206 & "subprogram calls", N
);
4208 ("\??corresponding internal tag cannot be obtained", N
);
4213 --------------------------
4214 -- Implicit_Dereference --
4215 --------------------------
4217 when Attribute_Implicit_Dereference
=>
4219 -- Legality checks already performed at the point of the type
4220 -- declaration, aspect is not delayed.
4228 when Attribute_Input
=>
4229 Analyze_Stream_TSS_Definition
(TSS_Stream_Input
);
4230 Set_Has_Specified_Stream_Input
(Ent
);
4232 ------------------------
4233 -- Interrupt_Priority --
4234 ------------------------
4236 when Attribute_Interrupt_Priority
=> Interrupt_Priority
:
4238 -- Interrupt_Priority attribute definition clause not allowed
4239 -- except from aspect specification.
4241 if From_Aspect_Specification
(N
) then
4242 if not (Is_Protected_Type
(U_Ent
)
4243 or else Is_Task_Type
(U_Ent
))
4246 ("Interrupt_Priority can only be defined for task" &
4247 "and protected object",
4250 elsif Duplicate_Clause
then
4254 -- The expression must be analyzed in the special manner
4255 -- described in "Handling of Default and Per-Object
4256 -- Expressions" in sem.ads.
4258 -- The visibility to the discriminants must be restored
4260 Push_Scope_And_Install_Discriminants
(U_Ent
);
4262 Preanalyze_Spec_Expression
4263 (Expr
, RTE
(RE_Interrupt_Priority
));
4265 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
4270 ("attribute& cannot be set with definition clause", N
);
4272 end Interrupt_Priority
;
4274 ----------------------
4275 -- Iterator_Element --
4276 ----------------------
4278 when Attribute_Iterator_Element
=>
4281 if not Is_Entity_Name
(Expr
)
4282 or else not Is_Type
(Entity
(Expr
))
4284 Error_Msg_N
("aspect Iterator_Element must be a type", Expr
);
4291 -- Machine radix attribute definition clause
4293 when Attribute_Machine_Radix
=> Machine_Radix
: declare
4294 Radix
: constant Uint
:= Static_Integer
(Expr
);
4297 if not Is_Decimal_Fixed_Point_Type
(U_Ent
) then
4298 Error_Msg_N
("decimal fixed-point type expected for &", Nam
);
4300 elsif Duplicate_Clause
then
4303 elsif Radix
/= No_Uint
then
4304 Set_Has_Machine_Radix_Clause
(U_Ent
);
4305 Set_Has_Non_Standard_Rep
(Base_Type
(U_Ent
));
4309 elsif Radix
= 10 then
4310 Set_Machine_Radix_10
(U_Ent
);
4312 Error_Msg_N
("machine radix value must be 2 or 10", Expr
);
4321 -- Object_Size attribute definition clause
4323 when Attribute_Object_Size
=> Object_Size
: declare
4324 Size
: constant Uint
:= Static_Integer
(Expr
);
4327 pragma Warnings
(Off
, Biased
);
4330 if not Is_Type
(U_Ent
) then
4331 Error_Msg_N
("Object_Size cannot be given for &", Nam
);
4333 elsif Duplicate_Clause
then
4337 Check_Size
(Expr
, U_Ent
, Size
, Biased
);
4345 UI_Mod
(Size
, 64) /= 0
4348 ("Object_Size must be 8, 16, 32, or multiple of 64",
4352 Set_Esize
(U_Ent
, Size
);
4353 Set_Has_Object_Size_Clause
(U_Ent
);
4354 Alignment_Check_For_Size_Change
(U_Ent
, Size
);
4362 when Attribute_Output
=>
4363 Analyze_Stream_TSS_Definition
(TSS_Stream_Output
);
4364 Set_Has_Specified_Stream_Output
(Ent
);
4370 when Attribute_Priority
=> Priority
:
4372 -- Priority attribute definition clause not allowed except from
4373 -- aspect specification.
4375 if From_Aspect_Specification
(N
) then
4376 if not (Is_Protected_Type
(U_Ent
)
4377 or else Is_Task_Type
(U_Ent
)
4378 or else Ekind
(U_Ent
) = E_Procedure
)
4381 ("Priority can only be defined for task and protected " &
4385 elsif Duplicate_Clause
then
4389 -- The expression must be analyzed in the special manner
4390 -- described in "Handling of Default and Per-Object
4391 -- Expressions" in sem.ads.
4393 -- The visibility to the discriminants must be restored
4395 Push_Scope_And_Install_Discriminants
(U_Ent
);
4396 Preanalyze_Spec_Expression
(Expr
, Standard_Integer
);
4397 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
4399 if not Is_Static_Expression
(Expr
) then
4400 Check_Restriction
(Static_Priorities
, Expr
);
4406 ("attribute& cannot be set with definition clause", N
);
4414 when Attribute_Read
=>
4415 Analyze_Stream_TSS_Definition
(TSS_Stream_Read
);
4416 Set_Has_Specified_Stream_Read
(Ent
);
4418 --------------------------
4419 -- Scalar_Storage_Order --
4420 --------------------------
4422 -- Scalar_Storage_Order attribute definition clause
4424 when Attribute_Scalar_Storage_Order
=> Scalar_Storage_Order
: declare
4426 if not (Is_Record_Type
(U_Ent
) or else Is_Array_Type
(U_Ent
)) then
4428 ("Scalar_Storage_Order can only be defined for "
4429 & "record or array type", Nam
);
4431 elsif Duplicate_Clause
then
4435 Analyze_And_Resolve
(Expr
, RTE
(RE_Bit_Order
));
4437 if Etype
(Expr
) = Any_Type
then
4440 elsif not Is_Static_Expression
(Expr
) then
4441 Flag_Non_Static_Expr
4442 ("Scalar_Storage_Order requires static expression!", Expr
);
4444 elsif (Expr_Value
(Expr
) = 0) /= Bytes_Big_Endian
then
4446 -- Here for the case of a non-default (i.e. non-confirming)
4447 -- Scalar_Storage_Order attribute definition.
4449 if Support_Nondefault_SSO_On_Target
then
4450 Set_Reverse_Storage_Order
(Base_Type
(U_Ent
), True);
4453 ("non-default Scalar_Storage_Order "
4454 & "not supported on target", Expr
);
4458 end Scalar_Storage_Order
;
4464 -- Size attribute definition clause
4466 when Attribute_Size
=> Size
: declare
4467 Size
: constant Uint
:= Static_Integer
(Expr
);
4474 if Duplicate_Clause
then
4477 elsif not Is_Type
(U_Ent
)
4478 and then Ekind
(U_Ent
) /= E_Variable
4479 and then Ekind
(U_Ent
) /= E_Constant
4481 Error_Msg_N
("size cannot be given for &", Nam
);
4483 elsif Is_Array_Type
(U_Ent
)
4484 and then not Is_Constrained
(U_Ent
)
4487 ("size cannot be given for unconstrained array", Nam
);
4489 elsif Size
/= No_Uint
then
4490 if VM_Target
/= No_VM
and then not GNAT_Mode
then
4492 -- Size clause is not handled properly on VM targets.
4493 -- Display a warning unless we are in GNAT mode, in which
4494 -- case this is useless.
4497 ("size clauses are ignored in this configuration??", N
);
4500 if Is_Type
(U_Ent
) then
4503 Etyp
:= Etype
(U_Ent
);
4506 -- Check size, note that Gigi is in charge of checking that the
4507 -- size of an array or record type is OK. Also we do not check
4508 -- the size in the ordinary fixed-point case, since it is too
4509 -- early to do so (there may be subsequent small clause that
4510 -- affects the size). We can check the size if a small clause
4511 -- has already been given.
4513 if not Is_Ordinary_Fixed_Point_Type
(U_Ent
)
4514 or else Has_Small_Clause
(U_Ent
)
4516 Check_Size
(Expr
, Etyp
, Size
, Biased
);
4517 Set_Biased
(U_Ent
, N
, "size clause", Biased
);
4520 -- For types set RM_Size and Esize if possible
4522 if Is_Type
(U_Ent
) then
4523 Set_RM_Size
(U_Ent
, Size
);
4525 -- For elementary types, increase Object_Size to power of 2,
4526 -- but not less than a storage unit in any case (normally
4527 -- this means it will be byte addressable).
4529 -- For all other types, nothing else to do, we leave Esize
4530 -- (object size) unset, the back end will set it from the
4531 -- size and alignment in an appropriate manner.
4533 -- In both cases, we check whether the alignment must be
4534 -- reset in the wake of the size change.
4536 if Is_Elementary_Type
(U_Ent
) then
4537 if Size
<= System_Storage_Unit
then
4538 Init_Esize
(U_Ent
, System_Storage_Unit
);
4539 elsif Size
<= 16 then
4540 Init_Esize
(U_Ent
, 16);
4541 elsif Size
<= 32 then
4542 Init_Esize
(U_Ent
, 32);
4544 Set_Esize
(U_Ent
, (Size
+ 63) / 64 * 64);
4547 Alignment_Check_For_Size_Change
(U_Ent
, Esize
(U_Ent
));
4549 Alignment_Check_For_Size_Change
(U_Ent
, Size
);
4552 -- For objects, set Esize only
4555 if Is_Elementary_Type
(Etyp
) then
4556 if Size
/= System_Storage_Unit
4558 Size
/= System_Storage_Unit
* 2
4560 Size
/= System_Storage_Unit
* 4
4562 Size
/= System_Storage_Unit
* 8
4564 Error_Msg_Uint_1
:= UI_From_Int
(System_Storage_Unit
);
4565 Error_Msg_Uint_2
:= Error_Msg_Uint_1
* 8;
4567 ("size for primitive object must be a power of 2"
4568 & " in the range ^-^", N
);
4572 Set_Esize
(U_Ent
, Size
);
4575 Set_Has_Size_Clause
(U_Ent
);
4583 -- Small attribute definition clause
4585 when Attribute_Small
=> Small
: declare
4586 Implicit_Base
: constant Entity_Id
:= Base_Type
(U_Ent
);
4590 Analyze_And_Resolve
(Expr
, Any_Real
);
4592 if Etype
(Expr
) = Any_Type
then
4595 elsif not Is_Static_Expression
(Expr
) then
4596 Flag_Non_Static_Expr
4597 ("small requires static expression!", Expr
);
4601 Small
:= Expr_Value_R
(Expr
);
4603 if Small
<= Ureal_0
then
4604 Error_Msg_N
("small value must be greater than zero", Expr
);
4610 if not Is_Ordinary_Fixed_Point_Type
(U_Ent
) then
4612 ("small requires an ordinary fixed point type", Nam
);
4614 elsif Has_Small_Clause
(U_Ent
) then
4615 Error_Msg_N
("small already given for &", Nam
);
4617 elsif Small
> Delta_Value
(U_Ent
) then
4619 ("small value must not be greater than delta value", Nam
);
4622 Set_Small_Value
(U_Ent
, Small
);
4623 Set_Small_Value
(Implicit_Base
, Small
);
4624 Set_Has_Small_Clause
(U_Ent
);
4625 Set_Has_Small_Clause
(Implicit_Base
);
4626 Set_Has_Non_Standard_Rep
(Implicit_Base
);
4634 -- Storage_Pool attribute definition clause
4636 when Attribute_Storage_Pool | Attribute_Simple_Storage_Pool
=> declare
4641 if Ekind
(U_Ent
) = E_Access_Subprogram_Type
then
4643 ("storage pool cannot be given for access-to-subprogram type",
4648 Ekind_In
(U_Ent
, E_Access_Type
, E_General_Access_Type
)
4651 ("storage pool can only be given for access types", Nam
);
4654 elsif Is_Derived_Type
(U_Ent
) then
4656 ("storage pool cannot be given for a derived access type",
4659 elsif Duplicate_Clause
then
4662 elsif Present
(Associated_Storage_Pool
(U_Ent
)) then
4663 Error_Msg_N
("storage pool already given for &", Nam
);
4667 -- Check for Storage_Size previously given
4670 SS
: constant Node_Id
:=
4671 Get_Attribute_Definition_Clause
4672 (U_Ent
, Attribute_Storage_Size
);
4674 if Present
(SS
) then
4675 Check_Pool_Size_Clash
(U_Ent
, N
, SS
);
4679 -- Storage_Pool case
4681 if Id
= Attribute_Storage_Pool
then
4683 (Expr
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
4685 -- In the Simple_Storage_Pool case, we allow a variable of any
4686 -- simple storage pool type, so we Resolve without imposing an
4690 Analyze_And_Resolve
(Expr
);
4692 if not Present
(Get_Rep_Pragma
4693 (Etype
(Expr
), Name_Simple_Storage_Pool_Type
))
4696 ("expression must be of a simple storage pool type", Expr
);
4700 if not Denotes_Variable
(Expr
) then
4701 Error_Msg_N
("storage pool must be a variable", Expr
);
4705 if Nkind
(Expr
) = N_Type_Conversion
then
4706 T
:= Etype
(Expression
(Expr
));
4711 -- The Stack_Bounded_Pool is used internally for implementing
4712 -- access types with a Storage_Size. Since it only work properly
4713 -- when used on one specific type, we need to check that it is not
4714 -- hijacked improperly:
4716 -- type T is access Integer;
4717 -- for T'Storage_Size use n;
4718 -- type Q is access Float;
4719 -- for Q'Storage_Size use T'Storage_Size; -- incorrect
4721 if RTE_Available
(RE_Stack_Bounded_Pool
)
4722 and then Base_Type
(T
) = RTE
(RE_Stack_Bounded_Pool
)
4724 Error_Msg_N
("non-shareable internal Pool", Expr
);
4728 -- If the argument is a name that is not an entity name, then
4729 -- we construct a renaming operation to define an entity of
4730 -- type storage pool.
4732 if not Is_Entity_Name
(Expr
)
4733 and then Is_Object_Reference
(Expr
)
4735 Pool
:= Make_Temporary
(Loc
, 'P', Expr
);
4738 Rnode
: constant Node_Id
:=
4739 Make_Object_Renaming_Declaration
(Loc
,
4740 Defining_Identifier
=> Pool
,
4742 New_Occurrence_Of
(Etype
(Expr
), Loc
),
4746 -- If the attribute definition clause comes from an aspect
4747 -- clause, then insert the renaming before the associated
4748 -- entity's declaration, since the attribute clause has
4749 -- not yet been appended to the declaration list.
4751 if From_Aspect_Specification
(N
) then
4752 Insert_Before
(Parent
(Entity
(N
)), Rnode
);
4754 Insert_Before
(N
, Rnode
);
4758 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
4761 elsif Is_Entity_Name
(Expr
) then
4762 Pool
:= Entity
(Expr
);
4764 -- If pool is a renamed object, get original one. This can
4765 -- happen with an explicit renaming, and within instances.
4767 while Present
(Renamed_Object
(Pool
))
4768 and then Is_Entity_Name
(Renamed_Object
(Pool
))
4770 Pool
:= Entity
(Renamed_Object
(Pool
));
4773 if Present
(Renamed_Object
(Pool
))
4774 and then Nkind
(Renamed_Object
(Pool
)) = N_Type_Conversion
4775 and then Is_Entity_Name
(Expression
(Renamed_Object
(Pool
)))
4777 Pool
:= Entity
(Expression
(Renamed_Object
(Pool
)));
4780 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
4782 elsif Nkind
(Expr
) = N_Type_Conversion
4783 and then Is_Entity_Name
(Expression
(Expr
))
4784 and then Nkind
(Original_Node
(Expr
)) = N_Attribute_Reference
4786 Pool
:= Entity
(Expression
(Expr
));
4787 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
4790 Error_Msg_N
("incorrect reference to a Storage Pool", Expr
);
4799 -- Storage_Size attribute definition clause
4801 when Attribute_Storage_Size
=> Storage_Size
: declare
4802 Btype
: constant Entity_Id
:= Base_Type
(U_Ent
);
4805 if Is_Task_Type
(U_Ent
) then
4807 -- Check obsolescent (but never obsolescent if from aspect)
4809 if not From_Aspect_Specification
(N
) then
4810 Check_Restriction
(No_Obsolescent_Features
, N
);
4812 if Warn_On_Obsolescent_Feature
then
4814 ("?j?storage size clause for task is an " &
4815 "obsolescent feature (RM J.9)", N
);
4816 Error_Msg_N
("\?j?use Storage_Size pragma instead", N
);
4823 if not Is_Access_Type
(U_Ent
)
4824 and then Ekind
(U_Ent
) /= E_Task_Type
4826 Error_Msg_N
("storage size cannot be given for &", Nam
);
4828 elsif Is_Access_Type
(U_Ent
) and Is_Derived_Type
(U_Ent
) then
4830 ("storage size cannot be given for a derived access type",
4833 elsif Duplicate_Clause
then
4837 Analyze_And_Resolve
(Expr
, Any_Integer
);
4839 if Is_Access_Type
(U_Ent
) then
4841 -- Check for Storage_Pool previously given
4844 SP
: constant Node_Id
:=
4845 Get_Attribute_Definition_Clause
4846 (U_Ent
, Attribute_Storage_Pool
);
4849 if Present
(SP
) then
4850 Check_Pool_Size_Clash
(U_Ent
, SP
, N
);
4854 -- Special case of for x'Storage_Size use 0
4856 if Is_OK_Static_Expression
(Expr
)
4857 and then Expr_Value
(Expr
) = 0
4859 Set_No_Pool_Assigned
(Btype
);
4863 Set_Has_Storage_Size_Clause
(Btype
);
4871 when Attribute_Stream_Size
=> Stream_Size
: declare
4872 Size
: constant Uint
:= Static_Integer
(Expr
);
4875 if Ada_Version
<= Ada_95
then
4876 Check_Restriction
(No_Implementation_Attributes
, N
);
4879 if Duplicate_Clause
then
4882 elsif Is_Elementary_Type
(U_Ent
) then
4883 if Size
/= System_Storage_Unit
4885 Size
/= System_Storage_Unit
* 2
4887 Size
/= System_Storage_Unit
* 4
4889 Size
/= System_Storage_Unit
* 8
4891 Error_Msg_Uint_1
:= UI_From_Int
(System_Storage_Unit
);
4893 ("stream size for elementary type must be a"
4894 & " power of 2 and at least ^", N
);
4896 elsif RM_Size
(U_Ent
) > Size
then
4897 Error_Msg_Uint_1
:= RM_Size
(U_Ent
);
4899 ("stream size for elementary type must be a"
4900 & " power of 2 and at least ^", N
);
4903 Set_Has_Stream_Size_Clause
(U_Ent
);
4906 Error_Msg_N
("Stream_Size cannot be given for &", Nam
);
4914 -- Value_Size attribute definition clause
4916 when Attribute_Value_Size
=> Value_Size
: declare
4917 Size
: constant Uint
:= Static_Integer
(Expr
);
4921 if not Is_Type
(U_Ent
) then
4922 Error_Msg_N
("Value_Size cannot be given for &", Nam
);
4924 elsif Duplicate_Clause
then
4927 elsif Is_Array_Type
(U_Ent
)
4928 and then not Is_Constrained
(U_Ent
)
4931 ("Value_Size cannot be given for unconstrained array", Nam
);
4934 if Is_Elementary_Type
(U_Ent
) then
4935 Check_Size
(Expr
, U_Ent
, Size
, Biased
);
4936 Set_Biased
(U_Ent
, N
, "value size clause", Biased
);
4939 Set_RM_Size
(U_Ent
, Size
);
4943 -----------------------
4944 -- Variable_Indexing --
4945 -----------------------
4947 when Attribute_Variable_Indexing
=>
4948 Check_Indexing_Functions
;
4954 when Attribute_Write
=>
4955 Analyze_Stream_TSS_Definition
(TSS_Stream_Write
);
4956 Set_Has_Specified_Stream_Write
(Ent
);
4958 -- All other attributes cannot be set
4962 ("attribute& cannot be set with definition clause", N
);
4965 -- The test for the type being frozen must be performed after any
4966 -- expression the clause has been analyzed since the expression itself
4967 -- might cause freezing that makes the clause illegal.
4969 if Rep_Item_Too_Late
(U_Ent
, N
, FOnly
) then
4972 end Analyze_Attribute_Definition_Clause
;
4974 ----------------------------
4975 -- Analyze_Code_Statement --
4976 ----------------------------
4978 procedure Analyze_Code_Statement
(N
: Node_Id
) is
4979 HSS
: constant Node_Id
:= Parent
(N
);
4980 SBody
: constant Node_Id
:= Parent
(HSS
);
4981 Subp
: constant Entity_Id
:= Current_Scope
;
4988 -- Analyze and check we get right type, note that this implements the
4989 -- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that
4990 -- is the only way that Asm_Insn could possibly be visible.
4992 Analyze_And_Resolve
(Expression
(N
));
4994 if Etype
(Expression
(N
)) = Any_Type
then
4996 elsif Etype
(Expression
(N
)) /= RTE
(RE_Asm_Insn
) then
4997 Error_Msg_N
("incorrect type for code statement", N
);
5001 Check_Code_Statement
(N
);
5003 -- Make sure we appear in the handled statement sequence of a
5004 -- subprogram (RM 13.8(3)).
5006 if Nkind
(HSS
) /= N_Handled_Sequence_Of_Statements
5007 or else Nkind
(SBody
) /= N_Subprogram_Body
5010 ("code statement can only appear in body of subprogram", N
);
5014 -- Do remaining checks (RM 13.8(3)) if not already done
5016 if not Is_Machine_Code_Subprogram
(Subp
) then
5017 Set_Is_Machine_Code_Subprogram
(Subp
);
5019 -- No exception handlers allowed
5021 if Present
(Exception_Handlers
(HSS
)) then
5023 ("exception handlers not permitted in machine code subprogram",
5024 First
(Exception_Handlers
(HSS
)));
5027 -- No declarations other than use clauses and pragmas (we allow
5028 -- certain internally generated declarations as well).
5030 Decl
:= First
(Declarations
(SBody
));
5031 while Present
(Decl
) loop
5032 DeclO
:= Original_Node
(Decl
);
5033 if Comes_From_Source
(DeclO
)
5034 and not Nkind_In
(DeclO
, N_Pragma
,
5035 N_Use_Package_Clause
,
5037 N_Implicit_Label_Declaration
)
5040 ("this declaration not allowed in machine code subprogram",
5047 -- No statements other than code statements, pragmas, and labels.
5048 -- Again we allow certain internally generated statements.
5050 -- In Ada 2012, qualified expressions are names, and the code
5051 -- statement is initially parsed as a procedure call.
5053 Stmt
:= First
(Statements
(HSS
));
5054 while Present
(Stmt
) loop
5055 StmtO
:= Original_Node
(Stmt
);
5057 -- A procedure call transformed into a code statement is OK.
5059 if Ada_Version
>= Ada_2012
5060 and then Nkind
(StmtO
) = N_Procedure_Call_Statement
5061 and then Nkind
(Name
(StmtO
)) = N_Qualified_Expression
5065 elsif Comes_From_Source
(StmtO
)
5066 and then not Nkind_In
(StmtO
, N_Pragma
,
5071 ("this statement is not allowed in machine code subprogram",
5078 end Analyze_Code_Statement
;
5080 -----------------------------------------------
5081 -- Analyze_Enumeration_Representation_Clause --
5082 -----------------------------------------------
5084 procedure Analyze_Enumeration_Representation_Clause
(N
: Node_Id
) is
5085 Ident
: constant Node_Id
:= Identifier
(N
);
5086 Aggr
: constant Node_Id
:= Array_Aggregate
(N
);
5087 Enumtype
: Entity_Id
;
5094 Err
: Boolean := False;
5095 -- Set True to avoid cascade errors and crashes on incorrect source code
5097 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Universal_Integer
));
5098 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(Universal_Integer
));
5099 -- Allowed range of universal integer (= allowed range of enum lit vals)
5103 -- Minimum and maximum values of entries
5106 -- Pointer to node for literal providing max value
5109 if Ignore_Rep_Clauses
then
5113 -- Ignore enumeration rep clauses by default in CodePeer mode,
5114 -- unless -gnatd.I is specified, as a work around for potential false
5115 -- positive messages.
5117 if CodePeer_Mode
and not Debug_Flag_Dot_II
then
5121 -- First some basic error checks
5124 Enumtype
:= Entity
(Ident
);
5126 if Enumtype
= Any_Type
5127 or else Rep_Item_Too_Early
(Enumtype
, N
)
5131 Enumtype
:= Underlying_Type
(Enumtype
);
5134 if not Is_Enumeration_Type
(Enumtype
) then
5136 ("enumeration type required, found}",
5137 Ident
, First_Subtype
(Enumtype
));
5141 -- Ignore rep clause on generic actual type. This will already have
5142 -- been flagged on the template as an error, and this is the safest
5143 -- way to ensure we don't get a junk cascaded message in the instance.
5145 if Is_Generic_Actual_Type
(Enumtype
) then
5148 -- Type must be in current scope
5150 elsif Scope
(Enumtype
) /= Current_Scope
then
5151 Error_Msg_N
("type must be declared in this scope", Ident
);
5154 -- Type must be a first subtype
5156 elsif not Is_First_Subtype
(Enumtype
) then
5157 Error_Msg_N
("cannot give enumeration rep clause for subtype", N
);
5160 -- Ignore duplicate rep clause
5162 elsif Has_Enumeration_Rep_Clause
(Enumtype
) then
5163 Error_Msg_N
("duplicate enumeration rep clause ignored", N
);
5166 -- Don't allow rep clause for standard [wide_[wide_]]character
5168 elsif Is_Standard_Character_Type
(Enumtype
) then
5169 Error_Msg_N
("enumeration rep clause not allowed for this type", N
);
5172 -- Check that the expression is a proper aggregate (no parentheses)
5174 elsif Paren_Count
(Aggr
) /= 0 then
5176 ("extra parentheses surrounding aggregate not allowed",
5180 -- All tests passed, so set rep clause in place
5183 Set_Has_Enumeration_Rep_Clause
(Enumtype
);
5184 Set_Has_Enumeration_Rep_Clause
(Base_Type
(Enumtype
));
5187 -- Now we process the aggregate. Note that we don't use the normal
5188 -- aggregate code for this purpose, because we don't want any of the
5189 -- normal expansion activities, and a number of special semantic
5190 -- rules apply (including the component type being any integer type)
5192 Elit
:= First_Literal
(Enumtype
);
5194 -- First the positional entries if any
5196 if Present
(Expressions
(Aggr
)) then
5197 Expr
:= First
(Expressions
(Aggr
));
5198 while Present
(Expr
) loop
5200 Error_Msg_N
("too many entries in aggregate", Expr
);
5204 Val
:= Static_Integer
(Expr
);
5206 -- Err signals that we found some incorrect entries processing
5207 -- the list. The final checks for completeness and ordering are
5208 -- skipped in this case.
5210 if Val
= No_Uint
then
5212 elsif Val
< Lo
or else Hi
< Val
then
5213 Error_Msg_N
("value outside permitted range", Expr
);
5217 Set_Enumeration_Rep
(Elit
, Val
);
5218 Set_Enumeration_Rep_Expr
(Elit
, Expr
);
5224 -- Now process the named entries if present
5226 if Present
(Component_Associations
(Aggr
)) then
5227 Assoc
:= First
(Component_Associations
(Aggr
));
5228 while Present
(Assoc
) loop
5229 Choice
:= First
(Choices
(Assoc
));
5231 if Present
(Next
(Choice
)) then
5233 ("multiple choice not allowed here", Next
(Choice
));
5237 if Nkind
(Choice
) = N_Others_Choice
then
5238 Error_Msg_N
("others choice not allowed here", Choice
);
5241 elsif Nkind
(Choice
) = N_Range
then
5243 -- ??? should allow zero/one element range here
5245 Error_Msg_N
("range not allowed here", Choice
);
5249 Analyze_And_Resolve
(Choice
, Enumtype
);
5251 if Error_Posted
(Choice
) then
5256 if Is_Entity_Name
(Choice
)
5257 and then Is_Type
(Entity
(Choice
))
5259 Error_Msg_N
("subtype name not allowed here", Choice
);
5262 -- ??? should allow static subtype with zero/one entry
5264 elsif Etype
(Choice
) = Base_Type
(Enumtype
) then
5265 if not Is_Static_Expression
(Choice
) then
5266 Flag_Non_Static_Expr
5267 ("non-static expression used for choice!", Choice
);
5271 Elit
:= Expr_Value_E
(Choice
);
5273 if Present
(Enumeration_Rep_Expr
(Elit
)) then
5275 Sloc
(Enumeration_Rep_Expr
(Elit
));
5277 ("representation for& previously given#",
5282 Set_Enumeration_Rep_Expr
(Elit
, Expression
(Assoc
));
5284 Expr
:= Expression
(Assoc
);
5285 Val
:= Static_Integer
(Expr
);
5287 if Val
= No_Uint
then
5290 elsif Val
< Lo
or else Hi
< Val
then
5291 Error_Msg_N
("value outside permitted range", Expr
);
5295 Set_Enumeration_Rep
(Elit
, Val
);
5305 -- Aggregate is fully processed. Now we check that a full set of
5306 -- representations was given, and that they are in range and in order.
5307 -- These checks are only done if no other errors occurred.
5313 Elit
:= First_Literal
(Enumtype
);
5314 while Present
(Elit
) loop
5315 if No
(Enumeration_Rep_Expr
(Elit
)) then
5316 Error_Msg_NE
("missing representation for&!", N
, Elit
);
5319 Val
:= Enumeration_Rep
(Elit
);
5321 if Min
= No_Uint
then
5325 if Val
/= No_Uint
then
5326 if Max
/= No_Uint
and then Val
<= Max
then
5328 ("enumeration value for& not ordered!",
5329 Enumeration_Rep_Expr
(Elit
), Elit
);
5332 Max_Node
:= Enumeration_Rep_Expr
(Elit
);
5336 -- If there is at least one literal whose representation is not
5337 -- equal to the Pos value, then note that this enumeration type
5338 -- has a non-standard representation.
5340 if Val
/= Enumeration_Pos
(Elit
) then
5341 Set_Has_Non_Standard_Rep
(Base_Type
(Enumtype
));
5348 -- Now set proper size information
5351 Minsize
: Uint
:= UI_From_Int
(Minimum_Size
(Enumtype
));
5354 if Has_Size_Clause
(Enumtype
) then
5356 -- All OK, if size is OK now
5358 if RM_Size
(Enumtype
) >= Minsize
then
5362 -- Try if we can get by with biasing
5365 UI_From_Int
(Minimum_Size
(Enumtype
, Biased
=> True));
5367 -- Error message if even biasing does not work
5369 if RM_Size
(Enumtype
) < Minsize
then
5370 Error_Msg_Uint_1
:= RM_Size
(Enumtype
);
5371 Error_Msg_Uint_2
:= Max
;
5373 ("previously given size (^) is too small "
5374 & "for this value (^)", Max_Node
);
5376 -- If biasing worked, indicate that we now have biased rep
5380 (Enumtype
, Size_Clause
(Enumtype
), "size clause");
5385 Set_RM_Size
(Enumtype
, Minsize
);
5386 Set_Enum_Esize
(Enumtype
);
5389 Set_RM_Size
(Base_Type
(Enumtype
), RM_Size
(Enumtype
));
5390 Set_Esize
(Base_Type
(Enumtype
), Esize
(Enumtype
));
5391 Set_Alignment
(Base_Type
(Enumtype
), Alignment
(Enumtype
));
5395 -- We repeat the too late test in case it froze itself
5397 if Rep_Item_Too_Late
(Enumtype
, N
) then
5400 end Analyze_Enumeration_Representation_Clause
;
5402 ----------------------------
5403 -- Analyze_Free_Statement --
5404 ----------------------------
5406 procedure Analyze_Free_Statement
(N
: Node_Id
) is
5408 Analyze
(Expression
(N
));
5409 end Analyze_Free_Statement
;
5411 ---------------------------
5412 -- Analyze_Freeze_Entity --
5413 ---------------------------
5415 procedure Analyze_Freeze_Entity
(N
: Node_Id
) is
5417 Freeze_Entity_Checks
(N
);
5418 end Analyze_Freeze_Entity
;
5420 -----------------------------------
5421 -- Analyze_Freeze_Generic_Entity --
5422 -----------------------------------
5424 procedure Analyze_Freeze_Generic_Entity
(N
: Node_Id
) is
5426 Freeze_Entity_Checks
(N
);
5427 end Analyze_Freeze_Generic_Entity
;
5429 ------------------------------------------
5430 -- Analyze_Record_Representation_Clause --
5431 ------------------------------------------
5433 -- Note: we check as much as we can here, but we can't do any checks
5434 -- based on the position values (e.g. overlap checks) until freeze time
5435 -- because especially in Ada 2005 (machine scalar mode), the processing
5436 -- for non-standard bit order can substantially change the positions.
5437 -- See procedure Check_Record_Representation_Clause (called from Freeze)
5438 -- for the remainder of this processing.
5440 procedure Analyze_Record_Representation_Clause
(N
: Node_Id
) is
5441 Ident
: constant Node_Id
:= Identifier
(N
);
5446 Hbit
: Uint
:= Uint_0
;
5450 Rectype
: Entity_Id
;
5453 function Is_Inherited
(Comp
: Entity_Id
) return Boolean;
5454 -- True if Comp is an inherited component in a record extension
5460 function Is_Inherited
(Comp
: Entity_Id
) return Boolean is
5461 Comp_Base
: Entity_Id
;
5464 if Ekind
(Rectype
) = E_Record_Subtype
then
5465 Comp_Base
:= Original_Record_Component
(Comp
);
5470 return Comp_Base
/= Original_Record_Component
(Comp_Base
);
5475 Is_Record_Extension
: Boolean;
5476 -- True if Rectype is a record extension
5478 CR_Pragma
: Node_Id
:= Empty
;
5479 -- Points to N_Pragma node if Complete_Representation pragma present
5481 -- Start of processing for Analyze_Record_Representation_Clause
5484 if Ignore_Rep_Clauses
then
5489 Rectype
:= Entity
(Ident
);
5491 if Rectype
= Any_Type
or else Rep_Item_Too_Early
(Rectype
, N
) then
5494 Rectype
:= Underlying_Type
(Rectype
);
5497 -- First some basic error checks
5499 if not Is_Record_Type
(Rectype
) then
5501 ("record type required, found}", Ident
, First_Subtype
(Rectype
));
5504 elsif Scope
(Rectype
) /= Current_Scope
then
5505 Error_Msg_N
("type must be declared in this scope", N
);
5508 elsif not Is_First_Subtype
(Rectype
) then
5509 Error_Msg_N
("cannot give record rep clause for subtype", N
);
5512 elsif Has_Record_Rep_Clause
(Rectype
) then
5513 Error_Msg_N
("duplicate record rep clause ignored", N
);
5516 elsif Rep_Item_Too_Late
(Rectype
, N
) then
5520 -- We know we have a first subtype, now possibly go the the anonymous
5521 -- base type to determine whether Rectype is a record extension.
5523 Recdef
:= Type_Definition
(Declaration_Node
(Base_Type
(Rectype
)));
5524 Is_Record_Extension
:=
5525 Nkind
(Recdef
) = N_Derived_Type_Definition
5526 and then Present
(Record_Extension_Part
(Recdef
));
5528 if Present
(Mod_Clause
(N
)) then
5530 Loc
: constant Source_Ptr
:= Sloc
(N
);
5531 M
: constant Node_Id
:= Mod_Clause
(N
);
5532 P
: constant List_Id
:= Pragmas_Before
(M
);
5536 pragma Warnings
(Off
, Mod_Val
);
5539 Check_Restriction
(No_Obsolescent_Features
, Mod_Clause
(N
));
5541 if Warn_On_Obsolescent_Feature
then
5543 ("?j?mod clause is an obsolescent feature (RM J.8)", N
);
5545 ("\?j?use alignment attribute definition clause instead", N
);
5552 -- In ASIS_Mode mode, expansion is disabled, but we must convert
5553 -- the Mod clause into an alignment clause anyway, so that the
5554 -- back-end can compute and back-annotate properly the size and
5555 -- alignment of types that may include this record.
5557 -- This seems dubious, this destroys the source tree in a manner
5558 -- not detectable by ASIS ???
5560 if Operating_Mode
= Check_Semantics
and then ASIS_Mode
then
5562 Make_Attribute_Definition_Clause
(Loc
,
5563 Name
=> New_Reference_To
(Base_Type
(Rectype
), Loc
),
5564 Chars
=> Name_Alignment
,
5565 Expression
=> Relocate_Node
(Expression
(M
)));
5567 Set_From_At_Mod
(AtM_Nod
);
5568 Insert_After
(N
, AtM_Nod
);
5569 Mod_Val
:= Get_Alignment_Value
(Expression
(AtM_Nod
));
5570 Set_Mod_Clause
(N
, Empty
);
5573 -- Get the alignment value to perform error checking
5575 Mod_Val
:= Get_Alignment_Value
(Expression
(M
));
5580 -- For untagged types, clear any existing component clauses for the
5581 -- type. If the type is derived, this is what allows us to override
5582 -- a rep clause for the parent. For type extensions, the representation
5583 -- of the inherited components is inherited, so we want to keep previous
5584 -- component clauses for completeness.
5586 if not Is_Tagged_Type
(Rectype
) then
5587 Comp
:= First_Component_Or_Discriminant
(Rectype
);
5588 while Present
(Comp
) loop
5589 Set_Component_Clause
(Comp
, Empty
);
5590 Next_Component_Or_Discriminant
(Comp
);
5594 -- All done if no component clauses
5596 CC
:= First
(Component_Clauses
(N
));
5602 -- A representation like this applies to the base type
5604 Set_Has_Record_Rep_Clause
(Base_Type
(Rectype
));
5605 Set_Has_Non_Standard_Rep
(Base_Type
(Rectype
));
5606 Set_Has_Specified_Layout
(Base_Type
(Rectype
));
5608 -- Process the component clauses
5610 while Present
(CC
) loop
5614 if Nkind
(CC
) = N_Pragma
then
5617 -- The only pragma of interest is Complete_Representation
5619 if Pragma_Name
(CC
) = Name_Complete_Representation
then
5623 -- Processing for real component clause
5626 Posit
:= Static_Integer
(Position
(CC
));
5627 Fbit
:= Static_Integer
(First_Bit
(CC
));
5628 Lbit
:= Static_Integer
(Last_Bit
(CC
));
5631 and then Fbit
/= No_Uint
5632 and then Lbit
/= No_Uint
5636 ("position cannot be negative", Position
(CC
));
5640 ("first bit cannot be negative", First_Bit
(CC
));
5642 -- The Last_Bit specified in a component clause must not be
5643 -- less than the First_Bit minus one (RM-13.5.1(10)).
5645 elsif Lbit
< Fbit
- 1 then
5647 ("last bit cannot be less than first bit minus one",
5650 -- Values look OK, so find the corresponding record component
5651 -- Even though the syntax allows an attribute reference for
5652 -- implementation-defined components, GNAT does not allow the
5653 -- tag to get an explicit position.
5655 elsif Nkind
(Component_Name
(CC
)) = N_Attribute_Reference
then
5656 if Attribute_Name
(Component_Name
(CC
)) = Name_Tag
then
5657 Error_Msg_N
("position of tag cannot be specified", CC
);
5659 Error_Msg_N
("illegal component name", CC
);
5663 Comp
:= First_Entity
(Rectype
);
5664 while Present
(Comp
) loop
5665 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
5671 -- Maybe component of base type that is absent from
5672 -- statically constrained first subtype.
5674 Comp
:= First_Entity
(Base_Type
(Rectype
));
5675 while Present
(Comp
) loop
5676 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
5683 ("component clause is for non-existent field", CC
);
5685 -- Ada 2012 (AI05-0026): Any name that denotes a
5686 -- discriminant of an object of an unchecked union type
5687 -- shall not occur within a record_representation_clause.
5689 -- The general restriction of using record rep clauses on
5690 -- Unchecked_Union types has now been lifted. Since it is
5691 -- possible to introduce a record rep clause which mentions
5692 -- the discriminant of an Unchecked_Union in non-Ada 2012
5693 -- code, this check is applied to all versions of the
5696 elsif Ekind
(Comp
) = E_Discriminant
5697 and then Is_Unchecked_Union
(Rectype
)
5700 ("cannot reference discriminant of unchecked union",
5701 Component_Name
(CC
));
5703 elsif Is_Record_Extension
and then Is_Inherited
(Comp
) then
5705 ("component clause not allowed for inherited "
5706 & "component&", CC
, Comp
);
5708 elsif Present
(Component_Clause
(Comp
)) then
5710 -- Diagnose duplicate rep clause, or check consistency
5711 -- if this is an inherited component. In a double fault,
5712 -- there may be a duplicate inconsistent clause for an
5713 -- inherited component.
5715 if Scope
(Original_Record_Component
(Comp
)) = Rectype
5716 or else Parent
(Component_Clause
(Comp
)) = N
5718 Error_Msg_Sloc
:= Sloc
(Component_Clause
(Comp
));
5719 Error_Msg_N
("component clause previously given#", CC
);
5723 Rep1
: constant Node_Id
:= Component_Clause
(Comp
);
5725 if Intval
(Position
(Rep1
)) /=
5726 Intval
(Position
(CC
))
5727 or else Intval
(First_Bit
(Rep1
)) /=
5728 Intval
(First_Bit
(CC
))
5729 or else Intval
(Last_Bit
(Rep1
)) /=
5730 Intval
(Last_Bit
(CC
))
5733 ("component clause inconsistent "
5734 & "with representation of ancestor", CC
);
5736 elsif Warn_On_Redundant_Constructs
then
5738 ("?r?redundant confirming component clause "
5739 & "for component!", CC
);
5744 -- Normal case where this is the first component clause we
5745 -- have seen for this entity, so set it up properly.
5748 -- Make reference for field in record rep clause and set
5749 -- appropriate entity field in the field identifier.
5752 (Comp
, Component_Name
(CC
), Set_Ref
=> False);
5753 Set_Entity
(Component_Name
(CC
), Comp
);
5755 -- Update Fbit and Lbit to the actual bit number
5757 Fbit
:= Fbit
+ UI_From_Int
(SSU
) * Posit
;
5758 Lbit
:= Lbit
+ UI_From_Int
(SSU
) * Posit
;
5760 if Has_Size_Clause
(Rectype
)
5761 and then RM_Size
(Rectype
) <= Lbit
5764 ("bit number out of range of specified size",
5767 Set_Component_Clause
(Comp
, CC
);
5768 Set_Component_Bit_Offset
(Comp
, Fbit
);
5769 Set_Esize
(Comp
, 1 + (Lbit
- Fbit
));
5770 Set_Normalized_First_Bit
(Comp
, Fbit
mod SSU
);
5771 Set_Normalized_Position
(Comp
, Fbit
/ SSU
);
5773 if Warn_On_Overridden_Size
5774 and then Has_Size_Clause
(Etype
(Comp
))
5775 and then RM_Size
(Etype
(Comp
)) /= Esize
(Comp
)
5778 ("?S?component size overrides size clause for&",
5779 Component_Name
(CC
), Etype
(Comp
));
5782 -- This information is also set in the corresponding
5783 -- component of the base type, found by accessing the
5784 -- Original_Record_Component link if it is present.
5786 Ocomp
:= Original_Record_Component
(Comp
);
5793 (Component_Name
(CC
),
5799 (Comp
, First_Node
(CC
), "component clause", Biased
);
5801 if Present
(Ocomp
) then
5802 Set_Component_Clause
(Ocomp
, CC
);
5803 Set_Component_Bit_Offset
(Ocomp
, Fbit
);
5804 Set_Normalized_First_Bit
(Ocomp
, Fbit
mod SSU
);
5805 Set_Normalized_Position
(Ocomp
, Fbit
/ SSU
);
5806 Set_Esize
(Ocomp
, 1 + (Lbit
- Fbit
));
5808 Set_Normalized_Position_Max
5809 (Ocomp
, Normalized_Position
(Ocomp
));
5811 -- Note: we don't use Set_Biased here, because we
5812 -- already gave a warning above if needed, and we
5813 -- would get a duplicate for the same name here.
5815 Set_Has_Biased_Representation
5816 (Ocomp
, Has_Biased_Representation
(Comp
));
5819 if Esize
(Comp
) < 0 then
5820 Error_Msg_N
("component size is negative", CC
);
5831 -- Check missing components if Complete_Representation pragma appeared
5833 if Present
(CR_Pragma
) then
5834 Comp
:= First_Component_Or_Discriminant
(Rectype
);
5835 while Present
(Comp
) loop
5836 if No
(Component_Clause
(Comp
)) then
5838 ("missing component clause for &", CR_Pragma
, Comp
);
5841 Next_Component_Or_Discriminant
(Comp
);
5844 -- Give missing components warning if required
5846 elsif Warn_On_Unrepped_Components
then
5848 Num_Repped_Components
: Nat
:= 0;
5849 Num_Unrepped_Components
: Nat
:= 0;
5852 -- First count number of repped and unrepped components
5854 Comp
:= First_Component_Or_Discriminant
(Rectype
);
5855 while Present
(Comp
) loop
5856 if Present
(Component_Clause
(Comp
)) then
5857 Num_Repped_Components
:= Num_Repped_Components
+ 1;
5859 Num_Unrepped_Components
:= Num_Unrepped_Components
+ 1;
5862 Next_Component_Or_Discriminant
(Comp
);
5865 -- We are only interested in the case where there is at least one
5866 -- unrepped component, and at least half the components have rep
5867 -- clauses. We figure that if less than half have them, then the
5868 -- partial rep clause is really intentional. If the component
5869 -- type has no underlying type set at this point (as for a generic
5870 -- formal type), we don't know enough to give a warning on the
5873 if Num_Unrepped_Components
> 0
5874 and then Num_Unrepped_Components
< Num_Repped_Components
5876 Comp
:= First_Component_Or_Discriminant
(Rectype
);
5877 while Present
(Comp
) loop
5878 if No
(Component_Clause
(Comp
))
5879 and then Comes_From_Source
(Comp
)
5880 and then Present
(Underlying_Type
(Etype
(Comp
)))
5881 and then (Is_Scalar_Type
(Underlying_Type
(Etype
(Comp
)))
5882 or else Size_Known_At_Compile_Time
5883 (Underlying_Type
(Etype
(Comp
))))
5884 and then not Has_Warnings_Off
(Rectype
)
5886 Error_Msg_Sloc
:= Sloc
(Comp
);
5888 ("?C?no component clause given for & declared #",
5892 Next_Component_Or_Discriminant
(Comp
);
5897 end Analyze_Record_Representation_Clause
;
5899 -------------------------------------------
5900 -- Build_Invariant_Procedure_Declaration --
5901 -------------------------------------------
5903 function Build_Invariant_Procedure_Declaration
5904 (Typ
: Entity_Id
) return Node_Id
5906 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
5907 Object_Entity
: constant Entity_Id
:=
5908 Make_Defining_Identifier
(Loc
, New_Internal_Name
('I'));
5913 Set_Etype
(Object_Entity
, Typ
);
5915 -- Check for duplicate definiations.
5917 if Has_Invariants
(Typ
) and then Present
(Invariant_Procedure
(Typ
)) then
5922 Make_Defining_Identifier
(Loc
,
5923 Chars
=> New_External_Name
(Chars
(Typ
), "Invariant"));
5924 Set_Has_Invariants
(Typ
);
5925 Set_Ekind
(SId
, E_Procedure
);
5926 Set_Is_Invariant_Procedure
(SId
);
5927 Set_Invariant_Procedure
(Typ
, SId
);
5930 Make_Procedure_Specification
(Loc
,
5931 Defining_Unit_Name
=> SId
,
5932 Parameter_Specifications
=> New_List
(
5933 Make_Parameter_Specification
(Loc
,
5934 Defining_Identifier
=> Object_Entity
,
5935 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))));
5937 return Make_Subprogram_Declaration
(Loc
, Specification
=> Spec
);
5938 end Build_Invariant_Procedure_Declaration
;
5940 -------------------------------
5941 -- Build_Invariant_Procedure --
5942 -------------------------------
5944 -- The procedure that is constructed here has the form
5946 -- procedure typInvariant (Ixxx : typ) is
5948 -- pragma Check (Invariant, exp, "failed invariant from xxx");
5949 -- pragma Check (Invariant, exp, "failed invariant from xxx");
5951 -- pragma Check (Invariant, exp, "failed inherited invariant from xxx");
5953 -- end typInvariant;
5955 procedure Build_Invariant_Procedure
(Typ
: Entity_Id
; N
: Node_Id
) is
5956 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
5963 Visible_Decls
: constant List_Id
:= Visible_Declarations
(N
);
5964 Private_Decls
: constant List_Id
:= Private_Declarations
(N
);
5966 procedure Add_Invariants
(T
: Entity_Id
; Inherit
: Boolean);
5967 -- Appends statements to Stmts for any invariants in the rep item chain
5968 -- of the given type. If Inherit is False, then we only process entries
5969 -- on the chain for the type Typ. If Inherit is True, then we ignore any
5970 -- Invariant aspects, but we process all Invariant'Class aspects, adding
5971 -- "inherited" to the exception message and generating an informational
5972 -- message about the inheritance of an invariant.
5974 Object_Name
: Name_Id
;
5975 -- Name for argument of invariant procedure
5977 Object_Entity
: Node_Id
;
5978 -- The entity of the formal for the procedure
5980 --------------------
5981 -- Add_Invariants --
5982 --------------------
5984 procedure Add_Invariants
(T
: Entity_Id
; Inherit
: Boolean) is
5994 procedure Replace_Type_Reference
(N
: Node_Id
);
5995 -- Replace a single occurrence N of the subtype name with a reference
5996 -- to the formal of the predicate function. N can be an identifier
5997 -- referencing the subtype, or a selected component, representing an
5998 -- appropriately qualified occurrence of the subtype name.
6000 procedure Replace_Type_References
is
6001 new Replace_Type_References_Generic
(Replace_Type_Reference
);
6002 -- Traverse an expression replacing all occurrences of the subtype
6003 -- name with appropriate references to the object that is the formal
6004 -- parameter of the predicate function. Note that we must ensure
6005 -- that the type and entity information is properly set in the
6006 -- replacement node, since we will do a Preanalyze call of this
6007 -- expression without proper visibility of the procedure argument.
6009 ----------------------------
6010 -- Replace_Type_Reference --
6011 ----------------------------
6013 -- Note: See comments in Add_Predicates.Replace_Type_Reference
6014 -- regarding handling of Sloc and Comes_From_Source.
6016 procedure Replace_Type_Reference
(N
: Node_Id
) is
6019 -- Add semantic information to node to be rewritten, for ASIS
6020 -- navigation needs.
6022 if Nkind
(N
) = N_Identifier
then
6026 elsif Nkind
(N
) = N_Selected_Component
then
6027 Analyze
(Prefix
(N
));
6028 Set_Entity
(Selector_Name
(N
), T
);
6029 Set_Etype
(Selector_Name
(N
), T
);
6032 -- Invariant'Class, replace with T'Class (obj)
6034 if Class_Present
(Ritem
) then
6036 Make_Type_Conversion
(Sloc
(N
),
6038 Make_Attribute_Reference
(Sloc
(N
),
6039 Prefix
=> New_Occurrence_Of
(T
, Sloc
(N
)),
6040 Attribute_Name
=> Name_Class
),
6041 Expression
=> Make_Identifier
(Sloc
(N
), Object_Name
)));
6043 Set_Entity
(Expression
(N
), Object_Entity
);
6044 Set_Etype
(Expression
(N
), Typ
);
6046 -- Invariant, replace with obj
6049 Rewrite
(N
, Make_Identifier
(Sloc
(N
), Object_Name
));
6050 Set_Entity
(N
, Object_Entity
);
6054 Set_Comes_From_Source
(N
, True);
6055 end Replace_Type_Reference
;
6057 -- Start of processing for Add_Invariants
6060 Ritem
:= First_Rep_Item
(T
);
6061 while Present
(Ritem
) loop
6062 if Nkind
(Ritem
) = N_Pragma
6063 and then Pragma_Name
(Ritem
) = Name_Invariant
6065 Arg1
:= First
(Pragma_Argument_Associations
(Ritem
));
6066 Arg2
:= Next
(Arg1
);
6067 Arg3
:= Next
(Arg2
);
6069 Arg1
:= Get_Pragma_Arg
(Arg1
);
6070 Arg2
:= Get_Pragma_Arg
(Arg2
);
6072 -- For Inherit case, ignore Invariant, process only Class case
6075 if not Class_Present
(Ritem
) then
6079 -- For Inherit false, process only item for right type
6082 if Entity
(Arg1
) /= Typ
then
6088 Stmts
:= Empty_List
;
6091 Exp
:= New_Copy_Tree
(Arg2
);
6093 -- Preserve sloc of original pragma Invariant
6095 Loc
:= Sloc
(Ritem
);
6097 -- We need to replace any occurrences of the name of the type
6098 -- with references to the object, converted to type'Class in
6099 -- the case of Invariant'Class aspects.
6101 Replace_Type_References
(Exp
, Chars
(T
));
6103 -- If this invariant comes from an aspect, find the aspect
6104 -- specification, and replace the saved expression because
6105 -- we need the subtype references replaced for the calls to
6106 -- Preanalyze_Spec_Expressin in Check_Aspect_At_Freeze_Point
6107 -- and Check_Aspect_At_End_Of_Declarations.
6109 if From_Aspect_Specification
(Ritem
) then
6114 -- Loop to find corresponding aspect, note that this
6115 -- must be present given the pragma is marked delayed.
6117 Aitem
:= Next_Rep_Item
(Ritem
);
6118 while Present
(Aitem
) loop
6119 if Nkind
(Aitem
) = N_Aspect_Specification
6120 and then Aspect_Rep_Item
(Aitem
) = Ritem
6123 (Identifier
(Aitem
), New_Copy_Tree
(Exp
));
6127 Aitem
:= Next_Rep_Item
(Aitem
);
6132 -- Now we need to preanalyze the expression to properly capture
6133 -- the visibility in the visible part. The expression will not
6134 -- be analyzed for real until the body is analyzed, but that is
6135 -- at the end of the private part and has the wrong visibility.
6137 Set_Parent
(Exp
, N
);
6138 Preanalyze_Assert_Expression
(Exp
, Standard_Boolean
);
6140 -- In ASIS mode, even if assertions are not enabled, we must
6141 -- analyze the original expression in the aspect specification
6142 -- because it is part of the original tree.
6146 Inv
: constant Node_Id
:=
6147 Expression
(Corresponding_Aspect
(Ritem
));
6149 Replace_Type_References
(Inv
, Chars
(T
));
6150 Preanalyze_Assert_Expression
(Inv
, Standard_Boolean
);
6154 -- Build first two arguments for Check pragma
6157 Make_Pragma_Argument_Association
(Loc
,
6158 Expression
=> Make_Identifier
(Loc
, Name_Invariant
)),
6159 Make_Pragma_Argument_Association
(Loc
,
6160 Expression
=> Exp
));
6162 -- Add message if present in Invariant pragma
6164 if Present
(Arg3
) then
6165 Str
:= Strval
(Get_Pragma_Arg
(Arg3
));
6167 -- If inherited case, and message starts "failed invariant",
6168 -- change it to be "failed inherited invariant".
6171 String_To_Name_Buffer
(Str
);
6173 if Name_Buffer
(1 .. 16) = "failed invariant" then
6174 Insert_Str_In_Name_Buffer
("inherited ", 8);
6175 Str
:= String_From_Name_Buffer
;
6180 Make_Pragma_Argument_Association
(Loc
,
6181 Expression
=> Make_String_Literal
(Loc
, Str
)));
6184 -- Add Check pragma to list of statements
6188 Pragma_Identifier
=>
6189 Make_Identifier
(Loc
, Name_Check
),
6190 Pragma_Argument_Associations
=> Assoc
));
6192 -- If Inherited case and option enabled, output info msg. Note
6193 -- that we know this is a case of Invariant'Class.
6195 if Inherit
and Opt
.List_Inherited_Aspects
then
6196 Error_Msg_Sloc
:= Sloc
(Ritem
);
6198 ("?L?info: & inherits `Invariant''Class` aspect from #",
6204 Next_Rep_Item
(Ritem
);
6208 -- Start of processing for Build_Invariant_Procedure
6216 -- If the aspect specification exists for some view of the type, the
6217 -- declaration for the procedure has been created.
6219 if Has_Invariants
(Typ
) then
6220 SId
:= Invariant_Procedure
(Typ
);
6223 if Present
(SId
) then
6224 PDecl
:= Unit_Declaration_Node
(SId
);
6226 PDecl
:= Build_Invariant_Procedure_Declaration
(Typ
);
6229 -- Recover formal of procedure, for use in the calls to invariant
6230 -- functions (including inherited ones).
6234 (First
(Parameter_Specifications
(Specification
(PDecl
))));
6235 Object_Name
:= Chars
(Object_Entity
);
6237 -- Add invariants for the current type
6239 Add_Invariants
(Typ
, Inherit
=> False);
6241 -- Add invariants for parent types
6244 Current_Typ
: Entity_Id
;
6245 Parent_Typ
: Entity_Id
;
6250 Parent_Typ
:= Etype
(Current_Typ
);
6252 if Is_Private_Type
(Parent_Typ
)
6253 and then Present
(Full_View
(Base_Type
(Parent_Typ
)))
6255 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
6258 exit when Parent_Typ
= Current_Typ
;
6260 Current_Typ
:= Parent_Typ
;
6261 Add_Invariants
(Current_Typ
, Inherit
=> True);
6265 -- Build the procedure if we generated at least one Check pragma
6267 if Stmts
/= No_List
then
6268 Spec
:= Copy_Separate_Tree
(Specification
(PDecl
));
6271 Make_Subprogram_Body
(Loc
,
6272 Specification
=> Spec
,
6273 Declarations
=> Empty_List
,
6274 Handled_Statement_Sequence
=>
6275 Make_Handled_Sequence_Of_Statements
(Loc
,
6276 Statements
=> Stmts
));
6278 -- Insert procedure declaration and spec at the appropriate points.
6279 -- If declaration is already analyzed, it was processed by the
6280 -- generated pragma.
6282 if Present
(Private_Decls
) then
6284 -- The spec goes at the end of visible declarations, but they have
6285 -- already been analyzed, so we need to explicitly do the analyze.
6287 if not Analyzed
(PDecl
) then
6288 Append_To
(Visible_Decls
, PDecl
);
6292 -- The body goes at the end of the private declarations, which we
6293 -- have not analyzed yet, so we do not need to perform an explicit
6294 -- analyze call. We skip this if there are no private declarations
6295 -- (this is an error that will be caught elsewhere);
6297 Append_To
(Private_Decls
, PBody
);
6299 -- If the invariant appears on the full view of a type, the
6300 -- analysis of the private part is complete, and we must
6301 -- analyze the new body explicitly.
6303 if In_Private_Part
(Current_Scope
) then
6307 -- If there are no private declarations this may be an error that
6308 -- will be diagnosed elsewhere. However, if this is a non-private
6309 -- type that inherits invariants, it needs no completion and there
6310 -- may be no private part. In this case insert invariant procedure
6311 -- at end of current declarative list, and analyze at once, given
6312 -- that the type is about to be frozen.
6314 elsif not Is_Private_Type
(Typ
) then
6315 Append_To
(Visible_Decls
, PDecl
);
6316 Append_To
(Visible_Decls
, PBody
);
6321 end Build_Invariant_Procedure
;
6323 -------------------------------
6324 -- Build_Predicate_Functions --
6325 -------------------------------
6327 -- The procedures that are constructed here have the form:
6329 -- function typPredicate (Ixxx : typ) return Boolean is
6332 -- exp1 and then exp2 and then ...
6333 -- and then typ1Predicate (typ1 (Ixxx))
6334 -- and then typ2Predicate (typ2 (Ixxx))
6336 -- end typPredicate;
6338 -- Here exp1, and exp2 are expressions from Predicate pragmas. Note that
6339 -- this is the point at which these expressions get analyzed, providing the
6340 -- required delay, and typ1, typ2, are entities from which predicates are
6341 -- inherited. Note that we do NOT generate Check pragmas, that's because we
6342 -- use this function even if checks are off, e.g. for membership tests.
6344 -- If the expression has at least one Raise_Expression, then we also build
6345 -- the typPredicateM version of the function, in which any occurrence of a
6346 -- Raise_Expression is converted to "return False".
6348 procedure Build_Predicate_Functions
(Typ
: Entity_Id
; N
: Node_Id
) is
6349 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
6352 -- This is the expression for the result of the function. It is
6353 -- is build by connecting the component predicates with AND THEN.
6356 -- This is the corresponding return expression for the Predicate_M
6357 -- function. It differs in that raise expressions are marked for
6358 -- special expansion (see Process_REs).
6360 Object_Name
: constant Name_Id
:= New_Internal_Name
('I');
6361 -- Name for argument of Predicate procedure. Note that we use the same
6362 -- name for both predicate procedure. That way the reference within the
6363 -- predicate expression is the same in both functions.
6365 Object_Entity
: constant Entity_Id
:=
6366 Make_Defining_Identifier
(Loc
, Chars
=> Object_Name
);
6367 -- Entity for argument of Predicate procedure
6369 Object_Entity_M
: constant Entity_Id
:=
6370 Make_Defining_Identifier
(Loc
, Chars
=> Object_Name
);
6371 -- Entity for argument of Predicate_M procedure
6373 Raise_Expression_Present
: Boolean := False;
6374 -- Set True if Expr has at least one Raise_Expression
6376 Static_Predic
: Node_Id
:= Empty
;
6377 -- Set to N_Pragma node for a static predicate if one is encountered
6379 procedure Add_Call
(T
: Entity_Id
);
6380 -- Includes a call to the predicate function for type T in Expr if T
6381 -- has predicates and Predicate_Function (T) is non-empty.
6383 procedure Add_Predicates
;
6384 -- Appends expressions for any Predicate pragmas in the rep item chain
6385 -- Typ to Expr. Note that we look only at items for this exact entity.
6386 -- Inheritance of predicates for the parent type is done by calling the
6387 -- Predicate_Function of the parent type, using Add_Call above.
6389 function Test_RE
(N
: Node_Id
) return Traverse_Result
;
6390 -- Used in Test_REs, tests one node for being a raise expression, and if
6391 -- so sets Raise_Expression_Present True.
6393 procedure Test_REs
is new Traverse_Proc
(Test_RE
);
6394 -- Tests to see if Expr contains any raise expressions
6396 function Process_RE
(N
: Node_Id
) return Traverse_Result
;
6397 -- Used in Process REs, tests if node N is a raise expression, and if
6398 -- so, marks it to be converted to return False.
6400 procedure Process_REs
is new Traverse_Proc
(Process_RE
);
6401 -- Marks any raise expressions in Expr_M to return False
6407 procedure Add_Call
(T
: Entity_Id
) is
6411 if Present
(T
) and then Present
(Predicate_Function
(T
)) then
6412 Set_Has_Predicates
(Typ
);
6414 -- Build the call to the predicate function of T
6418 (T
, Convert_To
(T
, Make_Identifier
(Loc
, Object_Name
)));
6420 -- Add call to evolving expression, using AND THEN if needed
6427 Left_Opnd
=> Relocate_Node
(Expr
),
6431 -- Output info message on inheritance if required. Note we do not
6432 -- give this information for generic actual types, since it is
6433 -- unwelcome noise in that case in instantiations. We also
6434 -- generally suppress the message in instantiations, and also
6435 -- if it involves internal names.
6437 if Opt
.List_Inherited_Aspects
6438 and then not Is_Generic_Actual_Type
(Typ
)
6439 and then Instantiation_Depth
(Sloc
(Typ
)) = 0
6440 and then not Is_Internal_Name
(Chars
(T
))
6441 and then not Is_Internal_Name
(Chars
(Typ
))
6443 Error_Msg_Sloc
:= Sloc
(Predicate_Function
(T
));
6444 Error_Msg_Node_2
:= T
;
6445 Error_Msg_N
("info: & inherits predicate from & #?L?", Typ
);
6450 --------------------
6451 -- Add_Predicates --
6452 --------------------
6454 procedure Add_Predicates
is
6459 procedure Replace_Type_Reference
(N
: Node_Id
);
6460 -- Replace a single occurrence N of the subtype name with a reference
6461 -- to the formal of the predicate function. N can be an identifier
6462 -- referencing the subtype, or a selected component, representing an
6463 -- appropriately qualified occurrence of the subtype name.
6465 procedure Replace_Type_References
is
6466 new Replace_Type_References_Generic
(Replace_Type_Reference
);
6467 -- Traverse an expression changing every occurrence of an identifier
6468 -- whose name matches the name of the subtype with a reference to
6469 -- the formal parameter of the predicate function.
6471 ----------------------------
6472 -- Replace_Type_Reference --
6473 ----------------------------
6475 procedure Replace_Type_Reference
(N
: Node_Id
) is
6477 Rewrite
(N
, Make_Identifier
(Sloc
(N
), Object_Name
));
6478 -- Use the Sloc of the usage name, not the defining name
6481 Set_Entity
(N
, Object_Entity
);
6483 -- We want to treat the node as if it comes from source, so that
6484 -- ASIS will not ignore it
6486 Set_Comes_From_Source
(N
, True);
6487 end Replace_Type_Reference
;
6489 -- Start of processing for Add_Predicates
6492 Ritem
:= First_Rep_Item
(Typ
);
6493 while Present
(Ritem
) loop
6494 if Nkind
(Ritem
) = N_Pragma
6495 and then Pragma_Name
(Ritem
) = Name_Predicate
6497 -- Save the static predicate of the type for diagnostics and
6498 -- error reporting purposes.
6500 if Present
(Corresponding_Aspect
(Ritem
))
6501 and then Chars
(Identifier
(Corresponding_Aspect
(Ritem
))) =
6502 Name_Static_Predicate
6504 Static_Predic
:= Ritem
;
6507 -- Acquire arguments
6509 Arg1
:= First
(Pragma_Argument_Associations
(Ritem
));
6510 Arg2
:= Next
(Arg1
);
6512 Arg1
:= Get_Pragma_Arg
(Arg1
);
6513 Arg2
:= Get_Pragma_Arg
(Arg2
);
6515 -- See if this predicate pragma is for the current type or for
6516 -- its full view. A predicate on a private completion is placed
6517 -- on the partial view beause this is the visible entity that
6520 if Entity
(Arg1
) = Typ
6521 or else Full_View
(Entity
(Arg1
)) = Typ
6523 -- We have a match, this entry is for our subtype
6525 -- We need to replace any occurrences of the name of the
6526 -- type with references to the object.
6528 Replace_Type_References
(Arg2
, Chars
(Typ
));
6530 -- If this predicate comes from an aspect, find the aspect
6531 -- specification, and replace the saved expression because
6532 -- we need the subtype references replaced for the calls to
6533 -- Preanalyze_Spec_Expressin in Check_Aspect_At_Freeze_Point
6534 -- and Check_Aspect_At_End_Of_Declarations.
6536 if From_Aspect_Specification
(Ritem
) then
6541 -- Loop to find corresponding aspect, note that this
6542 -- must be present given the pragma is marked delayed.
6544 Aitem
:= Next_Rep_Item
(Ritem
);
6546 if Nkind
(Aitem
) = N_Aspect_Specification
6547 and then Aspect_Rep_Item
(Aitem
) = Ritem
6550 (Identifier
(Aitem
), New_Copy_Tree
(Arg2
));
6554 Aitem
:= Next_Rep_Item
(Aitem
);
6559 -- Now we can add the expression
6562 Expr
:= Relocate_Node
(Arg2
);
6564 -- There already was a predicate, so add to it
6569 Left_Opnd
=> Relocate_Node
(Expr
),
6570 Right_Opnd
=> Relocate_Node
(Arg2
));
6575 Next_Rep_Item
(Ritem
);
6583 function Process_RE
(N
: Node_Id
) return Traverse_Result
is
6585 if Nkind
(N
) = N_Raise_Expression
then
6586 Set_Convert_To_Return_False
(N
);
6597 function Test_RE
(N
: Node_Id
) return Traverse_Result
is
6599 if Nkind
(N
) = N_Raise_Expression
then
6600 Raise_Expression_Present
:= True;
6607 -- Start of processing for Build_Predicate_Functions
6610 -- Return if already built or if type does not have predicates
6612 if not Has_Predicates
(Typ
)
6613 or else Present
(Predicate_Function
(Typ
))
6618 -- Prepare to construct predicate expression
6622 -- Add Predicates for the current type
6626 -- Add predicates for ancestor if present
6629 Atyp
: constant Entity_Id
:= Nearest_Ancestor
(Typ
);
6631 if Present
(Atyp
) then
6636 -- Case where predicates are present
6638 if Present
(Expr
) then
6640 -- Test for raise expression present
6644 -- If raise expression is present, capture a copy of Expr for use
6645 -- in building the predicateM function version later on. For this
6646 -- copy we replace references to Object_Entity by Object_Entity_M.
6648 if Raise_Expression_Present
then
6650 Map
: constant Elist_Id
:= New_Elmt_List
;
6652 Append_Elmt
(Object_Entity
, Map
);
6653 Append_Elmt
(Object_Entity_M
, Map
);
6654 Expr_M
:= New_Copy_Tree
(Expr
, Map
=> Map
);
6658 -- Build the main predicate function
6661 SId
: constant Entity_Id
:=
6662 Make_Defining_Identifier
(Loc
,
6663 Chars
=> New_External_Name
(Chars
(Typ
), "Predicate"));
6664 -- The entity for the the function spec
6666 SIdB
: constant Entity_Id
:=
6667 Make_Defining_Identifier
(Loc
,
6668 Chars
=> New_External_Name
(Chars
(Typ
), "Predicate"));
6669 -- The entity for the function body
6676 -- Build function declaration
6678 Set_Ekind
(SId
, E_Function
);
6679 Set_Is_Predicate_Function
(SId
);
6680 Set_Predicate_Function
(Typ
, SId
);
6682 -- The predicate function is shared between views of a type
6684 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
6685 Set_Predicate_Function
(Full_View
(Typ
), SId
);
6689 Make_Function_Specification
(Loc
,
6690 Defining_Unit_Name
=> SId
,
6691 Parameter_Specifications
=> New_List
(
6692 Make_Parameter_Specification
(Loc
,
6693 Defining_Identifier
=> Object_Entity
,
6694 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))),
6695 Result_Definition
=>
6696 New_Occurrence_Of
(Standard_Boolean
, Loc
));
6699 Make_Subprogram_Declaration
(Loc
,
6700 Specification
=> Spec
);
6702 -- Build function body
6705 Make_Function_Specification
(Loc
,
6706 Defining_Unit_Name
=> SIdB
,
6707 Parameter_Specifications
=> New_List
(
6708 Make_Parameter_Specification
(Loc
,
6709 Defining_Identifier
=>
6710 Make_Defining_Identifier
(Loc
, Object_Name
),
6712 New_Occurrence_Of
(Typ
, Loc
))),
6713 Result_Definition
=>
6714 New_Occurrence_Of
(Standard_Boolean
, Loc
));
6717 Make_Subprogram_Body
(Loc
,
6718 Specification
=> Spec
,
6719 Declarations
=> Empty_List
,
6720 Handled_Statement_Sequence
=>
6721 Make_Handled_Sequence_Of_Statements
(Loc
,
6722 Statements
=> New_List
(
6723 Make_Simple_Return_Statement
(Loc
,
6724 Expression
=> Expr
))));
6726 -- Insert declaration before freeze node and body after
6728 Insert_Before_And_Analyze
(N
, FDecl
);
6729 Insert_After_And_Analyze
(N
, FBody
);
6732 -- Test for raise expressions present and if so build M version
6734 if Raise_Expression_Present
then
6736 SId
: constant Entity_Id
:=
6737 Make_Defining_Identifier
(Loc
,
6738 Chars
=> New_External_Name
(Chars
(Typ
), "PredicateM"));
6739 -- The entity for the the function spec
6741 SIdB
: constant Entity_Id
:=
6742 Make_Defining_Identifier
(Loc
,
6743 Chars
=> New_External_Name
(Chars
(Typ
), "PredicateM"));
6744 -- The entity for the function body
6752 -- Mark any raise expressions for special expansion
6754 Process_REs
(Expr_M
);
6756 -- Build function declaration
6758 Set_Ekind
(SId
, E_Function
);
6759 Set_Is_Predicate_Function_M
(SId
);
6760 Set_Predicate_Function_M
(Typ
, SId
);
6762 -- The predicate function is shared between views of a type
6764 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
6765 Set_Predicate_Function_M
(Full_View
(Typ
), SId
);
6769 Make_Function_Specification
(Loc
,
6770 Defining_Unit_Name
=> SId
,
6771 Parameter_Specifications
=> New_List
(
6772 Make_Parameter_Specification
(Loc
,
6773 Defining_Identifier
=> Object_Entity_M
,
6774 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))),
6775 Result_Definition
=>
6776 New_Occurrence_Of
(Standard_Boolean
, Loc
));
6779 Make_Subprogram_Declaration
(Loc
,
6780 Specification
=> Spec
);
6782 -- Build function body
6785 Make_Function_Specification
(Loc
,
6786 Defining_Unit_Name
=> SIdB
,
6787 Parameter_Specifications
=> New_List
(
6788 Make_Parameter_Specification
(Loc
,
6789 Defining_Identifier
=>
6790 Make_Defining_Identifier
(Loc
, Object_Name
),
6792 New_Occurrence_Of
(Typ
, Loc
))),
6793 Result_Definition
=>
6794 New_Occurrence_Of
(Standard_Boolean
, Loc
));
6796 -- Build the body, we declare the boolean expression before
6797 -- doing the return, because we are not really confident of
6798 -- what happens if a return appears within a return.
6801 Make_Defining_Identifier
(Loc
,
6802 Chars
=> New_Internal_Name
('B'));
6805 Make_Subprogram_Body
(Loc
,
6806 Specification
=> Spec
,
6808 Declarations
=> New_List
(
6809 Make_Object_Declaration
(Loc
,
6810 Defining_Identifier
=> BTemp
,
6811 Constant_Present
=> True,
6812 Object_Definition
=>
6813 New_Reference_To
(Standard_Boolean
, Loc
),
6814 Expression
=> Expr_M
)),
6816 Handled_Statement_Sequence
=>
6817 Make_Handled_Sequence_Of_Statements
(Loc
,
6818 Statements
=> New_List
(
6819 Make_Simple_Return_Statement
(Loc
,
6820 Expression
=> New_Reference_To
(BTemp
, Loc
)))));
6822 -- Insert declaration before freeze node and body after
6824 Insert_Before_And_Analyze
(N
, FDecl
);
6825 Insert_After_And_Analyze
(N
, FBody
);
6829 if Is_Scalar_Type
(Typ
) then
6831 -- Attempt to build a static predicate for a discrete or a real
6832 -- subtype. This action may fail because the actual expression may
6833 -- not be static. Note that the presence of an inherited or
6834 -- explicitly declared dynamic predicate is orthogonal to this
6835 -- check because we are only interested in the static predicate.
6837 if Ekind_In
(Typ
, E_Decimal_Fixed_Point_Subtype
,
6838 E_Enumeration_Subtype
,
6839 E_Floating_Point_Subtype
,
6840 E_Modular_Integer_Subtype
,
6841 E_Ordinary_Fixed_Point_Subtype
,
6842 E_Signed_Integer_Subtype
)
6844 Build_Static_Predicate
(Typ
, Expr
, Object_Name
);
6846 -- Emit an error when the predicate is categorized as static
6847 -- but its expression is dynamic.
6849 if Present
(Static_Predic
)
6850 and then No
(Static_Predicate
(Typ
))
6853 ("expression does not have required form for "
6854 & "static predicate",
6855 Next
(First
(Pragma_Argument_Associations
6860 -- If a static predicate applies on other types, that's an error:
6861 -- either the type is scalar but non-static, or it's not even a
6862 -- scalar type. We do not issue an error on generated types, as
6863 -- these may be duplicates of the same error on a source type.
6865 elsif Present
(Static_Predic
) and then Comes_From_Source
(Typ
) then
6866 if Is_Scalar_Type
(Typ
) then
6868 ("static predicate not allowed for non-static type&",
6872 ("static predicate not allowed for non-scalar type&",
6877 end Build_Predicate_Functions
;
6879 ----------------------------
6880 -- Build_Static_Predicate --
6881 ----------------------------
6883 procedure Build_Static_Predicate
6888 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
6890 Non_Static
: exception;
6891 -- Raised if something non-static is found
6893 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
6895 BLo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Btyp
));
6896 BHi
: constant Uint
:= Expr_Value
(Type_High_Bound
(Btyp
));
6897 -- Low bound and high bound value of base type of Typ
6899 TLo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Typ
));
6900 THi
: constant Uint
:= Expr_Value
(Type_High_Bound
(Typ
));
6901 -- Low bound and high bound values of static subtype Typ
6906 -- One entry in a Rlist value, a single REnt (range entry) value denotes
6907 -- one range from Lo to Hi. To represent a single value range Lo = Hi =
6910 type RList
is array (Nat
range <>) of REnt
;
6911 -- A list of ranges. The ranges are sorted in increasing order, and are
6912 -- disjoint (there is a gap of at least one value between each range in
6913 -- the table). A value is in the set of ranges in Rlist if it lies
6914 -- within one of these ranges.
6916 False_Range
: constant RList
:=
6917 RList
'(1 .. 0 => REnt'(No_Uint
, No_Uint
));
6918 -- An empty set of ranges represents a range list that can never be
6919 -- satisfied, since there are no ranges in which the value could lie,
6920 -- so it does not lie in any of them. False_Range is a canonical value
6921 -- for this empty set, but general processing should test for an Rlist
6922 -- with length zero (see Is_False predicate), since other null ranges
6923 -- may appear which must be treated as False.
6925 True_Range
: constant RList
:= RList
'(1 => REnt'(BLo
, BHi
));
6926 -- Range representing True, value must be in the base range
6928 function "and" (Left
: RList
; Right
: RList
) return RList
;
6929 -- And's together two range lists, returning a range list. This is a set
6930 -- intersection operation.
6932 function "or" (Left
: RList
; Right
: RList
) return RList
;
6933 -- Or's together two range lists, returning a range list. This is a set
6936 function "not" (Right
: RList
) return RList
;
6937 -- Returns complement of a given range list, i.e. a range list
6938 -- representing all the values in TLo .. THi that are not in the input
6941 function Build_Val
(V
: Uint
) return Node_Id
;
6942 -- Return an analyzed N_Identifier node referencing this value, suitable
6943 -- for use as an entry in the Static_Predicate list. This node is typed
6944 -- with the base type.
6946 function Build_Range
(Lo
: Uint
; Hi
: Uint
) return Node_Id
;
6947 -- Return an analyzed N_Range node referencing this range, suitable for
6948 -- use as an entry in the Static_Predicate list. This node is typed with
6951 function Get_RList
(Exp
: Node_Id
) return RList
;
6952 -- This is a recursive routine that converts the given expression into a
6953 -- list of ranges, suitable for use in building the static predicate.
6955 function Is_False
(R
: RList
) return Boolean;
6956 pragma Inline
(Is_False
);
6957 -- Returns True if the given range list is empty, and thus represents a
6958 -- False list of ranges that can never be satisfied.
6960 function Is_True
(R
: RList
) return Boolean;
6961 -- Returns True if R trivially represents the True predicate by having a
6962 -- single range from BLo to BHi.
6964 function Is_Type_Ref
(N
: Node_Id
) return Boolean;
6965 pragma Inline
(Is_Type_Ref
);
6966 -- Returns if True if N is a reference to the type for the predicate in
6967 -- the expression (i.e. if it is an identifier whose Chars field matches
6968 -- the Nam given in the call).
6970 function Lo_Val
(N
: Node_Id
) return Uint
;
6971 -- Given static expression or static range from a Static_Predicate list,
6972 -- gets expression value or low bound of range.
6974 function Hi_Val
(N
: Node_Id
) return Uint
;
6975 -- Given static expression or static range from a Static_Predicate list,
6976 -- gets expression value of high bound of range.
6978 function Membership_Entry
(N
: Node_Id
) return RList
;
6979 -- Given a single membership entry (range, value, or subtype), returns
6980 -- the corresponding range list. Raises Static_Error if not static.
6982 function Membership_Entries
(N
: Node_Id
) return RList
;
6983 -- Given an element on an alternatives list of a membership operation,
6984 -- returns the range list corresponding to this entry and all following
6985 -- entries (i.e. returns the "or" of this list of values).
6987 function Stat_Pred
(Typ
: Entity_Id
) return RList
;
6988 -- Given a type, if it has a static predicate, then return the predicate
6989 -- as a range list, otherwise raise Non_Static.
6995 function "and" (Left
: RList
; Right
: RList
) return RList
is
6997 -- First range of result
6999 SLeft
: Nat
:= Left
'First;
7000 -- Start of rest of left entries
7002 SRight
: Nat
:= Right
'First;
7003 -- Start of rest of right entries
7006 -- If either range is True, return the other
7008 if Is_True
(Left
) then
7010 elsif Is_True
(Right
) then
7014 -- If either range is False, return False
7016 if Is_False
(Left
) or else Is_False
(Right
) then
7020 -- Loop to remove entries at start that are disjoint, and thus just
7021 -- get discarded from the result entirely.
7024 -- If no operands left in either operand, result is false
7026 if SLeft
> Left
'Last or else SRight
> Right
'Last then
7029 -- Discard first left operand entry if disjoint with right
7031 elsif Left
(SLeft
).Hi
< Right
(SRight
).Lo
then
7034 -- Discard first right operand entry if disjoint with left
7036 elsif Right
(SRight
).Hi
< Left
(SLeft
).Lo
then
7037 SRight
:= SRight
+ 1;
7039 -- Otherwise we have an overlapping entry
7046 -- Now we have two non-null operands, and first entries overlap. The
7047 -- first entry in the result will be the overlapping part of these
7050 FEnt
:= REnt
'(Lo => UI_Max (Left (SLeft).Lo, Right (SRight).Lo),
7051 Hi => UI_Min (Left (SLeft).Hi, Right (SRight).Hi));
7053 -- Now we can remove the entry that ended at a lower value, since its
7054 -- contribution is entirely contained in Fent.
7056 if Left (SLeft).Hi <= Right (SRight).Hi then
7059 SRight := SRight + 1;
7062 -- Compute result by concatenating this first entry with the "and" of
7063 -- the remaining parts of the left and right operands. Note that if
7064 -- either of these is empty, "and" will yield empty, so that we will
7065 -- end up with just Fent, which is what we want in that case.
7068 FEnt & (Left (SLeft .. Left'Last) and Right (SRight .. Right'Last));
7075 function "not" (Right : RList) return RList is
7077 -- Return True if False range
7079 if Is_False (Right) then
7083 -- Return False if True range
7085 if Is_True (Right) then
7089 -- Here if not trivial case
7092 Result : RList (1 .. Right'Length + 1);
7093 -- May need one more entry for gap at beginning and end
7096 -- Number of entries stored in Result
7101 if Right (Right'First).Lo > TLo then
7103 Result (Count) := REnt'(TLo
, Right
(Right
'First).Lo
- 1);
7106 -- Gaps between ranges
7108 for J
in Right
'First .. Right
'Last - 1 loop
7111 REnt
'(Right (J).Hi + 1, Right (J + 1).Lo - 1);
7116 if Right (Right'Last).Hi < THi then
7118 Result (Count) := REnt'(Right
(Right
'Last).Hi
+ 1, THi
);
7121 return Result
(1 .. Count
);
7129 function "or" (Left
: RList
; Right
: RList
) return RList
is
7131 -- First range of result
7133 SLeft
: Nat
:= Left
'First;
7134 -- Start of rest of left entries
7136 SRight
: Nat
:= Right
'First;
7137 -- Start of rest of right entries
7140 -- If either range is True, return True
7142 if Is_True
(Left
) or else Is_True
(Right
) then
7146 -- If either range is False (empty), return the other
7148 if Is_False
(Left
) then
7150 elsif Is_False
(Right
) then
7154 -- Initialize result first entry from left or right operand depending
7155 -- on which starts with the lower range.
7157 if Left
(SLeft
).Lo
< Right
(SRight
).Lo
then
7158 FEnt
:= Left
(SLeft
);
7161 FEnt
:= Right
(SRight
);
7162 SRight
:= SRight
+ 1;
7165 -- This loop eats ranges from left and right operands that are
7166 -- contiguous with the first range we are gathering.
7169 -- Eat first entry in left operand if contiguous or overlapped by
7170 -- gathered first operand of result.
7172 if SLeft
<= Left
'Last
7173 and then Left
(SLeft
).Lo
<= FEnt
.Hi
+ 1
7175 FEnt
.Hi
:= UI_Max
(FEnt
.Hi
, Left
(SLeft
).Hi
);
7178 -- Eat first entry in right operand if contiguous or overlapped by
7179 -- gathered right operand of result.
7181 elsif SRight
<= Right
'Last
7182 and then Right
(SRight
).Lo
<= FEnt
.Hi
+ 1
7184 FEnt
.Hi
:= UI_Max
(FEnt
.Hi
, Right
(SRight
).Hi
);
7185 SRight
:= SRight
+ 1;
7187 -- All done if no more entries to eat
7194 -- Obtain result as the first entry we just computed, concatenated
7195 -- to the "or" of the remaining results (if one operand is empty,
7196 -- this will just concatenate with the other
7199 FEnt
& (Left
(SLeft
.. Left
'Last) or Right
(SRight
.. Right
'Last));
7206 function Build_Range
(Lo
: Uint
; Hi
: Uint
) return Node_Id
is
7212 Low_Bound
=> Build_Val
(Lo
),
7213 High_Bound
=> Build_Val
(Hi
));
7214 Set_Etype
(Result
, Btyp
);
7215 Set_Analyzed
(Result
);
7224 function Build_Val
(V
: Uint
) return Node_Id
is
7228 if Is_Enumeration_Type
(Typ
) then
7229 Result
:= Get_Enum_Lit_From_Pos
(Typ
, V
, Loc
);
7231 Result
:= Make_Integer_Literal
(Loc
, V
);
7234 Set_Etype
(Result
, Btyp
);
7235 Set_Is_Static_Expression
(Result
);
7236 Set_Analyzed
(Result
);
7244 function Get_RList
(Exp
: Node_Id
) return RList
is
7249 -- Static expression can only be true or false
7251 if Is_OK_Static_Expression
(Exp
) then
7255 if Expr_Value
(Exp
) = 0 then
7262 -- Otherwise test node type
7270 when N_Op_And | N_And_Then
=>
7271 return Get_RList
(Left_Opnd
(Exp
))
7273 Get_RList
(Right_Opnd
(Exp
));
7277 when N_Op_Or | N_Or_Else
=>
7278 return Get_RList
(Left_Opnd
(Exp
))
7280 Get_RList
(Right_Opnd
(Exp
));
7285 return not Get_RList
(Right_Opnd
(Exp
));
7287 -- Comparisons of type with static value
7289 when N_Op_Compare
=>
7291 -- Type is left operand
7293 if Is_Type_Ref
(Left_Opnd
(Exp
))
7294 and then Is_OK_Static_Expression
(Right_Opnd
(Exp
))
7296 Val
:= Expr_Value
(Right_Opnd
(Exp
));
7298 -- Typ is right operand
7300 elsif Is_Type_Ref
(Right_Opnd
(Exp
))
7301 and then Is_OK_Static_Expression
(Left_Opnd
(Exp
))
7303 Val
:= Expr_Value
(Left_Opnd
(Exp
));
7305 -- Invert sense of comparison
7308 when N_Op_Gt
=> Op
:= N_Op_Lt
;
7309 when N_Op_Lt
=> Op
:= N_Op_Gt
;
7310 when N_Op_Ge
=> Op
:= N_Op_Le
;
7311 when N_Op_Le
=> Op
:= N_Op_Ge
;
7312 when others => null;
7315 -- Other cases are non-static
7321 -- Construct range according to comparison operation
7325 return RList
'(1 => REnt'(Val
, Val
));
7328 return RList
'(1 => REnt'(Val
, BHi
));
7331 return RList
'(1 => REnt'(Val
+ 1, BHi
));
7334 return RList
'(1 => REnt'(BLo
, Val
));
7337 return RList
'(1 => REnt'(BLo
, Val
- 1));
7340 return RList
'(REnt'(BLo
, Val
- 1),
7341 REnt
'(Val + 1, BHi));
7344 raise Program_Error;
7350 if not Is_Type_Ref (Left_Opnd (Exp)) then
7354 if Present (Right_Opnd (Exp)) then
7355 return Membership_Entry (Right_Opnd (Exp));
7357 return Membership_Entries (First (Alternatives (Exp)));
7360 -- Negative membership (NOT IN)
7363 if not Is_Type_Ref (Left_Opnd (Exp)) then
7367 if Present (Right_Opnd (Exp)) then
7368 return not Membership_Entry (Right_Opnd (Exp));
7370 return not Membership_Entries (First (Alternatives (Exp)));
7373 -- Function call, may be call to static predicate
7375 when N_Function_Call =>
7376 if Is_Entity_Name (Name (Exp)) then
7378 Ent : constant Entity_Id := Entity (Name (Exp));
7380 if Is_Predicate_Function (Ent)
7382 Is_Predicate_Function_M (Ent)
7384 return Stat_Pred (Etype (First_Formal (Ent)));
7389 -- Other function call cases are non-static
7393 -- Qualified expression, dig out the expression
7395 when N_Qualified_Expression =>
7396 return Get_RList (Expression (Exp));
7398 -- Expression with actions: if no actions, dig out expression
7400 when N_Expression_With_Actions =>
7401 if Is_Empty_List (Actions (Exp)) then
7402 return Get_RList (Expression (Exp));
7411 return (Get_RList (Left_Opnd (Exp))
7412 and not Get_RList (Right_Opnd (Exp)))
7413 or (Get_RList (Right_Opnd (Exp))
7414 and not Get_RList (Left_Opnd (Exp)));
7416 -- Any other node type is non-static
7427 function Hi_Val (N : Node_Id) return Uint is
7429 if Is_Static_Expression (N) then
7430 return Expr_Value (N);
7432 pragma Assert (Nkind (N) = N_Range);
7433 return Expr_Value (High_Bound (N));
7441 function Is_False (R : RList) return Boolean is
7443 return R'Length = 0;
7450 function Is_True (R : RList) return Boolean is
7453 and then R (R'First).Lo = BLo
7454 and then R (R'First).Hi = BHi;
7461 function Is_Type_Ref (N : Node_Id) return Boolean is
7463 return Nkind (N) = N_Identifier and then Chars (N) = Nam;
7470 function Lo_Val (N : Node_Id) return Uint is
7472 if Is_Static_Expression (N) then
7473 return Expr_Value (N);
7475 pragma Assert (Nkind (N) = N_Range);
7476 return Expr_Value (Low_Bound (N));
7480 ------------------------
7481 -- Membership_Entries --
7482 ------------------------
7484 function Membership_Entries (N : Node_Id) return RList is
7486 if No (Next (N)) then
7487 return Membership_Entry (N);
7489 return Membership_Entry (N) or Membership_Entries (Next (N));
7491 end Membership_Entries;
7493 ----------------------
7494 -- Membership_Entry --
7495 ----------------------
7497 function Membership_Entry (N : Node_Id) return RList is
7505 if Nkind (N) = N_Range then
7506 if not Is_Static_Expression (Low_Bound (N))
7508 not Is_Static_Expression (High_Bound (N))
7512 SLo := Expr_Value (Low_Bound (N));
7513 SHi := Expr_Value (High_Bound (N));
7514 return RList'(1 => REnt
'(SLo, SHi));
7517 -- Static expression case
7519 elsif Is_Static_Expression (N) then
7520 Val := Expr_Value (N);
7521 return RList'(1 => REnt
'(Val, Val));
7523 -- Identifier (other than static expression) case
7525 else pragma Assert (Nkind (N) = N_Identifier);
7529 if Is_Type (Entity (N)) then
7531 -- If type has predicates, process them
7533 if Has_Predicates (Entity (N)) then
7534 return Stat_Pred (Entity (N));
7536 -- For static subtype without predicates, get range
7538 elsif Is_Static_Subtype (Entity (N)) then
7539 SLo := Expr_Value (Type_Low_Bound (Entity (N)));
7540 SHi := Expr_Value (Type_High_Bound (Entity (N)));
7541 return RList'(1 => REnt
'(SLo, SHi));
7543 -- Any other type makes us non-static
7549 -- Any other kind of identifier in predicate (e.g. a non-static
7550 -- expression value) means this is not a static predicate.
7556 end Membership_Entry;
7562 function Stat_Pred (Typ : Entity_Id) return RList is
7564 -- Not static if type does not have static predicates
7566 if not Has_Predicates (Typ) or else No (Static_Predicate (Typ)) then
7570 -- Otherwise we convert the predicate list to a range list
7573 Result : RList (1 .. List_Length (Static_Predicate (Typ)));
7577 P := First (Static_Predicate (Typ));
7578 for J in Result'Range loop
7579 Result (J) := REnt'(Lo_Val
(P
), Hi_Val
(P
));
7587 -- Start of processing for Build_Static_Predicate
7590 -- Now analyze the expression to see if it is a static predicate
7593 Ranges
: constant RList
:= Get_RList
(Expr
);
7594 -- Range list from expression if it is static
7599 -- Convert range list into a form for the static predicate. In the
7600 -- Ranges array, we just have raw ranges, these must be converted
7601 -- to properly typed and analyzed static expressions or range nodes.
7603 -- Note: here we limit ranges to the ranges of the subtype, so that
7604 -- a predicate is always false for values outside the subtype. That
7605 -- seems fine, such values are invalid anyway, and considering them
7606 -- to fail the predicate seems allowed and friendly, and furthermore
7607 -- simplifies processing for case statements and loops.
7611 for J
in Ranges
'Range loop
7613 Lo
: Uint
:= Ranges
(J
).Lo
;
7614 Hi
: Uint
:= Ranges
(J
).Hi
;
7617 -- Ignore completely out of range entry
7619 if Hi
< TLo
or else Lo
> THi
then
7622 -- Otherwise process entry
7625 -- Adjust out of range value to subtype range
7635 -- Convert range into required form
7637 Append_To
(Plist
, Build_Range
(Lo
, Hi
));
7642 -- Processing was successful and all entries were static, so now we
7643 -- can store the result as the predicate list.
7645 Set_Static_Predicate
(Typ
, Plist
);
7647 -- The processing for static predicates put the expression into
7648 -- canonical form as a series of ranges. It also eliminated
7649 -- duplicates and collapsed and combined ranges. We might as well
7650 -- replace the alternatives list of the right operand of the
7651 -- membership test with the static predicate list, which will
7652 -- usually be more efficient.
7655 New_Alts
: constant List_Id
:= New_List
;
7660 Old_Node
:= First
(Plist
);
7661 while Present
(Old_Node
) loop
7662 New_Node
:= New_Copy
(Old_Node
);
7664 if Nkind
(New_Node
) = N_Range
then
7665 Set_Low_Bound
(New_Node
, New_Copy
(Low_Bound
(Old_Node
)));
7666 Set_High_Bound
(New_Node
, New_Copy
(High_Bound
(Old_Node
)));
7669 Append_To
(New_Alts
, New_Node
);
7673 -- If empty list, replace by False
7675 if Is_Empty_List
(New_Alts
) then
7676 Rewrite
(Expr
, New_Occurrence_Of
(Standard_False
, Loc
));
7678 -- Else replace by set membership test
7683 Left_Opnd
=> Make_Identifier
(Loc
, Nam
),
7684 Right_Opnd
=> Empty
,
7685 Alternatives
=> New_Alts
));
7687 -- Resolve new expression in function context
7689 Install_Formals
(Predicate_Function
(Typ
));
7690 Push_Scope
(Predicate_Function
(Typ
));
7691 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
7697 -- If non-static, return doing nothing
7702 end Build_Static_Predicate
;
7704 -----------------------------------------
7705 -- Check_Aspect_At_End_Of_Declarations --
7706 -----------------------------------------
7708 procedure Check_Aspect_At_End_Of_Declarations
(ASN
: Node_Id
) is
7709 Ent
: constant Entity_Id
:= Entity
(ASN
);
7710 Ident
: constant Node_Id
:= Identifier
(ASN
);
7711 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Chars
(Ident
));
7713 End_Decl_Expr
: constant Node_Id
:= Entity
(Ident
);
7714 -- Expression to be analyzed at end of declarations
7716 Freeze_Expr
: constant Node_Id
:= Expression
(ASN
);
7717 -- Expression from call to Check_Aspect_At_Freeze_Point
7719 T
: constant Entity_Id
:= Etype
(Freeze_Expr
);
7720 -- Type required for preanalyze call
7723 -- Set False if error
7725 -- On entry to this procedure, Entity (Ident) contains a copy of the
7726 -- original expression from the aspect, saved for this purpose, and
7727 -- but Expression (Ident) is a preanalyzed copy of the expression,
7728 -- preanalyzed just after the freeze point.
7730 procedure Check_Overloaded_Name
;
7731 -- For aspects whose expression is simply a name, this routine checks if
7732 -- the name is overloaded or not. If so, it verifies there is an
7733 -- interpretation that matches the entity obtained at the freeze point,
7734 -- otherwise the compiler complains.
7736 ---------------------------
7737 -- Check_Overloaded_Name --
7738 ---------------------------
7740 procedure Check_Overloaded_Name
is
7742 if not Is_Overloaded
(End_Decl_Expr
) then
7743 Err
:= Entity
(End_Decl_Expr
) /= Entity
(Freeze_Expr
);
7749 Index
: Interp_Index
;
7753 Get_First_Interp
(End_Decl_Expr
, Index
, It
);
7754 while Present
(It
.Typ
) loop
7755 if It
.Nam
= Entity
(Freeze_Expr
) then
7760 Get_Next_Interp
(Index
, It
);
7764 end Check_Overloaded_Name
;
7766 -- Start of processing for Check_Aspect_At_End_Of_Declarations
7769 -- Case of aspects Dimension, Dimension_System and Synchronization
7771 if A_Id
= Aspect_Synchronization
then
7774 -- Case of stream attributes, just have to compare entities. However,
7775 -- the expression is just a name (possibly overloaded), and there may
7776 -- be stream operations declared for unrelated types, so we just need
7777 -- to verify that one of these interpretations is the one available at
7778 -- at the freeze point.
7780 elsif A_Id
= Aspect_Input
or else
7781 A_Id
= Aspect_Output
or else
7782 A_Id
= Aspect_Read
or else
7785 Analyze
(End_Decl_Expr
);
7786 Check_Overloaded_Name
;
7788 elsif A_Id
= Aspect_Variable_Indexing
or else
7789 A_Id
= Aspect_Constant_Indexing
or else
7790 A_Id
= Aspect_Default_Iterator
or else
7791 A_Id
= Aspect_Iterator_Element
7793 -- Make type unfrozen before analysis, to prevent spurious errors
7794 -- about late attributes.
7796 Set_Is_Frozen
(Ent
, False);
7797 Analyze
(End_Decl_Expr
);
7798 Set_Is_Frozen
(Ent
, True);
7800 -- If the end of declarations comes before any other freeze
7801 -- point, the Freeze_Expr is not analyzed: no check needed.
7803 if Analyzed
(Freeze_Expr
) and then not In_Instance
then
7804 Check_Overloaded_Name
;
7812 -- In a generic context the aspect expressions have not been
7813 -- preanalyzed, so do it now. There are no conformance checks
7814 -- to perform in this case.
7817 Check_Aspect_At_Freeze_Point
(ASN
);
7820 -- The default values attributes may be defined in the private part,
7821 -- and the analysis of the expression may take place when only the
7822 -- partial view is visible. The expression must be scalar, so use
7823 -- the full view to resolve.
7825 elsif (A_Id
= Aspect_Default_Value
7827 A_Id
= Aspect_Default_Component_Value
)
7828 and then Is_Private_Type
(T
)
7830 Preanalyze_Spec_Expression
(End_Decl_Expr
, Full_View
(T
));
7832 Preanalyze_Spec_Expression
(End_Decl_Expr
, T
);
7835 Err
:= not Fully_Conformant_Expressions
(End_Decl_Expr
, Freeze_Expr
);
7838 -- Output error message if error
7842 ("visibility of aspect for& changes after freeze point",
7845 ("info: & is frozen here, aspects evaluated at this point??",
7846 Freeze_Node
(Ent
), Ent
);
7848 end Check_Aspect_At_End_Of_Declarations
;
7850 ----------------------------------
7851 -- Check_Aspect_At_Freeze_Point --
7852 ----------------------------------
7854 procedure Check_Aspect_At_Freeze_Point
(ASN
: Node_Id
) is
7855 Ident
: constant Node_Id
:= Identifier
(ASN
);
7856 -- Identifier (use Entity field to save expression)
7858 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Chars
(Ident
));
7860 T
: Entity_Id
:= Empty
;
7861 -- Type required for preanalyze call
7864 -- On entry to this procedure, Entity (Ident) contains a copy of the
7865 -- original expression from the aspect, saved for this purpose.
7867 -- On exit from this procedure Entity (Ident) is unchanged, still
7868 -- containing that copy, but Expression (Ident) is a preanalyzed copy
7869 -- of the expression, preanalyzed just after the freeze point.
7871 -- Make a copy of the expression to be preanalyzed
7873 Set_Expression
(ASN
, New_Copy_Tree
(Entity
(Ident
)));
7875 -- Find type for preanalyze call
7879 -- No_Aspect should be impossible
7882 raise Program_Error
;
7884 -- Aspects taking an optional boolean argument
7886 when Boolean_Aspects |
7887 Library_Unit_Aspects
=>
7889 T
:= Standard_Boolean
;
7891 -- Aspects corresponding to attribute definition clauses
7893 when Aspect_Address
=>
7894 T
:= RTE
(RE_Address
);
7896 when Aspect_Attach_Handler
=>
7897 T
:= RTE
(RE_Interrupt_ID
);
7899 when Aspect_Bit_Order | Aspect_Scalar_Storage_Order
=>
7900 T
:= RTE
(RE_Bit_Order
);
7902 when Aspect_Convention
=>
7906 T
:= RTE
(RE_CPU_Range
);
7908 -- Default_Component_Value is resolved with the component type
7910 when Aspect_Default_Component_Value
=>
7911 T
:= Component_Type
(Entity
(ASN
));
7913 -- Default_Value is resolved with the type entity in question
7915 when Aspect_Default_Value
=>
7918 -- Depends is a delayed aspect because it mentiones names first
7919 -- introduced by aspect Global which is already delayed. There is
7920 -- no action to be taken with respect to the aspect itself as the
7921 -- analysis is done by the corresponding pragma.
7923 when Aspect_Depends
=>
7926 when Aspect_Dispatching_Domain
=>
7927 T
:= RTE
(RE_Dispatching_Domain
);
7929 when Aspect_External_Tag
=>
7930 T
:= Standard_String
;
7932 when Aspect_External_Name
=>
7933 T
:= Standard_String
;
7935 -- Global is a delayed aspect because it may reference names that
7936 -- have not been declared yet. There is no action to be taken with
7937 -- respect to the aspect itself as the reference checking is done
7938 -- on the corresponding pragma.
7940 when Aspect_Global
=>
7943 when Aspect_Link_Name
=>
7944 T
:= Standard_String
;
7946 when Aspect_Priority | Aspect_Interrupt_Priority
=>
7947 T
:= Standard_Integer
;
7949 when Aspect_Relative_Deadline
=>
7950 T
:= RTE
(RE_Time_Span
);
7952 when Aspect_Small
=>
7953 T
:= Universal_Real
;
7955 -- For a simple storage pool, we have to retrieve the type of the
7956 -- pool object associated with the aspect's corresponding attribute
7957 -- definition clause.
7959 when Aspect_Simple_Storage_Pool
=>
7960 T
:= Etype
(Expression
(Aspect_Rep_Item
(ASN
)));
7962 when Aspect_Storage_Pool
=>
7963 T
:= Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
));
7965 when Aspect_Alignment |
7966 Aspect_Component_Size |
7967 Aspect_Machine_Radix |
7968 Aspect_Object_Size |
7970 Aspect_Storage_Size |
7971 Aspect_Stream_Size |
7972 Aspect_Value_Size
=>
7975 when Aspect_Linker_Section
=>
7976 T
:= Standard_String
;
7978 when Aspect_Synchronization
=>
7981 -- Special case, the expression of these aspects is just an entity
7982 -- that does not need any resolution, so just analyze.
7991 Analyze
(Expression
(ASN
));
7994 -- Same for Iterator aspects, where the expression is a function
7995 -- name. Legality rules are checked separately.
7997 when Aspect_Constant_Indexing |
7998 Aspect_Default_Iterator |
7999 Aspect_Iterator_Element |
8000 Aspect_Variable_Indexing
=>
8001 Analyze
(Expression
(ASN
));
8004 -- Invariant/Predicate take boolean expressions
8006 when Aspect_Dynamic_Predicate |
8009 Aspect_Static_Predicate |
8010 Aspect_Type_Invariant
=>
8011 T
:= Standard_Boolean
;
8013 -- Here is the list of aspects that don't require delay analysis
8015 when Aspect_Abstract_State |
8016 Aspect_Contract_Cases |
8018 Aspect_Dimension_System |
8019 Aspect_Implicit_Dereference |
8020 Aspect_Initial_Condition |
8021 Aspect_Initializes |
8024 Aspect_Postcondition |
8026 Aspect_Precondition |
8027 Aspect_Refined_Depends |
8028 Aspect_Refined_Global |
8029 Aspect_Refined_Post |
8030 Aspect_Refined_State |
8033 raise Program_Error
;
8037 -- Do the preanalyze call
8039 Preanalyze_Spec_Expression
(Expression
(ASN
), T
);
8040 end Check_Aspect_At_Freeze_Point
;
8042 -----------------------------------
8043 -- Check_Constant_Address_Clause --
8044 -----------------------------------
8046 procedure Check_Constant_Address_Clause
8050 procedure Check_At_Constant_Address
(Nod
: Node_Id
);
8051 -- Checks that the given node N represents a name whose 'Address is
8052 -- constant (in the same sense as OK_Constant_Address_Clause, i.e. the
8053 -- address value is the same at the point of declaration of U_Ent and at
8054 -- the time of elaboration of the address clause.
8056 procedure Check_Expr_Constants
(Nod
: Node_Id
);
8057 -- Checks that Nod meets the requirements for a constant address clause
8058 -- in the sense of the enclosing procedure.
8060 procedure Check_List_Constants
(Lst
: List_Id
);
8061 -- Check that all elements of list Lst meet the requirements for a
8062 -- constant address clause in the sense of the enclosing procedure.
8064 -------------------------------
8065 -- Check_At_Constant_Address --
8066 -------------------------------
8068 procedure Check_At_Constant_Address
(Nod
: Node_Id
) is
8070 if Is_Entity_Name
(Nod
) then
8071 if Present
(Address_Clause
(Entity
((Nod
)))) then
8073 ("invalid address clause for initialized object &!",
8076 ("address for& cannot" &
8077 " depend on another address clause! (RM 13.1(22))!",
8080 elsif In_Same_Source_Unit
(Entity
(Nod
), U_Ent
)
8081 and then Sloc
(U_Ent
) < Sloc
(Entity
(Nod
))
8084 ("invalid address clause for initialized object &!",
8086 Error_Msg_Node_2
:= U_Ent
;
8088 ("\& must be defined before & (RM 13.1(22))!",
8092 elsif Nkind
(Nod
) = N_Selected_Component
then
8094 T
: constant Entity_Id
:= Etype
(Prefix
(Nod
));
8097 if (Is_Record_Type
(T
)
8098 and then Has_Discriminants
(T
))
8101 and then Is_Record_Type
(Designated_Type
(T
))
8102 and then Has_Discriminants
(Designated_Type
(T
)))
8105 ("invalid address clause for initialized object &!",
8108 ("\address cannot depend on component" &
8109 " of discriminated record (RM 13.1(22))!",
8112 Check_At_Constant_Address
(Prefix
(Nod
));
8116 elsif Nkind
(Nod
) = N_Indexed_Component
then
8117 Check_At_Constant_Address
(Prefix
(Nod
));
8118 Check_List_Constants
(Expressions
(Nod
));
8121 Check_Expr_Constants
(Nod
);
8123 end Check_At_Constant_Address
;
8125 --------------------------
8126 -- Check_Expr_Constants --
8127 --------------------------
8129 procedure Check_Expr_Constants
(Nod
: Node_Id
) is
8130 Loc_U_Ent
: constant Source_Ptr
:= Sloc
(U_Ent
);
8131 Ent
: Entity_Id
:= Empty
;
8134 if Nkind
(Nod
) in N_Has_Etype
8135 and then Etype
(Nod
) = Any_Type
8141 when N_Empty | N_Error
=>
8144 when N_Identifier | N_Expanded_Name
=>
8145 Ent
:= Entity
(Nod
);
8147 -- We need to look at the original node if it is different
8148 -- from the node, since we may have rewritten things and
8149 -- substituted an identifier representing the rewrite.
8151 if Original_Node
(Nod
) /= Nod
then
8152 Check_Expr_Constants
(Original_Node
(Nod
));
8154 -- If the node is an object declaration without initial
8155 -- value, some code has been expanded, and the expression
8156 -- is not constant, even if the constituents might be
8157 -- acceptable, as in A'Address + offset.
8159 if Ekind
(Ent
) = E_Variable
8161 Nkind
(Declaration_Node
(Ent
)) = N_Object_Declaration
8163 No
(Expression
(Declaration_Node
(Ent
)))
8166 ("invalid address clause for initialized object &!",
8169 -- If entity is constant, it may be the result of expanding
8170 -- a check. We must verify that its declaration appears
8171 -- before the object in question, else we also reject the
8174 elsif Ekind
(Ent
) = E_Constant
8175 and then In_Same_Source_Unit
(Ent
, U_Ent
)
8176 and then Sloc
(Ent
) > Loc_U_Ent
8179 ("invalid address clause for initialized object &!",
8186 -- Otherwise look at the identifier and see if it is OK
8188 if Ekind_In
(Ent
, E_Named_Integer
, E_Named_Real
)
8189 or else Is_Type
(Ent
)
8194 Ekind
(Ent
) = E_Constant
8196 Ekind
(Ent
) = E_In_Parameter
8198 -- This is the case where we must have Ent defined before
8199 -- U_Ent. Clearly if they are in different units this
8200 -- requirement is met since the unit containing Ent is
8201 -- already processed.
8203 if not In_Same_Source_Unit
(Ent
, U_Ent
) then
8206 -- Otherwise location of Ent must be before the location
8207 -- of U_Ent, that's what prior defined means.
8209 elsif Sloc
(Ent
) < Loc_U_Ent
then
8214 ("invalid address clause for initialized object &!",
8216 Error_Msg_Node_2
:= U_Ent
;
8218 ("\& must be defined before & (RM 13.1(22))!",
8222 elsif Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
8223 Check_Expr_Constants
(Original_Node
(Nod
));
8227 ("invalid address clause for initialized object &!",
8230 if Comes_From_Source
(Ent
) then
8232 ("\reference to variable& not allowed"
8233 & " (RM 13.1(22))!", Nod
, Ent
);
8236 ("non-static expression not allowed"
8237 & " (RM 13.1(22))!", Nod
);
8241 when N_Integer_Literal
=>
8243 -- If this is a rewritten unchecked conversion, in a system
8244 -- where Address is an integer type, always use the base type
8245 -- for a literal value. This is user-friendly and prevents
8246 -- order-of-elaboration issues with instances of unchecked
8249 if Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
8250 Set_Etype
(Nod
, Base_Type
(Etype
(Nod
)));
8253 when N_Real_Literal |
8255 N_Character_Literal
=>
8259 Check_Expr_Constants
(Low_Bound
(Nod
));
8260 Check_Expr_Constants
(High_Bound
(Nod
));
8262 when N_Explicit_Dereference
=>
8263 Check_Expr_Constants
(Prefix
(Nod
));
8265 when N_Indexed_Component
=>
8266 Check_Expr_Constants
(Prefix
(Nod
));
8267 Check_List_Constants
(Expressions
(Nod
));
8270 Check_Expr_Constants
(Prefix
(Nod
));
8271 Check_Expr_Constants
(Discrete_Range
(Nod
));
8273 when N_Selected_Component
=>
8274 Check_Expr_Constants
(Prefix
(Nod
));
8276 when N_Attribute_Reference
=>
8277 if Nam_In
(Attribute_Name
(Nod
), Name_Address
,
8279 Name_Unchecked_Access
,
8280 Name_Unrestricted_Access
)
8282 Check_At_Constant_Address
(Prefix
(Nod
));
8285 Check_Expr_Constants
(Prefix
(Nod
));
8286 Check_List_Constants
(Expressions
(Nod
));
8290 Check_List_Constants
(Component_Associations
(Nod
));
8291 Check_List_Constants
(Expressions
(Nod
));
8293 when N_Component_Association
=>
8294 Check_Expr_Constants
(Expression
(Nod
));
8296 when N_Extension_Aggregate
=>
8297 Check_Expr_Constants
(Ancestor_Part
(Nod
));
8298 Check_List_Constants
(Component_Associations
(Nod
));
8299 Check_List_Constants
(Expressions
(Nod
));
8304 when N_Binary_Op | N_Short_Circuit | N_Membership_Test
=>
8305 Check_Expr_Constants
(Left_Opnd
(Nod
));
8306 Check_Expr_Constants
(Right_Opnd
(Nod
));
8309 Check_Expr_Constants
(Right_Opnd
(Nod
));
8311 when N_Type_Conversion |
8312 N_Qualified_Expression |
8314 N_Unchecked_Type_Conversion
=>
8315 Check_Expr_Constants
(Expression
(Nod
));
8317 when N_Function_Call
=>
8318 if not Is_Pure
(Entity
(Name
(Nod
))) then
8320 ("invalid address clause for initialized object &!",
8324 ("\function & is not pure (RM 13.1(22))!",
8325 Nod
, Entity
(Name
(Nod
)));
8328 Check_List_Constants
(Parameter_Associations
(Nod
));
8331 when N_Parameter_Association
=>
8332 Check_Expr_Constants
(Explicit_Actual_Parameter
(Nod
));
8336 ("invalid address clause for initialized object &!",
8339 ("\must be constant defined before& (RM 13.1(22))!",
8342 end Check_Expr_Constants
;
8344 --------------------------
8345 -- Check_List_Constants --
8346 --------------------------
8348 procedure Check_List_Constants
(Lst
: List_Id
) is
8352 if Present
(Lst
) then
8353 Nod1
:= First
(Lst
);
8354 while Present
(Nod1
) loop
8355 Check_Expr_Constants
(Nod1
);
8359 end Check_List_Constants
;
8361 -- Start of processing for Check_Constant_Address_Clause
8364 -- If rep_clauses are to be ignored, no need for legality checks. In
8365 -- particular, no need to pester user about rep clauses that violate
8366 -- the rule on constant addresses, given that these clauses will be
8367 -- removed by Freeze before they reach the back end.
8369 if not Ignore_Rep_Clauses
then
8370 Check_Expr_Constants
(Expr
);
8372 end Check_Constant_Address_Clause
;
8374 ---------------------------
8375 -- Check_Pool_Size_Clash --
8376 ---------------------------
8378 procedure Check_Pool_Size_Clash
(Ent
: Entity_Id
; SP
, SS
: Node_Id
) is
8382 -- We need to find out which one came first. Note that in the case of
8383 -- aspects mixed with pragmas there are cases where the processing order
8384 -- is reversed, which is why we do the check here.
8386 if Sloc
(SP
) < Sloc
(SS
) then
8387 Error_Msg_Sloc
:= Sloc
(SP
);
8389 Error_Msg_NE
("Storage_Pool previously given for&#", Post
, Ent
);
8392 Error_Msg_Sloc
:= Sloc
(SS
);
8394 Error_Msg_NE
("Storage_Size previously given for&#", Post
, Ent
);
8398 ("\cannot have Storage_Size and Storage_Pool (RM 13.11(3))", Post
);
8399 end Check_Pool_Size_Clash
;
8401 ----------------------------------------
8402 -- Check_Record_Representation_Clause --
8403 ----------------------------------------
8405 procedure Check_Record_Representation_Clause
(N
: Node_Id
) is
8406 Loc
: constant Source_Ptr
:= Sloc
(N
);
8407 Ident
: constant Node_Id
:= Identifier
(N
);
8408 Rectype
: Entity_Id
;
8413 Hbit
: Uint
:= Uint_0
;
8417 Max_Bit_So_Far
: Uint
;
8418 -- Records the maximum bit position so far. If all field positions
8419 -- are monotonically increasing, then we can skip the circuit for
8420 -- checking for overlap, since no overlap is possible.
8422 Tagged_Parent
: Entity_Id
:= Empty
;
8423 -- This is set in the case of a derived tagged type for which we have
8424 -- Is_Fully_Repped_Tagged_Type True (indicating that all components are
8425 -- positioned by record representation clauses). In this case we must
8426 -- check for overlap between components of this tagged type, and the
8427 -- components of its parent. Tagged_Parent will point to this parent
8428 -- type. For all other cases Tagged_Parent is left set to Empty.
8430 Parent_Last_Bit
: Uint
;
8431 -- Relevant only if Tagged_Parent is set, Parent_Last_Bit indicates the
8432 -- last bit position for any field in the parent type. We only need to
8433 -- check overlap for fields starting below this point.
8435 Overlap_Check_Required
: Boolean;
8436 -- Used to keep track of whether or not an overlap check is required
8438 Overlap_Detected
: Boolean := False;
8439 -- Set True if an overlap is detected
8441 Ccount
: Natural := 0;
8442 -- Number of component clauses in record rep clause
8444 procedure Check_Component_Overlap
(C1_Ent
, C2_Ent
: Entity_Id
);
8445 -- Given two entities for record components or discriminants, checks
8446 -- if they have overlapping component clauses and issues errors if so.
8448 procedure Find_Component
;
8449 -- Finds component entity corresponding to current component clause (in
8450 -- CC), and sets Comp to the entity, and Fbit/Lbit to the zero origin
8451 -- start/stop bits for the field. If there is no matching component or
8452 -- if the matching component does not have a component clause, then
8453 -- that's an error and Comp is set to Empty, but no error message is
8454 -- issued, since the message was already given. Comp is also set to
8455 -- Empty if the current "component clause" is in fact a pragma.
8457 -----------------------------
8458 -- Check_Component_Overlap --
8459 -----------------------------
8461 procedure Check_Component_Overlap
(C1_Ent
, C2_Ent
: Entity_Id
) is
8462 CC1
: constant Node_Id
:= Component_Clause
(C1_Ent
);
8463 CC2
: constant Node_Id
:= Component_Clause
(C2_Ent
);
8466 if Present
(CC1
) and then Present
(CC2
) then
8468 -- Exclude odd case where we have two tag components in the same
8469 -- record, both at location zero. This seems a bit strange, but
8470 -- it seems to happen in some circumstances, perhaps on an error.
8472 if Nam_In
(Chars
(C1_Ent
), Name_uTag
, Name_uTag
) then
8476 -- Here we check if the two fields overlap
8479 S1
: constant Uint
:= Component_Bit_Offset
(C1_Ent
);
8480 S2
: constant Uint
:= Component_Bit_Offset
(C2_Ent
);
8481 E1
: constant Uint
:= S1
+ Esize
(C1_Ent
);
8482 E2
: constant Uint
:= S2
+ Esize
(C2_Ent
);
8485 if E2
<= S1
or else E1
<= S2
then
8488 Error_Msg_Node_2
:= Component_Name
(CC2
);
8489 Error_Msg_Sloc
:= Sloc
(Error_Msg_Node_2
);
8490 Error_Msg_Node_1
:= Component_Name
(CC1
);
8492 ("component& overlaps & #", Component_Name
(CC1
));
8493 Overlap_Detected
:= True;
8497 end Check_Component_Overlap
;
8499 --------------------
8500 -- Find_Component --
8501 --------------------
8503 procedure Find_Component
is
8505 procedure Search_Component
(R
: Entity_Id
);
8506 -- Search components of R for a match. If found, Comp is set
8508 ----------------------
8509 -- Search_Component --
8510 ----------------------
8512 procedure Search_Component
(R
: Entity_Id
) is
8514 Comp
:= First_Component_Or_Discriminant
(R
);
8515 while Present
(Comp
) loop
8517 -- Ignore error of attribute name for component name (we
8518 -- already gave an error message for this, so no need to
8521 if Nkind
(Component_Name
(CC
)) = N_Attribute_Reference
then
8524 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
8527 Next_Component_Or_Discriminant
(Comp
);
8529 end Search_Component
;
8531 -- Start of processing for Find_Component
8534 -- Return with Comp set to Empty if we have a pragma
8536 if Nkind
(CC
) = N_Pragma
then
8541 -- Search current record for matching component
8543 Search_Component
(Rectype
);
8545 -- If not found, maybe component of base type discriminant that is
8546 -- absent from statically constrained first subtype.
8549 Search_Component
(Base_Type
(Rectype
));
8552 -- If no component, or the component does not reference the component
8553 -- clause in question, then there was some previous error for which
8554 -- we already gave a message, so just return with Comp Empty.
8556 if No
(Comp
) or else Component_Clause
(Comp
) /= CC
then
8557 Check_Error_Detected
;
8560 -- Normal case where we have a component clause
8563 Fbit
:= Component_Bit_Offset
(Comp
);
8564 Lbit
:= Fbit
+ Esize
(Comp
) - 1;
8568 -- Start of processing for Check_Record_Representation_Clause
8572 Rectype
:= Entity
(Ident
);
8574 if Rectype
= Any_Type
then
8577 Rectype
:= Underlying_Type
(Rectype
);
8580 -- See if we have a fully repped derived tagged type
8583 PS
: constant Entity_Id
:= Parent_Subtype
(Rectype
);
8586 if Present
(PS
) and then Is_Fully_Repped_Tagged_Type
(PS
) then
8587 Tagged_Parent
:= PS
;
8589 -- Find maximum bit of any component of the parent type
8591 Parent_Last_Bit
:= UI_From_Int
(System_Address_Size
- 1);
8592 Pcomp
:= First_Entity
(Tagged_Parent
);
8593 while Present
(Pcomp
) loop
8594 if Ekind_In
(Pcomp
, E_Discriminant
, E_Component
) then
8595 if Component_Bit_Offset
(Pcomp
) /= No_Uint
8596 and then Known_Static_Esize
(Pcomp
)
8601 Component_Bit_Offset
(Pcomp
) + Esize
(Pcomp
) - 1);
8604 Next_Entity
(Pcomp
);
8610 -- All done if no component clauses
8612 CC
:= First
(Component_Clauses
(N
));
8618 -- If a tag is present, then create a component clause that places it
8619 -- at the start of the record (otherwise gigi may place it after other
8620 -- fields that have rep clauses).
8622 Fent
:= First_Entity
(Rectype
);
8624 if Nkind
(Fent
) = N_Defining_Identifier
8625 and then Chars
(Fent
) = Name_uTag
8627 Set_Component_Bit_Offset
(Fent
, Uint_0
);
8628 Set_Normalized_Position
(Fent
, Uint_0
);
8629 Set_Normalized_First_Bit
(Fent
, Uint_0
);
8630 Set_Normalized_Position_Max
(Fent
, Uint_0
);
8631 Init_Esize
(Fent
, System_Address_Size
);
8633 Set_Component_Clause
(Fent
,
8634 Make_Component_Clause
(Loc
,
8635 Component_Name
=> Make_Identifier
(Loc
, Name_uTag
),
8637 Position
=> Make_Integer_Literal
(Loc
, Uint_0
),
8638 First_Bit
=> Make_Integer_Literal
(Loc
, Uint_0
),
8640 Make_Integer_Literal
(Loc
,
8641 UI_From_Int
(System_Address_Size
))));
8643 Ccount
:= Ccount
+ 1;
8646 Max_Bit_So_Far
:= Uint_Minus_1
;
8647 Overlap_Check_Required
:= False;
8649 -- Process the component clauses
8651 while Present
(CC
) loop
8654 if Present
(Comp
) then
8655 Ccount
:= Ccount
+ 1;
8657 -- We need a full overlap check if record positions non-monotonic
8659 if Fbit
<= Max_Bit_So_Far
then
8660 Overlap_Check_Required
:= True;
8663 Max_Bit_So_Far
:= Lbit
;
8665 -- Check bit position out of range of specified size
8667 if Has_Size_Clause
(Rectype
)
8668 and then RM_Size
(Rectype
) <= Lbit
8671 ("bit number out of range of specified size",
8674 -- Check for overlap with tag component
8677 if Is_Tagged_Type
(Rectype
)
8678 and then Fbit
< System_Address_Size
8681 ("component overlaps tag field of&",
8682 Component_Name
(CC
), Rectype
);
8683 Overlap_Detected
:= True;
8691 -- Check parent overlap if component might overlap parent field
8693 if Present
(Tagged_Parent
) and then Fbit
<= Parent_Last_Bit
then
8694 Pcomp
:= First_Component_Or_Discriminant
(Tagged_Parent
);
8695 while Present
(Pcomp
) loop
8696 if not Is_Tag
(Pcomp
)
8697 and then Chars
(Pcomp
) /= Name_uParent
8699 Check_Component_Overlap
(Comp
, Pcomp
);
8702 Next_Component_Or_Discriminant
(Pcomp
);
8710 -- Now that we have processed all the component clauses, check for
8711 -- overlap. We have to leave this till last, since the components can
8712 -- appear in any arbitrary order in the representation clause.
8714 -- We do not need this check if all specified ranges were monotonic,
8715 -- as recorded by Overlap_Check_Required being False at this stage.
8717 -- This first section checks if there are any overlapping entries at
8718 -- all. It does this by sorting all entries and then seeing if there are
8719 -- any overlaps. If there are none, then that is decisive, but if there
8720 -- are overlaps, they may still be OK (they may result from fields in
8721 -- different variants).
8723 if Overlap_Check_Required
then
8724 Overlap_Check1
: declare
8726 OC_Fbit
: array (0 .. Ccount
) of Uint
;
8727 -- First-bit values for component clauses, the value is the offset
8728 -- of the first bit of the field from start of record. The zero
8729 -- entry is for use in sorting.
8731 OC_Lbit
: array (0 .. Ccount
) of Uint
;
8732 -- Last-bit values for component clauses, the value is the offset
8733 -- of the last bit of the field from start of record. The zero
8734 -- entry is for use in sorting.
8736 OC_Count
: Natural := 0;
8737 -- Count of entries in OC_Fbit and OC_Lbit
8739 function OC_Lt
(Op1
, Op2
: Natural) return Boolean;
8740 -- Compare routine for Sort
8742 procedure OC_Move
(From
: Natural; To
: Natural);
8743 -- Move routine for Sort
8745 package Sorting
is new GNAT
.Heap_Sort_G
(OC_Move
, OC_Lt
);
8751 function OC_Lt
(Op1
, Op2
: Natural) return Boolean is
8753 return OC_Fbit
(Op1
) < OC_Fbit
(Op2
);
8760 procedure OC_Move
(From
: Natural; To
: Natural) is
8762 OC_Fbit
(To
) := OC_Fbit
(From
);
8763 OC_Lbit
(To
) := OC_Lbit
(From
);
8766 -- Start of processing for Overlap_Check
8769 CC
:= First
(Component_Clauses
(N
));
8770 while Present
(CC
) loop
8772 -- Exclude component clause already marked in error
8774 if not Error_Posted
(CC
) then
8777 if Present
(Comp
) then
8778 OC_Count
:= OC_Count
+ 1;
8779 OC_Fbit
(OC_Count
) := Fbit
;
8780 OC_Lbit
(OC_Count
) := Lbit
;
8787 Sorting
.Sort
(OC_Count
);
8789 Overlap_Check_Required
:= False;
8790 for J
in 1 .. OC_Count
- 1 loop
8791 if OC_Lbit
(J
) >= OC_Fbit
(J
+ 1) then
8792 Overlap_Check_Required
:= True;
8799 -- If Overlap_Check_Required is still True, then we have to do the full
8800 -- scale overlap check, since we have at least two fields that do
8801 -- overlap, and we need to know if that is OK since they are in
8802 -- different variant, or whether we have a definite problem.
8804 if Overlap_Check_Required
then
8805 Overlap_Check2
: declare
8806 C1_Ent
, C2_Ent
: Entity_Id
;
8807 -- Entities of components being checked for overlap
8810 -- Component_List node whose Component_Items are being checked
8813 -- Component declaration for component being checked
8816 C1_Ent
:= First_Entity
(Base_Type
(Rectype
));
8818 -- Loop through all components in record. For each component check
8819 -- for overlap with any of the preceding elements on the component
8820 -- list containing the component and also, if the component is in
8821 -- a variant, check against components outside the case structure.
8822 -- This latter test is repeated recursively up the variant tree.
8824 Main_Component_Loop
: while Present
(C1_Ent
) loop
8825 if not Ekind_In
(C1_Ent
, E_Component
, E_Discriminant
) then
8826 goto Continue_Main_Component_Loop
;
8829 -- Skip overlap check if entity has no declaration node. This
8830 -- happens with discriminants in constrained derived types.
8831 -- Possibly we are missing some checks as a result, but that
8832 -- does not seem terribly serious.
8834 if No
(Declaration_Node
(C1_Ent
)) then
8835 goto Continue_Main_Component_Loop
;
8838 Clist
:= Parent
(List_Containing
(Declaration_Node
(C1_Ent
)));
8840 -- Loop through component lists that need checking. Check the
8841 -- current component list and all lists in variants above us.
8843 Component_List_Loop
: loop
8845 -- If derived type definition, go to full declaration
8846 -- If at outer level, check discriminants if there are any.
8848 if Nkind
(Clist
) = N_Derived_Type_Definition
then
8849 Clist
:= Parent
(Clist
);
8852 -- Outer level of record definition, check discriminants
8854 if Nkind_In
(Clist
, N_Full_Type_Declaration
,
8855 N_Private_Type_Declaration
)
8857 if Has_Discriminants
(Defining_Identifier
(Clist
)) then
8859 First_Discriminant
(Defining_Identifier
(Clist
));
8860 while Present
(C2_Ent
) loop
8861 exit when C1_Ent
= C2_Ent
;
8862 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
8863 Next_Discriminant
(C2_Ent
);
8867 -- Record extension case
8869 elsif Nkind
(Clist
) = N_Derived_Type_Definition
then
8872 -- Otherwise check one component list
8875 Citem
:= First
(Component_Items
(Clist
));
8876 while Present
(Citem
) loop
8877 if Nkind
(Citem
) = N_Component_Declaration
then
8878 C2_Ent
:= Defining_Identifier
(Citem
);
8879 exit when C1_Ent
= C2_Ent
;
8880 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
8887 -- Check for variants above us (the parent of the Clist can
8888 -- be a variant, in which case its parent is a variant part,
8889 -- and the parent of the variant part is a component list
8890 -- whose components must all be checked against the current
8891 -- component for overlap).
8893 if Nkind
(Parent
(Clist
)) = N_Variant
then
8894 Clist
:= Parent
(Parent
(Parent
(Clist
)));
8896 -- Check for possible discriminant part in record, this
8897 -- is treated essentially as another level in the
8898 -- recursion. For this case the parent of the component
8899 -- list is the record definition, and its parent is the
8900 -- full type declaration containing the discriminant
8903 elsif Nkind
(Parent
(Clist
)) = N_Record_Definition
then
8904 Clist
:= Parent
(Parent
((Clist
)));
8906 -- If neither of these two cases, we are at the top of
8910 exit Component_List_Loop
;
8912 end loop Component_List_Loop
;
8914 <<Continue_Main_Component_Loop
>>
8915 Next_Entity
(C1_Ent
);
8917 end loop Main_Component_Loop
;
8921 -- The following circuit deals with warning on record holes (gaps). We
8922 -- skip this check if overlap was detected, since it makes sense for the
8923 -- programmer to fix this illegality before worrying about warnings.
8925 if not Overlap_Detected
and Warn_On_Record_Holes
then
8926 Record_Hole_Check
: declare
8927 Decl
: constant Node_Id
:= Declaration_Node
(Base_Type
(Rectype
));
8928 -- Full declaration of record type
8930 procedure Check_Component_List
8934 -- Check component list CL for holes. The starting bit should be
8935 -- Sbit. which is zero for the main record component list and set
8936 -- appropriately for recursive calls for variants. DS is set to
8937 -- a list of discriminant specifications to be included in the
8938 -- consideration of components. It is No_List if none to consider.
8940 --------------------------
8941 -- Check_Component_List --
8942 --------------------------
8944 procedure Check_Component_List
8952 Compl
:= Integer (List_Length
(Component_Items
(CL
)));
8954 if DS
/= No_List
then
8955 Compl
:= Compl
+ Integer (List_Length
(DS
));
8959 Comps
: array (Natural range 0 .. Compl
) of Entity_Id
;
8960 -- Gather components (zero entry is for sort routine)
8962 Ncomps
: Natural := 0;
8963 -- Number of entries stored in Comps (starting at Comps (1))
8966 -- One component item or discriminant specification
8969 -- Starting bit for next component
8977 function Lt
(Op1
, Op2
: Natural) return Boolean;
8978 -- Compare routine for Sort
8980 procedure Move
(From
: Natural; To
: Natural);
8981 -- Move routine for Sort
8983 package Sorting
is new GNAT
.Heap_Sort_G
(Move
, Lt
);
8989 function Lt
(Op1
, Op2
: Natural) return Boolean is
8991 return Component_Bit_Offset
(Comps
(Op1
))
8993 Component_Bit_Offset
(Comps
(Op2
));
9000 procedure Move
(From
: Natural; To
: Natural) is
9002 Comps
(To
) := Comps
(From
);
9006 -- Gather discriminants into Comp
9008 if DS
/= No_List
then
9009 Citem
:= First
(DS
);
9010 while Present
(Citem
) loop
9011 if Nkind
(Citem
) = N_Discriminant_Specification
then
9013 Ent
: constant Entity_Id
:=
9014 Defining_Identifier
(Citem
);
9016 if Ekind
(Ent
) = E_Discriminant
then
9017 Ncomps
:= Ncomps
+ 1;
9018 Comps
(Ncomps
) := Ent
;
9027 -- Gather component entities into Comp
9029 Citem
:= First
(Component_Items
(CL
));
9030 while Present
(Citem
) loop
9031 if Nkind
(Citem
) = N_Component_Declaration
then
9032 Ncomps
:= Ncomps
+ 1;
9033 Comps
(Ncomps
) := Defining_Identifier
(Citem
);
9039 -- Now sort the component entities based on the first bit.
9040 -- Note we already know there are no overlapping components.
9042 Sorting
.Sort
(Ncomps
);
9044 -- Loop through entries checking for holes
9047 for J
in 1 .. Ncomps
loop
9049 Error_Msg_Uint_1
:= Component_Bit_Offset
(CEnt
) - Nbit
;
9051 if Error_Msg_Uint_1
> 0 then
9053 ("?H?^-bit gap before component&",
9054 Component_Name
(Component_Clause
(CEnt
)), CEnt
);
9057 Nbit
:= Component_Bit_Offset
(CEnt
) + Esize
(CEnt
);
9060 -- Process variant parts recursively if present
9062 if Present
(Variant_Part
(CL
)) then
9063 Variant
:= First
(Variants
(Variant_Part
(CL
)));
9064 while Present
(Variant
) loop
9065 Check_Component_List
9066 (Component_List
(Variant
), Nbit
, No_List
);
9071 end Check_Component_List
;
9073 -- Start of processing for Record_Hole_Check
9080 if Is_Tagged_Type
(Rectype
) then
9081 Sbit
:= UI_From_Int
(System_Address_Size
);
9086 if Nkind
(Decl
) = N_Full_Type_Declaration
9087 and then Nkind
(Type_Definition
(Decl
)) = N_Record_Definition
9089 Check_Component_List
9090 (Component_List
(Type_Definition
(Decl
)),
9092 Discriminant_Specifications
(Decl
));
9095 end Record_Hole_Check
;
9098 -- For records that have component clauses for all components, and whose
9099 -- size is less than or equal to 32, we need to know the size in the
9100 -- front end to activate possible packed array processing where the
9101 -- component type is a record.
9103 -- At this stage Hbit + 1 represents the first unused bit from all the
9104 -- component clauses processed, so if the component clauses are
9105 -- complete, then this is the length of the record.
9107 -- For records longer than System.Storage_Unit, and for those where not
9108 -- all components have component clauses, the back end determines the
9109 -- length (it may for example be appropriate to round up the size
9110 -- to some convenient boundary, based on alignment considerations, etc).
9112 if Unknown_RM_Size
(Rectype
) and then Hbit
+ 1 <= 32 then
9114 -- Nothing to do if at least one component has no component clause
9116 Comp
:= First_Component_Or_Discriminant
(Rectype
);
9117 while Present
(Comp
) loop
9118 exit when No
(Component_Clause
(Comp
));
9119 Next_Component_Or_Discriminant
(Comp
);
9122 -- If we fall out of loop, all components have component clauses
9123 -- and so we can set the size to the maximum value.
9126 Set_RM_Size
(Rectype
, Hbit
+ 1);
9129 end Check_Record_Representation_Clause
;
9135 procedure Check_Size
9139 Biased
: out Boolean)
9141 UT
: constant Entity_Id
:= Underlying_Type
(T
);
9147 -- Reject patently improper size values.
9149 if Is_Elementary_Type
(T
)
9150 and then Siz
> UI_From_Int
(Int
'Last)
9152 Error_Msg_N
("Size value too large for elementary type", N
);
9154 if Nkind
(Original_Node
(N
)) = N_Op_Expon
then
9156 ("\maybe '* was meant, rather than '*'*", Original_Node
(N
));
9160 -- Dismiss generic types
9162 if Is_Generic_Type
(T
)
9164 Is_Generic_Type
(UT
)
9166 Is_Generic_Type
(Root_Type
(UT
))
9170 -- Guard against previous errors
9172 elsif No
(UT
) or else UT
= Any_Type
then
9173 Check_Error_Detected
;
9176 -- Check case of bit packed array
9178 elsif Is_Array_Type
(UT
)
9179 and then Known_Static_Component_Size
(UT
)
9180 and then Is_Bit_Packed_Array
(UT
)
9188 Asiz
:= Component_Size
(UT
);
9189 Indx
:= First_Index
(UT
);
9191 Ityp
:= Etype
(Indx
);
9193 -- If non-static bound, then we are not in the business of
9194 -- trying to check the length, and indeed an error will be
9195 -- issued elsewhere, since sizes of non-static array types
9196 -- cannot be set implicitly or explicitly.
9198 if not Is_Static_Subtype
(Ityp
) then
9202 -- Otherwise accumulate next dimension
9204 Asiz
:= Asiz
* (Expr_Value
(Type_High_Bound
(Ityp
)) -
9205 Expr_Value
(Type_Low_Bound
(Ityp
)) +
9209 exit when No
(Indx
);
9216 Error_Msg_Uint_1
:= Asiz
;
9218 ("size for& too small, minimum allowed is ^", N
, T
);
9219 Set_Esize
(T
, Asiz
);
9220 Set_RM_Size
(T
, Asiz
);
9224 -- All other composite types are ignored
9226 elsif Is_Composite_Type
(UT
) then
9229 -- For fixed-point types, don't check minimum if type is not frozen,
9230 -- since we don't know all the characteristics of the type that can
9231 -- affect the size (e.g. a specified small) till freeze time.
9233 elsif Is_Fixed_Point_Type
(UT
)
9234 and then not Is_Frozen
(UT
)
9238 -- Cases for which a minimum check is required
9241 -- Ignore if specified size is correct for the type
9243 if Known_Esize
(UT
) and then Siz
= Esize
(UT
) then
9247 -- Otherwise get minimum size
9249 M
:= UI_From_Int
(Minimum_Size
(UT
));
9253 -- Size is less than minimum size, but one possibility remains
9254 -- that we can manage with the new size if we bias the type.
9256 M
:= UI_From_Int
(Minimum_Size
(UT
, Biased
=> True));
9259 Error_Msg_Uint_1
:= M
;
9261 ("size for& too small, minimum allowed is ^", N
, T
);
9271 --------------------------
9272 -- Freeze_Entity_Checks --
9273 --------------------------
9275 procedure Freeze_Entity_Checks
(N
: Node_Id
) is
9276 E
: constant Entity_Id
:= Entity
(N
);
9278 Non_Generic_Case
: constant Boolean := Nkind
(N
) = N_Freeze_Entity
;
9279 -- True in non-generic case. Some of the processing here is skipped
9280 -- for the generic case since it is not needed. Basically in the
9281 -- generic case, we only need to do stuff that might generate error
9282 -- messages or warnings.
9284 -- Remember that we are processing a freezing entity. Required to
9285 -- ensure correct decoration of internal entities associated with
9286 -- interfaces (see New_Overloaded_Entity).
9288 Inside_Freezing_Actions
:= Inside_Freezing_Actions
+ 1;
9290 -- For tagged types covering interfaces add internal entities that link
9291 -- the primitives of the interfaces with the primitives that cover them.
9292 -- Note: These entities were originally generated only when generating
9293 -- code because their main purpose was to provide support to initialize
9294 -- the secondary dispatch tables. They are now generated also when
9295 -- compiling with no code generation to provide ASIS the relationship
9296 -- between interface primitives and tagged type primitives. They are
9297 -- also used to locate primitives covering interfaces when processing
9298 -- generics (see Derive_Subprograms).
9300 -- This is not needed in the generic case
9302 if Ada_Version
>= Ada_2005
9303 and then Non_Generic_Case
9304 and then Ekind
(E
) = E_Record_Type
9305 and then Is_Tagged_Type
(E
)
9306 and then not Is_Interface
(E
)
9307 and then Has_Interfaces
(E
)
9309 -- This would be a good common place to call the routine that checks
9310 -- overriding of interface primitives (and thus factorize calls to
9311 -- Check_Abstract_Overriding located at different contexts in the
9312 -- compiler). However, this is not possible because it causes
9313 -- spurious errors in case of late overriding.
9315 Add_Internal_Interface_Entities
(E
);
9320 if Ekind
(E
) = E_Record_Type
9321 and then Is_CPP_Class
(E
)
9322 and then Is_Tagged_Type
(E
)
9323 and then Tagged_Type_Expansion
9325 if CPP_Num_Prims
(E
) = 0 then
9327 -- If the CPP type has user defined components then it must import
9328 -- primitives from C++. This is required because if the C++ class
9329 -- has no primitives then the C++ compiler does not added the _tag
9330 -- component to the type.
9332 if First_Entity
(E
) /= Last_Entity
(E
) then
9334 ("'C'P'P type must import at least one primitive from C++??",
9339 -- Check that all its primitives are abstract or imported from C++.
9340 -- Check also availability of the C++ constructor.
9343 Has_Constructors
: constant Boolean := Has_CPP_Constructors
(E
);
9345 Error_Reported
: Boolean := False;
9349 Elmt
:= First_Elmt
(Primitive_Operations
(E
));
9350 while Present
(Elmt
) loop
9351 Prim
:= Node
(Elmt
);
9353 if Comes_From_Source
(Prim
) then
9354 if Is_Abstract_Subprogram
(Prim
) then
9357 elsif not Is_Imported
(Prim
)
9358 or else Convention
(Prim
) /= Convention_CPP
9361 ("primitives of 'C'P'P types must be imported from C++ "
9362 & "or abstract??", Prim
);
9364 elsif not Has_Constructors
9365 and then not Error_Reported
9367 Error_Msg_Name_1
:= Chars
(E
);
9369 ("??'C'P'P constructor required for type %", Prim
);
9370 Error_Reported
:= True;
9379 -- Check Ada derivation of CPP type
9381 if Expander_Active
-- why? losing errors in -gnatc mode???
9382 and then Tagged_Type_Expansion
9383 and then Ekind
(E
) = E_Record_Type
9384 and then Etype
(E
) /= E
9385 and then Is_CPP_Class
(Etype
(E
))
9386 and then CPP_Num_Prims
(Etype
(E
)) > 0
9387 and then not Is_CPP_Class
(E
)
9388 and then not Has_CPP_Constructors
(Etype
(E
))
9390 -- If the parent has C++ primitives but it has no constructor then
9391 -- check that all the primitives are overridden in this derivation;
9392 -- otherwise the constructor of the parent is needed to build the
9400 Elmt
:= First_Elmt
(Primitive_Operations
(E
));
9401 while Present
(Elmt
) loop
9402 Prim
:= Node
(Elmt
);
9404 if not Is_Abstract_Subprogram
(Prim
)
9405 and then No
(Interface_Alias
(Prim
))
9406 and then Find_Dispatching_Type
(Ultimate_Alias
(Prim
)) /= E
9408 Error_Msg_Name_1
:= Chars
(Etype
(E
));
9410 ("'C'P'P constructor required for parent type %", E
);
9419 Inside_Freezing_Actions
:= Inside_Freezing_Actions
- 1;
9421 -- If we have a type with predicates, build predicate function. This
9422 -- is not needed in the generic casee
9424 if Non_Generic_Case
and then Is_Type
(E
) and then Has_Predicates
(E
) then
9425 Build_Predicate_Functions
(E
, N
);
9428 -- If type has delayed aspects, this is where we do the preanalysis at
9429 -- the freeze point, as part of the consistent visibility check. Note
9430 -- that this must be done after calling Build_Predicate_Functions or
9431 -- Build_Invariant_Procedure since these subprograms fix occurrences of
9432 -- the subtype name in the saved expression so that they will not cause
9433 -- trouble in the preanalysis.
9435 -- This is also not needed in the generic case
9438 and then Has_Delayed_Aspects
(E
)
9439 and then Scope
(E
) = Current_Scope
9441 -- Retrieve the visibility to the discriminants in order to properly
9442 -- analyze the aspects.
9444 Push_Scope_And_Install_Discriminants
(E
);
9450 -- Look for aspect specification entries for this entity
9452 Ritem
:= First_Rep_Item
(E
);
9453 while Present
(Ritem
) loop
9454 if Nkind
(Ritem
) = N_Aspect_Specification
9455 and then Entity
(Ritem
) = E
9456 and then Is_Delayed_Aspect
(Ritem
)
9458 Check_Aspect_At_Freeze_Point
(Ritem
);
9461 Next_Rep_Item
(Ritem
);
9465 Uninstall_Discriminants_And_Pop_Scope
(E
);
9468 -- For a record type, deal with variant parts. This has to be delayed
9469 -- to this point, because of the issue of statically precicated
9470 -- subtypes, which we have to ensure are frozen before checking
9471 -- choices, since we need to have the static choice list set.
9473 if Is_Record_Type
(E
) then
9474 Check_Variant_Part
: declare
9475 D
: constant Node_Id
:= Declaration_Node
(E
);
9480 Others_Present
: Boolean;
9481 pragma Warnings
(Off
, Others_Present
);
9482 -- Indicates others present, not used in this case
9484 procedure Non_Static_Choice_Error
(Choice
: Node_Id
);
9485 -- Error routine invoked by the generic instantiation below when
9486 -- the variant part has a non static choice.
9488 procedure Process_Declarations
(Variant
: Node_Id
);
9489 -- Processes declarations associated with a variant. We analyzed
9490 -- the declarations earlier (in Sem_Ch3.Analyze_Variant_Part),
9491 -- but we still need the recursive call to Check_Choices for any
9492 -- nested variant to get its choices properly processed. This is
9493 -- also where we expand out the choices if expansion is active.
9495 package Variant_Choices_Processing
is new
9496 Generic_Check_Choices
9497 (Process_Empty_Choice
=> No_OP
,
9498 Process_Non_Static_Choice
=> Non_Static_Choice_Error
,
9499 Process_Associated_Node
=> Process_Declarations
);
9500 use Variant_Choices_Processing
;
9502 -----------------------------
9503 -- Non_Static_Choice_Error --
9504 -----------------------------
9506 procedure Non_Static_Choice_Error
(Choice
: Node_Id
) is
9508 Flag_Non_Static_Expr
9509 ("choice given in variant part is not static!", Choice
);
9510 end Non_Static_Choice_Error
;
9512 --------------------------
9513 -- Process_Declarations --
9514 --------------------------
9516 procedure Process_Declarations
(Variant
: Node_Id
) is
9517 CL
: constant Node_Id
:= Component_List
(Variant
);
9521 -- Check for static predicate present in this variant
9523 if Has_SP_Choice
(Variant
) then
9525 -- Here we expand. You might expect to find this call in
9526 -- Expand_N_Variant_Part, but that is called when we first
9527 -- see the variant part, and we cannot do this expansion
9528 -- earlier than the freeze point, since for statically
9529 -- predicated subtypes, the predicate is not known till
9530 -- the freeze point.
9532 -- Furthermore, we do this expansion even if the expander
9533 -- is not active, because other semantic processing, e.g.
9534 -- for aggregates, requires the expanded list of choices.
9536 -- If the expander is not active, then we can't just clobber
9537 -- the list since it would invalidate the ASIS -gnatct tree.
9538 -- So we have to rewrite the variant part with a Rewrite
9539 -- call that replaces it with a copy and clobber the copy.
9541 if not Expander_Active
then
9543 NewV
: constant Node_Id
:= New_Copy
(Variant
);
9545 Set_Discrete_Choices
9546 (NewV
, New_Copy_List
(Discrete_Choices
(Variant
)));
9547 Rewrite
(Variant
, NewV
);
9551 Expand_Static_Predicates_In_Choices
(Variant
);
9554 -- We don't need to worry about the declarations in the variant
9555 -- (since they were analyzed by Analyze_Choices when we first
9556 -- encountered the variant), but we do need to take care of
9557 -- expansion of any nested variants.
9559 if not Null_Present
(CL
) then
9560 VP
:= Variant_Part
(CL
);
9562 if Present
(VP
) then
9564 (VP
, Variants
(VP
), Etype
(Name
(VP
)), Others_Present
);
9567 end Process_Declarations
;
9569 -- Start of processing for Check_Variant_Part
9572 -- Find component list
9576 if Nkind
(D
) = N_Full_Type_Declaration
then
9577 T
:= Type_Definition
(D
);
9579 if Nkind
(T
) = N_Record_Definition
then
9580 C
:= Component_List
(T
);
9582 elsif Nkind
(T
) = N_Derived_Type_Definition
9583 and then Present
(Record_Extension_Part
(T
))
9585 C
:= Component_List
(Record_Extension_Part
(T
));
9589 -- Case of variant part present
9591 if Present
(C
) and then Present
(Variant_Part
(C
)) then
9592 VP
:= Variant_Part
(C
);
9597 (VP
, Variants
(VP
), Etype
(Name
(VP
)), Others_Present
);
9599 -- If the last variant does not contain the Others choice,
9600 -- replace it with an N_Others_Choice node since Gigi always
9601 -- wants an Others. Note that we do not bother to call Analyze
9602 -- on the modified variant part, since its only effect would be
9603 -- to compute the Others_Discrete_Choices node laboriously, and
9604 -- of course we already know the list of choices corresponding
9605 -- to the others choice (it's the list we're replacing).
9607 -- We only want to do this if the expander is active, since
9608 -- we do not want to clobber the ASIS tree.
9610 if Expander_Active
then
9612 Last_Var
: constant Node_Id
:=
9613 Last_Non_Pragma
(Variants
(VP
));
9615 Others_Node
: Node_Id
;
9618 if Nkind
(First
(Discrete_Choices
(Last_Var
))) /=
9621 Others_Node
:= Make_Others_Choice
(Sloc
(Last_Var
));
9622 Set_Others_Discrete_Choices
9623 (Others_Node
, Discrete_Choices
(Last_Var
));
9624 Set_Discrete_Choices
9625 (Last_Var
, New_List
(Others_Node
));
9630 end Check_Variant_Part
;
9632 end Freeze_Entity_Checks
;
9634 -------------------------
9635 -- Get_Alignment_Value --
9636 -------------------------
9638 function Get_Alignment_Value
(Expr
: Node_Id
) return Uint
is
9639 Align
: constant Uint
:= Static_Integer
(Expr
);
9642 if Align
= No_Uint
then
9645 elsif Align
<= 0 then
9646 Error_Msg_N
("alignment value must be positive", Expr
);
9650 for J
in Int
range 0 .. 64 loop
9652 M
: constant Uint
:= Uint_2
** J
;
9655 exit when M
= Align
;
9659 ("alignment value must be power of 2", Expr
);
9667 end Get_Alignment_Value
;
9669 -------------------------------------
9670 -- Inherit_Aspects_At_Freeze_Point --
9671 -------------------------------------
9673 procedure Inherit_Aspects_At_Freeze_Point
(Typ
: Entity_Id
) is
9674 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9675 (Rep_Item
: Node_Id
) return Boolean;
9676 -- This routine checks if Rep_Item is either a pragma or an aspect
9677 -- specification node whose correponding pragma (if any) is present in
9678 -- the Rep Item chain of the entity it has been specified to.
9680 --------------------------------------------------
9681 -- Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item --
9682 --------------------------------------------------
9684 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9685 (Rep_Item
: Node_Id
) return Boolean
9688 return Nkind
(Rep_Item
) = N_Pragma
9689 or else Present_In_Rep_Item
9690 (Entity
(Rep_Item
), Aspect_Rep_Item
(Rep_Item
));
9691 end Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
;
9693 -- Start of processing for Inherit_Aspects_At_Freeze_Point
9696 -- A representation item is either subtype-specific (Size and Alignment
9697 -- clauses) or type-related (all others). Subtype-specific aspects may
9698 -- differ for different subtypes of the same type (RM 13.1.8).
9700 -- A derived type inherits each type-related representation aspect of
9701 -- its parent type that was directly specified before the declaration of
9702 -- the derived type (RM 13.1.15).
9704 -- A derived subtype inherits each subtype-specific representation
9705 -- aspect of its parent subtype that was directly specified before the
9706 -- declaration of the derived type (RM 13.1.15).
9708 -- The general processing involves inheriting a representation aspect
9709 -- from a parent type whenever the first rep item (aspect specification,
9710 -- attribute definition clause, pragma) corresponding to the given
9711 -- representation aspect in the rep item chain of Typ, if any, isn't
9712 -- directly specified to Typ but to one of its parents.
9714 -- ??? Note that, for now, just a limited number of representation
9715 -- aspects have been inherited here so far. Many of them are
9716 -- still inherited in Sem_Ch3. This will be fixed soon. Here is
9717 -- a non- exhaustive list of aspects that likely also need to
9718 -- be moved to this routine: Alignment, Component_Alignment,
9719 -- Component_Size, Machine_Radix, Object_Size, Pack, Predicates,
9720 -- Preelaborable_Initialization, RM_Size and Small.
9722 if Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
then
9728 if not Has_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
, False)
9729 and then Has_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
)
9730 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9731 (Get_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
))
9733 Set_Is_Ada_2005_Only
(Typ
);
9738 if not Has_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
, False)
9739 and then Has_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
)
9740 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9741 (Get_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
))
9743 Set_Is_Ada_2012_Only
(Typ
);
9748 if not Has_Rep_Item
(Typ
, Name_Atomic
, Name_Shared
, False)
9749 and then Has_Rep_Pragma
(Typ
, Name_Atomic
, Name_Shared
)
9750 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9751 (Get_Rep_Item
(Typ
, Name_Atomic
, Name_Shared
))
9753 Set_Is_Atomic
(Typ
);
9754 Set_Treat_As_Volatile
(Typ
);
9755 Set_Is_Volatile
(Typ
);
9758 -- Default_Component_Value
9760 if Is_Array_Type
(Typ
)
9761 and then Is_Base_Type
(Typ
)
9762 and then Has_Rep_Item
(Typ
, Name_Default_Component_Value
, False)
9763 and then Has_Rep_Item
(Typ
, Name_Default_Component_Value
)
9765 Set_Default_Aspect_Component_Value
(Typ
,
9766 Default_Aspect_Component_Value
9767 (Entity
(Get_Rep_Item
(Typ
, Name_Default_Component_Value
))));
9772 if Is_Scalar_Type
(Typ
)
9773 and then Is_Base_Type
(Typ
)
9774 and then Has_Rep_Item
(Typ
, Name_Default_Value
, False)
9775 and then Has_Rep_Item
(Typ
, Name_Default_Value
)
9777 Set_Default_Aspect_Value
(Typ
,
9778 Default_Aspect_Value
9779 (Entity
(Get_Rep_Item
(Typ
, Name_Default_Value
))));
9784 if not Has_Rep_Item
(Typ
, Name_Discard_Names
, False)
9785 and then Has_Rep_Item
(Typ
, Name_Discard_Names
)
9786 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9787 (Get_Rep_Item
(Typ
, Name_Discard_Names
))
9789 Set_Discard_Names
(Typ
);
9794 if not Has_Rep_Item
(Typ
, Name_Invariant
, False)
9795 and then Has_Rep_Item
(Typ
, Name_Invariant
)
9796 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9797 (Get_Rep_Item
(Typ
, Name_Invariant
))
9799 Set_Has_Invariants
(Typ
);
9801 if Class_Present
(Get_Rep_Item
(Typ
, Name_Invariant
)) then
9802 Set_Has_Inheritable_Invariants
(Typ
);
9808 if not Has_Rep_Item
(Typ
, Name_Volatile
, False)
9809 and then Has_Rep_Item
(Typ
, Name_Volatile
)
9810 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9811 (Get_Rep_Item
(Typ
, Name_Volatile
))
9813 Set_Treat_As_Volatile
(Typ
);
9814 Set_Is_Volatile
(Typ
);
9817 -- Inheritance for derived types only
9819 if Is_Derived_Type
(Typ
) then
9821 Bas_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
9822 Imp_Bas_Typ
: constant Entity_Id
:= Implementation_Base_Type
(Typ
);
9825 -- Atomic_Components
9827 if not Has_Rep_Item
(Typ
, Name_Atomic_Components
, False)
9828 and then Has_Rep_Item
(Typ
, Name_Atomic_Components
)
9829 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9830 (Get_Rep_Item
(Typ
, Name_Atomic_Components
))
9832 Set_Has_Atomic_Components
(Imp_Bas_Typ
);
9835 -- Volatile_Components
9837 if not Has_Rep_Item
(Typ
, Name_Volatile_Components
, False)
9838 and then Has_Rep_Item
(Typ
, Name_Volatile_Components
)
9839 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9840 (Get_Rep_Item
(Typ
, Name_Volatile_Components
))
9842 Set_Has_Volatile_Components
(Imp_Bas_Typ
);
9845 -- Finalize_Storage_Only.
9847 if not Has_Rep_Pragma
(Typ
, Name_Finalize_Storage_Only
, False)
9848 and then Has_Rep_Pragma
(Typ
, Name_Finalize_Storage_Only
)
9850 Set_Finalize_Storage_Only
(Bas_Typ
);
9853 -- Universal_Aliasing
9855 if not Has_Rep_Item
(Typ
, Name_Universal_Aliasing
, False)
9856 and then Has_Rep_Item
(Typ
, Name_Universal_Aliasing
)
9857 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
9858 (Get_Rep_Item
(Typ
, Name_Universal_Aliasing
))
9860 Set_Universal_Aliasing
(Imp_Bas_Typ
);
9863 -- Record type specific aspects
9865 if Is_Record_Type
(Typ
) then
9869 if not Has_Rep_Item
(Typ
, Name_Bit_Order
, False)
9870 and then Has_Rep_Item
(Typ
, Name_Bit_Order
)
9872 Set_Reverse_Bit_Order
(Bas_Typ
,
9873 Reverse_Bit_Order
(Entity
(Name
9874 (Get_Rep_Item
(Typ
, Name_Bit_Order
)))));
9877 -- Scalar_Storage_Order
9879 if not Has_Rep_Item
(Typ
, Name_Scalar_Storage_Order
, False)
9880 and then Has_Rep_Item
(Typ
, Name_Scalar_Storage_Order
)
9882 Set_Reverse_Storage_Order
(Bas_Typ
,
9883 Reverse_Storage_Order
(Entity
(Name
9884 (Get_Rep_Item
(Typ
, Name_Scalar_Storage_Order
)))));
9889 end Inherit_Aspects_At_Freeze_Point
;
9895 procedure Initialize
is
9897 Address_Clause_Checks
.Init
;
9898 Independence_Checks
.Init
;
9899 Unchecked_Conversions
.Init
;
9902 -------------------------
9903 -- Is_Operational_Item --
9904 -------------------------
9906 function Is_Operational_Item
(N
: Node_Id
) return Boolean is
9908 if Nkind
(N
) /= N_Attribute_Definition_Clause
then
9913 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Chars
(N
));
9915 return Id
= Attribute_Input
9916 or else Id
= Attribute_Output
9917 or else Id
= Attribute_Read
9918 or else Id
= Attribute_Write
9919 or else Id
= Attribute_External_Tag
;
9922 end Is_Operational_Item
;
9928 function Minimum_Size
9930 Biased
: Boolean := False) return Nat
9932 Lo
: Uint
:= No_Uint
;
9933 Hi
: Uint
:= No_Uint
;
9934 LoR
: Ureal
:= No_Ureal
;
9935 HiR
: Ureal
:= No_Ureal
;
9936 LoSet
: Boolean := False;
9937 HiSet
: Boolean := False;
9941 R_Typ
: constant Entity_Id
:= Root_Type
(T
);
9944 -- If bad type, return 0
9946 if T
= Any_Type
then
9949 -- For generic types, just return zero. There cannot be any legitimate
9950 -- need to know such a size, but this routine may be called with a
9951 -- generic type as part of normal processing.
9953 elsif Is_Generic_Type
(R_Typ
)
9954 or else R_Typ
= Any_Type
9958 -- Access types. Normally an access type cannot have a size smaller
9959 -- than the size of System.Address. The exception is on VMS, where
9960 -- we have short and long addresses, and it is possible for an access
9961 -- type to have a short address size (and thus be less than the size
9962 -- of System.Address itself). We simply skip the check for VMS, and
9963 -- leave it to the back end to do the check.
9965 elsif Is_Access_Type
(T
) then
9966 if OpenVMS_On_Target
then
9969 return System_Address_Size
;
9972 -- Floating-point types
9974 elsif Is_Floating_Point_Type
(T
) then
9975 return UI_To_Int
(Esize
(R_Typ
));
9979 elsif Is_Discrete_Type
(T
) then
9981 -- The following loop is looking for the nearest compile time known
9982 -- bounds following the ancestor subtype chain. The idea is to find
9983 -- the most restrictive known bounds information.
9987 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
9992 if Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
)) then
9993 Lo
:= Expr_Rep_Value
(Type_Low_Bound
(Ancest
));
10000 if Compile_Time_Known_Value
(Type_High_Bound
(Ancest
)) then
10001 Hi
:= Expr_Rep_Value
(Type_High_Bound
(Ancest
));
10007 Ancest
:= Ancestor_Subtype
(Ancest
);
10009 if No
(Ancest
) then
10010 Ancest
:= Base_Type
(T
);
10012 if Is_Generic_Type
(Ancest
) then
10018 -- Fixed-point types. We can't simply use Expr_Value to get the
10019 -- Corresponding_Integer_Value values of the bounds, since these do not
10020 -- get set till the type is frozen, and this routine can be called
10021 -- before the type is frozen. Similarly the test for bounds being static
10022 -- needs to include the case where we have unanalyzed real literals for
10023 -- the same reason.
10025 elsif Is_Fixed_Point_Type
(T
) then
10027 -- The following loop is looking for the nearest compile time known
10028 -- bounds following the ancestor subtype chain. The idea is to find
10029 -- the most restrictive known bounds information.
10033 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
10037 -- Note: In the following two tests for LoSet and HiSet, it may
10038 -- seem redundant to test for N_Real_Literal here since normally
10039 -- one would assume that the test for the value being known at
10040 -- compile time includes this case. However, there is a glitch.
10041 -- If the real literal comes from folding a non-static expression,
10042 -- then we don't consider any non- static expression to be known
10043 -- at compile time if we are in configurable run time mode (needed
10044 -- in some cases to give a clearer definition of what is and what
10045 -- is not accepted). So the test is indeed needed. Without it, we
10046 -- would set neither Lo_Set nor Hi_Set and get an infinite loop.
10049 if Nkind
(Type_Low_Bound
(Ancest
)) = N_Real_Literal
10050 or else Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
))
10052 LoR
:= Expr_Value_R
(Type_Low_Bound
(Ancest
));
10059 if Nkind
(Type_High_Bound
(Ancest
)) = N_Real_Literal
10060 or else Compile_Time_Known_Value
(Type_High_Bound
(Ancest
))
10062 HiR
:= Expr_Value_R
(Type_High_Bound
(Ancest
));
10068 Ancest
:= Ancestor_Subtype
(Ancest
);
10070 if No
(Ancest
) then
10071 Ancest
:= Base_Type
(T
);
10073 if Is_Generic_Type
(Ancest
) then
10079 Lo
:= UR_To_Uint
(LoR
/ Small_Value
(T
));
10080 Hi
:= UR_To_Uint
(HiR
/ Small_Value
(T
));
10082 -- No other types allowed
10085 raise Program_Error
;
10088 -- Fall through with Hi and Lo set. Deal with biased case
10091 and then not Is_Fixed_Point_Type
(T
)
10092 and then not (Is_Enumeration_Type
(T
)
10093 and then Has_Non_Standard_Rep
(T
)))
10094 or else Has_Biased_Representation
(T
)
10100 -- Signed case. Note that we consider types like range 1 .. -1 to be
10101 -- signed for the purpose of computing the size, since the bounds have
10102 -- to be accommodated in the base type.
10104 if Lo
< 0 or else Hi
< 0 then
10108 -- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1))
10109 -- Note that we accommodate the case where the bounds cross. This
10110 -- can happen either because of the way the bounds are declared
10111 -- or because of the algorithm in Freeze_Fixed_Point_Type.
10125 -- If both bounds are positive, make sure that both are represen-
10126 -- table in the case where the bounds are crossed. This can happen
10127 -- either because of the way the bounds are declared, or because of
10128 -- the algorithm in Freeze_Fixed_Point_Type.
10134 -- S = size, (can accommodate 0 .. (2**size - 1))
10137 while Hi
>= Uint_2
** S
loop
10145 ---------------------------
10146 -- New_Stream_Subprogram --
10147 ---------------------------
10149 procedure New_Stream_Subprogram
10153 Nam
: TSS_Name_Type
)
10155 Loc
: constant Source_Ptr
:= Sloc
(N
);
10156 Sname
: constant Name_Id
:= Make_TSS_Name
(Base_Type
(Ent
), Nam
);
10157 Subp_Id
: Entity_Id
;
10158 Subp_Decl
: Node_Id
;
10162 Defer_Declaration
: constant Boolean :=
10163 Is_Tagged_Type
(Ent
) or else Is_Private_Type
(Ent
);
10164 -- For a tagged type, there is a declaration for each stream attribute
10165 -- at the freeze point, and we must generate only a completion of this
10166 -- declaration. We do the same for private types, because the full view
10167 -- might be tagged. Otherwise we generate a declaration at the point of
10168 -- the attribute definition clause.
10170 function Build_Spec
return Node_Id
;
10171 -- Used for declaration and renaming declaration, so that this is
10172 -- treated as a renaming_as_body.
10178 function Build_Spec
return Node_Id
is
10179 Out_P
: constant Boolean := (Nam
= TSS_Stream_Read
);
10182 T_Ref
: constant Node_Id
:= New_Reference_To
(Etyp
, Loc
);
10185 Subp_Id
:= Make_Defining_Identifier
(Loc
, Sname
);
10187 -- S : access Root_Stream_Type'Class
10189 Formals
:= New_List
(
10190 Make_Parameter_Specification
(Loc
,
10191 Defining_Identifier
=>
10192 Make_Defining_Identifier
(Loc
, Name_S
),
10194 Make_Access_Definition
(Loc
,
10197 Designated_Type
(Etype
(F
)), Loc
))));
10199 if Nam
= TSS_Stream_Input
then
10201 Make_Function_Specification
(Loc
,
10202 Defining_Unit_Name
=> Subp_Id
,
10203 Parameter_Specifications
=> Formals
,
10204 Result_Definition
=> T_Ref
);
10208 Append_To
(Formals
,
10209 Make_Parameter_Specification
(Loc
,
10210 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_V
),
10211 Out_Present
=> Out_P
,
10212 Parameter_Type
=> T_Ref
));
10215 Make_Procedure_Specification
(Loc
,
10216 Defining_Unit_Name
=> Subp_Id
,
10217 Parameter_Specifications
=> Formals
);
10223 -- Start of processing for New_Stream_Subprogram
10226 F
:= First_Formal
(Subp
);
10228 if Ekind
(Subp
) = E_Procedure
then
10229 Etyp
:= Etype
(Next_Formal
(F
));
10231 Etyp
:= Etype
(Subp
);
10234 -- Prepare subprogram declaration and insert it as an action on the
10235 -- clause node. The visibility for this entity is used to test for
10236 -- visibility of the attribute definition clause (in the sense of
10237 -- 8.3(23) as amended by AI-195).
10239 if not Defer_Declaration
then
10241 Make_Subprogram_Declaration
(Loc
,
10242 Specification
=> Build_Spec
);
10244 -- For a tagged type, there is always a visible declaration for each
10245 -- stream TSS (it is a predefined primitive operation), and the
10246 -- completion of this declaration occurs at the freeze point, which is
10247 -- not always visible at places where the attribute definition clause is
10248 -- visible. So, we create a dummy entity here for the purpose of
10249 -- tracking the visibility of the attribute definition clause itself.
10253 Make_Defining_Identifier
(Loc
, New_External_Name
(Sname
, 'V'));
10255 Make_Object_Declaration
(Loc
,
10256 Defining_Identifier
=> Subp_Id
,
10257 Object_Definition
=> New_Occurrence_Of
(Standard_Boolean
, Loc
));
10260 Insert_Action
(N
, Subp_Decl
);
10261 Set_Entity
(N
, Subp_Id
);
10264 Make_Subprogram_Renaming_Declaration
(Loc
,
10265 Specification
=> Build_Spec
,
10266 Name
=> New_Reference_To
(Subp
, Loc
));
10268 if Defer_Declaration
then
10269 Set_TSS
(Base_Type
(Ent
), Subp_Id
);
10271 Insert_Action
(N
, Subp_Decl
);
10272 Copy_TSS
(Subp_Id
, Base_Type
(Ent
));
10274 end New_Stream_Subprogram
;
10276 ------------------------
10277 -- Rep_Item_Too_Early --
10278 ------------------------
10280 function Rep_Item_Too_Early
(T
: Entity_Id
; N
: Node_Id
) return Boolean is
10282 -- Cannot apply non-operational rep items to generic types
10284 if Is_Operational_Item
(N
) then
10288 and then Is_Generic_Type
(Root_Type
(T
))
10290 Error_Msg_N
("representation item not allowed for generic type", N
);
10294 -- Otherwise check for incomplete type
10296 if Is_Incomplete_Or_Private_Type
(T
)
10297 and then No
(Underlying_Type
(T
))
10299 (Nkind
(N
) /= N_Pragma
10300 or else Get_Pragma_Id
(N
) /= Pragma_Import
)
10303 ("representation item must be after full type declaration", N
);
10306 -- If the type has incomplete components, a representation clause is
10307 -- illegal but stream attributes and Convention pragmas are correct.
10309 elsif Has_Private_Component
(T
) then
10310 if Nkind
(N
) = N_Pragma
then
10315 ("representation item must appear after type is fully defined",
10322 end Rep_Item_Too_Early
;
10324 -----------------------
10325 -- Rep_Item_Too_Late --
10326 -----------------------
10328 function Rep_Item_Too_Late
10331 FOnly
: Boolean := False) return Boolean
10334 Parent_Type
: Entity_Id
;
10336 procedure Too_Late
;
10337 -- Output the too late message. Note that this is not considered a
10338 -- serious error, since the effect is simply that we ignore the
10339 -- representation clause in this case.
10345 procedure Too_Late
is
10347 -- Other compilers seem more relaxed about rep items appearing too
10348 -- late. Since analysis tools typically don't care about rep items
10349 -- anyway, no reason to be too strict about this.
10351 if not Relaxed_RM_Semantics
then
10352 Error_Msg_N
("|representation item appears too late!", N
);
10356 -- Start of processing for Rep_Item_Too_Late
10359 -- First make sure entity is not frozen (RM 13.1(9))
10363 -- Exclude imported types, which may be frozen if they appear in a
10364 -- representation clause for a local type.
10366 and then not From_Limited_With
(T
)
10368 -- Exclude generated entities (not coming from source). The common
10369 -- case is when we generate a renaming which prematurely freezes the
10370 -- renamed internal entity, but we still want to be able to set copies
10371 -- of attribute values such as Size/Alignment.
10373 and then Comes_From_Source
(T
)
10376 S
:= First_Subtype
(T
);
10378 if Present
(Freeze_Node
(S
)) then
10380 ("??no more representation items for }", Freeze_Node
(S
), S
);
10385 -- Check for case of non-tagged derived type whose parent either has
10386 -- primitive operations, or is a by reference type (RM 13.1(10)).
10390 and then Is_Derived_Type
(T
)
10391 and then not Is_Tagged_Type
(T
)
10393 Parent_Type
:= Etype
(Base_Type
(T
));
10395 if Has_Primitive_Operations
(Parent_Type
) then
10398 ("primitive operations already defined for&!", N
, Parent_Type
);
10401 elsif Is_By_Reference_Type
(Parent_Type
) then
10404 ("parent type & is a by reference type!", N
, Parent_Type
);
10409 -- No error, link item into head of chain of rep items for the entity,
10410 -- but avoid chaining if we have an overloadable entity, and the pragma
10411 -- is one that can apply to multiple overloaded entities.
10413 if Is_Overloadable
(T
) and then Nkind
(N
) = N_Pragma
then
10415 Pname
: constant Name_Id
:= Pragma_Name
(N
);
10417 if Nam_In
(Pname
, Name_Convention
, Name_Import
, Name_Export
,
10418 Name_External
, Name_Interface
)
10425 Record_Rep_Item
(T
, N
);
10427 end Rep_Item_Too_Late
;
10429 -------------------------------------
10430 -- Replace_Type_References_Generic --
10431 -------------------------------------
10433 procedure Replace_Type_References_Generic
(N
: Node_Id
; TName
: Name_Id
) is
10435 function Replace_Node
(N
: Node_Id
) return Traverse_Result
;
10436 -- Processes a single node in the traversal procedure below, checking
10437 -- if node N should be replaced, and if so, doing the replacement.
10439 procedure Replace_Type_Refs
is new Traverse_Proc
(Replace_Node
);
10440 -- This instantiation provides the body of Replace_Type_References
10446 function Replace_Node
(N
: Node_Id
) return Traverse_Result
is
10451 -- Case of identifier
10453 if Nkind
(N
) = N_Identifier
then
10455 -- If not the type name, all done with this node
10457 if Chars
(N
) /= TName
then
10460 -- Otherwise do the replacement and we are done with this node
10463 Replace_Type_Reference
(N
);
10467 -- Case of selected component (which is what a qualification
10468 -- looks like in the unanalyzed tree, which is what we have.
10470 elsif Nkind
(N
) = N_Selected_Component
then
10472 -- If selector name is not our type, keeping going (we might
10473 -- still have an occurrence of the type in the prefix).
10475 if Nkind
(Selector_Name
(N
)) /= N_Identifier
10476 or else Chars
(Selector_Name
(N
)) /= TName
10480 -- Selector name is our type, check qualification
10483 -- Loop through scopes and prefixes, doing comparison
10485 S
:= Current_Scope
;
10488 -- Continue if no more scopes or scope with no name
10490 if No
(S
) or else Nkind
(S
) not in N_Has_Chars
then
10494 -- Do replace if prefix is an identifier matching the
10495 -- scope that we are currently looking at.
10497 if Nkind
(P
) = N_Identifier
10498 and then Chars
(P
) = Chars
(S
)
10500 Replace_Type_Reference
(N
);
10504 -- Go check scope above us if prefix is itself of the
10505 -- form of a selected component, whose selector matches
10506 -- the scope we are currently looking at.
10508 if Nkind
(P
) = N_Selected_Component
10509 and then Nkind
(Selector_Name
(P
)) = N_Identifier
10510 and then Chars
(Selector_Name
(P
)) = Chars
(S
)
10515 -- For anything else, we don't have a match, so keep on
10516 -- going, there are still some weird cases where we may
10517 -- still have a replacement within the prefix.
10525 -- Continue for any other node kind
10533 Replace_Type_Refs
(N
);
10534 end Replace_Type_References_Generic
;
10536 -------------------------
10537 -- Same_Representation --
10538 -------------------------
10540 function Same_Representation
(Typ1
, Typ2
: Entity_Id
) return Boolean is
10541 T1
: constant Entity_Id
:= Underlying_Type
(Typ1
);
10542 T2
: constant Entity_Id
:= Underlying_Type
(Typ2
);
10545 -- A quick check, if base types are the same, then we definitely have
10546 -- the same representation, because the subtype specific representation
10547 -- attributes (Size and Alignment) do not affect representation from
10548 -- the point of view of this test.
10550 if Base_Type
(T1
) = Base_Type
(T2
) then
10553 elsif Is_Private_Type
(Base_Type
(T2
))
10554 and then Base_Type
(T1
) = Full_View
(Base_Type
(T2
))
10559 -- Tagged types never have differing representations
10561 if Is_Tagged_Type
(T1
) then
10565 -- Representations are definitely different if conventions differ
10567 if Convention
(T1
) /= Convention
(T2
) then
10571 -- Representations are different if component alignments or scalar
10572 -- storage orders differ.
10574 if (Is_Record_Type
(T1
) or else Is_Array_Type
(T1
))
10576 (Is_Record_Type
(T2
) or else Is_Array_Type
(T2
))
10578 (Component_Alignment
(T1
) /= Component_Alignment
(T2
)
10580 Reverse_Storage_Order
(T1
) /= Reverse_Storage_Order
(T2
))
10585 -- For arrays, the only real issue is component size. If we know the
10586 -- component size for both arrays, and it is the same, then that's
10587 -- good enough to know we don't have a change of representation.
10589 if Is_Array_Type
(T1
) then
10590 if Known_Component_Size
(T1
)
10591 and then Known_Component_Size
(T2
)
10592 and then Component_Size
(T1
) = Component_Size
(T2
)
10594 if VM_Target
= No_VM
then
10597 -- In VM targets the representation of arrays with aliased
10598 -- components differs from arrays with non-aliased components
10601 return Has_Aliased_Components
(Base_Type
(T1
))
10603 Has_Aliased_Components
(Base_Type
(T2
));
10608 -- Types definitely have same representation if neither has non-standard
10609 -- representation since default representations are always consistent.
10610 -- If only one has non-standard representation, and the other does not,
10611 -- then we consider that they do not have the same representation. They
10612 -- might, but there is no way of telling early enough.
10614 if Has_Non_Standard_Rep
(T1
) then
10615 if not Has_Non_Standard_Rep
(T2
) then
10619 return not Has_Non_Standard_Rep
(T2
);
10622 -- Here the two types both have non-standard representation, and we need
10623 -- to determine if they have the same non-standard representation.
10625 -- For arrays, we simply need to test if the component sizes are the
10626 -- same. Pragma Pack is reflected in modified component sizes, so this
10627 -- check also deals with pragma Pack.
10629 if Is_Array_Type
(T1
) then
10630 return Component_Size
(T1
) = Component_Size
(T2
);
10632 -- Tagged types always have the same representation, because it is not
10633 -- possible to specify different representations for common fields.
10635 elsif Is_Tagged_Type
(T1
) then
10638 -- Case of record types
10640 elsif Is_Record_Type
(T1
) then
10642 -- Packed status must conform
10644 if Is_Packed
(T1
) /= Is_Packed
(T2
) then
10647 -- Otherwise we must check components. Typ2 maybe a constrained
10648 -- subtype with fewer components, so we compare the components
10649 -- of the base types.
10652 Record_Case
: declare
10653 CD1
, CD2
: Entity_Id
;
10655 function Same_Rep
return Boolean;
10656 -- CD1 and CD2 are either components or discriminants. This
10657 -- function tests whether they have the same representation.
10663 function Same_Rep
return Boolean is
10665 if No
(Component_Clause
(CD1
)) then
10666 return No
(Component_Clause
(CD2
));
10668 -- Note: at this point, component clauses have been
10669 -- normalized to the default bit order, so that the
10670 -- comparison of Component_Bit_Offsets is meaningful.
10673 Present
(Component_Clause
(CD2
))
10675 Component_Bit_Offset
(CD1
) = Component_Bit_Offset
(CD2
)
10677 Esize
(CD1
) = Esize
(CD2
);
10681 -- Start of processing for Record_Case
10684 if Has_Discriminants
(T1
) then
10686 -- The number of discriminants may be different if the
10687 -- derived type has fewer (constrained by values). The
10688 -- invisible discriminants retain the representation of
10689 -- the original, so the discrepancy does not per se
10690 -- indicate a different representation.
10692 CD1
:= First_Discriminant
(T1
);
10693 CD2
:= First_Discriminant
(T2
);
10694 while Present
(CD1
) and then Present
(CD2
) loop
10695 if not Same_Rep
then
10698 Next_Discriminant
(CD1
);
10699 Next_Discriminant
(CD2
);
10704 CD1
:= First_Component
(Underlying_Type
(Base_Type
(T1
)));
10705 CD2
:= First_Component
(Underlying_Type
(Base_Type
(T2
)));
10706 while Present
(CD1
) loop
10707 if not Same_Rep
then
10710 Next_Component
(CD1
);
10711 Next_Component
(CD2
);
10719 -- For enumeration types, we must check each literal to see if the
10720 -- representation is the same. Note that we do not permit enumeration
10721 -- representation clauses for Character and Wide_Character, so these
10722 -- cases were already dealt with.
10724 elsif Is_Enumeration_Type
(T1
) then
10725 Enumeration_Case
: declare
10726 L1
, L2
: Entity_Id
;
10729 L1
:= First_Literal
(T1
);
10730 L2
:= First_Literal
(T2
);
10731 while Present
(L1
) loop
10732 if Enumeration_Rep
(L1
) /= Enumeration_Rep
(L2
) then
10741 end Enumeration_Case
;
10743 -- Any other types have the same representation for these purposes
10748 end Same_Representation
;
10754 procedure Set_Biased
10758 Biased
: Boolean := True)
10762 Set_Has_Biased_Representation
(E
);
10764 if Warn_On_Biased_Representation
then
10766 ("?B?" & Msg
& " forces biased representation for&", N
, E
);
10771 --------------------
10772 -- Set_Enum_Esize --
10773 --------------------
10775 procedure Set_Enum_Esize
(T
: Entity_Id
) is
10781 Init_Alignment
(T
);
10783 -- Find the minimum standard size (8,16,32,64) that fits
10785 Lo
:= Enumeration_Rep
(Entity
(Type_Low_Bound
(T
)));
10786 Hi
:= Enumeration_Rep
(Entity
(Type_High_Bound
(T
)));
10789 if Lo
>= -Uint_2
**07 and then Hi
< Uint_2
**07 then
10790 Sz
:= Standard_Character_Size
; -- May be > 8 on some targets
10792 elsif Lo
>= -Uint_2
**15 and then Hi
< Uint_2
**15 then
10795 elsif Lo
>= -Uint_2
**31 and then Hi
< Uint_2
**31 then
10798 else pragma Assert
(Lo
>= -Uint_2
**63 and then Hi
< Uint_2
**63);
10803 if Hi
< Uint_2
**08 then
10804 Sz
:= Standard_Character_Size
; -- May be > 8 on some targets
10806 elsif Hi
< Uint_2
**16 then
10809 elsif Hi
< Uint_2
**32 then
10812 else pragma Assert
(Hi
< Uint_2
**63);
10817 -- That minimum is the proper size unless we have a foreign convention
10818 -- and the size required is 32 or less, in which case we bump the size
10819 -- up to 32. This is required for C and C++ and seems reasonable for
10820 -- all other foreign conventions.
10822 if Has_Foreign_Convention
(T
)
10823 and then Esize
(T
) < Standard_Integer_Size
10825 -- Don't do this if Short_Enums on target
10827 and then not Target_Short_Enums
10829 Init_Esize
(T
, Standard_Integer_Size
);
10831 Init_Esize
(T
, Sz
);
10833 end Set_Enum_Esize
;
10835 ------------------------------
10836 -- Validate_Address_Clauses --
10837 ------------------------------
10839 procedure Validate_Address_Clauses
is
10841 for J
in Address_Clause_Checks
.First
.. Address_Clause_Checks
.Last
loop
10843 ACCR
: Address_Clause_Check_Record
10844 renames Address_Clause_Checks
.Table
(J
);
10848 X_Alignment
: Uint
;
10849 Y_Alignment
: Uint
;
10855 -- Skip processing of this entry if warning already posted
10857 if not Address_Warning_Posted
(ACCR
.N
) then
10858 Expr
:= Original_Node
(Expression
(ACCR
.N
));
10862 X_Alignment
:= Alignment
(ACCR
.X
);
10863 Y_Alignment
:= Alignment
(ACCR
.Y
);
10865 -- Similarly obtain sizes
10867 X_Size
:= Esize
(ACCR
.X
);
10868 Y_Size
:= Esize
(ACCR
.Y
);
10870 -- Check for large object overlaying smaller one
10873 and then X_Size
> Uint_0
10874 and then X_Size
> Y_Size
10877 ("?& overlays smaller object", ACCR
.N
, ACCR
.X
);
10879 ("\??program execution may be erroneous", ACCR
.N
);
10880 Error_Msg_Uint_1
:= X_Size
;
10882 ("\??size of & is ^", ACCR
.N
, ACCR
.X
);
10883 Error_Msg_Uint_1
:= Y_Size
;
10885 ("\??size of & is ^", ACCR
.N
, ACCR
.Y
);
10887 -- Check for inadequate alignment, both of the base object
10888 -- and of the offset, if any.
10890 -- Note: we do not check the alignment if we gave a size
10891 -- warning, since it would likely be redundant.
10893 elsif Y_Alignment
/= Uint_0
10894 and then (Y_Alignment
< X_Alignment
10897 Nkind
(Expr
) = N_Attribute_Reference
10899 Attribute_Name
(Expr
) = Name_Address
10901 Has_Compatible_Alignment
10902 (ACCR
.X
, Prefix
(Expr
))
10903 /= Known_Compatible
))
10906 ("??specified address for& may be inconsistent "
10907 & "with alignment", ACCR
.N
, ACCR
.X
);
10909 ("\??program execution may be erroneous (RM 13.3(27))",
10911 Error_Msg_Uint_1
:= X_Alignment
;
10913 ("\??alignment of & is ^", ACCR
.N
, ACCR
.X
);
10914 Error_Msg_Uint_1
:= Y_Alignment
;
10916 ("\??alignment of & is ^", ACCR
.N
, ACCR
.Y
);
10917 if Y_Alignment
>= X_Alignment
then
10919 ("\??but offset is not multiple of alignment", ACCR
.N
);
10925 end Validate_Address_Clauses
;
10927 ---------------------------
10928 -- Validate_Independence --
10929 ---------------------------
10931 procedure Validate_Independence
is
10932 SU
: constant Uint
:= UI_From_Int
(System_Storage_Unit
);
10940 procedure Check_Array_Type
(Atyp
: Entity_Id
);
10941 -- Checks if the array type Atyp has independent components, and
10942 -- if not, outputs an appropriate set of error messages.
10944 procedure No_Independence
;
10945 -- Output message that independence cannot be guaranteed
10947 function OK_Component
(C
: Entity_Id
) return Boolean;
10948 -- Checks one component to see if it is independently accessible, and
10949 -- if so yields True, otherwise yields False if independent access
10950 -- cannot be guaranteed. This is a conservative routine, it only
10951 -- returns True if it knows for sure, it returns False if it knows
10952 -- there is a problem, or it cannot be sure there is no problem.
10954 procedure Reason_Bad_Component
(C
: Entity_Id
);
10955 -- Outputs continuation message if a reason can be determined for
10956 -- the component C being bad.
10958 ----------------------
10959 -- Check_Array_Type --
10960 ----------------------
10962 procedure Check_Array_Type
(Atyp
: Entity_Id
) is
10963 Ctyp
: constant Entity_Id
:= Component_Type
(Atyp
);
10966 -- OK if no alignment clause, no pack, and no component size
10968 if not Has_Component_Size_Clause
(Atyp
)
10969 and then not Has_Alignment_Clause
(Atyp
)
10970 and then not Is_Packed
(Atyp
)
10975 -- Check actual component size
10977 if not Known_Component_Size
(Atyp
)
10978 or else not (Addressable
(Component_Size
(Atyp
))
10979 and then Component_Size
(Atyp
) < 64)
10980 or else Component_Size
(Atyp
) mod Esize
(Ctyp
) /= 0
10984 -- Bad component size, check reason
10986 if Has_Component_Size_Clause
(Atyp
) then
10987 P
:= Get_Attribute_Definition_Clause
10988 (Atyp
, Attribute_Component_Size
);
10990 if Present
(P
) then
10991 Error_Msg_Sloc
:= Sloc
(P
);
10992 Error_Msg_N
("\because of Component_Size clause#", N
);
10997 if Is_Packed
(Atyp
) then
10998 P
:= Get_Rep_Pragma
(Atyp
, Name_Pack
);
11000 if Present
(P
) then
11001 Error_Msg_Sloc
:= Sloc
(P
);
11002 Error_Msg_N
("\because of pragma Pack#", N
);
11007 -- No reason found, just return
11012 -- Array type is OK independence-wise
11015 end Check_Array_Type
;
11017 ---------------------
11018 -- No_Independence --
11019 ---------------------
11021 procedure No_Independence
is
11023 if Pragma_Name
(N
) = Name_Independent
then
11024 Error_Msg_NE
("independence cannot be guaranteed for&", N
, E
);
11027 ("independent components cannot be guaranteed for&", N
, E
);
11029 end No_Independence
;
11035 function OK_Component
(C
: Entity_Id
) return Boolean is
11036 Rec
: constant Entity_Id
:= Scope
(C
);
11037 Ctyp
: constant Entity_Id
:= Etype
(C
);
11040 -- OK if no component clause, no Pack, and no alignment clause
11042 if No
(Component_Clause
(C
))
11043 and then not Is_Packed
(Rec
)
11044 and then not Has_Alignment_Clause
(Rec
)
11049 -- Here we look at the actual component layout. A component is
11050 -- addressable if its size is a multiple of the Esize of the
11051 -- component type, and its starting position in the record has
11052 -- appropriate alignment, and the record itself has appropriate
11053 -- alignment to guarantee the component alignment.
11055 -- Make sure sizes are static, always assume the worst for any
11056 -- cases where we cannot check static values.
11058 if not (Known_Static_Esize
(C
)
11060 Known_Static_Esize
(Ctyp
))
11065 -- Size of component must be addressable or greater than 64 bits
11066 -- and a multiple of bytes.
11068 if not Addressable
(Esize
(C
)) and then Esize
(C
) < Uint_64
then
11072 -- Check size is proper multiple
11074 if Esize
(C
) mod Esize
(Ctyp
) /= 0 then
11078 -- Check alignment of component is OK
11080 if not Known_Component_Bit_Offset
(C
)
11081 or else Component_Bit_Offset
(C
) < Uint_0
11082 or else Component_Bit_Offset
(C
) mod Esize
(Ctyp
) /= 0
11087 -- Check alignment of record type is OK
11089 if not Known_Alignment
(Rec
)
11090 or else (Alignment
(Rec
) * SU
) mod Esize
(Ctyp
) /= 0
11095 -- All tests passed, component is addressable
11100 --------------------------
11101 -- Reason_Bad_Component --
11102 --------------------------
11104 procedure Reason_Bad_Component
(C
: Entity_Id
) is
11105 Rec
: constant Entity_Id
:= Scope
(C
);
11106 Ctyp
: constant Entity_Id
:= Etype
(C
);
11109 -- If component clause present assume that's the problem
11111 if Present
(Component_Clause
(C
)) then
11112 Error_Msg_Sloc
:= Sloc
(Component_Clause
(C
));
11113 Error_Msg_N
("\because of Component_Clause#", N
);
11117 -- If pragma Pack clause present, assume that's the problem
11119 if Is_Packed
(Rec
) then
11120 P
:= Get_Rep_Pragma
(Rec
, Name_Pack
);
11122 if Present
(P
) then
11123 Error_Msg_Sloc
:= Sloc
(P
);
11124 Error_Msg_N
("\because of pragma Pack#", N
);
11129 -- See if record has bad alignment clause
11131 if Has_Alignment_Clause
(Rec
)
11132 and then Known_Alignment
(Rec
)
11133 and then (Alignment
(Rec
) * SU
) mod Esize
(Ctyp
) /= 0
11135 P
:= Get_Attribute_Definition_Clause
(Rec
, Attribute_Alignment
);
11137 if Present
(P
) then
11138 Error_Msg_Sloc
:= Sloc
(P
);
11139 Error_Msg_N
("\because of Alignment clause#", N
);
11143 -- Couldn't find a reason, so return without a message
11146 end Reason_Bad_Component
;
11148 -- Start of processing for Validate_Independence
11151 for J
in Independence_Checks
.First
.. Independence_Checks
.Last
loop
11152 N
:= Independence_Checks
.Table
(J
).N
;
11153 E
:= Independence_Checks
.Table
(J
).E
;
11154 IC
:= Pragma_Name
(N
) = Name_Independent_Components
;
11156 -- Deal with component case
11158 if Ekind
(E
) = E_Discriminant
or else Ekind
(E
) = E_Component
then
11159 if not OK_Component
(E
) then
11161 Reason_Bad_Component
(E
);
11166 -- Deal with record with Independent_Components
11168 if IC
and then Is_Record_Type
(E
) then
11169 Comp
:= First_Component_Or_Discriminant
(E
);
11170 while Present
(Comp
) loop
11171 if not OK_Component
(Comp
) then
11173 Reason_Bad_Component
(Comp
);
11177 Next_Component_Or_Discriminant
(Comp
);
11181 -- Deal with address clause case
11183 if Is_Object
(E
) then
11184 Addr
:= Address_Clause
(E
);
11186 if Present
(Addr
) then
11188 Error_Msg_Sloc
:= Sloc
(Addr
);
11189 Error_Msg_N
("\because of Address clause#", N
);
11194 -- Deal with independent components for array type
11196 if IC
and then Is_Array_Type
(E
) then
11197 Check_Array_Type
(E
);
11200 -- Deal with independent components for array object
11202 if IC
and then Is_Object
(E
) and then Is_Array_Type
(Etype
(E
)) then
11203 Check_Array_Type
(Etype
(E
));
11208 end Validate_Independence
;
11210 -----------------------------------
11211 -- Validate_Unchecked_Conversion --
11212 -----------------------------------
11214 procedure Validate_Unchecked_Conversion
11216 Act_Unit
: Entity_Id
)
11218 Source
: Entity_Id
;
11219 Target
: Entity_Id
;
11223 -- Obtain source and target types. Note that we call Ancestor_Subtype
11224 -- here because the processing for generic instantiation always makes
11225 -- subtypes, and we want the original frozen actual types.
11227 -- If we are dealing with private types, then do the check on their
11228 -- fully declared counterparts if the full declarations have been
11229 -- encountered (they don't have to be visible, but they must exist).
11231 Source
:= Ancestor_Subtype
(Etype
(First_Formal
(Act_Unit
)));
11233 if Is_Private_Type
(Source
)
11234 and then Present
(Underlying_Type
(Source
))
11236 Source
:= Underlying_Type
(Source
);
11239 Target
:= Ancestor_Subtype
(Etype
(Act_Unit
));
11241 -- If either type is generic, the instantiation happens within a generic
11242 -- unit, and there is nothing to check. The proper check will happen
11243 -- when the enclosing generic is instantiated.
11245 if Is_Generic_Type
(Source
) or else Is_Generic_Type
(Target
) then
11249 if Is_Private_Type
(Target
)
11250 and then Present
(Underlying_Type
(Target
))
11252 Target
:= Underlying_Type
(Target
);
11255 -- Source may be unconstrained array, but not target
11257 if Is_Array_Type
(Target
) and then not Is_Constrained
(Target
) then
11259 ("unchecked conversion to unconstrained array not allowed", N
);
11263 -- Warn if conversion between two different convention pointers
11265 if Is_Access_Type
(Target
)
11266 and then Is_Access_Type
(Source
)
11267 and then Convention
(Target
) /= Convention
(Source
)
11268 and then Warn_On_Unchecked_Conversion
11270 -- Give warnings for subprogram pointers only on most targets. The
11271 -- exception is VMS, where data pointers can have different lengths
11272 -- depending on the pointer convention.
11274 if Is_Access_Subprogram_Type
(Target
)
11275 or else Is_Access_Subprogram_Type
(Source
)
11276 or else OpenVMS_On_Target
11279 ("?z?conversion between pointers with different conventions!",
11284 -- Warn if one of the operands is Ada.Calendar.Time. Do not emit a
11285 -- warning when compiling GNAT-related sources.
11287 if Warn_On_Unchecked_Conversion
11288 and then not In_Predefined_Unit
(N
)
11289 and then RTU_Loaded
(Ada_Calendar
)
11291 (Chars
(Source
) = Name_Time
11293 Chars
(Target
) = Name_Time
)
11295 -- If Ada.Calendar is loaded and the name of one of the operands is
11296 -- Time, there is a good chance that this is Ada.Calendar.Time.
11299 Calendar_Time
: constant Entity_Id
:=
11300 Full_View
(RTE
(RO_CA_Time
));
11302 pragma Assert
(Present
(Calendar_Time
));
11304 if Source
= Calendar_Time
or else Target
= Calendar_Time
then
11306 ("?z?representation of 'Time values may change between " &
11307 "'G'N'A'T versions", N
);
11312 -- Make entry in unchecked conversion table for later processing by
11313 -- Validate_Unchecked_Conversions, which will check sizes and alignments
11314 -- (using values set by the back-end where possible). This is only done
11315 -- if the appropriate warning is active.
11317 if Warn_On_Unchecked_Conversion
then
11318 Unchecked_Conversions
.Append
11319 (New_Val
=> UC_Entry
'(Eloc => Sloc (N),
11321 Target => Target));
11323 -- If both sizes are known statically now, then back end annotation
11324 -- is not required to do a proper check but if either size is not
11325 -- known statically, then we need the annotation.
11327 if Known_Static_RM_Size (Source)
11329 Known_Static_RM_Size (Target)
11333 Back_Annotate_Rep_Info := True;
11337 -- If unchecked conversion to access type, and access type is declared
11338 -- in the same unit as the unchecked conversion, then set the flag
11339 -- No_Strict_Aliasing (no strict aliasing is implicit here)
11341 if Is_Access_Type (Target) and then
11342 In_Same_Source_Unit (Target, N)
11344 Set_No_Strict_Aliasing (Implementation_Base_Type (Target));
11347 -- Generate N_Validate_Unchecked_Conversion node for back end in case
11348 -- the back end needs to perform special validation checks.
11350 -- Shouldn't this be in Exp_Ch13, since the check only gets done if we
11351 -- have full expansion and the back end is called ???
11354 Make_Validate_Unchecked_Conversion (Sloc (N));
11355 Set_Source_Type (Vnode, Source);
11356 Set_Target_Type (Vnode, Target);
11358 -- If the unchecked conversion node is in a list, just insert before it.
11359 -- If not we have some strange case, not worth bothering about.
11361 if Is_List_Member (N) then
11362 Insert_After (N, Vnode);
11364 end Validate_Unchecked_Conversion;
11366 ------------------------------------
11367 -- Validate_Unchecked_Conversions --
11368 ------------------------------------
11370 procedure Validate_Unchecked_Conversions is
11372 for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop
11374 T : UC_Entry renames Unchecked_Conversions.Table (N);
11376 Eloc : constant Source_Ptr := T.Eloc;
11377 Source : constant Entity_Id := T.Source;
11378 Target : constant Entity_Id := T.Target;
11384 -- This validation check, which warns if we have unequal sizes for
11385 -- unchecked conversion, and thus potentially implementation
11386 -- dependent semantics, is one of the few occasions on which we
11387 -- use the official RM size instead of Esize. See description in
11388 -- Einfo "Handling of Type'Size Values" for details.
11390 if Serious_Errors_Detected = 0
11391 and then Known_Static_RM_Size (Source)
11392 and then Known_Static_RM_Size (Target)
11394 -- Don't do the check if warnings off for either type, note the
11395 -- deliberate use of OR here instead of OR ELSE to get the flag
11396 -- Warnings_Off_Used set for both types if appropriate.
11398 and then not (Has_Warnings_Off (Source)
11400 Has_Warnings_Off (Target))
11402 Source_Siz := RM_Size (Source);
11403 Target_Siz := RM_Size (Target);
11405 if Source_Siz /= Target_Siz then
11407 ("?z?types for unchecked conversion have different sizes!",
11410 if All_Errors_Mode then
11411 Error_Msg_Name_1 := Chars (Source);
11412 Error_Msg_Uint_1 := Source_Siz;
11413 Error_Msg_Name_2 := Chars (Target);
11414 Error_Msg_Uint_2 := Target_Siz;
11415 Error_Msg ("\size of % is ^, size of % is ^?z?", Eloc);
11417 Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz);
11419 if Is_Discrete_Type (Source)
11421 Is_Discrete_Type (Target)
11423 if Source_Siz > Target_Siz then
11425 ("\?z?^ high order bits of source will "
11426 & "be ignored!", Eloc);
11428 elsif Is_Unsigned_Type (Source) then
11430 ("\?z?source will be extended with ^ high order "
11431 & "zero bits?!", Eloc);
11435 ("\?z?source will be extended with ^ high order "
11436 & "sign bits!", Eloc);
11439 elsif Source_Siz < Target_Siz then
11440 if Is_Discrete_Type (Target) then
11441 if Bytes_Big_Endian then
11443 ("\?z?target value will include ^ undefined "
11444 & "low order bits!", Eloc);
11447 ("\?z?target value will include ^ undefined "
11448 & "high order bits!", Eloc);
11453 ("\?z?^ trailing bits of target value will be "
11454 & "undefined!", Eloc);
11457 else pragma Assert (Source_Siz > Target_Siz);
11459 ("\?z?^ trailing bits of source will be ignored!",
11466 -- If both types are access types, we need to check the alignment.
11467 -- If the alignment of both is specified, we can do it here.
11469 if Serious_Errors_Detected = 0
11470 and then Ekind (Source) in Access_Kind
11471 and then Ekind (Target) in Access_Kind
11472 and then Target_Strict_Alignment
11473 and then Present (Designated_Type (Source))
11474 and then Present (Designated_Type (Target))
11477 D_Source : constant Entity_Id := Designated_Type (Source);
11478 D_Target : constant Entity_Id := Designated_Type (Target);
11481 if Known_Alignment (D_Source)
11483 Known_Alignment (D_Target)
11486 Source_Align : constant Uint := Alignment (D_Source);
11487 Target_Align : constant Uint := Alignment (D_Target);
11490 if Source_Align < Target_Align
11491 and then not Is_Tagged_Type (D_Source)
11493 -- Suppress warning if warnings suppressed on either
11494 -- type or either designated type. Note the use of
11495 -- OR here instead of OR ELSE. That is intentional,
11496 -- we would like to set flag Warnings_Off_Used in
11497 -- all types for which warnings are suppressed.
11499 and then not (Has_Warnings_Off (D_Source)
11501 Has_Warnings_Off (D_Target)
11503 Has_Warnings_Off (Source)
11505 Has_Warnings_Off (Target))
11507 Error_Msg_Uint_1 := Target_Align;
11508 Error_Msg_Uint_2 := Source_Align;
11509 Error_Msg_Node_1 := D_Target;
11510 Error_Msg_Node_2 := D_Source;
11512 ("?z?alignment of & (^) is stricter than "
11513 & "alignment of & (^)!", Eloc);
11515 ("\?z?resulting access value may have invalid "
11516 & "alignment!", Eloc);
11524 end Validate_Unchecked_Conversions;