1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2023, 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 Accessibility
; use Accessibility
;
27 with Aspects
; use Aspects
;
28 with Atree
; use Atree
;
29 with Checks
; use Checks
;
30 with Contracts
; use Contracts
;
31 with Debug
; use Debug
;
32 with Einfo
; use Einfo
;
33 with Einfo
.Entities
; use Einfo
.Entities
;
34 with Einfo
.Utils
; use Einfo
.Utils
;
35 with Elists
; use Elists
;
36 with Errout
; use Errout
;
37 with Exp_Ch3
; use Exp_Ch3
;
38 with Exp_Disp
; use Exp_Disp
;
39 with Exp_Tss
; use Exp_Tss
;
40 with Exp_Util
; use Exp_Util
;
41 with Expander
; use Expander
;
42 with Freeze
; use Freeze
;
43 with Ghost
; use Ghost
;
45 with Lib
.Xref
; use Lib
.Xref
;
46 with Namet
; use Namet
;
47 with Nlists
; use Nlists
;
48 with Nmake
; use Nmake
;
50 with Par_SCO
; use Par_SCO
;
51 with Restrict
; use Restrict
;
52 with Rident
; use Rident
;
53 with Rtsfind
; use Rtsfind
;
55 with Sem_Aux
; use Sem_Aux
;
56 with Sem_Case
; use Sem_Case
;
57 with Sem_Cat
; use Sem_Cat
;
58 with Sem_Ch3
; use Sem_Ch3
;
59 with Sem_Ch6
; use Sem_Ch6
;
60 with Sem_Ch7
; use Sem_Ch7
;
61 with Sem_Ch8
; use Sem_Ch8
;
62 with Sem_Dim
; use Sem_Dim
;
63 with Sem_Eval
; use Sem_Eval
;
64 with Sem_Prag
; use Sem_Prag
;
65 with Sem_Res
; use Sem_Res
;
66 with Sem_Type
; use Sem_Type
;
67 with Sem_Util
; use Sem_Util
;
68 with Sem_Warn
; use Sem_Warn
;
69 with Sinfo
; use Sinfo
;
70 with Sinfo
.Nodes
; use Sinfo
.Nodes
;
71 with Sinfo
.Utils
; use Sinfo
.Utils
;
72 with Sinput
; use Sinput
;
73 with Snames
; use Snames
;
74 with Stand
; use Stand
;
75 with System
.Case_Util
; use System
.Case_Util
;
77 with Targparm
; use Targparm
;
78 with Ttypes
; use Ttypes
;
79 with Tbuild
; use Tbuild
;
80 with Urealp
; use Urealp
;
81 with Warnsw
; use Warnsw
;
83 with GNAT
.Heap_Sort_G
;
85 package body Sem_Ch13
is
87 SSU
: constant Pos
:= System_Storage_Unit
;
88 -- Convenient short hand for commonly used constant
90 -----------------------
91 -- Local Subprograms --
92 -----------------------
94 procedure Adjust_Record_For_Reverse_Bit_Order_Ada_95
(R
: Entity_Id
);
95 -- Helper routine providing the original (pre-AI95-0133) behavior for
96 -- Adjust_Record_For_Reverse_Bit_Order.
98 procedure Alignment_Check_For_Size_Change
(Typ
: Entity_Id
; Size
: Uint
);
99 -- This routine is called after setting one of the sizes of type entity
100 -- Typ to Size. The purpose is to deal with the situation of a derived
101 -- type whose inherited alignment is no longer appropriate for the new
102 -- size value. In this case, we reset the Alignment to unknown.
104 function All_Static_Choices
(L
: List_Id
) return Boolean;
105 -- Returns true if all elements of the list are OK static choices
106 -- as defined below for Is_Static_Choice. Used for case expression
107 -- alternatives and for the right operand of a membership test. An
108 -- others_choice is static if the corresponding expression is static.
109 -- The staticness of the bounds is checked separately.
111 procedure Build_Discrete_Static_Predicate
115 -- Given a predicated type Typ, where Typ is a discrete static subtype,
116 -- whose predicate expression is Expr, tests if Expr is a static predicate,
117 -- and if so, builds the predicate range list. Nam is the name of the one
118 -- argument to the predicate function. Occurrences of the type name in the
119 -- predicate expression have been replaced by identifier references to this
120 -- name, which is unique, so any identifier with Chars matching Nam must be
121 -- a reference to the type. If the predicate is non-static, this procedure
122 -- returns doing nothing. If the predicate is static, then the predicate
123 -- list is stored in Static_Discrete_Predicate (Typ), and the Expr is
124 -- rewritten as a canonicalized membership operation.
126 function Build_Export_Import_Pragma
128 Id
: Entity_Id
) return Node_Id
;
129 -- Create the corresponding pragma for aspect Export or Import denoted by
130 -- Asp. Id is the related entity subject to the aspect. Return Empty when
131 -- the expression of aspect Asp evaluates to False or is erroneous.
133 function Build_Predicate_Function_Declaration
134 (Typ
: Entity_Id
) return Node_Id
;
135 -- Build the declaration for a predicate function. The declaration is built
136 -- at the same time as the body but inserted before, as explained below.
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 No
(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 No
(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
1413 -- Exceptional_Cases
1416 -- Initial_Condition
1424 -- Subprogram_Variant
1426 -- Insert pragma Prag such that it mimics the placement of a source
1427 -- pragma of the same kind. Flag Is_Generic should be set when the
1428 -- context denotes a generic instance.
1430 function Relocate_Expression
(Source
: Node_Id
) return Node_Id
;
1431 -- Outside of a generic this function is equivalent to Relocate_Node.
1432 -- Inside a generic it is an identity function, because Relocate_Node
1433 -- would create a new node that is not associated with the generic
1434 -- template. This association is needed to save references to entities
1435 -- that are global to the generic (and might be not visible from where
1436 -- the generic is instantiated).
1438 -- Inside a generic the original tree is shared between aspect and
1439 -- a corresponding pragma (or an attribute definition clause). This
1440 -- parallels what is done in sem_prag.adb (see Get_Argument).
1446 procedure Decorate
(Asp
: Node_Id
; Prag
: Node_Id
) is
1448 Set_Aspect_Rep_Item
(Asp
, Prag
);
1449 Set_Corresponding_Aspect
(Prag
, Asp
);
1450 Set_From_Aspect_Specification
(Prag
);
1451 Set_Parent
(Prag
, Asp
);
1458 procedure Insert_Pragma
1460 Is_Instance
: Boolean := False)
1466 Inserted
: Boolean := False;
1469 -- When the aspect appears on an entry, package, protected unit,
1470 -- subprogram, or task unit body, insert the generated pragma at the
1471 -- top of the body declarations to emulate the behavior of a source
1474 -- package body Pack with Aspect is
1476 -- package body Pack is
1479 if Nkind
(N
) in N_Entry_Body
1485 Decls
:= Declarations
(N
);
1489 Set_Declarations
(N
, Decls
);
1492 Prepend_To
(Decls
, Prag
);
1494 -- When the aspect is associated with a [generic] package declaration
1495 -- insert the generated pragma at the top of the visible declarations
1496 -- to emulate the behavior of a source pragma.
1498 -- package Pack with Aspect is
1503 elsif Nkind
(N
) in N_Generic_Package_Declaration
1504 | N_Package_Declaration
1506 Decls
:= Visible_Declarations
(Specification
(N
));
1510 Set_Visible_Declarations
(Specification
(N
), Decls
);
1513 -- The visible declarations of a generic instance have the
1514 -- following structure:
1516 -- <renamings of generic formals>
1517 -- <renamings of internally-generated spec and body>
1518 -- <first source declaration>
1520 -- Insert the pragma before the first source declaration by
1521 -- skipping the instance "header" to ensure proper visibility of
1525 Decl
:= First
(Decls
);
1526 while Present
(Decl
) loop
1527 if Comes_From_Source
(Decl
) then
1528 Insert_Before
(Decl
, Prag
);
1536 -- The pragma is placed after the instance "header"
1538 if not Inserted
then
1539 Append_To
(Decls
, Prag
);
1542 -- Otherwise this is not a generic instance
1545 Prepend_To
(Decls
, Prag
);
1548 -- When the aspect is associated with a protected unit declaration,
1549 -- insert the generated pragma at the top of the visible declarations
1550 -- the emulate the behavior of a source pragma.
1552 -- protected [type] Prot with Aspect is
1554 -- protected [type] Prot is
1557 elsif Nkind
(N
) = N_Protected_Type_Declaration
then
1558 Def
:= Protected_Definition
(N
);
1562 Make_Protected_Definition
(Sloc
(N
),
1563 Visible_Declarations
=> New_List
,
1564 End_Label
=> Empty
);
1566 Set_Protected_Definition
(N
, Def
);
1569 Decls
:= Visible_Declarations
(Def
);
1573 Set_Visible_Declarations
(Def
, Decls
);
1576 Prepend_To
(Decls
, Prag
);
1578 -- When the aspect is associated with a task unit declaration, insert
1579 -- insert the generated pragma at the top of the visible declarations
1580 -- the emulate the behavior of a source pragma.
1582 -- task [type] Prot with Aspect is
1584 -- task [type] Prot is
1587 elsif Nkind
(N
) = N_Task_Type_Declaration
then
1588 Def
:= Task_Definition
(N
);
1592 Make_Task_Definition
(Sloc
(N
),
1593 Visible_Declarations
=> New_List
,
1594 End_Label
=> Empty
);
1596 Set_Task_Definition
(N
, Def
);
1599 Decls
:= Visible_Declarations
(Def
);
1603 Set_Visible_Declarations
(Def
, Decls
);
1606 Prepend_To
(Decls
, Prag
);
1608 -- When the context is a library unit, the pragma is added to the
1609 -- Pragmas_After list.
1611 elsif Nkind
(Parent
(N
)) = N_Compilation_Unit
then
1612 Aux
:= Aux_Decls_Node
(Parent
(N
));
1614 if No
(Pragmas_After
(Aux
)) then
1615 Set_Pragmas_After
(Aux
, New_List
);
1618 Prepend
(Prag
, Pragmas_After
(Aux
));
1620 -- Default, the pragma is inserted after the context
1623 Insert_After
(N
, Prag
);
1627 -------------------------
1628 -- Relocate_Expression --
1629 -------------------------
1631 function Relocate_Expression
(Source
: Node_Id
) return Node_Id
is
1633 if Inside_A_Generic
then
1636 return Atree
.Relocate_Node
(Source
);
1638 end Relocate_Expression
;
1643 Aitem
: Node_Id
:= Empty
;
1646 L
: constant List_Id
:= Aspect_Specifications
(N
);
1647 pragma Assert
(Present
(L
));
1649 Ins_Node
: Node_Id
:= N
;
1650 -- Insert pragmas/attribute definition clause after this node when no
1651 -- delayed analysis is required.
1653 -- Start of processing for Analyze_Aspect_Specifications
1656 -- The general processing involves building an attribute definition
1657 -- clause or a pragma node that corresponds to the aspect. Then in order
1658 -- to delay the evaluation of this aspect to the freeze point, we attach
1659 -- the corresponding pragma/attribute definition clause to the aspect
1660 -- specification node, which is then placed in the Rep Item chain. In
1661 -- this case we mark the entity by setting the flag Has_Delayed_Aspects
1662 -- and we evaluate the rep item at the freeze point. When the aspect
1663 -- doesn't have a corresponding pragma/attribute definition clause, then
1664 -- its analysis is simply delayed at the freeze point.
1666 -- Some special cases don't require delay analysis, thus the aspect is
1667 -- analyzed right now.
1669 -- Note that there is a special handling for Pre, Post, Test_Case,
1670 -- Contract_Cases, Exceptional_Cases and Subprogram_Variant aspects.
1671 -- In these cases, we do not have to worry about delay issues, since the
1672 -- pragmas themselves deal with delay of visibility for the expression
1673 -- analysis. Thus, we just insert the pragma after the node N.
1675 -- Loop through aspects
1677 Aspect
:= First
(L
);
1678 Aspect_Loop
: while Present
(Aspect
) loop
1679 Analyze_One_Aspect
: declare
1681 Aspect_Exit
: exception;
1682 -- This exception is used to exit aspect processing completely. It
1683 -- is used when an error is detected, and no further processing is
1684 -- required. It is also used if an earlier error has left the tree
1685 -- in a state where the aspect should not be processed.
1687 Expr
: constant Node_Id
:= Expression
(Aspect
);
1688 Id
: constant Node_Id
:= Identifier
(Aspect
);
1689 Loc
: constant Source_Ptr
:= Sloc
(Aspect
);
1690 Nam
: constant Name_Id
:= Chars
(Id
);
1691 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Nam
);
1694 Delay_Required
: Boolean;
1695 -- Set False if delay is not required
1697 Eloc
: Source_Ptr
:= No_Location
;
1698 -- Source location of expression, modified when we split PPC's. It
1699 -- is set below when Expr is present.
1701 procedure Analyze_Aspect_Convention
;
1702 -- Perform analysis of aspect Convention
1704 procedure Analyze_Aspect_Disable_Controlled
;
1705 -- Perform analysis of aspect Disable_Controlled
1707 procedure Analyze_Aspect_Export_Import
;
1708 -- Perform analysis of aspects Export or Import
1710 procedure Analyze_Aspect_External_Link_Name
;
1711 -- Perform analysis of aspects External_Name or Link_Name
1713 procedure Analyze_Aspect_Implicit_Dereference
;
1714 -- Perform analysis of the Implicit_Dereference aspects
1716 procedure Analyze_Aspect_Relaxed_Initialization
;
1717 -- Perform analysis of aspect Relaxed_Initialization
1719 procedure Analyze_Aspect_Yield
;
1720 -- Perform analysis of aspect Yield
1722 procedure Analyze_Aspect_Static
;
1723 -- Ada 2022 (AI12-0075): Perform analysis of aspect Static
1725 procedure Check_Expr_Is_OK_Static_Expression
1727 Typ
: Entity_Id
:= Empty
);
1728 -- Check the specified expression Expr to make sure that it is a
1729 -- static expression of the given type (i.e. it will be analyzed
1730 -- and resolved using this type, which can be any valid argument
1731 -- to Resolve, e.g. Any_Integer is OK). If not, give an error
1732 -- and raise Aspect_Exit. If Typ is left Empty, then any static
1733 -- expression is allowed. Includes checking that the expression
1734 -- does not raise Constraint_Error.
1736 function Directly_Specified
1737 (Id
: Entity_Id
; A
: Aspect_Id
) return Boolean;
1738 -- Returns True if the given aspect is directly (as opposed to
1739 -- via any form of inheritance) specified for the given entity.
1741 function Make_Aitem_Pragma
1742 (Pragma_Argument_Associations
: List_Id
;
1743 Pragma_Name
: Name_Id
) return Node_Id
;
1744 -- This is a wrapper for Make_Pragma used for converting aspects
1745 -- to pragmas. It takes care of Sloc (set from Loc) and building
1746 -- the pragma identifier from the given name. In addition the
1747 -- flags Class_Present and Split_PPC are set from the aspect
1748 -- node, as well as Is_Ignored. This routine also sets the
1749 -- From_Aspect_Specification in the resulting pragma node to
1750 -- True, and sets Corresponding_Aspect to point to the aspect.
1751 -- The resulting pragma is assigned to Aitem.
1753 -------------------------------
1754 -- Analyze_Aspect_Convention --
1755 -------------------------------
1757 procedure Analyze_Aspect_Convention
is
1766 -- Obtain all interfacing aspects that apply to the related
1769 Get_Interfacing_Aspects
1770 (Iface_Asp
=> Aspect
,
1771 Conv_Asp
=> Dummy_1
,
1778 -- The related entity is subject to aspect Export or Import.
1779 -- Do not process Convention now because it must be analysed
1780 -- as part of Export or Import.
1782 if Present
(Expo
) or else Present
(Imp
) then
1785 -- Otherwise Convention appears by itself
1788 -- The aspect specifies a particular convention
1790 if Present
(Expr
) then
1791 Conv
:= New_Copy_Tree
(Expr
);
1793 -- Otherwise assume convention Ada
1796 Conv
:= Make_Identifier
(Loc
, Name_Ada
);
1800 -- pragma Convention (<Conv>, <E>);
1802 Aitem
:= Make_Aitem_Pragma
1803 (Pragma_Name
=> Name_Convention
,
1804 Pragma_Argument_Associations
=> New_List
(
1805 Make_Pragma_Argument_Association
(Loc
,
1806 Expression
=> Conv
),
1807 Make_Pragma_Argument_Association
(Loc
,
1808 Expression
=> New_Occurrence_Of
(E
, Loc
))));
1810 Decorate
(Aspect
, Aitem
);
1811 Insert_Pragma
(Aitem
);
1813 end Analyze_Aspect_Convention
;
1815 ---------------------------------------
1816 -- Analyze_Aspect_Disable_Controlled --
1817 ---------------------------------------
1819 procedure Analyze_Aspect_Disable_Controlled
is
1821 -- The aspect applies only to controlled records
1823 if not (Ekind
(E
) = E_Record_Type
1824 and then Is_Controlled_Active
(E
))
1827 ("aspect % requires controlled record type", Aspect
);
1831 -- Preanalyze the expression (if any) when the aspect resides
1832 -- in a generic unit.
1834 if Inside_A_Generic
then
1835 if Present
(Expr
) then
1836 Preanalyze_And_Resolve
(Expr
, Any_Boolean
);
1839 -- Otherwise the aspect resides in a nongeneric context
1842 -- A controlled record type loses its controlled semantics
1843 -- when the expression statically evaluates to True.
1845 if Present
(Expr
) then
1846 Analyze_And_Resolve
(Expr
, Any_Boolean
);
1848 if Is_OK_Static_Expression
(Expr
) then
1849 if Is_True
(Static_Boolean
(Expr
)) then
1850 Set_Disable_Controlled
(E
);
1853 -- Otherwise the expression is not static
1857 ("expression of aspect % must be static", Aspect
);
1860 -- Otherwise the aspect appears without an expression and
1861 -- defaults to True.
1864 Set_Disable_Controlled
(E
);
1867 end Analyze_Aspect_Disable_Controlled
;
1869 ----------------------------------
1870 -- Analyze_Aspect_Export_Import --
1871 ----------------------------------
1873 procedure Analyze_Aspect_Export_Import
is
1881 -- Obtain all interfacing aspects that apply to the related
1884 Get_Interfacing_Aspects
1885 (Iface_Asp
=> Aspect
,
1886 Conv_Asp
=> Dummy_1
,
1893 -- The related entity cannot be subject to both aspects Export
1896 if Present
(Expo
) and then Present
(Imp
) then
1898 ("incompatible interfacing aspects given for &", E
);
1899 Error_Msg_Sloc
:= Sloc
(Expo
);
1900 Error_Msg_N
("\aspect Export #", E
);
1901 Error_Msg_Sloc
:= Sloc
(Imp
);
1902 Error_Msg_N
("\aspect Import #", E
);
1905 -- A variable is most likely modified from the outside. Take
1906 -- the optimistic approach to avoid spurious errors.
1908 if Ekind
(E
) = E_Variable
then
1909 Set_Never_Set_In_Source
(E
, False);
1912 -- Resolve the expression of an Import or Export here, and
1913 -- require it to be of type Boolean and static. This is not
1914 -- quite right, because in general this should be delayed,
1915 -- but that seems tricky for these, because normally Boolean
1916 -- aspects are replaced with pragmas at the freeze point in
1917 -- Make_Pragma_From_Boolean_Aspect.
1920 or else Is_True
(Static_Boolean
(Expr
))
1922 if A_Id
= Aspect_Import
then
1923 Set_Has_Completion
(E
);
1924 Set_Is_Imported
(E
);
1926 -- An imported object cannot be explicitly initialized
1928 if Nkind
(N
) = N_Object_Declaration
1929 and then Present
(Expression
(N
))
1932 ("imported entities cannot be initialized "
1933 & "(RM B.1(24))", Expression
(N
));
1937 pragma Assert
(A_Id
= Aspect_Export
);
1938 Set_Is_Exported
(E
);
1941 -- Create the proper form of pragma Export or Import taking
1942 -- into account Conversion, External_Name, and Link_Name.
1944 Aitem
:= Build_Export_Import_Pragma
(Aspect
, E
);
1946 -- Otherwise the expression is either False or erroneous. There
1947 -- is no corresponding pragma.
1952 end Analyze_Aspect_Export_Import
;
1954 ---------------------------------------
1955 -- Analyze_Aspect_External_Link_Name --
1956 ---------------------------------------
1958 procedure Analyze_Aspect_External_Link_Name
is
1966 -- Obtain all interfacing aspects that apply to the related
1969 Get_Interfacing_Aspects
1970 (Iface_Asp
=> Aspect
,
1971 Conv_Asp
=> Dummy_1
,
1978 -- Ensure that aspect External_Name applies to aspect Export or
1981 if A_Id
= Aspect_External_Name
then
1982 if No
(Expo
) and then No
(Imp
) then
1984 ("aspect External_Name requires aspect Import or "
1985 & "Export", Aspect
);
1988 -- Otherwise ensure that aspect Link_Name applies to aspect
1989 -- Export or Import.
1992 pragma Assert
(A_Id
= Aspect_Link_Name
);
1993 if No
(Expo
) and then No
(Imp
) then
1995 ("aspect Link_Name requires aspect Import or Export",
1999 end Analyze_Aspect_External_Link_Name
;
2001 -----------------------------------------
2002 -- Analyze_Aspect_Implicit_Dereference --
2003 -----------------------------------------
2005 procedure Analyze_Aspect_Implicit_Dereference
is
2007 if not Is_Type
(E
) or else not Has_Discriminants
(E
) then
2009 ("aspect must apply to a type with discriminants", Expr
);
2011 elsif not Is_Entity_Name
(Expr
) then
2013 ("aspect must name a discriminant of current type", Expr
);
2016 -- Discriminant type be an anonymous access type or an
2017 -- anonymous access to subprogram.
2019 -- Missing synchronized types???
2022 Disc
: Entity_Id
:= First_Discriminant
(E
);
2024 while Present
(Disc
) loop
2025 if Chars
(Expr
) = Chars
(Disc
)
2026 and then Ekind
(Etype
(Disc
)) in
2027 E_Anonymous_Access_Subprogram_Type |
2028 E_Anonymous_Access_Type
2030 Set_Has_Implicit_Dereference
(E
);
2031 Set_Has_Implicit_Dereference
(Disc
);
2035 Next_Discriminant
(Disc
);
2038 -- Error if no proper access discriminant
2040 if Present
(Disc
) then
2041 -- For a type extension, check whether parent has
2042 -- a reference discriminant, to verify that use is
2045 if Is_Derived_Type
(E
)
2046 and then Has_Discriminants
(Etype
(E
))
2049 Parent_Disc
: constant Entity_Id
:=
2050 Get_Reference_Discriminant
(Etype
(E
));
2052 if Present
(Parent_Disc
)
2053 and then Corresponding_Discriminant
(Disc
) /=
2057 ("reference discriminant does not match "
2058 & "discriminant of parent type", Expr
);
2065 ("not an access discriminant of&", Expr
, E
);
2070 end Analyze_Aspect_Implicit_Dereference
;
2072 -------------------------------------------
2073 -- Analyze_Aspect_Relaxed_Initialization --
2074 -------------------------------------------
2076 procedure Analyze_Aspect_Relaxed_Initialization
is
2077 procedure Analyze_Relaxed_Parameter
2078 (Subp_Id
: Entity_Id
;
2080 Seen
: in out Elist_Id
);
2081 -- Analyze parameter that appears in the expression of the
2082 -- aspect Relaxed_Initialization.
2084 -------------------------------
2085 -- Analyze_Relaxed_Parameter --
2086 -------------------------------
2088 procedure Analyze_Relaxed_Parameter
2089 (Subp_Id
: Entity_Id
;
2091 Seen
: in out Elist_Id
)
2094 -- Set name of the aspect for error messages
2095 Error_Msg_Name_1
:= Nam
;
2097 -- The relaxed parameter is a formal parameter
2099 if Nkind
(Param
) in N_Identifier | N_Expanded_Name
then
2103 Item
: constant Entity_Id
:= Entity
(Param
);
2105 -- It must be a formal of the analyzed subprogram
2107 if Scope
(Item
) = Subp_Id
then
2109 pragma Assert
(Is_Formal
(Item
));
2111 -- It must not have scalar or access type
2113 if Is_Elementary_Type
(Etype
(Item
)) then
2114 Error_Msg_N
("illegal aspect % item", Param
);
2116 ("\item must not have elementary type", Param
);
2119 -- Detect duplicated items
2121 if Contains
(Seen
, Item
) then
2122 Error_Msg_N
("duplicate aspect % item", Param
);
2124 Append_New_Elmt
(Item
, Seen
);
2127 Error_Msg_N
("illegal aspect % item", Param
);
2131 -- The relaxed parameter is the function's Result attribute
2133 elsif Is_Attribute_Result
(Param
) then
2137 Pref
: constant Node_Id
:= Prefix
(Param
);
2141 Nkind
(Pref
) in N_Identifier | N_Expanded_Name
2143 Entity
(Pref
) = Subp_Id
2145 -- Function result must not have scalar or access
2148 if Is_Elementary_Type
(Etype
(Pref
)) then
2149 Error_Msg_N
("illegal aspect % item", Param
);
2151 ("\function result must not have elementary"
2155 -- Detect duplicated items
2157 if Contains
(Seen
, Subp_Id
) then
2158 Error_Msg_N
("duplicate aspect % item", Param
);
2160 Append_New_Elmt
(Entity
(Pref
), Seen
);
2164 Error_Msg_N
("illegal aspect % item", Param
);
2168 Error_Msg_N
("illegal aspect % item", Param
);
2170 end Analyze_Relaxed_Parameter
;
2174 Seen
: Elist_Id
:= No_Elist
;
2175 -- Items that appear in the relaxed initialization aspect
2176 -- expression of a subprogram; for detecting duplicates.
2178 Restore_Scope
: Boolean;
2179 -- Will be set to True if we need to restore the scope table
2180 -- after analyzing the aspect expression.
2182 Prev_Id
: Entity_Id
;
2184 -- Start of processing for Analyze_Aspect_Relaxed_Initialization
2187 -- Set name of the aspect for error messages
2188 Error_Msg_Name_1
:= Nam
;
2190 -- Annotation of a type; no aspect expression is allowed.
2191 -- For a private type, the aspect must be attached to the
2194 -- ??? Once the exact rule for this aspect is ready, we will
2195 -- likely reject concurrent types, etc., so let's keep the code
2196 -- for types and variable separate.
2198 if Is_First_Subtype
(E
) then
2199 Prev_Id
:= Incomplete_Or_Partial_View
(E
);
2200 if Present
(Prev_Id
) then
2202 -- Aspect may appear on the full view of an incomplete
2203 -- type because the incomplete declaration cannot have
2206 if Ekind
(Prev_Id
) = E_Incomplete_Type
then
2209 Error_Msg_N
("aspect % must apply to partial view", N
);
2212 elsif Present
(Expr
) then
2213 Error_Msg_N
("illegal aspect % expression", Expr
);
2216 -- Annotation of a variable; no aspect expression is allowed
2218 elsif Ekind
(E
) = E_Variable
then
2219 if Present
(Expr
) then
2220 Error_Msg_N
("illegal aspect % expression", Expr
);
2223 -- Annotation of a constant; no aspect expression is allowed.
2224 -- For a deferred constant, the aspect must be attached to the
2227 elsif Ekind
(E
) = E_Constant
then
2228 if Present
(Incomplete_Or_Partial_View
(E
)) then
2230 ("aspect % must apply to deferred constant", N
);
2232 elsif Present
(Expr
) then
2233 Error_Msg_N
("illegal aspect % expression", Expr
);
2236 -- Annotation of a subprogram; aspect expression is required
2238 elsif Is_Subprogram_Or_Entry
(E
)
2239 or else Is_Generic_Subprogram
(E
)
2241 if Present
(Expr
) then
2243 -- If we analyze subprogram body that acts as its own
2244 -- spec, then the subprogram itself and its formals are
2245 -- already installed; otherwise, we need to install them,
2246 -- as they must be visible when analyzing the aspect
2249 if In_Open_Scopes
(E
) then
2250 Restore_Scope
:= False;
2252 Restore_Scope
:= True;
2255 -- Only formals of the subprogram itself can appear
2256 -- in Relaxed_Initialization aspect expression, not
2257 -- formals of the enclosing generic unit. (This is
2258 -- different than in Precondition or Depends aspects,
2259 -- where both kinds of formals are allowed.)
2261 Install_Formals
(E
);
2264 -- Aspect expression is either an aggregate with list of
2265 -- parameters (and possibly the Result attribute for a
2268 if Nkind
(Expr
) = N_Aggregate
then
2270 -- Component associations in the aggregate must be a
2271 -- parameter name followed by a static boolean
2274 if Present
(Component_Associations
(Expr
)) then
2277 First
(Component_Associations
(Expr
));
2279 while Present
(Assoc
) loop
2280 if List_Length
(Choices
(Assoc
)) = 1 then
2281 Analyze_Relaxed_Parameter
2282 (E
, First
(Choices
(Assoc
)), Seen
);
2284 if Inside_A_Generic
then
2285 Preanalyze_And_Resolve
2286 (Expression
(Assoc
), Any_Boolean
);
2289 (Expression
(Assoc
), Any_Boolean
);
2292 if not Is_OK_Static_Expression
2293 (Expression
(Assoc
))
2295 Error_Msg_Name_1
:= Nam
;
2297 ("expression of aspect % " &
2298 "must be static", Aspect
);
2302 Error_Msg_Name_1
:= Nam
;
2304 ("illegal aspect % expression", Expr
);
2311 -- Expressions of the aggregate are parameter names
2313 if Present
(Expressions
(Expr
)) then
2315 Param
: Node_Id
:= First
(Expressions
(Expr
));
2318 while Present
(Param
) loop
2319 Analyze_Relaxed_Parameter
(E
, Param
, Seen
);
2325 -- Mark the aggregate expression itself as analyzed;
2326 -- its subexpressions were marked when they themselves
2329 Set_Analyzed
(Expr
);
2331 -- Otherwise, it is a single name of a subprogram
2332 -- parameter (or possibly the Result attribute for
2336 Analyze_Relaxed_Parameter
(E
, Expr
, Seen
);
2339 if Restore_Scope
then
2343 Error_Msg_N
("missing expression for aspect %", N
);
2347 Error_Msg_N
("inappropriate entity for aspect %", E
);
2349 end Analyze_Aspect_Relaxed_Initialization
;
2351 ---------------------------
2352 -- Analyze_Aspect_Static --
2353 ---------------------------
2355 procedure Analyze_Aspect_Static
is
2356 function Has_Convention_Intrinsic
(L
: List_Id
) return Boolean;
2357 -- Return True if L contains a pragma argument association
2358 -- node representing a convention Intrinsic.
2360 ------------------------------
2361 -- Has_Convention_Intrinsic --
2362 ------------------------------
2364 function Has_Convention_Intrinsic
2365 (L
: List_Id
) return Boolean
2367 Arg
: Node_Id
:= First
(L
);
2369 while Present
(Arg
) loop
2370 if Nkind
(Arg
) = N_Pragma_Argument_Association
2371 and then Chars
(Arg
) = Name_Convention
2372 and then Chars
(Expression
(Arg
)) = Name_Intrinsic
2381 end Has_Convention_Intrinsic
;
2383 Is_Imported_Intrinsic
: Boolean;
2386 if Ada_Version
< Ada_2022
then
2387 Error_Msg_Ada_2022_Feature
("aspect %", Sloc
(Aspect
));
2391 Is_Imported_Intrinsic
:= Is_Imported
(E
)
2393 Has_Convention_Intrinsic
2394 (Pragma_Argument_Associations
(Import_Pragma
(E
)));
2396 -- The aspect applies only to expression functions that
2397 -- statisfy the requirements for a static expression function
2398 -- (such as having an expression that is predicate-static) as
2399 -- well as Intrinsic imported functions as a -gnatX extension.
2401 if not Is_Expression_Function
(E
)
2403 not (All_Extensions_Allowed
and then Is_Imported_Intrinsic
)
2405 if All_Extensions_Allowed
then
2407 ("aspect % requires intrinsic or expression function",
2410 elsif Is_Imported_Intrinsic
then
2411 Error_Msg_GNAT_Extension
2412 ("aspect % on intrinsic function", Sloc
(Aspect
),
2413 Is_Core_Extension
=> True);
2417 ("aspect % requires expression function", Aspect
);
2422 -- Ada 2022 (AI12-0075): Check that the function satisfies
2423 -- several requirements of static functions as specified in
2424 -- RM 6.8(5.1-5.8). Note that some of the requirements given
2425 -- there are checked elsewhere.
2428 -- The expression of the expression function must be a
2429 -- potentially static expression (RM 2022 6.8(3.2-3.4)).
2430 -- That's checked in Sem_Ch6.Analyze_Expression_Function.
2432 -- The function must not contain any calls to itself, which
2433 -- is checked in Sem_Res.Resolve_Call.
2435 -- Each formal must be of mode in and have a static subtype
2438 Formal
: Entity_Id
:= First_Formal
(E
);
2440 while Present
(Formal
) loop
2441 if Ekind
(Formal
) /= E_In_Parameter
then
2443 ("aspect % requires formals of mode IN",
2449 if not Is_Static_Subtype
(Etype
(Formal
)) then
2451 ("aspect % requires formals with static subtypes",
2457 Next_Formal
(Formal
);
2461 -- The function's result subtype must be a static subtype
2463 if not Is_Static_Subtype
(Etype
(E
)) then
2465 ("aspect % requires function with result of "
2466 & "a static subtype",
2472 -- Check that the function does not have any applicable
2473 -- precondition or postcondition expression.
2475 for Asp
in Pre_Post_Aspects
loop
2476 if Has_Aspect
(E
, Asp
) then
2477 Error_Msg_Name_1
:= Aspect_Names
(Asp
);
2479 ("aspect % is not allowed for a static "
2480 & "expression function",
2481 Find_Aspect
(E
, Asp
));
2487 -- ??? Must check that "for result type R, if the
2488 -- function is a boundary entity for type R (see 7.3.2),
2489 -- no type invariant applies to type R; if R has a
2490 -- component type C, a similar rule applies to C."
2493 -- When the expression is present, it must be static. If it
2494 -- evaluates to True, the expression function is treated as
2495 -- a static function. Otherwise the aspect appears without
2496 -- an expression and defaults to True.
2498 if Present
(Expr
) then
2499 -- Preanalyze the expression when the aspect resides in a
2500 -- generic unit. (Is this generic-related code necessary
2501 -- for this aspect? It's modeled on what's done for aspect
2502 -- Disable_Controlled. ???)
2504 if Inside_A_Generic
then
2505 Preanalyze_And_Resolve
(Expr
, Any_Boolean
);
2507 -- Otherwise the aspect resides in a nongeneric context
2510 Analyze_And_Resolve
(Expr
, Any_Boolean
);
2512 -- Error if the boolean expression is not static
2514 if not Is_OK_Static_Expression
(Expr
) then
2516 ("expression of aspect % must be static", Aspect
);
2520 end Analyze_Aspect_Static
;
2522 --------------------------
2523 -- Analyze_Aspect_Yield --
2524 --------------------------
2526 procedure Analyze_Aspect_Yield
is
2527 Expr_Value
: Boolean := False;
2530 -- Check valid entity for 'Yield
2532 if (Is_Subprogram
(E
)
2533 or else Is_Generic_Subprogram
(E
)
2534 or else Is_Entry
(E
))
2535 and then not Within_Protected_Type
(E
)
2539 elsif Within_Protected_Type
(E
) then
2541 ("aspect% not applicable to protected operation", Id
);
2546 ("aspect% only applicable to subprogram and entry "
2547 & "declarations", Id
);
2551 -- Evaluate its static expression (if available); otherwise it
2552 -- defaults to True.
2557 -- Otherwise it must have a static boolean expression
2560 if Inside_A_Generic
then
2561 Preanalyze_And_Resolve
(Expr
, Any_Boolean
);
2563 Analyze_And_Resolve
(Expr
, Any_Boolean
);
2566 if Is_OK_Static_Expression
(Expr
) then
2567 if Is_True
(Static_Boolean
(Expr
)) then
2572 ("expression of aspect % must be static", Aspect
);
2577 Set_Has_Yield_Aspect
(E
);
2580 -- If the Yield aspect is specified for a dispatching
2581 -- subprogram that inherits the aspect, the specified
2582 -- value shall be confirming.
2585 and then Is_Dispatching_Operation
(E
)
2586 and then Present
(Overridden_Operation
(E
))
2587 and then Has_Yield_Aspect
(Overridden_Operation
(E
))
2588 /= Is_True
(Static_Boolean
(Expr
))
2590 Error_Msg_N
("specification of inherited aspect% can only " &
2591 "confirm parent value", Id
);
2593 end Analyze_Aspect_Yield
;
2595 ----------------------------------------
2596 -- Check_Expr_Is_OK_Static_Expression --
2597 ----------------------------------------
2599 procedure Check_Expr_Is_OK_Static_Expression
2601 Typ
: Entity_Id
:= Empty
)
2604 if Present
(Typ
) then
2605 Analyze_And_Resolve
(Expr
, Typ
);
2607 Analyze_And_Resolve
(Expr
);
2610 -- An expression cannot be considered static if its resolution
2611 -- failed or if it's erroneous. Stop the analysis of the
2614 if Etype
(Expr
) = Any_Type
or else Error_Posted
(Expr
) then
2617 elsif Is_OK_Static_Expression
(Expr
) then
2620 -- Finally, we have a real error
2623 Error_Msg_Name_1
:= Nam
;
2624 Flag_Non_Static_Expr
2625 ("entity for aspect% must be a static expression",
2629 end Check_Expr_Is_OK_Static_Expression
;
2631 ------------------------
2632 -- Directly_Specified --
2633 ------------------------
2635 function Directly_Specified
2636 (Id
: Entity_Id
; A
: Aspect_Id
) return Boolean
2638 Aspect_Spec
: constant Node_Id
:= Find_Aspect
(Id
, A
);
2640 return Present
(Aspect_Spec
) and then Entity
(Aspect_Spec
) = Id
;
2641 end Directly_Specified
;
2643 -----------------------
2644 -- Make_Aitem_Pragma --
2645 -----------------------
2647 function Make_Aitem_Pragma
2648 (Pragma_Argument_Associations
: List_Id
;
2649 Pragma_Name
: Name_Id
) return Node_Id
2651 Args
: List_Id
:= Pragma_Argument_Associations
;
2655 -- We should never get here if aspect was disabled
2657 pragma Assert
(not Is_Disabled
(Aspect
));
2659 -- Certain aspects allow for an optional name or expression. Do
2660 -- not generate a pragma with empty argument association list.
2662 if No
(Args
) or else No
(Expression
(First
(Args
))) then
2670 Pragma_Argument_Associations
=> Args
,
2671 Pragma_Identifier
=>
2672 Make_Identifier
(Sloc
(Id
), Pragma_Name
),
2673 Class_Present
=> Class_Present
(Aspect
),
2674 Split_PPC
=> Split_PPC
(Aspect
));
2676 -- Set additional semantic fields
2678 if Is_Ignored
(Aspect
) then
2679 Set_Is_Ignored
(Aitem
);
2680 elsif Is_Checked
(Aspect
) then
2681 Set_Is_Checked
(Aitem
);
2684 Set_Corresponding_Aspect
(Aitem
, Aspect
);
2685 Set_From_Aspect_Specification
(Aitem
);
2688 end Make_Aitem_Pragma
;
2690 -- Start of processing for Analyze_One_Aspect
2693 -- Skip aspect if already analyzed, to avoid looping in some cases
2695 if Analyzed
(Aspect
) then
2699 -- Skip looking at aspect if it is totally disabled. Just mark it
2700 -- as such for later reference in the tree. This also sets the
2701 -- Is_Ignored and Is_Checked flags appropriately.
2703 Check_Applicable_Policy
(Aspect
);
2705 if Is_Disabled
(Aspect
) then
2709 -- Set the source location of expression, used in the case of
2710 -- a failed precondition/postcondition or invariant. Note that
2711 -- the source location of the expression is not usually the best
2712 -- choice here. For example, it gets located on the last AND
2713 -- keyword in a chain of boolean expressiond AND'ed together.
2714 -- It is best to put the message on the first character of the
2715 -- assertion, which is the effect of the First_Node call here.
2717 if Present
(Expr
) then
2718 Eloc
:= Sloc
(First_Node
(Expr
));
2721 -- Check restriction No_Implementation_Aspect_Specifications
2723 if Implementation_Defined_Aspect
(A_Id
) then
2725 (No_Implementation_Aspect_Specifications
, Aspect
);
2728 -- Check restriction No_Specification_Of_Aspect
2730 Check_Restriction_No_Specification_Of_Aspect
(Aspect
);
2732 -- Mark aspect analyzed (actual analysis is delayed till later)
2734 Set_Analyzed
(Aspect
);
2735 Set_Entity
(Aspect
, E
);
2737 -- Build the reference to E that will be used in the built pragmas
2739 Ent
:= New_Occurrence_Of
(E
, Sloc
(Id
));
2741 if A_Id
in Aspect_Attach_Handler | Aspect_Interrupt_Handler
then
2743 -- Treat the specification as a reference to the protected
2744 -- operation, which might otherwise appear unreferenced and
2745 -- generate spurious warnings.
2747 Generate_Reference
(E
, Id
);
2750 -- Check for duplicate aspect. Note that the Comes_From_Source
2751 -- test allows duplicate Pre/Post's that we generate internally
2752 -- to escape being flagged here.
2754 if No_Duplicates_Allowed
(A_Id
) then
2756 while Anod
/= Aspect
loop
2757 if Comes_From_Source
(Aspect
)
2758 and then Same_Aspect
(A_Id
, Get_Aspect_Id
(Anod
))
2760 Error_Msg_Name_1
:= Nam
;
2761 Error_Msg_Sloc
:= Sloc
(Anod
);
2763 -- Case of same aspect specified twice
2765 if Class_Present
(Anod
) = Class_Present
(Aspect
) then
2766 if not Class_Present
(Anod
) then
2768 ("aspect% for & previously given#",
2772 ("aspect `%''Class` for & previously given#",
2782 -- Check some general restrictions on language defined aspects
2784 if not Implementation_Defined_Aspect
(A_Id
)
2785 or else A_Id
in Aspect_Async_Readers
2786 | Aspect_Async_Writers
2787 | Aspect_Effective_Reads
2788 | Aspect_Effective_Writes
2789 | Aspect_Preelaborable_Initialization
2791 Error_Msg_Name_1
:= Nam
;
2793 -- Not allowed for renaming declarations. Examine the original
2794 -- node because a subprogram renaming may have been rewritten
2797 if Nkind
(Original_Node
(N
)) in N_Renaming_Declaration
then
2799 ("aspect % not allowed for renaming declaration",
2803 -- Not allowed for formal type declarations in previous
2804 -- versions of the language. Allowed for them only for
2805 -- shared variable control aspects.
2807 -- Original node is used in case expansion rewrote the node -
2808 -- as is the case with generic derived types.
2810 if Nkind
(Original_Node
(N
)) = N_Formal_Type_Declaration
then
2811 if Ada_Version
< Ada_2022
then
2813 ("aspect % not allowed for formal type declaration",
2816 elsif A_Id
not in Aspect_Atomic
2818 | Aspect_Independent
2819 | Aspect_Atomic_Components
2820 | Aspect_Independent_Components
2821 | Aspect_Volatile_Components
2822 | Aspect_Async_Readers
2823 | Aspect_Async_Writers
2824 | Aspect_Effective_Reads
2825 | Aspect_Effective_Writes
2826 | Aspect_Preelaborable_Initialization
2829 ("aspect % not allowed for formal type declaration",
2835 -- Copy expression for later processing by the procedures
2836 -- Check_Aspect_At_[Freeze_Point | End_Of_Declarations]
2838 -- The expression may be a subprogram name, and can
2839 -- be an operator name that appears as a string, but
2840 -- requires its own analysis procedure (see sem_ch6).
2842 if Nkind
(Expr
) = N_Operator_Symbol
then
2843 Set_Entity
(Id
, Expr
);
2845 Set_Entity
(Id
, New_Copy_Tree
(Expr
));
2848 -- Set Delay_Required as appropriate to aspect
2850 case Aspect_Delay
(A_Id
) is
2851 when Always_Delay
=>
2852 -- For Boolean aspects, do not delay if no expression
2854 if A_Id
in Boolean_Aspects | Library_Unit_Aspects
then
2855 Delay_Required
:= Present
(Expr
);
2857 Delay_Required
:= True;
2861 Delay_Required
:= False;
2865 -- For Boolean aspects, do not delay if no expression except
2866 -- for Full_Access_Only because we need to process it after
2867 -- Volatile and Atomic, which can be independently delayed.
2869 if A_Id
in Boolean_Aspects
2870 and then A_Id
/= Aspect_Full_Access_Only
2873 Delay_Required
:= False;
2875 -- For non-Boolean aspects, if the expression has the form
2876 -- of an integer literal, then do not delay, since we know
2877 -- the value cannot change. This optimization catches most
2878 -- rep clause cases.
2880 elsif A_Id
not in Boolean_Aspects
2881 and then Present
(Expr
)
2882 and then Nkind
(Expr
) = N_Integer_Literal
2884 Delay_Required
:= False;
2886 -- For Alignment and various Size aspects, do not delay for
2887 -- an attribute reference whose prefix is Standard, for
2888 -- example Standard'Maximum_Alignment or Standard'Word_Size.
2890 elsif A_Id
in Aspect_Alignment
2891 | Aspect_Component_Size
2892 | Aspect_Object_Size
2895 and then Present
(Expr
)
2896 and then Nkind
(Expr
) = N_Attribute_Reference
2897 and then Nkind
(Prefix
(Expr
)) = N_Identifier
2898 and then Chars
(Prefix
(Expr
)) = Name_Standard
2900 Delay_Required
:= False;
2902 -- All other cases are delayed
2905 Delay_Required
:= True;
2906 Set_Has_Delayed_Rep_Aspects
(E
);
2911 and then (A_Id
= Aspect_Stable_Properties
2912 or else A_Id
= Aspect_Designated_Storage_Model
2913 or else A_Id
= Aspect_Storage_Model_Type
2914 or else A_Id
= Aspect_Aggregate
)
2915 -- ??? It seems like we should do this for all aspects, not
2916 -- just these, but that causes as-yet-undiagnosed regressions.
2919 Set_Has_Delayed_Aspects
(E
);
2920 Set_Is_Delayed_Aspect
(Aspect
);
2923 -- Check 13.1(9.2/5): A representation aspect of a subtype or type
2924 -- shall not be specified (whether by a representation item or an
2925 -- aspect_specification) before the type is completely defined
2928 if Is_Representation_Aspect
(A_Id
)
2929 and then Rep_Item_Too_Early
(E
, N
)
2934 -- Processing based on specific aspect
2937 when Aspect_Unimplemented
=>
2938 null; -- ??? temp for now
2940 -- No_Aspect should be impossible
2943 raise Program_Error
;
2945 -- Case 1: Aspects corresponding to attribute definition
2951 | Aspect_Component_Size
2952 | Aspect_Constant_Indexing
2953 | Aspect_Default_Iterator
2954 | Aspect_Dispatching_Domain
2955 | Aspect_External_Tag
2958 | Aspect_Iterator_Element
2959 | Aspect_Machine_Radix
2960 | Aspect_Object_Size
2964 | Aspect_Scalar_Storage_Order
2965 | Aspect_Simple_Storage_Pool
2968 | Aspect_Storage_Pool
2969 | Aspect_Stream_Size
2971 | Aspect_Variable_Indexing
2974 -- Indexing aspects apply only to tagged type
2976 if A_Id
in Aspect_Constant_Indexing
2977 | Aspect_Variable_Indexing
2978 and then not (Is_Type
(E
)
2979 and then Is_Tagged_Type
(E
))
2982 ("indexing aspect can only apply to a tagged type",
2987 -- For the case of aspect Address, we don't consider that we
2988 -- know the entity is never set in the source, since it is
2989 -- is likely aliasing is occurring.
2991 -- Note: one might think that the analysis of the resulting
2992 -- attribute definition clause would take care of that, but
2993 -- that's not the case since it won't be from source.
2995 if A_Id
= Aspect_Address
then
2996 Set_Never_Set_In_Source
(E
, False);
2999 -- Correctness of the profile of a stream operation is
3000 -- verified at the freeze point, but we must detect the
3001 -- illegal specification of this aspect for a subtype now,
3002 -- to prevent malformed rep_item chains.
3004 if A_Id
in Aspect_Input
3009 if not Is_First_Subtype
(E
) then
3011 ("local name must be a first subtype", Aspect
);
3014 -- If stream aspect applies to the class-wide type,
3015 -- the generated attribute definition applies to the
3016 -- class-wide type as well.
3018 elsif Class_Present
(Aspect
) then
3020 Make_Attribute_Reference
(Loc
,
3022 Attribute_Name
=> Name_Class
);
3026 -- Construct the attribute_definition_clause. The expression
3027 -- in the aspect specification is simply shared with the
3028 -- constructed attribute, because it will be fully analyzed
3029 -- when the attribute is processed.
3032 Make_Attribute_Definition_Clause
(Loc
,
3035 Expression
=> Relocate_Expression
(Expr
));
3037 -- If the address is specified, then we treat the entity as
3038 -- referenced, to avoid spurious warnings. This is analogous
3039 -- to what is done with an attribute definition clause, but
3040 -- here we don't want to generate a reference because this
3041 -- is the point of definition of the entity.
3043 if A_Id
= Aspect_Address
then
3047 -- Case 2: Aspects corresponding to pragmas
3049 -- Case 2a: Aspects corresponding to pragmas with two
3050 -- arguments, where the first argument is a local name
3051 -- referring to the entity, and the second argument is the
3052 -- aspect definition expression.
3056 when Aspect_Linker_Section
=>
3057 Aitem
:= Make_Aitem_Pragma
3058 (Pragma_Argument_Associations
=> New_List
(
3059 Make_Pragma_Argument_Association
(Loc
,
3060 Expression
=> New_Occurrence_Of
(E
, Loc
)),
3061 Make_Pragma_Argument_Association
(Sloc
(Expr
),
3062 Expression
=> Relocate_Node
(Expr
))),
3063 Pragma_Name
=> Name_Linker_Section
);
3065 -- Linker_Section does not need delaying, as its argument
3066 -- must be a static string. Furthermore, if applied to
3067 -- an object with an explicit initialization, the object
3068 -- must be frozen in order to elaborate the initialization
3069 -- code. (This is already done for types with implicit
3070 -- initialization, such as protected types.)
3072 if Nkind
(N
) = N_Object_Declaration
3073 and then Has_Init_Expression
(N
)
3075 Delay_Required
:= False;
3080 -- Corresponds to pragma Implemented, construct the pragma
3082 when Aspect_Synchronization
=>
3083 Aitem
:= Make_Aitem_Pragma
3084 (Pragma_Argument_Associations
=> New_List
(
3085 Make_Pragma_Argument_Association
(Loc
,
3086 Expression
=> New_Occurrence_Of
(E
, Loc
)),
3087 Make_Pragma_Argument_Association
(Sloc
(Expr
),
3088 Expression
=> Relocate_Node
(Expr
))),
3089 Pragma_Name
=> Name_Implemented
);
3093 when Aspect_Attach_Handler
=>
3094 Aitem
:= Make_Aitem_Pragma
3095 (Pragma_Argument_Associations
=> New_List
(
3096 Make_Pragma_Argument_Association
(Sloc
(Ent
),
3098 Make_Pragma_Argument_Association
(Sloc
(Expr
),
3099 Expression
=> Relocate_Expression
(Expr
))),
3100 Pragma_Name
=> Name_Attach_Handler
);
3102 -- We need to insert this pragma into the tree to get proper
3103 -- processing and to look valid from a placement viewpoint.
3105 Insert_Pragma
(Aitem
);
3108 -- Dynamic_Predicate, Predicate, Static_Predicate
3110 when Aspect_Dynamic_Predicate
3112 | Aspect_Static_Predicate
3114 -- These aspects apply only to subtypes
3116 if not Is_Type
(E
) then
3118 ("predicate can only be specified for a subtype",
3122 elsif Is_Incomplete_Type
(E
) then
3124 ("predicate cannot apply to incomplete view", Aspect
);
3126 elsif Is_Generic_Type
(E
) then
3128 ("predicate cannot apply to formal type", Aspect
);
3132 -- Construct the pragma (always a pragma Predicate, with
3133 -- flags recording whether it is static/dynamic). We also
3134 -- set flags recording this in the type itself.
3136 Aitem
:= Make_Aitem_Pragma
3137 (Pragma_Argument_Associations
=> New_List
(
3138 Make_Pragma_Argument_Association
(Sloc
(Ent
),
3140 Make_Pragma_Argument_Association
(Sloc
(Expr
),
3141 Expression
=> Relocate_Expression
(Expr
))),
3142 Pragma_Name
=> Name_Predicate
);
3144 -- Mark type has predicates, and remember what kind of
3145 -- aspect lead to this predicate (we need this to access
3146 -- the right set of check policies later on).
3148 Set_Has_Predicates
(E
);
3150 if A_Id
= Aspect_Dynamic_Predicate
then
3151 Set_Has_Dynamic_Predicate_Aspect
(E
);
3153 -- If the entity has a dynamic predicate, any inherited
3154 -- static predicate becomes dynamic as well, and the
3155 -- predicate function includes the conjunction of both.
3157 Set_Has_Static_Predicate_Aspect
(E
, False);
3159 elsif A_Id
= Aspect_Static_Predicate
then
3160 Set_Has_Static_Predicate_Aspect
(E
);
3163 -- If the type is private, indicate that its completion
3164 -- has a freeze node, because that is the one that will
3165 -- be visible at freeze time.
3167 if Is_Private_Type
(E
) and then Present
(Full_View
(E
)) then
3168 Set_Has_Predicates
(Full_View
(E
));
3170 if A_Id
= Aspect_Dynamic_Predicate
then
3171 Set_Has_Dynamic_Predicate_Aspect
(Full_View
(E
));
3172 elsif A_Id
= Aspect_Static_Predicate
then
3173 Set_Has_Static_Predicate_Aspect
(Full_View
(E
));
3176 Set_Has_Delayed_Aspects
(Full_View
(E
));
3177 Ensure_Freeze_Node
(Full_View
(E
));
3179 -- If there is an Underlying_Full_View, also create a
3180 -- freeze node for that one.
3182 if Is_Private_Type
(Full_View
(E
)) then
3184 U_Full
: constant Entity_Id
:=
3185 Underlying_Full_View
(Full_View
(E
));
3187 if Present
(U_Full
) then
3188 Set_Has_Delayed_Aspects
(U_Full
);
3189 Ensure_Freeze_Node
(U_Full
);
3195 -- Predicate_Failure
3197 when Aspect_Predicate_Failure
=>
3199 -- This aspect applies only to subtypes
3201 if not Is_Type
(E
) then
3203 ("predicate can only be specified for a subtype",
3207 elsif Is_Incomplete_Type
(E
) then
3209 ("predicate cannot apply to incomplete view", Aspect
);
3212 elsif not Has_Predicates
(E
) then
3214 ("Predicate_Failure requires previous predicate" &
3215 " specification", Aspect
);
3218 elsif not (Directly_Specified
(E
, Aspect_Dynamic_Predicate
)
3219 or else Directly_Specified
(E
, Aspect_Static_Predicate
)
3220 or else Directly_Specified
(E
, Aspect_Predicate
))
3223 ("Predicate_Failure requires accompanying" &
3224 " noninherited predicate specification", Aspect
);
3228 -- Construct the pragma
3230 Aitem
:= Make_Aitem_Pragma
3231 (Pragma_Argument_Associations
=> New_List
(
3232 Make_Pragma_Argument_Association
(Sloc
(Ent
),
3234 Make_Pragma_Argument_Association
(Sloc
(Expr
),
3235 Expression
=> Relocate_Node
(Expr
))),
3236 Pragma_Name
=> Name_Predicate_Failure
);
3238 -- Case 2b: Aspects corresponding to pragmas with two
3239 -- arguments, where the second argument is a local name
3240 -- referring to the entity, and the first argument is the
3241 -- aspect definition expression.
3245 when Aspect_Convention
=>
3246 Analyze_Aspect_Convention
;
3249 -- External_Name, Link_Name
3251 when Aspect_External_Name
3254 Analyze_Aspect_External_Link_Name
;
3257 -- CPU, Interrupt_Priority, Priority
3259 -- These three aspects can be specified for a subprogram spec
3260 -- or body, in which case we analyze the expression and export
3261 -- the value of the aspect.
3263 -- Previously, we generated an equivalent pragma for bodies
3264 -- (note that the specs cannot contain these pragmas). The
3265 -- pragma was inserted ahead of local declarations, rather than
3266 -- after the body. This leads to a certain duplication between
3267 -- the processing performed for the aspect and the pragma, but
3268 -- given the straightforward handling required it is simpler
3269 -- to duplicate than to translate the aspect in the spec into
3270 -- a pragma in the declarative part of the body.
3273 | Aspect_Interrupt_Priority
3276 -- Verify the expression is static when Static_Priorities is
3279 if not Is_OK_Static_Expression
(Expr
) then
3280 Check_Restriction
(Static_Priorities
, Expr
);
3283 if Nkind
(N
) in N_Subprogram_Body | N_Subprogram_Declaration
3285 -- Analyze the aspect expression
3287 Analyze_And_Resolve
(Expr
, Standard_Integer
);
3289 -- Interrupt_Priority aspect not allowed for main
3290 -- subprograms. RM D.1 does not forbid this explicitly,
3291 -- but RM J.15.11(6/3) does not permit pragma
3292 -- Interrupt_Priority for subprograms.
3294 if A_Id
= Aspect_Interrupt_Priority
then
3296 ("Interrupt_Priority aspect cannot apply to "
3297 & "subprogram", Expr
);
3299 -- The expression must be static
3301 elsif not Is_OK_Static_Expression
(Expr
) then
3302 Flag_Non_Static_Expr
3303 ("aspect requires static expression!", Expr
);
3305 -- Check whether this is the main subprogram. Issue a
3306 -- warning only if it is obviously not a main program
3307 -- (when it has parameters or when the subprogram is
3308 -- within a package).
3310 elsif Present
(Parameter_Specifications
3311 (Specification
(N
)))
3312 or else not Is_Compilation_Unit
(Defining_Entity
(N
))
3314 -- See RM D.1(14/3) and D.16(12/3)
3317 ("aspect applied to subprogram other than the "
3318 & "main subprogram has no effect??", Expr
);
3320 -- Otherwise check in range and export the value
3322 -- For the CPU aspect
3324 elsif A_Id
= Aspect_CPU
then
3325 if Is_In_Range
(Expr
, RTE
(RE_CPU_Range
)) then
3327 -- Value is correct so we export the value to make
3328 -- it available at execution time.
3331 (Main_Unit
, UI_To_Int
(Expr_Value
(Expr
)));
3335 ("main subprogram 'C'P'U is out of range", Expr
);
3338 -- For the Priority aspect
3340 elsif A_Id
= Aspect_Priority
then
3341 if Is_In_Range
(Expr
, RTE
(RE_Priority
)) then
3343 -- Value is correct so we export the value to make
3344 -- it available at execution time.
3347 (Main_Unit
, UI_To_Int
(Expr_Value
(Expr
)));
3349 -- Ignore pragma if Relaxed_RM_Semantics to support
3350 -- other targets/non GNAT compilers.
3352 elsif not Relaxed_RM_Semantics
then
3354 ("main subprogram priority is out of range",
3359 -- Load an arbitrary entity from System.Tasking.Stages
3360 -- or System.Tasking.Restricted.Stages (depending on
3361 -- the supported profile) to make sure that one of these
3362 -- packages is implicitly with'ed, since we need to have
3363 -- the tasking run time active for the pragma Priority to
3364 -- have any effect. Previously we with'ed the package
3365 -- System.Tasking, but this package does not trigger the
3366 -- required initialization of the run-time library.
3368 if Restricted_Profile
then
3369 Discard_Node
(RTE
(RE_Activate_Restricted_Tasks
));
3371 Discard_Node
(RTE
(RE_Activate_Tasks
));
3374 -- Handling for these aspects in subprograms is complete
3378 -- For task and protected types pass the aspect as an
3383 Make_Attribute_Definition_Clause
(Loc
,
3386 Expression
=> Relocate_Expression
(Expr
));
3389 -- Suppress/Unsuppress
3391 when Aspect_Suppress
3394 Aitem
:= Make_Aitem_Pragma
3395 (Pragma_Argument_Associations
=> New_List
(
3396 Make_Pragma_Argument_Association
(Loc
,
3397 Expression
=> Relocate_Node
(Expr
)),
3398 Make_Pragma_Argument_Association
(Sloc
(Expr
),
3399 Expression
=> New_Occurrence_Of
(E
, Loc
))),
3400 Pragma_Name
=> Nam
);
3402 Delay_Required
:= False;
3406 when Aspect_Warnings
=>
3407 Aitem
:= Make_Aitem_Pragma
3408 (Pragma_Argument_Associations
=> New_List
(
3409 Make_Pragma_Argument_Association
(Sloc
(Expr
),
3410 Expression
=> Relocate_Node
(Expr
)),
3411 Make_Pragma_Argument_Association
(Loc
,
3412 Expression
=> New_Occurrence_Of
(E
, Loc
))),
3413 Pragma_Name
=> Name_Warnings
);
3415 Decorate
(Aspect
, Aitem
);
3416 Insert_Pragma
(Aitem
);
3419 -- Case 2c: Aspects corresponding to pragmas with three
3422 -- Invariant aspects have a first argument that references the
3423 -- entity, a second argument that is the expression and a third
3424 -- argument that is an appropriate message.
3426 -- Invariant, Type_Invariant
3428 when Aspect_Invariant
3429 | Aspect_Type_Invariant
3431 -- Analysis of the pragma will verify placement legality:
3432 -- an invariant must apply to a private type, or appear in
3433 -- the private part of a spec and apply to a completion.
3435 Aitem
:= Make_Aitem_Pragma
3436 (Pragma_Argument_Associations
=> New_List
(
3437 Make_Pragma_Argument_Association
(Sloc
(Ent
),
3439 Make_Pragma_Argument_Association
(Sloc
(Expr
),
3440 Expression
=> Relocate_Node
(Expr
))),
3441 Pragma_Name
=> Name_Invariant
);
3443 -- Add message unless exception messages are suppressed
3445 if not Opt
.Exception_Locations_Suppressed
then
3446 Append_To
(Pragma_Argument_Associations
(Aitem
),
3447 Make_Pragma_Argument_Association
(Eloc
,
3448 Chars
=> Name_Message
,
3450 Make_String_Literal
(Eloc
,
3451 Strval
=> "failed invariant from "
3452 & Build_Location_String
(Eloc
))));
3455 -- For Invariant case, insert immediately after the entity
3456 -- declaration. We do not have to worry about delay issues
3457 -- since the pragma processing takes care of this.
3459 Delay_Required
:= False;
3461 -- Case 2d : Aspects that correspond to a pragma with one
3466 -- Aspect Abstract_State introduces implicit declarations for
3467 -- all state abstraction entities it defines. To emulate this
3468 -- behavior, insert the pragma at the beginning of the visible
3469 -- declarations of the related package so that it is analyzed
3472 when Aspect_Abstract_State
=> Abstract_State
: declare
3473 Context
: Node_Id
:= N
;
3476 -- When aspect Abstract_State appears on a generic package,
3477 -- it is propagated to the package instance. The context in
3478 -- this case is the instance spec.
3480 if Nkind
(Context
) = N_Package_Instantiation
then
3481 Context
:= Instance_Spec
(Context
);
3484 if Nkind
(Context
) in N_Generic_Package_Declaration
3485 | N_Package_Declaration
3487 Aitem
:= Make_Aitem_Pragma
3488 (Pragma_Argument_Associations
=> New_List
(
3489 Make_Pragma_Argument_Association
(Loc
,
3490 Expression
=> Relocate_Node
(Expr
))),
3491 Pragma_Name
=> Name_Abstract_State
);
3493 Decorate
(Aspect
, Aitem
);
3497 Is_Generic_Instance
(Defining_Entity
(Context
)));
3501 ("aspect & must apply to a package declaration",
3508 -- Aspect Async_Readers is never delayed because it is
3509 -- equivalent to a source pragma which appears after the
3510 -- related object declaration.
3512 when Aspect_Async_Readers
=>
3513 Aitem
:= Make_Aitem_Pragma
3514 (Pragma_Argument_Associations
=> New_List
(
3515 Make_Pragma_Argument_Association
(Loc
,
3516 Expression
=> Relocate_Node
(Expr
))),
3517 Pragma_Name
=> Name_Async_Readers
);
3519 Decorate
(Aspect
, Aitem
);
3520 Insert_Pragma
(Aitem
);
3523 -- Aspect Async_Writers is never delayed because it is
3524 -- equivalent to a source pragma which appears after the
3525 -- related object declaration.
3527 when Aspect_Async_Writers
=>
3528 Aitem
:= Make_Aitem_Pragma
3529 (Pragma_Argument_Associations
=> New_List
(
3530 Make_Pragma_Argument_Association
(Loc
,
3531 Expression
=> Relocate_Node
(Expr
))),
3532 Pragma_Name
=> Name_Async_Writers
);
3534 Decorate
(Aspect
, Aitem
);
3535 Insert_Pragma
(Aitem
);
3538 -- Aspect Constant_After_Elaboration is never delayed because
3539 -- it is equivalent to a source pragma which appears after the
3540 -- related object declaration.
3542 when Aspect_Constant_After_Elaboration
=>
3543 Aitem
:= Make_Aitem_Pragma
3544 (Pragma_Argument_Associations
=> New_List
(
3545 Make_Pragma_Argument_Association
(Loc
,
3546 Expression
=> Relocate_Node
(Expr
))),
3548 Name_Constant_After_Elaboration
);
3550 Decorate
(Aspect
, Aitem
);
3551 Insert_Pragma
(Aitem
);
3554 -- Aspect Default_Internal_Condition is never delayed because
3555 -- it is equivalent to a source pragma which appears after the
3556 -- related private type. To deal with forward references, the
3557 -- generated pragma is stored in the rep chain of the related
3558 -- private type as types do not carry contracts. The pragma is
3559 -- wrapped inside of a procedure at the freeze point of the
3560 -- private type's full view.
3562 -- A type entity argument is appended to facilitate inheriting
3563 -- the aspect from parent types (see Build_DIC_Procedure_Body),
3564 -- though that extra argument isn't documented for the pragma.
3566 when Aspect_Default_Initial_Condition
=>
3567 Aitem
:= Make_Aitem_Pragma
3568 (Pragma_Argument_Associations
=> New_List
(
3569 Make_Pragma_Argument_Association
(Loc
,
3570 Expression
=> Relocate_Node
(Expr
)),
3571 Make_Pragma_Argument_Association
(Sloc
(Ent
),
3572 Expression
=> Ent
)),
3574 Name_Default_Initial_Condition
);
3576 Decorate
(Aspect
, Aitem
);
3577 Insert_Pragma
(Aitem
);
3580 -- Default_Storage_Pool
3582 when Aspect_Default_Storage_Pool
=>
3583 Aitem
:= Make_Aitem_Pragma
3584 (Pragma_Argument_Associations
=> New_List
(
3585 Make_Pragma_Argument_Association
(Loc
,
3586 Expression
=> Relocate_Node
(Expr
))),
3588 Name_Default_Storage_Pool
);
3590 Decorate
(Aspect
, Aitem
);
3591 Insert_Pragma
(Aitem
);
3596 -- Aspect Depends is never delayed because it is equivalent to
3597 -- a source pragma which appears after the related subprogram.
3598 -- To deal with forward references, the generated pragma is
3599 -- stored in the contract of the related subprogram and later
3600 -- analyzed at the end of the declarative region. See routine
3601 -- Analyze_Depends_In_Decl_Part for details.
3603 when Aspect_Depends
=>
3604 Aitem
:= Make_Aitem_Pragma
3605 (Pragma_Argument_Associations
=> New_List
(
3606 Make_Pragma_Argument_Association
(Loc
,
3607 Expression
=> Relocate_Node
(Expr
))),
3608 Pragma_Name
=> Name_Depends
);
3610 Decorate
(Aspect
, Aitem
);
3611 Insert_Pragma
(Aitem
);
3614 -- Aspect Effective_Reads is never delayed because it is
3615 -- equivalent to a source pragma which appears after the
3616 -- related object declaration.
3618 when Aspect_Effective_Reads
=>
3619 Aitem
:= Make_Aitem_Pragma
3620 (Pragma_Argument_Associations
=> New_List
(
3621 Make_Pragma_Argument_Association
(Loc
,
3622 Expression
=> Relocate_Node
(Expr
))),
3623 Pragma_Name
=> Name_Effective_Reads
);
3625 Decorate
(Aspect
, Aitem
);
3626 Insert_Pragma
(Aitem
);
3629 -- Aspect Effective_Writes is never delayed because it is
3630 -- equivalent to a source pragma which appears after the
3631 -- related object declaration.
3633 when Aspect_Effective_Writes
=>
3634 Aitem
:= Make_Aitem_Pragma
3635 (Pragma_Argument_Associations
=> New_List
(
3636 Make_Pragma_Argument_Association
(Loc
,
3637 Expression
=> Relocate_Node
(Expr
))),
3638 Pragma_Name
=> Name_Effective_Writes
);
3640 Decorate
(Aspect
, Aitem
);
3641 Insert_Pragma
(Aitem
);
3644 -- Aspect Extensions_Visible is never delayed because it is
3645 -- equivalent to a source pragma which appears after the
3646 -- related subprogram.
3648 when Aspect_Extensions_Visible
=>
3649 Aitem
:= Make_Aitem_Pragma
3650 (Pragma_Argument_Associations
=> New_List
(
3651 Make_Pragma_Argument_Association
(Loc
,
3652 Expression
=> Relocate_Node
(Expr
))),
3653 Pragma_Name
=> Name_Extensions_Visible
);
3655 Decorate
(Aspect
, Aitem
);
3656 Insert_Pragma
(Aitem
);
3659 -- Aspect Ghost is never delayed because it is equivalent to a
3660 -- source pragma which appears at the top of [generic] package
3661 -- declarations or after an object, a [generic] subprogram, or
3662 -- a type declaration.
3664 when Aspect_Ghost
=>
3665 Aitem
:= Make_Aitem_Pragma
3666 (Pragma_Argument_Associations
=> New_List
(
3667 Make_Pragma_Argument_Association
(Loc
,
3668 Expression
=> Relocate_Node
(Expr
))),
3669 Pragma_Name
=> Name_Ghost
);
3671 Decorate
(Aspect
, Aitem
);
3672 Insert_Pragma
(Aitem
);
3677 -- Aspect Global is never delayed because it is equivalent to
3678 -- a source pragma which appears after the related subprogram.
3679 -- To deal with forward references, the generated pragma is
3680 -- stored in the contract of the related subprogram and later
3681 -- analyzed at the end of the declarative region. See routine
3682 -- Analyze_Global_In_Decl_Part for details.
3684 when Aspect_Global
=>
3685 Aitem
:= Make_Aitem_Pragma
3686 (Pragma_Argument_Associations
=> New_List
(
3687 Make_Pragma_Argument_Association
(Loc
,
3688 Expression
=> Relocate_Node
(Expr
))),
3689 Pragma_Name
=> Name_Global
);
3691 Decorate
(Aspect
, Aitem
);
3692 Insert_Pragma
(Aitem
);
3695 -- Initial_Condition
3697 -- Aspect Initial_Condition is never delayed because it is
3698 -- equivalent to a source pragma which appears after the
3699 -- related package. To deal with forward references, the
3700 -- generated pragma is stored in the contract of the related
3701 -- package and later analyzed at the end of the declarative
3702 -- region. See routine Analyze_Initial_Condition_In_Decl_Part
3705 when Aspect_Initial_Condition
=> Initial_Condition
: declare
3706 Context
: Node_Id
:= N
;
3709 -- When aspect Initial_Condition appears on a generic
3710 -- package, it is propagated to the package instance. The
3711 -- context in this case is the instance spec.
3713 if Nkind
(Context
) = N_Package_Instantiation
then
3714 Context
:= Instance_Spec
(Context
);
3717 if Nkind
(Context
) in N_Generic_Package_Declaration
3718 | N_Package_Declaration
3720 Aitem
:= Make_Aitem_Pragma
3721 (Pragma_Argument_Associations
=> New_List
(
3722 Make_Pragma_Argument_Association
(Loc
,
3723 Expression
=> Relocate_Node
(Expr
))),
3725 Name_Initial_Condition
);
3727 Decorate
(Aspect
, Aitem
);
3731 Is_Generic_Instance
(Defining_Entity
(Context
)));
3733 -- Otherwise the context is illegal
3737 ("aspect & must apply to a package declaration",
3742 end Initial_Condition
;
3746 -- Aspect Initializes is never delayed because it is equivalent
3747 -- to a source pragma appearing after the related package. To
3748 -- deal with forward references, the generated pragma is stored
3749 -- in the contract of the related package and later analyzed at
3750 -- the end of the declarative region. For details, see routine
3751 -- Analyze_Initializes_In_Decl_Part.
3753 when Aspect_Initializes
=> Initializes
: declare
3754 Context
: Node_Id
:= N
;
3757 -- When aspect Initializes appears on a generic package,
3758 -- it is propagated to the package instance. The context
3759 -- in this case is the instance spec.
3761 if Nkind
(Context
) = N_Package_Instantiation
then
3762 Context
:= Instance_Spec
(Context
);
3765 if Nkind
(Context
) in N_Generic_Package_Declaration
3766 | N_Package_Declaration
3768 Aitem
:= Make_Aitem_Pragma
3769 (Pragma_Argument_Associations
=> New_List
(
3770 Make_Pragma_Argument_Association
(Loc
,
3771 Expression
=> Relocate_Node
(Expr
))),
3772 Pragma_Name
=> Name_Initializes
);
3774 Decorate
(Aspect
, Aitem
);
3778 Is_Generic_Instance
(Defining_Entity
(Context
)));
3780 -- Otherwise the context is illegal
3784 ("aspect & must apply to a package declaration",
3791 -- Max_Entry_Queue_Depth
3793 when Aspect_Max_Entry_Queue_Depth
=>
3794 Aitem
:= Make_Aitem_Pragma
3795 (Pragma_Argument_Associations
=> New_List
(
3796 Make_Pragma_Argument_Association
(Loc
,
3797 Expression
=> Relocate_Node
(Expr
))),
3798 Pragma_Name
=> Name_Max_Entry_Queue_Depth
);
3800 Decorate
(Aspect
, Aitem
);
3801 Insert_Pragma
(Aitem
);
3804 -- Max_Entry_Queue_Length
3806 when Aspect_Max_Entry_Queue_Length
=>
3807 Aitem
:= Make_Aitem_Pragma
3808 (Pragma_Argument_Associations
=> New_List
(
3809 Make_Pragma_Argument_Association
(Loc
,
3810 Expression
=> Relocate_Node
(Expr
))),
3811 Pragma_Name
=> Name_Max_Entry_Queue_Length
);
3813 Decorate
(Aspect
, Aitem
);
3814 Insert_Pragma
(Aitem
);
3819 when Aspect_Max_Queue_Length
=>
3820 Aitem
:= Make_Aitem_Pragma
3821 (Pragma_Argument_Associations
=> New_List
(
3822 Make_Pragma_Argument_Association
(Loc
,
3823 Expression
=> Relocate_Node
(Expr
))),
3824 Pragma_Name
=> Name_Max_Queue_Length
);
3826 Decorate
(Aspect
, Aitem
);
3827 Insert_Pragma
(Aitem
);
3830 -- Aspect No_Caching is never delayed because it is equivalent
3831 -- to a source pragma which appears after the related object
3834 when Aspect_No_Caching
=>
3835 Aitem
:= Make_Aitem_Pragma
3836 (Pragma_Argument_Associations
=> New_List
(
3837 Make_Pragma_Argument_Association
(Loc
,
3838 Expression
=> Relocate_Node
(Expr
))),
3839 Pragma_Name
=> Name_No_Caching
);
3841 Decorate
(Aspect
, Aitem
);
3842 Insert_Pragma
(Aitem
);
3845 -- No_Controlled_Parts, No_Task_Parts
3847 when Aspect_No_Controlled_Parts | Aspect_No_Task_Parts
=>
3849 -- Check appropriate type argument
3851 if not Is_Type
(E
) then
3853 ("aspect % can only be applied to types", E
);
3856 -- Disallow subtypes
3858 if Nkind
(Declaration_Node
(E
)) = N_Subtype_Declaration
then
3860 ("aspect % cannot be applied to subtypes", E
);
3863 -- Resolve the expression to a boolean
3865 if Present
(Expr
) then
3866 Check_Expr_Is_OK_Static_Expression
(Expr
, Any_Boolean
);
3873 when Aspect_Obsolescent
=> declare
3881 Make_Pragma_Argument_Association
(Sloc
(Expr
),
3882 Expression
=> Relocate_Node
(Expr
)));
3885 Aitem
:= Make_Aitem_Pragma
3886 (Pragma_Argument_Associations
=> Args
,
3887 Pragma_Name
=> Name_Obsolescent
);
3892 when Aspect_Part_Of
=>
3893 if Nkind
(N
) in N_Object_Declaration
3894 | N_Package_Instantiation
3895 or else Is_Single_Concurrent_Type_Declaration
(N
)
3897 Aitem
:= Make_Aitem_Pragma
3898 (Pragma_Argument_Associations
=> New_List
(
3899 Make_Pragma_Argument_Association
(Loc
,
3900 Expression
=> Relocate_Node
(Expr
))),
3901 Pragma_Name
=> Name_Part_Of
);
3903 Decorate
(Aspect
, Aitem
);
3904 Insert_Pragma
(Aitem
);
3908 ("aspect & must apply to package instantiation, "
3909 & "object, single protected type or single task type",
3917 when Aspect_SPARK_Mode
=>
3918 Aitem
:= Make_Aitem_Pragma
3919 (Pragma_Argument_Associations
=> New_List
(
3920 Make_Pragma_Argument_Association
(Loc
,
3921 Expression
=> Relocate_Node
(Expr
))),
3922 Pragma_Name
=> Name_SPARK_Mode
);
3924 Decorate
(Aspect
, Aitem
);
3925 Insert_Pragma
(Aitem
);
3930 -- Aspect Refined_Depends is never delayed because it is
3931 -- equivalent to a source pragma which appears in the
3932 -- declarations of the related subprogram body. To deal with
3933 -- forward references, the generated pragma is stored in the
3934 -- contract of the related subprogram body and later analyzed
3935 -- at the end of the declarative region. For details, see
3936 -- routine Analyze_Refined_Depends_In_Decl_Part.
3938 when Aspect_Refined_Depends
=>
3939 Aitem
:= Make_Aitem_Pragma
3940 (Pragma_Argument_Associations
=> New_List
(
3941 Make_Pragma_Argument_Association
(Loc
,
3942 Expression
=> Relocate_Node
(Expr
))),
3943 Pragma_Name
=> Name_Refined_Depends
);
3945 Decorate
(Aspect
, Aitem
);
3946 Insert_Pragma
(Aitem
);
3951 -- Aspect Refined_Global is never delayed because it is
3952 -- equivalent to a source pragma which appears in the
3953 -- declarations of the related subprogram body. To deal with
3954 -- forward references, the generated pragma is stored in the
3955 -- contract of the related subprogram body and later analyzed
3956 -- at the end of the declarative region. For details, see
3957 -- routine Analyze_Refined_Global_In_Decl_Part.
3959 when Aspect_Refined_Global
=>
3960 Aitem
:= Make_Aitem_Pragma
3961 (Pragma_Argument_Associations
=> New_List
(
3962 Make_Pragma_Argument_Association
(Loc
,
3963 Expression
=> Relocate_Node
(Expr
))),
3964 Pragma_Name
=> Name_Refined_Global
);
3966 Decorate
(Aspect
, Aitem
);
3967 Insert_Pragma
(Aitem
);
3972 when Aspect_Refined_Post
=>
3973 Aitem
:= Make_Aitem_Pragma
3974 (Pragma_Argument_Associations
=> New_List
(
3975 Make_Pragma_Argument_Association
(Loc
,
3976 Expression
=> Relocate_Node
(Expr
))),
3977 Pragma_Name
=> Name_Refined_Post
);
3979 Decorate
(Aspect
, Aitem
);
3980 Insert_Pragma
(Aitem
);
3985 when Aspect_Refined_State
=>
3987 -- The corresponding pragma for Refined_State is inserted in
3988 -- the declarations of the related package body. This action
3989 -- synchronizes both the source and from-aspect versions of
3992 if Nkind
(N
) = N_Package_Body
then
3993 Aitem
:= Make_Aitem_Pragma
3994 (Pragma_Argument_Associations
=> New_List
(
3995 Make_Pragma_Argument_Association
(Loc
,
3996 Expression
=> Relocate_Node
(Expr
))),
3997 Pragma_Name
=> Name_Refined_State
);
3999 Decorate
(Aspect
, Aitem
);
4000 Insert_Pragma
(Aitem
);
4002 -- Otherwise the context is illegal
4006 ("aspect & must apply to a package body", Aspect
, Id
);
4011 -- Relative_Deadline
4013 when Aspect_Relative_Deadline
=>
4014 Aitem
:= Make_Aitem_Pragma
4015 (Pragma_Argument_Associations
=> New_List
(
4016 Make_Pragma_Argument_Association
(Loc
,
4017 Expression
=> Relocate_Node
(Expr
))),
4018 Pragma_Name
=> Name_Relative_Deadline
);
4020 -- If the aspect applies to a task, the corresponding pragma
4021 -- must appear within its declarations, not after.
4023 if Nkind
(N
) = N_Task_Type_Declaration
then
4029 if No
(Task_Definition
(N
)) then
4030 Set_Task_Definition
(N
,
4031 Make_Task_Definition
(Loc
,
4032 Visible_Declarations
=> New_List
,
4033 End_Label
=> Empty
));
4036 Def
:= Task_Definition
(N
);
4037 V
:= Visible_Declarations
(Def
);
4038 if not Is_Empty_List
(V
) then
4039 Insert_Before
(First
(V
), Aitem
);
4042 Set_Visible_Declarations
(Def
, New_List
(Aitem
));
4049 -- Relaxed_Initialization
4051 when Aspect_Relaxed_Initialization
=>
4052 Analyze_Aspect_Relaxed_Initialization
;
4055 -- Secondary_Stack_Size
4057 -- Aspect Secondary_Stack_Size needs to be converted into a
4058 -- pragma for two reasons: the attribute is not analyzed until
4059 -- after the expansion of the task type declaration and the
4060 -- attribute does not have visibility on the discriminant.
4062 when Aspect_Secondary_Stack_Size
=>
4063 Aitem
:= Make_Aitem_Pragma
4064 (Pragma_Argument_Associations
=> New_List
(
4065 Make_Pragma_Argument_Association
(Loc
,
4066 Expression
=> Relocate_Node
(Expr
))),
4068 Name_Secondary_Stack_Size
);
4070 Decorate
(Aspect
, Aitem
);
4071 Insert_Pragma
(Aitem
);
4074 -- Volatile_Function
4076 -- Aspect Volatile_Function is never delayed because it is
4077 -- equivalent to a source pragma which appears after the
4078 -- related subprogram.
4080 when Aspect_Volatile_Function
=>
4081 Aitem
:= Make_Aitem_Pragma
4082 (Pragma_Argument_Associations
=> New_List
(
4083 Make_Pragma_Argument_Association
(Loc
,
4084 Expression
=> Relocate_Node
(Expr
))),
4085 Pragma_Name
=> Name_Volatile_Function
);
4087 Decorate
(Aspect
, Aitem
);
4088 Insert_Pragma
(Aitem
);
4091 -- Case 2e: Annotate aspect
4093 when Aspect_Annotate | Aspect_GNAT_Annotate
=>
4100 -- The argument can be a single identifier
4102 if Nkind
(Expr
) = N_Identifier
then
4104 -- One level of parens is allowed
4106 if Paren_Count
(Expr
) > 1 then
4107 Error_Msg_F
("extra parentheses ignored", Expr
);
4110 Set_Paren_Count
(Expr
, 0);
4112 -- Add the single item to the list
4114 Args
:= New_List
(Expr
);
4116 -- Otherwise we must have an aggregate
4118 elsif Nkind
(Expr
) = N_Aggregate
then
4120 -- Must be positional
4122 if Present
(Component_Associations
(Expr
)) then
4124 ("purely positional aggregate required", Expr
);
4128 -- Must not be parenthesized
4130 if Paren_Count
(Expr
) /= 0 then
4131 Error_Msg_F
-- CODEFIX
4132 ("redundant parentheses", Expr
);
4135 -- List of arguments is list of aggregate expressions
4137 Args
:= Expressions
(Expr
);
4139 -- Anything else is illegal
4142 Error_Msg_F
("wrong form for Annotate aspect", Expr
);
4146 -- Prepare pragma arguments
4149 Arg
:= First
(Args
);
4150 while Present
(Arg
) loop
4152 Make_Pragma_Argument_Association
(Sloc
(Arg
),
4153 Expression
=> Relocate_Node
(Arg
)));
4158 Make_Pragma_Argument_Association
(Sloc
(Ent
),
4159 Chars
=> Name_Entity
,
4160 Expression
=> Ent
));
4162 Aitem
:= Make_Aitem_Pragma
4163 (Pragma_Argument_Associations
=> Pargs
,
4164 Pragma_Name
=> Name_Annotate
);
4167 -- Case 3 : Aspects that don't correspond to pragma/attribute
4168 -- definition clause.
4170 -- Case 3a: The aspects listed below don't correspond to
4171 -- pragmas/attributes but do require delayed analysis.
4173 when Aspect_Default_Value | Aspect_Default_Component_Value
=>
4174 Error_Msg_Name_1
:= Nam
;
4176 if not Is_Type
(E
) then
4177 Error_Msg_N
("aspect% can only apply to a type", Id
);
4180 elsif not Is_First_Subtype
(E
) then
4181 Error_Msg_N
("aspect% cannot apply to subtype", Id
);
4184 elsif A_Id
= Aspect_Default_Value
4185 and then not Is_Scalar_Type
(E
)
4188 ("aspect% can only be applied to scalar type", Id
);
4191 elsif A_Id
= Aspect_Default_Component_Value
then
4192 if not Is_Array_Type
(E
) then
4194 ("aspect% can only be applied to array type", Id
);
4197 elsif not Is_Scalar_Type
(Component_Type
(E
)) then
4198 Error_Msg_N
("aspect% requires scalar components", Id
);
4205 when Aspect_Aggregate
=>
4206 -- We will be checking that the aspect is not specified on a
4207 -- non-array type in Check_Aspect_At_Freeze_Point
4209 Validate_Aspect_Aggregate
(Expr
);
4210 Record_Rep_Item
(E
, Aspect
);
4213 when Aspect_Stable_Properties
=>
4214 Validate_Aspect_Stable_Properties
4215 (E
, Expr
, Class_Present
=> Class_Present
(Aspect
));
4216 Record_Rep_Item
(E
, Aspect
);
4219 when Aspect_Designated_Storage_Model
=>
4220 if not All_Extensions_Allowed
then
4221 Error_Msg_GNAT_Extension
("aspect %", Sloc
(Aspect
));
4223 elsif not Is_Type
(E
)
4224 or else Ekind
(E
) /= E_Access_Type
4227 ("can only be specified for pool-specific access type",
4231 Record_Rep_Item
(E
, Aspect
);
4234 when Aspect_Storage_Model_Type
=>
4235 if not All_Extensions_Allowed
then
4236 Error_Msg_GNAT_Extension
("aspect %", Sloc
(Aspect
));
4238 elsif not Is_Type
(E
)
4239 or else not Is_Immutably_Limited_Type
(E
)
4242 ("can only be specified for immutably limited type",
4246 Record_Rep_Item
(E
, Aspect
);
4249 when Aspect_Integer_Literal
4250 | Aspect_Real_Literal
4251 | Aspect_String_Literal
4254 if not Is_First_Subtype
(E
) then
4256 ("may only be specified for a first subtype", Aspect
);
4260 if Ada_Version
< Ada_2022
then
4262 (No_Implementation_Aspect_Specifications
, N
);
4267 -- Case 3b: The aspects listed below don't correspond to
4268 -- pragmas/attributes and don't need delayed analysis.
4270 -- Implicit_Dereference
4272 -- For Implicit_Dereference, External_Name and Link_Name, only
4273 -- the legality checks are done during the analysis, thus no
4274 -- delay is required.
4276 when Aspect_Implicit_Dereference
=>
4277 Analyze_Aspect_Implicit_Dereference
;
4282 when Aspect_Dimension
=>
4283 Analyze_Aspect_Dimension
(N
, Id
, Expr
);
4288 when Aspect_Dimension_System
=>
4289 Analyze_Aspect_Dimension_System
(N
, Id
, Expr
);
4292 -- Case 4: Aspects requiring special handling
4294 -- Pre/Post/Test_Case/Contract_Cases/Exceptional_Cases and
4295 -- Subprogram_Variant whose corresponding pragmas take care
4300 -- Aspects Pre/Post generate Precondition/Postcondition pragmas
4301 -- with a first argument that is the expression, and a second
4302 -- argument that is an informative message if the test fails.
4303 -- This is inserted right after the declaration, to get the
4304 -- required pragma placement. The processing for the pragmas
4305 -- takes care of the required delay.
4307 when Pre_Post_Aspects
=> Pre_Post
: declare
4311 if A_Id
in Aspect_Pre | Aspect_Precondition
then
4312 Pname
:= Name_Precondition
;
4314 Pname
:= Name_Postcondition
;
4317 -- Check that the class-wide predicate cannot be applied to
4318 -- an operation of a synchronized type. AI12-0182 forbids
4319 -- these altogether, while earlier language semantics made
4320 -- them legal on tagged synchronized types.
4322 -- Other legality checks are performed when analyzing the
4323 -- contract of the operation.
4325 if Class_Present
(Aspect
)
4326 and then Is_Concurrent_Type
(Current_Scope
)
4327 and then Ekind
(E
) in E_Entry | E_Function | E_Procedure
4329 Error_Msg_Name_1
:= Original_Aspect_Pragma_Name
(Aspect
);
4331 ("aspect % can only be specified for a primitive "
4332 & "operation of a tagged type", Aspect
);
4337 -- Remember class-wide conditions; they will be merged
4338 -- with inherited conditions.
4340 if Class_Present
(Aspect
)
4341 and then A_Id
in Aspect_Pre | Aspect_Post
4342 and then Is_Subprogram
(E
)
4343 and then not Is_Ignored_Ghost_Entity
(E
)
4345 if A_Id
= Aspect_Pre
then
4346 if Is_Ignored
(Aspect
) then
4347 Set_Ignored_Class_Preconditions
(E
,
4348 New_Copy_Tree
(Expr
));
4350 Set_Class_Preconditions
(E
, New_Copy_Tree
(Expr
));
4353 -- Postconditions may split into separate aspects, and we
4354 -- remember the expression before such split (i.e. when
4355 -- the first postcondition is processed).
4357 elsif No
(Class_Postconditions
(E
))
4358 and then No
(Ignored_Class_Postconditions
(E
))
4360 if Is_Ignored
(Aspect
) then
4361 Set_Ignored_Class_Postconditions
(E
,
4362 New_Copy_Tree
(Expr
));
4364 Set_Class_Postconditions
(E
, New_Copy_Tree
(Expr
));
4369 -- If the expressions is of the form A and then B, then
4370 -- we generate separate Pre/Post aspects for the separate
4371 -- clauses. Since we allow multiple pragmas, there is no
4372 -- problem in allowing multiple Pre/Post aspects internally.
4373 -- These should be treated in reverse order (B first and
4374 -- A second) since they are later inserted just after N in
4375 -- the order they are treated. This way, the pragma for A
4376 -- ends up preceding the pragma for B, which may have an
4377 -- importance for the error raised (either constraint error
4378 -- or precondition error).
4380 -- We do not do this for Pre'Class, since we have to put
4381 -- these conditions together in a complex OR expression.
4383 -- We don't do this in GNATprove mode, because it brings no
4384 -- benefit for proof and causes annoyance for flow analysis,
4385 -- which prefers to be as close to the original source code
4386 -- as possible. Also we don't do this when analyzing generic
4387 -- units since it causes spurious visibility errors in the
4388 -- preanalysis of instantiations.
4390 if not GNATprove_Mode
4391 and then (Pname
= Name_Postcondition
4392 or else not Class_Present
(Aspect
))
4393 and then not Inside_A_Generic
4395 while Nkind
(Expr
) = N_And_Then
loop
4396 Insert_After
(Aspect
,
4397 Make_Aspect_Specification
(Sloc
(Left_Opnd
(Expr
)),
4398 Identifier
=> Identifier
(Aspect
),
4399 Expression
=> Relocate_Node
(Left_Opnd
(Expr
)),
4400 Class_Present
=> Class_Present
(Aspect
),
4401 Split_PPC
=> True));
4402 Rewrite
(Expr
, Relocate_Node
(Right_Opnd
(Expr
)));
4403 Eloc
:= Sloc
(Expr
);
4407 -- Build the precondition/postcondition pragma
4409 Aitem
:= Make_Aitem_Pragma
4410 (Pragma_Argument_Associations
=> New_List
(
4411 Make_Pragma_Argument_Association
(Eloc
,
4412 Chars
=> Name_Check
,
4413 Expression
=> Relocate_Expression
(Expr
))),
4414 Pragma_Name
=> Pname
);
4416 -- Add message unless exception messages are suppressed
4418 if not Opt
.Exception_Locations_Suppressed
then
4419 Append_To
(Pragma_Argument_Associations
(Aitem
),
4420 Make_Pragma_Argument_Association
(Eloc
,
4421 Chars
=> Name_Message
,
4423 Make_String_Literal
(Eloc
,
4425 & Get_Name_String
(Pname
)
4427 & Build_Location_String
(Eloc
))));
4430 Set_Is_Delayed_Aspect
(Aspect
);
4432 -- For Pre/Post cases, insert immediately after the entity
4433 -- declaration, since that is the required pragma placement.
4434 -- Note that for these aspects, we do not have to worry
4435 -- about delay issues, since the pragmas themselves deal
4436 -- with delay of visibility for the expression analysis.
4438 Insert_Pragma
(Aitem
);
4445 when Aspect_Test_Case
=> Test_Case
: declare
4447 Comp_Expr
: Node_Id
;
4448 Comp_Assn
: Node_Id
;
4453 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
4454 Error_Msg_Name_1
:= Nam
;
4455 Error_Msg_N
("incorrect placement of aspect %", E
);
4459 if Nkind
(Expr
) /= N_Aggregate
4460 or else Null_Record_Present
(Expr
)
4462 Error_Msg_Name_1
:= Nam
;
4464 ("wrong syntax for aspect % for &", Id
, E
);
4468 -- Check that the expression is a proper aggregate (no
4471 if Paren_Count
(Expr
) /= 0 then
4472 Error_Msg_F
-- CODEFIX
4473 ("redundant parentheses", Expr
);
4477 -- Create the list of arguments for building the Test_Case
4480 Comp_Expr
:= First
(Expressions
(Expr
));
4481 while Present
(Comp_Expr
) loop
4483 Make_Pragma_Argument_Association
(Sloc
(Comp_Expr
),
4484 Expression
=> Relocate_Node
(Comp_Expr
)));
4488 Comp_Assn
:= First
(Component_Associations
(Expr
));
4489 while Present
(Comp_Assn
) loop
4490 if List_Length
(Choices
(Comp_Assn
)) /= 1
4492 Nkind
(First
(Choices
(Comp_Assn
))) /= N_Identifier
4494 Error_Msg_Name_1
:= Nam
;
4496 ("wrong syntax for aspect % for &", Id
, E
);
4501 Make_Pragma_Argument_Association
(Sloc
(Comp_Assn
),
4502 Chars
=> Chars
(First
(Choices
(Comp_Assn
))),
4504 Relocate_Node
(Expression
(Comp_Assn
))));
4508 -- Build the test-case pragma
4510 Aitem
:= Make_Aitem_Pragma
4511 (Pragma_Argument_Associations
=> Args
,
4512 Pragma_Name
=> Name_Test_Case
);
4517 when Aspect_Contract_Cases
=>
4518 Aitem
:= Make_Aitem_Pragma
4519 (Pragma_Argument_Associations
=> New_List
(
4520 Make_Pragma_Argument_Association
(Loc
,
4521 Expression
=> Relocate_Node
(Expr
))),
4522 Pragma_Name
=> Name_Contract_Cases
);
4524 Decorate
(Aspect
, Aitem
);
4525 Insert_Pragma
(Aitem
);
4528 -- Exceptional_Cases
4530 when Aspect_Exceptional_Cases
=>
4531 Aitem
:= Make_Aitem_Pragma
4532 (Pragma_Argument_Associations
=> New_List
(
4533 Make_Pragma_Argument_Association
(Loc
,
4534 Expression
=> Relocate_Node
(Expr
))),
4535 Pragma_Name
=> Name_Exceptional_Cases
);
4537 Decorate
(Aspect
, Aitem
);
4538 Insert_Pragma
(Aitem
);
4541 -- Subprogram_Variant
4543 when Aspect_Subprogram_Variant
=>
4544 Aitem
:= Make_Aitem_Pragma
4545 (Pragma_Argument_Associations
=> New_List
(
4546 Make_Pragma_Argument_Association
(Loc
,
4547 Expression
=> Relocate_Node
(Expr
))),
4548 Pragma_Name
=> Name_Subprogram_Variant
);
4550 Decorate
(Aspect
, Aitem
);
4551 Insert_Pragma
(Aitem
);
4554 -- Case 5: Special handling for aspects with an optional
4555 -- boolean argument.
4557 -- In the delayed case, the corresponding pragma cannot be
4558 -- generated yet because the evaluation of the boolean needs
4559 -- to be delayed till the freeze point.
4561 when Boolean_Aspects
4562 | Library_Unit_Aspects
4564 Set_Is_Boolean_Aspect
(Aspect
);
4566 -- Lock_Free aspect only apply to protected objects
4568 if A_Id
= Aspect_Lock_Free
then
4569 if Ekind
(E
) /= E_Protected_Type
then
4570 Error_Msg_Name_1
:= Nam
;
4572 ("aspect % only applies to a protected type " &
4577 -- Set the Uses_Lock_Free flag to True if there is no
4578 -- expression or if the expression is True. The
4579 -- evaluation of this aspect should be delayed to the
4580 -- freeze point if we wanted to handle the corner case
4581 -- of "true" or "false" being redefined.
4584 or else Is_True
(Static_Boolean
(Expr
))
4586 Set_Uses_Lock_Free
(E
);
4589 Record_Rep_Item
(E
, Aspect
);
4594 elsif A_Id
in Aspect_Export | Aspect_Import
then
4595 Analyze_Aspect_Export_Import
;
4597 -- Disable_Controlled
4599 elsif A_Id
= Aspect_Disable_Controlled
then
4600 Analyze_Aspect_Disable_Controlled
;
4603 -- Ada 2022 (AI12-0129): Exclusive_Functions
4605 elsif A_Id
= Aspect_Exclusive_Functions
then
4606 if Ekind
(E
) /= E_Protected_Type
then
4607 Error_Msg_Name_1
:= Nam
;
4609 ("aspect % only applies to a protected type " &
4616 -- Ada 2022 (AI12-0363): Full_Access_Only
4618 elsif A_Id
= Aspect_Full_Access_Only
then
4619 Error_Msg_Ada_2022_Feature
("aspect %", Sloc
(Aspect
));
4621 -- Ada 2022 (AI12-0075): static expression functions
4623 elsif A_Id
= Aspect_Static
then
4624 Analyze_Aspect_Static
;
4627 -- Ada 2022 (AI12-0279)
4629 elsif A_Id
= Aspect_Yield
then
4630 Analyze_Aspect_Yield
;
4634 -- Library unit aspects require special handling in the case
4635 -- of a package declaration, the pragma needs to be inserted
4636 -- in the list of declarations for the associated package.
4637 -- There is no issue of visibility delay for these aspects.
4639 if A_Id
in Library_Unit_Aspects
4641 Nkind
(N
) in N_Package_Declaration
4642 | N_Generic_Package_Declaration
4643 and then Nkind
(Parent
(N
)) /= N_Compilation_Unit
4645 -- Aspect is legal on a local instantiation of a library-
4646 -- level generic unit.
4648 and then not Is_Generic_Instance
(Defining_Entity
(N
))
4651 ("incorrect context for library unit aspect&", Id
);
4655 -- Cases where we do not delay
4657 if not Delay_Required
then
4659 -- Exclude aspects Export and Import because their pragma
4660 -- syntax does not map directly to a Boolean aspect.
4662 if A_Id
not in Aspect_Export | Aspect_Import
then
4663 Aitem
:= Make_Aitem_Pragma
4664 (Pragma_Argument_Associations
=> New_List
(
4665 Make_Pragma_Argument_Association
(Sloc
(Ent
),
4666 Expression
=> Ent
)),
4667 Pragma_Name
=> Nam
);
4670 -- In general cases, the corresponding pragma/attribute
4671 -- definition clause will be inserted later at the freezing
4672 -- point, and we do not need to build it now.
4680 -- This is special because for access types we need to generate
4681 -- an attribute definition clause. This also works for single
4682 -- task declarations, but it does not work for task type
4683 -- declarations, because we have the case where the expression
4684 -- references a discriminant of the task type. That can't use
4685 -- an attribute definition clause because we would not have
4686 -- visibility on the discriminant. For that case we must
4687 -- generate a pragma in the task definition.
4689 when Aspect_Storage_Size
=>
4693 if Ekind
(E
) = E_Task_Type
then
4695 Decl
: constant Node_Id
:= Declaration_Node
(E
);
4698 pragma Assert
(Nkind
(Decl
) = N_Task_Type_Declaration
);
4700 -- If no task definition, create one
4702 if No
(Task_Definition
(Decl
)) then
4703 Set_Task_Definition
(Decl
,
4704 Make_Task_Definition
(Loc
,
4705 Visible_Declarations
=> Empty_List
,
4706 End_Label
=> Empty
));
4709 -- Create a pragma and put it at the start of the task
4710 -- definition for the task type declaration.
4712 Aitem
:= Make_Aitem_Pragma
4713 (Pragma_Argument_Associations
=> New_List
(
4714 Make_Pragma_Argument_Association
(Loc
,
4715 Expression
=> Relocate_Node
(Expr
))),
4716 Pragma_Name
=> Name_Storage_Size
);
4720 Visible_Declarations
(Task_Definition
(Decl
)));
4724 -- All other cases, generate attribute definition
4728 Make_Attribute_Definition_Clause
(Loc
,
4730 Chars
=> Name_Storage_Size
,
4731 Expression
=> Relocate_Node
(Expr
));
4735 -- Attach the corresponding pragma/attribute definition clause to
4736 -- the aspect specification node.
4738 if Present
(Aitem
) then
4739 Set_From_Aspect_Specification
(Aitem
);
4742 -- For an aspect that applies to a type, indicate whether it
4743 -- appears on a partial view of the type.
4746 and then Is_Private_Type
(E
)
4748 Set_Aspect_On_Partial_View
(Aspect
);
4751 -- In the context of a compilation unit, we directly put the
4752 -- pragma in the Pragmas_After list of the N_Compilation_Unit_Aux
4753 -- node (no delay is required here) except for aspects on a
4754 -- subprogram body (see below) and a generic package, for which we
4755 -- need to introduce the pragma before building the generic copy
4756 -- (see sem_ch12), and for package instantiations, where the
4757 -- library unit pragmas are better handled early.
4759 if Nkind
(Parent
(N
)) = N_Compilation_Unit
4760 and then (Present
(Aitem
) or else Is_Boolean_Aspect
(Aspect
))
4763 Aux
: constant Node_Id
:= Aux_Decls_Node
(Parent
(N
));
4766 pragma Assert
(Nkind
(Aux
) = N_Compilation_Unit_Aux
);
4768 -- For a Boolean aspect, create the corresponding pragma if
4769 -- no expression or if the value is True.
4771 if Is_Boolean_Aspect
(Aspect
) and then No
(Aitem
) then
4772 if Is_True
(Static_Boolean
(Expr
)) then
4773 Aitem
:= Make_Aitem_Pragma
4774 (Pragma_Argument_Associations
=> New_List
(
4775 Make_Pragma_Argument_Association
(Sloc
(Ent
),
4776 Expression
=> Ent
)),
4777 Pragma_Name
=> Nam
);
4779 Set_From_Aspect_Specification
(Aitem
, True);
4780 Set_Corresponding_Aspect
(Aitem
, Aspect
);
4787 -- If the aspect is on a subprogram body (relevant aspect
4788 -- is Inline), add the pragma in front of the declarations.
4790 if Nkind
(N
) = N_Subprogram_Body
then
4791 if No
(Declarations
(N
)) then
4792 Set_Declarations
(N
, New_List
);
4795 Prepend
(Aitem
, Declarations
(N
));
4797 elsif Nkind
(N
) = N_Generic_Package_Declaration
then
4798 if No
(Visible_Declarations
(Specification
(N
))) then
4799 Set_Visible_Declarations
(Specification
(N
), New_List
);
4803 Visible_Declarations
(Specification
(N
)));
4805 elsif Nkind
(N
) = N_Package_Instantiation
then
4807 Spec
: constant Node_Id
:=
4808 Specification
(Instance_Spec
(N
));
4810 if No
(Visible_Declarations
(Spec
)) then
4811 Set_Visible_Declarations
(Spec
, New_List
);
4814 Prepend
(Aitem
, Visible_Declarations
(Spec
));
4818 if No
(Pragmas_After
(Aux
)) then
4819 Set_Pragmas_After
(Aux
, New_List
);
4822 Append
(Aitem
, Pragmas_After
(Aux
));
4829 -- The evaluation of the aspect is delayed to the freezing point.
4830 -- The pragma or attribute clause if there is one is then attached
4831 -- to the aspect specification which is put in the rep item list.
4833 if Delay_Required
then
4834 if Present
(Aitem
) then
4835 Set_Is_Delayed_Aspect
(Aitem
);
4836 Set_Aspect_Rep_Item
(Aspect
, Aitem
);
4837 Set_Parent
(Aitem
, Aspect
);
4840 Set_Is_Delayed_Aspect
(Aspect
);
4842 -- In the case of Default_Value, link the aspect to base type
4843 -- as well, even though it appears on a first subtype. This is
4844 -- mandated by the semantics of the aspect. Do not establish
4845 -- the link when processing the base type itself as this leads
4846 -- to a rep item circularity.
4848 if A_Id
= Aspect_Default_Value
and then Base_Type
(E
) /= E
then
4849 Set_Has_Delayed_Aspects
(Base_Type
(E
));
4850 Record_Rep_Item
(Base_Type
(E
), Aspect
);
4853 Set_Has_Delayed_Aspects
(E
);
4854 Record_Rep_Item
(E
, Aspect
);
4856 -- When delay is not required and the context is a package or a
4857 -- subprogram body, insert the pragma in the body declarations.
4859 elsif Nkind
(N
) in N_Package_Body | N_Subprogram_Body
then
4860 if No
(Declarations
(N
)) then
4861 Set_Declarations
(N
, New_List
);
4864 -- The pragma is added before source declarations
4866 Prepend_To
(Declarations
(N
), Aitem
);
4868 -- When delay is not required and the context is not a compilation
4869 -- unit, we simply insert the pragma/attribute definition clause
4872 elsif Present
(Aitem
) then
4873 Insert_After
(Ins_Node
, Aitem
);
4879 -- If a nonoverridable aspect is explicitly specified for a
4880 -- derived type, then check consistency with the parent type.
4882 if A_Id
in Nonoverridable_Aspect_Id
4883 and then Nkind
(N
) = N_Full_Type_Declaration
4884 and then Nkind
(Type_Definition
(N
)) = N_Derived_Type_Definition
4885 and then not In_Instance_Body
4888 Parent_Type
: constant Entity_Id
:= Etype
(E
);
4889 Inherited_Aspect
: constant Node_Id
:=
4890 Find_Aspect
(Parent_Type
, A_Id
);
4892 if Present
(Inherited_Aspect
)
4893 and then not Is_Confirming
4894 (A_Id
, Inherited_Aspect
, Aspect
)
4896 Error_Msg_Name_1
:= Aspect_Names
(A_Id
);
4897 Error_Msg_Sloc
:= Sloc
(Inherited_Aspect
);
4900 ("overriding aspect specification for "
4901 & "nonoverridable aspect % does not confirm "
4902 & "aspect specification inherited from #",
4908 when Aspect_Exit
=> null;
4909 end Analyze_One_Aspect
;
4912 end loop Aspect_Loop
;
4914 if Has_Delayed_Aspects
(E
) then
4915 Ensure_Freeze_Node
(E
);
4917 end Analyze_Aspect_Specifications
;
4919 ------------------------------------------------
4920 -- Analyze_Aspects_On_Subprogram_Body_Or_Stub --
4921 ------------------------------------------------
4923 procedure Analyze_Aspects_On_Subprogram_Body_Or_Stub
(N
: Node_Id
) is
4924 Body_Id
: constant Entity_Id
:= Defining_Entity
(N
);
4926 procedure Diagnose_Misplaced_Aspects
(Spec_Id
: Entity_Id
);
4927 -- Body [stub] N has aspects, but they are not properly placed. Emit an
4928 -- error message depending on the aspects involved. Spec_Id denotes the
4929 -- entity of the corresponding spec.
4931 --------------------------------
4932 -- Diagnose_Misplaced_Aspects --
4933 --------------------------------
4935 procedure Diagnose_Misplaced_Aspects
(Spec_Id
: Entity_Id
) is
4936 procedure Misplaced_Aspect_Error
4939 -- Emit an error message concerning misplaced aspect Asp. Ref_Nam is
4940 -- the name of the refined version of the aspect.
4942 ----------------------------
4943 -- Misplaced_Aspect_Error --
4944 ----------------------------
4946 procedure Misplaced_Aspect_Error
4950 Asp_Nam
: constant Name_Id
:= Chars
(Identifier
(Asp
));
4951 Asp_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Asp_Nam
);
4954 -- The corresponding spec already contains the aspect in question
4955 -- and the one appearing on the body must be the refined form:
4957 -- procedure P with Global ...;
4958 -- procedure P with Global ... is ... end P;
4962 if Has_Aspect
(Spec_Id
, Asp_Id
) then
4963 Error_Msg_Name_1
:= Asp_Nam
;
4965 -- Subunits cannot carry aspects that apply to a subprogram
4968 if Nkind
(Parent
(N
)) = N_Subunit
then
4969 Error_Msg_N
("aspect % cannot apply to a subunit", Asp
);
4971 -- Otherwise suggest the refined form
4974 Error_Msg_Name_2
:= Ref_Nam
;
4975 Error_Msg_N
("aspect % should be %", Asp
);
4978 -- Otherwise the aspect must appear on the spec, not on the body
4981 -- procedure P with Global ... is ... end P;
4985 ("aspect specification must appear on initial declaration",
4988 end Misplaced_Aspect_Error
;
4995 -- Start of processing for Diagnose_Misplaced_Aspects
4998 -- Iterate over the aspect specifications and emit specific errors
4999 -- where applicable.
5001 Asp
:= First
(Aspect_Specifications
(N
));
5002 while Present
(Asp
) loop
5003 Asp_Nam
:= Chars
(Identifier
(Asp
));
5005 -- Do not emit errors on aspects that can appear on a subprogram
5006 -- body. This scenario occurs when the aspect specification list
5007 -- contains both misplaced and properly placed aspects.
5009 if Aspect_On_Body_Or_Stub_OK
(Get_Aspect_Id
(Asp_Nam
)) then
5012 -- Special diagnostics for SPARK aspects
5014 elsif Asp_Nam
= Name_Depends
then
5015 Misplaced_Aspect_Error
(Asp
, Name_Refined_Depends
);
5017 elsif Asp_Nam
= Name_Global
then
5018 Misplaced_Aspect_Error
(Asp
, Name_Refined_Global
);
5020 elsif Asp_Nam
= Name_Post
then
5021 Misplaced_Aspect_Error
(Asp
, Name_Refined_Post
);
5023 -- Otherwise a language-defined aspect is misplaced
5027 ("aspect specification must appear on initial declaration",
5033 end Diagnose_Misplaced_Aspects
;
5037 Spec_Id
: constant Entity_Id
:= Unique_Defining_Entity
(N
);
5039 -- Start of processing for Analyze_Aspects_On_Subprogram_Body_Or_Stub
5042 -- Language-defined aspects cannot be associated with a subprogram body
5043 -- [stub] if the subprogram has a spec. Certain implementation defined
5044 -- aspects are allowed to break this rule (for all applicable cases, see
5045 -- table Aspects.Aspect_On_Body_Or_Stub_OK).
5047 if Spec_Id
/= Body_Id
and then not Aspects_On_Body_Or_Stub_OK
(N
) then
5048 Diagnose_Misplaced_Aspects
(Spec_Id
);
5050 Analyze_Aspect_Specifications
(N
, Body_Id
);
5052 end Analyze_Aspects_On_Subprogram_Body_Or_Stub
;
5054 -----------------------
5055 -- Analyze_At_Clause --
5056 -----------------------
5058 -- An at clause is replaced by the corresponding Address attribute
5059 -- definition clause that is the preferred approach in Ada 95.
5061 procedure Analyze_At_Clause
(N
: Node_Id
) is
5062 CS
: constant Boolean := Comes_From_Source
(N
);
5065 -- This is an obsolescent feature
5067 Check_Restriction
(No_Obsolescent_Features
, N
);
5069 if Warn_On_Obsolescent_Feature
then
5071 ("?j?at clause is an obsolescent feature (RM J.7(2))", N
);
5073 ("\?j?use address attribute definition clause instead", N
);
5076 -- Rewrite as address clause
5079 Make_Attribute_Definition_Clause
(Sloc
(N
),
5080 Name
=> Identifier
(N
),
5081 Chars
=> Name_Address
,
5082 Expression
=> Expression
(N
)));
5084 -- We preserve Comes_From_Source, since logically the clause still comes
5085 -- from the source program even though it is changed in form.
5087 Set_Comes_From_Source
(N
, CS
);
5089 -- Analyze rewritten clause
5091 Analyze_Attribute_Definition_Clause
(N
);
5092 end Analyze_At_Clause
;
5094 -----------------------------------------
5095 -- Analyze_Attribute_Definition_Clause --
5096 -----------------------------------------
5098 procedure Analyze_Attribute_Definition_Clause
(N
: Node_Id
) is
5099 Loc
: constant Source_Ptr
:= Sloc
(N
);
5100 Nam
: constant Node_Id
:= Name
(N
);
5101 Attr
: constant Name_Id
:= Chars
(N
);
5102 Expr
: constant Node_Id
:= Expression
(N
);
5103 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Attr
);
5106 -- The entity of Nam after it is analyzed. In the case of an incomplete
5107 -- type, this is the underlying type.
5110 -- The underlying entity to which the attribute applies. Generally this
5111 -- is the Underlying_Type of Ent, except in the case where the clause
5112 -- applies to the full view of an incomplete or private type, in which
5113 -- case U_Ent is just a copy of Ent.
5115 FOnly
: Boolean := False;
5116 -- Reset to True for subtype specific attribute (Alignment, Size)
5117 -- and for stream attributes, i.e. those cases where in the call to
5118 -- Rep_Item_Too_Late, FOnly is set True so that only the freezing rules
5119 -- are checked. Note that the case of stream attributes is not clear
5120 -- from the RM, but see AI95-00137. Also, the RM seems to disallow
5121 -- Storage_Size for derived task types, but that is also clearly
5124 procedure Analyze_Put_Image_TSS_Definition
;
5126 procedure Analyze_Stream_TSS_Definition
(TSS_Nam
: TSS_Name_Type
);
5127 -- Common processing for 'Read, 'Write, 'Input and 'Output attribute
5128 -- definition clauses.
5130 function Duplicate_Clause
return Boolean;
5131 -- This routine checks if the aspect for U_Ent being given by attribute
5132 -- definition clause N is for an aspect that has already been specified,
5133 -- and if so gives an error message. If there is a duplicate, True is
5134 -- returned, otherwise there is no error, and False is returned. Size
5135 -- and Value_Size are considered to conflict, but for compatibility,
5136 -- this is merely a warning.
5138 procedure Check_Indexing_Functions
;
5139 -- Check that the function in Constant_Indexing or Variable_Indexing
5140 -- attribute has the proper type structure. If the name is overloaded,
5141 -- check that some interpretation is legal.
5143 procedure Check_Iterator_Functions
;
5144 -- Check that there is a single function in Default_Iterator attribute
5145 -- that has the proper type structure.
5147 function Check_Primitive_Function
(Subp
: Entity_Id
) return Boolean;
5148 -- Common legality check for the previous two
5150 -----------------------------------
5151 -- Analyze_Put_Image_TSS_Definition --
5152 -----------------------------------
5154 procedure Analyze_Put_Image_TSS_Definition
is
5155 Subp
: Entity_Id
:= Empty
;
5160 function Has_Good_Profile
5162 Report
: Boolean := False) return Boolean;
5163 -- Return true if the entity is a subprogram with an appropriate
5164 -- profile for the attribute being defined. If result is False and
5165 -- Report is True, function emits appropriate error.
5167 ----------------------
5168 -- Has_Good_Profile --
5169 ----------------------
5171 function Has_Good_Profile
5173 Report
: Boolean := False) return Boolean
5179 if Ekind
(Subp
) /= E_Procedure
then
5183 F
:= First_Formal
(Subp
);
5189 if Base_Type
(Etype
(F
))
5190 /= Class_Wide_Type
(RTE
(RE_Root_Buffer_Type
))
5194 ("wrong type for Put_Image procedure''s first parameter",
5195 Parameter_Type
(Parent
(F
)));
5201 if Parameter_Mode
(F
) /= E_In_Out_Parameter
then
5204 ("wrong mode for Put_Image procedure''s first parameter",
5215 -- Verify that the prefix of the attribute and the local name for
5216 -- the type of the formal match.
5218 if Base_Type
(Typ
) /= Base_Type
(Ent
) then
5221 ("wrong type for Put_Image procedure''s second parameter",
5222 Parameter_Type
(Parent
(F
)));
5228 if Parameter_Mode
(F
) /= E_In_Parameter
then
5231 ("wrong mode for Put_Image procedure''s second parameter",
5238 if Present
(Next_Formal
(F
)) then
5243 end Has_Good_Profile
;
5245 -- Start of processing for Analyze_Put_Image_TSS_Definition
5248 if not Is_Type
(U_Ent
) then
5249 Error_Msg_N
("local name must be a subtype", Nam
);
5252 elsif not Is_First_Subtype
(U_Ent
) then
5253 Error_Msg_N
("local name must be a first subtype", Nam
);
5257 Pnam
:= TSS
(Base_Type
(U_Ent
), TSS_Put_Image
);
5259 -- If Pnam is present, it can be either inherited from an ancestor
5260 -- type (in which case it is legal to redefine it for this type), or
5261 -- be a previous definition of the attribute for the same type (in
5262 -- which case it is illegal).
5264 -- In the first case, it will have been analyzed already, and we can
5265 -- check that its profile does not match the expected profile for the
5266 -- Put_Image attribute of U_Ent. In the second case, either Pnam has
5267 -- been analyzed (and has the expected profile), or it has not been
5268 -- analyzed yet (case of a type that has not been frozen yet and for
5269 -- which Put_Image has been set using Set_TSS).
5272 and then (No
(First_Entity
(Pnam
)) or else Has_Good_Profile
(Pnam
))
5274 Error_Msg_Sloc
:= Sloc
(Pnam
);
5275 Error_Msg_Name_1
:= Attr
;
5276 Error_Msg_N
("% attribute already defined #", Nam
);
5282 if Is_Entity_Name
(Expr
) then
5283 if not Is_Overloaded
(Expr
) then
5284 if Has_Good_Profile
(Entity
(Expr
), Report
=> True) then
5285 Subp
:= Entity
(Expr
);
5289 Get_First_Interp
(Expr
, I
, It
);
5290 while Present
(It
.Nam
) loop
5291 if Has_Good_Profile
(It
.Nam
) then
5296 Get_Next_Interp
(I
, It
);
5301 if Present
(Subp
) then
5302 if Is_Abstract_Subprogram
(Subp
) then
5303 Error_Msg_N
("Put_Image subprogram must not be abstract", Expr
);
5307 Set_Entity
(Expr
, Subp
);
5308 Set_Etype
(Expr
, Etype
(Subp
));
5310 New_Put_Image_Subprogram
(N
, U_Ent
, Subp
);
5313 Error_Msg_Name_1
:= Attr
;
5314 Error_Msg_N
("incorrect expression for% attribute", Expr
);
5316 end Analyze_Put_Image_TSS_Definition
;
5318 -----------------------------------
5319 -- Analyze_Stream_TSS_Definition --
5320 -----------------------------------
5322 procedure Analyze_Stream_TSS_Definition
(TSS_Nam
: TSS_Name_Type
) is
5323 Subp
: Entity_Id
:= Empty
;
5328 Is_Read
: constant Boolean := (TSS_Nam
= TSS_Stream_Read
);
5329 -- True for Read attribute, False for other attributes
5331 function Has_Good_Profile
5333 Report
: Boolean := False) return Boolean;
5334 -- Return true if the entity is a subprogram with an appropriate
5335 -- profile for the attribute being defined. If result is False and
5336 -- Report is True, function emits appropriate error.
5338 ----------------------
5339 -- Has_Good_Profile --
5340 ----------------------
5342 function Has_Good_Profile
5344 Report
: Boolean := False) return Boolean
5346 Expected_Ekind
: constant array (Boolean) of Entity_Kind
:=
5347 (False => E_Procedure
, True => E_Function
);
5348 Is_Function
: constant Boolean := (TSS_Nam
= TSS_Stream_Input
);
5353 if Ekind
(Subp
) /= Expected_Ekind
(Is_Function
) then
5357 F
:= First_Formal
(Subp
);
5360 or else Ekind
(Etype
(F
)) /= E_Anonymous_Access_Type
5361 or else Base_Type
(Designated_Type
(Etype
(F
))) /=
5362 Class_Wide_Type
(RTE
(RE_Root_Stream_Type
))
5367 if not Is_Function
then
5371 Expected_Mode
: constant array (Boolean) of Entity_Kind
:=
5372 (False => E_In_Parameter
,
5373 True => E_Out_Parameter
);
5375 if Parameter_Mode
(F
) /= Expected_Mode
(Is_Read
) then
5383 Typ
:= Etype
(Subp
);
5386 -- Verify that the prefix of the attribute and the local name for
5387 -- the type of the formal match.
5389 if Base_Type
(Typ
) /= Base_Type
(Ent
) then
5393 if Present
(Next_Formal
(F
)) then
5396 elsif not Is_Scalar_Type
(Typ
)
5397 and then not Is_First_Subtype
(Typ
)
5398 and then not Is_Class_Wide_Type
(Typ
)
5400 if Report
and not Is_First_Subtype
(Typ
) then
5402 ("subtype of formal in stream operation must be a first "
5403 & "subtype", Parameter_Type
(Parent
(F
)));
5411 end Has_Good_Profile
;
5413 -- Start of processing for Analyze_Stream_TSS_Definition
5418 if not Is_Type
(U_Ent
) then
5419 Error_Msg_N
("local name must be a subtype", Nam
);
5422 elsif not Is_First_Subtype
(U_Ent
) then
5423 Error_Msg_N
("local name must be a first subtype", Nam
);
5427 Pnam
:= TSS
(Base_Type
(U_Ent
), TSS_Nam
);
5429 -- If Pnam is present, it can be either inherited from an ancestor
5430 -- type (in which case it is legal to redefine it for this type), or
5431 -- be a previous definition of the attribute for the same type (in
5432 -- which case it is illegal).
5434 -- In the first case, it will have been analyzed already, and we
5435 -- can check that its profile does not match the expected profile
5436 -- for a stream attribute of U_Ent. In the second case, either Pnam
5437 -- has been analyzed (and has the expected profile), or it has not
5438 -- been analyzed yet (case of a type that has not been frozen yet
5439 -- and for which the stream attribute has been set using Set_TSS).
5442 and then (No
(First_Entity
(Pnam
)) or else Has_Good_Profile
(Pnam
))
5444 Error_Msg_Sloc
:= Sloc
(Pnam
);
5445 Error_Msg_Name_1
:= Attr
;
5446 Error_Msg_N
("% attribute already defined #", Nam
);
5452 if Is_Entity_Name
(Expr
) then
5453 if not Is_Overloaded
(Expr
) then
5454 if Has_Good_Profile
(Entity
(Expr
), Report
=> True) then
5455 Subp
:= Entity
(Expr
);
5459 Get_First_Interp
(Expr
, I
, It
);
5460 while Present
(It
.Nam
) loop
5461 if Has_Good_Profile
(It
.Nam
) then
5466 Get_Next_Interp
(I
, It
);
5471 if Present
(Subp
) then
5472 if Is_Abstract_Subprogram
(Subp
) then
5473 Error_Msg_N
("stream subprogram must not be abstract", Expr
);
5476 -- A stream subprogram for an interface type must be a null
5477 -- procedure (RM 13.13.2 (38/3)). Note that the class-wide type
5478 -- of an interface is not an interface type (3.9.4 (6.b/2)).
5480 elsif Is_Interface
(U_Ent
)
5481 and then not Is_Class_Wide_Type
(U_Ent
)
5482 and then not Inside_A_Generic
5484 (Ekind
(Subp
) = E_Function
5488 (Unit_Declaration_Node
(Ultimate_Alias
(Subp
)))))
5491 ("stream subprogram for interface type must be null "
5492 & "procedure", Expr
);
5495 Set_Entity
(Expr
, Subp
);
5496 Set_Etype
(Expr
, Etype
(Subp
));
5498 New_Stream_Subprogram
(N
, U_Ent
, Subp
, TSS_Nam
);
5501 Error_Msg_Name_1
:= Attr
;
5503 if Is_Class_Wide_Type
(Base_Type
(Ent
)) then
5505 ("incorrect expression for class-wide% attribute", Expr
);
5507 Error_Msg_N
("incorrect expression for% attribute", Expr
);
5510 end Analyze_Stream_TSS_Definition
;
5512 ------------------------------
5513 -- Check_Indexing_Functions --
5514 ------------------------------
5516 procedure Check_Indexing_Functions
is
5517 Indexing_Found
: Boolean := False;
5519 procedure Check_Inherited_Indexing
;
5520 -- For a derived type, check that for a derived type, a specification
5521 -- of an indexing aspect can only be confirming, i.e. uses the same
5522 -- name as in the parent type.
5523 -- AI12-0160: Verify that an indexing cannot be specified for
5524 -- a derived type unless it is specified for the parent.
5526 procedure Check_One_Function
(Subp
: Entity_Id
);
5527 -- Check one possible interpretation. Sets Indexing_Found True if a
5528 -- legal indexing function is found.
5530 procedure Illegal_Indexing
(Msg
: String);
5531 -- Diagnose illegal indexing function if not overloaded. In the
5532 -- overloaded case indicate that no legal interpretation exists.
5534 ------------------------------
5535 -- Check_Inherited_Indexing --
5536 ------------------------------
5538 procedure Check_Inherited_Indexing
is
5539 Inherited
: Node_Id
;
5540 Other_Indexing
: Node_Id
;
5543 if Attr
= Name_Constant_Indexing
then
5545 Find_Aspect
(Etype
(Ent
), Aspect_Constant_Indexing
);
5547 Find_Aspect
(Etype
(Ent
), Aspect_Variable_Indexing
);
5549 else pragma Assert
(Attr
= Name_Variable_Indexing
);
5551 Find_Aspect
(Etype
(Ent
), Aspect_Variable_Indexing
);
5553 Find_Aspect
(Etype
(Ent
), Aspect_Constant_Indexing
);
5556 if Present
(Inherited
) then
5557 if Debug_Flag_Dot_XX
then
5560 -- OK if current attribute_definition_clause is expansion of
5561 -- inherited aspect.
5563 elsif Aspect_Rep_Item
(Inherited
) = N
then
5566 -- Check if this is a confirming specification. The name
5567 -- may be overloaded between the parent operation and the
5568 -- inherited one, so we check that the Chars fields match.
5570 elsif Is_Entity_Name
(Expression
(Inherited
))
5571 and then Chars
(Entity
(Expression
(Inherited
))) =
5572 Chars
(Entity
(Expression
(N
)))
5574 Indexing_Found
:= True;
5576 -- Indicate the operation that must be overridden, rather than
5577 -- redefining the indexing aspect.
5581 ("indexing function already inherited from parent type");
5583 ("!override & instead",
5584 N
, Entity
(Expression
(Inherited
)));
5587 -- If not inherited and the parent has another indexing function
5588 -- this is illegal, because it leads to inconsistent results in
5589 -- class-wide calls.
5591 elsif Present
(Other_Indexing
) then
5593 ("cannot specify indexing operation on derived type"
5594 & " if not specified for parent", N
);
5596 end Check_Inherited_Indexing
;
5598 ------------------------
5599 -- Check_One_Function --
5600 ------------------------
5602 procedure Check_One_Function
(Subp
: Entity_Id
) is
5603 Default_Element
: Node_Id
;
5604 Ret_Type
: constant Entity_Id
:= Etype
(Subp
);
5607 if not Is_Overloadable
(Subp
) then
5608 Illegal_Indexing
("illegal indexing function for type&");
5611 elsif Scope
(Subp
) /= Scope
(Ent
) then
5612 if Nkind
(Expr
) = N_Expanded_Name
then
5614 -- Indexing function can't be declared elsewhere
5617 ("indexing function must be declared"
5618 & " in scope of type&");
5621 if Is_Derived_Type
(Ent
) then
5622 Check_Inherited_Indexing
;
5627 elsif No
(First_Formal
(Subp
)) then
5629 ("Indexing requires a function that applies to type&");
5632 elsif No
(Next_Formal
(First_Formal
(Subp
))) then
5634 ("indexing function must have at least two parameters");
5637 elsif Is_Derived_Type
(Ent
) then
5638 Check_Inherited_Indexing
;
5641 if not Check_Primitive_Function
(Subp
) then
5643 ("Indexing aspect requires a function that applies to type&");
5647 -- If partial declaration exists, verify that it is not tagged.
5649 if Ekind
(Current_Scope
) = E_Package
5650 and then Has_Private_Declaration
(Ent
)
5651 and then From_Aspect_Specification
(N
)
5653 List_Containing
(Parent
(Ent
)) =
5654 Private_Declarations
5655 (Specification
(Unit_Declaration_Node
(Current_Scope
)))
5656 and then Nkind
(N
) = N_Attribute_Definition_Clause
5663 First
(Visible_Declarations
5665 (Unit_Declaration_Node
(Current_Scope
))));
5667 while Present
(Decl
) loop
5668 if Nkind
(Decl
) = N_Private_Type_Declaration
5669 and then Ent
= Full_View
(Defining_Identifier
(Decl
))
5670 and then Tagged_Present
(Decl
)
5671 and then No
(Aspect_Specifications
(Decl
))
5674 ("Indexing aspect cannot be specified on full view "
5675 & "if partial view is tagged");
5684 -- An indexing function must return either the default element of
5685 -- the container, or a reference type. For variable indexing it
5686 -- must be the latter.
5689 Find_Value_Of_Aspect
5690 (Etype
(First_Formal
(Subp
)), Aspect_Iterator_Element
);
5692 if Present
(Default_Element
) then
5693 Analyze
(Default_Element
);
5696 -- For variable_indexing the return type must be a reference type
5698 if Attr
= Name_Variable_Indexing
then
5699 if not Has_Implicit_Dereference
(Ret_Type
) then
5701 ("variable indexing must return a reference type");
5704 elsif Is_Access_Constant
5705 (Etype
(First_Discriminant
(Ret_Type
)))
5708 ("variable indexing must return an access to variable");
5713 if Has_Implicit_Dereference
(Ret_Type
)
5716 (Etype
(Get_Reference_Discriminant
(Ret_Type
)))
5719 ("constant indexing must return an access to constant");
5722 elsif Is_Access_Type
(Etype
(First_Formal
(Subp
)))
5723 and then not Is_Access_Constant
(Etype
(First_Formal
(Subp
)))
5726 ("constant indexing must apply to an access to constant");
5731 -- All checks succeeded
5733 Indexing_Found
:= True;
5734 end Check_One_Function
;
5736 -----------------------
5737 -- Illegal_Indexing --
5738 -----------------------
5740 procedure Illegal_Indexing
(Msg
: String) is
5742 Error_Msg_NE
(Msg
, N
, Ent
);
5743 end Illegal_Indexing
;
5745 -- Start of processing for Check_Indexing_Functions
5749 Check_Inherited_Indexing
;
5754 if not Is_Overloaded
(Expr
) then
5755 Check_One_Function
(Entity
(Expr
));
5763 Indexing_Found
:= False;
5764 Get_First_Interp
(Expr
, I
, It
);
5765 while Present
(It
.Nam
) loop
5767 -- Note that analysis will have added the interpretation
5768 -- that corresponds to the dereference. We only check the
5769 -- subprogram itself. Ignore homonyms that may come from
5770 -- derived types in the context.
5772 if Is_Overloadable
(It
.Nam
)
5773 and then Comes_From_Source
(It
.Nam
)
5775 Check_One_Function
(It
.Nam
);
5778 Get_Next_Interp
(I
, It
);
5783 if not Indexing_Found
and then not Error_Posted
(N
) then
5785 ("aspect Indexing requires a local function that applies to "
5786 & "type&", Expr
, Ent
);
5788 end Check_Indexing_Functions
;
5790 ------------------------------
5791 -- Check_Iterator_Functions --
5792 ------------------------------
5794 procedure Check_Iterator_Functions
is
5795 function Valid_Default_Iterator
(Subp
: Entity_Id
) return Boolean;
5796 -- Check one possible interpretation for validity
5798 ----------------------------
5799 -- Valid_Default_Iterator --
5800 ----------------------------
5802 function Valid_Default_Iterator
(Subp
: Entity_Id
) return Boolean is
5803 Root_T
: constant Entity_Id
:= Root_Type
(Etype
(Etype
(Subp
)));
5807 if not Check_Primitive_Function
(Subp
) then
5810 -- The return type must be derived from a type in an instance
5811 -- of Iterator.Interfaces, and thus its root type must have a
5814 elsif Chars
(Root_T
) /= Name_Forward_Iterator
5815 and then Chars
(Root_T
) /= Name_Reversible_Iterator
5820 Formal
:= First_Formal
(Subp
);
5823 -- False if any subsequent formal has no default expression
5825 Next_Formal
(Formal
);
5826 while Present
(Formal
) loop
5827 if No
(Expression
(Parent
(Formal
))) then
5831 Next_Formal
(Formal
);
5834 -- True if all subsequent formals have default expressions
5837 end Valid_Default_Iterator
;
5839 -- Start of processing for Check_Iterator_Functions
5844 if not Is_Entity_Name
(Expr
) then
5845 Error_Msg_N
("aspect Iterator must be a function name", Expr
);
5848 if not Is_Overloaded
(Expr
) then
5849 if Entity
(Expr
) /= Any_Id
5850 and then not Check_Primitive_Function
(Entity
(Expr
))
5853 ("aspect Indexing requires a function that applies to type&",
5854 Entity
(Expr
), Ent
);
5857 -- Flag the default_iterator as well as the denoted function.
5859 if not Valid_Default_Iterator
(Entity
(Expr
)) then
5860 Error_Msg_N
("improper function for default iterator!", Expr
);
5865 Default
: Entity_Id
:= Empty
;
5870 Get_First_Interp
(Expr
, I
, It
);
5871 while Present
(It
.Nam
) loop
5872 if not Check_Primitive_Function
(It
.Nam
)
5873 or else not Valid_Default_Iterator
(It
.Nam
)
5877 elsif Present
(Default
) then
5879 -- An explicit one should override an implicit one
5881 if Comes_From_Source
(Default
) =
5882 Comes_From_Source
(It
.Nam
)
5884 Error_Msg_N
("default iterator must be unique", Expr
);
5885 Error_Msg_Sloc
:= Sloc
(Default
);
5886 Error_Msg_N
("\\possible interpretation#", Expr
);
5887 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
5888 Error_Msg_N
("\\possible interpretation#", Expr
);
5890 elsif Comes_From_Source
(It
.Nam
) then
5897 Get_Next_Interp
(I
, It
);
5900 if Present
(Default
) then
5901 Set_Entity
(Expr
, Default
);
5902 Set_Is_Overloaded
(Expr
, False);
5905 ("no interpretation is a valid default iterator!", Expr
);
5909 end Check_Iterator_Functions
;
5911 -------------------------------
5912 -- Check_Primitive_Function --
5913 -------------------------------
5915 function Check_Primitive_Function
(Subp
: Entity_Id
) return Boolean is
5919 if Ekind
(Subp
) /= E_Function
then
5923 if No
(First_Formal
(Subp
)) then
5926 Ctrl
:= Etype
(First_Formal
(Subp
));
5929 -- To be a primitive operation subprogram has to be in same scope.
5931 if Scope
(Ctrl
) /= Scope
(Subp
) then
5935 -- Type of formal may be the class-wide type, an access to such,
5936 -- or an incomplete view.
5939 or else Ctrl
= Class_Wide_Type
(Ent
)
5941 (Ekind
(Ctrl
) = E_Anonymous_Access_Type
5942 and then (Designated_Type
(Ctrl
) = Ent
5944 Designated_Type
(Ctrl
) = Class_Wide_Type
(Ent
)))
5946 (Ekind
(Ctrl
) = E_Incomplete_Type
5947 and then Full_View
(Ctrl
) = Ent
)
5955 end Check_Primitive_Function
;
5957 ----------------------
5958 -- Duplicate_Clause --
5959 ----------------------
5961 function Duplicate_Clause
return Boolean is
5963 function Check_One_Attr
(Attr_1
, Attr_2
: Name_Id
) return Boolean;
5964 -- Check for one attribute; Attr_1 is the attribute_designator we are
5965 -- looking for. Attr_2 is the attribute_designator of the current
5966 -- node. Normally, this is called just once by Duplicate_Clause, with
5967 -- Attr_1 = Attr_2. However, it needs to be called twice for Size and
5968 -- Value_Size, because these mean the same thing. For compatibility,
5969 -- we allow specifying both Size and Value_Size, but only if the two
5972 --------------------
5973 -- Check_One_Attr --
5974 --------------------
5976 function Check_One_Attr
(Attr_1
, Attr_2
: Name_Id
) return Boolean is
5977 A
: constant Node_Id
:=
5978 Get_Rep_Item
(U_Ent
, Attr_1
, Check_Parents
=> False);
5981 if Attr_1
= Attr_2
then
5982 Error_Msg_Name_1
:= Attr_1
;
5983 Error_Msg_Sloc
:= Sloc
(A
);
5984 Error_Msg_NE
("aspect% for & previously given#", N
, U_Ent
);
5987 pragma Assert
(Attr_1
in Name_Size | Name_Value_Size
);
5988 pragma Assert
(Attr_2
in Name_Size | Name_Value_Size
);
5990 Error_Msg_Name_1
:= Attr_2
;
5991 Error_Msg_Name_2
:= Attr_1
;
5992 Error_Msg_Sloc
:= Sloc
(A
);
5993 Error_Msg_NE
("?% for & conflicts with % #", N
, U_Ent
);
6002 -- Start of processing for Duplicate_Clause
6005 -- Nothing to do if this attribute definition clause comes from
6006 -- an aspect specification, since we could not be duplicating an
6007 -- explicit clause, and we dealt with the case of duplicated aspects
6008 -- in Analyze_Aspect_Specifications.
6010 if From_Aspect_Specification
(N
) then
6014 -- Special cases for Size and Value_Size
6016 if (Chars
(N
) = Name_Size
6017 and then Check_One_Attr
(Name_Value_Size
, Name_Size
))
6019 (Chars
(N
) = Name_Value_Size
6020 and then Check_One_Attr
(Name_Size
, Name_Value_Size
))
6025 -- Normal case (including Size and Value_Size)
6027 return Check_One_Attr
(Chars
(N
), Chars
(N
));
6028 end Duplicate_Clause
;
6030 -- Start of processing for Analyze_Attribute_Definition_Clause
6033 -- The following code is a defense against recursion. Not clear that
6034 -- this can happen legitimately, but perhaps some error situations can
6035 -- cause it, and we did see this recursion during testing.
6037 if Analyzed
(N
) then
6040 Set_Analyzed
(N
, True);
6043 Check_Restriction_No_Use_Of_Attribute
(N
);
6045 if Is_Aspect_Id
(Chars
(N
)) then
6046 -- 6.1/3 No_Specification_of_Aspect: Identifies an aspect for which
6047 -- no aspect_specification, attribute_definition_clause, or pragma
6049 Check_Restriction_No_Specification_Of_Aspect
(N
);
6052 -- Ignore some selected attributes in CodePeer mode since they are not
6053 -- relevant in this context.
6055 if CodePeer_Mode
then
6058 -- Ignore Component_Size in CodePeer mode, to avoid changing the
6059 -- internal representation of types by implicitly packing them.
6061 when Attribute_Component_Size
=>
6062 Rewrite
(N
, Make_Null_Statement
(Sloc
(N
)));
6070 -- Process Ignore_Rep_Clauses option
6072 if Ignore_Rep_Clauses
then
6075 -- The following should be ignored. They do not affect legality
6076 -- and may be target dependent. The basic idea of -gnatI is to
6077 -- ignore any rep clauses that may be target dependent but do not
6078 -- affect legality (except possibly to be rejected because they
6079 -- are incompatible with the compilation target).
6081 when Attribute_Alignment
6082 | Attribute_Bit_Order
6083 | Attribute_Component_Size
6084 | Attribute_Default_Scalar_Storage_Order
6085 | Attribute_Machine_Radix
6086 | Attribute_Object_Size
6087 | Attribute_Scalar_Storage_Order
6090 | Attribute_Stream_Size
6091 | Attribute_Value_Size
6093 Kill_Rep_Clause
(N
);
6096 -- The following should not be ignored, because in the first place
6097 -- they are reasonably portable, and should not cause problems
6098 -- in compiling code from another target, and also they do affect
6099 -- legality, e.g. failing to provide a stream attribute for a type
6100 -- may make a program illegal.
6102 when Attribute_External_Tag
6105 | Attribute_Put_Image
6107 | Attribute_Simple_Storage_Pool
6108 | Attribute_Storage_Pool
6109 | Attribute_Storage_Size
6114 -- We do not do anything here with address clauses, they will be
6115 -- removed by Freeze later on, but for now, it works better to
6116 -- keep them in the tree.
6118 when Attribute_Address
=>
6121 -- Other cases are errors ("attribute& cannot be set with
6122 -- definition clause"), which will be caught below.
6130 Ent
:= Entity
(Nam
);
6132 if Rep_Item_Too_Early
(Ent
, N
) then
6136 -- Rep clause applies to (underlying) full view of private or incomplete
6137 -- type if we have one (if not, this is a premature use of the type).
6138 -- However, some semantic checks need to be done on the specified entity
6139 -- i.e. the private view, so we save it in Ent.
6141 if Is_Private_Type
(Ent
)
6142 and then Is_Derived_Type
(Ent
)
6143 and then not Is_Tagged_Type
(Ent
)
6144 and then No
(Full_View
(Ent
))
6145 and then No
(Underlying_Full_View
(Ent
))
6149 elsif Ekind
(Ent
) = E_Incomplete_Type
then
6151 -- The attribute applies to the full view, set the entity of the
6152 -- attribute definition accordingly.
6154 Ent
:= Underlying_Type
(Ent
);
6156 Set_Entity
(Nam
, Ent
);
6159 U_Ent
:= Underlying_Type
(Ent
);
6162 -- Avoid cascaded error
6164 if Etype
(Nam
) = Any_Type
then
6167 -- Must be declared in current scope or in case of an aspect
6168 -- specification, must be visible in current scope.
6170 elsif Scope
(Ent
) /= Current_Scope
6172 not (From_Aspect_Specification
(N
)
6173 and then Scope_Within_Or_Same
(Current_Scope
, Scope
(Ent
)))
6175 Error_Msg_N
("entity must be declared in this scope", Nam
);
6178 -- Must not be a source renaming (we do have some cases where the
6179 -- expander generates a renaming, and those cases are OK, in such
6180 -- cases any attribute applies to the renamed object as well).
6182 elsif Is_Object
(Ent
)
6183 and then Present
(Renamed_Object
(Ent
))
6185 -- In the case of a renamed object from source, this is an error
6186 -- unless the object is an aggregate and the renaming is created
6187 -- for an object declaration.
6189 if Comes_From_Source
(Renamed_Object
(Ent
))
6190 and then Nkind
(Renamed_Object
(Ent
)) /= N_Aggregate
6192 Get_Name_String
(Chars
(N
));
6193 Error_Msg_Strlen
:= Name_Len
;
6194 Error_Msg_String
(1 .. Name_Len
) := Name_Buffer
(1 .. Name_Len
);
6196 ("~ clause not allowed for a renaming declaration "
6197 & "(RM 13.1(6))", Nam
);
6200 -- For the case of a compiler generated renaming, the attribute
6201 -- definition clause applies to the renamed object created by the
6202 -- expander. The easiest general way to handle this is to create a
6203 -- copy of the attribute definition clause for this object.
6205 elsif Is_Entity_Name
(Renamed_Object
(Ent
)) then
6207 Make_Attribute_Definition_Clause
(Loc
,
6209 New_Occurrence_Of
(Entity
(Renamed_Object
(Ent
)), Loc
),
6211 Expression
=> Duplicate_Subexpr
(Expression
(N
))));
6213 -- If the renamed object is not an entity, it must be a dereference
6214 -- of an unconstrained function call, and we must introduce a new
6215 -- declaration to capture the expression. This is needed in the case
6216 -- of 'Alignment, where the original declaration must be rewritten.
6220 (Nkind
(Renamed_Object
(Ent
)) = N_Explicit_Dereference
);
6224 -- If no underlying entity, use entity itself, applies to some
6225 -- previously detected error cases ???
6227 elsif No
(U_Ent
) then
6230 -- Cannot specify for a subtype (exception Object/Value_Size)
6232 elsif Is_Type
(U_Ent
)
6233 and then not Is_First_Subtype
(U_Ent
)
6234 and then Id
/= Attribute_Object_Size
6235 and then Id
/= Attribute_Value_Size
6236 and then not From_At_Mod
(N
)
6238 Error_Msg_N
("cannot specify attribute for subtype", Nam
);
6242 Set_Entity
(N
, U_Ent
);
6244 -- Switch on particular attribute
6252 -- Address attribute definition clause
6254 when Attribute_Address
=> Address
: begin
6256 -- A little error check, catch for X'Address use X'Address;
6258 if Nkind
(Nam
) = N_Identifier
6259 and then Nkind
(Expr
) = N_Attribute_Reference
6260 and then Attribute_Name
(Expr
) = Name_Address
6261 and then Nkind
(Prefix
(Expr
)) = N_Identifier
6262 and then Chars
(Nam
) = Chars
(Prefix
(Expr
))
6265 ("address for & is self-referencing", Prefix
(Expr
), Ent
);
6269 -- Not that special case, carry on with analysis of expression
6271 Analyze_And_Resolve
(Expr
, RTE
(RE_Address
));
6273 -- Even when ignoring rep clauses we need to indicate that the
6274 -- entity has an address clause and thus it is legal to declare
6275 -- it imported. Freeze will get rid of the address clause later.
6276 -- Also call Set_Address_Taken to indicate that an address clause
6277 -- was present, even if we are about to remove it.
6279 if Ignore_Rep_Clauses
then
6280 Set_Address_Taken
(U_Ent
);
6282 if Ekind
(U_Ent
) in E_Variable | E_Constant
then
6283 Record_Rep_Item
(U_Ent
, N
);
6289 if Duplicate_Clause
then
6292 -- Case of address clause for subprogram
6294 elsif Is_Subprogram
(U_Ent
) then
6295 if Has_Homonym
(U_Ent
) then
6297 ("address clause cannot be given for overloaded "
6298 & "subprogram", Nam
);
6302 -- For subprograms, all address clauses are permitted, and we
6303 -- mark the subprogram as having a deferred freeze so that Gigi
6304 -- will not elaborate it too soon.
6306 -- Above needs more comments, what is too soon about???
6308 Set_Has_Delayed_Freeze
(U_Ent
);
6310 -- Case of address clause for entry
6312 elsif Ekind
(U_Ent
) = E_Entry
then
6313 if Nkind
(Parent
(N
)) = N_Task_Body
then
6315 ("entry address must be specified in task spec", Nam
);
6319 -- For entries, we require a constant address
6321 Check_Constant_Address_Clause
(Expr
, U_Ent
);
6323 -- Special checks for task types
6325 if Is_Task_Type
(Scope
(U_Ent
))
6326 and then Comes_From_Source
(Scope
(U_Ent
))
6329 ("??entry address declared for entry in task type", N
);
6331 ("\??only one task can be declared of this type", N
);
6334 -- Entry address clauses are obsolescent
6336 Check_Restriction
(No_Obsolescent_Features
, N
);
6338 if Warn_On_Obsolescent_Feature
then
6340 ("?j?attaching interrupt to task entry is an obsolescent "
6341 & "feature (RM J.7.1)", N
);
6343 ("\?j?use interrupt procedure instead", N
);
6346 -- Case of address clause for an object
6348 elsif Ekind
(U_Ent
) in E_Constant | E_Variable
then
6350 -- Disallow case of an address clause for an object of an
6351 -- indefinite subtype which takes its bounds/discriminant/tag
6352 -- from its initial value. Without this, we get a Gigi
6353 -- assertion failure for things like
6354 -- X : String := Some_Function (...) with Address => ...;
6355 -- where the result subtype of the function is unconstrained.
6357 -- We want to reject two cases: the class-wide case, and the
6358 -- case where the FE conjures up a renaming declaration and
6359 -- would then otherwise generate an address specification for
6360 -- that renaming (which is a malformed tree, which is why Gigi
6363 if Is_Class_Wide_Type
(Etype
(U_Ent
)) then
6365 ("address specification not supported for class-wide " &
6366 "object declaration", Nam
);
6368 elsif Is_Constr_Subt_For_U_Nominal
(Etype
(U_Ent
))
6370 Nkind
(Parent
(U_Ent
)) = N_Object_Renaming_Declaration
6372 -- Confirm accuracy of " and dynamic size" message text
6373 -- before including it. We want to include that text when
6374 -- it is correct because it may be useful to the reader.
6375 -- The case where we omit that part of the message text
6376 -- might be dead code, but let's not rely on that.
6379 ("address specification not supported for object " &
6380 "declaration with indefinite nominal subtype" &
6381 (if Size_Known_At_Compile_Time
(Etype
(U_Ent
))
6383 else " and dynamic size"), Nam
);
6388 Expr
: constant Node_Id
:= Expression
(N
);
6393 -- Exported variables cannot have an address clause, because
6394 -- this cancels the effect of the pragma Export.
6396 if Is_Exported
(U_Ent
) then
6398 ("cannot export object with address clause", Nam
);
6402 Find_Overlaid_Entity
(N
, O_Ent
, Off
);
6404 if Present
(O_Ent
) then
6406 -- If the object overlays a constant object, mark it so
6408 if Is_Constant_Object
(O_Ent
) then
6409 Set_Overlays_Constant
(U_Ent
);
6412 -- If the address clause is of the form:
6414 -- for X'Address use Y'Address;
6418 -- C : constant Address := Y'Address;
6420 -- for X'Address use C;
6422 -- then we make an entry in the table to check the size
6423 -- and alignment of the overlaying variable. But we defer
6424 -- this check till after code generation to take full
6425 -- advantage of the annotation done by the back end.
6427 -- If the entity has a generic type, the check will be
6428 -- performed in the instance if the actual type justifies
6429 -- it, and we do not insert the clause in the table to
6430 -- prevent spurious warnings.
6432 -- Note: we used to test Comes_From_Source and only give
6433 -- this warning for source entities, but we have removed
6434 -- this test. It really seems bogus to generate overlays
6435 -- that would trigger this warning in generated code.
6436 -- Furthermore, by removing the test, we handle the
6437 -- aspect case properly.
6439 if Is_Object
(O_Ent
)
6440 and then not Is_Generic_Formal
(O_Ent
)
6441 and then not Is_Generic_Type
(Etype
(U_Ent
))
6442 and then Address_Clause_Overlay_Warnings
6444 Register_Address_Clause_Check
6445 (N
, U_Ent
, No_Uint
, O_Ent
, Off
);
6448 -- If the overlay changes the storage order, warn since
6449 -- the construct is not really supported by the back end.
6450 -- Also mark the entity as being volatile to block the
6451 -- optimizer, even if there is no warranty on the result.
6453 if (Is_Record_Type
(Etype
(U_Ent
))
6454 or else Is_Array_Type
(Etype
(U_Ent
)))
6455 and then (Is_Record_Type
(Etype
(O_Ent
))
6456 or else Is_Array_Type
(Etype
(O_Ent
)))
6457 and then Reverse_Storage_Order
(Etype
(U_Ent
)) /=
6458 Reverse_Storage_Order
(Etype
(O_Ent
))
6461 ("??overlay changes scalar storage order", Expr
);
6462 Set_Treat_As_Volatile
(U_Ent
);
6466 -- If this is not an overlay, mark a variable as being
6467 -- volatile to prevent unwanted optimizations. It's a
6468 -- conservative interpretation of RM 13.3(19) for the
6469 -- cases where the compiler cannot detect potential
6470 -- aliasing issues easily and it also covers the case
6471 -- of an absolute address where the volatile aspect is
6472 -- kind of implicit.
6474 if Ekind
(U_Ent
) = E_Variable
then
6475 Set_Treat_As_Volatile
(U_Ent
);
6478 -- Make an entry in the table for an absolute address as
6479 -- above to check that the value is compatible with the
6480 -- alignment of the object.
6483 Addr
: constant Node_Id
:= Address_Value
(Expr
);
6485 if Compile_Time_Known_Value
(Addr
)
6486 and then Address_Clause_Overlay_Warnings
6488 Register_Address_Clause_Check
6489 (N
, U_Ent
, Expr_Value
(Addr
), Empty
, False);
6494 -- Issue an unconditional warning for a constant overlaying
6495 -- a variable. For the reverse case, we will issue it only
6496 -- if the variable is modified.
6497 -- Within a generic unit an In_Parameter is a constant.
6498 -- It can be instantiated with a variable, in which case
6499 -- there will be a warning on the instance.
6501 if Ekind
(U_Ent
) = E_Constant
6502 and then Present
(O_Ent
)
6503 and then Ekind
(O_Ent
) /= E_Generic_In_Parameter
6504 and then not Overlays_Constant
(U_Ent
)
6505 and then Address_Clause_Overlay_Warnings
6507 Error_Msg_N
("?o?constant overlays a variable", Expr
);
6509 -- Imported variables can have an address clause, but then
6510 -- the import is pretty meaningless except to suppress
6511 -- initializations, so we do not need such variables to
6512 -- be statically allocated (and in fact it causes trouble
6513 -- if the address clause is a local value).
6515 elsif Is_Imported
(U_Ent
) then
6516 Set_Is_Statically_Allocated
(U_Ent
, False);
6519 -- We mark a possible modification of a variable with an
6520 -- address clause, since it is likely aliasing is occurring.
6522 Note_Possible_Modification
(Nam
, Sure
=> False);
6524 -- Legality checks on the address clause for initialized
6525 -- objects is deferred until the freeze point, because
6526 -- a subsequent pragma might indicate that the object
6527 -- is imported and thus not initialized. Also, the address
6528 -- clause might involve entities that have yet to be
6531 Set_Has_Delayed_Freeze
(U_Ent
);
6533 -- If an initialization call has been generated for this
6534 -- object, it needs to be deferred to after the freeze node
6535 -- we have just now added, otherwise GIGI will see a
6536 -- reference to the variable (as actual to the IP call)
6537 -- before its definition.
6540 Init_Call
: constant Node_Id
:=
6541 Remove_Init_Call
(U_Ent
, N
);
6544 if Present
(Init_Call
) then
6545 Append_Freeze_Action
(U_Ent
, Init_Call
);
6547 -- Reset Initialization_Statements pointer so that
6548 -- if there is a pragma Import further down, it can
6549 -- clear any default initialization.
6551 Set_Initialization_Statements
(U_Ent
, Init_Call
);
6555 -- Entity has delayed freeze, so we will generate an
6556 -- alignment check at the freeze point unless suppressed.
6558 if not Range_Checks_Suppressed
(U_Ent
)
6559 and then not Alignment_Checks_Suppressed
(U_Ent
)
6561 Set_Check_Address_Alignment
(N
);
6564 -- Kill the size check code, since we are not allocating
6565 -- the variable, it is somewhere else.
6567 Kill_Size_Check_Code
(U_Ent
);
6570 -- Not a valid entity for an address clause
6573 Error_Msg_N
("address cannot be given for &", Nam
);
6581 -- Alignment attribute definition clause
6583 when Attribute_Alignment
=> Alignment
: declare
6584 Align
: constant Uint
:= Get_Alignment_Value
(Expr
);
6585 Max_Align
: constant Uint
:= UI_From_Int
(Maximum_Alignment
);
6590 if not Is_Type
(U_Ent
)
6591 and then Ekind
(U_Ent
) /= E_Variable
6592 and then Ekind
(U_Ent
) /= E_Constant
6594 Error_Msg_N
("alignment cannot be given for &", Nam
);
6596 elsif Duplicate_Clause
then
6599 elsif Present
(Align
) then
6600 Set_Has_Alignment_Clause
(U_Ent
);
6602 -- Tagged type case, check for attempt to set alignment to a
6603 -- value greater than Max_Align, and reset if so.
6605 if Is_Tagged_Type
(U_Ent
) and then Align
> Max_Align
then
6607 ("alignment for & set to Maximum_Aligment??", Nam
);
6608 Set_Alignment
(U_Ent
, Max_Align
);
6613 Set_Alignment
(U_Ent
, Align
);
6616 -- For an array type, U_Ent is the first subtype. In that case,
6617 -- also set the alignment of the anonymous base type so that
6618 -- other subtypes (such as the itypes for aggregates of the
6619 -- type) also receive the expected alignment.
6621 if Is_Array_Type
(U_Ent
) then
6622 Set_Alignment
(Base_Type
(U_Ent
), Align
);
6631 -- Bit_Order attribute definition clause
6633 when Attribute_Bit_Order
=>
6634 if not Is_Record_Type
(U_Ent
) then
6636 ("Bit_Order can only be defined for record type", Nam
);
6638 elsif Is_Tagged_Type
(U_Ent
) and then Is_Derived_Type
(U_Ent
) then
6640 ("Bit_Order cannot be defined for record extensions", Nam
);
6642 elsif Duplicate_Clause
then
6646 Analyze_And_Resolve
(Expr
, RTE
(RE_Bit_Order
));
6648 if Etype
(Expr
) = Any_Type
then
6651 elsif not Is_OK_Static_Expression
(Expr
) then
6652 Flag_Non_Static_Expr
6653 ("Bit_Order requires static expression!", Expr
);
6655 elsif (Expr_Value
(Expr
) = 0) /= Bytes_Big_Endian
then
6656 Set_Reverse_Bit_Order
(Base_Type
(U_Ent
), True);
6660 --------------------
6661 -- Component_Size --
6662 --------------------
6664 -- Component_Size attribute definition clause
6666 when Attribute_Component_Size
=> Component_Size_Case
: declare
6667 Csize
: constant Uint
:= Static_Integer
(Expr
);
6671 New_Ctyp
: Entity_Id
;
6675 if not Is_Array_Type
(U_Ent
) then
6676 Error_Msg_N
("component size requires array type", Nam
);
6680 Btype
:= Base_Type
(U_Ent
);
6681 Ctyp
:= Component_Type
(Btype
);
6683 if Duplicate_Clause
then
6686 elsif Rep_Item_Too_Early
(Btype
, N
) then
6689 elsif Present
(Csize
) then
6690 Check_Size
(Expr
, Ctyp
, Csize
, Biased
);
6692 -- For the biased case, build a declaration for a subtype that
6693 -- will be used to represent the biased subtype that reflects
6694 -- the biased representation of components. We need the subtype
6695 -- to get proper conversions on referencing elements of the
6700 Make_Defining_Identifier
(Loc
,
6702 New_External_Name
(Chars
(U_Ent
), 'C', 0, 'T'));
6705 Make_Subtype_Declaration
(Loc
,
6706 Defining_Identifier
=> New_Ctyp
,
6707 Subtype_Indication
=>
6708 New_Occurrence_Of
(Component_Type
(Btype
), Loc
));
6710 Set_Parent
(Decl
, N
);
6711 Analyze
(Decl
, Suppress
=> All_Checks
);
6713 Set_Has_Delayed_Freeze
(New_Ctyp
, False);
6714 Reinit_Esize
(New_Ctyp
);
6715 Set_RM_Size
(New_Ctyp
, Csize
);
6716 Reinit_Alignment
(New_Ctyp
);
6717 Set_Is_Itype
(New_Ctyp
, True);
6718 Set_Associated_Node_For_Itype
(New_Ctyp
, U_Ent
);
6720 Set_Component_Type
(Btype
, New_Ctyp
);
6721 Set_Biased
(New_Ctyp
, N
, "component size clause");
6724 Set_Component_Size
(Btype
, Csize
);
6726 -- Deal with warning on overridden size
6728 if Warn_On_Overridden_Size
6729 and then Has_Size_Clause
(Ctyp
)
6730 and then RM_Size
(Ctyp
) /= Csize
6733 ("component size overrides size clause for&?.s?", N
, Ctyp
);
6736 Set_Has_Component_Size_Clause
(Btype
, True);
6737 Set_Has_Non_Standard_Rep
(Btype
, True);
6739 end Component_Size_Case
;
6741 -----------------------
6742 -- Constant_Indexing --
6743 -----------------------
6745 when Attribute_Constant_Indexing
=>
6746 Check_Indexing_Functions
;
6752 when Attribute_CPU
=>
6753 pragma Assert
(From_Aspect_Specification
(N
));
6754 -- The parser forbids this clause in source code, so it must have
6755 -- come from an aspect specification.
6757 if not Is_Task_Type
(U_Ent
) then
6758 Error_Msg_N
("'C'P'U can only be defined for task", Nam
);
6760 elsif Duplicate_Clause
then
6764 -- The expression must be analyzed in the special manner
6765 -- described in "Handling of Default and Per-Object
6766 -- Expressions" in sem.ads.
6768 -- The visibility to the components must be established
6769 -- and restored before and after analysis.
6772 Preanalyze_Spec_Expression
(Expr
, RTE
(RE_CPU_Range
));
6775 -- AI12-0117-1, "Restriction No_Tasks_Unassigned_To_CPU":
6776 -- If the expression is static, and its value is
6777 -- System.Multiprocessors.Not_A_Specific_CPU (i.e. zero) then
6778 -- that's a violation of No_Tasks_Unassigned_To_CPU. It might
6779 -- seem better to refer to Not_A_Specific_CPU here, but that
6780 -- involves a lot of horsing around with Rtsfind, and this
6781 -- value is not going to change, so it's better to hardwire
6784 -- AI12-0055-1, "All properties of a usage profile are defined
6785 -- by pragmas": If the expression is nonstatic, that's a
6786 -- violation of No_Dynamic_CPU_Assignment.
6788 if Is_OK_Static_Expression
(Expr
) then
6789 if Expr_Value
(Expr
) = Uint_0
then
6790 Check_Restriction
(No_Tasks_Unassigned_To_CPU
, Expr
);
6793 Check_Restriction
(No_Dynamic_CPU_Assignment
, Expr
);
6797 ----------------------
6798 -- Default_Iterator --
6799 ----------------------
6801 when Attribute_Default_Iterator
=> Default_Iterator
: declare
6806 -- If target type is untagged, further checks are irrelevant
6808 if not Is_Tagged_Type
(U_Ent
) then
6810 ("aspect Default_Iterator applies to tagged type", Nam
);
6814 Check_Iterator_Functions
;
6818 if not Is_Entity_Name
(Expr
)
6819 or else Ekind
(Entity
(Expr
)) /= E_Function
6821 Error_Msg_N
("aspect Iterator must be a function", Expr
);
6824 Func
:= Entity
(Expr
);
6827 -- The type of the first parameter must be T, T'class, or a
6828 -- corresponding access type (5.5.1 (8/3). If function is
6829 -- parameterless label type accordingly.
6831 if No
(First_Formal
(Func
)) then
6834 Typ
:= Etype
(First_Formal
(Func
));
6838 or else Typ
= Class_Wide_Type
(U_Ent
)
6839 or else (Is_Access_Type
(Typ
)
6840 and then Designated_Type
(Typ
) = U_Ent
)
6841 or else (Is_Access_Type
(Typ
)
6842 and then Designated_Type
(Typ
) =
6843 Class_Wide_Type
(U_Ent
))
6849 ("Default_Iterator must be a primitive of&", Func
, U_Ent
);
6851 end Default_Iterator
;
6853 ------------------------
6854 -- Dispatching_Domain --
6855 ------------------------
6857 when Attribute_Dispatching_Domain
=>
6858 pragma Assert
(From_Aspect_Specification
(N
));
6859 -- The parser forbids this clause in source code, so it must have
6860 -- come from an aspect specification.
6862 if not Is_Task_Type
(U_Ent
) then
6864 ("Dispatching_Domain can only be defined for task", Nam
);
6866 elsif Duplicate_Clause
then
6870 -- The expression must be analyzed in the special manner
6871 -- described in "Handling of Default and Per-Object
6872 -- Expressions" in sem.ads.
6874 -- The visibility to the components must be restored
6878 Preanalyze_Spec_Expression
6879 (Expr
, RTE
(RE_Dispatching_Domain
));
6888 when Attribute_External_Tag
=>
6889 if not Is_Tagged_Type
(U_Ent
) then
6890 Error_Msg_N
("should be a tagged type", Nam
);
6893 if Duplicate_Clause
then
6897 Analyze_And_Resolve
(Expr
, Standard_String
);
6899 if not Is_OK_Static_Expression
(Expr
) then
6900 Flag_Non_Static_Expr
6901 ("static string required for tag name!", Nam
);
6904 if not Is_Library_Level_Entity
(U_Ent
) then
6906 ("??non-unique external tag supplied for &", N
, U_Ent
);
6908 ("\??same external tag applies to all subprogram calls",
6911 ("\??corresponding internal tag cannot be obtained", N
);
6915 --------------------------
6916 -- Implicit_Dereference --
6917 --------------------------
6919 when Attribute_Implicit_Dereference
=>
6921 -- Legality checks already performed at the point of the type
6922 -- declaration, aspect is not delayed.
6930 when Attribute_Input
=>
6931 Analyze_Stream_TSS_Definition
(TSS_Stream_Input
);
6932 Set_Has_Specified_Stream_Input
(Ent
);
6934 ------------------------
6935 -- Interrupt_Priority --
6936 ------------------------
6938 when Attribute_Interrupt_Priority
=>
6939 pragma Assert
(From_Aspect_Specification
(N
));
6940 -- The parser forbids this clause in source code, so it must have
6941 -- come from an aspect specification.
6943 if not Is_Concurrent_Type
(U_Ent
) then
6945 ("Interrupt_Priority can only be defined for task and "
6946 & "protected object", Nam
);
6948 elsif Duplicate_Clause
then
6952 -- The expression must be analyzed in the special manner
6953 -- described in "Handling of Default and Per-Object
6954 -- Expressions" in sem.ads.
6956 -- The visibility to the components must be restored
6960 Preanalyze_Spec_Expression
6961 (Expr
, RTE
(RE_Interrupt_Priority
));
6965 -- Check the No_Task_At_Interrupt_Priority restriction
6967 if Is_Task_Type
(U_Ent
) then
6968 Check_Restriction
(No_Task_At_Interrupt_Priority
, N
);
6976 when Attribute_Iterable
=>
6979 if Nkind
(Expr
) /= N_Aggregate
then
6980 Error_Msg_N
("aspect Iterable must be an aggregate", Expr
);
6988 Assoc
:= First
(Component_Associations
(Expr
));
6989 while Present
(Assoc
) loop
6990 Analyze
(Expression
(Assoc
));
6992 if not Is_Entity_Name
(Expression
(Assoc
))
6993 or else Ekind
(Entity
(Expression
(Assoc
))) /= E_Function
6995 Error_Msg_N
("value must be a function", Assoc
);
7002 ----------------------
7003 -- Iterator_Element --
7004 ----------------------
7006 when Attribute_Iterator_Element
=>
7009 if not Is_Entity_Name
(Expr
)
7010 or else not Is_Type
(Entity
(Expr
))
7012 Error_Msg_N
("aspect Iterator_Element must be a type", Expr
);
7020 -- Machine radix attribute definition clause
7022 when Attribute_Machine_Radix
=> Machine_Radix
: declare
7023 Radix
: constant Uint
:= Static_Integer
(Expr
);
7026 if not Is_Decimal_Fixed_Point_Type
(U_Ent
) then
7027 Error_Msg_N
("decimal fixed-point type expected for &", Nam
);
7029 elsif Duplicate_Clause
then
7032 elsif Present
(Radix
) then
7033 Set_Has_Machine_Radix_Clause
(U_Ent
);
7034 Set_Has_Non_Standard_Rep
(Base_Type
(U_Ent
));
7039 elsif Radix
= 10 then
7040 Set_Machine_Radix_10
(U_Ent
);
7043 Error_Msg_N
("machine radix value must be 2 or 10", Expr
);
7052 -- Object_Size attribute definition clause
7054 when Attribute_Object_Size
=> Object_Size
: declare
7055 Size
: constant Uint
:= Static_Integer
(Expr
);
7058 pragma Warnings
(Off
, Biased
);
7061 if not Is_Type
(U_Ent
) then
7062 Error_Msg_N
("Object_Size cannot be given for &", Nam
);
7064 elsif Duplicate_Clause
then
7068 Check_Size
(Expr
, U_Ent
, Size
, Biased
);
7070 if No
(Size
) or else Size
<= 0 then
7071 Error_Msg_N
("Object_Size must be positive", Expr
);
7073 elsif Is_Scalar_Type
(U_Ent
) then
7074 if Size
/= 8 and then Size
/= 16 and then Size
/= 32
7075 and then UI_Mod
(Size
, 64) /= 0
7078 ("Object_Size must be 8, 16, 32, or multiple of 64",
7082 elsif Size
mod 8 /= 0 then
7083 Error_Msg_N
("Object_Size must be a multiple of 8", Expr
);
7086 Set_Esize
(U_Ent
, Size
);
7087 Set_Has_Object_Size_Clause
(U_Ent
);
7088 Alignment_Check_For_Size_Change
(U_Ent
, Size
);
7096 when Attribute_Output
=>
7097 Analyze_Stream_TSS_Definition
(TSS_Stream_Output
);
7098 Set_Has_Specified_Stream_Output
(Ent
);
7104 when Attribute_Priority
=>
7106 -- Priority attribute definition clause not allowed except from
7107 -- aspect specification.
7109 if From_Aspect_Specification
(N
) then
7110 if not (Is_Concurrent_Type
(U_Ent
)
7111 or else Ekind
(U_Ent
) = E_Procedure
)
7114 ("Priority can only be defined for task and protected "
7117 elsif Duplicate_Clause
then
7121 -- The expression must be analyzed in the special manner
7122 -- described in "Handling of Default and Per-Object
7123 -- Expressions" in sem.ads.
7125 -- The visibility to the components must be restored
7128 Preanalyze_Spec_Expression
(Expr
, Standard_Integer
);
7131 if not Is_OK_Static_Expression
(Expr
) then
7132 Check_Restriction
(Static_Priorities
, Expr
);
7138 ("attribute& cannot be set with definition clause", N
);
7145 when Attribute_Put_Image
=>
7146 Analyze_Put_Image_TSS_Definition
;
7152 when Attribute_Read
=>
7153 Analyze_Stream_TSS_Definition
(TSS_Stream_Read
);
7154 Set_Has_Specified_Stream_Read
(Ent
);
7156 --------------------------
7157 -- Scalar_Storage_Order --
7158 --------------------------
7160 -- Scalar_Storage_Order attribute definition clause
7162 when Attribute_Scalar_Storage_Order
=>
7163 if not (Is_Record_Type
(U_Ent
) or else Is_Array_Type
(U_Ent
)) then
7165 ("Scalar_Storage_Order can only be defined for record or "
7166 & "array type", Nam
);
7168 elsif Duplicate_Clause
then
7172 Analyze_And_Resolve
(Expr
, RTE
(RE_Bit_Order
));
7174 if Etype
(Expr
) = Any_Type
then
7177 elsif not Is_OK_Static_Expression
(Expr
) then
7178 Flag_Non_Static_Expr
7179 ("Scalar_Storage_Order requires static expression!", Expr
);
7181 elsif (Expr_Value
(Expr
) = 0) /= Bytes_Big_Endian
then
7183 -- Here for the case of a non-default (i.e. non-confirming)
7184 -- Scalar_Storage_Order attribute definition.
7186 if Support_Nondefault_SSO_On_Target
then
7187 Set_Reverse_Storage_Order
(Base_Type
(U_Ent
), True);
7190 ("non-default Scalar_Storage_Order not supported on "
7195 -- Clear SSO default indications since explicit setting of the
7196 -- order overrides the defaults.
7198 Set_SSO_Set_Low_By_Default
(Base_Type
(U_Ent
), False);
7199 Set_SSO_Set_High_By_Default
(Base_Type
(U_Ent
), False);
7202 ------------------------
7203 -- Size or Value_Size --
7204 ------------------------
7206 -- Size or Value_Size attribute definition clause. These are treated
7207 -- the same, except that Size is allowed on objects, and Value_Size
7208 -- is allowed on nonfirst subtypes. First subtypes allow both Size
7209 -- and Value_Size; the treatment is the same for both.
7211 when Attribute_Size | Attribute_Value_Size
=> Size
: declare
7212 Size
: constant Uint
:= Static_Integer
(Expr
);
7214 Attr_Name
: constant String :=
7215 (if Id
= Attribute_Size
then "size"
7216 elsif Id
= Attribute_Value_Size
then "value size"
7217 else ""); -- can't happen
7218 -- Name of the attribute for printing in messages
7220 OK_Prefix
: constant Boolean :=
7221 (if Id
= Attribute_Size
then
7222 Ekind
(U_Ent
) in Type_Kind | Constant_Or_Variable_Kind
7223 elsif Id
= Attribute_Value_Size
then
7224 Ekind
(U_Ent
) in Type_Kind
7225 else False); -- can't happen
7226 -- For X'Size, X can be a type or object; for X'Value_Size,
7227 -- X can be a type. Note that we already checked that 'Size
7228 -- can be specified only for a first subtype.
7233 if not OK_Prefix
then
7234 Error_Msg_N
(Attr_Name
& " cannot be given for &", Nam
);
7236 elsif Duplicate_Clause
then
7239 elsif Is_Array_Type
(U_Ent
)
7240 and then not Is_Constrained
(U_Ent
)
7243 (Attr_Name
& " cannot be given for unconstrained array", Nam
);
7245 elsif Present
(Size
) then
7247 Etyp
: constant Entity_Id
:=
7248 (if Is_Type
(U_Ent
) then U_Ent
else Etype
(U_Ent
));
7251 -- Check size, note that Gigi is in charge of checking that
7252 -- the size of an array or record type is OK. Also we do not
7253 -- check the size in the ordinary fixed-point case, since
7254 -- it is too early to do so (there may be subsequent small
7255 -- clause that affects the size). We can check the size if
7256 -- a small clause has already been given.
7258 if not Is_Ordinary_Fixed_Point_Type
(U_Ent
)
7259 or else Has_Small_Clause
(U_Ent
)
7264 Check_Size
(Expr
, Etyp
, Size
, Biased
);
7265 Set_Biased
(U_Ent
, N
, Attr_Name
& " clause", Biased
);
7269 -- For types, set RM_Size and Esize if appropriate
7271 if Is_Type
(U_Ent
) then
7272 Set_RM_Size
(U_Ent
, Size
);
7274 -- If we are specifying the Size or Value_Size of a
7275 -- first subtype, then for elementary types, increase
7276 -- Object_Size to power of 2, but not less than a storage
7277 -- unit in any case (normally this means it will be byte
7280 -- For all other types, nothing else to do, we leave
7281 -- Esize (object size) unset; the back end will set it
7282 -- from the size and alignment in an appropriate manner.
7284 -- In both cases, we check whether the alignment must be
7285 -- reset in the wake of the size change.
7287 -- For nonfirst subtypes ('Value_Size only), we do
7290 if Is_First_Subtype
(U_Ent
) then
7291 if Is_Elementary_Type
(U_Ent
) then
7292 if Size
<= System_Storage_Unit
then
7294 (U_Ent
, UI_From_Int
(System_Storage_Unit
));
7295 elsif Size
<= 16 then
7296 Set_Esize
(U_Ent
, Uint_16
);
7297 elsif Size
<= 32 then
7298 Set_Esize
(U_Ent
, Uint_32
);
7300 Set_Esize
(U_Ent
, (Size
+ 63) / 64 * 64);
7303 Alignment_Check_For_Size_Change
7304 (U_Ent
, Esize
(U_Ent
));
7306 Alignment_Check_For_Size_Change
(U_Ent
, Size
);
7310 -- For Object'Size, set Esize only
7313 if Is_Elementary_Type
(Etyp
)
7314 and then Size
/= System_Storage_Unit
7318 and then Size
/= System_Max_Integer_Size
7320 Error_Msg_Uint_1
:= UI_From_Int
(System_Storage_Unit
);
7322 UI_From_Int
(System_Max_Integer_Size
);
7324 ("size for primitive object must be a power of 2 in "
7325 & "the range ^-^", N
);
7328 Set_Esize
(U_Ent
, Size
);
7331 -- As of RM 13.1, only confirming size
7332 -- (i.e. (Size = Esize (Etyp))) for aliased object of
7333 -- elementary type must be supported.
7334 -- GNAT rejects nonconfirming size for such object.
7336 if Is_Aliased
(U_Ent
)
7337 and then Is_Elementary_Type
(Etyp
)
7338 and then Known_Esize
(U_Ent
)
7339 and then Size
/= Esize
(Etyp
)
7342 ("nonconfirming Size for aliased object is not "
7346 Set_Has_Size_Clause
(U_Ent
);
7355 -- Small attribute definition clause
7357 when Attribute_Small
=> Small
: declare
7358 Implicit_Base
: constant Entity_Id
:= Base_Type
(U_Ent
);
7362 Analyze_And_Resolve
(Expr
, Any_Real
);
7364 if Etype
(Expr
) = Any_Type
then
7367 elsif not Is_OK_Static_Expression
(Expr
) then
7368 Flag_Non_Static_Expr
7369 ("small requires static expression!", Expr
);
7373 Small
:= Expr_Value_R
(Expr
);
7375 if Small
<= Ureal_0
then
7376 Error_Msg_N
("small value must be greater than zero", Expr
);
7382 if not Is_Ordinary_Fixed_Point_Type
(U_Ent
) then
7384 ("small requires an ordinary fixed point type", Nam
);
7386 elsif Has_Small_Clause
(U_Ent
) then
7387 Error_Msg_N
("small already given for &", Nam
);
7389 elsif Small
> Delta_Value
(U_Ent
) then
7391 ("small value must not be greater than delta value", Nam
);
7394 Set_Small_Value
(U_Ent
, Small
);
7395 Set_Small_Value
(Implicit_Base
, Small
);
7396 Set_Has_Small_Clause
(U_Ent
);
7397 Set_Has_Small_Clause
(Implicit_Base
);
7398 Set_Has_Non_Standard_Rep
(Implicit_Base
);
7406 -- Storage_Pool attribute definition clause
7408 when Attribute_Simple_Storage_Pool
7409 | Attribute_Storage_Pool
7411 Storage_Pool
: declare
7415 procedure Associate_Storage_Pool
7416 (Ent
: Entity_Id
; Pool
: Entity_Id
);
7417 -- Associate Pool to Ent and perform legality checks on subpools
7419 ----------------------------
7420 -- Associate_Storage_Pool --
7421 ----------------------------
7423 procedure Associate_Storage_Pool
7424 (Ent
: Entity_Id
; Pool
: Entity_Id
)
7426 function Object_From
(Pool
: Entity_Id
) return Entity_Id
;
7427 -- Return the entity of which Pool is a part of
7433 function Object_From
7434 (Pool
: Entity_Id
) return Entity_Id
7436 N
: Node_Id
:= Pool
;
7438 if Present
(Renamed_Object
(Pool
)) then
7439 N
:= Renamed_Object
(Pool
);
7442 while Present
(N
) loop
7444 when N_Defining_Identifier
=>
7447 when N_Identifier | N_Expanded_Name
=>
7450 when N_Indexed_Component | N_Selected_Component |
7451 N_Explicit_Dereference
7455 when N_Type_Conversion
=>
7456 N
:= Expression
(N
);
7459 -- ??? we probably should handle more cases but
7460 -- this is good enough in practice for this check
7461 -- on a corner case.
7473 Set_Associated_Storage_Pool
(Ent
, Pool
);
7475 -- Check RM 13.11.4(22-23/3): a specification of a storage pool
7476 -- is illegal if the storage pool supports subpools and:
7477 -- (A) The access type is a general access type.
7478 -- (B) The access type is statically deeper than the storage
7480 -- (C) The storage pool object is a part of a formal parameter;
7481 -- (D) The storage pool object is a part of the dereference of
7482 -- a non-library level general access type;
7484 if Ada_Version
>= Ada_2012
7485 and then RTU_Loaded
(System_Storage_Pools_Subpools
)
7487 Is_Ancestor
(RTE
(RE_Root_Storage_Pool_With_Subpools
),
7492 if Ekind
(Etype
(Ent
)) = E_General_Access_Type
then
7494 ("subpool cannot be used on general access type", Ent
);
7499 if Type_Access_Level
(Ent
)
7500 > Static_Accessibility_Level
7501 (Pool
, Object_Decl_Level
)
7504 ("subpool access type has deeper accessibility "
7505 & "level than pool", Ent
);
7509 Obj
:= Object_From
(Pool
);
7513 if Present
(Obj
) and then Is_Formal
(Obj
) then
7515 ("subpool cannot be part of a parameter", Ent
);
7522 and then Ekind
(Etype
(Obj
)) = E_General_Access_Type
7523 and then not Is_Library_Level_Entity
(Etype
(Obj
))
7526 ("subpool cannot be part of the dereference of a " &
7527 "nested general access type", Ent
);
7531 end Associate_Storage_Pool
;
7534 if Ekind
(U_Ent
) = E_Access_Subprogram_Type
then
7536 ("storage pool cannot be given for access-to-subprogram type",
7540 elsif Ekind
(U_Ent
) not in E_Access_Type | E_General_Access_Type
7543 ("storage pool can only be given for access types", Nam
);
7546 elsif Is_Derived_Type
(U_Ent
) then
7548 ("storage pool cannot be given for a derived access type",
7551 elsif Duplicate_Clause
then
7554 elsif Present
(Associated_Storage_Pool
(U_Ent
)) then
7555 Error_Msg_N
("storage pool already given for &", Nam
);
7559 -- Check for Storage_Size previously given
7562 SS
: constant Node_Id
:=
7563 Get_Attribute_Definition_Clause
7564 (U_Ent
, Attribute_Storage_Size
);
7566 if Present
(SS
) then
7567 Check_Pool_Size_Clash
(U_Ent
, N
, SS
);
7571 -- Storage_Pool case
7573 if Id
= Attribute_Storage_Pool
then
7575 (Expr
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
7577 -- In the Simple_Storage_Pool case, we allow a variable of any
7578 -- simple storage pool type, so we Resolve without imposing an
7582 Analyze_And_Resolve
(Expr
);
7584 if No
(Get_Rep_Pragma
7585 (Etype
(Expr
), Name_Simple_Storage_Pool_Type
))
7588 ("expression must be of a simple storage pool type", Expr
);
7592 if not Denotes_Variable
(Expr
) then
7593 Error_Msg_N
("storage pool must be a variable", Expr
);
7597 if Nkind
(Expr
) = N_Type_Conversion
then
7598 T
:= Etype
(Expression
(Expr
));
7603 -- The Stack_Bounded_Pool is used internally for implementing
7604 -- access types with a Storage_Size. Since it only work properly
7605 -- when used on one specific type, we need to check that it is not
7606 -- hijacked improperly:
7608 -- type T is access Integer;
7609 -- for T'Storage_Size use n;
7610 -- type Q is access Float;
7611 -- for Q'Storage_Size use T'Storage_Size; -- incorrect
7613 if Is_RTE
(Base_Type
(T
), RE_Stack_Bounded_Pool
) then
7614 Error_Msg_N
("non-shareable internal Pool", Expr
);
7618 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
7619 -- Storage_Pool since this attribute cannot be defined for such
7620 -- types (RM E.2.2(17)).
7622 Validate_Remote_Access_To_Class_Wide_Type
(N
);
7624 -- If the argument is a name that is not an entity name, then
7625 -- we construct a renaming operation to define an entity of
7626 -- type storage pool.
7628 if not Is_Entity_Name
(Expr
)
7629 and then Is_Object_Reference
(Expr
)
7631 Pool
:= Make_Temporary
(Loc
, 'P', Expr
);
7634 Rnode
: constant Node_Id
:=
7635 Make_Object_Renaming_Declaration
(Loc
,
7636 Defining_Identifier
=> Pool
,
7638 New_Occurrence_Of
(Etype
(Expr
), Loc
),
7642 -- If the attribute definition clause comes from an aspect
7643 -- clause, then insert the renaming before the associated
7644 -- entity's declaration, since the attribute clause has
7645 -- not yet been appended to the declaration list.
7647 if From_Aspect_Specification
(N
) then
7648 Insert_Before
(Parent
(Entity
(N
)), Rnode
);
7650 Insert_Before
(N
, Rnode
);
7654 Associate_Storage_Pool
(U_Ent
, Pool
);
7657 elsif Is_Entity_Name
(Expr
) then
7658 Pool
:= Entity
(Expr
);
7660 -- If pool is a renamed object, get original one. This can
7661 -- happen with an explicit renaming, and within instances.
7663 while Present
(Renamed_Object
(Pool
))
7664 and then Is_Entity_Name
(Renamed_Object
(Pool
))
7666 Pool
:= Entity
(Renamed_Object
(Pool
));
7669 if Present
(Renamed_Object
(Pool
))
7670 and then Nkind
(Renamed_Object
(Pool
)) = N_Type_Conversion
7671 and then Is_Entity_Name
(Expression
(Renamed_Object
(Pool
)))
7673 Pool
:= Entity
(Expression
(Renamed_Object
(Pool
)));
7676 Associate_Storage_Pool
(U_Ent
, Pool
);
7678 elsif Nkind
(Expr
) = N_Type_Conversion
7679 and then Is_Entity_Name
(Expression
(Expr
))
7680 and then Nkind
(Original_Node
(Expr
)) = N_Attribute_Reference
7682 Pool
:= Entity
(Expression
(Expr
));
7683 Associate_Storage_Pool
(U_Ent
, Pool
);
7686 Error_Msg_N
("incorrect reference to a Storage Pool", Expr
);
7695 -- Storage_Size attribute definition clause
7697 when Attribute_Storage_Size
=> Storage_Size
: declare
7698 Btype
: constant Entity_Id
:= Base_Type
(U_Ent
);
7701 if Is_Task_Type
(U_Ent
) then
7703 -- Check obsolescent (but never obsolescent if from aspect)
7705 if not From_Aspect_Specification
(N
) then
7706 Check_Restriction
(No_Obsolescent_Features
, N
);
7708 if Warn_On_Obsolescent_Feature
then
7710 ("?j?storage size clause for task is an obsolescent "
7711 & "feature (RM J.9)", N
);
7712 Error_Msg_N
("\?j?use Storage_Size pragma instead", N
);
7719 if not Is_Access_Type
(U_Ent
)
7720 and then Ekind
(U_Ent
) /= E_Task_Type
7722 Error_Msg_N
("storage size cannot be given for &", Nam
);
7724 elsif Is_Access_Type
(U_Ent
) and Is_Derived_Type
(U_Ent
) then
7726 ("storage size cannot be given for a derived access type",
7729 elsif Duplicate_Clause
then
7733 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
7734 -- Storage_Size since this attribute cannot be defined for such
7735 -- types (RM E.2.2(17)).
7737 Validate_Remote_Access_To_Class_Wide_Type
(N
);
7739 Analyze_And_Resolve
(Expr
, Any_Integer
);
7741 if Is_Access_Type
(U_Ent
) then
7743 -- Check for Storage_Pool previously given
7746 SP
: constant Node_Id
:=
7747 Get_Attribute_Definition_Clause
7748 (U_Ent
, Attribute_Storage_Pool
);
7751 if Present
(SP
) then
7752 Check_Pool_Size_Clash
(U_Ent
, SP
, N
);
7756 -- Special case of for x'Storage_Size use 0
7758 if Is_OK_Static_Expression
(Expr
)
7759 and then Expr_Value
(Expr
) = 0
7761 Set_No_Pool_Assigned
(Btype
);
7765 Set_Has_Storage_Size_Clause
(Btype
);
7773 when Attribute_Stream_Size
=> Stream_Size
: declare
7774 Size
: constant Uint
:= Static_Integer
(Expr
);
7777 if Ada_Version
<= Ada_95
then
7778 Check_Restriction
(No_Implementation_Attributes
, N
);
7781 if Duplicate_Clause
then
7784 elsif Is_Elementary_Type
(U_Ent
) then
7785 -- Size will be empty if we already detected an error
7786 -- (e.g. Expr is of the wrong type); we might as well
7787 -- give the useful hint below even in that case.
7789 if No
(Size
) or else
7790 (Size
/= System_Storage_Unit
7791 and then Size
/= System_Storage_Unit
* 2
7792 and then Size
/= System_Storage_Unit
* 3
7793 and then Size
/= System_Storage_Unit
* 4
7794 and then Size
/= System_Storage_Unit
* 8)
7797 ("stream size for elementary type must be 8, 16, 24, " &
7800 elsif Known_RM_Size
(U_Ent
) and then RM_Size
(U_Ent
) > Size
then
7801 Error_Msg_Uint_1
:= RM_Size
(U_Ent
);
7803 ("stream size for elementary type must be 8, 16, 24, " &
7804 "32 or 64 and at least ^", N
);
7807 Set_Has_Stream_Size_Clause
(U_Ent
);
7810 Error_Msg_N
("Stream_Size cannot be given for &", Nam
);
7814 -----------------------
7815 -- Variable_Indexing --
7816 -----------------------
7818 when Attribute_Variable_Indexing
=>
7819 Check_Indexing_Functions
;
7825 when Attribute_Write
=>
7826 Analyze_Stream_TSS_Definition
(TSS_Stream_Write
);
7827 Set_Has_Specified_Stream_Write
(Ent
);
7829 -- All other attributes cannot be set
7833 ("attribute& cannot be set with definition clause", N
);
7836 -- The test for the type being frozen must be performed after any
7837 -- expression the clause has been analyzed since the expression itself
7838 -- might cause freezing that makes the clause illegal.
7840 if Rep_Item_Too_Late
(U_Ent
, N
, FOnly
) then
7843 end Analyze_Attribute_Definition_Clause
;
7845 ----------------------------
7846 -- Analyze_Code_Statement --
7847 ----------------------------
7849 procedure Analyze_Code_Statement
(N
: Node_Id
) is
7850 HSS
: constant Node_Id
:= Parent
(N
);
7851 SBody
: constant Node_Id
:= Parent
(HSS
);
7852 Subp
: constant Entity_Id
:= Current_Scope
;
7859 -- Accept foreign code statements for CodePeer. The analysis is skipped
7860 -- to avoid rejecting unrecognized constructs.
7862 if CodePeer_Mode
then
7867 -- Analyze and check we get right type, note that this implements the
7868 -- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that is
7869 -- the only way that Asm_Insn could possibly be visible.
7871 Analyze_And_Resolve
(Expression
(N
));
7873 if Etype
(Expression
(N
)) = Any_Type
then
7875 elsif not Is_RTE
(Etype
(Expression
(N
)), RE_Asm_Insn
) then
7876 Error_Msg_N
("incorrect type for code statement", N
);
7880 Check_Code_Statement
(N
);
7882 -- Make sure we appear in the handled statement sequence of a subprogram
7885 if Nkind
(HSS
) /= N_Handled_Sequence_Of_Statements
7886 or else Nkind
(SBody
) /= N_Subprogram_Body
7889 ("code statement can only appear in body of subprogram", N
);
7893 -- Do remaining checks (RM 13.8(3)) if not already done
7895 if not Is_Machine_Code_Subprogram
(Subp
) then
7896 Set_Is_Machine_Code_Subprogram
(Subp
);
7898 -- No exception handlers allowed
7900 if Present
(Exception_Handlers
(HSS
)) then
7902 ("exception handlers not permitted in machine code subprogram",
7903 First
(Exception_Handlers
(HSS
)));
7906 -- No declarations other than use clauses and pragmas (we allow
7907 -- certain internally generated declarations as well).
7909 Decl
:= First
(Declarations
(SBody
));
7910 while Present
(Decl
) loop
7911 DeclO
:= Original_Node
(Decl
);
7912 if Comes_From_Source
(DeclO
)
7913 and Nkind
(DeclO
) not in N_Pragma
7914 | N_Use_Package_Clause
7916 | N_Implicit_Label_Declaration
7919 ("this declaration is not allowed in machine code subprogram",
7926 -- No statements other than code statements, pragmas, and labels.
7927 -- Again we allow certain internally generated statements.
7929 -- In Ada 2012, qualified expressions are names, and the code
7930 -- statement is initially parsed as a procedure call.
7932 Stmt
:= First
(Statements
(HSS
));
7933 while Present
(Stmt
) loop
7934 StmtO
:= Original_Node
(Stmt
);
7936 -- A procedure call transformed into a code statement is OK
7938 if Ada_Version
>= Ada_2012
7939 and then Nkind
(StmtO
) = N_Procedure_Call_Statement
7940 and then Nkind
(Name
(StmtO
)) = N_Qualified_Expression
7944 elsif Comes_From_Source
(StmtO
)
7945 and then Nkind
(StmtO
) not in
7946 N_Pragma | N_Label | N_Code_Statement
7949 ("this statement is not allowed in machine code subprogram",
7956 end Analyze_Code_Statement
;
7958 -----------------------------------------------
7959 -- Analyze_Enumeration_Representation_Clause --
7960 -----------------------------------------------
7962 procedure Analyze_Enumeration_Representation_Clause
(N
: Node_Id
) is
7963 Ident
: constant Node_Id
:= Identifier
(N
);
7964 Aggr
: constant Node_Id
:= Array_Aggregate
(N
);
7965 Enumtype
: Entity_Id
;
7972 Err
: Boolean := False;
7973 -- Set True to avoid cascade errors and crashes on incorrect source code
7975 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Universal_Integer
));
7976 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(Universal_Integer
));
7977 -- Allowed range of universal integer (= allowed range of enum lit vals)
7981 -- Minimum and maximum values of entries
7983 Max_Node
: Node_Id
:= Empty
; -- init to avoid warning
7984 -- Pointer to node for literal providing max value
7987 if Ignore_Rep_Clauses
then
7988 Kill_Rep_Clause
(N
);
7992 -- Ignore enumeration rep clauses by default in CodePeer mode,
7993 -- unless -gnatd.I is specified, as a work around for potential false
7994 -- positive messages.
7996 if CodePeer_Mode
and not Debug_Flag_Dot_II
then
8000 -- First some basic error checks
8003 Enumtype
:= Entity
(Ident
);
8005 if Enumtype
= Any_Type
8006 or else Rep_Item_Too_Early
(Enumtype
, N
)
8010 Enumtype
:= Underlying_Type
(Enumtype
);
8013 if not Is_Enumeration_Type
(Enumtype
) then
8015 ("enumeration type required, found}",
8016 Ident
, First_Subtype
(Enumtype
));
8020 -- Ignore rep clause on generic actual type. This will already have
8021 -- been flagged on the template as an error, and this is the safest
8022 -- way to ensure we don't get a junk cascaded message in the instance.
8024 if Is_Generic_Actual_Type
(Enumtype
) then
8027 -- Type must be in current scope
8029 elsif Scope
(Enumtype
) /= Current_Scope
then
8030 Error_Msg_N
("type must be declared in this scope", Ident
);
8033 -- Type must be a first subtype
8035 elsif not Is_First_Subtype
(Enumtype
) then
8036 Error_Msg_N
("cannot give enumeration rep clause for subtype", N
);
8039 -- Ignore duplicate rep clause
8041 elsif Has_Enumeration_Rep_Clause
(Enumtype
) then
8042 Error_Msg_N
("duplicate enumeration rep clause ignored", N
);
8045 -- Don't allow rep clause for standard [wide_[wide_]]character
8047 elsif Is_Standard_Character_Type
(Enumtype
) then
8048 Error_Msg_N
("enumeration rep clause not allowed for this type", N
);
8051 -- Check that the expression is a proper aggregate (no parentheses)
8053 elsif Paren_Count
(Aggr
) /= 0 then
8055 ("extra parentheses surrounding aggregate not allowed", Aggr
);
8058 -- Reject the mixing of named and positional entries in the aggregate
8060 elsif Present
(Expressions
(Aggr
))
8061 and then Present
(Component_Associations
(Aggr
))
8063 Error_Msg_N
("cannot mix positional and named entries in "
8064 & "enumeration rep clause", N
);
8067 -- All tests passed, so set rep clause in place
8070 Set_Has_Enumeration_Rep_Clause
(Enumtype
);
8071 Set_Has_Enumeration_Rep_Clause
(Base_Type
(Enumtype
));
8074 -- Now we process the aggregate. Note that we don't use the normal
8075 -- aggregate code for this purpose, because we don't want any of the
8076 -- normal expansion activities, and a number of special semantic
8077 -- rules apply (including the component type being any integer type)
8079 Elit
:= First_Literal
(Enumtype
);
8081 -- Process positional entries
8083 if Present
(Expressions
(Aggr
)) then
8084 Expr
:= First
(Expressions
(Aggr
));
8085 while Present
(Expr
) loop
8087 Error_Msg_N
("too many entries in aggregate", Expr
);
8091 Val
:= Static_Integer
(Expr
);
8093 -- Err signals that we found some incorrect entries processing
8094 -- the list. The final checks for completeness and ordering are
8095 -- skipped in this case.
8100 elsif Val
< Lo
or else Hi
< Val
then
8101 Error_Msg_N
("value outside permitted range", Expr
);
8105 Set_Enumeration_Rep
(Elit
, Val
);
8106 Set_Enumeration_Rep_Expr
(Elit
, Expr
);
8113 -- Process named entries
8115 elsif Present
(Component_Associations
(Aggr
)) then
8116 Assoc
:= First
(Component_Associations
(Aggr
));
8117 while Present
(Assoc
) loop
8118 Choice
:= First
(Choices
(Assoc
));
8120 if Present
(Next
(Choice
)) then
8122 ("multiple choice not allowed here", Next
(Choice
));
8126 if Nkind
(Choice
) = N_Others_Choice
then
8127 Error_Msg_N
("OTHERS choice not allowed here", Choice
);
8130 elsif Nkind
(Choice
) = N_Range
then
8132 -- ??? should allow zero/one element range here
8134 Error_Msg_N
("range not allowed here", Choice
);
8138 Analyze_And_Resolve
(Choice
, Enumtype
);
8140 if Error_Posted
(Choice
) then
8145 if Is_Entity_Name
(Choice
)
8146 and then Is_Type
(Entity
(Choice
))
8148 Error_Msg_N
("subtype name not allowed here", Choice
);
8151 -- ??? should allow static subtype with zero/one entry
8153 elsif Etype
(Choice
) = Base_Type
(Enumtype
) then
8154 if not Is_OK_Static_Expression
(Choice
) then
8155 Flag_Non_Static_Expr
8156 ("non-static expression used for choice!", Choice
);
8160 Elit
:= Expr_Value_E
(Choice
);
8162 if Present
(Enumeration_Rep_Expr
(Elit
)) then
8164 Sloc
(Enumeration_Rep_Expr
(Elit
));
8166 ("representation for& previously given#",
8171 Set_Enumeration_Rep_Expr
(Elit
, Expression
(Assoc
));
8173 Expr
:= Expression
(Assoc
);
8174 Val
:= Static_Integer
(Expr
);
8179 elsif Val
< Lo
or else Hi
< Val
then
8180 Error_Msg_N
("value outside permitted range", Expr
);
8184 Set_Enumeration_Rep
(Elit
, Val
);
8195 -- Aggregate is fully processed. Now we check that a full set of
8196 -- representations was given, and that they are in range and in order.
8197 -- These checks are only done if no other errors occurred.
8203 Elit
:= First_Literal
(Enumtype
);
8204 while Present
(Elit
) loop
8205 if No
(Enumeration_Rep_Expr
(Elit
)) then
8206 Error_Msg_NE
("missing representation for&!", N
, Elit
);
8209 Val
:= Enumeration_Rep
(Elit
);
8215 if Present
(Val
) then
8216 if Present
(Max
) and then Val
<= Max
then
8218 ("enumeration value for& not ordered!",
8219 Enumeration_Rep_Expr
(Elit
), Elit
);
8222 Max_Node
:= Enumeration_Rep_Expr
(Elit
);
8226 -- If there is at least one literal whose representation is not
8227 -- equal to the Pos value, then note that this enumeration type
8228 -- has a non-standard representation.
8230 if Val
/= Enumeration_Pos
(Elit
) then
8231 Set_Has_Non_Standard_Rep
(Base_Type
(Enumtype
));
8238 -- Now set proper size information
8241 Minsize
: Uint
:= UI_From_Int
(Minimum_Size
(Enumtype
));
8244 if Has_Size_Clause
(Enumtype
) then
8246 -- All OK, if size is OK now
8248 if RM_Size
(Enumtype
) >= Minsize
then
8252 -- Try if we can get by with biasing
8255 UI_From_Int
(Minimum_Size
(Enumtype
, Biased
=> True));
8257 -- Error message if even biasing does not work
8259 if RM_Size
(Enumtype
) < Minsize
then
8260 Error_Msg_Uint_1
:= RM_Size
(Enumtype
);
8261 Error_Msg_Uint_2
:= Max
;
8263 ("previously given size (^) is too small "
8264 & "for this value (^)", Max_Node
);
8266 -- If biasing worked, indicate that we now have biased rep
8270 (Enumtype
, Size_Clause
(Enumtype
), "size clause");
8275 Set_RM_Size
(Enumtype
, Minsize
);
8276 Set_Enum_Esize
(Enumtype
);
8279 Set_RM_Size
(Base_Type
(Enumtype
), RM_Size
(Enumtype
));
8280 Set_Esize
(Base_Type
(Enumtype
), Esize
(Enumtype
));
8282 Copy_Alignment
(To
=> Base_Type
(Enumtype
), From
=> Enumtype
);
8286 -- We repeat the too late test in case it froze itself
8288 if Rep_Item_Too_Late
(Enumtype
, N
) then
8291 end Analyze_Enumeration_Representation_Clause
;
8293 ----------------------------
8294 -- Analyze_Free_Statement --
8295 ----------------------------
8297 procedure Analyze_Free_Statement
(N
: Node_Id
) is
8299 Analyze
(Expression
(N
));
8300 end Analyze_Free_Statement
;
8302 ---------------------------
8303 -- Analyze_Freeze_Entity --
8304 ---------------------------
8306 procedure Analyze_Freeze_Entity
(N
: Node_Id
) is
8308 Freeze_Entity_Checks
(N
);
8309 end Analyze_Freeze_Entity
;
8311 -----------------------------------
8312 -- Analyze_Freeze_Generic_Entity --
8313 -----------------------------------
8315 procedure Analyze_Freeze_Generic_Entity
(N
: Node_Id
) is
8316 E
: constant Entity_Id
:= Entity
(N
);
8319 if not Is_Frozen
(E
) and then Has_Delayed_Aspects
(E
) then
8320 Analyze_Aspects_At_Freeze_Point
(E
);
8323 Freeze_Entity_Checks
(N
);
8324 end Analyze_Freeze_Generic_Entity
;
8326 ------------------------------------------
8327 -- Analyze_Record_Representation_Clause --
8328 ------------------------------------------
8330 -- Note: we check as much as we can here, but we can't do any checks
8331 -- based on the position values (e.g. overlap checks) until freeze time
8332 -- because especially in Ada 2005 (machine scalar mode), the processing
8333 -- for non-standard bit order can substantially change the positions.
8334 -- See procedure Check_Record_Representation_Clause (called from Freeze)
8335 -- for the remainder of this processing.
8337 procedure Analyze_Record_Representation_Clause
(N
: Node_Id
) is
8338 Ident
: constant Node_Id
:= Identifier
(N
);
8346 Rectype
: Entity_Id
;
8349 function Is_Inherited
(Comp
: Entity_Id
) return Boolean;
8350 -- True if Comp is an inherited component in a record extension
8356 function Is_Inherited
(Comp
: Entity_Id
) return Boolean is
8357 Comp_Base
: Entity_Id
;
8360 if Ekind
(Rectype
) = E_Record_Subtype
then
8361 Comp_Base
:= Original_Record_Component
(Comp
);
8366 return Comp_Base
/= Original_Record_Component
(Comp_Base
);
8371 Is_Record_Extension
: Boolean;
8372 -- True if Rectype is a record extension
8374 CR_Pragma
: Node_Id
:= Empty
;
8375 -- Points to N_Pragma node if Complete_Representation pragma present
8377 -- Start of processing for Analyze_Record_Representation_Clause
8380 if Ignore_Rep_Clauses
then
8381 Kill_Rep_Clause
(N
);
8386 Rectype
:= Entity
(Ident
);
8388 if Rectype
= Any_Type
or else Rep_Item_Too_Early
(Rectype
, N
) then
8391 Rectype
:= Underlying_Type
(Rectype
);
8394 -- First some basic error checks
8396 if not Is_Record_Type
(Rectype
) then
8398 ("record type required, found}", Ident
, First_Subtype
(Rectype
));
8401 elsif Scope
(Rectype
) /= Current_Scope
then
8402 Error_Msg_N
("type must be declared in this scope", N
);
8405 elsif not Is_First_Subtype
(Rectype
) then
8406 Error_Msg_N
("cannot give record rep clause for subtype", N
);
8409 elsif Has_Record_Rep_Clause
(Rectype
) then
8410 Error_Msg_N
("duplicate record rep clause ignored", N
);
8413 elsif Rep_Item_Too_Late
(Rectype
, N
) then
8417 -- We know we have a first subtype, now possibly go to the anonymous
8418 -- base type to determine whether Rectype is a record extension.
8420 Recdef
:= Type_Definition
(Declaration_Node
(Base_Type
(Rectype
)));
8421 Is_Record_Extension
:=
8422 Nkind
(Recdef
) = N_Derived_Type_Definition
8423 and then Present
(Record_Extension_Part
(Recdef
));
8425 if Present
(Mod_Clause
(N
)) then
8427 M
: constant Node_Id
:= Mod_Clause
(N
);
8428 P
: constant List_Id
:= Pragmas_Before
(M
);
8432 Check_Restriction
(No_Obsolescent_Features
, Mod_Clause
(N
));
8434 if Warn_On_Obsolescent_Feature
then
8436 ("?j?mod clause is an obsolescent feature (RM J.8)", N
);
8438 ("\?j?use alignment attribute definition clause instead", N
);
8445 -- Get the alignment value to perform error checking
8447 Ignore
:= Get_Alignment_Value
(Expression
(M
));
8451 -- For untagged types, clear any existing component clauses for the
8452 -- type. If the type is derived, this is what allows us to override
8453 -- a rep clause for the parent. For type extensions, the representation
8454 -- of the inherited components is inherited, so we want to keep previous
8455 -- component clauses for completeness.
8457 if not Is_Tagged_Type
(Rectype
) then
8458 Comp
:= First_Component_Or_Discriminant
(Rectype
);
8459 while Present
(Comp
) loop
8460 Set_Component_Clause
(Comp
, Empty
);
8461 Next_Component_Or_Discriminant
(Comp
);
8465 -- All done if no component clauses
8467 CC
:= First
(Component_Clauses
(N
));
8473 -- A representation like this applies to the base type
8475 Set_Has_Record_Rep_Clause
(Base_Type
(Rectype
));
8476 Set_Has_Non_Standard_Rep
(Base_Type
(Rectype
));
8477 Set_Has_Specified_Layout
(Base_Type
(Rectype
));
8479 -- Process the component clauses
8481 while Present
(CC
) loop
8485 if Nkind
(CC
) = N_Pragma
then
8488 -- The only pragma of interest is Complete_Representation
8490 if Pragma_Name
(CC
) = Name_Complete_Representation
then
8494 -- Processing for real component clause
8497 Posit
:= Static_Integer
(Position
(CC
));
8498 Fbit
:= Static_Integer
(First_Bit
(CC
));
8499 Lbit
:= Static_Integer
(Last_Bit
(CC
));
8502 and then Present
(Fbit
)
8503 and then Present
(Lbit
)
8506 Error_Msg_N
("position cannot be negative", Position
(CC
));
8509 Error_Msg_N
("first bit cannot be negative", First_Bit
(CC
));
8511 -- The Last_Bit specified in a component clause must not be
8512 -- less than the First_Bit minus one (RM-13.5.1(10)).
8514 elsif Lbit
< Fbit
- 1 then
8516 ("last bit cannot be less than first bit minus one",
8519 -- Values look OK, so find the corresponding record component
8520 -- Even though the syntax allows an attribute reference for
8521 -- implementation-defined components, GNAT does not allow the
8522 -- tag to get an explicit position.
8524 elsif Nkind
(Component_Name
(CC
)) = N_Attribute_Reference
then
8525 if Attribute_Name
(Component_Name
(CC
)) = Name_Tag
then
8526 Error_Msg_N
("position of tag cannot be specified", CC
);
8528 Error_Msg_N
("illegal component name", CC
);
8532 Comp
:= First_Entity
(Rectype
);
8533 while Present
(Comp
) loop
8534 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
8540 -- Maybe component of base type that is absent from
8541 -- statically constrained first subtype.
8543 Comp
:= First_Entity
(Base_Type
(Rectype
));
8544 while Present
(Comp
) loop
8545 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
8552 ("component clause is for non-existent field", CC
);
8554 -- Ada 2012 (AI05-0026): Any name that denotes a
8555 -- discriminant of an object of an unchecked union type
8556 -- shall not occur within a record_representation_clause.
8558 -- The general restriction of using record rep clauses on
8559 -- Unchecked_Union types has now been lifted. Since it is
8560 -- possible to introduce a record rep clause which mentions
8561 -- the discriminant of an Unchecked_Union in non-Ada 2012
8562 -- code, this check is applied to all versions of the
8565 elsif Ekind
(Comp
) = E_Discriminant
8566 and then Is_Unchecked_Union
(Rectype
)
8569 ("cannot reference discriminant of unchecked union",
8570 Component_Name
(CC
));
8572 elsif Is_Record_Extension
and then Is_Inherited
(Comp
) then
8574 ("component clause not allowed for inherited "
8575 & "component&", CC
, Comp
);
8577 elsif Present
(Component_Clause
(Comp
)) then
8579 -- Diagnose duplicate rep clause, or check consistency
8580 -- if this is an inherited component. In a double fault,
8581 -- there may be a duplicate inconsistent clause for an
8582 -- inherited component.
8584 if Scope
(Original_Record_Component
(Comp
)) = Rectype
8585 or else Parent
(Component_Clause
(Comp
)) = N
8587 Error_Msg_Sloc
:= Sloc
(Component_Clause
(Comp
));
8588 Error_Msg_N
("component clause previously given#", CC
);
8592 Rep1
: constant Node_Id
:= Component_Clause
(Comp
);
8594 if Intval
(Position
(Rep1
)) /=
8595 Intval
(Position
(CC
))
8596 or else Intval
(First_Bit
(Rep1
)) /=
8597 Intval
(First_Bit
(CC
))
8598 or else Intval
(Last_Bit
(Rep1
)) /=
8599 Intval
(Last_Bit
(CC
))
8602 ("component clause inconsistent with "
8603 & "representation of ancestor", CC
);
8605 elsif Warn_On_Redundant_Constructs
then
8607 ("?r?redundant confirming component clause "
8608 & "for component!", CC
);
8613 -- Normal case where this is the first component clause we
8614 -- have seen for this entity, so set it up properly.
8617 -- Make reference for field in record rep clause and set
8618 -- appropriate entity field in the field identifier.
8621 (Comp
, Component_Name
(CC
), Set_Ref
=> False);
8622 Set_Entity_With_Checks
(Component_Name
(CC
), Comp
);
8624 -- Update Fbit and Lbit to the actual bit number
8626 Fbit
:= Fbit
+ UI_From_Int
(SSU
) * Posit
;
8627 Lbit
:= Lbit
+ UI_From_Int
(SSU
) * Posit
;
8629 if Has_Size_Clause
(Rectype
)
8630 and then RM_Size
(Rectype
) <= Lbit
8632 Error_Msg_Uint_1
:= RM_Size
(Rectype
);
8633 Error_Msg_Uint_2
:= Lbit
+ 1;
8634 Error_Msg_N
("bit number out of range of specified "
8635 & "size (expected ^, got ^)",
8638 Set_Component_Clause
(Comp
, CC
);
8639 Set_Component_Bit_Offset
(Comp
, Fbit
);
8640 Set_Esize
(Comp
, 1 + (Lbit
- Fbit
));
8641 Set_Normalized_First_Bit
(Comp
, Fbit
mod SSU
);
8642 Set_Normalized_Position
(Comp
, Fbit
/ SSU
);
8644 if Warn_On_Overridden_Size
8645 and then Has_Size_Clause
(Etype
(Comp
))
8646 and then RM_Size
(Etype
(Comp
)) /= Esize
(Comp
)
8649 ("?.s?component size overrides size clause for&",
8650 Component_Name
(CC
), Etype
(Comp
));
8654 (Component_Name
(CC
),
8660 (Comp
, First_Node
(CC
), "component clause", Biased
);
8662 -- This information is also set in the corresponding
8663 -- component of the base type, found by accessing the
8664 -- Original_Record_Component link if it is present.
8666 Ocomp
:= Original_Record_Component
(Comp
);
8668 if Present
(Ocomp
) and then Ocomp
/= Comp
then
8669 Set_Component_Clause
(Ocomp
, CC
);
8670 Set_Component_Bit_Offset
(Ocomp
, Fbit
);
8671 Set_Esize
(Ocomp
, 1 + (Lbit
- Fbit
));
8672 Set_Normalized_First_Bit
(Ocomp
, Fbit
mod SSU
);
8673 Set_Normalized_Position
(Ocomp
, Fbit
/ SSU
);
8675 -- Note: we don't use Set_Biased here, because we
8676 -- already gave a warning above if needed, and we
8677 -- would get a duplicate for the same name here.
8679 Set_Has_Biased_Representation
8680 (Ocomp
, Has_Biased_Representation
(Comp
));
8683 if Esize
(Comp
) < 0 then
8684 Error_Msg_N
("component size is negative", CC
);
8695 -- Check missing components if Complete_Representation pragma appeared
8697 if Present
(CR_Pragma
) then
8698 Comp
:= First_Component_Or_Discriminant
(Rectype
);
8699 while Present
(Comp
) loop
8700 if No
(Component_Clause
(Comp
)) then
8702 ("missing component clause for &", CR_Pragma
, Comp
);
8705 Next_Component_Or_Discriminant
(Comp
);
8708 -- Give missing components warning if required
8710 elsif Warn_On_Unrepped_Components
then
8712 Num_Repped_Components
: Nat
:= 0;
8713 Num_Unrepped_Components
: Nat
:= 0;
8716 -- First count number of repped and unrepped components
8718 Comp
:= First_Component_Or_Discriminant
(Rectype
);
8719 while Present
(Comp
) loop
8720 if Present
(Component_Clause
(Comp
)) then
8721 Num_Repped_Components
:= Num_Repped_Components
+ 1;
8723 Num_Unrepped_Components
:= Num_Unrepped_Components
+ 1;
8726 Next_Component_Or_Discriminant
(Comp
);
8729 -- We are only interested in the case where there is at least one
8730 -- unrepped component, and at least half the components have rep
8731 -- clauses. We figure that if less than half have them, then the
8732 -- partial rep clause is really intentional. If the component
8733 -- type has no underlying type set at this point (as for a generic
8734 -- formal type), we don't know enough to give a warning on the
8737 if Num_Unrepped_Components
> 0
8738 and then Num_Unrepped_Components
< Num_Repped_Components
8740 Comp
:= First_Component_Or_Discriminant
(Rectype
);
8741 while Present
(Comp
) loop
8742 if No
(Component_Clause
(Comp
))
8743 and then Comes_From_Source
(Comp
)
8744 and then Present
(Underlying_Type
(Etype
(Comp
)))
8745 and then (Is_Scalar_Type
(Underlying_Type
(Etype
(Comp
)))
8746 or else Size_Known_At_Compile_Time
8747 (Underlying_Type
(Etype
(Comp
))))
8748 and then not Has_Warnings_Off
(Rectype
)
8750 -- Ignore discriminant in unchecked union, since it is
8751 -- not there, and cannot have a component clause.
8753 and then (not Is_Unchecked_Union
(Rectype
)
8754 or else Ekind
(Comp
) /= E_Discriminant
)
8756 Error_Msg_Sloc
:= Sloc
(Comp
);
8758 ("?.c?no component clause given for & declared #",
8762 Next_Component_Or_Discriminant
(Comp
);
8767 end Analyze_Record_Representation_Clause
;
8769 -------------------------------------
8770 -- Build_Discrete_Static_Predicate --
8771 -------------------------------------
8773 procedure Build_Discrete_Static_Predicate
8778 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
8780 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
8782 BLo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Btyp
));
8783 BHi
: constant Uint
:= Expr_Value
(Type_High_Bound
(Btyp
));
8784 -- Low bound and high bound value of base type of Typ
8788 -- Bounds for constructing the static predicate. We use the bound of the
8789 -- subtype if it is static, otherwise the corresponding base type bound.
8790 -- Note: a non-static subtype can have a static predicate.
8795 -- One entry in a Rlist value, a single REnt (range entry) value denotes
8796 -- one range from Lo to Hi. To represent a single value range Lo = Hi =
8799 type RList
is array (Nat
range <>) of REnt
;
8800 -- A list of ranges. The ranges are sorted in increasing order, and are
8801 -- disjoint (there is a gap of at least one value between each range in
8802 -- the table). A value is in the set of ranges in Rlist if it lies
8803 -- within one of these ranges.
8805 False_Range
: constant RList
:=
8806 RList
'(1 .. 0 => REnt'(No_Uint
, No_Uint
));
8807 -- An empty set of ranges represents a range list that can never be
8808 -- satisfied, since there are no ranges in which the value could lie,
8809 -- so it does not lie in any of them. False_Range is a canonical value
8810 -- for this empty set, but general processing should test for an Rlist
8811 -- with length zero (see Is_False predicate), since other null ranges
8812 -- may appear which must be treated as False.
8814 True_Range
: constant RList
:= RList
'(1 => REnt'(BLo
, BHi
));
8815 -- Range representing True, value must be in the base range
8817 function "and" (Left
: RList
; Right
: RList
) return RList
;
8818 -- And's together two range lists, returning a range list. This is a set
8819 -- intersection operation.
8821 function "or" (Left
: RList
; Right
: RList
) return RList
;
8822 -- Or's together two range lists, returning a range list. This is a set
8825 function "not" (Right
: RList
) return RList
;
8826 -- Returns complement of a given range list, i.e. a range list
8827 -- representing all the values in TLo .. THi that are not in the input
8830 function Build_Val
(V
: Uint
) return Node_Id
;
8831 -- Return an analyzed N_Identifier node referencing this value, suitable
8832 -- for use as an entry in the Static_Discrete_Predicate list. This node
8833 -- is typed with the base type.
8835 function Build_Range
(Lo
: Uint
; Hi
: Uint
) return Node_Id
;
8836 -- Return an analyzed N_Range node referencing this range, suitable for
8837 -- use as an entry in the Static_Discrete_Predicate list. This node is
8838 -- typed with the base type.
8842 Static
: access Boolean) return RList
;
8843 -- This is a recursive routine that converts the given expression into a
8844 -- list of ranges, suitable for use in building the static predicate.
8845 -- Static.all will be set to False if the expression is found to be non
8846 -- static. Note that Static.all should be set to True by the caller.
8848 function Is_False
(R
: RList
) return Boolean;
8849 pragma Inline
(Is_False
);
8850 -- Returns True if the given range list is empty, and thus represents a
8851 -- False list of ranges that can never be satisfied.
8853 function Is_True
(R
: RList
) return Boolean;
8854 -- Returns True if R trivially represents the True predicate by having a
8855 -- single range from BLo to BHi.
8857 function Is_Type_Ref
(N
: Node_Id
) return Boolean;
8858 pragma Inline
(Is_Type_Ref
);
8859 -- Returns if True if N is a reference to the type for the predicate in
8860 -- the expression (i.e. if it is an identifier whose Chars field matches
8861 -- the Nam given in the call). N must not be parenthesized, if the type
8862 -- name appears in parens, this routine will return False.
8864 function Lo_Val
(N
: Node_Id
) return Uint
;
8865 -- Given an entry from a Static_Discrete_Predicate list that is either
8866 -- a static expression or static range, gets either the expression value
8867 -- or the low bound of the range.
8869 function Hi_Val
(N
: Node_Id
) return Uint
;
8870 -- Given an entry from a Static_Discrete_Predicate list that is either
8871 -- a static expression or static range, gets either the expression value
8872 -- or the high bound of the range.
8874 function Membership_Entry
8875 (N
: Node_Id
; Static
: access Boolean) return RList
;
8876 -- Given a single membership entry (range, value, or subtype), returns
8877 -- the corresponding range list. Set Static.all to False if not static.
8879 function Membership_Entries
8880 (N
: Node_Id
; Static
: access Boolean) return RList
;
8881 -- Given an element on an alternatives list of a membership operation,
8882 -- returns the range list corresponding to this entry and all following
8883 -- entries (i.e. returns the "or" of this list of values).
8884 -- Set Static.all to False if not static.
8888 Static
: access Boolean) return RList
;
8889 -- Given a type, if it has a static predicate, then set Result to the
8890 -- predicate as a range list, otherwise set Static.all to False.
8892 procedure Warn_If_Test_Ineffective
(REntry
: REnt
; N
: Node_Id
);
8893 -- Issue a warning if REntry includes only values that are
8894 -- outside the range TLo .. THi.
8900 function "and" (Left
: RList
; Right
: RList
) return RList
is
8902 -- First range of result
8904 SLeft
: Nat
:= Left
'First;
8905 -- Start of rest of left entries
8907 SRight
: Nat
:= Right
'First;
8908 -- Start of rest of right entries
8911 -- If either range is True, return the other
8913 if Is_True
(Left
) then
8915 elsif Is_True
(Right
) then
8919 -- If either range is False, return False
8921 if Is_False
(Left
) or else Is_False
(Right
) then
8925 -- Loop to remove entries at start that are disjoint, and thus just
8926 -- get discarded from the result entirely.
8929 -- If no operands left in either operand, result is false
8931 if SLeft
> Left
'Last or else SRight
> Right
'Last then
8934 -- Discard first left operand entry if disjoint with right
8936 elsif Left
(SLeft
).Hi
< Right
(SRight
).Lo
then
8939 -- Discard first right operand entry if disjoint with left
8941 elsif Right
(SRight
).Hi
< Left
(SLeft
).Lo
then
8942 SRight
:= SRight
+ 1;
8944 -- Otherwise we have an overlapping entry
8951 -- Now we have two non-null operands, and first entries overlap. The
8952 -- first entry in the result will be the overlapping part of these
8955 FEnt
:= REnt
'(Lo => UI_Max (Left (SLeft).Lo, Right (SRight).Lo),
8956 Hi => UI_Min (Left (SLeft).Hi, Right (SRight).Hi));
8958 -- Now we can remove the entry that ended at a lower value, since its
8959 -- contribution is entirely contained in Fent.
8961 if Left (SLeft).Hi <= Right (SRight).Hi then
8964 SRight := SRight + 1;
8967 -- Compute result by concatenating this first entry with the "and" of
8968 -- the remaining parts of the left and right operands. Note that if
8969 -- either of these is empty, "and" will yield empty, so that we will
8970 -- end up with just Fent, which is what we want in that case.
8973 FEnt & (Left (SLeft .. Left'Last) and Right (SRight .. Right'Last));
8980 function "not" (Right : RList) return RList is
8982 -- Return True if False range
8984 if Is_False (Right) then
8988 -- Return False if True range
8990 if Is_True (Right) then
8994 -- Here if not trivial case
8997 Result : RList (1 .. Right'Length + 1);
8998 -- May need one more entry for gap at beginning and end
9001 -- Number of entries stored in Result
9006 if Right (Right'First).Lo > TLo then
9008 Result (Count) := REnt'(TLo
, Right
(Right
'First).Lo
- 1);
9011 -- Gaps between ranges
9013 for J
in Right
'First .. Right
'Last - 1 loop
9015 Result
(Count
) := REnt
'(Right (J).Hi + 1, Right (J + 1).Lo - 1);
9020 if Right (Right'Last).Hi < THi then
9022 Result (Count) := REnt'(Right
(Right
'Last).Hi
+ 1, THi
);
9025 return Result
(1 .. Count
);
9033 function "or" (Left
: RList
; Right
: RList
) return RList
is
9035 -- First range of result
9037 SLeft
: Nat
:= Left
'First;
9038 -- Start of rest of left entries
9040 SRight
: Nat
:= Right
'First;
9041 -- Start of rest of right entries
9044 -- If either range is True, return True
9046 if Is_True
(Left
) or else Is_True
(Right
) then
9050 -- If either range is False (empty), return the other
9052 if Is_False
(Left
) then
9054 elsif Is_False
(Right
) then
9058 -- Initialize result first entry from left or right operand depending
9059 -- on which starts with the lower range.
9061 if Left
(SLeft
).Lo
< Right
(SRight
).Lo
then
9062 FEnt
:= Left
(SLeft
);
9065 FEnt
:= Right
(SRight
);
9066 SRight
:= SRight
+ 1;
9069 -- This loop eats ranges from left and right operands that are
9070 -- contiguous with the first range we are gathering.
9073 -- Eat first entry in left operand if contiguous or overlapped by
9074 -- gathered first operand of result.
9076 if SLeft
<= Left
'Last
9077 and then Left
(SLeft
).Lo
<= FEnt
.Hi
+ 1
9079 FEnt
.Hi
:= UI_Max
(FEnt
.Hi
, Left
(SLeft
).Hi
);
9082 -- Eat first entry in right operand if contiguous or overlapped by
9083 -- gathered right operand of result.
9085 elsif SRight
<= Right
'Last
9086 and then Right
(SRight
).Lo
<= FEnt
.Hi
+ 1
9088 FEnt
.Hi
:= UI_Max
(FEnt
.Hi
, Right
(SRight
).Hi
);
9089 SRight
:= SRight
+ 1;
9091 -- All done if no more entries to eat
9098 -- Obtain result as the first entry we just computed, concatenated
9099 -- to the "or" of the remaining results (if one operand is empty,
9100 -- this will just concatenate with the other
9103 FEnt
& (Left
(SLeft
.. Left
'Last) or Right
(SRight
.. Right
'Last));
9110 function Build_Range
(Lo
: Uint
; Hi
: Uint
) return Node_Id
is
9115 Low_Bound
=> Build_Val
(Lo
),
9116 High_Bound
=> Build_Val
(Hi
));
9117 Set_Etype
(Result
, Btyp
);
9118 Set_Analyzed
(Result
);
9126 function Build_Val
(V
: Uint
) return Node_Id
is
9130 if Is_Enumeration_Type
(Typ
) then
9131 Result
:= Get_Enum_Lit_From_Pos
(Typ
, V
, Loc
);
9133 Result
:= Make_Integer_Literal
(Loc
, V
);
9136 Set_Etype
(Result
, Btyp
);
9137 Set_Is_Static_Expression
(Result
);
9138 Set_Analyzed
(Result
);
9148 Static
: access Boolean) return RList
9152 Val_Bearer
: Node_Id
;
9155 -- Static expression can only be true or false
9157 if Is_OK_Static_Expression
(Exp
) then
9158 if Expr_Value
(Exp
) = 0 then
9165 -- Otherwise test node type
9176 return Get_RList
(Left_Opnd
(Exp
), Static
)
9178 Get_RList
(Right_Opnd
(Exp
), Static
);
9185 return Get_RList
(Left_Opnd
(Exp
), Static
)
9187 Get_RList
(Right_Opnd
(Exp
), Static
);
9192 return not Get_RList
(Right_Opnd
(Exp
), Static
);
9194 -- Comparisons of type with static value
9196 when N_Op_Compare
=>
9198 -- Type is left operand
9200 if Is_Type_Ref
(Left_Opnd
(Exp
))
9201 and then Is_OK_Static_Expression
(Right_Opnd
(Exp
))
9203 Val_Bearer
:= Right_Opnd
(Exp
);
9205 -- Typ is right operand
9207 elsif Is_Type_Ref
(Right_Opnd
(Exp
))
9208 and then Is_OK_Static_Expression
(Left_Opnd
(Exp
))
9210 Val_Bearer
:= Left_Opnd
(Exp
);
9212 -- Invert sense of comparison
9215 when N_Op_Gt
=> Op
:= N_Op_Lt
;
9216 when N_Op_Lt
=> Op
:= N_Op_Gt
;
9217 when N_Op_Ge
=> Op
:= N_Op_Le
;
9218 when N_Op_Le
=> Op
:= N_Op_Ge
;
9219 when others => null;
9222 -- Other cases are non-static
9225 Static
.all := False;
9229 Val
:= Expr_Value
(Val_Bearer
);
9231 -- Construct range according to comparison operation
9238 REntry
:= (Val
, Val
);
9241 REntry
:= (Val
, THi
);
9244 REntry
:= (Val
+ 1, THi
);
9247 REntry
:= (TLo
, Val
);
9250 REntry
:= (TLo
, Val
- 1);
9253 Warn_If_Test_Ineffective
((Val
, Val
), Val_Bearer
);
9254 return RList
'(REnt'(TLo
, Val
- 1),
9255 REnt
'(Val + 1, THi));
9258 raise Program_Error;
9261 Warn_If_Test_Ineffective (REntry, Val_Bearer);
9262 return RList'(1 => REntry
);
9268 if not Is_Type_Ref
(Left_Opnd
(Exp
)) then
9269 Static
.all := False;
9273 if Present
(Right_Opnd
(Exp
)) then
9274 return Membership_Entry
(Right_Opnd
(Exp
), Static
);
9276 return Membership_Entries
9277 (First
(Alternatives
(Exp
)), Static
);
9280 -- Negative membership (NOT IN)
9283 if not Is_Type_Ref
(Left_Opnd
(Exp
)) then
9284 Static
.all := False;
9288 if Present
(Right_Opnd
(Exp
)) then
9289 return not Membership_Entry
(Right_Opnd
(Exp
), Static
);
9291 return not Membership_Entries
9292 (First
(Alternatives
(Exp
)), Static
);
9295 -- Function call, may be call to static predicate
9297 when N_Function_Call
=>
9298 if Is_Entity_Name
(Name
(Exp
)) then
9300 Ent
: constant Entity_Id
:= Entity
(Name
(Exp
));
9302 if Is_Predicate_Function
(Ent
) then
9303 return Stat_Pred
(Etype
(First_Formal
(Ent
)), Static
);
9308 -- Other function call cases are non-static
9310 Static
.all := False;
9313 -- Qualified expression, dig out the expression
9315 when N_Qualified_Expression
=>
9316 return Get_RList
(Expression
(Exp
), Static
);
9318 when N_Case_Expression
=>
9325 if not Is_Entity_Name
(Expression
(Expr
))
9326 or else Etype
(Expression
(Expr
)) /= Typ
9329 ("expression must denote subtype", Expression
(Expr
));
9333 -- Collect discrete choices in all True alternatives
9335 Choices
:= New_List
;
9336 Alt
:= First
(Alternatives
(Exp
));
9337 while Present
(Alt
) loop
9338 Dep
:= Expression
(Alt
);
9340 if not Is_OK_Static_Expression
(Dep
) then
9341 Static
.all := False;
9344 elsif Is_True
(Expr_Value
(Dep
)) then
9345 Append_List_To
(Choices
,
9346 New_Copy_List
(Discrete_Choices
(Alt
)));
9352 return Membership_Entries
(First
(Choices
), Static
);
9355 -- Expression with actions: if no actions, dig out expression
9357 when N_Expression_With_Actions
=>
9358 if Is_Empty_List
(Actions
(Exp
)) then
9359 return Get_RList
(Expression
(Exp
), Static
);
9361 Static
.all := False;
9368 return (Get_RList
(Left_Opnd
(Exp
), Static
)
9369 and not Get_RList
(Right_Opnd
(Exp
), Static
))
9370 or (Get_RList
(Right_Opnd
(Exp
), Static
)
9371 and not Get_RList
(Left_Opnd
(Exp
), Static
));
9373 -- Any other node type is non-static
9376 Static
.all := False;
9385 function Hi_Val
(N
: Node_Id
) return Uint
is
9387 if Is_OK_Static_Expression
(N
) then
9388 return Expr_Value
(N
);
9390 pragma Assert
(Nkind
(N
) = N_Range
);
9391 return Expr_Value
(High_Bound
(N
));
9399 function Is_False
(R
: RList
) return Boolean is
9401 return R
'Length = 0;
9408 function Is_True
(R
: RList
) return Boolean is
9411 and then R
(R
'First).Lo
= BLo
9412 and then R
(R
'First).Hi
= BHi
;
9419 function Is_Type_Ref
(N
: Node_Id
) return Boolean is
9421 return Nkind
(N
) = N_Identifier
9422 and then Chars
(N
) = Nam
9423 and then Paren_Count
(N
) = 0;
9430 function Lo_Val
(N
: Node_Id
) return Uint
is
9432 if Is_OK_Static_Expression
(N
) then
9433 return Expr_Value
(N
);
9435 pragma Assert
(Nkind
(N
) = N_Range
);
9436 return Expr_Value
(Low_Bound
(N
));
9440 ------------------------
9441 -- Membership_Entries --
9442 ------------------------
9444 function Membership_Entries
9445 (N
: Node_Id
; Static
: access Boolean) return RList
is
9447 if No
(Next
(N
)) then
9448 return Membership_Entry
(N
, Static
);
9450 return Membership_Entry
(N
, Static
)
9451 or Membership_Entries
(Next
(N
), Static
);
9453 end Membership_Entries
;
9455 ----------------------
9456 -- Membership_Entry --
9457 ----------------------
9459 function Membership_Entry
9460 (N
: Node_Id
; Static
: access Boolean) return RList
9469 if Nkind
(N
) = N_Range
then
9470 if not Is_OK_Static_Expression
(Low_Bound
(N
))
9472 not Is_OK_Static_Expression
(High_Bound
(N
))
9474 Static
.all := False;
9477 SLo
:= Expr_Value
(Low_Bound
(N
));
9478 SHi
:= Expr_Value
(High_Bound
(N
));
9480 REntry
: constant REnt
:= (SLo
, SHi
);
9482 Warn_If_Test_Ineffective
(REntry
, N
);
9483 return RList
'(1 => REntry);
9489 elsif Nkind (N) = N_Others_Choice then
9491 Choices : constant List_Id := Others_Discrete_Choices (N);
9493 Range_List : RList (1 .. List_Length (Choices));
9496 Choice := First (Choices);
9498 for J in Range_List'Range loop
9499 Range_List (J) := REnt'(Lo_Val
(Choice
), Hi_Val
(Choice
));
9506 -- Static expression case
9508 elsif Is_OK_Static_Expression
(N
) then
9509 Val
:= Expr_Value
(N
);
9511 REntry
: constant REnt
:= (Val
, Val
);
9513 Warn_If_Test_Ineffective
(REntry
, N
);
9514 return RList
'(1 => REntry);
9517 -- Identifier (other than static expression) case
9519 else pragma Assert (Nkind (N) in N_Expanded_Name | N_Identifier);
9523 if Is_Type (Entity (N)) then
9525 -- If type has predicates, process them
9527 if Has_Predicates (Entity (N)) then
9528 return Stat_Pred (Entity (N), Static);
9530 -- For static subtype without predicates, get range
9532 elsif Is_OK_Static_Subtype (Entity (N)) then
9533 SLo := Expr_Value (Type_Low_Bound (Entity (N)));
9534 SHi := Expr_Value (Type_High_Bound (Entity (N)));
9535 return RList'(1 => REnt
'(SLo, SHi));
9537 -- Any other type makes us non-static
9540 Static.all := False;
9544 -- Any other kind of identifier in predicate (e.g. a non-static
9545 -- expression value) means this is not a static predicate.
9548 Static.all := False;
9552 end Membership_Entry;
9560 Static : access Boolean) return RList is
9562 -- Not static if type does not have static predicates
9564 if not Has_Static_Predicate (Typ) then
9565 Static.all := False;
9569 -- Otherwise we convert the predicate list to a range list
9572 Spred : constant List_Id := Static_Discrete_Predicate (Typ);
9573 Result : RList (1 .. List_Length (Spred));
9577 P := First (Static_Discrete_Predicate (Typ));
9578 for J in Result'Range loop
9579 Result (J) := REnt'(Lo_Val
(P
), Hi_Val
(P
));
9587 procedure Warn_If_Test_Ineffective
(REntry
: REnt
; N
: Node_Id
) is
9589 procedure IPT_Warning
(Msg
: String);
9595 procedure IPT_Warning
(Msg
: String) is
9597 Error_Msg_N
("ineffective predicate test " & Msg
& "?_s?", N
);
9600 -- Start of processing for Warn_If_Test_Ineffective
9603 -- Do nothing if warning disabled
9605 if not Warn_On_Ineffective_Predicate_Test
then
9608 -- skip null-range corner cases
9610 elsif REntry
.Lo
> REntry
.Hi
or else TLo
> THi
then
9613 -- warn if no overlap between subtype bounds and the given range
9615 elsif REntry
.Lo
> THi
or else REntry
.Hi
< TLo
then
9616 Error_Msg_Uint_1
:= REntry
.Lo
;
9617 if REntry
.Lo
/= REntry
.Hi
then
9618 Error_Msg_Uint_2
:= REntry
.Hi
;
9619 IPT_Warning
("range: ^ .. ^");
9620 elsif Is_Enumeration_Type
(Typ
) and then
9621 Nkind
(N
) in N_Identifier | N_Expanded_Name
9623 IPT_Warning
("value: &");
9625 IPT_Warning
("value: ^");
9628 end Warn_If_Test_Ineffective
;
9630 -- Start of processing for Build_Discrete_Static_Predicate
9633 -- Establish bounds for the predicate
9635 if Compile_Time_Known_Value
(Type_Low_Bound
(Typ
)) then
9636 TLo
:= Expr_Value
(Type_Low_Bound
(Typ
));
9641 if Compile_Time_Known_Value
(Type_High_Bound
(Typ
)) then
9642 THi
:= Expr_Value
(Type_High_Bound
(Typ
));
9647 -- Analyze the expression to see if it is a static predicate
9650 Static
: aliased Boolean := True;
9651 Ranges
: constant RList
:= Get_RList
(Expr
, Static
'Access);
9652 -- Range list from expression if it is static
9657 -- If non-static, return doing nothing
9663 -- Convert range list into a form for the static predicate. In the
9664 -- Ranges array, we just have raw ranges, these must be converted
9665 -- to properly typed and analyzed static expressions or range nodes.
9667 -- Note: here we limit ranges to the ranges of the subtype, so that
9668 -- a predicate is always false for values outside the subtype. That
9669 -- seems fine, such values are invalid anyway, and considering them
9670 -- to fail the predicate seems allowed and friendly, and furthermore
9671 -- simplifies processing for case statements and loops.
9675 for J
in Ranges
'Range loop
9677 Lo
: Uint
:= Ranges
(J
).Lo
;
9678 Hi
: Uint
:= Ranges
(J
).Hi
;
9681 -- Ignore completely out of range entry
9683 if Hi
< TLo
or else Lo
> THi
then
9686 -- Otherwise process entry
9689 -- Adjust out of range value to subtype range
9699 -- Convert range into required form
9701 Append_To
(Plist
, Build_Range
(Lo
, Hi
));
9706 -- Processing was successful and all entries were static, so now we
9707 -- can store the result as the predicate list.
9709 Set_Static_Discrete_Predicate
(Typ
, Plist
);
9711 -- Within a generic the predicate functions themselves need not
9714 if Inside_A_Generic
then
9718 -- The processing for static predicates put the expression into
9719 -- canonical form as a series of ranges. It also eliminated
9720 -- duplicates and collapsed and combined ranges. We might as well
9721 -- replace the alternatives list of the right operand of the
9722 -- membership test with the static predicate list, which will
9723 -- usually be more efficient.
9726 New_Alts
: constant List_Id
:= New_List
;
9731 Old_Node
:= First
(Plist
);
9732 while Present
(Old_Node
) loop
9733 New_Node
:= New_Copy
(Old_Node
);
9735 if Nkind
(New_Node
) = N_Range
then
9736 Set_Low_Bound
(New_Node
, New_Copy
(Low_Bound
(Old_Node
)));
9737 Set_High_Bound
(New_Node
, New_Copy
(High_Bound
(Old_Node
)));
9740 Append_To
(New_Alts
, New_Node
);
9744 -- If empty list, replace by False
9746 if Is_Empty_List
(New_Alts
) then
9747 Rewrite
(Expr
, New_Occurrence_Of
(Standard_False
, Loc
));
9749 -- Else replace by set membership test
9754 Left_Opnd
=> Make_Identifier
(Loc
, Nam
),
9755 Right_Opnd
=> Empty
,
9756 Alternatives
=> New_Alts
));
9758 -- Resolve new expression in function context
9760 Install_Formals
(Predicate_Function
(Typ
));
9761 Push_Scope
(Predicate_Function
(Typ
));
9762 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
9767 end Build_Discrete_Static_Predicate
;
9769 --------------------------------
9770 -- Build_Export_Import_Pragma --
9771 --------------------------------
9773 function Build_Export_Import_Pragma
9775 Id
: Entity_Id
) return Node_Id
9777 Asp_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Asp
);
9778 Expr
: constant Node_Id
:= Expression
(Asp
);
9779 Loc
: constant Source_Ptr
:= Sloc
(Asp
);
9790 Create_Pragma
: Boolean := False;
9791 -- This flag is set when the aspect form is such that it warrants the
9792 -- creation of a corresponding pragma.
9795 if Present
(Expr
) then
9796 if Error_Posted
(Expr
) then
9799 elsif Is_True
(Expr_Value
(Expr
)) then
9800 Create_Pragma
:= True;
9803 -- Otherwise the aspect defaults to True
9806 Create_Pragma
:= True;
9809 -- Nothing to do when the expression is False or is erroneous
9811 if not Create_Pragma
then
9815 -- Obtain all interfacing aspects that apply to the related entity
9817 Get_Interfacing_Aspects
9821 Expo_Asp
=> Dummy_1
,
9827 -- Handle the convention argument
9829 if Present
(Conv
) then
9830 Conv_Arg
:= New_Copy_Tree
(Expression
(Conv
));
9832 -- Assume convention "Ada' when aspect Convention is missing
9835 Conv_Arg
:= Make_Identifier
(Loc
, Name_Ada
);
9839 Make_Pragma_Argument_Association
(Loc
,
9840 Chars
=> Name_Convention
,
9841 Expression
=> Conv_Arg
));
9843 -- Handle the entity argument
9846 Make_Pragma_Argument_Association
(Loc
,
9847 Chars
=> Name_Entity
,
9848 Expression
=> New_Occurrence_Of
(Id
, Loc
)));
9850 -- Handle the External_Name argument
9852 if Present
(EN
) then
9854 Make_Pragma_Argument_Association
(Loc
,
9855 Chars
=> Name_External_Name
,
9856 Expression
=> New_Copy_Tree
(Expression
(EN
))));
9859 -- Handle the Link_Name argument
9861 if Present
(LN
) then
9863 Make_Pragma_Argument_Association
(Loc
,
9864 Chars
=> Name_Link_Name
,
9865 Expression
=> New_Copy_Tree
(Expression
(LN
))));
9869 -- pragma Export/Import
9870 -- (Convention => <Conv>/Ada,
9872 -- [External_Name => <EN>,]
9873 -- [Link_Name => <LN>]);
9877 Pragma_Identifier
=>
9878 Make_Identifier
(Loc
, Chars
(Identifier
(Asp
))),
9879 Pragma_Argument_Associations
=> Args
);
9881 -- Decorate the relevant aspect and the pragma
9883 Set_Aspect_Rep_Item
(Asp
, Prag
);
9885 Set_Corresponding_Aspect
(Prag
, Asp
);
9886 Set_From_Aspect_Specification
(Prag
);
9887 Set_Parent
(Prag
, Asp
);
9889 if Asp_Id
= Aspect_Import
and then Is_Subprogram
(Id
) then
9890 Set_Import_Pragma
(Id
, Prag
);
9894 end Build_Export_Import_Pragma
;
9896 ------------------------------
9897 -- Build_Predicate_Function --
9898 ------------------------------
9900 -- The function constructed here has the form:
9902 -- function typPredicate (Ixxx : typ) return Boolean is
9905 -- typ1Predicate (typ1 (Ixxx))
9906 -- and then typ2Predicate (typ2 (Ixxx))
9908 -- and then exp1 and then exp2 and then ...;
9909 -- end typPredicate;
9911 -- If Predicate_Function_Needs_Membership_Parameter is true, then this
9912 -- function takes an additional boolean parameter; the parameter
9913 -- indicates whether the predicate evaluation is part of a membership
9914 -- test. This parameter is used in two cases: 1) It is passed along
9915 -- if another predicate function is called and that predicate function
9916 -- expects to be passed a boolean parameter. 2) If the Predicate_Failure
9917 -- aspect is directly specified for typ, then we replace the return
9918 -- expression described above with
9919 -- (if <expression described above> then True
9920 -- elsif For_Membership_Test then False
9921 -- else (raise Assertion_Error
9922 -- with <Predicate_Failure expression>))
9923 -- Here exp1, and exp2 are expressions from Predicate pragmas. Note that
9924 -- this is the point at which these expressions get analyzed, providing the
9925 -- required delay, and typ1, typ2, are entities from which predicates are
9926 -- inherited. Note that we do NOT generate Check pragmas, that's because we
9927 -- use this function even if checks are off, e.g. for membership tests.
9929 -- Note that the inherited predicates are evaluated first, as required by
9932 -- Note that Sem_Eval.Real_Or_String_Static_Predicate_Matches depends on
9933 -- the form of this return expression.
9935 -- WARNING: This routine manages Ghost regions. Return statements must be
9936 -- replaced by gotos which jump to the end of the routine and restore the
9939 procedure Build_Predicate_Function
(Typ
: Entity_Id
; N
: Node_Id
) is
9940 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
9942 Saved_GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
9943 Saved_IGR
: constant Node_Id
:= Ignored_Ghost_Region
;
9944 -- Save the Ghost-related attributes to restore on exit
9947 -- This is the expression for the result of the function. It is
9948 -- is build by connecting the component predicates with AND THEN.
9950 Object_Name
: Name_Id
;
9951 -- Name for argument of Predicate procedure. Note that we use the same
9952 -- name for both predicate functions. That way the reference within the
9953 -- predicate expression is the same in both functions.
9955 Object_Entity
: Entity_Id
;
9956 -- Entity for argument of Predicate procedure
9959 -- The function declaration
9964 Restore_Scope
: Boolean;
9965 -- True if the current scope must be restored on exit
9967 Ancestor_Predicate_Function_Called
: Boolean := False;
9968 -- Does this predicate function include a call to the
9969 -- predication function of an ancestor subtype?
9971 procedure Add_Condition
(Cond
: Node_Id
);
9972 -- Append Cond to Expr using "and then" (or just copy Cond to Expr if
9975 procedure Add_Predicates
;
9976 -- Appends expressions for any Predicate pragmas in the rep item chain
9977 -- Typ to Expr. Note that we look only at items for this exact entity.
9978 -- Inheritance of predicates for the parent type is done by calling the
9979 -- Predicate_Function of the parent type, using Add_Call above.
9981 procedure Add_Call
(T
: Entity_Id
);
9982 -- Includes a call to the predicate function for type T in Expr if
9983 -- Predicate_Function (T) is non-empty.
9985 procedure Replace_Current_Instance_References
9986 (N
: Node_Id
; Typ
, New_Entity
: Entity_Id
);
9987 -- Replace all references to Typ in the tree rooted at N with
9988 -- references to Param. [New_Entity will be a formal parameter of a
9989 -- predicate function.]
9995 procedure Add_Call
(T
: Entity_Id
) is
9999 if Present
(Predicate_Function
(T
)) then
10000 pragma Assert
(Has_Predicates
(Typ
));
10002 -- Build the call to the predicate function of T. The type may be
10003 -- derived, so use an unchecked conversion for the actual.
10006 Dynamic_Mem
: Node_Id
:= Empty
;
10007 Second_Formal
: constant Entity_Id
:=
10008 Next_Entity
(Object_Entity
);
10010 -- Some predicate functions require a second parameter;
10011 -- If one predicate function calls another and the second
10012 -- requires two parameters, then the first should also
10013 -- take two parameters (so that the first function has
10014 -- something to pass to the second function).
10015 if Predicate_Function_Needs_Membership_Parameter
(T
) then
10016 pragma Assert
(Present
(Second_Formal
));
10017 Dynamic_Mem
:= New_Occurrence_Of
(Second_Formal
, Loc
);
10021 Make_Predicate_Call
10024 Unchecked_Convert_To
(T
,
10025 Make_Identifier
(Loc
, Object_Name
)),
10026 Dynamic_Mem
=> Dynamic_Mem
);
10029 -- "and"-in the call to evolving expression
10031 Add_Condition
(Exp
);
10032 Ancestor_Predicate_Function_Called
:= True;
10034 -- Output info message on inheritance if required. Note we do not
10035 -- give this information for generic actual types, since it is
10036 -- unwelcome noise in that case in instantiations. We also
10037 -- generally suppress the message in instantiations, and also
10038 -- if it involves internal names.
10040 if List_Inherited_Aspects
10041 and then not Is_Generic_Actual_Type
(Typ
)
10042 and then Instantiation_Location
(Sloc
(Typ
)) = No_Location
10043 and then not Is_Internal_Name
(Chars
(T
))
10044 and then not Is_Internal_Name
(Chars
(Typ
))
10046 Error_Msg_Sloc
:= Sloc
(Predicate_Function
(T
));
10047 Error_Msg_Node_2
:= T
;
10048 Error_Msg_N
("info: & inherits predicate from & #?.l?", Typ
);
10053 -------------------
10054 -- Add_Condition --
10055 -------------------
10057 procedure Add_Condition
(Cond
: Node_Id
) is
10059 -- This is the first predicate expression
10064 -- Otherwise concatenate to the existing predicate expressions by
10065 -- using "and then".
10069 Make_And_Then
(Loc
,
10070 Left_Opnd
=> Relocate_Node
(Expr
),
10071 Right_Opnd
=> Cond
);
10075 --------------------
10076 -- Add_Predicates --
10077 --------------------
10079 procedure Add_Predicates
is
10080 procedure Add_Predicate
(Prag
: Node_Id
);
10081 -- Concatenate the expression of predicate pragma Prag to Expr by
10082 -- using a short circuit "and then" operator.
10084 -------------------
10085 -- Add_Predicate --
10086 -------------------
10088 procedure Add_Predicate
(Prag
: Node_Id
) is
10091 Asp
: constant Node_Id
:= Corresponding_Aspect
(Prag
);
10095 -- Start of processing for Add_Predicate
10098 -- Mark corresponding SCO as enabled
10100 Set_SCO_Pragma_Enabled
(Sloc
(Prag
));
10102 -- Extract the arguments of the pragma
10104 Arg1
:= First
(Pragma_Argument_Associations
(Prag
));
10105 Arg2
:= Next
(Arg1
);
10107 Arg1
:= Get_Pragma_Arg
(Arg1
);
10108 Arg2
:= Get_Pragma_Arg
(Arg2
);
10110 -- When the predicate pragma applies to the current type or its
10111 -- full view, replace all occurrences of the subtype name with
10112 -- references to the formal parameter of the predicate function.
10114 if Entity
(Arg1
) = Typ
10115 or else Full_View
(Entity
(Arg1
)) = Typ
10118 Arg2_Copy
: constant Node_Id
:= New_Copy_Tree
(Arg2
);
10120 Replace_Current_Instance_References
10121 (Arg2_Copy
, Typ
=> Typ
, New_Entity
=> Object_Entity
);
10123 -- If the predicate pragma comes from an aspect, replace the
10124 -- saved expression because we need the subtype references
10125 -- replaced for the calls to Preanalyze_Spec_Expression in
10126 -- Check_Aspect_At_xxx routines.
10128 if Present
(Asp
) then
10129 Set_Entity
(Identifier
(Asp
), New_Copy_Tree
(Arg2_Copy
));
10132 -- "and"-in the Arg2 condition to evolving expression
10134 Add_Condition
(Arg2_Copy
);
10143 -- Start of processing for Add_Predicates
10146 Ritem
:= First_Rep_Item
(Typ
);
10148 -- If the type is private, check whether full view has inherited
10151 if Is_Private_Type
(Typ
)
10152 and then No
(Ritem
)
10153 and then Present
(Full_View
(Typ
))
10155 Ritem
:= First_Rep_Item
(Full_View
(Typ
));
10158 while Present
(Ritem
) loop
10159 if Nkind
(Ritem
) = N_Pragma
10160 and then Pragma_Name
(Ritem
) = Name_Predicate
10162 Add_Predicate
(Ritem
);
10164 -- If the type is declared in an inner package it may be frozen
10165 -- outside of the package, and the generated pragma has not been
10166 -- analyzed yet, so capture the expression for the predicate
10167 -- function at this point.
10169 elsif Nkind
(Ritem
) = N_Aspect_Specification
10170 and then Present
(Aspect_Rep_Item
(Ritem
))
10171 and then Scope_Depth
(Scope
(Typ
)) > Scope_Depth
(Current_Scope
)
10174 Prag
: constant Node_Id
:= Aspect_Rep_Item
(Ritem
);
10177 if Nkind
(Prag
) = N_Pragma
10178 and then Pragma_Name
(Prag
) = Name_Predicate
10180 Add_Predicate
(Prag
);
10185 Next_Rep_Item
(Ritem
);
10187 end Add_Predicates
;
10189 -----------------------------------------
10190 -- Replace_Current_Instance_References --
10191 -----------------------------------------
10193 procedure Replace_Current_Instance_References
10194 (N
: Node_Id
; Typ
, New_Entity
: Entity_Id
)
10196 Root
: Node_Id
renames N
;
10198 procedure Replace_One_Reference
(N
: Node_Id
);
10199 -- Actual parameter for Replace_Type_References_Generic instance
10201 ---------------------------
10202 -- Replace_One_Reference --
10203 ---------------------------
10205 procedure Replace_One_Reference
(N
: Node_Id
) is
10206 pragma Assert
(In_Subtree
(N
, Root
=> Root
));
10208 Rewrite
(N
, New_Occurrence_Of
(New_Entity
, Sloc
(N
)));
10209 -- Use the Sloc of the usage name, not the defining name
10210 end Replace_One_Reference
;
10212 procedure Replace_Type_References
is
10213 new Replace_Type_References_Generic
(Replace_One_Reference
);
10215 Replace_Type_References
(N
, Typ
);
10216 end Replace_Current_Instance_References
;
10218 -- Start of processing for Build_Predicate_Function
10221 -- Return if already built, if type does not have predicates,
10222 -- or if type is a constructed subtype that will inherit a
10223 -- predicate function from its ancestor. In a generic context
10224 -- the predicated parent may not have a predicate function yet
10225 -- but we don't want to build a new one for the subtype. This can
10226 -- happen in an instance body which is nested within a generic
10227 -- unit, in which case Within_A_Generic may be false, SId is
10228 -- Empty, but uses of Typ will receive a predicate check in a
10229 -- context where expansion and tests are enabled.
10231 SId
:= Predicate_Function
(Typ
);
10232 if not Has_Predicates
(Typ
)
10233 or else (Present
(SId
) and then Has_Completion
(SId
))
10236 and then not Comes_From_Source
(Typ
)
10237 and then Ekind
(Typ
) in E_Array_Subtype
10239 | E_Record_Subtype_With_Private
10240 and then Present
(Predicated_Parent
(Typ
)))
10244 -- Do not generate predicate bodies within a generic unit. The
10245 -- expressions have been analyzed already, and the bodies play no role
10246 -- if not within an executable unit. However, if a static predicate is
10247 -- present it must be processed for legality checks such as case
10248 -- coverage in an expression.
10250 elsif Inside_A_Generic
10251 and then not Has_Static_Predicate_Aspect
(Typ
)
10256 -- Ensure that the declarations are added to the scope of the type
10258 if Scope
(Typ
) /= Current_Scope
then
10259 Push_Scope
(Scope
(Typ
));
10260 Restore_Scope
:= True;
10262 Restore_Scope
:= False;
10265 -- The related type may be subject to pragma Ghost. Set the mode now to
10266 -- ensure that the predicate functions are properly marked as Ghost.
10268 Set_Ghost_Mode
(Typ
);
10270 -- Prepare to construct predicate expression
10274 if Present
(SId
) then
10275 FDecl
:= Unit_Declaration_Node
(SId
);
10278 FDecl
:= Build_Predicate_Function_Declaration
(Typ
);
10279 SId
:= Defining_Entity
(FDecl
);
10282 -- Recover name of formal parameter of function that replaces references
10283 -- to the type in predicate expressions.
10286 Defining_Identifier
10287 (First
(Parameter_Specifications
(Specification
(FDecl
))));
10289 Object_Name
:= Chars
(Object_Entity
);
10291 -- Add predicates for ancestor if present. These must come before the
10292 -- ones for the current type, as required by AI12-0071-1.
10294 -- Looks like predicates aren't added for case of inheriting from
10295 -- multiple progenitors???
10300 Atyp
:= Nearest_Ancestor
(Typ
);
10302 -- The type may be private but the full view may inherit predicates
10304 if No
(Atyp
) and then Is_Private_Type
(Typ
) then
10305 Atyp
:= Nearest_Ancestor
(Full_View
(Typ
));
10308 if Present
(Atyp
) then
10313 -- Add Predicates for the current type
10317 -- Case where predicates are present
10319 if Present
(Expr
) then
10321 -- Build the main predicate function
10324 SIdB
: constant Entity_Id
:=
10325 Make_Defining_Identifier
(Loc
,
10326 Chars
=> New_External_Name
(Chars
(Typ
), "Predicate"));
10327 -- The entity for the function body
10333 Mutate_Ekind
(SIdB
, E_Function
);
10334 Set_Is_Predicate_Function
(SIdB
);
10336 -- Build function body
10339 Param_Specs
: constant List_Id
:= New_List
(
10340 Make_Parameter_Specification
(Loc
,
10341 Defining_Identifier
=>
10342 Make_Defining_Identifier
(Loc
, Object_Name
),
10344 New_Occurrence_Of
(Typ
, Loc
)));
10346 -- if Spec has 2 parameters, then body should too
10347 if Present
(Next_Entity
(Object_Entity
)) then
10348 Append
(Make_Parameter_Specification
(Loc
,
10349 Defining_Identifier
=>
10350 Make_Defining_Identifier
10351 (Loc
, Chars
(Next_Entity
(Object_Entity
))),
10353 New_Occurrence_Of
(Standard_Boolean
, Loc
)),
10358 Make_Function_Specification
(Loc
,
10359 Defining_Unit_Name
=> SIdB
,
10360 Parameter_Specifications
=> Param_Specs
,
10361 Result_Definition
=>
10362 New_Occurrence_Of
(Standard_Boolean
, Loc
));
10365 -- The Predicate_Expression attribute is used by SPARK.
10367 -- If Ancestor_Predicate_Function_Called is True, then
10368 -- we try to exclude that call to the ancestor's
10369 -- predicate function by calling Right_Opnd.
10370 -- The call is not excluded in the case where
10371 -- it is not "and"ed with anything else (so we don't have
10372 -- an N_And_Then node). This exclusion is required if the
10373 -- Predicate_Failure aspect is specified for Typ because
10374 -- in that case we are going to drop the N_And_Then node
10375 -- on the floor. Otherwise, it is a question of what is
10376 -- most convenient for SPARK.
10378 Set_Predicate_Expression
10379 (SId
, (if Ancestor_Predicate_Function_Called
10380 and then Nkind
(Expr
) = N_And_Then
10381 then Right_Opnd
(Expr
)
10385 Result_Expr
: Node_Id
:= Expr
;
10386 PF_Expr
: Node_Id
:= Predicate_Failure_Expression
10387 (Typ
, Inherited_OK
=> False);
10388 PF_Expr_Copy
: Node_Id
;
10389 Second_Formal
: constant Entity_Id
:=
10390 Next_Entity
(Object_Entity
);
10392 -- In GNATprove mode we are only interested in the predicate
10393 -- expression itself and don't want a raise expression that
10394 -- comes from the Predicate_Failure. Ditto for CodePeer.
10395 -- And an illegal Predicate_Failure aspect can lead to cases
10396 -- we want to avoid.
10398 if Present
(PF_Expr
)
10399 and then not GNATprove_Mode
10400 and then not CodePeer_Mode
10401 and then Serious_Errors_Detected
= 0
10403 pragma Assert
(Present
(Second_Formal
));
10405 -- This is an ugly hack to cope with an ugly situation.
10406 -- PF_Expr may have children whose Parent attribute
10407 -- does not point back to PF_Expr. If we pass such a
10408 -- tree to New_Copy_Tree, then it does not make a deep
10409 -- copy. But we need a deep copy. So we need to find a
10410 -- tree for which New_Copy_Tree *will* make a deep copy.
10413 function Check_Node_Parent
(Parent_Node
, Node
: Node_Id
)
10414 return Traverse_Result
;
10415 function Check_Node_Parent
(Parent_Node
, Node
: Node_Id
)
10416 return Traverse_Result
is
10418 if Parent_Node
= PF_Expr
10419 and then not Is_List_Member
(Node
)
10422 (Nkind
(PF_Expr
) = Nkind
(Parent
(Node
)));
10424 -- We need PF_Expr to be a node for which
10425 -- New_Copy_Tree will make a deep copy.
10426 PF_Expr
:= Parent
(Node
);
10430 end Check_Node_Parent
;
10431 procedure Check_Parentage
is
10432 new Traverse_Proc_With_Parent
(Check_Node_Parent
);
10434 Check_Parentage
(PF_Expr
);
10435 PF_Expr_Copy
:= New_Copy_Tree
(PF_Expr
);
10438 -- Current instance uses need to have their Entity
10439 -- fields set so that Replace_Current_Instance_References
10440 -- can find them. So we preanalyze. Just for purposes of
10441 -- calls to Is_Current_Instance during this preanalysis,
10442 -- we set the Parent field.
10443 Set_Parent
(PF_Expr_Copy
, Parent
(PF_Expr
));
10444 Preanalyze
(PF_Expr_Copy
);
10445 Set_Parent
(PF_Expr_Copy
, Empty
);
10447 Replace_Current_Instance_References
10448 (PF_Expr_Copy
, Typ
=> Typ
, New_Entity
=> Object_Entity
);
10450 if Ancestor_Predicate_Function_Called
then
10451 -- If the call to an ancestor predicate function
10452 -- returns False, we do not want to raise an
10453 -- exception here. Our Predicate_Failure aspect does
10454 -- not apply in that case. So we have to build a
10455 -- more complicated result expression:
10456 -- (if not Ancestor_Predicate_Function (...) then False
10457 -- elsif Noninherited_Predicates (...) then True
10458 -- elsif Is_Membership_Test then False
10459 -- else (raise Assertion_Error with PF text))
10462 Ancestor_Call
: constant Node_Id
:=
10463 Left_Opnd
(Result_Expr
);
10464 Local_Preds
: constant Node_Id
:=
10465 Right_Opnd
(Result_Expr
);
10468 Make_If_Expression
(Loc
,
10469 Expressions
=> New_List
(
10470 Make_Op_Not
(Loc
, Ancestor_Call
),
10471 New_Occurrence_Of
(Standard_False
, Loc
),
10472 Make_If_Expression
(Loc
,
10474 Expressions
=> New_List
(
10476 New_Occurrence_Of
(Standard_True
, Loc
),
10477 Make_If_Expression
(Loc
,
10479 Expressions
=> New_List
(
10480 New_Occurrence_Of
(Second_Formal
, Loc
),
10481 New_Occurrence_Of
(Standard_False
, Loc
),
10482 Make_Raise_Expression
(Loc
,
10483 New_Occurrence_Of
(RTE
10484 (RE_Assert_Failure
), Loc
),
10485 PF_Expr_Copy
)))))));
10489 -- Build a conditional expression:
10490 -- (if <predicate evaluates to True> then True
10491 -- elsif Is_Membership_Test then False
10492 -- else (raise Assertion_Error with PF text))
10495 Make_If_Expression
(Loc
,
10496 Expressions
=> New_List
(
10498 New_Occurrence_Of
(Standard_True
, Loc
),
10499 Make_If_Expression
(Loc
,
10501 Expressions
=> New_List
(
10502 New_Occurrence_Of
(Second_Formal
, Loc
),
10503 New_Occurrence_Of
(Standard_False
, Loc
),
10504 Make_Raise_Expression
(Loc
,
10505 New_Occurrence_Of
(RTE
10506 (RE_Assert_Failure
), Loc
),
10512 Make_Subprogram_Body
(Loc
,
10513 Specification
=> Spec
,
10514 Declarations
=> Empty_List
,
10515 Handled_Statement_Sequence
=>
10516 Make_Handled_Sequence_Of_Statements
(Loc
,
10517 Statements
=> New_List
(
10518 Make_Simple_Return_Statement
(Loc
,
10519 Expression
=> Result_Expr
))));
10522 -- The declaration has been analyzed when created, and placed
10523 -- after type declaration. Insert body itself after freeze node,
10524 -- unless subprogram declaration is already there, in which case
10525 -- body better be placed afterwards.
10527 if FDecl
= Next
(N
) then
10528 Insert_After_And_Analyze
(FDecl
, FBody
);
10530 Insert_After_And_Analyze
(N
, FBody
);
10533 -- The defining identifier of a quantified expression carries the
10534 -- scope in which the type appears, but when unnesting we need
10535 -- to indicate that its proper scope is the constructed predicate
10536 -- function. The quantified expressions have been converted into
10537 -- loops during analysis and expansion.
10540 function Reset_Quantified_Variable_Scope
10541 (N
: Node_Id
) return Traverse_Result
;
10543 procedure Reset_Quantified_Variables_Scope
is
10544 new Traverse_Proc
(Reset_Quantified_Variable_Scope
);
10546 -------------------------------------
10547 -- Reset_Quantified_Variable_Scope --
10548 -------------------------------------
10550 function Reset_Quantified_Variable_Scope
10551 (N
: Node_Id
) return Traverse_Result
is
10553 if Nkind
(N
) in N_Iterator_Specification
10554 | N_Loop_Parameter_Specification
10556 Set_Scope
(Defining_Identifier
(N
),
10557 Predicate_Function
(Typ
));
10561 end Reset_Quantified_Variable_Scope
;
10564 if Unnest_Subprogram_Mode
then
10565 Reset_Quantified_Variables_Scope
(Expr
);
10569 -- Within a generic unit, prevent a double analysis of the body
10570 -- which will not be marked analyzed yet. This will happen when
10571 -- the freeze node is created during the preanalysis of an
10572 -- expression function.
10574 if Inside_A_Generic
then
10575 Set_Analyzed
(FBody
);
10578 -- Static predicate functions are always side-effect free, and
10579 -- in most cases dynamic predicate functions are as well. Mark
10580 -- them as such whenever possible, so redundant predicate checks
10581 -- can be optimized. If there is a variable reference within the
10582 -- expression, the function is not pure.
10584 if Expander_Active
then
10586 Side_Effect_Free
(Expr
, Variable_Ref
=> True));
10587 Set_Is_Inlined
(SId
);
10591 -- See if we have a static predicate. Note that the answer may be
10592 -- yes even if we have an explicit Dynamic_Predicate present.
10599 if not Is_Scalar_Type
(Typ
) and then not Is_String_Type
(Typ
) then
10602 PS
:= Is_Predicate_Static
(Expr
, Object_Name
);
10605 -- Case where we have a predicate-static aspect
10609 -- We don't set Has_Static_Predicate_Aspect, since we can have
10610 -- any of the three cases (Predicate, Dynamic_Predicate, or
10611 -- Static_Predicate) generating a predicate with an expression
10612 -- that is predicate-static. We just indicate that we have a
10613 -- predicate that can be treated as static.
10615 Set_Has_Static_Predicate
(Typ
);
10617 -- For discrete subtype, build the static predicate list
10619 if Is_Discrete_Type
(Typ
) then
10620 Build_Discrete_Static_Predicate
(Typ
, Expr
, Object_Name
);
10622 -- If we don't get a static predicate list, it means that we
10623 -- have a case where this is not possible, most typically in
10624 -- the case where we inherit a dynamic predicate. We do not
10625 -- consider this an error, we just leave the predicate as
10626 -- dynamic. But if we do succeed in building the list, then
10627 -- we mark the predicate as static.
10629 if No
(Static_Discrete_Predicate
(Typ
)) then
10630 Set_Has_Static_Predicate
(Typ
, False);
10633 -- For real or string subtype, save predicate expression
10635 elsif Is_Real_Type
(Typ
) or else Is_String_Type
(Typ
) then
10636 Set_Static_Real_Or_String_Predicate
(Typ
, Expr
);
10639 -- Case of dynamic predicate (expression is not predicate-static)
10642 -- Again, we don't set Has_Dynamic_Predicate_Aspect, since that
10643 -- is only set if we have an explicit Dynamic_Predicate aspect
10644 -- given. Here we may simply have a Predicate aspect where the
10645 -- expression happens not to be predicate-static.
10647 -- Emit an error when the predicate is categorized as static
10648 -- but its expression is not predicate-static.
10650 -- First a little fiddling to get a nice location for the
10651 -- message. If the expression is of the form (A and then B),
10652 -- where A is an inherited predicate, then use the right
10653 -- operand for the Sloc. This avoids getting confused by a call
10654 -- to an inherited predicate with a less convenient source
10658 while Nkind
(EN
) = N_And_Then
10659 and then Nkind
(Left_Opnd
(EN
)) = N_Function_Call
10660 and then Is_Predicate_Function
10661 (Entity
(Name
(Left_Opnd
(EN
))))
10663 EN
:= Right_Opnd
(EN
);
10666 -- Now post appropriate message
10668 if Has_Static_Predicate_Aspect
(Typ
) then
10669 if Is_Scalar_Type
(Typ
) or else Is_String_Type
(Typ
) then
10671 ("expression is not predicate-static (RM 3.2.4(16-22))",
10675 ("static predicate requires scalar or string type", EN
);
10682 Restore_Ghost_Region
(Saved_GM
, Saved_IGR
);
10684 if Restore_Scope
then
10687 end Build_Predicate_Function
;
10689 ------------------------------------------
10690 -- Build_Predicate_Function_Declaration --
10691 ------------------------------------------
10693 -- WARNING: This routine manages Ghost regions. Return statements must be
10694 -- replaced by gotos which jump to the end of the routine and restore the
10697 function Build_Predicate_Function_Declaration
10698 (Typ
: Entity_Id
) return Node_Id
10700 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
10702 Saved_GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
10703 Saved_IGR
: constant Node_Id
:= Ignored_Ghost_Region
;
10704 -- Save the Ghost-related attributes to restore on exit
10706 Func_Decl
: Node_Id
;
10707 Func_Id
: Entity_Id
;
10710 CRec_Typ
: Entity_Id
;
10711 -- The corresponding record type of Full_Typ
10713 Full_Typ
: Entity_Id
;
10714 -- The full view of Typ
10716 Priv_Typ
: Entity_Id
;
10717 -- The partial view of Typ
10719 UFull_Typ
: Entity_Id
;
10720 -- The underlying full view of Full_Typ
10723 -- The related type may be subject to pragma Ghost. Set the mode now to
10724 -- ensure that the predicate functions are properly marked as Ghost.
10726 Set_Ghost_Mode
(Typ
);
10729 Make_Defining_Identifier
(Loc
,
10730 Chars
=> New_External_Name
(Chars
(Typ
), "Predicate"));
10732 Mutate_Ekind
(Func_Id
, E_Function
);
10733 Set_Etype
(Func_Id
, Standard_Boolean
);
10734 Set_Is_Internal
(Func_Id
);
10735 Set_Is_Predicate_Function
(Func_Id
);
10736 Set_Predicate_Function
(Typ
, Func_Id
);
10738 -- The predicate function requires debug info when the predicates are
10739 -- subject to Source Coverage Obligations.
10741 if Opt
.Generate_SCO
then
10742 Set_Debug_Info_Needed
(Func_Id
);
10745 -- Obtain all views of the input type
10747 Get_Views
(Typ
, Priv_Typ
, Full_Typ
, UFull_Typ
, CRec_Typ
);
10749 -- Associate the predicate function and various flags with all views
10751 Propagate_Predicate_Attributes
(Priv_Typ
, From_Typ
=> Typ
);
10752 Propagate_Predicate_Attributes
(Full_Typ
, From_Typ
=> Typ
);
10753 Propagate_Predicate_Attributes
(UFull_Typ
, From_Typ
=> Typ
);
10754 Propagate_Predicate_Attributes
(CRec_Typ
, From_Typ
=> Typ
);
10757 Param_Specs
: constant List_Id
:= New_List
(
10758 Make_Parameter_Specification
(Loc
,
10759 Defining_Identifier
=> Make_Temporary
(Loc
, 'I'),
10760 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)));
10762 if Predicate_Function_Needs_Membership_Parameter
(Typ
) then
10763 -- Add Boolean-valued For_Membership_Test param
10764 Append
(Make_Parameter_Specification
(Loc
,
10765 Defining_Identifier
=> Make_Temporary
(Loc
, 'M'),
10767 New_Occurrence_Of
(Standard_Boolean
, Loc
)),
10772 Make_Function_Specification
(Loc
,
10773 Defining_Unit_Name
=> Func_Id
,
10774 Parameter_Specifications
=> Param_Specs
,
10775 Result_Definition
=>
10776 New_Occurrence_Of
(Standard_Boolean
, Loc
));
10779 Func_Decl
:= Make_Subprogram_Declaration
(Loc
, Specification
=> Spec
);
10781 Insert_After
(Parent
(Typ
), Func_Decl
);
10782 Analyze
(Func_Decl
);
10784 Restore_Ghost_Region
(Saved_GM
, Saved_IGR
);
10787 end Build_Predicate_Function_Declaration
;
10789 -----------------------------------------
10790 -- Check_Aspect_At_End_Of_Declarations --
10791 -----------------------------------------
10793 procedure Check_Aspect_At_End_Of_Declarations
(ASN
: Node_Id
) is
10794 Ent
: constant Entity_Id
:= Entity
(ASN
);
10795 Ident
: constant Node_Id
:= Identifier
(ASN
);
10796 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Chars
(Ident
));
10798 End_Decl_Expr
: constant Node_Id
:= Entity
(Ident
);
10799 -- Expression to be analyzed at end of declarations
10801 Freeze_Expr
: constant Node_Id
:= Expression
(ASN
);
10802 -- Expression from call to Check_Aspect_At_Freeze_Point.
10804 T
: constant Entity_Id
:=
10805 (if Present
(Freeze_Expr
) and A_Id
/= Aspect_Stable_Properties
10806 then Etype
(Original_Node
(Freeze_Expr
))
10808 -- Type required for preanalyze call. We use the original expression to
10809 -- get the proper type, to prevent cascaded errors when the expression
10810 -- is constant-folded. For Stable_Properties, the aspect value is
10811 -- not semantically an expression (although it is syntactically);
10812 -- in particular, it has no type.
10815 -- Set True if error
10817 -- On entry to this procedure, Entity (Ident) contains a copy of the
10818 -- original expression from the aspect, saved for this purpose, and
10819 -- but Expression (Ident) is a preanalyzed copy of the expression,
10820 -- preanalyzed just after the freeze point.
10822 procedure Check_Overloaded_Name
;
10823 -- For aspects whose expression is simply a name, this routine checks if
10824 -- the name is overloaded or not. If so, it verifies there is an
10825 -- interpretation that matches the entity obtained at the freeze point,
10826 -- otherwise the compiler complains.
10828 ---------------------------
10829 -- Check_Overloaded_Name --
10830 ---------------------------
10832 procedure Check_Overloaded_Name
is
10834 if not Is_Overloaded
(End_Decl_Expr
) then
10835 Err
:= not Is_Entity_Name
(End_Decl_Expr
)
10836 or else Entity
(End_Decl_Expr
) /= Entity
(Freeze_Expr
);
10842 Index
: Interp_Index
;
10846 Get_First_Interp
(End_Decl_Expr
, Index
, It
);
10847 while Present
(It
.Typ
) loop
10848 if It
.Nam
= Entity
(Freeze_Expr
) then
10853 Get_Next_Interp
(Index
, It
);
10857 end Check_Overloaded_Name
;
10859 -- Start of processing for Check_Aspect_At_End_Of_Declarations
10862 -- In an instance we do not perform the consistency check between freeze
10863 -- point and end of declarations, because it was done already in the
10864 -- analysis of the generic. Furthermore, the delayed analysis of an
10865 -- aspect of the instance may produce spurious errors when the generic
10866 -- is a child unit that references entities in the parent (which might
10867 -- not be in scope at the freeze point of the instance).
10869 if In_Instance
then
10872 -- The enclosing scope may have been rewritten during expansion (.e.g. a
10873 -- task body is rewritten as a procedure) after this conformance check
10874 -- has been performed, so do not perform it again (it may not easily be
10875 -- done if full visibility of local entities is not available).
10877 elsif not Comes_From_Source
(Current_Scope
) then
10880 -- Case of aspects Dimension, Dimension_System and Synchronization
10882 elsif A_Id
= Aspect_Synchronization
then
10885 -- Case of stream attributes and Put_Image, just have to compare
10886 -- entities. However, the expression is just a possibly-overloaded
10887 -- name, so we need to verify that one of these interpretations is
10888 -- the one available at at the freeze point.
10890 elsif A_Id
in Aspect_Input
10896 Analyze
(End_Decl_Expr
);
10897 Check_Overloaded_Name
;
10899 elsif A_Id
in Aspect_Variable_Indexing
10900 | Aspect_Constant_Indexing
10901 | Aspect_Default_Iterator
10902 | Aspect_Iterator_Element
10903 | Aspect_Integer_Literal
10904 | Aspect_Real_Literal
10905 | Aspect_String_Literal
10907 -- Make type unfrozen before analysis, to prevent spurious errors
10908 -- about late attributes.
10910 Set_Is_Frozen
(Ent
, False);
10911 Analyze
(End_Decl_Expr
);
10912 Set_Is_Frozen
(Ent
, True);
10914 -- If the end of declarations comes before any other freeze point,
10915 -- the Freeze_Expr is not analyzed: no check needed.
10917 if Analyzed
(Freeze_Expr
) and then not In_Instance
then
10918 Check_Overloaded_Name
;
10926 -- In a generic context freeze nodes are not always generated, so
10927 -- analyze the expression now. If the aspect is for a type, we must
10928 -- also make its potential components accessible.
10930 if not Analyzed
(Freeze_Expr
) and then Inside_A_Generic
then
10931 if A_Id
in Aspect_Dynamic_Predicate | Aspect_Predicate |
10932 Aspect_Static_Predicate
10935 Preanalyze_Spec_Expression
(Freeze_Expr
, Standard_Boolean
);
10938 elsif A_Id
= Aspect_Priority
then
10940 Preanalyze_Spec_Expression
(Freeze_Expr
, Any_Integer
);
10944 Preanalyze
(Freeze_Expr
);
10948 -- Indicate that the expression comes from an aspect specification,
10949 -- which is used in subsequent analysis even if expansion is off.
10951 if Present
(End_Decl_Expr
) then
10952 Set_Parent
(End_Decl_Expr
, ASN
);
10955 -- In a generic context the original aspect expressions have not
10956 -- been preanalyzed, so do it now. There are no conformance checks
10957 -- to perform in this case. As before, we have to make components
10958 -- visible for aspects that may reference them.
10960 if Present
(Freeze_Expr
) and then No
(T
) then
10961 if A_Id
in Aspect_Dynamic_Predicate
10964 | Aspect_Static_Predicate
10967 Check_Aspect_At_Freeze_Point
(ASN
);
10971 Check_Aspect_At_Freeze_Point
(ASN
);
10975 -- The default values attributes may be defined in the private part,
10976 -- and the analysis of the expression may take place when only the
10977 -- partial view is visible. The expression must be scalar, so use
10978 -- the full view to resolve.
10980 elsif A_Id
in Aspect_Default_Component_Value | Aspect_Default_Value
10981 and then Is_Private_Type
(T
)
10983 Preanalyze_Spec_Expression
(End_Decl_Expr
, Full_View
(T
));
10985 -- The following aspect expressions may contain references to
10986 -- components and discriminants of the type.
10988 elsif A_Id
in Aspect_CPU
10989 | Aspect_Dynamic_Predicate
10992 | Aspect_Static_Predicate
10995 Preanalyze_Spec_Expression
(End_Decl_Expr
, T
);
10998 elsif A_Id
= Aspect_Predicate_Failure
then
10999 Preanalyze_Spec_Expression
(End_Decl_Expr
, Standard_String
);
11000 elsif Present
(End_Decl_Expr
) then
11001 Preanalyze_Spec_Expression
(End_Decl_Expr
, T
);
11005 not Fully_Conformant_Expressions
11006 (End_Decl_Expr
, Freeze_Expr
, Report
=> True);
11009 -- Output error message if error. Force error on aspect specification
11010 -- even if there is an error on the expression itself.
11014 ("!visibility of aspect for& changes after freeze point",
11017 ("info: & is frozen here, (RM 13.1.1 (13/3))??",
11018 Freeze_Node
(Ent
), Ent
);
11020 end Check_Aspect_At_End_Of_Declarations
;
11022 ----------------------------------
11023 -- Check_Aspect_At_Freeze_Point --
11024 ----------------------------------
11026 procedure Check_Aspect_At_Freeze_Point
(ASN
: Node_Id
) is
11027 Ident
: constant Node_Id
:= Identifier
(ASN
);
11028 -- Identifier (use Entity field to save expression)
11030 Expr
: constant Node_Id
:= Expression
(ASN
);
11031 -- For cases where using Entity (Identifier) doesn't work
11033 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Chars
(Ident
));
11035 T
: Entity_Id
:= Empty
;
11036 -- Type required for preanalyze call
11039 -- On entry to this procedure, Entity (Ident) contains a copy of the
11040 -- original expression from the aspect, saved for this purpose.
11042 -- On exit from this procedure Entity (Ident) is unchanged, still
11043 -- containing that copy, but Expression (Ident) is a preanalyzed copy
11044 -- of the expression, preanalyzed just after the freeze point.
11046 -- Make a copy of the expression to be preanalyzed
11048 Set_Expression
(ASN
, New_Copy_Tree
(Entity
(Ident
)));
11050 -- Find type for preanalyze call
11054 -- No_Aspect should be impossible
11057 raise Program_Error
;
11059 -- Aspects taking an optional boolean argument
11061 when Boolean_Aspects
11062 | Library_Unit_Aspects
11064 T
:= Standard_Boolean
;
11066 -- Aspects corresponding to attribute definition clauses
11068 when Aspect_Address
=>
11069 T
:= RTE
(RE_Address
);
11071 when Aspect_Attach_Handler
=>
11072 T
:= RTE
(RE_Interrupt_ID
);
11074 when Aspect_Bit_Order
11075 | Aspect_Scalar_Storage_Order
11077 T
:= RTE
(RE_Bit_Order
);
11079 when Aspect_Convention
=>
11083 T
:= RTE
(RE_CPU_Range
);
11085 -- Default_Component_Value is resolved with the component type
11087 when Aspect_Default_Component_Value
=>
11088 T
:= Component_Type
(Entity
(ASN
));
11090 when Aspect_Default_Storage_Pool
=>
11091 T
:= Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
));
11093 -- Default_Value is resolved with the type entity in question
11095 when Aspect_Default_Value
=>
11098 when Aspect_Dispatching_Domain
=>
11099 T
:= RTE
(RE_Dispatching_Domain
);
11101 when Aspect_External_Tag
=>
11102 T
:= Standard_String
;
11104 when Aspect_External_Name
=>
11105 T
:= Standard_String
;
11107 when Aspect_Link_Name
=>
11108 T
:= Standard_String
;
11110 when Aspect_Interrupt_Priority
11113 T
:= Standard_Integer
;
11115 when Aspect_Relative_Deadline
=>
11116 T
:= RTE
(RE_Time_Span
);
11118 when Aspect_Secondary_Stack_Size
=>
11119 T
:= Standard_Integer
;
11121 when Aspect_Small
=>
11123 -- Note that the expression can be of any real type (not just a
11124 -- real universal literal) as long as it is a static constant.
11128 -- For a simple storage pool, we have to retrieve the type of the
11129 -- pool object associated with the aspect's corresponding attribute
11130 -- definition clause.
11132 when Aspect_Simple_Storage_Pool
=>
11133 T
:= Etype
(Expression
(Aspect_Rep_Item
(ASN
)));
11135 when Aspect_Storage_Pool
=>
11136 T
:= Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
));
11138 when Aspect_Alignment
11139 | Aspect_Component_Size
11140 | Aspect_Machine_Radix
11141 | Aspect_Object_Size
11143 | Aspect_Storage_Size
11144 | Aspect_Stream_Size
11145 | Aspect_Value_Size
11149 when Aspect_Linker_Section
=>
11150 T
:= Standard_String
;
11152 when Aspect_Synchronization
=>
11155 -- Special case, the expression of these aspects is just an entity
11156 -- that does not need any resolution, so just analyze.
11165 Analyze
(Expression
(ASN
));
11168 -- Same for Iterator aspects, where the expression is a function
11169 -- name. Legality rules are checked separately.
11171 when Aspect_Constant_Indexing
11172 | Aspect_Default_Iterator
11173 | Aspect_Iterator_Element
11174 | Aspect_Variable_Indexing
11176 Analyze
(Expression
(ASN
));
11179 -- Same for Literal aspects, where the expression is a function
11180 -- name. Legality rules are checked separately. Use Expr to avoid
11181 -- losing track of the previous resolution of Expression.
11183 when Aspect_Integer_Literal
11184 | Aspect_Real_Literal
11185 | Aspect_String_Literal
11187 Set_Entity
(Expression
(ASN
), Entity
(Expr
));
11188 Set_Etype
(Expression
(ASN
), Etype
(Expr
));
11189 Set_Is_Overloaded
(Expression
(ASN
), False);
11190 Analyze
(Expression
(ASN
));
11193 -- Ditto for Iterable, legality checks in Validate_Iterable_Aspect.
11195 when Aspect_Iterable
=>
11199 Cursor
: constant Entity_Id
:= Get_Cursor_Type
(ASN
, T
);
11204 if Cursor
= Any_Type
then
11208 Assoc
:= First
(Component_Associations
(Expression
(ASN
)));
11209 while Present
(Assoc
) loop
11210 Expr
:= Expression
(Assoc
);
11213 if not Error_Posted
(Expr
) then
11214 Resolve_Iterable_Operation
11215 (Expr
, Cursor
, T
, Chars
(First
(Choices
(Assoc
))));
11224 when Aspect_Aggregate
=>
11225 if Is_Array_Type
(Entity
(ASN
)) then
11227 ("aspect% can only be applied to non-array type",
11230 Resolve_Aspect_Aggregate
(Entity
(ASN
), Expression
(ASN
));
11233 when Aspect_Stable_Properties
=>
11234 Resolve_Aspect_Stable_Properties
11235 (Entity
(ASN
), Expression
(ASN
),
11236 Class_Present
=> Class_Present
(ASN
));
11239 -- Invariant/Predicate take boolean expressions
11241 when Aspect_Dynamic_Predicate
11244 | Aspect_Static_Predicate
11245 | Aspect_Type_Invariant
11247 T
:= Standard_Boolean
;
11249 when Aspect_Predicate_Failure
=>
11250 T
:= Standard_String
;
11252 -- As for some other aspects above, the expression of this aspect is
11253 -- just an entity that does not need any resolution, so just analyze.
11255 when Aspect_Designated_Storage_Model
=>
11256 Analyze
(Expression
(ASN
));
11259 when Aspect_Storage_Model_Type
=>
11261 -- The aggregate argument of Storage_Model_Type is optional, and
11262 -- when not present the aspect defaults to the native storage
11263 -- model (where the address type is System.Address, and other
11264 -- arguments default to corresponding native storage operations).
11266 if No
(Expression
(ASN
)) then
11275 Addr_Type
: Entity_Id
:= Empty
;
11278 Assoc
:= First
(Component_Associations
(Expression
(ASN
)));
11279 while Present
(Assoc
) loop
11280 Expr
:= Expression
(Assoc
);
11283 if not Error_Posted
(Expr
) then
11284 Resolve_Storage_Model_Type_Argument
11285 (Expr
, T
, Addr_Type
, Chars
(First
(Choices
(Assoc
))));
11294 -- Here is the list of aspects that don't require delay analysis
11296 when Aspect_Abstract_State
11298 | Aspect_Async_Readers
11299 | Aspect_Async_Writers
11300 | Aspect_Constant_After_Elaboration
11301 | Aspect_Contract_Cases
11302 | Aspect_Default_Initial_Condition
11305 | Aspect_Dimension_System
11306 | Aspect_Exceptional_Cases
11307 | Aspect_Effective_Reads
11308 | Aspect_Effective_Writes
11309 | Aspect_Extensions_Visible
11312 | Aspect_GNAT_Annotate
11313 | Aspect_Implicit_Dereference
11314 | Aspect_Initial_Condition
11315 | Aspect_Initializes
11316 | Aspect_Max_Entry_Queue_Depth
11317 | Aspect_Max_Entry_Queue_Length
11318 | Aspect_Max_Queue_Length
11319 | Aspect_No_Caching
11320 | Aspect_No_Controlled_Parts
11321 | Aspect_No_Task_Parts
11322 | Aspect_Obsolescent
11325 | Aspect_Postcondition
11327 | Aspect_Precondition
11328 | Aspect_Refined_Depends
11329 | Aspect_Refined_Global
11330 | Aspect_Refined_Post
11331 | Aspect_Refined_State
11332 | Aspect_Relaxed_Initialization
11333 | Aspect_SPARK_Mode
11334 | Aspect_Subprogram_Variant
11337 | Aspect_Unimplemented
11338 | Aspect_Unsuppress
11339 | Aspect_Volatile_Function
11341 raise Program_Error
;
11345 -- Do the preanalyze call
11347 if Present
(Expression
(ASN
)) then
11348 Preanalyze_Spec_Expression
(Expression
(ASN
), T
);
11350 end Check_Aspect_At_Freeze_Point
;
11352 -----------------------------------
11353 -- Check_Constant_Address_Clause --
11354 -----------------------------------
11356 procedure Check_Constant_Address_Clause
11360 procedure Check_At_Constant_Address
(Nod
: Node_Id
);
11361 -- Checks that the given node N represents a name whose 'Address is
11362 -- constant (in the same sense as OK_Constant_Address_Clause, i.e. the
11363 -- address value is the same at the point of declaration of U_Ent and at
11364 -- the time of elaboration of the address clause.
11366 procedure Check_Expr_Constants
(Nod
: Node_Id
);
11367 -- Checks that Nod meets the requirements for a constant address clause
11368 -- in the sense of the enclosing procedure.
11370 procedure Check_List_Constants
(Lst
: List_Id
);
11371 -- Check that all elements of list Lst meet the requirements for a
11372 -- constant address clause in the sense of the enclosing procedure.
11374 -------------------------------
11375 -- Check_At_Constant_Address --
11376 -------------------------------
11378 procedure Check_At_Constant_Address
(Nod
: Node_Id
) is
11380 if Is_Entity_Name
(Nod
) then
11381 if Present
(Address_Clause
(Entity
((Nod
)))) then
11383 ("invalid address clause for initialized object &!",
11386 ("address for& cannot depend on another address clause! "
11387 & "(RM 13.1(22))!", Nod
, U_Ent
);
11389 elsif In_Same_Source_Unit
(Entity
(Nod
), U_Ent
)
11390 and then Sloc
(U_Ent
) < Sloc
(Entity
(Nod
))
11393 ("invalid address clause for initialized object &!",
11395 Error_Msg_Node_2
:= U_Ent
;
11397 ("\& must be defined before & (RM 13.1(22))!",
11398 Nod
, Entity
(Nod
));
11401 elsif Nkind
(Nod
) = N_Selected_Component
then
11403 T
: constant Entity_Id
:= Etype
(Prefix
(Nod
));
11406 if (Is_Record_Type
(T
)
11407 and then Has_Discriminants
(T
))
11409 (Is_Access_Type
(T
)
11410 and then Is_Record_Type
(Designated_Type
(T
))
11411 and then Has_Discriminants
(Designated_Type
(T
)))
11414 ("invalid address clause for initialized object &!",
11417 ("\address cannot depend on component of discriminated "
11418 & "record (RM 13.1(22))!", Nod
);
11420 Check_At_Constant_Address
(Prefix
(Nod
));
11424 elsif Nkind
(Nod
) = N_Indexed_Component
then
11425 Check_At_Constant_Address
(Prefix
(Nod
));
11426 Check_List_Constants
(Expressions
(Nod
));
11429 Check_Expr_Constants
(Nod
);
11431 end Check_At_Constant_Address
;
11433 --------------------------
11434 -- Check_Expr_Constants --
11435 --------------------------
11437 procedure Check_Expr_Constants
(Nod
: Node_Id
) is
11438 Loc_U_Ent
: constant Source_Ptr
:= Sloc
(U_Ent
);
11439 Ent
: Entity_Id
:= Empty
;
11442 if Nkind
(Nod
) in N_Has_Etype
11443 and then Etype
(Nod
) = Any_Type
11448 case Nkind
(Nod
) is
11454 when N_Expanded_Name
11457 Ent
:= Entity
(Nod
);
11459 -- We need to look at the original node if it is different
11460 -- from the node, since we may have rewritten things and
11461 -- substituted an identifier representing the rewrite.
11463 if Is_Rewrite_Substitution
(Nod
) then
11464 Check_Expr_Constants
(Original_Node
(Nod
));
11466 -- If the node is an object declaration without initial
11467 -- value, some code has been expanded, and the expression
11468 -- is not constant, even if the constituents might be
11469 -- acceptable, as in A'Address + offset.
11471 if Ekind
(Ent
) = E_Variable
11473 Nkind
(Declaration_Node
(Ent
)) = N_Object_Declaration
11475 No
(Expression
(Declaration_Node
(Ent
)))
11478 ("invalid address clause for initialized object &!",
11481 -- If entity is constant, it may be the result of expanding
11482 -- a check. We must verify that its declaration appears
11483 -- before the object in question, else we also reject the
11486 elsif Ekind
(Ent
) = E_Constant
11487 and then In_Same_Source_Unit
(Ent
, U_Ent
)
11488 and then Sloc
(Ent
) > Loc_U_Ent
11491 ("invalid address clause for initialized object &!",
11498 -- Otherwise look at the identifier and see if it is OK
11500 if Is_Named_Number
(Ent
) or else Is_Type
(Ent
) then
11503 elsif Ekind
(Ent
) in E_Constant | E_In_Parameter
then
11505 -- This is the case where we must have Ent defined before
11506 -- U_Ent. Clearly if they are in different units this
11507 -- requirement is met since the unit containing Ent is
11508 -- already processed.
11510 if not In_Same_Source_Unit
(Ent
, U_Ent
) then
11513 -- Otherwise location of Ent must be before the location
11514 -- of U_Ent, that's what prior defined means.
11516 elsif Sloc
(Ent
) < Loc_U_Ent
then
11521 ("invalid address clause for initialized object &!",
11523 Error_Msg_Node_2
:= U_Ent
;
11525 ("\& must be defined before & (RM 13.1(22))!",
11529 elsif Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
11530 Check_Expr_Constants
(Original_Node
(Nod
));
11534 ("invalid address clause for initialized object &!",
11537 if Comes_From_Source
(Ent
) then
11539 ("\reference to variable& not allowed"
11540 & " (RM 13.1(22))!", Nod
, Ent
);
11543 ("non-static expression not allowed"
11544 & " (RM 13.1(22))!", Nod
);
11548 when N_Integer_Literal
=>
11550 -- If this is a rewritten unchecked conversion, in a system
11551 -- where Address is an integer type, always use the base type
11552 -- for a literal value. This is user-friendly and prevents
11553 -- order-of-elaboration issues with instances of unchecked
11556 if Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
11557 Set_Etype
(Nod
, Base_Type
(Etype
(Nod
)));
11560 when N_Character_Literal
11567 Check_Expr_Constants
(Low_Bound
(Nod
));
11568 Check_Expr_Constants
(High_Bound
(Nod
));
11570 when N_Explicit_Dereference
=>
11571 Check_Expr_Constants
(Prefix
(Nod
));
11573 when N_Indexed_Component
=>
11574 Check_Expr_Constants
(Prefix
(Nod
));
11575 Check_List_Constants
(Expressions
(Nod
));
11578 Check_Expr_Constants
(Prefix
(Nod
));
11579 Check_Expr_Constants
(Discrete_Range
(Nod
));
11581 when N_Selected_Component
=>
11582 Check_Expr_Constants
(Prefix
(Nod
));
11584 when N_Attribute_Reference
=>
11585 if Attribute_Name
(Nod
) in Name_Address
11587 | Name_Unchecked_Access
11588 | Name_Unrestricted_Access
11590 Check_At_Constant_Address
(Prefix
(Nod
));
11592 -- Normally, System'To_Address will have been transformed into
11593 -- an Unchecked_Conversion, but in -gnatc mode, it will not,
11594 -- and we don't want to give an error, because the whole point
11595 -- of 'To_Address is that it is static.
11597 elsif Attribute_Name
(Nod
) = Name_To_Address
then
11598 pragma Assert
(Operating_Mode
= Check_Semantics
);
11602 Check_Expr_Constants
(Prefix
(Nod
));
11603 Check_List_Constants
(Expressions
(Nod
));
11606 when N_Aggregate
=>
11607 Check_List_Constants
(Component_Associations
(Nod
));
11608 Check_List_Constants
(Expressions
(Nod
));
11610 when N_Component_Association
=>
11611 Check_Expr_Constants
(Expression
(Nod
));
11613 when N_Extension_Aggregate
=>
11614 Check_Expr_Constants
(Ancestor_Part
(Nod
));
11615 Check_List_Constants
(Component_Associations
(Nod
));
11616 Check_List_Constants
(Expressions
(Nod
));
11622 | N_Membership_Test
11625 Check_Expr_Constants
(Left_Opnd
(Nod
));
11626 Check_Expr_Constants
(Right_Opnd
(Nod
));
11629 Check_Expr_Constants
(Right_Opnd
(Nod
));
11632 | N_Qualified_Expression
11633 | N_Type_Conversion
11634 | N_Unchecked_Type_Conversion
11636 Check_Expr_Constants
(Expression
(Nod
));
11638 when N_Function_Call
=>
11639 if not Is_Pure
(Entity
(Name
(Nod
))) then
11641 ("invalid address clause for initialized object &!",
11645 ("\function & is not pure (RM 13.1(22))!",
11646 Nod
, Entity
(Name
(Nod
)));
11649 Check_List_Constants
(Parameter_Associations
(Nod
));
11652 when N_Parameter_Association
=>
11653 Check_Expr_Constants
(Explicit_Actual_Parameter
(Nod
));
11657 ("invalid address clause for initialized object &!",
11660 ("\must be constant defined before& (RM 13.1(22))!",
11663 end Check_Expr_Constants
;
11665 --------------------------
11666 -- Check_List_Constants --
11667 --------------------------
11669 procedure Check_List_Constants
(Lst
: List_Id
) is
11673 Nod1
:= First
(Lst
);
11674 while Present
(Nod1
) loop
11675 Check_Expr_Constants
(Nod1
);
11678 end Check_List_Constants
;
11680 -- Start of processing for Check_Constant_Address_Clause
11683 -- If rep_clauses are to be ignored, no need for legality checks. In
11684 -- particular, no need to pester user about rep clauses that violate the
11685 -- rule on constant addresses, given that these clauses will be removed
11686 -- by Freeze before they reach the back end. Similarly in CodePeer mode,
11687 -- we want to relax these checks.
11689 if not Ignore_Rep_Clauses
and not CodePeer_Mode
then
11690 Check_Expr_Constants
(Expr
);
11692 end Check_Constant_Address_Clause
;
11694 ---------------------------
11695 -- Check_Pool_Size_Clash --
11696 ---------------------------
11698 procedure Check_Pool_Size_Clash
(Ent
: Entity_Id
; SP
, SS
: Node_Id
) is
11702 -- We need to find out which one came first. Note that in the case of
11703 -- aspects mixed with pragmas there are cases where the processing order
11704 -- is reversed, which is why we do the check here.
11706 if Sloc
(SP
) < Sloc
(SS
) then
11707 Error_Msg_Sloc
:= Sloc
(SP
);
11709 Error_Msg_NE
("Storage_Pool previously given for&#", Post
, Ent
);
11712 Error_Msg_Sloc
:= Sloc
(SS
);
11714 Error_Msg_NE
("Storage_Size previously given for&#", Post
, Ent
);
11718 ("\cannot have Storage_Size and Storage_Pool (RM 13.11(3))", Post
);
11719 end Check_Pool_Size_Clash
;
11721 ----------------------------------------
11722 -- Check_Record_Representation_Clause --
11723 ----------------------------------------
11725 procedure Check_Record_Representation_Clause
(N
: Node_Id
) is
11726 Loc
: constant Source_Ptr
:= Sloc
(N
);
11727 Ident
: constant Node_Id
:= Identifier
(N
);
11728 Rectype
: Entity_Id
;
11731 Fbit
: Uint
:= No_Uint
;
11732 Lbit
: Uint
:= No_Uint
;
11733 Hbit
: Uint
:= Uint_0
;
11737 Max_Bit_So_Far
: Uint
;
11738 -- Records the maximum bit position so far. If all field positions
11739 -- are monotonically increasing, then we can skip the circuit for
11740 -- checking for overlap, since no overlap is possible.
11742 Tagged_Parent
: Entity_Id
:= Empty
;
11743 -- This is set in the case of an extension for which we have either a
11744 -- size clause or Is_Fully_Repped_Tagged_Type True (indicating that all
11745 -- components are positioned by record representation clauses) on the
11746 -- parent type. In this case we check for overlap between components of
11747 -- this tagged type and the parent component. Tagged_Parent will point
11748 -- to this parent type. For all other cases, Tagged_Parent is Empty.
11750 Parent_Last_Bit
: Uint
:= No_Uint
; -- init to avoid warning
11751 -- Relevant only if Tagged_Parent is set, Parent_Last_Bit indicates the
11752 -- last bit position for any field in the parent type. We only need to
11753 -- check overlap for fields starting below this point.
11755 Overlap_Check_Required
: Boolean;
11756 -- Used to keep track of whether or not an overlap check is required
11758 Overlap_Detected
: Boolean := False;
11759 -- Set True if an overlap is detected
11761 Ccount
: Natural := 0;
11762 -- Number of component clauses in record rep clause
11764 procedure Check_Component_Overlap
(C1_Ent
, C2_Ent
: Entity_Id
);
11765 -- Given two entities for record components or discriminants, checks
11766 -- if they have overlapping component clauses and issues errors if so.
11768 procedure Find_Component
;
11769 -- Finds component entity corresponding to current component clause (in
11770 -- CC), and sets Comp to the entity, and Fbit/Lbit to the zero origin
11771 -- start/stop bits for the field. If there is no matching component or
11772 -- if the matching component does not have a component clause, then
11773 -- that's an error and Comp is set to Empty, but no error message is
11774 -- issued, since the message was already given. Comp is also set to
11775 -- Empty if the current "component clause" is in fact a pragma.
11777 procedure Record_Hole_Check
11778 (Rectype
: Entity_Id
; After_Last
: out Uint
; Warn
: Boolean);
11779 -- Checks for gaps in the given Rectype. Compute After_Last, the bit
11780 -- number after the last component. Warn is True on the initial call,
11781 -- and warnings are given for gaps. For a type extension, this is called
11782 -- recursively to compute After_Last for the parent type; in this case
11783 -- Warn is False and the warnings are suppressed.
11785 procedure Component_Order_Check
(Rectype
: Entity_Id
);
11786 -- Check that the order of component clauses agrees with the order of
11787 -- component declarations, and that the component clauses are given in
11788 -- increasing order of bit offset.
11790 -----------------------------
11791 -- Check_Component_Overlap --
11792 -----------------------------
11794 procedure Check_Component_Overlap
(C1_Ent
, C2_Ent
: Entity_Id
) is
11795 CC1
: constant Node_Id
:= Component_Clause
(C1_Ent
);
11796 CC2
: constant Node_Id
:= Component_Clause
(C2_Ent
);
11799 if Present
(CC1
) and then Present
(CC2
) then
11801 -- Exclude odd case where we have two tag components in the same
11802 -- record, both at location zero. This seems a bit strange, but
11803 -- it seems to happen in some circumstances, perhaps on an error.
11805 if Chars
(C1_Ent
) = Name_uTag
then
11809 -- Here we check if the two fields overlap
11812 S1
: constant Uint
:= Component_Bit_Offset
(C1_Ent
);
11813 S2
: constant Uint
:= Component_Bit_Offset
(C2_Ent
);
11814 E1
: constant Uint
:= S1
+ Esize
(C1_Ent
);
11815 E2
: constant Uint
:= S2
+ Esize
(C2_Ent
);
11818 if E2
<= S1
or else E1
<= S2
then
11821 Error_Msg_Node_2
:= Component_Name
(CC2
);
11822 Error_Msg_Sloc
:= Sloc
(Error_Msg_Node_2
);
11823 Error_Msg_Node_1
:= Component_Name
(CC1
);
11825 ("component& overlaps & #", Component_Name
(CC1
));
11826 Overlap_Detected
:= True;
11830 end Check_Component_Overlap
;
11832 ---------------------------
11833 -- Component_Order_Check --
11834 ---------------------------
11836 procedure Component_Order_Check
(Rectype
: Entity_Id
) is
11837 Comp
: Entity_Id
:= First_Component
(Rectype
);
11838 Clause
: Node_Id
:= First
(Component_Clauses
(N
));
11839 Prev_Bit_Offset
: Uint
:= Uint_0
;
11840 OOO
: constant String :=
11841 "?_r?component clause out of order with respect to declaration";
11844 -- Step Comp through components and Clause through component clauses,
11845 -- skipping pragmas. We ignore discriminants and variant parts,
11846 -- because we get most of the benefit from the plain vanilla
11847 -- component cases, without the extra complexity. If we find a Comp
11848 -- and Clause that don't match, give a warning on both and quit. If
11849 -- we find two subsequent clauses out of order by bit layout, give
11850 -- warning and quit. On each iteration, Prev_Bit_Offset is the one
11851 -- from the previous iteration (or 0 to start).
11853 while Present
(Comp
) and then Present
(Clause
) loop
11854 if Nkind
(Clause
) = N_Component_Clause
11855 and then Ekind
(Entity
(Component_Name
(Clause
))) = E_Component
11857 if Entity
(Component_Name
(Clause
)) /= Comp
then
11858 Error_Msg_N
(OOO
, Comp
);
11859 Error_Msg_N
(OOO
, Clause
);
11863 if not Reverse_Bit_Order
(Rectype
)
11864 and then not Reverse_Storage_Order
(Rectype
)
11865 and then Component_Bit_Offset
(Comp
) < Prev_Bit_Offset
11867 Error_Msg_N
("?_r?memory layout out of order", Clause
);
11871 Prev_Bit_Offset
:= Component_Bit_Offset
(Comp
);
11872 Next_Component
(Comp
);
11877 end Component_Order_Check
;
11879 --------------------
11880 -- Find_Component --
11881 --------------------
11883 procedure Find_Component
is
11885 procedure Search_Component
(R
: Entity_Id
);
11886 -- Search components of R for a match. If found, Comp is set
11888 ----------------------
11889 -- Search_Component --
11890 ----------------------
11892 procedure Search_Component
(R
: Entity_Id
) is
11894 Comp
:= First_Component_Or_Discriminant
(R
);
11895 while Present
(Comp
) loop
11897 -- Ignore error of attribute name for component name (we
11898 -- already gave an error message for this, so no need to
11901 if Nkind
(Component_Name
(CC
)) = N_Attribute_Reference
then
11904 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
11907 Next_Component_Or_Discriminant
(Comp
);
11909 end Search_Component
;
11911 -- Start of processing for Find_Component
11914 -- Return with Comp set to Empty if we have a pragma
11916 if Nkind
(CC
) = N_Pragma
then
11921 -- Search current record for matching component
11923 Search_Component
(Rectype
);
11925 -- If not found, maybe component of base type discriminant that is
11926 -- absent from statically constrained first subtype.
11929 Search_Component
(Base_Type
(Rectype
));
11932 -- If no component, or the component does not reference the component
11933 -- clause in question, then there was some previous error for which
11934 -- we already gave a message, so just return with Comp Empty.
11936 if No
(Comp
) or else Component_Clause
(Comp
) /= CC
then
11937 Check_Error_Detected
;
11940 -- Normal case where we have a component clause
11943 Fbit
:= Component_Bit_Offset
(Comp
);
11944 Lbit
:= Fbit
+ Esize
(Comp
) - 1;
11946 end Find_Component
;
11948 -----------------------
11949 -- Record_Hole_Check --
11950 -----------------------
11952 procedure Record_Hole_Check
11953 (Rectype
: Entity_Id
; After_Last
: out Uint
; Warn
: Boolean)
11955 Decl
: constant Node_Id
:= Declaration_Node
(Base_Type
(Rectype
));
11956 -- Full declaration of record type
11958 procedure Check_Component_List
11963 -- Check component list CL for holes. DS is a list of discriminant
11964 -- specifications to be included in the consideration of components.
11965 -- Sbit is the starting bit, which is zero if there are no preceding
11966 -- components (before a variant part, or a parent type, or a tag
11967 -- field). If there are preceding components, Sbit is the bit just
11968 -- after the last such component. Abit is set to the bit just after
11969 -- the last component of DS and CL.
11971 --------------------------
11972 -- Check_Component_List --
11973 --------------------------
11975 procedure Check_Component_List
11984 Compl
:= Integer (List_Length
(Component_Items
(CL
)));
11986 if DS
/= No_List
then
11987 Compl
:= Compl
+ Integer (List_Length
(DS
));
11991 Comps
: array (Natural range 0 .. Compl
) of Entity_Id
;
11992 -- Gather components (zero entry is for sort routine)
11994 Ncomps
: Natural := 0;
11995 -- Number of entries stored in Comps (starting at Comps (1))
11998 -- One component item or discriminant specification
12001 -- Starting bit for next component
12004 -- Component entity
12009 function Lt
(Op1
, Op2
: Natural) return Boolean;
12010 -- Compare routine for Sort
12012 procedure Move
(From
: Natural; To
: Natural);
12013 -- Move routine for Sort
12015 package Sorting
is new GNAT
.Heap_Sort_G
(Move
, Lt
);
12021 function Lt
(Op1
, Op2
: Natural) return Boolean is
12022 K1
: constant Boolean :=
12023 Known_Component_Bit_Offset
(Comps
(Op1
));
12024 K2
: constant Boolean :=
12025 Known_Component_Bit_Offset
(Comps
(Op2
));
12026 -- Record representation clauses can be incomplete, so the
12027 -- Component_Bit_Offsets can be unknown.
12031 return Component_Bit_Offset
(Comps
(Op1
))
12032 < Component_Bit_Offset
(Comps
(Op2
));
12045 procedure Move
(From
: Natural; To
: Natural) is
12047 Comps
(To
) := Comps
(From
);
12051 -- Gather discriminants into Comp
12053 Citem
:= First
(DS
);
12054 while Present
(Citem
) loop
12055 if Nkind
(Citem
) = N_Discriminant_Specification
then
12057 Ent
: constant Entity_Id
:=
12058 Defining_Identifier
(Citem
);
12060 if Ekind
(Ent
) = E_Discriminant
then
12061 Ncomps
:= Ncomps
+ 1;
12062 Comps
(Ncomps
) := Ent
;
12070 -- Gather component entities into Comp
12072 Citem
:= First
(Component_Items
(CL
));
12073 while Present
(Citem
) loop
12074 if Nkind
(Citem
) = N_Component_Declaration
then
12075 Ncomps
:= Ncomps
+ 1;
12076 Comps
(Ncomps
) := Defining_Identifier
(Citem
);
12082 -- Now sort the component entities based on the first bit.
12083 -- Note we already know there are no overlapping components.
12085 Sorting
.Sort
(Ncomps
);
12087 -- Loop through entries checking for holes
12090 for J
in 1 .. Ncomps
loop
12092 pragma Annotate
(CodePeer
, Modified
, CEnt
);
12095 CBO
: constant Uint
:= Component_Bit_Offset
(CEnt
);
12098 -- Skip components with unknown offsets
12100 if Present
(CBO
) and then CBO
>= 0 then
12101 Error_Msg_Uint_1
:= CBO
- Nbit
;
12103 if Warn
and then Error_Msg_Uint_1
> 0 then
12105 ("?.h?^-bit gap before component&",
12106 Component_Name
(Component_Clause
(CEnt
)),
12110 Nbit
:= CBO
+ Esize
(CEnt
);
12115 -- Set Abit to just after the last nonvariant component
12119 -- Process variant parts recursively if present. Set Abit to
12120 -- the maximum for all variant parts.
12122 if Present
(Variant_Part
(CL
)) then
12124 Var_Start
: constant Uint
:= Nbit
;
12126 Variant
:= First
(Variants
(Variant_Part
(CL
)));
12127 while Present
(Variant
) loop
12128 Check_Component_List
12129 (No_List
, Component_List
(Variant
), Var_Start
, Nbit
);
12131 if Nbit
> Abit
then
12138 end Check_Component_List
;
12143 -- Starting bit for call to Check_Component_List. Zero for an
12144 -- untagged type. The size of the Tag for a nonderived tagged
12145 -- type. Parent size for a type extension.
12147 Record_Definition
: Node_Id
;
12148 -- Record_Definition containing Component_List to pass to
12149 -- Check_Component_List.
12151 -- Start of processing for Record_Hole_Check
12154 if Is_Tagged_Type
(Rectype
) then
12155 Sbit
:= UI_From_Int
(System_Address_Size
);
12160 After_Last
:= Uint_0
;
12162 if Nkind
(Decl
) = N_Full_Type_Declaration
then
12163 Record_Definition
:= Type_Definition
(Decl
);
12165 -- If we have a record extension, set Sbit to point after the last
12166 -- component of the parent type, by calling Record_Hole_Check
12169 if Nkind
(Record_Definition
) = N_Derived_Type_Definition
then
12170 Record_Definition
:= Record_Extension_Part
(Record_Definition
);
12171 Record_Hole_Check
(Underlying_Type
(Parent_Subtype
(Rectype
)),
12172 After_Last
=> Sbit
, Warn
=> False);
12175 if Nkind
(Record_Definition
) = N_Record_Definition
then
12176 Check_Component_List
12177 (Discriminant_Specifications
(Decl
),
12178 Component_List
(Record_Definition
),
12182 end Record_Hole_Check
;
12184 -- Start of processing for Check_Record_Representation_Clause
12188 Rectype
:= Entity
(Ident
);
12190 if Rectype
= Any_Type
then
12194 Rectype
:= Underlying_Type
(Rectype
);
12196 -- See if we have a fully repped derived tagged type
12199 PS
: constant Entity_Id
:= Parent_Subtype
(Rectype
);
12202 if Present
(PS
) and then Known_Static_RM_Size
(PS
) then
12203 Tagged_Parent
:= PS
;
12204 Parent_Last_Bit
:= RM_Size
(PS
) - 1;
12206 elsif Present
(PS
) and then Is_Fully_Repped_Tagged_Type
(PS
) then
12207 Tagged_Parent
:= PS
;
12209 -- Find maximum bit of any component of the parent type
12211 Parent_Last_Bit
:= UI_From_Int
(System_Address_Size
- 1);
12212 Pcomp
:= First_Component_Or_Discriminant
(Tagged_Parent
);
12213 while Present
(Pcomp
) loop
12214 if Present
(Component_Bit_Offset
(Pcomp
))
12215 and then Known_Static_Esize
(Pcomp
)
12220 Component_Bit_Offset
(Pcomp
) + Esize
(Pcomp
) - 1);
12223 Next_Component_Or_Discriminant
(Pcomp
);
12228 -- All done if no component clauses
12230 CC
:= First
(Component_Clauses
(N
));
12236 -- If a tag is present, then create a component clause that places it
12237 -- at the start of the record (otherwise gigi may place it after other
12238 -- fields that have rep clauses).
12240 Fent
:= First_Entity
(Rectype
);
12242 if Nkind
(Fent
) = N_Defining_Identifier
12243 and then Chars
(Fent
) = Name_uTag
12245 Set_Component_Bit_Offset
(Fent
, Uint_0
);
12246 Set_Normalized_Position
(Fent
, Uint_0
);
12247 Set_Normalized_First_Bit
(Fent
, Uint_0
);
12248 Set_Esize
(Fent
, UI_From_Int
(System_Address_Size
));
12250 Set_Component_Clause
(Fent
,
12251 Make_Component_Clause
(Loc
,
12252 Component_Name
=> Make_Identifier
(Loc
, Name_uTag
),
12254 Position
=> Make_Integer_Literal
(Loc
, Uint_0
),
12255 First_Bit
=> Make_Integer_Literal
(Loc
, Uint_0
),
12257 Make_Integer_Literal
(Loc
,
12258 UI_From_Int
(System_Address_Size
- 1))));
12260 Ccount
:= Ccount
+ 1;
12263 Max_Bit_So_Far
:= Uint_Minus_1
;
12264 Overlap_Check_Required
:= False;
12266 -- Process the component clauses
12268 while Present
(CC
) loop
12271 if Present
(Comp
) then
12272 Ccount
:= Ccount
+ 1;
12274 -- We need a full overlap check if record positions non-monotonic
12276 if Fbit
<= Max_Bit_So_Far
then
12277 Overlap_Check_Required
:= True;
12280 Max_Bit_So_Far
:= Lbit
;
12282 -- Check bit position out of range of specified size
12284 if Has_Size_Clause
(Rectype
)
12285 and then RM_Size
(Rectype
) <= Lbit
12287 Error_Msg_Uint_1
:= RM_Size
(Rectype
);
12288 Error_Msg_Uint_2
:= Lbit
+ 1;
12289 Error_Msg_N
("bit number out of range of specified "
12290 & "size (expected ^, got ^)",
12293 -- Check for overlap with tag or parent component
12296 if Is_Tagged_Type
(Rectype
)
12297 and then Fbit
< System_Address_Size
12300 ("component overlaps tag field of&",
12301 Component_Name
(CC
), Rectype
);
12302 Overlap_Detected
:= True;
12304 elsif Present
(Tagged_Parent
)
12305 and then Fbit
<= Parent_Last_Bit
12308 ("component overlaps parent field of&",
12309 Component_Name
(CC
), Rectype
);
12310 Overlap_Detected
:= True;
12313 if Hbit
< Lbit
then
12322 -- Now that we have processed all the component clauses, check for
12323 -- overlap. We have to leave this till last, since the components can
12324 -- appear in any arbitrary order in the representation clause.
12326 -- We do not need this check if all specified ranges were monotonic,
12327 -- as recorded by Overlap_Check_Required being False at this stage.
12329 -- This first section checks if there are any overlapping entries at
12330 -- all. It does this by sorting all entries and then seeing if there are
12331 -- any overlaps. If there are none, then that is decisive, but if there
12332 -- are overlaps, they may still be OK (they may result from fields in
12333 -- different variants).
12335 if Overlap_Check_Required
then
12336 Overlap_Check1
: declare
12338 OC_Fbit
: array (0 .. Ccount
) of Uint
;
12339 -- First-bit values for component clauses, the value is the offset
12340 -- of the first bit of the field from start of record. The zero
12341 -- entry is for use in sorting.
12343 OC_Lbit
: array (0 .. Ccount
) of Uint
;
12344 -- Last-bit values for component clauses, the value is the offset
12345 -- of the last bit of the field from start of record. The zero
12346 -- entry is for use in sorting.
12348 OC_Count
: Natural := 0;
12349 -- Count of entries in OC_Fbit and OC_Lbit
12351 function OC_Lt
(Op1
, Op2
: Natural) return Boolean;
12352 -- Compare routine for Sort
12354 procedure OC_Move
(From
: Natural; To
: Natural);
12355 -- Move routine for Sort
12357 package Sorting
is new GNAT
.Heap_Sort_G
(OC_Move
, OC_Lt
);
12363 function OC_Lt
(Op1
, Op2
: Natural) return Boolean is
12365 return OC_Fbit
(Op1
) < OC_Fbit
(Op2
);
12372 procedure OC_Move
(From
: Natural; To
: Natural) is
12374 OC_Fbit
(To
) := OC_Fbit
(From
);
12375 OC_Lbit
(To
) := OC_Lbit
(From
);
12378 -- Start of processing for Overlap_Check
12381 CC
:= First
(Component_Clauses
(N
));
12382 while Present
(CC
) loop
12384 -- Exclude component clause already marked in error
12386 if not Error_Posted
(CC
) then
12389 if Present
(Comp
) then
12390 OC_Count
:= OC_Count
+ 1;
12391 OC_Fbit
(OC_Count
) := Fbit
;
12392 OC_Lbit
(OC_Count
) := Lbit
;
12399 Sorting
.Sort
(OC_Count
);
12401 Overlap_Check_Required
:= False;
12402 for J
in 1 .. OC_Count
- 1 loop
12403 if OC_Lbit
(J
) >= OC_Fbit
(J
+ 1) then
12404 Overlap_Check_Required
:= True;
12408 end Overlap_Check1
;
12411 -- If Overlap_Check_Required is still True, then we have to do the full
12412 -- scale overlap check, since we have at least two fields that do
12413 -- overlap, and we need to know if that is OK since they are in
12414 -- different variant, or whether we have a definite problem.
12416 if Overlap_Check_Required
then
12417 Overlap_Check2
: declare
12418 C1_Ent
, C2_Ent
: Entity_Id
;
12419 -- Entities of components being checked for overlap
12422 -- Component_List node whose Component_Items are being checked
12425 -- Component declaration for component being checked
12428 C1_Ent
:= First_Entity
(Base_Type
(Rectype
));
12430 -- Loop through all components in record. For each component check
12431 -- for overlap with any of the preceding elements on the component
12432 -- list containing the component and also, if the component is in
12433 -- a variant, check against components outside the case structure.
12434 -- This latter test is repeated recursively up the variant tree.
12436 Main_Component_Loop
: while Present
(C1_Ent
) loop
12437 if Ekind
(C1_Ent
) not in E_Component | E_Discriminant
then
12438 goto Continue_Main_Component_Loop
;
12441 -- Skip overlap check if entity has no declaration node. This
12442 -- happens with discriminants in constrained derived types.
12443 -- Possibly we are missing some checks as a result, but that
12444 -- does not seem terribly serious.
12446 if No
(Declaration_Node
(C1_Ent
)) then
12447 goto Continue_Main_Component_Loop
;
12450 Clist
:= Parent
(List_Containing
(Declaration_Node
(C1_Ent
)));
12452 -- Loop through component lists that need checking. Check the
12453 -- current component list and all lists in variants above us.
12455 Component_List_Loop
: loop
12457 -- If derived type definition, go to full declaration
12458 -- If at outer level, check discriminants if there are any.
12460 if Nkind
(Clist
) = N_Derived_Type_Definition
then
12461 Clist
:= Parent
(Clist
);
12464 -- Outer level of record definition, check discriminants
12465 -- but be careful not to flag a non-stored discriminant
12466 -- and the stored discriminant it renames as overlapping.
12468 if Nkind
(Clist
) in N_Full_Type_Declaration
12469 | N_Private_Type_Declaration
12471 if Has_Discriminants
(Defining_Identifier
(Clist
)) then
12473 First_Discriminant
(Defining_Identifier
(Clist
));
12474 while Present
(C2_Ent
) loop
12476 Original_Record_Component
(C1_Ent
) =
12477 Original_Record_Component
(C2_Ent
);
12478 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
12479 Next_Discriminant
(C2_Ent
);
12483 -- Record extension case
12485 elsif Nkind
(Clist
) = N_Derived_Type_Definition
then
12488 -- Otherwise check one component list
12491 Citem
:= First
(Component_Items
(Clist
));
12492 while Present
(Citem
) loop
12493 if Nkind
(Citem
) = N_Component_Declaration
then
12494 C2_Ent
:= Defining_Identifier
(Citem
);
12495 exit when C1_Ent
= C2_Ent
;
12496 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
12503 -- Check for variants above us (the parent of the Clist can
12504 -- be a variant, in which case its parent is a variant part,
12505 -- and the parent of the variant part is a component list
12506 -- whose components must all be checked against the current
12507 -- component for overlap).
12509 if Nkind
(Parent
(Clist
)) = N_Variant
then
12510 Clist
:= Parent
(Parent
(Parent
(Clist
)));
12512 -- Check for possible discriminant part in record, this
12513 -- is treated essentially as another level in the
12514 -- recursion. For this case the parent of the component
12515 -- list is the record definition, and its parent is the
12516 -- full type declaration containing the discriminant
12519 elsif Nkind
(Parent
(Clist
)) = N_Record_Definition
then
12520 Clist
:= Parent
(Parent
((Clist
)));
12522 -- If neither of these two cases, we are at the top of
12526 exit Component_List_Loop
;
12528 end loop Component_List_Loop
;
12530 <<Continue_Main_Component_Loop
>>
12531 Next_Entity
(C1_Ent
);
12533 end loop Main_Component_Loop
;
12534 end Overlap_Check2
;
12537 -- Skip the following warnings if overlap was detected; programmer
12538 -- should fix the errors first. Also skip the warnings for types in
12539 -- generics, because their representation information is not fully
12542 if not Overlap_Detected
and then not In_Generic_Scope
(Rectype
) then
12543 -- Check for record holes (gaps)
12545 if Warn_On_Record_Holes
then
12549 Record_Hole_Check
(Rectype
, After_Last
=> Ignore
, Warn
=> True);
12553 -- Check for out-of-order component clauses
12555 if Warn_On_Component_Order
then
12556 Component_Order_Check
(Rectype
);
12560 -- For records that have component clauses for all components, and whose
12561 -- size is less than or equal to 32, and which can be fully packed, we
12562 -- need to know the size in the front end to activate possible packed
12563 -- array processing where the component type is a record.
12565 -- At this stage Hbit + 1 represents the first unused bit from all the
12566 -- component clauses processed, so if the component clauses are
12567 -- complete, then this is the length of the record.
12569 -- For records longer than System.Storage_Unit, and for those where not
12570 -- all components have component clauses, the back end determines the
12571 -- length (it may for example be appropriate to round up the size
12572 -- to some convenient boundary, based on alignment considerations, etc).
12574 if not Known_RM_Size
(Rectype
)
12575 and then Hbit
+ 1 <= 32
12576 and then not Strict_Alignment
(Rectype
)
12579 -- Nothing to do if at least one component has no component clause
12581 Comp
:= First_Component_Or_Discriminant
(Rectype
);
12582 while Present
(Comp
) loop
12583 exit when No
(Component_Clause
(Comp
));
12584 Next_Component_Or_Discriminant
(Comp
);
12587 -- If we fall out of loop, all components have component clauses
12588 -- and so we can set the size to the maximum value.
12591 Set_RM_Size
(Rectype
, Hbit
+ 1);
12594 end Check_Record_Representation_Clause
;
12600 procedure Check_Size
12604 Biased
: out Boolean)
12606 procedure Size_Too_Small_Error
(Min_Siz
: Uint
);
12607 -- Emit an error concerning illegal size Siz. Min_Siz denotes the
12610 --------------------------
12611 -- Size_Too_Small_Error --
12612 --------------------------
12614 procedure Size_Too_Small_Error
(Min_Siz
: Uint
) is
12616 Error_Msg_Uint_1
:= Min_Siz
;
12617 Error_Msg_NE
(Size_Too_Small_Message
, N
, T
);
12618 end Size_Too_Small_Error
;
12622 UT
: constant Entity_Id
:= Underlying_Type
(T
);
12625 -- Start of processing for Check_Size
12630 -- Reject patently improper size values
12632 if Is_Elementary_Type
(T
)
12633 and then Siz
> Int
'Last
12635 Error_Msg_N
("Size value too large for elementary type", N
);
12637 if Nkind
(Original_Node
(N
)) = N_Op_Expon
then
12639 ("\maybe '* was meant, rather than '*'*", Original_Node
(N
));
12643 -- Dismiss generic types
12645 if Is_Generic_Type
(T
)
12647 Is_Generic_Type
(UT
)
12649 Is_Generic_Type
(Root_Type
(UT
))
12653 -- Guard against previous errors
12655 elsif No
(UT
) or else UT
= Any_Type
then
12656 Check_Error_Detected
;
12659 -- Check case of bit packed array
12661 elsif Is_Array_Type
(UT
)
12662 and then Known_Static_Component_Size
(UT
)
12663 and then Is_Bit_Packed_Array
(UT
)
12671 Asiz
:= Component_Size
(UT
);
12672 Indx
:= First_Index
(UT
);
12674 Ityp
:= Etype
(Indx
);
12676 -- If non-static bound, then we are not in the business of
12677 -- trying to check the length, and indeed an error will be
12678 -- issued elsewhere, since sizes of non-static array types
12679 -- cannot be set implicitly or explicitly.
12681 if not Is_OK_Static_Subtype
(Ityp
) then
12685 -- Otherwise accumulate next dimension
12687 Asiz
:= Asiz
* (Expr_Value
(Type_High_Bound
(Ityp
)) -
12688 Expr_Value
(Type_Low_Bound
(Ityp
)) +
12692 exit when No
(Indx
);
12695 if Asiz
<= Siz
then
12699 Size_Too_Small_Error
(Asiz
);
12703 -- All other composite types are ignored
12705 elsif Is_Composite_Type
(UT
) then
12708 -- For fixed-point types, don't check minimum if type is not frozen,
12709 -- since we don't know all the characteristics of the type that can
12710 -- affect the size (e.g. a specified small) till freeze time.
12712 elsif Is_Fixed_Point_Type
(UT
) and then not Is_Frozen
(UT
) then
12715 -- Cases for which a minimum check is required
12718 -- Ignore if specified size is correct for the type
12720 if Known_Esize
(UT
) and then Siz
= Esize
(UT
) then
12724 -- Otherwise get minimum size
12726 M
:= UI_From_Int
(Minimum_Size
(UT
));
12730 -- Size is less than minimum size, but one possibility remains
12731 -- that we can manage with the new size if we bias the type.
12733 M
:= UI_From_Int
(Minimum_Size
(UT
, Biased
=> True));
12736 Size_Too_Small_Error
(M
);
12744 --------------------------
12745 -- Freeze_Entity_Checks --
12746 --------------------------
12748 procedure Freeze_Entity_Checks
(N
: Node_Id
) is
12749 procedure Hide_Non_Overridden_Subprograms
(Typ
: Entity_Id
);
12750 -- Inspect the primitive operations of type Typ and hide all pairs of
12751 -- implicitly declared non-overridden non-fully conformant homographs
12752 -- (Ada RM 8.3 12.3/2).
12754 -------------------------------------
12755 -- Hide_Non_Overridden_Subprograms --
12756 -------------------------------------
12758 procedure Hide_Non_Overridden_Subprograms
(Typ
: Entity_Id
) is
12759 procedure Hide_Matching_Homographs
12760 (Subp_Id
: Entity_Id
;
12761 Start_Elmt
: Elmt_Id
);
12762 -- Inspect a list of primitive operations starting with Start_Elmt
12763 -- and find matching implicitly declared non-overridden non-fully
12764 -- conformant homographs of Subp_Id. If found, all matches along
12765 -- with Subp_Id are hidden from all visibility.
12767 function Is_Non_Overridden_Or_Null_Procedure
12768 (Subp_Id
: Entity_Id
) return Boolean;
12769 -- Determine whether subprogram Subp_Id is implicitly declared non-
12770 -- overridden subprogram or an implicitly declared null procedure.
12772 ------------------------------
12773 -- Hide_Matching_Homographs --
12774 ------------------------------
12776 procedure Hide_Matching_Homographs
12777 (Subp_Id
: Entity_Id
;
12778 Start_Elmt
: Elmt_Id
)
12781 Prim_Elmt
: Elmt_Id
;
12784 Prim_Elmt
:= Start_Elmt
;
12785 while Present
(Prim_Elmt
) loop
12786 Prim
:= Node
(Prim_Elmt
);
12788 -- The current primitive is implicitly declared non-overridden
12789 -- non-fully conformant homograph of Subp_Id. Both subprograms
12790 -- must be hidden from visibility.
12792 if Chars
(Prim
) = Chars
(Subp_Id
)
12793 and then Is_Non_Overridden_Or_Null_Procedure
(Prim
)
12794 and then not Fully_Conformant
(Prim
, Subp_Id
)
12796 Set_Is_Hidden_Non_Overridden_Subpgm
(Prim
);
12797 Set_Is_Immediately_Visible
(Prim
, False);
12798 Set_Is_Potentially_Use_Visible
(Prim
, False);
12800 Set_Is_Hidden_Non_Overridden_Subpgm
(Subp_Id
);
12801 Set_Is_Immediately_Visible
(Subp_Id
, False);
12802 Set_Is_Potentially_Use_Visible
(Subp_Id
, False);
12805 Next_Elmt
(Prim_Elmt
);
12807 end Hide_Matching_Homographs
;
12809 -----------------------------------------
12810 -- Is_Non_Overridden_Or_Null_Procedure --
12811 -----------------------------------------
12813 function Is_Non_Overridden_Or_Null_Procedure
12814 (Subp_Id
: Entity_Id
) return Boolean
12816 Alias_Id
: Entity_Id
;
12819 -- The subprogram is inherited (implicitly declared), it does not
12820 -- override and does not cover a primitive of an interface.
12822 if Ekind
(Subp_Id
) in E_Function | E_Procedure
12823 and then Present
(Alias
(Subp_Id
))
12824 and then No
(Interface_Alias
(Subp_Id
))
12825 and then No
(Overridden_Operation
(Subp_Id
))
12827 Alias_Id
:= Alias
(Subp_Id
);
12829 if Requires_Overriding
(Alias_Id
) then
12832 elsif Nkind
(Parent
(Alias_Id
)) = N_Procedure_Specification
12833 and then Null_Present
(Parent
(Alias_Id
))
12840 end Is_Non_Overridden_Or_Null_Procedure
;
12844 Prim_Ops
: constant Elist_Id
:= Direct_Primitive_Operations
(Typ
);
12846 Prim_Elmt
: Elmt_Id
;
12848 -- Start of processing for Hide_Non_Overridden_Subprograms
12851 -- Inspect the list of primitives looking for non-overridden
12854 if Present
(Prim_Ops
) then
12855 Prim_Elmt
:= First_Elmt
(Prim_Ops
);
12856 while Present
(Prim_Elmt
) loop
12857 Prim
:= Node
(Prim_Elmt
);
12858 Next_Elmt
(Prim_Elmt
);
12860 if Is_Non_Overridden_Or_Null_Procedure
(Prim
) then
12861 Hide_Matching_Homographs
12863 Start_Elmt
=> Prim_Elmt
);
12867 end Hide_Non_Overridden_Subprograms
;
12871 E
: constant Entity_Id
:= Entity
(N
);
12873 Nongeneric_Case
: constant Boolean := Nkind
(N
) = N_Freeze_Entity
;
12874 -- True in nongeneric case. Some of the processing here is skipped
12875 -- for the generic case since it is not needed. Basically in the
12876 -- generic case, we only need to do stuff that might generate error
12877 -- messages or warnings.
12879 -- Start of processing for Freeze_Entity_Checks
12882 -- Remember that we are processing a freezing entity. Required to
12883 -- ensure correct decoration of internal entities associated with
12884 -- interfaces (see New_Overloaded_Entity).
12886 Inside_Freezing_Actions
:= Inside_Freezing_Actions
+ 1;
12888 -- For tagged types covering interfaces add internal entities that link
12889 -- the primitives of the interfaces with the primitives that cover them.
12890 -- Note: These entities were originally generated only when generating
12891 -- code because their main purpose was to provide support to initialize
12892 -- the secondary dispatch tables. They are also used to locate
12893 -- primitives covering interfaces when processing generics (see
12894 -- Derive_Subprograms).
12896 -- This is not needed in the generic case
12898 if Ada_Version
>= Ada_2005
12899 and then Nongeneric_Case
12900 and then Ekind
(E
) = E_Record_Type
12901 and then Is_Tagged_Type
(E
)
12902 and then not Is_Interface
(E
)
12903 and then Has_Interfaces
(E
)
12905 -- This would be a good common place to call the routine that checks
12906 -- overriding of interface primitives (and thus factorize calls to
12907 -- Check_Abstract_Overriding located at different contexts in the
12908 -- compiler). However, this is not possible because it causes
12909 -- spurious errors in case of late overriding.
12911 Add_Internal_Interface_Entities
(E
);
12914 -- After all forms of overriding have been resolved, a tagged type may
12915 -- be left with a set of implicitly declared and possibly erroneous
12916 -- abstract subprograms, null procedures and subprograms that require
12917 -- overriding. If this set contains fully conformant homographs, then
12918 -- one is chosen arbitrarily (already done during resolution), otherwise
12919 -- all remaining non-fully conformant homographs are hidden from
12920 -- visibility (Ada RM 8.3 12.3/2).
12922 if Is_Tagged_Type
(E
) then
12923 Hide_Non_Overridden_Subprograms
(E
);
12928 if Ekind
(E
) = E_Record_Type
12929 and then Is_CPP_Class
(E
)
12930 and then Is_Tagged_Type
(E
)
12931 and then Tagged_Type_Expansion
12933 if CPP_Num_Prims
(E
) = 0 then
12935 -- If the CPP type has user defined components then it must import
12936 -- primitives from C++. This is required because if the C++ class
12937 -- has no primitives then the C++ compiler does not added the _tag
12938 -- component to the type.
12940 if First_Entity
(E
) /= Last_Entity
(E
) then
12942 ("'C'P'P type must import at least one primitive from C++??",
12947 -- Check that all its primitives are abstract or imported from C++.
12948 -- Check also availability of the C++ constructor.
12951 Has_Constructors
: constant Boolean := Has_CPP_Constructors
(E
);
12953 Error_Reported
: Boolean := False;
12957 Elmt
:= First_Elmt
(Primitive_Operations
(E
));
12958 while Present
(Elmt
) loop
12959 Prim
:= Node
(Elmt
);
12961 if Comes_From_Source
(Prim
) then
12962 if Is_Abstract_Subprogram
(Prim
) then
12965 elsif not Is_Imported
(Prim
)
12966 or else Convention
(Prim
) /= Convention_CPP
12969 ("primitives of 'C'P'P types must be imported from C++ "
12970 & "or abstract??", Prim
);
12972 elsif not Has_Constructors
12973 and then not Error_Reported
12975 Error_Msg_Name_1
:= Chars
(E
);
12977 ("??'C'P'P constructor required for type %", Prim
);
12978 Error_Reported
:= True;
12987 -- Check Ada derivation of CPP type
12989 if Expander_Active
-- why? losing errors in -gnatc mode???
12990 and then Present
(Etype
(E
)) -- defend against errors
12991 and then Tagged_Type_Expansion
12992 and then Ekind
(E
) = E_Record_Type
12993 and then Etype
(E
) /= E
12994 and then Is_CPP_Class
(Etype
(E
))
12995 and then CPP_Num_Prims
(Etype
(E
)) > 0
12996 and then not Is_CPP_Class
(E
)
12997 and then not Has_CPP_Constructors
(Etype
(E
))
12999 -- If the parent has C++ primitives but it has no constructor then
13000 -- check that all the primitives are overridden in this derivation;
13001 -- otherwise the constructor of the parent is needed to build the
13009 Elmt
:= First_Elmt
(Primitive_Operations
(E
));
13010 while Present
(Elmt
) loop
13011 Prim
:= Node
(Elmt
);
13013 if not Is_Abstract_Subprogram
(Prim
)
13014 and then No
(Interface_Alias
(Prim
))
13015 and then Find_Dispatching_Type
(Ultimate_Alias
(Prim
)) /= E
13017 Error_Msg_Name_1
:= Chars
(Etype
(E
));
13019 ("'C'P'P constructor required for parent type %", E
);
13028 Inside_Freezing_Actions
:= Inside_Freezing_Actions
- 1;
13030 -- For a record type, deal with variant parts. This has to be delayed to
13031 -- this point, because of the issue of statically predicated subtypes,
13032 -- which we have to ensure are frozen before checking choices, since we
13033 -- need to have the static choice list set.
13035 if Is_Record_Type
(E
) then
13036 Check_Variant_Part
: declare
13037 D
: constant Node_Id
:= Declaration_Node
(E
);
13042 Others_Present
: Boolean;
13043 pragma Warnings
(Off
, Others_Present
);
13044 -- Indicates others present, not used in this case
13046 procedure Non_Static_Choice_Error
(Choice
: Node_Id
);
13047 -- Error routine invoked by the generic instantiation below when
13048 -- the variant part has a non static choice.
13050 procedure Process_Declarations
(Variant
: Node_Id
);
13051 -- Processes declarations associated with a variant. We analyzed
13052 -- the declarations earlier (in Sem_Ch3.Analyze_Variant_Part),
13053 -- but we still need the recursive call to Check_Choices for any
13054 -- nested variant to get its choices properly processed. This is
13055 -- also where we expand out the choices if expansion is active.
13057 package Variant_Choices_Processing
is new
13058 Generic_Check_Choices
13059 (Process_Empty_Choice
=> No_OP
,
13060 Process_Non_Static_Choice
=> Non_Static_Choice_Error
,
13061 Process_Associated_Node
=> Process_Declarations
);
13062 use Variant_Choices_Processing
;
13064 -----------------------------
13065 -- Non_Static_Choice_Error --
13066 -----------------------------
13068 procedure Non_Static_Choice_Error
(Choice
: Node_Id
) is
13070 Flag_Non_Static_Expr
13071 ("choice given in variant part is not static!", Choice
);
13072 end Non_Static_Choice_Error
;
13074 --------------------------
13075 -- Process_Declarations --
13076 --------------------------
13078 procedure Process_Declarations
(Variant
: Node_Id
) is
13079 CL
: constant Node_Id
:= Component_List
(Variant
);
13083 -- Check for static predicate present in this variant
13085 if Has_SP_Choice
(Variant
) then
13087 -- Here we expand. You might expect to find this call in
13088 -- Expand_N_Variant_Part, but that is called when we first
13089 -- see the variant part, and we cannot do this expansion
13090 -- earlier than the freeze point, since for statically
13091 -- predicated subtypes, the predicate is not known till
13092 -- the freeze point.
13094 -- Furthermore, we do this expansion even if the expander
13095 -- is not active, because other semantic processing, e.g.
13096 -- for aggregates, requires the expanded list of choices.
13098 -- If the expander is not active, then we can't just clobber
13099 -- the list since it would invalidate the tree.
13100 -- So we have to rewrite the variant part with a Rewrite
13101 -- call that replaces it with a copy and clobber the copy.
13103 if not Expander_Active
then
13105 NewV
: constant Node_Id
:= New_Copy
(Variant
);
13107 Set_Discrete_Choices
13108 (NewV
, New_Copy_List
(Discrete_Choices
(Variant
)));
13109 Rewrite
(Variant
, NewV
);
13113 Expand_Static_Predicates_In_Choices
(Variant
);
13116 -- We don't need to worry about the declarations in the variant
13117 -- (since they were analyzed by Analyze_Choices when we first
13118 -- encountered the variant), but we do need to take care of
13119 -- expansion of any nested variants.
13121 if not Null_Present
(CL
) then
13122 VP
:= Variant_Part
(CL
);
13124 if Present
(VP
) then
13126 (VP
, Variants
(VP
), Etype
(Name
(VP
)), Others_Present
);
13129 end Process_Declarations
;
13131 -- Start of processing for Check_Variant_Part
13134 -- Find component list
13138 if Nkind
(D
) = N_Full_Type_Declaration
then
13139 T
:= Type_Definition
(D
);
13141 if Nkind
(T
) = N_Record_Definition
then
13142 C
:= Component_List
(T
);
13144 elsif Nkind
(T
) = N_Derived_Type_Definition
13145 and then Present
(Record_Extension_Part
(T
))
13147 C
:= Component_List
(Record_Extension_Part
(T
));
13151 -- Case of variant part present
13153 if Present
(C
) and then Present
(Variant_Part
(C
)) then
13154 VP
:= Variant_Part
(C
);
13159 (VP
, Variants
(VP
), Etype
(Name
(VP
)), Others_Present
);
13161 -- If the last variant does not contain the Others choice,
13162 -- replace it with an N_Others_Choice node since Gigi always
13163 -- wants an Others. Note that we do not bother to call Analyze
13164 -- on the modified variant part, since its only effect would be
13165 -- to compute the Others_Discrete_Choices node laboriously, and
13166 -- of course we already know the list of choices corresponding
13167 -- to the others choice (it's the list we're replacing).
13169 -- We only want to do this if the expander is active, since
13170 -- we do not want to clobber the tree.
13172 if Expander_Active
then
13174 Last_Var
: constant Node_Id
:=
13175 Last_Non_Pragma
(Variants
(VP
));
13177 Others_Node
: Node_Id
;
13180 if Nkind
(First
(Discrete_Choices
(Last_Var
))) /=
13183 Others_Node
:= Make_Others_Choice
(Sloc
(Last_Var
));
13184 Set_Others_Discrete_Choices
13185 (Others_Node
, Discrete_Choices
(Last_Var
));
13186 Set_Discrete_Choices
13187 (Last_Var
, New_List
(Others_Node
));
13192 end Check_Variant_Part
;
13195 -- If we have a type with predicates, build predicate function. This is
13196 -- not needed in the generic case, nor within e.g. TSS subprograms and
13197 -- other predefined primitives. For a derived type, ensure that the
13198 -- parent type is already frozen so that its predicate function has been
13199 -- constructed already. This is necessary if the parent is declared
13200 -- in a nested package and its own freeze point has not been reached.
13203 and then Nongeneric_Case
13204 and then Has_Predicates
(E
)
13205 and then Predicate_Check_In_Scope
(N
)
13208 Atyp
: constant Entity_Id
:= Nearest_Ancestor
(E
);
13212 and then Has_Predicates
(Atyp
)
13213 and then not Is_Frozen
(Atyp
)
13215 Freeze_Before
(N
, Atyp
);
13219 -- Before we build a predicate function, ensure that discriminant
13220 -- checking functions are available. The predicate function might
13221 -- need to call these functions if the predicate references any
13222 -- components declared in a variant part.
13224 if Ekind
(E
) = E_Record_Type
and then Has_Discriminants
(E
) then
13225 Build_Or_Copy_Discr_Checking_Funcs
(Parent
(E
));
13228 Build_Predicate_Function
(E
, N
);
13231 -- If type has delayed aspects, this is where we do the preanalysis at
13232 -- the freeze point, as part of the consistent visibility check. Note
13233 -- that this must be done after calling Build_Predicate_Function or
13234 -- Build_Invariant_Procedure since these subprograms fix occurrences of
13235 -- the subtype name in the saved expression so that they will not cause
13236 -- trouble in the preanalysis.
13238 -- This is also not needed in the generic case
13241 and then Has_Delayed_Aspects
(E
)
13242 and then Scope
(E
) = Current_Scope
13248 -- Look for aspect specification entries for this entity
13250 Ritem
:= First_Rep_Item
(E
);
13251 while Present
(Ritem
) loop
13252 if Nkind
(Ritem
) = N_Aspect_Specification
13253 and then Entity
(Ritem
) = E
13254 and then Is_Delayed_Aspect
(Ritem
)
13256 if Get_Aspect_Id
(Ritem
) in Aspect_CPU
13257 | Aspect_Dynamic_Predicate
13259 | Aspect_Static_Predicate
13262 -- Retrieve the visibility to components and discriminants
13263 -- in order to properly analyze the aspects.
13266 Check_Aspect_At_Freeze_Point
(Ritem
);
13268 -- In the case of predicate aspects, there will be
13269 -- a corresponding Predicate pragma associated with
13270 -- the aspect, and the expression of the pragma also
13271 -- needs to be analyzed at this point, to ensure that
13272 -- Save_Global_References will capture global refs in
13273 -- expressions that occur in generic bodies, for proper
13274 -- later resolution of the pragma in instantiations.
13277 and then Inside_A_Generic
13278 and then Has_Predicates
(E
)
13279 and then Present
(Aspect_Rep_Item
(Ritem
))
13282 Pragma_Args
: constant List_Id
:=
13283 Pragma_Argument_Associations
13284 (Aspect_Rep_Item
(Ritem
));
13285 Pragma_Expr
: constant Node_Id
:=
13286 Expression
(Next
(First
(Pragma_Args
)));
13288 if Present
(Pragma_Expr
) then
13289 Analyze_And_Resolve
13290 (Pragma_Expr
, Standard_Boolean
);
13298 Check_Aspect_At_Freeze_Point
(Ritem
);
13301 -- A pragma Predicate should be checked like one of the
13302 -- corresponding aspects, wrt possible misuse of ghost
13305 elsif Nkind
(Ritem
) = N_Pragma
13306 and then No
(Corresponding_Aspect
(Ritem
))
13308 Get_Pragma_Id
(Pragma_Name
(Ritem
)) = Pragma_Predicate
13310 -- Retrieve the visibility to components and discriminants
13311 -- in order to properly analyze the pragma.
13314 Arg
: constant Node_Id
:=
13315 Next
(First
(Pragma_Argument_Associations
(Ritem
)));
13318 Preanalyze_Spec_Expression
13319 (Expression
(Arg
), Standard_Boolean
);
13324 Next_Rep_Item
(Ritem
);
13329 if not In_Generic_Scope
(E
)
13330 and then Ekind
(E
) = E_Record_Type
13331 and then Is_Tagged_Type
(E
)
13333 Process_Class_Conditions_At_Freeze_Point
(E
);
13335 end Freeze_Entity_Checks
;
13337 -------------------------
13338 -- Get_Alignment_Value --
13339 -------------------------
13341 function Get_Alignment_Value
(Expr
: Node_Id
) return Uint
is
13342 Align
: constant Uint
:= Static_Integer
(Expr
);
13348 elsif Align
< 0 then
13349 Error_Msg_N
("alignment value must be positive", Expr
);
13352 -- If Alignment is specified to be 0, we treat it the same as 1
13354 elsif Align
= 0 then
13358 for J
in Int
range 0 .. 64 loop
13360 M
: constant Uint
:= Uint_2
** J
;
13363 exit when M
= Align
;
13366 Error_Msg_N
("alignment value must be power of 2", Expr
);
13374 end Get_Alignment_Value
;
13376 -----------------------------------
13377 -- Has_Compatible_Representation --
13378 -----------------------------------
13380 function Has_Compatible_Representation
13381 (Target_Typ
, Operand_Typ
: Entity_Id
) return Boolean
13383 -- The subtype-specific representation attributes (Size and Alignment)
13384 -- do not affect representation from the point of view of this function.
13386 T1
: constant Entity_Id
:= Implementation_Base_Type
(Target_Typ
);
13387 T2
: constant Entity_Id
:= Implementation_Base_Type
(Operand_Typ
);
13390 -- Return true immediately for the same base type
13395 -- Tagged types always have the same representation, because it is not
13396 -- possible to specify different representations for common fields.
13398 elsif Is_Tagged_Type
(T1
) then
13401 -- Representations are definitely different if conventions differ
13403 elsif Convention
(T1
) /= Convention
(T2
) then
13406 -- Representations are different if component alignments or scalar
13407 -- storage orders differ.
13409 elsif (Is_Record_Type
(T1
) or else Is_Array_Type
(T1
))
13411 (Is_Record_Type
(T2
) or else Is_Array_Type
(T2
))
13412 and then (Component_Alignment
(T1
) /= Component_Alignment
(T2
)
13414 Reverse_Storage_Order
(T1
) /= Reverse_Storage_Order
(T2
))
13419 -- For arrays, the only real issue is component size. If we know the
13420 -- component size for both arrays, and it is the same, then that's
13421 -- good enough to know we don't have a change of representation.
13423 if Is_Array_Type
(T1
) then
13425 -- In a view conversion, if the target type is an array type having
13426 -- aliased components and the operand type is an array type having
13427 -- unaliased components, then a new object is created (4.6(58.3/4)).
13429 if Has_Aliased_Components
(T1
)
13430 and then not Has_Aliased_Components
(T2
)
13435 if Known_Component_Size
(T1
)
13436 and then Known_Component_Size
(T2
)
13437 and then Component_Size
(T1
) = Component_Size
(T2
)
13442 -- For records, representations are different if reordering differs
13444 elsif Is_Record_Type
(T1
)
13445 and then Is_Record_Type
(T2
)
13446 and then No_Reordering
(T1
) /= No_Reordering
(T2
)
13451 -- Types definitely have same representation if neither has non-standard
13452 -- representation since default representations are always consistent.
13453 -- If only one has non-standard representation, and the other does not,
13454 -- then we consider that they do not have the same representation. They
13455 -- might, but there is no way of telling early enough.
13457 if Has_Non_Standard_Rep
(T1
) then
13458 if not Has_Non_Standard_Rep
(T2
) then
13462 return not Has_Non_Standard_Rep
(T2
);
13465 -- Here the two types both have non-standard representation, and we need
13466 -- to determine if they have the same non-standard representation.
13468 -- For arrays, we simply need to test if the component sizes are the
13469 -- same. Pragma Pack is reflected in modified component sizes, so this
13470 -- check also deals with pragma Pack.
13472 if Is_Array_Type
(T1
) then
13473 return Component_Size
(T1
) = Component_Size
(T2
);
13475 -- Case of record types
13477 elsif Is_Record_Type
(T1
) then
13479 -- Packed status must conform
13481 if Is_Packed
(T1
) /= Is_Packed
(T2
) then
13484 -- If the operand type is derived from the target type and no clause
13485 -- has been given after the derivation, then the representations are
13486 -- the same since the derived type inherits that of the parent type.
13488 elsif Is_Derived_Type
(T2
)
13489 and then Etype
(T2
) = T1
13490 and then not Has_Record_Rep_Clause
(T2
)
13494 -- Otherwise we must check components. Typ2 maybe a constrained
13495 -- subtype with fewer components, so we compare the components
13496 -- of the base types.
13499 Record_Case
: declare
13500 CD1
, CD2
: Entity_Id
;
13502 function Same_Rep
return Boolean;
13503 -- CD1 and CD2 are either components or discriminants. This
13504 -- function tests whether they have the same representation.
13510 function Same_Rep
return Boolean is
13512 if No
(Component_Clause
(CD1
)) then
13513 return No
(Component_Clause
(CD2
));
13515 -- Note: at this point, component clauses have been
13516 -- normalized to the default bit order, so that the
13517 -- comparison of Component_Bit_Offsets is meaningful.
13520 Present
(Component_Clause
(CD2
))
13522 Component_Bit_Offset
(CD1
) = Component_Bit_Offset
(CD2
)
13524 Esize
(CD1
) = Esize
(CD2
);
13528 -- Start of processing for Record_Case
13531 if Has_Discriminants
(T1
) then
13533 -- The number of discriminants may be different if the
13534 -- derived type has fewer (constrained by values). The
13535 -- invisible discriminants retain the representation of
13536 -- the original, so the discrepancy does not per se
13537 -- indicate a different representation.
13539 CD1
:= First_Discriminant
(T1
);
13540 CD2
:= First_Discriminant
(T2
);
13541 while Present
(CD1
) and then Present
(CD2
) loop
13542 if not Same_Rep
then
13545 Next_Discriminant
(CD1
);
13546 Next_Discriminant
(CD2
);
13551 CD1
:= First_Component
(Underlying_Type
(Base_Type
(T1
)));
13552 CD2
:= First_Component
(Underlying_Type
(Base_Type
(T2
)));
13553 while Present
(CD1
) loop
13554 if not Same_Rep
then
13557 Next_Component
(CD1
);
13558 Next_Component
(CD2
);
13566 -- For enumeration types, we must check each literal to see if the
13567 -- representation is the same. Note that we do not permit enumeration
13568 -- representation clauses for Character and Wide_Character, so these
13569 -- cases were already dealt with.
13571 elsif Is_Enumeration_Type
(T1
) then
13572 Enumeration_Case
: declare
13573 L1
, L2
: Entity_Id
;
13576 L1
:= First_Literal
(T1
);
13577 L2
:= First_Literal
(T2
);
13578 while Present
(L1
) loop
13579 if Enumeration_Rep
(L1
) /= Enumeration_Rep
(L2
) then
13588 end Enumeration_Case
;
13590 -- Any other types have the same representation for these purposes
13595 end Has_Compatible_Representation
;
13597 -------------------------------------
13598 -- Inherit_Aspects_At_Freeze_Point --
13599 -------------------------------------
13601 procedure Inherit_Aspects_At_Freeze_Point
(Typ
: Entity_Id
) is
13602 function Get_Inherited_Rep_Item
13604 Nam
: Name_Id
) return Node_Id
;
13605 -- Search the Rep_Item chain of entity E for an instance of a rep item
13606 -- (pragma, attribute definition clause, or aspect specification) whose
13607 -- name matches the given name Nam, and that has been inherited from its
13608 -- parent, i.e. that has not been directly specified for E . If one is
13609 -- found, it is returned, otherwise Empty is returned.
13611 function Get_Inherited_Rep_Item
13614 Nam2
: Name_Id
) return Node_Id
;
13615 -- Search the Rep_Item chain of entity E for an instance of a rep item
13616 -- (pragma, attribute definition clause, or aspect specification) whose
13617 -- name matches one of the given names Nam1 or Nam2, and that has been
13618 -- inherited from its parent, i.e. that has not been directly specified
13619 -- for E . If one is found, it is returned, otherwise Empty is returned.
13621 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
13622 (Rep_Item
: Node_Id
) return Boolean;
13623 -- This routine checks if Rep_Item is either a pragma or an aspect
13624 -- specification node whose corresponding pragma (if any) is present in
13625 -- the Rep Item chain of the entity it has been specified to.
13627 ----------------------------
13628 -- Get_Inherited_Rep_Item --
13629 ----------------------------
13631 function Get_Inherited_Rep_Item
13633 Nam
: Name_Id
) return Node_Id
13635 Rep
: constant Node_Id
13636 := Get_Rep_Item
(E
, Nam
, Check_Parents
=> True);
13639 and then not Has_Rep_Item
(E
, Nam
, Check_Parents
=> False)
13645 end Get_Inherited_Rep_Item
;
13647 function Get_Inherited_Rep_Item
13650 Nam2
: Name_Id
) return Node_Id
13652 Rep
: constant Node_Id
13653 := Get_Rep_Item
(E
, Nam1
, Nam2
, Check_Parents
=> True);
13656 and then not Has_Rep_Item
(E
, Nam1
, Nam2
, Check_Parents
=> False)
13662 end Get_Inherited_Rep_Item
;
13664 --------------------------------------------------
13665 -- Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item --
13666 --------------------------------------------------
13668 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
13669 (Rep_Item
: Node_Id
) return Boolean
13673 Nkind
(Rep_Item
) = N_Pragma
13675 Present_In_Rep_Item
(Entity
(Rep_Item
), Aspect_Rep_Item
(Rep_Item
));
13676 end Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
;
13680 -- Start of processing for Inherit_Aspects_At_Freeze_Point
13683 -- A representation item is either subtype-specific (Size and Alignment
13684 -- clauses) or type-related (all others). Subtype-specific aspects may
13685 -- differ for different subtypes of the same type (RM 13.1.8).
13687 -- A derived type inherits each type-related representation aspect of
13688 -- its parent type that was directly specified before the declaration of
13689 -- the derived type (RM 13.1.15).
13691 -- A derived subtype inherits each subtype-specific representation
13692 -- aspect of its parent subtype that was directly specified before the
13693 -- declaration of the derived type (RM 13.1.15).
13695 -- The general processing involves inheriting a representation aspect
13696 -- from a parent type whenever the first rep item (aspect specification,
13697 -- attribute definition clause, pragma) corresponding to the given
13698 -- representation aspect in the rep item chain of Typ, if any, isn't
13699 -- directly specified to Typ but to one of its parents.
13701 -- In addition, Convention must be propagated from base type to subtype,
13702 -- because the subtype may have been declared on an incomplete view.
13704 if Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
then
13710 Rep
:= Get_Inherited_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
);
13712 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
(Rep
)
13714 Set_Is_Ada_2005_Only
(Typ
);
13719 Rep
:= Get_Inherited_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
);
13721 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
(Rep
)
13723 Set_Is_Ada_2012_Only
(Typ
);
13728 Rep
:= Get_Inherited_Rep_Item
(Typ
, Name_Ada_2022
);
13730 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
(Rep
)
13732 Set_Is_Ada_2022_Only
(Typ
);
13737 Rep
:= Get_Inherited_Rep_Item
(Typ
, Name_Atomic
, Name_Shared
);
13739 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
(Rep
)
13741 Set_Is_Atomic
(Typ
);
13742 Set_Is_Volatile
(Typ
);
13743 Set_Treat_As_Volatile
(Typ
);
13748 if Is_Record_Type
(Typ
)
13749 and then Typ
/= Base_Type
(Typ
) and then Is_Frozen
(Base_Type
(Typ
))
13751 Set_Convention
(Typ
, Convention
(Base_Type
(Typ
)));
13754 -- Default_Component_Value (for base types only)
13756 -- Note that we need to look into the first subtype because the base
13757 -- type may be the implicit base type built by the compiler for the
13758 -- declaration of a constrained subtype with the aspect.
13760 if Is_Array_Type
(Typ
) and then Is_Base_Type
(Typ
) then
13762 F_Typ
: constant Entity_Id
:= First_Subtype
(Typ
);
13768 Get_Inherited_Rep_Item
(F_Typ
, Name_Default_Component_Value
);
13769 if Present
(Rep
) then
13772 -- Deal with private types
13774 if Is_Private_Type
(E
) then
13775 E
:= Full_View
(E
);
13778 Set_Default_Aspect_Component_Value
13779 (Typ
, Default_Aspect_Component_Value
(E
));
13780 Set_Has_Default_Aspect
(Typ
);
13785 -- Default_Value (for base types only)
13787 -- Note that we need to look into the first subtype because the base
13788 -- type may be the implicit base type built by the compiler for the
13789 -- declaration of a constrained subtype with the aspect.
13791 if Is_Scalar_Type
(Typ
) and then Is_Base_Type
(Typ
) then
13793 F_Typ
: constant Entity_Id
:= First_Subtype
(Typ
);
13798 Rep
:= Get_Inherited_Rep_Item
(F_Typ
, Name_Default_Value
);
13799 if Present
(Rep
) then
13802 -- Deal with private types
13804 if Is_Private_Type
(E
) then
13805 E
:= Full_View
(E
);
13808 Set_Default_Aspect_Value
(Typ
, Default_Aspect_Value
(E
));
13809 Set_Has_Default_Aspect
(Typ
);
13816 Rep
:= Get_Inherited_Rep_Item
(Typ
, Name_Discard_Names
);
13818 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
(Rep
)
13820 Set_Discard_Names
(Typ
);
13825 Rep
:= Get_Inherited_Rep_Item
(Typ
, Name_Volatile
);
13827 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
(Rep
)
13829 Set_Is_Volatile
(Typ
);
13830 Set_Treat_As_Volatile
(Typ
);
13833 -- Volatile_Full_Access and Full_Access_Only
13835 Rep
:= Get_Inherited_Rep_Item
13836 (Typ
, Name_Volatile_Full_Access
, Name_Full_Access_Only
);
13838 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
(Rep
)
13840 Set_Is_Volatile_Full_Access
(Typ
);
13841 Set_Is_Volatile
(Typ
);
13842 Set_Treat_As_Volatile
(Typ
);
13845 -- Inheritance for derived types only
13847 if Is_Derived_Type
(Typ
) then
13849 Bas_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
13850 Imp_Bas_Typ
: constant Entity_Id
:= Implementation_Base_Type
(Typ
);
13853 -- Atomic_Components
13855 Rep
:= Get_Inherited_Rep_Item
(Typ
, Name_Atomic_Components
);
13857 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
(Rep
)
13859 Set_Has_Atomic_Components
(Imp_Bas_Typ
);
13862 -- Volatile_Components
13864 Rep
:= Get_Inherited_Rep_Item
(Typ
, Name_Volatile_Components
);
13866 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
(Rep
)
13868 Set_Has_Volatile_Components
(Imp_Bas_Typ
);
13871 -- Finalize_Storage_Only
13873 Rep
:= Get_Inherited_Rep_Item
(Typ
, Name_Finalize_Storage_Only
);
13874 if Present
(Rep
) then
13875 Set_Finalize_Storage_Only
(Bas_Typ
);
13878 -- Universal_Aliasing
13880 Rep
:= Get_Inherited_Rep_Item
(Typ
, Name_Universal_Aliasing
);
13882 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
(Rep
)
13884 Set_Universal_Aliasing
(Imp_Bas_Typ
);
13889 if Is_Record_Type
(Typ
) and then Typ
= Bas_Typ
then
13890 Rep
:= Get_Inherited_Rep_Item
(Typ
, Name_Bit_Order
);
13891 if Present
(Rep
) then
13892 Set_Reverse_Bit_Order
(Bas_Typ
,
13894 (Implementation_Base_Type
(Etype
(Bas_Typ
))));
13898 -- Scalar_Storage_Order
13900 if (Is_Record_Type
(Typ
) or else Is_Array_Type
(Typ
))
13901 and then Typ
= Bas_Typ
13903 -- For a type extension, always inherit from parent; otherwise
13904 -- inherit if no default applies. Note: we do not check for
13905 -- an explicit rep item on the parent type when inheriting,
13906 -- because the parent SSO may itself have been set by default.
13908 if not Has_Rep_Item
(First_Subtype
(Typ
),
13909 Name_Scalar_Storage_Order
, False)
13910 and then (Is_Tagged_Type
(Bas_Typ
)
13911 or else not (SSO_Set_Low_By_Default
(Bas_Typ
)
13913 SSO_Set_High_By_Default
(Bas_Typ
)))
13915 Set_Reverse_Storage_Order
(Bas_Typ
,
13916 Reverse_Storage_Order
13917 (Implementation_Base_Type
(Etype
(Bas_Typ
))));
13919 -- Clear default SSO indications, since the inherited aspect
13920 -- which was set explicitly overrides the default.
13922 Set_SSO_Set_Low_By_Default
(Bas_Typ
, False);
13923 Set_SSO_Set_High_By_Default
(Bas_Typ
, False);
13928 end Inherit_Aspects_At_Freeze_Point
;
13930 ---------------------------------
13931 -- Inherit_Delayed_Rep_Aspects --
13932 ---------------------------------
13934 procedure Inherit_Delayed_Rep_Aspects
(Typ
: Entity_Id
) is
13940 -- Find the first aspect that has been inherited
13942 N
:= First_Rep_Item
(Typ
);
13943 while Present
(N
) loop
13944 if Nkind
(N
) = N_Aspect_Specification
then
13945 exit when Entity
(N
) /= Typ
;
13951 -- There must be one if we reach here
13953 pragma Assert
(Present
(N
));
13956 -- Loop through delayed aspects for the parent type
13958 while Present
(N
) loop
13959 if Nkind
(N
) = N_Aspect_Specification
then
13960 exit when Entity
(N
) /= P
;
13962 if Is_Delayed_Aspect
(N
) then
13963 A
:= Get_Aspect_Id
(N
);
13965 -- Process delayed rep aspect. For Boolean attributes it is
13966 -- not possible to cancel an attribute once set (the attempt
13967 -- to use an aspect with xxx => False is an error) for a
13968 -- derived type. So for those cases, we do not have to check
13969 -- if a clause has been given for the derived type, since it
13970 -- is harmless to set it again if it is already set.
13976 when Aspect_Alignment
=>
13977 if not Has_Alignment_Clause
(Typ
) then
13978 Set_Alignment
(Typ
, Alignment
(P
));
13983 when Aspect_Atomic
=>
13984 if Is_Atomic
(P
) then
13985 Set_Is_Atomic
(Typ
);
13988 -- Atomic_Components
13990 when Aspect_Atomic_Components
=>
13991 if Has_Atomic_Components
(P
) then
13992 Set_Has_Atomic_Components
(Base_Type
(Typ
));
13997 when Aspect_Bit_Order
=>
13998 if Is_Record_Type
(Typ
)
13999 and then No
(Get_Attribute_Definition_Clause
14000 (Typ
, Attribute_Bit_Order
))
14001 and then Reverse_Bit_Order
(P
)
14003 Set_Reverse_Bit_Order
(Base_Type
(Typ
));
14008 when Aspect_Component_Size
=>
14009 if Is_Array_Type
(Typ
)
14010 and then not Has_Component_Size_Clause
(Typ
)
14013 (Base_Type
(Typ
), Component_Size
(P
));
14018 when Aspect_Machine_Radix
=>
14019 if Is_Decimal_Fixed_Point_Type
(Typ
)
14020 and then not Has_Machine_Radix_Clause
(Typ
)
14022 Set_Machine_Radix_10
(Typ
, Machine_Radix_10
(P
));
14025 -- Object_Size (also Size which also sets Object_Size)
14027 when Aspect_Object_Size
14030 if not Has_Size_Clause
(Typ
)
14032 No
(Get_Attribute_Definition_Clause
14033 (Typ
, Attribute_Object_Size
))
14035 Set_Esize
(Typ
, Esize
(P
));
14040 when Aspect_Pack
=>
14041 if not Is_Packed
(Typ
) then
14042 Set_Is_Packed
(Base_Type
(Typ
));
14044 if Is_Bit_Packed_Array
(P
) then
14045 Set_Is_Bit_Packed_Array
(Base_Type
(Typ
));
14046 Set_Packed_Array_Impl_Type
14047 (Typ
, Packed_Array_Impl_Type
(P
));
14051 -- Scalar_Storage_Order
14053 when Aspect_Scalar_Storage_Order
=>
14054 if (Is_Record_Type
(Typ
) or else Is_Array_Type
(Typ
))
14055 and then No
(Get_Attribute_Definition_Clause
14056 (Typ
, Attribute_Scalar_Storage_Order
))
14057 and then Reverse_Storage_Order
(P
)
14059 Set_Reverse_Storage_Order
(Base_Type
(Typ
));
14061 -- Clear default SSO indications, since the aspect
14062 -- overrides the default.
14064 Set_SSO_Set_Low_By_Default
(Base_Type
(Typ
), False);
14065 Set_SSO_Set_High_By_Default
(Base_Type
(Typ
), False);
14070 when Aspect_Small
=>
14071 if Is_Fixed_Point_Type
(Typ
)
14072 and then not Has_Small_Clause
(Typ
)
14074 Set_Small_Value
(Typ
, Small_Value
(P
));
14079 when Aspect_Storage_Size
=>
14080 if (Is_Access_Type
(Typ
) or else Is_Task_Type
(Typ
))
14081 and then not Has_Storage_Size_Clause
(Typ
)
14083 Set_Storage_Size_Variable
14084 (Base_Type
(Typ
), Storage_Size_Variable
(P
));
14089 when Aspect_Value_Size
=>
14091 -- Value_Size is never inherited, it is either set by
14092 -- default, or it is explicitly set for the derived
14093 -- type. So nothing to do here.
14099 when Aspect_Volatile
=>
14100 if Is_Volatile
(P
) then
14101 Set_Is_Volatile
(Typ
);
14104 -- Volatile_Full_Access (also Full_Access_Only)
14106 when Aspect_Volatile_Full_Access
14107 | Aspect_Full_Access_Only
14109 if Is_Volatile_Full_Access
(P
) then
14110 Set_Is_Volatile_Full_Access
(Typ
);
14113 -- Volatile_Components
14115 when Aspect_Volatile_Components
=>
14116 if Has_Volatile_Components
(P
) then
14117 Set_Has_Volatile_Components
(Base_Type
(Typ
));
14120 -- That should be all the Rep Aspects
14123 pragma Assert
(Aspect_Delay
(A
) /= Rep_Aspect
);
14131 end Inherit_Delayed_Rep_Aspects
;
14137 procedure Initialize
is
14139 Address_Clause_Checks
.Init
;
14140 Unchecked_Conversions
.Init
;
14142 -- The following might be needed in the future for some non-GCC back
14144 -- if AAMP_On_Target then
14145 -- Independence_Checks.Init;
14149 ---------------------------
14150 -- Install_Discriminants --
14151 ---------------------------
14153 procedure Install_Discriminants
(E
: Entity_Id
) is
14157 Disc
:= First_Discriminant
(E
);
14158 while Present
(Disc
) loop
14159 Prev
:= Current_Entity
(Disc
);
14160 Set_Current_Entity
(Disc
);
14161 Set_Is_Immediately_Visible
(Disc
);
14162 Set_Homonym
(Disc
, Prev
);
14163 Next_Discriminant
(Disc
);
14165 end Install_Discriminants
;
14167 -------------------------
14168 -- Is_Operational_Item --
14169 -------------------------
14171 function Is_Operational_Item
(N
: Node_Id
) return Boolean is
14173 -- List of operational items is given in AARM 13.1(8.mm/1). It is
14174 -- clearly incomplete, as it does not include iterator aspects, among
14177 return Nkind
(N
) = N_Attribute_Definition_Clause
14179 Get_Attribute_Id
(Chars
(N
)) in Attribute_Constant_Indexing
14180 | Attribute_External_Tag
14181 | Attribute_Default_Iterator
14182 | Attribute_Implicit_Dereference
14184 | Attribute_Iterable
14185 | Attribute_Iterator_Element
14187 | Attribute_Put_Image
14189 | Attribute_Variable_Indexing
14191 end Is_Operational_Item
;
14193 -------------------------
14194 -- Is_Predicate_Static --
14195 -------------------------
14197 -- Note: the basic legality of the expression has already been checked, so
14198 -- we don't need to worry about cases or ranges on strings for example.
14200 function Is_Predicate_Static
14203 Warn
: Boolean := True) return Boolean
14205 function All_Static_Case_Alternatives
(L
: List_Id
) return Boolean;
14206 -- Given a list of case expression alternatives, returns True if all
14207 -- the alternatives are static (have all static choices, and a static
14210 function Is_Type_Ref
(N
: Node_Id
) return Boolean;
14211 pragma Inline
(Is_Type_Ref
);
14212 -- Returns True if N is a reference to the type for the predicate in the
14213 -- expression (i.e. if it is an identifier whose Chars field matches the
14214 -- Nam given in the call). N must not be parenthesized, if the type name
14215 -- appears in parens, this routine will return False.
14217 -- The routine also returns True for function calls generated during the
14218 -- expansion of comparison operators on strings, which are intended to
14219 -- be legal in static predicates, and are converted into calls to array
14220 -- comparison routines in the body of the corresponding predicate
14223 ----------------------------------
14224 -- All_Static_Case_Alternatives --
14225 ----------------------------------
14227 function All_Static_Case_Alternatives
(L
: List_Id
) return Boolean is
14232 while Present
(N
) loop
14233 if not (All_Static_Choices
(Discrete_Choices
(N
))
14234 and then Is_OK_Static_Expression
(Expression
(N
)))
14243 end All_Static_Case_Alternatives
;
14249 function Is_Type_Ref
(N
: Node_Id
) return Boolean is
14251 return (Nkind
(N
) = N_Identifier
14252 and then Chars
(N
) = Nam
14253 and then Paren_Count
(N
) = 0);
14256 -- helper function for recursive calls
14257 function Is_Predicate_Static_Aux
(Expr
: Node_Id
) return Boolean is
14258 (Is_Predicate_Static
(Expr
, Nam
, Warn
=> False));
14260 -- Start of processing for Is_Predicate_Static
14263 -- Handle cases like
14264 -- subtype S is Integer with Static_Predicate =>
14265 -- (Some_Integer_Variable in Integer) and then (S /= 0);
14266 -- where the predicate (which should be rejected) might have been
14267 -- transformed into just "(S /= 0)", which would appear to be
14268 -- a predicate-static expression (and therefore legal).
14270 if Original_Node
(Expr
) /= Expr
then
14272 -- Emit warnings for predicates that are always True or always False
14273 -- and were not originally expressed as Boolean literals.
14275 return Result
: constant Boolean :=
14276 Is_Predicate_Static_Aux
(Original_Node
(Expr
))
14278 if Result
and then Warn
and then Is_Entity_Name
(Expr
) then
14279 if Entity
(Expr
) = Standard_True
then
14280 Error_Msg_N
("predicate is redundant (always True)?", Expr
);
14281 elsif Entity
(Expr
) = Standard_False
then
14283 ("predicate is unsatisfiable (always False)?", Expr
);
14289 -- Predicate_Static means one of the following holds. Numbers are the
14290 -- corresponding paragraph numbers in (RM 3.2.4(16-22)).
14292 -- 16: A static expression
14294 if Is_OK_Static_Expression
(Expr
) then
14297 -- 17: A membership test whose simple_expression is the current
14298 -- instance, and whose membership_choice_list meets the requirements
14299 -- for a static membership test.
14301 elsif Nkind
(Expr
) in N_Membership_Test
14302 and then Is_Type_Ref
(Left_Opnd
(Expr
))
14303 and then All_Membership_Choices_Static
(Expr
)
14307 -- 18. A case_expression whose selecting_expression is the current
14308 -- instance, and whose dependent expressions are static expressions.
14310 elsif Nkind
(Expr
) = N_Case_Expression
14311 and then Is_Type_Ref
(Expression
(Expr
))
14312 and then All_Static_Case_Alternatives
(Alternatives
(Expr
))
14316 -- 19. A call to a predefined equality or ordering operator, where one
14317 -- operand is the current instance, and the other is a static
14320 -- Note: the RM is clearly wrong here in not excluding string types.
14321 -- Without this exclusion, we would allow expressions like X > "ABC"
14322 -- to be considered as predicate-static, which is clearly not intended,
14323 -- since the idea is for predicate-static to be a subset of normal
14324 -- static expressions (and "DEF" > "ABC" is not a static expression).
14326 -- However, we do allow internally generated (not from source) equality
14327 -- and inequality operations to be valid on strings (this helps deal
14328 -- with cases where we transform A in "ABC" to A = "ABC).
14330 -- In fact, it appears that the intent of the ARG is to extend static
14331 -- predicates to strings, and that the extension should probably apply
14332 -- to static expressions themselves. The code below accepts comparison
14333 -- operators that apply to static strings.
14335 elsif Nkind
(Expr
) in N_Op_Compare
14336 and then ((Is_Type_Ref
(Left_Opnd
(Expr
))
14337 and then Is_OK_Static_Expression
(Right_Opnd
(Expr
)))
14339 (Is_Type_Ref
(Right_Opnd
(Expr
))
14340 and then Is_OK_Static_Expression
(Left_Opnd
(Expr
))))
14344 -- 20. A call to a predefined boolean logical operator, where each
14345 -- operand is predicate-static.
14347 elsif (Nkind
(Expr
) in N_Op_And | N_Op_Or | N_Op_Xor
14348 and then Is_Predicate_Static_Aux
(Left_Opnd
(Expr
))
14349 and then Is_Predicate_Static_Aux
(Right_Opnd
(Expr
)))
14351 (Nkind
(Expr
) = N_Op_Not
14352 and then Is_Predicate_Static_Aux
(Right_Opnd
(Expr
)))
14356 -- 21. A short-circuit control form where both operands are
14357 -- predicate-static.
14359 elsif Nkind
(Expr
) in N_Short_Circuit
14360 and then Is_Predicate_Static_Aux
(Left_Opnd
(Expr
))
14361 and then Is_Predicate_Static_Aux
(Right_Opnd
(Expr
))
14365 -- 22. A parenthesized predicate-static expression. This does not
14366 -- require any special test, since we just ignore paren levels in
14367 -- all the cases above.
14369 -- One more test that is an implementation artifact caused by the fact
14370 -- that we are analyzing not the original expression, but the generated
14371 -- expression in the body of the predicate function. This can include
14372 -- references to inherited predicates, so that the expression we are
14373 -- processing looks like:
14375 -- xxPredicate (typ (Inns)) and then expression
14377 -- Where the call is to a Predicate function for an inherited predicate.
14378 -- We simply ignore such a call, which could be to either a dynamic or
14379 -- a static predicate. Note that if the parent predicate is dynamic then
14380 -- eventually this type will be marked as dynamic, but you are allowed
14381 -- to specify a static predicate for a subtype which is inheriting a
14382 -- dynamic predicate, so the static predicate validation here ignores
14383 -- the inherited predicate even if it is dynamic.
14384 -- In all cases, a static predicate can only apply to a scalar type.
14386 elsif Nkind
(Expr
) = N_Function_Call
14387 and then Is_Predicate_Function
(Entity
(Name
(Expr
)))
14388 and then Is_Scalar_Type
(Etype
(First_Entity
(Entity
(Name
(Expr
)))))
14392 -- That's an exhaustive list of tests, all other cases are not
14393 -- predicate-static, so we return False.
14398 end Is_Predicate_Static
;
14400 ----------------------
14401 -- Is_Static_Choice --
14402 ----------------------
14404 function Is_Static_Choice
(N
: Node_Id
) return Boolean is
14406 return Nkind
(N
) = N_Others_Choice
14407 or else Is_OK_Static_Expression
(N
)
14408 or else (Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
))
14409 and then Is_OK_Static_Subtype
(Entity
(N
)))
14410 or else (Nkind
(N
) = N_Subtype_Indication
14411 and then Is_OK_Static_Subtype
(Entity
(N
)))
14412 or else (Nkind
(N
) = N_Range
and then Is_OK_Static_Range
(N
));
14413 end Is_Static_Choice
;
14415 ------------------------------
14416 -- Is_Type_Related_Rep_Item --
14417 ------------------------------
14419 function Is_Type_Related_Rep_Item
(N
: Node_Id
) return Boolean is
14422 when N_Attribute_Definition_Clause
=>
14423 -- See AARM 13.1(8.f-8.x) list items that end in "clause"
14424 -- ???: include any GNAT-defined attributes here?
14425 return Get_Attribute_Id
(Chars
(N
)) in Attribute_Bit_Order
14426 | Attribute_Component_Size
14427 | Attribute_Machine_Radix
14428 | Attribute_Storage_Pool
14429 | Attribute_Stream_Size
;
14432 case Get_Pragma_Id
(N
) is
14433 -- See AARM 13.1(8.f-8.x) list items that start with "pragma"
14434 -- ???: include any GNAT-defined pragmas here?
14438 | Pragma_Convention
14440 | Pragma_Independent
14442 | Pragma_Atomic_Components
14443 | Pragma_Independent_Components
14444 | Pragma_Volatile_Components
14445 | Pragma_Discard_Names
14452 when N_Enumeration_Representation_Clause
14453 | N_Record_Representation_Clause
14462 end Is_Type_Related_Rep_Item
;
14464 ---------------------
14465 -- Kill_Rep_Clause --
14466 ---------------------
14468 procedure Kill_Rep_Clause
(N
: Node_Id
) is
14470 pragma Assert
(Ignore_Rep_Clauses
);
14472 -- Note: we use Replace rather than Rewrite, because we don't want
14473 -- tools to be able to use Original_Node to dig out the (undecorated)
14474 -- rep clause that is being replaced.
14476 Replace
(N
, Make_Null_Statement
(Sloc
(N
)));
14478 -- The null statement must be marked as not coming from source. This is
14479 -- so that tools ignore it, and also the back end does not expect bogus
14480 -- "from source" null statements in weird places (e.g. in declarative
14481 -- regions where such null statements are not allowed).
14483 Set_Comes_From_Source
(N
, False);
14484 end Kill_Rep_Clause
;
14490 function Minimum_Size
14492 Biased
: Boolean := False) return Int
14494 Lo
: Uint
:= No_Uint
;
14495 Hi
: Uint
:= No_Uint
;
14496 LoR
: Ureal
:= No_Ureal
;
14497 HiR
: Ureal
:= No_Ureal
;
14498 LoSet
: Boolean := False;
14499 HiSet
: Boolean := False;
14502 Ancest
: Entity_Id
;
14503 R_Typ
: constant Entity_Id
:= Root_Type
(T
);
14508 if T
= Any_Type
then
14509 return Unknown_Minimum_Size
;
14511 -- For generic types, just return unknown. There cannot be any
14512 -- legitimate need to know such a size, but this routine may be
14513 -- called with a generic type as part of normal processing.
14515 elsif Is_Generic_Type
(R_Typ
) or else R_Typ
= Any_Type
then
14516 return Unknown_Minimum_Size
;
14518 -- Access types (cannot have size smaller than System.Address)
14520 elsif Is_Access_Type
(T
) then
14521 return System_Address_Size
;
14523 -- Floating-point types
14525 elsif Is_Floating_Point_Type
(T
) then
14526 return UI_To_Int
(Esize
(R_Typ
));
14530 elsif Is_Discrete_Type
(T
) then
14532 -- The following loop is looking for the nearest compile time known
14533 -- bounds following the ancestor subtype chain. The idea is to find
14534 -- the most restrictive known bounds information.
14538 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
14539 return Unknown_Minimum_Size
;
14543 if Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
)) then
14544 Lo
:= Expr_Rep_Value
(Type_Low_Bound
(Ancest
));
14551 if Compile_Time_Known_Value
(Type_High_Bound
(Ancest
)) then
14552 Hi
:= Expr_Rep_Value
(Type_High_Bound
(Ancest
));
14558 Ancest
:= Ancestor_Subtype
(Ancest
);
14560 if No
(Ancest
) then
14561 Ancest
:= Base_Type
(T
);
14563 if Is_Generic_Type
(Ancest
) then
14564 return Unknown_Minimum_Size
;
14569 -- Fixed-point types. We can't simply use Expr_Value to get the
14570 -- Corresponding_Integer_Value values of the bounds, since these do not
14571 -- get set till the type is frozen, and this routine can be called
14572 -- before the type is frozen. Similarly the test for bounds being static
14573 -- needs to include the case where we have unanalyzed real literals for
14574 -- the same reason.
14576 elsif Is_Fixed_Point_Type
(T
) then
14578 -- The following loop is looking for the nearest compile time known
14579 -- bounds following the ancestor subtype chain. The idea is to find
14580 -- the most restrictive known bounds information.
14584 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
14585 return Unknown_Minimum_Size
;
14588 -- Note: In the following two tests for LoSet and HiSet, it may
14589 -- seem redundant to test for N_Real_Literal here since normally
14590 -- one would assume that the test for the value being known at
14591 -- compile time includes this case. However, there is a glitch.
14592 -- If the real literal comes from folding a non-static expression,
14593 -- then we don't consider any non- static expression to be known
14594 -- at compile time if we are in configurable run time mode (needed
14595 -- in some cases to give a clearer definition of what is and what
14596 -- is not accepted). So the test is indeed needed. Without it, we
14597 -- would set neither Lo_Set nor Hi_Set and get an infinite loop.
14600 if Nkind
(Type_Low_Bound
(Ancest
)) = N_Real_Literal
14601 or else Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
))
14603 LoR
:= Expr_Value_R
(Type_Low_Bound
(Ancest
));
14610 if Nkind
(Type_High_Bound
(Ancest
)) = N_Real_Literal
14611 or else Compile_Time_Known_Value
(Type_High_Bound
(Ancest
))
14613 HiR
:= Expr_Value_R
(Type_High_Bound
(Ancest
));
14619 Ancest
:= Ancestor_Subtype
(Ancest
);
14621 if No
(Ancest
) then
14622 Ancest
:= Base_Type
(T
);
14624 if Is_Generic_Type
(Ancest
) then
14625 return Unknown_Minimum_Size
;
14630 Lo
:= UR_To_Uint
(LoR
/ Small_Value
(T
));
14631 Hi
:= UR_To_Uint
(HiR
/ Small_Value
(T
));
14633 -- No other types allowed
14636 raise Program_Error
;
14639 -- Fall through with Hi and Lo set. Deal with biased case
14642 and then not Is_Fixed_Point_Type
(T
)
14643 and then not (Is_Enumeration_Type
(T
)
14644 and then Has_Non_Standard_Rep
(T
)))
14645 or else Has_Biased_Representation
(T
)
14651 -- Null range case, size is always zero. We only do this in the discrete
14652 -- type case, since that's the odd case that came up. Probably we should
14653 -- also do this in the fixed-point case, but doing so causes peculiar
14654 -- gigi failures, and it is not worth worrying about this incredibly
14655 -- marginal case (explicit null-range fixed-point type declarations).
14657 if Lo
> Hi
and then Is_Discrete_Type
(T
) then
14660 -- Signed case. Note that we consider types like range 1 .. -1 to be
14661 -- signed for the purpose of computing the size, since the bounds have
14662 -- to be accommodated in the base type.
14664 elsif Lo
< 0 or else Hi
< 0 then
14668 -- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1))
14669 -- Note that we accommodate the case where the bounds cross. This
14670 -- can happen either because of the way the bounds are declared
14671 -- or because of the algorithm in Freeze_Fixed_Point_Type.
14685 -- If both bounds are positive, make sure that both are represen-
14686 -- table in the case where the bounds are crossed. This can happen
14687 -- either because of the way the bounds are declared, or because of
14688 -- the algorithm in Freeze_Fixed_Point_Type.
14694 -- S = size, (can accommodate 0 .. (2**size - 1))
14697 while Hi
>= Uint_2
** S
loop
14705 ------------------------------
14706 -- New_Put_Image_Subprogram --
14707 ------------------------------
14709 procedure New_Put_Image_Subprogram
14714 Loc
: constant Source_Ptr
:= Sloc
(N
);
14715 Sname
: constant Name_Id
:=
14716 Make_TSS_Name
(Base_Type
(Ent
), TSS_Put_Image
);
14717 Subp_Id
: Entity_Id
;
14718 Subp_Decl
: Node_Id
;
14722 Defer_Declaration
: constant Boolean :=
14723 Is_Tagged_Type
(Ent
) or else Is_Private_Type
(Ent
);
14724 -- For a tagged type, there is a declaration at the freeze point, and
14725 -- we must generate only a completion of this declaration. We do the
14726 -- same for private types, because the full view might be tagged.
14727 -- Otherwise we generate a declaration at the point of the attribute
14728 -- definition clause. If the attribute definition comes from an aspect
14729 -- specification the declaration is part of the freeze actions of the
14732 function Build_Spec
return Node_Id
;
14733 -- Used for declaration and renaming declaration, so that this is
14734 -- treated as a renaming_as_body.
14740 function Build_Spec
return Node_Id
is
14743 T_Ref
: constant Node_Id
:= New_Occurrence_Of
(Etyp
, Loc
);
14746 Subp_Id
:= Make_Defining_Identifier
(Loc
, Sname
);
14748 -- S : Root_Buffer_Type'Class
14750 Formals
:= New_List
(
14751 Make_Parameter_Specification
(Loc
,
14752 Defining_Identifier
=>
14753 Make_Defining_Identifier
(Loc
, Name_S
),
14754 In_Present
=> True,
14755 Out_Present
=> True,
14757 New_Occurrence_Of
(Etype
(F
), Loc
)));
14761 Append_To
(Formals
,
14762 Make_Parameter_Specification
(Loc
,
14763 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_V
),
14764 Parameter_Type
=> T_Ref
));
14767 Make_Procedure_Specification
(Loc
,
14768 Defining_Unit_Name
=> Subp_Id
,
14769 Parameter_Specifications
=> Formals
);
14774 -- Start of processing for New_Put_Image_Subprogram
14777 F
:= First_Formal
(Subp
);
14779 Etyp
:= Etype
(Next_Formal
(F
));
14781 -- Prepare subprogram declaration and insert it as an action on the
14782 -- clause node. The visibility for this entity is used to test for
14783 -- visibility of the attribute definition clause (in the sense of
14784 -- 8.3(23) as amended by AI-195).
14786 if not Defer_Declaration
then
14788 Make_Subprogram_Declaration
(Loc
,
14789 Specification
=> Build_Spec
);
14791 -- For a tagged type, there is always a visible declaration for the
14792 -- Put_Image TSS (it is a predefined primitive operation), and the
14793 -- completion of this declaration occurs at the freeze point, which is
14794 -- not always visible at places where the attribute definition clause is
14795 -- visible. So, we create a dummy entity here for the purpose of
14796 -- tracking the visibility of the attribute definition clause itself.
14800 Make_Defining_Identifier
(Loc
, New_External_Name
(Sname
, 'V'));
14802 Make_Object_Declaration
(Loc
,
14803 Defining_Identifier
=> Subp_Id
,
14804 Object_Definition
=> New_Occurrence_Of
(Standard_Boolean
, Loc
));
14807 if not Defer_Declaration
14808 and then From_Aspect_Specification
(N
)
14809 and then Has_Delayed_Freeze
(Ent
)
14811 Append_Freeze_Action
(Ent
, Subp_Decl
);
14814 Insert_Action
(N
, Subp_Decl
);
14815 Set_Entity
(N
, Subp_Id
);
14819 Make_Subprogram_Renaming_Declaration
(Loc
,
14820 Specification
=> Build_Spec
,
14821 Name
=> New_Occurrence_Of
(Subp
, Loc
));
14823 if Defer_Declaration
then
14824 Set_TSS
(Base_Type
(Ent
), Subp_Id
);
14827 if From_Aspect_Specification
(N
) then
14828 Append_Freeze_Action
(Ent
, Subp_Decl
);
14830 Insert_Action
(N
, Subp_Decl
);
14833 Copy_TSS
(Subp_Id
, Base_Type
(Ent
));
14835 end New_Put_Image_Subprogram
;
14837 ---------------------------
14838 -- New_Stream_Subprogram --
14839 ---------------------------
14841 procedure New_Stream_Subprogram
14845 Nam
: TSS_Name_Type
)
14847 Loc
: constant Source_Ptr
:= Sloc
(N
);
14848 Sname
: constant Name_Id
:= Make_TSS_Name
(Base_Type
(Ent
), Nam
);
14849 Subp_Id
: Entity_Id
;
14850 Subp_Decl
: Node_Id
;
14854 Defer_Declaration
: constant Boolean :=
14855 Is_Tagged_Type
(Ent
) or else Is_Private_Type
(Ent
);
14856 -- For a tagged type, there is a declaration for each stream attribute
14857 -- at the freeze point, and we must generate only a completion of this
14858 -- declaration. We do the same for private types, because the full view
14859 -- might be tagged. Otherwise we generate a declaration at the point of
14860 -- the attribute definition clause. If the attribute definition comes
14861 -- from an aspect specification the declaration is part of the freeze
14862 -- actions of the type.
14864 function Build_Spec
return Node_Id
;
14865 -- Used for declaration and renaming declaration, so that this is
14866 -- treated as a renaming_as_body.
14872 function Build_Spec
return Node_Id
is
14873 Out_P
: constant Boolean := (Nam
= TSS_Stream_Read
);
14876 T_Ref
: constant Node_Id
:= New_Occurrence_Of
(Etyp
, Loc
);
14879 Subp_Id
:= Make_Defining_Identifier
(Loc
, Sname
);
14881 -- S : access Root_Stream_Type'Class
14883 Formals
:= New_List
(
14884 Make_Parameter_Specification
(Loc
,
14885 Defining_Identifier
=>
14886 Make_Defining_Identifier
(Loc
, Name_S
),
14888 Make_Access_Definition
(Loc
,
14890 New_Occurrence_Of
(
14891 Designated_Type
(Etype
(F
)), Loc
))));
14893 if Nam
= TSS_Stream_Input
then
14895 Make_Function_Specification
(Loc
,
14896 Defining_Unit_Name
=> Subp_Id
,
14897 Parameter_Specifications
=> Formals
,
14898 Result_Definition
=> T_Ref
);
14902 Append_To
(Formals
,
14903 Make_Parameter_Specification
(Loc
,
14904 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_V
),
14905 Out_Present
=> Out_P
,
14906 Parameter_Type
=> T_Ref
));
14909 Make_Procedure_Specification
(Loc
,
14910 Defining_Unit_Name
=> Subp_Id
,
14911 Parameter_Specifications
=> Formals
);
14917 -- Start of processing for New_Stream_Subprogram
14920 F
:= First_Formal
(Subp
);
14922 if Ekind
(Subp
) = E_Procedure
then
14923 Etyp
:= Etype
(Next_Formal
(F
));
14925 Etyp
:= Etype
(Subp
);
14928 -- Prepare subprogram declaration and insert it as an action on the
14929 -- clause node. The visibility for this entity is used to test for
14930 -- visibility of the attribute definition clause (in the sense of
14931 -- 8.3(23) as amended by AI-195).
14933 if not Defer_Declaration
then
14935 Make_Subprogram_Declaration
(Loc
,
14936 Specification
=> Build_Spec
);
14938 -- For a tagged type, there is always a visible declaration for each
14939 -- stream TSS (it is a predefined primitive operation), and the
14940 -- completion of this declaration occurs at the freeze point, which is
14941 -- not always visible at places where the attribute definition clause is
14942 -- visible. So, we create a dummy entity here for the purpose of
14943 -- tracking the visibility of the attribute definition clause itself.
14947 Make_Defining_Identifier
(Loc
, New_External_Name
(Sname
, 'V'));
14949 Make_Object_Declaration
(Loc
,
14950 Defining_Identifier
=> Subp_Id
,
14951 Object_Definition
=> New_Occurrence_Of
(Standard_Boolean
, Loc
));
14954 if not Defer_Declaration
14955 and then From_Aspect_Specification
(N
)
14956 and then Has_Delayed_Freeze
(Ent
)
14958 Append_Freeze_Action
(Ent
, Subp_Decl
);
14961 Insert_Action
(N
, Subp_Decl
);
14962 Set_Entity
(N
, Subp_Id
);
14966 Make_Subprogram_Renaming_Declaration
(Loc
,
14967 Specification
=> Build_Spec
,
14968 Name
=> New_Occurrence_Of
(Subp
, Loc
));
14970 if Defer_Declaration
then
14971 Set_TSS
(Base_Type
(Ent
), Subp_Id
);
14974 if From_Aspect_Specification
(N
) then
14975 Append_Freeze_Action
(Ent
, Subp_Decl
);
14977 Insert_Action
(N
, Subp_Decl
);
14980 Copy_TSS
(Subp_Id
, Base_Type
(Ent
));
14982 end New_Stream_Subprogram
;
14984 ----------------------
14985 -- No_Type_Rep_Item --
14986 ----------------------
14988 procedure No_Type_Rep_Item
(N
: Node_Id
) is
14990 Error_Msg_N
("|type-related representation item not permitted!", N
);
14991 end No_Type_Rep_Item
;
14997 procedure Pop_Type
(E
: Entity_Id
) is
14999 if Ekind
(E
) = E_Record_Type
and then E
= Current_Scope
then
15003 and then Has_Discriminants
(E
)
15004 and then Nkind
(Parent
(E
)) /= N_Subtype_Declaration
15006 Uninstall_Discriminants
(E
);
15015 procedure Push_Type
(E
: Entity_Id
) is
15019 if Ekind
(E
) = E_Record_Type
then
15022 Comp
:= First_Component
(E
);
15023 while Present
(Comp
) loop
15024 Install_Entity
(Comp
);
15025 Next_Component
(Comp
);
15028 if Has_Discriminants
(E
) then
15029 Install_Discriminants
(E
);
15033 and then Has_Discriminants
(E
)
15034 and then Nkind
(Parent
(E
)) /= N_Subtype_Declaration
15037 Install_Discriminants
(E
);
15041 -----------------------------------
15042 -- Register_Address_Clause_Check --
15043 -----------------------------------
15045 procedure Register_Address_Clause_Check
15052 ACS
: constant Boolean := Scope_Suppress
.Suppress
(Alignment_Check
);
15054 Address_Clause_Checks
.Append
((N
, X
, A
, Y
, Off
, ACS
));
15055 end Register_Address_Clause_Check
;
15057 ------------------------
15058 -- Rep_Item_Too_Early --
15059 ------------------------
15061 function Rep_Item_Too_Early
(T
: Entity_Id
; N
: Node_Id
) return Boolean is
15062 function Has_Generic_Parent
(E
: Entity_Id
) return Boolean;
15063 -- Return True if R or any ancestor is a generic type
15065 ------------------------
15066 -- Has_Generic_Parent --
15067 ------------------------
15069 function Has_Generic_Parent
(E
: Entity_Id
) return Boolean is
15070 Ancestor_Type
: Entity_Id
:= Etype
(E
);
15073 if Is_Generic_Type
(E
) then
15077 while Present
(Ancestor_Type
)
15078 and then not Is_Generic_Type
(Ancestor_Type
)
15079 and then Etype
(Ancestor_Type
) /= Ancestor_Type
15081 Ancestor_Type
:= Etype
(Ancestor_Type
);
15085 Present
(Ancestor_Type
) and then Is_Generic_Type
(Ancestor_Type
);
15086 end Has_Generic_Parent
;
15088 -- Start of processing for Rep_Item_Too_Early
15091 -- Cannot apply non-operational rep items to generic types
15093 if Is_Operational_Item
(N
) then
15097 and then Has_Generic_Parent
(T
)
15098 and then (Nkind
(N
) /= N_Pragma
15099 or else Get_Pragma_Id
(N
) /= Pragma_Convention
)
15101 if Ada_Version
< Ada_2022
then
15103 ("representation item not allowed for generic type", N
);
15110 -- Otherwise check for incomplete type
15112 if Is_Incomplete_Or_Private_Type
(T
)
15113 and then No
(Underlying_Type
(T
))
15115 (Nkind
(N
) /= N_Pragma
15116 or else Get_Pragma_Id
(N
) /= Pragma_Import
)
15119 ("representation item must be after full type declaration", N
);
15122 -- If the type has incomplete components, a representation clause is
15123 -- illegal but stream attributes and Convention pragmas are correct.
15125 elsif Has_Private_Component
(T
) then
15126 if Nkind
(N
) = N_Pragma
then
15131 ("representation item must appear after type is fully defined",
15138 end Rep_Item_Too_Early
;
15140 -----------------------
15141 -- Rep_Item_Too_Late --
15142 -----------------------
15144 function Rep_Item_Too_Late
15147 FOnly
: Boolean := False) return Boolean
15149 procedure Too_Late
;
15150 -- Output message for an aspect being specified too late
15152 -- Note that neither of the above errors is considered a serious one,
15153 -- since the effect is simply that we ignore the representation clause
15155 -- Is this really true? In any case if we make this change we must
15156 -- document the requirement in the spec of Rep_Item_Too_Late that
15157 -- if True is returned, then the rep item must be completely ignored???
15163 procedure Too_Late
is
15165 -- Other compilers seem more relaxed about rep items appearing too
15166 -- late. Since analysis tools typically don't care about rep items
15167 -- anyway, no reason to be too strict about this.
15169 if not Relaxed_RM_Semantics
then
15170 Error_Msg_N
("|representation item appears too late!", N
);
15176 Parent_Type
: Entity_Id
;
15179 -- Start of processing for Rep_Item_Too_Late
15182 -- First make sure entity is not frozen (RM 13.1(9))
15186 -- Exclude imported types, which may be frozen if they appear in a
15187 -- representation clause for a local type.
15189 and then not From_Limited_With
(T
)
15191 -- Exclude generated entities (not coming from source). The common
15192 -- case is when we generate a renaming which prematurely freezes the
15193 -- renamed internal entity, but we still want to be able to set copies
15194 -- of attribute values such as Size/Alignment.
15196 and then Comes_From_Source
(T
)
15198 -- A self-referential aspect is illegal if it forces freezing the
15199 -- entity before the corresponding pragma has been analyzed.
15201 if Nkind
(N
) in N_Attribute_Definition_Clause | N_Pragma
15202 and then From_Aspect_Specification
(N
)
15205 ("aspect specification causes premature freezing of&", N
, T
);
15206 Set_Has_Delayed_Freeze
(T
, False);
15211 S
:= First_Subtype
(T
);
15213 if Present
(Freeze_Node
(S
)) then
15214 if not Relaxed_RM_Semantics
then
15216 ("??no more representation items for }", Freeze_Node
(S
), S
);
15222 -- Check for case of untagged derived type whose parent either has
15223 -- primitive operations (pre Ada 2022), or is a by-reference type (RM
15224 -- 13.1(10)). In this case we do not output a Too_Late message, since
15225 -- there is no earlier point where the rep item could be placed to make
15227 -- ??? Confirming representation clauses should be allowed here.
15231 and then Is_Derived_Type
(T
)
15232 and then not Is_Tagged_Type
(T
)
15234 Parent_Type
:= Etype
(Base_Type
(T
));
15236 if Relaxed_RM_Semantics
then
15239 elsif Ada_Version
<= Ada_2012
15240 and then Has_Primitive_Operations
(Parent_Type
)
15243 ("|representation item not permitted before Ada 2022!", N
);
15245 ("\parent type & has primitive operations!", N
, Parent_Type
);
15248 elsif Is_By_Reference_Type
(Parent_Type
) then
15249 No_Type_Rep_Item
(N
);
15251 ("\parent type & is a by-reference type!", N
, Parent_Type
);
15256 -- No error, but one more warning to consider. The RM (surprisingly)
15257 -- allows this pattern in some cases:
15260 -- primitive operations for S
15261 -- type R is new S;
15262 -- rep clause for S
15264 -- Meaning that calls on the primitive operations of S for values of
15265 -- type R may require possibly expensive implicit conversion operations.
15266 -- So even when this is not an error, it is still worth a warning.
15268 if not Relaxed_RM_Semantics
and then Is_Type
(T
) then
15270 DTL
: constant Entity_Id
:= Derived_Type_Link
(Base_Type
(T
));
15275 -- For now, do not generate this warning for the case of
15276 -- aspect specification using Ada 2012 syntax, since we get
15277 -- wrong messages we do not understand. The whole business
15278 -- of derived types and rep items seems a bit confused when
15279 -- aspects are used, since the aspects are not evaluated
15280 -- till freeze time. However, AI12-0109 confirms (in an AARM
15281 -- ramification) that inheritance in this case is required
15284 and then not From_Aspect_Specification
(N
)
15286 if Is_By_Reference_Type
(T
)
15287 and then not Is_Tagged_Type
(T
)
15288 and then Is_Type_Related_Rep_Item
(N
)
15289 and then (Ada_Version
>= Ada_2012
15290 or else Has_Primitive_Operations
(Base_Type
(T
)))
15292 -- Treat as hard error (AI12-0109, binding interpretation).
15293 -- Implementing a change of representation is not really
15294 -- an option in the case of a by-reference type, so we
15295 -- take this path for all Ada dialects if primitive
15296 -- operations are present.
15297 Error_Msg_Sloc
:= Sloc
(DTL
);
15299 ("representation item for& appears after derived type "
15300 & "declaration#", N
);
15302 elsif Has_Primitive_Operations
(Base_Type
(T
)) then
15303 Error_Msg_Sloc
:= Sloc
(DTL
);
15306 ("representation item for& appears after derived type "
15307 & "declaration#??", N
);
15309 ("\may result in implicit conversions for primitive "
15310 & "operations of&??", N
, T
);
15312 ("\to change representations when called with arguments "
15313 & "of type&??", N
, DTL
);
15319 -- No error, link item into head of chain of rep items for the entity,
15320 -- but avoid chaining if we have an overloadable entity, and the pragma
15321 -- is one that can apply to multiple overloaded entities.
15323 if Is_Overloadable
(T
) and then Nkind
(N
) = N_Pragma
then
15325 Pname
: constant Name_Id
:= Pragma_Name
(N
);
15327 if Pname
in Name_Convention | Name_Import | Name_Export
15328 | Name_External | Name_Interface
15335 Record_Rep_Item
(T
, N
);
15337 end Rep_Item_Too_Late
;
15339 -------------------------------------
15340 -- Replace_Type_References_Generic --
15341 -------------------------------------
15343 procedure Replace_Type_References_Generic
(N
: Node_Id
; T
: Entity_Id
) is
15344 TName
: constant Name_Id
:= Chars
(T
);
15346 function Replace_Type_Ref
(N
: Node_Id
) return Traverse_Result
;
15347 -- Processes a single node in the traversal procedure below, checking
15348 -- if node N should be replaced, and if so, doing the replacement.
15350 function Visible_Component
(Comp
: Name_Id
) return Entity_Id
;
15351 -- Given an identifier in the expression, check whether there is a
15352 -- discriminant, component, protected procedure, or entry of the type
15353 -- that is directy visible, and rewrite it as the corresponding selected
15354 -- component of the formal of the subprogram.
15356 ----------------------
15357 -- Replace_Type_Ref --
15358 ----------------------
15360 function Replace_Type_Ref
(N
: Node_Id
) return Traverse_Result
is
15361 Loc
: constant Source_Ptr
:= Sloc
(N
);
15363 procedure Add_Prefix
(Ref
: Node_Id
; Comp
: Entity_Id
);
15364 -- Add the proper prefix to a reference to a component of the type
15365 -- when it is not already a selected component.
15371 procedure Add_Prefix
(Ref
: Node_Id
; Comp
: Entity_Id
) is
15374 Make_Selected_Component
(Loc
,
15375 Prefix
=> New_Occurrence_Of
(T
, Loc
),
15376 Selector_Name
=> New_Occurrence_Of
(Comp
, Loc
)));
15377 Replace_Type_Reference
(Prefix
(Ref
));
15386 -- Start of processing for Replace_Type_Ref
15389 if Nkind
(N
) = N_Identifier
then
15391 -- If not the type name, check whether it is a reference to some
15392 -- other type, which must be frozen before the predicate function
15393 -- is analyzed, i.e. before the freeze node of the type to which
15394 -- the predicate applies.
15396 if Chars
(N
) /= TName
then
15397 if Present
(Current_Entity
(N
))
15398 and then Is_Type
(Current_Entity
(N
))
15400 Freeze_Before
(Freeze_Node
(T
), Current_Entity
(N
));
15403 -- The components of the type are directly visible and can
15404 -- be referenced in the source code without a prefix.
15405 -- If a name denoting a component doesn't already have a
15406 -- prefix, then normalize it by adding a reference to the
15407 -- current instance of the type as a prefix.
15409 -- This isn't right in the pathological corner case of an
15410 -- object-declaring expression (e.g., a quantified expression
15411 -- or a declare expression) that declares an object with the
15412 -- same name as a visible component declaration, thereby hiding
15413 -- the component within that expression. For example, given a
15414 -- record with a Boolean component "C" and a dynamic predicate
15415 -- "C = (for some C in Character => Some_Function (C))", only
15416 -- the first of the two uses of C should have a prefix added
15417 -- here; instead, both will get prefixes.
15419 if Nkind
(Parent
(N
)) /= N_Selected_Component
15420 or else N
/= Selector_Name
(Parent
(N
))
15422 Comp
:= Visible_Component
(Chars
(N
));
15424 if Present
(Comp
) then
15425 Add_Prefix
(N
, Comp
);
15431 -- Otherwise do the replacement if this is not a qualified
15432 -- reference to a homograph of the type itself. Note that the
15433 -- current instance could not appear in such a context, e.g.
15434 -- the prefix of a type conversion.
15437 if Nkind
(Parent
(N
)) /= N_Selected_Component
15438 or else N
/= Selector_Name
(Parent
(N
))
15440 Replace_Type_Reference
(N
);
15446 -- Case of selected component, which may be a subcomponent of the
15447 -- current instance, or an expanded name which is still unanalyzed.
15449 elsif Nkind
(N
) = N_Selected_Component
then
15451 -- If selector name is not our type, keep going (we might still
15452 -- have an occurrence of the type in the prefix). If it is a
15453 -- subcomponent of the current entity, add prefix.
15455 if Nkind
(Selector_Name
(N
)) /= N_Identifier
15456 or else Chars
(Selector_Name
(N
)) /= TName
15458 if Nkind
(Prefix
(N
)) = N_Identifier
then
15459 Comp
:= Visible_Component
(Chars
(Prefix
(N
)));
15461 if Present
(Comp
) then
15462 Add_Prefix
(Prefix
(N
), Comp
);
15468 -- Selector name is our type, check qualification
15471 -- Loop through scopes and prefixes, doing comparison
15473 Scop
:= Current_Scope
;
15474 Pref
:= Prefix
(N
);
15476 -- Continue if no more scopes or scope with no name
15478 if No
(Scop
) or else Nkind
(Scop
) not in N_Has_Chars
then
15482 -- Do replace if prefix is an identifier matching the scope
15483 -- that we are currently looking at.
15485 if Nkind
(Pref
) = N_Identifier
15486 and then Chars
(Pref
) = Chars
(Scop
)
15488 Replace_Type_Reference
(N
);
15492 -- Go check scope above us if prefix is itself of the form
15493 -- of a selected component, whose selector matches the scope
15494 -- we are currently looking at.
15496 if Nkind
(Pref
) = N_Selected_Component
15497 and then Nkind
(Selector_Name
(Pref
)) = N_Identifier
15498 and then Chars
(Selector_Name
(Pref
)) = Chars
(Scop
)
15500 Scop
:= Scope
(Scop
);
15501 Pref
:= Prefix
(Pref
);
15503 -- For anything else, we don't have a match, so keep on
15504 -- going, there are still some weird cases where we may
15505 -- still have a replacement within the prefix.
15513 -- Continue for any other node kind
15518 end Replace_Type_Ref
;
15520 procedure Replace_Type_Refs
is new Traverse_Proc
(Replace_Type_Ref
);
15522 -----------------------
15523 -- Visible_Component --
15524 -----------------------
15526 function Visible_Component
(Comp
: Name_Id
) return Entity_Id
is
15529 -- Types with nameable components are record, task, and protected
15530 -- types, and discriminated private types.
15532 if Ekind
(T
) in E_Record_Type
15535 or else (Is_Private_Type
(T
) and then Has_Discriminants
(T
))
15537 -- This is a sequential search, which seems acceptable
15538 -- efficiency-wise, given the typical size of component
15539 -- lists, protected operation lists, task item lists, and
15540 -- check expressions.
15542 E
:= First_Entity
(T
);
15543 while Present
(E
) loop
15544 if Comes_From_Source
(E
) and then Chars
(E
) = Comp
then
15552 -- Nothing by that name
15555 end Visible_Component
;
15557 -- Start of processing for Replace_Type_References_Generic
15560 Replace_Type_Refs
(N
);
15561 end Replace_Type_References_Generic
;
15563 --------------------------------
15564 -- Resolve_Aspect_Expressions --
15565 --------------------------------
15567 procedure Resolve_Aspect_Expressions
(E
: Entity_Id
) is
15568 function Resolve_Name
(N
: Node_Id
) return Traverse_Result
;
15569 -- Verify that all identifiers in the expression, with the exception
15570 -- of references to the current entity, denote visible entities. This
15571 -- is done only to detect visibility errors, as the expression will be
15572 -- properly analyzed/expanded during analysis of the predicate function
15573 -- body. We omit quantified expressions from this test, given that they
15574 -- introduce a local identifier that would require proper expansion to
15575 -- handle properly.
15581 function Resolve_Name
(N
: Node_Id
) return Traverse_Result
is
15582 Dummy
: Traverse_Result
;
15585 if Nkind
(N
) = N_Selected_Component
then
15586 if Nkind
(Prefix
(N
)) = N_Identifier
15587 and then Chars
(Prefix
(N
)) /= Chars
(E
)
15589 Find_Selected_Component
(N
);
15594 -- Resolve identifiers that are not selectors in parameter
15595 -- associations (these are never resolved by visibility).
15597 elsif Nkind
(N
) = N_Identifier
15598 and then Chars
(N
) /= Chars
(E
)
15599 and then (Nkind
(Parent
(N
)) /= N_Parameter_Association
15600 or else N
/= Selector_Name
(Parent
(N
)))
15602 Find_Direct_Name
(N
);
15604 -- Reset the Entity if N is overloaded since the entity may not
15605 -- be the correct one.
15607 if Is_Overloaded
(N
) then
15608 Set_Entity
(N
, Empty
);
15611 -- The name in a component association needs no resolution
15613 elsif Nkind
(N
) = N_Component_Association
then
15614 Dummy
:= Resolve_Name
(Expression
(N
));
15617 elsif Nkind
(N
) = N_Quantified_Expression
then
15624 procedure Resolve_Aspect_Expression
is new Traverse_Proc
(Resolve_Name
);
15628 ASN
: Node_Id
:= First_Rep_Item
(E
);
15630 -- Start of processing for Resolve_Aspect_Expressions
15633 while Present
(ASN
) loop
15634 if Nkind
(ASN
) = N_Aspect_Specification
and then Entity
(ASN
) = E
then
15636 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(ASN
);
15637 Expr
: constant Node_Id
:= Expression
(ASN
);
15642 when Aspect_Aggregate
=>
15643 Resolve_Aspect_Aggregate
(Entity
(ASN
), Expr
);
15645 when Aspect_Stable_Properties
=>
15646 Resolve_Aspect_Stable_Properties
15647 (Entity
(ASN
), Expr
, Class_Present
(ASN
));
15649 -- For now we only deal with aspects that do not generate
15650 -- subprograms, or that may mention current instances of
15651 -- types. These will require special handling???.
15653 when Aspect_Invariant
15654 | Aspect_Predicate_Failure
15658 when Aspect_Dynamic_Predicate
15659 | Aspect_Static_Predicate
15662 -- Preanalyze expression after type replacement to catch
15663 -- name resolution errors if the predicate function has
15664 -- not been built yet.
15666 -- Note that we cannot use Preanalyze_Spec_Expression
15667 -- directly because of the special handling required for
15668 -- quantifiers (see comments on Resolve_Aspect_Expression
15669 -- above) but we need to emulate it properly.
15671 if No
(Predicate_Function
(E
)) then
15673 Save_In_Spec_Expression
: constant Boolean :=
15674 In_Spec_Expression
;
15675 Save_Full_Analysis
: constant Boolean :=
15678 In_Spec_Expression
:= True;
15679 Full_Analysis
:= False;
15680 Expander_Mode_Save_And_Set
(False);
15682 Resolve_Aspect_Expression
(Expr
);
15684 Expander_Mode_Restore
;
15685 Full_Analysis
:= Save_Full_Analysis
;
15686 In_Spec_Expression
:= Save_In_Spec_Expression
;
15690 when Pre_Post_Aspects
=>
15693 when Aspect_Iterable
=>
15694 if Nkind
(Expr
) = N_Aggregate
then
15699 Assoc
:= First
(Component_Associations
(Expr
));
15700 while Present
(Assoc
) loop
15701 if Nkind
(Expression
(Assoc
)) in N_Has_Entity
15703 Find_Direct_Name
(Expression
(Assoc
));
15711 -- The expression for Default_Value is a static expression
15712 -- of the type, but this expression does not freeze the
15713 -- type, so it can still appear in a representation clause
15714 -- before the actual freeze point.
15716 when Aspect_Default_Value
=>
15717 Set_Must_Not_Freeze
(Expr
);
15718 Preanalyze_Spec_Expression
(Expr
, E
);
15720 when Aspect_Priority
=>
15722 Preanalyze_Spec_Expression
(Expr
, Any_Integer
);
15725 -- Ditto for Storage_Size. Any other aspects that carry
15726 -- expressions that should not freeze ??? This is only
15727 -- relevant to the misuse of deferred constants.
15729 when Aspect_Storage_Size
=>
15730 Set_Must_Not_Freeze
(Expr
);
15731 Preanalyze_Spec_Expression
(Expr
, Any_Integer
);
15734 if Present
(Expr
) then
15735 case Aspect_Argument
(A_Id
) is
15737 | Optional_Expression
15739 Analyze_And_Resolve
(Expr
);
15744 if Nkind
(Expr
) = N_Identifier
then
15745 Find_Direct_Name
(Expr
);
15747 elsif Nkind
(Expr
) = N_Selected_Component
then
15748 Find_Selected_Component
(Expr
);
15756 Next_Rep_Item
(ASN
);
15758 end Resolve_Aspect_Expressions
;
15760 ----------------------------
15761 -- Parse_Aspect_Aggregate --
15762 ----------------------------
15764 procedure Parse_Aspect_Aggregate
15766 Empty_Subp
: in out Node_Id
;
15767 Add_Named_Subp
: in out Node_Id
;
15768 Add_Unnamed_Subp
: in out Node_Id
;
15769 New_Indexed_Subp
: in out Node_Id
;
15770 Assign_Indexed_Subp
: in out Node_Id
)
15772 Assoc
: Node_Id
:= First
(Component_Associations
(N
));
15777 while Present
(Assoc
) loop
15778 Subp
:= Expression
(Assoc
);
15779 Op_Name
:= Chars
(First
(Choices
(Assoc
)));
15780 if Op_Name
= Name_Empty
then
15781 Empty_Subp
:= Subp
;
15783 elsif Op_Name
= Name_Add_Named
then
15784 Add_Named_Subp
:= Subp
;
15786 elsif Op_Name
= Name_Add_Unnamed
then
15787 Add_Unnamed_Subp
:= Subp
;
15789 elsif Op_Name
= Name_New_Indexed
then
15790 New_Indexed_Subp
:= Subp
;
15792 elsif Op_Name
= Name_Assign_Indexed
then
15793 Assign_Indexed_Subp
:= Subp
;
15798 end Parse_Aspect_Aggregate
;
15800 ------------------------------------
15801 -- Parse_Aspect_Stable_Properties --
15802 ------------------------------------
15804 function Parse_Aspect_Stable_Properties
15805 (Aspect_Spec
: Node_Id
; Negated
: out Boolean) return Subprogram_List
15807 function Extract_Entity
(Expr
: Node_Id
) return Entity_Id
;
15808 -- Given an element of a Stable_Properties aspect spec, return the
15809 -- associated entity.
15810 -- This function updates the Negated flag as a side-effect.
15812 --------------------
15813 -- Extract_Entity --
15814 --------------------
15816 function Extract_Entity
(Expr
: Node_Id
) return Entity_Id
is
15819 if Nkind
(Expr
) = N_Op_Not
then
15821 Name
:= Right_Opnd
(Expr
);
15826 if Nkind
(Name
) in N_Has_Entity
then
15827 return Entity
(Name
);
15831 end Extract_Entity
;
15838 -- Start of processing for Parse_Aspect_Stable_Properties
15843 if Nkind
(Aspect_Spec
) /= N_Aggregate
then
15844 return (1 => Extract_Entity
(Aspect_Spec
));
15846 L
:= Expressions
(Aspect_Spec
);
15849 return Result
: Subprogram_List
(1 .. List_Length
(L
)) do
15850 for I
in Result
'Range loop
15851 Result
(I
) := Extract_Entity
(Id
);
15853 if No
(Result
(I
)) then
15854 pragma Assert
(Serious_Errors_Detected
> 0);
15855 goto Ignore_Aspect
;
15863 <<Ignore_Aspect
>> return (1 .. 0 => <>);
15864 end Parse_Aspect_Stable_Properties
;
15866 -------------------------------
15867 -- Validate_Aspect_Aggregate --
15868 -------------------------------
15870 procedure Validate_Aspect_Aggregate
(N
: Node_Id
) is
15871 Empty_Subp
: Node_Id
:= Empty
;
15872 Add_Named_Subp
: Node_Id
:= Empty
;
15873 Add_Unnamed_Subp
: Node_Id
:= Empty
;
15874 New_Indexed_Subp
: Node_Id
:= Empty
;
15875 Assign_Indexed_Subp
: Node_Id
:= Empty
;
15878 Error_Msg_Ada_2022_Feature
("aspect Aggregate", Sloc
(N
));
15880 if Nkind
(N
) /= N_Aggregate
15881 or else Present
(Expressions
(N
))
15882 or else No
(Component_Associations
(N
))
15884 Error_Msg_N
("aspect Aggregate requires an aggregate "
15885 & "with component associations", N
);
15889 Parse_Aspect_Aggregate
(N
,
15890 Empty_Subp
, Add_Named_Subp
, Add_Unnamed_Subp
,
15891 New_Indexed_Subp
, Assign_Indexed_Subp
);
15893 if No
(Empty_Subp
) then
15894 Error_Msg_N
("missing specification for Empty in aggregate", N
);
15897 if Present
(Add_Named_Subp
) then
15898 if Present
(Add_Unnamed_Subp
)
15899 or else Present
(Assign_Indexed_Subp
)
15902 ("conflicting operations for aggregate (RM 4.3.5)", N
);
15906 elsif No
(Add_Named_Subp
)
15907 and then No
(Add_Unnamed_Subp
)
15908 and then No
(Assign_Indexed_Subp
)
15910 Error_Msg_N
("incomplete specification for aggregate", N
);
15912 elsif Present
(New_Indexed_Subp
) /= Present
(Assign_Indexed_Subp
) then
15913 Error_Msg_N
("incomplete specification for indexed aggregate", N
);
15915 end Validate_Aspect_Aggregate
;
15917 -------------------------------
15918 -- Validate_Aspect_Stable_Properties --
15919 -------------------------------
15921 procedure Validate_Aspect_Stable_Properties
15922 (E
: Entity_Id
; N
: Node_Id
; Class_Present
: Boolean)
15924 Is_Aspect_Of_Type
: constant Boolean := Is_Type
(E
);
15926 type Permission
is (Forbidden
, Optional
, Required
);
15927 Modifier_Permission
: Permission
:=
15928 (if Is_Aspect_Of_Type
then Forbidden
else Optional
);
15929 Modifier_Error_Called
: Boolean := False;
15931 procedure Check_Property_Function_Arg
(PF_Arg
: Node_Id
);
15932 -- Check syntax of a property function argument
15934 ----------------------------------
15935 -- Check_Property_Function_Arg --
15936 ----------------------------------
15938 procedure Check_Property_Function_Arg
(PF_Arg
: Node_Id
) is
15939 procedure Modifier_Error
;
15940 -- Generate message about bad "not" modifier if no message already
15941 -- generated. Errors include specifying "not" for an aspect of
15942 -- of a type and specifying "not" for some but not all of the
15943 -- names in a list.
15945 --------------------
15946 -- Modifier_Error --
15947 --------------------
15949 procedure Modifier_Error
is
15951 if Modifier_Error_Called
then
15952 return; -- error message already generated
15955 Modifier_Error_Called
:= True;
15957 if Is_Aspect_Of_Type
then
15959 ("NOT modifier not allowed for Stable_Properties aspect"
15960 & " of a type", PF_Arg
);
15962 Error_Msg_N
("mixed use of NOT modifiers", PF_Arg
);
15964 end Modifier_Error
;
15966 PF_Name
: Node_Id
:= PF_Arg
;
15968 -- Start of processing for Check_Property_Function_Arg
15971 if Nkind
(PF_Arg
) = N_Op_Not
then
15972 PF_Name
:= Right_Opnd
(PF_Arg
);
15974 case Modifier_Permission
is
15978 Modifier_Permission
:= Required
;
15983 case Modifier_Permission
is
15987 Modifier_Permission
:= Forbidden
;
15993 if Nkind
(PF_Name
) not in
15994 N_Identifier | N_Operator_Symbol | N_Selected_Component
15996 Error_Msg_N
("bad property function name", PF_Name
);
15998 end Check_Property_Function_Arg
;
16000 -- Start of processing for Validate_Aspect_Stable_Properties
16003 Error_Msg_Ada_2022_Feature
("aspect Stable_Properties", Sloc
(N
));
16005 if not Is_Aspect_Of_Type
and then not Is_Subprogram
(E
) then
16006 Error_Msg_N
("Stable_Properties aspect can only be specified for "
16007 & "a type or a subprogram", N
);
16008 elsif Class_Present
then
16009 if Is_Aspect_Of_Type
then
16010 if not Is_Tagged_Type
(E
) then
16012 ("Stable_Properties''Class aspect cannot be specified for "
16013 & "an untagged type", N
);
16016 if not Is_Dispatching_Operation
(E
) then
16018 ("Stable_Properties''Class aspect cannot be specified for "
16019 & "a subprogram that is not a primitive subprogram "
16020 & "of a tagged type", N
);
16025 if Nkind
(N
) = N_Aggregate
then
16026 if Present
(Component_Associations
(N
))
16027 or else Null_Record_Present
(N
)
16028 or else not Present
(Expressions
(N
))
16030 Error_Msg_N
("bad Stable_Properties aspect specification", N
);
16035 PF_Arg
: Node_Id
:= First
(Expressions
(N
));
16037 while Present
(PF_Arg
) loop
16038 Check_Property_Function_Arg
(PF_Arg
);
16043 Check_Property_Function_Arg
(N
);
16045 end Validate_Aspect_Stable_Properties
;
16047 --------------------------------
16048 -- Resolve_Iterable_Operation --
16049 --------------------------------
16051 procedure Resolve_Iterable_Operation
16053 Cursor
: Entity_Id
;
16062 if not Is_Overloaded
(N
) then
16063 if not Is_Entity_Name
(N
)
16064 or else Ekind
(Entity
(N
)) /= E_Function
16065 or else Scope
(Entity
(N
)) /= Scope
(Typ
)
16066 or else No
(First_Formal
(Entity
(N
)))
16067 or else Etype
(First_Formal
(Entity
(N
))) /= Typ
16070 ("iterable primitive must be local function name whose first "
16071 & "formal is an iterable type", N
);
16076 F1
:= First_Formal
(Ent
);
16077 F2
:= Next_Formal
(F1
);
16079 if Nam
= Name_First
then
16081 -- First (Container) => Cursor
16083 if Etype
(Ent
) /= Cursor
then
16084 Error_Msg_N
("primitive for First must yield a cursor", N
);
16085 elsif Present
(F2
) then
16086 Error_Msg_N
("no match for First iterable primitive", N
);
16089 elsif Nam
= Name_Last
then
16091 -- Last (Container) => Cursor
16093 if Etype
(Ent
) /= Cursor
then
16094 Error_Msg_N
("primitive for Last must yield a cursor", N
);
16095 elsif Present
(F2
) then
16096 Error_Msg_N
("no match for Last iterable primitive", N
);
16099 elsif Nam
= Name_Next
then
16101 -- Next (Container, Cursor) => Cursor
16104 or else Etype
(F2
) /= Cursor
16105 or else Etype
(Ent
) /= Cursor
16106 or else Present
(Next_Formal
(F2
))
16108 Error_Msg_N
("no match for Next iterable primitive", N
);
16111 elsif Nam
= Name_Previous
then
16113 -- Previous (Container, Cursor) => Cursor
16116 or else Etype
(F2
) /= Cursor
16117 or else Etype
(Ent
) /= Cursor
16118 or else Present
(Next_Formal
(F2
))
16120 Error_Msg_N
("no match for Previous iterable primitive", N
);
16123 elsif Nam
= Name_Has_Element
then
16125 -- Has_Element (Container, Cursor) => Boolean
16128 or else Etype
(F2
) /= Cursor
16129 or else Etype
(Ent
) /= Standard_Boolean
16130 or else Present
(Next_Formal
(F2
))
16132 Error_Msg_N
("no match for Has_Element iterable primitive", N
);
16135 elsif Nam
= Name_Element
then
16137 -- Element (Container, Cursor) => Element_Type;
16140 or else Etype
(F2
) /= Cursor
16141 or else Present
(Next_Formal
(F2
))
16143 Error_Msg_N
("no match for Element iterable primitive", N
);
16147 raise Program_Error
;
16151 -- Overloaded case: find subprogram with proper signature. Caller
16152 -- will report error if no match is found.
16159 Get_First_Interp
(N
, I
, It
);
16160 while Present
(It
.Typ
) loop
16161 if Ekind
(It
.Nam
) = E_Function
16162 and then Scope
(It
.Nam
) = Scope
(Typ
)
16163 and then Present
(First_Formal
(It
.Nam
))
16164 and then Etype
(First_Formal
(It
.Nam
)) = Typ
16166 F1
:= First_Formal
(It
.Nam
);
16168 if Nam
= Name_First
then
16169 if Etype
(It
.Nam
) = Cursor
16170 and then No
(Next_Formal
(F1
))
16172 Set_Entity
(N
, It
.Nam
);
16176 elsif Nam
= Name_Next
then
16177 F2
:= Next_Formal
(F1
);
16180 and then No
(Next_Formal
(F2
))
16181 and then Etype
(F2
) = Cursor
16182 and then Etype
(It
.Nam
) = Cursor
16184 Set_Entity
(N
, It
.Nam
);
16188 elsif Nam
= Name_Has_Element
then
16189 F2
:= Next_Formal
(F1
);
16192 and then No
(Next_Formal
(F2
))
16193 and then Etype
(F2
) = Cursor
16194 and then Etype
(It
.Nam
) = Standard_Boolean
16196 Set_Entity
(N
, It
.Nam
);
16197 F2
:= Next_Formal
(F1
);
16201 elsif Nam
= Name_Element
then
16202 F2
:= Next_Formal
(F1
);
16205 and then No
(Next_Formal
(F2
))
16206 and then Etype
(F2
) = Cursor
16208 Set_Entity
(N
, It
.Nam
);
16214 Get_Next_Interp
(I
, It
);
16218 end Resolve_Iterable_Operation
;
16220 ------------------------------
16221 -- Resolve_Aspect_Aggregate --
16222 ------------------------------
16224 procedure Resolve_Aspect_Aggregate
16228 function Valid_Empty
(E
: Entity_Id
) return Boolean;
16229 function Valid_Add_Named
(E
: Entity_Id
) return Boolean;
16230 function Valid_Add_Unnamed
(E
: Entity_Id
) return Boolean;
16231 function Valid_New_Indexed
(E
: Entity_Id
) return Boolean;
16232 function Valid_Assign_Indexed
(E
: Entity_Id
) return Boolean;
16233 -- Predicates that establish the legality of each possible operation in
16234 -- an Aggregate aspect.
16237 with function Pred
(Id
: Node_Id
) return Boolean;
16238 procedure Resolve_Operation
(Subp_Id
: Node_Id
);
16239 -- Common processing to resolve each aggregate operation.
16241 ------------------------
16242 -- Valid_Assign_Index --
16243 ------------------------
16245 function Valid_Assign_Indexed
(E
: Entity_Id
) return Boolean is
16247 -- The profile must be the same as for Add_Named, with the added
16248 -- requirement that the key_type be a discrete type.
16250 if Valid_Add_Named
(E
) then
16251 return Is_Discrete_Type
(Etype
(Next_Formal
(First_Formal
(E
))));
16255 end Valid_Assign_Indexed
;
16261 function Valid_Empty
(E
: Entity_Id
) return Boolean is
16263 if Etype
(E
) /= Typ
or else Scope
(E
) /= Scope
(Typ
) then
16266 elsif Ekind
(E
) = E_Constant
then
16269 elsif Ekind
(E
) = E_Function
then
16270 return No
(First_Formal
(E
))
16272 (Is_Integer_Type
(Etype
(First_Formal
(E
)))
16273 and then No
(Next_Formal
(First_Formal
(E
))));
16279 ---------------------
16280 -- Valid_Add_Named --
16281 ---------------------
16283 function Valid_Add_Named
(E
: Entity_Id
) return Boolean is
16284 F2
, F3
: Entity_Id
;
16286 if Ekind
(E
) = E_Procedure
16287 and then Scope
(E
) = Scope
(Typ
)
16288 and then Number_Formals
(E
) = 3
16289 and then Etype
(First_Formal
(E
)) = Typ
16290 and then Ekind
(First_Formal
(E
)) = E_In_Out_Parameter
16292 F2
:= Next_Formal
(First_Formal
(E
));
16293 F3
:= Next_Formal
(F2
);
16294 return Ekind
(F2
) = E_In_Parameter
16295 and then Ekind
(F3
) = E_In_Parameter
16296 and then not Is_Limited_Type
(Etype
(F2
))
16297 and then not Is_Limited_Type
(Etype
(F3
));
16301 end Valid_Add_Named
;
16303 -----------------------
16304 -- Valid_Add_Unnamed --
16305 -----------------------
16307 function Valid_Add_Unnamed
(E
: Entity_Id
) return Boolean is
16309 return Ekind
(E
) = E_Procedure
16310 and then Scope
(E
) = Scope
(Typ
)
16311 and then Number_Formals
(E
) = 2
16312 and then Etype
(First_Formal
(E
)) = Typ
16313 and then Ekind
(First_Formal
(E
)) = E_In_Out_Parameter
16315 not Is_Limited_Type
(Etype
(Next_Formal
(First_Formal
(E
))));
16316 end Valid_Add_Unnamed
;
16318 -----------------------
16319 -- Valid_Nmw_Indexed --
16320 -----------------------
16322 function Valid_New_Indexed
(E
: Entity_Id
) return Boolean is
16324 return Ekind
(E
) = E_Function
16325 and then Scope
(E
) = Scope
(Typ
)
16326 and then Etype
(E
) = Typ
16327 and then Number_Formals
(E
) = 2
16328 and then Is_Discrete_Type
(Etype
(First_Formal
(E
)))
16329 and then Etype
(First_Formal
(E
)) =
16330 Etype
(Next_Formal
(First_Formal
(E
)));
16331 end Valid_New_Indexed
;
16333 -----------------------
16334 -- Resolve_Operation --
16335 -----------------------
16337 procedure Resolve_Operation
(Subp_Id
: Node_Id
) is
16344 if not Is_Overloaded
(Subp_Id
) then
16345 Subp
:= Entity
(Subp_Id
);
16346 if not Pred
(Subp
) then
16348 ("improper aggregate operation for&", Subp_Id
, Typ
);
16352 Set_Entity
(Subp_Id
, Empty
);
16353 Get_First_Interp
(Subp_Id
, I
, It
);
16354 while Present
(It
.Nam
) loop
16355 if Pred
(It
.Nam
) then
16356 Set_Is_Overloaded
(Subp_Id
, False);
16357 Set_Entity
(Subp_Id
, It
.Nam
);
16361 Get_Next_Interp
(I
, It
);
16364 if No
(Entity
(Subp_Id
)) then
16366 ("improper aggregate operation for&", Subp_Id
, Typ
);
16369 end Resolve_Operation
;
16375 procedure Resolve_Empty
is new Resolve_Operation
(Valid_Empty
);
16376 procedure Resolve_Unnamed
is new Resolve_Operation
(Valid_Add_Unnamed
);
16377 procedure Resolve_Named
is new Resolve_Operation
(Valid_Add_Named
);
16378 procedure Resolve_Indexed
is new Resolve_Operation
(Valid_New_Indexed
);
16379 procedure Resolve_Assign_Indexed
16380 is new Resolve_Operation
16381 (Valid_Assign_Indexed
);
16383 -- Start of processing for Resolve_Aspect_Aggregate
16386 Assoc
:= First
(Component_Associations
(Expr
));
16388 while Present
(Assoc
) loop
16389 Op_Name
:= Chars
(First
(Choices
(Assoc
)));
16391 -- When verifying the consistency of aspects between the freeze point
16392 -- and the end of declarqtions, we use a copy which is not analyzed
16393 -- yet, so do it now.
16395 Subp_Id
:= Expression
(Assoc
);
16396 if No
(Etype
(Subp_Id
)) then
16400 if Op_Name
= Name_Empty
then
16401 Resolve_Empty
(Subp_Id
);
16403 elsif Op_Name
= Name_Add_Named
then
16404 Resolve_Named
(Subp_Id
);
16406 elsif Op_Name
= Name_Add_Unnamed
then
16407 Resolve_Unnamed
(Subp_Id
);
16409 elsif Op_Name
= Name_New_Indexed
then
16410 Resolve_Indexed
(Subp_Id
);
16412 elsif Op_Name
= Name_Assign_Indexed
then
16413 Resolve_Assign_Indexed
(Subp_Id
);
16418 end Resolve_Aspect_Aggregate
;
16420 --------------------------------------
16421 -- Resolve_Aspect_Stable_Properties --
16422 --------------------------------------
16424 procedure Resolve_Aspect_Stable_Properties
16425 (Typ_Or_Subp
: Entity_Id
; Expr
: Node_Id
; Class_Present
: Boolean)
16427 Is_Aspect_Of_Type
: constant Boolean := Is_Type
(Typ_Or_Subp
);
16429 Singleton
: constant Boolean := Nkind
(Expr
) /= N_Aggregate
;
16430 Subp_Name
: Node_Id
:= (if Singleton
16432 else First
(Expressions
(Expr
)));
16435 if Is_Aspect_Of_Type
16436 and then Has_Private_Declaration
(Typ_Or_Subp
)
16437 and then not Is_Private_Type
(Typ_Or_Subp
)
16440 ("Stable_Properties aspect cannot be specified " &
16441 "for the completion of a private type", Typ_Or_Subp
);
16444 -- Analogous checks that the aspect is not specified for a completion
16445 -- in the subprogram case are not performed here because they are not
16446 -- specific to this particular aspect. Right ???
16449 Has_Not
:= Nkind
(Subp_Name
) = N_Op_Not
;
16451 Set_Analyzed
(Subp_Name
); -- ???
16452 Subp_Name
:= Right_Opnd
(Subp_Name
);
16455 if No
(Etype
(Subp_Name
)) then
16456 Analyze
(Subp_Name
);
16460 Subp
: Entity_Id
:= Empty
;
16465 function Is_Property_Function
(E
: Entity_Id
) return Boolean;
16466 -- Implements RM 7.3.4 definition of "property function".
16468 function Is_Property_Function
(E
: Entity_Id
) return Boolean is
16470 if Ekind
(E
) not in E_Function | E_Operator
16471 or else Number_Formals
(E
) /= 1
16477 Param_Type
: constant Entity_Id
:=
16478 Base_Type
(Etype
(First_Formal
(E
)));
16480 function Matches_Param_Type
(Typ
: Entity_Id
)
16482 (Base_Type
(Typ
) = Param_Type
16484 (Is_Class_Wide_Type
(Param_Type
)
16485 and then Is_Ancestor
(Root_Type
(Param_Type
),
16486 Base_Type
(Typ
))));
16488 if Is_Aspect_Of_Type
then
16489 if Matches_Param_Type
(Typ_Or_Subp
) then
16492 elsif Is_Primitive
(Typ_Or_Subp
) then
16494 Formal
: Entity_Id
:= First_Formal
(Typ_Or_Subp
);
16496 while Present
(Formal
) loop
16497 if Matches_Param_Type
(Etype
(Formal
)) then
16499 -- Test whether Typ_Or_Subp (which is a subp
16500 -- in this case) is primitive op of the type
16501 -- of this parameter.
16502 if Scope
(Typ_Or_Subp
) = Scope
(Param_Type
) then
16506 Next_Formal
(Formal
);
16513 end Is_Property_Function
;
16515 if not Is_Overloaded
(Subp_Name
) then
16516 Subp
:= Entity
(Subp_Name
);
16517 if not Is_Property_Function
(Subp
) then
16518 Error_Msg_NE
("improper property function for&",
16519 Subp_Name
, Typ_Or_Subp
);
16523 Set_Entity
(Subp_Name
, Empty
);
16524 Get_First_Interp
(Subp_Name
, I
, It
);
16525 while Present
(It
.Nam
) loop
16526 if Is_Property_Function
(It
.Nam
) then
16527 if Present
(Subp
) then
16529 ("ambiguous property function name for&",
16530 Subp_Name
, Typ_Or_Subp
);
16535 Set_Is_Overloaded
(Subp_Name
, False);
16536 Set_Entity
(Subp_Name
, Subp
);
16539 Get_Next_Interp
(I
, It
);
16543 Error_Msg_NE
("improper property function for&",
16544 Subp_Name
, Typ_Or_Subp
);
16549 -- perform legality (as opposed to name resolution) Subp checks
16551 if Is_Limited_Type
(Etype
(Subp
)) then
16553 ("result type of property function for& is limited",
16554 Subp_Name
, Typ_Or_Subp
);
16557 if Ekind
(First_Formal
(Subp
)) /= E_In_Parameter
then
16559 ("mode of parameter of property function for& is not IN",
16560 Subp_Name
, Typ_Or_Subp
);
16563 if Is_Class_Wide_Type
(Etype
(First_Formal
(Subp
))) then
16564 if not Covers
(Etype
(First_Formal
(Subp
)), Typ_Or_Subp
) then
16566 ("class-wide parameter type of property function " &
16567 "for& does not cover the type",
16568 Subp_Name
, Typ_Or_Subp
);
16570 -- ??? This test is slightly stricter than 7.3.4(12/5);
16571 -- some legal corner cases may be incorrectly rejected.
16572 elsif Scope
(Subp
) /= Scope
(Etype
(First_Formal
(Subp
)))
16575 ("property function for& not declared in same scope " &
16576 "as parameter type",
16577 Subp_Name
, Typ_Or_Subp
);
16579 elsif Is_Aspect_Of_Type
and then
16580 Scope
(Subp
) /= Scope
(Typ_Or_Subp
) and then
16581 Scope
(Subp
) /= Standard_Standard
-- e.g., derived type's "abs"
16584 ("property function for& " &
16585 "not a primitive function of the type",
16586 Subp_Name
, Typ_Or_Subp
);
16590 -- check that Subp was mentioned in param type's aspect spec
16592 Param_Type
: constant Entity_Id
:=
16593 Base_Type
(Etype
(First_Formal
(Subp
)));
16594 Aspect_Spec
: constant Node_Id
:=
16595 Find_Value_Of_Aspect
16596 (Param_Type
, Aspect_Stable_Properties
,
16597 Class_Present
=> Class_Present
);
16598 Found
: Boolean := False;
16600 if Present
(Aspect_Spec
) then
16603 SPF_List
: constant Subprogram_List
:=
16604 Parse_Aspect_Stable_Properties
16605 (Aspect_Spec
, Negated
=> Ignored
);
16607 Found
:= (for some E
of SPF_List
=> E
= Subp
);
16608 -- look through renamings ???
16613 CW_Modifier
: constant String :=
16614 (if Class_Present
then "class-wide " else "");
16618 & "property function for& mentioned after NOT "
16621 & "stable property function of its parameter type",
16622 Subp_Name
, Typ_Or_Subp
);
16629 exit when Singleton
;
16631 Next
((if Has_Not
then Parent
(Subp_Name
) else Subp_Name
));
16632 exit when No
(Subp_Name
);
16635 Set_Analyzed
(Expr
);
16636 end Resolve_Aspect_Stable_Properties
;
16638 -----------------------------------------
16639 -- Resolve_Storage_Model_Type_Argument --
16640 -----------------------------------------
16642 procedure Resolve_Storage_Model_Type_Argument
16645 Addr_Type
: in out Entity_Id
;
16649 type Formal_Profile
is record
16651 Mode
: Formal_Kind
;
16654 type Formal_Profiles
is array (Positive range <>) of Formal_Profile
;
16656 function Aspect_Argument_Profile_Matches
16658 Profiles
: Formal_Profiles
;
16659 Result_Subt
: Entity_Id
;
16660 Err_On_Mismatch
: Boolean) return Boolean;
16661 -- Checks that the formal parameters of subprogram Subp conform to the
16662 -- subtypes and modes specified by Profiles, as well as to the result
16663 -- subtype Result_Subt when that is nonempty.
16665 function Aspect_Argument_Profile_Matches
16667 Profiles
: Formal_Profiles
;
16668 Result_Subt
: Entity_Id
;
16669 Err_On_Mismatch
: Boolean) return Boolean
16672 procedure Report_Argument_Error
16674 Formal
: Entity_Id
:= Empty
;
16675 Subt
: Entity_Id
:= Empty
);
16676 -- If Err_On_Mismatch is True, reports an argument error given by Msg
16677 -- associated with Formal and/or Subt.
16679 procedure Report_Argument_Error
16681 Formal
: Entity_Id
:= Empty
;
16682 Subt
: Entity_Id
:= Empty
)
16685 if Err_On_Mismatch
then
16686 if Present
(Formal
) then
16687 if Present
(Subt
) then
16688 Error_Msg_Node_2
:= Subt
;
16690 Error_Msg_NE
(Msg
, N
, Formal
);
16692 elsif Present
(Subt
) then
16693 Error_Msg_NE
(Msg
, N
, Subt
);
16696 Error_Msg_N
(Msg
, N
);
16699 end Report_Argument_Error
;
16703 Formal
: Entity_Id
:= First_Formal
(Subp
);
16704 Is_Error
: Boolean := False;
16706 -- Start of processing for Aspect_Argument_Profile_Matches
16709 for FP
of Profiles
loop
16710 if No
(Formal
) then
16712 Report_Argument_Error
("missing formal of }", Subt
=> FP
.Subt
);
16715 elsif not Subtypes_Statically_Match
16716 (Etype
(Formal
), FP
.Subt
)
16719 Report_Argument_Error
16720 ("formal& must be of subtype&",
16721 Formal
=> Formal
, Subt
=> FP
.Subt
);
16724 elsif Ekind
(Formal
) /= FP
.Mode
then
16726 Report_Argument_Error
16727 ("formal& has wrong mode", Formal
=> Formal
);
16731 Formal
:= Next_Formal
(Formal
);
16735 and then Present
(Formal
)
16738 Report_Argument_Error
16739 ("too many formals for subprogram in aspect");
16743 and then Present
(Result_Subt
)
16744 and then not Subtypes_Statically_Match
(Etype
(Subp
), Result_Subt
)
16747 Report_Argument_Error
16748 ("subprogram must have result}", Subt
=> Result_Subt
);
16751 return not Is_Error
;
16752 end Aspect_Argument_Profile_Matches
;
16758 Storage_Count_Type
: constant Entity_Id
:= RTE
(RE_Storage_Count
);
16759 System_Address_Type
: constant Entity_Id
:= RTE
(RE_Address
);
16761 -- Start of processing for Resolve_Storage_Model_Type_Argument
16764 if Nam
= Name_Address_Type
then
16765 if not Is_Entity_Name
(N
)
16766 or else not Is_Type
(Entity
(N
))
16767 or else (Root_Type
(Entity
(N
)) /= System_Address_Type
16768 and then not Is_Integer_Type
(Entity
(N
)))
16770 Error_Msg_N
("named entity must be a descendant of System.Address "
16771 & "or an integer type", N
);
16774 Addr_Type
:= Entity
(N
);
16778 -- If Addr_Type is not present as the first association, then we default
16779 -- it to System.Address.
16781 elsif No
(Addr_Type
) then
16782 Addr_Type
:= RTE
(RE_Address
);
16785 if Nam
= Name_Null_Address
then
16786 if not Is_Entity_Name
(N
)
16787 or else not Is_Constant_Object
(Entity
(N
))
16789 not Subtypes_Statically_Match
(Etype
(Entity
(N
)), Addr_Type
)
16792 ("named entity must be constant of subtype}", N
, Addr_Type
);
16797 elsif not Is_Overloaded
(N
) then
16798 if not Is_Entity_Name
(N
)
16799 or else Ekind
(Entity
(N
)) not in E_Function | E_Procedure
16800 or else Scope
(Entity
(N
)) /= Scope
(Typ
)
16802 Error_Msg_N
("argument must be local subprogram name", N
);
16808 if Nam
= Name_Allocate
then
16809 if not Aspect_Argument_Profile_Matches
16812 ((Typ
, E_In_Out_Parameter
),
16813 (Addr_Type
, E_Out_Parameter
),
16814 (Storage_Count_Type
, E_In_Parameter
),
16815 (Storage_Count_Type
, E_In_Parameter
)),
16816 Result_Subt
=> Empty
,
16817 Err_On_Mismatch
=> True)
16819 Error_Msg_N
("no match for Allocate operation", N
);
16822 elsif Nam
= Name_Deallocate
then
16823 if not Aspect_Argument_Profile_Matches
16826 ((Typ
, E_In_Out_Parameter
),
16827 (Addr_Type
, E_In_Parameter
),
16828 (Storage_Count_Type
, E_In_Parameter
),
16829 (Storage_Count_Type
, E_In_Parameter
)),
16830 Result_Subt
=> Empty
,
16831 Err_On_Mismatch
=> True)
16833 Error_Msg_N
("no match for Deallocate operation", N
);
16836 elsif Nam
= Name_Copy_From
then
16837 if not Aspect_Argument_Profile_Matches
16840 ((Typ
, E_In_Out_Parameter
),
16841 (System_Address_Type
, E_In_Parameter
),
16842 (Addr_Type
, E_In_Parameter
),
16843 (Storage_Count_Type
, E_In_Parameter
)),
16844 Result_Subt
=> Empty
,
16845 Err_On_Mismatch
=> True)
16847 Error_Msg_N
("no match for Copy_From operation", N
);
16850 elsif Nam
= Name_Copy_To
then
16851 if not Aspect_Argument_Profile_Matches
16854 ((Typ
, E_In_Out_Parameter
),
16855 (Addr_Type
, E_In_Parameter
),
16856 (System_Address_Type
, E_In_Parameter
),
16857 (Storage_Count_Type
, E_In_Parameter
)),
16858 Result_Subt
=> Empty
,
16859 Err_On_Mismatch
=> True)
16861 Error_Msg_N
("no match for Copy_To operation", N
);
16864 elsif Nam
= Name_Storage_Size
then
16865 if not Aspect_Argument_Profile_Matches
16867 Profiles
=> (1 => (Typ
, E_In_Parameter
)),
16868 Result_Subt
=> Storage_Count_Type
,
16869 Err_On_Mismatch
=> True)
16871 Error_Msg_N
("no match for Storage_Size operation", N
);
16875 null; -- Error will be caught in Validate_Storage_Model_Type_Aspect
16879 -- Overloaded case: find subprogram with proper signature
16884 Found_Match
: Boolean := False;
16887 Get_First_Interp
(N
, I
, It
);
16888 while Present
(It
.Typ
) loop
16889 if Ekind
(It
.Nam
) in E_Function | E_Procedure
16890 and then Scope
(It
.Nam
) = Scope
(Typ
)
16892 if Nam
= Name_Allocate
then
16894 Aspect_Argument_Profile_Matches
16897 ((Typ
, E_In_Out_Parameter
),
16898 (Addr_Type
, E_Out_Parameter
),
16899 (Storage_Count_Type
, E_In_Parameter
),
16900 (Storage_Count_Type
, E_In_Parameter
)),
16901 Result_Subt
=> Empty
,
16902 Err_On_Mismatch
=> False);
16904 elsif Nam
= Name_Deallocate
then
16906 Aspect_Argument_Profile_Matches
16909 ((Typ
, E_In_Out_Parameter
),
16910 (Addr_Type
, E_In_Parameter
),
16911 (Storage_Count_Type
, E_In_Parameter
),
16912 (Storage_Count_Type
, E_In_Parameter
)),
16913 Result_Subt
=> Empty
,
16914 Err_On_Mismatch
=> False);
16916 elsif Nam
= Name_Copy_From
then
16918 Aspect_Argument_Profile_Matches
16921 ((Typ
, E_In_Out_Parameter
),
16922 (System_Address_Type
, E_In_Parameter
),
16923 (Addr_Type
, E_In_Parameter
),
16924 (Storage_Count_Type
, E_In_Parameter
),
16925 (Storage_Count_Type
, E_In_Parameter
)),
16926 Result_Subt
=> Empty
,
16927 Err_On_Mismatch
=> False);
16929 elsif Nam
= Name_Copy_To
then
16931 Aspect_Argument_Profile_Matches
16934 ((Typ
, E_In_Out_Parameter
),
16935 (Addr_Type
, E_In_Parameter
),
16936 (Storage_Count_Type
, E_In_Parameter
),
16937 (System_Address_Type
, E_In_Parameter
),
16938 (Storage_Count_Type
, E_In_Parameter
)),
16939 Result_Subt
=> Empty
,
16940 Err_On_Mismatch
=> False);
16942 elsif Nam
= Name_Storage_Size
then
16944 Aspect_Argument_Profile_Matches
16946 Profiles
=> (1 => (Typ
, E_In_Parameter
)),
16947 Result_Subt
=> Storage_Count_Type
,
16948 Err_On_Mismatch
=> False);
16951 if Found_Match
then
16952 Set_Entity
(N
, It
.Nam
);
16957 Get_Next_Interp
(I
, It
);
16960 if not Found_Match
then
16962 ("no match found for Storage_Model_Type operation", N
);
16966 end Resolve_Storage_Model_Type_Argument
;
16972 procedure Set_Biased
16976 Biased
: Boolean := True)
16980 Set_Has_Biased_Representation
(E
);
16982 if Warn_On_Biased_Representation
then
16984 ("?.b?" & Msg
& " forces biased representation for&", N
, E
);
16989 --------------------
16990 -- Set_Enum_Esize --
16991 --------------------
16993 procedure Set_Enum_Esize
(T
: Entity_Id
) is
16999 Reinit_Alignment
(T
);
17001 -- Find the minimum standard size (8,16,32,64,128) that fits
17003 Lo
:= Enumeration_Rep
(Entity
(Type_Low_Bound
(T
)));
17004 Hi
:= Enumeration_Rep
(Entity
(Type_High_Bound
(T
)));
17007 if Lo
>= -Uint_2
**7 and then Hi
< Uint_2
**7 then
17008 Sz
:= UI_From_Int
(Standard_Character_Size
);
17009 -- Might be > 8 on some targets
17011 elsif Lo
>= -Uint_2
**15 and then Hi
< Uint_2
**15 then
17014 elsif Lo
>= -Uint_2
**31 and then Hi
< Uint_2
**31 then
17017 elsif Lo
>= -Uint_2
**63 and then Hi
< Uint_2
**63 then
17020 else pragma Assert
(Lo
>= -Uint_2
**127 and then Hi
< Uint_2
**127);
17025 if Hi
< Uint_2
**8 then
17026 Sz
:= UI_From_Int
(Standard_Character_Size
);
17028 elsif Hi
< Uint_2
**16 then
17031 elsif Hi
< Uint_2
**32 then
17034 elsif Hi
< Uint_2
**64 then
17037 else pragma Assert
(Hi
< Uint_2
**128);
17042 -- That minimum is the proper size unless we have a foreign convention
17043 -- and the size required is 32 or less, in which case we bump the size
17044 -- up to 32. This is required for C and C++ and seems reasonable for
17045 -- all other foreign conventions.
17047 if Has_Foreign_Convention
(T
)
17048 and then Esize
(T
) < Standard_Integer_Size
17050 -- Don't do this if Short_Enums on target
17052 and then not Target_Short_Enums
17054 Set_Esize
(T
, UI_From_Int
(Standard_Integer_Size
));
17058 end Set_Enum_Esize
;
17060 -----------------------------
17061 -- Uninstall_Discriminants --
17062 -----------------------------
17064 procedure Uninstall_Discriminants
(E
: Entity_Id
) is
17070 -- Discriminants have been made visible for type declarations and
17071 -- protected type declarations, not for subtype declarations.
17073 if Nkind
(Parent
(E
)) /= N_Subtype_Declaration
then
17074 Disc
:= First_Discriminant
(E
);
17075 while Present
(Disc
) loop
17076 if Disc
/= Current_Entity
(Disc
) then
17077 Prev
:= Current_Entity
(Disc
);
17078 while Present
(Prev
)
17079 and then Present
(Homonym
(Prev
))
17080 and then Homonym
(Prev
) /= Disc
17082 Prev
:= Homonym
(Prev
);
17088 Set_Is_Immediately_Visible
(Disc
, False);
17090 Outer
:= Homonym
(Disc
);
17091 while Present
(Outer
) and then Scope
(Outer
) = E
loop
17092 Outer
:= Homonym
(Outer
);
17095 -- Reset homonym link of other entities, but do not modify link
17096 -- between entities in current scope, so that the back end can
17097 -- have a proper count of local overloadings.
17100 Set_Name_Entity_Id
(Chars
(Disc
), Outer
);
17102 elsif Scope
(Prev
) /= Scope
(Disc
) then
17103 Set_Homonym
(Prev
, Outer
);
17106 Next_Discriminant
(Disc
);
17109 end Uninstall_Discriminants
;
17111 ------------------------------
17112 -- Validate_Address_Clauses --
17113 ------------------------------
17115 procedure Validate_Address_Clauses
is
17116 function Offset_Value
(Expr
: Node_Id
) return Uint
;
17117 -- Given an Address attribute reference, return the value in bits of its
17118 -- offset from the first bit of the underlying entity, or 0 if it is not
17119 -- known at compile time.
17125 function Offset_Value
(Expr
: Node_Id
) return Uint
is
17126 N
: Node_Id
:= Prefix
(Expr
);
17128 Val
: Uint
:= Uint_0
;
17131 -- Climb the prefix chain and compute the cumulative offset
17134 if Is_Entity_Name
(N
) then
17137 elsif Nkind
(N
) = N_Selected_Component
then
17138 Off
:= Component_Bit_Offset
(Entity
(Selector_Name
(N
)));
17139 if Present
(Off
) and then Off
>= Uint_0
then
17146 elsif Nkind
(N
) = N_Indexed_Component
then
17147 Off
:= Indexed_Component_Bit_Offset
(N
);
17148 if Present
(Off
) then
17161 -- Start of processing for Validate_Address_Clauses
17164 for J
in Address_Clause_Checks
.First
.. Address_Clause_Checks
.Last
loop
17166 ACCR
: Address_Clause_Check_Record
17167 renames Address_Clause_Checks
.Table
(J
);
17171 X_Alignment
: Uint
;
17172 Y_Alignment
: Uint
:= Uint_0
;
17175 Y_Size
: Uint
:= Uint_0
;
17180 -- Skip processing of this entry if warning already posted, or if
17181 -- alignments are not set.
17183 if not Address_Warning_Posted
(ACCR
.N
)
17184 and then Known_Alignment
(ACCR
.X
)
17185 and then Known_Alignment
(ACCR
.Y
)
17187 Expr
:= Original_Node
(Expression
(ACCR
.N
));
17189 -- Get alignments, sizes and offset, if any
17191 X_Alignment
:= Alignment
(ACCR
.X
);
17192 X_Size
:= Esize
(ACCR
.X
);
17194 if Present
(ACCR
.Y
) then
17195 Y_Alignment
:= Alignment
(ACCR
.Y
);
17197 (if Known_Esize
(ACCR
.Y
) then Esize
(ACCR
.Y
) else Uint_0
);
17201 and then Nkind
(Expr
) = N_Attribute_Reference
17202 and then Attribute_Name
(Expr
) = Name_Address
17204 X_Offs
:= Offset_Value
(Expr
);
17209 -- Check for known value not multiple of alignment
17211 if No
(ACCR
.Y
) then
17212 if not Alignment_Checks_Suppressed
(ACCR
)
17213 and then X_Alignment
/= 0
17214 and then ACCR
.A
mod X_Alignment
/= 0
17217 ("??specified address for& is inconsistent with "
17218 & "alignment", ACCR
.N
, ACCR
.X
);
17220 ("\??program execution may be erroneous (RM 13.3(27))",
17223 Error_Msg_Uint_1
:= X_Alignment
;
17224 Error_Msg_NE
("\??alignment of & is ^", ACCR
.N
, ACCR
.X
);
17227 -- Check for large object overlaying smaller one
17229 elsif Y_Size
> Uint_0
17230 and then X_Size
> Uint_0
17231 and then X_Offs
+ X_Size
> Y_Size
17233 Error_Msg_NE
("??& overlays smaller object", ACCR
.N
, ACCR
.X
);
17235 ("\??program execution may be erroneous", ACCR
.N
);
17237 Error_Msg_Uint_1
:= X_Size
;
17238 Error_Msg_NE
("\??size of & is ^", ACCR
.N
, ACCR
.X
);
17240 Error_Msg_Uint_1
:= Y_Size
;
17241 Error_Msg_NE
("\??size of & is ^", ACCR
.N
, ACCR
.Y
);
17243 if Y_Size
>= X_Size
then
17244 Error_Msg_Uint_1
:= X_Offs
;
17245 Error_Msg_NE
("\??but offset of & is ^", ACCR
.N
, ACCR
.X
);
17248 -- Check for inadequate alignment, both of the base object
17249 -- and of the offset, if any. We only do this check if the
17250 -- run-time Alignment_Check is active. No point in warning
17251 -- if this check has been suppressed (or is suppressed by
17252 -- default in the non-strict alignment machine case).
17254 -- Note: we do not check the alignment if we gave a size
17255 -- warning, since it would likely be redundant.
17257 elsif not Alignment_Checks_Suppressed
(ACCR
)
17258 and then Y_Alignment
/= Uint_0
17260 (Y_Alignment
< X_Alignment
17263 and then Nkind
(Expr
) = N_Attribute_Reference
17264 and then Attribute_Name
(Expr
) = Name_Address
17265 and then Has_Compatible_Alignment
17266 (ACCR
.X
, Prefix
(Expr
), True) /=
17270 ("??specified address for& may be inconsistent with "
17271 & "alignment", ACCR
.N
, ACCR
.X
);
17273 ("\??program execution may be erroneous (RM 13.3(27))",
17276 Error_Msg_Uint_1
:= X_Alignment
;
17277 Error_Msg_NE
("\??alignment of & is ^", ACCR
.N
, ACCR
.X
);
17279 Error_Msg_Uint_1
:= Y_Alignment
;
17280 Error_Msg_NE
("\??alignment of & is ^", ACCR
.N
, ACCR
.Y
);
17282 if Y_Alignment
>= X_Alignment
then
17284 ("\??but offset is not multiple of alignment", ACCR
.N
);
17290 end Validate_Address_Clauses
;
17292 ------------------------------
17293 -- Validate_Iterable_Aspect --
17294 ------------------------------
17296 procedure Validate_Iterable_Aspect
(Typ
: Entity_Id
; ASN
: Node_Id
) is
17297 Aggr
: constant Node_Id
:= Expression
(ASN
);
17302 Cursor
: Entity_Id
;
17304 First_Id
: Entity_Id
:= Empty
;
17305 Last_Id
: Entity_Id
:= Empty
;
17306 Next_Id
: Entity_Id
:= Empty
;
17307 Has_Element_Id
: Entity_Id
:= Empty
;
17308 Element_Id
: Entity_Id
:= Empty
;
17311 if Nkind
(Aggr
) /= N_Aggregate
then
17312 Error_Msg_N
("aspect Iterable must be an aggregate", Aggr
);
17316 Cursor
:= Get_Cursor_Type
(ASN
, Typ
);
17318 -- If previous error aspect is unusable
17320 if Cursor
= Any_Type
then
17324 if not Is_Empty_List
(Expressions
(Aggr
)) then
17326 ("illegal positional association", First
(Expressions
(Aggr
)));
17329 -- Each expression must resolve to a function with the proper signature
17331 Assoc
:= First
(Component_Associations
(Aggr
));
17332 while Present
(Assoc
) loop
17333 Expr
:= Expression
(Assoc
);
17336 Prim
:= First
(Choices
(Assoc
));
17338 if Nkind
(Prim
) /= N_Identifier
or else Present
(Next
(Prim
)) then
17339 Error_Msg_N
("illegal name in association", Prim
);
17341 elsif Chars
(Prim
) = Name_First
then
17342 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_First
);
17343 First_Id
:= Entity
(Expr
);
17345 elsif Chars
(Prim
) = Name_Last
then
17346 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_Last
);
17347 Last_Id
:= Entity
(Expr
);
17349 elsif Chars
(Prim
) = Name_Previous
then
17350 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_Previous
);
17351 Last_Id
:= Entity
(Expr
);
17353 elsif Chars
(Prim
) = Name_Next
then
17354 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_Next
);
17355 Next_Id
:= Entity
(Expr
);
17357 elsif Chars
(Prim
) = Name_Has_Element
then
17358 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_Has_Element
);
17359 Has_Element_Id
:= Entity
(Expr
);
17361 elsif Chars
(Prim
) = Name_Element
then
17362 Resolve_Iterable_Operation
(Expr
, Cursor
, Typ
, Name_Element
);
17363 Element_Id
:= Entity
(Expr
);
17366 Error_Msg_N
("invalid name for iterable function", Prim
);
17372 if No
(First_Id
) then
17373 Error_Msg_N
("match for First primitive not found", ASN
);
17375 elsif No
(Next_Id
) then
17376 Error_Msg_N
("match for Next primitive not found", ASN
);
17378 elsif No
(Has_Element_Id
) then
17379 Error_Msg_N
("match for Has_Element primitive not found", ASN
);
17381 elsif No
(Element_Id
) or else No
(Last_Id
) then
17384 end Validate_Iterable_Aspect
;
17386 ------------------------------
17387 -- Validate_Literal_Aspect --
17388 ------------------------------
17390 procedure Validate_Literal_Aspect
(Typ
: Entity_Id
; ASN
: Node_Id
) is
17391 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(ASN
);
17392 pragma Assert
(A_Id
in Aspect_Integer_Literal |
17393 Aspect_Real_Literal | Aspect_String_Literal
);
17394 Func_Name
: constant Node_Id
:= Expression
(ASN
);
17395 Overloaded
: Boolean := Is_Overloaded
(Func_Name
);
17397 I
: Interp_Index
:= 0;
17399 Param_Type
: Entity_Id
;
17400 Match_Found
: Boolean := False;
17401 Match2_Found
: Boolean := False;
17402 Is_Match
: Boolean;
17404 Match2
: Entity_Id
:= Empty
;
17407 (Param_Id
: Entity_Id
; Param_Type
: Entity_Id
) return Boolean;
17408 -- Return True if Param_Id is a non aliased in parameter whose base type
17416 (Param_Id
: Entity_Id
; Param_Type
: Entity_Id
) return Boolean is
17418 return Base_Type
(Etype
(Param_Id
)) = Param_Type
17419 and then Ekind
(Param_Id
) = E_In_Parameter
17420 and then not Is_Aliased
(Param_Id
);
17424 if not Is_Type
(Typ
) then
17425 Error_Msg_N
("aspect can only be specified for a type", ASN
);
17428 elsif not Is_First_Subtype
(Typ
) then
17429 Error_Msg_N
("aspect cannot be specified for a subtype", ASN
);
17433 if A_Id
= Aspect_String_Literal
then
17434 if Is_String_Type
(Typ
) then
17435 Error_Msg_N
("aspect cannot be specified for a string type", ASN
);
17439 Param_Type
:= Standard_Wide_Wide_String
;
17442 if Is_Numeric_Type
(Typ
) then
17443 Error_Msg_N
("aspect cannot be specified for a numeric type", ASN
);
17447 Param_Type
:= Standard_String
;
17450 if not Overloaded
and then No
(Entity
(Func_Name
)) then
17451 -- The aspect is specified by a subprogram name, which
17452 -- may be an operator name given originally by a string.
17454 if Is_Operator_Name
(Chars
(Func_Name
)) then
17455 Analyze_Operator_Symbol
(Func_Name
);
17457 Analyze
(Func_Name
);
17460 Overloaded
:= Is_Overloaded
(Func_Name
);
17464 Get_First_Interp
(Func_Name
, I
=> I
, It
=> It
);
17466 -- only one possible interpretation
17467 It
.Nam
:= Entity
(Func_Name
);
17468 pragma Assert
(Present
(It
.Nam
));
17471 while It
.Nam
/= Empty
loop
17474 if Ekind
(It
.Nam
) = E_Function
17475 and then Base_Type
(Etype
(It
.Nam
)) = Base_Type
(Typ
)
17478 Params
: constant List_Id
:=
17479 Parameter_Specifications
(Parent
(It
.Nam
));
17480 Param_Spec
: Node_Id
;
17483 if List_Length
(Params
) = 1 then
17484 Param_Spec
:= First
(Params
);
17486 Matching
(Defining_Identifier
(Param_Spec
), Param_Type
);
17488 -- Look for the optional overloaded 2-param Real_Literal
17490 elsif List_Length
(Params
) = 2
17491 and then A_Id
= Aspect_Real_Literal
17493 Param_Spec
:= First
(Params
);
17495 if Matching
(Defining_Identifier
(Param_Spec
), Param_Type
)
17497 Param_Spec
:= Next
(Param_Spec
);
17499 if Matching
(Defining_Identifier
(Param_Spec
), Param_Type
)
17501 if No
(Match2
) then
17503 Match2_Found
:= True;
17505 -- If we find more than one possible match then
17506 -- do not take any into account here: since the
17507 -- 2-parameter version of Real_Literal is optional
17508 -- we cannot generate an error here, so let
17509 -- standard resolution fail later if we do need to
17510 -- call this variant.
17512 Match2_Found
:= False;
17521 if Match_Found
then
17522 Error_Msg_N
("aspect specification is ambiguous", ASN
);
17526 Match_Found
:= True;
17530 exit when not Overloaded
;
17532 if not Is_Match
then
17533 Remove_Interp
(I
=> I
);
17536 Get_Next_Interp
(I
=> I
, It
=> It
);
17539 if not Match_Found
then
17541 ("function name in aspect specification cannot be resolved", ASN
);
17545 Set_Entity
(Func_Name
, Match
.Nam
);
17546 Set_Etype
(Func_Name
, Etype
(Match
.Nam
));
17547 Set_Is_Overloaded
(Func_Name
, False);
17549 -- Record the match for 2-parameter function if found
17551 if Match2_Found
then
17552 Set_Related_Expression
(Match
.Nam
, Match2
);
17554 end Validate_Literal_Aspect
;
17556 ----------------------------------------
17557 -- Validate_Storage_Model_Type_Aspect --
17558 ----------------------------------------
17560 procedure Validate_Storage_Model_Type_Aspect
17561 (Typ
: Entity_Id
; ASN
: Node_Id
)
17564 Choice
: Entity_Id
;
17565 Choice_Name
: Name_Id
;
17568 Address_Type_Id
: Entity_Id
:= Empty
;
17569 Null_Address_Id
: Entity_Id
:= Empty
;
17570 Allocate_Id
: Entity_Id
:= Empty
;
17571 Deallocate_Id
: Entity_Id
:= Empty
;
17572 Copy_From_Id
: Entity_Id
:= Empty
;
17573 Copy_To_Id
: Entity_Id
:= Empty
;
17574 Storage_Size_Id
: Entity_Id
:= Empty
;
17576 procedure Check_And_Resolve_Storage_Model_Type_Argument
17579 Argument_Id
: in out Entity_Id
;
17581 -- Checks that the subaspect for Nam has not already been specified for
17582 -- Typ's Storage_Model_Type aspect (i.e., checks Argument_Id = Empty),
17583 -- resolves Expr, and sets Argument_Id to the entity resolved for Expr.
17585 procedure Check_And_Resolve_Storage_Model_Type_Argument
17588 Argument_Id
: in out Entity_Id
;
17591 Name_String
: String := Get_Name_String
(Nam
);
17594 To_Mixed
(Name_String
);
17596 if Present
(Argument_Id
) then
17597 Error_Msg_String
(1 .. Name_String
'Length) := Name_String
;
17598 Error_Msg_Strlen
:= Name_String
'Length;
17600 Error_Msg_N
("~ already specified", Expr
);
17603 Resolve_Storage_Model_Type_Argument
(Expr
, Typ
, Address_Type_Id
, Nam
);
17604 Argument_Id
:= Entity
(Expr
);
17605 end Check_And_Resolve_Storage_Model_Type_Argument
;
17607 -- Start of processing for Validate_Storage_Model_Type_Aspect
17610 -- The aggregate argument of Storage_Model_Type is optional, and when
17611 -- not present the aspect defaults to the native storage model (where
17612 -- the address type is System.Address, and other arguments default to
17613 -- the corresponding native storage operations).
17615 if No
(Expression
(ASN
)) then
17619 -- Each expression must resolve to an entity of the right kind or proper
17622 Assoc
:= First
(Component_Associations
(Expression
(ASN
)));
17623 while Present
(Assoc
) loop
17624 Expr
:= Expression
(Assoc
);
17627 Choice
:= First
(Choices
(Assoc
));
17629 Choice_Name
:= Chars
(Choice
);
17631 if Nkind
(Choice
) /= N_Identifier
or else Present
(Next
(Choice
)) then
17632 Error_Msg_N
("illegal name in association", Choice
);
17634 elsif Choice_Name
= Name_Address_Type
then
17635 if Assoc
/= First
(Component_Associations
(Expression
(ASN
))) then
17636 Error_Msg_N
("Address_Type must be first association", Choice
);
17639 Check_And_Resolve_Storage_Model_Type_Argument
17640 (Expr
, Typ
, Address_Type_Id
, Name_Address_Type
);
17643 -- It's allowed to leave out the Address_Type argument, in which
17644 -- case the address type is defined to default to System.Address.
17646 if No
(Address_Type_Id
) then
17647 Address_Type_Id
:= RTE
(RE_Address
);
17650 if Choice_Name
= Name_Null_Address
then
17651 Check_And_Resolve_Storage_Model_Type_Argument
17652 (Expr
, Typ
, Null_Address_Id
, Name_Null_Address
);
17654 elsif Choice_Name
= Name_Allocate
then
17655 Check_And_Resolve_Storage_Model_Type_Argument
17656 (Expr
, Typ
, Allocate_Id
, Name_Allocate
);
17658 elsif Choice_Name
= Name_Deallocate
then
17659 Check_And_Resolve_Storage_Model_Type_Argument
17660 (Expr
, Typ
, Deallocate_Id
, Name_Deallocate
);
17662 elsif Choice_Name
= Name_Copy_From
then
17663 Check_And_Resolve_Storage_Model_Type_Argument
17664 (Expr
, Typ
, Copy_From_Id
, Name_Copy_From
);
17666 elsif Choice_Name
= Name_Copy_To
then
17667 Check_And_Resolve_Storage_Model_Type_Argument
17668 (Expr
, Typ
, Copy_To_Id
, Name_Copy_To
);
17670 elsif Choice_Name
= Name_Storage_Size
then
17671 Check_And_Resolve_Storage_Model_Type_Argument
17672 (Expr
, Typ
, Storage_Size_Id
, Name_Storage_Size
);
17676 ("invalid name for Storage_Model_Type argument", Choice
);
17683 -- If Address_Type has been specified as or defaults to System.Address,
17684 -- then other "subaspect" arguments can be specified, but are optional.
17685 -- Otherwise, all other arguments are required and an error is flagged
17686 -- about any that are missing.
17688 if Address_Type_Id
= RTE
(RE_Address
) then
17691 elsif No
(Null_Address_Id
) then
17692 Error_Msg_N
("match for Null_Address primitive not found", ASN
);
17694 elsif No
(Allocate_Id
) then
17695 Error_Msg_N
("match for Allocate primitive not found", ASN
);
17697 elsif No
(Deallocate_Id
) then
17698 Error_Msg_N
("match for Deallocate primitive not found", ASN
);
17700 elsif No
(Copy_From_Id
) then
17701 Error_Msg_N
("match for Copy_From primitive not found", ASN
);
17703 elsif No
(Copy_To_Id
) then
17704 Error_Msg_N
("match for Copy_To primitive not found", ASN
);
17706 elsif No
(Storage_Size_Id
) then
17707 Error_Msg_N
("match for Storage_Size primitive not found", ASN
);
17709 end Validate_Storage_Model_Type_Aspect
;
17711 -----------------------------------
17712 -- Validate_Unchecked_Conversion --
17713 -----------------------------------
17715 procedure Validate_Unchecked_Conversion
17717 Act_Unit
: Entity_Id
)
17719 Source
: Entity_Id
;
17720 Target
: Entity_Id
;
17722 procedure Warn_Nonportable
(RE
: RE_Id
);
17723 -- Warn if either source or target of the conversion is a predefined
17724 -- private type, whose representation might differ between releases and
17725 -- targets of the compiler.
17727 ----------------------
17728 -- Warn_Nonportable --
17729 ----------------------
17731 procedure Warn_Nonportable
(RE
: RE_Id
) is
17733 if Is_RTE
(Source
, RE
) or else Is_RTE
(Target
, RE
) then
17734 pragma Assert
(Is_Private_Type
(RTE
(RE
)));
17736 ("?z?representation of & values may change between "
17737 & "'G'N'A'T versions", N
, RTE
(RE
));
17739 end Warn_Nonportable
;
17745 -- Start of processing for Validate_Unchecked_Conversion
17748 -- Obtain source and target types. Note that we call Ancestor_Subtype
17749 -- here because the processing for generic instantiation always makes
17750 -- subtypes, and we want the original frozen actual types.
17752 Source
:= Ancestor_Subtype
(Etype
(First_Formal
(Act_Unit
)));
17753 Target
:= Ancestor_Subtype
(Etype
(Act_Unit
));
17755 -- If either type is generic, the instantiation happens within a generic
17756 -- unit, and there is nothing to check. The proper check will happen
17757 -- when the enclosing generic is instantiated.
17759 if Is_Generic_Type
(Source
) or else Is_Generic_Type
(Target
) then
17763 -- Warn if one of the operands is a private type declared in
17764 -- Ada.Calendar or Ada.Real_Time. Do not emit a warning when compiling
17765 -- GNAT-related sources.
17767 if Warn_On_Unchecked_Conversion
17768 and then not In_Predefined_Unit
(N
)
17770 Warn_Nonportable
(RO_CA_Time
);
17771 Warn_Nonportable
(RO_RT_Time
);
17772 Warn_Nonportable
(RE_Time_Span
);
17775 -- If we are dealing with private types, then do the check on their
17776 -- fully declared counterparts if the full declarations have been
17777 -- encountered (they don't have to be visible, but they must exist).
17779 if Is_Private_Type
(Source
)
17780 and then Present
(Underlying_Type
(Source
))
17782 Source
:= Underlying_Type
(Source
);
17785 if Is_Private_Type
(Target
)
17786 and then Present
(Underlying_Type
(Target
))
17788 Target
:= Underlying_Type
(Target
);
17791 -- Source may be unconstrained array, but not target, except in relaxed
17794 if Is_Array_Type
(Target
)
17795 and then not Is_Constrained
(Target
)
17796 and then not Relaxed_RM_Semantics
17799 ("unchecked conversion to unconstrained array not allowed", N
);
17803 -- Warn if conversion between two different convention pointers
17805 if Is_Access_Type
(Target
)
17806 and then Is_Access_Type
(Source
)
17807 and then Convention
(Target
) /= Convention
(Source
)
17808 and then Warn_On_Unchecked_Conversion
17810 -- Give warnings for subprogram pointers only on most targets
17812 if Is_Access_Subprogram_Type
(Target
)
17813 or else Is_Access_Subprogram_Type
(Source
)
17816 ("?z?conversion between pointers with different conventions!",
17821 -- Make entry in unchecked conversion table for later processing by
17822 -- Validate_Unchecked_Conversions, which will check sizes and alignments
17823 -- (using values set by the back end where possible). This is only done
17824 -- if the appropriate warning is active.
17826 if Warn_On_Unchecked_Conversion
then
17827 Unchecked_Conversions
.Append
17828 (New_Val
=> UC_Entry
'(Eloc => Sloc (N),
17831 Act_Unit => Act_Unit));
17833 -- If both sizes are known statically now, then back-end annotation
17834 -- is not required to do a proper check but if either size is not
17835 -- known statically, then we need the annotation.
17837 if Known_Static_RM_Size (Source)
17839 Known_Static_RM_Size (Target)
17843 Back_Annotate_Rep_Info := True;
17847 -- If unchecked conversion to access type, and access type is declared
17848 -- in the same unit as the unchecked conversion, then set the flag
17849 -- No_Strict_Aliasing (no strict aliasing is implicit here)
17851 if Is_Access_Type (Target)
17852 and then In_Same_Source_Unit (Target, N)
17854 Set_No_Strict_Aliasing (Implementation_Base_Type (Target));
17857 -- If the unchecked conversion is between Address and an access
17858 -- subprogram type, show that we shouldn't use an internal
17859 -- representation for the access subprogram type.
17861 if Is_Access_Subprogram_Type (Target)
17862 and then Is_Descendant_Of_Address (Source)
17863 and then In_Same_Source_Unit (Target, N)
17865 Set_Can_Use_Internal_Rep (Base_Type (Target), False);
17866 elsif Is_Access_Subprogram_Type (Source)
17867 and then Is_Descendant_Of_Address (Target)
17868 and then In_Same_Source_Unit (Source, N)
17870 Set_Can_Use_Internal_Rep (Base_Type (Source), False);
17873 -- Generate N_Validate_Unchecked_Conversion node for back end in case
17874 -- the back end needs to perform special validation checks.
17876 -- Shouldn't this be in Exp_Ch13, since the check only gets done if we
17877 -- have full expansion and the back end is called ???
17880 Make_Validate_Unchecked_Conversion (Sloc (N));
17881 Set_Source_Type (Vnode, Source);
17882 Set_Target_Type (Vnode, Target);
17884 -- If the unchecked conversion node is in a list, just insert before it.
17885 -- If not we have some strange case, not worth bothering about.
17887 if Is_List_Member (N) then
17888 Insert_After (N, Vnode);
17890 end Validate_Unchecked_Conversion;
17892 ------------------------------------
17893 -- Validate_Unchecked_Conversions --
17894 ------------------------------------
17896 procedure Validate_Unchecked_Conversions is
17897 function Is_Null_Array (T : Entity_Id) return Boolean;
17898 -- We want to warn in the case of converting to a wrong-sized array of
17899 -- bytes, including the zero-size case. This returns True in that case,
17900 -- which is necessary because a size of 0 is used to indicate both an
17901 -- unknown size and a size of 0. It's OK for this to return True in
17902 -- other zero-size cases, but we don't go out of our way; for example,
17903 -- we don't bother with multidimensional arrays.
17905 function Is_Null_Array (T : Entity_Id) return Boolean is
17907 if Is_Array_Type (T) and then Is_Constrained (T) then
17909 Index : constant Node_Id := First_Index (T);
17910 R : Node_Id; -- N_Range
17912 case Nkind (Index) is
17915 when N_Subtype_Indication =>
17916 R := Range_Expression (Constraint (Index));
17917 when N_Identifier | N_Expanded_Name =>
17918 R := Scalar_Range (Entity (Index));
17920 raise Program_Error;
17923 return Is_Null_Range (Low_Bound (R), High_Bound (R));
17931 for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop
17933 T : UC_Entry renames Unchecked_Conversions.Table (N);
17935 Act_Unit : constant Entity_Id := T.Act_Unit;
17936 Eloc : constant Source_Ptr := T.Eloc;
17937 Source : constant Entity_Id := T.Source;
17938 Target : constant Entity_Id := T.Target;
17944 -- Skip if function marked as warnings off
17946 if Has_Warnings_Off (Act_Unit)
17947 or else Serious_Errors_Detected > 0
17952 -- Don't do the check if warnings off for either type, note the
17953 -- deliberate use of OR here instead of OR ELSE to get the flag
17954 -- Warnings_Off_Used set for both types if appropriate.
17956 if Has_Warnings_Off (Source) or Has_Warnings_Off (Target) then
17960 if (Known_Static_RM_Size (Source)
17961 and then Known_Static_RM_Size (Target))
17962 or else Is_Null_Array (Target)
17964 -- This validation check, which warns if we have unequal sizes
17965 -- for unchecked conversion, and thus implementation dependent
17966 -- semantics, is one of the few occasions on which we use the
17967 -- official RM size instead of Esize. See description in Einfo
17968 -- "Handling of Type'Size Values" for details.
17970 Source_Siz := RM_Size (Source);
17971 Target_Siz := RM_Size (Target);
17973 if Present (Source_Siz) and then Present (Target_Siz)
17974 and then Source_Siz /= Target_Siz
17977 ("?z?types for unchecked conversion have different sizes!",
17980 if All_Errors_Mode then
17981 Error_Msg_Name_1 := Chars (Source);
17982 Error_Msg_Uint_1 := Source_Siz;
17983 Error_Msg_Name_2 := Chars (Target);
17984 Error_Msg_Uint_2 := Target_Siz;
17985 Error_Msg ("\size of % is ^, size of % is ^?z?", Eloc);
17987 Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz);
17989 if Is_Discrete_Type (Source)
17991 Is_Discrete_Type (Target)
17993 if Source_Siz > Target_Siz then
17995 ("\?z?^ high order bits of source will "
17996 & "be ignored!", Eloc);
17998 elsif Is_Unsigned_Type (Source) then
18000 ("\?z?source will be extended with ^ high order "
18001 & "zero bits!", Eloc);
18005 ("\?z?source will be extended with ^ high order "
18006 & "sign bits!", Eloc);
18009 elsif Source_Siz < Target_Siz then
18010 if Is_Discrete_Type (Target) then
18011 if Bytes_Big_Endian then
18013 ("\?z?target value will include ^ undefined "
18014 & "low order bits!", Eloc, Act_Unit);
18017 ("\?z?target value will include ^ undefined "
18018 & "high order bits!", Eloc, Act_Unit);
18023 ("\?z?^ trailing bits of target value will be "
18024 & "undefined!", Eloc, Act_Unit);
18027 else pragma Assert (Source_Siz > Target_Siz);
18028 if Is_Discrete_Type (Source) then
18029 if Bytes_Big_Endian then
18031 ("\?z?^ low order bits of source will be "
18032 & "ignored!", Eloc, Act_Unit);
18035 ("\?z?^ high order bits of source will be "
18036 & "ignored!", Eloc, Act_Unit);
18041 ("\?z?^ trailing bits of source will be "
18042 & "ignored!", Eloc, Act_Unit);
18049 -- If both types are access types, we need to check the alignment.
18050 -- If the alignment of both is specified, we can do it here.
18052 if Serious_Errors_Detected = 0
18053 and then Is_Access_Type (Source)
18054 and then Is_Access_Type (Target)
18055 and then Target_Strict_Alignment
18056 and then Present (Designated_Type (Source))
18057 and then Present (Designated_Type (Target))
18060 D_Source : constant Entity_Id := Designated_Type (Source);
18061 D_Target : constant Entity_Id := Designated_Type (Target);
18064 if Known_Alignment (D_Source)
18066 Known_Alignment (D_Target)
18069 Source_Align : constant Uint := Alignment (D_Source);
18070 Target_Align : constant Uint := Alignment (D_Target);
18073 if Source_Align < Target_Align
18074 and then not Is_Tagged_Type (D_Source)
18076 -- Suppress warning if warnings suppressed on either
18077 -- type or either designated type. Note the use of
18078 -- OR here instead of OR ELSE. That is intentional,
18079 -- we would like to set flag Warnings_Off_Used in
18080 -- all types for which warnings are suppressed.
18082 and then not (Has_Warnings_Off (D_Source)
18084 Has_Warnings_Off (D_Target)
18086 Has_Warnings_Off (Source)
18088 Has_Warnings_Off (Target))
18090 Error_Msg_Uint_1 := Target_Align;
18091 Error_Msg_Uint_2 := Source_Align;
18092 Error_Msg_Node_1 := D_Target;
18093 Error_Msg_Node_2 := D_Source;
18095 ("?z?alignment of & (^) is stricter than "
18096 & "alignment of & (^)!", Eloc, Act_Unit);
18098 ("\?z?resulting access value may have invalid "
18099 & "alignment!", Eloc, Act_Unit);
18110 end Validate_Unchecked_Conversions;