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
4325 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 for overloaded "
4762 & "subprogram", Nam
);
4766 -- For subprograms, all address clauses are permitted, and we
4767 -- mark the subprogram as having a deferred freeze so that Gigi
4768 -- will not elaborate it too soon.
4770 -- Above needs more comments, what is too soon about???
4772 Set_Has_Delayed_Freeze
(U_Ent
);
4774 -- Case of address clause for entry
4776 elsif Ekind
(U_Ent
) = E_Entry
then
4777 if Nkind
(Parent
(N
)) = N_Task_Body
then
4779 ("entry address must be specified in task spec", Nam
);
4783 -- For entries, we require a constant address
4785 Check_Constant_Address_Clause
(Expr
, U_Ent
);
4787 -- Special checks for task types
4789 if Is_Task_Type
(Scope
(U_Ent
))
4790 and then Comes_From_Source
(Scope
(U_Ent
))
4793 ("??entry address declared for entry in task type", N
);
4795 ("\??only one task can be declared of this type", N
);
4798 -- Entry address clauses are obsolescent
4800 Check_Restriction
(No_Obsolescent_Features
, N
);
4802 if Warn_On_Obsolescent_Feature
then
4804 ("?j?attaching interrupt to task entry is an obsolescent "
4805 & "feature (RM J.7.1)", N
);
4807 ("\?j?use interrupt procedure instead", N
);
4810 -- Case of an address clause for a controlled object which we
4811 -- consider to be erroneous.
4813 elsif Is_Controlled
(Etype
(U_Ent
))
4814 or else Has_Controlled_Component
(Etype
(U_Ent
))
4817 ("??controlled object& must not be overlaid", Nam
, U_Ent
);
4819 ("\??Program_Error will be raised at run time", Nam
);
4820 Insert_Action
(Declaration_Node
(U_Ent
),
4821 Make_Raise_Program_Error
(Loc
,
4822 Reason
=> PE_Overlaid_Controlled_Object
));
4825 -- Case of address clause for a (non-controlled) object
4827 elsif Ekind_In
(U_Ent
, E_Variable
, E_Constant
) then
4829 Expr
: constant Node_Id
:= Expression
(N
);
4834 -- Exported variables cannot have an address clause, because
4835 -- this cancels the effect of the pragma Export.
4837 if Is_Exported
(U_Ent
) then
4839 ("cannot export object with address clause", Nam
);
4843 Find_Overlaid_Entity
(N
, O_Ent
, Off
);
4845 if Present
(O_Ent
) then
4847 -- If the object overlays a constant object, mark it so
4849 if Is_Constant_Object
(O_Ent
) then
4850 Set_Overlays_Constant
(U_Ent
);
4854 -- If this is not an overlay, mark a variable as being
4855 -- volatile to prevent unwanted optimizations. It's a
4856 -- conservative interpretation of RM 13.3(19) for the
4857 -- cases where the compiler cannot detect potential
4858 -- aliasing issues easily and it also covers the case
4859 -- of an absolute address where the volatile aspect is
4860 -- kind of implicit.
4862 if Ekind
(U_Ent
) = E_Variable
then
4863 Set_Treat_As_Volatile
(U_Ent
);
4867 -- Overlaying controlled objects is erroneous. Emit warning
4868 -- but continue analysis because program is itself legal,
4869 -- and back end must see address clause.
4872 and then (Has_Controlled_Component
(Etype
(O_Ent
))
4873 or else Is_Controlled
(Etype
(O_Ent
)))
4874 and then not Inside_A_Generic
4877 ("??cannot use overlays with controlled objects", Expr
);
4879 ("\??Program_Error will be raised at run time", Expr
);
4880 Insert_Action
(Declaration_Node
(U_Ent
),
4881 Make_Raise_Program_Error
(Loc
,
4882 Reason
=> PE_Overlaid_Controlled_Object
));
4884 -- Issue an unconditional warning for a constant overlaying
4885 -- a variable. For the reverse case, we will issue it only
4886 -- if the variable is modified.
4888 elsif Ekind
(U_Ent
) = E_Constant
4889 and then Present
(O_Ent
)
4890 and then not Overlays_Constant
(U_Ent
)
4891 and then Address_Clause_Overlay_Warnings
4893 Error_Msg_N
("??constant overlays a variable", Expr
);
4895 -- Imported variables can have an address clause, but then
4896 -- the import is pretty meaningless except to suppress
4897 -- initializations, so we do not need such variables to
4898 -- be statically allocated (and in fact it causes trouble
4899 -- if the address clause is a local value).
4901 elsif Is_Imported
(U_Ent
) then
4902 Set_Is_Statically_Allocated
(U_Ent
, False);
4905 -- We mark a possible modification of a variable with an
4906 -- address clause, since it is likely aliasing is occurring.
4908 Note_Possible_Modification
(Nam
, Sure
=> False);
4910 -- Legality checks on the address clause for initialized
4911 -- objects is deferred until the freeze point, because
4912 -- a subsequent pragma might indicate that the object
4913 -- is imported and thus not initialized. Also, the address
4914 -- clause might involve entities that have yet to be
4917 Set_Has_Delayed_Freeze
(U_Ent
);
4919 -- If an initialization call has been generated for this
4920 -- object, it needs to be deferred to after the freeze node
4921 -- we have just now added, otherwise GIGI will see a
4922 -- reference to the variable (as actual to the IP call)
4923 -- before its definition.
4926 Init_Call
: constant Node_Id
:=
4927 Remove_Init_Call
(U_Ent
, N
);
4930 if Present
(Init_Call
) then
4931 Append_Freeze_Action
(U_Ent
, Init_Call
);
4933 -- Reset Initialization_Statements pointer so that
4934 -- if there is a pragma Import further down, it can
4935 -- clear any default initialization.
4937 Set_Initialization_Statements
(U_Ent
, Init_Call
);
4941 -- Entity has delayed freeze, so we will generate an
4942 -- alignment check at the freeze point unless suppressed.
4944 if not Range_Checks_Suppressed
(U_Ent
)
4945 and then not Alignment_Checks_Suppressed
(U_Ent
)
4947 Set_Check_Address_Alignment
(N
);
4950 -- Kill the size check code, since we are not allocating
4951 -- the variable, it is somewhere else.
4953 Kill_Size_Check_Code
(U_Ent
);
4955 -- If the address clause is of the form:
4957 -- for Y'Address use X'Address
4961 -- Const : constant Address := X'Address;
4963 -- for Y'Address use Const;
4965 -- then we make an entry in the table for checking the size
4966 -- and alignment of the overlaying variable. We defer this
4967 -- check till after code generation to take full advantage
4968 -- of the annotation done by the back end.
4970 -- If the entity has a generic type, the check will be
4971 -- performed in the instance if the actual type justifies
4972 -- it, and we do not insert the clause in the table to
4973 -- prevent spurious warnings.
4975 -- Note: we used to test Comes_From_Source and only give
4976 -- this warning for source entities, but we have removed
4977 -- this test. It really seems bogus to generate overlays
4978 -- that would trigger this warning in generated code.
4979 -- Furthermore, by removing the test, we handle the
4980 -- aspect case properly.
4983 and then Is_Object
(O_Ent
)
4984 and then not Is_Generic_Type
(Etype
(U_Ent
))
4985 and then Address_Clause_Overlay_Warnings
4987 Address_Clause_Checks
.Append
((N
, U_Ent
, O_Ent
, Off
));
4991 -- Not a valid entity for an address clause
4994 Error_Msg_N
("address cannot be given for &", Nam
);
5002 -- Alignment attribute definition clause
5004 when Attribute_Alignment
=> Alignment
: declare
5005 Align
: constant Uint
:= Get_Alignment_Value
(Expr
);
5006 Max_Align
: constant Uint
:= UI_From_Int
(Maximum_Alignment
);
5011 if not Is_Type
(U_Ent
)
5012 and then Ekind
(U_Ent
) /= E_Variable
5013 and then Ekind
(U_Ent
) /= E_Constant
5015 Error_Msg_N
("alignment cannot be given for &", Nam
);
5017 elsif Duplicate_Clause
then
5020 elsif Align
/= No_Uint
then
5021 Set_Has_Alignment_Clause
(U_Ent
);
5023 -- Tagged type case, check for attempt to set alignment to a
5024 -- value greater than Max_Align, and reset if so. This error
5025 -- is suppressed in ASIS mode to allow for different ASIS
5026 -- back ends or ASIS-based tools to query the illegal clause.
5028 if Is_Tagged_Type
(U_Ent
)
5029 and then Align
> Max_Align
5030 and then not ASIS_Mode
5033 ("alignment for & set to Maximum_Aligment??", Nam
);
5034 Set_Alignment
(U_Ent
, Max_Align
);
5039 Set_Alignment
(U_Ent
, Align
);
5042 -- For an array type, U_Ent is the first subtype. In that case,
5043 -- also set the alignment of the anonymous base type so that
5044 -- other subtypes (such as the itypes for aggregates of the
5045 -- type) also receive the expected alignment.
5047 if Is_Array_Type
(U_Ent
) then
5048 Set_Alignment
(Base_Type
(U_Ent
), Align
);
5057 -- Bit_Order attribute definition clause
5059 when Attribute_Bit_Order
=> Bit_Order
: declare
5061 if not Is_Record_Type
(U_Ent
) then
5063 ("Bit_Order can only be defined for record type", Nam
);
5065 elsif Duplicate_Clause
then
5069 Analyze_And_Resolve
(Expr
, RTE
(RE_Bit_Order
));
5071 if Etype
(Expr
) = Any_Type
then
5074 elsif not Is_OK_Static_Expression
(Expr
) then
5075 Flag_Non_Static_Expr
5076 ("Bit_Order requires static expression!", Expr
);
5079 if (Expr_Value
(Expr
) = 0) /= Bytes_Big_Endian
then
5080 Set_Reverse_Bit_Order
(Base_Type
(U_Ent
), True);
5086 --------------------
5087 -- Component_Size --
5088 --------------------
5090 -- Component_Size attribute definition clause
5092 when Attribute_Component_Size
=> Component_Size_Case
: declare
5093 Csize
: constant Uint
:= Static_Integer
(Expr
);
5097 New_Ctyp
: Entity_Id
;
5101 if not Is_Array_Type
(U_Ent
) then
5102 Error_Msg_N
("component size requires array type", Nam
);
5106 Btype
:= Base_Type
(U_Ent
);
5107 Ctyp
:= Component_Type
(Btype
);
5109 if Duplicate_Clause
then
5112 elsif Rep_Item_Too_Early
(Btype
, N
) then
5115 elsif Csize
/= No_Uint
then
5116 Check_Size
(Expr
, Ctyp
, Csize
, Biased
);
5118 -- For the biased case, build a declaration for a subtype that
5119 -- will be used to represent the biased subtype that reflects
5120 -- the biased representation of components. We need the subtype
5121 -- to get proper conversions on referencing elements of the
5126 Make_Defining_Identifier
(Loc
,
5128 New_External_Name
(Chars
(U_Ent
), 'C', 0, 'T'));
5131 Make_Subtype_Declaration
(Loc
,
5132 Defining_Identifier
=> New_Ctyp
,
5133 Subtype_Indication
=>
5134 New_Occurrence_Of
(Component_Type
(Btype
), Loc
));
5136 Set_Parent
(Decl
, N
);
5137 Analyze
(Decl
, Suppress
=> All_Checks
);
5139 Set_Has_Delayed_Freeze
(New_Ctyp
, False);
5140 Set_Esize
(New_Ctyp
, Csize
);
5141 Set_RM_Size
(New_Ctyp
, Csize
);
5142 Init_Alignment
(New_Ctyp
);
5143 Set_Is_Itype
(New_Ctyp
, True);
5144 Set_Associated_Node_For_Itype
(New_Ctyp
, U_Ent
);
5146 Set_Component_Type
(Btype
, New_Ctyp
);
5147 Set_Biased
(New_Ctyp
, N
, "component size clause");
5150 Set_Component_Size
(Btype
, Csize
);
5152 -- Deal with warning on overridden size
5154 if Warn_On_Overridden_Size
5155 and then Has_Size_Clause
(Ctyp
)
5156 and then RM_Size
(Ctyp
) /= Csize
5159 ("component size overrides size clause for&?S?", N
, Ctyp
);
5162 Set_Has_Component_Size_Clause
(Btype
, True);
5163 Set_Has_Non_Standard_Rep
(Btype
, True);
5165 end Component_Size_Case
;
5167 -----------------------
5168 -- Constant_Indexing --
5169 -----------------------
5171 when Attribute_Constant_Indexing
=>
5172 Check_Indexing_Functions
;
5178 when Attribute_CPU
=> CPU
:
5180 -- CPU attribute definition clause not allowed except from aspect
5183 if From_Aspect_Specification
(N
) then
5184 if not Is_Task_Type
(U_Ent
) then
5185 Error_Msg_N
("CPU can only be defined for task", Nam
);
5187 elsif Duplicate_Clause
then
5191 -- The expression must be analyzed in the special manner
5192 -- described in "Handling of Default and Per-Object
5193 -- Expressions" in sem.ads.
5195 -- The visibility to the discriminants must be restored
5197 Push_Scope_And_Install_Discriminants
(U_Ent
);
5198 Preanalyze_Spec_Expression
(Expr
, RTE
(RE_CPU_Range
));
5199 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
5201 if not Is_OK_Static_Expression
(Expr
) then
5202 Check_Restriction
(Static_Priorities
, Expr
);
5208 ("attribute& cannot be set with definition clause", N
);
5212 ----------------------
5213 -- Default_Iterator --
5214 ----------------------
5216 when Attribute_Default_Iterator
=> Default_Iterator
: declare
5221 -- If target type is untagged, further checks are irrelevant
5223 if not Is_Tagged_Type
(U_Ent
) then
5225 ("aspect Default_Iterator applies to tagged type", Nam
);
5229 Check_Iterator_Functions
;
5233 if not Is_Entity_Name
(Expr
)
5234 or else Ekind
(Entity
(Expr
)) /= E_Function
5236 Error_Msg_N
("aspect Iterator must be a function", Expr
);
5239 Func
:= Entity
(Expr
);
5242 -- The type of the first parameter must be T, T'class, or a
5243 -- corresponding access type (5.5.1 (8/3). If function is
5244 -- parameterless label type accordingly.
5246 if No
(First_Formal
(Func
)) then
5249 Typ
:= Etype
(First_Formal
(Func
));
5253 or else Typ
= Class_Wide_Type
(U_Ent
)
5254 or else (Is_Access_Type
(Typ
)
5255 and then Designated_Type
(Typ
) = U_Ent
)
5256 or else (Is_Access_Type
(Typ
)
5257 and then Designated_Type
(Typ
) =
5258 Class_Wide_Type
(U_Ent
))
5264 ("Default Iterator must be a primitive of&", Func
, U_Ent
);
5266 end Default_Iterator
;
5268 ------------------------
5269 -- Dispatching_Domain --
5270 ------------------------
5272 when Attribute_Dispatching_Domain
=> Dispatching_Domain
:
5274 -- Dispatching_Domain attribute definition clause not allowed
5275 -- except from aspect specification.
5277 if From_Aspect_Specification
(N
) then
5278 if not Is_Task_Type
(U_Ent
) then
5280 ("Dispatching_Domain can only be defined for task", Nam
);
5282 elsif Duplicate_Clause
then
5286 -- The expression must be analyzed in the special manner
5287 -- described in "Handling of Default and Per-Object
5288 -- Expressions" in sem.ads.
5290 -- The visibility to the discriminants must be restored
5292 Push_Scope_And_Install_Discriminants
(U_Ent
);
5294 Preanalyze_Spec_Expression
5295 (Expr
, RTE
(RE_Dispatching_Domain
));
5297 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
5302 ("attribute& cannot be set with definition clause", N
);
5304 end Dispatching_Domain
;
5310 when Attribute_External_Tag
=> External_Tag
:
5312 if not Is_Tagged_Type
(U_Ent
) then
5313 Error_Msg_N
("should be a tagged type", Nam
);
5316 if Duplicate_Clause
then
5320 Analyze_And_Resolve
(Expr
, Standard_String
);
5322 if not Is_OK_Static_Expression
(Expr
) then
5323 Flag_Non_Static_Expr
5324 ("static string required for tag name!", Nam
);
5327 if not Is_Library_Level_Entity
(U_Ent
) then
5329 ("??non-unique external tag supplied for &", N
, U_Ent
);
5331 ("\??same external tag applies to all subprogram calls",
5334 ("\??corresponding internal tag cannot be obtained", N
);
5339 --------------------------
5340 -- Implicit_Dereference --
5341 --------------------------
5343 when Attribute_Implicit_Dereference
=>
5345 -- Legality checks already performed at the point of the type
5346 -- declaration, aspect is not delayed.
5354 when Attribute_Input
=>
5355 Analyze_Stream_TSS_Definition
(TSS_Stream_Input
);
5356 Set_Has_Specified_Stream_Input
(Ent
);
5358 ------------------------
5359 -- Interrupt_Priority --
5360 ------------------------
5362 when Attribute_Interrupt_Priority
=> Interrupt_Priority
:
5364 -- Interrupt_Priority attribute definition clause not allowed
5365 -- except from aspect specification.
5367 if From_Aspect_Specification
(N
) then
5368 if not Is_Concurrent_Type
(U_Ent
) then
5370 ("Interrupt_Priority can only be defined for task and "
5371 & "protected object", Nam
);
5373 elsif Duplicate_Clause
then
5377 -- The expression must be analyzed in the special manner
5378 -- described in "Handling of Default and Per-Object
5379 -- Expressions" in sem.ads.
5381 -- The visibility to the discriminants must be restored
5383 Push_Scope_And_Install_Discriminants
(U_Ent
);
5385 Preanalyze_Spec_Expression
5386 (Expr
, RTE
(RE_Interrupt_Priority
));
5388 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
5390 -- Check the No_Task_At_Interrupt_Priority restriction
5392 if Is_Task_Type
(U_Ent
) then
5393 Check_Restriction
(No_Task_At_Interrupt_Priority
, N
);
5399 ("attribute& cannot be set with definition clause", N
);
5401 end Interrupt_Priority
;
5407 when Attribute_Iterable
=>
5410 if Nkind
(Expr
) /= N_Aggregate
then
5411 Error_Msg_N
("aspect Iterable must be an aggregate", Expr
);
5418 Assoc
:= First
(Component_Associations
(Expr
));
5419 while Present
(Assoc
) loop
5420 if not Is_Entity_Name
(Expression
(Assoc
)) then
5421 Error_Msg_N
("value must be a function", Assoc
);
5428 ----------------------
5429 -- Iterator_Element --
5430 ----------------------
5432 when Attribute_Iterator_Element
=>
5435 if not Is_Entity_Name
(Expr
)
5436 or else not Is_Type
(Entity
(Expr
))
5438 Error_Msg_N
("aspect Iterator_Element must be a type", Expr
);
5445 -- Machine radix attribute definition clause
5447 when Attribute_Machine_Radix
=> Machine_Radix
: declare
5448 Radix
: constant Uint
:= Static_Integer
(Expr
);
5451 if not Is_Decimal_Fixed_Point_Type
(U_Ent
) then
5452 Error_Msg_N
("decimal fixed-point type expected for &", Nam
);
5454 elsif Duplicate_Clause
then
5457 elsif Radix
/= No_Uint
then
5458 Set_Has_Machine_Radix_Clause
(U_Ent
);
5459 Set_Has_Non_Standard_Rep
(Base_Type
(U_Ent
));
5464 elsif Radix
= 10 then
5465 Set_Machine_Radix_10
(U_Ent
);
5467 -- The following error is suppressed in ASIS mode to allow for
5468 -- different ASIS back ends or ASIS-based tools to query the
5471 elsif not ASIS_Mode
then
5472 Error_Msg_N
("machine radix value must be 2 or 10", Expr
);
5481 -- Object_Size attribute definition clause
5483 when Attribute_Object_Size
=> Object_Size
: declare
5484 Size
: constant Uint
:= Static_Integer
(Expr
);
5487 pragma Warnings
(Off
, Biased
);
5490 if not Is_Type
(U_Ent
) then
5491 Error_Msg_N
("Object_Size cannot be given for &", Nam
);
5493 elsif Duplicate_Clause
then
5497 Check_Size
(Expr
, U_Ent
, Size
, Biased
);
5499 -- The following errors are suppressed in ASIS mode to allow
5500 -- for different ASIS back ends or ASIS-based tools to query
5501 -- the illegal clause.
5506 elsif Is_Scalar_Type
(U_Ent
) then
5507 if Size
/= 8 and then Size
/= 16 and then Size
/= 32
5508 and then UI_Mod
(Size
, 64) /= 0
5511 ("Object_Size must be 8, 16, 32, or multiple of 64",
5515 elsif Size
mod 8 /= 0 then
5516 Error_Msg_N
("Object_Size must be a multiple of 8", Expr
);
5519 Set_Esize
(U_Ent
, Size
);
5520 Set_Has_Object_Size_Clause
(U_Ent
);
5521 Alignment_Check_For_Size_Change
(U_Ent
, Size
);
5529 when Attribute_Output
=>
5530 Analyze_Stream_TSS_Definition
(TSS_Stream_Output
);
5531 Set_Has_Specified_Stream_Output
(Ent
);
5537 when Attribute_Priority
=> Priority
:
5539 -- Priority attribute definition clause not allowed except from
5540 -- aspect specification.
5542 if From_Aspect_Specification
(N
) then
5543 if not (Is_Concurrent_Type
(U_Ent
)
5544 or else Ekind
(U_Ent
) = E_Procedure
)
5547 ("Priority can only be defined for task and protected "
5550 elsif Duplicate_Clause
then
5554 -- The expression must be analyzed in the special manner
5555 -- described in "Handling of Default and Per-Object
5556 -- Expressions" in sem.ads.
5558 -- The visibility to the discriminants must be restored
5560 Push_Scope_And_Install_Discriminants
(U_Ent
);
5561 Preanalyze_Spec_Expression
(Expr
, Standard_Integer
);
5562 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
5564 if not Is_OK_Static_Expression
(Expr
) then
5565 Check_Restriction
(Static_Priorities
, Expr
);
5571 ("attribute& cannot be set with definition clause", N
);
5579 when Attribute_Read
=>
5580 Analyze_Stream_TSS_Definition
(TSS_Stream_Read
);
5581 Set_Has_Specified_Stream_Read
(Ent
);
5583 --------------------------
5584 -- Scalar_Storage_Order --
5585 --------------------------
5587 -- Scalar_Storage_Order attribute definition clause
5589 when Attribute_Scalar_Storage_Order
=> Scalar_Storage_Order
: declare
5591 if not (Is_Record_Type
(U_Ent
) or else Is_Array_Type
(U_Ent
)) then
5593 ("Scalar_Storage_Order can only be defined for record or "
5594 & "array type", Nam
);
5596 elsif Duplicate_Clause
then
5600 Analyze_And_Resolve
(Expr
, RTE
(RE_Bit_Order
));
5602 if Etype
(Expr
) = Any_Type
then
5605 elsif not Is_OK_Static_Expression
(Expr
) then
5606 Flag_Non_Static_Expr
5607 ("Scalar_Storage_Order requires static expression!", Expr
);
5609 elsif (Expr_Value
(Expr
) = 0) /= Bytes_Big_Endian
then
5611 -- Here for the case of a non-default (i.e. non-confirming)
5612 -- Scalar_Storage_Order attribute definition.
5614 if Support_Nondefault_SSO_On_Target
then
5615 Set_Reverse_Storage_Order
(Base_Type
(U_Ent
), True);
5618 ("non-default Scalar_Storage_Order not supported on "
5623 -- Clear SSO default indications since explicit setting of the
5624 -- order overrides the defaults.
5626 Set_SSO_Set_Low_By_Default
(Base_Type
(U_Ent
), False);
5627 Set_SSO_Set_High_By_Default
(Base_Type
(U_Ent
), False);
5629 end Scalar_Storage_Order
;
5635 -- Size attribute definition clause
5637 when Attribute_Size
=> Size
: declare
5638 Size
: constant Uint
:= Static_Integer
(Expr
);
5645 if Duplicate_Clause
then
5648 elsif not Is_Type
(U_Ent
)
5649 and then Ekind
(U_Ent
) /= E_Variable
5650 and then Ekind
(U_Ent
) /= E_Constant
5652 Error_Msg_N
("size cannot be given for &", Nam
);
5654 elsif Is_Array_Type
(U_Ent
)
5655 and then not Is_Constrained
(U_Ent
)
5658 ("size cannot be given for unconstrained array", Nam
);
5660 elsif Size
/= No_Uint
then
5661 if Is_Type
(U_Ent
) then
5664 Etyp
:= Etype
(U_Ent
);
5667 -- Check size, note that Gigi is in charge of checking that the
5668 -- size of an array or record type is OK. Also we do not check
5669 -- the size in the ordinary fixed-point case, since it is too
5670 -- early to do so (there may be subsequent small clause that
5671 -- affects the size). We can check the size if a small clause
5672 -- has already been given.
5674 if not Is_Ordinary_Fixed_Point_Type
(U_Ent
)
5675 or else Has_Small_Clause
(U_Ent
)
5677 Check_Size
(Expr
, Etyp
, Size
, Biased
);
5678 Set_Biased
(U_Ent
, N
, "size clause", Biased
);
5681 -- For types set RM_Size and Esize if possible
5683 if Is_Type
(U_Ent
) then
5684 Set_RM_Size
(U_Ent
, Size
);
5686 -- For elementary types, increase Object_Size to power of 2,
5687 -- but not less than a storage unit in any case (normally
5688 -- this means it will be byte addressable).
5690 -- For all other types, nothing else to do, we leave Esize
5691 -- (object size) unset, the back end will set it from the
5692 -- size and alignment in an appropriate manner.
5694 -- In both cases, we check whether the alignment must be
5695 -- reset in the wake of the size change.
5697 if Is_Elementary_Type
(U_Ent
) then
5698 if Size
<= System_Storage_Unit
then
5699 Init_Esize
(U_Ent
, System_Storage_Unit
);
5700 elsif Size
<= 16 then
5701 Init_Esize
(U_Ent
, 16);
5702 elsif Size
<= 32 then
5703 Init_Esize
(U_Ent
, 32);
5705 Set_Esize
(U_Ent
, (Size
+ 63) / 64 * 64);
5708 Alignment_Check_For_Size_Change
(U_Ent
, Esize
(U_Ent
));
5710 Alignment_Check_For_Size_Change
(U_Ent
, Size
);
5713 -- For objects, set Esize only
5716 -- The following error is suppressed in ASIS mode to allow
5717 -- for different ASIS back ends or ASIS-based tools to query
5718 -- the illegal clause.
5720 if Is_Elementary_Type
(Etyp
)
5721 and then Size
/= System_Storage_Unit
5722 and then Size
/= System_Storage_Unit
* 2
5723 and then Size
/= System_Storage_Unit
* 4
5724 and then Size
/= System_Storage_Unit
* 8
5725 and then not ASIS_Mode
5727 Error_Msg_Uint_1
:= UI_From_Int
(System_Storage_Unit
);
5728 Error_Msg_Uint_2
:= Error_Msg_Uint_1
* 8;
5730 ("size for primitive object must be a power of 2 in "
5731 & "the range ^-^", N
);
5734 Set_Esize
(U_Ent
, Size
);
5737 Set_Has_Size_Clause
(U_Ent
);
5745 -- Small attribute definition clause
5747 when Attribute_Small
=> Small
: declare
5748 Implicit_Base
: constant Entity_Id
:= Base_Type
(U_Ent
);
5752 Analyze_And_Resolve
(Expr
, Any_Real
);
5754 if Etype
(Expr
) = Any_Type
then
5757 elsif not Is_OK_Static_Expression
(Expr
) then
5758 Flag_Non_Static_Expr
5759 ("small requires static expression!", Expr
);
5763 Small
:= Expr_Value_R
(Expr
);
5765 if Small
<= Ureal_0
then
5766 Error_Msg_N
("small value must be greater than zero", Expr
);
5772 if not Is_Ordinary_Fixed_Point_Type
(U_Ent
) then
5774 ("small requires an ordinary fixed point type", Nam
);
5776 elsif Has_Small_Clause
(U_Ent
) then
5777 Error_Msg_N
("small already given for &", Nam
);
5779 elsif Small
> Delta_Value
(U_Ent
) then
5781 ("small value must not be greater than delta value", Nam
);
5784 Set_Small_Value
(U_Ent
, Small
);
5785 Set_Small_Value
(Implicit_Base
, Small
);
5786 Set_Has_Small_Clause
(U_Ent
);
5787 Set_Has_Small_Clause
(Implicit_Base
);
5788 Set_Has_Non_Standard_Rep
(Implicit_Base
);
5796 -- Storage_Pool attribute definition clause
5798 when Attribute_Storage_Pool | Attribute_Simple_Storage_Pool
=> declare
5803 if Ekind
(U_Ent
) = E_Access_Subprogram_Type
then
5805 ("storage pool cannot be given for access-to-subprogram type",
5810 Ekind_In
(U_Ent
, E_Access_Type
, E_General_Access_Type
)
5813 ("storage pool can only be given for access types", Nam
);
5816 elsif Is_Derived_Type
(U_Ent
) then
5818 ("storage pool cannot be given for a derived access type",
5821 elsif Duplicate_Clause
then
5824 elsif Present
(Associated_Storage_Pool
(U_Ent
)) then
5825 Error_Msg_N
("storage pool already given for &", Nam
);
5829 -- Check for Storage_Size previously given
5832 SS
: constant Node_Id
:=
5833 Get_Attribute_Definition_Clause
5834 (U_Ent
, Attribute_Storage_Size
);
5836 if Present
(SS
) then
5837 Check_Pool_Size_Clash
(U_Ent
, N
, SS
);
5841 -- Storage_Pool case
5843 if Id
= Attribute_Storage_Pool
then
5845 (Expr
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
5847 -- In the Simple_Storage_Pool case, we allow a variable of any
5848 -- simple storage pool type, so we Resolve without imposing an
5852 Analyze_And_Resolve
(Expr
);
5854 if not Present
(Get_Rep_Pragma
5855 (Etype
(Expr
), Name_Simple_Storage_Pool_Type
))
5858 ("expression must be of a simple storage pool type", Expr
);
5862 if not Denotes_Variable
(Expr
) then
5863 Error_Msg_N
("storage pool must be a variable", Expr
);
5867 if Nkind
(Expr
) = N_Type_Conversion
then
5868 T
:= Etype
(Expression
(Expr
));
5873 -- The Stack_Bounded_Pool is used internally for implementing
5874 -- access types with a Storage_Size. Since it only work properly
5875 -- when used on one specific type, we need to check that it is not
5876 -- hijacked improperly:
5878 -- type T is access Integer;
5879 -- for T'Storage_Size use n;
5880 -- type Q is access Float;
5881 -- for Q'Storage_Size use T'Storage_Size; -- incorrect
5883 if RTE_Available
(RE_Stack_Bounded_Pool
)
5884 and then Base_Type
(T
) = RTE
(RE_Stack_Bounded_Pool
)
5886 Error_Msg_N
("non-shareable internal Pool", Expr
);
5890 -- If the argument is a name that is not an entity name, then
5891 -- we construct a renaming operation to define an entity of
5892 -- type storage pool.
5894 if not Is_Entity_Name
(Expr
)
5895 and then Is_Object_Reference
(Expr
)
5897 Pool
:= Make_Temporary
(Loc
, 'P', Expr
);
5900 Rnode
: constant Node_Id
:=
5901 Make_Object_Renaming_Declaration
(Loc
,
5902 Defining_Identifier
=> Pool
,
5904 New_Occurrence_Of
(Etype
(Expr
), Loc
),
5908 -- If the attribute definition clause comes from an aspect
5909 -- clause, then insert the renaming before the associated
5910 -- entity's declaration, since the attribute clause has
5911 -- not yet been appended to the declaration list.
5913 if From_Aspect_Specification
(N
) then
5914 Insert_Before
(Parent
(Entity
(N
)), Rnode
);
5916 Insert_Before
(N
, Rnode
);
5920 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
5923 elsif Is_Entity_Name
(Expr
) then
5924 Pool
:= Entity
(Expr
);
5926 -- If pool is a renamed object, get original one. This can
5927 -- happen with an explicit renaming, and within instances.
5929 while Present
(Renamed_Object
(Pool
))
5930 and then Is_Entity_Name
(Renamed_Object
(Pool
))
5932 Pool
:= Entity
(Renamed_Object
(Pool
));
5935 if Present
(Renamed_Object
(Pool
))
5936 and then Nkind
(Renamed_Object
(Pool
)) = N_Type_Conversion
5937 and then Is_Entity_Name
(Expression
(Renamed_Object
(Pool
)))
5939 Pool
:= Entity
(Expression
(Renamed_Object
(Pool
)));
5942 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
5944 elsif Nkind
(Expr
) = N_Type_Conversion
5945 and then Is_Entity_Name
(Expression
(Expr
))
5946 and then Nkind
(Original_Node
(Expr
)) = N_Attribute_Reference
5948 Pool
:= Entity
(Expression
(Expr
));
5949 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
5952 Error_Msg_N
("incorrect reference to a Storage Pool", Expr
);
5961 -- Storage_Size attribute definition clause
5963 when Attribute_Storage_Size
=> Storage_Size
: declare
5964 Btype
: constant Entity_Id
:= Base_Type
(U_Ent
);
5967 if Is_Task_Type
(U_Ent
) then
5969 -- Check obsolescent (but never obsolescent if from aspect)
5971 if not From_Aspect_Specification
(N
) then
5972 Check_Restriction
(No_Obsolescent_Features
, N
);
5974 if Warn_On_Obsolescent_Feature
then
5976 ("?j?storage size clause for task is an obsolescent "
5977 & "feature (RM J.9)", N
);
5978 Error_Msg_N
("\?j?use Storage_Size pragma instead", N
);
5985 if not Is_Access_Type
(U_Ent
)
5986 and then Ekind
(U_Ent
) /= E_Task_Type
5988 Error_Msg_N
("storage size cannot be given for &", Nam
);
5990 elsif Is_Access_Type
(U_Ent
) and Is_Derived_Type
(U_Ent
) then
5992 ("storage size cannot be given for a derived access type",
5995 elsif Duplicate_Clause
then
5999 Analyze_And_Resolve
(Expr
, Any_Integer
);
6001 if Is_Access_Type
(U_Ent
) then
6003 -- Check for Storage_Pool previously given
6006 SP
: constant Node_Id
:=
6007 Get_Attribute_Definition_Clause
6008 (U_Ent
, Attribute_Storage_Pool
);
6011 if Present
(SP
) then
6012 Check_Pool_Size_Clash
(U_Ent
, SP
, N
);
6016 -- Special case of for x'Storage_Size use 0
6018 if Is_OK_Static_Expression
(Expr
)
6019 and then Expr_Value
(Expr
) = 0
6021 Set_No_Pool_Assigned
(Btype
);
6025 Set_Has_Storage_Size_Clause
(Btype
);
6033 when Attribute_Stream_Size
=> Stream_Size
: declare
6034 Size
: constant Uint
:= Static_Integer
(Expr
);
6037 if Ada_Version
<= Ada_95
then
6038 Check_Restriction
(No_Implementation_Attributes
, N
);
6041 if Duplicate_Clause
then
6044 elsif Is_Elementary_Type
(U_Ent
) then
6046 -- The following errors are suppressed in ASIS mode to allow
6047 -- for different ASIS back ends or ASIS-based tools to query
6048 -- the illegal clause.
6053 elsif Size
/= System_Storage_Unit
6054 and then Size
/= System_Storage_Unit
* 2
6055 and then Size
/= System_Storage_Unit
* 4
6056 and then Size
/= System_Storage_Unit
* 8
6058 Error_Msg_Uint_1
:= UI_From_Int
(System_Storage_Unit
);
6060 ("stream size for elementary type must be a power of 2 "
6061 & "and at least ^", N
);
6063 elsif RM_Size
(U_Ent
) > Size
then
6064 Error_Msg_Uint_1
:= RM_Size
(U_Ent
);
6066 ("stream size for elementary type must be a power of 2 "
6067 & "and at least ^", N
);
6070 Set_Has_Stream_Size_Clause
(U_Ent
);
6073 Error_Msg_N
("Stream_Size cannot be given for &", Nam
);
6081 -- Value_Size attribute definition clause
6083 when Attribute_Value_Size
=> Value_Size
: declare
6084 Size
: constant Uint
:= Static_Integer
(Expr
);
6088 if not Is_Type
(U_Ent
) then
6089 Error_Msg_N
("Value_Size cannot be given for &", Nam
);
6091 elsif Duplicate_Clause
then
6094 elsif Is_Array_Type
(U_Ent
)
6095 and then not Is_Constrained
(U_Ent
)
6098 ("Value_Size cannot be given for unconstrained array", Nam
);
6101 if Is_Elementary_Type
(U_Ent
) then
6102 Check_Size
(Expr
, U_Ent
, Size
, Biased
);
6103 Set_Biased
(U_Ent
, N
, "value size clause", Biased
);
6106 Set_RM_Size
(U_Ent
, Size
);
6110 -----------------------
6111 -- Variable_Indexing --
6112 -----------------------
6114 when Attribute_Variable_Indexing
=>
6115 Check_Indexing_Functions
;
6121 when Attribute_Write
=>
6122 Analyze_Stream_TSS_Definition
(TSS_Stream_Write
);
6123 Set_Has_Specified_Stream_Write
(Ent
);
6125 -- All other attributes cannot be set
6129 ("attribute& cannot be set with definition clause", N
);
6132 -- The test for the type being frozen must be performed after any
6133 -- expression the clause has been analyzed since the expression itself
6134 -- might cause freezing that makes the clause illegal.
6136 if Rep_Item_Too_Late
(U_Ent
, N
, FOnly
) then
6139 end Analyze_Attribute_Definition_Clause
;
6141 ----------------------------
6142 -- Analyze_Code_Statement --
6143 ----------------------------
6145 procedure Analyze_Code_Statement
(N
: Node_Id
) is
6146 HSS
: constant Node_Id
:= Parent
(N
);
6147 SBody
: constant Node_Id
:= Parent
(HSS
);
6148 Subp
: constant Entity_Id
:= Current_Scope
;
6155 -- Accept foreign code statements for CodePeer. The analysis is skipped
6156 -- to avoid rejecting unrecognized constructs.
6158 if CodePeer_Mode
then
6163 -- Analyze and check we get right type, note that this implements the
6164 -- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that is
6165 -- the only way that Asm_Insn could possibly be visible.
6167 Analyze_And_Resolve
(Expression
(N
));
6169 if Etype
(Expression
(N
)) = Any_Type
then
6171 elsif Etype
(Expression
(N
)) /= RTE
(RE_Asm_Insn
) then
6172 Error_Msg_N
("incorrect type for code statement", N
);
6176 Check_Code_Statement
(N
);
6178 -- Make sure we appear in the handled statement sequence of a subprogram
6181 if Nkind
(HSS
) /= N_Handled_Sequence_Of_Statements
6182 or else Nkind
(SBody
) /= N_Subprogram_Body
6185 ("code statement can only appear in body of subprogram", N
);
6189 -- Do remaining checks (RM 13.8(3)) if not already done
6191 if not Is_Machine_Code_Subprogram
(Subp
) then
6192 Set_Is_Machine_Code_Subprogram
(Subp
);
6194 -- No exception handlers allowed
6196 if Present
(Exception_Handlers
(HSS
)) then
6198 ("exception handlers not permitted in machine code subprogram",
6199 First
(Exception_Handlers
(HSS
)));
6202 -- No declarations other than use clauses and pragmas (we allow
6203 -- certain internally generated declarations as well).
6205 Decl
:= First
(Declarations
(SBody
));
6206 while Present
(Decl
) loop
6207 DeclO
:= Original_Node
(Decl
);
6208 if Comes_From_Source
(DeclO
)
6209 and not Nkind_In
(DeclO
, N_Pragma
,
6210 N_Use_Package_Clause
,
6212 N_Implicit_Label_Declaration
)
6215 ("this declaration not allowed in machine code subprogram",
6222 -- No statements other than code statements, pragmas, and labels.
6223 -- Again we allow certain internally generated statements.
6225 -- In Ada 2012, qualified expressions are names, and the code
6226 -- statement is initially parsed as a procedure call.
6228 Stmt
:= First
(Statements
(HSS
));
6229 while Present
(Stmt
) loop
6230 StmtO
:= Original_Node
(Stmt
);
6232 -- A procedure call transformed into a code statement is OK
6234 if Ada_Version
>= Ada_2012
6235 and then Nkind
(StmtO
) = N_Procedure_Call_Statement
6236 and then Nkind
(Name
(StmtO
)) = N_Qualified_Expression
6240 elsif Comes_From_Source
(StmtO
)
6241 and then not Nkind_In
(StmtO
, N_Pragma
,
6246 ("this statement is not allowed in machine code subprogram",
6253 end Analyze_Code_Statement
;
6255 -----------------------------------------------
6256 -- Analyze_Enumeration_Representation_Clause --
6257 -----------------------------------------------
6259 procedure Analyze_Enumeration_Representation_Clause
(N
: Node_Id
) is
6260 Ident
: constant Node_Id
:= Identifier
(N
);
6261 Aggr
: constant Node_Id
:= Array_Aggregate
(N
);
6262 Enumtype
: Entity_Id
;
6269 Err
: Boolean := False;
6270 -- Set True to avoid cascade errors and crashes on incorrect source code
6272 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Universal_Integer
));
6273 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(Universal_Integer
));
6274 -- Allowed range of universal integer (= allowed range of enum lit vals)
6278 -- Minimum and maximum values of entries
6281 -- Pointer to node for literal providing max value
6284 if Ignore_Rep_Clauses
then
6285 Kill_Rep_Clause
(N
);
6289 -- Ignore enumeration rep clauses by default in CodePeer mode,
6290 -- unless -gnatd.I is specified, as a work around for potential false
6291 -- positive messages.
6293 if CodePeer_Mode
and not Debug_Flag_Dot_II
then
6297 -- First some basic error checks
6300 Enumtype
:= Entity
(Ident
);
6302 if Enumtype
= Any_Type
6303 or else Rep_Item_Too_Early
(Enumtype
, N
)
6307 Enumtype
:= Underlying_Type
(Enumtype
);
6310 if not Is_Enumeration_Type
(Enumtype
) then
6312 ("enumeration type required, found}",
6313 Ident
, First_Subtype
(Enumtype
));
6317 -- Ignore rep clause on generic actual type. This will already have
6318 -- been flagged on the template as an error, and this is the safest
6319 -- way to ensure we don't get a junk cascaded message in the instance.
6321 if Is_Generic_Actual_Type
(Enumtype
) then
6324 -- Type must be in current scope
6326 elsif Scope
(Enumtype
) /= Current_Scope
then
6327 Error_Msg_N
("type must be declared in this scope", Ident
);
6330 -- Type must be a first subtype
6332 elsif not Is_First_Subtype
(Enumtype
) then
6333 Error_Msg_N
("cannot give enumeration rep clause for subtype", N
);
6336 -- Ignore duplicate rep clause
6338 elsif Has_Enumeration_Rep_Clause
(Enumtype
) then
6339 Error_Msg_N
("duplicate enumeration rep clause ignored", N
);
6342 -- Don't allow rep clause for standard [wide_[wide_]]character
6344 elsif Is_Standard_Character_Type
(Enumtype
) then
6345 Error_Msg_N
("enumeration rep clause not allowed for this type", N
);
6348 -- Check that the expression is a proper aggregate (no parentheses)
6350 elsif Paren_Count
(Aggr
) /= 0 then
6352 ("extra parentheses surrounding aggregate not allowed",
6356 -- All tests passed, so set rep clause in place
6359 Set_Has_Enumeration_Rep_Clause
(Enumtype
);
6360 Set_Has_Enumeration_Rep_Clause
(Base_Type
(Enumtype
));
6363 -- Now we process the aggregate. Note that we don't use the normal
6364 -- aggregate code for this purpose, because we don't want any of the
6365 -- normal expansion activities, and a number of special semantic
6366 -- rules apply (including the component type being any integer type)
6368 Elit
:= First_Literal
(Enumtype
);
6370 -- First the positional entries if any
6372 if Present
(Expressions
(Aggr
)) then
6373 Expr
:= First
(Expressions
(Aggr
));
6374 while Present
(Expr
) loop
6376 Error_Msg_N
("too many entries in aggregate", Expr
);
6380 Val
:= Static_Integer
(Expr
);
6382 -- Err signals that we found some incorrect entries processing
6383 -- the list. The final checks for completeness and ordering are
6384 -- skipped in this case.
6386 if Val
= No_Uint
then
6389 elsif Val
< Lo
or else Hi
< Val
then
6390 Error_Msg_N
("value outside permitted range", Expr
);
6394 Set_Enumeration_Rep
(Elit
, Val
);
6395 Set_Enumeration_Rep_Expr
(Elit
, Expr
);
6401 -- Now process the named entries if present
6403 if Present
(Component_Associations
(Aggr
)) then
6404 Assoc
:= First
(Component_Associations
(Aggr
));
6405 while Present
(Assoc
) loop
6406 Choice
:= First
(Choices
(Assoc
));
6408 if Present
(Next
(Choice
)) then
6410 ("multiple choice not allowed here", Next
(Choice
));
6414 if Nkind
(Choice
) = N_Others_Choice
then
6415 Error_Msg_N
("others choice not allowed here", Choice
);
6418 elsif Nkind
(Choice
) = N_Range
then
6420 -- ??? should allow zero/one element range here
6422 Error_Msg_N
("range not allowed here", Choice
);
6426 Analyze_And_Resolve
(Choice
, Enumtype
);
6428 if Error_Posted
(Choice
) then
6433 if Is_Entity_Name
(Choice
)
6434 and then Is_Type
(Entity
(Choice
))
6436 Error_Msg_N
("subtype name not allowed here", Choice
);
6439 -- ??? should allow static subtype with zero/one entry
6441 elsif Etype
(Choice
) = Base_Type
(Enumtype
) then
6442 if not Is_OK_Static_Expression
(Choice
) then
6443 Flag_Non_Static_Expr
6444 ("non-static expression used for choice!", Choice
);
6448 Elit
:= Expr_Value_E
(Choice
);
6450 if Present
(Enumeration_Rep_Expr
(Elit
)) then
6452 Sloc
(Enumeration_Rep_Expr
(Elit
));
6454 ("representation for& previously given#",
6459 Set_Enumeration_Rep_Expr
(Elit
, Expression
(Assoc
));
6461 Expr
:= Expression
(Assoc
);
6462 Val
:= Static_Integer
(Expr
);
6464 if Val
= No_Uint
then
6467 elsif Val
< Lo
or else Hi
< Val
then
6468 Error_Msg_N
("value outside permitted range", Expr
);
6472 Set_Enumeration_Rep
(Elit
, Val
);
6482 -- Aggregate is fully processed. Now we check that a full set of
6483 -- representations was given, and that they are in range and in order.
6484 -- These checks are only done if no other errors occurred.
6490 Elit
:= First_Literal
(Enumtype
);
6491 while Present
(Elit
) loop
6492 if No
(Enumeration_Rep_Expr
(Elit
)) then
6493 Error_Msg_NE
("missing representation for&!", N
, Elit
);
6496 Val
:= Enumeration_Rep
(Elit
);
6498 if Min
= No_Uint
then
6502 if Val
/= No_Uint
then
6503 if Max
/= No_Uint
and then Val
<= Max
then
6505 ("enumeration value for& not ordered!",
6506 Enumeration_Rep_Expr
(Elit
), Elit
);
6509 Max_Node
:= Enumeration_Rep_Expr
(Elit
);
6513 -- If there is at least one literal whose representation is not
6514 -- equal to the Pos value, then note that this enumeration type
6515 -- has a non-standard representation.
6517 if Val
/= Enumeration_Pos
(Elit
) then
6518 Set_Has_Non_Standard_Rep
(Base_Type
(Enumtype
));
6525 -- Now set proper size information
6528 Minsize
: Uint
:= UI_From_Int
(Minimum_Size
(Enumtype
));
6531 if Has_Size_Clause
(Enumtype
) then
6533 -- All OK, if size is OK now
6535 if RM_Size
(Enumtype
) >= Minsize
then
6539 -- Try if we can get by with biasing
6542 UI_From_Int
(Minimum_Size
(Enumtype
, Biased
=> True));
6544 -- Error message if even biasing does not work
6546 if RM_Size
(Enumtype
) < Minsize
then
6547 Error_Msg_Uint_1
:= RM_Size
(Enumtype
);
6548 Error_Msg_Uint_2
:= Max
;
6550 ("previously given size (^) is too small "
6551 & "for this value (^)", Max_Node
);
6553 -- If biasing worked, indicate that we now have biased rep
6557 (Enumtype
, Size_Clause
(Enumtype
), "size clause");
6562 Set_RM_Size
(Enumtype
, Minsize
);
6563 Set_Enum_Esize
(Enumtype
);
6566 Set_RM_Size
(Base_Type
(Enumtype
), RM_Size
(Enumtype
));
6567 Set_Esize
(Base_Type
(Enumtype
), Esize
(Enumtype
));
6568 Set_Alignment
(Base_Type
(Enumtype
), Alignment
(Enumtype
));
6572 -- We repeat the too late test in case it froze itself
6574 if Rep_Item_Too_Late
(Enumtype
, N
) then
6577 end Analyze_Enumeration_Representation_Clause
;
6579 ----------------------------
6580 -- Analyze_Free_Statement --
6581 ----------------------------
6583 procedure Analyze_Free_Statement
(N
: Node_Id
) is
6585 Analyze
(Expression
(N
));
6586 end Analyze_Free_Statement
;
6588 ---------------------------
6589 -- Analyze_Freeze_Entity --
6590 ---------------------------
6592 procedure Analyze_Freeze_Entity
(N
: Node_Id
) is
6594 Freeze_Entity_Checks
(N
);
6595 end Analyze_Freeze_Entity
;
6597 -----------------------------------
6598 -- Analyze_Freeze_Generic_Entity --
6599 -----------------------------------
6601 procedure Analyze_Freeze_Generic_Entity
(N
: Node_Id
) is
6603 Freeze_Entity_Checks
(N
);
6604 end Analyze_Freeze_Generic_Entity
;
6606 ------------------------------------------
6607 -- Analyze_Record_Representation_Clause --
6608 ------------------------------------------
6610 -- Note: we check as much as we can here, but we can't do any checks
6611 -- based on the position values (e.g. overlap checks) until freeze time
6612 -- because especially in Ada 2005 (machine scalar mode), the processing
6613 -- for non-standard bit order can substantially change the positions.
6614 -- See procedure Check_Record_Representation_Clause (called from Freeze)
6615 -- for the remainder of this processing.
6617 procedure Analyze_Record_Representation_Clause
(N
: Node_Id
) is
6618 Ident
: constant Node_Id
:= Identifier
(N
);
6623 Hbit
: Uint
:= Uint_0
;
6627 Rectype
: Entity_Id
;
6630 function Is_Inherited
(Comp
: Entity_Id
) return Boolean;
6631 -- True if Comp is an inherited component in a record extension
6637 function Is_Inherited
(Comp
: Entity_Id
) return Boolean is
6638 Comp_Base
: Entity_Id
;
6641 if Ekind
(Rectype
) = E_Record_Subtype
then
6642 Comp_Base
:= Original_Record_Component
(Comp
);
6647 return Comp_Base
/= Original_Record_Component
(Comp_Base
);
6652 Is_Record_Extension
: Boolean;
6653 -- True if Rectype is a record extension
6655 CR_Pragma
: Node_Id
:= Empty
;
6656 -- Points to N_Pragma node if Complete_Representation pragma present
6658 -- Start of processing for Analyze_Record_Representation_Clause
6661 if Ignore_Rep_Clauses
then
6662 Kill_Rep_Clause
(N
);
6667 Rectype
:= Entity
(Ident
);
6669 if Rectype
= Any_Type
or else Rep_Item_Too_Early
(Rectype
, N
) then
6672 Rectype
:= Underlying_Type
(Rectype
);
6675 -- First some basic error checks
6677 if not Is_Record_Type
(Rectype
) then
6679 ("record type required, found}", Ident
, First_Subtype
(Rectype
));
6682 elsif Scope
(Rectype
) /= Current_Scope
then
6683 Error_Msg_N
("type must be declared in this scope", N
);
6686 elsif not Is_First_Subtype
(Rectype
) then
6687 Error_Msg_N
("cannot give record rep clause for subtype", N
);
6690 elsif Has_Record_Rep_Clause
(Rectype
) then
6691 Error_Msg_N
("duplicate record rep clause ignored", N
);
6694 elsif Rep_Item_Too_Late
(Rectype
, N
) then
6698 -- We know we have a first subtype, now possibly go to the anonymous
6699 -- base type to determine whether Rectype is a record extension.
6701 Recdef
:= Type_Definition
(Declaration_Node
(Base_Type
(Rectype
)));
6702 Is_Record_Extension
:=
6703 Nkind
(Recdef
) = N_Derived_Type_Definition
6704 and then Present
(Record_Extension_Part
(Recdef
));
6706 if Present
(Mod_Clause
(N
)) then
6708 Loc
: constant Source_Ptr
:= Sloc
(N
);
6709 M
: constant Node_Id
:= Mod_Clause
(N
);
6710 P
: constant List_Id
:= Pragmas_Before
(M
);
6714 pragma Warnings
(Off
, Mod_Val
);
6717 Check_Restriction
(No_Obsolescent_Features
, Mod_Clause
(N
));
6719 if Warn_On_Obsolescent_Feature
then
6721 ("?j?mod clause is an obsolescent feature (RM J.8)", N
);
6723 ("\?j?use alignment attribute definition clause instead", N
);
6730 -- In ASIS_Mode mode, expansion is disabled, but we must convert
6731 -- the Mod clause into an alignment clause anyway, so that the
6732 -- back end can compute and back-annotate properly the size and
6733 -- alignment of types that may include this record.
6735 -- This seems dubious, this destroys the source tree in a manner
6736 -- not detectable by ASIS ???
6738 if Operating_Mode
= Check_Semantics
and then ASIS_Mode
then
6740 Make_Attribute_Definition_Clause
(Loc
,
6741 Name
=> New_Occurrence_Of
(Base_Type
(Rectype
), Loc
),
6742 Chars
=> Name_Alignment
,
6743 Expression
=> Relocate_Node
(Expression
(M
)));
6745 Set_From_At_Mod
(AtM_Nod
);
6746 Insert_After
(N
, AtM_Nod
);
6747 Mod_Val
:= Get_Alignment_Value
(Expression
(AtM_Nod
));
6748 Set_Mod_Clause
(N
, Empty
);
6751 -- Get the alignment value to perform error checking
6753 Mod_Val
:= Get_Alignment_Value
(Expression
(M
));
6758 -- For untagged types, clear any existing component clauses for the
6759 -- type. If the type is derived, this is what allows us to override
6760 -- a rep clause for the parent. For type extensions, the representation
6761 -- of the inherited components is inherited, so we want to keep previous
6762 -- component clauses for completeness.
6764 if not Is_Tagged_Type
(Rectype
) then
6765 Comp
:= First_Component_Or_Discriminant
(Rectype
);
6766 while Present
(Comp
) loop
6767 Set_Component_Clause
(Comp
, Empty
);
6768 Next_Component_Or_Discriminant
(Comp
);
6772 -- All done if no component clauses
6774 CC
:= First
(Component_Clauses
(N
));
6780 -- A representation like this applies to the base type
6782 Set_Has_Record_Rep_Clause
(Base_Type
(Rectype
));
6783 Set_Has_Non_Standard_Rep
(Base_Type
(Rectype
));
6784 Set_Has_Specified_Layout
(Base_Type
(Rectype
));
6786 -- Process the component clauses
6788 while Present
(CC
) loop
6792 if Nkind
(CC
) = N_Pragma
then
6795 -- The only pragma of interest is Complete_Representation
6797 if Pragma_Name
(CC
) = Name_Complete_Representation
then
6801 -- Processing for real component clause
6804 Posit
:= Static_Integer
(Position
(CC
));
6805 Fbit
:= Static_Integer
(First_Bit
(CC
));
6806 Lbit
:= Static_Integer
(Last_Bit
(CC
));
6809 and then Fbit
/= No_Uint
6810 and then Lbit
/= No_Uint
6813 Error_Msg_N
("position cannot be negative", Position
(CC
));
6816 Error_Msg_N
("first bit cannot be negative", First_Bit
(CC
));
6818 -- The Last_Bit specified in a component clause must not be
6819 -- less than the First_Bit minus one (RM-13.5.1(10)).
6821 elsif Lbit
< Fbit
- 1 then
6823 ("last bit cannot be less than first bit minus one",
6826 -- Values look OK, so find the corresponding record component
6827 -- Even though the syntax allows an attribute reference for
6828 -- implementation-defined components, GNAT does not allow the
6829 -- tag to get an explicit position.
6831 elsif Nkind
(Component_Name
(CC
)) = N_Attribute_Reference
then
6832 if Attribute_Name
(Component_Name
(CC
)) = Name_Tag
then
6833 Error_Msg_N
("position of tag cannot be specified", CC
);
6835 Error_Msg_N
("illegal component name", CC
);
6839 Comp
:= First_Entity
(Rectype
);
6840 while Present
(Comp
) loop
6841 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
6847 -- Maybe component of base type that is absent from
6848 -- statically constrained first subtype.
6850 Comp
:= First_Entity
(Base_Type
(Rectype
));
6851 while Present
(Comp
) loop
6852 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
6859 ("component clause is for non-existent field", CC
);
6861 -- Ada 2012 (AI05-0026): Any name that denotes a
6862 -- discriminant of an object of an unchecked union type
6863 -- shall not occur within a record_representation_clause.
6865 -- The general restriction of using record rep clauses on
6866 -- Unchecked_Union types has now been lifted. Since it is
6867 -- possible to introduce a record rep clause which mentions
6868 -- the discriminant of an Unchecked_Union in non-Ada 2012
6869 -- code, this check is applied to all versions of the
6872 elsif Ekind
(Comp
) = E_Discriminant
6873 and then Is_Unchecked_Union
(Rectype
)
6876 ("cannot reference discriminant of unchecked union",
6877 Component_Name
(CC
));
6879 elsif Is_Record_Extension
and then Is_Inherited
(Comp
) then
6881 ("component clause not allowed for inherited "
6882 & "component&", CC
, Comp
);
6884 elsif Present
(Component_Clause
(Comp
)) then
6886 -- Diagnose duplicate rep clause, or check consistency
6887 -- if this is an inherited component. In a double fault,
6888 -- there may be a duplicate inconsistent clause for an
6889 -- inherited component.
6891 if Scope
(Original_Record_Component
(Comp
)) = Rectype
6892 or else Parent
(Component_Clause
(Comp
)) = N
6894 Error_Msg_Sloc
:= Sloc
(Component_Clause
(Comp
));
6895 Error_Msg_N
("component clause previously given#", CC
);
6899 Rep1
: constant Node_Id
:= Component_Clause
(Comp
);
6901 if Intval
(Position
(Rep1
)) /=
6902 Intval
(Position
(CC
))
6903 or else Intval
(First_Bit
(Rep1
)) /=
6904 Intval
(First_Bit
(CC
))
6905 or else Intval
(Last_Bit
(Rep1
)) /=
6906 Intval
(Last_Bit
(CC
))
6909 ("component clause inconsistent with "
6910 & "representation of ancestor", CC
);
6912 elsif Warn_On_Redundant_Constructs
then
6914 ("?r?redundant confirming component clause "
6915 & "for component!", CC
);
6920 -- Normal case where this is the first component clause we
6921 -- have seen for this entity, so set it up properly.
6924 -- Make reference for field in record rep clause and set
6925 -- appropriate entity field in the field identifier.
6928 (Comp
, Component_Name
(CC
), Set_Ref
=> False);
6929 Set_Entity
(Component_Name
(CC
), Comp
);
6931 -- Update Fbit and Lbit to the actual bit number
6933 Fbit
:= Fbit
+ UI_From_Int
(SSU
) * Posit
;
6934 Lbit
:= Lbit
+ UI_From_Int
(SSU
) * Posit
;
6936 if Has_Size_Clause
(Rectype
)
6937 and then RM_Size
(Rectype
) <= Lbit
6940 ("bit number out of range of specified size",
6943 Set_Component_Clause
(Comp
, CC
);
6944 Set_Component_Bit_Offset
(Comp
, Fbit
);
6945 Set_Esize
(Comp
, 1 + (Lbit
- Fbit
));
6946 Set_Normalized_First_Bit
(Comp
, Fbit
mod SSU
);
6947 Set_Normalized_Position
(Comp
, Fbit
/ SSU
);
6949 if Warn_On_Overridden_Size
6950 and then Has_Size_Clause
(Etype
(Comp
))
6951 and then RM_Size
(Etype
(Comp
)) /= Esize
(Comp
)
6954 ("?S?component size overrides size clause for&",
6955 Component_Name
(CC
), Etype
(Comp
));
6958 -- This information is also set in the corresponding
6959 -- component of the base type, found by accessing the
6960 -- Original_Record_Component link if it is present.
6962 Ocomp
:= Original_Record_Component
(Comp
);
6969 (Component_Name
(CC
),
6975 (Comp
, First_Node
(CC
), "component clause", Biased
);
6977 if Present
(Ocomp
) then
6978 Set_Component_Clause
(Ocomp
, CC
);
6979 Set_Component_Bit_Offset
(Ocomp
, Fbit
);
6980 Set_Normalized_First_Bit
(Ocomp
, Fbit
mod SSU
);
6981 Set_Normalized_Position
(Ocomp
, Fbit
/ SSU
);
6982 Set_Esize
(Ocomp
, 1 + (Lbit
- Fbit
));
6984 Set_Normalized_Position_Max
6985 (Ocomp
, Normalized_Position
(Ocomp
));
6987 -- Note: we don't use Set_Biased here, because we
6988 -- already gave a warning above if needed, and we
6989 -- would get a duplicate for the same name here.
6991 Set_Has_Biased_Representation
6992 (Ocomp
, Has_Biased_Representation
(Comp
));
6995 if Esize
(Comp
) < 0 then
6996 Error_Msg_N
("component size is negative", CC
);
7007 -- Check missing components if Complete_Representation pragma appeared
7009 if Present
(CR_Pragma
) then
7010 Comp
:= First_Component_Or_Discriminant
(Rectype
);
7011 while Present
(Comp
) loop
7012 if No
(Component_Clause
(Comp
)) then
7014 ("missing component clause for &", CR_Pragma
, Comp
);
7017 Next_Component_Or_Discriminant
(Comp
);
7020 -- Give missing components warning if required
7022 elsif Warn_On_Unrepped_Components
then
7024 Num_Repped_Components
: Nat
:= 0;
7025 Num_Unrepped_Components
: Nat
:= 0;
7028 -- First count number of repped and unrepped components
7030 Comp
:= First_Component_Or_Discriminant
(Rectype
);
7031 while Present
(Comp
) loop
7032 if Present
(Component_Clause
(Comp
)) then
7033 Num_Repped_Components
:= Num_Repped_Components
+ 1;
7035 Num_Unrepped_Components
:= Num_Unrepped_Components
+ 1;
7038 Next_Component_Or_Discriminant
(Comp
);
7041 -- We are only interested in the case where there is at least one
7042 -- unrepped component, and at least half the components have rep
7043 -- clauses. We figure that if less than half have them, then the
7044 -- partial rep clause is really intentional. If the component
7045 -- type has no underlying type set at this point (as for a generic
7046 -- formal type), we don't know enough to give a warning on the
7049 if Num_Unrepped_Components
> 0
7050 and then Num_Unrepped_Components
< Num_Repped_Components
7052 Comp
:= First_Component_Or_Discriminant
(Rectype
);
7053 while Present
(Comp
) loop
7054 if No
(Component_Clause
(Comp
))
7055 and then Comes_From_Source
(Comp
)
7056 and then Present
(Underlying_Type
(Etype
(Comp
)))
7057 and then (Is_Scalar_Type
(Underlying_Type
(Etype
(Comp
)))
7058 or else Size_Known_At_Compile_Time
7059 (Underlying_Type
(Etype
(Comp
))))
7060 and then not Has_Warnings_Off
(Rectype
)
7062 -- Ignore discriminant in unchecked union, since it is
7063 -- not there, and cannot have a component clause.
7065 and then (not Is_Unchecked_Union
(Rectype
)
7066 or else Ekind
(Comp
) /= E_Discriminant
)
7068 Error_Msg_Sloc
:= Sloc
(Comp
);
7070 ("?C?no component clause given for & declared #",
7074 Next_Component_Or_Discriminant
(Comp
);
7079 end Analyze_Record_Representation_Clause
;
7081 -------------------------------------
7082 -- Build_Discrete_Static_Predicate --
7083 -------------------------------------
7085 procedure Build_Discrete_Static_Predicate
7090 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
7092 Non_Static
: exception;
7093 -- Raised if something non-static is found
7095 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
7097 BLo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Btyp
));
7098 BHi
: constant Uint
:= Expr_Value
(Type_High_Bound
(Btyp
));
7099 -- Low bound and high bound value of base type of Typ
7103 -- Bounds for constructing the static predicate. We use the bound of the
7104 -- subtype if it is static, otherwise the corresponding base type bound.
7105 -- Note: a non-static subtype can have a static predicate.
7110 -- One entry in a Rlist value, a single REnt (range entry) value denotes
7111 -- one range from Lo to Hi. To represent a single value range Lo = Hi =
7114 type RList
is array (Nat
range <>) of REnt
;
7115 -- A list of ranges. The ranges are sorted in increasing order, and are
7116 -- disjoint (there is a gap of at least one value between each range in
7117 -- the table). A value is in the set of ranges in Rlist if it lies
7118 -- within one of these ranges.
7120 False_Range
: constant RList
:=
7121 RList
'(1 .. 0 => REnt'(No_Uint
, No_Uint
));
7122 -- An empty set of ranges represents a range list that can never be
7123 -- satisfied, since there are no ranges in which the value could lie,
7124 -- so it does not lie in any of them. False_Range is a canonical value
7125 -- for this empty set, but general processing should test for an Rlist
7126 -- with length zero (see Is_False predicate), since other null ranges
7127 -- may appear which must be treated as False.
7129 True_Range
: constant RList
:= RList
'(1 => REnt'(BLo
, BHi
));
7130 -- Range representing True, value must be in the base range
7132 function "and" (Left
: RList
; Right
: RList
) return RList
;
7133 -- And's together two range lists, returning a range list. This is a set
7134 -- intersection operation.
7136 function "or" (Left
: RList
; Right
: RList
) return RList
;
7137 -- Or's together two range lists, returning a range list. This is a set
7140 function "not" (Right
: RList
) return RList
;
7141 -- Returns complement of a given range list, i.e. a range list
7142 -- representing all the values in TLo .. THi that are not in the input
7145 function Build_Val
(V
: Uint
) return Node_Id
;
7146 -- Return an analyzed N_Identifier node referencing this value, suitable
7147 -- for use as an entry in the Static_Discrte_Predicate list. This node
7148 -- is typed with the base type.
7150 function Build_Range
(Lo
: Uint
; Hi
: Uint
) return Node_Id
;
7151 -- Return an analyzed N_Range node referencing this range, suitable for
7152 -- use as an entry in the Static_Discrete_Predicate list. This node is
7153 -- typed with the base type.
7155 function Get_RList
(Exp
: Node_Id
) return RList
;
7156 -- This is a recursive routine that converts the given expression into a
7157 -- list of ranges, suitable for use in building the static predicate.
7159 function Is_False
(R
: RList
) return Boolean;
7160 pragma Inline
(Is_False
);
7161 -- Returns True if the given range list is empty, and thus represents a
7162 -- False list of ranges that can never be satisfied.
7164 function Is_True
(R
: RList
) return Boolean;
7165 -- Returns True if R trivially represents the True predicate by having a
7166 -- single range from BLo to BHi.
7168 function Is_Type_Ref
(N
: Node_Id
) return Boolean;
7169 pragma Inline
(Is_Type_Ref
);
7170 -- Returns if True if N is a reference to the type for the predicate in
7171 -- the expression (i.e. if it is an identifier whose Chars field matches
7172 -- the Nam given in the call). N must not be parenthesized, if the type
7173 -- name appears in parens, this routine will return False.
7175 function Lo_Val
(N
: Node_Id
) return Uint
;
7176 -- Given an entry from a Static_Discrete_Predicate list that is either
7177 -- a static expression or static range, gets either the expression value
7178 -- or the low bound of the range.
7180 function Hi_Val
(N
: Node_Id
) return Uint
;
7181 -- Given an entry from a Static_Discrete_Predicate list that is either
7182 -- a static expression or static range, gets either the expression value
7183 -- or the high bound of the range.
7185 function Membership_Entry
(N
: Node_Id
) return RList
;
7186 -- Given a single membership entry (range, value, or subtype), returns
7187 -- the corresponding range list. Raises Static_Error if not static.
7189 function Membership_Entries
(N
: Node_Id
) return RList
;
7190 -- Given an element on an alternatives list of a membership operation,
7191 -- returns the range list corresponding to this entry and all following
7192 -- entries (i.e. returns the "or" of this list of values).
7194 function Stat_Pred
(Typ
: Entity_Id
) return RList
;
7195 -- Given a type, if it has a static predicate, then return the predicate
7196 -- as a range list, otherwise raise Non_Static.
7202 function "and" (Left
: RList
; Right
: RList
) return RList
is
7204 -- First range of result
7206 SLeft
: Nat
:= Left
'First;
7207 -- Start of rest of left entries
7209 SRight
: Nat
:= Right
'First;
7210 -- Start of rest of right entries
7213 -- If either range is True, return the other
7215 if Is_True
(Left
) then
7217 elsif Is_True
(Right
) then
7221 -- If either range is False, return False
7223 if Is_False
(Left
) or else Is_False
(Right
) then
7227 -- Loop to remove entries at start that are disjoint, and thus just
7228 -- get discarded from the result entirely.
7231 -- If no operands left in either operand, result is false
7233 if SLeft
> Left
'Last or else SRight
> Right
'Last then
7236 -- Discard first left operand entry if disjoint with right
7238 elsif Left
(SLeft
).Hi
< Right
(SRight
).Lo
then
7241 -- Discard first right operand entry if disjoint with left
7243 elsif Right
(SRight
).Hi
< Left
(SLeft
).Lo
then
7244 SRight
:= SRight
+ 1;
7246 -- Otherwise we have an overlapping entry
7253 -- Now we have two non-null operands, and first entries overlap. The
7254 -- first entry in the result will be the overlapping part of these
7257 FEnt
:= REnt
'(Lo => UI_Max (Left (SLeft).Lo, Right (SRight).Lo),
7258 Hi => UI_Min (Left (SLeft).Hi, Right (SRight).Hi));
7260 -- Now we can remove the entry that ended at a lower value, since its
7261 -- contribution is entirely contained in Fent.
7263 if Left (SLeft).Hi <= Right (SRight).Hi then
7266 SRight := SRight + 1;
7269 -- Compute result by concatenating this first entry with the "and" of
7270 -- the remaining parts of the left and right operands. Note that if
7271 -- either of these is empty, "and" will yield empty, so that we will
7272 -- end up with just Fent, which is what we want in that case.
7275 FEnt & (Left (SLeft .. Left'Last) and Right (SRight .. Right'Last));
7282 function "not" (Right : RList) return RList is
7284 -- Return True if False range
7286 if Is_False (Right) then
7290 -- Return False if True range
7292 if Is_True (Right) then
7296 -- Here if not trivial case
7299 Result : RList (1 .. Right'Length + 1);
7300 -- May need one more entry for gap at beginning and end
7303 -- Number of entries stored in Result
7308 if Right (Right'First).Lo > TLo then
7310 Result (Count) := REnt'(TLo
, Right
(Right
'First).Lo
- 1);
7313 -- Gaps between ranges
7315 for J
in Right
'First .. Right
'Last - 1 loop
7317 Result
(Count
) := REnt
'(Right (J).Hi + 1, Right (J + 1).Lo - 1);
7322 if Right (Right'Last).Hi < THi then
7324 Result (Count) := REnt'(Right
(Right
'Last).Hi
+ 1, THi
);
7327 return Result
(1 .. Count
);
7335 function "or" (Left
: RList
; Right
: RList
) return RList
is
7337 -- First range of result
7339 SLeft
: Nat
:= Left
'First;
7340 -- Start of rest of left entries
7342 SRight
: Nat
:= Right
'First;
7343 -- Start of rest of right entries
7346 -- If either range is True, return True
7348 if Is_True
(Left
) or else Is_True
(Right
) then
7352 -- If either range is False (empty), return the other
7354 if Is_False
(Left
) then
7356 elsif Is_False
(Right
) then
7360 -- Initialize result first entry from left or right operand depending
7361 -- on which starts with the lower range.
7363 if Left
(SLeft
).Lo
< Right
(SRight
).Lo
then
7364 FEnt
:= Left
(SLeft
);
7367 FEnt
:= Right
(SRight
);
7368 SRight
:= SRight
+ 1;
7371 -- This loop eats ranges from left and right operands that are
7372 -- contiguous with the first range we are gathering.
7375 -- Eat first entry in left operand if contiguous or overlapped by
7376 -- gathered first operand of result.
7378 if SLeft
<= Left
'Last
7379 and then Left
(SLeft
).Lo
<= FEnt
.Hi
+ 1
7381 FEnt
.Hi
:= UI_Max
(FEnt
.Hi
, Left
(SLeft
).Hi
);
7384 -- Eat first entry in right operand if contiguous or overlapped by
7385 -- gathered right operand of result.
7387 elsif SRight
<= Right
'Last
7388 and then Right
(SRight
).Lo
<= FEnt
.Hi
+ 1
7390 FEnt
.Hi
:= UI_Max
(FEnt
.Hi
, Right
(SRight
).Hi
);
7391 SRight
:= SRight
+ 1;
7393 -- All done if no more entries to eat
7400 -- Obtain result as the first entry we just computed, concatenated
7401 -- to the "or" of the remaining results (if one operand is empty,
7402 -- this will just concatenate with the other
7405 FEnt
& (Left
(SLeft
.. Left
'Last) or Right
(SRight
.. Right
'Last));
7412 function Build_Range
(Lo
: Uint
; Hi
: Uint
) return Node_Id
is
7417 Low_Bound
=> Build_Val
(Lo
),
7418 High_Bound
=> Build_Val
(Hi
));
7419 Set_Etype
(Result
, Btyp
);
7420 Set_Analyzed
(Result
);
7428 function Build_Val
(V
: Uint
) return Node_Id
is
7432 if Is_Enumeration_Type
(Typ
) then
7433 Result
:= Get_Enum_Lit_From_Pos
(Typ
, V
, Loc
);
7435 Result
:= Make_Integer_Literal
(Loc
, V
);
7438 Set_Etype
(Result
, Btyp
);
7439 Set_Is_Static_Expression
(Result
);
7440 Set_Analyzed
(Result
);
7448 function Get_RList
(Exp
: Node_Id
) return RList
is
7453 -- Static expression can only be true or false
7455 if Is_OK_Static_Expression
(Exp
) then
7456 if Expr_Value
(Exp
) = 0 then
7463 -- Otherwise test node type
7471 when N_Op_And | N_And_Then
=>
7472 return Get_RList
(Left_Opnd
(Exp
))
7474 Get_RList
(Right_Opnd
(Exp
));
7478 when N_Op_Or | N_Or_Else
=>
7479 return Get_RList
(Left_Opnd
(Exp
))
7481 Get_RList
(Right_Opnd
(Exp
));
7486 return not Get_RList
(Right_Opnd
(Exp
));
7488 -- Comparisons of type with static value
7490 when N_Op_Compare
=>
7492 -- Type is left operand
7494 if Is_Type_Ref
(Left_Opnd
(Exp
))
7495 and then Is_OK_Static_Expression
(Right_Opnd
(Exp
))
7497 Val
:= Expr_Value
(Right_Opnd
(Exp
));
7499 -- Typ is right operand
7501 elsif Is_Type_Ref
(Right_Opnd
(Exp
))
7502 and then Is_OK_Static_Expression
(Left_Opnd
(Exp
))
7504 Val
:= Expr_Value
(Left_Opnd
(Exp
));
7506 -- Invert sense of comparison
7509 when N_Op_Gt
=> Op
:= N_Op_Lt
;
7510 when N_Op_Lt
=> Op
:= N_Op_Gt
;
7511 when N_Op_Ge
=> Op
:= N_Op_Le
;
7512 when N_Op_Le
=> Op
:= N_Op_Ge
;
7513 when others => null;
7516 -- Other cases are non-static
7522 -- Construct range according to comparison operation
7526 return RList
'(1 => REnt'(Val
, Val
));
7529 return RList
'(1 => REnt'(Val
, BHi
));
7532 return RList
'(1 => REnt'(Val
+ 1, BHi
));
7535 return RList
'(1 => REnt'(BLo
, Val
));
7538 return RList
'(1 => REnt'(BLo
, Val
- 1));
7541 return RList
'(REnt'(BLo
, Val
- 1), REnt
'(Val + 1, BHi));
7544 raise Program_Error;
7550 if not Is_Type_Ref (Left_Opnd (Exp)) then
7554 if Present (Right_Opnd (Exp)) then
7555 return Membership_Entry (Right_Opnd (Exp));
7557 return Membership_Entries (First (Alternatives (Exp)));
7560 -- Negative membership (NOT IN)
7563 if not Is_Type_Ref (Left_Opnd (Exp)) then
7567 if Present (Right_Opnd (Exp)) then
7568 return not Membership_Entry (Right_Opnd (Exp));
7570 return not Membership_Entries (First (Alternatives (Exp)));
7573 -- Function call, may be call to static predicate
7575 when N_Function_Call =>
7576 if Is_Entity_Name (Name (Exp)) then
7578 Ent : constant Entity_Id := Entity (Name (Exp));
7580 if Is_Predicate_Function (Ent)
7582 Is_Predicate_Function_M (Ent)
7584 return Stat_Pred (Etype (First_Formal (Ent)));
7589 -- Other function call cases are non-static
7593 -- Qualified expression, dig out the expression
7595 when N_Qualified_Expression =>
7596 return Get_RList (Expression (Exp));
7598 when N_Case_Expression =>
7605 if not Is_Entity_Name (Expression (Expr))
7606 or else Etype (Expression (Expr)) /= Typ
7609 ("expression must denaote subtype", Expression (Expr));
7613 -- Collect discrete choices in all True alternatives
7615 Choices := New_List;
7616 Alt := First (Alternatives (Exp));
7617 while Present (Alt) loop
7618 Dep := Expression (Alt);
7620 if not Is_OK_Static_Expression (Dep) then
7623 elsif Is_True (Expr_Value (Dep)) then
7624 Append_List_To (Choices,
7625 New_Copy_List (Discrete_Choices (Alt)));
7631 return Membership_Entries (First (Choices));
7634 -- Expression with actions: if no actions, dig out expression
7636 when N_Expression_With_Actions =>
7637 if Is_Empty_List (Actions (Exp)) then
7638 return Get_RList (Expression (Exp));
7646 return (Get_RList (Left_Opnd (Exp))
7647 and not Get_RList (Right_Opnd (Exp)))
7648 or (Get_RList (Right_Opnd (Exp))
7649 and not Get_RList (Left_Opnd (Exp)));
7651 -- Any other node type is non-static
7662 function Hi_Val (N : Node_Id) return Uint is
7664 if Is_OK_Static_Expression (N) then
7665 return Expr_Value (N);
7667 pragma Assert (Nkind (N) = N_Range);
7668 return Expr_Value (High_Bound (N));
7676 function Is_False (R : RList) return Boolean is
7678 return R'Length = 0;
7685 function Is_True (R : RList) return Boolean is
7688 and then R (R'First).Lo = BLo
7689 and then R (R'First).Hi = BHi;
7696 function Is_Type_Ref (N : Node_Id) return Boolean is
7698 return Nkind (N) = N_Identifier
7699 and then Chars (N) = Nam
7700 and then Paren_Count (N) = 0;
7707 function Lo_Val (N : Node_Id) return Uint is
7709 if Is_OK_Static_Expression (N) then
7710 return Expr_Value (N);
7712 pragma Assert (Nkind (N) = N_Range);
7713 return Expr_Value (Low_Bound (N));
7717 ------------------------
7718 -- Membership_Entries --
7719 ------------------------
7721 function Membership_Entries (N : Node_Id) return RList is
7723 if No (Next (N)) then
7724 return Membership_Entry (N);
7726 return Membership_Entry (N) or Membership_Entries (Next (N));
7728 end Membership_Entries;
7730 ----------------------
7731 -- Membership_Entry --
7732 ----------------------
7734 function Membership_Entry (N : Node_Id) return RList is
7742 if Nkind (N) = N_Range then
7743 if not Is_OK_Static_Expression (Low_Bound (N))
7745 not Is_OK_Static_Expression (High_Bound (N))
7749 SLo := Expr_Value (Low_Bound (N));
7750 SHi := Expr_Value (High_Bound (N));
7751 return RList'(1 => REnt
'(SLo, SHi));
7754 -- Static expression case
7756 elsif Is_OK_Static_Expression (N) then
7757 Val := Expr_Value (N);
7758 return RList'(1 => REnt
'(Val, Val));
7760 -- Identifier (other than static expression) case
7762 else pragma Assert (Nkind (N) = N_Identifier);
7766 if Is_Type (Entity (N)) then
7768 -- If type has predicates, process them
7770 if Has_Predicates (Entity (N)) then
7771 return Stat_Pred (Entity (N));
7773 -- For static subtype without predicates, get range
7775 elsif Is_OK_Static_Subtype (Entity (N)) then
7776 SLo := Expr_Value (Type_Low_Bound (Entity (N)));
7777 SHi := Expr_Value (Type_High_Bound (Entity (N)));
7778 return RList'(1 => REnt
'(SLo, SHi));
7780 -- Any other type makes us non-static
7786 -- Any other kind of identifier in predicate (e.g. a non-static
7787 -- expression value) means this is not a static predicate.
7793 end Membership_Entry;
7799 function Stat_Pred (Typ : Entity_Id) return RList is
7801 -- Not static if type does not have static predicates
7803 if not Has_Static_Predicate (Typ) then
7807 -- Otherwise we convert the predicate list to a range list
7810 Spred : constant List_Id := Static_Discrete_Predicate (Typ);
7811 Result : RList (1 .. List_Length (Spred));
7815 P := First (Static_Discrete_Predicate (Typ));
7816 for J in Result'Range loop
7817 Result (J) := REnt'(Lo_Val
(P
), Hi_Val
(P
));
7825 -- Start of processing for Build_Discrete_Static_Predicate
7828 -- Establish bounds for the predicate
7830 if Compile_Time_Known_Value
(Type_Low_Bound
(Typ
)) then
7831 TLo
:= Expr_Value
(Type_Low_Bound
(Typ
));
7836 if Compile_Time_Known_Value
(Type_High_Bound
(Typ
)) then
7837 THi
:= Expr_Value
(Type_High_Bound
(Typ
));
7842 -- Analyze the expression to see if it is a static predicate
7845 Ranges
: constant RList
:= Get_RList
(Expr
);
7846 -- Range list from expression if it is static
7851 -- Convert range list into a form for the static predicate. In the
7852 -- Ranges array, we just have raw ranges, these must be converted
7853 -- to properly typed and analyzed static expressions or range nodes.
7855 -- Note: here we limit ranges to the ranges of the subtype, so that
7856 -- a predicate is always false for values outside the subtype. That
7857 -- seems fine, such values are invalid anyway, and considering them
7858 -- to fail the predicate seems allowed and friendly, and furthermore
7859 -- simplifies processing for case statements and loops.
7863 for J
in Ranges
'Range loop
7865 Lo
: Uint
:= Ranges
(J
).Lo
;
7866 Hi
: Uint
:= Ranges
(J
).Hi
;
7869 -- Ignore completely out of range entry
7871 if Hi
< TLo
or else Lo
> THi
then
7874 -- Otherwise process entry
7877 -- Adjust out of range value to subtype range
7887 -- Convert range into required form
7889 Append_To
(Plist
, Build_Range
(Lo
, Hi
));
7894 -- Processing was successful and all entries were static, so now we
7895 -- can store the result as the predicate list.
7897 Set_Static_Discrete_Predicate
(Typ
, Plist
);
7899 -- The processing for static predicates put the expression into
7900 -- canonical form as a series of ranges. It also eliminated
7901 -- duplicates and collapsed and combined ranges. We might as well
7902 -- replace the alternatives list of the right operand of the
7903 -- membership test with the static predicate list, which will
7904 -- usually be more efficient.
7907 New_Alts
: constant List_Id
:= New_List
;
7912 Old_Node
:= First
(Plist
);
7913 while Present
(Old_Node
) loop
7914 New_Node
:= New_Copy
(Old_Node
);
7916 if Nkind
(New_Node
) = N_Range
then
7917 Set_Low_Bound
(New_Node
, New_Copy
(Low_Bound
(Old_Node
)));
7918 Set_High_Bound
(New_Node
, New_Copy
(High_Bound
(Old_Node
)));
7921 Append_To
(New_Alts
, New_Node
);
7925 -- If empty list, replace by False
7927 if Is_Empty_List
(New_Alts
) then
7928 Rewrite
(Expr
, New_Occurrence_Of
(Standard_False
, Loc
));
7930 -- Else replace by set membership test
7935 Left_Opnd
=> Make_Identifier
(Loc
, Nam
),
7936 Right_Opnd
=> Empty
,
7937 Alternatives
=> New_Alts
));
7939 -- Resolve new expression in function context
7941 Install_Formals
(Predicate_Function
(Typ
));
7942 Push_Scope
(Predicate_Function
(Typ
));
7943 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
7949 -- If non-static, return doing nothing
7954 end Build_Discrete_Static_Predicate
;
7956 --------------------------------
7957 -- Build_Export_Import_Pragma --
7958 --------------------------------
7960 function Build_Export_Import_Pragma
7962 Id
: Entity_Id
) return Node_Id
7964 Asp_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Asp
);
7965 Expr
: constant Node_Id
:= Expression
(Asp
);
7966 Loc
: constant Source_Ptr
:= Sloc
(Asp
);
7977 Create_Pragma
: Boolean := False;
7978 -- This flag is set when the aspect form is such that it warrants the
7979 -- creation of a corresponding pragma.
7982 if Present
(Expr
) then
7983 if Error_Posted
(Expr
) then
7986 elsif Is_True
(Expr_Value
(Expr
)) then
7987 Create_Pragma
:= True;
7990 -- Otherwise the aspect defaults to True
7993 Create_Pragma
:= True;
7996 -- Nothing to do when the expression is False or is erroneous
7998 if not Create_Pragma
then
8002 -- Obtain all interfacing aspects that apply to the related entity
8004 Get_Interfacing_Aspects
8008 Expo_Asp
=> Dummy_1
,
8014 -- Handle the convention argument
8016 if Present
(Conv
) then
8017 Conv_Arg
:= New_Copy_Tree
(Expression
(Conv
));
8019 -- Assume convention "Ada' when aspect Convention is missing
8022 Conv_Arg
:= Make_Identifier
(Loc
, Name_Ada
);
8026 Make_Pragma_Argument_Association
(Loc
,
8027 Chars
=> Name_Convention
,
8028 Expression
=> Conv_Arg
));
8030 -- Handle the entity argument
8033 Make_Pragma_Argument_Association
(Loc
,
8034 Chars
=> Name_Entity
,
8035 Expression
=> New_Occurrence_Of
(Id
, Loc
)));
8037 -- Handle the External_Name argument
8039 if Present
(EN
) then
8041 Make_Pragma_Argument_Association
(Loc
,
8042 Chars
=> Name_External_Name
,
8043 Expression
=> New_Copy_Tree
(Expression
(EN
))));
8046 -- Handle the Link_Name argument
8048 if Present
(LN
) then
8050 Make_Pragma_Argument_Association
(Loc
,
8051 Chars
=> Name_Link_Name
,
8052 Expression
=> New_Copy_Tree
(Expression
(LN
))));
8056 -- pragma Export/Import
8057 -- (Convention => <Conv>/Ada,
8059 -- [External_Name => <EN>,]
8060 -- [Link_Name => <LN>]);
8064 Pragma_Identifier
=>
8065 Make_Identifier
(Loc
, Chars
(Identifier
(Asp
))),
8066 Pragma_Argument_Associations
=> Args
);
8068 -- Decorate the relevant aspect and the pragma
8070 Set_Aspect_Rep_Item
(Asp
, Prag
);
8072 Set_Corresponding_Aspect
(Prag
, Asp
);
8073 Set_From_Aspect_Specification
(Prag
);
8074 Set_Parent
(Prag
, Asp
);
8076 if Asp_Id
= Aspect_Import
and then Is_Subprogram
(Id
) then
8077 Set_Import_Pragma
(Id
, Prag
);
8081 end Build_Export_Import_Pragma
;
8083 -------------------------------------------
8084 -- Build_Invariant_Procedure_Declaration --
8085 -------------------------------------------
8087 function Build_Invariant_Procedure_Declaration
8088 (Typ
: Entity_Id
) return Node_Id
8090 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
8095 Save_Ghost_Mode
: constant Ghost_Mode_Type
:= Ghost_Mode
;
8098 -- Check for duplicate definitions
8100 if Has_Invariants
(Typ
) and then Present
(Invariant_Procedure
(Typ
)) then
8104 -- The related type may be subject to pragma Ghost. Set the mode now to
8105 -- ensure that the invariant procedure is properly marked as Ghost.
8107 Set_Ghost_Mode_From_Entity
(Typ
);
8110 Make_Defining_Identifier
(Loc
,
8111 Chars
=> New_External_Name
(Chars
(Typ
), "Invariant"));
8112 Set_Has_Invariants
(Typ
);
8113 Set_Ekind
(SId
, E_Procedure
);
8114 Set_Etype
(SId
, Standard_Void_Type
);
8115 Set_Is_Invariant_Procedure
(SId
);
8116 Set_Invariant_Procedure
(Typ
, SId
);
8118 -- Source Coverage Obligations might be attached to the invariant
8119 -- expression this procedure evaluates, and we need debug info to be
8120 -- able to assess the coverage achieved by evaluations.
8122 if Opt
.Generate_SCO
then
8123 Set_Needs_Debug_Info
(SId
);
8126 -- Mark the invariant procedure explicitly as Ghost because it does not
8127 -- come from source.
8129 if Ghost_Mode
> None
then
8130 Set_Is_Ghost_Entity
(SId
);
8133 Obj_Id
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('I'));
8134 Set_Etype
(Obj_Id
, Typ
);
8137 Make_Subprogram_Declaration
(Loc
,
8138 Make_Procedure_Specification
(Loc
,
8139 Defining_Unit_Name
=> SId
,
8140 Parameter_Specifications
=> New_List
(
8141 Make_Parameter_Specification
(Loc
,
8142 Defining_Identifier
=> Obj_Id
,
8143 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)))));
8145 Ghost_Mode
:= Save_Ghost_Mode
;
8148 end Build_Invariant_Procedure_Declaration
;
8150 -------------------------------
8151 -- Build_Invariant_Procedure --
8152 -------------------------------
8154 -- The procedure that is constructed here has the form
8156 -- procedure typInvariant (Ixxx : typ) is
8158 -- pragma Check (Invariant, exp, "failed invariant from xxx");
8159 -- pragma Check (Invariant, exp, "failed invariant from xxx");
8161 -- pragma Check (Invariant, exp, "failed inherited invariant from xxx");
8163 -- end typInvariant;
8165 procedure Build_Invariant_Procedure
(Typ
: Entity_Id
; N
: Node_Id
) is
8166 procedure Add_Invariants
8169 Stmts
: in out List_Id
;
8171 -- Appends statements to Stmts for any invariants in the rep item chain
8172 -- of the given type. If Inherit is False, then we only process entries
8173 -- on the chain for the type Typ. If Inherit is True, then we ignore any
8174 -- Invariant aspects, but we process all Invariant'Class aspects, adding
8175 -- "inherited" to the exception message and generating an informational
8176 -- message about the inheritance of an invariant.
8178 --------------------
8179 -- Add_Invariants --
8180 --------------------
8182 procedure Add_Invariants
8185 Stmts
: in out List_Id
;
8188 procedure Add_Invariant
(Prag
: Node_Id
);
8189 -- Create a runtime check to verify the exression of invariant pragma
8190 -- Prag. All generated code is added to list Stmts.
8196 procedure Add_Invariant
(Prag
: Node_Id
) is
8197 procedure Replace_Type_Reference
(N
: Node_Id
);
8198 -- Replace a single occurrence N of the subtype name with a
8199 -- reference to the formal of the predicate function. N can be an
8200 -- identifier referencing the subtype, or a selected component,
8201 -- representing an appropriately qualified occurrence of the
8204 procedure Replace_Type_References
is
8205 new Replace_Type_References_Generic
(Replace_Type_Reference
);
8206 -- Traverse an expression replacing all occurrences of the subtype
8207 -- name with appropriate references to the formal of the predicate
8208 -- function. Note that we must ensure that the type and entity
8209 -- information is properly set in the replacement node, since we
8210 -- will do a Preanalyze call of this expression without proper
8211 -- visibility of the procedure argument.
8213 ----------------------------
8214 -- Replace_Type_Reference --
8215 ----------------------------
8217 -- Note: See comments in Add_Predicates.Replace_Type_Reference
8218 -- regarding handling of Sloc and Comes_From_Source.
8220 procedure Replace_Type_Reference
(N
: Node_Id
) is
8221 Nloc
: constant Source_Ptr
:= Sloc
(N
);
8224 -- Add semantic information to node to be rewritten, for ASIS
8225 -- navigation needs.
8227 if Nkind
(N
) = N_Identifier
then
8231 elsif Nkind
(N
) = N_Selected_Component
then
8232 Analyze
(Prefix
(N
));
8233 Set_Entity
(Selector_Name
(N
), T
);
8234 Set_Etype
(Selector_Name
(N
), T
);
8237 -- Invariant'Class, replace with T'Class (obj)
8239 if Class_Present
(Prag
) then
8241 -- In ASIS mode, an inherited item is already analyzed,
8242 -- and the replacement has been done, so do not repeat
8243 -- the transformation to prevent a malformed tree.
8246 and then Nkind
(Parent
(N
)) = N_Attribute_Reference
8247 and then Attribute_Name
(Parent
(N
)) = Name_Class
8253 Make_Type_Conversion
(Nloc
,
8255 Make_Attribute_Reference
(Nloc
,
8256 Prefix
=> New_Occurrence_Of
(T
, Nloc
),
8257 Attribute_Name
=> Name_Class
),
8259 Make_Identifier
(Nloc
, Chars
(Obj_Id
))));
8261 Set_Entity
(Expression
(N
), Obj_Id
);
8262 Set_Etype
(Expression
(N
), Typ
);
8265 -- Invariant, replace with obj
8268 Rewrite
(N
, Make_Identifier
(Nloc
, Chars
(Obj_Id
)));
8269 Set_Entity
(N
, Obj_Id
);
8273 Set_Comes_From_Source
(N
, True);
8274 end Replace_Type_Reference
;
8278 Asp
: constant Node_Id
:= Corresponding_Aspect
(Prag
);
8279 Nam
: constant Name_Id
:= Original_Aspect_Pragma_Name
(Prag
);
8280 Ploc
: constant Source_Ptr
:= Sloc
(Prag
);
8288 -- Start of processing for Add_Invariant
8291 -- Extract the arguments of the invariant pragma
8293 Arg1
:= First
(Pragma_Argument_Associations
(Prag
));
8294 Arg2
:= Next
(Arg1
);
8295 Arg3
:= Next
(Arg2
);
8297 Arg1
:= Get_Pragma_Arg
(Arg1
);
8298 Arg2
:= Get_Pragma_Arg
(Arg2
);
8300 -- The caller requests processing of all Invariant'Class pragmas,
8301 -- but the current pragma does not fall in this category. Return
8302 -- as there is nothing left to do.
8305 if not Class_Present
(Prag
) then
8309 -- Otherwise the pragma must apply to the current type
8311 elsif Entity
(Arg1
) /= T
then
8315 Expr
:= New_Copy_Tree
(Arg2
);
8317 -- Replace all occurrences of the type's name with references to
8318 -- the formal parameter of the invariant procedure.
8320 Replace_Type_References
(Expr
, T
);
8322 -- If the invariant pragma comes from an aspect, replace the saved
8323 -- expression because we need the subtype references replaced for
8324 -- the calls to Preanalyze_Spec_Expression in Check_Aspect_At_xxx
8325 -- routines. This is not done for interited class-wide invariants
8326 -- because the original pragma of the parent type must remain
8329 if not Inherit
and then Present
(Asp
) then
8330 Set_Entity
(Identifier
(Asp
), New_Copy_Tree
(Expr
));
8333 -- Preanalyze the invariant expression to capture the visibility
8334 -- of the proper package part. In general the expression is not
8335 -- fully analyzed until the body of the invariant procedure is
8336 -- analyzed at the end of the private part, but that yields the
8337 -- wrong visibility.
8339 -- Historical note: we used to set N as the parent, but a package
8340 -- specification as the parent of an expression is bizarre.
8342 Set_Parent
(Expr
, Parent
(Arg2
));
8343 Preanalyze_Assert_Expression
(Expr
, Any_Boolean
);
8345 -- Both modifications performed below are not done for inherited
8346 -- class-wide invariants because the origial aspect/pragma of the
8347 -- parent type must remain unchanged.
8351 -- A class-wide invariant may be inherited in a separate unit,
8352 -- where the corresponding expression cannot be resolved by
8353 -- visibility, because it refers to a local function. Propagate
8354 -- semantic information to the original representation item, to
8355 -- be used when an invariant procedure for a derived type is
8358 -- ??? Unclear how to handle class-wide invariants that are not
8361 if Class_Present
(Prag
)
8362 and then Nkind
(Expr
) = N_Function_Call
8363 and then Nkind
(Arg2
) = N_Indexed_Component
8366 Make_Function_Call
(Ploc
,
8368 New_Occurrence_Of
(Entity
(Name
(Expr
)), Ploc
),
8369 Parameter_Associations
=> Expressions
(Arg2
)));
8372 -- In ASIS mode, even if assertions are not enabled, we must
8373 -- analyze the original expression in the aspect specification
8374 -- because it is part of the original tree.
8376 if ASIS_Mode
and then Present
(Asp
) then
8378 Asp_Expr
: constant Node_Id
:= Expression
(Asp
);
8381 Replace_Type_References
(Asp_Expr
, T
);
8382 Preanalyze_Assert_Expression
(Asp_Expr
, Any_Boolean
);
8387 -- An ignored invariant must not generate a runtime check. Add a
8388 -- null statement to ensure that the invariant procedure does get
8389 -- a completing body.
8392 Stmts
:= Empty_List
;
8395 if Is_Ignored
(Prag
) then
8396 Append_To
(Stmts
, Make_Null_Statement
(Ploc
));
8398 -- Otherwise the invariant is checked. Build a Check pragma to
8399 -- verify the expression at runtime.
8403 Make_Pragma_Argument_Association
(Ploc
,
8404 Expression
=> Make_Identifier
(Ploc
, Nam
)),
8405 Make_Pragma_Argument_Association
(Ploc
,
8406 Expression
=> Expr
));
8408 -- Handle the String argument (if any)
8410 if Present
(Arg3
) then
8411 Str
:= Strval
(Get_Pragma_Arg
(Arg3
));
8413 -- When inheriting an invariant, modify the message from
8414 -- "failed invariant" to "failed inherited invariant".
8417 String_To_Name_Buffer
(Str
);
8419 if Name_Buffer
(1 .. 16) = "failed invariant" then
8420 Insert_Str_In_Name_Buffer
("inherited ", 8);
8421 Str
:= String_From_Name_Buffer
;
8426 Make_Pragma_Argument_Association
(Ploc
,
8427 Expression
=> Make_String_Literal
(Ploc
, Str
)));
8431 -- pragma Check (Nam, Expr, Str);
8435 Pragma_Identifier
=>
8436 Make_Identifier
(Ploc
, Name_Check
),
8437 Pragma_Argument_Associations
=> Assoc
));
8440 -- Output an info message when inheriting an invariant and the
8441 -- listing option is enabled.
8443 if Inherit
and Opt
.List_Inherited_Aspects
then
8444 Error_Msg_Sloc
:= Sloc
(Prag
);
8446 ("info: & inherits `Invariant''Class` aspect from #?L?", Typ
);
8454 -- Start of processing for Add_Invariants
8457 Ritem
:= First_Rep_Item
(T
);
8458 while Present
(Ritem
) loop
8459 if Nkind
(Ritem
) = N_Pragma
8460 and then Pragma_Name
(Ritem
) = Name_Invariant
8462 Add_Invariant
(Ritem
);
8465 Next_Rep_Item
(Ritem
);
8471 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
8472 Priv_Decls
: constant List_Id
:= Private_Declarations
(N
);
8473 Vis_Decls
: constant List_Id
:= Visible_Declarations
(N
);
8475 Save_Ghost_Mode
: constant Ghost_Mode_Type
:= Ghost_Mode
;
8484 -- The entity of the formal for the procedure
8486 -- Start of processing for Build_Invariant_Procedure
8489 -- The related type may be subject to pragma Ghost. Set the mode now to
8490 -- ensure that the invariant procedure is properly marked as Ghost.
8492 Set_Ghost_Mode_From_Entity
(Typ
);
8499 -- If the aspect specification exists for some view of the type, the
8500 -- declaration for the procedure has been created.
8502 if Has_Invariants
(Typ
) then
8503 SId
:= Invariant_Procedure
(Typ
);
8506 -- If the body is already present, nothing to do. This will occur when
8507 -- the type is already frozen, which is the case when the invariant
8508 -- appears in a private part, and the freezing takes place before the
8509 -- final pass over full declarations.
8511 -- See Exp_Ch3.Insert_Component_Invariant_Checks for details.
8513 if Present
(SId
) then
8514 PDecl
:= Unit_Declaration_Node
(SId
);
8517 and then Nkind
(PDecl
) = N_Subprogram_Declaration
8518 and then Present
(Corresponding_Body
(PDecl
))
8520 Ghost_Mode
:= Save_Ghost_Mode
;
8525 PDecl
:= Build_Invariant_Procedure_Declaration
(Typ
);
8528 -- Recover formal of procedure, for use in the calls to invariant
8529 -- functions (including inherited ones).
8533 (First
(Parameter_Specifications
(Specification
(PDecl
))));
8535 -- Add invariants for the current type
8543 -- Add invariants for parent types
8546 Current_Typ
: Entity_Id
;
8547 Parent_Typ
: Entity_Id
;
8552 Parent_Typ
:= Etype
(Current_Typ
);
8554 if Is_Private_Type
(Parent_Typ
)
8555 and then Present
(Full_View
(Base_Type
(Parent_Typ
)))
8557 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
8560 exit when Parent_Typ
= Current_Typ
;
8562 Current_Typ
:= Parent_Typ
;
8571 -- Add invariants of progenitors
8573 if Is_Tagged_Type
(Typ
) and then not Is_Interface
(Typ
) then
8575 Ifaces_List
: Elist_Id
;
8580 Collect_Interfaces
(Typ
, Ifaces_List
);
8582 AI
:= First_Elmt
(Ifaces_List
);
8583 while Present
(AI
) loop
8586 if not Is_Ancestor
(Iface
, Typ
, Use_Full_View
=> True) then
8599 -- Build the procedure if we generated at least one Check pragma
8601 if Stmts
/= No_List
then
8602 Spec
:= Copy_Separate_Tree
(Specification
(PDecl
));
8605 Make_Subprogram_Body
(Loc
,
8606 Specification
=> Spec
,
8607 Declarations
=> Empty_List
,
8608 Handled_Statement_Sequence
=>
8609 Make_Handled_Sequence_Of_Statements
(Loc
,
8610 Statements
=> Stmts
));
8612 -- The processing of an invariant pragma immediately generates the
8613 -- invariant procedure spec, inserts it into the tree, and analyzes
8614 -- it. If the spec has not been analyzed, then the invariant pragma
8615 -- is being inherited and requires manual insertion and analysis.
8617 if not Analyzed
(PDecl
) then
8618 Append_To
(Vis_Decls
, PDecl
);
8622 -- The invariant procedure body is inserted at the end of the private
8625 if Present
(Priv_Decls
) then
8626 Append_To
(Priv_Decls
, PBody
);
8628 -- If the invariant appears on the full view of a private type,
8629 -- then the analysis of the private part is already completed.
8630 -- Manually analyze the new body in this case, otherwise wait
8631 -- for the analysis of the private declarations to process the
8634 if In_Private_Part
(Current_Scope
) then
8638 -- Otherwise there are no private declarations. This is either an
8639 -- error or the related type is a private extension, in which case
8640 -- it does not need a completion in a private part. Insert the body
8641 -- at the end of the visible declarations and analyze immediately
8642 -- because the related type is about to be frozen.
8645 Append_To
(Vis_Decls
, PBody
);
8650 Ghost_Mode
:= Save_Ghost_Mode
;
8651 end Build_Invariant_Procedure
;
8653 -------------------------------
8654 -- Build_Predicate_Functions --
8655 -------------------------------
8657 -- The procedures that are constructed here have the form:
8659 -- function typPredicate (Ixxx : typ) return Boolean is
8662 -- typ1Predicate (typ1 (Ixxx))
8663 -- and then typ2Predicate (typ2 (Ixxx))
8665 -- exp1 and then exp2 and then ...
8666 -- end typPredicate;
8668 -- Here exp1, and exp2 are expressions from Predicate pragmas. Note that
8669 -- this is the point at which these expressions get analyzed, providing the
8670 -- required delay, and typ1, typ2, are entities from which predicates are
8671 -- inherited. Note that we do NOT generate Check pragmas, that's because we
8672 -- use this function even if checks are off, e.g. for membership tests.
8674 -- Note that the inherited predicates are evaluated first, as required by
8677 -- Note that Sem_Eval.Real_Or_String_Static_Predicate_Matches depends on
8678 -- the form of this return expression.
8680 -- If the expression has at least one Raise_Expression, then we also build
8681 -- the typPredicateM version of the function, in which any occurrence of a
8682 -- Raise_Expression is converted to "return False".
8684 procedure Build_Predicate_Functions
(Typ
: Entity_Id
; N
: Node_Id
) is
8685 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
8688 -- This is the expression for the result of the function. It is
8689 -- is build by connecting the component predicates with AND THEN.
8692 -- This is the corresponding return expression for the Predicate_M
8693 -- function. It differs in that raise expressions are marked for
8694 -- special expansion (see Process_REs).
8696 Object_Name
: Name_Id
;
8697 -- Name for argument of Predicate procedure. Note that we use the same
8698 -- name for both predicate functions. That way the reference within the
8699 -- predicate expression is the same in both functions.
8701 Object_Entity
: Entity_Id
;
8702 -- Entity for argument of Predicate procedure
8704 Object_Entity_M
: Entity_Id
;
8705 -- Entity for argument of separate Predicate procedure when exceptions
8706 -- are present in expression.
8709 -- The function declaration
8714 Raise_Expression_Present
: Boolean := False;
8715 -- Set True if Expr has at least one Raise_Expression
8717 procedure Add_Condition
(Cond
: Node_Id
);
8718 -- Append Cond to Expr using "and then" (or just copy Cond to Expr if
8721 procedure Add_Predicates
;
8722 -- Appends expressions for any Predicate pragmas in the rep item chain
8723 -- Typ to Expr. Note that we look only at items for this exact entity.
8724 -- Inheritance of predicates for the parent type is done by calling the
8725 -- Predicate_Function of the parent type, using Add_Call above.
8727 procedure Add_Call
(T
: Entity_Id
);
8728 -- Includes a call to the predicate function for type T in Expr if T
8729 -- has predicates and Predicate_Function (T) is non-empty.
8731 function Process_RE
(N
: Node_Id
) return Traverse_Result
;
8732 -- Used in Process REs, tests if node N is a raise expression, and if
8733 -- so, marks it to be converted to return False.
8735 procedure Process_REs
is new Traverse_Proc
(Process_RE
);
8736 -- Marks any raise expressions in Expr_M to return False
8738 function Test_RE
(N
: Node_Id
) return Traverse_Result
;
8739 -- Used in Test_REs, tests one node for being a raise expression, and if
8740 -- so sets Raise_Expression_Present True.
8742 procedure Test_REs
is new Traverse_Proc
(Test_RE
);
8743 -- Tests to see if Expr contains any raise expressions
8749 procedure Add_Call
(T
: Entity_Id
) is
8753 if Present
(T
) and then Present
(Predicate_Function
(T
)) then
8754 Set_Has_Predicates
(Typ
);
8756 -- Build the call to the predicate function of T
8760 (T
, Convert_To
(T
, Make_Identifier
(Loc
, Object_Name
)));
8762 -- "and"-in the call to evolving expression
8764 Add_Condition
(Exp
);
8766 -- Output info message on inheritance if required. Note we do not
8767 -- give this information for generic actual types, since it is
8768 -- unwelcome noise in that case in instantiations. We also
8769 -- generally suppress the message in instantiations, and also
8770 -- if it involves internal names.
8772 if Opt
.List_Inherited_Aspects
8773 and then not Is_Generic_Actual_Type
(Typ
)
8774 and then Instantiation_Depth
(Sloc
(Typ
)) = 0
8775 and then not Is_Internal_Name
(Chars
(T
))
8776 and then not Is_Internal_Name
(Chars
(Typ
))
8778 Error_Msg_Sloc
:= Sloc
(Predicate_Function
(T
));
8779 Error_Msg_Node_2
:= T
;
8780 Error_Msg_N
("info: & inherits predicate from & #?L?", Typ
);
8789 procedure Add_Condition
(Cond
: Node_Id
) is
8791 -- This is the first predicate expression
8796 -- Otherwise concatenate to the existing predicate expressions by
8797 -- using "and then".
8802 Left_Opnd
=> Relocate_Node
(Expr
),
8803 Right_Opnd
=> Cond
);
8807 --------------------
8808 -- Add_Predicates --
8809 --------------------
8811 procedure Add_Predicates
is
8812 procedure Add_Predicate
(Prag
: Node_Id
);
8813 -- Concatenate the expression of predicate pragma Prag to Expr by
8814 -- using a short circuit "and then" operator.
8820 procedure Add_Predicate
(Prag
: Node_Id
) is
8821 procedure Replace_Type_Reference
(N
: Node_Id
);
8822 -- Replace a single occurrence N of the subtype name with a
8823 -- reference to the formal of the predicate function. N can be an
8824 -- identifier referencing the subtype, or a selected component,
8825 -- representing an appropriately qualified occurrence of the
8828 procedure Replace_Type_References
is
8829 new Replace_Type_References_Generic
(Replace_Type_Reference
);
8830 -- Traverse an expression changing every occurrence of an
8831 -- identifier whose name matches the name of the subtype with a
8832 -- reference to the formal parameter of the predicate function.
8834 ----------------------------
8835 -- Replace_Type_Reference --
8836 ----------------------------
8838 procedure Replace_Type_Reference
(N
: Node_Id
) is
8840 Rewrite
(N
, Make_Identifier
(Sloc
(N
), Object_Name
));
8841 -- Use the Sloc of the usage name, not the defining name
8844 Set_Entity
(N
, Object_Entity
);
8846 -- We want to treat the node as if it comes from source, so
8847 -- that ASIS will not ignore it.
8849 Set_Comes_From_Source
(N
, True);
8850 end Replace_Type_Reference
;
8854 Asp
: constant Node_Id
:= Corresponding_Aspect
(Prag
);
8858 -- Start of processing for Add_Predicate
8861 -- Extract the arguments of the pragma. The expression itself
8862 -- is copied for use in the predicate function, to preserve the
8863 -- original version for ASIS use.
8865 Arg1
:= First
(Pragma_Argument_Associations
(Prag
));
8866 Arg2
:= Next
(Arg1
);
8868 Arg1
:= Get_Pragma_Arg
(Arg1
);
8869 Arg2
:= New_Copy_Tree
(Get_Pragma_Arg
(Arg2
));
8871 -- When the predicate pragma applies to the current type or its
8872 -- full view, replace all occurrences of the subtype name with
8873 -- references to the formal parameter of the predicate function.
8875 if Entity
(Arg1
) = Typ
8876 or else Full_View
(Entity
(Arg1
)) = Typ
8878 Replace_Type_References
(Arg2
, Typ
);
8880 -- If the predicate pragma comes from an aspect, replace the
8881 -- saved expression because we need the subtype references
8882 -- replaced for the calls to Preanalyze_Spec_Expression in
8883 -- Check_Aspect_At_xxx routines.
8885 if Present
(Asp
) then
8886 Set_Entity
(Identifier
(Asp
), New_Copy_Tree
(Arg2
));
8889 -- "and"-in the Arg2 condition to evolving expression
8891 Add_Condition
(Relocate_Node
(Arg2
));
8899 -- Start of processing for Add_Predicates
8902 Ritem
:= First_Rep_Item
(Typ
);
8903 while Present
(Ritem
) loop
8904 if Nkind
(Ritem
) = N_Pragma
8905 and then Pragma_Name
(Ritem
) = Name_Predicate
8907 Add_Predicate
(Ritem
);
8909 -- If the type is declared in an inner package it may be frozen
8910 -- outside of the package, and the generated pragma has not been
8911 -- analyzed yet, so capture the expression for the predicate
8912 -- function at this point.
8914 elsif Nkind
(Ritem
) = N_Aspect_Specification
8915 and then Present
(Aspect_Rep_Item
(Ritem
))
8916 and then Scope
(Typ
) /= Current_Scope
8919 Prag
: constant Node_Id
:= Aspect_Rep_Item
(Ritem
);
8922 if Nkind
(Prag
) = N_Pragma
8923 and then Pragma_Name
(Prag
) = Name_Predicate
8925 Add_Predicate
(Prag
);
8930 Next_Rep_Item
(Ritem
);
8938 function Process_RE
(N
: Node_Id
) return Traverse_Result
is
8940 if Nkind
(N
) = N_Raise_Expression
then
8941 Set_Convert_To_Return_False
(N
);
8952 function Test_RE
(N
: Node_Id
) return Traverse_Result
is
8954 if Nkind
(N
) = N_Raise_Expression
then
8955 Raise_Expression_Present
:= True;
8964 Save_Ghost_Mode
: constant Ghost_Mode_Type
:= Ghost_Mode
;
8966 -- Start of processing for Build_Predicate_Functions
8969 -- Return if already built or if type does not have predicates
8971 SId
:= Predicate_Function
(Typ
);
8972 if not Has_Predicates
(Typ
)
8973 or else (Present
(SId
) and then Has_Completion
(SId
))
8978 -- The related type may be subject to pragma Ghost. Set the mode now to
8979 -- ensure that the predicate functions are properly marked as Ghost.
8981 Set_Ghost_Mode_From_Entity
(Typ
);
8983 -- Prepare to construct predicate expression
8987 if Present
(SId
) then
8988 FDecl
:= Unit_Declaration_Node
(SId
);
8991 FDecl
:= Build_Predicate_Function_Declaration
(Typ
);
8992 SId
:= Defining_Entity
(FDecl
);
8995 -- Recover name of formal parameter of function that replaces references
8996 -- to the type in predicate expressions.
9000 (First
(Parameter_Specifications
(Specification
(FDecl
))));
9002 Object_Name
:= Chars
(Object_Entity
);
9003 Object_Entity_M
:= Make_Defining_Identifier
(Loc
, Chars
=> Object_Name
);
9005 -- Add predicates for ancestor if present. These must come before the
9006 -- ones for the current type, as required by AI12-0071-1.
9009 Atyp
: constant Entity_Id
:= Nearest_Ancestor
(Typ
);
9011 if Present
(Atyp
) then
9016 -- Add Predicates for the current type
9020 -- Case where predicates are present
9022 if Present
(Expr
) then
9024 -- Test for raise expression present
9028 -- If raise expression is present, capture a copy of Expr for use
9029 -- in building the predicateM function version later on. For this
9030 -- copy we replace references to Object_Entity by Object_Entity_M.
9032 if Raise_Expression_Present
then
9034 Map
: constant Elist_Id
:= New_Elmt_List
;
9035 New_V
: Entity_Id
:= Empty
;
9037 -- The unanalyzed expression will be copied and appear in
9038 -- both functions. Normally expressions do not declare new
9039 -- entities, but quantified expressions do, so we need to
9040 -- create new entities for their bound variables, to prevent
9041 -- multiple definitions in gigi.
9043 function Reset_Loop_Variable
(N
: Node_Id
)
9044 return Traverse_Result
;
9046 procedure Collect_Loop_Variables
is
9047 new Traverse_Proc
(Reset_Loop_Variable
);
9049 ------------------------
9050 -- Reset_Loop_Variable --
9051 ------------------------
9053 function Reset_Loop_Variable
(N
: Node_Id
)
9054 return Traverse_Result
9057 if Nkind
(N
) = N_Iterator_Specification
then
9058 New_V
:= Make_Defining_Identifier
9059 (Sloc
(N
), Chars
(Defining_Identifier
(N
)));
9061 Set_Defining_Identifier
(N
, New_V
);
9065 end Reset_Loop_Variable
;
9068 Append_Elmt
(Object_Entity
, Map
);
9069 Append_Elmt
(Object_Entity_M
, Map
);
9070 Expr_M
:= New_Copy_Tree
(Expr
, Map
=> Map
);
9071 Collect_Loop_Variables
(Expr_M
);
9075 -- Build the main predicate function
9078 SIdB
: constant Entity_Id
:=
9079 Make_Defining_Identifier
(Loc
,
9080 Chars
=> New_External_Name
(Chars
(Typ
), "Predicate"));
9081 -- The entity for the function body
9088 -- The predicate function is shared between views of a type
9090 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
9091 Set_Predicate_Function
(Full_View
(Typ
), SId
);
9094 -- Mark the predicate function explicitly as Ghost because it does
9095 -- not come from source.
9097 if Ghost_Mode
> None
then
9098 Set_Is_Ghost_Entity
(SId
);
9101 -- Build function body
9104 Make_Function_Specification
(Loc
,
9105 Defining_Unit_Name
=> SIdB
,
9106 Parameter_Specifications
=> New_List
(
9107 Make_Parameter_Specification
(Loc
,
9108 Defining_Identifier
=>
9109 Make_Defining_Identifier
(Loc
, Object_Name
),
9111 New_Occurrence_Of
(Typ
, Loc
))),
9112 Result_Definition
=>
9113 New_Occurrence_Of
(Standard_Boolean
, Loc
));
9116 Make_Subprogram_Body
(Loc
,
9117 Specification
=> Spec
,
9118 Declarations
=> Empty_List
,
9119 Handled_Statement_Sequence
=>
9120 Make_Handled_Sequence_Of_Statements
(Loc
,
9121 Statements
=> New_List
(
9122 Make_Simple_Return_Statement
(Loc
,
9123 Expression
=> Expr
))));
9125 -- If declaration has not been analyzed yet, Insert declaration
9126 -- before freeze node.
9127 -- Insert body after freeze node.
9129 if not Analyzed
(FDecl
) then
9130 Insert_Before_And_Analyze
(N
, FDecl
);
9133 Insert_After_And_Analyze
(N
, FBody
);
9135 -- Static predicate functions are always side-effect free, and
9136 -- in most cases dynamic predicate functions are as well. Mark
9137 -- them as such whenever possible, so redundant predicate checks
9138 -- can be optimized. If there is a variable reference within the
9139 -- expression, the function is not pure.
9141 if Expander_Active
then
9143 Side_Effect_Free
(Expr
, Variable_Ref
=> True));
9144 Set_Is_Inlined
(SId
);
9148 -- Test for raise expressions present and if so build M version
9150 if Raise_Expression_Present
then
9152 SId
: constant Entity_Id
:=
9153 Make_Defining_Identifier
(Loc
,
9154 Chars
=> New_External_Name
(Chars
(Typ
), "PredicateM"));
9155 -- The entity for the function spec
9157 SIdB
: constant Entity_Id
:=
9158 Make_Defining_Identifier
(Loc
,
9159 Chars
=> New_External_Name
(Chars
(Typ
), "PredicateM"));
9160 -- The entity for the function body
9168 -- Mark any raise expressions for special expansion
9170 Process_REs
(Expr_M
);
9172 -- Build function declaration
9174 Set_Ekind
(SId
, E_Function
);
9175 Set_Is_Predicate_Function_M
(SId
);
9176 Set_Predicate_Function_M
(Typ
, SId
);
9178 -- The predicate function is shared between views of a type
9180 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
9181 Set_Predicate_Function_M
(Full_View
(Typ
), SId
);
9184 -- Mark the predicate function explicitly as Ghost because it
9185 -- does not come from source.
9187 if Ghost_Mode
> None
then
9188 Set_Is_Ghost_Entity
(SId
);
9192 Make_Function_Specification
(Loc
,
9193 Defining_Unit_Name
=> SId
,
9194 Parameter_Specifications
=> New_List
(
9195 Make_Parameter_Specification
(Loc
,
9196 Defining_Identifier
=> Object_Entity_M
,
9197 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))),
9198 Result_Definition
=>
9199 New_Occurrence_Of
(Standard_Boolean
, Loc
));
9202 Make_Subprogram_Declaration
(Loc
,
9203 Specification
=> Spec
);
9205 -- Build function body
9208 Make_Function_Specification
(Loc
,
9209 Defining_Unit_Name
=> SIdB
,
9210 Parameter_Specifications
=> New_List
(
9211 Make_Parameter_Specification
(Loc
,
9212 Defining_Identifier
=>
9213 Make_Defining_Identifier
(Loc
, Object_Name
),
9215 New_Occurrence_Of
(Typ
, Loc
))),
9216 Result_Definition
=>
9217 New_Occurrence_Of
(Standard_Boolean
, Loc
));
9219 -- Build the body, we declare the boolean expression before
9220 -- doing the return, because we are not really confident of
9221 -- what happens if a return appears within a return.
9224 Make_Defining_Identifier
(Loc
,
9225 Chars
=> New_Internal_Name
('B'));
9228 Make_Subprogram_Body
(Loc
,
9229 Specification
=> Spec
,
9231 Declarations
=> New_List
(
9232 Make_Object_Declaration
(Loc
,
9233 Defining_Identifier
=> BTemp
,
9234 Constant_Present
=> True,
9235 Object_Definition
=>
9236 New_Occurrence_Of
(Standard_Boolean
, Loc
),
9237 Expression
=> Expr_M
)),
9239 Handled_Statement_Sequence
=>
9240 Make_Handled_Sequence_Of_Statements
(Loc
,
9241 Statements
=> New_List
(
9242 Make_Simple_Return_Statement
(Loc
,
9243 Expression
=> New_Occurrence_Of
(BTemp
, Loc
)))));
9245 -- Insert declaration before freeze node and body after
9247 Insert_Before_And_Analyze
(N
, FDecl
);
9248 Insert_After_And_Analyze
(N
, FBody
);
9252 -- See if we have a static predicate. Note that the answer may be
9253 -- yes even if we have an explicit Dynamic_Predicate present.
9260 if not Is_Scalar_Type
(Typ
) and then not Is_String_Type
(Typ
) then
9263 PS
:= Is_Predicate_Static
(Expr
, Object_Name
);
9266 -- Case where we have a predicate-static aspect
9270 -- We don't set Has_Static_Predicate_Aspect, since we can have
9271 -- any of the three cases (Predicate, Dynamic_Predicate, or
9272 -- Static_Predicate) generating a predicate with an expression
9273 -- that is predicate-static. We just indicate that we have a
9274 -- predicate that can be treated as static.
9276 Set_Has_Static_Predicate
(Typ
);
9278 -- For discrete subtype, build the static predicate list
9280 if Is_Discrete_Type
(Typ
) then
9281 Build_Discrete_Static_Predicate
(Typ
, Expr
, Object_Name
);
9283 -- If we don't get a static predicate list, it means that we
9284 -- have a case where this is not possible, most typically in
9285 -- the case where we inherit a dynamic predicate. We do not
9286 -- consider this an error, we just leave the predicate as
9287 -- dynamic. But if we do succeed in building the list, then
9288 -- we mark the predicate as static.
9290 if No
(Static_Discrete_Predicate
(Typ
)) then
9291 Set_Has_Static_Predicate
(Typ
, False);
9294 -- For real or string subtype, save predicate expression
9296 elsif Is_Real_Type
(Typ
) or else Is_String_Type
(Typ
) then
9297 Set_Static_Real_Or_String_Predicate
(Typ
, Expr
);
9300 -- Case of dynamic predicate (expression is not predicate-static)
9303 -- Again, we don't set Has_Dynamic_Predicate_Aspect, since that
9304 -- is only set if we have an explicit Dynamic_Predicate aspect
9305 -- given. Here we may simply have a Predicate aspect where the
9306 -- expression happens not to be predicate-static.
9308 -- Emit an error when the predicate is categorized as static
9309 -- but its expression is not predicate-static.
9311 -- First a little fiddling to get a nice location for the
9312 -- message. If the expression is of the form (A and then B),
9313 -- where A is an inherited predicate, then use the right
9314 -- operand for the Sloc. This avoids getting confused by a call
9315 -- to an inherited predicate with a less convenient source
9319 while Nkind
(EN
) = N_And_Then
9320 and then Nkind
(Left_Opnd
(EN
)) = N_Function_Call
9321 and then Is_Predicate_Function
9322 (Entity
(Name
(Left_Opnd
(EN
))))
9324 EN
:= Right_Opnd
(EN
);
9327 -- Now post appropriate message
9329 if Has_Static_Predicate_Aspect
(Typ
) then
9330 if Is_Scalar_Type
(Typ
) or else Is_String_Type
(Typ
) then
9332 ("expression is not predicate-static (RM 3.2.4(16-22))",
9336 ("static predicate requires scalar or string type", EN
);
9343 Ghost_Mode
:= Save_Ghost_Mode
;
9344 end Build_Predicate_Functions
;
9346 ------------------------------------------
9347 -- Build_Predicate_Function_Declaration --
9348 ------------------------------------------
9350 function Build_Predicate_Function_Declaration
9351 (Typ
: Entity_Id
) return Node_Id
9353 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
9355 Object_Entity
: constant Entity_Id
:=
9356 Make_Defining_Identifier
(Loc
,
9357 Chars
=> New_Internal_Name
('I'));
9359 -- The formal parameter of the function
9361 SId
: constant Entity_Id
:=
9362 Make_Defining_Identifier
(Loc
,
9363 Chars
=> New_External_Name
(Chars
(Typ
), "Predicate"));
9365 -- The entity for the function spec
9372 Make_Function_Specification
(Loc
,
9373 Defining_Unit_Name
=> SId
,
9374 Parameter_Specifications
=> New_List
(
9375 Make_Parameter_Specification
(Loc
,
9376 Defining_Identifier
=> Object_Entity
,
9377 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))),
9378 Result_Definition
=>
9379 New_Occurrence_Of
(Standard_Boolean
, Loc
));
9381 FDecl
:= Make_Subprogram_Declaration
(Loc
, Specification
=> Spec
);
9383 Set_Ekind
(SId
, E_Function
);
9384 Set_Etype
(SId
, Standard_Boolean
);
9385 Set_Is_Internal
(SId
);
9386 Set_Is_Predicate_Function
(SId
);
9387 Set_Predicate_Function
(Typ
, SId
);
9389 Insert_After
(Parent
(Typ
), FDecl
);
9394 end Build_Predicate_Function_Declaration
;
9396 -----------------------------------------
9397 -- Check_Aspect_At_End_Of_Declarations --
9398 -----------------------------------------
9400 procedure Check_Aspect_At_End_Of_Declarations
(ASN
: Node_Id
) is
9401 Ent
: constant Entity_Id
:= Entity
(ASN
);
9402 Ident
: constant Node_Id
:= Identifier
(ASN
);
9403 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Chars
(Ident
));
9405 End_Decl_Expr
: constant Node_Id
:= Entity
(Ident
);
9406 -- Expression to be analyzed at end of declarations
9408 Freeze_Expr
: constant Node_Id
:= Expression
(ASN
);
9409 -- Expression from call to Check_Aspect_At_Freeze_Point
9411 T
: constant Entity_Id
:= Etype
(Freeze_Expr
);
9412 -- Type required for preanalyze call
9415 -- Set False if error
9417 -- On entry to this procedure, Entity (Ident) contains a copy of the
9418 -- original expression from the aspect, saved for this purpose, and
9419 -- but Expression (Ident) is a preanalyzed copy of the expression,
9420 -- preanalyzed just after the freeze point.
9422 procedure Check_Overloaded_Name
;
9423 -- For aspects whose expression is simply a name, this routine checks if
9424 -- the name is overloaded or not. If so, it verifies there is an
9425 -- interpretation that matches the entity obtained at the freeze point,
9426 -- otherwise the compiler complains.
9428 ---------------------------
9429 -- Check_Overloaded_Name --
9430 ---------------------------
9432 procedure Check_Overloaded_Name
is
9434 if not Is_Overloaded
(End_Decl_Expr
) then
9435 Err
:= not Is_Entity_Name
(End_Decl_Expr
)
9436 or else Entity
(End_Decl_Expr
) /= Entity
(Freeze_Expr
);
9442 Index
: Interp_Index
;
9446 Get_First_Interp
(End_Decl_Expr
, Index
, It
);
9447 while Present
(It
.Typ
) loop
9448 if It
.Nam
= Entity
(Freeze_Expr
) then
9453 Get_Next_Interp
(Index
, It
);
9457 end Check_Overloaded_Name
;
9459 -- Start of processing for Check_Aspect_At_End_Of_Declarations
9462 -- In an instance we do not perform the consistency check between freeze
9463 -- point and end of declarations, because it was done already in the
9464 -- analysis of the generic. Furthermore, the delayed analysis of an
9465 -- aspect of the instance may produce spurious errors when the generic
9466 -- is a child unit that references entities in the parent (which might
9467 -- not be in scope at the freeze point of the instance).
9472 -- Case of aspects Dimension, Dimension_System and Synchronization
9474 elsif A_Id
= Aspect_Synchronization
then
9477 -- Case of stream attributes, just have to compare entities. However,
9478 -- the expression is just a name (possibly overloaded), and there may
9479 -- be stream operations declared for unrelated types, so we just need
9480 -- to verify that one of these interpretations is the one available at
9481 -- at the freeze point.
9483 elsif A_Id
= Aspect_Input
or else
9484 A_Id
= Aspect_Output
or else
9485 A_Id
= Aspect_Read
or else
9488 Analyze
(End_Decl_Expr
);
9489 Check_Overloaded_Name
;
9491 elsif A_Id
= Aspect_Variable_Indexing
or else
9492 A_Id
= Aspect_Constant_Indexing
or else
9493 A_Id
= Aspect_Default_Iterator
or else
9494 A_Id
= Aspect_Iterator_Element
9496 -- Make type unfrozen before analysis, to prevent spurious errors
9497 -- about late attributes.
9499 Set_Is_Frozen
(Ent
, False);
9500 Analyze
(End_Decl_Expr
);
9501 Set_Is_Frozen
(Ent
, True);
9503 -- If the end of declarations comes before any other freeze
9504 -- point, the Freeze_Expr is not analyzed: no check needed.
9506 if Analyzed
(Freeze_Expr
) and then not In_Instance
then
9507 Check_Overloaded_Name
;
9515 -- Indicate that the expression comes from an aspect specification,
9516 -- which is used in subsequent analysis even if expansion is off.
9518 Set_Parent
(End_Decl_Expr
, ASN
);
9520 -- In a generic context the aspect expressions have not been
9521 -- preanalyzed, so do it now. There are no conformance checks
9522 -- to perform in this case.
9525 Check_Aspect_At_Freeze_Point
(ASN
);
9528 -- The default values attributes may be defined in the private part,
9529 -- and the analysis of the expression may take place when only the
9530 -- partial view is visible. The expression must be scalar, so use
9531 -- the full view to resolve.
9533 elsif (A_Id
= Aspect_Default_Value
9535 A_Id
= Aspect_Default_Component_Value
)
9536 and then Is_Private_Type
(T
)
9538 Preanalyze_Spec_Expression
(End_Decl_Expr
, Full_View
(T
));
9541 Preanalyze_Spec_Expression
(End_Decl_Expr
, T
);
9544 Err
:= not Fully_Conformant_Expressions
(End_Decl_Expr
, Freeze_Expr
);
9547 -- Output error message if error. Force error on aspect specification
9548 -- even if there is an error on the expression itself.
9552 ("!visibility of aspect for& changes after freeze point",
9555 ("info: & is frozen here, aspects evaluated at this point??",
9556 Freeze_Node
(Ent
), Ent
);
9558 end Check_Aspect_At_End_Of_Declarations
;
9560 ----------------------------------
9561 -- Check_Aspect_At_Freeze_Point --
9562 ----------------------------------
9564 procedure Check_Aspect_At_Freeze_Point
(ASN
: Node_Id
) is
9565 Ident
: constant Node_Id
:= Identifier
(ASN
);
9566 -- Identifier (use Entity field to save expression)
9568 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Chars
(Ident
));
9570 T
: Entity_Id
:= Empty
;
9571 -- Type required for preanalyze call
9574 -- On entry to this procedure, Entity (Ident) contains a copy of the
9575 -- original expression from the aspect, saved for this purpose.
9577 -- On exit from this procedure Entity (Ident) is unchanged, still
9578 -- containing that copy, but Expression (Ident) is a preanalyzed copy
9579 -- of the expression, preanalyzed just after the freeze point.
9581 -- Make a copy of the expression to be preanalyzed
9583 Set_Expression
(ASN
, New_Copy_Tree
(Entity
(Ident
)));
9585 -- Find type for preanalyze call
9589 -- No_Aspect should be impossible
9592 raise Program_Error
;
9594 -- Aspects taking an optional boolean argument
9596 when Boolean_Aspects |
9597 Library_Unit_Aspects
=>
9599 T
:= Standard_Boolean
;
9601 -- Aspects corresponding to attribute definition clauses
9603 when Aspect_Address
=>
9604 T
:= RTE
(RE_Address
);
9606 when Aspect_Attach_Handler
=>
9607 T
:= RTE
(RE_Interrupt_ID
);
9609 when Aspect_Bit_Order | Aspect_Scalar_Storage_Order
=>
9610 T
:= RTE
(RE_Bit_Order
);
9612 when Aspect_Convention
=>
9616 T
:= RTE
(RE_CPU_Range
);
9618 -- Default_Component_Value is resolved with the component type
9620 when Aspect_Default_Component_Value
=>
9621 T
:= Component_Type
(Entity
(ASN
));
9623 when Aspect_Default_Storage_Pool
=>
9624 T
:= Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
));
9626 -- Default_Value is resolved with the type entity in question
9628 when Aspect_Default_Value
=>
9631 when Aspect_Dispatching_Domain
=>
9632 T
:= RTE
(RE_Dispatching_Domain
);
9634 when Aspect_External_Tag
=>
9635 T
:= Standard_String
;
9637 when Aspect_External_Name
=>
9638 T
:= Standard_String
;
9640 when Aspect_Link_Name
=>
9641 T
:= Standard_String
;
9643 when Aspect_Priority | Aspect_Interrupt_Priority
=>
9644 T
:= Standard_Integer
;
9646 when Aspect_Relative_Deadline
=>
9647 T
:= RTE
(RE_Time_Span
);
9649 when Aspect_Small
=>
9650 T
:= Universal_Real
;
9652 -- For a simple storage pool, we have to retrieve the type of the
9653 -- pool object associated with the aspect's corresponding attribute
9654 -- definition clause.
9656 when Aspect_Simple_Storage_Pool
=>
9657 T
:= Etype
(Expression
(Aspect_Rep_Item
(ASN
)));
9659 when Aspect_Storage_Pool
=>
9660 T
:= Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
));
9662 when Aspect_Alignment |
9663 Aspect_Component_Size |
9664 Aspect_Machine_Radix |
9665 Aspect_Object_Size |
9667 Aspect_Storage_Size |
9668 Aspect_Stream_Size |
9669 Aspect_Value_Size
=>
9672 when Aspect_Linker_Section
=>
9673 T
:= Standard_String
;
9675 when Aspect_Synchronization
=>
9678 -- Special case, the expression of these aspects is just an entity
9679 -- that does not need any resolution, so just analyze.
9688 Analyze
(Expression
(ASN
));
9691 -- Same for Iterator aspects, where the expression is a function
9692 -- name. Legality rules are checked separately.
9694 when Aspect_Constant_Indexing |
9695 Aspect_Default_Iterator |
9696 Aspect_Iterator_Element |
9697 Aspect_Variable_Indexing
=>
9698 Analyze
(Expression
(ASN
));
9701 -- Ditto for Iterable, legality checks in Validate_Iterable_Aspect.
9703 when Aspect_Iterable
=>
9707 Cursor
: constant Entity_Id
:= Get_Cursor_Type
(ASN
, T
);
9712 if Cursor
= Any_Type
then
9716 Assoc
:= First
(Component_Associations
(Expression
(ASN
)));
9717 while Present
(Assoc
) loop
9718 Expr
:= Expression
(Assoc
);
9721 if not Error_Posted
(Expr
) then
9722 Resolve_Iterable_Operation
9723 (Expr
, Cursor
, T
, Chars
(First
(Choices
(Assoc
))));
9732 -- Invariant/Predicate take boolean expressions
9734 when Aspect_Dynamic_Predicate |
9737 Aspect_Static_Predicate |
9738 Aspect_Type_Invariant
=>
9739 T
:= Standard_Boolean
;
9741 when Aspect_Predicate_Failure
=>
9742 T
:= Standard_String
;
9744 -- Here is the list of aspects that don't require delay analysis
9746 when Aspect_Abstract_State |
9748 Aspect_Async_Readers |
9749 Aspect_Async_Writers |
9750 Aspect_Constant_After_Elaboration |
9751 Aspect_Contract_Cases |
9752 Aspect_Default_Initial_Condition |
9755 Aspect_Dimension_System |
9756 Aspect_Effective_Reads |
9757 Aspect_Effective_Writes |
9758 Aspect_Extensions_Visible |
9761 Aspect_Implicit_Dereference |
9762 Aspect_Initial_Condition |
9763 Aspect_Initializes |
9764 Aspect_Obsolescent |
9767 Aspect_Postcondition |
9769 Aspect_Precondition |
9770 Aspect_Refined_Depends |
9771 Aspect_Refined_Global |
9772 Aspect_Refined_Post |
9773 Aspect_Refined_State |
9776 Aspect_Unimplemented |
9777 Aspect_Volatile_Function
=>
9778 raise Program_Error
;
9782 -- Do the preanalyze call
9784 Preanalyze_Spec_Expression
(Expression
(ASN
), T
);
9785 end Check_Aspect_At_Freeze_Point
;
9787 -----------------------------------
9788 -- Check_Constant_Address_Clause --
9789 -----------------------------------
9791 procedure Check_Constant_Address_Clause
9795 procedure Check_At_Constant_Address
(Nod
: Node_Id
);
9796 -- Checks that the given node N represents a name whose 'Address is
9797 -- constant (in the same sense as OK_Constant_Address_Clause, i.e. the
9798 -- address value is the same at the point of declaration of U_Ent and at
9799 -- the time of elaboration of the address clause.
9801 procedure Check_Expr_Constants
(Nod
: Node_Id
);
9802 -- Checks that Nod meets the requirements for a constant address clause
9803 -- in the sense of the enclosing procedure.
9805 procedure Check_List_Constants
(Lst
: List_Id
);
9806 -- Check that all elements of list Lst meet the requirements for a
9807 -- constant address clause in the sense of the enclosing procedure.
9809 -------------------------------
9810 -- Check_At_Constant_Address --
9811 -------------------------------
9813 procedure Check_At_Constant_Address
(Nod
: Node_Id
) is
9815 if Is_Entity_Name
(Nod
) then
9816 if Present
(Address_Clause
(Entity
((Nod
)))) then
9818 ("invalid address clause for initialized object &!",
9821 ("address for& cannot" &
9822 " depend on another address clause! (RM 13.1(22))!",
9825 elsif In_Same_Source_Unit
(Entity
(Nod
), U_Ent
)
9826 and then Sloc
(U_Ent
) < Sloc
(Entity
(Nod
))
9829 ("invalid address clause for initialized object &!",
9831 Error_Msg_Node_2
:= U_Ent
;
9833 ("\& must be defined before & (RM 13.1(22))!",
9837 elsif Nkind
(Nod
) = N_Selected_Component
then
9839 T
: constant Entity_Id
:= Etype
(Prefix
(Nod
));
9842 if (Is_Record_Type
(T
)
9843 and then Has_Discriminants
(T
))
9846 and then Is_Record_Type
(Designated_Type
(T
))
9847 and then Has_Discriminants
(Designated_Type
(T
)))
9850 ("invalid address clause for initialized object &!",
9853 ("\address cannot depend on component" &
9854 " of discriminated record (RM 13.1(22))!",
9857 Check_At_Constant_Address
(Prefix
(Nod
));
9861 elsif Nkind
(Nod
) = N_Indexed_Component
then
9862 Check_At_Constant_Address
(Prefix
(Nod
));
9863 Check_List_Constants
(Expressions
(Nod
));
9866 Check_Expr_Constants
(Nod
);
9868 end Check_At_Constant_Address
;
9870 --------------------------
9871 -- Check_Expr_Constants --
9872 --------------------------
9874 procedure Check_Expr_Constants
(Nod
: Node_Id
) is
9875 Loc_U_Ent
: constant Source_Ptr
:= Sloc
(U_Ent
);
9876 Ent
: Entity_Id
:= Empty
;
9879 if Nkind
(Nod
) in N_Has_Etype
9880 and then Etype
(Nod
) = Any_Type
9886 when N_Empty | N_Error
=>
9889 when N_Identifier | N_Expanded_Name
=>
9890 Ent
:= Entity
(Nod
);
9892 -- We need to look at the original node if it is different
9893 -- from the node, since we may have rewritten things and
9894 -- substituted an identifier representing the rewrite.
9896 if Original_Node
(Nod
) /= Nod
then
9897 Check_Expr_Constants
(Original_Node
(Nod
));
9899 -- If the node is an object declaration without initial
9900 -- value, some code has been expanded, and the expression
9901 -- is not constant, even if the constituents might be
9902 -- acceptable, as in A'Address + offset.
9904 if Ekind
(Ent
) = E_Variable
9906 Nkind
(Declaration_Node
(Ent
)) = N_Object_Declaration
9908 No
(Expression
(Declaration_Node
(Ent
)))
9911 ("invalid address clause for initialized object &!",
9914 -- If entity is constant, it may be the result of expanding
9915 -- a check. We must verify that its declaration appears
9916 -- before the object in question, else we also reject the
9919 elsif Ekind
(Ent
) = E_Constant
9920 and then In_Same_Source_Unit
(Ent
, U_Ent
)
9921 and then Sloc
(Ent
) > Loc_U_Ent
9924 ("invalid address clause for initialized object &!",
9931 -- Otherwise look at the identifier and see if it is OK
9933 if Ekind_In
(Ent
, E_Named_Integer
, E_Named_Real
)
9934 or else Is_Type
(Ent
)
9938 elsif Ekind_In
(Ent
, E_Constant
, E_In_Parameter
) then
9940 -- This is the case where we must have Ent defined before
9941 -- U_Ent. Clearly if they are in different units this
9942 -- requirement is met since the unit containing Ent is
9943 -- already processed.
9945 if not In_Same_Source_Unit
(Ent
, U_Ent
) then
9948 -- Otherwise location of Ent must be before the location
9949 -- of U_Ent, that's what prior defined means.
9951 elsif Sloc
(Ent
) < Loc_U_Ent
then
9956 ("invalid address clause for initialized object &!",
9958 Error_Msg_Node_2
:= U_Ent
;
9960 ("\& must be defined before & (RM 13.1(22))!",
9964 elsif Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
9965 Check_Expr_Constants
(Original_Node
(Nod
));
9969 ("invalid address clause for initialized object &!",
9972 if Comes_From_Source
(Ent
) then
9974 ("\reference to variable& not allowed"
9975 & " (RM 13.1(22))!", Nod
, Ent
);
9978 ("non-static expression not allowed"
9979 & " (RM 13.1(22))!", Nod
);
9983 when N_Integer_Literal
=>
9985 -- If this is a rewritten unchecked conversion, in a system
9986 -- where Address is an integer type, always use the base type
9987 -- for a literal value. This is user-friendly and prevents
9988 -- order-of-elaboration issues with instances of unchecked
9991 if Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
9992 Set_Etype
(Nod
, Base_Type
(Etype
(Nod
)));
9995 when N_Real_Literal |
9997 N_Character_Literal
=>
10001 Check_Expr_Constants
(Low_Bound
(Nod
));
10002 Check_Expr_Constants
(High_Bound
(Nod
));
10004 when N_Explicit_Dereference
=>
10005 Check_Expr_Constants
(Prefix
(Nod
));
10007 when N_Indexed_Component
=>
10008 Check_Expr_Constants
(Prefix
(Nod
));
10009 Check_List_Constants
(Expressions
(Nod
));
10012 Check_Expr_Constants
(Prefix
(Nod
));
10013 Check_Expr_Constants
(Discrete_Range
(Nod
));
10015 when N_Selected_Component
=>
10016 Check_Expr_Constants
(Prefix
(Nod
));
10018 when N_Attribute_Reference
=>
10019 if Nam_In
(Attribute_Name
(Nod
), Name_Address
,
10021 Name_Unchecked_Access
,
10022 Name_Unrestricted_Access
)
10024 Check_At_Constant_Address
(Prefix
(Nod
));
10027 Check_Expr_Constants
(Prefix
(Nod
));
10028 Check_List_Constants
(Expressions
(Nod
));
10031 when N_Aggregate
=>
10032 Check_List_Constants
(Component_Associations
(Nod
));
10033 Check_List_Constants
(Expressions
(Nod
));
10035 when N_Component_Association
=>
10036 Check_Expr_Constants
(Expression
(Nod
));
10038 when N_Extension_Aggregate
=>
10039 Check_Expr_Constants
(Ancestor_Part
(Nod
));
10040 Check_List_Constants
(Component_Associations
(Nod
));
10041 Check_List_Constants
(Expressions
(Nod
));
10046 when N_Binary_Op | N_Short_Circuit | N_Membership_Test
=>
10047 Check_Expr_Constants
(Left_Opnd
(Nod
));
10048 Check_Expr_Constants
(Right_Opnd
(Nod
));
10051 Check_Expr_Constants
(Right_Opnd
(Nod
));
10053 when N_Type_Conversion |
10054 N_Qualified_Expression |
10056 N_Unchecked_Type_Conversion
=>
10057 Check_Expr_Constants
(Expression
(Nod
));
10059 when N_Function_Call
=>
10060 if not Is_Pure
(Entity
(Name
(Nod
))) then
10062 ("invalid address clause for initialized object &!",
10066 ("\function & is not pure (RM 13.1(22))!",
10067 Nod
, Entity
(Name
(Nod
)));
10070 Check_List_Constants
(Parameter_Associations
(Nod
));
10073 when N_Parameter_Association
=>
10074 Check_Expr_Constants
(Explicit_Actual_Parameter
(Nod
));
10078 ("invalid address clause for initialized object &!",
10081 ("\must be constant defined before& (RM 13.1(22))!",
10084 end Check_Expr_Constants
;
10086 --------------------------
10087 -- Check_List_Constants --
10088 --------------------------
10090 procedure Check_List_Constants
(Lst
: List_Id
) is
10094 if Present
(Lst
) then
10095 Nod1
:= First
(Lst
);
10096 while Present
(Nod1
) loop
10097 Check_Expr_Constants
(Nod1
);
10101 end Check_List_Constants
;
10103 -- Start of processing for Check_Constant_Address_Clause
10106 -- If rep_clauses are to be ignored, no need for legality checks. In
10107 -- particular, no need to pester user about rep clauses that violate the
10108 -- rule on constant addresses, given that these clauses will be removed
10109 -- by Freeze before they reach the back end. Similarly in CodePeer mode,
10110 -- we want to relax these checks.
10112 if not Ignore_Rep_Clauses
and not CodePeer_Mode
then
10113 Check_Expr_Constants
(Expr
);
10115 end Check_Constant_Address_Clause
;
10117 ---------------------------
10118 -- Check_Pool_Size_Clash --
10119 ---------------------------
10121 procedure Check_Pool_Size_Clash
(Ent
: Entity_Id
; SP
, SS
: Node_Id
) is
10125 -- We need to find out which one came first. Note that in the case of
10126 -- aspects mixed with pragmas there are cases where the processing order
10127 -- is reversed, which is why we do the check here.
10129 if Sloc
(SP
) < Sloc
(SS
) then
10130 Error_Msg_Sloc
:= Sloc
(SP
);
10132 Error_Msg_NE
("Storage_Pool previously given for&#", Post
, Ent
);
10135 Error_Msg_Sloc
:= Sloc
(SS
);
10137 Error_Msg_NE
("Storage_Size previously given for&#", Post
, Ent
);
10141 ("\cannot have Storage_Size and Storage_Pool (RM 13.11(3))", Post
);
10142 end Check_Pool_Size_Clash
;
10144 ----------------------------------------
10145 -- Check_Record_Representation_Clause --
10146 ----------------------------------------
10148 procedure Check_Record_Representation_Clause
(N
: Node_Id
) is
10149 Loc
: constant Source_Ptr
:= Sloc
(N
);
10150 Ident
: constant Node_Id
:= Identifier
(N
);
10151 Rectype
: Entity_Id
;
10156 Hbit
: Uint
:= Uint_0
;
10160 Max_Bit_So_Far
: Uint
;
10161 -- Records the maximum bit position so far. If all field positions
10162 -- are monotonically increasing, then we can skip the circuit for
10163 -- checking for overlap, since no overlap is possible.
10165 Tagged_Parent
: Entity_Id
:= Empty
;
10166 -- This is set in the case of a derived tagged type for which we have
10167 -- Is_Fully_Repped_Tagged_Type True (indicating that all components are
10168 -- positioned by record representation clauses). In this case we must
10169 -- check for overlap between components of this tagged type, and the
10170 -- components of its parent. Tagged_Parent will point to this parent
10171 -- type. For all other cases Tagged_Parent is left set to Empty.
10173 Parent_Last_Bit
: Uint
;
10174 -- Relevant only if Tagged_Parent is set, Parent_Last_Bit indicates the
10175 -- last bit position for any field in the parent type. We only need to
10176 -- check overlap for fields starting below this point.
10178 Overlap_Check_Required
: Boolean;
10179 -- Used to keep track of whether or not an overlap check is required
10181 Overlap_Detected
: Boolean := False;
10182 -- Set True if an overlap is detected
10184 Ccount
: Natural := 0;
10185 -- Number of component clauses in record rep clause
10187 procedure Check_Component_Overlap
(C1_Ent
, C2_Ent
: Entity_Id
);
10188 -- Given two entities for record components or discriminants, checks
10189 -- if they have overlapping component clauses and issues errors if so.
10191 procedure Find_Component
;
10192 -- Finds component entity corresponding to current component clause (in
10193 -- CC), and sets Comp to the entity, and Fbit/Lbit to the zero origin
10194 -- start/stop bits for the field. If there is no matching component or
10195 -- if the matching component does not have a component clause, then
10196 -- that's an error and Comp is set to Empty, but no error message is
10197 -- issued, since the message was already given. Comp is also set to
10198 -- Empty if the current "component clause" is in fact a pragma.
10200 -----------------------------
10201 -- Check_Component_Overlap --
10202 -----------------------------
10204 procedure Check_Component_Overlap
(C1_Ent
, C2_Ent
: Entity_Id
) is
10205 CC1
: constant Node_Id
:= Component_Clause
(C1_Ent
);
10206 CC2
: constant Node_Id
:= Component_Clause
(C2_Ent
);
10209 if Present
(CC1
) and then Present
(CC2
) then
10211 -- Exclude odd case where we have two tag components in the same
10212 -- record, both at location zero. This seems a bit strange, but
10213 -- it seems to happen in some circumstances, perhaps on an error.
10215 if Nam_In
(Chars
(C1_Ent
), Name_uTag
, Name_uTag
) then
10219 -- Here we check if the two fields overlap
10222 S1
: constant Uint
:= Component_Bit_Offset
(C1_Ent
);
10223 S2
: constant Uint
:= Component_Bit_Offset
(C2_Ent
);
10224 E1
: constant Uint
:= S1
+ Esize
(C1_Ent
);
10225 E2
: constant Uint
:= S2
+ Esize
(C2_Ent
);
10228 if E2
<= S1
or else E1
<= S2
then
10231 Error_Msg_Node_2
:= Component_Name
(CC2
);
10232 Error_Msg_Sloc
:= Sloc
(Error_Msg_Node_2
);
10233 Error_Msg_Node_1
:= Component_Name
(CC1
);
10235 ("component& overlaps & #", Component_Name
(CC1
));
10236 Overlap_Detected
:= True;
10240 end Check_Component_Overlap
;
10242 --------------------
10243 -- Find_Component --
10244 --------------------
10246 procedure Find_Component
is
10248 procedure Search_Component
(R
: Entity_Id
);
10249 -- Search components of R for a match. If found, Comp is set
10251 ----------------------
10252 -- Search_Component --
10253 ----------------------
10255 procedure Search_Component
(R
: Entity_Id
) is
10257 Comp
:= First_Component_Or_Discriminant
(R
);
10258 while Present
(Comp
) loop
10260 -- Ignore error of attribute name for component name (we
10261 -- already gave an error message for this, so no need to
10264 if Nkind
(Component_Name
(CC
)) = N_Attribute_Reference
then
10267 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
10270 Next_Component_Or_Discriminant
(Comp
);
10272 end Search_Component
;
10274 -- Start of processing for Find_Component
10277 -- Return with Comp set to Empty if we have a pragma
10279 if Nkind
(CC
) = N_Pragma
then
10284 -- Search current record for matching component
10286 Search_Component
(Rectype
);
10288 -- If not found, maybe component of base type discriminant that is
10289 -- absent from statically constrained first subtype.
10292 Search_Component
(Base_Type
(Rectype
));
10295 -- If no component, or the component does not reference the component
10296 -- clause in question, then there was some previous error for which
10297 -- we already gave a message, so just return with Comp Empty.
10299 if No
(Comp
) or else Component_Clause
(Comp
) /= CC
then
10300 Check_Error_Detected
;
10303 -- Normal case where we have a component clause
10306 Fbit
:= Component_Bit_Offset
(Comp
);
10307 Lbit
:= Fbit
+ Esize
(Comp
) - 1;
10309 end Find_Component
;
10311 -- Start of processing for Check_Record_Representation_Clause
10315 Rectype
:= Entity
(Ident
);
10317 if Rectype
= Any_Type
then
10320 Rectype
:= Underlying_Type
(Rectype
);
10323 -- See if we have a fully repped derived tagged type
10326 PS
: constant Entity_Id
:= Parent_Subtype
(Rectype
);
10329 if Present
(PS
) and then Is_Fully_Repped_Tagged_Type
(PS
) then
10330 Tagged_Parent
:= PS
;
10332 -- Find maximum bit of any component of the parent type
10334 Parent_Last_Bit
:= UI_From_Int
(System_Address_Size
- 1);
10335 Pcomp
:= First_Entity
(Tagged_Parent
);
10336 while Present
(Pcomp
) loop
10337 if Ekind_In
(Pcomp
, E_Discriminant
, E_Component
) then
10338 if Component_Bit_Offset
(Pcomp
) /= No_Uint
10339 and then Known_Static_Esize
(Pcomp
)
10344 Component_Bit_Offset
(Pcomp
) + Esize
(Pcomp
) - 1);
10348 -- Skip anonymous types generated for constrained array
10349 -- or record components.
10354 Next_Entity
(Pcomp
);
10359 -- All done if no component clauses
10361 CC
:= First
(Component_Clauses
(N
));
10367 -- If a tag is present, then create a component clause that places it
10368 -- at the start of the record (otherwise gigi may place it after other
10369 -- fields that have rep clauses).
10371 Fent
:= First_Entity
(Rectype
);
10373 if Nkind
(Fent
) = N_Defining_Identifier
10374 and then Chars
(Fent
) = Name_uTag
10376 Set_Component_Bit_Offset
(Fent
, Uint_0
);
10377 Set_Normalized_Position
(Fent
, Uint_0
);
10378 Set_Normalized_First_Bit
(Fent
, Uint_0
);
10379 Set_Normalized_Position_Max
(Fent
, Uint_0
);
10380 Init_Esize
(Fent
, System_Address_Size
);
10382 Set_Component_Clause
(Fent
,
10383 Make_Component_Clause
(Loc
,
10384 Component_Name
=> Make_Identifier
(Loc
, Name_uTag
),
10386 Position
=> Make_Integer_Literal
(Loc
, Uint_0
),
10387 First_Bit
=> Make_Integer_Literal
(Loc
, Uint_0
),
10389 Make_Integer_Literal
(Loc
,
10390 UI_From_Int
(System_Address_Size
))));
10392 Ccount
:= Ccount
+ 1;
10395 Max_Bit_So_Far
:= Uint_Minus_1
;
10396 Overlap_Check_Required
:= False;
10398 -- Process the component clauses
10400 while Present
(CC
) loop
10403 if Present
(Comp
) then
10404 Ccount
:= Ccount
+ 1;
10406 -- We need a full overlap check if record positions non-monotonic
10408 if Fbit
<= Max_Bit_So_Far
then
10409 Overlap_Check_Required
:= True;
10412 Max_Bit_So_Far
:= Lbit
;
10414 -- Check bit position out of range of specified size
10416 if Has_Size_Clause
(Rectype
)
10417 and then RM_Size
(Rectype
) <= Lbit
10420 ("bit number out of range of specified size",
10423 -- Check for overlap with tag component
10426 if Is_Tagged_Type
(Rectype
)
10427 and then Fbit
< System_Address_Size
10430 ("component overlaps tag field of&",
10431 Component_Name
(CC
), Rectype
);
10432 Overlap_Detected
:= True;
10435 if Hbit
< Lbit
then
10440 -- Check parent overlap if component might overlap parent field
10442 if Present
(Tagged_Parent
) and then Fbit
<= Parent_Last_Bit
then
10443 Pcomp
:= First_Component_Or_Discriminant
(Tagged_Parent
);
10444 while Present
(Pcomp
) loop
10445 if not Is_Tag
(Pcomp
)
10446 and then Chars
(Pcomp
) /= Name_uParent
10448 Check_Component_Overlap
(Comp
, Pcomp
);
10451 Next_Component_Or_Discriminant
(Pcomp
);
10459 -- Now that we have processed all the component clauses, check for
10460 -- overlap. We have to leave this till last, since the components can
10461 -- appear in any arbitrary order in the representation clause.
10463 -- We do not need this check if all specified ranges were monotonic,
10464 -- as recorded by Overlap_Check_Required being False at this stage.
10466 -- This first section checks if there are any overlapping entries at
10467 -- all. It does this by sorting all entries and then seeing if there are
10468 -- any overlaps. If there are none, then that is decisive, but if there
10469 -- are overlaps, they may still be OK (they may result from fields in
10470 -- different variants).
10472 if Overlap_Check_Required
then
10473 Overlap_Check1
: declare
10475 OC_Fbit
: array (0 .. Ccount
) of Uint
;
10476 -- First-bit values for component clauses, the value is the offset
10477 -- of the first bit of the field from start of record. The zero
10478 -- entry is for use in sorting.
10480 OC_Lbit
: array (0 .. Ccount
) of Uint
;
10481 -- Last-bit values for component clauses, the value is the offset
10482 -- of the last bit of the field from start of record. The zero
10483 -- entry is for use in sorting.
10485 OC_Count
: Natural := 0;
10486 -- Count of entries in OC_Fbit and OC_Lbit
10488 function OC_Lt
(Op1
, Op2
: Natural) return Boolean;
10489 -- Compare routine for Sort
10491 procedure OC_Move
(From
: Natural; To
: Natural);
10492 -- Move routine for Sort
10494 package Sorting
is new GNAT
.Heap_Sort_G
(OC_Move
, OC_Lt
);
10500 function OC_Lt
(Op1
, Op2
: Natural) return Boolean is
10502 return OC_Fbit
(Op1
) < OC_Fbit
(Op2
);
10509 procedure OC_Move
(From
: Natural; To
: Natural) is
10511 OC_Fbit
(To
) := OC_Fbit
(From
);
10512 OC_Lbit
(To
) := OC_Lbit
(From
);
10515 -- Start of processing for Overlap_Check
10518 CC
:= First
(Component_Clauses
(N
));
10519 while Present
(CC
) loop
10521 -- Exclude component clause already marked in error
10523 if not Error_Posted
(CC
) then
10526 if Present
(Comp
) then
10527 OC_Count
:= OC_Count
+ 1;
10528 OC_Fbit
(OC_Count
) := Fbit
;
10529 OC_Lbit
(OC_Count
) := Lbit
;
10536 Sorting
.Sort
(OC_Count
);
10538 Overlap_Check_Required
:= False;
10539 for J
in 1 .. OC_Count
- 1 loop
10540 if OC_Lbit
(J
) >= OC_Fbit
(J
+ 1) then
10541 Overlap_Check_Required
:= True;
10545 end Overlap_Check1
;
10548 -- If Overlap_Check_Required is still True, then we have to do the full
10549 -- scale overlap check, since we have at least two fields that do
10550 -- overlap, and we need to know if that is OK since they are in
10551 -- different variant, or whether we have a definite problem.
10553 if Overlap_Check_Required
then
10554 Overlap_Check2
: declare
10555 C1_Ent
, C2_Ent
: Entity_Id
;
10556 -- Entities of components being checked for overlap
10559 -- Component_List node whose Component_Items are being checked
10562 -- Component declaration for component being checked
10565 C1_Ent
:= First_Entity
(Base_Type
(Rectype
));
10567 -- Loop through all components in record. For each component check
10568 -- for overlap with any of the preceding elements on the component
10569 -- list containing the component and also, if the component is in
10570 -- a variant, check against components outside the case structure.
10571 -- This latter test is repeated recursively up the variant tree.
10573 Main_Component_Loop
: while Present
(C1_Ent
) loop
10574 if not Ekind_In
(C1_Ent
, E_Component
, E_Discriminant
) then
10575 goto Continue_Main_Component_Loop
;
10578 -- Skip overlap check if entity has no declaration node. This
10579 -- happens with discriminants in constrained derived types.
10580 -- Possibly we are missing some checks as a result, but that
10581 -- does not seem terribly serious.
10583 if No
(Declaration_Node
(C1_Ent
)) then
10584 goto Continue_Main_Component_Loop
;
10587 Clist
:= Parent
(List_Containing
(Declaration_Node
(C1_Ent
)));
10589 -- Loop through component lists that need checking. Check the
10590 -- current component list and all lists in variants above us.
10592 Component_List_Loop
: loop
10594 -- If derived type definition, go to full declaration
10595 -- If at outer level, check discriminants if there are any.
10597 if Nkind
(Clist
) = N_Derived_Type_Definition
then
10598 Clist
:= Parent
(Clist
);
10601 -- Outer level of record definition, check discriminants
10603 if Nkind_In
(Clist
, N_Full_Type_Declaration
,
10604 N_Private_Type_Declaration
)
10606 if Has_Discriminants
(Defining_Identifier
(Clist
)) then
10608 First_Discriminant
(Defining_Identifier
(Clist
));
10609 while Present
(C2_Ent
) loop
10610 exit when C1_Ent
= C2_Ent
;
10611 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
10612 Next_Discriminant
(C2_Ent
);
10616 -- Record extension case
10618 elsif Nkind
(Clist
) = N_Derived_Type_Definition
then
10621 -- Otherwise check one component list
10624 Citem
:= First
(Component_Items
(Clist
));
10625 while Present
(Citem
) loop
10626 if Nkind
(Citem
) = N_Component_Declaration
then
10627 C2_Ent
:= Defining_Identifier
(Citem
);
10628 exit when C1_Ent
= C2_Ent
;
10629 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
10636 -- Check for variants above us (the parent of the Clist can
10637 -- be a variant, in which case its parent is a variant part,
10638 -- and the parent of the variant part is a component list
10639 -- whose components must all be checked against the current
10640 -- component for overlap).
10642 if Nkind
(Parent
(Clist
)) = N_Variant
then
10643 Clist
:= Parent
(Parent
(Parent
(Clist
)));
10645 -- Check for possible discriminant part in record, this
10646 -- is treated essentially as another level in the
10647 -- recursion. For this case the parent of the component
10648 -- list is the record definition, and its parent is the
10649 -- full type declaration containing the discriminant
10652 elsif Nkind
(Parent
(Clist
)) = N_Record_Definition
then
10653 Clist
:= Parent
(Parent
((Clist
)));
10655 -- If neither of these two cases, we are at the top of
10659 exit Component_List_Loop
;
10661 end loop Component_List_Loop
;
10663 <<Continue_Main_Component_Loop
>>
10664 Next_Entity
(C1_Ent
);
10666 end loop Main_Component_Loop
;
10667 end Overlap_Check2
;
10670 -- The following circuit deals with warning on record holes (gaps). We
10671 -- skip this check if overlap was detected, since it makes sense for the
10672 -- programmer to fix this illegality before worrying about warnings.
10674 if not Overlap_Detected
and Warn_On_Record_Holes
then
10675 Record_Hole_Check
: declare
10676 Decl
: constant Node_Id
:= Declaration_Node
(Base_Type
(Rectype
));
10677 -- Full declaration of record type
10679 procedure Check_Component_List
10683 -- Check component list CL for holes. The starting bit should be
10684 -- Sbit. which is zero for the main record component list and set
10685 -- appropriately for recursive calls for variants. DS is set to
10686 -- a list of discriminant specifications to be included in the
10687 -- consideration of components. It is No_List if none to consider.
10689 --------------------------
10690 -- Check_Component_List --
10691 --------------------------
10693 procedure Check_Component_List
10701 Compl
:= Integer (List_Length
(Component_Items
(CL
)));
10703 if DS
/= No_List
then
10704 Compl
:= Compl
+ Integer (List_Length
(DS
));
10708 Comps
: array (Natural range 0 .. Compl
) of Entity_Id
;
10709 -- Gather components (zero entry is for sort routine)
10711 Ncomps
: Natural := 0;
10712 -- Number of entries stored in Comps (starting at Comps (1))
10715 -- One component item or discriminant specification
10718 -- Starting bit for next component
10721 -- Component entity
10726 function Lt
(Op1
, Op2
: Natural) return Boolean;
10727 -- Compare routine for Sort
10729 procedure Move
(From
: Natural; To
: Natural);
10730 -- Move routine for Sort
10732 package Sorting
is new GNAT
.Heap_Sort_G
(Move
, Lt
);
10738 function Lt
(Op1
, Op2
: Natural) return Boolean is
10740 return Component_Bit_Offset
(Comps
(Op1
))
10742 Component_Bit_Offset
(Comps
(Op2
));
10749 procedure Move
(From
: Natural; To
: Natural) is
10751 Comps
(To
) := Comps
(From
);
10755 -- Gather discriminants into Comp
10757 if DS
/= No_List
then
10758 Citem
:= First
(DS
);
10759 while Present
(Citem
) loop
10760 if Nkind
(Citem
) = N_Discriminant_Specification
then
10762 Ent
: constant Entity_Id
:=
10763 Defining_Identifier
(Citem
);
10765 if Ekind
(Ent
) = E_Discriminant
then
10766 Ncomps
:= Ncomps
+ 1;
10767 Comps
(Ncomps
) := Ent
;
10776 -- Gather component entities into Comp
10778 Citem
:= First
(Component_Items
(CL
));
10779 while Present
(Citem
) loop
10780 if Nkind
(Citem
) = N_Component_Declaration
then
10781 Ncomps
:= Ncomps
+ 1;
10782 Comps
(Ncomps
) := Defining_Identifier
(Citem
);
10788 -- Now sort the component entities based on the first bit.
10789 -- Note we already know there are no overlapping components.
10791 Sorting
.Sort
(Ncomps
);
10793 -- Loop through entries checking for holes
10796 for J
in 1 .. Ncomps
loop
10798 Error_Msg_Uint_1
:= Component_Bit_Offset
(CEnt
) - Nbit
;
10800 if Error_Msg_Uint_1
> 0 then
10802 ("?H?^-bit gap before component&",
10803 Component_Name
(Component_Clause
(CEnt
)), CEnt
);
10806 Nbit
:= Component_Bit_Offset
(CEnt
) + Esize
(CEnt
);
10809 -- Process variant parts recursively if present
10811 if Present
(Variant_Part
(CL
)) then
10812 Variant
:= First
(Variants
(Variant_Part
(CL
)));
10813 while Present
(Variant
) loop
10814 Check_Component_List
10815 (Component_List
(Variant
), Nbit
, No_List
);
10820 end Check_Component_List
;
10822 -- Start of processing for Record_Hole_Check
10829 if Is_Tagged_Type
(Rectype
) then
10830 Sbit
:= UI_From_Int
(System_Address_Size
);
10835 if Nkind
(Decl
) = N_Full_Type_Declaration
10836 and then Nkind
(Type_Definition
(Decl
)) = N_Record_Definition
10838 Check_Component_List
10839 (Component_List
(Type_Definition
(Decl
)),
10841 Discriminant_Specifications
(Decl
));
10844 end Record_Hole_Check
;
10847 -- For records that have component clauses for all components, and whose
10848 -- size is less than or equal to 32, we need to know the size in the
10849 -- front end to activate possible packed array processing where the
10850 -- component type is a record.
10852 -- At this stage Hbit + 1 represents the first unused bit from all the
10853 -- component clauses processed, so if the component clauses are
10854 -- complete, then this is the length of the record.
10856 -- For records longer than System.Storage_Unit, and for those where not
10857 -- all components have component clauses, the back end determines the
10858 -- length (it may for example be appropriate to round up the size
10859 -- to some convenient boundary, based on alignment considerations, etc).
10861 if Unknown_RM_Size
(Rectype
) and then Hbit
+ 1 <= 32 then
10863 -- Nothing to do if at least one component has no component clause
10865 Comp
:= First_Component_Or_Discriminant
(Rectype
);
10866 while Present
(Comp
) loop
10867 exit when No
(Component_Clause
(Comp
));
10868 Next_Component_Or_Discriminant
(Comp
);
10871 -- If we fall out of loop, all components have component clauses
10872 -- and so we can set the size to the maximum value.
10875 Set_RM_Size
(Rectype
, Hbit
+ 1);
10878 end Check_Record_Representation_Clause
;
10884 procedure Check_Size
10888 Biased
: out Boolean)
10890 procedure Size_Too_Small_Error
(Min_Siz
: Uint
);
10891 -- Emit an error concerning illegal size Siz. Min_Siz denotes the
10894 --------------------------
10895 -- Size_Too_Small_Error --
10896 --------------------------
10898 procedure Size_Too_Small_Error
(Min_Siz
: Uint
) is
10900 -- This error is suppressed in ASIS mode to allow for different ASIS
10901 -- back ends or ASIS-based tools to query the illegal clause.
10903 if not ASIS_Mode
then
10904 Error_Msg_Uint_1
:= Min_Siz
;
10905 Error_Msg_NE
("size for& too small, minimum allowed is ^", N
, T
);
10907 end Size_Too_Small_Error
;
10911 UT
: constant Entity_Id
:= Underlying_Type
(T
);
10914 -- Start of processing for Check_Size
10919 -- Reject patently improper size values
10921 if Is_Elementary_Type
(T
)
10922 and then Siz
> UI_From_Int
(Int
'Last)
10924 Error_Msg_N
("Size value too large for elementary type", N
);
10926 if Nkind
(Original_Node
(N
)) = N_Op_Expon
then
10928 ("\maybe '* was meant, rather than '*'*", Original_Node
(N
));
10932 -- Dismiss generic types
10934 if Is_Generic_Type
(T
)
10936 Is_Generic_Type
(UT
)
10938 Is_Generic_Type
(Root_Type
(UT
))
10942 -- Guard against previous errors
10944 elsif No
(UT
) or else UT
= Any_Type
then
10945 Check_Error_Detected
;
10948 -- Check case of bit packed array
10950 elsif Is_Array_Type
(UT
)
10951 and then Known_Static_Component_Size
(UT
)
10952 and then Is_Bit_Packed_Array
(UT
)
10960 Asiz
:= Component_Size
(UT
);
10961 Indx
:= First_Index
(UT
);
10963 Ityp
:= Etype
(Indx
);
10965 -- If non-static bound, then we are not in the business of
10966 -- trying to check the length, and indeed an error will be
10967 -- issued elsewhere, since sizes of non-static array types
10968 -- cannot be set implicitly or explicitly.
10970 if not Is_OK_Static_Subtype
(Ityp
) then
10974 -- Otherwise accumulate next dimension
10976 Asiz
:= Asiz
* (Expr_Value
(Type_High_Bound
(Ityp
)) -
10977 Expr_Value
(Type_Low_Bound
(Ityp
)) +
10981 exit when No
(Indx
);
10984 if Asiz
<= Siz
then
10988 Size_Too_Small_Error
(Asiz
);
10989 Set_Esize
(T
, Asiz
);
10990 Set_RM_Size
(T
, Asiz
);
10994 -- All other composite types are ignored
10996 elsif Is_Composite_Type
(UT
) then
10999 -- For fixed-point types, don't check minimum if type is not frozen,
11000 -- since we don't know all the characteristics of the type that can
11001 -- affect the size (e.g. a specified small) till freeze time.
11003 elsif Is_Fixed_Point_Type
(UT
) and then not Is_Frozen
(UT
) then
11006 -- Cases for which a minimum check is required
11009 -- Ignore if specified size is correct for the type
11011 if Known_Esize
(UT
) and then Siz
= Esize
(UT
) then
11015 -- Otherwise get minimum size
11017 M
:= UI_From_Int
(Minimum_Size
(UT
));
11021 -- Size is less than minimum size, but one possibility remains
11022 -- that we can manage with the new size if we bias the type.
11024 M
:= UI_From_Int
(Minimum_Size
(UT
, Biased
=> True));
11027 Size_Too_Small_Error
(M
);
11029 Set_RM_Size
(T
, M
);
11037 --------------------------
11038 -- Freeze_Entity_Checks --
11039 --------------------------
11041 procedure Freeze_Entity_Checks
(N
: Node_Id
) is
11042 procedure Hide_Non_Overridden_Subprograms
(Typ
: Entity_Id
);
11043 -- Inspect the primitive operations of type Typ and hide all pairs of
11044 -- implicitly declared non-overridden non-fully conformant homographs
11045 -- (Ada RM 8.3 12.3/2).
11047 -------------------------------------
11048 -- Hide_Non_Overridden_Subprograms --
11049 -------------------------------------
11051 procedure Hide_Non_Overridden_Subprograms
(Typ
: Entity_Id
) is
11052 procedure Hide_Matching_Homographs
11053 (Subp_Id
: Entity_Id
;
11054 Start_Elmt
: Elmt_Id
);
11055 -- Inspect a list of primitive operations starting with Start_Elmt
11056 -- and find matching implicitly declared non-overridden non-fully
11057 -- conformant homographs of Subp_Id. If found, all matches along
11058 -- with Subp_Id are hidden from all visibility.
11060 function Is_Non_Overridden_Or_Null_Procedure
11061 (Subp_Id
: Entity_Id
) return Boolean;
11062 -- Determine whether subprogram Subp_Id is implicitly declared non-
11063 -- overridden subprogram or an implicitly declared null procedure.
11065 ------------------------------
11066 -- Hide_Matching_Homographs --
11067 ------------------------------
11069 procedure Hide_Matching_Homographs
11070 (Subp_Id
: Entity_Id
;
11071 Start_Elmt
: Elmt_Id
)
11074 Prim_Elmt
: Elmt_Id
;
11077 Prim_Elmt
:= Start_Elmt
;
11078 while Present
(Prim_Elmt
) loop
11079 Prim
:= Node
(Prim_Elmt
);
11081 -- The current primitive is implicitly declared non-overridden
11082 -- non-fully conformant homograph of Subp_Id. Both subprograms
11083 -- must be hidden from visibility.
11085 if Chars
(Prim
) = Chars
(Subp_Id
)
11086 and then Is_Non_Overridden_Or_Null_Procedure
(Prim
)
11087 and then not Fully_Conformant
(Prim
, Subp_Id
)
11089 Set_Is_Hidden_Non_Overridden_Subpgm
(Prim
);
11090 Set_Is_Immediately_Visible
(Prim
, False);
11091 Set_Is_Potentially_Use_Visible
(Prim
, False);
11093 Set_Is_Hidden_Non_Overridden_Subpgm
(Subp_Id
);
11094 Set_Is_Immediately_Visible
(Subp_Id
, False);
11095 Set_Is_Potentially_Use_Visible
(Subp_Id
, False);
11098 Next_Elmt
(Prim_Elmt
);
11100 end Hide_Matching_Homographs
;
11102 -----------------------------------------
11103 -- Is_Non_Overridden_Or_Null_Procedure --
11104 -----------------------------------------
11106 function Is_Non_Overridden_Or_Null_Procedure
11107 (Subp_Id
: Entity_Id
) return Boolean
11109 Alias_Id
: Entity_Id
;
11112 -- The subprogram is inherited (implicitly declared), it does not
11113 -- override and does not cover a primitive of an interface.
11115 if Ekind_In
(Subp_Id
, E_Function
, E_Procedure
)
11116 and then Present
(Alias
(Subp_Id
))
11117 and then No
(Interface_Alias
(Subp_Id
))
11118 and then No
(Overridden_Operation
(Subp_Id
))
11120 Alias_Id
:= Alias
(Subp_Id
);
11122 if Requires_Overriding
(Alias_Id
) then
11125 elsif Nkind
(Parent
(Alias_Id
)) = N_Procedure_Specification
11126 and then Null_Present
(Parent
(Alias_Id
))
11133 end Is_Non_Overridden_Or_Null_Procedure
;
11137 Prim_Ops
: constant Elist_Id
:= Direct_Primitive_Operations
(Typ
);
11139 Prim_Elmt
: Elmt_Id
;
11141 -- Start of processing for Hide_Non_Overridden_Subprograms
11144 -- Inspect the list of primitives looking for non-overridden
11147 if Present
(Prim_Ops
) then
11148 Prim_Elmt
:= First_Elmt
(Prim_Ops
);
11149 while Present
(Prim_Elmt
) loop
11150 Prim
:= Node
(Prim_Elmt
);
11151 Next_Elmt
(Prim_Elmt
);
11153 if Is_Non_Overridden_Or_Null_Procedure
(Prim
) then
11154 Hide_Matching_Homographs
11156 Start_Elmt
=> Prim_Elmt
);
11160 end Hide_Non_Overridden_Subprograms
;
11162 ---------------------
11163 -- Local variables --
11164 ---------------------
11166 E
: constant Entity_Id
:= Entity
(N
);
11168 Non_Generic_Case
: constant Boolean := Nkind
(N
) = N_Freeze_Entity
;
11169 -- True in non-generic case. Some of the processing here is skipped
11170 -- for the generic case since it is not needed. Basically in the
11171 -- generic case, we only need to do stuff that might generate error
11172 -- messages or warnings.
11174 -- Start of processing for Freeze_Entity_Checks
11177 -- Remember that we are processing a freezing entity. Required to
11178 -- ensure correct decoration of internal entities associated with
11179 -- interfaces (see New_Overloaded_Entity).
11181 Inside_Freezing_Actions
:= Inside_Freezing_Actions
+ 1;
11183 -- For tagged types covering interfaces add internal entities that link
11184 -- the primitives of the interfaces with the primitives that cover them.
11185 -- Note: These entities were originally generated only when generating
11186 -- code because their main purpose was to provide support to initialize
11187 -- the secondary dispatch tables. They are now generated also when
11188 -- compiling with no code generation to provide ASIS the relationship
11189 -- between interface primitives and tagged type primitives. They are
11190 -- also used to locate primitives covering interfaces when processing
11191 -- generics (see Derive_Subprograms).
11193 -- This is not needed in the generic case
11195 if Ada_Version
>= Ada_2005
11196 and then Non_Generic_Case
11197 and then Ekind
(E
) = E_Record_Type
11198 and then Is_Tagged_Type
(E
)
11199 and then not Is_Interface
(E
)
11200 and then Has_Interfaces
(E
)
11202 -- This would be a good common place to call the routine that checks
11203 -- overriding of interface primitives (and thus factorize calls to
11204 -- Check_Abstract_Overriding located at different contexts in the
11205 -- compiler). However, this is not possible because it causes
11206 -- spurious errors in case of late overriding.
11208 Add_Internal_Interface_Entities
(E
);
11211 -- After all forms of overriding have been resolved, a tagged type may
11212 -- be left with a set of implicitly declared and possibly erroneous
11213 -- abstract subprograms, null procedures and subprograms that require
11214 -- overriding. If this set contains fully conformant homographs, then
11215 -- one is chosen arbitrarily (already done during resolution), otherwise
11216 -- all remaining non-fully conformant homographs are hidden from
11217 -- visibility (Ada RM 8.3 12.3/2).
11219 if Is_Tagged_Type
(E
) then
11220 Hide_Non_Overridden_Subprograms
(E
);
11225 if Ekind
(E
) = E_Record_Type
11226 and then Is_CPP_Class
(E
)
11227 and then Is_Tagged_Type
(E
)
11228 and then Tagged_Type_Expansion
11230 if CPP_Num_Prims
(E
) = 0 then
11232 -- If the CPP type has user defined components then it must import
11233 -- primitives from C++. This is required because if the C++ class
11234 -- has no primitives then the C++ compiler does not added the _tag
11235 -- component to the type.
11237 if First_Entity
(E
) /= Last_Entity
(E
) then
11239 ("'C'P'P type must import at least one primitive from C++??",
11244 -- Check that all its primitives are abstract or imported from C++.
11245 -- Check also availability of the C++ constructor.
11248 Has_Constructors
: constant Boolean := Has_CPP_Constructors
(E
);
11250 Error_Reported
: Boolean := False;
11254 Elmt
:= First_Elmt
(Primitive_Operations
(E
));
11255 while Present
(Elmt
) loop
11256 Prim
:= Node
(Elmt
);
11258 if Comes_From_Source
(Prim
) then
11259 if Is_Abstract_Subprogram
(Prim
) then
11262 elsif not Is_Imported
(Prim
)
11263 or else Convention
(Prim
) /= Convention_CPP
11266 ("primitives of 'C'P'P types must be imported from C++ "
11267 & "or abstract??", Prim
);
11269 elsif not Has_Constructors
11270 and then not Error_Reported
11272 Error_Msg_Name_1
:= Chars
(E
);
11274 ("??'C'P'P constructor required for type %", Prim
);
11275 Error_Reported
:= True;
11284 -- Check Ada derivation of CPP type
11286 if Expander_Active
-- why? losing errors in -gnatc mode???
11287 and then Present
(Etype
(E
)) -- defend against errors
11288 and then Tagged_Type_Expansion
11289 and then Ekind
(E
) = E_Record_Type
11290 and then Etype
(E
) /= E
11291 and then Is_CPP_Class
(Etype
(E
))
11292 and then CPP_Num_Prims
(Etype
(E
)) > 0
11293 and then not Is_CPP_Class
(E
)
11294 and then not Has_CPP_Constructors
(Etype
(E
))
11296 -- If the parent has C++ primitives but it has no constructor then
11297 -- check that all the primitives are overridden in this derivation;
11298 -- otherwise the constructor of the parent is needed to build the
11306 Elmt
:= First_Elmt
(Primitive_Operations
(E
));
11307 while Present
(Elmt
) loop
11308 Prim
:= Node
(Elmt
);
11310 if not Is_Abstract_Subprogram
(Prim
)
11311 and then No
(Interface_Alias
(Prim
))
11312 and then Find_Dispatching_Type
(Ultimate_Alias
(Prim
)) /= E
11314 Error_Msg_Name_1
:= Chars
(Etype
(E
));
11316 ("'C'P'P constructor required for parent type %", E
);
11325 Inside_Freezing_Actions
:= Inside_Freezing_Actions
- 1;
11327 -- If we have a type with predicates, build predicate function. This
11328 -- is not needed in the generic case, and is not needed within TSS
11329 -- subprograms and other predefined primitives.
11331 if Non_Generic_Case
11332 and then Is_Type
(E
)
11333 and then Has_Predicates
(E
)
11334 and then not Within_Internal_Subprogram
11336 Build_Predicate_Functions
(E
, N
);
11339 -- If type has delayed aspects, this is where we do the preanalysis at
11340 -- the freeze point, as part of the consistent visibility check. Note
11341 -- that this must be done after calling Build_Predicate_Functions or
11342 -- Build_Invariant_Procedure since these subprograms fix occurrences of
11343 -- the subtype name in the saved expression so that they will not cause
11344 -- trouble in the preanalysis.
11346 -- This is also not needed in the generic case
11348 if Non_Generic_Case
11349 and then Has_Delayed_Aspects
(E
)
11350 and then Scope
(E
) = Current_Scope
11352 -- Retrieve the visibility to the discriminants in order to properly
11353 -- analyze the aspects.
11355 Push_Scope_And_Install_Discriminants
(E
);
11361 -- Look for aspect specification entries for this entity
11363 Ritem
:= First_Rep_Item
(E
);
11364 while Present
(Ritem
) loop
11365 if Nkind
(Ritem
) = N_Aspect_Specification
11366 and then Entity
(Ritem
) = E
11367 and then Is_Delayed_Aspect
(Ritem
)
11369 Check_Aspect_At_Freeze_Point
(Ritem
);
11372 Next_Rep_Item
(Ritem
);
11376 Uninstall_Discriminants_And_Pop_Scope
(E
);
11379 -- For a record type, deal with variant parts. This has to be delayed
11380 -- to this point, because of the issue of statically predicated
11381 -- subtypes, which we have to ensure are frozen before checking
11382 -- choices, since we need to have the static choice list set.
11384 if Is_Record_Type
(E
) then
11385 Check_Variant_Part
: declare
11386 D
: constant Node_Id
:= Declaration_Node
(E
);
11391 Others_Present
: Boolean;
11392 pragma Warnings
(Off
, Others_Present
);
11393 -- Indicates others present, not used in this case
11395 procedure Non_Static_Choice_Error
(Choice
: Node_Id
);
11396 -- Error routine invoked by the generic instantiation below when
11397 -- the variant part has a non static choice.
11399 procedure Process_Declarations
(Variant
: Node_Id
);
11400 -- Processes declarations associated with a variant. We analyzed
11401 -- the declarations earlier (in Sem_Ch3.Analyze_Variant_Part),
11402 -- but we still need the recursive call to Check_Choices for any
11403 -- nested variant to get its choices properly processed. This is
11404 -- also where we expand out the choices if expansion is active.
11406 package Variant_Choices_Processing
is new
11407 Generic_Check_Choices
11408 (Process_Empty_Choice
=> No_OP
,
11409 Process_Non_Static_Choice
=> Non_Static_Choice_Error
,
11410 Process_Associated_Node
=> Process_Declarations
);
11411 use Variant_Choices_Processing
;
11413 -----------------------------
11414 -- Non_Static_Choice_Error --
11415 -----------------------------
11417 procedure Non_Static_Choice_Error
(Choice
: Node_Id
) is
11419 Flag_Non_Static_Expr
11420 ("choice given in variant part is not static!", Choice
);
11421 end Non_Static_Choice_Error
;
11423 --------------------------
11424 -- Process_Declarations --
11425 --------------------------
11427 procedure Process_Declarations
(Variant
: Node_Id
) is
11428 CL
: constant Node_Id
:= Component_List
(Variant
);
11432 -- Check for static predicate present in this variant
11434 if Has_SP_Choice
(Variant
) then
11436 -- Here we expand. You might expect to find this call in
11437 -- Expand_N_Variant_Part, but that is called when we first
11438 -- see the variant part, and we cannot do this expansion
11439 -- earlier than the freeze point, since for statically
11440 -- predicated subtypes, the predicate is not known till
11441 -- the freeze point.
11443 -- Furthermore, we do this expansion even if the expander
11444 -- is not active, because other semantic processing, e.g.
11445 -- for aggregates, requires the expanded list of choices.
11447 -- If the expander is not active, then we can't just clobber
11448 -- the list since it would invalidate the ASIS -gnatct tree.
11449 -- So we have to rewrite the variant part with a Rewrite
11450 -- call that replaces it with a copy and clobber the copy.
11452 if not Expander_Active
then
11454 NewV
: constant Node_Id
:= New_Copy
(Variant
);
11456 Set_Discrete_Choices
11457 (NewV
, New_Copy_List
(Discrete_Choices
(Variant
)));
11458 Rewrite
(Variant
, NewV
);
11462 Expand_Static_Predicates_In_Choices
(Variant
);
11465 -- We don't need to worry about the declarations in the variant
11466 -- (since they were analyzed by Analyze_Choices when we first
11467 -- encountered the variant), but we do need to take care of
11468 -- expansion of any nested variants.
11470 if not Null_Present
(CL
) then
11471 VP
:= Variant_Part
(CL
);
11473 if Present
(VP
) then
11475 (VP
, Variants
(VP
), Etype
(Name
(VP
)), Others_Present
);
11478 end Process_Declarations
;
11480 -- Start of processing for Check_Variant_Part
11483 -- Find component list
11487 if Nkind
(D
) = N_Full_Type_Declaration
then
11488 T
:= Type_Definition
(D
);
11490 if Nkind
(T
) = N_Record_Definition
then
11491 C
:= Component_List
(T
);
11493 elsif Nkind
(T
) = N_Derived_Type_Definition
11494 and then Present
(Record_Extension_Part
(T
))
11496 C
:= Component_List
(Record_Extension_Part
(T
));
11500 -- Case of variant part present
11502 if Present
(C
) and then Present
(Variant_Part
(C
)) then
11503 VP
:= Variant_Part
(C
);
11508 (VP
, Variants
(VP
), Etype
(Name
(VP
)), Others_Present
);
11510 -- If the last variant does not contain the Others choice,
11511 -- replace it with an N_Others_Choice node since Gigi always
11512 -- wants an Others. Note that we do not bother to call Analyze
11513 -- on the modified variant part, since its only effect would be
11514 -- to compute the Others_Discrete_Choices node laboriously, and
11515 -- of course we already know the list of choices corresponding
11516 -- to the others choice (it's the list we're replacing).
11518 -- We only want to do this if the expander is active, since
11519 -- we do not want to clobber the ASIS tree.
11521 if Expander_Active
then
11523 Last_Var
: constant Node_Id
:=
11524 Last_Non_Pragma
(Variants
(VP
));
11526 Others_Node
: Node_Id
;
11529 if Nkind
(First
(Discrete_Choices
(Last_Var
))) /=
11532 Others_Node
:= Make_Others_Choice
(Sloc
(Last_Var
));
11533 Set_Others_Discrete_Choices
11534 (Others_Node
, Discrete_Choices
(Last_Var
));
11535 Set_Discrete_Choices
11536 (Last_Var
, New_List
(Others_Node
));
11541 end Check_Variant_Part
;
11543 end Freeze_Entity_Checks
;
11545 -------------------------
11546 -- Get_Alignment_Value --
11547 -------------------------
11549 function Get_Alignment_Value
(Expr
: Node_Id
) return Uint
is
11550 Align
: constant Uint
:= Static_Integer
(Expr
);
11553 if Align
= No_Uint
then
11556 elsif Align
<= 0 then
11558 -- This error is suppressed in ASIS mode to allow for different ASIS
11559 -- back ends or ASIS-based tools to query the illegal clause.
11561 if not ASIS_Mode
then
11562 Error_Msg_N
("alignment value must be positive", Expr
);
11568 for J
in Int
range 0 .. 64 loop
11570 M
: constant Uint
:= Uint_2
** J
;
11573 exit when M
= Align
;
11577 -- This error is suppressed in ASIS mode to allow for
11578 -- different ASIS back ends or ASIS-based tools to query the
11581 if not ASIS_Mode
then
11582 Error_Msg_N
("alignment value must be power of 2", Expr
);
11592 end Get_Alignment_Value
;
11594 -----------------------------
11595 -- Get_Interfacing_Aspects --
11596 -----------------------------
11598 procedure Get_Interfacing_Aspects
11599 (Iface_Asp
: Node_Id
;
11600 Conv_Asp
: out Node_Id
;
11601 EN_Asp
: out Node_Id
;
11602 Expo_Asp
: out Node_Id
;
11603 Imp_Asp
: out Node_Id
;
11604 LN_Asp
: out Node_Id
;
11605 Do_Checks
: Boolean := False)
11607 procedure Save_Or_Duplication_Error
11609 To
: in out Node_Id
);
11610 -- Save the value of aspect Asp in node To. If To already has a value,
11611 -- then this is considered a duplicate use of aspect. Emit an error if
11612 -- flag Do_Checks is set.
11614 -------------------------------
11615 -- Save_Or_Duplication_Error --
11616 -------------------------------
11618 procedure Save_Or_Duplication_Error
11620 To
: in out Node_Id
)
11623 -- Detect an extra aspect and issue an error
11625 if Present
(To
) then
11627 Error_Msg_Name_1
:= Chars
(Identifier
(Asp
));
11628 Error_Msg_Sloc
:= Sloc
(To
);
11629 Error_Msg_N
("aspect % previously given #", Asp
);
11632 -- Otherwise capture the aspect
11637 end Save_Or_Duplication_Error
;
11642 Asp_Id
: Aspect_Id
;
11644 -- The following variables capture each individual aspect
11646 Conv
: Node_Id
:= Empty
;
11647 EN
: Node_Id
:= Empty
;
11648 Expo
: Node_Id
:= Empty
;
11649 Imp
: Node_Id
:= Empty
;
11650 LN
: Node_Id
:= Empty
;
11652 -- Start of processing for Get_Interfacing_Aspects
11655 -- The input interfacing aspect should reside in an aspect specification
11658 pragma Assert
(Is_List_Member
(Iface_Asp
));
11660 -- Examine the aspect specifications of the related entity. Find and
11661 -- capture all interfacing aspects. Detect duplicates and emit errors
11664 Asp
:= First
(List_Containing
(Iface_Asp
));
11665 while Present
(Asp
) loop
11666 Asp_Id
:= Get_Aspect_Id
(Asp
);
11668 if Asp_Id
= Aspect_Convention
then
11669 Save_Or_Duplication_Error
(Asp
, Conv
);
11671 elsif Asp_Id
= Aspect_External_Name
then
11672 Save_Or_Duplication_Error
(Asp
, EN
);
11674 elsif Asp_Id
= Aspect_Export
then
11675 Save_Or_Duplication_Error
(Asp
, Expo
);
11677 elsif Asp_Id
= Aspect_Import
then
11678 Save_Or_Duplication_Error
(Asp
, Imp
);
11680 elsif Asp_Id
= Aspect_Link_Name
then
11681 Save_Or_Duplication_Error
(Asp
, LN
);
11692 end Get_Interfacing_Aspects
;
11694 -------------------------------------
11695 -- Inherit_Aspects_At_Freeze_Point --
11696 -------------------------------------
11698 procedure Inherit_Aspects_At_Freeze_Point
(Typ
: Entity_Id
) is
11699 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11700 (Rep_Item
: Node_Id
) return Boolean;
11701 -- This routine checks if Rep_Item is either a pragma or an aspect
11702 -- specification node whose correponding pragma (if any) is present in
11703 -- the Rep Item chain of the entity it has been specified to.
11705 --------------------------------------------------
11706 -- Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item --
11707 --------------------------------------------------
11709 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11710 (Rep_Item
: Node_Id
) return Boolean
11714 Nkind
(Rep_Item
) = N_Pragma
11715 or else Present_In_Rep_Item
11716 (Entity
(Rep_Item
), Aspect_Rep_Item
(Rep_Item
));
11717 end Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
;
11719 -- Start of processing for Inherit_Aspects_At_Freeze_Point
11722 -- A representation item is either subtype-specific (Size and Alignment
11723 -- clauses) or type-related (all others). Subtype-specific aspects may
11724 -- differ for different subtypes of the same type (RM 13.1.8).
11726 -- A derived type inherits each type-related representation aspect of
11727 -- its parent type that was directly specified before the declaration of
11728 -- the derived type (RM 13.1.15).
11730 -- A derived subtype inherits each subtype-specific representation
11731 -- aspect of its parent subtype that was directly specified before the
11732 -- declaration of the derived type (RM 13.1.15).
11734 -- The general processing involves inheriting a representation aspect
11735 -- from a parent type whenever the first rep item (aspect specification,
11736 -- attribute definition clause, pragma) corresponding to the given
11737 -- representation aspect in the rep item chain of Typ, if any, isn't
11738 -- directly specified to Typ but to one of its parents.
11740 -- ??? Note that, for now, just a limited number of representation
11741 -- aspects have been inherited here so far. Many of them are
11742 -- still inherited in Sem_Ch3. This will be fixed soon. Here is
11743 -- a non- exhaustive list of aspects that likely also need to
11744 -- be moved to this routine: Alignment, Component_Alignment,
11745 -- Component_Size, Machine_Radix, Object_Size, Pack, Predicates,
11746 -- Preelaborable_Initialization, RM_Size and Small.
11748 -- In addition, Convention must be propagated from base type to subtype,
11749 -- because the subtype may have been declared on an incomplete view.
11751 if Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
then
11757 if not Has_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
, False)
11758 and then Has_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
)
11759 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11760 (Get_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
))
11762 Set_Is_Ada_2005_Only
(Typ
);
11767 if not Has_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
, False)
11768 and then Has_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
)
11769 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11770 (Get_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
))
11772 Set_Is_Ada_2012_Only
(Typ
);
11777 if not Has_Rep_Item
(Typ
, Name_Atomic
, Name_Shared
, False)
11778 and then Has_Rep_Pragma
(Typ
, Name_Atomic
, Name_Shared
)
11779 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11780 (Get_Rep_Item
(Typ
, Name_Atomic
, Name_Shared
))
11782 Set_Is_Atomic
(Typ
);
11783 Set_Is_Volatile
(Typ
);
11784 Set_Treat_As_Volatile
(Typ
);
11789 if Is_Record_Type
(Typ
)
11790 and then Typ
/= Base_Type
(Typ
) and then Is_Frozen
(Base_Type
(Typ
))
11792 Set_Convention
(Typ
, Convention
(Base_Type
(Typ
)));
11795 -- Default_Component_Value
11797 -- Verify that there is no rep_item declared for the type, and there
11798 -- is one coming from an ancestor.
11800 if Is_Array_Type
(Typ
)
11801 and then Is_Base_Type
(Typ
)
11802 and then not Has_Rep_Item
(Typ
, Name_Default_Component_Value
, False)
11803 and then Has_Rep_Item
(Typ
, Name_Default_Component_Value
)
11805 Set_Default_Aspect_Component_Value
(Typ
,
11806 Default_Aspect_Component_Value
11807 (Entity
(Get_Rep_Item
(Typ
, Name_Default_Component_Value
))));
11812 if Is_Scalar_Type
(Typ
)
11813 and then Is_Base_Type
(Typ
)
11814 and then not Has_Rep_Item
(Typ
, Name_Default_Value
, False)
11815 and then Has_Rep_Item
(Typ
, Name_Default_Value
)
11817 Set_Has_Default_Aspect
(Typ
);
11818 Set_Default_Aspect_Value
(Typ
,
11819 Default_Aspect_Value
11820 (Entity
(Get_Rep_Item
(Typ
, Name_Default_Value
))));
11825 if not Has_Rep_Item
(Typ
, Name_Discard_Names
, False)
11826 and then Has_Rep_Item
(Typ
, Name_Discard_Names
)
11827 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11828 (Get_Rep_Item
(Typ
, Name_Discard_Names
))
11830 Set_Discard_Names
(Typ
);
11835 if not Has_Rep_Item
(Typ
, Name_Invariant
, False)
11836 and then Has_Rep_Item
(Typ
, Name_Invariant
)
11837 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11838 (Get_Rep_Item
(Typ
, Name_Invariant
))
11840 Set_Has_Invariants
(Typ
);
11842 if Class_Present
(Get_Rep_Item
(Typ
, Name_Invariant
)) then
11843 Set_Has_Inheritable_Invariants
(Typ
);
11846 -- If we have a subtype with invariants, whose base type does not have
11847 -- invariants, copy these invariants to the base type. This happens for
11848 -- the case of implicit base types created for scalar and array types.
11850 elsif Has_Invariants
(Typ
)
11851 and then not Has_Invariants
(Base_Type
(Typ
))
11853 Set_Has_Invariants
(Base_Type
(Typ
));
11854 Set_Invariant_Procedure
(Base_Type
(Typ
), Invariant_Procedure
(Typ
));
11859 if not Has_Rep_Item
(Typ
, Name_Volatile
, False)
11860 and then Has_Rep_Item
(Typ
, Name_Volatile
)
11861 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11862 (Get_Rep_Item
(Typ
, Name_Volatile
))
11864 Set_Is_Volatile
(Typ
);
11865 Set_Treat_As_Volatile
(Typ
);
11868 -- Volatile_Full_Access
11870 if not Has_Rep_Item
(Typ
, Name_Volatile_Full_Access
, False)
11871 and then Has_Rep_Pragma
(Typ
, Name_Volatile_Full_Access
)
11872 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11873 (Get_Rep_Item
(Typ
, Name_Volatile_Full_Access
))
11875 Set_Is_Volatile_Full_Access
(Typ
);
11876 Set_Is_Volatile
(Typ
);
11877 Set_Treat_As_Volatile
(Typ
);
11880 -- Inheritance for derived types only
11882 if Is_Derived_Type
(Typ
) then
11884 Bas_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
11885 Imp_Bas_Typ
: constant Entity_Id
:= Implementation_Base_Type
(Typ
);
11888 -- Atomic_Components
11890 if not Has_Rep_Item
(Typ
, Name_Atomic_Components
, False)
11891 and then Has_Rep_Item
(Typ
, Name_Atomic_Components
)
11892 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11893 (Get_Rep_Item
(Typ
, Name_Atomic_Components
))
11895 Set_Has_Atomic_Components
(Imp_Bas_Typ
);
11898 -- Volatile_Components
11900 if not Has_Rep_Item
(Typ
, Name_Volatile_Components
, False)
11901 and then Has_Rep_Item
(Typ
, Name_Volatile_Components
)
11902 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11903 (Get_Rep_Item
(Typ
, Name_Volatile_Components
))
11905 Set_Has_Volatile_Components
(Imp_Bas_Typ
);
11908 -- Finalize_Storage_Only
11910 if not Has_Rep_Pragma
(Typ
, Name_Finalize_Storage_Only
, False)
11911 and then Has_Rep_Pragma
(Typ
, Name_Finalize_Storage_Only
)
11913 Set_Finalize_Storage_Only
(Bas_Typ
);
11916 -- Universal_Aliasing
11918 if not Has_Rep_Item
(Typ
, Name_Universal_Aliasing
, False)
11919 and then Has_Rep_Item
(Typ
, Name_Universal_Aliasing
)
11920 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11921 (Get_Rep_Item
(Typ
, Name_Universal_Aliasing
))
11923 Set_Universal_Aliasing
(Imp_Bas_Typ
);
11928 if Is_Record_Type
(Typ
) then
11929 if not Has_Rep_Item
(Typ
, Name_Bit_Order
, False)
11930 and then Has_Rep_Item
(Typ
, Name_Bit_Order
)
11932 Set_Reverse_Bit_Order
(Bas_Typ
,
11933 Reverse_Bit_Order
(Entity
(Name
11934 (Get_Rep_Item
(Typ
, Name_Bit_Order
)))));
11938 -- Scalar_Storage_Order
11940 -- Note: the aspect is specified on a first subtype, but recorded
11941 -- in a flag of the base type!
11943 if (Is_Record_Type
(Typ
) or else Is_Array_Type
(Typ
))
11944 and then Typ
= Bas_Typ
11946 -- For a type extension, always inherit from parent; otherwise
11947 -- inherit if no default applies. Note: we do not check for
11948 -- an explicit rep item on the parent type when inheriting,
11949 -- because the parent SSO may itself have been set by default.
11951 if not Has_Rep_Item
(First_Subtype
(Typ
),
11952 Name_Scalar_Storage_Order
, False)
11953 and then (Is_Tagged_Type
(Bas_Typ
)
11954 or else not (SSO_Set_Low_By_Default
(Bas_Typ
)
11956 SSO_Set_High_By_Default
(Bas_Typ
)))
11958 Set_Reverse_Storage_Order
(Bas_Typ
,
11959 Reverse_Storage_Order
11960 (Implementation_Base_Type
(Etype
(Bas_Typ
))));
11962 -- Clear default SSO indications, since the inherited aspect
11963 -- which was set explicitly overrides the default.
11965 Set_SSO_Set_Low_By_Default
(Bas_Typ
, False);
11966 Set_SSO_Set_High_By_Default
(Bas_Typ
, False);
11971 end Inherit_Aspects_At_Freeze_Point
;
11977 procedure Initialize
is
11979 Address_Clause_Checks
.Init
;
11980 Unchecked_Conversions
.Init
;
11982 if AAMP_On_Target
then
11983 Independence_Checks
.Init
;
11987 ---------------------------
11988 -- Install_Discriminants --
11989 ---------------------------
11991 procedure Install_Discriminants
(E
: Entity_Id
) is
11995 Disc
:= First_Discriminant
(E
);
11996 while Present
(Disc
) loop
11997 Prev
:= Current_Entity
(Disc
);
11998 Set_Current_Entity
(Disc
);
11999 Set_Is_Immediately_Visible
(Disc
);
12000 Set_Homonym
(Disc
, Prev
);
12001 Next_Discriminant
(Disc
);
12003 end Install_Discriminants
;
12005 -------------------------
12006 -- Is_Operational_Item --
12007 -------------------------
12009 function Is_Operational_Item
(N
: Node_Id
) return Boolean is
12011 if Nkind
(N
) /= N_Attribute_Definition_Clause
then
12016 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Chars
(N
));
12019 -- List of operational items is given in AARM 13.1(8.mm/1).
12020 -- It is clearly incomplete, as it does not include iterator
12021 -- aspects, among others.
12023 return Id
= Attribute_Constant_Indexing
12024 or else Id
= Attribute_Default_Iterator
12025 or else Id
= Attribute_Implicit_Dereference
12026 or else Id
= Attribute_Input
12027 or else Id
= Attribute_Iterator_Element
12028 or else Id
= Attribute_Iterable
12029 or else Id
= Attribute_Output
12030 or else Id
= Attribute_Read
12031 or else Id
= Attribute_Variable_Indexing
12032 or else Id
= Attribute_Write
12033 or else Id
= Attribute_External_Tag
;
12036 end Is_Operational_Item
;
12038 -------------------------
12039 -- Is_Predicate_Static --
12040 -------------------------
12042 -- Note: the basic legality of the expression has already been checked, so
12043 -- we don't need to worry about cases or ranges on strings for example.
12045 function Is_Predicate_Static
12047 Nam
: Name_Id
) return Boolean
12049 function All_Static_Case_Alternatives
(L
: List_Id
) return Boolean;
12050 -- Given a list of case expression alternatives, returns True if all
12051 -- the alternatives are static (have all static choices, and a static
12054 function All_Static_Choices
(L
: List_Id
) return Boolean;
12055 -- Returns true if all elements of the list are OK static choices
12056 -- as defined below for Is_Static_Choice. Used for case expression
12057 -- alternatives and for the right operand of a membership test. An
12058 -- others_choice is static if the corresponding expression is static.
12059 -- The staticness of the bounds is checked separately.
12061 function Is_Static_Choice
(N
: Node_Id
) return Boolean;
12062 -- Returns True if N represents a static choice (static subtype, or
12063 -- static subtype indication, or static expression, or static range).
12065 -- Note that this is a bit more inclusive than we actually need
12066 -- (in particular membership tests do not allow the use of subtype
12067 -- indications). But that doesn't matter, we have already checked
12068 -- that the construct is legal to get this far.
12070 function Is_Type_Ref
(N
: Node_Id
) return Boolean;
12071 pragma Inline
(Is_Type_Ref
);
12072 -- Returns True if N is a reference to the type for the predicate in the
12073 -- expression (i.e. if it is an identifier whose Chars field matches the
12074 -- Nam given in the call). N must not be parenthesized, if the type name
12075 -- appears in parens, this routine will return False.
12077 ----------------------------------
12078 -- All_Static_Case_Alternatives --
12079 ----------------------------------
12081 function All_Static_Case_Alternatives
(L
: List_Id
) return Boolean is
12086 while Present
(N
) loop
12087 if not (All_Static_Choices
(Discrete_Choices
(N
))
12088 and then Is_OK_Static_Expression
(Expression
(N
)))
12097 end All_Static_Case_Alternatives
;
12099 ------------------------
12100 -- All_Static_Choices --
12101 ------------------------
12103 function All_Static_Choices
(L
: List_Id
) return Boolean is
12108 while Present
(N
) loop
12109 if not Is_Static_Choice
(N
) then
12117 end All_Static_Choices
;
12119 ----------------------
12120 -- Is_Static_Choice --
12121 ----------------------
12123 function Is_Static_Choice
(N
: Node_Id
) return Boolean is
12125 return Nkind
(N
) = N_Others_Choice
12126 or else Is_OK_Static_Expression
(N
)
12127 or else (Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
))
12128 and then Is_OK_Static_Subtype
(Entity
(N
)))
12129 or else (Nkind
(N
) = N_Subtype_Indication
12130 and then Is_OK_Static_Subtype
(Entity
(N
)))
12131 or else (Nkind
(N
) = N_Range
and then Is_OK_Static_Range
(N
));
12132 end Is_Static_Choice
;
12138 function Is_Type_Ref
(N
: Node_Id
) return Boolean is
12140 return Nkind
(N
) = N_Identifier
12141 and then Chars
(N
) = Nam
12142 and then Paren_Count
(N
) = 0;
12145 -- Start of processing for Is_Predicate_Static
12148 -- Predicate_Static means one of the following holds. Numbers are the
12149 -- corresponding paragraph numbers in (RM 3.2.4(16-22)).
12151 -- 16: A static expression
12153 if Is_OK_Static_Expression
(Expr
) then
12156 -- 17: A membership test whose simple_expression is the current
12157 -- instance, and whose membership_choice_list meets the requirements
12158 -- for a static membership test.
12160 elsif Nkind
(Expr
) in N_Membership_Test
12161 and then ((Present
(Right_Opnd
(Expr
))
12162 and then Is_Static_Choice
(Right_Opnd
(Expr
)))
12164 (Present
(Alternatives
(Expr
))
12165 and then All_Static_Choices
(Alternatives
(Expr
))))
12169 -- 18. A case_expression whose selecting_expression is the current
12170 -- instance, and whose dependent expressions are static expressions.
12172 elsif Nkind
(Expr
) = N_Case_Expression
12173 and then Is_Type_Ref
(Expression
(Expr
))
12174 and then All_Static_Case_Alternatives
(Alternatives
(Expr
))
12178 -- 19. A call to a predefined equality or ordering operator, where one
12179 -- operand is the current instance, and the other is a static
12182 -- Note: the RM is clearly wrong here in not excluding string types.
12183 -- Without this exclusion, we would allow expressions like X > "ABC"
12184 -- to be considered as predicate-static, which is clearly not intended,
12185 -- since the idea is for predicate-static to be a subset of normal
12186 -- static expressions (and "DEF" > "ABC" is not a static expression).
12188 -- However, we do allow internally generated (not from source) equality
12189 -- and inequality operations to be valid on strings (this helps deal
12190 -- with cases where we transform A in "ABC" to A = "ABC).
12192 elsif Nkind
(Expr
) in N_Op_Compare
12193 and then ((not Is_String_Type
(Etype
(Left_Opnd
(Expr
))))
12194 or else (Nkind_In
(Expr
, N_Op_Eq
, N_Op_Ne
)
12195 and then not Comes_From_Source
(Expr
)))
12196 and then ((Is_Type_Ref
(Left_Opnd
(Expr
))
12197 and then Is_OK_Static_Expression
(Right_Opnd
(Expr
)))
12199 (Is_Type_Ref
(Right_Opnd
(Expr
))
12200 and then Is_OK_Static_Expression
(Left_Opnd
(Expr
))))
12204 -- 20. A call to a predefined boolean logical operator, where each
12205 -- operand is predicate-static.
12207 elsif (Nkind_In
(Expr
, N_Op_And
, N_Op_Or
, N_Op_Xor
)
12208 and then Is_Predicate_Static
(Left_Opnd
(Expr
), Nam
)
12209 and then Is_Predicate_Static
(Right_Opnd
(Expr
), Nam
))
12211 (Nkind
(Expr
) = N_Op_Not
12212 and then Is_Predicate_Static
(Right_Opnd
(Expr
), Nam
))
12216 -- 21. A short-circuit control form where both operands are
12217 -- predicate-static.
12219 elsif Nkind
(Expr
) in N_Short_Circuit
12220 and then Is_Predicate_Static
(Left_Opnd
(Expr
), Nam
)
12221 and then Is_Predicate_Static
(Right_Opnd
(Expr
), Nam
)
12225 -- 22. A parenthesized predicate-static expression. This does not
12226 -- require any special test, since we just ignore paren levels in
12227 -- all the cases above.
12229 -- One more test that is an implementation artifact caused by the fact
12230 -- that we are analyzing not the original expression, but the generated
12231 -- expression in the body of the predicate function. This can include
12232 -- references to inherited predicates, so that the expression we are
12233 -- processing looks like:
12235 -- xxPredicate (typ (Inns)) and then expression
12237 -- Where the call is to a Predicate function for an inherited predicate.
12238 -- We simply ignore such a call, which could be to either a dynamic or
12239 -- a static predicate. Note that if the parent predicate is dynamic then
12240 -- eventually this type will be marked as dynamic, but you are allowed
12241 -- to specify a static predicate for a subtype which is inheriting a
12242 -- dynamic predicate, so the static predicate validation here ignores
12243 -- the inherited predicate even if it is dynamic.
12245 elsif Nkind
(Expr
) = N_Function_Call
12246 and then Is_Predicate_Function
(Entity
(Name
(Expr
)))
12250 -- That's an exhaustive list of tests, all other cases are not
12251 -- predicate-static, so we return False.
12256 end Is_Predicate_Static
;
12258 ---------------------
12259 -- Kill_Rep_Clause --
12260 ---------------------
12262 procedure Kill_Rep_Clause
(N
: Node_Id
) is
12264 pragma Assert
(Ignore_Rep_Clauses
);
12266 -- Note: we use Replace rather than Rewrite, because we don't want
12267 -- ASIS to be able to use Original_Node to dig out the (undecorated)
12268 -- rep clause that is being replaced.
12270 Replace
(N
, Make_Null_Statement
(Sloc
(N
)));
12272 -- The null statement must be marked as not coming from source. This is
12273 -- so that ASIS ignores it, and also the back end does not expect bogus
12274 -- "from source" null statements in weird places (e.g. in declarative
12275 -- regions where such null statements are not allowed).
12277 Set_Comes_From_Source
(N
, False);
12278 end Kill_Rep_Clause
;
12284 function Minimum_Size
12286 Biased
: Boolean := False) return Nat
12288 Lo
: Uint
:= No_Uint
;
12289 Hi
: Uint
:= No_Uint
;
12290 LoR
: Ureal
:= No_Ureal
;
12291 HiR
: Ureal
:= No_Ureal
;
12292 LoSet
: Boolean := False;
12293 HiSet
: Boolean := False;
12296 Ancest
: Entity_Id
;
12297 R_Typ
: constant Entity_Id
:= Root_Type
(T
);
12300 -- If bad type, return 0
12302 if T
= Any_Type
then
12305 -- For generic types, just return zero. There cannot be any legitimate
12306 -- need to know such a size, but this routine may be called with a
12307 -- generic type as part of normal processing.
12309 elsif Is_Generic_Type
(R_Typ
) or else R_Typ
= Any_Type
then
12312 -- Access types (cannot have size smaller than System.Address)
12314 elsif Is_Access_Type
(T
) then
12315 return System_Address_Size
;
12317 -- Floating-point types
12319 elsif Is_Floating_Point_Type
(T
) then
12320 return UI_To_Int
(Esize
(R_Typ
));
12324 elsif Is_Discrete_Type
(T
) then
12326 -- The following loop is looking for the nearest compile time known
12327 -- bounds following the ancestor subtype chain. The idea is to find
12328 -- the most restrictive known bounds information.
12332 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
12337 if Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
)) then
12338 Lo
:= Expr_Rep_Value
(Type_Low_Bound
(Ancest
));
12345 if Compile_Time_Known_Value
(Type_High_Bound
(Ancest
)) then
12346 Hi
:= Expr_Rep_Value
(Type_High_Bound
(Ancest
));
12352 Ancest
:= Ancestor_Subtype
(Ancest
);
12354 if No
(Ancest
) then
12355 Ancest
:= Base_Type
(T
);
12357 if Is_Generic_Type
(Ancest
) then
12363 -- Fixed-point types. We can't simply use Expr_Value to get the
12364 -- Corresponding_Integer_Value values of the bounds, since these do not
12365 -- get set till the type is frozen, and this routine can be called
12366 -- before the type is frozen. Similarly the test for bounds being static
12367 -- needs to include the case where we have unanalyzed real literals for
12368 -- the same reason.
12370 elsif Is_Fixed_Point_Type
(T
) then
12372 -- The following loop is looking for the nearest compile time known
12373 -- bounds following the ancestor subtype chain. The idea is to find
12374 -- the most restrictive known bounds information.
12378 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
12382 -- Note: In the following two tests for LoSet and HiSet, it may
12383 -- seem redundant to test for N_Real_Literal here since normally
12384 -- one would assume that the test for the value being known at
12385 -- compile time includes this case. However, there is a glitch.
12386 -- If the real literal comes from folding a non-static expression,
12387 -- then we don't consider any non- static expression to be known
12388 -- at compile time if we are in configurable run time mode (needed
12389 -- in some cases to give a clearer definition of what is and what
12390 -- is not accepted). So the test is indeed needed. Without it, we
12391 -- would set neither Lo_Set nor Hi_Set and get an infinite loop.
12394 if Nkind
(Type_Low_Bound
(Ancest
)) = N_Real_Literal
12395 or else Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
))
12397 LoR
:= Expr_Value_R
(Type_Low_Bound
(Ancest
));
12404 if Nkind
(Type_High_Bound
(Ancest
)) = N_Real_Literal
12405 or else Compile_Time_Known_Value
(Type_High_Bound
(Ancest
))
12407 HiR
:= Expr_Value_R
(Type_High_Bound
(Ancest
));
12413 Ancest
:= Ancestor_Subtype
(Ancest
);
12415 if No
(Ancest
) then
12416 Ancest
:= Base_Type
(T
);
12418 if Is_Generic_Type
(Ancest
) then
12424 Lo
:= UR_To_Uint
(LoR
/ Small_Value
(T
));
12425 Hi
:= UR_To_Uint
(HiR
/ Small_Value
(T
));
12427 -- No other types allowed
12430 raise Program_Error
;
12433 -- Fall through with Hi and Lo set. Deal with biased case
12436 and then not Is_Fixed_Point_Type
(T
)
12437 and then not (Is_Enumeration_Type
(T
)
12438 and then Has_Non_Standard_Rep
(T
)))
12439 or else Has_Biased_Representation
(T
)
12445 -- Null range case, size is always zero. We only do this in the discrete
12446 -- type case, since that's the odd case that came up. Probably we should
12447 -- also do this in the fixed-point case, but doing so causes peculiar
12448 -- gigi failures, and it is not worth worrying about this incredibly
12449 -- marginal case (explicit null-range fixed-point type declarations)???
12451 if Lo
> Hi
and then Is_Discrete_Type
(T
) then
12454 -- Signed case. Note that we consider types like range 1 .. -1 to be
12455 -- signed for the purpose of computing the size, since the bounds have
12456 -- to be accommodated in the base type.
12458 elsif Lo
< 0 or else Hi
< 0 then
12462 -- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1))
12463 -- Note that we accommodate the case where the bounds cross. This
12464 -- can happen either because of the way the bounds are declared
12465 -- or because of the algorithm in Freeze_Fixed_Point_Type.
12479 -- If both bounds are positive, make sure that both are represen-
12480 -- table in the case where the bounds are crossed. This can happen
12481 -- either because of the way the bounds are declared, or because of
12482 -- the algorithm in Freeze_Fixed_Point_Type.
12488 -- S = size, (can accommodate 0 .. (2**size - 1))
12491 while Hi
>= Uint_2
** S
loop
12499 ---------------------------
12500 -- New_Stream_Subprogram --
12501 ---------------------------
12503 procedure New_Stream_Subprogram
12507 Nam
: TSS_Name_Type
)
12509 Loc
: constant Source_Ptr
:= Sloc
(N
);
12510 Sname
: constant Name_Id
:= Make_TSS_Name
(Base_Type
(Ent
), Nam
);
12511 Subp_Id
: Entity_Id
;
12512 Subp_Decl
: Node_Id
;
12516 Defer_Declaration
: constant Boolean :=
12517 Is_Tagged_Type
(Ent
) or else Is_Private_Type
(Ent
);
12518 -- For a tagged type, there is a declaration for each stream attribute
12519 -- at the freeze point, and we must generate only a completion of this
12520 -- declaration. We do the same for private types, because the full view
12521 -- might be tagged. Otherwise we generate a declaration at the point of
12522 -- the attribute definition clause.
12524 function Build_Spec
return Node_Id
;
12525 -- Used for declaration and renaming declaration, so that this is
12526 -- treated as a renaming_as_body.
12532 function Build_Spec
return Node_Id
is
12533 Out_P
: constant Boolean := (Nam
= TSS_Stream_Read
);
12536 T_Ref
: constant Node_Id
:= New_Occurrence_Of
(Etyp
, Loc
);
12539 Subp_Id
:= Make_Defining_Identifier
(Loc
, Sname
);
12541 -- S : access Root_Stream_Type'Class
12543 Formals
:= New_List
(
12544 Make_Parameter_Specification
(Loc
,
12545 Defining_Identifier
=>
12546 Make_Defining_Identifier
(Loc
, Name_S
),
12548 Make_Access_Definition
(Loc
,
12550 New_Occurrence_Of
(
12551 Designated_Type
(Etype
(F
)), Loc
))));
12553 if Nam
= TSS_Stream_Input
then
12555 Make_Function_Specification
(Loc
,
12556 Defining_Unit_Name
=> Subp_Id
,
12557 Parameter_Specifications
=> Formals
,
12558 Result_Definition
=> T_Ref
);
12562 Append_To
(Formals
,
12563 Make_Parameter_Specification
(Loc
,
12564 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_V
),
12565 Out_Present
=> Out_P
,
12566 Parameter_Type
=> T_Ref
));
12569 Make_Procedure_Specification
(Loc
,
12570 Defining_Unit_Name
=> Subp_Id
,
12571 Parameter_Specifications
=> Formals
);
12577 -- Start of processing for New_Stream_Subprogram
12580 F
:= First_Formal
(Subp
);
12582 if Ekind
(Subp
) = E_Procedure
then
12583 Etyp
:= Etype
(Next_Formal
(F
));
12585 Etyp
:= Etype
(Subp
);
12588 -- Prepare subprogram declaration and insert it as an action on the
12589 -- clause node. The visibility for this entity is used to test for
12590 -- visibility of the attribute definition clause (in the sense of
12591 -- 8.3(23) as amended by AI-195).
12593 if not Defer_Declaration
then
12595 Make_Subprogram_Declaration
(Loc
,
12596 Specification
=> Build_Spec
);
12598 -- For a tagged type, there is always a visible declaration for each
12599 -- stream TSS (it is a predefined primitive operation), and the
12600 -- completion of this declaration occurs at the freeze point, which is
12601 -- not always visible at places where the attribute definition clause is
12602 -- visible. So, we create a dummy entity here for the purpose of
12603 -- tracking the visibility of the attribute definition clause itself.
12607 Make_Defining_Identifier
(Loc
, New_External_Name
(Sname
, 'V'));
12609 Make_Object_Declaration
(Loc
,
12610 Defining_Identifier
=> Subp_Id
,
12611 Object_Definition
=> New_Occurrence_Of
(Standard_Boolean
, Loc
));
12614 Insert_Action
(N
, Subp_Decl
);
12615 Set_Entity
(N
, Subp_Id
);
12618 Make_Subprogram_Renaming_Declaration
(Loc
,
12619 Specification
=> Build_Spec
,
12620 Name
=> New_Occurrence_Of
(Subp
, Loc
));
12622 if Defer_Declaration
then
12623 Set_TSS
(Base_Type
(Ent
), Subp_Id
);
12625 Insert_Action
(N
, Subp_Decl
);
12626 Copy_TSS
(Subp_Id
, Base_Type
(Ent
));
12628 end New_Stream_Subprogram
;
12630 ------------------------------------------
12631 -- Push_Scope_And_Install_Discriminants --
12632 ------------------------------------------
12634 procedure Push_Scope_And_Install_Discriminants
(E
: Entity_Id
) is
12636 if Has_Discriminants
(E
) then
12639 -- Make discriminants visible for type declarations and protected
12640 -- type declarations, not for subtype declarations (RM 13.1.1 (12/3))
12642 if Nkind
(Parent
(E
)) /= N_Subtype_Declaration
then
12643 Install_Discriminants
(E
);
12646 end Push_Scope_And_Install_Discriminants
;
12648 ------------------------
12649 -- Rep_Item_Too_Early --
12650 ------------------------
12652 function Rep_Item_Too_Early
(T
: Entity_Id
; N
: Node_Id
) return Boolean is
12654 -- Cannot apply non-operational rep items to generic types
12656 if Is_Operational_Item
(N
) then
12660 and then Is_Generic_Type
(Root_Type
(T
))
12661 and then (Nkind
(N
) /= N_Pragma
12662 or else Get_Pragma_Id
(N
) /= Pragma_Convention
)
12664 Error_Msg_N
("representation item not allowed for generic type", N
);
12668 -- Otherwise check for incomplete type
12670 if Is_Incomplete_Or_Private_Type
(T
)
12671 and then No
(Underlying_Type
(T
))
12673 (Nkind
(N
) /= N_Pragma
12674 or else Get_Pragma_Id
(N
) /= Pragma_Import
)
12677 ("representation item must be after full type declaration", N
);
12680 -- If the type has incomplete components, a representation clause is
12681 -- illegal but stream attributes and Convention pragmas are correct.
12683 elsif Has_Private_Component
(T
) then
12684 if Nkind
(N
) = N_Pragma
then
12689 ("representation item must appear after type is fully defined",
12696 end Rep_Item_Too_Early
;
12698 -----------------------
12699 -- Rep_Item_Too_Late --
12700 -----------------------
12702 function Rep_Item_Too_Late
12705 FOnly
: Boolean := False) return Boolean
12708 Parent_Type
: Entity_Id
;
12710 procedure No_Type_Rep_Item
;
12711 -- Output message indicating that no type-related aspects can be
12712 -- specified due to some property of the parent type.
12714 procedure Too_Late
;
12715 -- Output message for an aspect being specified too late
12717 -- Note that neither of the above errors is considered a serious one,
12718 -- since the effect is simply that we ignore the representation clause
12720 -- Is this really true? In any case if we make this change we must
12721 -- document the requirement in the spec of Rep_Item_Too_Late that
12722 -- if True is returned, then the rep item must be completely ignored???
12724 ----------------------
12725 -- No_Type_Rep_Item --
12726 ----------------------
12728 procedure No_Type_Rep_Item
is
12730 Error_Msg_N
("|type-related representation item not permitted!", N
);
12731 end No_Type_Rep_Item
;
12737 procedure Too_Late
is
12739 -- Other compilers seem more relaxed about rep items appearing too
12740 -- late. Since analysis tools typically don't care about rep items
12741 -- anyway, no reason to be too strict about this.
12743 if not Relaxed_RM_Semantics
then
12744 Error_Msg_N
("|representation item appears too late!", N
);
12748 -- Start of processing for Rep_Item_Too_Late
12751 -- First make sure entity is not frozen (RM 13.1(9))
12755 -- Exclude imported types, which may be frozen if they appear in a
12756 -- representation clause for a local type.
12758 and then not From_Limited_With
(T
)
12760 -- Exclude generated entities (not coming from source). The common
12761 -- case is when we generate a renaming which prematurely freezes the
12762 -- renamed internal entity, but we still want to be able to set copies
12763 -- of attribute values such as Size/Alignment.
12765 and then Comes_From_Source
(T
)
12767 -- A self-referential aspect is illegal if it forces freezing the
12768 -- entity before the corresponding pragma has been analyzed.
12770 if Nkind_In
(N
, N_Attribute_Definition_Clause
, N_Pragma
)
12771 and then From_Aspect_Specification
(N
)
12774 ("aspect specification causes premature freezing of&", T
, N
);
12775 Set_Has_Delayed_Freeze
(T
, False);
12780 S
:= First_Subtype
(T
);
12782 if Present
(Freeze_Node
(S
)) then
12783 if not Relaxed_RM_Semantics
then
12785 ("??no more representation items for }", Freeze_Node
(S
), S
);
12791 -- Check for case of untagged derived type whose parent either has
12792 -- primitive operations, or is a by reference type (RM 13.1(10)). In
12793 -- this case we do not output a Too_Late message, since there is no
12794 -- earlier point where the rep item could be placed to make it legal.
12798 and then Is_Derived_Type
(T
)
12799 and then not Is_Tagged_Type
(T
)
12801 Parent_Type
:= Etype
(Base_Type
(T
));
12803 if Has_Primitive_Operations
(Parent_Type
) then
12806 if not Relaxed_RM_Semantics
then
12808 ("\parent type & has primitive operations!", N
, Parent_Type
);
12813 elsif Is_By_Reference_Type
(Parent_Type
) then
12816 if not Relaxed_RM_Semantics
then
12818 ("\parent type & is a by reference type!", N
, Parent_Type
);
12825 -- No error, but one more warning to consider. The RM (surprisingly)
12826 -- allows this pattern:
12829 -- primitive operations for S
12830 -- type R is new S;
12831 -- rep clause for S
12833 -- Meaning that calls on the primitive operations of S for values of
12834 -- type R may require possibly expensive implicit conversion operations.
12835 -- This is not an error, but is worth a warning.
12837 if not Relaxed_RM_Semantics
and then Is_Type
(T
) then
12839 DTL
: constant Entity_Id
:= Derived_Type_Link
(Base_Type
(T
));
12843 and then Has_Primitive_Operations
(Base_Type
(T
))
12845 -- For now, do not generate this warning for the case of aspect
12846 -- specification using Ada 2012 syntax, since we get wrong
12847 -- messages we do not understand. The whole business of derived
12848 -- types and rep items seems a bit confused when aspects are
12849 -- used, since the aspects are not evaluated till freeze time.
12851 and then not From_Aspect_Specification
(N
)
12853 Error_Msg_Sloc
:= Sloc
(DTL
);
12855 ("representation item for& appears after derived type "
12856 & "declaration#??", N
);
12858 ("\may result in implicit conversions for primitive "
12859 & "operations of&??", N
, T
);
12861 ("\to change representations when called with arguments "
12862 & "of type&??", N
, DTL
);
12867 -- No error, link item into head of chain of rep items for the entity,
12868 -- but avoid chaining if we have an overloadable entity, and the pragma
12869 -- is one that can apply to multiple overloaded entities.
12871 if Is_Overloadable
(T
) and then Nkind
(N
) = N_Pragma
then
12873 Pname
: constant Name_Id
:= Pragma_Name
(N
);
12875 if Nam_In
(Pname
, Name_Convention
, Name_Import
, Name_Export
,
12876 Name_External
, Name_Interface
)
12883 Record_Rep_Item
(T
, N
);
12885 end Rep_Item_Too_Late
;
12887 -------------------------------------
12888 -- Replace_Type_References_Generic --
12889 -------------------------------------
12891 procedure Replace_Type_References_Generic
(N
: Node_Id
; T
: Entity_Id
) is
12892 TName
: constant Name_Id
:= Chars
(T
);
12894 function Replace_Node
(N
: Node_Id
) return Traverse_Result
;
12895 -- Processes a single node in the traversal procedure below, checking
12896 -- if node N should be replaced, and if so, doing the replacement.
12898 procedure Replace_Type_Refs
is new Traverse_Proc
(Replace_Node
);
12899 -- This instantiation provides the body of Replace_Type_References
12905 function Replace_Node
(N
: Node_Id
) return Traverse_Result
is
12910 -- Case of identifier
12912 if Nkind
(N
) = N_Identifier
then
12914 -- If not the type name, check whether it is a reference to
12915 -- some other type, which must be frozen before the predicate
12916 -- function is analyzed, i.e. before the freeze node of the
12917 -- type to which the predicate applies.
12919 if Chars
(N
) /= TName
then
12920 if Present
(Current_Entity
(N
))
12921 and then Is_Type
(Current_Entity
(N
))
12923 Freeze_Before
(Freeze_Node
(T
), Current_Entity
(N
));
12928 -- Otherwise do the replacement and we are done with this node
12931 Replace_Type_Reference
(N
);
12935 -- Case of selected component (which is what a qualification
12936 -- looks like in the unanalyzed tree, which is what we have.
12938 elsif Nkind
(N
) = N_Selected_Component
then
12940 -- If selector name is not our type, keeping going (we might
12941 -- still have an occurrence of the type in the prefix).
12943 if Nkind
(Selector_Name
(N
)) /= N_Identifier
12944 or else Chars
(Selector_Name
(N
)) /= TName
12948 -- Selector name is our type, check qualification
12951 -- Loop through scopes and prefixes, doing comparison
12953 S
:= Current_Scope
;
12956 -- Continue if no more scopes or scope with no name
12958 if No
(S
) or else Nkind
(S
) not in N_Has_Chars
then
12962 -- Do replace if prefix is an identifier matching the
12963 -- scope that we are currently looking at.
12965 if Nkind
(P
) = N_Identifier
12966 and then Chars
(P
) = Chars
(S
)
12968 Replace_Type_Reference
(N
);
12972 -- Go check scope above us if prefix is itself of the
12973 -- form of a selected component, whose selector matches
12974 -- the scope we are currently looking at.
12976 if Nkind
(P
) = N_Selected_Component
12977 and then Nkind
(Selector_Name
(P
)) = N_Identifier
12978 and then Chars
(Selector_Name
(P
)) = Chars
(S
)
12983 -- For anything else, we don't have a match, so keep on
12984 -- going, there are still some weird cases where we may
12985 -- still have a replacement within the prefix.
12993 -- Continue for any other node kind
13001 Replace_Type_Refs
(N
);
13002 end Replace_Type_References_Generic
;
13004 --------------------------------
13005 -- Resolve_Aspect_Expressions --
13006 --------------------------------
13008 procedure Resolve_Aspect_Expressions
(E
: Entity_Id
) is
13013 function Resolve_Name
(N
: Node_Id
) return Traverse_Result
;
13014 -- Verify that all identifiers in the expression, with the exception
13015 -- of references to the current entity, denote visible entities. This
13016 -- is done only to detect visibility errors, as the expression will be
13017 -- properly analyzed/expanded during analysis of the predicate function
13018 -- body. We omit quantified expressions from this test, given that they
13019 -- introduce a local identifier that would require proper expansion to
13020 -- handle properly.
13026 function Resolve_Name
(N
: Node_Id
) return Traverse_Result
is
13028 if Nkind
(N
) = N_Selected_Component
then
13029 if Nkind
(Prefix
(N
)) = N_Identifier
13030 and then Chars
(Prefix
(N
)) /= Chars
(E
)
13032 Find_Selected_Component
(N
);
13037 elsif Nkind
(N
) = N_Identifier
and then Chars
(N
) /= Chars
(E
) then
13038 Find_Direct_Name
(N
);
13039 Set_Entity
(N
, Empty
);
13041 elsif Nkind
(N
) = N_Quantified_Expression
then
13048 procedure Resolve_Aspect_Expression
is new Traverse_Proc
(Resolve_Name
);
13050 -- Start of processing for Resolve_Aspect_Expressions
13053 ASN
:= First_Rep_Item
(E
);
13054 while Present
(ASN
) loop
13055 if Nkind
(ASN
) = N_Aspect_Specification
and then Entity
(ASN
) = E
then
13056 A_Id
:= Get_Aspect_Id
(ASN
);
13057 Expr
:= Expression
(ASN
);
13060 -- For now we only deal with aspects that do not generate
13061 -- subprograms, or that may mention current instances of
13062 -- types. These will require special handling (???TBD).
13064 when Aspect_Predicate |
13065 Aspect_Predicate_Failure |
13066 Aspect_Invariant
=>
13069 when Aspect_Static_Predicate |
13070 Aspect_Dynamic_Predicate
=>
13072 -- Build predicate function specification and preanalyze
13073 -- expression after type replacement.
13075 if No
(Predicate_Function
(E
)) then
13077 FDecl
: constant Node_Id
:=
13078 Build_Predicate_Function_Declaration
(E
);
13079 pragma Unreferenced
(FDecl
);
13081 Resolve_Aspect_Expression
(Expr
);
13085 when Pre_Post_Aspects
=>
13088 when Aspect_Iterable
=>
13089 if Nkind
(Expr
) = N_Aggregate
then
13094 Assoc
:= First
(Component_Associations
(Expr
));
13095 while Present
(Assoc
) loop
13096 Find_Direct_Name
(Expression
(Assoc
));
13103 if Present
(Expr
) then
13104 case Aspect_Argument
(A_Id
) is
13105 when Expression | Optional_Expression
=>
13106 Analyze_And_Resolve
(Expression
(ASN
));
13108 when Name | Optional_Name
=>
13109 if Nkind
(Expr
) = N_Identifier
then
13110 Find_Direct_Name
(Expr
);
13112 elsif Nkind
(Expr
) = N_Selected_Component
then
13113 Find_Selected_Component
(Expr
);
13123 ASN
:= Next_Rep_Item
(ASN
);
13125 end Resolve_Aspect_Expressions
;
13127 -------------------------
13128 -- Same_Representation --
13129 -------------------------
13131 function Same_Representation
(Typ1
, Typ2
: Entity_Id
) return Boolean is
13132 T1
: constant Entity_Id
:= Underlying_Type
(Typ1
);
13133 T2
: constant Entity_Id
:= Underlying_Type
(Typ2
);
13136 -- A quick check, if base types are the same, then we definitely have
13137 -- the same representation, because the subtype specific representation
13138 -- attributes (Size and Alignment) do not affect representation from
13139 -- the point of view of this test.
13141 if Base_Type
(T1
) = Base_Type
(T2
) then
13144 elsif Is_Private_Type
(Base_Type
(T2
))
13145 and then Base_Type
(T1
) = Full_View
(Base_Type
(T2
))
13150 -- Tagged types never have differing representations
13152 if Is_Tagged_Type
(T1
) then
13156 -- Representations are definitely different if conventions differ
13158 if Convention
(T1
) /= Convention
(T2
) then
13162 -- Representations are different if component alignments or scalar
13163 -- storage orders differ.
13165 if (Is_Record_Type
(T1
) or else Is_Array_Type
(T1
))
13167 (Is_Record_Type
(T2
) or else Is_Array_Type
(T2
))
13169 (Component_Alignment
(T1
) /= Component_Alignment
(T2
)
13170 or else Reverse_Storage_Order
(T1
) /= Reverse_Storage_Order
(T2
))
13175 -- For arrays, the only real issue is component size. If we know the
13176 -- component size for both arrays, and it is the same, then that's
13177 -- good enough to know we don't have a change of representation.
13179 if Is_Array_Type
(T1
) then
13180 if Known_Component_Size
(T1
)
13181 and then Known_Component_Size
(T2
)
13182 and then Component_Size
(T1
) = Component_Size
(T2
)
13188 -- Types definitely have same representation if neither has non-standard
13189 -- representation since default representations are always consistent.
13190 -- If only one has non-standard representation, and the other does not,
13191 -- then we consider that they do not have the same representation. They
13192 -- might, but there is no way of telling early enough.
13194 if Has_Non_Standard_Rep
(T1
) then
13195 if not Has_Non_Standard_Rep
(T2
) then
13199 return not Has_Non_Standard_Rep
(T2
);
13202 -- Here the two types both have non-standard representation, and we need
13203 -- to determine if they have the same non-standard representation.
13205 -- For arrays, we simply need to test if the component sizes are the
13206 -- same. Pragma Pack is reflected in modified component sizes, so this
13207 -- check also deals with pragma Pack.
13209 if Is_Array_Type
(T1
) then
13210 return Component_Size
(T1
) = Component_Size
(T2
);
13212 -- Tagged types always have the same representation, because it is not
13213 -- possible to specify different representations for common fields.
13215 elsif Is_Tagged_Type
(T1
) then
13218 -- Case of record types
13220 elsif Is_Record_Type
(T1
) then
13222 -- Packed status must conform
13224 if Is_Packed
(T1
) /= Is_Packed
(T2
) then
13227 -- Otherwise we must check components. Typ2 maybe a constrained
13228 -- subtype with fewer components, so we compare the components
13229 -- of the base types.
13232 Record_Case
: declare
13233 CD1
, CD2
: Entity_Id
;
13235 function Same_Rep
return Boolean;
13236 -- CD1 and CD2 are either components or discriminants. This
13237 -- function tests whether they have the same representation.
13243 function Same_Rep
return Boolean is
13245 if No
(Component_Clause
(CD1
)) then
13246 return No
(Component_Clause
(CD2
));
13248 -- Note: at this point, component clauses have been
13249 -- normalized to the default bit order, so that the
13250 -- comparison of Component_Bit_Offsets is meaningful.
13253 Present
(Component_Clause
(CD2
))
13255 Component_Bit_Offset
(CD1
) = Component_Bit_Offset
(CD2
)
13257 Esize
(CD1
) = Esize
(CD2
);
13261 -- Start of processing for Record_Case
13264 if Has_Discriminants
(T1
) then
13266 -- The number of discriminants may be different if the
13267 -- derived type has fewer (constrained by values). The
13268 -- invisible discriminants retain the representation of
13269 -- the original, so the discrepancy does not per se
13270 -- indicate a different representation.
13272 CD1
:= First_Discriminant
(T1
);
13273 CD2
:= First_Discriminant
(T2
);
13274 while Present
(CD1
) and then Present
(CD2
) loop
13275 if not Same_Rep
then
13278 Next_Discriminant
(CD1
);
13279 Next_Discriminant
(CD2
);
13284 CD1
:= First_Component
(Underlying_Type
(Base_Type
(T1
)));
13285 CD2
:= First_Component
(Underlying_Type
(Base_Type
(T2
)));
13286 while Present
(CD1
) loop
13287 if not Same_Rep
then
13290 Next_Component
(CD1
);
13291 Next_Component
(CD2
);
13299 -- For enumeration types, we must check each literal to see if the
13300 -- representation is the same. Note that we do not permit enumeration
13301 -- representation clauses for Character and Wide_Character, so these
13302 -- cases were already dealt with.
13304 elsif Is_Enumeration_Type
(T1
) then
13305 Enumeration_Case
: declare
13306 L1
, L2
: Entity_Id
;
13309 L1
:= First_Literal
(T1
);
13310 L2
:= First_Literal
(T2
);
13311 while Present
(L1
) loop
13312 if Enumeration_Rep
(L1
) /= Enumeration_Rep
(L2
) then
13321 end Enumeration_Case
;
13323 -- Any other types have the same representation for these purposes
13328 end Same_Representation
;
13330 --------------------------------
13331 -- Resolve_Iterable_Operation --
13332 --------------------------------
13334 procedure Resolve_Iterable_Operation
13336 Cursor
: Entity_Id
;
13345 if not Is_Overloaded
(N
) then
13346 if not Is_Entity_Name
(N
)
13347 or else Ekind
(Entity
(N
)) /= E_Function
13348 or else Scope
(Entity
(N
)) /= Scope
(Typ
)
13349 or else No
(First_Formal
(Entity
(N
)))
13350 or else Etype
(First_Formal
(Entity
(N
))) /= Typ
13352 Error_Msg_N
("iterable primitive must be local function name "
13353 & "whose first formal is an iterable type", N
);
13358 F1
:= First_Formal
(Ent
);
13359 if Nam
= Name_First
then
13361 -- First (Container) => Cursor
13363 if Etype
(Ent
) /= Cursor
then
13364 Error_Msg_N
("primitive for First must yield a curosr", N
);
13367 elsif Nam
= Name_Next
then
13369 -- Next (Container, Cursor) => Cursor
13371 F2
:= Next_Formal
(F1
);
13373 if Etype
(F2
) /= Cursor
13374 or else Etype
(Ent
) /= Cursor
13375 or else Present
(Next_Formal
(F2
))
13377 Error_Msg_N
("no match for Next iterable primitive", N
);
13380 elsif Nam
= Name_Has_Element
then
13382 -- Has_Element (Container, Cursor) => Boolean
13384 F2
:= Next_Formal
(F1
);
13385 if Etype
(F2
) /= Cursor
13386 or else Etype
(Ent
) /= Standard_Boolean
13387 or else Present
(Next_Formal
(F2
))
13389 Error_Msg_N
("no match for Has_Element iterable primitive", N
);
13392 elsif Nam
= Name_Element
then
13393 F2
:= Next_Formal
(F1
);
13396 or else Etype
(F2
) /= Cursor
13397 or else Present
(Next_Formal
(F2
))
13399 Error_Msg_N
("no match for Element iterable primitive", N
);
13404 raise Program_Error
;
13408 -- Overloaded case: find subprogram with proper signature.
13409 -- Caller will report error if no match is found.
13416 Get_First_Interp
(N
, I
, It
);
13417 while Present
(It
.Typ
) loop
13418 if Ekind
(It
.Nam
) = E_Function
13419 and then Scope
(It
.Nam
) = Scope
(Typ
)
13420 and then Etype
(First_Formal
(It
.Nam
)) = Typ
13422 F1
:= First_Formal
(It
.Nam
);
13424 if Nam
= Name_First
then
13425 if Etype
(It
.Nam
) = Cursor
13426 and then No
(Next_Formal
(F1
))
13428 Set_Entity
(N
, It
.Nam
);
13432 elsif Nam
= Name_Next
then
13433 F2
:= Next_Formal
(F1
);
13436 and then No
(Next_Formal
(F2
))
13437 and then Etype
(F2
) = Cursor
13438 and then Etype
(It
.Nam
) = Cursor
13440 Set_Entity
(N
, It
.Nam
);
13444 elsif Nam
= Name_Has_Element
then
13445 F2
:= Next_Formal
(F1
);
13448 and then No
(Next_Formal
(F2
))
13449 and then Etype
(F2
) = Cursor
13450 and then Etype
(It
.Nam
) = Standard_Boolean
13452 Set_Entity
(N
, It
.Nam
);
13453 F2
:= Next_Formal
(F1
);
13457 elsif Nam
= Name_Element
then
13458 F2
:= Next_Formal
(F1
);
13461 and then No
(Next_Formal
(F2
))
13462 and then Etype
(F2
) = Cursor
13464 Set_Entity
(N
, It
.Nam
);
13470 Get_Next_Interp
(I
, It
);
13474 end Resolve_Iterable_Operation
;
13480 procedure Set_Biased
13484 Biased
: Boolean := True)
13488 Set_Has_Biased_Representation
(E
);
13490 if Warn_On_Biased_Representation
then
13492 ("?B?" & Msg
& " forces biased representation for&", N
, E
);
13497 --------------------
13498 -- Set_Enum_Esize --
13499 --------------------
13501 procedure Set_Enum_Esize
(T
: Entity_Id
) is
13507 Init_Alignment
(T
);
13509 -- Find the minimum standard size (8,16,32,64) that fits
13511 Lo
:= Enumeration_Rep
(Entity
(Type_Low_Bound
(T
)));
13512 Hi
:= Enumeration_Rep
(Entity
(Type_High_Bound
(T
)));
13515 if Lo
>= -Uint_2
**07 and then Hi
< Uint_2
**07 then
13516 Sz
:= Standard_Character_Size
; -- May be > 8 on some targets
13518 elsif Lo
>= -Uint_2
**15 and then Hi
< Uint_2
**15 then
13521 elsif Lo
>= -Uint_2
**31 and then Hi
< Uint_2
**31 then
13524 else pragma Assert
(Lo
>= -Uint_2
**63 and then Hi
< Uint_2
**63);
13529 if Hi
< Uint_2
**08 then
13530 Sz
:= Standard_Character_Size
; -- May be > 8 on some targets
13532 elsif Hi
< Uint_2
**16 then
13535 elsif Hi
< Uint_2
**32 then
13538 else pragma Assert
(Hi
< Uint_2
**63);
13543 -- That minimum is the proper size unless we have a foreign convention
13544 -- and the size required is 32 or less, in which case we bump the size
13545 -- up to 32. This is required for C and C++ and seems reasonable for
13546 -- all other foreign conventions.
13548 if Has_Foreign_Convention
(T
)
13549 and then Esize
(T
) < Standard_Integer_Size
13551 -- Don't do this if Short_Enums on target
13553 and then not Target_Short_Enums
13555 Init_Esize
(T
, Standard_Integer_Size
);
13557 Init_Esize
(T
, Sz
);
13559 end Set_Enum_Esize
;
13561 -----------------------------
13562 -- Uninstall_Discriminants --
13563 -----------------------------
13565 procedure Uninstall_Discriminants
(E
: Entity_Id
) is
13571 -- Discriminants have been made visible for type declarations and
13572 -- protected type declarations, not for subtype declarations.
13574 if Nkind
(Parent
(E
)) /= N_Subtype_Declaration
then
13575 Disc
:= First_Discriminant
(E
);
13576 while Present
(Disc
) loop
13577 if Disc
/= Current_Entity
(Disc
) then
13578 Prev
:= Current_Entity
(Disc
);
13579 while Present
(Prev
)
13580 and then Present
(Homonym
(Prev
))
13581 and then Homonym
(Prev
) /= Disc
13583 Prev
:= Homonym
(Prev
);
13589 Set_Is_Immediately_Visible
(Disc
, False);
13591 Outer
:= Homonym
(Disc
);
13592 while Present
(Outer
) and then Scope
(Outer
) = E
loop
13593 Outer
:= Homonym
(Outer
);
13596 -- Reset homonym link of other entities, but do not modify link
13597 -- between entities in current scope, so that the back end can
13598 -- have a proper count of local overloadings.
13601 Set_Name_Entity_Id
(Chars
(Disc
), Outer
);
13603 elsif Scope
(Prev
) /= Scope
(Disc
) then
13604 Set_Homonym
(Prev
, Outer
);
13607 Next_Discriminant
(Disc
);
13610 end Uninstall_Discriminants
;
13612 -------------------------------------------
13613 -- Uninstall_Discriminants_And_Pop_Scope --
13614 -------------------------------------------
13616 procedure Uninstall_Discriminants_And_Pop_Scope
(E
: Entity_Id
) is
13618 if Has_Discriminants
(E
) then
13619 Uninstall_Discriminants
(E
);
13622 end Uninstall_Discriminants_And_Pop_Scope
;
13624 ------------------------------
13625 -- Validate_Address_Clauses --
13626 ------------------------------
13628 procedure Validate_Address_Clauses
is
13630 for J
in Address_Clause_Checks
.First
.. Address_Clause_Checks
.Last
loop
13632 ACCR
: Address_Clause_Check_Record
13633 renames Address_Clause_Checks
.Table
(J
);
13637 X_Alignment
: Uint
;
13638 Y_Alignment
: Uint
;
13644 -- Skip processing of this entry if warning already posted
13646 if not Address_Warning_Posted
(ACCR
.N
) then
13647 Expr
:= Original_Node
(Expression
(ACCR
.N
));
13651 X_Alignment
:= Alignment
(ACCR
.X
);
13652 Y_Alignment
:= Alignment
(ACCR
.Y
);
13654 -- Similarly obtain sizes
13656 X_Size
:= Esize
(ACCR
.X
);
13657 Y_Size
:= Esize
(ACCR
.Y
);
13659 -- Check for large object overlaying smaller one
13662 and then X_Size
> Uint_0
13663 and then X_Size
> Y_Size
13665 Error_Msg_NE
("??& overlays smaller object", ACCR
.N
, ACCR
.X
);
13667 ("\??program execution may be erroneous", ACCR
.N
);
13669 Error_Msg_Uint_1
:= X_Size
;
13670 Error_Msg_NE
("\??size of & is ^", ACCR
.N
, ACCR
.X
);
13672 Error_Msg_Uint_1
:= Y_Size
;
13673 Error_Msg_NE
("\??size of & is ^", ACCR
.N
, ACCR
.Y
);
13675 -- Check for inadequate alignment, both of the base object
13676 -- and of the offset, if any. We only do this check if the
13677 -- run-time Alignment_Check is active. No point in warning
13678 -- if this check has been suppressed (or is suppressed by
13679 -- default in the non-strict alignment machine case).
13681 -- Note: we do not check the alignment if we gave a size
13682 -- warning, since it would likely be redundant.
13684 elsif not Alignment_Checks_Suppressed
(ACCR
.Y
)
13685 and then Y_Alignment
/= Uint_0
13687 (Y_Alignment
< X_Alignment
13690 and then Nkind
(Expr
) = N_Attribute_Reference
13691 and then Attribute_Name
(Expr
) = Name_Address
13692 and then Has_Compatible_Alignment
13693 (ACCR
.X
, Prefix
(Expr
), True) /=
13697 ("??specified address for& may be inconsistent with "
13698 & "alignment", ACCR
.N
, ACCR
.X
);
13700 ("\??program execution may be erroneous (RM 13.3(27))",
13703 Error_Msg_Uint_1
:= X_Alignment
;
13704 Error_Msg_NE
("\??alignment of & is ^", ACCR
.N
, ACCR
.X
);
13706 Error_Msg_Uint_1
:= Y_Alignment
;
13707 Error_Msg_NE
("\??alignment of & is ^", ACCR
.N
, ACCR
.Y
);
13709 if Y_Alignment
>= X_Alignment
then
13711 ("\??but offset is not multiple of alignment", ACCR
.N
);
13717 end Validate_Address_Clauses
;
13719 ---------------------------
13720 -- Validate_Independence --
13721 ---------------------------
13723 procedure Validate_Independence
is
13724 SU
: constant Uint
:= UI_From_Int
(System_Storage_Unit
);
13732 procedure Check_Array_Type
(Atyp
: Entity_Id
);
13733 -- Checks if the array type Atyp has independent components, and
13734 -- if not, outputs an appropriate set of error messages.
13736 procedure No_Independence
;
13737 -- Output message that independence cannot be guaranteed
13739 function OK_Component
(C
: Entity_Id
) return Boolean;
13740 -- Checks one component to see if it is independently accessible, and
13741 -- if so yields True, otherwise yields False if independent access
13742 -- cannot be guaranteed. This is a conservative routine, it only
13743 -- returns True if it knows for sure, it returns False if it knows
13744 -- there is a problem, or it cannot be sure there is no problem.
13746 procedure Reason_Bad_Component
(C
: Entity_Id
);
13747 -- Outputs continuation message if a reason can be determined for
13748 -- the component C being bad.
13750 ----------------------
13751 -- Check_Array_Type --
13752 ----------------------
13754 procedure Check_Array_Type
(Atyp
: Entity_Id
) is
13755 Ctyp
: constant Entity_Id
:= Component_Type
(Atyp
);
13758 -- OK if no alignment clause, no pack, and no component size
13760 if not Has_Component_Size_Clause
(Atyp
)
13761 and then not Has_Alignment_Clause
(Atyp
)
13762 and then not Is_Packed
(Atyp
)
13767 -- Case of component size is greater than or equal to 64 and the
13768 -- alignment of the array is at least as large as the alignment
13769 -- of the component. We are definitely OK in this situation.
13771 if Known_Component_Size
(Atyp
)
13772 and then Component_Size
(Atyp
) >= 64
13773 and then Known_Alignment
(Atyp
)
13774 and then Known_Alignment
(Ctyp
)
13775 and then Alignment
(Atyp
) >= Alignment
(Ctyp
)
13780 -- Check actual component size
13782 if not Known_Component_Size
(Atyp
)
13783 or else not (Addressable
(Component_Size
(Atyp
))
13784 and then Component_Size
(Atyp
) < 64)
13785 or else Component_Size
(Atyp
) mod Esize
(Ctyp
) /= 0
13789 -- Bad component size, check reason
13791 if Has_Component_Size_Clause
(Atyp
) then
13792 P
:= Get_Attribute_Definition_Clause
13793 (Atyp
, Attribute_Component_Size
);
13795 if Present
(P
) then
13796 Error_Msg_Sloc
:= Sloc
(P
);
13797 Error_Msg_N
("\because of Component_Size clause#", N
);
13802 if Is_Packed
(Atyp
) then
13803 P
:= Get_Rep_Pragma
(Atyp
, Name_Pack
);
13805 if Present
(P
) then
13806 Error_Msg_Sloc
:= Sloc
(P
);
13807 Error_Msg_N
("\because of pragma Pack#", N
);
13812 -- No reason found, just return
13817 -- Array type is OK independence-wise
13820 end Check_Array_Type
;
13822 ---------------------
13823 -- No_Independence --
13824 ---------------------
13826 procedure No_Independence
is
13828 if Pragma_Name
(N
) = Name_Independent
then
13829 Error_Msg_NE
("independence cannot be guaranteed for&", N
, E
);
13832 ("independent components cannot be guaranteed for&", N
, E
);
13834 end No_Independence
;
13840 function OK_Component
(C
: Entity_Id
) return Boolean is
13841 Rec
: constant Entity_Id
:= Scope
(C
);
13842 Ctyp
: constant Entity_Id
:= Etype
(C
);
13845 -- OK if no component clause, no Pack, and no alignment clause
13847 if No
(Component_Clause
(C
))
13848 and then not Is_Packed
(Rec
)
13849 and then not Has_Alignment_Clause
(Rec
)
13854 -- Here we look at the actual component layout. A component is
13855 -- addressable if its size is a multiple of the Esize of the
13856 -- component type, and its starting position in the record has
13857 -- appropriate alignment, and the record itself has appropriate
13858 -- alignment to guarantee the component alignment.
13860 -- Make sure sizes are static, always assume the worst for any
13861 -- cases where we cannot check static values.
13863 if not (Known_Static_Esize
(C
)
13865 Known_Static_Esize
(Ctyp
))
13870 -- Size of component must be addressable or greater than 64 bits
13871 -- and a multiple of bytes.
13873 if not Addressable
(Esize
(C
)) and then Esize
(C
) < Uint_64
then
13877 -- Check size is proper multiple
13879 if Esize
(C
) mod Esize
(Ctyp
) /= 0 then
13883 -- Check alignment of component is OK
13885 if not Known_Component_Bit_Offset
(C
)
13886 or else Component_Bit_Offset
(C
) < Uint_0
13887 or else Component_Bit_Offset
(C
) mod Esize
(Ctyp
) /= 0
13892 -- Check alignment of record type is OK
13894 if not Known_Alignment
(Rec
)
13895 or else (Alignment
(Rec
) * SU
) mod Esize
(Ctyp
) /= 0
13900 -- All tests passed, component is addressable
13905 --------------------------
13906 -- Reason_Bad_Component --
13907 --------------------------
13909 procedure Reason_Bad_Component
(C
: Entity_Id
) is
13910 Rec
: constant Entity_Id
:= Scope
(C
);
13911 Ctyp
: constant Entity_Id
:= Etype
(C
);
13914 -- If component clause present assume that's the problem
13916 if Present
(Component_Clause
(C
)) then
13917 Error_Msg_Sloc
:= Sloc
(Component_Clause
(C
));
13918 Error_Msg_N
("\because of Component_Clause#", N
);
13922 -- If pragma Pack clause present, assume that's the problem
13924 if Is_Packed
(Rec
) then
13925 P
:= Get_Rep_Pragma
(Rec
, Name_Pack
);
13927 if Present
(P
) then
13928 Error_Msg_Sloc
:= Sloc
(P
);
13929 Error_Msg_N
("\because of pragma Pack#", N
);
13934 -- See if record has bad alignment clause
13936 if Has_Alignment_Clause
(Rec
)
13937 and then Known_Alignment
(Rec
)
13938 and then (Alignment
(Rec
) * SU
) mod Esize
(Ctyp
) /= 0
13940 P
:= Get_Attribute_Definition_Clause
(Rec
, Attribute_Alignment
);
13942 if Present
(P
) then
13943 Error_Msg_Sloc
:= Sloc
(P
);
13944 Error_Msg_N
("\because of Alignment clause#", N
);
13948 -- Couldn't find a reason, so return without a message
13951 end Reason_Bad_Component
;
13953 -- Start of processing for Validate_Independence
13956 for J
in Independence_Checks
.First
.. Independence_Checks
.Last
loop
13957 N
:= Independence_Checks
.Table
(J
).N
;
13958 E
:= Independence_Checks
.Table
(J
).E
;
13959 IC
:= Pragma_Name
(N
) = Name_Independent_Components
;
13961 -- Deal with component case
13963 if Ekind
(E
) = E_Discriminant
or else Ekind
(E
) = E_Component
then
13964 if not OK_Component
(E
) then
13966 Reason_Bad_Component
(E
);
13971 -- Deal with record with Independent_Components
13973 if IC
and then Is_Record_Type
(E
) then
13974 Comp
:= First_Component_Or_Discriminant
(E
);
13975 while Present
(Comp
) loop
13976 if not OK_Component
(Comp
) then
13978 Reason_Bad_Component
(Comp
);
13982 Next_Component_Or_Discriminant
(Comp
);
13986 -- Deal with address clause case
13988 if Is_Object
(E
) then
13989 Addr
:= Address_Clause
(E
);
13991 if Present
(Addr
) then
13993 Error_Msg_Sloc
:= Sloc
(Addr
);
13994 Error_Msg_N
("\because of Address clause#", N
);
13999 -- Deal with independent components for array type
14001 if IC
and then Is_Array_Type
(E
) then
14002 Check_Array_Type
(E
);
14005 -- Deal with independent components for array object
14007 if IC
and then Is_Object
(E
) and then Is_Array_Type
(Etype
(E
)) then
14008 Check_Array_Type
(Etype
(E
));
14013 end Validate_Independence
;
14015 ------------------------------
14016 -- Validate_Iterable_Aspect --
14017 ------------------------------
14019 procedure Validate_Iterable_Aspect
(Typ
: Entity_Id
; ASN
: Node_Id
) is
14024 Cursor
: constant Entity_Id
:= Get_Cursor_Type
(ASN
, Typ
);
14026 First_Id
: Entity_Id
;
14027 Next_Id
: Entity_Id
;
14028 Has_Element_Id
: Entity_Id
;
14029 Element_Id
: Entity_Id
;
14032 -- If previous error aspect is unusable
14034 if Cursor
= Any_Type
then
14040 Has_Element_Id
:= Empty
;
14041 Element_Id
:= Empty
;
14043 -- Each expression must resolve to a function with the proper signature
14045 Assoc
:= First
(Component_Associations
(Expression
(ASN
)));
14046 while Present
(Assoc
) loop
14047 Expr
:= Expression
(Assoc
);
14050 Prim
:= First
(Choices
(Assoc
));
14052 if Nkind
(Prim
) /= N_Identifier
or else Present
(Next
(Prim
)) then
14053 Error_Msg_N
("illegal name in association", Prim
);
14055 elsif Chars
(Prim
) = Name_First
then
14056 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_First
);
14057 First_Id
:= Entity
(Expr
);
14059 elsif Chars
(Prim
) = Name_Next
then
14060 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_Next
);
14061 Next_Id
:= Entity
(Expr
);
14063 elsif Chars
(Prim
) = Name_Has_Element
then
14064 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_Has_Element
);
14065 Has_Element_Id
:= Entity
(Expr
);
14067 elsif Chars
(Prim
) = Name_Element
then
14068 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_Element
);
14069 Element_Id
:= Entity
(Expr
);
14072 Error_Msg_N
("invalid name for iterable function", Prim
);
14078 if No
(First_Id
) then
14079 Error_Msg_N
("match for First primitive not found", ASN
);
14081 elsif No
(Next_Id
) then
14082 Error_Msg_N
("match for Next primitive not found", ASN
);
14084 elsif No
(Has_Element_Id
) then
14085 Error_Msg_N
("match for Has_Element primitive not found", ASN
);
14087 elsif No
(Element_Id
) then
14090 end Validate_Iterable_Aspect
;
14092 -----------------------------------
14093 -- Validate_Unchecked_Conversion --
14094 -----------------------------------
14096 procedure Validate_Unchecked_Conversion
14098 Act_Unit
: Entity_Id
)
14100 Source
: Entity_Id
;
14101 Target
: Entity_Id
;
14105 -- Obtain source and target types. Note that we call Ancestor_Subtype
14106 -- here because the processing for generic instantiation always makes
14107 -- subtypes, and we want the original frozen actual types.
14109 -- If we are dealing with private types, then do the check on their
14110 -- fully declared counterparts if the full declarations have been
14111 -- encountered (they don't have to be visible, but they must exist).
14113 Source
:= Ancestor_Subtype
(Etype
(First_Formal
(Act_Unit
)));
14115 if Is_Private_Type
(Source
)
14116 and then Present
(Underlying_Type
(Source
))
14118 Source
:= Underlying_Type
(Source
);
14121 Target
:= Ancestor_Subtype
(Etype
(Act_Unit
));
14123 -- If either type is generic, the instantiation happens within a generic
14124 -- unit, and there is nothing to check. The proper check will happen
14125 -- when the enclosing generic is instantiated.
14127 if Is_Generic_Type
(Source
) or else Is_Generic_Type
(Target
) then
14131 if Is_Private_Type
(Target
)
14132 and then Present
(Underlying_Type
(Target
))
14134 Target
:= Underlying_Type
(Target
);
14137 -- Source may be unconstrained array, but not target, except in relaxed
14140 if Is_Array_Type
(Target
)
14141 and then not Is_Constrained
(Target
)
14142 and then not Relaxed_RM_Semantics
14145 ("unchecked conversion to unconstrained array not allowed", N
);
14149 -- Warn if conversion between two different convention pointers
14151 if Is_Access_Type
(Target
)
14152 and then Is_Access_Type
(Source
)
14153 and then Convention
(Target
) /= Convention
(Source
)
14154 and then Warn_On_Unchecked_Conversion
14156 -- Give warnings for subprogram pointers only on most targets
14158 if Is_Access_Subprogram_Type
(Target
)
14159 or else Is_Access_Subprogram_Type
(Source
)
14162 ("?z?conversion between pointers with different conventions!",
14167 -- Warn if one of the operands is Ada.Calendar.Time. Do not emit a
14168 -- warning when compiling GNAT-related sources.
14170 if Warn_On_Unchecked_Conversion
14171 and then not In_Predefined_Unit
(N
)
14172 and then RTU_Loaded
(Ada_Calendar
)
14173 and then (Chars
(Source
) = Name_Time
14175 Chars
(Target
) = Name_Time
)
14177 -- If Ada.Calendar is loaded and the name of one of the operands is
14178 -- Time, there is a good chance that this is Ada.Calendar.Time.
14181 Calendar_Time
: constant Entity_Id
:= Full_View
(RTE
(RO_CA_Time
));
14183 pragma Assert
(Present
(Calendar_Time
));
14185 if Source
= Calendar_Time
or else Target
= Calendar_Time
then
14187 ("?z?representation of 'Time values may change between "
14188 & "'G'N'A'T versions", N
);
14193 -- Make entry in unchecked conversion table for later processing by
14194 -- Validate_Unchecked_Conversions, which will check sizes and alignments
14195 -- (using values set by the back end where possible). This is only done
14196 -- if the appropriate warning is active.
14198 if Warn_On_Unchecked_Conversion
then
14199 Unchecked_Conversions
.Append
14200 (New_Val
=> UC_Entry
'(Eloc => Sloc (N),
14203 Act_Unit => Act_Unit));
14205 -- If both sizes are known statically now, then back-end annotation
14206 -- is not required to do a proper check but if either size is not
14207 -- known statically, then we need the annotation.
14209 if Known_Static_RM_Size (Source)
14211 Known_Static_RM_Size (Target)
14215 Back_Annotate_Rep_Info := True;
14219 -- If unchecked conversion to access type, and access type is declared
14220 -- in the same unit as the unchecked conversion, then set the flag
14221 -- No_Strict_Aliasing (no strict aliasing is implicit here)
14223 if Is_Access_Type (Target) and then
14224 In_Same_Source_Unit (Target, N)
14226 Set_No_Strict_Aliasing (Implementation_Base_Type (Target));
14229 -- Generate N_Validate_Unchecked_Conversion node for back end in case
14230 -- the back end needs to perform special validation checks.
14232 -- Shouldn't this be in Exp_Ch13, since the check only gets done if we
14233 -- have full expansion and the back end is called ???
14236 Make_Validate_Unchecked_Conversion (Sloc (N));
14237 Set_Source_Type (Vnode, Source);
14238 Set_Target_Type (Vnode, Target);
14240 -- If the unchecked conversion node is in a list, just insert before it.
14241 -- If not we have some strange case, not worth bothering about.
14243 if Is_List_Member (N) then
14244 Insert_After (N, Vnode);
14246 end Validate_Unchecked_Conversion;
14248 ------------------------------------
14249 -- Validate_Unchecked_Conversions --
14250 ------------------------------------
14252 procedure Validate_Unchecked_Conversions is
14254 for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop
14256 T : UC_Entry renames Unchecked_Conversions.Table (N);
14258 Eloc : constant Source_Ptr := T.Eloc;
14259 Source : constant Entity_Id := T.Source;
14260 Target : constant Entity_Id := T.Target;
14261 Act_Unit : constant Entity_Id := T.Act_Unit;
14267 -- Skip if function marked as warnings off
14269 if Warnings_Off (Act_Unit) then
14273 -- This validation check, which warns if we have unequal sizes for
14274 -- unchecked conversion, and thus potentially implementation
14275 -- dependent semantics, is one of the few occasions on which we
14276 -- use the official RM size instead of Esize. See description in
14277 -- Einfo "Handling of Type'Size Values" for details.
14279 if Serious_Errors_Detected = 0
14280 and then Known_Static_RM_Size (Source)
14281 and then Known_Static_RM_Size (Target)
14283 -- Don't do the check if warnings off for either type, note the
14284 -- deliberate use of OR here instead of OR ELSE to get the flag
14285 -- Warnings_Off_Used set for both types if appropriate.
14287 and then not (Has_Warnings_Off (Source)
14289 Has_Warnings_Off (Target))
14291 Source_Siz := RM_Size (Source);
14292 Target_Siz := RM_Size (Target);
14294 if Source_Siz /= Target_Siz then
14296 ("?z?types for unchecked conversion have different sizes!",
14299 if All_Errors_Mode then
14300 Error_Msg_Name_1 := Chars (Source);
14301 Error_Msg_Uint_1 := Source_Siz;
14302 Error_Msg_Name_2 := Chars (Target);
14303 Error_Msg_Uint_2 := Target_Siz;
14304 Error_Msg ("\size of % is ^, size of % is ^?z?", Eloc);
14306 Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz);
14308 if Is_Discrete_Type (Source)
14310 Is_Discrete_Type (Target)
14312 if Source_Siz > Target_Siz then
14314 ("\?z?^ high order bits of source will "
14315 & "be ignored!", Eloc);
14317 elsif Is_Unsigned_Type (Source) then
14319 ("\?z?source will be extended with ^ high order "
14320 & "zero bits!", Eloc);
14324 ("\?z?source will be extended with ^ high order "
14325 & "sign bits!", Eloc);
14328 elsif Source_Siz < Target_Siz then
14329 if Is_Discrete_Type (Target) then
14330 if Bytes_Big_Endian then
14332 ("\?z?target value will include ^ undefined "
14333 & "low order bits!", Eloc);
14336 ("\?z?target value will include ^ undefined "
14337 & "high order bits!", Eloc);
14342 ("\?z?^ trailing bits of target value will be "
14343 & "undefined!", Eloc);
14346 else pragma Assert (Source_Siz > Target_Siz);
14347 if Is_Discrete_Type (Source) then
14348 if Bytes_Big_Endian then
14350 ("\?z?^ low order bits of source will be "
14351 & "ignored!", Eloc);
14354 ("\?z?^ high order bits of source will be "
14355 & "ignored!", Eloc);
14360 ("\?z?^ trailing bits of source will be "
14361 & "ignored!", Eloc);
14368 -- If both types are access types, we need to check the alignment.
14369 -- If the alignment of both is specified, we can do it here.
14371 if Serious_Errors_Detected = 0
14372 and then Is_Access_Type (Source)
14373 and then Is_Access_Type (Target)
14374 and then Target_Strict_Alignment
14375 and then Present (Designated_Type (Source))
14376 and then Present (Designated_Type (Target))
14379 D_Source : constant Entity_Id := Designated_Type (Source);
14380 D_Target : constant Entity_Id := Designated_Type (Target);
14383 if Known_Alignment (D_Source)
14385 Known_Alignment (D_Target)
14388 Source_Align : constant Uint := Alignment (D_Source);
14389 Target_Align : constant Uint := Alignment (D_Target);
14392 if Source_Align < Target_Align
14393 and then not Is_Tagged_Type (D_Source)
14395 -- Suppress warning if warnings suppressed on either
14396 -- type or either designated type. Note the use of
14397 -- OR here instead of OR ELSE. That is intentional,
14398 -- we would like to set flag Warnings_Off_Used in
14399 -- all types for which warnings are suppressed.
14401 and then not (Has_Warnings_Off (D_Source)
14403 Has_Warnings_Off (D_Target)
14405 Has_Warnings_Off (Source)
14407 Has_Warnings_Off (Target))
14409 Error_Msg_Uint_1 := Target_Align;
14410 Error_Msg_Uint_2 := Source_Align;
14411 Error_Msg_Node_1 := D_Target;
14412 Error_Msg_Node_2 := D_Source;
14414 ("?z?alignment of & (^) is stricter than "
14415 & "alignment of & (^)!", Eloc);
14417 ("\?z?resulting access value may have invalid "
14418 & "alignment!", Eloc);
14429 end Validate_Unchecked_Conversions;