1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2022, 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 Contracts
; use Contracts
;
30 with Debug
; use Debug
;
31 with Einfo
; use Einfo
;
32 with Einfo
.Entities
; use Einfo
.Entities
;
33 with Einfo
.Utils
; use Einfo
.Utils
;
34 with Elists
; use Elists
;
35 with Errout
; use Errout
;
36 with Exp_Ch3
; use Exp_Ch3
;
37 with Exp_Disp
; use Exp_Disp
;
38 with Exp_Tss
; use Exp_Tss
;
39 with Exp_Util
; use Exp_Util
;
40 with Freeze
; use Freeze
;
41 with Ghost
; use Ghost
;
43 with Lib
.Xref
; use Lib
.Xref
;
44 with Namet
; use Namet
;
45 with Nlists
; use Nlists
;
46 with Nmake
; use Nmake
;
48 with Par_SCO
; use Par_SCO
;
49 with Restrict
; use Restrict
;
50 with Rident
; use Rident
;
51 with Rtsfind
; use Rtsfind
;
53 with Sem_Aux
; use Sem_Aux
;
54 with Sem_Case
; use Sem_Case
;
55 with Sem_Cat
; use Sem_Cat
;
56 with Sem_Ch3
; use Sem_Ch3
;
57 with Sem_Ch6
; use Sem_Ch6
;
58 with Sem_Ch7
; use Sem_Ch7
;
59 with Sem_Ch8
; use Sem_Ch8
;
60 with Sem_Dim
; use Sem_Dim
;
61 with Sem_Eval
; use Sem_Eval
;
62 with Sem_Prag
; use Sem_Prag
;
63 with Sem_Res
; use Sem_Res
;
64 with Sem_Type
; use Sem_Type
;
65 with Sem_Util
; use Sem_Util
;
66 with Sem_Warn
; use Sem_Warn
;
67 with Sinfo
; use Sinfo
;
68 with Sinfo
.Nodes
; use Sinfo
.Nodes
;
69 with Sinfo
.Utils
; use Sinfo
.Utils
;
70 with Sinput
; use Sinput
;
71 with Snames
; use Snames
;
72 with Stand
; use Stand
;
73 with System
.Case_Util
; use System
.Case_Util
;
75 with Targparm
; use Targparm
;
76 with Ttypes
; use Ttypes
;
77 with Tbuild
; use Tbuild
;
78 with Urealp
; use Urealp
;
79 with Warnsw
; use Warnsw
;
81 with GNAT
.Heap_Sort_G
;
83 package body Sem_Ch13
is
85 SSU
: constant Pos
:= System_Storage_Unit
;
86 -- Convenient short hand for commonly used constant
88 -----------------------
89 -- Local Subprograms --
90 -----------------------
92 procedure Adjust_Record_For_Reverse_Bit_Order_Ada_95
(R
: Entity_Id
);
93 -- Helper routine providing the original (pre-AI95-0133) behavior for
94 -- Adjust_Record_For_Reverse_Bit_Order.
96 procedure Alignment_Check_For_Size_Change
(Typ
: Entity_Id
; Size
: Uint
);
97 -- This routine is called after setting one of the sizes of type entity
98 -- Typ to Size. The purpose is to deal with the situation of a derived
99 -- type whose inherited alignment is no longer appropriate for the new
100 -- size value. In this case, we reset the Alignment to unknown.
102 function All_Static_Choices
(L
: List_Id
) return Boolean;
103 -- Returns true if all elements of the list are OK static choices
104 -- as defined below for Is_Static_Choice. Used for case expression
105 -- alternatives and for the right operand of a membership test. An
106 -- others_choice is static if the corresponding expression is static.
107 -- The staticness of the bounds is checked separately.
109 procedure Build_Discrete_Static_Predicate
113 -- Given a predicated type Typ, where Typ is a discrete static subtype,
114 -- whose predicate expression is Expr, tests if Expr is a static predicate,
115 -- and if so, builds the predicate range list. Nam is the name of the one
116 -- argument to the predicate function. Occurrences of the type name in the
117 -- predicate expression have been replaced by identifier references to this
118 -- name, which is unique, so any identifier with Chars matching Nam must be
119 -- a reference to the type. If the predicate is non-static, this procedure
120 -- returns doing nothing. If the predicate is static, then the predicate
121 -- list is stored in Static_Discrete_Predicate (Typ), and the Expr is
122 -- rewritten as a canonicalized membership operation.
124 function Build_Export_Import_Pragma
126 Id
: Entity_Id
) return Node_Id
;
127 -- Create the corresponding pragma for aspect Export or Import denoted by
128 -- Asp. Id is the related entity subject to the aspect. Return Empty when
129 -- the expression of aspect Asp evaluates to False or is erroneous.
131 function Build_Predicate_Function_Declaration
132 (Typ
: Entity_Id
) return Node_Id
;
133 -- Build the declaration for a predicate function. The declaration is built
134 -- at the end of the declarative part containing the type definition, which
135 -- may be before the freeze point of the type. The predicate expression is
136 -- preanalyzed at this point, to catch visibility errors.
138 procedure Build_Predicate_Function
(Typ
: Entity_Id
; N
: Node_Id
);
139 -- If Typ has predicates (indicated by Has_Predicates being set for Typ),
140 -- then either there are pragma Predicate entries on the rep chain for the
141 -- type (note that Predicate aspects are converted to pragma Predicate), or
142 -- there are inherited aspects from a parent type, or ancestor subtypes.
143 -- This procedure builds body for the Predicate function that tests these
144 -- predicates. N is the freeze node for the type. The spec of the function
145 -- is inserted before the freeze node, and the body of the function is
146 -- inserted after the freeze node.
148 procedure Check_Pool_Size_Clash
(Ent
: Entity_Id
; SP
, SS
: Node_Id
);
149 -- Called if both Storage_Pool and Storage_Size attribute definition
150 -- clauses (SP and SS) are present for entity Ent. Issue error message.
152 procedure Freeze_Entity_Checks
(N
: Node_Id
);
153 -- Called from Analyze_Freeze_Entity and Analyze_Generic_Freeze Entity
154 -- to generate appropriate semantic checks that are delayed until this
155 -- point (they had to be delayed this long for cases of delayed aspects,
156 -- e.g. analysis of statically predicated subtypes in choices, for which
157 -- we have to be sure the subtypes in question are frozen before checking).
159 function Get_Alignment_Value
(Expr
: Node_Id
) return Uint
;
160 -- Given the expression for an alignment value, returns the corresponding
161 -- Uint value. If the value is inappropriate, then error messages are
162 -- posted as required, and a value of No_Uint is returned.
164 function Is_Operational_Item
(N
: Node_Id
) return Boolean;
165 -- A specification for a stream attribute is allowed before the full type
166 -- is declared, as explained in AI-00137 and the corrigendum. Attributes
167 -- that do not specify a representation characteristic are operational
170 function Is_Static_Choice
(N
: Node_Id
) return Boolean;
171 -- Returns True if N represents a static choice (static subtype, or
172 -- static subtype indication, or static expression, or static range).
174 -- Note that this is a bit more inclusive than we actually need
175 -- (in particular membership tests do not allow the use of subtype
176 -- indications). But that doesn't matter, we have already checked
177 -- that the construct is legal to get this far.
179 function Is_Type_Related_Rep_Item
(N
: Node_Id
) return Boolean;
180 -- Returns True for a representation clause/pragma that specifies a
181 -- type-related representation (as opposed to operational) aspect.
183 function Is_Predicate_Static
186 Warn
: Boolean := True) return Boolean;
187 -- Given predicate expression Expr, tests if Expr is predicate-static in
188 -- the sense of the rules in (RM 3.2.4 (15-24)). Occurrences of the type
189 -- name in the predicate expression have been replaced by references to
190 -- an identifier whose Chars field is Nam. This name is unique, so any
191 -- identifier with Chars matching Nam must be a reference to the type.
192 -- Returns True if the expression is predicate-static and False otherwise,
193 -- but is not in the business of setting flags or issuing error messages.
195 -- Only scalar types can have static predicates, so False is always
196 -- returned for non-scalar types.
198 -- Note: the RM seems to suggest that string types can also have static
199 -- predicates. But that really makes little sense as very few useful
200 -- predicates can be constructed for strings. Remember that:
204 -- is not a static expression. So even though the clearly faulty RM wording
205 -- allows the following:
207 -- subtype S is String with Static_Predicate => S < "DEF"
209 -- We can't allow this, otherwise we have predicate-static applying to a
210 -- larger class than static expressions, which was never intended.
212 -- The Warn parameter is True iff this is not a recursive call. This
213 -- parameter is used to avoid generating warnings for subexpressions and
214 -- for cases where the predicate expression (as originally written by
215 -- the user, before any transformations) is a Boolean literal.
217 procedure New_Put_Image_Subprogram
221 -- Similar to New_Stream_Subprogram, but for the Put_Image attribute
223 procedure New_Stream_Subprogram
227 Nam
: TSS_Name_Type
);
228 -- Create a subprogram renaming of a given stream attribute to the
229 -- designated subprogram and then in the tagged case, provide this as a
230 -- primitive operation, or in the untagged case make an appropriate TSS
231 -- entry. This is more properly an expansion activity than just semantics,
232 -- but the presence of user-defined stream functions for limited types
233 -- is a legality check, which is why this takes place here rather than in
234 -- exp_ch13, where it was previously. Nam indicates the name of the TSS
235 -- function to be generated.
237 -- To avoid elaboration anomalies with freeze nodes, for untagged types
238 -- we generate both a subprogram declaration and a subprogram renaming
239 -- declaration, so that the attribute specification is handled as a
240 -- renaming_as_body. For tagged types, the specification is one of the
243 procedure No_Type_Rep_Item
(N
: Node_Id
);
244 -- Output message indicating that no type-related aspects can be
245 -- specified due to some property of the parent type.
247 procedure Register_Address_Clause_Check
253 -- Register a check for the address clause N. The rest of the parameters
254 -- are in keeping with the components of Address_Clause_Check_Record below.
256 procedure Validate_Aspect_Aggregate
(N
: Node_Id
);
257 -- Check legality of operations given in the Ada 2022 Aggregate aspect for
260 procedure Resolve_Aspect_Aggregate
263 -- Resolve each one of the operations specified in the specification of
266 procedure Validate_Aspect_Stable_Properties
267 (E
: Entity_Id
; N
: Node_Id
; Class_Present
: Boolean);
268 -- Check legality of functions given in the Ada 2022 Stable_Properties
269 -- (or Stable_Properties'Class) aspect.
271 procedure Validate_Storage_Model_Type_Aspect
272 (Typ
: Entity_Id
; ASN
: Node_Id
);
273 -- Check legality and completeness of the aggregate associations given in
274 -- the Storage_Model_Type aspect associated with Typ.
276 procedure Resolve_Storage_Model_Type_Argument
279 Addr_Type
: in out Entity_Id
;
281 -- Resolve argument N to be of the proper kind (when a type or constant)
282 -- or to have the proper profile (when a subprogram).
284 procedure Resolve_Aspect_Stable_Properties
285 (Typ_Or_Subp
: Entity_Id
;
287 Class_Present
: Boolean);
288 -- Resolve each one of the functions specified in the specification of
289 -- aspect Stable_Properties (or Stable_Properties'Class).
291 procedure Resolve_Iterable_Operation
296 -- If the name of a primitive operation for an Iterable aspect is
297 -- overloaded, resolve according to required signature.
303 Biased
: Boolean := True);
304 -- If Biased is True, sets Has_Biased_Representation flag for E, and
305 -- outputs a warning message at node N if Warn_On_Biased_Representation is
306 -- is True. This warning inserts the string Msg to describe the construct
309 -----------------------------------------------------------
310 -- Visibility of Discriminants in Aspect Specifications --
311 -----------------------------------------------------------
313 -- The discriminants of a type are visible when analyzing the aspect
314 -- specifications of a type declaration or protected type declaration,
315 -- but not when analyzing those of a subtype declaration. The following
316 -- routines enforce this distinction.
318 procedure Push_Type
(E
: Entity_Id
);
319 -- Push scope E and make visible the discriminants of type entity E if E
320 -- has discriminants and is not a subtype.
322 procedure Pop_Type
(E
: Entity_Id
);
323 -- Remove visibility to the discriminants of type entity E and pop the
324 -- scope stack if E has discriminants and is not a subtype.
326 ----------------------------------------------
327 -- Table for Validate_Unchecked_Conversions --
328 ----------------------------------------------
330 -- The following table collects unchecked conversions for validation.
331 -- Entries are made by Validate_Unchecked_Conversion and then the call
332 -- to Validate_Unchecked_Conversions does the actual error checking and
333 -- posting of warnings. The reason for this delayed processing is to take
334 -- advantage of back-annotations of size and alignment values performed by
337 -- Note: the reason we store a Source_Ptr value instead of a Node_Id is
338 -- that by the time Validate_Unchecked_Conversions is called, Sprint will
339 -- already have modified all Sloc values if the -gnatD option is set.
341 type UC_Entry
is record
342 Eloc
: Source_Ptr
; -- node used for posting warnings
343 Source
: Entity_Id
; -- source type for unchecked conversion
344 Target
: Entity_Id
; -- target type for unchecked conversion
345 Act_Unit
: Entity_Id
; -- actual function instantiated
348 package Unchecked_Conversions
is new Table
.Table
(
349 Table_Component_Type
=> UC_Entry
,
350 Table_Index_Type
=> Int
,
351 Table_Low_Bound
=> 1,
353 Table_Increment
=> 200,
354 Table_Name
=> "Unchecked_Conversions");
356 ----------------------------------------
357 -- Table for Validate_Address_Clauses --
358 ----------------------------------------
360 -- If an address clause has the form
362 -- for X'Address use Expr
364 -- where Expr has a value known at compile time or is of the form Y'Address
365 -- or recursively is a reference to a constant initialized with either of
366 -- these forms, and the value of Expr is not a multiple of X's alignment,
367 -- or if Y has a smaller alignment than X, then that merits a warning about
368 -- possible bad alignment. The following table collects address clauses of
369 -- this kind. We put these in a table so that they can be checked after the
370 -- back end has completed annotation of the alignments of objects, since we
371 -- can catch more cases that way.
373 type Address_Clause_Check_Record
is record
375 -- The address clause
378 -- The entity of the object subject to the address clause
381 -- The value of the address in the first case
384 -- The entity of the object being overlaid in the second case
387 -- Whether the address is offset within Y in the second case
389 Alignment_Checks_Suppressed
: Boolean;
390 -- Whether alignment checks are suppressed by an active scope suppress
391 -- setting. We need to save the value in order to be able to reuse it
392 -- after the back end has been run.
395 package Address_Clause_Checks
is new Table
.Table
(
396 Table_Component_Type
=> Address_Clause_Check_Record
,
397 Table_Index_Type
=> Int
,
398 Table_Low_Bound
=> 1,
400 Table_Increment
=> 200,
401 Table_Name
=> "Address_Clause_Checks");
403 function Alignment_Checks_Suppressed
404 (ACCR
: Address_Clause_Check_Record
) return Boolean;
405 -- Return whether the alignment check generated for the address clause
408 ---------------------------------
409 -- Alignment_Checks_Suppressed --
410 ---------------------------------
412 function Alignment_Checks_Suppressed
413 (ACCR
: Address_Clause_Check_Record
) return Boolean
416 if Checks_May_Be_Suppressed
(ACCR
.X
) then
417 return Is_Check_Suppressed
(ACCR
.X
, Alignment_Check
);
419 return ACCR
.Alignment_Checks_Suppressed
;
421 end Alignment_Checks_Suppressed
;
423 -----------------------------------------
424 -- Adjust_Record_For_Reverse_Bit_Order --
425 -----------------------------------------
427 procedure Adjust_Record_For_Reverse_Bit_Order
(R
: Entity_Id
) is
428 Max_Machine_Scalar_Size
: constant Uint
:=
429 UI_From_Int
(System_Max_Integer_Size
);
430 -- We use this as the maximum machine scalar size
432 SSU
: constant Uint
:= UI_From_Int
(System_Storage_Unit
);
439 -- The processing done here used to depend on the Ada version, but the
440 -- behavior has been changed by AI95-0133. However this AI is a Binding
441 -- Interpretation, so we now implement it even in Ada 95 mode. But the
442 -- original behavior from unamended Ada 95 is available for the sake of
443 -- compatibility under the debugging switch -gnatd.p in Ada 95 mode.
445 if Ada_Version
< Ada_2005
and then Debug_Flag_Dot_P
then
446 Adjust_Record_For_Reverse_Bit_Order_Ada_95
(R
);
450 -- For Ada 2005, we do machine scalar processing, as fully described In
451 -- AI-133. This involves gathering all components which start at the
452 -- same byte offset and processing them together. Same approach is still
453 -- valid in later versions including Ada 2012.
455 -- Note that component clauses found on record types may be inherited,
456 -- in which case the layout of the component with such a clause still
457 -- has to be done at this point. Therefore, the processing done here
458 -- must exclusively rely on the Component_Clause of the component.
460 -- This first loop through components does two things. First it deals
461 -- with the case of components with component clauses whose length is
462 -- greater than the maximum machine scalar size (either accepting them
463 -- or rejecting as needed). Second, it counts the number of components
464 -- with component clauses whose length does not exceed this maximum for
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 last bit
483 -- + 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 scalar "
516 & "size (^)", First_Bit
(CC
));
518 if (Lbit
+ 1) mod SSU
/= 0 then
519 Error_Msg_Uint_1
:= SSU
;
521 ("\and is not a multiple of Storage_Unit (^) "
522 & "(RM 13.5.1(10))", First_Bit
(CC
));
525 Error_Msg_Uint_1
:= Fbit
;
527 ("\and first bit (^) is non-zero "
528 & "(RM 13.4.1(10))", First_Bit
(CC
));
532 -- OK case of machine scalar related component clause. For now,
536 Num_CC
:= Num_CC
+ 1;
541 Next_Component_Or_Discriminant
(Comp
);
544 -- We need to sort the component clauses on the basis of the Position
545 -- values in the clause, so we can group clauses with the same Position
546 -- together to determine the relevant machine scalar size.
549 Comps
: array (0 .. Num_CC
) of Entity_Id
;
550 -- Array to collect component and discriminant entities. The data
551 -- starts at index 1, the 0'th entry is for the sort routine.
553 function CP_Lt
(Op1
, Op2
: Natural) return Boolean;
554 -- Compare routine for Sort
556 procedure CP_Move
(From
: Natural; To
: Natural);
557 -- Move routine for Sort
559 package Sorting
is new GNAT
.Heap_Sort_G
(CP_Move
, CP_Lt
);
562 -- Maximum last bit value of any component in this set
565 -- Corresponding machine scalar size
569 -- Start and stop positions in the component list of the set of
570 -- components with the same starting position (that constitute
571 -- components in a single machine scalar).
577 function CP_Lt
(Op1
, Op2
: Natural) return Boolean is
580 Position
(Component_Clause
(Comps
(Op1
))) <
581 Position
(Component_Clause
(Comps
(Op2
)));
588 procedure CP_Move
(From
: Natural; To
: Natural) is
590 Comps
(To
) := Comps
(From
);
593 -- Start of processing for Sort_CC
596 -- Collect the machine scalar relevant component clauses
599 Comp
:= First_Component_Or_Discriminant
(R
);
600 while Present
(Comp
) loop
602 CC
: constant Node_Id
:= Component_Clause
(Comp
);
605 -- Collect only component clauses whose last bit is less than
606 -- machine scalar size. Any component clause whose last bit
607 -- exceeds this value does not take part in machine scalar
608 -- layout considerations. The test for Error_Posted makes sure
609 -- we exclude component clauses for which we already posted an
613 and then not Error_Posted
(Last_Bit
(CC
))
614 and then Static_Integer
(Last_Bit
(CC
)) <
615 Max_Machine_Scalar_Size
617 Num_CC
:= Num_CC
+ 1;
618 Comps
(Num_CC
) := Comp
;
622 Next_Component_Or_Discriminant
(Comp
);
625 -- Sort by ascending position number
627 Sorting
.Sort
(Num_CC
);
629 -- We now have all the components whose size does not exceed the max
630 -- machine scalar value, sorted by starting position. In this loop we
631 -- gather groups of clauses starting at the same position, to process
632 -- them in accordance with AI-133.
635 while Stop
< Num_CC
loop
640 (Last_Bit
(Component_Clause
(Comps
(Start
))));
641 while Stop
< Num_CC
loop
643 (Position
(Component_Clause
(Comps
(Stop
+ 1)))) =
645 (Position
(Component_Clause
(Comps
(Stop
))))
653 (Component_Clause
(Comps
(Stop
)))));
659 -- Now we have a group of component clauses from Start to Stop
660 -- whose positions are identical, and MaxL is the maximum last
661 -- bit value of any of these components.
663 -- We need to determine the corresponding machine scalar size.
664 -- This loop assumes that machine scalar sizes are even, and that
665 -- each possible machine scalar has twice as many bits as the next
668 MSS
:= Max_Machine_Scalar_Size
;
670 and then (MSS
/ 2) >= SSU
671 and then (MSS
/ 2) > MaxL
676 -- Here is where we fix up the Component_Bit_Offset value to
677 -- account for the reverse bit order. Some examples of what needs
678 -- to be done for the case of a machine scalar size of 8 are:
680 -- First_Bit .. Last_Bit Component_Bit_Offset
692 -- The rule is that the first bit is obtained by subtracting the
693 -- old ending bit from machine scalar size - 1.
695 for C
in Start
.. Stop
loop
697 Comp
: constant Entity_Id
:= Comps
(C
);
698 CC
: constant Node_Id
:= Component_Clause
(Comp
);
700 FB
: constant Uint
:= Static_Integer
(First_Bit
(CC
));
701 LB
: constant Uint
:= Static_Integer
(Last_Bit
(CC
));
702 NFB
: constant Uint
:= MSS
- 1 - LB
;
703 NLB
: constant Uint
:= NFB
+ LB
- FB
;
704 Pos
: constant Uint
:= Static_Integer
(Position
(CC
));
707 -- Do not warn for the artificial clause built for the tag
708 -- in Check_Record_Representation_Clause if it is inherited.
710 if Warn_On_Reverse_Bit_Order
711 and then Chars
(Comp
) /= Name_uTag
713 Error_Msg_Uint_1
:= MSS
;
715 ("info: reverse bit order in machine scalar of "
716 & "length^?.v?", First_Bit
(CC
));
717 Error_Msg_Uint_1
:= NFB
;
718 Error_Msg_Uint_2
:= NLB
;
720 if Bytes_Big_Endian
then
722 ("\big-endian range for component & is ^ .. ^?.v?",
723 First_Bit
(CC
), Comp
);
726 ("\little-endian range for component " &
728 First_Bit
(CC
), Comp
);
732 Set_Component_Bit_Offset
(Comp
, Pos
* SSU
+ NFB
);
733 Set_Esize
(Comp
, 1 + (NLB
- NFB
));
734 Set_Normalized_First_Bit
(Comp
, NFB
mod SSU
);
735 Set_Normalized_Position
(Comp
, Pos
+ NFB
/ SSU
);
740 end Adjust_Record_For_Reverse_Bit_Order
;
742 ------------------------------------------------
743 -- Adjust_Record_For_Reverse_Bit_Order_Ada_95 --
744 ------------------------------------------------
746 procedure Adjust_Record_For_Reverse_Bit_Order_Ada_95
(R
: Entity_Id
) is
751 -- For Ada 95, we just renumber bits within a storage unit. We do the
752 -- same for Ada 83 mode, since we recognize the Bit_Order attribute in
753 -- Ada 83, and are free to add this extension.
755 Comp
:= First_Component_Or_Discriminant
(R
);
756 while Present
(Comp
) loop
757 CC
:= Component_Clause
(Comp
);
759 -- If component clause is present, then deal with the non-default
760 -- bit order case for Ada 95 mode.
762 -- We only do this processing for the base type, and in fact that
763 -- is important, since otherwise if there are record subtypes, we
764 -- could reverse the bits once for each subtype, which is wrong.
766 if Present
(CC
) and then Ekind
(R
) = E_Record_Type
then
768 CFB
: constant Uint
:= Component_Bit_Offset
(Comp
);
769 CSZ
: constant Uint
:= Esize
(Comp
);
770 CLC
: constant Node_Id
:= Component_Clause
(Comp
);
771 Pos
: constant Node_Id
:= Position
(CLC
);
772 FB
: constant Node_Id
:= First_Bit
(CLC
);
774 Storage_Unit_Offset
: constant Uint
:=
775 CFB
/ System_Storage_Unit
;
777 Start_Bit
: constant Uint
:=
778 CFB
mod System_Storage_Unit
;
781 -- Cases where field goes over storage unit boundary
783 if Start_Bit
+ CSZ
> System_Storage_Unit
then
785 -- Allow multi-byte field but generate warning
787 if Start_Bit
mod System_Storage_Unit
= 0
788 and then CSZ
mod System_Storage_Unit
= 0
791 ("info: multi-byte field specified with non-standard "
792 & "Bit_Order?.v?", CLC
);
794 if Bytes_Big_Endian
then
796 ("\bytes are not reversed "
797 & "(component is big-endian)?.v?", CLC
);
800 ("\bytes are not reversed "
801 & "(component is little-endian)?.v?", CLC
);
804 -- Do not allow non-contiguous field
808 ("attempt to specify non-contiguous field not "
811 ("\caused by non-standard Bit_Order specified in "
812 & "legacy Ada 95 mode", CLC
);
815 -- Case where field fits in one storage unit
818 -- Give warning if suspicious component clause
820 if Intval
(FB
) >= System_Storage_Unit
821 and then Warn_On_Reverse_Bit_Order
824 ("info: Bit_Order clause does not affect byte "
825 & "ordering?.v?", Pos
);
827 Intval
(Pos
) + Intval
(FB
) /
830 ("info: position normalized to ^ before bit order "
831 & "interpreted?.v?", Pos
);
834 -- Here is where we fix up the Component_Bit_Offset value
835 -- to account for the reverse bit order. Some examples of
836 -- what needs to be done are:
838 -- First_Bit .. Last_Bit Component_Bit_Offset
850 -- The rule is that the first bit is obtained by subtracting
851 -- the old ending bit from storage_unit - 1.
853 Set_Component_Bit_Offset
(Comp
,
854 (Storage_Unit_Offset
* System_Storage_Unit
) +
855 (System_Storage_Unit
- 1) -
856 (Start_Bit
+ CSZ
- 1));
858 Set_Normalized_Position
(Comp
,
859 Component_Bit_Offset
(Comp
) / System_Storage_Unit
);
861 Set_Normalized_First_Bit
(Comp
,
862 Component_Bit_Offset
(Comp
) mod System_Storage_Unit
);
867 Next_Component_Or_Discriminant
(Comp
);
869 end Adjust_Record_For_Reverse_Bit_Order_Ada_95
;
871 -------------------------------------
872 -- Alignment_Check_For_Size_Change --
873 -------------------------------------
875 procedure Alignment_Check_For_Size_Change
(Typ
: Entity_Id
; Size
: Uint
) is
877 -- If the alignment is known, and not set by a rep clause, and is
878 -- inconsistent with the size being set, then reset it to unknown,
879 -- we assume in this case that the size overrides the inherited
880 -- alignment, and that the alignment must be recomputed.
882 if Known_Alignment
(Typ
)
883 and then not Has_Alignment_Clause
(Typ
)
884 and then Present
(Size
)
885 and then Size
mod (Alignment
(Typ
) * SSU
) /= 0
887 Reinit_Alignment
(Typ
);
889 end Alignment_Check_For_Size_Change
;
891 -----------------------------------
892 -- All_Membership_Choices_Static --
893 -----------------------------------
895 function All_Membership_Choices_Static
(Expr
: Node_Id
) return Boolean is
896 pragma Assert
(Nkind
(Expr
) in N_Membership_Test
);
899 (Present
(Right_Opnd
(Expr
))
901 Present
(Alternatives
(Expr
)));
903 if Present
(Right_Opnd
(Expr
)) then
904 return Is_Static_Choice
(Right_Opnd
(Expr
));
906 return All_Static_Choices
(Alternatives
(Expr
));
908 end All_Membership_Choices_Static
;
910 ------------------------
911 -- All_Static_Choices --
912 ------------------------
914 function All_Static_Choices
(L
: List_Id
) return Boolean is
919 while Present
(N
) loop
920 if not Is_Static_Choice
(N
) then
928 end All_Static_Choices
;
930 -------------------------------------
931 -- Analyze_Aspects_At_Freeze_Point --
932 -------------------------------------
934 procedure Analyze_Aspects_At_Freeze_Point
(E
: Entity_Id
) is
935 procedure Analyze_Aspect_Default_Value
(ASN
: Node_Id
);
936 -- This routine analyzes an Aspect_Default_[Component_]Value denoted by
937 -- the aspect specification node ASN.
939 procedure Check_Aspect_Too_Late
(N
: Node_Id
);
940 -- This procedure is similar to Rep_Item_Too_Late for representation
941 -- aspects that apply to type and that do not have a corresponding
943 -- Used to check in particular that the expression associated with
944 -- aspect node N for the given type (entity) of the aspect does not
945 -- appear too late according to the rules in RM 13.1(9) and 13.1(10).
947 procedure Make_Pragma_From_Boolean_Aspect
(ASN
: Node_Id
);
948 -- Given an aspect specification node ASN whose expression is an
949 -- optional Boolean, this routines creates the corresponding pragma
950 -- at the freezing point.
952 ----------------------------------
953 -- Analyze_Aspect_Default_Value --
954 ----------------------------------
956 procedure Analyze_Aspect_Default_Value
(ASN
: Node_Id
) is
957 Ent
: constant Entity_Id
:= Entity
(ASN
);
958 Expr
: constant Node_Id
:= Expression
(ASN
);
961 Set_Has_Default_Aspect
(Base_Type
(Ent
));
963 if Is_Scalar_Type
(Ent
) then
964 Set_Default_Aspect_Value
(Base_Type
(Ent
), Expr
);
966 Set_Default_Aspect_Component_Value
(Base_Type
(Ent
), Expr
);
969 Check_Aspect_Too_Late
(ASN
);
970 end Analyze_Aspect_Default_Value
;
972 ---------------------------
973 -- Check_Aspect_Too_Late --
974 ---------------------------
976 procedure Check_Aspect_Too_Late
(N
: Node_Id
) is
977 Typ
: constant Entity_Id
:= Entity
(N
);
978 Expr
: constant Node_Id
:= Expression
(N
);
980 function Find_Type_Reference
981 (Typ
: Entity_Id
; Expr
: Node_Id
) return Boolean;
982 -- Return True if a reference to type Typ is found in the expression
985 -------------------------
986 -- Find_Type_Reference --
987 -------------------------
989 function Find_Type_Reference
990 (Typ
: Entity_Id
; Expr
: Node_Id
) return Boolean
992 function Find_Type
(N
: Node_Id
) return Traverse_Result
;
993 -- Set Found to True if N refers to Typ
999 function Find_Type
(N
: Node_Id
) return Traverse_Result
is
1002 or else (Nkind
(N
) in N_Identifier | N_Expanded_Name
1003 and then Present
(Entity
(N
))
1004 and then Entity
(N
) = Typ
)
1012 function Search_Type_Reference
is new Traverse_Func
(Find_Type
);
1015 return Search_Type_Reference
(Expr
) = Abandon
;
1016 end Find_Type_Reference
;
1018 Parent_Type
: Entity_Id
;
1021 -- Ensure Expr is analyzed so that e.g. all types are properly
1022 -- resolved for Find_Type_Reference.
1026 -- A self-referential aspect is illegal if it forces freezing the
1027 -- entity before the corresponding aspect has been analyzed.
1029 if Find_Type_Reference
(Typ
, Expr
) then
1031 ("aspect specification causes premature freezing of&", N
, Typ
);
1034 -- For representation aspects, check for case of untagged derived
1035 -- type whose parent either has primitive operations (pre Ada 2022),
1036 -- or is a by-reference type (RM 13.1(10)).
1037 -- Strictly speaking the check also applies to Ada 2012 but it is
1038 -- really too constraining for existing code already, so relax it.
1039 -- ??? Confirming aspects should be allowed here.
1041 if Is_Representation_Aspect
(Get_Aspect_Id
(N
))
1042 and then Is_Derived_Type
(Typ
)
1043 and then not Is_Tagged_Type
(Typ
)
1045 Parent_Type
:= Etype
(Base_Type
(Typ
));
1047 if Ada_Version
<= Ada_2012
1048 and then Has_Primitive_Operations
(Parent_Type
)
1051 ("|representation aspect not permitted before Ada 2022: " &
1052 "use -gnat2022!", N
);
1054 ("\parent type & has primitive operations!", N
, Parent_Type
);
1056 elsif Is_By_Reference_Type
(Parent_Type
) then
1057 No_Type_Rep_Item
(N
);
1059 ("\parent type & is a by-reference type!", N
, Parent_Type
);
1062 end Check_Aspect_Too_Late
;
1064 -------------------------------------
1065 -- Make_Pragma_From_Boolean_Aspect --
1066 -------------------------------------
1068 procedure Make_Pragma_From_Boolean_Aspect
(ASN
: Node_Id
) is
1069 Ident
: constant Node_Id
:= Identifier
(ASN
);
1070 A_Name
: constant Name_Id
:= Chars
(Ident
);
1071 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(A_Name
);
1072 Ent
: constant Entity_Id
:= Entity
(ASN
);
1073 Expr
: constant Node_Id
:= Expression
(ASN
);
1074 Loc
: constant Source_Ptr
:= Sloc
(ASN
);
1076 procedure Check_False_Aspect_For_Derived_Type
;
1077 -- This procedure checks for the case of a false aspect for a derived
1078 -- type, which improperly tries to cancel an aspect inherited from
1081 -----------------------------------------
1082 -- Check_False_Aspect_For_Derived_Type --
1083 -----------------------------------------
1085 procedure Check_False_Aspect_For_Derived_Type
is
1089 -- We are only checking derived types
1091 if not Is_Derived_Type
(E
) then
1095 Par
:= Nearest_Ancestor
(E
);
1101 if not Is_Atomic
(Par
) then
1105 when Aspect_Atomic_Components
=>
1106 if not Has_Atomic_Components
(Par
) then
1110 when Aspect_Discard_Names
=>
1111 if not Discard_Names
(Par
) then
1116 if not Is_Packed
(Par
) then
1120 when Aspect_Unchecked_Union
=>
1121 if not Is_Unchecked_Union
(Par
) then
1125 when Aspect_Volatile
=>
1126 if not Is_Volatile
(Par
) then
1130 when Aspect_Volatile_Components
=>
1131 if not Has_Volatile_Components
(Par
) then
1135 when Aspect_Volatile_Full_Access
1136 | Aspect_Full_Access_Only
1138 if not Is_Volatile_Full_Access
(Par
) then
1146 -- Fall through means we are canceling an inherited aspect
1148 Error_Msg_Name_1
:= A_Name
;
1150 ("derived type& inherits aspect%, cannot cancel", Expr
, E
);
1151 end Check_False_Aspect_For_Derived_Type
;
1158 -- Start of processing for Make_Pragma_From_Boolean_Aspect
1161 if Present
(Expr
) and then Is_False
(Static_Boolean
(Expr
)) then
1162 Check_False_Aspect_For_Derived_Type
;
1165 -- There is no Full_Access_Only pragma so use VFA instead
1167 if A_Name
= Name_Full_Access_Only
then
1168 P_Name
:= Name_Volatile_Full_Access
;
1175 Pragma_Identifier
=>
1176 Make_Identifier
(Sloc
(Ident
), P_Name
),
1177 Pragma_Argument_Associations
=> New_List
(
1178 Make_Pragma_Argument_Association
(Sloc
(Ident
),
1179 Expression
=> New_Occurrence_Of
(Ent
, Sloc
(Ident
)))));
1181 Set_From_Aspect_Specification
(Prag
, True);
1182 Set_Corresponding_Aspect
(Prag
, ASN
);
1183 Set_Aspect_Rep_Item
(ASN
, Prag
);
1184 Set_Is_Delayed_Aspect
(Prag
);
1185 Set_Parent
(Prag
, ASN
);
1187 end Make_Pragma_From_Boolean_Aspect
;
1195 -- Start of processing for Analyze_Aspects_At_Freeze_Point
1198 -- Must be visible in current scope, but if this is a type from a nested
1199 -- package it may be frozen from an object declaration in the enclosing
1200 -- scope, so install the package declarations to complete the analysis
1201 -- of the aspects, if any. If the package itself is frozen the type will
1202 -- have been frozen as well.
1204 if not Scope_Within_Or_Same
(Current_Scope
, Scope
(E
)) then
1205 if Is_Type
(E
) and then From_Nested_Package
(E
) then
1207 Pack
: constant Entity_Id
:= Scope
(E
);
1211 Install_Visible_Declarations
(Pack
);
1212 Install_Private_Declarations
(Pack
);
1213 Analyze_Aspects_At_Freeze_Point
(E
);
1215 if Is_Private_Type
(E
)
1216 and then Present
(Full_View
(E
))
1218 Analyze_Aspects_At_Freeze_Point
(Full_View
(E
));
1221 End_Package_Scope
(Pack
);
1225 -- Aspects from other entities in different contexts are analyzed
1233 -- Look for aspect specification entries for this entity
1235 ASN
:= First_Rep_Item
(E
);
1236 while Present
(ASN
) loop
1237 if Nkind
(ASN
) = N_Aspect_Specification
then
1238 exit when Entity
(ASN
) /= E
;
1240 if Is_Delayed_Aspect
(ASN
) then
1241 A_Id
:= Get_Aspect_Id
(ASN
);
1245 -- For aspects whose expression is an optional Boolean, make
1246 -- the corresponding pragma at the freeze point.
1248 when Boolean_Aspects
1249 | Library_Unit_Aspects
1251 -- Aspects Export and Import require special handling.
1252 -- Both are by definition Boolean and may benefit from
1253 -- forward references, however their expressions are
1254 -- treated as static. In addition, the syntax of their
1255 -- corresponding pragmas requires extra "pieces" which
1256 -- may also contain forward references. To account for
1257 -- all of this, the corresponding pragma is created by
1258 -- Analyze_Aspect_Export_Import, but is not analyzed as
1259 -- the complete analysis must happen now.
1261 -- Aspect Full_Access_Only must be analyzed last so that
1262 -- aspects Volatile and Atomic, if any, are analyzed.
1264 -- Skip creation of pragma Preelaborable_Initialization
1265 -- in the case where the aspect has an expression,
1266 -- because the pragma is only needed for setting flag
1267 -- Known_To_Have_Preelab_Init, which is set by other
1268 -- means following resolution of the aspect expression.
1270 if A_Id
not in Aspect_Export
1271 | Aspect_Full_Access_Only
1273 and then (A_Id
/= Aspect_Preelaborable_Initialization
1274 or else not Present
(Expression
(ASN
)))
1276 Make_Pragma_From_Boolean_Aspect
(ASN
);
1279 -- Special handling for aspects that don't correspond to
1280 -- pragmas/attributes.
1282 when Aspect_Default_Value
1283 | Aspect_Default_Component_Value
1285 -- Do not inherit aspect for anonymous base type of a
1286 -- scalar or array type, because they apply to the first
1287 -- subtype of the type, and will be processed when that
1288 -- first subtype is frozen.
1290 if Is_Derived_Type
(E
)
1291 and then not Comes_From_Source
(E
)
1292 and then E
/= First_Subtype
(E
)
1296 Analyze_Aspect_Default_Value
(ASN
);
1299 -- Ditto for iterator aspects, because the corresponding
1300 -- attributes may not have been analyzed yet.
1302 when Aspect_Constant_Indexing
1303 | Aspect_Default_Iterator
1304 | Aspect_Iterator_Element
1305 | Aspect_Variable_Indexing
1307 Analyze
(Expression
(ASN
));
1309 if Etype
(Expression
(ASN
)) = Any_Type
then
1311 ("\aspect must be fully defined before & is frozen",
1315 when Aspect_Integer_Literal
1316 | Aspect_Real_Literal
1317 | Aspect_String_Literal
1319 Validate_Literal_Aspect
(E
, ASN
);
1321 when Aspect_Iterable
=>
1322 Validate_Iterable_Aspect
(E
, ASN
);
1324 when Aspect_Designated_Storage_Model
=>
1325 Analyze_And_Resolve
(Expression
(ASN
));
1327 if not Is_Entity_Name
(Expression
(ASN
))
1328 or else not Is_Object
(Entity
(Expression
(ASN
)))
1330 not Present
(Find_Aspect
(Etype
(Expression
(ASN
)),
1331 Aspect_Storage_Model_Type
))
1334 ("must specify name of stand-alone object of type "
1335 & "with aspect Storage_Model_Type",
1338 -- Set access type's Associated_Storage_Pool to denote
1339 -- the Storage_Model_Type object given for the aspect
1340 -- (even though that isn't actually an Ada storage pool).
1343 Set_Associated_Storage_Pool
1344 (E
, Entity
(Expression
(ASN
)));
1347 when Aspect_Storage_Model_Type
=>
1348 Validate_Storage_Model_Type_Aspect
(E
, ASN
);
1350 when Aspect_Aggregate
=>
1357 Ritem
:= Aspect_Rep_Item
(ASN
);
1359 if Present
(Ritem
) then
1365 Next_Rep_Item
(ASN
);
1368 -- Make a second pass for a Full_Access_Only entry
1370 ASN
:= First_Rep_Item
(E
);
1371 while Present
(ASN
) loop
1372 if Nkind
(ASN
) = N_Aspect_Specification
then
1373 exit when Entity
(ASN
) /= E
;
1375 if Get_Aspect_Id
(ASN
) = Aspect_Full_Access_Only
then
1376 Make_Pragma_From_Boolean_Aspect
(ASN
);
1377 Ritem
:= Aspect_Rep_Item
(ASN
);
1378 if Present
(Ritem
) then
1384 Next_Rep_Item
(ASN
);
1388 and then E
/= Base_Type
(E
)
1389 and then Is_First_Subtype
(E
)
1391 Inherit_Rep_Item_Chain
(Base_Type
(E
), E
);
1393 end Analyze_Aspects_At_Freeze_Point
;
1395 -----------------------------------
1396 -- Analyze_Aspect_Specifications --
1397 -----------------------------------
1399 procedure Analyze_Aspect_Specifications
(N
: Node_Id
; E
: Entity_Id
) is
1400 pragma Assert
(Present
(E
));
1402 procedure Decorate
(Asp
: Node_Id
; Prag
: Node_Id
);
1403 -- Establish linkages between an aspect and its corresponding pragma
1405 procedure Insert_Pragma
1407 Is_Instance
: Boolean := False);
1408 -- Subsidiary to the analysis of aspects
1415 -- Initial_Condition
1423 -- Subprogram_Variant
1425 -- Insert pragma Prag such that it mimics the placement of a source
1426 -- pragma of the same kind. Flag Is_Generic should be set when the
1427 -- context denotes a generic instance.
1429 function Relocate_Expression
(Source
: Node_Id
) return Node_Id
;
1430 -- Outside of a generic this function is equivalent to Relocate_Node.
1431 -- Inside a generic it is an identity function, because Relocate_Node
1432 -- would create a new node that is not associated with the generic
1433 -- template. This association is needed to save references to entities
1434 -- that are global to the generic (and might be not visible from where
1435 -- the generic is instantiated).
1437 -- Inside a generic the original tree is shared between aspect and
1438 -- a corresponding pragma (or an attribute definition clause). This
1439 -- parallels what is done in sem_prag.adb (see Get_Argument).
1445 procedure Decorate
(Asp
: Node_Id
; Prag
: Node_Id
) is
1447 Set_Aspect_Rep_Item
(Asp
, Prag
);
1448 Set_Corresponding_Aspect
(Prag
, Asp
);
1449 Set_From_Aspect_Specification
(Prag
);
1450 Set_Parent
(Prag
, Asp
);
1457 procedure Insert_Pragma
1459 Is_Instance
: Boolean := False)
1465 Inserted
: Boolean := False;
1468 -- When the aspect appears on an entry, package, protected unit,
1469 -- subprogram, or task unit body, insert the generated pragma at the
1470 -- top of the body declarations to emulate the behavior of a source
1473 -- package body Pack with Aspect is
1475 -- package body Pack is
1478 if Nkind
(N
) in N_Entry_Body
1484 Decls
:= Declarations
(N
);
1488 Set_Declarations
(N
, Decls
);
1491 Prepend_To
(Decls
, Prag
);
1493 -- When the aspect is associated with a [generic] package declaration
1494 -- insert the generated pragma at the top of the visible declarations
1495 -- to emulate the behavior of a source pragma.
1497 -- package Pack with Aspect is
1502 elsif Nkind
(N
) in N_Generic_Package_Declaration
1503 | N_Package_Declaration
1505 Decls
:= Visible_Declarations
(Specification
(N
));
1509 Set_Visible_Declarations
(Specification
(N
), Decls
);
1512 -- The visible declarations of a generic instance have the
1513 -- following structure:
1515 -- <renamings of generic formals>
1516 -- <renamings of internally-generated spec and body>
1517 -- <first source declaration>
1519 -- Insert the pragma before the first source declaration by
1520 -- skipping the instance "header" to ensure proper visibility of
1524 Decl
:= First
(Decls
);
1525 while Present
(Decl
) loop
1526 if Comes_From_Source
(Decl
) then
1527 Insert_Before
(Decl
, Prag
);
1535 -- The pragma is placed after the instance "header"
1537 if not Inserted
then
1538 Append_To
(Decls
, Prag
);
1541 -- Otherwise this is not a generic instance
1544 Prepend_To
(Decls
, Prag
);
1547 -- When the aspect is associated with a protected unit declaration,
1548 -- insert the generated pragma at the top of the visible declarations
1549 -- the emulate the behavior of a source pragma.
1551 -- protected [type] Prot with Aspect is
1553 -- protected [type] Prot is
1556 elsif Nkind
(N
) = N_Protected_Type_Declaration
then
1557 Def
:= Protected_Definition
(N
);
1561 Make_Protected_Definition
(Sloc
(N
),
1562 Visible_Declarations
=> New_List
,
1563 End_Label
=> Empty
);
1565 Set_Protected_Definition
(N
, Def
);
1568 Decls
:= Visible_Declarations
(Def
);
1572 Set_Visible_Declarations
(Def
, Decls
);
1575 Prepend_To
(Decls
, Prag
);
1577 -- When the aspect is associated with a task unit declaration, insert
1578 -- insert the generated pragma at the top of the visible declarations
1579 -- the emulate the behavior of a source pragma.
1581 -- task [type] Prot with Aspect is
1583 -- task [type] Prot is
1586 elsif Nkind
(N
) = N_Task_Type_Declaration
then
1587 Def
:= Task_Definition
(N
);
1591 Make_Task_Definition
(Sloc
(N
),
1592 Visible_Declarations
=> New_List
,
1593 End_Label
=> Empty
);
1595 Set_Task_Definition
(N
, Def
);
1598 Decls
:= Visible_Declarations
(Def
);
1602 Set_Visible_Declarations
(Def
, Decls
);
1605 Prepend_To
(Decls
, Prag
);
1607 -- When the context is a library unit, the pragma is added to the
1608 -- Pragmas_After list.
1610 elsif Nkind
(Parent
(N
)) = N_Compilation_Unit
then
1611 Aux
:= Aux_Decls_Node
(Parent
(N
));
1613 if No
(Pragmas_After
(Aux
)) then
1614 Set_Pragmas_After
(Aux
, New_List
);
1617 Prepend
(Prag
, Pragmas_After
(Aux
));
1619 -- Default, the pragma is inserted after the context
1622 Insert_After
(N
, Prag
);
1626 -------------------------
1627 -- Relocate_Expression --
1628 -------------------------
1630 function Relocate_Expression
(Source
: Node_Id
) return Node_Id
is
1632 if Inside_A_Generic
then
1635 return Atree
.Relocate_Node
(Source
);
1637 end Relocate_Expression
;
1642 Aitem
: Node_Id
:= Empty
;
1645 L
: constant List_Id
:= Aspect_Specifications
(N
);
1646 pragma Assert
(Present
(L
));
1648 Ins_Node
: Node_Id
:= N
;
1649 -- Insert pragmas/attribute definition clause after this node when no
1650 -- delayed analysis is required.
1652 -- Start of processing for Analyze_Aspect_Specifications
1655 -- The general processing involves building an attribute definition
1656 -- clause or a pragma node that corresponds to the aspect. Then in order
1657 -- to delay the evaluation of this aspect to the freeze point, we attach
1658 -- the corresponding pragma/attribute definition clause to the aspect
1659 -- specification node, which is then placed in the Rep Item chain. In
1660 -- this case we mark the entity by setting the flag Has_Delayed_Aspects
1661 -- and we evaluate the rep item at the freeze point. When the aspect
1662 -- doesn't have a corresponding pragma/attribute definition clause, then
1663 -- its analysis is simply delayed at the freeze point.
1665 -- Some special cases don't require delay analysis, thus the aspect is
1666 -- analyzed right now.
1668 -- Note that there is a special handling for Pre, Post, Test_Case,
1669 -- Contract_Cases and Subprogram_Variant aspects. In these cases, we do
1670 -- not have to worry about delay issues, since the pragmas themselves
1671 -- deal with delay of visibility for the expression analysis. Thus, we
1672 -- just insert the pragma after the node N.
1674 -- Loop through aspects
1676 Aspect
:= First
(L
);
1677 Aspect_Loop
: while Present
(Aspect
) loop
1678 Analyze_One_Aspect
: declare
1680 Aspect_Exit
: exception;
1681 -- This exception is used to exit aspect processing completely. It
1682 -- is used when an error is detected, and no further processing is
1683 -- required. It is also used if an earlier error has left the tree
1684 -- in a state where the aspect should not be processed.
1686 Expr
: constant Node_Id
:= Expression
(Aspect
);
1687 Id
: constant Node_Id
:= Identifier
(Aspect
);
1688 Loc
: constant Source_Ptr
:= Sloc
(Aspect
);
1689 Nam
: constant Name_Id
:= Chars
(Id
);
1690 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Nam
);
1693 Delay_Required
: Boolean;
1694 -- Set False if delay is not required
1696 Eloc
: Source_Ptr
:= No_Location
;
1697 -- Source location of expression, modified when we split PPC's. It
1698 -- is set below when Expr is present.
1700 procedure Analyze_Aspect_Convention
;
1701 -- Perform analysis of aspect Convention
1703 procedure Analyze_Aspect_Disable_Controlled
;
1704 -- Perform analysis of aspect Disable_Controlled
1706 procedure Analyze_Aspect_Export_Import
;
1707 -- Perform analysis of aspects Export or Import
1709 procedure Analyze_Aspect_External_Link_Name
;
1710 -- Perform analysis of aspects External_Name or Link_Name
1712 procedure Analyze_Aspect_Implicit_Dereference
;
1713 -- Perform analysis of the Implicit_Dereference aspects
1715 procedure Analyze_Aspect_Relaxed_Initialization
;
1716 -- Perform analysis of aspect Relaxed_Initialization
1718 procedure Analyze_Aspect_Yield
;
1719 -- Perform analysis of aspect Yield
1721 procedure Analyze_Aspect_Static
;
1722 -- Ada 2022 (AI12-0075): Perform analysis of aspect Static
1724 procedure Check_Expr_Is_OK_Static_Expression
1726 Typ
: Entity_Id
:= Empty
);
1727 -- Check the specified expression Expr to make sure that it is a
1728 -- static expression of the given type (i.e. it will be analyzed
1729 -- and resolved using this type, which can be any valid argument
1730 -- to Resolve, e.g. Any_Integer is OK). If not, give an error
1731 -- and raise Aspect_Exit. If Typ is left Empty, then any static
1732 -- expression is allowed. Includes checking that the expression
1733 -- does not raise Constraint_Error.
1735 function Directly_Specified
1736 (Id
: Entity_Id
; A
: Aspect_Id
) return Boolean;
1737 -- Returns True if the given aspect is directly (as opposed to
1738 -- via any form of inheritance) specified for the given entity.
1740 function Make_Aitem_Pragma
1741 (Pragma_Argument_Associations
: List_Id
;
1742 Pragma_Name
: Name_Id
) return Node_Id
;
1743 -- This is a wrapper for Make_Pragma used for converting aspects
1744 -- to pragmas. It takes care of Sloc (set from Loc) and building
1745 -- the pragma identifier from the given name. In addition the
1746 -- flags Class_Present and Split_PPC are set from the aspect
1747 -- node, as well as Is_Ignored. This routine also sets the
1748 -- From_Aspect_Specification in the resulting pragma node to
1749 -- True, and sets Corresponding_Aspect to point to the aspect.
1750 -- The resulting pragma is assigned to Aitem.
1752 -------------------------------
1753 -- Analyze_Aspect_Convention --
1754 -------------------------------
1756 procedure Analyze_Aspect_Convention
is
1765 -- Obtain all interfacing aspects that apply to the related
1768 Get_Interfacing_Aspects
1769 (Iface_Asp
=> Aspect
,
1770 Conv_Asp
=> Dummy_1
,
1777 -- The related entity is subject to aspect Export or Import.
1778 -- Do not process Convention now because it must be analysed
1779 -- as part of Export or Import.
1781 if Present
(Expo
) or else Present
(Imp
) then
1784 -- Otherwise Convention appears by itself
1787 -- The aspect specifies a particular convention
1789 if Present
(Expr
) then
1790 Conv
:= New_Copy_Tree
(Expr
);
1792 -- Otherwise assume convention Ada
1795 Conv
:= Make_Identifier
(Loc
, Name_Ada
);
1799 -- pragma Convention (<Conv>, <E>);
1801 Aitem
:= Make_Aitem_Pragma
1802 (Pragma_Name
=> Name_Convention
,
1803 Pragma_Argument_Associations
=> New_List
(
1804 Make_Pragma_Argument_Association
(Loc
,
1805 Expression
=> Conv
),
1806 Make_Pragma_Argument_Association
(Loc
,
1807 Expression
=> New_Occurrence_Of
(E
, Loc
))));
1809 Decorate
(Aspect
, Aitem
);
1810 Insert_Pragma
(Aitem
);
1812 end Analyze_Aspect_Convention
;
1814 ---------------------------------------
1815 -- Analyze_Aspect_Disable_Controlled --
1816 ---------------------------------------
1818 procedure Analyze_Aspect_Disable_Controlled
is
1820 -- The aspect applies only to controlled records
1822 if not (Ekind
(E
) = E_Record_Type
1823 and then Is_Controlled_Active
(E
))
1826 ("aspect % requires controlled record type", Aspect
);
1830 -- Preanalyze the expression (if any) when the aspect resides
1831 -- in a generic unit.
1833 if Inside_A_Generic
then
1834 if Present
(Expr
) then
1835 Preanalyze_And_Resolve
(Expr
, Any_Boolean
);
1838 -- Otherwise the aspect resides in a nongeneric context
1841 -- A controlled record type loses its controlled semantics
1842 -- when the expression statically evaluates to True.
1844 if Present
(Expr
) then
1845 Analyze_And_Resolve
(Expr
, Any_Boolean
);
1847 if Is_OK_Static_Expression
(Expr
) then
1848 if Is_True
(Static_Boolean
(Expr
)) then
1849 Set_Disable_Controlled
(E
);
1852 -- Otherwise the expression is not static
1856 ("expression of aspect % must be static", Aspect
);
1859 -- Otherwise the aspect appears without an expression and
1860 -- defaults to True.
1863 Set_Disable_Controlled
(E
);
1866 end Analyze_Aspect_Disable_Controlled
;
1868 ----------------------------------
1869 -- Analyze_Aspect_Export_Import --
1870 ----------------------------------
1872 procedure Analyze_Aspect_Export_Import
is
1880 -- Obtain all interfacing aspects that apply to the related
1883 Get_Interfacing_Aspects
1884 (Iface_Asp
=> Aspect
,
1885 Conv_Asp
=> Dummy_1
,
1892 -- The related entity cannot be subject to both aspects Export
1895 if Present
(Expo
) and then Present
(Imp
) then
1897 ("incompatible interfacing aspects given for &", E
);
1898 Error_Msg_Sloc
:= Sloc
(Expo
);
1899 Error_Msg_N
("\aspect Export #", E
);
1900 Error_Msg_Sloc
:= Sloc
(Imp
);
1901 Error_Msg_N
("\aspect Import #", E
);
1904 -- A variable is most likely modified from the outside. Take
1905 -- the optimistic approach to avoid spurious errors.
1907 if Ekind
(E
) = E_Variable
then
1908 Set_Never_Set_In_Source
(E
, False);
1911 -- Resolve the expression of an Import or Export here, and
1912 -- require it to be of type Boolean and static. This is not
1913 -- quite right, because in general this should be delayed,
1914 -- but that seems tricky for these, because normally Boolean
1915 -- aspects are replaced with pragmas at the freeze point in
1916 -- Make_Pragma_From_Boolean_Aspect.
1918 if not Present
(Expr
)
1919 or else Is_True
(Static_Boolean
(Expr
))
1921 if A_Id
= Aspect_Import
then
1922 Set_Has_Completion
(E
);
1923 Set_Is_Imported
(E
);
1925 -- An imported object cannot be explicitly initialized
1927 if Nkind
(N
) = N_Object_Declaration
1928 and then Present
(Expression
(N
))
1931 ("imported entities cannot be initialized "
1932 & "(RM B.1(24))", Expression
(N
));
1936 pragma Assert
(A_Id
= Aspect_Export
);
1937 Set_Is_Exported
(E
);
1940 -- Create the proper form of pragma Export or Import taking
1941 -- into account Conversion, External_Name, and Link_Name.
1943 Aitem
:= Build_Export_Import_Pragma
(Aspect
, E
);
1945 -- Otherwise the expression is either False or erroneous. There
1946 -- is no corresponding pragma.
1951 end Analyze_Aspect_Export_Import
;
1953 ---------------------------------------
1954 -- Analyze_Aspect_External_Link_Name --
1955 ---------------------------------------
1957 procedure Analyze_Aspect_External_Link_Name
is
1965 -- Obtain all interfacing aspects that apply to the related
1968 Get_Interfacing_Aspects
1969 (Iface_Asp
=> Aspect
,
1970 Conv_Asp
=> Dummy_1
,
1977 -- Ensure that aspect External_Name applies to aspect Export or
1980 if A_Id
= Aspect_External_Name
then
1981 if No
(Expo
) and then No
(Imp
) then
1983 ("aspect External_Name requires aspect Import or "
1984 & "Export", Aspect
);
1987 -- Otherwise ensure that aspect Link_Name applies to aspect
1988 -- Export or Import.
1991 pragma Assert
(A_Id
= Aspect_Link_Name
);
1992 if No
(Expo
) and then No
(Imp
) then
1994 ("aspect Link_Name requires aspect Import or Export",
1998 end Analyze_Aspect_External_Link_Name
;
2000 -----------------------------------------
2001 -- Analyze_Aspect_Implicit_Dereference --
2002 -----------------------------------------
2004 procedure Analyze_Aspect_Implicit_Dereference
is
2006 if not Is_Type
(E
) or else not Has_Discriminants
(E
) then
2008 ("aspect must apply to a type with discriminants", Expr
);
2010 elsif not Is_Entity_Name
(Expr
) then
2012 ("aspect must name a discriminant of current type", Expr
);
2015 -- Discriminant type be an anonymous access type or an
2016 -- anonymous access to subprogram.
2018 -- Missing synchronized types???
2021 Disc
: Entity_Id
:= First_Discriminant
(E
);
2023 while Present
(Disc
) loop
2024 if Chars
(Expr
) = Chars
(Disc
)
2025 and then Ekind
(Etype
(Disc
)) in
2026 E_Anonymous_Access_Subprogram_Type |
2027 E_Anonymous_Access_Type
2029 Set_Has_Implicit_Dereference
(E
);
2030 Set_Has_Implicit_Dereference
(Disc
);
2034 Next_Discriminant
(Disc
);
2037 -- Error if no proper access discriminant
2039 if Present
(Disc
) then
2040 -- For a type extension, check whether parent has
2041 -- a reference discriminant, to verify that use is
2044 if Is_Derived_Type
(E
)
2045 and then Has_Discriminants
(Etype
(E
))
2048 Parent_Disc
: constant Entity_Id
:=
2049 Get_Reference_Discriminant
(Etype
(E
));
2051 if Present
(Parent_Disc
)
2052 and then Corresponding_Discriminant
(Disc
) /=
2056 ("reference discriminant does not match "
2057 & "discriminant of parent type", Expr
);
2064 ("not an access discriminant of&", Expr
, E
);
2069 end Analyze_Aspect_Implicit_Dereference
;
2071 -------------------------------------------
2072 -- Analyze_Aspect_Relaxed_Initialization --
2073 -------------------------------------------
2075 procedure Analyze_Aspect_Relaxed_Initialization
is
2076 procedure Analyze_Relaxed_Parameter
2077 (Subp_Id
: Entity_Id
;
2079 Seen
: in out Elist_Id
);
2080 -- Analyze parameter that appears in the expression of the
2081 -- aspect Relaxed_Initialization.
2083 -------------------------------
2084 -- Analyze_Relaxed_Parameter --
2085 -------------------------------
2087 procedure Analyze_Relaxed_Parameter
2088 (Subp_Id
: Entity_Id
;
2090 Seen
: in out Elist_Id
)
2093 -- Set name of the aspect for error messages
2094 Error_Msg_Name_1
:= Nam
;
2096 -- The relaxed parameter is a formal parameter
2098 if Nkind
(Param
) in N_Identifier | N_Expanded_Name
then
2102 Item
: constant Entity_Id
:= Entity
(Param
);
2104 -- It must be a formal of the analyzed subprogram
2106 if Scope
(Item
) = Subp_Id
then
2108 pragma Assert
(Is_Formal
(Item
));
2110 -- It must not have scalar or access type
2112 if Is_Elementary_Type
(Etype
(Item
)) then
2113 Error_Msg_N
("illegal aspect % item", Param
);
2115 ("\item must not have elementary type", Param
);
2118 -- Detect duplicated items
2120 if Contains
(Seen
, Item
) then
2121 Error_Msg_N
("duplicate aspect % item", Param
);
2123 Append_New_Elmt
(Item
, Seen
);
2126 Error_Msg_N
("illegal aspect % item", Param
);
2130 -- The relaxed parameter is the function's Result attribute
2132 elsif Is_Attribute_Result
(Param
) then
2136 Pref
: constant Node_Id
:= Prefix
(Param
);
2140 Nkind
(Pref
) in N_Identifier | N_Expanded_Name
2142 Entity
(Pref
) = Subp_Id
2144 -- Function result must not have scalar or access
2147 if Is_Elementary_Type
(Etype
(Pref
)) then
2148 Error_Msg_N
("illegal aspect % item", Param
);
2150 ("\function result must not have elementary"
2154 -- Detect duplicated items
2156 if Contains
(Seen
, Subp_Id
) then
2157 Error_Msg_N
("duplicate aspect % item", Param
);
2159 Append_New_Elmt
(Entity
(Pref
), Seen
);
2163 Error_Msg_N
("illegal aspect % item", Param
);
2167 Error_Msg_N
("illegal aspect % item", Param
);
2169 end Analyze_Relaxed_Parameter
;
2173 Seen
: Elist_Id
:= No_Elist
;
2174 -- Items that appear in the relaxed initialization aspect
2175 -- expression of a subprogram; for detecting duplicates.
2177 Restore_Scope
: Boolean;
2178 -- Will be set to True if we need to restore the scope table
2179 -- after analyzing the aspect expression.
2181 Prev_Id
: Entity_Id
;
2183 -- Start of processing for Analyze_Aspect_Relaxed_Initialization
2186 -- Set name of the aspect for error messages
2187 Error_Msg_Name_1
:= Nam
;
2189 -- Annotation of a type; no aspect expression is allowed.
2190 -- For a private type, the aspect must be attached to the
2193 -- ??? Once the exact rule for this aspect is ready, we will
2194 -- likely reject concurrent types, etc., so let's keep the code
2195 -- for types and variable separate.
2197 if Is_First_Subtype
(E
) then
2198 Prev_Id
:= Incomplete_Or_Partial_View
(E
);
2199 if Present
(Prev_Id
) then
2201 -- Aspect may appear on the full view of an incomplete
2202 -- type because the incomplete declaration cannot have
2205 if Ekind
(Prev_Id
) = E_Incomplete_Type
then
2208 Error_Msg_N
("aspect % must apply to partial view", N
);
2211 elsif Present
(Expr
) then
2212 Error_Msg_N
("illegal aspect % expression", Expr
);
2215 -- Annotation of a variable; no aspect expression is allowed
2217 elsif Ekind
(E
) = E_Variable
then
2218 if Present
(Expr
) then
2219 Error_Msg_N
("illegal aspect % expression", Expr
);
2222 -- Annotation of a constant; no aspect expression is allowed.
2223 -- For a deferred constant, the aspect must be attached to the
2226 elsif Ekind
(E
) = E_Constant
then
2227 if Present
(Incomplete_Or_Partial_View
(E
)) then
2229 ("aspect % must apply to deferred constant", N
);
2231 elsif Present
(Expr
) then
2232 Error_Msg_N
("illegal aspect % expression", Expr
);
2235 -- Annotation of a subprogram; aspect expression is required
2237 elsif Is_Subprogram_Or_Entry
(E
)
2238 or else Is_Generic_Subprogram
(E
)
2240 if Present
(Expr
) then
2242 -- If we analyze subprogram body that acts as its own
2243 -- spec, then the subprogram itself and its formals are
2244 -- already installed; otherwise, we need to install them,
2245 -- as they must be visible when analyzing the aspect
2248 if In_Open_Scopes
(E
) then
2249 Restore_Scope
:= False;
2251 Restore_Scope
:= True;
2254 -- Only formals of the subprogram itself can appear
2255 -- in Relaxed_Initialization aspect expression, not
2256 -- formals of the enclosing generic unit. (This is
2257 -- different than in Precondition or Depends aspects,
2258 -- where both kinds of formals are allowed.)
2260 Install_Formals
(E
);
2263 -- Aspect expression is either an aggregate with list of
2264 -- parameters (and possibly the Result attribute for a
2267 if Nkind
(Expr
) = N_Aggregate
then
2269 -- Component associations in the aggregate must be a
2270 -- parameter name followed by a static boolean
2273 if Present
(Component_Associations
(Expr
)) then
2276 First
(Component_Associations
(Expr
));
2278 while Present
(Assoc
) loop
2279 if List_Length
(Choices
(Assoc
)) = 1 then
2280 Analyze_Relaxed_Parameter
2281 (E
, First
(Choices
(Assoc
)), Seen
);
2283 if Inside_A_Generic
then
2284 Preanalyze_And_Resolve
2285 (Expression
(Assoc
), Any_Boolean
);
2288 (Expression
(Assoc
), Any_Boolean
);
2291 if not Is_OK_Static_Expression
2292 (Expression
(Assoc
))
2294 Error_Msg_Name_1
:= Nam
;
2296 ("expression of aspect %" &
2297 "must be static", Aspect
);
2301 Error_Msg_Name_1
:= Nam
;
2303 ("illegal aspect % expression", Expr
);
2310 -- Expressions of the aggregate are parameter names
2312 if Present
(Expressions
(Expr
)) then
2314 Param
: Node_Id
:= First
(Expressions
(Expr
));
2317 while Present
(Param
) loop
2318 Analyze_Relaxed_Parameter
(E
, Param
, Seen
);
2324 -- Mark the aggregate expression itself as analyzed;
2325 -- its subexpressions were marked when they themselves
2328 Set_Analyzed
(Expr
);
2330 -- Otherwise, it is a single name of a subprogram
2331 -- parameter (or possibly the Result attribute for
2335 Analyze_Relaxed_Parameter
(E
, Expr
, Seen
);
2338 if Restore_Scope
then
2342 Error_Msg_N
("missing expression for aspect %", N
);
2346 Error_Msg_N
("inappropriate entity for aspect %", E
);
2348 end Analyze_Aspect_Relaxed_Initialization
;
2350 ---------------------------
2351 -- Analyze_Aspect_Static --
2352 ---------------------------
2354 procedure Analyze_Aspect_Static
is
2355 function Has_Convention_Intrinsic
(L
: List_Id
) return Boolean;
2356 -- Return True if L contains a pragma argument association
2357 -- node representing a convention Intrinsic.
2359 ------------------------------
2360 -- Has_Convention_Intrinsic --
2361 ------------------------------
2363 function Has_Convention_Intrinsic
2364 (L
: List_Id
) return Boolean
2366 Arg
: Node_Id
:= First
(L
);
2368 while Present
(Arg
) loop
2369 if Nkind
(Arg
) = N_Pragma_Argument_Association
2370 and then Chars
(Arg
) = Name_Convention
2371 and then Chars
(Expression
(Arg
)) = Name_Intrinsic
2380 end Has_Convention_Intrinsic
;
2382 Is_Imported_Intrinsic
: Boolean;
2385 if Ada_Version
< Ada_2022
then
2386 Error_Msg_Ada_2022_Feature
("aspect %", Sloc
(Aspect
));
2390 Is_Imported_Intrinsic
:= Is_Imported
(E
)
2392 Has_Convention_Intrinsic
2393 (Pragma_Argument_Associations
(Import_Pragma
(E
)));
2395 -- The aspect applies only to expression functions that
2396 -- statisfy the requirements for a static expression function
2397 -- (such as having an expression that is predicate-static) as
2398 -- well as Intrinsic imported functions as a -gnatX extension.
2400 if not Is_Expression_Function
(E
)
2402 not (Extensions_Allowed
and then Is_Imported_Intrinsic
)
2404 if Extensions_Allowed
then
2406 ("aspect % requires intrinsic or expression function",
2409 elsif Is_Imported_Intrinsic
then
2410 Error_Msg_GNAT_Extension
2411 ("aspect % on intrinsic function", Sloc
(Aspect
));
2415 ("aspect % requires expression function", Aspect
);
2420 -- Ada 2022 (AI12-0075): Check that the function satisfies
2421 -- several requirements of static functions as specified in
2422 -- RM 6.8(5.1-5.8). Note that some of the requirements given
2423 -- there are checked elsewhere.
2426 -- The expression of the expression function must be a
2427 -- potentially static expression (RM 2022 6.8(3.2-3.4)).
2428 -- That's checked in Sem_Ch6.Analyze_Expression_Function.
2430 -- The function must not contain any calls to itself, which
2431 -- is checked in Sem_Res.Resolve_Call.
2433 -- Each formal must be of mode in and have a static subtype
2436 Formal
: Entity_Id
:= First_Formal
(E
);
2438 while Present
(Formal
) loop
2439 if Ekind
(Formal
) /= E_In_Parameter
then
2441 ("aspect % requires formals of mode IN",
2447 if not Is_Static_Subtype
(Etype
(Formal
)) then
2449 ("aspect % requires formals with static subtypes",
2455 Next_Formal
(Formal
);
2459 -- The function's result subtype must be a static subtype
2461 if not Is_Static_Subtype
(Etype
(E
)) then
2463 ("aspect % requires function with result of "
2464 & "a static subtype",
2470 -- Check that the function does not have any applicable
2471 -- precondition or postcondition expression.
2473 for Asp
in Pre_Post_Aspects
loop
2474 if Has_Aspect
(E
, Asp
) then
2475 Error_Msg_Name_1
:= Aspect_Names
(Asp
);
2477 ("aspect % is not allowed for a static "
2478 & "expression function",
2479 Find_Aspect
(E
, Asp
));
2485 -- ??? Must check that "for result type R, if the
2486 -- function is a boundary entity for type R (see 7.3.2),
2487 -- no type invariant applies to type R; if R has a
2488 -- component type C, a similar rule applies to C."
2491 -- When the expression is present, it must be static. If it
2492 -- evaluates to True, the expression function is treated as
2493 -- a static function. Otherwise the aspect appears without
2494 -- an expression and defaults to True.
2496 if Present
(Expr
) then
2497 -- Preanalyze the expression when the aspect resides in a
2498 -- generic unit. (Is this generic-related code necessary
2499 -- for this aspect? It's modeled on what's done for aspect
2500 -- Disable_Controlled. ???)
2502 if Inside_A_Generic
then
2503 Preanalyze_And_Resolve
(Expr
, Any_Boolean
);
2505 -- Otherwise the aspect resides in a nongeneric context
2508 Analyze_And_Resolve
(Expr
, Any_Boolean
);
2510 -- Error if the boolean expression is not static
2512 if not Is_OK_Static_Expression
(Expr
) then
2514 ("expression of aspect % must be static", Aspect
);
2518 end Analyze_Aspect_Static
;
2520 --------------------------
2521 -- Analyze_Aspect_Yield --
2522 --------------------------
2524 procedure Analyze_Aspect_Yield
is
2525 Expr_Value
: Boolean := False;
2528 -- Check valid entity for 'Yield
2530 if (Is_Subprogram
(E
)
2531 or else Is_Generic_Subprogram
(E
)
2532 or else Is_Entry
(E
))
2533 and then not Within_Protected_Type
(E
)
2537 elsif Within_Protected_Type
(E
) then
2539 ("aspect% not applicable to protected operation", Id
);
2544 ("aspect% only applicable to subprogram and entry "
2545 & "declarations", Id
);
2549 -- Evaluate its static expression (if available); otherwise it
2550 -- defaults to True.
2555 -- Otherwise it must have a static boolean expression
2558 if Inside_A_Generic
then
2559 Preanalyze_And_Resolve
(Expr
, Any_Boolean
);
2561 Analyze_And_Resolve
(Expr
, Any_Boolean
);
2564 if Is_OK_Static_Expression
(Expr
) then
2565 if Is_True
(Static_Boolean
(Expr
)) then
2570 ("expression of aspect % must be static", Aspect
);
2575 Set_Has_Yield_Aspect
(E
);
2578 -- If the Yield aspect is specified for a dispatching
2579 -- subprogram that inherits the aspect, the specified
2580 -- value shall be confirming.
2583 and then Is_Dispatching_Operation
(E
)
2584 and then Present
(Overridden_Operation
(E
))
2585 and then Has_Yield_Aspect
(Overridden_Operation
(E
))
2586 /= Is_True
(Static_Boolean
(Expr
))
2588 Error_Msg_N
("specification of inherited aspect% can only " &
2589 "confirm parent value", Id
);
2591 end Analyze_Aspect_Yield
;
2593 ----------------------------------------
2594 -- Check_Expr_Is_OK_Static_Expression --
2595 ----------------------------------------
2597 procedure Check_Expr_Is_OK_Static_Expression
2599 Typ
: Entity_Id
:= Empty
)
2602 if Present
(Typ
) then
2603 Analyze_And_Resolve
(Expr
, Typ
);
2605 Analyze_And_Resolve
(Expr
);
2608 -- An expression cannot be considered static if its resolution
2609 -- failed or if it's erroneous. Stop the analysis of the
2612 if Etype
(Expr
) = Any_Type
or else Error_Posted
(Expr
) then
2615 elsif Is_OK_Static_Expression
(Expr
) then
2618 -- Finally, we have a real error
2621 Error_Msg_Name_1
:= Nam
;
2622 Flag_Non_Static_Expr
2623 ("entity for aspect% must be a static expression",
2627 end Check_Expr_Is_OK_Static_Expression
;
2629 ------------------------
2630 -- Directly_Specified --
2631 ------------------------
2633 function Directly_Specified
2634 (Id
: Entity_Id
; A
: Aspect_Id
) return Boolean
2636 Aspect_Spec
: constant Node_Id
:= Find_Aspect
(Id
, A
);
2638 return Present
(Aspect_Spec
) and then Entity
(Aspect_Spec
) = Id
;
2639 end Directly_Specified
;
2641 -----------------------
2642 -- Make_Aitem_Pragma --
2643 -----------------------
2645 function Make_Aitem_Pragma
2646 (Pragma_Argument_Associations
: List_Id
;
2647 Pragma_Name
: Name_Id
) return Node_Id
2649 Args
: List_Id
:= Pragma_Argument_Associations
;
2653 -- We should never get here if aspect was disabled
2655 pragma Assert
(not Is_Disabled
(Aspect
));
2657 -- Certain aspects allow for an optional name or expression. Do
2658 -- not generate a pragma with empty argument association list.
2660 if No
(Args
) or else No
(Expression
(First
(Args
))) then
2668 Pragma_Argument_Associations
=> Args
,
2669 Pragma_Identifier
=>
2670 Make_Identifier
(Sloc
(Id
), Pragma_Name
),
2671 Class_Present
=> Class_Present
(Aspect
),
2672 Split_PPC
=> Split_PPC
(Aspect
));
2674 -- Set additional semantic fields
2676 if Is_Ignored
(Aspect
) then
2677 Set_Is_Ignored
(Aitem
);
2678 elsif Is_Checked
(Aspect
) then
2679 Set_Is_Checked
(Aitem
);
2682 Set_Corresponding_Aspect
(Aitem
, Aspect
);
2683 Set_From_Aspect_Specification
(Aitem
);
2686 end Make_Aitem_Pragma
;
2688 -- Start of processing for Analyze_One_Aspect
2691 -- Skip aspect if already analyzed, to avoid looping in some cases
2693 if Analyzed
(Aspect
) then
2697 -- Skip looking at aspect if it is totally disabled. Just mark it
2698 -- as such for later reference in the tree. This also sets the
2699 -- Is_Ignored and Is_Checked flags appropriately.
2701 Check_Applicable_Policy
(Aspect
);
2703 if Is_Disabled
(Aspect
) then
2707 -- Set the source location of expression, used in the case of
2708 -- a failed precondition/postcondition or invariant. Note that
2709 -- the source location of the expression is not usually the best
2710 -- choice here. For example, it gets located on the last AND
2711 -- keyword in a chain of boolean expressiond AND'ed together.
2712 -- It is best to put the message on the first character of the
2713 -- assertion, which is the effect of the First_Node call here.
2715 if Present
(Expr
) then
2716 Eloc
:= Sloc
(First_Node
(Expr
));
2719 -- Check restriction No_Implementation_Aspect_Specifications
2721 if Implementation_Defined_Aspect
(A_Id
) then
2723 (No_Implementation_Aspect_Specifications
, Aspect
);
2726 -- Check restriction No_Specification_Of_Aspect
2728 Check_Restriction_No_Specification_Of_Aspect
(Aspect
);
2730 -- Mark aspect analyzed (actual analysis is delayed till later)
2732 Set_Analyzed
(Aspect
);
2733 Set_Entity
(Aspect
, E
);
2735 -- Build the reference to E that will be used in the built pragmas
2737 Ent
:= New_Occurrence_Of
(E
, Sloc
(Id
));
2739 if A_Id
in Aspect_Attach_Handler | Aspect_Interrupt_Handler
then
2741 -- Treat the specification as a reference to the protected
2742 -- operation, which might otherwise appear unreferenced and
2743 -- generate spurious warnings.
2745 Generate_Reference
(E
, Id
);
2748 -- Check for duplicate aspect. Note that the Comes_From_Source
2749 -- test allows duplicate Pre/Post's that we generate internally
2750 -- to escape being flagged here.
2752 if No_Duplicates_Allowed
(A_Id
) then
2754 while Anod
/= Aspect
loop
2755 if Comes_From_Source
(Aspect
)
2756 and then Same_Aspect
(A_Id
, Get_Aspect_Id
(Anod
))
2758 Error_Msg_Name_1
:= Nam
;
2759 Error_Msg_Sloc
:= Sloc
(Anod
);
2761 -- Case of same aspect specified twice
2763 if Class_Present
(Anod
) = Class_Present
(Aspect
) then
2764 if not Class_Present
(Anod
) then
2766 ("aspect% for & previously given#",
2770 ("aspect `%''Class` for & previously given#",
2780 -- Check some general restrictions on language defined aspects
2782 if not Implementation_Defined_Aspect
(A_Id
)
2783 or else A_Id
in Aspect_Async_Readers
2784 | Aspect_Async_Writers
2785 | Aspect_Effective_Reads
2786 | Aspect_Effective_Writes
2787 | Aspect_Preelaborable_Initialization
2789 Error_Msg_Name_1
:= Nam
;
2791 -- Not allowed for renaming declarations. Examine the original
2792 -- node because a subprogram renaming may have been rewritten
2795 if Nkind
(Original_Node
(N
)) in N_Renaming_Declaration
then
2797 ("aspect % not allowed for renaming declaration",
2801 -- Not allowed for formal type declarations in previous
2802 -- versions of the language. Allowed for them only for
2803 -- shared variable control aspects.
2805 -- Original node is used in case expansion rewrote the node -
2806 -- as is the case with generic derived types.
2808 if Nkind
(Original_Node
(N
)) = N_Formal_Type_Declaration
then
2809 if Ada_Version
< Ada_2022
then
2811 ("aspect % not allowed for formal type declaration",
2814 elsif A_Id
not in Aspect_Atomic
2816 | Aspect_Independent
2817 | Aspect_Atomic_Components
2818 | Aspect_Independent_Components
2819 | Aspect_Volatile_Components
2820 | Aspect_Async_Readers
2821 | Aspect_Async_Writers
2822 | Aspect_Effective_Reads
2823 | Aspect_Effective_Writes
2824 | Aspect_Preelaborable_Initialization
2827 ("aspect % not allowed for formal type declaration",
2833 -- Copy expression for later processing by the procedures
2834 -- Check_Aspect_At_[Freeze_Point | End_Of_Declarations]
2836 -- The expression may be a subprogram name, and can
2837 -- be an operator name that appears as a string, but
2838 -- requires its own analysis procedure (see sem_ch6).
2840 if Nkind
(Expr
) = N_Operator_Symbol
then
2841 Set_Entity
(Id
, Expr
);
2843 Set_Entity
(Id
, New_Copy_Tree
(Expr
));
2846 -- Set Delay_Required as appropriate to aspect
2848 case Aspect_Delay
(A_Id
) is
2849 when Always_Delay
=>
2850 -- For Boolean aspects, do not delay if no expression
2852 if A_Id
in Boolean_Aspects | Library_Unit_Aspects
then
2853 Delay_Required
:= Present
(Expr
);
2855 Delay_Required
:= True;
2859 Delay_Required
:= False;
2863 -- For Boolean aspects, do not delay if no expression except
2864 -- for Full_Access_Only because we need to process it after
2865 -- Volatile and Atomic, which can be independently delayed.
2867 if A_Id
in Boolean_Aspects
2868 and then A_Id
/= Aspect_Full_Access_Only
2871 Delay_Required
:= False;
2873 -- For non-Boolean aspects, if the expression has the form
2874 -- of an integer literal, then do not delay, since we know
2875 -- the value cannot change. This optimization catches most
2876 -- rep clause cases.
2878 elsif A_Id
not in Boolean_Aspects
2879 and then Present
(Expr
)
2880 and then Nkind
(Expr
) = N_Integer_Literal
2882 Delay_Required
:= False;
2884 -- For Alignment and various Size aspects, do not delay for
2885 -- an attribute reference whose prefix is Standard, for
2886 -- example Standard'Maximum_Alignment or Standard'Word_Size.
2888 elsif A_Id
in Aspect_Alignment
2889 | Aspect_Component_Size
2890 | Aspect_Object_Size
2893 and then Present
(Expr
)
2894 and then Nkind
(Expr
) = N_Attribute_Reference
2895 and then Nkind
(Prefix
(Expr
)) = N_Identifier
2896 and then Chars
(Prefix
(Expr
)) = Name_Standard
2898 Delay_Required
:= False;
2900 -- All other cases are delayed
2903 Delay_Required
:= True;
2904 Set_Has_Delayed_Rep_Aspects
(E
);
2910 and then (A_Id
= Aspect_Stable_Properties
2911 or else A_Id
= Aspect_Designated_Storage_Model
2912 or else A_Id
= Aspect_Storage_Model_Type
)
2913 -- ??? It seems like we should do this for all aspects, not
2914 -- just these, but that causes as-yet-undiagnosed regressions.
2917 Set_Has_Delayed_Aspects
(E
);
2918 Set_Is_Delayed_Aspect
(Aspect
);
2921 -- Check 13.1(9.2/5): A representation aspect of a subtype or type
2922 -- shall not be specified (whether by a representation item or an
2923 -- aspect_specification) before the type is completely defined
2926 if Is_Representation_Aspect
(A_Id
)
2927 and then Rep_Item_Too_Early
(E
, N
)
2932 -- Processing based on specific aspect
2935 when Aspect_Unimplemented
=>
2936 null; -- ??? temp for now
2938 -- No_Aspect should be impossible
2941 raise Program_Error
;
2943 -- Case 1: Aspects corresponding to attribute definition
2949 | Aspect_Component_Size
2950 | Aspect_Constant_Indexing
2951 | Aspect_Default_Iterator
2952 | Aspect_Dispatching_Domain
2953 | Aspect_External_Tag
2956 | Aspect_Iterator_Element
2957 | Aspect_Machine_Radix
2958 | Aspect_Object_Size
2962 | Aspect_Scalar_Storage_Order
2963 | Aspect_Simple_Storage_Pool
2966 | Aspect_Storage_Pool
2967 | Aspect_Stream_Size
2969 | Aspect_Variable_Indexing
2972 -- Indexing aspects apply only to tagged type
2974 if A_Id
in Aspect_Constant_Indexing
2975 | Aspect_Variable_Indexing
2976 and then not (Is_Type
(E
)
2977 and then Is_Tagged_Type
(E
))
2980 ("indexing aspect can only apply to a tagged type",
2985 -- For the case of aspect Address, we don't consider that we
2986 -- know the entity is never set in the source, since it is
2987 -- is likely aliasing is occurring.
2989 -- Note: one might think that the analysis of the resulting
2990 -- attribute definition clause would take care of that, but
2991 -- that's not the case since it won't be from source.
2993 if A_Id
= Aspect_Address
then
2994 Set_Never_Set_In_Source
(E
, False);
2997 -- Correctness of the profile of a stream operation is
2998 -- verified at the freeze point, but we must detect the
2999 -- illegal specification of this aspect for a subtype now,
3000 -- to prevent malformed rep_item chains.
3002 if A_Id
in Aspect_Input
3007 if not Is_First_Subtype
(E
) then
3009 ("local name must be a first subtype", Aspect
);
3012 -- If stream aspect applies to the class-wide type,
3013 -- the generated attribute definition applies to the
3014 -- class-wide type as well.
3016 elsif Class_Present
(Aspect
) then
3018 Make_Attribute_Reference
(Loc
,
3020 Attribute_Name
=> Name_Class
);
3024 -- Construct the attribute_definition_clause. The expression
3025 -- in the aspect specification is simply shared with the
3026 -- constructed attribute, because it will be fully analyzed
3027 -- when the attribute is processed.
3030 Make_Attribute_Definition_Clause
(Loc
,
3033 Expression
=> Relocate_Expression
(Expr
));
3035 -- If the address is specified, then we treat the entity as
3036 -- referenced, to avoid spurious warnings. This is analogous
3037 -- to what is done with an attribute definition clause, but
3038 -- here we don't want to generate a reference because this
3039 -- is the point of definition of the entity.
3041 if A_Id
= Aspect_Address
then
3045 -- Case 2: Aspects corresponding to pragmas
3047 -- Case 2a: Aspects corresponding to pragmas with two
3048 -- arguments, where the first argument is a local name
3049 -- referring to the entity, and the second argument is the
3050 -- aspect definition expression.
3054 when Aspect_Linker_Section
=>
3055 Aitem
:= Make_Aitem_Pragma
3056 (Pragma_Argument_Associations
=> New_List
(
3057 Make_Pragma_Argument_Association
(Loc
,
3058 Expression
=> New_Occurrence_Of
(E
, Loc
)),
3059 Make_Pragma_Argument_Association
(Sloc
(Expr
),
3060 Expression
=> Relocate_Node
(Expr
))),
3061 Pragma_Name
=> Name_Linker_Section
);
3063 -- Linker_Section does not need delaying, as its argument
3064 -- must be a static string. Furthermore, if applied to
3065 -- an object with an explicit initialization, the object
3066 -- must be frozen in order to elaborate the initialization
3067 -- code. (This is already done for types with implicit
3068 -- initialization, such as protected types.)
3070 if Nkind
(N
) = N_Object_Declaration
3071 and then Has_Init_Expression
(N
)
3073 Delay_Required
:= False;
3078 -- Corresponds to pragma Implemented, construct the pragma
3080 when Aspect_Synchronization
=>
3081 Aitem
:= Make_Aitem_Pragma
3082 (Pragma_Argument_Associations
=> New_List
(
3083 Make_Pragma_Argument_Association
(Loc
,
3084 Expression
=> New_Occurrence_Of
(E
, Loc
)),
3085 Make_Pragma_Argument_Association
(Sloc
(Expr
),
3086 Expression
=> Relocate_Node
(Expr
))),
3087 Pragma_Name
=> Name_Implemented
);
3091 when Aspect_Attach_Handler
=>
3092 Aitem
:= Make_Aitem_Pragma
3093 (Pragma_Argument_Associations
=> New_List
(
3094 Make_Pragma_Argument_Association
(Sloc
(Ent
),
3096 Make_Pragma_Argument_Association
(Sloc
(Expr
),
3097 Expression
=> Relocate_Expression
(Expr
))),
3098 Pragma_Name
=> Name_Attach_Handler
);
3100 -- We need to insert this pragma into the tree to get proper
3101 -- processing and to look valid from a placement viewpoint.
3103 Insert_Pragma
(Aitem
);
3106 -- Dynamic_Predicate, Predicate, Static_Predicate
3108 when Aspect_Dynamic_Predicate
3110 | Aspect_Static_Predicate
3112 -- These aspects apply only to subtypes
3114 if not Is_Type
(E
) then
3116 ("predicate can only be specified for a subtype",
3120 elsif Is_Incomplete_Type
(E
) then
3122 ("predicate cannot apply to incomplete view", Aspect
);
3124 elsif Is_Generic_Type
(E
) then
3126 ("predicate cannot apply to formal type", Aspect
);
3130 -- Construct the pragma (always a pragma Predicate, with
3131 -- flags recording whether it is static/dynamic). We also
3132 -- set flags recording this in the type itself.
3134 Aitem
:= Make_Aitem_Pragma
3135 (Pragma_Argument_Associations
=> New_List
(
3136 Make_Pragma_Argument_Association
(Sloc
(Ent
),
3138 Make_Pragma_Argument_Association
(Sloc
(Expr
),
3139 Expression
=> Relocate_Expression
(Expr
))),
3140 Pragma_Name
=> Name_Predicate
);
3142 -- Mark type has predicates, and remember what kind of
3143 -- aspect lead to this predicate (we need this to access
3144 -- the right set of check policies later on).
3146 Set_Has_Predicates
(E
);
3148 if A_Id
= Aspect_Dynamic_Predicate
then
3149 Set_Has_Dynamic_Predicate_Aspect
(E
);
3151 -- If the entity has a dynamic predicate, any inherited
3152 -- static predicate becomes dynamic as well, and the
3153 -- predicate function includes the conjunction of both.
3155 Set_Has_Static_Predicate_Aspect
(E
, False);
3157 elsif A_Id
= Aspect_Static_Predicate
then
3158 Set_Has_Static_Predicate_Aspect
(E
);
3161 -- If the type is private, indicate that its completion
3162 -- has a freeze node, because that is the one that will
3163 -- be visible at freeze time.
3165 if Is_Private_Type
(E
) and then Present
(Full_View
(E
)) then
3166 Set_Has_Predicates
(Full_View
(E
));
3168 if A_Id
= Aspect_Dynamic_Predicate
then
3169 Set_Has_Dynamic_Predicate_Aspect
(Full_View
(E
));
3170 elsif A_Id
= Aspect_Static_Predicate
then
3171 Set_Has_Static_Predicate_Aspect
(Full_View
(E
));
3174 Set_Has_Delayed_Aspects
(Full_View
(E
));
3175 Ensure_Freeze_Node
(Full_View
(E
));
3177 -- If there is an Underlying_Full_View, also create a
3178 -- freeze node for that one.
3180 if Is_Private_Type
(Full_View
(E
)) then
3182 U_Full
: constant Entity_Id
:=
3183 Underlying_Full_View
(Full_View
(E
));
3185 if Present
(U_Full
) then
3186 Set_Has_Delayed_Aspects
(U_Full
);
3187 Ensure_Freeze_Node
(U_Full
);
3193 -- Predicate_Failure
3195 when Aspect_Predicate_Failure
=>
3197 -- This aspect applies only to subtypes
3199 if not Is_Type
(E
) then
3201 ("predicate can only be specified for a subtype",
3205 elsif Is_Incomplete_Type
(E
) then
3207 ("predicate cannot apply to incomplete view", Aspect
);
3210 elsif not Has_Predicates
(E
) then
3212 ("Predicate_Failure requires previous predicate" &
3213 " specification", Aspect
);
3216 elsif not (Directly_Specified
(E
, Aspect_Dynamic_Predicate
)
3217 or else Directly_Specified
(E
, Aspect_Static_Predicate
)
3218 or else Directly_Specified
(E
, Aspect_Predicate
))
3221 ("Predicate_Failure requires accompanying" &
3222 " noninherited predicate specification", Aspect
);
3226 -- Construct the pragma
3228 Aitem
:= Make_Aitem_Pragma
3229 (Pragma_Argument_Associations
=> New_List
(
3230 Make_Pragma_Argument_Association
(Sloc
(Ent
),
3232 Make_Pragma_Argument_Association
(Sloc
(Expr
),
3233 Expression
=> Relocate_Node
(Expr
))),
3234 Pragma_Name
=> Name_Predicate_Failure
);
3236 -- Case 2b: Aspects corresponding to pragmas with two
3237 -- arguments, where the second argument is a local name
3238 -- referring to the entity, and the first argument is the
3239 -- aspect definition expression.
3243 when Aspect_Convention
=>
3244 Analyze_Aspect_Convention
;
3247 -- External_Name, Link_Name
3249 when Aspect_External_Name
3252 Analyze_Aspect_External_Link_Name
;
3255 -- CPU, Interrupt_Priority, Priority
3257 -- These three aspects can be specified for a subprogram spec
3258 -- or body, in which case we analyze the expression and export
3259 -- the value of the aspect.
3261 -- Previously, we generated an equivalent pragma for bodies
3262 -- (note that the specs cannot contain these pragmas). The
3263 -- pragma was inserted ahead of local declarations, rather than
3264 -- after the body. This leads to a certain duplication between
3265 -- the processing performed for the aspect and the pragma, but
3266 -- given the straightforward handling required it is simpler
3267 -- to duplicate than to translate the aspect in the spec into
3268 -- a pragma in the declarative part of the body.
3271 | Aspect_Interrupt_Priority
3274 -- Verify the expression is static when Static_Priorities is
3277 if not Is_OK_Static_Expression
(Expr
) then
3278 Check_Restriction
(Static_Priorities
, Expr
);
3281 if Nkind
(N
) in N_Subprogram_Body | N_Subprogram_Declaration
3283 -- Analyze the aspect expression
3285 Analyze_And_Resolve
(Expr
, Standard_Integer
);
3287 -- Interrupt_Priority aspect not allowed for main
3288 -- subprograms. RM D.1 does not forbid this explicitly,
3289 -- but RM J.15.11(6/3) does not permit pragma
3290 -- Interrupt_Priority for subprograms.
3292 if A_Id
= Aspect_Interrupt_Priority
then
3294 ("Interrupt_Priority aspect cannot apply to "
3295 & "subprogram", Expr
);
3297 -- The expression must be static
3299 elsif not Is_OK_Static_Expression
(Expr
) then
3300 Flag_Non_Static_Expr
3301 ("aspect requires static expression!", Expr
);
3303 -- Check whether this is the main subprogram. Issue a
3304 -- warning only if it is obviously not a main program
3305 -- (when it has parameters or when the subprogram is
3306 -- within a package).
3308 elsif Present
(Parameter_Specifications
3309 (Specification
(N
)))
3310 or else not Is_Compilation_Unit
(Defining_Entity
(N
))
3312 -- See RM D.1(14/3) and D.16(12/3)
3315 ("aspect applied to subprogram other than the "
3316 & "main subprogram has no effect??", Expr
);
3318 -- Otherwise check in range and export the value
3320 -- For the CPU aspect
3322 elsif A_Id
= Aspect_CPU
then
3323 if Is_In_Range
(Expr
, RTE
(RE_CPU_Range
)) then
3325 -- Value is correct so we export the value to make
3326 -- it available at execution time.
3329 (Main_Unit
, UI_To_Int
(Expr_Value
(Expr
)));
3333 ("main subprogram 'C'P'U is out of range", Expr
);
3336 -- For the Priority aspect
3338 elsif A_Id
= Aspect_Priority
then
3339 if Is_In_Range
(Expr
, RTE
(RE_Priority
)) then
3341 -- Value is correct so we export the value to make
3342 -- it available at execution time.
3345 (Main_Unit
, UI_To_Int
(Expr_Value
(Expr
)));
3347 -- Ignore pragma if Relaxed_RM_Semantics to support
3348 -- other targets/non GNAT compilers.
3350 elsif not Relaxed_RM_Semantics
then
3352 ("main subprogram priority is out of range",
3357 -- Load an arbitrary entity from System.Tasking.Stages
3358 -- or System.Tasking.Restricted.Stages (depending on
3359 -- the supported profile) to make sure that one of these
3360 -- packages is implicitly with'ed, since we need to have
3361 -- the tasking run time active for the pragma Priority to
3362 -- have any effect. Previously we with'ed the package
3363 -- System.Tasking, but this package does not trigger the
3364 -- required initialization of the run-time library.
3366 if Restricted_Profile
then
3367 Discard_Node
(RTE
(RE_Activate_Restricted_Tasks
));
3369 Discard_Node
(RTE
(RE_Activate_Tasks
));
3372 -- Handling for these aspects in subprograms is complete
3376 -- For task and protected types pass the aspect as an
3381 Make_Attribute_Definition_Clause
(Loc
,
3384 Expression
=> Relocate_Expression
(Expr
));
3387 -- Suppress/Unsuppress
3389 when Aspect_Suppress
3392 Aitem
:= Make_Aitem_Pragma
3393 (Pragma_Argument_Associations
=> New_List
(
3394 Make_Pragma_Argument_Association
(Loc
,
3395 Expression
=> Relocate_Node
(Expr
)),
3396 Make_Pragma_Argument_Association
(Sloc
(Expr
),
3397 Expression
=> New_Occurrence_Of
(E
, Loc
))),
3398 Pragma_Name
=> Nam
);
3400 Delay_Required
:= False;
3404 when Aspect_Warnings
=>
3405 Aitem
:= Make_Aitem_Pragma
3406 (Pragma_Argument_Associations
=> New_List
(
3407 Make_Pragma_Argument_Association
(Sloc
(Expr
),
3408 Expression
=> Relocate_Node
(Expr
)),
3409 Make_Pragma_Argument_Association
(Loc
,
3410 Expression
=> New_Occurrence_Of
(E
, Loc
))),
3411 Pragma_Name
=> Name_Warnings
);
3413 Decorate
(Aspect
, Aitem
);
3414 Insert_Pragma
(Aitem
);
3417 -- Case 2c: Aspects corresponding to pragmas with three
3420 -- Invariant aspects have a first argument that references the
3421 -- entity, a second argument that is the expression and a third
3422 -- argument that is an appropriate message.
3424 -- Invariant, Type_Invariant
3426 when Aspect_Invariant
3427 | Aspect_Type_Invariant
3429 -- Analysis of the pragma will verify placement legality:
3430 -- an invariant must apply to a private type, or appear in
3431 -- the private part of a spec and apply to a completion.
3433 Aitem
:= Make_Aitem_Pragma
3434 (Pragma_Argument_Associations
=> New_List
(
3435 Make_Pragma_Argument_Association
(Sloc
(Ent
),
3437 Make_Pragma_Argument_Association
(Sloc
(Expr
),
3438 Expression
=> Relocate_Node
(Expr
))),
3439 Pragma_Name
=> Name_Invariant
);
3441 -- Add message unless exception messages are suppressed
3443 if not Opt
.Exception_Locations_Suppressed
then
3444 Append_To
(Pragma_Argument_Associations
(Aitem
),
3445 Make_Pragma_Argument_Association
(Eloc
,
3446 Chars
=> Name_Message
,
3448 Make_String_Literal
(Eloc
,
3449 Strval
=> "failed invariant from "
3450 & Build_Location_String
(Eloc
))));
3453 -- For Invariant case, insert immediately after the entity
3454 -- declaration. We do not have to worry about delay issues
3455 -- since the pragma processing takes care of this.
3457 Delay_Required
:= False;
3459 -- Case 2d : Aspects that correspond to a pragma with one
3464 -- Aspect Abstract_State introduces implicit declarations for
3465 -- all state abstraction entities it defines. To emulate this
3466 -- behavior, insert the pragma at the beginning of the visible
3467 -- declarations of the related package so that it is analyzed
3470 when Aspect_Abstract_State
=> Abstract_State
: declare
3471 Context
: Node_Id
:= N
;
3474 -- When aspect Abstract_State appears on a generic package,
3475 -- it is propagated to the package instance. The context in
3476 -- this case is the instance spec.
3478 if Nkind
(Context
) = N_Package_Instantiation
then
3479 Context
:= Instance_Spec
(Context
);
3482 if Nkind
(Context
) in N_Generic_Package_Declaration
3483 | N_Package_Declaration
3485 Aitem
:= Make_Aitem_Pragma
3486 (Pragma_Argument_Associations
=> New_List
(
3487 Make_Pragma_Argument_Association
(Loc
,
3488 Expression
=> Relocate_Node
(Expr
))),
3489 Pragma_Name
=> Name_Abstract_State
);
3491 Decorate
(Aspect
, Aitem
);
3495 Is_Generic_Instance
(Defining_Entity
(Context
)));
3499 ("aspect & must apply to a package declaration",
3506 -- Aspect Async_Readers is never delayed because it is
3507 -- equivalent to a source pragma which appears after the
3508 -- related object declaration.
3510 when Aspect_Async_Readers
=>
3511 Aitem
:= Make_Aitem_Pragma
3512 (Pragma_Argument_Associations
=> New_List
(
3513 Make_Pragma_Argument_Association
(Loc
,
3514 Expression
=> Relocate_Node
(Expr
))),
3515 Pragma_Name
=> Name_Async_Readers
);
3517 Decorate
(Aspect
, Aitem
);
3518 Insert_Pragma
(Aitem
);
3521 -- Aspect Async_Writers is never delayed because it is
3522 -- equivalent to a source pragma which appears after the
3523 -- related object declaration.
3525 when Aspect_Async_Writers
=>
3526 Aitem
:= Make_Aitem_Pragma
3527 (Pragma_Argument_Associations
=> New_List
(
3528 Make_Pragma_Argument_Association
(Loc
,
3529 Expression
=> Relocate_Node
(Expr
))),
3530 Pragma_Name
=> Name_Async_Writers
);
3532 Decorate
(Aspect
, Aitem
);
3533 Insert_Pragma
(Aitem
);
3536 -- Aspect Constant_After_Elaboration is never delayed because
3537 -- it is equivalent to a source pragma which appears after the
3538 -- related object declaration.
3540 when Aspect_Constant_After_Elaboration
=>
3541 Aitem
:= Make_Aitem_Pragma
3542 (Pragma_Argument_Associations
=> New_List
(
3543 Make_Pragma_Argument_Association
(Loc
,
3544 Expression
=> Relocate_Node
(Expr
))),
3546 Name_Constant_After_Elaboration
);
3548 Decorate
(Aspect
, Aitem
);
3549 Insert_Pragma
(Aitem
);
3552 -- Aspect Default_Internal_Condition is never delayed because
3553 -- it is equivalent to a source pragma which appears after the
3554 -- related private type. To deal with forward references, the
3555 -- generated pragma is stored in the rep chain of the related
3556 -- private type as types do not carry contracts. The pragma is
3557 -- wrapped inside of a procedure at the freeze point of the
3558 -- private type's full view.
3560 -- A type entity argument is appended to facilitate inheriting
3561 -- the aspect from parent types (see Build_DIC_Procedure_Body),
3562 -- though that extra argument isn't documented for the pragma.
3564 when Aspect_Default_Initial_Condition
=>
3565 Aitem
:= Make_Aitem_Pragma
3566 (Pragma_Argument_Associations
=> New_List
(
3567 Make_Pragma_Argument_Association
(Loc
,
3568 Expression
=> Relocate_Node
(Expr
)),
3569 Make_Pragma_Argument_Association
(Sloc
(Ent
),
3570 Expression
=> Ent
)),
3572 Name_Default_Initial_Condition
);
3574 Decorate
(Aspect
, Aitem
);
3575 Insert_Pragma
(Aitem
);
3578 -- Default_Storage_Pool
3580 when Aspect_Default_Storage_Pool
=>
3581 Aitem
:= Make_Aitem_Pragma
3582 (Pragma_Argument_Associations
=> New_List
(
3583 Make_Pragma_Argument_Association
(Loc
,
3584 Expression
=> Relocate_Node
(Expr
))),
3586 Name_Default_Storage_Pool
);
3588 Decorate
(Aspect
, Aitem
);
3589 Insert_Pragma
(Aitem
);
3594 -- Aspect Depends is never delayed because it is equivalent to
3595 -- a source pragma which appears after the related subprogram.
3596 -- To deal with forward references, the generated pragma is
3597 -- stored in the contract of the related subprogram and later
3598 -- analyzed at the end of the declarative region. See routine
3599 -- Analyze_Depends_In_Decl_Part for details.
3601 when Aspect_Depends
=>
3602 Aitem
:= Make_Aitem_Pragma
3603 (Pragma_Argument_Associations
=> New_List
(
3604 Make_Pragma_Argument_Association
(Loc
,
3605 Expression
=> Relocate_Node
(Expr
))),
3606 Pragma_Name
=> Name_Depends
);
3608 Decorate
(Aspect
, Aitem
);
3609 Insert_Pragma
(Aitem
);
3612 -- Aspect Effective_Reads is never delayed because it is
3613 -- equivalent to a source pragma which appears after the
3614 -- related object declaration.
3616 when Aspect_Effective_Reads
=>
3617 Aitem
:= Make_Aitem_Pragma
3618 (Pragma_Argument_Associations
=> New_List
(
3619 Make_Pragma_Argument_Association
(Loc
,
3620 Expression
=> Relocate_Node
(Expr
))),
3621 Pragma_Name
=> Name_Effective_Reads
);
3623 Decorate
(Aspect
, Aitem
);
3624 Insert_Pragma
(Aitem
);
3627 -- Aspect Effective_Writes is never delayed because it is
3628 -- equivalent to a source pragma which appears after the
3629 -- related object declaration.
3631 when Aspect_Effective_Writes
=>
3632 Aitem
:= Make_Aitem_Pragma
3633 (Pragma_Argument_Associations
=> New_List
(
3634 Make_Pragma_Argument_Association
(Loc
,
3635 Expression
=> Relocate_Node
(Expr
))),
3636 Pragma_Name
=> Name_Effective_Writes
);
3638 Decorate
(Aspect
, Aitem
);
3639 Insert_Pragma
(Aitem
);
3642 -- Aspect Extensions_Visible is never delayed because it is
3643 -- equivalent to a source pragma which appears after the
3644 -- related subprogram.
3646 when Aspect_Extensions_Visible
=>
3647 Aitem
:= Make_Aitem_Pragma
3648 (Pragma_Argument_Associations
=> New_List
(
3649 Make_Pragma_Argument_Association
(Loc
,
3650 Expression
=> Relocate_Node
(Expr
))),
3651 Pragma_Name
=> Name_Extensions_Visible
);
3653 Decorate
(Aspect
, Aitem
);
3654 Insert_Pragma
(Aitem
);
3657 -- Aspect Ghost is never delayed because it is equivalent to a
3658 -- source pragma which appears at the top of [generic] package
3659 -- declarations or after an object, a [generic] subprogram, or
3660 -- a type declaration.
3662 when Aspect_Ghost
=>
3663 Aitem
:= Make_Aitem_Pragma
3664 (Pragma_Argument_Associations
=> New_List
(
3665 Make_Pragma_Argument_Association
(Loc
,
3666 Expression
=> Relocate_Node
(Expr
))),
3667 Pragma_Name
=> Name_Ghost
);
3669 Decorate
(Aspect
, Aitem
);
3670 Insert_Pragma
(Aitem
);
3675 -- Aspect Global is never delayed because it is equivalent to
3676 -- a source pragma which appears after the related subprogram.
3677 -- To deal with forward references, the generated pragma is
3678 -- stored in the contract of the related subprogram and later
3679 -- analyzed at the end of the declarative region. See routine
3680 -- Analyze_Global_In_Decl_Part for details.
3682 when Aspect_Global
=>
3683 Aitem
:= Make_Aitem_Pragma
3684 (Pragma_Argument_Associations
=> New_List
(
3685 Make_Pragma_Argument_Association
(Loc
,
3686 Expression
=> Relocate_Node
(Expr
))),
3687 Pragma_Name
=> Name_Global
);
3689 Decorate
(Aspect
, Aitem
);
3690 Insert_Pragma
(Aitem
);
3693 -- Initial_Condition
3695 -- Aspect Initial_Condition is never delayed because it is
3696 -- equivalent to a source pragma which appears after the
3697 -- related package. To deal with forward references, the
3698 -- generated pragma is stored in the contract of the related
3699 -- package and later analyzed at the end of the declarative
3700 -- region. See routine Analyze_Initial_Condition_In_Decl_Part
3703 when Aspect_Initial_Condition
=> Initial_Condition
: declare
3704 Context
: Node_Id
:= N
;
3707 -- When aspect Initial_Condition appears on a generic
3708 -- package, it is propagated to the package instance. The
3709 -- context in this case is the instance spec.
3711 if Nkind
(Context
) = N_Package_Instantiation
then
3712 Context
:= Instance_Spec
(Context
);
3715 if Nkind
(Context
) in N_Generic_Package_Declaration
3716 | N_Package_Declaration
3718 Aitem
:= Make_Aitem_Pragma
3719 (Pragma_Argument_Associations
=> New_List
(
3720 Make_Pragma_Argument_Association
(Loc
,
3721 Expression
=> Relocate_Node
(Expr
))),
3723 Name_Initial_Condition
);
3725 Decorate
(Aspect
, Aitem
);
3729 Is_Generic_Instance
(Defining_Entity
(Context
)));
3731 -- Otherwise the context is illegal
3735 ("aspect & must apply to a package declaration",
3740 end Initial_Condition
;
3744 -- Aspect Initializes is never delayed because it is equivalent
3745 -- to a source pragma appearing after the related package. To
3746 -- deal with forward references, the generated pragma is stored
3747 -- in the contract of the related package and later analyzed at
3748 -- the end of the declarative region. For details, see routine
3749 -- Analyze_Initializes_In_Decl_Part.
3751 when Aspect_Initializes
=> Initializes
: declare
3752 Context
: Node_Id
:= N
;
3755 -- When aspect Initializes appears on a generic package,
3756 -- it is propagated to the package instance. The context
3757 -- in this case is the instance spec.
3759 if Nkind
(Context
) = N_Package_Instantiation
then
3760 Context
:= Instance_Spec
(Context
);
3763 if Nkind
(Context
) in N_Generic_Package_Declaration
3764 | N_Package_Declaration
3766 Aitem
:= Make_Aitem_Pragma
3767 (Pragma_Argument_Associations
=> New_List
(
3768 Make_Pragma_Argument_Association
(Loc
,
3769 Expression
=> Relocate_Node
(Expr
))),
3770 Pragma_Name
=> Name_Initializes
);
3772 Decorate
(Aspect
, Aitem
);
3776 Is_Generic_Instance
(Defining_Entity
(Context
)));
3778 -- Otherwise the context is illegal
3782 ("aspect & must apply to a package declaration",
3789 -- Max_Entry_Queue_Depth
3791 when Aspect_Max_Entry_Queue_Depth
=>
3792 Aitem
:= Make_Aitem_Pragma
3793 (Pragma_Argument_Associations
=> New_List
(
3794 Make_Pragma_Argument_Association
(Loc
,
3795 Expression
=> Relocate_Node
(Expr
))),
3796 Pragma_Name
=> Name_Max_Entry_Queue_Depth
);
3798 Decorate
(Aspect
, Aitem
);
3799 Insert_Pragma
(Aitem
);
3802 -- Max_Entry_Queue_Length
3804 when Aspect_Max_Entry_Queue_Length
=>
3805 Aitem
:= Make_Aitem_Pragma
3806 (Pragma_Argument_Associations
=> New_List
(
3807 Make_Pragma_Argument_Association
(Loc
,
3808 Expression
=> Relocate_Node
(Expr
))),
3809 Pragma_Name
=> Name_Max_Entry_Queue_Length
);
3811 Decorate
(Aspect
, Aitem
);
3812 Insert_Pragma
(Aitem
);
3817 when Aspect_Max_Queue_Length
=>
3818 Aitem
:= Make_Aitem_Pragma
3819 (Pragma_Argument_Associations
=> New_List
(
3820 Make_Pragma_Argument_Association
(Loc
,
3821 Expression
=> Relocate_Node
(Expr
))),
3822 Pragma_Name
=> Name_Max_Queue_Length
);
3824 Decorate
(Aspect
, Aitem
);
3825 Insert_Pragma
(Aitem
);
3828 -- Aspect No_Caching is never delayed because it is equivalent
3829 -- to a source pragma which appears after the related object
3832 when Aspect_No_Caching
=>
3833 Aitem
:= Make_Aitem_Pragma
3834 (Pragma_Argument_Associations
=> New_List
(
3835 Make_Pragma_Argument_Association
(Loc
,
3836 Expression
=> Relocate_Node
(Expr
))),
3837 Pragma_Name
=> Name_No_Caching
);
3839 Decorate
(Aspect
, Aitem
);
3840 Insert_Pragma
(Aitem
);
3843 -- No_Controlled_Parts, No_Task_Parts
3845 when Aspect_No_Controlled_Parts | Aspect_No_Task_Parts
=>
3847 -- Check appropriate type argument
3849 if not Is_Type
(E
) then
3851 ("aspect % can only be applied to types", E
);
3854 -- Disallow subtypes
3856 if Nkind
(Declaration_Node
(E
)) = N_Subtype_Declaration
then
3858 ("aspect % cannot be applied to subtypes", E
);
3861 -- Resolve the expression to a boolean
3863 if Present
(Expr
) then
3864 Check_Expr_Is_OK_Static_Expression
(Expr
, Any_Boolean
);
3871 when Aspect_Obsolescent
=> declare
3879 Make_Pragma_Argument_Association
(Sloc
(Expr
),
3880 Expression
=> Relocate_Node
(Expr
)));
3883 Aitem
:= Make_Aitem_Pragma
3884 (Pragma_Argument_Associations
=> Args
,
3885 Pragma_Name
=> Name_Obsolescent
);
3890 when Aspect_Part_Of
=>
3891 if Nkind
(N
) in N_Object_Declaration
3892 | N_Package_Instantiation
3893 or else Is_Single_Concurrent_Type_Declaration
(N
)
3895 Aitem
:= Make_Aitem_Pragma
3896 (Pragma_Argument_Associations
=> New_List
(
3897 Make_Pragma_Argument_Association
(Loc
,
3898 Expression
=> Relocate_Node
(Expr
))),
3899 Pragma_Name
=> Name_Part_Of
);
3901 Decorate
(Aspect
, Aitem
);
3902 Insert_Pragma
(Aitem
);
3906 ("aspect & must apply to package instantiation, "
3907 & "object, single protected type or single task type",
3915 when Aspect_SPARK_Mode
=>
3916 Aitem
:= Make_Aitem_Pragma
3917 (Pragma_Argument_Associations
=> New_List
(
3918 Make_Pragma_Argument_Association
(Loc
,
3919 Expression
=> Relocate_Node
(Expr
))),
3920 Pragma_Name
=> Name_SPARK_Mode
);
3922 Decorate
(Aspect
, Aitem
);
3923 Insert_Pragma
(Aitem
);
3928 -- Aspect Refined_Depends is never delayed because it is
3929 -- equivalent to a source pragma which appears in the
3930 -- declarations of the related subprogram body. To deal with
3931 -- forward references, the generated pragma is stored in the
3932 -- contract of the related subprogram body and later analyzed
3933 -- at the end of the declarative region. For details, see
3934 -- routine Analyze_Refined_Depends_In_Decl_Part.
3936 when Aspect_Refined_Depends
=>
3937 Aitem
:= Make_Aitem_Pragma
3938 (Pragma_Argument_Associations
=> New_List
(
3939 Make_Pragma_Argument_Association
(Loc
,
3940 Expression
=> Relocate_Node
(Expr
))),
3941 Pragma_Name
=> Name_Refined_Depends
);
3943 Decorate
(Aspect
, Aitem
);
3944 Insert_Pragma
(Aitem
);
3949 -- Aspect Refined_Global is never delayed because it is
3950 -- equivalent to a source pragma which appears in the
3951 -- declarations of the related subprogram body. To deal with
3952 -- forward references, the generated pragma is stored in the
3953 -- contract of the related subprogram body and later analyzed
3954 -- at the end of the declarative region. For details, see
3955 -- routine Analyze_Refined_Global_In_Decl_Part.
3957 when Aspect_Refined_Global
=>
3958 Aitem
:= Make_Aitem_Pragma
3959 (Pragma_Argument_Associations
=> New_List
(
3960 Make_Pragma_Argument_Association
(Loc
,
3961 Expression
=> Relocate_Node
(Expr
))),
3962 Pragma_Name
=> Name_Refined_Global
);
3964 Decorate
(Aspect
, Aitem
);
3965 Insert_Pragma
(Aitem
);
3970 when Aspect_Refined_Post
=>
3971 Aitem
:= Make_Aitem_Pragma
3972 (Pragma_Argument_Associations
=> New_List
(
3973 Make_Pragma_Argument_Association
(Loc
,
3974 Expression
=> Relocate_Node
(Expr
))),
3975 Pragma_Name
=> Name_Refined_Post
);
3977 Decorate
(Aspect
, Aitem
);
3978 Insert_Pragma
(Aitem
);
3983 when Aspect_Refined_State
=>
3985 -- The corresponding pragma for Refined_State is inserted in
3986 -- the declarations of the related package body. This action
3987 -- synchronizes both the source and from-aspect versions of
3990 if Nkind
(N
) = N_Package_Body
then
3991 Aitem
:= Make_Aitem_Pragma
3992 (Pragma_Argument_Associations
=> New_List
(
3993 Make_Pragma_Argument_Association
(Loc
,
3994 Expression
=> Relocate_Node
(Expr
))),
3995 Pragma_Name
=> Name_Refined_State
);
3997 Decorate
(Aspect
, Aitem
);
3998 Insert_Pragma
(Aitem
);
4000 -- Otherwise the context is illegal
4004 ("aspect & must apply to a package body", Aspect
, Id
);
4009 -- Relative_Deadline
4011 when Aspect_Relative_Deadline
=>
4012 Aitem
:= Make_Aitem_Pragma
4013 (Pragma_Argument_Associations
=> New_List
(
4014 Make_Pragma_Argument_Association
(Loc
,
4015 Expression
=> Relocate_Node
(Expr
))),
4016 Pragma_Name
=> Name_Relative_Deadline
);
4018 -- If the aspect applies to a task, the corresponding pragma
4019 -- must appear within its declarations, not after.
4021 if Nkind
(N
) = N_Task_Type_Declaration
then
4027 if No
(Task_Definition
(N
)) then
4028 Set_Task_Definition
(N
,
4029 Make_Task_Definition
(Loc
,
4030 Visible_Declarations
=> New_List
,
4031 End_Label
=> Empty
));
4034 Def
:= Task_Definition
(N
);
4035 V
:= Visible_Declarations
(Def
);
4036 if not Is_Empty_List
(V
) then
4037 Insert_Before
(First
(V
), Aitem
);
4040 Set_Visible_Declarations
(Def
, New_List
(Aitem
));
4047 -- Relaxed_Initialization
4049 when Aspect_Relaxed_Initialization
=>
4050 Analyze_Aspect_Relaxed_Initialization
;
4053 -- Secondary_Stack_Size
4055 -- Aspect Secondary_Stack_Size needs to be converted into a
4056 -- pragma for two reasons: the attribute is not analyzed until
4057 -- after the expansion of the task type declaration and the
4058 -- attribute does not have visibility on the discriminant.
4060 when Aspect_Secondary_Stack_Size
=>
4061 Aitem
:= Make_Aitem_Pragma
4062 (Pragma_Argument_Associations
=> New_List
(
4063 Make_Pragma_Argument_Association
(Loc
,
4064 Expression
=> Relocate_Node
(Expr
))),
4066 Name_Secondary_Stack_Size
);
4068 Decorate
(Aspect
, Aitem
);
4069 Insert_Pragma
(Aitem
);
4072 -- Volatile_Function
4074 -- Aspect Volatile_Function is never delayed because it is
4075 -- equivalent to a source pragma which appears after the
4076 -- related subprogram.
4078 when Aspect_Volatile_Function
=>
4079 Aitem
:= Make_Aitem_Pragma
4080 (Pragma_Argument_Associations
=> New_List
(
4081 Make_Pragma_Argument_Association
(Loc
,
4082 Expression
=> Relocate_Node
(Expr
))),
4083 Pragma_Name
=> Name_Volatile_Function
);
4085 Decorate
(Aspect
, Aitem
);
4086 Insert_Pragma
(Aitem
);
4089 -- Case 2e: Annotate aspect
4091 when Aspect_Annotate | Aspect_GNAT_Annotate
=>
4098 -- The argument can be a single identifier
4100 if Nkind
(Expr
) = N_Identifier
then
4102 -- One level of parens is allowed
4104 if Paren_Count
(Expr
) > 1 then
4105 Error_Msg_F
("extra parentheses ignored", Expr
);
4108 Set_Paren_Count
(Expr
, 0);
4110 -- Add the single item to the list
4112 Args
:= New_List
(Expr
);
4114 -- Otherwise we must have an aggregate
4116 elsif Nkind
(Expr
) = N_Aggregate
then
4118 -- Must be positional
4120 if Present
(Component_Associations
(Expr
)) then
4122 ("purely positional aggregate required", Expr
);
4126 -- Must not be parenthesized
4128 if Paren_Count
(Expr
) /= 0 then
4129 Error_Msg_F
-- CODEFIX
4130 ("redundant parentheses", Expr
);
4133 -- List of arguments is list of aggregate expressions
4135 Args
:= Expressions
(Expr
);
4137 -- Anything else is illegal
4140 Error_Msg_F
("wrong form for Annotate aspect", Expr
);
4144 -- Prepare pragma arguments
4147 Arg
:= First
(Args
);
4148 while Present
(Arg
) loop
4150 Make_Pragma_Argument_Association
(Sloc
(Arg
),
4151 Expression
=> Relocate_Node
(Arg
)));
4156 Make_Pragma_Argument_Association
(Sloc
(Ent
),
4157 Chars
=> Name_Entity
,
4158 Expression
=> Ent
));
4160 Aitem
:= Make_Aitem_Pragma
4161 (Pragma_Argument_Associations
=> Pargs
,
4162 Pragma_Name
=> Name_Annotate
);
4165 -- Case 3 : Aspects that don't correspond to pragma/attribute
4166 -- definition clause.
4168 -- Case 3a: The aspects listed below don't correspond to
4169 -- pragmas/attributes but do require delayed analysis.
4171 when Aspect_Default_Value | Aspect_Default_Component_Value
=>
4172 Error_Msg_Name_1
:= Nam
;
4174 if not Is_Type
(E
) then
4175 Error_Msg_N
("aspect% can only apply to a type", Id
);
4178 elsif not Is_First_Subtype
(E
) then
4179 Error_Msg_N
("aspect% cannot apply to subtype", Id
);
4182 elsif A_Id
= Aspect_Default_Value
4183 and then not Is_Scalar_Type
(E
)
4186 ("aspect% can only be applied to scalar type", Id
);
4189 elsif A_Id
= Aspect_Default_Component_Value
then
4190 if not Is_Array_Type
(E
) then
4192 ("aspect% can only be applied to array type", Id
);
4195 elsif not Is_Scalar_Type
(Component_Type
(E
)) then
4196 Error_Msg_N
("aspect% requires scalar components", Id
);
4203 when Aspect_Aggregate
=>
4204 Validate_Aspect_Aggregate
(Expr
);
4205 Record_Rep_Item
(E
, Aspect
);
4208 when Aspect_Stable_Properties
=>
4209 Validate_Aspect_Stable_Properties
4210 (E
, Expr
, Class_Present
=> Class_Present
(Aspect
));
4211 Record_Rep_Item
(E
, Aspect
);
4214 when Aspect_Designated_Storage_Model
=>
4215 if not Extensions_Allowed
then
4216 Error_Msg_GNAT_Extension
("aspect %", Sloc
(Aspect
));
4218 elsif not Is_Type
(E
)
4219 or else Ekind
(E
) /= E_Access_Type
4222 ("can only be specified for pool-specific access type",
4226 Record_Rep_Item
(E
, Aspect
);
4229 when Aspect_Storage_Model_Type
=>
4230 if not Extensions_Allowed
then
4231 Error_Msg_GNAT_Extension
("aspect %", Sloc
(Aspect
));
4233 elsif not Is_Type
(E
)
4234 or else not Is_Immutably_Limited_Type
(E
)
4237 ("can only be specified for immutably limited type",
4241 Record_Rep_Item
(E
, Aspect
);
4244 when Aspect_Integer_Literal
4245 | Aspect_Real_Literal
4246 | Aspect_String_Literal
4249 if not Is_First_Subtype
(E
) then
4251 ("may only be specified for a first subtype", Aspect
);
4255 if Ada_Version
< Ada_2022
then
4257 (No_Implementation_Aspect_Specifications
, N
);
4262 -- Case 3b: The aspects listed below don't correspond to
4263 -- pragmas/attributes and don't need delayed analysis.
4265 -- Implicit_Dereference
4267 -- For Implicit_Dereference, External_Name and Link_Name, only
4268 -- the legality checks are done during the analysis, thus no
4269 -- delay is required.
4271 when Aspect_Implicit_Dereference
=>
4272 Analyze_Aspect_Implicit_Dereference
;
4277 when Aspect_Dimension
=>
4278 Analyze_Aspect_Dimension
(N
, Id
, Expr
);
4283 when Aspect_Dimension_System
=>
4284 Analyze_Aspect_Dimension_System
(N
, Id
, Expr
);
4287 -- Case 4: Aspects requiring special handling
4289 -- Pre/Post/Test_Case/Contract_Cases/Subprogram_Variant whose
4290 -- corresponding pragmas take care of the delay.
4294 -- Aspects Pre/Post generate Precondition/Postcondition pragmas
4295 -- with a first argument that is the expression, and a second
4296 -- argument that is an informative message if the test fails.
4297 -- This is inserted right after the declaration, to get the
4298 -- required pragma placement. The processing for the pragmas
4299 -- takes care of the required delay.
4301 when Pre_Post_Aspects
=> Pre_Post
: declare
4305 if A_Id
in Aspect_Pre | Aspect_Precondition
then
4306 Pname
:= Name_Precondition
;
4308 Pname
:= Name_Postcondition
;
4311 -- Check that the class-wide predicate cannot be applied to
4312 -- an operation of a synchronized type. AI12-0182 forbids
4313 -- these altogether, while earlier language semantics made
4314 -- them legal on tagged synchronized types.
4316 -- Other legality checks are performed when analyzing the
4317 -- contract of the operation.
4319 if Class_Present
(Aspect
)
4320 and then Is_Concurrent_Type
(Current_Scope
)
4321 and then Ekind
(E
) in E_Entry | E_Function | E_Procedure
4323 Error_Msg_Name_1
:= Original_Aspect_Pragma_Name
(Aspect
);
4325 ("aspect % can only be specified for a primitive "
4326 & "operation of a tagged type", Aspect
);
4331 -- Remember class-wide conditions; they will be merged
4332 -- with inherited conditions.
4334 if Class_Present
(Aspect
)
4335 and then A_Id
in Aspect_Pre | Aspect_Post
4336 and then Is_Subprogram
(E
)
4337 and then not Is_Ignored_Ghost_Entity
(E
)
4339 if A_Id
= Aspect_Pre
then
4340 if Is_Ignored
(Aspect
) then
4341 Set_Ignored_Class_Preconditions
(E
,
4342 New_Copy_Tree
(Expr
));
4344 Set_Class_Preconditions
(E
, New_Copy_Tree
(Expr
));
4347 -- Postconditions may split into separate aspects, and we
4348 -- remember the expression before such split (i.e. when
4349 -- the first postcondition is processed).
4351 elsif No
(Class_Postconditions
(E
))
4352 and then No
(Ignored_Class_Postconditions
(E
))
4354 if Is_Ignored
(Aspect
) then
4355 Set_Ignored_Class_Postconditions
(E
,
4356 New_Copy_Tree
(Expr
));
4358 Set_Class_Postconditions
(E
, New_Copy_Tree
(Expr
));
4363 -- If the expressions is of the form A and then B, then
4364 -- we generate separate Pre/Post aspects for the separate
4365 -- clauses. Since we allow multiple pragmas, there is no
4366 -- problem in allowing multiple Pre/Post aspects internally.
4367 -- These should be treated in reverse order (B first and
4368 -- A second) since they are later inserted just after N in
4369 -- the order they are treated. This way, the pragma for A
4370 -- ends up preceding the pragma for B, which may have an
4371 -- importance for the error raised (either constraint error
4372 -- or precondition error).
4374 -- We do not do this for Pre'Class, since we have to put
4375 -- these conditions together in a complex OR expression.
4377 -- We don't do this in GNATprove mode, because it brings no
4378 -- benefit for proof and causes annoyance for flow analysis,
4379 -- which prefers to be as close to the original source code
4380 -- as possible. Also we don't do this when analyzing generic
4381 -- units since it causes spurious visibility errors in the
4382 -- preanalysis of instantiations.
4384 if not GNATprove_Mode
4385 and then (Pname
= Name_Postcondition
4386 or else not Class_Present
(Aspect
))
4387 and then not Inside_A_Generic
4389 while Nkind
(Expr
) = N_And_Then
loop
4390 Insert_After
(Aspect
,
4391 Make_Aspect_Specification
(Sloc
(Left_Opnd
(Expr
)),
4392 Identifier
=> Identifier
(Aspect
),
4393 Expression
=> Relocate_Node
(Left_Opnd
(Expr
)),
4394 Class_Present
=> Class_Present
(Aspect
),
4395 Split_PPC
=> True));
4396 Rewrite
(Expr
, Relocate_Node
(Right_Opnd
(Expr
)));
4397 Eloc
:= Sloc
(Expr
);
4401 -- Build the precondition/postcondition pragma
4403 Aitem
:= Make_Aitem_Pragma
4404 (Pragma_Argument_Associations
=> New_List
(
4405 Make_Pragma_Argument_Association
(Eloc
,
4406 Chars
=> Name_Check
,
4407 Expression
=> Relocate_Expression
(Expr
))),
4408 Pragma_Name
=> Pname
);
4410 -- Add message unless exception messages are suppressed
4412 if not Opt
.Exception_Locations_Suppressed
then
4413 Append_To
(Pragma_Argument_Associations
(Aitem
),
4414 Make_Pragma_Argument_Association
(Eloc
,
4415 Chars
=> Name_Message
,
4417 Make_String_Literal
(Eloc
,
4419 & Get_Name_String
(Pname
)
4421 & Build_Location_String
(Eloc
))));
4424 Set_Is_Delayed_Aspect
(Aspect
);
4426 -- For Pre/Post cases, insert immediately after the entity
4427 -- declaration, since that is the required pragma placement.
4428 -- Note that for these aspects, we do not have to worry
4429 -- about delay issues, since the pragmas themselves deal
4430 -- with delay of visibility for the expression analysis.
4432 Insert_Pragma
(Aitem
);
4439 when Aspect_Test_Case
=> Test_Case
: declare
4441 Comp_Expr
: Node_Id
;
4442 Comp_Assn
: Node_Id
;
4447 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
4448 Error_Msg_Name_1
:= Nam
;
4449 Error_Msg_N
("incorrect placement of aspect %", E
);
4453 if Nkind
(Expr
) /= N_Aggregate
4454 or else Null_Record_Present
(Expr
)
4456 Error_Msg_Name_1
:= Nam
;
4458 ("wrong syntax for aspect % for &", Id
, E
);
4462 -- Check that the expression is a proper aggregate (no
4465 if Paren_Count
(Expr
) /= 0 then
4466 Error_Msg_F
-- CODEFIX
4467 ("redundant parentheses", Expr
);
4471 -- Create the list of arguments for building the Test_Case
4474 Comp_Expr
:= First
(Expressions
(Expr
));
4475 while Present
(Comp_Expr
) loop
4477 Make_Pragma_Argument_Association
(Sloc
(Comp_Expr
),
4478 Expression
=> Relocate_Node
(Comp_Expr
)));
4482 Comp_Assn
:= First
(Component_Associations
(Expr
));
4483 while Present
(Comp_Assn
) loop
4484 if List_Length
(Choices
(Comp_Assn
)) /= 1
4486 Nkind
(First
(Choices
(Comp_Assn
))) /= N_Identifier
4488 Error_Msg_Name_1
:= Nam
;
4490 ("wrong syntax for aspect % for &", Id
, E
);
4495 Make_Pragma_Argument_Association
(Sloc
(Comp_Assn
),
4496 Chars
=> Chars
(First
(Choices
(Comp_Assn
))),
4498 Relocate_Node
(Expression
(Comp_Assn
))));
4502 -- Build the test-case pragma
4504 Aitem
:= Make_Aitem_Pragma
4505 (Pragma_Argument_Associations
=> Args
,
4506 Pragma_Name
=> Name_Test_Case
);
4511 when Aspect_Contract_Cases
=>
4512 Aitem
:= Make_Aitem_Pragma
4513 (Pragma_Argument_Associations
=> New_List
(
4514 Make_Pragma_Argument_Association
(Loc
,
4515 Expression
=> Relocate_Node
(Expr
))),
4516 Pragma_Name
=> Name_Contract_Cases
);
4518 Decorate
(Aspect
, Aitem
);
4519 Insert_Pragma
(Aitem
);
4522 -- Subprogram_Variant
4524 when Aspect_Subprogram_Variant
=>
4525 Aitem
:= Make_Aitem_Pragma
4526 (Pragma_Argument_Associations
=> New_List
(
4527 Make_Pragma_Argument_Association
(Loc
,
4528 Expression
=> Relocate_Node
(Expr
))),
4529 Pragma_Name
=> Name_Subprogram_Variant
);
4531 Decorate
(Aspect
, Aitem
);
4532 Insert_Pragma
(Aitem
);
4535 -- Case 5: Special handling for aspects with an optional
4536 -- boolean argument.
4538 -- In the delayed case, the corresponding pragma cannot be
4539 -- generated yet because the evaluation of the boolean needs
4540 -- to be delayed till the freeze point.
4542 when Boolean_Aspects
4543 | Library_Unit_Aspects
4545 Set_Is_Boolean_Aspect
(Aspect
);
4547 -- Lock_Free aspect only apply to protected objects
4549 if A_Id
= Aspect_Lock_Free
then
4550 if Ekind
(E
) /= E_Protected_Type
then
4551 Error_Msg_Name_1
:= Nam
;
4553 ("aspect % only applies to a protected type " &
4558 -- Set the Uses_Lock_Free flag to True if there is no
4559 -- expression or if the expression is True. The
4560 -- evaluation of this aspect should be delayed to the
4561 -- freeze point if we wanted to handle the corner case
4562 -- of "true" or "false" being redefined.
4565 or else Is_True
(Static_Boolean
(Expr
))
4567 Set_Uses_Lock_Free
(E
);
4570 Record_Rep_Item
(E
, Aspect
);
4575 elsif A_Id
in Aspect_Export | Aspect_Import
then
4576 Analyze_Aspect_Export_Import
;
4578 -- Disable_Controlled
4580 elsif A_Id
= Aspect_Disable_Controlled
then
4581 Analyze_Aspect_Disable_Controlled
;
4584 -- Ada 2022 (AI12-0129): Exclusive_Functions
4586 elsif A_Id
= Aspect_Exclusive_Functions
then
4587 if Ekind
(E
) /= E_Protected_Type
then
4588 Error_Msg_Name_1
:= Nam
;
4590 ("aspect % only applies to a protected type " &
4597 -- Ada 2022 (AI12-0363): Full_Access_Only
4599 elsif A_Id
= Aspect_Full_Access_Only
then
4600 Error_Msg_Ada_2022_Feature
("aspect %", Sloc
(Aspect
));
4602 -- Ada 2022 (AI12-0075): static expression functions
4604 elsif A_Id
= Aspect_Static
then
4605 Analyze_Aspect_Static
;
4608 -- Ada 2022 (AI12-0279)
4610 elsif A_Id
= Aspect_Yield
then
4611 Analyze_Aspect_Yield
;
4615 -- Library unit aspects require special handling in the case
4616 -- of a package declaration, the pragma needs to be inserted
4617 -- in the list of declarations for the associated package.
4618 -- There is no issue of visibility delay for these aspects.
4620 if A_Id
in Library_Unit_Aspects
4622 Nkind
(N
) in N_Package_Declaration
4623 | N_Generic_Package_Declaration
4624 and then Nkind
(Parent
(N
)) /= N_Compilation_Unit
4626 -- Aspect is legal on a local instantiation of a library-
4627 -- level generic unit.
4629 and then not Is_Generic_Instance
(Defining_Entity
(N
))
4632 ("incorrect context for library unit aspect&", Id
);
4636 -- Cases where we do not delay
4638 if not Delay_Required
then
4640 -- Exclude aspects Export and Import because their pragma
4641 -- syntax does not map directly to a Boolean aspect.
4643 if A_Id
not in Aspect_Export | Aspect_Import
then
4644 Aitem
:= Make_Aitem_Pragma
4645 (Pragma_Argument_Associations
=> New_List
(
4646 Make_Pragma_Argument_Association
(Sloc
(Ent
),
4647 Expression
=> Ent
)),
4648 Pragma_Name
=> Nam
);
4651 -- In general cases, the corresponding pragma/attribute
4652 -- definition clause will be inserted later at the freezing
4653 -- point, and we do not need to build it now.
4661 -- This is special because for access types we need to generate
4662 -- an attribute definition clause. This also works for single
4663 -- task declarations, but it does not work for task type
4664 -- declarations, because we have the case where the expression
4665 -- references a discriminant of the task type. That can't use
4666 -- an attribute definition clause because we would not have
4667 -- visibility on the discriminant. For that case we must
4668 -- generate a pragma in the task definition.
4670 when Aspect_Storage_Size
=>
4674 if Ekind
(E
) = E_Task_Type
then
4676 Decl
: constant Node_Id
:= Declaration_Node
(E
);
4679 pragma Assert
(Nkind
(Decl
) = N_Task_Type_Declaration
);
4681 -- If no task definition, create one
4683 if No
(Task_Definition
(Decl
)) then
4684 Set_Task_Definition
(Decl
,
4685 Make_Task_Definition
(Loc
,
4686 Visible_Declarations
=> Empty_List
,
4687 End_Label
=> Empty
));
4690 -- Create a pragma and put it at the start of the task
4691 -- definition for the task type declaration.
4693 Aitem
:= Make_Aitem_Pragma
4694 (Pragma_Argument_Associations
=> New_List
(
4695 Make_Pragma_Argument_Association
(Loc
,
4696 Expression
=> Relocate_Node
(Expr
))),
4697 Pragma_Name
=> Name_Storage_Size
);
4701 Visible_Declarations
(Task_Definition
(Decl
)));
4705 -- All other cases, generate attribute definition
4709 Make_Attribute_Definition_Clause
(Loc
,
4711 Chars
=> Name_Storage_Size
,
4712 Expression
=> Relocate_Node
(Expr
));
4716 -- Attach the corresponding pragma/attribute definition clause to
4717 -- the aspect specification node.
4719 if Present
(Aitem
) then
4720 Set_From_Aspect_Specification
(Aitem
);
4723 -- For an aspect that applies to a type, indicate whether it
4724 -- appears on a partial view of the type.
4727 and then Is_Private_Type
(E
)
4729 Set_Aspect_On_Partial_View
(Aspect
);
4732 -- In the context of a compilation unit, we directly put the
4733 -- pragma in the Pragmas_After list of the N_Compilation_Unit_Aux
4734 -- node (no delay is required here) except for aspects on a
4735 -- subprogram body (see below) and a generic package, for which we
4736 -- need to introduce the pragma before building the generic copy
4737 -- (see sem_ch12), and for package instantiations, where the
4738 -- library unit pragmas are better handled early.
4740 if Nkind
(Parent
(N
)) = N_Compilation_Unit
4741 and then (Present
(Aitem
) or else Is_Boolean_Aspect
(Aspect
))
4744 Aux
: constant Node_Id
:= Aux_Decls_Node
(Parent
(N
));
4747 pragma Assert
(Nkind
(Aux
) = N_Compilation_Unit_Aux
);
4749 -- For a Boolean aspect, create the corresponding pragma if
4750 -- no expression or if the value is True.
4752 if Is_Boolean_Aspect
(Aspect
) and then No
(Aitem
) then
4753 if Is_True
(Static_Boolean
(Expr
)) then
4754 Aitem
:= Make_Aitem_Pragma
4755 (Pragma_Argument_Associations
=> New_List
(
4756 Make_Pragma_Argument_Association
(Sloc
(Ent
),
4757 Expression
=> Ent
)),
4758 Pragma_Name
=> Nam
);
4760 Set_From_Aspect_Specification
(Aitem
, True);
4761 Set_Corresponding_Aspect
(Aitem
, Aspect
);
4768 -- If the aspect is on a subprogram body (relevant aspect
4769 -- is Inline), add the pragma in front of the declarations.
4771 if Nkind
(N
) = N_Subprogram_Body
then
4772 if No
(Declarations
(N
)) then
4773 Set_Declarations
(N
, New_List
);
4776 Prepend
(Aitem
, Declarations
(N
));
4778 elsif Nkind
(N
) = N_Generic_Package_Declaration
then
4779 if No
(Visible_Declarations
(Specification
(N
))) then
4780 Set_Visible_Declarations
(Specification
(N
), New_List
);
4784 Visible_Declarations
(Specification
(N
)));
4786 elsif Nkind
(N
) = N_Package_Instantiation
then
4788 Spec
: constant Node_Id
:=
4789 Specification
(Instance_Spec
(N
));
4791 if No
(Visible_Declarations
(Spec
)) then
4792 Set_Visible_Declarations
(Spec
, New_List
);
4795 Prepend
(Aitem
, Visible_Declarations
(Spec
));
4799 if No
(Pragmas_After
(Aux
)) then
4800 Set_Pragmas_After
(Aux
, New_List
);
4803 Append
(Aitem
, Pragmas_After
(Aux
));
4810 -- The evaluation of the aspect is delayed to the freezing point.
4811 -- The pragma or attribute clause if there is one is then attached
4812 -- to the aspect specification which is put in the rep item list.
4814 if Delay_Required
then
4815 if Present
(Aitem
) then
4816 Set_Is_Delayed_Aspect
(Aitem
);
4817 Set_Aspect_Rep_Item
(Aspect
, Aitem
);
4818 Set_Parent
(Aitem
, Aspect
);
4821 Set_Is_Delayed_Aspect
(Aspect
);
4823 -- In the case of Default_Value, link the aspect to base type
4824 -- as well, even though it appears on a first subtype. This is
4825 -- mandated by the semantics of the aspect. Do not establish
4826 -- the link when processing the base type itself as this leads
4827 -- to a rep item circularity.
4829 if A_Id
= Aspect_Default_Value
and then Base_Type
(E
) /= E
then
4830 Set_Has_Delayed_Aspects
(Base_Type
(E
));
4831 Record_Rep_Item
(Base_Type
(E
), Aspect
);
4834 Set_Has_Delayed_Aspects
(E
);
4835 Record_Rep_Item
(E
, Aspect
);
4837 -- When delay is not required and the context is a package or a
4838 -- subprogram body, insert the pragma in the body declarations.
4840 elsif Nkind
(N
) in N_Package_Body | N_Subprogram_Body
then
4841 if No
(Declarations
(N
)) then
4842 Set_Declarations
(N
, New_List
);
4845 -- The pragma is added before source declarations
4847 Prepend_To
(Declarations
(N
), Aitem
);
4849 -- When delay is not required and the context is not a compilation
4850 -- unit, we simply insert the pragma/attribute definition clause
4853 elsif Present
(Aitem
) then
4854 Insert_After
(Ins_Node
, Aitem
);
4860 -- If a nonoverridable aspect is explicitly specified for a
4861 -- derived type, then check consistency with the parent type.
4863 if A_Id
in Nonoverridable_Aspect_Id
4864 and then Nkind
(N
) = N_Full_Type_Declaration
4865 and then Nkind
(Type_Definition
(N
)) = N_Derived_Type_Definition
4866 and then not In_Instance_Body
4869 Parent_Type
: constant Entity_Id
:= Etype
(E
);
4870 Inherited_Aspect
: constant Node_Id
:=
4871 Find_Aspect
(Parent_Type
, A_Id
);
4873 if Present
(Inherited_Aspect
)
4874 and then not Is_Confirming
4875 (A_Id
, Inherited_Aspect
, Aspect
)
4877 Error_Msg_Name_1
:= Aspect_Names
(A_Id
);
4878 Error_Msg_Sloc
:= Sloc
(Inherited_Aspect
);
4881 ("overriding aspect specification for "
4882 & "nonoverridable aspect % does not confirm "
4883 & "aspect specification inherited from #",
4889 when Aspect_Exit
=> null;
4890 end Analyze_One_Aspect
;
4893 end loop Aspect_Loop
;
4895 if Has_Delayed_Aspects
(E
) then
4896 Ensure_Freeze_Node
(E
);
4898 end Analyze_Aspect_Specifications
;
4900 ------------------------------------------------
4901 -- Analyze_Aspects_On_Subprogram_Body_Or_Stub --
4902 ------------------------------------------------
4904 procedure Analyze_Aspects_On_Subprogram_Body_Or_Stub
(N
: Node_Id
) is
4905 Body_Id
: constant Entity_Id
:= Defining_Entity
(N
);
4907 procedure Diagnose_Misplaced_Aspects
(Spec_Id
: Entity_Id
);
4908 -- Body [stub] N has aspects, but they are not properly placed. Emit an
4909 -- error message depending on the aspects involved. Spec_Id denotes the
4910 -- entity of the corresponding spec.
4912 --------------------------------
4913 -- Diagnose_Misplaced_Aspects --
4914 --------------------------------
4916 procedure Diagnose_Misplaced_Aspects
(Spec_Id
: Entity_Id
) is
4917 procedure Misplaced_Aspect_Error
4920 -- Emit an error message concerning misplaced aspect Asp. Ref_Nam is
4921 -- the name of the refined version of the aspect.
4923 ----------------------------
4924 -- Misplaced_Aspect_Error --
4925 ----------------------------
4927 procedure Misplaced_Aspect_Error
4931 Asp_Nam
: constant Name_Id
:= Chars
(Identifier
(Asp
));
4932 Asp_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Asp_Nam
);
4935 -- The corresponding spec already contains the aspect in question
4936 -- and the one appearing on the body must be the refined form:
4938 -- procedure P with Global ...;
4939 -- procedure P with Global ... is ... end P;
4943 if Has_Aspect
(Spec_Id
, Asp_Id
) then
4944 Error_Msg_Name_1
:= Asp_Nam
;
4946 -- Subunits cannot carry aspects that apply to a subprogram
4949 if Nkind
(Parent
(N
)) = N_Subunit
then
4950 Error_Msg_N
("aspect % cannot apply to a subunit", Asp
);
4952 -- Otherwise suggest the refined form
4955 Error_Msg_Name_2
:= Ref_Nam
;
4956 Error_Msg_N
("aspect % should be %", Asp
);
4959 -- Otherwise the aspect must appear on the spec, not on the body
4962 -- procedure P with Global ... is ... end P;
4966 ("aspect specification must appear on initial declaration",
4969 end Misplaced_Aspect_Error
;
4976 -- Start of processing for Diagnose_Misplaced_Aspects
4979 -- Iterate over the aspect specifications and emit specific errors
4980 -- where applicable.
4982 Asp
:= First
(Aspect_Specifications
(N
));
4983 while Present
(Asp
) loop
4984 Asp_Nam
:= Chars
(Identifier
(Asp
));
4986 -- Do not emit errors on aspects that can appear on a subprogram
4987 -- body. This scenario occurs when the aspect specification list
4988 -- contains both misplaced and properly placed aspects.
4990 if Aspect_On_Body_Or_Stub_OK
(Get_Aspect_Id
(Asp_Nam
)) then
4993 -- Special diagnostics for SPARK aspects
4995 elsif Asp_Nam
= Name_Depends
then
4996 Misplaced_Aspect_Error
(Asp
, Name_Refined_Depends
);
4998 elsif Asp_Nam
= Name_Global
then
4999 Misplaced_Aspect_Error
(Asp
, Name_Refined_Global
);
5001 elsif Asp_Nam
= Name_Post
then
5002 Misplaced_Aspect_Error
(Asp
, Name_Refined_Post
);
5004 -- Otherwise a language-defined aspect is misplaced
5008 ("aspect specification must appear on initial declaration",
5014 end Diagnose_Misplaced_Aspects
;
5018 Spec_Id
: constant Entity_Id
:= Unique_Defining_Entity
(N
);
5020 -- Start of processing for Analyze_Aspects_On_Subprogram_Body_Or_Stub
5023 -- Language-defined aspects cannot be associated with a subprogram body
5024 -- [stub] if the subprogram has a spec. Certain implementation defined
5025 -- aspects are allowed to break this rule (for all applicable cases, see
5026 -- table Aspects.Aspect_On_Body_Or_Stub_OK).
5028 if Spec_Id
/= Body_Id
and then not Aspects_On_Body_Or_Stub_OK
(N
) then
5029 Diagnose_Misplaced_Aspects
(Spec_Id
);
5031 Analyze_Aspect_Specifications
(N
, Body_Id
);
5033 end Analyze_Aspects_On_Subprogram_Body_Or_Stub
;
5035 -----------------------
5036 -- Analyze_At_Clause --
5037 -----------------------
5039 -- An at clause is replaced by the corresponding Address attribute
5040 -- definition clause that is the preferred approach in Ada 95.
5042 procedure Analyze_At_Clause
(N
: Node_Id
) is
5043 CS
: constant Boolean := Comes_From_Source
(N
);
5046 -- This is an obsolescent feature
5048 Check_Restriction
(No_Obsolescent_Features
, N
);
5050 if Warn_On_Obsolescent_Feature
then
5052 ("?j?at clause is an obsolescent feature (RM J.7(2))", N
);
5054 ("\?j?use address attribute definition clause instead", N
);
5057 -- Rewrite as address clause
5060 Make_Attribute_Definition_Clause
(Sloc
(N
),
5061 Name
=> Identifier
(N
),
5062 Chars
=> Name_Address
,
5063 Expression
=> Expression
(N
)));
5065 -- We preserve Comes_From_Source, since logically the clause still comes
5066 -- from the source program even though it is changed in form.
5068 Set_Comes_From_Source
(N
, CS
);
5070 -- Analyze rewritten clause
5072 Analyze_Attribute_Definition_Clause
(N
);
5073 end Analyze_At_Clause
;
5075 -----------------------------------------
5076 -- Analyze_Attribute_Definition_Clause --
5077 -----------------------------------------
5079 procedure Analyze_Attribute_Definition_Clause
(N
: Node_Id
) is
5080 Loc
: constant Source_Ptr
:= Sloc
(N
);
5081 Nam
: constant Node_Id
:= Name
(N
);
5082 Attr
: constant Name_Id
:= Chars
(N
);
5083 Expr
: constant Node_Id
:= Expression
(N
);
5084 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Attr
);
5087 -- The entity of Nam after it is analyzed. In the case of an incomplete
5088 -- type, this is the underlying type.
5091 -- The underlying entity to which the attribute applies. Generally this
5092 -- is the Underlying_Type of Ent, except in the case where the clause
5093 -- applies to the full view of an incomplete or private type, in which
5094 -- case U_Ent is just a copy of Ent.
5096 FOnly
: Boolean := False;
5097 -- Reset to True for subtype specific attribute (Alignment, Size)
5098 -- and for stream attributes, i.e. those cases where in the call to
5099 -- Rep_Item_Too_Late, FOnly is set True so that only the freezing rules
5100 -- are checked. Note that the case of stream attributes is not clear
5101 -- from the RM, but see AI95-00137. Also, the RM seems to disallow
5102 -- Storage_Size for derived task types, but that is also clearly
5105 procedure Analyze_Put_Image_TSS_Definition
;
5107 procedure Analyze_Stream_TSS_Definition
(TSS_Nam
: TSS_Name_Type
);
5108 -- Common processing for 'Read, 'Write, 'Input and 'Output attribute
5109 -- definition clauses.
5111 function Duplicate_Clause
return Boolean;
5112 -- This routine checks if the aspect for U_Ent being given by attribute
5113 -- definition clause N is for an aspect that has already been specified,
5114 -- and if so gives an error message. If there is a duplicate, True is
5115 -- returned, otherwise there is no error, and False is returned. Size
5116 -- and Value_Size are considered to conflict, but for compatibility,
5117 -- this is merely a warning.
5119 procedure Check_Indexing_Functions
;
5120 -- Check that the function in Constant_Indexing or Variable_Indexing
5121 -- attribute has the proper type structure. If the name is overloaded,
5122 -- check that some interpretation is legal.
5124 procedure Check_Iterator_Functions
;
5125 -- Check that there is a single function in Default_Iterator attribute
5126 -- that has the proper type structure.
5128 function Check_Primitive_Function
(Subp
: Entity_Id
) return Boolean;
5129 -- Common legality check for the previous two
5131 -----------------------------------
5132 -- Analyze_Put_Image_TSS_Definition --
5133 -----------------------------------
5135 procedure Analyze_Put_Image_TSS_Definition
is
5136 Subp
: Entity_Id
:= Empty
;
5141 function Has_Good_Profile
5143 Report
: Boolean := False) return Boolean;
5144 -- Return true if the entity is a subprogram with an appropriate
5145 -- profile for the attribute being defined. If result is False and
5146 -- Report is True, function emits appropriate error.
5148 ----------------------
5149 -- Has_Good_Profile --
5150 ----------------------
5152 function Has_Good_Profile
5154 Report
: Boolean := False) return Boolean
5160 if Ekind
(Subp
) /= E_Procedure
then
5164 F
:= First_Formal
(Subp
);
5170 if Base_Type
(Etype
(F
))
5171 /= Class_Wide_Type
(RTE
(RE_Root_Buffer_Type
))
5175 ("wrong type for Put_Image procedure''s first parameter",
5176 Parameter_Type
(Parent
(F
)));
5182 if Parameter_Mode
(F
) /= E_In_Out_Parameter
then
5185 ("wrong mode for Put_Image procedure''s first parameter",
5196 -- Verify that the prefix of the attribute and the local name for
5197 -- the type of the formal match.
5199 if Base_Type
(Typ
) /= Base_Type
(Ent
) then
5202 ("wrong type for Put_Image procedure''s second parameter",
5203 Parameter_Type
(Parent
(F
)));
5209 if Parameter_Mode
(F
) /= E_In_Parameter
then
5212 ("wrong mode for Put_Image procedure''s second parameter",
5219 if Present
(Next_Formal
(F
)) then
5224 end Has_Good_Profile
;
5226 -- Start of processing for Analyze_Put_Image_TSS_Definition
5229 if not Is_Type
(U_Ent
) then
5230 Error_Msg_N
("local name must be a subtype", Nam
);
5233 elsif not Is_First_Subtype
(U_Ent
) then
5234 Error_Msg_N
("local name must be a first subtype", Nam
);
5238 Pnam
:= TSS
(Base_Type
(U_Ent
), TSS_Put_Image
);
5240 -- If Pnam is present, it can be either inherited from an ancestor
5241 -- type (in which case it is legal to redefine it for this type), or
5242 -- be a previous definition of the attribute for the same type (in
5243 -- which case it is illegal).
5245 -- In the first case, it will have been analyzed already, and we can
5246 -- check that its profile does not match the expected profile for the
5247 -- Put_Image attribute of U_Ent. In the second case, either Pnam has
5248 -- been analyzed (and has the expected profile), or it has not been
5249 -- analyzed yet (case of a type that has not been frozen yet and for
5250 -- which Put_Image has been set using Set_TSS).
5253 and then (No
(First_Entity
(Pnam
)) or else Has_Good_Profile
(Pnam
))
5255 Error_Msg_Sloc
:= Sloc
(Pnam
);
5256 Error_Msg_Name_1
:= Attr
;
5257 Error_Msg_N
("% attribute already defined #", Nam
);
5263 if Is_Entity_Name
(Expr
) then
5264 if not Is_Overloaded
(Expr
) then
5265 if Has_Good_Profile
(Entity
(Expr
), Report
=> True) then
5266 Subp
:= Entity
(Expr
);
5270 Get_First_Interp
(Expr
, I
, It
);
5271 while Present
(It
.Nam
) loop
5272 if Has_Good_Profile
(It
.Nam
) then
5277 Get_Next_Interp
(I
, It
);
5282 if Present
(Subp
) then
5283 if Is_Abstract_Subprogram
(Subp
) then
5284 Error_Msg_N
("Put_Image subprogram must not be abstract", Expr
);
5288 Set_Entity
(Expr
, Subp
);
5289 Set_Etype
(Expr
, Etype
(Subp
));
5291 New_Put_Image_Subprogram
(N
, U_Ent
, Subp
);
5294 Error_Msg_Name_1
:= Attr
;
5295 Error_Msg_N
("incorrect expression for% attribute", Expr
);
5297 end Analyze_Put_Image_TSS_Definition
;
5299 -----------------------------------
5300 -- Analyze_Stream_TSS_Definition --
5301 -----------------------------------
5303 procedure Analyze_Stream_TSS_Definition
(TSS_Nam
: TSS_Name_Type
) is
5304 Subp
: Entity_Id
:= Empty
;
5309 Is_Read
: constant Boolean := (TSS_Nam
= TSS_Stream_Read
);
5310 -- True for Read attribute, False for other attributes
5312 function Has_Good_Profile
5314 Report
: Boolean := False) return Boolean;
5315 -- Return true if the entity is a subprogram with an appropriate
5316 -- profile for the attribute being defined. If result is False and
5317 -- Report is True, function emits appropriate error.
5319 ----------------------
5320 -- Has_Good_Profile --
5321 ----------------------
5323 function Has_Good_Profile
5325 Report
: Boolean := False) return Boolean
5327 Expected_Ekind
: constant array (Boolean) of Entity_Kind
:=
5328 (False => E_Procedure
, True => E_Function
);
5329 Is_Function
: constant Boolean := (TSS_Nam
= TSS_Stream_Input
);
5334 if Ekind
(Subp
) /= Expected_Ekind
(Is_Function
) then
5338 F
:= First_Formal
(Subp
);
5341 or else Ekind
(Etype
(F
)) /= E_Anonymous_Access_Type
5342 or else Base_Type
(Designated_Type
(Etype
(F
))) /=
5343 Class_Wide_Type
(RTE
(RE_Root_Stream_Type
))
5348 if not Is_Function
then
5352 Expected_Mode
: constant array (Boolean) of Entity_Kind
:=
5353 (False => E_In_Parameter
,
5354 True => E_Out_Parameter
);
5356 if Parameter_Mode
(F
) /= Expected_Mode
(Is_Read
) then
5364 Typ
:= Etype
(Subp
);
5367 -- Verify that the prefix of the attribute and the local name for
5368 -- the type of the formal match.
5370 if Base_Type
(Typ
) /= Base_Type
(Ent
) then
5374 if Present
(Next_Formal
(F
)) then
5377 elsif not Is_Scalar_Type
(Typ
)
5378 and then not Is_First_Subtype
(Typ
)
5379 and then not Is_Class_Wide_Type
(Typ
)
5381 if Report
and not Is_First_Subtype
(Typ
) then
5383 ("subtype of formal in stream operation must be a first "
5384 & "subtype", Parameter_Type
(Parent
(F
)));
5392 end Has_Good_Profile
;
5394 -- Start of processing for Analyze_Stream_TSS_Definition
5399 if not Is_Type
(U_Ent
) then
5400 Error_Msg_N
("local name must be a subtype", Nam
);
5403 elsif not Is_First_Subtype
(U_Ent
) then
5404 Error_Msg_N
("local name must be a first subtype", Nam
);
5408 Pnam
:= TSS
(Base_Type
(U_Ent
), TSS_Nam
);
5410 -- If Pnam is present, it can be either inherited from an ancestor
5411 -- type (in which case it is legal to redefine it for this type), or
5412 -- be a previous definition of the attribute for the same type (in
5413 -- which case it is illegal).
5415 -- In the first case, it will have been analyzed already, and we
5416 -- can check that its profile does not match the expected profile
5417 -- for a stream attribute of U_Ent. In the second case, either Pnam
5418 -- has been analyzed (and has the expected profile), or it has not
5419 -- been analyzed yet (case of a type that has not been frozen yet
5420 -- and for which the stream attribute has been set using Set_TSS).
5423 and then (No
(First_Entity
(Pnam
)) or else Has_Good_Profile
(Pnam
))
5425 Error_Msg_Sloc
:= Sloc
(Pnam
);
5426 Error_Msg_Name_1
:= Attr
;
5427 Error_Msg_N
("% attribute already defined #", Nam
);
5433 if Is_Entity_Name
(Expr
) then
5434 if not Is_Overloaded
(Expr
) then
5435 if Has_Good_Profile
(Entity
(Expr
), Report
=> True) then
5436 Subp
:= Entity
(Expr
);
5440 Get_First_Interp
(Expr
, I
, It
);
5441 while Present
(It
.Nam
) loop
5442 if Has_Good_Profile
(It
.Nam
) then
5447 Get_Next_Interp
(I
, It
);
5452 if Present
(Subp
) then
5453 if Is_Abstract_Subprogram
(Subp
) then
5454 Error_Msg_N
("stream subprogram must not be abstract", Expr
);
5457 -- A stream subprogram for an interface type must be a null
5458 -- procedure (RM 13.13.2 (38/3)). Note that the class-wide type
5459 -- of an interface is not an interface type (3.9.4 (6.b/2)).
5461 elsif Is_Interface
(U_Ent
)
5462 and then not Is_Class_Wide_Type
(U_Ent
)
5463 and then not Inside_A_Generic
5465 (Ekind
(Subp
) = E_Function
5469 (Unit_Declaration_Node
(Ultimate_Alias
(Subp
)))))
5472 ("stream subprogram for interface type must be null "
5473 & "procedure", Expr
);
5476 Set_Entity
(Expr
, Subp
);
5477 Set_Etype
(Expr
, Etype
(Subp
));
5479 New_Stream_Subprogram
(N
, U_Ent
, Subp
, TSS_Nam
);
5482 Error_Msg_Name_1
:= Attr
;
5484 if Is_Class_Wide_Type
(Base_Type
(Ent
)) then
5486 ("incorrect expression for class-wide% attribute", Expr
);
5488 Error_Msg_N
("incorrect expression for% attribute", Expr
);
5491 end Analyze_Stream_TSS_Definition
;
5493 ------------------------------
5494 -- Check_Indexing_Functions --
5495 ------------------------------
5497 procedure Check_Indexing_Functions
is
5498 Indexing_Found
: Boolean := False;
5500 procedure Check_Inherited_Indexing
;
5501 -- For a derived type, check that for a derived type, a specification
5502 -- of an indexing aspect can only be confirming, i.e. uses the same
5503 -- name as in the parent type.
5504 -- AI12-0160: Verify that an indexing cannot be specified for
5505 -- a derived type unless it is specified for the parent.
5507 procedure Check_One_Function
(Subp
: Entity_Id
);
5508 -- Check one possible interpretation. Sets Indexing_Found True if a
5509 -- legal indexing function is found.
5511 procedure Illegal_Indexing
(Msg
: String);
5512 -- Diagnose illegal indexing function if not overloaded. In the
5513 -- overloaded case indicate that no legal interpretation exists.
5515 ------------------------------
5516 -- Check_Inherited_Indexing --
5517 ------------------------------
5519 procedure Check_Inherited_Indexing
is
5520 Inherited
: Node_Id
;
5521 Other_Indexing
: Node_Id
;
5524 if Attr
= Name_Constant_Indexing
then
5526 Find_Aspect
(Etype
(Ent
), Aspect_Constant_Indexing
);
5528 Find_Aspect
(Etype
(Ent
), Aspect_Variable_Indexing
);
5530 else pragma Assert
(Attr
= Name_Variable_Indexing
);
5532 Find_Aspect
(Etype
(Ent
), Aspect_Variable_Indexing
);
5534 Find_Aspect
(Etype
(Ent
), Aspect_Constant_Indexing
);
5537 if Present
(Inherited
) then
5538 if Debug_Flag_Dot_XX
then
5541 -- OK if current attribute_definition_clause is expansion of
5542 -- inherited aspect.
5544 elsif Aspect_Rep_Item
(Inherited
) = N
then
5547 -- Check if this is a confirming specification. The name
5548 -- may be overloaded between the parent operation and the
5549 -- inherited one, so we check that the Chars fields match.
5551 elsif Is_Entity_Name
(Expression
(Inherited
))
5552 and then Chars
(Entity
(Expression
(Inherited
))) =
5553 Chars
(Entity
(Expression
(N
)))
5555 Indexing_Found
:= True;
5557 -- Indicate the operation that must be overridden, rather than
5558 -- redefining the indexing aspect.
5562 ("indexing function already inherited from parent type");
5564 ("!override & instead",
5565 N
, Entity
(Expression
(Inherited
)));
5568 -- If not inherited and the parent has another indexing function
5569 -- this is illegal, because it leads to inconsistent results in
5570 -- class-wide calls.
5572 elsif Present
(Other_Indexing
) then
5574 ("cannot specify indexing operation on derived type"
5575 & " if not specified for parent", N
);
5577 end Check_Inherited_Indexing
;
5579 ------------------------
5580 -- Check_One_Function --
5581 ------------------------
5583 procedure Check_One_Function
(Subp
: Entity_Id
) is
5584 Default_Element
: Node_Id
;
5585 Ret_Type
: constant Entity_Id
:= Etype
(Subp
);
5588 if not Is_Overloadable
(Subp
) then
5589 Illegal_Indexing
("illegal indexing function for type&");
5592 elsif Scope
(Subp
) /= Scope
(Ent
) then
5593 if Nkind
(Expr
) = N_Expanded_Name
then
5595 -- Indexing function can't be declared elsewhere
5598 ("indexing function must be declared"
5599 & " in scope of type&");
5602 if Is_Derived_Type
(Ent
) then
5603 Check_Inherited_Indexing
;
5608 elsif No
(First_Formal
(Subp
)) then
5610 ("Indexing requires a function that applies to type&");
5613 elsif No
(Next_Formal
(First_Formal
(Subp
))) then
5615 ("indexing function must have at least two parameters");
5618 elsif Is_Derived_Type
(Ent
) then
5619 Check_Inherited_Indexing
;
5622 if not Check_Primitive_Function
(Subp
) then
5624 ("Indexing aspect requires a function that applies to type&");
5628 -- If partial declaration exists, verify that it is not tagged.
5630 if Ekind
(Current_Scope
) = E_Package
5631 and then Has_Private_Declaration
(Ent
)
5632 and then From_Aspect_Specification
(N
)
5634 List_Containing
(Parent
(Ent
)) =
5635 Private_Declarations
5636 (Specification
(Unit_Declaration_Node
(Current_Scope
)))
5637 and then Nkind
(N
) = N_Attribute_Definition_Clause
5644 First
(Visible_Declarations
5646 (Unit_Declaration_Node
(Current_Scope
))));
5648 while Present
(Decl
) loop
5649 if Nkind
(Decl
) = N_Private_Type_Declaration
5650 and then Ent
= Full_View
(Defining_Identifier
(Decl
))
5651 and then Tagged_Present
(Decl
)
5652 and then No
(Aspect_Specifications
(Decl
))
5655 ("Indexing aspect cannot be specified on full view "
5656 & "if partial view is tagged");
5665 -- An indexing function must return either the default element of
5666 -- the container, or a reference type. For variable indexing it
5667 -- must be the latter.
5670 Find_Value_Of_Aspect
5671 (Etype
(First_Formal
(Subp
)), Aspect_Iterator_Element
);
5673 if Present
(Default_Element
) then
5674 Analyze
(Default_Element
);
5677 -- For variable_indexing the return type must be a reference type
5679 if Attr
= Name_Variable_Indexing
then
5680 if not Has_Implicit_Dereference
(Ret_Type
) then
5682 ("variable indexing must return a reference type");
5685 elsif Is_Access_Constant
5686 (Etype
(First_Discriminant
(Ret_Type
)))
5689 ("variable indexing must return an access to variable");
5694 if Has_Implicit_Dereference
(Ret_Type
)
5697 (Etype
(Get_Reference_Discriminant
(Ret_Type
)))
5700 ("constant indexing must return an access to constant");
5703 elsif Is_Access_Type
(Etype
(First_Formal
(Subp
)))
5704 and then not Is_Access_Constant
(Etype
(First_Formal
(Subp
)))
5707 ("constant indexing must apply to an access to constant");
5712 -- All checks succeeded
5714 Indexing_Found
:= True;
5715 end Check_One_Function
;
5717 -----------------------
5718 -- Illegal_Indexing --
5719 -----------------------
5721 procedure Illegal_Indexing
(Msg
: String) is
5723 Error_Msg_NE
(Msg
, N
, Ent
);
5724 end Illegal_Indexing
;
5726 -- Start of processing for Check_Indexing_Functions
5730 Check_Inherited_Indexing
;
5735 if not Is_Overloaded
(Expr
) then
5736 Check_One_Function
(Entity
(Expr
));
5744 Indexing_Found
:= False;
5745 Get_First_Interp
(Expr
, I
, It
);
5746 while Present
(It
.Nam
) loop
5748 -- Note that analysis will have added the interpretation
5749 -- that corresponds to the dereference. We only check the
5750 -- subprogram itself. Ignore homonyms that may come from
5751 -- derived types in the context.
5753 if Is_Overloadable
(It
.Nam
)
5754 and then Comes_From_Source
(It
.Nam
)
5756 Check_One_Function
(It
.Nam
);
5759 Get_Next_Interp
(I
, It
);
5764 if not Indexing_Found
and then not Error_Posted
(N
) then
5766 ("aspect Indexing requires a local function that applies to "
5767 & "type&", Expr
, Ent
);
5769 end Check_Indexing_Functions
;
5771 ------------------------------
5772 -- Check_Iterator_Functions --
5773 ------------------------------
5775 procedure Check_Iterator_Functions
is
5776 function Valid_Default_Iterator
(Subp
: Entity_Id
) return Boolean;
5777 -- Check one possible interpretation for validity
5779 ----------------------------
5780 -- Valid_Default_Iterator --
5781 ----------------------------
5783 function Valid_Default_Iterator
(Subp
: Entity_Id
) return Boolean is
5784 Root_T
: constant Entity_Id
:= Root_Type
(Etype
(Etype
(Subp
)));
5788 if not Check_Primitive_Function
(Subp
) then
5791 -- The return type must be derived from a type in an instance
5792 -- of Iterator.Interfaces, and thus its root type must have a
5795 elsif Chars
(Root_T
) /= Name_Forward_Iterator
5796 and then Chars
(Root_T
) /= Name_Reversible_Iterator
5801 Formal
:= First_Formal
(Subp
);
5804 -- False if any subsequent formal has no default expression
5806 Next_Formal
(Formal
);
5807 while Present
(Formal
) loop
5808 if No
(Expression
(Parent
(Formal
))) then
5812 Next_Formal
(Formal
);
5815 -- True if all subsequent formals have default expressions
5818 end Valid_Default_Iterator
;
5820 -- Start of processing for Check_Iterator_Functions
5825 if not Is_Entity_Name
(Expr
) then
5826 Error_Msg_N
("aspect Iterator must be a function name", Expr
);
5829 if not Is_Overloaded
(Expr
) then
5830 if Entity
(Expr
) /= Any_Id
5831 and then not Check_Primitive_Function
(Entity
(Expr
))
5834 ("aspect Indexing requires a function that applies to type&",
5835 Entity
(Expr
), Ent
);
5838 -- Flag the default_iterator as well as the denoted function.
5840 if not Valid_Default_Iterator
(Entity
(Expr
)) then
5841 Error_Msg_N
("improper function for default iterator!", Expr
);
5846 Default
: Entity_Id
:= Empty
;
5851 Get_First_Interp
(Expr
, I
, It
);
5852 while Present
(It
.Nam
) loop
5853 if not Check_Primitive_Function
(It
.Nam
)
5854 or else not Valid_Default_Iterator
(It
.Nam
)
5858 elsif Present
(Default
) then
5860 -- An explicit one should override an implicit one
5862 if Comes_From_Source
(Default
) =
5863 Comes_From_Source
(It
.Nam
)
5865 Error_Msg_N
("default iterator must be unique", Expr
);
5866 Error_Msg_Sloc
:= Sloc
(Default
);
5867 Error_Msg_N
("\\possible interpretation#", Expr
);
5868 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
5869 Error_Msg_N
("\\possible interpretation#", Expr
);
5871 elsif Comes_From_Source
(It
.Nam
) then
5878 Get_Next_Interp
(I
, It
);
5881 if Present
(Default
) then
5882 Set_Entity
(Expr
, Default
);
5883 Set_Is_Overloaded
(Expr
, False);
5886 ("no interpretation is a valid default iterator!", Expr
);
5890 end Check_Iterator_Functions
;
5892 -------------------------------
5893 -- Check_Primitive_Function --
5894 -------------------------------
5896 function Check_Primitive_Function
(Subp
: Entity_Id
) return Boolean is
5900 if Ekind
(Subp
) /= E_Function
then
5904 if No
(First_Formal
(Subp
)) then
5907 Ctrl
:= Etype
(First_Formal
(Subp
));
5910 -- To be a primitive operation subprogram has to be in same scope.
5912 if Scope
(Ctrl
) /= Scope
(Subp
) then
5916 -- Type of formal may be the class-wide type, an access to such,
5917 -- or an incomplete view.
5920 or else Ctrl
= Class_Wide_Type
(Ent
)
5922 (Ekind
(Ctrl
) = E_Anonymous_Access_Type
5923 and then (Designated_Type
(Ctrl
) = Ent
5925 Designated_Type
(Ctrl
) = Class_Wide_Type
(Ent
)))
5927 (Ekind
(Ctrl
) = E_Incomplete_Type
5928 and then Full_View
(Ctrl
) = Ent
)
5936 end Check_Primitive_Function
;
5938 ----------------------
5939 -- Duplicate_Clause --
5940 ----------------------
5942 function Duplicate_Clause
return Boolean is
5944 function Check_One_Attr
(Attr_1
, Attr_2
: Name_Id
) return Boolean;
5945 -- Check for one attribute; Attr_1 is the attribute_designator we are
5946 -- looking for. Attr_2 is the attribute_designator of the current
5947 -- node. Normally, this is called just once by Duplicate_Clause, with
5948 -- Attr_1 = Attr_2. However, it needs to be called twice for Size and
5949 -- Value_Size, because these mean the same thing. For compatibility,
5950 -- we allow specifying both Size and Value_Size, but only if the two
5953 --------------------
5954 -- Check_One_Attr --
5955 --------------------
5957 function Check_One_Attr
(Attr_1
, Attr_2
: Name_Id
) return Boolean is
5958 A
: constant Node_Id
:=
5959 Get_Rep_Item
(U_Ent
, Attr_1
, Check_Parents
=> False);
5962 if Attr_1
= Attr_2
then
5963 Error_Msg_Name_1
:= Attr_1
;
5964 Error_Msg_Sloc
:= Sloc
(A
);
5965 Error_Msg_NE
("aspect% for & previously given#", N
, U_Ent
);
5968 pragma Assert
(Attr_1
in Name_Size | Name_Value_Size
);
5969 pragma Assert
(Attr_2
in Name_Size | Name_Value_Size
);
5971 Error_Msg_Name_1
:= Attr_2
;
5972 Error_Msg_Name_2
:= Attr_1
;
5973 Error_Msg_Sloc
:= Sloc
(A
);
5974 Error_Msg_NE
("?% for & conflicts with % #", N
, U_Ent
);
5983 -- Start of processing for Duplicate_Clause
5986 -- Nothing to do if this attribute definition clause comes from
5987 -- an aspect specification, since we could not be duplicating an
5988 -- explicit clause, and we dealt with the case of duplicated aspects
5989 -- in Analyze_Aspect_Specifications.
5991 if From_Aspect_Specification
(N
) then
5995 -- Special cases for Size and Value_Size
5997 if (Chars
(N
) = Name_Size
5998 and then Check_One_Attr
(Name_Value_Size
, Name_Size
))
6000 (Chars
(N
) = Name_Value_Size
6001 and then Check_One_Attr
(Name_Size
, Name_Value_Size
))
6006 -- Normal case (including Size and Value_Size)
6008 return Check_One_Attr
(Chars
(N
), Chars
(N
));
6009 end Duplicate_Clause
;
6011 -- Start of processing for Analyze_Attribute_Definition_Clause
6014 -- The following code is a defense against recursion. Not clear that
6015 -- this can happen legitimately, but perhaps some error situations can
6016 -- cause it, and we did see this recursion during testing.
6018 if Analyzed
(N
) then
6021 Set_Analyzed
(N
, True);
6024 Check_Restriction_No_Use_Of_Attribute
(N
);
6026 if Is_Aspect_Id
(Chars
(N
)) then
6027 -- 6.1/3 No_Specification_of_Aspect: Identifies an aspect for which
6028 -- no aspect_specification, attribute_definition_clause, or pragma
6030 Check_Restriction_No_Specification_Of_Aspect
(N
);
6033 -- Ignore some selected attributes in CodePeer mode since they are not
6034 -- relevant in this context.
6036 if CodePeer_Mode
then
6039 -- Ignore Component_Size in CodePeer mode, to avoid changing the
6040 -- internal representation of types by implicitly packing them.
6042 when Attribute_Component_Size
=>
6043 Rewrite
(N
, Make_Null_Statement
(Sloc
(N
)));
6051 -- Process Ignore_Rep_Clauses option
6053 if Ignore_Rep_Clauses
then
6056 -- The following should be ignored. They do not affect legality
6057 -- and may be target dependent. The basic idea of -gnatI is to
6058 -- ignore any rep clauses that may be target dependent but do not
6059 -- affect legality (except possibly to be rejected because they
6060 -- are incompatible with the compilation target).
6062 when Attribute_Alignment
6063 | Attribute_Bit_Order
6064 | Attribute_Component_Size
6065 | Attribute_Default_Scalar_Storage_Order
6066 | Attribute_Machine_Radix
6067 | Attribute_Object_Size
6068 | Attribute_Scalar_Storage_Order
6071 | Attribute_Stream_Size
6072 | Attribute_Value_Size
6074 Kill_Rep_Clause
(N
);
6077 -- The following should not be ignored, because in the first place
6078 -- they are reasonably portable, and should not cause problems
6079 -- in compiling code from another target, and also they do affect
6080 -- legality, e.g. failing to provide a stream attribute for a type
6081 -- may make a program illegal.
6083 when Attribute_External_Tag
6086 | Attribute_Put_Image
6088 | Attribute_Simple_Storage_Pool
6089 | Attribute_Storage_Pool
6090 | Attribute_Storage_Size
6095 -- We do not do anything here with address clauses, they will be
6096 -- removed by Freeze later on, but for now, it works better to
6097 -- keep them in the tree.
6099 when Attribute_Address
=>
6102 -- Other cases are errors ("attribute& cannot be set with
6103 -- definition clause"), which will be caught below.
6111 Ent
:= Entity
(Nam
);
6113 if Rep_Item_Too_Early
(Ent
, N
) then
6117 -- Rep clause applies to (underlying) full view of private or incomplete
6118 -- type if we have one (if not, this is a premature use of the type).
6119 -- However, some semantic checks need to be done on the specified entity
6120 -- i.e. the private view, so we save it in Ent.
6122 if Is_Private_Type
(Ent
)
6123 and then Is_Derived_Type
(Ent
)
6124 and then not Is_Tagged_Type
(Ent
)
6125 and then No
(Full_View
(Ent
))
6126 and then No
(Underlying_Full_View
(Ent
))
6130 elsif Ekind
(Ent
) = E_Incomplete_Type
then
6132 -- The attribute applies to the full view, set the entity of the
6133 -- attribute definition accordingly.
6135 Ent
:= Underlying_Type
(Ent
);
6137 Set_Entity
(Nam
, Ent
);
6140 U_Ent
:= Underlying_Type
(Ent
);
6143 -- Avoid cascaded error
6145 if Etype
(Nam
) = Any_Type
then
6148 -- Must be declared in current scope or in case of an aspect
6149 -- specification, must be visible in current scope.
6151 elsif Scope
(Ent
) /= Current_Scope
6153 not (From_Aspect_Specification
(N
)
6154 and then Scope_Within_Or_Same
(Current_Scope
, Scope
(Ent
)))
6156 Error_Msg_N
("entity must be declared in this scope", Nam
);
6159 -- Must not be a source renaming (we do have some cases where the
6160 -- expander generates a renaming, and those cases are OK, in such
6161 -- cases any attribute applies to the renamed object as well).
6163 elsif Is_Object
(Ent
)
6164 and then Present
(Renamed_Object
(Ent
))
6166 -- In the case of a renamed object from source, this is an error
6167 -- unless the object is an aggregate and the renaming is created
6168 -- for an object declaration.
6170 if Comes_From_Source
(Renamed_Object
(Ent
))
6171 and then Nkind
(Renamed_Object
(Ent
)) /= N_Aggregate
6173 Get_Name_String
(Chars
(N
));
6174 Error_Msg_Strlen
:= Name_Len
;
6175 Error_Msg_String
(1 .. Name_Len
) := Name_Buffer
(1 .. Name_Len
);
6177 ("~ clause not allowed for a renaming declaration "
6178 & "(RM 13.1(6))", Nam
);
6181 -- For the case of a compiler generated renaming, the attribute
6182 -- definition clause applies to the renamed object created by the
6183 -- expander. The easiest general way to handle this is to create a
6184 -- copy of the attribute definition clause for this object.
6186 elsif Is_Entity_Name
(Renamed_Object
(Ent
)) then
6188 Make_Attribute_Definition_Clause
(Loc
,
6190 New_Occurrence_Of
(Entity
(Renamed_Object
(Ent
)), Loc
),
6192 Expression
=> Duplicate_Subexpr
(Expression
(N
))));
6194 -- If the renamed object is not an entity, it must be a dereference
6195 -- of an unconstrained function call, and we must introduce a new
6196 -- declaration to capture the expression. This is needed in the case
6197 -- of 'Alignment, where the original declaration must be rewritten.
6201 (Nkind
(Renamed_Object
(Ent
)) = N_Explicit_Dereference
);
6205 -- If no underlying entity, use entity itself, applies to some
6206 -- previously detected error cases ???
6208 elsif No
(U_Ent
) then
6211 -- Cannot specify for a subtype (exception Object/Value_Size)
6213 elsif Is_Type
(U_Ent
)
6214 and then not Is_First_Subtype
(U_Ent
)
6215 and then Id
/= Attribute_Object_Size
6216 and then Id
/= Attribute_Value_Size
6217 and then not From_At_Mod
(N
)
6219 Error_Msg_N
("cannot specify attribute for subtype", Nam
);
6223 Set_Entity
(N
, U_Ent
);
6225 -- Switch on particular attribute
6233 -- Address attribute definition clause
6235 when Attribute_Address
=> Address
: begin
6237 -- A little error check, catch for X'Address use X'Address;
6239 if Nkind
(Nam
) = N_Identifier
6240 and then Nkind
(Expr
) = N_Attribute_Reference
6241 and then Attribute_Name
(Expr
) = Name_Address
6242 and then Nkind
(Prefix
(Expr
)) = N_Identifier
6243 and then Chars
(Nam
) = Chars
(Prefix
(Expr
))
6246 ("address for & is self-referencing", Prefix
(Expr
), Ent
);
6250 -- Not that special case, carry on with analysis of expression
6252 Analyze_And_Resolve
(Expr
, RTE
(RE_Address
));
6254 -- Even when ignoring rep clauses we need to indicate that the
6255 -- entity has an address clause and thus it is legal to declare
6256 -- it imported. Freeze will get rid of the address clause later.
6257 -- Also call Set_Address_Taken to indicate that an address clause
6258 -- was present, even if we are about to remove it.
6260 if Ignore_Rep_Clauses
then
6261 Set_Address_Taken
(U_Ent
);
6263 if Ekind
(U_Ent
) in E_Variable | E_Constant
then
6264 Record_Rep_Item
(U_Ent
, N
);
6270 if Duplicate_Clause
then
6273 -- Case of address clause for subprogram
6275 elsif Is_Subprogram
(U_Ent
) then
6276 if Has_Homonym
(U_Ent
) then
6278 ("address clause cannot be given for overloaded "
6279 & "subprogram", Nam
);
6283 -- For subprograms, all address clauses are permitted, and we
6284 -- mark the subprogram as having a deferred freeze so that Gigi
6285 -- will not elaborate it too soon.
6287 -- Above needs more comments, what is too soon about???
6289 Set_Has_Delayed_Freeze
(U_Ent
);
6291 -- Case of address clause for entry
6293 elsif Ekind
(U_Ent
) = E_Entry
then
6294 if Nkind
(Parent
(N
)) = N_Task_Body
then
6296 ("entry address must be specified in task spec", Nam
);
6300 -- For entries, we require a constant address
6302 Check_Constant_Address_Clause
(Expr
, U_Ent
);
6304 -- Special checks for task types
6306 if Is_Task_Type
(Scope
(U_Ent
))
6307 and then Comes_From_Source
(Scope
(U_Ent
))
6310 ("??entry address declared for entry in task type", N
);
6312 ("\??only one task can be declared of this type", N
);
6315 -- Entry address clauses are obsolescent
6317 Check_Restriction
(No_Obsolescent_Features
, N
);
6319 if Warn_On_Obsolescent_Feature
then
6321 ("?j?attaching interrupt to task entry is an obsolescent "
6322 & "feature (RM J.7.1)", N
);
6324 ("\?j?use interrupt procedure instead", N
);
6327 -- Case of address clause for an object
6329 elsif Ekind
(U_Ent
) in E_Constant | E_Variable
then
6331 -- Disallow case of an address clause for an object of an
6332 -- indefinite subtype which takes its bounds/discriminant/tag
6333 -- from its initial value. Without this, we get a Gigi
6334 -- assertion failure for things like
6335 -- X : String := Some_Function (...) with Address => ...;
6336 -- where the result subtype of the function is unconstrained.
6338 -- We want to reject two cases: the class-wide case, and the
6339 -- case where the FE conjures up a renaming declaration and
6340 -- would then otherwise generate an address specification for
6341 -- that renaming (which is a malformed tree, which is why Gigi
6344 if Is_Class_Wide_Type
(Etype
(U_Ent
)) then
6346 ("address specification not supported for class-wide " &
6347 "object declaration", Nam
);
6349 elsif Is_Constr_Subt_For_U_Nominal
(Etype
(U_Ent
))
6351 Nkind
(Parent
(U_Ent
)) = N_Object_Renaming_Declaration
6353 -- Confirm accuracy of " and dynamic size" message text
6354 -- before including it. We want to include that text when
6355 -- it is correct because it may be useful to the reader.
6356 -- The case where we omit that part of the message text
6357 -- might be dead code, but let's not rely on that.
6360 ("address specification not supported for object " &
6361 "declaration with indefinite nominal subtype" &
6362 (if Size_Known_At_Compile_Time
(Etype
(U_Ent
))
6364 else " and dynamic size"), Nam
);
6369 Expr
: constant Node_Id
:= Expression
(N
);
6374 -- Exported variables cannot have an address clause, because
6375 -- this cancels the effect of the pragma Export.
6377 if Is_Exported
(U_Ent
) then
6379 ("cannot export object with address clause", Nam
);
6383 Find_Overlaid_Entity
(N
, O_Ent
, Off
);
6385 if Present
(O_Ent
) then
6387 -- If the object overlays a constant object, mark it so
6389 if Is_Constant_Object
(O_Ent
) then
6390 Set_Overlays_Constant
(U_Ent
);
6393 -- If the address clause is of the form:
6395 -- for X'Address use Y'Address;
6399 -- C : constant Address := Y'Address;
6401 -- for X'Address use C;
6403 -- then we make an entry in the table to check the size
6404 -- and alignment of the overlaying variable. But we defer
6405 -- this check till after code generation to take full
6406 -- advantage of the annotation done by the back end.
6408 -- If the entity has a generic type, the check will be
6409 -- performed in the instance if the actual type justifies
6410 -- it, and we do not insert the clause in the table to
6411 -- prevent spurious warnings.
6413 -- Note: we used to test Comes_From_Source and only give
6414 -- this warning for source entities, but we have removed
6415 -- this test. It really seems bogus to generate overlays
6416 -- that would trigger this warning in generated code.
6417 -- Furthermore, by removing the test, we handle the
6418 -- aspect case properly.
6420 if Is_Object
(O_Ent
)
6421 and then not Is_Generic_Formal
(O_Ent
)
6422 and then not Is_Generic_Type
(Etype
(U_Ent
))
6423 and then Address_Clause_Overlay_Warnings
6425 Register_Address_Clause_Check
6426 (N
, U_Ent
, No_Uint
, O_Ent
, Off
);
6429 -- If the overlay changes the storage order, warn since
6430 -- the construct is not really supported by the back end.
6431 -- Also mark the entity as being volatile to block the
6432 -- optimizer, even if there is no warranty on the result.
6434 if (Is_Record_Type
(Etype
(U_Ent
))
6435 or else Is_Array_Type
(Etype
(U_Ent
)))
6436 and then (Is_Record_Type
(Etype
(O_Ent
))
6437 or else Is_Array_Type
(Etype
(O_Ent
)))
6438 and then Reverse_Storage_Order
(Etype
(U_Ent
)) /=
6439 Reverse_Storage_Order
(Etype
(O_Ent
))
6442 ("??overlay changes scalar storage order", Expr
);
6443 Set_Treat_As_Volatile
(U_Ent
);
6447 -- If this is not an overlay, mark a variable as being
6448 -- volatile to prevent unwanted optimizations. It's a
6449 -- conservative interpretation of RM 13.3(19) for the
6450 -- cases where the compiler cannot detect potential
6451 -- aliasing issues easily and it also covers the case
6452 -- of an absolute address where the volatile aspect is
6453 -- kind of implicit.
6455 if Ekind
(U_Ent
) = E_Variable
then
6456 Set_Treat_As_Volatile
(U_Ent
);
6459 -- Make an entry in the table for an absolute address as
6460 -- above to check that the value is compatible with the
6461 -- alignment of the object.
6464 Addr
: constant Node_Id
:= Address_Value
(Expr
);
6466 if Compile_Time_Known_Value
(Addr
)
6467 and then Address_Clause_Overlay_Warnings
6469 Register_Address_Clause_Check
6470 (N
, U_Ent
, Expr_Value
(Addr
), Empty
, False);
6475 -- Issue an unconditional warning for a constant overlaying
6476 -- a variable. For the reverse case, we will issue it only
6477 -- if the variable is modified.
6478 -- Within a generic unit an In_Parameter is a constant.
6479 -- It can be instantiated with a variable, in which case
6480 -- there will be a warning on the instance.
6482 if Ekind
(U_Ent
) = E_Constant
6483 and then Present
(O_Ent
)
6484 and then Ekind
(O_Ent
) /= E_Generic_In_Parameter
6485 and then not Overlays_Constant
(U_Ent
)
6486 and then Address_Clause_Overlay_Warnings
6488 Error_Msg_N
("?o?constant overlays a variable", Expr
);
6490 -- Imported variables can have an address clause, but then
6491 -- the import is pretty meaningless except to suppress
6492 -- initializations, so we do not need such variables to
6493 -- be statically allocated (and in fact it causes trouble
6494 -- if the address clause is a local value).
6496 elsif Is_Imported
(U_Ent
) then
6497 Set_Is_Statically_Allocated
(U_Ent
, False);
6500 -- We mark a possible modification of a variable with an
6501 -- address clause, since it is likely aliasing is occurring.
6503 Note_Possible_Modification
(Nam
, Sure
=> False);
6505 -- Legality checks on the address clause for initialized
6506 -- objects is deferred until the freeze point, because
6507 -- a subsequent pragma might indicate that the object
6508 -- is imported and thus not initialized. Also, the address
6509 -- clause might involve entities that have yet to be
6512 Set_Has_Delayed_Freeze
(U_Ent
);
6514 -- If an initialization call has been generated for this
6515 -- object, it needs to be deferred to after the freeze node
6516 -- we have just now added, otherwise GIGI will see a
6517 -- reference to the variable (as actual to the IP call)
6518 -- before its definition.
6521 Init_Call
: constant Node_Id
:=
6522 Remove_Init_Call
(U_Ent
, N
);
6525 if Present
(Init_Call
) then
6526 Append_Freeze_Action
(U_Ent
, Init_Call
);
6528 -- Reset Initialization_Statements pointer so that
6529 -- if there is a pragma Import further down, it can
6530 -- clear any default initialization.
6532 Set_Initialization_Statements
(U_Ent
, Init_Call
);
6536 -- Entity has delayed freeze, so we will generate an
6537 -- alignment check at the freeze point unless suppressed.
6539 if not Range_Checks_Suppressed
(U_Ent
)
6540 and then not Alignment_Checks_Suppressed
(U_Ent
)
6542 Set_Check_Address_Alignment
(N
);
6545 -- Kill the size check code, since we are not allocating
6546 -- the variable, it is somewhere else.
6548 Kill_Size_Check_Code
(U_Ent
);
6551 -- Not a valid entity for an address clause
6554 Error_Msg_N
("address cannot be given for &", Nam
);
6562 -- Alignment attribute definition clause
6564 when Attribute_Alignment
=> Alignment
: declare
6565 Align
: constant Uint
:= Get_Alignment_Value
(Expr
);
6566 Max_Align
: constant Uint
:= UI_From_Int
(Maximum_Alignment
);
6571 if not Is_Type
(U_Ent
)
6572 and then Ekind
(U_Ent
) /= E_Variable
6573 and then Ekind
(U_Ent
) /= E_Constant
6575 Error_Msg_N
("alignment cannot be given for &", Nam
);
6577 elsif Duplicate_Clause
then
6580 elsif Present
(Align
) then
6581 Set_Has_Alignment_Clause
(U_Ent
);
6583 -- Tagged type case, check for attempt to set alignment to a
6584 -- value greater than Max_Align, and reset if so.
6586 if Is_Tagged_Type
(U_Ent
) and then Align
> Max_Align
then
6588 ("alignment for & set to Maximum_Aligment??", Nam
);
6589 Set_Alignment
(U_Ent
, Max_Align
);
6594 Set_Alignment
(U_Ent
, Align
);
6597 -- For an array type, U_Ent is the first subtype. In that case,
6598 -- also set the alignment of the anonymous base type so that
6599 -- other subtypes (such as the itypes for aggregates of the
6600 -- type) also receive the expected alignment.
6602 if Is_Array_Type
(U_Ent
) then
6603 Set_Alignment
(Base_Type
(U_Ent
), Align
);
6612 -- Bit_Order attribute definition clause
6614 when Attribute_Bit_Order
=>
6615 if not Is_Record_Type
(U_Ent
) then
6617 ("Bit_Order can only be defined for record type", Nam
);
6619 elsif Is_Tagged_Type
(U_Ent
) and then Is_Derived_Type
(U_Ent
) then
6621 ("Bit_Order cannot be defined for record extensions", Nam
);
6623 elsif Duplicate_Clause
then
6627 Analyze_And_Resolve
(Expr
, RTE
(RE_Bit_Order
));
6629 if Etype
(Expr
) = Any_Type
then
6632 elsif not Is_OK_Static_Expression
(Expr
) then
6633 Flag_Non_Static_Expr
6634 ("Bit_Order requires static expression!", Expr
);
6636 elsif (Expr_Value
(Expr
) = 0) /= Bytes_Big_Endian
then
6637 Set_Reverse_Bit_Order
(Base_Type
(U_Ent
), True);
6641 --------------------
6642 -- Component_Size --
6643 --------------------
6645 -- Component_Size attribute definition clause
6647 when Attribute_Component_Size
=> Component_Size_Case
: declare
6648 Csize
: constant Uint
:= Static_Integer
(Expr
);
6652 New_Ctyp
: Entity_Id
;
6656 if not Is_Array_Type
(U_Ent
) then
6657 Error_Msg_N
("component size requires array type", Nam
);
6661 Btype
:= Base_Type
(U_Ent
);
6662 Ctyp
:= Component_Type
(Btype
);
6664 if Duplicate_Clause
then
6667 elsif Rep_Item_Too_Early
(Btype
, N
) then
6670 elsif Present
(Csize
) then
6671 Check_Size
(Expr
, Ctyp
, Csize
, Biased
);
6673 -- For the biased case, build a declaration for a subtype that
6674 -- will be used to represent the biased subtype that reflects
6675 -- the biased representation of components. We need the subtype
6676 -- to get proper conversions on referencing elements of the
6681 Make_Defining_Identifier
(Loc
,
6683 New_External_Name
(Chars
(U_Ent
), 'C', 0, 'T'));
6686 Make_Subtype_Declaration
(Loc
,
6687 Defining_Identifier
=> New_Ctyp
,
6688 Subtype_Indication
=>
6689 New_Occurrence_Of
(Component_Type
(Btype
), Loc
));
6691 Set_Parent
(Decl
, N
);
6692 Analyze
(Decl
, Suppress
=> All_Checks
);
6694 Set_Has_Delayed_Freeze
(New_Ctyp
, False);
6695 Reinit_Esize
(New_Ctyp
);
6696 Set_RM_Size
(New_Ctyp
, Csize
);
6697 Reinit_Alignment
(New_Ctyp
);
6698 Set_Is_Itype
(New_Ctyp
, True);
6699 Set_Associated_Node_For_Itype
(New_Ctyp
, U_Ent
);
6701 Set_Component_Type
(Btype
, New_Ctyp
);
6702 Set_Biased
(New_Ctyp
, N
, "component size clause");
6705 Set_Component_Size
(Btype
, Csize
);
6707 -- Deal with warning on overridden size
6709 if Warn_On_Overridden_Size
6710 and then Has_Size_Clause
(Ctyp
)
6711 and then RM_Size
(Ctyp
) /= Csize
6714 ("component size overrides size clause for&?.s?", N
, Ctyp
);
6717 Set_Has_Component_Size_Clause
(Btype
, True);
6718 Set_Has_Non_Standard_Rep
(Btype
, True);
6720 end Component_Size_Case
;
6722 -----------------------
6723 -- Constant_Indexing --
6724 -----------------------
6726 when Attribute_Constant_Indexing
=>
6727 Check_Indexing_Functions
;
6733 when Attribute_CPU
=>
6734 pragma Assert
(From_Aspect_Specification
(N
));
6735 -- The parser forbids this clause in source code, so it must have
6736 -- come from an aspect specification.
6738 if not Is_Task_Type
(U_Ent
) then
6739 Error_Msg_N
("'C'P'U can only be defined for task", Nam
);
6741 elsif Duplicate_Clause
then
6745 -- The expression must be analyzed in the special manner
6746 -- described in "Handling of Default and Per-Object
6747 -- Expressions" in sem.ads.
6749 -- The visibility to the components must be established
6750 -- and restored before and after analysis.
6753 Preanalyze_Spec_Expression
(Expr
, RTE
(RE_CPU_Range
));
6756 -- AI12-0117-1, "Restriction No_Tasks_Unassigned_To_CPU":
6757 -- If the expression is static, and its value is
6758 -- System.Multiprocessors.Not_A_Specific_CPU (i.e. zero) then
6759 -- that's a violation of No_Tasks_Unassigned_To_CPU. It might
6760 -- seem better to refer to Not_A_Specific_CPU here, but that
6761 -- involves a lot of horsing around with Rtsfind, and this
6762 -- value is not going to change, so it's better to hardwire
6765 -- AI12-0055-1, "All properties of a usage profile are defined
6766 -- by pragmas": If the expression is nonstatic, that's a
6767 -- violation of No_Dynamic_CPU_Assignment.
6769 if Is_OK_Static_Expression
(Expr
) then
6770 if Expr_Value
(Expr
) = Uint_0
then
6771 Check_Restriction
(No_Tasks_Unassigned_To_CPU
, Expr
);
6774 Check_Restriction
(No_Dynamic_CPU_Assignment
, Expr
);
6778 ----------------------
6779 -- Default_Iterator --
6780 ----------------------
6782 when Attribute_Default_Iterator
=> Default_Iterator
: declare
6787 -- If target type is untagged, further checks are irrelevant
6789 if not Is_Tagged_Type
(U_Ent
) then
6791 ("aspect Default_Iterator applies to tagged type", Nam
);
6795 Check_Iterator_Functions
;
6799 if not Is_Entity_Name
(Expr
)
6800 or else Ekind
(Entity
(Expr
)) /= E_Function
6802 Error_Msg_N
("aspect Iterator must be a function", Expr
);
6805 Func
:= Entity
(Expr
);
6808 -- The type of the first parameter must be T, T'class, or a
6809 -- corresponding access type (5.5.1 (8/3). If function is
6810 -- parameterless label type accordingly.
6812 if No
(First_Formal
(Func
)) then
6815 Typ
:= Etype
(First_Formal
(Func
));
6819 or else Typ
= Class_Wide_Type
(U_Ent
)
6820 or else (Is_Access_Type
(Typ
)
6821 and then Designated_Type
(Typ
) = U_Ent
)
6822 or else (Is_Access_Type
(Typ
)
6823 and then Designated_Type
(Typ
) =
6824 Class_Wide_Type
(U_Ent
))
6830 ("Default_Iterator must be a primitive of&", Func
, U_Ent
);
6832 end Default_Iterator
;
6834 ------------------------
6835 -- Dispatching_Domain --
6836 ------------------------
6838 when Attribute_Dispatching_Domain
=>
6839 pragma Assert
(From_Aspect_Specification
(N
));
6840 -- The parser forbids this clause in source code, so it must have
6841 -- come from an aspect specification.
6843 if not Is_Task_Type
(U_Ent
) then
6845 ("Dispatching_Domain can only be defined for task", Nam
);
6847 elsif Duplicate_Clause
then
6851 -- The expression must be analyzed in the special manner
6852 -- described in "Handling of Default and Per-Object
6853 -- Expressions" in sem.ads.
6855 -- The visibility to the components must be restored
6859 Preanalyze_Spec_Expression
6860 (Expr
, RTE
(RE_Dispatching_Domain
));
6869 when Attribute_External_Tag
=>
6870 if not Is_Tagged_Type
(U_Ent
) then
6871 Error_Msg_N
("should be a tagged type", Nam
);
6874 if Duplicate_Clause
then
6878 Analyze_And_Resolve
(Expr
, Standard_String
);
6880 if not Is_OK_Static_Expression
(Expr
) then
6881 Flag_Non_Static_Expr
6882 ("static string required for tag name!", Nam
);
6885 if not Is_Library_Level_Entity
(U_Ent
) then
6887 ("??non-unique external tag supplied for &", N
, U_Ent
);
6889 ("\??same external tag applies to all subprogram calls",
6892 ("\??corresponding internal tag cannot be obtained", N
);
6896 --------------------------
6897 -- Implicit_Dereference --
6898 --------------------------
6900 when Attribute_Implicit_Dereference
=>
6902 -- Legality checks already performed at the point of the type
6903 -- declaration, aspect is not delayed.
6911 when Attribute_Input
=>
6912 Analyze_Stream_TSS_Definition
(TSS_Stream_Input
);
6913 Set_Has_Specified_Stream_Input
(Ent
);
6915 ------------------------
6916 -- Interrupt_Priority --
6917 ------------------------
6919 when Attribute_Interrupt_Priority
=>
6920 pragma Assert
(From_Aspect_Specification
(N
));
6921 -- The parser forbids this clause in source code, so it must have
6922 -- come from an aspect specification.
6924 if not Is_Concurrent_Type
(U_Ent
) then
6926 ("Interrupt_Priority can only be defined for task and "
6927 & "protected object", Nam
);
6929 elsif Duplicate_Clause
then
6933 -- The expression must be analyzed in the special manner
6934 -- described in "Handling of Default and Per-Object
6935 -- Expressions" in sem.ads.
6937 -- The visibility to the components must be restored
6941 Preanalyze_Spec_Expression
6942 (Expr
, RTE
(RE_Interrupt_Priority
));
6946 -- Check the No_Task_At_Interrupt_Priority restriction
6948 if Is_Task_Type
(U_Ent
) then
6949 Check_Restriction
(No_Task_At_Interrupt_Priority
, N
);
6957 when Attribute_Iterable
=>
6960 if Nkind
(Expr
) /= N_Aggregate
then
6961 Error_Msg_N
("aspect Iterable must be an aggregate", Expr
);
6969 Assoc
:= First
(Component_Associations
(Expr
));
6970 while Present
(Assoc
) loop
6971 Analyze
(Expression
(Assoc
));
6973 if not Is_Entity_Name
(Expression
(Assoc
))
6974 or else Ekind
(Entity
(Expression
(Assoc
))) /= E_Function
6976 Error_Msg_N
("value must be a function", Assoc
);
6983 ----------------------
6984 -- Iterator_Element --
6985 ----------------------
6987 when Attribute_Iterator_Element
=>
6990 if not Is_Entity_Name
(Expr
)
6991 or else not Is_Type
(Entity
(Expr
))
6993 Error_Msg_N
("aspect Iterator_Element must be a type", Expr
);
7001 -- Machine radix attribute definition clause
7003 when Attribute_Machine_Radix
=> Machine_Radix
: declare
7004 Radix
: constant Uint
:= Static_Integer
(Expr
);
7007 if not Is_Decimal_Fixed_Point_Type
(U_Ent
) then
7008 Error_Msg_N
("decimal fixed-point type expected for &", Nam
);
7010 elsif Duplicate_Clause
then
7013 elsif Present
(Radix
) then
7014 Set_Has_Machine_Radix_Clause
(U_Ent
);
7015 Set_Has_Non_Standard_Rep
(Base_Type
(U_Ent
));
7020 elsif Radix
= 10 then
7021 Set_Machine_Radix_10
(U_Ent
);
7024 Error_Msg_N
("machine radix value must be 2 or 10", Expr
);
7033 -- Object_Size attribute definition clause
7035 when Attribute_Object_Size
=> Object_Size
: declare
7036 Size
: constant Uint
:= Static_Integer
(Expr
);
7039 pragma Warnings
(Off
, Biased
);
7042 if not Is_Type
(U_Ent
) then
7043 Error_Msg_N
("Object_Size cannot be given for &", Nam
);
7045 elsif Duplicate_Clause
then
7049 Check_Size
(Expr
, U_Ent
, Size
, Biased
);
7051 if No
(Size
) or else Size
<= 0 then
7052 Error_Msg_N
("Object_Size must be positive", Expr
);
7054 elsif Is_Scalar_Type
(U_Ent
) then
7055 if Size
/= 8 and then Size
/= 16 and then Size
/= 32
7056 and then UI_Mod
(Size
, 64) /= 0
7059 ("Object_Size must be 8, 16, 32, or multiple of 64",
7063 elsif Size
mod 8 /= 0 then
7064 Error_Msg_N
("Object_Size must be a multiple of 8", Expr
);
7067 Set_Esize
(U_Ent
, Size
);
7068 Set_Has_Object_Size_Clause
(U_Ent
);
7069 Alignment_Check_For_Size_Change
(U_Ent
, Size
);
7077 when Attribute_Output
=>
7078 Analyze_Stream_TSS_Definition
(TSS_Stream_Output
);
7079 Set_Has_Specified_Stream_Output
(Ent
);
7085 when Attribute_Priority
=>
7087 -- Priority attribute definition clause not allowed except from
7088 -- aspect specification.
7090 if From_Aspect_Specification
(N
) then
7091 if not (Is_Concurrent_Type
(U_Ent
)
7092 or else Ekind
(U_Ent
) = E_Procedure
)
7095 ("Priority can only be defined for task and protected "
7098 elsif Duplicate_Clause
then
7102 -- The expression must be analyzed in the special manner
7103 -- described in "Handling of Default and Per-Object
7104 -- Expressions" in sem.ads.
7106 -- The visibility to the components must be restored
7109 Preanalyze_Spec_Expression
(Expr
, Standard_Integer
);
7112 if not Is_OK_Static_Expression
(Expr
) then
7113 Check_Restriction
(Static_Priorities
, Expr
);
7119 ("attribute& cannot be set with definition clause", N
);
7126 when Attribute_Put_Image
=>
7127 Analyze_Put_Image_TSS_Definition
;
7133 when Attribute_Read
=>
7134 Analyze_Stream_TSS_Definition
(TSS_Stream_Read
);
7135 Set_Has_Specified_Stream_Read
(Ent
);
7137 --------------------------
7138 -- Scalar_Storage_Order --
7139 --------------------------
7141 -- Scalar_Storage_Order attribute definition clause
7143 when Attribute_Scalar_Storage_Order
=>
7144 if not (Is_Record_Type
(U_Ent
) or else Is_Array_Type
(U_Ent
)) then
7146 ("Scalar_Storage_Order can only be defined for record or "
7147 & "array type", Nam
);
7149 elsif Duplicate_Clause
then
7153 Analyze_And_Resolve
(Expr
, RTE
(RE_Bit_Order
));
7155 if Etype
(Expr
) = Any_Type
then
7158 elsif not Is_OK_Static_Expression
(Expr
) then
7159 Flag_Non_Static_Expr
7160 ("Scalar_Storage_Order requires static expression!", Expr
);
7162 elsif (Expr_Value
(Expr
) = 0) /= Bytes_Big_Endian
then
7164 -- Here for the case of a non-default (i.e. non-confirming)
7165 -- Scalar_Storage_Order attribute definition.
7167 if Support_Nondefault_SSO_On_Target
then
7168 Set_Reverse_Storage_Order
(Base_Type
(U_Ent
), True);
7171 ("non-default Scalar_Storage_Order not supported on "
7176 -- Clear SSO default indications since explicit setting of the
7177 -- order overrides the defaults.
7179 Set_SSO_Set_Low_By_Default
(Base_Type
(U_Ent
), False);
7180 Set_SSO_Set_High_By_Default
(Base_Type
(U_Ent
), False);
7183 ------------------------
7184 -- Size or Value_Size --
7185 ------------------------
7187 -- Size or Value_Size attribute definition clause. These are treated
7188 -- the same, except that Size is allowed on objects, and Value_Size
7189 -- is allowed on nonfirst subtypes. First subtypes allow both Size
7190 -- and Value_Size; the treatment is the same for both.
7192 when Attribute_Size | Attribute_Value_Size
=> Size
: declare
7193 Size
: constant Uint
:= Static_Integer
(Expr
);
7195 Attr_Name
: constant String :=
7196 (if Id
= Attribute_Size
then "size"
7197 elsif Id
= Attribute_Value_Size
then "value size"
7198 else ""); -- can't happen
7199 -- Name of the attribute for printing in messages
7201 OK_Prefix
: constant Boolean :=
7202 (if Id
= Attribute_Size
then
7203 Ekind
(U_Ent
) in Type_Kind | Constant_Or_Variable_Kind
7204 elsif Id
= Attribute_Value_Size
then
7205 Ekind
(U_Ent
) in Type_Kind
7206 else False); -- can't happen
7207 -- For X'Size, X can be a type or object; for X'Value_Size,
7208 -- X can be a type. Note that we already checked that 'Size
7209 -- can be specified only for a first subtype.
7214 if not OK_Prefix
then
7215 Error_Msg_N
(Attr_Name
& " cannot be given for &", Nam
);
7217 elsif Duplicate_Clause
then
7220 elsif Is_Array_Type
(U_Ent
)
7221 and then not Is_Constrained
(U_Ent
)
7224 (Attr_Name
& " cannot be given for unconstrained array", Nam
);
7226 elsif Present
(Size
) then
7228 Etyp
: constant Entity_Id
:=
7229 (if Is_Type
(U_Ent
) then U_Ent
else Etype
(U_Ent
));
7232 -- Check size, note that Gigi is in charge of checking that
7233 -- the size of an array or record type is OK. Also we do not
7234 -- check the size in the ordinary fixed-point case, since
7235 -- it is too early to do so (there may be subsequent small
7236 -- clause that affects the size). We can check the size if
7237 -- a small clause has already been given.
7239 if not Is_Ordinary_Fixed_Point_Type
(U_Ent
)
7240 or else Has_Small_Clause
(U_Ent
)
7245 Check_Size
(Expr
, Etyp
, Size
, Biased
);
7246 Set_Biased
(U_Ent
, N
, Attr_Name
& " clause", Biased
);
7250 -- For types, set RM_Size and Esize if appropriate
7252 if Is_Type
(U_Ent
) then
7253 Set_RM_Size
(U_Ent
, Size
);
7255 -- If we are specifying the Size or Value_Size of a
7256 -- first subtype, then for elementary types, increase
7257 -- Object_Size to power of 2, but not less than a storage
7258 -- unit in any case (normally this means it will be byte
7261 -- For all other types, nothing else to do, we leave
7262 -- Esize (object size) unset; the back end will set it
7263 -- from the size and alignment in an appropriate manner.
7265 -- In both cases, we check whether the alignment must be
7266 -- reset in the wake of the size change.
7268 -- For nonfirst subtypes ('Value_Size only), we do
7271 if Is_First_Subtype
(U_Ent
) then
7272 if Is_Elementary_Type
(U_Ent
) then
7273 if Size
<= System_Storage_Unit
then
7275 (U_Ent
, UI_From_Int
(System_Storage_Unit
));
7276 elsif Size
<= 16 then
7277 Set_Esize
(U_Ent
, Uint_16
);
7278 elsif Size
<= 32 then
7279 Set_Esize
(U_Ent
, Uint_32
);
7281 Set_Esize
(U_Ent
, (Size
+ 63) / 64 * 64);
7284 Alignment_Check_For_Size_Change
7285 (U_Ent
, Esize
(U_Ent
));
7287 Alignment_Check_For_Size_Change
(U_Ent
, Size
);
7291 -- For Object'Size, set Esize only
7294 if Is_Elementary_Type
(Etyp
)
7295 and then Size
/= System_Storage_Unit
7299 and then Size
/= System_Max_Integer_Size
7301 Error_Msg_Uint_1
:= UI_From_Int
(System_Storage_Unit
);
7303 UI_From_Int
(System_Max_Integer_Size
);
7305 ("size for primitive object must be a power of 2 in "
7306 & "the range ^-^", N
);
7309 Set_Esize
(U_Ent
, Size
);
7312 Set_Has_Size_Clause
(U_Ent
);
7321 -- Small attribute definition clause
7323 when Attribute_Small
=> Small
: declare
7324 Implicit_Base
: constant Entity_Id
:= Base_Type
(U_Ent
);
7328 Analyze_And_Resolve
(Expr
, Any_Real
);
7330 if Etype
(Expr
) = Any_Type
then
7333 elsif not Is_OK_Static_Expression
(Expr
) then
7334 Flag_Non_Static_Expr
7335 ("small requires static expression!", Expr
);
7339 Small
:= Expr_Value_R
(Expr
);
7341 if Small
<= Ureal_0
then
7342 Error_Msg_N
("small value must be greater than zero", Expr
);
7348 if not Is_Ordinary_Fixed_Point_Type
(U_Ent
) then
7350 ("small requires an ordinary fixed point type", Nam
);
7352 elsif Has_Small_Clause
(U_Ent
) then
7353 Error_Msg_N
("small already given for &", Nam
);
7355 elsif Small
> Delta_Value
(U_Ent
) then
7357 ("small value must not be greater than delta value", Nam
);
7360 Set_Small_Value
(U_Ent
, Small
);
7361 Set_Small_Value
(Implicit_Base
, Small
);
7362 Set_Has_Small_Clause
(U_Ent
);
7363 Set_Has_Small_Clause
(Implicit_Base
);
7364 Set_Has_Non_Standard_Rep
(Implicit_Base
);
7372 -- Storage_Pool attribute definition clause
7374 when Attribute_Simple_Storage_Pool
7375 | Attribute_Storage_Pool
7377 Storage_Pool
: declare
7381 procedure Associate_Storage_Pool
7382 (Ent
: Entity_Id
; Pool
: Entity_Id
);
7383 -- Associate Pool to Ent and perform legality checks on subpools
7385 ----------------------------
7386 -- Associate_Storage_Pool --
7387 ----------------------------
7389 procedure Associate_Storage_Pool
7390 (Ent
: Entity_Id
; Pool
: Entity_Id
)
7392 function Object_From
(Pool
: Entity_Id
) return Entity_Id
;
7393 -- Return the entity of which Pool is a part of
7399 function Object_From
7400 (Pool
: Entity_Id
) return Entity_Id
7402 N
: Node_Id
:= Pool
;
7404 if Present
(Renamed_Object
(Pool
)) then
7405 N
:= Renamed_Object
(Pool
);
7408 while Present
(N
) loop
7410 when N_Defining_Identifier
=>
7413 when N_Identifier | N_Expanded_Name
=>
7416 when N_Indexed_Component | N_Selected_Component |
7417 N_Explicit_Dereference
7421 when N_Type_Conversion
=>
7422 N
:= Expression
(N
);
7425 -- ??? we probably should handle more cases but
7426 -- this is good enough in practice for this check
7427 -- on a corner case.
7439 Set_Associated_Storage_Pool
(Ent
, Pool
);
7441 -- Check RM 13.11.4(22-23/3): a specification of a storage pool
7442 -- is illegal if the storage pool supports subpools and:
7443 -- (A) The access type is a general access type.
7444 -- (B) The access type is statically deeper than the storage
7446 -- (C) The storage pool object is a part of a formal parameter;
7447 -- (D) The storage pool object is a part of the dereference of
7448 -- a non-library level general access type;
7450 if Ada_Version
>= Ada_2012
7451 and then RTU_Loaded
(System_Storage_Pools_Subpools
)
7453 Is_Ancestor
(RTE
(RE_Root_Storage_Pool_With_Subpools
),
7458 if Ekind
(Etype
(Ent
)) = E_General_Access_Type
then
7460 ("subpool cannot be used on general access type", Ent
);
7465 if Type_Access_Level
(Ent
)
7466 > Static_Accessibility_Level
7467 (Pool
, Object_Decl_Level
)
7470 ("subpool access type has deeper accessibility "
7471 & "level than pool", Ent
);
7475 Obj
:= Object_From
(Pool
);
7479 if Present
(Obj
) and then Is_Formal
(Obj
) then
7481 ("subpool cannot be part of a parameter", Ent
);
7488 and then Ekind
(Etype
(Obj
)) = E_General_Access_Type
7489 and then not Is_Library_Level_Entity
(Etype
(Obj
))
7492 ("subpool cannot be part of the dereference of a " &
7493 "nested general access type", Ent
);
7497 end Associate_Storage_Pool
;
7500 if Ekind
(U_Ent
) = E_Access_Subprogram_Type
then
7502 ("storage pool cannot be given for access-to-subprogram type",
7506 elsif Ekind
(U_Ent
) not in E_Access_Type | E_General_Access_Type
7509 ("storage pool can only be given for access types", Nam
);
7512 elsif Is_Derived_Type
(U_Ent
) then
7514 ("storage pool cannot be given for a derived access type",
7517 elsif Duplicate_Clause
then
7520 elsif Present
(Associated_Storage_Pool
(U_Ent
)) then
7521 Error_Msg_N
("storage pool already given for &", Nam
);
7525 -- Check for Storage_Size previously given
7528 SS
: constant Node_Id
:=
7529 Get_Attribute_Definition_Clause
7530 (U_Ent
, Attribute_Storage_Size
);
7532 if Present
(SS
) then
7533 Check_Pool_Size_Clash
(U_Ent
, N
, SS
);
7537 -- Storage_Pool case
7539 if Id
= Attribute_Storage_Pool
then
7541 (Expr
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
7543 -- In the Simple_Storage_Pool case, we allow a variable of any
7544 -- simple storage pool type, so we Resolve without imposing an
7548 Analyze_And_Resolve
(Expr
);
7550 if not Present
(Get_Rep_Pragma
7551 (Etype
(Expr
), Name_Simple_Storage_Pool_Type
))
7554 ("expression must be of a simple storage pool type", Expr
);
7558 if not Denotes_Variable
(Expr
) then
7559 Error_Msg_N
("storage pool must be a variable", Expr
);
7563 if Nkind
(Expr
) = N_Type_Conversion
then
7564 T
:= Etype
(Expression
(Expr
));
7569 -- The Stack_Bounded_Pool is used internally for implementing
7570 -- access types with a Storage_Size. Since it only work properly
7571 -- when used on one specific type, we need to check that it is not
7572 -- hijacked improperly:
7574 -- type T is access Integer;
7575 -- for T'Storage_Size use n;
7576 -- type Q is access Float;
7577 -- for Q'Storage_Size use T'Storage_Size; -- incorrect
7579 if Is_RTE
(Base_Type
(T
), RE_Stack_Bounded_Pool
) then
7580 Error_Msg_N
("non-shareable internal Pool", Expr
);
7584 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
7585 -- Storage_Pool since this attribute cannot be defined for such
7586 -- types (RM E.2.2(17)).
7588 Validate_Remote_Access_To_Class_Wide_Type
(N
);
7590 -- If the argument is a name that is not an entity name, then
7591 -- we construct a renaming operation to define an entity of
7592 -- type storage pool.
7594 if not Is_Entity_Name
(Expr
)
7595 and then Is_Object_Reference
(Expr
)
7597 Pool
:= Make_Temporary
(Loc
, 'P', Expr
);
7600 Rnode
: constant Node_Id
:=
7601 Make_Object_Renaming_Declaration
(Loc
,
7602 Defining_Identifier
=> Pool
,
7604 New_Occurrence_Of
(Etype
(Expr
), Loc
),
7608 -- If the attribute definition clause comes from an aspect
7609 -- clause, then insert the renaming before the associated
7610 -- entity's declaration, since the attribute clause has
7611 -- not yet been appended to the declaration list.
7613 if From_Aspect_Specification
(N
) then
7614 Insert_Before
(Parent
(Entity
(N
)), Rnode
);
7616 Insert_Before
(N
, Rnode
);
7620 Associate_Storage_Pool
(U_Ent
, Pool
);
7623 elsif Is_Entity_Name
(Expr
) then
7624 Pool
:= Entity
(Expr
);
7626 -- If pool is a renamed object, get original one. This can
7627 -- happen with an explicit renaming, and within instances.
7629 while Present
(Renamed_Object
(Pool
))
7630 and then Is_Entity_Name
(Renamed_Object
(Pool
))
7632 Pool
:= Entity
(Renamed_Object
(Pool
));
7635 if Present
(Renamed_Object
(Pool
))
7636 and then Nkind
(Renamed_Object
(Pool
)) = N_Type_Conversion
7637 and then Is_Entity_Name
(Expression
(Renamed_Object
(Pool
)))
7639 Pool
:= Entity
(Expression
(Renamed_Object
(Pool
)));
7642 Associate_Storage_Pool
(U_Ent
, Pool
);
7644 elsif Nkind
(Expr
) = N_Type_Conversion
7645 and then Is_Entity_Name
(Expression
(Expr
))
7646 and then Nkind
(Original_Node
(Expr
)) = N_Attribute_Reference
7648 Pool
:= Entity
(Expression
(Expr
));
7649 Associate_Storage_Pool
(U_Ent
, Pool
);
7652 Error_Msg_N
("incorrect reference to a Storage Pool", Expr
);
7661 -- Storage_Size attribute definition clause
7663 when Attribute_Storage_Size
=> Storage_Size
: declare
7664 Btype
: constant Entity_Id
:= Base_Type
(U_Ent
);
7667 if Is_Task_Type
(U_Ent
) then
7669 -- Check obsolescent (but never obsolescent if from aspect)
7671 if not From_Aspect_Specification
(N
) then
7672 Check_Restriction
(No_Obsolescent_Features
, N
);
7674 if Warn_On_Obsolescent_Feature
then
7676 ("?j?storage size clause for task is an obsolescent "
7677 & "feature (RM J.9)", N
);
7678 Error_Msg_N
("\?j?use Storage_Size pragma instead", N
);
7685 if not Is_Access_Type
(U_Ent
)
7686 and then Ekind
(U_Ent
) /= E_Task_Type
7688 Error_Msg_N
("storage size cannot be given for &", Nam
);
7690 elsif Is_Access_Type
(U_Ent
) and Is_Derived_Type
(U_Ent
) then
7692 ("storage size cannot be given for a derived access type",
7695 elsif Duplicate_Clause
then
7699 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
7700 -- Storage_Size since this attribute cannot be defined for such
7701 -- types (RM E.2.2(17)).
7703 Validate_Remote_Access_To_Class_Wide_Type
(N
);
7705 Analyze_And_Resolve
(Expr
, Any_Integer
);
7707 if Is_Access_Type
(U_Ent
) then
7709 -- Check for Storage_Pool previously given
7712 SP
: constant Node_Id
:=
7713 Get_Attribute_Definition_Clause
7714 (U_Ent
, Attribute_Storage_Pool
);
7717 if Present
(SP
) then
7718 Check_Pool_Size_Clash
(U_Ent
, SP
, N
);
7722 -- Special case of for x'Storage_Size use 0
7724 if Is_OK_Static_Expression
(Expr
)
7725 and then Expr_Value
(Expr
) = 0
7727 Set_No_Pool_Assigned
(Btype
);
7731 Set_Has_Storage_Size_Clause
(Btype
);
7739 when Attribute_Stream_Size
=> Stream_Size
: declare
7740 Size
: constant Uint
:= Static_Integer
(Expr
);
7743 if Ada_Version
<= Ada_95
then
7744 Check_Restriction
(No_Implementation_Attributes
, N
);
7747 if Duplicate_Clause
then
7750 elsif Is_Elementary_Type
(U_Ent
) then
7751 -- Size will be empty if we already detected an error
7752 -- (e.g. Expr is of the wrong type); we might as well
7753 -- give the useful hint below even in that case.
7755 if No
(Size
) or else
7756 (Size
/= System_Storage_Unit
7757 and then Size
/= System_Storage_Unit
* 2
7758 and then Size
/= System_Storage_Unit
* 3
7759 and then Size
/= System_Storage_Unit
* 4
7760 and then Size
/= System_Storage_Unit
* 8)
7763 ("stream size for elementary type must be 8, 16, 24, " &
7766 elsif Known_RM_Size
(U_Ent
) and then RM_Size
(U_Ent
) > Size
then
7767 Error_Msg_Uint_1
:= RM_Size
(U_Ent
);
7769 ("stream size for elementary type must be 8, 16, 24, " &
7770 "32 or 64 and at least ^", N
);
7773 Set_Has_Stream_Size_Clause
(U_Ent
);
7776 Error_Msg_N
("Stream_Size cannot be given for &", Nam
);
7780 -----------------------
7781 -- Variable_Indexing --
7782 -----------------------
7784 when Attribute_Variable_Indexing
=>
7785 Check_Indexing_Functions
;
7791 when Attribute_Write
=>
7792 Analyze_Stream_TSS_Definition
(TSS_Stream_Write
);
7793 Set_Has_Specified_Stream_Write
(Ent
);
7795 -- All other attributes cannot be set
7799 ("attribute& cannot be set with definition clause", N
);
7802 -- The test for the type being frozen must be performed after any
7803 -- expression the clause has been analyzed since the expression itself
7804 -- might cause freezing that makes the clause illegal.
7806 if Rep_Item_Too_Late
(U_Ent
, N
, FOnly
) then
7809 end Analyze_Attribute_Definition_Clause
;
7811 ----------------------------
7812 -- Analyze_Code_Statement --
7813 ----------------------------
7815 procedure Analyze_Code_Statement
(N
: Node_Id
) is
7816 HSS
: constant Node_Id
:= Parent
(N
);
7817 SBody
: constant Node_Id
:= Parent
(HSS
);
7818 Subp
: constant Entity_Id
:= Current_Scope
;
7825 -- Accept foreign code statements for CodePeer. The analysis is skipped
7826 -- to avoid rejecting unrecognized constructs.
7828 if CodePeer_Mode
then
7833 -- Analyze and check we get right type, note that this implements the
7834 -- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that is
7835 -- the only way that Asm_Insn could possibly be visible.
7837 Analyze_And_Resolve
(Expression
(N
));
7839 if Etype
(Expression
(N
)) = Any_Type
then
7841 elsif not Is_RTE
(Etype
(Expression
(N
)), RE_Asm_Insn
) then
7842 Error_Msg_N
("incorrect type for code statement", N
);
7846 Check_Code_Statement
(N
);
7848 -- Make sure we appear in the handled statement sequence of a subprogram
7851 if Nkind
(HSS
) /= N_Handled_Sequence_Of_Statements
7852 or else Nkind
(SBody
) /= N_Subprogram_Body
7855 ("code statement can only appear in body of subprogram", N
);
7859 -- Do remaining checks (RM 13.8(3)) if not already done
7861 if not Is_Machine_Code_Subprogram
(Subp
) then
7862 Set_Is_Machine_Code_Subprogram
(Subp
);
7864 -- No exception handlers allowed
7866 if Present
(Exception_Handlers
(HSS
)) then
7868 ("exception handlers not permitted in machine code subprogram",
7869 First
(Exception_Handlers
(HSS
)));
7872 -- No declarations other than use clauses and pragmas (we allow
7873 -- certain internally generated declarations as well).
7875 Decl
:= First
(Declarations
(SBody
));
7876 while Present
(Decl
) loop
7877 DeclO
:= Original_Node
(Decl
);
7878 if Comes_From_Source
(DeclO
)
7879 and Nkind
(DeclO
) not in N_Pragma
7880 | N_Use_Package_Clause
7882 | N_Implicit_Label_Declaration
7885 ("this declaration is not allowed in machine code subprogram",
7892 -- No statements other than code statements, pragmas, and labels.
7893 -- Again we allow certain internally generated statements.
7895 -- In Ada 2012, qualified expressions are names, and the code
7896 -- statement is initially parsed as a procedure call.
7898 Stmt
:= First
(Statements
(HSS
));
7899 while Present
(Stmt
) loop
7900 StmtO
:= Original_Node
(Stmt
);
7902 -- A procedure call transformed into a code statement is OK
7904 if Ada_Version
>= Ada_2012
7905 and then Nkind
(StmtO
) = N_Procedure_Call_Statement
7906 and then Nkind
(Name
(StmtO
)) = N_Qualified_Expression
7910 elsif Comes_From_Source
(StmtO
)
7911 and then Nkind
(StmtO
) not in
7912 N_Pragma | N_Label | N_Code_Statement
7915 ("this statement is not allowed in machine code subprogram",
7922 end Analyze_Code_Statement
;
7924 -----------------------------------------------
7925 -- Analyze_Enumeration_Representation_Clause --
7926 -----------------------------------------------
7928 procedure Analyze_Enumeration_Representation_Clause
(N
: Node_Id
) is
7929 Ident
: constant Node_Id
:= Identifier
(N
);
7930 Aggr
: constant Node_Id
:= Array_Aggregate
(N
);
7931 Enumtype
: Entity_Id
;
7938 Err
: Boolean := False;
7939 -- Set True to avoid cascade errors and crashes on incorrect source code
7941 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Universal_Integer
));
7942 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(Universal_Integer
));
7943 -- Allowed range of universal integer (= allowed range of enum lit vals)
7947 -- Minimum and maximum values of entries
7949 Max_Node
: Node_Id
:= Empty
; -- init to avoid warning
7950 -- Pointer to node for literal providing max value
7953 if Ignore_Rep_Clauses
then
7954 Kill_Rep_Clause
(N
);
7958 -- Ignore enumeration rep clauses by default in CodePeer mode,
7959 -- unless -gnatd.I is specified, as a work around for potential false
7960 -- positive messages.
7962 if CodePeer_Mode
and not Debug_Flag_Dot_II
then
7966 -- First some basic error checks
7969 Enumtype
:= Entity
(Ident
);
7971 if Enumtype
= Any_Type
7972 or else Rep_Item_Too_Early
(Enumtype
, N
)
7976 Enumtype
:= Underlying_Type
(Enumtype
);
7979 if not Is_Enumeration_Type
(Enumtype
) then
7981 ("enumeration type required, found}",
7982 Ident
, First_Subtype
(Enumtype
));
7986 -- Ignore rep clause on generic actual type. This will already have
7987 -- been flagged on the template as an error, and this is the safest
7988 -- way to ensure we don't get a junk cascaded message in the instance.
7990 if Is_Generic_Actual_Type
(Enumtype
) then
7993 -- Type must be in current scope
7995 elsif Scope
(Enumtype
) /= Current_Scope
then
7996 Error_Msg_N
("type must be declared in this scope", Ident
);
7999 -- Type must be a first subtype
8001 elsif not Is_First_Subtype
(Enumtype
) then
8002 Error_Msg_N
("cannot give enumeration rep clause for subtype", N
);
8005 -- Ignore duplicate rep clause
8007 elsif Has_Enumeration_Rep_Clause
(Enumtype
) then
8008 Error_Msg_N
("duplicate enumeration rep clause ignored", N
);
8011 -- Don't allow rep clause for standard [wide_[wide_]]character
8013 elsif Is_Standard_Character_Type
(Enumtype
) then
8014 Error_Msg_N
("enumeration rep clause not allowed for this type", N
);
8017 -- Check that the expression is a proper aggregate (no parentheses)
8019 elsif Paren_Count
(Aggr
) /= 0 then
8021 ("extra parentheses surrounding aggregate not allowed", Aggr
);
8024 -- Reject the mixing of named and positional entries in the aggregate
8026 elsif Present
(Expressions
(Aggr
))
8027 and then Present
(Component_Associations
(Aggr
))
8029 Error_Msg_N
("cannot mix positional and named entries in "
8030 & "enumeration rep clause", N
);
8033 -- All tests passed, so set rep clause in place
8036 Set_Has_Enumeration_Rep_Clause
(Enumtype
);
8037 Set_Has_Enumeration_Rep_Clause
(Base_Type
(Enumtype
));
8040 -- Now we process the aggregate. Note that we don't use the normal
8041 -- aggregate code for this purpose, because we don't want any of the
8042 -- normal expansion activities, and a number of special semantic
8043 -- rules apply (including the component type being any integer type)
8045 Elit
:= First_Literal
(Enumtype
);
8047 -- Process positional entries
8049 if Present
(Expressions
(Aggr
)) then
8050 Expr
:= First
(Expressions
(Aggr
));
8051 while Present
(Expr
) loop
8053 Error_Msg_N
("too many entries in aggregate", Expr
);
8057 Val
:= Static_Integer
(Expr
);
8059 -- Err signals that we found some incorrect entries processing
8060 -- the list. The final checks for completeness and ordering are
8061 -- skipped in this case.
8066 elsif Val
< Lo
or else Hi
< Val
then
8067 Error_Msg_N
("value outside permitted range", Expr
);
8071 Set_Enumeration_Rep
(Elit
, Val
);
8072 Set_Enumeration_Rep_Expr
(Elit
, Expr
);
8079 -- Process named entries
8081 elsif Present
(Component_Associations
(Aggr
)) then
8082 Assoc
:= First
(Component_Associations
(Aggr
));
8083 while Present
(Assoc
) loop
8084 Choice
:= First
(Choices
(Assoc
));
8086 if Present
(Next
(Choice
)) then
8088 ("multiple choice not allowed here", Next
(Choice
));
8092 if Nkind
(Choice
) = N_Others_Choice
then
8093 Error_Msg_N
("OTHERS choice not allowed here", Choice
);
8096 elsif Nkind
(Choice
) = N_Range
then
8098 -- ??? should allow zero/one element range here
8100 Error_Msg_N
("range not allowed here", Choice
);
8104 Analyze_And_Resolve
(Choice
, Enumtype
);
8106 if Error_Posted
(Choice
) then
8111 if Is_Entity_Name
(Choice
)
8112 and then Is_Type
(Entity
(Choice
))
8114 Error_Msg_N
("subtype name not allowed here", Choice
);
8117 -- ??? should allow static subtype with zero/one entry
8119 elsif Etype
(Choice
) = Base_Type
(Enumtype
) then
8120 if not Is_OK_Static_Expression
(Choice
) then
8121 Flag_Non_Static_Expr
8122 ("non-static expression used for choice!", Choice
);
8126 Elit
:= Expr_Value_E
(Choice
);
8128 if Present
(Enumeration_Rep_Expr
(Elit
)) then
8130 Sloc
(Enumeration_Rep_Expr
(Elit
));
8132 ("representation for& previously given#",
8137 Set_Enumeration_Rep_Expr
(Elit
, Expression
(Assoc
));
8139 Expr
:= Expression
(Assoc
);
8140 Val
:= Static_Integer
(Expr
);
8145 elsif Val
< Lo
or else Hi
< Val
then
8146 Error_Msg_N
("value outside permitted range", Expr
);
8150 Set_Enumeration_Rep
(Elit
, Val
);
8161 -- Aggregate is fully processed. Now we check that a full set of
8162 -- representations was given, and that they are in range and in order.
8163 -- These checks are only done if no other errors occurred.
8169 Elit
:= First_Literal
(Enumtype
);
8170 while Present
(Elit
) loop
8171 if No
(Enumeration_Rep_Expr
(Elit
)) then
8172 Error_Msg_NE
("missing representation for&!", N
, Elit
);
8175 Val
:= Enumeration_Rep
(Elit
);
8181 if Present
(Val
) then
8182 if Present
(Max
) and then Val
<= Max
then
8184 ("enumeration value for& not ordered!",
8185 Enumeration_Rep_Expr
(Elit
), Elit
);
8188 Max_Node
:= Enumeration_Rep_Expr
(Elit
);
8192 -- If there is at least one literal whose representation is not
8193 -- equal to the Pos value, then note that this enumeration type
8194 -- has a non-standard representation.
8196 if Val
/= Enumeration_Pos
(Elit
) then
8197 Set_Has_Non_Standard_Rep
(Base_Type
(Enumtype
));
8204 -- Now set proper size information
8207 Minsize
: Uint
:= UI_From_Int
(Minimum_Size
(Enumtype
));
8210 if Has_Size_Clause
(Enumtype
) then
8212 -- All OK, if size is OK now
8214 if RM_Size
(Enumtype
) >= Minsize
then
8218 -- Try if we can get by with biasing
8221 UI_From_Int
(Minimum_Size
(Enumtype
, Biased
=> True));
8223 -- Error message if even biasing does not work
8225 if RM_Size
(Enumtype
) < Minsize
then
8226 Error_Msg_Uint_1
:= RM_Size
(Enumtype
);
8227 Error_Msg_Uint_2
:= Max
;
8229 ("previously given size (^) is too small "
8230 & "for this value (^)", Max_Node
);
8232 -- If biasing worked, indicate that we now have biased rep
8236 (Enumtype
, Size_Clause
(Enumtype
), "size clause");
8241 Set_RM_Size
(Enumtype
, Minsize
);
8242 Set_Enum_Esize
(Enumtype
);
8245 Set_RM_Size
(Base_Type
(Enumtype
), RM_Size
(Enumtype
));
8246 Set_Esize
(Base_Type
(Enumtype
), Esize
(Enumtype
));
8248 Copy_Alignment
(To
=> Base_Type
(Enumtype
), From
=> Enumtype
);
8252 -- We repeat the too late test in case it froze itself
8254 if Rep_Item_Too_Late
(Enumtype
, N
) then
8257 end Analyze_Enumeration_Representation_Clause
;
8259 ----------------------------
8260 -- Analyze_Free_Statement --
8261 ----------------------------
8263 procedure Analyze_Free_Statement
(N
: Node_Id
) is
8265 Analyze
(Expression
(N
));
8266 end Analyze_Free_Statement
;
8268 ---------------------------
8269 -- Analyze_Freeze_Entity --
8270 ---------------------------
8272 procedure Analyze_Freeze_Entity
(N
: Node_Id
) is
8274 Freeze_Entity_Checks
(N
);
8275 end Analyze_Freeze_Entity
;
8277 -----------------------------------
8278 -- Analyze_Freeze_Generic_Entity --
8279 -----------------------------------
8281 procedure Analyze_Freeze_Generic_Entity
(N
: Node_Id
) is
8282 E
: constant Entity_Id
:= Entity
(N
);
8285 if not Is_Frozen
(E
) and then Has_Delayed_Aspects
(E
) then
8286 Analyze_Aspects_At_Freeze_Point
(E
);
8289 Freeze_Entity_Checks
(N
);
8290 end Analyze_Freeze_Generic_Entity
;
8292 ------------------------------------------
8293 -- Analyze_Record_Representation_Clause --
8294 ------------------------------------------
8296 -- Note: we check as much as we can here, but we can't do any checks
8297 -- based on the position values (e.g. overlap checks) until freeze time
8298 -- because especially in Ada 2005 (machine scalar mode), the processing
8299 -- for non-standard bit order can substantially change the positions.
8300 -- See procedure Check_Record_Representation_Clause (called from Freeze)
8301 -- for the remainder of this processing.
8303 procedure Analyze_Record_Representation_Clause
(N
: Node_Id
) is
8304 Ident
: constant Node_Id
:= Identifier
(N
);
8312 Rectype
: Entity_Id
;
8315 function Is_Inherited
(Comp
: Entity_Id
) return Boolean;
8316 -- True if Comp is an inherited component in a record extension
8322 function Is_Inherited
(Comp
: Entity_Id
) return Boolean is
8323 Comp_Base
: Entity_Id
;
8326 if Ekind
(Rectype
) = E_Record_Subtype
then
8327 Comp_Base
:= Original_Record_Component
(Comp
);
8332 return Comp_Base
/= Original_Record_Component
(Comp_Base
);
8337 Is_Record_Extension
: Boolean;
8338 -- True if Rectype is a record extension
8340 CR_Pragma
: Node_Id
:= Empty
;
8341 -- Points to N_Pragma node if Complete_Representation pragma present
8343 -- Start of processing for Analyze_Record_Representation_Clause
8346 if Ignore_Rep_Clauses
then
8347 Kill_Rep_Clause
(N
);
8352 Rectype
:= Entity
(Ident
);
8354 if Rectype
= Any_Type
or else Rep_Item_Too_Early
(Rectype
, N
) then
8357 Rectype
:= Underlying_Type
(Rectype
);
8360 -- First some basic error checks
8362 if not Is_Record_Type
(Rectype
) then
8364 ("record type required, found}", Ident
, First_Subtype
(Rectype
));
8367 elsif Scope
(Rectype
) /= Current_Scope
then
8368 Error_Msg_N
("type must be declared in this scope", N
);
8371 elsif not Is_First_Subtype
(Rectype
) then
8372 Error_Msg_N
("cannot give record rep clause for subtype", N
);
8375 elsif Has_Record_Rep_Clause
(Rectype
) then
8376 Error_Msg_N
("duplicate record rep clause ignored", N
);
8379 elsif Rep_Item_Too_Late
(Rectype
, N
) then
8383 -- We know we have a first subtype, now possibly go to the anonymous
8384 -- base type to determine whether Rectype is a record extension.
8386 Recdef
:= Type_Definition
(Declaration_Node
(Base_Type
(Rectype
)));
8387 Is_Record_Extension
:=
8388 Nkind
(Recdef
) = N_Derived_Type_Definition
8389 and then Present
(Record_Extension_Part
(Recdef
));
8391 if Present
(Mod_Clause
(N
)) then
8393 M
: constant Node_Id
:= Mod_Clause
(N
);
8394 P
: constant List_Id
:= Pragmas_Before
(M
);
8398 Check_Restriction
(No_Obsolescent_Features
, Mod_Clause
(N
));
8400 if Warn_On_Obsolescent_Feature
then
8402 ("?j?mod clause is an obsolescent feature (RM J.8)", N
);
8404 ("\?j?use alignment attribute definition clause instead", N
);
8411 -- Get the alignment value to perform error checking
8413 Ignore
:= Get_Alignment_Value
(Expression
(M
));
8417 -- For untagged types, clear any existing component clauses for the
8418 -- type. If the type is derived, this is what allows us to override
8419 -- a rep clause for the parent. For type extensions, the representation
8420 -- of the inherited components is inherited, so we want to keep previous
8421 -- component clauses for completeness.
8423 if not Is_Tagged_Type
(Rectype
) then
8424 Comp
:= First_Component_Or_Discriminant
(Rectype
);
8425 while Present
(Comp
) loop
8426 Set_Component_Clause
(Comp
, Empty
);
8427 Next_Component_Or_Discriminant
(Comp
);
8431 -- All done if no component clauses
8433 CC
:= First
(Component_Clauses
(N
));
8439 -- A representation like this applies to the base type
8441 Set_Has_Record_Rep_Clause
(Base_Type
(Rectype
));
8442 Set_Has_Non_Standard_Rep
(Base_Type
(Rectype
));
8443 Set_Has_Specified_Layout
(Base_Type
(Rectype
));
8445 -- Process the component clauses
8447 while Present
(CC
) loop
8451 if Nkind
(CC
) = N_Pragma
then
8454 -- The only pragma of interest is Complete_Representation
8456 if Pragma_Name
(CC
) = Name_Complete_Representation
then
8460 -- Processing for real component clause
8463 Posit
:= Static_Integer
(Position
(CC
));
8464 Fbit
:= Static_Integer
(First_Bit
(CC
));
8465 Lbit
:= Static_Integer
(Last_Bit
(CC
));
8468 and then Present
(Fbit
)
8469 and then Present
(Lbit
)
8472 Error_Msg_N
("position cannot be negative", Position
(CC
));
8475 Error_Msg_N
("first bit cannot be negative", First_Bit
(CC
));
8477 -- The Last_Bit specified in a component clause must not be
8478 -- less than the First_Bit minus one (RM-13.5.1(10)).
8480 elsif Lbit
< Fbit
- 1 then
8482 ("last bit cannot be less than first bit minus one",
8485 -- Values look OK, so find the corresponding record component
8486 -- Even though the syntax allows an attribute reference for
8487 -- implementation-defined components, GNAT does not allow the
8488 -- tag to get an explicit position.
8490 elsif Nkind
(Component_Name
(CC
)) = N_Attribute_Reference
then
8491 if Attribute_Name
(Component_Name
(CC
)) = Name_Tag
then
8492 Error_Msg_N
("position of tag cannot be specified", CC
);
8494 Error_Msg_N
("illegal component name", CC
);
8498 Comp
:= First_Entity
(Rectype
);
8499 while Present
(Comp
) loop
8500 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
8506 -- Maybe component of base type that is absent from
8507 -- statically constrained first subtype.
8509 Comp
:= First_Entity
(Base_Type
(Rectype
));
8510 while Present
(Comp
) loop
8511 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
8518 ("component clause is for non-existent field", CC
);
8520 -- Ada 2012 (AI05-0026): Any name that denotes a
8521 -- discriminant of an object of an unchecked union type
8522 -- shall not occur within a record_representation_clause.
8524 -- The general restriction of using record rep clauses on
8525 -- Unchecked_Union types has now been lifted. Since it is
8526 -- possible to introduce a record rep clause which mentions
8527 -- the discriminant of an Unchecked_Union in non-Ada 2012
8528 -- code, this check is applied to all versions of the
8531 elsif Ekind
(Comp
) = E_Discriminant
8532 and then Is_Unchecked_Union
(Rectype
)
8535 ("cannot reference discriminant of unchecked union",
8536 Component_Name
(CC
));
8538 elsif Is_Record_Extension
and then Is_Inherited
(Comp
) then
8540 ("component clause not allowed for inherited "
8541 & "component&", CC
, Comp
);
8543 elsif Present
(Component_Clause
(Comp
)) then
8545 -- Diagnose duplicate rep clause, or check consistency
8546 -- if this is an inherited component. In a double fault,
8547 -- there may be a duplicate inconsistent clause for an
8548 -- inherited component.
8550 if Scope
(Original_Record_Component
(Comp
)) = Rectype
8551 or else Parent
(Component_Clause
(Comp
)) = N
8553 Error_Msg_Sloc
:= Sloc
(Component_Clause
(Comp
));
8554 Error_Msg_N
("component clause previously given#", CC
);
8558 Rep1
: constant Node_Id
:= Component_Clause
(Comp
);
8560 if Intval
(Position
(Rep1
)) /=
8561 Intval
(Position
(CC
))
8562 or else Intval
(First_Bit
(Rep1
)) /=
8563 Intval
(First_Bit
(CC
))
8564 or else Intval
(Last_Bit
(Rep1
)) /=
8565 Intval
(Last_Bit
(CC
))
8568 ("component clause inconsistent with "
8569 & "representation of ancestor", CC
);
8571 elsif Warn_On_Redundant_Constructs
then
8573 ("?r?redundant confirming component clause "
8574 & "for component!", CC
);
8579 -- Normal case where this is the first component clause we
8580 -- have seen for this entity, so set it up properly.
8583 -- Make reference for field in record rep clause and set
8584 -- appropriate entity field in the field identifier.
8587 (Comp
, Component_Name
(CC
), Set_Ref
=> False);
8588 Set_Entity_With_Checks
(Component_Name
(CC
), Comp
);
8590 -- Update Fbit and Lbit to the actual bit number
8592 Fbit
:= Fbit
+ UI_From_Int
(SSU
) * Posit
;
8593 Lbit
:= Lbit
+ UI_From_Int
(SSU
) * Posit
;
8595 if Has_Size_Clause
(Rectype
)
8596 and then RM_Size
(Rectype
) <= Lbit
8598 Error_Msg_Uint_1
:= RM_Size
(Rectype
);
8599 Error_Msg_Uint_2
:= Lbit
+ 1;
8600 Error_Msg_N
("bit number out of range of specified "
8601 & "size (expected ^, got ^)",
8604 Set_Component_Clause
(Comp
, CC
);
8605 Set_Component_Bit_Offset
(Comp
, Fbit
);
8606 Set_Esize
(Comp
, 1 + (Lbit
- Fbit
));
8607 Set_Normalized_First_Bit
(Comp
, Fbit
mod SSU
);
8608 Set_Normalized_Position
(Comp
, Fbit
/ SSU
);
8610 if Warn_On_Overridden_Size
8611 and then Has_Size_Clause
(Etype
(Comp
))
8612 and then RM_Size
(Etype
(Comp
)) /= Esize
(Comp
)
8615 ("?.s?component size overrides size clause for&",
8616 Component_Name
(CC
), Etype
(Comp
));
8620 (Component_Name
(CC
),
8626 (Comp
, First_Node
(CC
), "component clause", Biased
);
8628 -- This information is also set in the corresponding
8629 -- component of the base type, found by accessing the
8630 -- Original_Record_Component link if it is present.
8632 Ocomp
:= Original_Record_Component
(Comp
);
8634 if Present
(Ocomp
) and then Ocomp
/= Comp
then
8635 Set_Component_Clause
(Ocomp
, CC
);
8636 Set_Component_Bit_Offset
(Ocomp
, Fbit
);
8637 Set_Esize
(Ocomp
, 1 + (Lbit
- Fbit
));
8638 Set_Normalized_First_Bit
(Ocomp
, Fbit
mod SSU
);
8639 Set_Normalized_Position
(Ocomp
, Fbit
/ SSU
);
8641 -- Note: we don't use Set_Biased here, because we
8642 -- already gave a warning above if needed, and we
8643 -- would get a duplicate for the same name here.
8645 Set_Has_Biased_Representation
8646 (Ocomp
, Has_Biased_Representation
(Comp
));
8649 if Esize
(Comp
) < 0 then
8650 Error_Msg_N
("component size is negative", CC
);
8661 -- Check missing components if Complete_Representation pragma appeared
8663 if Present
(CR_Pragma
) then
8664 Comp
:= First_Component_Or_Discriminant
(Rectype
);
8665 while Present
(Comp
) loop
8666 if No
(Component_Clause
(Comp
)) then
8668 ("missing component clause for &", CR_Pragma
, Comp
);
8671 Next_Component_Or_Discriminant
(Comp
);
8674 -- Give missing components warning if required
8676 elsif Warn_On_Unrepped_Components
then
8678 Num_Repped_Components
: Nat
:= 0;
8679 Num_Unrepped_Components
: Nat
:= 0;
8682 -- First count number of repped and unrepped components
8684 Comp
:= First_Component_Or_Discriminant
(Rectype
);
8685 while Present
(Comp
) loop
8686 if Present
(Component_Clause
(Comp
)) then
8687 Num_Repped_Components
:= Num_Repped_Components
+ 1;
8689 Num_Unrepped_Components
:= Num_Unrepped_Components
+ 1;
8692 Next_Component_Or_Discriminant
(Comp
);
8695 -- We are only interested in the case where there is at least one
8696 -- unrepped component, and at least half the components have rep
8697 -- clauses. We figure that if less than half have them, then the
8698 -- partial rep clause is really intentional. If the component
8699 -- type has no underlying type set at this point (as for a generic
8700 -- formal type), we don't know enough to give a warning on the
8703 if Num_Unrepped_Components
> 0
8704 and then Num_Unrepped_Components
< Num_Repped_Components
8706 Comp
:= First_Component_Or_Discriminant
(Rectype
);
8707 while Present
(Comp
) loop
8708 if No
(Component_Clause
(Comp
))
8709 and then Comes_From_Source
(Comp
)
8710 and then Present
(Underlying_Type
(Etype
(Comp
)))
8711 and then (Is_Scalar_Type
(Underlying_Type
(Etype
(Comp
)))
8712 or else Size_Known_At_Compile_Time
8713 (Underlying_Type
(Etype
(Comp
))))
8714 and then not Has_Warnings_Off
(Rectype
)
8716 -- Ignore discriminant in unchecked union, since it is
8717 -- not there, and cannot have a component clause.
8719 and then (not Is_Unchecked_Union
(Rectype
)
8720 or else Ekind
(Comp
) /= E_Discriminant
)
8722 Error_Msg_Sloc
:= Sloc
(Comp
);
8724 ("?.c?no component clause given for & declared #",
8728 Next_Component_Or_Discriminant
(Comp
);
8733 end Analyze_Record_Representation_Clause
;
8735 -------------------------------------
8736 -- Build_Discrete_Static_Predicate --
8737 -------------------------------------
8739 procedure Build_Discrete_Static_Predicate
8744 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
8746 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
8748 BLo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Btyp
));
8749 BHi
: constant Uint
:= Expr_Value
(Type_High_Bound
(Btyp
));
8750 -- Low bound and high bound value of base type of Typ
8754 -- Bounds for constructing the static predicate. We use the bound of the
8755 -- subtype if it is static, otherwise the corresponding base type bound.
8756 -- Note: a non-static subtype can have a static predicate.
8761 -- One entry in a Rlist value, a single REnt (range entry) value denotes
8762 -- one range from Lo to Hi. To represent a single value range Lo = Hi =
8765 type RList
is array (Nat
range <>) of REnt
;
8766 -- A list of ranges. The ranges are sorted in increasing order, and are
8767 -- disjoint (there is a gap of at least one value between each range in
8768 -- the table). A value is in the set of ranges in Rlist if it lies
8769 -- within one of these ranges.
8771 False_Range
: constant RList
:=
8772 RList
'(1 .. 0 => REnt'(No_Uint
, No_Uint
));
8773 -- An empty set of ranges represents a range list that can never be
8774 -- satisfied, since there are no ranges in which the value could lie,
8775 -- so it does not lie in any of them. False_Range is a canonical value
8776 -- for this empty set, but general processing should test for an Rlist
8777 -- with length zero (see Is_False predicate), since other null ranges
8778 -- may appear which must be treated as False.
8780 True_Range
: constant RList
:= RList
'(1 => REnt'(BLo
, BHi
));
8781 -- Range representing True, value must be in the base range
8783 function "and" (Left
: RList
; Right
: RList
) return RList
;
8784 -- And's together two range lists, returning a range list. This is a set
8785 -- intersection operation.
8787 function "or" (Left
: RList
; Right
: RList
) return RList
;
8788 -- Or's together two range lists, returning a range list. This is a set
8791 function "not" (Right
: RList
) return RList
;
8792 -- Returns complement of a given range list, i.e. a range list
8793 -- representing all the values in TLo .. THi that are not in the input
8796 function Build_Val
(V
: Uint
) return Node_Id
;
8797 -- Return an analyzed N_Identifier node referencing this value, suitable
8798 -- for use as an entry in the Static_Discrete_Predicate list. This node
8799 -- is typed with the base type.
8801 function Build_Range
(Lo
: Uint
; Hi
: Uint
) return Node_Id
;
8802 -- Return an analyzed N_Range node referencing this range, suitable for
8803 -- use as an entry in the Static_Discrete_Predicate list. This node is
8804 -- typed with the base type.
8808 Static
: access Boolean) return RList
;
8809 -- This is a recursive routine that converts the given expression into a
8810 -- list of ranges, suitable for use in building the static predicate.
8811 -- Static.all will be set to False if the expression is found to be non
8812 -- static. Note that Static.all should be set to True by the caller.
8814 function Is_False
(R
: RList
) return Boolean;
8815 pragma Inline
(Is_False
);
8816 -- Returns True if the given range list is empty, and thus represents a
8817 -- False list of ranges that can never be satisfied.
8819 function Is_True
(R
: RList
) return Boolean;
8820 -- Returns True if R trivially represents the True predicate by having a
8821 -- single range from BLo to BHi.
8823 function Is_Type_Ref
(N
: Node_Id
) return Boolean;
8824 pragma Inline
(Is_Type_Ref
);
8825 -- Returns if True if N is a reference to the type for the predicate in
8826 -- the expression (i.e. if it is an identifier whose Chars field matches
8827 -- the Nam given in the call). N must not be parenthesized, if the type
8828 -- name appears in parens, this routine will return False.
8830 function Lo_Val
(N
: Node_Id
) return Uint
;
8831 -- Given an entry from a Static_Discrete_Predicate list that is either
8832 -- a static expression or static range, gets either the expression value
8833 -- or the low bound of the range.
8835 function Hi_Val
(N
: Node_Id
) return Uint
;
8836 -- Given an entry from a Static_Discrete_Predicate list that is either
8837 -- a static expression or static range, gets either the expression value
8838 -- or the high bound of the range.
8840 function Membership_Entry
8841 (N
: Node_Id
; Static
: access Boolean) return RList
;
8842 -- Given a single membership entry (range, value, or subtype), returns
8843 -- the corresponding range list. Set Static.all to False if not static.
8845 function Membership_Entries
8846 (N
: Node_Id
; Static
: access Boolean) return RList
;
8847 -- Given an element on an alternatives list of a membership operation,
8848 -- returns the range list corresponding to this entry and all following
8849 -- entries (i.e. returns the "or" of this list of values).
8850 -- Set Static.all to False if not static.
8854 Static
: access Boolean) return RList
;
8855 -- Given a type, if it has a static predicate, then set Result to the
8856 -- predicate as a range list, otherwise set Static.all to False.
8862 function "and" (Left
: RList
; Right
: RList
) return RList
is
8864 -- First range of result
8866 SLeft
: Nat
:= Left
'First;
8867 -- Start of rest of left entries
8869 SRight
: Nat
:= Right
'First;
8870 -- Start of rest of right entries
8873 -- If either range is True, return the other
8875 if Is_True
(Left
) then
8877 elsif Is_True
(Right
) then
8881 -- If either range is False, return False
8883 if Is_False
(Left
) or else Is_False
(Right
) then
8887 -- Loop to remove entries at start that are disjoint, and thus just
8888 -- get discarded from the result entirely.
8891 -- If no operands left in either operand, result is false
8893 if SLeft
> Left
'Last or else SRight
> Right
'Last then
8896 -- Discard first left operand entry if disjoint with right
8898 elsif Left
(SLeft
).Hi
< Right
(SRight
).Lo
then
8901 -- Discard first right operand entry if disjoint with left
8903 elsif Right
(SRight
).Hi
< Left
(SLeft
).Lo
then
8904 SRight
:= SRight
+ 1;
8906 -- Otherwise we have an overlapping entry
8913 -- Now we have two non-null operands, and first entries overlap. The
8914 -- first entry in the result will be the overlapping part of these
8917 FEnt
:= REnt
'(Lo => UI_Max (Left (SLeft).Lo, Right (SRight).Lo),
8918 Hi => UI_Min (Left (SLeft).Hi, Right (SRight).Hi));
8920 -- Now we can remove the entry that ended at a lower value, since its
8921 -- contribution is entirely contained in Fent.
8923 if Left (SLeft).Hi <= Right (SRight).Hi then
8926 SRight := SRight + 1;
8929 -- Compute result by concatenating this first entry with the "and" of
8930 -- the remaining parts of the left and right operands. Note that if
8931 -- either of these is empty, "and" will yield empty, so that we will
8932 -- end up with just Fent, which is what we want in that case.
8935 FEnt & (Left (SLeft .. Left'Last) and Right (SRight .. Right'Last));
8942 function "not" (Right : RList) return RList is
8944 -- Return True if False range
8946 if Is_False (Right) then
8950 -- Return False if True range
8952 if Is_True (Right) then
8956 -- Here if not trivial case
8959 Result : RList (1 .. Right'Length + 1);
8960 -- May need one more entry for gap at beginning and end
8963 -- Number of entries stored in Result
8968 if Right (Right'First).Lo > TLo then
8970 Result (Count) := REnt'(TLo
, Right
(Right
'First).Lo
- 1);
8973 -- Gaps between ranges
8975 for J
in Right
'First .. Right
'Last - 1 loop
8977 Result
(Count
) := REnt
'(Right (J).Hi + 1, Right (J + 1).Lo - 1);
8982 if Right (Right'Last).Hi < THi then
8984 Result (Count) := REnt'(Right
(Right
'Last).Hi
+ 1, THi
);
8987 return Result
(1 .. Count
);
8995 function "or" (Left
: RList
; Right
: RList
) return RList
is
8997 -- First range of result
8999 SLeft
: Nat
:= Left
'First;
9000 -- Start of rest of left entries
9002 SRight
: Nat
:= Right
'First;
9003 -- Start of rest of right entries
9006 -- If either range is True, return True
9008 if Is_True
(Left
) or else Is_True
(Right
) then
9012 -- If either range is False (empty), return the other
9014 if Is_False
(Left
) then
9016 elsif Is_False
(Right
) then
9020 -- Initialize result first entry from left or right operand depending
9021 -- on which starts with the lower range.
9023 if Left
(SLeft
).Lo
< Right
(SRight
).Lo
then
9024 FEnt
:= Left
(SLeft
);
9027 FEnt
:= Right
(SRight
);
9028 SRight
:= SRight
+ 1;
9031 -- This loop eats ranges from left and right operands that are
9032 -- contiguous with the first range we are gathering.
9035 -- Eat first entry in left operand if contiguous or overlapped by
9036 -- gathered first operand of result.
9038 if SLeft
<= Left
'Last
9039 and then Left
(SLeft
).Lo
<= FEnt
.Hi
+ 1
9041 FEnt
.Hi
:= UI_Max
(FEnt
.Hi
, Left
(SLeft
).Hi
);
9044 -- Eat first entry in right operand if contiguous or overlapped by
9045 -- gathered right operand of result.
9047 elsif SRight
<= Right
'Last
9048 and then Right
(SRight
).Lo
<= FEnt
.Hi
+ 1
9050 FEnt
.Hi
:= UI_Max
(FEnt
.Hi
, Right
(SRight
).Hi
);
9051 SRight
:= SRight
+ 1;
9053 -- All done if no more entries to eat
9060 -- Obtain result as the first entry we just computed, concatenated
9061 -- to the "or" of the remaining results (if one operand is empty,
9062 -- this will just concatenate with the other
9065 FEnt
& (Left
(SLeft
.. Left
'Last) or Right
(SRight
.. Right
'Last));
9072 function Build_Range
(Lo
: Uint
; Hi
: Uint
) return Node_Id
is
9077 Low_Bound
=> Build_Val
(Lo
),
9078 High_Bound
=> Build_Val
(Hi
));
9079 Set_Etype
(Result
, Btyp
);
9080 Set_Analyzed
(Result
);
9088 function Build_Val
(V
: Uint
) return Node_Id
is
9092 if Is_Enumeration_Type
(Typ
) then
9093 Result
:= Get_Enum_Lit_From_Pos
(Typ
, V
, Loc
);
9095 Result
:= Make_Integer_Literal
(Loc
, V
);
9098 Set_Etype
(Result
, Btyp
);
9099 Set_Is_Static_Expression
(Result
);
9100 Set_Analyzed
(Result
);
9110 Static
: access Boolean) return RList
9116 -- Static expression can only be true or false
9118 if Is_OK_Static_Expression
(Exp
) then
9119 if Expr_Value
(Exp
) = 0 then
9126 -- Otherwise test node type
9137 return Get_RList
(Left_Opnd
(Exp
), Static
)
9139 Get_RList
(Right_Opnd
(Exp
), Static
);
9146 return Get_RList
(Left_Opnd
(Exp
), Static
)
9148 Get_RList
(Right_Opnd
(Exp
), Static
);
9153 return not Get_RList
(Right_Opnd
(Exp
), Static
);
9155 -- Comparisons of type with static value
9157 when N_Op_Compare
=>
9159 -- Type is left operand
9161 if Is_Type_Ref
(Left_Opnd
(Exp
))
9162 and then Is_OK_Static_Expression
(Right_Opnd
(Exp
))
9164 Val
:= Expr_Value
(Right_Opnd
(Exp
));
9166 -- Typ is right operand
9168 elsif Is_Type_Ref
(Right_Opnd
(Exp
))
9169 and then Is_OK_Static_Expression
(Left_Opnd
(Exp
))
9171 Val
:= Expr_Value
(Left_Opnd
(Exp
));
9173 -- Invert sense of comparison
9176 when N_Op_Gt
=> Op
:= N_Op_Lt
;
9177 when N_Op_Lt
=> Op
:= N_Op_Gt
;
9178 when N_Op_Ge
=> Op
:= N_Op_Le
;
9179 when N_Op_Le
=> Op
:= N_Op_Ge
;
9180 when others => null;
9183 -- Other cases are non-static
9186 Static
.all := False;
9190 -- Construct range according to comparison operation
9194 return RList
'(1 => REnt'(Val
, Val
));
9197 return RList
'(1 => REnt'(Val
, BHi
));
9200 return RList
'(1 => REnt'(Val
+ 1, BHi
));
9203 return RList
'(1 => REnt'(BLo
, Val
));
9206 return RList
'(1 => REnt'(BLo
, Val
- 1));
9209 return RList
'(REnt'(BLo
, Val
- 1), REnt
'(Val + 1, BHi));
9212 raise Program_Error;
9218 if not Is_Type_Ref (Left_Opnd (Exp)) then
9219 Static.all := False;
9223 if Present (Right_Opnd (Exp)) then
9224 return Membership_Entry (Right_Opnd (Exp), Static);
9226 return Membership_Entries
9227 (First (Alternatives (Exp)), Static);
9230 -- Negative membership (NOT IN)
9233 if not Is_Type_Ref (Left_Opnd (Exp)) then
9234 Static.all := False;
9238 if Present (Right_Opnd (Exp)) then
9239 return not Membership_Entry (Right_Opnd (Exp), Static);
9241 return not Membership_Entries
9242 (First (Alternatives (Exp)), Static);
9245 -- Function call, may be call to static predicate
9247 when N_Function_Call =>
9248 if Is_Entity_Name (Name (Exp)) then
9250 Ent : constant Entity_Id := Entity (Name (Exp));
9252 if Is_Predicate_Function (Ent) then
9253 return Stat_Pred (Etype (First_Formal (Ent)), Static);
9258 -- Other function call cases are non-static
9260 Static.all := False;
9263 -- Qualified expression, dig out the expression
9265 when N_Qualified_Expression =>
9266 return Get_RList (Expression (Exp), Static);
9268 when N_Case_Expression =>
9275 if not Is_Entity_Name (Expression (Expr))
9276 or else Etype (Expression (Expr)) /= Typ
9279 ("expression must denote subtype", Expression (Expr));
9283 -- Collect discrete choices in all True alternatives
9285 Choices := New_List;
9286 Alt := First (Alternatives (Exp));
9287 while Present (Alt) loop
9288 Dep := Expression (Alt);
9290 if not Is_OK_Static_Expression (Dep) then
9291 Static.all := False;
9294 elsif Is_True (Expr_Value (Dep)) then
9295 Append_List_To (Choices,
9296 New_Copy_List (Discrete_Choices (Alt)));
9302 return Membership_Entries (First (Choices), Static);
9305 -- Expression with actions: if no actions, dig out expression
9307 when N_Expression_With_Actions =>
9308 if Is_Empty_List (Actions (Exp)) then
9309 return Get_RList (Expression (Exp), Static);
9311 Static.all := False;
9318 return (Get_RList (Left_Opnd (Exp), Static)
9319 and not Get_RList (Right_Opnd (Exp), Static))
9320 or (Get_RList (Right_Opnd (Exp), Static)
9321 and not Get_RList (Left_Opnd (Exp), Static));
9323 -- Any other node type is non-static
9326 Static.all := False;
9335 function Hi_Val (N : Node_Id) return Uint is
9337 if Is_OK_Static_Expression (N) then
9338 return Expr_Value (N);
9340 pragma Assert (Nkind (N) = N_Range);
9341 return Expr_Value (High_Bound (N));
9349 function Is_False (R : RList) return Boolean is
9351 return R'Length = 0;
9358 function Is_True (R : RList) return Boolean is
9361 and then R (R'First).Lo = BLo
9362 and then R (R'First).Hi = BHi;
9369 function Is_Type_Ref (N : Node_Id) return Boolean is
9371 return Nkind (N) = N_Identifier
9372 and then Chars (N) = Nam
9373 and then Paren_Count (N) = 0;
9380 function Lo_Val (N : Node_Id) return Uint is
9382 if Is_OK_Static_Expression (N) then
9383 return Expr_Value (N);
9385 pragma Assert (Nkind (N) = N_Range);
9386 return Expr_Value (Low_Bound (N));
9390 ------------------------
9391 -- Membership_Entries --
9392 ------------------------
9394 function Membership_Entries
9395 (N : Node_Id; Static : access Boolean) return RList is
9397 if No (Next (N)) then
9398 return Membership_Entry (N, Static);
9400 return Membership_Entry (N, Static)
9401 or Membership_Entries (Next (N), Static);
9403 end Membership_Entries;
9405 ----------------------
9406 -- Membership_Entry --
9407 ----------------------
9409 function Membership_Entry
9410 (N : Node_Id; Static : access Boolean) return RList
9419 if Nkind (N) = N_Range then
9420 if not Is_OK_Static_Expression (Low_Bound (N))
9422 not Is_OK_Static_Expression (High_Bound (N))
9424 Static.all := False;
9427 SLo := Expr_Value (Low_Bound (N));
9428 SHi := Expr_Value (High_Bound (N));
9429 return RList'(1 => REnt
'(SLo, SHi));
9434 elsif Nkind (N) = N_Others_Choice then
9436 Choices : constant List_Id := Others_Discrete_Choices (N);
9438 Range_List : RList (1 .. List_Length (Choices));
9441 Choice := First (Choices);
9443 for J in Range_List'Range loop
9444 Range_List (J) := REnt'(Lo_Val
(Choice
), Hi_Val
(Choice
));
9451 -- Static expression case
9453 elsif Is_OK_Static_Expression
(N
) then
9454 Val
:= Expr_Value
(N
);
9455 return RList
'(1 => REnt'(Val
, Val
));
9457 -- Identifier (other than static expression) case
9459 else pragma Assert
(Nkind
(N
) in N_Expanded_Name | N_Identifier
);
9463 if Is_Type
(Entity
(N
)) then
9465 -- If type has predicates, process them
9467 if Has_Predicates
(Entity
(N
)) then
9468 return Stat_Pred
(Entity
(N
), Static
);
9470 -- For static subtype without predicates, get range
9472 elsif Is_OK_Static_Subtype
(Entity
(N
)) then
9473 SLo
:= Expr_Value
(Type_Low_Bound
(Entity
(N
)));
9474 SHi
:= Expr_Value
(Type_High_Bound
(Entity
(N
)));
9475 return RList
'(1 => REnt'(SLo
, SHi
));
9477 -- Any other type makes us non-static
9480 Static
.all := False;
9484 -- Any other kind of identifier in predicate (e.g. a non-static
9485 -- expression value) means this is not a static predicate.
9488 Static
.all := False;
9492 end Membership_Entry
;
9500 Static
: access Boolean) return RList
is
9502 -- Not static if type does not have static predicates
9504 if not Has_Static_Predicate
(Typ
) then
9505 Static
.all := False;
9509 -- Otherwise we convert the predicate list to a range list
9512 Spred
: constant List_Id
:= Static_Discrete_Predicate
(Typ
);
9513 Result
: RList
(1 .. List_Length
(Spred
));
9517 P
:= First
(Static_Discrete_Predicate
(Typ
));
9518 for J
in Result
'Range loop
9519 Result
(J
) := REnt
'(Lo_Val (P), Hi_Val (P));
9527 -- Start of processing for Build_Discrete_Static_Predicate
9530 -- Establish bounds for the predicate
9532 if Compile_Time_Known_Value (Type_Low_Bound (Typ)) then
9533 TLo := Expr_Value (Type_Low_Bound (Typ));
9538 if Compile_Time_Known_Value (Type_High_Bound (Typ)) then
9539 THi := Expr_Value (Type_High_Bound (Typ));
9544 -- Analyze the expression to see if it is a static predicate
9547 Static : aliased Boolean := True;
9548 Ranges : constant RList := Get_RList (Expr, Static'Access);
9549 -- Range list from expression if it is static
9554 -- If non-static, return doing nothing
9560 -- Convert range list into a form for the static predicate. In the
9561 -- Ranges array, we just have raw ranges, these must be converted
9562 -- to properly typed and analyzed static expressions or range nodes.
9564 -- Note: here we limit ranges to the ranges of the subtype, so that
9565 -- a predicate is always false for values outside the subtype. That
9566 -- seems fine, such values are invalid anyway, and considering them
9567 -- to fail the predicate seems allowed and friendly, and furthermore
9568 -- simplifies processing for case statements and loops.
9572 for J in Ranges'Range loop
9574 Lo : Uint := Ranges (J).Lo;
9575 Hi : Uint := Ranges (J).Hi;
9578 -- Ignore completely out of range entry
9580 if Hi < TLo or else Lo > THi then
9583 -- Otherwise process entry
9586 -- Adjust out of range value to subtype range
9596 -- Convert range into required form
9598 Append_To (Plist, Build_Range (Lo, Hi));
9603 -- Processing was successful and all entries were static, so now we
9604 -- can store the result as the predicate list.
9606 Set_Static_Discrete_Predicate (Typ, Plist);
9608 -- Within a generic the predicate functions themselves need not
9611 if Inside_A_Generic then
9615 -- The processing for static predicates put the expression into
9616 -- canonical form as a series of ranges. It also eliminated
9617 -- duplicates and collapsed and combined ranges. We might as well
9618 -- replace the alternatives list of the right operand of the
9619 -- membership test with the static predicate list, which will
9620 -- usually be more efficient.
9623 New_Alts : constant List_Id := New_List;
9628 Old_Node := First (Plist);
9629 while Present (Old_Node) loop
9630 New_Node := New_Copy (Old_Node);
9632 if Nkind (New_Node) = N_Range then
9633 Set_Low_Bound (New_Node, New_Copy (Low_Bound (Old_Node)));
9634 Set_High_Bound (New_Node, New_Copy (High_Bound (Old_Node)));
9637 Append_To (New_Alts, New_Node);
9641 -- If empty list, replace by False
9643 if Is_Empty_List (New_Alts) then
9644 Rewrite (Expr, New_Occurrence_Of (Standard_False, Loc));
9646 -- Else replace by set membership test
9651 Left_Opnd => Make_Identifier (Loc, Nam),
9652 Right_Opnd => Empty,
9653 Alternatives => New_Alts));
9655 -- Resolve new expression in function context
9657 Install_Formals (Predicate_Function (Typ));
9658 Push_Scope (Predicate_Function (Typ));
9659 Analyze_And_Resolve (Expr, Standard_Boolean);
9664 end Build_Discrete_Static_Predicate;
9666 --------------------------------
9667 -- Build_Export_Import_Pragma --
9668 --------------------------------
9670 function Build_Export_Import_Pragma
9672 Id : Entity_Id) return Node_Id
9674 Asp_Id : constant Aspect_Id := Get_Aspect_Id (Asp);
9675 Expr : constant Node_Id := Expression (Asp);
9676 Loc : constant Source_Ptr := Sloc (Asp);
9687 Create_Pragma : Boolean := False;
9688 -- This flag is set when the aspect form is such that it warrants the
9689 -- creation of a corresponding pragma.
9692 if Present (Expr) then
9693 if Error_Posted (Expr) then
9696 elsif Is_True (Expr_Value (Expr)) then
9697 Create_Pragma := True;
9700 -- Otherwise the aspect defaults to True
9703 Create_Pragma := True;
9706 -- Nothing to do when the expression is False or is erroneous
9708 if not Create_Pragma then
9712 -- Obtain all interfacing aspects that apply to the related entity
9714 Get_Interfacing_Aspects
9718 Expo_Asp => Dummy_1,
9724 -- Handle the convention argument
9726 if Present (Conv) then
9727 Conv_Arg := New_Copy_Tree (Expression (Conv));
9729 -- Assume convention "Ada' when aspect Convention
is missing
9732 Conv_Arg
:= Make_Identifier
(Loc
, Name_Ada
);
9736 Make_Pragma_Argument_Association
(Loc
,
9737 Chars
=> Name_Convention
,
9738 Expression
=> Conv_Arg
));
9740 -- Handle the entity argument
9743 Make_Pragma_Argument_Association
(Loc
,
9744 Chars
=> Name_Entity
,
9745 Expression
=> New_Occurrence_Of
(Id
, Loc
)));
9747 -- Handle the External_Name argument
9749 if Present
(EN
) then
9751 Make_Pragma_Argument_Association
(Loc
,
9752 Chars
=> Name_External_Name
,
9753 Expression
=> New_Copy_Tree
(Expression
(EN
))));
9756 -- Handle the Link_Name argument
9758 if Present
(LN
) then
9760 Make_Pragma_Argument_Association
(Loc
,
9761 Chars
=> Name_Link_Name
,
9762 Expression
=> New_Copy_Tree
(Expression
(LN
))));
9766 -- pragma Export/Import
9767 -- (Convention => <Conv>/Ada,
9769 -- [External_Name => <EN>,]
9770 -- [Link_Name => <LN>]);
9774 Pragma_Identifier
=>
9775 Make_Identifier
(Loc
, Chars
(Identifier
(Asp
))),
9776 Pragma_Argument_Associations
=> Args
);
9778 -- Decorate the relevant aspect and the pragma
9780 Set_Aspect_Rep_Item
(Asp
, Prag
);
9782 Set_Corresponding_Aspect
(Prag
, Asp
);
9783 Set_From_Aspect_Specification
(Prag
);
9784 Set_Parent
(Prag
, Asp
);
9786 if Asp_Id
= Aspect_Import
and then Is_Subprogram
(Id
) then
9787 Set_Import_Pragma
(Id
, Prag
);
9791 end Build_Export_Import_Pragma
;
9793 ------------------------------
9794 -- Build_Predicate_Function --
9795 ------------------------------
9797 -- The function constructed here has the form:
9799 -- function typPredicate (Ixxx : typ) return Boolean is
9802 -- typ1Predicate (typ1 (Ixxx))
9803 -- and then typ2Predicate (typ2 (Ixxx))
9805 -- and then exp1 and then exp2 and then ...;
9806 -- end typPredicate;
9808 -- If Predicate_Function_Needs_Membership_Parameter is true, then this
9809 -- function takes an additional boolean parameter; the parameter
9810 -- indicates whether the predicate evaluation is part of a membership
9811 -- test. This parameter is used in two cases: 1) It is passed along
9812 -- if another predicate function is called and that predicate function
9813 -- expects to be passed a boolean parameter. 2) If the Predicate_Failure
9814 -- aspect is directly specified for typ, then we replace the return
9815 -- expression described above with
9816 -- (if <expression described above> then True
9817 -- elsif For_Membership_Test then False
9818 -- else (raise Assertion_Error
9819 -- with <Predicate_Failure expression>))
9820 -- Here exp1, and exp2 are expressions from Predicate pragmas. Note that
9821 -- this is the point at which these expressions get analyzed, providing the
9822 -- required delay, and typ1, typ2, are entities from which predicates are
9823 -- inherited. Note that we do NOT generate Check pragmas, that's because we
9824 -- use this function even if checks are off, e.g. for membership tests.
9826 -- Note that the inherited predicates are evaluated first, as required by
9829 -- Note that Sem_Eval.Real_Or_String_Static_Predicate_Matches depends on
9830 -- the form of this return expression.
9832 -- WARNING: This routine manages Ghost regions. Return statements must be
9833 -- replaced by gotos which jump to the end of the routine and restore the
9836 procedure Build_Predicate_Function
(Typ
: Entity_Id
; N
: Node_Id
) is
9837 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
9840 -- This is the expression for the result of the function. It is
9841 -- is build by connecting the component predicates with AND THEN.
9843 Object_Name
: Name_Id
;
9844 -- Name for argument of Predicate procedure. Note that we use the same
9845 -- name for both predicate functions. That way the reference within the
9846 -- predicate expression is the same in both functions.
9848 Object_Entity
: Entity_Id
;
9849 -- Entity for argument of Predicate procedure
9852 -- The function declaration
9857 Ancestor_Predicate_Function_Called
: Boolean := False;
9858 -- Does this predicate function include a call to the
9859 -- predication function of an ancestor subtype?
9861 procedure Add_Condition
(Cond
: Node_Id
);
9862 -- Append Cond to Expr using "and then" (or just copy Cond to Expr if
9865 procedure Add_Predicates
;
9866 -- Appends expressions for any Predicate pragmas in the rep item chain
9867 -- Typ to Expr. Note that we look only at items for this exact entity.
9868 -- Inheritance of predicates for the parent type is done by calling the
9869 -- Predicate_Function of the parent type, using Add_Call above.
9871 procedure Add_Call
(T
: Entity_Id
);
9872 -- Includes a call to the predicate function for type T in Expr if
9873 -- Predicate_Function (T) is non-empty.
9875 procedure Replace_Current_Instance_References
9876 (N
: Node_Id
; Typ
, New_Entity
: Entity_Id
);
9877 -- Replace all references to Typ in the tree rooted at N with
9878 -- references to Param. [New_Entity will be a formal parameter of a
9879 -- predicate function.]
9885 procedure Add_Call
(T
: Entity_Id
) is
9889 if Present
(Predicate_Function
(T
)) then
9890 pragma Assert
(Has_Predicates
(Typ
));
9892 -- Build the call to the predicate function of T. The type may be
9893 -- derived, so use an unchecked conversion for the actual.
9896 Dynamic_Mem
: Node_Id
:= Empty
;
9897 Second_Formal
: constant Entity_Id
:=
9898 Next_Entity
(Object_Entity
);
9900 -- Some predicate functions require a second parameter;
9901 -- If one predicate function calls another and the second
9902 -- requires two parameters, then the first should also
9903 -- take two parameters (so that the first function has
9904 -- something to pass to the second function).
9905 if Predicate_Function_Needs_Membership_Parameter
(T
) then
9906 pragma Assert
(Present
(Second_Formal
));
9907 Dynamic_Mem
:= New_Occurrence_Of
(Second_Formal
, Loc
);
9914 Unchecked_Convert_To
(T
,
9915 Make_Identifier
(Loc
, Object_Name
)),
9916 Dynamic_Mem
=> Dynamic_Mem
);
9919 -- "and"-in the call to evolving expression
9921 Add_Condition
(Exp
);
9922 Ancestor_Predicate_Function_Called
:= True;
9924 -- Output info message on inheritance if required. Note we do not
9925 -- give this information for generic actual types, since it is
9926 -- unwelcome noise in that case in instantiations. We also
9927 -- generally suppress the message in instantiations, and also
9928 -- if it involves internal names.
9930 if Opt
.List_Inherited_Aspects
9931 and then not Is_Generic_Actual_Type
(Typ
)
9932 and then Instantiation_Depth
(Sloc
(Typ
)) = 0
9933 and then not Is_Internal_Name
(Chars
(T
))
9934 and then not Is_Internal_Name
(Chars
(Typ
))
9936 Error_Msg_Sloc
:= Sloc
(Predicate_Function
(T
));
9937 Error_Msg_Node_2
:= T
;
9938 Error_Msg_N
("info: & inherits predicate from & #?.l?", Typ
);
9947 procedure Add_Condition
(Cond
: Node_Id
) is
9949 -- This is the first predicate expression
9954 -- Otherwise concatenate to the existing predicate expressions by
9955 -- using "and then".
9960 Left_Opnd
=> Relocate_Node
(Expr
),
9961 Right_Opnd
=> Cond
);
9965 --------------------
9966 -- Add_Predicates --
9967 --------------------
9969 procedure Add_Predicates
is
9970 procedure Add_Predicate
(Prag
: Node_Id
);
9971 -- Concatenate the expression of predicate pragma Prag to Expr by
9972 -- using a short circuit "and then" operator.
9978 procedure Add_Predicate
(Prag
: Node_Id
) is
9981 Asp
: constant Node_Id
:= Corresponding_Aspect
(Prag
);
9985 -- Start of processing for Add_Predicate
9988 -- Mark corresponding SCO as enabled
9990 Set_SCO_Pragma_Enabled
(Sloc
(Prag
));
9992 -- Extract the arguments of the pragma
9994 Arg1
:= First
(Pragma_Argument_Associations
(Prag
));
9995 Arg2
:= Next
(Arg1
);
9997 Arg1
:= Get_Pragma_Arg
(Arg1
);
9998 Arg2
:= Get_Pragma_Arg
(Arg2
);
10000 -- When the predicate pragma applies to the current type or its
10001 -- full view, replace all occurrences of the subtype name with
10002 -- references to the formal parameter of the predicate function.
10004 if Entity
(Arg1
) = Typ
10005 or else Full_View
(Entity
(Arg1
)) = Typ
10008 Arg2_Copy
: constant Node_Id
:= New_Copy_Tree
(Arg2
);
10010 Replace_Current_Instance_References
10011 (Arg2_Copy
, Typ
=> Typ
, New_Entity
=> Object_Entity
);
10013 -- If the predicate pragma comes from an aspect, replace the
10014 -- saved expression because we need the subtype references
10015 -- replaced for the calls to Preanalyze_Spec_Expression in
10016 -- Check_Aspect_At_xxx routines.
10018 if Present
(Asp
) then
10019 Set_Entity
(Identifier
(Asp
), New_Copy_Tree
(Arg2_Copy
));
10022 -- "and"-in the Arg2 condition to evolving expression
10024 Add_Condition
(Arg2_Copy
);
10033 -- Start of processing for Add_Predicates
10036 Ritem
:= First_Rep_Item
(Typ
);
10038 -- If the type is private, check whether full view has inherited
10041 if Is_Private_Type
(Typ
)
10042 and then No
(Ritem
)
10043 and then Present
(Full_View
(Typ
))
10045 Ritem
:= First_Rep_Item
(Full_View
(Typ
));
10048 while Present
(Ritem
) loop
10049 if Nkind
(Ritem
) = N_Pragma
10050 and then Pragma_Name
(Ritem
) = Name_Predicate
10052 Add_Predicate
(Ritem
);
10054 -- If the type is declared in an inner package it may be frozen
10055 -- outside of the package, and the generated pragma has not been
10056 -- analyzed yet, so capture the expression for the predicate
10057 -- function at this point.
10059 elsif Nkind
(Ritem
) = N_Aspect_Specification
10060 and then Present
(Aspect_Rep_Item
(Ritem
))
10061 and then Scope_Depth
(Scope
(Typ
)) > Scope_Depth
(Current_Scope
)
10064 Prag
: constant Node_Id
:= Aspect_Rep_Item
(Ritem
);
10067 if Nkind
(Prag
) = N_Pragma
10068 and then Pragma_Name
(Prag
) = Name_Predicate
10070 Add_Predicate
(Prag
);
10075 Next_Rep_Item
(Ritem
);
10077 end Add_Predicates
;
10079 -----------------------------------------
10080 -- Replace_Current_Instance_References --
10081 -----------------------------------------
10083 procedure Replace_Current_Instance_References
10084 (N
: Node_Id
; Typ
, New_Entity
: Entity_Id
)
10086 Root
: Node_Id
renames N
;
10088 procedure Replace_One_Reference
(N
: Node_Id
);
10089 -- Actual parameter for Replace_Type_References_Generic instance
10091 ---------------------------
10092 -- Replace_One_Reference --
10093 ---------------------------
10095 procedure Replace_One_Reference
(N
: Node_Id
) is
10096 pragma Assert
(In_Subtree
(N
, Root
=> Root
));
10098 Rewrite
(N
, New_Occurrence_Of
(New_Entity
, Sloc
(N
)));
10099 -- Use the Sloc of the usage name, not the defining name
10100 end Replace_One_Reference
;
10102 procedure Replace_Type_References
is
10103 new Replace_Type_References_Generic
(Replace_One_Reference
);
10105 Replace_Type_References
(N
, Typ
);
10106 end Replace_Current_Instance_References
;
10110 Saved_GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
10111 Saved_IGR
: constant Node_Id
:= Ignored_Ghost_Region
;
10112 -- Save the Ghost-related attributes to restore on exit
10114 -- Start of processing for Build_Predicate_Function
10117 -- Return if already built, if type does not have predicates,
10118 -- or if type is a constructed subtype that will inherit a
10119 -- predicate function from its ancestor. In a generic context
10120 -- the predicated parent may not have a predicate function yet
10121 -- but we don't want to build a new one for the subtype. This can
10122 -- happen in an instance body which is nested within a generic
10123 -- unit, in which case Within_A_Generic may be false, SId is
10124 -- Empty, but uses of Typ will receive a predicate check in a
10125 -- context where expansion and tests are enabled.
10127 SId
:= Predicate_Function
(Typ
);
10128 if not Has_Predicates
(Typ
)
10129 or else (Present
(SId
) and then Has_Completion
(SId
))
10132 and then not Comes_From_Source
(Typ
)
10133 and then Ekind
(Typ
) in E_Array_Subtype
10135 | E_Record_Subtype_With_Private
10136 and then Present
(Predicated_Parent
(Typ
)))
10140 -- Do not generate predicate bodies within a generic unit. The
10141 -- expressions have been analyzed already, and the bodies play no role
10142 -- if not within an executable unit. However, if a static predicate is
10143 -- present it must be processed for legality checks such as case
10144 -- coverage in an expression.
10146 elsif Inside_A_Generic
10147 and then not Has_Static_Predicate_Aspect
(Typ
)
10152 -- The related type may be subject to pragma Ghost. Set the mode now to
10153 -- ensure that the predicate functions are properly marked as Ghost.
10155 Set_Ghost_Mode
(Typ
);
10157 -- Prepare to construct predicate expression
10161 if Present
(SId
) then
10162 FDecl
:= Unit_Declaration_Node
(SId
);
10165 FDecl
:= Build_Predicate_Function_Declaration
(Typ
);
10166 SId
:= Defining_Entity
(FDecl
);
10169 -- Recover name of formal parameter of function that replaces references
10170 -- to the type in predicate expressions.
10173 Defining_Identifier
10174 (First
(Parameter_Specifications
(Specification
(FDecl
))));
10176 Object_Name
:= Chars
(Object_Entity
);
10178 -- Add predicates for ancestor if present. These must come before the
10179 -- ones for the current type, as required by AI12-0071-1.
10181 -- Looks like predicates aren't added for case of inheriting from
10182 -- multiple progenitors???
10187 Atyp
:= Nearest_Ancestor
(Typ
);
10189 -- The type may be private but the full view may inherit predicates
10191 if No
(Atyp
) and then Is_Private_Type
(Typ
) then
10192 Atyp
:= Nearest_Ancestor
(Full_View
(Typ
));
10195 if Present
(Atyp
) then
10200 -- Add Predicates for the current type
10204 -- Case where predicates are present
10206 if Present
(Expr
) then
10208 -- Build the main predicate function
10211 SIdB
: constant Entity_Id
:=
10212 Make_Defining_Identifier
(Loc
,
10213 Chars
=> New_External_Name
(Chars
(Typ
), "Predicate"));
10214 -- The entity for the function body
10220 Mutate_Ekind
(SIdB
, E_Function
);
10221 Set_Is_Predicate_Function
(SIdB
);
10223 -- Build function body
10226 Param_Specs
: constant List_Id
:= New_List
(
10227 Make_Parameter_Specification
(Loc
,
10228 Defining_Identifier
=>
10229 Make_Defining_Identifier
(Loc
, Object_Name
),
10231 New_Occurrence_Of
(Typ
, Loc
)));
10233 -- if Spec has 2 parameters, then body should too
10234 if Present
(Next_Entity
(Object_Entity
)) then
10235 Append
(Make_Parameter_Specification
(Loc
,
10236 Defining_Identifier
=>
10237 Make_Defining_Identifier
10238 (Loc
, Chars
(Next_Entity
(Object_Entity
))),
10240 New_Occurrence_Of
(Standard_Boolean
, Loc
)),
10245 Make_Function_Specification
(Loc
,
10246 Defining_Unit_Name
=> SIdB
,
10247 Parameter_Specifications
=> Param_Specs
,
10248 Result_Definition
=>
10249 New_Occurrence_Of
(Standard_Boolean
, Loc
));
10252 -- The Predicate_Expression attribute is used by SPARK.
10254 -- If Ancestor_Predicate_Function_Called is True, then
10255 -- we try to exclude that call to the ancestor's
10256 -- predicate function by calling Right_Opnd.
10257 -- The call is not excluded in the case where
10258 -- it is not "and"ed with anything else (so we don't have
10259 -- an N_And_Then node). This exclusion is required if the
10260 -- Predicate_Failure aspect is specified for Typ because
10261 -- in that case we are going to drop the N_And_Then node
10262 -- on the floor. Otherwise, it is a question of what is
10263 -- most convenient for SPARK.
10265 Set_Predicate_Expression
10266 (SId
, (if Ancestor_Predicate_Function_Called
10267 and then Nkind
(Expr
) = N_And_Then
10268 then Right_Opnd
(Expr
)
10272 Result_Expr
: Node_Id
:= Expr
;
10273 PF_Expr
: Node_Id
:= Predicate_Failure_Expression
10274 (Typ
, Inherited_OK
=> False);
10275 PF_Expr_Copy
: Node_Id
;
10276 Second_Formal
: constant Entity_Id
:=
10277 Next_Entity
(Object_Entity
);
10279 -- In GNATprove mode we are only interested in the predicate
10280 -- expression itself and don't want a raise expression that
10281 -- comes from the Predicate_Failure. Ditto for CodePeer.
10282 -- And an illegal Predicate_Failure aspect can lead to cases
10283 -- we want to avoid.
10285 if Present
(PF_Expr
)
10286 and then not GNATprove_Mode
10287 and then not CodePeer_Mode
10288 and then Serious_Errors_Detected
= 0
10290 pragma Assert
(Present
(Second_Formal
));
10292 -- This is an ugly hack to cope with an ugly situation.
10293 -- PF_Expr may have children whose Parent attribute
10294 -- does not point back to PF_Expr. If we pass such a
10295 -- tree to New_Copy_Tree, then it does not make a deep
10296 -- copy. But we need a deep copy. So we need to find a
10297 -- tree for which New_Copy_Tree *will* make a deep copy.
10300 function Check_Node_Parent
(Parent_Node
, Node
: Node_Id
)
10301 return Traverse_Result
;
10302 function Check_Node_Parent
(Parent_Node
, Node
: Node_Id
)
10303 return Traverse_Result
is
10305 if Parent_Node
= PF_Expr
10306 and then not Is_List_Member
(Node
)
10309 (Nkind
(PF_Expr
) = Nkind
(Parent
(Node
)));
10311 -- We need PF_Expr to be a node for which
10312 -- New_Copy_Tree will make a deep copy.
10313 PF_Expr
:= Parent
(Node
);
10317 end Check_Node_Parent
;
10318 procedure Check_Parentage
is
10319 new Traverse_Proc_With_Parent
(Check_Node_Parent
);
10321 Check_Parentage
(PF_Expr
);
10322 PF_Expr_Copy
:= New_Copy_Tree
(PF_Expr
);
10325 -- Current instance uses need to have their Entity
10326 -- fields set so that Replace_Current_Instance_References
10327 -- can find them. So we preanalyze. Just for purposes of
10328 -- calls to Is_Current_Instance during this preanalysis,
10329 -- we set the Parent field.
10330 Set_Parent
(PF_Expr_Copy
, Parent
(PF_Expr
));
10331 Preanalyze
(PF_Expr_Copy
);
10332 Set_Parent
(PF_Expr_Copy
, Empty
);
10334 Replace_Current_Instance_References
10335 (PF_Expr_Copy
, Typ
=> Typ
, New_Entity
=> Object_Entity
);
10337 if Ancestor_Predicate_Function_Called
then
10338 -- If the call to an ancestor predicate function
10339 -- returns False, we do not want to raise an
10340 -- exception here. Our Predicate_Failure aspect does
10341 -- not apply in that case. So we have to build a
10342 -- more complicated result expression:
10343 -- (if not Ancestor_Predicate_Function (...) then False
10344 -- elsif Noninherited_Predicates (...) then True
10345 -- elsif Is_Membership_Test then False
10346 -- else (raise Assertion_Error with PF text))
10349 Ancestor_Call
: constant Node_Id
:=
10350 Left_Opnd
(Result_Expr
);
10351 Local_Preds
: constant Node_Id
:=
10352 Right_Opnd
(Result_Expr
);
10355 Make_If_Expression
(Loc
,
10356 Expressions
=> New_List
(
10357 Make_Op_Not
(Loc
, Ancestor_Call
),
10358 New_Occurrence_Of
(Standard_False
, Loc
),
10359 Make_If_Expression
(Loc
,
10361 Expressions
=> New_List
(
10363 New_Occurrence_Of
(Standard_True
, Loc
),
10364 Make_If_Expression
(Loc
,
10366 Expressions
=> New_List
(
10367 New_Occurrence_Of
(Second_Formal
, Loc
),
10368 New_Occurrence_Of
(Standard_False
, Loc
),
10369 Make_Raise_Expression
(Loc
,
10370 New_Occurrence_Of
(RTE
10371 (RE_Assert_Failure
), Loc
),
10372 PF_Expr_Copy
)))))));
10376 -- Build a conditional expression:
10377 -- (if <predicate evaluates to True> then True
10378 -- elsif Is_Membership_Test then False
10379 -- else (raise Assertion_Error with PF text))
10382 Make_If_Expression
(Loc
,
10383 Expressions
=> New_List
(
10385 New_Occurrence_Of
(Standard_True
, Loc
),
10386 Make_If_Expression
(Loc
,
10388 Expressions
=> New_List
(
10389 New_Occurrence_Of
(Second_Formal
, Loc
),
10390 New_Occurrence_Of
(Standard_False
, Loc
),
10391 Make_Raise_Expression
(Loc
,
10392 New_Occurrence_Of
(RTE
10393 (RE_Assert_Failure
), Loc
),
10399 Make_Subprogram_Body
(Loc
,
10400 Specification
=> Spec
,
10401 Declarations
=> Empty_List
,
10402 Handled_Statement_Sequence
=>
10403 Make_Handled_Sequence_Of_Statements
(Loc
,
10404 Statements
=> New_List
(
10405 Make_Simple_Return_Statement
(Loc
,
10406 Expression
=> Result_Expr
))));
10409 -- The declaration has been analyzed when created, and placed
10410 -- after type declaration. Insert body itself after freeze node,
10411 -- unless subprogram declaration is already there, in which case
10412 -- body better be placed afterwards.
10414 if FDecl
= Next
(N
) then
10415 Insert_After_And_Analyze
(FDecl
, FBody
);
10417 Insert_After_And_Analyze
(N
, FBody
);
10420 -- The defining identifier of a quantified expression carries the
10421 -- scope in which the type appears, but when unnesting we need
10422 -- to indicate that its proper scope is the constructed predicate
10423 -- function. The quantified expressions have been converted into
10424 -- loops during analysis and expansion.
10427 function Reset_Quantified_Variable_Scope
10428 (N
: Node_Id
) return Traverse_Result
;
10430 procedure Reset_Quantified_Variables_Scope
is
10431 new Traverse_Proc
(Reset_Quantified_Variable_Scope
);
10433 -------------------------------------
10434 -- Reset_Quantified_Variable_Scope --
10435 -------------------------------------
10437 function Reset_Quantified_Variable_Scope
10438 (N
: Node_Id
) return Traverse_Result
is
10440 if Nkind
(N
) in N_Iterator_Specification
10441 | N_Loop_Parameter_Specification
10443 Set_Scope
(Defining_Identifier
(N
),
10444 Predicate_Function
(Typ
));
10448 end Reset_Quantified_Variable_Scope
;
10451 if Unnest_Subprogram_Mode
then
10452 Reset_Quantified_Variables_Scope
(Expr
);
10456 -- Within a generic unit, prevent a double analysis of the body
10457 -- which will not be marked analyzed yet. This will happen when
10458 -- the freeze node is created during the preanalysis of an
10459 -- expression function.
10461 if Inside_A_Generic
then
10462 Set_Analyzed
(FBody
);
10465 -- Static predicate functions are always side-effect free, and
10466 -- in most cases dynamic predicate functions are as well. Mark
10467 -- them as such whenever possible, so redundant predicate checks
10468 -- can be optimized. If there is a variable reference within the
10469 -- expression, the function is not pure.
10471 if Expander_Active
then
10473 Side_Effect_Free
(Expr
, Variable_Ref
=> True));
10474 Set_Is_Inlined
(SId
);
10478 -- See if we have a static predicate. Note that the answer may be
10479 -- yes even if we have an explicit Dynamic_Predicate present.
10486 if not Is_Scalar_Type
(Typ
) and then not Is_String_Type
(Typ
) then
10489 PS
:= Is_Predicate_Static
(Expr
, Object_Name
);
10492 -- Case where we have a predicate-static aspect
10496 -- We don't set Has_Static_Predicate_Aspect, since we can have
10497 -- any of the three cases (Predicate, Dynamic_Predicate, or
10498 -- Static_Predicate) generating a predicate with an expression
10499 -- that is predicate-static. We just indicate that we have a
10500 -- predicate that can be treated as static.
10502 Set_Has_Static_Predicate
(Typ
);
10504 -- For discrete subtype, build the static predicate list
10506 if Is_Discrete_Type
(Typ
) then
10507 Build_Discrete_Static_Predicate
(Typ
, Expr
, Object_Name
);
10509 -- If we don't get a static predicate list, it means that we
10510 -- have a case where this is not possible, most typically in
10511 -- the case where we inherit a dynamic predicate. We do not
10512 -- consider this an error, we just leave the predicate as
10513 -- dynamic. But if we do succeed in building the list, then
10514 -- we mark the predicate as static.
10516 if No
(Static_Discrete_Predicate
(Typ
)) then
10517 Set_Has_Static_Predicate
(Typ
, False);
10520 -- For real or string subtype, save predicate expression
10522 elsif Is_Real_Type
(Typ
) or else Is_String_Type
(Typ
) then
10523 Set_Static_Real_Or_String_Predicate
(Typ
, Expr
);
10526 -- Case of dynamic predicate (expression is not predicate-static)
10529 -- Again, we don't set Has_Dynamic_Predicate_Aspect, since that
10530 -- is only set if we have an explicit Dynamic_Predicate aspect
10531 -- given. Here we may simply have a Predicate aspect where the
10532 -- expression happens not to be predicate-static.
10534 -- Emit an error when the predicate is categorized as static
10535 -- but its expression is not predicate-static.
10537 -- First a little fiddling to get a nice location for the
10538 -- message. If the expression is of the form (A and then B),
10539 -- where A is an inherited predicate, then use the right
10540 -- operand for the Sloc. This avoids getting confused by a call
10541 -- to an inherited predicate with a less convenient source
10545 while Nkind
(EN
) = N_And_Then
10546 and then Nkind
(Left_Opnd
(EN
)) = N_Function_Call
10547 and then Is_Predicate_Function
10548 (Entity
(Name
(Left_Opnd
(EN
))))
10550 EN
:= Right_Opnd
(EN
);
10553 -- Now post appropriate message
10555 if Has_Static_Predicate_Aspect
(Typ
) then
10556 if Is_Scalar_Type
(Typ
) or else Is_String_Type
(Typ
) then
10558 ("expression is not predicate-static (RM 3.2.4(16-22))",
10562 ("static predicate requires scalar or string type", EN
);
10569 Restore_Ghost_Region
(Saved_GM
, Saved_IGR
);
10570 end Build_Predicate_Function
;
10572 ------------------------------------------
10573 -- Build_Predicate_Function_Declaration --
10574 ------------------------------------------
10576 -- WARNING: This routine manages Ghost regions. Return statements must be
10577 -- replaced by gotos which jump to the end of the routine and restore the
10580 function Build_Predicate_Function_Declaration
10581 (Typ
: Entity_Id
) return Node_Id
10583 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
10585 Saved_GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
10586 Saved_IGR
: constant Node_Id
:= Ignored_Ghost_Region
;
10587 -- Save the Ghost-related attributes to restore on exit
10589 Func_Decl
: Node_Id
;
10590 Func_Id
: Entity_Id
;
10593 CRec_Typ
: Entity_Id
;
10594 -- The corresponding record type of Full_Typ
10596 Full_Typ
: Entity_Id
;
10597 -- The full view of Typ
10599 Priv_Typ
: Entity_Id
;
10600 -- The partial view of Typ
10602 UFull_Typ
: Entity_Id
;
10603 -- The underlying full view of Full_Typ
10606 -- The related type may be subject to pragma Ghost. Set the mode now to
10607 -- ensure that the predicate functions are properly marked as Ghost.
10609 Set_Ghost_Mode
(Typ
);
10612 Make_Defining_Identifier
(Loc
,
10613 Chars
=> New_External_Name
(Chars
(Typ
), "Predicate"));
10615 Mutate_Ekind
(Func_Id
, E_Function
);
10616 Set_Etype
(Func_Id
, Standard_Boolean
);
10617 Set_Is_Internal
(Func_Id
);
10618 Set_Is_Predicate_Function
(Func_Id
);
10619 Set_Predicate_Function
(Typ
, Func_Id
);
10621 -- The predicate function requires debug info when the predicates are
10622 -- subject to Source Coverage Obligations.
10624 if Opt
.Generate_SCO
then
10625 Set_Debug_Info_Needed
(Func_Id
);
10628 -- Obtain all views of the input type
10630 Get_Views
(Typ
, Priv_Typ
, Full_Typ
, UFull_Typ
, CRec_Typ
);
10632 -- Associate the predicate function and various flags with all views
10634 Propagate_Predicate_Attributes
(Priv_Typ
, From_Typ
=> Typ
);
10635 Propagate_Predicate_Attributes
(Full_Typ
, From_Typ
=> Typ
);
10636 Propagate_Predicate_Attributes
(UFull_Typ
, From_Typ
=> Typ
);
10637 Propagate_Predicate_Attributes
(CRec_Typ
, From_Typ
=> Typ
);
10640 Param_Specs
: constant List_Id
:= New_List
(
10641 Make_Parameter_Specification
(Loc
,
10642 Defining_Identifier
=> Make_Temporary
(Loc
, 'I'),
10643 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)));
10645 if Predicate_Function_Needs_Membership_Parameter
(Typ
) then
10646 -- Add Boolean-valued For_Membership_Test param
10647 Append
(Make_Parameter_Specification
(Loc
,
10648 Defining_Identifier
=> Make_Temporary
(Loc
, 'M'),
10650 New_Occurrence_Of
(Standard_Boolean
, Loc
)),
10655 Make_Function_Specification
(Loc
,
10656 Defining_Unit_Name
=> Func_Id
,
10657 Parameter_Specifications
=> Param_Specs
,
10658 Result_Definition
=>
10659 New_Occurrence_Of
(Standard_Boolean
, Loc
));
10662 Func_Decl
:= Make_Subprogram_Declaration
(Loc
, Specification
=> Spec
);
10664 Insert_After
(Parent
(Typ
), Func_Decl
);
10665 Analyze
(Func_Decl
);
10667 Restore_Ghost_Region
(Saved_GM
, Saved_IGR
);
10670 end Build_Predicate_Function_Declaration
;
10672 -----------------------------------------
10673 -- Check_Aspect_At_End_Of_Declarations --
10674 -----------------------------------------
10676 procedure Check_Aspect_At_End_Of_Declarations
(ASN
: Node_Id
) is
10677 Ent
: constant Entity_Id
:= Entity
(ASN
);
10678 Ident
: constant Node_Id
:= Identifier
(ASN
);
10679 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Chars
(Ident
));
10681 End_Decl_Expr
: constant Node_Id
:= Entity
(Ident
);
10682 -- Expression to be analyzed at end of declarations
10684 Freeze_Expr
: constant Node_Id
:= Expression
(ASN
);
10685 -- Expression from call to Check_Aspect_At_Freeze_Point.
10687 T
: constant Entity_Id
:=
10688 (if Present
(Freeze_Expr
) and (A_Id
/= Aspect_Stable_Properties
)
10689 then Etype
(Original_Node
(Freeze_Expr
))
10691 -- Type required for preanalyze call. We use the original expression to
10692 -- get the proper type, to prevent cascaded errors when the expression
10693 -- is constant-folded. For Stable_Properties, the aspect value is
10694 -- not semantically an expression (although it is syntactically);
10695 -- in particular, it has no type.
10698 -- Set True if error
10700 -- On entry to this procedure, Entity (Ident) contains a copy of the
10701 -- original expression from the aspect, saved for this purpose, and
10702 -- but Expression (Ident) is a preanalyzed copy of the expression,
10703 -- preanalyzed just after the freeze point.
10705 procedure Check_Overloaded_Name
;
10706 -- For aspects whose expression is simply a name, this routine checks if
10707 -- the name is overloaded or not. If so, it verifies there is an
10708 -- interpretation that matches the entity obtained at the freeze point,
10709 -- otherwise the compiler complains.
10711 ---------------------------
10712 -- Check_Overloaded_Name --
10713 ---------------------------
10715 procedure Check_Overloaded_Name
is
10717 if not Is_Overloaded
(End_Decl_Expr
) then
10718 Err
:= not Is_Entity_Name
(End_Decl_Expr
)
10719 or else Entity
(End_Decl_Expr
) /= Entity
(Freeze_Expr
);
10725 Index
: Interp_Index
;
10729 Get_First_Interp
(End_Decl_Expr
, Index
, It
);
10730 while Present
(It
.Typ
) loop
10731 if It
.Nam
= Entity
(Freeze_Expr
) then
10736 Get_Next_Interp
(Index
, It
);
10740 end Check_Overloaded_Name
;
10742 -- Start of processing for Check_Aspect_At_End_Of_Declarations
10745 -- In an instance we do not perform the consistency check between freeze
10746 -- point and end of declarations, because it was done already in the
10747 -- analysis of the generic. Furthermore, the delayed analysis of an
10748 -- aspect of the instance may produce spurious errors when the generic
10749 -- is a child unit that references entities in the parent (which might
10750 -- not be in scope at the freeze point of the instance).
10752 if In_Instance
then
10755 -- The enclosing scope may have been rewritten during expansion (.e.g. a
10756 -- task body is rewritten as a procedure) after this conformance check
10757 -- has been performed, so do not perform it again (it may not easily be
10758 -- done if full visibility of local entities is not available).
10760 elsif not Comes_From_Source
(Current_Scope
) then
10763 -- Case of aspects Dimension, Dimension_System and Synchronization
10765 elsif A_Id
= Aspect_Synchronization
then
10768 -- Case of stream attributes and Put_Image, just have to compare
10769 -- entities. However, the expression is just a possibly-overloaded
10770 -- name, so we need to verify that one of these interpretations is
10771 -- the one available at at the freeze point.
10773 elsif A_Id
in Aspect_Input
10779 Analyze
(End_Decl_Expr
);
10780 Check_Overloaded_Name
;
10782 elsif A_Id
in Aspect_Variable_Indexing
10783 | Aspect_Constant_Indexing
10784 | Aspect_Default_Iterator
10785 | Aspect_Iterator_Element
10786 | Aspect_Integer_Literal
10787 | Aspect_Real_Literal
10788 | Aspect_String_Literal
10790 -- Make type unfrozen before analysis, to prevent spurious errors
10791 -- about late attributes.
10793 Set_Is_Frozen
(Ent
, False);
10794 Analyze
(End_Decl_Expr
);
10795 Set_Is_Frozen
(Ent
, True);
10797 -- If the end of declarations comes before any other freeze point,
10798 -- the Freeze_Expr is not analyzed: no check needed.
10800 if Analyzed
(Freeze_Expr
) and then not In_Instance
then
10801 Check_Overloaded_Name
;
10809 -- In a generic context freeze nodes are not always generated, so
10810 -- analyze the expression now. If the aspect is for a type, we must
10811 -- also make its potential components accessible.
10813 if not Analyzed
(Freeze_Expr
) and then Inside_A_Generic
then
10814 if A_Id
in Aspect_Dynamic_Predicate | Aspect_Predicate |
10815 Aspect_Static_Predicate
10818 Preanalyze_Spec_Expression
(Freeze_Expr
, Standard_Boolean
);
10821 elsif A_Id
= Aspect_Priority
then
10823 Preanalyze_Spec_Expression
(Freeze_Expr
, Any_Integer
);
10827 Preanalyze
(Freeze_Expr
);
10831 -- Indicate that the expression comes from an aspect specification,
10832 -- which is used in subsequent analysis even if expansion is off.
10834 if Present
(End_Decl_Expr
) then
10835 Set_Parent
(End_Decl_Expr
, ASN
);
10838 -- In a generic context the original aspect expressions have not
10839 -- been preanalyzed, so do it now. There are no conformance checks
10840 -- to perform in this case. As before, we have to make components
10841 -- visible for aspects that may reference them.
10843 if Present
(Freeze_Expr
) and then No
(T
) then
10844 if A_Id
in Aspect_Dynamic_Predicate
10847 | Aspect_Static_Predicate
10850 Check_Aspect_At_Freeze_Point
(ASN
);
10854 Check_Aspect_At_Freeze_Point
(ASN
);
10858 -- The default values attributes may be defined in the private part,
10859 -- and the analysis of the expression may take place when only the
10860 -- partial view is visible. The expression must be scalar, so use
10861 -- the full view to resolve.
10863 elsif A_Id
in Aspect_Default_Component_Value | Aspect_Default_Value
10864 and then Is_Private_Type
(T
)
10866 Preanalyze_Spec_Expression
(End_Decl_Expr
, Full_View
(T
));
10868 -- The following aspect expressions may contain references to
10869 -- components and discriminants of the type.
10871 elsif A_Id
in Aspect_CPU
10872 | Aspect_Dynamic_Predicate
10875 | Aspect_Static_Predicate
10878 Preanalyze_Spec_Expression
(End_Decl_Expr
, T
);
10881 elsif A_Id
= Aspect_Predicate_Failure
then
10882 Preanalyze_Spec_Expression
(End_Decl_Expr
, Standard_String
);
10883 elsif Present
(End_Decl_Expr
) then
10884 Preanalyze_Spec_Expression
(End_Decl_Expr
, T
);
10888 not Fully_Conformant_Expressions
10889 (End_Decl_Expr
, Freeze_Expr
, Report
=> True);
10892 -- Output error message if error. Force error on aspect specification
10893 -- even if there is an error on the expression itself.
10897 ("!visibility of aspect for& changes after freeze point",
10900 ("info: & is frozen here, (RM 13.1.1 (13/3))??",
10901 Freeze_Node
(Ent
), Ent
);
10903 end Check_Aspect_At_End_Of_Declarations
;
10905 ----------------------------------
10906 -- Check_Aspect_At_Freeze_Point --
10907 ----------------------------------
10909 procedure Check_Aspect_At_Freeze_Point
(ASN
: Node_Id
) is
10910 Ident
: constant Node_Id
:= Identifier
(ASN
);
10911 -- Identifier (use Entity field to save expression)
10913 Expr
: constant Node_Id
:= Expression
(ASN
);
10914 -- For cases where using Entity (Identifier) doesn't work
10916 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Chars
(Ident
));
10918 T
: Entity_Id
:= Empty
;
10919 -- Type required for preanalyze call
10922 -- On entry to this procedure, Entity (Ident) contains a copy of the
10923 -- original expression from the aspect, saved for this purpose.
10925 -- On exit from this procedure Entity (Ident) is unchanged, still
10926 -- containing that copy, but Expression (Ident) is a preanalyzed copy
10927 -- of the expression, preanalyzed just after the freeze point.
10929 -- Make a copy of the expression to be preanalyzed
10931 Set_Expression
(ASN
, New_Copy_Tree
(Entity
(Ident
)));
10933 -- Find type for preanalyze call
10937 -- No_Aspect should be impossible
10940 raise Program_Error
;
10942 -- Aspects taking an optional boolean argument
10944 when Boolean_Aspects
10945 | Library_Unit_Aspects
10947 T
:= Standard_Boolean
;
10949 -- Aspects corresponding to attribute definition clauses
10951 when Aspect_Address
=>
10952 T
:= RTE
(RE_Address
);
10954 when Aspect_Attach_Handler
=>
10955 T
:= RTE
(RE_Interrupt_ID
);
10957 when Aspect_Bit_Order
10958 | Aspect_Scalar_Storage_Order
10960 T
:= RTE
(RE_Bit_Order
);
10962 when Aspect_Convention
=>
10966 T
:= RTE
(RE_CPU_Range
);
10968 -- Default_Component_Value is resolved with the component type
10970 when Aspect_Default_Component_Value
=>
10971 T
:= Component_Type
(Entity
(ASN
));
10973 when Aspect_Default_Storage_Pool
=>
10974 T
:= Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
));
10976 -- Default_Value is resolved with the type entity in question
10978 when Aspect_Default_Value
=>
10981 when Aspect_Dispatching_Domain
=>
10982 T
:= RTE
(RE_Dispatching_Domain
);
10984 when Aspect_External_Tag
=>
10985 T
:= Standard_String
;
10987 when Aspect_External_Name
=>
10988 T
:= Standard_String
;
10990 when Aspect_Link_Name
=>
10991 T
:= Standard_String
;
10993 when Aspect_Interrupt_Priority
10996 T
:= Standard_Integer
;
10998 when Aspect_Relative_Deadline
=>
10999 T
:= RTE
(RE_Time_Span
);
11001 when Aspect_Secondary_Stack_Size
=>
11002 T
:= Standard_Integer
;
11004 when Aspect_Small
=>
11006 -- Note that the expression can be of any real type (not just a
11007 -- real universal literal) as long as it is a static constant.
11011 -- For a simple storage pool, we have to retrieve the type of the
11012 -- pool object associated with the aspect's corresponding attribute
11013 -- definition clause.
11015 when Aspect_Simple_Storage_Pool
=>
11016 T
:= Etype
(Expression
(Aspect_Rep_Item
(ASN
)));
11018 when Aspect_Storage_Pool
=>
11019 T
:= Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
));
11021 when Aspect_Alignment
11022 | Aspect_Component_Size
11023 | Aspect_Machine_Radix
11024 | Aspect_Object_Size
11026 | Aspect_Storage_Size
11027 | Aspect_Stream_Size
11028 | Aspect_Value_Size
11032 when Aspect_Linker_Section
=>
11033 T
:= Standard_String
;
11035 when Aspect_Synchronization
=>
11038 -- Special case, the expression of these aspects is just an entity
11039 -- that does not need any resolution, so just analyze.
11048 Analyze
(Expression
(ASN
));
11051 -- Same for Iterator aspects, where the expression is a function
11052 -- name. Legality rules are checked separately.
11054 when Aspect_Constant_Indexing
11055 | Aspect_Default_Iterator
11056 | Aspect_Iterator_Element
11057 | Aspect_Variable_Indexing
11059 Analyze
(Expression
(ASN
));
11062 -- Same for Literal aspects, where the expression is a function
11063 -- name. Legality rules are checked separately. Use Expr to avoid
11064 -- losing track of the previous resolution of Expression.
11066 when Aspect_Integer_Literal
11067 | Aspect_Real_Literal
11068 | Aspect_String_Literal
11070 Set_Entity
(Expression
(ASN
), Entity
(Expr
));
11071 Set_Etype
(Expression
(ASN
), Etype
(Expr
));
11072 Set_Is_Overloaded
(Expression
(ASN
), False);
11073 Analyze
(Expression
(ASN
));
11076 -- Ditto for Iterable, legality checks in Validate_Iterable_Aspect.
11078 when Aspect_Iterable
=>
11082 Cursor
: constant Entity_Id
:= Get_Cursor_Type
(ASN
, T
);
11087 if Cursor
= Any_Type
then
11091 Assoc
:= First
(Component_Associations
(Expression
(ASN
)));
11092 while Present
(Assoc
) loop
11093 Expr
:= Expression
(Assoc
);
11096 if not Error_Posted
(Expr
) then
11097 Resolve_Iterable_Operation
11098 (Expr
, Cursor
, T
, Chars
(First
(Choices
(Assoc
))));
11107 when Aspect_Aggregate
=>
11108 Resolve_Aspect_Aggregate
(Entity
(ASN
), Expression
(ASN
));
11111 when Aspect_Stable_Properties
=>
11112 Resolve_Aspect_Stable_Properties
11113 (Entity
(ASN
), Expression
(ASN
),
11114 Class_Present
=> Class_Present
(ASN
));
11117 -- Invariant/Predicate take boolean expressions
11119 when Aspect_Dynamic_Predicate
11122 | Aspect_Static_Predicate
11123 | Aspect_Type_Invariant
11125 T
:= Standard_Boolean
;
11127 when Aspect_Predicate_Failure
=>
11128 T
:= Standard_String
;
11130 -- As for some other aspects above, the expression of this aspect is
11131 -- just an entity that does not need any resolution, so just analyze.
11133 when Aspect_Designated_Storage_Model
=>
11134 Analyze
(Expression
(ASN
));
11137 when Aspect_Storage_Model_Type
=>
11139 -- The aggregate argument of Storage_Model_Type is optional, and
11140 -- when not present the aspect defaults to the native storage
11141 -- model (where the address type is System.Address, and other
11142 -- arguments default to corresponding native storage operations).
11144 if No
(Expression
(ASN
)) then
11153 Addr_Type
: Entity_Id
:= Empty
;
11156 Assoc
:= First
(Component_Associations
(Expression
(ASN
)));
11157 while Present
(Assoc
) loop
11158 Expr
:= Expression
(Assoc
);
11161 if not Error_Posted
(Expr
) then
11162 Resolve_Storage_Model_Type_Argument
11163 (Expr
, T
, Addr_Type
, Chars
(First
(Choices
(Assoc
))));
11172 -- Here is the list of aspects that don't require delay analysis
11174 when Aspect_Abstract_State
11176 | Aspect_Async_Readers
11177 | Aspect_Async_Writers
11178 | Aspect_Constant_After_Elaboration
11179 | Aspect_Contract_Cases
11180 | Aspect_Default_Initial_Condition
11183 | Aspect_Dimension_System
11184 | Aspect_Effective_Reads
11185 | Aspect_Effective_Writes
11186 | Aspect_Extensions_Visible
11189 | Aspect_GNAT_Annotate
11190 | Aspect_Implicit_Dereference
11191 | Aspect_Initial_Condition
11192 | Aspect_Initializes
11193 | Aspect_Max_Entry_Queue_Depth
11194 | Aspect_Max_Entry_Queue_Length
11195 | Aspect_Max_Queue_Length
11196 | Aspect_No_Caching
11197 | Aspect_No_Controlled_Parts
11198 | Aspect_No_Task_Parts
11199 | Aspect_Obsolescent
11202 | Aspect_Postcondition
11204 | Aspect_Precondition
11205 | Aspect_Refined_Depends
11206 | Aspect_Refined_Global
11207 | Aspect_Refined_Post
11208 | Aspect_Refined_State
11209 | Aspect_Relaxed_Initialization
11210 | Aspect_SPARK_Mode
11211 | Aspect_Subprogram_Variant
11214 | Aspect_Unimplemented
11215 | Aspect_Unsuppress
11216 | Aspect_Volatile_Function
11218 raise Program_Error
;
11222 -- Do the preanalyze call
11224 if Present
(Expression
(ASN
)) then
11225 Preanalyze_Spec_Expression
(Expression
(ASN
), T
);
11227 end Check_Aspect_At_Freeze_Point
;
11229 -----------------------------------
11230 -- Check_Constant_Address_Clause --
11231 -----------------------------------
11233 procedure Check_Constant_Address_Clause
11237 procedure Check_At_Constant_Address
(Nod
: Node_Id
);
11238 -- Checks that the given node N represents a name whose 'Address is
11239 -- constant (in the same sense as OK_Constant_Address_Clause, i.e. the
11240 -- address value is the same at the point of declaration of U_Ent and at
11241 -- the time of elaboration of the address clause.
11243 procedure Check_Expr_Constants
(Nod
: Node_Id
);
11244 -- Checks that Nod meets the requirements for a constant address clause
11245 -- in the sense of the enclosing procedure.
11247 procedure Check_List_Constants
(Lst
: List_Id
);
11248 -- Check that all elements of list Lst meet the requirements for a
11249 -- constant address clause in the sense of the enclosing procedure.
11251 -------------------------------
11252 -- Check_At_Constant_Address --
11253 -------------------------------
11255 procedure Check_At_Constant_Address
(Nod
: Node_Id
) is
11257 if Is_Entity_Name
(Nod
) then
11258 if Present
(Address_Clause
(Entity
((Nod
)))) then
11260 ("invalid address clause for initialized object &!",
11263 ("address for& cannot depend on another address clause! "
11264 & "(RM 13.1(22))!", Nod
, U_Ent
);
11266 elsif In_Same_Source_Unit
(Entity
(Nod
), U_Ent
)
11267 and then Sloc
(U_Ent
) < Sloc
(Entity
(Nod
))
11270 ("invalid address clause for initialized object &!",
11272 Error_Msg_Node_2
:= U_Ent
;
11274 ("\& must be defined before & (RM 13.1(22))!",
11275 Nod
, Entity
(Nod
));
11278 elsif Nkind
(Nod
) = N_Selected_Component
then
11280 T
: constant Entity_Id
:= Etype
(Prefix
(Nod
));
11283 if (Is_Record_Type
(T
)
11284 and then Has_Discriminants
(T
))
11286 (Is_Access_Type
(T
)
11287 and then Is_Record_Type
(Designated_Type
(T
))
11288 and then Has_Discriminants
(Designated_Type
(T
)))
11291 ("invalid address clause for initialized object &!",
11294 ("\address cannot depend on component of discriminated "
11295 & "record (RM 13.1(22))!", Nod
);
11297 Check_At_Constant_Address
(Prefix
(Nod
));
11301 elsif Nkind
(Nod
) = N_Indexed_Component
then
11302 Check_At_Constant_Address
(Prefix
(Nod
));
11303 Check_List_Constants
(Expressions
(Nod
));
11306 Check_Expr_Constants
(Nod
);
11308 end Check_At_Constant_Address
;
11310 --------------------------
11311 -- Check_Expr_Constants --
11312 --------------------------
11314 procedure Check_Expr_Constants
(Nod
: Node_Id
) is
11315 Loc_U_Ent
: constant Source_Ptr
:= Sloc
(U_Ent
);
11316 Ent
: Entity_Id
:= Empty
;
11319 if Nkind
(Nod
) in N_Has_Etype
11320 and then Etype
(Nod
) = Any_Type
11325 case Nkind
(Nod
) is
11331 when N_Expanded_Name
11334 Ent
:= Entity
(Nod
);
11336 -- We need to look at the original node if it is different
11337 -- from the node, since we may have rewritten things and
11338 -- substituted an identifier representing the rewrite.
11340 if Is_Rewrite_Substitution
(Nod
) then
11341 Check_Expr_Constants
(Original_Node
(Nod
));
11343 -- If the node is an object declaration without initial
11344 -- value, some code has been expanded, and the expression
11345 -- is not constant, even if the constituents might be
11346 -- acceptable, as in A'Address + offset.
11348 if Ekind
(Ent
) = E_Variable
11350 Nkind
(Declaration_Node
(Ent
)) = N_Object_Declaration
11352 No
(Expression
(Declaration_Node
(Ent
)))
11355 ("invalid address clause for initialized object &!",
11358 -- If entity is constant, it may be the result of expanding
11359 -- a check. We must verify that its declaration appears
11360 -- before the object in question, else we also reject the
11363 elsif Ekind
(Ent
) = E_Constant
11364 and then In_Same_Source_Unit
(Ent
, U_Ent
)
11365 and then Sloc
(Ent
) > Loc_U_Ent
11368 ("invalid address clause for initialized object &!",
11375 -- Otherwise look at the identifier and see if it is OK
11377 if Is_Named_Number
(Ent
) or else Is_Type
(Ent
) then
11380 elsif Ekind
(Ent
) in E_Constant | E_In_Parameter
then
11382 -- This is the case where we must have Ent defined before
11383 -- U_Ent. Clearly if they are in different units this
11384 -- requirement is met since the unit containing Ent is
11385 -- already processed.
11387 if not In_Same_Source_Unit
(Ent
, U_Ent
) then
11390 -- Otherwise location of Ent must be before the location
11391 -- of U_Ent, that's what prior defined means.
11393 elsif Sloc
(Ent
) < Loc_U_Ent
then
11398 ("invalid address clause for initialized object &!",
11400 Error_Msg_Node_2
:= U_Ent
;
11402 ("\& must be defined before & (RM 13.1(22))!",
11406 elsif Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
11407 Check_Expr_Constants
(Original_Node
(Nod
));
11411 ("invalid address clause for initialized object &!",
11414 if Comes_From_Source
(Ent
) then
11416 ("\reference to variable& not allowed"
11417 & " (RM 13.1(22))!", Nod
, Ent
);
11420 ("non-static expression not allowed"
11421 & " (RM 13.1(22))!", Nod
);
11425 when N_Integer_Literal
=>
11427 -- If this is a rewritten unchecked conversion, in a system
11428 -- where Address is an integer type, always use the base type
11429 -- for a literal value. This is user-friendly and prevents
11430 -- order-of-elaboration issues with instances of unchecked
11433 if Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
11434 Set_Etype
(Nod
, Base_Type
(Etype
(Nod
)));
11437 when N_Character_Literal
11444 Check_Expr_Constants
(Low_Bound
(Nod
));
11445 Check_Expr_Constants
(High_Bound
(Nod
));
11447 when N_Explicit_Dereference
=>
11448 Check_Expr_Constants
(Prefix
(Nod
));
11450 when N_Indexed_Component
=>
11451 Check_Expr_Constants
(Prefix
(Nod
));
11452 Check_List_Constants
(Expressions
(Nod
));
11455 Check_Expr_Constants
(Prefix
(Nod
));
11456 Check_Expr_Constants
(Discrete_Range
(Nod
));
11458 when N_Selected_Component
=>
11459 Check_Expr_Constants
(Prefix
(Nod
));
11461 when N_Attribute_Reference
=>
11462 if Attribute_Name
(Nod
) in Name_Address
11464 | Name_Unchecked_Access
11465 | Name_Unrestricted_Access
11467 Check_At_Constant_Address
(Prefix
(Nod
));
11469 -- Normally, System'To_Address will have been transformed into
11470 -- an Unchecked_Conversion, but in -gnatc mode, it will not,
11471 -- and we don't want to give an error, because the whole point
11472 -- of 'To_Address is that it is static.
11474 elsif Attribute_Name
(Nod
) = Name_To_Address
then
11475 pragma Assert
(Operating_Mode
= Check_Semantics
);
11479 Check_Expr_Constants
(Prefix
(Nod
));
11480 Check_List_Constants
(Expressions
(Nod
));
11483 when N_Aggregate
=>
11484 Check_List_Constants
(Component_Associations
(Nod
));
11485 Check_List_Constants
(Expressions
(Nod
));
11487 when N_Component_Association
=>
11488 Check_Expr_Constants
(Expression
(Nod
));
11490 when N_Extension_Aggregate
=>
11491 Check_Expr_Constants
(Ancestor_Part
(Nod
));
11492 Check_List_Constants
(Component_Associations
(Nod
));
11493 Check_List_Constants
(Expressions
(Nod
));
11499 | N_Membership_Test
11502 Check_Expr_Constants
(Left_Opnd
(Nod
));
11503 Check_Expr_Constants
(Right_Opnd
(Nod
));
11506 Check_Expr_Constants
(Right_Opnd
(Nod
));
11509 | N_Qualified_Expression
11510 | N_Type_Conversion
11511 | N_Unchecked_Type_Conversion
11513 Check_Expr_Constants
(Expression
(Nod
));
11515 when N_Function_Call
=>
11516 if not Is_Pure
(Entity
(Name
(Nod
))) then
11518 ("invalid address clause for initialized object &!",
11522 ("\function & is not pure (RM 13.1(22))!",
11523 Nod
, Entity
(Name
(Nod
)));
11526 Check_List_Constants
(Parameter_Associations
(Nod
));
11529 when N_Parameter_Association
=>
11530 Check_Expr_Constants
(Explicit_Actual_Parameter
(Nod
));
11534 ("invalid address clause for initialized object &!",
11537 ("\must be constant defined before& (RM 13.1(22))!",
11540 end Check_Expr_Constants
;
11542 --------------------------
11543 -- Check_List_Constants --
11544 --------------------------
11546 procedure Check_List_Constants
(Lst
: List_Id
) is
11550 Nod1
:= First
(Lst
);
11551 while Present
(Nod1
) loop
11552 Check_Expr_Constants
(Nod1
);
11555 end Check_List_Constants
;
11557 -- Start of processing for Check_Constant_Address_Clause
11560 -- If rep_clauses are to be ignored, no need for legality checks. In
11561 -- particular, no need to pester user about rep clauses that violate the
11562 -- rule on constant addresses, given that these clauses will be removed
11563 -- by Freeze before they reach the back end. Similarly in CodePeer mode,
11564 -- we want to relax these checks.
11566 if not Ignore_Rep_Clauses
and not CodePeer_Mode
then
11567 Check_Expr_Constants
(Expr
);
11569 end Check_Constant_Address_Clause
;
11571 ---------------------------
11572 -- Check_Pool_Size_Clash --
11573 ---------------------------
11575 procedure Check_Pool_Size_Clash
(Ent
: Entity_Id
; SP
, SS
: Node_Id
) is
11579 -- We need to find out which one came first. Note that in the case of
11580 -- aspects mixed with pragmas there are cases where the processing order
11581 -- is reversed, which is why we do the check here.
11583 if Sloc
(SP
) < Sloc
(SS
) then
11584 Error_Msg_Sloc
:= Sloc
(SP
);
11586 Error_Msg_NE
("Storage_Pool previously given for&#", Post
, Ent
);
11589 Error_Msg_Sloc
:= Sloc
(SS
);
11591 Error_Msg_NE
("Storage_Size previously given for&#", Post
, Ent
);
11595 ("\cannot have Storage_Size and Storage_Pool (RM 13.11(3))", Post
);
11596 end Check_Pool_Size_Clash
;
11598 ----------------------------------------
11599 -- Check_Record_Representation_Clause --
11600 ----------------------------------------
11602 procedure Check_Record_Representation_Clause
(N
: Node_Id
) is
11603 Loc
: constant Source_Ptr
:= Sloc
(N
);
11604 Ident
: constant Node_Id
:= Identifier
(N
);
11605 Rectype
: Entity_Id
;
11608 Fbit
: Uint
:= No_Uint
;
11609 Lbit
: Uint
:= No_Uint
;
11610 Hbit
: Uint
:= Uint_0
;
11614 Max_Bit_So_Far
: Uint
;
11615 -- Records the maximum bit position so far. If all field positions
11616 -- are monotonically increasing, then we can skip the circuit for
11617 -- checking for overlap, since no overlap is possible.
11619 Tagged_Parent
: Entity_Id
:= Empty
;
11620 -- This is set in the case of an extension for which we have either a
11621 -- size clause or Is_Fully_Repped_Tagged_Type True (indicating that all
11622 -- components are positioned by record representation clauses) on the
11623 -- parent type. In this case we check for overlap between components of
11624 -- this tagged type and the parent component. Tagged_Parent will point
11625 -- to this parent type. For all other cases, Tagged_Parent is Empty.
11627 Parent_Last_Bit
: Uint
:= No_Uint
; -- init to avoid warning
11628 -- Relevant only if Tagged_Parent is set, Parent_Last_Bit indicates the
11629 -- last bit position for any field in the parent type. We only need to
11630 -- check overlap for fields starting below this point.
11632 Overlap_Check_Required
: Boolean;
11633 -- Used to keep track of whether or not an overlap check is required
11635 Overlap_Detected
: Boolean := False;
11636 -- Set True if an overlap is detected
11638 Ccount
: Natural := 0;
11639 -- Number of component clauses in record rep clause
11641 procedure Check_Component_Overlap
(C1_Ent
, C2_Ent
: Entity_Id
);
11642 -- Given two entities for record components or discriminants, checks
11643 -- if they have overlapping component clauses and issues errors if so.
11645 procedure Find_Component
;
11646 -- Finds component entity corresponding to current component clause (in
11647 -- CC), and sets Comp to the entity, and Fbit/Lbit to the zero origin
11648 -- start/stop bits for the field. If there is no matching component or
11649 -- if the matching component does not have a component clause, then
11650 -- that's an error and Comp is set to Empty, but no error message is
11651 -- issued, since the message was already given. Comp is also set to
11652 -- Empty if the current "component clause" is in fact a pragma.
11654 procedure Record_Hole_Check
11655 (Rectype
: Entity_Id
; After_Last
: out Uint
; Warn
: Boolean);
11656 -- Checks for gaps in the given Rectype. Compute After_Last, the bit
11657 -- number after the last component. Warn is True on the initial call,
11658 -- and warnings are given for gaps. For a type extension, this is called
11659 -- recursively to compute After_Last for the parent type; in this case
11660 -- Warn is False and the warnings are suppressed.
11662 procedure Component_Order_Check
(Rectype
: Entity_Id
);
11663 -- Check that the order of component clauses agrees with the order of
11664 -- component declarations, and that the component clauses are given in
11665 -- increasing order of bit offset.
11667 -----------------------------
11668 -- Check_Component_Overlap --
11669 -----------------------------
11671 procedure Check_Component_Overlap
(C1_Ent
, C2_Ent
: Entity_Id
) is
11672 CC1
: constant Node_Id
:= Component_Clause
(C1_Ent
);
11673 CC2
: constant Node_Id
:= Component_Clause
(C2_Ent
);
11676 if Present
(CC1
) and then Present
(CC2
) then
11678 -- Exclude odd case where we have two tag components in the same
11679 -- record, both at location zero. This seems a bit strange, but
11680 -- it seems to happen in some circumstances, perhaps on an error.
11682 if Chars
(C1_Ent
) = Name_uTag
then
11686 -- Here we check if the two fields overlap
11689 S1
: constant Uint
:= Component_Bit_Offset
(C1_Ent
);
11690 S2
: constant Uint
:= Component_Bit_Offset
(C2_Ent
);
11691 E1
: constant Uint
:= S1
+ Esize
(C1_Ent
);
11692 E2
: constant Uint
:= S2
+ Esize
(C2_Ent
);
11695 if E2
<= S1
or else E1
<= S2
then
11698 Error_Msg_Node_2
:= Component_Name
(CC2
);
11699 Error_Msg_Sloc
:= Sloc
(Error_Msg_Node_2
);
11700 Error_Msg_Node_1
:= Component_Name
(CC1
);
11702 ("component& overlaps & #", Component_Name
(CC1
));
11703 Overlap_Detected
:= True;
11707 end Check_Component_Overlap
;
11709 ---------------------------
11710 -- Component_Order_Check --
11711 ---------------------------
11713 procedure Component_Order_Check
(Rectype
: Entity_Id
) is
11714 Comp
: Entity_Id
:= First_Component
(Rectype
);
11715 Clause
: Node_Id
:= First
(Component_Clauses
(N
));
11716 Prev_Bit_Offset
: Uint
:= Uint_0
;
11717 OOO
: constant String :=
11718 "?_r?component clause out of order with respect to declaration";
11721 -- Step Comp through components and Clause through component clauses,
11722 -- skipping pragmas. We ignore discriminants and variant parts,
11723 -- because we get most of the benefit from the plain vanilla
11724 -- component cases, without the extra complexity. If we find a Comp
11725 -- and Clause that don't match, give a warning on both and quit. If
11726 -- we find two subsequent clauses out of order by bit layout, give
11727 -- warning and quit. On each iteration, Prev_Bit_Offset is the one
11728 -- from the previous iteration (or 0 to start).
11730 while Present
(Comp
) and then Present
(Clause
) loop
11731 if Nkind
(Clause
) = N_Component_Clause
11732 and then Ekind
(Entity
(Component_Name
(Clause
))) = E_Component
11734 if Entity
(Component_Name
(Clause
)) /= Comp
then
11735 Error_Msg_N
(OOO
, Comp
);
11736 Error_Msg_N
(OOO
, Clause
);
11740 if not Reverse_Bit_Order
(Rectype
)
11741 and then not Reverse_Storage_Order
(Rectype
)
11742 and then Component_Bit_Offset
(Comp
) < Prev_Bit_Offset
11744 Error_Msg_N
("?_r?memory layout out of order", Clause
);
11748 Prev_Bit_Offset
:= Component_Bit_Offset
(Comp
);
11749 Next_Component
(Comp
);
11754 end Component_Order_Check
;
11756 --------------------
11757 -- Find_Component --
11758 --------------------
11760 procedure Find_Component
is
11762 procedure Search_Component
(R
: Entity_Id
);
11763 -- Search components of R for a match. If found, Comp is set
11765 ----------------------
11766 -- Search_Component --
11767 ----------------------
11769 procedure Search_Component
(R
: Entity_Id
) is
11771 Comp
:= First_Component_Or_Discriminant
(R
);
11772 while Present
(Comp
) loop
11774 -- Ignore error of attribute name for component name (we
11775 -- already gave an error message for this, so no need to
11778 if Nkind
(Component_Name
(CC
)) = N_Attribute_Reference
then
11781 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
11784 Next_Component_Or_Discriminant
(Comp
);
11786 end Search_Component
;
11788 -- Start of processing for Find_Component
11791 -- Return with Comp set to Empty if we have a pragma
11793 if Nkind
(CC
) = N_Pragma
then
11798 -- Search current record for matching component
11800 Search_Component
(Rectype
);
11802 -- If not found, maybe component of base type discriminant that is
11803 -- absent from statically constrained first subtype.
11806 Search_Component
(Base_Type
(Rectype
));
11809 -- If no component, or the component does not reference the component
11810 -- clause in question, then there was some previous error for which
11811 -- we already gave a message, so just return with Comp Empty.
11813 if No
(Comp
) or else Component_Clause
(Comp
) /= CC
then
11814 Check_Error_Detected
;
11817 -- Normal case where we have a component clause
11820 Fbit
:= Component_Bit_Offset
(Comp
);
11821 Lbit
:= Fbit
+ Esize
(Comp
) - 1;
11823 end Find_Component
;
11825 -----------------------
11826 -- Record_Hole_Check --
11827 -----------------------
11829 procedure Record_Hole_Check
11830 (Rectype
: Entity_Id
; After_Last
: out Uint
; Warn
: Boolean)
11832 Decl
: constant Node_Id
:= Declaration_Node
(Base_Type
(Rectype
));
11833 -- Full declaration of record type
11835 procedure Check_Component_List
11840 -- Check component list CL for holes. DS is a list of discriminant
11841 -- specifications to be included in the consideration of components.
11842 -- Sbit is the starting bit, which is zero if there are no preceding
11843 -- components (before a variant part, or a parent type, or a tag
11844 -- field). If there are preceding components, Sbit is the bit just
11845 -- after the last such component. Abit is set to the bit just after
11846 -- the last component of DS and CL.
11848 --------------------------
11849 -- Check_Component_List --
11850 --------------------------
11852 procedure Check_Component_List
11861 Compl
:= Integer (List_Length
(Component_Items
(CL
)));
11863 if DS
/= No_List
then
11864 Compl
:= Compl
+ Integer (List_Length
(DS
));
11868 Comps
: array (Natural range 0 .. Compl
) of Entity_Id
;
11869 -- Gather components (zero entry is for sort routine)
11871 Ncomps
: Natural := 0;
11872 -- Number of entries stored in Comps (starting at Comps (1))
11875 -- One component item or discriminant specification
11878 -- Starting bit for next component
11881 -- Component entity
11886 function Lt
(Op1
, Op2
: Natural) return Boolean;
11887 -- Compare routine for Sort
11889 procedure Move
(From
: Natural; To
: Natural);
11890 -- Move routine for Sort
11892 package Sorting
is new GNAT
.Heap_Sort_G
(Move
, Lt
);
11898 function Lt
(Op1
, Op2
: Natural) return Boolean is
11899 K1
: constant Boolean :=
11900 Known_Component_Bit_Offset
(Comps
(Op1
));
11901 K2
: constant Boolean :=
11902 Known_Component_Bit_Offset
(Comps
(Op2
));
11903 -- Record representation clauses can be incomplete, so the
11904 -- Component_Bit_Offsets can be unknown.
11908 return Component_Bit_Offset
(Comps
(Op1
))
11909 < Component_Bit_Offset
(Comps
(Op2
));
11922 procedure Move
(From
: Natural; To
: Natural) is
11924 Comps
(To
) := Comps
(From
);
11928 -- Gather discriminants into Comp
11930 Citem
:= First
(DS
);
11931 while Present
(Citem
) loop
11932 if Nkind
(Citem
) = N_Discriminant_Specification
then
11934 Ent
: constant Entity_Id
:=
11935 Defining_Identifier
(Citem
);
11937 if Ekind
(Ent
) = E_Discriminant
then
11938 Ncomps
:= Ncomps
+ 1;
11939 Comps
(Ncomps
) := Ent
;
11947 -- Gather component entities into Comp
11949 Citem
:= First
(Component_Items
(CL
));
11950 while Present
(Citem
) loop
11951 if Nkind
(Citem
) = N_Component_Declaration
then
11952 Ncomps
:= Ncomps
+ 1;
11953 Comps
(Ncomps
) := Defining_Identifier
(Citem
);
11959 -- Now sort the component entities based on the first bit.
11960 -- Note we already know there are no overlapping components.
11962 Sorting
.Sort
(Ncomps
);
11964 -- Loop through entries checking for holes
11967 for J
in 1 .. Ncomps
loop
11969 pragma Annotate
(CodePeer
, Modified
, CEnt
);
11972 CBO
: constant Uint
:= Component_Bit_Offset
(CEnt
);
11975 -- Skip components with unknown offsets
11977 if Present
(CBO
) and then CBO
>= 0 then
11978 Error_Msg_Uint_1
:= CBO
- Nbit
;
11980 if Warn
and then Error_Msg_Uint_1
> 0 then
11982 ("?.h?^-bit gap before component&",
11983 Component_Name
(Component_Clause
(CEnt
)),
11987 Nbit
:= CBO
+ Esize
(CEnt
);
11992 -- Set Abit to just after the last nonvariant component
11996 -- Process variant parts recursively if present. Set Abit to
11997 -- the maximum for all variant parts.
11999 if Present
(Variant_Part
(CL
)) then
12001 Var_Start
: constant Uint
:= Nbit
;
12003 Variant
:= First
(Variants
(Variant_Part
(CL
)));
12004 while Present
(Variant
) loop
12005 Check_Component_List
12006 (No_List
, Component_List
(Variant
), Var_Start
, Nbit
);
12008 if Nbit
> Abit
then
12015 end Check_Component_List
;
12020 -- Starting bit for call to Check_Component_List. Zero for an
12021 -- untagged type. The size of the Tag for a nonderived tagged
12022 -- type. Parent size for a type extension.
12024 Record_Definition
: Node_Id
;
12025 -- Record_Definition containing Component_List to pass to
12026 -- Check_Component_List.
12028 -- Start of processing for Record_Hole_Check
12031 if Is_Tagged_Type
(Rectype
) then
12032 Sbit
:= UI_From_Int
(System_Address_Size
);
12037 After_Last
:= Uint_0
;
12039 if Nkind
(Decl
) = N_Full_Type_Declaration
then
12040 Record_Definition
:= Type_Definition
(Decl
);
12042 -- If we have a record extension, set Sbit to point after the last
12043 -- component of the parent type, by calling Record_Hole_Check
12046 if Nkind
(Record_Definition
) = N_Derived_Type_Definition
then
12047 Record_Definition
:= Record_Extension_Part
(Record_Definition
);
12048 Record_Hole_Check
(Underlying_Type
(Parent_Subtype
(Rectype
)),
12049 After_Last
=> Sbit
, Warn
=> False);
12052 if Nkind
(Record_Definition
) = N_Record_Definition
then
12053 Check_Component_List
12054 (Discriminant_Specifications
(Decl
),
12055 Component_List
(Record_Definition
),
12059 end Record_Hole_Check
;
12061 -- Start of processing for Check_Record_Representation_Clause
12065 Rectype
:= Entity
(Ident
);
12067 if Rectype
= Any_Type
then
12071 Rectype
:= Underlying_Type
(Rectype
);
12073 -- See if we have a fully repped derived tagged type
12076 PS
: constant Entity_Id
:= Parent_Subtype
(Rectype
);
12079 if Present
(PS
) and then Known_Static_RM_Size
(PS
) then
12080 Tagged_Parent
:= PS
;
12081 Parent_Last_Bit
:= RM_Size
(PS
) - 1;
12083 elsif Present
(PS
) and then Is_Fully_Repped_Tagged_Type
(PS
) then
12084 Tagged_Parent
:= PS
;
12086 -- Find maximum bit of any component of the parent type
12088 Parent_Last_Bit
:= UI_From_Int
(System_Address_Size
- 1);
12089 Pcomp
:= First_Component_Or_Discriminant
(Tagged_Parent
);
12090 while Present
(Pcomp
) loop
12091 if Present
(Component_Bit_Offset
(Pcomp
))
12092 and then Known_Static_Esize
(Pcomp
)
12097 Component_Bit_Offset
(Pcomp
) + Esize
(Pcomp
) - 1);
12100 Next_Component_Or_Discriminant
(Pcomp
);
12105 -- All done if no component clauses
12107 CC
:= First
(Component_Clauses
(N
));
12113 -- If a tag is present, then create a component clause that places it
12114 -- at the start of the record (otherwise gigi may place it after other
12115 -- fields that have rep clauses).
12117 Fent
:= First_Entity
(Rectype
);
12119 if Nkind
(Fent
) = N_Defining_Identifier
12120 and then Chars
(Fent
) = Name_uTag
12122 Set_Component_Bit_Offset
(Fent
, Uint_0
);
12123 Set_Normalized_Position
(Fent
, Uint_0
);
12124 Set_Normalized_First_Bit
(Fent
, Uint_0
);
12125 Set_Esize
(Fent
, UI_From_Int
(System_Address_Size
));
12127 Set_Component_Clause
(Fent
,
12128 Make_Component_Clause
(Loc
,
12129 Component_Name
=> Make_Identifier
(Loc
, Name_uTag
),
12131 Position
=> Make_Integer_Literal
(Loc
, Uint_0
),
12132 First_Bit
=> Make_Integer_Literal
(Loc
, Uint_0
),
12134 Make_Integer_Literal
(Loc
,
12135 UI_From_Int
(System_Address_Size
- 1))));
12137 Ccount
:= Ccount
+ 1;
12140 Max_Bit_So_Far
:= Uint_Minus_1
;
12141 Overlap_Check_Required
:= False;
12143 -- Process the component clauses
12145 while Present
(CC
) loop
12148 if Present
(Comp
) then
12149 Ccount
:= Ccount
+ 1;
12151 -- We need a full overlap check if record positions non-monotonic
12153 if Fbit
<= Max_Bit_So_Far
then
12154 Overlap_Check_Required
:= True;
12157 Max_Bit_So_Far
:= Lbit
;
12159 -- Check bit position out of range of specified size
12161 if Has_Size_Clause
(Rectype
)
12162 and then RM_Size
(Rectype
) <= Lbit
12164 Error_Msg_Uint_1
:= RM_Size
(Rectype
);
12165 Error_Msg_Uint_2
:= Lbit
+ 1;
12166 Error_Msg_N
("bit number out of range of specified "
12167 & "size (expected ^, got ^)",
12170 -- Check for overlap with tag or parent component
12173 if Is_Tagged_Type
(Rectype
)
12174 and then Fbit
< System_Address_Size
12177 ("component overlaps tag field of&",
12178 Component_Name
(CC
), Rectype
);
12179 Overlap_Detected
:= True;
12181 elsif Present
(Tagged_Parent
)
12182 and then Fbit
<= Parent_Last_Bit
12185 ("component overlaps parent field of&",
12186 Component_Name
(CC
), Rectype
);
12187 Overlap_Detected
:= True;
12190 if Hbit
< Lbit
then
12199 -- Now that we have processed all the component clauses, check for
12200 -- overlap. We have to leave this till last, since the components can
12201 -- appear in any arbitrary order in the representation clause.
12203 -- We do not need this check if all specified ranges were monotonic,
12204 -- as recorded by Overlap_Check_Required being False at this stage.
12206 -- This first section checks if there are any overlapping entries at
12207 -- all. It does this by sorting all entries and then seeing if there are
12208 -- any overlaps. If there are none, then that is decisive, but if there
12209 -- are overlaps, they may still be OK (they may result from fields in
12210 -- different variants).
12212 if Overlap_Check_Required
then
12213 Overlap_Check1
: declare
12215 OC_Fbit
: array (0 .. Ccount
) of Uint
;
12216 -- First-bit values for component clauses, the value is the offset
12217 -- of the first bit of the field from start of record. The zero
12218 -- entry is for use in sorting.
12220 OC_Lbit
: array (0 .. Ccount
) of Uint
;
12221 -- Last-bit values for component clauses, the value is the offset
12222 -- of the last bit of the field from start of record. The zero
12223 -- entry is for use in sorting.
12225 OC_Count
: Natural := 0;
12226 -- Count of entries in OC_Fbit and OC_Lbit
12228 function OC_Lt
(Op1
, Op2
: Natural) return Boolean;
12229 -- Compare routine for Sort
12231 procedure OC_Move
(From
: Natural; To
: Natural);
12232 -- Move routine for Sort
12234 package Sorting
is new GNAT
.Heap_Sort_G
(OC_Move
, OC_Lt
);
12240 function OC_Lt
(Op1
, Op2
: Natural) return Boolean is
12242 return OC_Fbit
(Op1
) < OC_Fbit
(Op2
);
12249 procedure OC_Move
(From
: Natural; To
: Natural) is
12251 OC_Fbit
(To
) := OC_Fbit
(From
);
12252 OC_Lbit
(To
) := OC_Lbit
(From
);
12255 -- Start of processing for Overlap_Check
12258 CC
:= First
(Component_Clauses
(N
));
12259 while Present
(CC
) loop
12261 -- Exclude component clause already marked in error
12263 if not Error_Posted
(CC
) then
12266 if Present
(Comp
) then
12267 OC_Count
:= OC_Count
+ 1;
12268 OC_Fbit
(OC_Count
) := Fbit
;
12269 OC_Lbit
(OC_Count
) := Lbit
;
12276 Sorting
.Sort
(OC_Count
);
12278 Overlap_Check_Required
:= False;
12279 for J
in 1 .. OC_Count
- 1 loop
12280 if OC_Lbit
(J
) >= OC_Fbit
(J
+ 1) then
12281 Overlap_Check_Required
:= True;
12285 end Overlap_Check1
;
12288 -- If Overlap_Check_Required is still True, then we have to do the full
12289 -- scale overlap check, since we have at least two fields that do
12290 -- overlap, and we need to know if that is OK since they are in
12291 -- different variant, or whether we have a definite problem.
12293 if Overlap_Check_Required
then
12294 Overlap_Check2
: declare
12295 C1_Ent
, C2_Ent
: Entity_Id
;
12296 -- Entities of components being checked for overlap
12299 -- Component_List node whose Component_Items are being checked
12302 -- Component declaration for component being checked
12305 C1_Ent
:= First_Entity
(Base_Type
(Rectype
));
12307 -- Loop through all components in record. For each component check
12308 -- for overlap with any of the preceding elements on the component
12309 -- list containing the component and also, if the component is in
12310 -- a variant, check against components outside the case structure.
12311 -- This latter test is repeated recursively up the variant tree.
12313 Main_Component_Loop
: while Present
(C1_Ent
) loop
12314 if Ekind
(C1_Ent
) not in E_Component | E_Discriminant
then
12315 goto Continue_Main_Component_Loop
;
12318 -- Skip overlap check if entity has no declaration node. This
12319 -- happens with discriminants in constrained derived types.
12320 -- Possibly we are missing some checks as a result, but that
12321 -- does not seem terribly serious.
12323 if No
(Declaration_Node
(C1_Ent
)) then
12324 goto Continue_Main_Component_Loop
;
12327 Clist
:= Parent
(List_Containing
(Declaration_Node
(C1_Ent
)));
12329 -- Loop through component lists that need checking. Check the
12330 -- current component list and all lists in variants above us.
12332 Component_List_Loop
: loop
12334 -- If derived type definition, go to full declaration
12335 -- If at outer level, check discriminants if there are any.
12337 if Nkind
(Clist
) = N_Derived_Type_Definition
then
12338 Clist
:= Parent
(Clist
);
12341 -- Outer level of record definition, check discriminants
12342 -- but be careful not to flag a non-stored discriminant
12343 -- and the stored discriminant it renames as overlapping.
12345 if Nkind
(Clist
) in N_Full_Type_Declaration
12346 | N_Private_Type_Declaration
12348 if Has_Discriminants
(Defining_Identifier
(Clist
)) then
12350 First_Discriminant
(Defining_Identifier
(Clist
));
12351 while Present
(C2_Ent
) loop
12353 Original_Record_Component
(C1_Ent
) =
12354 Original_Record_Component
(C2_Ent
);
12355 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
12356 Next_Discriminant
(C2_Ent
);
12360 -- Record extension case
12362 elsif Nkind
(Clist
) = N_Derived_Type_Definition
then
12365 -- Otherwise check one component list
12368 Citem
:= First
(Component_Items
(Clist
));
12369 while Present
(Citem
) loop
12370 if Nkind
(Citem
) = N_Component_Declaration
then
12371 C2_Ent
:= Defining_Identifier
(Citem
);
12372 exit when C1_Ent
= C2_Ent
;
12373 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
12380 -- Check for variants above us (the parent of the Clist can
12381 -- be a variant, in which case its parent is a variant part,
12382 -- and the parent of the variant part is a component list
12383 -- whose components must all be checked against the current
12384 -- component for overlap).
12386 if Nkind
(Parent
(Clist
)) = N_Variant
then
12387 Clist
:= Parent
(Parent
(Parent
(Clist
)));
12389 -- Check for possible discriminant part in record, this
12390 -- is treated essentially as another level in the
12391 -- recursion. For this case the parent of the component
12392 -- list is the record definition, and its parent is the
12393 -- full type declaration containing the discriminant
12396 elsif Nkind
(Parent
(Clist
)) = N_Record_Definition
then
12397 Clist
:= Parent
(Parent
((Clist
)));
12399 -- If neither of these two cases, we are at the top of
12403 exit Component_List_Loop
;
12405 end loop Component_List_Loop
;
12407 <<Continue_Main_Component_Loop
>>
12408 Next_Entity
(C1_Ent
);
12410 end loop Main_Component_Loop
;
12411 end Overlap_Check2
;
12414 -- Skip the following warnings if overlap was detected; programmer
12415 -- should fix the errors first. Also skip the warnings for types in
12416 -- generics, because their representation information is not fully
12419 if not Overlap_Detected
and then not In_Generic_Scope
(Rectype
) then
12420 -- Check for record holes (gaps)
12422 if Warn_On_Record_Holes
then
12426 Record_Hole_Check
(Rectype
, After_Last
=> Ignore
, Warn
=> True);
12430 -- Check for out-of-order component clauses
12432 if Warn_On_Component_Order
then
12433 Component_Order_Check
(Rectype
);
12437 -- For records that have component clauses for all components, and whose
12438 -- size is less than or equal to 32, and which can be fully packed, we
12439 -- need to know the size in the front end to activate possible packed
12440 -- array processing where the component type is a record.
12442 -- At this stage Hbit + 1 represents the first unused bit from all the
12443 -- component clauses processed, so if the component clauses are
12444 -- complete, then this is the length of the record.
12446 -- For records longer than System.Storage_Unit, and for those where not
12447 -- all components have component clauses, the back end determines the
12448 -- length (it may for example be appropriate to round up the size
12449 -- to some convenient boundary, based on alignment considerations, etc).
12451 if not Known_RM_Size
(Rectype
)
12452 and then Hbit
+ 1 <= 32
12453 and then not Strict_Alignment
(Rectype
)
12456 -- Nothing to do if at least one component has no component clause
12458 Comp
:= First_Component_Or_Discriminant
(Rectype
);
12459 while Present
(Comp
) loop
12460 exit when No
(Component_Clause
(Comp
));
12461 Next_Component_Or_Discriminant
(Comp
);
12464 -- If we fall out of loop, all components have component clauses
12465 -- and so we can set the size to the maximum value.
12468 Set_RM_Size
(Rectype
, Hbit
+ 1);
12471 end Check_Record_Representation_Clause
;
12477 procedure Check_Size
12481 Biased
: out Boolean)
12483 procedure Size_Too_Small_Error
(Min_Siz
: Uint
);
12484 -- Emit an error concerning illegal size Siz. Min_Siz denotes the
12487 --------------------------
12488 -- Size_Too_Small_Error --
12489 --------------------------
12491 procedure Size_Too_Small_Error
(Min_Siz
: Uint
) is
12493 Error_Msg_Uint_1
:= Min_Siz
;
12494 Error_Msg_NE
(Size_Too_Small_Message
, N
, T
);
12495 end Size_Too_Small_Error
;
12499 UT
: constant Entity_Id
:= Underlying_Type
(T
);
12502 -- Start of processing for Check_Size
12507 -- Reject patently improper size values
12509 if Is_Elementary_Type
(T
)
12510 and then Siz
> Int
'Last
12512 Error_Msg_N
("Size value too large for elementary type", N
);
12514 if Nkind
(Original_Node
(N
)) = N_Op_Expon
then
12516 ("\maybe '* was meant, rather than '*'*", Original_Node
(N
));
12520 -- Dismiss generic types
12522 if Is_Generic_Type
(T
)
12524 Is_Generic_Type
(UT
)
12526 Is_Generic_Type
(Root_Type
(UT
))
12530 -- Guard against previous errors
12532 elsif No
(UT
) or else UT
= Any_Type
then
12533 Check_Error_Detected
;
12536 -- Check case of bit packed array
12538 elsif Is_Array_Type
(UT
)
12539 and then Known_Static_Component_Size
(UT
)
12540 and then Is_Bit_Packed_Array
(UT
)
12548 Asiz
:= Component_Size
(UT
);
12549 Indx
:= First_Index
(UT
);
12551 Ityp
:= Etype
(Indx
);
12553 -- If non-static bound, then we are not in the business of
12554 -- trying to check the length, and indeed an error will be
12555 -- issued elsewhere, since sizes of non-static array types
12556 -- cannot be set implicitly or explicitly.
12558 if not Is_OK_Static_Subtype
(Ityp
) then
12562 -- Otherwise accumulate next dimension
12564 Asiz
:= Asiz
* (Expr_Value
(Type_High_Bound
(Ityp
)) -
12565 Expr_Value
(Type_Low_Bound
(Ityp
)) +
12569 exit when No
(Indx
);
12572 if Asiz
<= Siz
then
12576 Size_Too_Small_Error
(Asiz
);
12580 -- All other composite types are ignored
12582 elsif Is_Composite_Type
(UT
) then
12585 -- For fixed-point types, don't check minimum if type is not frozen,
12586 -- since we don't know all the characteristics of the type that can
12587 -- affect the size (e.g. a specified small) till freeze time.
12589 elsif Is_Fixed_Point_Type
(UT
) and then not Is_Frozen
(UT
) then
12592 -- Cases for which a minimum check is required
12595 -- Ignore if specified size is correct for the type
12597 if Known_Esize
(UT
) and then Siz
= Esize
(UT
) then
12601 -- Otherwise get minimum size
12603 M
:= UI_From_Int
(Minimum_Size
(UT
));
12607 -- Size is less than minimum size, but one possibility remains
12608 -- that we can manage with the new size if we bias the type.
12610 M
:= UI_From_Int
(Minimum_Size
(UT
, Biased
=> True));
12613 Size_Too_Small_Error
(M
);
12621 --------------------------
12622 -- Freeze_Entity_Checks --
12623 --------------------------
12625 procedure Freeze_Entity_Checks
(N
: Node_Id
) is
12626 procedure Hide_Non_Overridden_Subprograms
(Typ
: Entity_Id
);
12627 -- Inspect the primitive operations of type Typ and hide all pairs of
12628 -- implicitly declared non-overridden non-fully conformant homographs
12629 -- (Ada RM 8.3 12.3/2).
12631 -------------------------------------
12632 -- Hide_Non_Overridden_Subprograms --
12633 -------------------------------------
12635 procedure Hide_Non_Overridden_Subprograms
(Typ
: Entity_Id
) is
12636 procedure Hide_Matching_Homographs
12637 (Subp_Id
: Entity_Id
;
12638 Start_Elmt
: Elmt_Id
);
12639 -- Inspect a list of primitive operations starting with Start_Elmt
12640 -- and find matching implicitly declared non-overridden non-fully
12641 -- conformant homographs of Subp_Id. If found, all matches along
12642 -- with Subp_Id are hidden from all visibility.
12644 function Is_Non_Overridden_Or_Null_Procedure
12645 (Subp_Id
: Entity_Id
) return Boolean;
12646 -- Determine whether subprogram Subp_Id is implicitly declared non-
12647 -- overridden subprogram or an implicitly declared null procedure.
12649 ------------------------------
12650 -- Hide_Matching_Homographs --
12651 ------------------------------
12653 procedure Hide_Matching_Homographs
12654 (Subp_Id
: Entity_Id
;
12655 Start_Elmt
: Elmt_Id
)
12658 Prim_Elmt
: Elmt_Id
;
12661 Prim_Elmt
:= Start_Elmt
;
12662 while Present
(Prim_Elmt
) loop
12663 Prim
:= Node
(Prim_Elmt
);
12665 -- The current primitive is implicitly declared non-overridden
12666 -- non-fully conformant homograph of Subp_Id. Both subprograms
12667 -- must be hidden from visibility.
12669 if Chars
(Prim
) = Chars
(Subp_Id
)
12670 and then Is_Non_Overridden_Or_Null_Procedure
(Prim
)
12671 and then not Fully_Conformant
(Prim
, Subp_Id
)
12673 Set_Is_Hidden_Non_Overridden_Subpgm
(Prim
);
12674 Set_Is_Immediately_Visible
(Prim
, False);
12675 Set_Is_Potentially_Use_Visible
(Prim
, False);
12677 Set_Is_Hidden_Non_Overridden_Subpgm
(Subp_Id
);
12678 Set_Is_Immediately_Visible
(Subp_Id
, False);
12679 Set_Is_Potentially_Use_Visible
(Subp_Id
, False);
12682 Next_Elmt
(Prim_Elmt
);
12684 end Hide_Matching_Homographs
;
12686 -----------------------------------------
12687 -- Is_Non_Overridden_Or_Null_Procedure --
12688 -----------------------------------------
12690 function Is_Non_Overridden_Or_Null_Procedure
12691 (Subp_Id
: Entity_Id
) return Boolean
12693 Alias_Id
: Entity_Id
;
12696 -- The subprogram is inherited (implicitly declared), it does not
12697 -- override and does not cover a primitive of an interface.
12699 if Ekind
(Subp_Id
) in E_Function | E_Procedure
12700 and then Present
(Alias
(Subp_Id
))
12701 and then No
(Interface_Alias
(Subp_Id
))
12702 and then No
(Overridden_Operation
(Subp_Id
))
12704 Alias_Id
:= Alias
(Subp_Id
);
12706 if Requires_Overriding
(Alias_Id
) then
12709 elsif Nkind
(Parent
(Alias_Id
)) = N_Procedure_Specification
12710 and then Null_Present
(Parent
(Alias_Id
))
12717 end Is_Non_Overridden_Or_Null_Procedure
;
12721 Prim_Ops
: constant Elist_Id
:= Direct_Primitive_Operations
(Typ
);
12723 Prim_Elmt
: Elmt_Id
;
12725 -- Start of processing for Hide_Non_Overridden_Subprograms
12728 -- Inspect the list of primitives looking for non-overridden
12731 if Present
(Prim_Ops
) then
12732 Prim_Elmt
:= First_Elmt
(Prim_Ops
);
12733 while Present
(Prim_Elmt
) loop
12734 Prim
:= Node
(Prim_Elmt
);
12735 Next_Elmt
(Prim_Elmt
);
12737 if Is_Non_Overridden_Or_Null_Procedure
(Prim
) then
12738 Hide_Matching_Homographs
12740 Start_Elmt
=> Prim_Elmt
);
12744 end Hide_Non_Overridden_Subprograms
;
12748 E
: constant Entity_Id
:= Entity
(N
);
12750 Nongeneric_Case
: constant Boolean := Nkind
(N
) = N_Freeze_Entity
;
12751 -- True in nongeneric case. Some of the processing here is skipped
12752 -- for the generic case since it is not needed. Basically in the
12753 -- generic case, we only need to do stuff that might generate error
12754 -- messages or warnings.
12756 -- Start of processing for Freeze_Entity_Checks
12759 -- Remember that we are processing a freezing entity. Required to
12760 -- ensure correct decoration of internal entities associated with
12761 -- interfaces (see New_Overloaded_Entity).
12763 Inside_Freezing_Actions
:= Inside_Freezing_Actions
+ 1;
12765 -- For tagged types covering interfaces add internal entities that link
12766 -- the primitives of the interfaces with the primitives that cover them.
12767 -- Note: These entities were originally generated only when generating
12768 -- code because their main purpose was to provide support to initialize
12769 -- the secondary dispatch tables. They are also used to locate
12770 -- primitives covering interfaces when processing generics (see
12771 -- Derive_Subprograms).
12773 -- This is not needed in the generic case
12775 if Ada_Version
>= Ada_2005
12776 and then Nongeneric_Case
12777 and then Ekind
(E
) = E_Record_Type
12778 and then Is_Tagged_Type
(E
)
12779 and then not Is_Interface
(E
)
12780 and then Has_Interfaces
(E
)
12782 -- This would be a good common place to call the routine that checks
12783 -- overriding of interface primitives (and thus factorize calls to
12784 -- Check_Abstract_Overriding located at different contexts in the
12785 -- compiler). However, this is not possible because it causes
12786 -- spurious errors in case of late overriding.
12788 Add_Internal_Interface_Entities
(E
);
12791 -- After all forms of overriding have been resolved, a tagged type may
12792 -- be left with a set of implicitly declared and possibly erroneous
12793 -- abstract subprograms, null procedures and subprograms that require
12794 -- overriding. If this set contains fully conformant homographs, then
12795 -- one is chosen arbitrarily (already done during resolution), otherwise
12796 -- all remaining non-fully conformant homographs are hidden from
12797 -- visibility (Ada RM 8.3 12.3/2).
12799 if Is_Tagged_Type
(E
) then
12800 Hide_Non_Overridden_Subprograms
(E
);
12805 if Ekind
(E
) = E_Record_Type
12806 and then Is_CPP_Class
(E
)
12807 and then Is_Tagged_Type
(E
)
12808 and then Tagged_Type_Expansion
12810 if CPP_Num_Prims
(E
) = 0 then
12812 -- If the CPP type has user defined components then it must import
12813 -- primitives from C++. This is required because if the C++ class
12814 -- has no primitives then the C++ compiler does not added the _tag
12815 -- component to the type.
12817 if First_Entity
(E
) /= Last_Entity
(E
) then
12819 ("'C'P'P type must import at least one primitive from C++??",
12824 -- Check that all its primitives are abstract or imported from C++.
12825 -- Check also availability of the C++ constructor.
12828 Has_Constructors
: constant Boolean := Has_CPP_Constructors
(E
);
12830 Error_Reported
: Boolean := False;
12834 Elmt
:= First_Elmt
(Primitive_Operations
(E
));
12835 while Present
(Elmt
) loop
12836 Prim
:= Node
(Elmt
);
12838 if Comes_From_Source
(Prim
) then
12839 if Is_Abstract_Subprogram
(Prim
) then
12842 elsif not Is_Imported
(Prim
)
12843 or else Convention
(Prim
) /= Convention_CPP
12846 ("primitives of 'C'P'P types must be imported from C++ "
12847 & "or abstract??", Prim
);
12849 elsif not Has_Constructors
12850 and then not Error_Reported
12852 Error_Msg_Name_1
:= Chars
(E
);
12854 ("??'C'P'P constructor required for type %", Prim
);
12855 Error_Reported
:= True;
12864 -- Check Ada derivation of CPP type
12866 if Expander_Active
-- why? losing errors in -gnatc mode???
12867 and then Present
(Etype
(E
)) -- defend against errors
12868 and then Tagged_Type_Expansion
12869 and then Ekind
(E
) = E_Record_Type
12870 and then Etype
(E
) /= E
12871 and then Is_CPP_Class
(Etype
(E
))
12872 and then CPP_Num_Prims
(Etype
(E
)) > 0
12873 and then not Is_CPP_Class
(E
)
12874 and then not Has_CPP_Constructors
(Etype
(E
))
12876 -- If the parent has C++ primitives but it has no constructor then
12877 -- check that all the primitives are overridden in this derivation;
12878 -- otherwise the constructor of the parent is needed to build the
12886 Elmt
:= First_Elmt
(Primitive_Operations
(E
));
12887 while Present
(Elmt
) loop
12888 Prim
:= Node
(Elmt
);
12890 if not Is_Abstract_Subprogram
(Prim
)
12891 and then No
(Interface_Alias
(Prim
))
12892 and then Find_Dispatching_Type
(Ultimate_Alias
(Prim
)) /= E
12894 Error_Msg_Name_1
:= Chars
(Etype
(E
));
12896 ("'C'P'P constructor required for parent type %", E
);
12905 Inside_Freezing_Actions
:= Inside_Freezing_Actions
- 1;
12907 -- For a record type, deal with variant parts. This has to be delayed to
12908 -- this point, because of the issue of statically predicated subtypes,
12909 -- which we have to ensure are frozen before checking choices, since we
12910 -- need to have the static choice list set.
12912 if Is_Record_Type
(E
) then
12913 Check_Variant_Part
: declare
12914 D
: constant Node_Id
:= Declaration_Node
(E
);
12919 Others_Present
: Boolean;
12920 pragma Warnings
(Off
, Others_Present
);
12921 -- Indicates others present, not used in this case
12923 procedure Non_Static_Choice_Error
(Choice
: Node_Id
);
12924 -- Error routine invoked by the generic instantiation below when
12925 -- the variant part has a non static choice.
12927 procedure Process_Declarations
(Variant
: Node_Id
);
12928 -- Processes declarations associated with a variant. We analyzed
12929 -- the declarations earlier (in Sem_Ch3.Analyze_Variant_Part),
12930 -- but we still need the recursive call to Check_Choices for any
12931 -- nested variant to get its choices properly processed. This is
12932 -- also where we expand out the choices if expansion is active.
12934 package Variant_Choices_Processing
is new
12935 Generic_Check_Choices
12936 (Process_Empty_Choice
=> No_OP
,
12937 Process_Non_Static_Choice
=> Non_Static_Choice_Error
,
12938 Process_Associated_Node
=> Process_Declarations
);
12939 use Variant_Choices_Processing
;
12941 -----------------------------
12942 -- Non_Static_Choice_Error --
12943 -----------------------------
12945 procedure Non_Static_Choice_Error
(Choice
: Node_Id
) is
12947 Flag_Non_Static_Expr
12948 ("choice given in variant part is not static!", Choice
);
12949 end Non_Static_Choice_Error
;
12951 --------------------------
12952 -- Process_Declarations --
12953 --------------------------
12955 procedure Process_Declarations
(Variant
: Node_Id
) is
12956 CL
: constant Node_Id
:= Component_List
(Variant
);
12960 -- Check for static predicate present in this variant
12962 if Has_SP_Choice
(Variant
) then
12964 -- Here we expand. You might expect to find this call in
12965 -- Expand_N_Variant_Part, but that is called when we first
12966 -- see the variant part, and we cannot do this expansion
12967 -- earlier than the freeze point, since for statically
12968 -- predicated subtypes, the predicate is not known till
12969 -- the freeze point.
12971 -- Furthermore, we do this expansion even if the expander
12972 -- is not active, because other semantic processing, e.g.
12973 -- for aggregates, requires the expanded list of choices.
12975 -- If the expander is not active, then we can't just clobber
12976 -- the list since it would invalidate the tree.
12977 -- So we have to rewrite the variant part with a Rewrite
12978 -- call that replaces it with a copy and clobber the copy.
12980 if not Expander_Active
then
12982 NewV
: constant Node_Id
:= New_Copy
(Variant
);
12984 Set_Discrete_Choices
12985 (NewV
, New_Copy_List
(Discrete_Choices
(Variant
)));
12986 Rewrite
(Variant
, NewV
);
12990 Expand_Static_Predicates_In_Choices
(Variant
);
12993 -- We don't need to worry about the declarations in the variant
12994 -- (since they were analyzed by Analyze_Choices when we first
12995 -- encountered the variant), but we do need to take care of
12996 -- expansion of any nested variants.
12998 if not Null_Present
(CL
) then
12999 VP
:= Variant_Part
(CL
);
13001 if Present
(VP
) then
13003 (VP
, Variants
(VP
), Etype
(Name
(VP
)), Others_Present
);
13006 end Process_Declarations
;
13008 -- Start of processing for Check_Variant_Part
13011 -- Find component list
13015 if Nkind
(D
) = N_Full_Type_Declaration
then
13016 T
:= Type_Definition
(D
);
13018 if Nkind
(T
) = N_Record_Definition
then
13019 C
:= Component_List
(T
);
13021 elsif Nkind
(T
) = N_Derived_Type_Definition
13022 and then Present
(Record_Extension_Part
(T
))
13024 C
:= Component_List
(Record_Extension_Part
(T
));
13028 -- Case of variant part present
13030 if Present
(C
) and then Present
(Variant_Part
(C
)) then
13031 VP
:= Variant_Part
(C
);
13036 (VP
, Variants
(VP
), Etype
(Name
(VP
)), Others_Present
);
13038 -- If the last variant does not contain the Others choice,
13039 -- replace it with an N_Others_Choice node since Gigi always
13040 -- wants an Others. Note that we do not bother to call Analyze
13041 -- on the modified variant part, since its only effect would be
13042 -- to compute the Others_Discrete_Choices node laboriously, and
13043 -- of course we already know the list of choices corresponding
13044 -- to the others choice (it's the list we're replacing).
13046 -- We only want to do this if the expander is active, since
13047 -- we do not want to clobber the tree.
13049 if Expander_Active
then
13051 Last_Var
: constant Node_Id
:=
13052 Last_Non_Pragma
(Variants
(VP
));
13054 Others_Node
: Node_Id
;
13057 if Nkind
(First
(Discrete_Choices
(Last_Var
))) /=
13060 Others_Node
:= Make_Others_Choice
(Sloc
(Last_Var
));
13061 Set_Others_Discrete_Choices
13062 (Others_Node
, Discrete_Choices
(Last_Var
));
13063 Set_Discrete_Choices
13064 (Last_Var
, New_List
(Others_Node
));
13069 end Check_Variant_Part
;
13072 -- If we have a type with predicates, build predicate function. This is
13073 -- not needed in the generic case, nor within e.g. TSS subprograms and
13074 -- other predefined primitives. For a derived type, ensure that the
13075 -- parent type is already frozen so that its predicate function has been
13076 -- constructed already. This is necessary if the parent is declared
13077 -- in a nested package and its own freeze point has not been reached.
13080 and then Nongeneric_Case
13081 and then Has_Predicates
(E
)
13082 and then Predicate_Check_In_Scope
(N
)
13085 Atyp
: constant Entity_Id
:= Nearest_Ancestor
(E
);
13089 and then Has_Predicates
(Atyp
)
13090 and then not Is_Frozen
(Atyp
)
13092 Freeze_Before
(N
, Atyp
);
13096 -- Before we build a predicate function, ensure that discriminant
13097 -- checking functions are available. The predicate function might
13098 -- need to call these functions if the predicate references any
13099 -- components declared in a variant part.
13101 if Ekind
(E
) = E_Record_Type
and then Has_Discriminants
(E
) then
13102 Build_Or_Copy_Discr_Checking_Funcs
(Parent
(E
));
13105 Build_Predicate_Function
(E
, N
);
13108 -- If type has delayed aspects, this is where we do the preanalysis at
13109 -- the freeze point, as part of the consistent visibility check. Note
13110 -- that this must be done after calling Build_Predicate_Function or
13111 -- Build_Invariant_Procedure since these subprograms fix occurrences of
13112 -- the subtype name in the saved expression so that they will not cause
13113 -- trouble in the preanalysis.
13115 -- This is also not needed in the generic case
13118 and then Has_Delayed_Aspects
(E
)
13119 and then Scope
(E
) = Current_Scope
13125 -- Look for aspect specification entries for this entity
13127 Ritem
:= First_Rep_Item
(E
);
13128 while Present
(Ritem
) loop
13129 if Nkind
(Ritem
) = N_Aspect_Specification
13130 and then Entity
(Ritem
) = E
13131 and then Is_Delayed_Aspect
(Ritem
)
13133 if Get_Aspect_Id
(Ritem
) in Aspect_CPU
13134 | Aspect_Dynamic_Predicate
13136 | Aspect_Static_Predicate
13139 -- Retrieve the visibility to components and discriminants
13140 -- in order to properly analyze the aspects.
13143 Check_Aspect_At_Freeze_Point
(Ritem
);
13145 -- In the case of predicate aspects, there will be
13146 -- a corresponding Predicate pragma associated with
13147 -- the aspect, and the expression of the pragma also
13148 -- needs to be analyzed at this point, to ensure that
13149 -- Save_Global_References will capture global refs in
13150 -- expressions that occur in generic bodies, for proper
13151 -- later resolution of the pragma in instantiations.
13154 and then Inside_A_Generic
13155 and then Has_Predicates
(E
)
13156 and then Present
(Aspect_Rep_Item
(Ritem
))
13159 Pragma_Args
: constant List_Id
:=
13160 Pragma_Argument_Associations
13161 (Aspect_Rep_Item
(Ritem
));
13162 Pragma_Expr
: constant Node_Id
:=
13163 Expression
(Next
(First
(Pragma_Args
)));
13165 if Present
(Pragma_Expr
) then
13166 Analyze_And_Resolve
13167 (Pragma_Expr
, Standard_Boolean
);
13175 Check_Aspect_At_Freeze_Point
(Ritem
);
13178 -- A pragma Predicate should be checked like one of the
13179 -- corresponding aspects, wrt possible misuse of ghost
13182 elsif Nkind
(Ritem
) = N_Pragma
13183 and then No
(Corresponding_Aspect
(Ritem
))
13185 Get_Pragma_Id
(Pragma_Name
(Ritem
)) = Pragma_Predicate
13187 -- Retrieve the visibility to components and discriminants
13188 -- in order to properly analyze the pragma.
13191 Arg
: constant Node_Id
:=
13192 Next
(First
(Pragma_Argument_Associations
(Ritem
)));
13195 Preanalyze_Spec_Expression
13196 (Expression
(Arg
), Standard_Boolean
);
13201 Next_Rep_Item
(Ritem
);
13206 if not In_Generic_Scope
(E
)
13207 and then Ekind
(E
) = E_Record_Type
13208 and then Is_Tagged_Type
(E
)
13210 Process_Class_Conditions_At_Freeze_Point
(E
);
13212 end Freeze_Entity_Checks
;
13214 -------------------------
13215 -- Get_Alignment_Value --
13216 -------------------------
13218 function Get_Alignment_Value
(Expr
: Node_Id
) return Uint
is
13219 Align
: constant Uint
:= Static_Integer
(Expr
);
13225 elsif Align
< 0 then
13226 Error_Msg_N
("alignment value must be positive", Expr
);
13229 -- If Alignment is specified to be 0, we treat it the same as 1
13231 elsif Align
= 0 then
13235 for J
in Int
range 0 .. 64 loop
13237 M
: constant Uint
:= Uint_2
** J
;
13240 exit when M
= Align
;
13243 Error_Msg_N
("alignment value must be power of 2", Expr
);
13251 end Get_Alignment_Value
;
13253 -----------------------------------
13254 -- Has_Compatible_Representation --
13255 -----------------------------------
13257 function Has_Compatible_Representation
13258 (Target_Typ
, Operand_Typ
: Entity_Id
) return Boolean
13260 -- The subtype-specific representation attributes (Size and Alignment)
13261 -- do not affect representation from the point of view of this function.
13263 T1
: constant Entity_Id
:= Implementation_Base_Type
(Target_Typ
);
13264 T2
: constant Entity_Id
:= Implementation_Base_Type
(Operand_Typ
);
13267 -- Return true immediately for the same base type
13272 -- Tagged types always have the same representation, because it is not
13273 -- possible to specify different representations for common fields.
13275 elsif Is_Tagged_Type
(T1
) then
13278 -- Representations are definitely different if conventions differ
13280 elsif Convention
(T1
) /= Convention
(T2
) then
13283 -- Representations are different if component alignments or scalar
13284 -- storage orders differ.
13286 elsif (Is_Record_Type
(T1
) or else Is_Array_Type
(T1
))
13288 (Is_Record_Type
(T2
) or else Is_Array_Type
(T2
))
13289 and then (Component_Alignment
(T1
) /= Component_Alignment
(T2
)
13291 Reverse_Storage_Order
(T1
) /= Reverse_Storage_Order
(T2
))
13296 -- For arrays, the only real issue is component size. If we know the
13297 -- component size for both arrays, and it is the same, then that's
13298 -- good enough to know we don't have a change of representation.
13300 if Is_Array_Type
(T1
) then
13302 -- In a view conversion, if the target type is an array type having
13303 -- aliased components and the operand type is an array type having
13304 -- unaliased components, then a new object is created (4.6(58.3/4)).
13306 if Has_Aliased_Components
(T1
)
13307 and then not Has_Aliased_Components
(T2
)
13312 if Known_Component_Size
(T1
)
13313 and then Known_Component_Size
(T2
)
13314 and then Component_Size
(T1
) = Component_Size
(T2
)
13319 -- For records, representations are different if reordering differs
13321 elsif Is_Record_Type
(T1
)
13322 and then Is_Record_Type
(T2
)
13323 and then No_Reordering
(T1
) /= No_Reordering
(T2
)
13328 -- Types definitely have same representation if neither has non-standard
13329 -- representation since default representations are always consistent.
13330 -- If only one has non-standard representation, and the other does not,
13331 -- then we consider that they do not have the same representation. They
13332 -- might, but there is no way of telling early enough.
13334 if Has_Non_Standard_Rep
(T1
) then
13335 if not Has_Non_Standard_Rep
(T2
) then
13339 return not Has_Non_Standard_Rep
(T2
);
13342 -- Here the two types both have non-standard representation, and we need
13343 -- to determine if they have the same non-standard representation.
13345 -- For arrays, we simply need to test if the component sizes are the
13346 -- same. Pragma Pack is reflected in modified component sizes, so this
13347 -- check also deals with pragma Pack.
13349 if Is_Array_Type
(T1
) then
13350 return Component_Size
(T1
) = Component_Size
(T2
);
13352 -- Case of record types
13354 elsif Is_Record_Type
(T1
) then
13356 -- Packed status must conform
13358 if Is_Packed
(T1
) /= Is_Packed
(T2
) then
13361 -- If the operand type is derived from the target type and no clause
13362 -- has been given after the derivation, then the representations are
13363 -- the same since the derived type inherits that of the parent type.
13365 elsif Is_Derived_Type
(T2
)
13366 and then Etype
(T2
) = T1
13367 and then not Has_Record_Rep_Clause
(T2
)
13371 -- Otherwise we must check components. Typ2 maybe a constrained
13372 -- subtype with fewer components, so we compare the components
13373 -- of the base types.
13376 Record_Case
: declare
13377 CD1
, CD2
: Entity_Id
;
13379 function Same_Rep
return Boolean;
13380 -- CD1 and CD2 are either components or discriminants. This
13381 -- function tests whether they have the same representation.
13387 function Same_Rep
return Boolean is
13389 if No
(Component_Clause
(CD1
)) then
13390 return No
(Component_Clause
(CD2
));
13392 -- Note: at this point, component clauses have been
13393 -- normalized to the default bit order, so that the
13394 -- comparison of Component_Bit_Offsets is meaningful.
13397 Present
(Component_Clause
(CD2
))
13399 Component_Bit_Offset
(CD1
) = Component_Bit_Offset
(CD2
)
13401 Esize
(CD1
) = Esize
(CD2
);
13405 -- Start of processing for Record_Case
13408 if Has_Discriminants
(T1
) then
13410 -- The number of discriminants may be different if the
13411 -- derived type has fewer (constrained by values). The
13412 -- invisible discriminants retain the representation of
13413 -- the original, so the discrepancy does not per se
13414 -- indicate a different representation.
13416 CD1
:= First_Discriminant
(T1
);
13417 CD2
:= First_Discriminant
(T2
);
13418 while Present
(CD1
) and then Present
(CD2
) loop
13419 if not Same_Rep
then
13422 Next_Discriminant
(CD1
);
13423 Next_Discriminant
(CD2
);
13428 CD1
:= First_Component
(Underlying_Type
(Base_Type
(T1
)));
13429 CD2
:= First_Component
(Underlying_Type
(Base_Type
(T2
)));
13430 while Present
(CD1
) loop
13431 if not Same_Rep
then
13434 Next_Component
(CD1
);
13435 Next_Component
(CD2
);
13443 -- For enumeration types, we must check each literal to see if the
13444 -- representation is the same. Note that we do not permit enumeration
13445 -- representation clauses for Character and Wide_Character, so these
13446 -- cases were already dealt with.
13448 elsif Is_Enumeration_Type
(T1
) then
13449 Enumeration_Case
: declare
13450 L1
, L2
: Entity_Id
;
13453 L1
:= First_Literal
(T1
);
13454 L2
:= First_Literal
(T2
);
13455 while Present
(L1
) loop
13456 if Enumeration_Rep
(L1
) /= Enumeration_Rep
(L2
) then
13465 end Enumeration_Case
;
13467 -- Any other types have the same representation for these purposes
13472 end Has_Compatible_Representation
;
13474 -------------------------------------
13475 -- Inherit_Aspects_At_Freeze_Point --
13476 -------------------------------------
13478 procedure Inherit_Aspects_At_Freeze_Point
(Typ
: Entity_Id
) is
13479 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
13480 (Rep_Item
: Node_Id
) return Boolean;
13481 -- This routine checks if Rep_Item is either a pragma or an aspect
13482 -- specification node whose corresponding pragma (if any) is present in
13483 -- the Rep Item chain of the entity it has been specified to.
13485 --------------------------------------------------
13486 -- Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item --
13487 --------------------------------------------------
13489 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
13490 (Rep_Item
: Node_Id
) return Boolean
13494 Nkind
(Rep_Item
) = N_Pragma
13496 Present_In_Rep_Item
(Entity
(Rep_Item
), Aspect_Rep_Item
(Rep_Item
));
13497 end Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
;
13499 -- Start of processing for Inherit_Aspects_At_Freeze_Point
13502 -- A representation item is either subtype-specific (Size and Alignment
13503 -- clauses) or type-related (all others). Subtype-specific aspects may
13504 -- differ for different subtypes of the same type (RM 13.1.8).
13506 -- A derived type inherits each type-related representation aspect of
13507 -- its parent type that was directly specified before the declaration of
13508 -- the derived type (RM 13.1.15).
13510 -- A derived subtype inherits each subtype-specific representation
13511 -- aspect of its parent subtype that was directly specified before the
13512 -- declaration of the derived type (RM 13.1.15).
13514 -- The general processing involves inheriting a representation aspect
13515 -- from a parent type whenever the first rep item (aspect specification,
13516 -- attribute definition clause, pragma) corresponding to the given
13517 -- representation aspect in the rep item chain of Typ, if any, isn't
13518 -- directly specified to Typ but to one of its parents.
13520 -- In addition, Convention must be propagated from base type to subtype,
13521 -- because the subtype may have been declared on an incomplete view.
13523 if Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
then
13529 if not Has_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
, False)
13530 and then Has_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
)
13531 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
13532 (Get_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
))
13534 Set_Is_Ada_2005_Only
(Typ
);
13539 if not Has_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
, False)
13540 and then Has_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
)
13541 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
13542 (Get_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
))
13544 Set_Is_Ada_2012_Only
(Typ
);
13549 if not Has_Rep_Item
(Typ
, Name_Ada_2022
, False)
13550 and then Has_Rep_Item
(Typ
, Name_Ada_2022
)
13551 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
13552 (Get_Rep_Item
(Typ
, Name_Ada_2022
))
13554 Set_Is_Ada_2022_Only
(Typ
);
13559 if not Has_Rep_Item
(Typ
, Name_Atomic
, Name_Shared
, False)
13560 and then Has_Rep_Pragma
(Typ
, Name_Atomic
, Name_Shared
)
13561 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
13562 (Get_Rep_Item
(Typ
, Name_Atomic
, Name_Shared
))
13564 Set_Is_Atomic
(Typ
);
13565 Set_Is_Volatile
(Typ
);
13566 Set_Treat_As_Volatile
(Typ
);
13571 if Is_Record_Type
(Typ
)
13572 and then Typ
/= Base_Type
(Typ
) and then Is_Frozen
(Base_Type
(Typ
))
13574 Set_Convention
(Typ
, Convention
(Base_Type
(Typ
)));
13577 -- Default_Component_Value
13579 -- Verify that there is no rep_item declared for the type, and there
13580 -- is one coming from an ancestor.
13582 if Is_Array_Type
(Typ
)
13583 and then Is_Base_Type
(Typ
)
13584 and then not Has_Rep_Item
(Typ
, Name_Default_Component_Value
, False)
13585 and then Has_Rep_Item
(Typ
, Name_Default_Component_Value
)
13591 E
:= Entity
(Get_Rep_Item
(Typ
, Name_Default_Component_Value
));
13593 -- Deal with private types
13595 if Is_Private_Type
(E
) then
13596 E
:= Full_View
(E
);
13599 Set_Default_Aspect_Component_Value
(Typ
,
13600 Default_Aspect_Component_Value
(E
));
13606 if Is_Scalar_Type
(Typ
)
13607 and then Is_Base_Type
(Typ
)
13608 and then not Has_Rep_Item
(Typ
, Name_Default_Value
, False)
13609 and then Has_Rep_Item
(Typ
, Name_Default_Value
)
13611 Set_Has_Default_Aspect
(Typ
);
13617 E
:= Entity
(Get_Rep_Item
(Typ
, Name_Default_Value
));
13619 -- Deal with private types
13621 if Is_Private_Type
(E
) then
13622 E
:= Full_View
(E
);
13625 Set_Default_Aspect_Value
(Typ
, Default_Aspect_Value
(E
));
13631 if not Has_Rep_Item
(Typ
, Name_Discard_Names
, False)
13632 and then Has_Rep_Item
(Typ
, Name_Discard_Names
)
13633 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
13634 (Get_Rep_Item
(Typ
, Name_Discard_Names
))
13636 Set_Discard_Names
(Typ
);
13641 if not Has_Rep_Item
(Typ
, Name_Volatile
, False)
13642 and then Has_Rep_Item
(Typ
, Name_Volatile
)
13643 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
13644 (Get_Rep_Item
(Typ
, Name_Volatile
))
13646 Set_Is_Volatile
(Typ
);
13647 Set_Treat_As_Volatile
(Typ
);
13650 -- Volatile_Full_Access and Full_Access_Only
13652 if not Has_Rep_Item
(Typ
, Name_Volatile_Full_Access
, False)
13653 and then not Has_Rep_Item
(Typ
, Name_Full_Access_Only
, False)
13654 and then (Has_Rep_Item
(Typ
, Name_Volatile_Full_Access
)
13655 or else Has_Rep_Item
(Typ
, Name_Full_Access_Only
))
13656 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
13657 (Get_Rep_Item
(Typ
, Name_Volatile_Full_Access
))
13659 Set_Is_Volatile_Full_Access
(Typ
);
13660 Set_Is_Volatile
(Typ
);
13661 Set_Treat_As_Volatile
(Typ
);
13664 -- Inheritance for derived types only
13666 if Is_Derived_Type
(Typ
) then
13668 Bas_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
13669 Imp_Bas_Typ
: constant Entity_Id
:= Implementation_Base_Type
(Typ
);
13672 -- Atomic_Components
13674 if not Has_Rep_Item
(Typ
, Name_Atomic_Components
, False)
13675 and then Has_Rep_Item
(Typ
, Name_Atomic_Components
)
13676 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
13677 (Get_Rep_Item
(Typ
, Name_Atomic_Components
))
13679 Set_Has_Atomic_Components
(Imp_Bas_Typ
);
13682 -- Volatile_Components
13684 if not Has_Rep_Item
(Typ
, Name_Volatile_Components
, False)
13685 and then Has_Rep_Item
(Typ
, Name_Volatile_Components
)
13686 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
13687 (Get_Rep_Item
(Typ
, Name_Volatile_Components
))
13689 Set_Has_Volatile_Components
(Imp_Bas_Typ
);
13692 -- Finalize_Storage_Only
13694 if not Has_Rep_Pragma
(Typ
, Name_Finalize_Storage_Only
, False)
13695 and then Has_Rep_Pragma
(Typ
, Name_Finalize_Storage_Only
)
13697 Set_Finalize_Storage_Only
(Bas_Typ
);
13700 -- Universal_Aliasing
13702 if not Has_Rep_Item
(Typ
, Name_Universal_Aliasing
, False)
13703 and then Has_Rep_Item
(Typ
, Name_Universal_Aliasing
)
13704 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
13705 (Get_Rep_Item
(Typ
, Name_Universal_Aliasing
))
13707 Set_Universal_Aliasing
(Imp_Bas_Typ
);
13712 if Is_Record_Type
(Typ
) and then Typ
= Bas_Typ
then
13713 if not Has_Rep_Item
(Typ
, Name_Bit_Order
, False)
13714 and then Has_Rep_Item
(Typ
, Name_Bit_Order
)
13716 Set_Reverse_Bit_Order
(Bas_Typ
,
13718 (Implementation_Base_Type
(Etype
(Bas_Typ
))));
13722 -- Scalar_Storage_Order
13724 if (Is_Record_Type
(Typ
) or else Is_Array_Type
(Typ
))
13725 and then Typ
= Bas_Typ
13727 -- For a type extension, always inherit from parent; otherwise
13728 -- inherit if no default applies. Note: we do not check for
13729 -- an explicit rep item on the parent type when inheriting,
13730 -- because the parent SSO may itself have been set by default.
13732 if not Has_Rep_Item
(First_Subtype
(Typ
),
13733 Name_Scalar_Storage_Order
, False)
13734 and then (Is_Tagged_Type
(Bas_Typ
)
13735 or else not (SSO_Set_Low_By_Default
(Bas_Typ
)
13737 SSO_Set_High_By_Default
(Bas_Typ
)))
13739 Set_Reverse_Storage_Order
(Bas_Typ
,
13740 Reverse_Storage_Order
13741 (Implementation_Base_Type
(Etype
(Bas_Typ
))));
13743 -- Clear default SSO indications, since the inherited aspect
13744 -- which was set explicitly overrides the default.
13746 Set_SSO_Set_Low_By_Default
(Bas_Typ
, False);
13747 Set_SSO_Set_High_By_Default
(Bas_Typ
, False);
13752 end Inherit_Aspects_At_Freeze_Point
;
13754 ---------------------------------
13755 -- Inherit_Delayed_Rep_Aspects --
13756 ---------------------------------
13758 procedure Inherit_Delayed_Rep_Aspects
(Typ
: Entity_Id
) is
13764 -- Find the first aspect that has been inherited
13766 N
:= First_Rep_Item
(Typ
);
13767 while Present
(N
) loop
13768 if Nkind
(N
) = N_Aspect_Specification
then
13769 exit when Entity
(N
) /= Typ
;
13775 -- There must be one if we reach here
13777 pragma Assert
(Present
(N
));
13780 -- Loop through delayed aspects for the parent type
13782 while Present
(N
) loop
13783 if Nkind
(N
) = N_Aspect_Specification
then
13784 exit when Entity
(N
) /= P
;
13786 if Is_Delayed_Aspect
(N
) then
13787 A
:= Get_Aspect_Id
(N
);
13789 -- Process delayed rep aspect. For Boolean attributes it is
13790 -- not possible to cancel an attribute once set (the attempt
13791 -- to use an aspect with xxx => False is an error) for a
13792 -- derived type. So for those cases, we do not have to check
13793 -- if a clause has been given for the derived type, since it
13794 -- is harmless to set it again if it is already set.
13800 when Aspect_Alignment
=>
13801 if not Has_Alignment_Clause
(Typ
) then
13802 Set_Alignment
(Typ
, Alignment
(P
));
13807 when Aspect_Atomic
=>
13808 if Is_Atomic
(P
) then
13809 Set_Is_Atomic
(Typ
);
13812 -- Atomic_Components
13814 when Aspect_Atomic_Components
=>
13815 if Has_Atomic_Components
(P
) then
13816 Set_Has_Atomic_Components
(Base_Type
(Typ
));
13821 when Aspect_Bit_Order
=>
13822 if Is_Record_Type
(Typ
)
13823 and then No
(Get_Attribute_Definition_Clause
13824 (Typ
, Attribute_Bit_Order
))
13825 and then Reverse_Bit_Order
(P
)
13827 Set_Reverse_Bit_Order
(Base_Type
(Typ
));
13832 when Aspect_Component_Size
=>
13833 if Is_Array_Type
(Typ
)
13834 and then not Has_Component_Size_Clause
(Typ
)
13837 (Base_Type
(Typ
), Component_Size
(P
));
13842 when Aspect_Machine_Radix
=>
13843 if Is_Decimal_Fixed_Point_Type
(Typ
)
13844 and then not Has_Machine_Radix_Clause
(Typ
)
13846 Set_Machine_Radix_10
(Typ
, Machine_Radix_10
(P
));
13849 -- Object_Size (also Size which also sets Object_Size)
13851 when Aspect_Object_Size
13854 if not Has_Size_Clause
(Typ
)
13856 No
(Get_Attribute_Definition_Clause
13857 (Typ
, Attribute_Object_Size
))
13859 Set_Esize
(Typ
, Esize
(P
));
13864 when Aspect_Pack
=>
13865 if not Is_Packed
(Typ
) then
13866 Set_Is_Packed
(Base_Type
(Typ
));
13868 if Is_Bit_Packed_Array
(P
) then
13869 Set_Is_Bit_Packed_Array
(Base_Type
(Typ
));
13870 Set_Packed_Array_Impl_Type
13871 (Typ
, Packed_Array_Impl_Type
(P
));
13875 -- Scalar_Storage_Order
13877 when Aspect_Scalar_Storage_Order
=>
13878 if (Is_Record_Type
(Typ
) or else Is_Array_Type
(Typ
))
13879 and then No
(Get_Attribute_Definition_Clause
13880 (Typ
, Attribute_Scalar_Storage_Order
))
13881 and then Reverse_Storage_Order
(P
)
13883 Set_Reverse_Storage_Order
(Base_Type
(Typ
));
13885 -- Clear default SSO indications, since the aspect
13886 -- overrides the default.
13888 Set_SSO_Set_Low_By_Default
(Base_Type
(Typ
), False);
13889 Set_SSO_Set_High_By_Default
(Base_Type
(Typ
), False);
13894 when Aspect_Small
=>
13895 if Is_Fixed_Point_Type
(Typ
)
13896 and then not Has_Small_Clause
(Typ
)
13898 Set_Small_Value
(Typ
, Small_Value
(P
));
13903 when Aspect_Storage_Size
=>
13904 if (Is_Access_Type
(Typ
) or else Is_Task_Type
(Typ
))
13905 and then not Has_Storage_Size_Clause
(Typ
)
13907 Set_Storage_Size_Variable
13908 (Base_Type
(Typ
), Storage_Size_Variable
(P
));
13913 when Aspect_Value_Size
=>
13915 -- Value_Size is never inherited, it is either set by
13916 -- default, or it is explicitly set for the derived
13917 -- type. So nothing to do here.
13923 when Aspect_Volatile
=>
13924 if Is_Volatile
(P
) then
13925 Set_Is_Volatile
(Typ
);
13928 -- Volatile_Full_Access (also Full_Access_Only)
13930 when Aspect_Volatile_Full_Access
13931 | Aspect_Full_Access_Only
13933 if Is_Volatile_Full_Access
(P
) then
13934 Set_Is_Volatile_Full_Access
(Typ
);
13937 -- Volatile_Components
13939 when Aspect_Volatile_Components
=>
13940 if Has_Volatile_Components
(P
) then
13941 Set_Has_Volatile_Components
(Base_Type
(Typ
));
13944 -- That should be all the Rep Aspects
13947 pragma Assert
(Aspect_Delay
(A
) /= Rep_Aspect
);
13955 end Inherit_Delayed_Rep_Aspects
;
13961 procedure Initialize
is
13963 Address_Clause_Checks
.Init
;
13964 Unchecked_Conversions
.Init
;
13966 -- The following might be needed in the future for some non-GCC back
13968 -- if AAMP_On_Target then
13969 -- Independence_Checks.Init;
13973 ---------------------------
13974 -- Install_Discriminants --
13975 ---------------------------
13977 procedure Install_Discriminants
(E
: Entity_Id
) is
13981 Disc
:= First_Discriminant
(E
);
13982 while Present
(Disc
) loop
13983 Prev
:= Current_Entity
(Disc
);
13984 Set_Current_Entity
(Disc
);
13985 Set_Is_Immediately_Visible
(Disc
);
13986 Set_Homonym
(Disc
, Prev
);
13987 Next_Discriminant
(Disc
);
13989 end Install_Discriminants
;
13991 -------------------------
13992 -- Is_Operational_Item --
13993 -------------------------
13995 function Is_Operational_Item
(N
: Node_Id
) return Boolean is
13997 -- List of operational items is given in AARM 13.1(8.mm/1). It is
13998 -- clearly incomplete, as it does not include iterator aspects, among
14001 return Nkind
(N
) = N_Attribute_Definition_Clause
14003 Get_Attribute_Id
(Chars
(N
)) in Attribute_Constant_Indexing
14004 | Attribute_External_Tag
14005 | Attribute_Default_Iterator
14006 | Attribute_Implicit_Dereference
14008 | Attribute_Iterable
14009 | Attribute_Iterator_Element
14011 | Attribute_Put_Image
14013 | Attribute_Variable_Indexing
14015 end Is_Operational_Item
;
14017 -------------------------
14018 -- Is_Predicate_Static --
14019 -------------------------
14021 -- Note: the basic legality of the expression has already been checked, so
14022 -- we don't need to worry about cases or ranges on strings for example.
14024 function Is_Predicate_Static
14027 Warn
: Boolean := True) return Boolean
14029 function All_Static_Case_Alternatives
(L
: List_Id
) return Boolean;
14030 -- Given a list of case expression alternatives, returns True if all
14031 -- the alternatives are static (have all static choices, and a static
14034 function Is_Type_Ref
(N
: Node_Id
) return Boolean;
14035 pragma Inline
(Is_Type_Ref
);
14036 -- Returns True if N is a reference to the type for the predicate in the
14037 -- expression (i.e. if it is an identifier whose Chars field matches the
14038 -- Nam given in the call). N must not be parenthesized, if the type name
14039 -- appears in parens, this routine will return False.
14041 -- The routine also returns True for function calls generated during the
14042 -- expansion of comparison operators on strings, which are intended to
14043 -- be legal in static predicates, and are converted into calls to array
14044 -- comparison routines in the body of the corresponding predicate
14047 ----------------------------------
14048 -- All_Static_Case_Alternatives --
14049 ----------------------------------
14051 function All_Static_Case_Alternatives
(L
: List_Id
) return Boolean is
14056 while Present
(N
) loop
14057 if not (All_Static_Choices
(Discrete_Choices
(N
))
14058 and then Is_OK_Static_Expression
(Expression
(N
)))
14067 end All_Static_Case_Alternatives
;
14073 function Is_Type_Ref
(N
: Node_Id
) return Boolean is
14075 return (Nkind
(N
) = N_Identifier
14076 and then Chars
(N
) = Nam
14077 and then Paren_Count
(N
) = 0);
14080 -- helper function for recursive calls
14081 function Is_Predicate_Static_Aux
(Expr
: Node_Id
) return Boolean is
14082 (Is_Predicate_Static
(Expr
, Nam
, Warn
=> False));
14084 -- Start of processing for Is_Predicate_Static
14087 -- Handle cases like
14088 -- subtype S is Integer with Static_Predicate =>
14089 -- (Some_Integer_Variable in Integer) and then (S /= 0);
14090 -- where the predicate (which should be rejected) might have been
14091 -- transformed into just "(S /= 0)", which would appear to be
14092 -- a predicate-static expression (and therefore legal).
14094 if Original_Node
(Expr
) /= Expr
then
14096 -- Emit warnings for predicates that are always True or always False
14097 -- and were not originally expressed as Boolean literals.
14099 return Result
: constant Boolean :=
14100 Is_Predicate_Static_Aux
(Original_Node
(Expr
))
14102 if Result
and then Warn
and then Is_Entity_Name
(Expr
) then
14103 if Entity
(Expr
) = Standard_True
then
14104 Error_Msg_N
("predicate is redundant (always True)?", Expr
);
14105 elsif Entity
(Expr
) = Standard_False
then
14107 ("predicate is unsatisfiable (always False)?", Expr
);
14113 -- Predicate_Static means one of the following holds. Numbers are the
14114 -- corresponding paragraph numbers in (RM 3.2.4(16-22)).
14116 -- 16: A static expression
14118 if Is_OK_Static_Expression
(Expr
) then
14121 -- 17: A membership test whose simple_expression is the current
14122 -- instance, and whose membership_choice_list meets the requirements
14123 -- for a static membership test.
14125 elsif Nkind
(Expr
) in N_Membership_Test
14126 and then Is_Type_Ref
(Left_Opnd
(Expr
))
14127 and then All_Membership_Choices_Static
(Expr
)
14131 -- 18. A case_expression whose selecting_expression is the current
14132 -- instance, and whose dependent expressions are static expressions.
14134 elsif Nkind
(Expr
) = N_Case_Expression
14135 and then Is_Type_Ref
(Expression
(Expr
))
14136 and then All_Static_Case_Alternatives
(Alternatives
(Expr
))
14140 -- 19. A call to a predefined equality or ordering operator, where one
14141 -- operand is the current instance, and the other is a static
14144 -- Note: the RM is clearly wrong here in not excluding string types.
14145 -- Without this exclusion, we would allow expressions like X > "ABC"
14146 -- to be considered as predicate-static, which is clearly not intended,
14147 -- since the idea is for predicate-static to be a subset of normal
14148 -- static expressions (and "DEF" > "ABC" is not a static expression).
14150 -- However, we do allow internally generated (not from source) equality
14151 -- and inequality operations to be valid on strings (this helps deal
14152 -- with cases where we transform A in "ABC" to A = "ABC).
14154 -- In fact, it appears that the intent of the ARG is to extend static
14155 -- predicates to strings, and that the extension should probably apply
14156 -- to static expressions themselves. The code below accepts comparison
14157 -- operators that apply to static strings.
14159 elsif Nkind
(Expr
) in N_Op_Compare
14160 and then ((Is_Type_Ref
(Left_Opnd
(Expr
))
14161 and then Is_OK_Static_Expression
(Right_Opnd
(Expr
)))
14163 (Is_Type_Ref
(Right_Opnd
(Expr
))
14164 and then Is_OK_Static_Expression
(Left_Opnd
(Expr
))))
14168 -- 20. A call to a predefined boolean logical operator, where each
14169 -- operand is predicate-static.
14171 elsif (Nkind
(Expr
) in N_Op_And | N_Op_Or | N_Op_Xor
14172 and then Is_Predicate_Static_Aux
(Left_Opnd
(Expr
))
14173 and then Is_Predicate_Static_Aux
(Right_Opnd
(Expr
)))
14175 (Nkind
(Expr
) = N_Op_Not
14176 and then Is_Predicate_Static_Aux
(Right_Opnd
(Expr
)))
14180 -- 21. A short-circuit control form where both operands are
14181 -- predicate-static.
14183 elsif Nkind
(Expr
) in N_Short_Circuit
14184 and then Is_Predicate_Static_Aux
(Left_Opnd
(Expr
))
14185 and then Is_Predicate_Static_Aux
(Right_Opnd
(Expr
))
14189 -- 22. A parenthesized predicate-static expression. This does not
14190 -- require any special test, since we just ignore paren levels in
14191 -- all the cases above.
14193 -- One more test that is an implementation artifact caused by the fact
14194 -- that we are analyzing not the original expression, but the generated
14195 -- expression in the body of the predicate function. This can include
14196 -- references to inherited predicates, so that the expression we are
14197 -- processing looks like:
14199 -- xxPredicate (typ (Inns)) and then expression
14201 -- Where the call is to a Predicate function for an inherited predicate.
14202 -- We simply ignore such a call, which could be to either a dynamic or
14203 -- a static predicate. Note that if the parent predicate is dynamic then
14204 -- eventually this type will be marked as dynamic, but you are allowed
14205 -- to specify a static predicate for a subtype which is inheriting a
14206 -- dynamic predicate, so the static predicate validation here ignores
14207 -- the inherited predicate even if it is dynamic.
14208 -- In all cases, a static predicate can only apply to a scalar type.
14210 elsif Nkind
(Expr
) = N_Function_Call
14211 and then Is_Predicate_Function
(Entity
(Name
(Expr
)))
14212 and then Is_Scalar_Type
(Etype
(First_Entity
(Entity
(Name
(Expr
)))))
14216 -- That's an exhaustive list of tests, all other cases are not
14217 -- predicate-static, so we return False.
14222 end Is_Predicate_Static
;
14224 ----------------------
14225 -- Is_Static_Choice --
14226 ----------------------
14228 function Is_Static_Choice
(N
: Node_Id
) return Boolean is
14230 return Nkind
(N
) = N_Others_Choice
14231 or else Is_OK_Static_Expression
(N
)
14232 or else (Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
))
14233 and then Is_OK_Static_Subtype
(Entity
(N
)))
14234 or else (Nkind
(N
) = N_Subtype_Indication
14235 and then Is_OK_Static_Subtype
(Entity
(N
)))
14236 or else (Nkind
(N
) = N_Range
and then Is_OK_Static_Range
(N
));
14237 end Is_Static_Choice
;
14239 ------------------------------
14240 -- Is_Type_Related_Rep_Item --
14241 ------------------------------
14243 function Is_Type_Related_Rep_Item
(N
: Node_Id
) return Boolean is
14246 when N_Attribute_Definition_Clause
=>
14247 -- See AARM 13.1(8.f-8.x) list items that end in "clause"
14248 -- ???: include any GNAT-defined attributes here?
14249 return Get_Attribute_Id
(Chars
(N
)) in Attribute_Bit_Order
14250 | Attribute_Component_Size
14251 | Attribute_Machine_Radix
14252 | Attribute_Storage_Pool
14253 | Attribute_Stream_Size
;
14256 case Get_Pragma_Id
(N
) is
14257 -- See AARM 13.1(8.f-8.x) list items that start with "pragma"
14258 -- ???: include any GNAT-defined pragmas here?
14262 | Pragma_Convention
14264 | Pragma_Independent
14266 | Pragma_Atomic_Components
14267 | Pragma_Independent_Components
14268 | Pragma_Volatile_Components
14269 | Pragma_Discard_Names
14276 when N_Enumeration_Representation_Clause
14277 | N_Record_Representation_Clause
14286 end Is_Type_Related_Rep_Item
;
14288 ---------------------
14289 -- Kill_Rep_Clause --
14290 ---------------------
14292 procedure Kill_Rep_Clause
(N
: Node_Id
) is
14294 pragma Assert
(Ignore_Rep_Clauses
);
14296 -- Note: we use Replace rather than Rewrite, because we don't want
14297 -- tools to be able to use Original_Node to dig out the (undecorated)
14298 -- rep clause that is being replaced.
14300 Replace
(N
, Make_Null_Statement
(Sloc
(N
)));
14302 -- The null statement must be marked as not coming from source. This is
14303 -- so that tools ignore it, and also the back end does not expect bogus
14304 -- "from source" null statements in weird places (e.g. in declarative
14305 -- regions where such null statements are not allowed).
14307 Set_Comes_From_Source
(N
, False);
14308 end Kill_Rep_Clause
;
14314 function Minimum_Size
14316 Biased
: Boolean := False) return Int
14318 Lo
: Uint
:= No_Uint
;
14319 Hi
: Uint
:= No_Uint
;
14320 LoR
: Ureal
:= No_Ureal
;
14321 HiR
: Ureal
:= No_Ureal
;
14322 LoSet
: Boolean := False;
14323 HiSet
: Boolean := False;
14326 Ancest
: Entity_Id
;
14327 R_Typ
: constant Entity_Id
:= Root_Type
(T
);
14332 if T
= Any_Type
then
14333 return Unknown_Minimum_Size
;
14335 -- For generic types, just return unknown. There cannot be any
14336 -- legitimate need to know such a size, but this routine may be
14337 -- called with a generic type as part of normal processing.
14339 elsif Is_Generic_Type
(R_Typ
) or else R_Typ
= Any_Type
then
14340 return Unknown_Minimum_Size
;
14342 -- Access types (cannot have size smaller than System.Address)
14344 elsif Is_Access_Type
(T
) then
14345 return System_Address_Size
;
14347 -- Floating-point types
14349 elsif Is_Floating_Point_Type
(T
) then
14350 return UI_To_Int
(Esize
(R_Typ
));
14354 elsif Is_Discrete_Type
(T
) then
14356 -- The following loop is looking for the nearest compile time known
14357 -- bounds following the ancestor subtype chain. The idea is to find
14358 -- the most restrictive known bounds information.
14362 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
14363 return Unknown_Minimum_Size
;
14367 if Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
)) then
14368 Lo
:= Expr_Rep_Value
(Type_Low_Bound
(Ancest
));
14375 if Compile_Time_Known_Value
(Type_High_Bound
(Ancest
)) then
14376 Hi
:= Expr_Rep_Value
(Type_High_Bound
(Ancest
));
14382 Ancest
:= Ancestor_Subtype
(Ancest
);
14384 if No
(Ancest
) then
14385 Ancest
:= Base_Type
(T
);
14387 if Is_Generic_Type
(Ancest
) then
14388 return Unknown_Minimum_Size
;
14393 -- Fixed-point types. We can't simply use Expr_Value to get the
14394 -- Corresponding_Integer_Value values of the bounds, since these do not
14395 -- get set till the type is frozen, and this routine can be called
14396 -- before the type is frozen. Similarly the test for bounds being static
14397 -- needs to include the case where we have unanalyzed real literals for
14398 -- the same reason.
14400 elsif Is_Fixed_Point_Type
(T
) then
14402 -- The following loop is looking for the nearest compile time known
14403 -- bounds following the ancestor subtype chain. The idea is to find
14404 -- the most restrictive known bounds information.
14408 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
14409 return Unknown_Minimum_Size
;
14412 -- Note: In the following two tests for LoSet and HiSet, it may
14413 -- seem redundant to test for N_Real_Literal here since normally
14414 -- one would assume that the test for the value being known at
14415 -- compile time includes this case. However, there is a glitch.
14416 -- If the real literal comes from folding a non-static expression,
14417 -- then we don't consider any non- static expression to be known
14418 -- at compile time if we are in configurable run time mode (needed
14419 -- in some cases to give a clearer definition of what is and what
14420 -- is not accepted). So the test is indeed needed. Without it, we
14421 -- would set neither Lo_Set nor Hi_Set and get an infinite loop.
14424 if Nkind
(Type_Low_Bound
(Ancest
)) = N_Real_Literal
14425 or else Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
))
14427 LoR
:= Expr_Value_R
(Type_Low_Bound
(Ancest
));
14434 if Nkind
(Type_High_Bound
(Ancest
)) = N_Real_Literal
14435 or else Compile_Time_Known_Value
(Type_High_Bound
(Ancest
))
14437 HiR
:= Expr_Value_R
(Type_High_Bound
(Ancest
));
14443 Ancest
:= Ancestor_Subtype
(Ancest
);
14445 if No
(Ancest
) then
14446 Ancest
:= Base_Type
(T
);
14448 if Is_Generic_Type
(Ancest
) then
14449 return Unknown_Minimum_Size
;
14454 Lo
:= UR_To_Uint
(LoR
/ Small_Value
(T
));
14455 Hi
:= UR_To_Uint
(HiR
/ Small_Value
(T
));
14457 -- No other types allowed
14460 raise Program_Error
;
14463 -- Fall through with Hi and Lo set. Deal with biased case
14466 and then not Is_Fixed_Point_Type
(T
)
14467 and then not (Is_Enumeration_Type
(T
)
14468 and then Has_Non_Standard_Rep
(T
)))
14469 or else Has_Biased_Representation
(T
)
14475 -- Null range case, size is always zero. We only do this in the discrete
14476 -- type case, since that's the odd case that came up. Probably we should
14477 -- also do this in the fixed-point case, but doing so causes peculiar
14478 -- gigi failures, and it is not worth worrying about this incredibly
14479 -- marginal case (explicit null-range fixed-point type declarations).
14481 if Lo
> Hi
and then Is_Discrete_Type
(T
) then
14484 -- Signed case. Note that we consider types like range 1 .. -1 to be
14485 -- signed for the purpose of computing the size, since the bounds have
14486 -- to be accommodated in the base type.
14488 elsif Lo
< 0 or else Hi
< 0 then
14492 -- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1))
14493 -- Note that we accommodate the case where the bounds cross. This
14494 -- can happen either because of the way the bounds are declared
14495 -- or because of the algorithm in Freeze_Fixed_Point_Type.
14509 -- If both bounds are positive, make sure that both are represen-
14510 -- table in the case where the bounds are crossed. This can happen
14511 -- either because of the way the bounds are declared, or because of
14512 -- the algorithm in Freeze_Fixed_Point_Type.
14518 -- S = size, (can accommodate 0 .. (2**size - 1))
14521 while Hi
>= Uint_2
** S
loop
14529 ------------------------------
14530 -- New_Put_Image_Subprogram --
14531 ------------------------------
14533 procedure New_Put_Image_Subprogram
14538 Loc
: constant Source_Ptr
:= Sloc
(N
);
14539 Sname
: constant Name_Id
:=
14540 Make_TSS_Name
(Base_Type
(Ent
), TSS_Put_Image
);
14541 Subp_Id
: Entity_Id
;
14542 Subp_Decl
: Node_Id
;
14546 Defer_Declaration
: constant Boolean :=
14547 Is_Tagged_Type
(Ent
) or else Is_Private_Type
(Ent
);
14548 -- For a tagged type, there is a declaration at the freeze point, and
14549 -- we must generate only a completion of this declaration. We do the
14550 -- same for private types, because the full view might be tagged.
14551 -- Otherwise we generate a declaration at the point of the attribute
14552 -- definition clause. If the attribute definition comes from an aspect
14553 -- specification the declaration is part of the freeze actions of the
14556 function Build_Spec
return Node_Id
;
14557 -- Used for declaration and renaming declaration, so that this is
14558 -- treated as a renaming_as_body.
14564 function Build_Spec
return Node_Id
is
14567 T_Ref
: constant Node_Id
:= New_Occurrence_Of
(Etyp
, Loc
);
14570 Subp_Id
:= Make_Defining_Identifier
(Loc
, Sname
);
14572 -- S : Root_Buffer_Type'Class
14574 Formals
:= New_List
(
14575 Make_Parameter_Specification
(Loc
,
14576 Defining_Identifier
=>
14577 Make_Defining_Identifier
(Loc
, Name_S
),
14578 In_Present
=> True,
14579 Out_Present
=> True,
14581 New_Occurrence_Of
(Etype
(F
), Loc
)));
14585 Append_To
(Formals
,
14586 Make_Parameter_Specification
(Loc
,
14587 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_V
),
14588 Parameter_Type
=> T_Ref
));
14591 Make_Procedure_Specification
(Loc
,
14592 Defining_Unit_Name
=> Subp_Id
,
14593 Parameter_Specifications
=> Formals
);
14598 -- Start of processing for New_Put_Image_Subprogram
14601 F
:= First_Formal
(Subp
);
14603 Etyp
:= Etype
(Next_Formal
(F
));
14605 -- Prepare subprogram declaration and insert it as an action on the
14606 -- clause node. The visibility for this entity is used to test for
14607 -- visibility of the attribute definition clause (in the sense of
14608 -- 8.3(23) as amended by AI-195).
14610 if not Defer_Declaration
then
14612 Make_Subprogram_Declaration
(Loc
,
14613 Specification
=> Build_Spec
);
14615 -- For a tagged type, there is always a visible declaration for the
14616 -- Put_Image TSS (it is a predefined primitive operation), and the
14617 -- completion of this declaration occurs at the freeze point, which is
14618 -- not always visible at places where the attribute definition clause is
14619 -- visible. So, we create a dummy entity here for the purpose of
14620 -- tracking the visibility of the attribute definition clause itself.
14624 Make_Defining_Identifier
(Loc
, New_External_Name
(Sname
, 'V'));
14626 Make_Object_Declaration
(Loc
,
14627 Defining_Identifier
=> Subp_Id
,
14628 Object_Definition
=> New_Occurrence_Of
(Standard_Boolean
, Loc
));
14631 if not Defer_Declaration
14632 and then From_Aspect_Specification
(N
)
14633 and then Has_Delayed_Freeze
(Ent
)
14635 Append_Freeze_Action
(Ent
, Subp_Decl
);
14638 Insert_Action
(N
, Subp_Decl
);
14639 Set_Entity
(N
, Subp_Id
);
14643 Make_Subprogram_Renaming_Declaration
(Loc
,
14644 Specification
=> Build_Spec
,
14645 Name
=> New_Occurrence_Of
(Subp
, Loc
));
14647 if Defer_Declaration
then
14648 Set_TSS
(Base_Type
(Ent
), Subp_Id
);
14651 if From_Aspect_Specification
(N
) then
14652 Append_Freeze_Action
(Ent
, Subp_Decl
);
14654 Insert_Action
(N
, Subp_Decl
);
14657 Copy_TSS
(Subp_Id
, Base_Type
(Ent
));
14659 end New_Put_Image_Subprogram
;
14661 ---------------------------
14662 -- New_Stream_Subprogram --
14663 ---------------------------
14665 procedure New_Stream_Subprogram
14669 Nam
: TSS_Name_Type
)
14671 Loc
: constant Source_Ptr
:= Sloc
(N
);
14672 Sname
: constant Name_Id
:= Make_TSS_Name
(Base_Type
(Ent
), Nam
);
14673 Subp_Id
: Entity_Id
;
14674 Subp_Decl
: Node_Id
;
14678 Defer_Declaration
: constant Boolean :=
14679 Is_Tagged_Type
(Ent
) or else Is_Private_Type
(Ent
);
14680 -- For a tagged type, there is a declaration for each stream attribute
14681 -- at the freeze point, and we must generate only a completion of this
14682 -- declaration. We do the same for private types, because the full view
14683 -- might be tagged. Otherwise we generate a declaration at the point of
14684 -- the attribute definition clause. If the attribute definition comes
14685 -- from an aspect specification the declaration is part of the freeze
14686 -- actions of the type.
14688 function Build_Spec
return Node_Id
;
14689 -- Used for declaration and renaming declaration, so that this is
14690 -- treated as a renaming_as_body.
14696 function Build_Spec
return Node_Id
is
14697 Out_P
: constant Boolean := (Nam
= TSS_Stream_Read
);
14700 T_Ref
: constant Node_Id
:= New_Occurrence_Of
(Etyp
, Loc
);
14703 Subp_Id
:= Make_Defining_Identifier
(Loc
, Sname
);
14705 -- S : access Root_Stream_Type'Class
14707 Formals
:= New_List
(
14708 Make_Parameter_Specification
(Loc
,
14709 Defining_Identifier
=>
14710 Make_Defining_Identifier
(Loc
, Name_S
),
14712 Make_Access_Definition
(Loc
,
14714 New_Occurrence_Of
(
14715 Designated_Type
(Etype
(F
)), Loc
))));
14717 if Nam
= TSS_Stream_Input
then
14719 Make_Function_Specification
(Loc
,
14720 Defining_Unit_Name
=> Subp_Id
,
14721 Parameter_Specifications
=> Formals
,
14722 Result_Definition
=> T_Ref
);
14726 Append_To
(Formals
,
14727 Make_Parameter_Specification
(Loc
,
14728 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_V
),
14729 Out_Present
=> Out_P
,
14730 Parameter_Type
=> T_Ref
));
14733 Make_Procedure_Specification
(Loc
,
14734 Defining_Unit_Name
=> Subp_Id
,
14735 Parameter_Specifications
=> Formals
);
14741 -- Start of processing for New_Stream_Subprogram
14744 F
:= First_Formal
(Subp
);
14746 if Ekind
(Subp
) = E_Procedure
then
14747 Etyp
:= Etype
(Next_Formal
(F
));
14749 Etyp
:= Etype
(Subp
);
14752 -- Prepare subprogram declaration and insert it as an action on the
14753 -- clause node. The visibility for this entity is used to test for
14754 -- visibility of the attribute definition clause (in the sense of
14755 -- 8.3(23) as amended by AI-195).
14757 if not Defer_Declaration
then
14759 Make_Subprogram_Declaration
(Loc
,
14760 Specification
=> Build_Spec
);
14762 -- For a tagged type, there is always a visible declaration for each
14763 -- stream TSS (it is a predefined primitive operation), and the
14764 -- completion of this declaration occurs at the freeze point, which is
14765 -- not always visible at places where the attribute definition clause is
14766 -- visible. So, we create a dummy entity here for the purpose of
14767 -- tracking the visibility of the attribute definition clause itself.
14771 Make_Defining_Identifier
(Loc
, New_External_Name
(Sname
, 'V'));
14773 Make_Object_Declaration
(Loc
,
14774 Defining_Identifier
=> Subp_Id
,
14775 Object_Definition
=> New_Occurrence_Of
(Standard_Boolean
, Loc
));
14778 if not Defer_Declaration
14779 and then From_Aspect_Specification
(N
)
14780 and then Has_Delayed_Freeze
(Ent
)
14782 Append_Freeze_Action
(Ent
, Subp_Decl
);
14785 Insert_Action
(N
, Subp_Decl
);
14786 Set_Entity
(N
, Subp_Id
);
14790 Make_Subprogram_Renaming_Declaration
(Loc
,
14791 Specification
=> Build_Spec
,
14792 Name
=> New_Occurrence_Of
(Subp
, Loc
));
14794 if Defer_Declaration
then
14795 Set_TSS
(Base_Type
(Ent
), Subp_Id
);
14798 if From_Aspect_Specification
(N
) then
14799 Append_Freeze_Action
(Ent
, Subp_Decl
);
14801 Insert_Action
(N
, Subp_Decl
);
14804 Copy_TSS
(Subp_Id
, Base_Type
(Ent
));
14806 end New_Stream_Subprogram
;
14808 ----------------------
14809 -- No_Type_Rep_Item --
14810 ----------------------
14812 procedure No_Type_Rep_Item
(N
: Node_Id
) is
14814 Error_Msg_N
("|type-related representation item not permitted!", N
);
14815 end No_Type_Rep_Item
;
14821 procedure Pop_Type
(E
: Entity_Id
) is
14823 if Ekind
(E
) = E_Record_Type
and then E
= Current_Scope
then
14827 and then Has_Discriminants
(E
)
14828 and then Nkind
(Parent
(E
)) /= N_Subtype_Declaration
14830 Uninstall_Discriminants
(E
);
14839 procedure Push_Type
(E
: Entity_Id
) is
14843 if Ekind
(E
) = E_Record_Type
then
14846 Comp
:= First_Component
(E
);
14847 while Present
(Comp
) loop
14848 Install_Entity
(Comp
);
14849 Next_Component
(Comp
);
14852 if Has_Discriminants
(E
) then
14853 Install_Discriminants
(E
);
14857 and then Has_Discriminants
(E
)
14858 and then Nkind
(Parent
(E
)) /= N_Subtype_Declaration
14861 Install_Discriminants
(E
);
14865 -----------------------------------
14866 -- Register_Address_Clause_Check --
14867 -----------------------------------
14869 procedure Register_Address_Clause_Check
14876 ACS
: constant Boolean := Scope_Suppress
.Suppress
(Alignment_Check
);
14878 Address_Clause_Checks
.Append
((N
, X
, A
, Y
, Off
, ACS
));
14879 end Register_Address_Clause_Check
;
14881 ------------------------
14882 -- Rep_Item_Too_Early --
14883 ------------------------
14885 function Rep_Item_Too_Early
(T
: Entity_Id
; N
: Node_Id
) return Boolean is
14886 function Has_Generic_Parent
(E
: Entity_Id
) return Boolean;
14887 -- Return True if R or any ancestor is a generic type
14889 ------------------------
14890 -- Has_Generic_Parent --
14891 ------------------------
14893 function Has_Generic_Parent
(E
: Entity_Id
) return Boolean is
14894 Ancestor_Type
: Entity_Id
:= Etype
(E
);
14897 if Is_Generic_Type
(E
) then
14901 while Present
(Ancestor_Type
)
14902 and then not Is_Generic_Type
(Ancestor_Type
)
14903 and then Etype
(Ancestor_Type
) /= Ancestor_Type
14905 Ancestor_Type
:= Etype
(Ancestor_Type
);
14909 Present
(Ancestor_Type
) and then Is_Generic_Type
(Ancestor_Type
);
14910 end Has_Generic_Parent
;
14912 -- Start of processing for Rep_Item_Too_Early
14915 -- Cannot apply non-operational rep items to generic types
14917 if Is_Operational_Item
(N
) then
14921 and then Has_Generic_Parent
(T
)
14922 and then (Nkind
(N
) /= N_Pragma
14923 or else Get_Pragma_Id
(N
) /= Pragma_Convention
)
14925 if Ada_Version
< Ada_2022
then
14927 ("representation item not allowed for generic type", N
);
14934 -- Otherwise check for incomplete type
14936 if Is_Incomplete_Or_Private_Type
(T
)
14937 and then No
(Underlying_Type
(T
))
14939 (Nkind
(N
) /= N_Pragma
14940 or else Get_Pragma_Id
(N
) /= Pragma_Import
)
14943 ("representation item must be after full type declaration", N
);
14946 -- If the type has incomplete components, a representation clause is
14947 -- illegal but stream attributes and Convention pragmas are correct.
14949 elsif Has_Private_Component
(T
) then
14950 if Nkind
(N
) = N_Pragma
then
14955 ("representation item must appear after type is fully defined",
14962 end Rep_Item_Too_Early
;
14964 -----------------------
14965 -- Rep_Item_Too_Late --
14966 -----------------------
14968 function Rep_Item_Too_Late
14971 FOnly
: Boolean := False) return Boolean
14973 procedure Too_Late
;
14974 -- Output message for an aspect being specified too late
14976 -- Note that neither of the above errors is considered a serious one,
14977 -- since the effect is simply that we ignore the representation clause
14979 -- Is this really true? In any case if we make this change we must
14980 -- document the requirement in the spec of Rep_Item_Too_Late that
14981 -- if True is returned, then the rep item must be completely ignored???
14987 procedure Too_Late
is
14989 -- Other compilers seem more relaxed about rep items appearing too
14990 -- late. Since analysis tools typically don't care about rep items
14991 -- anyway, no reason to be too strict about this.
14993 if not Relaxed_RM_Semantics
then
14994 Error_Msg_N
("|representation item appears too late!", N
);
15000 Parent_Type
: Entity_Id
;
15003 -- Start of processing for Rep_Item_Too_Late
15006 -- First make sure entity is not frozen (RM 13.1(9))
15010 -- Exclude imported types, which may be frozen if they appear in a
15011 -- representation clause for a local type.
15013 and then not From_Limited_With
(T
)
15015 -- Exclude generated entities (not coming from source). The common
15016 -- case is when we generate a renaming which prematurely freezes the
15017 -- renamed internal entity, but we still want to be able to set copies
15018 -- of attribute values such as Size/Alignment.
15020 and then Comes_From_Source
(T
)
15022 -- A self-referential aspect is illegal if it forces freezing the
15023 -- entity before the corresponding pragma has been analyzed.
15025 if Nkind
(N
) in N_Attribute_Definition_Clause | N_Pragma
15026 and then From_Aspect_Specification
(N
)
15029 ("aspect specification causes premature freezing of&", N
, T
);
15030 Set_Has_Delayed_Freeze
(T
, False);
15035 S
:= First_Subtype
(T
);
15037 if Present
(Freeze_Node
(S
)) then
15038 if not Relaxed_RM_Semantics
then
15040 ("??no more representation items for }", Freeze_Node
(S
), S
);
15046 -- Check for case of untagged derived type whose parent either has
15047 -- primitive operations (pre Ada 2022), or is a by-reference type (RM
15048 -- 13.1(10)). In this case we do not output a Too_Late message, since
15049 -- there is no earlier point where the rep item could be placed to make
15051 -- ??? Confirming representation clauses should be allowed here.
15055 and then Is_Derived_Type
(T
)
15056 and then not Is_Tagged_Type
(T
)
15058 Parent_Type
:= Etype
(Base_Type
(T
));
15060 if Relaxed_RM_Semantics
then
15063 elsif Ada_Version
<= Ada_2012
15064 and then Has_Primitive_Operations
(Parent_Type
)
15067 ("|representation item not permitted before Ada 2022!", N
);
15069 ("\parent type & has primitive operations!", N
, Parent_Type
);
15072 elsif Is_By_Reference_Type
(Parent_Type
) then
15073 No_Type_Rep_Item
(N
);
15075 ("\parent type & is a by-reference type!", N
, Parent_Type
);
15080 -- No error, but one more warning to consider. The RM (surprisingly)
15081 -- allows this pattern in some cases:
15084 -- primitive operations for S
15085 -- type R is new S;
15086 -- rep clause for S
15088 -- Meaning that calls on the primitive operations of S for values of
15089 -- type R may require possibly expensive implicit conversion operations.
15090 -- So even when this is not an error, it is still worth a warning.
15092 if not Relaxed_RM_Semantics
and then Is_Type
(T
) then
15094 DTL
: constant Entity_Id
:= Derived_Type_Link
(Base_Type
(T
));
15099 -- For now, do not generate this warning for the case of
15100 -- aspect specification using Ada 2012 syntax, since we get
15101 -- wrong messages we do not understand. The whole business
15102 -- of derived types and rep items seems a bit confused when
15103 -- aspects are used, since the aspects are not evaluated
15104 -- till freeze time. However, AI12-0109 confirms (in an AARM
15105 -- ramification) that inheritance in this case is required
15108 and then not From_Aspect_Specification
(N
)
15110 if Is_By_Reference_Type
(T
)
15111 and then not Is_Tagged_Type
(T
)
15112 and then Is_Type_Related_Rep_Item
(N
)
15113 and then (Ada_Version
>= Ada_2012
15114 or else Has_Primitive_Operations
(Base_Type
(T
)))
15116 -- Treat as hard error (AI12-0109, binding interpretation).
15117 -- Implementing a change of representation is not really
15118 -- an option in the case of a by-reference type, so we
15119 -- take this path for all Ada dialects if primitive
15120 -- operations are present.
15121 Error_Msg_Sloc
:= Sloc
(DTL
);
15123 ("representation item for& appears after derived type "
15124 & "declaration#", N
);
15126 elsif Has_Primitive_Operations
(Base_Type
(T
)) then
15127 Error_Msg_Sloc
:= Sloc
(DTL
);
15130 ("representation item for& appears after derived type "
15131 & "declaration#??", N
);
15133 ("\may result in implicit conversions for primitive "
15134 & "operations of&??", N
, T
);
15136 ("\to change representations when called with arguments "
15137 & "of type&??", N
, DTL
);
15143 -- No error, link item into head of chain of rep items for the entity,
15144 -- but avoid chaining if we have an overloadable entity, and the pragma
15145 -- is one that can apply to multiple overloaded entities.
15147 if Is_Overloadable
(T
) and then Nkind
(N
) = N_Pragma
then
15149 Pname
: constant Name_Id
:= Pragma_Name
(N
);
15151 if Pname
in Name_Convention | Name_Import | Name_Export
15152 | Name_External | Name_Interface
15159 Record_Rep_Item
(T
, N
);
15161 end Rep_Item_Too_Late
;
15163 -------------------------------------
15164 -- Replace_Type_References_Generic --
15165 -------------------------------------
15167 procedure Replace_Type_References_Generic
(N
: Node_Id
; T
: Entity_Id
) is
15168 TName
: constant Name_Id
:= Chars
(T
);
15170 function Replace_Type_Ref
(N
: Node_Id
) return Traverse_Result
;
15171 -- Processes a single node in the traversal procedure below, checking
15172 -- if node N should be replaced, and if so, doing the replacement.
15174 function Visible_Component
(Comp
: Name_Id
) return Entity_Id
;
15175 -- Given an identifier in the expression, check whether there is a
15176 -- discriminant, component, protected procedure, or entry of the type
15177 -- that is directy visible, and rewrite it as the corresponding selected
15178 -- component of the formal of the subprogram.
15180 ----------------------
15181 -- Replace_Type_Ref --
15182 ----------------------
15184 function Replace_Type_Ref
(N
: Node_Id
) return Traverse_Result
is
15185 Loc
: constant Source_Ptr
:= Sloc
(N
);
15187 procedure Add_Prefix
(Ref
: Node_Id
; Comp
: Entity_Id
);
15188 -- Add the proper prefix to a reference to a component of the type
15189 -- when it is not already a selected component.
15195 procedure Add_Prefix
(Ref
: Node_Id
; Comp
: Entity_Id
) is
15198 Make_Selected_Component
(Loc
,
15199 Prefix
=> New_Occurrence_Of
(T
, Loc
),
15200 Selector_Name
=> New_Occurrence_Of
(Comp
, Loc
)));
15201 Replace_Type_Reference
(Prefix
(Ref
));
15210 -- Start of processing for Replace_Type_Ref
15213 if Nkind
(N
) = N_Identifier
then
15215 -- If not the type name, check whether it is a reference to some
15216 -- other type, which must be frozen before the predicate function
15217 -- is analyzed, i.e. before the freeze node of the type to which
15218 -- the predicate applies.
15220 if Chars
(N
) /= TName
then
15221 if Present
(Current_Entity
(N
))
15222 and then Is_Type
(Current_Entity
(N
))
15224 Freeze_Before
(Freeze_Node
(T
), Current_Entity
(N
));
15227 -- The components of the type are directly visible and can
15228 -- be referenced in the source code without a prefix.
15229 -- If a name denoting a component doesn't already have a
15230 -- prefix, then normalize it by adding a reference to the
15231 -- current instance of the type as a prefix.
15233 -- This isn't right in the pathological corner case of an
15234 -- object-declaring expression (e.g., a quantified expression
15235 -- or a declare expression) that declares an object with the
15236 -- same name as a visible component declaration, thereby hiding
15237 -- the component within that expression. For example, given a
15238 -- record with a Boolean component "C" and a dynamic predicate
15239 -- "C = (for some C in Character => Some_Function (C))", only
15240 -- the first of the two uses of C should have a prefix added
15241 -- here; instead, both will get prefixes.
15243 if Nkind
(Parent
(N
)) /= N_Selected_Component
15244 or else N
/= Selector_Name
(Parent
(N
))
15246 Comp
:= Visible_Component
(Chars
(N
));
15248 if Present
(Comp
) then
15249 Add_Prefix
(N
, Comp
);
15255 -- Otherwise do the replacement if this is not a qualified
15256 -- reference to a homograph of the type itself. Note that the
15257 -- current instance could not appear in such a context, e.g.
15258 -- the prefix of a type conversion.
15261 if Nkind
(Parent
(N
)) /= N_Selected_Component
15262 or else N
/= Selector_Name
(Parent
(N
))
15264 Replace_Type_Reference
(N
);
15270 -- Case of selected component, which may be a subcomponent of the
15271 -- current instance, or an expanded name which is still unanalyzed.
15273 elsif Nkind
(N
) = N_Selected_Component
then
15275 -- If selector name is not our type, keep going (we might still
15276 -- have an occurrence of the type in the prefix). If it is a
15277 -- subcomponent of the current entity, add prefix.
15279 if Nkind
(Selector_Name
(N
)) /= N_Identifier
15280 or else Chars
(Selector_Name
(N
)) /= TName
15282 if Nkind
(Prefix
(N
)) = N_Identifier
then
15283 Comp
:= Visible_Component
(Chars
(Prefix
(N
)));
15285 if Present
(Comp
) then
15286 Add_Prefix
(Prefix
(N
), Comp
);
15292 -- Selector name is our type, check qualification
15295 -- Loop through scopes and prefixes, doing comparison
15297 Scop
:= Current_Scope
;
15298 Pref
:= Prefix
(N
);
15300 -- Continue if no more scopes or scope with no name
15302 if No
(Scop
) or else Nkind
(Scop
) not in N_Has_Chars
then
15306 -- Do replace if prefix is an identifier matching the scope
15307 -- that we are currently looking at.
15309 if Nkind
(Pref
) = N_Identifier
15310 and then Chars
(Pref
) = Chars
(Scop
)
15312 Replace_Type_Reference
(N
);
15316 -- Go check scope above us if prefix is itself of the form
15317 -- of a selected component, whose selector matches the scope
15318 -- we are currently looking at.
15320 if Nkind
(Pref
) = N_Selected_Component
15321 and then Nkind
(Selector_Name
(Pref
)) = N_Identifier
15322 and then Chars
(Selector_Name
(Pref
)) = Chars
(Scop
)
15324 Scop
:= Scope
(Scop
);
15325 Pref
:= Prefix
(Pref
);
15327 -- For anything else, we don't have a match, so keep on
15328 -- going, there are still some weird cases where we may
15329 -- still have a replacement within the prefix.
15337 -- Continue for any other node kind
15342 end Replace_Type_Ref
;
15344 procedure Replace_Type_Refs
is new Traverse_Proc
(Replace_Type_Ref
);
15346 -----------------------
15347 -- Visible_Component --
15348 -----------------------
15350 function Visible_Component
(Comp
: Name_Id
) return Entity_Id
is
15353 -- Types with nameable components are record, task, and protected
15354 -- types, and discriminated private types.
15356 if Ekind
(T
) in E_Record_Type
15359 or else (Is_Private_Type
(T
) and then Has_Discriminants
(T
))
15361 -- This is a sequential search, which seems acceptable
15362 -- efficiency-wise, given the typical size of component
15363 -- lists, protected operation lists, task item lists, and
15364 -- check expressions.
15366 E
:= First_Entity
(T
);
15367 while Present
(E
) loop
15368 if Comes_From_Source
(E
) and then Chars
(E
) = Comp
then
15376 -- Nothing by that name
15379 end Visible_Component
;
15381 -- Start of processing for Replace_Type_References_Generic
15384 Replace_Type_Refs
(N
);
15385 end Replace_Type_References_Generic
;
15387 --------------------------------
15388 -- Resolve_Aspect_Expressions --
15389 --------------------------------
15391 procedure Resolve_Aspect_Expressions
(E
: Entity_Id
) is
15392 function Resolve_Name
(N
: Node_Id
) return Traverse_Result
;
15393 -- Verify that all identifiers in the expression, with the exception
15394 -- of references to the current entity, denote visible entities. This
15395 -- is done only to detect visibility errors, as the expression will be
15396 -- properly analyzed/expanded during analysis of the predicate function
15397 -- body. We omit quantified expressions from this test, given that they
15398 -- introduce a local identifier that would require proper expansion to
15399 -- handle properly.
15405 function Resolve_Name
(N
: Node_Id
) return Traverse_Result
is
15406 Dummy
: Traverse_Result
;
15409 if Nkind
(N
) = N_Selected_Component
then
15410 if Nkind
(Prefix
(N
)) = N_Identifier
15411 and then Chars
(Prefix
(N
)) /= Chars
(E
)
15413 Find_Selected_Component
(N
);
15418 -- Resolve identifiers that are not selectors in parameter
15419 -- associations (these are never resolved by visibility).
15421 elsif Nkind
(N
) = N_Identifier
15422 and then Chars
(N
) /= Chars
(E
)
15423 and then (Nkind
(Parent
(N
)) /= N_Parameter_Association
15424 or else N
/= Selector_Name
(Parent
(N
)))
15426 Find_Direct_Name
(N
);
15428 -- Reset the Entity if N is overloaded since the entity may not
15429 -- be the correct one.
15431 if Is_Overloaded
(N
) then
15432 Set_Entity
(N
, Empty
);
15435 -- The name in a component association needs no resolution
15437 elsif Nkind
(N
) = N_Component_Association
then
15438 Dummy
:= Resolve_Name
(Expression
(N
));
15441 elsif Nkind
(N
) = N_Quantified_Expression
then
15448 procedure Resolve_Aspect_Expression
is new Traverse_Proc
(Resolve_Name
);
15452 ASN
: Node_Id
:= First_Rep_Item
(E
);
15454 -- Start of processing for Resolve_Aspect_Expressions
15457 while Present
(ASN
) loop
15458 if Nkind
(ASN
) = N_Aspect_Specification
and then Entity
(ASN
) = E
then
15460 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(ASN
);
15461 Expr
: constant Node_Id
:= Expression
(ASN
);
15466 when Aspect_Aggregate
=>
15467 Resolve_Aspect_Aggregate
(Entity
(ASN
), Expr
);
15469 when Aspect_Stable_Properties
=>
15470 Resolve_Aspect_Stable_Properties
15471 (Entity
(ASN
), Expr
, Class_Present
(ASN
));
15473 -- For now we only deal with aspects that do not generate
15474 -- subprograms, or that may mention current instances of
15475 -- types. These will require special handling???.
15477 when Aspect_Invariant
15478 | Aspect_Predicate_Failure
15482 when Aspect_Dynamic_Predicate
15483 | Aspect_Static_Predicate
15486 -- Preanalyze expression after type replacement to catch
15487 -- name resolution errors if the predicate function has
15488 -- not been built yet.
15489 -- Note that we cannot use Preanalyze_Spec_Expression
15490 -- because of the special handling required for
15491 -- quantifiers, see comments on Resolve_Aspect_Expression
15494 if No
(Predicate_Function
(E
)) then
15496 Resolve_Aspect_Expression
(Expr
);
15500 when Pre_Post_Aspects
=>
15503 when Aspect_Iterable
=>
15504 if Nkind
(Expr
) = N_Aggregate
then
15509 Assoc
:= First
(Component_Associations
(Expr
));
15510 while Present
(Assoc
) loop
15511 if Nkind
(Expression
(Assoc
)) in N_Has_Entity
15513 Find_Direct_Name
(Expression
(Assoc
));
15521 -- The expression for Default_Value is a static expression
15522 -- of the type, but this expression does not freeze the
15523 -- type, so it can still appear in a representation clause
15524 -- before the actual freeze point.
15526 when Aspect_Default_Value
=>
15527 Set_Must_Not_Freeze
(Expr
);
15528 Preanalyze_Spec_Expression
(Expr
, E
);
15530 when Aspect_Priority
=>
15532 Preanalyze_Spec_Expression
(Expr
, Any_Integer
);
15535 -- Ditto for Storage_Size. Any other aspects that carry
15536 -- expressions that should not freeze ??? This is only
15537 -- relevant to the misuse of deferred constants.
15539 when Aspect_Storage_Size
=>
15540 Set_Must_Not_Freeze
(Expr
);
15541 Preanalyze_Spec_Expression
(Expr
, Any_Integer
);
15544 if Present
(Expr
) then
15545 case Aspect_Argument
(A_Id
) is
15547 | Optional_Expression
15549 Analyze_And_Resolve
(Expr
);
15554 if Nkind
(Expr
) = N_Identifier
then
15555 Find_Direct_Name
(Expr
);
15557 elsif Nkind
(Expr
) = N_Selected_Component
then
15558 Find_Selected_Component
(Expr
);
15566 Next_Rep_Item
(ASN
);
15568 end Resolve_Aspect_Expressions
;
15570 ----------------------------
15571 -- Parse_Aspect_Aggregate --
15572 ----------------------------
15574 procedure Parse_Aspect_Aggregate
15576 Empty_Subp
: in out Node_Id
;
15577 Add_Named_Subp
: in out Node_Id
;
15578 Add_Unnamed_Subp
: in out Node_Id
;
15579 New_Indexed_Subp
: in out Node_Id
;
15580 Assign_Indexed_Subp
: in out Node_Id
)
15582 Assoc
: Node_Id
:= First
(Component_Associations
(N
));
15587 while Present
(Assoc
) loop
15588 Subp
:= Expression
(Assoc
);
15589 Op_Name
:= Chars
(First
(Choices
(Assoc
)));
15590 if Op_Name
= Name_Empty
then
15591 Empty_Subp
:= Subp
;
15593 elsif Op_Name
= Name_Add_Named
then
15594 Add_Named_Subp
:= Subp
;
15596 elsif Op_Name
= Name_Add_Unnamed
then
15597 Add_Unnamed_Subp
:= Subp
;
15599 elsif Op_Name
= Name_New_Indexed
then
15600 New_Indexed_Subp
:= Subp
;
15602 elsif Op_Name
= Name_Assign_Indexed
then
15603 Assign_Indexed_Subp
:= Subp
;
15608 end Parse_Aspect_Aggregate
;
15610 ------------------------------------
15611 -- Parse_Aspect_Stable_Properties --
15612 ------------------------------------
15614 function Parse_Aspect_Stable_Properties
15615 (Aspect_Spec
: Node_Id
; Negated
: out Boolean) return Subprogram_List
15617 function Extract_Entity
(Expr
: Node_Id
) return Entity_Id
;
15618 -- Given an element of a Stable_Properties aspect spec, return the
15619 -- associated entity.
15620 -- This function updates the Negated flag as a side-effect.
15622 --------------------
15623 -- Extract_Entity --
15624 --------------------
15626 function Extract_Entity
(Expr
: Node_Id
) return Entity_Id
is
15629 if Nkind
(Expr
) = N_Op_Not
then
15631 Name
:= Right_Opnd
(Expr
);
15636 if Nkind
(Name
) in N_Has_Entity
then
15637 return Entity
(Name
);
15641 end Extract_Entity
;
15648 -- Start of processing for Parse_Aspect_Stable_Properties
15653 if Nkind
(Aspect_Spec
) /= N_Aggregate
then
15654 return (1 => Extract_Entity
(Aspect_Spec
));
15656 L
:= Expressions
(Aspect_Spec
);
15659 return Result
: Subprogram_List
(1 .. List_Length
(L
)) do
15660 for I
in Result
'Range loop
15661 Result
(I
) := Extract_Entity
(Id
);
15663 if No
(Result
(I
)) then
15664 pragma Assert
(Serious_Errors_Detected
> 0);
15665 goto Ignore_Aspect
;
15673 <<Ignore_Aspect
>> return (1 .. 0 => <>);
15674 end Parse_Aspect_Stable_Properties
;
15676 -------------------------------
15677 -- Validate_Aspect_Aggregate --
15678 -------------------------------
15680 procedure Validate_Aspect_Aggregate
(N
: Node_Id
) is
15681 Empty_Subp
: Node_Id
:= Empty
;
15682 Add_Named_Subp
: Node_Id
:= Empty
;
15683 Add_Unnamed_Subp
: Node_Id
:= Empty
;
15684 New_Indexed_Subp
: Node_Id
:= Empty
;
15685 Assign_Indexed_Subp
: Node_Id
:= Empty
;
15688 Error_Msg_Ada_2022_Feature
("aspect Aggregate", Sloc
(N
));
15690 if Nkind
(N
) /= N_Aggregate
15691 or else Present
(Expressions
(N
))
15692 or else No
(Component_Associations
(N
))
15694 Error_Msg_N
("aspect Aggregate requires an aggregate "
15695 & "with component associations", N
);
15699 Parse_Aspect_Aggregate
(N
,
15700 Empty_Subp
, Add_Named_Subp
, Add_Unnamed_Subp
,
15701 New_Indexed_Subp
, Assign_Indexed_Subp
);
15703 if No
(Empty_Subp
) then
15704 Error_Msg_N
("missing specification for Empty in aggregate", N
);
15707 if Present
(Add_Named_Subp
) then
15708 if Present
(Add_Unnamed_Subp
)
15709 or else Present
(Assign_Indexed_Subp
)
15712 ("conflicting operations for aggregate (RM 4.3.5)", N
);
15716 elsif Present
(New_Indexed_Subp
) /= Present
(Assign_Indexed_Subp
) then
15717 Error_Msg_N
("incomplete specification for indexed aggregate", N
);
15719 end Validate_Aspect_Aggregate
;
15721 -------------------------------
15722 -- Validate_Aspect_Stable_Properties --
15723 -------------------------------
15725 procedure Validate_Aspect_Stable_Properties
15726 (E
: Entity_Id
; N
: Node_Id
; Class_Present
: Boolean)
15728 Is_Aspect_Of_Type
: constant Boolean := Is_Type
(E
);
15730 type Permission
is (Forbidden
, Optional
, Required
);
15731 Modifier_Permission
: Permission
:=
15732 (if Is_Aspect_Of_Type
then Forbidden
else Optional
);
15733 Modifier_Error_Called
: Boolean := False;
15735 procedure Check_Property_Function_Arg
(PF_Arg
: Node_Id
);
15736 -- Check syntax of a property function argument
15738 ----------------------------------
15739 -- Check_Property_Function_Arg --
15740 ----------------------------------
15742 procedure Check_Property_Function_Arg
(PF_Arg
: Node_Id
) is
15743 procedure Modifier_Error
;
15744 -- Generate message about bad "not" modifier if no message already
15745 -- generated. Errors include specifying "not" for an aspect of
15746 -- of a type and specifying "not" for some but not all of the
15747 -- names in a list.
15749 --------------------
15750 -- Modifier_Error --
15751 --------------------
15753 procedure Modifier_Error
is
15755 if Modifier_Error_Called
then
15756 return; -- error message already generated
15759 Modifier_Error_Called
:= True;
15761 if Is_Aspect_Of_Type
then
15763 ("NOT modifier not allowed for Stable_Properties aspect"
15764 & " of a type", PF_Arg
);
15766 Error_Msg_N
("mixed use of NOT modifiers", PF_Arg
);
15768 end Modifier_Error
;
15770 PF_Name
: Node_Id
:= PF_Arg
;
15772 -- Start of processing for Check_Property_Function_Arg
15775 if Nkind
(PF_Arg
) = N_Op_Not
then
15776 PF_Name
:= Right_Opnd
(PF_Arg
);
15778 case Modifier_Permission
is
15782 Modifier_Permission
:= Required
;
15787 case Modifier_Permission
is
15791 Modifier_Permission
:= Forbidden
;
15797 if Nkind
(PF_Name
) not in
15798 N_Identifier | N_Operator_Symbol | N_Selected_Component
15800 Error_Msg_N
("bad property function name", PF_Name
);
15802 end Check_Property_Function_Arg
;
15804 -- Start of processing for Validate_Aspect_Stable_Properties
15807 Error_Msg_Ada_2022_Feature
("aspect Stable_Properties", Sloc
(N
));
15809 if (not Is_Aspect_Of_Type
) and then (not Is_Subprogram
(E
)) then
15810 Error_Msg_N
("Stable_Properties aspect can only be specified for "
15811 & "a type or a subprogram", N
);
15812 elsif Class_Present
then
15813 if Is_Aspect_Of_Type
then
15814 if not Is_Tagged_Type
(E
) then
15816 ("Stable_Properties''Class aspect cannot be specified for "
15817 & "an untagged type", N
);
15820 if not Is_Dispatching_Operation
(E
) then
15822 ("Stable_Properties''Class aspect cannot be specified for "
15823 & "a subprogram that is not a primitive subprogram "
15824 & "of a tagged type", N
);
15829 if Nkind
(N
) = N_Aggregate
then
15830 if Present
(Component_Associations
(N
))
15831 or else Null_Record_Present
(N
)
15832 or else not Present
(Expressions
(N
))
15834 Error_Msg_N
("bad Stable_Properties aspect specification", N
);
15839 PF_Arg
: Node_Id
:= First
(Expressions
(N
));
15841 while Present
(PF_Arg
) loop
15842 Check_Property_Function_Arg
(PF_Arg
);
15847 Check_Property_Function_Arg
(N
);
15849 end Validate_Aspect_Stable_Properties
;
15851 --------------------------------
15852 -- Resolve_Iterable_Operation --
15853 --------------------------------
15855 procedure Resolve_Iterable_Operation
15857 Cursor
: Entity_Id
;
15866 if not Is_Overloaded
(N
) then
15867 if not Is_Entity_Name
(N
)
15868 or else Ekind
(Entity
(N
)) /= E_Function
15869 or else Scope
(Entity
(N
)) /= Scope
(Typ
)
15870 or else No
(First_Formal
(Entity
(N
)))
15871 or else Etype
(First_Formal
(Entity
(N
))) /= Typ
15874 ("iterable primitive must be local function name whose first "
15875 & "formal is an iterable type", N
);
15880 F1
:= First_Formal
(Ent
);
15881 F2
:= Next_Formal
(F1
);
15883 if Nam
= Name_First
then
15885 -- First (Container) => Cursor
15887 if Etype
(Ent
) /= Cursor
then
15888 Error_Msg_N
("primitive for First must yield a cursor", N
);
15889 elsif Present
(F2
) then
15890 Error_Msg_N
("no match for First iterable primitive", N
);
15893 elsif Nam
= Name_Last
then
15895 -- Last (Container) => Cursor
15897 if Etype
(Ent
) /= Cursor
then
15898 Error_Msg_N
("primitive for Last must yield a cursor", N
);
15899 elsif Present
(F2
) then
15900 Error_Msg_N
("no match for Last iterable primitive", N
);
15903 elsif Nam
= Name_Next
then
15905 -- Next (Container, Cursor) => Cursor
15908 or else Etype
(F2
) /= Cursor
15909 or else Etype
(Ent
) /= Cursor
15910 or else Present
(Next_Formal
(F2
))
15912 Error_Msg_N
("no match for Next iterable primitive", N
);
15915 elsif Nam
= Name_Previous
then
15917 -- Previous (Container, Cursor) => Cursor
15920 or else Etype
(F2
) /= Cursor
15921 or else Etype
(Ent
) /= Cursor
15922 or else Present
(Next_Formal
(F2
))
15924 Error_Msg_N
("no match for Previous iterable primitive", N
);
15927 elsif Nam
= Name_Has_Element
then
15929 -- Has_Element (Container, Cursor) => Boolean
15932 or else Etype
(F2
) /= Cursor
15933 or else Etype
(Ent
) /= Standard_Boolean
15934 or else Present
(Next_Formal
(F2
))
15936 Error_Msg_N
("no match for Has_Element iterable primitive", N
);
15939 elsif Nam
= Name_Element
then
15941 -- Element (Container, Cursor) => Element_Type;
15944 or else Etype
(F2
) /= Cursor
15945 or else Present
(Next_Formal
(F2
))
15947 Error_Msg_N
("no match for Element iterable primitive", N
);
15951 raise Program_Error
;
15955 -- Overloaded case: find subprogram with proper signature. Caller
15956 -- will report error if no match is found.
15963 Get_First_Interp
(N
, I
, It
);
15964 while Present
(It
.Typ
) loop
15965 if Ekind
(It
.Nam
) = E_Function
15966 and then Scope
(It
.Nam
) = Scope
(Typ
)
15967 and then Present
(First_Formal
(It
.Nam
))
15968 and then Etype
(First_Formal
(It
.Nam
)) = Typ
15970 F1
:= First_Formal
(It
.Nam
);
15972 if Nam
= Name_First
then
15973 if Etype
(It
.Nam
) = Cursor
15974 and then No
(Next_Formal
(F1
))
15976 Set_Entity
(N
, It
.Nam
);
15980 elsif Nam
= Name_Next
then
15981 F2
:= Next_Formal
(F1
);
15984 and then No
(Next_Formal
(F2
))
15985 and then Etype
(F2
) = Cursor
15986 and then Etype
(It
.Nam
) = Cursor
15988 Set_Entity
(N
, It
.Nam
);
15992 elsif Nam
= Name_Has_Element
then
15993 F2
:= Next_Formal
(F1
);
15996 and then No
(Next_Formal
(F2
))
15997 and then Etype
(F2
) = Cursor
15998 and then Etype
(It
.Nam
) = Standard_Boolean
16000 Set_Entity
(N
, It
.Nam
);
16001 F2
:= Next_Formal
(F1
);
16005 elsif Nam
= Name_Element
then
16006 F2
:= Next_Formal
(F1
);
16009 and then No
(Next_Formal
(F2
))
16010 and then Etype
(F2
) = Cursor
16012 Set_Entity
(N
, It
.Nam
);
16018 Get_Next_Interp
(I
, It
);
16022 end Resolve_Iterable_Operation
;
16024 ------------------------------
16025 -- Resolve_Aspect_Aggregate --
16026 ------------------------------
16028 procedure Resolve_Aspect_Aggregate
16032 function Valid_Empty
(E
: Entity_Id
) return Boolean;
16033 function Valid_Add_Named
(E
: Entity_Id
) return Boolean;
16034 function Valid_Add_Unnamed
(E
: Entity_Id
) return Boolean;
16035 function Valid_New_Indexed
(E
: Entity_Id
) return Boolean;
16036 function Valid_Assign_Indexed
(E
: Entity_Id
) return Boolean;
16037 -- Predicates that establish the legality of each possible operation in
16038 -- an Aggregate aspect.
16041 with function Pred
(Id
: Node_Id
) return Boolean;
16042 procedure Resolve_Operation
(Subp_Id
: Node_Id
);
16043 -- Common processing to resolve each aggregate operation.
16045 ------------------------
16046 -- Valid_Assign_Index --
16047 ------------------------
16049 function Valid_Assign_Indexed
(E
: Entity_Id
) return Boolean is
16051 -- The profile must be the same as for Add_Named, with the added
16052 -- requirement that the key_type be a discrete type.
16054 if Valid_Add_Named
(E
) then
16055 return Is_Discrete_Type
(Etype
(Next_Formal
(First_Formal
(E
))));
16059 end Valid_Assign_Indexed
;
16065 function Valid_Empty
(E
: Entity_Id
) return Boolean is
16067 if Etype
(E
) /= Typ
or else Scope
(E
) /= Scope
(Typ
) then
16070 elsif Ekind
(E
) = E_Constant
then
16073 elsif Ekind
(E
) = E_Function
then
16074 return No
(First_Formal
(E
))
16076 (Is_Integer_Type
(Etype
(First_Formal
(E
)))
16077 and then No
(Next_Formal
(First_Formal
(E
))));
16083 ---------------------
16084 -- Valid_Add_Named --
16085 ---------------------
16087 function Valid_Add_Named
(E
: Entity_Id
) return Boolean is
16088 F2
, F3
: Entity_Id
;
16090 if Ekind
(E
) = E_Procedure
16091 and then Scope
(E
) = Scope
(Typ
)
16092 and then Number_Formals
(E
) = 3
16093 and then Etype
(First_Formal
(E
)) = Typ
16094 and then Ekind
(First_Formal
(E
)) = E_In_Out_Parameter
16096 F2
:= Next_Formal
(First_Formal
(E
));
16097 F3
:= Next_Formal
(F2
);
16098 return Ekind
(F2
) = E_In_Parameter
16099 and then Ekind
(F3
) = E_In_Parameter
16100 and then not Is_Limited_Type
(Etype
(F2
))
16101 and then not Is_Limited_Type
(Etype
(F3
));
16105 end Valid_Add_Named
;
16107 -----------------------
16108 -- Valid_Add_Unnamed --
16109 -----------------------
16111 function Valid_Add_Unnamed
(E
: Entity_Id
) return Boolean is
16113 return Ekind
(E
) = E_Procedure
16114 and then Scope
(E
) = Scope
(Typ
)
16115 and then Number_Formals
(E
) = 2
16116 and then Etype
(First_Formal
(E
)) = Typ
16117 and then Ekind
(First_Formal
(E
)) = E_In_Out_Parameter
16119 not Is_Limited_Type
(Etype
(Next_Formal
(First_Formal
(E
))));
16120 end Valid_Add_Unnamed
;
16122 -----------------------
16123 -- Valid_Nmw_Indexed --
16124 -----------------------
16126 function Valid_New_Indexed
(E
: Entity_Id
) return Boolean is
16128 return Ekind
(E
) = E_Function
16129 and then Scope
(E
) = Scope
(Typ
)
16130 and then Etype
(E
) = Typ
16131 and then Number_Formals
(E
) = 2
16132 and then Is_Discrete_Type
(Etype
(First_Formal
(E
)))
16133 and then Etype
(First_Formal
(E
)) =
16134 Etype
(Next_Formal
(First_Formal
(E
)));
16135 end Valid_New_Indexed
;
16137 -----------------------
16138 -- Resolve_Operation --
16139 -----------------------
16141 procedure Resolve_Operation
(Subp_Id
: Node_Id
) is
16148 if not Is_Overloaded
(Subp_Id
) then
16149 Subp
:= Entity
(Subp_Id
);
16150 if not Pred
(Subp
) then
16152 ("improper aggregate operation for&", Subp_Id
, Typ
);
16156 Set_Entity
(Subp_Id
, Empty
);
16157 Get_First_Interp
(Subp_Id
, I
, It
);
16158 while Present
(It
.Nam
) loop
16159 if Pred
(It
.Nam
) then
16160 Set_Is_Overloaded
(Subp_Id
, False);
16161 Set_Entity
(Subp_Id
, It
.Nam
);
16165 Get_Next_Interp
(I
, It
);
16168 if No
(Entity
(Subp_Id
)) then
16170 ("improper aggregate operation for&", Subp_Id
, Typ
);
16173 end Resolve_Operation
;
16179 procedure Resolve_Empty
is new Resolve_Operation
(Valid_Empty
);
16180 procedure Resolve_Unnamed
is new Resolve_Operation
(Valid_Add_Unnamed
);
16181 procedure Resolve_Named
is new Resolve_Operation
(Valid_Add_Named
);
16182 procedure Resolve_Indexed
is new Resolve_Operation
(Valid_New_Indexed
);
16183 procedure Resolve_Assign_Indexed
16184 is new Resolve_Operation
16185 (Valid_Assign_Indexed
);
16187 -- Start of processing for Resolve_Aspect_Aggregate
16190 Assoc
:= First
(Component_Associations
(Expr
));
16192 while Present
(Assoc
) loop
16193 Op_Name
:= Chars
(First
(Choices
(Assoc
)));
16195 -- When verifying the consistency of aspects between the freeze point
16196 -- and the end of declarqtions, we use a copy which is not analyzed
16197 -- yet, so do it now.
16199 Subp_Id
:= Expression
(Assoc
);
16200 if No
(Etype
(Subp_Id
)) then
16204 if Op_Name
= Name_Empty
then
16205 Resolve_Empty
(Subp_Id
);
16207 elsif Op_Name
= Name_Add_Named
then
16208 Resolve_Named
(Subp_Id
);
16210 elsif Op_Name
= Name_Add_Unnamed
then
16211 Resolve_Unnamed
(Subp_Id
);
16213 elsif Op_Name
= Name_New_Indexed
then
16214 Resolve_Indexed
(Subp_Id
);
16216 elsif Op_Name
= Name_Assign_Indexed
then
16217 Resolve_Assign_Indexed
(Subp_Id
);
16222 end Resolve_Aspect_Aggregate
;
16224 --------------------------------------
16225 -- Resolve_Aspect_Stable_Properties --
16226 --------------------------------------
16228 procedure Resolve_Aspect_Stable_Properties
16229 (Typ_Or_Subp
: Entity_Id
; Expr
: Node_Id
; Class_Present
: Boolean)
16231 Is_Aspect_Of_Type
: constant Boolean := Is_Type
(Typ_Or_Subp
);
16233 Singleton
: constant Boolean := Nkind
(Expr
) /= N_Aggregate
;
16234 Subp_Name
: Node_Id
:= (if Singleton
16236 else First
(Expressions
(Expr
)));
16239 if Is_Aspect_Of_Type
16240 and then Has_Private_Declaration
(Typ_Or_Subp
)
16241 and then not Is_Private_Type
(Typ_Or_Subp
)
16244 ("Stable_Properties aspect cannot be specified " &
16245 "for the completion of a private type", Typ_Or_Subp
);
16248 -- Analogous checks that the aspect is not specified for a completion
16249 -- in the subprogram case are not performed here because they are not
16250 -- specific to this particular aspect. Right ???
16253 Has_Not
:= Nkind
(Subp_Name
) = N_Op_Not
;
16255 Set_Analyzed
(Subp_Name
); -- ???
16256 Subp_Name
:= Right_Opnd
(Subp_Name
);
16259 if No
(Etype
(Subp_Name
)) then
16260 Analyze
(Subp_Name
);
16264 Subp
: Entity_Id
:= Empty
;
16269 function Is_Property_Function
(E
: Entity_Id
) return Boolean;
16270 -- Implements RM 7.3.4 definition of "property function".
16272 function Is_Property_Function
(E
: Entity_Id
) return Boolean is
16274 if Ekind
(E
) not in E_Function | E_Operator
16275 or else Number_Formals
(E
) /= 1
16281 Param_Type
: constant Entity_Id
:=
16282 Base_Type
(Etype
(First_Formal
(E
)));
16284 function Matches_Param_Type
(Typ
: Entity_Id
)
16286 ((Base_Type
(Typ
) = Param_Type
)
16288 (Is_Class_Wide_Type
(Param_Type
)
16289 and then Is_Ancestor
(Root_Type
(Param_Type
),
16290 Base_Type
(Typ
))));
16292 if Is_Aspect_Of_Type
then
16293 if Matches_Param_Type
(Typ_Or_Subp
) then
16296 elsif Is_Primitive
(Typ_Or_Subp
) then
16298 Formal
: Entity_Id
:= First_Formal
(Typ_Or_Subp
);
16300 while Present
(Formal
) loop
16301 if Matches_Param_Type
(Etype
(Formal
)) then
16303 -- Test whether Typ_Or_Subp (which is a subp
16304 -- in this case) is primitive op of the type
16305 -- of this parameter.
16306 if Scope
(Typ_Or_Subp
) = Scope
(Param_Type
) then
16310 Next_Formal
(Formal
);
16317 end Is_Property_Function
;
16319 if not Is_Overloaded
(Subp_Name
) then
16320 Subp
:= Entity
(Subp_Name
);
16321 if not Is_Property_Function
(Subp
) then
16322 Error_Msg_NE
("improper property function for&",
16323 Subp_Name
, Typ_Or_Subp
);
16327 Set_Entity
(Subp_Name
, Empty
);
16328 Get_First_Interp
(Subp_Name
, I
, It
);
16329 while Present
(It
.Nam
) loop
16330 if Is_Property_Function
(It
.Nam
) then
16331 if Present
(Subp
) then
16333 ("ambiguous property function name for&",
16334 Subp_Name
, Typ_Or_Subp
);
16339 Set_Is_Overloaded
(Subp_Name
, False);
16340 Set_Entity
(Subp_Name
, Subp
);
16343 Get_Next_Interp
(I
, It
);
16347 Error_Msg_NE
("improper property function for&",
16348 Subp_Name
, Typ_Or_Subp
);
16353 -- perform legality (as opposed to name resolution) Subp checks
16355 if Is_Limited_Type
(Etype
(Subp
)) then
16357 ("result type of property function for& is limited",
16358 Subp_Name
, Typ_Or_Subp
);
16361 if Ekind
(First_Formal
(Subp
)) /= E_In_Parameter
then
16363 ("mode of parameter of property function for& is not IN",
16364 Subp_Name
, Typ_Or_Subp
);
16367 if Is_Class_Wide_Type
(Etype
(First_Formal
(Subp
))) then
16368 if not Covers
(Etype
(First_Formal
(Subp
)), Typ_Or_Subp
) then
16370 ("class-wide parameter type of property function " &
16371 "for& does not cover the type",
16372 Subp_Name
, Typ_Or_Subp
);
16374 -- ??? This test is slightly stricter than 7.3.4(12/5);
16375 -- some legal corner cases may be incorrectly rejected.
16376 elsif Scope
(Subp
) /= Scope
(Etype
(First_Formal
(Subp
)))
16379 ("property function for& not declared in same scope " &
16380 "as parameter type",
16381 Subp_Name
, Typ_Or_Subp
);
16383 elsif Is_Aspect_Of_Type
and then
16384 Scope
(Subp
) /= Scope
(Typ_Or_Subp
) and then
16385 Scope
(Subp
) /= Standard_Standard
-- e.g., derived type's "abs"
16388 ("property function for& " &
16389 "not a primitive function of the type",
16390 Subp_Name
, Typ_Or_Subp
);
16394 -- check that Subp was mentioned in param type's aspect spec
16396 Param_Type
: constant Entity_Id
:=
16397 Base_Type
(Etype
(First_Formal
(Subp
)));
16398 Aspect_Spec
: constant Node_Id
:=
16399 Find_Value_Of_Aspect
16400 (Param_Type
, Aspect_Stable_Properties
,
16401 Class_Present
=> Class_Present
);
16402 Found
: Boolean := False;
16404 if Present
(Aspect_Spec
) then
16407 SPF_List
: constant Subprogram_List
:=
16408 Parse_Aspect_Stable_Properties
16409 (Aspect_Spec
, Negated
=> Ignored
);
16411 Found
:= (for some E
of SPF_List
=> E
= Subp
);
16412 -- look through renamings ???
16417 CW_Modifier
: constant String :=
16418 (if Class_Present
then "class-wide " else "");
16422 & "property function for& mentioned after NOT "
16425 & "stable property function of its parameter type",
16426 Subp_Name
, Typ_Or_Subp
);
16433 exit when Singleton
;
16435 Next
((if Has_Not
then Parent
(Subp_Name
) else Subp_Name
));
16436 exit when No
(Subp_Name
);
16439 Set_Analyzed
(Expr
);
16440 end Resolve_Aspect_Stable_Properties
;
16442 -----------------------------------------
16443 -- Resolve_Storage_Model_Type_Argument --
16444 -----------------------------------------
16446 procedure Resolve_Storage_Model_Type_Argument
16449 Addr_Type
: in out Entity_Id
;
16453 type Formal_Profile
is record
16455 Mode
: Formal_Kind
;
16458 type Formal_Profiles
is array (Positive range <>) of Formal_Profile
;
16460 function Aspect_Argument_Profile_Matches
16462 Profiles
: Formal_Profiles
;
16463 Result_Subt
: Entity_Id
;
16464 Err_On_Mismatch
: Boolean) return Boolean;
16465 -- Checks that the formal parameters of subprogram Subp conform to the
16466 -- subtypes and modes specified by Profiles, as well as to the result
16467 -- subtype Result_Subt when that is nonempty.
16469 function Aspect_Argument_Profile_Matches
16471 Profiles
: Formal_Profiles
;
16472 Result_Subt
: Entity_Id
;
16473 Err_On_Mismatch
: Boolean) return Boolean
16476 procedure Report_Argument_Error
16478 Formal
: Entity_Id
:= Empty
;
16479 Subt
: Entity_Id
:= Empty
);
16480 -- If Err_On_Mismatch is True, reports an argument error given by Msg
16481 -- associated with Formal and/or Subt.
16483 procedure Report_Argument_Error
16485 Formal
: Entity_Id
:= Empty
;
16486 Subt
: Entity_Id
:= Empty
)
16489 if Err_On_Mismatch
then
16490 if Present
(Formal
) then
16491 if Present
(Subt
) then
16492 Error_Msg_Node_2
:= Subt
;
16494 Error_Msg_NE
(Msg
, N
, Formal
);
16496 elsif Present
(Subt
) then
16497 Error_Msg_NE
(Msg
, N
, Subt
);
16500 Error_Msg_N
(Msg
, N
);
16503 end Report_Argument_Error
;
16507 Formal
: Entity_Id
:= First_Formal
(Subp
);
16508 Is_Error
: Boolean := False;
16510 -- Start of processing for Aspect_Argument_Profile_Matches
16513 for FP
of Profiles
loop
16514 if not Present
(Formal
) then
16516 Report_Argument_Error
("missing formal of }", Subt
=> FP
.Subt
);
16519 elsif not Subtypes_Statically_Match
16520 (Etype
(Formal
), FP
.Subt
)
16523 Report_Argument_Error
16524 ("formal& must be of subtype&",
16525 Formal
=> Formal
, Subt
=> FP
.Subt
);
16528 elsif Ekind
(Formal
) /= FP
.Mode
then
16530 Report_Argument_Error
16531 ("formal& has wrong mode", Formal
=> Formal
);
16535 Formal
:= Next_Formal
(Formal
);
16539 and then Present
(Formal
)
16542 Report_Argument_Error
16543 ("too many formals for subprogram in aspect");
16547 and then Present
(Result_Subt
)
16548 and then not Subtypes_Statically_Match
(Etype
(Subp
), Result_Subt
)
16551 Report_Argument_Error
16552 ("subprogram must have result}", Subt
=> Result_Subt
);
16555 return not Is_Error
;
16556 end Aspect_Argument_Profile_Matches
;
16562 Storage_Count_Type
: constant Entity_Id
:= RTE
(RE_Storage_Count
);
16563 System_Address_Type
: constant Entity_Id
:= RTE
(RE_Address
);
16565 -- Start of processing for Resolve_Storage_Model_Type_Argument
16568 if Nam
= Name_Address_Type
then
16569 if not Is_Entity_Name
(N
)
16570 or else not Is_Type
(Entity
(N
))
16571 or else (Root_Type
(Entity
(N
)) /= System_Address_Type
16572 and then not Is_Integer_Type
(Entity
(N
)))
16574 Error_Msg_N
("named entity must be a descendant of System.Address "
16575 & "or an integer type", N
);
16578 Addr_Type
:= Entity
(N
);
16582 -- If Addr_Type is not present as the first association, then we default
16583 -- it to System.Address.
16585 elsif not Present
(Addr_Type
) then
16586 Addr_Type
:= RTE
(RE_Address
);
16589 if Nam
= Name_Null_Address
then
16590 if not Is_Entity_Name
(N
)
16591 or else not Is_Constant_Object
(Entity
(N
))
16593 not Subtypes_Statically_Match
(Etype
(Entity
(N
)), Addr_Type
)
16596 ("named entity must be constant of subtype}", N
, Addr_Type
);
16601 elsif not Is_Overloaded
(N
) then
16602 if not Is_Entity_Name
(N
)
16603 or else Ekind
(Entity
(N
)) not in E_Function | E_Procedure
16604 or else Scope
(Entity
(N
)) /= Scope
(Typ
)
16606 Error_Msg_N
("argument must be local subprogram name", N
);
16612 if Nam
= Name_Allocate
then
16613 if not Aspect_Argument_Profile_Matches
16616 ((Typ
, E_In_Out_Parameter
),
16617 (Addr_Type
, E_Out_Parameter
),
16618 (Storage_Count_Type
, E_In_Parameter
),
16619 (Storage_Count_Type
, E_In_Parameter
)),
16620 Result_Subt
=> Empty
,
16621 Err_On_Mismatch
=> True)
16623 Error_Msg_N
("no match for Allocate operation", N
);
16626 elsif Nam
= Name_Deallocate
then
16627 if not Aspect_Argument_Profile_Matches
16630 ((Typ
, E_In_Out_Parameter
),
16631 (Addr_Type
, E_In_Parameter
),
16632 (Storage_Count_Type
, E_In_Parameter
),
16633 (Storage_Count_Type
, E_In_Parameter
)),
16634 Result_Subt
=> Empty
,
16635 Err_On_Mismatch
=> True)
16637 Error_Msg_N
("no match for Deallocate operation", N
);
16640 elsif Nam
= Name_Copy_From
then
16641 if not Aspect_Argument_Profile_Matches
16644 ((Typ
, E_In_Out_Parameter
),
16645 (System_Address_Type
, E_In_Parameter
),
16646 (Addr_Type
, E_In_Parameter
),
16647 (Storage_Count_Type
, E_In_Parameter
)),
16648 Result_Subt
=> Empty
,
16649 Err_On_Mismatch
=> True)
16651 Error_Msg_N
("no match for Copy_From operation", N
);
16654 elsif Nam
= Name_Copy_To
then
16655 if not Aspect_Argument_Profile_Matches
16658 ((Typ
, E_In_Out_Parameter
),
16659 (Addr_Type
, E_In_Parameter
),
16660 (System_Address_Type
, E_In_Parameter
),
16661 (Storage_Count_Type
, E_In_Parameter
)),
16662 Result_Subt
=> Empty
,
16663 Err_On_Mismatch
=> True)
16665 Error_Msg_N
("no match for Copy_To operation", N
);
16668 elsif Nam
= Name_Storage_Size
then
16669 if not Aspect_Argument_Profile_Matches
16671 Profiles
=> (1 => (Typ
, E_In_Parameter
)),
16672 Result_Subt
=> Storage_Count_Type
,
16673 Err_On_Mismatch
=> True)
16675 Error_Msg_N
("no match for Storage_Size operation", N
);
16679 null; -- Error will be caught in Validate_Storage_Model_Type_Aspect
16683 -- Overloaded case: find subprogram with proper signature
16688 Found_Match
: Boolean := False;
16691 Get_First_Interp
(N
, I
, It
);
16692 while Present
(It
.Typ
) loop
16693 if Ekind
(It
.Nam
) in E_Function | E_Procedure
16694 and then Scope
(It
.Nam
) = Scope
(Typ
)
16696 if Nam
= Name_Allocate
then
16698 Aspect_Argument_Profile_Matches
16701 ((Typ
, E_In_Out_Parameter
),
16702 (Addr_Type
, E_Out_Parameter
),
16703 (Storage_Count_Type
, E_In_Parameter
),
16704 (Storage_Count_Type
, E_In_Parameter
)),
16705 Result_Subt
=> Empty
,
16706 Err_On_Mismatch
=> False);
16708 elsif Nam
= Name_Deallocate
then
16710 Aspect_Argument_Profile_Matches
16713 ((Typ
, E_In_Out_Parameter
),
16714 (Addr_Type
, E_In_Parameter
),
16715 (Storage_Count_Type
, E_In_Parameter
),
16716 (Storage_Count_Type
, E_In_Parameter
)),
16717 Result_Subt
=> Empty
,
16718 Err_On_Mismatch
=> False);
16720 elsif Nam
= Name_Copy_From
then
16722 Aspect_Argument_Profile_Matches
16725 ((Typ
, E_In_Out_Parameter
),
16726 (System_Address_Type
, E_In_Parameter
),
16727 (Addr_Type
, E_In_Parameter
),
16728 (Storage_Count_Type
, E_In_Parameter
),
16729 (Storage_Count_Type
, E_In_Parameter
)),
16730 Result_Subt
=> Empty
,
16731 Err_On_Mismatch
=> False);
16733 elsif Nam
= Name_Copy_To
then
16735 Aspect_Argument_Profile_Matches
16738 ((Typ
, E_In_Out_Parameter
),
16739 (Addr_Type
, E_In_Parameter
),
16740 (Storage_Count_Type
, E_In_Parameter
),
16741 (System_Address_Type
, E_In_Parameter
),
16742 (Storage_Count_Type
, E_In_Parameter
)),
16743 Result_Subt
=> Empty
,
16744 Err_On_Mismatch
=> False);
16746 elsif Nam
= Name_Storage_Size
then
16748 Aspect_Argument_Profile_Matches
16750 Profiles
=> (1 => (Typ
, E_In_Parameter
)),
16751 Result_Subt
=> Storage_Count_Type
,
16752 Err_On_Mismatch
=> False);
16755 if Found_Match
then
16756 Set_Entity
(N
, It
.Nam
);
16761 Get_Next_Interp
(I
, It
);
16764 if not Found_Match
then
16766 ("no match found for Storage_Model_Type operation", N
);
16770 end Resolve_Storage_Model_Type_Argument
;
16776 procedure Set_Biased
16780 Biased
: Boolean := True)
16784 Set_Has_Biased_Representation
(E
);
16786 if Warn_On_Biased_Representation
then
16788 ("?.b?" & Msg
& " forces biased representation for&", N
, E
);
16793 --------------------
16794 -- Set_Enum_Esize --
16795 --------------------
16797 procedure Set_Enum_Esize
(T
: Entity_Id
) is
16803 Reinit_Alignment
(T
);
16805 -- Find the minimum standard size (8,16,32,64,128) that fits
16807 Lo
:= Enumeration_Rep
(Entity
(Type_Low_Bound
(T
)));
16808 Hi
:= Enumeration_Rep
(Entity
(Type_High_Bound
(T
)));
16811 if Lo
>= -Uint_2
**7 and then Hi
< Uint_2
**7 then
16812 Sz
:= UI_From_Int
(Standard_Character_Size
);
16813 -- Might be > 8 on some targets
16815 elsif Lo
>= -Uint_2
**15 and then Hi
< Uint_2
**15 then
16818 elsif Lo
>= -Uint_2
**31 and then Hi
< Uint_2
**31 then
16821 elsif Lo
>= -Uint_2
**63 and then Hi
< Uint_2
**63 then
16824 else pragma Assert
(Lo
>= -Uint_2
**127 and then Hi
< Uint_2
**127);
16829 if Hi
< Uint_2
**8 then
16830 Sz
:= UI_From_Int
(Standard_Character_Size
);
16832 elsif Hi
< Uint_2
**16 then
16835 elsif Hi
< Uint_2
**32 then
16838 elsif Hi
< Uint_2
**64 then
16841 else pragma Assert
(Hi
< Uint_2
**128);
16846 -- That minimum is the proper size unless we have a foreign convention
16847 -- and the size required is 32 or less, in which case we bump the size
16848 -- up to 32. This is required for C and C++ and seems reasonable for
16849 -- all other foreign conventions.
16851 if Has_Foreign_Convention
(T
)
16852 and then Esize
(T
) < Standard_Integer_Size
16854 -- Don't do this if Short_Enums on target
16856 and then not Target_Short_Enums
16858 Set_Esize
(T
, UI_From_Int
(Standard_Integer_Size
));
16862 end Set_Enum_Esize
;
16864 -----------------------------
16865 -- Uninstall_Discriminants --
16866 -----------------------------
16868 procedure Uninstall_Discriminants
(E
: Entity_Id
) is
16874 -- Discriminants have been made visible for type declarations and
16875 -- protected type declarations, not for subtype declarations.
16877 if Nkind
(Parent
(E
)) /= N_Subtype_Declaration
then
16878 Disc
:= First_Discriminant
(E
);
16879 while Present
(Disc
) loop
16880 if Disc
/= Current_Entity
(Disc
) then
16881 Prev
:= Current_Entity
(Disc
);
16882 while Present
(Prev
)
16883 and then Present
(Homonym
(Prev
))
16884 and then Homonym
(Prev
) /= Disc
16886 Prev
:= Homonym
(Prev
);
16892 Set_Is_Immediately_Visible
(Disc
, False);
16894 Outer
:= Homonym
(Disc
);
16895 while Present
(Outer
) and then Scope
(Outer
) = E
loop
16896 Outer
:= Homonym
(Outer
);
16899 -- Reset homonym link of other entities, but do not modify link
16900 -- between entities in current scope, so that the back end can
16901 -- have a proper count of local overloadings.
16904 Set_Name_Entity_Id
(Chars
(Disc
), Outer
);
16906 elsif Scope
(Prev
) /= Scope
(Disc
) then
16907 Set_Homonym
(Prev
, Outer
);
16910 Next_Discriminant
(Disc
);
16913 end Uninstall_Discriminants
;
16915 ------------------------------
16916 -- Validate_Address_Clauses --
16917 ------------------------------
16919 procedure Validate_Address_Clauses
is
16920 function Offset_Value
(Expr
: Node_Id
) return Uint
;
16921 -- Given an Address attribute reference, return the value in bits of its
16922 -- offset from the first bit of the underlying entity, or 0 if it is not
16923 -- known at compile time.
16929 function Offset_Value
(Expr
: Node_Id
) return Uint
is
16930 N
: Node_Id
:= Prefix
(Expr
);
16932 Val
: Uint
:= Uint_0
;
16935 -- Climb the prefix chain and compute the cumulative offset
16938 if Is_Entity_Name
(N
) then
16941 elsif Nkind
(N
) = N_Selected_Component
then
16942 Off
:= Component_Bit_Offset
(Entity
(Selector_Name
(N
)));
16943 if Present
(Off
) and then Off
>= Uint_0
then
16950 elsif Nkind
(N
) = N_Indexed_Component
then
16951 Off
:= Indexed_Component_Bit_Offset
(N
);
16952 if Present
(Off
) then
16965 -- Start of processing for Validate_Address_Clauses
16968 for J
in Address_Clause_Checks
.First
.. Address_Clause_Checks
.Last
loop
16970 ACCR
: Address_Clause_Check_Record
16971 renames Address_Clause_Checks
.Table
(J
);
16975 X_Alignment
: Uint
;
16976 Y_Alignment
: Uint
:= Uint_0
;
16979 Y_Size
: Uint
:= Uint_0
;
16984 -- Skip processing of this entry if warning already posted, or if
16985 -- alignments are not set.
16987 if not Address_Warning_Posted
(ACCR
.N
)
16988 and then Known_Alignment
(ACCR
.X
)
16989 and then Known_Alignment
(ACCR
.Y
)
16991 Expr
:= Original_Node
(Expression
(ACCR
.N
));
16993 -- Get alignments, sizes and offset, if any
16995 X_Alignment
:= Alignment
(ACCR
.X
);
16996 X_Size
:= Esize
(ACCR
.X
);
16998 if Present
(ACCR
.Y
) then
16999 Y_Alignment
:= Alignment
(ACCR
.Y
);
17001 (if Known_Esize
(ACCR
.Y
) then Esize
(ACCR
.Y
) else Uint_0
);
17005 and then Nkind
(Expr
) = N_Attribute_Reference
17006 and then Attribute_Name
(Expr
) = Name_Address
17008 X_Offs
:= Offset_Value
(Expr
);
17013 -- Check for known value not multiple of alignment
17015 if No
(ACCR
.Y
) then
17016 if not Alignment_Checks_Suppressed
(ACCR
)
17017 and then X_Alignment
/= 0
17018 and then ACCR
.A
mod X_Alignment
/= 0
17021 ("??specified address for& is inconsistent with "
17022 & "alignment", ACCR
.N
, ACCR
.X
);
17024 ("\??program execution may be erroneous (RM 13.3(27))",
17027 Error_Msg_Uint_1
:= X_Alignment
;
17028 Error_Msg_NE
("\??alignment of & is ^", ACCR
.N
, ACCR
.X
);
17031 -- Check for large object overlaying smaller one
17033 elsif Y_Size
> Uint_0
17034 and then X_Size
> Uint_0
17035 and then X_Offs
+ X_Size
> Y_Size
17037 Error_Msg_NE
("??& overlays smaller object", ACCR
.N
, ACCR
.X
);
17039 ("\??program execution may be erroneous", ACCR
.N
);
17041 Error_Msg_Uint_1
:= X_Size
;
17042 Error_Msg_NE
("\??size of & is ^", ACCR
.N
, ACCR
.X
);
17044 Error_Msg_Uint_1
:= Y_Size
;
17045 Error_Msg_NE
("\??size of & is ^", ACCR
.N
, ACCR
.Y
);
17047 if Y_Size
>= X_Size
then
17048 Error_Msg_Uint_1
:= X_Offs
;
17049 Error_Msg_NE
("\??but offset of & is ^", ACCR
.N
, ACCR
.X
);
17052 -- Check for inadequate alignment, both of the base object
17053 -- and of the offset, if any. We only do this check if the
17054 -- run-time Alignment_Check is active. No point in warning
17055 -- if this check has been suppressed (or is suppressed by
17056 -- default in the non-strict alignment machine case).
17058 -- Note: we do not check the alignment if we gave a size
17059 -- warning, since it would likely be redundant.
17061 elsif not Alignment_Checks_Suppressed
(ACCR
)
17062 and then Y_Alignment
/= Uint_0
17064 (Y_Alignment
< X_Alignment
17067 and then Nkind
(Expr
) = N_Attribute_Reference
17068 and then Attribute_Name
(Expr
) = Name_Address
17069 and then Has_Compatible_Alignment
17070 (ACCR
.X
, Prefix
(Expr
), True) /=
17074 ("??specified address for& may be inconsistent with "
17075 & "alignment", ACCR
.N
, ACCR
.X
);
17077 ("\??program execution may be erroneous (RM 13.3(27))",
17080 Error_Msg_Uint_1
:= X_Alignment
;
17081 Error_Msg_NE
("\??alignment of & is ^", ACCR
.N
, ACCR
.X
);
17083 Error_Msg_Uint_1
:= Y_Alignment
;
17084 Error_Msg_NE
("\??alignment of & is ^", ACCR
.N
, ACCR
.Y
);
17086 if Y_Alignment
>= X_Alignment
then
17088 ("\??but offset is not multiple of alignment", ACCR
.N
);
17094 end Validate_Address_Clauses
;
17096 ------------------------------
17097 -- Validate_Iterable_Aspect --
17098 ------------------------------
17100 procedure Validate_Iterable_Aspect
(Typ
: Entity_Id
; ASN
: Node_Id
) is
17101 Aggr
: constant Node_Id
:= Expression
(ASN
);
17106 Cursor
: Entity_Id
;
17108 First_Id
: Entity_Id
:= Empty
;
17109 Last_Id
: Entity_Id
:= Empty
;
17110 Next_Id
: Entity_Id
:= Empty
;
17111 Has_Element_Id
: Entity_Id
:= Empty
;
17112 Element_Id
: Entity_Id
:= Empty
;
17115 if Nkind
(Aggr
) /= N_Aggregate
then
17116 Error_Msg_N
("aspect Iterable must be an aggregate", Aggr
);
17120 Cursor
:= Get_Cursor_Type
(ASN
, Typ
);
17122 -- If previous error aspect is unusable
17124 if Cursor
= Any_Type
then
17128 if not Is_Empty_List
(Expressions
(Aggr
)) then
17130 ("illegal positional association", First
(Expressions
(Aggr
)));
17133 -- Each expression must resolve to a function with the proper signature
17135 Assoc
:= First
(Component_Associations
(Aggr
));
17136 while Present
(Assoc
) loop
17137 Expr
:= Expression
(Assoc
);
17140 Prim
:= First
(Choices
(Assoc
));
17142 if Nkind
(Prim
) /= N_Identifier
or else Present
(Next
(Prim
)) then
17143 Error_Msg_N
("illegal name in association", Prim
);
17145 elsif Chars
(Prim
) = Name_First
then
17146 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_First
);
17147 First_Id
:= Entity
(Expr
);
17149 elsif Chars
(Prim
) = Name_Last
then
17150 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_Last
);
17151 Last_Id
:= Entity
(Expr
);
17153 elsif Chars
(Prim
) = Name_Previous
then
17154 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_Previous
);
17155 Last_Id
:= Entity
(Expr
);
17157 elsif Chars
(Prim
) = Name_Next
then
17158 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_Next
);
17159 Next_Id
:= Entity
(Expr
);
17161 elsif Chars
(Prim
) = Name_Has_Element
then
17162 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_Has_Element
);
17163 Has_Element_Id
:= Entity
(Expr
);
17165 elsif Chars
(Prim
) = Name_Element
then
17166 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_Element
);
17167 Element_Id
:= Entity
(Expr
);
17170 Error_Msg_N
("invalid name for iterable function", Prim
);
17176 if No
(First_Id
) then
17177 Error_Msg_N
("match for First primitive not found", ASN
);
17179 elsif No
(Next_Id
) then
17180 Error_Msg_N
("match for Next primitive not found", ASN
);
17182 elsif No
(Has_Element_Id
) then
17183 Error_Msg_N
("match for Has_Element primitive not found", ASN
);
17185 elsif No
(Element_Id
) or else No
(Last_Id
) then
17188 end Validate_Iterable_Aspect
;
17190 ------------------------------
17191 -- Validate_Literal_Aspect --
17192 ------------------------------
17194 procedure Validate_Literal_Aspect
(Typ
: Entity_Id
; ASN
: Node_Id
) is
17195 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(ASN
);
17196 pragma Assert
(A_Id
in Aspect_Integer_Literal |
17197 Aspect_Real_Literal | Aspect_String_Literal
);
17198 Func_Name
: constant Node_Id
:= Expression
(ASN
);
17199 Overloaded
: Boolean := Is_Overloaded
(Func_Name
);
17201 I
: Interp_Index
:= 0;
17203 Param_Type
: Entity_Id
;
17204 Match_Found
: Boolean := False;
17205 Match2_Found
: Boolean := False;
17206 Is_Match
: Boolean;
17208 Match2
: Entity_Id
:= Empty
;
17211 (Param_Id
: Entity_Id
; Param_Type
: Entity_Id
) return Boolean;
17212 -- Return True if Param_Id is a non aliased in parameter whose base type
17220 (Param_Id
: Entity_Id
; Param_Type
: Entity_Id
) return Boolean is
17222 return Base_Type
(Etype
(Param_Id
)) = Param_Type
17223 and then Ekind
(Param_Id
) = E_In_Parameter
17224 and then not Is_Aliased
(Param_Id
);
17228 if not Is_Type
(Typ
) then
17229 Error_Msg_N
("aspect can only be specified for a type", ASN
);
17232 elsif not Is_First_Subtype
(Typ
) then
17233 Error_Msg_N
("aspect cannot be specified for a subtype", ASN
);
17237 if A_Id
= Aspect_String_Literal
then
17238 if Is_String_Type
(Typ
) then
17239 Error_Msg_N
("aspect cannot be specified for a string type", ASN
);
17243 Param_Type
:= Standard_Wide_Wide_String
;
17246 if Is_Numeric_Type
(Typ
) then
17247 Error_Msg_N
("aspect cannot be specified for a numeric type", ASN
);
17251 Param_Type
:= Standard_String
;
17254 if not Overloaded
and then not Present
(Entity
(Func_Name
)) then
17255 -- The aspect is specified by a subprogram name, which
17256 -- may be an operator name given originally by a string.
17258 if Is_Operator_Name
(Chars
(Func_Name
)) then
17259 Analyze_Operator_Symbol
(Func_Name
);
17261 Analyze
(Func_Name
);
17264 Overloaded
:= Is_Overloaded
(Func_Name
);
17268 Get_First_Interp
(Func_Name
, I
=> I
, It
=> It
);
17270 -- only one possible interpretation
17271 It
.Nam
:= Entity
(Func_Name
);
17272 pragma Assert
(Present
(It
.Nam
));
17275 while It
.Nam
/= Empty
loop
17278 if Ekind
(It
.Nam
) = E_Function
17279 and then Base_Type
(Etype
(It
.Nam
)) = Base_Type
(Typ
)
17282 Params
: constant List_Id
:=
17283 Parameter_Specifications
(Parent
(It
.Nam
));
17284 Param_Spec
: Node_Id
;
17287 if List_Length
(Params
) = 1 then
17288 Param_Spec
:= First
(Params
);
17290 Matching
(Defining_Identifier
(Param_Spec
), Param_Type
);
17292 -- Look for the optional overloaded 2-param Real_Literal
17294 elsif List_Length
(Params
) = 2
17295 and then A_Id
= Aspect_Real_Literal
17297 Param_Spec
:= First
(Params
);
17299 if Matching
(Defining_Identifier
(Param_Spec
), Param_Type
)
17301 Param_Spec
:= Next
(Param_Spec
);
17303 if Matching
(Defining_Identifier
(Param_Spec
), Param_Type
)
17305 if No
(Match2
) then
17307 Match2_Found
:= True;
17309 -- If we find more than one possible match then
17310 -- do not take any into account here: since the
17311 -- 2-parameter version of Real_Literal is optional
17312 -- we cannot generate an error here, so let
17313 -- standard resolution fail later if we do need to
17314 -- call this variant.
17316 Match2_Found
:= False;
17325 if Match_Found
then
17326 Error_Msg_N
("aspect specification is ambiguous", ASN
);
17330 Match_Found
:= True;
17334 exit when not Overloaded
;
17336 if not Is_Match
then
17337 Remove_Interp
(I
=> I
);
17340 Get_Next_Interp
(I
=> I
, It
=> It
);
17343 if not Match_Found
then
17345 ("function name in aspect specification cannot be resolved", ASN
);
17349 Set_Entity
(Func_Name
, Match
.Nam
);
17350 Set_Etype
(Func_Name
, Etype
(Match
.Nam
));
17351 Set_Is_Overloaded
(Func_Name
, False);
17353 -- Record the match for 2-parameter function if found
17355 if Match2_Found
then
17356 Set_Related_Expression
(Match
.Nam
, Match2
);
17358 end Validate_Literal_Aspect
;
17360 ----------------------------------------
17361 -- Validate_Storage_Model_Type_Aspect --
17362 ----------------------------------------
17364 procedure Validate_Storage_Model_Type_Aspect
17365 (Typ
: Entity_Id
; ASN
: Node_Id
)
17368 Choice
: Entity_Id
;
17369 Choice_Name
: Name_Id
;
17372 Address_Type_Id
: Entity_Id
:= Empty
;
17373 Null_Address_Id
: Entity_Id
:= Empty
;
17374 Allocate_Id
: Entity_Id
:= Empty
;
17375 Deallocate_Id
: Entity_Id
:= Empty
;
17376 Copy_From_Id
: Entity_Id
:= Empty
;
17377 Copy_To_Id
: Entity_Id
:= Empty
;
17378 Storage_Size_Id
: Entity_Id
:= Empty
;
17380 procedure Check_And_Resolve_Storage_Model_Type_Argument
17383 Argument_Id
: in out Entity_Id
;
17385 -- Checks that the subaspect for Nam has not already been specified for
17386 -- Typ's Storage_Model_Type aspect (i.e., checks Argument_Id = Empty),
17387 -- resolves Expr, and sets Argument_Id to the entity resolved for Expr.
17389 procedure Check_And_Resolve_Storage_Model_Type_Argument
17392 Argument_Id
: in out Entity_Id
;
17395 Name_String
: String := Get_Name_String
(Nam
);
17398 To_Mixed
(Name_String
);
17400 if Present
(Argument_Id
) then
17401 Error_Msg_String
(1 .. Name_String
'Length) := Name_String
;
17402 Error_Msg_Strlen
:= Name_String
'Length;
17404 Error_Msg_N
("~ already specified", Expr
);
17407 Resolve_Storage_Model_Type_Argument
(Expr
, Typ
, Address_Type_Id
, Nam
);
17408 Argument_Id
:= Entity
(Expr
);
17409 end Check_And_Resolve_Storage_Model_Type_Argument
;
17411 -- Start of processing for Validate_Storage_Model_Type_Aspect
17414 -- The aggregate argument of Storage_Model_Type is optional, and when
17415 -- not present the aspect defaults to the native storage model (where
17416 -- the address type is System.Address, and other arguments default to
17417 -- the corresponding native storage operations).
17419 if No
(Expression
(ASN
)) then
17423 -- Each expression must resolve to an entity of the right kind or proper
17426 Assoc
:= First
(Component_Associations
(Expression
(ASN
)));
17427 while Present
(Assoc
) loop
17428 Expr
:= Expression
(Assoc
);
17431 Choice
:= First
(Choices
(Assoc
));
17433 Choice_Name
:= Chars
(Choice
);
17435 if Nkind
(Choice
) /= N_Identifier
or else Present
(Next
(Choice
)) then
17436 Error_Msg_N
("illegal name in association", Choice
);
17438 elsif Choice_Name
= Name_Address_Type
then
17439 if Assoc
/= First
(Component_Associations
(Expression
(ASN
))) then
17440 Error_Msg_N
("Address_Type must be first association", Choice
);
17443 Check_And_Resolve_Storage_Model_Type_Argument
17444 (Expr
, Typ
, Address_Type_Id
, Name_Address_Type
);
17447 -- It's allowed to leave out the Address_Type argument, in which
17448 -- case the address type is defined to default to System.Address.
17450 if No
(Address_Type_Id
) then
17451 Address_Type_Id
:= RTE
(RE_Address
);
17454 if Choice_Name
= Name_Null_Address
then
17455 Check_And_Resolve_Storage_Model_Type_Argument
17456 (Expr
, Typ
, Null_Address_Id
, Name_Null_Address
);
17458 elsif Choice_Name
= Name_Allocate
then
17459 Check_And_Resolve_Storage_Model_Type_Argument
17460 (Expr
, Typ
, Allocate_Id
, Name_Allocate
);
17462 elsif Choice_Name
= Name_Deallocate
then
17463 Check_And_Resolve_Storage_Model_Type_Argument
17464 (Expr
, Typ
, Deallocate_Id
, Name_Deallocate
);
17466 elsif Choice_Name
= Name_Copy_From
then
17467 Check_And_Resolve_Storage_Model_Type_Argument
17468 (Expr
, Typ
, Copy_From_Id
, Name_Copy_From
);
17470 elsif Choice_Name
= Name_Copy_To
then
17471 Check_And_Resolve_Storage_Model_Type_Argument
17472 (Expr
, Typ
, Copy_To_Id
, Name_Copy_To
);
17474 elsif Choice_Name
= Name_Storage_Size
then
17475 Check_And_Resolve_Storage_Model_Type_Argument
17476 (Expr
, Typ
, Storage_Size_Id
, Name_Storage_Size
);
17480 ("invalid name for Storage_Model_Type argument", Choice
);
17487 -- If Address_Type has been specified as or defaults to System.Address,
17488 -- then other "subaspect" arguments can be specified, but are optional.
17489 -- Otherwise, all other arguments are required and an error is flagged
17490 -- about any that are missing.
17492 if Address_Type_Id
= RTE
(RE_Address
) then
17495 elsif No
(Null_Address_Id
) then
17496 Error_Msg_N
("match for Null_Address primitive not found", ASN
);
17498 elsif No
(Allocate_Id
) then
17499 Error_Msg_N
("match for Allocate primitive not found", ASN
);
17501 elsif No
(Deallocate_Id
) then
17502 Error_Msg_N
("match for Deallocate primitive not found", ASN
);
17504 elsif No
(Copy_From_Id
) then
17505 Error_Msg_N
("match for Copy_From primitive not found", ASN
);
17507 elsif No
(Copy_To_Id
) then
17508 Error_Msg_N
("match for Copy_To primitive not found", ASN
);
17510 elsif No
(Storage_Size_Id
) then
17511 Error_Msg_N
("match for Storage_Size primitive not found", ASN
);
17513 end Validate_Storage_Model_Type_Aspect
;
17515 -----------------------------------
17516 -- Validate_Unchecked_Conversion --
17517 -----------------------------------
17519 procedure Validate_Unchecked_Conversion
17521 Act_Unit
: Entity_Id
)
17523 Source
: Entity_Id
;
17524 Target
: Entity_Id
;
17526 procedure Warn_Nonportable
(RE
: RE_Id
);
17527 -- Warn if either source or target of the conversion is a predefined
17528 -- private type, whose representation might differ between releases and
17529 -- targets of the compiler.
17531 ----------------------
17532 -- Warn_Nonportable --
17533 ----------------------
17535 procedure Warn_Nonportable
(RE
: RE_Id
) is
17537 if Is_RTE
(Source
, RE
) or else Is_RTE
(Target
, RE
) then
17538 pragma Assert
(Is_Private_Type
(RTE
(RE
)));
17540 ("?z?representation of & values may change between "
17541 & "'G'N'A'T versions", N
, RTE
(RE
));
17543 end Warn_Nonportable
;
17549 -- Start of processing for Validate_Unchecked_Conversion
17552 -- Obtain source and target types. Note that we call Ancestor_Subtype
17553 -- here because the processing for generic instantiation always makes
17554 -- subtypes, and we want the original frozen actual types.
17556 Source
:= Ancestor_Subtype
(Etype
(First_Formal
(Act_Unit
)));
17557 Target
:= Ancestor_Subtype
(Etype
(Act_Unit
));
17559 -- If either type is generic, the instantiation happens within a generic
17560 -- unit, and there is nothing to check. The proper check will happen
17561 -- when the enclosing generic is instantiated.
17563 if Is_Generic_Type
(Source
) or else Is_Generic_Type
(Target
) then
17567 -- Warn if one of the operands is a private type declared in
17568 -- Ada.Calendar or Ada.Real_Time. Do not emit a warning when compiling
17569 -- GNAT-related sources.
17571 if Warn_On_Unchecked_Conversion
17572 and then not In_Predefined_Unit
(N
)
17574 Warn_Nonportable
(RO_CA_Time
);
17575 Warn_Nonportable
(RO_RT_Time
);
17576 Warn_Nonportable
(RE_Time_Span
);
17579 -- If we are dealing with private types, then do the check on their
17580 -- fully declared counterparts if the full declarations have been
17581 -- encountered (they don't have to be visible, but they must exist).
17583 if Is_Private_Type
(Source
)
17584 and then Present
(Underlying_Type
(Source
))
17586 Source
:= Underlying_Type
(Source
);
17589 if Is_Private_Type
(Target
)
17590 and then Present
(Underlying_Type
(Target
))
17592 Target
:= Underlying_Type
(Target
);
17595 -- Source may be unconstrained array, but not target, except in relaxed
17598 if Is_Array_Type
(Target
)
17599 and then not Is_Constrained
(Target
)
17600 and then not Relaxed_RM_Semantics
17603 ("unchecked conversion to unconstrained array not allowed", N
);
17607 -- Warn if conversion between two different convention pointers
17609 if Is_Access_Type
(Target
)
17610 and then Is_Access_Type
(Source
)
17611 and then Convention
(Target
) /= Convention
(Source
)
17612 and then Warn_On_Unchecked_Conversion
17614 -- Give warnings for subprogram pointers only on most targets
17616 if Is_Access_Subprogram_Type
(Target
)
17617 or else Is_Access_Subprogram_Type
(Source
)
17620 ("?z?conversion between pointers with different conventions!",
17625 -- Make entry in unchecked conversion table for later processing by
17626 -- Validate_Unchecked_Conversions, which will check sizes and alignments
17627 -- (using values set by the back end where possible). This is only done
17628 -- if the appropriate warning is active.
17630 if Warn_On_Unchecked_Conversion
then
17631 Unchecked_Conversions
.Append
17632 (New_Val
=> UC_Entry
'(Eloc => Sloc (N),
17635 Act_Unit => Act_Unit));
17637 -- If both sizes are known statically now, then back-end annotation
17638 -- is not required to do a proper check but if either size is not
17639 -- known statically, then we need the annotation.
17641 if Known_Static_RM_Size (Source)
17643 Known_Static_RM_Size (Target)
17647 Back_Annotate_Rep_Info := True;
17651 -- If unchecked conversion to access type, and access type is declared
17652 -- in the same unit as the unchecked conversion, then set the flag
17653 -- No_Strict_Aliasing (no strict aliasing is implicit here)
17655 if Is_Access_Type (Target)
17656 and then In_Same_Source_Unit (Target, N)
17658 Set_No_Strict_Aliasing (Implementation_Base_Type (Target));
17661 -- If the unchecked conversion is between Address and an access
17662 -- subprogram type, show that we shouldn't use an internal
17663 -- representation for the access subprogram type.
17665 if Is_Access_Subprogram_Type (Target)
17666 and then Is_Descendant_Of_Address (Source)
17667 and then In_Same_Source_Unit (Target, N)
17669 Set_Can_Use_Internal_Rep (Target, False);
17670 elsif Is_Access_Subprogram_Type (Source)
17671 and then Is_Descendant_Of_Address (Target)
17672 and then In_Same_Source_Unit (Source, N)
17674 Set_Can_Use_Internal_Rep (Source, False);
17677 -- Generate N_Validate_Unchecked_Conversion node for back end in case
17678 -- the back end needs to perform special validation checks.
17680 -- Shouldn't this be in Exp_Ch13, since the check only gets done if we
17681 -- have full expansion and the back end is called ???
17684 Make_Validate_Unchecked_Conversion (Sloc (N));
17685 Set_Source_Type (Vnode, Source);
17686 Set_Target_Type (Vnode, Target);
17688 -- If the unchecked conversion node is in a list, just insert before it.
17689 -- If not we have some strange case, not worth bothering about.
17691 if Is_List_Member (N) then
17692 Insert_After (N, Vnode);
17694 end Validate_Unchecked_Conversion;
17696 ------------------------------------
17697 -- Validate_Unchecked_Conversions --
17698 ------------------------------------
17700 procedure Validate_Unchecked_Conversions is
17701 function Is_Null_Array (T : Entity_Id) return Boolean;
17702 -- We want to warn in the case of converting to a wrong-sized array of
17703 -- bytes, including the zero-size case. This returns True in that case,
17704 -- which is necessary because a size of 0 is used to indicate both an
17705 -- unknown size and a size of 0. It's OK for this to return True in
17706 -- other zero-size cases, but we don't go out of our way; for example,
17707 -- we don't bother with multidimensional arrays.
17709 function Is_Null_Array (T : Entity_Id) return Boolean is
17711 if Is_Array_Type (T) and then Is_Constrained (T) then
17713 Index : constant Node_Id := First_Index (T);
17714 R : Node_Id; -- N_Range
17716 case Nkind (Index) is
17719 when N_Subtype_Indication =>
17720 R := Range_Expression (Constraint (Index));
17721 when N_Identifier | N_Expanded_Name =>
17722 R := Scalar_Range (Entity (Index));
17724 raise Program_Error;
17727 return Is_Null_Range (Low_Bound (R), High_Bound (R));
17735 for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop
17737 T : UC_Entry renames Unchecked_Conversions.Table (N);
17739 Act_Unit : constant Entity_Id := T.Act_Unit;
17740 Eloc : constant Source_Ptr := T.Eloc;
17741 Source : constant Entity_Id := T.Source;
17742 Target : constant Entity_Id := T.Target;
17748 -- Skip if function marked as warnings off
17750 if Has_Warnings_Off (Act_Unit)
17751 or else Serious_Errors_Detected > 0
17756 -- Don't do the check if warnings off for either type, note the
17757 -- deliberate use of OR here instead of OR ELSE to get the flag
17758 -- Warnings_Off_Used set for both types if appropriate.
17760 if Has_Warnings_Off (Source) or Has_Warnings_Off (Target) then
17764 if (Known_Static_RM_Size (Source)
17765 and then Known_Static_RM_Size (Target))
17766 or else Is_Null_Array (Target)
17768 -- This validation check, which warns if we have unequal sizes
17769 -- for unchecked conversion, and thus implementation dependent
17770 -- semantics, is one of the few occasions on which we use the
17771 -- official RM size instead of Esize. See description in Einfo
17772 -- "Handling of Type'Size Values" for details.
17774 Source_Siz := RM_Size (Source);
17775 Target_Siz := RM_Size (Target);
17777 if Present (Source_Siz) and then Present (Target_Siz)
17778 and then Source_Siz /= Target_Siz
17781 ("?z?types for unchecked conversion have different sizes!",
17784 if All_Errors_Mode then
17785 Error_Msg_Name_1 := Chars (Source);
17786 Error_Msg_Uint_1 := Source_Siz;
17787 Error_Msg_Name_2 := Chars (Target);
17788 Error_Msg_Uint_2 := Target_Siz;
17789 Error_Msg ("\size of % is ^, size of % is ^?z?", Eloc);
17791 Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz);
17793 if Is_Discrete_Type (Source)
17795 Is_Discrete_Type (Target)
17797 if Source_Siz > Target_Siz then
17799 ("\?z?^ high order bits of source will "
17800 & "be ignored!", Eloc);
17802 elsif Is_Unsigned_Type (Source) then
17804 ("\?z?source will be extended with ^ high order "
17805 & "zero bits!", Eloc);
17809 ("\?z?source will be extended with ^ high order "
17810 & "sign bits!", Eloc);
17813 elsif Source_Siz < Target_Siz then
17814 if Is_Discrete_Type (Target) then
17815 if Bytes_Big_Endian then
17817 ("\?z?target value will include ^ undefined "
17818 & "low order bits!", Eloc, Act_Unit);
17821 ("\?z?target value will include ^ undefined "
17822 & "high order bits!", Eloc, Act_Unit);
17827 ("\?z?^ trailing bits of target value will be "
17828 & "undefined!", Eloc, Act_Unit);
17831 else pragma Assert (Source_Siz > Target_Siz);
17832 if Is_Discrete_Type (Source) then
17833 if Bytes_Big_Endian then
17835 ("\?z?^ low order bits of source will be "
17836 & "ignored!", Eloc, Act_Unit);
17839 ("\?z?^ high order bits of source will be "
17840 & "ignored!", Eloc, Act_Unit);
17845 ("\?z?^ trailing bits of source will be "
17846 & "ignored!", Eloc, Act_Unit);
17853 -- If both types are access types, we need to check the alignment.
17854 -- If the alignment of both is specified, we can do it here.
17856 if Serious_Errors_Detected = 0
17857 and then Is_Access_Type (Source)
17858 and then Is_Access_Type (Target)
17859 and then Target_Strict_Alignment
17860 and then Present (Designated_Type (Source))
17861 and then Present (Designated_Type (Target))
17864 D_Source : constant Entity_Id := Designated_Type (Source);
17865 D_Target : constant Entity_Id := Designated_Type (Target);
17868 if Known_Alignment (D_Source)
17870 Known_Alignment (D_Target)
17873 Source_Align : constant Uint := Alignment (D_Source);
17874 Target_Align : constant Uint := Alignment (D_Target);
17877 if Source_Align < Target_Align
17878 and then not Is_Tagged_Type (D_Source)
17880 -- Suppress warning if warnings suppressed on either
17881 -- type or either designated type. Note the use of
17882 -- OR here instead of OR ELSE. That is intentional,
17883 -- we would like to set flag Warnings_Off_Used in
17884 -- all types for which warnings are suppressed.
17886 and then not (Has_Warnings_Off (D_Source)
17888 Has_Warnings_Off (D_Target)
17890 Has_Warnings_Off (Source)
17892 Has_Warnings_Off (Target))
17894 Error_Msg_Uint_1 := Target_Align;
17895 Error_Msg_Uint_2 := Source_Align;
17896 Error_Msg_Node_1 := D_Target;
17897 Error_Msg_Node_2 := D_Source;
17899 ("?z?alignment of & (^) is stricter than "
17900 & "alignment of & (^)!", Eloc, Act_Unit);
17902 ("\?z?resulting access value may have invalid "
17903 & "alignment!", Eloc, Act_Unit);
17914 end Validate_Unchecked_Conversions;