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 Targparm
; use Targparm
;
66 with Ttypes
; use Ttypes
;
67 with Tbuild
; use Tbuild
;
68 with Urealp
; use Urealp
;
69 with Warnsw
; use Warnsw
;
71 with GNAT
.Heap_Sort_G
;
73 package body Sem_Ch13
is
75 SSU
: constant Pos
:= System_Storage_Unit
;
76 -- Convenient short hand for commonly used constant
78 -----------------------
79 -- Local Subprograms --
80 -----------------------
82 procedure Alignment_Check_For_Size_Change
(Typ
: Entity_Id
; Size
: Uint
);
83 -- This routine is called after setting one of the sizes of type entity
84 -- Typ to Size. The purpose is to deal with the situation of a derived
85 -- type whose inherited alignment is no longer appropriate for the new
86 -- size value. In this case, we reset the Alignment to unknown.
88 procedure Build_Discrete_Static_Predicate
92 -- Given a predicated type Typ, where Typ is a discrete static subtype,
93 -- whose predicate expression is Expr, tests if Expr is a static predicate,
94 -- and if so, builds the predicate range list. Nam is the name of the one
95 -- argument to the predicate function. Occurrences of the type name in the
96 -- predicate expression have been replaced by identifier references to this
97 -- name, which is unique, so any identifier with Chars matching Nam must be
98 -- a reference to the type. If the predicate is non-static, this procedure
99 -- returns doing nothing. If the predicate is static, then the predicate
100 -- list is stored in Static_Discrete_Predicate (Typ), and the Expr is
101 -- rewritten as a canonicalized membership operation.
103 function Build_Export_Import_Pragma
105 Id
: Entity_Id
) return Node_Id
;
106 -- Create the corresponding pragma for aspect Export or Import denoted by
107 -- Asp. Id is the related entity subject to the aspect. Return Empty when
108 -- the expression of aspect Asp evaluates to False or is erroneous.
110 function Build_Predicate_Function_Declaration
111 (Typ
: Entity_Id
) return Node_Id
;
112 -- Build the declaration for a predicate function. The declaration is built
113 -- at the end of the declarative part containing the type definition, which
114 -- may be before the freeze point of the type. The predicate expression is
115 -- pre-analyzed at this point, to catch visibility errors.
117 procedure Build_Predicate_Functions
(Typ
: Entity_Id
; N
: Node_Id
);
118 -- If Typ has predicates (indicated by Has_Predicates being set for Typ),
119 -- then either there are pragma Predicate entries on the rep chain for the
120 -- type (note that Predicate aspects are converted to pragma Predicate), or
121 -- there are inherited aspects from a parent type, or ancestor subtypes.
122 -- This procedure builds body for the Predicate function that tests these
123 -- predicates. N is the freeze node for the type. The spec of the function
124 -- is inserted before the freeze node, and the body of the function is
125 -- inserted after the freeze node. If the predicate expression has a least
126 -- one Raise_Expression, then this procedure also builds the M version of
127 -- the predicate function for use in membership tests.
129 procedure Check_Pool_Size_Clash
(Ent
: Entity_Id
; SP
, SS
: Node_Id
);
130 -- Called if both Storage_Pool and Storage_Size attribute definition
131 -- clauses (SP and SS) are present for entity Ent. Issue error message.
133 procedure Freeze_Entity_Checks
(N
: Node_Id
);
134 -- Called from Analyze_Freeze_Entity and Analyze_Generic_Freeze Entity
135 -- to generate appropriate semantic checks that are delayed until this
136 -- point (they had to be delayed this long for cases of delayed aspects,
137 -- e.g. analysis of statically predicated subtypes in choices, for which
138 -- we have to be sure the subtypes in question are frozen before checking).
140 function Get_Alignment_Value
(Expr
: Node_Id
) return Uint
;
141 -- Given the expression for an alignment value, returns the corresponding
142 -- Uint value. If the value is inappropriate, then error messages are
143 -- posted as required, and a value of No_Uint is returned.
145 procedure Get_Interfacing_Aspects
146 (Iface_Asp
: Node_Id
;
147 Conv_Asp
: out Node_Id
;
148 EN_Asp
: out Node_Id
;
149 Expo_Asp
: out Node_Id
;
150 Imp_Asp
: out Node_Id
;
151 LN_Asp
: out Node_Id
;
152 Do_Checks
: Boolean := False);
153 -- Given a single interfacing aspect Iface_Asp, retrieve other interfacing
154 -- aspects that apply to the same related entity. The aspects considered by
155 -- this routine are as follows:
157 -- Conv_Asp - aspect Convention
158 -- EN_Asp - aspect External_Name
159 -- Expo_Asp - aspect Export
160 -- Imp_Asp - aspect Import
161 -- LN_Asp - aspect Link_Name
163 -- When flag Do_Checks is set, this routine will flag duplicate uses of
166 function Is_Operational_Item
(N
: Node_Id
) return Boolean;
167 -- A specification for a stream attribute is allowed before the full type
168 -- is declared, as explained in AI-00137 and the corrigendum. Attributes
169 -- that do not specify a representation characteristic are operational
172 function Is_Predicate_Static
174 Nam
: Name_Id
) return Boolean;
175 -- Given predicate expression Expr, tests if Expr is predicate-static in
176 -- the sense of the rules in (RM 3.2.4 (15-24)). Occurrences of the type
177 -- name in the predicate expression have been replaced by references to
178 -- an identifier whose Chars field is Nam. This name is unique, so any
179 -- identifier with Chars matching Nam must be a reference to the type.
180 -- Returns True if the expression is predicate-static and False otherwise,
181 -- but is not in the business of setting flags or issuing error messages.
183 -- Only scalar types can have static predicates, so False is always
184 -- returned for non-scalar types.
186 -- Note: the RM seems to suggest that string types can also have static
187 -- predicates. But that really makes lttle sense as very few useful
188 -- predicates can be constructed for strings. Remember that:
192 -- is not a static expression. So even though the clearly faulty RM wording
193 -- allows the following:
195 -- subtype S is String with Static_Predicate => S < "DEF"
197 -- We can't allow this, otherwise we have predicate-static applying to a
198 -- larger class than static expressions, which was never intended.
200 procedure New_Stream_Subprogram
204 Nam
: TSS_Name_Type
);
205 -- Create a subprogram renaming of a given stream attribute to the
206 -- designated subprogram and then in the tagged case, provide this as a
207 -- primitive operation, or in the untagged case make an appropriate TSS
208 -- entry. This is more properly an expansion activity than just semantics,
209 -- but the presence of user-defined stream functions for limited types
210 -- is a legality check, which is why this takes place here rather than in
211 -- exp_ch13, where it was previously. Nam indicates the name of the TSS
212 -- function to be generated.
214 -- To avoid elaboration anomalies with freeze nodes, for untagged types
215 -- we generate both a subprogram declaration and a subprogram renaming
216 -- declaration, so that the attribute specification is handled as a
217 -- renaming_as_body. For tagged types, the specification is one of the
220 procedure Resolve_Iterable_Operation
225 -- If the name of a primitive operation for an Iterable aspect is
226 -- overloaded, resolve according to required signature.
232 Biased
: Boolean := True);
233 -- If Biased is True, sets Has_Biased_Representation flag for E, and
234 -- outputs a warning message at node N if Warn_On_Biased_Representation is
235 -- is True. This warning inserts the string Msg to describe the construct
238 ----------------------------------------------
239 -- Table for Validate_Unchecked_Conversions --
240 ----------------------------------------------
242 -- The following table collects unchecked conversions for validation.
243 -- Entries are made by Validate_Unchecked_Conversion and then the call
244 -- to Validate_Unchecked_Conversions does the actual error checking and
245 -- posting of warnings. The reason for this delayed processing is to take
246 -- advantage of back-annotations of size and alignment values performed by
249 -- Note: the reason we store a Source_Ptr value instead of a Node_Id is
250 -- that by the time Validate_Unchecked_Conversions is called, Sprint will
251 -- already have modified all Sloc values if the -gnatD option is set.
253 type UC_Entry
is record
254 Eloc
: Source_Ptr
; -- node used for posting warnings
255 Source
: Entity_Id
; -- source type for unchecked conversion
256 Target
: Entity_Id
; -- target type for unchecked conversion
257 Act_Unit
: Entity_Id
; -- actual function instantiated
260 package Unchecked_Conversions
is new Table
.Table
(
261 Table_Component_Type
=> UC_Entry
,
262 Table_Index_Type
=> Int
,
263 Table_Low_Bound
=> 1,
265 Table_Increment
=> 200,
266 Table_Name
=> "Unchecked_Conversions");
268 ----------------------------------------
269 -- Table for Validate_Address_Clauses --
270 ----------------------------------------
272 -- If an address clause has the form
274 -- for X'Address use Expr
276 -- where Expr has a value known at compile time or is of the form Y'Address
277 -- or recursively is a reference to a constant initialized with either of
278 -- these forms, and the value of Expr is not a multiple of X's alignment,
279 -- or if Y has a smaller alignment than X, then 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 subject to the address clause
293 -- The value of the address in the first case
296 -- The entity of the object being overlaid in the second case
299 -- Whether the address is offset within Y in the second case
302 package Address_Clause_Checks
is new Table
.Table
(
303 Table_Component_Type
=> Address_Clause_Check_Record
,
304 Table_Index_Type
=> Int
,
305 Table_Low_Bound
=> 1,
307 Table_Increment
=> 200,
308 Table_Name
=> "Address_Clause_Checks");
310 -----------------------------------------
311 -- Adjust_Record_For_Reverse_Bit_Order --
312 -----------------------------------------
314 procedure Adjust_Record_For_Reverse_Bit_Order
(R
: Entity_Id
) is
319 -- Processing depends on version of Ada
321 -- For Ada 95, we just renumber bits within a storage unit. We do the
322 -- same for Ada 83 mode, since we recognize the Bit_Order attribute in
323 -- Ada 83, and are free to add this extension.
325 if Ada_Version
< Ada_2005
then
326 Comp
:= First_Component_Or_Discriminant
(R
);
327 while Present
(Comp
) loop
328 CC
:= Component_Clause
(Comp
);
330 -- If component clause is present, then deal with the non-default
331 -- bit order case for Ada 95 mode.
333 -- We only do this processing for the base type, and in fact that
334 -- is important, since otherwise if there are record subtypes, we
335 -- could reverse the bits once for each subtype, which is wrong.
337 if Present
(CC
) and then Ekind
(R
) = E_Record_Type
then
339 CFB
: constant Uint
:= Component_Bit_Offset
(Comp
);
340 CSZ
: constant Uint
:= Esize
(Comp
);
341 CLC
: constant Node_Id
:= Component_Clause
(Comp
);
342 Pos
: constant Node_Id
:= Position
(CLC
);
343 FB
: constant Node_Id
:= First_Bit
(CLC
);
345 Storage_Unit_Offset
: constant Uint
:=
346 CFB
/ System_Storage_Unit
;
348 Start_Bit
: constant Uint
:=
349 CFB
mod System_Storage_Unit
;
352 -- Cases where field goes over storage unit boundary
354 if Start_Bit
+ CSZ
> System_Storage_Unit
then
356 -- Allow multi-byte field but generate warning
358 if Start_Bit
mod System_Storage_Unit
= 0
359 and then CSZ
mod System_Storage_Unit
= 0
362 ("info: multi-byte field specified with "
363 & "non-standard Bit_Order?V?", CLC
);
365 if Bytes_Big_Endian
then
367 ("\bytes are not reversed "
368 & "(component is big-endian)?V?", CLC
);
371 ("\bytes are not reversed "
372 & "(component is little-endian)?V?", CLC
);
375 -- Do not allow non-contiguous field
379 ("attempt to specify non-contiguous field "
380 & "not permitted", CLC
);
382 ("\caused by non-standard Bit_Order "
385 ("\consider possibility of using "
386 & "Ada 2005 mode here", CLC
);
389 -- Case where field fits in one storage unit
392 -- Give warning if suspicious component clause
394 if Intval
(FB
) >= System_Storage_Unit
395 and then Warn_On_Reverse_Bit_Order
398 ("info: Bit_Order clause does not affect " &
399 "byte ordering?V?", Pos
);
401 Intval
(Pos
) + Intval
(FB
) /
404 ("info: position normalized to ^ before bit " &
405 "order interpreted?V?", Pos
);
408 -- Here is where we fix up the Component_Bit_Offset value
409 -- to account for the reverse bit order. Some examples of
410 -- what needs to be done are:
412 -- First_Bit .. Last_Bit Component_Bit_Offset
424 -- The rule is that the first bit is is obtained by
425 -- subtracting the old ending bit from storage_unit - 1.
427 Set_Component_Bit_Offset
429 (Storage_Unit_Offset
* System_Storage_Unit
) +
430 (System_Storage_Unit
- 1) -
431 (Start_Bit
+ CSZ
- 1));
433 Set_Normalized_First_Bit
435 Component_Bit_Offset
(Comp
) mod
436 System_Storage_Unit
);
441 Next_Component_Or_Discriminant
(Comp
);
444 -- For Ada 2005, we do machine scalar processing, as fully described In
445 -- AI-133. This involves gathering all components which start at the
446 -- same byte offset and processing them together. Same approach is still
447 -- valid in later versions including Ada 2012.
451 Max_Machine_Scalar_Size
: constant Uint
:=
453 (Standard_Long_Long_Integer_Size
);
454 -- We use this as the maximum machine scalar size
457 SSU
: constant Uint
:= UI_From_Int
(System_Storage_Unit
);
460 -- This first loop through components does two things. First it
461 -- deals with the case of components with component clauses whose
462 -- length is greater than the maximum machine scalar size (either
463 -- accepting them or rejecting as needed). Second, it counts the
464 -- number of components with component clauses whose length does
465 -- not exceed this maximum for later processing.
468 Comp
:= First_Component_Or_Discriminant
(R
);
469 while Present
(Comp
) loop
470 CC
:= Component_Clause
(Comp
);
474 Fbit
: constant Uint
:= Static_Integer
(First_Bit
(CC
));
475 Lbit
: constant Uint
:= Static_Integer
(Last_Bit
(CC
));
478 -- Case of component with last bit >= max machine scalar
480 if Lbit
>= Max_Machine_Scalar_Size
then
482 -- This is allowed only if first bit is zero, and
483 -- last bit + 1 is a multiple of storage unit size.
485 if Fbit
= 0 and then (Lbit
+ 1) mod SSU
= 0 then
487 -- This is the case to give a warning if enabled
489 if Warn_On_Reverse_Bit_Order
then
491 ("info: multi-byte field specified with "
492 & "non-standard Bit_Order?V?", CC
);
494 if Bytes_Big_Endian
then
496 ("\bytes are not reversed "
497 & "(component is big-endian)?V?", CC
);
500 ("\bytes are not reversed "
501 & "(component is little-endian)?V?", CC
);
505 -- Give error message for RM 13.5.1(10) violation
509 ("machine scalar rules not followed for&",
510 First_Bit
(CC
), Comp
);
512 Error_Msg_Uint_1
:= Lbit
+ 1;
513 Error_Msg_Uint_2
:= Max_Machine_Scalar_Size
;
515 ("\last bit + 1 (^) exceeds maximum machine "
519 if (Lbit
+ 1) mod SSU
/= 0 then
520 Error_Msg_Uint_1
:= SSU
;
522 ("\and is not a multiple of Storage_Unit (^) "
527 Error_Msg_Uint_1
:= Fbit
;
529 ("\and first bit (^) is non-zero "
535 -- OK case of machine scalar related component clause,
536 -- For now, just count them.
539 Num_CC
:= Num_CC
+ 1;
544 Next_Component_Or_Discriminant
(Comp
);
547 -- We need to sort the component clauses on the basis of the
548 -- Position values in the clause, so we can group clauses with
549 -- the same Position together to determine the relevant machine
553 Comps
: array (0 .. Num_CC
) of Entity_Id
;
554 -- Array to collect component and discriminant entities. The
555 -- data starts at index 1, the 0'th entry is for the sort
558 function CP_Lt
(Op1
, Op2
: Natural) return Boolean;
559 -- Compare routine for Sort
561 procedure CP_Move
(From
: Natural; To
: Natural);
562 -- Move routine for Sort
564 package Sorting
is new GNAT
.Heap_Sort_G
(CP_Move
, CP_Lt
);
568 -- Start and stop positions in the component list of the set of
569 -- components with the same starting position (that constitute
570 -- components in a single machine scalar).
573 -- Maximum last bit value of any component in this set
576 -- Corresponding machine scalar size
582 function CP_Lt
(Op1
, Op2
: Natural) return Boolean is
584 return Position
(Component_Clause
(Comps
(Op1
))) <
585 Position
(Component_Clause
(Comps
(Op2
)));
592 procedure CP_Move
(From
: Natural; To
: Natural) is
594 Comps
(To
) := Comps
(From
);
597 -- Start of processing for Sort_CC
600 -- Collect the machine scalar relevant component clauses
603 Comp
:= First_Component_Or_Discriminant
(R
);
604 while Present
(Comp
) loop
606 CC
: constant Node_Id
:= Component_Clause
(Comp
);
609 -- Collect only component clauses whose last bit is less
610 -- than machine scalar size. Any component clause whose
611 -- last bit exceeds this value does not take part in
612 -- machine scalar layout considerations. The test for
613 -- Error_Posted makes sure we exclude component clauses
614 -- for which we already posted an error.
617 and then not Error_Posted
(Last_Bit
(CC
))
618 and then Static_Integer
(Last_Bit
(CC
)) <
619 Max_Machine_Scalar_Size
621 Num_CC
:= Num_CC
+ 1;
622 Comps
(Num_CC
) := Comp
;
626 Next_Component_Or_Discriminant
(Comp
);
629 -- Sort by ascending position number
631 Sorting
.Sort
(Num_CC
);
633 -- We now have all the components whose size does not exceed
634 -- the max machine scalar value, sorted by starting position.
635 -- In this loop we gather groups of clauses starting at the
636 -- same position, to process them in accordance with AI-133.
639 while Stop
< Num_CC
loop
644 (Last_Bit
(Component_Clause
(Comps
(Start
))));
645 while Stop
< Num_CC
loop
647 (Position
(Component_Clause
(Comps
(Stop
+ 1)))) =
649 (Position
(Component_Clause
(Comps
(Stop
))))
657 (Component_Clause
(Comps
(Stop
)))));
663 -- Now we have a group of component clauses from Start to
664 -- Stop whose positions are identical, and MaxL is the
665 -- maximum last bit value of any of these components.
667 -- We need to determine the corresponding machine scalar
668 -- size. This loop assumes that machine scalar sizes are
669 -- even, and that each possible machine scalar has twice
670 -- as many bits as the next smaller one.
672 MSS
:= Max_Machine_Scalar_Size
;
674 and then (MSS
/ 2) >= SSU
675 and then (MSS
/ 2) > MaxL
680 -- Here is where we fix up the Component_Bit_Offset value
681 -- to account for the reverse bit order. Some examples of
682 -- what needs to be done for the case of a machine scalar
685 -- First_Bit .. Last_Bit Component_Bit_Offset
697 -- The rule is that the first bit is obtained by subtracting
698 -- the old ending bit from machine scalar size - 1.
700 for C
in Start
.. Stop
loop
702 Comp
: constant Entity_Id
:= Comps
(C
);
703 CC
: constant Node_Id
:= Component_Clause
(Comp
);
705 LB
: constant Uint
:= Static_Integer
(Last_Bit
(CC
));
706 NFB
: constant Uint
:= MSS
- Uint_1
- LB
;
707 NLB
: constant Uint
:= NFB
+ Esize
(Comp
) - 1;
708 Pos
: constant Uint
:= Static_Integer
(Position
(CC
));
711 if Warn_On_Reverse_Bit_Order
then
712 Error_Msg_Uint_1
:= MSS
;
714 ("info: reverse bit order in machine " &
715 "scalar of length^?V?", First_Bit
(CC
));
716 Error_Msg_Uint_1
:= NFB
;
717 Error_Msg_Uint_2
:= NLB
;
719 if Bytes_Big_Endian
then
721 ("\big-endian range for component "
722 & "& is ^ .. ^?V?", First_Bit
(CC
), Comp
);
725 ("\little-endian range for component"
726 & "& is ^ .. ^?V?", First_Bit
(CC
), Comp
);
730 Set_Component_Bit_Offset
(Comp
, Pos
* SSU
+ NFB
);
731 Set_Normalized_First_Bit
(Comp
, NFB
mod SSU
);
738 end Adjust_Record_For_Reverse_Bit_Order
;
740 -------------------------------------
741 -- Alignment_Check_For_Size_Change --
742 -------------------------------------
744 procedure Alignment_Check_For_Size_Change
(Typ
: Entity_Id
; Size
: Uint
) is
746 -- If the alignment is known, and not set by a rep clause, and is
747 -- inconsistent with the size being set, then reset it to unknown,
748 -- we assume in this case that the size overrides the inherited
749 -- alignment, and that the alignment must be recomputed.
751 if Known_Alignment
(Typ
)
752 and then not Has_Alignment_Clause
(Typ
)
753 and then Size
mod (Alignment
(Typ
) * SSU
) /= 0
755 Init_Alignment
(Typ
);
757 end Alignment_Check_For_Size_Change
;
759 -------------------------------------
760 -- Analyze_Aspects_At_Freeze_Point --
761 -------------------------------------
763 procedure Analyze_Aspects_At_Freeze_Point
(E
: Entity_Id
) is
764 procedure Analyze_Aspect_Default_Value
(ASN
: Node_Id
);
765 -- This routine analyzes an Aspect_Default_[Component_]Value denoted by
766 -- the aspect specification node ASN.
768 procedure Inherit_Delayed_Rep_Aspects
(ASN
: Node_Id
);
769 -- As discussed in the spec of Aspects (see Aspect_Delay declaration),
770 -- a derived type can inherit aspects from its parent which have been
771 -- specified at the time of the derivation using an aspect, as in:
773 -- type A is range 1 .. 10
774 -- with Size => Not_Defined_Yet;
778 -- Not_Defined_Yet : constant := 64;
780 -- In this example, the Size of A is considered to be specified prior
781 -- to the derivation, and thus inherited, even though the value is not
782 -- known at the time of derivation. To deal with this, we use two entity
783 -- flags. The flag Has_Derived_Rep_Aspects is set in the parent type (A
784 -- here), and then the flag May_Inherit_Delayed_Rep_Aspects is set in
785 -- the derived type (B here). If this flag is set when the derived type
786 -- is frozen, then this procedure is called to ensure proper inheritance
787 -- of all delayed aspects from the parent type. The derived type is E,
788 -- the argument to Analyze_Aspects_At_Freeze_Point. ASN is the first
789 -- aspect specification node in the Rep_Item chain for the parent type.
791 procedure Make_Pragma_From_Boolean_Aspect
(ASN
: Node_Id
);
792 -- Given an aspect specification node ASN whose expression is an
793 -- optional Boolean, this routines creates the corresponding pragma
794 -- at the freezing point.
796 ----------------------------------
797 -- Analyze_Aspect_Default_Value --
798 ----------------------------------
800 procedure Analyze_Aspect_Default_Value
(ASN
: Node_Id
) is
801 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(ASN
);
802 Ent
: constant Entity_Id
:= Entity
(ASN
);
803 Expr
: constant Node_Id
:= Expression
(ASN
);
804 Id
: constant Node_Id
:= Identifier
(ASN
);
807 Error_Msg_Name_1
:= Chars
(Id
);
809 if not Is_Type
(Ent
) then
810 Error_Msg_N
("aspect% can only apply to a type", Id
);
813 elsif not Is_First_Subtype
(Ent
) then
814 Error_Msg_N
("aspect% cannot apply to subtype", Id
);
817 elsif A_Id
= Aspect_Default_Value
818 and then not Is_Scalar_Type
(Ent
)
820 Error_Msg_N
("aspect% can only be applied to scalar type", Id
);
823 elsif A_Id
= Aspect_Default_Component_Value
then
824 if not Is_Array_Type
(Ent
) then
825 Error_Msg_N
("aspect% can only be applied to array type", Id
);
828 elsif not Is_Scalar_Type
(Component_Type
(Ent
)) then
829 Error_Msg_N
("aspect% requires scalar components", Id
);
834 Set_Has_Default_Aspect
(Base_Type
(Ent
));
836 if Is_Scalar_Type
(Ent
) then
837 Set_Default_Aspect_Value
(Base_Type
(Ent
), Expr
);
839 Set_Default_Aspect_Component_Value
(Base_Type
(Ent
), Expr
);
841 end Analyze_Aspect_Default_Value
;
843 ---------------------------------
844 -- Inherit_Delayed_Rep_Aspects --
845 ---------------------------------
847 procedure Inherit_Delayed_Rep_Aspects
(ASN
: Node_Id
) is
848 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(ASN
);
849 P
: constant Entity_Id
:= Entity
(ASN
);
850 -- Entithy for parent type
853 -- Item from Rep_Item chain
858 -- Loop through delayed aspects for the parent type
861 while Present
(N
) loop
862 if Nkind
(N
) = N_Aspect_Specification
then
863 exit when Entity
(N
) /= P
;
865 if Is_Delayed_Aspect
(N
) then
866 A
:= Get_Aspect_Id
(Chars
(Identifier
(N
)));
868 -- Process delayed rep aspect. For Boolean attributes it is
869 -- not possible to cancel an attribute once set (the attempt
870 -- to use an aspect with xxx => False is an error) for a
871 -- derived type. So for those cases, we do not have to check
872 -- if a clause has been given for the derived type, since it
873 -- is harmless to set it again if it is already set.
879 when Aspect_Alignment
=>
880 if not Has_Alignment_Clause
(E
) then
881 Set_Alignment
(E
, Alignment
(P
));
886 when Aspect_Atomic
=>
887 if Is_Atomic
(P
) then
893 when Aspect_Atomic_Components
=>
894 if Has_Atomic_Components
(P
) then
895 Set_Has_Atomic_Components
(Base_Type
(E
));
900 when Aspect_Bit_Order
=>
901 if Is_Record_Type
(E
)
902 and then No
(Get_Attribute_Definition_Clause
903 (E
, Attribute_Bit_Order
))
904 and then Reverse_Bit_Order
(P
)
906 Set_Reverse_Bit_Order
(Base_Type
(E
));
911 when Aspect_Component_Size
=>
913 and then not Has_Component_Size_Clause
(E
)
916 (Base_Type
(E
), Component_Size
(P
));
921 when Aspect_Machine_Radix
=>
922 if Is_Decimal_Fixed_Point_Type
(E
)
923 and then not Has_Machine_Radix_Clause
(E
)
925 Set_Machine_Radix_10
(E
, Machine_Radix_10
(P
));
928 -- Object_Size (also Size which also sets Object_Size)
930 when Aspect_Object_Size | Aspect_Size
=>
931 if not Has_Size_Clause
(E
)
933 No
(Get_Attribute_Definition_Clause
934 (E
, Attribute_Object_Size
))
936 Set_Esize
(E
, Esize
(P
));
942 if not Is_Packed
(E
) then
943 Set_Is_Packed
(Base_Type
(E
));
945 if Is_Bit_Packed_Array
(P
) then
946 Set_Is_Bit_Packed_Array
(Base_Type
(E
));
947 Set_Packed_Array_Impl_Type
948 (E
, Packed_Array_Impl_Type
(P
));
952 -- Scalar_Storage_Order
954 when Aspect_Scalar_Storage_Order
=>
955 if (Is_Record_Type
(E
) or else Is_Array_Type
(E
))
956 and then No
(Get_Attribute_Definition_Clause
957 (E
, Attribute_Scalar_Storage_Order
))
958 and then Reverse_Storage_Order
(P
)
960 Set_Reverse_Storage_Order
(Base_Type
(E
));
962 -- Clear default SSO indications, since the aspect
963 -- overrides the default.
965 Set_SSO_Set_Low_By_Default
(Base_Type
(E
), False);
966 Set_SSO_Set_High_By_Default
(Base_Type
(E
), False);
972 if Is_Fixed_Point_Type
(E
)
973 and then not Has_Small_Clause
(E
)
975 Set_Small_Value
(E
, Small_Value
(P
));
980 when Aspect_Storage_Size
=>
981 if (Is_Access_Type
(E
) or else Is_Task_Type
(E
))
982 and then not Has_Storage_Size_Clause
(E
)
984 Set_Storage_Size_Variable
985 (Base_Type
(E
), Storage_Size_Variable
(P
));
990 when Aspect_Value_Size
=>
992 -- Value_Size is never inherited, it is either set by
993 -- default, or it is explicitly set for the derived
994 -- type. So nothing to do here.
1000 when Aspect_Volatile
=>
1001 if Is_Volatile
(P
) then
1002 Set_Is_Volatile
(E
);
1005 -- Volatile_Full_Access
1007 when Aspect_Volatile_Full_Access
=>
1008 if Is_Volatile_Full_Access
(P
) then
1009 Set_Is_Volatile_Full_Access
(E
);
1012 -- Volatile_Components
1014 when Aspect_Volatile_Components
=>
1015 if Has_Volatile_Components
(P
) then
1016 Set_Has_Volatile_Components
(Base_Type
(E
));
1019 -- That should be all the Rep Aspects
1022 pragma Assert
(Aspect_Delay
(A_Id
) /= Rep_Aspect
);
1029 N
:= Next_Rep_Item
(N
);
1031 end Inherit_Delayed_Rep_Aspects
;
1033 -------------------------------------
1034 -- Make_Pragma_From_Boolean_Aspect --
1035 -------------------------------------
1037 procedure Make_Pragma_From_Boolean_Aspect
(ASN
: Node_Id
) is
1038 Ident
: constant Node_Id
:= Identifier
(ASN
);
1039 A_Name
: constant Name_Id
:= Chars
(Ident
);
1040 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(A_Name
);
1041 Ent
: constant Entity_Id
:= Entity
(ASN
);
1042 Expr
: constant Node_Id
:= Expression
(ASN
);
1043 Loc
: constant Source_Ptr
:= Sloc
(ASN
);
1045 procedure Check_False_Aspect_For_Derived_Type
;
1046 -- This procedure checks for the case of a false aspect for a derived
1047 -- type, which improperly tries to cancel an aspect inherited from
1050 -----------------------------------------
1051 -- Check_False_Aspect_For_Derived_Type --
1052 -----------------------------------------
1054 procedure Check_False_Aspect_For_Derived_Type
is
1058 -- We are only checking derived types
1060 if not Is_Derived_Type
(E
) then
1064 Par
:= Nearest_Ancestor
(E
);
1067 when Aspect_Atomic | Aspect_Shared
=>
1068 if not Is_Atomic
(Par
) then
1072 when Aspect_Atomic_Components
=>
1073 if not Has_Atomic_Components
(Par
) then
1077 when Aspect_Discard_Names
=>
1078 if not Discard_Names
(Par
) then
1083 if not Is_Packed
(Par
) then
1087 when Aspect_Unchecked_Union
=>
1088 if not Is_Unchecked_Union
(Par
) then
1092 when Aspect_Volatile
=>
1093 if not Is_Volatile
(Par
) then
1097 when Aspect_Volatile_Components
=>
1098 if not Has_Volatile_Components
(Par
) then
1102 when Aspect_Volatile_Full_Access
=>
1103 if not Is_Volatile_Full_Access
(Par
) then
1111 -- Fall through means we are canceling an inherited aspect
1113 Error_Msg_Name_1
:= A_Name
;
1115 ("derived type& inherits aspect%, cannot cancel", Expr
, E
);
1116 end Check_False_Aspect_For_Derived_Type
;
1122 -- Start of processing for Make_Pragma_From_Boolean_Aspect
1125 -- Note that we know Expr is present, because for a missing Expr
1126 -- argument, we knew it was True and did not need to delay the
1127 -- evaluation to the freeze point.
1129 if Is_False
(Static_Boolean
(Expr
)) then
1130 Check_False_Aspect_For_Derived_Type
;
1135 Pragma_Identifier
=>
1136 Make_Identifier
(Sloc
(Ident
), Chars
(Ident
)),
1137 Pragma_Argument_Associations
=> New_List
(
1138 Make_Pragma_Argument_Association
(Sloc
(Ident
),
1139 Expression
=> New_Occurrence_Of
(Ent
, Sloc
(Ident
)))));
1141 Set_From_Aspect_Specification
(Prag
, True);
1142 Set_Corresponding_Aspect
(Prag
, ASN
);
1143 Set_Aspect_Rep_Item
(ASN
, Prag
);
1144 Set_Is_Delayed_Aspect
(Prag
);
1145 Set_Parent
(Prag
, ASN
);
1147 end Make_Pragma_From_Boolean_Aspect
;
1155 -- Start of processing for Analyze_Aspects_At_Freeze_Point
1158 -- Must be visible in current scope
1160 if not Scope_Within_Or_Same
(Current_Scope
, Scope
(E
)) then
1164 -- Look for aspect specification entries for this entity
1166 ASN
:= First_Rep_Item
(E
);
1167 while Present
(ASN
) loop
1168 if Nkind
(ASN
) = N_Aspect_Specification
then
1169 exit when Entity
(ASN
) /= E
;
1171 if Is_Delayed_Aspect
(ASN
) then
1172 A_Id
:= Get_Aspect_Id
(ASN
);
1176 -- For aspects whose expression is an optional Boolean, make
1177 -- the corresponding pragma at the freeze point.
1179 when Boolean_Aspects |
1180 Library_Unit_Aspects
=>
1182 -- Aspects Export and Import require special handling.
1183 -- Both are by definition Boolean and may benefit from
1184 -- forward references, however their expressions are
1185 -- treated as static. In addition, the syntax of their
1186 -- corresponding pragmas requires extra "pieces" which
1187 -- may also contain forward references. To account for
1188 -- all of this, the corresponding pragma is created by
1189 -- Analyze_Aspect_Export_Import, but is not analyzed as
1190 -- the complete analysis must happen now.
1192 if A_Id
= Aspect_Export
or else A_Id
= Aspect_Import
then
1195 -- Otherwise create a corresponding pragma
1198 Make_Pragma_From_Boolean_Aspect
(ASN
);
1201 -- Special handling for aspects that don't correspond to
1202 -- pragmas/attributes.
1204 when Aspect_Default_Value |
1205 Aspect_Default_Component_Value
=>
1207 -- Do not inherit aspect for anonymous base type of a
1208 -- scalar or array type, because they apply to the first
1209 -- subtype of the type, and will be processed when that
1210 -- first subtype is frozen.
1212 if Is_Derived_Type
(E
)
1213 and then not Comes_From_Source
(E
)
1214 and then E
/= First_Subtype
(E
)
1218 Analyze_Aspect_Default_Value
(ASN
);
1221 -- Ditto for iterator aspects, because the corresponding
1222 -- attributes may not have been analyzed yet.
1224 when Aspect_Constant_Indexing |
1225 Aspect_Variable_Indexing |
1226 Aspect_Default_Iterator |
1227 Aspect_Iterator_Element
=>
1228 Analyze
(Expression
(ASN
));
1230 if Etype
(Expression
(ASN
)) = Any_Type
then
1232 ("\aspect must be fully defined before & is frozen",
1236 when Aspect_Iterable
=>
1237 Validate_Iterable_Aspect
(E
, ASN
);
1243 Ritem
:= Aspect_Rep_Item
(ASN
);
1245 if Present
(Ritem
) then
1251 Next_Rep_Item
(ASN
);
1254 -- This is where we inherit delayed rep aspects from our parent. Note
1255 -- that if we fell out of the above loop with ASN non-empty, it means
1256 -- we hit an aspect for an entity other than E, and it must be the
1257 -- type from which we were derived.
1259 if May_Inherit_Delayed_Rep_Aspects
(E
) then
1260 Inherit_Delayed_Rep_Aspects
(ASN
);
1262 end Analyze_Aspects_At_Freeze_Point
;
1264 -----------------------------------
1265 -- Analyze_Aspect_Specifications --
1266 -----------------------------------
1268 procedure Analyze_Aspect_Specifications
(N
: Node_Id
; E
: Entity_Id
) is
1269 procedure Decorate
(Asp
: Node_Id
; Prag
: Node_Id
);
1270 -- Establish linkages between an aspect and its corresponding pragma
1272 procedure Insert_Pragma
1274 Is_Instance
: Boolean := False);
1275 -- Subsidiary to the analysis of aspects
1282 -- Initial_Condition
1291 -- Insert pragma Prag such that it mimics the placement of a source
1292 -- pragma of the same kind. Flag Is_Generic should be set when the
1293 -- context denotes a generic instance.
1299 procedure Decorate
(Asp
: Node_Id
; Prag
: Node_Id
) is
1301 Set_Aspect_Rep_Item
(Asp
, Prag
);
1302 Set_Corresponding_Aspect
(Prag
, Asp
);
1303 Set_From_Aspect_Specification
(Prag
);
1304 Set_Parent
(Prag
, Asp
);
1311 procedure Insert_Pragma
1313 Is_Instance
: Boolean := False)
1319 Inserted
: Boolean := False;
1322 -- When the aspect appears on an entry, package, protected unit,
1323 -- subprogram, or task unit body, insert the generated pragma at the
1324 -- top of the body declarations to emulate the behavior of a source
1327 -- package body Pack with Aspect is
1329 -- package body Pack is
1332 if Nkind_In
(N
, N_Entry_Body
,
1338 Decls
:= Declarations
(N
);
1342 Set_Declarations
(N
, Decls
);
1345 Prepend_To
(Decls
, Prag
);
1347 -- When the aspect is associated with a [generic] package declaration
1348 -- insert the generated pragma at the top of the visible declarations
1349 -- to emulate the behavior of a source pragma.
1351 -- package Pack with Aspect is
1356 elsif Nkind_In
(N
, N_Generic_Package_Declaration
,
1357 N_Package_Declaration
)
1359 Decls
:= Visible_Declarations
(Specification
(N
));
1363 Set_Visible_Declarations
(Specification
(N
), Decls
);
1366 -- The visible declarations of a generic instance have the
1367 -- following structure:
1369 -- <renamings of generic formals>
1370 -- <renamings of internally-generated spec and body>
1371 -- <first source declaration>
1373 -- Insert the pragma before the first source declaration by
1374 -- skipping the instance "header" to ensure proper visibility of
1378 Decl
:= First
(Decls
);
1379 while Present
(Decl
) loop
1380 if Comes_From_Source
(Decl
) then
1381 Insert_Before
(Decl
, Prag
);
1389 -- The pragma is placed after the instance "header"
1391 if not Inserted
then
1392 Append_To
(Decls
, Prag
);
1395 -- Otherwise this is not a generic instance
1398 Prepend_To
(Decls
, Prag
);
1401 -- When the aspect is associated with a protected unit declaration,
1402 -- insert the generated pragma at the top of the visible declarations
1403 -- the emulate the behavior of a source pragma.
1405 -- protected [type] Prot with Aspect is
1407 -- protected [type] Prot is
1410 elsif Nkind
(N
) = N_Protected_Type_Declaration
then
1411 Def
:= Protected_Definition
(N
);
1415 Make_Protected_Definition
(Sloc
(N
),
1416 Visible_Declarations
=> New_List
,
1417 End_Label
=> Empty
);
1419 Set_Protected_Definition
(N
, Def
);
1422 Decls
:= Visible_Declarations
(Def
);
1426 Set_Visible_Declarations
(Def
, Decls
);
1429 Prepend_To
(Decls
, Prag
);
1431 -- When the aspect is associated with a task unit declaration, insert
1432 -- insert the generated pragma at the top of the visible declarations
1433 -- the emulate the behavior of a source pragma.
1435 -- task [type] Prot with Aspect is
1437 -- task [type] Prot is
1440 elsif Nkind
(N
) = N_Task_Type_Declaration
then
1441 Def
:= Task_Definition
(N
);
1445 Make_Task_Definition
(Sloc
(N
),
1446 Visible_Declarations
=> New_List
,
1447 End_Label
=> Empty
);
1449 Set_Task_Definition
(N
, Def
);
1452 Decls
:= Visible_Declarations
(Def
);
1456 Set_Visible_Declarations
(Def
, Decls
);
1459 Prepend_To
(Decls
, Prag
);
1461 -- When the context is a library unit, the pragma is added to the
1462 -- Pragmas_After list.
1464 elsif Nkind
(Parent
(N
)) = N_Compilation_Unit
then
1465 Aux
:= Aux_Decls_Node
(Parent
(N
));
1467 if No
(Pragmas_After
(Aux
)) then
1468 Set_Pragmas_After
(Aux
, New_List
);
1471 Prepend
(Prag
, Pragmas_After
(Aux
));
1473 -- Default, the pragma is inserted after the context
1476 Insert_After
(N
, Prag
);
1486 L
: constant List_Id
:= Aspect_Specifications
(N
);
1488 Ins_Node
: Node_Id
:= N
;
1489 -- Insert pragmas/attribute definition clause after this node when no
1490 -- delayed analysis is required.
1492 -- Start of processing for Analyze_Aspect_Specifications
1495 -- The general processing involves building an attribute definition
1496 -- clause or a pragma node that corresponds to the aspect. Then in order
1497 -- to delay the evaluation of this aspect to the freeze point, we attach
1498 -- the corresponding pragma/attribute definition clause to the aspect
1499 -- specification node, which is then placed in the Rep Item chain. In
1500 -- this case we mark the entity by setting the flag Has_Delayed_Aspects
1501 -- and we evaluate the rep item at the freeze point. When the aspect
1502 -- doesn't have a corresponding pragma/attribute definition clause, then
1503 -- its analysis is simply delayed at the freeze point.
1505 -- Some special cases don't require delay analysis, thus the aspect is
1506 -- analyzed right now.
1508 -- Note that there is a special handling for Pre, Post, Test_Case,
1509 -- Contract_Cases aspects. In these cases, we do not have to worry
1510 -- about delay issues, since the pragmas themselves deal with delay
1511 -- of visibility for the expression analysis. Thus, we just insert
1512 -- the pragma after the node N.
1514 pragma Assert
(Present
(L
));
1516 -- Loop through aspects
1518 Aspect
:= First
(L
);
1519 Aspect_Loop
: while Present
(Aspect
) loop
1520 Analyze_One_Aspect
: declare
1521 Expr
: constant Node_Id
:= Expression
(Aspect
);
1522 Id
: constant Node_Id
:= Identifier
(Aspect
);
1523 Loc
: constant Source_Ptr
:= Sloc
(Aspect
);
1524 Nam
: constant Name_Id
:= Chars
(Id
);
1525 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Nam
);
1528 Delay_Required
: Boolean;
1529 -- Set False if delay is not required
1531 Eloc
: Source_Ptr
:= No_Location
;
1532 -- Source location of expression, modified when we split PPC's. It
1533 -- is set below when Expr is present.
1535 procedure Analyze_Aspect_Convention
;
1536 -- Perform analysis of aspect Convention
1538 procedure Analyze_Aspect_Export_Import
;
1539 -- Perform analysis of aspects Export or Import
1541 procedure Analyze_Aspect_External_Link_Name
;
1542 -- Perform analysis of aspects External_Name or Link_Name
1544 procedure Analyze_Aspect_Implicit_Dereference
;
1545 -- Perform analysis of the Implicit_Dereference aspects
1547 procedure Make_Aitem_Pragma
1548 (Pragma_Argument_Associations
: List_Id
;
1549 Pragma_Name
: Name_Id
);
1550 -- This is a wrapper for Make_Pragma used for converting aspects
1551 -- to pragmas. It takes care of Sloc (set from Loc) and building
1552 -- the pragma identifier from the given name. In addition the
1553 -- flags Class_Present and Split_PPC are set from the aspect
1554 -- node, as well as Is_Ignored. This routine also sets the
1555 -- From_Aspect_Specification in the resulting pragma node to
1556 -- True, and sets Corresponding_Aspect to point to the aspect.
1557 -- The resulting pragma is assigned to Aitem.
1559 -------------------------------
1560 -- Analyze_Aspect_Convention --
1561 -------------------------------
1563 procedure Analyze_Aspect_Convention
is
1572 -- Obtain all interfacing aspects that apply to the related
1575 Get_Interfacing_Aspects
1576 (Iface_Asp
=> Aspect
,
1577 Conv_Asp
=> Dummy_1
,
1584 -- The related entity is subject to aspect Export or Import.
1585 -- Do not process Convention now because it must be analysed
1586 -- as part of Export or Import.
1588 if Present
(Expo
) or else Present
(Imp
) then
1591 -- Otherwise Convention appears by itself
1594 -- The aspect specifies a particular convention
1596 if Present
(Expr
) then
1597 Conv
:= New_Copy_Tree
(Expr
);
1599 -- Otherwise assume convention Ada
1602 Conv
:= Make_Identifier
(Loc
, Name_Ada
);
1606 -- pragma Convention (<Conv>, <E>);
1609 (Pragma_Name
=> Name_Convention
,
1610 Pragma_Argument_Associations
=> New_List
(
1611 Make_Pragma_Argument_Association
(Loc
,
1612 Expression
=> Conv
),
1613 Make_Pragma_Argument_Association
(Loc
,
1614 Expression
=> New_Occurrence_Of
(E
, Loc
))));
1616 Decorate
(Aspect
, Aitem
);
1617 Insert_Pragma
(Aitem
);
1619 end Analyze_Aspect_Convention
;
1621 ----------------------------------
1622 -- Analyze_Aspect_Export_Import --
1623 ----------------------------------
1625 procedure Analyze_Aspect_Export_Import
is
1633 -- Obtain all interfacing aspects that apply to the related
1636 Get_Interfacing_Aspects
1637 (Iface_Asp
=> Aspect
,
1638 Conv_Asp
=> Dummy_1
,
1645 -- The related entity cannot be subject to both aspects Export
1648 if Present
(Expo
) and then Present
(Imp
) then
1650 ("incompatible interfacing aspects given for &", E
);
1651 Error_Msg_Sloc
:= Sloc
(Expo
);
1652 Error_Msg_N
("\aspect `Export` #", E
);
1653 Error_Msg_Sloc
:= Sloc
(Imp
);
1654 Error_Msg_N
("\aspect `Import` #", E
);
1657 -- A variable is most likely modified from the outside. Take
1658 -- Take the optimistic approach to avoid spurious errors.
1660 if Ekind
(E
) = E_Variable
then
1661 Set_Never_Set_In_Source
(E
, False);
1664 -- Resolve the expression of an Import or Export here, and
1665 -- require it to be of type Boolean and static. This is not
1666 -- quite right, because in general this should be delayed,
1667 -- but that seems tricky for these, because normally Boolean
1668 -- aspects are replaced with pragmas at the freeze point in
1669 -- Make_Pragma_From_Boolean_Aspect.
1671 if not Present
(Expr
)
1672 or else Is_True
(Static_Boolean
(Expr
))
1674 if A_Id
= Aspect_Import
then
1675 Set_Has_Completion
(E
);
1676 Set_Is_Imported
(E
);
1678 -- An imported object cannot be explicitly initialized
1680 if Nkind
(N
) = N_Object_Declaration
1681 and then Present
(Expression
(N
))
1684 ("imported entities cannot be initialized "
1685 & "(RM B.1(24))", Expression
(N
));
1689 pragma Assert
(A_Id
= Aspect_Export
);
1690 Set_Is_Exported
(E
);
1693 -- Create the proper form of pragma Export or Import taking
1694 -- into account Conversion, External_Name, and Link_Name.
1696 Aitem
:= Build_Export_Import_Pragma
(Aspect
, E
);
1698 -- Otherwise the expression is either False or erroneous. There
1699 -- is no corresponding pragma.
1704 end Analyze_Aspect_Export_Import
;
1706 ---------------------------------------
1707 -- Analyze_Aspect_External_Link_Name --
1708 ---------------------------------------
1710 procedure Analyze_Aspect_External_Link_Name
is
1718 -- Obtain all interfacing aspects that apply to the related
1721 Get_Interfacing_Aspects
1722 (Iface_Asp
=> Aspect
,
1723 Conv_Asp
=> Dummy_1
,
1730 -- Ensure that aspect External_Name applies to aspect Export or
1733 if A_Id
= Aspect_External_Name
then
1734 if No
(Expo
) and then No
(Imp
) then
1736 ("aspect `External_Name` requires aspect `Import` or "
1737 & "`Export`", Aspect
);
1740 -- Otherwise ensure that aspect Link_Name applies to aspect
1741 -- Export or Import.
1744 pragma Assert
(A_Id
= Aspect_Link_Name
);
1745 if No
(Expo
) and then No
(Imp
) then
1747 ("aspect `Link_Name` requires aspect `Import` or "
1748 & "`Export`", Aspect
);
1751 end Analyze_Aspect_External_Link_Name
;
1753 -----------------------------------------
1754 -- Analyze_Aspect_Implicit_Dereference --
1755 -----------------------------------------
1757 procedure Analyze_Aspect_Implicit_Dereference
is
1759 Parent_Disc
: Entity_Id
;
1762 if not Is_Type
(E
) or else not Has_Discriminants
(E
) then
1764 ("aspect must apply to a type with discriminants", Expr
);
1766 elsif not Is_Entity_Name
(Expr
) then
1768 ("aspect must name a discriminant of current type", Expr
);
1771 Disc
:= First_Discriminant
(E
);
1772 while Present
(Disc
) loop
1773 if Chars
(Expr
) = Chars
(Disc
)
1774 and then Ekind
(Etype
(Disc
)) =
1775 E_Anonymous_Access_Type
1777 Set_Has_Implicit_Dereference
(E
);
1778 Set_Has_Implicit_Dereference
(Disc
);
1782 Next_Discriminant
(Disc
);
1785 -- Error if no proper access discriminant
1788 Error_Msg_NE
("not an access discriminant of&", Expr
, E
);
1793 -- For a type extension, check whether parent has a
1794 -- reference discriminant, to verify that use is proper.
1796 if Is_Derived_Type
(E
)
1797 and then Has_Discriminants
(Etype
(E
))
1799 Parent_Disc
:= Get_Reference_Discriminant
(Etype
(E
));
1801 if Present
(Parent_Disc
)
1802 and then Corresponding_Discriminant
(Disc
) /= Parent_Disc
1805 ("reference discriminant does not match discriminant "
1806 & "of parent type", Expr
);
1809 end Analyze_Aspect_Implicit_Dereference
;
1811 -----------------------
1812 -- Make_Aitem_Pragma --
1813 -----------------------
1815 procedure Make_Aitem_Pragma
1816 (Pragma_Argument_Associations
: List_Id
;
1817 Pragma_Name
: Name_Id
)
1819 Args
: List_Id
:= Pragma_Argument_Associations
;
1822 -- We should never get here if aspect was disabled
1824 pragma Assert
(not Is_Disabled
(Aspect
));
1826 -- Certain aspects allow for an optional name or expression. Do
1827 -- not generate a pragma with empty argument association list.
1829 if No
(Args
) or else No
(Expression
(First
(Args
))) then
1837 Pragma_Argument_Associations
=> Args
,
1838 Pragma_Identifier
=>
1839 Make_Identifier
(Sloc
(Id
), Pragma_Name
),
1840 Class_Present
=> Class_Present
(Aspect
),
1841 Split_PPC
=> Split_PPC
(Aspect
));
1843 -- Set additional semantic fields
1845 if Is_Ignored
(Aspect
) then
1846 Set_Is_Ignored
(Aitem
);
1847 elsif Is_Checked
(Aspect
) then
1848 Set_Is_Checked
(Aitem
);
1851 Set_Corresponding_Aspect
(Aitem
, Aspect
);
1852 Set_From_Aspect_Specification
(Aitem
);
1853 end Make_Aitem_Pragma
;
1855 -- Start of processing for Analyze_One_Aspect
1858 -- Skip aspect if already analyzed, to avoid looping in some cases
1860 if Analyzed
(Aspect
) then
1864 -- Skip looking at aspect if it is totally disabled. Just mark it
1865 -- as such for later reference in the tree. This also sets the
1866 -- Is_Ignored and Is_Checked flags appropriately.
1868 Check_Applicable_Policy
(Aspect
);
1870 if Is_Disabled
(Aspect
) then
1874 -- Set the source location of expression, used in the case of
1875 -- a failed precondition/postcondition or invariant. Note that
1876 -- the source location of the expression is not usually the best
1877 -- choice here. For example, it gets located on the last AND
1878 -- keyword in a chain of boolean expressiond AND'ed together.
1879 -- It is best to put the message on the first character of the
1880 -- assertion, which is the effect of the First_Node call here.
1882 if Present
(Expr
) then
1883 Eloc
:= Sloc
(First_Node
(Expr
));
1886 -- Check restriction No_Implementation_Aspect_Specifications
1888 if Implementation_Defined_Aspect
(A_Id
) then
1890 (No_Implementation_Aspect_Specifications
, Aspect
);
1893 -- Check restriction No_Specification_Of_Aspect
1895 Check_Restriction_No_Specification_Of_Aspect
(Aspect
);
1897 -- Mark aspect analyzed (actual analysis is delayed till later)
1899 Set_Analyzed
(Aspect
);
1900 Set_Entity
(Aspect
, E
);
1901 Ent
:= New_Occurrence_Of
(E
, Sloc
(Id
));
1903 -- Check for duplicate aspect. Note that the Comes_From_Source
1904 -- test allows duplicate Pre/Post's that we generate internally
1905 -- to escape being flagged here.
1907 if No_Duplicates_Allowed
(A_Id
) then
1909 while Anod
/= Aspect
loop
1910 if Comes_From_Source
(Aspect
)
1911 and then Same_Aspect
(A_Id
, Get_Aspect_Id
(Anod
))
1913 Error_Msg_Name_1
:= Nam
;
1914 Error_Msg_Sloc
:= Sloc
(Anod
);
1916 -- Case of same aspect specified twice
1918 if Class_Present
(Anod
) = Class_Present
(Aspect
) then
1919 if not Class_Present
(Anod
) then
1921 ("aspect% for & previously given#",
1925 ("aspect `%''Class` for & previously given#",
1935 -- Check some general restrictions on language defined aspects
1937 if not Implementation_Defined_Aspect
(A_Id
) then
1938 Error_Msg_Name_1
:= Nam
;
1940 -- Not allowed for renaming declarations. Examine the original
1941 -- node because a subprogram renaming may have been rewritten
1944 if Nkind
(Original_Node
(N
)) in N_Renaming_Declaration
then
1946 ("aspect % not allowed for renaming declaration",
1950 -- Not allowed for formal type declarations
1952 if Nkind
(N
) = N_Formal_Type_Declaration
then
1954 ("aspect % not allowed for formal type declaration",
1959 -- Copy expression for later processing by the procedures
1960 -- Check_Aspect_At_[Freeze_Point | End_Of_Declarations]
1962 Set_Entity
(Id
, New_Copy_Tree
(Expr
));
1964 -- Set Delay_Required as appropriate to aspect
1966 case Aspect_Delay
(A_Id
) is
1967 when Always_Delay
=>
1968 Delay_Required
:= True;
1971 Delay_Required
:= False;
1975 -- If expression has the form of an integer literal, then
1976 -- do not delay, since we know the value cannot change.
1977 -- This optimization catches most rep clause cases.
1979 -- For Boolean aspects, don't delay if no expression
1981 if A_Id
in Boolean_Aspects
and then No
(Expr
) then
1982 Delay_Required
:= False;
1984 -- For non-Boolean aspects, don't delay if integer literal
1986 elsif A_Id
not in Boolean_Aspects
1987 and then Present
(Expr
)
1988 and then Nkind
(Expr
) = N_Integer_Literal
1990 Delay_Required
:= False;
1992 -- All other cases are delayed
1995 Delay_Required
:= True;
1996 Set_Has_Delayed_Rep_Aspects
(E
);
2000 -- Processing based on specific aspect
2003 when Aspect_Unimplemented
=>
2004 null; -- ??? temp for now
2006 -- No_Aspect should be impossible
2009 raise Program_Error
;
2011 -- Case 1: Aspects corresponding to attribute definition
2014 when Aspect_Address |
2017 Aspect_Component_Size |
2018 Aspect_Constant_Indexing |
2019 Aspect_Default_Iterator |
2020 Aspect_Dispatching_Domain |
2021 Aspect_External_Tag |
2024 Aspect_Iterator_Element |
2025 Aspect_Machine_Radix |
2026 Aspect_Object_Size |
2029 Aspect_Scalar_Storage_Order |
2032 Aspect_Simple_Storage_Pool |
2033 Aspect_Storage_Pool |
2034 Aspect_Stream_Size |
2036 Aspect_Variable_Indexing |
2039 -- Indexing aspects apply only to tagged type
2041 if (A_Id
= Aspect_Constant_Indexing
2043 A_Id
= Aspect_Variable_Indexing
)
2044 and then not (Is_Type
(E
)
2045 and then Is_Tagged_Type
(E
))
2048 ("indexing aspect can only apply to a tagged type",
2053 -- For the case of aspect Address, we don't consider that we
2054 -- know the entity is never set in the source, since it is
2055 -- is likely aliasing is occurring.
2057 -- Note: one might think that the analysis of the resulting
2058 -- attribute definition clause would take care of that, but
2059 -- that's not the case since it won't be from source.
2061 if A_Id
= Aspect_Address
then
2062 Set_Never_Set_In_Source
(E
, False);
2065 -- Correctness of the profile of a stream operation is
2066 -- verified at the freeze point, but we must detect the
2067 -- illegal specification of this aspect for a subtype now,
2068 -- to prevent malformed rep_item chains.
2070 if A_Id
= Aspect_Input
or else
2071 A_Id
= Aspect_Output
or else
2072 A_Id
= Aspect_Read
or else
2075 if not Is_First_Subtype
(E
) then
2077 ("local name must be a first subtype", Aspect
);
2080 -- If stream aspect applies to the class-wide type,
2081 -- the generated attribute definition applies to the
2082 -- class-wide type as well.
2084 elsif Class_Present
(Aspect
) then
2086 Make_Attribute_Reference
(Loc
,
2088 Attribute_Name
=> Name_Class
);
2092 -- Construct the attribute definition clause
2095 Make_Attribute_Definition_Clause
(Loc
,
2097 Chars
=> Chars
(Id
),
2098 Expression
=> Relocate_Node
(Expr
));
2100 -- If the address is specified, then we treat the entity as
2101 -- referenced, to avoid spurious warnings. This is analogous
2102 -- to what is done with an attribute definition clause, but
2103 -- here we don't want to generate a reference because this
2104 -- is the point of definition of the entity.
2106 if A_Id
= Aspect_Address
then
2110 -- Case 2: Aspects corresponding to pragmas
2112 -- Case 2a: Aspects corresponding to pragmas with two
2113 -- arguments, where the first argument is a local name
2114 -- referring to the entity, and the second argument is the
2115 -- aspect definition expression.
2117 -- Linker_Section/Suppress/Unsuppress
2119 when Aspect_Linker_Section |
2121 Aspect_Unsuppress
=>
2124 (Pragma_Argument_Associations
=> New_List
(
2125 Make_Pragma_Argument_Association
(Loc
,
2126 Expression
=> New_Occurrence_Of
(E
, Loc
)),
2127 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2128 Expression
=> Relocate_Node
(Expr
))),
2129 Pragma_Name
=> Chars
(Id
));
2133 -- Corresponds to pragma Implemented, construct the pragma
2135 when Aspect_Synchronization
=>
2137 (Pragma_Argument_Associations
=> New_List
(
2138 Make_Pragma_Argument_Association
(Loc
,
2139 Expression
=> New_Occurrence_Of
(E
, Loc
)),
2140 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2141 Expression
=> Relocate_Node
(Expr
))),
2142 Pragma_Name
=> Name_Implemented
);
2146 when Aspect_Attach_Handler
=>
2148 (Pragma_Argument_Associations
=> New_List
(
2149 Make_Pragma_Argument_Association
(Sloc
(Ent
),
2151 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2152 Expression
=> Relocate_Node
(Expr
))),
2153 Pragma_Name
=> Name_Attach_Handler
);
2155 -- We need to insert this pragma into the tree to get proper
2156 -- processing and to look valid from a placement viewpoint.
2158 Insert_Pragma
(Aitem
);
2161 -- Dynamic_Predicate, Predicate, Static_Predicate
2163 when Aspect_Dynamic_Predicate |
2165 Aspect_Static_Predicate
=>
2167 -- These aspects apply only to subtypes
2169 if not Is_Type
(E
) then
2171 ("predicate can only be specified for a subtype",
2175 elsif Is_Incomplete_Type
(E
) then
2177 ("predicate cannot apply to incomplete view", Aspect
);
2181 -- Construct the pragma (always a pragma Predicate, with
2182 -- flags recording whether it is static/dynamic). We also
2183 -- set flags recording this in the type itself.
2186 (Pragma_Argument_Associations
=> New_List
(
2187 Make_Pragma_Argument_Association
(Sloc
(Ent
),
2189 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2190 Expression
=> Relocate_Node
(Expr
))),
2191 Pragma_Name
=> Name_Predicate
);
2193 -- Mark type has predicates, and remember what kind of
2194 -- aspect lead to this predicate (we need this to access
2195 -- the right set of check policies later on).
2197 Set_Has_Predicates
(E
);
2199 if A_Id
= Aspect_Dynamic_Predicate
then
2200 Set_Has_Dynamic_Predicate_Aspect
(E
);
2201 elsif A_Id
= Aspect_Static_Predicate
then
2202 Set_Has_Static_Predicate_Aspect
(E
);
2205 -- If the type is private, indicate that its completion
2206 -- has a freeze node, because that is the one that will
2207 -- be visible at freeze time.
2209 if Is_Private_Type
(E
) and then Present
(Full_View
(E
)) then
2210 Set_Has_Predicates
(Full_View
(E
));
2212 if A_Id
= Aspect_Dynamic_Predicate
then
2213 Set_Has_Dynamic_Predicate_Aspect
(Full_View
(E
));
2214 elsif A_Id
= Aspect_Static_Predicate
then
2215 Set_Has_Static_Predicate_Aspect
(Full_View
(E
));
2218 Set_Has_Delayed_Aspects
(Full_View
(E
));
2219 Ensure_Freeze_Node
(Full_View
(E
));
2222 -- Predicate_Failure
2224 when Aspect_Predicate_Failure
=>
2226 -- This aspect applies only to subtypes
2228 if not Is_Type
(E
) then
2230 ("predicate can only be specified for a subtype",
2234 elsif Is_Incomplete_Type
(E
) then
2236 ("predicate cannot apply to incomplete view", Aspect
);
2240 -- Construct the pragma
2243 (Pragma_Argument_Associations
=> New_List
(
2244 Make_Pragma_Argument_Association
(Sloc
(Ent
),
2246 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2247 Expression
=> Relocate_Node
(Expr
))),
2248 Pragma_Name
=> Name_Predicate_Failure
);
2250 Set_Has_Predicates
(E
);
2252 -- If the type is private, indicate that its completion
2253 -- has a freeze node, because that is the one that will
2254 -- be visible at freeze time.
2256 if Is_Private_Type
(E
) and then Present
(Full_View
(E
)) then
2257 Set_Has_Predicates
(Full_View
(E
));
2258 Set_Has_Delayed_Aspects
(Full_View
(E
));
2259 Ensure_Freeze_Node
(Full_View
(E
));
2262 -- Case 2b: Aspects corresponding to pragmas with two
2263 -- arguments, where the second argument is a local name
2264 -- referring to the entity, and the first argument is the
2265 -- aspect definition expression.
2269 when Aspect_Convention
=>
2270 Analyze_Aspect_Convention
;
2273 -- External_Name, Link_Name
2275 when Aspect_External_Name |
2277 Analyze_Aspect_External_Link_Name
;
2280 -- CPU, Interrupt_Priority, Priority
2282 -- These three aspects can be specified for a subprogram spec
2283 -- or body, in which case we analyze the expression and export
2284 -- the value of the aspect.
2286 -- Previously, we generated an equivalent pragma for bodies
2287 -- (note that the specs cannot contain these pragmas). The
2288 -- pragma was inserted ahead of local declarations, rather than
2289 -- after the body. This leads to a certain duplication between
2290 -- the processing performed for the aspect and the pragma, but
2291 -- given the straightforward handling required it is simpler
2292 -- to duplicate than to translate the aspect in the spec into
2293 -- a pragma in the declarative part of the body.
2296 Aspect_Interrupt_Priority |
2299 if Nkind_In
(N
, N_Subprogram_Body
,
2300 N_Subprogram_Declaration
)
2302 -- Analyze the aspect expression
2304 Analyze_And_Resolve
(Expr
, Standard_Integer
);
2306 -- Interrupt_Priority aspect not allowed for main
2307 -- subprograms. RM D.1 does not forbid this explicitly,
2308 -- but RM J.15.11(6/3) does not permit pragma
2309 -- Interrupt_Priority for subprograms.
2311 if A_Id
= Aspect_Interrupt_Priority
then
2313 ("Interrupt_Priority aspect cannot apply to "
2314 & "subprogram", Expr
);
2316 -- The expression must be static
2318 elsif not Is_OK_Static_Expression
(Expr
) then
2319 Flag_Non_Static_Expr
2320 ("aspect requires static expression!", Expr
);
2322 -- Check whether this is the main subprogram. Issue a
2323 -- warning only if it is obviously not a main program
2324 -- (when it has parameters or when the subprogram is
2325 -- within a package).
2327 elsif Present
(Parameter_Specifications
2328 (Specification
(N
)))
2329 or else not Is_Compilation_Unit
(Defining_Entity
(N
))
2331 -- See RM D.1(14/3) and D.16(12/3)
2334 ("aspect applied to subprogram other than the "
2335 & "main subprogram has no effect??", Expr
);
2337 -- Otherwise check in range and export the value
2339 -- For the CPU aspect
2341 elsif A_Id
= Aspect_CPU
then
2342 if Is_In_Range
(Expr
, RTE
(RE_CPU_Range
)) then
2344 -- Value is correct so we export the value to make
2345 -- it available at execution time.
2348 (Main_Unit
, UI_To_Int
(Expr_Value
(Expr
)));
2352 ("main subprogram CPU is out of range", Expr
);
2355 -- For the Priority aspect
2357 elsif A_Id
= Aspect_Priority
then
2358 if Is_In_Range
(Expr
, RTE
(RE_Priority
)) then
2360 -- Value is correct so we export the value to make
2361 -- it available at execution time.
2364 (Main_Unit
, UI_To_Int
(Expr_Value
(Expr
)));
2366 -- Ignore pragma if Relaxed_RM_Semantics to support
2367 -- other targets/non GNAT compilers.
2369 elsif not Relaxed_RM_Semantics
then
2371 ("main subprogram priority is out of range",
2376 -- Load an arbitrary entity from System.Tasking.Stages
2377 -- or System.Tasking.Restricted.Stages (depending on
2378 -- the supported profile) to make sure that one of these
2379 -- packages is implicitly with'ed, since we need to have
2380 -- the tasking run time active for the pragma Priority to
2381 -- have any effect. Previously we with'ed the package
2382 -- System.Tasking, but this package does not trigger the
2383 -- required initialization of the run-time library.
2386 Discard
: Entity_Id
;
2388 if Restricted_Profile
then
2389 Discard
:= RTE
(RE_Activate_Restricted_Tasks
);
2391 Discard
:= RTE
(RE_Activate_Tasks
);
2395 -- Handling for these Aspects in subprograms is complete
2399 -- For tasks pass the aspect as an attribute
2403 Make_Attribute_Definition_Clause
(Loc
,
2405 Chars
=> Chars
(Id
),
2406 Expression
=> Relocate_Node
(Expr
));
2411 when Aspect_Warnings
=>
2413 (Pragma_Argument_Associations
=> New_List
(
2414 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2415 Expression
=> Relocate_Node
(Expr
)),
2416 Make_Pragma_Argument_Association
(Loc
,
2417 Expression
=> New_Occurrence_Of
(E
, Loc
))),
2418 Pragma_Name
=> Chars
(Id
));
2420 Decorate
(Aspect
, Aitem
);
2421 Insert_Pragma
(Aitem
);
2424 -- Case 2c: Aspects corresponding to pragmas with three
2427 -- Invariant aspects have a first argument that references the
2428 -- entity, a second argument that is the expression and a third
2429 -- argument that is an appropriate message.
2431 -- Invariant, Type_Invariant
2433 when Aspect_Invariant |
2434 Aspect_Type_Invariant
=>
2436 -- Analysis of the pragma will verify placement legality:
2437 -- an invariant must apply to a private type, or appear in
2438 -- the private part of a spec and apply to a completion.
2441 (Pragma_Argument_Associations
=> New_List
(
2442 Make_Pragma_Argument_Association
(Sloc
(Ent
),
2444 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2445 Expression
=> Relocate_Node
(Expr
))),
2446 Pragma_Name
=> Name_Invariant
);
2448 -- Add message unless exception messages are suppressed
2450 if not Opt
.Exception_Locations_Suppressed
then
2451 Append_To
(Pragma_Argument_Associations
(Aitem
),
2452 Make_Pragma_Argument_Association
(Eloc
,
2453 Chars
=> Name_Message
,
2455 Make_String_Literal
(Eloc
,
2456 Strval
=> "failed invariant from "
2457 & Build_Location_String
(Eloc
))));
2460 -- For Invariant case, insert immediately after the entity
2461 -- declaration. We do not have to worry about delay issues
2462 -- since the pragma processing takes care of this.
2464 Delay_Required
:= False;
2466 -- Case 2d : Aspects that correspond to a pragma with one
2471 -- Aspect Abstract_State introduces implicit declarations for
2472 -- all state abstraction entities it defines. To emulate this
2473 -- behavior, insert the pragma at the beginning of the visible
2474 -- declarations of the related package so that it is analyzed
2477 when Aspect_Abstract_State
=> Abstract_State
: declare
2478 Context
: Node_Id
:= N
;
2481 -- When aspect Abstract_State appears on a generic package,
2482 -- it is propageted to the package instance. The context in
2483 -- this case is the instance spec.
2485 if Nkind
(Context
) = N_Package_Instantiation
then
2486 Context
:= Instance_Spec
(Context
);
2489 if Nkind_In
(Context
, N_Generic_Package_Declaration
,
2490 N_Package_Declaration
)
2493 (Pragma_Argument_Associations
=> New_List
(
2494 Make_Pragma_Argument_Association
(Loc
,
2495 Expression
=> Relocate_Node
(Expr
))),
2496 Pragma_Name
=> Name_Abstract_State
);
2498 Decorate
(Aspect
, Aitem
);
2502 Is_Generic_Instance
(Defining_Entity
(Context
)));
2506 ("aspect & must apply to a package declaration",
2513 -- Aspect Async_Readers is never delayed because it is
2514 -- equivalent to a source pragma which appears after the
2515 -- related object declaration.
2517 when Aspect_Async_Readers
=>
2519 (Pragma_Argument_Associations
=> New_List
(
2520 Make_Pragma_Argument_Association
(Loc
,
2521 Expression
=> Relocate_Node
(Expr
))),
2522 Pragma_Name
=> Name_Async_Readers
);
2524 Decorate
(Aspect
, Aitem
);
2525 Insert_Pragma
(Aitem
);
2528 -- Aspect Async_Writers is never delayed because it is
2529 -- equivalent to a source pragma which appears after the
2530 -- related object declaration.
2532 when Aspect_Async_Writers
=>
2534 (Pragma_Argument_Associations
=> New_List
(
2535 Make_Pragma_Argument_Association
(Loc
,
2536 Expression
=> Relocate_Node
(Expr
))),
2537 Pragma_Name
=> Name_Async_Writers
);
2539 Decorate
(Aspect
, Aitem
);
2540 Insert_Pragma
(Aitem
);
2543 -- Aspect Constant_After_Elaboration is never delayed because
2544 -- it is equivalent to a source pragma which appears after the
2545 -- related object declaration.
2547 when Aspect_Constant_After_Elaboration
=>
2549 (Pragma_Argument_Associations
=> New_List
(
2550 Make_Pragma_Argument_Association
(Loc
,
2551 Expression
=> Relocate_Node
(Expr
))),
2553 Name_Constant_After_Elaboration
);
2555 Decorate
(Aspect
, Aitem
);
2556 Insert_Pragma
(Aitem
);
2559 -- Aspect Default_Internal_Condition is never delayed because
2560 -- it is equivalent to a source pragma which appears after the
2561 -- related private type. To deal with forward references, the
2562 -- generated pragma is stored in the rep chain of the related
2563 -- private type as types do not carry contracts. The pragma is
2564 -- wrapped inside of a procedure at the freeze point of the
2565 -- private type's full view.
2567 when Aspect_Default_Initial_Condition
=>
2569 (Pragma_Argument_Associations
=> New_List
(
2570 Make_Pragma_Argument_Association
(Loc
,
2571 Expression
=> Relocate_Node
(Expr
))),
2573 Name_Default_Initial_Condition
);
2575 Decorate
(Aspect
, Aitem
);
2576 Insert_Pragma
(Aitem
);
2579 -- Default_Storage_Pool
2581 when Aspect_Default_Storage_Pool
=>
2583 (Pragma_Argument_Associations
=> New_List
(
2584 Make_Pragma_Argument_Association
(Loc
,
2585 Expression
=> Relocate_Node
(Expr
))),
2587 Name_Default_Storage_Pool
);
2589 Decorate
(Aspect
, Aitem
);
2590 Insert_Pragma
(Aitem
);
2595 -- Aspect Depends is never delayed because it is equivalent to
2596 -- a source pragma which appears after the related subprogram.
2597 -- To deal with forward references, the generated pragma is
2598 -- stored in the contract of the related subprogram and later
2599 -- analyzed at the end of the declarative region. See routine
2600 -- Analyze_Depends_In_Decl_Part for details.
2602 when Aspect_Depends
=>
2604 (Pragma_Argument_Associations
=> New_List
(
2605 Make_Pragma_Argument_Association
(Loc
,
2606 Expression
=> Relocate_Node
(Expr
))),
2607 Pragma_Name
=> Name_Depends
);
2609 Decorate
(Aspect
, Aitem
);
2610 Insert_Pragma
(Aitem
);
2613 -- Aspect Effecitve_Reads is never delayed because it is
2614 -- equivalent to a source pragma which appears after the
2615 -- related object declaration.
2617 when Aspect_Effective_Reads
=>
2619 (Pragma_Argument_Associations
=> New_List
(
2620 Make_Pragma_Argument_Association
(Loc
,
2621 Expression
=> Relocate_Node
(Expr
))),
2622 Pragma_Name
=> Name_Effective_Reads
);
2624 Decorate
(Aspect
, Aitem
);
2625 Insert_Pragma
(Aitem
);
2628 -- Aspect Effective_Writes is never delayed because it is
2629 -- equivalent to a source pragma which appears after the
2630 -- related object declaration.
2632 when Aspect_Effective_Writes
=>
2634 (Pragma_Argument_Associations
=> New_List
(
2635 Make_Pragma_Argument_Association
(Loc
,
2636 Expression
=> Relocate_Node
(Expr
))),
2637 Pragma_Name
=> Name_Effective_Writes
);
2639 Decorate
(Aspect
, Aitem
);
2640 Insert_Pragma
(Aitem
);
2643 -- Aspect Extensions_Visible is never delayed because it is
2644 -- equivalent to a source pragma which appears after the
2645 -- related subprogram.
2647 when Aspect_Extensions_Visible
=>
2649 (Pragma_Argument_Associations
=> New_List
(
2650 Make_Pragma_Argument_Association
(Loc
,
2651 Expression
=> Relocate_Node
(Expr
))),
2652 Pragma_Name
=> Name_Extensions_Visible
);
2654 Decorate
(Aspect
, Aitem
);
2655 Insert_Pragma
(Aitem
);
2658 -- Aspect Ghost is never delayed because it is equivalent to a
2659 -- source pragma which appears at the top of [generic] package
2660 -- declarations or after an object, a [generic] subprogram, or
2661 -- a type declaration.
2663 when Aspect_Ghost
=>
2665 (Pragma_Argument_Associations
=> New_List
(
2666 Make_Pragma_Argument_Association
(Loc
,
2667 Expression
=> Relocate_Node
(Expr
))),
2668 Pragma_Name
=> Name_Ghost
);
2670 Decorate
(Aspect
, Aitem
);
2671 Insert_Pragma
(Aitem
);
2676 -- Aspect Global is never delayed because it is equivalent to
2677 -- a source pragma which appears after the related subprogram.
2678 -- To deal with forward references, the generated pragma is
2679 -- stored in the contract of the related subprogram and later
2680 -- analyzed at the end of the declarative region. See routine
2681 -- Analyze_Global_In_Decl_Part for details.
2683 when Aspect_Global
=>
2685 (Pragma_Argument_Associations
=> New_List
(
2686 Make_Pragma_Argument_Association
(Loc
,
2687 Expression
=> Relocate_Node
(Expr
))),
2688 Pragma_Name
=> Name_Global
);
2690 Decorate
(Aspect
, Aitem
);
2691 Insert_Pragma
(Aitem
);
2694 -- Initial_Condition
2696 -- Aspect Initial_Condition is never delayed because it is
2697 -- equivalent to a source pragma which appears after the
2698 -- related package. To deal with forward references, the
2699 -- generated pragma is stored in the contract of the related
2700 -- package and later analyzed at the end of the declarative
2701 -- region. See routine Analyze_Initial_Condition_In_Decl_Part
2704 when Aspect_Initial_Condition
=> Initial_Condition
: declare
2705 Context
: Node_Id
:= N
;
2708 -- When aspect Initial_Condition appears on a generic
2709 -- package, it is propageted to the package instance. The
2710 -- context in this case is the instance spec.
2712 if Nkind
(Context
) = N_Package_Instantiation
then
2713 Context
:= Instance_Spec
(Context
);
2716 if Nkind_In
(Context
, N_Generic_Package_Declaration
,
2717 N_Package_Declaration
)
2720 (Pragma_Argument_Associations
=> New_List
(
2721 Make_Pragma_Argument_Association
(Loc
,
2722 Expression
=> Relocate_Node
(Expr
))),
2724 Name_Initial_Condition
);
2726 Decorate
(Aspect
, Aitem
);
2730 Is_Generic_Instance
(Defining_Entity
(Context
)));
2732 -- Otherwise the context is illegal
2736 ("aspect & must apply to a package declaration",
2741 end Initial_Condition
;
2745 -- Aspect Initializes is never delayed because it is equivalent
2746 -- to a source pragma appearing after the related package. To
2747 -- deal with forward references, the generated pragma is stored
2748 -- in the contract of the related package and later analyzed at
2749 -- the end of the declarative region. For details, see routine
2750 -- Analyze_Initializes_In_Decl_Part.
2752 when Aspect_Initializes
=> Initializes
: declare
2753 Context
: Node_Id
:= N
;
2756 -- When aspect Initializes appears on a generic package,
2757 -- it is propageted to the package instance. The context
2758 -- in this case is the instance spec.
2760 if Nkind
(Context
) = N_Package_Instantiation
then
2761 Context
:= Instance_Spec
(Context
);
2764 if Nkind_In
(Context
, N_Generic_Package_Declaration
,
2765 N_Package_Declaration
)
2768 (Pragma_Argument_Associations
=> New_List
(
2769 Make_Pragma_Argument_Association
(Loc
,
2770 Expression
=> Relocate_Node
(Expr
))),
2771 Pragma_Name
=> Name_Initializes
);
2773 Decorate
(Aspect
, Aitem
);
2777 Is_Generic_Instance
(Defining_Entity
(Context
)));
2779 -- Otherwise the context is illegal
2783 ("aspect & must apply to a package declaration",
2792 when Aspect_Obsolescent
=> declare
2800 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2801 Expression
=> Relocate_Node
(Expr
)));
2805 (Pragma_Argument_Associations
=> Args
,
2806 Pragma_Name
=> Chars
(Id
));
2811 when Aspect_Part_Of
=>
2812 if Nkind_In
(N
, N_Object_Declaration
,
2813 N_Package_Instantiation
)
2814 or else Is_Single_Concurrent_Type_Declaration
(N
)
2817 (Pragma_Argument_Associations
=> New_List
(
2818 Make_Pragma_Argument_Association
(Loc
,
2819 Expression
=> Relocate_Node
(Expr
))),
2820 Pragma_Name
=> Name_Part_Of
);
2822 Decorate
(Aspect
, Aitem
);
2823 Insert_Pragma
(Aitem
);
2827 ("aspect & must apply to package instantiation, "
2828 & "object, single protected type or single task type",
2836 when Aspect_SPARK_Mode
=>
2838 (Pragma_Argument_Associations
=> New_List
(
2839 Make_Pragma_Argument_Association
(Loc
,
2840 Expression
=> Relocate_Node
(Expr
))),
2841 Pragma_Name
=> Name_SPARK_Mode
);
2843 Decorate
(Aspect
, Aitem
);
2844 Insert_Pragma
(Aitem
);
2849 -- Aspect Refined_Depends is never delayed because it is
2850 -- equivalent to a source pragma which appears in the
2851 -- declarations of the related subprogram body. To deal with
2852 -- forward references, the generated pragma is stored in the
2853 -- contract of the related subprogram body and later analyzed
2854 -- at the end of the declarative region. For details, see
2855 -- routine Analyze_Refined_Depends_In_Decl_Part.
2857 when Aspect_Refined_Depends
=>
2859 (Pragma_Argument_Associations
=> New_List
(
2860 Make_Pragma_Argument_Association
(Loc
,
2861 Expression
=> Relocate_Node
(Expr
))),
2862 Pragma_Name
=> Name_Refined_Depends
);
2864 Decorate
(Aspect
, Aitem
);
2865 Insert_Pragma
(Aitem
);
2870 -- Aspect Refined_Global is never delayed because it is
2871 -- equivalent to a source pragma which appears in the
2872 -- declarations of the related subprogram body. To deal with
2873 -- forward references, the generated pragma is stored in the
2874 -- contract of the related subprogram body and later analyzed
2875 -- at the end of the declarative region. For details, see
2876 -- routine Analyze_Refined_Global_In_Decl_Part.
2878 when Aspect_Refined_Global
=>
2880 (Pragma_Argument_Associations
=> New_List
(
2881 Make_Pragma_Argument_Association
(Loc
,
2882 Expression
=> Relocate_Node
(Expr
))),
2883 Pragma_Name
=> Name_Refined_Global
);
2885 Decorate
(Aspect
, Aitem
);
2886 Insert_Pragma
(Aitem
);
2891 when Aspect_Refined_Post
=>
2893 (Pragma_Argument_Associations
=> New_List
(
2894 Make_Pragma_Argument_Association
(Loc
,
2895 Expression
=> Relocate_Node
(Expr
))),
2896 Pragma_Name
=> Name_Refined_Post
);
2898 Decorate
(Aspect
, Aitem
);
2899 Insert_Pragma
(Aitem
);
2904 when Aspect_Refined_State
=>
2906 -- The corresponding pragma for Refined_State is inserted in
2907 -- the declarations of the related package body. This action
2908 -- synchronizes both the source and from-aspect versions of
2911 if Nkind
(N
) = N_Package_Body
then
2913 (Pragma_Argument_Associations
=> New_List
(
2914 Make_Pragma_Argument_Association
(Loc
,
2915 Expression
=> Relocate_Node
(Expr
))),
2916 Pragma_Name
=> Name_Refined_State
);
2918 Decorate
(Aspect
, Aitem
);
2919 Insert_Pragma
(Aitem
);
2921 -- Otherwise the context is illegal
2925 ("aspect & must apply to a package body", Aspect
, Id
);
2930 -- Relative_Deadline
2932 when Aspect_Relative_Deadline
=>
2934 (Pragma_Argument_Associations
=> New_List
(
2935 Make_Pragma_Argument_Association
(Loc
,
2936 Expression
=> Relocate_Node
(Expr
))),
2937 Pragma_Name
=> Name_Relative_Deadline
);
2939 -- If the aspect applies to a task, the corresponding pragma
2940 -- must appear within its declarations, not after.
2942 if Nkind
(N
) = N_Task_Type_Declaration
then
2948 if No
(Task_Definition
(N
)) then
2949 Set_Task_Definition
(N
,
2950 Make_Task_Definition
(Loc
,
2951 Visible_Declarations
=> New_List
,
2952 End_Label
=> Empty
));
2955 Def
:= Task_Definition
(N
);
2956 V
:= Visible_Declarations
(Def
);
2957 if not Is_Empty_List
(V
) then
2958 Insert_Before
(First
(V
), Aitem
);
2961 Set_Visible_Declarations
(Def
, New_List
(Aitem
));
2968 -- Aspect Volatile_Function is never delayed because it is
2969 -- equivalent to a source pragma which appears after the
2970 -- related subprogram.
2972 when Aspect_Volatile_Function
=>
2974 (Pragma_Argument_Associations
=> New_List
(
2975 Make_Pragma_Argument_Association
(Loc
,
2976 Expression
=> Relocate_Node
(Expr
))),
2977 Pragma_Name
=> Name_Volatile_Function
);
2979 Decorate
(Aspect
, Aitem
);
2980 Insert_Pragma
(Aitem
);
2983 -- Case 2e: Annotate aspect
2985 when Aspect_Annotate
=>
2992 -- The argument can be a single identifier
2994 if Nkind
(Expr
) = N_Identifier
then
2996 -- One level of parens is allowed
2998 if Paren_Count
(Expr
) > 1 then
2999 Error_Msg_F
("extra parentheses ignored", Expr
);
3002 Set_Paren_Count
(Expr
, 0);
3004 -- Add the single item to the list
3006 Args
:= New_List
(Expr
);
3008 -- Otherwise we must have an aggregate
3010 elsif Nkind
(Expr
) = N_Aggregate
then
3012 -- Must be positional
3014 if Present
(Component_Associations
(Expr
)) then
3016 ("purely positional aggregate required", Expr
);
3020 -- Must not be parenthesized
3022 if Paren_Count
(Expr
) /= 0 then
3023 Error_Msg_F
("extra parentheses ignored", Expr
);
3026 -- List of arguments is list of aggregate expressions
3028 Args
:= Expressions
(Expr
);
3030 -- Anything else is illegal
3033 Error_Msg_F
("wrong form for Annotate aspect", Expr
);
3037 -- Prepare pragma arguments
3040 Arg
:= First
(Args
);
3041 while Present
(Arg
) loop
3043 Make_Pragma_Argument_Association
(Sloc
(Arg
),
3044 Expression
=> Relocate_Node
(Arg
)));
3049 Make_Pragma_Argument_Association
(Sloc
(Ent
),
3050 Chars
=> Name_Entity
,
3051 Expression
=> Ent
));
3054 (Pragma_Argument_Associations
=> Pargs
,
3055 Pragma_Name
=> Name_Annotate
);
3058 -- Case 3 : Aspects that don't correspond to pragma/attribute
3059 -- definition clause.
3061 -- Case 3a: The aspects listed below don't correspond to
3062 -- pragmas/attributes but do require delayed analysis.
3064 -- Default_Value can only apply to a scalar type
3066 when Aspect_Default_Value
=>
3067 if not Is_Scalar_Type
(E
) then
3069 ("aspect Default_Value must apply to a scalar type", N
);
3074 -- Default_Component_Value can only apply to an array type
3075 -- with scalar components.
3077 when Aspect_Default_Component_Value
=>
3078 if not (Is_Array_Type
(E
)
3079 and then Is_Scalar_Type
(Component_Type
(E
)))
3082 ("aspect Default_Component_Value can only apply to an "
3083 & "array of scalar components", N
);
3088 -- Case 3b: The aspects listed below don't correspond to
3089 -- pragmas/attributes and don't need delayed analysis.
3091 -- Implicit_Dereference
3093 -- For Implicit_Dereference, External_Name and Link_Name, only
3094 -- the legality checks are done during the analysis, thus no
3095 -- delay is required.
3097 when Aspect_Implicit_Dereference
=>
3098 Analyze_Aspect_Implicit_Dereference
;
3103 when Aspect_Dimension
=>
3104 Analyze_Aspect_Dimension
(N
, Id
, Expr
);
3109 when Aspect_Dimension_System
=>
3110 Analyze_Aspect_Dimension_System
(N
, Id
, Expr
);
3113 -- Case 4: Aspects requiring special handling
3115 -- Pre/Post/Test_Case/Contract_Cases whose corresponding
3116 -- pragmas take care of the delay.
3120 -- Aspects Pre/Post generate Precondition/Postcondition pragmas
3121 -- with a first argument that is the expression, and a second
3122 -- argument that is an informative message if the test fails.
3123 -- This is inserted right after the declaration, to get the
3124 -- required pragma placement. The processing for the pragmas
3125 -- takes care of the required delay.
3127 when Pre_Post_Aspects
=> Pre_Post
: declare
3131 if A_Id
= Aspect_Pre
or else A_Id
= Aspect_Precondition
then
3132 Pname
:= Name_Precondition
;
3134 Pname
:= Name_Postcondition
;
3137 -- Check that the class-wide predicate cannot be applied to
3138 -- an operation of a synchronized type that is not a tagged
3139 -- type. Other legality checks are performed when analyzing
3140 -- the contract of the operation.
3142 if Class_Present
(Aspect
)
3143 and then Is_Concurrent_Type
(Current_Scope
)
3144 and then not Is_Tagged_Type
(Current_Scope
)
3145 and then Ekind_In
(E
, E_Entry
, E_Function
, E_Procedure
)
3147 Error_Msg_Name_1
:= Original_Aspect_Pragma_Name
(Aspect
);
3149 ("aspect % can only be specified for a primitive "
3150 & "operation of a tagged type", Aspect
);
3155 -- If the expressions is of the form A and then B, then
3156 -- we generate separate Pre/Post aspects for the separate
3157 -- clauses. Since we allow multiple pragmas, there is no
3158 -- problem in allowing multiple Pre/Post aspects internally.
3159 -- These should be treated in reverse order (B first and
3160 -- A second) since they are later inserted just after N in
3161 -- the order they are treated. This way, the pragma for A
3162 -- ends up preceding the pragma for B, which may have an
3163 -- importance for the error raised (either constraint error
3164 -- or precondition error).
3166 -- We do not do this for Pre'Class, since we have to put
3167 -- these conditions together in a complex OR expression.
3169 -- We do not do this in ASIS mode, as ASIS relies on the
3170 -- original node representing the complete expression, when
3171 -- retrieving it through the source aspect table.
3174 and then (Pname
= Name_Postcondition
3175 or else not Class_Present
(Aspect
))
3177 while Nkind
(Expr
) = N_And_Then
loop
3178 Insert_After
(Aspect
,
3179 Make_Aspect_Specification
(Sloc
(Left_Opnd
(Expr
)),
3180 Identifier
=> Identifier
(Aspect
),
3181 Expression
=> Relocate_Node
(Left_Opnd
(Expr
)),
3182 Class_Present
=> Class_Present
(Aspect
),
3183 Split_PPC
=> True));
3184 Rewrite
(Expr
, Relocate_Node
(Right_Opnd
(Expr
)));
3185 Eloc
:= Sloc
(Expr
);
3189 -- Build the precondition/postcondition pragma
3191 -- Add note about why we do NOT need Copy_Tree here???
3194 (Pragma_Argument_Associations
=> New_List
(
3195 Make_Pragma_Argument_Association
(Eloc
,
3196 Chars
=> Name_Check
,
3197 Expression
=> Relocate_Node
(Expr
))),
3198 Pragma_Name
=> Pname
);
3200 -- Add message unless exception messages are suppressed
3202 if not Opt
.Exception_Locations_Suppressed
then
3203 Append_To
(Pragma_Argument_Associations
(Aitem
),
3204 Make_Pragma_Argument_Association
(Eloc
,
3205 Chars
=> Name_Message
,
3207 Make_String_Literal
(Eloc
,
3209 & Get_Name_String
(Pname
)
3211 & Build_Location_String
(Eloc
))));
3214 Set_Is_Delayed_Aspect
(Aspect
);
3216 -- For Pre/Post cases, insert immediately after the entity
3217 -- declaration, since that is the required pragma placement.
3218 -- Note that for these aspects, we do not have to worry
3219 -- about delay issues, since the pragmas themselves deal
3220 -- with delay of visibility for the expression analysis.
3222 Insert_Pragma
(Aitem
);
3229 when Aspect_Test_Case
=> Test_Case
: declare
3231 Comp_Expr
: Node_Id
;
3232 Comp_Assn
: Node_Id
;
3238 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
3239 Error_Msg_Name_1
:= Nam
;
3240 Error_Msg_N
("incorrect placement of aspect `%`", E
);
3244 if Nkind
(Expr
) /= N_Aggregate
then
3245 Error_Msg_Name_1
:= Nam
;
3247 ("wrong syntax for aspect `%` for &", Id
, E
);
3251 -- Make pragma expressions refer to the original aspect
3252 -- expressions through the Original_Node link. This is used
3253 -- in semantic analysis for ASIS mode, so that the original
3254 -- expression also gets analyzed.
3256 Comp_Expr
:= First
(Expressions
(Expr
));
3257 while Present
(Comp_Expr
) loop
3258 New_Expr
:= Relocate_Node
(Comp_Expr
);
3260 Make_Pragma_Argument_Association
(Sloc
(Comp_Expr
),
3261 Expression
=> New_Expr
));
3265 Comp_Assn
:= First
(Component_Associations
(Expr
));
3266 while Present
(Comp_Assn
) loop
3267 if List_Length
(Choices
(Comp_Assn
)) /= 1
3269 Nkind
(First
(Choices
(Comp_Assn
))) /= N_Identifier
3271 Error_Msg_Name_1
:= Nam
;
3273 ("wrong syntax for aspect `%` for &", Id
, E
);
3278 Make_Pragma_Argument_Association
(Sloc
(Comp_Assn
),
3279 Chars
=> Chars
(First
(Choices
(Comp_Assn
))),
3281 Relocate_Node
(Expression
(Comp_Assn
))));
3285 -- Build the test-case pragma
3288 (Pragma_Argument_Associations
=> Args
,
3289 Pragma_Name
=> Nam
);
3294 when Aspect_Contract_Cases
=>
3296 (Pragma_Argument_Associations
=> New_List
(
3297 Make_Pragma_Argument_Association
(Loc
,
3298 Expression
=> Relocate_Node
(Expr
))),
3299 Pragma_Name
=> Nam
);
3301 Decorate
(Aspect
, Aitem
);
3302 Insert_Pragma
(Aitem
);
3305 -- Case 5: Special handling for aspects with an optional
3306 -- boolean argument.
3308 -- In the delayed case, the corresponding pragma cannot be
3309 -- generated yet because the evaluation of the boolean needs
3310 -- to be delayed till the freeze point.
3312 when Boolean_Aspects |
3313 Library_Unit_Aspects
=>
3315 Set_Is_Boolean_Aspect
(Aspect
);
3317 -- Lock_Free aspect only apply to protected objects
3319 if A_Id
= Aspect_Lock_Free
then
3320 if Ekind
(E
) /= E_Protected_Type
then
3321 Error_Msg_Name_1
:= Nam
;
3323 ("aspect % only applies to a protected object",
3327 -- Set the Uses_Lock_Free flag to True if there is no
3328 -- expression or if the expression is True. The
3329 -- evaluation of this aspect should be delayed to the
3330 -- freeze point (why???)
3333 or else Is_True
(Static_Boolean
(Expr
))
3335 Set_Uses_Lock_Free
(E
);
3338 Record_Rep_Item
(E
, Aspect
);
3343 elsif A_Id
= Aspect_Export
or else A_Id
= Aspect_Import
then
3344 Analyze_Aspect_Export_Import
;
3346 -- Disable_Controlled
3348 elsif A_Id
= Aspect_Disable_Controlled
then
3349 if Ekind
(E
) /= E_Record_Type
3350 or else not Is_Controlled
(E
)
3353 ("aspect % requires controlled record type", Aspect
);
3357 -- If we're in a generic template, we don't want to try
3358 -- to disable controlled types, because typical usage is
3359 -- "Disable_Controlled => not <some_check>'Enabled", and
3360 -- the value of Enabled is not known until we see a
3361 -- particular instance. In such a context, we just need
3362 -- to preanalyze the expression for legality.
3364 if Expander_Active
then
3365 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
3367 if not Present
(Expr
)
3368 or else Is_True
(Static_Boolean
(Expr
))
3370 Set_Disable_Controlled
(E
);
3373 elsif Serious_Errors_Detected
= 0 then
3374 Preanalyze_And_Resolve
(Expr
, Standard_Boolean
);
3380 -- Library unit aspects require special handling in the case
3381 -- of a package declaration, the pragma needs to be inserted
3382 -- in the list of declarations for the associated package.
3383 -- There is no issue of visibility delay for these aspects.
3385 if A_Id
in Library_Unit_Aspects
3387 Nkind_In
(N
, N_Package_Declaration
,
3388 N_Generic_Package_Declaration
)
3389 and then Nkind
(Parent
(N
)) /= N_Compilation_Unit
3391 -- Aspect is legal on a local instantiation of a library-
3392 -- level generic unit.
3394 and then not Is_Generic_Instance
(Defining_Entity
(N
))
3397 ("incorrect context for library unit aspect&", Id
);
3401 -- Cases where we do not delay, includes all cases where the
3402 -- expression is missing other than the above cases.
3404 if not Delay_Required
or else No
(Expr
) then
3406 -- Exclude aspects Export and Import because their pragma
3407 -- syntax does not map directly to a Boolean aspect.
3409 if A_Id
/= Aspect_Export
3410 and then A_Id
/= Aspect_Import
3413 (Pragma_Argument_Associations
=> New_List
(
3414 Make_Pragma_Argument_Association
(Sloc
(Ent
),
3415 Expression
=> Ent
)),
3416 Pragma_Name
=> Chars
(Id
));
3419 Delay_Required
:= False;
3421 -- In general cases, the corresponding pragma/attribute
3422 -- definition clause will be inserted later at the freezing
3423 -- point, and we do not need to build it now.
3431 -- This is special because for access types we need to generate
3432 -- an attribute definition clause. This also works for single
3433 -- task declarations, but it does not work for task type
3434 -- declarations, because we have the case where the expression
3435 -- references a discriminant of the task type. That can't use
3436 -- an attribute definition clause because we would not have
3437 -- visibility on the discriminant. For that case we must
3438 -- generate a pragma in the task definition.
3440 when Aspect_Storage_Size
=>
3444 if Ekind
(E
) = E_Task_Type
then
3446 Decl
: constant Node_Id
:= Declaration_Node
(E
);
3449 pragma Assert
(Nkind
(Decl
) = N_Task_Type_Declaration
);
3451 -- If no task definition, create one
3453 if No
(Task_Definition
(Decl
)) then
3454 Set_Task_Definition
(Decl
,
3455 Make_Task_Definition
(Loc
,
3456 Visible_Declarations
=> Empty_List
,
3457 End_Label
=> Empty
));
3460 -- Create a pragma and put it at the start of the task
3461 -- definition for the task type declaration.
3464 (Pragma_Argument_Associations
=> New_List
(
3465 Make_Pragma_Argument_Association
(Loc
,
3466 Expression
=> Relocate_Node
(Expr
))),
3467 Pragma_Name
=> Name_Storage_Size
);
3471 Visible_Declarations
(Task_Definition
(Decl
)));
3475 -- All other cases, generate attribute definition
3479 Make_Attribute_Definition_Clause
(Loc
,
3481 Chars
=> Chars
(Id
),
3482 Expression
=> Relocate_Node
(Expr
));
3486 -- Attach the corresponding pragma/attribute definition clause to
3487 -- the aspect specification node.
3489 if Present
(Aitem
) then
3490 Set_From_Aspect_Specification
(Aitem
);
3493 -- In the context of a compilation unit, we directly put the
3494 -- pragma in the Pragmas_After list of the N_Compilation_Unit_Aux
3495 -- node (no delay is required here) except for aspects on a
3496 -- subprogram body (see below) and a generic package, for which we
3497 -- need to introduce the pragma before building the generic copy
3498 -- (see sem_ch12), and for package instantiations, where the
3499 -- library unit pragmas are better handled early.
3501 if Nkind
(Parent
(N
)) = N_Compilation_Unit
3502 and then (Present
(Aitem
) or else Is_Boolean_Aspect
(Aspect
))
3505 Aux
: constant Node_Id
:= Aux_Decls_Node
(Parent
(N
));
3508 pragma Assert
(Nkind
(Aux
) = N_Compilation_Unit_Aux
);
3510 -- For a Boolean aspect, create the corresponding pragma if
3511 -- no expression or if the value is True.
3513 if Is_Boolean_Aspect
(Aspect
) and then No
(Aitem
) then
3514 if Is_True
(Static_Boolean
(Expr
)) then
3516 (Pragma_Argument_Associations
=> New_List
(
3517 Make_Pragma_Argument_Association
(Sloc
(Ent
),
3518 Expression
=> Ent
)),
3519 Pragma_Name
=> Chars
(Id
));
3521 Set_From_Aspect_Specification
(Aitem
, True);
3522 Set_Corresponding_Aspect
(Aitem
, Aspect
);
3529 -- If the aspect is on a subprogram body (relevant aspect
3530 -- is Inline), add the pragma in front of the declarations.
3532 if Nkind
(N
) = N_Subprogram_Body
then
3533 if No
(Declarations
(N
)) then
3534 Set_Declarations
(N
, New_List
);
3537 Prepend
(Aitem
, Declarations
(N
));
3539 elsif Nkind
(N
) = N_Generic_Package_Declaration
then
3540 if No
(Visible_Declarations
(Specification
(N
))) then
3541 Set_Visible_Declarations
(Specification
(N
), New_List
);
3545 Visible_Declarations
(Specification
(N
)));
3547 elsif Nkind
(N
) = N_Package_Instantiation
then
3549 Spec
: constant Node_Id
:=
3550 Specification
(Instance_Spec
(N
));
3552 if No
(Visible_Declarations
(Spec
)) then
3553 Set_Visible_Declarations
(Spec
, New_List
);
3556 Prepend
(Aitem
, Visible_Declarations
(Spec
));
3560 if No
(Pragmas_After
(Aux
)) then
3561 Set_Pragmas_After
(Aux
, New_List
);
3564 Append
(Aitem
, Pragmas_After
(Aux
));
3571 -- The evaluation of the aspect is delayed to the freezing point.
3572 -- The pragma or attribute clause if there is one is then attached
3573 -- to the aspect specification which is put in the rep item list.
3575 if Delay_Required
then
3576 if Present
(Aitem
) then
3577 Set_Is_Delayed_Aspect
(Aitem
);
3578 Set_Aspect_Rep_Item
(Aspect
, Aitem
);
3579 Set_Parent
(Aitem
, Aspect
);
3582 Set_Is_Delayed_Aspect
(Aspect
);
3584 -- In the case of Default_Value, link the aspect to base type
3585 -- as well, even though it appears on a first subtype. This is
3586 -- mandated by the semantics of the aspect. Do not establish
3587 -- the link when processing the base type itself as this leads
3588 -- to a rep item circularity. Verify that we are dealing with
3589 -- a scalar type to prevent cascaded errors.
3591 if A_Id
= Aspect_Default_Value
3592 and then Is_Scalar_Type
(E
)
3593 and then Base_Type
(E
) /= E
3595 Set_Has_Delayed_Aspects
(Base_Type
(E
));
3596 Record_Rep_Item
(Base_Type
(E
), Aspect
);
3599 Set_Has_Delayed_Aspects
(E
);
3600 Record_Rep_Item
(E
, Aspect
);
3602 -- When delay is not required and the context is a package or a
3603 -- subprogram body, insert the pragma in the body declarations.
3605 elsif Nkind_In
(N
, N_Package_Body
, N_Subprogram_Body
) then
3606 if No
(Declarations
(N
)) then
3607 Set_Declarations
(N
, New_List
);
3610 -- The pragma is added before source declarations
3612 Prepend_To
(Declarations
(N
), Aitem
);
3614 -- When delay is not required and the context is not a compilation
3615 -- unit, we simply insert the pragma/attribute definition clause
3618 elsif Present
(Aitem
) then
3619 Insert_After
(Ins_Node
, Aitem
);
3622 end Analyze_One_Aspect
;
3626 end loop Aspect_Loop
;
3628 if Has_Delayed_Aspects
(E
) then
3629 Ensure_Freeze_Node
(E
);
3631 end Analyze_Aspect_Specifications
;
3633 ---------------------------------------------------
3634 -- Analyze_Aspect_Specifications_On_Body_Or_Stub --
3635 ---------------------------------------------------
3637 procedure Analyze_Aspect_Specifications_On_Body_Or_Stub
(N
: Node_Id
) is
3638 Body_Id
: constant Entity_Id
:= Defining_Entity
(N
);
3640 procedure Diagnose_Misplaced_Aspects
(Spec_Id
: Entity_Id
);
3641 -- Body [stub] N has aspects, but they are not properly placed. Emit an
3642 -- error message depending on the aspects involved. Spec_Id denotes the
3643 -- entity of the corresponding spec.
3645 --------------------------------
3646 -- Diagnose_Misplaced_Aspects --
3647 --------------------------------
3649 procedure Diagnose_Misplaced_Aspects
(Spec_Id
: Entity_Id
) is
3650 procedure Misplaced_Aspect_Error
3653 -- Emit an error message concerning misplaced aspect Asp. Ref_Nam is
3654 -- the name of the refined version of the aspect.
3656 ----------------------------
3657 -- Misplaced_Aspect_Error --
3658 ----------------------------
3660 procedure Misplaced_Aspect_Error
3664 Asp_Nam
: constant Name_Id
:= Chars
(Identifier
(Asp
));
3665 Asp_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Asp_Nam
);
3668 -- The corresponding spec already contains the aspect in question
3669 -- and the one appearing on the body must be the refined form:
3671 -- procedure P with Global ...;
3672 -- procedure P with Global ... is ... end P;
3676 if Has_Aspect
(Spec_Id
, Asp_Id
) then
3677 Error_Msg_Name_1
:= Asp_Nam
;
3679 -- Subunits cannot carry aspects that apply to a subprogram
3682 if Nkind
(Parent
(N
)) = N_Subunit
then
3683 Error_Msg_N
("aspect % cannot apply to a subunit", Asp
);
3685 -- Otherwise suggest the refined form
3688 Error_Msg_Name_2
:= Ref_Nam
;
3689 Error_Msg_N
("aspect % should be %", Asp
);
3692 -- Otherwise the aspect must appear on the spec, not on the body
3695 -- procedure P with Global ... is ... end P;
3699 ("aspect specification must appear on initial declaration",
3702 end Misplaced_Aspect_Error
;
3709 -- Start of processing for Diagnose_Misplaced_Aspects
3712 -- Iterate over the aspect specifications and emit specific errors
3713 -- where applicable.
3715 Asp
:= First
(Aspect_Specifications
(N
));
3716 while Present
(Asp
) loop
3717 Asp_Nam
:= Chars
(Identifier
(Asp
));
3719 -- Do not emit errors on aspects that can appear on a subprogram
3720 -- body. This scenario occurs when the aspect specification list
3721 -- contains both misplaced and properly placed aspects.
3723 if Aspect_On_Body_Or_Stub_OK
(Get_Aspect_Id
(Asp_Nam
)) then
3726 -- Special diagnostics for SPARK aspects
3728 elsif Asp_Nam
= Name_Depends
then
3729 Misplaced_Aspect_Error
(Asp
, Name_Refined_Depends
);
3731 elsif Asp_Nam
= Name_Global
then
3732 Misplaced_Aspect_Error
(Asp
, Name_Refined_Global
);
3734 elsif Asp_Nam
= Name_Post
then
3735 Misplaced_Aspect_Error
(Asp
, Name_Refined_Post
);
3737 -- Otherwise a language-defined aspect is misplaced
3741 ("aspect specification must appear on initial declaration",
3747 end Diagnose_Misplaced_Aspects
;
3751 Spec_Id
: constant Entity_Id
:= Unique_Defining_Entity
(N
);
3753 -- Start of processing for Analyze_Aspects_On_Body_Or_Stub
3756 -- Language-defined aspects cannot be associated with a subprogram body
3757 -- [stub] if the subprogram has a spec. Certain implementation defined
3758 -- aspects are allowed to break this rule (for all applicable cases, see
3759 -- table Aspects.Aspect_On_Body_Or_Stub_OK).
3761 if Spec_Id
/= Body_Id
and then not Aspects_On_Body_Or_Stub_OK
(N
) then
3762 Diagnose_Misplaced_Aspects
(Spec_Id
);
3764 Analyze_Aspect_Specifications
(N
, Body_Id
);
3766 end Analyze_Aspect_Specifications_On_Body_Or_Stub
;
3768 -----------------------
3769 -- Analyze_At_Clause --
3770 -----------------------
3772 -- An at clause is replaced by the corresponding Address attribute
3773 -- definition clause that is the preferred approach in Ada 95.
3775 procedure Analyze_At_Clause
(N
: Node_Id
) is
3776 CS
: constant Boolean := Comes_From_Source
(N
);
3779 -- This is an obsolescent feature
3781 Check_Restriction
(No_Obsolescent_Features
, N
);
3783 if Warn_On_Obsolescent_Feature
then
3785 ("?j?at clause is an obsolescent feature (RM J.7(2))", N
);
3787 ("\?j?use address attribute definition clause instead", N
);
3790 -- Rewrite as address clause
3793 Make_Attribute_Definition_Clause
(Sloc
(N
),
3794 Name
=> Identifier
(N
),
3795 Chars
=> Name_Address
,
3796 Expression
=> Expression
(N
)));
3798 -- We preserve Comes_From_Source, since logically the clause still comes
3799 -- from the source program even though it is changed in form.
3801 Set_Comes_From_Source
(N
, CS
);
3803 -- Analyze rewritten clause
3805 Analyze_Attribute_Definition_Clause
(N
);
3806 end Analyze_At_Clause
;
3808 -----------------------------------------
3809 -- Analyze_Attribute_Definition_Clause --
3810 -----------------------------------------
3812 procedure Analyze_Attribute_Definition_Clause
(N
: Node_Id
) is
3813 Loc
: constant Source_Ptr
:= Sloc
(N
);
3814 Nam
: constant Node_Id
:= Name
(N
);
3815 Attr
: constant Name_Id
:= Chars
(N
);
3816 Expr
: constant Node_Id
:= Expression
(N
);
3817 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Attr
);
3820 -- The entity of Nam after it is analyzed. In the case of an incomplete
3821 -- type, this is the underlying type.
3824 -- The underlying entity to which the attribute applies. Generally this
3825 -- is the Underlying_Type of Ent, except in the case where the clause
3826 -- applies to the full view of an incomplete or private type, in which
3827 -- case U_Ent is just a copy of Ent.
3829 FOnly
: Boolean := False;
3830 -- Reset to True for subtype specific attribute (Alignment, Size)
3831 -- and for stream attributes, i.e. those cases where in the call to
3832 -- Rep_Item_Too_Late, FOnly is set True so that only the freezing rules
3833 -- are checked. Note that the case of stream attributes is not clear
3834 -- from the RM, but see AI95-00137. Also, the RM seems to disallow
3835 -- Storage_Size for derived task types, but that is also clearly
3838 procedure Analyze_Stream_TSS_Definition
(TSS_Nam
: TSS_Name_Type
);
3839 -- Common processing for 'Read, 'Write, 'Input and 'Output attribute
3840 -- definition clauses.
3842 function Duplicate_Clause
return Boolean;
3843 -- This routine checks if the aspect for U_Ent being given by attribute
3844 -- definition clause N is for an aspect that has already been specified,
3845 -- and if so gives an error message. If there is a duplicate, True is
3846 -- returned, otherwise if there is no error, False is returned.
3848 procedure Check_Indexing_Functions
;
3849 -- Check that the function in Constant_Indexing or Variable_Indexing
3850 -- attribute has the proper type structure. If the name is overloaded,
3851 -- check that some interpretation is legal.
3853 procedure Check_Iterator_Functions
;
3854 -- Check that there is a single function in Default_Iterator attribute
3855 -- has the proper type structure.
3857 function Check_Primitive_Function
(Subp
: Entity_Id
) return Boolean;
3858 -- Common legality check for the previous two
3860 -----------------------------------
3861 -- Analyze_Stream_TSS_Definition --
3862 -----------------------------------
3864 procedure Analyze_Stream_TSS_Definition
(TSS_Nam
: TSS_Name_Type
) is
3865 Subp
: Entity_Id
:= Empty
;
3870 Is_Read
: constant Boolean := (TSS_Nam
= TSS_Stream_Read
);
3871 -- True for Read attribute, False for other attributes
3873 function Has_Good_Profile
3875 Report
: Boolean := False) return Boolean;
3876 -- Return true if the entity is a subprogram with an appropriate
3877 -- profile for the attribute being defined. If result is False and
3878 -- Report is True, function emits appropriate error.
3880 ----------------------
3881 -- Has_Good_Profile --
3882 ----------------------
3884 function Has_Good_Profile
3886 Report
: Boolean := False) return Boolean
3888 Expected_Ekind
: constant array (Boolean) of Entity_Kind
:=
3889 (False => E_Procedure
, True => E_Function
);
3890 Is_Function
: constant Boolean := (TSS_Nam
= TSS_Stream_Input
);
3895 if Ekind
(Subp
) /= Expected_Ekind
(Is_Function
) then
3899 F
:= First_Formal
(Subp
);
3902 or else Ekind
(Etype
(F
)) /= E_Anonymous_Access_Type
3903 or else Designated_Type
(Etype
(F
)) /=
3904 Class_Wide_Type
(RTE
(RE_Root_Stream_Type
))
3909 if not Is_Function
then
3913 Expected_Mode
: constant array (Boolean) of Entity_Kind
:=
3914 (False => E_In_Parameter
,
3915 True => E_Out_Parameter
);
3917 if Parameter_Mode
(F
) /= Expected_Mode
(Is_Read
) then
3924 -- If the attribute specification comes from an aspect
3925 -- specification for a class-wide stream, the parameter must be
3926 -- a class-wide type of the entity to which the aspect applies.
3928 if From_Aspect_Specification
(N
)
3929 and then Class_Present
(Parent
(N
))
3930 and then Is_Class_Wide_Type
(Typ
)
3936 Typ
:= Etype
(Subp
);
3939 -- Verify that the prefix of the attribute and the local name for
3940 -- the type of the formal match, or one is the class-wide of the
3941 -- other, in the case of a class-wide stream operation.
3943 if Base_Type
(Typ
) = Base_Type
(Ent
)
3944 or else (Is_Class_Wide_Type
(Typ
)
3945 and then Typ
= Class_Wide_Type
(Base_Type
(Ent
)))
3946 or else (Is_Class_Wide_Type
(Ent
)
3947 and then Ent
= Class_Wide_Type
(Base_Type
(Typ
)))
3954 if Present
(Next_Formal
(F
)) then
3957 elsif not Is_Scalar_Type
(Typ
)
3958 and then not Is_First_Subtype
(Typ
)
3959 and then not Is_Class_Wide_Type
(Typ
)
3961 if Report
and not Is_First_Subtype
(Typ
) then
3963 ("subtype of formal in stream operation must be a first "
3964 & "subtype", Parameter_Type
(Parent
(F
)));
3972 end Has_Good_Profile
;
3974 -- Start of processing for Analyze_Stream_TSS_Definition
3979 if not Is_Type
(U_Ent
) then
3980 Error_Msg_N
("local name must be a subtype", Nam
);
3983 elsif not Is_First_Subtype
(U_Ent
) then
3984 Error_Msg_N
("local name must be a first subtype", Nam
);
3988 Pnam
:= TSS
(Base_Type
(U_Ent
), TSS_Nam
);
3990 -- If Pnam is present, it can be either inherited from an ancestor
3991 -- type (in which case it is legal to redefine it for this type), or
3992 -- be a previous definition of the attribute for the same type (in
3993 -- which case it is illegal).
3995 -- In the first case, it will have been analyzed already, and we
3996 -- can check that its profile does not match the expected profile
3997 -- for a stream attribute of U_Ent. In the second case, either Pnam
3998 -- has been analyzed (and has the expected profile), or it has not
3999 -- been analyzed yet (case of a type that has not been frozen yet
4000 -- and for which the stream attribute has been set using Set_TSS).
4003 and then (No
(First_Entity
(Pnam
)) or else Has_Good_Profile
(Pnam
))
4005 Error_Msg_Sloc
:= Sloc
(Pnam
);
4006 Error_Msg_Name_1
:= Attr
;
4007 Error_Msg_N
("% attribute already defined #", Nam
);
4013 if Is_Entity_Name
(Expr
) then
4014 if not Is_Overloaded
(Expr
) then
4015 if Has_Good_Profile
(Entity
(Expr
), Report
=> True) then
4016 Subp
:= Entity
(Expr
);
4020 Get_First_Interp
(Expr
, I
, It
);
4021 while Present
(It
.Nam
) loop
4022 if Has_Good_Profile
(It
.Nam
) then
4027 Get_Next_Interp
(I
, It
);
4032 if Present
(Subp
) then
4033 if Is_Abstract_Subprogram
(Subp
) then
4034 Error_Msg_N
("stream subprogram must not be abstract", Expr
);
4037 -- A stream subprogram for an interface type must be a null
4038 -- procedure (RM 13.13.2 (38/3)). Note that the class-wide type
4039 -- of an interface is not an interface type (3.9.4 (6.b/2)).
4041 elsif Is_Interface
(U_Ent
)
4042 and then not Is_Class_Wide_Type
(U_Ent
)
4043 and then not Inside_A_Generic
4045 (Ekind
(Subp
) = E_Function
4049 (Unit_Declaration_Node
(Ultimate_Alias
(Subp
)))))
4052 ("stream subprogram for interface type must be null "
4053 & "procedure", Expr
);
4056 Set_Entity
(Expr
, Subp
);
4057 Set_Etype
(Expr
, Etype
(Subp
));
4059 New_Stream_Subprogram
(N
, U_Ent
, Subp
, TSS_Nam
);
4062 Error_Msg_Name_1
:= Attr
;
4063 Error_Msg_N
("incorrect expression for% attribute", Expr
);
4065 end Analyze_Stream_TSS_Definition
;
4067 ------------------------------
4068 -- Check_Indexing_Functions --
4069 ------------------------------
4071 procedure Check_Indexing_Functions
is
4072 Indexing_Found
: Boolean := False;
4074 procedure Check_Inherited_Indexing
;
4075 -- For a derived type, check that no indexing aspect is specified
4076 -- for the type if it is also inherited
4078 procedure Check_One_Function
(Subp
: Entity_Id
);
4079 -- Check one possible interpretation. Sets Indexing_Found True if a
4080 -- legal indexing function is found.
4082 procedure Illegal_Indexing
(Msg
: String);
4083 -- Diagnose illegal indexing function if not overloaded. In the
4084 -- overloaded case indicate that no legal interpretation exists.
4086 ------------------------------
4087 -- Check_Inherited_Indexing --
4088 ------------------------------
4090 procedure Check_Inherited_Indexing
is
4091 Inherited
: Node_Id
;
4094 if Attr
= Name_Constant_Indexing
then
4096 Find_Aspect
(Etype
(Ent
), Aspect_Constant_Indexing
);
4097 else pragma Assert
(Attr
= Name_Variable_Indexing
);
4099 Find_Aspect
(Etype
(Ent
), Aspect_Variable_Indexing
);
4102 if Present
(Inherited
) then
4103 if Debug_Flag_Dot_XX
then
4106 -- OK if current attribute_definition_clause is expansion of
4107 -- inherited aspect.
4109 elsif Aspect_Rep_Item
(Inherited
) = N
then
4112 -- Indicate the operation that must be overridden, rather than
4113 -- redefining the indexing aspect.
4117 ("indexing function already inherited from parent type");
4119 ("!override & instead",
4120 N
, Entity
(Expression
(Inherited
)));
4123 end Check_Inherited_Indexing
;
4125 ------------------------
4126 -- Check_One_Function --
4127 ------------------------
4129 procedure Check_One_Function
(Subp
: Entity_Id
) is
4130 Default_Element
: Node_Id
;
4131 Ret_Type
: constant Entity_Id
:= Etype
(Subp
);
4134 if not Is_Overloadable
(Subp
) then
4135 Illegal_Indexing
("illegal indexing function for type&");
4138 elsif Scope
(Subp
) /= Scope
(Ent
) then
4139 if Nkind
(Expr
) = N_Expanded_Name
then
4141 -- Indexing function can't be declared elsewhere
4144 ("indexing function must be declared in scope of type&");
4149 elsif No
(First_Formal
(Subp
)) then
4151 ("Indexing requires a function that applies to type&");
4154 elsif No
(Next_Formal
(First_Formal
(Subp
))) then
4156 ("indexing function must have at least two parameters");
4159 elsif Is_Derived_Type
(Ent
) then
4160 Check_Inherited_Indexing
;
4163 if not Check_Primitive_Function
(Subp
) then
4165 ("Indexing aspect requires a function that applies to type&");
4169 -- If partial declaration exists, verify that it is not tagged.
4171 if Ekind
(Current_Scope
) = E_Package
4172 and then Has_Private_Declaration
(Ent
)
4173 and then From_Aspect_Specification
(N
)
4175 List_Containing
(Parent
(Ent
)) =
4176 Private_Declarations
4177 (Specification
(Unit_Declaration_Node
(Current_Scope
)))
4178 and then Nkind
(N
) = N_Attribute_Definition_Clause
4185 First
(Visible_Declarations
4187 (Unit_Declaration_Node
(Current_Scope
))));
4189 while Present
(Decl
) loop
4190 if Nkind
(Decl
) = N_Private_Type_Declaration
4191 and then Ent
= Full_View
(Defining_Identifier
(Decl
))
4192 and then Tagged_Present
(Decl
)
4193 and then No
(Aspect_Specifications
(Decl
))
4196 ("Indexing aspect cannot be specified on full view "
4197 & "if partial view is tagged");
4206 -- An indexing function must return either the default element of
4207 -- the container, or a reference type. For variable indexing it
4208 -- must be the latter.
4211 Find_Value_Of_Aspect
4212 (Etype
(First_Formal
(Subp
)), Aspect_Iterator_Element
);
4214 if Present
(Default_Element
) then
4215 Analyze
(Default_Element
);
4217 if Is_Entity_Name
(Default_Element
)
4218 and then not Covers
(Entity
(Default_Element
), Ret_Type
)
4222 ("wrong return type for indexing function");
4227 -- For variable_indexing the return type must be a reference type
4229 if Attr
= Name_Variable_Indexing
then
4230 if not Has_Implicit_Dereference
(Ret_Type
) then
4232 ("variable indexing must return a reference type");
4235 elsif Is_Access_Constant
4236 (Etype
(First_Discriminant
(Ret_Type
)))
4239 ("variable indexing must return an access to variable");
4244 if Has_Implicit_Dereference
(Ret_Type
)
4246 Is_Access_Constant
(Etype
(First_Discriminant
(Ret_Type
)))
4249 ("constant indexing must return an access to constant");
4252 elsif Is_Access_Type
(Etype
(First_Formal
(Subp
)))
4253 and then not Is_Access_Constant
(Etype
(First_Formal
(Subp
)))
4256 ("constant indexing must apply to an access to constant");
4261 -- All checks succeeded.
4263 Indexing_Found
:= True;
4264 end Check_One_Function
;
4266 -----------------------
4267 -- Illegal_Indexing --
4268 -----------------------
4270 procedure Illegal_Indexing
(Msg
: String) is
4272 Error_Msg_NE
(Msg
, N
, Ent
);
4273 end Illegal_Indexing
;
4275 -- Start of processing for Check_Indexing_Functions
4279 Check_Inherited_Indexing
;
4284 if not Is_Overloaded
(Expr
) then
4285 Check_One_Function
(Entity
(Expr
));
4293 Indexing_Found
:= False;
4294 Get_First_Interp
(Expr
, I
, It
);
4295 while Present
(It
.Nam
) loop
4297 -- Note that analysis will have added the interpretation
4298 -- that corresponds to the dereference. We only check the
4299 -- subprogram itself.
4301 if Is_Overloadable
(It
.Nam
) then
4302 Check_One_Function
(It
.Nam
);
4305 Get_Next_Interp
(I
, It
);
4310 if not Indexing_Found
and then not Error_Posted
(N
) then
4312 ("aspect Indexing requires a local function that "
4313 & "applies to type&", Expr
, Ent
);
4315 end Check_Indexing_Functions
;
4317 ------------------------------
4318 -- Check_Iterator_Functions --
4319 ------------------------------
4321 procedure Check_Iterator_Functions
is
4322 function Valid_Default_Iterator
(Subp
: Entity_Id
) return Boolean;
4323 -- Check one possible interpretation for validity
4325 ----------------------------
4326 -- Valid_Default_Iterator --
4327 ----------------------------
4329 function Valid_Default_Iterator
(Subp
: Entity_Id
) return Boolean is
4330 Root_T
: constant Entity_Id
:= Root_Type
(Etype
(Etype
(Subp
)));
4334 if not Check_Primitive_Function
(Subp
) then
4337 -- The return type must be derived from a type in an instance
4338 -- of Iterator.Interfaces, and thus its root type must have a
4341 elsif Chars
(Root_T
) /= Name_Forward_Iterator
4342 and then Chars
(Root_T
) /= Name_Reversible_Iterator
4347 Formal
:= First_Formal
(Subp
);
4350 -- False if any subsequent formal has no default expression
4352 Formal
:= Next_Formal
(Formal
);
4353 while Present
(Formal
) loop
4354 if No
(Expression
(Parent
(Formal
))) then
4358 Next_Formal
(Formal
);
4361 -- True if all subsequent formals have default expressions
4364 end Valid_Default_Iterator
;
4366 -- Start of processing for Check_Iterator_Functions
4371 if not Is_Entity_Name
(Expr
) then
4372 Error_Msg_N
("aspect Iterator must be a function name", Expr
);
4375 if not Is_Overloaded
(Expr
) then
4376 if not Check_Primitive_Function
(Entity
(Expr
)) then
4378 ("aspect Indexing requires a function that applies to type&",
4379 Entity
(Expr
), Ent
);
4382 -- Flag the default_iterator as well as the denoted function.
4384 if not Valid_Default_Iterator
(Entity
(Expr
)) then
4385 Error_Msg_N
("improper function for default iterator!", Expr
);
4390 Default
: Entity_Id
:= Empty
;
4395 Get_First_Interp
(Expr
, I
, It
);
4396 while Present
(It
.Nam
) loop
4397 if not Check_Primitive_Function
(It
.Nam
)
4398 or else not Valid_Default_Iterator
(It
.Nam
)
4402 elsif Present
(Default
) then
4404 -- An explicit one should override an implicit one
4406 if Comes_From_Source
(Default
) =
4407 Comes_From_Source
(It
.Nam
)
4409 Error_Msg_N
("default iterator must be unique", Expr
);
4410 Error_Msg_Sloc
:= Sloc
(Default
);
4411 Error_Msg_N
("\\possible interpretation#", Expr
);
4412 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
4413 Error_Msg_N
("\\possible interpretation#", Expr
);
4415 elsif Comes_From_Source
(It
.Nam
) then
4422 Get_Next_Interp
(I
, It
);
4425 if Present
(Default
) then
4426 Set_Entity
(Expr
, Default
);
4427 Set_Is_Overloaded
(Expr
, False);
4430 ("no interpretation is a valid default iterator!", Expr
);
4434 end Check_Iterator_Functions
;
4436 -------------------------------
4437 -- Check_Primitive_Function --
4438 -------------------------------
4440 function Check_Primitive_Function
(Subp
: Entity_Id
) return Boolean is
4444 if Ekind
(Subp
) /= E_Function
then
4448 if No
(First_Formal
(Subp
)) then
4451 Ctrl
:= Etype
(First_Formal
(Subp
));
4454 -- To be a primitive operation subprogram has to be in same scope.
4456 if Scope
(Ctrl
) /= Scope
(Subp
) then
4460 -- Type of formal may be the class-wide type, an access to such,
4461 -- or an incomplete view.
4464 or else Ctrl
= Class_Wide_Type
(Ent
)
4466 (Ekind
(Ctrl
) = E_Anonymous_Access_Type
4467 and then (Designated_Type
(Ctrl
) = Ent
4469 Designated_Type
(Ctrl
) = Class_Wide_Type
(Ent
)))
4471 (Ekind
(Ctrl
) = E_Incomplete_Type
4472 and then Full_View
(Ctrl
) = Ent
)
4480 end Check_Primitive_Function
;
4482 ----------------------
4483 -- Duplicate_Clause --
4484 ----------------------
4486 function Duplicate_Clause
return Boolean is
4490 -- Nothing to do if this attribute definition clause comes from
4491 -- an aspect specification, since we could not be duplicating an
4492 -- explicit clause, and we dealt with the case of duplicated aspects
4493 -- in Analyze_Aspect_Specifications.
4495 if From_Aspect_Specification
(N
) then
4499 -- Otherwise current clause may duplicate previous clause, or a
4500 -- previously given pragma or aspect specification for the same
4503 A
:= Get_Rep_Item
(U_Ent
, Chars
(N
), Check_Parents
=> False);
4506 Error_Msg_Name_1
:= Chars
(N
);
4507 Error_Msg_Sloc
:= Sloc
(A
);
4509 Error_Msg_NE
("aspect% for & previously given#", N
, U_Ent
);
4514 end Duplicate_Clause
;
4516 -- Start of processing for Analyze_Attribute_Definition_Clause
4519 -- The following code is a defense against recursion. Not clear that
4520 -- this can happen legitimately, but perhaps some error situations can
4521 -- cause it, and we did see this recursion during testing.
4523 if Analyzed
(N
) then
4526 Set_Analyzed
(N
, True);
4529 Check_Restriction_No_Use_Of_Attribute
(N
);
4531 -- Ignore some selected attributes in CodePeer mode since they are not
4532 -- relevant in this context.
4534 if CodePeer_Mode
then
4537 -- Ignore Component_Size in CodePeer mode, to avoid changing the
4538 -- internal representation of types by implicitly packing them.
4540 when Attribute_Component_Size
=>
4541 Rewrite
(N
, Make_Null_Statement
(Sloc
(N
)));
4549 -- Process Ignore_Rep_Clauses option
4551 if Ignore_Rep_Clauses
then
4554 -- The following should be ignored. They do not affect legality
4555 -- and may be target dependent. The basic idea of -gnatI is to
4556 -- ignore any rep clauses that may be target dependent but do not
4557 -- affect legality (except possibly to be rejected because they
4558 -- are incompatible with the compilation target).
4560 when Attribute_Alignment |
4561 Attribute_Bit_Order |
4562 Attribute_Component_Size |
4563 Attribute_Machine_Radix |
4564 Attribute_Object_Size |
4567 Attribute_Stream_Size |
4568 Attribute_Value_Size
=>
4569 Kill_Rep_Clause
(N
);
4572 -- The following should not be ignored, because in the first place
4573 -- they are reasonably portable, and should not cause problems
4574 -- in compiling code from another target, and also they do affect
4575 -- legality, e.g. failing to provide a stream attribute for a type
4576 -- may make a program illegal.
4578 when Attribute_External_Tag |
4582 Attribute_Simple_Storage_Pool |
4583 Attribute_Storage_Pool |
4584 Attribute_Storage_Size |
4588 -- We do not do anything here with address clauses, they will be
4589 -- removed by Freeze later on, but for now, it works better to
4590 -- keep then in the tree.
4592 when Attribute_Address
=>
4595 -- Other cases are errors ("attribute& cannot be set with
4596 -- definition clause"), which will be caught below.
4604 Ent
:= Entity
(Nam
);
4606 if Rep_Item_Too_Early
(Ent
, N
) then
4610 -- Rep clause applies to full view of incomplete type or private type if
4611 -- we have one (if not, this is a premature use of the type). However,
4612 -- certain semantic checks need to be done on the specified entity (i.e.
4613 -- the private view), so we save it in Ent.
4615 if Is_Private_Type
(Ent
)
4616 and then Is_Derived_Type
(Ent
)
4617 and then not Is_Tagged_Type
(Ent
)
4618 and then No
(Full_View
(Ent
))
4620 -- If this is a private type whose completion is a derivation from
4621 -- another private type, there is no full view, and the attribute
4622 -- belongs to the type itself, not its underlying parent.
4626 elsif Ekind
(Ent
) = E_Incomplete_Type
then
4628 -- The attribute applies to the full view, set the entity of the
4629 -- attribute definition accordingly.
4631 Ent
:= Underlying_Type
(Ent
);
4633 Set_Entity
(Nam
, Ent
);
4636 U_Ent
:= Underlying_Type
(Ent
);
4639 -- Avoid cascaded error
4641 if Etype
(Nam
) = Any_Type
then
4644 -- Must be declared in current scope or in case of an aspect
4645 -- specification, must be visible in current scope.
4647 elsif Scope
(Ent
) /= Current_Scope
4649 not (From_Aspect_Specification
(N
)
4650 and then Scope_Within_Or_Same
(Current_Scope
, Scope
(Ent
)))
4652 Error_Msg_N
("entity must be declared in this scope", Nam
);
4655 -- Must not be a source renaming (we do have some cases where the
4656 -- expander generates a renaming, and those cases are OK, in such
4657 -- cases any attribute applies to the renamed object as well).
4659 elsif Is_Object
(Ent
)
4660 and then Present
(Renamed_Object
(Ent
))
4662 -- Case of renamed object from source, this is an error
4664 if Comes_From_Source
(Renamed_Object
(Ent
)) then
4665 Get_Name_String
(Chars
(N
));
4666 Error_Msg_Strlen
:= Name_Len
;
4667 Error_Msg_String
(1 .. Name_Len
) := Name_Buffer
(1 .. Name_Len
);
4669 ("~ clause not allowed for a renaming declaration "
4670 & "(RM 13.1(6))", Nam
);
4673 -- For the case of a compiler generated renaming, the attribute
4674 -- definition clause applies to the renamed object created by the
4675 -- expander. The easiest general way to handle this is to create a
4676 -- copy of the attribute definition clause for this object.
4678 elsif Is_Entity_Name
(Renamed_Object
(Ent
)) then
4680 Make_Attribute_Definition_Clause
(Loc
,
4682 New_Occurrence_Of
(Entity
(Renamed_Object
(Ent
)), Loc
),
4684 Expression
=> Duplicate_Subexpr
(Expression
(N
))));
4686 -- If the renamed object is not an entity, it must be a dereference
4687 -- of an unconstrained function call, and we must introduce a new
4688 -- declaration to capture the expression. This is needed in the case
4689 -- of 'Alignment, where the original declaration must be rewritten.
4693 (Nkind
(Renamed_Object
(Ent
)) = N_Explicit_Dereference
);
4697 -- If no underlying entity, use entity itself, applies to some
4698 -- previously detected error cases ???
4700 elsif No
(U_Ent
) then
4703 -- Cannot specify for a subtype (exception Object/Value_Size)
4705 elsif Is_Type
(U_Ent
)
4706 and then not Is_First_Subtype
(U_Ent
)
4707 and then Id
/= Attribute_Object_Size
4708 and then Id
/= Attribute_Value_Size
4709 and then not From_At_Mod
(N
)
4711 Error_Msg_N
("cannot specify attribute for subtype", Nam
);
4715 Set_Entity
(N
, U_Ent
);
4717 -- Switch on particular attribute
4725 -- Address attribute definition clause
4727 when Attribute_Address
=> Address
: begin
4729 -- A little error check, catch for X'Address use X'Address;
4731 if Nkind
(Nam
) = N_Identifier
4732 and then Nkind
(Expr
) = N_Attribute_Reference
4733 and then Attribute_Name
(Expr
) = Name_Address
4734 and then Nkind
(Prefix
(Expr
)) = N_Identifier
4735 and then Chars
(Nam
) = Chars
(Prefix
(Expr
))
4738 ("address for & is self-referencing", Prefix
(Expr
), Ent
);
4742 -- Not that special case, carry on with analysis of expression
4744 Analyze_And_Resolve
(Expr
, RTE
(RE_Address
));
4746 -- Even when ignoring rep clauses we need to indicate that the
4747 -- entity has an address clause and thus it is legal to declare
4748 -- it imported. Freeze will get rid of the address clause later.
4750 if Ignore_Rep_Clauses
then
4751 if Ekind_In
(U_Ent
, E_Variable
, E_Constant
) then
4752 Record_Rep_Item
(U_Ent
, N
);
4758 if Duplicate_Clause
then
4761 -- Case of address clause for subprogram
4763 elsif Is_Subprogram
(U_Ent
) then
4764 if Has_Homonym
(U_Ent
) then
4766 ("address clause cannot be given for overloaded "
4767 & "subprogram", Nam
);
4771 -- For subprograms, all address clauses are permitted, and we
4772 -- mark the subprogram as having a deferred freeze so that Gigi
4773 -- will not elaborate it too soon.
4775 -- Above needs more comments, what is too soon about???
4777 Set_Has_Delayed_Freeze
(U_Ent
);
4779 -- Case of address clause for entry
4781 elsif Ekind
(U_Ent
) = E_Entry
then
4782 if Nkind
(Parent
(N
)) = N_Task_Body
then
4784 ("entry address must be specified in task spec", Nam
);
4788 -- For entries, we require a constant address
4790 Check_Constant_Address_Clause
(Expr
, U_Ent
);
4792 -- Special checks for task types
4794 if Is_Task_Type
(Scope
(U_Ent
))
4795 and then Comes_From_Source
(Scope
(U_Ent
))
4798 ("??entry address declared for entry in task type", N
);
4800 ("\??only one task can be declared of this type", N
);
4803 -- Entry address clauses are obsolescent
4805 Check_Restriction
(No_Obsolescent_Features
, N
);
4807 if Warn_On_Obsolescent_Feature
then
4809 ("?j?attaching interrupt to task entry is an obsolescent "
4810 & "feature (RM J.7.1)", N
);
4812 ("\?j?use interrupt procedure instead", N
);
4815 -- Case of an address clause for a controlled object which we
4816 -- consider to be erroneous.
4818 elsif Is_Controlled
(Etype
(U_Ent
))
4819 or else Has_Controlled_Component
(Etype
(U_Ent
))
4822 ("??controlled object& must not be overlaid", Nam
, U_Ent
);
4824 ("\??Program_Error will be raised at run time", Nam
);
4825 Insert_Action
(Declaration_Node
(U_Ent
),
4826 Make_Raise_Program_Error
(Loc
,
4827 Reason
=> PE_Overlaid_Controlled_Object
));
4830 -- Case of address clause for a (non-controlled) object
4832 elsif Ekind_In
(U_Ent
, E_Variable
, E_Constant
) then
4834 Expr
: constant Node_Id
:= Expression
(N
);
4839 -- Exported variables cannot have an address clause, because
4840 -- this cancels the effect of the pragma Export.
4842 if Is_Exported
(U_Ent
) then
4844 ("cannot export object with address clause", Nam
);
4848 Find_Overlaid_Entity
(N
, O_Ent
, Off
);
4850 if Present
(O_Ent
) then
4852 -- If the object overlays a constant object, mark it so
4854 if Is_Constant_Object
(O_Ent
) then
4855 Set_Overlays_Constant
(U_Ent
);
4858 -- If the address clause is of the form:
4860 -- for X'Address use Y'Address;
4864 -- C : constant Address := Y'Address;
4866 -- for X'Address use C;
4868 -- then we make an entry in the table to check the size
4869 -- and alignment of the overlaying variable. But we defer
4870 -- this check till after code generation to take full
4871 -- advantage of the annotation done by the back end.
4873 -- If the entity has a generic type, the check will be
4874 -- performed in the instance if the actual type justifies
4875 -- it, and we do not insert the clause in the table to
4876 -- prevent spurious warnings.
4878 -- Note: we used to test Comes_From_Source and only give
4879 -- this warning for source entities, but we have removed
4880 -- this test. It really seems bogus to generate overlays
4881 -- that would trigger this warning in generated code.
4882 -- Furthermore, by removing the test, we handle the
4883 -- aspect case properly.
4885 if Is_Object
(O_Ent
)
4886 and then not Is_Generic_Type
(Etype
(U_Ent
))
4887 and then Address_Clause_Overlay_Warnings
4889 Address_Clause_Checks
.Append
4890 ((N
, U_Ent
, No_Uint
, O_Ent
, Off
));
4893 -- If this is not an overlay, mark a variable as being
4894 -- volatile to prevent unwanted optimizations. It's a
4895 -- conservative interpretation of RM 13.3(19) for the
4896 -- cases where the compiler cannot detect potential
4897 -- aliasing issues easily and it also covers the case
4898 -- of an absolute address where the volatile aspect is
4899 -- kind of implicit.
4901 if Ekind
(U_Ent
) = E_Variable
then
4902 Set_Treat_As_Volatile
(U_Ent
);
4905 -- Make an entry in the table for an absolute address as
4906 -- above to check that the value is compatible with the
4907 -- alignment of the object.
4910 Addr
: constant Node_Id
:= Address_Value
(Expr
);
4912 if Compile_Time_Known_Value
(Addr
)
4913 and then Address_Clause_Overlay_Warnings
4915 Address_Clause_Checks
.Append
4916 ((N
, U_Ent
, Expr_Value
(Addr
), Empty
, False));
4921 -- Overlaying controlled objects is erroneous. Emit warning
4922 -- but continue analysis because program is itself legal,
4923 -- and back end must see address clause.
4926 and then (Has_Controlled_Component
(Etype
(O_Ent
))
4927 or else Is_Controlled
(Etype
(O_Ent
)))
4928 and then not Inside_A_Generic
4931 ("??cannot use overlays with controlled objects", Expr
);
4933 ("\??Program_Error will be raised at run time", Expr
);
4934 Insert_Action
(Declaration_Node
(U_Ent
),
4935 Make_Raise_Program_Error
(Loc
,
4936 Reason
=> PE_Overlaid_Controlled_Object
));
4938 -- Issue an unconditional warning for a constant overlaying
4939 -- a variable. For the reverse case, we will issue it only
4940 -- if the variable is modified.
4942 elsif Ekind
(U_Ent
) = E_Constant
4943 and then Present
(O_Ent
)
4944 and then not Overlays_Constant
(U_Ent
)
4945 and then Address_Clause_Overlay_Warnings
4947 Error_Msg_N
("??constant overlays a variable", Expr
);
4949 -- Imported variables can have an address clause, but then
4950 -- the import is pretty meaningless except to suppress
4951 -- initializations, so we do not need such variables to
4952 -- be statically allocated (and in fact it causes trouble
4953 -- if the address clause is a local value).
4955 elsif Is_Imported
(U_Ent
) then
4956 Set_Is_Statically_Allocated
(U_Ent
, False);
4959 -- We mark a possible modification of a variable with an
4960 -- address clause, since it is likely aliasing is occurring.
4962 Note_Possible_Modification
(Nam
, Sure
=> False);
4964 -- Legality checks on the address clause for initialized
4965 -- objects is deferred until the freeze point, because
4966 -- a subsequent pragma might indicate that the object
4967 -- is imported and thus not initialized. Also, the address
4968 -- clause might involve entities that have yet to be
4971 Set_Has_Delayed_Freeze
(U_Ent
);
4973 -- If an initialization call has been generated for this
4974 -- object, it needs to be deferred to after the freeze node
4975 -- we have just now added, otherwise GIGI will see a
4976 -- reference to the variable (as actual to the IP call)
4977 -- before its definition.
4980 Init_Call
: constant Node_Id
:=
4981 Remove_Init_Call
(U_Ent
, N
);
4984 if Present
(Init_Call
) then
4985 Append_Freeze_Action
(U_Ent
, Init_Call
);
4987 -- Reset Initialization_Statements pointer so that
4988 -- if there is a pragma Import further down, it can
4989 -- clear any default initialization.
4991 Set_Initialization_Statements
(U_Ent
, Init_Call
);
4995 -- Entity has delayed freeze, so we will generate an
4996 -- alignment check at the freeze point unless suppressed.
4998 if not Range_Checks_Suppressed
(U_Ent
)
4999 and then not Alignment_Checks_Suppressed
(U_Ent
)
5001 Set_Check_Address_Alignment
(N
);
5004 -- Kill the size check code, since we are not allocating
5005 -- the variable, it is somewhere else.
5007 Kill_Size_Check_Code
(U_Ent
);
5010 -- Not a valid entity for an address clause
5013 Error_Msg_N
("address cannot be given for &", Nam
);
5021 -- Alignment attribute definition clause
5023 when Attribute_Alignment
=> Alignment
: declare
5024 Align
: constant Uint
:= Get_Alignment_Value
(Expr
);
5025 Max_Align
: constant Uint
:= UI_From_Int
(Maximum_Alignment
);
5030 if not Is_Type
(U_Ent
)
5031 and then Ekind
(U_Ent
) /= E_Variable
5032 and then Ekind
(U_Ent
) /= E_Constant
5034 Error_Msg_N
("alignment cannot be given for &", Nam
);
5036 elsif Duplicate_Clause
then
5039 elsif Align
/= No_Uint
then
5040 Set_Has_Alignment_Clause
(U_Ent
);
5042 -- Tagged type case, check for attempt to set alignment to a
5043 -- value greater than Max_Align, and reset if so. This error
5044 -- is suppressed in ASIS mode to allow for different ASIS
5045 -- back ends or ASIS-based tools to query the illegal clause.
5047 if Is_Tagged_Type
(U_Ent
)
5048 and then Align
> Max_Align
5049 and then not ASIS_Mode
5052 ("alignment for & set to Maximum_Aligment??", Nam
);
5053 Set_Alignment
(U_Ent
, Max_Align
);
5058 Set_Alignment
(U_Ent
, Align
);
5061 -- For an array type, U_Ent is the first subtype. In that case,
5062 -- also set the alignment of the anonymous base type so that
5063 -- other subtypes (such as the itypes for aggregates of the
5064 -- type) also receive the expected alignment.
5066 if Is_Array_Type
(U_Ent
) then
5067 Set_Alignment
(Base_Type
(U_Ent
), Align
);
5076 -- Bit_Order attribute definition clause
5078 when Attribute_Bit_Order
=> Bit_Order
: declare
5080 if not Is_Record_Type
(U_Ent
) then
5082 ("Bit_Order can only be defined for record type", Nam
);
5084 elsif Duplicate_Clause
then
5088 Analyze_And_Resolve
(Expr
, RTE
(RE_Bit_Order
));
5090 if Etype
(Expr
) = Any_Type
then
5093 elsif not Is_OK_Static_Expression
(Expr
) then
5094 Flag_Non_Static_Expr
5095 ("Bit_Order requires static expression!", Expr
);
5098 if (Expr_Value
(Expr
) = 0) /= Bytes_Big_Endian
then
5099 Set_Reverse_Bit_Order
(Base_Type
(U_Ent
), True);
5105 --------------------
5106 -- Component_Size --
5107 --------------------
5109 -- Component_Size attribute definition clause
5111 when Attribute_Component_Size
=> Component_Size_Case
: declare
5112 Csize
: constant Uint
:= Static_Integer
(Expr
);
5116 New_Ctyp
: Entity_Id
;
5120 if not Is_Array_Type
(U_Ent
) then
5121 Error_Msg_N
("component size requires array type", Nam
);
5125 Btype
:= Base_Type
(U_Ent
);
5126 Ctyp
:= Component_Type
(Btype
);
5128 if Duplicate_Clause
then
5131 elsif Rep_Item_Too_Early
(Btype
, N
) then
5134 elsif Csize
/= No_Uint
then
5135 Check_Size
(Expr
, Ctyp
, Csize
, Biased
);
5137 -- For the biased case, build a declaration for a subtype that
5138 -- will be used to represent the biased subtype that reflects
5139 -- the biased representation of components. We need the subtype
5140 -- to get proper conversions on referencing elements of the
5145 Make_Defining_Identifier
(Loc
,
5147 New_External_Name
(Chars
(U_Ent
), 'C', 0, 'T'));
5150 Make_Subtype_Declaration
(Loc
,
5151 Defining_Identifier
=> New_Ctyp
,
5152 Subtype_Indication
=>
5153 New_Occurrence_Of
(Component_Type
(Btype
), Loc
));
5155 Set_Parent
(Decl
, N
);
5156 Analyze
(Decl
, Suppress
=> All_Checks
);
5158 Set_Has_Delayed_Freeze
(New_Ctyp
, False);
5159 Set_Esize
(New_Ctyp
, Csize
);
5160 Set_RM_Size
(New_Ctyp
, Csize
);
5161 Init_Alignment
(New_Ctyp
);
5162 Set_Is_Itype
(New_Ctyp
, True);
5163 Set_Associated_Node_For_Itype
(New_Ctyp
, U_Ent
);
5165 Set_Component_Type
(Btype
, New_Ctyp
);
5166 Set_Biased
(New_Ctyp
, N
, "component size clause");
5169 Set_Component_Size
(Btype
, Csize
);
5171 -- Deal with warning on overridden size
5173 if Warn_On_Overridden_Size
5174 and then Has_Size_Clause
(Ctyp
)
5175 and then RM_Size
(Ctyp
) /= Csize
5178 ("component size overrides size clause for&?S?", N
, Ctyp
);
5181 Set_Has_Component_Size_Clause
(Btype
, True);
5182 Set_Has_Non_Standard_Rep
(Btype
, True);
5184 end Component_Size_Case
;
5186 -----------------------
5187 -- Constant_Indexing --
5188 -----------------------
5190 when Attribute_Constant_Indexing
=>
5191 Check_Indexing_Functions
;
5197 when Attribute_CPU
=> CPU
:
5199 -- CPU attribute definition clause not allowed except from aspect
5202 if From_Aspect_Specification
(N
) then
5203 if not Is_Task_Type
(U_Ent
) then
5204 Error_Msg_N
("CPU can only be defined for task", Nam
);
5206 elsif Duplicate_Clause
then
5210 -- The expression must be analyzed in the special manner
5211 -- described in "Handling of Default and Per-Object
5212 -- Expressions" in sem.ads.
5214 -- The visibility to the discriminants must be restored
5216 Push_Scope_And_Install_Discriminants
(U_Ent
);
5217 Preanalyze_Spec_Expression
(Expr
, RTE
(RE_CPU_Range
));
5218 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
5220 if not Is_OK_Static_Expression
(Expr
) then
5221 Check_Restriction
(Static_Priorities
, Expr
);
5227 ("attribute& cannot be set with definition clause", N
);
5231 ----------------------
5232 -- Default_Iterator --
5233 ----------------------
5235 when Attribute_Default_Iterator
=> Default_Iterator
: declare
5240 -- If target type is untagged, further checks are irrelevant
5242 if not Is_Tagged_Type
(U_Ent
) then
5244 ("aspect Default_Iterator applies to tagged type", Nam
);
5248 Check_Iterator_Functions
;
5252 if not Is_Entity_Name
(Expr
)
5253 or else Ekind
(Entity
(Expr
)) /= E_Function
5255 Error_Msg_N
("aspect Iterator must be a function", Expr
);
5258 Func
:= Entity
(Expr
);
5261 -- The type of the first parameter must be T, T'class, or a
5262 -- corresponding access type (5.5.1 (8/3). If function is
5263 -- parameterless label type accordingly.
5265 if No
(First_Formal
(Func
)) then
5268 Typ
:= Etype
(First_Formal
(Func
));
5272 or else Typ
= Class_Wide_Type
(U_Ent
)
5273 or else (Is_Access_Type
(Typ
)
5274 and then Designated_Type
(Typ
) = U_Ent
)
5275 or else (Is_Access_Type
(Typ
)
5276 and then Designated_Type
(Typ
) =
5277 Class_Wide_Type
(U_Ent
))
5283 ("Default Iterator must be a primitive of&", Func
, U_Ent
);
5285 end Default_Iterator
;
5287 ------------------------
5288 -- Dispatching_Domain --
5289 ------------------------
5291 when Attribute_Dispatching_Domain
=> Dispatching_Domain
:
5293 -- Dispatching_Domain attribute definition clause not allowed
5294 -- except from aspect specification.
5296 if From_Aspect_Specification
(N
) then
5297 if not Is_Task_Type
(U_Ent
) then
5299 ("Dispatching_Domain can only be defined for task", Nam
);
5301 elsif Duplicate_Clause
then
5305 -- The expression must be analyzed in the special manner
5306 -- described in "Handling of Default and Per-Object
5307 -- Expressions" in sem.ads.
5309 -- The visibility to the discriminants must be restored
5311 Push_Scope_And_Install_Discriminants
(U_Ent
);
5313 Preanalyze_Spec_Expression
5314 (Expr
, RTE
(RE_Dispatching_Domain
));
5316 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
5321 ("attribute& cannot be set with definition clause", N
);
5323 end Dispatching_Domain
;
5329 when Attribute_External_Tag
=> External_Tag
:
5331 if not Is_Tagged_Type
(U_Ent
) then
5332 Error_Msg_N
("should be a tagged type", Nam
);
5335 if Duplicate_Clause
then
5339 Analyze_And_Resolve
(Expr
, Standard_String
);
5341 if not Is_OK_Static_Expression
(Expr
) then
5342 Flag_Non_Static_Expr
5343 ("static string required for tag name!", Nam
);
5346 if not Is_Library_Level_Entity
(U_Ent
) then
5348 ("??non-unique external tag supplied for &", N
, U_Ent
);
5350 ("\??same external tag applies to all subprogram calls",
5353 ("\??corresponding internal tag cannot be obtained", N
);
5358 --------------------------
5359 -- Implicit_Dereference --
5360 --------------------------
5362 when Attribute_Implicit_Dereference
=>
5364 -- Legality checks already performed at the point of the type
5365 -- declaration, aspect is not delayed.
5373 when Attribute_Input
=>
5374 Analyze_Stream_TSS_Definition
(TSS_Stream_Input
);
5375 Set_Has_Specified_Stream_Input
(Ent
);
5377 ------------------------
5378 -- Interrupt_Priority --
5379 ------------------------
5381 when Attribute_Interrupt_Priority
=> Interrupt_Priority
:
5383 -- Interrupt_Priority attribute definition clause not allowed
5384 -- except from aspect specification.
5386 if From_Aspect_Specification
(N
) then
5387 if not Is_Concurrent_Type
(U_Ent
) then
5389 ("Interrupt_Priority can only be defined for task and "
5390 & "protected object", Nam
);
5392 elsif Duplicate_Clause
then
5396 -- The expression must be analyzed in the special manner
5397 -- described in "Handling of Default and Per-Object
5398 -- Expressions" in sem.ads.
5400 -- The visibility to the discriminants must be restored
5402 Push_Scope_And_Install_Discriminants
(U_Ent
);
5404 Preanalyze_Spec_Expression
5405 (Expr
, RTE
(RE_Interrupt_Priority
));
5407 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
5409 -- Check the No_Task_At_Interrupt_Priority restriction
5411 if Is_Task_Type
(U_Ent
) then
5412 Check_Restriction
(No_Task_At_Interrupt_Priority
, N
);
5418 ("attribute& cannot be set with definition clause", N
);
5420 end Interrupt_Priority
;
5426 when Attribute_Iterable
=>
5429 if Nkind
(Expr
) /= N_Aggregate
then
5430 Error_Msg_N
("aspect Iterable must be an aggregate", Expr
);
5437 Assoc
:= First
(Component_Associations
(Expr
));
5438 while Present
(Assoc
) loop
5439 if not Is_Entity_Name
(Expression
(Assoc
)) then
5440 Error_Msg_N
("value must be a function", Assoc
);
5447 ----------------------
5448 -- Iterator_Element --
5449 ----------------------
5451 when Attribute_Iterator_Element
=>
5454 if not Is_Entity_Name
(Expr
)
5455 or else not Is_Type
(Entity
(Expr
))
5457 Error_Msg_N
("aspect Iterator_Element must be a type", Expr
);
5464 -- Machine radix attribute definition clause
5466 when Attribute_Machine_Radix
=> Machine_Radix
: declare
5467 Radix
: constant Uint
:= Static_Integer
(Expr
);
5470 if not Is_Decimal_Fixed_Point_Type
(U_Ent
) then
5471 Error_Msg_N
("decimal fixed-point type expected for &", Nam
);
5473 elsif Duplicate_Clause
then
5476 elsif Radix
/= No_Uint
then
5477 Set_Has_Machine_Radix_Clause
(U_Ent
);
5478 Set_Has_Non_Standard_Rep
(Base_Type
(U_Ent
));
5483 elsif Radix
= 10 then
5484 Set_Machine_Radix_10
(U_Ent
);
5486 -- The following error is suppressed in ASIS mode to allow for
5487 -- different ASIS back ends or ASIS-based tools to query the
5490 elsif not ASIS_Mode
then
5491 Error_Msg_N
("machine radix value must be 2 or 10", Expr
);
5500 -- Object_Size attribute definition clause
5502 when Attribute_Object_Size
=> Object_Size
: declare
5503 Size
: constant Uint
:= Static_Integer
(Expr
);
5506 pragma Warnings
(Off
, Biased
);
5509 if not Is_Type
(U_Ent
) then
5510 Error_Msg_N
("Object_Size cannot be given for &", Nam
);
5512 elsif Duplicate_Clause
then
5516 Check_Size
(Expr
, U_Ent
, Size
, Biased
);
5518 -- The following errors are suppressed in ASIS mode to allow
5519 -- for different ASIS back ends or ASIS-based tools to query
5520 -- the illegal clause.
5525 elsif Is_Scalar_Type
(U_Ent
) then
5526 if Size
/= 8 and then Size
/= 16 and then Size
/= 32
5527 and then UI_Mod
(Size
, 64) /= 0
5530 ("Object_Size must be 8, 16, 32, or multiple of 64",
5534 elsif Size
mod 8 /= 0 then
5535 Error_Msg_N
("Object_Size must be a multiple of 8", Expr
);
5538 Set_Esize
(U_Ent
, Size
);
5539 Set_Has_Object_Size_Clause
(U_Ent
);
5540 Alignment_Check_For_Size_Change
(U_Ent
, Size
);
5548 when Attribute_Output
=>
5549 Analyze_Stream_TSS_Definition
(TSS_Stream_Output
);
5550 Set_Has_Specified_Stream_Output
(Ent
);
5556 when Attribute_Priority
=> Priority
:
5558 -- Priority attribute definition clause not allowed except from
5559 -- aspect specification.
5561 if From_Aspect_Specification
(N
) then
5562 if not (Is_Concurrent_Type
(U_Ent
)
5563 or else Ekind
(U_Ent
) = E_Procedure
)
5566 ("Priority can only be defined for task and protected "
5569 elsif Duplicate_Clause
then
5573 -- The expression must be analyzed in the special manner
5574 -- described in "Handling of Default and Per-Object
5575 -- Expressions" in sem.ads.
5577 -- The visibility to the discriminants must be restored
5579 Push_Scope_And_Install_Discriminants
(U_Ent
);
5580 Preanalyze_Spec_Expression
(Expr
, Standard_Integer
);
5581 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
5583 if not Is_OK_Static_Expression
(Expr
) then
5584 Check_Restriction
(Static_Priorities
, Expr
);
5590 ("attribute& cannot be set with definition clause", N
);
5598 when Attribute_Read
=>
5599 Analyze_Stream_TSS_Definition
(TSS_Stream_Read
);
5600 Set_Has_Specified_Stream_Read
(Ent
);
5602 --------------------------
5603 -- Scalar_Storage_Order --
5604 --------------------------
5606 -- Scalar_Storage_Order attribute definition clause
5608 when Attribute_Scalar_Storage_Order
=> Scalar_Storage_Order
: declare
5610 if not (Is_Record_Type
(U_Ent
) or else Is_Array_Type
(U_Ent
)) then
5612 ("Scalar_Storage_Order can only be defined for record or "
5613 & "array type", Nam
);
5615 elsif Duplicate_Clause
then
5619 Analyze_And_Resolve
(Expr
, RTE
(RE_Bit_Order
));
5621 if Etype
(Expr
) = Any_Type
then
5624 elsif not Is_OK_Static_Expression
(Expr
) then
5625 Flag_Non_Static_Expr
5626 ("Scalar_Storage_Order requires static expression!", Expr
);
5628 elsif (Expr_Value
(Expr
) = 0) /= Bytes_Big_Endian
then
5630 -- Here for the case of a non-default (i.e. non-confirming)
5631 -- Scalar_Storage_Order attribute definition.
5633 if Support_Nondefault_SSO_On_Target
then
5634 Set_Reverse_Storage_Order
(Base_Type
(U_Ent
), True);
5637 ("non-default Scalar_Storage_Order not supported on "
5642 -- Clear SSO default indications since explicit setting of the
5643 -- order overrides the defaults.
5645 Set_SSO_Set_Low_By_Default
(Base_Type
(U_Ent
), False);
5646 Set_SSO_Set_High_By_Default
(Base_Type
(U_Ent
), False);
5648 end Scalar_Storage_Order
;
5654 -- Size attribute definition clause
5656 when Attribute_Size
=> Size
: declare
5657 Size
: constant Uint
:= Static_Integer
(Expr
);
5664 if Duplicate_Clause
then
5667 elsif not Is_Type
(U_Ent
)
5668 and then Ekind
(U_Ent
) /= E_Variable
5669 and then Ekind
(U_Ent
) /= E_Constant
5671 Error_Msg_N
("size cannot be given for &", Nam
);
5673 elsif Is_Array_Type
(U_Ent
)
5674 and then not Is_Constrained
(U_Ent
)
5677 ("size cannot be given for unconstrained array", Nam
);
5679 elsif Size
/= No_Uint
then
5680 if Is_Type
(U_Ent
) then
5683 Etyp
:= Etype
(U_Ent
);
5686 -- Check size, note that Gigi is in charge of checking that the
5687 -- size of an array or record type is OK. Also we do not check
5688 -- the size in the ordinary fixed-point case, since it is too
5689 -- early to do so (there may be subsequent small clause that
5690 -- affects the size). We can check the size if a small clause
5691 -- has already been given.
5693 if not Is_Ordinary_Fixed_Point_Type
(U_Ent
)
5694 or else Has_Small_Clause
(U_Ent
)
5696 Check_Size
(Expr
, Etyp
, Size
, Biased
);
5697 Set_Biased
(U_Ent
, N
, "size clause", Biased
);
5700 -- For types set RM_Size and Esize if possible
5702 if Is_Type
(U_Ent
) then
5703 Set_RM_Size
(U_Ent
, Size
);
5705 -- For elementary types, increase Object_Size to power of 2,
5706 -- but not less than a storage unit in any case (normally
5707 -- this means it will be byte addressable).
5709 -- For all other types, nothing else to do, we leave Esize
5710 -- (object size) unset, the back end will set it from the
5711 -- size and alignment in an appropriate manner.
5713 -- In both cases, we check whether the alignment must be
5714 -- reset in the wake of the size change.
5716 if Is_Elementary_Type
(U_Ent
) then
5717 if Size
<= System_Storage_Unit
then
5718 Init_Esize
(U_Ent
, System_Storage_Unit
);
5719 elsif Size
<= 16 then
5720 Init_Esize
(U_Ent
, 16);
5721 elsif Size
<= 32 then
5722 Init_Esize
(U_Ent
, 32);
5724 Set_Esize
(U_Ent
, (Size
+ 63) / 64 * 64);
5727 Alignment_Check_For_Size_Change
(U_Ent
, Esize
(U_Ent
));
5729 Alignment_Check_For_Size_Change
(U_Ent
, Size
);
5732 -- For objects, set Esize only
5735 -- The following error is suppressed in ASIS mode to allow
5736 -- for different ASIS back ends or ASIS-based tools to query
5737 -- the illegal clause.
5739 if Is_Elementary_Type
(Etyp
)
5740 and then Size
/= System_Storage_Unit
5741 and then Size
/= System_Storage_Unit
* 2
5742 and then Size
/= System_Storage_Unit
* 4
5743 and then Size
/= System_Storage_Unit
* 8
5744 and then not ASIS_Mode
5746 Error_Msg_Uint_1
:= UI_From_Int
(System_Storage_Unit
);
5747 Error_Msg_Uint_2
:= Error_Msg_Uint_1
* 8;
5749 ("size for primitive object must be a power of 2 in "
5750 & "the range ^-^", N
);
5753 Set_Esize
(U_Ent
, Size
);
5756 Set_Has_Size_Clause
(U_Ent
);
5764 -- Small attribute definition clause
5766 when Attribute_Small
=> Small
: declare
5767 Implicit_Base
: constant Entity_Id
:= Base_Type
(U_Ent
);
5771 Analyze_And_Resolve
(Expr
, Any_Real
);
5773 if Etype
(Expr
) = Any_Type
then
5776 elsif not Is_OK_Static_Expression
(Expr
) then
5777 Flag_Non_Static_Expr
5778 ("small requires static expression!", Expr
);
5782 Small
:= Expr_Value_R
(Expr
);
5784 if Small
<= Ureal_0
then
5785 Error_Msg_N
("small value must be greater than zero", Expr
);
5791 if not Is_Ordinary_Fixed_Point_Type
(U_Ent
) then
5793 ("small requires an ordinary fixed point type", Nam
);
5795 elsif Has_Small_Clause
(U_Ent
) then
5796 Error_Msg_N
("small already given for &", Nam
);
5798 elsif Small
> Delta_Value
(U_Ent
) then
5800 ("small value must not be greater than delta value", Nam
);
5803 Set_Small_Value
(U_Ent
, Small
);
5804 Set_Small_Value
(Implicit_Base
, Small
);
5805 Set_Has_Small_Clause
(U_Ent
);
5806 Set_Has_Small_Clause
(Implicit_Base
);
5807 Set_Has_Non_Standard_Rep
(Implicit_Base
);
5815 -- Storage_Pool attribute definition clause
5817 when Attribute_Storage_Pool | Attribute_Simple_Storage_Pool
=> declare
5822 if Ekind
(U_Ent
) = E_Access_Subprogram_Type
then
5824 ("storage pool cannot be given for access-to-subprogram type",
5829 Ekind_In
(U_Ent
, E_Access_Type
, E_General_Access_Type
)
5832 ("storage pool can only be given for access types", Nam
);
5835 elsif Is_Derived_Type
(U_Ent
) then
5837 ("storage pool cannot be given for a derived access type",
5840 elsif Duplicate_Clause
then
5843 elsif Present
(Associated_Storage_Pool
(U_Ent
)) then
5844 Error_Msg_N
("storage pool already given for &", Nam
);
5848 -- Check for Storage_Size previously given
5851 SS
: constant Node_Id
:=
5852 Get_Attribute_Definition_Clause
5853 (U_Ent
, Attribute_Storage_Size
);
5855 if Present
(SS
) then
5856 Check_Pool_Size_Clash
(U_Ent
, N
, SS
);
5860 -- Storage_Pool case
5862 if Id
= Attribute_Storage_Pool
then
5864 (Expr
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
5866 -- In the Simple_Storage_Pool case, we allow a variable of any
5867 -- simple storage pool type, so we Resolve without imposing an
5871 Analyze_And_Resolve
(Expr
);
5873 if not Present
(Get_Rep_Pragma
5874 (Etype
(Expr
), Name_Simple_Storage_Pool_Type
))
5877 ("expression must be of a simple storage pool type", Expr
);
5881 if not Denotes_Variable
(Expr
) then
5882 Error_Msg_N
("storage pool must be a variable", Expr
);
5886 if Nkind
(Expr
) = N_Type_Conversion
then
5887 T
:= Etype
(Expression
(Expr
));
5892 -- The Stack_Bounded_Pool is used internally for implementing
5893 -- access types with a Storage_Size. Since it only work properly
5894 -- when used on one specific type, we need to check that it is not
5895 -- hijacked improperly:
5897 -- type T is access Integer;
5898 -- for T'Storage_Size use n;
5899 -- type Q is access Float;
5900 -- for Q'Storage_Size use T'Storage_Size; -- incorrect
5902 if RTE_Available
(RE_Stack_Bounded_Pool
)
5903 and then Base_Type
(T
) = RTE
(RE_Stack_Bounded_Pool
)
5905 Error_Msg_N
("non-shareable internal Pool", Expr
);
5909 -- If the argument is a name that is not an entity name, then
5910 -- we construct a renaming operation to define an entity of
5911 -- type storage pool.
5913 if not Is_Entity_Name
(Expr
)
5914 and then Is_Object_Reference
(Expr
)
5916 Pool
:= Make_Temporary
(Loc
, 'P', Expr
);
5919 Rnode
: constant Node_Id
:=
5920 Make_Object_Renaming_Declaration
(Loc
,
5921 Defining_Identifier
=> Pool
,
5923 New_Occurrence_Of
(Etype
(Expr
), Loc
),
5927 -- If the attribute definition clause comes from an aspect
5928 -- clause, then insert the renaming before the associated
5929 -- entity's declaration, since the attribute clause has
5930 -- not yet been appended to the declaration list.
5932 if From_Aspect_Specification
(N
) then
5933 Insert_Before
(Parent
(Entity
(N
)), Rnode
);
5935 Insert_Before
(N
, Rnode
);
5939 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
5942 elsif Is_Entity_Name
(Expr
) then
5943 Pool
:= Entity
(Expr
);
5945 -- If pool is a renamed object, get original one. This can
5946 -- happen with an explicit renaming, and within instances.
5948 while Present
(Renamed_Object
(Pool
))
5949 and then Is_Entity_Name
(Renamed_Object
(Pool
))
5951 Pool
:= Entity
(Renamed_Object
(Pool
));
5954 if Present
(Renamed_Object
(Pool
))
5955 and then Nkind
(Renamed_Object
(Pool
)) = N_Type_Conversion
5956 and then Is_Entity_Name
(Expression
(Renamed_Object
(Pool
)))
5958 Pool
:= Entity
(Expression
(Renamed_Object
(Pool
)));
5961 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
5963 elsif Nkind
(Expr
) = N_Type_Conversion
5964 and then Is_Entity_Name
(Expression
(Expr
))
5965 and then Nkind
(Original_Node
(Expr
)) = N_Attribute_Reference
5967 Pool
:= Entity
(Expression
(Expr
));
5968 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
5971 Error_Msg_N
("incorrect reference to a Storage Pool", Expr
);
5980 -- Storage_Size attribute definition clause
5982 when Attribute_Storage_Size
=> Storage_Size
: declare
5983 Btype
: constant Entity_Id
:= Base_Type
(U_Ent
);
5986 if Is_Task_Type
(U_Ent
) then
5988 -- Check obsolescent (but never obsolescent if from aspect)
5990 if not From_Aspect_Specification
(N
) then
5991 Check_Restriction
(No_Obsolescent_Features
, N
);
5993 if Warn_On_Obsolescent_Feature
then
5995 ("?j?storage size clause for task is an obsolescent "
5996 & "feature (RM J.9)", N
);
5997 Error_Msg_N
("\?j?use Storage_Size pragma instead", N
);
6004 if not Is_Access_Type
(U_Ent
)
6005 and then Ekind
(U_Ent
) /= E_Task_Type
6007 Error_Msg_N
("storage size cannot be given for &", Nam
);
6009 elsif Is_Access_Type
(U_Ent
) and Is_Derived_Type
(U_Ent
) then
6011 ("storage size cannot be given for a derived access type",
6014 elsif Duplicate_Clause
then
6018 Analyze_And_Resolve
(Expr
, Any_Integer
);
6020 if Is_Access_Type
(U_Ent
) then
6022 -- Check for Storage_Pool previously given
6025 SP
: constant Node_Id
:=
6026 Get_Attribute_Definition_Clause
6027 (U_Ent
, Attribute_Storage_Pool
);
6030 if Present
(SP
) then
6031 Check_Pool_Size_Clash
(U_Ent
, SP
, N
);
6035 -- Special case of for x'Storage_Size use 0
6037 if Is_OK_Static_Expression
(Expr
)
6038 and then Expr_Value
(Expr
) = 0
6040 Set_No_Pool_Assigned
(Btype
);
6044 Set_Has_Storage_Size_Clause
(Btype
);
6052 when Attribute_Stream_Size
=> Stream_Size
: declare
6053 Size
: constant Uint
:= Static_Integer
(Expr
);
6056 if Ada_Version
<= Ada_95
then
6057 Check_Restriction
(No_Implementation_Attributes
, N
);
6060 if Duplicate_Clause
then
6063 elsif Is_Elementary_Type
(U_Ent
) then
6065 -- The following errors are suppressed in ASIS mode to allow
6066 -- for different ASIS back ends or ASIS-based tools to query
6067 -- the illegal clause.
6072 elsif Size
/= System_Storage_Unit
6073 and then Size
/= System_Storage_Unit
* 2
6074 and then Size
/= System_Storage_Unit
* 4
6075 and then Size
/= System_Storage_Unit
* 8
6077 Error_Msg_Uint_1
:= UI_From_Int
(System_Storage_Unit
);
6079 ("stream size for elementary type must be a power of 2 "
6080 & "and at least ^", N
);
6082 elsif RM_Size
(U_Ent
) > Size
then
6083 Error_Msg_Uint_1
:= RM_Size
(U_Ent
);
6085 ("stream size for elementary type must be a power of 2 "
6086 & "and at least ^", N
);
6089 Set_Has_Stream_Size_Clause
(U_Ent
);
6092 Error_Msg_N
("Stream_Size cannot be given for &", Nam
);
6100 -- Value_Size attribute definition clause
6102 when Attribute_Value_Size
=> Value_Size
: declare
6103 Size
: constant Uint
:= Static_Integer
(Expr
);
6107 if not Is_Type
(U_Ent
) then
6108 Error_Msg_N
("Value_Size cannot be given for &", Nam
);
6110 elsif Duplicate_Clause
then
6113 elsif Is_Array_Type
(U_Ent
)
6114 and then not Is_Constrained
(U_Ent
)
6117 ("Value_Size cannot be given for unconstrained array", Nam
);
6120 if Is_Elementary_Type
(U_Ent
) then
6121 Check_Size
(Expr
, U_Ent
, Size
, Biased
);
6122 Set_Biased
(U_Ent
, N
, "value size clause", Biased
);
6125 Set_RM_Size
(U_Ent
, Size
);
6129 -----------------------
6130 -- Variable_Indexing --
6131 -----------------------
6133 when Attribute_Variable_Indexing
=>
6134 Check_Indexing_Functions
;
6140 when Attribute_Write
=>
6141 Analyze_Stream_TSS_Definition
(TSS_Stream_Write
);
6142 Set_Has_Specified_Stream_Write
(Ent
);
6144 -- All other attributes cannot be set
6148 ("attribute& cannot be set with definition clause", N
);
6151 -- The test for the type being frozen must be performed after any
6152 -- expression the clause has been analyzed since the expression itself
6153 -- might cause freezing that makes the clause illegal.
6155 if Rep_Item_Too_Late
(U_Ent
, N
, FOnly
) then
6158 end Analyze_Attribute_Definition_Clause
;
6160 ----------------------------
6161 -- Analyze_Code_Statement --
6162 ----------------------------
6164 procedure Analyze_Code_Statement
(N
: Node_Id
) is
6165 HSS
: constant Node_Id
:= Parent
(N
);
6166 SBody
: constant Node_Id
:= Parent
(HSS
);
6167 Subp
: constant Entity_Id
:= Current_Scope
;
6174 -- Accept foreign code statements for CodePeer. The analysis is skipped
6175 -- to avoid rejecting unrecognized constructs.
6177 if CodePeer_Mode
then
6182 -- Analyze and check we get right type, note that this implements the
6183 -- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that is
6184 -- the only way that Asm_Insn could possibly be visible.
6186 Analyze_And_Resolve
(Expression
(N
));
6188 if Etype
(Expression
(N
)) = Any_Type
then
6190 elsif Etype
(Expression
(N
)) /= RTE
(RE_Asm_Insn
) then
6191 Error_Msg_N
("incorrect type for code statement", N
);
6195 Check_Code_Statement
(N
);
6197 -- Make sure we appear in the handled statement sequence of a subprogram
6200 if Nkind
(HSS
) /= N_Handled_Sequence_Of_Statements
6201 or else Nkind
(SBody
) /= N_Subprogram_Body
6204 ("code statement can only appear in body of subprogram", N
);
6208 -- Do remaining checks (RM 13.8(3)) if not already done
6210 if not Is_Machine_Code_Subprogram
(Subp
) then
6211 Set_Is_Machine_Code_Subprogram
(Subp
);
6213 -- No exception handlers allowed
6215 if Present
(Exception_Handlers
(HSS
)) then
6217 ("exception handlers not permitted in machine code subprogram",
6218 First
(Exception_Handlers
(HSS
)));
6221 -- No declarations other than use clauses and pragmas (we allow
6222 -- certain internally generated declarations as well).
6224 Decl
:= First
(Declarations
(SBody
));
6225 while Present
(Decl
) loop
6226 DeclO
:= Original_Node
(Decl
);
6227 if Comes_From_Source
(DeclO
)
6228 and not Nkind_In
(DeclO
, N_Pragma
,
6229 N_Use_Package_Clause
,
6231 N_Implicit_Label_Declaration
)
6234 ("this declaration not allowed in machine code subprogram",
6241 -- No statements other than code statements, pragmas, and labels.
6242 -- Again we allow certain internally generated statements.
6244 -- In Ada 2012, qualified expressions are names, and the code
6245 -- statement is initially parsed as a procedure call.
6247 Stmt
:= First
(Statements
(HSS
));
6248 while Present
(Stmt
) loop
6249 StmtO
:= Original_Node
(Stmt
);
6251 -- A procedure call transformed into a code statement is OK
6253 if Ada_Version
>= Ada_2012
6254 and then Nkind
(StmtO
) = N_Procedure_Call_Statement
6255 and then Nkind
(Name
(StmtO
)) = N_Qualified_Expression
6259 elsif Comes_From_Source
(StmtO
)
6260 and then not Nkind_In
(StmtO
, N_Pragma
,
6265 ("this statement is not allowed in machine code subprogram",
6272 end Analyze_Code_Statement
;
6274 -----------------------------------------------
6275 -- Analyze_Enumeration_Representation_Clause --
6276 -----------------------------------------------
6278 procedure Analyze_Enumeration_Representation_Clause
(N
: Node_Id
) is
6279 Ident
: constant Node_Id
:= Identifier
(N
);
6280 Aggr
: constant Node_Id
:= Array_Aggregate
(N
);
6281 Enumtype
: Entity_Id
;
6288 Err
: Boolean := False;
6289 -- Set True to avoid cascade errors and crashes on incorrect source code
6291 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Universal_Integer
));
6292 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(Universal_Integer
));
6293 -- Allowed range of universal integer (= allowed range of enum lit vals)
6297 -- Minimum and maximum values of entries
6300 -- Pointer to node for literal providing max value
6303 if Ignore_Rep_Clauses
then
6304 Kill_Rep_Clause
(N
);
6308 -- Ignore enumeration rep clauses by default in CodePeer mode,
6309 -- unless -gnatd.I is specified, as a work around for potential false
6310 -- positive messages.
6312 if CodePeer_Mode
and not Debug_Flag_Dot_II
then
6316 -- First some basic error checks
6319 Enumtype
:= Entity
(Ident
);
6321 if Enumtype
= Any_Type
6322 or else Rep_Item_Too_Early
(Enumtype
, N
)
6326 Enumtype
:= Underlying_Type
(Enumtype
);
6329 if not Is_Enumeration_Type
(Enumtype
) then
6331 ("enumeration type required, found}",
6332 Ident
, First_Subtype
(Enumtype
));
6336 -- Ignore rep clause on generic actual type. This will already have
6337 -- been flagged on the template as an error, and this is the safest
6338 -- way to ensure we don't get a junk cascaded message in the instance.
6340 if Is_Generic_Actual_Type
(Enumtype
) then
6343 -- Type must be in current scope
6345 elsif Scope
(Enumtype
) /= Current_Scope
then
6346 Error_Msg_N
("type must be declared in this scope", Ident
);
6349 -- Type must be a first subtype
6351 elsif not Is_First_Subtype
(Enumtype
) then
6352 Error_Msg_N
("cannot give enumeration rep clause for subtype", N
);
6355 -- Ignore duplicate rep clause
6357 elsif Has_Enumeration_Rep_Clause
(Enumtype
) then
6358 Error_Msg_N
("duplicate enumeration rep clause ignored", N
);
6361 -- Don't allow rep clause for standard [wide_[wide_]]character
6363 elsif Is_Standard_Character_Type
(Enumtype
) then
6364 Error_Msg_N
("enumeration rep clause not allowed for this type", N
);
6367 -- Check that the expression is a proper aggregate (no parentheses)
6369 elsif Paren_Count
(Aggr
) /= 0 then
6371 ("extra parentheses surrounding aggregate not allowed",
6375 -- All tests passed, so set rep clause in place
6378 Set_Has_Enumeration_Rep_Clause
(Enumtype
);
6379 Set_Has_Enumeration_Rep_Clause
(Base_Type
(Enumtype
));
6382 -- Now we process the aggregate. Note that we don't use the normal
6383 -- aggregate code for this purpose, because we don't want any of the
6384 -- normal expansion activities, and a number of special semantic
6385 -- rules apply (including the component type being any integer type)
6387 Elit
:= First_Literal
(Enumtype
);
6389 -- First the positional entries if any
6391 if Present
(Expressions
(Aggr
)) then
6392 Expr
:= First
(Expressions
(Aggr
));
6393 while Present
(Expr
) loop
6395 Error_Msg_N
("too many entries in aggregate", Expr
);
6399 Val
:= Static_Integer
(Expr
);
6401 -- Err signals that we found some incorrect entries processing
6402 -- the list. The final checks for completeness and ordering are
6403 -- skipped in this case.
6405 if Val
= No_Uint
then
6408 elsif Val
< Lo
or else Hi
< Val
then
6409 Error_Msg_N
("value outside permitted range", Expr
);
6413 Set_Enumeration_Rep
(Elit
, Val
);
6414 Set_Enumeration_Rep_Expr
(Elit
, Expr
);
6420 -- Now process the named entries if present
6422 if Present
(Component_Associations
(Aggr
)) then
6423 Assoc
:= First
(Component_Associations
(Aggr
));
6424 while Present
(Assoc
) loop
6425 Choice
:= First
(Choices
(Assoc
));
6427 if Present
(Next
(Choice
)) then
6429 ("multiple choice not allowed here", Next
(Choice
));
6433 if Nkind
(Choice
) = N_Others_Choice
then
6434 Error_Msg_N
("others choice not allowed here", Choice
);
6437 elsif Nkind
(Choice
) = N_Range
then
6439 -- ??? should allow zero/one element range here
6441 Error_Msg_N
("range not allowed here", Choice
);
6445 Analyze_And_Resolve
(Choice
, Enumtype
);
6447 if Error_Posted
(Choice
) then
6452 if Is_Entity_Name
(Choice
)
6453 and then Is_Type
(Entity
(Choice
))
6455 Error_Msg_N
("subtype name not allowed here", Choice
);
6458 -- ??? should allow static subtype with zero/one entry
6460 elsif Etype
(Choice
) = Base_Type
(Enumtype
) then
6461 if not Is_OK_Static_Expression
(Choice
) then
6462 Flag_Non_Static_Expr
6463 ("non-static expression used for choice!", Choice
);
6467 Elit
:= Expr_Value_E
(Choice
);
6469 if Present
(Enumeration_Rep_Expr
(Elit
)) then
6471 Sloc
(Enumeration_Rep_Expr
(Elit
));
6473 ("representation for& previously given#",
6478 Set_Enumeration_Rep_Expr
(Elit
, Expression
(Assoc
));
6480 Expr
:= Expression
(Assoc
);
6481 Val
:= Static_Integer
(Expr
);
6483 if Val
= No_Uint
then
6486 elsif Val
< Lo
or else Hi
< Val
then
6487 Error_Msg_N
("value outside permitted range", Expr
);
6491 Set_Enumeration_Rep
(Elit
, Val
);
6501 -- Aggregate is fully processed. Now we check that a full set of
6502 -- representations was given, and that they are in range and in order.
6503 -- These checks are only done if no other errors occurred.
6509 Elit
:= First_Literal
(Enumtype
);
6510 while Present
(Elit
) loop
6511 if No
(Enumeration_Rep_Expr
(Elit
)) then
6512 Error_Msg_NE
("missing representation for&!", N
, Elit
);
6515 Val
:= Enumeration_Rep
(Elit
);
6517 if Min
= No_Uint
then
6521 if Val
/= No_Uint
then
6522 if Max
/= No_Uint
and then Val
<= Max
then
6524 ("enumeration value for& not ordered!",
6525 Enumeration_Rep_Expr
(Elit
), Elit
);
6528 Max_Node
:= Enumeration_Rep_Expr
(Elit
);
6532 -- If there is at least one literal whose representation is not
6533 -- equal to the Pos value, then note that this enumeration type
6534 -- has a non-standard representation.
6536 if Val
/= Enumeration_Pos
(Elit
) then
6537 Set_Has_Non_Standard_Rep
(Base_Type
(Enumtype
));
6544 -- Now set proper size information
6547 Minsize
: Uint
:= UI_From_Int
(Minimum_Size
(Enumtype
));
6550 if Has_Size_Clause
(Enumtype
) then
6552 -- All OK, if size is OK now
6554 if RM_Size
(Enumtype
) >= Minsize
then
6558 -- Try if we can get by with biasing
6561 UI_From_Int
(Minimum_Size
(Enumtype
, Biased
=> True));
6563 -- Error message if even biasing does not work
6565 if RM_Size
(Enumtype
) < Minsize
then
6566 Error_Msg_Uint_1
:= RM_Size
(Enumtype
);
6567 Error_Msg_Uint_2
:= Max
;
6569 ("previously given size (^) is too small "
6570 & "for this value (^)", Max_Node
);
6572 -- If biasing worked, indicate that we now have biased rep
6576 (Enumtype
, Size_Clause
(Enumtype
), "size clause");
6581 Set_RM_Size
(Enumtype
, Minsize
);
6582 Set_Enum_Esize
(Enumtype
);
6585 Set_RM_Size
(Base_Type
(Enumtype
), RM_Size
(Enumtype
));
6586 Set_Esize
(Base_Type
(Enumtype
), Esize
(Enumtype
));
6587 Set_Alignment
(Base_Type
(Enumtype
), Alignment
(Enumtype
));
6591 -- We repeat the too late test in case it froze itself
6593 if Rep_Item_Too_Late
(Enumtype
, N
) then
6596 end Analyze_Enumeration_Representation_Clause
;
6598 ----------------------------
6599 -- Analyze_Free_Statement --
6600 ----------------------------
6602 procedure Analyze_Free_Statement
(N
: Node_Id
) is
6604 Analyze
(Expression
(N
));
6605 end Analyze_Free_Statement
;
6607 ---------------------------
6608 -- Analyze_Freeze_Entity --
6609 ---------------------------
6611 procedure Analyze_Freeze_Entity
(N
: Node_Id
) is
6613 Freeze_Entity_Checks
(N
);
6614 end Analyze_Freeze_Entity
;
6616 -----------------------------------
6617 -- Analyze_Freeze_Generic_Entity --
6618 -----------------------------------
6620 procedure Analyze_Freeze_Generic_Entity
(N
: Node_Id
) is
6621 E
: constant Entity_Id
:= Entity
(N
);
6624 if not Is_Frozen
(E
) and then Has_Delayed_Aspects
(E
) then
6625 Analyze_Aspects_At_Freeze_Point
(E
);
6628 Freeze_Entity_Checks
(N
);
6629 end Analyze_Freeze_Generic_Entity
;
6631 ------------------------------------------
6632 -- Analyze_Record_Representation_Clause --
6633 ------------------------------------------
6635 -- Note: we check as much as we can here, but we can't do any checks
6636 -- based on the position values (e.g. overlap checks) until freeze time
6637 -- because especially in Ada 2005 (machine scalar mode), the processing
6638 -- for non-standard bit order can substantially change the positions.
6639 -- See procedure Check_Record_Representation_Clause (called from Freeze)
6640 -- for the remainder of this processing.
6642 procedure Analyze_Record_Representation_Clause
(N
: Node_Id
) is
6643 Ident
: constant Node_Id
:= Identifier
(N
);
6648 Hbit
: Uint
:= Uint_0
;
6652 Rectype
: Entity_Id
;
6655 function Is_Inherited
(Comp
: Entity_Id
) return Boolean;
6656 -- True if Comp is an inherited component in a record extension
6662 function Is_Inherited
(Comp
: Entity_Id
) return Boolean is
6663 Comp_Base
: Entity_Id
;
6666 if Ekind
(Rectype
) = E_Record_Subtype
then
6667 Comp_Base
:= Original_Record_Component
(Comp
);
6672 return Comp_Base
/= Original_Record_Component
(Comp_Base
);
6677 Is_Record_Extension
: Boolean;
6678 -- True if Rectype is a record extension
6680 CR_Pragma
: Node_Id
:= Empty
;
6681 -- Points to N_Pragma node if Complete_Representation pragma present
6683 -- Start of processing for Analyze_Record_Representation_Clause
6686 if Ignore_Rep_Clauses
then
6687 Kill_Rep_Clause
(N
);
6692 Rectype
:= Entity
(Ident
);
6694 if Rectype
= Any_Type
or else Rep_Item_Too_Early
(Rectype
, N
) then
6697 Rectype
:= Underlying_Type
(Rectype
);
6700 -- First some basic error checks
6702 if not Is_Record_Type
(Rectype
) then
6704 ("record type required, found}", Ident
, First_Subtype
(Rectype
));
6707 elsif Scope
(Rectype
) /= Current_Scope
then
6708 Error_Msg_N
("type must be declared in this scope", N
);
6711 elsif not Is_First_Subtype
(Rectype
) then
6712 Error_Msg_N
("cannot give record rep clause for subtype", N
);
6715 elsif Has_Record_Rep_Clause
(Rectype
) then
6716 Error_Msg_N
("duplicate record rep clause ignored", N
);
6719 elsif Rep_Item_Too_Late
(Rectype
, N
) then
6723 -- We know we have a first subtype, now possibly go to the anonymous
6724 -- base type to determine whether Rectype is a record extension.
6726 Recdef
:= Type_Definition
(Declaration_Node
(Base_Type
(Rectype
)));
6727 Is_Record_Extension
:=
6728 Nkind
(Recdef
) = N_Derived_Type_Definition
6729 and then Present
(Record_Extension_Part
(Recdef
));
6731 if Present
(Mod_Clause
(N
)) then
6733 Loc
: constant Source_Ptr
:= Sloc
(N
);
6734 M
: constant Node_Id
:= Mod_Clause
(N
);
6735 P
: constant List_Id
:= Pragmas_Before
(M
);
6739 pragma Warnings
(Off
, Mod_Val
);
6742 Check_Restriction
(No_Obsolescent_Features
, Mod_Clause
(N
));
6744 if Warn_On_Obsolescent_Feature
then
6746 ("?j?mod clause is an obsolescent feature (RM J.8)", N
);
6748 ("\?j?use alignment attribute definition clause instead", N
);
6755 -- In ASIS_Mode mode, expansion is disabled, but we must convert
6756 -- the Mod clause into an alignment clause anyway, so that the
6757 -- back end can compute and back-annotate properly the size and
6758 -- alignment of types that may include this record.
6760 -- This seems dubious, this destroys the source tree in a manner
6761 -- not detectable by ASIS ???
6763 if Operating_Mode
= Check_Semantics
and then ASIS_Mode
then
6765 Make_Attribute_Definition_Clause
(Loc
,
6766 Name
=> New_Occurrence_Of
(Base_Type
(Rectype
), Loc
),
6767 Chars
=> Name_Alignment
,
6768 Expression
=> Relocate_Node
(Expression
(M
)));
6770 Set_From_At_Mod
(AtM_Nod
);
6771 Insert_After
(N
, AtM_Nod
);
6772 Mod_Val
:= Get_Alignment_Value
(Expression
(AtM_Nod
));
6773 Set_Mod_Clause
(N
, Empty
);
6776 -- Get the alignment value to perform error checking
6778 Mod_Val
:= Get_Alignment_Value
(Expression
(M
));
6783 -- For untagged types, clear any existing component clauses for the
6784 -- type. If the type is derived, this is what allows us to override
6785 -- a rep clause for the parent. For type extensions, the representation
6786 -- of the inherited components is inherited, so we want to keep previous
6787 -- component clauses for completeness.
6789 if not Is_Tagged_Type
(Rectype
) then
6790 Comp
:= First_Component_Or_Discriminant
(Rectype
);
6791 while Present
(Comp
) loop
6792 Set_Component_Clause
(Comp
, Empty
);
6793 Next_Component_Or_Discriminant
(Comp
);
6797 -- All done if no component clauses
6799 CC
:= First
(Component_Clauses
(N
));
6805 -- A representation like this applies to the base type
6807 Set_Has_Record_Rep_Clause
(Base_Type
(Rectype
));
6808 Set_Has_Non_Standard_Rep
(Base_Type
(Rectype
));
6809 Set_Has_Specified_Layout
(Base_Type
(Rectype
));
6811 -- Process the component clauses
6813 while Present
(CC
) loop
6817 if Nkind
(CC
) = N_Pragma
then
6820 -- The only pragma of interest is Complete_Representation
6822 if Pragma_Name
(CC
) = Name_Complete_Representation
then
6826 -- Processing for real component clause
6829 Posit
:= Static_Integer
(Position
(CC
));
6830 Fbit
:= Static_Integer
(First_Bit
(CC
));
6831 Lbit
:= Static_Integer
(Last_Bit
(CC
));
6834 and then Fbit
/= No_Uint
6835 and then Lbit
/= No_Uint
6838 Error_Msg_N
("position cannot be negative", Position
(CC
));
6841 Error_Msg_N
("first bit cannot be negative", First_Bit
(CC
));
6843 -- The Last_Bit specified in a component clause must not be
6844 -- less than the First_Bit minus one (RM-13.5.1(10)).
6846 elsif Lbit
< Fbit
- 1 then
6848 ("last bit cannot be less than first bit minus one",
6851 -- Values look OK, so find the corresponding record component
6852 -- Even though the syntax allows an attribute reference for
6853 -- implementation-defined components, GNAT does not allow the
6854 -- tag to get an explicit position.
6856 elsif Nkind
(Component_Name
(CC
)) = N_Attribute_Reference
then
6857 if Attribute_Name
(Component_Name
(CC
)) = Name_Tag
then
6858 Error_Msg_N
("position of tag cannot be specified", CC
);
6860 Error_Msg_N
("illegal component name", CC
);
6864 Comp
:= First_Entity
(Rectype
);
6865 while Present
(Comp
) loop
6866 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
6872 -- Maybe component of base type that is absent from
6873 -- statically constrained first subtype.
6875 Comp
:= First_Entity
(Base_Type
(Rectype
));
6876 while Present
(Comp
) loop
6877 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
6884 ("component clause is for non-existent field", CC
);
6886 -- Ada 2012 (AI05-0026): Any name that denotes a
6887 -- discriminant of an object of an unchecked union type
6888 -- shall not occur within a record_representation_clause.
6890 -- The general restriction of using record rep clauses on
6891 -- Unchecked_Union types has now been lifted. Since it is
6892 -- possible to introduce a record rep clause which mentions
6893 -- the discriminant of an Unchecked_Union in non-Ada 2012
6894 -- code, this check is applied to all versions of the
6897 elsif Ekind
(Comp
) = E_Discriminant
6898 and then Is_Unchecked_Union
(Rectype
)
6901 ("cannot reference discriminant of unchecked union",
6902 Component_Name
(CC
));
6904 elsif Is_Record_Extension
and then Is_Inherited
(Comp
) then
6906 ("component clause not allowed for inherited "
6907 & "component&", CC
, Comp
);
6909 elsif Present
(Component_Clause
(Comp
)) then
6911 -- Diagnose duplicate rep clause, or check consistency
6912 -- if this is an inherited component. In a double fault,
6913 -- there may be a duplicate inconsistent clause for an
6914 -- inherited component.
6916 if Scope
(Original_Record_Component
(Comp
)) = Rectype
6917 or else Parent
(Component_Clause
(Comp
)) = N
6919 Error_Msg_Sloc
:= Sloc
(Component_Clause
(Comp
));
6920 Error_Msg_N
("component clause previously given#", CC
);
6924 Rep1
: constant Node_Id
:= Component_Clause
(Comp
);
6926 if Intval
(Position
(Rep1
)) /=
6927 Intval
(Position
(CC
))
6928 or else Intval
(First_Bit
(Rep1
)) /=
6929 Intval
(First_Bit
(CC
))
6930 or else Intval
(Last_Bit
(Rep1
)) /=
6931 Intval
(Last_Bit
(CC
))
6934 ("component clause inconsistent with "
6935 & "representation of ancestor", CC
);
6937 elsif Warn_On_Redundant_Constructs
then
6939 ("?r?redundant confirming component clause "
6940 & "for component!", CC
);
6945 -- Normal case where this is the first component clause we
6946 -- have seen for this entity, so set it up properly.
6949 -- Make reference for field in record rep clause and set
6950 -- appropriate entity field in the field identifier.
6953 (Comp
, Component_Name
(CC
), Set_Ref
=> False);
6954 Set_Entity
(Component_Name
(CC
), Comp
);
6956 -- Update Fbit and Lbit to the actual bit number
6958 Fbit
:= Fbit
+ UI_From_Int
(SSU
) * Posit
;
6959 Lbit
:= Lbit
+ UI_From_Int
(SSU
) * Posit
;
6961 if Has_Size_Clause
(Rectype
)
6962 and then RM_Size
(Rectype
) <= Lbit
6965 ("bit number out of range of specified size",
6968 Set_Component_Clause
(Comp
, CC
);
6969 Set_Component_Bit_Offset
(Comp
, Fbit
);
6970 Set_Esize
(Comp
, 1 + (Lbit
- Fbit
));
6971 Set_Normalized_First_Bit
(Comp
, Fbit
mod SSU
);
6972 Set_Normalized_Position
(Comp
, Fbit
/ SSU
);
6974 if Warn_On_Overridden_Size
6975 and then Has_Size_Clause
(Etype
(Comp
))
6976 and then RM_Size
(Etype
(Comp
)) /= Esize
(Comp
)
6979 ("?S?component size overrides size clause for&",
6980 Component_Name
(CC
), Etype
(Comp
));
6983 -- This information is also set in the corresponding
6984 -- component of the base type, found by accessing the
6985 -- Original_Record_Component link if it is present.
6987 Ocomp
:= Original_Record_Component
(Comp
);
6994 (Component_Name
(CC
),
7000 (Comp
, First_Node
(CC
), "component clause", Biased
);
7002 if Present
(Ocomp
) then
7003 Set_Component_Clause
(Ocomp
, CC
);
7004 Set_Component_Bit_Offset
(Ocomp
, Fbit
);
7005 Set_Normalized_First_Bit
(Ocomp
, Fbit
mod SSU
);
7006 Set_Normalized_Position
(Ocomp
, Fbit
/ SSU
);
7007 Set_Esize
(Ocomp
, 1 + (Lbit
- Fbit
));
7009 Set_Normalized_Position_Max
7010 (Ocomp
, Normalized_Position
(Ocomp
));
7012 -- Note: we don't use Set_Biased here, because we
7013 -- already gave a warning above if needed, and we
7014 -- would get a duplicate for the same name here.
7016 Set_Has_Biased_Representation
7017 (Ocomp
, Has_Biased_Representation
(Comp
));
7020 if Esize
(Comp
) < 0 then
7021 Error_Msg_N
("component size is negative", CC
);
7032 -- Check missing components if Complete_Representation pragma appeared
7034 if Present
(CR_Pragma
) then
7035 Comp
:= First_Component_Or_Discriminant
(Rectype
);
7036 while Present
(Comp
) loop
7037 if No
(Component_Clause
(Comp
)) then
7039 ("missing component clause for &", CR_Pragma
, Comp
);
7042 Next_Component_Or_Discriminant
(Comp
);
7045 -- Give missing components warning if required
7047 elsif Warn_On_Unrepped_Components
then
7049 Num_Repped_Components
: Nat
:= 0;
7050 Num_Unrepped_Components
: Nat
:= 0;
7053 -- First count number of repped and unrepped components
7055 Comp
:= First_Component_Or_Discriminant
(Rectype
);
7056 while Present
(Comp
) loop
7057 if Present
(Component_Clause
(Comp
)) then
7058 Num_Repped_Components
:= Num_Repped_Components
+ 1;
7060 Num_Unrepped_Components
:= Num_Unrepped_Components
+ 1;
7063 Next_Component_Or_Discriminant
(Comp
);
7066 -- We are only interested in the case where there is at least one
7067 -- unrepped component, and at least half the components have rep
7068 -- clauses. We figure that if less than half have them, then the
7069 -- partial rep clause is really intentional. If the component
7070 -- type has no underlying type set at this point (as for a generic
7071 -- formal type), we don't know enough to give a warning on the
7074 if Num_Unrepped_Components
> 0
7075 and then Num_Unrepped_Components
< Num_Repped_Components
7077 Comp
:= First_Component_Or_Discriminant
(Rectype
);
7078 while Present
(Comp
) loop
7079 if No
(Component_Clause
(Comp
))
7080 and then Comes_From_Source
(Comp
)
7081 and then Present
(Underlying_Type
(Etype
(Comp
)))
7082 and then (Is_Scalar_Type
(Underlying_Type
(Etype
(Comp
)))
7083 or else Size_Known_At_Compile_Time
7084 (Underlying_Type
(Etype
(Comp
))))
7085 and then not Has_Warnings_Off
(Rectype
)
7087 -- Ignore discriminant in unchecked union, since it is
7088 -- not there, and cannot have a component clause.
7090 and then (not Is_Unchecked_Union
(Rectype
)
7091 or else Ekind
(Comp
) /= E_Discriminant
)
7093 Error_Msg_Sloc
:= Sloc
(Comp
);
7095 ("?C?no component clause given for & declared #",
7099 Next_Component_Or_Discriminant
(Comp
);
7104 end Analyze_Record_Representation_Clause
;
7106 -------------------------------------
7107 -- Build_Discrete_Static_Predicate --
7108 -------------------------------------
7110 procedure Build_Discrete_Static_Predicate
7115 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
7117 Non_Static
: exception;
7118 -- Raised if something non-static is found
7120 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
7122 BLo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Btyp
));
7123 BHi
: constant Uint
:= Expr_Value
(Type_High_Bound
(Btyp
));
7124 -- Low bound and high bound value of base type of Typ
7128 -- Bounds for constructing the static predicate. We use the bound of the
7129 -- subtype if it is static, otherwise the corresponding base type bound.
7130 -- Note: a non-static subtype can have a static predicate.
7135 -- One entry in a Rlist value, a single REnt (range entry) value denotes
7136 -- one range from Lo to Hi. To represent a single value range Lo = Hi =
7139 type RList
is array (Nat
range <>) of REnt
;
7140 -- A list of ranges. The ranges are sorted in increasing order, and are
7141 -- disjoint (there is a gap of at least one value between each range in
7142 -- the table). A value is in the set of ranges in Rlist if it lies
7143 -- within one of these ranges.
7145 False_Range
: constant RList
:=
7146 RList
'(1 .. 0 => REnt'(No_Uint
, No_Uint
));
7147 -- An empty set of ranges represents a range list that can never be
7148 -- satisfied, since there are no ranges in which the value could lie,
7149 -- so it does not lie in any of them. False_Range is a canonical value
7150 -- for this empty set, but general processing should test for an Rlist
7151 -- with length zero (see Is_False predicate), since other null ranges
7152 -- may appear which must be treated as False.
7154 True_Range
: constant RList
:= RList
'(1 => REnt'(BLo
, BHi
));
7155 -- Range representing True, value must be in the base range
7157 function "and" (Left
: RList
; Right
: RList
) return RList
;
7158 -- And's together two range lists, returning a range list. This is a set
7159 -- intersection operation.
7161 function "or" (Left
: RList
; Right
: RList
) return RList
;
7162 -- Or's together two range lists, returning a range list. This is a set
7165 function "not" (Right
: RList
) return RList
;
7166 -- Returns complement of a given range list, i.e. a range list
7167 -- representing all the values in TLo .. THi that are not in the input
7170 function Build_Val
(V
: Uint
) return Node_Id
;
7171 -- Return an analyzed N_Identifier node referencing this value, suitable
7172 -- for use as an entry in the Static_Discrte_Predicate list. This node
7173 -- is typed with the base type.
7175 function Build_Range
(Lo
: Uint
; Hi
: Uint
) return Node_Id
;
7176 -- Return an analyzed N_Range node referencing this range, suitable for
7177 -- use as an entry in the Static_Discrete_Predicate list. This node is
7178 -- typed with the base type.
7180 function Get_RList
(Exp
: Node_Id
) return RList
;
7181 -- This is a recursive routine that converts the given expression into a
7182 -- list of ranges, suitable for use in building the static predicate.
7184 function Is_False
(R
: RList
) return Boolean;
7185 pragma Inline
(Is_False
);
7186 -- Returns True if the given range list is empty, and thus represents a
7187 -- False list of ranges that can never be satisfied.
7189 function Is_True
(R
: RList
) return Boolean;
7190 -- Returns True if R trivially represents the True predicate by having a
7191 -- single range from BLo to BHi.
7193 function Is_Type_Ref
(N
: Node_Id
) return Boolean;
7194 pragma Inline
(Is_Type_Ref
);
7195 -- Returns if True if N is a reference to the type for the predicate in
7196 -- the expression (i.e. if it is an identifier whose Chars field matches
7197 -- the Nam given in the call). N must not be parenthesized, if the type
7198 -- name appears in parens, this routine will return False.
7200 function Lo_Val
(N
: Node_Id
) return Uint
;
7201 -- Given an entry from a Static_Discrete_Predicate list that is either
7202 -- a static expression or static range, gets either the expression value
7203 -- or the low bound of the range.
7205 function Hi_Val
(N
: Node_Id
) return Uint
;
7206 -- Given an entry from a Static_Discrete_Predicate list that is either
7207 -- a static expression or static range, gets either the expression value
7208 -- or the high bound of the range.
7210 function Membership_Entry
(N
: Node_Id
) return RList
;
7211 -- Given a single membership entry (range, value, or subtype), returns
7212 -- the corresponding range list. Raises Static_Error if not static.
7214 function Membership_Entries
(N
: Node_Id
) return RList
;
7215 -- Given an element on an alternatives list of a membership operation,
7216 -- returns the range list corresponding to this entry and all following
7217 -- entries (i.e. returns the "or" of this list of values).
7219 function Stat_Pred
(Typ
: Entity_Id
) return RList
;
7220 -- Given a type, if it has a static predicate, then return the predicate
7221 -- as a range list, otherwise raise Non_Static.
7227 function "and" (Left
: RList
; Right
: RList
) return RList
is
7229 -- First range of result
7231 SLeft
: Nat
:= Left
'First;
7232 -- Start of rest of left entries
7234 SRight
: Nat
:= Right
'First;
7235 -- Start of rest of right entries
7238 -- If either range is True, return the other
7240 if Is_True
(Left
) then
7242 elsif Is_True
(Right
) then
7246 -- If either range is False, return False
7248 if Is_False
(Left
) or else Is_False
(Right
) then
7252 -- Loop to remove entries at start that are disjoint, and thus just
7253 -- get discarded from the result entirely.
7256 -- If no operands left in either operand, result is false
7258 if SLeft
> Left
'Last or else SRight
> Right
'Last then
7261 -- Discard first left operand entry if disjoint with right
7263 elsif Left
(SLeft
).Hi
< Right
(SRight
).Lo
then
7266 -- Discard first right operand entry if disjoint with left
7268 elsif Right
(SRight
).Hi
< Left
(SLeft
).Lo
then
7269 SRight
:= SRight
+ 1;
7271 -- Otherwise we have an overlapping entry
7278 -- Now we have two non-null operands, and first entries overlap. The
7279 -- first entry in the result will be the overlapping part of these
7282 FEnt
:= REnt
'(Lo => UI_Max (Left (SLeft).Lo, Right (SRight).Lo),
7283 Hi => UI_Min (Left (SLeft).Hi, Right (SRight).Hi));
7285 -- Now we can remove the entry that ended at a lower value, since its
7286 -- contribution is entirely contained in Fent.
7288 if Left (SLeft).Hi <= Right (SRight).Hi then
7291 SRight := SRight + 1;
7294 -- Compute result by concatenating this first entry with the "and" of
7295 -- the remaining parts of the left and right operands. Note that if
7296 -- either of these is empty, "and" will yield empty, so that we will
7297 -- end up with just Fent, which is what we want in that case.
7300 FEnt & (Left (SLeft .. Left'Last) and Right (SRight .. Right'Last));
7307 function "not" (Right : RList) return RList is
7309 -- Return True if False range
7311 if Is_False (Right) then
7315 -- Return False if True range
7317 if Is_True (Right) then
7321 -- Here if not trivial case
7324 Result : RList (1 .. Right'Length + 1);
7325 -- May need one more entry for gap at beginning and end
7328 -- Number of entries stored in Result
7333 if Right (Right'First).Lo > TLo then
7335 Result (Count) := REnt'(TLo
, Right
(Right
'First).Lo
- 1);
7338 -- Gaps between ranges
7340 for J
in Right
'First .. Right
'Last - 1 loop
7342 Result
(Count
) := REnt
'(Right (J).Hi + 1, Right (J + 1).Lo - 1);
7347 if Right (Right'Last).Hi < THi then
7349 Result (Count) := REnt'(Right
(Right
'Last).Hi
+ 1, THi
);
7352 return Result
(1 .. Count
);
7360 function "or" (Left
: RList
; Right
: RList
) return RList
is
7362 -- First range of result
7364 SLeft
: Nat
:= Left
'First;
7365 -- Start of rest of left entries
7367 SRight
: Nat
:= Right
'First;
7368 -- Start of rest of right entries
7371 -- If either range is True, return True
7373 if Is_True
(Left
) or else Is_True
(Right
) then
7377 -- If either range is False (empty), return the other
7379 if Is_False
(Left
) then
7381 elsif Is_False
(Right
) then
7385 -- Initialize result first entry from left or right operand depending
7386 -- on which starts with the lower range.
7388 if Left
(SLeft
).Lo
< Right
(SRight
).Lo
then
7389 FEnt
:= Left
(SLeft
);
7392 FEnt
:= Right
(SRight
);
7393 SRight
:= SRight
+ 1;
7396 -- This loop eats ranges from left and right operands that are
7397 -- contiguous with the first range we are gathering.
7400 -- Eat first entry in left operand if contiguous or overlapped by
7401 -- gathered first operand of result.
7403 if SLeft
<= Left
'Last
7404 and then Left
(SLeft
).Lo
<= FEnt
.Hi
+ 1
7406 FEnt
.Hi
:= UI_Max
(FEnt
.Hi
, Left
(SLeft
).Hi
);
7409 -- Eat first entry in right operand if contiguous or overlapped by
7410 -- gathered right operand of result.
7412 elsif SRight
<= Right
'Last
7413 and then Right
(SRight
).Lo
<= FEnt
.Hi
+ 1
7415 FEnt
.Hi
:= UI_Max
(FEnt
.Hi
, Right
(SRight
).Hi
);
7416 SRight
:= SRight
+ 1;
7418 -- All done if no more entries to eat
7425 -- Obtain result as the first entry we just computed, concatenated
7426 -- to the "or" of the remaining results (if one operand is empty,
7427 -- this will just concatenate with the other
7430 FEnt
& (Left
(SLeft
.. Left
'Last) or Right
(SRight
.. Right
'Last));
7437 function Build_Range
(Lo
: Uint
; Hi
: Uint
) return Node_Id
is
7442 Low_Bound
=> Build_Val
(Lo
),
7443 High_Bound
=> Build_Val
(Hi
));
7444 Set_Etype
(Result
, Btyp
);
7445 Set_Analyzed
(Result
);
7453 function Build_Val
(V
: Uint
) return Node_Id
is
7457 if Is_Enumeration_Type
(Typ
) then
7458 Result
:= Get_Enum_Lit_From_Pos
(Typ
, V
, Loc
);
7460 Result
:= Make_Integer_Literal
(Loc
, V
);
7463 Set_Etype
(Result
, Btyp
);
7464 Set_Is_Static_Expression
(Result
);
7465 Set_Analyzed
(Result
);
7473 function Get_RList
(Exp
: Node_Id
) return RList
is
7478 -- Static expression can only be true or false
7480 if Is_OK_Static_Expression
(Exp
) then
7481 if Expr_Value
(Exp
) = 0 then
7488 -- Otherwise test node type
7496 when N_Op_And | N_And_Then
=>
7497 return Get_RList
(Left_Opnd
(Exp
))
7499 Get_RList
(Right_Opnd
(Exp
));
7503 when N_Op_Or | N_Or_Else
=>
7504 return Get_RList
(Left_Opnd
(Exp
))
7506 Get_RList
(Right_Opnd
(Exp
));
7511 return not Get_RList
(Right_Opnd
(Exp
));
7513 -- Comparisons of type with static value
7515 when N_Op_Compare
=>
7517 -- Type is left operand
7519 if Is_Type_Ref
(Left_Opnd
(Exp
))
7520 and then Is_OK_Static_Expression
(Right_Opnd
(Exp
))
7522 Val
:= Expr_Value
(Right_Opnd
(Exp
));
7524 -- Typ is right operand
7526 elsif Is_Type_Ref
(Right_Opnd
(Exp
))
7527 and then Is_OK_Static_Expression
(Left_Opnd
(Exp
))
7529 Val
:= Expr_Value
(Left_Opnd
(Exp
));
7531 -- Invert sense of comparison
7534 when N_Op_Gt
=> Op
:= N_Op_Lt
;
7535 when N_Op_Lt
=> Op
:= N_Op_Gt
;
7536 when N_Op_Ge
=> Op
:= N_Op_Le
;
7537 when N_Op_Le
=> Op
:= N_Op_Ge
;
7538 when others => null;
7541 -- Other cases are non-static
7547 -- Construct range according to comparison operation
7551 return RList
'(1 => REnt'(Val
, Val
));
7554 return RList
'(1 => REnt'(Val
, BHi
));
7557 return RList
'(1 => REnt'(Val
+ 1, BHi
));
7560 return RList
'(1 => REnt'(BLo
, Val
));
7563 return RList
'(1 => REnt'(BLo
, Val
- 1));
7566 return RList
'(REnt'(BLo
, Val
- 1), REnt
'(Val + 1, BHi));
7569 raise Program_Error;
7575 if not Is_Type_Ref (Left_Opnd (Exp)) then
7579 if Present (Right_Opnd (Exp)) then
7580 return Membership_Entry (Right_Opnd (Exp));
7582 return Membership_Entries (First (Alternatives (Exp)));
7585 -- Negative membership (NOT IN)
7588 if not Is_Type_Ref (Left_Opnd (Exp)) then
7592 if Present (Right_Opnd (Exp)) then
7593 return not Membership_Entry (Right_Opnd (Exp));
7595 return not Membership_Entries (First (Alternatives (Exp)));
7598 -- Function call, may be call to static predicate
7600 when N_Function_Call =>
7601 if Is_Entity_Name (Name (Exp)) then
7603 Ent : constant Entity_Id := Entity (Name (Exp));
7605 if Is_Predicate_Function (Ent)
7607 Is_Predicate_Function_M (Ent)
7609 return Stat_Pred (Etype (First_Formal (Ent)));
7614 -- Other function call cases are non-static
7618 -- Qualified expression, dig out the expression
7620 when N_Qualified_Expression =>
7621 return Get_RList (Expression (Exp));
7623 when N_Case_Expression =>
7630 if not Is_Entity_Name (Expression (Expr))
7631 or else Etype (Expression (Expr)) /= Typ
7634 ("expression must denaote subtype", Expression (Expr));
7638 -- Collect discrete choices in all True alternatives
7640 Choices := New_List;
7641 Alt := First (Alternatives (Exp));
7642 while Present (Alt) loop
7643 Dep := Expression (Alt);
7645 if not Is_OK_Static_Expression (Dep) then
7648 elsif Is_True (Expr_Value (Dep)) then
7649 Append_List_To (Choices,
7650 New_Copy_List (Discrete_Choices (Alt)));
7656 return Membership_Entries (First (Choices));
7659 -- Expression with actions: if no actions, dig out expression
7661 when N_Expression_With_Actions =>
7662 if Is_Empty_List (Actions (Exp)) then
7663 return Get_RList (Expression (Exp));
7671 return (Get_RList (Left_Opnd (Exp))
7672 and not Get_RList (Right_Opnd (Exp)))
7673 or (Get_RList (Right_Opnd (Exp))
7674 and not Get_RList (Left_Opnd (Exp)));
7676 -- Any other node type is non-static
7687 function Hi_Val (N : Node_Id) return Uint is
7689 if Is_OK_Static_Expression (N) then
7690 return Expr_Value (N);
7692 pragma Assert (Nkind (N) = N_Range);
7693 return Expr_Value (High_Bound (N));
7701 function Is_False (R : RList) return Boolean is
7703 return R'Length = 0;
7710 function Is_True (R : RList) return Boolean is
7713 and then R (R'First).Lo = BLo
7714 and then R (R'First).Hi = BHi;
7721 function Is_Type_Ref (N : Node_Id) return Boolean is
7723 return Nkind (N) = N_Identifier
7724 and then Chars (N) = Nam
7725 and then Paren_Count (N) = 0;
7732 function Lo_Val (N : Node_Id) return Uint is
7734 if Is_OK_Static_Expression (N) then
7735 return Expr_Value (N);
7737 pragma Assert (Nkind (N) = N_Range);
7738 return Expr_Value (Low_Bound (N));
7742 ------------------------
7743 -- Membership_Entries --
7744 ------------------------
7746 function Membership_Entries (N : Node_Id) return RList is
7748 if No (Next (N)) then
7749 return Membership_Entry (N);
7751 return Membership_Entry (N) or Membership_Entries (Next (N));
7753 end Membership_Entries;
7755 ----------------------
7756 -- Membership_Entry --
7757 ----------------------
7759 function Membership_Entry (N : Node_Id) return RList is
7767 if Nkind (N) = N_Range then
7768 if not Is_OK_Static_Expression (Low_Bound (N))
7770 not Is_OK_Static_Expression (High_Bound (N))
7774 SLo := Expr_Value (Low_Bound (N));
7775 SHi := Expr_Value (High_Bound (N));
7776 return RList'(1 => REnt
'(SLo, SHi));
7779 -- Static expression case
7781 elsif Is_OK_Static_Expression (N) then
7782 Val := Expr_Value (N);
7783 return RList'(1 => REnt
'(Val, Val));
7785 -- Identifier (other than static expression) case
7787 else pragma Assert (Nkind (N) = N_Identifier);
7791 if Is_Type (Entity (N)) then
7793 -- If type has predicates, process them
7795 if Has_Predicates (Entity (N)) then
7796 return Stat_Pred (Entity (N));
7798 -- For static subtype without predicates, get range
7800 elsif Is_OK_Static_Subtype (Entity (N)) then
7801 SLo := Expr_Value (Type_Low_Bound (Entity (N)));
7802 SHi := Expr_Value (Type_High_Bound (Entity (N)));
7803 return RList'(1 => REnt
'(SLo, SHi));
7805 -- Any other type makes us non-static
7811 -- Any other kind of identifier in predicate (e.g. a non-static
7812 -- expression value) means this is not a static predicate.
7818 end Membership_Entry;
7824 function Stat_Pred (Typ : Entity_Id) return RList is
7826 -- Not static if type does not have static predicates
7828 if not Has_Static_Predicate (Typ) then
7832 -- Otherwise we convert the predicate list to a range list
7835 Spred : constant List_Id := Static_Discrete_Predicate (Typ);
7836 Result : RList (1 .. List_Length (Spred));
7840 P := First (Static_Discrete_Predicate (Typ));
7841 for J in Result'Range loop
7842 Result (J) := REnt'(Lo_Val
(P
), Hi_Val
(P
));
7850 -- Start of processing for Build_Discrete_Static_Predicate
7853 -- Establish bounds for the predicate
7855 if Compile_Time_Known_Value
(Type_Low_Bound
(Typ
)) then
7856 TLo
:= Expr_Value
(Type_Low_Bound
(Typ
));
7861 if Compile_Time_Known_Value
(Type_High_Bound
(Typ
)) then
7862 THi
:= Expr_Value
(Type_High_Bound
(Typ
));
7867 -- Analyze the expression to see if it is a static predicate
7870 Ranges
: constant RList
:= Get_RList
(Expr
);
7871 -- Range list from expression if it is static
7876 -- Convert range list into a form for the static predicate. In the
7877 -- Ranges array, we just have raw ranges, these must be converted
7878 -- to properly typed and analyzed static expressions or range nodes.
7880 -- Note: here we limit ranges to the ranges of the subtype, so that
7881 -- a predicate is always false for values outside the subtype. That
7882 -- seems fine, such values are invalid anyway, and considering them
7883 -- to fail the predicate seems allowed and friendly, and furthermore
7884 -- simplifies processing for case statements and loops.
7888 for J
in Ranges
'Range loop
7890 Lo
: Uint
:= Ranges
(J
).Lo
;
7891 Hi
: Uint
:= Ranges
(J
).Hi
;
7894 -- Ignore completely out of range entry
7896 if Hi
< TLo
or else Lo
> THi
then
7899 -- Otherwise process entry
7902 -- Adjust out of range value to subtype range
7912 -- Convert range into required form
7914 Append_To
(Plist
, Build_Range
(Lo
, Hi
));
7919 -- Processing was successful and all entries were static, so now we
7920 -- can store the result as the predicate list.
7922 Set_Static_Discrete_Predicate
(Typ
, Plist
);
7924 -- The processing for static predicates put the expression into
7925 -- canonical form as a series of ranges. It also eliminated
7926 -- duplicates and collapsed and combined ranges. We might as well
7927 -- replace the alternatives list of the right operand of the
7928 -- membership test with the static predicate list, which will
7929 -- usually be more efficient.
7932 New_Alts
: constant List_Id
:= New_List
;
7937 Old_Node
:= First
(Plist
);
7938 while Present
(Old_Node
) loop
7939 New_Node
:= New_Copy
(Old_Node
);
7941 if Nkind
(New_Node
) = N_Range
then
7942 Set_Low_Bound
(New_Node
, New_Copy
(Low_Bound
(Old_Node
)));
7943 Set_High_Bound
(New_Node
, New_Copy
(High_Bound
(Old_Node
)));
7946 Append_To
(New_Alts
, New_Node
);
7950 -- If empty list, replace by False
7952 if Is_Empty_List
(New_Alts
) then
7953 Rewrite
(Expr
, New_Occurrence_Of
(Standard_False
, Loc
));
7955 -- Else replace by set membership test
7960 Left_Opnd
=> Make_Identifier
(Loc
, Nam
),
7961 Right_Opnd
=> Empty
,
7962 Alternatives
=> New_Alts
));
7964 -- Resolve new expression in function context
7966 Install_Formals
(Predicate_Function
(Typ
));
7967 Push_Scope
(Predicate_Function
(Typ
));
7968 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
7974 -- If non-static, return doing nothing
7979 end Build_Discrete_Static_Predicate
;
7981 --------------------------------
7982 -- Build_Export_Import_Pragma --
7983 --------------------------------
7985 function Build_Export_Import_Pragma
7987 Id
: Entity_Id
) return Node_Id
7989 Asp_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Asp
);
7990 Expr
: constant Node_Id
:= Expression
(Asp
);
7991 Loc
: constant Source_Ptr
:= Sloc
(Asp
);
8002 Create_Pragma
: Boolean := False;
8003 -- This flag is set when the aspect form is such that it warrants the
8004 -- creation of a corresponding pragma.
8007 if Present
(Expr
) then
8008 if Error_Posted
(Expr
) then
8011 elsif Is_True
(Expr_Value
(Expr
)) then
8012 Create_Pragma
:= True;
8015 -- Otherwise the aspect defaults to True
8018 Create_Pragma
:= True;
8021 -- Nothing to do when the expression is False or is erroneous
8023 if not Create_Pragma
then
8027 -- Obtain all interfacing aspects that apply to the related entity
8029 Get_Interfacing_Aspects
8033 Expo_Asp
=> Dummy_1
,
8039 -- Handle the convention argument
8041 if Present
(Conv
) then
8042 Conv_Arg
:= New_Copy_Tree
(Expression
(Conv
));
8044 -- Assume convention "Ada' when aspect Convention is missing
8047 Conv_Arg
:= Make_Identifier
(Loc
, Name_Ada
);
8051 Make_Pragma_Argument_Association
(Loc
,
8052 Chars
=> Name_Convention
,
8053 Expression
=> Conv_Arg
));
8055 -- Handle the entity argument
8058 Make_Pragma_Argument_Association
(Loc
,
8059 Chars
=> Name_Entity
,
8060 Expression
=> New_Occurrence_Of
(Id
, Loc
)));
8062 -- Handle the External_Name argument
8064 if Present
(EN
) then
8066 Make_Pragma_Argument_Association
(Loc
,
8067 Chars
=> Name_External_Name
,
8068 Expression
=> New_Copy_Tree
(Expression
(EN
))));
8071 -- Handle the Link_Name argument
8073 if Present
(LN
) then
8075 Make_Pragma_Argument_Association
(Loc
,
8076 Chars
=> Name_Link_Name
,
8077 Expression
=> New_Copy_Tree
(Expression
(LN
))));
8081 -- pragma Export/Import
8082 -- (Convention => <Conv>/Ada,
8084 -- [External_Name => <EN>,]
8085 -- [Link_Name => <LN>]);
8089 Pragma_Identifier
=>
8090 Make_Identifier
(Loc
, Chars
(Identifier
(Asp
))),
8091 Pragma_Argument_Associations
=> Args
);
8093 -- Decorate the relevant aspect and the pragma
8095 Set_Aspect_Rep_Item
(Asp
, Prag
);
8097 Set_Corresponding_Aspect
(Prag
, Asp
);
8098 Set_From_Aspect_Specification
(Prag
);
8099 Set_Parent
(Prag
, Asp
);
8101 if Asp_Id
= Aspect_Import
and then Is_Subprogram
(Id
) then
8102 Set_Import_Pragma
(Id
, Prag
);
8106 end Build_Export_Import_Pragma
;
8108 -------------------------------
8109 -- Build_Predicate_Functions --
8110 -------------------------------
8112 -- The procedures that are constructed here have the form:
8114 -- function typPredicate (Ixxx : typ) return Boolean is
8117 -- typ1Predicate (typ1 (Ixxx))
8118 -- and then typ2Predicate (typ2 (Ixxx))
8120 -- exp1 and then exp2 and then ...
8121 -- end typPredicate;
8123 -- Here exp1, and exp2 are expressions from Predicate pragmas. Note that
8124 -- this is the point at which these expressions get analyzed, providing the
8125 -- required delay, and typ1, typ2, are entities from which predicates are
8126 -- inherited. Note that we do NOT generate Check pragmas, that's because we
8127 -- use this function even if checks are off, e.g. for membership tests.
8129 -- Note that the inherited predicates are evaluated first, as required by
8132 -- Note that Sem_Eval.Real_Or_String_Static_Predicate_Matches depends on
8133 -- the form of this return expression.
8135 -- If the expression has at least one Raise_Expression, then we also build
8136 -- the typPredicateM version of the function, in which any occurrence of a
8137 -- Raise_Expression is converted to "return False".
8139 procedure Build_Predicate_Functions
(Typ
: Entity_Id
; N
: Node_Id
) is
8140 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
8143 -- This is the expression for the result of the function. It is
8144 -- is build by connecting the component predicates with AND THEN.
8147 -- This is the corresponding return expression for the Predicate_M
8148 -- function. It differs in that raise expressions are marked for
8149 -- special expansion (see Process_REs).
8151 Object_Name
: Name_Id
;
8152 -- Name for argument of Predicate procedure. Note that we use the same
8153 -- name for both predicate functions. That way the reference within the
8154 -- predicate expression is the same in both functions.
8156 Object_Entity
: Entity_Id
;
8157 -- Entity for argument of Predicate procedure
8159 Object_Entity_M
: Entity_Id
;
8160 -- Entity for argument of separate Predicate procedure when exceptions
8161 -- are present in expression.
8164 -- The function declaration
8169 Raise_Expression_Present
: Boolean := False;
8170 -- Set True if Expr has at least one Raise_Expression
8172 procedure Add_Condition
(Cond
: Node_Id
);
8173 -- Append Cond to Expr using "and then" (or just copy Cond to Expr if
8176 procedure Add_Predicates
;
8177 -- Appends expressions for any Predicate pragmas in the rep item chain
8178 -- Typ to Expr. Note that we look only at items for this exact entity.
8179 -- Inheritance of predicates for the parent type is done by calling the
8180 -- Predicate_Function of the parent type, using Add_Call above.
8182 procedure Add_Call
(T
: Entity_Id
);
8183 -- Includes a call to the predicate function for type T in Expr if T
8184 -- has predicates and Predicate_Function (T) is non-empty.
8186 function Process_RE
(N
: Node_Id
) return Traverse_Result
;
8187 -- Used in Process REs, tests if node N is a raise expression, and if
8188 -- so, marks it to be converted to return False.
8190 procedure Process_REs
is new Traverse_Proc
(Process_RE
);
8191 -- Marks any raise expressions in Expr_M to return False
8193 function Test_RE
(N
: Node_Id
) return Traverse_Result
;
8194 -- Used in Test_REs, tests one node for being a raise expression, and if
8195 -- so sets Raise_Expression_Present True.
8197 procedure Test_REs
is new Traverse_Proc
(Test_RE
);
8198 -- Tests to see if Expr contains any raise expressions
8204 procedure Add_Call
(T
: Entity_Id
) is
8208 if Present
(T
) and then Present
(Predicate_Function
(T
)) then
8209 Set_Has_Predicates
(Typ
);
8211 -- Build the call to the predicate function of T
8215 (T
, Convert_To
(T
, Make_Identifier
(Loc
, Object_Name
)));
8217 -- "and"-in the call to evolving expression
8219 Add_Condition
(Exp
);
8221 -- Output info message on inheritance if required. Note we do not
8222 -- give this information for generic actual types, since it is
8223 -- unwelcome noise in that case in instantiations. We also
8224 -- generally suppress the message in instantiations, and also
8225 -- if it involves internal names.
8227 if Opt
.List_Inherited_Aspects
8228 and then not Is_Generic_Actual_Type
(Typ
)
8229 and then Instantiation_Depth
(Sloc
(Typ
)) = 0
8230 and then not Is_Internal_Name
(Chars
(T
))
8231 and then not Is_Internal_Name
(Chars
(Typ
))
8233 Error_Msg_Sloc
:= Sloc
(Predicate_Function
(T
));
8234 Error_Msg_Node_2
:= T
;
8235 Error_Msg_N
("info: & inherits predicate from & #?L?", Typ
);
8244 procedure Add_Condition
(Cond
: Node_Id
) is
8246 -- This is the first predicate expression
8251 -- Otherwise concatenate to the existing predicate expressions by
8252 -- using "and then".
8257 Left_Opnd
=> Relocate_Node
(Expr
),
8258 Right_Opnd
=> Cond
);
8262 --------------------
8263 -- Add_Predicates --
8264 --------------------
8266 procedure Add_Predicates
is
8267 procedure Add_Predicate
(Prag
: Node_Id
);
8268 -- Concatenate the expression of predicate pragma Prag to Expr by
8269 -- using a short circuit "and then" operator.
8275 procedure Add_Predicate
(Prag
: Node_Id
) is
8276 procedure Replace_Type_Reference
(N
: Node_Id
);
8277 -- Replace a single occurrence N of the subtype name with a
8278 -- reference to the formal of the predicate function. N can be an
8279 -- identifier referencing the subtype, or a selected component,
8280 -- representing an appropriately qualified occurrence of the
8283 procedure Replace_Type_References
is
8284 new Replace_Type_References_Generic
(Replace_Type_Reference
);
8285 -- Traverse an expression changing every occurrence of an
8286 -- identifier whose name matches the name of the subtype with a
8287 -- reference to the formal parameter of the predicate function.
8289 ----------------------------
8290 -- Replace_Type_Reference --
8291 ----------------------------
8293 procedure Replace_Type_Reference
(N
: Node_Id
) is
8295 Rewrite
(N
, Make_Identifier
(Sloc
(N
), Object_Name
));
8296 -- Use the Sloc of the usage name, not the defining name
8299 Set_Entity
(N
, Object_Entity
);
8301 -- We want to treat the node as if it comes from source, so
8302 -- that ASIS will not ignore it.
8304 Set_Comes_From_Source
(N
, True);
8305 end Replace_Type_Reference
;
8309 Asp
: constant Node_Id
:= Corresponding_Aspect
(Prag
);
8313 -- Start of processing for Add_Predicate
8316 -- Extract the arguments of the pragma. The expression itself
8317 -- is copied for use in the predicate function, to preserve the
8318 -- original version for ASIS use.
8320 Arg1
:= First
(Pragma_Argument_Associations
(Prag
));
8321 Arg2
:= Next
(Arg1
);
8323 Arg1
:= Get_Pragma_Arg
(Arg1
);
8324 Arg2
:= New_Copy_Tree
(Get_Pragma_Arg
(Arg2
));
8326 -- When the predicate pragma applies to the current type or its
8327 -- full view, replace all occurrences of the subtype name with
8328 -- references to the formal parameter of the predicate function.
8330 if Entity
(Arg1
) = Typ
8331 or else Full_View
(Entity
(Arg1
)) = Typ
8333 Replace_Type_References
(Arg2
, Typ
);
8335 -- If the predicate pragma comes from an aspect, replace the
8336 -- saved expression because we need the subtype references
8337 -- replaced for the calls to Preanalyze_Spec_Expression in
8338 -- Check_Aspect_At_xxx routines.
8340 if Present
(Asp
) then
8341 Set_Entity
(Identifier
(Asp
), New_Copy_Tree
(Arg2
));
8344 -- "and"-in the Arg2 condition to evolving expression
8346 Add_Condition
(Relocate_Node
(Arg2
));
8354 -- Start of processing for Add_Predicates
8357 Ritem
:= First_Rep_Item
(Typ
);
8358 while Present
(Ritem
) loop
8359 if Nkind
(Ritem
) = N_Pragma
8360 and then Pragma_Name
(Ritem
) = Name_Predicate
8362 Add_Predicate
(Ritem
);
8364 -- If the type is declared in an inner package it may be frozen
8365 -- outside of the package, and the generated pragma has not been
8366 -- analyzed yet, so capture the expression for the predicate
8367 -- function at this point.
8369 elsif Nkind
(Ritem
) = N_Aspect_Specification
8370 and then Present
(Aspect_Rep_Item
(Ritem
))
8371 and then Scope
(Typ
) /= Current_Scope
8374 Prag
: constant Node_Id
:= Aspect_Rep_Item
(Ritem
);
8377 if Nkind
(Prag
) = N_Pragma
8378 and then Pragma_Name
(Prag
) = Name_Predicate
8380 Add_Predicate
(Prag
);
8385 Next_Rep_Item
(Ritem
);
8393 function Process_RE
(N
: Node_Id
) return Traverse_Result
is
8395 if Nkind
(N
) = N_Raise_Expression
then
8396 Set_Convert_To_Return_False
(N
);
8407 function Test_RE
(N
: Node_Id
) return Traverse_Result
is
8409 if Nkind
(N
) = N_Raise_Expression
then
8410 Raise_Expression_Present
:= True;
8419 Save_Ghost_Mode
: constant Ghost_Mode_Type
:= Ghost_Mode
;
8421 -- Start of processing for Build_Predicate_Functions
8424 -- Return if already built or if type does not have predicates
8426 SId
:= Predicate_Function
(Typ
);
8427 if not Has_Predicates
(Typ
)
8428 or else (Present
(SId
) and then Has_Completion
(SId
))
8433 -- The related type may be subject to pragma Ghost. Set the mode now to
8434 -- ensure that the predicate functions are properly marked as Ghost.
8436 Set_Ghost_Mode_From_Entity
(Typ
);
8438 -- Prepare to construct predicate expression
8442 if Present
(SId
) then
8443 FDecl
:= Unit_Declaration_Node
(SId
);
8446 FDecl
:= Build_Predicate_Function_Declaration
(Typ
);
8447 SId
:= Defining_Entity
(FDecl
);
8450 -- Recover name of formal parameter of function that replaces references
8451 -- to the type in predicate expressions.
8455 (First
(Parameter_Specifications
(Specification
(FDecl
))));
8457 Object_Name
:= Chars
(Object_Entity
);
8458 Object_Entity_M
:= Make_Defining_Identifier
(Loc
, Chars
=> Object_Name
);
8460 -- Add predicates for ancestor if present. These must come before the
8461 -- ones for the current type, as required by AI12-0071-1.
8464 Atyp
: constant Entity_Id
:= Nearest_Ancestor
(Typ
);
8466 if Present
(Atyp
) then
8471 -- Add Predicates for the current type
8475 -- Case where predicates are present
8477 if Present
(Expr
) then
8479 -- Test for raise expression present
8483 -- If raise expression is present, capture a copy of Expr for use
8484 -- in building the predicateM function version later on. For this
8485 -- copy we replace references to Object_Entity by Object_Entity_M.
8487 if Raise_Expression_Present
then
8489 Map
: constant Elist_Id
:= New_Elmt_List
;
8490 New_V
: Entity_Id
:= Empty
;
8492 -- The unanalyzed expression will be copied and appear in
8493 -- both functions. Normally expressions do not declare new
8494 -- entities, but quantified expressions do, so we need to
8495 -- create new entities for their bound variables, to prevent
8496 -- multiple definitions in gigi.
8498 function Reset_Loop_Variable
(N
: Node_Id
)
8499 return Traverse_Result
;
8501 procedure Collect_Loop_Variables
is
8502 new Traverse_Proc
(Reset_Loop_Variable
);
8504 ------------------------
8505 -- Reset_Loop_Variable --
8506 ------------------------
8508 function Reset_Loop_Variable
(N
: Node_Id
)
8509 return Traverse_Result
8512 if Nkind
(N
) = N_Iterator_Specification
then
8513 New_V
:= Make_Defining_Identifier
8514 (Sloc
(N
), Chars
(Defining_Identifier
(N
)));
8516 Set_Defining_Identifier
(N
, New_V
);
8520 end Reset_Loop_Variable
;
8523 Append_Elmt
(Object_Entity
, Map
);
8524 Append_Elmt
(Object_Entity_M
, Map
);
8525 Expr_M
:= New_Copy_Tree
(Expr
, Map
=> Map
);
8526 Collect_Loop_Variables
(Expr_M
);
8530 -- Build the main predicate function
8533 SIdB
: constant Entity_Id
:=
8534 Make_Defining_Identifier
(Loc
,
8535 Chars
=> New_External_Name
(Chars
(Typ
), "Predicate"));
8536 -- The entity for the function body
8543 -- The predicate function is shared between views of a type
8545 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
8546 Set_Predicate_Function
(Full_View
(Typ
), SId
);
8549 -- Mark the predicate function explicitly as Ghost because it does
8550 -- not come from source.
8552 if Ghost_Mode
> None
then
8553 Set_Is_Ghost_Entity
(SId
);
8556 -- Build function body
8559 Make_Function_Specification
(Loc
,
8560 Defining_Unit_Name
=> SIdB
,
8561 Parameter_Specifications
=> New_List
(
8562 Make_Parameter_Specification
(Loc
,
8563 Defining_Identifier
=>
8564 Make_Defining_Identifier
(Loc
, Object_Name
),
8566 New_Occurrence_Of
(Typ
, Loc
))),
8567 Result_Definition
=>
8568 New_Occurrence_Of
(Standard_Boolean
, Loc
));
8571 Make_Subprogram_Body
(Loc
,
8572 Specification
=> Spec
,
8573 Declarations
=> Empty_List
,
8574 Handled_Statement_Sequence
=>
8575 Make_Handled_Sequence_Of_Statements
(Loc
,
8576 Statements
=> New_List
(
8577 Make_Simple_Return_Statement
(Loc
,
8578 Expression
=> Expr
))));
8580 -- If declaration has not been analyzed yet, Insert declaration
8581 -- before freeze node. Insert body itself after freeze node.
8583 if not Analyzed
(FDecl
) then
8584 Insert_Before_And_Analyze
(N
, FDecl
);
8587 Insert_After_And_Analyze
(N
, FBody
);
8589 -- Static predicate functions are always side-effect free, and
8590 -- in most cases dynamic predicate functions are as well. Mark
8591 -- them as such whenever possible, so redundant predicate checks
8592 -- can be optimized. If there is a variable reference within the
8593 -- expression, the function is not pure.
8595 if Expander_Active
then
8597 Side_Effect_Free
(Expr
, Variable_Ref
=> True));
8598 Set_Is_Inlined
(SId
);
8602 -- Test for raise expressions present and if so build M version
8604 if Raise_Expression_Present
then
8606 SId
: constant Entity_Id
:=
8607 Make_Defining_Identifier
(Loc
,
8608 Chars
=> New_External_Name
(Chars
(Typ
), "PredicateM"));
8609 -- The entity for the function spec
8611 SIdB
: constant Entity_Id
:=
8612 Make_Defining_Identifier
(Loc
,
8613 Chars
=> New_External_Name
(Chars
(Typ
), "PredicateM"));
8614 -- The entity for the function body
8622 -- Mark any raise expressions for special expansion
8624 Process_REs
(Expr_M
);
8626 -- Build function declaration
8628 Set_Ekind
(SId
, E_Function
);
8629 Set_Is_Predicate_Function_M
(SId
);
8630 Set_Predicate_Function_M
(Typ
, SId
);
8632 -- The predicate function is shared between views of a type
8634 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
8635 Set_Predicate_Function_M
(Full_View
(Typ
), SId
);
8638 -- Mark the predicate function explicitly as Ghost because it
8639 -- does not come from source.
8641 if Ghost_Mode
> None
then
8642 Set_Is_Ghost_Entity
(SId
);
8646 Make_Function_Specification
(Loc
,
8647 Defining_Unit_Name
=> SId
,
8648 Parameter_Specifications
=> New_List
(
8649 Make_Parameter_Specification
(Loc
,
8650 Defining_Identifier
=> Object_Entity_M
,
8651 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))),
8652 Result_Definition
=>
8653 New_Occurrence_Of
(Standard_Boolean
, Loc
));
8656 Make_Subprogram_Declaration
(Loc
,
8657 Specification
=> Spec
);
8659 -- Build function body
8662 Make_Function_Specification
(Loc
,
8663 Defining_Unit_Name
=> SIdB
,
8664 Parameter_Specifications
=> New_List
(
8665 Make_Parameter_Specification
(Loc
,
8666 Defining_Identifier
=>
8667 Make_Defining_Identifier
(Loc
, Object_Name
),
8669 New_Occurrence_Of
(Typ
, Loc
))),
8670 Result_Definition
=>
8671 New_Occurrence_Of
(Standard_Boolean
, Loc
));
8673 -- Build the body, we declare the boolean expression before
8674 -- doing the return, because we are not really confident of
8675 -- what happens if a return appears within a return.
8678 Make_Defining_Identifier
(Loc
,
8679 Chars
=> New_Internal_Name
('B'));
8682 Make_Subprogram_Body
(Loc
,
8683 Specification
=> Spec
,
8685 Declarations
=> New_List
(
8686 Make_Object_Declaration
(Loc
,
8687 Defining_Identifier
=> BTemp
,
8688 Constant_Present
=> True,
8689 Object_Definition
=>
8690 New_Occurrence_Of
(Standard_Boolean
, Loc
),
8691 Expression
=> Expr_M
)),
8693 Handled_Statement_Sequence
=>
8694 Make_Handled_Sequence_Of_Statements
(Loc
,
8695 Statements
=> New_List
(
8696 Make_Simple_Return_Statement
(Loc
,
8697 Expression
=> New_Occurrence_Of
(BTemp
, Loc
)))));
8699 -- Insert declaration before freeze node and body after
8701 Insert_Before_And_Analyze
(N
, FDecl
);
8702 Insert_After_And_Analyze
(N
, FBody
);
8706 -- See if we have a static predicate. Note that the answer may be
8707 -- yes even if we have an explicit Dynamic_Predicate present.
8714 if not Is_Scalar_Type
(Typ
) and then not Is_String_Type
(Typ
) then
8717 PS
:= Is_Predicate_Static
(Expr
, Object_Name
);
8720 -- Case where we have a predicate-static aspect
8724 -- We don't set Has_Static_Predicate_Aspect, since we can have
8725 -- any of the three cases (Predicate, Dynamic_Predicate, or
8726 -- Static_Predicate) generating a predicate with an expression
8727 -- that is predicate-static. We just indicate that we have a
8728 -- predicate that can be treated as static.
8730 Set_Has_Static_Predicate
(Typ
);
8732 -- For discrete subtype, build the static predicate list
8734 if Is_Discrete_Type
(Typ
) then
8735 Build_Discrete_Static_Predicate
(Typ
, Expr
, Object_Name
);
8737 -- If we don't get a static predicate list, it means that we
8738 -- have a case where this is not possible, most typically in
8739 -- the case where we inherit a dynamic predicate. We do not
8740 -- consider this an error, we just leave the predicate as
8741 -- dynamic. But if we do succeed in building the list, then
8742 -- we mark the predicate as static.
8744 if No
(Static_Discrete_Predicate
(Typ
)) then
8745 Set_Has_Static_Predicate
(Typ
, False);
8748 -- For real or string subtype, save predicate expression
8750 elsif Is_Real_Type
(Typ
) or else Is_String_Type
(Typ
) then
8751 Set_Static_Real_Or_String_Predicate
(Typ
, Expr
);
8754 -- Case of dynamic predicate (expression is not predicate-static)
8757 -- Again, we don't set Has_Dynamic_Predicate_Aspect, since that
8758 -- is only set if we have an explicit Dynamic_Predicate aspect
8759 -- given. Here we may simply have a Predicate aspect where the
8760 -- expression happens not to be predicate-static.
8762 -- Emit an error when the predicate is categorized as static
8763 -- but its expression is not predicate-static.
8765 -- First a little fiddling to get a nice location for the
8766 -- message. If the expression is of the form (A and then B),
8767 -- where A is an inherited predicate, then use the right
8768 -- operand for the Sloc. This avoids getting confused by a call
8769 -- to an inherited predicate with a less convenient source
8773 while Nkind
(EN
) = N_And_Then
8774 and then Nkind
(Left_Opnd
(EN
)) = N_Function_Call
8775 and then Is_Predicate_Function
8776 (Entity
(Name
(Left_Opnd
(EN
))))
8778 EN
:= Right_Opnd
(EN
);
8781 -- Now post appropriate message
8783 if Has_Static_Predicate_Aspect
(Typ
) then
8784 if Is_Scalar_Type
(Typ
) or else Is_String_Type
(Typ
) then
8786 ("expression is not predicate-static (RM 3.2.4(16-22))",
8790 ("static predicate requires scalar or string type", EN
);
8797 Ghost_Mode
:= Save_Ghost_Mode
;
8798 end Build_Predicate_Functions
;
8800 ------------------------------------------
8801 -- Build_Predicate_Function_Declaration --
8802 ------------------------------------------
8804 function Build_Predicate_Function_Declaration
8805 (Typ
: Entity_Id
) return Node_Id
8807 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
8809 Object_Entity
: constant Entity_Id
:=
8810 Make_Defining_Identifier
(Loc
,
8811 Chars
=> New_Internal_Name
('I'));
8813 -- The formal parameter of the function
8815 SId
: constant Entity_Id
:=
8816 Make_Defining_Identifier
(Loc
,
8817 Chars
=> New_External_Name
(Chars
(Typ
), "Predicate"));
8819 -- The entity for the function spec
8826 Make_Function_Specification
(Loc
,
8827 Defining_Unit_Name
=> SId
,
8828 Parameter_Specifications
=> New_List
(
8829 Make_Parameter_Specification
(Loc
,
8830 Defining_Identifier
=> Object_Entity
,
8831 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))),
8832 Result_Definition
=>
8833 New_Occurrence_Of
(Standard_Boolean
, Loc
));
8835 FDecl
:= Make_Subprogram_Declaration
(Loc
, Specification
=> Spec
);
8837 Set_Ekind
(SId
, E_Function
);
8838 Set_Etype
(SId
, Standard_Boolean
);
8839 Set_Is_Internal
(SId
);
8840 Set_Is_Predicate_Function
(SId
);
8841 Set_Predicate_Function
(Typ
, SId
);
8843 Insert_After
(Parent
(Typ
), FDecl
);
8848 end Build_Predicate_Function_Declaration
;
8850 -----------------------------------------
8851 -- Check_Aspect_At_End_Of_Declarations --
8852 -----------------------------------------
8854 procedure Check_Aspect_At_End_Of_Declarations
(ASN
: Node_Id
) is
8855 Ent
: constant Entity_Id
:= Entity
(ASN
);
8856 Ident
: constant Node_Id
:= Identifier
(ASN
);
8857 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Chars
(Ident
));
8859 End_Decl_Expr
: constant Node_Id
:= Entity
(Ident
);
8860 -- Expression to be analyzed at end of declarations
8862 Freeze_Expr
: constant Node_Id
:= Expression
(ASN
);
8863 -- Expression from call to Check_Aspect_At_Freeze_Point
8865 T
: constant Entity_Id
:= Etype
(Freeze_Expr
);
8866 -- Type required for preanalyze call
8869 -- Set False if error
8871 -- On entry to this procedure, Entity (Ident) contains a copy of the
8872 -- original expression from the aspect, saved for this purpose, and
8873 -- but Expression (Ident) is a preanalyzed copy of the expression,
8874 -- preanalyzed just after the freeze point.
8876 procedure Check_Overloaded_Name
;
8877 -- For aspects whose expression is simply a name, this routine checks if
8878 -- the name is overloaded or not. If so, it verifies there is an
8879 -- interpretation that matches the entity obtained at the freeze point,
8880 -- otherwise the compiler complains.
8882 ---------------------------
8883 -- Check_Overloaded_Name --
8884 ---------------------------
8886 procedure Check_Overloaded_Name
is
8888 if not Is_Overloaded
(End_Decl_Expr
) then
8889 Err
:= not Is_Entity_Name
(End_Decl_Expr
)
8890 or else Entity
(End_Decl_Expr
) /= Entity
(Freeze_Expr
);
8896 Index
: Interp_Index
;
8900 Get_First_Interp
(End_Decl_Expr
, Index
, It
);
8901 while Present
(It
.Typ
) loop
8902 if It
.Nam
= Entity
(Freeze_Expr
) then
8907 Get_Next_Interp
(Index
, It
);
8911 end Check_Overloaded_Name
;
8913 -- Start of processing for Check_Aspect_At_End_Of_Declarations
8916 -- In an instance we do not perform the consistency check between freeze
8917 -- point and end of declarations, because it was done already in the
8918 -- analysis of the generic. Furthermore, the delayed analysis of an
8919 -- aspect of the instance may produce spurious errors when the generic
8920 -- is a child unit that references entities in the parent (which might
8921 -- not be in scope at the freeze point of the instance).
8926 -- Case of aspects Dimension, Dimension_System and Synchronization
8928 elsif A_Id
= Aspect_Synchronization
then
8931 -- Case of stream attributes, just have to compare entities. However,
8932 -- the expression is just a name (possibly overloaded), and there may
8933 -- be stream operations declared for unrelated types, so we just need
8934 -- to verify that one of these interpretations is the one available at
8935 -- at the freeze point.
8937 elsif A_Id
= Aspect_Input
or else
8938 A_Id
= Aspect_Output
or else
8939 A_Id
= Aspect_Read
or else
8942 Analyze
(End_Decl_Expr
);
8943 Check_Overloaded_Name
;
8945 elsif A_Id
= Aspect_Variable_Indexing
or else
8946 A_Id
= Aspect_Constant_Indexing
or else
8947 A_Id
= Aspect_Default_Iterator
or else
8948 A_Id
= Aspect_Iterator_Element
8950 -- Make type unfrozen before analysis, to prevent spurious errors
8951 -- about late attributes.
8953 Set_Is_Frozen
(Ent
, False);
8954 Analyze
(End_Decl_Expr
);
8955 Set_Is_Frozen
(Ent
, True);
8957 -- If the end of declarations comes before any other freeze
8958 -- point, the Freeze_Expr is not analyzed: no check needed.
8960 if Analyzed
(Freeze_Expr
) and then not In_Instance
then
8961 Check_Overloaded_Name
;
8969 -- Indicate that the expression comes from an aspect specification,
8970 -- which is used in subsequent analysis even if expansion is off.
8972 Set_Parent
(End_Decl_Expr
, ASN
);
8974 -- In a generic context the aspect expressions have not been
8975 -- preanalyzed, so do it now. There are no conformance checks
8976 -- to perform in this case.
8979 Check_Aspect_At_Freeze_Point
(ASN
);
8982 -- The default values attributes may be defined in the private part,
8983 -- and the analysis of the expression may take place when only the
8984 -- partial view is visible. The expression must be scalar, so use
8985 -- the full view to resolve.
8987 elsif (A_Id
= Aspect_Default_Value
8989 A_Id
= Aspect_Default_Component_Value
)
8990 and then Is_Private_Type
(T
)
8992 Preanalyze_Spec_Expression
(End_Decl_Expr
, Full_View
(T
));
8995 Preanalyze_Spec_Expression
(End_Decl_Expr
, T
);
8998 Err
:= not Fully_Conformant_Expressions
(End_Decl_Expr
, Freeze_Expr
);
9001 -- Output error message if error. Force error on aspect specification
9002 -- even if there is an error on the expression itself.
9006 ("!visibility of aspect for& changes after freeze point",
9009 ("info: & is frozen here, aspects evaluated at this point??",
9010 Freeze_Node
(Ent
), Ent
);
9012 end Check_Aspect_At_End_Of_Declarations
;
9014 ----------------------------------
9015 -- Check_Aspect_At_Freeze_Point --
9016 ----------------------------------
9018 procedure Check_Aspect_At_Freeze_Point
(ASN
: Node_Id
) is
9019 Ident
: constant Node_Id
:= Identifier
(ASN
);
9020 -- Identifier (use Entity field to save expression)
9022 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Chars
(Ident
));
9024 T
: Entity_Id
:= Empty
;
9025 -- Type required for preanalyze call
9028 -- On entry to this procedure, Entity (Ident) contains a copy of the
9029 -- original expression from the aspect, saved for this purpose.
9031 -- On exit from this procedure Entity (Ident) is unchanged, still
9032 -- containing that copy, but Expression (Ident) is a preanalyzed copy
9033 -- of the expression, preanalyzed just after the freeze point.
9035 -- Make a copy of the expression to be preanalyzed
9037 Set_Expression
(ASN
, New_Copy_Tree
(Entity
(Ident
)));
9039 -- Find type for preanalyze call
9043 -- No_Aspect should be impossible
9046 raise Program_Error
;
9048 -- Aspects taking an optional boolean argument
9050 when Boolean_Aspects |
9051 Library_Unit_Aspects
=>
9053 T
:= Standard_Boolean
;
9055 -- Aspects corresponding to attribute definition clauses
9057 when Aspect_Address
=>
9058 T
:= RTE
(RE_Address
);
9060 when Aspect_Attach_Handler
=>
9061 T
:= RTE
(RE_Interrupt_ID
);
9063 when Aspect_Bit_Order | Aspect_Scalar_Storage_Order
=>
9064 T
:= RTE
(RE_Bit_Order
);
9066 when Aspect_Convention
=>
9070 T
:= RTE
(RE_CPU_Range
);
9072 -- Default_Component_Value is resolved with the component type
9074 when Aspect_Default_Component_Value
=>
9075 T
:= Component_Type
(Entity
(ASN
));
9077 when Aspect_Default_Storage_Pool
=>
9078 T
:= Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
));
9080 -- Default_Value is resolved with the type entity in question
9082 when Aspect_Default_Value
=>
9085 when Aspect_Dispatching_Domain
=>
9086 T
:= RTE
(RE_Dispatching_Domain
);
9088 when Aspect_External_Tag
=>
9089 T
:= Standard_String
;
9091 when Aspect_External_Name
=>
9092 T
:= Standard_String
;
9094 when Aspect_Link_Name
=>
9095 T
:= Standard_String
;
9097 when Aspect_Priority | Aspect_Interrupt_Priority
=>
9098 T
:= Standard_Integer
;
9100 when Aspect_Relative_Deadline
=>
9101 T
:= RTE
(RE_Time_Span
);
9103 when Aspect_Small
=>
9104 T
:= Universal_Real
;
9106 -- For a simple storage pool, we have to retrieve the type of the
9107 -- pool object associated with the aspect's corresponding attribute
9108 -- definition clause.
9110 when Aspect_Simple_Storage_Pool
=>
9111 T
:= Etype
(Expression
(Aspect_Rep_Item
(ASN
)));
9113 when Aspect_Storage_Pool
=>
9114 T
:= Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
));
9116 when Aspect_Alignment |
9117 Aspect_Component_Size |
9118 Aspect_Machine_Radix |
9119 Aspect_Object_Size |
9121 Aspect_Storage_Size |
9122 Aspect_Stream_Size |
9123 Aspect_Value_Size
=>
9126 when Aspect_Linker_Section
=>
9127 T
:= Standard_String
;
9129 when Aspect_Synchronization
=>
9132 -- Special case, the expression of these aspects is just an entity
9133 -- that does not need any resolution, so just analyze.
9142 Analyze
(Expression
(ASN
));
9145 -- Same for Iterator aspects, where the expression is a function
9146 -- name. Legality rules are checked separately.
9148 when Aspect_Constant_Indexing |
9149 Aspect_Default_Iterator |
9150 Aspect_Iterator_Element |
9151 Aspect_Variable_Indexing
=>
9152 Analyze
(Expression
(ASN
));
9155 -- Ditto for Iterable, legality checks in Validate_Iterable_Aspect.
9157 when Aspect_Iterable
=>
9161 Cursor
: constant Entity_Id
:= Get_Cursor_Type
(ASN
, T
);
9166 if Cursor
= Any_Type
then
9170 Assoc
:= First
(Component_Associations
(Expression
(ASN
)));
9171 while Present
(Assoc
) loop
9172 Expr
:= Expression
(Assoc
);
9175 if not Error_Posted
(Expr
) then
9176 Resolve_Iterable_Operation
9177 (Expr
, Cursor
, T
, Chars
(First
(Choices
(Assoc
))));
9186 -- Invariant/Predicate take boolean expressions
9188 when Aspect_Dynamic_Predicate |
9191 Aspect_Static_Predicate |
9192 Aspect_Type_Invariant
=>
9193 T
:= Standard_Boolean
;
9195 when Aspect_Predicate_Failure
=>
9196 T
:= Standard_String
;
9198 -- Here is the list of aspects that don't require delay analysis
9200 when Aspect_Abstract_State |
9202 Aspect_Async_Readers |
9203 Aspect_Async_Writers |
9204 Aspect_Constant_After_Elaboration |
9205 Aspect_Contract_Cases |
9206 Aspect_Default_Initial_Condition |
9209 Aspect_Dimension_System |
9210 Aspect_Effective_Reads |
9211 Aspect_Effective_Writes |
9212 Aspect_Extensions_Visible |
9215 Aspect_Implicit_Dereference |
9216 Aspect_Initial_Condition |
9217 Aspect_Initializes |
9218 Aspect_Obsolescent |
9221 Aspect_Postcondition |
9223 Aspect_Precondition |
9224 Aspect_Refined_Depends |
9225 Aspect_Refined_Global |
9226 Aspect_Refined_Post |
9227 Aspect_Refined_State |
9230 Aspect_Unimplemented |
9231 Aspect_Volatile_Function
=>
9232 raise Program_Error
;
9236 -- Do the preanalyze call
9238 Preanalyze_Spec_Expression
(Expression
(ASN
), T
);
9239 end Check_Aspect_At_Freeze_Point
;
9241 -----------------------------------
9242 -- Check_Constant_Address_Clause --
9243 -----------------------------------
9245 procedure Check_Constant_Address_Clause
9249 procedure Check_At_Constant_Address
(Nod
: Node_Id
);
9250 -- Checks that the given node N represents a name whose 'Address is
9251 -- constant (in the same sense as OK_Constant_Address_Clause, i.e. the
9252 -- address value is the same at the point of declaration of U_Ent and at
9253 -- the time of elaboration of the address clause.
9255 procedure Check_Expr_Constants
(Nod
: Node_Id
);
9256 -- Checks that Nod meets the requirements for a constant address clause
9257 -- in the sense of the enclosing procedure.
9259 procedure Check_List_Constants
(Lst
: List_Id
);
9260 -- Check that all elements of list Lst meet the requirements for a
9261 -- constant address clause in the sense of the enclosing procedure.
9263 -------------------------------
9264 -- Check_At_Constant_Address --
9265 -------------------------------
9267 procedure Check_At_Constant_Address
(Nod
: Node_Id
) is
9269 if Is_Entity_Name
(Nod
) then
9270 if Present
(Address_Clause
(Entity
((Nod
)))) then
9272 ("invalid address clause for initialized object &!",
9275 ("address for& cannot" &
9276 " depend on another address clause! (RM 13.1(22))!",
9279 elsif In_Same_Source_Unit
(Entity
(Nod
), U_Ent
)
9280 and then Sloc
(U_Ent
) < Sloc
(Entity
(Nod
))
9283 ("invalid address clause for initialized object &!",
9285 Error_Msg_Node_2
:= U_Ent
;
9287 ("\& must be defined before & (RM 13.1(22))!",
9291 elsif Nkind
(Nod
) = N_Selected_Component
then
9293 T
: constant Entity_Id
:= Etype
(Prefix
(Nod
));
9296 if (Is_Record_Type
(T
)
9297 and then Has_Discriminants
(T
))
9300 and then Is_Record_Type
(Designated_Type
(T
))
9301 and then Has_Discriminants
(Designated_Type
(T
)))
9304 ("invalid address clause for initialized object &!",
9307 ("\address cannot depend on component" &
9308 " of discriminated record (RM 13.1(22))!",
9311 Check_At_Constant_Address
(Prefix
(Nod
));
9315 elsif Nkind
(Nod
) = N_Indexed_Component
then
9316 Check_At_Constant_Address
(Prefix
(Nod
));
9317 Check_List_Constants
(Expressions
(Nod
));
9320 Check_Expr_Constants
(Nod
);
9322 end Check_At_Constant_Address
;
9324 --------------------------
9325 -- Check_Expr_Constants --
9326 --------------------------
9328 procedure Check_Expr_Constants
(Nod
: Node_Id
) is
9329 Loc_U_Ent
: constant Source_Ptr
:= Sloc
(U_Ent
);
9330 Ent
: Entity_Id
:= Empty
;
9333 if Nkind
(Nod
) in N_Has_Etype
9334 and then Etype
(Nod
) = Any_Type
9340 when N_Empty | N_Error
=>
9343 when N_Identifier | N_Expanded_Name
=>
9344 Ent
:= Entity
(Nod
);
9346 -- We need to look at the original node if it is different
9347 -- from the node, since we may have rewritten things and
9348 -- substituted an identifier representing the rewrite.
9350 if Original_Node
(Nod
) /= Nod
then
9351 Check_Expr_Constants
(Original_Node
(Nod
));
9353 -- If the node is an object declaration without initial
9354 -- value, some code has been expanded, and the expression
9355 -- is not constant, even if the constituents might be
9356 -- acceptable, as in A'Address + offset.
9358 if Ekind
(Ent
) = E_Variable
9360 Nkind
(Declaration_Node
(Ent
)) = N_Object_Declaration
9362 No
(Expression
(Declaration_Node
(Ent
)))
9365 ("invalid address clause for initialized object &!",
9368 -- If entity is constant, it may be the result of expanding
9369 -- a check. We must verify that its declaration appears
9370 -- before the object in question, else we also reject the
9373 elsif Ekind
(Ent
) = E_Constant
9374 and then In_Same_Source_Unit
(Ent
, U_Ent
)
9375 and then Sloc
(Ent
) > Loc_U_Ent
9378 ("invalid address clause for initialized object &!",
9385 -- Otherwise look at the identifier and see if it is OK
9387 if Ekind_In
(Ent
, E_Named_Integer
, E_Named_Real
)
9388 or else Is_Type
(Ent
)
9392 elsif Ekind_In
(Ent
, E_Constant
, E_In_Parameter
) then
9394 -- This is the case where we must have Ent defined before
9395 -- U_Ent. Clearly if they are in different units this
9396 -- requirement is met since the unit containing Ent is
9397 -- already processed.
9399 if not In_Same_Source_Unit
(Ent
, U_Ent
) then
9402 -- Otherwise location of Ent must be before the location
9403 -- of U_Ent, that's what prior defined means.
9405 elsif Sloc
(Ent
) < Loc_U_Ent
then
9410 ("invalid address clause for initialized object &!",
9412 Error_Msg_Node_2
:= U_Ent
;
9414 ("\& must be defined before & (RM 13.1(22))!",
9418 elsif Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
9419 Check_Expr_Constants
(Original_Node
(Nod
));
9423 ("invalid address clause for initialized object &!",
9426 if Comes_From_Source
(Ent
) then
9428 ("\reference to variable& not allowed"
9429 & " (RM 13.1(22))!", Nod
, Ent
);
9432 ("non-static expression not allowed"
9433 & " (RM 13.1(22))!", Nod
);
9437 when N_Integer_Literal
=>
9439 -- If this is a rewritten unchecked conversion, in a system
9440 -- where Address is an integer type, always use the base type
9441 -- for a literal value. This is user-friendly and prevents
9442 -- order-of-elaboration issues with instances of unchecked
9445 if Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
9446 Set_Etype
(Nod
, Base_Type
(Etype
(Nod
)));
9449 when N_Real_Literal |
9451 N_Character_Literal
=>
9455 Check_Expr_Constants
(Low_Bound
(Nod
));
9456 Check_Expr_Constants
(High_Bound
(Nod
));
9458 when N_Explicit_Dereference
=>
9459 Check_Expr_Constants
(Prefix
(Nod
));
9461 when N_Indexed_Component
=>
9462 Check_Expr_Constants
(Prefix
(Nod
));
9463 Check_List_Constants
(Expressions
(Nod
));
9466 Check_Expr_Constants
(Prefix
(Nod
));
9467 Check_Expr_Constants
(Discrete_Range
(Nod
));
9469 when N_Selected_Component
=>
9470 Check_Expr_Constants
(Prefix
(Nod
));
9472 when N_Attribute_Reference
=>
9473 if Nam_In
(Attribute_Name
(Nod
), Name_Address
,
9475 Name_Unchecked_Access
,
9476 Name_Unrestricted_Access
)
9478 Check_At_Constant_Address
(Prefix
(Nod
));
9481 Check_Expr_Constants
(Prefix
(Nod
));
9482 Check_List_Constants
(Expressions
(Nod
));
9486 Check_List_Constants
(Component_Associations
(Nod
));
9487 Check_List_Constants
(Expressions
(Nod
));
9489 when N_Component_Association
=>
9490 Check_Expr_Constants
(Expression
(Nod
));
9492 when N_Extension_Aggregate
=>
9493 Check_Expr_Constants
(Ancestor_Part
(Nod
));
9494 Check_List_Constants
(Component_Associations
(Nod
));
9495 Check_List_Constants
(Expressions
(Nod
));
9500 when N_Binary_Op | N_Short_Circuit | N_Membership_Test
=>
9501 Check_Expr_Constants
(Left_Opnd
(Nod
));
9502 Check_Expr_Constants
(Right_Opnd
(Nod
));
9505 Check_Expr_Constants
(Right_Opnd
(Nod
));
9507 when N_Type_Conversion |
9508 N_Qualified_Expression |
9510 N_Unchecked_Type_Conversion
=>
9511 Check_Expr_Constants
(Expression
(Nod
));
9513 when N_Function_Call
=>
9514 if not Is_Pure
(Entity
(Name
(Nod
))) then
9516 ("invalid address clause for initialized object &!",
9520 ("\function & is not pure (RM 13.1(22))!",
9521 Nod
, Entity
(Name
(Nod
)));
9524 Check_List_Constants
(Parameter_Associations
(Nod
));
9527 when N_Parameter_Association
=>
9528 Check_Expr_Constants
(Explicit_Actual_Parameter
(Nod
));
9532 ("invalid address clause for initialized object &!",
9535 ("\must be constant defined before& (RM 13.1(22))!",
9538 end Check_Expr_Constants
;
9540 --------------------------
9541 -- Check_List_Constants --
9542 --------------------------
9544 procedure Check_List_Constants
(Lst
: List_Id
) is
9548 if Present
(Lst
) then
9549 Nod1
:= First
(Lst
);
9550 while Present
(Nod1
) loop
9551 Check_Expr_Constants
(Nod1
);
9555 end Check_List_Constants
;
9557 -- Start of processing for Check_Constant_Address_Clause
9560 -- If rep_clauses are to be ignored, no need for legality checks. In
9561 -- particular, no need to pester user about rep clauses that violate the
9562 -- rule on constant addresses, given that these clauses will be removed
9563 -- by Freeze before they reach the back end. Similarly in CodePeer mode,
9564 -- we want to relax these checks.
9566 if not Ignore_Rep_Clauses
and not CodePeer_Mode
then
9567 Check_Expr_Constants
(Expr
);
9569 end Check_Constant_Address_Clause
;
9571 ---------------------------
9572 -- Check_Pool_Size_Clash --
9573 ---------------------------
9575 procedure Check_Pool_Size_Clash
(Ent
: Entity_Id
; SP
, SS
: Node_Id
) is
9579 -- We need to find out which one came first. Note that in the case of
9580 -- aspects mixed with pragmas there are cases where the processing order
9581 -- is reversed, which is why we do the check here.
9583 if Sloc
(SP
) < Sloc
(SS
) then
9584 Error_Msg_Sloc
:= Sloc
(SP
);
9586 Error_Msg_NE
("Storage_Pool previously given for&#", Post
, Ent
);
9589 Error_Msg_Sloc
:= Sloc
(SS
);
9591 Error_Msg_NE
("Storage_Size previously given for&#", Post
, Ent
);
9595 ("\cannot have Storage_Size and Storage_Pool (RM 13.11(3))", Post
);
9596 end Check_Pool_Size_Clash
;
9598 ----------------------------------------
9599 -- Check_Record_Representation_Clause --
9600 ----------------------------------------
9602 procedure Check_Record_Representation_Clause
(N
: Node_Id
) is
9603 Loc
: constant Source_Ptr
:= Sloc
(N
);
9604 Ident
: constant Node_Id
:= Identifier
(N
);
9605 Rectype
: Entity_Id
;
9610 Hbit
: Uint
:= Uint_0
;
9614 Max_Bit_So_Far
: Uint
;
9615 -- Records the maximum bit position so far. If all field positions
9616 -- are monotonically increasing, then we can skip the circuit for
9617 -- checking for overlap, since no overlap is possible.
9619 Tagged_Parent
: Entity_Id
:= Empty
;
9620 -- This is set in the case of a derived tagged type for which we have
9621 -- Is_Fully_Repped_Tagged_Type True (indicating that all components are
9622 -- positioned by record representation clauses). In this case we must
9623 -- check for overlap between components of this tagged type, and the
9624 -- components of its parent. Tagged_Parent will point to this parent
9625 -- type. For all other cases Tagged_Parent is left set to Empty.
9627 Parent_Last_Bit
: Uint
;
9628 -- Relevant only if Tagged_Parent is set, Parent_Last_Bit indicates the
9629 -- last bit position for any field in the parent type. We only need to
9630 -- check overlap for fields starting below this point.
9632 Overlap_Check_Required
: Boolean;
9633 -- Used to keep track of whether or not an overlap check is required
9635 Overlap_Detected
: Boolean := False;
9636 -- Set True if an overlap is detected
9638 Ccount
: Natural := 0;
9639 -- Number of component clauses in record rep clause
9641 procedure Check_Component_Overlap
(C1_Ent
, C2_Ent
: Entity_Id
);
9642 -- Given two entities for record components or discriminants, checks
9643 -- if they have overlapping component clauses and issues errors if so.
9645 procedure Find_Component
;
9646 -- Finds component entity corresponding to current component clause (in
9647 -- CC), and sets Comp to the entity, and Fbit/Lbit to the zero origin
9648 -- start/stop bits for the field. If there is no matching component or
9649 -- if the matching component does not have a component clause, then
9650 -- that's an error and Comp is set to Empty, but no error message is
9651 -- issued, since the message was already given. Comp is also set to
9652 -- Empty if the current "component clause" is in fact a pragma.
9654 -----------------------------
9655 -- Check_Component_Overlap --
9656 -----------------------------
9658 procedure Check_Component_Overlap
(C1_Ent
, C2_Ent
: Entity_Id
) is
9659 CC1
: constant Node_Id
:= Component_Clause
(C1_Ent
);
9660 CC2
: constant Node_Id
:= Component_Clause
(C2_Ent
);
9663 if Present
(CC1
) and then Present
(CC2
) then
9665 -- Exclude odd case where we have two tag components in the same
9666 -- record, both at location zero. This seems a bit strange, but
9667 -- it seems to happen in some circumstances, perhaps on an error.
9669 if Nam_In
(Chars
(C1_Ent
), Name_uTag
, Name_uTag
) then
9673 -- Here we check if the two fields overlap
9676 S1
: constant Uint
:= Component_Bit_Offset
(C1_Ent
);
9677 S2
: constant Uint
:= Component_Bit_Offset
(C2_Ent
);
9678 E1
: constant Uint
:= S1
+ Esize
(C1_Ent
);
9679 E2
: constant Uint
:= S2
+ Esize
(C2_Ent
);
9682 if E2
<= S1
or else E1
<= S2
then
9685 Error_Msg_Node_2
:= Component_Name
(CC2
);
9686 Error_Msg_Sloc
:= Sloc
(Error_Msg_Node_2
);
9687 Error_Msg_Node_1
:= Component_Name
(CC1
);
9689 ("component& overlaps & #", Component_Name
(CC1
));
9690 Overlap_Detected
:= True;
9694 end Check_Component_Overlap
;
9696 --------------------
9697 -- Find_Component --
9698 --------------------
9700 procedure Find_Component
is
9702 procedure Search_Component
(R
: Entity_Id
);
9703 -- Search components of R for a match. If found, Comp is set
9705 ----------------------
9706 -- Search_Component --
9707 ----------------------
9709 procedure Search_Component
(R
: Entity_Id
) is
9711 Comp
:= First_Component_Or_Discriminant
(R
);
9712 while Present
(Comp
) loop
9714 -- Ignore error of attribute name for component name (we
9715 -- already gave an error message for this, so no need to
9718 if Nkind
(Component_Name
(CC
)) = N_Attribute_Reference
then
9721 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
9724 Next_Component_Or_Discriminant
(Comp
);
9726 end Search_Component
;
9728 -- Start of processing for Find_Component
9731 -- Return with Comp set to Empty if we have a pragma
9733 if Nkind
(CC
) = N_Pragma
then
9738 -- Search current record for matching component
9740 Search_Component
(Rectype
);
9742 -- If not found, maybe component of base type discriminant that is
9743 -- absent from statically constrained first subtype.
9746 Search_Component
(Base_Type
(Rectype
));
9749 -- If no component, or the component does not reference the component
9750 -- clause in question, then there was some previous error for which
9751 -- we already gave a message, so just return with Comp Empty.
9753 if No
(Comp
) or else Component_Clause
(Comp
) /= CC
then
9754 Check_Error_Detected
;
9757 -- Normal case where we have a component clause
9760 Fbit
:= Component_Bit_Offset
(Comp
);
9761 Lbit
:= Fbit
+ Esize
(Comp
) - 1;
9765 -- Start of processing for Check_Record_Representation_Clause
9769 Rectype
:= Entity
(Ident
);
9771 if Rectype
= Any_Type
then
9774 Rectype
:= Underlying_Type
(Rectype
);
9777 -- See if we have a fully repped derived tagged type
9780 PS
: constant Entity_Id
:= Parent_Subtype
(Rectype
);
9783 if Present
(PS
) and then Is_Fully_Repped_Tagged_Type
(PS
) then
9784 Tagged_Parent
:= PS
;
9786 -- Find maximum bit of any component of the parent type
9788 Parent_Last_Bit
:= UI_From_Int
(System_Address_Size
- 1);
9789 Pcomp
:= First_Entity
(Tagged_Parent
);
9790 while Present
(Pcomp
) loop
9791 if Ekind_In
(Pcomp
, E_Discriminant
, E_Component
) then
9792 if Component_Bit_Offset
(Pcomp
) /= No_Uint
9793 and then Known_Static_Esize
(Pcomp
)
9798 Component_Bit_Offset
(Pcomp
) + Esize
(Pcomp
) - 1);
9802 -- Skip anonymous types generated for constrained array
9803 -- or record components.
9808 Next_Entity
(Pcomp
);
9813 -- All done if no component clauses
9815 CC
:= First
(Component_Clauses
(N
));
9821 -- If a tag is present, then create a component clause that places it
9822 -- at the start of the record (otherwise gigi may place it after other
9823 -- fields that have rep clauses).
9825 Fent
:= First_Entity
(Rectype
);
9827 if Nkind
(Fent
) = N_Defining_Identifier
9828 and then Chars
(Fent
) = Name_uTag
9830 Set_Component_Bit_Offset
(Fent
, Uint_0
);
9831 Set_Normalized_Position
(Fent
, Uint_0
);
9832 Set_Normalized_First_Bit
(Fent
, Uint_0
);
9833 Set_Normalized_Position_Max
(Fent
, Uint_0
);
9834 Init_Esize
(Fent
, System_Address_Size
);
9836 Set_Component_Clause
(Fent
,
9837 Make_Component_Clause
(Loc
,
9838 Component_Name
=> Make_Identifier
(Loc
, Name_uTag
),
9840 Position
=> Make_Integer_Literal
(Loc
, Uint_0
),
9841 First_Bit
=> Make_Integer_Literal
(Loc
, Uint_0
),
9843 Make_Integer_Literal
(Loc
,
9844 UI_From_Int
(System_Address_Size
))));
9846 Ccount
:= Ccount
+ 1;
9849 Max_Bit_So_Far
:= Uint_Minus_1
;
9850 Overlap_Check_Required
:= False;
9852 -- Process the component clauses
9854 while Present
(CC
) loop
9857 if Present
(Comp
) then
9858 Ccount
:= Ccount
+ 1;
9860 -- We need a full overlap check if record positions non-monotonic
9862 if Fbit
<= Max_Bit_So_Far
then
9863 Overlap_Check_Required
:= True;
9866 Max_Bit_So_Far
:= Lbit
;
9868 -- Check bit position out of range of specified size
9870 if Has_Size_Clause
(Rectype
)
9871 and then RM_Size
(Rectype
) <= Lbit
9874 ("bit number out of range of specified size",
9877 -- Check for overlap with tag component
9880 if Is_Tagged_Type
(Rectype
)
9881 and then Fbit
< System_Address_Size
9884 ("component overlaps tag field of&",
9885 Component_Name
(CC
), Rectype
);
9886 Overlap_Detected
:= True;
9894 -- Check parent overlap if component might overlap parent field
9896 if Present
(Tagged_Parent
) and then Fbit
<= Parent_Last_Bit
then
9897 Pcomp
:= First_Component_Or_Discriminant
(Tagged_Parent
);
9898 while Present
(Pcomp
) loop
9899 if not Is_Tag
(Pcomp
)
9900 and then Chars
(Pcomp
) /= Name_uParent
9902 Check_Component_Overlap
(Comp
, Pcomp
);
9905 Next_Component_Or_Discriminant
(Pcomp
);
9913 -- Now that we have processed all the component clauses, check for
9914 -- overlap. We have to leave this till last, since the components can
9915 -- appear in any arbitrary order in the representation clause.
9917 -- We do not need this check if all specified ranges were monotonic,
9918 -- as recorded by Overlap_Check_Required being False at this stage.
9920 -- This first section checks if there are any overlapping entries at
9921 -- all. It does this by sorting all entries and then seeing if there are
9922 -- any overlaps. If there are none, then that is decisive, but if there
9923 -- are overlaps, they may still be OK (they may result from fields in
9924 -- different variants).
9926 if Overlap_Check_Required
then
9927 Overlap_Check1
: declare
9929 OC_Fbit
: array (0 .. Ccount
) of Uint
;
9930 -- First-bit values for component clauses, the value is the offset
9931 -- of the first bit of the field from start of record. The zero
9932 -- entry is for use in sorting.
9934 OC_Lbit
: array (0 .. Ccount
) of Uint
;
9935 -- Last-bit values for component clauses, the value is the offset
9936 -- of the last bit of the field from start of record. The zero
9937 -- entry is for use in sorting.
9939 OC_Count
: Natural := 0;
9940 -- Count of entries in OC_Fbit and OC_Lbit
9942 function OC_Lt
(Op1
, Op2
: Natural) return Boolean;
9943 -- Compare routine for Sort
9945 procedure OC_Move
(From
: Natural; To
: Natural);
9946 -- Move routine for Sort
9948 package Sorting
is new GNAT
.Heap_Sort_G
(OC_Move
, OC_Lt
);
9954 function OC_Lt
(Op1
, Op2
: Natural) return Boolean is
9956 return OC_Fbit
(Op1
) < OC_Fbit
(Op2
);
9963 procedure OC_Move
(From
: Natural; To
: Natural) is
9965 OC_Fbit
(To
) := OC_Fbit
(From
);
9966 OC_Lbit
(To
) := OC_Lbit
(From
);
9969 -- Start of processing for Overlap_Check
9972 CC
:= First
(Component_Clauses
(N
));
9973 while Present
(CC
) loop
9975 -- Exclude component clause already marked in error
9977 if not Error_Posted
(CC
) then
9980 if Present
(Comp
) then
9981 OC_Count
:= OC_Count
+ 1;
9982 OC_Fbit
(OC_Count
) := Fbit
;
9983 OC_Lbit
(OC_Count
) := Lbit
;
9990 Sorting
.Sort
(OC_Count
);
9992 Overlap_Check_Required
:= False;
9993 for J
in 1 .. OC_Count
- 1 loop
9994 if OC_Lbit
(J
) >= OC_Fbit
(J
+ 1) then
9995 Overlap_Check_Required
:= True;
10002 -- If Overlap_Check_Required is still True, then we have to do the full
10003 -- scale overlap check, since we have at least two fields that do
10004 -- overlap, and we need to know if that is OK since they are in
10005 -- different variant, or whether we have a definite problem.
10007 if Overlap_Check_Required
then
10008 Overlap_Check2
: declare
10009 C1_Ent
, C2_Ent
: Entity_Id
;
10010 -- Entities of components being checked for overlap
10013 -- Component_List node whose Component_Items are being checked
10016 -- Component declaration for component being checked
10019 C1_Ent
:= First_Entity
(Base_Type
(Rectype
));
10021 -- Loop through all components in record. For each component check
10022 -- for overlap with any of the preceding elements on the component
10023 -- list containing the component and also, if the component is in
10024 -- a variant, check against components outside the case structure.
10025 -- This latter test is repeated recursively up the variant tree.
10027 Main_Component_Loop
: while Present
(C1_Ent
) loop
10028 if not Ekind_In
(C1_Ent
, E_Component
, E_Discriminant
) then
10029 goto Continue_Main_Component_Loop
;
10032 -- Skip overlap check if entity has no declaration node. This
10033 -- happens with discriminants in constrained derived types.
10034 -- Possibly we are missing some checks as a result, but that
10035 -- does not seem terribly serious.
10037 if No
(Declaration_Node
(C1_Ent
)) then
10038 goto Continue_Main_Component_Loop
;
10041 Clist
:= Parent
(List_Containing
(Declaration_Node
(C1_Ent
)));
10043 -- Loop through component lists that need checking. Check the
10044 -- current component list and all lists in variants above us.
10046 Component_List_Loop
: loop
10048 -- If derived type definition, go to full declaration
10049 -- If at outer level, check discriminants if there are any.
10051 if Nkind
(Clist
) = N_Derived_Type_Definition
then
10052 Clist
:= Parent
(Clist
);
10055 -- Outer level of record definition, check discriminants
10057 if Nkind_In
(Clist
, N_Full_Type_Declaration
,
10058 N_Private_Type_Declaration
)
10060 if Has_Discriminants
(Defining_Identifier
(Clist
)) then
10062 First_Discriminant
(Defining_Identifier
(Clist
));
10063 while Present
(C2_Ent
) loop
10064 exit when C1_Ent
= C2_Ent
;
10065 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
10066 Next_Discriminant
(C2_Ent
);
10070 -- Record extension case
10072 elsif Nkind
(Clist
) = N_Derived_Type_Definition
then
10075 -- Otherwise check one component list
10078 Citem
:= First
(Component_Items
(Clist
));
10079 while Present
(Citem
) loop
10080 if Nkind
(Citem
) = N_Component_Declaration
then
10081 C2_Ent
:= Defining_Identifier
(Citem
);
10082 exit when C1_Ent
= C2_Ent
;
10083 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
10090 -- Check for variants above us (the parent of the Clist can
10091 -- be a variant, in which case its parent is a variant part,
10092 -- and the parent of the variant part is a component list
10093 -- whose components must all be checked against the current
10094 -- component for overlap).
10096 if Nkind
(Parent
(Clist
)) = N_Variant
then
10097 Clist
:= Parent
(Parent
(Parent
(Clist
)));
10099 -- Check for possible discriminant part in record, this
10100 -- is treated essentially as another level in the
10101 -- recursion. For this case the parent of the component
10102 -- list is the record definition, and its parent is the
10103 -- full type declaration containing the discriminant
10106 elsif Nkind
(Parent
(Clist
)) = N_Record_Definition
then
10107 Clist
:= Parent
(Parent
((Clist
)));
10109 -- If neither of these two cases, we are at the top of
10113 exit Component_List_Loop
;
10115 end loop Component_List_Loop
;
10117 <<Continue_Main_Component_Loop
>>
10118 Next_Entity
(C1_Ent
);
10120 end loop Main_Component_Loop
;
10121 end Overlap_Check2
;
10124 -- The following circuit deals with warning on record holes (gaps). We
10125 -- skip this check if overlap was detected, since it makes sense for the
10126 -- programmer to fix this illegality before worrying about warnings.
10128 if not Overlap_Detected
and Warn_On_Record_Holes
then
10129 Record_Hole_Check
: declare
10130 Decl
: constant Node_Id
:= Declaration_Node
(Base_Type
(Rectype
));
10131 -- Full declaration of record type
10133 procedure Check_Component_List
10137 -- Check component list CL for holes. The starting bit should be
10138 -- Sbit. which is zero for the main record component list and set
10139 -- appropriately for recursive calls for variants. DS is set to
10140 -- a list of discriminant specifications to be included in the
10141 -- consideration of components. It is No_List if none to consider.
10143 --------------------------
10144 -- Check_Component_List --
10145 --------------------------
10147 procedure Check_Component_List
10155 Compl
:= Integer (List_Length
(Component_Items
(CL
)));
10157 if DS
/= No_List
then
10158 Compl
:= Compl
+ Integer (List_Length
(DS
));
10162 Comps
: array (Natural range 0 .. Compl
) of Entity_Id
;
10163 -- Gather components (zero entry is for sort routine)
10165 Ncomps
: Natural := 0;
10166 -- Number of entries stored in Comps (starting at Comps (1))
10169 -- One component item or discriminant specification
10172 -- Starting bit for next component
10175 -- Component entity
10180 function Lt
(Op1
, Op2
: Natural) return Boolean;
10181 -- Compare routine for Sort
10183 procedure Move
(From
: Natural; To
: Natural);
10184 -- Move routine for Sort
10186 package Sorting
is new GNAT
.Heap_Sort_G
(Move
, Lt
);
10192 function Lt
(Op1
, Op2
: Natural) return Boolean is
10194 return Component_Bit_Offset
(Comps
(Op1
))
10196 Component_Bit_Offset
(Comps
(Op2
));
10203 procedure Move
(From
: Natural; To
: Natural) is
10205 Comps
(To
) := Comps
(From
);
10209 -- Gather discriminants into Comp
10211 if DS
/= No_List
then
10212 Citem
:= First
(DS
);
10213 while Present
(Citem
) loop
10214 if Nkind
(Citem
) = N_Discriminant_Specification
then
10216 Ent
: constant Entity_Id
:=
10217 Defining_Identifier
(Citem
);
10219 if Ekind
(Ent
) = E_Discriminant
then
10220 Ncomps
:= Ncomps
+ 1;
10221 Comps
(Ncomps
) := Ent
;
10230 -- Gather component entities into Comp
10232 Citem
:= First
(Component_Items
(CL
));
10233 while Present
(Citem
) loop
10234 if Nkind
(Citem
) = N_Component_Declaration
then
10235 Ncomps
:= Ncomps
+ 1;
10236 Comps
(Ncomps
) := Defining_Identifier
(Citem
);
10242 -- Now sort the component entities based on the first bit.
10243 -- Note we already know there are no overlapping components.
10245 Sorting
.Sort
(Ncomps
);
10247 -- Loop through entries checking for holes
10250 for J
in 1 .. Ncomps
loop
10252 Error_Msg_Uint_1
:= Component_Bit_Offset
(CEnt
) - Nbit
;
10254 if Error_Msg_Uint_1
> 0 then
10256 ("?H?^-bit gap before component&",
10257 Component_Name
(Component_Clause
(CEnt
)), CEnt
);
10260 Nbit
:= Component_Bit_Offset
(CEnt
) + Esize
(CEnt
);
10263 -- Process variant parts recursively if present
10265 if Present
(Variant_Part
(CL
)) then
10266 Variant
:= First
(Variants
(Variant_Part
(CL
)));
10267 while Present
(Variant
) loop
10268 Check_Component_List
10269 (Component_List
(Variant
), Nbit
, No_List
);
10274 end Check_Component_List
;
10276 -- Start of processing for Record_Hole_Check
10283 if Is_Tagged_Type
(Rectype
) then
10284 Sbit
:= UI_From_Int
(System_Address_Size
);
10289 if Nkind
(Decl
) = N_Full_Type_Declaration
10290 and then Nkind
(Type_Definition
(Decl
)) = N_Record_Definition
10292 Check_Component_List
10293 (Component_List
(Type_Definition
(Decl
)),
10295 Discriminant_Specifications
(Decl
));
10298 end Record_Hole_Check
;
10301 -- For records that have component clauses for all components, and whose
10302 -- size is less than or equal to 32, we need to know the size in the
10303 -- front end to activate possible packed array processing where the
10304 -- component type is a record.
10306 -- At this stage Hbit + 1 represents the first unused bit from all the
10307 -- component clauses processed, so if the component clauses are
10308 -- complete, then this is the length of the record.
10310 -- For records longer than System.Storage_Unit, and for those where not
10311 -- all components have component clauses, the back end determines the
10312 -- length (it may for example be appropriate to round up the size
10313 -- to some convenient boundary, based on alignment considerations, etc).
10315 if Unknown_RM_Size
(Rectype
) and then Hbit
+ 1 <= 32 then
10317 -- Nothing to do if at least one component has no component clause
10319 Comp
:= First_Component_Or_Discriminant
(Rectype
);
10320 while Present
(Comp
) loop
10321 exit when No
(Component_Clause
(Comp
));
10322 Next_Component_Or_Discriminant
(Comp
);
10325 -- If we fall out of loop, all components have component clauses
10326 -- and so we can set the size to the maximum value.
10329 Set_RM_Size
(Rectype
, Hbit
+ 1);
10332 end Check_Record_Representation_Clause
;
10338 procedure Check_Size
10342 Biased
: out Boolean)
10344 procedure Size_Too_Small_Error
(Min_Siz
: Uint
);
10345 -- Emit an error concerning illegal size Siz. Min_Siz denotes the
10348 --------------------------
10349 -- Size_Too_Small_Error --
10350 --------------------------
10352 procedure Size_Too_Small_Error
(Min_Siz
: Uint
) is
10354 -- This error is suppressed in ASIS mode to allow for different ASIS
10355 -- back ends or ASIS-based tools to query the illegal clause.
10357 if not ASIS_Mode
then
10358 Error_Msg_Uint_1
:= Min_Siz
;
10359 Error_Msg_NE
("size for& too small, minimum allowed is ^", N
, T
);
10361 end Size_Too_Small_Error
;
10365 UT
: constant Entity_Id
:= Underlying_Type
(T
);
10368 -- Start of processing for Check_Size
10373 -- Reject patently improper size values
10375 if Is_Elementary_Type
(T
)
10376 and then Siz
> UI_From_Int
(Int
'Last)
10378 Error_Msg_N
("Size value too large for elementary type", N
);
10380 if Nkind
(Original_Node
(N
)) = N_Op_Expon
then
10382 ("\maybe '* was meant, rather than '*'*", Original_Node
(N
));
10386 -- Dismiss generic types
10388 if Is_Generic_Type
(T
)
10390 Is_Generic_Type
(UT
)
10392 Is_Generic_Type
(Root_Type
(UT
))
10396 -- Guard against previous errors
10398 elsif No
(UT
) or else UT
= Any_Type
then
10399 Check_Error_Detected
;
10402 -- Check case of bit packed array
10404 elsif Is_Array_Type
(UT
)
10405 and then Known_Static_Component_Size
(UT
)
10406 and then Is_Bit_Packed_Array
(UT
)
10414 Asiz
:= Component_Size
(UT
);
10415 Indx
:= First_Index
(UT
);
10417 Ityp
:= Etype
(Indx
);
10419 -- If non-static bound, then we are not in the business of
10420 -- trying to check the length, and indeed an error will be
10421 -- issued elsewhere, since sizes of non-static array types
10422 -- cannot be set implicitly or explicitly.
10424 if not Is_OK_Static_Subtype
(Ityp
) then
10428 -- Otherwise accumulate next dimension
10430 Asiz
:= Asiz
* (Expr_Value
(Type_High_Bound
(Ityp
)) -
10431 Expr_Value
(Type_Low_Bound
(Ityp
)) +
10435 exit when No
(Indx
);
10438 if Asiz
<= Siz
then
10442 Size_Too_Small_Error
(Asiz
);
10443 Set_Esize
(T
, Asiz
);
10444 Set_RM_Size
(T
, Asiz
);
10448 -- All other composite types are ignored
10450 elsif Is_Composite_Type
(UT
) then
10453 -- For fixed-point types, don't check minimum if type is not frozen,
10454 -- since we don't know all the characteristics of the type that can
10455 -- affect the size (e.g. a specified small) till freeze time.
10457 elsif Is_Fixed_Point_Type
(UT
) and then not Is_Frozen
(UT
) then
10460 -- Cases for which a minimum check is required
10463 -- Ignore if specified size is correct for the type
10465 if Known_Esize
(UT
) and then Siz
= Esize
(UT
) then
10469 -- Otherwise get minimum size
10471 M
:= UI_From_Int
(Minimum_Size
(UT
));
10475 -- Size is less than minimum size, but one possibility remains
10476 -- that we can manage with the new size if we bias the type.
10478 M
:= UI_From_Int
(Minimum_Size
(UT
, Biased
=> True));
10481 Size_Too_Small_Error
(M
);
10483 Set_RM_Size
(T
, M
);
10491 --------------------------
10492 -- Freeze_Entity_Checks --
10493 --------------------------
10495 procedure Freeze_Entity_Checks
(N
: Node_Id
) is
10496 procedure Hide_Non_Overridden_Subprograms
(Typ
: Entity_Id
);
10497 -- Inspect the primitive operations of type Typ and hide all pairs of
10498 -- implicitly declared non-overridden non-fully conformant homographs
10499 -- (Ada RM 8.3 12.3/2).
10501 -------------------------------------
10502 -- Hide_Non_Overridden_Subprograms --
10503 -------------------------------------
10505 procedure Hide_Non_Overridden_Subprograms
(Typ
: Entity_Id
) is
10506 procedure Hide_Matching_Homographs
10507 (Subp_Id
: Entity_Id
;
10508 Start_Elmt
: Elmt_Id
);
10509 -- Inspect a list of primitive operations starting with Start_Elmt
10510 -- and find matching implicitly declared non-overridden non-fully
10511 -- conformant homographs of Subp_Id. If found, all matches along
10512 -- with Subp_Id are hidden from all visibility.
10514 function Is_Non_Overridden_Or_Null_Procedure
10515 (Subp_Id
: Entity_Id
) return Boolean;
10516 -- Determine whether subprogram Subp_Id is implicitly declared non-
10517 -- overridden subprogram or an implicitly declared null procedure.
10519 ------------------------------
10520 -- Hide_Matching_Homographs --
10521 ------------------------------
10523 procedure Hide_Matching_Homographs
10524 (Subp_Id
: Entity_Id
;
10525 Start_Elmt
: Elmt_Id
)
10528 Prim_Elmt
: Elmt_Id
;
10531 Prim_Elmt
:= Start_Elmt
;
10532 while Present
(Prim_Elmt
) loop
10533 Prim
:= Node
(Prim_Elmt
);
10535 -- The current primitive is implicitly declared non-overridden
10536 -- non-fully conformant homograph of Subp_Id. Both subprograms
10537 -- must be hidden from visibility.
10539 if Chars
(Prim
) = Chars
(Subp_Id
)
10540 and then Is_Non_Overridden_Or_Null_Procedure
(Prim
)
10541 and then not Fully_Conformant
(Prim
, Subp_Id
)
10543 Set_Is_Hidden_Non_Overridden_Subpgm
(Prim
);
10544 Set_Is_Immediately_Visible
(Prim
, False);
10545 Set_Is_Potentially_Use_Visible
(Prim
, False);
10547 Set_Is_Hidden_Non_Overridden_Subpgm
(Subp_Id
);
10548 Set_Is_Immediately_Visible
(Subp_Id
, False);
10549 Set_Is_Potentially_Use_Visible
(Subp_Id
, False);
10552 Next_Elmt
(Prim_Elmt
);
10554 end Hide_Matching_Homographs
;
10556 -----------------------------------------
10557 -- Is_Non_Overridden_Or_Null_Procedure --
10558 -----------------------------------------
10560 function Is_Non_Overridden_Or_Null_Procedure
10561 (Subp_Id
: Entity_Id
) return Boolean
10563 Alias_Id
: Entity_Id
;
10566 -- The subprogram is inherited (implicitly declared), it does not
10567 -- override and does not cover a primitive of an interface.
10569 if Ekind_In
(Subp_Id
, E_Function
, E_Procedure
)
10570 and then Present
(Alias
(Subp_Id
))
10571 and then No
(Interface_Alias
(Subp_Id
))
10572 and then No
(Overridden_Operation
(Subp_Id
))
10574 Alias_Id
:= Alias
(Subp_Id
);
10576 if Requires_Overriding
(Alias_Id
) then
10579 elsif Nkind
(Parent
(Alias_Id
)) = N_Procedure_Specification
10580 and then Null_Present
(Parent
(Alias_Id
))
10587 end Is_Non_Overridden_Or_Null_Procedure
;
10591 Prim_Ops
: constant Elist_Id
:= Direct_Primitive_Operations
(Typ
);
10593 Prim_Elmt
: Elmt_Id
;
10595 -- Start of processing for Hide_Non_Overridden_Subprograms
10598 -- Inspect the list of primitives looking for non-overridden
10601 if Present
(Prim_Ops
) then
10602 Prim_Elmt
:= First_Elmt
(Prim_Ops
);
10603 while Present
(Prim_Elmt
) loop
10604 Prim
:= Node
(Prim_Elmt
);
10605 Next_Elmt
(Prim_Elmt
);
10607 if Is_Non_Overridden_Or_Null_Procedure
(Prim
) then
10608 Hide_Matching_Homographs
10610 Start_Elmt
=> Prim_Elmt
);
10614 end Hide_Non_Overridden_Subprograms
;
10618 E
: constant Entity_Id
:= Entity
(N
);
10620 Non_Generic_Case
: constant Boolean := Nkind
(N
) = N_Freeze_Entity
;
10621 -- True in non-generic case. Some of the processing here is skipped
10622 -- for the generic case since it is not needed. Basically in the
10623 -- generic case, we only need to do stuff that might generate error
10624 -- messages or warnings.
10626 -- Start of processing for Freeze_Entity_Checks
10629 -- Remember that we are processing a freezing entity. Required to
10630 -- ensure correct decoration of internal entities associated with
10631 -- interfaces (see New_Overloaded_Entity).
10633 Inside_Freezing_Actions
:= Inside_Freezing_Actions
+ 1;
10635 -- For tagged types covering interfaces add internal entities that link
10636 -- the primitives of the interfaces with the primitives that cover them.
10637 -- Note: These entities were originally generated only when generating
10638 -- code because their main purpose was to provide support to initialize
10639 -- the secondary dispatch tables. They are now generated also when
10640 -- compiling with no code generation to provide ASIS the relationship
10641 -- between interface primitives and tagged type primitives. They are
10642 -- also used to locate primitives covering interfaces when processing
10643 -- generics (see Derive_Subprograms).
10645 -- This is not needed in the generic case
10647 if Ada_Version
>= Ada_2005
10648 and then Non_Generic_Case
10649 and then Ekind
(E
) = E_Record_Type
10650 and then Is_Tagged_Type
(E
)
10651 and then not Is_Interface
(E
)
10652 and then Has_Interfaces
(E
)
10654 -- This would be a good common place to call the routine that checks
10655 -- overriding of interface primitives (and thus factorize calls to
10656 -- Check_Abstract_Overriding located at different contexts in the
10657 -- compiler). However, this is not possible because it causes
10658 -- spurious errors in case of late overriding.
10660 Add_Internal_Interface_Entities
(E
);
10663 -- After all forms of overriding have been resolved, a tagged type may
10664 -- be left with a set of implicitly declared and possibly erroneous
10665 -- abstract subprograms, null procedures and subprograms that require
10666 -- overriding. If this set contains fully conformant homographs, then
10667 -- one is chosen arbitrarily (already done during resolution), otherwise
10668 -- all remaining non-fully conformant homographs are hidden from
10669 -- visibility (Ada RM 8.3 12.3/2).
10671 if Is_Tagged_Type
(E
) then
10672 Hide_Non_Overridden_Subprograms
(E
);
10677 if Ekind
(E
) = E_Record_Type
10678 and then Is_CPP_Class
(E
)
10679 and then Is_Tagged_Type
(E
)
10680 and then Tagged_Type_Expansion
10682 if CPP_Num_Prims
(E
) = 0 then
10684 -- If the CPP type has user defined components then it must import
10685 -- primitives from C++. This is required because if the C++ class
10686 -- has no primitives then the C++ compiler does not added the _tag
10687 -- component to the type.
10689 if First_Entity
(E
) /= Last_Entity
(E
) then
10691 ("'C'P'P type must import at least one primitive from C++??",
10696 -- Check that all its primitives are abstract or imported from C++.
10697 -- Check also availability of the C++ constructor.
10700 Has_Constructors
: constant Boolean := Has_CPP_Constructors
(E
);
10702 Error_Reported
: Boolean := False;
10706 Elmt
:= First_Elmt
(Primitive_Operations
(E
));
10707 while Present
(Elmt
) loop
10708 Prim
:= Node
(Elmt
);
10710 if Comes_From_Source
(Prim
) then
10711 if Is_Abstract_Subprogram
(Prim
) then
10714 elsif not Is_Imported
(Prim
)
10715 or else Convention
(Prim
) /= Convention_CPP
10718 ("primitives of 'C'P'P types must be imported from C++ "
10719 & "or abstract??", Prim
);
10721 elsif not Has_Constructors
10722 and then not Error_Reported
10724 Error_Msg_Name_1
:= Chars
(E
);
10726 ("??'C'P'P constructor required for type %", Prim
);
10727 Error_Reported
:= True;
10736 -- Check Ada derivation of CPP type
10738 if Expander_Active
-- why? losing errors in -gnatc mode???
10739 and then Present
(Etype
(E
)) -- defend against errors
10740 and then Tagged_Type_Expansion
10741 and then Ekind
(E
) = E_Record_Type
10742 and then Etype
(E
) /= E
10743 and then Is_CPP_Class
(Etype
(E
))
10744 and then CPP_Num_Prims
(Etype
(E
)) > 0
10745 and then not Is_CPP_Class
(E
)
10746 and then not Has_CPP_Constructors
(Etype
(E
))
10748 -- If the parent has C++ primitives but it has no constructor then
10749 -- check that all the primitives are overridden in this derivation;
10750 -- otherwise the constructor of the parent is needed to build the
10758 Elmt
:= First_Elmt
(Primitive_Operations
(E
));
10759 while Present
(Elmt
) loop
10760 Prim
:= Node
(Elmt
);
10762 if not Is_Abstract_Subprogram
(Prim
)
10763 and then No
(Interface_Alias
(Prim
))
10764 and then Find_Dispatching_Type
(Ultimate_Alias
(Prim
)) /= E
10766 Error_Msg_Name_1
:= Chars
(Etype
(E
));
10768 ("'C'P'P constructor required for parent type %", E
);
10777 Inside_Freezing_Actions
:= Inside_Freezing_Actions
- 1;
10779 -- If we have a type with predicates, build predicate function. This is
10780 -- not needed in the generic case, nor within TSS subprograms and other
10781 -- predefined primitives.
10784 and then Non_Generic_Case
10785 and then not Within_Internal_Subprogram
10786 and then Has_Predicates
(E
)
10788 Build_Predicate_Functions
(E
, N
);
10791 -- If type has delayed aspects, this is where we do the preanalysis at
10792 -- the freeze point, as part of the consistent visibility check. Note
10793 -- that this must be done after calling Build_Predicate_Functions or
10794 -- Build_Invariant_Procedure since these subprograms fix occurrences of
10795 -- the subtype name in the saved expression so that they will not cause
10796 -- trouble in the preanalysis.
10798 -- This is also not needed in the generic case
10800 if Non_Generic_Case
10801 and then Has_Delayed_Aspects
(E
)
10802 and then Scope
(E
) = Current_Scope
10804 -- Retrieve the visibility to the discriminants in order to properly
10805 -- analyze the aspects.
10807 Push_Scope_And_Install_Discriminants
(E
);
10813 -- Look for aspect specification entries for this entity
10815 Ritem
:= First_Rep_Item
(E
);
10816 while Present
(Ritem
) loop
10817 if Nkind
(Ritem
) = N_Aspect_Specification
10818 and then Entity
(Ritem
) = E
10819 and then Is_Delayed_Aspect
(Ritem
)
10821 Check_Aspect_At_Freeze_Point
(Ritem
);
10824 Next_Rep_Item
(Ritem
);
10828 Uninstall_Discriminants_And_Pop_Scope
(E
);
10831 -- For a record type, deal with variant parts. This has to be delayed
10832 -- to this point, because of the issue of statically predicated
10833 -- subtypes, which we have to ensure are frozen before checking
10834 -- choices, since we need to have the static choice list set.
10836 if Is_Record_Type
(E
) then
10837 Check_Variant_Part
: declare
10838 D
: constant Node_Id
:= Declaration_Node
(E
);
10843 Others_Present
: Boolean;
10844 pragma Warnings
(Off
, Others_Present
);
10845 -- Indicates others present, not used in this case
10847 procedure Non_Static_Choice_Error
(Choice
: Node_Id
);
10848 -- Error routine invoked by the generic instantiation below when
10849 -- the variant part has a non static choice.
10851 procedure Process_Declarations
(Variant
: Node_Id
);
10852 -- Processes declarations associated with a variant. We analyzed
10853 -- the declarations earlier (in Sem_Ch3.Analyze_Variant_Part),
10854 -- but we still need the recursive call to Check_Choices for any
10855 -- nested variant to get its choices properly processed. This is
10856 -- also where we expand out the choices if expansion is active.
10858 package Variant_Choices_Processing
is new
10859 Generic_Check_Choices
10860 (Process_Empty_Choice
=> No_OP
,
10861 Process_Non_Static_Choice
=> Non_Static_Choice_Error
,
10862 Process_Associated_Node
=> Process_Declarations
);
10863 use Variant_Choices_Processing
;
10865 -----------------------------
10866 -- Non_Static_Choice_Error --
10867 -----------------------------
10869 procedure Non_Static_Choice_Error
(Choice
: Node_Id
) is
10871 Flag_Non_Static_Expr
10872 ("choice given in variant part is not static!", Choice
);
10873 end Non_Static_Choice_Error
;
10875 --------------------------
10876 -- Process_Declarations --
10877 --------------------------
10879 procedure Process_Declarations
(Variant
: Node_Id
) is
10880 CL
: constant Node_Id
:= Component_List
(Variant
);
10884 -- Check for static predicate present in this variant
10886 if Has_SP_Choice
(Variant
) then
10888 -- Here we expand. You might expect to find this call in
10889 -- Expand_N_Variant_Part, but that is called when we first
10890 -- see the variant part, and we cannot do this expansion
10891 -- earlier than the freeze point, since for statically
10892 -- predicated subtypes, the predicate is not known till
10893 -- the freeze point.
10895 -- Furthermore, we do this expansion even if the expander
10896 -- is not active, because other semantic processing, e.g.
10897 -- for aggregates, requires the expanded list of choices.
10899 -- If the expander is not active, then we can't just clobber
10900 -- the list since it would invalidate the ASIS -gnatct tree.
10901 -- So we have to rewrite the variant part with a Rewrite
10902 -- call that replaces it with a copy and clobber the copy.
10904 if not Expander_Active
then
10906 NewV
: constant Node_Id
:= New_Copy
(Variant
);
10908 Set_Discrete_Choices
10909 (NewV
, New_Copy_List
(Discrete_Choices
(Variant
)));
10910 Rewrite
(Variant
, NewV
);
10914 Expand_Static_Predicates_In_Choices
(Variant
);
10917 -- We don't need to worry about the declarations in the variant
10918 -- (since they were analyzed by Analyze_Choices when we first
10919 -- encountered the variant), but we do need to take care of
10920 -- expansion of any nested variants.
10922 if not Null_Present
(CL
) then
10923 VP
:= Variant_Part
(CL
);
10925 if Present
(VP
) then
10927 (VP
, Variants
(VP
), Etype
(Name
(VP
)), Others_Present
);
10930 end Process_Declarations
;
10932 -- Start of processing for Check_Variant_Part
10935 -- Find component list
10939 if Nkind
(D
) = N_Full_Type_Declaration
then
10940 T
:= Type_Definition
(D
);
10942 if Nkind
(T
) = N_Record_Definition
then
10943 C
:= Component_List
(T
);
10945 elsif Nkind
(T
) = N_Derived_Type_Definition
10946 and then Present
(Record_Extension_Part
(T
))
10948 C
:= Component_List
(Record_Extension_Part
(T
));
10952 -- Case of variant part present
10954 if Present
(C
) and then Present
(Variant_Part
(C
)) then
10955 VP
:= Variant_Part
(C
);
10960 (VP
, Variants
(VP
), Etype
(Name
(VP
)), Others_Present
);
10962 -- If the last variant does not contain the Others choice,
10963 -- replace it with an N_Others_Choice node since Gigi always
10964 -- wants an Others. Note that we do not bother to call Analyze
10965 -- on the modified variant part, since its only effect would be
10966 -- to compute the Others_Discrete_Choices node laboriously, and
10967 -- of course we already know the list of choices corresponding
10968 -- to the others choice (it's the list we're replacing).
10970 -- We only want to do this if the expander is active, since
10971 -- we do not want to clobber the ASIS tree.
10973 if Expander_Active
then
10975 Last_Var
: constant Node_Id
:=
10976 Last_Non_Pragma
(Variants
(VP
));
10978 Others_Node
: Node_Id
;
10981 if Nkind
(First
(Discrete_Choices
(Last_Var
))) /=
10984 Others_Node
:= Make_Others_Choice
(Sloc
(Last_Var
));
10985 Set_Others_Discrete_Choices
10986 (Others_Node
, Discrete_Choices
(Last_Var
));
10987 Set_Discrete_Choices
10988 (Last_Var
, New_List
(Others_Node
));
10993 end Check_Variant_Part
;
10995 end Freeze_Entity_Checks
;
10997 -------------------------
10998 -- Get_Alignment_Value --
10999 -------------------------
11001 function Get_Alignment_Value
(Expr
: Node_Id
) return Uint
is
11002 Align
: constant Uint
:= Static_Integer
(Expr
);
11005 if Align
= No_Uint
then
11008 elsif Align
<= 0 then
11010 -- This error is suppressed in ASIS mode to allow for different ASIS
11011 -- back ends or ASIS-based tools to query the illegal clause.
11013 if not ASIS_Mode
then
11014 Error_Msg_N
("alignment value must be positive", Expr
);
11020 for J
in Int
range 0 .. 64 loop
11022 M
: constant Uint
:= Uint_2
** J
;
11025 exit when M
= Align
;
11029 -- This error is suppressed in ASIS mode to allow for
11030 -- different ASIS back ends or ASIS-based tools to query the
11033 if not ASIS_Mode
then
11034 Error_Msg_N
("alignment value must be power of 2", Expr
);
11044 end Get_Alignment_Value
;
11046 -----------------------------
11047 -- Get_Interfacing_Aspects --
11048 -----------------------------
11050 procedure Get_Interfacing_Aspects
11051 (Iface_Asp
: Node_Id
;
11052 Conv_Asp
: out Node_Id
;
11053 EN_Asp
: out Node_Id
;
11054 Expo_Asp
: out Node_Id
;
11055 Imp_Asp
: out Node_Id
;
11056 LN_Asp
: out Node_Id
;
11057 Do_Checks
: Boolean := False)
11059 procedure Save_Or_Duplication_Error
11061 To
: in out Node_Id
);
11062 -- Save the value of aspect Asp in node To. If To already has a value,
11063 -- then this is considered a duplicate use of aspect. Emit an error if
11064 -- flag Do_Checks is set.
11066 -------------------------------
11067 -- Save_Or_Duplication_Error --
11068 -------------------------------
11070 procedure Save_Or_Duplication_Error
11072 To
: in out Node_Id
)
11075 -- Detect an extra aspect and issue an error
11077 if Present
(To
) then
11079 Error_Msg_Name_1
:= Chars
(Identifier
(Asp
));
11080 Error_Msg_Sloc
:= Sloc
(To
);
11081 Error_Msg_N
("aspect % previously given #", Asp
);
11084 -- Otherwise capture the aspect
11089 end Save_Or_Duplication_Error
;
11094 Asp_Id
: Aspect_Id
;
11096 -- The following variables capture each individual aspect
11098 Conv
: Node_Id
:= Empty
;
11099 EN
: Node_Id
:= Empty
;
11100 Expo
: Node_Id
:= Empty
;
11101 Imp
: Node_Id
:= Empty
;
11102 LN
: Node_Id
:= Empty
;
11104 -- Start of processing for Get_Interfacing_Aspects
11107 -- The input interfacing aspect should reside in an aspect specification
11110 pragma Assert
(Is_List_Member
(Iface_Asp
));
11112 -- Examine the aspect specifications of the related entity. Find and
11113 -- capture all interfacing aspects. Detect duplicates and emit errors
11116 Asp
:= First
(List_Containing
(Iface_Asp
));
11117 while Present
(Asp
) loop
11118 Asp_Id
:= Get_Aspect_Id
(Asp
);
11120 if Asp_Id
= Aspect_Convention
then
11121 Save_Or_Duplication_Error
(Asp
, Conv
);
11123 elsif Asp_Id
= Aspect_External_Name
then
11124 Save_Or_Duplication_Error
(Asp
, EN
);
11126 elsif Asp_Id
= Aspect_Export
then
11127 Save_Or_Duplication_Error
(Asp
, Expo
);
11129 elsif Asp_Id
= Aspect_Import
then
11130 Save_Or_Duplication_Error
(Asp
, Imp
);
11132 elsif Asp_Id
= Aspect_Link_Name
then
11133 Save_Or_Duplication_Error
(Asp
, LN
);
11144 end Get_Interfacing_Aspects
;
11146 -------------------------------------
11147 -- Inherit_Aspects_At_Freeze_Point --
11148 -------------------------------------
11150 procedure Inherit_Aspects_At_Freeze_Point
(Typ
: Entity_Id
) is
11151 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11152 (Rep_Item
: Node_Id
) return Boolean;
11153 -- This routine checks if Rep_Item is either a pragma or an aspect
11154 -- specification node whose correponding pragma (if any) is present in
11155 -- the Rep Item chain of the entity it has been specified to.
11157 --------------------------------------------------
11158 -- Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item --
11159 --------------------------------------------------
11161 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11162 (Rep_Item
: Node_Id
) return Boolean
11166 Nkind
(Rep_Item
) = N_Pragma
11167 or else Present_In_Rep_Item
11168 (Entity
(Rep_Item
), Aspect_Rep_Item
(Rep_Item
));
11169 end Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
;
11171 -- Start of processing for Inherit_Aspects_At_Freeze_Point
11174 -- A representation item is either subtype-specific (Size and Alignment
11175 -- clauses) or type-related (all others). Subtype-specific aspects may
11176 -- differ for different subtypes of the same type (RM 13.1.8).
11178 -- A derived type inherits each type-related representation aspect of
11179 -- its parent type that was directly specified before the declaration of
11180 -- the derived type (RM 13.1.15).
11182 -- A derived subtype inherits each subtype-specific representation
11183 -- aspect of its parent subtype that was directly specified before the
11184 -- declaration of the derived type (RM 13.1.15).
11186 -- The general processing involves inheriting a representation aspect
11187 -- from a parent type whenever the first rep item (aspect specification,
11188 -- attribute definition clause, pragma) corresponding to the given
11189 -- representation aspect in the rep item chain of Typ, if any, isn't
11190 -- directly specified to Typ but to one of its parents.
11192 -- ??? Note that, for now, just a limited number of representation
11193 -- aspects have been inherited here so far. Many of them are
11194 -- still inherited in Sem_Ch3. This will be fixed soon. Here is
11195 -- a non- exhaustive list of aspects that likely also need to
11196 -- be moved to this routine: Alignment, Component_Alignment,
11197 -- Component_Size, Machine_Radix, Object_Size, Pack, Predicates,
11198 -- Preelaborable_Initialization, RM_Size and Small.
11200 -- In addition, Convention must be propagated from base type to subtype,
11201 -- because the subtype may have been declared on an incomplete view.
11203 if Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
then
11209 if not Has_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
, False)
11210 and then Has_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
)
11211 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11212 (Get_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
))
11214 Set_Is_Ada_2005_Only
(Typ
);
11219 if not Has_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
, False)
11220 and then Has_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
)
11221 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11222 (Get_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
))
11224 Set_Is_Ada_2012_Only
(Typ
);
11229 if not Has_Rep_Item
(Typ
, Name_Atomic
, Name_Shared
, False)
11230 and then Has_Rep_Pragma
(Typ
, Name_Atomic
, Name_Shared
)
11231 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11232 (Get_Rep_Item
(Typ
, Name_Atomic
, Name_Shared
))
11234 Set_Is_Atomic
(Typ
);
11235 Set_Is_Volatile
(Typ
);
11236 Set_Treat_As_Volatile
(Typ
);
11241 if Is_Record_Type
(Typ
)
11242 and then Typ
/= Base_Type
(Typ
) and then Is_Frozen
(Base_Type
(Typ
))
11244 Set_Convention
(Typ
, Convention
(Base_Type
(Typ
)));
11247 -- Default_Component_Value
11249 -- Verify that there is no rep_item declared for the type, and there
11250 -- is one coming from an ancestor.
11252 if Is_Array_Type
(Typ
)
11253 and then Is_Base_Type
(Typ
)
11254 and then not Has_Rep_Item
(Typ
, Name_Default_Component_Value
, False)
11255 and then Has_Rep_Item
(Typ
, Name_Default_Component_Value
)
11257 Set_Default_Aspect_Component_Value
(Typ
,
11258 Default_Aspect_Component_Value
11259 (Entity
(Get_Rep_Item
(Typ
, Name_Default_Component_Value
))));
11264 if Is_Scalar_Type
(Typ
)
11265 and then Is_Base_Type
(Typ
)
11266 and then not Has_Rep_Item
(Typ
, Name_Default_Value
, False)
11267 and then Has_Rep_Item
(Typ
, Name_Default_Value
)
11269 Set_Has_Default_Aspect
(Typ
);
11270 Set_Default_Aspect_Value
(Typ
,
11271 Default_Aspect_Value
11272 (Entity
(Get_Rep_Item
(Typ
, Name_Default_Value
))));
11277 if not Has_Rep_Item
(Typ
, Name_Discard_Names
, False)
11278 and then Has_Rep_Item
(Typ
, Name_Discard_Names
)
11279 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11280 (Get_Rep_Item
(Typ
, Name_Discard_Names
))
11282 Set_Discard_Names
(Typ
);
11287 if not Has_Rep_Item
(Typ
, Name_Volatile
, False)
11288 and then Has_Rep_Item
(Typ
, Name_Volatile
)
11289 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11290 (Get_Rep_Item
(Typ
, Name_Volatile
))
11292 Set_Is_Volatile
(Typ
);
11293 Set_Treat_As_Volatile
(Typ
);
11296 -- Volatile_Full_Access
11298 if not Has_Rep_Item
(Typ
, Name_Volatile_Full_Access
, False)
11299 and then Has_Rep_Pragma
(Typ
, Name_Volatile_Full_Access
)
11300 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11301 (Get_Rep_Item
(Typ
, Name_Volatile_Full_Access
))
11303 Set_Is_Volatile_Full_Access
(Typ
);
11304 Set_Is_Volatile
(Typ
);
11305 Set_Treat_As_Volatile
(Typ
);
11308 -- Inheritance for derived types only
11310 if Is_Derived_Type
(Typ
) then
11312 Bas_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
11313 Imp_Bas_Typ
: constant Entity_Id
:= Implementation_Base_Type
(Typ
);
11316 -- Atomic_Components
11318 if not Has_Rep_Item
(Typ
, Name_Atomic_Components
, False)
11319 and then Has_Rep_Item
(Typ
, Name_Atomic_Components
)
11320 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11321 (Get_Rep_Item
(Typ
, Name_Atomic_Components
))
11323 Set_Has_Atomic_Components
(Imp_Bas_Typ
);
11326 -- Volatile_Components
11328 if not Has_Rep_Item
(Typ
, Name_Volatile_Components
, False)
11329 and then Has_Rep_Item
(Typ
, Name_Volatile_Components
)
11330 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11331 (Get_Rep_Item
(Typ
, Name_Volatile_Components
))
11333 Set_Has_Volatile_Components
(Imp_Bas_Typ
);
11336 -- Finalize_Storage_Only
11338 if not Has_Rep_Pragma
(Typ
, Name_Finalize_Storage_Only
, False)
11339 and then Has_Rep_Pragma
(Typ
, Name_Finalize_Storage_Only
)
11341 Set_Finalize_Storage_Only
(Bas_Typ
);
11344 -- Universal_Aliasing
11346 if not Has_Rep_Item
(Typ
, Name_Universal_Aliasing
, False)
11347 and then Has_Rep_Item
(Typ
, Name_Universal_Aliasing
)
11348 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11349 (Get_Rep_Item
(Typ
, Name_Universal_Aliasing
))
11351 Set_Universal_Aliasing
(Imp_Bas_Typ
);
11356 if Is_Record_Type
(Typ
) then
11357 if not Has_Rep_Item
(Typ
, Name_Bit_Order
, False)
11358 and then Has_Rep_Item
(Typ
, Name_Bit_Order
)
11360 Set_Reverse_Bit_Order
(Bas_Typ
,
11361 Reverse_Bit_Order
(Entity
(Name
11362 (Get_Rep_Item
(Typ
, Name_Bit_Order
)))));
11366 -- Scalar_Storage_Order
11368 -- Note: the aspect is specified on a first subtype, but recorded
11369 -- in a flag of the base type!
11371 if (Is_Record_Type
(Typ
) or else Is_Array_Type
(Typ
))
11372 and then Typ
= Bas_Typ
11374 -- For a type extension, always inherit from parent; otherwise
11375 -- inherit if no default applies. Note: we do not check for
11376 -- an explicit rep item on the parent type when inheriting,
11377 -- because the parent SSO may itself have been set by default.
11379 if not Has_Rep_Item
(First_Subtype
(Typ
),
11380 Name_Scalar_Storage_Order
, False)
11381 and then (Is_Tagged_Type
(Bas_Typ
)
11382 or else not (SSO_Set_Low_By_Default
(Bas_Typ
)
11384 SSO_Set_High_By_Default
(Bas_Typ
)))
11386 Set_Reverse_Storage_Order
(Bas_Typ
,
11387 Reverse_Storage_Order
11388 (Implementation_Base_Type
(Etype
(Bas_Typ
))));
11390 -- Clear default SSO indications, since the inherited aspect
11391 -- which was set explicitly overrides the default.
11393 Set_SSO_Set_Low_By_Default
(Bas_Typ
, False);
11394 Set_SSO_Set_High_By_Default
(Bas_Typ
, False);
11399 end Inherit_Aspects_At_Freeze_Point
;
11405 procedure Initialize
is
11407 Address_Clause_Checks
.Init
;
11408 Unchecked_Conversions
.Init
;
11410 if AAMP_On_Target
then
11411 Independence_Checks
.Init
;
11415 ---------------------------
11416 -- Install_Discriminants --
11417 ---------------------------
11419 procedure Install_Discriminants
(E
: Entity_Id
) is
11423 Disc
:= First_Discriminant
(E
);
11424 while Present
(Disc
) loop
11425 Prev
:= Current_Entity
(Disc
);
11426 Set_Current_Entity
(Disc
);
11427 Set_Is_Immediately_Visible
(Disc
);
11428 Set_Homonym
(Disc
, Prev
);
11429 Next_Discriminant
(Disc
);
11431 end Install_Discriminants
;
11433 -------------------------
11434 -- Is_Operational_Item --
11435 -------------------------
11437 function Is_Operational_Item
(N
: Node_Id
) return Boolean is
11439 if Nkind
(N
) /= N_Attribute_Definition_Clause
then
11444 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Chars
(N
));
11447 -- List of operational items is given in AARM 13.1(8.mm/1).
11448 -- It is clearly incomplete, as it does not include iterator
11449 -- aspects, among others.
11451 return Id
= Attribute_Constant_Indexing
11452 or else Id
= Attribute_Default_Iterator
11453 or else Id
= Attribute_Implicit_Dereference
11454 or else Id
= Attribute_Input
11455 or else Id
= Attribute_Iterator_Element
11456 or else Id
= Attribute_Iterable
11457 or else Id
= Attribute_Output
11458 or else Id
= Attribute_Read
11459 or else Id
= Attribute_Variable_Indexing
11460 or else Id
= Attribute_Write
11461 or else Id
= Attribute_External_Tag
;
11464 end Is_Operational_Item
;
11466 -------------------------
11467 -- Is_Predicate_Static --
11468 -------------------------
11470 -- Note: the basic legality of the expression has already been checked, so
11471 -- we don't need to worry about cases or ranges on strings for example.
11473 function Is_Predicate_Static
11475 Nam
: Name_Id
) return Boolean
11477 function All_Static_Case_Alternatives
(L
: List_Id
) return Boolean;
11478 -- Given a list of case expression alternatives, returns True if all
11479 -- the alternatives are static (have all static choices, and a static
11482 function All_Static_Choices
(L
: List_Id
) return Boolean;
11483 -- Returns true if all elements of the list are OK static choices
11484 -- as defined below for Is_Static_Choice. Used for case expression
11485 -- alternatives and for the right operand of a membership test. An
11486 -- others_choice is static if the corresponding expression is static.
11487 -- The staticness of the bounds is checked separately.
11489 function Is_Static_Choice
(N
: Node_Id
) return Boolean;
11490 -- Returns True if N represents a static choice (static subtype, or
11491 -- static subtype indication, or static expression, or static range).
11493 -- Note that this is a bit more inclusive than we actually need
11494 -- (in particular membership tests do not allow the use of subtype
11495 -- indications). But that doesn't matter, we have already checked
11496 -- that the construct is legal to get this far.
11498 function Is_Type_Ref
(N
: Node_Id
) return Boolean;
11499 pragma Inline
(Is_Type_Ref
);
11500 -- Returns True if N is a reference to the type for the predicate in the
11501 -- expression (i.e. if it is an identifier whose Chars field matches the
11502 -- Nam given in the call). N must not be parenthesized, if the type name
11503 -- appears in parens, this routine will return False.
11505 ----------------------------------
11506 -- All_Static_Case_Alternatives --
11507 ----------------------------------
11509 function All_Static_Case_Alternatives
(L
: List_Id
) return Boolean is
11514 while Present
(N
) loop
11515 if not (All_Static_Choices
(Discrete_Choices
(N
))
11516 and then Is_OK_Static_Expression
(Expression
(N
)))
11525 end All_Static_Case_Alternatives
;
11527 ------------------------
11528 -- All_Static_Choices --
11529 ------------------------
11531 function All_Static_Choices
(L
: List_Id
) return Boolean is
11536 while Present
(N
) loop
11537 if not Is_Static_Choice
(N
) then
11545 end All_Static_Choices
;
11547 ----------------------
11548 -- Is_Static_Choice --
11549 ----------------------
11551 function Is_Static_Choice
(N
: Node_Id
) return Boolean is
11553 return Nkind
(N
) = N_Others_Choice
11554 or else Is_OK_Static_Expression
(N
)
11555 or else (Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
))
11556 and then Is_OK_Static_Subtype
(Entity
(N
)))
11557 or else (Nkind
(N
) = N_Subtype_Indication
11558 and then Is_OK_Static_Subtype
(Entity
(N
)))
11559 or else (Nkind
(N
) = N_Range
and then Is_OK_Static_Range
(N
));
11560 end Is_Static_Choice
;
11566 function Is_Type_Ref
(N
: Node_Id
) return Boolean is
11568 return Nkind
(N
) = N_Identifier
11569 and then Chars
(N
) = Nam
11570 and then Paren_Count
(N
) = 0;
11573 -- Start of processing for Is_Predicate_Static
11576 -- Predicate_Static means one of the following holds. Numbers are the
11577 -- corresponding paragraph numbers in (RM 3.2.4(16-22)).
11579 -- 16: A static expression
11581 if Is_OK_Static_Expression
(Expr
) then
11584 -- 17: A membership test whose simple_expression is the current
11585 -- instance, and whose membership_choice_list meets the requirements
11586 -- for a static membership test.
11588 elsif Nkind
(Expr
) in N_Membership_Test
11589 and then ((Present
(Right_Opnd
(Expr
))
11590 and then Is_Static_Choice
(Right_Opnd
(Expr
)))
11592 (Present
(Alternatives
(Expr
))
11593 and then All_Static_Choices
(Alternatives
(Expr
))))
11597 -- 18. A case_expression whose selecting_expression is the current
11598 -- instance, and whose dependent expressions are static expressions.
11600 elsif Nkind
(Expr
) = N_Case_Expression
11601 and then Is_Type_Ref
(Expression
(Expr
))
11602 and then All_Static_Case_Alternatives
(Alternatives
(Expr
))
11606 -- 19. A call to a predefined equality or ordering operator, where one
11607 -- operand is the current instance, and the other is a static
11610 -- Note: the RM is clearly wrong here in not excluding string types.
11611 -- Without this exclusion, we would allow expressions like X > "ABC"
11612 -- to be considered as predicate-static, which is clearly not intended,
11613 -- since the idea is for predicate-static to be a subset of normal
11614 -- static expressions (and "DEF" > "ABC" is not a static expression).
11616 -- However, we do allow internally generated (not from source) equality
11617 -- and inequality operations to be valid on strings (this helps deal
11618 -- with cases where we transform A in "ABC" to A = "ABC).
11620 elsif Nkind
(Expr
) in N_Op_Compare
11621 and then ((not Is_String_Type
(Etype
(Left_Opnd
(Expr
))))
11622 or else (Nkind_In
(Expr
, N_Op_Eq
, N_Op_Ne
)
11623 and then not Comes_From_Source
(Expr
)))
11624 and then ((Is_Type_Ref
(Left_Opnd
(Expr
))
11625 and then Is_OK_Static_Expression
(Right_Opnd
(Expr
)))
11627 (Is_Type_Ref
(Right_Opnd
(Expr
))
11628 and then Is_OK_Static_Expression
(Left_Opnd
(Expr
))))
11632 -- 20. A call to a predefined boolean logical operator, where each
11633 -- operand is predicate-static.
11635 elsif (Nkind_In
(Expr
, N_Op_And
, N_Op_Or
, N_Op_Xor
)
11636 and then Is_Predicate_Static
(Left_Opnd
(Expr
), Nam
)
11637 and then Is_Predicate_Static
(Right_Opnd
(Expr
), Nam
))
11639 (Nkind
(Expr
) = N_Op_Not
11640 and then Is_Predicate_Static
(Right_Opnd
(Expr
), Nam
))
11644 -- 21. A short-circuit control form where both operands are
11645 -- predicate-static.
11647 elsif Nkind
(Expr
) in N_Short_Circuit
11648 and then Is_Predicate_Static
(Left_Opnd
(Expr
), Nam
)
11649 and then Is_Predicate_Static
(Right_Opnd
(Expr
), Nam
)
11653 -- 22. A parenthesized predicate-static expression. This does not
11654 -- require any special test, since we just ignore paren levels in
11655 -- all the cases above.
11657 -- One more test that is an implementation artifact caused by the fact
11658 -- that we are analyzing not the original expression, but the generated
11659 -- expression in the body of the predicate function. This can include
11660 -- references to inherited predicates, so that the expression we are
11661 -- processing looks like:
11663 -- xxPredicate (typ (Inns)) and then expression
11665 -- Where the call is to a Predicate function for an inherited predicate.
11666 -- We simply ignore such a call, which could be to either a dynamic or
11667 -- a static predicate. Note that if the parent predicate is dynamic then
11668 -- eventually this type will be marked as dynamic, but you are allowed
11669 -- to specify a static predicate for a subtype which is inheriting a
11670 -- dynamic predicate, so the static predicate validation here ignores
11671 -- the inherited predicate even if it is dynamic.
11672 -- In all cases, a static predicate can only apply to a scalar type.
11674 elsif Nkind
(Expr
) = N_Function_Call
11675 and then Is_Predicate_Function
(Entity
(Name
(Expr
)))
11676 and then Is_Scalar_Type
(Etype
(First_Entity
(Entity
(Name
(Expr
)))))
11680 -- That's an exhaustive list of tests, all other cases are not
11681 -- predicate-static, so we return False.
11686 end Is_Predicate_Static
;
11688 ---------------------
11689 -- Kill_Rep_Clause --
11690 ---------------------
11692 procedure Kill_Rep_Clause
(N
: Node_Id
) is
11694 pragma Assert
(Ignore_Rep_Clauses
);
11696 -- Note: we use Replace rather than Rewrite, because we don't want
11697 -- ASIS to be able to use Original_Node to dig out the (undecorated)
11698 -- rep clause that is being replaced.
11700 Replace
(N
, Make_Null_Statement
(Sloc
(N
)));
11702 -- The null statement must be marked as not coming from source. This is
11703 -- so that ASIS ignores it, and also the back end does not expect bogus
11704 -- "from source" null statements in weird places (e.g. in declarative
11705 -- regions where such null statements are not allowed).
11707 Set_Comes_From_Source
(N
, False);
11708 end Kill_Rep_Clause
;
11714 function Minimum_Size
11716 Biased
: Boolean := False) return Nat
11718 Lo
: Uint
:= No_Uint
;
11719 Hi
: Uint
:= No_Uint
;
11720 LoR
: Ureal
:= No_Ureal
;
11721 HiR
: Ureal
:= No_Ureal
;
11722 LoSet
: Boolean := False;
11723 HiSet
: Boolean := False;
11726 Ancest
: Entity_Id
;
11727 R_Typ
: constant Entity_Id
:= Root_Type
(T
);
11730 -- If bad type, return 0
11732 if T
= Any_Type
then
11735 -- For generic types, just return zero. There cannot be any legitimate
11736 -- need to know such a size, but this routine may be called with a
11737 -- generic type as part of normal processing.
11739 elsif Is_Generic_Type
(R_Typ
) or else R_Typ
= Any_Type
then
11742 -- Access types (cannot have size smaller than System.Address)
11744 elsif Is_Access_Type
(T
) then
11745 return System_Address_Size
;
11747 -- Floating-point types
11749 elsif Is_Floating_Point_Type
(T
) then
11750 return UI_To_Int
(Esize
(R_Typ
));
11754 elsif Is_Discrete_Type
(T
) then
11756 -- The following loop is looking for the nearest compile time known
11757 -- bounds following the ancestor subtype chain. The idea is to find
11758 -- the most restrictive known bounds information.
11762 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
11767 if Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
)) then
11768 Lo
:= Expr_Rep_Value
(Type_Low_Bound
(Ancest
));
11775 if Compile_Time_Known_Value
(Type_High_Bound
(Ancest
)) then
11776 Hi
:= Expr_Rep_Value
(Type_High_Bound
(Ancest
));
11782 Ancest
:= Ancestor_Subtype
(Ancest
);
11784 if No
(Ancest
) then
11785 Ancest
:= Base_Type
(T
);
11787 if Is_Generic_Type
(Ancest
) then
11793 -- Fixed-point types. We can't simply use Expr_Value to get the
11794 -- Corresponding_Integer_Value values of the bounds, since these do not
11795 -- get set till the type is frozen, and this routine can be called
11796 -- before the type is frozen. Similarly the test for bounds being static
11797 -- needs to include the case where we have unanalyzed real literals for
11798 -- the same reason.
11800 elsif Is_Fixed_Point_Type
(T
) then
11802 -- The following loop is looking for the nearest compile time known
11803 -- bounds following the ancestor subtype chain. The idea is to find
11804 -- the most restrictive known bounds information.
11808 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
11812 -- Note: In the following two tests for LoSet and HiSet, it may
11813 -- seem redundant to test for N_Real_Literal here since normally
11814 -- one would assume that the test for the value being known at
11815 -- compile time includes this case. However, there is a glitch.
11816 -- If the real literal comes from folding a non-static expression,
11817 -- then we don't consider any non- static expression to be known
11818 -- at compile time if we are in configurable run time mode (needed
11819 -- in some cases to give a clearer definition of what is and what
11820 -- is not accepted). So the test is indeed needed. Without it, we
11821 -- would set neither Lo_Set nor Hi_Set and get an infinite loop.
11824 if Nkind
(Type_Low_Bound
(Ancest
)) = N_Real_Literal
11825 or else Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
))
11827 LoR
:= Expr_Value_R
(Type_Low_Bound
(Ancest
));
11834 if Nkind
(Type_High_Bound
(Ancest
)) = N_Real_Literal
11835 or else Compile_Time_Known_Value
(Type_High_Bound
(Ancest
))
11837 HiR
:= Expr_Value_R
(Type_High_Bound
(Ancest
));
11843 Ancest
:= Ancestor_Subtype
(Ancest
);
11845 if No
(Ancest
) then
11846 Ancest
:= Base_Type
(T
);
11848 if Is_Generic_Type
(Ancest
) then
11854 Lo
:= UR_To_Uint
(LoR
/ Small_Value
(T
));
11855 Hi
:= UR_To_Uint
(HiR
/ Small_Value
(T
));
11857 -- No other types allowed
11860 raise Program_Error
;
11863 -- Fall through with Hi and Lo set. Deal with biased case
11866 and then not Is_Fixed_Point_Type
(T
)
11867 and then not (Is_Enumeration_Type
(T
)
11868 and then Has_Non_Standard_Rep
(T
)))
11869 or else Has_Biased_Representation
(T
)
11875 -- Null range case, size is always zero. We only do this in the discrete
11876 -- type case, since that's the odd case that came up. Probably we should
11877 -- also do this in the fixed-point case, but doing so causes peculiar
11878 -- gigi failures, and it is not worth worrying about this incredibly
11879 -- marginal case (explicit null-range fixed-point type declarations)???
11881 if Lo
> Hi
and then Is_Discrete_Type
(T
) then
11884 -- Signed case. Note that we consider types like range 1 .. -1 to be
11885 -- signed for the purpose of computing the size, since the bounds have
11886 -- to be accommodated in the base type.
11888 elsif Lo
< 0 or else Hi
< 0 then
11892 -- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1))
11893 -- Note that we accommodate the case where the bounds cross. This
11894 -- can happen either because of the way the bounds are declared
11895 -- or because of the algorithm in Freeze_Fixed_Point_Type.
11909 -- If both bounds are positive, make sure that both are represen-
11910 -- table in the case where the bounds are crossed. This can happen
11911 -- either because of the way the bounds are declared, or because of
11912 -- the algorithm in Freeze_Fixed_Point_Type.
11918 -- S = size, (can accommodate 0 .. (2**size - 1))
11921 while Hi
>= Uint_2
** S
loop
11929 ---------------------------
11930 -- New_Stream_Subprogram --
11931 ---------------------------
11933 procedure New_Stream_Subprogram
11937 Nam
: TSS_Name_Type
)
11939 Loc
: constant Source_Ptr
:= Sloc
(N
);
11940 Sname
: constant Name_Id
:= Make_TSS_Name
(Base_Type
(Ent
), Nam
);
11941 Subp_Id
: Entity_Id
;
11942 Subp_Decl
: Node_Id
;
11946 Defer_Declaration
: constant Boolean :=
11947 Is_Tagged_Type
(Ent
) or else Is_Private_Type
(Ent
);
11948 -- For a tagged type, there is a declaration for each stream attribute
11949 -- at the freeze point, and we must generate only a completion of this
11950 -- declaration. We do the same for private types, because the full view
11951 -- might be tagged. Otherwise we generate a declaration at the point of
11952 -- the attribute definition clause. If the attribute definition comes
11953 -- from an aspect specification the declaration is part of the freeze
11954 -- actions of the type.
11956 function Build_Spec
return Node_Id
;
11957 -- Used for declaration and renaming declaration, so that this is
11958 -- treated as a renaming_as_body.
11964 function Build_Spec
return Node_Id
is
11965 Out_P
: constant Boolean := (Nam
= TSS_Stream_Read
);
11968 T_Ref
: constant Node_Id
:= New_Occurrence_Of
(Etyp
, Loc
);
11971 Subp_Id
:= Make_Defining_Identifier
(Loc
, Sname
);
11973 -- S : access Root_Stream_Type'Class
11975 Formals
:= New_List
(
11976 Make_Parameter_Specification
(Loc
,
11977 Defining_Identifier
=>
11978 Make_Defining_Identifier
(Loc
, Name_S
),
11980 Make_Access_Definition
(Loc
,
11982 New_Occurrence_Of
(
11983 Designated_Type
(Etype
(F
)), Loc
))));
11985 if Nam
= TSS_Stream_Input
then
11987 Make_Function_Specification
(Loc
,
11988 Defining_Unit_Name
=> Subp_Id
,
11989 Parameter_Specifications
=> Formals
,
11990 Result_Definition
=> T_Ref
);
11994 Append_To
(Formals
,
11995 Make_Parameter_Specification
(Loc
,
11996 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_V
),
11997 Out_Present
=> Out_P
,
11998 Parameter_Type
=> T_Ref
));
12001 Make_Procedure_Specification
(Loc
,
12002 Defining_Unit_Name
=> Subp_Id
,
12003 Parameter_Specifications
=> Formals
);
12009 -- Start of processing for New_Stream_Subprogram
12012 F
:= First_Formal
(Subp
);
12014 if Ekind
(Subp
) = E_Procedure
then
12015 Etyp
:= Etype
(Next_Formal
(F
));
12017 Etyp
:= Etype
(Subp
);
12020 -- Prepare subprogram declaration and insert it as an action on the
12021 -- clause node. The visibility for this entity is used to test for
12022 -- visibility of the attribute definition clause (in the sense of
12023 -- 8.3(23) as amended by AI-195).
12025 if not Defer_Declaration
then
12027 Make_Subprogram_Declaration
(Loc
,
12028 Specification
=> Build_Spec
);
12030 -- For a tagged type, there is always a visible declaration for each
12031 -- stream TSS (it is a predefined primitive operation), and the
12032 -- completion of this declaration occurs at the freeze point, which is
12033 -- not always visible at places where the attribute definition clause is
12034 -- visible. So, we create a dummy entity here for the purpose of
12035 -- tracking the visibility of the attribute definition clause itself.
12039 Make_Defining_Identifier
(Loc
, New_External_Name
(Sname
, 'V'));
12041 Make_Object_Declaration
(Loc
,
12042 Defining_Identifier
=> Subp_Id
,
12043 Object_Definition
=> New_Occurrence_Of
(Standard_Boolean
, Loc
));
12046 if not Defer_Declaration
12047 and then From_Aspect_Specification
(N
)
12048 and then Has_Delayed_Freeze
(Ent
)
12050 Append_Freeze_Action
(Ent
, Subp_Decl
);
12053 Insert_Action
(N
, Subp_Decl
);
12054 Set_Entity
(N
, Subp_Id
);
12058 Make_Subprogram_Renaming_Declaration
(Loc
,
12059 Specification
=> Build_Spec
,
12060 Name
=> New_Occurrence_Of
(Subp
, Loc
));
12062 if Defer_Declaration
then
12063 Set_TSS
(Base_Type
(Ent
), Subp_Id
);
12066 if From_Aspect_Specification
(N
) then
12067 Append_Freeze_Action
(Ent
, Subp_Decl
);
12069 Insert_Action
(N
, Subp_Decl
);
12072 Copy_TSS
(Subp_Id
, Base_Type
(Ent
));
12074 end New_Stream_Subprogram
;
12076 ------------------------------------------
12077 -- Push_Scope_And_Install_Discriminants --
12078 ------------------------------------------
12080 procedure Push_Scope_And_Install_Discriminants
(E
: Entity_Id
) is
12082 if Has_Discriminants
(E
) then
12085 -- Make the discriminants visible for type declarations and protected
12086 -- type declarations, not for subtype declarations (RM 13.1.1 (12/3))
12088 if Nkind
(Parent
(E
)) /= N_Subtype_Declaration
then
12089 Install_Discriminants
(E
);
12092 end Push_Scope_And_Install_Discriminants
;
12094 ------------------------
12095 -- Rep_Item_Too_Early --
12096 ------------------------
12098 function Rep_Item_Too_Early
(T
: Entity_Id
; N
: Node_Id
) return Boolean is
12100 -- Cannot apply non-operational rep items to generic types
12102 if Is_Operational_Item
(N
) then
12106 and then Is_Generic_Type
(Root_Type
(T
))
12107 and then (Nkind
(N
) /= N_Pragma
12108 or else Get_Pragma_Id
(N
) /= Pragma_Convention
)
12110 Error_Msg_N
("representation item not allowed for generic type", N
);
12114 -- Otherwise check for incomplete type
12116 if Is_Incomplete_Or_Private_Type
(T
)
12117 and then No
(Underlying_Type
(T
))
12119 (Nkind
(N
) /= N_Pragma
12120 or else Get_Pragma_Id
(N
) /= Pragma_Import
)
12123 ("representation item must be after full type declaration", N
);
12126 -- If the type has incomplete components, a representation clause is
12127 -- illegal but stream attributes and Convention pragmas are correct.
12129 elsif Has_Private_Component
(T
) then
12130 if Nkind
(N
) = N_Pragma
then
12135 ("representation item must appear after type is fully defined",
12142 end Rep_Item_Too_Early
;
12144 -----------------------
12145 -- Rep_Item_Too_Late --
12146 -----------------------
12148 function Rep_Item_Too_Late
12151 FOnly
: Boolean := False) return Boolean
12154 Parent_Type
: Entity_Id
;
12156 procedure No_Type_Rep_Item
;
12157 -- Output message indicating that no type-related aspects can be
12158 -- specified due to some property of the parent type.
12160 procedure Too_Late
;
12161 -- Output message for an aspect being specified too late
12163 -- Note that neither of the above errors is considered a serious one,
12164 -- since the effect is simply that we ignore the representation clause
12166 -- Is this really true? In any case if we make this change we must
12167 -- document the requirement in the spec of Rep_Item_Too_Late that
12168 -- if True is returned, then the rep item must be completely ignored???
12170 ----------------------
12171 -- No_Type_Rep_Item --
12172 ----------------------
12174 procedure No_Type_Rep_Item
is
12176 Error_Msg_N
("|type-related representation item not permitted!", N
);
12177 end No_Type_Rep_Item
;
12183 procedure Too_Late
is
12185 -- Other compilers seem more relaxed about rep items appearing too
12186 -- late. Since analysis tools typically don't care about rep items
12187 -- anyway, no reason to be too strict about this.
12189 if not Relaxed_RM_Semantics
then
12190 Error_Msg_N
("|representation item appears too late!", N
);
12194 -- Start of processing for Rep_Item_Too_Late
12197 -- First make sure entity is not frozen (RM 13.1(9))
12201 -- Exclude imported types, which may be frozen if they appear in a
12202 -- representation clause for a local type.
12204 and then not From_Limited_With
(T
)
12206 -- Exclude generated entities (not coming from source). The common
12207 -- case is when we generate a renaming which prematurely freezes the
12208 -- renamed internal entity, but we still want to be able to set copies
12209 -- of attribute values such as Size/Alignment.
12211 and then Comes_From_Source
(T
)
12213 -- A self-referential aspect is illegal if it forces freezing the
12214 -- entity before the corresponding pragma has been analyzed.
12216 if Nkind_In
(N
, N_Attribute_Definition_Clause
, N_Pragma
)
12217 and then From_Aspect_Specification
(N
)
12220 ("aspect specification causes premature freezing of&", T
, N
);
12221 Set_Has_Delayed_Freeze
(T
, False);
12226 S
:= First_Subtype
(T
);
12228 if Present
(Freeze_Node
(S
)) then
12229 if not Relaxed_RM_Semantics
then
12231 ("??no more representation items for }", Freeze_Node
(S
), S
);
12237 -- Check for case of untagged derived type whose parent either has
12238 -- primitive operations, or is a by reference type (RM 13.1(10)). In
12239 -- this case we do not output a Too_Late message, since there is no
12240 -- earlier point where the rep item could be placed to make it legal.
12244 and then Is_Derived_Type
(T
)
12245 and then not Is_Tagged_Type
(T
)
12247 Parent_Type
:= Etype
(Base_Type
(T
));
12249 if Has_Primitive_Operations
(Parent_Type
) then
12252 if not Relaxed_RM_Semantics
then
12254 ("\parent type & has primitive operations!", N
, Parent_Type
);
12259 elsif Is_By_Reference_Type
(Parent_Type
) then
12262 if not Relaxed_RM_Semantics
then
12264 ("\parent type & is a by reference type!", N
, Parent_Type
);
12271 -- No error, but one more warning to consider. The RM (surprisingly)
12272 -- allows this pattern:
12275 -- primitive operations for S
12276 -- type R is new S;
12277 -- rep clause for S
12279 -- Meaning that calls on the primitive operations of S for values of
12280 -- type R may require possibly expensive implicit conversion operations.
12281 -- This is not an error, but is worth a warning.
12283 if not Relaxed_RM_Semantics
and then Is_Type
(T
) then
12285 DTL
: constant Entity_Id
:= Derived_Type_Link
(Base_Type
(T
));
12289 and then Has_Primitive_Operations
(Base_Type
(T
))
12291 -- For now, do not generate this warning for the case of aspect
12292 -- specification using Ada 2012 syntax, since we get wrong
12293 -- messages we do not understand. The whole business of derived
12294 -- types and rep items seems a bit confused when aspects are
12295 -- used, since the aspects are not evaluated till freeze time.
12297 and then not From_Aspect_Specification
(N
)
12299 Error_Msg_Sloc
:= Sloc
(DTL
);
12301 ("representation item for& appears after derived type "
12302 & "declaration#??", N
);
12304 ("\may result in implicit conversions for primitive "
12305 & "operations of&??", N
, T
);
12307 ("\to change representations when called with arguments "
12308 & "of type&??", N
, DTL
);
12313 -- No error, link item into head of chain of rep items for the entity,
12314 -- but avoid chaining if we have an overloadable entity, and the pragma
12315 -- is one that can apply to multiple overloaded entities.
12317 if Is_Overloadable
(T
) and then Nkind
(N
) = N_Pragma
then
12319 Pname
: constant Name_Id
:= Pragma_Name
(N
);
12321 if Nam_In
(Pname
, Name_Convention
, Name_Import
, Name_Export
,
12322 Name_External
, Name_Interface
)
12329 Record_Rep_Item
(T
, N
);
12331 end Rep_Item_Too_Late
;
12333 -------------------------------------
12334 -- Replace_Type_References_Generic --
12335 -------------------------------------
12337 procedure Replace_Type_References_Generic
(N
: Node_Id
; T
: Entity_Id
) is
12338 TName
: constant Name_Id
:= Chars
(T
);
12340 function Replace_Type_Ref
(N
: Node_Id
) return Traverse_Result
;
12341 -- Processes a single node in the traversal procedure below, checking
12342 -- if node N should be replaced, and if so, doing the replacement.
12344 function Visible_Component
(Comp
: Name_Id
) return Entity_Id
;
12345 -- Given an identifier in the expression, check whether there is a
12346 -- discriminant or component of the type that is directy visible, and
12347 -- rewrite it as the corresponding selected component of the formal of
12348 -- the subprogram. The entity is located by a sequential search, which
12349 -- seems acceptable given the typical size of component lists and check
12350 -- expressions. Possible optimization ???
12352 ----------------------
12353 -- Replace_Type_Ref --
12354 ----------------------
12356 function Replace_Type_Ref
(N
: Node_Id
) return Traverse_Result
is
12357 Loc
: constant Source_Ptr
:= Sloc
(N
);
12359 procedure Add_Prefix
(Ref
: Node_Id
; Comp
: Entity_Id
);
12360 -- Add the proper prefix to a reference to a component of the type
12361 -- when it is not already a selected component.
12367 procedure Add_Prefix
(Ref
: Node_Id
; Comp
: Entity_Id
) is
12370 Make_Selected_Component
(Loc
,
12371 Prefix
=> New_Occurrence_Of
(T
, Loc
),
12372 Selector_Name
=> New_Occurrence_Of
(Comp
, Loc
)));
12373 Replace_Type_Reference
(Prefix
(Ref
));
12382 -- Start of processing for Replace_Type_Ref
12385 if Nkind
(N
) = N_Identifier
then
12387 -- If not the type name, check whether it is a reference to some
12388 -- other type, which must be frozen before the predicate function
12389 -- is analyzed, i.e. before the freeze node of the type to which
12390 -- the predicate applies.
12392 if Chars
(N
) /= TName
then
12393 if Present
(Current_Entity
(N
))
12394 and then Is_Type
(Current_Entity
(N
))
12396 Freeze_Before
(Freeze_Node
(T
), Current_Entity
(N
));
12399 -- The components of the type are directly visible and can
12400 -- be referenced without a prefix.
12402 if Nkind
(Parent
(N
)) = N_Selected_Component
then
12405 -- In expression C (I), C may be a directly visible function
12406 -- or a visible component that has an array type. Disambiguate
12407 -- by examining the component type.
12409 elsif Nkind
(Parent
(N
)) = N_Indexed_Component
12410 and then N
= Prefix
(Parent
(N
))
12412 Comp
:= Visible_Component
(Chars
(N
));
12414 if Present
(Comp
) and then Is_Array_Type
(Etype
(Comp
)) then
12415 Add_Prefix
(N
, Comp
);
12419 Comp
:= Visible_Component
(Chars
(N
));
12421 if Present
(Comp
) then
12422 Add_Prefix
(N
, Comp
);
12428 -- Otherwise do the replacement and we are done with this node
12431 Replace_Type_Reference
(N
);
12435 -- Case of selected component (which is what a qualification looks
12436 -- like in the unanalyzed tree, which is what we have.
12438 elsif Nkind
(N
) = N_Selected_Component
then
12440 -- If selector name is not our type, keeping going (we might still
12441 -- have an occurrence of the type in the prefix).
12443 if Nkind
(Selector_Name
(N
)) /= N_Identifier
12444 or else Chars
(Selector_Name
(N
)) /= TName
12448 -- Selector name is our type, check qualification
12451 -- Loop through scopes and prefixes, doing comparison
12453 Scop
:= Current_Scope
;
12454 Pref
:= Prefix
(N
);
12456 -- Continue if no more scopes or scope with no name
12458 if No
(Scop
) or else Nkind
(Scop
) not in N_Has_Chars
then
12462 -- Do replace if prefix is an identifier matching the scope
12463 -- that we are currently looking at.
12465 if Nkind
(Pref
) = N_Identifier
12466 and then Chars
(Pref
) = Chars
(Scop
)
12468 Replace_Type_Reference
(N
);
12472 -- Go check scope above us if prefix is itself of the form
12473 -- of a selected component, whose selector matches the scope
12474 -- we are currently looking at.
12476 if Nkind
(Pref
) = N_Selected_Component
12477 and then Nkind
(Selector_Name
(Pref
)) = N_Identifier
12478 and then Chars
(Selector_Name
(Pref
)) = Chars
(Scop
)
12480 Scop
:= Scope
(Scop
);
12481 Pref
:= Prefix
(Pref
);
12483 -- For anything else, we don't have a match, so keep on
12484 -- going, there are still some weird cases where we may
12485 -- still have a replacement within the prefix.
12493 -- Continue for any other node kind
12498 end Replace_Type_Ref
;
12500 procedure Replace_Type_Refs
is new Traverse_Proc
(Replace_Type_Ref
);
12502 -----------------------
12503 -- Visible_Component --
12504 -----------------------
12506 function Visible_Component
(Comp
: Name_Id
) return Entity_Id
is
12510 if Ekind
(T
) /= E_Record_Type
then
12514 E
:= First_Entity
(T
);
12515 while Present
(E
) loop
12516 if Comes_From_Source
(E
) and then Chars
(E
) = Comp
then
12525 end Visible_Component
;
12527 -- Start of processing for Replace_Type_References_Generic
12530 Replace_Type_Refs
(N
);
12531 end Replace_Type_References_Generic
;
12533 --------------------------------
12534 -- Resolve_Aspect_Expressions --
12535 --------------------------------
12537 procedure Resolve_Aspect_Expressions
(E
: Entity_Id
) is
12542 function Resolve_Name
(N
: Node_Id
) return Traverse_Result
;
12543 -- Verify that all identifiers in the expression, with the exception
12544 -- of references to the current entity, denote visible entities. This
12545 -- is done only to detect visibility errors, as the expression will be
12546 -- properly analyzed/expanded during analysis of the predicate function
12547 -- body. We omit quantified expressions from this test, given that they
12548 -- introduce a local identifier that would require proper expansion to
12549 -- handle properly.
12555 function Resolve_Name
(N
: Node_Id
) return Traverse_Result
is
12557 if Nkind
(N
) = N_Selected_Component
then
12558 if Nkind
(Prefix
(N
)) = N_Identifier
12559 and then Chars
(Prefix
(N
)) /= Chars
(E
)
12561 Find_Selected_Component
(N
);
12566 elsif Nkind
(N
) = N_Identifier
and then Chars
(N
) /= Chars
(E
) then
12567 Find_Direct_Name
(N
);
12568 Set_Entity
(N
, Empty
);
12570 elsif Nkind
(N
) = N_Quantified_Expression
then
12577 procedure Resolve_Aspect_Expression
is new Traverse_Proc
(Resolve_Name
);
12579 -- Start of processing for Resolve_Aspect_Expressions
12582 ASN
:= First_Rep_Item
(E
);
12583 while Present
(ASN
) loop
12584 if Nkind
(ASN
) = N_Aspect_Specification
and then Entity
(ASN
) = E
then
12585 A_Id
:= Get_Aspect_Id
(ASN
);
12586 Expr
:= Expression
(ASN
);
12590 -- For now we only deal with aspects that do not generate
12591 -- subprograms, or that may mention current instances of
12592 -- types. These will require special handling (???TBD).
12594 when Aspect_Predicate |
12595 Aspect_Predicate_Failure |
12596 Aspect_Invariant
=>
12599 when Aspect_Dynamic_Predicate |
12600 Aspect_Static_Predicate
=>
12602 -- Build predicate function specification and preanalyze
12603 -- expression after type replacement.
12605 if No
(Predicate_Function
(E
)) then
12607 FDecl
: constant Node_Id
:=
12608 Build_Predicate_Function_Declaration
(E
);
12609 pragma Unreferenced
(FDecl
);
12611 Resolve_Aspect_Expression
(Expr
);
12615 when Pre_Post_Aspects
=>
12618 when Aspect_Iterable
=>
12619 if Nkind
(Expr
) = N_Aggregate
then
12624 Assoc
:= First
(Component_Associations
(Expr
));
12625 while Present
(Assoc
) loop
12626 Find_Direct_Name
(Expression
(Assoc
));
12633 if Present
(Expr
) then
12634 case Aspect_Argument
(A_Id
) is
12635 when Expression | Optional_Expression
=>
12636 Analyze_And_Resolve
(Expression
(ASN
));
12638 when Name | Optional_Name
=>
12639 if Nkind
(Expr
) = N_Identifier
then
12640 Find_Direct_Name
(Expr
);
12642 elsif Nkind
(Expr
) = N_Selected_Component
then
12643 Find_Selected_Component
(Expr
);
12653 ASN
:= Next_Rep_Item
(ASN
);
12655 end Resolve_Aspect_Expressions
;
12657 -------------------------
12658 -- Same_Representation --
12659 -------------------------
12661 function Same_Representation
(Typ1
, Typ2
: Entity_Id
) return Boolean is
12662 T1
: constant Entity_Id
:= Underlying_Type
(Typ1
);
12663 T2
: constant Entity_Id
:= Underlying_Type
(Typ2
);
12666 -- A quick check, if base types are the same, then we definitely have
12667 -- the same representation, because the subtype specific representation
12668 -- attributes (Size and Alignment) do not affect representation from
12669 -- the point of view of this test.
12671 if Base_Type
(T1
) = Base_Type
(T2
) then
12674 elsif Is_Private_Type
(Base_Type
(T2
))
12675 and then Base_Type
(T1
) = Full_View
(Base_Type
(T2
))
12680 -- Tagged types never have differing representations
12682 if Is_Tagged_Type
(T1
) then
12686 -- Representations are definitely different if conventions differ
12688 if Convention
(T1
) /= Convention
(T2
) then
12692 -- Representations are different if component alignments or scalar
12693 -- storage orders differ.
12695 if (Is_Record_Type
(T1
) or else Is_Array_Type
(T1
))
12697 (Is_Record_Type
(T2
) or else Is_Array_Type
(T2
))
12699 (Component_Alignment
(T1
) /= Component_Alignment
(T2
)
12700 or else Reverse_Storage_Order
(T1
) /= Reverse_Storage_Order
(T2
))
12705 -- For arrays, the only real issue is component size. If we know the
12706 -- component size for both arrays, and it is the same, then that's
12707 -- good enough to know we don't have a change of representation.
12709 if Is_Array_Type
(T1
) then
12710 if Known_Component_Size
(T1
)
12711 and then Known_Component_Size
(T2
)
12712 and then Component_Size
(T1
) = Component_Size
(T2
)
12718 -- Types definitely have same representation if neither has non-standard
12719 -- representation since default representations are always consistent.
12720 -- If only one has non-standard representation, and the other does not,
12721 -- then we consider that they do not have the same representation. They
12722 -- might, but there is no way of telling early enough.
12724 if Has_Non_Standard_Rep
(T1
) then
12725 if not Has_Non_Standard_Rep
(T2
) then
12729 return not Has_Non_Standard_Rep
(T2
);
12732 -- Here the two types both have non-standard representation, and we need
12733 -- to determine if they have the same non-standard representation.
12735 -- For arrays, we simply need to test if the component sizes are the
12736 -- same. Pragma Pack is reflected in modified component sizes, so this
12737 -- check also deals with pragma Pack.
12739 if Is_Array_Type
(T1
) then
12740 return Component_Size
(T1
) = Component_Size
(T2
);
12742 -- Tagged types always have the same representation, because it is not
12743 -- possible to specify different representations for common fields.
12745 elsif Is_Tagged_Type
(T1
) then
12748 -- Case of record types
12750 elsif Is_Record_Type
(T1
) then
12752 -- Packed status must conform
12754 if Is_Packed
(T1
) /= Is_Packed
(T2
) then
12757 -- Otherwise we must check components. Typ2 maybe a constrained
12758 -- subtype with fewer components, so we compare the components
12759 -- of the base types.
12762 Record_Case
: declare
12763 CD1
, CD2
: Entity_Id
;
12765 function Same_Rep
return Boolean;
12766 -- CD1 and CD2 are either components or discriminants. This
12767 -- function tests whether they have the same representation.
12773 function Same_Rep
return Boolean is
12775 if No
(Component_Clause
(CD1
)) then
12776 return No
(Component_Clause
(CD2
));
12778 -- Note: at this point, component clauses have been
12779 -- normalized to the default bit order, so that the
12780 -- comparison of Component_Bit_Offsets is meaningful.
12783 Present
(Component_Clause
(CD2
))
12785 Component_Bit_Offset
(CD1
) = Component_Bit_Offset
(CD2
)
12787 Esize
(CD1
) = Esize
(CD2
);
12791 -- Start of processing for Record_Case
12794 if Has_Discriminants
(T1
) then
12796 -- The number of discriminants may be different if the
12797 -- derived type has fewer (constrained by values). The
12798 -- invisible discriminants retain the representation of
12799 -- the original, so the discrepancy does not per se
12800 -- indicate a different representation.
12802 CD1
:= First_Discriminant
(T1
);
12803 CD2
:= First_Discriminant
(T2
);
12804 while Present
(CD1
) and then Present
(CD2
) loop
12805 if not Same_Rep
then
12808 Next_Discriminant
(CD1
);
12809 Next_Discriminant
(CD2
);
12814 CD1
:= First_Component
(Underlying_Type
(Base_Type
(T1
)));
12815 CD2
:= First_Component
(Underlying_Type
(Base_Type
(T2
)));
12816 while Present
(CD1
) loop
12817 if not Same_Rep
then
12820 Next_Component
(CD1
);
12821 Next_Component
(CD2
);
12829 -- For enumeration types, we must check each literal to see if the
12830 -- representation is the same. Note that we do not permit enumeration
12831 -- representation clauses for Character and Wide_Character, so these
12832 -- cases were already dealt with.
12834 elsif Is_Enumeration_Type
(T1
) then
12835 Enumeration_Case
: declare
12836 L1
, L2
: Entity_Id
;
12839 L1
:= First_Literal
(T1
);
12840 L2
:= First_Literal
(T2
);
12841 while Present
(L1
) loop
12842 if Enumeration_Rep
(L1
) /= Enumeration_Rep
(L2
) then
12851 end Enumeration_Case
;
12853 -- Any other types have the same representation for these purposes
12858 end Same_Representation
;
12860 --------------------------------
12861 -- Resolve_Iterable_Operation --
12862 --------------------------------
12864 procedure Resolve_Iterable_Operation
12866 Cursor
: Entity_Id
;
12875 if not Is_Overloaded
(N
) then
12876 if not Is_Entity_Name
(N
)
12877 or else Ekind
(Entity
(N
)) /= E_Function
12878 or else Scope
(Entity
(N
)) /= Scope
(Typ
)
12879 or else No
(First_Formal
(Entity
(N
)))
12880 or else Etype
(First_Formal
(Entity
(N
))) /= Typ
12882 Error_Msg_N
("iterable primitive must be local function name "
12883 & "whose first formal is an iterable type", N
);
12888 F1
:= First_Formal
(Ent
);
12889 if Nam
= Name_First
then
12891 -- First (Container) => Cursor
12893 if Etype
(Ent
) /= Cursor
then
12894 Error_Msg_N
("primitive for First must yield a curosr", N
);
12897 elsif Nam
= Name_Next
then
12899 -- Next (Container, Cursor) => Cursor
12901 F2
:= Next_Formal
(F1
);
12903 if Etype
(F2
) /= Cursor
12904 or else Etype
(Ent
) /= Cursor
12905 or else Present
(Next_Formal
(F2
))
12907 Error_Msg_N
("no match for Next iterable primitive", N
);
12910 elsif Nam
= Name_Has_Element
then
12912 -- Has_Element (Container, Cursor) => Boolean
12914 F2
:= Next_Formal
(F1
);
12915 if Etype
(F2
) /= Cursor
12916 or else Etype
(Ent
) /= Standard_Boolean
12917 or else Present
(Next_Formal
(F2
))
12919 Error_Msg_N
("no match for Has_Element iterable primitive", N
);
12922 elsif Nam
= Name_Element
then
12923 F2
:= Next_Formal
(F1
);
12926 or else Etype
(F2
) /= Cursor
12927 or else Present
(Next_Formal
(F2
))
12929 Error_Msg_N
("no match for Element iterable primitive", N
);
12934 raise Program_Error
;
12938 -- Overloaded case: find subprogram with proper signature.
12939 -- Caller will report error if no match is found.
12946 Get_First_Interp
(N
, I
, It
);
12947 while Present
(It
.Typ
) loop
12948 if Ekind
(It
.Nam
) = E_Function
12949 and then Scope
(It
.Nam
) = Scope
(Typ
)
12950 and then Etype
(First_Formal
(It
.Nam
)) = Typ
12952 F1
:= First_Formal
(It
.Nam
);
12954 if Nam
= Name_First
then
12955 if Etype
(It
.Nam
) = Cursor
12956 and then No
(Next_Formal
(F1
))
12958 Set_Entity
(N
, It
.Nam
);
12962 elsif Nam
= Name_Next
then
12963 F2
:= Next_Formal
(F1
);
12966 and then No
(Next_Formal
(F2
))
12967 and then Etype
(F2
) = Cursor
12968 and then Etype
(It
.Nam
) = Cursor
12970 Set_Entity
(N
, It
.Nam
);
12974 elsif Nam
= Name_Has_Element
then
12975 F2
:= Next_Formal
(F1
);
12978 and then No
(Next_Formal
(F2
))
12979 and then Etype
(F2
) = Cursor
12980 and then Etype
(It
.Nam
) = Standard_Boolean
12982 Set_Entity
(N
, It
.Nam
);
12983 F2
:= Next_Formal
(F1
);
12987 elsif Nam
= Name_Element
then
12988 F2
:= Next_Formal
(F1
);
12991 and then No
(Next_Formal
(F2
))
12992 and then Etype
(F2
) = Cursor
12994 Set_Entity
(N
, It
.Nam
);
13000 Get_Next_Interp
(I
, It
);
13004 end Resolve_Iterable_Operation
;
13010 procedure Set_Biased
13014 Biased
: Boolean := True)
13018 Set_Has_Biased_Representation
(E
);
13020 if Warn_On_Biased_Representation
then
13022 ("?B?" & Msg
& " forces biased representation for&", N
, E
);
13027 --------------------
13028 -- Set_Enum_Esize --
13029 --------------------
13031 procedure Set_Enum_Esize
(T
: Entity_Id
) is
13037 Init_Alignment
(T
);
13039 -- Find the minimum standard size (8,16,32,64) that fits
13041 Lo
:= Enumeration_Rep
(Entity
(Type_Low_Bound
(T
)));
13042 Hi
:= Enumeration_Rep
(Entity
(Type_High_Bound
(T
)));
13045 if Lo
>= -Uint_2
**07 and then Hi
< Uint_2
**07 then
13046 Sz
:= Standard_Character_Size
; -- May be > 8 on some targets
13048 elsif Lo
>= -Uint_2
**15 and then Hi
< Uint_2
**15 then
13051 elsif Lo
>= -Uint_2
**31 and then Hi
< Uint_2
**31 then
13054 else pragma Assert
(Lo
>= -Uint_2
**63 and then Hi
< Uint_2
**63);
13059 if Hi
< Uint_2
**08 then
13060 Sz
:= Standard_Character_Size
; -- May be > 8 on some targets
13062 elsif Hi
< Uint_2
**16 then
13065 elsif Hi
< Uint_2
**32 then
13068 else pragma Assert
(Hi
< Uint_2
**63);
13073 -- That minimum is the proper size unless we have a foreign convention
13074 -- and the size required is 32 or less, in which case we bump the size
13075 -- up to 32. This is required for C and C++ and seems reasonable for
13076 -- all other foreign conventions.
13078 if Has_Foreign_Convention
(T
)
13079 and then Esize
(T
) < Standard_Integer_Size
13081 -- Don't do this if Short_Enums on target
13083 and then not Target_Short_Enums
13085 Init_Esize
(T
, Standard_Integer_Size
);
13087 Init_Esize
(T
, Sz
);
13089 end Set_Enum_Esize
;
13091 -----------------------------
13092 -- Uninstall_Discriminants --
13093 -----------------------------
13095 procedure Uninstall_Discriminants
(E
: Entity_Id
) is
13101 -- Discriminants have been made visible for type declarations and
13102 -- protected type declarations, not for subtype declarations.
13104 if Nkind
(Parent
(E
)) /= N_Subtype_Declaration
then
13105 Disc
:= First_Discriminant
(E
);
13106 while Present
(Disc
) loop
13107 if Disc
/= Current_Entity
(Disc
) then
13108 Prev
:= Current_Entity
(Disc
);
13109 while Present
(Prev
)
13110 and then Present
(Homonym
(Prev
))
13111 and then Homonym
(Prev
) /= Disc
13113 Prev
:= Homonym
(Prev
);
13119 Set_Is_Immediately_Visible
(Disc
, False);
13121 Outer
:= Homonym
(Disc
);
13122 while Present
(Outer
) and then Scope
(Outer
) = E
loop
13123 Outer
:= Homonym
(Outer
);
13126 -- Reset homonym link of other entities, but do not modify link
13127 -- between entities in current scope, so that the back end can
13128 -- have a proper count of local overloadings.
13131 Set_Name_Entity_Id
(Chars
(Disc
), Outer
);
13133 elsif Scope
(Prev
) /= Scope
(Disc
) then
13134 Set_Homonym
(Prev
, Outer
);
13137 Next_Discriminant
(Disc
);
13140 end Uninstall_Discriminants
;
13142 -------------------------------------------
13143 -- Uninstall_Discriminants_And_Pop_Scope --
13144 -------------------------------------------
13146 procedure Uninstall_Discriminants_And_Pop_Scope
(E
: Entity_Id
) is
13148 if Has_Discriminants
(E
) then
13149 Uninstall_Discriminants
(E
);
13152 end Uninstall_Discriminants_And_Pop_Scope
;
13154 ------------------------------
13155 -- Validate_Address_Clauses --
13156 ------------------------------
13158 procedure Validate_Address_Clauses
is
13159 function Offset_Value
(Expr
: Node_Id
) return Uint
;
13160 -- Given an Address attribute reference, return the value in bits of its
13161 -- offset from the first bit of the underlying entity, or 0 if it is not
13162 -- known at compile time.
13168 function Offset_Value
(Expr
: Node_Id
) return Uint
is
13169 N
: Node_Id
:= Prefix
(Expr
);
13171 Val
: Uint
:= Uint_0
;
13174 -- Climb the prefix chain and compute the cumulative offset
13177 if Is_Entity_Name
(N
) then
13180 elsif Nkind
(N
) = N_Selected_Component
then
13181 Off
:= Component_Bit_Offset
(Entity
(Selector_Name
(N
)));
13182 if Off
/= No_Uint
and then Off
>= Uint_0
then
13189 elsif Nkind
(N
) = N_Indexed_Component
then
13190 Off
:= Indexed_Component_Bit_Offset
(N
);
13191 if Off
/= No_Uint
then
13204 -- Start of processing for Validate_Address_Clauses
13207 for J
in Address_Clause_Checks
.First
.. Address_Clause_Checks
.Last
loop
13209 ACCR
: Address_Clause_Check_Record
13210 renames Address_Clause_Checks
.Table
(J
);
13214 X_Alignment
: Uint
;
13215 Y_Alignment
: Uint
;
13223 -- Skip processing of this entry if warning already posted
13225 if not Address_Warning_Posted
(ACCR
.N
) then
13226 Expr
:= Original_Node
(Expression
(ACCR
.N
));
13228 -- Get alignments, sizes and offset, if any
13230 X_Alignment
:= Alignment
(ACCR
.X
);
13231 X_Size
:= Esize
(ACCR
.X
);
13233 if Present
(ACCR
.Y
) then
13234 Y_Alignment
:= Alignment
(ACCR
.Y
);
13235 Y_Size
:= Esize
(ACCR
.Y
);
13239 and then Nkind
(Expr
) = N_Attribute_Reference
13240 and then Attribute_Name
(Expr
) = Name_Address
13242 X_Offs
:= Offset_Value
(Expr
);
13247 -- Check for known value not multiple of alignment
13249 if No
(ACCR
.Y
) then
13250 if not Alignment_Checks_Suppressed
(ACCR
.X
)
13251 and then X_Alignment
/= 0
13252 and then ACCR
.A
mod X_Alignment
/= 0
13255 ("??specified address for& is inconsistent with "
13256 & "alignment", ACCR
.N
, ACCR
.X
);
13258 ("\??program execution may be erroneous (RM 13.3(27))",
13261 Error_Msg_Uint_1
:= X_Alignment
;
13262 Error_Msg_NE
("\??alignment of & is ^", ACCR
.N
, ACCR
.X
);
13265 -- Check for large object overlaying smaller one
13267 elsif Y_Size
> Uint_0
13268 and then X_Size
> Uint_0
13269 and then X_Offs
+ X_Size
> Y_Size
13271 Error_Msg_NE
("??& overlays smaller object", ACCR
.N
, ACCR
.X
);
13273 ("\??program execution may be erroneous", ACCR
.N
);
13275 Error_Msg_Uint_1
:= X_Size
;
13276 Error_Msg_NE
("\??size of & is ^", ACCR
.N
, ACCR
.X
);
13278 Error_Msg_Uint_1
:= Y_Size
;
13279 Error_Msg_NE
("\??size of & is ^", ACCR
.N
, ACCR
.Y
);
13281 if Y_Size
>= X_Size
then
13282 Error_Msg_Uint_1
:= X_Offs
;
13283 Error_Msg_NE
("\??but offset of & is ^", ACCR
.N
, ACCR
.X
);
13286 -- Check for inadequate alignment, both of the base object
13287 -- and of the offset, if any. We only do this check if the
13288 -- run-time Alignment_Check is active. No point in warning
13289 -- if this check has been suppressed (or is suppressed by
13290 -- default in the non-strict alignment machine case).
13292 -- Note: we do not check the alignment if we gave a size
13293 -- warning, since it would likely be redundant.
13295 elsif not Alignment_Checks_Suppressed
(ACCR
.X
)
13296 and then Y_Alignment
/= Uint_0
13298 (Y_Alignment
< X_Alignment
13301 and then Nkind
(Expr
) = N_Attribute_Reference
13302 and then Attribute_Name
(Expr
) = Name_Address
13303 and then Has_Compatible_Alignment
13304 (ACCR
.X
, Prefix
(Expr
), True) /=
13308 ("??specified address for& may be inconsistent with "
13309 & "alignment", ACCR
.N
, ACCR
.X
);
13311 ("\??program execution may be erroneous (RM 13.3(27))",
13314 Error_Msg_Uint_1
:= X_Alignment
;
13315 Error_Msg_NE
("\??alignment of & is ^", ACCR
.N
, ACCR
.X
);
13317 Error_Msg_Uint_1
:= Y_Alignment
;
13318 Error_Msg_NE
("\??alignment of & is ^", ACCR
.N
, ACCR
.Y
);
13320 if Y_Alignment
>= X_Alignment
then
13322 ("\??but offset is not multiple of alignment", ACCR
.N
);
13328 end Validate_Address_Clauses
;
13330 ---------------------------
13331 -- Validate_Independence --
13332 ---------------------------
13334 procedure Validate_Independence
is
13335 SU
: constant Uint
:= UI_From_Int
(System_Storage_Unit
);
13343 procedure Check_Array_Type
(Atyp
: Entity_Id
);
13344 -- Checks if the array type Atyp has independent components, and
13345 -- if not, outputs an appropriate set of error messages.
13347 procedure No_Independence
;
13348 -- Output message that independence cannot be guaranteed
13350 function OK_Component
(C
: Entity_Id
) return Boolean;
13351 -- Checks one component to see if it is independently accessible, and
13352 -- if so yields True, otherwise yields False if independent access
13353 -- cannot be guaranteed. This is a conservative routine, it only
13354 -- returns True if it knows for sure, it returns False if it knows
13355 -- there is a problem, or it cannot be sure there is no problem.
13357 procedure Reason_Bad_Component
(C
: Entity_Id
);
13358 -- Outputs continuation message if a reason can be determined for
13359 -- the component C being bad.
13361 ----------------------
13362 -- Check_Array_Type --
13363 ----------------------
13365 procedure Check_Array_Type
(Atyp
: Entity_Id
) is
13366 Ctyp
: constant Entity_Id
:= Component_Type
(Atyp
);
13369 -- OK if no alignment clause, no pack, and no component size
13371 if not Has_Component_Size_Clause
(Atyp
)
13372 and then not Has_Alignment_Clause
(Atyp
)
13373 and then not Is_Packed
(Atyp
)
13378 -- Case of component size is greater than or equal to 64 and the
13379 -- alignment of the array is at least as large as the alignment
13380 -- of the component. We are definitely OK in this situation.
13382 if Known_Component_Size
(Atyp
)
13383 and then Component_Size
(Atyp
) >= 64
13384 and then Known_Alignment
(Atyp
)
13385 and then Known_Alignment
(Ctyp
)
13386 and then Alignment
(Atyp
) >= Alignment
(Ctyp
)
13391 -- Check actual component size
13393 if not Known_Component_Size
(Atyp
)
13394 or else not (Addressable
(Component_Size
(Atyp
))
13395 and then Component_Size
(Atyp
) < 64)
13396 or else Component_Size
(Atyp
) mod Esize
(Ctyp
) /= 0
13400 -- Bad component size, check reason
13402 if Has_Component_Size_Clause
(Atyp
) then
13403 P
:= Get_Attribute_Definition_Clause
13404 (Atyp
, Attribute_Component_Size
);
13406 if Present
(P
) then
13407 Error_Msg_Sloc
:= Sloc
(P
);
13408 Error_Msg_N
("\because of Component_Size clause#", N
);
13413 if Is_Packed
(Atyp
) then
13414 P
:= Get_Rep_Pragma
(Atyp
, Name_Pack
);
13416 if Present
(P
) then
13417 Error_Msg_Sloc
:= Sloc
(P
);
13418 Error_Msg_N
("\because of pragma Pack#", N
);
13423 -- No reason found, just return
13428 -- Array type is OK independence-wise
13431 end Check_Array_Type
;
13433 ---------------------
13434 -- No_Independence --
13435 ---------------------
13437 procedure No_Independence
is
13439 if Pragma_Name
(N
) = Name_Independent
then
13440 Error_Msg_NE
("independence cannot be guaranteed for&", N
, E
);
13443 ("independent components cannot be guaranteed for&", N
, E
);
13445 end No_Independence
;
13451 function OK_Component
(C
: Entity_Id
) return Boolean is
13452 Rec
: constant Entity_Id
:= Scope
(C
);
13453 Ctyp
: constant Entity_Id
:= Etype
(C
);
13456 -- OK if no component clause, no Pack, and no alignment clause
13458 if No
(Component_Clause
(C
))
13459 and then not Is_Packed
(Rec
)
13460 and then not Has_Alignment_Clause
(Rec
)
13465 -- Here we look at the actual component layout. A component is
13466 -- addressable if its size is a multiple of the Esize of the
13467 -- component type, and its starting position in the record has
13468 -- appropriate alignment, and the record itself has appropriate
13469 -- alignment to guarantee the component alignment.
13471 -- Make sure sizes are static, always assume the worst for any
13472 -- cases where we cannot check static values.
13474 if not (Known_Static_Esize
(C
)
13476 Known_Static_Esize
(Ctyp
))
13481 -- Size of component must be addressable or greater than 64 bits
13482 -- and a multiple of bytes.
13484 if not Addressable
(Esize
(C
)) and then Esize
(C
) < Uint_64
then
13488 -- Check size is proper multiple
13490 if Esize
(C
) mod Esize
(Ctyp
) /= 0 then
13494 -- Check alignment of component is OK
13496 if not Known_Component_Bit_Offset
(C
)
13497 or else Component_Bit_Offset
(C
) < Uint_0
13498 or else Component_Bit_Offset
(C
) mod Esize
(Ctyp
) /= 0
13503 -- Check alignment of record type is OK
13505 if not Known_Alignment
(Rec
)
13506 or else (Alignment
(Rec
) * SU
) mod Esize
(Ctyp
) /= 0
13511 -- All tests passed, component is addressable
13516 --------------------------
13517 -- Reason_Bad_Component --
13518 --------------------------
13520 procedure Reason_Bad_Component
(C
: Entity_Id
) is
13521 Rec
: constant Entity_Id
:= Scope
(C
);
13522 Ctyp
: constant Entity_Id
:= Etype
(C
);
13525 -- If component clause present assume that's the problem
13527 if Present
(Component_Clause
(C
)) then
13528 Error_Msg_Sloc
:= Sloc
(Component_Clause
(C
));
13529 Error_Msg_N
("\because of Component_Clause#", N
);
13533 -- If pragma Pack clause present, assume that's the problem
13535 if Is_Packed
(Rec
) then
13536 P
:= Get_Rep_Pragma
(Rec
, Name_Pack
);
13538 if Present
(P
) then
13539 Error_Msg_Sloc
:= Sloc
(P
);
13540 Error_Msg_N
("\because of pragma Pack#", N
);
13545 -- See if record has bad alignment clause
13547 if Has_Alignment_Clause
(Rec
)
13548 and then Known_Alignment
(Rec
)
13549 and then (Alignment
(Rec
) * SU
) mod Esize
(Ctyp
) /= 0
13551 P
:= Get_Attribute_Definition_Clause
(Rec
, Attribute_Alignment
);
13553 if Present
(P
) then
13554 Error_Msg_Sloc
:= Sloc
(P
);
13555 Error_Msg_N
("\because of Alignment clause#", N
);
13559 -- Couldn't find a reason, so return without a message
13562 end Reason_Bad_Component
;
13564 -- Start of processing for Validate_Independence
13567 for J
in Independence_Checks
.First
.. Independence_Checks
.Last
loop
13568 N
:= Independence_Checks
.Table
(J
).N
;
13569 E
:= Independence_Checks
.Table
(J
).E
;
13570 IC
:= Pragma_Name
(N
) = Name_Independent_Components
;
13572 -- Deal with component case
13574 if Ekind
(E
) = E_Discriminant
or else Ekind
(E
) = E_Component
then
13575 if not OK_Component
(E
) then
13577 Reason_Bad_Component
(E
);
13582 -- Deal with record with Independent_Components
13584 if IC
and then Is_Record_Type
(E
) then
13585 Comp
:= First_Component_Or_Discriminant
(E
);
13586 while Present
(Comp
) loop
13587 if not OK_Component
(Comp
) then
13589 Reason_Bad_Component
(Comp
);
13593 Next_Component_Or_Discriminant
(Comp
);
13597 -- Deal with address clause case
13599 if Is_Object
(E
) then
13600 Addr
:= Address_Clause
(E
);
13602 if Present
(Addr
) then
13604 Error_Msg_Sloc
:= Sloc
(Addr
);
13605 Error_Msg_N
("\because of Address clause#", N
);
13610 -- Deal with independent components for array type
13612 if IC
and then Is_Array_Type
(E
) then
13613 Check_Array_Type
(E
);
13616 -- Deal with independent components for array object
13618 if IC
and then Is_Object
(E
) and then Is_Array_Type
(Etype
(E
)) then
13619 Check_Array_Type
(Etype
(E
));
13624 end Validate_Independence
;
13626 ------------------------------
13627 -- Validate_Iterable_Aspect --
13628 ------------------------------
13630 procedure Validate_Iterable_Aspect
(Typ
: Entity_Id
; ASN
: Node_Id
) is
13635 Cursor
: constant Entity_Id
:= Get_Cursor_Type
(ASN
, Typ
);
13637 First_Id
: Entity_Id
;
13638 Next_Id
: Entity_Id
;
13639 Has_Element_Id
: Entity_Id
;
13640 Element_Id
: Entity_Id
;
13643 -- If previous error aspect is unusable
13645 if Cursor
= Any_Type
then
13651 Has_Element_Id
:= Empty
;
13652 Element_Id
:= Empty
;
13654 -- Each expression must resolve to a function with the proper signature
13656 Assoc
:= First
(Component_Associations
(Expression
(ASN
)));
13657 while Present
(Assoc
) loop
13658 Expr
:= Expression
(Assoc
);
13661 Prim
:= First
(Choices
(Assoc
));
13663 if Nkind
(Prim
) /= N_Identifier
or else Present
(Next
(Prim
)) then
13664 Error_Msg_N
("illegal name in association", Prim
);
13666 elsif Chars
(Prim
) = Name_First
then
13667 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_First
);
13668 First_Id
:= Entity
(Expr
);
13670 elsif Chars
(Prim
) = Name_Next
then
13671 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_Next
);
13672 Next_Id
:= Entity
(Expr
);
13674 elsif Chars
(Prim
) = Name_Has_Element
then
13675 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_Has_Element
);
13676 Has_Element_Id
:= Entity
(Expr
);
13678 elsif Chars
(Prim
) = Name_Element
then
13679 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_Element
);
13680 Element_Id
:= Entity
(Expr
);
13683 Error_Msg_N
("invalid name for iterable function", Prim
);
13689 if No
(First_Id
) then
13690 Error_Msg_N
("match for First primitive not found", ASN
);
13692 elsif No
(Next_Id
) then
13693 Error_Msg_N
("match for Next primitive not found", ASN
);
13695 elsif No
(Has_Element_Id
) then
13696 Error_Msg_N
("match for Has_Element primitive not found", ASN
);
13698 elsif No
(Element_Id
) then
13701 end Validate_Iterable_Aspect
;
13703 -----------------------------------
13704 -- Validate_Unchecked_Conversion --
13705 -----------------------------------
13707 procedure Validate_Unchecked_Conversion
13709 Act_Unit
: Entity_Id
)
13711 Source
: Entity_Id
;
13712 Target
: Entity_Id
;
13716 -- Obtain source and target types. Note that we call Ancestor_Subtype
13717 -- here because the processing for generic instantiation always makes
13718 -- subtypes, and we want the original frozen actual types.
13720 -- If we are dealing with private types, then do the check on their
13721 -- fully declared counterparts if the full declarations have been
13722 -- encountered (they don't have to be visible, but they must exist).
13724 Source
:= Ancestor_Subtype
(Etype
(First_Formal
(Act_Unit
)));
13726 if Is_Private_Type
(Source
)
13727 and then Present
(Underlying_Type
(Source
))
13729 Source
:= Underlying_Type
(Source
);
13732 Target
:= Ancestor_Subtype
(Etype
(Act_Unit
));
13734 -- If either type is generic, the instantiation happens within a generic
13735 -- unit, and there is nothing to check. The proper check will happen
13736 -- when the enclosing generic is instantiated.
13738 if Is_Generic_Type
(Source
) or else Is_Generic_Type
(Target
) then
13742 if Is_Private_Type
(Target
)
13743 and then Present
(Underlying_Type
(Target
))
13745 Target
:= Underlying_Type
(Target
);
13748 -- Source may be unconstrained array, but not target, except in relaxed
13751 if Is_Array_Type
(Target
)
13752 and then not Is_Constrained
(Target
)
13753 and then not Relaxed_RM_Semantics
13756 ("unchecked conversion to unconstrained array not allowed", N
);
13760 -- Warn if conversion between two different convention pointers
13762 if Is_Access_Type
(Target
)
13763 and then Is_Access_Type
(Source
)
13764 and then Convention
(Target
) /= Convention
(Source
)
13765 and then Warn_On_Unchecked_Conversion
13767 -- Give warnings for subprogram pointers only on most targets
13769 if Is_Access_Subprogram_Type
(Target
)
13770 or else Is_Access_Subprogram_Type
(Source
)
13773 ("?z?conversion between pointers with different conventions!",
13778 -- Warn if one of the operands is Ada.Calendar.Time. Do not emit a
13779 -- warning when compiling GNAT-related sources.
13781 if Warn_On_Unchecked_Conversion
13782 and then not In_Predefined_Unit
(N
)
13783 and then RTU_Loaded
(Ada_Calendar
)
13784 and then (Chars
(Source
) = Name_Time
13786 Chars
(Target
) = Name_Time
)
13788 -- If Ada.Calendar is loaded and the name of one of the operands is
13789 -- Time, there is a good chance that this is Ada.Calendar.Time.
13792 Calendar_Time
: constant Entity_Id
:= Full_View
(RTE
(RO_CA_Time
));
13794 pragma Assert
(Present
(Calendar_Time
));
13796 if Source
= Calendar_Time
or else Target
= Calendar_Time
then
13798 ("?z?representation of 'Time values may change between "
13799 & "'G'N'A'T versions", N
);
13804 -- Make entry in unchecked conversion table for later processing by
13805 -- Validate_Unchecked_Conversions, which will check sizes and alignments
13806 -- (using values set by the back end where possible). This is only done
13807 -- if the appropriate warning is active.
13809 if Warn_On_Unchecked_Conversion
then
13810 Unchecked_Conversions
.Append
13811 (New_Val
=> UC_Entry
'(Eloc => Sloc (N),
13814 Act_Unit => Act_Unit));
13816 -- If both sizes are known statically now, then back-end annotation
13817 -- is not required to do a proper check but if either size is not
13818 -- known statically, then we need the annotation.
13820 if Known_Static_RM_Size (Source)
13822 Known_Static_RM_Size (Target)
13826 Back_Annotate_Rep_Info := True;
13830 -- If unchecked conversion to access type, and access type is declared
13831 -- in the same unit as the unchecked conversion, then set the flag
13832 -- No_Strict_Aliasing (no strict aliasing is implicit here)
13834 if Is_Access_Type (Target) and then
13835 In_Same_Source_Unit (Target, N)
13837 Set_No_Strict_Aliasing (Implementation_Base_Type (Target));
13840 -- Generate N_Validate_Unchecked_Conversion node for back end in case
13841 -- the back end needs to perform special validation checks.
13843 -- Shouldn't this be in Exp_Ch13, since the check only gets done if we
13844 -- have full expansion and the back end is called ???
13847 Make_Validate_Unchecked_Conversion (Sloc (N));
13848 Set_Source_Type (Vnode, Source);
13849 Set_Target_Type (Vnode, Target);
13851 -- If the unchecked conversion node is in a list, just insert before it.
13852 -- If not we have some strange case, not worth bothering about.
13854 if Is_List_Member (N) then
13855 Insert_After (N, Vnode);
13857 end Validate_Unchecked_Conversion;
13859 ------------------------------------
13860 -- Validate_Unchecked_Conversions --
13861 ------------------------------------
13863 procedure Validate_Unchecked_Conversions is
13865 for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop
13867 T : UC_Entry renames Unchecked_Conversions.Table (N);
13869 Act_Unit : constant Entity_Id := T.Act_Unit;
13870 Eloc : constant Source_Ptr := T.Eloc;
13871 Source : constant Entity_Id := T.Source;
13872 Target : constant Entity_Id := T.Target;
13878 -- Skip if function marked as warnings off
13880 if Warnings_Off (Act_Unit) then
13884 -- This validation check, which warns if we have unequal sizes for
13885 -- unchecked conversion, and thus potentially implementation
13886 -- dependent semantics, is one of the few occasions on which we
13887 -- use the official RM size instead of Esize. See description in
13888 -- Einfo "Handling of Type'Size Values" for details.
13890 if Serious_Errors_Detected = 0
13891 and then Known_Static_RM_Size (Source)
13892 and then Known_Static_RM_Size (Target)
13894 -- Don't do the check if warnings off for either type, note the
13895 -- deliberate use of OR here instead of OR ELSE to get the flag
13896 -- Warnings_Off_Used set for both types if appropriate.
13898 and then not (Has_Warnings_Off (Source)
13900 Has_Warnings_Off (Target))
13902 Source_Siz := RM_Size (Source);
13903 Target_Siz := RM_Size (Target);
13905 if Source_Siz /= Target_Siz then
13907 ("?z?types for unchecked conversion have different sizes!",
13910 if All_Errors_Mode then
13911 Error_Msg_Name_1 := Chars (Source);
13912 Error_Msg_Uint_1 := Source_Siz;
13913 Error_Msg_Name_2 := Chars (Target);
13914 Error_Msg_Uint_2 := Target_Siz;
13915 Error_Msg ("\size of % is ^, size of % is ^?z?", Eloc);
13917 Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz);
13919 if Is_Discrete_Type (Source)
13921 Is_Discrete_Type (Target)
13923 if Source_Siz > Target_Siz then
13925 ("\?z?^ high order bits of source will "
13926 & "be ignored!", Eloc);
13928 elsif Is_Unsigned_Type (Source) then
13930 ("\?z?source will be extended with ^ high order "
13931 & "zero bits!", Eloc);
13935 ("\?z?source will be extended with ^ high order "
13936 & "sign bits!", Eloc);
13939 elsif Source_Siz < Target_Siz then
13940 if Is_Discrete_Type (Target) then
13941 if Bytes_Big_Endian then
13943 ("\?z?target value will include ^ undefined "
13944 & "low order bits!", Eloc);
13947 ("\?z?target value will include ^ undefined "
13948 & "high order bits!", Eloc);
13953 ("\?z?^ trailing bits of target value will be "
13954 & "undefined!", Eloc);
13957 else pragma Assert (Source_Siz > Target_Siz);
13958 if Is_Discrete_Type (Source) then
13959 if Bytes_Big_Endian then
13961 ("\?z?^ low order bits of source will be "
13962 & "ignored!", Eloc);
13965 ("\?z?^ high order bits of source will be "
13966 & "ignored!", Eloc);
13971 ("\?z?^ trailing bits of source will be "
13972 & "ignored!", Eloc);
13979 -- If both types are access types, we need to check the alignment.
13980 -- If the alignment of both is specified, we can do it here.
13982 if Serious_Errors_Detected = 0
13983 and then Is_Access_Type (Source)
13984 and then Is_Access_Type (Target)
13985 and then Target_Strict_Alignment
13986 and then Present (Designated_Type (Source))
13987 and then Present (Designated_Type (Target))
13990 D_Source : constant Entity_Id := Designated_Type (Source);
13991 D_Target : constant Entity_Id := Designated_Type (Target);
13994 if Known_Alignment (D_Source)
13996 Known_Alignment (D_Target)
13999 Source_Align : constant Uint := Alignment (D_Source);
14000 Target_Align : constant Uint := Alignment (D_Target);
14003 if Source_Align < Target_Align
14004 and then not Is_Tagged_Type (D_Source)
14006 -- Suppress warning if warnings suppressed on either
14007 -- type or either designated type. Note the use of
14008 -- OR here instead of OR ELSE. That is intentional,
14009 -- we would like to set flag Warnings_Off_Used in
14010 -- all types for which warnings are suppressed.
14012 and then not (Has_Warnings_Off (D_Source)
14014 Has_Warnings_Off (D_Target)
14016 Has_Warnings_Off (Source)
14018 Has_Warnings_Off (Target))
14020 Error_Msg_Uint_1 := Target_Align;
14021 Error_Msg_Uint_2 := Source_Align;
14022 Error_Msg_Node_1 := D_Target;
14023 Error_Msg_Node_2 := D_Source;
14025 ("?z?alignment of & (^) is stricter than "
14026 & "alignment of & (^)!", Eloc);
14028 ("\?z?resulting access value may have invalid "
14029 & "alignment!", Eloc);
14040 end Validate_Unchecked_Conversions;