1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2016, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Aspects
; use Aspects
;
27 with Atree
; use Atree
;
28 with Checks
; use Checks
;
29 with Debug
; use Debug
;
30 with Einfo
; use Einfo
;
31 with Elists
; use Elists
;
32 with Errout
; use Errout
;
33 with Exp_Disp
; use Exp_Disp
;
34 with Exp_Tss
; use Exp_Tss
;
35 with Exp_Util
; use Exp_Util
;
36 with Freeze
; use Freeze
;
37 with Ghost
; use Ghost
;
39 with Lib
.Xref
; use Lib
.Xref
;
40 with Namet
; use Namet
;
41 with Nlists
; use Nlists
;
42 with Nmake
; use Nmake
;
44 with Restrict
; use Restrict
;
45 with Rident
; use Rident
;
46 with Rtsfind
; use Rtsfind
;
48 with Sem_Aux
; use Sem_Aux
;
49 with Sem_Case
; use Sem_Case
;
50 with Sem_Ch3
; use Sem_Ch3
;
51 with Sem_Ch6
; use Sem_Ch6
;
52 with Sem_Ch8
; use Sem_Ch8
;
53 with Sem_Dim
; use Sem_Dim
;
54 with Sem_Disp
; use Sem_Disp
;
55 with Sem_Eval
; use Sem_Eval
;
56 with Sem_Prag
; use Sem_Prag
;
57 with Sem_Res
; use Sem_Res
;
58 with Sem_Type
; use Sem_Type
;
59 with Sem_Util
; use Sem_Util
;
60 with Sem_Warn
; use Sem_Warn
;
61 with Sinput
; use Sinput
;
62 with Snames
; use Snames
;
63 with Stand
; use Stand
;
64 with Sinfo
; use Sinfo
;
65 with Stringt
; use Stringt
;
66 with Targparm
; use Targparm
;
67 with Ttypes
; use Ttypes
;
68 with Tbuild
; use Tbuild
;
69 with Urealp
; use Urealp
;
70 with Warnsw
; use Warnsw
;
72 with GNAT
.Heap_Sort_G
;
74 package body Sem_Ch13
is
76 SSU
: constant Pos
:= System_Storage_Unit
;
77 -- Convenient short hand for commonly used constant
79 -----------------------
80 -- Local Subprograms --
81 -----------------------
83 procedure Alignment_Check_For_Size_Change
(Typ
: Entity_Id
; Size
: Uint
);
84 -- This routine is called after setting one of the sizes of type entity
85 -- Typ to Size. The purpose is to deal with the situation of a derived
86 -- type whose inherited alignment is no longer appropriate for the new
87 -- size value. In this case, we reset the Alignment to unknown.
89 procedure Build_Discrete_Static_Predicate
93 -- Given a predicated type Typ, where Typ is a discrete static subtype,
94 -- whose predicate expression is Expr, tests if Expr is a static predicate,
95 -- and if so, builds the predicate range list. Nam is the name of the one
96 -- argument to the predicate function. Occurrences of the type name in the
97 -- predicate expression have been replaced by identifier references to this
98 -- name, which is unique, so any identifier with Chars matching Nam must be
99 -- a reference to the type. If the predicate is non-static, this procedure
100 -- returns doing nothing. If the predicate is static, then the predicate
101 -- list is stored in Static_Discrete_Predicate (Typ), and the Expr is
102 -- rewritten as a canonicalized membership operation.
104 function Build_Export_Import_Pragma
106 Id
: Entity_Id
) return Node_Id
;
107 -- Create the corresponding pragma for aspect Export or Import denoted by
108 -- Asp. Id is the related entity subject to the aspect. Return Empty when
109 -- the expression of aspect Asp evaluates to False or is erroneous.
111 function Build_Predicate_Function_Declaration
112 (Typ
: Entity_Id
) return Node_Id
;
113 -- Build the declaration for a predicate function. The declaration is built
114 -- at the end of the declarative part containing the type definition, which
115 -- may be before the freeze point of the type. The predicate expression is
116 -- pre-analyzed at this point, to catch visibility errors.
118 procedure Build_Predicate_Functions
(Typ
: Entity_Id
; N
: Node_Id
);
119 -- If Typ has predicates (indicated by Has_Predicates being set for Typ),
120 -- then either there are pragma Predicate entries on the rep chain for the
121 -- type (note that Predicate aspects are converted to pragma Predicate), or
122 -- there are inherited aspects from a parent type, or ancestor subtypes.
123 -- This procedure builds body for the Predicate function that tests these
124 -- predicates. N is the freeze node for the type. The spec of the function
125 -- is inserted before the freeze node, and the body of the function is
126 -- inserted after the freeze node. If the predicate expression has a least
127 -- one Raise_Expression, then this procedure also builds the M version of
128 -- the predicate function for use in membership tests.
130 procedure Check_Pool_Size_Clash
(Ent
: Entity_Id
; SP
, SS
: Node_Id
);
131 -- Called if both Storage_Pool and Storage_Size attribute definition
132 -- clauses (SP and SS) are present for entity Ent. Issue error message.
134 procedure Freeze_Entity_Checks
(N
: Node_Id
);
135 -- Called from Analyze_Freeze_Entity and Analyze_Generic_Freeze Entity
136 -- to generate appropriate semantic checks that are delayed until this
137 -- point (they had to be delayed this long for cases of delayed aspects,
138 -- e.g. analysis of statically predicated subtypes in choices, for which
139 -- we have to be sure the subtypes in question are frozen before checking).
141 function Get_Alignment_Value
(Expr
: Node_Id
) return Uint
;
142 -- Given the expression for an alignment value, returns the corresponding
143 -- Uint value. If the value is inappropriate, then error messages are
144 -- posted as required, and a value of No_Uint is returned.
146 procedure Get_Interfacing_Aspects
147 (Iface_Asp
: Node_Id
;
148 Conv_Asp
: out Node_Id
;
149 EN_Asp
: out Node_Id
;
150 Expo_Asp
: out Node_Id
;
151 Imp_Asp
: out Node_Id
;
152 LN_Asp
: out Node_Id
;
153 Do_Checks
: Boolean := False);
154 -- Given a single interfacing aspect Iface_Asp, retrieve other interfacing
155 -- aspects that apply to the same related entity. The aspects considered by
156 -- this routine are as follows:
158 -- Conv_Asp - aspect Convention
159 -- EN_Asp - aspect External_Name
160 -- Expo_Asp - aspect Export
161 -- Imp_Asp - aspect Import
162 -- LN_Asp - aspect Link_Name
164 -- When flag Do_Checks is set, this routine will flag duplicate uses of
167 function Is_Operational_Item
(N
: Node_Id
) return Boolean;
168 -- A specification for a stream attribute is allowed before the full type
169 -- is declared, as explained in AI-00137 and the corrigendum. Attributes
170 -- that do not specify a representation characteristic are operational
173 function Is_Predicate_Static
175 Nam
: Name_Id
) return Boolean;
176 -- Given predicate expression Expr, tests if Expr is predicate-static in
177 -- the sense of the rules in (RM 3.2.4 (15-24)). Occurrences of the type
178 -- name in the predicate expression have been replaced by references to
179 -- an identifier whose Chars field is Nam. This name is unique, so any
180 -- identifier with Chars matching Nam must be a reference to the type.
181 -- Returns True if the expression is predicate-static and False otherwise,
182 -- but is not in the business of setting flags or issuing error messages.
184 -- Only scalar types can have static predicates, so False is always
185 -- returned for non-scalar types.
187 -- Note: the RM seems to suggest that string types can also have static
188 -- predicates. But that really makes lttle sense as very few useful
189 -- predicates can be constructed for strings. Remember that:
193 -- is not a static expression. So even though the clearly faulty RM wording
194 -- allows the following:
196 -- subtype S is String with Static_Predicate => S < "DEF"
198 -- We can't allow this, otherwise we have predicate-static applying to a
199 -- larger class than static expressions, which was never intended.
201 procedure New_Stream_Subprogram
205 Nam
: TSS_Name_Type
);
206 -- Create a subprogram renaming of a given stream attribute to the
207 -- designated subprogram and then in the tagged case, provide this as a
208 -- primitive operation, or in the untagged case make an appropriate TSS
209 -- entry. This is more properly an expansion activity than just semantics,
210 -- but the presence of user-defined stream functions for limited types
211 -- is a legality check, which is why this takes place here rather than in
212 -- exp_ch13, where it was previously. Nam indicates the name of the TSS
213 -- function to be generated.
215 -- To avoid elaboration anomalies with freeze nodes, for untagged types
216 -- we generate both a subprogram declaration and a subprogram renaming
217 -- declaration, so that the attribute specification is handled as a
218 -- renaming_as_body. For tagged types, the specification is one of the
221 procedure Resolve_Iterable_Operation
226 -- If the name of a primitive operation for an Iterable aspect is
227 -- overloaded, resolve according to required signature.
233 Biased
: Boolean := True);
234 -- If Biased is True, sets Has_Biased_Representation flag for E, and
235 -- outputs a warning message at node N if Warn_On_Biased_Representation is
236 -- is True. This warning inserts the string Msg to describe the construct
239 ----------------------------------------------
240 -- Table for Validate_Unchecked_Conversions --
241 ----------------------------------------------
243 -- The following table collects unchecked conversions for validation.
244 -- Entries are made by Validate_Unchecked_Conversion and then the call
245 -- to Validate_Unchecked_Conversions does the actual error checking and
246 -- posting of warnings. The reason for this delayed processing is to take
247 -- advantage of back-annotations of size and alignment values performed by
250 -- Note: the reason we store a Source_Ptr value instead of a Node_Id is
251 -- that by the time Validate_Unchecked_Conversions is called, Sprint will
252 -- already have modified all Sloc values if the -gnatD option is set.
254 type UC_Entry
is record
255 Eloc
: Source_Ptr
; -- node used for posting warnings
256 Source
: Entity_Id
; -- source type for unchecked conversion
257 Target
: Entity_Id
; -- target type for unchecked conversion
258 Act_Unit
: Entity_Id
; -- actual function instantiated
261 package Unchecked_Conversions
is new Table
.Table
(
262 Table_Component_Type
=> UC_Entry
,
263 Table_Index_Type
=> Int
,
264 Table_Low_Bound
=> 1,
266 Table_Increment
=> 200,
267 Table_Name
=> "Unchecked_Conversions");
269 ----------------------------------------
270 -- Table for Validate_Address_Clauses --
271 ----------------------------------------
273 -- If an address clause has the form
275 -- for X'Address use Expr
277 -- where Expr is of the form Y'Address or recursively is a reference to a
278 -- constant of either of these forms, and X and Y are entities of objects,
279 -- then if Y has a smaller alignment than X, that merits a warning about
280 -- possible bad alignment. The following table collects address clauses of
281 -- this kind. We put these in a table so that they can be checked after the
282 -- back end has completed annotation of the alignments of objects, since we
283 -- can catch more cases that way.
285 type Address_Clause_Check_Record
is record
287 -- The address clause
290 -- The entity of the object overlaying Y
293 -- The entity of the object being overlaid
296 -- Whether the address is offset within Y
299 package Address_Clause_Checks
is new Table
.Table
(
300 Table_Component_Type
=> Address_Clause_Check_Record
,
301 Table_Index_Type
=> Int
,
302 Table_Low_Bound
=> 1,
304 Table_Increment
=> 200,
305 Table_Name
=> "Address_Clause_Checks");
307 -----------------------------------------
308 -- Adjust_Record_For_Reverse_Bit_Order --
309 -----------------------------------------
311 procedure Adjust_Record_For_Reverse_Bit_Order
(R
: Entity_Id
) is
316 -- Processing depends on version of Ada
318 -- For Ada 95, we just renumber bits within a storage unit. We do the
319 -- same for Ada 83 mode, since we recognize the Bit_Order attribute in
320 -- Ada 83, and are free to add this extension.
322 if Ada_Version
< Ada_2005
then
323 Comp
:= First_Component_Or_Discriminant
(R
);
324 while Present
(Comp
) loop
325 CC
:= Component_Clause
(Comp
);
327 -- If component clause is present, then deal with the non-default
328 -- bit order case for Ada 95 mode.
330 -- We only do this processing for the base type, and in fact that
331 -- is important, since otherwise if there are record subtypes, we
332 -- could reverse the bits once for each subtype, which is wrong.
334 if Present
(CC
) and then Ekind
(R
) = E_Record_Type
then
336 CFB
: constant Uint
:= Component_Bit_Offset
(Comp
);
337 CSZ
: constant Uint
:= Esize
(Comp
);
338 CLC
: constant Node_Id
:= Component_Clause
(Comp
);
339 Pos
: constant Node_Id
:= Position
(CLC
);
340 FB
: constant Node_Id
:= First_Bit
(CLC
);
342 Storage_Unit_Offset
: constant Uint
:=
343 CFB
/ System_Storage_Unit
;
345 Start_Bit
: constant Uint
:=
346 CFB
mod System_Storage_Unit
;
349 -- Cases where field goes over storage unit boundary
351 if Start_Bit
+ CSZ
> System_Storage_Unit
then
353 -- Allow multi-byte field but generate warning
355 if Start_Bit
mod System_Storage_Unit
= 0
356 and then CSZ
mod System_Storage_Unit
= 0
359 ("info: multi-byte field specified with "
360 & "non-standard Bit_Order?V?", CLC
);
362 if Bytes_Big_Endian
then
364 ("\bytes are not reversed "
365 & "(component is big-endian)?V?", CLC
);
368 ("\bytes are not reversed "
369 & "(component is little-endian)?V?", CLC
);
372 -- Do not allow non-contiguous field
376 ("attempt to specify non-contiguous field "
377 & "not permitted", CLC
);
379 ("\caused by non-standard Bit_Order "
382 ("\consider possibility of using "
383 & "Ada 2005 mode here", CLC
);
386 -- Case where field fits in one storage unit
389 -- Give warning if suspicious component clause
391 if Intval
(FB
) >= System_Storage_Unit
392 and then Warn_On_Reverse_Bit_Order
395 ("info: Bit_Order clause does not affect " &
396 "byte ordering?V?", Pos
);
398 Intval
(Pos
) + Intval
(FB
) /
401 ("info: position normalized to ^ before bit " &
402 "order interpreted?V?", Pos
);
405 -- Here is where we fix up the Component_Bit_Offset value
406 -- to account for the reverse bit order. Some examples of
407 -- what needs to be done are:
409 -- First_Bit .. Last_Bit Component_Bit_Offset
421 -- The rule is that the first bit is is obtained by
422 -- subtracting the old ending bit from storage_unit - 1.
424 Set_Component_Bit_Offset
426 (Storage_Unit_Offset
* System_Storage_Unit
) +
427 (System_Storage_Unit
- 1) -
428 (Start_Bit
+ CSZ
- 1));
430 Set_Normalized_First_Bit
432 Component_Bit_Offset
(Comp
) mod
433 System_Storage_Unit
);
438 Next_Component_Or_Discriminant
(Comp
);
441 -- For Ada 2005, we do machine scalar processing, as fully described In
442 -- AI-133. This involves gathering all components which start at the
443 -- same byte offset and processing them together. Same approach is still
444 -- valid in later versions including Ada 2012.
448 Max_Machine_Scalar_Size
: constant Uint
:=
450 (Standard_Long_Long_Integer_Size
);
451 -- We use this as the maximum machine scalar size
454 SSU
: constant Uint
:= UI_From_Int
(System_Storage_Unit
);
457 -- This first loop through components does two things. First it
458 -- deals with the case of components with component clauses whose
459 -- length is greater than the maximum machine scalar size (either
460 -- accepting them or rejecting as needed). Second, it counts the
461 -- number of components with component clauses whose length does
462 -- not exceed this maximum for later processing.
465 Comp
:= First_Component_Or_Discriminant
(R
);
466 while Present
(Comp
) loop
467 CC
:= Component_Clause
(Comp
);
471 Fbit
: constant Uint
:= Static_Integer
(First_Bit
(CC
));
472 Lbit
: constant Uint
:= Static_Integer
(Last_Bit
(CC
));
475 -- Case of component with last bit >= max machine scalar
477 if Lbit
>= Max_Machine_Scalar_Size
then
479 -- This is allowed only if first bit is zero, and
480 -- last bit + 1 is a multiple of storage unit size.
482 if Fbit
= 0 and then (Lbit
+ 1) mod SSU
= 0 then
484 -- This is the case to give a warning if enabled
486 if Warn_On_Reverse_Bit_Order
then
488 ("info: multi-byte field specified with "
489 & "non-standard Bit_Order?V?", CC
);
491 if Bytes_Big_Endian
then
493 ("\bytes are not reversed "
494 & "(component is big-endian)?V?", CC
);
497 ("\bytes are not reversed "
498 & "(component is little-endian)?V?", CC
);
502 -- Give error message for RM 13.5.1(10) violation
506 ("machine scalar rules not followed for&",
507 First_Bit
(CC
), Comp
);
509 Error_Msg_Uint_1
:= Lbit
+ 1;
510 Error_Msg_Uint_2
:= Max_Machine_Scalar_Size
;
512 ("\last bit + 1 (^) exceeds maximum machine "
516 if (Lbit
+ 1) mod SSU
/= 0 then
517 Error_Msg_Uint_1
:= SSU
;
519 ("\and is not a multiple of Storage_Unit (^) "
524 Error_Msg_Uint_1
:= Fbit
;
526 ("\and first bit (^) is non-zero "
532 -- OK case of machine scalar related component clause,
533 -- For now, just count them.
536 Num_CC
:= Num_CC
+ 1;
541 Next_Component_Or_Discriminant
(Comp
);
544 -- We need to sort the component clauses on the basis of the
545 -- Position values in the clause, so we can group clauses with
546 -- the same Position together to determine the relevant machine
550 Comps
: array (0 .. Num_CC
) of Entity_Id
;
551 -- Array to collect component and discriminant entities. The
552 -- data starts at index 1, the 0'th entry is for the sort
555 function CP_Lt
(Op1
, Op2
: Natural) return Boolean;
556 -- Compare routine for Sort
558 procedure CP_Move
(From
: Natural; To
: Natural);
559 -- Move routine for Sort
561 package Sorting
is new GNAT
.Heap_Sort_G
(CP_Move
, CP_Lt
);
565 -- Start and stop positions in the component list of the set of
566 -- components with the same starting position (that constitute
567 -- components in a single machine scalar).
570 -- Maximum last bit value of any component in this set
573 -- Corresponding machine scalar size
579 function CP_Lt
(Op1
, Op2
: Natural) return Boolean is
581 return Position
(Component_Clause
(Comps
(Op1
))) <
582 Position
(Component_Clause
(Comps
(Op2
)));
589 procedure CP_Move
(From
: Natural; To
: Natural) is
591 Comps
(To
) := Comps
(From
);
594 -- Start of processing for Sort_CC
597 -- Collect the machine scalar relevant component clauses
600 Comp
:= First_Component_Or_Discriminant
(R
);
601 while Present
(Comp
) loop
603 CC
: constant Node_Id
:= Component_Clause
(Comp
);
606 -- Collect only component clauses whose last bit is less
607 -- than machine scalar size. Any component clause whose
608 -- last bit exceeds this value does not take part in
609 -- machine scalar layout considerations. The test for
610 -- Error_Posted makes sure we exclude component clauses
611 -- for which we already posted an error.
614 and then not Error_Posted
(Last_Bit
(CC
))
615 and then Static_Integer
(Last_Bit
(CC
)) <
616 Max_Machine_Scalar_Size
618 Num_CC
:= Num_CC
+ 1;
619 Comps
(Num_CC
) := Comp
;
623 Next_Component_Or_Discriminant
(Comp
);
626 -- Sort by ascending position number
628 Sorting
.Sort
(Num_CC
);
630 -- We now have all the components whose size does not exceed
631 -- the max machine scalar value, sorted by starting position.
632 -- In this loop we gather groups of clauses starting at the
633 -- same position, to process them in accordance with AI-133.
636 while Stop
< Num_CC
loop
641 (Last_Bit
(Component_Clause
(Comps
(Start
))));
642 while Stop
< Num_CC
loop
644 (Position
(Component_Clause
(Comps
(Stop
+ 1)))) =
646 (Position
(Component_Clause
(Comps
(Stop
))))
654 (Component_Clause
(Comps
(Stop
)))));
660 -- Now we have a group of component clauses from Start to
661 -- Stop whose positions are identical, and MaxL is the
662 -- maximum last bit value of any of these components.
664 -- We need to determine the corresponding machine scalar
665 -- size. This loop assumes that machine scalar sizes are
666 -- even, and that each possible machine scalar has twice
667 -- as many bits as the next smaller one.
669 MSS
:= Max_Machine_Scalar_Size
;
671 and then (MSS
/ 2) >= SSU
672 and then (MSS
/ 2) > MaxL
677 -- Here is where we fix up the Component_Bit_Offset value
678 -- to account for the reverse bit order. Some examples of
679 -- what needs to be done for the case of a machine scalar
682 -- First_Bit .. Last_Bit Component_Bit_Offset
694 -- The rule is that the first bit is obtained by subtracting
695 -- the old ending bit from machine scalar size - 1.
697 for C
in Start
.. Stop
loop
699 Comp
: constant Entity_Id
:= Comps
(C
);
700 CC
: constant Node_Id
:= Component_Clause
(Comp
);
702 LB
: constant Uint
:= Static_Integer
(Last_Bit
(CC
));
703 NFB
: constant Uint
:= MSS
- Uint_1
- LB
;
704 NLB
: constant Uint
:= NFB
+ Esize
(Comp
) - 1;
705 Pos
: constant Uint
:= Static_Integer
(Position
(CC
));
708 if Warn_On_Reverse_Bit_Order
then
709 Error_Msg_Uint_1
:= MSS
;
711 ("info: reverse bit order in machine " &
712 "scalar of length^?V?", First_Bit
(CC
));
713 Error_Msg_Uint_1
:= NFB
;
714 Error_Msg_Uint_2
:= NLB
;
716 if Bytes_Big_Endian
then
718 ("\big-endian range for component "
719 & "& is ^ .. ^?V?", First_Bit
(CC
), Comp
);
722 ("\little-endian range for component"
723 & "& is ^ .. ^?V?", First_Bit
(CC
), Comp
);
727 Set_Component_Bit_Offset
(Comp
, Pos
* SSU
+ NFB
);
728 Set_Normalized_First_Bit
(Comp
, NFB
mod SSU
);
735 end Adjust_Record_For_Reverse_Bit_Order
;
737 -------------------------------------
738 -- Alignment_Check_For_Size_Change --
739 -------------------------------------
741 procedure Alignment_Check_For_Size_Change
(Typ
: Entity_Id
; Size
: Uint
) is
743 -- If the alignment is known, and not set by a rep clause, and is
744 -- inconsistent with the size being set, then reset it to unknown,
745 -- we assume in this case that the size overrides the inherited
746 -- alignment, and that the alignment must be recomputed.
748 if Known_Alignment
(Typ
)
749 and then not Has_Alignment_Clause
(Typ
)
750 and then Size
mod (Alignment
(Typ
) * SSU
) /= 0
752 Init_Alignment
(Typ
);
754 end Alignment_Check_For_Size_Change
;
756 -------------------------------------
757 -- Analyze_Aspects_At_Freeze_Point --
758 -------------------------------------
760 procedure Analyze_Aspects_At_Freeze_Point
(E
: Entity_Id
) is
761 procedure Analyze_Aspect_Default_Value
(ASN
: Node_Id
);
762 -- This routine analyzes an Aspect_Default_[Component_]Value denoted by
763 -- the aspect specification node ASN.
765 procedure Inherit_Delayed_Rep_Aspects
(ASN
: Node_Id
);
766 -- As discussed in the spec of Aspects (see Aspect_Delay declaration),
767 -- a derived type can inherit aspects from its parent which have been
768 -- specified at the time of the derivation using an aspect, as in:
770 -- type A is range 1 .. 10
771 -- with Size => Not_Defined_Yet;
775 -- Not_Defined_Yet : constant := 64;
777 -- In this example, the Size of A is considered to be specified prior
778 -- to the derivation, and thus inherited, even though the value is not
779 -- known at the time of derivation. To deal with this, we use two entity
780 -- flags. The flag Has_Derived_Rep_Aspects is set in the parent type (A
781 -- here), and then the flag May_Inherit_Delayed_Rep_Aspects is set in
782 -- the derived type (B here). If this flag is set when the derived type
783 -- is frozen, then this procedure is called to ensure proper inheritance
784 -- of all delayed aspects from the parent type. The derived type is E,
785 -- the argument to Analyze_Aspects_At_Freeze_Point. ASN is the first
786 -- aspect specification node in the Rep_Item chain for the parent type.
788 procedure Make_Pragma_From_Boolean_Aspect
(ASN
: Node_Id
);
789 -- Given an aspect specification node ASN whose expression is an
790 -- optional Boolean, this routines creates the corresponding pragma
791 -- at the freezing point.
793 ----------------------------------
794 -- Analyze_Aspect_Default_Value --
795 ----------------------------------
797 procedure Analyze_Aspect_Default_Value
(ASN
: Node_Id
) is
798 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(ASN
);
799 Ent
: constant Entity_Id
:= Entity
(ASN
);
800 Expr
: constant Node_Id
:= Expression
(ASN
);
801 Id
: constant Node_Id
:= Identifier
(ASN
);
804 Error_Msg_Name_1
:= Chars
(Id
);
806 if not Is_Type
(Ent
) then
807 Error_Msg_N
("aspect% can only apply to a type", Id
);
810 elsif not Is_First_Subtype
(Ent
) then
811 Error_Msg_N
("aspect% cannot apply to subtype", Id
);
814 elsif A_Id
= Aspect_Default_Value
815 and then not Is_Scalar_Type
(Ent
)
817 Error_Msg_N
("aspect% can only be applied to scalar type", Id
);
820 elsif A_Id
= Aspect_Default_Component_Value
then
821 if not Is_Array_Type
(Ent
) then
822 Error_Msg_N
("aspect% can only be applied to array type", Id
);
825 elsif not Is_Scalar_Type
(Component_Type
(Ent
)) then
826 Error_Msg_N
("aspect% requires scalar components", Id
);
831 Set_Has_Default_Aspect
(Base_Type
(Ent
));
833 if Is_Scalar_Type
(Ent
) then
834 Set_Default_Aspect_Value
(Base_Type
(Ent
), Expr
);
836 Set_Default_Aspect_Component_Value
(Base_Type
(Ent
), Expr
);
838 end Analyze_Aspect_Default_Value
;
840 ---------------------------------
841 -- Inherit_Delayed_Rep_Aspects --
842 ---------------------------------
844 procedure Inherit_Delayed_Rep_Aspects
(ASN
: Node_Id
) is
845 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(ASN
);
846 P
: constant Entity_Id
:= Entity
(ASN
);
847 -- Entithy for parent type
850 -- Item from Rep_Item chain
855 -- Loop through delayed aspects for the parent type
858 while Present
(N
) loop
859 if Nkind
(N
) = N_Aspect_Specification
then
860 exit when Entity
(N
) /= P
;
862 if Is_Delayed_Aspect
(N
) then
863 A
:= Get_Aspect_Id
(Chars
(Identifier
(N
)));
865 -- Process delayed rep aspect. For Boolean attributes it is
866 -- not possible to cancel an attribute once set (the attempt
867 -- to use an aspect with xxx => False is an error) for a
868 -- derived type. So for those cases, we do not have to check
869 -- if a clause has been given for the derived type, since it
870 -- is harmless to set it again if it is already set.
876 when Aspect_Alignment
=>
877 if not Has_Alignment_Clause
(E
) then
878 Set_Alignment
(E
, Alignment
(P
));
883 when Aspect_Atomic
=>
884 if Is_Atomic
(P
) then
890 when Aspect_Atomic_Components
=>
891 if Has_Atomic_Components
(P
) then
892 Set_Has_Atomic_Components
(Base_Type
(E
));
897 when Aspect_Bit_Order
=>
898 if Is_Record_Type
(E
)
899 and then No
(Get_Attribute_Definition_Clause
900 (E
, Attribute_Bit_Order
))
901 and then Reverse_Bit_Order
(P
)
903 Set_Reverse_Bit_Order
(Base_Type
(E
));
908 when Aspect_Component_Size
=>
910 and then not Has_Component_Size_Clause
(E
)
913 (Base_Type
(E
), Component_Size
(P
));
918 when Aspect_Machine_Radix
=>
919 if Is_Decimal_Fixed_Point_Type
(E
)
920 and then not Has_Machine_Radix_Clause
(E
)
922 Set_Machine_Radix_10
(E
, Machine_Radix_10
(P
));
925 -- Object_Size (also Size which also sets Object_Size)
927 when Aspect_Object_Size | Aspect_Size
=>
928 if not Has_Size_Clause
(E
)
930 No
(Get_Attribute_Definition_Clause
931 (E
, Attribute_Object_Size
))
933 Set_Esize
(E
, Esize
(P
));
939 if not Is_Packed
(E
) then
940 Set_Is_Packed
(Base_Type
(E
));
942 if Is_Bit_Packed_Array
(P
) then
943 Set_Is_Bit_Packed_Array
(Base_Type
(E
));
944 Set_Packed_Array_Impl_Type
945 (E
, Packed_Array_Impl_Type
(P
));
949 -- Scalar_Storage_Order
951 when Aspect_Scalar_Storage_Order
=>
952 if (Is_Record_Type
(E
) or else Is_Array_Type
(E
))
953 and then No
(Get_Attribute_Definition_Clause
954 (E
, Attribute_Scalar_Storage_Order
))
955 and then Reverse_Storage_Order
(P
)
957 Set_Reverse_Storage_Order
(Base_Type
(E
));
959 -- Clear default SSO indications, since the aspect
960 -- overrides the default.
962 Set_SSO_Set_Low_By_Default
(Base_Type
(E
), False);
963 Set_SSO_Set_High_By_Default
(Base_Type
(E
), False);
969 if Is_Fixed_Point_Type
(E
)
970 and then not Has_Small_Clause
(E
)
972 Set_Small_Value
(E
, Small_Value
(P
));
977 when Aspect_Storage_Size
=>
978 if (Is_Access_Type
(E
) or else Is_Task_Type
(E
))
979 and then not Has_Storage_Size_Clause
(E
)
981 Set_Storage_Size_Variable
982 (Base_Type
(E
), Storage_Size_Variable
(P
));
987 when Aspect_Value_Size
=>
989 -- Value_Size is never inherited, it is either set by
990 -- default, or it is explicitly set for the derived
991 -- type. So nothing to do here.
997 when Aspect_Volatile
=>
998 if Is_Volatile
(P
) then
1002 -- Volatile_Full_Access
1004 when Aspect_Volatile_Full_Access
=>
1005 if Is_Volatile_Full_Access
(P
) then
1006 Set_Is_Volatile_Full_Access
(E
);
1009 -- Volatile_Components
1011 when Aspect_Volatile_Components
=>
1012 if Has_Volatile_Components
(P
) then
1013 Set_Has_Volatile_Components
(Base_Type
(E
));
1016 -- That should be all the Rep Aspects
1019 pragma Assert
(Aspect_Delay
(A_Id
) /= Rep_Aspect
);
1026 N
:= Next_Rep_Item
(N
);
1028 end Inherit_Delayed_Rep_Aspects
;
1030 -------------------------------------
1031 -- Make_Pragma_From_Boolean_Aspect --
1032 -------------------------------------
1034 procedure Make_Pragma_From_Boolean_Aspect
(ASN
: Node_Id
) is
1035 Ident
: constant Node_Id
:= Identifier
(ASN
);
1036 A_Name
: constant Name_Id
:= Chars
(Ident
);
1037 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(A_Name
);
1038 Ent
: constant Entity_Id
:= Entity
(ASN
);
1039 Expr
: constant Node_Id
:= Expression
(ASN
);
1040 Loc
: constant Source_Ptr
:= Sloc
(ASN
);
1042 procedure Check_False_Aspect_For_Derived_Type
;
1043 -- This procedure checks for the case of a false aspect for a derived
1044 -- type, which improperly tries to cancel an aspect inherited from
1047 -----------------------------------------
1048 -- Check_False_Aspect_For_Derived_Type --
1049 -----------------------------------------
1051 procedure Check_False_Aspect_For_Derived_Type
is
1055 -- We are only checking derived types
1057 if not Is_Derived_Type
(E
) then
1061 Par
:= Nearest_Ancestor
(E
);
1064 when Aspect_Atomic | Aspect_Shared
=>
1065 if not Is_Atomic
(Par
) then
1069 when Aspect_Atomic_Components
=>
1070 if not Has_Atomic_Components
(Par
) then
1074 when Aspect_Discard_Names
=>
1075 if not Discard_Names
(Par
) then
1080 if not Is_Packed
(Par
) then
1084 when Aspect_Unchecked_Union
=>
1085 if not Is_Unchecked_Union
(Par
) then
1089 when Aspect_Volatile
=>
1090 if not Is_Volatile
(Par
) then
1094 when Aspect_Volatile_Components
=>
1095 if not Has_Volatile_Components
(Par
) then
1099 when Aspect_Volatile_Full_Access
=>
1100 if not Is_Volatile_Full_Access
(Par
) then
1108 -- Fall through means we are canceling an inherited aspect
1110 Error_Msg_Name_1
:= A_Name
;
1112 ("derived type& inherits aspect%, cannot cancel", Expr
, E
);
1113 end Check_False_Aspect_For_Derived_Type
;
1119 -- Start of processing for Make_Pragma_From_Boolean_Aspect
1122 -- Note that we know Expr is present, because for a missing Expr
1123 -- argument, we knew it was True and did not need to delay the
1124 -- evaluation to the freeze point.
1126 if Is_False
(Static_Boolean
(Expr
)) then
1127 Check_False_Aspect_For_Derived_Type
;
1132 Pragma_Identifier
=>
1133 Make_Identifier
(Sloc
(Ident
), Chars
(Ident
)),
1134 Pragma_Argument_Associations
=> New_List
(
1135 Make_Pragma_Argument_Association
(Sloc
(Ident
),
1136 Expression
=> New_Occurrence_Of
(Ent
, Sloc
(Ident
)))));
1138 Set_From_Aspect_Specification
(Prag
, True);
1139 Set_Corresponding_Aspect
(Prag
, ASN
);
1140 Set_Aspect_Rep_Item
(ASN
, Prag
);
1141 Set_Is_Delayed_Aspect
(Prag
);
1142 Set_Parent
(Prag
, ASN
);
1144 end Make_Pragma_From_Boolean_Aspect
;
1152 -- Start of processing for Analyze_Aspects_At_Freeze_Point
1155 -- Must be visible in current scope
1157 if not Scope_Within_Or_Same
(Current_Scope
, Scope
(E
)) then
1161 -- Look for aspect specification entries for this entity
1163 ASN
:= First_Rep_Item
(E
);
1164 while Present
(ASN
) loop
1165 if Nkind
(ASN
) = N_Aspect_Specification
then
1166 exit when Entity
(ASN
) /= E
;
1168 if Is_Delayed_Aspect
(ASN
) then
1169 A_Id
:= Get_Aspect_Id
(ASN
);
1173 -- For aspects whose expression is an optional Boolean, make
1174 -- the corresponding pragma at the freeze point.
1176 when Boolean_Aspects |
1177 Library_Unit_Aspects
=>
1179 -- Aspects Export and Import require special handling.
1180 -- Both are by definition Boolean and may benefit from
1181 -- forward references, however their expressions are
1182 -- treated as static. In addition, the syntax of their
1183 -- corresponding pragmas requires extra "pieces" which
1184 -- may also contain forward references. To account for
1185 -- all of this, the corresponding pragma is created by
1186 -- Analyze_Aspect_Export_Import, but is not analyzed as
1187 -- the complete analysis must happen now.
1189 if A_Id
= Aspect_Export
or else A_Id
= Aspect_Import
then
1192 -- Otherwise create a corresponding pragma
1195 Make_Pragma_From_Boolean_Aspect
(ASN
);
1198 -- Special handling for aspects that don't correspond to
1199 -- pragmas/attributes.
1201 when Aspect_Default_Value |
1202 Aspect_Default_Component_Value
=>
1204 -- Do not inherit aspect for anonymous base type of a
1205 -- scalar or array type, because they apply to the first
1206 -- subtype of the type, and will be processed when that
1207 -- first subtype is frozen.
1209 if Is_Derived_Type
(E
)
1210 and then not Comes_From_Source
(E
)
1211 and then E
/= First_Subtype
(E
)
1215 Analyze_Aspect_Default_Value
(ASN
);
1218 -- Ditto for iterator aspects, because the corresponding
1219 -- attributes may not have been analyzed yet.
1221 when Aspect_Constant_Indexing |
1222 Aspect_Variable_Indexing |
1223 Aspect_Default_Iterator |
1224 Aspect_Iterator_Element
=>
1225 Analyze
(Expression
(ASN
));
1227 if Etype
(Expression
(ASN
)) = Any_Type
then
1229 ("\aspect must be fully defined before & is frozen",
1233 when Aspect_Iterable
=>
1234 Validate_Iterable_Aspect
(E
, ASN
);
1240 Ritem
:= Aspect_Rep_Item
(ASN
);
1242 if Present
(Ritem
) then
1248 Next_Rep_Item
(ASN
);
1251 -- This is where we inherit delayed rep aspects from our parent. Note
1252 -- that if we fell out of the above loop with ASN non-empty, it means
1253 -- we hit an aspect for an entity other than E, and it must be the
1254 -- type from which we were derived.
1256 if May_Inherit_Delayed_Rep_Aspects
(E
) then
1257 Inherit_Delayed_Rep_Aspects
(ASN
);
1259 end Analyze_Aspects_At_Freeze_Point
;
1261 -----------------------------------
1262 -- Analyze_Aspect_Specifications --
1263 -----------------------------------
1265 procedure Analyze_Aspect_Specifications
(N
: Node_Id
; E
: Entity_Id
) is
1266 procedure Decorate
(Asp
: Node_Id
; Prag
: Node_Id
);
1267 -- Establish linkages between an aspect and its corresponding pragma
1269 procedure Insert_Pragma
1271 Is_Instance
: Boolean := False);
1272 -- Subsidiary to the analysis of aspects
1279 -- Initial_Condition
1288 -- Insert pragma Prag such that it mimics the placement of a source
1289 -- pragma of the same kind. Flag Is_Generic should be set when the
1290 -- context denotes a generic instance.
1296 procedure Decorate
(Asp
: Node_Id
; Prag
: Node_Id
) is
1298 Set_Aspect_Rep_Item
(Asp
, Prag
);
1299 Set_Corresponding_Aspect
(Prag
, Asp
);
1300 Set_From_Aspect_Specification
(Prag
);
1301 Set_Parent
(Prag
, Asp
);
1308 procedure Insert_Pragma
1310 Is_Instance
: Boolean := False)
1316 Inserted
: Boolean := False;
1319 -- When the aspect appears on an entry, package, protected unit,
1320 -- subprogram, or task unit body, insert the generated pragma at the
1321 -- top of the body declarations to emulate the behavior of a source
1324 -- package body Pack with Aspect is
1326 -- package body Pack is
1329 if Nkind_In
(N
, N_Entry_Body
,
1335 Decls
:= Declarations
(N
);
1339 Set_Declarations
(N
, Decls
);
1342 Prepend_To
(Decls
, Prag
);
1344 -- When the aspect is associated with a [generic] package declaration
1345 -- insert the generated pragma at the top of the visible declarations
1346 -- to emulate the behavior of a source pragma.
1348 -- package Pack with Aspect is
1353 elsif Nkind_In
(N
, N_Generic_Package_Declaration
,
1354 N_Package_Declaration
)
1356 Decls
:= Visible_Declarations
(Specification
(N
));
1360 Set_Visible_Declarations
(Specification
(N
), Decls
);
1363 -- The visible declarations of a generic instance have the
1364 -- following structure:
1366 -- <renamings of generic formals>
1367 -- <renamings of internally-generated spec and body>
1368 -- <first source declaration>
1370 -- Insert the pragma before the first source declaration by
1371 -- skipping the instance "header" to ensure proper visibility of
1375 Decl
:= First
(Decls
);
1376 while Present
(Decl
) loop
1377 if Comes_From_Source
(Decl
) then
1378 Insert_Before
(Decl
, Prag
);
1386 -- The pragma is placed after the instance "header"
1388 if not Inserted
then
1389 Append_To
(Decls
, Prag
);
1392 -- Otherwise this is not a generic instance
1395 Prepend_To
(Decls
, Prag
);
1398 -- When the aspect is associated with a protected unit declaration,
1399 -- insert the generated pragma at the top of the visible declarations
1400 -- the emulate the behavior of a source pragma.
1402 -- protected [type] Prot with Aspect is
1404 -- protected [type] Prot is
1407 elsif Nkind
(N
) = N_Protected_Type_Declaration
then
1408 Def
:= Protected_Definition
(N
);
1412 Make_Protected_Definition
(Sloc
(N
),
1413 Visible_Declarations
=> New_List
,
1414 End_Label
=> Empty
);
1416 Set_Protected_Definition
(N
, Def
);
1419 Decls
:= Visible_Declarations
(Def
);
1423 Set_Visible_Declarations
(Def
, Decls
);
1426 Prepend_To
(Decls
, Prag
);
1428 -- When the aspect is associated with a task unit declaration, insert
1429 -- insert the generated pragma at the top of the visible declarations
1430 -- the emulate the behavior of a source pragma.
1432 -- task [type] Prot with Aspect is
1434 -- task [type] Prot is
1437 elsif Nkind
(N
) = N_Task_Type_Declaration
then
1438 Def
:= Task_Definition
(N
);
1442 Make_Task_Definition
(Sloc
(N
),
1443 Visible_Declarations
=> New_List
,
1444 End_Label
=> Empty
);
1446 Set_Task_Definition
(N
, Def
);
1449 Decls
:= Visible_Declarations
(Def
);
1453 Set_Visible_Declarations
(Def
, Decls
);
1456 Prepend_To
(Decls
, Prag
);
1458 -- When the context is a library unit, the pragma is added to the
1459 -- Pragmas_After list.
1461 elsif Nkind
(Parent
(N
)) = N_Compilation_Unit
then
1462 Aux
:= Aux_Decls_Node
(Parent
(N
));
1464 if No
(Pragmas_After
(Aux
)) then
1465 Set_Pragmas_After
(Aux
, New_List
);
1468 Prepend
(Prag
, Pragmas_After
(Aux
));
1470 -- Default, the pragma is inserted after the context
1473 Insert_After
(N
, Prag
);
1483 L
: constant List_Id
:= Aspect_Specifications
(N
);
1485 Ins_Node
: Node_Id
:= N
;
1486 -- Insert pragmas/attribute definition clause after this node when no
1487 -- delayed analysis is required.
1489 -- Start of processing for Analyze_Aspect_Specifications
1492 -- The general processing involves building an attribute definition
1493 -- clause or a pragma node that corresponds to the aspect. Then in order
1494 -- to delay the evaluation of this aspect to the freeze point, we attach
1495 -- the corresponding pragma/attribute definition clause to the aspect
1496 -- specification node, which is then placed in the Rep Item chain. In
1497 -- this case we mark the entity by setting the flag Has_Delayed_Aspects
1498 -- and we evaluate the rep item at the freeze point. When the aspect
1499 -- doesn't have a corresponding pragma/attribute definition clause, then
1500 -- its analysis is simply delayed at the freeze point.
1502 -- Some special cases don't require delay analysis, thus the aspect is
1503 -- analyzed right now.
1505 -- Note that there is a special handling for Pre, Post, Test_Case,
1506 -- Contract_Cases aspects. In these cases, we do not have to worry
1507 -- about delay issues, since the pragmas themselves deal with delay
1508 -- of visibility for the expression analysis. Thus, we just insert
1509 -- the pragma after the node N.
1511 pragma Assert
(Present
(L
));
1513 -- Loop through aspects
1515 Aspect
:= First
(L
);
1516 Aspect_Loop
: while Present
(Aspect
) loop
1517 Analyze_One_Aspect
: declare
1518 Expr
: constant Node_Id
:= Expression
(Aspect
);
1519 Id
: constant Node_Id
:= Identifier
(Aspect
);
1520 Loc
: constant Source_Ptr
:= Sloc
(Aspect
);
1521 Nam
: constant Name_Id
:= Chars
(Id
);
1522 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Nam
);
1525 Delay_Required
: Boolean;
1526 -- Set False if delay is not required
1528 Eloc
: Source_Ptr
:= No_Location
;
1529 -- Source location of expression, modified when we split PPC's. It
1530 -- is set below when Expr is present.
1532 procedure Analyze_Aspect_Convention
;
1533 -- Perform analysis of aspect Convention
1535 procedure Analyze_Aspect_Export_Import
;
1536 -- Perform analysis of aspects Export or Import
1538 procedure Analyze_Aspect_External_Link_Name
;
1539 -- Perform analysis of aspects External_Name or Link_Name
1541 procedure Analyze_Aspect_Implicit_Dereference
;
1542 -- Perform analysis of the Implicit_Dereference aspects
1544 procedure Make_Aitem_Pragma
1545 (Pragma_Argument_Associations
: List_Id
;
1546 Pragma_Name
: Name_Id
);
1547 -- This is a wrapper for Make_Pragma used for converting aspects
1548 -- to pragmas. It takes care of Sloc (set from Loc) and building
1549 -- the pragma identifier from the given name. In addition the
1550 -- flags Class_Present and Split_PPC are set from the aspect
1551 -- node, as well as Is_Ignored. This routine also sets the
1552 -- From_Aspect_Specification in the resulting pragma node to
1553 -- True, and sets Corresponding_Aspect to point to the aspect.
1554 -- The resulting pragma is assigned to Aitem.
1556 -------------------------------
1557 -- Analyze_Aspect_Convention --
1558 -------------------------------
1560 procedure Analyze_Aspect_Convention
is
1569 -- Obtain all interfacing aspects that apply to the related
1572 Get_Interfacing_Aspects
1573 (Iface_Asp
=> Aspect
,
1574 Conv_Asp
=> Dummy_1
,
1581 -- The related entity is subject to aspect Export or Import.
1582 -- Do not process Convention now because it must be analysed
1583 -- as part of Export or Import.
1585 if Present
(Expo
) or else Present
(Imp
) then
1588 -- Otherwise Convention appears by itself
1591 -- The aspect specifies a particular convention
1593 if Present
(Expr
) then
1594 Conv
:= New_Copy_Tree
(Expr
);
1596 -- Otherwise assume convention Ada
1599 Conv
:= Make_Identifier
(Loc
, Name_Ada
);
1603 -- pragma Convention (<Conv>, <E>);
1606 (Pragma_Name
=> Name_Convention
,
1607 Pragma_Argument_Associations
=> New_List
(
1608 Make_Pragma_Argument_Association
(Loc
,
1609 Expression
=> Conv
),
1610 Make_Pragma_Argument_Association
(Loc
,
1611 Expression
=> New_Occurrence_Of
(E
, Loc
))));
1613 Decorate
(Aspect
, Aitem
);
1614 Insert_Pragma
(Aitem
);
1616 end Analyze_Aspect_Convention
;
1618 ----------------------------------
1619 -- Analyze_Aspect_Export_Import --
1620 ----------------------------------
1622 procedure Analyze_Aspect_Export_Import
is
1630 -- Obtain all interfacing aspects that apply to the related
1633 Get_Interfacing_Aspects
1634 (Iface_Asp
=> Aspect
,
1635 Conv_Asp
=> Dummy_1
,
1642 -- The related entity cannot be subject to both aspects Export
1645 if Present
(Expo
) and then Present
(Imp
) then
1647 ("incompatible interfacing aspects given for &", E
);
1648 Error_Msg_Sloc
:= Sloc
(Expo
);
1649 Error_Msg_N
("\aspect `Export` #", E
);
1650 Error_Msg_Sloc
:= Sloc
(Imp
);
1651 Error_Msg_N
("\aspect `Import` #", E
);
1654 -- A variable is most likely modified from the outside. Take
1655 -- Take the optimistic approach to avoid spurious errors.
1657 if Ekind
(E
) = E_Variable
then
1658 Set_Never_Set_In_Source
(E
, False);
1661 -- Resolve the expression of an Import or Export here, and
1662 -- require it to be of type Boolean and static. This is not
1663 -- quite right, because in general this should be delayed,
1664 -- but that seems tricky for these, because normally Boolean
1665 -- aspects are replaced with pragmas at the freeze point in
1666 -- Make_Pragma_From_Boolean_Aspect.
1668 if not Present
(Expr
)
1669 or else Is_True
(Static_Boolean
(Expr
))
1671 if A_Id
= Aspect_Import
then
1672 Set_Has_Completion
(E
);
1673 Set_Is_Imported
(E
);
1675 -- An imported object cannot be explicitly initialized
1677 if Nkind
(N
) = N_Object_Declaration
1678 and then Present
(Expression
(N
))
1681 ("imported entities cannot be initialized "
1682 & "(RM B.1(24))", Expression
(N
));
1686 pragma Assert
(A_Id
= Aspect_Export
);
1687 Set_Is_Exported
(E
);
1690 -- Create the proper form of pragma Export or Import taking
1691 -- into account Conversion, External_Name, and Link_Name.
1693 Aitem
:= Build_Export_Import_Pragma
(Aspect
, E
);
1695 -- Otherwise the expression is either False or erroneous. There
1696 -- is no corresponding pragma.
1701 end Analyze_Aspect_Export_Import
;
1703 ---------------------------------------
1704 -- Analyze_Aspect_External_Link_Name --
1705 ---------------------------------------
1707 procedure Analyze_Aspect_External_Link_Name
is
1715 -- Obtain all interfacing aspects that apply to the related
1718 Get_Interfacing_Aspects
1719 (Iface_Asp
=> Aspect
,
1720 Conv_Asp
=> Dummy_1
,
1727 -- Ensure that aspect External_Name applies to aspect Export or
1730 if A_Id
= Aspect_External_Name
then
1731 if No
(Expo
) and then No
(Imp
) then
1733 ("aspect `External_Name` requires aspect `Import` or "
1734 & "`Export`", Aspect
);
1737 -- Otherwise ensure that aspect Link_Name applies to aspect
1738 -- Export or Import.
1741 pragma Assert
(A_Id
= Aspect_Link_Name
);
1742 if No
(Expo
) and then No
(Imp
) then
1744 ("aspect `Link_Name` requires aspect `Import` or "
1745 & "`Export`", Aspect
);
1748 end Analyze_Aspect_External_Link_Name
;
1750 -----------------------------------------
1751 -- Analyze_Aspect_Implicit_Dereference --
1752 -----------------------------------------
1754 procedure Analyze_Aspect_Implicit_Dereference
is
1756 Parent_Disc
: Entity_Id
;
1759 if not Is_Type
(E
) or else not Has_Discriminants
(E
) then
1761 ("aspect must apply to a type with discriminants", Expr
);
1763 elsif not Is_Entity_Name
(Expr
) then
1765 ("aspect must name a discriminant of current type", Expr
);
1768 Disc
:= First_Discriminant
(E
);
1769 while Present
(Disc
) loop
1770 if Chars
(Expr
) = Chars
(Disc
)
1771 and then Ekind
(Etype
(Disc
)) =
1772 E_Anonymous_Access_Type
1774 Set_Has_Implicit_Dereference
(E
);
1775 Set_Has_Implicit_Dereference
(Disc
);
1779 Next_Discriminant
(Disc
);
1782 -- Error if no proper access discriminant
1785 Error_Msg_NE
("not an access discriminant of&", Expr
, E
);
1790 -- For a type extension, check whether parent has a
1791 -- reference discriminant, to verify that use is proper.
1793 if Is_Derived_Type
(E
)
1794 and then Has_Discriminants
(Etype
(E
))
1796 Parent_Disc
:= Get_Reference_Discriminant
(Etype
(E
));
1798 if Present
(Parent_Disc
)
1799 and then Corresponding_Discriminant
(Disc
) /= Parent_Disc
1802 ("reference discriminant does not match discriminant "
1803 & "of parent type", Expr
);
1806 end Analyze_Aspect_Implicit_Dereference
;
1808 -----------------------
1809 -- Make_Aitem_Pragma --
1810 -----------------------
1812 procedure Make_Aitem_Pragma
1813 (Pragma_Argument_Associations
: List_Id
;
1814 Pragma_Name
: Name_Id
)
1816 Args
: List_Id
:= Pragma_Argument_Associations
;
1819 -- We should never get here if aspect was disabled
1821 pragma Assert
(not Is_Disabled
(Aspect
));
1823 -- Certain aspects allow for an optional name or expression. Do
1824 -- not generate a pragma with empty argument association list.
1826 if No
(Args
) or else No
(Expression
(First
(Args
))) then
1834 Pragma_Argument_Associations
=> Args
,
1835 Pragma_Identifier
=>
1836 Make_Identifier
(Sloc
(Id
), Pragma_Name
),
1837 Class_Present
=> Class_Present
(Aspect
),
1838 Split_PPC
=> Split_PPC
(Aspect
));
1840 -- Set additional semantic fields
1842 if Is_Ignored
(Aspect
) then
1843 Set_Is_Ignored
(Aitem
);
1844 elsif Is_Checked
(Aspect
) then
1845 Set_Is_Checked
(Aitem
);
1848 Set_Corresponding_Aspect
(Aitem
, Aspect
);
1849 Set_From_Aspect_Specification
(Aitem
);
1850 end Make_Aitem_Pragma
;
1852 -- Start of processing for Analyze_One_Aspect
1855 -- Skip aspect if already analyzed, to avoid looping in some cases
1857 if Analyzed
(Aspect
) then
1861 -- Skip looking at aspect if it is totally disabled. Just mark it
1862 -- as such for later reference in the tree. This also sets the
1863 -- Is_Ignored and Is_Checked flags appropriately.
1865 Check_Applicable_Policy
(Aspect
);
1867 if Is_Disabled
(Aspect
) then
1871 -- Set the source location of expression, used in the case of
1872 -- a failed precondition/postcondition or invariant. Note that
1873 -- the source location of the expression is not usually the best
1874 -- choice here. For example, it gets located on the last AND
1875 -- keyword in a chain of boolean expressiond AND'ed together.
1876 -- It is best to put the message on the first character of the
1877 -- assertion, which is the effect of the First_Node call here.
1879 if Present
(Expr
) then
1880 Eloc
:= Sloc
(First_Node
(Expr
));
1883 -- Check restriction No_Implementation_Aspect_Specifications
1885 if Implementation_Defined_Aspect
(A_Id
) then
1887 (No_Implementation_Aspect_Specifications
, Aspect
);
1890 -- Check restriction No_Specification_Of_Aspect
1892 Check_Restriction_No_Specification_Of_Aspect
(Aspect
);
1894 -- Mark aspect analyzed (actual analysis is delayed till later)
1896 Set_Analyzed
(Aspect
);
1897 Set_Entity
(Aspect
, E
);
1898 Ent
:= New_Occurrence_Of
(E
, Sloc
(Id
));
1900 -- Check for duplicate aspect. Note that the Comes_From_Source
1901 -- test allows duplicate Pre/Post's that we generate internally
1902 -- to escape being flagged here.
1904 if No_Duplicates_Allowed
(A_Id
) then
1906 while Anod
/= Aspect
loop
1907 if Comes_From_Source
(Aspect
)
1908 and then Same_Aspect
(A_Id
, Get_Aspect_Id
(Anod
))
1910 Error_Msg_Name_1
:= Nam
;
1911 Error_Msg_Sloc
:= Sloc
(Anod
);
1913 -- Case of same aspect specified twice
1915 if Class_Present
(Anod
) = Class_Present
(Aspect
) then
1916 if not Class_Present
(Anod
) then
1918 ("aspect% for & previously given#",
1922 ("aspect `%''Class` for & previously given#",
1932 -- Check some general restrictions on language defined aspects
1934 if not Implementation_Defined_Aspect
(A_Id
) then
1935 Error_Msg_Name_1
:= Nam
;
1937 -- Not allowed for renaming declarations
1939 if Nkind
(N
) in N_Renaming_Declaration
then
1941 ("aspect % not allowed for renaming declaration",
1945 -- Not allowed for formal type declarations
1947 if Nkind
(N
) = N_Formal_Type_Declaration
then
1949 ("aspect % not allowed for formal type declaration",
1954 -- Copy expression for later processing by the procedures
1955 -- Check_Aspect_At_[Freeze_Point | End_Of_Declarations]
1957 Set_Entity
(Id
, New_Copy_Tree
(Expr
));
1959 -- Set Delay_Required as appropriate to aspect
1961 case Aspect_Delay
(A_Id
) is
1962 when Always_Delay
=>
1963 Delay_Required
:= True;
1966 Delay_Required
:= False;
1970 -- If expression has the form of an integer literal, then
1971 -- do not delay, since we know the value cannot change.
1972 -- This optimization catches most rep clause cases.
1974 -- For Boolean aspects, don't delay if no expression
1976 if A_Id
in Boolean_Aspects
and then No
(Expr
) then
1977 Delay_Required
:= False;
1979 -- For non-Boolean aspects, don't delay if integer literal
1981 elsif A_Id
not in Boolean_Aspects
1982 and then Present
(Expr
)
1983 and then Nkind
(Expr
) = N_Integer_Literal
1985 Delay_Required
:= False;
1987 -- All other cases are delayed
1990 Delay_Required
:= True;
1991 Set_Has_Delayed_Rep_Aspects
(E
);
1995 -- Processing based on specific aspect
1998 when Aspect_Unimplemented
=>
1999 null; -- ??? temp for now
2001 -- No_Aspect should be impossible
2004 raise Program_Error
;
2006 -- Case 1: Aspects corresponding to attribute definition
2009 when Aspect_Address |
2012 Aspect_Component_Size |
2013 Aspect_Constant_Indexing |
2014 Aspect_Default_Iterator |
2015 Aspect_Dispatching_Domain |
2016 Aspect_External_Tag |
2019 Aspect_Iterator_Element |
2020 Aspect_Machine_Radix |
2021 Aspect_Object_Size |
2024 Aspect_Scalar_Storage_Order |
2027 Aspect_Simple_Storage_Pool |
2028 Aspect_Storage_Pool |
2029 Aspect_Stream_Size |
2031 Aspect_Variable_Indexing |
2034 -- Indexing aspects apply only to tagged type
2036 if (A_Id
= Aspect_Constant_Indexing
2038 A_Id
= Aspect_Variable_Indexing
)
2039 and then not (Is_Type
(E
)
2040 and then Is_Tagged_Type
(E
))
2043 ("indexing aspect can only apply to a tagged type",
2048 -- For the case of aspect Address, we don't consider that we
2049 -- know the entity is never set in the source, since it is
2050 -- is likely aliasing is occurring.
2052 -- Note: one might think that the analysis of the resulting
2053 -- attribute definition clause would take care of that, but
2054 -- that's not the case since it won't be from source.
2056 if A_Id
= Aspect_Address
then
2057 Set_Never_Set_In_Source
(E
, False);
2060 -- Correctness of the profile of a stream operation is
2061 -- verified at the freeze point, but we must detect the
2062 -- illegal specification of this aspect for a subtype now,
2063 -- to prevent malformed rep_item chains.
2065 if A_Id
= Aspect_Input
or else
2066 A_Id
= Aspect_Output
or else
2067 A_Id
= Aspect_Read
or else
2070 if not Is_First_Subtype
(E
) then
2072 ("local name must be a first subtype", Aspect
);
2075 -- If stream aspect applies to the class-wide type,
2076 -- the generated attribute definition applies to the
2077 -- class-wide type as well.
2079 elsif Class_Present
(Aspect
) then
2081 Make_Attribute_Reference
(Loc
,
2083 Attribute_Name
=> Name_Class
);
2087 -- Construct the attribute definition clause
2090 Make_Attribute_Definition_Clause
(Loc
,
2092 Chars
=> Chars
(Id
),
2093 Expression
=> Relocate_Node
(Expr
));
2095 -- If the address is specified, then we treat the entity as
2096 -- referenced, to avoid spurious warnings. This is analogous
2097 -- to what is done with an attribute definition clause, but
2098 -- here we don't want to generate a reference because this
2099 -- is the point of definition of the entity.
2101 if A_Id
= Aspect_Address
then
2105 -- Case 2: Aspects corresponding to pragmas
2107 -- Case 2a: Aspects corresponding to pragmas with two
2108 -- arguments, where the first argument is a local name
2109 -- referring to the entity, and the second argument is the
2110 -- aspect definition expression.
2112 -- Linker_Section/Suppress/Unsuppress
2114 when Aspect_Linker_Section |
2116 Aspect_Unsuppress
=>
2119 (Pragma_Argument_Associations
=> New_List
(
2120 Make_Pragma_Argument_Association
(Loc
,
2121 Expression
=> New_Occurrence_Of
(E
, Loc
)),
2122 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2123 Expression
=> Relocate_Node
(Expr
))),
2124 Pragma_Name
=> Chars
(Id
));
2128 -- Corresponds to pragma Implemented, construct the pragma
2130 when Aspect_Synchronization
=>
2132 (Pragma_Argument_Associations
=> New_List
(
2133 Make_Pragma_Argument_Association
(Loc
,
2134 Expression
=> New_Occurrence_Of
(E
, Loc
)),
2135 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2136 Expression
=> Relocate_Node
(Expr
))),
2137 Pragma_Name
=> Name_Implemented
);
2141 when Aspect_Attach_Handler
=>
2143 (Pragma_Argument_Associations
=> New_List
(
2144 Make_Pragma_Argument_Association
(Sloc
(Ent
),
2146 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2147 Expression
=> Relocate_Node
(Expr
))),
2148 Pragma_Name
=> Name_Attach_Handler
);
2150 -- We need to insert this pragma into the tree to get proper
2151 -- processing and to look valid from a placement viewpoint.
2153 Insert_Pragma
(Aitem
);
2156 -- Dynamic_Predicate, Predicate, Static_Predicate
2158 when Aspect_Dynamic_Predicate |
2160 Aspect_Static_Predicate
=>
2162 -- These aspects apply only to subtypes
2164 if not Is_Type
(E
) then
2166 ("predicate can only be specified for a subtype",
2170 elsif Is_Incomplete_Type
(E
) then
2172 ("predicate cannot apply to incomplete view", Aspect
);
2176 -- Construct the pragma (always a pragma Predicate, with
2177 -- flags recording whether it is static/dynamic). We also
2178 -- set flags recording this in the type itself.
2181 (Pragma_Argument_Associations
=> New_List
(
2182 Make_Pragma_Argument_Association
(Sloc
(Ent
),
2184 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2185 Expression
=> Relocate_Node
(Expr
))),
2186 Pragma_Name
=> Name_Predicate
);
2188 -- Mark type has predicates, and remember what kind of
2189 -- aspect lead to this predicate (we need this to access
2190 -- the right set of check policies later on).
2192 Set_Has_Predicates
(E
);
2194 if A_Id
= Aspect_Dynamic_Predicate
then
2195 Set_Has_Dynamic_Predicate_Aspect
(E
);
2196 elsif A_Id
= Aspect_Static_Predicate
then
2197 Set_Has_Static_Predicate_Aspect
(E
);
2200 -- If the type is private, indicate that its completion
2201 -- has a freeze node, because that is the one that will
2202 -- be visible at freeze time.
2204 if Is_Private_Type
(E
) and then Present
(Full_View
(E
)) then
2205 Set_Has_Predicates
(Full_View
(E
));
2207 if A_Id
= Aspect_Dynamic_Predicate
then
2208 Set_Has_Dynamic_Predicate_Aspect
(Full_View
(E
));
2209 elsif A_Id
= Aspect_Static_Predicate
then
2210 Set_Has_Static_Predicate_Aspect
(Full_View
(E
));
2213 Set_Has_Delayed_Aspects
(Full_View
(E
));
2214 Ensure_Freeze_Node
(Full_View
(E
));
2217 -- Predicate_Failure
2219 when Aspect_Predicate_Failure
=>
2221 -- This aspect applies only to subtypes
2223 if not Is_Type
(E
) then
2225 ("predicate can only be specified for a subtype",
2229 elsif Is_Incomplete_Type
(E
) then
2231 ("predicate cannot apply to incomplete view", Aspect
);
2235 -- Construct the pragma
2238 (Pragma_Argument_Associations
=> New_List
(
2239 Make_Pragma_Argument_Association
(Sloc
(Ent
),
2241 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2242 Expression
=> Relocate_Node
(Expr
))),
2243 Pragma_Name
=> Name_Predicate_Failure
);
2245 Set_Has_Predicates
(E
);
2247 -- If the type is private, indicate that its completion
2248 -- has a freeze node, because that is the one that will
2249 -- be visible at freeze time.
2251 if Is_Private_Type
(E
) and then Present
(Full_View
(E
)) then
2252 Set_Has_Predicates
(Full_View
(E
));
2253 Set_Has_Delayed_Aspects
(Full_View
(E
));
2254 Ensure_Freeze_Node
(Full_View
(E
));
2257 -- Case 2b: Aspects corresponding to pragmas with two
2258 -- arguments, where the second argument is a local name
2259 -- referring to the entity, and the first argument is the
2260 -- aspect definition expression.
2264 when Aspect_Convention
=>
2265 Analyze_Aspect_Convention
;
2268 -- External_Name, Link_Name
2270 when Aspect_External_Name |
2272 Analyze_Aspect_External_Link_Name
;
2275 -- CPU, Interrupt_Priority, Priority
2277 -- These three aspects can be specified for a subprogram spec
2278 -- or body, in which case we analyze the expression and export
2279 -- the value of the aspect.
2281 -- Previously, we generated an equivalent pragma for bodies
2282 -- (note that the specs cannot contain these pragmas). The
2283 -- pragma was inserted ahead of local declarations, rather than
2284 -- after the body. This leads to a certain duplication between
2285 -- the processing performed for the aspect and the pragma, but
2286 -- given the straightforward handling required it is simpler
2287 -- to duplicate than to translate the aspect in the spec into
2288 -- a pragma in the declarative part of the body.
2291 Aspect_Interrupt_Priority |
2294 if Nkind_In
(N
, N_Subprogram_Body
,
2295 N_Subprogram_Declaration
)
2297 -- Analyze the aspect expression
2299 Analyze_And_Resolve
(Expr
, Standard_Integer
);
2301 -- Interrupt_Priority aspect not allowed for main
2302 -- subprograms. RM D.1 does not forbid this explicitly,
2303 -- but RM J.15.11(6/3) does not permit pragma
2304 -- Interrupt_Priority for subprograms.
2306 if A_Id
= Aspect_Interrupt_Priority
then
2308 ("Interrupt_Priority aspect cannot apply to "
2309 & "subprogram", Expr
);
2311 -- The expression must be static
2313 elsif not Is_OK_Static_Expression
(Expr
) then
2314 Flag_Non_Static_Expr
2315 ("aspect requires static expression!", Expr
);
2317 -- Check whether this is the main subprogram. Issue a
2318 -- warning only if it is obviously not a main program
2319 -- (when it has parameters or when the subprogram is
2320 -- within a package).
2322 elsif Present
(Parameter_Specifications
2323 (Specification
(N
)))
2324 or else not Is_Compilation_Unit
(Defining_Entity
(N
))
2326 -- See RM D.1(14/3) and D.16(12/3)
2329 ("aspect applied to subprogram other than the "
2330 & "main subprogram has no effect??", Expr
);
2332 -- Otherwise check in range and export the value
2334 -- For the CPU aspect
2336 elsif A_Id
= Aspect_CPU
then
2337 if Is_In_Range
(Expr
, RTE
(RE_CPU_Range
)) then
2339 -- Value is correct so we export the value to make
2340 -- it available at execution time.
2343 (Main_Unit
, UI_To_Int
(Expr_Value
(Expr
)));
2347 ("main subprogram CPU is out of range", Expr
);
2350 -- For the Priority aspect
2352 elsif A_Id
= Aspect_Priority
then
2353 if Is_In_Range
(Expr
, RTE
(RE_Priority
)) then
2355 -- Value is correct so we export the value to make
2356 -- it available at execution time.
2359 (Main_Unit
, UI_To_Int
(Expr_Value
(Expr
)));
2361 -- Ignore pragma if Relaxed_RM_Semantics to support
2362 -- other targets/non GNAT compilers.
2364 elsif not Relaxed_RM_Semantics
then
2366 ("main subprogram priority is out of range",
2371 -- Load an arbitrary entity from System.Tasking.Stages
2372 -- or System.Tasking.Restricted.Stages (depending on
2373 -- the supported profile) to make sure that one of these
2374 -- packages is implicitly with'ed, since we need to have
2375 -- the tasking run time active for the pragma Priority to
2376 -- have any effect. Previously we with'ed the package
2377 -- System.Tasking, but this package does not trigger the
2378 -- required initialization of the run-time library.
2381 Discard
: Entity_Id
;
2383 if Restricted_Profile
then
2384 Discard
:= RTE
(RE_Activate_Restricted_Tasks
);
2386 Discard
:= RTE
(RE_Activate_Tasks
);
2390 -- Handling for these Aspects in subprograms is complete
2394 -- For tasks pass the aspect as an attribute
2398 Make_Attribute_Definition_Clause
(Loc
,
2400 Chars
=> Chars
(Id
),
2401 Expression
=> Relocate_Node
(Expr
));
2406 when Aspect_Warnings
=>
2408 (Pragma_Argument_Associations
=> New_List
(
2409 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2410 Expression
=> Relocate_Node
(Expr
)),
2411 Make_Pragma_Argument_Association
(Loc
,
2412 Expression
=> New_Occurrence_Of
(E
, Loc
))),
2413 Pragma_Name
=> Chars
(Id
));
2415 Decorate
(Aspect
, Aitem
);
2416 Insert_Pragma
(Aitem
);
2419 -- Case 2c: Aspects corresponding to pragmas with three
2422 -- Invariant aspects have a first argument that references the
2423 -- entity, a second argument that is the expression and a third
2424 -- argument that is an appropriate message.
2426 -- Invariant, Type_Invariant
2428 when Aspect_Invariant |
2429 Aspect_Type_Invariant
=>
2431 -- Analysis of the pragma will verify placement legality:
2432 -- an invariant must apply to a private type, or appear in
2433 -- the private part of a spec and apply to a completion.
2436 (Pragma_Argument_Associations
=> New_List
(
2437 Make_Pragma_Argument_Association
(Sloc
(Ent
),
2439 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2440 Expression
=> Relocate_Node
(Expr
))),
2441 Pragma_Name
=> Name_Invariant
);
2443 -- Add message unless exception messages are suppressed
2445 if not Opt
.Exception_Locations_Suppressed
then
2446 Append_To
(Pragma_Argument_Associations
(Aitem
),
2447 Make_Pragma_Argument_Association
(Eloc
,
2448 Chars
=> Name_Message
,
2450 Make_String_Literal
(Eloc
,
2451 Strval
=> "failed invariant from "
2452 & Build_Location_String
(Eloc
))));
2455 -- For Invariant case, insert immediately after the entity
2456 -- declaration. We do not have to worry about delay issues
2457 -- since the pragma processing takes care of this.
2459 Delay_Required
:= False;
2461 -- Case 2d : Aspects that correspond to a pragma with one
2466 -- Aspect Abstract_State introduces implicit declarations for
2467 -- all state abstraction entities it defines. To emulate this
2468 -- behavior, insert the pragma at the beginning of the visible
2469 -- declarations of the related package so that it is analyzed
2472 when Aspect_Abstract_State
=> Abstract_State
: declare
2473 Context
: Node_Id
:= N
;
2476 -- When aspect Abstract_State appears on a generic package,
2477 -- it is propageted to the package instance. The context in
2478 -- this case is the instance spec.
2480 if Nkind
(Context
) = N_Package_Instantiation
then
2481 Context
:= Instance_Spec
(Context
);
2484 if Nkind_In
(Context
, N_Generic_Package_Declaration
,
2485 N_Package_Declaration
)
2488 (Pragma_Argument_Associations
=> New_List
(
2489 Make_Pragma_Argument_Association
(Loc
,
2490 Expression
=> Relocate_Node
(Expr
))),
2491 Pragma_Name
=> Name_Abstract_State
);
2493 Decorate
(Aspect
, Aitem
);
2497 Is_Generic_Instance
(Defining_Entity
(Context
)));
2501 ("aspect & must apply to a package declaration",
2508 -- Aspect Async_Readers is never delayed because it is
2509 -- equivalent to a source pragma which appears after the
2510 -- related object declaration.
2512 when Aspect_Async_Readers
=>
2514 (Pragma_Argument_Associations
=> New_List
(
2515 Make_Pragma_Argument_Association
(Loc
,
2516 Expression
=> Relocate_Node
(Expr
))),
2517 Pragma_Name
=> Name_Async_Readers
);
2519 Decorate
(Aspect
, Aitem
);
2520 Insert_Pragma
(Aitem
);
2523 -- Aspect Async_Writers is never delayed because it is
2524 -- equivalent to a source pragma which appears after the
2525 -- related object declaration.
2527 when Aspect_Async_Writers
=>
2529 (Pragma_Argument_Associations
=> New_List
(
2530 Make_Pragma_Argument_Association
(Loc
,
2531 Expression
=> Relocate_Node
(Expr
))),
2532 Pragma_Name
=> Name_Async_Writers
);
2534 Decorate
(Aspect
, Aitem
);
2535 Insert_Pragma
(Aitem
);
2538 -- Aspect Constant_After_Elaboration is never delayed because
2539 -- it is equivalent to a source pragma which appears after the
2540 -- related object declaration.
2542 when Aspect_Constant_After_Elaboration
=>
2544 (Pragma_Argument_Associations
=> New_List
(
2545 Make_Pragma_Argument_Association
(Loc
,
2546 Expression
=> Relocate_Node
(Expr
))),
2548 Name_Constant_After_Elaboration
);
2550 Decorate
(Aspect
, Aitem
);
2551 Insert_Pragma
(Aitem
);
2554 -- Aspect Default_Internal_Condition is never delayed because
2555 -- it is equivalent to a source pragma which appears after the
2556 -- related private type. To deal with forward references, the
2557 -- generated pragma is stored in the rep chain of the related
2558 -- private type as types do not carry contracts. The pragma is
2559 -- wrapped inside of a procedure at the freeze point of the
2560 -- private type's full view.
2562 when Aspect_Default_Initial_Condition
=>
2564 (Pragma_Argument_Associations
=> New_List
(
2565 Make_Pragma_Argument_Association
(Loc
,
2566 Expression
=> Relocate_Node
(Expr
))),
2568 Name_Default_Initial_Condition
);
2570 Decorate
(Aspect
, Aitem
);
2571 Insert_Pragma
(Aitem
);
2574 -- Default_Storage_Pool
2576 when Aspect_Default_Storage_Pool
=>
2578 (Pragma_Argument_Associations
=> New_List
(
2579 Make_Pragma_Argument_Association
(Loc
,
2580 Expression
=> Relocate_Node
(Expr
))),
2582 Name_Default_Storage_Pool
);
2584 Decorate
(Aspect
, Aitem
);
2585 Insert_Pragma
(Aitem
);
2590 -- Aspect Depends is never delayed because it is equivalent to
2591 -- a source pragma which appears after the related subprogram.
2592 -- To deal with forward references, the generated pragma is
2593 -- stored in the contract of the related subprogram and later
2594 -- analyzed at the end of the declarative region. See routine
2595 -- Analyze_Depends_In_Decl_Part for details.
2597 when Aspect_Depends
=>
2599 (Pragma_Argument_Associations
=> New_List
(
2600 Make_Pragma_Argument_Association
(Loc
,
2601 Expression
=> Relocate_Node
(Expr
))),
2602 Pragma_Name
=> Name_Depends
);
2604 Decorate
(Aspect
, Aitem
);
2605 Insert_Pragma
(Aitem
);
2608 -- Aspect Effecitve_Reads is never delayed because it is
2609 -- equivalent to a source pragma which appears after the
2610 -- related object declaration.
2612 when Aspect_Effective_Reads
=>
2614 (Pragma_Argument_Associations
=> New_List
(
2615 Make_Pragma_Argument_Association
(Loc
,
2616 Expression
=> Relocate_Node
(Expr
))),
2617 Pragma_Name
=> Name_Effective_Reads
);
2619 Decorate
(Aspect
, Aitem
);
2620 Insert_Pragma
(Aitem
);
2623 -- Aspect Effective_Writes is never delayed because it is
2624 -- equivalent to a source pragma which appears after the
2625 -- related object declaration.
2627 when Aspect_Effective_Writes
=>
2629 (Pragma_Argument_Associations
=> New_List
(
2630 Make_Pragma_Argument_Association
(Loc
,
2631 Expression
=> Relocate_Node
(Expr
))),
2632 Pragma_Name
=> Name_Effective_Writes
);
2634 Decorate
(Aspect
, Aitem
);
2635 Insert_Pragma
(Aitem
);
2638 -- Aspect Extensions_Visible is never delayed because it is
2639 -- equivalent to a source pragma which appears after the
2640 -- related subprogram.
2642 when Aspect_Extensions_Visible
=>
2644 (Pragma_Argument_Associations
=> New_List
(
2645 Make_Pragma_Argument_Association
(Loc
,
2646 Expression
=> Relocate_Node
(Expr
))),
2647 Pragma_Name
=> Name_Extensions_Visible
);
2649 Decorate
(Aspect
, Aitem
);
2650 Insert_Pragma
(Aitem
);
2653 -- Aspect Ghost is never delayed because it is equivalent to a
2654 -- source pragma which appears at the top of [generic] package
2655 -- declarations or after an object, a [generic] subprogram, or
2656 -- a type declaration.
2658 when Aspect_Ghost
=>
2660 (Pragma_Argument_Associations
=> New_List
(
2661 Make_Pragma_Argument_Association
(Loc
,
2662 Expression
=> Relocate_Node
(Expr
))),
2663 Pragma_Name
=> Name_Ghost
);
2665 Decorate
(Aspect
, Aitem
);
2666 Insert_Pragma
(Aitem
);
2671 -- Aspect Global is never delayed because it is equivalent to
2672 -- a source pragma which appears after the related subprogram.
2673 -- To deal with forward references, the generated pragma is
2674 -- stored in the contract of the related subprogram and later
2675 -- analyzed at the end of the declarative region. See routine
2676 -- Analyze_Global_In_Decl_Part for details.
2678 when Aspect_Global
=>
2680 (Pragma_Argument_Associations
=> New_List
(
2681 Make_Pragma_Argument_Association
(Loc
,
2682 Expression
=> Relocate_Node
(Expr
))),
2683 Pragma_Name
=> Name_Global
);
2685 Decorate
(Aspect
, Aitem
);
2686 Insert_Pragma
(Aitem
);
2689 -- Initial_Condition
2691 -- Aspect Initial_Condition is never delayed because it is
2692 -- equivalent to a source pragma which appears after the
2693 -- related package. To deal with forward references, the
2694 -- generated pragma is stored in the contract of the related
2695 -- package and later analyzed at the end of the declarative
2696 -- region. See routine Analyze_Initial_Condition_In_Decl_Part
2699 when Aspect_Initial_Condition
=> Initial_Condition
: declare
2700 Context
: Node_Id
:= N
;
2703 -- When aspect Initial_Condition appears on a generic
2704 -- package, it is propageted to the package instance. The
2705 -- context in this case is the instance spec.
2707 if Nkind
(Context
) = N_Package_Instantiation
then
2708 Context
:= Instance_Spec
(Context
);
2711 if Nkind_In
(Context
, N_Generic_Package_Declaration
,
2712 N_Package_Declaration
)
2715 (Pragma_Argument_Associations
=> New_List
(
2716 Make_Pragma_Argument_Association
(Loc
,
2717 Expression
=> Relocate_Node
(Expr
))),
2719 Name_Initial_Condition
);
2721 Decorate
(Aspect
, Aitem
);
2725 Is_Generic_Instance
(Defining_Entity
(Context
)));
2727 -- Otherwise the context is illegal
2731 ("aspect & must apply to a package declaration",
2736 end Initial_Condition
;
2740 -- Aspect Initializes is never delayed because it is equivalent
2741 -- to a source pragma appearing after the related package. To
2742 -- deal with forward references, the generated pragma is stored
2743 -- in the contract of the related package and later analyzed at
2744 -- the end of the declarative region. For details, see routine
2745 -- Analyze_Initializes_In_Decl_Part.
2747 when Aspect_Initializes
=> Initializes
: declare
2748 Context
: Node_Id
:= N
;
2751 -- When aspect Initializes appears on a generic package,
2752 -- it is propageted to the package instance. The context
2753 -- in this case is the instance spec.
2755 if Nkind
(Context
) = N_Package_Instantiation
then
2756 Context
:= Instance_Spec
(Context
);
2759 if Nkind_In
(Context
, N_Generic_Package_Declaration
,
2760 N_Package_Declaration
)
2763 (Pragma_Argument_Associations
=> New_List
(
2764 Make_Pragma_Argument_Association
(Loc
,
2765 Expression
=> Relocate_Node
(Expr
))),
2766 Pragma_Name
=> Name_Initializes
);
2768 Decorate
(Aspect
, Aitem
);
2772 Is_Generic_Instance
(Defining_Entity
(Context
)));
2774 -- Otherwise the context is illegal
2778 ("aspect & must apply to a package declaration",
2787 when Aspect_Obsolescent
=> declare
2795 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2796 Expression
=> Relocate_Node
(Expr
)));
2800 (Pragma_Argument_Associations
=> Args
,
2801 Pragma_Name
=> Chars
(Id
));
2806 when Aspect_Part_Of
=>
2807 if Nkind_In
(N
, N_Object_Declaration
,
2808 N_Package_Instantiation
)
2809 or else Is_Single_Concurrent_Type_Declaration
(N
)
2812 (Pragma_Argument_Associations
=> New_List
(
2813 Make_Pragma_Argument_Association
(Loc
,
2814 Expression
=> Relocate_Node
(Expr
))),
2815 Pragma_Name
=> Name_Part_Of
);
2817 Decorate
(Aspect
, Aitem
);
2818 Insert_Pragma
(Aitem
);
2822 ("aspect & must apply to package instantiation, "
2823 & "object, single protected type or single task type",
2831 when Aspect_SPARK_Mode
=>
2833 (Pragma_Argument_Associations
=> New_List
(
2834 Make_Pragma_Argument_Association
(Loc
,
2835 Expression
=> Relocate_Node
(Expr
))),
2836 Pragma_Name
=> Name_SPARK_Mode
);
2838 Decorate
(Aspect
, Aitem
);
2839 Insert_Pragma
(Aitem
);
2844 -- Aspect Refined_Depends is never delayed because it is
2845 -- equivalent to a source pragma which appears in the
2846 -- declarations of the related subprogram body. To deal with
2847 -- forward references, the generated pragma is stored in the
2848 -- contract of the related subprogram body and later analyzed
2849 -- at the end of the declarative region. For details, see
2850 -- routine Analyze_Refined_Depends_In_Decl_Part.
2852 when Aspect_Refined_Depends
=>
2854 (Pragma_Argument_Associations
=> New_List
(
2855 Make_Pragma_Argument_Association
(Loc
,
2856 Expression
=> Relocate_Node
(Expr
))),
2857 Pragma_Name
=> Name_Refined_Depends
);
2859 Decorate
(Aspect
, Aitem
);
2860 Insert_Pragma
(Aitem
);
2865 -- Aspect Refined_Global is never delayed because it is
2866 -- equivalent to a source pragma which appears in the
2867 -- declarations of the related subprogram body. To deal with
2868 -- forward references, the generated pragma is stored in the
2869 -- contract of the related subprogram body and later analyzed
2870 -- at the end of the declarative region. For details, see
2871 -- routine Analyze_Refined_Global_In_Decl_Part.
2873 when Aspect_Refined_Global
=>
2875 (Pragma_Argument_Associations
=> New_List
(
2876 Make_Pragma_Argument_Association
(Loc
,
2877 Expression
=> Relocate_Node
(Expr
))),
2878 Pragma_Name
=> Name_Refined_Global
);
2880 Decorate
(Aspect
, Aitem
);
2881 Insert_Pragma
(Aitem
);
2886 when Aspect_Refined_Post
=>
2888 (Pragma_Argument_Associations
=> New_List
(
2889 Make_Pragma_Argument_Association
(Loc
,
2890 Expression
=> Relocate_Node
(Expr
))),
2891 Pragma_Name
=> Name_Refined_Post
);
2893 Decorate
(Aspect
, Aitem
);
2894 Insert_Pragma
(Aitem
);
2899 when Aspect_Refined_State
=>
2901 -- The corresponding pragma for Refined_State is inserted in
2902 -- the declarations of the related package body. This action
2903 -- synchronizes both the source and from-aspect versions of
2906 if Nkind
(N
) = N_Package_Body
then
2908 (Pragma_Argument_Associations
=> New_List
(
2909 Make_Pragma_Argument_Association
(Loc
,
2910 Expression
=> Relocate_Node
(Expr
))),
2911 Pragma_Name
=> Name_Refined_State
);
2913 Decorate
(Aspect
, Aitem
);
2914 Insert_Pragma
(Aitem
);
2916 -- Otherwise the context is illegal
2920 ("aspect & must apply to a package body", Aspect
, Id
);
2925 -- Relative_Deadline
2927 when Aspect_Relative_Deadline
=>
2929 (Pragma_Argument_Associations
=> New_List
(
2930 Make_Pragma_Argument_Association
(Loc
,
2931 Expression
=> Relocate_Node
(Expr
))),
2932 Pragma_Name
=> Name_Relative_Deadline
);
2934 -- If the aspect applies to a task, the corresponding pragma
2935 -- must appear within its declarations, not after.
2937 if Nkind
(N
) = N_Task_Type_Declaration
then
2943 if No
(Task_Definition
(N
)) then
2944 Set_Task_Definition
(N
,
2945 Make_Task_Definition
(Loc
,
2946 Visible_Declarations
=> New_List
,
2947 End_Label
=> Empty
));
2950 Def
:= Task_Definition
(N
);
2951 V
:= Visible_Declarations
(Def
);
2952 if not Is_Empty_List
(V
) then
2953 Insert_Before
(First
(V
), Aitem
);
2956 Set_Visible_Declarations
(Def
, New_List
(Aitem
));
2963 -- Aspect Volatile_Function is never delayed because it is
2964 -- equivalent to a source pragma which appears after the
2965 -- related subprogram.
2967 when Aspect_Volatile_Function
=>
2969 (Pragma_Argument_Associations
=> New_List
(
2970 Make_Pragma_Argument_Association
(Loc
,
2971 Expression
=> Relocate_Node
(Expr
))),
2972 Pragma_Name
=> Name_Volatile_Function
);
2974 Decorate
(Aspect
, Aitem
);
2975 Insert_Pragma
(Aitem
);
2978 -- Case 2e: Annotate aspect
2980 when Aspect_Annotate
=>
2987 -- The argument can be a single identifier
2989 if Nkind
(Expr
) = N_Identifier
then
2991 -- One level of parens is allowed
2993 if Paren_Count
(Expr
) > 1 then
2994 Error_Msg_F
("extra parentheses ignored", Expr
);
2997 Set_Paren_Count
(Expr
, 0);
2999 -- Add the single item to the list
3001 Args
:= New_List
(Expr
);
3003 -- Otherwise we must have an aggregate
3005 elsif Nkind
(Expr
) = N_Aggregate
then
3007 -- Must be positional
3009 if Present
(Component_Associations
(Expr
)) then
3011 ("purely positional aggregate required", Expr
);
3015 -- Must not be parenthesized
3017 if Paren_Count
(Expr
) /= 0 then
3018 Error_Msg_F
("extra parentheses ignored", Expr
);
3021 -- List of arguments is list of aggregate expressions
3023 Args
:= Expressions
(Expr
);
3025 -- Anything else is illegal
3028 Error_Msg_F
("wrong form for Annotate aspect", Expr
);
3032 -- Prepare pragma arguments
3035 Arg
:= First
(Args
);
3036 while Present
(Arg
) loop
3038 Make_Pragma_Argument_Association
(Sloc
(Arg
),
3039 Expression
=> Relocate_Node
(Arg
)));
3044 Make_Pragma_Argument_Association
(Sloc
(Ent
),
3045 Chars
=> Name_Entity
,
3046 Expression
=> Ent
));
3049 (Pragma_Argument_Associations
=> Pargs
,
3050 Pragma_Name
=> Name_Annotate
);
3053 -- Case 3 : Aspects that don't correspond to pragma/attribute
3054 -- definition clause.
3056 -- Case 3a: The aspects listed below don't correspond to
3057 -- pragmas/attributes but do require delayed analysis.
3059 -- Default_Value can only apply to a scalar type
3061 when Aspect_Default_Value
=>
3062 if not Is_Scalar_Type
(E
) then
3064 ("aspect Default_Value must apply to a scalar type", N
);
3069 -- Default_Component_Value can only apply to an array type
3070 -- with scalar components.
3072 when Aspect_Default_Component_Value
=>
3073 if not (Is_Array_Type
(E
)
3074 and then Is_Scalar_Type
(Component_Type
(E
)))
3077 ("aspect Default_Component_Value can only apply to an "
3078 & "array of scalar components", N
);
3083 -- Case 3b: The aspects listed below don't correspond to
3084 -- pragmas/attributes and don't need delayed analysis.
3086 -- Implicit_Dereference
3088 -- For Implicit_Dereference, External_Name and Link_Name, only
3089 -- the legality checks are done during the analysis, thus no
3090 -- delay is required.
3092 when Aspect_Implicit_Dereference
=>
3093 Analyze_Aspect_Implicit_Dereference
;
3098 when Aspect_Dimension
=>
3099 Analyze_Aspect_Dimension
(N
, Id
, Expr
);
3104 when Aspect_Dimension_System
=>
3105 Analyze_Aspect_Dimension_System
(N
, Id
, Expr
);
3108 -- Case 4: Aspects requiring special handling
3110 -- Pre/Post/Test_Case/Contract_Cases whose corresponding
3111 -- pragmas take care of the delay.
3115 -- Aspects Pre/Post generate Precondition/Postcondition pragmas
3116 -- with a first argument that is the expression, and a second
3117 -- argument that is an informative message if the test fails.
3118 -- This is inserted right after the declaration, to get the
3119 -- required pragma placement. The processing for the pragmas
3120 -- takes care of the required delay.
3122 when Pre_Post_Aspects
=> Pre_Post
: declare
3126 if A_Id
= Aspect_Pre
or else A_Id
= Aspect_Precondition
then
3127 Pname
:= Name_Precondition
;
3129 Pname
:= Name_Postcondition
;
3132 -- If the expressions is of the form A and then B, then
3133 -- we generate separate Pre/Post aspects for the separate
3134 -- clauses. Since we allow multiple pragmas, there is no
3135 -- problem in allowing multiple Pre/Post aspects internally.
3136 -- These should be treated in reverse order (B first and
3137 -- A second) since they are later inserted just after N in
3138 -- the order they are treated. This way, the pragma for A
3139 -- ends up preceding the pragma for B, which may have an
3140 -- importance for the error raised (either constraint error
3141 -- or precondition error).
3143 -- We do not do this for Pre'Class, since we have to put
3144 -- these conditions together in a complex OR expression.
3146 -- We do not do this in ASIS mode, as ASIS relies on the
3147 -- original node representing the complete expression, when
3148 -- retrieving it through the source aspect table.
3151 and then (Pname
= Name_Postcondition
3152 or else not Class_Present
(Aspect
))
3154 while Nkind
(Expr
) = N_And_Then
loop
3155 Insert_After
(Aspect
,
3156 Make_Aspect_Specification
(Sloc
(Left_Opnd
(Expr
)),
3157 Identifier
=> Identifier
(Aspect
),
3158 Expression
=> Relocate_Node
(Left_Opnd
(Expr
)),
3159 Class_Present
=> Class_Present
(Aspect
),
3160 Split_PPC
=> True));
3161 Rewrite
(Expr
, Relocate_Node
(Right_Opnd
(Expr
)));
3162 Eloc
:= Sloc
(Expr
);
3166 -- Build the precondition/postcondition pragma
3168 -- Add note about why we do NOT need Copy_Tree here???
3171 (Pragma_Argument_Associations
=> New_List
(
3172 Make_Pragma_Argument_Association
(Eloc
,
3173 Chars
=> Name_Check
,
3174 Expression
=> Relocate_Node
(Expr
))),
3175 Pragma_Name
=> Pname
);
3177 -- Add message unless exception messages are suppressed
3179 if not Opt
.Exception_Locations_Suppressed
then
3180 Append_To
(Pragma_Argument_Associations
(Aitem
),
3181 Make_Pragma_Argument_Association
(Eloc
,
3182 Chars
=> Name_Message
,
3184 Make_String_Literal
(Eloc
,
3186 & Get_Name_String
(Pname
)
3188 & Build_Location_String
(Eloc
))));
3191 Set_Is_Delayed_Aspect
(Aspect
);
3193 -- For Pre/Post cases, insert immediately after the entity
3194 -- declaration, since that is the required pragma placement.
3195 -- Note that for these aspects, we do not have to worry
3196 -- about delay issues, since the pragmas themselves deal
3197 -- with delay of visibility for the expression analysis.
3199 Insert_Pragma
(Aitem
);
3206 when Aspect_Test_Case
=> Test_Case
: declare
3208 Comp_Expr
: Node_Id
;
3209 Comp_Assn
: Node_Id
;
3215 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
3216 Error_Msg_Name_1
:= Nam
;
3217 Error_Msg_N
("incorrect placement of aspect `%`", E
);
3221 if Nkind
(Expr
) /= N_Aggregate
then
3222 Error_Msg_Name_1
:= Nam
;
3224 ("wrong syntax for aspect `%` for &", Id
, E
);
3228 -- Make pragma expressions refer to the original aspect
3229 -- expressions through the Original_Node link. This is used
3230 -- in semantic analysis for ASIS mode, so that the original
3231 -- expression also gets analyzed.
3233 Comp_Expr
:= First
(Expressions
(Expr
));
3234 while Present
(Comp_Expr
) loop
3235 New_Expr
:= Relocate_Node
(Comp_Expr
);
3237 Make_Pragma_Argument_Association
(Sloc
(Comp_Expr
),
3238 Expression
=> New_Expr
));
3242 Comp_Assn
:= First
(Component_Associations
(Expr
));
3243 while Present
(Comp_Assn
) loop
3244 if List_Length
(Choices
(Comp_Assn
)) /= 1
3246 Nkind
(First
(Choices
(Comp_Assn
))) /= N_Identifier
3248 Error_Msg_Name_1
:= Nam
;
3250 ("wrong syntax for aspect `%` for &", Id
, E
);
3255 Make_Pragma_Argument_Association
(Sloc
(Comp_Assn
),
3256 Chars
=> Chars
(First
(Choices
(Comp_Assn
))),
3258 Relocate_Node
(Expression
(Comp_Assn
))));
3262 -- Build the test-case pragma
3265 (Pragma_Argument_Associations
=> Args
,
3266 Pragma_Name
=> Nam
);
3271 when Aspect_Contract_Cases
=>
3273 (Pragma_Argument_Associations
=> New_List
(
3274 Make_Pragma_Argument_Association
(Loc
,
3275 Expression
=> Relocate_Node
(Expr
))),
3276 Pragma_Name
=> Nam
);
3278 Decorate
(Aspect
, Aitem
);
3279 Insert_Pragma
(Aitem
);
3282 -- Case 5: Special handling for aspects with an optional
3283 -- boolean argument.
3285 -- In the delayed case, the corresponding pragma cannot be
3286 -- generated yet because the evaluation of the boolean needs
3287 -- to be delayed till the freeze point.
3289 when Boolean_Aspects |
3290 Library_Unit_Aspects
=>
3292 Set_Is_Boolean_Aspect
(Aspect
);
3294 -- Lock_Free aspect only apply to protected objects
3296 if A_Id
= Aspect_Lock_Free
then
3297 if Ekind
(E
) /= E_Protected_Type
then
3298 Error_Msg_Name_1
:= Nam
;
3300 ("aspect % only applies to a protected object",
3304 -- Set the Uses_Lock_Free flag to True if there is no
3305 -- expression or if the expression is True. The
3306 -- evaluation of this aspect should be delayed to the
3307 -- freeze point (why???)
3310 or else Is_True
(Static_Boolean
(Expr
))
3312 Set_Uses_Lock_Free
(E
);
3315 Record_Rep_Item
(E
, Aspect
);
3320 elsif A_Id
= Aspect_Export
or else A_Id
= Aspect_Import
then
3321 Analyze_Aspect_Export_Import
;
3323 -- Disable_Controlled
3325 elsif A_Id
= Aspect_Disable_Controlled
then
3326 if Ekind
(E
) /= E_Record_Type
3327 or else not Is_Controlled
(E
)
3330 ("aspect % requires controlled record type", Aspect
);
3334 -- If we're in a generic template, we don't want to try
3335 -- to disable controlled types, because typical usage is
3336 -- "Disable_Controlled => not <some_check>'Enabled", and
3337 -- the value of Enabled is not known until we see a
3338 -- particular instance. In such a context, we just need
3339 -- to preanalyze the expression for legality.
3341 if Expander_Active
then
3342 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
3344 if not Present
(Expr
)
3345 or else Is_True
(Static_Boolean
(Expr
))
3347 Set_Disable_Controlled
(E
);
3350 elsif Serious_Errors_Detected
= 0 then
3351 Preanalyze_And_Resolve
(Expr
, Standard_Boolean
);
3357 -- Library unit aspects require special handling in the case
3358 -- of a package declaration, the pragma needs to be inserted
3359 -- in the list of declarations for the associated package.
3360 -- There is no issue of visibility delay for these aspects.
3362 if A_Id
in Library_Unit_Aspects
3364 Nkind_In
(N
, N_Package_Declaration
,
3365 N_Generic_Package_Declaration
)
3366 and then Nkind
(Parent
(N
)) /= N_Compilation_Unit
3368 -- Aspect is legal on a local instantiation of a library-
3369 -- level generic unit.
3371 and then not Is_Generic_Instance
(Defining_Entity
(N
))
3374 ("incorrect context for library unit aspect&", Id
);
3378 -- Cases where we do not delay, includes all cases where the
3379 -- expression is missing other than the above cases.
3381 if not Delay_Required
or else No
(Expr
) then
3383 -- Exclude aspects Export and Import because their pragma
3384 -- syntax does not map directly to a Boolean aspect.
3386 if A_Id
/= Aspect_Export
3387 and then A_Id
/= Aspect_Import
3390 (Pragma_Argument_Associations
=> New_List
(
3391 Make_Pragma_Argument_Association
(Sloc
(Ent
),
3392 Expression
=> Ent
)),
3393 Pragma_Name
=> Chars
(Id
));
3396 Delay_Required
:= False;
3398 -- In general cases, the corresponding pragma/attribute
3399 -- definition clause will be inserted later at the freezing
3400 -- point, and we do not need to build it now.
3408 -- This is special because for access types we need to generate
3409 -- an attribute definition clause. This also works for single
3410 -- task declarations, but it does not work for task type
3411 -- declarations, because we have the case where the expression
3412 -- references a discriminant of the task type. That can't use
3413 -- an attribute definition clause because we would not have
3414 -- visibility on the discriminant. For that case we must
3415 -- generate a pragma in the task definition.
3417 when Aspect_Storage_Size
=>
3421 if Ekind
(E
) = E_Task_Type
then
3423 Decl
: constant Node_Id
:= Declaration_Node
(E
);
3426 pragma Assert
(Nkind
(Decl
) = N_Task_Type_Declaration
);
3428 -- If no task definition, create one
3430 if No
(Task_Definition
(Decl
)) then
3431 Set_Task_Definition
(Decl
,
3432 Make_Task_Definition
(Loc
,
3433 Visible_Declarations
=> Empty_List
,
3434 End_Label
=> Empty
));
3437 -- Create a pragma and put it at the start of the task
3438 -- definition for the task type declaration.
3441 (Pragma_Argument_Associations
=> New_List
(
3442 Make_Pragma_Argument_Association
(Loc
,
3443 Expression
=> Relocate_Node
(Expr
))),
3444 Pragma_Name
=> Name_Storage_Size
);
3448 Visible_Declarations
(Task_Definition
(Decl
)));
3452 -- All other cases, generate attribute definition
3456 Make_Attribute_Definition_Clause
(Loc
,
3458 Chars
=> Chars
(Id
),
3459 Expression
=> Relocate_Node
(Expr
));
3463 -- Attach the corresponding pragma/attribute definition clause to
3464 -- the aspect specification node.
3466 if Present
(Aitem
) then
3467 Set_From_Aspect_Specification
(Aitem
);
3470 -- In the context of a compilation unit, we directly put the
3471 -- pragma in the Pragmas_After list of the N_Compilation_Unit_Aux
3472 -- node (no delay is required here) except for aspects on a
3473 -- subprogram body (see below) and a generic package, for which we
3474 -- need to introduce the pragma before building the generic copy
3475 -- (see sem_ch12), and for package instantiations, where the
3476 -- library unit pragmas are better handled early.
3478 if Nkind
(Parent
(N
)) = N_Compilation_Unit
3479 and then (Present
(Aitem
) or else Is_Boolean_Aspect
(Aspect
))
3482 Aux
: constant Node_Id
:= Aux_Decls_Node
(Parent
(N
));
3485 pragma Assert
(Nkind
(Aux
) = N_Compilation_Unit_Aux
);
3487 -- For a Boolean aspect, create the corresponding pragma if
3488 -- no expression or if the value is True.
3490 if Is_Boolean_Aspect
(Aspect
) and then No
(Aitem
) then
3491 if Is_True
(Static_Boolean
(Expr
)) then
3493 (Pragma_Argument_Associations
=> New_List
(
3494 Make_Pragma_Argument_Association
(Sloc
(Ent
),
3495 Expression
=> Ent
)),
3496 Pragma_Name
=> Chars
(Id
));
3498 Set_From_Aspect_Specification
(Aitem
, True);
3499 Set_Corresponding_Aspect
(Aitem
, Aspect
);
3506 -- If the aspect is on a subprogram body (relevant aspect
3507 -- is Inline), add the pragma in front of the declarations.
3509 if Nkind
(N
) = N_Subprogram_Body
then
3510 if No
(Declarations
(N
)) then
3511 Set_Declarations
(N
, New_List
);
3514 Prepend
(Aitem
, Declarations
(N
));
3516 elsif Nkind
(N
) = N_Generic_Package_Declaration
then
3517 if No
(Visible_Declarations
(Specification
(N
))) then
3518 Set_Visible_Declarations
(Specification
(N
), New_List
);
3522 Visible_Declarations
(Specification
(N
)));
3524 elsif Nkind
(N
) = N_Package_Instantiation
then
3526 Spec
: constant Node_Id
:=
3527 Specification
(Instance_Spec
(N
));
3529 if No
(Visible_Declarations
(Spec
)) then
3530 Set_Visible_Declarations
(Spec
, New_List
);
3533 Prepend
(Aitem
, Visible_Declarations
(Spec
));
3537 if No
(Pragmas_After
(Aux
)) then
3538 Set_Pragmas_After
(Aux
, New_List
);
3541 Append
(Aitem
, Pragmas_After
(Aux
));
3548 -- The evaluation of the aspect is delayed to the freezing point.
3549 -- The pragma or attribute clause if there is one is then attached
3550 -- to the aspect specification which is put in the rep item list.
3552 if Delay_Required
then
3553 if Present
(Aitem
) then
3554 Set_Is_Delayed_Aspect
(Aitem
);
3555 Set_Aspect_Rep_Item
(Aspect
, Aitem
);
3556 Set_Parent
(Aitem
, Aspect
);
3559 Set_Is_Delayed_Aspect
(Aspect
);
3561 -- In the case of Default_Value, link the aspect to base type
3562 -- as well, even though it appears on a first subtype. This is
3563 -- mandated by the semantics of the aspect. Do not establish
3564 -- the link when processing the base type itself as this leads
3565 -- to a rep item circularity. Verify that we are dealing with
3566 -- a scalar type to prevent cascaded errors.
3568 if A_Id
= Aspect_Default_Value
3569 and then Is_Scalar_Type
(E
)
3570 and then Base_Type
(E
) /= E
3572 Set_Has_Delayed_Aspects
(Base_Type
(E
));
3573 Record_Rep_Item
(Base_Type
(E
), Aspect
);
3576 Set_Has_Delayed_Aspects
(E
);
3577 Record_Rep_Item
(E
, Aspect
);
3579 -- When delay is not required and the context is a package or a
3580 -- subprogram body, insert the pragma in the body declarations.
3582 elsif Nkind_In
(N
, N_Package_Body
, N_Subprogram_Body
) then
3583 if No
(Declarations
(N
)) then
3584 Set_Declarations
(N
, New_List
);
3587 -- The pragma is added before source declarations
3589 Prepend_To
(Declarations
(N
), Aitem
);
3591 -- When delay is not required and the context is not a compilation
3592 -- unit, we simply insert the pragma/attribute definition clause
3595 elsif Present
(Aitem
) then
3596 Insert_After
(Ins_Node
, Aitem
);
3599 end Analyze_One_Aspect
;
3603 end loop Aspect_Loop
;
3605 if Has_Delayed_Aspects
(E
) then
3606 Ensure_Freeze_Node
(E
);
3608 end Analyze_Aspect_Specifications
;
3610 ---------------------------------------------------
3611 -- Analyze_Aspect_Specifications_On_Body_Or_Stub --
3612 ---------------------------------------------------
3614 procedure Analyze_Aspect_Specifications_On_Body_Or_Stub
(N
: Node_Id
) is
3615 Body_Id
: constant Entity_Id
:= Defining_Entity
(N
);
3617 procedure Diagnose_Misplaced_Aspects
(Spec_Id
: Entity_Id
);
3618 -- Body [stub] N has aspects, but they are not properly placed. Emit an
3619 -- error message depending on the aspects involved. Spec_Id denotes the
3620 -- entity of the corresponding spec.
3622 --------------------------------
3623 -- Diagnose_Misplaced_Aspects --
3624 --------------------------------
3626 procedure Diagnose_Misplaced_Aspects
(Spec_Id
: Entity_Id
) is
3627 procedure Misplaced_Aspect_Error
3630 -- Emit an error message concerning misplaced aspect Asp. Ref_Nam is
3631 -- the name of the refined version of the aspect.
3633 ----------------------------
3634 -- Misplaced_Aspect_Error --
3635 ----------------------------
3637 procedure Misplaced_Aspect_Error
3641 Asp_Nam
: constant Name_Id
:= Chars
(Identifier
(Asp
));
3642 Asp_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Asp_Nam
);
3645 -- The corresponding spec already contains the aspect in question
3646 -- and the one appearing on the body must be the refined form:
3648 -- procedure P with Global ...;
3649 -- procedure P with Global ... is ... end P;
3653 if Has_Aspect
(Spec_Id
, Asp_Id
) then
3654 Error_Msg_Name_1
:= Asp_Nam
;
3656 -- Subunits cannot carry aspects that apply to a subprogram
3659 if Nkind
(Parent
(N
)) = N_Subunit
then
3660 Error_Msg_N
("aspect % cannot apply to a subunit", Asp
);
3662 -- Otherwise suggest the refined form
3665 Error_Msg_Name_2
:= Ref_Nam
;
3666 Error_Msg_N
("aspect % should be %", Asp
);
3669 -- Otherwise the aspect must appear on the spec, not on the body
3672 -- procedure P with Global ... is ... end P;
3676 ("aspect specification must appear on initial declaration",
3679 end Misplaced_Aspect_Error
;
3686 -- Start of processing for Diagnose_Misplaced_Aspects
3689 -- Iterate over the aspect specifications and emit specific errors
3690 -- where applicable.
3692 Asp
:= First
(Aspect_Specifications
(N
));
3693 while Present
(Asp
) loop
3694 Asp_Nam
:= Chars
(Identifier
(Asp
));
3696 -- Do not emit errors on aspects that can appear on a subprogram
3697 -- body. This scenario occurs when the aspect specification list
3698 -- contains both misplaced and properly placed aspects.
3700 if Aspect_On_Body_Or_Stub_OK
(Get_Aspect_Id
(Asp_Nam
)) then
3703 -- Special diagnostics for SPARK aspects
3705 elsif Asp_Nam
= Name_Depends
then
3706 Misplaced_Aspect_Error
(Asp
, Name_Refined_Depends
);
3708 elsif Asp_Nam
= Name_Global
then
3709 Misplaced_Aspect_Error
(Asp
, Name_Refined_Global
);
3711 elsif Asp_Nam
= Name_Post
then
3712 Misplaced_Aspect_Error
(Asp
, Name_Refined_Post
);
3714 -- Otherwise a language-defined aspect is misplaced
3718 ("aspect specification must appear on initial declaration",
3724 end Diagnose_Misplaced_Aspects
;
3728 Spec_Id
: constant Entity_Id
:= Unique_Defining_Entity
(N
);
3730 -- Start of processing for Analyze_Aspects_On_Body_Or_Stub
3733 -- Language-defined aspects cannot be associated with a subprogram body
3734 -- [stub] if the subprogram has a spec. Certain implementation defined
3735 -- aspects are allowed to break this rule (for all applicable cases, see
3736 -- table Aspects.Aspect_On_Body_Or_Stub_OK).
3738 if Spec_Id
/= Body_Id
and then not Aspects_On_Body_Or_Stub_OK
(N
) then
3739 Diagnose_Misplaced_Aspects
(Spec_Id
);
3741 Analyze_Aspect_Specifications
(N
, Body_Id
);
3743 end Analyze_Aspect_Specifications_On_Body_Or_Stub
;
3745 -----------------------
3746 -- Analyze_At_Clause --
3747 -----------------------
3749 -- An at clause is replaced by the corresponding Address attribute
3750 -- definition clause that is the preferred approach in Ada 95.
3752 procedure Analyze_At_Clause
(N
: Node_Id
) is
3753 CS
: constant Boolean := Comes_From_Source
(N
);
3756 -- This is an obsolescent feature
3758 Check_Restriction
(No_Obsolescent_Features
, N
);
3760 if Warn_On_Obsolescent_Feature
then
3762 ("?j?at clause is an obsolescent feature (RM J.7(2))", N
);
3764 ("\?j?use address attribute definition clause instead", N
);
3767 -- Rewrite as address clause
3770 Make_Attribute_Definition_Clause
(Sloc
(N
),
3771 Name
=> Identifier
(N
),
3772 Chars
=> Name_Address
,
3773 Expression
=> Expression
(N
)));
3775 -- We preserve Comes_From_Source, since logically the clause still comes
3776 -- from the source program even though it is changed in form.
3778 Set_Comes_From_Source
(N
, CS
);
3780 -- Analyze rewritten clause
3782 Analyze_Attribute_Definition_Clause
(N
);
3783 end Analyze_At_Clause
;
3785 -----------------------------------------
3786 -- Analyze_Attribute_Definition_Clause --
3787 -----------------------------------------
3789 procedure Analyze_Attribute_Definition_Clause
(N
: Node_Id
) is
3790 Loc
: constant Source_Ptr
:= Sloc
(N
);
3791 Nam
: constant Node_Id
:= Name
(N
);
3792 Attr
: constant Name_Id
:= Chars
(N
);
3793 Expr
: constant Node_Id
:= Expression
(N
);
3794 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Attr
);
3797 -- The entity of Nam after it is analyzed. In the case of an incomplete
3798 -- type, this is the underlying type.
3801 -- The underlying entity to which the attribute applies. Generally this
3802 -- is the Underlying_Type of Ent, except in the case where the clause
3803 -- applies to full view of incomplete type or private type in which case
3804 -- U_Ent is just a copy of Ent.
3806 FOnly
: Boolean := False;
3807 -- Reset to True for subtype specific attribute (Alignment, Size)
3808 -- and for stream attributes, i.e. those cases where in the call to
3809 -- Rep_Item_Too_Late, FOnly is set True so that only the freezing rules
3810 -- are checked. Note that the case of stream attributes is not clear
3811 -- from the RM, but see AI95-00137. Also, the RM seems to disallow
3812 -- Storage_Size for derived task types, but that is also clearly
3815 procedure Analyze_Stream_TSS_Definition
(TSS_Nam
: TSS_Name_Type
);
3816 -- Common processing for 'Read, 'Write, 'Input and 'Output attribute
3817 -- definition clauses.
3819 function Duplicate_Clause
return Boolean;
3820 -- This routine checks if the aspect for U_Ent being given by attribute
3821 -- definition clause N is for an aspect that has already been specified,
3822 -- and if so gives an error message. If there is a duplicate, True is
3823 -- returned, otherwise if there is no error, False is returned.
3825 procedure Check_Indexing_Functions
;
3826 -- Check that the function in Constant_Indexing or Variable_Indexing
3827 -- attribute has the proper type structure. If the name is overloaded,
3828 -- check that some interpretation is legal.
3830 procedure Check_Iterator_Functions
;
3831 -- Check that there is a single function in Default_Iterator attribute
3832 -- has the proper type structure.
3834 function Check_Primitive_Function
(Subp
: Entity_Id
) return Boolean;
3835 -- Common legality check for the previous two
3837 -----------------------------------
3838 -- Analyze_Stream_TSS_Definition --
3839 -----------------------------------
3841 procedure Analyze_Stream_TSS_Definition
(TSS_Nam
: TSS_Name_Type
) is
3842 Subp
: Entity_Id
:= Empty
;
3847 Is_Read
: constant Boolean := (TSS_Nam
= TSS_Stream_Read
);
3848 -- True for Read attribute, False for other attributes
3850 function Has_Good_Profile
3852 Report
: Boolean := False) return Boolean;
3853 -- Return true if the entity is a subprogram with an appropriate
3854 -- profile for the attribute being defined. If result is False and
3855 -- Report is True, function emits appropriate error.
3857 ----------------------
3858 -- Has_Good_Profile --
3859 ----------------------
3861 function Has_Good_Profile
3863 Report
: Boolean := False) return Boolean
3865 Expected_Ekind
: constant array (Boolean) of Entity_Kind
:=
3866 (False => E_Procedure
, True => E_Function
);
3867 Is_Function
: constant Boolean := (TSS_Nam
= TSS_Stream_Input
);
3872 if Ekind
(Subp
) /= Expected_Ekind
(Is_Function
) then
3876 F
:= First_Formal
(Subp
);
3879 or else Ekind
(Etype
(F
)) /= E_Anonymous_Access_Type
3880 or else Designated_Type
(Etype
(F
)) /=
3881 Class_Wide_Type
(RTE
(RE_Root_Stream_Type
))
3886 if not Is_Function
then
3890 Expected_Mode
: constant array (Boolean) of Entity_Kind
:=
3891 (False => E_In_Parameter
,
3892 True => E_Out_Parameter
);
3894 if Parameter_Mode
(F
) /= Expected_Mode
(Is_Read
) then
3901 -- If the attribute specification comes from an aspect
3902 -- specification for a class-wide stream, the parameter must be
3903 -- a class-wide type of the entity to which the aspect applies.
3905 if From_Aspect_Specification
(N
)
3906 and then Class_Present
(Parent
(N
))
3907 and then Is_Class_Wide_Type
(Typ
)
3913 Typ
:= Etype
(Subp
);
3916 -- Verify that the prefix of the attribute and the local name for
3917 -- the type of the formal match, or one is the class-wide of the
3918 -- other, in the case of a class-wide stream operation.
3920 if Base_Type
(Typ
) = Base_Type
(Ent
)
3921 or else (Is_Class_Wide_Type
(Typ
)
3922 and then Typ
= Class_Wide_Type
(Base_Type
(Ent
)))
3923 or else (Is_Class_Wide_Type
(Ent
)
3924 and then Ent
= Class_Wide_Type
(Base_Type
(Typ
)))
3931 if Present
(Next_Formal
(F
)) then
3934 elsif not Is_Scalar_Type
(Typ
)
3935 and then not Is_First_Subtype
(Typ
)
3936 and then not Is_Class_Wide_Type
(Typ
)
3938 if Report
and not Is_First_Subtype
(Typ
) then
3940 ("subtype of formal in stream operation must be a first "
3941 & "subtype", Parameter_Type
(Parent
(F
)));
3949 end Has_Good_Profile
;
3951 -- Start of processing for Analyze_Stream_TSS_Definition
3956 if not Is_Type
(U_Ent
) then
3957 Error_Msg_N
("local name must be a subtype", Nam
);
3960 elsif not Is_First_Subtype
(U_Ent
) then
3961 Error_Msg_N
("local name must be a first subtype", Nam
);
3965 Pnam
:= TSS
(Base_Type
(U_Ent
), TSS_Nam
);
3967 -- If Pnam is present, it can be either inherited from an ancestor
3968 -- type (in which case it is legal to redefine it for this type), or
3969 -- be a previous definition of the attribute for the same type (in
3970 -- which case it is illegal).
3972 -- In the first case, it will have been analyzed already, and we
3973 -- can check that its profile does not match the expected profile
3974 -- for a stream attribute of U_Ent. In the second case, either Pnam
3975 -- has been analyzed (and has the expected profile), or it has not
3976 -- been analyzed yet (case of a type that has not been frozen yet
3977 -- and for which the stream attribute has been set using Set_TSS).
3980 and then (No
(First_Entity
(Pnam
)) or else Has_Good_Profile
(Pnam
))
3982 Error_Msg_Sloc
:= Sloc
(Pnam
);
3983 Error_Msg_Name_1
:= Attr
;
3984 Error_Msg_N
("% attribute already defined #", Nam
);
3990 if Is_Entity_Name
(Expr
) then
3991 if not Is_Overloaded
(Expr
) then
3992 if Has_Good_Profile
(Entity
(Expr
), Report
=> True) then
3993 Subp
:= Entity
(Expr
);
3997 Get_First_Interp
(Expr
, I
, It
);
3998 while Present
(It
.Nam
) loop
3999 if Has_Good_Profile
(It
.Nam
) then
4004 Get_Next_Interp
(I
, It
);
4009 if Present
(Subp
) then
4010 if Is_Abstract_Subprogram
(Subp
) then
4011 Error_Msg_N
("stream subprogram must not be abstract", Expr
);
4014 -- A stream subprogram for an interface type must be a null
4015 -- procedure (RM 13.13.2 (38/3)). Note that the class-wide type
4016 -- of an interface is not an interface type (3.9.4 (6.b/2)).
4018 elsif Is_Interface
(U_Ent
)
4019 and then not Is_Class_Wide_Type
(U_Ent
)
4020 and then not Inside_A_Generic
4022 (Ekind
(Subp
) = E_Function
4026 (Unit_Declaration_Node
(Ultimate_Alias
(Subp
)))))
4029 ("stream subprogram for interface type must be null "
4030 & "procedure", Expr
);
4033 Set_Entity
(Expr
, Subp
);
4034 Set_Etype
(Expr
, Etype
(Subp
));
4036 New_Stream_Subprogram
(N
, U_Ent
, Subp
, TSS_Nam
);
4039 Error_Msg_Name_1
:= Attr
;
4040 Error_Msg_N
("incorrect expression for% attribute", Expr
);
4042 end Analyze_Stream_TSS_Definition
;
4044 ------------------------------
4045 -- Check_Indexing_Functions --
4046 ------------------------------
4048 procedure Check_Indexing_Functions
is
4049 Indexing_Found
: Boolean := False;
4051 procedure Check_Inherited_Indexing
;
4052 -- For a derived type, check that no indexing aspect is specified
4053 -- for the type if it is also inherited
4055 procedure Check_One_Function
(Subp
: Entity_Id
);
4056 -- Check one possible interpretation. Sets Indexing_Found True if a
4057 -- legal indexing function is found.
4059 procedure Illegal_Indexing
(Msg
: String);
4060 -- Diagnose illegal indexing function if not overloaded. In the
4061 -- overloaded case indicate that no legal interpretation exists.
4063 ------------------------------
4064 -- Check_Inherited_Indexing --
4065 ------------------------------
4067 procedure Check_Inherited_Indexing
is
4068 Inherited
: Node_Id
;
4071 if Attr
= Name_Constant_Indexing
then
4073 Find_Aspect
(Etype
(Ent
), Aspect_Constant_Indexing
);
4074 else pragma Assert
(Attr
= Name_Variable_Indexing
);
4076 Find_Aspect
(Etype
(Ent
), Aspect_Variable_Indexing
);
4079 if Present
(Inherited
) then
4080 if Debug_Flag_Dot_XX
then
4083 -- OK if current attribute_definition_clause is expansion of
4084 -- inherited aspect.
4086 elsif Aspect_Rep_Item
(Inherited
) = N
then
4089 -- Indicate the operation that must be overridden, rather than
4090 -- redefining the indexing aspect.
4094 ("indexing function already inherited from parent type");
4096 ("!override & instead",
4097 N
, Entity
(Expression
(Inherited
)));
4100 end Check_Inherited_Indexing
;
4102 ------------------------
4103 -- Check_One_Function --
4104 ------------------------
4106 procedure Check_One_Function
(Subp
: Entity_Id
) is
4107 Default_Element
: Node_Id
;
4108 Ret_Type
: constant Entity_Id
:= Etype
(Subp
);
4111 if not Is_Overloadable
(Subp
) then
4112 Illegal_Indexing
("illegal indexing function for type&");
4115 elsif Scope
(Subp
) /= Scope
(Ent
) then
4116 if Nkind
(Expr
) = N_Expanded_Name
then
4118 -- Indexing function can't be declared elsewhere
4121 ("indexing function must be declared in scope of type&");
4126 elsif No
(First_Formal
(Subp
)) then
4128 ("Indexing requires a function that applies to type&");
4131 elsif No
(Next_Formal
(First_Formal
(Subp
))) then
4133 ("indexing function must have at least two parameters");
4136 elsif Is_Derived_Type
(Ent
) then
4137 Check_Inherited_Indexing
;
4140 if not Check_Primitive_Function
(Subp
) then
4142 ("Indexing aspect requires a function that applies to type&");
4146 -- If partial declaration exists, verify that it is not tagged.
4148 if Ekind
(Current_Scope
) = E_Package
4149 and then Has_Private_Declaration
(Ent
)
4150 and then From_Aspect_Specification
(N
)
4152 List_Containing
(Parent
(Ent
)) =
4153 Private_Declarations
4154 (Specification
(Unit_Declaration_Node
(Current_Scope
)))
4155 and then Nkind
(N
) = N_Attribute_Definition_Clause
4162 First
(Visible_Declarations
4164 (Unit_Declaration_Node
(Current_Scope
))));
4166 while Present
(Decl
) loop
4167 if Nkind
(Decl
) = N_Private_Type_Declaration
4168 and then Ent
= Full_View
(Defining_Identifier
(Decl
))
4169 and then Tagged_Present
(Decl
)
4170 and then No
(Aspect_Specifications
(Decl
))
4173 ("Indexing aspect cannot be specified on full view "
4174 & "if partial view is tagged");
4183 -- An indexing function must return either the default element of
4184 -- the container, or a reference type. For variable indexing it
4185 -- must be the latter.
4188 Find_Value_Of_Aspect
4189 (Etype
(First_Formal
(Subp
)), Aspect_Iterator_Element
);
4191 if Present
(Default_Element
) then
4192 Analyze
(Default_Element
);
4194 if Is_Entity_Name
(Default_Element
)
4195 and then not Covers
(Entity
(Default_Element
), Ret_Type
)
4199 ("wrong return type for indexing function");
4204 -- For variable_indexing the return type must be a reference type
4206 if Attr
= Name_Variable_Indexing
then
4207 if not Has_Implicit_Dereference
(Ret_Type
) then
4209 ("variable indexing must return a reference type");
4212 elsif Is_Access_Constant
4213 (Etype
(First_Discriminant
(Ret_Type
)))
4216 ("variable indexing must return an access to variable");
4221 if Has_Implicit_Dereference
(Ret_Type
)
4223 Is_Access_Constant
(Etype
(First_Discriminant
(Ret_Type
)))
4226 ("constant indexing must return an access to constant");
4229 elsif Is_Access_Type
(Etype
(First_Formal
(Subp
)))
4230 and then not Is_Access_Constant
(Etype
(First_Formal
(Subp
)))
4233 ("constant indexing must apply to an access to constant");
4238 -- All checks succeeded.
4240 Indexing_Found
:= True;
4241 end Check_One_Function
;
4243 -----------------------
4244 -- Illegal_Indexing --
4245 -----------------------
4247 procedure Illegal_Indexing
(Msg
: String) is
4249 Error_Msg_NE
(Msg
, N
, Ent
);
4250 end Illegal_Indexing
;
4252 -- Start of processing for Check_Indexing_Functions
4256 Check_Inherited_Indexing
;
4261 if not Is_Overloaded
(Expr
) then
4262 Check_One_Function
(Entity
(Expr
));
4270 Indexing_Found
:= False;
4271 Get_First_Interp
(Expr
, I
, It
);
4272 while Present
(It
.Nam
) loop
4274 -- Note that analysis will have added the interpretation
4275 -- that corresponds to the dereference. We only check the
4276 -- subprogram itself.
4278 if Is_Overloadable
(It
.Nam
) then
4279 Check_One_Function
(It
.Nam
);
4282 Get_Next_Interp
(I
, It
);
4287 if not Indexing_Found
and then not Error_Posted
(N
) then
4289 ("aspect Indexing requires a local function that "
4290 & "applies to type&", Expr
, Ent
);
4292 end Check_Indexing_Functions
;
4294 ------------------------------
4295 -- Check_Iterator_Functions --
4296 ------------------------------
4298 procedure Check_Iterator_Functions
is
4299 function Valid_Default_Iterator
(Subp
: Entity_Id
) return Boolean;
4300 -- Check one possible interpretation for validity
4302 ----------------------------
4303 -- Valid_Default_Iterator --
4304 ----------------------------
4306 function Valid_Default_Iterator
(Subp
: Entity_Id
) return Boolean is
4310 if not Check_Primitive_Function
(Subp
) then
4313 Formal
:= First_Formal
(Subp
);
4316 -- False if any subsequent formal has no default expression
4318 Formal
:= Next_Formal
(Formal
);
4319 while Present
(Formal
) loop
4320 if No
(Expression
(Parent
(Formal
))) then
4324 Next_Formal
(Formal
);
4327 -- True if all subsequent formals have default expressions
4330 end Valid_Default_Iterator
;
4332 -- Start of processing for Check_Iterator_Functions
4337 if not Is_Entity_Name
(Expr
) then
4338 Error_Msg_N
("aspect Iterator must be a function name", Expr
);
4341 if not Is_Overloaded
(Expr
) then
4342 if not Check_Primitive_Function
(Entity
(Expr
)) then
4344 ("aspect Indexing requires a function that applies to type&",
4345 Entity
(Expr
), Ent
);
4348 -- Flag the default_iterator as well as the denoted function.
4350 if not Valid_Default_Iterator
(Entity
(Expr
)) then
4351 Error_Msg_N
("improper function for default iterator!", Expr
);
4356 Default
: Entity_Id
:= Empty
;
4361 Get_First_Interp
(Expr
, I
, It
);
4362 while Present
(It
.Nam
) loop
4363 if not Check_Primitive_Function
(It
.Nam
)
4364 or else not Valid_Default_Iterator
(It
.Nam
)
4368 elsif Present
(Default
) then
4370 -- An explicit one should override an implicit one
4372 if Comes_From_Source
(Default
) =
4373 Comes_From_Source
(It
.Nam
)
4375 Error_Msg_N
("default iterator must be unique", Expr
);
4376 Error_Msg_Sloc
:= Sloc
(Default
);
4377 Error_Msg_N
("\\possible interpretation#", Expr
);
4378 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
4379 Error_Msg_N
("\\possible interpretation#", Expr
);
4381 elsif Comes_From_Source
(It
.Nam
) then
4388 Get_Next_Interp
(I
, It
);
4391 if Present
(Default
) then
4392 Set_Entity
(Expr
, Default
);
4393 Set_Is_Overloaded
(Expr
, False);
4397 end Check_Iterator_Functions
;
4399 -------------------------------
4400 -- Check_Primitive_Function --
4401 -------------------------------
4403 function Check_Primitive_Function
(Subp
: Entity_Id
) return Boolean is
4407 if Ekind
(Subp
) /= E_Function
then
4411 if No
(First_Formal
(Subp
)) then
4414 Ctrl
:= Etype
(First_Formal
(Subp
));
4417 -- To be a primitive operation subprogram has to be in same scope.
4419 if Scope
(Ctrl
) /= Scope
(Subp
) then
4423 -- Type of formal may be the class-wide type, an access to such,
4424 -- or an incomplete view.
4427 or else Ctrl
= Class_Wide_Type
(Ent
)
4429 (Ekind
(Ctrl
) = E_Anonymous_Access_Type
4430 and then (Designated_Type
(Ctrl
) = Ent
4432 Designated_Type
(Ctrl
) = Class_Wide_Type
(Ent
)))
4434 (Ekind
(Ctrl
) = E_Incomplete_Type
4435 and then Full_View
(Ctrl
) = Ent
)
4443 end Check_Primitive_Function
;
4445 ----------------------
4446 -- Duplicate_Clause --
4447 ----------------------
4449 function Duplicate_Clause
return Boolean is
4453 -- Nothing to do if this attribute definition clause comes from
4454 -- an aspect specification, since we could not be duplicating an
4455 -- explicit clause, and we dealt with the case of duplicated aspects
4456 -- in Analyze_Aspect_Specifications.
4458 if From_Aspect_Specification
(N
) then
4462 -- Otherwise current clause may duplicate previous clause, or a
4463 -- previously given pragma or aspect specification for the same
4466 A
:= Get_Rep_Item
(U_Ent
, Chars
(N
), Check_Parents
=> False);
4469 Error_Msg_Name_1
:= Chars
(N
);
4470 Error_Msg_Sloc
:= Sloc
(A
);
4472 Error_Msg_NE
("aspect% for & previously given#", N
, U_Ent
);
4477 end Duplicate_Clause
;
4479 -- Start of processing for Analyze_Attribute_Definition_Clause
4482 -- The following code is a defense against recursion. Not clear that
4483 -- this can happen legitimately, but perhaps some error situations can
4484 -- cause it, and we did see this recursion during testing.
4486 if Analyzed
(N
) then
4489 Set_Analyzed
(N
, True);
4492 Check_Restriction_No_Use_Of_Attribute
(N
);
4494 -- Ignore some selected attributes in CodePeer mode since they are not
4495 -- relevant in this context.
4497 if CodePeer_Mode
then
4500 -- Ignore Component_Size in CodePeer mode, to avoid changing the
4501 -- internal representation of types by implicitly packing them.
4503 when Attribute_Component_Size
=>
4504 Rewrite
(N
, Make_Null_Statement
(Sloc
(N
)));
4512 -- Process Ignore_Rep_Clauses option
4514 if Ignore_Rep_Clauses
then
4517 -- The following should be ignored. They do not affect legality
4518 -- and may be target dependent. The basic idea of -gnatI is to
4519 -- ignore any rep clauses that may be target dependent but do not
4520 -- affect legality (except possibly to be rejected because they
4521 -- are incompatible with the compilation target).
4523 when Attribute_Alignment |
4524 Attribute_Bit_Order |
4525 Attribute_Component_Size |
4526 Attribute_Machine_Radix |
4527 Attribute_Object_Size |
4530 Attribute_Stream_Size |
4531 Attribute_Value_Size
=>
4532 Kill_Rep_Clause
(N
);
4535 -- The following should not be ignored, because in the first place
4536 -- they are reasonably portable, and should not cause problems
4537 -- in compiling code from another target, and also they do affect
4538 -- legality, e.g. failing to provide a stream attribute for a type
4539 -- may make a program illegal.
4541 when Attribute_External_Tag |
4545 Attribute_Simple_Storage_Pool |
4546 Attribute_Storage_Pool |
4547 Attribute_Storage_Size |
4551 -- We do not do anything here with address clauses, they will be
4552 -- removed by Freeze later on, but for now, it works better to
4553 -- keep then in the tree.
4555 when Attribute_Address
=>
4558 -- Other cases are errors ("attribute& cannot be set with
4559 -- definition clause"), which will be caught below.
4567 Ent
:= Entity
(Nam
);
4569 if Rep_Item_Too_Early
(Ent
, N
) then
4573 -- Rep clause applies to full view of incomplete type or private type if
4574 -- we have one (if not, this is a premature use of the type). However,
4575 -- certain semantic checks need to be done on the specified entity (i.e.
4576 -- the private view), so we save it in Ent.
4578 if Is_Private_Type
(Ent
)
4579 and then Is_Derived_Type
(Ent
)
4580 and then not Is_Tagged_Type
(Ent
)
4581 and then No
(Full_View
(Ent
))
4583 -- If this is a private type whose completion is a derivation from
4584 -- another private type, there is no full view, and the attribute
4585 -- belongs to the type itself, not its underlying parent.
4589 elsif Ekind
(Ent
) = E_Incomplete_Type
then
4591 -- The attribute applies to the full view, set the entity of the
4592 -- attribute definition accordingly.
4594 Ent
:= Underlying_Type
(Ent
);
4596 Set_Entity
(Nam
, Ent
);
4599 U_Ent
:= Underlying_Type
(Ent
);
4602 -- Avoid cascaded error
4604 if Etype
(Nam
) = Any_Type
then
4607 -- Must be declared in current scope or in case of an aspect
4608 -- specification, must be visible in current scope.
4610 elsif Scope
(Ent
) /= Current_Scope
4612 not (From_Aspect_Specification
(N
)
4613 and then Scope_Within_Or_Same
(Current_Scope
, Scope
(Ent
)))
4615 Error_Msg_N
("entity must be declared in this scope", Nam
);
4618 -- Must not be a source renaming (we do have some cases where the
4619 -- expander generates a renaming, and those cases are OK, in such
4620 -- cases any attribute applies to the renamed object as well).
4622 elsif Is_Object
(Ent
)
4623 and then Present
(Renamed_Object
(Ent
))
4625 -- Case of renamed object from source, this is an error
4627 if Comes_From_Source
(Renamed_Object
(Ent
)) then
4628 Get_Name_String
(Chars
(N
));
4629 Error_Msg_Strlen
:= Name_Len
;
4630 Error_Msg_String
(1 .. Name_Len
) := Name_Buffer
(1 .. Name_Len
);
4632 ("~ clause not allowed for a renaming declaration "
4633 & "(RM 13.1(6))", Nam
);
4636 -- For the case of a compiler generated renaming, the attribute
4637 -- definition clause applies to the renamed object created by the
4638 -- expander. The easiest general way to handle this is to create a
4639 -- copy of the attribute definition clause for this object.
4641 elsif Is_Entity_Name
(Renamed_Object
(Ent
)) then
4643 Make_Attribute_Definition_Clause
(Loc
,
4645 New_Occurrence_Of
(Entity
(Renamed_Object
(Ent
)), Loc
),
4647 Expression
=> Duplicate_Subexpr
(Expression
(N
))));
4649 -- If the renamed object is not an entity, it must be a dereference
4650 -- of an unconstrained function call, and we must introduce a new
4651 -- declaration to capture the expression. This is needed in the case
4652 -- of 'Alignment, where the original declaration must be rewritten.
4656 (Nkind
(Renamed_Object
(Ent
)) = N_Explicit_Dereference
);
4660 -- If no underlying entity, use entity itself, applies to some
4661 -- previously detected error cases ???
4663 elsif No
(U_Ent
) then
4666 -- Cannot specify for a subtype (exception Object/Value_Size)
4668 elsif Is_Type
(U_Ent
)
4669 and then not Is_First_Subtype
(U_Ent
)
4670 and then Id
/= Attribute_Object_Size
4671 and then Id
/= Attribute_Value_Size
4672 and then not From_At_Mod
(N
)
4674 Error_Msg_N
("cannot specify attribute for subtype", Nam
);
4678 Set_Entity
(N
, U_Ent
);
4680 -- Switch on particular attribute
4688 -- Address attribute definition clause
4690 when Attribute_Address
=> Address
: begin
4692 -- A little error check, catch for X'Address use X'Address;
4694 if Nkind
(Nam
) = N_Identifier
4695 and then Nkind
(Expr
) = N_Attribute_Reference
4696 and then Attribute_Name
(Expr
) = Name_Address
4697 and then Nkind
(Prefix
(Expr
)) = N_Identifier
4698 and then Chars
(Nam
) = Chars
(Prefix
(Expr
))
4701 ("address for & is self-referencing", Prefix
(Expr
), Ent
);
4705 -- Not that special case, carry on with analysis of expression
4707 Analyze_And_Resolve
(Expr
, RTE
(RE_Address
));
4709 -- Even when ignoring rep clauses we need to indicate that the
4710 -- entity has an address clause and thus it is legal to declare
4711 -- it imported. Freeze will get rid of the address clause later.
4713 if Ignore_Rep_Clauses
then
4714 if Ekind_In
(U_Ent
, E_Variable
, E_Constant
) then
4715 Record_Rep_Item
(U_Ent
, N
);
4721 if Duplicate_Clause
then
4724 -- Case of address clause for subprogram
4726 elsif Is_Subprogram
(U_Ent
) then
4727 if Has_Homonym
(U_Ent
) then
4729 ("address clause cannot be given " &
4730 "for overloaded subprogram",
4735 -- For subprograms, all address clauses are permitted, and we
4736 -- mark the subprogram as having a deferred freeze so that Gigi
4737 -- will not elaborate it too soon.
4739 -- Above needs more comments, what is too soon about???
4741 Set_Has_Delayed_Freeze
(U_Ent
);
4743 -- Case of address clause for entry
4745 elsif Ekind
(U_Ent
) = E_Entry
then
4746 if Nkind
(Parent
(N
)) = N_Task_Body
then
4748 ("entry address must be specified in task spec", Nam
);
4752 -- For entries, we require a constant address
4754 Check_Constant_Address_Clause
(Expr
, U_Ent
);
4756 -- Special checks for task types
4758 if Is_Task_Type
(Scope
(U_Ent
))
4759 and then Comes_From_Source
(Scope
(U_Ent
))
4762 ("??entry address declared for entry in task type", N
);
4764 ("\??only one task can be declared of this type", N
);
4767 -- Entry address clauses are obsolescent
4769 Check_Restriction
(No_Obsolescent_Features
, N
);
4771 if Warn_On_Obsolescent_Feature
then
4773 ("?j?attaching interrupt to task entry is an " &
4774 "obsolescent feature (RM J.7.1)", N
);
4776 ("\?j?use interrupt procedure instead", N
);
4779 -- Case of an address clause for a controlled object which we
4780 -- consider to be erroneous.
4782 elsif Is_Controlled
(Etype
(U_Ent
))
4783 or else Has_Controlled_Component
(Etype
(U_Ent
))
4786 ("??controlled object& must not be overlaid", Nam
, U_Ent
);
4788 ("\??Program_Error will be raised at run time", Nam
);
4789 Insert_Action
(Declaration_Node
(U_Ent
),
4790 Make_Raise_Program_Error
(Loc
,
4791 Reason
=> PE_Overlaid_Controlled_Object
));
4794 -- Case of address clause for a (non-controlled) object
4796 elsif Ekind_In
(U_Ent
, E_Variable
, E_Constant
) then
4798 Expr
: constant Node_Id
:= Expression
(N
);
4803 -- Exported variables cannot have an address clause, because
4804 -- this cancels the effect of the pragma Export.
4806 if Is_Exported
(U_Ent
) then
4808 ("cannot export object with address clause", Nam
);
4812 Find_Overlaid_Entity
(N
, O_Ent
, Off
);
4814 if Present
(O_Ent
) then
4816 -- If the object overlays a constant object, mark it so
4818 if Is_Constant_Object
(O_Ent
) then
4819 Set_Overlays_Constant
(U_Ent
);
4823 -- If this is not an overlay, mark a variable as being
4824 -- volatile to prevent unwanted optimizations. It's a
4825 -- conservative interpretation of RM 13.3(19) for the
4826 -- cases where the compiler cannot detect potential
4827 -- aliasing issues easily and it also covers the case
4828 -- of an absolute address where the volatile aspect is
4829 -- kind of implicit.
4831 if Ekind
(U_Ent
) = E_Variable
then
4832 Set_Treat_As_Volatile
(U_Ent
);
4836 -- Overlaying controlled objects is erroneous. Emit warning
4837 -- but continue analysis because program is itself legal,
4838 -- and back end must see address clause.
4841 and then (Has_Controlled_Component
(Etype
(O_Ent
))
4842 or else Is_Controlled
(Etype
(O_Ent
)))
4843 and then not Inside_A_Generic
4846 ("??cannot use overlays with controlled objects", Expr
);
4848 ("\??Program_Error will be raised at run time", Expr
);
4849 Insert_Action
(Declaration_Node
(U_Ent
),
4850 Make_Raise_Program_Error
(Loc
,
4851 Reason
=> PE_Overlaid_Controlled_Object
));
4853 -- Issue an unconditional warning for a constant overlaying
4854 -- a variable. For the reverse case, we will issue it only
4855 -- if the variable is modified.
4857 elsif Ekind
(U_Ent
) = E_Constant
4858 and then Present
(O_Ent
)
4859 and then not Overlays_Constant
(U_Ent
)
4860 and then Address_Clause_Overlay_Warnings
4862 Error_Msg_N
("??constant overlays a variable", Expr
);
4864 -- Imported variables can have an address clause, but then
4865 -- the import is pretty meaningless except to suppress
4866 -- initializations, so we do not need such variables to
4867 -- be statically allocated (and in fact it causes trouble
4868 -- if the address clause is a local value).
4870 elsif Is_Imported
(U_Ent
) then
4871 Set_Is_Statically_Allocated
(U_Ent
, False);
4874 -- We mark a possible modification of a variable with an
4875 -- address clause, since it is likely aliasing is occurring.
4877 Note_Possible_Modification
(Nam
, Sure
=> False);
4879 -- Legality checks on the address clause for initialized
4880 -- objects is deferred until the freeze point, because
4881 -- a subsequent pragma might indicate that the object
4882 -- is imported and thus not initialized. Also, the address
4883 -- clause might involve entities that have yet to be
4886 Set_Has_Delayed_Freeze
(U_Ent
);
4888 -- If an initialization call has been generated for this
4889 -- object, it needs to be deferred to after the freeze node
4890 -- we have just now added, otherwise GIGI will see a
4891 -- reference to the variable (as actual to the IP call)
4892 -- before its definition.
4895 Init_Call
: constant Node_Id
:=
4896 Remove_Init_Call
(U_Ent
, N
);
4899 if Present
(Init_Call
) then
4900 Append_Freeze_Action
(U_Ent
, Init_Call
);
4902 -- Reset Initialization_Statements pointer so that
4903 -- if there is a pragma Import further down, it can
4904 -- clear any default initialization.
4906 Set_Initialization_Statements
(U_Ent
, Init_Call
);
4910 -- Entity has delayed freeze, so we will generate an
4911 -- alignment check at the freeze point unless suppressed.
4913 if not Range_Checks_Suppressed
(U_Ent
)
4914 and then not Alignment_Checks_Suppressed
(U_Ent
)
4916 Set_Check_Address_Alignment
(N
);
4919 -- Kill the size check code, since we are not allocating
4920 -- the variable, it is somewhere else.
4922 Kill_Size_Check_Code
(U_Ent
);
4924 -- If the address clause is of the form:
4926 -- for Y'Address use X'Address
4930 -- Const : constant Address := X'Address;
4932 -- for Y'Address use Const;
4934 -- then we make an entry in the table for checking the size
4935 -- and alignment of the overlaying variable. We defer this
4936 -- check till after code generation to take full advantage
4937 -- of the annotation done by the back end.
4939 -- If the entity has a generic type, the check will be
4940 -- performed in the instance if the actual type justifies
4941 -- it, and we do not insert the clause in the table to
4942 -- prevent spurious warnings.
4944 -- Note: we used to test Comes_From_Source and only give
4945 -- this warning for source entities, but we have removed
4946 -- this test. It really seems bogus to generate overlays
4947 -- that would trigger this warning in generated code.
4948 -- Furthermore, by removing the test, we handle the
4949 -- aspect case properly.
4952 and then Is_Object
(O_Ent
)
4953 and then not Is_Generic_Type
(Etype
(U_Ent
))
4954 and then Address_Clause_Overlay_Warnings
4956 Address_Clause_Checks
.Append
((N
, U_Ent
, O_Ent
, Off
));
4960 -- Not a valid entity for an address clause
4963 Error_Msg_N
("address cannot be given for &", Nam
);
4971 -- Alignment attribute definition clause
4973 when Attribute_Alignment
=> Alignment
: declare
4974 Align
: constant Uint
:= Get_Alignment_Value
(Expr
);
4975 Max_Align
: constant Uint
:= UI_From_Int
(Maximum_Alignment
);
4980 if not Is_Type
(U_Ent
)
4981 and then Ekind
(U_Ent
) /= E_Variable
4982 and then Ekind
(U_Ent
) /= E_Constant
4984 Error_Msg_N
("alignment cannot be given for &", Nam
);
4986 elsif Duplicate_Clause
then
4989 elsif Align
/= No_Uint
then
4990 Set_Has_Alignment_Clause
(U_Ent
);
4992 -- Tagged type case, check for attempt to set alignment to a
4993 -- value greater than Max_Align, and reset if so.
4995 if Is_Tagged_Type
(U_Ent
) and then Align
> Max_Align
then
4997 ("alignment for & set to Maximum_Aligment??", Nam
);
4998 Set_Alignment
(U_Ent
, Max_Align
);
5003 Set_Alignment
(U_Ent
, Align
);
5006 -- For an array type, U_Ent is the first subtype. In that case,
5007 -- also set the alignment of the anonymous base type so that
5008 -- other subtypes (such as the itypes for aggregates of the
5009 -- type) also receive the expected alignment.
5011 if Is_Array_Type
(U_Ent
) then
5012 Set_Alignment
(Base_Type
(U_Ent
), Align
);
5021 -- Bit_Order attribute definition clause
5023 when Attribute_Bit_Order
=> Bit_Order
: declare
5025 if not Is_Record_Type
(U_Ent
) then
5027 ("Bit_Order can only be defined for record type", Nam
);
5029 elsif Duplicate_Clause
then
5033 Analyze_And_Resolve
(Expr
, RTE
(RE_Bit_Order
));
5035 if Etype
(Expr
) = Any_Type
then
5038 elsif not Is_OK_Static_Expression
(Expr
) then
5039 Flag_Non_Static_Expr
5040 ("Bit_Order requires static expression!", Expr
);
5043 if (Expr_Value
(Expr
) = 0) /= Bytes_Big_Endian
then
5044 Set_Reverse_Bit_Order
(Base_Type
(U_Ent
), True);
5050 --------------------
5051 -- Component_Size --
5052 --------------------
5054 -- Component_Size attribute definition clause
5056 when Attribute_Component_Size
=> Component_Size_Case
: declare
5057 Csize
: constant Uint
:= Static_Integer
(Expr
);
5061 New_Ctyp
: Entity_Id
;
5065 if not Is_Array_Type
(U_Ent
) then
5066 Error_Msg_N
("component size requires array type", Nam
);
5070 Btype
:= Base_Type
(U_Ent
);
5071 Ctyp
:= Component_Type
(Btype
);
5073 if Duplicate_Clause
then
5076 elsif Rep_Item_Too_Early
(Btype
, N
) then
5079 elsif Csize
/= No_Uint
then
5080 Check_Size
(Expr
, Ctyp
, Csize
, Biased
);
5082 -- For the biased case, build a declaration for a subtype that
5083 -- will be used to represent the biased subtype that reflects
5084 -- the biased representation of components. We need the subtype
5085 -- to get proper conversions on referencing elements of the
5090 Make_Defining_Identifier
(Loc
,
5092 New_External_Name
(Chars
(U_Ent
), 'C', 0, 'T'));
5095 Make_Subtype_Declaration
(Loc
,
5096 Defining_Identifier
=> New_Ctyp
,
5097 Subtype_Indication
=>
5098 New_Occurrence_Of
(Component_Type
(Btype
), Loc
));
5100 Set_Parent
(Decl
, N
);
5101 Analyze
(Decl
, Suppress
=> All_Checks
);
5103 Set_Has_Delayed_Freeze
(New_Ctyp
, False);
5104 Set_Esize
(New_Ctyp
, Csize
);
5105 Set_RM_Size
(New_Ctyp
, Csize
);
5106 Init_Alignment
(New_Ctyp
);
5107 Set_Is_Itype
(New_Ctyp
, True);
5108 Set_Associated_Node_For_Itype
(New_Ctyp
, U_Ent
);
5110 Set_Component_Type
(Btype
, New_Ctyp
);
5111 Set_Biased
(New_Ctyp
, N
, "component size clause");
5114 Set_Component_Size
(Btype
, Csize
);
5116 -- Deal with warning on overridden size
5118 if Warn_On_Overridden_Size
5119 and then Has_Size_Clause
(Ctyp
)
5120 and then RM_Size
(Ctyp
) /= Csize
5123 ("component size overrides size clause for&?S?", N
, Ctyp
);
5126 Set_Has_Component_Size_Clause
(Btype
, True);
5127 Set_Has_Non_Standard_Rep
(Btype
, True);
5129 end Component_Size_Case
;
5131 -----------------------
5132 -- Constant_Indexing --
5133 -----------------------
5135 when Attribute_Constant_Indexing
=>
5136 Check_Indexing_Functions
;
5142 when Attribute_CPU
=> CPU
:
5144 -- CPU attribute definition clause not allowed except from aspect
5147 if From_Aspect_Specification
(N
) then
5148 if not Is_Task_Type
(U_Ent
) then
5149 Error_Msg_N
("CPU can only be defined for task", Nam
);
5151 elsif Duplicate_Clause
then
5155 -- The expression must be analyzed in the special manner
5156 -- described in "Handling of Default and Per-Object
5157 -- Expressions" in sem.ads.
5159 -- The visibility to the discriminants must be restored
5161 Push_Scope_And_Install_Discriminants
(U_Ent
);
5162 Preanalyze_Spec_Expression
(Expr
, RTE
(RE_CPU_Range
));
5163 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
5165 if not Is_OK_Static_Expression
(Expr
) then
5166 Check_Restriction
(Static_Priorities
, Expr
);
5172 ("attribute& cannot be set with definition clause", N
);
5176 ----------------------
5177 -- Default_Iterator --
5178 ----------------------
5180 when Attribute_Default_Iterator
=> Default_Iterator
: declare
5185 -- If target type is untagged, further checks are irrelevant
5187 if not Is_Tagged_Type
(U_Ent
) then
5189 ("aspect Default_Iterator applies to tagged type", Nam
);
5193 Check_Iterator_Functions
;
5197 if not Is_Entity_Name
(Expr
)
5198 or else Ekind
(Entity
(Expr
)) /= E_Function
5200 Error_Msg_N
("aspect Iterator must be a function", Expr
);
5203 Func
:= Entity
(Expr
);
5206 -- The type of the first parameter must be T, T'class, or a
5207 -- corresponding access type (5.5.1 (8/3). If function is
5208 -- parameterless label type accordingly.
5210 if No
(First_Formal
(Func
)) then
5213 Typ
:= Etype
(First_Formal
(Func
));
5217 or else Typ
= Class_Wide_Type
(U_Ent
)
5218 or else (Is_Access_Type
(Typ
)
5219 and then Designated_Type
(Typ
) = U_Ent
)
5220 or else (Is_Access_Type
(Typ
)
5221 and then Designated_Type
(Typ
) =
5222 Class_Wide_Type
(U_Ent
))
5228 ("Default Iterator must be a primitive of&", Func
, U_Ent
);
5230 end Default_Iterator
;
5232 ------------------------
5233 -- Dispatching_Domain --
5234 ------------------------
5236 when Attribute_Dispatching_Domain
=> Dispatching_Domain
:
5238 -- Dispatching_Domain attribute definition clause not allowed
5239 -- except from aspect specification.
5241 if From_Aspect_Specification
(N
) then
5242 if not Is_Task_Type
(U_Ent
) then
5244 ("Dispatching_Domain can only be defined for task", Nam
);
5246 elsif Duplicate_Clause
then
5250 -- The expression must be analyzed in the special manner
5251 -- described in "Handling of Default and Per-Object
5252 -- Expressions" in sem.ads.
5254 -- The visibility to the discriminants must be restored
5256 Push_Scope_And_Install_Discriminants
(U_Ent
);
5258 Preanalyze_Spec_Expression
5259 (Expr
, RTE
(RE_Dispatching_Domain
));
5261 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
5266 ("attribute& cannot be set with definition clause", N
);
5268 end Dispatching_Domain
;
5274 when Attribute_External_Tag
=> External_Tag
:
5276 if not Is_Tagged_Type
(U_Ent
) then
5277 Error_Msg_N
("should be a tagged type", Nam
);
5280 if Duplicate_Clause
then
5284 Analyze_And_Resolve
(Expr
, Standard_String
);
5286 if not Is_OK_Static_Expression
(Expr
) then
5287 Flag_Non_Static_Expr
5288 ("static string required for tag name!", Nam
);
5291 if not Is_Library_Level_Entity
(U_Ent
) then
5293 ("??non-unique external tag supplied for &", N
, U_Ent
);
5295 ("\??same external tag applies to all "
5296 & "subprogram calls", N
);
5298 ("\??corresponding internal tag cannot be obtained", N
);
5303 --------------------------
5304 -- Implicit_Dereference --
5305 --------------------------
5307 when Attribute_Implicit_Dereference
=>
5309 -- Legality checks already performed at the point of the type
5310 -- declaration, aspect is not delayed.
5318 when Attribute_Input
=>
5319 Analyze_Stream_TSS_Definition
(TSS_Stream_Input
);
5320 Set_Has_Specified_Stream_Input
(Ent
);
5322 ------------------------
5323 -- Interrupt_Priority --
5324 ------------------------
5326 when Attribute_Interrupt_Priority
=> Interrupt_Priority
:
5328 -- Interrupt_Priority attribute definition clause not allowed
5329 -- except from aspect specification.
5331 if From_Aspect_Specification
(N
) then
5332 if not Is_Concurrent_Type
(U_Ent
) then
5334 ("Interrupt_Priority can only be defined for task "
5335 & "and protected object", Nam
);
5337 elsif Duplicate_Clause
then
5341 -- The expression must be analyzed in the special manner
5342 -- described in "Handling of Default and Per-Object
5343 -- Expressions" in sem.ads.
5345 -- The visibility to the discriminants must be restored
5347 Push_Scope_And_Install_Discriminants
(U_Ent
);
5349 Preanalyze_Spec_Expression
5350 (Expr
, RTE
(RE_Interrupt_Priority
));
5352 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
5354 -- Check the No_Task_At_Interrupt_Priority restriction
5356 if Is_Task_Type
(U_Ent
) then
5357 Check_Restriction
(No_Task_At_Interrupt_Priority
, N
);
5363 ("attribute& cannot be set with definition clause", N
);
5365 end Interrupt_Priority
;
5371 when Attribute_Iterable
=>
5374 if Nkind
(Expr
) /= N_Aggregate
then
5375 Error_Msg_N
("aspect Iterable must be an aggregate", Expr
);
5382 Assoc
:= First
(Component_Associations
(Expr
));
5383 while Present
(Assoc
) loop
5384 if not Is_Entity_Name
(Expression
(Assoc
)) then
5385 Error_Msg_N
("value must be a function", Assoc
);
5392 ----------------------
5393 -- Iterator_Element --
5394 ----------------------
5396 when Attribute_Iterator_Element
=>
5399 if not Is_Entity_Name
(Expr
)
5400 or else not Is_Type
(Entity
(Expr
))
5402 Error_Msg_N
("aspect Iterator_Element must be a type", Expr
);
5409 -- Machine radix attribute definition clause
5411 when Attribute_Machine_Radix
=> Machine_Radix
: declare
5412 Radix
: constant Uint
:= Static_Integer
(Expr
);
5415 if not Is_Decimal_Fixed_Point_Type
(U_Ent
) then
5416 Error_Msg_N
("decimal fixed-point type expected for &", Nam
);
5418 elsif Duplicate_Clause
then
5421 elsif Radix
/= No_Uint
then
5422 Set_Has_Machine_Radix_Clause
(U_Ent
);
5423 Set_Has_Non_Standard_Rep
(Base_Type
(U_Ent
));
5427 elsif Radix
= 10 then
5428 Set_Machine_Radix_10
(U_Ent
);
5430 Error_Msg_N
("machine radix value must be 2 or 10", Expr
);
5439 -- Object_Size attribute definition clause
5441 when Attribute_Object_Size
=> Object_Size
: declare
5442 Size
: constant Uint
:= Static_Integer
(Expr
);
5445 pragma Warnings
(Off
, Biased
);
5448 if not Is_Type
(U_Ent
) then
5449 Error_Msg_N
("Object_Size cannot be given for &", Nam
);
5451 elsif Duplicate_Clause
then
5455 Check_Size
(Expr
, U_Ent
, Size
, Biased
);
5457 if Is_Scalar_Type
(U_Ent
) then
5458 if Size
/= 8 and then Size
/= 16 and then Size
/= 32
5459 and then UI_Mod
(Size
, 64) /= 0
5462 ("Object_Size must be 8, 16, 32, or multiple of 64",
5466 elsif Size
mod 8 /= 0 then
5467 Error_Msg_N
("Object_Size must be a multiple of 8", Expr
);
5470 Set_Esize
(U_Ent
, Size
);
5471 Set_Has_Object_Size_Clause
(U_Ent
);
5472 Alignment_Check_For_Size_Change
(U_Ent
, Size
);
5480 when Attribute_Output
=>
5481 Analyze_Stream_TSS_Definition
(TSS_Stream_Output
);
5482 Set_Has_Specified_Stream_Output
(Ent
);
5488 when Attribute_Priority
=> Priority
:
5490 -- Priority attribute definition clause not allowed except from
5491 -- aspect specification.
5493 if From_Aspect_Specification
(N
) then
5494 if not (Is_Concurrent_Type
(U_Ent
)
5495 or else Ekind
(U_Ent
) = E_Procedure
)
5498 ("Priority can only be defined for task and protected "
5501 elsif Duplicate_Clause
then
5505 -- The expression must be analyzed in the special manner
5506 -- described in "Handling of Default and Per-Object
5507 -- Expressions" in sem.ads.
5509 -- The visibility to the discriminants must be restored
5511 Push_Scope_And_Install_Discriminants
(U_Ent
);
5512 Preanalyze_Spec_Expression
(Expr
, Standard_Integer
);
5513 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
5515 if not Is_OK_Static_Expression
(Expr
) then
5516 Check_Restriction
(Static_Priorities
, Expr
);
5522 ("attribute& cannot be set with definition clause", N
);
5530 when Attribute_Read
=>
5531 Analyze_Stream_TSS_Definition
(TSS_Stream_Read
);
5532 Set_Has_Specified_Stream_Read
(Ent
);
5534 --------------------------
5535 -- Scalar_Storage_Order --
5536 --------------------------
5538 -- Scalar_Storage_Order attribute definition clause
5540 when Attribute_Scalar_Storage_Order
=> Scalar_Storage_Order
: declare
5542 if not (Is_Record_Type
(U_Ent
) or else Is_Array_Type
(U_Ent
)) then
5544 ("Scalar_Storage_Order can only be defined for "
5545 & "record or array type", Nam
);
5547 elsif Duplicate_Clause
then
5551 Analyze_And_Resolve
(Expr
, RTE
(RE_Bit_Order
));
5553 if Etype
(Expr
) = Any_Type
then
5556 elsif not Is_OK_Static_Expression
(Expr
) then
5557 Flag_Non_Static_Expr
5558 ("Scalar_Storage_Order requires static expression!", Expr
);
5560 elsif (Expr_Value
(Expr
) = 0) /= Bytes_Big_Endian
then
5562 -- Here for the case of a non-default (i.e. non-confirming)
5563 -- Scalar_Storage_Order attribute definition.
5565 if Support_Nondefault_SSO_On_Target
then
5566 Set_Reverse_Storage_Order
(Base_Type
(U_Ent
), True);
5569 ("non-default Scalar_Storage_Order "
5570 & "not supported on target", Expr
);
5574 -- Clear SSO default indications since explicit setting of the
5575 -- order overrides the defaults.
5577 Set_SSO_Set_Low_By_Default
(Base_Type
(U_Ent
), False);
5578 Set_SSO_Set_High_By_Default
(Base_Type
(U_Ent
), False);
5580 end Scalar_Storage_Order
;
5586 -- Size attribute definition clause
5588 when Attribute_Size
=> Size
: declare
5589 Size
: constant Uint
:= Static_Integer
(Expr
);
5596 if Duplicate_Clause
then
5599 elsif not Is_Type
(U_Ent
)
5600 and then Ekind
(U_Ent
) /= E_Variable
5601 and then Ekind
(U_Ent
) /= E_Constant
5603 Error_Msg_N
("size cannot be given for &", Nam
);
5605 elsif Is_Array_Type
(U_Ent
)
5606 and then not Is_Constrained
(U_Ent
)
5609 ("size cannot be given for unconstrained array", Nam
);
5611 elsif Size
/= No_Uint
then
5612 if Is_Type
(U_Ent
) then
5615 Etyp
:= Etype
(U_Ent
);
5618 -- Check size, note that Gigi is in charge of checking that the
5619 -- size of an array or record type is OK. Also we do not check
5620 -- the size in the ordinary fixed-point case, since it is too
5621 -- early to do so (there may be subsequent small clause that
5622 -- affects the size). We can check the size if a small clause
5623 -- has already been given.
5625 if not Is_Ordinary_Fixed_Point_Type
(U_Ent
)
5626 or else Has_Small_Clause
(U_Ent
)
5628 Check_Size
(Expr
, Etyp
, Size
, Biased
);
5629 Set_Biased
(U_Ent
, N
, "size clause", Biased
);
5632 -- For types set RM_Size and Esize if possible
5634 if Is_Type
(U_Ent
) then
5635 Set_RM_Size
(U_Ent
, Size
);
5637 -- For elementary types, increase Object_Size to power of 2,
5638 -- but not less than a storage unit in any case (normally
5639 -- this means it will be byte addressable).
5641 -- For all other types, nothing else to do, we leave Esize
5642 -- (object size) unset, the back end will set it from the
5643 -- size and alignment in an appropriate manner.
5645 -- In both cases, we check whether the alignment must be
5646 -- reset in the wake of the size change.
5648 if Is_Elementary_Type
(U_Ent
) then
5649 if Size
<= System_Storage_Unit
then
5650 Init_Esize
(U_Ent
, System_Storage_Unit
);
5651 elsif Size
<= 16 then
5652 Init_Esize
(U_Ent
, 16);
5653 elsif Size
<= 32 then
5654 Init_Esize
(U_Ent
, 32);
5656 Set_Esize
(U_Ent
, (Size
+ 63) / 64 * 64);
5659 Alignment_Check_For_Size_Change
(U_Ent
, Esize
(U_Ent
));
5661 Alignment_Check_For_Size_Change
(U_Ent
, Size
);
5664 -- For objects, set Esize only
5667 if Is_Elementary_Type
(Etyp
) then
5668 if Size
/= System_Storage_Unit
5670 Size
/= System_Storage_Unit
* 2
5672 Size
/= System_Storage_Unit
* 4
5674 Size
/= System_Storage_Unit
* 8
5676 Error_Msg_Uint_1
:= UI_From_Int
(System_Storage_Unit
);
5677 Error_Msg_Uint_2
:= Error_Msg_Uint_1
* 8;
5679 ("size for primitive object must be a power of 2"
5680 & " in the range ^-^", N
);
5684 Set_Esize
(U_Ent
, Size
);
5687 Set_Has_Size_Clause
(U_Ent
);
5695 -- Small attribute definition clause
5697 when Attribute_Small
=> Small
: declare
5698 Implicit_Base
: constant Entity_Id
:= Base_Type
(U_Ent
);
5702 Analyze_And_Resolve
(Expr
, Any_Real
);
5704 if Etype
(Expr
) = Any_Type
then
5707 elsif not Is_OK_Static_Expression
(Expr
) then
5708 Flag_Non_Static_Expr
5709 ("small requires static expression!", Expr
);
5713 Small
:= Expr_Value_R
(Expr
);
5715 if Small
<= Ureal_0
then
5716 Error_Msg_N
("small value must be greater than zero", Expr
);
5722 if not Is_Ordinary_Fixed_Point_Type
(U_Ent
) then
5724 ("small requires an ordinary fixed point type", Nam
);
5726 elsif Has_Small_Clause
(U_Ent
) then
5727 Error_Msg_N
("small already given for &", Nam
);
5729 elsif Small
> Delta_Value
(U_Ent
) then
5731 ("small value must not be greater than delta value", Nam
);
5734 Set_Small_Value
(U_Ent
, Small
);
5735 Set_Small_Value
(Implicit_Base
, Small
);
5736 Set_Has_Small_Clause
(U_Ent
);
5737 Set_Has_Small_Clause
(Implicit_Base
);
5738 Set_Has_Non_Standard_Rep
(Implicit_Base
);
5746 -- Storage_Pool attribute definition clause
5748 when Attribute_Storage_Pool | Attribute_Simple_Storage_Pool
=> declare
5753 if Ekind
(U_Ent
) = E_Access_Subprogram_Type
then
5755 ("storage pool cannot be given for access-to-subprogram type",
5760 Ekind_In
(U_Ent
, E_Access_Type
, E_General_Access_Type
)
5763 ("storage pool can only be given for access types", Nam
);
5766 elsif Is_Derived_Type
(U_Ent
) then
5768 ("storage pool cannot be given for a derived access type",
5771 elsif Duplicate_Clause
then
5774 elsif Present
(Associated_Storage_Pool
(U_Ent
)) then
5775 Error_Msg_N
("storage pool already given for &", Nam
);
5779 -- Check for Storage_Size previously given
5782 SS
: constant Node_Id
:=
5783 Get_Attribute_Definition_Clause
5784 (U_Ent
, Attribute_Storage_Size
);
5786 if Present
(SS
) then
5787 Check_Pool_Size_Clash
(U_Ent
, N
, SS
);
5791 -- Storage_Pool case
5793 if Id
= Attribute_Storage_Pool
then
5795 (Expr
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
5797 -- In the Simple_Storage_Pool case, we allow a variable of any
5798 -- simple storage pool type, so we Resolve without imposing an
5802 Analyze_And_Resolve
(Expr
);
5804 if not Present
(Get_Rep_Pragma
5805 (Etype
(Expr
), Name_Simple_Storage_Pool_Type
))
5808 ("expression must be of a simple storage pool type", Expr
);
5812 if not Denotes_Variable
(Expr
) then
5813 Error_Msg_N
("storage pool must be a variable", Expr
);
5817 if Nkind
(Expr
) = N_Type_Conversion
then
5818 T
:= Etype
(Expression
(Expr
));
5823 -- The Stack_Bounded_Pool is used internally for implementing
5824 -- access types with a Storage_Size. Since it only work properly
5825 -- when used on one specific type, we need to check that it is not
5826 -- hijacked improperly:
5828 -- type T is access Integer;
5829 -- for T'Storage_Size use n;
5830 -- type Q is access Float;
5831 -- for Q'Storage_Size use T'Storage_Size; -- incorrect
5833 if RTE_Available
(RE_Stack_Bounded_Pool
)
5834 and then Base_Type
(T
) = RTE
(RE_Stack_Bounded_Pool
)
5836 Error_Msg_N
("non-shareable internal Pool", Expr
);
5840 -- If the argument is a name that is not an entity name, then
5841 -- we construct a renaming operation to define an entity of
5842 -- type storage pool.
5844 if not Is_Entity_Name
(Expr
)
5845 and then Is_Object_Reference
(Expr
)
5847 Pool
:= Make_Temporary
(Loc
, 'P', Expr
);
5850 Rnode
: constant Node_Id
:=
5851 Make_Object_Renaming_Declaration
(Loc
,
5852 Defining_Identifier
=> Pool
,
5854 New_Occurrence_Of
(Etype
(Expr
), Loc
),
5858 -- If the attribute definition clause comes from an aspect
5859 -- clause, then insert the renaming before the associated
5860 -- entity's declaration, since the attribute clause has
5861 -- not yet been appended to the declaration list.
5863 if From_Aspect_Specification
(N
) then
5864 Insert_Before
(Parent
(Entity
(N
)), Rnode
);
5866 Insert_Before
(N
, Rnode
);
5870 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
5873 elsif Is_Entity_Name
(Expr
) then
5874 Pool
:= Entity
(Expr
);
5876 -- If pool is a renamed object, get original one. This can
5877 -- happen with an explicit renaming, and within instances.
5879 while Present
(Renamed_Object
(Pool
))
5880 and then Is_Entity_Name
(Renamed_Object
(Pool
))
5882 Pool
:= Entity
(Renamed_Object
(Pool
));
5885 if Present
(Renamed_Object
(Pool
))
5886 and then Nkind
(Renamed_Object
(Pool
)) = N_Type_Conversion
5887 and then Is_Entity_Name
(Expression
(Renamed_Object
(Pool
)))
5889 Pool
:= Entity
(Expression
(Renamed_Object
(Pool
)));
5892 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
5894 elsif Nkind
(Expr
) = N_Type_Conversion
5895 and then Is_Entity_Name
(Expression
(Expr
))
5896 and then Nkind
(Original_Node
(Expr
)) = N_Attribute_Reference
5898 Pool
:= Entity
(Expression
(Expr
));
5899 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
5902 Error_Msg_N
("incorrect reference to a Storage Pool", Expr
);
5911 -- Storage_Size attribute definition clause
5913 when Attribute_Storage_Size
=> Storage_Size
: declare
5914 Btype
: constant Entity_Id
:= Base_Type
(U_Ent
);
5917 if Is_Task_Type
(U_Ent
) then
5919 -- Check obsolescent (but never obsolescent if from aspect)
5921 if not From_Aspect_Specification
(N
) then
5922 Check_Restriction
(No_Obsolescent_Features
, N
);
5924 if Warn_On_Obsolescent_Feature
then
5926 ("?j?storage size clause for task is an " &
5927 "obsolescent feature (RM J.9)", N
);
5928 Error_Msg_N
("\?j?use Storage_Size pragma instead", N
);
5935 if not Is_Access_Type
(U_Ent
)
5936 and then Ekind
(U_Ent
) /= E_Task_Type
5938 Error_Msg_N
("storage size cannot be given for &", Nam
);
5940 elsif Is_Access_Type
(U_Ent
) and Is_Derived_Type
(U_Ent
) then
5942 ("storage size cannot be given for a derived access type",
5945 elsif Duplicate_Clause
then
5949 Analyze_And_Resolve
(Expr
, Any_Integer
);
5951 if Is_Access_Type
(U_Ent
) then
5953 -- Check for Storage_Pool previously given
5956 SP
: constant Node_Id
:=
5957 Get_Attribute_Definition_Clause
5958 (U_Ent
, Attribute_Storage_Pool
);
5961 if Present
(SP
) then
5962 Check_Pool_Size_Clash
(U_Ent
, SP
, N
);
5966 -- Special case of for x'Storage_Size use 0
5968 if Is_OK_Static_Expression
(Expr
)
5969 and then Expr_Value
(Expr
) = 0
5971 Set_No_Pool_Assigned
(Btype
);
5975 Set_Has_Storage_Size_Clause
(Btype
);
5983 when Attribute_Stream_Size
=> Stream_Size
: declare
5984 Size
: constant Uint
:= Static_Integer
(Expr
);
5987 if Ada_Version
<= Ada_95
then
5988 Check_Restriction
(No_Implementation_Attributes
, N
);
5991 if Duplicate_Clause
then
5994 elsif Is_Elementary_Type
(U_Ent
) then
5995 if Size
/= System_Storage_Unit
5997 Size
/= System_Storage_Unit
* 2
5999 Size
/= System_Storage_Unit
* 4
6001 Size
/= System_Storage_Unit
* 8
6003 Error_Msg_Uint_1
:= UI_From_Int
(System_Storage_Unit
);
6005 ("stream size for elementary type must be a"
6006 & " power of 2 and at least ^", N
);
6008 elsif RM_Size
(U_Ent
) > Size
then
6009 Error_Msg_Uint_1
:= RM_Size
(U_Ent
);
6011 ("stream size for elementary type must be a"
6012 & " power of 2 and at least ^", N
);
6015 Set_Has_Stream_Size_Clause
(U_Ent
);
6018 Error_Msg_N
("Stream_Size cannot be given for &", Nam
);
6026 -- Value_Size attribute definition clause
6028 when Attribute_Value_Size
=> Value_Size
: declare
6029 Size
: constant Uint
:= Static_Integer
(Expr
);
6033 if not Is_Type
(U_Ent
) then
6034 Error_Msg_N
("Value_Size cannot be given for &", Nam
);
6036 elsif Duplicate_Clause
then
6039 elsif Is_Array_Type
(U_Ent
)
6040 and then not Is_Constrained
(U_Ent
)
6043 ("Value_Size cannot be given for unconstrained array", Nam
);
6046 if Is_Elementary_Type
(U_Ent
) then
6047 Check_Size
(Expr
, U_Ent
, Size
, Biased
);
6048 Set_Biased
(U_Ent
, N
, "value size clause", Biased
);
6051 Set_RM_Size
(U_Ent
, Size
);
6055 -----------------------
6056 -- Variable_Indexing --
6057 -----------------------
6059 when Attribute_Variable_Indexing
=>
6060 Check_Indexing_Functions
;
6066 when Attribute_Write
=>
6067 Analyze_Stream_TSS_Definition
(TSS_Stream_Write
);
6068 Set_Has_Specified_Stream_Write
(Ent
);
6070 -- All other attributes cannot be set
6074 ("attribute& cannot be set with definition clause", N
);
6077 -- The test for the type being frozen must be performed after any
6078 -- expression the clause has been analyzed since the expression itself
6079 -- might cause freezing that makes the clause illegal.
6081 if Rep_Item_Too_Late
(U_Ent
, N
, FOnly
) then
6084 end Analyze_Attribute_Definition_Clause
;
6086 ----------------------------
6087 -- Analyze_Code_Statement --
6088 ----------------------------
6090 procedure Analyze_Code_Statement
(N
: Node_Id
) is
6091 HSS
: constant Node_Id
:= Parent
(N
);
6092 SBody
: constant Node_Id
:= Parent
(HSS
);
6093 Subp
: constant Entity_Id
:= Current_Scope
;
6100 -- Accept foreign code statements for CodePeer. The analysis is skipped
6101 -- to avoid rejecting unrecognized constructs.
6103 if CodePeer_Mode
then
6108 -- Analyze and check we get right type, note that this implements the
6109 -- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that is
6110 -- the only way that Asm_Insn could possibly be visible.
6112 Analyze_And_Resolve
(Expression
(N
));
6114 if Etype
(Expression
(N
)) = Any_Type
then
6116 elsif Etype
(Expression
(N
)) /= RTE
(RE_Asm_Insn
) then
6117 Error_Msg_N
("incorrect type for code statement", N
);
6121 Check_Code_Statement
(N
);
6123 -- Make sure we appear in the handled statement sequence of a subprogram
6126 if Nkind
(HSS
) /= N_Handled_Sequence_Of_Statements
6127 or else Nkind
(SBody
) /= N_Subprogram_Body
6130 ("code statement can only appear in body of subprogram", N
);
6134 -- Do remaining checks (RM 13.8(3)) if not already done
6136 if not Is_Machine_Code_Subprogram
(Subp
) then
6137 Set_Is_Machine_Code_Subprogram
(Subp
);
6139 -- No exception handlers allowed
6141 if Present
(Exception_Handlers
(HSS
)) then
6143 ("exception handlers not permitted in machine code subprogram",
6144 First
(Exception_Handlers
(HSS
)));
6147 -- No declarations other than use clauses and pragmas (we allow
6148 -- certain internally generated declarations as well).
6150 Decl
:= First
(Declarations
(SBody
));
6151 while Present
(Decl
) loop
6152 DeclO
:= Original_Node
(Decl
);
6153 if Comes_From_Source
(DeclO
)
6154 and not Nkind_In
(DeclO
, N_Pragma
,
6155 N_Use_Package_Clause
,
6157 N_Implicit_Label_Declaration
)
6160 ("this declaration not allowed in machine code subprogram",
6167 -- No statements other than code statements, pragmas, and labels.
6168 -- Again we allow certain internally generated statements.
6170 -- In Ada 2012, qualified expressions are names, and the code
6171 -- statement is initially parsed as a procedure call.
6173 Stmt
:= First
(Statements
(HSS
));
6174 while Present
(Stmt
) loop
6175 StmtO
:= Original_Node
(Stmt
);
6177 -- A procedure call transformed into a code statement is OK
6179 if Ada_Version
>= Ada_2012
6180 and then Nkind
(StmtO
) = N_Procedure_Call_Statement
6181 and then Nkind
(Name
(StmtO
)) = N_Qualified_Expression
6185 elsif Comes_From_Source
(StmtO
)
6186 and then not Nkind_In
(StmtO
, N_Pragma
,
6191 ("this statement is not allowed in machine code subprogram",
6198 end Analyze_Code_Statement
;
6200 -----------------------------------------------
6201 -- Analyze_Enumeration_Representation_Clause --
6202 -----------------------------------------------
6204 procedure Analyze_Enumeration_Representation_Clause
(N
: Node_Id
) is
6205 Ident
: constant Node_Id
:= Identifier
(N
);
6206 Aggr
: constant Node_Id
:= Array_Aggregate
(N
);
6207 Enumtype
: Entity_Id
;
6214 Err
: Boolean := False;
6215 -- Set True to avoid cascade errors and crashes on incorrect source code
6217 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Universal_Integer
));
6218 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(Universal_Integer
));
6219 -- Allowed range of universal integer (= allowed range of enum lit vals)
6223 -- Minimum and maximum values of entries
6226 -- Pointer to node for literal providing max value
6229 if Ignore_Rep_Clauses
then
6230 Kill_Rep_Clause
(N
);
6234 -- Ignore enumeration rep clauses by default in CodePeer mode,
6235 -- unless -gnatd.I is specified, as a work around for potential false
6236 -- positive messages.
6238 if CodePeer_Mode
and not Debug_Flag_Dot_II
then
6242 -- First some basic error checks
6245 Enumtype
:= Entity
(Ident
);
6247 if Enumtype
= Any_Type
6248 or else Rep_Item_Too_Early
(Enumtype
, N
)
6252 Enumtype
:= Underlying_Type
(Enumtype
);
6255 if not Is_Enumeration_Type
(Enumtype
) then
6257 ("enumeration type required, found}",
6258 Ident
, First_Subtype
(Enumtype
));
6262 -- Ignore rep clause on generic actual type. This will already have
6263 -- been flagged on the template as an error, and this is the safest
6264 -- way to ensure we don't get a junk cascaded message in the instance.
6266 if Is_Generic_Actual_Type
(Enumtype
) then
6269 -- Type must be in current scope
6271 elsif Scope
(Enumtype
) /= Current_Scope
then
6272 Error_Msg_N
("type must be declared in this scope", Ident
);
6275 -- Type must be a first subtype
6277 elsif not Is_First_Subtype
(Enumtype
) then
6278 Error_Msg_N
("cannot give enumeration rep clause for subtype", N
);
6281 -- Ignore duplicate rep clause
6283 elsif Has_Enumeration_Rep_Clause
(Enumtype
) then
6284 Error_Msg_N
("duplicate enumeration rep clause ignored", N
);
6287 -- Don't allow rep clause for standard [wide_[wide_]]character
6289 elsif Is_Standard_Character_Type
(Enumtype
) then
6290 Error_Msg_N
("enumeration rep clause not allowed for this type", N
);
6293 -- Check that the expression is a proper aggregate (no parentheses)
6295 elsif Paren_Count
(Aggr
) /= 0 then
6297 ("extra parentheses surrounding aggregate not allowed",
6301 -- All tests passed, so set rep clause in place
6304 Set_Has_Enumeration_Rep_Clause
(Enumtype
);
6305 Set_Has_Enumeration_Rep_Clause
(Base_Type
(Enumtype
));
6308 -- Now we process the aggregate. Note that we don't use the normal
6309 -- aggregate code for this purpose, because we don't want any of the
6310 -- normal expansion activities, and a number of special semantic
6311 -- rules apply (including the component type being any integer type)
6313 Elit
:= First_Literal
(Enumtype
);
6315 -- First the positional entries if any
6317 if Present
(Expressions
(Aggr
)) then
6318 Expr
:= First
(Expressions
(Aggr
));
6319 while Present
(Expr
) loop
6321 Error_Msg_N
("too many entries in aggregate", Expr
);
6325 Val
:= Static_Integer
(Expr
);
6327 -- Err signals that we found some incorrect entries processing
6328 -- the list. The final checks for completeness and ordering are
6329 -- skipped in this case.
6331 if Val
= No_Uint
then
6334 elsif Val
< Lo
or else Hi
< Val
then
6335 Error_Msg_N
("value outside permitted range", Expr
);
6339 Set_Enumeration_Rep
(Elit
, Val
);
6340 Set_Enumeration_Rep_Expr
(Elit
, Expr
);
6346 -- Now process the named entries if present
6348 if Present
(Component_Associations
(Aggr
)) then
6349 Assoc
:= First
(Component_Associations
(Aggr
));
6350 while Present
(Assoc
) loop
6351 Choice
:= First
(Choices
(Assoc
));
6353 if Present
(Next
(Choice
)) then
6355 ("multiple choice not allowed here", Next
(Choice
));
6359 if Nkind
(Choice
) = N_Others_Choice
then
6360 Error_Msg_N
("others choice not allowed here", Choice
);
6363 elsif Nkind
(Choice
) = N_Range
then
6365 -- ??? should allow zero/one element range here
6367 Error_Msg_N
("range not allowed here", Choice
);
6371 Analyze_And_Resolve
(Choice
, Enumtype
);
6373 if Error_Posted
(Choice
) then
6378 if Is_Entity_Name
(Choice
)
6379 and then Is_Type
(Entity
(Choice
))
6381 Error_Msg_N
("subtype name not allowed here", Choice
);
6384 -- ??? should allow static subtype with zero/one entry
6386 elsif Etype
(Choice
) = Base_Type
(Enumtype
) then
6387 if not Is_OK_Static_Expression
(Choice
) then
6388 Flag_Non_Static_Expr
6389 ("non-static expression used for choice!", Choice
);
6393 Elit
:= Expr_Value_E
(Choice
);
6395 if Present
(Enumeration_Rep_Expr
(Elit
)) then
6397 Sloc
(Enumeration_Rep_Expr
(Elit
));
6399 ("representation for& previously given#",
6404 Set_Enumeration_Rep_Expr
(Elit
, Expression
(Assoc
));
6406 Expr
:= Expression
(Assoc
);
6407 Val
:= Static_Integer
(Expr
);
6409 if Val
= No_Uint
then
6412 elsif Val
< Lo
or else Hi
< Val
then
6413 Error_Msg_N
("value outside permitted range", Expr
);
6417 Set_Enumeration_Rep
(Elit
, Val
);
6427 -- Aggregate is fully processed. Now we check that a full set of
6428 -- representations was given, and that they are in range and in order.
6429 -- These checks are only done if no other errors occurred.
6435 Elit
:= First_Literal
(Enumtype
);
6436 while Present
(Elit
) loop
6437 if No
(Enumeration_Rep_Expr
(Elit
)) then
6438 Error_Msg_NE
("missing representation for&!", N
, Elit
);
6441 Val
:= Enumeration_Rep
(Elit
);
6443 if Min
= No_Uint
then
6447 if Val
/= No_Uint
then
6448 if Max
/= No_Uint
and then Val
<= Max
then
6450 ("enumeration value for& not ordered!",
6451 Enumeration_Rep_Expr
(Elit
), Elit
);
6454 Max_Node
:= Enumeration_Rep_Expr
(Elit
);
6458 -- If there is at least one literal whose representation is not
6459 -- equal to the Pos value, then note that this enumeration type
6460 -- has a non-standard representation.
6462 if Val
/= Enumeration_Pos
(Elit
) then
6463 Set_Has_Non_Standard_Rep
(Base_Type
(Enumtype
));
6470 -- Now set proper size information
6473 Minsize
: Uint
:= UI_From_Int
(Minimum_Size
(Enumtype
));
6476 if Has_Size_Clause
(Enumtype
) then
6478 -- All OK, if size is OK now
6480 if RM_Size
(Enumtype
) >= Minsize
then
6484 -- Try if we can get by with biasing
6487 UI_From_Int
(Minimum_Size
(Enumtype
, Biased
=> True));
6489 -- Error message if even biasing does not work
6491 if RM_Size
(Enumtype
) < Minsize
then
6492 Error_Msg_Uint_1
:= RM_Size
(Enumtype
);
6493 Error_Msg_Uint_2
:= Max
;
6495 ("previously given size (^) is too small "
6496 & "for this value (^)", Max_Node
);
6498 -- If biasing worked, indicate that we now have biased rep
6502 (Enumtype
, Size_Clause
(Enumtype
), "size clause");
6507 Set_RM_Size
(Enumtype
, Minsize
);
6508 Set_Enum_Esize
(Enumtype
);
6511 Set_RM_Size
(Base_Type
(Enumtype
), RM_Size
(Enumtype
));
6512 Set_Esize
(Base_Type
(Enumtype
), Esize
(Enumtype
));
6513 Set_Alignment
(Base_Type
(Enumtype
), Alignment
(Enumtype
));
6517 -- We repeat the too late test in case it froze itself
6519 if Rep_Item_Too_Late
(Enumtype
, N
) then
6522 end Analyze_Enumeration_Representation_Clause
;
6524 ----------------------------
6525 -- Analyze_Free_Statement --
6526 ----------------------------
6528 procedure Analyze_Free_Statement
(N
: Node_Id
) is
6530 Analyze
(Expression
(N
));
6531 end Analyze_Free_Statement
;
6533 ---------------------------
6534 -- Analyze_Freeze_Entity --
6535 ---------------------------
6537 procedure Analyze_Freeze_Entity
(N
: Node_Id
) is
6539 Freeze_Entity_Checks
(N
);
6540 end Analyze_Freeze_Entity
;
6542 -----------------------------------
6543 -- Analyze_Freeze_Generic_Entity --
6544 -----------------------------------
6546 procedure Analyze_Freeze_Generic_Entity
(N
: Node_Id
) is
6548 Freeze_Entity_Checks
(N
);
6549 end Analyze_Freeze_Generic_Entity
;
6551 ------------------------------------------
6552 -- Analyze_Record_Representation_Clause --
6553 ------------------------------------------
6555 -- Note: we check as much as we can here, but we can't do any checks
6556 -- based on the position values (e.g. overlap checks) until freeze time
6557 -- because especially in Ada 2005 (machine scalar mode), the processing
6558 -- for non-standard bit order can substantially change the positions.
6559 -- See procedure Check_Record_Representation_Clause (called from Freeze)
6560 -- for the remainder of this processing.
6562 procedure Analyze_Record_Representation_Clause
(N
: Node_Id
) is
6563 Ident
: constant Node_Id
:= Identifier
(N
);
6568 Hbit
: Uint
:= Uint_0
;
6572 Rectype
: Entity_Id
;
6575 function Is_Inherited
(Comp
: Entity_Id
) return Boolean;
6576 -- True if Comp is an inherited component in a record extension
6582 function Is_Inherited
(Comp
: Entity_Id
) return Boolean is
6583 Comp_Base
: Entity_Id
;
6586 if Ekind
(Rectype
) = E_Record_Subtype
then
6587 Comp_Base
:= Original_Record_Component
(Comp
);
6592 return Comp_Base
/= Original_Record_Component
(Comp_Base
);
6597 Is_Record_Extension
: Boolean;
6598 -- True if Rectype is a record extension
6600 CR_Pragma
: Node_Id
:= Empty
;
6601 -- Points to N_Pragma node if Complete_Representation pragma present
6603 -- Start of processing for Analyze_Record_Representation_Clause
6606 if Ignore_Rep_Clauses
then
6607 Kill_Rep_Clause
(N
);
6612 Rectype
:= Entity
(Ident
);
6614 if Rectype
= Any_Type
or else Rep_Item_Too_Early
(Rectype
, N
) then
6617 Rectype
:= Underlying_Type
(Rectype
);
6620 -- First some basic error checks
6622 if not Is_Record_Type
(Rectype
) then
6624 ("record type required, found}", Ident
, First_Subtype
(Rectype
));
6627 elsif Scope
(Rectype
) /= Current_Scope
then
6628 Error_Msg_N
("type must be declared in this scope", N
);
6631 elsif not Is_First_Subtype
(Rectype
) then
6632 Error_Msg_N
("cannot give record rep clause for subtype", N
);
6635 elsif Has_Record_Rep_Clause
(Rectype
) then
6636 Error_Msg_N
("duplicate record rep clause ignored", N
);
6639 elsif Rep_Item_Too_Late
(Rectype
, N
) then
6643 -- We know we have a first subtype, now possibly go to the anonymous
6644 -- base type to determine whether Rectype is a record extension.
6646 Recdef
:= Type_Definition
(Declaration_Node
(Base_Type
(Rectype
)));
6647 Is_Record_Extension
:=
6648 Nkind
(Recdef
) = N_Derived_Type_Definition
6649 and then Present
(Record_Extension_Part
(Recdef
));
6651 if Present
(Mod_Clause
(N
)) then
6653 Loc
: constant Source_Ptr
:= Sloc
(N
);
6654 M
: constant Node_Id
:= Mod_Clause
(N
);
6655 P
: constant List_Id
:= Pragmas_Before
(M
);
6659 pragma Warnings
(Off
, Mod_Val
);
6662 Check_Restriction
(No_Obsolescent_Features
, Mod_Clause
(N
));
6664 if Warn_On_Obsolescent_Feature
then
6666 ("?j?mod clause is an obsolescent feature (RM J.8)", N
);
6668 ("\?j?use alignment attribute definition clause instead", N
);
6675 -- In ASIS_Mode mode, expansion is disabled, but we must convert
6676 -- the Mod clause into an alignment clause anyway, so that the
6677 -- back end can compute and back-annotate properly the size and
6678 -- alignment of types that may include this record.
6680 -- This seems dubious, this destroys the source tree in a manner
6681 -- not detectable by ASIS ???
6683 if Operating_Mode
= Check_Semantics
and then ASIS_Mode
then
6685 Make_Attribute_Definition_Clause
(Loc
,
6686 Name
=> New_Occurrence_Of
(Base_Type
(Rectype
), Loc
),
6687 Chars
=> Name_Alignment
,
6688 Expression
=> Relocate_Node
(Expression
(M
)));
6690 Set_From_At_Mod
(AtM_Nod
);
6691 Insert_After
(N
, AtM_Nod
);
6692 Mod_Val
:= Get_Alignment_Value
(Expression
(AtM_Nod
));
6693 Set_Mod_Clause
(N
, Empty
);
6696 -- Get the alignment value to perform error checking
6698 Mod_Val
:= Get_Alignment_Value
(Expression
(M
));
6703 -- For untagged types, clear any existing component clauses for the
6704 -- type. If the type is derived, this is what allows us to override
6705 -- a rep clause for the parent. For type extensions, the representation
6706 -- of the inherited components is inherited, so we want to keep previous
6707 -- component clauses for completeness.
6709 if not Is_Tagged_Type
(Rectype
) then
6710 Comp
:= First_Component_Or_Discriminant
(Rectype
);
6711 while Present
(Comp
) loop
6712 Set_Component_Clause
(Comp
, Empty
);
6713 Next_Component_Or_Discriminant
(Comp
);
6717 -- All done if no component clauses
6719 CC
:= First
(Component_Clauses
(N
));
6725 -- A representation like this applies to the base type
6727 Set_Has_Record_Rep_Clause
(Base_Type
(Rectype
));
6728 Set_Has_Non_Standard_Rep
(Base_Type
(Rectype
));
6729 Set_Has_Specified_Layout
(Base_Type
(Rectype
));
6731 -- Process the component clauses
6733 while Present
(CC
) loop
6737 if Nkind
(CC
) = N_Pragma
then
6740 -- The only pragma of interest is Complete_Representation
6742 if Pragma_Name
(CC
) = Name_Complete_Representation
then
6746 -- Processing for real component clause
6749 Posit
:= Static_Integer
(Position
(CC
));
6750 Fbit
:= Static_Integer
(First_Bit
(CC
));
6751 Lbit
:= Static_Integer
(Last_Bit
(CC
));
6754 and then Fbit
/= No_Uint
6755 and then Lbit
/= No_Uint
6759 ("position cannot be negative", Position
(CC
));
6763 ("first bit cannot be negative", First_Bit
(CC
));
6765 -- The Last_Bit specified in a component clause must not be
6766 -- less than the First_Bit minus one (RM-13.5.1(10)).
6768 elsif Lbit
< Fbit
- 1 then
6770 ("last bit cannot be less than first bit minus one",
6773 -- Values look OK, so find the corresponding record component
6774 -- Even though the syntax allows an attribute reference for
6775 -- implementation-defined components, GNAT does not allow the
6776 -- tag to get an explicit position.
6778 elsif Nkind
(Component_Name
(CC
)) = N_Attribute_Reference
then
6779 if Attribute_Name
(Component_Name
(CC
)) = Name_Tag
then
6780 Error_Msg_N
("position of tag cannot be specified", CC
);
6782 Error_Msg_N
("illegal component name", CC
);
6786 Comp
:= First_Entity
(Rectype
);
6787 while Present
(Comp
) loop
6788 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
6794 -- Maybe component of base type that is absent from
6795 -- statically constrained first subtype.
6797 Comp
:= First_Entity
(Base_Type
(Rectype
));
6798 while Present
(Comp
) loop
6799 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
6806 ("component clause is for non-existent field", CC
);
6808 -- Ada 2012 (AI05-0026): Any name that denotes a
6809 -- discriminant of an object of an unchecked union type
6810 -- shall not occur within a record_representation_clause.
6812 -- The general restriction of using record rep clauses on
6813 -- Unchecked_Union types has now been lifted. Since it is
6814 -- possible to introduce a record rep clause which mentions
6815 -- the discriminant of an Unchecked_Union in non-Ada 2012
6816 -- code, this check is applied to all versions of the
6819 elsif Ekind
(Comp
) = E_Discriminant
6820 and then Is_Unchecked_Union
(Rectype
)
6823 ("cannot reference discriminant of unchecked union",
6824 Component_Name
(CC
));
6826 elsif Is_Record_Extension
and then Is_Inherited
(Comp
) then
6828 ("component clause not allowed for inherited "
6829 & "component&", CC
, Comp
);
6831 elsif Present
(Component_Clause
(Comp
)) then
6833 -- Diagnose duplicate rep clause, or check consistency
6834 -- if this is an inherited component. In a double fault,
6835 -- there may be a duplicate inconsistent clause for an
6836 -- inherited component.
6838 if Scope
(Original_Record_Component
(Comp
)) = Rectype
6839 or else Parent
(Component_Clause
(Comp
)) = N
6841 Error_Msg_Sloc
:= Sloc
(Component_Clause
(Comp
));
6842 Error_Msg_N
("component clause previously given#", CC
);
6846 Rep1
: constant Node_Id
:= Component_Clause
(Comp
);
6848 if Intval
(Position
(Rep1
)) /=
6849 Intval
(Position
(CC
))
6850 or else Intval
(First_Bit
(Rep1
)) /=
6851 Intval
(First_Bit
(CC
))
6852 or else Intval
(Last_Bit
(Rep1
)) /=
6853 Intval
(Last_Bit
(CC
))
6856 ("component clause inconsistent "
6857 & "with representation of ancestor", CC
);
6859 elsif Warn_On_Redundant_Constructs
then
6861 ("?r?redundant confirming component clause "
6862 & "for component!", CC
);
6867 -- Normal case where this is the first component clause we
6868 -- have seen for this entity, so set it up properly.
6871 -- Make reference for field in record rep clause and set
6872 -- appropriate entity field in the field identifier.
6875 (Comp
, Component_Name
(CC
), Set_Ref
=> False);
6876 Set_Entity
(Component_Name
(CC
), Comp
);
6878 -- Update Fbit and Lbit to the actual bit number
6880 Fbit
:= Fbit
+ UI_From_Int
(SSU
) * Posit
;
6881 Lbit
:= Lbit
+ UI_From_Int
(SSU
) * Posit
;
6883 if Has_Size_Clause
(Rectype
)
6884 and then RM_Size
(Rectype
) <= Lbit
6887 ("bit number out of range of specified size",
6890 Set_Component_Clause
(Comp
, CC
);
6891 Set_Component_Bit_Offset
(Comp
, Fbit
);
6892 Set_Esize
(Comp
, 1 + (Lbit
- Fbit
));
6893 Set_Normalized_First_Bit
(Comp
, Fbit
mod SSU
);
6894 Set_Normalized_Position
(Comp
, Fbit
/ SSU
);
6896 if Warn_On_Overridden_Size
6897 and then Has_Size_Clause
(Etype
(Comp
))
6898 and then RM_Size
(Etype
(Comp
)) /= Esize
(Comp
)
6901 ("?S?component size overrides size clause for&",
6902 Component_Name
(CC
), Etype
(Comp
));
6905 -- This information is also set in the corresponding
6906 -- component of the base type, found by accessing the
6907 -- Original_Record_Component link if it is present.
6909 Ocomp
:= Original_Record_Component
(Comp
);
6916 (Component_Name
(CC
),
6922 (Comp
, First_Node
(CC
), "component clause", Biased
);
6924 if Present
(Ocomp
) then
6925 Set_Component_Clause
(Ocomp
, CC
);
6926 Set_Component_Bit_Offset
(Ocomp
, Fbit
);
6927 Set_Normalized_First_Bit
(Ocomp
, Fbit
mod SSU
);
6928 Set_Normalized_Position
(Ocomp
, Fbit
/ SSU
);
6929 Set_Esize
(Ocomp
, 1 + (Lbit
- Fbit
));
6931 Set_Normalized_Position_Max
6932 (Ocomp
, Normalized_Position
(Ocomp
));
6934 -- Note: we don't use Set_Biased here, because we
6935 -- already gave a warning above if needed, and we
6936 -- would get a duplicate for the same name here.
6938 Set_Has_Biased_Representation
6939 (Ocomp
, Has_Biased_Representation
(Comp
));
6942 if Esize
(Comp
) < 0 then
6943 Error_Msg_N
("component size is negative", CC
);
6954 -- Check missing components if Complete_Representation pragma appeared
6956 if Present
(CR_Pragma
) then
6957 Comp
:= First_Component_Or_Discriminant
(Rectype
);
6958 while Present
(Comp
) loop
6959 if No
(Component_Clause
(Comp
)) then
6961 ("missing component clause for &", CR_Pragma
, Comp
);
6964 Next_Component_Or_Discriminant
(Comp
);
6967 -- Give missing components warning if required
6969 elsif Warn_On_Unrepped_Components
then
6971 Num_Repped_Components
: Nat
:= 0;
6972 Num_Unrepped_Components
: Nat
:= 0;
6975 -- First count number of repped and unrepped components
6977 Comp
:= First_Component_Or_Discriminant
(Rectype
);
6978 while Present
(Comp
) loop
6979 if Present
(Component_Clause
(Comp
)) then
6980 Num_Repped_Components
:= Num_Repped_Components
+ 1;
6982 Num_Unrepped_Components
:= Num_Unrepped_Components
+ 1;
6985 Next_Component_Or_Discriminant
(Comp
);
6988 -- We are only interested in the case where there is at least one
6989 -- unrepped component, and at least half the components have rep
6990 -- clauses. We figure that if less than half have them, then the
6991 -- partial rep clause is really intentional. If the component
6992 -- type has no underlying type set at this point (as for a generic
6993 -- formal type), we don't know enough to give a warning on the
6996 if Num_Unrepped_Components
> 0
6997 and then Num_Unrepped_Components
< Num_Repped_Components
6999 Comp
:= First_Component_Or_Discriminant
(Rectype
);
7000 while Present
(Comp
) loop
7001 if No
(Component_Clause
(Comp
))
7002 and then Comes_From_Source
(Comp
)
7003 and then Present
(Underlying_Type
(Etype
(Comp
)))
7004 and then (Is_Scalar_Type
(Underlying_Type
(Etype
(Comp
)))
7005 or else Size_Known_At_Compile_Time
7006 (Underlying_Type
(Etype
(Comp
))))
7007 and then not Has_Warnings_Off
(Rectype
)
7009 -- Ignore discriminant in unchecked union, since it is
7010 -- not there, and cannot have a component clause.
7012 and then (not Is_Unchecked_Union
(Rectype
)
7013 or else Ekind
(Comp
) /= E_Discriminant
)
7015 Error_Msg_Sloc
:= Sloc
(Comp
);
7017 ("?C?no component clause given for & declared #",
7021 Next_Component_Or_Discriminant
(Comp
);
7026 end Analyze_Record_Representation_Clause
;
7028 -------------------------------------
7029 -- Build_Discrete_Static_Predicate --
7030 -------------------------------------
7032 procedure Build_Discrete_Static_Predicate
7037 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
7039 Non_Static
: exception;
7040 -- Raised if something non-static is found
7042 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
7044 BLo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Btyp
));
7045 BHi
: constant Uint
:= Expr_Value
(Type_High_Bound
(Btyp
));
7046 -- Low bound and high bound value of base type of Typ
7050 -- Bounds for constructing the static predicate. We use the bound of the
7051 -- subtype if it is static, otherwise the corresponding base type bound.
7052 -- Note: a non-static subtype can have a static predicate.
7057 -- One entry in a Rlist value, a single REnt (range entry) value denotes
7058 -- one range from Lo to Hi. To represent a single value range Lo = Hi =
7061 type RList
is array (Nat
range <>) of REnt
;
7062 -- A list of ranges. The ranges are sorted in increasing order, and are
7063 -- disjoint (there is a gap of at least one value between each range in
7064 -- the table). A value is in the set of ranges in Rlist if it lies
7065 -- within one of these ranges.
7067 False_Range
: constant RList
:=
7068 RList
'(1 .. 0 => REnt'(No_Uint
, No_Uint
));
7069 -- An empty set of ranges represents a range list that can never be
7070 -- satisfied, since there are no ranges in which the value could lie,
7071 -- so it does not lie in any of them. False_Range is a canonical value
7072 -- for this empty set, but general processing should test for an Rlist
7073 -- with length zero (see Is_False predicate), since other null ranges
7074 -- may appear which must be treated as False.
7076 True_Range
: constant RList
:= RList
'(1 => REnt'(BLo
, BHi
));
7077 -- Range representing True, value must be in the base range
7079 function "and" (Left
: RList
; Right
: RList
) return RList
;
7080 -- And's together two range lists, returning a range list. This is a set
7081 -- intersection operation.
7083 function "or" (Left
: RList
; Right
: RList
) return RList
;
7084 -- Or's together two range lists, returning a range list. This is a set
7087 function "not" (Right
: RList
) return RList
;
7088 -- Returns complement of a given range list, i.e. a range list
7089 -- representing all the values in TLo .. THi that are not in the input
7092 function Build_Val
(V
: Uint
) return Node_Id
;
7093 -- Return an analyzed N_Identifier node referencing this value, suitable
7094 -- for use as an entry in the Static_Discrte_Predicate list. This node
7095 -- is typed with the base type.
7097 function Build_Range
(Lo
: Uint
; Hi
: Uint
) return Node_Id
;
7098 -- Return an analyzed N_Range node referencing this range, suitable for
7099 -- use as an entry in the Static_Discrete_Predicate list. This node is
7100 -- typed with the base type.
7102 function Get_RList
(Exp
: Node_Id
) return RList
;
7103 -- This is a recursive routine that converts the given expression into a
7104 -- list of ranges, suitable for use in building the static predicate.
7106 function Is_False
(R
: RList
) return Boolean;
7107 pragma Inline
(Is_False
);
7108 -- Returns True if the given range list is empty, and thus represents a
7109 -- False list of ranges that can never be satisfied.
7111 function Is_True
(R
: RList
) return Boolean;
7112 -- Returns True if R trivially represents the True predicate by having a
7113 -- single range from BLo to BHi.
7115 function Is_Type_Ref
(N
: Node_Id
) return Boolean;
7116 pragma Inline
(Is_Type_Ref
);
7117 -- Returns if True if N is a reference to the type for the predicate in
7118 -- the expression (i.e. if it is an identifier whose Chars field matches
7119 -- the Nam given in the call). N must not be parenthesized, if the type
7120 -- name appears in parens, this routine will return False.
7122 function Lo_Val
(N
: Node_Id
) return Uint
;
7123 -- Given an entry from a Static_Discrete_Predicate list that is either
7124 -- a static expression or static range, gets either the expression value
7125 -- or the low bound of the range.
7127 function Hi_Val
(N
: Node_Id
) return Uint
;
7128 -- Given an entry from a Static_Discrete_Predicate list that is either
7129 -- a static expression or static range, gets either the expression value
7130 -- or the high bound of the range.
7132 function Membership_Entry
(N
: Node_Id
) return RList
;
7133 -- Given a single membership entry (range, value, or subtype), returns
7134 -- the corresponding range list. Raises Static_Error if not static.
7136 function Membership_Entries
(N
: Node_Id
) return RList
;
7137 -- Given an element on an alternatives list of a membership operation,
7138 -- returns the range list corresponding to this entry and all following
7139 -- entries (i.e. returns the "or" of this list of values).
7141 function Stat_Pred
(Typ
: Entity_Id
) return RList
;
7142 -- Given a type, if it has a static predicate, then return the predicate
7143 -- as a range list, otherwise raise Non_Static.
7149 function "and" (Left
: RList
; Right
: RList
) return RList
is
7151 -- First range of result
7153 SLeft
: Nat
:= Left
'First;
7154 -- Start of rest of left entries
7156 SRight
: Nat
:= Right
'First;
7157 -- Start of rest of right entries
7160 -- If either range is True, return the other
7162 if Is_True
(Left
) then
7164 elsif Is_True
(Right
) then
7168 -- If either range is False, return False
7170 if Is_False
(Left
) or else Is_False
(Right
) then
7174 -- Loop to remove entries at start that are disjoint, and thus just
7175 -- get discarded from the result entirely.
7178 -- If no operands left in either operand, result is false
7180 if SLeft
> Left
'Last or else SRight
> Right
'Last then
7183 -- Discard first left operand entry if disjoint with right
7185 elsif Left
(SLeft
).Hi
< Right
(SRight
).Lo
then
7188 -- Discard first right operand entry if disjoint with left
7190 elsif Right
(SRight
).Hi
< Left
(SLeft
).Lo
then
7191 SRight
:= SRight
+ 1;
7193 -- Otherwise we have an overlapping entry
7200 -- Now we have two non-null operands, and first entries overlap. The
7201 -- first entry in the result will be the overlapping part of these
7204 FEnt
:= REnt
'(Lo => UI_Max (Left (SLeft).Lo, Right (SRight).Lo),
7205 Hi => UI_Min (Left (SLeft).Hi, Right (SRight).Hi));
7207 -- Now we can remove the entry that ended at a lower value, since its
7208 -- contribution is entirely contained in Fent.
7210 if Left (SLeft).Hi <= Right (SRight).Hi then
7213 SRight := SRight + 1;
7216 -- Compute result by concatenating this first entry with the "and" of
7217 -- the remaining parts of the left and right operands. Note that if
7218 -- either of these is empty, "and" will yield empty, so that we will
7219 -- end up with just Fent, which is what we want in that case.
7222 FEnt & (Left (SLeft .. Left'Last) and Right (SRight .. Right'Last));
7229 function "not" (Right : RList) return RList is
7231 -- Return True if False range
7233 if Is_False (Right) then
7237 -- Return False if True range
7239 if Is_True (Right) then
7243 -- Here if not trivial case
7246 Result : RList (1 .. Right'Length + 1);
7247 -- May need one more entry for gap at beginning and end
7250 -- Number of entries stored in Result
7255 if Right (Right'First).Lo > TLo then
7257 Result (Count) := REnt'(TLo
, Right
(Right
'First).Lo
- 1);
7260 -- Gaps between ranges
7262 for J
in Right
'First .. Right
'Last - 1 loop
7264 Result
(Count
) := REnt
'(Right (J).Hi + 1, Right (J + 1).Lo - 1);
7269 if Right (Right'Last).Hi < THi then
7271 Result (Count) := REnt'(Right
(Right
'Last).Hi
+ 1, THi
);
7274 return Result
(1 .. Count
);
7282 function "or" (Left
: RList
; Right
: RList
) return RList
is
7284 -- First range of result
7286 SLeft
: Nat
:= Left
'First;
7287 -- Start of rest of left entries
7289 SRight
: Nat
:= Right
'First;
7290 -- Start of rest of right entries
7293 -- If either range is True, return True
7295 if Is_True
(Left
) or else Is_True
(Right
) then
7299 -- If either range is False (empty), return the other
7301 if Is_False
(Left
) then
7303 elsif Is_False
(Right
) then
7307 -- Initialize result first entry from left or right operand depending
7308 -- on which starts with the lower range.
7310 if Left
(SLeft
).Lo
< Right
(SRight
).Lo
then
7311 FEnt
:= Left
(SLeft
);
7314 FEnt
:= Right
(SRight
);
7315 SRight
:= SRight
+ 1;
7318 -- This loop eats ranges from left and right operands that are
7319 -- contiguous with the first range we are gathering.
7322 -- Eat first entry in left operand if contiguous or overlapped by
7323 -- gathered first operand of result.
7325 if SLeft
<= Left
'Last
7326 and then Left
(SLeft
).Lo
<= FEnt
.Hi
+ 1
7328 FEnt
.Hi
:= UI_Max
(FEnt
.Hi
, Left
(SLeft
).Hi
);
7331 -- Eat first entry in right operand if contiguous or overlapped by
7332 -- gathered right operand of result.
7334 elsif SRight
<= Right
'Last
7335 and then Right
(SRight
).Lo
<= FEnt
.Hi
+ 1
7337 FEnt
.Hi
:= UI_Max
(FEnt
.Hi
, Right
(SRight
).Hi
);
7338 SRight
:= SRight
+ 1;
7340 -- All done if no more entries to eat
7347 -- Obtain result as the first entry we just computed, concatenated
7348 -- to the "or" of the remaining results (if one operand is empty,
7349 -- this will just concatenate with the other
7352 FEnt
& (Left
(SLeft
.. Left
'Last) or Right
(SRight
.. Right
'Last));
7359 function Build_Range
(Lo
: Uint
; Hi
: Uint
) return Node_Id
is
7364 Low_Bound
=> Build_Val
(Lo
),
7365 High_Bound
=> Build_Val
(Hi
));
7366 Set_Etype
(Result
, Btyp
);
7367 Set_Analyzed
(Result
);
7375 function Build_Val
(V
: Uint
) return Node_Id
is
7379 if Is_Enumeration_Type
(Typ
) then
7380 Result
:= Get_Enum_Lit_From_Pos
(Typ
, V
, Loc
);
7382 Result
:= Make_Integer_Literal
(Loc
, V
);
7385 Set_Etype
(Result
, Btyp
);
7386 Set_Is_Static_Expression
(Result
);
7387 Set_Analyzed
(Result
);
7395 function Get_RList
(Exp
: Node_Id
) return RList
is
7400 -- Static expression can only be true or false
7402 if Is_OK_Static_Expression
(Exp
) then
7403 if Expr_Value
(Exp
) = 0 then
7410 -- Otherwise test node type
7418 when N_Op_And | N_And_Then
=>
7419 return Get_RList
(Left_Opnd
(Exp
))
7421 Get_RList
(Right_Opnd
(Exp
));
7425 when N_Op_Or | N_Or_Else
=>
7426 return Get_RList
(Left_Opnd
(Exp
))
7428 Get_RList
(Right_Opnd
(Exp
));
7433 return not Get_RList
(Right_Opnd
(Exp
));
7435 -- Comparisons of type with static value
7437 when N_Op_Compare
=>
7439 -- Type is left operand
7441 if Is_Type_Ref
(Left_Opnd
(Exp
))
7442 and then Is_OK_Static_Expression
(Right_Opnd
(Exp
))
7444 Val
:= Expr_Value
(Right_Opnd
(Exp
));
7446 -- Typ is right operand
7448 elsif Is_Type_Ref
(Right_Opnd
(Exp
))
7449 and then Is_OK_Static_Expression
(Left_Opnd
(Exp
))
7451 Val
:= Expr_Value
(Left_Opnd
(Exp
));
7453 -- Invert sense of comparison
7456 when N_Op_Gt
=> Op
:= N_Op_Lt
;
7457 when N_Op_Lt
=> Op
:= N_Op_Gt
;
7458 when N_Op_Ge
=> Op
:= N_Op_Le
;
7459 when N_Op_Le
=> Op
:= N_Op_Ge
;
7460 when others => null;
7463 -- Other cases are non-static
7469 -- Construct range according to comparison operation
7473 return RList
'(1 => REnt'(Val
, Val
));
7476 return RList
'(1 => REnt'(Val
, BHi
));
7479 return RList
'(1 => REnt'(Val
+ 1, BHi
));
7482 return RList
'(1 => REnt'(BLo
, Val
));
7485 return RList
'(1 => REnt'(BLo
, Val
- 1));
7488 return RList
'(REnt'(BLo
, Val
- 1), REnt
'(Val + 1, BHi));
7491 raise Program_Error;
7497 if not Is_Type_Ref (Left_Opnd (Exp)) then
7501 if Present (Right_Opnd (Exp)) then
7502 return Membership_Entry (Right_Opnd (Exp));
7504 return Membership_Entries (First (Alternatives (Exp)));
7507 -- Negative membership (NOT IN)
7510 if not Is_Type_Ref (Left_Opnd (Exp)) then
7514 if Present (Right_Opnd (Exp)) then
7515 return not Membership_Entry (Right_Opnd (Exp));
7517 return not Membership_Entries (First (Alternatives (Exp)));
7520 -- Function call, may be call to static predicate
7522 when N_Function_Call =>
7523 if Is_Entity_Name (Name (Exp)) then
7525 Ent : constant Entity_Id := Entity (Name (Exp));
7527 if Is_Predicate_Function (Ent)
7529 Is_Predicate_Function_M (Ent)
7531 return Stat_Pred (Etype (First_Formal (Ent)));
7536 -- Other function call cases are non-static
7540 -- Qualified expression, dig out the expression
7542 when N_Qualified_Expression =>
7543 return Get_RList (Expression (Exp));
7545 when N_Case_Expression =>
7552 if not Is_Entity_Name (Expression (Expr))
7553 or else Etype (Expression (Expr)) /= Typ
7556 ("expression must denaote subtype", Expression (Expr));
7560 -- Collect discrete choices in all True alternatives
7562 Choices := New_List;
7563 Alt := First (Alternatives (Exp));
7564 while Present (Alt) loop
7565 Dep := Expression (Alt);
7567 if not Is_OK_Static_Expression (Dep) then
7570 elsif Is_True (Expr_Value (Dep)) then
7571 Append_List_To (Choices,
7572 New_Copy_List (Discrete_Choices (Alt)));
7578 return Membership_Entries (First (Choices));
7581 -- Expression with actions: if no actions, dig out expression
7583 when N_Expression_With_Actions =>
7584 if Is_Empty_List (Actions (Exp)) then
7585 return Get_RList (Expression (Exp));
7593 return (Get_RList (Left_Opnd (Exp))
7594 and not Get_RList (Right_Opnd (Exp)))
7595 or (Get_RList (Right_Opnd (Exp))
7596 and not Get_RList (Left_Opnd (Exp)));
7598 -- Any other node type is non-static
7609 function Hi_Val (N : Node_Id) return Uint is
7611 if Is_OK_Static_Expression (N) then
7612 return Expr_Value (N);
7614 pragma Assert (Nkind (N) = N_Range);
7615 return Expr_Value (High_Bound (N));
7623 function Is_False (R : RList) return Boolean is
7625 return R'Length = 0;
7632 function Is_True (R : RList) return Boolean is
7635 and then R (R'First).Lo = BLo
7636 and then R (R'First).Hi = BHi;
7643 function Is_Type_Ref (N : Node_Id) return Boolean is
7645 return Nkind (N) = N_Identifier
7646 and then Chars (N) = Nam
7647 and then Paren_Count (N) = 0;
7654 function Lo_Val (N : Node_Id) return Uint is
7656 if Is_OK_Static_Expression (N) then
7657 return Expr_Value (N);
7659 pragma Assert (Nkind (N) = N_Range);
7660 return Expr_Value (Low_Bound (N));
7664 ------------------------
7665 -- Membership_Entries --
7666 ------------------------
7668 function Membership_Entries (N : Node_Id) return RList is
7670 if No (Next (N)) then
7671 return Membership_Entry (N);
7673 return Membership_Entry (N) or Membership_Entries (Next (N));
7675 end Membership_Entries;
7677 ----------------------
7678 -- Membership_Entry --
7679 ----------------------
7681 function Membership_Entry (N : Node_Id) return RList is
7689 if Nkind (N) = N_Range then
7690 if not Is_OK_Static_Expression (Low_Bound (N))
7692 not Is_OK_Static_Expression (High_Bound (N))
7696 SLo := Expr_Value (Low_Bound (N));
7697 SHi := Expr_Value (High_Bound (N));
7698 return RList'(1 => REnt
'(SLo, SHi));
7701 -- Static expression case
7703 elsif Is_OK_Static_Expression (N) then
7704 Val := Expr_Value (N);
7705 return RList'(1 => REnt
'(Val, Val));
7707 -- Identifier (other than static expression) case
7709 else pragma Assert (Nkind (N) = N_Identifier);
7713 if Is_Type (Entity (N)) then
7715 -- If type has predicates, process them
7717 if Has_Predicates (Entity (N)) then
7718 return Stat_Pred (Entity (N));
7720 -- For static subtype without predicates, get range
7722 elsif Is_OK_Static_Subtype (Entity (N)) then
7723 SLo := Expr_Value (Type_Low_Bound (Entity (N)));
7724 SHi := Expr_Value (Type_High_Bound (Entity (N)));
7725 return RList'(1 => REnt
'(SLo, SHi));
7727 -- Any other type makes us non-static
7733 -- Any other kind of identifier in predicate (e.g. a non-static
7734 -- expression value) means this is not a static predicate.
7740 end Membership_Entry;
7746 function Stat_Pred (Typ : Entity_Id) return RList is
7748 -- Not static if type does not have static predicates
7750 if not Has_Static_Predicate (Typ) then
7754 -- Otherwise we convert the predicate list to a range list
7757 Spred : constant List_Id := Static_Discrete_Predicate (Typ);
7758 Result : RList (1 .. List_Length (Spred));
7762 P := First (Static_Discrete_Predicate (Typ));
7763 for J in Result'Range loop
7764 Result (J) := REnt'(Lo_Val
(P
), Hi_Val
(P
));
7772 -- Start of processing for Build_Discrete_Static_Predicate
7775 -- Establish bounds for the predicate
7777 if Compile_Time_Known_Value
(Type_Low_Bound
(Typ
)) then
7778 TLo
:= Expr_Value
(Type_Low_Bound
(Typ
));
7783 if Compile_Time_Known_Value
(Type_High_Bound
(Typ
)) then
7784 THi
:= Expr_Value
(Type_High_Bound
(Typ
));
7789 -- Analyze the expression to see if it is a static predicate
7792 Ranges
: constant RList
:= Get_RList
(Expr
);
7793 -- Range list from expression if it is static
7798 -- Convert range list into a form for the static predicate. In the
7799 -- Ranges array, we just have raw ranges, these must be converted
7800 -- to properly typed and analyzed static expressions or range nodes.
7802 -- Note: here we limit ranges to the ranges of the subtype, so that
7803 -- a predicate is always false for values outside the subtype. That
7804 -- seems fine, such values are invalid anyway, and considering them
7805 -- to fail the predicate seems allowed and friendly, and furthermore
7806 -- simplifies processing for case statements and loops.
7810 for J
in Ranges
'Range loop
7812 Lo
: Uint
:= Ranges
(J
).Lo
;
7813 Hi
: Uint
:= Ranges
(J
).Hi
;
7816 -- Ignore completely out of range entry
7818 if Hi
< TLo
or else Lo
> THi
then
7821 -- Otherwise process entry
7824 -- Adjust out of range value to subtype range
7834 -- Convert range into required form
7836 Append_To
(Plist
, Build_Range
(Lo
, Hi
));
7841 -- Processing was successful and all entries were static, so now we
7842 -- can store the result as the predicate list.
7844 Set_Static_Discrete_Predicate
(Typ
, Plist
);
7846 -- The processing for static predicates put the expression into
7847 -- canonical form as a series of ranges. It also eliminated
7848 -- duplicates and collapsed and combined ranges. We might as well
7849 -- replace the alternatives list of the right operand of the
7850 -- membership test with the static predicate list, which will
7851 -- usually be more efficient.
7854 New_Alts
: constant List_Id
:= New_List
;
7859 Old_Node
:= First
(Plist
);
7860 while Present
(Old_Node
) loop
7861 New_Node
:= New_Copy
(Old_Node
);
7863 if Nkind
(New_Node
) = N_Range
then
7864 Set_Low_Bound
(New_Node
, New_Copy
(Low_Bound
(Old_Node
)));
7865 Set_High_Bound
(New_Node
, New_Copy
(High_Bound
(Old_Node
)));
7868 Append_To
(New_Alts
, New_Node
);
7872 -- If empty list, replace by False
7874 if Is_Empty_List
(New_Alts
) then
7875 Rewrite
(Expr
, New_Occurrence_Of
(Standard_False
, Loc
));
7877 -- Else replace by set membership test
7882 Left_Opnd
=> Make_Identifier
(Loc
, Nam
),
7883 Right_Opnd
=> Empty
,
7884 Alternatives
=> New_Alts
));
7886 -- Resolve new expression in function context
7888 Install_Formals
(Predicate_Function
(Typ
));
7889 Push_Scope
(Predicate_Function
(Typ
));
7890 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
7896 -- If non-static, return doing nothing
7901 end Build_Discrete_Static_Predicate
;
7903 --------------------------------
7904 -- Build_Export_Import_Pragma --
7905 --------------------------------
7907 function Build_Export_Import_Pragma
7909 Id
: Entity_Id
) return Node_Id
7911 Asp_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Asp
);
7912 Expr
: constant Node_Id
:= Expression
(Asp
);
7913 Loc
: constant Source_Ptr
:= Sloc
(Asp
);
7924 Create_Pragma
: Boolean := False;
7925 -- This flag is set when the aspect form is such that it warrants the
7926 -- creation of a corresponding pragma.
7929 if Present
(Expr
) then
7930 if Error_Posted
(Expr
) then
7933 elsif Is_True
(Expr_Value
(Expr
)) then
7934 Create_Pragma
:= True;
7937 -- Otherwise the aspect defaults to True
7940 Create_Pragma
:= True;
7943 -- Nothing to do when the expression is False or is erroneous
7945 if not Create_Pragma
then
7949 -- Obtain all interfacing aspects that apply to the related entity
7951 Get_Interfacing_Aspects
7955 Expo_Asp
=> Dummy_1
,
7961 -- Handle the convention argument
7963 if Present
(Conv
) then
7964 Conv_Arg
:= New_Copy_Tree
(Expression
(Conv
));
7966 -- Assume convention "Ada' when aspect Convention is missing
7969 Conv_Arg
:= Make_Identifier
(Loc
, Name_Ada
);
7973 Make_Pragma_Argument_Association
(Loc
,
7974 Chars
=> Name_Convention
,
7975 Expression
=> Conv_Arg
));
7977 -- Handle the entity argument
7980 Make_Pragma_Argument_Association
(Loc
,
7981 Chars
=> Name_Entity
,
7982 Expression
=> New_Occurrence_Of
(Id
, Loc
)));
7984 -- Handle the External_Name argument
7986 if Present
(EN
) then
7988 Make_Pragma_Argument_Association
(Loc
,
7989 Chars
=> Name_External_Name
,
7990 Expression
=> New_Copy_Tree
(Expression
(EN
))));
7993 -- Handle the Link_Name argument
7995 if Present
(LN
) then
7997 Make_Pragma_Argument_Association
(Loc
,
7998 Chars
=> Name_Link_Name
,
7999 Expression
=> New_Copy_Tree
(Expression
(LN
))));
8003 -- pragma Export/Import
8004 -- (Convention => <Conv>/Ada,
8006 -- [External_Name => <EN>,]
8007 -- [Link_Name => <LN>]);
8011 Pragma_Identifier
=>
8012 Make_Identifier
(Loc
, Chars
(Identifier
(Asp
))),
8013 Pragma_Argument_Associations
=> Args
);
8015 -- Decorate the relevant aspect and the pragma
8017 Set_Aspect_Rep_Item
(Asp
, Prag
);
8019 Set_Corresponding_Aspect
(Prag
, Asp
);
8020 Set_From_Aspect_Specification
(Prag
);
8021 Set_Parent
(Prag
, Asp
);
8023 if Asp_Id
= Aspect_Import
and then Is_Subprogram
(Id
) then
8024 Set_Import_Pragma
(Id
, Prag
);
8028 end Build_Export_Import_Pragma
;
8030 -------------------------------------------
8031 -- Build_Invariant_Procedure_Declaration --
8032 -------------------------------------------
8034 function Build_Invariant_Procedure_Declaration
8035 (Typ
: Entity_Id
) return Node_Id
8037 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
8042 Save_Ghost_Mode
: constant Ghost_Mode_Type
:= Ghost_Mode
;
8045 -- Check for duplicate definitions
8047 if Has_Invariants
(Typ
) and then Present
(Invariant_Procedure
(Typ
)) then
8051 -- The related type may be subject to pragma Ghost. Set the mode now to
8052 -- ensure that the invariant procedure is properly marked as Ghost.
8054 Set_Ghost_Mode_From_Entity
(Typ
);
8057 Make_Defining_Identifier
(Loc
,
8058 Chars
=> New_External_Name
(Chars
(Typ
), "Invariant"));
8059 Set_Has_Invariants
(Typ
);
8060 Set_Ekind
(SId
, E_Procedure
);
8061 Set_Etype
(SId
, Standard_Void_Type
);
8062 Set_Is_Invariant_Procedure
(SId
);
8063 Set_Invariant_Procedure
(Typ
, SId
);
8065 -- Source Coverage Obligations might be attached to the invariant
8066 -- expression this procedure evaluates, and we need debug info to be
8067 -- able to assess the coverage achieved by evaluations.
8069 if Opt
.Generate_SCO
then
8070 Set_Needs_Debug_Info
(SId
);
8073 -- Mark the invariant procedure explicitly as Ghost because it does not
8074 -- come from source.
8076 if Ghost_Mode
> None
then
8077 Set_Is_Ghost_Entity
(SId
);
8080 Obj_Id
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('I'));
8081 Set_Etype
(Obj_Id
, Typ
);
8084 Make_Subprogram_Declaration
(Loc
,
8085 Make_Procedure_Specification
(Loc
,
8086 Defining_Unit_Name
=> SId
,
8087 Parameter_Specifications
=> New_List
(
8088 Make_Parameter_Specification
(Loc
,
8089 Defining_Identifier
=> Obj_Id
,
8090 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)))));
8092 Ghost_Mode
:= Save_Ghost_Mode
;
8095 end Build_Invariant_Procedure_Declaration
;
8097 -------------------------------
8098 -- Build_Invariant_Procedure --
8099 -------------------------------
8101 -- The procedure that is constructed here has the form
8103 -- procedure typInvariant (Ixxx : typ) is
8105 -- pragma Check (Invariant, exp, "failed invariant from xxx");
8106 -- pragma Check (Invariant, exp, "failed invariant from xxx");
8108 -- pragma Check (Invariant, exp, "failed inherited invariant from xxx");
8110 -- end typInvariant;
8112 procedure Build_Invariant_Procedure
(Typ
: Entity_Id
; N
: Node_Id
) is
8113 procedure Add_Invariants
8116 Stmts
: in out List_Id
;
8118 -- Appends statements to Stmts for any invariants in the rep item chain
8119 -- of the given type. If Inherit is False, then we only process entries
8120 -- on the chain for the type Typ. If Inherit is True, then we ignore any
8121 -- Invariant aspects, but we process all Invariant'Class aspects, adding
8122 -- "inherited" to the exception message and generating an informational
8123 -- message about the inheritance of an invariant.
8125 --------------------
8126 -- Add_Invariants --
8127 --------------------
8129 procedure Add_Invariants
8132 Stmts
: in out List_Id
;
8135 procedure Add_Invariant
(Prag
: Node_Id
);
8136 -- Create a runtime check to verify the exression of invariant pragma
8137 -- Prag. All generated code is added to list Stmts.
8143 procedure Add_Invariant
(Prag
: Node_Id
) is
8144 procedure Replace_Type_Reference
(N
: Node_Id
);
8145 -- Replace a single occurrence N of the subtype name with a
8146 -- reference to the formal of the predicate function. N can be an
8147 -- identifier referencing the subtype, or a selected component,
8148 -- representing an appropriately qualified occurrence of the
8151 procedure Replace_Type_References
is
8152 new Replace_Type_References_Generic
(Replace_Type_Reference
);
8153 -- Traverse an expression replacing all occurrences of the subtype
8154 -- name with appropriate references to the formal of the predicate
8155 -- function. Note that we must ensure that the type and entity
8156 -- information is properly set in the replacement node, since we
8157 -- will do a Preanalyze call of this expression without proper
8158 -- visibility of the procedure argument.
8160 ----------------------------
8161 -- Replace_Type_Reference --
8162 ----------------------------
8164 -- Note: See comments in Add_Predicates.Replace_Type_Reference
8165 -- regarding handling of Sloc and Comes_From_Source.
8167 procedure Replace_Type_Reference
(N
: Node_Id
) is
8168 Nloc
: constant Source_Ptr
:= Sloc
(N
);
8171 -- Add semantic information to node to be rewritten, for ASIS
8172 -- navigation needs.
8174 if Nkind
(N
) = N_Identifier
then
8178 elsif Nkind
(N
) = N_Selected_Component
then
8179 Analyze
(Prefix
(N
));
8180 Set_Entity
(Selector_Name
(N
), T
);
8181 Set_Etype
(Selector_Name
(N
), T
);
8184 -- Invariant'Class, replace with T'Class (obj)
8186 if Class_Present
(Prag
) then
8188 -- In ASIS mode, an inherited item is already analyzed,
8189 -- and the replacement has been done, so do not repeat
8190 -- the transformation to prevent a malformed tree.
8193 and then Nkind
(Parent
(N
)) = N_Attribute_Reference
8194 and then Attribute_Name
(Parent
(N
)) = Name_Class
8200 Make_Type_Conversion
(Nloc
,
8202 Make_Attribute_Reference
(Nloc
,
8203 Prefix
=> New_Occurrence_Of
(T
, Nloc
),
8204 Attribute_Name
=> Name_Class
),
8206 Make_Identifier
(Nloc
, Chars
(Obj_Id
))));
8208 Set_Entity
(Expression
(N
), Obj_Id
);
8209 Set_Etype
(Expression
(N
), Typ
);
8212 -- Invariant, replace with obj
8215 Rewrite
(N
, Make_Identifier
(Nloc
, Chars
(Obj_Id
)));
8216 Set_Entity
(N
, Obj_Id
);
8220 Set_Comes_From_Source
(N
, True);
8221 end Replace_Type_Reference
;
8225 Asp
: constant Node_Id
:= Corresponding_Aspect
(Prag
);
8226 Nam
: constant Name_Id
:= Original_Aspect_Pragma_Name
(Prag
);
8227 Ploc
: constant Source_Ptr
:= Sloc
(Prag
);
8235 -- Start of processing for Add_Invariant
8238 -- Extract the arguments of the invariant pragma
8240 Arg1
:= First
(Pragma_Argument_Associations
(Prag
));
8241 Arg2
:= Next
(Arg1
);
8242 Arg3
:= Next
(Arg2
);
8244 Arg1
:= Get_Pragma_Arg
(Arg1
);
8245 Arg2
:= Get_Pragma_Arg
(Arg2
);
8247 -- The caller requests processing of all Invariant'Class pragmas,
8248 -- but the current pragma does not fall in this category. Return
8249 -- as there is nothing left to do.
8252 if not Class_Present
(Prag
) then
8256 -- Otherwise the pragma must apply to the current type
8258 elsif Entity
(Arg1
) /= T
then
8262 Expr
:= New_Copy_Tree
(Arg2
);
8264 -- Replace all occurrences of the type's name with references to
8265 -- the formal parameter of the invariant procedure.
8267 Replace_Type_References
(Expr
, T
);
8269 -- If the invariant pragma comes from an aspect, replace the saved
8270 -- expression because we need the subtype references replaced for
8271 -- the calls to Preanalyze_Spec_Expression in Check_Aspect_At_xxx
8272 -- routines. This is not done for interited class-wide invariants
8273 -- because the original pragma of the parent type must remain
8276 if not Inherit
and then Present
(Asp
) then
8277 Set_Entity
(Identifier
(Asp
), New_Copy_Tree
(Expr
));
8280 -- Preanalyze the invariant expression to capture the visibility
8281 -- of the proper package part. In general the expression is not
8282 -- fully analyzed until the body of the invariant procedure is
8283 -- analyzed at the end of the private part, but that yields the
8284 -- wrong visibility.
8286 -- Historical note: we used to set N as the parent, but a package
8287 -- specification as the parent of an expression is bizarre.
8289 Set_Parent
(Expr
, Parent
(Arg2
));
8290 Preanalyze_Assert_Expression
(Expr
, Any_Boolean
);
8292 -- Both modifications performed below are not done for inherited
8293 -- class-wide invariants because the origial aspect/pragma of the
8294 -- parent type must remain unchanged.
8298 -- A class-wide invariant may be inherited in a separate unit,
8299 -- where the corresponding expression cannot be resolved by
8300 -- visibility, because it refers to a local function. Propagate
8301 -- semantic information to the original representation item, to
8302 -- be used when an invariant procedure for a derived type is
8305 -- ??? Unclear how to handle class-wide invariants that are not
8308 if Class_Present
(Prag
)
8309 and then Nkind
(Expr
) = N_Function_Call
8310 and then Nkind
(Arg2
) = N_Indexed_Component
8313 Make_Function_Call
(Ploc
,
8315 New_Occurrence_Of
(Entity
(Name
(Expr
)), Ploc
),
8316 Parameter_Associations
=> Expressions
(Arg2
)));
8319 -- In ASIS mode, even if assertions are not enabled, we must
8320 -- analyze the original expression in the aspect specification
8321 -- because it is part of the original tree.
8323 if ASIS_Mode
and then Present
(Asp
) then
8325 Asp_Expr
: constant Node_Id
:= Expression
(Asp
);
8328 Replace_Type_References
(Asp_Expr
, T
);
8329 Preanalyze_Assert_Expression
(Asp_Expr
, Any_Boolean
);
8334 -- An ignored invariant must not generate a runtime check. Add a
8335 -- null statement to ensure that the invariant procedure does get
8336 -- a completing body.
8339 Stmts
:= Empty_List
;
8342 if Is_Ignored
(Prag
) then
8343 Append_To
(Stmts
, Make_Null_Statement
(Ploc
));
8345 -- Otherwise the invariant is checked. Build a Check pragma to
8346 -- verify the expression at runtime.
8350 Make_Pragma_Argument_Association
(Ploc
,
8351 Expression
=> Make_Identifier
(Ploc
, Nam
)),
8352 Make_Pragma_Argument_Association
(Ploc
,
8353 Expression
=> Expr
));
8355 -- Handle the String argument (if any)
8357 if Present
(Arg3
) then
8358 Str
:= Strval
(Get_Pragma_Arg
(Arg3
));
8360 -- When inheriting an invariant, modify the message from
8361 -- "failed invariant" to "failed inherited invariant".
8364 String_To_Name_Buffer
(Str
);
8366 if Name_Buffer
(1 .. 16) = "failed invariant" then
8367 Insert_Str_In_Name_Buffer
("inherited ", 8);
8368 Str
:= String_From_Name_Buffer
;
8373 Make_Pragma_Argument_Association
(Ploc
,
8374 Expression
=> Make_String_Literal
(Ploc
, Str
)));
8378 -- pragma Check (Nam, Expr, Str);
8382 Pragma_Identifier
=>
8383 Make_Identifier
(Ploc
, Name_Check
),
8384 Pragma_Argument_Associations
=> Assoc
));
8387 -- Output an info message when inheriting an invariant and the
8388 -- listing option is enabled.
8390 if Inherit
and Opt
.List_Inherited_Aspects
then
8391 Error_Msg_Sloc
:= Sloc
(Prag
);
8393 ("info: & inherits `Invariant''Class` aspect from #?L?", Typ
);
8401 -- Start of processing for Add_Invariants
8404 Ritem
:= First_Rep_Item
(T
);
8405 while Present
(Ritem
) loop
8406 if Nkind
(Ritem
) = N_Pragma
8407 and then Pragma_Name
(Ritem
) = Name_Invariant
8409 Add_Invariant
(Ritem
);
8412 Next_Rep_Item
(Ritem
);
8418 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
8419 Priv_Decls
: constant List_Id
:= Private_Declarations
(N
);
8420 Vis_Decls
: constant List_Id
:= Visible_Declarations
(N
);
8422 Save_Ghost_Mode
: constant Ghost_Mode_Type
:= Ghost_Mode
;
8431 -- The entity of the formal for the procedure
8433 -- Start of processing for Build_Invariant_Procedure
8436 -- The related type may be subject to pragma Ghost. Set the mode now to
8437 -- ensure that the invariant procedure is properly marked as Ghost.
8439 Set_Ghost_Mode_From_Entity
(Typ
);
8446 -- If the aspect specification exists for some view of the type, the
8447 -- declaration for the procedure has been created.
8449 if Has_Invariants
(Typ
) then
8450 SId
:= Invariant_Procedure
(Typ
);
8453 -- If the body is already present, nothing to do. This will occur when
8454 -- the type is already frozen, which is the case when the invariant
8455 -- appears in a private part, and the freezing takes place before the
8456 -- final pass over full declarations.
8458 -- See Exp_Ch3.Insert_Component_Invariant_Checks for details.
8460 if Present
(SId
) then
8461 PDecl
:= Unit_Declaration_Node
(SId
);
8464 and then Nkind
(PDecl
) = N_Subprogram_Declaration
8465 and then Present
(Corresponding_Body
(PDecl
))
8467 Ghost_Mode
:= Save_Ghost_Mode
;
8472 PDecl
:= Build_Invariant_Procedure_Declaration
(Typ
);
8475 -- Recover formal of procedure, for use in the calls to invariant
8476 -- functions (including inherited ones).
8480 (First
(Parameter_Specifications
(Specification
(PDecl
))));
8482 -- Add invariants for the current type
8490 -- Add invariants for parent types
8493 Current_Typ
: Entity_Id
;
8494 Parent_Typ
: Entity_Id
;
8499 Parent_Typ
:= Etype
(Current_Typ
);
8501 if Is_Private_Type
(Parent_Typ
)
8502 and then Present
(Full_View
(Base_Type
(Parent_Typ
)))
8504 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
8507 exit when Parent_Typ
= Current_Typ
;
8509 Current_Typ
:= Parent_Typ
;
8518 -- Add invariants of progenitors
8520 if Is_Tagged_Type
(Typ
) and then not Is_Interface
(Typ
) then
8522 Ifaces_List
: Elist_Id
;
8527 Collect_Interfaces
(Typ
, Ifaces_List
);
8529 AI
:= First_Elmt
(Ifaces_List
);
8530 while Present
(AI
) loop
8533 if not Is_Ancestor
(Iface
, Typ
, Use_Full_View
=> True) then
8546 -- Build the procedure if we generated at least one Check pragma
8548 if Stmts
/= No_List
then
8549 Spec
:= Copy_Separate_Tree
(Specification
(PDecl
));
8552 Make_Subprogram_Body
(Loc
,
8553 Specification
=> Spec
,
8554 Declarations
=> Empty_List
,
8555 Handled_Statement_Sequence
=>
8556 Make_Handled_Sequence_Of_Statements
(Loc
,
8557 Statements
=> Stmts
));
8559 -- The processing of an invariant pragma immediately generates the
8560 -- invariant procedure spec, inserts it into the tree, and analyzes
8561 -- it. If the spec has not been analyzed, then the invariant pragma
8562 -- is being inherited and requires manual insertion and analysis.
8564 if not Analyzed
(PDecl
) then
8565 Append_To
(Vis_Decls
, PDecl
);
8569 -- The invariant procedure body is inserted at the end of the private
8572 if Present
(Priv_Decls
) then
8573 Append_To
(Priv_Decls
, PBody
);
8575 -- If the invariant appears on the full view of a private type,
8576 -- then the analysis of the private part is already completed.
8577 -- Manually analyze the new body in this case, otherwise wait
8578 -- for the analysis of the private declarations to process the
8581 if In_Private_Part
(Current_Scope
) then
8585 -- Otherwise there are no private declarations. This is either an
8586 -- error or the related type is a private extension, in which case
8587 -- it does not need a completion in a private part. Insert the body
8588 -- at the end of the visible declarations and analyze immediately
8589 -- because the related type is about to be frozen.
8592 Append_To
(Vis_Decls
, PBody
);
8597 Ghost_Mode
:= Save_Ghost_Mode
;
8598 end Build_Invariant_Procedure
;
8600 -------------------------------
8601 -- Build_Predicate_Functions --
8602 -------------------------------
8604 -- The procedures that are constructed here have the form:
8606 -- function typPredicate (Ixxx : typ) return Boolean is
8609 -- typ1Predicate (typ1 (Ixxx))
8610 -- and then typ2Predicate (typ2 (Ixxx))
8612 -- exp1 and then exp2 and then ...
8613 -- end typPredicate;
8615 -- Here exp1, and exp2 are expressions from Predicate pragmas. Note that
8616 -- this is the point at which these expressions get analyzed, providing the
8617 -- required delay, and typ1, typ2, are entities from which predicates are
8618 -- inherited. Note that we do NOT generate Check pragmas, that's because we
8619 -- use this function even if checks are off, e.g. for membership tests.
8621 -- Note that the inherited predicates are evaluated first, as required by
8624 -- Note that Sem_Eval.Real_Or_String_Static_Predicate_Matches depends on
8625 -- the form of this return expression.
8627 -- If the expression has at least one Raise_Expression, then we also build
8628 -- the typPredicateM version of the function, in which any occurrence of a
8629 -- Raise_Expression is converted to "return False".
8631 procedure Build_Predicate_Functions
(Typ
: Entity_Id
; N
: Node_Id
) is
8632 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
8635 -- This is the expression for the result of the function. It is
8636 -- is build by connecting the component predicates with AND THEN.
8639 -- This is the corresponding return expression for the Predicate_M
8640 -- function. It differs in that raise expressions are marked for
8641 -- special expansion (see Process_REs).
8643 Object_Name
: Name_Id
;
8644 -- Name for argument of Predicate procedure. Note that we use the same
8645 -- name for both predicate functions. That way the reference within the
8646 -- predicate expression is the same in both functions.
8648 Object_Entity
: Entity_Id
;
8649 -- Entity for argument of Predicate procedure
8651 Object_Entity_M
: Entity_Id
;
8652 -- Entity for argument of separate Predicate procedure when exceptions
8653 -- are present in expression.
8656 -- The function declaration
8661 Raise_Expression_Present
: Boolean := False;
8662 -- Set True if Expr has at least one Raise_Expression
8664 procedure Add_Condition
(Cond
: Node_Id
);
8665 -- Append Cond to Expr using "and then" (or just copy Cond to Expr if
8668 procedure Add_Predicates
;
8669 -- Appends expressions for any Predicate pragmas in the rep item chain
8670 -- Typ to Expr. Note that we look only at items for this exact entity.
8671 -- Inheritance of predicates for the parent type is done by calling the
8672 -- Predicate_Function of the parent type, using Add_Call above.
8674 procedure Add_Call
(T
: Entity_Id
);
8675 -- Includes a call to the predicate function for type T in Expr if T
8676 -- has predicates and Predicate_Function (T) is non-empty.
8678 function Process_RE
(N
: Node_Id
) return Traverse_Result
;
8679 -- Used in Process REs, tests if node N is a raise expression, and if
8680 -- so, marks it to be converted to return False.
8682 procedure Process_REs
is new Traverse_Proc
(Process_RE
);
8683 -- Marks any raise expressions in Expr_M to return False
8685 function Test_RE
(N
: Node_Id
) return Traverse_Result
;
8686 -- Used in Test_REs, tests one node for being a raise expression, and if
8687 -- so sets Raise_Expression_Present True.
8689 procedure Test_REs
is new Traverse_Proc
(Test_RE
);
8690 -- Tests to see if Expr contains any raise expressions
8696 procedure Add_Call
(T
: Entity_Id
) is
8700 if Present
(T
) and then Present
(Predicate_Function
(T
)) then
8701 Set_Has_Predicates
(Typ
);
8703 -- Build the call to the predicate function of T
8707 (T
, Convert_To
(T
, Make_Identifier
(Loc
, Object_Name
)));
8709 -- "and"-in the call to evolving expression
8711 Add_Condition
(Exp
);
8713 -- Output info message on inheritance if required. Note we do not
8714 -- give this information for generic actual types, since it is
8715 -- unwelcome noise in that case in instantiations. We also
8716 -- generally suppress the message in instantiations, and also
8717 -- if it involves internal names.
8719 if Opt
.List_Inherited_Aspects
8720 and then not Is_Generic_Actual_Type
(Typ
)
8721 and then Instantiation_Depth
(Sloc
(Typ
)) = 0
8722 and then not Is_Internal_Name
(Chars
(T
))
8723 and then not Is_Internal_Name
(Chars
(Typ
))
8725 Error_Msg_Sloc
:= Sloc
(Predicate_Function
(T
));
8726 Error_Msg_Node_2
:= T
;
8727 Error_Msg_N
("info: & inherits predicate from & #?L?", Typ
);
8736 procedure Add_Condition
(Cond
: Node_Id
) is
8738 -- This is the first predicate expression
8743 -- Otherwise concatenate to the existing predicate expressions by
8744 -- using "and then".
8749 Left_Opnd
=> Relocate_Node
(Expr
),
8750 Right_Opnd
=> Cond
);
8754 --------------------
8755 -- Add_Predicates --
8756 --------------------
8758 procedure Add_Predicates
is
8759 procedure Add_Predicate
(Prag
: Node_Id
);
8760 -- Concatenate the expression of predicate pragma Prag to Expr by
8761 -- using a short circuit "and then" operator.
8767 procedure Add_Predicate
(Prag
: Node_Id
) is
8768 procedure Replace_Type_Reference
(N
: Node_Id
);
8769 -- Replace a single occurrence N of the subtype name with a
8770 -- reference to the formal of the predicate function. N can be an
8771 -- identifier referencing the subtype, or a selected component,
8772 -- representing an appropriately qualified occurrence of the
8775 procedure Replace_Type_References
is
8776 new Replace_Type_References_Generic
(Replace_Type_Reference
);
8777 -- Traverse an expression changing every occurrence of an
8778 -- identifier whose name matches the name of the subtype with a
8779 -- reference to the formal parameter of the predicate function.
8781 ----------------------------
8782 -- Replace_Type_Reference --
8783 ----------------------------
8785 procedure Replace_Type_Reference
(N
: Node_Id
) is
8787 Rewrite
(N
, Make_Identifier
(Sloc
(N
), Object_Name
));
8788 -- Use the Sloc of the usage name, not the defining name
8791 Set_Entity
(N
, Object_Entity
);
8793 -- We want to treat the node as if it comes from source, so
8794 -- that ASIS will not ignore it.
8796 Set_Comes_From_Source
(N
, True);
8797 end Replace_Type_Reference
;
8801 Asp
: constant Node_Id
:= Corresponding_Aspect
(Prag
);
8805 -- Start of processing for Add_Predicate
8808 -- Extract the arguments of the pragma. The expression itself
8809 -- is copied for use in the predicate function, to preserve the
8810 -- original version for ASIS use.
8812 Arg1
:= First
(Pragma_Argument_Associations
(Prag
));
8813 Arg2
:= Next
(Arg1
);
8815 Arg1
:= Get_Pragma_Arg
(Arg1
);
8816 Arg2
:= New_Copy_Tree
(Get_Pragma_Arg
(Arg2
));
8818 -- When the predicate pragma applies to the current type or its
8819 -- full view, replace all occurrences of the subtype name with
8820 -- references to the formal parameter of the predicate function.
8822 if Entity
(Arg1
) = Typ
8823 or else Full_View
(Entity
(Arg1
)) = Typ
8825 Replace_Type_References
(Arg2
, Typ
);
8827 -- If the predicate pragma comes from an aspect, replace the
8828 -- saved expression because we need the subtype references
8829 -- replaced for the calls to Preanalyze_Spec_Expression in
8830 -- Check_Aspect_At_xxx routines.
8832 if Present
(Asp
) then
8833 Set_Entity
(Identifier
(Asp
), New_Copy_Tree
(Arg2
));
8836 -- "and"-in the Arg2 condition to evolving expression
8838 Add_Condition
(Relocate_Node
(Arg2
));
8846 -- Start of processing for Add_Predicates
8849 Ritem
:= First_Rep_Item
(Typ
);
8850 while Present
(Ritem
) loop
8851 if Nkind
(Ritem
) = N_Pragma
8852 and then Pragma_Name
(Ritem
) = Name_Predicate
8854 Add_Predicate
(Ritem
);
8856 -- If the type is declared in an inner package it may be frozen
8857 -- outside of the package, and the generated pragma has not been
8858 -- analyzed yet, so capture the expression for the predicate
8859 -- function at this point.
8861 elsif Nkind
(Ritem
) = N_Aspect_Specification
8862 and then Present
(Aspect_Rep_Item
(Ritem
))
8863 and then Scope
(Typ
) /= Current_Scope
8866 Prag
: constant Node_Id
:= Aspect_Rep_Item
(Ritem
);
8869 if Nkind
(Prag
) = N_Pragma
8870 and then Pragma_Name
(Prag
) = Name_Predicate
8872 Add_Predicate
(Prag
);
8877 Next_Rep_Item
(Ritem
);
8885 function Process_RE
(N
: Node_Id
) return Traverse_Result
is
8887 if Nkind
(N
) = N_Raise_Expression
then
8888 Set_Convert_To_Return_False
(N
);
8899 function Test_RE
(N
: Node_Id
) return Traverse_Result
is
8901 if Nkind
(N
) = N_Raise_Expression
then
8902 Raise_Expression_Present
:= True;
8911 Save_Ghost_Mode
: constant Ghost_Mode_Type
:= Ghost_Mode
;
8913 -- Start of processing for Build_Predicate_Functions
8916 -- Return if already built or if type does not have predicates
8918 SId
:= Predicate_Function
(Typ
);
8919 if not Has_Predicates
(Typ
)
8920 or else (Present
(SId
) and then Has_Completion
(SId
))
8925 -- The related type may be subject to pragma Ghost. Set the mode now to
8926 -- ensure that the predicate functions are properly marked as Ghost.
8928 Set_Ghost_Mode_From_Entity
(Typ
);
8930 -- Prepare to construct predicate expression
8934 if Present
(SId
) then
8935 FDecl
:= Unit_Declaration_Node
(SId
);
8938 FDecl
:= Build_Predicate_Function_Declaration
(Typ
);
8939 SId
:= Defining_Entity
(FDecl
);
8942 -- Recover name of formal parameter of function that replaces references
8943 -- to the type in predicate expressions.
8947 (First
(Parameter_Specifications
(Specification
(FDecl
))));
8949 Object_Name
:= Chars
(Object_Entity
);
8950 Object_Entity_M
:= Make_Defining_Identifier
(Loc
, Chars
=> Object_Name
);
8952 -- Add predicates for ancestor if present. These must come before the
8953 -- ones for the current type, as required by AI12-0071-1.
8956 Atyp
: constant Entity_Id
:= Nearest_Ancestor
(Typ
);
8958 if Present
(Atyp
) then
8963 -- Add Predicates for the current type
8967 -- Case where predicates are present
8969 if Present
(Expr
) then
8971 -- Test for raise expression present
8975 -- If raise expression is present, capture a copy of Expr for use
8976 -- in building the predicateM function version later on. For this
8977 -- copy we replace references to Object_Entity by Object_Entity_M.
8979 if Raise_Expression_Present
then
8981 Map
: constant Elist_Id
:= New_Elmt_List
;
8982 New_V
: Entity_Id
:= Empty
;
8984 -- The unanalyzed expression will be copied and appear in
8985 -- both functions. Normally expressions do not declare new
8986 -- entities, but quantified expressions do, so we need to
8987 -- create new entities for their bound variables, to prevent
8988 -- multiple definitions in gigi.
8990 function Reset_Loop_Variable
(N
: Node_Id
)
8991 return Traverse_Result
;
8993 procedure Collect_Loop_Variables
is
8994 new Traverse_Proc
(Reset_Loop_Variable
);
8996 ------------------------
8997 -- Reset_Loop_Variable --
8998 ------------------------
9000 function Reset_Loop_Variable
(N
: Node_Id
)
9001 return Traverse_Result
9004 if Nkind
(N
) = N_Iterator_Specification
then
9005 New_V
:= Make_Defining_Identifier
9006 (Sloc
(N
), Chars
(Defining_Identifier
(N
)));
9008 Set_Defining_Identifier
(N
, New_V
);
9012 end Reset_Loop_Variable
;
9015 Append_Elmt
(Object_Entity
, Map
);
9016 Append_Elmt
(Object_Entity_M
, Map
);
9017 Expr_M
:= New_Copy_Tree
(Expr
, Map
=> Map
);
9018 Collect_Loop_Variables
(Expr_M
);
9022 -- Build the main predicate function
9025 SIdB
: constant Entity_Id
:=
9026 Make_Defining_Identifier
(Loc
,
9027 Chars
=> New_External_Name
(Chars
(Typ
), "Predicate"));
9028 -- The entity for the function body
9035 -- The predicate function is shared between views of a type
9037 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
9038 Set_Predicate_Function
(Full_View
(Typ
), SId
);
9041 -- Mark the predicate function explicitly as Ghost because it does
9042 -- not come from source.
9044 if Ghost_Mode
> None
then
9045 Set_Is_Ghost_Entity
(SId
);
9048 -- Build function body
9051 Make_Function_Specification
(Loc
,
9052 Defining_Unit_Name
=> SIdB
,
9053 Parameter_Specifications
=> New_List
(
9054 Make_Parameter_Specification
(Loc
,
9055 Defining_Identifier
=>
9056 Make_Defining_Identifier
(Loc
, Object_Name
),
9058 New_Occurrence_Of
(Typ
, Loc
))),
9059 Result_Definition
=>
9060 New_Occurrence_Of
(Standard_Boolean
, Loc
));
9063 Make_Subprogram_Body
(Loc
,
9064 Specification
=> Spec
,
9065 Declarations
=> Empty_List
,
9066 Handled_Statement_Sequence
=>
9067 Make_Handled_Sequence_Of_Statements
(Loc
,
9068 Statements
=> New_List
(
9069 Make_Simple_Return_Statement
(Loc
,
9070 Expression
=> Expr
))));
9072 -- If declaration has not been analyzed yet, Insert declaration
9073 -- before freeze node.
9074 -- Insert body after freeze node.
9076 if not Analyzed
(FDecl
) then
9077 Insert_Before_And_Analyze
(N
, FDecl
);
9080 Insert_After_And_Analyze
(N
, FBody
);
9082 -- Static predicate functions are always side-effect free, and
9083 -- in most cases dynamic predicate functions are as well. Mark
9084 -- them as such whenever possible, so redundant predicate checks
9085 -- can be optimized. If there is a variable reference within the
9086 -- expression, the function is not pure.
9088 if Expander_Active
then
9090 Side_Effect_Free
(Expr
, Variable_Ref
=> True));
9091 Set_Is_Inlined
(SId
);
9095 -- Test for raise expressions present and if so build M version
9097 if Raise_Expression_Present
then
9099 SId
: constant Entity_Id
:=
9100 Make_Defining_Identifier
(Loc
,
9101 Chars
=> New_External_Name
(Chars
(Typ
), "PredicateM"));
9102 -- The entity for the function spec
9104 SIdB
: constant Entity_Id
:=
9105 Make_Defining_Identifier
(Loc
,
9106 Chars
=> New_External_Name
(Chars
(Typ
), "PredicateM"));
9107 -- The entity for the function body
9115 -- Mark any raise expressions for special expansion
9117 Process_REs
(Expr_M
);
9119 -- Build function declaration
9121 Set_Ekind
(SId
, E_Function
);
9122 Set_Is_Predicate_Function_M
(SId
);
9123 Set_Predicate_Function_M
(Typ
, SId
);
9125 -- The predicate function is shared between views of a type
9127 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
9128 Set_Predicate_Function_M
(Full_View
(Typ
), SId
);
9131 -- Mark the predicate function explicitly as Ghost because it
9132 -- does not come from source.
9134 if Ghost_Mode
> None
then
9135 Set_Is_Ghost_Entity
(SId
);
9139 Make_Function_Specification
(Loc
,
9140 Defining_Unit_Name
=> SId
,
9141 Parameter_Specifications
=> New_List
(
9142 Make_Parameter_Specification
(Loc
,
9143 Defining_Identifier
=> Object_Entity_M
,
9144 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))),
9145 Result_Definition
=>
9146 New_Occurrence_Of
(Standard_Boolean
, Loc
));
9149 Make_Subprogram_Declaration
(Loc
,
9150 Specification
=> Spec
);
9152 -- Build function body
9155 Make_Function_Specification
(Loc
,
9156 Defining_Unit_Name
=> SIdB
,
9157 Parameter_Specifications
=> New_List
(
9158 Make_Parameter_Specification
(Loc
,
9159 Defining_Identifier
=>
9160 Make_Defining_Identifier
(Loc
, Object_Name
),
9162 New_Occurrence_Of
(Typ
, Loc
))),
9163 Result_Definition
=>
9164 New_Occurrence_Of
(Standard_Boolean
, Loc
));
9166 -- Build the body, we declare the boolean expression before
9167 -- doing the return, because we are not really confident of
9168 -- what happens if a return appears within a return.
9171 Make_Defining_Identifier
(Loc
,
9172 Chars
=> New_Internal_Name
('B'));
9175 Make_Subprogram_Body
(Loc
,
9176 Specification
=> Spec
,
9178 Declarations
=> New_List
(
9179 Make_Object_Declaration
(Loc
,
9180 Defining_Identifier
=> BTemp
,
9181 Constant_Present
=> True,
9182 Object_Definition
=>
9183 New_Occurrence_Of
(Standard_Boolean
, Loc
),
9184 Expression
=> Expr_M
)),
9186 Handled_Statement_Sequence
=>
9187 Make_Handled_Sequence_Of_Statements
(Loc
,
9188 Statements
=> New_List
(
9189 Make_Simple_Return_Statement
(Loc
,
9190 Expression
=> New_Occurrence_Of
(BTemp
, Loc
)))));
9192 -- Insert declaration before freeze node and body after
9194 Insert_Before_And_Analyze
(N
, FDecl
);
9195 Insert_After_And_Analyze
(N
, FBody
);
9199 -- See if we have a static predicate. Note that the answer may be
9200 -- yes even if we have an explicit Dynamic_Predicate present.
9207 if not Is_Scalar_Type
(Typ
) and then not Is_String_Type
(Typ
) then
9210 PS
:= Is_Predicate_Static
(Expr
, Object_Name
);
9213 -- Case where we have a predicate-static aspect
9217 -- We don't set Has_Static_Predicate_Aspect, since we can have
9218 -- any of the three cases (Predicate, Dynamic_Predicate, or
9219 -- Static_Predicate) generating a predicate with an expression
9220 -- that is predicate-static. We just indicate that we have a
9221 -- predicate that can be treated as static.
9223 Set_Has_Static_Predicate
(Typ
);
9225 -- For discrete subtype, build the static predicate list
9227 if Is_Discrete_Type
(Typ
) then
9228 Build_Discrete_Static_Predicate
(Typ
, Expr
, Object_Name
);
9230 -- If we don't get a static predicate list, it means that we
9231 -- have a case where this is not possible, most typically in
9232 -- the case where we inherit a dynamic predicate. We do not
9233 -- consider this an error, we just leave the predicate as
9234 -- dynamic. But if we do succeed in building the list, then
9235 -- we mark the predicate as static.
9237 if No
(Static_Discrete_Predicate
(Typ
)) then
9238 Set_Has_Static_Predicate
(Typ
, False);
9241 -- For real or string subtype, save predicate expression
9243 elsif Is_Real_Type
(Typ
) or else Is_String_Type
(Typ
) then
9244 Set_Static_Real_Or_String_Predicate
(Typ
, Expr
);
9247 -- Case of dynamic predicate (expression is not predicate-static)
9250 -- Again, we don't set Has_Dynamic_Predicate_Aspect, since that
9251 -- is only set if we have an explicit Dynamic_Predicate aspect
9252 -- given. Here we may simply have a Predicate aspect where the
9253 -- expression happens not to be predicate-static.
9255 -- Emit an error when the predicate is categorized as static
9256 -- but its expression is not predicate-static.
9258 -- First a little fiddling to get a nice location for the
9259 -- message. If the expression is of the form (A and then B),
9260 -- where A is an inherited predicate, then use the right
9261 -- operand for the Sloc. This avoids getting confused by a call
9262 -- to an inherited predicate with a less convenient source
9266 while Nkind
(EN
) = N_And_Then
9267 and then Nkind
(Left_Opnd
(EN
)) = N_Function_Call
9268 and then Is_Predicate_Function
9269 (Entity
(Name
(Left_Opnd
(EN
))))
9271 EN
:= Right_Opnd
(EN
);
9274 -- Now post appropriate message
9276 if Has_Static_Predicate_Aspect
(Typ
) then
9277 if Is_Scalar_Type
(Typ
) or else Is_String_Type
(Typ
) then
9279 ("expression is not predicate-static (RM 3.2.4(16-22))",
9283 ("static predicate requires scalar or string type", EN
);
9290 Ghost_Mode
:= Save_Ghost_Mode
;
9291 end Build_Predicate_Functions
;
9293 ------------------------------------------
9294 -- Build_Predicate_Function_Declaration --
9295 ------------------------------------------
9297 function Build_Predicate_Function_Declaration
9298 (Typ
: Entity_Id
) return Node_Id
9300 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
9302 Object_Entity
: constant Entity_Id
:=
9303 Make_Defining_Identifier
(Loc
,
9304 Chars
=> New_Internal_Name
('I'));
9306 -- The formal parameter of the function
9308 SId
: constant Entity_Id
:=
9309 Make_Defining_Identifier
(Loc
,
9310 Chars
=> New_External_Name
(Chars
(Typ
), "Predicate"));
9312 -- The entity for the function spec
9319 Make_Function_Specification
(Loc
,
9320 Defining_Unit_Name
=> SId
,
9321 Parameter_Specifications
=> New_List
(
9322 Make_Parameter_Specification
(Loc
,
9323 Defining_Identifier
=> Object_Entity
,
9324 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))),
9325 Result_Definition
=>
9326 New_Occurrence_Of
(Standard_Boolean
, Loc
));
9328 FDecl
:= Make_Subprogram_Declaration
(Loc
, Specification
=> Spec
);
9330 Set_Ekind
(SId
, E_Function
);
9331 Set_Etype
(SId
, Standard_Boolean
);
9332 Set_Is_Internal
(SId
);
9333 Set_Is_Predicate_Function
(SId
);
9334 Set_Predicate_Function
(Typ
, SId
);
9336 if Comes_From_Source
(Typ
) then
9337 Insert_After
(Parent
(Typ
), FDecl
);
9339 Insert_After
(Parent
(Base_Type
(Typ
)), FDecl
);
9345 end Build_Predicate_Function_Declaration
;
9347 -----------------------------------------
9348 -- Check_Aspect_At_End_Of_Declarations --
9349 -----------------------------------------
9351 procedure Check_Aspect_At_End_Of_Declarations
(ASN
: Node_Id
) is
9352 Ent
: constant Entity_Id
:= Entity
(ASN
);
9353 Ident
: constant Node_Id
:= Identifier
(ASN
);
9354 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Chars
(Ident
));
9356 End_Decl_Expr
: constant Node_Id
:= Entity
(Ident
);
9357 -- Expression to be analyzed at end of declarations
9359 Freeze_Expr
: constant Node_Id
:= Expression
(ASN
);
9360 -- Expression from call to Check_Aspect_At_Freeze_Point
9362 T
: constant Entity_Id
:= Etype
(Freeze_Expr
);
9363 -- Type required for preanalyze call
9366 -- Set False if error
9368 -- On entry to this procedure, Entity (Ident) contains a copy of the
9369 -- original expression from the aspect, saved for this purpose, and
9370 -- but Expression (Ident) is a preanalyzed copy of the expression,
9371 -- preanalyzed just after the freeze point.
9373 procedure Check_Overloaded_Name
;
9374 -- For aspects whose expression is simply a name, this routine checks if
9375 -- the name is overloaded or not. If so, it verifies there is an
9376 -- interpretation that matches the entity obtained at the freeze point,
9377 -- otherwise the compiler complains.
9379 ---------------------------
9380 -- Check_Overloaded_Name --
9381 ---------------------------
9383 procedure Check_Overloaded_Name
is
9385 if not Is_Overloaded
(End_Decl_Expr
) then
9386 Err
:= not Is_Entity_Name
(End_Decl_Expr
)
9387 or else Entity
(End_Decl_Expr
) /= Entity
(Freeze_Expr
);
9393 Index
: Interp_Index
;
9397 Get_First_Interp
(End_Decl_Expr
, Index
, It
);
9398 while Present
(It
.Typ
) loop
9399 if It
.Nam
= Entity
(Freeze_Expr
) then
9404 Get_Next_Interp
(Index
, It
);
9408 end Check_Overloaded_Name
;
9410 -- Start of processing for Check_Aspect_At_End_Of_Declarations
9413 -- In an instance we do not perform the consistency check between freeze
9414 -- point and end of declarations, because it was done already in the
9415 -- analysis of the generic. Furthermore, the delayed analysis of an
9416 -- aspect of the instance may produce spurious errors when the generic
9417 -- is a child unit that references entities in the parent (which might
9418 -- not be in scope at the freeze point of the instance).
9423 -- Case of aspects Dimension, Dimension_System and Synchronization
9425 elsif A_Id
= Aspect_Synchronization
then
9428 -- Case of stream attributes, just have to compare entities. However,
9429 -- the expression is just a name (possibly overloaded), and there may
9430 -- be stream operations declared for unrelated types, so we just need
9431 -- to verify that one of these interpretations is the one available at
9432 -- at the freeze point.
9434 elsif A_Id
= Aspect_Input
or else
9435 A_Id
= Aspect_Output
or else
9436 A_Id
= Aspect_Read
or else
9439 Analyze
(End_Decl_Expr
);
9440 Check_Overloaded_Name
;
9442 elsif A_Id
= Aspect_Variable_Indexing
or else
9443 A_Id
= Aspect_Constant_Indexing
or else
9444 A_Id
= Aspect_Default_Iterator
or else
9445 A_Id
= Aspect_Iterator_Element
9447 -- Make type unfrozen before analysis, to prevent spurious errors
9448 -- about late attributes.
9450 Set_Is_Frozen
(Ent
, False);
9451 Analyze
(End_Decl_Expr
);
9452 Set_Is_Frozen
(Ent
, True);
9454 -- If the end of declarations comes before any other freeze
9455 -- point, the Freeze_Expr is not analyzed: no check needed.
9457 if Analyzed
(Freeze_Expr
) and then not In_Instance
then
9458 Check_Overloaded_Name
;
9466 -- Indicate that the expression comes from an aspect specification,
9467 -- which is used in subsequent analysis even if expansion is off.
9469 Set_Parent
(End_Decl_Expr
, ASN
);
9471 -- In a generic context the aspect expressions have not been
9472 -- preanalyzed, so do it now. There are no conformance checks
9473 -- to perform in this case.
9476 Check_Aspect_At_Freeze_Point
(ASN
);
9479 -- The default values attributes may be defined in the private part,
9480 -- and the analysis of the expression may take place when only the
9481 -- partial view is visible. The expression must be scalar, so use
9482 -- the full view to resolve.
9484 elsif (A_Id
= Aspect_Default_Value
9486 A_Id
= Aspect_Default_Component_Value
)
9487 and then Is_Private_Type
(T
)
9489 Preanalyze_Spec_Expression
(End_Decl_Expr
, Full_View
(T
));
9492 Preanalyze_Spec_Expression
(End_Decl_Expr
, T
);
9495 Err
:= not Fully_Conformant_Expressions
(End_Decl_Expr
, Freeze_Expr
);
9498 -- Output error message if error. Force error on aspect specification
9499 -- even if there is an error on the expression itself.
9503 ("!visibility of aspect for& changes after freeze point",
9506 ("info: & is frozen here, aspects evaluated at this point??",
9507 Freeze_Node
(Ent
), Ent
);
9509 end Check_Aspect_At_End_Of_Declarations
;
9511 ----------------------------------
9512 -- Check_Aspect_At_Freeze_Point --
9513 ----------------------------------
9515 procedure Check_Aspect_At_Freeze_Point
(ASN
: Node_Id
) is
9516 Ident
: constant Node_Id
:= Identifier
(ASN
);
9517 -- Identifier (use Entity field to save expression)
9519 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Chars
(Ident
));
9521 T
: Entity_Id
:= Empty
;
9522 -- Type required for preanalyze call
9525 -- On entry to this procedure, Entity (Ident) contains a copy of the
9526 -- original expression from the aspect, saved for this purpose.
9528 -- On exit from this procedure Entity (Ident) is unchanged, still
9529 -- containing that copy, but Expression (Ident) is a preanalyzed copy
9530 -- of the expression, preanalyzed just after the freeze point.
9532 -- Make a copy of the expression to be preanalyzed
9534 Set_Expression
(ASN
, New_Copy_Tree
(Entity
(Ident
)));
9536 -- Find type for preanalyze call
9540 -- No_Aspect should be impossible
9543 raise Program_Error
;
9545 -- Aspects taking an optional boolean argument
9547 when Boolean_Aspects |
9548 Library_Unit_Aspects
=>
9550 T
:= Standard_Boolean
;
9552 -- Aspects corresponding to attribute definition clauses
9554 when Aspect_Address
=>
9555 T
:= RTE
(RE_Address
);
9557 when Aspect_Attach_Handler
=>
9558 T
:= RTE
(RE_Interrupt_ID
);
9560 when Aspect_Bit_Order | Aspect_Scalar_Storage_Order
=>
9561 T
:= RTE
(RE_Bit_Order
);
9563 when Aspect_Convention
=>
9567 T
:= RTE
(RE_CPU_Range
);
9569 -- Default_Component_Value is resolved with the component type
9571 when Aspect_Default_Component_Value
=>
9572 T
:= Component_Type
(Entity
(ASN
));
9574 when Aspect_Default_Storage_Pool
=>
9575 T
:= Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
));
9577 -- Default_Value is resolved with the type entity in question
9579 when Aspect_Default_Value
=>
9582 when Aspect_Dispatching_Domain
=>
9583 T
:= RTE
(RE_Dispatching_Domain
);
9585 when Aspect_External_Tag
=>
9586 T
:= Standard_String
;
9588 when Aspect_External_Name
=>
9589 T
:= Standard_String
;
9591 when Aspect_Link_Name
=>
9592 T
:= Standard_String
;
9594 when Aspect_Priority | Aspect_Interrupt_Priority
=>
9595 T
:= Standard_Integer
;
9597 when Aspect_Relative_Deadline
=>
9598 T
:= RTE
(RE_Time_Span
);
9600 when Aspect_Small
=>
9601 T
:= Universal_Real
;
9603 -- For a simple storage pool, we have to retrieve the type of the
9604 -- pool object associated with the aspect's corresponding attribute
9605 -- definition clause.
9607 when Aspect_Simple_Storage_Pool
=>
9608 T
:= Etype
(Expression
(Aspect_Rep_Item
(ASN
)));
9610 when Aspect_Storage_Pool
=>
9611 T
:= Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
));
9613 when Aspect_Alignment |
9614 Aspect_Component_Size |
9615 Aspect_Machine_Radix |
9616 Aspect_Object_Size |
9618 Aspect_Storage_Size |
9619 Aspect_Stream_Size |
9620 Aspect_Value_Size
=>
9623 when Aspect_Linker_Section
=>
9624 T
:= Standard_String
;
9626 when Aspect_Synchronization
=>
9629 -- Special case, the expression of these aspects is just an entity
9630 -- that does not need any resolution, so just analyze.
9639 Analyze
(Expression
(ASN
));
9642 -- Same for Iterator aspects, where the expression is a function
9643 -- name. Legality rules are checked separately.
9645 when Aspect_Constant_Indexing |
9646 Aspect_Default_Iterator |
9647 Aspect_Iterator_Element |
9648 Aspect_Variable_Indexing
=>
9649 Analyze
(Expression
(ASN
));
9652 -- Ditto for Iterable, legality checks in Validate_Iterable_Aspect.
9654 when Aspect_Iterable
=>
9658 Cursor
: constant Entity_Id
:= Get_Cursor_Type
(ASN
, T
);
9663 if Cursor
= Any_Type
then
9667 Assoc
:= First
(Component_Associations
(Expression
(ASN
)));
9668 while Present
(Assoc
) loop
9669 Expr
:= Expression
(Assoc
);
9672 if not Error_Posted
(Expr
) then
9673 Resolve_Iterable_Operation
9674 (Expr
, Cursor
, T
, Chars
(First
(Choices
(Assoc
))));
9683 -- Invariant/Predicate take boolean expressions
9685 when Aspect_Dynamic_Predicate |
9688 Aspect_Static_Predicate |
9689 Aspect_Type_Invariant
=>
9690 T
:= Standard_Boolean
;
9692 when Aspect_Predicate_Failure
=>
9693 T
:= Standard_String
;
9695 -- Here is the list of aspects that don't require delay analysis
9697 when Aspect_Abstract_State |
9699 Aspect_Async_Readers |
9700 Aspect_Async_Writers |
9701 Aspect_Constant_After_Elaboration |
9702 Aspect_Contract_Cases |
9703 Aspect_Default_Initial_Condition |
9706 Aspect_Dimension_System |
9707 Aspect_Effective_Reads |
9708 Aspect_Effective_Writes |
9709 Aspect_Extensions_Visible |
9712 Aspect_Implicit_Dereference |
9713 Aspect_Initial_Condition |
9714 Aspect_Initializes |
9715 Aspect_Obsolescent |
9718 Aspect_Postcondition |
9720 Aspect_Precondition |
9721 Aspect_Refined_Depends |
9722 Aspect_Refined_Global |
9723 Aspect_Refined_Post |
9724 Aspect_Refined_State |
9727 Aspect_Unimplemented |
9728 Aspect_Volatile_Function
=>
9729 raise Program_Error
;
9733 -- Do the preanalyze call
9735 Preanalyze_Spec_Expression
(Expression
(ASN
), T
);
9736 end Check_Aspect_At_Freeze_Point
;
9738 -----------------------------------
9739 -- Check_Constant_Address_Clause --
9740 -----------------------------------
9742 procedure Check_Constant_Address_Clause
9746 procedure Check_At_Constant_Address
(Nod
: Node_Id
);
9747 -- Checks that the given node N represents a name whose 'Address is
9748 -- constant (in the same sense as OK_Constant_Address_Clause, i.e. the
9749 -- address value is the same at the point of declaration of U_Ent and at
9750 -- the time of elaboration of the address clause.
9752 procedure Check_Expr_Constants
(Nod
: Node_Id
);
9753 -- Checks that Nod meets the requirements for a constant address clause
9754 -- in the sense of the enclosing procedure.
9756 procedure Check_List_Constants
(Lst
: List_Id
);
9757 -- Check that all elements of list Lst meet the requirements for a
9758 -- constant address clause in the sense of the enclosing procedure.
9760 -------------------------------
9761 -- Check_At_Constant_Address --
9762 -------------------------------
9764 procedure Check_At_Constant_Address
(Nod
: Node_Id
) is
9766 if Is_Entity_Name
(Nod
) then
9767 if Present
(Address_Clause
(Entity
((Nod
)))) then
9769 ("invalid address clause for initialized object &!",
9772 ("address for& cannot" &
9773 " depend on another address clause! (RM 13.1(22))!",
9776 elsif In_Same_Source_Unit
(Entity
(Nod
), U_Ent
)
9777 and then Sloc
(U_Ent
) < Sloc
(Entity
(Nod
))
9780 ("invalid address clause for initialized object &!",
9782 Error_Msg_Node_2
:= U_Ent
;
9784 ("\& must be defined before & (RM 13.1(22))!",
9788 elsif Nkind
(Nod
) = N_Selected_Component
then
9790 T
: constant Entity_Id
:= Etype
(Prefix
(Nod
));
9793 if (Is_Record_Type
(T
)
9794 and then Has_Discriminants
(T
))
9797 and then Is_Record_Type
(Designated_Type
(T
))
9798 and then Has_Discriminants
(Designated_Type
(T
)))
9801 ("invalid address clause for initialized object &!",
9804 ("\address cannot depend on component" &
9805 " of discriminated record (RM 13.1(22))!",
9808 Check_At_Constant_Address
(Prefix
(Nod
));
9812 elsif Nkind
(Nod
) = N_Indexed_Component
then
9813 Check_At_Constant_Address
(Prefix
(Nod
));
9814 Check_List_Constants
(Expressions
(Nod
));
9817 Check_Expr_Constants
(Nod
);
9819 end Check_At_Constant_Address
;
9821 --------------------------
9822 -- Check_Expr_Constants --
9823 --------------------------
9825 procedure Check_Expr_Constants
(Nod
: Node_Id
) is
9826 Loc_U_Ent
: constant Source_Ptr
:= Sloc
(U_Ent
);
9827 Ent
: Entity_Id
:= Empty
;
9830 if Nkind
(Nod
) in N_Has_Etype
9831 and then Etype
(Nod
) = Any_Type
9837 when N_Empty | N_Error
=>
9840 when N_Identifier | N_Expanded_Name
=>
9841 Ent
:= Entity
(Nod
);
9843 -- We need to look at the original node if it is different
9844 -- from the node, since we may have rewritten things and
9845 -- substituted an identifier representing the rewrite.
9847 if Original_Node
(Nod
) /= Nod
then
9848 Check_Expr_Constants
(Original_Node
(Nod
));
9850 -- If the node is an object declaration without initial
9851 -- value, some code has been expanded, and the expression
9852 -- is not constant, even if the constituents might be
9853 -- acceptable, as in A'Address + offset.
9855 if Ekind
(Ent
) = E_Variable
9857 Nkind
(Declaration_Node
(Ent
)) = N_Object_Declaration
9859 No
(Expression
(Declaration_Node
(Ent
)))
9862 ("invalid address clause for initialized object &!",
9865 -- If entity is constant, it may be the result of expanding
9866 -- a check. We must verify that its declaration appears
9867 -- before the object in question, else we also reject the
9870 elsif Ekind
(Ent
) = E_Constant
9871 and then In_Same_Source_Unit
(Ent
, U_Ent
)
9872 and then Sloc
(Ent
) > Loc_U_Ent
9875 ("invalid address clause for initialized object &!",
9882 -- Otherwise look at the identifier and see if it is OK
9884 if Ekind_In
(Ent
, E_Named_Integer
, E_Named_Real
)
9885 or else Is_Type
(Ent
)
9889 elsif Ekind_In
(Ent
, E_Constant
, E_In_Parameter
) then
9891 -- This is the case where we must have Ent defined before
9892 -- U_Ent. Clearly if they are in different units this
9893 -- requirement is met since the unit containing Ent is
9894 -- already processed.
9896 if not In_Same_Source_Unit
(Ent
, U_Ent
) then
9899 -- Otherwise location of Ent must be before the location
9900 -- of U_Ent, that's what prior defined means.
9902 elsif Sloc
(Ent
) < Loc_U_Ent
then
9907 ("invalid address clause for initialized object &!",
9909 Error_Msg_Node_2
:= U_Ent
;
9911 ("\& must be defined before & (RM 13.1(22))!",
9915 elsif Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
9916 Check_Expr_Constants
(Original_Node
(Nod
));
9920 ("invalid address clause for initialized object &!",
9923 if Comes_From_Source
(Ent
) then
9925 ("\reference to variable& not allowed"
9926 & " (RM 13.1(22))!", Nod
, Ent
);
9929 ("non-static expression not allowed"
9930 & " (RM 13.1(22))!", Nod
);
9934 when N_Integer_Literal
=>
9936 -- If this is a rewritten unchecked conversion, in a system
9937 -- where Address is an integer type, always use the base type
9938 -- for a literal value. This is user-friendly and prevents
9939 -- order-of-elaboration issues with instances of unchecked
9942 if Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
9943 Set_Etype
(Nod
, Base_Type
(Etype
(Nod
)));
9946 when N_Real_Literal |
9948 N_Character_Literal
=>
9952 Check_Expr_Constants
(Low_Bound
(Nod
));
9953 Check_Expr_Constants
(High_Bound
(Nod
));
9955 when N_Explicit_Dereference
=>
9956 Check_Expr_Constants
(Prefix
(Nod
));
9958 when N_Indexed_Component
=>
9959 Check_Expr_Constants
(Prefix
(Nod
));
9960 Check_List_Constants
(Expressions
(Nod
));
9963 Check_Expr_Constants
(Prefix
(Nod
));
9964 Check_Expr_Constants
(Discrete_Range
(Nod
));
9966 when N_Selected_Component
=>
9967 Check_Expr_Constants
(Prefix
(Nod
));
9969 when N_Attribute_Reference
=>
9970 if Nam_In
(Attribute_Name
(Nod
), Name_Address
,
9972 Name_Unchecked_Access
,
9973 Name_Unrestricted_Access
)
9975 Check_At_Constant_Address
(Prefix
(Nod
));
9978 Check_Expr_Constants
(Prefix
(Nod
));
9979 Check_List_Constants
(Expressions
(Nod
));
9983 Check_List_Constants
(Component_Associations
(Nod
));
9984 Check_List_Constants
(Expressions
(Nod
));
9986 when N_Component_Association
=>
9987 Check_Expr_Constants
(Expression
(Nod
));
9989 when N_Extension_Aggregate
=>
9990 Check_Expr_Constants
(Ancestor_Part
(Nod
));
9991 Check_List_Constants
(Component_Associations
(Nod
));
9992 Check_List_Constants
(Expressions
(Nod
));
9997 when N_Binary_Op | N_Short_Circuit | N_Membership_Test
=>
9998 Check_Expr_Constants
(Left_Opnd
(Nod
));
9999 Check_Expr_Constants
(Right_Opnd
(Nod
));
10002 Check_Expr_Constants
(Right_Opnd
(Nod
));
10004 when N_Type_Conversion |
10005 N_Qualified_Expression |
10007 N_Unchecked_Type_Conversion
=>
10008 Check_Expr_Constants
(Expression
(Nod
));
10010 when N_Function_Call
=>
10011 if not Is_Pure
(Entity
(Name
(Nod
))) then
10013 ("invalid address clause for initialized object &!",
10017 ("\function & is not pure (RM 13.1(22))!",
10018 Nod
, Entity
(Name
(Nod
)));
10021 Check_List_Constants
(Parameter_Associations
(Nod
));
10024 when N_Parameter_Association
=>
10025 Check_Expr_Constants
(Explicit_Actual_Parameter
(Nod
));
10029 ("invalid address clause for initialized object &!",
10032 ("\must be constant defined before& (RM 13.1(22))!",
10035 end Check_Expr_Constants
;
10037 --------------------------
10038 -- Check_List_Constants --
10039 --------------------------
10041 procedure Check_List_Constants
(Lst
: List_Id
) is
10045 if Present
(Lst
) then
10046 Nod1
:= First
(Lst
);
10047 while Present
(Nod1
) loop
10048 Check_Expr_Constants
(Nod1
);
10052 end Check_List_Constants
;
10054 -- Start of processing for Check_Constant_Address_Clause
10057 -- If rep_clauses are to be ignored, no need for legality checks. In
10058 -- particular, no need to pester user about rep clauses that violate the
10059 -- rule on constant addresses, given that these clauses will be removed
10060 -- by Freeze before they reach the back end. Similarly in CodePeer mode,
10061 -- we want to relax these checks.
10063 if not Ignore_Rep_Clauses
and not CodePeer_Mode
then
10064 Check_Expr_Constants
(Expr
);
10066 end Check_Constant_Address_Clause
;
10068 ---------------------------
10069 -- Check_Pool_Size_Clash --
10070 ---------------------------
10072 procedure Check_Pool_Size_Clash
(Ent
: Entity_Id
; SP
, SS
: Node_Id
) is
10076 -- We need to find out which one came first. Note that in the case of
10077 -- aspects mixed with pragmas there are cases where the processing order
10078 -- is reversed, which is why we do the check here.
10080 if Sloc
(SP
) < Sloc
(SS
) then
10081 Error_Msg_Sloc
:= Sloc
(SP
);
10083 Error_Msg_NE
("Storage_Pool previously given for&#", Post
, Ent
);
10086 Error_Msg_Sloc
:= Sloc
(SS
);
10088 Error_Msg_NE
("Storage_Size previously given for&#", Post
, Ent
);
10092 ("\cannot have Storage_Size and Storage_Pool (RM 13.11(3))", Post
);
10093 end Check_Pool_Size_Clash
;
10095 ----------------------------------------
10096 -- Check_Record_Representation_Clause --
10097 ----------------------------------------
10099 procedure Check_Record_Representation_Clause
(N
: Node_Id
) is
10100 Loc
: constant Source_Ptr
:= Sloc
(N
);
10101 Ident
: constant Node_Id
:= Identifier
(N
);
10102 Rectype
: Entity_Id
;
10107 Hbit
: Uint
:= Uint_0
;
10111 Max_Bit_So_Far
: Uint
;
10112 -- Records the maximum bit position so far. If all field positions
10113 -- are monotonically increasing, then we can skip the circuit for
10114 -- checking for overlap, since no overlap is possible.
10116 Tagged_Parent
: Entity_Id
:= Empty
;
10117 -- This is set in the case of a derived tagged type for which we have
10118 -- Is_Fully_Repped_Tagged_Type True (indicating that all components are
10119 -- positioned by record representation clauses). In this case we must
10120 -- check for overlap between components of this tagged type, and the
10121 -- components of its parent. Tagged_Parent will point to this parent
10122 -- type. For all other cases Tagged_Parent is left set to Empty.
10124 Parent_Last_Bit
: Uint
;
10125 -- Relevant only if Tagged_Parent is set, Parent_Last_Bit indicates the
10126 -- last bit position for any field in the parent type. We only need to
10127 -- check overlap for fields starting below this point.
10129 Overlap_Check_Required
: Boolean;
10130 -- Used to keep track of whether or not an overlap check is required
10132 Overlap_Detected
: Boolean := False;
10133 -- Set True if an overlap is detected
10135 Ccount
: Natural := 0;
10136 -- Number of component clauses in record rep clause
10138 procedure Check_Component_Overlap
(C1_Ent
, C2_Ent
: Entity_Id
);
10139 -- Given two entities for record components or discriminants, checks
10140 -- if they have overlapping component clauses and issues errors if so.
10142 procedure Find_Component
;
10143 -- Finds component entity corresponding to current component clause (in
10144 -- CC), and sets Comp to the entity, and Fbit/Lbit to the zero origin
10145 -- start/stop bits for the field. If there is no matching component or
10146 -- if the matching component does not have a component clause, then
10147 -- that's an error and Comp is set to Empty, but no error message is
10148 -- issued, since the message was already given. Comp is also set to
10149 -- Empty if the current "component clause" is in fact a pragma.
10151 -----------------------------
10152 -- Check_Component_Overlap --
10153 -----------------------------
10155 procedure Check_Component_Overlap
(C1_Ent
, C2_Ent
: Entity_Id
) is
10156 CC1
: constant Node_Id
:= Component_Clause
(C1_Ent
);
10157 CC2
: constant Node_Id
:= Component_Clause
(C2_Ent
);
10160 if Present
(CC1
) and then Present
(CC2
) then
10162 -- Exclude odd case where we have two tag components in the same
10163 -- record, both at location zero. This seems a bit strange, but
10164 -- it seems to happen in some circumstances, perhaps on an error.
10166 if Nam_In
(Chars
(C1_Ent
), Name_uTag
, Name_uTag
) then
10170 -- Here we check if the two fields overlap
10173 S1
: constant Uint
:= Component_Bit_Offset
(C1_Ent
);
10174 S2
: constant Uint
:= Component_Bit_Offset
(C2_Ent
);
10175 E1
: constant Uint
:= S1
+ Esize
(C1_Ent
);
10176 E2
: constant Uint
:= S2
+ Esize
(C2_Ent
);
10179 if E2
<= S1
or else E1
<= S2
then
10182 Error_Msg_Node_2
:= Component_Name
(CC2
);
10183 Error_Msg_Sloc
:= Sloc
(Error_Msg_Node_2
);
10184 Error_Msg_Node_1
:= Component_Name
(CC1
);
10186 ("component& overlaps & #", Component_Name
(CC1
));
10187 Overlap_Detected
:= True;
10191 end Check_Component_Overlap
;
10193 --------------------
10194 -- Find_Component --
10195 --------------------
10197 procedure Find_Component
is
10199 procedure Search_Component
(R
: Entity_Id
);
10200 -- Search components of R for a match. If found, Comp is set
10202 ----------------------
10203 -- Search_Component --
10204 ----------------------
10206 procedure Search_Component
(R
: Entity_Id
) is
10208 Comp
:= First_Component_Or_Discriminant
(R
);
10209 while Present
(Comp
) loop
10211 -- Ignore error of attribute name for component name (we
10212 -- already gave an error message for this, so no need to
10215 if Nkind
(Component_Name
(CC
)) = N_Attribute_Reference
then
10218 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
10221 Next_Component_Or_Discriminant
(Comp
);
10223 end Search_Component
;
10225 -- Start of processing for Find_Component
10228 -- Return with Comp set to Empty if we have a pragma
10230 if Nkind
(CC
) = N_Pragma
then
10235 -- Search current record for matching component
10237 Search_Component
(Rectype
);
10239 -- If not found, maybe component of base type discriminant that is
10240 -- absent from statically constrained first subtype.
10243 Search_Component
(Base_Type
(Rectype
));
10246 -- If no component, or the component does not reference the component
10247 -- clause in question, then there was some previous error for which
10248 -- we already gave a message, so just return with Comp Empty.
10250 if No
(Comp
) or else Component_Clause
(Comp
) /= CC
then
10251 Check_Error_Detected
;
10254 -- Normal case where we have a component clause
10257 Fbit
:= Component_Bit_Offset
(Comp
);
10258 Lbit
:= Fbit
+ Esize
(Comp
) - 1;
10260 end Find_Component
;
10262 -- Start of processing for Check_Record_Representation_Clause
10266 Rectype
:= Entity
(Ident
);
10268 if Rectype
= Any_Type
then
10271 Rectype
:= Underlying_Type
(Rectype
);
10274 -- See if we have a fully repped derived tagged type
10277 PS
: constant Entity_Id
:= Parent_Subtype
(Rectype
);
10280 if Present
(PS
) and then Is_Fully_Repped_Tagged_Type
(PS
) then
10281 Tagged_Parent
:= PS
;
10283 -- Find maximum bit of any component of the parent type
10285 Parent_Last_Bit
:= UI_From_Int
(System_Address_Size
- 1);
10286 Pcomp
:= First_Entity
(Tagged_Parent
);
10287 while Present
(Pcomp
) loop
10288 if Ekind_In
(Pcomp
, E_Discriminant
, E_Component
) then
10289 if Component_Bit_Offset
(Pcomp
) /= No_Uint
10290 and then Known_Static_Esize
(Pcomp
)
10295 Component_Bit_Offset
(Pcomp
) + Esize
(Pcomp
) - 1);
10299 -- Skip anonymous types generated for constrained array
10300 -- or record components.
10305 Next_Entity
(Pcomp
);
10310 -- All done if no component clauses
10312 CC
:= First
(Component_Clauses
(N
));
10318 -- If a tag is present, then create a component clause that places it
10319 -- at the start of the record (otherwise gigi may place it after other
10320 -- fields that have rep clauses).
10322 Fent
:= First_Entity
(Rectype
);
10324 if Nkind
(Fent
) = N_Defining_Identifier
10325 and then Chars
(Fent
) = Name_uTag
10327 Set_Component_Bit_Offset
(Fent
, Uint_0
);
10328 Set_Normalized_Position
(Fent
, Uint_0
);
10329 Set_Normalized_First_Bit
(Fent
, Uint_0
);
10330 Set_Normalized_Position_Max
(Fent
, Uint_0
);
10331 Init_Esize
(Fent
, System_Address_Size
);
10333 Set_Component_Clause
(Fent
,
10334 Make_Component_Clause
(Loc
,
10335 Component_Name
=> Make_Identifier
(Loc
, Name_uTag
),
10337 Position
=> Make_Integer_Literal
(Loc
, Uint_0
),
10338 First_Bit
=> Make_Integer_Literal
(Loc
, Uint_0
),
10340 Make_Integer_Literal
(Loc
,
10341 UI_From_Int
(System_Address_Size
))));
10343 Ccount
:= Ccount
+ 1;
10346 Max_Bit_So_Far
:= Uint_Minus_1
;
10347 Overlap_Check_Required
:= False;
10349 -- Process the component clauses
10351 while Present
(CC
) loop
10354 if Present
(Comp
) then
10355 Ccount
:= Ccount
+ 1;
10357 -- We need a full overlap check if record positions non-monotonic
10359 if Fbit
<= Max_Bit_So_Far
then
10360 Overlap_Check_Required
:= True;
10363 Max_Bit_So_Far
:= Lbit
;
10365 -- Check bit position out of range of specified size
10367 if Has_Size_Clause
(Rectype
)
10368 and then RM_Size
(Rectype
) <= Lbit
10371 ("bit number out of range of specified size",
10374 -- Check for overlap with tag component
10377 if Is_Tagged_Type
(Rectype
)
10378 and then Fbit
< System_Address_Size
10381 ("component overlaps tag field of&",
10382 Component_Name
(CC
), Rectype
);
10383 Overlap_Detected
:= True;
10386 if Hbit
< Lbit
then
10391 -- Check parent overlap if component might overlap parent field
10393 if Present
(Tagged_Parent
) and then Fbit
<= Parent_Last_Bit
then
10394 Pcomp
:= First_Component_Or_Discriminant
(Tagged_Parent
);
10395 while Present
(Pcomp
) loop
10396 if not Is_Tag
(Pcomp
)
10397 and then Chars
(Pcomp
) /= Name_uParent
10399 Check_Component_Overlap
(Comp
, Pcomp
);
10402 Next_Component_Or_Discriminant
(Pcomp
);
10410 -- Now that we have processed all the component clauses, check for
10411 -- overlap. We have to leave this till last, since the components can
10412 -- appear in any arbitrary order in the representation clause.
10414 -- We do not need this check if all specified ranges were monotonic,
10415 -- as recorded by Overlap_Check_Required being False at this stage.
10417 -- This first section checks if there are any overlapping entries at
10418 -- all. It does this by sorting all entries and then seeing if there are
10419 -- any overlaps. If there are none, then that is decisive, but if there
10420 -- are overlaps, they may still be OK (they may result from fields in
10421 -- different variants).
10423 if Overlap_Check_Required
then
10424 Overlap_Check1
: declare
10426 OC_Fbit
: array (0 .. Ccount
) of Uint
;
10427 -- First-bit values for component clauses, the value is the offset
10428 -- of the first bit of the field from start of record. The zero
10429 -- entry is for use in sorting.
10431 OC_Lbit
: array (0 .. Ccount
) of Uint
;
10432 -- Last-bit values for component clauses, the value is the offset
10433 -- of the last bit of the field from start of record. The zero
10434 -- entry is for use in sorting.
10436 OC_Count
: Natural := 0;
10437 -- Count of entries in OC_Fbit and OC_Lbit
10439 function OC_Lt
(Op1
, Op2
: Natural) return Boolean;
10440 -- Compare routine for Sort
10442 procedure OC_Move
(From
: Natural; To
: Natural);
10443 -- Move routine for Sort
10445 package Sorting
is new GNAT
.Heap_Sort_G
(OC_Move
, OC_Lt
);
10451 function OC_Lt
(Op1
, Op2
: Natural) return Boolean is
10453 return OC_Fbit
(Op1
) < OC_Fbit
(Op2
);
10460 procedure OC_Move
(From
: Natural; To
: Natural) is
10462 OC_Fbit
(To
) := OC_Fbit
(From
);
10463 OC_Lbit
(To
) := OC_Lbit
(From
);
10466 -- Start of processing for Overlap_Check
10469 CC
:= First
(Component_Clauses
(N
));
10470 while Present
(CC
) loop
10472 -- Exclude component clause already marked in error
10474 if not Error_Posted
(CC
) then
10477 if Present
(Comp
) then
10478 OC_Count
:= OC_Count
+ 1;
10479 OC_Fbit
(OC_Count
) := Fbit
;
10480 OC_Lbit
(OC_Count
) := Lbit
;
10487 Sorting
.Sort
(OC_Count
);
10489 Overlap_Check_Required
:= False;
10490 for J
in 1 .. OC_Count
- 1 loop
10491 if OC_Lbit
(J
) >= OC_Fbit
(J
+ 1) then
10492 Overlap_Check_Required
:= True;
10496 end Overlap_Check1
;
10499 -- If Overlap_Check_Required is still True, then we have to do the full
10500 -- scale overlap check, since we have at least two fields that do
10501 -- overlap, and we need to know if that is OK since they are in
10502 -- different variant, or whether we have a definite problem.
10504 if Overlap_Check_Required
then
10505 Overlap_Check2
: declare
10506 C1_Ent
, C2_Ent
: Entity_Id
;
10507 -- Entities of components being checked for overlap
10510 -- Component_List node whose Component_Items are being checked
10513 -- Component declaration for component being checked
10516 C1_Ent
:= First_Entity
(Base_Type
(Rectype
));
10518 -- Loop through all components in record. For each component check
10519 -- for overlap with any of the preceding elements on the component
10520 -- list containing the component and also, if the component is in
10521 -- a variant, check against components outside the case structure.
10522 -- This latter test is repeated recursively up the variant tree.
10524 Main_Component_Loop
: while Present
(C1_Ent
) loop
10525 if not Ekind_In
(C1_Ent
, E_Component
, E_Discriminant
) then
10526 goto Continue_Main_Component_Loop
;
10529 -- Skip overlap check if entity has no declaration node. This
10530 -- happens with discriminants in constrained derived types.
10531 -- Possibly we are missing some checks as a result, but that
10532 -- does not seem terribly serious.
10534 if No
(Declaration_Node
(C1_Ent
)) then
10535 goto Continue_Main_Component_Loop
;
10538 Clist
:= Parent
(List_Containing
(Declaration_Node
(C1_Ent
)));
10540 -- Loop through component lists that need checking. Check the
10541 -- current component list and all lists in variants above us.
10543 Component_List_Loop
: loop
10545 -- If derived type definition, go to full declaration
10546 -- If at outer level, check discriminants if there are any.
10548 if Nkind
(Clist
) = N_Derived_Type_Definition
then
10549 Clist
:= Parent
(Clist
);
10552 -- Outer level of record definition, check discriminants
10554 if Nkind_In
(Clist
, N_Full_Type_Declaration
,
10555 N_Private_Type_Declaration
)
10557 if Has_Discriminants
(Defining_Identifier
(Clist
)) then
10559 First_Discriminant
(Defining_Identifier
(Clist
));
10560 while Present
(C2_Ent
) loop
10561 exit when C1_Ent
= C2_Ent
;
10562 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
10563 Next_Discriminant
(C2_Ent
);
10567 -- Record extension case
10569 elsif Nkind
(Clist
) = N_Derived_Type_Definition
then
10572 -- Otherwise check one component list
10575 Citem
:= First
(Component_Items
(Clist
));
10576 while Present
(Citem
) loop
10577 if Nkind
(Citem
) = N_Component_Declaration
then
10578 C2_Ent
:= Defining_Identifier
(Citem
);
10579 exit when C1_Ent
= C2_Ent
;
10580 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
10587 -- Check for variants above us (the parent of the Clist can
10588 -- be a variant, in which case its parent is a variant part,
10589 -- and the parent of the variant part is a component list
10590 -- whose components must all be checked against the current
10591 -- component for overlap).
10593 if Nkind
(Parent
(Clist
)) = N_Variant
then
10594 Clist
:= Parent
(Parent
(Parent
(Clist
)));
10596 -- Check for possible discriminant part in record, this
10597 -- is treated essentially as another level in the
10598 -- recursion. For this case the parent of the component
10599 -- list is the record definition, and its parent is the
10600 -- full type declaration containing the discriminant
10603 elsif Nkind
(Parent
(Clist
)) = N_Record_Definition
then
10604 Clist
:= Parent
(Parent
((Clist
)));
10606 -- If neither of these two cases, we are at the top of
10610 exit Component_List_Loop
;
10612 end loop Component_List_Loop
;
10614 <<Continue_Main_Component_Loop
>>
10615 Next_Entity
(C1_Ent
);
10617 end loop Main_Component_Loop
;
10618 end Overlap_Check2
;
10621 -- The following circuit deals with warning on record holes (gaps). We
10622 -- skip this check if overlap was detected, since it makes sense for the
10623 -- programmer to fix this illegality before worrying about warnings.
10625 if not Overlap_Detected
and Warn_On_Record_Holes
then
10626 Record_Hole_Check
: declare
10627 Decl
: constant Node_Id
:= Declaration_Node
(Base_Type
(Rectype
));
10628 -- Full declaration of record type
10630 procedure Check_Component_List
10634 -- Check component list CL for holes. The starting bit should be
10635 -- Sbit. which is zero for the main record component list and set
10636 -- appropriately for recursive calls for variants. DS is set to
10637 -- a list of discriminant specifications to be included in the
10638 -- consideration of components. It is No_List if none to consider.
10640 --------------------------
10641 -- Check_Component_List --
10642 --------------------------
10644 procedure Check_Component_List
10652 Compl
:= Integer (List_Length
(Component_Items
(CL
)));
10654 if DS
/= No_List
then
10655 Compl
:= Compl
+ Integer (List_Length
(DS
));
10659 Comps
: array (Natural range 0 .. Compl
) of Entity_Id
;
10660 -- Gather components (zero entry is for sort routine)
10662 Ncomps
: Natural := 0;
10663 -- Number of entries stored in Comps (starting at Comps (1))
10666 -- One component item or discriminant specification
10669 -- Starting bit for next component
10672 -- Component entity
10677 function Lt
(Op1
, Op2
: Natural) return Boolean;
10678 -- Compare routine for Sort
10680 procedure Move
(From
: Natural; To
: Natural);
10681 -- Move routine for Sort
10683 package Sorting
is new GNAT
.Heap_Sort_G
(Move
, Lt
);
10689 function Lt
(Op1
, Op2
: Natural) return Boolean is
10691 return Component_Bit_Offset
(Comps
(Op1
))
10693 Component_Bit_Offset
(Comps
(Op2
));
10700 procedure Move
(From
: Natural; To
: Natural) is
10702 Comps
(To
) := Comps
(From
);
10706 -- Gather discriminants into Comp
10708 if DS
/= No_List
then
10709 Citem
:= First
(DS
);
10710 while Present
(Citem
) loop
10711 if Nkind
(Citem
) = N_Discriminant_Specification
then
10713 Ent
: constant Entity_Id
:=
10714 Defining_Identifier
(Citem
);
10716 if Ekind
(Ent
) = E_Discriminant
then
10717 Ncomps
:= Ncomps
+ 1;
10718 Comps
(Ncomps
) := Ent
;
10727 -- Gather component entities into Comp
10729 Citem
:= First
(Component_Items
(CL
));
10730 while Present
(Citem
) loop
10731 if Nkind
(Citem
) = N_Component_Declaration
then
10732 Ncomps
:= Ncomps
+ 1;
10733 Comps
(Ncomps
) := Defining_Identifier
(Citem
);
10739 -- Now sort the component entities based on the first bit.
10740 -- Note we already know there are no overlapping components.
10742 Sorting
.Sort
(Ncomps
);
10744 -- Loop through entries checking for holes
10747 for J
in 1 .. Ncomps
loop
10749 Error_Msg_Uint_1
:= Component_Bit_Offset
(CEnt
) - Nbit
;
10751 if Error_Msg_Uint_1
> 0 then
10753 ("?H?^-bit gap before component&",
10754 Component_Name
(Component_Clause
(CEnt
)), CEnt
);
10757 Nbit
:= Component_Bit_Offset
(CEnt
) + Esize
(CEnt
);
10760 -- Process variant parts recursively if present
10762 if Present
(Variant_Part
(CL
)) then
10763 Variant
:= First
(Variants
(Variant_Part
(CL
)));
10764 while Present
(Variant
) loop
10765 Check_Component_List
10766 (Component_List
(Variant
), Nbit
, No_List
);
10771 end Check_Component_List
;
10773 -- Start of processing for Record_Hole_Check
10780 if Is_Tagged_Type
(Rectype
) then
10781 Sbit
:= UI_From_Int
(System_Address_Size
);
10786 if Nkind
(Decl
) = N_Full_Type_Declaration
10787 and then Nkind
(Type_Definition
(Decl
)) = N_Record_Definition
10789 Check_Component_List
10790 (Component_List
(Type_Definition
(Decl
)),
10792 Discriminant_Specifications
(Decl
));
10795 end Record_Hole_Check
;
10798 -- For records that have component clauses for all components, and whose
10799 -- size is less than or equal to 32, we need to know the size in the
10800 -- front end to activate possible packed array processing where the
10801 -- component type is a record.
10803 -- At this stage Hbit + 1 represents the first unused bit from all the
10804 -- component clauses processed, so if the component clauses are
10805 -- complete, then this is the length of the record.
10807 -- For records longer than System.Storage_Unit, and for those where not
10808 -- all components have component clauses, the back end determines the
10809 -- length (it may for example be appropriate to round up the size
10810 -- to some convenient boundary, based on alignment considerations, etc).
10812 if Unknown_RM_Size
(Rectype
) and then Hbit
+ 1 <= 32 then
10814 -- Nothing to do if at least one component has no component clause
10816 Comp
:= First_Component_Or_Discriminant
(Rectype
);
10817 while Present
(Comp
) loop
10818 exit when No
(Component_Clause
(Comp
));
10819 Next_Component_Or_Discriminant
(Comp
);
10822 -- If we fall out of loop, all components have component clauses
10823 -- and so we can set the size to the maximum value.
10826 Set_RM_Size
(Rectype
, Hbit
+ 1);
10829 end Check_Record_Representation_Clause
;
10835 procedure Check_Size
10839 Biased
: out Boolean)
10841 UT
: constant Entity_Id
:= Underlying_Type
(T
);
10847 -- Reject patently improper size values.
10849 if Is_Elementary_Type
(T
)
10850 and then Siz
> UI_From_Int
(Int
'Last)
10852 Error_Msg_N
("Size value too large for elementary type", N
);
10854 if Nkind
(Original_Node
(N
)) = N_Op_Expon
then
10856 ("\maybe '* was meant, rather than '*'*", Original_Node
(N
));
10860 -- Dismiss generic types
10862 if Is_Generic_Type
(T
)
10864 Is_Generic_Type
(UT
)
10866 Is_Generic_Type
(Root_Type
(UT
))
10870 -- Guard against previous errors
10872 elsif No
(UT
) or else UT
= Any_Type
then
10873 Check_Error_Detected
;
10876 -- Check case of bit packed array
10878 elsif Is_Array_Type
(UT
)
10879 and then Known_Static_Component_Size
(UT
)
10880 and then Is_Bit_Packed_Array
(UT
)
10888 Asiz
:= Component_Size
(UT
);
10889 Indx
:= First_Index
(UT
);
10891 Ityp
:= Etype
(Indx
);
10893 -- If non-static bound, then we are not in the business of
10894 -- trying to check the length, and indeed an error will be
10895 -- issued elsewhere, since sizes of non-static array types
10896 -- cannot be set implicitly or explicitly.
10898 if not Is_OK_Static_Subtype
(Ityp
) then
10902 -- Otherwise accumulate next dimension
10904 Asiz
:= Asiz
* (Expr_Value
(Type_High_Bound
(Ityp
)) -
10905 Expr_Value
(Type_Low_Bound
(Ityp
)) +
10909 exit when No
(Indx
);
10912 if Asiz
<= Siz
then
10916 Error_Msg_Uint_1
:= Asiz
;
10918 ("size for& too small, minimum allowed is ^", N
, T
);
10919 Set_Esize
(T
, Asiz
);
10920 Set_RM_Size
(T
, Asiz
);
10924 -- All other composite types are ignored
10926 elsif Is_Composite_Type
(UT
) then
10929 -- For fixed-point types, don't check minimum if type is not frozen,
10930 -- since we don't know all the characteristics of the type that can
10931 -- affect the size (e.g. a specified small) till freeze time.
10933 elsif Is_Fixed_Point_Type
(UT
)
10934 and then not Is_Frozen
(UT
)
10938 -- Cases for which a minimum check is required
10941 -- Ignore if specified size is correct for the type
10943 if Known_Esize
(UT
) and then Siz
= Esize
(UT
) then
10947 -- Otherwise get minimum size
10949 M
:= UI_From_Int
(Minimum_Size
(UT
));
10953 -- Size is less than minimum size, but one possibility remains
10954 -- that we can manage with the new size if we bias the type.
10956 M
:= UI_From_Int
(Minimum_Size
(UT
, Biased
=> True));
10959 Error_Msg_Uint_1
:= M
;
10961 ("size for& too small, minimum allowed is ^", N
, T
);
10963 Set_RM_Size
(T
, M
);
10971 --------------------------
10972 -- Freeze_Entity_Checks --
10973 --------------------------
10975 procedure Freeze_Entity_Checks
(N
: Node_Id
) is
10976 procedure Hide_Non_Overridden_Subprograms
(Typ
: Entity_Id
);
10977 -- Inspect the primitive operations of type Typ and hide all pairs of
10978 -- implicitly declared non-overridden non-fully conformant homographs
10979 -- (Ada RM 8.3 12.3/2).
10981 -------------------------------------
10982 -- Hide_Non_Overridden_Subprograms --
10983 -------------------------------------
10985 procedure Hide_Non_Overridden_Subprograms
(Typ
: Entity_Id
) is
10986 procedure Hide_Matching_Homographs
10987 (Subp_Id
: Entity_Id
;
10988 Start_Elmt
: Elmt_Id
);
10989 -- Inspect a list of primitive operations starting with Start_Elmt
10990 -- and find matching implicitly declared non-overridden non-fully
10991 -- conformant homographs of Subp_Id. If found, all matches along
10992 -- with Subp_Id are hidden from all visibility.
10994 function Is_Non_Overridden_Or_Null_Procedure
10995 (Subp_Id
: Entity_Id
) return Boolean;
10996 -- Determine whether subprogram Subp_Id is implicitly declared non-
10997 -- overridden subprogram or an implicitly declared null procedure.
10999 ------------------------------
11000 -- Hide_Matching_Homographs --
11001 ------------------------------
11003 procedure Hide_Matching_Homographs
11004 (Subp_Id
: Entity_Id
;
11005 Start_Elmt
: Elmt_Id
)
11008 Prim_Elmt
: Elmt_Id
;
11011 Prim_Elmt
:= Start_Elmt
;
11012 while Present
(Prim_Elmt
) loop
11013 Prim
:= Node
(Prim_Elmt
);
11015 -- The current primitive is implicitly declared non-overridden
11016 -- non-fully conformant homograph of Subp_Id. Both subprograms
11017 -- must be hidden from visibility.
11019 if Chars
(Prim
) = Chars
(Subp_Id
)
11020 and then Is_Non_Overridden_Or_Null_Procedure
(Prim
)
11021 and then not Fully_Conformant
(Prim
, Subp_Id
)
11023 Set_Is_Hidden_Non_Overridden_Subpgm
(Prim
);
11024 Set_Is_Immediately_Visible
(Prim
, False);
11025 Set_Is_Potentially_Use_Visible
(Prim
, False);
11027 Set_Is_Hidden_Non_Overridden_Subpgm
(Subp_Id
);
11028 Set_Is_Immediately_Visible
(Subp_Id
, False);
11029 Set_Is_Potentially_Use_Visible
(Subp_Id
, False);
11032 Next_Elmt
(Prim_Elmt
);
11034 end Hide_Matching_Homographs
;
11036 -----------------------------------------
11037 -- Is_Non_Overridden_Or_Null_Procedure --
11038 -----------------------------------------
11040 function Is_Non_Overridden_Or_Null_Procedure
11041 (Subp_Id
: Entity_Id
) return Boolean
11043 Alias_Id
: Entity_Id
;
11046 -- The subprogram is inherited (implicitly declared), it does not
11047 -- override and does not cover a primitive of an interface.
11049 if Ekind_In
(Subp_Id
, E_Function
, E_Procedure
)
11050 and then Present
(Alias
(Subp_Id
))
11051 and then No
(Interface_Alias
(Subp_Id
))
11052 and then No
(Overridden_Operation
(Subp_Id
))
11054 Alias_Id
:= Alias
(Subp_Id
);
11056 if Requires_Overriding
(Alias_Id
) then
11059 elsif Nkind
(Parent
(Alias_Id
)) = N_Procedure_Specification
11060 and then Null_Present
(Parent
(Alias_Id
))
11067 end Is_Non_Overridden_Or_Null_Procedure
;
11071 Prim_Ops
: constant Elist_Id
:= Direct_Primitive_Operations
(Typ
);
11073 Prim_Elmt
: Elmt_Id
;
11075 -- Start of processing for Hide_Non_Overridden_Subprograms
11078 -- Inspect the list of primitives looking for non-overridden
11081 if Present
(Prim_Ops
) then
11082 Prim_Elmt
:= First_Elmt
(Prim_Ops
);
11083 while Present
(Prim_Elmt
) loop
11084 Prim
:= Node
(Prim_Elmt
);
11085 Next_Elmt
(Prim_Elmt
);
11087 if Is_Non_Overridden_Or_Null_Procedure
(Prim
) then
11088 Hide_Matching_Homographs
11090 Start_Elmt
=> Prim_Elmt
);
11094 end Hide_Non_Overridden_Subprograms
;
11096 ---------------------
11097 -- Local variables --
11098 ---------------------
11100 E
: constant Entity_Id
:= Entity
(N
);
11102 Non_Generic_Case
: constant Boolean := Nkind
(N
) = N_Freeze_Entity
;
11103 -- True in non-generic case. Some of the processing here is skipped
11104 -- for the generic case since it is not needed. Basically in the
11105 -- generic case, we only need to do stuff that might generate error
11106 -- messages or warnings.
11108 -- Start of processing for Freeze_Entity_Checks
11111 -- Remember that we are processing a freezing entity. Required to
11112 -- ensure correct decoration of internal entities associated with
11113 -- interfaces (see New_Overloaded_Entity).
11115 Inside_Freezing_Actions
:= Inside_Freezing_Actions
+ 1;
11117 -- For tagged types covering interfaces add internal entities that link
11118 -- the primitives of the interfaces with the primitives that cover them.
11119 -- Note: These entities were originally generated only when generating
11120 -- code because their main purpose was to provide support to initialize
11121 -- the secondary dispatch tables. They are now generated also when
11122 -- compiling with no code generation to provide ASIS the relationship
11123 -- between interface primitives and tagged type primitives. They are
11124 -- also used to locate primitives covering interfaces when processing
11125 -- generics (see Derive_Subprograms).
11127 -- This is not needed in the generic case
11129 if Ada_Version
>= Ada_2005
11130 and then Non_Generic_Case
11131 and then Ekind
(E
) = E_Record_Type
11132 and then Is_Tagged_Type
(E
)
11133 and then not Is_Interface
(E
)
11134 and then Has_Interfaces
(E
)
11136 -- This would be a good common place to call the routine that checks
11137 -- overriding of interface primitives (and thus factorize calls to
11138 -- Check_Abstract_Overriding located at different contexts in the
11139 -- compiler). However, this is not possible because it causes
11140 -- spurious errors in case of late overriding.
11142 Add_Internal_Interface_Entities
(E
);
11145 -- After all forms of overriding have been resolved, a tagged type may
11146 -- be left with a set of implicitly declared and possibly erroneous
11147 -- abstract subprograms, null procedures and subprograms that require
11148 -- overriding. If this set contains fully conformant homographs, then
11149 -- one is chosen arbitrarily (already done during resolution), otherwise
11150 -- all remaining non-fully conformant homographs are hidden from
11151 -- visibility (Ada RM 8.3 12.3/2).
11153 if Is_Tagged_Type
(E
) then
11154 Hide_Non_Overridden_Subprograms
(E
);
11159 if Ekind
(E
) = E_Record_Type
11160 and then Is_CPP_Class
(E
)
11161 and then Is_Tagged_Type
(E
)
11162 and then Tagged_Type_Expansion
11164 if CPP_Num_Prims
(E
) = 0 then
11166 -- If the CPP type has user defined components then it must import
11167 -- primitives from C++. This is required because if the C++ class
11168 -- has no primitives then the C++ compiler does not added the _tag
11169 -- component to the type.
11171 if First_Entity
(E
) /= Last_Entity
(E
) then
11173 ("'C'P'P type must import at least one primitive from C++??",
11178 -- Check that all its primitives are abstract or imported from C++.
11179 -- Check also availability of the C++ constructor.
11182 Has_Constructors
: constant Boolean := Has_CPP_Constructors
(E
);
11184 Error_Reported
: Boolean := False;
11188 Elmt
:= First_Elmt
(Primitive_Operations
(E
));
11189 while Present
(Elmt
) loop
11190 Prim
:= Node
(Elmt
);
11192 if Comes_From_Source
(Prim
) then
11193 if Is_Abstract_Subprogram
(Prim
) then
11196 elsif not Is_Imported
(Prim
)
11197 or else Convention
(Prim
) /= Convention_CPP
11200 ("primitives of 'C'P'P types must be imported from C++ "
11201 & "or abstract??", Prim
);
11203 elsif not Has_Constructors
11204 and then not Error_Reported
11206 Error_Msg_Name_1
:= Chars
(E
);
11208 ("??'C'P'P constructor required for type %", Prim
);
11209 Error_Reported
:= True;
11218 -- Check Ada derivation of CPP type
11220 if Expander_Active
-- why? losing errors in -gnatc mode???
11221 and then Present
(Etype
(E
)) -- defend against errors
11222 and then Tagged_Type_Expansion
11223 and then Ekind
(E
) = E_Record_Type
11224 and then Etype
(E
) /= E
11225 and then Is_CPP_Class
(Etype
(E
))
11226 and then CPP_Num_Prims
(Etype
(E
)) > 0
11227 and then not Is_CPP_Class
(E
)
11228 and then not Has_CPP_Constructors
(Etype
(E
))
11230 -- If the parent has C++ primitives but it has no constructor then
11231 -- check that all the primitives are overridden in this derivation;
11232 -- otherwise the constructor of the parent is needed to build the
11240 Elmt
:= First_Elmt
(Primitive_Operations
(E
));
11241 while Present
(Elmt
) loop
11242 Prim
:= Node
(Elmt
);
11244 if not Is_Abstract_Subprogram
(Prim
)
11245 and then No
(Interface_Alias
(Prim
))
11246 and then Find_Dispatching_Type
(Ultimate_Alias
(Prim
)) /= E
11248 Error_Msg_Name_1
:= Chars
(Etype
(E
));
11250 ("'C'P'P constructor required for parent type %", E
);
11259 Inside_Freezing_Actions
:= Inside_Freezing_Actions
- 1;
11261 -- If we have a type with predicates, build predicate function. This
11262 -- is not needed in the generic case, and is not needed within TSS
11263 -- subprograms and other predefined primitives.
11265 if Non_Generic_Case
11266 and then Is_Type
(E
)
11267 and then Has_Predicates
(E
)
11268 and then not Within_Internal_Subprogram
11270 Build_Predicate_Functions
(E
, N
);
11273 -- If type has delayed aspects, this is where we do the preanalysis at
11274 -- the freeze point, as part of the consistent visibility check. Note
11275 -- that this must be done after calling Build_Predicate_Functions or
11276 -- Build_Invariant_Procedure since these subprograms fix occurrences of
11277 -- the subtype name in the saved expression so that they will not cause
11278 -- trouble in the preanalysis.
11280 -- This is also not needed in the generic case
11282 if Non_Generic_Case
11283 and then Has_Delayed_Aspects
(E
)
11284 and then Scope
(E
) = Current_Scope
11286 -- Retrieve the visibility to the discriminants in order to properly
11287 -- analyze the aspects.
11289 Push_Scope_And_Install_Discriminants
(E
);
11295 -- Look for aspect specification entries for this entity
11297 Ritem
:= First_Rep_Item
(E
);
11298 while Present
(Ritem
) loop
11299 if Nkind
(Ritem
) = N_Aspect_Specification
11300 and then Entity
(Ritem
) = E
11301 and then Is_Delayed_Aspect
(Ritem
)
11303 Check_Aspect_At_Freeze_Point
(Ritem
);
11306 Next_Rep_Item
(Ritem
);
11310 Uninstall_Discriminants_And_Pop_Scope
(E
);
11313 -- For a record type, deal with variant parts. This has to be delayed
11314 -- to this point, because of the issue of statically predicated
11315 -- subtypes, which we have to ensure are frozen before checking
11316 -- choices, since we need to have the static choice list set.
11318 if Is_Record_Type
(E
) then
11319 Check_Variant_Part
: declare
11320 D
: constant Node_Id
:= Declaration_Node
(E
);
11325 Others_Present
: Boolean;
11326 pragma Warnings
(Off
, Others_Present
);
11327 -- Indicates others present, not used in this case
11329 procedure Non_Static_Choice_Error
(Choice
: Node_Id
);
11330 -- Error routine invoked by the generic instantiation below when
11331 -- the variant part has a non static choice.
11333 procedure Process_Declarations
(Variant
: Node_Id
);
11334 -- Processes declarations associated with a variant. We analyzed
11335 -- the declarations earlier (in Sem_Ch3.Analyze_Variant_Part),
11336 -- but we still need the recursive call to Check_Choices for any
11337 -- nested variant to get its choices properly processed. This is
11338 -- also where we expand out the choices if expansion is active.
11340 package Variant_Choices_Processing
is new
11341 Generic_Check_Choices
11342 (Process_Empty_Choice
=> No_OP
,
11343 Process_Non_Static_Choice
=> Non_Static_Choice_Error
,
11344 Process_Associated_Node
=> Process_Declarations
);
11345 use Variant_Choices_Processing
;
11347 -----------------------------
11348 -- Non_Static_Choice_Error --
11349 -----------------------------
11351 procedure Non_Static_Choice_Error
(Choice
: Node_Id
) is
11353 Flag_Non_Static_Expr
11354 ("choice given in variant part is not static!", Choice
);
11355 end Non_Static_Choice_Error
;
11357 --------------------------
11358 -- Process_Declarations --
11359 --------------------------
11361 procedure Process_Declarations
(Variant
: Node_Id
) is
11362 CL
: constant Node_Id
:= Component_List
(Variant
);
11366 -- Check for static predicate present in this variant
11368 if Has_SP_Choice
(Variant
) then
11370 -- Here we expand. You might expect to find this call in
11371 -- Expand_N_Variant_Part, but that is called when we first
11372 -- see the variant part, and we cannot do this expansion
11373 -- earlier than the freeze point, since for statically
11374 -- predicated subtypes, the predicate is not known till
11375 -- the freeze point.
11377 -- Furthermore, we do this expansion even if the expander
11378 -- is not active, because other semantic processing, e.g.
11379 -- for aggregates, requires the expanded list of choices.
11381 -- If the expander is not active, then we can't just clobber
11382 -- the list since it would invalidate the ASIS -gnatct tree.
11383 -- So we have to rewrite the variant part with a Rewrite
11384 -- call that replaces it with a copy and clobber the copy.
11386 if not Expander_Active
then
11388 NewV
: constant Node_Id
:= New_Copy
(Variant
);
11390 Set_Discrete_Choices
11391 (NewV
, New_Copy_List
(Discrete_Choices
(Variant
)));
11392 Rewrite
(Variant
, NewV
);
11396 Expand_Static_Predicates_In_Choices
(Variant
);
11399 -- We don't need to worry about the declarations in the variant
11400 -- (since they were analyzed by Analyze_Choices when we first
11401 -- encountered the variant), but we do need to take care of
11402 -- expansion of any nested variants.
11404 if not Null_Present
(CL
) then
11405 VP
:= Variant_Part
(CL
);
11407 if Present
(VP
) then
11409 (VP
, Variants
(VP
), Etype
(Name
(VP
)), Others_Present
);
11412 end Process_Declarations
;
11414 -- Start of processing for Check_Variant_Part
11417 -- Find component list
11421 if Nkind
(D
) = N_Full_Type_Declaration
then
11422 T
:= Type_Definition
(D
);
11424 if Nkind
(T
) = N_Record_Definition
then
11425 C
:= Component_List
(T
);
11427 elsif Nkind
(T
) = N_Derived_Type_Definition
11428 and then Present
(Record_Extension_Part
(T
))
11430 C
:= Component_List
(Record_Extension_Part
(T
));
11434 -- Case of variant part present
11436 if Present
(C
) and then Present
(Variant_Part
(C
)) then
11437 VP
:= Variant_Part
(C
);
11442 (VP
, Variants
(VP
), Etype
(Name
(VP
)), Others_Present
);
11444 -- If the last variant does not contain the Others choice,
11445 -- replace it with an N_Others_Choice node since Gigi always
11446 -- wants an Others. Note that we do not bother to call Analyze
11447 -- on the modified variant part, since its only effect would be
11448 -- to compute the Others_Discrete_Choices node laboriously, and
11449 -- of course we already know the list of choices corresponding
11450 -- to the others choice (it's the list we're replacing).
11452 -- We only want to do this if the expander is active, since
11453 -- we do not want to clobber the ASIS tree.
11455 if Expander_Active
then
11457 Last_Var
: constant Node_Id
:=
11458 Last_Non_Pragma
(Variants
(VP
));
11460 Others_Node
: Node_Id
;
11463 if Nkind
(First
(Discrete_Choices
(Last_Var
))) /=
11466 Others_Node
:= Make_Others_Choice
(Sloc
(Last_Var
));
11467 Set_Others_Discrete_Choices
11468 (Others_Node
, Discrete_Choices
(Last_Var
));
11469 Set_Discrete_Choices
11470 (Last_Var
, New_List
(Others_Node
));
11475 end Check_Variant_Part
;
11477 end Freeze_Entity_Checks
;
11479 -------------------------
11480 -- Get_Alignment_Value --
11481 -------------------------
11483 function Get_Alignment_Value
(Expr
: Node_Id
) return Uint
is
11484 Align
: constant Uint
:= Static_Integer
(Expr
);
11487 if Align
= No_Uint
then
11490 elsif Align
<= 0 then
11491 Error_Msg_N
("alignment value must be positive", Expr
);
11495 for J
in Int
range 0 .. 64 loop
11497 M
: constant Uint
:= Uint_2
** J
;
11500 exit when M
= Align
;
11504 ("alignment value must be power of 2", Expr
);
11512 end Get_Alignment_Value
;
11514 -----------------------------
11515 -- Get_Interfacing_Aspects --
11516 -----------------------------
11518 procedure Get_Interfacing_Aspects
11519 (Iface_Asp
: Node_Id
;
11520 Conv_Asp
: out Node_Id
;
11521 EN_Asp
: out Node_Id
;
11522 Expo_Asp
: out Node_Id
;
11523 Imp_Asp
: out Node_Id
;
11524 LN_Asp
: out Node_Id
;
11525 Do_Checks
: Boolean := False)
11527 procedure Save_Or_Duplication_Error
11529 To
: in out Node_Id
);
11530 -- Save the value of aspect Asp in node To. If To already has a value,
11531 -- then this is considered a duplicate use of aspect. Emit an error if
11532 -- flag Do_Checks is set.
11534 -------------------------------
11535 -- Save_Or_Duplication_Error --
11536 -------------------------------
11538 procedure Save_Or_Duplication_Error
11540 To
: in out Node_Id
)
11543 -- Detect an extra aspect and issue an error
11545 if Present
(To
) then
11547 Error_Msg_Name_1
:= Chars
(Identifier
(Asp
));
11548 Error_Msg_Sloc
:= Sloc
(To
);
11549 Error_Msg_N
("aspect % previously given #", Asp
);
11552 -- Otherwise capture the aspect
11557 end Save_Or_Duplication_Error
;
11562 Asp_Id
: Aspect_Id
;
11564 -- The following variables capture each individual aspect
11566 Conv
: Node_Id
:= Empty
;
11567 EN
: Node_Id
:= Empty
;
11568 Expo
: Node_Id
:= Empty
;
11569 Imp
: Node_Id
:= Empty
;
11570 LN
: Node_Id
:= Empty
;
11572 -- Start of processing for Get_Interfacing_Aspects
11575 -- The input interfacing aspect should reside in an aspect specification
11578 pragma Assert
(Is_List_Member
(Iface_Asp
));
11580 -- Examine the aspect specifications of the related entity. Find and
11581 -- capture all interfacing aspects. Detect duplicates and emit errors
11584 Asp
:= First
(List_Containing
(Iface_Asp
));
11585 while Present
(Asp
) loop
11586 Asp_Id
:= Get_Aspect_Id
(Asp
);
11588 if Asp_Id
= Aspect_Convention
then
11589 Save_Or_Duplication_Error
(Asp
, Conv
);
11591 elsif Asp_Id
= Aspect_External_Name
then
11592 Save_Or_Duplication_Error
(Asp
, EN
);
11594 elsif Asp_Id
= Aspect_Export
then
11595 Save_Or_Duplication_Error
(Asp
, Expo
);
11597 elsif Asp_Id
= Aspect_Import
then
11598 Save_Or_Duplication_Error
(Asp
, Imp
);
11600 elsif Asp_Id
= Aspect_Link_Name
then
11601 Save_Or_Duplication_Error
(Asp
, LN
);
11612 end Get_Interfacing_Aspects
;
11614 -------------------------------------
11615 -- Inherit_Aspects_At_Freeze_Point --
11616 -------------------------------------
11618 procedure Inherit_Aspects_At_Freeze_Point
(Typ
: Entity_Id
) is
11619 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11620 (Rep_Item
: Node_Id
) return Boolean;
11621 -- This routine checks if Rep_Item is either a pragma or an aspect
11622 -- specification node whose correponding pragma (if any) is present in
11623 -- the Rep Item chain of the entity it has been specified to.
11625 --------------------------------------------------
11626 -- Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item --
11627 --------------------------------------------------
11629 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11630 (Rep_Item
: Node_Id
) return Boolean
11634 Nkind
(Rep_Item
) = N_Pragma
11635 or else Present_In_Rep_Item
11636 (Entity
(Rep_Item
), Aspect_Rep_Item
(Rep_Item
));
11637 end Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
;
11639 -- Start of processing for Inherit_Aspects_At_Freeze_Point
11642 -- A representation item is either subtype-specific (Size and Alignment
11643 -- clauses) or type-related (all others). Subtype-specific aspects may
11644 -- differ for different subtypes of the same type (RM 13.1.8).
11646 -- A derived type inherits each type-related representation aspect of
11647 -- its parent type that was directly specified before the declaration of
11648 -- the derived type (RM 13.1.15).
11650 -- A derived subtype inherits each subtype-specific representation
11651 -- aspect of its parent subtype that was directly specified before the
11652 -- declaration of the derived type (RM 13.1.15).
11654 -- The general processing involves inheriting a representation aspect
11655 -- from a parent type whenever the first rep item (aspect specification,
11656 -- attribute definition clause, pragma) corresponding to the given
11657 -- representation aspect in the rep item chain of Typ, if any, isn't
11658 -- directly specified to Typ but to one of its parents.
11660 -- ??? Note that, for now, just a limited number of representation
11661 -- aspects have been inherited here so far. Many of them are
11662 -- still inherited in Sem_Ch3. This will be fixed soon. Here is
11663 -- a non- exhaustive list of aspects that likely also need to
11664 -- be moved to this routine: Alignment, Component_Alignment,
11665 -- Component_Size, Machine_Radix, Object_Size, Pack, Predicates,
11666 -- Preelaborable_Initialization, RM_Size and Small.
11668 -- In addition, Convention must be propagated from base type to subtype,
11669 -- because the subtype may have been declared on an incomplete view.
11671 if Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
then
11677 if not Has_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
, False)
11678 and then Has_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
)
11679 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11680 (Get_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
))
11682 Set_Is_Ada_2005_Only
(Typ
);
11687 if not Has_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
, False)
11688 and then Has_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
)
11689 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11690 (Get_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
))
11692 Set_Is_Ada_2012_Only
(Typ
);
11697 if not Has_Rep_Item
(Typ
, Name_Atomic
, Name_Shared
, False)
11698 and then Has_Rep_Pragma
(Typ
, Name_Atomic
, Name_Shared
)
11699 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11700 (Get_Rep_Item
(Typ
, Name_Atomic
, Name_Shared
))
11702 Set_Is_Atomic
(Typ
);
11703 Set_Is_Volatile
(Typ
);
11704 Set_Treat_As_Volatile
(Typ
);
11709 if Is_Record_Type
(Typ
)
11710 and then Typ
/= Base_Type
(Typ
) and then Is_Frozen
(Base_Type
(Typ
))
11712 Set_Convention
(Typ
, Convention
(Base_Type
(Typ
)));
11715 -- Default_Component_Value
11717 -- Verify that there is no rep_item declared for the type, and there
11718 -- is one coming from an ancestor.
11720 if Is_Array_Type
(Typ
)
11721 and then Is_Base_Type
(Typ
)
11722 and then not Has_Rep_Item
(Typ
, Name_Default_Component_Value
, False)
11723 and then Has_Rep_Item
(Typ
, Name_Default_Component_Value
)
11725 Set_Default_Aspect_Component_Value
(Typ
,
11726 Default_Aspect_Component_Value
11727 (Entity
(Get_Rep_Item
(Typ
, Name_Default_Component_Value
))));
11732 if Is_Scalar_Type
(Typ
)
11733 and then Is_Base_Type
(Typ
)
11734 and then not Has_Rep_Item
(Typ
, Name_Default_Value
, False)
11735 and then Has_Rep_Item
(Typ
, Name_Default_Value
)
11737 Set_Has_Default_Aspect
(Typ
);
11738 Set_Default_Aspect_Value
(Typ
,
11739 Default_Aspect_Value
11740 (Entity
(Get_Rep_Item
(Typ
, Name_Default_Value
))));
11745 if not Has_Rep_Item
(Typ
, Name_Discard_Names
, False)
11746 and then Has_Rep_Item
(Typ
, Name_Discard_Names
)
11747 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11748 (Get_Rep_Item
(Typ
, Name_Discard_Names
))
11750 Set_Discard_Names
(Typ
);
11755 if not Has_Rep_Item
(Typ
, Name_Invariant
, False)
11756 and then Has_Rep_Item
(Typ
, Name_Invariant
)
11757 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11758 (Get_Rep_Item
(Typ
, Name_Invariant
))
11760 Set_Has_Invariants
(Typ
);
11762 if Class_Present
(Get_Rep_Item
(Typ
, Name_Invariant
)) then
11763 Set_Has_Inheritable_Invariants
(Typ
);
11766 -- If we have a subtype with invariants, whose base type does not have
11767 -- invariants, copy these invariants to the base type. This happens for
11768 -- the case of implicit base types created for scalar and array types.
11770 elsif Has_Invariants
(Typ
)
11771 and then not Has_Invariants
(Base_Type
(Typ
))
11773 Set_Has_Invariants
(Base_Type
(Typ
));
11774 Set_Invariant_Procedure
(Base_Type
(Typ
), Invariant_Procedure
(Typ
));
11779 if not Has_Rep_Item
(Typ
, Name_Volatile
, False)
11780 and then Has_Rep_Item
(Typ
, Name_Volatile
)
11781 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11782 (Get_Rep_Item
(Typ
, Name_Volatile
))
11784 Set_Is_Volatile
(Typ
);
11785 Set_Treat_As_Volatile
(Typ
);
11788 -- Volatile_Full_Access
11790 if not Has_Rep_Item
(Typ
, Name_Volatile_Full_Access
, False)
11791 and then Has_Rep_Pragma
(Typ
, Name_Volatile_Full_Access
)
11792 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11793 (Get_Rep_Item
(Typ
, Name_Volatile_Full_Access
))
11795 Set_Is_Volatile_Full_Access
(Typ
);
11796 Set_Is_Volatile
(Typ
);
11797 Set_Treat_As_Volatile
(Typ
);
11800 -- Inheritance for derived types only
11802 if Is_Derived_Type
(Typ
) then
11804 Bas_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
11805 Imp_Bas_Typ
: constant Entity_Id
:= Implementation_Base_Type
(Typ
);
11808 -- Atomic_Components
11810 if not Has_Rep_Item
(Typ
, Name_Atomic_Components
, False)
11811 and then Has_Rep_Item
(Typ
, Name_Atomic_Components
)
11812 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11813 (Get_Rep_Item
(Typ
, Name_Atomic_Components
))
11815 Set_Has_Atomic_Components
(Imp_Bas_Typ
);
11818 -- Volatile_Components
11820 if not Has_Rep_Item
(Typ
, Name_Volatile_Components
, False)
11821 and then Has_Rep_Item
(Typ
, Name_Volatile_Components
)
11822 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11823 (Get_Rep_Item
(Typ
, Name_Volatile_Components
))
11825 Set_Has_Volatile_Components
(Imp_Bas_Typ
);
11828 -- Finalize_Storage_Only
11830 if not Has_Rep_Pragma
(Typ
, Name_Finalize_Storage_Only
, False)
11831 and then Has_Rep_Pragma
(Typ
, Name_Finalize_Storage_Only
)
11833 Set_Finalize_Storage_Only
(Bas_Typ
);
11836 -- Universal_Aliasing
11838 if not Has_Rep_Item
(Typ
, Name_Universal_Aliasing
, False)
11839 and then Has_Rep_Item
(Typ
, Name_Universal_Aliasing
)
11840 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11841 (Get_Rep_Item
(Typ
, Name_Universal_Aliasing
))
11843 Set_Universal_Aliasing
(Imp_Bas_Typ
);
11848 if Is_Record_Type
(Typ
) then
11849 if not Has_Rep_Item
(Typ
, Name_Bit_Order
, False)
11850 and then Has_Rep_Item
(Typ
, Name_Bit_Order
)
11852 Set_Reverse_Bit_Order
(Bas_Typ
,
11853 Reverse_Bit_Order
(Entity
(Name
11854 (Get_Rep_Item
(Typ
, Name_Bit_Order
)))));
11858 -- Scalar_Storage_Order
11860 -- Note: the aspect is specified on a first subtype, but recorded
11861 -- in a flag of the base type!
11863 if (Is_Record_Type
(Typ
) or else Is_Array_Type
(Typ
))
11864 and then Typ
= Bas_Typ
11866 -- For a type extension, always inherit from parent; otherwise
11867 -- inherit if no default applies. Note: we do not check for
11868 -- an explicit rep item on the parent type when inheriting,
11869 -- because the parent SSO may itself have been set by default.
11871 if not Has_Rep_Item
(First_Subtype
(Typ
),
11872 Name_Scalar_Storage_Order
, False)
11873 and then (Is_Tagged_Type
(Bas_Typ
)
11874 or else not (SSO_Set_Low_By_Default
(Bas_Typ
)
11876 SSO_Set_High_By_Default
(Bas_Typ
)))
11878 Set_Reverse_Storage_Order
(Bas_Typ
,
11879 Reverse_Storage_Order
11880 (Implementation_Base_Type
(Etype
(Bas_Typ
))));
11882 -- Clear default SSO indications, since the inherited aspect
11883 -- which was set explicitly overrides the default.
11885 Set_SSO_Set_Low_By_Default
(Bas_Typ
, False);
11886 Set_SSO_Set_High_By_Default
(Bas_Typ
, False);
11891 end Inherit_Aspects_At_Freeze_Point
;
11897 procedure Initialize
is
11899 Address_Clause_Checks
.Init
;
11900 Unchecked_Conversions
.Init
;
11902 if AAMP_On_Target
then
11903 Independence_Checks
.Init
;
11907 ---------------------------
11908 -- Install_Discriminants --
11909 ---------------------------
11911 procedure Install_Discriminants
(E
: Entity_Id
) is
11915 Disc
:= First_Discriminant
(E
);
11916 while Present
(Disc
) loop
11917 Prev
:= Current_Entity
(Disc
);
11918 Set_Current_Entity
(Disc
);
11919 Set_Is_Immediately_Visible
(Disc
);
11920 Set_Homonym
(Disc
, Prev
);
11921 Next_Discriminant
(Disc
);
11923 end Install_Discriminants
;
11925 -------------------------
11926 -- Is_Operational_Item --
11927 -------------------------
11929 function Is_Operational_Item
(N
: Node_Id
) return Boolean is
11931 if Nkind
(N
) /= N_Attribute_Definition_Clause
then
11936 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Chars
(N
));
11939 -- List of operational items is given in AARM 13.1(8.mm/1).
11940 -- It is clearly incomplete, as it does not include iterator
11941 -- aspects, among others.
11943 return Id
= Attribute_Constant_Indexing
11944 or else Id
= Attribute_Default_Iterator
11945 or else Id
= Attribute_Implicit_Dereference
11946 or else Id
= Attribute_Input
11947 or else Id
= Attribute_Iterator_Element
11948 or else Id
= Attribute_Iterable
11949 or else Id
= Attribute_Output
11950 or else Id
= Attribute_Read
11951 or else Id
= Attribute_Variable_Indexing
11952 or else Id
= Attribute_Write
11953 or else Id
= Attribute_External_Tag
;
11956 end Is_Operational_Item
;
11958 -------------------------
11959 -- Is_Predicate_Static --
11960 -------------------------
11962 -- Note: the basic legality of the expression has already been checked, so
11963 -- we don't need to worry about cases or ranges on strings for example.
11965 function Is_Predicate_Static
11967 Nam
: Name_Id
) return Boolean
11969 function All_Static_Case_Alternatives
(L
: List_Id
) return Boolean;
11970 -- Given a list of case expression alternatives, returns True if all
11971 -- the alternatives are static (have all static choices, and a static
11974 function All_Static_Choices
(L
: List_Id
) return Boolean;
11975 -- Returns true if all elements of the list are OK static choices
11976 -- as defined below for Is_Static_Choice. Used for case expression
11977 -- alternatives and for the right operand of a membership test. An
11978 -- others_choice is static if the corresponding expression is static.
11979 -- The staticness of the bounds is checked separately.
11981 function Is_Static_Choice
(N
: Node_Id
) return Boolean;
11982 -- Returns True if N represents a static choice (static subtype, or
11983 -- static subtype indication, or static expression, or static range).
11985 -- Note that this is a bit more inclusive than we actually need
11986 -- (in particular membership tests do not allow the use of subtype
11987 -- indications). But that doesn't matter, we have already checked
11988 -- that the construct is legal to get this far.
11990 function Is_Type_Ref
(N
: Node_Id
) return Boolean;
11991 pragma Inline
(Is_Type_Ref
);
11992 -- Returns True if N is a reference to the type for the predicate in the
11993 -- expression (i.e. if it is an identifier whose Chars field matches the
11994 -- Nam given in the call). N must not be parenthesized, if the type name
11995 -- appears in parens, this routine will return False.
11997 ----------------------------------
11998 -- All_Static_Case_Alternatives --
11999 ----------------------------------
12001 function All_Static_Case_Alternatives
(L
: List_Id
) return Boolean is
12006 while Present
(N
) loop
12007 if not (All_Static_Choices
(Discrete_Choices
(N
))
12008 and then Is_OK_Static_Expression
(Expression
(N
)))
12017 end All_Static_Case_Alternatives
;
12019 ------------------------
12020 -- All_Static_Choices --
12021 ------------------------
12023 function All_Static_Choices
(L
: List_Id
) return Boolean is
12028 while Present
(N
) loop
12029 if not Is_Static_Choice
(N
) then
12037 end All_Static_Choices
;
12039 ----------------------
12040 -- Is_Static_Choice --
12041 ----------------------
12043 function Is_Static_Choice
(N
: Node_Id
) return Boolean is
12045 return Nkind
(N
) = N_Others_Choice
12046 or else Is_OK_Static_Expression
(N
)
12047 or else (Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
))
12048 and then Is_OK_Static_Subtype
(Entity
(N
)))
12049 or else (Nkind
(N
) = N_Subtype_Indication
12050 and then Is_OK_Static_Subtype
(Entity
(N
)))
12051 or else (Nkind
(N
) = N_Range
and then Is_OK_Static_Range
(N
));
12052 end Is_Static_Choice
;
12058 function Is_Type_Ref
(N
: Node_Id
) return Boolean is
12060 return Nkind
(N
) = N_Identifier
12061 and then Chars
(N
) = Nam
12062 and then Paren_Count
(N
) = 0;
12065 -- Start of processing for Is_Predicate_Static
12068 -- Predicate_Static means one of the following holds. Numbers are the
12069 -- corresponding paragraph numbers in (RM 3.2.4(16-22)).
12071 -- 16: A static expression
12073 if Is_OK_Static_Expression
(Expr
) then
12076 -- 17: A membership test whose simple_expression is the current
12077 -- instance, and whose membership_choice_list meets the requirements
12078 -- for a static membership test.
12080 elsif Nkind
(Expr
) in N_Membership_Test
12081 and then ((Present
(Right_Opnd
(Expr
))
12082 and then Is_Static_Choice
(Right_Opnd
(Expr
)))
12084 (Present
(Alternatives
(Expr
))
12085 and then All_Static_Choices
(Alternatives
(Expr
))))
12089 -- 18. A case_expression whose selecting_expression is the current
12090 -- instance, and whose dependent expressions are static expressions.
12092 elsif Nkind
(Expr
) = N_Case_Expression
12093 and then Is_Type_Ref
(Expression
(Expr
))
12094 and then All_Static_Case_Alternatives
(Alternatives
(Expr
))
12098 -- 19. A call to a predefined equality or ordering operator, where one
12099 -- operand is the current instance, and the other is a static
12102 -- Note: the RM is clearly wrong here in not excluding string types.
12103 -- Without this exclusion, we would allow expressions like X > "ABC"
12104 -- to be considered as predicate-static, which is clearly not intended,
12105 -- since the idea is for predicate-static to be a subset of normal
12106 -- static expressions (and "DEF" > "ABC" is not a static expression).
12108 -- However, we do allow internally generated (not from source) equality
12109 -- and inequality operations to be valid on strings (this helps deal
12110 -- with cases where we transform A in "ABC" to A = "ABC).
12112 elsif Nkind
(Expr
) in N_Op_Compare
12113 and then ((not Is_String_Type
(Etype
(Left_Opnd
(Expr
))))
12114 or else (Nkind_In
(Expr
, N_Op_Eq
, N_Op_Ne
)
12115 and then not Comes_From_Source
(Expr
)))
12116 and then ((Is_Type_Ref
(Left_Opnd
(Expr
))
12117 and then Is_OK_Static_Expression
(Right_Opnd
(Expr
)))
12119 (Is_Type_Ref
(Right_Opnd
(Expr
))
12120 and then Is_OK_Static_Expression
(Left_Opnd
(Expr
))))
12124 -- 20. A call to a predefined boolean logical operator, where each
12125 -- operand is predicate-static.
12127 elsif (Nkind_In
(Expr
, N_Op_And
, N_Op_Or
, N_Op_Xor
)
12128 and then Is_Predicate_Static
(Left_Opnd
(Expr
), Nam
)
12129 and then Is_Predicate_Static
(Right_Opnd
(Expr
), Nam
))
12131 (Nkind
(Expr
) = N_Op_Not
12132 and then Is_Predicate_Static
(Right_Opnd
(Expr
), Nam
))
12136 -- 21. A short-circuit control form where both operands are
12137 -- predicate-static.
12139 elsif Nkind
(Expr
) in N_Short_Circuit
12140 and then Is_Predicate_Static
(Left_Opnd
(Expr
), Nam
)
12141 and then Is_Predicate_Static
(Right_Opnd
(Expr
), Nam
)
12145 -- 22. A parenthesized predicate-static expression. This does not
12146 -- require any special test, since we just ignore paren levels in
12147 -- all the cases above.
12149 -- One more test that is an implementation artifact caused by the fact
12150 -- that we are analyzing not the original expression, but the generated
12151 -- expression in the body of the predicate function. This can include
12152 -- references to inherited predicates, so that the expression we are
12153 -- processing looks like:
12155 -- xxPredicate (typ (Inns)) and then expression
12157 -- Where the call is to a Predicate function for an inherited predicate.
12158 -- We simply ignore such a call, which could be to either a dynamic or
12159 -- a static predicate. Note that if the parent predicate is dynamic then
12160 -- eventually this type will be marked as dynamic, but you are allowed
12161 -- to specify a static predicate for a subtype which is inheriting a
12162 -- dynamic predicate, so the static predicate validation here ignores
12163 -- the inherited predicate even if it is dynamic.
12165 elsif Nkind
(Expr
) = N_Function_Call
12166 and then Is_Predicate_Function
(Entity
(Name
(Expr
)))
12170 -- That's an exhaustive list of tests, all other cases are not
12171 -- predicate-static, so we return False.
12176 end Is_Predicate_Static
;
12178 ---------------------
12179 -- Kill_Rep_Clause --
12180 ---------------------
12182 procedure Kill_Rep_Clause
(N
: Node_Id
) is
12184 pragma Assert
(Ignore_Rep_Clauses
);
12186 -- Note: we use Replace rather than Rewrite, because we don't want
12187 -- ASIS to be able to use Original_Node to dig out the (undecorated)
12188 -- rep clause that is being replaced.
12190 Replace
(N
, Make_Null_Statement
(Sloc
(N
)));
12192 -- The null statement must be marked as not coming from source. This is
12193 -- so that ASIS ignores it, and also the back end does not expect bogus
12194 -- "from source" null statements in weird places (e.g. in declarative
12195 -- regions where such null statements are not allowed).
12197 Set_Comes_From_Source
(N
, False);
12198 end Kill_Rep_Clause
;
12204 function Minimum_Size
12206 Biased
: Boolean := False) return Nat
12208 Lo
: Uint
:= No_Uint
;
12209 Hi
: Uint
:= No_Uint
;
12210 LoR
: Ureal
:= No_Ureal
;
12211 HiR
: Ureal
:= No_Ureal
;
12212 LoSet
: Boolean := False;
12213 HiSet
: Boolean := False;
12216 Ancest
: Entity_Id
;
12217 R_Typ
: constant Entity_Id
:= Root_Type
(T
);
12220 -- If bad type, return 0
12222 if T
= Any_Type
then
12225 -- For generic types, just return zero. There cannot be any legitimate
12226 -- need to know such a size, but this routine may be called with a
12227 -- generic type as part of normal processing.
12229 elsif Is_Generic_Type
(R_Typ
) or else R_Typ
= Any_Type
then
12232 -- Access types (cannot have size smaller than System.Address)
12234 elsif Is_Access_Type
(T
) then
12235 return System_Address_Size
;
12237 -- Floating-point types
12239 elsif Is_Floating_Point_Type
(T
) then
12240 return UI_To_Int
(Esize
(R_Typ
));
12244 elsif Is_Discrete_Type
(T
) then
12246 -- The following loop is looking for the nearest compile time known
12247 -- bounds following the ancestor subtype chain. The idea is to find
12248 -- the most restrictive known bounds information.
12252 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
12257 if Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
)) then
12258 Lo
:= Expr_Rep_Value
(Type_Low_Bound
(Ancest
));
12265 if Compile_Time_Known_Value
(Type_High_Bound
(Ancest
)) then
12266 Hi
:= Expr_Rep_Value
(Type_High_Bound
(Ancest
));
12272 Ancest
:= Ancestor_Subtype
(Ancest
);
12274 if No
(Ancest
) then
12275 Ancest
:= Base_Type
(T
);
12277 if Is_Generic_Type
(Ancest
) then
12283 -- Fixed-point types. We can't simply use Expr_Value to get the
12284 -- Corresponding_Integer_Value values of the bounds, since these do not
12285 -- get set till the type is frozen, and this routine can be called
12286 -- before the type is frozen. Similarly the test for bounds being static
12287 -- needs to include the case where we have unanalyzed real literals for
12288 -- the same reason.
12290 elsif Is_Fixed_Point_Type
(T
) then
12292 -- The following loop is looking for the nearest compile time known
12293 -- bounds following the ancestor subtype chain. The idea is to find
12294 -- the most restrictive known bounds information.
12298 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
12302 -- Note: In the following two tests for LoSet and HiSet, it may
12303 -- seem redundant to test for N_Real_Literal here since normally
12304 -- one would assume that the test for the value being known at
12305 -- compile time includes this case. However, there is a glitch.
12306 -- If the real literal comes from folding a non-static expression,
12307 -- then we don't consider any non- static expression to be known
12308 -- at compile time if we are in configurable run time mode (needed
12309 -- in some cases to give a clearer definition of what is and what
12310 -- is not accepted). So the test is indeed needed. Without it, we
12311 -- would set neither Lo_Set nor Hi_Set and get an infinite loop.
12314 if Nkind
(Type_Low_Bound
(Ancest
)) = N_Real_Literal
12315 or else Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
))
12317 LoR
:= Expr_Value_R
(Type_Low_Bound
(Ancest
));
12324 if Nkind
(Type_High_Bound
(Ancest
)) = N_Real_Literal
12325 or else Compile_Time_Known_Value
(Type_High_Bound
(Ancest
))
12327 HiR
:= Expr_Value_R
(Type_High_Bound
(Ancest
));
12333 Ancest
:= Ancestor_Subtype
(Ancest
);
12335 if No
(Ancest
) then
12336 Ancest
:= Base_Type
(T
);
12338 if Is_Generic_Type
(Ancest
) then
12344 Lo
:= UR_To_Uint
(LoR
/ Small_Value
(T
));
12345 Hi
:= UR_To_Uint
(HiR
/ Small_Value
(T
));
12347 -- No other types allowed
12350 raise Program_Error
;
12353 -- Fall through with Hi and Lo set. Deal with biased case
12356 and then not Is_Fixed_Point_Type
(T
)
12357 and then not (Is_Enumeration_Type
(T
)
12358 and then Has_Non_Standard_Rep
(T
)))
12359 or else Has_Biased_Representation
(T
)
12365 -- Null range case, size is always zero. We only do this in the discrete
12366 -- type case, since that's the odd case that came up. Probably we should
12367 -- also do this in the fixed-point case, but doing so causes peculiar
12368 -- gigi failures, and it is not worth worrying about this incredibly
12369 -- marginal case (explicit null-range fixed-point type declarations)???
12371 if Lo
> Hi
and then Is_Discrete_Type
(T
) then
12374 -- Signed case. Note that we consider types like range 1 .. -1 to be
12375 -- signed for the purpose of computing the size, since the bounds have
12376 -- to be accommodated in the base type.
12378 elsif Lo
< 0 or else Hi
< 0 then
12382 -- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1))
12383 -- Note that we accommodate the case where the bounds cross. This
12384 -- can happen either because of the way the bounds are declared
12385 -- or because of the algorithm in Freeze_Fixed_Point_Type.
12399 -- If both bounds are positive, make sure that both are represen-
12400 -- table in the case where the bounds are crossed. This can happen
12401 -- either because of the way the bounds are declared, or because of
12402 -- the algorithm in Freeze_Fixed_Point_Type.
12408 -- S = size, (can accommodate 0 .. (2**size - 1))
12411 while Hi
>= Uint_2
** S
loop
12419 ---------------------------
12420 -- New_Stream_Subprogram --
12421 ---------------------------
12423 procedure New_Stream_Subprogram
12427 Nam
: TSS_Name_Type
)
12429 Loc
: constant Source_Ptr
:= Sloc
(N
);
12430 Sname
: constant Name_Id
:= Make_TSS_Name
(Base_Type
(Ent
), Nam
);
12431 Subp_Id
: Entity_Id
;
12432 Subp_Decl
: Node_Id
;
12436 Defer_Declaration
: constant Boolean :=
12437 Is_Tagged_Type
(Ent
) or else Is_Private_Type
(Ent
);
12438 -- For a tagged type, there is a declaration for each stream attribute
12439 -- at the freeze point, and we must generate only a completion of this
12440 -- declaration. We do the same for private types, because the full view
12441 -- might be tagged. Otherwise we generate a declaration at the point of
12442 -- the attribute definition clause.
12444 function Build_Spec
return Node_Id
;
12445 -- Used for declaration and renaming declaration, so that this is
12446 -- treated as a renaming_as_body.
12452 function Build_Spec
return Node_Id
is
12453 Out_P
: constant Boolean := (Nam
= TSS_Stream_Read
);
12456 T_Ref
: constant Node_Id
:= New_Occurrence_Of
(Etyp
, Loc
);
12459 Subp_Id
:= Make_Defining_Identifier
(Loc
, Sname
);
12461 -- S : access Root_Stream_Type'Class
12463 Formals
:= New_List
(
12464 Make_Parameter_Specification
(Loc
,
12465 Defining_Identifier
=>
12466 Make_Defining_Identifier
(Loc
, Name_S
),
12468 Make_Access_Definition
(Loc
,
12470 New_Occurrence_Of
(
12471 Designated_Type
(Etype
(F
)), Loc
))));
12473 if Nam
= TSS_Stream_Input
then
12475 Make_Function_Specification
(Loc
,
12476 Defining_Unit_Name
=> Subp_Id
,
12477 Parameter_Specifications
=> Formals
,
12478 Result_Definition
=> T_Ref
);
12482 Append_To
(Formals
,
12483 Make_Parameter_Specification
(Loc
,
12484 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_V
),
12485 Out_Present
=> Out_P
,
12486 Parameter_Type
=> T_Ref
));
12489 Make_Procedure_Specification
(Loc
,
12490 Defining_Unit_Name
=> Subp_Id
,
12491 Parameter_Specifications
=> Formals
);
12497 -- Start of processing for New_Stream_Subprogram
12500 F
:= First_Formal
(Subp
);
12502 if Ekind
(Subp
) = E_Procedure
then
12503 Etyp
:= Etype
(Next_Formal
(F
));
12505 Etyp
:= Etype
(Subp
);
12508 -- Prepare subprogram declaration and insert it as an action on the
12509 -- clause node. The visibility for this entity is used to test for
12510 -- visibility of the attribute definition clause (in the sense of
12511 -- 8.3(23) as amended by AI-195).
12513 if not Defer_Declaration
then
12515 Make_Subprogram_Declaration
(Loc
,
12516 Specification
=> Build_Spec
);
12518 -- For a tagged type, there is always a visible declaration for each
12519 -- stream TSS (it is a predefined primitive operation), and the
12520 -- completion of this declaration occurs at the freeze point, which is
12521 -- not always visible at places where the attribute definition clause is
12522 -- visible. So, we create a dummy entity here for the purpose of
12523 -- tracking the visibility of the attribute definition clause itself.
12527 Make_Defining_Identifier
(Loc
, New_External_Name
(Sname
, 'V'));
12529 Make_Object_Declaration
(Loc
,
12530 Defining_Identifier
=> Subp_Id
,
12531 Object_Definition
=> New_Occurrence_Of
(Standard_Boolean
, Loc
));
12534 Insert_Action
(N
, Subp_Decl
);
12535 Set_Entity
(N
, Subp_Id
);
12538 Make_Subprogram_Renaming_Declaration
(Loc
,
12539 Specification
=> Build_Spec
,
12540 Name
=> New_Occurrence_Of
(Subp
, Loc
));
12542 if Defer_Declaration
then
12543 Set_TSS
(Base_Type
(Ent
), Subp_Id
);
12545 Insert_Action
(N
, Subp_Decl
);
12546 Copy_TSS
(Subp_Id
, Base_Type
(Ent
));
12548 end New_Stream_Subprogram
;
12550 ------------------------------------------
12551 -- Push_Scope_And_Install_Discriminants --
12552 ------------------------------------------
12554 procedure Push_Scope_And_Install_Discriminants
(E
: Entity_Id
) is
12556 if Has_Discriminants
(E
) then
12559 -- Make discriminants visible for type declarations and protected
12560 -- type declarations, not for subtype declarations (RM 13.1.1 (12/3))
12562 if Nkind
(Parent
(E
)) /= N_Subtype_Declaration
then
12563 Install_Discriminants
(E
);
12566 end Push_Scope_And_Install_Discriminants
;
12568 ------------------------
12569 -- Rep_Item_Too_Early --
12570 ------------------------
12572 function Rep_Item_Too_Early
(T
: Entity_Id
; N
: Node_Id
) return Boolean is
12574 -- Cannot apply non-operational rep items to generic types
12576 if Is_Operational_Item
(N
) then
12580 and then Is_Generic_Type
(Root_Type
(T
))
12581 and then (Nkind
(N
) /= N_Pragma
12582 or else Get_Pragma_Id
(N
) /= Pragma_Convention
)
12584 Error_Msg_N
("representation item not allowed for generic type", N
);
12588 -- Otherwise check for incomplete type
12590 if Is_Incomplete_Or_Private_Type
(T
)
12591 and then No
(Underlying_Type
(T
))
12593 (Nkind
(N
) /= N_Pragma
12594 or else Get_Pragma_Id
(N
) /= Pragma_Import
)
12597 ("representation item must be after full type declaration", N
);
12600 -- If the type has incomplete components, a representation clause is
12601 -- illegal but stream attributes and Convention pragmas are correct.
12603 elsif Has_Private_Component
(T
) then
12604 if Nkind
(N
) = N_Pragma
then
12609 ("representation item must appear after type is fully defined",
12616 end Rep_Item_Too_Early
;
12618 -----------------------
12619 -- Rep_Item_Too_Late --
12620 -----------------------
12622 function Rep_Item_Too_Late
12625 FOnly
: Boolean := False) return Boolean
12628 Parent_Type
: Entity_Id
;
12630 procedure No_Type_Rep_Item
;
12631 -- Output message indicating that no type-related aspects can be
12632 -- specified due to some property of the parent type.
12634 procedure Too_Late
;
12635 -- Output message for an aspect being specified too late
12637 -- Note that neither of the above errors is considered a serious one,
12638 -- since the effect is simply that we ignore the representation clause
12640 -- Is this really true? In any case if we make this change we must
12641 -- document the requirement in the spec of Rep_Item_Too_Late that
12642 -- if True is returned, then the rep item must be completely ignored???
12644 ----------------------
12645 -- No_Type_Rep_Item --
12646 ----------------------
12648 procedure No_Type_Rep_Item
is
12650 Error_Msg_N
("|type-related representation item not permitted!", N
);
12651 end No_Type_Rep_Item
;
12657 procedure Too_Late
is
12659 -- Other compilers seem more relaxed about rep items appearing too
12660 -- late. Since analysis tools typically don't care about rep items
12661 -- anyway, no reason to be too strict about this.
12663 if not Relaxed_RM_Semantics
then
12664 Error_Msg_N
("|representation item appears too late!", N
);
12668 -- Start of processing for Rep_Item_Too_Late
12671 -- First make sure entity is not frozen (RM 13.1(9))
12675 -- Exclude imported types, which may be frozen if they appear in a
12676 -- representation clause for a local type.
12678 and then not From_Limited_With
(T
)
12680 -- Exclude generated entities (not coming from source). The common
12681 -- case is when we generate a renaming which prematurely freezes the
12682 -- renamed internal entity, but we still want to be able to set copies
12683 -- of attribute values such as Size/Alignment.
12685 and then Comes_From_Source
(T
)
12687 -- A self-referential aspect is illegal if it forces freezing the
12688 -- entity before the corresponding pragma has been analyzed.
12690 if Nkind_In
(N
, N_Attribute_Definition_Clause
, N_Pragma
)
12691 and then From_Aspect_Specification
(N
)
12694 ("aspect specification causes premature freezing of&", T
, N
);
12695 Set_Has_Delayed_Freeze
(T
, False);
12700 S
:= First_Subtype
(T
);
12702 if Present
(Freeze_Node
(S
)) then
12703 if not Relaxed_RM_Semantics
then
12705 ("??no more representation items for }", Freeze_Node
(S
), S
);
12711 -- Check for case of untagged derived type whose parent either has
12712 -- primitive operations, or is a by reference type (RM 13.1(10)). In
12713 -- this case we do not output a Too_Late message, since there is no
12714 -- earlier point where the rep item could be placed to make it legal.
12718 and then Is_Derived_Type
(T
)
12719 and then not Is_Tagged_Type
(T
)
12721 Parent_Type
:= Etype
(Base_Type
(T
));
12723 if Has_Primitive_Operations
(Parent_Type
) then
12726 if not Relaxed_RM_Semantics
then
12728 ("\parent type & has primitive operations!", N
, Parent_Type
);
12733 elsif Is_By_Reference_Type
(Parent_Type
) then
12736 if not Relaxed_RM_Semantics
then
12738 ("\parent type & is a by reference type!", N
, Parent_Type
);
12745 -- No error, but one more warning to consider. The RM (surprisingly)
12746 -- allows this pattern:
12749 -- primitive operations for S
12750 -- type R is new S;
12751 -- rep clause for S
12753 -- Meaning that calls on the primitive operations of S for values of
12754 -- type R may require possibly expensive implicit conversion operations.
12755 -- This is not an error, but is worth a warning.
12757 if not Relaxed_RM_Semantics
and then Is_Type
(T
) then
12759 DTL
: constant Entity_Id
:= Derived_Type_Link
(Base_Type
(T
));
12763 and then Has_Primitive_Operations
(Base_Type
(T
))
12765 -- For now, do not generate this warning for the case of aspect
12766 -- specification using Ada 2012 syntax, since we get wrong
12767 -- messages we do not understand. The whole business of derived
12768 -- types and rep items seems a bit confused when aspects are
12769 -- used, since the aspects are not evaluated till freeze time.
12771 and then not From_Aspect_Specification
(N
)
12773 Error_Msg_Sloc
:= Sloc
(DTL
);
12775 ("representation item for& appears after derived type "
12776 & "declaration#??", N
);
12778 ("\may result in implicit conversions for primitive "
12779 & "operations of&??", N
, T
);
12781 ("\to change representations when called with arguments "
12782 & "of type&??", N
, DTL
);
12787 -- No error, link item into head of chain of rep items for the entity,
12788 -- but avoid chaining if we have an overloadable entity, and the pragma
12789 -- is one that can apply to multiple overloaded entities.
12791 if Is_Overloadable
(T
) and then Nkind
(N
) = N_Pragma
then
12793 Pname
: constant Name_Id
:= Pragma_Name
(N
);
12795 if Nam_In
(Pname
, Name_Convention
, Name_Import
, Name_Export
,
12796 Name_External
, Name_Interface
)
12803 Record_Rep_Item
(T
, N
);
12805 end Rep_Item_Too_Late
;
12807 -------------------------------------
12808 -- Replace_Type_References_Generic --
12809 -------------------------------------
12811 procedure Replace_Type_References_Generic
(N
: Node_Id
; T
: Entity_Id
) is
12812 TName
: constant Name_Id
:= Chars
(T
);
12814 function Replace_Node
(N
: Node_Id
) return Traverse_Result
;
12815 -- Processes a single node in the traversal procedure below, checking
12816 -- if node N should be replaced, and if so, doing the replacement.
12818 procedure Replace_Type_Refs
is new Traverse_Proc
(Replace_Node
);
12819 -- This instantiation provides the body of Replace_Type_References
12825 function Replace_Node
(N
: Node_Id
) return Traverse_Result
is
12830 -- Case of identifier
12832 if Nkind
(N
) = N_Identifier
then
12834 -- If not the type name, check whether it is a reference to
12835 -- some other type, which must be frozen before the predicate
12836 -- function is analyzed, i.e. before the freeze node of the
12837 -- type to which the predicate applies.
12839 if Chars
(N
) /= TName
then
12840 if Present
(Current_Entity
(N
))
12841 and then Is_Type
(Current_Entity
(N
))
12843 Freeze_Before
(Freeze_Node
(T
), Current_Entity
(N
));
12848 -- Otherwise do the replacement and we are done with this node
12851 Replace_Type_Reference
(N
);
12855 -- Case of selected component (which is what a qualification
12856 -- looks like in the unanalyzed tree, which is what we have.
12858 elsif Nkind
(N
) = N_Selected_Component
then
12860 -- If selector name is not our type, keeping going (we might
12861 -- still have an occurrence of the type in the prefix).
12863 if Nkind
(Selector_Name
(N
)) /= N_Identifier
12864 or else Chars
(Selector_Name
(N
)) /= TName
12868 -- Selector name is our type, check qualification
12871 -- Loop through scopes and prefixes, doing comparison
12873 S
:= Current_Scope
;
12876 -- Continue if no more scopes or scope with no name
12878 if No
(S
) or else Nkind
(S
) not in N_Has_Chars
then
12882 -- Do replace if prefix is an identifier matching the
12883 -- scope that we are currently looking at.
12885 if Nkind
(P
) = N_Identifier
12886 and then Chars
(P
) = Chars
(S
)
12888 Replace_Type_Reference
(N
);
12892 -- Go check scope above us if prefix is itself of the
12893 -- form of a selected component, whose selector matches
12894 -- the scope we are currently looking at.
12896 if Nkind
(P
) = N_Selected_Component
12897 and then Nkind
(Selector_Name
(P
)) = N_Identifier
12898 and then Chars
(Selector_Name
(P
)) = Chars
(S
)
12903 -- For anything else, we don't have a match, so keep on
12904 -- going, there are still some weird cases where we may
12905 -- still have a replacement within the prefix.
12913 -- Continue for any other node kind
12921 Replace_Type_Refs
(N
);
12922 end Replace_Type_References_Generic
;
12924 --------------------------------
12925 -- Resolve_Aspect_Expressions --
12926 --------------------------------
12928 procedure Resolve_Aspect_Expressions
(E
: Entity_Id
) is
12933 function Resolve_Name
(N
: Node_Id
) return Traverse_Result
;
12934 -- Verify that all identifiers in the expression, with the exception
12935 -- of references to the current entity, denote visible entities. This
12936 -- is done only to detect visibility errors, as the expression will be
12937 -- properly analyzed/expanded during analysis of the predicate function
12938 -- body. We omit quantified expressions from this test, given that they
12939 -- introduce a local identifier that would require proper expansion to
12940 -- handle properly.
12946 function Resolve_Name
(N
: Node_Id
) return Traverse_Result
is
12948 if Nkind
(N
) = N_Selected_Component
then
12949 if Nkind
(Prefix
(N
)) = N_Identifier
12950 and then Chars
(Prefix
(N
)) /= Chars
(E
)
12952 Find_Selected_Component
(N
);
12957 elsif Nkind
(N
) = N_Identifier
and then Chars
(N
) /= Chars
(E
) then
12958 Find_Direct_Name
(N
);
12959 Set_Entity
(N
, Empty
);
12961 elsif Nkind
(N
) = N_Quantified_Expression
then
12968 procedure Resolve_Aspect_Expression
is new Traverse_Proc
(Resolve_Name
);
12970 -- Start of processing for Resolve_Aspect_Expressions
12973 ASN
:= First_Rep_Item
(E
);
12974 while Present
(ASN
) loop
12975 if Nkind
(ASN
) = N_Aspect_Specification
and then Entity
(ASN
) = E
then
12976 A_Id
:= Get_Aspect_Id
(ASN
);
12977 Expr
:= Expression
(ASN
);
12980 -- For now we only deal with aspects that do not generate
12981 -- subprograms, or that may mention current instances of
12982 -- types. These will require special handling (???TBD).
12984 when Aspect_Predicate |
12985 Aspect_Predicate_Failure |
12986 Aspect_Invariant
=>
12989 when Aspect_Static_Predicate |
12990 Aspect_Dynamic_Predicate
=>
12992 -- Build predicate function specification and preanalyze
12993 -- expression after type replacement.
12995 if No
(Predicate_Function
(E
)) then
12997 FDecl
: constant Node_Id
:=
12998 Build_Predicate_Function_Declaration
(E
);
12999 pragma Unreferenced
(FDecl
);
13001 Resolve_Aspect_Expression
(Expr
);
13005 when Pre_Post_Aspects
=>
13008 when Aspect_Iterable
=>
13009 if Nkind
(Expr
) = N_Aggregate
then
13014 Assoc
:= First
(Component_Associations
(Expr
));
13015 while Present
(Assoc
) loop
13016 Find_Direct_Name
(Expression
(Assoc
));
13023 if Present
(Expr
) then
13024 case Aspect_Argument
(A_Id
) is
13025 when Expression | Optional_Expression
=>
13026 Analyze_And_Resolve
(Expression
(ASN
));
13028 when Name | Optional_Name
=>
13029 if Nkind
(Expr
) = N_Identifier
then
13030 Find_Direct_Name
(Expr
);
13032 elsif Nkind
(Expr
) = N_Selected_Component
then
13033 Find_Selected_Component
(Expr
);
13043 ASN
:= Next_Rep_Item
(ASN
);
13045 end Resolve_Aspect_Expressions
;
13047 -------------------------
13048 -- Same_Representation --
13049 -------------------------
13051 function Same_Representation
(Typ1
, Typ2
: Entity_Id
) return Boolean is
13052 T1
: constant Entity_Id
:= Underlying_Type
(Typ1
);
13053 T2
: constant Entity_Id
:= Underlying_Type
(Typ2
);
13056 -- A quick check, if base types are the same, then we definitely have
13057 -- the same representation, because the subtype specific representation
13058 -- attributes (Size and Alignment) do not affect representation from
13059 -- the point of view of this test.
13061 if Base_Type
(T1
) = Base_Type
(T2
) then
13064 elsif Is_Private_Type
(Base_Type
(T2
))
13065 and then Base_Type
(T1
) = Full_View
(Base_Type
(T2
))
13070 -- Tagged types never have differing representations
13072 if Is_Tagged_Type
(T1
) then
13076 -- Representations are definitely different if conventions differ
13078 if Convention
(T1
) /= Convention
(T2
) then
13082 -- Representations are different if component alignments or scalar
13083 -- storage orders differ.
13085 if (Is_Record_Type
(T1
) or else Is_Array_Type
(T1
))
13087 (Is_Record_Type
(T2
) or else Is_Array_Type
(T2
))
13089 (Component_Alignment
(T1
) /= Component_Alignment
(T2
)
13090 or else Reverse_Storage_Order
(T1
) /= Reverse_Storage_Order
(T2
))
13095 -- For arrays, the only real issue is component size. If we know the
13096 -- component size for both arrays, and it is the same, then that's
13097 -- good enough to know we don't have a change of representation.
13099 if Is_Array_Type
(T1
) then
13100 if Known_Component_Size
(T1
)
13101 and then Known_Component_Size
(T2
)
13102 and then Component_Size
(T1
) = Component_Size
(T2
)
13108 -- Types definitely have same representation if neither has non-standard
13109 -- representation since default representations are always consistent.
13110 -- If only one has non-standard representation, and the other does not,
13111 -- then we consider that they do not have the same representation. They
13112 -- might, but there is no way of telling early enough.
13114 if Has_Non_Standard_Rep
(T1
) then
13115 if not Has_Non_Standard_Rep
(T2
) then
13119 return not Has_Non_Standard_Rep
(T2
);
13122 -- Here the two types both have non-standard representation, and we need
13123 -- to determine if they have the same non-standard representation.
13125 -- For arrays, we simply need to test if the component sizes are the
13126 -- same. Pragma Pack is reflected in modified component sizes, so this
13127 -- check also deals with pragma Pack.
13129 if Is_Array_Type
(T1
) then
13130 return Component_Size
(T1
) = Component_Size
(T2
);
13132 -- Tagged types always have the same representation, because it is not
13133 -- possible to specify different representations for common fields.
13135 elsif Is_Tagged_Type
(T1
) then
13138 -- Case of record types
13140 elsif Is_Record_Type
(T1
) then
13142 -- Packed status must conform
13144 if Is_Packed
(T1
) /= Is_Packed
(T2
) then
13147 -- Otherwise we must check components. Typ2 maybe a constrained
13148 -- subtype with fewer components, so we compare the components
13149 -- of the base types.
13152 Record_Case
: declare
13153 CD1
, CD2
: Entity_Id
;
13155 function Same_Rep
return Boolean;
13156 -- CD1 and CD2 are either components or discriminants. This
13157 -- function tests whether they have the same representation.
13163 function Same_Rep
return Boolean is
13165 if No
(Component_Clause
(CD1
)) then
13166 return No
(Component_Clause
(CD2
));
13168 -- Note: at this point, component clauses have been
13169 -- normalized to the default bit order, so that the
13170 -- comparison of Component_Bit_Offsets is meaningful.
13173 Present
(Component_Clause
(CD2
))
13175 Component_Bit_Offset
(CD1
) = Component_Bit_Offset
(CD2
)
13177 Esize
(CD1
) = Esize
(CD2
);
13181 -- Start of processing for Record_Case
13184 if Has_Discriminants
(T1
) then
13186 -- The number of discriminants may be different if the
13187 -- derived type has fewer (constrained by values). The
13188 -- invisible discriminants retain the representation of
13189 -- the original, so the discrepancy does not per se
13190 -- indicate a different representation.
13192 CD1
:= First_Discriminant
(T1
);
13193 CD2
:= First_Discriminant
(T2
);
13194 while Present
(CD1
) and then Present
(CD2
) loop
13195 if not Same_Rep
then
13198 Next_Discriminant
(CD1
);
13199 Next_Discriminant
(CD2
);
13204 CD1
:= First_Component
(Underlying_Type
(Base_Type
(T1
)));
13205 CD2
:= First_Component
(Underlying_Type
(Base_Type
(T2
)));
13206 while Present
(CD1
) loop
13207 if not Same_Rep
then
13210 Next_Component
(CD1
);
13211 Next_Component
(CD2
);
13219 -- For enumeration types, we must check each literal to see if the
13220 -- representation is the same. Note that we do not permit enumeration
13221 -- representation clauses for Character and Wide_Character, so these
13222 -- cases were already dealt with.
13224 elsif Is_Enumeration_Type
(T1
) then
13225 Enumeration_Case
: declare
13226 L1
, L2
: Entity_Id
;
13229 L1
:= First_Literal
(T1
);
13230 L2
:= First_Literal
(T2
);
13231 while Present
(L1
) loop
13232 if Enumeration_Rep
(L1
) /= Enumeration_Rep
(L2
) then
13241 end Enumeration_Case
;
13243 -- Any other types have the same representation for these purposes
13248 end Same_Representation
;
13250 --------------------------------
13251 -- Resolve_Iterable_Operation --
13252 --------------------------------
13254 procedure Resolve_Iterable_Operation
13256 Cursor
: Entity_Id
;
13265 if not Is_Overloaded
(N
) then
13266 if not Is_Entity_Name
(N
)
13267 or else Ekind
(Entity
(N
)) /= E_Function
13268 or else Scope
(Entity
(N
)) /= Scope
(Typ
)
13269 or else No
(First_Formal
(Entity
(N
)))
13270 or else Etype
(First_Formal
(Entity
(N
))) /= Typ
13272 Error_Msg_N
("iterable primitive must be local function name "
13273 & "whose first formal is an iterable type", N
);
13278 F1
:= First_Formal
(Ent
);
13279 if Nam
= Name_First
then
13281 -- First (Container) => Cursor
13283 if Etype
(Ent
) /= Cursor
then
13284 Error_Msg_N
("primitive for First must yield a curosr", N
);
13287 elsif Nam
= Name_Next
then
13289 -- Next (Container, Cursor) => Cursor
13291 F2
:= Next_Formal
(F1
);
13293 if Etype
(F2
) /= Cursor
13294 or else Etype
(Ent
) /= Cursor
13295 or else Present
(Next_Formal
(F2
))
13297 Error_Msg_N
("no match for Next iterable primitive", N
);
13300 elsif Nam
= Name_Has_Element
then
13302 -- Has_Element (Container, Cursor) => Boolean
13304 F2
:= Next_Formal
(F1
);
13305 if Etype
(F2
) /= Cursor
13306 or else Etype
(Ent
) /= Standard_Boolean
13307 or else Present
(Next_Formal
(F2
))
13309 Error_Msg_N
("no match for Has_Element iterable primitive", N
);
13312 elsif Nam
= Name_Element
then
13313 F2
:= Next_Formal
(F1
);
13316 or else Etype
(F2
) /= Cursor
13317 or else Present
(Next_Formal
(F2
))
13319 Error_Msg_N
("no match for Element iterable primitive", N
);
13324 raise Program_Error
;
13328 -- Overloaded case: find subprogram with proper signature.
13329 -- Caller will report error if no match is found.
13336 Get_First_Interp
(N
, I
, It
);
13337 while Present
(It
.Typ
) loop
13338 if Ekind
(It
.Nam
) = E_Function
13339 and then Scope
(It
.Nam
) = Scope
(Typ
)
13340 and then Etype
(First_Formal
(It
.Nam
)) = Typ
13342 F1
:= First_Formal
(It
.Nam
);
13344 if Nam
= Name_First
then
13345 if Etype
(It
.Nam
) = Cursor
13346 and then No
(Next_Formal
(F1
))
13348 Set_Entity
(N
, It
.Nam
);
13352 elsif Nam
= Name_Next
then
13353 F2
:= Next_Formal
(F1
);
13356 and then No
(Next_Formal
(F2
))
13357 and then Etype
(F2
) = Cursor
13358 and then Etype
(It
.Nam
) = Cursor
13360 Set_Entity
(N
, It
.Nam
);
13364 elsif Nam
= Name_Has_Element
then
13365 F2
:= Next_Formal
(F1
);
13368 and then No
(Next_Formal
(F2
))
13369 and then Etype
(F2
) = Cursor
13370 and then Etype
(It
.Nam
) = Standard_Boolean
13372 Set_Entity
(N
, It
.Nam
);
13373 F2
:= Next_Formal
(F1
);
13377 elsif Nam
= Name_Element
then
13378 F2
:= Next_Formal
(F1
);
13381 and then No
(Next_Formal
(F2
))
13382 and then Etype
(F2
) = Cursor
13384 Set_Entity
(N
, It
.Nam
);
13390 Get_Next_Interp
(I
, It
);
13394 end Resolve_Iterable_Operation
;
13400 procedure Set_Biased
13404 Biased
: Boolean := True)
13408 Set_Has_Biased_Representation
(E
);
13410 if Warn_On_Biased_Representation
then
13412 ("?B?" & Msg
& " forces biased representation for&", N
, E
);
13417 --------------------
13418 -- Set_Enum_Esize --
13419 --------------------
13421 procedure Set_Enum_Esize
(T
: Entity_Id
) is
13427 Init_Alignment
(T
);
13429 -- Find the minimum standard size (8,16,32,64) that fits
13431 Lo
:= Enumeration_Rep
(Entity
(Type_Low_Bound
(T
)));
13432 Hi
:= Enumeration_Rep
(Entity
(Type_High_Bound
(T
)));
13435 if Lo
>= -Uint_2
**07 and then Hi
< Uint_2
**07 then
13436 Sz
:= Standard_Character_Size
; -- May be > 8 on some targets
13438 elsif Lo
>= -Uint_2
**15 and then Hi
< Uint_2
**15 then
13441 elsif Lo
>= -Uint_2
**31 and then Hi
< Uint_2
**31 then
13444 else pragma Assert
(Lo
>= -Uint_2
**63 and then Hi
< Uint_2
**63);
13449 if Hi
< Uint_2
**08 then
13450 Sz
:= Standard_Character_Size
; -- May be > 8 on some targets
13452 elsif Hi
< Uint_2
**16 then
13455 elsif Hi
< Uint_2
**32 then
13458 else pragma Assert
(Hi
< Uint_2
**63);
13463 -- That minimum is the proper size unless we have a foreign convention
13464 -- and the size required is 32 or less, in which case we bump the size
13465 -- up to 32. This is required for C and C++ and seems reasonable for
13466 -- all other foreign conventions.
13468 if Has_Foreign_Convention
(T
)
13469 and then Esize
(T
) < Standard_Integer_Size
13471 -- Don't do this if Short_Enums on target
13473 and then not Target_Short_Enums
13475 Init_Esize
(T
, Standard_Integer_Size
);
13477 Init_Esize
(T
, Sz
);
13479 end Set_Enum_Esize
;
13481 -----------------------------
13482 -- Uninstall_Discriminants --
13483 -----------------------------
13485 procedure Uninstall_Discriminants
(E
: Entity_Id
) is
13491 -- Discriminants have been made visible for type declarations and
13492 -- protected type declarations, not for subtype declarations.
13494 if Nkind
(Parent
(E
)) /= N_Subtype_Declaration
then
13495 Disc
:= First_Discriminant
(E
);
13496 while Present
(Disc
) loop
13497 if Disc
/= Current_Entity
(Disc
) then
13498 Prev
:= Current_Entity
(Disc
);
13499 while Present
(Prev
)
13500 and then Present
(Homonym
(Prev
))
13501 and then Homonym
(Prev
) /= Disc
13503 Prev
:= Homonym
(Prev
);
13509 Set_Is_Immediately_Visible
(Disc
, False);
13511 Outer
:= Homonym
(Disc
);
13512 while Present
(Outer
) and then Scope
(Outer
) = E
loop
13513 Outer
:= Homonym
(Outer
);
13516 -- Reset homonym link of other entities, but do not modify link
13517 -- between entities in current scope, so that the back end can
13518 -- have a proper count of local overloadings.
13521 Set_Name_Entity_Id
(Chars
(Disc
), Outer
);
13523 elsif Scope
(Prev
) /= Scope
(Disc
) then
13524 Set_Homonym
(Prev
, Outer
);
13527 Next_Discriminant
(Disc
);
13530 end Uninstall_Discriminants
;
13532 -------------------------------------------
13533 -- Uninstall_Discriminants_And_Pop_Scope --
13534 -------------------------------------------
13536 procedure Uninstall_Discriminants_And_Pop_Scope
(E
: Entity_Id
) is
13538 if Has_Discriminants
(E
) then
13539 Uninstall_Discriminants
(E
);
13542 end Uninstall_Discriminants_And_Pop_Scope
;
13544 ------------------------------
13545 -- Validate_Address_Clauses --
13546 ------------------------------
13548 procedure Validate_Address_Clauses
is
13550 for J
in Address_Clause_Checks
.First
.. Address_Clause_Checks
.Last
loop
13552 ACCR
: Address_Clause_Check_Record
13553 renames Address_Clause_Checks
.Table
(J
);
13557 X_Alignment
: Uint
;
13558 Y_Alignment
: Uint
;
13564 -- Skip processing of this entry if warning already posted
13566 if not Address_Warning_Posted
(ACCR
.N
) then
13567 Expr
:= Original_Node
(Expression
(ACCR
.N
));
13571 X_Alignment
:= Alignment
(ACCR
.X
);
13572 Y_Alignment
:= Alignment
(ACCR
.Y
);
13574 -- Similarly obtain sizes
13576 X_Size
:= Esize
(ACCR
.X
);
13577 Y_Size
:= Esize
(ACCR
.Y
);
13579 -- Check for large object overlaying smaller one
13582 and then X_Size
> Uint_0
13583 and then X_Size
> Y_Size
13585 Error_Msg_NE
("??& overlays smaller object", ACCR
.N
, ACCR
.X
);
13587 ("\??program execution may be erroneous", ACCR
.N
);
13589 Error_Msg_Uint_1
:= X_Size
;
13590 Error_Msg_NE
("\??size of & is ^", ACCR
.N
, ACCR
.X
);
13592 Error_Msg_Uint_1
:= Y_Size
;
13593 Error_Msg_NE
("\??size of & is ^", ACCR
.N
, ACCR
.Y
);
13595 -- Check for inadequate alignment, both of the base object
13596 -- and of the offset, if any. We only do this check if the
13597 -- run-time Alignment_Check is active. No point in warning
13598 -- if this check has been suppressed (or is suppressed by
13599 -- default in the non-strict alignment machine case).
13601 -- Note: we do not check the alignment if we gave a size
13602 -- warning, since it would likely be redundant.
13604 elsif not Alignment_Checks_Suppressed
(ACCR
.Y
)
13605 and then Y_Alignment
/= Uint_0
13607 (Y_Alignment
< X_Alignment
13610 and then Nkind
(Expr
) = N_Attribute_Reference
13611 and then Attribute_Name
(Expr
) = Name_Address
13612 and then Has_Compatible_Alignment
13613 (ACCR
.X
, Prefix
(Expr
), True) /=
13617 ("??specified address for& may be inconsistent with "
13618 & "alignment", ACCR
.N
, ACCR
.X
);
13620 ("\??program execution may be erroneous (RM 13.3(27))",
13623 Error_Msg_Uint_1
:= X_Alignment
;
13624 Error_Msg_NE
("\??alignment of & is ^", ACCR
.N
, ACCR
.X
);
13626 Error_Msg_Uint_1
:= Y_Alignment
;
13627 Error_Msg_NE
("\??alignment of & is ^", ACCR
.N
, ACCR
.Y
);
13629 if Y_Alignment
>= X_Alignment
then
13631 ("\??but offset is not multiple of alignment", ACCR
.N
);
13637 end Validate_Address_Clauses
;
13639 ---------------------------
13640 -- Validate_Independence --
13641 ---------------------------
13643 procedure Validate_Independence
is
13644 SU
: constant Uint
:= UI_From_Int
(System_Storage_Unit
);
13652 procedure Check_Array_Type
(Atyp
: Entity_Id
);
13653 -- Checks if the array type Atyp has independent components, and
13654 -- if not, outputs an appropriate set of error messages.
13656 procedure No_Independence
;
13657 -- Output message that independence cannot be guaranteed
13659 function OK_Component
(C
: Entity_Id
) return Boolean;
13660 -- Checks one component to see if it is independently accessible, and
13661 -- if so yields True, otherwise yields False if independent access
13662 -- cannot be guaranteed. This is a conservative routine, it only
13663 -- returns True if it knows for sure, it returns False if it knows
13664 -- there is a problem, or it cannot be sure there is no problem.
13666 procedure Reason_Bad_Component
(C
: Entity_Id
);
13667 -- Outputs continuation message if a reason can be determined for
13668 -- the component C being bad.
13670 ----------------------
13671 -- Check_Array_Type --
13672 ----------------------
13674 procedure Check_Array_Type
(Atyp
: Entity_Id
) is
13675 Ctyp
: constant Entity_Id
:= Component_Type
(Atyp
);
13678 -- OK if no alignment clause, no pack, and no component size
13680 if not Has_Component_Size_Clause
(Atyp
)
13681 and then not Has_Alignment_Clause
(Atyp
)
13682 and then not Is_Packed
(Atyp
)
13687 -- Case of component size is greater than or equal to 64 and the
13688 -- alignment of the array is at least as large as the alignment
13689 -- of the component. We are definitely OK in this situation.
13691 if Known_Component_Size
(Atyp
)
13692 and then Component_Size
(Atyp
) >= 64
13693 and then Known_Alignment
(Atyp
)
13694 and then Known_Alignment
(Ctyp
)
13695 and then Alignment
(Atyp
) >= Alignment
(Ctyp
)
13700 -- Check actual component size
13702 if not Known_Component_Size
(Atyp
)
13703 or else not (Addressable
(Component_Size
(Atyp
))
13704 and then Component_Size
(Atyp
) < 64)
13705 or else Component_Size
(Atyp
) mod Esize
(Ctyp
) /= 0
13709 -- Bad component size, check reason
13711 if Has_Component_Size_Clause
(Atyp
) then
13712 P
:= Get_Attribute_Definition_Clause
13713 (Atyp
, Attribute_Component_Size
);
13715 if Present
(P
) then
13716 Error_Msg_Sloc
:= Sloc
(P
);
13717 Error_Msg_N
("\because of Component_Size clause#", N
);
13722 if Is_Packed
(Atyp
) then
13723 P
:= Get_Rep_Pragma
(Atyp
, Name_Pack
);
13725 if Present
(P
) then
13726 Error_Msg_Sloc
:= Sloc
(P
);
13727 Error_Msg_N
("\because of pragma Pack#", N
);
13732 -- No reason found, just return
13737 -- Array type is OK independence-wise
13740 end Check_Array_Type
;
13742 ---------------------
13743 -- No_Independence --
13744 ---------------------
13746 procedure No_Independence
is
13748 if Pragma_Name
(N
) = Name_Independent
then
13749 Error_Msg_NE
("independence cannot be guaranteed for&", N
, E
);
13752 ("independent components cannot be guaranteed for&", N
, E
);
13754 end No_Independence
;
13760 function OK_Component
(C
: Entity_Id
) return Boolean is
13761 Rec
: constant Entity_Id
:= Scope
(C
);
13762 Ctyp
: constant Entity_Id
:= Etype
(C
);
13765 -- OK if no component clause, no Pack, and no alignment clause
13767 if No
(Component_Clause
(C
))
13768 and then not Is_Packed
(Rec
)
13769 and then not Has_Alignment_Clause
(Rec
)
13774 -- Here we look at the actual component layout. A component is
13775 -- addressable if its size is a multiple of the Esize of the
13776 -- component type, and its starting position in the record has
13777 -- appropriate alignment, and the record itself has appropriate
13778 -- alignment to guarantee the component alignment.
13780 -- Make sure sizes are static, always assume the worst for any
13781 -- cases where we cannot check static values.
13783 if not (Known_Static_Esize
(C
)
13785 Known_Static_Esize
(Ctyp
))
13790 -- Size of component must be addressable or greater than 64 bits
13791 -- and a multiple of bytes.
13793 if not Addressable
(Esize
(C
)) and then Esize
(C
) < Uint_64
then
13797 -- Check size is proper multiple
13799 if Esize
(C
) mod Esize
(Ctyp
) /= 0 then
13803 -- Check alignment of component is OK
13805 if not Known_Component_Bit_Offset
(C
)
13806 or else Component_Bit_Offset
(C
) < Uint_0
13807 or else Component_Bit_Offset
(C
) mod Esize
(Ctyp
) /= 0
13812 -- Check alignment of record type is OK
13814 if not Known_Alignment
(Rec
)
13815 or else (Alignment
(Rec
) * SU
) mod Esize
(Ctyp
) /= 0
13820 -- All tests passed, component is addressable
13825 --------------------------
13826 -- Reason_Bad_Component --
13827 --------------------------
13829 procedure Reason_Bad_Component
(C
: Entity_Id
) is
13830 Rec
: constant Entity_Id
:= Scope
(C
);
13831 Ctyp
: constant Entity_Id
:= Etype
(C
);
13834 -- If component clause present assume that's the problem
13836 if Present
(Component_Clause
(C
)) then
13837 Error_Msg_Sloc
:= Sloc
(Component_Clause
(C
));
13838 Error_Msg_N
("\because of Component_Clause#", N
);
13842 -- If pragma Pack clause present, assume that's the problem
13844 if Is_Packed
(Rec
) then
13845 P
:= Get_Rep_Pragma
(Rec
, Name_Pack
);
13847 if Present
(P
) then
13848 Error_Msg_Sloc
:= Sloc
(P
);
13849 Error_Msg_N
("\because of pragma Pack#", N
);
13854 -- See if record has bad alignment clause
13856 if Has_Alignment_Clause
(Rec
)
13857 and then Known_Alignment
(Rec
)
13858 and then (Alignment
(Rec
) * SU
) mod Esize
(Ctyp
) /= 0
13860 P
:= Get_Attribute_Definition_Clause
(Rec
, Attribute_Alignment
);
13862 if Present
(P
) then
13863 Error_Msg_Sloc
:= Sloc
(P
);
13864 Error_Msg_N
("\because of Alignment clause#", N
);
13868 -- Couldn't find a reason, so return without a message
13871 end Reason_Bad_Component
;
13873 -- Start of processing for Validate_Independence
13876 for J
in Independence_Checks
.First
.. Independence_Checks
.Last
loop
13877 N
:= Independence_Checks
.Table
(J
).N
;
13878 E
:= Independence_Checks
.Table
(J
).E
;
13879 IC
:= Pragma_Name
(N
) = Name_Independent_Components
;
13881 -- Deal with component case
13883 if Ekind
(E
) = E_Discriminant
or else Ekind
(E
) = E_Component
then
13884 if not OK_Component
(E
) then
13886 Reason_Bad_Component
(E
);
13891 -- Deal with record with Independent_Components
13893 if IC
and then Is_Record_Type
(E
) then
13894 Comp
:= First_Component_Or_Discriminant
(E
);
13895 while Present
(Comp
) loop
13896 if not OK_Component
(Comp
) then
13898 Reason_Bad_Component
(Comp
);
13902 Next_Component_Or_Discriminant
(Comp
);
13906 -- Deal with address clause case
13908 if Is_Object
(E
) then
13909 Addr
:= Address_Clause
(E
);
13911 if Present
(Addr
) then
13913 Error_Msg_Sloc
:= Sloc
(Addr
);
13914 Error_Msg_N
("\because of Address clause#", N
);
13919 -- Deal with independent components for array type
13921 if IC
and then Is_Array_Type
(E
) then
13922 Check_Array_Type
(E
);
13925 -- Deal with independent components for array object
13927 if IC
and then Is_Object
(E
) and then Is_Array_Type
(Etype
(E
)) then
13928 Check_Array_Type
(Etype
(E
));
13933 end Validate_Independence
;
13935 ------------------------------
13936 -- Validate_Iterable_Aspect --
13937 ------------------------------
13939 procedure Validate_Iterable_Aspect
(Typ
: Entity_Id
; ASN
: Node_Id
) is
13944 Cursor
: constant Entity_Id
:= Get_Cursor_Type
(ASN
, Typ
);
13946 First_Id
: Entity_Id
;
13947 Next_Id
: Entity_Id
;
13948 Has_Element_Id
: Entity_Id
;
13949 Element_Id
: Entity_Id
;
13952 -- If previous error aspect is unusable
13954 if Cursor
= Any_Type
then
13960 Has_Element_Id
:= Empty
;
13961 Element_Id
:= Empty
;
13963 -- Each expression must resolve to a function with the proper signature
13965 Assoc
:= First
(Component_Associations
(Expression
(ASN
)));
13966 while Present
(Assoc
) loop
13967 Expr
:= Expression
(Assoc
);
13970 Prim
:= First
(Choices
(Assoc
));
13972 if Nkind
(Prim
) /= N_Identifier
or else Present
(Next
(Prim
)) then
13973 Error_Msg_N
("illegal name in association", Prim
);
13975 elsif Chars
(Prim
) = Name_First
then
13976 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_First
);
13977 First_Id
:= Entity
(Expr
);
13979 elsif Chars
(Prim
) = Name_Next
then
13980 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_Next
);
13981 Next_Id
:= Entity
(Expr
);
13983 elsif Chars
(Prim
) = Name_Has_Element
then
13984 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_Has_Element
);
13985 Has_Element_Id
:= Entity
(Expr
);
13987 elsif Chars
(Prim
) = Name_Element
then
13988 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_Element
);
13989 Element_Id
:= Entity
(Expr
);
13992 Error_Msg_N
("invalid name for iterable function", Prim
);
13998 if No
(First_Id
) then
13999 Error_Msg_N
("match for First primitive not found", ASN
);
14001 elsif No
(Next_Id
) then
14002 Error_Msg_N
("match for Next primitive not found", ASN
);
14004 elsif No
(Has_Element_Id
) then
14005 Error_Msg_N
("match for Has_Element primitive not found", ASN
);
14007 elsif No
(Element_Id
) then
14010 end Validate_Iterable_Aspect
;
14012 -----------------------------------
14013 -- Validate_Unchecked_Conversion --
14014 -----------------------------------
14016 procedure Validate_Unchecked_Conversion
14018 Act_Unit
: Entity_Id
)
14020 Source
: Entity_Id
;
14021 Target
: Entity_Id
;
14025 -- Obtain source and target types. Note that we call Ancestor_Subtype
14026 -- here because the processing for generic instantiation always makes
14027 -- subtypes, and we want the original frozen actual types.
14029 -- If we are dealing with private types, then do the check on their
14030 -- fully declared counterparts if the full declarations have been
14031 -- encountered (they don't have to be visible, but they must exist).
14033 Source
:= Ancestor_Subtype
(Etype
(First_Formal
(Act_Unit
)));
14035 if Is_Private_Type
(Source
)
14036 and then Present
(Underlying_Type
(Source
))
14038 Source
:= Underlying_Type
(Source
);
14041 Target
:= Ancestor_Subtype
(Etype
(Act_Unit
));
14043 -- If either type is generic, the instantiation happens within a generic
14044 -- unit, and there is nothing to check. The proper check will happen
14045 -- when the enclosing generic is instantiated.
14047 if Is_Generic_Type
(Source
) or else Is_Generic_Type
(Target
) then
14051 if Is_Private_Type
(Target
)
14052 and then Present
(Underlying_Type
(Target
))
14054 Target
:= Underlying_Type
(Target
);
14057 -- Source may be unconstrained array, but not target, except in relaxed
14060 if Is_Array_Type
(Target
)
14061 and then not Is_Constrained
(Target
)
14062 and then not Relaxed_RM_Semantics
14065 ("unchecked conversion to unconstrained array not allowed", N
);
14069 -- Warn if conversion between two different convention pointers
14071 if Is_Access_Type
(Target
)
14072 and then Is_Access_Type
(Source
)
14073 and then Convention
(Target
) /= Convention
(Source
)
14074 and then Warn_On_Unchecked_Conversion
14076 -- Give warnings for subprogram pointers only on most targets
14078 if Is_Access_Subprogram_Type
(Target
)
14079 or else Is_Access_Subprogram_Type
(Source
)
14082 ("?z?conversion between pointers with different conventions!",
14087 -- Warn if one of the operands is Ada.Calendar.Time. Do not emit a
14088 -- warning when compiling GNAT-related sources.
14090 if Warn_On_Unchecked_Conversion
14091 and then not In_Predefined_Unit
(N
)
14092 and then RTU_Loaded
(Ada_Calendar
)
14093 and then (Chars
(Source
) = Name_Time
14095 Chars
(Target
) = Name_Time
)
14097 -- If Ada.Calendar is loaded and the name of one of the operands is
14098 -- Time, there is a good chance that this is Ada.Calendar.Time.
14101 Calendar_Time
: constant Entity_Id
:= Full_View
(RTE
(RO_CA_Time
));
14103 pragma Assert
(Present
(Calendar_Time
));
14105 if Source
= Calendar_Time
or else Target
= Calendar_Time
then
14107 ("?z?representation of 'Time values may change between "
14108 & "'G'N'A'T versions", N
);
14113 -- Make entry in unchecked conversion table for later processing by
14114 -- Validate_Unchecked_Conversions, which will check sizes and alignments
14115 -- (using values set by the back end where possible). This is only done
14116 -- if the appropriate warning is active.
14118 if Warn_On_Unchecked_Conversion
then
14119 Unchecked_Conversions
.Append
14120 (New_Val
=> UC_Entry
'(Eloc => Sloc (N),
14123 Act_Unit => Act_Unit));
14125 -- If both sizes are known statically now, then back end annotation
14126 -- is not required to do a proper check but if either size is not
14127 -- known statically, then we need the annotation.
14129 if Known_Static_RM_Size (Source)
14131 Known_Static_RM_Size (Target)
14135 Back_Annotate_Rep_Info := True;
14139 -- If unchecked conversion to access type, and access type is declared
14140 -- in the same unit as the unchecked conversion, then set the flag
14141 -- No_Strict_Aliasing (no strict aliasing is implicit here)
14143 if Is_Access_Type (Target) and then
14144 In_Same_Source_Unit (Target, N)
14146 Set_No_Strict_Aliasing (Implementation_Base_Type (Target));
14149 -- Generate N_Validate_Unchecked_Conversion node for back end in case
14150 -- the back end needs to perform special validation checks.
14152 -- Shouldn't this be in Exp_Ch13, since the check only gets done if we
14153 -- have full expansion and the back end is called ???
14156 Make_Validate_Unchecked_Conversion (Sloc (N));
14157 Set_Source_Type (Vnode, Source);
14158 Set_Target_Type (Vnode, Target);
14160 -- If the unchecked conversion node is in a list, just insert before it.
14161 -- If not we have some strange case, not worth bothering about.
14163 if Is_List_Member (N) then
14164 Insert_After (N, Vnode);
14166 end Validate_Unchecked_Conversion;
14168 ------------------------------------
14169 -- Validate_Unchecked_Conversions --
14170 ------------------------------------
14172 procedure Validate_Unchecked_Conversions is
14174 for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop
14176 T : UC_Entry renames Unchecked_Conversions.Table (N);
14178 Eloc : constant Source_Ptr := T.Eloc;
14179 Source : constant Entity_Id := T.Source;
14180 Target : constant Entity_Id := T.Target;
14181 Act_Unit : constant Entity_Id := T.Act_Unit;
14187 -- Skip if function marked as warnings off
14189 if Warnings_Off (Act_Unit) then
14193 -- This validation check, which warns if we have unequal sizes for
14194 -- unchecked conversion, and thus potentially implementation
14195 -- dependent semantics, is one of the few occasions on which we
14196 -- use the official RM size instead of Esize. See description in
14197 -- Einfo "Handling of Type'Size Values" for details.
14199 if Serious_Errors_Detected = 0
14200 and then Known_Static_RM_Size (Source)
14201 and then Known_Static_RM_Size (Target)
14203 -- Don't do the check if warnings off for either type, note the
14204 -- deliberate use of OR here instead of OR ELSE to get the flag
14205 -- Warnings_Off_Used set for both types if appropriate.
14207 and then not (Has_Warnings_Off (Source)
14209 Has_Warnings_Off (Target))
14211 Source_Siz := RM_Size (Source);
14212 Target_Siz := RM_Size (Target);
14214 if Source_Siz /= Target_Siz then
14216 ("?z?types for unchecked conversion have different sizes!",
14219 if All_Errors_Mode then
14220 Error_Msg_Name_1 := Chars (Source);
14221 Error_Msg_Uint_1 := Source_Siz;
14222 Error_Msg_Name_2 := Chars (Target);
14223 Error_Msg_Uint_2 := Target_Siz;
14224 Error_Msg ("\size of % is ^, size of % is ^?z?", Eloc);
14226 Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz);
14228 if Is_Discrete_Type (Source)
14230 Is_Discrete_Type (Target)
14232 if Source_Siz > Target_Siz then
14234 ("\?z?^ high order bits of source will "
14235 & "be ignored!", Eloc);
14237 elsif Is_Unsigned_Type (Source) then
14239 ("\?z?source will be extended with ^ high order "
14240 & "zero bits!", Eloc);
14244 ("\?z?source will be extended with ^ high order "
14245 & "sign bits!", Eloc);
14248 elsif Source_Siz < Target_Siz then
14249 if Is_Discrete_Type (Target) then
14250 if Bytes_Big_Endian then
14252 ("\?z?target value will include ^ undefined "
14253 & "low order bits!", Eloc);
14256 ("\?z?target value will include ^ undefined "
14257 & "high order bits!", Eloc);
14262 ("\?z?^ trailing bits of target value will be "
14263 & "undefined!", Eloc);
14266 else pragma Assert (Source_Siz > Target_Siz);
14267 if Is_Discrete_Type (Source) then
14268 if Bytes_Big_Endian then
14270 ("\?z?^ low order bits of source will be "
14271 & "ignored!", Eloc);
14274 ("\?z?^ high order bits of source will be "
14275 & "ignored!", Eloc);
14280 ("\?z?^ trailing bits of source will be "
14281 & "ignored!", Eloc);
14288 -- If both types are access types, we need to check the alignment.
14289 -- If the alignment of both is specified, we can do it here.
14291 if Serious_Errors_Detected = 0
14292 and then Is_Access_Type (Source)
14293 and then Is_Access_Type (Target)
14294 and then Target_Strict_Alignment
14295 and then Present (Designated_Type (Source))
14296 and then Present (Designated_Type (Target))
14299 D_Source : constant Entity_Id := Designated_Type (Source);
14300 D_Target : constant Entity_Id := Designated_Type (Target);
14303 if Known_Alignment (D_Source)
14305 Known_Alignment (D_Target)
14308 Source_Align : constant Uint := Alignment (D_Source);
14309 Target_Align : constant Uint := Alignment (D_Target);
14312 if Source_Align < Target_Align
14313 and then not Is_Tagged_Type (D_Source)
14315 -- Suppress warning if warnings suppressed on either
14316 -- type or either designated type. Note the use of
14317 -- OR here instead of OR ELSE. That is intentional,
14318 -- we would like to set flag Warnings_Off_Used in
14319 -- all types for which warnings are suppressed.
14321 and then not (Has_Warnings_Off (D_Source)
14323 Has_Warnings_Off (D_Target)
14325 Has_Warnings_Off (Source)
14327 Has_Warnings_Off (Target))
14329 Error_Msg_Uint_1 := Target_Align;
14330 Error_Msg_Uint_2 := Source_Align;
14331 Error_Msg_Node_1 := D_Target;
14332 Error_Msg_Node_2 := D_Source;
14334 ("?z?alignment of & (^) is stricter than "
14335 & "alignment of & (^)!", Eloc);
14337 ("\?z?resulting access value may have invalid "
14338 & "alignment!", Eloc);
14349 end Validate_Unchecked_Conversions;