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 -- Check that the class-wide predicate cannot be applied to
3133 -- an operation of a synchronized type that is not a tagged
3134 -- type. Other legality checks are performed when analyzing
3135 -- the contract of the operation.
3137 if Class_Present
(Aspect
)
3138 and then Is_Concurrent_Type
(Current_Scope
)
3139 and then not Is_Tagged_Type
(Current_Scope
)
3140 and then Ekind_In
(E
, E_Entry
, E_Function
, E_Procedure
)
3142 Error_Msg_Name_1
:= Original_Aspect_Pragma_Name
(Aspect
);
3144 ("aspect % can only be specified for a primitive "
3145 & "operation of a tagged type", Aspect
);
3150 -- If the expressions is of the form A and then B, then
3151 -- we generate separate Pre/Post aspects for the separate
3152 -- clauses. Since we allow multiple pragmas, there is no
3153 -- problem in allowing multiple Pre/Post aspects internally.
3154 -- These should be treated in reverse order (B first and
3155 -- A second) since they are later inserted just after N in
3156 -- the order they are treated. This way, the pragma for A
3157 -- ends up preceding the pragma for B, which may have an
3158 -- importance for the error raised (either constraint error
3159 -- or precondition error).
3161 -- We do not do this for Pre'Class, since we have to put
3162 -- these conditions together in a complex OR expression.
3164 -- We do not do this in ASIS mode, as ASIS relies on the
3165 -- original node representing the complete expression, when
3166 -- retrieving it through the source aspect table.
3169 and then (Pname
= Name_Postcondition
3170 or else not Class_Present
(Aspect
))
3172 while Nkind
(Expr
) = N_And_Then
loop
3173 Insert_After
(Aspect
,
3174 Make_Aspect_Specification
(Sloc
(Left_Opnd
(Expr
)),
3175 Identifier
=> Identifier
(Aspect
),
3176 Expression
=> Relocate_Node
(Left_Opnd
(Expr
)),
3177 Class_Present
=> Class_Present
(Aspect
),
3178 Split_PPC
=> True));
3179 Rewrite
(Expr
, Relocate_Node
(Right_Opnd
(Expr
)));
3180 Eloc
:= Sloc
(Expr
);
3184 -- Build the precondition/postcondition pragma
3186 -- Add note about why we do NOT need Copy_Tree here???
3189 (Pragma_Argument_Associations
=> New_List
(
3190 Make_Pragma_Argument_Association
(Eloc
,
3191 Chars
=> Name_Check
,
3192 Expression
=> Relocate_Node
(Expr
))),
3193 Pragma_Name
=> Pname
);
3195 -- Add message unless exception messages are suppressed
3197 if not Opt
.Exception_Locations_Suppressed
then
3198 Append_To
(Pragma_Argument_Associations
(Aitem
),
3199 Make_Pragma_Argument_Association
(Eloc
,
3200 Chars
=> Name_Message
,
3202 Make_String_Literal
(Eloc
,
3204 & Get_Name_String
(Pname
)
3206 & Build_Location_String
(Eloc
))));
3209 Set_Is_Delayed_Aspect
(Aspect
);
3211 -- For Pre/Post cases, insert immediately after the entity
3212 -- declaration, since that is the required pragma placement.
3213 -- Note that for these aspects, we do not have to worry
3214 -- about delay issues, since the pragmas themselves deal
3215 -- with delay of visibility for the expression analysis.
3217 Insert_Pragma
(Aitem
);
3224 when Aspect_Test_Case
=> Test_Case
: declare
3226 Comp_Expr
: Node_Id
;
3227 Comp_Assn
: Node_Id
;
3233 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
3234 Error_Msg_Name_1
:= Nam
;
3235 Error_Msg_N
("incorrect placement of aspect `%`", E
);
3239 if Nkind
(Expr
) /= N_Aggregate
then
3240 Error_Msg_Name_1
:= Nam
;
3242 ("wrong syntax for aspect `%` for &", Id
, E
);
3246 -- Make pragma expressions refer to the original aspect
3247 -- expressions through the Original_Node link. This is used
3248 -- in semantic analysis for ASIS mode, so that the original
3249 -- expression also gets analyzed.
3251 Comp_Expr
:= First
(Expressions
(Expr
));
3252 while Present
(Comp_Expr
) loop
3253 New_Expr
:= Relocate_Node
(Comp_Expr
);
3255 Make_Pragma_Argument_Association
(Sloc
(Comp_Expr
),
3256 Expression
=> New_Expr
));
3260 Comp_Assn
:= First
(Component_Associations
(Expr
));
3261 while Present
(Comp_Assn
) loop
3262 if List_Length
(Choices
(Comp_Assn
)) /= 1
3264 Nkind
(First
(Choices
(Comp_Assn
))) /= N_Identifier
3266 Error_Msg_Name_1
:= Nam
;
3268 ("wrong syntax for aspect `%` for &", Id
, E
);
3273 Make_Pragma_Argument_Association
(Sloc
(Comp_Assn
),
3274 Chars
=> Chars
(First
(Choices
(Comp_Assn
))),
3276 Relocate_Node
(Expression
(Comp_Assn
))));
3280 -- Build the test-case pragma
3283 (Pragma_Argument_Associations
=> Args
,
3284 Pragma_Name
=> Nam
);
3289 when Aspect_Contract_Cases
=>
3291 (Pragma_Argument_Associations
=> New_List
(
3292 Make_Pragma_Argument_Association
(Loc
,
3293 Expression
=> Relocate_Node
(Expr
))),
3294 Pragma_Name
=> Nam
);
3296 Decorate
(Aspect
, Aitem
);
3297 Insert_Pragma
(Aitem
);
3300 -- Case 5: Special handling for aspects with an optional
3301 -- boolean argument.
3303 -- In the delayed case, the corresponding pragma cannot be
3304 -- generated yet because the evaluation of the boolean needs
3305 -- to be delayed till the freeze point.
3307 when Boolean_Aspects |
3308 Library_Unit_Aspects
=>
3310 Set_Is_Boolean_Aspect
(Aspect
);
3312 -- Lock_Free aspect only apply to protected objects
3314 if A_Id
= Aspect_Lock_Free
then
3315 if Ekind
(E
) /= E_Protected_Type
then
3316 Error_Msg_Name_1
:= Nam
;
3318 ("aspect % only applies to a protected object",
3322 -- Set the Uses_Lock_Free flag to True if there is no
3323 -- expression or if the expression is True. The
3324 -- evaluation of this aspect should be delayed to the
3325 -- freeze point (why???)
3328 or else Is_True
(Static_Boolean
(Expr
))
3330 Set_Uses_Lock_Free
(E
);
3333 Record_Rep_Item
(E
, Aspect
);
3338 elsif A_Id
= Aspect_Export
or else A_Id
= Aspect_Import
then
3339 Analyze_Aspect_Export_Import
;
3341 -- Disable_Controlled
3343 elsif A_Id
= Aspect_Disable_Controlled
then
3344 if Ekind
(E
) /= E_Record_Type
3345 or else not Is_Controlled
(E
)
3348 ("aspect % requires controlled record type", Aspect
);
3352 -- If we're in a generic template, we don't want to try
3353 -- to disable controlled types, because typical usage is
3354 -- "Disable_Controlled => not <some_check>'Enabled", and
3355 -- the value of Enabled is not known until we see a
3356 -- particular instance. In such a context, we just need
3357 -- to preanalyze the expression for legality.
3359 if Expander_Active
then
3360 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
3362 if not Present
(Expr
)
3363 or else Is_True
(Static_Boolean
(Expr
))
3365 Set_Disable_Controlled
(E
);
3368 elsif Serious_Errors_Detected
= 0 then
3369 Preanalyze_And_Resolve
(Expr
, Standard_Boolean
);
3375 -- Library unit aspects require special handling in the case
3376 -- of a package declaration, the pragma needs to be inserted
3377 -- in the list of declarations for the associated package.
3378 -- There is no issue of visibility delay for these aspects.
3380 if A_Id
in Library_Unit_Aspects
3382 Nkind_In
(N
, N_Package_Declaration
,
3383 N_Generic_Package_Declaration
)
3384 and then Nkind
(Parent
(N
)) /= N_Compilation_Unit
3386 -- Aspect is legal on a local instantiation of a library-
3387 -- level generic unit.
3389 and then not Is_Generic_Instance
(Defining_Entity
(N
))
3392 ("incorrect context for library unit aspect&", Id
);
3396 -- Cases where we do not delay, includes all cases where the
3397 -- expression is missing other than the above cases.
3399 if not Delay_Required
or else No
(Expr
) then
3401 -- Exclude aspects Export and Import because their pragma
3402 -- syntax does not map directly to a Boolean aspect.
3404 if A_Id
/= Aspect_Export
3405 and then A_Id
/= Aspect_Import
3408 (Pragma_Argument_Associations
=> New_List
(
3409 Make_Pragma_Argument_Association
(Sloc
(Ent
),
3410 Expression
=> Ent
)),
3411 Pragma_Name
=> Chars
(Id
));
3414 Delay_Required
:= False;
3416 -- In general cases, the corresponding pragma/attribute
3417 -- definition clause will be inserted later at the freezing
3418 -- point, and we do not need to build it now.
3426 -- This is special because for access types we need to generate
3427 -- an attribute definition clause. This also works for single
3428 -- task declarations, but it does not work for task type
3429 -- declarations, because we have the case where the expression
3430 -- references a discriminant of the task type. That can't use
3431 -- an attribute definition clause because we would not have
3432 -- visibility on the discriminant. For that case we must
3433 -- generate a pragma in the task definition.
3435 when Aspect_Storage_Size
=>
3439 if Ekind
(E
) = E_Task_Type
then
3441 Decl
: constant Node_Id
:= Declaration_Node
(E
);
3444 pragma Assert
(Nkind
(Decl
) = N_Task_Type_Declaration
);
3446 -- If no task definition, create one
3448 if No
(Task_Definition
(Decl
)) then
3449 Set_Task_Definition
(Decl
,
3450 Make_Task_Definition
(Loc
,
3451 Visible_Declarations
=> Empty_List
,
3452 End_Label
=> Empty
));
3455 -- Create a pragma and put it at the start of the task
3456 -- definition for the task type declaration.
3459 (Pragma_Argument_Associations
=> New_List
(
3460 Make_Pragma_Argument_Association
(Loc
,
3461 Expression
=> Relocate_Node
(Expr
))),
3462 Pragma_Name
=> Name_Storage_Size
);
3466 Visible_Declarations
(Task_Definition
(Decl
)));
3470 -- All other cases, generate attribute definition
3474 Make_Attribute_Definition_Clause
(Loc
,
3476 Chars
=> Chars
(Id
),
3477 Expression
=> Relocate_Node
(Expr
));
3481 -- Attach the corresponding pragma/attribute definition clause to
3482 -- the aspect specification node.
3484 if Present
(Aitem
) then
3485 Set_From_Aspect_Specification
(Aitem
);
3488 -- In the context of a compilation unit, we directly put the
3489 -- pragma in the Pragmas_After list of the N_Compilation_Unit_Aux
3490 -- node (no delay is required here) except for aspects on a
3491 -- subprogram body (see below) and a generic package, for which we
3492 -- need to introduce the pragma before building the generic copy
3493 -- (see sem_ch12), and for package instantiations, where the
3494 -- library unit pragmas are better handled early.
3496 if Nkind
(Parent
(N
)) = N_Compilation_Unit
3497 and then (Present
(Aitem
) or else Is_Boolean_Aspect
(Aspect
))
3500 Aux
: constant Node_Id
:= Aux_Decls_Node
(Parent
(N
));
3503 pragma Assert
(Nkind
(Aux
) = N_Compilation_Unit_Aux
);
3505 -- For a Boolean aspect, create the corresponding pragma if
3506 -- no expression or if the value is True.
3508 if Is_Boolean_Aspect
(Aspect
) and then No
(Aitem
) then
3509 if Is_True
(Static_Boolean
(Expr
)) then
3511 (Pragma_Argument_Associations
=> New_List
(
3512 Make_Pragma_Argument_Association
(Sloc
(Ent
),
3513 Expression
=> Ent
)),
3514 Pragma_Name
=> Chars
(Id
));
3516 Set_From_Aspect_Specification
(Aitem
, True);
3517 Set_Corresponding_Aspect
(Aitem
, Aspect
);
3524 -- If the aspect is on a subprogram body (relevant aspect
3525 -- is Inline), add the pragma in front of the declarations.
3527 if Nkind
(N
) = N_Subprogram_Body
then
3528 if No
(Declarations
(N
)) then
3529 Set_Declarations
(N
, New_List
);
3532 Prepend
(Aitem
, Declarations
(N
));
3534 elsif Nkind
(N
) = N_Generic_Package_Declaration
then
3535 if No
(Visible_Declarations
(Specification
(N
))) then
3536 Set_Visible_Declarations
(Specification
(N
), New_List
);
3540 Visible_Declarations
(Specification
(N
)));
3542 elsif Nkind
(N
) = N_Package_Instantiation
then
3544 Spec
: constant Node_Id
:=
3545 Specification
(Instance_Spec
(N
));
3547 if No
(Visible_Declarations
(Spec
)) then
3548 Set_Visible_Declarations
(Spec
, New_List
);
3551 Prepend
(Aitem
, Visible_Declarations
(Spec
));
3555 if No
(Pragmas_After
(Aux
)) then
3556 Set_Pragmas_After
(Aux
, New_List
);
3559 Append
(Aitem
, Pragmas_After
(Aux
));
3566 -- The evaluation of the aspect is delayed to the freezing point.
3567 -- The pragma or attribute clause if there is one is then attached
3568 -- to the aspect specification which is put in the rep item list.
3570 if Delay_Required
then
3571 if Present
(Aitem
) then
3572 Set_Is_Delayed_Aspect
(Aitem
);
3573 Set_Aspect_Rep_Item
(Aspect
, Aitem
);
3574 Set_Parent
(Aitem
, Aspect
);
3577 Set_Is_Delayed_Aspect
(Aspect
);
3579 -- In the case of Default_Value, link the aspect to base type
3580 -- as well, even though it appears on a first subtype. This is
3581 -- mandated by the semantics of the aspect. Do not establish
3582 -- the link when processing the base type itself as this leads
3583 -- to a rep item circularity. Verify that we are dealing with
3584 -- a scalar type to prevent cascaded errors.
3586 if A_Id
= Aspect_Default_Value
3587 and then Is_Scalar_Type
(E
)
3588 and then Base_Type
(E
) /= E
3590 Set_Has_Delayed_Aspects
(Base_Type
(E
));
3591 Record_Rep_Item
(Base_Type
(E
), Aspect
);
3594 Set_Has_Delayed_Aspects
(E
);
3595 Record_Rep_Item
(E
, Aspect
);
3597 -- When delay is not required and the context is a package or a
3598 -- subprogram body, insert the pragma in the body declarations.
3600 elsif Nkind_In
(N
, N_Package_Body
, N_Subprogram_Body
) then
3601 if No
(Declarations
(N
)) then
3602 Set_Declarations
(N
, New_List
);
3605 -- The pragma is added before source declarations
3607 Prepend_To
(Declarations
(N
), Aitem
);
3609 -- When delay is not required and the context is not a compilation
3610 -- unit, we simply insert the pragma/attribute definition clause
3613 elsif Present
(Aitem
) then
3614 Insert_After
(Ins_Node
, Aitem
);
3617 end Analyze_One_Aspect
;
3621 end loop Aspect_Loop
;
3623 if Has_Delayed_Aspects
(E
) then
3624 Ensure_Freeze_Node
(E
);
3626 end Analyze_Aspect_Specifications
;
3628 ---------------------------------------------------
3629 -- Analyze_Aspect_Specifications_On_Body_Or_Stub --
3630 ---------------------------------------------------
3632 procedure Analyze_Aspect_Specifications_On_Body_Or_Stub
(N
: Node_Id
) is
3633 Body_Id
: constant Entity_Id
:= Defining_Entity
(N
);
3635 procedure Diagnose_Misplaced_Aspects
(Spec_Id
: Entity_Id
);
3636 -- Body [stub] N has aspects, but they are not properly placed. Emit an
3637 -- error message depending on the aspects involved. Spec_Id denotes the
3638 -- entity of the corresponding spec.
3640 --------------------------------
3641 -- Diagnose_Misplaced_Aspects --
3642 --------------------------------
3644 procedure Diagnose_Misplaced_Aspects
(Spec_Id
: Entity_Id
) is
3645 procedure Misplaced_Aspect_Error
3648 -- Emit an error message concerning misplaced aspect Asp. Ref_Nam is
3649 -- the name of the refined version of the aspect.
3651 ----------------------------
3652 -- Misplaced_Aspect_Error --
3653 ----------------------------
3655 procedure Misplaced_Aspect_Error
3659 Asp_Nam
: constant Name_Id
:= Chars
(Identifier
(Asp
));
3660 Asp_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Asp_Nam
);
3663 -- The corresponding spec already contains the aspect in question
3664 -- and the one appearing on the body must be the refined form:
3666 -- procedure P with Global ...;
3667 -- procedure P with Global ... is ... end P;
3671 if Has_Aspect
(Spec_Id
, Asp_Id
) then
3672 Error_Msg_Name_1
:= Asp_Nam
;
3674 -- Subunits cannot carry aspects that apply to a subprogram
3677 if Nkind
(Parent
(N
)) = N_Subunit
then
3678 Error_Msg_N
("aspect % cannot apply to a subunit", Asp
);
3680 -- Otherwise suggest the refined form
3683 Error_Msg_Name_2
:= Ref_Nam
;
3684 Error_Msg_N
("aspect % should be %", Asp
);
3687 -- Otherwise the aspect must appear on the spec, not on the body
3690 -- procedure P with Global ... is ... end P;
3694 ("aspect specification must appear on initial declaration",
3697 end Misplaced_Aspect_Error
;
3704 -- Start of processing for Diagnose_Misplaced_Aspects
3707 -- Iterate over the aspect specifications and emit specific errors
3708 -- where applicable.
3710 Asp
:= First
(Aspect_Specifications
(N
));
3711 while Present
(Asp
) loop
3712 Asp_Nam
:= Chars
(Identifier
(Asp
));
3714 -- Do not emit errors on aspects that can appear on a subprogram
3715 -- body. This scenario occurs when the aspect specification list
3716 -- contains both misplaced and properly placed aspects.
3718 if Aspect_On_Body_Or_Stub_OK
(Get_Aspect_Id
(Asp_Nam
)) then
3721 -- Special diagnostics for SPARK aspects
3723 elsif Asp_Nam
= Name_Depends
then
3724 Misplaced_Aspect_Error
(Asp
, Name_Refined_Depends
);
3726 elsif Asp_Nam
= Name_Global
then
3727 Misplaced_Aspect_Error
(Asp
, Name_Refined_Global
);
3729 elsif Asp_Nam
= Name_Post
then
3730 Misplaced_Aspect_Error
(Asp
, Name_Refined_Post
);
3732 -- Otherwise a language-defined aspect is misplaced
3736 ("aspect specification must appear on initial declaration",
3742 end Diagnose_Misplaced_Aspects
;
3746 Spec_Id
: constant Entity_Id
:= Unique_Defining_Entity
(N
);
3748 -- Start of processing for Analyze_Aspects_On_Body_Or_Stub
3751 -- Language-defined aspects cannot be associated with a subprogram body
3752 -- [stub] if the subprogram has a spec. Certain implementation defined
3753 -- aspects are allowed to break this rule (for all applicable cases, see
3754 -- table Aspects.Aspect_On_Body_Or_Stub_OK).
3756 if Spec_Id
/= Body_Id
and then not Aspects_On_Body_Or_Stub_OK
(N
) then
3757 Diagnose_Misplaced_Aspects
(Spec_Id
);
3759 Analyze_Aspect_Specifications
(N
, Body_Id
);
3761 end Analyze_Aspect_Specifications_On_Body_Or_Stub
;
3763 -----------------------
3764 -- Analyze_At_Clause --
3765 -----------------------
3767 -- An at clause is replaced by the corresponding Address attribute
3768 -- definition clause that is the preferred approach in Ada 95.
3770 procedure Analyze_At_Clause
(N
: Node_Id
) is
3771 CS
: constant Boolean := Comes_From_Source
(N
);
3774 -- This is an obsolescent feature
3776 Check_Restriction
(No_Obsolescent_Features
, N
);
3778 if Warn_On_Obsolescent_Feature
then
3780 ("?j?at clause is an obsolescent feature (RM J.7(2))", N
);
3782 ("\?j?use address attribute definition clause instead", N
);
3785 -- Rewrite as address clause
3788 Make_Attribute_Definition_Clause
(Sloc
(N
),
3789 Name
=> Identifier
(N
),
3790 Chars
=> Name_Address
,
3791 Expression
=> Expression
(N
)));
3793 -- We preserve Comes_From_Source, since logically the clause still comes
3794 -- from the source program even though it is changed in form.
3796 Set_Comes_From_Source
(N
, CS
);
3798 -- Analyze rewritten clause
3800 Analyze_Attribute_Definition_Clause
(N
);
3801 end Analyze_At_Clause
;
3803 -----------------------------------------
3804 -- Analyze_Attribute_Definition_Clause --
3805 -----------------------------------------
3807 procedure Analyze_Attribute_Definition_Clause
(N
: Node_Id
) is
3808 Loc
: constant Source_Ptr
:= Sloc
(N
);
3809 Nam
: constant Node_Id
:= Name
(N
);
3810 Attr
: constant Name_Id
:= Chars
(N
);
3811 Expr
: constant Node_Id
:= Expression
(N
);
3812 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Attr
);
3815 -- The entity of Nam after it is analyzed. In the case of an incomplete
3816 -- type, this is the underlying type.
3819 -- The underlying entity to which the attribute applies. Generally this
3820 -- is the Underlying_Type of Ent, except in the case where the clause
3821 -- applies to full view of incomplete type or private type in which case
3822 -- U_Ent is just a copy of Ent.
3824 FOnly
: Boolean := False;
3825 -- Reset to True for subtype specific attribute (Alignment, Size)
3826 -- and for stream attributes, i.e. those cases where in the call to
3827 -- Rep_Item_Too_Late, FOnly is set True so that only the freezing rules
3828 -- are checked. Note that the case of stream attributes is not clear
3829 -- from the RM, but see AI95-00137. Also, the RM seems to disallow
3830 -- Storage_Size for derived task types, but that is also clearly
3833 procedure Analyze_Stream_TSS_Definition
(TSS_Nam
: TSS_Name_Type
);
3834 -- Common processing for 'Read, 'Write, 'Input and 'Output attribute
3835 -- definition clauses.
3837 function Duplicate_Clause
return Boolean;
3838 -- This routine checks if the aspect for U_Ent being given by attribute
3839 -- definition clause N is for an aspect that has already been specified,
3840 -- and if so gives an error message. If there is a duplicate, True is
3841 -- returned, otherwise if there is no error, False is returned.
3843 procedure Check_Indexing_Functions
;
3844 -- Check that the function in Constant_Indexing or Variable_Indexing
3845 -- attribute has the proper type structure. If the name is overloaded,
3846 -- check that some interpretation is legal.
3848 procedure Check_Iterator_Functions
;
3849 -- Check that there is a single function in Default_Iterator attribute
3850 -- has the proper type structure.
3852 function Check_Primitive_Function
(Subp
: Entity_Id
) return Boolean;
3853 -- Common legality check for the previous two
3855 -----------------------------------
3856 -- Analyze_Stream_TSS_Definition --
3857 -----------------------------------
3859 procedure Analyze_Stream_TSS_Definition
(TSS_Nam
: TSS_Name_Type
) is
3860 Subp
: Entity_Id
:= Empty
;
3865 Is_Read
: constant Boolean := (TSS_Nam
= TSS_Stream_Read
);
3866 -- True for Read attribute, False for other attributes
3868 function Has_Good_Profile
3870 Report
: Boolean := False) return Boolean;
3871 -- Return true if the entity is a subprogram with an appropriate
3872 -- profile for the attribute being defined. If result is False and
3873 -- Report is True, function emits appropriate error.
3875 ----------------------
3876 -- Has_Good_Profile --
3877 ----------------------
3879 function Has_Good_Profile
3881 Report
: Boolean := False) return Boolean
3883 Expected_Ekind
: constant array (Boolean) of Entity_Kind
:=
3884 (False => E_Procedure
, True => E_Function
);
3885 Is_Function
: constant Boolean := (TSS_Nam
= TSS_Stream_Input
);
3890 if Ekind
(Subp
) /= Expected_Ekind
(Is_Function
) then
3894 F
:= First_Formal
(Subp
);
3897 or else Ekind
(Etype
(F
)) /= E_Anonymous_Access_Type
3898 or else Designated_Type
(Etype
(F
)) /=
3899 Class_Wide_Type
(RTE
(RE_Root_Stream_Type
))
3904 if not Is_Function
then
3908 Expected_Mode
: constant array (Boolean) of Entity_Kind
:=
3909 (False => E_In_Parameter
,
3910 True => E_Out_Parameter
);
3912 if Parameter_Mode
(F
) /= Expected_Mode
(Is_Read
) then
3919 -- If the attribute specification comes from an aspect
3920 -- specification for a class-wide stream, the parameter must be
3921 -- a class-wide type of the entity to which the aspect applies.
3923 if From_Aspect_Specification
(N
)
3924 and then Class_Present
(Parent
(N
))
3925 and then Is_Class_Wide_Type
(Typ
)
3931 Typ
:= Etype
(Subp
);
3934 -- Verify that the prefix of the attribute and the local name for
3935 -- the type of the formal match, or one is the class-wide of the
3936 -- other, in the case of a class-wide stream operation.
3938 if Base_Type
(Typ
) = Base_Type
(Ent
)
3939 or else (Is_Class_Wide_Type
(Typ
)
3940 and then Typ
= Class_Wide_Type
(Base_Type
(Ent
)))
3941 or else (Is_Class_Wide_Type
(Ent
)
3942 and then Ent
= Class_Wide_Type
(Base_Type
(Typ
)))
3949 if Present
(Next_Formal
(F
)) then
3952 elsif not Is_Scalar_Type
(Typ
)
3953 and then not Is_First_Subtype
(Typ
)
3954 and then not Is_Class_Wide_Type
(Typ
)
3956 if Report
and not Is_First_Subtype
(Typ
) then
3958 ("subtype of formal in stream operation must be a first "
3959 & "subtype", Parameter_Type
(Parent
(F
)));
3967 end Has_Good_Profile
;
3969 -- Start of processing for Analyze_Stream_TSS_Definition
3974 if not Is_Type
(U_Ent
) then
3975 Error_Msg_N
("local name must be a subtype", Nam
);
3978 elsif not Is_First_Subtype
(U_Ent
) then
3979 Error_Msg_N
("local name must be a first subtype", Nam
);
3983 Pnam
:= TSS
(Base_Type
(U_Ent
), TSS_Nam
);
3985 -- If Pnam is present, it can be either inherited from an ancestor
3986 -- type (in which case it is legal to redefine it for this type), or
3987 -- be a previous definition of the attribute for the same type (in
3988 -- which case it is illegal).
3990 -- In the first case, it will have been analyzed already, and we
3991 -- can check that its profile does not match the expected profile
3992 -- for a stream attribute of U_Ent. In the second case, either Pnam
3993 -- has been analyzed (and has the expected profile), or it has not
3994 -- been analyzed yet (case of a type that has not been frozen yet
3995 -- and for which the stream attribute has been set using Set_TSS).
3998 and then (No
(First_Entity
(Pnam
)) or else Has_Good_Profile
(Pnam
))
4000 Error_Msg_Sloc
:= Sloc
(Pnam
);
4001 Error_Msg_Name_1
:= Attr
;
4002 Error_Msg_N
("% attribute already defined #", Nam
);
4008 if Is_Entity_Name
(Expr
) then
4009 if not Is_Overloaded
(Expr
) then
4010 if Has_Good_Profile
(Entity
(Expr
), Report
=> True) then
4011 Subp
:= Entity
(Expr
);
4015 Get_First_Interp
(Expr
, I
, It
);
4016 while Present
(It
.Nam
) loop
4017 if Has_Good_Profile
(It
.Nam
) then
4022 Get_Next_Interp
(I
, It
);
4027 if Present
(Subp
) then
4028 if Is_Abstract_Subprogram
(Subp
) then
4029 Error_Msg_N
("stream subprogram must not be abstract", Expr
);
4032 -- A stream subprogram for an interface type must be a null
4033 -- procedure (RM 13.13.2 (38/3)). Note that the class-wide type
4034 -- of an interface is not an interface type (3.9.4 (6.b/2)).
4036 elsif Is_Interface
(U_Ent
)
4037 and then not Is_Class_Wide_Type
(U_Ent
)
4038 and then not Inside_A_Generic
4040 (Ekind
(Subp
) = E_Function
4044 (Unit_Declaration_Node
(Ultimate_Alias
(Subp
)))))
4047 ("stream subprogram for interface type must be null "
4048 & "procedure", Expr
);
4051 Set_Entity
(Expr
, Subp
);
4052 Set_Etype
(Expr
, Etype
(Subp
));
4054 New_Stream_Subprogram
(N
, U_Ent
, Subp
, TSS_Nam
);
4057 Error_Msg_Name_1
:= Attr
;
4058 Error_Msg_N
("incorrect expression for% attribute", Expr
);
4060 end Analyze_Stream_TSS_Definition
;
4062 ------------------------------
4063 -- Check_Indexing_Functions --
4064 ------------------------------
4066 procedure Check_Indexing_Functions
is
4067 Indexing_Found
: Boolean := False;
4069 procedure Check_Inherited_Indexing
;
4070 -- For a derived type, check that no indexing aspect is specified
4071 -- for the type if it is also inherited
4073 procedure Check_One_Function
(Subp
: Entity_Id
);
4074 -- Check one possible interpretation. Sets Indexing_Found True if a
4075 -- legal indexing function is found.
4077 procedure Illegal_Indexing
(Msg
: String);
4078 -- Diagnose illegal indexing function if not overloaded. In the
4079 -- overloaded case indicate that no legal interpretation exists.
4081 ------------------------------
4082 -- Check_Inherited_Indexing --
4083 ------------------------------
4085 procedure Check_Inherited_Indexing
is
4086 Inherited
: Node_Id
;
4089 if Attr
= Name_Constant_Indexing
then
4091 Find_Aspect
(Etype
(Ent
), Aspect_Constant_Indexing
);
4092 else pragma Assert
(Attr
= Name_Variable_Indexing
);
4094 Find_Aspect
(Etype
(Ent
), Aspect_Variable_Indexing
);
4097 if Present
(Inherited
) then
4098 if Debug_Flag_Dot_XX
then
4101 -- OK if current attribute_definition_clause is expansion of
4102 -- inherited aspect.
4104 elsif Aspect_Rep_Item
(Inherited
) = N
then
4107 -- Indicate the operation that must be overridden, rather than
4108 -- redefining the indexing aspect.
4112 ("indexing function already inherited from parent type");
4114 ("!override & instead",
4115 N
, Entity
(Expression
(Inherited
)));
4118 end Check_Inherited_Indexing
;
4120 ------------------------
4121 -- Check_One_Function --
4122 ------------------------
4124 procedure Check_One_Function
(Subp
: Entity_Id
) is
4125 Default_Element
: Node_Id
;
4126 Ret_Type
: constant Entity_Id
:= Etype
(Subp
);
4129 if not Is_Overloadable
(Subp
) then
4130 Illegal_Indexing
("illegal indexing function for type&");
4133 elsif Scope
(Subp
) /= Scope
(Ent
) then
4134 if Nkind
(Expr
) = N_Expanded_Name
then
4136 -- Indexing function can't be declared elsewhere
4139 ("indexing function must be declared in scope of type&");
4144 elsif No
(First_Formal
(Subp
)) then
4146 ("Indexing requires a function that applies to type&");
4149 elsif No
(Next_Formal
(First_Formal
(Subp
))) then
4151 ("indexing function must have at least two parameters");
4154 elsif Is_Derived_Type
(Ent
) then
4155 Check_Inherited_Indexing
;
4158 if not Check_Primitive_Function
(Subp
) then
4160 ("Indexing aspect requires a function that applies to type&");
4164 -- If partial declaration exists, verify that it is not tagged.
4166 if Ekind
(Current_Scope
) = E_Package
4167 and then Has_Private_Declaration
(Ent
)
4168 and then From_Aspect_Specification
(N
)
4170 List_Containing
(Parent
(Ent
)) =
4171 Private_Declarations
4172 (Specification
(Unit_Declaration_Node
(Current_Scope
)))
4173 and then Nkind
(N
) = N_Attribute_Definition_Clause
4180 First
(Visible_Declarations
4182 (Unit_Declaration_Node
(Current_Scope
))));
4184 while Present
(Decl
) loop
4185 if Nkind
(Decl
) = N_Private_Type_Declaration
4186 and then Ent
= Full_View
(Defining_Identifier
(Decl
))
4187 and then Tagged_Present
(Decl
)
4188 and then No
(Aspect_Specifications
(Decl
))
4191 ("Indexing aspect cannot be specified on full view "
4192 & "if partial view is tagged");
4201 -- An indexing function must return either the default element of
4202 -- the container, or a reference type. For variable indexing it
4203 -- must be the latter.
4206 Find_Value_Of_Aspect
4207 (Etype
(First_Formal
(Subp
)), Aspect_Iterator_Element
);
4209 if Present
(Default_Element
) then
4210 Analyze
(Default_Element
);
4212 if Is_Entity_Name
(Default_Element
)
4213 and then not Covers
(Entity
(Default_Element
), Ret_Type
)
4217 ("wrong return type for indexing function");
4222 -- For variable_indexing the return type must be a reference type
4224 if Attr
= Name_Variable_Indexing
then
4225 if not Has_Implicit_Dereference
(Ret_Type
) then
4227 ("variable indexing must return a reference type");
4230 elsif Is_Access_Constant
4231 (Etype
(First_Discriminant
(Ret_Type
)))
4234 ("variable indexing must return an access to variable");
4239 if Has_Implicit_Dereference
(Ret_Type
)
4241 Is_Access_Constant
(Etype
(First_Discriminant
(Ret_Type
)))
4244 ("constant indexing must return an access to constant");
4247 elsif Is_Access_Type
(Etype
(First_Formal
(Subp
)))
4248 and then not Is_Access_Constant
(Etype
(First_Formal
(Subp
)))
4251 ("constant indexing must apply to an access to constant");
4256 -- All checks succeeded.
4258 Indexing_Found
:= True;
4259 end Check_One_Function
;
4261 -----------------------
4262 -- Illegal_Indexing --
4263 -----------------------
4265 procedure Illegal_Indexing
(Msg
: String) is
4267 Error_Msg_NE
(Msg
, N
, Ent
);
4268 end Illegal_Indexing
;
4270 -- Start of processing for Check_Indexing_Functions
4274 Check_Inherited_Indexing
;
4279 if not Is_Overloaded
(Expr
) then
4280 Check_One_Function
(Entity
(Expr
));
4288 Indexing_Found
:= False;
4289 Get_First_Interp
(Expr
, I
, It
);
4290 while Present
(It
.Nam
) loop
4292 -- Note that analysis will have added the interpretation
4293 -- that corresponds to the dereference. We only check the
4294 -- subprogram itself.
4296 if Is_Overloadable
(It
.Nam
) then
4297 Check_One_Function
(It
.Nam
);
4300 Get_Next_Interp
(I
, It
);
4305 if not Indexing_Found
and then not Error_Posted
(N
) then
4307 ("aspect Indexing requires a local function that "
4308 & "applies to type&", Expr
, Ent
);
4310 end Check_Indexing_Functions
;
4312 ------------------------------
4313 -- Check_Iterator_Functions --
4314 ------------------------------
4316 procedure Check_Iterator_Functions
is
4317 function Valid_Default_Iterator
(Subp
: Entity_Id
) return Boolean;
4318 -- Check one possible interpretation for validity
4320 ----------------------------
4321 -- Valid_Default_Iterator --
4322 ----------------------------
4324 function Valid_Default_Iterator
(Subp
: Entity_Id
) return Boolean is
4326 Root_T
: constant Entity_Id
:= Root_Type
(Etype
(Etype
(Subp
)));
4329 if not Check_Primitive_Function
(Subp
) then
4332 -- The return type must be derived from a type in an instance
4333 -- of Iterator.Interfaces, and thus its root type must have a
4336 elsif Chars
(Root_T
) /= Name_Forward_Iterator
4337 and then Chars
(Root_T
) /= Name_Reversible_Iterator
4342 Formal
:= First_Formal
(Subp
);
4345 -- False if any subsequent formal has no default expression
4347 Formal
:= Next_Formal
(Formal
);
4348 while Present
(Formal
) loop
4349 if No
(Expression
(Parent
(Formal
))) then
4353 Next_Formal
(Formal
);
4356 -- True if all subsequent formals have default expressions
4359 end Valid_Default_Iterator
;
4361 -- Start of processing for Check_Iterator_Functions
4366 if not Is_Entity_Name
(Expr
) then
4367 Error_Msg_N
("aspect Iterator must be a function name", Expr
);
4370 if not Is_Overloaded
(Expr
) then
4371 if not Check_Primitive_Function
(Entity
(Expr
)) then
4373 ("aspect Indexing requires a function that applies to type&",
4374 Entity
(Expr
), Ent
);
4377 -- Flag the default_iterator as well as the denoted function.
4379 if not Valid_Default_Iterator
(Entity
(Expr
)) then
4380 Error_Msg_N
("improper function for default iterator!", Expr
);
4385 Default
: Entity_Id
:= Empty
;
4390 Get_First_Interp
(Expr
, I
, It
);
4391 while Present
(It
.Nam
) loop
4392 if not Check_Primitive_Function
(It
.Nam
)
4393 or else not Valid_Default_Iterator
(It
.Nam
)
4397 elsif Present
(Default
) then
4399 -- An explicit one should override an implicit one
4401 if Comes_From_Source
(Default
) =
4402 Comes_From_Source
(It
.Nam
)
4404 Error_Msg_N
("default iterator must be unique", Expr
);
4405 Error_Msg_Sloc
:= Sloc
(Default
);
4406 Error_Msg_N
("\\possible interpretation#", Expr
);
4407 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
4408 Error_Msg_N
("\\possible interpretation#", Expr
);
4410 elsif Comes_From_Source
(It
.Nam
) then
4417 Get_Next_Interp
(I
, It
);
4420 if Present
(Default
) then
4421 Set_Entity
(Expr
, Default
);
4422 Set_Is_Overloaded
(Expr
, False);
4425 ("No interpretation is a valid default iterator!", Expr
);
4429 end Check_Iterator_Functions
;
4431 -------------------------------
4432 -- Check_Primitive_Function --
4433 -------------------------------
4435 function Check_Primitive_Function
(Subp
: Entity_Id
) return Boolean is
4439 if Ekind
(Subp
) /= E_Function
then
4443 if No
(First_Formal
(Subp
)) then
4446 Ctrl
:= Etype
(First_Formal
(Subp
));
4449 -- To be a primitive operation subprogram has to be in same scope.
4451 if Scope
(Ctrl
) /= Scope
(Subp
) then
4455 -- Type of formal may be the class-wide type, an access to such,
4456 -- or an incomplete view.
4459 or else Ctrl
= Class_Wide_Type
(Ent
)
4461 (Ekind
(Ctrl
) = E_Anonymous_Access_Type
4462 and then (Designated_Type
(Ctrl
) = Ent
4464 Designated_Type
(Ctrl
) = Class_Wide_Type
(Ent
)))
4466 (Ekind
(Ctrl
) = E_Incomplete_Type
4467 and then Full_View
(Ctrl
) = Ent
)
4475 end Check_Primitive_Function
;
4477 ----------------------
4478 -- Duplicate_Clause --
4479 ----------------------
4481 function Duplicate_Clause
return Boolean is
4485 -- Nothing to do if this attribute definition clause comes from
4486 -- an aspect specification, since we could not be duplicating an
4487 -- explicit clause, and we dealt with the case of duplicated aspects
4488 -- in Analyze_Aspect_Specifications.
4490 if From_Aspect_Specification
(N
) then
4494 -- Otherwise current clause may duplicate previous clause, or a
4495 -- previously given pragma or aspect specification for the same
4498 A
:= Get_Rep_Item
(U_Ent
, Chars
(N
), Check_Parents
=> False);
4501 Error_Msg_Name_1
:= Chars
(N
);
4502 Error_Msg_Sloc
:= Sloc
(A
);
4504 Error_Msg_NE
("aspect% for & previously given#", N
, U_Ent
);
4509 end Duplicate_Clause
;
4511 -- Start of processing for Analyze_Attribute_Definition_Clause
4514 -- The following code is a defense against recursion. Not clear that
4515 -- this can happen legitimately, but perhaps some error situations can
4516 -- cause it, and we did see this recursion during testing.
4518 if Analyzed
(N
) then
4521 Set_Analyzed
(N
, True);
4524 Check_Restriction_No_Use_Of_Attribute
(N
);
4526 -- Ignore some selected attributes in CodePeer mode since they are not
4527 -- relevant in this context.
4529 if CodePeer_Mode
then
4532 -- Ignore Component_Size in CodePeer mode, to avoid changing the
4533 -- internal representation of types by implicitly packing them.
4535 when Attribute_Component_Size
=>
4536 Rewrite
(N
, Make_Null_Statement
(Sloc
(N
)));
4544 -- Process Ignore_Rep_Clauses option
4546 if Ignore_Rep_Clauses
then
4549 -- The following should be ignored. They do not affect legality
4550 -- and may be target dependent. The basic idea of -gnatI is to
4551 -- ignore any rep clauses that may be target dependent but do not
4552 -- affect legality (except possibly to be rejected because they
4553 -- are incompatible with the compilation target).
4555 when Attribute_Alignment |
4556 Attribute_Bit_Order |
4557 Attribute_Component_Size |
4558 Attribute_Machine_Radix |
4559 Attribute_Object_Size |
4562 Attribute_Stream_Size |
4563 Attribute_Value_Size
=>
4564 Kill_Rep_Clause
(N
);
4567 -- The following should not be ignored, because in the first place
4568 -- they are reasonably portable, and should not cause problems
4569 -- in compiling code from another target, and also they do affect
4570 -- legality, e.g. failing to provide a stream attribute for a type
4571 -- may make a program illegal.
4573 when Attribute_External_Tag |
4577 Attribute_Simple_Storage_Pool |
4578 Attribute_Storage_Pool |
4579 Attribute_Storage_Size |
4583 -- We do not do anything here with address clauses, they will be
4584 -- removed by Freeze later on, but for now, it works better to
4585 -- keep then in the tree.
4587 when Attribute_Address
=>
4590 -- Other cases are errors ("attribute& cannot be set with
4591 -- definition clause"), which will be caught below.
4599 Ent
:= Entity
(Nam
);
4601 if Rep_Item_Too_Early
(Ent
, N
) then
4605 -- Rep clause applies to full view of incomplete type or private type if
4606 -- we have one (if not, this is a premature use of the type). However,
4607 -- certain semantic checks need to be done on the specified entity (i.e.
4608 -- the private view), so we save it in Ent.
4610 if Is_Private_Type
(Ent
)
4611 and then Is_Derived_Type
(Ent
)
4612 and then not Is_Tagged_Type
(Ent
)
4613 and then No
(Full_View
(Ent
))
4615 -- If this is a private type whose completion is a derivation from
4616 -- another private type, there is no full view, and the attribute
4617 -- belongs to the type itself, not its underlying parent.
4621 elsif Ekind
(Ent
) = E_Incomplete_Type
then
4623 -- The attribute applies to the full view, set the entity of the
4624 -- attribute definition accordingly.
4626 Ent
:= Underlying_Type
(Ent
);
4628 Set_Entity
(Nam
, Ent
);
4631 U_Ent
:= Underlying_Type
(Ent
);
4634 -- Avoid cascaded error
4636 if Etype
(Nam
) = Any_Type
then
4639 -- Must be declared in current scope or in case of an aspect
4640 -- specification, must be visible in current scope.
4642 elsif Scope
(Ent
) /= Current_Scope
4644 not (From_Aspect_Specification
(N
)
4645 and then Scope_Within_Or_Same
(Current_Scope
, Scope
(Ent
)))
4647 Error_Msg_N
("entity must be declared in this scope", Nam
);
4650 -- Must not be a source renaming (we do have some cases where the
4651 -- expander generates a renaming, and those cases are OK, in such
4652 -- cases any attribute applies to the renamed object as well).
4654 elsif Is_Object
(Ent
)
4655 and then Present
(Renamed_Object
(Ent
))
4657 -- Case of renamed object from source, this is an error
4659 if Comes_From_Source
(Renamed_Object
(Ent
)) then
4660 Get_Name_String
(Chars
(N
));
4661 Error_Msg_Strlen
:= Name_Len
;
4662 Error_Msg_String
(1 .. Name_Len
) := Name_Buffer
(1 .. Name_Len
);
4664 ("~ clause not allowed for a renaming declaration "
4665 & "(RM 13.1(6))", Nam
);
4668 -- For the case of a compiler generated renaming, the attribute
4669 -- definition clause applies to the renamed object created by the
4670 -- expander. The easiest general way to handle this is to create a
4671 -- copy of the attribute definition clause for this object.
4673 elsif Is_Entity_Name
(Renamed_Object
(Ent
)) then
4675 Make_Attribute_Definition_Clause
(Loc
,
4677 New_Occurrence_Of
(Entity
(Renamed_Object
(Ent
)), Loc
),
4679 Expression
=> Duplicate_Subexpr
(Expression
(N
))));
4681 -- If the renamed object is not an entity, it must be a dereference
4682 -- of an unconstrained function call, and we must introduce a new
4683 -- declaration to capture the expression. This is needed in the case
4684 -- of 'Alignment, where the original declaration must be rewritten.
4688 (Nkind
(Renamed_Object
(Ent
)) = N_Explicit_Dereference
);
4692 -- If no underlying entity, use entity itself, applies to some
4693 -- previously detected error cases ???
4695 elsif No
(U_Ent
) then
4698 -- Cannot specify for a subtype (exception Object/Value_Size)
4700 elsif Is_Type
(U_Ent
)
4701 and then not Is_First_Subtype
(U_Ent
)
4702 and then Id
/= Attribute_Object_Size
4703 and then Id
/= Attribute_Value_Size
4704 and then not From_At_Mod
(N
)
4706 Error_Msg_N
("cannot specify attribute for subtype", Nam
);
4710 Set_Entity
(N
, U_Ent
);
4712 -- Switch on particular attribute
4720 -- Address attribute definition clause
4722 when Attribute_Address
=> Address
: begin
4724 -- A little error check, catch for X'Address use X'Address;
4726 if Nkind
(Nam
) = N_Identifier
4727 and then Nkind
(Expr
) = N_Attribute_Reference
4728 and then Attribute_Name
(Expr
) = Name_Address
4729 and then Nkind
(Prefix
(Expr
)) = N_Identifier
4730 and then Chars
(Nam
) = Chars
(Prefix
(Expr
))
4733 ("address for & is self-referencing", Prefix
(Expr
), Ent
);
4737 -- Not that special case, carry on with analysis of expression
4739 Analyze_And_Resolve
(Expr
, RTE
(RE_Address
));
4741 -- Even when ignoring rep clauses we need to indicate that the
4742 -- entity has an address clause and thus it is legal to declare
4743 -- it imported. Freeze will get rid of the address clause later.
4745 if Ignore_Rep_Clauses
then
4746 if Ekind_In
(U_Ent
, E_Variable
, E_Constant
) then
4747 Record_Rep_Item
(U_Ent
, N
);
4753 if Duplicate_Clause
then
4756 -- Case of address clause for subprogram
4758 elsif Is_Subprogram
(U_Ent
) then
4759 if Has_Homonym
(U_Ent
) then
4761 ("address clause cannot be given " &
4762 "for overloaded subprogram",
4767 -- For subprograms, all address clauses are permitted, and we
4768 -- mark the subprogram as having a deferred freeze so that Gigi
4769 -- will not elaborate it too soon.
4771 -- Above needs more comments, what is too soon about???
4773 Set_Has_Delayed_Freeze
(U_Ent
);
4775 -- Case of address clause for entry
4777 elsif Ekind
(U_Ent
) = E_Entry
then
4778 if Nkind
(Parent
(N
)) = N_Task_Body
then
4780 ("entry address must be specified in task spec", Nam
);
4784 -- For entries, we require a constant address
4786 Check_Constant_Address_Clause
(Expr
, U_Ent
);
4788 -- Special checks for task types
4790 if Is_Task_Type
(Scope
(U_Ent
))
4791 and then Comes_From_Source
(Scope
(U_Ent
))
4794 ("??entry address declared for entry in task type", N
);
4796 ("\??only one task can be declared of this type", N
);
4799 -- Entry address clauses are obsolescent
4801 Check_Restriction
(No_Obsolescent_Features
, N
);
4803 if Warn_On_Obsolescent_Feature
then
4805 ("?j?attaching interrupt to task entry is an " &
4806 "obsolescent feature (RM J.7.1)", N
);
4808 ("\?j?use interrupt procedure instead", N
);
4811 -- Case of an address clause for a controlled object which we
4812 -- consider to be erroneous.
4814 elsif Is_Controlled
(Etype
(U_Ent
))
4815 or else Has_Controlled_Component
(Etype
(U_Ent
))
4818 ("??controlled object& must not be overlaid", Nam
, U_Ent
);
4820 ("\??Program_Error will be raised at run time", Nam
);
4821 Insert_Action
(Declaration_Node
(U_Ent
),
4822 Make_Raise_Program_Error
(Loc
,
4823 Reason
=> PE_Overlaid_Controlled_Object
));
4826 -- Case of address clause for a (non-controlled) object
4828 elsif Ekind_In
(U_Ent
, E_Variable
, E_Constant
) then
4830 Expr
: constant Node_Id
:= Expression
(N
);
4835 -- Exported variables cannot have an address clause, because
4836 -- this cancels the effect of the pragma Export.
4838 if Is_Exported
(U_Ent
) then
4840 ("cannot export object with address clause", Nam
);
4844 Find_Overlaid_Entity
(N
, O_Ent
, Off
);
4846 if Present
(O_Ent
) then
4848 -- If the object overlays a constant object, mark it so
4850 if Is_Constant_Object
(O_Ent
) then
4851 Set_Overlays_Constant
(U_Ent
);
4855 -- If this is not an overlay, mark a variable as being
4856 -- volatile to prevent unwanted optimizations. It's a
4857 -- conservative interpretation of RM 13.3(19) for the
4858 -- cases where the compiler cannot detect potential
4859 -- aliasing issues easily and it also covers the case
4860 -- of an absolute address where the volatile aspect is
4861 -- kind of implicit.
4863 if Ekind
(U_Ent
) = E_Variable
then
4864 Set_Treat_As_Volatile
(U_Ent
);
4868 -- Overlaying controlled objects is erroneous. Emit warning
4869 -- but continue analysis because program is itself legal,
4870 -- and back end must see address clause.
4873 and then (Has_Controlled_Component
(Etype
(O_Ent
))
4874 or else Is_Controlled
(Etype
(O_Ent
)))
4875 and then not Inside_A_Generic
4878 ("??cannot use overlays with controlled objects", Expr
);
4880 ("\??Program_Error will be raised at run time", Expr
);
4881 Insert_Action
(Declaration_Node
(U_Ent
),
4882 Make_Raise_Program_Error
(Loc
,
4883 Reason
=> PE_Overlaid_Controlled_Object
));
4885 -- Issue an unconditional warning for a constant overlaying
4886 -- a variable. For the reverse case, we will issue it only
4887 -- if the variable is modified.
4889 elsif Ekind
(U_Ent
) = E_Constant
4890 and then Present
(O_Ent
)
4891 and then not Overlays_Constant
(U_Ent
)
4892 and then Address_Clause_Overlay_Warnings
4894 Error_Msg_N
("??constant overlays a variable", Expr
);
4896 -- Imported variables can have an address clause, but then
4897 -- the import is pretty meaningless except to suppress
4898 -- initializations, so we do not need such variables to
4899 -- be statically allocated (and in fact it causes trouble
4900 -- if the address clause is a local value).
4902 elsif Is_Imported
(U_Ent
) then
4903 Set_Is_Statically_Allocated
(U_Ent
, False);
4906 -- We mark a possible modification of a variable with an
4907 -- address clause, since it is likely aliasing is occurring.
4909 Note_Possible_Modification
(Nam
, Sure
=> False);
4911 -- Legality checks on the address clause for initialized
4912 -- objects is deferred until the freeze point, because
4913 -- a subsequent pragma might indicate that the object
4914 -- is imported and thus not initialized. Also, the address
4915 -- clause might involve entities that have yet to be
4918 Set_Has_Delayed_Freeze
(U_Ent
);
4920 -- If an initialization call has been generated for this
4921 -- object, it needs to be deferred to after the freeze node
4922 -- we have just now added, otherwise GIGI will see a
4923 -- reference to the variable (as actual to the IP call)
4924 -- before its definition.
4927 Init_Call
: constant Node_Id
:=
4928 Remove_Init_Call
(U_Ent
, N
);
4931 if Present
(Init_Call
) then
4932 Append_Freeze_Action
(U_Ent
, Init_Call
);
4934 -- Reset Initialization_Statements pointer so that
4935 -- if there is a pragma Import further down, it can
4936 -- clear any default initialization.
4938 Set_Initialization_Statements
(U_Ent
, Init_Call
);
4942 -- Entity has delayed freeze, so we will generate an
4943 -- alignment check at the freeze point unless suppressed.
4945 if not Range_Checks_Suppressed
(U_Ent
)
4946 and then not Alignment_Checks_Suppressed
(U_Ent
)
4948 Set_Check_Address_Alignment
(N
);
4951 -- Kill the size check code, since we are not allocating
4952 -- the variable, it is somewhere else.
4954 Kill_Size_Check_Code
(U_Ent
);
4956 -- If the address clause is of the form:
4958 -- for Y'Address use X'Address
4962 -- Const : constant Address := X'Address;
4964 -- for Y'Address use Const;
4966 -- then we make an entry in the table for checking the size
4967 -- and alignment of the overlaying variable. We defer this
4968 -- check till after code generation to take full advantage
4969 -- of the annotation done by the back end.
4971 -- If the entity has a generic type, the check will be
4972 -- performed in the instance if the actual type justifies
4973 -- it, and we do not insert the clause in the table to
4974 -- prevent spurious warnings.
4976 -- Note: we used to test Comes_From_Source and only give
4977 -- this warning for source entities, but we have removed
4978 -- this test. It really seems bogus to generate overlays
4979 -- that would trigger this warning in generated code.
4980 -- Furthermore, by removing the test, we handle the
4981 -- aspect case properly.
4984 and then Is_Object
(O_Ent
)
4985 and then not Is_Generic_Type
(Etype
(U_Ent
))
4986 and then Address_Clause_Overlay_Warnings
4988 Address_Clause_Checks
.Append
((N
, U_Ent
, O_Ent
, Off
));
4992 -- Not a valid entity for an address clause
4995 Error_Msg_N
("address cannot be given for &", Nam
);
5003 -- Alignment attribute definition clause
5005 when Attribute_Alignment
=> Alignment
: declare
5006 Align
: constant Uint
:= Get_Alignment_Value
(Expr
);
5007 Max_Align
: constant Uint
:= UI_From_Int
(Maximum_Alignment
);
5012 if not Is_Type
(U_Ent
)
5013 and then Ekind
(U_Ent
) /= E_Variable
5014 and then Ekind
(U_Ent
) /= E_Constant
5016 Error_Msg_N
("alignment cannot be given for &", Nam
);
5018 elsif Duplicate_Clause
then
5021 elsif Align
/= No_Uint
then
5022 Set_Has_Alignment_Clause
(U_Ent
);
5024 -- Tagged type case, check for attempt to set alignment to a
5025 -- value greater than Max_Align, and reset if so.
5027 if Is_Tagged_Type
(U_Ent
) and then Align
> Max_Align
then
5029 ("alignment for & set to Maximum_Aligment??", Nam
);
5030 Set_Alignment
(U_Ent
, Max_Align
);
5035 Set_Alignment
(U_Ent
, Align
);
5038 -- For an array type, U_Ent is the first subtype. In that case,
5039 -- also set the alignment of the anonymous base type so that
5040 -- other subtypes (such as the itypes for aggregates of the
5041 -- type) also receive the expected alignment.
5043 if Is_Array_Type
(U_Ent
) then
5044 Set_Alignment
(Base_Type
(U_Ent
), Align
);
5053 -- Bit_Order attribute definition clause
5055 when Attribute_Bit_Order
=> Bit_Order
: declare
5057 if not Is_Record_Type
(U_Ent
) then
5059 ("Bit_Order can only be defined for record type", Nam
);
5061 elsif Duplicate_Clause
then
5065 Analyze_And_Resolve
(Expr
, RTE
(RE_Bit_Order
));
5067 if Etype
(Expr
) = Any_Type
then
5070 elsif not Is_OK_Static_Expression
(Expr
) then
5071 Flag_Non_Static_Expr
5072 ("Bit_Order requires static expression!", Expr
);
5075 if (Expr_Value
(Expr
) = 0) /= Bytes_Big_Endian
then
5076 Set_Reverse_Bit_Order
(Base_Type
(U_Ent
), True);
5082 --------------------
5083 -- Component_Size --
5084 --------------------
5086 -- Component_Size attribute definition clause
5088 when Attribute_Component_Size
=> Component_Size_Case
: declare
5089 Csize
: constant Uint
:= Static_Integer
(Expr
);
5093 New_Ctyp
: Entity_Id
;
5097 if not Is_Array_Type
(U_Ent
) then
5098 Error_Msg_N
("component size requires array type", Nam
);
5102 Btype
:= Base_Type
(U_Ent
);
5103 Ctyp
:= Component_Type
(Btype
);
5105 if Duplicate_Clause
then
5108 elsif Rep_Item_Too_Early
(Btype
, N
) then
5111 elsif Csize
/= No_Uint
then
5112 Check_Size
(Expr
, Ctyp
, Csize
, Biased
);
5114 -- For the biased case, build a declaration for a subtype that
5115 -- will be used to represent the biased subtype that reflects
5116 -- the biased representation of components. We need the subtype
5117 -- to get proper conversions on referencing elements of the
5122 Make_Defining_Identifier
(Loc
,
5124 New_External_Name
(Chars
(U_Ent
), 'C', 0, 'T'));
5127 Make_Subtype_Declaration
(Loc
,
5128 Defining_Identifier
=> New_Ctyp
,
5129 Subtype_Indication
=>
5130 New_Occurrence_Of
(Component_Type
(Btype
), Loc
));
5132 Set_Parent
(Decl
, N
);
5133 Analyze
(Decl
, Suppress
=> All_Checks
);
5135 Set_Has_Delayed_Freeze
(New_Ctyp
, False);
5136 Set_Esize
(New_Ctyp
, Csize
);
5137 Set_RM_Size
(New_Ctyp
, Csize
);
5138 Init_Alignment
(New_Ctyp
);
5139 Set_Is_Itype
(New_Ctyp
, True);
5140 Set_Associated_Node_For_Itype
(New_Ctyp
, U_Ent
);
5142 Set_Component_Type
(Btype
, New_Ctyp
);
5143 Set_Biased
(New_Ctyp
, N
, "component size clause");
5146 Set_Component_Size
(Btype
, Csize
);
5148 -- Deal with warning on overridden size
5150 if Warn_On_Overridden_Size
5151 and then Has_Size_Clause
(Ctyp
)
5152 and then RM_Size
(Ctyp
) /= Csize
5155 ("component size overrides size clause for&?S?", N
, Ctyp
);
5158 Set_Has_Component_Size_Clause
(Btype
, True);
5159 Set_Has_Non_Standard_Rep
(Btype
, True);
5161 end Component_Size_Case
;
5163 -----------------------
5164 -- Constant_Indexing --
5165 -----------------------
5167 when Attribute_Constant_Indexing
=>
5168 Check_Indexing_Functions
;
5174 when Attribute_CPU
=> CPU
:
5176 -- CPU attribute definition clause not allowed except from aspect
5179 if From_Aspect_Specification
(N
) then
5180 if not Is_Task_Type
(U_Ent
) then
5181 Error_Msg_N
("CPU can only be defined for task", Nam
);
5183 elsif Duplicate_Clause
then
5187 -- The expression must be analyzed in the special manner
5188 -- described in "Handling of Default and Per-Object
5189 -- Expressions" in sem.ads.
5191 -- The visibility to the discriminants must be restored
5193 Push_Scope_And_Install_Discriminants
(U_Ent
);
5194 Preanalyze_Spec_Expression
(Expr
, RTE
(RE_CPU_Range
));
5195 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
5197 if not Is_OK_Static_Expression
(Expr
) then
5198 Check_Restriction
(Static_Priorities
, Expr
);
5204 ("attribute& cannot be set with definition clause", N
);
5208 ----------------------
5209 -- Default_Iterator --
5210 ----------------------
5212 when Attribute_Default_Iterator
=> Default_Iterator
: declare
5217 -- If target type is untagged, further checks are irrelevant
5219 if not Is_Tagged_Type
(U_Ent
) then
5221 ("aspect Default_Iterator applies to tagged type", Nam
);
5225 Check_Iterator_Functions
;
5229 if not Is_Entity_Name
(Expr
)
5230 or else Ekind
(Entity
(Expr
)) /= E_Function
5232 Error_Msg_N
("aspect Iterator must be a function", Expr
);
5235 Func
:= Entity
(Expr
);
5238 -- The type of the first parameter must be T, T'class, or a
5239 -- corresponding access type (5.5.1 (8/3). If function is
5240 -- parameterless label type accordingly.
5242 if No
(First_Formal
(Func
)) then
5245 Typ
:= Etype
(First_Formal
(Func
));
5249 or else Typ
= Class_Wide_Type
(U_Ent
)
5250 or else (Is_Access_Type
(Typ
)
5251 and then Designated_Type
(Typ
) = U_Ent
)
5252 or else (Is_Access_Type
(Typ
)
5253 and then Designated_Type
(Typ
) =
5254 Class_Wide_Type
(U_Ent
))
5260 ("Default Iterator must be a primitive of&", Func
, U_Ent
);
5262 end Default_Iterator
;
5264 ------------------------
5265 -- Dispatching_Domain --
5266 ------------------------
5268 when Attribute_Dispatching_Domain
=> Dispatching_Domain
:
5270 -- Dispatching_Domain attribute definition clause not allowed
5271 -- except from aspect specification.
5273 if From_Aspect_Specification
(N
) then
5274 if not Is_Task_Type
(U_Ent
) then
5276 ("Dispatching_Domain can only be defined for task", Nam
);
5278 elsif Duplicate_Clause
then
5282 -- The expression must be analyzed in the special manner
5283 -- described in "Handling of Default and Per-Object
5284 -- Expressions" in sem.ads.
5286 -- The visibility to the discriminants must be restored
5288 Push_Scope_And_Install_Discriminants
(U_Ent
);
5290 Preanalyze_Spec_Expression
5291 (Expr
, RTE
(RE_Dispatching_Domain
));
5293 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
5298 ("attribute& cannot be set with definition clause", N
);
5300 end Dispatching_Domain
;
5306 when Attribute_External_Tag
=> External_Tag
:
5308 if not Is_Tagged_Type
(U_Ent
) then
5309 Error_Msg_N
("should be a tagged type", Nam
);
5312 if Duplicate_Clause
then
5316 Analyze_And_Resolve
(Expr
, Standard_String
);
5318 if not Is_OK_Static_Expression
(Expr
) then
5319 Flag_Non_Static_Expr
5320 ("static string required for tag name!", Nam
);
5323 if not Is_Library_Level_Entity
(U_Ent
) then
5325 ("??non-unique external tag supplied for &", N
, U_Ent
);
5327 ("\??same external tag applies to all "
5328 & "subprogram calls", N
);
5330 ("\??corresponding internal tag cannot be obtained", N
);
5335 --------------------------
5336 -- Implicit_Dereference --
5337 --------------------------
5339 when Attribute_Implicit_Dereference
=>
5341 -- Legality checks already performed at the point of the type
5342 -- declaration, aspect is not delayed.
5350 when Attribute_Input
=>
5351 Analyze_Stream_TSS_Definition
(TSS_Stream_Input
);
5352 Set_Has_Specified_Stream_Input
(Ent
);
5354 ------------------------
5355 -- Interrupt_Priority --
5356 ------------------------
5358 when Attribute_Interrupt_Priority
=> Interrupt_Priority
:
5360 -- Interrupt_Priority attribute definition clause not allowed
5361 -- except from aspect specification.
5363 if From_Aspect_Specification
(N
) then
5364 if not Is_Concurrent_Type
(U_Ent
) then
5366 ("Interrupt_Priority can only be defined for task "
5367 & "and protected object", Nam
);
5369 elsif Duplicate_Clause
then
5373 -- The expression must be analyzed in the special manner
5374 -- described in "Handling of Default and Per-Object
5375 -- Expressions" in sem.ads.
5377 -- The visibility to the discriminants must be restored
5379 Push_Scope_And_Install_Discriminants
(U_Ent
);
5381 Preanalyze_Spec_Expression
5382 (Expr
, RTE
(RE_Interrupt_Priority
));
5384 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
5386 -- Check the No_Task_At_Interrupt_Priority restriction
5388 if Is_Task_Type
(U_Ent
) then
5389 Check_Restriction
(No_Task_At_Interrupt_Priority
, N
);
5395 ("attribute& cannot be set with definition clause", N
);
5397 end Interrupt_Priority
;
5403 when Attribute_Iterable
=>
5406 if Nkind
(Expr
) /= N_Aggregate
then
5407 Error_Msg_N
("aspect Iterable must be an aggregate", Expr
);
5414 Assoc
:= First
(Component_Associations
(Expr
));
5415 while Present
(Assoc
) loop
5416 if not Is_Entity_Name
(Expression
(Assoc
)) then
5417 Error_Msg_N
("value must be a function", Assoc
);
5424 ----------------------
5425 -- Iterator_Element --
5426 ----------------------
5428 when Attribute_Iterator_Element
=>
5431 if not Is_Entity_Name
(Expr
)
5432 or else not Is_Type
(Entity
(Expr
))
5434 Error_Msg_N
("aspect Iterator_Element must be a type", Expr
);
5441 -- Machine radix attribute definition clause
5443 when Attribute_Machine_Radix
=> Machine_Radix
: declare
5444 Radix
: constant Uint
:= Static_Integer
(Expr
);
5447 if not Is_Decimal_Fixed_Point_Type
(U_Ent
) then
5448 Error_Msg_N
("decimal fixed-point type expected for &", Nam
);
5450 elsif Duplicate_Clause
then
5453 elsif Radix
/= No_Uint
then
5454 Set_Has_Machine_Radix_Clause
(U_Ent
);
5455 Set_Has_Non_Standard_Rep
(Base_Type
(U_Ent
));
5459 elsif Radix
= 10 then
5460 Set_Machine_Radix_10
(U_Ent
);
5462 Error_Msg_N
("machine radix value must be 2 or 10", Expr
);
5471 -- Object_Size attribute definition clause
5473 when Attribute_Object_Size
=> Object_Size
: declare
5474 Size
: constant Uint
:= Static_Integer
(Expr
);
5477 pragma Warnings
(Off
, Biased
);
5480 if not Is_Type
(U_Ent
) then
5481 Error_Msg_N
("Object_Size cannot be given for &", Nam
);
5483 elsif Duplicate_Clause
then
5487 Check_Size
(Expr
, U_Ent
, Size
, Biased
);
5489 if Is_Scalar_Type
(U_Ent
) then
5490 if Size
/= 8 and then Size
/= 16 and then Size
/= 32
5491 and then UI_Mod
(Size
, 64) /= 0
5494 ("Object_Size must be 8, 16, 32, or multiple of 64",
5498 elsif Size
mod 8 /= 0 then
5499 Error_Msg_N
("Object_Size must be a multiple of 8", Expr
);
5502 Set_Esize
(U_Ent
, Size
);
5503 Set_Has_Object_Size_Clause
(U_Ent
);
5504 Alignment_Check_For_Size_Change
(U_Ent
, Size
);
5512 when Attribute_Output
=>
5513 Analyze_Stream_TSS_Definition
(TSS_Stream_Output
);
5514 Set_Has_Specified_Stream_Output
(Ent
);
5520 when Attribute_Priority
=> Priority
:
5522 -- Priority attribute definition clause not allowed except from
5523 -- aspect specification.
5525 if From_Aspect_Specification
(N
) then
5526 if not (Is_Concurrent_Type
(U_Ent
)
5527 or else Ekind
(U_Ent
) = E_Procedure
)
5530 ("Priority can only be defined for task and protected "
5533 elsif Duplicate_Clause
then
5537 -- The expression must be analyzed in the special manner
5538 -- described in "Handling of Default and Per-Object
5539 -- Expressions" in sem.ads.
5541 -- The visibility to the discriminants must be restored
5543 Push_Scope_And_Install_Discriminants
(U_Ent
);
5544 Preanalyze_Spec_Expression
(Expr
, Standard_Integer
);
5545 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
5547 if not Is_OK_Static_Expression
(Expr
) then
5548 Check_Restriction
(Static_Priorities
, Expr
);
5554 ("attribute& cannot be set with definition clause", N
);
5562 when Attribute_Read
=>
5563 Analyze_Stream_TSS_Definition
(TSS_Stream_Read
);
5564 Set_Has_Specified_Stream_Read
(Ent
);
5566 --------------------------
5567 -- Scalar_Storage_Order --
5568 --------------------------
5570 -- Scalar_Storage_Order attribute definition clause
5572 when Attribute_Scalar_Storage_Order
=> Scalar_Storage_Order
: declare
5574 if not (Is_Record_Type
(U_Ent
) or else Is_Array_Type
(U_Ent
)) then
5576 ("Scalar_Storage_Order can only be defined for "
5577 & "record or array type", Nam
);
5579 elsif Duplicate_Clause
then
5583 Analyze_And_Resolve
(Expr
, RTE
(RE_Bit_Order
));
5585 if Etype
(Expr
) = Any_Type
then
5588 elsif not Is_OK_Static_Expression
(Expr
) then
5589 Flag_Non_Static_Expr
5590 ("Scalar_Storage_Order requires static expression!", Expr
);
5592 elsif (Expr_Value
(Expr
) = 0) /= Bytes_Big_Endian
then
5594 -- Here for the case of a non-default (i.e. non-confirming)
5595 -- Scalar_Storage_Order attribute definition.
5597 if Support_Nondefault_SSO_On_Target
then
5598 Set_Reverse_Storage_Order
(Base_Type
(U_Ent
), True);
5601 ("non-default Scalar_Storage_Order "
5602 & "not supported on target", Expr
);
5606 -- Clear SSO default indications since explicit setting of the
5607 -- order overrides the defaults.
5609 Set_SSO_Set_Low_By_Default
(Base_Type
(U_Ent
), False);
5610 Set_SSO_Set_High_By_Default
(Base_Type
(U_Ent
), False);
5612 end Scalar_Storage_Order
;
5618 -- Size attribute definition clause
5620 when Attribute_Size
=> Size
: declare
5621 Size
: constant Uint
:= Static_Integer
(Expr
);
5628 if Duplicate_Clause
then
5631 elsif not Is_Type
(U_Ent
)
5632 and then Ekind
(U_Ent
) /= E_Variable
5633 and then Ekind
(U_Ent
) /= E_Constant
5635 Error_Msg_N
("size cannot be given for &", Nam
);
5637 elsif Is_Array_Type
(U_Ent
)
5638 and then not Is_Constrained
(U_Ent
)
5641 ("size cannot be given for unconstrained array", Nam
);
5643 elsif Size
/= No_Uint
then
5644 if Is_Type
(U_Ent
) then
5647 Etyp
:= Etype
(U_Ent
);
5650 -- Check size, note that Gigi is in charge of checking that the
5651 -- size of an array or record type is OK. Also we do not check
5652 -- the size in the ordinary fixed-point case, since it is too
5653 -- early to do so (there may be subsequent small clause that
5654 -- affects the size). We can check the size if a small clause
5655 -- has already been given.
5657 if not Is_Ordinary_Fixed_Point_Type
(U_Ent
)
5658 or else Has_Small_Clause
(U_Ent
)
5660 Check_Size
(Expr
, Etyp
, Size
, Biased
);
5661 Set_Biased
(U_Ent
, N
, "size clause", Biased
);
5664 -- For types set RM_Size and Esize if possible
5666 if Is_Type
(U_Ent
) then
5667 Set_RM_Size
(U_Ent
, Size
);
5669 -- For elementary types, increase Object_Size to power of 2,
5670 -- but not less than a storage unit in any case (normally
5671 -- this means it will be byte addressable).
5673 -- For all other types, nothing else to do, we leave Esize
5674 -- (object size) unset, the back end will set it from the
5675 -- size and alignment in an appropriate manner.
5677 -- In both cases, we check whether the alignment must be
5678 -- reset in the wake of the size change.
5680 if Is_Elementary_Type
(U_Ent
) then
5681 if Size
<= System_Storage_Unit
then
5682 Init_Esize
(U_Ent
, System_Storage_Unit
);
5683 elsif Size
<= 16 then
5684 Init_Esize
(U_Ent
, 16);
5685 elsif Size
<= 32 then
5686 Init_Esize
(U_Ent
, 32);
5688 Set_Esize
(U_Ent
, (Size
+ 63) / 64 * 64);
5691 Alignment_Check_For_Size_Change
(U_Ent
, Esize
(U_Ent
));
5693 Alignment_Check_For_Size_Change
(U_Ent
, Size
);
5696 -- For objects, set Esize only
5699 if Is_Elementary_Type
(Etyp
) then
5700 if Size
/= System_Storage_Unit
5702 Size
/= System_Storage_Unit
* 2
5704 Size
/= System_Storage_Unit
* 4
5706 Size
/= System_Storage_Unit
* 8
5708 Error_Msg_Uint_1
:= UI_From_Int
(System_Storage_Unit
);
5709 Error_Msg_Uint_2
:= Error_Msg_Uint_1
* 8;
5711 ("size for primitive object must be a power of 2"
5712 & " in the range ^-^", N
);
5716 Set_Esize
(U_Ent
, Size
);
5719 Set_Has_Size_Clause
(U_Ent
);
5727 -- Small attribute definition clause
5729 when Attribute_Small
=> Small
: declare
5730 Implicit_Base
: constant Entity_Id
:= Base_Type
(U_Ent
);
5734 Analyze_And_Resolve
(Expr
, Any_Real
);
5736 if Etype
(Expr
) = Any_Type
then
5739 elsif not Is_OK_Static_Expression
(Expr
) then
5740 Flag_Non_Static_Expr
5741 ("small requires static expression!", Expr
);
5745 Small
:= Expr_Value_R
(Expr
);
5747 if Small
<= Ureal_0
then
5748 Error_Msg_N
("small value must be greater than zero", Expr
);
5754 if not Is_Ordinary_Fixed_Point_Type
(U_Ent
) then
5756 ("small requires an ordinary fixed point type", Nam
);
5758 elsif Has_Small_Clause
(U_Ent
) then
5759 Error_Msg_N
("small already given for &", Nam
);
5761 elsif Small
> Delta_Value
(U_Ent
) then
5763 ("small value must not be greater than delta value", Nam
);
5766 Set_Small_Value
(U_Ent
, Small
);
5767 Set_Small_Value
(Implicit_Base
, Small
);
5768 Set_Has_Small_Clause
(U_Ent
);
5769 Set_Has_Small_Clause
(Implicit_Base
);
5770 Set_Has_Non_Standard_Rep
(Implicit_Base
);
5778 -- Storage_Pool attribute definition clause
5780 when Attribute_Storage_Pool | Attribute_Simple_Storage_Pool
=> declare
5785 if Ekind
(U_Ent
) = E_Access_Subprogram_Type
then
5787 ("storage pool cannot be given for access-to-subprogram type",
5792 Ekind_In
(U_Ent
, E_Access_Type
, E_General_Access_Type
)
5795 ("storage pool can only be given for access types", Nam
);
5798 elsif Is_Derived_Type
(U_Ent
) then
5800 ("storage pool cannot be given for a derived access type",
5803 elsif Duplicate_Clause
then
5806 elsif Present
(Associated_Storage_Pool
(U_Ent
)) then
5807 Error_Msg_N
("storage pool already given for &", Nam
);
5811 -- Check for Storage_Size previously given
5814 SS
: constant Node_Id
:=
5815 Get_Attribute_Definition_Clause
5816 (U_Ent
, Attribute_Storage_Size
);
5818 if Present
(SS
) then
5819 Check_Pool_Size_Clash
(U_Ent
, N
, SS
);
5823 -- Storage_Pool case
5825 if Id
= Attribute_Storage_Pool
then
5827 (Expr
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
5829 -- In the Simple_Storage_Pool case, we allow a variable of any
5830 -- simple storage pool type, so we Resolve without imposing an
5834 Analyze_And_Resolve
(Expr
);
5836 if not Present
(Get_Rep_Pragma
5837 (Etype
(Expr
), Name_Simple_Storage_Pool_Type
))
5840 ("expression must be of a simple storage pool type", Expr
);
5844 if not Denotes_Variable
(Expr
) then
5845 Error_Msg_N
("storage pool must be a variable", Expr
);
5849 if Nkind
(Expr
) = N_Type_Conversion
then
5850 T
:= Etype
(Expression
(Expr
));
5855 -- The Stack_Bounded_Pool is used internally for implementing
5856 -- access types with a Storage_Size. Since it only work properly
5857 -- when used on one specific type, we need to check that it is not
5858 -- hijacked improperly:
5860 -- type T is access Integer;
5861 -- for T'Storage_Size use n;
5862 -- type Q is access Float;
5863 -- for Q'Storage_Size use T'Storage_Size; -- incorrect
5865 if RTE_Available
(RE_Stack_Bounded_Pool
)
5866 and then Base_Type
(T
) = RTE
(RE_Stack_Bounded_Pool
)
5868 Error_Msg_N
("non-shareable internal Pool", Expr
);
5872 -- If the argument is a name that is not an entity name, then
5873 -- we construct a renaming operation to define an entity of
5874 -- type storage pool.
5876 if not Is_Entity_Name
(Expr
)
5877 and then Is_Object_Reference
(Expr
)
5879 Pool
:= Make_Temporary
(Loc
, 'P', Expr
);
5882 Rnode
: constant Node_Id
:=
5883 Make_Object_Renaming_Declaration
(Loc
,
5884 Defining_Identifier
=> Pool
,
5886 New_Occurrence_Of
(Etype
(Expr
), Loc
),
5890 -- If the attribute definition clause comes from an aspect
5891 -- clause, then insert the renaming before the associated
5892 -- entity's declaration, since the attribute clause has
5893 -- not yet been appended to the declaration list.
5895 if From_Aspect_Specification
(N
) then
5896 Insert_Before
(Parent
(Entity
(N
)), Rnode
);
5898 Insert_Before
(N
, Rnode
);
5902 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
5905 elsif Is_Entity_Name
(Expr
) then
5906 Pool
:= Entity
(Expr
);
5908 -- If pool is a renamed object, get original one. This can
5909 -- happen with an explicit renaming, and within instances.
5911 while Present
(Renamed_Object
(Pool
))
5912 and then Is_Entity_Name
(Renamed_Object
(Pool
))
5914 Pool
:= Entity
(Renamed_Object
(Pool
));
5917 if Present
(Renamed_Object
(Pool
))
5918 and then Nkind
(Renamed_Object
(Pool
)) = N_Type_Conversion
5919 and then Is_Entity_Name
(Expression
(Renamed_Object
(Pool
)))
5921 Pool
:= Entity
(Expression
(Renamed_Object
(Pool
)));
5924 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
5926 elsif Nkind
(Expr
) = N_Type_Conversion
5927 and then Is_Entity_Name
(Expression
(Expr
))
5928 and then Nkind
(Original_Node
(Expr
)) = N_Attribute_Reference
5930 Pool
:= Entity
(Expression
(Expr
));
5931 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
5934 Error_Msg_N
("incorrect reference to a Storage Pool", Expr
);
5943 -- Storage_Size attribute definition clause
5945 when Attribute_Storage_Size
=> Storage_Size
: declare
5946 Btype
: constant Entity_Id
:= Base_Type
(U_Ent
);
5949 if Is_Task_Type
(U_Ent
) then
5951 -- Check obsolescent (but never obsolescent if from aspect)
5953 if not From_Aspect_Specification
(N
) then
5954 Check_Restriction
(No_Obsolescent_Features
, N
);
5956 if Warn_On_Obsolescent_Feature
then
5958 ("?j?storage size clause for task is an " &
5959 "obsolescent feature (RM J.9)", N
);
5960 Error_Msg_N
("\?j?use Storage_Size pragma instead", N
);
5967 if not Is_Access_Type
(U_Ent
)
5968 and then Ekind
(U_Ent
) /= E_Task_Type
5970 Error_Msg_N
("storage size cannot be given for &", Nam
);
5972 elsif Is_Access_Type
(U_Ent
) and Is_Derived_Type
(U_Ent
) then
5974 ("storage size cannot be given for a derived access type",
5977 elsif Duplicate_Clause
then
5981 Analyze_And_Resolve
(Expr
, Any_Integer
);
5983 if Is_Access_Type
(U_Ent
) then
5985 -- Check for Storage_Pool previously given
5988 SP
: constant Node_Id
:=
5989 Get_Attribute_Definition_Clause
5990 (U_Ent
, Attribute_Storage_Pool
);
5993 if Present
(SP
) then
5994 Check_Pool_Size_Clash
(U_Ent
, SP
, N
);
5998 -- Special case of for x'Storage_Size use 0
6000 if Is_OK_Static_Expression
(Expr
)
6001 and then Expr_Value
(Expr
) = 0
6003 Set_No_Pool_Assigned
(Btype
);
6007 Set_Has_Storage_Size_Clause
(Btype
);
6015 when Attribute_Stream_Size
=> Stream_Size
: declare
6016 Size
: constant Uint
:= Static_Integer
(Expr
);
6019 if Ada_Version
<= Ada_95
then
6020 Check_Restriction
(No_Implementation_Attributes
, N
);
6023 if Duplicate_Clause
then
6026 elsif Is_Elementary_Type
(U_Ent
) then
6027 if Size
/= System_Storage_Unit
6029 Size
/= System_Storage_Unit
* 2
6031 Size
/= System_Storage_Unit
* 4
6033 Size
/= System_Storage_Unit
* 8
6035 Error_Msg_Uint_1
:= UI_From_Int
(System_Storage_Unit
);
6037 ("stream size for elementary type must be a"
6038 & " power of 2 and at least ^", N
);
6040 elsif RM_Size
(U_Ent
) > Size
then
6041 Error_Msg_Uint_1
:= RM_Size
(U_Ent
);
6043 ("stream size for elementary type must be a"
6044 & " power of 2 and at least ^", N
);
6047 Set_Has_Stream_Size_Clause
(U_Ent
);
6050 Error_Msg_N
("Stream_Size cannot be given for &", Nam
);
6058 -- Value_Size attribute definition clause
6060 when Attribute_Value_Size
=> Value_Size
: declare
6061 Size
: constant Uint
:= Static_Integer
(Expr
);
6065 if not Is_Type
(U_Ent
) then
6066 Error_Msg_N
("Value_Size cannot be given for &", Nam
);
6068 elsif Duplicate_Clause
then
6071 elsif Is_Array_Type
(U_Ent
)
6072 and then not Is_Constrained
(U_Ent
)
6075 ("Value_Size cannot be given for unconstrained array", Nam
);
6078 if Is_Elementary_Type
(U_Ent
) then
6079 Check_Size
(Expr
, U_Ent
, Size
, Biased
);
6080 Set_Biased
(U_Ent
, N
, "value size clause", Biased
);
6083 Set_RM_Size
(U_Ent
, Size
);
6087 -----------------------
6088 -- Variable_Indexing --
6089 -----------------------
6091 when Attribute_Variable_Indexing
=>
6092 Check_Indexing_Functions
;
6098 when Attribute_Write
=>
6099 Analyze_Stream_TSS_Definition
(TSS_Stream_Write
);
6100 Set_Has_Specified_Stream_Write
(Ent
);
6102 -- All other attributes cannot be set
6106 ("attribute& cannot be set with definition clause", N
);
6109 -- The test for the type being frozen must be performed after any
6110 -- expression the clause has been analyzed since the expression itself
6111 -- might cause freezing that makes the clause illegal.
6113 if Rep_Item_Too_Late
(U_Ent
, N
, FOnly
) then
6116 end Analyze_Attribute_Definition_Clause
;
6118 ----------------------------
6119 -- Analyze_Code_Statement --
6120 ----------------------------
6122 procedure Analyze_Code_Statement
(N
: Node_Id
) is
6123 HSS
: constant Node_Id
:= Parent
(N
);
6124 SBody
: constant Node_Id
:= Parent
(HSS
);
6125 Subp
: constant Entity_Id
:= Current_Scope
;
6132 -- Accept foreign code statements for CodePeer. The analysis is skipped
6133 -- to avoid rejecting unrecognized constructs.
6135 if CodePeer_Mode
then
6140 -- Analyze and check we get right type, note that this implements the
6141 -- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that is
6142 -- the only way that Asm_Insn could possibly be visible.
6144 Analyze_And_Resolve
(Expression
(N
));
6146 if Etype
(Expression
(N
)) = Any_Type
then
6148 elsif Etype
(Expression
(N
)) /= RTE
(RE_Asm_Insn
) then
6149 Error_Msg_N
("incorrect type for code statement", N
);
6153 Check_Code_Statement
(N
);
6155 -- Make sure we appear in the handled statement sequence of a subprogram
6158 if Nkind
(HSS
) /= N_Handled_Sequence_Of_Statements
6159 or else Nkind
(SBody
) /= N_Subprogram_Body
6162 ("code statement can only appear in body of subprogram", N
);
6166 -- Do remaining checks (RM 13.8(3)) if not already done
6168 if not Is_Machine_Code_Subprogram
(Subp
) then
6169 Set_Is_Machine_Code_Subprogram
(Subp
);
6171 -- No exception handlers allowed
6173 if Present
(Exception_Handlers
(HSS
)) then
6175 ("exception handlers not permitted in machine code subprogram",
6176 First
(Exception_Handlers
(HSS
)));
6179 -- No declarations other than use clauses and pragmas (we allow
6180 -- certain internally generated declarations as well).
6182 Decl
:= First
(Declarations
(SBody
));
6183 while Present
(Decl
) loop
6184 DeclO
:= Original_Node
(Decl
);
6185 if Comes_From_Source
(DeclO
)
6186 and not Nkind_In
(DeclO
, N_Pragma
,
6187 N_Use_Package_Clause
,
6189 N_Implicit_Label_Declaration
)
6192 ("this declaration not allowed in machine code subprogram",
6199 -- No statements other than code statements, pragmas, and labels.
6200 -- Again we allow certain internally generated statements.
6202 -- In Ada 2012, qualified expressions are names, and the code
6203 -- statement is initially parsed as a procedure call.
6205 Stmt
:= First
(Statements
(HSS
));
6206 while Present
(Stmt
) loop
6207 StmtO
:= Original_Node
(Stmt
);
6209 -- A procedure call transformed into a code statement is OK
6211 if Ada_Version
>= Ada_2012
6212 and then Nkind
(StmtO
) = N_Procedure_Call_Statement
6213 and then Nkind
(Name
(StmtO
)) = N_Qualified_Expression
6217 elsif Comes_From_Source
(StmtO
)
6218 and then not Nkind_In
(StmtO
, N_Pragma
,
6223 ("this statement is not allowed in machine code subprogram",
6230 end Analyze_Code_Statement
;
6232 -----------------------------------------------
6233 -- Analyze_Enumeration_Representation_Clause --
6234 -----------------------------------------------
6236 procedure Analyze_Enumeration_Representation_Clause
(N
: Node_Id
) is
6237 Ident
: constant Node_Id
:= Identifier
(N
);
6238 Aggr
: constant Node_Id
:= Array_Aggregate
(N
);
6239 Enumtype
: Entity_Id
;
6246 Err
: Boolean := False;
6247 -- Set True to avoid cascade errors and crashes on incorrect source code
6249 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Universal_Integer
));
6250 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(Universal_Integer
));
6251 -- Allowed range of universal integer (= allowed range of enum lit vals)
6255 -- Minimum and maximum values of entries
6258 -- Pointer to node for literal providing max value
6261 if Ignore_Rep_Clauses
then
6262 Kill_Rep_Clause
(N
);
6266 -- Ignore enumeration rep clauses by default in CodePeer mode,
6267 -- unless -gnatd.I is specified, as a work around for potential false
6268 -- positive messages.
6270 if CodePeer_Mode
and not Debug_Flag_Dot_II
then
6274 -- First some basic error checks
6277 Enumtype
:= Entity
(Ident
);
6279 if Enumtype
= Any_Type
6280 or else Rep_Item_Too_Early
(Enumtype
, N
)
6284 Enumtype
:= Underlying_Type
(Enumtype
);
6287 if not Is_Enumeration_Type
(Enumtype
) then
6289 ("enumeration type required, found}",
6290 Ident
, First_Subtype
(Enumtype
));
6294 -- Ignore rep clause on generic actual type. This will already have
6295 -- been flagged on the template as an error, and this is the safest
6296 -- way to ensure we don't get a junk cascaded message in the instance.
6298 if Is_Generic_Actual_Type
(Enumtype
) then
6301 -- Type must be in current scope
6303 elsif Scope
(Enumtype
) /= Current_Scope
then
6304 Error_Msg_N
("type must be declared in this scope", Ident
);
6307 -- Type must be a first subtype
6309 elsif not Is_First_Subtype
(Enumtype
) then
6310 Error_Msg_N
("cannot give enumeration rep clause for subtype", N
);
6313 -- Ignore duplicate rep clause
6315 elsif Has_Enumeration_Rep_Clause
(Enumtype
) then
6316 Error_Msg_N
("duplicate enumeration rep clause ignored", N
);
6319 -- Don't allow rep clause for standard [wide_[wide_]]character
6321 elsif Is_Standard_Character_Type
(Enumtype
) then
6322 Error_Msg_N
("enumeration rep clause not allowed for this type", N
);
6325 -- Check that the expression is a proper aggregate (no parentheses)
6327 elsif Paren_Count
(Aggr
) /= 0 then
6329 ("extra parentheses surrounding aggregate not allowed",
6333 -- All tests passed, so set rep clause in place
6336 Set_Has_Enumeration_Rep_Clause
(Enumtype
);
6337 Set_Has_Enumeration_Rep_Clause
(Base_Type
(Enumtype
));
6340 -- Now we process the aggregate. Note that we don't use the normal
6341 -- aggregate code for this purpose, because we don't want any of the
6342 -- normal expansion activities, and a number of special semantic
6343 -- rules apply (including the component type being any integer type)
6345 Elit
:= First_Literal
(Enumtype
);
6347 -- First the positional entries if any
6349 if Present
(Expressions
(Aggr
)) then
6350 Expr
:= First
(Expressions
(Aggr
));
6351 while Present
(Expr
) loop
6353 Error_Msg_N
("too many entries in aggregate", Expr
);
6357 Val
:= Static_Integer
(Expr
);
6359 -- Err signals that we found some incorrect entries processing
6360 -- the list. The final checks for completeness and ordering are
6361 -- skipped in this case.
6363 if Val
= No_Uint
then
6366 elsif Val
< Lo
or else Hi
< Val
then
6367 Error_Msg_N
("value outside permitted range", Expr
);
6371 Set_Enumeration_Rep
(Elit
, Val
);
6372 Set_Enumeration_Rep_Expr
(Elit
, Expr
);
6378 -- Now process the named entries if present
6380 if Present
(Component_Associations
(Aggr
)) then
6381 Assoc
:= First
(Component_Associations
(Aggr
));
6382 while Present
(Assoc
) loop
6383 Choice
:= First
(Choices
(Assoc
));
6385 if Present
(Next
(Choice
)) then
6387 ("multiple choice not allowed here", Next
(Choice
));
6391 if Nkind
(Choice
) = N_Others_Choice
then
6392 Error_Msg_N
("others choice not allowed here", Choice
);
6395 elsif Nkind
(Choice
) = N_Range
then
6397 -- ??? should allow zero/one element range here
6399 Error_Msg_N
("range not allowed here", Choice
);
6403 Analyze_And_Resolve
(Choice
, Enumtype
);
6405 if Error_Posted
(Choice
) then
6410 if Is_Entity_Name
(Choice
)
6411 and then Is_Type
(Entity
(Choice
))
6413 Error_Msg_N
("subtype name not allowed here", Choice
);
6416 -- ??? should allow static subtype with zero/one entry
6418 elsif Etype
(Choice
) = Base_Type
(Enumtype
) then
6419 if not Is_OK_Static_Expression
(Choice
) then
6420 Flag_Non_Static_Expr
6421 ("non-static expression used for choice!", Choice
);
6425 Elit
:= Expr_Value_E
(Choice
);
6427 if Present
(Enumeration_Rep_Expr
(Elit
)) then
6429 Sloc
(Enumeration_Rep_Expr
(Elit
));
6431 ("representation for& previously given#",
6436 Set_Enumeration_Rep_Expr
(Elit
, Expression
(Assoc
));
6438 Expr
:= Expression
(Assoc
);
6439 Val
:= Static_Integer
(Expr
);
6441 if Val
= No_Uint
then
6444 elsif Val
< Lo
or else Hi
< Val
then
6445 Error_Msg_N
("value outside permitted range", Expr
);
6449 Set_Enumeration_Rep
(Elit
, Val
);
6459 -- Aggregate is fully processed. Now we check that a full set of
6460 -- representations was given, and that they are in range and in order.
6461 -- These checks are only done if no other errors occurred.
6467 Elit
:= First_Literal
(Enumtype
);
6468 while Present
(Elit
) loop
6469 if No
(Enumeration_Rep_Expr
(Elit
)) then
6470 Error_Msg_NE
("missing representation for&!", N
, Elit
);
6473 Val
:= Enumeration_Rep
(Elit
);
6475 if Min
= No_Uint
then
6479 if Val
/= No_Uint
then
6480 if Max
/= No_Uint
and then Val
<= Max
then
6482 ("enumeration value for& not ordered!",
6483 Enumeration_Rep_Expr
(Elit
), Elit
);
6486 Max_Node
:= Enumeration_Rep_Expr
(Elit
);
6490 -- If there is at least one literal whose representation is not
6491 -- equal to the Pos value, then note that this enumeration type
6492 -- has a non-standard representation.
6494 if Val
/= Enumeration_Pos
(Elit
) then
6495 Set_Has_Non_Standard_Rep
(Base_Type
(Enumtype
));
6502 -- Now set proper size information
6505 Minsize
: Uint
:= UI_From_Int
(Minimum_Size
(Enumtype
));
6508 if Has_Size_Clause
(Enumtype
) then
6510 -- All OK, if size is OK now
6512 if RM_Size
(Enumtype
) >= Minsize
then
6516 -- Try if we can get by with biasing
6519 UI_From_Int
(Minimum_Size
(Enumtype
, Biased
=> True));
6521 -- Error message if even biasing does not work
6523 if RM_Size
(Enumtype
) < Minsize
then
6524 Error_Msg_Uint_1
:= RM_Size
(Enumtype
);
6525 Error_Msg_Uint_2
:= Max
;
6527 ("previously given size (^) is too small "
6528 & "for this value (^)", Max_Node
);
6530 -- If biasing worked, indicate that we now have biased rep
6534 (Enumtype
, Size_Clause
(Enumtype
), "size clause");
6539 Set_RM_Size
(Enumtype
, Minsize
);
6540 Set_Enum_Esize
(Enumtype
);
6543 Set_RM_Size
(Base_Type
(Enumtype
), RM_Size
(Enumtype
));
6544 Set_Esize
(Base_Type
(Enumtype
), Esize
(Enumtype
));
6545 Set_Alignment
(Base_Type
(Enumtype
), Alignment
(Enumtype
));
6549 -- We repeat the too late test in case it froze itself
6551 if Rep_Item_Too_Late
(Enumtype
, N
) then
6554 end Analyze_Enumeration_Representation_Clause
;
6556 ----------------------------
6557 -- Analyze_Free_Statement --
6558 ----------------------------
6560 procedure Analyze_Free_Statement
(N
: Node_Id
) is
6562 Analyze
(Expression
(N
));
6563 end Analyze_Free_Statement
;
6565 ---------------------------
6566 -- Analyze_Freeze_Entity --
6567 ---------------------------
6569 procedure Analyze_Freeze_Entity
(N
: Node_Id
) is
6571 Freeze_Entity_Checks
(N
);
6572 end Analyze_Freeze_Entity
;
6574 -----------------------------------
6575 -- Analyze_Freeze_Generic_Entity --
6576 -----------------------------------
6578 procedure Analyze_Freeze_Generic_Entity
(N
: Node_Id
) is
6580 Freeze_Entity_Checks
(N
);
6581 end Analyze_Freeze_Generic_Entity
;
6583 ------------------------------------------
6584 -- Analyze_Record_Representation_Clause --
6585 ------------------------------------------
6587 -- Note: we check as much as we can here, but we can't do any checks
6588 -- based on the position values (e.g. overlap checks) until freeze time
6589 -- because especially in Ada 2005 (machine scalar mode), the processing
6590 -- for non-standard bit order can substantially change the positions.
6591 -- See procedure Check_Record_Representation_Clause (called from Freeze)
6592 -- for the remainder of this processing.
6594 procedure Analyze_Record_Representation_Clause
(N
: Node_Id
) is
6595 Ident
: constant Node_Id
:= Identifier
(N
);
6600 Hbit
: Uint
:= Uint_0
;
6604 Rectype
: Entity_Id
;
6607 function Is_Inherited
(Comp
: Entity_Id
) return Boolean;
6608 -- True if Comp is an inherited component in a record extension
6614 function Is_Inherited
(Comp
: Entity_Id
) return Boolean is
6615 Comp_Base
: Entity_Id
;
6618 if Ekind
(Rectype
) = E_Record_Subtype
then
6619 Comp_Base
:= Original_Record_Component
(Comp
);
6624 return Comp_Base
/= Original_Record_Component
(Comp_Base
);
6629 Is_Record_Extension
: Boolean;
6630 -- True if Rectype is a record extension
6632 CR_Pragma
: Node_Id
:= Empty
;
6633 -- Points to N_Pragma node if Complete_Representation pragma present
6635 -- Start of processing for Analyze_Record_Representation_Clause
6638 if Ignore_Rep_Clauses
then
6639 Kill_Rep_Clause
(N
);
6644 Rectype
:= Entity
(Ident
);
6646 if Rectype
= Any_Type
or else Rep_Item_Too_Early
(Rectype
, N
) then
6649 Rectype
:= Underlying_Type
(Rectype
);
6652 -- First some basic error checks
6654 if not Is_Record_Type
(Rectype
) then
6656 ("record type required, found}", Ident
, First_Subtype
(Rectype
));
6659 elsif Scope
(Rectype
) /= Current_Scope
then
6660 Error_Msg_N
("type must be declared in this scope", N
);
6663 elsif not Is_First_Subtype
(Rectype
) then
6664 Error_Msg_N
("cannot give record rep clause for subtype", N
);
6667 elsif Has_Record_Rep_Clause
(Rectype
) then
6668 Error_Msg_N
("duplicate record rep clause ignored", N
);
6671 elsif Rep_Item_Too_Late
(Rectype
, N
) then
6675 -- We know we have a first subtype, now possibly go to the anonymous
6676 -- base type to determine whether Rectype is a record extension.
6678 Recdef
:= Type_Definition
(Declaration_Node
(Base_Type
(Rectype
)));
6679 Is_Record_Extension
:=
6680 Nkind
(Recdef
) = N_Derived_Type_Definition
6681 and then Present
(Record_Extension_Part
(Recdef
));
6683 if Present
(Mod_Clause
(N
)) then
6685 Loc
: constant Source_Ptr
:= Sloc
(N
);
6686 M
: constant Node_Id
:= Mod_Clause
(N
);
6687 P
: constant List_Id
:= Pragmas_Before
(M
);
6691 pragma Warnings
(Off
, Mod_Val
);
6694 Check_Restriction
(No_Obsolescent_Features
, Mod_Clause
(N
));
6696 if Warn_On_Obsolescent_Feature
then
6698 ("?j?mod clause is an obsolescent feature (RM J.8)", N
);
6700 ("\?j?use alignment attribute definition clause instead", N
);
6707 -- In ASIS_Mode mode, expansion is disabled, but we must convert
6708 -- the Mod clause into an alignment clause anyway, so that the
6709 -- back end can compute and back-annotate properly the size and
6710 -- alignment of types that may include this record.
6712 -- This seems dubious, this destroys the source tree in a manner
6713 -- not detectable by ASIS ???
6715 if Operating_Mode
= Check_Semantics
and then ASIS_Mode
then
6717 Make_Attribute_Definition_Clause
(Loc
,
6718 Name
=> New_Occurrence_Of
(Base_Type
(Rectype
), Loc
),
6719 Chars
=> Name_Alignment
,
6720 Expression
=> Relocate_Node
(Expression
(M
)));
6722 Set_From_At_Mod
(AtM_Nod
);
6723 Insert_After
(N
, AtM_Nod
);
6724 Mod_Val
:= Get_Alignment_Value
(Expression
(AtM_Nod
));
6725 Set_Mod_Clause
(N
, Empty
);
6728 -- Get the alignment value to perform error checking
6730 Mod_Val
:= Get_Alignment_Value
(Expression
(M
));
6735 -- For untagged types, clear any existing component clauses for the
6736 -- type. If the type is derived, this is what allows us to override
6737 -- a rep clause for the parent. For type extensions, the representation
6738 -- of the inherited components is inherited, so we want to keep previous
6739 -- component clauses for completeness.
6741 if not Is_Tagged_Type
(Rectype
) then
6742 Comp
:= First_Component_Or_Discriminant
(Rectype
);
6743 while Present
(Comp
) loop
6744 Set_Component_Clause
(Comp
, Empty
);
6745 Next_Component_Or_Discriminant
(Comp
);
6749 -- All done if no component clauses
6751 CC
:= First
(Component_Clauses
(N
));
6757 -- A representation like this applies to the base type
6759 Set_Has_Record_Rep_Clause
(Base_Type
(Rectype
));
6760 Set_Has_Non_Standard_Rep
(Base_Type
(Rectype
));
6761 Set_Has_Specified_Layout
(Base_Type
(Rectype
));
6763 -- Process the component clauses
6765 while Present
(CC
) loop
6769 if Nkind
(CC
) = N_Pragma
then
6772 -- The only pragma of interest is Complete_Representation
6774 if Pragma_Name
(CC
) = Name_Complete_Representation
then
6778 -- Processing for real component clause
6781 Posit
:= Static_Integer
(Position
(CC
));
6782 Fbit
:= Static_Integer
(First_Bit
(CC
));
6783 Lbit
:= Static_Integer
(Last_Bit
(CC
));
6786 and then Fbit
/= No_Uint
6787 and then Lbit
/= No_Uint
6791 ("position cannot be negative", Position
(CC
));
6795 ("first bit cannot be negative", First_Bit
(CC
));
6797 -- The Last_Bit specified in a component clause must not be
6798 -- less than the First_Bit minus one (RM-13.5.1(10)).
6800 elsif Lbit
< Fbit
- 1 then
6802 ("last bit cannot be less than first bit minus one",
6805 -- Values look OK, so find the corresponding record component
6806 -- Even though the syntax allows an attribute reference for
6807 -- implementation-defined components, GNAT does not allow the
6808 -- tag to get an explicit position.
6810 elsif Nkind
(Component_Name
(CC
)) = N_Attribute_Reference
then
6811 if Attribute_Name
(Component_Name
(CC
)) = Name_Tag
then
6812 Error_Msg_N
("position of tag cannot be specified", CC
);
6814 Error_Msg_N
("illegal component name", CC
);
6818 Comp
:= First_Entity
(Rectype
);
6819 while Present
(Comp
) loop
6820 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
6826 -- Maybe component of base type that is absent from
6827 -- statically constrained first subtype.
6829 Comp
:= First_Entity
(Base_Type
(Rectype
));
6830 while Present
(Comp
) loop
6831 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
6838 ("component clause is for non-existent field", CC
);
6840 -- Ada 2012 (AI05-0026): Any name that denotes a
6841 -- discriminant of an object of an unchecked union type
6842 -- shall not occur within a record_representation_clause.
6844 -- The general restriction of using record rep clauses on
6845 -- Unchecked_Union types has now been lifted. Since it is
6846 -- possible to introduce a record rep clause which mentions
6847 -- the discriminant of an Unchecked_Union in non-Ada 2012
6848 -- code, this check is applied to all versions of the
6851 elsif Ekind
(Comp
) = E_Discriminant
6852 and then Is_Unchecked_Union
(Rectype
)
6855 ("cannot reference discriminant of unchecked union",
6856 Component_Name
(CC
));
6858 elsif Is_Record_Extension
and then Is_Inherited
(Comp
) then
6860 ("component clause not allowed for inherited "
6861 & "component&", CC
, Comp
);
6863 elsif Present
(Component_Clause
(Comp
)) then
6865 -- Diagnose duplicate rep clause, or check consistency
6866 -- if this is an inherited component. In a double fault,
6867 -- there may be a duplicate inconsistent clause for an
6868 -- inherited component.
6870 if Scope
(Original_Record_Component
(Comp
)) = Rectype
6871 or else Parent
(Component_Clause
(Comp
)) = N
6873 Error_Msg_Sloc
:= Sloc
(Component_Clause
(Comp
));
6874 Error_Msg_N
("component clause previously given#", CC
);
6878 Rep1
: constant Node_Id
:= Component_Clause
(Comp
);
6880 if Intval
(Position
(Rep1
)) /=
6881 Intval
(Position
(CC
))
6882 or else Intval
(First_Bit
(Rep1
)) /=
6883 Intval
(First_Bit
(CC
))
6884 or else Intval
(Last_Bit
(Rep1
)) /=
6885 Intval
(Last_Bit
(CC
))
6888 ("component clause inconsistent "
6889 & "with representation of ancestor", CC
);
6891 elsif Warn_On_Redundant_Constructs
then
6893 ("?r?redundant confirming component clause "
6894 & "for component!", CC
);
6899 -- Normal case where this is the first component clause we
6900 -- have seen for this entity, so set it up properly.
6903 -- Make reference for field in record rep clause and set
6904 -- appropriate entity field in the field identifier.
6907 (Comp
, Component_Name
(CC
), Set_Ref
=> False);
6908 Set_Entity
(Component_Name
(CC
), Comp
);
6910 -- Update Fbit and Lbit to the actual bit number
6912 Fbit
:= Fbit
+ UI_From_Int
(SSU
) * Posit
;
6913 Lbit
:= Lbit
+ UI_From_Int
(SSU
) * Posit
;
6915 if Has_Size_Clause
(Rectype
)
6916 and then RM_Size
(Rectype
) <= Lbit
6919 ("bit number out of range of specified size",
6922 Set_Component_Clause
(Comp
, CC
);
6923 Set_Component_Bit_Offset
(Comp
, Fbit
);
6924 Set_Esize
(Comp
, 1 + (Lbit
- Fbit
));
6925 Set_Normalized_First_Bit
(Comp
, Fbit
mod SSU
);
6926 Set_Normalized_Position
(Comp
, Fbit
/ SSU
);
6928 if Warn_On_Overridden_Size
6929 and then Has_Size_Clause
(Etype
(Comp
))
6930 and then RM_Size
(Etype
(Comp
)) /= Esize
(Comp
)
6933 ("?S?component size overrides size clause for&",
6934 Component_Name
(CC
), Etype
(Comp
));
6937 -- This information is also set in the corresponding
6938 -- component of the base type, found by accessing the
6939 -- Original_Record_Component link if it is present.
6941 Ocomp
:= Original_Record_Component
(Comp
);
6948 (Component_Name
(CC
),
6954 (Comp
, First_Node
(CC
), "component clause", Biased
);
6956 if Present
(Ocomp
) then
6957 Set_Component_Clause
(Ocomp
, CC
);
6958 Set_Component_Bit_Offset
(Ocomp
, Fbit
);
6959 Set_Normalized_First_Bit
(Ocomp
, Fbit
mod SSU
);
6960 Set_Normalized_Position
(Ocomp
, Fbit
/ SSU
);
6961 Set_Esize
(Ocomp
, 1 + (Lbit
- Fbit
));
6963 Set_Normalized_Position_Max
6964 (Ocomp
, Normalized_Position
(Ocomp
));
6966 -- Note: we don't use Set_Biased here, because we
6967 -- already gave a warning above if needed, and we
6968 -- would get a duplicate for the same name here.
6970 Set_Has_Biased_Representation
6971 (Ocomp
, Has_Biased_Representation
(Comp
));
6974 if Esize
(Comp
) < 0 then
6975 Error_Msg_N
("component size is negative", CC
);
6986 -- Check missing components if Complete_Representation pragma appeared
6988 if Present
(CR_Pragma
) then
6989 Comp
:= First_Component_Or_Discriminant
(Rectype
);
6990 while Present
(Comp
) loop
6991 if No
(Component_Clause
(Comp
)) then
6993 ("missing component clause for &", CR_Pragma
, Comp
);
6996 Next_Component_Or_Discriminant
(Comp
);
6999 -- Give missing components warning if required
7001 elsif Warn_On_Unrepped_Components
then
7003 Num_Repped_Components
: Nat
:= 0;
7004 Num_Unrepped_Components
: Nat
:= 0;
7007 -- First count number of repped and unrepped components
7009 Comp
:= First_Component_Or_Discriminant
(Rectype
);
7010 while Present
(Comp
) loop
7011 if Present
(Component_Clause
(Comp
)) then
7012 Num_Repped_Components
:= Num_Repped_Components
+ 1;
7014 Num_Unrepped_Components
:= Num_Unrepped_Components
+ 1;
7017 Next_Component_Or_Discriminant
(Comp
);
7020 -- We are only interested in the case where there is at least one
7021 -- unrepped component, and at least half the components have rep
7022 -- clauses. We figure that if less than half have them, then the
7023 -- partial rep clause is really intentional. If the component
7024 -- type has no underlying type set at this point (as for a generic
7025 -- formal type), we don't know enough to give a warning on the
7028 if Num_Unrepped_Components
> 0
7029 and then Num_Unrepped_Components
< Num_Repped_Components
7031 Comp
:= First_Component_Or_Discriminant
(Rectype
);
7032 while Present
(Comp
) loop
7033 if No
(Component_Clause
(Comp
))
7034 and then Comes_From_Source
(Comp
)
7035 and then Present
(Underlying_Type
(Etype
(Comp
)))
7036 and then (Is_Scalar_Type
(Underlying_Type
(Etype
(Comp
)))
7037 or else Size_Known_At_Compile_Time
7038 (Underlying_Type
(Etype
(Comp
))))
7039 and then not Has_Warnings_Off
(Rectype
)
7041 -- Ignore discriminant in unchecked union, since it is
7042 -- not there, and cannot have a component clause.
7044 and then (not Is_Unchecked_Union
(Rectype
)
7045 or else Ekind
(Comp
) /= E_Discriminant
)
7047 Error_Msg_Sloc
:= Sloc
(Comp
);
7049 ("?C?no component clause given for & declared #",
7053 Next_Component_Or_Discriminant
(Comp
);
7058 end Analyze_Record_Representation_Clause
;
7060 -------------------------------------
7061 -- Build_Discrete_Static_Predicate --
7062 -------------------------------------
7064 procedure Build_Discrete_Static_Predicate
7069 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
7071 Non_Static
: exception;
7072 -- Raised if something non-static is found
7074 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
7076 BLo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Btyp
));
7077 BHi
: constant Uint
:= Expr_Value
(Type_High_Bound
(Btyp
));
7078 -- Low bound and high bound value of base type of Typ
7082 -- Bounds for constructing the static predicate. We use the bound of the
7083 -- subtype if it is static, otherwise the corresponding base type bound.
7084 -- Note: a non-static subtype can have a static predicate.
7089 -- One entry in a Rlist value, a single REnt (range entry) value denotes
7090 -- one range from Lo to Hi. To represent a single value range Lo = Hi =
7093 type RList
is array (Nat
range <>) of REnt
;
7094 -- A list of ranges. The ranges are sorted in increasing order, and are
7095 -- disjoint (there is a gap of at least one value between each range in
7096 -- the table). A value is in the set of ranges in Rlist if it lies
7097 -- within one of these ranges.
7099 False_Range
: constant RList
:=
7100 RList
'(1 .. 0 => REnt'(No_Uint
, No_Uint
));
7101 -- An empty set of ranges represents a range list that can never be
7102 -- satisfied, since there are no ranges in which the value could lie,
7103 -- so it does not lie in any of them. False_Range is a canonical value
7104 -- for this empty set, but general processing should test for an Rlist
7105 -- with length zero (see Is_False predicate), since other null ranges
7106 -- may appear which must be treated as False.
7108 True_Range
: constant RList
:= RList
'(1 => REnt'(BLo
, BHi
));
7109 -- Range representing True, value must be in the base range
7111 function "and" (Left
: RList
; Right
: RList
) return RList
;
7112 -- And's together two range lists, returning a range list. This is a set
7113 -- intersection operation.
7115 function "or" (Left
: RList
; Right
: RList
) return RList
;
7116 -- Or's together two range lists, returning a range list. This is a set
7119 function "not" (Right
: RList
) return RList
;
7120 -- Returns complement of a given range list, i.e. a range list
7121 -- representing all the values in TLo .. THi that are not in the input
7124 function Build_Val
(V
: Uint
) return Node_Id
;
7125 -- Return an analyzed N_Identifier node referencing this value, suitable
7126 -- for use as an entry in the Static_Discrte_Predicate list. This node
7127 -- is typed with the base type.
7129 function Build_Range
(Lo
: Uint
; Hi
: Uint
) return Node_Id
;
7130 -- Return an analyzed N_Range node referencing this range, suitable for
7131 -- use as an entry in the Static_Discrete_Predicate list. This node is
7132 -- typed with the base type.
7134 function Get_RList
(Exp
: Node_Id
) return RList
;
7135 -- This is a recursive routine that converts the given expression into a
7136 -- list of ranges, suitable for use in building the static predicate.
7138 function Is_False
(R
: RList
) return Boolean;
7139 pragma Inline
(Is_False
);
7140 -- Returns True if the given range list is empty, and thus represents a
7141 -- False list of ranges that can never be satisfied.
7143 function Is_True
(R
: RList
) return Boolean;
7144 -- Returns True if R trivially represents the True predicate by having a
7145 -- single range from BLo to BHi.
7147 function Is_Type_Ref
(N
: Node_Id
) return Boolean;
7148 pragma Inline
(Is_Type_Ref
);
7149 -- Returns if True if N is a reference to the type for the predicate in
7150 -- the expression (i.e. if it is an identifier whose Chars field matches
7151 -- the Nam given in the call). N must not be parenthesized, if the type
7152 -- name appears in parens, this routine will return False.
7154 function Lo_Val
(N
: Node_Id
) return Uint
;
7155 -- Given an entry from a Static_Discrete_Predicate list that is either
7156 -- a static expression or static range, gets either the expression value
7157 -- or the low bound of the range.
7159 function Hi_Val
(N
: Node_Id
) return Uint
;
7160 -- Given an entry from a Static_Discrete_Predicate list that is either
7161 -- a static expression or static range, gets either the expression value
7162 -- or the high bound of the range.
7164 function Membership_Entry
(N
: Node_Id
) return RList
;
7165 -- Given a single membership entry (range, value, or subtype), returns
7166 -- the corresponding range list. Raises Static_Error if not static.
7168 function Membership_Entries
(N
: Node_Id
) return RList
;
7169 -- Given an element on an alternatives list of a membership operation,
7170 -- returns the range list corresponding to this entry and all following
7171 -- entries (i.e. returns the "or" of this list of values).
7173 function Stat_Pred
(Typ
: Entity_Id
) return RList
;
7174 -- Given a type, if it has a static predicate, then return the predicate
7175 -- as a range list, otherwise raise Non_Static.
7181 function "and" (Left
: RList
; Right
: RList
) return RList
is
7183 -- First range of result
7185 SLeft
: Nat
:= Left
'First;
7186 -- Start of rest of left entries
7188 SRight
: Nat
:= Right
'First;
7189 -- Start of rest of right entries
7192 -- If either range is True, return the other
7194 if Is_True
(Left
) then
7196 elsif Is_True
(Right
) then
7200 -- If either range is False, return False
7202 if Is_False
(Left
) or else Is_False
(Right
) then
7206 -- Loop to remove entries at start that are disjoint, and thus just
7207 -- get discarded from the result entirely.
7210 -- If no operands left in either operand, result is false
7212 if SLeft
> Left
'Last or else SRight
> Right
'Last then
7215 -- Discard first left operand entry if disjoint with right
7217 elsif Left
(SLeft
).Hi
< Right
(SRight
).Lo
then
7220 -- Discard first right operand entry if disjoint with left
7222 elsif Right
(SRight
).Hi
< Left
(SLeft
).Lo
then
7223 SRight
:= SRight
+ 1;
7225 -- Otherwise we have an overlapping entry
7232 -- Now we have two non-null operands, and first entries overlap. The
7233 -- first entry in the result will be the overlapping part of these
7236 FEnt
:= REnt
'(Lo => UI_Max (Left (SLeft).Lo, Right (SRight).Lo),
7237 Hi => UI_Min (Left (SLeft).Hi, Right (SRight).Hi));
7239 -- Now we can remove the entry that ended at a lower value, since its
7240 -- contribution is entirely contained in Fent.
7242 if Left (SLeft).Hi <= Right (SRight).Hi then
7245 SRight := SRight + 1;
7248 -- Compute result by concatenating this first entry with the "and" of
7249 -- the remaining parts of the left and right operands. Note that if
7250 -- either of these is empty, "and" will yield empty, so that we will
7251 -- end up with just Fent, which is what we want in that case.
7254 FEnt & (Left (SLeft .. Left'Last) and Right (SRight .. Right'Last));
7261 function "not" (Right : RList) return RList is
7263 -- Return True if False range
7265 if Is_False (Right) then
7269 -- Return False if True range
7271 if Is_True (Right) then
7275 -- Here if not trivial case
7278 Result : RList (1 .. Right'Length + 1);
7279 -- May need one more entry for gap at beginning and end
7282 -- Number of entries stored in Result
7287 if Right (Right'First).Lo > TLo then
7289 Result (Count) := REnt'(TLo
, Right
(Right
'First).Lo
- 1);
7292 -- Gaps between ranges
7294 for J
in Right
'First .. Right
'Last - 1 loop
7296 Result
(Count
) := REnt
'(Right (J).Hi + 1, Right (J + 1).Lo - 1);
7301 if Right (Right'Last).Hi < THi then
7303 Result (Count) := REnt'(Right
(Right
'Last).Hi
+ 1, THi
);
7306 return Result
(1 .. Count
);
7314 function "or" (Left
: RList
; Right
: RList
) return RList
is
7316 -- First range of result
7318 SLeft
: Nat
:= Left
'First;
7319 -- Start of rest of left entries
7321 SRight
: Nat
:= Right
'First;
7322 -- Start of rest of right entries
7325 -- If either range is True, return True
7327 if Is_True
(Left
) or else Is_True
(Right
) then
7331 -- If either range is False (empty), return the other
7333 if Is_False
(Left
) then
7335 elsif Is_False
(Right
) then
7339 -- Initialize result first entry from left or right operand depending
7340 -- on which starts with the lower range.
7342 if Left
(SLeft
).Lo
< Right
(SRight
).Lo
then
7343 FEnt
:= Left
(SLeft
);
7346 FEnt
:= Right
(SRight
);
7347 SRight
:= SRight
+ 1;
7350 -- This loop eats ranges from left and right operands that are
7351 -- contiguous with the first range we are gathering.
7354 -- Eat first entry in left operand if contiguous or overlapped by
7355 -- gathered first operand of result.
7357 if SLeft
<= Left
'Last
7358 and then Left
(SLeft
).Lo
<= FEnt
.Hi
+ 1
7360 FEnt
.Hi
:= UI_Max
(FEnt
.Hi
, Left
(SLeft
).Hi
);
7363 -- Eat first entry in right operand if contiguous or overlapped by
7364 -- gathered right operand of result.
7366 elsif SRight
<= Right
'Last
7367 and then Right
(SRight
).Lo
<= FEnt
.Hi
+ 1
7369 FEnt
.Hi
:= UI_Max
(FEnt
.Hi
, Right
(SRight
).Hi
);
7370 SRight
:= SRight
+ 1;
7372 -- All done if no more entries to eat
7379 -- Obtain result as the first entry we just computed, concatenated
7380 -- to the "or" of the remaining results (if one operand is empty,
7381 -- this will just concatenate with the other
7384 FEnt
& (Left
(SLeft
.. Left
'Last) or Right
(SRight
.. Right
'Last));
7391 function Build_Range
(Lo
: Uint
; Hi
: Uint
) return Node_Id
is
7396 Low_Bound
=> Build_Val
(Lo
),
7397 High_Bound
=> Build_Val
(Hi
));
7398 Set_Etype
(Result
, Btyp
);
7399 Set_Analyzed
(Result
);
7407 function Build_Val
(V
: Uint
) return Node_Id
is
7411 if Is_Enumeration_Type
(Typ
) then
7412 Result
:= Get_Enum_Lit_From_Pos
(Typ
, V
, Loc
);
7414 Result
:= Make_Integer_Literal
(Loc
, V
);
7417 Set_Etype
(Result
, Btyp
);
7418 Set_Is_Static_Expression
(Result
);
7419 Set_Analyzed
(Result
);
7427 function Get_RList
(Exp
: Node_Id
) return RList
is
7432 -- Static expression can only be true or false
7434 if Is_OK_Static_Expression
(Exp
) then
7435 if Expr_Value
(Exp
) = 0 then
7442 -- Otherwise test node type
7450 when N_Op_And | N_And_Then
=>
7451 return Get_RList
(Left_Opnd
(Exp
))
7453 Get_RList
(Right_Opnd
(Exp
));
7457 when N_Op_Or | N_Or_Else
=>
7458 return Get_RList
(Left_Opnd
(Exp
))
7460 Get_RList
(Right_Opnd
(Exp
));
7465 return not Get_RList
(Right_Opnd
(Exp
));
7467 -- Comparisons of type with static value
7469 when N_Op_Compare
=>
7471 -- Type is left operand
7473 if Is_Type_Ref
(Left_Opnd
(Exp
))
7474 and then Is_OK_Static_Expression
(Right_Opnd
(Exp
))
7476 Val
:= Expr_Value
(Right_Opnd
(Exp
));
7478 -- Typ is right operand
7480 elsif Is_Type_Ref
(Right_Opnd
(Exp
))
7481 and then Is_OK_Static_Expression
(Left_Opnd
(Exp
))
7483 Val
:= Expr_Value
(Left_Opnd
(Exp
));
7485 -- Invert sense of comparison
7488 when N_Op_Gt
=> Op
:= N_Op_Lt
;
7489 when N_Op_Lt
=> Op
:= N_Op_Gt
;
7490 when N_Op_Ge
=> Op
:= N_Op_Le
;
7491 when N_Op_Le
=> Op
:= N_Op_Ge
;
7492 when others => null;
7495 -- Other cases are non-static
7501 -- Construct range according to comparison operation
7505 return RList
'(1 => REnt'(Val
, Val
));
7508 return RList
'(1 => REnt'(Val
, BHi
));
7511 return RList
'(1 => REnt'(Val
+ 1, BHi
));
7514 return RList
'(1 => REnt'(BLo
, Val
));
7517 return RList
'(1 => REnt'(BLo
, Val
- 1));
7520 return RList
'(REnt'(BLo
, Val
- 1), REnt
'(Val + 1, BHi));
7523 raise Program_Error;
7529 if not Is_Type_Ref (Left_Opnd (Exp)) then
7533 if Present (Right_Opnd (Exp)) then
7534 return Membership_Entry (Right_Opnd (Exp));
7536 return Membership_Entries (First (Alternatives (Exp)));
7539 -- Negative membership (NOT IN)
7542 if not Is_Type_Ref (Left_Opnd (Exp)) then
7546 if Present (Right_Opnd (Exp)) then
7547 return not Membership_Entry (Right_Opnd (Exp));
7549 return not Membership_Entries (First (Alternatives (Exp)));
7552 -- Function call, may be call to static predicate
7554 when N_Function_Call =>
7555 if Is_Entity_Name (Name (Exp)) then
7557 Ent : constant Entity_Id := Entity (Name (Exp));
7559 if Is_Predicate_Function (Ent)
7561 Is_Predicate_Function_M (Ent)
7563 return Stat_Pred (Etype (First_Formal (Ent)));
7568 -- Other function call cases are non-static
7572 -- Qualified expression, dig out the expression
7574 when N_Qualified_Expression =>
7575 return Get_RList (Expression (Exp));
7577 when N_Case_Expression =>
7584 if not Is_Entity_Name (Expression (Expr))
7585 or else Etype (Expression (Expr)) /= Typ
7588 ("expression must denaote subtype", Expression (Expr));
7592 -- Collect discrete choices in all True alternatives
7594 Choices := New_List;
7595 Alt := First (Alternatives (Exp));
7596 while Present (Alt) loop
7597 Dep := Expression (Alt);
7599 if not Is_OK_Static_Expression (Dep) then
7602 elsif Is_True (Expr_Value (Dep)) then
7603 Append_List_To (Choices,
7604 New_Copy_List (Discrete_Choices (Alt)));
7610 return Membership_Entries (First (Choices));
7613 -- Expression with actions: if no actions, dig out expression
7615 when N_Expression_With_Actions =>
7616 if Is_Empty_List (Actions (Exp)) then
7617 return Get_RList (Expression (Exp));
7625 return (Get_RList (Left_Opnd (Exp))
7626 and not Get_RList (Right_Opnd (Exp)))
7627 or (Get_RList (Right_Opnd (Exp))
7628 and not Get_RList (Left_Opnd (Exp)));
7630 -- Any other node type is non-static
7641 function Hi_Val (N : Node_Id) return Uint is
7643 if Is_OK_Static_Expression (N) then
7644 return Expr_Value (N);
7646 pragma Assert (Nkind (N) = N_Range);
7647 return Expr_Value (High_Bound (N));
7655 function Is_False (R : RList) return Boolean is
7657 return R'Length = 0;
7664 function Is_True (R : RList) return Boolean is
7667 and then R (R'First).Lo = BLo
7668 and then R (R'First).Hi = BHi;
7675 function Is_Type_Ref (N : Node_Id) return Boolean is
7677 return Nkind (N) = N_Identifier
7678 and then Chars (N) = Nam
7679 and then Paren_Count (N) = 0;
7686 function Lo_Val (N : Node_Id) return Uint is
7688 if Is_OK_Static_Expression (N) then
7689 return Expr_Value (N);
7691 pragma Assert (Nkind (N) = N_Range);
7692 return Expr_Value (Low_Bound (N));
7696 ------------------------
7697 -- Membership_Entries --
7698 ------------------------
7700 function Membership_Entries (N : Node_Id) return RList is
7702 if No (Next (N)) then
7703 return Membership_Entry (N);
7705 return Membership_Entry (N) or Membership_Entries (Next (N));
7707 end Membership_Entries;
7709 ----------------------
7710 -- Membership_Entry --
7711 ----------------------
7713 function Membership_Entry (N : Node_Id) return RList is
7721 if Nkind (N) = N_Range then
7722 if not Is_OK_Static_Expression (Low_Bound (N))
7724 not Is_OK_Static_Expression (High_Bound (N))
7728 SLo := Expr_Value (Low_Bound (N));
7729 SHi := Expr_Value (High_Bound (N));
7730 return RList'(1 => REnt
'(SLo, SHi));
7733 -- Static expression case
7735 elsif Is_OK_Static_Expression (N) then
7736 Val := Expr_Value (N);
7737 return RList'(1 => REnt
'(Val, Val));
7739 -- Identifier (other than static expression) case
7741 else pragma Assert (Nkind (N) = N_Identifier);
7745 if Is_Type (Entity (N)) then
7747 -- If type has predicates, process them
7749 if Has_Predicates (Entity (N)) then
7750 return Stat_Pred (Entity (N));
7752 -- For static subtype without predicates, get range
7754 elsif Is_OK_Static_Subtype (Entity (N)) then
7755 SLo := Expr_Value (Type_Low_Bound (Entity (N)));
7756 SHi := Expr_Value (Type_High_Bound (Entity (N)));
7757 return RList'(1 => REnt
'(SLo, SHi));
7759 -- Any other type makes us non-static
7765 -- Any other kind of identifier in predicate (e.g. a non-static
7766 -- expression value) means this is not a static predicate.
7772 end Membership_Entry;
7778 function Stat_Pred (Typ : Entity_Id) return RList is
7780 -- Not static if type does not have static predicates
7782 if not Has_Static_Predicate (Typ) then
7786 -- Otherwise we convert the predicate list to a range list
7789 Spred : constant List_Id := Static_Discrete_Predicate (Typ);
7790 Result : RList (1 .. List_Length (Spred));
7794 P := First (Static_Discrete_Predicate (Typ));
7795 for J in Result'Range loop
7796 Result (J) := REnt'(Lo_Val
(P
), Hi_Val
(P
));
7804 -- Start of processing for Build_Discrete_Static_Predicate
7807 -- Establish bounds for the predicate
7809 if Compile_Time_Known_Value
(Type_Low_Bound
(Typ
)) then
7810 TLo
:= Expr_Value
(Type_Low_Bound
(Typ
));
7815 if Compile_Time_Known_Value
(Type_High_Bound
(Typ
)) then
7816 THi
:= Expr_Value
(Type_High_Bound
(Typ
));
7821 -- Analyze the expression to see if it is a static predicate
7824 Ranges
: constant RList
:= Get_RList
(Expr
);
7825 -- Range list from expression if it is static
7830 -- Convert range list into a form for the static predicate. In the
7831 -- Ranges array, we just have raw ranges, these must be converted
7832 -- to properly typed and analyzed static expressions or range nodes.
7834 -- Note: here we limit ranges to the ranges of the subtype, so that
7835 -- a predicate is always false for values outside the subtype. That
7836 -- seems fine, such values are invalid anyway, and considering them
7837 -- to fail the predicate seems allowed and friendly, and furthermore
7838 -- simplifies processing for case statements and loops.
7842 for J
in Ranges
'Range loop
7844 Lo
: Uint
:= Ranges
(J
).Lo
;
7845 Hi
: Uint
:= Ranges
(J
).Hi
;
7848 -- Ignore completely out of range entry
7850 if Hi
< TLo
or else Lo
> THi
then
7853 -- Otherwise process entry
7856 -- Adjust out of range value to subtype range
7866 -- Convert range into required form
7868 Append_To
(Plist
, Build_Range
(Lo
, Hi
));
7873 -- Processing was successful and all entries were static, so now we
7874 -- can store the result as the predicate list.
7876 Set_Static_Discrete_Predicate
(Typ
, Plist
);
7878 -- The processing for static predicates put the expression into
7879 -- canonical form as a series of ranges. It also eliminated
7880 -- duplicates and collapsed and combined ranges. We might as well
7881 -- replace the alternatives list of the right operand of the
7882 -- membership test with the static predicate list, which will
7883 -- usually be more efficient.
7886 New_Alts
: constant List_Id
:= New_List
;
7891 Old_Node
:= First
(Plist
);
7892 while Present
(Old_Node
) loop
7893 New_Node
:= New_Copy
(Old_Node
);
7895 if Nkind
(New_Node
) = N_Range
then
7896 Set_Low_Bound
(New_Node
, New_Copy
(Low_Bound
(Old_Node
)));
7897 Set_High_Bound
(New_Node
, New_Copy
(High_Bound
(Old_Node
)));
7900 Append_To
(New_Alts
, New_Node
);
7904 -- If empty list, replace by False
7906 if Is_Empty_List
(New_Alts
) then
7907 Rewrite
(Expr
, New_Occurrence_Of
(Standard_False
, Loc
));
7909 -- Else replace by set membership test
7914 Left_Opnd
=> Make_Identifier
(Loc
, Nam
),
7915 Right_Opnd
=> Empty
,
7916 Alternatives
=> New_Alts
));
7918 -- Resolve new expression in function context
7920 Install_Formals
(Predicate_Function
(Typ
));
7921 Push_Scope
(Predicate_Function
(Typ
));
7922 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
7928 -- If non-static, return doing nothing
7933 end Build_Discrete_Static_Predicate
;
7935 --------------------------------
7936 -- Build_Export_Import_Pragma --
7937 --------------------------------
7939 function Build_Export_Import_Pragma
7941 Id
: Entity_Id
) return Node_Id
7943 Asp_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Asp
);
7944 Expr
: constant Node_Id
:= Expression
(Asp
);
7945 Loc
: constant Source_Ptr
:= Sloc
(Asp
);
7956 Create_Pragma
: Boolean := False;
7957 -- This flag is set when the aspect form is such that it warrants the
7958 -- creation of a corresponding pragma.
7961 if Present
(Expr
) then
7962 if Error_Posted
(Expr
) then
7965 elsif Is_True
(Expr_Value
(Expr
)) then
7966 Create_Pragma
:= True;
7969 -- Otherwise the aspect defaults to True
7972 Create_Pragma
:= True;
7975 -- Nothing to do when the expression is False or is erroneous
7977 if not Create_Pragma
then
7981 -- Obtain all interfacing aspects that apply to the related entity
7983 Get_Interfacing_Aspects
7987 Expo_Asp
=> Dummy_1
,
7993 -- Handle the convention argument
7995 if Present
(Conv
) then
7996 Conv_Arg
:= New_Copy_Tree
(Expression
(Conv
));
7998 -- Assume convention "Ada' when aspect Convention is missing
8001 Conv_Arg
:= Make_Identifier
(Loc
, Name_Ada
);
8005 Make_Pragma_Argument_Association
(Loc
,
8006 Chars
=> Name_Convention
,
8007 Expression
=> Conv_Arg
));
8009 -- Handle the entity argument
8012 Make_Pragma_Argument_Association
(Loc
,
8013 Chars
=> Name_Entity
,
8014 Expression
=> New_Occurrence_Of
(Id
, Loc
)));
8016 -- Handle the External_Name argument
8018 if Present
(EN
) then
8020 Make_Pragma_Argument_Association
(Loc
,
8021 Chars
=> Name_External_Name
,
8022 Expression
=> New_Copy_Tree
(Expression
(EN
))));
8025 -- Handle the Link_Name argument
8027 if Present
(LN
) then
8029 Make_Pragma_Argument_Association
(Loc
,
8030 Chars
=> Name_Link_Name
,
8031 Expression
=> New_Copy_Tree
(Expression
(LN
))));
8035 -- pragma Export/Import
8036 -- (Convention => <Conv>/Ada,
8038 -- [External_Name => <EN>,]
8039 -- [Link_Name => <LN>]);
8043 Pragma_Identifier
=>
8044 Make_Identifier
(Loc
, Chars
(Identifier
(Asp
))),
8045 Pragma_Argument_Associations
=> Args
);
8047 -- Decorate the relevant aspect and the pragma
8049 Set_Aspect_Rep_Item
(Asp
, Prag
);
8051 Set_Corresponding_Aspect
(Prag
, Asp
);
8052 Set_From_Aspect_Specification
(Prag
);
8053 Set_Parent
(Prag
, Asp
);
8055 if Asp_Id
= Aspect_Import
and then Is_Subprogram
(Id
) then
8056 Set_Import_Pragma
(Id
, Prag
);
8060 end Build_Export_Import_Pragma
;
8062 -------------------------------------------
8063 -- Build_Invariant_Procedure_Declaration --
8064 -------------------------------------------
8066 function Build_Invariant_Procedure_Declaration
8067 (Typ
: Entity_Id
) return Node_Id
8069 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
8074 Save_Ghost_Mode
: constant Ghost_Mode_Type
:= Ghost_Mode
;
8077 -- Check for duplicate definitions
8079 if Has_Invariants
(Typ
) and then Present
(Invariant_Procedure
(Typ
)) then
8083 -- The related type may be subject to pragma Ghost. Set the mode now to
8084 -- ensure that the invariant procedure is properly marked as Ghost.
8086 Set_Ghost_Mode_From_Entity
(Typ
);
8089 Make_Defining_Identifier
(Loc
,
8090 Chars
=> New_External_Name
(Chars
(Typ
), "Invariant"));
8091 Set_Has_Invariants
(Typ
);
8092 Set_Ekind
(SId
, E_Procedure
);
8093 Set_Etype
(SId
, Standard_Void_Type
);
8094 Set_Is_Invariant_Procedure
(SId
);
8095 Set_Invariant_Procedure
(Typ
, SId
);
8097 -- Source Coverage Obligations might be attached to the invariant
8098 -- expression this procedure evaluates, and we need debug info to be
8099 -- able to assess the coverage achieved by evaluations.
8101 if Opt
.Generate_SCO
then
8102 Set_Needs_Debug_Info
(SId
);
8105 -- Mark the invariant procedure explicitly as Ghost because it does not
8106 -- come from source.
8108 if Ghost_Mode
> None
then
8109 Set_Is_Ghost_Entity
(SId
);
8112 Obj_Id
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('I'));
8113 Set_Etype
(Obj_Id
, Typ
);
8116 Make_Subprogram_Declaration
(Loc
,
8117 Make_Procedure_Specification
(Loc
,
8118 Defining_Unit_Name
=> SId
,
8119 Parameter_Specifications
=> New_List
(
8120 Make_Parameter_Specification
(Loc
,
8121 Defining_Identifier
=> Obj_Id
,
8122 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)))));
8124 Ghost_Mode
:= Save_Ghost_Mode
;
8127 end Build_Invariant_Procedure_Declaration
;
8129 -------------------------------
8130 -- Build_Invariant_Procedure --
8131 -------------------------------
8133 -- The procedure that is constructed here has the form
8135 -- procedure typInvariant (Ixxx : typ) is
8137 -- pragma Check (Invariant, exp, "failed invariant from xxx");
8138 -- pragma Check (Invariant, exp, "failed invariant from xxx");
8140 -- pragma Check (Invariant, exp, "failed inherited invariant from xxx");
8142 -- end typInvariant;
8144 procedure Build_Invariant_Procedure
(Typ
: Entity_Id
; N
: Node_Id
) is
8145 procedure Add_Invariants
8148 Stmts
: in out List_Id
;
8150 -- Appends statements to Stmts for any invariants in the rep item chain
8151 -- of the given type. If Inherit is False, then we only process entries
8152 -- on the chain for the type Typ. If Inherit is True, then we ignore any
8153 -- Invariant aspects, but we process all Invariant'Class aspects, adding
8154 -- "inherited" to the exception message and generating an informational
8155 -- message about the inheritance of an invariant.
8157 --------------------
8158 -- Add_Invariants --
8159 --------------------
8161 procedure Add_Invariants
8164 Stmts
: in out List_Id
;
8167 procedure Add_Invariant
(Prag
: Node_Id
);
8168 -- Create a runtime check to verify the exression of invariant pragma
8169 -- Prag. All generated code is added to list Stmts.
8175 procedure Add_Invariant
(Prag
: Node_Id
) is
8176 procedure Replace_Type_Reference
(N
: Node_Id
);
8177 -- Replace a single occurrence N of the subtype name with a
8178 -- reference to the formal of the predicate function. N can be an
8179 -- identifier referencing the subtype, or a selected component,
8180 -- representing an appropriately qualified occurrence of the
8183 procedure Replace_Type_References
is
8184 new Replace_Type_References_Generic
(Replace_Type_Reference
);
8185 -- Traverse an expression replacing all occurrences of the subtype
8186 -- name with appropriate references to the formal of the predicate
8187 -- function. Note that we must ensure that the type and entity
8188 -- information is properly set in the replacement node, since we
8189 -- will do a Preanalyze call of this expression without proper
8190 -- visibility of the procedure argument.
8192 ----------------------------
8193 -- Replace_Type_Reference --
8194 ----------------------------
8196 -- Note: See comments in Add_Predicates.Replace_Type_Reference
8197 -- regarding handling of Sloc and Comes_From_Source.
8199 procedure Replace_Type_Reference
(N
: Node_Id
) is
8200 Nloc
: constant Source_Ptr
:= Sloc
(N
);
8203 -- Add semantic information to node to be rewritten, for ASIS
8204 -- navigation needs.
8206 if Nkind
(N
) = N_Identifier
then
8210 elsif Nkind
(N
) = N_Selected_Component
then
8211 Analyze
(Prefix
(N
));
8212 Set_Entity
(Selector_Name
(N
), T
);
8213 Set_Etype
(Selector_Name
(N
), T
);
8216 -- Invariant'Class, replace with T'Class (obj)
8218 if Class_Present
(Prag
) then
8220 -- In ASIS mode, an inherited item is already analyzed,
8221 -- and the replacement has been done, so do not repeat
8222 -- the transformation to prevent a malformed tree.
8225 and then Nkind
(Parent
(N
)) = N_Attribute_Reference
8226 and then Attribute_Name
(Parent
(N
)) = Name_Class
8232 Make_Type_Conversion
(Nloc
,
8234 Make_Attribute_Reference
(Nloc
,
8235 Prefix
=> New_Occurrence_Of
(T
, Nloc
),
8236 Attribute_Name
=> Name_Class
),
8238 Make_Identifier
(Nloc
, Chars
(Obj_Id
))));
8240 Set_Entity
(Expression
(N
), Obj_Id
);
8241 Set_Etype
(Expression
(N
), Typ
);
8244 -- Invariant, replace with obj
8247 Rewrite
(N
, Make_Identifier
(Nloc
, Chars
(Obj_Id
)));
8248 Set_Entity
(N
, Obj_Id
);
8252 Set_Comes_From_Source
(N
, True);
8253 end Replace_Type_Reference
;
8257 Asp
: constant Node_Id
:= Corresponding_Aspect
(Prag
);
8258 Nam
: constant Name_Id
:= Original_Aspect_Pragma_Name
(Prag
);
8259 Ploc
: constant Source_Ptr
:= Sloc
(Prag
);
8267 -- Start of processing for Add_Invariant
8270 -- Extract the arguments of the invariant pragma
8272 Arg1
:= First
(Pragma_Argument_Associations
(Prag
));
8273 Arg2
:= Next
(Arg1
);
8274 Arg3
:= Next
(Arg2
);
8276 Arg1
:= Get_Pragma_Arg
(Arg1
);
8277 Arg2
:= Get_Pragma_Arg
(Arg2
);
8279 -- The caller requests processing of all Invariant'Class pragmas,
8280 -- but the current pragma does not fall in this category. Return
8281 -- as there is nothing left to do.
8284 if not Class_Present
(Prag
) then
8288 -- Otherwise the pragma must apply to the current type
8290 elsif Entity
(Arg1
) /= T
then
8294 Expr
:= New_Copy_Tree
(Arg2
);
8296 -- Replace all occurrences of the type's name with references to
8297 -- the formal parameter of the invariant procedure.
8299 Replace_Type_References
(Expr
, T
);
8301 -- If the invariant pragma comes from an aspect, replace the saved
8302 -- expression because we need the subtype references replaced for
8303 -- the calls to Preanalyze_Spec_Expression in Check_Aspect_At_xxx
8304 -- routines. This is not done for interited class-wide invariants
8305 -- because the original pragma of the parent type must remain
8308 if not Inherit
and then Present
(Asp
) then
8309 Set_Entity
(Identifier
(Asp
), New_Copy_Tree
(Expr
));
8312 -- Preanalyze the invariant expression to capture the visibility
8313 -- of the proper package part. In general the expression is not
8314 -- fully analyzed until the body of the invariant procedure is
8315 -- analyzed at the end of the private part, but that yields the
8316 -- wrong visibility.
8318 -- Historical note: we used to set N as the parent, but a package
8319 -- specification as the parent of an expression is bizarre.
8321 Set_Parent
(Expr
, Parent
(Arg2
));
8322 Preanalyze_Assert_Expression
(Expr
, Any_Boolean
);
8324 -- Both modifications performed below are not done for inherited
8325 -- class-wide invariants because the origial aspect/pragma of the
8326 -- parent type must remain unchanged.
8330 -- A class-wide invariant may be inherited in a separate unit,
8331 -- where the corresponding expression cannot be resolved by
8332 -- visibility, because it refers to a local function. Propagate
8333 -- semantic information to the original representation item, to
8334 -- be used when an invariant procedure for a derived type is
8337 -- ??? Unclear how to handle class-wide invariants that are not
8340 if Class_Present
(Prag
)
8341 and then Nkind
(Expr
) = N_Function_Call
8342 and then Nkind
(Arg2
) = N_Indexed_Component
8345 Make_Function_Call
(Ploc
,
8347 New_Occurrence_Of
(Entity
(Name
(Expr
)), Ploc
),
8348 Parameter_Associations
=> Expressions
(Arg2
)));
8351 -- In ASIS mode, even if assertions are not enabled, we must
8352 -- analyze the original expression in the aspect specification
8353 -- because it is part of the original tree.
8355 if ASIS_Mode
and then Present
(Asp
) then
8357 Asp_Expr
: constant Node_Id
:= Expression
(Asp
);
8360 Replace_Type_References
(Asp_Expr
, T
);
8361 Preanalyze_Assert_Expression
(Asp_Expr
, Any_Boolean
);
8366 -- An ignored invariant must not generate a runtime check. Add a
8367 -- null statement to ensure that the invariant procedure does get
8368 -- a completing body.
8371 Stmts
:= Empty_List
;
8374 if Is_Ignored
(Prag
) then
8375 Append_To
(Stmts
, Make_Null_Statement
(Ploc
));
8377 -- Otherwise the invariant is checked. Build a Check pragma to
8378 -- verify the expression at runtime.
8382 Make_Pragma_Argument_Association
(Ploc
,
8383 Expression
=> Make_Identifier
(Ploc
, Nam
)),
8384 Make_Pragma_Argument_Association
(Ploc
,
8385 Expression
=> Expr
));
8387 -- Handle the String argument (if any)
8389 if Present
(Arg3
) then
8390 Str
:= Strval
(Get_Pragma_Arg
(Arg3
));
8392 -- When inheriting an invariant, modify the message from
8393 -- "failed invariant" to "failed inherited invariant".
8396 String_To_Name_Buffer
(Str
);
8398 if Name_Buffer
(1 .. 16) = "failed invariant" then
8399 Insert_Str_In_Name_Buffer
("inherited ", 8);
8400 Str
:= String_From_Name_Buffer
;
8405 Make_Pragma_Argument_Association
(Ploc
,
8406 Expression
=> Make_String_Literal
(Ploc
, Str
)));
8410 -- pragma Check (Nam, Expr, Str);
8414 Pragma_Identifier
=>
8415 Make_Identifier
(Ploc
, Name_Check
),
8416 Pragma_Argument_Associations
=> Assoc
));
8419 -- Output an info message when inheriting an invariant and the
8420 -- listing option is enabled.
8422 if Inherit
and Opt
.List_Inherited_Aspects
then
8423 Error_Msg_Sloc
:= Sloc
(Prag
);
8425 ("info: & inherits `Invariant''Class` aspect from #?L?", Typ
);
8433 -- Start of processing for Add_Invariants
8436 Ritem
:= First_Rep_Item
(T
);
8437 while Present
(Ritem
) loop
8438 if Nkind
(Ritem
) = N_Pragma
8439 and then Pragma_Name
(Ritem
) = Name_Invariant
8441 Add_Invariant
(Ritem
);
8444 Next_Rep_Item
(Ritem
);
8450 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
8451 Priv_Decls
: constant List_Id
:= Private_Declarations
(N
);
8452 Vis_Decls
: constant List_Id
:= Visible_Declarations
(N
);
8454 Save_Ghost_Mode
: constant Ghost_Mode_Type
:= Ghost_Mode
;
8463 -- The entity of the formal for the procedure
8465 -- Start of processing for Build_Invariant_Procedure
8468 -- The related type may be subject to pragma Ghost. Set the mode now to
8469 -- ensure that the invariant procedure is properly marked as Ghost.
8471 Set_Ghost_Mode_From_Entity
(Typ
);
8478 -- If the aspect specification exists for some view of the type, the
8479 -- declaration for the procedure has been created.
8481 if Has_Invariants
(Typ
) then
8482 SId
:= Invariant_Procedure
(Typ
);
8485 -- If the body is already present, nothing to do. This will occur when
8486 -- the type is already frozen, which is the case when the invariant
8487 -- appears in a private part, and the freezing takes place before the
8488 -- final pass over full declarations.
8490 -- See Exp_Ch3.Insert_Component_Invariant_Checks for details.
8492 if Present
(SId
) then
8493 PDecl
:= Unit_Declaration_Node
(SId
);
8496 and then Nkind
(PDecl
) = N_Subprogram_Declaration
8497 and then Present
(Corresponding_Body
(PDecl
))
8499 Ghost_Mode
:= Save_Ghost_Mode
;
8504 PDecl
:= Build_Invariant_Procedure_Declaration
(Typ
);
8507 -- Recover formal of procedure, for use in the calls to invariant
8508 -- functions (including inherited ones).
8512 (First
(Parameter_Specifications
(Specification
(PDecl
))));
8514 -- Add invariants for the current type
8522 -- Add invariants for parent types
8525 Current_Typ
: Entity_Id
;
8526 Parent_Typ
: Entity_Id
;
8531 Parent_Typ
:= Etype
(Current_Typ
);
8533 if Is_Private_Type
(Parent_Typ
)
8534 and then Present
(Full_View
(Base_Type
(Parent_Typ
)))
8536 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
8539 exit when Parent_Typ
= Current_Typ
;
8541 Current_Typ
:= Parent_Typ
;
8550 -- Add invariants of progenitors
8552 if Is_Tagged_Type
(Typ
) and then not Is_Interface
(Typ
) then
8554 Ifaces_List
: Elist_Id
;
8559 Collect_Interfaces
(Typ
, Ifaces_List
);
8561 AI
:= First_Elmt
(Ifaces_List
);
8562 while Present
(AI
) loop
8565 if not Is_Ancestor
(Iface
, Typ
, Use_Full_View
=> True) then
8578 -- Build the procedure if we generated at least one Check pragma
8580 if Stmts
/= No_List
then
8581 Spec
:= Copy_Separate_Tree
(Specification
(PDecl
));
8584 Make_Subprogram_Body
(Loc
,
8585 Specification
=> Spec
,
8586 Declarations
=> Empty_List
,
8587 Handled_Statement_Sequence
=>
8588 Make_Handled_Sequence_Of_Statements
(Loc
,
8589 Statements
=> Stmts
));
8591 -- The processing of an invariant pragma immediately generates the
8592 -- invariant procedure spec, inserts it into the tree, and analyzes
8593 -- it. If the spec has not been analyzed, then the invariant pragma
8594 -- is being inherited and requires manual insertion and analysis.
8596 if not Analyzed
(PDecl
) then
8597 Append_To
(Vis_Decls
, PDecl
);
8601 -- The invariant procedure body is inserted at the end of the private
8604 if Present
(Priv_Decls
) then
8605 Append_To
(Priv_Decls
, PBody
);
8607 -- If the invariant appears on the full view of a private type,
8608 -- then the analysis of the private part is already completed.
8609 -- Manually analyze the new body in this case, otherwise wait
8610 -- for the analysis of the private declarations to process the
8613 if In_Private_Part
(Current_Scope
) then
8617 -- Otherwise there are no private declarations. This is either an
8618 -- error or the related type is a private extension, in which case
8619 -- it does not need a completion in a private part. Insert the body
8620 -- at the end of the visible declarations and analyze immediately
8621 -- because the related type is about to be frozen.
8624 Append_To
(Vis_Decls
, PBody
);
8629 Ghost_Mode
:= Save_Ghost_Mode
;
8630 end Build_Invariant_Procedure
;
8632 -------------------------------
8633 -- Build_Predicate_Functions --
8634 -------------------------------
8636 -- The procedures that are constructed here have the form:
8638 -- function typPredicate (Ixxx : typ) return Boolean is
8641 -- typ1Predicate (typ1 (Ixxx))
8642 -- and then typ2Predicate (typ2 (Ixxx))
8644 -- exp1 and then exp2 and then ...
8645 -- end typPredicate;
8647 -- Here exp1, and exp2 are expressions from Predicate pragmas. Note that
8648 -- this is the point at which these expressions get analyzed, providing the
8649 -- required delay, and typ1, typ2, are entities from which predicates are
8650 -- inherited. Note that we do NOT generate Check pragmas, that's because we
8651 -- use this function even if checks are off, e.g. for membership tests.
8653 -- Note that the inherited predicates are evaluated first, as required by
8656 -- Note that Sem_Eval.Real_Or_String_Static_Predicate_Matches depends on
8657 -- the form of this return expression.
8659 -- If the expression has at least one Raise_Expression, then we also build
8660 -- the typPredicateM version of the function, in which any occurrence of a
8661 -- Raise_Expression is converted to "return False".
8663 procedure Build_Predicate_Functions
(Typ
: Entity_Id
; N
: Node_Id
) is
8664 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
8667 -- This is the expression for the result of the function. It is
8668 -- is build by connecting the component predicates with AND THEN.
8671 -- This is the corresponding return expression for the Predicate_M
8672 -- function. It differs in that raise expressions are marked for
8673 -- special expansion (see Process_REs).
8675 Object_Name
: Name_Id
;
8676 -- Name for argument of Predicate procedure. Note that we use the same
8677 -- name for both predicate functions. That way the reference within the
8678 -- predicate expression is the same in both functions.
8680 Object_Entity
: Entity_Id
;
8681 -- Entity for argument of Predicate procedure
8683 Object_Entity_M
: Entity_Id
;
8684 -- Entity for argument of separate Predicate procedure when exceptions
8685 -- are present in expression.
8688 -- The function declaration
8693 Raise_Expression_Present
: Boolean := False;
8694 -- Set True if Expr has at least one Raise_Expression
8696 procedure Add_Condition
(Cond
: Node_Id
);
8697 -- Append Cond to Expr using "and then" (or just copy Cond to Expr if
8700 procedure Add_Predicates
;
8701 -- Appends expressions for any Predicate pragmas in the rep item chain
8702 -- Typ to Expr. Note that we look only at items for this exact entity.
8703 -- Inheritance of predicates for the parent type is done by calling the
8704 -- Predicate_Function of the parent type, using Add_Call above.
8706 procedure Add_Call
(T
: Entity_Id
);
8707 -- Includes a call to the predicate function for type T in Expr if T
8708 -- has predicates and Predicate_Function (T) is non-empty.
8710 function Process_RE
(N
: Node_Id
) return Traverse_Result
;
8711 -- Used in Process REs, tests if node N is a raise expression, and if
8712 -- so, marks it to be converted to return False.
8714 procedure Process_REs
is new Traverse_Proc
(Process_RE
);
8715 -- Marks any raise expressions in Expr_M to return False
8717 function Test_RE
(N
: Node_Id
) return Traverse_Result
;
8718 -- Used in Test_REs, tests one node for being a raise expression, and if
8719 -- so sets Raise_Expression_Present True.
8721 procedure Test_REs
is new Traverse_Proc
(Test_RE
);
8722 -- Tests to see if Expr contains any raise expressions
8728 procedure Add_Call
(T
: Entity_Id
) is
8732 if Present
(T
) and then Present
(Predicate_Function
(T
)) then
8733 Set_Has_Predicates
(Typ
);
8735 -- Build the call to the predicate function of T
8739 (T
, Convert_To
(T
, Make_Identifier
(Loc
, Object_Name
)));
8741 -- "and"-in the call to evolving expression
8743 Add_Condition
(Exp
);
8745 -- Output info message on inheritance if required. Note we do not
8746 -- give this information for generic actual types, since it is
8747 -- unwelcome noise in that case in instantiations. We also
8748 -- generally suppress the message in instantiations, and also
8749 -- if it involves internal names.
8751 if Opt
.List_Inherited_Aspects
8752 and then not Is_Generic_Actual_Type
(Typ
)
8753 and then Instantiation_Depth
(Sloc
(Typ
)) = 0
8754 and then not Is_Internal_Name
(Chars
(T
))
8755 and then not Is_Internal_Name
(Chars
(Typ
))
8757 Error_Msg_Sloc
:= Sloc
(Predicate_Function
(T
));
8758 Error_Msg_Node_2
:= T
;
8759 Error_Msg_N
("info: & inherits predicate from & #?L?", Typ
);
8768 procedure Add_Condition
(Cond
: Node_Id
) is
8770 -- This is the first predicate expression
8775 -- Otherwise concatenate to the existing predicate expressions by
8776 -- using "and then".
8781 Left_Opnd
=> Relocate_Node
(Expr
),
8782 Right_Opnd
=> Cond
);
8786 --------------------
8787 -- Add_Predicates --
8788 --------------------
8790 procedure Add_Predicates
is
8791 procedure Add_Predicate
(Prag
: Node_Id
);
8792 -- Concatenate the expression of predicate pragma Prag to Expr by
8793 -- using a short circuit "and then" operator.
8799 procedure Add_Predicate
(Prag
: Node_Id
) is
8800 procedure Replace_Type_Reference
(N
: Node_Id
);
8801 -- Replace a single occurrence N of the subtype name with a
8802 -- reference to the formal of the predicate function. N can be an
8803 -- identifier referencing the subtype, or a selected component,
8804 -- representing an appropriately qualified occurrence of the
8807 procedure Replace_Type_References
is
8808 new Replace_Type_References_Generic
(Replace_Type_Reference
);
8809 -- Traverse an expression changing every occurrence of an
8810 -- identifier whose name matches the name of the subtype with a
8811 -- reference to the formal parameter of the predicate function.
8813 ----------------------------
8814 -- Replace_Type_Reference --
8815 ----------------------------
8817 procedure Replace_Type_Reference
(N
: Node_Id
) is
8819 Rewrite
(N
, Make_Identifier
(Sloc
(N
), Object_Name
));
8820 -- Use the Sloc of the usage name, not the defining name
8823 Set_Entity
(N
, Object_Entity
);
8825 -- We want to treat the node as if it comes from source, so
8826 -- that ASIS will not ignore it.
8828 Set_Comes_From_Source
(N
, True);
8829 end Replace_Type_Reference
;
8833 Asp
: constant Node_Id
:= Corresponding_Aspect
(Prag
);
8837 -- Start of processing for Add_Predicate
8840 -- Extract the arguments of the pragma. The expression itself
8841 -- is copied for use in the predicate function, to preserve the
8842 -- original version for ASIS use.
8844 Arg1
:= First
(Pragma_Argument_Associations
(Prag
));
8845 Arg2
:= Next
(Arg1
);
8847 Arg1
:= Get_Pragma_Arg
(Arg1
);
8848 Arg2
:= New_Copy_Tree
(Get_Pragma_Arg
(Arg2
));
8850 -- When the predicate pragma applies to the current type or its
8851 -- full view, replace all occurrences of the subtype name with
8852 -- references to the formal parameter of the predicate function.
8854 if Entity
(Arg1
) = Typ
8855 or else Full_View
(Entity
(Arg1
)) = Typ
8857 Replace_Type_References
(Arg2
, Typ
);
8859 -- If the predicate pragma comes from an aspect, replace the
8860 -- saved expression because we need the subtype references
8861 -- replaced for the calls to Preanalyze_Spec_Expression in
8862 -- Check_Aspect_At_xxx routines.
8864 if Present
(Asp
) then
8865 Set_Entity
(Identifier
(Asp
), New_Copy_Tree
(Arg2
));
8868 -- "and"-in the Arg2 condition to evolving expression
8870 Add_Condition
(Relocate_Node
(Arg2
));
8878 -- Start of processing for Add_Predicates
8881 Ritem
:= First_Rep_Item
(Typ
);
8882 while Present
(Ritem
) loop
8883 if Nkind
(Ritem
) = N_Pragma
8884 and then Pragma_Name
(Ritem
) = Name_Predicate
8886 Add_Predicate
(Ritem
);
8888 -- If the type is declared in an inner package it may be frozen
8889 -- outside of the package, and the generated pragma has not been
8890 -- analyzed yet, so capture the expression for the predicate
8891 -- function at this point.
8893 elsif Nkind
(Ritem
) = N_Aspect_Specification
8894 and then Present
(Aspect_Rep_Item
(Ritem
))
8895 and then Scope
(Typ
) /= Current_Scope
8898 Prag
: constant Node_Id
:= Aspect_Rep_Item
(Ritem
);
8901 if Nkind
(Prag
) = N_Pragma
8902 and then Pragma_Name
(Prag
) = Name_Predicate
8904 Add_Predicate
(Prag
);
8909 Next_Rep_Item
(Ritem
);
8917 function Process_RE
(N
: Node_Id
) return Traverse_Result
is
8919 if Nkind
(N
) = N_Raise_Expression
then
8920 Set_Convert_To_Return_False
(N
);
8931 function Test_RE
(N
: Node_Id
) return Traverse_Result
is
8933 if Nkind
(N
) = N_Raise_Expression
then
8934 Raise_Expression_Present
:= True;
8943 Save_Ghost_Mode
: constant Ghost_Mode_Type
:= Ghost_Mode
;
8945 -- Start of processing for Build_Predicate_Functions
8948 -- Return if already built or if type does not have predicates
8950 SId
:= Predicate_Function
(Typ
);
8951 if not Has_Predicates
(Typ
)
8952 or else (Present
(SId
) and then Has_Completion
(SId
))
8957 -- The related type may be subject to pragma Ghost. Set the mode now to
8958 -- ensure that the predicate functions are properly marked as Ghost.
8960 Set_Ghost_Mode_From_Entity
(Typ
);
8962 -- Prepare to construct predicate expression
8966 if Present
(SId
) then
8967 FDecl
:= Unit_Declaration_Node
(SId
);
8970 FDecl
:= Build_Predicate_Function_Declaration
(Typ
);
8971 SId
:= Defining_Entity
(FDecl
);
8974 -- Recover name of formal parameter of function that replaces references
8975 -- to the type in predicate expressions.
8979 (First
(Parameter_Specifications
(Specification
(FDecl
))));
8981 Object_Name
:= Chars
(Object_Entity
);
8982 Object_Entity_M
:= Make_Defining_Identifier
(Loc
, Chars
=> Object_Name
);
8984 -- Add predicates for ancestor if present. These must come before the
8985 -- ones for the current type, as required by AI12-0071-1.
8988 Atyp
: constant Entity_Id
:= Nearest_Ancestor
(Typ
);
8990 if Present
(Atyp
) then
8995 -- Add Predicates for the current type
8999 -- Case where predicates are present
9001 if Present
(Expr
) then
9003 -- Test for raise expression present
9007 -- If raise expression is present, capture a copy of Expr for use
9008 -- in building the predicateM function version later on. For this
9009 -- copy we replace references to Object_Entity by Object_Entity_M.
9011 if Raise_Expression_Present
then
9013 Map
: constant Elist_Id
:= New_Elmt_List
;
9014 New_V
: Entity_Id
:= Empty
;
9016 -- The unanalyzed expression will be copied and appear in
9017 -- both functions. Normally expressions do not declare new
9018 -- entities, but quantified expressions do, so we need to
9019 -- create new entities for their bound variables, to prevent
9020 -- multiple definitions in gigi.
9022 function Reset_Loop_Variable
(N
: Node_Id
)
9023 return Traverse_Result
;
9025 procedure Collect_Loop_Variables
is
9026 new Traverse_Proc
(Reset_Loop_Variable
);
9028 ------------------------
9029 -- Reset_Loop_Variable --
9030 ------------------------
9032 function Reset_Loop_Variable
(N
: Node_Id
)
9033 return Traverse_Result
9036 if Nkind
(N
) = N_Iterator_Specification
then
9037 New_V
:= Make_Defining_Identifier
9038 (Sloc
(N
), Chars
(Defining_Identifier
(N
)));
9040 Set_Defining_Identifier
(N
, New_V
);
9044 end Reset_Loop_Variable
;
9047 Append_Elmt
(Object_Entity
, Map
);
9048 Append_Elmt
(Object_Entity_M
, Map
);
9049 Expr_M
:= New_Copy_Tree
(Expr
, Map
=> Map
);
9050 Collect_Loop_Variables
(Expr_M
);
9054 -- Build the main predicate function
9057 SIdB
: constant Entity_Id
:=
9058 Make_Defining_Identifier
(Loc
,
9059 Chars
=> New_External_Name
(Chars
(Typ
), "Predicate"));
9060 -- The entity for the function body
9067 -- The predicate function is shared between views of a type
9069 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
9070 Set_Predicate_Function
(Full_View
(Typ
), SId
);
9073 -- Mark the predicate function explicitly as Ghost because it does
9074 -- not come from source.
9076 if Ghost_Mode
> None
then
9077 Set_Is_Ghost_Entity
(SId
);
9080 -- Build function body
9083 Make_Function_Specification
(Loc
,
9084 Defining_Unit_Name
=> SIdB
,
9085 Parameter_Specifications
=> New_List
(
9086 Make_Parameter_Specification
(Loc
,
9087 Defining_Identifier
=>
9088 Make_Defining_Identifier
(Loc
, Object_Name
),
9090 New_Occurrence_Of
(Typ
, Loc
))),
9091 Result_Definition
=>
9092 New_Occurrence_Of
(Standard_Boolean
, Loc
));
9095 Make_Subprogram_Body
(Loc
,
9096 Specification
=> Spec
,
9097 Declarations
=> Empty_List
,
9098 Handled_Statement_Sequence
=>
9099 Make_Handled_Sequence_Of_Statements
(Loc
,
9100 Statements
=> New_List
(
9101 Make_Simple_Return_Statement
(Loc
,
9102 Expression
=> Expr
))));
9104 -- If declaration has not been analyzed yet, Insert declaration
9105 -- before freeze node.
9106 -- Insert body after freeze node.
9108 if not Analyzed
(FDecl
) then
9109 Insert_Before_And_Analyze
(N
, FDecl
);
9112 Insert_After_And_Analyze
(N
, FBody
);
9114 -- Static predicate functions are always side-effect free, and
9115 -- in most cases dynamic predicate functions are as well. Mark
9116 -- them as such whenever possible, so redundant predicate checks
9117 -- can be optimized. If there is a variable reference within the
9118 -- expression, the function is not pure.
9120 if Expander_Active
then
9122 Side_Effect_Free
(Expr
, Variable_Ref
=> True));
9123 Set_Is_Inlined
(SId
);
9127 -- Test for raise expressions present and if so build M version
9129 if Raise_Expression_Present
then
9131 SId
: constant Entity_Id
:=
9132 Make_Defining_Identifier
(Loc
,
9133 Chars
=> New_External_Name
(Chars
(Typ
), "PredicateM"));
9134 -- The entity for the function spec
9136 SIdB
: constant Entity_Id
:=
9137 Make_Defining_Identifier
(Loc
,
9138 Chars
=> New_External_Name
(Chars
(Typ
), "PredicateM"));
9139 -- The entity for the function body
9147 -- Mark any raise expressions for special expansion
9149 Process_REs
(Expr_M
);
9151 -- Build function declaration
9153 Set_Ekind
(SId
, E_Function
);
9154 Set_Is_Predicate_Function_M
(SId
);
9155 Set_Predicate_Function_M
(Typ
, SId
);
9157 -- The predicate function is shared between views of a type
9159 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
9160 Set_Predicate_Function_M
(Full_View
(Typ
), SId
);
9163 -- Mark the predicate function explicitly as Ghost because it
9164 -- does not come from source.
9166 if Ghost_Mode
> None
then
9167 Set_Is_Ghost_Entity
(SId
);
9171 Make_Function_Specification
(Loc
,
9172 Defining_Unit_Name
=> SId
,
9173 Parameter_Specifications
=> New_List
(
9174 Make_Parameter_Specification
(Loc
,
9175 Defining_Identifier
=> Object_Entity_M
,
9176 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))),
9177 Result_Definition
=>
9178 New_Occurrence_Of
(Standard_Boolean
, Loc
));
9181 Make_Subprogram_Declaration
(Loc
,
9182 Specification
=> Spec
);
9184 -- Build function body
9187 Make_Function_Specification
(Loc
,
9188 Defining_Unit_Name
=> SIdB
,
9189 Parameter_Specifications
=> New_List
(
9190 Make_Parameter_Specification
(Loc
,
9191 Defining_Identifier
=>
9192 Make_Defining_Identifier
(Loc
, Object_Name
),
9194 New_Occurrence_Of
(Typ
, Loc
))),
9195 Result_Definition
=>
9196 New_Occurrence_Of
(Standard_Boolean
, Loc
));
9198 -- Build the body, we declare the boolean expression before
9199 -- doing the return, because we are not really confident of
9200 -- what happens if a return appears within a return.
9203 Make_Defining_Identifier
(Loc
,
9204 Chars
=> New_Internal_Name
('B'));
9207 Make_Subprogram_Body
(Loc
,
9208 Specification
=> Spec
,
9210 Declarations
=> New_List
(
9211 Make_Object_Declaration
(Loc
,
9212 Defining_Identifier
=> BTemp
,
9213 Constant_Present
=> True,
9214 Object_Definition
=>
9215 New_Occurrence_Of
(Standard_Boolean
, Loc
),
9216 Expression
=> Expr_M
)),
9218 Handled_Statement_Sequence
=>
9219 Make_Handled_Sequence_Of_Statements
(Loc
,
9220 Statements
=> New_List
(
9221 Make_Simple_Return_Statement
(Loc
,
9222 Expression
=> New_Occurrence_Of
(BTemp
, Loc
)))));
9224 -- Insert declaration before freeze node and body after
9226 Insert_Before_And_Analyze
(N
, FDecl
);
9227 Insert_After_And_Analyze
(N
, FBody
);
9231 -- See if we have a static predicate. Note that the answer may be
9232 -- yes even if we have an explicit Dynamic_Predicate present.
9239 if not Is_Scalar_Type
(Typ
) and then not Is_String_Type
(Typ
) then
9242 PS
:= Is_Predicate_Static
(Expr
, Object_Name
);
9245 -- Case where we have a predicate-static aspect
9249 -- We don't set Has_Static_Predicate_Aspect, since we can have
9250 -- any of the three cases (Predicate, Dynamic_Predicate, or
9251 -- Static_Predicate) generating a predicate with an expression
9252 -- that is predicate-static. We just indicate that we have a
9253 -- predicate that can be treated as static.
9255 Set_Has_Static_Predicate
(Typ
);
9257 -- For discrete subtype, build the static predicate list
9259 if Is_Discrete_Type
(Typ
) then
9260 Build_Discrete_Static_Predicate
(Typ
, Expr
, Object_Name
);
9262 -- If we don't get a static predicate list, it means that we
9263 -- have a case where this is not possible, most typically in
9264 -- the case where we inherit a dynamic predicate. We do not
9265 -- consider this an error, we just leave the predicate as
9266 -- dynamic. But if we do succeed in building the list, then
9267 -- we mark the predicate as static.
9269 if No
(Static_Discrete_Predicate
(Typ
)) then
9270 Set_Has_Static_Predicate
(Typ
, False);
9273 -- For real or string subtype, save predicate expression
9275 elsif Is_Real_Type
(Typ
) or else Is_String_Type
(Typ
) then
9276 Set_Static_Real_Or_String_Predicate
(Typ
, Expr
);
9279 -- Case of dynamic predicate (expression is not predicate-static)
9282 -- Again, we don't set Has_Dynamic_Predicate_Aspect, since that
9283 -- is only set if we have an explicit Dynamic_Predicate aspect
9284 -- given. Here we may simply have a Predicate aspect where the
9285 -- expression happens not to be predicate-static.
9287 -- Emit an error when the predicate is categorized as static
9288 -- but its expression is not predicate-static.
9290 -- First a little fiddling to get a nice location for the
9291 -- message. If the expression is of the form (A and then B),
9292 -- where A is an inherited predicate, then use the right
9293 -- operand for the Sloc. This avoids getting confused by a call
9294 -- to an inherited predicate with a less convenient source
9298 while Nkind
(EN
) = N_And_Then
9299 and then Nkind
(Left_Opnd
(EN
)) = N_Function_Call
9300 and then Is_Predicate_Function
9301 (Entity
(Name
(Left_Opnd
(EN
))))
9303 EN
:= Right_Opnd
(EN
);
9306 -- Now post appropriate message
9308 if Has_Static_Predicate_Aspect
(Typ
) then
9309 if Is_Scalar_Type
(Typ
) or else Is_String_Type
(Typ
) then
9311 ("expression is not predicate-static (RM 3.2.4(16-22))",
9315 ("static predicate requires scalar or string type", EN
);
9322 Ghost_Mode
:= Save_Ghost_Mode
;
9323 end Build_Predicate_Functions
;
9325 ------------------------------------------
9326 -- Build_Predicate_Function_Declaration --
9327 ------------------------------------------
9329 function Build_Predicate_Function_Declaration
9330 (Typ
: Entity_Id
) return Node_Id
9332 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
9334 Object_Entity
: constant Entity_Id
:=
9335 Make_Defining_Identifier
(Loc
,
9336 Chars
=> New_Internal_Name
('I'));
9338 -- The formal parameter of the function
9340 SId
: constant Entity_Id
:=
9341 Make_Defining_Identifier
(Loc
,
9342 Chars
=> New_External_Name
(Chars
(Typ
), "Predicate"));
9344 -- The entity for the function spec
9351 Make_Function_Specification
(Loc
,
9352 Defining_Unit_Name
=> SId
,
9353 Parameter_Specifications
=> New_List
(
9354 Make_Parameter_Specification
(Loc
,
9355 Defining_Identifier
=> Object_Entity
,
9356 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))),
9357 Result_Definition
=>
9358 New_Occurrence_Of
(Standard_Boolean
, Loc
));
9360 FDecl
:= Make_Subprogram_Declaration
(Loc
, Specification
=> Spec
);
9362 Set_Ekind
(SId
, E_Function
);
9363 Set_Etype
(SId
, Standard_Boolean
);
9364 Set_Is_Internal
(SId
);
9365 Set_Is_Predicate_Function
(SId
);
9366 Set_Predicate_Function
(Typ
, SId
);
9368 if Comes_From_Source
(Typ
) then
9369 Insert_After
(Parent
(Typ
), FDecl
);
9371 Insert_After
(Parent
(Base_Type
(Typ
)), FDecl
);
9377 end Build_Predicate_Function_Declaration
;
9379 -----------------------------------------
9380 -- Check_Aspect_At_End_Of_Declarations --
9381 -----------------------------------------
9383 procedure Check_Aspect_At_End_Of_Declarations
(ASN
: Node_Id
) is
9384 Ent
: constant Entity_Id
:= Entity
(ASN
);
9385 Ident
: constant Node_Id
:= Identifier
(ASN
);
9386 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Chars
(Ident
));
9388 End_Decl_Expr
: constant Node_Id
:= Entity
(Ident
);
9389 -- Expression to be analyzed at end of declarations
9391 Freeze_Expr
: constant Node_Id
:= Expression
(ASN
);
9392 -- Expression from call to Check_Aspect_At_Freeze_Point
9394 T
: constant Entity_Id
:= Etype
(Freeze_Expr
);
9395 -- Type required for preanalyze call
9398 -- Set False if error
9400 -- On entry to this procedure, Entity (Ident) contains a copy of the
9401 -- original expression from the aspect, saved for this purpose, and
9402 -- but Expression (Ident) is a preanalyzed copy of the expression,
9403 -- preanalyzed just after the freeze point.
9405 procedure Check_Overloaded_Name
;
9406 -- For aspects whose expression is simply a name, this routine checks if
9407 -- the name is overloaded or not. If so, it verifies there is an
9408 -- interpretation that matches the entity obtained at the freeze point,
9409 -- otherwise the compiler complains.
9411 ---------------------------
9412 -- Check_Overloaded_Name --
9413 ---------------------------
9415 procedure Check_Overloaded_Name
is
9417 if not Is_Overloaded
(End_Decl_Expr
) then
9418 Err
:= not Is_Entity_Name
(End_Decl_Expr
)
9419 or else Entity
(End_Decl_Expr
) /= Entity
(Freeze_Expr
);
9425 Index
: Interp_Index
;
9429 Get_First_Interp
(End_Decl_Expr
, Index
, It
);
9430 while Present
(It
.Typ
) loop
9431 if It
.Nam
= Entity
(Freeze_Expr
) then
9436 Get_Next_Interp
(Index
, It
);
9440 end Check_Overloaded_Name
;
9442 -- Start of processing for Check_Aspect_At_End_Of_Declarations
9445 -- In an instance we do not perform the consistency check between freeze
9446 -- point and end of declarations, because it was done already in the
9447 -- analysis of the generic. Furthermore, the delayed analysis of an
9448 -- aspect of the instance may produce spurious errors when the generic
9449 -- is a child unit that references entities in the parent (which might
9450 -- not be in scope at the freeze point of the instance).
9455 -- Case of aspects Dimension, Dimension_System and Synchronization
9457 elsif A_Id
= Aspect_Synchronization
then
9460 -- Case of stream attributes, just have to compare entities. However,
9461 -- the expression is just a name (possibly overloaded), and there may
9462 -- be stream operations declared for unrelated types, so we just need
9463 -- to verify that one of these interpretations is the one available at
9464 -- at the freeze point.
9466 elsif A_Id
= Aspect_Input
or else
9467 A_Id
= Aspect_Output
or else
9468 A_Id
= Aspect_Read
or else
9471 Analyze
(End_Decl_Expr
);
9472 Check_Overloaded_Name
;
9474 elsif A_Id
= Aspect_Variable_Indexing
or else
9475 A_Id
= Aspect_Constant_Indexing
or else
9476 A_Id
= Aspect_Default_Iterator
or else
9477 A_Id
= Aspect_Iterator_Element
9479 -- Make type unfrozen before analysis, to prevent spurious errors
9480 -- about late attributes.
9482 Set_Is_Frozen
(Ent
, False);
9483 Analyze
(End_Decl_Expr
);
9484 Set_Is_Frozen
(Ent
, True);
9486 -- If the end of declarations comes before any other freeze
9487 -- point, the Freeze_Expr is not analyzed: no check needed.
9489 if Analyzed
(Freeze_Expr
) and then not In_Instance
then
9490 Check_Overloaded_Name
;
9498 -- Indicate that the expression comes from an aspect specification,
9499 -- which is used in subsequent analysis even if expansion is off.
9501 Set_Parent
(End_Decl_Expr
, ASN
);
9503 -- In a generic context the aspect expressions have not been
9504 -- preanalyzed, so do it now. There are no conformance checks
9505 -- to perform in this case.
9508 Check_Aspect_At_Freeze_Point
(ASN
);
9511 -- The default values attributes may be defined in the private part,
9512 -- and the analysis of the expression may take place when only the
9513 -- partial view is visible. The expression must be scalar, so use
9514 -- the full view to resolve.
9516 elsif (A_Id
= Aspect_Default_Value
9518 A_Id
= Aspect_Default_Component_Value
)
9519 and then Is_Private_Type
(T
)
9521 Preanalyze_Spec_Expression
(End_Decl_Expr
, Full_View
(T
));
9524 Preanalyze_Spec_Expression
(End_Decl_Expr
, T
);
9527 Err
:= not Fully_Conformant_Expressions
(End_Decl_Expr
, Freeze_Expr
);
9530 -- Output error message if error. Force error on aspect specification
9531 -- even if there is an error on the expression itself.
9535 ("!visibility of aspect for& changes after freeze point",
9538 ("info: & is frozen here, aspects evaluated at this point??",
9539 Freeze_Node
(Ent
), Ent
);
9541 end Check_Aspect_At_End_Of_Declarations
;
9543 ----------------------------------
9544 -- Check_Aspect_At_Freeze_Point --
9545 ----------------------------------
9547 procedure Check_Aspect_At_Freeze_Point
(ASN
: Node_Id
) is
9548 Ident
: constant Node_Id
:= Identifier
(ASN
);
9549 -- Identifier (use Entity field to save expression)
9551 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Chars
(Ident
));
9553 T
: Entity_Id
:= Empty
;
9554 -- Type required for preanalyze call
9557 -- On entry to this procedure, Entity (Ident) contains a copy of the
9558 -- original expression from the aspect, saved for this purpose.
9560 -- On exit from this procedure Entity (Ident) is unchanged, still
9561 -- containing that copy, but Expression (Ident) is a preanalyzed copy
9562 -- of the expression, preanalyzed just after the freeze point.
9564 -- Make a copy of the expression to be preanalyzed
9566 Set_Expression
(ASN
, New_Copy_Tree
(Entity
(Ident
)));
9568 -- Find type for preanalyze call
9572 -- No_Aspect should be impossible
9575 raise Program_Error
;
9577 -- Aspects taking an optional boolean argument
9579 when Boolean_Aspects |
9580 Library_Unit_Aspects
=>
9582 T
:= Standard_Boolean
;
9584 -- Aspects corresponding to attribute definition clauses
9586 when Aspect_Address
=>
9587 T
:= RTE
(RE_Address
);
9589 when Aspect_Attach_Handler
=>
9590 T
:= RTE
(RE_Interrupt_ID
);
9592 when Aspect_Bit_Order | Aspect_Scalar_Storage_Order
=>
9593 T
:= RTE
(RE_Bit_Order
);
9595 when Aspect_Convention
=>
9599 T
:= RTE
(RE_CPU_Range
);
9601 -- Default_Component_Value is resolved with the component type
9603 when Aspect_Default_Component_Value
=>
9604 T
:= Component_Type
(Entity
(ASN
));
9606 when Aspect_Default_Storage_Pool
=>
9607 T
:= Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
));
9609 -- Default_Value is resolved with the type entity in question
9611 when Aspect_Default_Value
=>
9614 when Aspect_Dispatching_Domain
=>
9615 T
:= RTE
(RE_Dispatching_Domain
);
9617 when Aspect_External_Tag
=>
9618 T
:= Standard_String
;
9620 when Aspect_External_Name
=>
9621 T
:= Standard_String
;
9623 when Aspect_Link_Name
=>
9624 T
:= Standard_String
;
9626 when Aspect_Priority | Aspect_Interrupt_Priority
=>
9627 T
:= Standard_Integer
;
9629 when Aspect_Relative_Deadline
=>
9630 T
:= RTE
(RE_Time_Span
);
9632 when Aspect_Small
=>
9633 T
:= Universal_Real
;
9635 -- For a simple storage pool, we have to retrieve the type of the
9636 -- pool object associated with the aspect's corresponding attribute
9637 -- definition clause.
9639 when Aspect_Simple_Storage_Pool
=>
9640 T
:= Etype
(Expression
(Aspect_Rep_Item
(ASN
)));
9642 when Aspect_Storage_Pool
=>
9643 T
:= Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
));
9645 when Aspect_Alignment |
9646 Aspect_Component_Size |
9647 Aspect_Machine_Radix |
9648 Aspect_Object_Size |
9650 Aspect_Storage_Size |
9651 Aspect_Stream_Size |
9652 Aspect_Value_Size
=>
9655 when Aspect_Linker_Section
=>
9656 T
:= Standard_String
;
9658 when Aspect_Synchronization
=>
9661 -- Special case, the expression of these aspects is just an entity
9662 -- that does not need any resolution, so just analyze.
9671 Analyze
(Expression
(ASN
));
9674 -- Same for Iterator aspects, where the expression is a function
9675 -- name. Legality rules are checked separately.
9677 when Aspect_Constant_Indexing |
9678 Aspect_Default_Iterator |
9679 Aspect_Iterator_Element |
9680 Aspect_Variable_Indexing
=>
9681 Analyze
(Expression
(ASN
));
9684 -- Ditto for Iterable, legality checks in Validate_Iterable_Aspect.
9686 when Aspect_Iterable
=>
9690 Cursor
: constant Entity_Id
:= Get_Cursor_Type
(ASN
, T
);
9695 if Cursor
= Any_Type
then
9699 Assoc
:= First
(Component_Associations
(Expression
(ASN
)));
9700 while Present
(Assoc
) loop
9701 Expr
:= Expression
(Assoc
);
9704 if not Error_Posted
(Expr
) then
9705 Resolve_Iterable_Operation
9706 (Expr
, Cursor
, T
, Chars
(First
(Choices
(Assoc
))));
9715 -- Invariant/Predicate take boolean expressions
9717 when Aspect_Dynamic_Predicate |
9720 Aspect_Static_Predicate |
9721 Aspect_Type_Invariant
=>
9722 T
:= Standard_Boolean
;
9724 when Aspect_Predicate_Failure
=>
9725 T
:= Standard_String
;
9727 -- Here is the list of aspects that don't require delay analysis
9729 when Aspect_Abstract_State |
9731 Aspect_Async_Readers |
9732 Aspect_Async_Writers |
9733 Aspect_Constant_After_Elaboration |
9734 Aspect_Contract_Cases |
9735 Aspect_Default_Initial_Condition |
9738 Aspect_Dimension_System |
9739 Aspect_Effective_Reads |
9740 Aspect_Effective_Writes |
9741 Aspect_Extensions_Visible |
9744 Aspect_Implicit_Dereference |
9745 Aspect_Initial_Condition |
9746 Aspect_Initializes |
9747 Aspect_Obsolescent |
9750 Aspect_Postcondition |
9752 Aspect_Precondition |
9753 Aspect_Refined_Depends |
9754 Aspect_Refined_Global |
9755 Aspect_Refined_Post |
9756 Aspect_Refined_State |
9759 Aspect_Unimplemented |
9760 Aspect_Volatile_Function
=>
9761 raise Program_Error
;
9765 -- Do the preanalyze call
9767 Preanalyze_Spec_Expression
(Expression
(ASN
), T
);
9768 end Check_Aspect_At_Freeze_Point
;
9770 -----------------------------------
9771 -- Check_Constant_Address_Clause --
9772 -----------------------------------
9774 procedure Check_Constant_Address_Clause
9778 procedure Check_At_Constant_Address
(Nod
: Node_Id
);
9779 -- Checks that the given node N represents a name whose 'Address is
9780 -- constant (in the same sense as OK_Constant_Address_Clause, i.e. the
9781 -- address value is the same at the point of declaration of U_Ent and at
9782 -- the time of elaboration of the address clause.
9784 procedure Check_Expr_Constants
(Nod
: Node_Id
);
9785 -- Checks that Nod meets the requirements for a constant address clause
9786 -- in the sense of the enclosing procedure.
9788 procedure Check_List_Constants
(Lst
: List_Id
);
9789 -- Check that all elements of list Lst meet the requirements for a
9790 -- constant address clause in the sense of the enclosing procedure.
9792 -------------------------------
9793 -- Check_At_Constant_Address --
9794 -------------------------------
9796 procedure Check_At_Constant_Address
(Nod
: Node_Id
) is
9798 if Is_Entity_Name
(Nod
) then
9799 if Present
(Address_Clause
(Entity
((Nod
)))) then
9801 ("invalid address clause for initialized object &!",
9804 ("address for& cannot" &
9805 " depend on another address clause! (RM 13.1(22))!",
9808 elsif In_Same_Source_Unit
(Entity
(Nod
), U_Ent
)
9809 and then Sloc
(U_Ent
) < Sloc
(Entity
(Nod
))
9812 ("invalid address clause for initialized object &!",
9814 Error_Msg_Node_2
:= U_Ent
;
9816 ("\& must be defined before & (RM 13.1(22))!",
9820 elsif Nkind
(Nod
) = N_Selected_Component
then
9822 T
: constant Entity_Id
:= Etype
(Prefix
(Nod
));
9825 if (Is_Record_Type
(T
)
9826 and then Has_Discriminants
(T
))
9829 and then Is_Record_Type
(Designated_Type
(T
))
9830 and then Has_Discriminants
(Designated_Type
(T
)))
9833 ("invalid address clause for initialized object &!",
9836 ("\address cannot depend on component" &
9837 " of discriminated record (RM 13.1(22))!",
9840 Check_At_Constant_Address
(Prefix
(Nod
));
9844 elsif Nkind
(Nod
) = N_Indexed_Component
then
9845 Check_At_Constant_Address
(Prefix
(Nod
));
9846 Check_List_Constants
(Expressions
(Nod
));
9849 Check_Expr_Constants
(Nod
);
9851 end Check_At_Constant_Address
;
9853 --------------------------
9854 -- Check_Expr_Constants --
9855 --------------------------
9857 procedure Check_Expr_Constants
(Nod
: Node_Id
) is
9858 Loc_U_Ent
: constant Source_Ptr
:= Sloc
(U_Ent
);
9859 Ent
: Entity_Id
:= Empty
;
9862 if Nkind
(Nod
) in N_Has_Etype
9863 and then Etype
(Nod
) = Any_Type
9869 when N_Empty | N_Error
=>
9872 when N_Identifier | N_Expanded_Name
=>
9873 Ent
:= Entity
(Nod
);
9875 -- We need to look at the original node if it is different
9876 -- from the node, since we may have rewritten things and
9877 -- substituted an identifier representing the rewrite.
9879 if Original_Node
(Nod
) /= Nod
then
9880 Check_Expr_Constants
(Original_Node
(Nod
));
9882 -- If the node is an object declaration without initial
9883 -- value, some code has been expanded, and the expression
9884 -- is not constant, even if the constituents might be
9885 -- acceptable, as in A'Address + offset.
9887 if Ekind
(Ent
) = E_Variable
9889 Nkind
(Declaration_Node
(Ent
)) = N_Object_Declaration
9891 No
(Expression
(Declaration_Node
(Ent
)))
9894 ("invalid address clause for initialized object &!",
9897 -- If entity is constant, it may be the result of expanding
9898 -- a check. We must verify that its declaration appears
9899 -- before the object in question, else we also reject the
9902 elsif Ekind
(Ent
) = E_Constant
9903 and then In_Same_Source_Unit
(Ent
, U_Ent
)
9904 and then Sloc
(Ent
) > Loc_U_Ent
9907 ("invalid address clause for initialized object &!",
9914 -- Otherwise look at the identifier and see if it is OK
9916 if Ekind_In
(Ent
, E_Named_Integer
, E_Named_Real
)
9917 or else Is_Type
(Ent
)
9921 elsif Ekind_In
(Ent
, E_Constant
, E_In_Parameter
) then
9923 -- This is the case where we must have Ent defined before
9924 -- U_Ent. Clearly if they are in different units this
9925 -- requirement is met since the unit containing Ent is
9926 -- already processed.
9928 if not In_Same_Source_Unit
(Ent
, U_Ent
) then
9931 -- Otherwise location of Ent must be before the location
9932 -- of U_Ent, that's what prior defined means.
9934 elsif Sloc
(Ent
) < Loc_U_Ent
then
9939 ("invalid address clause for initialized object &!",
9941 Error_Msg_Node_2
:= U_Ent
;
9943 ("\& must be defined before & (RM 13.1(22))!",
9947 elsif Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
9948 Check_Expr_Constants
(Original_Node
(Nod
));
9952 ("invalid address clause for initialized object &!",
9955 if Comes_From_Source
(Ent
) then
9957 ("\reference to variable& not allowed"
9958 & " (RM 13.1(22))!", Nod
, Ent
);
9961 ("non-static expression not allowed"
9962 & " (RM 13.1(22))!", Nod
);
9966 when N_Integer_Literal
=>
9968 -- If this is a rewritten unchecked conversion, in a system
9969 -- where Address is an integer type, always use the base type
9970 -- for a literal value. This is user-friendly and prevents
9971 -- order-of-elaboration issues with instances of unchecked
9974 if Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
9975 Set_Etype
(Nod
, Base_Type
(Etype
(Nod
)));
9978 when N_Real_Literal |
9980 N_Character_Literal
=>
9984 Check_Expr_Constants
(Low_Bound
(Nod
));
9985 Check_Expr_Constants
(High_Bound
(Nod
));
9987 when N_Explicit_Dereference
=>
9988 Check_Expr_Constants
(Prefix
(Nod
));
9990 when N_Indexed_Component
=>
9991 Check_Expr_Constants
(Prefix
(Nod
));
9992 Check_List_Constants
(Expressions
(Nod
));
9995 Check_Expr_Constants
(Prefix
(Nod
));
9996 Check_Expr_Constants
(Discrete_Range
(Nod
));
9998 when N_Selected_Component
=>
9999 Check_Expr_Constants
(Prefix
(Nod
));
10001 when N_Attribute_Reference
=>
10002 if Nam_In
(Attribute_Name
(Nod
), Name_Address
,
10004 Name_Unchecked_Access
,
10005 Name_Unrestricted_Access
)
10007 Check_At_Constant_Address
(Prefix
(Nod
));
10010 Check_Expr_Constants
(Prefix
(Nod
));
10011 Check_List_Constants
(Expressions
(Nod
));
10014 when N_Aggregate
=>
10015 Check_List_Constants
(Component_Associations
(Nod
));
10016 Check_List_Constants
(Expressions
(Nod
));
10018 when N_Component_Association
=>
10019 Check_Expr_Constants
(Expression
(Nod
));
10021 when N_Extension_Aggregate
=>
10022 Check_Expr_Constants
(Ancestor_Part
(Nod
));
10023 Check_List_Constants
(Component_Associations
(Nod
));
10024 Check_List_Constants
(Expressions
(Nod
));
10029 when N_Binary_Op | N_Short_Circuit | N_Membership_Test
=>
10030 Check_Expr_Constants
(Left_Opnd
(Nod
));
10031 Check_Expr_Constants
(Right_Opnd
(Nod
));
10034 Check_Expr_Constants
(Right_Opnd
(Nod
));
10036 when N_Type_Conversion |
10037 N_Qualified_Expression |
10039 N_Unchecked_Type_Conversion
=>
10040 Check_Expr_Constants
(Expression
(Nod
));
10042 when N_Function_Call
=>
10043 if not Is_Pure
(Entity
(Name
(Nod
))) then
10045 ("invalid address clause for initialized object &!",
10049 ("\function & is not pure (RM 13.1(22))!",
10050 Nod
, Entity
(Name
(Nod
)));
10053 Check_List_Constants
(Parameter_Associations
(Nod
));
10056 when N_Parameter_Association
=>
10057 Check_Expr_Constants
(Explicit_Actual_Parameter
(Nod
));
10061 ("invalid address clause for initialized object &!",
10064 ("\must be constant defined before& (RM 13.1(22))!",
10067 end Check_Expr_Constants
;
10069 --------------------------
10070 -- Check_List_Constants --
10071 --------------------------
10073 procedure Check_List_Constants
(Lst
: List_Id
) is
10077 if Present
(Lst
) then
10078 Nod1
:= First
(Lst
);
10079 while Present
(Nod1
) loop
10080 Check_Expr_Constants
(Nod1
);
10084 end Check_List_Constants
;
10086 -- Start of processing for Check_Constant_Address_Clause
10089 -- If rep_clauses are to be ignored, no need for legality checks. In
10090 -- particular, no need to pester user about rep clauses that violate the
10091 -- rule on constant addresses, given that these clauses will be removed
10092 -- by Freeze before they reach the back end. Similarly in CodePeer mode,
10093 -- we want to relax these checks.
10095 if not Ignore_Rep_Clauses
and not CodePeer_Mode
then
10096 Check_Expr_Constants
(Expr
);
10098 end Check_Constant_Address_Clause
;
10100 ---------------------------
10101 -- Check_Pool_Size_Clash --
10102 ---------------------------
10104 procedure Check_Pool_Size_Clash
(Ent
: Entity_Id
; SP
, SS
: Node_Id
) is
10108 -- We need to find out which one came first. Note that in the case of
10109 -- aspects mixed with pragmas there are cases where the processing order
10110 -- is reversed, which is why we do the check here.
10112 if Sloc
(SP
) < Sloc
(SS
) then
10113 Error_Msg_Sloc
:= Sloc
(SP
);
10115 Error_Msg_NE
("Storage_Pool previously given for&#", Post
, Ent
);
10118 Error_Msg_Sloc
:= Sloc
(SS
);
10120 Error_Msg_NE
("Storage_Size previously given for&#", Post
, Ent
);
10124 ("\cannot have Storage_Size and Storage_Pool (RM 13.11(3))", Post
);
10125 end Check_Pool_Size_Clash
;
10127 ----------------------------------------
10128 -- Check_Record_Representation_Clause --
10129 ----------------------------------------
10131 procedure Check_Record_Representation_Clause
(N
: Node_Id
) is
10132 Loc
: constant Source_Ptr
:= Sloc
(N
);
10133 Ident
: constant Node_Id
:= Identifier
(N
);
10134 Rectype
: Entity_Id
;
10139 Hbit
: Uint
:= Uint_0
;
10143 Max_Bit_So_Far
: Uint
;
10144 -- Records the maximum bit position so far. If all field positions
10145 -- are monotonically increasing, then we can skip the circuit for
10146 -- checking for overlap, since no overlap is possible.
10148 Tagged_Parent
: Entity_Id
:= Empty
;
10149 -- This is set in the case of a derived tagged type for which we have
10150 -- Is_Fully_Repped_Tagged_Type True (indicating that all components are
10151 -- positioned by record representation clauses). In this case we must
10152 -- check for overlap between components of this tagged type, and the
10153 -- components of its parent. Tagged_Parent will point to this parent
10154 -- type. For all other cases Tagged_Parent is left set to Empty.
10156 Parent_Last_Bit
: Uint
;
10157 -- Relevant only if Tagged_Parent is set, Parent_Last_Bit indicates the
10158 -- last bit position for any field in the parent type. We only need to
10159 -- check overlap for fields starting below this point.
10161 Overlap_Check_Required
: Boolean;
10162 -- Used to keep track of whether or not an overlap check is required
10164 Overlap_Detected
: Boolean := False;
10165 -- Set True if an overlap is detected
10167 Ccount
: Natural := 0;
10168 -- Number of component clauses in record rep clause
10170 procedure Check_Component_Overlap
(C1_Ent
, C2_Ent
: Entity_Id
);
10171 -- Given two entities for record components or discriminants, checks
10172 -- if they have overlapping component clauses and issues errors if so.
10174 procedure Find_Component
;
10175 -- Finds component entity corresponding to current component clause (in
10176 -- CC), and sets Comp to the entity, and Fbit/Lbit to the zero origin
10177 -- start/stop bits for the field. If there is no matching component or
10178 -- if the matching component does not have a component clause, then
10179 -- that's an error and Comp is set to Empty, but no error message is
10180 -- issued, since the message was already given. Comp is also set to
10181 -- Empty if the current "component clause" is in fact a pragma.
10183 -----------------------------
10184 -- Check_Component_Overlap --
10185 -----------------------------
10187 procedure Check_Component_Overlap
(C1_Ent
, C2_Ent
: Entity_Id
) is
10188 CC1
: constant Node_Id
:= Component_Clause
(C1_Ent
);
10189 CC2
: constant Node_Id
:= Component_Clause
(C2_Ent
);
10192 if Present
(CC1
) and then Present
(CC2
) then
10194 -- Exclude odd case where we have two tag components in the same
10195 -- record, both at location zero. This seems a bit strange, but
10196 -- it seems to happen in some circumstances, perhaps on an error.
10198 if Nam_In
(Chars
(C1_Ent
), Name_uTag
, Name_uTag
) then
10202 -- Here we check if the two fields overlap
10205 S1
: constant Uint
:= Component_Bit_Offset
(C1_Ent
);
10206 S2
: constant Uint
:= Component_Bit_Offset
(C2_Ent
);
10207 E1
: constant Uint
:= S1
+ Esize
(C1_Ent
);
10208 E2
: constant Uint
:= S2
+ Esize
(C2_Ent
);
10211 if E2
<= S1
or else E1
<= S2
then
10214 Error_Msg_Node_2
:= Component_Name
(CC2
);
10215 Error_Msg_Sloc
:= Sloc
(Error_Msg_Node_2
);
10216 Error_Msg_Node_1
:= Component_Name
(CC1
);
10218 ("component& overlaps & #", Component_Name
(CC1
));
10219 Overlap_Detected
:= True;
10223 end Check_Component_Overlap
;
10225 --------------------
10226 -- Find_Component --
10227 --------------------
10229 procedure Find_Component
is
10231 procedure Search_Component
(R
: Entity_Id
);
10232 -- Search components of R for a match. If found, Comp is set
10234 ----------------------
10235 -- Search_Component --
10236 ----------------------
10238 procedure Search_Component
(R
: Entity_Id
) is
10240 Comp
:= First_Component_Or_Discriminant
(R
);
10241 while Present
(Comp
) loop
10243 -- Ignore error of attribute name for component name (we
10244 -- already gave an error message for this, so no need to
10247 if Nkind
(Component_Name
(CC
)) = N_Attribute_Reference
then
10250 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
10253 Next_Component_Or_Discriminant
(Comp
);
10255 end Search_Component
;
10257 -- Start of processing for Find_Component
10260 -- Return with Comp set to Empty if we have a pragma
10262 if Nkind
(CC
) = N_Pragma
then
10267 -- Search current record for matching component
10269 Search_Component
(Rectype
);
10271 -- If not found, maybe component of base type discriminant that is
10272 -- absent from statically constrained first subtype.
10275 Search_Component
(Base_Type
(Rectype
));
10278 -- If no component, or the component does not reference the component
10279 -- clause in question, then there was some previous error for which
10280 -- we already gave a message, so just return with Comp Empty.
10282 if No
(Comp
) or else Component_Clause
(Comp
) /= CC
then
10283 Check_Error_Detected
;
10286 -- Normal case where we have a component clause
10289 Fbit
:= Component_Bit_Offset
(Comp
);
10290 Lbit
:= Fbit
+ Esize
(Comp
) - 1;
10292 end Find_Component
;
10294 -- Start of processing for Check_Record_Representation_Clause
10298 Rectype
:= Entity
(Ident
);
10300 if Rectype
= Any_Type
then
10303 Rectype
:= Underlying_Type
(Rectype
);
10306 -- See if we have a fully repped derived tagged type
10309 PS
: constant Entity_Id
:= Parent_Subtype
(Rectype
);
10312 if Present
(PS
) and then Is_Fully_Repped_Tagged_Type
(PS
) then
10313 Tagged_Parent
:= PS
;
10315 -- Find maximum bit of any component of the parent type
10317 Parent_Last_Bit
:= UI_From_Int
(System_Address_Size
- 1);
10318 Pcomp
:= First_Entity
(Tagged_Parent
);
10319 while Present
(Pcomp
) loop
10320 if Ekind_In
(Pcomp
, E_Discriminant
, E_Component
) then
10321 if Component_Bit_Offset
(Pcomp
) /= No_Uint
10322 and then Known_Static_Esize
(Pcomp
)
10327 Component_Bit_Offset
(Pcomp
) + Esize
(Pcomp
) - 1);
10331 -- Skip anonymous types generated for constrained array
10332 -- or record components.
10337 Next_Entity
(Pcomp
);
10342 -- All done if no component clauses
10344 CC
:= First
(Component_Clauses
(N
));
10350 -- If a tag is present, then create a component clause that places it
10351 -- at the start of the record (otherwise gigi may place it after other
10352 -- fields that have rep clauses).
10354 Fent
:= First_Entity
(Rectype
);
10356 if Nkind
(Fent
) = N_Defining_Identifier
10357 and then Chars
(Fent
) = Name_uTag
10359 Set_Component_Bit_Offset
(Fent
, Uint_0
);
10360 Set_Normalized_Position
(Fent
, Uint_0
);
10361 Set_Normalized_First_Bit
(Fent
, Uint_0
);
10362 Set_Normalized_Position_Max
(Fent
, Uint_0
);
10363 Init_Esize
(Fent
, System_Address_Size
);
10365 Set_Component_Clause
(Fent
,
10366 Make_Component_Clause
(Loc
,
10367 Component_Name
=> Make_Identifier
(Loc
, Name_uTag
),
10369 Position
=> Make_Integer_Literal
(Loc
, Uint_0
),
10370 First_Bit
=> Make_Integer_Literal
(Loc
, Uint_0
),
10372 Make_Integer_Literal
(Loc
,
10373 UI_From_Int
(System_Address_Size
))));
10375 Ccount
:= Ccount
+ 1;
10378 Max_Bit_So_Far
:= Uint_Minus_1
;
10379 Overlap_Check_Required
:= False;
10381 -- Process the component clauses
10383 while Present
(CC
) loop
10386 if Present
(Comp
) then
10387 Ccount
:= Ccount
+ 1;
10389 -- We need a full overlap check if record positions non-monotonic
10391 if Fbit
<= Max_Bit_So_Far
then
10392 Overlap_Check_Required
:= True;
10395 Max_Bit_So_Far
:= Lbit
;
10397 -- Check bit position out of range of specified size
10399 if Has_Size_Clause
(Rectype
)
10400 and then RM_Size
(Rectype
) <= Lbit
10403 ("bit number out of range of specified size",
10406 -- Check for overlap with tag component
10409 if Is_Tagged_Type
(Rectype
)
10410 and then Fbit
< System_Address_Size
10413 ("component overlaps tag field of&",
10414 Component_Name
(CC
), Rectype
);
10415 Overlap_Detected
:= True;
10418 if Hbit
< Lbit
then
10423 -- Check parent overlap if component might overlap parent field
10425 if Present
(Tagged_Parent
) and then Fbit
<= Parent_Last_Bit
then
10426 Pcomp
:= First_Component_Or_Discriminant
(Tagged_Parent
);
10427 while Present
(Pcomp
) loop
10428 if not Is_Tag
(Pcomp
)
10429 and then Chars
(Pcomp
) /= Name_uParent
10431 Check_Component_Overlap
(Comp
, Pcomp
);
10434 Next_Component_Or_Discriminant
(Pcomp
);
10442 -- Now that we have processed all the component clauses, check for
10443 -- overlap. We have to leave this till last, since the components can
10444 -- appear in any arbitrary order in the representation clause.
10446 -- We do not need this check if all specified ranges were monotonic,
10447 -- as recorded by Overlap_Check_Required being False at this stage.
10449 -- This first section checks if there are any overlapping entries at
10450 -- all. It does this by sorting all entries and then seeing if there are
10451 -- any overlaps. If there are none, then that is decisive, but if there
10452 -- are overlaps, they may still be OK (they may result from fields in
10453 -- different variants).
10455 if Overlap_Check_Required
then
10456 Overlap_Check1
: declare
10458 OC_Fbit
: array (0 .. Ccount
) of Uint
;
10459 -- First-bit values for component clauses, the value is the offset
10460 -- of the first bit of the field from start of record. The zero
10461 -- entry is for use in sorting.
10463 OC_Lbit
: array (0 .. Ccount
) of Uint
;
10464 -- Last-bit values for component clauses, the value is the offset
10465 -- of the last bit of the field from start of record. The zero
10466 -- entry is for use in sorting.
10468 OC_Count
: Natural := 0;
10469 -- Count of entries in OC_Fbit and OC_Lbit
10471 function OC_Lt
(Op1
, Op2
: Natural) return Boolean;
10472 -- Compare routine for Sort
10474 procedure OC_Move
(From
: Natural; To
: Natural);
10475 -- Move routine for Sort
10477 package Sorting
is new GNAT
.Heap_Sort_G
(OC_Move
, OC_Lt
);
10483 function OC_Lt
(Op1
, Op2
: Natural) return Boolean is
10485 return OC_Fbit
(Op1
) < OC_Fbit
(Op2
);
10492 procedure OC_Move
(From
: Natural; To
: Natural) is
10494 OC_Fbit
(To
) := OC_Fbit
(From
);
10495 OC_Lbit
(To
) := OC_Lbit
(From
);
10498 -- Start of processing for Overlap_Check
10501 CC
:= First
(Component_Clauses
(N
));
10502 while Present
(CC
) loop
10504 -- Exclude component clause already marked in error
10506 if not Error_Posted
(CC
) then
10509 if Present
(Comp
) then
10510 OC_Count
:= OC_Count
+ 1;
10511 OC_Fbit
(OC_Count
) := Fbit
;
10512 OC_Lbit
(OC_Count
) := Lbit
;
10519 Sorting
.Sort
(OC_Count
);
10521 Overlap_Check_Required
:= False;
10522 for J
in 1 .. OC_Count
- 1 loop
10523 if OC_Lbit
(J
) >= OC_Fbit
(J
+ 1) then
10524 Overlap_Check_Required
:= True;
10528 end Overlap_Check1
;
10531 -- If Overlap_Check_Required is still True, then we have to do the full
10532 -- scale overlap check, since we have at least two fields that do
10533 -- overlap, and we need to know if that is OK since they are in
10534 -- different variant, or whether we have a definite problem.
10536 if Overlap_Check_Required
then
10537 Overlap_Check2
: declare
10538 C1_Ent
, C2_Ent
: Entity_Id
;
10539 -- Entities of components being checked for overlap
10542 -- Component_List node whose Component_Items are being checked
10545 -- Component declaration for component being checked
10548 C1_Ent
:= First_Entity
(Base_Type
(Rectype
));
10550 -- Loop through all components in record. For each component check
10551 -- for overlap with any of the preceding elements on the component
10552 -- list containing the component and also, if the component is in
10553 -- a variant, check against components outside the case structure.
10554 -- This latter test is repeated recursively up the variant tree.
10556 Main_Component_Loop
: while Present
(C1_Ent
) loop
10557 if not Ekind_In
(C1_Ent
, E_Component
, E_Discriminant
) then
10558 goto Continue_Main_Component_Loop
;
10561 -- Skip overlap check if entity has no declaration node. This
10562 -- happens with discriminants in constrained derived types.
10563 -- Possibly we are missing some checks as a result, but that
10564 -- does not seem terribly serious.
10566 if No
(Declaration_Node
(C1_Ent
)) then
10567 goto Continue_Main_Component_Loop
;
10570 Clist
:= Parent
(List_Containing
(Declaration_Node
(C1_Ent
)));
10572 -- Loop through component lists that need checking. Check the
10573 -- current component list and all lists in variants above us.
10575 Component_List_Loop
: loop
10577 -- If derived type definition, go to full declaration
10578 -- If at outer level, check discriminants if there are any.
10580 if Nkind
(Clist
) = N_Derived_Type_Definition
then
10581 Clist
:= Parent
(Clist
);
10584 -- Outer level of record definition, check discriminants
10586 if Nkind_In
(Clist
, N_Full_Type_Declaration
,
10587 N_Private_Type_Declaration
)
10589 if Has_Discriminants
(Defining_Identifier
(Clist
)) then
10591 First_Discriminant
(Defining_Identifier
(Clist
));
10592 while Present
(C2_Ent
) loop
10593 exit when C1_Ent
= C2_Ent
;
10594 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
10595 Next_Discriminant
(C2_Ent
);
10599 -- Record extension case
10601 elsif Nkind
(Clist
) = N_Derived_Type_Definition
then
10604 -- Otherwise check one component list
10607 Citem
:= First
(Component_Items
(Clist
));
10608 while Present
(Citem
) loop
10609 if Nkind
(Citem
) = N_Component_Declaration
then
10610 C2_Ent
:= Defining_Identifier
(Citem
);
10611 exit when C1_Ent
= C2_Ent
;
10612 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
10619 -- Check for variants above us (the parent of the Clist can
10620 -- be a variant, in which case its parent is a variant part,
10621 -- and the parent of the variant part is a component list
10622 -- whose components must all be checked against the current
10623 -- component for overlap).
10625 if Nkind
(Parent
(Clist
)) = N_Variant
then
10626 Clist
:= Parent
(Parent
(Parent
(Clist
)));
10628 -- Check for possible discriminant part in record, this
10629 -- is treated essentially as another level in the
10630 -- recursion. For this case the parent of the component
10631 -- list is the record definition, and its parent is the
10632 -- full type declaration containing the discriminant
10635 elsif Nkind
(Parent
(Clist
)) = N_Record_Definition
then
10636 Clist
:= Parent
(Parent
((Clist
)));
10638 -- If neither of these two cases, we are at the top of
10642 exit Component_List_Loop
;
10644 end loop Component_List_Loop
;
10646 <<Continue_Main_Component_Loop
>>
10647 Next_Entity
(C1_Ent
);
10649 end loop Main_Component_Loop
;
10650 end Overlap_Check2
;
10653 -- The following circuit deals with warning on record holes (gaps). We
10654 -- skip this check if overlap was detected, since it makes sense for the
10655 -- programmer to fix this illegality before worrying about warnings.
10657 if not Overlap_Detected
and Warn_On_Record_Holes
then
10658 Record_Hole_Check
: declare
10659 Decl
: constant Node_Id
:= Declaration_Node
(Base_Type
(Rectype
));
10660 -- Full declaration of record type
10662 procedure Check_Component_List
10666 -- Check component list CL for holes. The starting bit should be
10667 -- Sbit. which is zero for the main record component list and set
10668 -- appropriately for recursive calls for variants. DS is set to
10669 -- a list of discriminant specifications to be included in the
10670 -- consideration of components. It is No_List if none to consider.
10672 --------------------------
10673 -- Check_Component_List --
10674 --------------------------
10676 procedure Check_Component_List
10684 Compl
:= Integer (List_Length
(Component_Items
(CL
)));
10686 if DS
/= No_List
then
10687 Compl
:= Compl
+ Integer (List_Length
(DS
));
10691 Comps
: array (Natural range 0 .. Compl
) of Entity_Id
;
10692 -- Gather components (zero entry is for sort routine)
10694 Ncomps
: Natural := 0;
10695 -- Number of entries stored in Comps (starting at Comps (1))
10698 -- One component item or discriminant specification
10701 -- Starting bit for next component
10704 -- Component entity
10709 function Lt
(Op1
, Op2
: Natural) return Boolean;
10710 -- Compare routine for Sort
10712 procedure Move
(From
: Natural; To
: Natural);
10713 -- Move routine for Sort
10715 package Sorting
is new GNAT
.Heap_Sort_G
(Move
, Lt
);
10721 function Lt
(Op1
, Op2
: Natural) return Boolean is
10723 return Component_Bit_Offset
(Comps
(Op1
))
10725 Component_Bit_Offset
(Comps
(Op2
));
10732 procedure Move
(From
: Natural; To
: Natural) is
10734 Comps
(To
) := Comps
(From
);
10738 -- Gather discriminants into Comp
10740 if DS
/= No_List
then
10741 Citem
:= First
(DS
);
10742 while Present
(Citem
) loop
10743 if Nkind
(Citem
) = N_Discriminant_Specification
then
10745 Ent
: constant Entity_Id
:=
10746 Defining_Identifier
(Citem
);
10748 if Ekind
(Ent
) = E_Discriminant
then
10749 Ncomps
:= Ncomps
+ 1;
10750 Comps
(Ncomps
) := Ent
;
10759 -- Gather component entities into Comp
10761 Citem
:= First
(Component_Items
(CL
));
10762 while Present
(Citem
) loop
10763 if Nkind
(Citem
) = N_Component_Declaration
then
10764 Ncomps
:= Ncomps
+ 1;
10765 Comps
(Ncomps
) := Defining_Identifier
(Citem
);
10771 -- Now sort the component entities based on the first bit.
10772 -- Note we already know there are no overlapping components.
10774 Sorting
.Sort
(Ncomps
);
10776 -- Loop through entries checking for holes
10779 for J
in 1 .. Ncomps
loop
10781 Error_Msg_Uint_1
:= Component_Bit_Offset
(CEnt
) - Nbit
;
10783 if Error_Msg_Uint_1
> 0 then
10785 ("?H?^-bit gap before component&",
10786 Component_Name
(Component_Clause
(CEnt
)), CEnt
);
10789 Nbit
:= Component_Bit_Offset
(CEnt
) + Esize
(CEnt
);
10792 -- Process variant parts recursively if present
10794 if Present
(Variant_Part
(CL
)) then
10795 Variant
:= First
(Variants
(Variant_Part
(CL
)));
10796 while Present
(Variant
) loop
10797 Check_Component_List
10798 (Component_List
(Variant
), Nbit
, No_List
);
10803 end Check_Component_List
;
10805 -- Start of processing for Record_Hole_Check
10812 if Is_Tagged_Type
(Rectype
) then
10813 Sbit
:= UI_From_Int
(System_Address_Size
);
10818 if Nkind
(Decl
) = N_Full_Type_Declaration
10819 and then Nkind
(Type_Definition
(Decl
)) = N_Record_Definition
10821 Check_Component_List
10822 (Component_List
(Type_Definition
(Decl
)),
10824 Discriminant_Specifications
(Decl
));
10827 end Record_Hole_Check
;
10830 -- For records that have component clauses for all components, and whose
10831 -- size is less than or equal to 32, we need to know the size in the
10832 -- front end to activate possible packed array processing where the
10833 -- component type is a record.
10835 -- At this stage Hbit + 1 represents the first unused bit from all the
10836 -- component clauses processed, so if the component clauses are
10837 -- complete, then this is the length of the record.
10839 -- For records longer than System.Storage_Unit, and for those where not
10840 -- all components have component clauses, the back end determines the
10841 -- length (it may for example be appropriate to round up the size
10842 -- to some convenient boundary, based on alignment considerations, etc).
10844 if Unknown_RM_Size
(Rectype
) and then Hbit
+ 1 <= 32 then
10846 -- Nothing to do if at least one component has no component clause
10848 Comp
:= First_Component_Or_Discriminant
(Rectype
);
10849 while Present
(Comp
) loop
10850 exit when No
(Component_Clause
(Comp
));
10851 Next_Component_Or_Discriminant
(Comp
);
10854 -- If we fall out of loop, all components have component clauses
10855 -- and so we can set the size to the maximum value.
10858 Set_RM_Size
(Rectype
, Hbit
+ 1);
10861 end Check_Record_Representation_Clause
;
10867 procedure Check_Size
10871 Biased
: out Boolean)
10873 UT
: constant Entity_Id
:= Underlying_Type
(T
);
10879 -- Reject patently improper size values.
10881 if Is_Elementary_Type
(T
)
10882 and then Siz
> UI_From_Int
(Int
'Last)
10884 Error_Msg_N
("Size value too large for elementary type", N
);
10886 if Nkind
(Original_Node
(N
)) = N_Op_Expon
then
10888 ("\maybe '* was meant, rather than '*'*", Original_Node
(N
));
10892 -- Dismiss generic types
10894 if Is_Generic_Type
(T
)
10896 Is_Generic_Type
(UT
)
10898 Is_Generic_Type
(Root_Type
(UT
))
10902 -- Guard against previous errors
10904 elsif No
(UT
) or else UT
= Any_Type
then
10905 Check_Error_Detected
;
10908 -- Check case of bit packed array
10910 elsif Is_Array_Type
(UT
)
10911 and then Known_Static_Component_Size
(UT
)
10912 and then Is_Bit_Packed_Array
(UT
)
10920 Asiz
:= Component_Size
(UT
);
10921 Indx
:= First_Index
(UT
);
10923 Ityp
:= Etype
(Indx
);
10925 -- If non-static bound, then we are not in the business of
10926 -- trying to check the length, and indeed an error will be
10927 -- issued elsewhere, since sizes of non-static array types
10928 -- cannot be set implicitly or explicitly.
10930 if not Is_OK_Static_Subtype
(Ityp
) then
10934 -- Otherwise accumulate next dimension
10936 Asiz
:= Asiz
* (Expr_Value
(Type_High_Bound
(Ityp
)) -
10937 Expr_Value
(Type_Low_Bound
(Ityp
)) +
10941 exit when No
(Indx
);
10944 if Asiz
<= Siz
then
10948 Error_Msg_Uint_1
:= Asiz
;
10950 ("size for& too small, minimum allowed is ^", N
, T
);
10951 Set_Esize
(T
, Asiz
);
10952 Set_RM_Size
(T
, Asiz
);
10956 -- All other composite types are ignored
10958 elsif Is_Composite_Type
(UT
) then
10961 -- For fixed-point types, don't check minimum if type is not frozen,
10962 -- since we don't know all the characteristics of the type that can
10963 -- affect the size (e.g. a specified small) till freeze time.
10965 elsif Is_Fixed_Point_Type
(UT
)
10966 and then not Is_Frozen
(UT
)
10970 -- Cases for which a minimum check is required
10973 -- Ignore if specified size is correct for the type
10975 if Known_Esize
(UT
) and then Siz
= Esize
(UT
) then
10979 -- Otherwise get minimum size
10981 M
:= UI_From_Int
(Minimum_Size
(UT
));
10985 -- Size is less than minimum size, but one possibility remains
10986 -- that we can manage with the new size if we bias the type.
10988 M
:= UI_From_Int
(Minimum_Size
(UT
, Biased
=> True));
10991 Error_Msg_Uint_1
:= M
;
10993 ("size for& too small, minimum allowed is ^", N
, T
);
10995 Set_RM_Size
(T
, M
);
11003 --------------------------
11004 -- Freeze_Entity_Checks --
11005 --------------------------
11007 procedure Freeze_Entity_Checks
(N
: Node_Id
) is
11008 procedure Hide_Non_Overridden_Subprograms
(Typ
: Entity_Id
);
11009 -- Inspect the primitive operations of type Typ and hide all pairs of
11010 -- implicitly declared non-overridden non-fully conformant homographs
11011 -- (Ada RM 8.3 12.3/2).
11013 -------------------------------------
11014 -- Hide_Non_Overridden_Subprograms --
11015 -------------------------------------
11017 procedure Hide_Non_Overridden_Subprograms
(Typ
: Entity_Id
) is
11018 procedure Hide_Matching_Homographs
11019 (Subp_Id
: Entity_Id
;
11020 Start_Elmt
: Elmt_Id
);
11021 -- Inspect a list of primitive operations starting with Start_Elmt
11022 -- and find matching implicitly declared non-overridden non-fully
11023 -- conformant homographs of Subp_Id. If found, all matches along
11024 -- with Subp_Id are hidden from all visibility.
11026 function Is_Non_Overridden_Or_Null_Procedure
11027 (Subp_Id
: Entity_Id
) return Boolean;
11028 -- Determine whether subprogram Subp_Id is implicitly declared non-
11029 -- overridden subprogram or an implicitly declared null procedure.
11031 ------------------------------
11032 -- Hide_Matching_Homographs --
11033 ------------------------------
11035 procedure Hide_Matching_Homographs
11036 (Subp_Id
: Entity_Id
;
11037 Start_Elmt
: Elmt_Id
)
11040 Prim_Elmt
: Elmt_Id
;
11043 Prim_Elmt
:= Start_Elmt
;
11044 while Present
(Prim_Elmt
) loop
11045 Prim
:= Node
(Prim_Elmt
);
11047 -- The current primitive is implicitly declared non-overridden
11048 -- non-fully conformant homograph of Subp_Id. Both subprograms
11049 -- must be hidden from visibility.
11051 if Chars
(Prim
) = Chars
(Subp_Id
)
11052 and then Is_Non_Overridden_Or_Null_Procedure
(Prim
)
11053 and then not Fully_Conformant
(Prim
, Subp_Id
)
11055 Set_Is_Hidden_Non_Overridden_Subpgm
(Prim
);
11056 Set_Is_Immediately_Visible
(Prim
, False);
11057 Set_Is_Potentially_Use_Visible
(Prim
, False);
11059 Set_Is_Hidden_Non_Overridden_Subpgm
(Subp_Id
);
11060 Set_Is_Immediately_Visible
(Subp_Id
, False);
11061 Set_Is_Potentially_Use_Visible
(Subp_Id
, False);
11064 Next_Elmt
(Prim_Elmt
);
11066 end Hide_Matching_Homographs
;
11068 -----------------------------------------
11069 -- Is_Non_Overridden_Or_Null_Procedure --
11070 -----------------------------------------
11072 function Is_Non_Overridden_Or_Null_Procedure
11073 (Subp_Id
: Entity_Id
) return Boolean
11075 Alias_Id
: Entity_Id
;
11078 -- The subprogram is inherited (implicitly declared), it does not
11079 -- override and does not cover a primitive of an interface.
11081 if Ekind_In
(Subp_Id
, E_Function
, E_Procedure
)
11082 and then Present
(Alias
(Subp_Id
))
11083 and then No
(Interface_Alias
(Subp_Id
))
11084 and then No
(Overridden_Operation
(Subp_Id
))
11086 Alias_Id
:= Alias
(Subp_Id
);
11088 if Requires_Overriding
(Alias_Id
) then
11091 elsif Nkind
(Parent
(Alias_Id
)) = N_Procedure_Specification
11092 and then Null_Present
(Parent
(Alias_Id
))
11099 end Is_Non_Overridden_Or_Null_Procedure
;
11103 Prim_Ops
: constant Elist_Id
:= Direct_Primitive_Operations
(Typ
);
11105 Prim_Elmt
: Elmt_Id
;
11107 -- Start of processing for Hide_Non_Overridden_Subprograms
11110 -- Inspect the list of primitives looking for non-overridden
11113 if Present
(Prim_Ops
) then
11114 Prim_Elmt
:= First_Elmt
(Prim_Ops
);
11115 while Present
(Prim_Elmt
) loop
11116 Prim
:= Node
(Prim_Elmt
);
11117 Next_Elmt
(Prim_Elmt
);
11119 if Is_Non_Overridden_Or_Null_Procedure
(Prim
) then
11120 Hide_Matching_Homographs
11122 Start_Elmt
=> Prim_Elmt
);
11126 end Hide_Non_Overridden_Subprograms
;
11128 ---------------------
11129 -- Local variables --
11130 ---------------------
11132 E
: constant Entity_Id
:= Entity
(N
);
11134 Non_Generic_Case
: constant Boolean := Nkind
(N
) = N_Freeze_Entity
;
11135 -- True in non-generic case. Some of the processing here is skipped
11136 -- for the generic case since it is not needed. Basically in the
11137 -- generic case, we only need to do stuff that might generate error
11138 -- messages or warnings.
11140 -- Start of processing for Freeze_Entity_Checks
11143 -- Remember that we are processing a freezing entity. Required to
11144 -- ensure correct decoration of internal entities associated with
11145 -- interfaces (see New_Overloaded_Entity).
11147 Inside_Freezing_Actions
:= Inside_Freezing_Actions
+ 1;
11149 -- For tagged types covering interfaces add internal entities that link
11150 -- the primitives of the interfaces with the primitives that cover them.
11151 -- Note: These entities were originally generated only when generating
11152 -- code because their main purpose was to provide support to initialize
11153 -- the secondary dispatch tables. They are now generated also when
11154 -- compiling with no code generation to provide ASIS the relationship
11155 -- between interface primitives and tagged type primitives. They are
11156 -- also used to locate primitives covering interfaces when processing
11157 -- generics (see Derive_Subprograms).
11159 -- This is not needed in the generic case
11161 if Ada_Version
>= Ada_2005
11162 and then Non_Generic_Case
11163 and then Ekind
(E
) = E_Record_Type
11164 and then Is_Tagged_Type
(E
)
11165 and then not Is_Interface
(E
)
11166 and then Has_Interfaces
(E
)
11168 -- This would be a good common place to call the routine that checks
11169 -- overriding of interface primitives (and thus factorize calls to
11170 -- Check_Abstract_Overriding located at different contexts in the
11171 -- compiler). However, this is not possible because it causes
11172 -- spurious errors in case of late overriding.
11174 Add_Internal_Interface_Entities
(E
);
11177 -- After all forms of overriding have been resolved, a tagged type may
11178 -- be left with a set of implicitly declared and possibly erroneous
11179 -- abstract subprograms, null procedures and subprograms that require
11180 -- overriding. If this set contains fully conformant homographs, then
11181 -- one is chosen arbitrarily (already done during resolution), otherwise
11182 -- all remaining non-fully conformant homographs are hidden from
11183 -- visibility (Ada RM 8.3 12.3/2).
11185 if Is_Tagged_Type
(E
) then
11186 Hide_Non_Overridden_Subprograms
(E
);
11191 if Ekind
(E
) = E_Record_Type
11192 and then Is_CPP_Class
(E
)
11193 and then Is_Tagged_Type
(E
)
11194 and then Tagged_Type_Expansion
11196 if CPP_Num_Prims
(E
) = 0 then
11198 -- If the CPP type has user defined components then it must import
11199 -- primitives from C++. This is required because if the C++ class
11200 -- has no primitives then the C++ compiler does not added the _tag
11201 -- component to the type.
11203 if First_Entity
(E
) /= Last_Entity
(E
) then
11205 ("'C'P'P type must import at least one primitive from C++??",
11210 -- Check that all its primitives are abstract or imported from C++.
11211 -- Check also availability of the C++ constructor.
11214 Has_Constructors
: constant Boolean := Has_CPP_Constructors
(E
);
11216 Error_Reported
: Boolean := False;
11220 Elmt
:= First_Elmt
(Primitive_Operations
(E
));
11221 while Present
(Elmt
) loop
11222 Prim
:= Node
(Elmt
);
11224 if Comes_From_Source
(Prim
) then
11225 if Is_Abstract_Subprogram
(Prim
) then
11228 elsif not Is_Imported
(Prim
)
11229 or else Convention
(Prim
) /= Convention_CPP
11232 ("primitives of 'C'P'P types must be imported from C++ "
11233 & "or abstract??", Prim
);
11235 elsif not Has_Constructors
11236 and then not Error_Reported
11238 Error_Msg_Name_1
:= Chars
(E
);
11240 ("??'C'P'P constructor required for type %", Prim
);
11241 Error_Reported
:= True;
11250 -- Check Ada derivation of CPP type
11252 if Expander_Active
-- why? losing errors in -gnatc mode???
11253 and then Present
(Etype
(E
)) -- defend against errors
11254 and then Tagged_Type_Expansion
11255 and then Ekind
(E
) = E_Record_Type
11256 and then Etype
(E
) /= E
11257 and then Is_CPP_Class
(Etype
(E
))
11258 and then CPP_Num_Prims
(Etype
(E
)) > 0
11259 and then not Is_CPP_Class
(E
)
11260 and then not Has_CPP_Constructors
(Etype
(E
))
11262 -- If the parent has C++ primitives but it has no constructor then
11263 -- check that all the primitives are overridden in this derivation;
11264 -- otherwise the constructor of the parent is needed to build the
11272 Elmt
:= First_Elmt
(Primitive_Operations
(E
));
11273 while Present
(Elmt
) loop
11274 Prim
:= Node
(Elmt
);
11276 if not Is_Abstract_Subprogram
(Prim
)
11277 and then No
(Interface_Alias
(Prim
))
11278 and then Find_Dispatching_Type
(Ultimate_Alias
(Prim
)) /= E
11280 Error_Msg_Name_1
:= Chars
(Etype
(E
));
11282 ("'C'P'P constructor required for parent type %", E
);
11291 Inside_Freezing_Actions
:= Inside_Freezing_Actions
- 1;
11293 -- If we have a type with predicates, build predicate function. This
11294 -- is not needed in the generic case, and is not needed within TSS
11295 -- subprograms and other predefined primitives.
11297 if Non_Generic_Case
11298 and then Is_Type
(E
)
11299 and then Has_Predicates
(E
)
11300 and then not Within_Internal_Subprogram
11302 Build_Predicate_Functions
(E
, N
);
11305 -- If type has delayed aspects, this is where we do the preanalysis at
11306 -- the freeze point, as part of the consistent visibility check. Note
11307 -- that this must be done after calling Build_Predicate_Functions or
11308 -- Build_Invariant_Procedure since these subprograms fix occurrences of
11309 -- the subtype name in the saved expression so that they will not cause
11310 -- trouble in the preanalysis.
11312 -- This is also not needed in the generic case
11314 if Non_Generic_Case
11315 and then Has_Delayed_Aspects
(E
)
11316 and then Scope
(E
) = Current_Scope
11318 -- Retrieve the visibility to the discriminants in order to properly
11319 -- analyze the aspects.
11321 Push_Scope_And_Install_Discriminants
(E
);
11327 -- Look for aspect specification entries for this entity
11329 Ritem
:= First_Rep_Item
(E
);
11330 while Present
(Ritem
) loop
11331 if Nkind
(Ritem
) = N_Aspect_Specification
11332 and then Entity
(Ritem
) = E
11333 and then Is_Delayed_Aspect
(Ritem
)
11335 Check_Aspect_At_Freeze_Point
(Ritem
);
11338 Next_Rep_Item
(Ritem
);
11342 Uninstall_Discriminants_And_Pop_Scope
(E
);
11345 -- For a record type, deal with variant parts. This has to be delayed
11346 -- to this point, because of the issue of statically predicated
11347 -- subtypes, which we have to ensure are frozen before checking
11348 -- choices, since we need to have the static choice list set.
11350 if Is_Record_Type
(E
) then
11351 Check_Variant_Part
: declare
11352 D
: constant Node_Id
:= Declaration_Node
(E
);
11357 Others_Present
: Boolean;
11358 pragma Warnings
(Off
, Others_Present
);
11359 -- Indicates others present, not used in this case
11361 procedure Non_Static_Choice_Error
(Choice
: Node_Id
);
11362 -- Error routine invoked by the generic instantiation below when
11363 -- the variant part has a non static choice.
11365 procedure Process_Declarations
(Variant
: Node_Id
);
11366 -- Processes declarations associated with a variant. We analyzed
11367 -- the declarations earlier (in Sem_Ch3.Analyze_Variant_Part),
11368 -- but we still need the recursive call to Check_Choices for any
11369 -- nested variant to get its choices properly processed. This is
11370 -- also where we expand out the choices if expansion is active.
11372 package Variant_Choices_Processing
is new
11373 Generic_Check_Choices
11374 (Process_Empty_Choice
=> No_OP
,
11375 Process_Non_Static_Choice
=> Non_Static_Choice_Error
,
11376 Process_Associated_Node
=> Process_Declarations
);
11377 use Variant_Choices_Processing
;
11379 -----------------------------
11380 -- Non_Static_Choice_Error --
11381 -----------------------------
11383 procedure Non_Static_Choice_Error
(Choice
: Node_Id
) is
11385 Flag_Non_Static_Expr
11386 ("choice given in variant part is not static!", Choice
);
11387 end Non_Static_Choice_Error
;
11389 --------------------------
11390 -- Process_Declarations --
11391 --------------------------
11393 procedure Process_Declarations
(Variant
: Node_Id
) is
11394 CL
: constant Node_Id
:= Component_List
(Variant
);
11398 -- Check for static predicate present in this variant
11400 if Has_SP_Choice
(Variant
) then
11402 -- Here we expand. You might expect to find this call in
11403 -- Expand_N_Variant_Part, but that is called when we first
11404 -- see the variant part, and we cannot do this expansion
11405 -- earlier than the freeze point, since for statically
11406 -- predicated subtypes, the predicate is not known till
11407 -- the freeze point.
11409 -- Furthermore, we do this expansion even if the expander
11410 -- is not active, because other semantic processing, e.g.
11411 -- for aggregates, requires the expanded list of choices.
11413 -- If the expander is not active, then we can't just clobber
11414 -- the list since it would invalidate the ASIS -gnatct tree.
11415 -- So we have to rewrite the variant part with a Rewrite
11416 -- call that replaces it with a copy and clobber the copy.
11418 if not Expander_Active
then
11420 NewV
: constant Node_Id
:= New_Copy
(Variant
);
11422 Set_Discrete_Choices
11423 (NewV
, New_Copy_List
(Discrete_Choices
(Variant
)));
11424 Rewrite
(Variant
, NewV
);
11428 Expand_Static_Predicates_In_Choices
(Variant
);
11431 -- We don't need to worry about the declarations in the variant
11432 -- (since they were analyzed by Analyze_Choices when we first
11433 -- encountered the variant), but we do need to take care of
11434 -- expansion of any nested variants.
11436 if not Null_Present
(CL
) then
11437 VP
:= Variant_Part
(CL
);
11439 if Present
(VP
) then
11441 (VP
, Variants
(VP
), Etype
(Name
(VP
)), Others_Present
);
11444 end Process_Declarations
;
11446 -- Start of processing for Check_Variant_Part
11449 -- Find component list
11453 if Nkind
(D
) = N_Full_Type_Declaration
then
11454 T
:= Type_Definition
(D
);
11456 if Nkind
(T
) = N_Record_Definition
then
11457 C
:= Component_List
(T
);
11459 elsif Nkind
(T
) = N_Derived_Type_Definition
11460 and then Present
(Record_Extension_Part
(T
))
11462 C
:= Component_List
(Record_Extension_Part
(T
));
11466 -- Case of variant part present
11468 if Present
(C
) and then Present
(Variant_Part
(C
)) then
11469 VP
:= Variant_Part
(C
);
11474 (VP
, Variants
(VP
), Etype
(Name
(VP
)), Others_Present
);
11476 -- If the last variant does not contain the Others choice,
11477 -- replace it with an N_Others_Choice node since Gigi always
11478 -- wants an Others. Note that we do not bother to call Analyze
11479 -- on the modified variant part, since its only effect would be
11480 -- to compute the Others_Discrete_Choices node laboriously, and
11481 -- of course we already know the list of choices corresponding
11482 -- to the others choice (it's the list we're replacing).
11484 -- We only want to do this if the expander is active, since
11485 -- we do not want to clobber the ASIS tree.
11487 if Expander_Active
then
11489 Last_Var
: constant Node_Id
:=
11490 Last_Non_Pragma
(Variants
(VP
));
11492 Others_Node
: Node_Id
;
11495 if Nkind
(First
(Discrete_Choices
(Last_Var
))) /=
11498 Others_Node
:= Make_Others_Choice
(Sloc
(Last_Var
));
11499 Set_Others_Discrete_Choices
11500 (Others_Node
, Discrete_Choices
(Last_Var
));
11501 Set_Discrete_Choices
11502 (Last_Var
, New_List
(Others_Node
));
11507 end Check_Variant_Part
;
11509 end Freeze_Entity_Checks
;
11511 -------------------------
11512 -- Get_Alignment_Value --
11513 -------------------------
11515 function Get_Alignment_Value
(Expr
: Node_Id
) return Uint
is
11516 Align
: constant Uint
:= Static_Integer
(Expr
);
11519 if Align
= No_Uint
then
11522 elsif Align
<= 0 then
11523 Error_Msg_N
("alignment value must be positive", Expr
);
11527 for J
in Int
range 0 .. 64 loop
11529 M
: constant Uint
:= Uint_2
** J
;
11532 exit when M
= Align
;
11536 ("alignment value must be power of 2", Expr
);
11544 end Get_Alignment_Value
;
11546 -----------------------------
11547 -- Get_Interfacing_Aspects --
11548 -----------------------------
11550 procedure Get_Interfacing_Aspects
11551 (Iface_Asp
: Node_Id
;
11552 Conv_Asp
: out Node_Id
;
11553 EN_Asp
: out Node_Id
;
11554 Expo_Asp
: out Node_Id
;
11555 Imp_Asp
: out Node_Id
;
11556 LN_Asp
: out Node_Id
;
11557 Do_Checks
: Boolean := False)
11559 procedure Save_Or_Duplication_Error
11561 To
: in out Node_Id
);
11562 -- Save the value of aspect Asp in node To. If To already has a value,
11563 -- then this is considered a duplicate use of aspect. Emit an error if
11564 -- flag Do_Checks is set.
11566 -------------------------------
11567 -- Save_Or_Duplication_Error --
11568 -------------------------------
11570 procedure Save_Or_Duplication_Error
11572 To
: in out Node_Id
)
11575 -- Detect an extra aspect and issue an error
11577 if Present
(To
) then
11579 Error_Msg_Name_1
:= Chars
(Identifier
(Asp
));
11580 Error_Msg_Sloc
:= Sloc
(To
);
11581 Error_Msg_N
("aspect % previously given #", Asp
);
11584 -- Otherwise capture the aspect
11589 end Save_Or_Duplication_Error
;
11594 Asp_Id
: Aspect_Id
;
11596 -- The following variables capture each individual aspect
11598 Conv
: Node_Id
:= Empty
;
11599 EN
: Node_Id
:= Empty
;
11600 Expo
: Node_Id
:= Empty
;
11601 Imp
: Node_Id
:= Empty
;
11602 LN
: Node_Id
:= Empty
;
11604 -- Start of processing for Get_Interfacing_Aspects
11607 -- The input interfacing aspect should reside in an aspect specification
11610 pragma Assert
(Is_List_Member
(Iface_Asp
));
11612 -- Examine the aspect specifications of the related entity. Find and
11613 -- capture all interfacing aspects. Detect duplicates and emit errors
11616 Asp
:= First
(List_Containing
(Iface_Asp
));
11617 while Present
(Asp
) loop
11618 Asp_Id
:= Get_Aspect_Id
(Asp
);
11620 if Asp_Id
= Aspect_Convention
then
11621 Save_Or_Duplication_Error
(Asp
, Conv
);
11623 elsif Asp_Id
= Aspect_External_Name
then
11624 Save_Or_Duplication_Error
(Asp
, EN
);
11626 elsif Asp_Id
= Aspect_Export
then
11627 Save_Or_Duplication_Error
(Asp
, Expo
);
11629 elsif Asp_Id
= Aspect_Import
then
11630 Save_Or_Duplication_Error
(Asp
, Imp
);
11632 elsif Asp_Id
= Aspect_Link_Name
then
11633 Save_Or_Duplication_Error
(Asp
, LN
);
11644 end Get_Interfacing_Aspects
;
11646 -------------------------------------
11647 -- Inherit_Aspects_At_Freeze_Point --
11648 -------------------------------------
11650 procedure Inherit_Aspects_At_Freeze_Point
(Typ
: Entity_Id
) is
11651 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11652 (Rep_Item
: Node_Id
) return Boolean;
11653 -- This routine checks if Rep_Item is either a pragma or an aspect
11654 -- specification node whose correponding pragma (if any) is present in
11655 -- the Rep Item chain of the entity it has been specified to.
11657 --------------------------------------------------
11658 -- Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item --
11659 --------------------------------------------------
11661 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11662 (Rep_Item
: Node_Id
) return Boolean
11666 Nkind
(Rep_Item
) = N_Pragma
11667 or else Present_In_Rep_Item
11668 (Entity
(Rep_Item
), Aspect_Rep_Item
(Rep_Item
));
11669 end Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
;
11671 -- Start of processing for Inherit_Aspects_At_Freeze_Point
11674 -- A representation item is either subtype-specific (Size and Alignment
11675 -- clauses) or type-related (all others). Subtype-specific aspects may
11676 -- differ for different subtypes of the same type (RM 13.1.8).
11678 -- A derived type inherits each type-related representation aspect of
11679 -- its parent type that was directly specified before the declaration of
11680 -- the derived type (RM 13.1.15).
11682 -- A derived subtype inherits each subtype-specific representation
11683 -- aspect of its parent subtype that was directly specified before the
11684 -- declaration of the derived type (RM 13.1.15).
11686 -- The general processing involves inheriting a representation aspect
11687 -- from a parent type whenever the first rep item (aspect specification,
11688 -- attribute definition clause, pragma) corresponding to the given
11689 -- representation aspect in the rep item chain of Typ, if any, isn't
11690 -- directly specified to Typ but to one of its parents.
11692 -- ??? Note that, for now, just a limited number of representation
11693 -- aspects have been inherited here so far. Many of them are
11694 -- still inherited in Sem_Ch3. This will be fixed soon. Here is
11695 -- a non- exhaustive list of aspects that likely also need to
11696 -- be moved to this routine: Alignment, Component_Alignment,
11697 -- Component_Size, Machine_Radix, Object_Size, Pack, Predicates,
11698 -- Preelaborable_Initialization, RM_Size and Small.
11700 -- In addition, Convention must be propagated from base type to subtype,
11701 -- because the subtype may have been declared on an incomplete view.
11703 if Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
then
11709 if not Has_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
, False)
11710 and then Has_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
)
11711 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11712 (Get_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
))
11714 Set_Is_Ada_2005_Only
(Typ
);
11719 if not Has_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
, False)
11720 and then Has_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
)
11721 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11722 (Get_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
))
11724 Set_Is_Ada_2012_Only
(Typ
);
11729 if not Has_Rep_Item
(Typ
, Name_Atomic
, Name_Shared
, False)
11730 and then Has_Rep_Pragma
(Typ
, Name_Atomic
, Name_Shared
)
11731 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11732 (Get_Rep_Item
(Typ
, Name_Atomic
, Name_Shared
))
11734 Set_Is_Atomic
(Typ
);
11735 Set_Is_Volatile
(Typ
);
11736 Set_Treat_As_Volatile
(Typ
);
11741 if Is_Record_Type
(Typ
)
11742 and then Typ
/= Base_Type
(Typ
) and then Is_Frozen
(Base_Type
(Typ
))
11744 Set_Convention
(Typ
, Convention
(Base_Type
(Typ
)));
11747 -- Default_Component_Value
11749 -- Verify that there is no rep_item declared for the type, and there
11750 -- is one coming from an ancestor.
11752 if Is_Array_Type
(Typ
)
11753 and then Is_Base_Type
(Typ
)
11754 and then not Has_Rep_Item
(Typ
, Name_Default_Component_Value
, False)
11755 and then Has_Rep_Item
(Typ
, Name_Default_Component_Value
)
11757 Set_Default_Aspect_Component_Value
(Typ
,
11758 Default_Aspect_Component_Value
11759 (Entity
(Get_Rep_Item
(Typ
, Name_Default_Component_Value
))));
11764 if Is_Scalar_Type
(Typ
)
11765 and then Is_Base_Type
(Typ
)
11766 and then not Has_Rep_Item
(Typ
, Name_Default_Value
, False)
11767 and then Has_Rep_Item
(Typ
, Name_Default_Value
)
11769 Set_Has_Default_Aspect
(Typ
);
11770 Set_Default_Aspect_Value
(Typ
,
11771 Default_Aspect_Value
11772 (Entity
(Get_Rep_Item
(Typ
, Name_Default_Value
))));
11777 if not Has_Rep_Item
(Typ
, Name_Discard_Names
, False)
11778 and then Has_Rep_Item
(Typ
, Name_Discard_Names
)
11779 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11780 (Get_Rep_Item
(Typ
, Name_Discard_Names
))
11782 Set_Discard_Names
(Typ
);
11787 if not Has_Rep_Item
(Typ
, Name_Invariant
, False)
11788 and then Has_Rep_Item
(Typ
, Name_Invariant
)
11789 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11790 (Get_Rep_Item
(Typ
, Name_Invariant
))
11792 Set_Has_Invariants
(Typ
);
11794 if Class_Present
(Get_Rep_Item
(Typ
, Name_Invariant
)) then
11795 Set_Has_Inheritable_Invariants
(Typ
);
11798 -- If we have a subtype with invariants, whose base type does not have
11799 -- invariants, copy these invariants to the base type. This happens for
11800 -- the case of implicit base types created for scalar and array types.
11802 elsif Has_Invariants
(Typ
)
11803 and then not Has_Invariants
(Base_Type
(Typ
))
11805 Set_Has_Invariants
(Base_Type
(Typ
));
11806 Set_Invariant_Procedure
(Base_Type
(Typ
), Invariant_Procedure
(Typ
));
11811 if not Has_Rep_Item
(Typ
, Name_Volatile
, False)
11812 and then Has_Rep_Item
(Typ
, Name_Volatile
)
11813 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11814 (Get_Rep_Item
(Typ
, Name_Volatile
))
11816 Set_Is_Volatile
(Typ
);
11817 Set_Treat_As_Volatile
(Typ
);
11820 -- Volatile_Full_Access
11822 if not Has_Rep_Item
(Typ
, Name_Volatile_Full_Access
, False)
11823 and then Has_Rep_Pragma
(Typ
, Name_Volatile_Full_Access
)
11824 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11825 (Get_Rep_Item
(Typ
, Name_Volatile_Full_Access
))
11827 Set_Is_Volatile_Full_Access
(Typ
);
11828 Set_Is_Volatile
(Typ
);
11829 Set_Treat_As_Volatile
(Typ
);
11832 -- Inheritance for derived types only
11834 if Is_Derived_Type
(Typ
) then
11836 Bas_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
11837 Imp_Bas_Typ
: constant Entity_Id
:= Implementation_Base_Type
(Typ
);
11840 -- Atomic_Components
11842 if not Has_Rep_Item
(Typ
, Name_Atomic_Components
, False)
11843 and then Has_Rep_Item
(Typ
, Name_Atomic_Components
)
11844 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11845 (Get_Rep_Item
(Typ
, Name_Atomic_Components
))
11847 Set_Has_Atomic_Components
(Imp_Bas_Typ
);
11850 -- Volatile_Components
11852 if not Has_Rep_Item
(Typ
, Name_Volatile_Components
, False)
11853 and then Has_Rep_Item
(Typ
, Name_Volatile_Components
)
11854 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11855 (Get_Rep_Item
(Typ
, Name_Volatile_Components
))
11857 Set_Has_Volatile_Components
(Imp_Bas_Typ
);
11860 -- Finalize_Storage_Only
11862 if not Has_Rep_Pragma
(Typ
, Name_Finalize_Storage_Only
, False)
11863 and then Has_Rep_Pragma
(Typ
, Name_Finalize_Storage_Only
)
11865 Set_Finalize_Storage_Only
(Bas_Typ
);
11868 -- Universal_Aliasing
11870 if not Has_Rep_Item
(Typ
, Name_Universal_Aliasing
, False)
11871 and then Has_Rep_Item
(Typ
, Name_Universal_Aliasing
)
11872 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11873 (Get_Rep_Item
(Typ
, Name_Universal_Aliasing
))
11875 Set_Universal_Aliasing
(Imp_Bas_Typ
);
11880 if Is_Record_Type
(Typ
) then
11881 if not Has_Rep_Item
(Typ
, Name_Bit_Order
, False)
11882 and then Has_Rep_Item
(Typ
, Name_Bit_Order
)
11884 Set_Reverse_Bit_Order
(Bas_Typ
,
11885 Reverse_Bit_Order
(Entity
(Name
11886 (Get_Rep_Item
(Typ
, Name_Bit_Order
)))));
11890 -- Scalar_Storage_Order
11892 -- Note: the aspect is specified on a first subtype, but recorded
11893 -- in a flag of the base type!
11895 if (Is_Record_Type
(Typ
) or else Is_Array_Type
(Typ
))
11896 and then Typ
= Bas_Typ
11898 -- For a type extension, always inherit from parent; otherwise
11899 -- inherit if no default applies. Note: we do not check for
11900 -- an explicit rep item on the parent type when inheriting,
11901 -- because the parent SSO may itself have been set by default.
11903 if not Has_Rep_Item
(First_Subtype
(Typ
),
11904 Name_Scalar_Storage_Order
, False)
11905 and then (Is_Tagged_Type
(Bas_Typ
)
11906 or else not (SSO_Set_Low_By_Default
(Bas_Typ
)
11908 SSO_Set_High_By_Default
(Bas_Typ
)))
11910 Set_Reverse_Storage_Order
(Bas_Typ
,
11911 Reverse_Storage_Order
11912 (Implementation_Base_Type
(Etype
(Bas_Typ
))));
11914 -- Clear default SSO indications, since the inherited aspect
11915 -- which was set explicitly overrides the default.
11917 Set_SSO_Set_Low_By_Default
(Bas_Typ
, False);
11918 Set_SSO_Set_High_By_Default
(Bas_Typ
, False);
11923 end Inherit_Aspects_At_Freeze_Point
;
11929 procedure Initialize
is
11931 Address_Clause_Checks
.Init
;
11932 Unchecked_Conversions
.Init
;
11934 if AAMP_On_Target
then
11935 Independence_Checks
.Init
;
11939 ---------------------------
11940 -- Install_Discriminants --
11941 ---------------------------
11943 procedure Install_Discriminants
(E
: Entity_Id
) is
11947 Disc
:= First_Discriminant
(E
);
11948 while Present
(Disc
) loop
11949 Prev
:= Current_Entity
(Disc
);
11950 Set_Current_Entity
(Disc
);
11951 Set_Is_Immediately_Visible
(Disc
);
11952 Set_Homonym
(Disc
, Prev
);
11953 Next_Discriminant
(Disc
);
11955 end Install_Discriminants
;
11957 -------------------------
11958 -- Is_Operational_Item --
11959 -------------------------
11961 function Is_Operational_Item
(N
: Node_Id
) return Boolean is
11963 if Nkind
(N
) /= N_Attribute_Definition_Clause
then
11968 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Chars
(N
));
11971 -- List of operational items is given in AARM 13.1(8.mm/1).
11972 -- It is clearly incomplete, as it does not include iterator
11973 -- aspects, among others.
11975 return Id
= Attribute_Constant_Indexing
11976 or else Id
= Attribute_Default_Iterator
11977 or else Id
= Attribute_Implicit_Dereference
11978 or else Id
= Attribute_Input
11979 or else Id
= Attribute_Iterator_Element
11980 or else Id
= Attribute_Iterable
11981 or else Id
= Attribute_Output
11982 or else Id
= Attribute_Read
11983 or else Id
= Attribute_Variable_Indexing
11984 or else Id
= Attribute_Write
11985 or else Id
= Attribute_External_Tag
;
11988 end Is_Operational_Item
;
11990 -------------------------
11991 -- Is_Predicate_Static --
11992 -------------------------
11994 -- Note: the basic legality of the expression has already been checked, so
11995 -- we don't need to worry about cases or ranges on strings for example.
11997 function Is_Predicate_Static
11999 Nam
: Name_Id
) return Boolean
12001 function All_Static_Case_Alternatives
(L
: List_Id
) return Boolean;
12002 -- Given a list of case expression alternatives, returns True if all
12003 -- the alternatives are static (have all static choices, and a static
12006 function All_Static_Choices
(L
: List_Id
) return Boolean;
12007 -- Returns true if all elements of the list are OK static choices
12008 -- as defined below for Is_Static_Choice. Used for case expression
12009 -- alternatives and for the right operand of a membership test. An
12010 -- others_choice is static if the corresponding expression is static.
12011 -- The staticness of the bounds is checked separately.
12013 function Is_Static_Choice
(N
: Node_Id
) return Boolean;
12014 -- Returns True if N represents a static choice (static subtype, or
12015 -- static subtype indication, or static expression, or static range).
12017 -- Note that this is a bit more inclusive than we actually need
12018 -- (in particular membership tests do not allow the use of subtype
12019 -- indications). But that doesn't matter, we have already checked
12020 -- that the construct is legal to get this far.
12022 function Is_Type_Ref
(N
: Node_Id
) return Boolean;
12023 pragma Inline
(Is_Type_Ref
);
12024 -- Returns True if N is a reference to the type for the predicate in the
12025 -- expression (i.e. if it is an identifier whose Chars field matches the
12026 -- Nam given in the call). N must not be parenthesized, if the type name
12027 -- appears in parens, this routine will return False.
12029 ----------------------------------
12030 -- All_Static_Case_Alternatives --
12031 ----------------------------------
12033 function All_Static_Case_Alternatives
(L
: List_Id
) return Boolean is
12038 while Present
(N
) loop
12039 if not (All_Static_Choices
(Discrete_Choices
(N
))
12040 and then Is_OK_Static_Expression
(Expression
(N
)))
12049 end All_Static_Case_Alternatives
;
12051 ------------------------
12052 -- All_Static_Choices --
12053 ------------------------
12055 function All_Static_Choices
(L
: List_Id
) return Boolean is
12060 while Present
(N
) loop
12061 if not Is_Static_Choice
(N
) then
12069 end All_Static_Choices
;
12071 ----------------------
12072 -- Is_Static_Choice --
12073 ----------------------
12075 function Is_Static_Choice
(N
: Node_Id
) return Boolean is
12077 return Nkind
(N
) = N_Others_Choice
12078 or else Is_OK_Static_Expression
(N
)
12079 or else (Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
))
12080 and then Is_OK_Static_Subtype
(Entity
(N
)))
12081 or else (Nkind
(N
) = N_Subtype_Indication
12082 and then Is_OK_Static_Subtype
(Entity
(N
)))
12083 or else (Nkind
(N
) = N_Range
and then Is_OK_Static_Range
(N
));
12084 end Is_Static_Choice
;
12090 function Is_Type_Ref
(N
: Node_Id
) return Boolean is
12092 return Nkind
(N
) = N_Identifier
12093 and then Chars
(N
) = Nam
12094 and then Paren_Count
(N
) = 0;
12097 -- Start of processing for Is_Predicate_Static
12100 -- Predicate_Static means one of the following holds. Numbers are the
12101 -- corresponding paragraph numbers in (RM 3.2.4(16-22)).
12103 -- 16: A static expression
12105 if Is_OK_Static_Expression
(Expr
) then
12108 -- 17: A membership test whose simple_expression is the current
12109 -- instance, and whose membership_choice_list meets the requirements
12110 -- for a static membership test.
12112 elsif Nkind
(Expr
) in N_Membership_Test
12113 and then ((Present
(Right_Opnd
(Expr
))
12114 and then Is_Static_Choice
(Right_Opnd
(Expr
)))
12116 (Present
(Alternatives
(Expr
))
12117 and then All_Static_Choices
(Alternatives
(Expr
))))
12121 -- 18. A case_expression whose selecting_expression is the current
12122 -- instance, and whose dependent expressions are static expressions.
12124 elsif Nkind
(Expr
) = N_Case_Expression
12125 and then Is_Type_Ref
(Expression
(Expr
))
12126 and then All_Static_Case_Alternatives
(Alternatives
(Expr
))
12130 -- 19. A call to a predefined equality or ordering operator, where one
12131 -- operand is the current instance, and the other is a static
12134 -- Note: the RM is clearly wrong here in not excluding string types.
12135 -- Without this exclusion, we would allow expressions like X > "ABC"
12136 -- to be considered as predicate-static, which is clearly not intended,
12137 -- since the idea is for predicate-static to be a subset of normal
12138 -- static expressions (and "DEF" > "ABC" is not a static expression).
12140 -- However, we do allow internally generated (not from source) equality
12141 -- and inequality operations to be valid on strings (this helps deal
12142 -- with cases where we transform A in "ABC" to A = "ABC).
12144 elsif Nkind
(Expr
) in N_Op_Compare
12145 and then ((not Is_String_Type
(Etype
(Left_Opnd
(Expr
))))
12146 or else (Nkind_In
(Expr
, N_Op_Eq
, N_Op_Ne
)
12147 and then not Comes_From_Source
(Expr
)))
12148 and then ((Is_Type_Ref
(Left_Opnd
(Expr
))
12149 and then Is_OK_Static_Expression
(Right_Opnd
(Expr
)))
12151 (Is_Type_Ref
(Right_Opnd
(Expr
))
12152 and then Is_OK_Static_Expression
(Left_Opnd
(Expr
))))
12156 -- 20. A call to a predefined boolean logical operator, where each
12157 -- operand is predicate-static.
12159 elsif (Nkind_In
(Expr
, N_Op_And
, N_Op_Or
, N_Op_Xor
)
12160 and then Is_Predicate_Static
(Left_Opnd
(Expr
), Nam
)
12161 and then Is_Predicate_Static
(Right_Opnd
(Expr
), Nam
))
12163 (Nkind
(Expr
) = N_Op_Not
12164 and then Is_Predicate_Static
(Right_Opnd
(Expr
), Nam
))
12168 -- 21. A short-circuit control form where both operands are
12169 -- predicate-static.
12171 elsif Nkind
(Expr
) in N_Short_Circuit
12172 and then Is_Predicate_Static
(Left_Opnd
(Expr
), Nam
)
12173 and then Is_Predicate_Static
(Right_Opnd
(Expr
), Nam
)
12177 -- 22. A parenthesized predicate-static expression. This does not
12178 -- require any special test, since we just ignore paren levels in
12179 -- all the cases above.
12181 -- One more test that is an implementation artifact caused by the fact
12182 -- that we are analyzing not the original expression, but the generated
12183 -- expression in the body of the predicate function. This can include
12184 -- references to inherited predicates, so that the expression we are
12185 -- processing looks like:
12187 -- xxPredicate (typ (Inns)) and then expression
12189 -- Where the call is to a Predicate function for an inherited predicate.
12190 -- We simply ignore such a call, which could be to either a dynamic or
12191 -- a static predicate. Note that if the parent predicate is dynamic then
12192 -- eventually this type will be marked as dynamic, but you are allowed
12193 -- to specify a static predicate for a subtype which is inheriting a
12194 -- dynamic predicate, so the static predicate validation here ignores
12195 -- the inherited predicate even if it is dynamic.
12197 elsif Nkind
(Expr
) = N_Function_Call
12198 and then Is_Predicate_Function
(Entity
(Name
(Expr
)))
12202 -- That's an exhaustive list of tests, all other cases are not
12203 -- predicate-static, so we return False.
12208 end Is_Predicate_Static
;
12210 ---------------------
12211 -- Kill_Rep_Clause --
12212 ---------------------
12214 procedure Kill_Rep_Clause
(N
: Node_Id
) is
12216 pragma Assert
(Ignore_Rep_Clauses
);
12218 -- Note: we use Replace rather than Rewrite, because we don't want
12219 -- ASIS to be able to use Original_Node to dig out the (undecorated)
12220 -- rep clause that is being replaced.
12222 Replace
(N
, Make_Null_Statement
(Sloc
(N
)));
12224 -- The null statement must be marked as not coming from source. This is
12225 -- so that ASIS ignores it, and also the back end does not expect bogus
12226 -- "from source" null statements in weird places (e.g. in declarative
12227 -- regions where such null statements are not allowed).
12229 Set_Comes_From_Source
(N
, False);
12230 end Kill_Rep_Clause
;
12236 function Minimum_Size
12238 Biased
: Boolean := False) return Nat
12240 Lo
: Uint
:= No_Uint
;
12241 Hi
: Uint
:= No_Uint
;
12242 LoR
: Ureal
:= No_Ureal
;
12243 HiR
: Ureal
:= No_Ureal
;
12244 LoSet
: Boolean := False;
12245 HiSet
: Boolean := False;
12248 Ancest
: Entity_Id
;
12249 R_Typ
: constant Entity_Id
:= Root_Type
(T
);
12252 -- If bad type, return 0
12254 if T
= Any_Type
then
12257 -- For generic types, just return zero. There cannot be any legitimate
12258 -- need to know such a size, but this routine may be called with a
12259 -- generic type as part of normal processing.
12261 elsif Is_Generic_Type
(R_Typ
) or else R_Typ
= Any_Type
then
12264 -- Access types (cannot have size smaller than System.Address)
12266 elsif Is_Access_Type
(T
) then
12267 return System_Address_Size
;
12269 -- Floating-point types
12271 elsif Is_Floating_Point_Type
(T
) then
12272 return UI_To_Int
(Esize
(R_Typ
));
12276 elsif Is_Discrete_Type
(T
) then
12278 -- The following loop is looking for the nearest compile time known
12279 -- bounds following the ancestor subtype chain. The idea is to find
12280 -- the most restrictive known bounds information.
12284 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
12289 if Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
)) then
12290 Lo
:= Expr_Rep_Value
(Type_Low_Bound
(Ancest
));
12297 if Compile_Time_Known_Value
(Type_High_Bound
(Ancest
)) then
12298 Hi
:= Expr_Rep_Value
(Type_High_Bound
(Ancest
));
12304 Ancest
:= Ancestor_Subtype
(Ancest
);
12306 if No
(Ancest
) then
12307 Ancest
:= Base_Type
(T
);
12309 if Is_Generic_Type
(Ancest
) then
12315 -- Fixed-point types. We can't simply use Expr_Value to get the
12316 -- Corresponding_Integer_Value values of the bounds, since these do not
12317 -- get set till the type is frozen, and this routine can be called
12318 -- before the type is frozen. Similarly the test for bounds being static
12319 -- needs to include the case where we have unanalyzed real literals for
12320 -- the same reason.
12322 elsif Is_Fixed_Point_Type
(T
) then
12324 -- The following loop is looking for the nearest compile time known
12325 -- bounds following the ancestor subtype chain. The idea is to find
12326 -- the most restrictive known bounds information.
12330 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
12334 -- Note: In the following two tests for LoSet and HiSet, it may
12335 -- seem redundant to test for N_Real_Literal here since normally
12336 -- one would assume that the test for the value being known at
12337 -- compile time includes this case. However, there is a glitch.
12338 -- If the real literal comes from folding a non-static expression,
12339 -- then we don't consider any non- static expression to be known
12340 -- at compile time if we are in configurable run time mode (needed
12341 -- in some cases to give a clearer definition of what is and what
12342 -- is not accepted). So the test is indeed needed. Without it, we
12343 -- would set neither Lo_Set nor Hi_Set and get an infinite loop.
12346 if Nkind
(Type_Low_Bound
(Ancest
)) = N_Real_Literal
12347 or else Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
))
12349 LoR
:= Expr_Value_R
(Type_Low_Bound
(Ancest
));
12356 if Nkind
(Type_High_Bound
(Ancest
)) = N_Real_Literal
12357 or else Compile_Time_Known_Value
(Type_High_Bound
(Ancest
))
12359 HiR
:= Expr_Value_R
(Type_High_Bound
(Ancest
));
12365 Ancest
:= Ancestor_Subtype
(Ancest
);
12367 if No
(Ancest
) then
12368 Ancest
:= Base_Type
(T
);
12370 if Is_Generic_Type
(Ancest
) then
12376 Lo
:= UR_To_Uint
(LoR
/ Small_Value
(T
));
12377 Hi
:= UR_To_Uint
(HiR
/ Small_Value
(T
));
12379 -- No other types allowed
12382 raise Program_Error
;
12385 -- Fall through with Hi and Lo set. Deal with biased case
12388 and then not Is_Fixed_Point_Type
(T
)
12389 and then not (Is_Enumeration_Type
(T
)
12390 and then Has_Non_Standard_Rep
(T
)))
12391 or else Has_Biased_Representation
(T
)
12397 -- Null range case, size is always zero. We only do this in the discrete
12398 -- type case, since that's the odd case that came up. Probably we should
12399 -- also do this in the fixed-point case, but doing so causes peculiar
12400 -- gigi failures, and it is not worth worrying about this incredibly
12401 -- marginal case (explicit null-range fixed-point type declarations)???
12403 if Lo
> Hi
and then Is_Discrete_Type
(T
) then
12406 -- Signed case. Note that we consider types like range 1 .. -1 to be
12407 -- signed for the purpose of computing the size, since the bounds have
12408 -- to be accommodated in the base type.
12410 elsif Lo
< 0 or else Hi
< 0 then
12414 -- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1))
12415 -- Note that we accommodate the case where the bounds cross. This
12416 -- can happen either because of the way the bounds are declared
12417 -- or because of the algorithm in Freeze_Fixed_Point_Type.
12431 -- If both bounds are positive, make sure that both are represen-
12432 -- table in the case where the bounds are crossed. This can happen
12433 -- either because of the way the bounds are declared, or because of
12434 -- the algorithm in Freeze_Fixed_Point_Type.
12440 -- S = size, (can accommodate 0 .. (2**size - 1))
12443 while Hi
>= Uint_2
** S
loop
12451 ---------------------------
12452 -- New_Stream_Subprogram --
12453 ---------------------------
12455 procedure New_Stream_Subprogram
12459 Nam
: TSS_Name_Type
)
12461 Loc
: constant Source_Ptr
:= Sloc
(N
);
12462 Sname
: constant Name_Id
:= Make_TSS_Name
(Base_Type
(Ent
), Nam
);
12463 Subp_Id
: Entity_Id
;
12464 Subp_Decl
: Node_Id
;
12468 Defer_Declaration
: constant Boolean :=
12469 Is_Tagged_Type
(Ent
) or else Is_Private_Type
(Ent
);
12470 -- For a tagged type, there is a declaration for each stream attribute
12471 -- at the freeze point, and we must generate only a completion of this
12472 -- declaration. We do the same for private types, because the full view
12473 -- might be tagged. Otherwise we generate a declaration at the point of
12474 -- the attribute definition clause.
12476 function Build_Spec
return Node_Id
;
12477 -- Used for declaration and renaming declaration, so that this is
12478 -- treated as a renaming_as_body.
12484 function Build_Spec
return Node_Id
is
12485 Out_P
: constant Boolean := (Nam
= TSS_Stream_Read
);
12488 T_Ref
: constant Node_Id
:= New_Occurrence_Of
(Etyp
, Loc
);
12491 Subp_Id
:= Make_Defining_Identifier
(Loc
, Sname
);
12493 -- S : access Root_Stream_Type'Class
12495 Formals
:= New_List
(
12496 Make_Parameter_Specification
(Loc
,
12497 Defining_Identifier
=>
12498 Make_Defining_Identifier
(Loc
, Name_S
),
12500 Make_Access_Definition
(Loc
,
12502 New_Occurrence_Of
(
12503 Designated_Type
(Etype
(F
)), Loc
))));
12505 if Nam
= TSS_Stream_Input
then
12507 Make_Function_Specification
(Loc
,
12508 Defining_Unit_Name
=> Subp_Id
,
12509 Parameter_Specifications
=> Formals
,
12510 Result_Definition
=> T_Ref
);
12514 Append_To
(Formals
,
12515 Make_Parameter_Specification
(Loc
,
12516 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_V
),
12517 Out_Present
=> Out_P
,
12518 Parameter_Type
=> T_Ref
));
12521 Make_Procedure_Specification
(Loc
,
12522 Defining_Unit_Name
=> Subp_Id
,
12523 Parameter_Specifications
=> Formals
);
12529 -- Start of processing for New_Stream_Subprogram
12532 F
:= First_Formal
(Subp
);
12534 if Ekind
(Subp
) = E_Procedure
then
12535 Etyp
:= Etype
(Next_Formal
(F
));
12537 Etyp
:= Etype
(Subp
);
12540 -- Prepare subprogram declaration and insert it as an action on the
12541 -- clause node. The visibility for this entity is used to test for
12542 -- visibility of the attribute definition clause (in the sense of
12543 -- 8.3(23) as amended by AI-195).
12545 if not Defer_Declaration
then
12547 Make_Subprogram_Declaration
(Loc
,
12548 Specification
=> Build_Spec
);
12550 -- For a tagged type, there is always a visible declaration for each
12551 -- stream TSS (it is a predefined primitive operation), and the
12552 -- completion of this declaration occurs at the freeze point, which is
12553 -- not always visible at places where the attribute definition clause is
12554 -- visible. So, we create a dummy entity here for the purpose of
12555 -- tracking the visibility of the attribute definition clause itself.
12559 Make_Defining_Identifier
(Loc
, New_External_Name
(Sname
, 'V'));
12561 Make_Object_Declaration
(Loc
,
12562 Defining_Identifier
=> Subp_Id
,
12563 Object_Definition
=> New_Occurrence_Of
(Standard_Boolean
, Loc
));
12566 Insert_Action
(N
, Subp_Decl
);
12567 Set_Entity
(N
, Subp_Id
);
12570 Make_Subprogram_Renaming_Declaration
(Loc
,
12571 Specification
=> Build_Spec
,
12572 Name
=> New_Occurrence_Of
(Subp
, Loc
));
12574 if Defer_Declaration
then
12575 Set_TSS
(Base_Type
(Ent
), Subp_Id
);
12577 Insert_Action
(N
, Subp_Decl
);
12578 Copy_TSS
(Subp_Id
, Base_Type
(Ent
));
12580 end New_Stream_Subprogram
;
12582 ------------------------------------------
12583 -- Push_Scope_And_Install_Discriminants --
12584 ------------------------------------------
12586 procedure Push_Scope_And_Install_Discriminants
(E
: Entity_Id
) is
12588 if Has_Discriminants
(E
) then
12591 -- Make discriminants visible for type declarations and protected
12592 -- type declarations, not for subtype declarations (RM 13.1.1 (12/3))
12594 if Nkind
(Parent
(E
)) /= N_Subtype_Declaration
then
12595 Install_Discriminants
(E
);
12598 end Push_Scope_And_Install_Discriminants
;
12600 ------------------------
12601 -- Rep_Item_Too_Early --
12602 ------------------------
12604 function Rep_Item_Too_Early
(T
: Entity_Id
; N
: Node_Id
) return Boolean is
12606 -- Cannot apply non-operational rep items to generic types
12608 if Is_Operational_Item
(N
) then
12612 and then Is_Generic_Type
(Root_Type
(T
))
12613 and then (Nkind
(N
) /= N_Pragma
12614 or else Get_Pragma_Id
(N
) /= Pragma_Convention
)
12616 Error_Msg_N
("representation item not allowed for generic type", N
);
12620 -- Otherwise check for incomplete type
12622 if Is_Incomplete_Or_Private_Type
(T
)
12623 and then No
(Underlying_Type
(T
))
12625 (Nkind
(N
) /= N_Pragma
12626 or else Get_Pragma_Id
(N
) /= Pragma_Import
)
12629 ("representation item must be after full type declaration", N
);
12632 -- If the type has incomplete components, a representation clause is
12633 -- illegal but stream attributes and Convention pragmas are correct.
12635 elsif Has_Private_Component
(T
) then
12636 if Nkind
(N
) = N_Pragma
then
12641 ("representation item must appear after type is fully defined",
12648 end Rep_Item_Too_Early
;
12650 -----------------------
12651 -- Rep_Item_Too_Late --
12652 -----------------------
12654 function Rep_Item_Too_Late
12657 FOnly
: Boolean := False) return Boolean
12660 Parent_Type
: Entity_Id
;
12662 procedure No_Type_Rep_Item
;
12663 -- Output message indicating that no type-related aspects can be
12664 -- specified due to some property of the parent type.
12666 procedure Too_Late
;
12667 -- Output message for an aspect being specified too late
12669 -- Note that neither of the above errors is considered a serious one,
12670 -- since the effect is simply that we ignore the representation clause
12672 -- Is this really true? In any case if we make this change we must
12673 -- document the requirement in the spec of Rep_Item_Too_Late that
12674 -- if True is returned, then the rep item must be completely ignored???
12676 ----------------------
12677 -- No_Type_Rep_Item --
12678 ----------------------
12680 procedure No_Type_Rep_Item
is
12682 Error_Msg_N
("|type-related representation item not permitted!", N
);
12683 end No_Type_Rep_Item
;
12689 procedure Too_Late
is
12691 -- Other compilers seem more relaxed about rep items appearing too
12692 -- late. Since analysis tools typically don't care about rep items
12693 -- anyway, no reason to be too strict about this.
12695 if not Relaxed_RM_Semantics
then
12696 Error_Msg_N
("|representation item appears too late!", N
);
12700 -- Start of processing for Rep_Item_Too_Late
12703 -- First make sure entity is not frozen (RM 13.1(9))
12707 -- Exclude imported types, which may be frozen if they appear in a
12708 -- representation clause for a local type.
12710 and then not From_Limited_With
(T
)
12712 -- Exclude generated entities (not coming from source). The common
12713 -- case is when we generate a renaming which prematurely freezes the
12714 -- renamed internal entity, but we still want to be able to set copies
12715 -- of attribute values such as Size/Alignment.
12717 and then Comes_From_Source
(T
)
12719 -- A self-referential aspect is illegal if it forces freezing the
12720 -- entity before the corresponding pragma has been analyzed.
12722 if Nkind_In
(N
, N_Attribute_Definition_Clause
, N_Pragma
)
12723 and then From_Aspect_Specification
(N
)
12726 ("aspect specification causes premature freezing of&", T
, N
);
12727 Set_Has_Delayed_Freeze
(T
, False);
12732 S
:= First_Subtype
(T
);
12734 if Present
(Freeze_Node
(S
)) then
12735 if not Relaxed_RM_Semantics
then
12737 ("??no more representation items for }", Freeze_Node
(S
), S
);
12743 -- Check for case of untagged derived type whose parent either has
12744 -- primitive operations, or is a by reference type (RM 13.1(10)). In
12745 -- this case we do not output a Too_Late message, since there is no
12746 -- earlier point where the rep item could be placed to make it legal.
12750 and then Is_Derived_Type
(T
)
12751 and then not Is_Tagged_Type
(T
)
12753 Parent_Type
:= Etype
(Base_Type
(T
));
12755 if Has_Primitive_Operations
(Parent_Type
) then
12758 if not Relaxed_RM_Semantics
then
12760 ("\parent type & has primitive operations!", N
, Parent_Type
);
12765 elsif Is_By_Reference_Type
(Parent_Type
) then
12768 if not Relaxed_RM_Semantics
then
12770 ("\parent type & is a by reference type!", N
, Parent_Type
);
12777 -- No error, but one more warning to consider. The RM (surprisingly)
12778 -- allows this pattern:
12781 -- primitive operations for S
12782 -- type R is new S;
12783 -- rep clause for S
12785 -- Meaning that calls on the primitive operations of S for values of
12786 -- type R may require possibly expensive implicit conversion operations.
12787 -- This is not an error, but is worth a warning.
12789 if not Relaxed_RM_Semantics
and then Is_Type
(T
) then
12791 DTL
: constant Entity_Id
:= Derived_Type_Link
(Base_Type
(T
));
12795 and then Has_Primitive_Operations
(Base_Type
(T
))
12797 -- For now, do not generate this warning for the case of aspect
12798 -- specification using Ada 2012 syntax, since we get wrong
12799 -- messages we do not understand. The whole business of derived
12800 -- types and rep items seems a bit confused when aspects are
12801 -- used, since the aspects are not evaluated till freeze time.
12803 and then not From_Aspect_Specification
(N
)
12805 Error_Msg_Sloc
:= Sloc
(DTL
);
12807 ("representation item for& appears after derived type "
12808 & "declaration#??", N
);
12810 ("\may result in implicit conversions for primitive "
12811 & "operations of&??", N
, T
);
12813 ("\to change representations when called with arguments "
12814 & "of type&??", N
, DTL
);
12819 -- No error, link item into head of chain of rep items for the entity,
12820 -- but avoid chaining if we have an overloadable entity, and the pragma
12821 -- is one that can apply to multiple overloaded entities.
12823 if Is_Overloadable
(T
) and then Nkind
(N
) = N_Pragma
then
12825 Pname
: constant Name_Id
:= Pragma_Name
(N
);
12827 if Nam_In
(Pname
, Name_Convention
, Name_Import
, Name_Export
,
12828 Name_External
, Name_Interface
)
12835 Record_Rep_Item
(T
, N
);
12837 end Rep_Item_Too_Late
;
12839 -------------------------------------
12840 -- Replace_Type_References_Generic --
12841 -------------------------------------
12843 procedure Replace_Type_References_Generic
(N
: Node_Id
; T
: Entity_Id
) is
12844 TName
: constant Name_Id
:= Chars
(T
);
12846 function Replace_Node
(N
: Node_Id
) return Traverse_Result
;
12847 -- Processes a single node in the traversal procedure below, checking
12848 -- if node N should be replaced, and if so, doing the replacement.
12850 procedure Replace_Type_Refs
is new Traverse_Proc
(Replace_Node
);
12851 -- This instantiation provides the body of Replace_Type_References
12857 function Replace_Node
(N
: Node_Id
) return Traverse_Result
is
12862 -- Case of identifier
12864 if Nkind
(N
) = N_Identifier
then
12866 -- If not the type name, check whether it is a reference to
12867 -- some other type, which must be frozen before the predicate
12868 -- function is analyzed, i.e. before the freeze node of the
12869 -- type to which the predicate applies.
12871 if Chars
(N
) /= TName
then
12872 if Present
(Current_Entity
(N
))
12873 and then Is_Type
(Current_Entity
(N
))
12875 Freeze_Before
(Freeze_Node
(T
), Current_Entity
(N
));
12880 -- Otherwise do the replacement and we are done with this node
12883 Replace_Type_Reference
(N
);
12887 -- Case of selected component (which is what a qualification
12888 -- looks like in the unanalyzed tree, which is what we have.
12890 elsif Nkind
(N
) = N_Selected_Component
then
12892 -- If selector name is not our type, keeping going (we might
12893 -- still have an occurrence of the type in the prefix).
12895 if Nkind
(Selector_Name
(N
)) /= N_Identifier
12896 or else Chars
(Selector_Name
(N
)) /= TName
12900 -- Selector name is our type, check qualification
12903 -- Loop through scopes and prefixes, doing comparison
12905 S
:= Current_Scope
;
12908 -- Continue if no more scopes or scope with no name
12910 if No
(S
) or else Nkind
(S
) not in N_Has_Chars
then
12914 -- Do replace if prefix is an identifier matching the
12915 -- scope that we are currently looking at.
12917 if Nkind
(P
) = N_Identifier
12918 and then Chars
(P
) = Chars
(S
)
12920 Replace_Type_Reference
(N
);
12924 -- Go check scope above us if prefix is itself of the
12925 -- form of a selected component, whose selector matches
12926 -- the scope we are currently looking at.
12928 if Nkind
(P
) = N_Selected_Component
12929 and then Nkind
(Selector_Name
(P
)) = N_Identifier
12930 and then Chars
(Selector_Name
(P
)) = Chars
(S
)
12935 -- For anything else, we don't have a match, so keep on
12936 -- going, there are still some weird cases where we may
12937 -- still have a replacement within the prefix.
12945 -- Continue for any other node kind
12953 Replace_Type_Refs
(N
);
12954 end Replace_Type_References_Generic
;
12956 --------------------------------
12957 -- Resolve_Aspect_Expressions --
12958 --------------------------------
12960 procedure Resolve_Aspect_Expressions
(E
: Entity_Id
) is
12965 function Resolve_Name
(N
: Node_Id
) return Traverse_Result
;
12966 -- Verify that all identifiers in the expression, with the exception
12967 -- of references to the current entity, denote visible entities. This
12968 -- is done only to detect visibility errors, as the expression will be
12969 -- properly analyzed/expanded during analysis of the predicate function
12970 -- body. We omit quantified expressions from this test, given that they
12971 -- introduce a local identifier that would require proper expansion to
12972 -- handle properly.
12978 function Resolve_Name
(N
: Node_Id
) return Traverse_Result
is
12980 if Nkind
(N
) = N_Selected_Component
then
12981 if Nkind
(Prefix
(N
)) = N_Identifier
12982 and then Chars
(Prefix
(N
)) /= Chars
(E
)
12984 Find_Selected_Component
(N
);
12989 elsif Nkind
(N
) = N_Identifier
and then Chars
(N
) /= Chars
(E
) then
12990 Find_Direct_Name
(N
);
12991 Set_Entity
(N
, Empty
);
12993 elsif Nkind
(N
) = N_Quantified_Expression
then
13000 procedure Resolve_Aspect_Expression
is new Traverse_Proc
(Resolve_Name
);
13002 -- Start of processing for Resolve_Aspect_Expressions
13005 ASN
:= First_Rep_Item
(E
);
13006 while Present
(ASN
) loop
13007 if Nkind
(ASN
) = N_Aspect_Specification
and then Entity
(ASN
) = E
then
13008 A_Id
:= Get_Aspect_Id
(ASN
);
13009 Expr
:= Expression
(ASN
);
13012 -- For now we only deal with aspects that do not generate
13013 -- subprograms, or that may mention current instances of
13014 -- types. These will require special handling (???TBD).
13016 when Aspect_Predicate |
13017 Aspect_Predicate_Failure |
13018 Aspect_Invariant
=>
13021 when Aspect_Static_Predicate |
13022 Aspect_Dynamic_Predicate
=>
13024 -- Build predicate function specification and preanalyze
13025 -- expression after type replacement.
13027 if No
(Predicate_Function
(E
)) then
13029 FDecl
: constant Node_Id
:=
13030 Build_Predicate_Function_Declaration
(E
);
13031 pragma Unreferenced
(FDecl
);
13033 Resolve_Aspect_Expression
(Expr
);
13037 when Pre_Post_Aspects
=>
13040 when Aspect_Iterable
=>
13041 if Nkind
(Expr
) = N_Aggregate
then
13046 Assoc
:= First
(Component_Associations
(Expr
));
13047 while Present
(Assoc
) loop
13048 Find_Direct_Name
(Expression
(Assoc
));
13055 if Present
(Expr
) then
13056 case Aspect_Argument
(A_Id
) is
13057 when Expression | Optional_Expression
=>
13058 Analyze_And_Resolve
(Expression
(ASN
));
13060 when Name | Optional_Name
=>
13061 if Nkind
(Expr
) = N_Identifier
then
13062 Find_Direct_Name
(Expr
);
13064 elsif Nkind
(Expr
) = N_Selected_Component
then
13065 Find_Selected_Component
(Expr
);
13075 ASN
:= Next_Rep_Item
(ASN
);
13077 end Resolve_Aspect_Expressions
;
13079 -------------------------
13080 -- Same_Representation --
13081 -------------------------
13083 function Same_Representation
(Typ1
, Typ2
: Entity_Id
) return Boolean is
13084 T1
: constant Entity_Id
:= Underlying_Type
(Typ1
);
13085 T2
: constant Entity_Id
:= Underlying_Type
(Typ2
);
13088 -- A quick check, if base types are the same, then we definitely have
13089 -- the same representation, because the subtype specific representation
13090 -- attributes (Size and Alignment) do not affect representation from
13091 -- the point of view of this test.
13093 if Base_Type
(T1
) = Base_Type
(T2
) then
13096 elsif Is_Private_Type
(Base_Type
(T2
))
13097 and then Base_Type
(T1
) = Full_View
(Base_Type
(T2
))
13102 -- Tagged types never have differing representations
13104 if Is_Tagged_Type
(T1
) then
13108 -- Representations are definitely different if conventions differ
13110 if Convention
(T1
) /= Convention
(T2
) then
13114 -- Representations are different if component alignments or scalar
13115 -- storage orders differ.
13117 if (Is_Record_Type
(T1
) or else Is_Array_Type
(T1
))
13119 (Is_Record_Type
(T2
) or else Is_Array_Type
(T2
))
13121 (Component_Alignment
(T1
) /= Component_Alignment
(T2
)
13122 or else Reverse_Storage_Order
(T1
) /= Reverse_Storage_Order
(T2
))
13127 -- For arrays, the only real issue is component size. If we know the
13128 -- component size for both arrays, and it is the same, then that's
13129 -- good enough to know we don't have a change of representation.
13131 if Is_Array_Type
(T1
) then
13132 if Known_Component_Size
(T1
)
13133 and then Known_Component_Size
(T2
)
13134 and then Component_Size
(T1
) = Component_Size
(T2
)
13140 -- Types definitely have same representation if neither has non-standard
13141 -- representation since default representations are always consistent.
13142 -- If only one has non-standard representation, and the other does not,
13143 -- then we consider that they do not have the same representation. They
13144 -- might, but there is no way of telling early enough.
13146 if Has_Non_Standard_Rep
(T1
) then
13147 if not Has_Non_Standard_Rep
(T2
) then
13151 return not Has_Non_Standard_Rep
(T2
);
13154 -- Here the two types both have non-standard representation, and we need
13155 -- to determine if they have the same non-standard representation.
13157 -- For arrays, we simply need to test if the component sizes are the
13158 -- same. Pragma Pack is reflected in modified component sizes, so this
13159 -- check also deals with pragma Pack.
13161 if Is_Array_Type
(T1
) then
13162 return Component_Size
(T1
) = Component_Size
(T2
);
13164 -- Tagged types always have the same representation, because it is not
13165 -- possible to specify different representations for common fields.
13167 elsif Is_Tagged_Type
(T1
) then
13170 -- Case of record types
13172 elsif Is_Record_Type
(T1
) then
13174 -- Packed status must conform
13176 if Is_Packed
(T1
) /= Is_Packed
(T2
) then
13179 -- Otherwise we must check components. Typ2 maybe a constrained
13180 -- subtype with fewer components, so we compare the components
13181 -- of the base types.
13184 Record_Case
: declare
13185 CD1
, CD2
: Entity_Id
;
13187 function Same_Rep
return Boolean;
13188 -- CD1 and CD2 are either components or discriminants. This
13189 -- function tests whether they have the same representation.
13195 function Same_Rep
return Boolean is
13197 if No
(Component_Clause
(CD1
)) then
13198 return No
(Component_Clause
(CD2
));
13200 -- Note: at this point, component clauses have been
13201 -- normalized to the default bit order, so that the
13202 -- comparison of Component_Bit_Offsets is meaningful.
13205 Present
(Component_Clause
(CD2
))
13207 Component_Bit_Offset
(CD1
) = Component_Bit_Offset
(CD2
)
13209 Esize
(CD1
) = Esize
(CD2
);
13213 -- Start of processing for Record_Case
13216 if Has_Discriminants
(T1
) then
13218 -- The number of discriminants may be different if the
13219 -- derived type has fewer (constrained by values). The
13220 -- invisible discriminants retain the representation of
13221 -- the original, so the discrepancy does not per se
13222 -- indicate a different representation.
13224 CD1
:= First_Discriminant
(T1
);
13225 CD2
:= First_Discriminant
(T2
);
13226 while Present
(CD1
) and then Present
(CD2
) loop
13227 if not Same_Rep
then
13230 Next_Discriminant
(CD1
);
13231 Next_Discriminant
(CD2
);
13236 CD1
:= First_Component
(Underlying_Type
(Base_Type
(T1
)));
13237 CD2
:= First_Component
(Underlying_Type
(Base_Type
(T2
)));
13238 while Present
(CD1
) loop
13239 if not Same_Rep
then
13242 Next_Component
(CD1
);
13243 Next_Component
(CD2
);
13251 -- For enumeration types, we must check each literal to see if the
13252 -- representation is the same. Note that we do not permit enumeration
13253 -- representation clauses for Character and Wide_Character, so these
13254 -- cases were already dealt with.
13256 elsif Is_Enumeration_Type
(T1
) then
13257 Enumeration_Case
: declare
13258 L1
, L2
: Entity_Id
;
13261 L1
:= First_Literal
(T1
);
13262 L2
:= First_Literal
(T2
);
13263 while Present
(L1
) loop
13264 if Enumeration_Rep
(L1
) /= Enumeration_Rep
(L2
) then
13273 end Enumeration_Case
;
13275 -- Any other types have the same representation for these purposes
13280 end Same_Representation
;
13282 --------------------------------
13283 -- Resolve_Iterable_Operation --
13284 --------------------------------
13286 procedure Resolve_Iterable_Operation
13288 Cursor
: Entity_Id
;
13297 if not Is_Overloaded
(N
) then
13298 if not Is_Entity_Name
(N
)
13299 or else Ekind
(Entity
(N
)) /= E_Function
13300 or else Scope
(Entity
(N
)) /= Scope
(Typ
)
13301 or else No
(First_Formal
(Entity
(N
)))
13302 or else Etype
(First_Formal
(Entity
(N
))) /= Typ
13304 Error_Msg_N
("iterable primitive must be local function name "
13305 & "whose first formal is an iterable type", N
);
13310 F1
:= First_Formal
(Ent
);
13311 if Nam
= Name_First
then
13313 -- First (Container) => Cursor
13315 if Etype
(Ent
) /= Cursor
then
13316 Error_Msg_N
("primitive for First must yield a curosr", N
);
13319 elsif Nam
= Name_Next
then
13321 -- Next (Container, Cursor) => Cursor
13323 F2
:= Next_Formal
(F1
);
13325 if Etype
(F2
) /= Cursor
13326 or else Etype
(Ent
) /= Cursor
13327 or else Present
(Next_Formal
(F2
))
13329 Error_Msg_N
("no match for Next iterable primitive", N
);
13332 elsif Nam
= Name_Has_Element
then
13334 -- Has_Element (Container, Cursor) => Boolean
13336 F2
:= Next_Formal
(F1
);
13337 if Etype
(F2
) /= Cursor
13338 or else Etype
(Ent
) /= Standard_Boolean
13339 or else Present
(Next_Formal
(F2
))
13341 Error_Msg_N
("no match for Has_Element iterable primitive", N
);
13344 elsif Nam
= Name_Element
then
13345 F2
:= Next_Formal
(F1
);
13348 or else Etype
(F2
) /= Cursor
13349 or else Present
(Next_Formal
(F2
))
13351 Error_Msg_N
("no match for Element iterable primitive", N
);
13356 raise Program_Error
;
13360 -- Overloaded case: find subprogram with proper signature.
13361 -- Caller will report error if no match is found.
13368 Get_First_Interp
(N
, I
, It
);
13369 while Present
(It
.Typ
) loop
13370 if Ekind
(It
.Nam
) = E_Function
13371 and then Scope
(It
.Nam
) = Scope
(Typ
)
13372 and then Etype
(First_Formal
(It
.Nam
)) = Typ
13374 F1
:= First_Formal
(It
.Nam
);
13376 if Nam
= Name_First
then
13377 if Etype
(It
.Nam
) = Cursor
13378 and then No
(Next_Formal
(F1
))
13380 Set_Entity
(N
, It
.Nam
);
13384 elsif Nam
= Name_Next
then
13385 F2
:= Next_Formal
(F1
);
13388 and then No
(Next_Formal
(F2
))
13389 and then Etype
(F2
) = Cursor
13390 and then Etype
(It
.Nam
) = Cursor
13392 Set_Entity
(N
, It
.Nam
);
13396 elsif Nam
= Name_Has_Element
then
13397 F2
:= Next_Formal
(F1
);
13400 and then No
(Next_Formal
(F2
))
13401 and then Etype
(F2
) = Cursor
13402 and then Etype
(It
.Nam
) = Standard_Boolean
13404 Set_Entity
(N
, It
.Nam
);
13405 F2
:= Next_Formal
(F1
);
13409 elsif Nam
= Name_Element
then
13410 F2
:= Next_Formal
(F1
);
13413 and then No
(Next_Formal
(F2
))
13414 and then Etype
(F2
) = Cursor
13416 Set_Entity
(N
, It
.Nam
);
13422 Get_Next_Interp
(I
, It
);
13426 end Resolve_Iterable_Operation
;
13432 procedure Set_Biased
13436 Biased
: Boolean := True)
13440 Set_Has_Biased_Representation
(E
);
13442 if Warn_On_Biased_Representation
then
13444 ("?B?" & Msg
& " forces biased representation for&", N
, E
);
13449 --------------------
13450 -- Set_Enum_Esize --
13451 --------------------
13453 procedure Set_Enum_Esize
(T
: Entity_Id
) is
13459 Init_Alignment
(T
);
13461 -- Find the minimum standard size (8,16,32,64) that fits
13463 Lo
:= Enumeration_Rep
(Entity
(Type_Low_Bound
(T
)));
13464 Hi
:= Enumeration_Rep
(Entity
(Type_High_Bound
(T
)));
13467 if Lo
>= -Uint_2
**07 and then Hi
< Uint_2
**07 then
13468 Sz
:= Standard_Character_Size
; -- May be > 8 on some targets
13470 elsif Lo
>= -Uint_2
**15 and then Hi
< Uint_2
**15 then
13473 elsif Lo
>= -Uint_2
**31 and then Hi
< Uint_2
**31 then
13476 else pragma Assert
(Lo
>= -Uint_2
**63 and then Hi
< Uint_2
**63);
13481 if Hi
< Uint_2
**08 then
13482 Sz
:= Standard_Character_Size
; -- May be > 8 on some targets
13484 elsif Hi
< Uint_2
**16 then
13487 elsif Hi
< Uint_2
**32 then
13490 else pragma Assert
(Hi
< Uint_2
**63);
13495 -- That minimum is the proper size unless we have a foreign convention
13496 -- and the size required is 32 or less, in which case we bump the size
13497 -- up to 32. This is required for C and C++ and seems reasonable for
13498 -- all other foreign conventions.
13500 if Has_Foreign_Convention
(T
)
13501 and then Esize
(T
) < Standard_Integer_Size
13503 -- Don't do this if Short_Enums on target
13505 and then not Target_Short_Enums
13507 Init_Esize
(T
, Standard_Integer_Size
);
13509 Init_Esize
(T
, Sz
);
13511 end Set_Enum_Esize
;
13513 -----------------------------
13514 -- Uninstall_Discriminants --
13515 -----------------------------
13517 procedure Uninstall_Discriminants
(E
: Entity_Id
) is
13523 -- Discriminants have been made visible for type declarations and
13524 -- protected type declarations, not for subtype declarations.
13526 if Nkind
(Parent
(E
)) /= N_Subtype_Declaration
then
13527 Disc
:= First_Discriminant
(E
);
13528 while Present
(Disc
) loop
13529 if Disc
/= Current_Entity
(Disc
) then
13530 Prev
:= Current_Entity
(Disc
);
13531 while Present
(Prev
)
13532 and then Present
(Homonym
(Prev
))
13533 and then Homonym
(Prev
) /= Disc
13535 Prev
:= Homonym
(Prev
);
13541 Set_Is_Immediately_Visible
(Disc
, False);
13543 Outer
:= Homonym
(Disc
);
13544 while Present
(Outer
) and then Scope
(Outer
) = E
loop
13545 Outer
:= Homonym
(Outer
);
13548 -- Reset homonym link of other entities, but do not modify link
13549 -- between entities in current scope, so that the back end can
13550 -- have a proper count of local overloadings.
13553 Set_Name_Entity_Id
(Chars
(Disc
), Outer
);
13555 elsif Scope
(Prev
) /= Scope
(Disc
) then
13556 Set_Homonym
(Prev
, Outer
);
13559 Next_Discriminant
(Disc
);
13562 end Uninstall_Discriminants
;
13564 -------------------------------------------
13565 -- Uninstall_Discriminants_And_Pop_Scope --
13566 -------------------------------------------
13568 procedure Uninstall_Discriminants_And_Pop_Scope
(E
: Entity_Id
) is
13570 if Has_Discriminants
(E
) then
13571 Uninstall_Discriminants
(E
);
13574 end Uninstall_Discriminants_And_Pop_Scope
;
13576 ------------------------------
13577 -- Validate_Address_Clauses --
13578 ------------------------------
13580 procedure Validate_Address_Clauses
is
13582 for J
in Address_Clause_Checks
.First
.. Address_Clause_Checks
.Last
loop
13584 ACCR
: Address_Clause_Check_Record
13585 renames Address_Clause_Checks
.Table
(J
);
13589 X_Alignment
: Uint
;
13590 Y_Alignment
: Uint
;
13596 -- Skip processing of this entry if warning already posted
13598 if not Address_Warning_Posted
(ACCR
.N
) then
13599 Expr
:= Original_Node
(Expression
(ACCR
.N
));
13603 X_Alignment
:= Alignment
(ACCR
.X
);
13604 Y_Alignment
:= Alignment
(ACCR
.Y
);
13606 -- Similarly obtain sizes
13608 X_Size
:= Esize
(ACCR
.X
);
13609 Y_Size
:= Esize
(ACCR
.Y
);
13611 -- Check for large object overlaying smaller one
13614 and then X_Size
> Uint_0
13615 and then X_Size
> Y_Size
13617 Error_Msg_NE
("??& overlays smaller object", ACCR
.N
, ACCR
.X
);
13619 ("\??program execution may be erroneous", ACCR
.N
);
13621 Error_Msg_Uint_1
:= X_Size
;
13622 Error_Msg_NE
("\??size of & is ^", ACCR
.N
, ACCR
.X
);
13624 Error_Msg_Uint_1
:= Y_Size
;
13625 Error_Msg_NE
("\??size of & is ^", ACCR
.N
, ACCR
.Y
);
13627 -- Check for inadequate alignment, both of the base object
13628 -- and of the offset, if any. We only do this check if the
13629 -- run-time Alignment_Check is active. No point in warning
13630 -- if this check has been suppressed (or is suppressed by
13631 -- default in the non-strict alignment machine case).
13633 -- Note: we do not check the alignment if we gave a size
13634 -- warning, since it would likely be redundant.
13636 elsif not Alignment_Checks_Suppressed
(ACCR
.Y
)
13637 and then Y_Alignment
/= Uint_0
13639 (Y_Alignment
< X_Alignment
13642 and then Nkind
(Expr
) = N_Attribute_Reference
13643 and then Attribute_Name
(Expr
) = Name_Address
13644 and then Has_Compatible_Alignment
13645 (ACCR
.X
, Prefix
(Expr
), True) /=
13649 ("??specified address for& may be inconsistent with "
13650 & "alignment", ACCR
.N
, ACCR
.X
);
13652 ("\??program execution may be erroneous (RM 13.3(27))",
13655 Error_Msg_Uint_1
:= X_Alignment
;
13656 Error_Msg_NE
("\??alignment of & is ^", ACCR
.N
, ACCR
.X
);
13658 Error_Msg_Uint_1
:= Y_Alignment
;
13659 Error_Msg_NE
("\??alignment of & is ^", ACCR
.N
, ACCR
.Y
);
13661 if Y_Alignment
>= X_Alignment
then
13663 ("\??but offset is not multiple of alignment", ACCR
.N
);
13669 end Validate_Address_Clauses
;
13671 ---------------------------
13672 -- Validate_Independence --
13673 ---------------------------
13675 procedure Validate_Independence
is
13676 SU
: constant Uint
:= UI_From_Int
(System_Storage_Unit
);
13684 procedure Check_Array_Type
(Atyp
: Entity_Id
);
13685 -- Checks if the array type Atyp has independent components, and
13686 -- if not, outputs an appropriate set of error messages.
13688 procedure No_Independence
;
13689 -- Output message that independence cannot be guaranteed
13691 function OK_Component
(C
: Entity_Id
) return Boolean;
13692 -- Checks one component to see if it is independently accessible, and
13693 -- if so yields True, otherwise yields False if independent access
13694 -- cannot be guaranteed. This is a conservative routine, it only
13695 -- returns True if it knows for sure, it returns False if it knows
13696 -- there is a problem, or it cannot be sure there is no problem.
13698 procedure Reason_Bad_Component
(C
: Entity_Id
);
13699 -- Outputs continuation message if a reason can be determined for
13700 -- the component C being bad.
13702 ----------------------
13703 -- Check_Array_Type --
13704 ----------------------
13706 procedure Check_Array_Type
(Atyp
: Entity_Id
) is
13707 Ctyp
: constant Entity_Id
:= Component_Type
(Atyp
);
13710 -- OK if no alignment clause, no pack, and no component size
13712 if not Has_Component_Size_Clause
(Atyp
)
13713 and then not Has_Alignment_Clause
(Atyp
)
13714 and then not Is_Packed
(Atyp
)
13719 -- Case of component size is greater than or equal to 64 and the
13720 -- alignment of the array is at least as large as the alignment
13721 -- of the component. We are definitely OK in this situation.
13723 if Known_Component_Size
(Atyp
)
13724 and then Component_Size
(Atyp
) >= 64
13725 and then Known_Alignment
(Atyp
)
13726 and then Known_Alignment
(Ctyp
)
13727 and then Alignment
(Atyp
) >= Alignment
(Ctyp
)
13732 -- Check actual component size
13734 if not Known_Component_Size
(Atyp
)
13735 or else not (Addressable
(Component_Size
(Atyp
))
13736 and then Component_Size
(Atyp
) < 64)
13737 or else Component_Size
(Atyp
) mod Esize
(Ctyp
) /= 0
13741 -- Bad component size, check reason
13743 if Has_Component_Size_Clause
(Atyp
) then
13744 P
:= Get_Attribute_Definition_Clause
13745 (Atyp
, Attribute_Component_Size
);
13747 if Present
(P
) then
13748 Error_Msg_Sloc
:= Sloc
(P
);
13749 Error_Msg_N
("\because of Component_Size clause#", N
);
13754 if Is_Packed
(Atyp
) then
13755 P
:= Get_Rep_Pragma
(Atyp
, Name_Pack
);
13757 if Present
(P
) then
13758 Error_Msg_Sloc
:= Sloc
(P
);
13759 Error_Msg_N
("\because of pragma Pack#", N
);
13764 -- No reason found, just return
13769 -- Array type is OK independence-wise
13772 end Check_Array_Type
;
13774 ---------------------
13775 -- No_Independence --
13776 ---------------------
13778 procedure No_Independence
is
13780 if Pragma_Name
(N
) = Name_Independent
then
13781 Error_Msg_NE
("independence cannot be guaranteed for&", N
, E
);
13784 ("independent components cannot be guaranteed for&", N
, E
);
13786 end No_Independence
;
13792 function OK_Component
(C
: Entity_Id
) return Boolean is
13793 Rec
: constant Entity_Id
:= Scope
(C
);
13794 Ctyp
: constant Entity_Id
:= Etype
(C
);
13797 -- OK if no component clause, no Pack, and no alignment clause
13799 if No
(Component_Clause
(C
))
13800 and then not Is_Packed
(Rec
)
13801 and then not Has_Alignment_Clause
(Rec
)
13806 -- Here we look at the actual component layout. A component is
13807 -- addressable if its size is a multiple of the Esize of the
13808 -- component type, and its starting position in the record has
13809 -- appropriate alignment, and the record itself has appropriate
13810 -- alignment to guarantee the component alignment.
13812 -- Make sure sizes are static, always assume the worst for any
13813 -- cases where we cannot check static values.
13815 if not (Known_Static_Esize
(C
)
13817 Known_Static_Esize
(Ctyp
))
13822 -- Size of component must be addressable or greater than 64 bits
13823 -- and a multiple of bytes.
13825 if not Addressable
(Esize
(C
)) and then Esize
(C
) < Uint_64
then
13829 -- Check size is proper multiple
13831 if Esize
(C
) mod Esize
(Ctyp
) /= 0 then
13835 -- Check alignment of component is OK
13837 if not Known_Component_Bit_Offset
(C
)
13838 or else Component_Bit_Offset
(C
) < Uint_0
13839 or else Component_Bit_Offset
(C
) mod Esize
(Ctyp
) /= 0
13844 -- Check alignment of record type is OK
13846 if not Known_Alignment
(Rec
)
13847 or else (Alignment
(Rec
) * SU
) mod Esize
(Ctyp
) /= 0
13852 -- All tests passed, component is addressable
13857 --------------------------
13858 -- Reason_Bad_Component --
13859 --------------------------
13861 procedure Reason_Bad_Component
(C
: Entity_Id
) is
13862 Rec
: constant Entity_Id
:= Scope
(C
);
13863 Ctyp
: constant Entity_Id
:= Etype
(C
);
13866 -- If component clause present assume that's the problem
13868 if Present
(Component_Clause
(C
)) then
13869 Error_Msg_Sloc
:= Sloc
(Component_Clause
(C
));
13870 Error_Msg_N
("\because of Component_Clause#", N
);
13874 -- If pragma Pack clause present, assume that's the problem
13876 if Is_Packed
(Rec
) then
13877 P
:= Get_Rep_Pragma
(Rec
, Name_Pack
);
13879 if Present
(P
) then
13880 Error_Msg_Sloc
:= Sloc
(P
);
13881 Error_Msg_N
("\because of pragma Pack#", N
);
13886 -- See if record has bad alignment clause
13888 if Has_Alignment_Clause
(Rec
)
13889 and then Known_Alignment
(Rec
)
13890 and then (Alignment
(Rec
) * SU
) mod Esize
(Ctyp
) /= 0
13892 P
:= Get_Attribute_Definition_Clause
(Rec
, Attribute_Alignment
);
13894 if Present
(P
) then
13895 Error_Msg_Sloc
:= Sloc
(P
);
13896 Error_Msg_N
("\because of Alignment clause#", N
);
13900 -- Couldn't find a reason, so return without a message
13903 end Reason_Bad_Component
;
13905 -- Start of processing for Validate_Independence
13908 for J
in Independence_Checks
.First
.. Independence_Checks
.Last
loop
13909 N
:= Independence_Checks
.Table
(J
).N
;
13910 E
:= Independence_Checks
.Table
(J
).E
;
13911 IC
:= Pragma_Name
(N
) = Name_Independent_Components
;
13913 -- Deal with component case
13915 if Ekind
(E
) = E_Discriminant
or else Ekind
(E
) = E_Component
then
13916 if not OK_Component
(E
) then
13918 Reason_Bad_Component
(E
);
13923 -- Deal with record with Independent_Components
13925 if IC
and then Is_Record_Type
(E
) then
13926 Comp
:= First_Component_Or_Discriminant
(E
);
13927 while Present
(Comp
) loop
13928 if not OK_Component
(Comp
) then
13930 Reason_Bad_Component
(Comp
);
13934 Next_Component_Or_Discriminant
(Comp
);
13938 -- Deal with address clause case
13940 if Is_Object
(E
) then
13941 Addr
:= Address_Clause
(E
);
13943 if Present
(Addr
) then
13945 Error_Msg_Sloc
:= Sloc
(Addr
);
13946 Error_Msg_N
("\because of Address clause#", N
);
13951 -- Deal with independent components for array type
13953 if IC
and then Is_Array_Type
(E
) then
13954 Check_Array_Type
(E
);
13957 -- Deal with independent components for array object
13959 if IC
and then Is_Object
(E
) and then Is_Array_Type
(Etype
(E
)) then
13960 Check_Array_Type
(Etype
(E
));
13965 end Validate_Independence
;
13967 ------------------------------
13968 -- Validate_Iterable_Aspect --
13969 ------------------------------
13971 procedure Validate_Iterable_Aspect
(Typ
: Entity_Id
; ASN
: Node_Id
) is
13976 Cursor
: constant Entity_Id
:= Get_Cursor_Type
(ASN
, Typ
);
13978 First_Id
: Entity_Id
;
13979 Next_Id
: Entity_Id
;
13980 Has_Element_Id
: Entity_Id
;
13981 Element_Id
: Entity_Id
;
13984 -- If previous error aspect is unusable
13986 if Cursor
= Any_Type
then
13992 Has_Element_Id
:= Empty
;
13993 Element_Id
:= Empty
;
13995 -- Each expression must resolve to a function with the proper signature
13997 Assoc
:= First
(Component_Associations
(Expression
(ASN
)));
13998 while Present
(Assoc
) loop
13999 Expr
:= Expression
(Assoc
);
14002 Prim
:= First
(Choices
(Assoc
));
14004 if Nkind
(Prim
) /= N_Identifier
or else Present
(Next
(Prim
)) then
14005 Error_Msg_N
("illegal name in association", Prim
);
14007 elsif Chars
(Prim
) = Name_First
then
14008 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_First
);
14009 First_Id
:= Entity
(Expr
);
14011 elsif Chars
(Prim
) = Name_Next
then
14012 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_Next
);
14013 Next_Id
:= Entity
(Expr
);
14015 elsif Chars
(Prim
) = Name_Has_Element
then
14016 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_Has_Element
);
14017 Has_Element_Id
:= Entity
(Expr
);
14019 elsif Chars
(Prim
) = Name_Element
then
14020 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_Element
);
14021 Element_Id
:= Entity
(Expr
);
14024 Error_Msg_N
("invalid name for iterable function", Prim
);
14030 if No
(First_Id
) then
14031 Error_Msg_N
("match for First primitive not found", ASN
);
14033 elsif No
(Next_Id
) then
14034 Error_Msg_N
("match for Next primitive not found", ASN
);
14036 elsif No
(Has_Element_Id
) then
14037 Error_Msg_N
("match for Has_Element primitive not found", ASN
);
14039 elsif No
(Element_Id
) then
14042 end Validate_Iterable_Aspect
;
14044 -----------------------------------
14045 -- Validate_Unchecked_Conversion --
14046 -----------------------------------
14048 procedure Validate_Unchecked_Conversion
14050 Act_Unit
: Entity_Id
)
14052 Source
: Entity_Id
;
14053 Target
: Entity_Id
;
14057 -- Obtain source and target types. Note that we call Ancestor_Subtype
14058 -- here because the processing for generic instantiation always makes
14059 -- subtypes, and we want the original frozen actual types.
14061 -- If we are dealing with private types, then do the check on their
14062 -- fully declared counterparts if the full declarations have been
14063 -- encountered (they don't have to be visible, but they must exist).
14065 Source
:= Ancestor_Subtype
(Etype
(First_Formal
(Act_Unit
)));
14067 if Is_Private_Type
(Source
)
14068 and then Present
(Underlying_Type
(Source
))
14070 Source
:= Underlying_Type
(Source
);
14073 Target
:= Ancestor_Subtype
(Etype
(Act_Unit
));
14075 -- If either type is generic, the instantiation happens within a generic
14076 -- unit, and there is nothing to check. The proper check will happen
14077 -- when the enclosing generic is instantiated.
14079 if Is_Generic_Type
(Source
) or else Is_Generic_Type
(Target
) then
14083 if Is_Private_Type
(Target
)
14084 and then Present
(Underlying_Type
(Target
))
14086 Target
:= Underlying_Type
(Target
);
14089 -- Source may be unconstrained array, but not target, except in relaxed
14092 if Is_Array_Type
(Target
)
14093 and then not Is_Constrained
(Target
)
14094 and then not Relaxed_RM_Semantics
14097 ("unchecked conversion to unconstrained array not allowed", N
);
14101 -- Warn if conversion between two different convention pointers
14103 if Is_Access_Type
(Target
)
14104 and then Is_Access_Type
(Source
)
14105 and then Convention
(Target
) /= Convention
(Source
)
14106 and then Warn_On_Unchecked_Conversion
14108 -- Give warnings for subprogram pointers only on most targets
14110 if Is_Access_Subprogram_Type
(Target
)
14111 or else Is_Access_Subprogram_Type
(Source
)
14114 ("?z?conversion between pointers with different conventions!",
14119 -- Warn if one of the operands is Ada.Calendar.Time. Do not emit a
14120 -- warning when compiling GNAT-related sources.
14122 if Warn_On_Unchecked_Conversion
14123 and then not In_Predefined_Unit
(N
)
14124 and then RTU_Loaded
(Ada_Calendar
)
14125 and then (Chars
(Source
) = Name_Time
14127 Chars
(Target
) = Name_Time
)
14129 -- If Ada.Calendar is loaded and the name of one of the operands is
14130 -- Time, there is a good chance that this is Ada.Calendar.Time.
14133 Calendar_Time
: constant Entity_Id
:= Full_View
(RTE
(RO_CA_Time
));
14135 pragma Assert
(Present
(Calendar_Time
));
14137 if Source
= Calendar_Time
or else Target
= Calendar_Time
then
14139 ("?z?representation of 'Time values may change between "
14140 & "'G'N'A'T versions", N
);
14145 -- Make entry in unchecked conversion table for later processing by
14146 -- Validate_Unchecked_Conversions, which will check sizes and alignments
14147 -- (using values set by the back end where possible). This is only done
14148 -- if the appropriate warning is active.
14150 if Warn_On_Unchecked_Conversion
then
14151 Unchecked_Conversions
.Append
14152 (New_Val
=> UC_Entry
'(Eloc => Sloc (N),
14155 Act_Unit => Act_Unit));
14157 -- If both sizes are known statically now, then back end annotation
14158 -- is not required to do a proper check but if either size is not
14159 -- known statically, then we need the annotation.
14161 if Known_Static_RM_Size (Source)
14163 Known_Static_RM_Size (Target)
14167 Back_Annotate_Rep_Info := True;
14171 -- If unchecked conversion to access type, and access type is declared
14172 -- in the same unit as the unchecked conversion, then set the flag
14173 -- No_Strict_Aliasing (no strict aliasing is implicit here)
14175 if Is_Access_Type (Target) and then
14176 In_Same_Source_Unit (Target, N)
14178 Set_No_Strict_Aliasing (Implementation_Base_Type (Target));
14181 -- Generate N_Validate_Unchecked_Conversion node for back end in case
14182 -- the back end needs to perform special validation checks.
14184 -- Shouldn't this be in Exp_Ch13, since the check only gets done if we
14185 -- have full expansion and the back end is called ???
14188 Make_Validate_Unchecked_Conversion (Sloc (N));
14189 Set_Source_Type (Vnode, Source);
14190 Set_Target_Type (Vnode, Target);
14192 -- If the unchecked conversion node is in a list, just insert before it.
14193 -- If not we have some strange case, not worth bothering about.
14195 if Is_List_Member (N) then
14196 Insert_After (N, Vnode);
14198 end Validate_Unchecked_Conversion;
14200 ------------------------------------
14201 -- Validate_Unchecked_Conversions --
14202 ------------------------------------
14204 procedure Validate_Unchecked_Conversions is
14206 for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop
14208 T : UC_Entry renames Unchecked_Conversions.Table (N);
14210 Eloc : constant Source_Ptr := T.Eloc;
14211 Source : constant Entity_Id := T.Source;
14212 Target : constant Entity_Id := T.Target;
14213 Act_Unit : constant Entity_Id := T.Act_Unit;
14219 -- Skip if function marked as warnings off
14221 if Warnings_Off (Act_Unit) then
14225 -- This validation check, which warns if we have unequal sizes for
14226 -- unchecked conversion, and thus potentially implementation
14227 -- dependent semantics, is one of the few occasions on which we
14228 -- use the official RM size instead of Esize. See description in
14229 -- Einfo "Handling of Type'Size Values" for details.
14231 if Serious_Errors_Detected = 0
14232 and then Known_Static_RM_Size (Source)
14233 and then Known_Static_RM_Size (Target)
14235 -- Don't do the check if warnings off for either type, note the
14236 -- deliberate use of OR here instead of OR ELSE to get the flag
14237 -- Warnings_Off_Used set for both types if appropriate.
14239 and then not (Has_Warnings_Off (Source)
14241 Has_Warnings_Off (Target))
14243 Source_Siz := RM_Size (Source);
14244 Target_Siz := RM_Size (Target);
14246 if Source_Siz /= Target_Siz then
14248 ("?z?types for unchecked conversion have different sizes!",
14251 if All_Errors_Mode then
14252 Error_Msg_Name_1 := Chars (Source);
14253 Error_Msg_Uint_1 := Source_Siz;
14254 Error_Msg_Name_2 := Chars (Target);
14255 Error_Msg_Uint_2 := Target_Siz;
14256 Error_Msg ("\size of % is ^, size of % is ^?z?", Eloc);
14258 Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz);
14260 if Is_Discrete_Type (Source)
14262 Is_Discrete_Type (Target)
14264 if Source_Siz > Target_Siz then
14266 ("\?z?^ high order bits of source will "
14267 & "be ignored!", Eloc);
14269 elsif Is_Unsigned_Type (Source) then
14271 ("\?z?source will be extended with ^ high order "
14272 & "zero bits!", Eloc);
14276 ("\?z?source will be extended with ^ high order "
14277 & "sign bits!", Eloc);
14280 elsif Source_Siz < Target_Siz then
14281 if Is_Discrete_Type (Target) then
14282 if Bytes_Big_Endian then
14284 ("\?z?target value will include ^ undefined "
14285 & "low order bits!", Eloc);
14288 ("\?z?target value will include ^ undefined "
14289 & "high order bits!", Eloc);
14294 ("\?z?^ trailing bits of target value will be "
14295 & "undefined!", Eloc);
14298 else pragma Assert (Source_Siz > Target_Siz);
14299 if Is_Discrete_Type (Source) then
14300 if Bytes_Big_Endian then
14302 ("\?z?^ low order bits of source will be "
14303 & "ignored!", Eloc);
14306 ("\?z?^ high order bits of source will be "
14307 & "ignored!", Eloc);
14312 ("\?z?^ trailing bits of source will be "
14313 & "ignored!", Eloc);
14320 -- If both types are access types, we need to check the alignment.
14321 -- If the alignment of both is specified, we can do it here.
14323 if Serious_Errors_Detected = 0
14324 and then Is_Access_Type (Source)
14325 and then Is_Access_Type (Target)
14326 and then Target_Strict_Alignment
14327 and then Present (Designated_Type (Source))
14328 and then Present (Designated_Type (Target))
14331 D_Source : constant Entity_Id := Designated_Type (Source);
14332 D_Target : constant Entity_Id := Designated_Type (Target);
14335 if Known_Alignment (D_Source)
14337 Known_Alignment (D_Target)
14340 Source_Align : constant Uint := Alignment (D_Source);
14341 Target_Align : constant Uint := Alignment (D_Target);
14344 if Source_Align < Target_Align
14345 and then not Is_Tagged_Type (D_Source)
14347 -- Suppress warning if warnings suppressed on either
14348 -- type or either designated type. Note the use of
14349 -- OR here instead of OR ELSE. That is intentional,
14350 -- we would like to set flag Warnings_Off_Used in
14351 -- all types for which warnings are suppressed.
14353 and then not (Has_Warnings_Off (D_Source)
14355 Has_Warnings_Off (D_Target)
14357 Has_Warnings_Off (Source)
14359 Has_Warnings_Off (Target))
14361 Error_Msg_Uint_1 := Target_Align;
14362 Error_Msg_Uint_2 := Source_Align;
14363 Error_Msg_Node_1 := D_Target;
14364 Error_Msg_Node_2 := D_Source;
14366 ("?z?alignment of & (^) is stricter than "
14367 & "alignment of & (^)!", Eloc);
14369 ("\?z?resulting access value may have invalid "
14370 & "alignment!", Eloc);
14381 end Validate_Unchecked_Conversions;