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 Aspects
; use Aspects
;
27 with Atree
; use Atree
;
28 with Checks
; use Checks
;
29 with Einfo
; use Einfo
;
30 with Einfo
.Utils
; use Einfo
.Utils
;
31 with Elists
; use Elists
;
32 with Errout
; use Errout
;
33 with Expander
; use Expander
;
34 with Exp_Ch6
; use Exp_Ch6
;
35 with Exp_Tss
; use Exp_Tss
;
36 with Exp_Util
; use Exp_Util
;
37 with Freeze
; use Freeze
;
38 with Itypes
; use Itypes
;
40 with Lib
.Xref
; use Lib
.Xref
;
41 with Namet
; use Namet
;
42 with Namet
.Sp
; use Namet
.Sp
;
43 with Nmake
; use Nmake
;
44 with Nlists
; use Nlists
;
46 with Restrict
; use Restrict
;
47 with Rident
; use Rident
;
49 with Sem_Aux
; use Sem_Aux
;
50 with Sem_Case
; use Sem_Case
;
51 with Sem_Cat
; use Sem_Cat
;
52 with Sem_Ch3
; use Sem_Ch3
;
53 with Sem_Ch8
; use Sem_Ch8
;
54 with Sem_Ch13
; use Sem_Ch13
;
55 with Sem_Dim
; use Sem_Dim
;
56 with Sem_Eval
; use Sem_Eval
;
57 with Sem_Res
; use Sem_Res
;
58 with Sem_Util
; use Sem_Util
;
59 with Sem_Type
; use Sem_Type
;
60 with Sem_Warn
; use Sem_Warn
;
61 with Sinfo
; use Sinfo
;
62 with Sinfo
.Nodes
; use Sinfo
.Nodes
;
63 with Sinfo
.Utils
; use Sinfo
.Utils
;
64 with Snames
; use Snames
;
65 with Stringt
; use Stringt
;
66 with Stand
; use Stand
;
67 with Style
; use Style
;
68 with Targparm
; use Targparm
;
69 with Tbuild
; use Tbuild
;
70 with Ttypes
; use Ttypes
;
71 with Uintp
; use Uintp
;
72 with Warnsw
; use Warnsw
;
74 package body Sem_Aggr
is
76 type Case_Bounds
is record
78 -- Low bound of choice. Once we sort the Case_Table, then entries
79 -- will be in order of ascending Choice_Lo values.
82 -- High Bound of choice. The sort does not pay any attention to the
83 -- high bound, so choices 1 .. 4 and 1 .. 5 could be in either order.
86 -- If there are duplicates or missing entries, then in the sorted
87 -- table, this records the highest value among Choice_Hi values
88 -- seen so far, including this entry.
91 -- The node of the choice
94 type Case_Table_Type
is array (Pos
range <>) of Case_Bounds
;
95 -- Table type used by Check_Case_Choices procedure
97 -----------------------
98 -- Local Subprograms --
99 -----------------------
101 procedure Sort_Case_Table
(Case_Table
: in out Case_Table_Type
);
102 -- Sort the Case Table using the Lower Bound of each Choice as the key. A
103 -- simple insertion sort is used since the choices in a case statement will
104 -- usually be in near sorted order.
106 procedure Check_Can_Never_Be_Null
(Typ
: Entity_Id
; Expr
: Node_Id
);
107 -- Ada 2005 (AI-231): Check bad usage of null for a component for which
108 -- null exclusion (NOT NULL) is specified. Typ can be an E_Array_Type for
109 -- the array case (the component type of the array will be used) or an
110 -- E_Component/E_Discriminant entity in the record case, in which case the
111 -- type of the component will be used for the test. If Typ is any other
112 -- kind of entity, the call is ignored. Expr is the component node in the
113 -- aggregate which is known to have a null value. A warning message will be
114 -- issued if the component is null excluding.
116 -- It would be better to pass the proper type for Typ ???
118 procedure Check_Expr_OK_In_Limited_Aggregate
(Expr
: Node_Id
);
119 -- Check that Expr is either not limited or else is one of the cases of
120 -- expressions allowed for a limited component association (namely, an
121 -- aggregate, function call, or <> notation). Report error for violations.
122 -- Expression is also OK in an instance or inlining context, because we
123 -- have already preanalyzed and it is known to be type correct.
125 ------------------------------------------------------
126 -- Subprograms used for RECORD AGGREGATE Processing --
127 ------------------------------------------------------
129 procedure Resolve_Record_Aggregate
(N
: Node_Id
; Typ
: Entity_Id
);
130 -- This procedure performs all the semantic checks required for record
131 -- aggregates. Note that for aggregates analysis and resolution go
132 -- hand in hand. Aggregate analysis has been delayed up to here and
133 -- it is done while resolving the aggregate.
135 -- N is the N_Aggregate node.
136 -- Typ is the record type for the aggregate resolution
138 -- While performing the semantic checks, this procedure builds a new
139 -- Component_Association_List where each record field appears alone in a
140 -- Component_Choice_List along with its corresponding expression. The
141 -- record fields in the Component_Association_List appear in the same order
142 -- in which they appear in the record type Typ.
144 -- Once this new Component_Association_List is built and all the semantic
145 -- checks performed, the original aggregate subtree is replaced with the
146 -- new named record aggregate just built. This new record aggregate has no
147 -- positional associations, so its Expressions field is set to No_List.
148 -- Note that subtree substitution is performed with Rewrite so as to be
149 -- able to retrieve the original aggregate.
151 -- The aggregate subtree manipulation performed by Resolve_Record_Aggregate
152 -- yields the aggregate format expected by Gigi. Typically, this kind of
153 -- tree manipulations are done in the expander. However, because the
154 -- semantic checks that need to be performed on record aggregates really go
155 -- hand in hand with the record aggregate normalization, the aggregate
156 -- subtree transformation is performed during resolution rather than
157 -- expansion. Had we decided otherwise we would have had to duplicate most
158 -- of the code in the expansion procedure Expand_Record_Aggregate. Note,
159 -- however, that all the expansion concerning aggregates for tagged records
160 -- is done in Expand_Record_Aggregate.
162 -- The algorithm of Resolve_Record_Aggregate proceeds as follows:
164 -- 1. Make sure that the record type against which the record aggregate
165 -- has to be resolved is not abstract. Furthermore if the type is a
166 -- null aggregate make sure the input aggregate N is also null.
168 -- 2. Verify that the structure of the aggregate is that of a record
169 -- aggregate. Specifically, look for component associations and ensure
170 -- that each choice list only has identifiers or the N_Others_Choice
171 -- node. Also make sure that if present, the N_Others_Choice occurs
172 -- last and by itself.
174 -- 3. If Typ contains discriminants, the values for each discriminant is
175 -- looked for. If the record type Typ has variants, we check that the
176 -- expressions corresponding to each discriminant ruling the (possibly
177 -- nested) variant parts of Typ, are static. This allows us to determine
178 -- the variant parts to which the rest of the aggregate must conform.
179 -- The names of discriminants with their values are saved in a new
180 -- association list, New_Assoc_List which is later augmented with the
181 -- names and values of the remaining components in the record type.
183 -- During this phase we also make sure that every discriminant is
184 -- assigned exactly one value. Note that when several values for a given
185 -- discriminant are found, semantic processing continues looking for
186 -- further errors. In this case it's the first discriminant value found
187 -- which we will be recorded.
189 -- IMPORTANT NOTE: For derived tagged types this procedure expects
190 -- First_Discriminant and Next_Discriminant to give the correct list
191 -- of discriminants, in the correct order.
193 -- 4. After all the discriminant values have been gathered, we can set the
194 -- Etype of the record aggregate. If Typ contains no discriminants this
195 -- is straightforward: the Etype of N is just Typ, otherwise a new
196 -- implicit constrained subtype of Typ is built to be the Etype of N.
198 -- 5. Gather the remaining record components according to the discriminant
199 -- values. This involves recursively traversing the record type
200 -- structure to see what variants are selected by the given discriminant
201 -- values. This processing is a little more convoluted if Typ is a
202 -- derived tagged types since we need to retrieve the record structure
203 -- of all the ancestors of Typ.
205 -- 6. After gathering the record components we look for their values in the
206 -- record aggregate and emit appropriate error messages should we not
207 -- find such values or should they be duplicated.
209 -- 7. We then make sure no illegal component names appear in the record
210 -- aggregate and make sure that the type of the record components
211 -- appearing in a same choice list is the same. Finally we ensure that
212 -- the others choice, if present, is used to provide the value of at
213 -- least a record component.
215 -- 8. The original aggregate node is replaced with the new named aggregate
216 -- built in steps 3 through 6, as explained earlier.
218 -- Given the complexity of record aggregate resolution, the primary goal of
219 -- this routine is clarity and simplicity rather than execution and storage
220 -- efficiency. If there are only positional components in the aggregate the
221 -- running time is linear. If there are associations the running time is
222 -- still linear as long as the order of the associations is not too far off
223 -- the order of the components in the record type. If this is not the case
224 -- the running time is at worst quadratic in the size of the association
227 procedure Check_Misspelled_Component
228 (Elements
: Elist_Id
;
229 Component
: Node_Id
);
230 -- Give possible misspelling diagnostic if Component is likely to be a
231 -- misspelling of one of the components of the Assoc_List. This is called
232 -- by Resolve_Aggr_Expr after producing an invalid component error message.
234 -----------------------------------------------------
235 -- Subprograms used for ARRAY AGGREGATE Processing --
236 -----------------------------------------------------
238 function Resolve_Array_Aggregate
241 Index_Constr
: Node_Id
;
242 Component_Typ
: Entity_Id
;
243 Others_Allowed
: Boolean) return Boolean;
244 -- This procedure performs the semantic checks for an array aggregate.
245 -- True is returned if the aggregate resolution succeeds.
247 -- The procedure works by recursively checking each nested aggregate.
248 -- Specifically, after checking a sub-aggregate nested at the i-th level
249 -- we recursively check all the subaggregates at the i+1-st level (if any).
250 -- Note that aggregates analysis and resolution go hand in hand.
251 -- Aggregate analysis has been delayed up to here and it is done while
252 -- resolving the aggregate.
254 -- N is the current N_Aggregate node to be checked.
256 -- Index is the index node corresponding to the array sub-aggregate that
257 -- we are currently checking (RM 4.3.3 (8)). Its Etype is the
258 -- corresponding index type (or subtype).
260 -- Index_Constr is the node giving the applicable index constraint if
261 -- any (RM 4.3.3 (10)). It "is a constraint provided by certain
262 -- contexts [...] that can be used to determine the bounds of the array
263 -- value specified by the aggregate". If Others_Allowed below is False
264 -- there is no applicable index constraint and this node is set to Index.
266 -- Component_Typ is the array component type.
268 -- Others_Allowed indicates whether an others choice is allowed
269 -- in the context where the top-level aggregate appeared.
271 -- The algorithm of Resolve_Array_Aggregate proceeds as follows:
273 -- 1. Make sure that the others choice, if present, is by itself and
274 -- appears last in the sub-aggregate. Check that we do not have
275 -- positional and named components in the array sub-aggregate (unless
276 -- the named association is an others choice). Finally if an others
277 -- choice is present, make sure it is allowed in the aggregate context.
279 -- 2. If the array sub-aggregate contains discrete_choices:
281 -- (A) Verify their validity. Specifically verify that:
283 -- (a) If a null range is present it must be the only possible
284 -- choice in the array aggregate.
286 -- (b) Ditto for a non static range.
288 -- (c) Ditto for a non static expression.
290 -- In addition this step analyzes and resolves each discrete_choice,
291 -- making sure that its type is the type of the corresponding Index.
292 -- If we are not at the lowest array aggregate level (in the case of
293 -- multi-dimensional aggregates) then invoke Resolve_Array_Aggregate
294 -- recursively on each component expression. Otherwise, resolve the
295 -- bottom level component expressions against the expected component
296 -- type ONLY IF the component corresponds to a single discrete choice
297 -- which is not an others choice (to see why read the DELAYED
298 -- COMPONENT RESOLUTION below).
300 -- (B) Determine the bounds of the sub-aggregate and lowest and
301 -- highest choice values.
303 -- 3. For positional aggregates:
305 -- (A) Loop over the component expressions either recursively invoking
306 -- Resolve_Array_Aggregate on each of these for multi-dimensional
307 -- array aggregates or resolving the bottom level component
308 -- expressions against the expected component type.
310 -- (B) Determine the bounds of the positional sub-aggregates.
312 -- 4. Try to determine statically whether the evaluation of the array
313 -- sub-aggregate raises Constraint_Error. If yes emit proper
314 -- warnings. The precise checks are the following:
316 -- (A) Check that the index range defined by aggregate bounds is
317 -- compatible with corresponding index subtype.
318 -- We also check against the base type. In fact it could be that
319 -- Low/High bounds of the base type are static whereas those of
320 -- the index subtype are not. Thus if we can statically catch
321 -- a problem with respect to the base type we are guaranteed
322 -- that the same problem will arise with the index subtype
324 -- (B) If we are dealing with a named aggregate containing an others
325 -- choice and at least one discrete choice then make sure the range
326 -- specified by the discrete choices does not overflow the
327 -- aggregate bounds. We also check against the index type and base
328 -- type bounds for the same reasons given in (A).
330 -- (C) If we are dealing with a positional aggregate with an others
331 -- choice make sure the number of positional elements specified
332 -- does not overflow the aggregate bounds. We also check against
333 -- the index type and base type bounds as mentioned in (A).
335 -- Finally construct an N_Range node giving the sub-aggregate bounds.
336 -- Set the Aggregate_Bounds field of the sub-aggregate to be this
337 -- N_Range. The routine Array_Aggr_Subtype below uses such N_Ranges
338 -- to build the appropriate aggregate subtype. Aggregate_Bounds
339 -- information is needed during expansion.
341 -- DELAYED COMPONENT RESOLUTION: The resolution of bottom level component
342 -- expressions in an array aggregate may call Duplicate_Subexpr or some
343 -- other routine that inserts code just outside the outermost aggregate.
344 -- If the array aggregate contains discrete choices or an others choice,
345 -- this may be wrong. Consider for instance the following example.
347 -- type Rec is record
351 -- type Acc_Rec is access Rec;
352 -- Arr : array (1..3) of Acc_Rec := (1 .. 3 => new Rec);
354 -- Then the transformation of "new Rec" that occurs during resolution
355 -- entails the following code modifications
357 -- P7b : constant Acc_Rec := new Rec;
359 -- Arr : array (1..3) of Acc_Rec := (1 .. 3 => P7b);
361 -- This code transformation is clearly wrong, since we need to call
362 -- "new Rec" for each of the 3 array elements. To avoid this problem we
363 -- delay resolution of the components of non positional array aggregates
364 -- to the expansion phase. As an optimization, if the discrete choice
365 -- specifies a single value we do not delay resolution.
367 function Array_Aggr_Subtype
(N
: Node_Id
; Typ
: Entity_Id
) return Entity_Id
;
368 -- This routine returns the type or subtype of an array aggregate.
370 -- N is the array aggregate node whose type we return.
372 -- Typ is the context type in which N occurs.
374 -- This routine creates an implicit array subtype whose bounds are
375 -- those defined by the aggregate. When this routine is invoked
376 -- Resolve_Array_Aggregate has already processed aggregate N. Thus the
377 -- Aggregate_Bounds of each sub-aggregate, is an N_Range node giving the
378 -- sub-aggregate bounds. When building the aggregate itype, this function
379 -- traverses the array aggregate N collecting such Aggregate_Bounds and
380 -- constructs the proper array aggregate itype.
382 -- Note that in the case of multidimensional aggregates each inner
383 -- sub-aggregate corresponding to a given array dimension, may provide a
384 -- different bounds. If it is possible to determine statically that
385 -- some sub-aggregates corresponding to the same index do not have the
386 -- same bounds, then a warning is emitted. If such check is not possible
387 -- statically (because some sub-aggregate bounds are dynamic expressions)
388 -- then this job is left to the expander. In all cases the particular
389 -- bounds that this function will chose for a given dimension is the first
390 -- N_Range node for a sub-aggregate corresponding to that dimension.
392 -- Note that the Raises_Constraint_Error flag of an array aggregate
393 -- whose evaluation is determined to raise CE by Resolve_Array_Aggregate,
394 -- is set in Resolve_Array_Aggregate but the aggregate is not
395 -- immediately replaced with a raise CE. In fact, Array_Aggr_Subtype must
396 -- first construct the proper itype for the aggregate (Gigi needs
397 -- this). After constructing the proper itype we will eventually replace
398 -- the top-level aggregate with a raise CE (done in Resolve_Aggregate).
399 -- Of course in cases such as:
401 -- type Arr is array (integer range <>) of Integer;
402 -- A : Arr := (positive range -1 .. 2 => 0);
404 -- The bounds of the aggregate itype are cooked up to look reasonable
405 -- (in this particular case the bounds will be 1 .. 2).
407 procedure Make_String_Into_Aggregate
(N
: Node_Id
);
408 -- A string literal can appear in a context in which a one dimensional
409 -- array of characters is expected. This procedure simply rewrites the
410 -- string as an aggregate, prior to resolution.
412 function Resolve_Null_Array_Aggregate
(N
: Node_Id
) return Boolean;
413 -- For the Ada 2022 construct, build a subtype with a null range for each
414 -- dimension, using the bounds from the context subtype (if the subtype
415 -- is constrained). If the subtype is unconstrained, then the bounds
416 -- are determined in much the same way as the bounds for a null string
417 -- literal with no applicable index constraint.
419 ---------------------------------
420 -- Delta aggregate processing --
421 ---------------------------------
423 procedure Resolve_Delta_Array_Aggregate
(N
: Node_Id
; Typ
: Entity_Id
);
424 procedure Resolve_Delta_Record_Aggregate
(N
: Node_Id
; Typ
: Entity_Id
);
425 procedure Resolve_Deep_Delta_Assoc
(N
: Node_Id
; Typ
: Entity_Id
);
426 -- Resolve the names/expressions in a component association for
427 -- a deep delta aggregate. Typ is the type of the enclosing object.
429 ------------------------
430 -- Array_Aggr_Subtype --
431 ------------------------
433 function Array_Aggr_Subtype
435 Typ
: Entity_Id
) return Entity_Id
437 Aggr_Dimension
: constant Pos
:= Number_Dimensions
(Typ
);
438 -- Number of aggregate index dimensions
440 Aggr_Range
: array (1 .. Aggr_Dimension
) of Node_Id
:= (others => Empty
);
441 -- Constrained N_Range of each index dimension in our aggregate itype
443 Aggr_Low
: array (1 .. Aggr_Dimension
) of Node_Id
:= (others => Empty
);
444 Aggr_High
: array (1 .. Aggr_Dimension
) of Node_Id
:= (others => Empty
);
445 -- Low and High bounds for each index dimension in our aggregate itype
447 Is_Fully_Positional
: Boolean := True;
449 procedure Collect_Aggr_Bounds
(N
: Node_Id
; Dim
: Pos
);
450 -- N is an array (sub-)aggregate. Dim is the dimension corresponding
451 -- to (sub-)aggregate N. This procedure collects and removes the side
452 -- effects of the constrained N_Range nodes corresponding to each index
453 -- dimension of our aggregate itype. These N_Range nodes are collected
454 -- in Aggr_Range above.
456 -- Likewise collect in Aggr_Low & Aggr_High above the low and high
457 -- bounds of each index dimension. If, when collecting, two bounds
458 -- corresponding to the same dimension are static and found to differ,
459 -- then emit a warning, and mark N as raising Constraint_Error.
461 -------------------------
462 -- Collect_Aggr_Bounds --
463 -------------------------
465 procedure Collect_Aggr_Bounds
(N
: Node_Id
; Dim
: Pos
) is
466 This_Range
: constant Node_Id
:= Aggregate_Bounds
(N
);
467 -- The aggregate range node of this specific sub-aggregate
469 This_Low
: constant Node_Id
:= Low_Bound
(This_Range
);
470 This_High
: constant Node_Id
:= High_Bound
(This_Range
);
471 -- The aggregate bounds of this specific sub-aggregate
477 Remove_Side_Effects
(This_Low
, Variable_Ref
=> True);
478 Remove_Side_Effects
(This_High
, Variable_Ref
=> True);
480 -- Collect the first N_Range for a given dimension that you find.
481 -- For a given dimension they must be all equal anyway.
483 if No
(Aggr_Range
(Dim
)) then
484 Aggr_Low
(Dim
) := This_Low
;
485 Aggr_High
(Dim
) := This_High
;
486 Aggr_Range
(Dim
) := This_Range
;
489 if Compile_Time_Known_Value
(This_Low
) then
490 if not Compile_Time_Known_Value
(Aggr_Low
(Dim
)) then
491 Aggr_Low
(Dim
) := This_Low
;
493 elsif Expr_Value
(This_Low
) /= Expr_Value
(Aggr_Low
(Dim
)) then
494 Set_Raises_Constraint_Error
(N
);
495 Error_Msg_Warn
:= SPARK_Mode
/= On
;
496 Error_Msg_N
("sub-aggregate low bound mismatch<<", N
);
497 Error_Msg_N
("\Constraint_Error [<<", N
);
501 if Compile_Time_Known_Value
(This_High
) then
502 if not Compile_Time_Known_Value
(Aggr_High
(Dim
)) then
503 Aggr_High
(Dim
) := This_High
;
506 Expr_Value
(This_High
) /= Expr_Value
(Aggr_High
(Dim
))
508 Set_Raises_Constraint_Error
(N
);
509 Error_Msg_Warn
:= SPARK_Mode
/= On
;
510 Error_Msg_N
("sub-aggregate high bound mismatch<<", N
);
511 Error_Msg_N
("\Constraint_Error [<<", N
);
516 if Dim
< Aggr_Dimension
then
518 -- Process positional components
520 if Present
(Expressions
(N
)) then
521 Expr
:= First
(Expressions
(N
));
522 while Present
(Expr
) loop
523 Collect_Aggr_Bounds
(Expr
, Dim
+ 1);
528 -- Process component associations
530 if Present
(Component_Associations
(N
)) then
531 Is_Fully_Positional
:= False;
533 Assoc
:= First
(Component_Associations
(N
));
534 while Present
(Assoc
) loop
535 Expr
:= Expression
(Assoc
);
536 Collect_Aggr_Bounds
(Expr
, Dim
+ 1);
541 end Collect_Aggr_Bounds
;
543 -- Array_Aggr_Subtype variables
546 -- The final itype of the overall aggregate
548 Index_Constraints
: constant List_Id
:= New_List
;
549 -- The list of index constraints of the aggregate itype
551 -- Start of processing for Array_Aggr_Subtype
554 -- Make sure that the list of index constraints is properly attached to
555 -- the tree, and then collect the aggregate bounds.
557 -- If no aggregaate bounds have been set, this is an aggregate with
558 -- iterator specifications and a dynamic size to be determined by
559 -- first pass of expanded code.
561 if No
(Aggregate_Bounds
(N
)) then
565 Set_Parent
(Index_Constraints
, N
);
567 -- When resolving a null aggregate we created a list of aggregate bounds
568 -- for the consecutive dimensions. The bounds for the first dimension
569 -- are attached as the Aggregate_Bounds of the aggregate node.
571 if Is_Null_Aggregate
(N
) then
573 This_Range
: Node_Id
:= Aggregate_Bounds
(N
);
575 for J
in 1 .. Aggr_Dimension
loop
576 Aggr_Range
(J
) := This_Range
;
577 Next_Index
(This_Range
);
579 -- Remove bounds from the list, so they can be reattached as
580 -- the First_Index/Next_Index again by the code that also
581 -- handles non-null aggregates.
583 Remove
(Aggr_Range
(J
));
587 Collect_Aggr_Bounds
(N
, 1);
590 -- Build the list of constrained indexes of our aggregate itype
592 for J
in 1 .. Aggr_Dimension
loop
593 Create_Index
: declare
594 Index_Base
: constant Entity_Id
:=
595 Base_Type
(Etype
(Aggr_Range
(J
)));
596 Index_Typ
: Entity_Id
;
599 -- Construct the Index subtype, and associate it with the range
600 -- construct that generates it.
603 Create_Itype
(Subtype_Kind
(Ekind
(Index_Base
)), Aggr_Range
(J
));
605 Set_Etype
(Index_Typ
, Index_Base
);
607 if Is_Character_Type
(Index_Base
) then
608 Set_Is_Character_Type
(Index_Typ
);
611 Set_Size_Info
(Index_Typ
, (Index_Base
));
612 Set_RM_Size
(Index_Typ
, RM_Size
(Index_Base
));
613 Set_First_Rep_Item
(Index_Typ
, First_Rep_Item
(Index_Base
));
614 Set_Scalar_Range
(Index_Typ
, Aggr_Range
(J
));
616 if Is_Discrete_Or_Fixed_Point_Type
(Index_Typ
) then
617 Set_RM_Size
(Index_Typ
, UI_From_Int
(Minimum_Size
(Index_Typ
)));
620 Set_Etype
(Aggr_Range
(J
), Index_Typ
);
622 Append
(Aggr_Range
(J
), To
=> Index_Constraints
);
626 -- Now build the Itype
628 Itype
:= Create_Itype
(E_Array_Subtype
, N
);
630 Set_First_Rep_Item
(Itype
, First_Rep_Item
(Typ
));
631 Set_Convention
(Itype
, Convention
(Typ
));
632 Set_Depends_On_Private
(Itype
, Has_Private_Component
(Typ
));
633 Set_Etype
(Itype
, Base_Type
(Typ
));
634 Set_Has_Alignment_Clause
(Itype
, Has_Alignment_Clause
(Typ
));
635 Set_Is_Aliased
(Itype
, Is_Aliased
(Typ
));
636 Set_Is_Independent
(Itype
, Is_Independent
(Typ
));
637 Set_Depends_On_Private
(Itype
, Depends_On_Private
(Typ
));
639 Copy_Suppress_Status
(Index_Check
, Typ
, Itype
);
640 Copy_Suppress_Status
(Length_Check
, Typ
, Itype
);
642 Set_First_Index
(Itype
, First
(Index_Constraints
));
643 Set_Is_Constrained
(Itype
, True);
644 Set_Is_Internal
(Itype
, True);
646 if Has_Predicates
(Typ
) then
647 Set_Has_Predicates
(Itype
);
649 -- If the base type has a predicate, capture the predicated parent
650 -- or the existing predicate function for SPARK use.
652 if Present
(Predicate_Function
(Typ
)) then
653 Set_Predicate_Function
(Itype
, Predicate_Function
(Typ
));
655 elsif Is_Itype
(Typ
) then
656 Set_Predicated_Parent
(Itype
, Predicated_Parent
(Typ
));
659 Set_Predicated_Parent
(Itype
, Typ
);
663 -- A simple optimization: purely positional aggregates of static
664 -- components should be passed to gigi unexpanded whenever possible, and
665 -- regardless of the staticness of the bounds themselves. Subsequent
666 -- checks in exp_aggr verify that type is not packed, etc.
668 Set_Size_Known_At_Compile_Time
671 and then Comes_From_Source
(N
)
672 and then Size_Known_At_Compile_Time
(Component_Type
(Typ
)));
674 -- We always need a freeze node for a packed array subtype, so that we
675 -- can build the Packed_Array_Impl_Type corresponding to the subtype. If
676 -- expansion is disabled, the packed array subtype is not built, and we
677 -- must not generate a freeze node for the type, or else it will appear
678 -- incomplete to gigi.
681 and then not In_Spec_Expression
682 and then Expander_Active
684 Freeze_Itype
(Itype
, N
);
688 end Array_Aggr_Subtype
;
690 --------------------------------
691 -- Check_Misspelled_Component --
692 --------------------------------
694 procedure Check_Misspelled_Component
695 (Elements
: Elist_Id
;
698 Max_Suggestions
: constant := 2;
700 Nr_Of_Suggestions
: Natural := 0;
701 Suggestion_1
: Entity_Id
:= Empty
;
702 Suggestion_2
: Entity_Id
:= Empty
;
703 Component_Elmt
: Elmt_Id
;
706 -- All the components of List are matched against Component and a count
707 -- is maintained of possible misspellings. When at the end of the
708 -- analysis there are one or two (not more) possible misspellings,
709 -- these misspellings will be suggested as possible corrections.
711 Component_Elmt
:= First_Elmt
(Elements
);
712 while Nr_Of_Suggestions
<= Max_Suggestions
713 and then Present
(Component_Elmt
)
715 if Is_Bad_Spelling_Of
716 (Chars
(Node
(Component_Elmt
)),
719 Nr_Of_Suggestions
:= Nr_Of_Suggestions
+ 1;
721 case Nr_Of_Suggestions
is
722 when 1 => Suggestion_1
:= Node
(Component_Elmt
);
723 when 2 => Suggestion_2
:= Node
(Component_Elmt
);
728 Next_Elmt
(Component_Elmt
);
731 -- Report at most two suggestions
733 if Nr_Of_Suggestions
= 1 then
734 Error_Msg_NE
-- CODEFIX
735 ("\possible misspelling of&", Component
, Suggestion_1
);
737 elsif Nr_Of_Suggestions
= 2 then
738 Error_Msg_Node_2
:= Suggestion_2
;
739 Error_Msg_NE
-- CODEFIX
740 ("\possible misspelling of& or&", Component
, Suggestion_1
);
742 end Check_Misspelled_Component
;
744 ----------------------------------------
745 -- Check_Expr_OK_In_Limited_Aggregate --
746 ----------------------------------------
748 procedure Check_Expr_OK_In_Limited_Aggregate
(Expr
: Node_Id
) is
750 if Is_Limited_Type
(Etype
(Expr
))
751 and then Comes_From_Source
(Expr
)
753 if In_Instance_Body
or else In_Inlined_Body
then
756 elsif not OK_For_Limited_Init
(Etype
(Expr
), Expr
) then
758 ("initialization not allowed for limited types", Expr
);
759 Explain_Limited_Type
(Etype
(Expr
), Expr
);
762 end Check_Expr_OK_In_Limited_Aggregate
;
768 function Is_Deep_Choice
770 Aggr_Type
: Type_Kind_Id
) return Boolean
772 Pref
: Node_Id
:= Choice
;
774 while not Is_Root_Prefix_Of_Deep_Choice
(Pref
) loop
775 Pref
:= Prefix
(Pref
);
778 if Is_Array_Type
(Aggr_Type
) then
779 return Paren_Count
(Pref
) > 0
780 and then Pref
/= Choice
;
782 return Pref
/= Choice
;
786 -------------------------
787 -- Is_Others_Aggregate --
788 -------------------------
790 function Is_Others_Aggregate
(Aggr
: Node_Id
) return Boolean is
791 Assoc
: constant List_Id
:= Component_Associations
(Aggr
);
794 return No
(Expressions
(Aggr
))
795 and then Nkind
(First
(Choice_List
(First
(Assoc
)))) = N_Others_Choice
;
796 end Is_Others_Aggregate
;
798 -----------------------------------
799 -- Is_Root_Prefix_Of_Deep_Choice --
800 -----------------------------------
802 function Is_Root_Prefix_Of_Deep_Choice
(Pref
: Node_Id
) return Boolean is
804 return Paren_Count
(Pref
) > 0
805 or else Nkind
(Pref
) not in N_Indexed_Component
806 | N_Selected_Component
;
807 end Is_Root_Prefix_Of_Deep_Choice
;
809 -------------------------
810 -- Is_Single_Aggregate --
811 -------------------------
813 function Is_Single_Aggregate
(Aggr
: Node_Id
) return Boolean is
814 Assoc
: constant List_Id
:= Component_Associations
(Aggr
);
817 return No
(Expressions
(Aggr
))
818 and then No
(Next
(First
(Assoc
)))
819 and then No
(Next
(First
(Choice_List
(First
(Assoc
)))));
820 end Is_Single_Aggregate
;
822 -----------------------
823 -- Is_Null_Aggregate --
824 -----------------------
826 function Is_Null_Aggregate
(N
: Node_Id
) return Boolean is
828 return Ada_Version
>= Ada_2022
829 and then Is_Homogeneous_Aggregate
(N
)
830 and then Is_Empty_List
(Expressions
(N
))
831 and then Is_Empty_List
(Component_Associations
(N
));
832 end Is_Null_Aggregate
;
834 ----------------------------------------
835 -- Is_Null_Array_Aggregate_High_Bound --
836 ----------------------------------------
838 function Is_Null_Array_Aggregate_High_Bound
(N
: Node_Id
) return Boolean is
839 Original_N
: constant Node_Id
:= Original_Node
(N
);
841 return Ada_Version
>= Ada_2022
842 and then not Comes_From_Source
(Original_N
)
843 and then Nkind
(Original_N
) = N_Attribute_Reference
845 Get_Attribute_Id
(Attribute_Name
(Original_N
)) = Attribute_Pred
846 and then Nkind
(Parent
(N
)) in N_Range | N_Op_Le
847 and then not Comes_From_Source
(Parent
(N
));
848 end Is_Null_Array_Aggregate_High_Bound
;
850 --------------------------------
851 -- Make_String_Into_Aggregate --
852 --------------------------------
854 procedure Make_String_Into_Aggregate
(N
: Node_Id
) is
855 Exprs
: constant List_Id
:= New_List
;
856 Loc
: constant Source_Ptr
:= Sloc
(N
);
857 Str
: constant String_Id
:= Strval
(N
);
858 Strlen
: constant Nat
:= String_Length
(Str
);
866 for J
in 1 .. Strlen
loop
867 C
:= Get_String_Char
(Str
, J
);
868 Set_Character_Literal_Name
(C
);
871 Make_Character_Literal
(P
,
873 Char_Literal_Value
=> UI_From_CC
(C
));
874 Set_Etype
(C_Node
, Any_Character
);
875 Append_To
(Exprs
, C_Node
);
878 -- Something special for wide strings???
881 New_N
:= Make_Aggregate
(Loc
, Expressions
=> Exprs
);
882 Set_Analyzed
(New_N
);
883 Set_Etype
(New_N
, Any_Composite
);
886 end Make_String_Into_Aggregate
;
888 -----------------------
889 -- Resolve_Aggregate --
890 -----------------------
892 procedure Resolve_Aggregate
(N
: Node_Id
; Typ
: Entity_Id
) is
893 Loc
: constant Source_Ptr
:= Sloc
(N
);
895 Aggr_Subtyp
: Entity_Id
;
896 -- The actual aggregate subtype. This is not necessarily the same as Typ
897 -- which is the subtype of the context in which the aggregate was found.
899 Others_Box
: Boolean := False;
900 -- Set to True if N represents a simple aggregate with only
901 -- (others => <>), not nested as part of another aggregate.
903 function Is_Full_Access_Aggregate
(N
: Node_Id
) return Boolean;
904 -- If a full access object is initialized with an aggregate or is
905 -- assigned an aggregate, we have to prevent a piecemeal access or
906 -- assignment to the object, even if the aggregate is to be expanded.
907 -- We create a temporary for the aggregate, and assign the temporary
908 -- instead, so that the back end can generate an atomic move for it.
909 -- This is only done in the context of an object declaration or an
910 -- assignment. Function is a noop and returns false in other contexts.
912 function Within_Aggregate
(N
: Node_Id
) return Boolean;
913 -- Return True if N is part of an N_Aggregate
915 ------------------------------
916 -- Is_Full_Access_Aggregate --
917 ------------------------------
919 function Is_Full_Access_Aggregate
(N
: Node_Id
) return Boolean is
920 Loc
: constant Source_Ptr
:= Sloc
(N
);
930 -- Aggregate may be qualified, so find outer context
932 if Nkind
(Par
) = N_Qualified_Expression
then
936 if not Comes_From_Source
(Par
) then
941 when N_Assignment_Statement
=>
942 Typ
:= Etype
(Name
(Par
));
944 if not Is_Full_Access
(Typ
)
945 and then not Is_Full_Access_Object
(Name
(Par
))
950 when N_Object_Declaration
=>
951 Typ
:= Etype
(Defining_Identifier
(Par
));
953 if not Is_Full_Access
(Typ
)
954 and then not Is_Full_Access
(Defining_Identifier
(Par
))
963 Temp
:= Make_Temporary
(Loc
, 'T', N
);
965 Make_Object_Declaration
(Loc
,
966 Defining_Identifier
=> Temp
,
967 Constant_Present
=> True,
968 Object_Definition
=> New_Occurrence_Of
(Typ
, Loc
),
969 Expression
=> Relocate_Node
(N
));
970 Insert_Action
(Par
, New_N
);
972 Rewrite
(N
, New_Occurrence_Of
(Temp
, Loc
));
973 Analyze_And_Resolve
(N
, Typ
);
976 end Is_Full_Access_Aggregate
;
978 ----------------------
979 -- Within_Aggregate --
980 ----------------------
982 function Within_Aggregate
(N
: Node_Id
) return Boolean is
983 P
: Node_Id
:= Parent
(N
);
985 while Present
(P
) loop
986 if Nkind
(P
) = N_Aggregate
then
994 end Within_Aggregate
;
996 -- Start of processing for Resolve_Aggregate
999 -- Ignore junk empty aggregate resulting from parser error
1001 if No
(Expressions
(N
))
1002 and then No
(Component_Associations
(N
))
1003 and then not Null_Record_Present
(N
)
1007 -- If the aggregate is assigned to a full access variable, we have
1008 -- to prevent a piecemeal assignment even if the aggregate is to be
1009 -- expanded. We create a temporary for the aggregate, and assign the
1010 -- temporary instead, so that the back end can generate an atomic move
1011 -- for it. This is properly an expansion activity but it must be done
1012 -- before resolution because aggregate resolution cannot be done twice.
1014 elsif Expander_Active
and then Is_Full_Access_Aggregate
(N
) then
1018 -- If the aggregate has box-initialized components, its type must be
1019 -- frozen so that initialization procedures can properly be called
1020 -- in the resolution that follows. The replacement of boxes with
1021 -- initialization calls is properly an expansion activity but it must
1022 -- be done during resolution.
1025 and then Present
(Component_Associations
(N
))
1029 First_Comp
: Boolean := True;
1032 Comp
:= First
(Component_Associations
(N
));
1033 while Present
(Comp
) loop
1034 if Box_Present
(Comp
) then
1036 and then No
(Expressions
(N
))
1037 and then Nkind
(First
(Choices
(Comp
))) = N_Others_Choice
1038 and then not Within_Aggregate
(N
)
1043 Insert_Actions
(N
, Freeze_Entity
(Typ
, N
));
1047 First_Comp
:= False;
1053 -- Check for aggregates not allowed in configurable run-time mode.
1054 -- We allow all cases of aggregates that do not come from source, since
1055 -- these are all assumed to be small (e.g. bounds of a string literal).
1056 -- We also allow aggregates of types we know to be small.
1058 if not Support_Aggregates_On_Target
1059 and then Comes_From_Source
(N
)
1060 and then (not Known_Static_Esize
(Typ
)
1061 or else Esize
(Typ
) > System_Max_Integer_Size
)
1063 Error_Msg_CRT
("aggregate", N
);
1066 -- Ada 2005 (AI-287): Limited aggregates allowed
1068 -- In an instance, ignore aggregate subcomponents that may be limited,
1069 -- because they originate in view conflicts. If the original aggregate
1070 -- is legal and the actuals are legal, the aggregate itself is legal.
1072 if Is_Limited_Type
(Typ
)
1073 and then Ada_Version
< Ada_2005
1074 and then not In_Instance
1076 Error_Msg_N
("aggregate type cannot be limited", N
);
1077 Explain_Limited_Type
(Typ
, N
);
1079 elsif Is_Class_Wide_Type
(Typ
) then
1080 Error_Msg_N
("type of aggregate cannot be class-wide", N
);
1082 elsif Typ
= Any_String
1083 or else Typ
= Any_Composite
1085 Error_Msg_N
("no unique type for aggregate", N
);
1086 Set_Etype
(N
, Any_Composite
);
1088 elsif Is_Array_Type
(Typ
) and then Null_Record_Present
(N
) then
1089 Error_Msg_N
("null record forbidden in array aggregate", N
);
1091 elsif Has_Aspect
(Typ
, Aspect_Aggregate
)
1092 and then Ekind
(Typ
) /= E_Record_Type
1093 and then Ada_Version
>= Ada_2022
1095 -- Check for Ada 2022 and () aggregate.
1097 if not Is_Homogeneous_Aggregate
(N
) then
1098 Error_Msg_N
("container aggregate must use '['], not ()", N
);
1101 Resolve_Container_Aggregate
(N
, Typ
);
1103 -- Check Ada 2022 empty aggregate [] initializing a record type that has
1104 -- aspect aggregate; the empty aggregate will be expanded into a call to
1105 -- the empty function specified in the aspect aggregate.
1107 elsif Has_Aspect
(Typ
, Aspect_Aggregate
)
1108 and then Ekind
(Typ
) = E_Record_Type
1109 and then Is_Homogeneous_Aggregate
(N
)
1110 and then Is_Empty_List
(Expressions
(N
))
1111 and then Is_Empty_List
(Component_Associations
(N
))
1112 and then Ada_Version
>= Ada_2022
1114 Resolve_Container_Aggregate
(N
, Typ
);
1116 elsif Is_Record_Type
(Typ
) then
1117 Resolve_Record_Aggregate
(N
, Typ
);
1119 elsif Is_Array_Type
(Typ
) then
1121 -- First a special test, for the case of a positional aggregate of
1122 -- characters which can be replaced by a string literal.
1124 -- Do not perform this transformation if this was a string literal
1125 -- to start with, whose components needed constraint checks, or if
1126 -- the component type is non-static, because it will require those
1127 -- checks and be transformed back into an aggregate. If the index
1128 -- type is not Integer the aggregate may represent a user-defined
1129 -- string type but the context might need the original type so we
1130 -- do not perform the transformation at this point.
1132 if Number_Dimensions
(Typ
) = 1
1133 and then Is_Standard_Character_Type
(Component_Type
(Typ
))
1134 and then No
(Component_Associations
(N
))
1135 and then not Is_Limited_Composite
(Typ
)
1136 and then not Is_Private_Composite
(Typ
)
1137 and then not Is_Bit_Packed_Array
(Typ
)
1138 and then Nkind
(Original_Node
(Parent
(N
))) /= N_String_Literal
1139 and then Is_OK_Static_Subtype
(Component_Type
(Typ
))
1140 and then Base_Type
(Etype
(First_Index
(Typ
))) =
1141 Base_Type
(Standard_Integer
)
1147 Expr
:= First
(Expressions
(N
));
1148 while Present
(Expr
) loop
1149 exit when Nkind
(Expr
) /= N_Character_Literal
;
1156 Expr
:= First
(Expressions
(N
));
1157 while Present
(Expr
) loop
1158 Store_String_Char
(UI_To_CC
(Char_Literal_Value
(Expr
)));
1162 Rewrite
(N
, Make_String_Literal
(Loc
, End_String
));
1164 Analyze_And_Resolve
(N
, Typ
);
1170 -- Here if we have a real aggregate to deal with
1172 Array_Aggregate
: declare
1173 Aggr_Resolved
: Boolean;
1174 Aggr_Typ
: constant Entity_Id
:= Etype
(Typ
);
1175 -- This is the unconstrained array type, which is the type against
1176 -- which the aggregate is to be resolved. Typ itself is the array
1177 -- type of the context which may not be the same subtype as the
1178 -- subtype for the final aggregate.
1180 Is_Null_Aggr
: constant Boolean := Is_Null_Aggregate
(N
);
1183 -- In the following we determine whether an OTHERS choice is
1184 -- allowed inside the array aggregate. The test checks the context
1185 -- in which the array aggregate occurs. If the context does not
1186 -- permit it, or the aggregate type is unconstrained, an OTHERS
1187 -- choice is not allowed (except that it is always allowed on the
1188 -- right-hand side of an assignment statement; in this case the
1189 -- constrainedness of the type doesn't matter, because an array
1190 -- object is always constrained).
1192 -- If expansion is disabled (generic context, or semantics-only
1193 -- mode) actual subtypes cannot be constructed, and the type of an
1194 -- object may be its unconstrained nominal type. However, if the
1195 -- context is an assignment statement, OTHERS is allowed, because
1196 -- the target of the assignment will have a constrained subtype
1197 -- when fully compiled. Ditto if the context is an initialization
1198 -- procedure where a component may have a predicate function that
1199 -- carries the base type.
1201 -- Note that there is no node for Explicit_Actual_Parameter.
1202 -- To test for this context we therefore have to test for node
1203 -- N_Parameter_Association which itself appears only if there is a
1204 -- formal parameter. Consequently we also need to test for
1205 -- N_Procedure_Call_Statement or N_Function_Call.
1207 -- The context may be an N_Reference node, created by expansion.
1208 -- Legality of the others clause was established in the source,
1209 -- so the context is legal.
1211 Set_Etype
(N
, Aggr_Typ
); -- May be overridden later on
1213 if Is_Null_Aggr
then
1215 Aggr_Resolved
:= Resolve_Null_Array_Aggregate
(N
);
1217 elsif Nkind
(Parent
(N
)) = N_Assignment_Statement
1218 or else Inside_Init_Proc
1219 or else (Is_Constrained
(Typ
)
1220 and then Nkind
(Parent
(N
)) in
1221 N_Parameter_Association
1223 | N_Procedure_Call_Statement
1224 | N_Generic_Association
1225 | N_Formal_Object_Declaration
1226 | N_Simple_Return_Statement
1227 | N_Object_Declaration
1228 | N_Component_Declaration
1229 | N_Parameter_Specification
1230 | N_Qualified_Expression
1231 | N_Unchecked_Type_Conversion
1234 | N_Extension_Aggregate
1235 | N_Component_Association
1236 | N_Case_Expression_Alternative
1238 | N_Expression_With_Actions
)
1241 Resolve_Array_Aggregate
1243 Index
=> First_Index
(Aggr_Typ
),
1244 Index_Constr
=> First_Index
(Typ
),
1245 Component_Typ
=> Component_Type
(Typ
),
1246 Others_Allowed
=> True);
1249 Resolve_Array_Aggregate
1251 Index
=> First_Index
(Aggr_Typ
),
1252 Index_Constr
=> First_Index
(Aggr_Typ
),
1253 Component_Typ
=> Component_Type
(Typ
),
1254 Others_Allowed
=> False);
1257 if not Aggr_Resolved
then
1259 -- A parenthesized expression may have been intended as an
1260 -- aggregate, leading to a type error when analyzing the
1261 -- component. This can also happen for a nested component
1262 -- (see Analyze_Aggr_Expr).
1264 if Paren_Count
(N
) > 0 then
1266 ("positional aggregate cannot have one component", N
);
1269 Aggr_Subtyp
:= Any_Composite
;
1272 Aggr_Subtyp
:= Array_Aggr_Subtype
(N
, Typ
);
1275 Set_Etype
(N
, Aggr_Subtyp
);
1276 end Array_Aggregate
;
1278 elsif Is_Private_Type
(Typ
)
1279 and then Present
(Full_View
(Typ
))
1280 and then (In_Inlined_Body
or In_Instance_Body
)
1281 and then Is_Composite_Type
(Full_View
(Typ
))
1283 Resolve
(N
, Full_View
(Typ
));
1286 Error_Msg_N
("illegal context for aggregate", N
);
1289 -- If we can determine statically that the evaluation of the aggregate
1290 -- raises Constraint_Error, then replace the aggregate with an
1291 -- N_Raise_Constraint_Error node, but set the Etype to the right
1292 -- aggregate subtype. Gigi needs this.
1294 if Raises_Constraint_Error
(N
) then
1295 Aggr_Subtyp
:= Etype
(N
);
1297 Make_Raise_Constraint_Error
(Loc
, Reason
=> CE_Range_Check_Failed
));
1298 Set_Raises_Constraint_Error
(N
);
1299 Set_Etype
(N
, Aggr_Subtyp
);
1303 if Warn_On_No_Value_Assigned
1305 and then not Is_Fully_Initialized_Type
(Etype
(N
))
1307 Error_Msg_N
("?v?aggregate not fully initialized", N
);
1310 Check_Function_Writable_Actuals
(N
);
1311 end Resolve_Aggregate
;
1313 -----------------------------
1314 -- Resolve_Array_Aggregate --
1315 -----------------------------
1317 function Resolve_Array_Aggregate
1320 Index_Constr
: Node_Id
;
1321 Component_Typ
: Entity_Id
;
1322 Others_Allowed
: Boolean) return Boolean
1324 Loc
: constant Source_Ptr
:= Sloc
(N
);
1326 Failure
: constant Boolean := False;
1327 Success
: constant Boolean := True;
1329 Index_Typ
: constant Entity_Id
:= Etype
(Index
);
1330 Index_Typ_Low
: constant Node_Id
:= Type_Low_Bound
(Index_Typ
);
1331 Index_Typ_High
: constant Node_Id
:= Type_High_Bound
(Index_Typ
);
1332 -- The type of the index corresponding to the array sub-aggregate along
1333 -- with its low and upper bounds.
1335 Index_Base
: constant Entity_Id
:= Base_Type
(Index_Typ
);
1336 Index_Base_Low
: constant Node_Id
:= Type_Low_Bound
(Index_Base
);
1337 Index_Base_High
: constant Node_Id
:= Type_High_Bound
(Index_Base
);
1338 -- Ditto for the base type
1340 Others_Present
: Boolean := False;
1342 Nb_Choices
: Nat
:= 0;
1343 -- Contains the overall number of named choices in this sub-aggregate
1345 function Add
(Val
: Uint
; To
: Node_Id
) return Node_Id
;
1346 -- Creates a new expression node where Val is added to expression To.
1347 -- Tries to constant fold whenever possible. To must be an already
1348 -- analyzed expression.
1350 procedure Check_Bound
(BH
: Node_Id
; AH
: in out Node_Id
);
1351 -- Checks that AH (the upper bound of an array aggregate) is less than
1352 -- or equal to BH (the upper bound of the index base type). If the check
1353 -- fails, a warning is emitted, the Raises_Constraint_Error flag of N is
1354 -- set, and AH is replaced with a duplicate of BH.
1356 procedure Check_Bounds
(L
, H
: Node_Id
; AL
, AH
: Node_Id
);
1357 -- Checks that range AL .. AH is compatible with range L .. H. Emits a
1358 -- warning if not and sets the Raises_Constraint_Error flag in N.
1360 procedure Check_Length
(L
, H
: Node_Id
; Len
: Uint
);
1361 -- Checks that range L .. H contains at least Len elements. Emits a
1362 -- warning if not and sets the Raises_Constraint_Error flag in N.
1364 function Dynamic_Or_Null_Range
(L
, H
: Node_Id
) return Boolean;
1365 -- Returns True if range L .. H is dynamic or null
1367 procedure Get
(Value
: out Uint
; From
: Node_Id
; OK
: out Boolean);
1368 -- Given expression node From, this routine sets OK to False if it
1369 -- cannot statically evaluate From. Otherwise it stores this static
1370 -- value into Value.
1372 function Resolve_Aggr_Expr
1374 Single_Elmt
: Boolean) return Boolean;
1375 -- Resolves aggregate expression Expr. Returns False if resolution
1376 -- fails. If Single_Elmt is set to False, the expression Expr may be
1377 -- used to initialize several array aggregate elements (this can happen
1378 -- for discrete choices such as "L .. H => Expr" or the OTHERS choice).
1379 -- In this event we do not resolve Expr unless expansion is disabled.
1380 -- To know why, see the DELAYED COMPONENT RESOLUTION note above.
1382 -- NOTE: In the case of "... => <>", we pass the N_Component_Association
1383 -- node as Expr, since there is no Expression and we need a Sloc for the
1386 procedure Resolve_Iterated_Component_Association
1388 Index_Typ
: Entity_Id
);
1391 procedure Warn_On_Null_Component_Association
(Expr
: Node_Id
);
1392 -- Expr is either a conditional expression or a case expression of an
1393 -- iterated component association initializing the aggregate N with
1394 -- components that can never be null. Report warning on associations
1395 -- that may initialize some component with a null value.
1401 function Add
(Val
: Uint
; To
: Node_Id
) return Node_Id
is
1407 if Raises_Constraint_Error
(To
) then
1411 -- First test if we can do constant folding
1413 if Compile_Time_Known_Value
(To
)
1414 or else Nkind
(To
) = N_Integer_Literal
1416 Expr_Pos
:= Make_Integer_Literal
(Loc
, Expr_Value
(To
) + Val
);
1417 Set_Is_Static_Expression
(Expr_Pos
);
1418 Set_Etype
(Expr_Pos
, Etype
(To
));
1419 Set_Analyzed
(Expr_Pos
, Analyzed
(To
));
1421 if not Is_Enumeration_Type
(Index_Typ
) then
1424 -- If we are dealing with enumeration return
1425 -- Index_Typ'Val (Expr_Pos)
1429 Make_Attribute_Reference
1431 Prefix
=> New_Occurrence_Of
(Index_Typ
, Loc
),
1432 Attribute_Name
=> Name_Val
,
1433 Expressions
=> New_List
(Expr_Pos
));
1439 -- If we are here no constant folding possible
1441 if not Is_Enumeration_Type
(Index_Base
) then
1444 Left_Opnd
=> Duplicate_Subexpr
(To
),
1445 Right_Opnd
=> Make_Integer_Literal
(Loc
, Val
));
1447 -- If we are dealing with enumeration return
1448 -- Index_Typ'Val (Index_Typ'Pos (To) + Val)
1452 Make_Attribute_Reference
1454 Prefix
=> New_Occurrence_Of
(Index_Typ
, Loc
),
1455 Attribute_Name
=> Name_Pos
,
1456 Expressions
=> New_List
(Duplicate_Subexpr
(To
)));
1460 Left_Opnd
=> To_Pos
,
1461 Right_Opnd
=> Make_Integer_Literal
(Loc
, Val
));
1464 Make_Attribute_Reference
1466 Prefix
=> New_Occurrence_Of
(Index_Typ
, Loc
),
1467 Attribute_Name
=> Name_Val
,
1468 Expressions
=> New_List
(Expr_Pos
));
1470 -- If the index type has a non standard representation, the
1471 -- attributes 'Val and 'Pos expand into function calls and the
1472 -- resulting expression is considered non-safe for reevaluation
1473 -- by the backend. Relocate it into a constant temporary in order
1474 -- to make it safe for reevaluation.
1476 if Has_Non_Standard_Rep
(Etype
(N
)) then
1481 Def_Id
:= Make_Temporary
(Loc
, 'R', Expr
);
1482 Set_Etype
(Def_Id
, Index_Typ
);
1484 Make_Object_Declaration
(Loc
,
1485 Defining_Identifier
=> Def_Id
,
1486 Object_Definition
=>
1487 New_Occurrence_Of
(Index_Typ
, Loc
),
1488 Constant_Present
=> True,
1489 Expression
=> Relocate_Node
(Expr
)));
1491 Expr
:= New_Occurrence_Of
(Def_Id
, Loc
);
1503 procedure Check_Bound
(BH
: Node_Id
; AH
: in out Node_Id
) is
1511 Get
(Value
=> Val_BH
, From
=> BH
, OK
=> OK_BH
);
1512 Get
(Value
=> Val_AH
, From
=> AH
, OK
=> OK_AH
);
1514 if OK_BH
and then OK_AH
and then Val_BH
< Val_AH
then
1515 Set_Raises_Constraint_Error
(N
);
1516 Error_Msg_Warn
:= SPARK_Mode
/= On
;
1517 Error_Msg_N
("upper bound out of range<<", AH
);
1518 Error_Msg_N
("\Constraint_Error [<<", AH
);
1520 -- You need to set AH to BH or else in the case of enumerations
1521 -- indexes we will not be able to resolve the aggregate bounds.
1523 AH
:= Duplicate_Subexpr
(BH
);
1531 procedure Check_Bounds
(L
, H
: Node_Id
; AL
, AH
: Node_Id
) is
1542 pragma Warnings
(Off
, OK_AL
);
1543 pragma Warnings
(Off
, OK_AH
);
1546 if Raises_Constraint_Error
(N
)
1547 or else Dynamic_Or_Null_Range
(AL
, AH
)
1552 Get
(Value
=> Val_L
, From
=> L
, OK
=> OK_L
);
1553 Get
(Value
=> Val_H
, From
=> H
, OK
=> OK_H
);
1555 Get
(Value
=> Val_AL
, From
=> AL
, OK
=> OK_AL
);
1556 Get
(Value
=> Val_AH
, From
=> AH
, OK
=> OK_AH
);
1558 if OK_L
and then Val_L
> Val_AL
then
1559 Set_Raises_Constraint_Error
(N
);
1560 Error_Msg_Warn
:= SPARK_Mode
/= On
;
1561 Error_Msg_N
("lower bound of aggregate out of range<<", N
);
1562 Error_Msg_N
("\Constraint_Error [<<", N
);
1565 if OK_H
and then Val_H
< Val_AH
then
1566 Set_Raises_Constraint_Error
(N
);
1567 Error_Msg_Warn
:= SPARK_Mode
/= On
;
1568 Error_Msg_N
("upper bound of aggregate out of range<<", N
);
1569 Error_Msg_N
("\Constraint_Error [<<", N
);
1577 procedure Check_Length
(L
, H
: Node_Id
; Len
: Uint
) is
1587 if Raises_Constraint_Error
(N
) then
1591 Get
(Value
=> Val_L
, From
=> L
, OK
=> OK_L
);
1592 Get
(Value
=> Val_H
, From
=> H
, OK
=> OK_H
);
1594 if not OK_L
or else not OK_H
then
1598 -- If null range length is zero
1600 if Val_L
> Val_H
then
1601 Range_Len
:= Uint_0
;
1603 Range_Len
:= Val_H
- Val_L
+ 1;
1606 if Range_Len
< Len
then
1607 Set_Raises_Constraint_Error
(N
);
1608 Error_Msg_Warn
:= SPARK_Mode
/= On
;
1609 Error_Msg_N
("too many elements<<", N
);
1610 Error_Msg_N
("\Constraint_Error [<<", N
);
1614 ---------------------------
1615 -- Dynamic_Or_Null_Range --
1616 ---------------------------
1618 function Dynamic_Or_Null_Range
(L
, H
: Node_Id
) return Boolean is
1626 Get
(Value
=> Val_L
, From
=> L
, OK
=> OK_L
);
1627 Get
(Value
=> Val_H
, From
=> H
, OK
=> OK_H
);
1629 return not OK_L
or else not OK_H
1630 or else not Is_OK_Static_Expression
(L
)
1631 or else not Is_OK_Static_Expression
(H
)
1632 or else Val_L
> Val_H
;
1633 end Dynamic_Or_Null_Range
;
1639 procedure Get
(Value
: out Uint
; From
: Node_Id
; OK
: out Boolean) is
1643 if Compile_Time_Known_Value
(From
) then
1644 Value
:= Expr_Value
(From
);
1646 -- If expression From is something like Some_Type'Val (10) then
1649 elsif Nkind
(From
) = N_Attribute_Reference
1650 and then Attribute_Name
(From
) = Name_Val
1651 and then Compile_Time_Known_Value
(First
(Expressions
(From
)))
1653 Value
:= Expr_Value
(First
(Expressions
(From
)));
1660 -----------------------
1661 -- Resolve_Aggr_Expr --
1662 -----------------------
1664 function Resolve_Aggr_Expr
1666 Single_Elmt
: Boolean) return Boolean
1668 Nxt_Ind
: constant Node_Id
:= Next_Index
(Index
);
1669 Nxt_Ind_Constr
: constant Node_Id
:= Next_Index
(Index_Constr
);
1670 -- Index is the current index corresponding to the expression
1672 Resolution_OK
: Boolean := True;
1673 -- Set to False if resolution of the expression failed
1676 -- Defend against previous errors
1678 if Nkind
(Expr
) = N_Error
1679 or else Error_Posted
(Expr
)
1684 -- If the array type against which we are resolving the aggregate
1685 -- has several dimensions, the expressions nested inside the
1686 -- aggregate must be further aggregates (or strings).
1688 if Present
(Nxt_Ind
) then
1689 if Nkind
(Expr
) /= N_Aggregate
then
1691 -- A string literal can appear where a one-dimensional array
1692 -- of characters is expected. If the literal looks like an
1693 -- operator, it is still an operator symbol, which will be
1694 -- transformed into a string when analyzed.
1696 if Is_Character_Type
(Component_Typ
)
1697 and then No
(Next_Index
(Nxt_Ind
))
1698 and then Nkind
(Expr
) in N_String_Literal | N_Operator_Symbol
1700 -- A string literal used in a multidimensional array
1701 -- aggregate in place of the final one-dimensional
1702 -- aggregate must not be enclosed in parentheses.
1704 if Paren_Count
(Expr
) /= 0 then
1705 Error_Msg_N
("no parenthesis allowed here", Expr
);
1708 Make_String_Into_Aggregate
(Expr
);
1711 Error_Msg_N
("nested array aggregate expected", Expr
);
1713 -- If the expression is parenthesized, this may be
1714 -- a missing component association for a 1-aggregate.
1716 if Paren_Count
(Expr
) > 0 then
1718 ("\if single-component aggregate is intended, "
1719 & "write e.g. (1 ='> ...)", Expr
);
1726 -- If it's "... => <>", nothing to resolve
1728 if Nkind
(Expr
) = N_Component_Association
then
1729 pragma Assert
(Box_Present
(Expr
));
1733 -- Ada 2005 (AI-231): Propagate the type to the nested aggregate.
1734 -- Required to check the null-exclusion attribute (if present).
1735 -- This value may be overridden later on.
1737 Set_Etype
(Expr
, Etype
(N
));
1739 Resolution_OK
:= Resolve_Array_Aggregate
1740 (Expr
, Nxt_Ind
, Nxt_Ind_Constr
, Component_Typ
, Others_Allowed
);
1743 -- If it's "... => <>", nothing to resolve
1745 if Nkind
(Expr
) = N_Component_Association
then
1746 pragma Assert
(Box_Present
(Expr
));
1750 -- Do not resolve the expressions of discrete or others choices
1751 -- unless the expression covers a single component, or the
1752 -- expander is inactive.
1754 -- In SPARK mode, expressions that can perform side effects will
1755 -- be recognized by the gnat2why back-end, and the whole
1756 -- subprogram will be ignored. So semantic analysis can be
1757 -- performed safely.
1760 or else not Expander_Active
1761 or else In_Spec_Expression
1763 Analyze_And_Resolve
(Expr
, Component_Typ
);
1764 Check_Expr_OK_In_Limited_Aggregate
(Expr
);
1765 Check_Non_Static_Context
(Expr
);
1766 Aggregate_Constraint_Checks
(Expr
, Component_Typ
);
1767 Check_Unset_Reference
(Expr
);
1771 -- If an aggregate component has a type with predicates, an explicit
1772 -- predicate check must be applied, as for an assignment statement,
1773 -- because the aggregate might not be expanded into individual
1774 -- component assignments. If the expression covers several components
1775 -- the analysis and the predicate check take place later.
1777 if Has_Predicates
(Component_Typ
)
1778 and then Analyzed
(Expr
)
1780 Apply_Predicate_Check
(Expr
, Component_Typ
);
1783 if Raises_Constraint_Error
(Expr
)
1784 and then Nkind
(Parent
(Expr
)) /= N_Component_Association
1786 Set_Raises_Constraint_Error
(N
);
1789 -- If the expression has been marked as requiring a range check,
1790 -- then generate it here. It's a bit odd to be generating such
1791 -- checks in the analyzer, but harmless since Generate_Range_Check
1792 -- does nothing (other than making sure Do_Range_Check is set) if
1793 -- the expander is not active.
1795 if Do_Range_Check
(Expr
) then
1796 Generate_Range_Check
(Expr
, Component_Typ
, CE_Range_Check_Failed
);
1799 return Resolution_OK
;
1800 end Resolve_Aggr_Expr
;
1802 --------------------------------------------
1803 -- Resolve_Iterated_Component_Association --
1804 --------------------------------------------
1806 procedure Resolve_Iterated_Component_Association
1808 Index_Typ
: Entity_Id
)
1810 Loc
: constant Source_Ptr
:= Sloc
(N
);
1811 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
1813 -----------------------
1814 -- Remove_References --
1815 -----------------------
1817 function Remove_Reference
(N
: Node_Id
) return Traverse_Result
;
1818 -- Remove reference to the entity Id after analysis, so it can be
1819 -- properly reanalyzed after construct is expanded into a loop.
1821 function Remove_Reference
(N
: Node_Id
) return Traverse_Result
is
1823 if Nkind
(N
) = N_Identifier
1824 and then Present
(Entity
(N
))
1825 and then Entity
(N
) = Id
1827 Set_Entity
(N
, Empty
);
1828 Set_Etype
(N
, Empty
);
1830 Set_Analyzed
(N
, False);
1832 end Remove_Reference
;
1834 procedure Remove_References
is new Traverse_Proc
(Remove_Reference
);
1841 Expr
: constant Node_Id
:= Expression
(N
);
1843 -- Start of processing for Resolve_Iterated_Component_Association
1846 Error_Msg_Ada_2022_Feature
("iterated component", Loc
);
1848 -- Create a scope in which to introduce an index, to make it visible
1849 -- for the analysis of component expression.
1851 Scop
:= New_Internal_Entity
(E_Loop
, Current_Scope
, Loc
, 'L');
1852 Set_Etype
(Scop
, Standard_Void_Type
);
1853 Set_Parent
(Scop
, Parent
(N
));
1856 -- If there is iterator specification, then its preanalysis will make
1857 -- the index visible.
1859 if Present
(Iterator_Specification
(N
)) then
1860 Preanalyze
(Iterator_Specification
(N
));
1862 -- Otherwise, analyze discrete choices and make the index visible
1865 -- Insert index name into current scope but don't decorate it yet,
1866 -- so that a premature usage of this name in discrete choices will
1867 -- be nicely diagnosed.
1871 Choice
:= First
(Discrete_Choices
(N
));
1873 while Present
(Choice
) loop
1874 if Nkind
(Choice
) = N_Others_Choice
then
1875 Others_Present
:= True;
1880 -- Choice can be a subtype name, a range, or an expression
1882 if Is_Entity_Name
(Choice
)
1883 and then Is_Type
(Entity
(Choice
))
1885 Base_Type
(Entity
(Choice
)) = Base_Type
(Index_Typ
)
1890 Analyze_And_Resolve
(Choice
, Index_Typ
);
1897 -- Decorate the index variable
1899 Set_Etype
(Id
, Index_Typ
);
1900 Mutate_Ekind
(Id
, E_Variable
);
1901 Set_Is_Not_Self_Hidden
(Id
);
1902 Set_Scope
(Id
, Scop
);
1905 -- Analyze expression without expansion, to verify legality.
1906 -- When generating code, we then remove references to the index
1907 -- variable, because the expression will be analyzed anew after
1908 -- rewritting as a loop with a new index variable; when not
1909 -- generating code we leave the analyzed expression as it is.
1911 Dummy
:= Resolve_Aggr_Expr
(Expr
, Single_Elmt
=> False);
1913 if Operating_Mode
/= Check_Semantics
then
1914 Remove_References
(Expr
);
1917 -- An iterated_component_association may appear in a nested
1918 -- aggregate for a multidimensional structure: preserve the bounds
1919 -- computed for the expression, as well as the anonymous array
1920 -- type generated for it; both are needed during array expansion.
1922 if Nkind
(Expr
) = N_Aggregate
then
1923 Set_Aggregate_Bounds
(Expression
(N
), Aggregate_Bounds
(Expr
));
1924 Set_Etype
(Expression
(N
), Etype
(Expr
));
1928 end Resolve_Iterated_Component_Association
;
1930 ----------------------------------------
1931 -- Warn_On_Null_Component_Association --
1932 ----------------------------------------
1934 procedure Warn_On_Null_Component_Association
(Expr
: Node_Id
) is
1935 Comp_Typ
: constant Entity_Id
:= Component_Type
(Etype
(N
));
1937 procedure Check_Case_Expr
(N
: Node_Id
);
1938 -- Check if a case expression may initialize some component with a
1941 procedure Check_Cond_Expr
(N
: Node_Id
);
1942 -- Check if a conditional expression may initialize some component
1943 -- with a null value.
1945 procedure Check_Expr
(Expr
: Node_Id
);
1946 -- Check if an expression may initialize some component with a
1949 procedure Warn_On_Null_Expression_And_Rewrite
(Null_Expr
: Node_Id
);
1950 -- Report warning on known null expression and replace the expression
1951 -- by a raise constraint error node.
1953 ---------------------
1954 -- Check_Case_Expr --
1955 ---------------------
1957 procedure Check_Case_Expr
(N
: Node_Id
) is
1958 Alt_Node
: Node_Id
:= First
(Alternatives
(N
));
1961 while Present
(Alt_Node
) loop
1962 Check_Expr
(Expression
(Alt_Node
));
1965 end Check_Case_Expr
;
1967 ---------------------
1968 -- Check_Cond_Expr --
1969 ---------------------
1971 procedure Check_Cond_Expr
(N
: Node_Id
) is
1972 If_Expr
: Node_Id
:= N
;
1973 Then_Expr
: Node_Id
;
1974 Else_Expr
: Node_Id
;
1977 Then_Expr
:= Next
(First
(Expressions
(If_Expr
)));
1978 Else_Expr
:= Next
(Then_Expr
);
1980 Check_Expr
(Then_Expr
);
1982 -- Process elsif parts (if any)
1984 while Nkind
(Else_Expr
) = N_If_Expression
loop
1985 If_Expr
:= Else_Expr
;
1986 Then_Expr
:= Next
(First
(Expressions
(If_Expr
)));
1987 Else_Expr
:= Next
(Then_Expr
);
1989 Check_Expr
(Then_Expr
);
1992 if Known_Null
(Else_Expr
) then
1993 Warn_On_Null_Expression_And_Rewrite
(Else_Expr
);
1995 end Check_Cond_Expr
;
2001 procedure Check_Expr
(Expr
: Node_Id
) is
2003 if Known_Null
(Expr
) then
2004 Warn_On_Null_Expression_And_Rewrite
(Expr
);
2006 elsif Nkind
(Expr
) = N_If_Expression
then
2007 Check_Cond_Expr
(Expr
);
2009 elsif Nkind
(Expr
) = N_Case_Expression
then
2010 Check_Case_Expr
(Expr
);
2014 -----------------------------------------
2015 -- Warn_On_Null_Expression_And_Rewrite --
2016 -----------------------------------------
2018 procedure Warn_On_Null_Expression_And_Rewrite
(Null_Expr
: Node_Id
) is
2021 ("(Ada 2005) NULL not allowed in null-excluding component??",
2024 ("\Constraint_Error might be raised at run time??", Null_Expr
);
2026 -- We cannot use Apply_Compile_Time_Constraint_Error because in
2027 -- some cases the components are rewritten and the runtime error
2031 Make_Raise_Constraint_Error
(Sloc
(Null_Expr
),
2032 Reason
=> CE_Access_Check_Failed
));
2034 Set_Etype
(Null_Expr
, Comp_Typ
);
2035 Set_Analyzed
(Null_Expr
);
2036 end Warn_On_Null_Expression_And_Rewrite
;
2038 -- Start of processing for Warn_On_Null_Component_Association
2041 pragma Assert
(Can_Never_Be_Null
(Comp_Typ
));
2043 case Nkind
(Expr
) is
2044 when N_If_Expression
=>
2045 Check_Cond_Expr
(Expr
);
2047 when N_Case_Expression
=>
2048 Check_Case_Expr
(Expr
);
2051 pragma Assert
(False);
2054 end Warn_On_Null_Component_Association
;
2063 Aggr_Low
: Node_Id
:= Empty
;
2064 Aggr_High
: Node_Id
:= Empty
;
2065 -- The actual low and high bounds of this sub-aggregate
2067 Case_Table_Size
: Nat
;
2068 -- Contains the size of the case table needed to sort aggregate choices
2070 Choices_Low
: Node_Id
:= Empty
;
2071 Choices_High
: Node_Id
:= Empty
;
2072 -- The lowest and highest discrete choices values for a named aggregate
2074 Delete_Choice
: Boolean;
2075 -- Used when replacing a subtype choice with predicate by a list
2077 Has_Iterator_Specifications
: Boolean := False;
2078 -- Flag to indicate that all named associations are iterated component
2079 -- associations with iterator specifications, in which case the
2080 -- expansion will create two loops: one to evaluate the size and one
2081 -- to generate the elements (4.3.3 (20.2/5)).
2083 Nb_Elements
: Uint
:= Uint_0
;
2084 -- The number of elements in a positional aggregate
2086 Nb_Discrete_Choices
: Nat
:= 0;
2087 -- The overall number of discrete choices (not counting others choice)
2089 -- Start of processing for Resolve_Array_Aggregate
2092 -- Ignore junk empty aggregate resulting from parser error
2094 if No
(Expressions
(N
))
2095 and then No
(Component_Associations
(N
))
2096 and then not Null_Record_Present
(N
)
2101 -- Disable the warning for GNAT Mode to allow for easier transition.
2103 if Ada_Version_Explicit
>= Ada_2022
2104 and then Warn_On_Obsolescent_Feature
2105 and then not GNAT_Mode
2106 and then not Is_Homogeneous_Aggregate
(N
)
2107 and then not Is_Enum_Array_Aggregate
(N
)
2108 and then Is_Parenthesis_Aggregate
(N
)
2109 and then Nkind
(Parent
(N
)) /= N_Qualified_Expression
2110 and then Comes_From_Source
(N
)
2113 ("?j?array aggregate using () is an" &
2114 " obsolescent syntax, use '['] instead", N
);
2117 -- STEP 1: make sure the aggregate is correctly formatted
2119 if Is_Null_Aggregate
(N
) then
2122 elsif Present
(Component_Associations
(N
)) then
2124 -- Verify that all or none of the component associations
2125 -- include an iterator specification.
2127 Assoc
:= First
(Component_Associations
(N
));
2128 if Nkind
(Assoc
) = N_Iterated_Component_Association
2129 and then Present
(Iterator_Specification
(Assoc
))
2131 -- All other component associations must have an iterator spec.
2134 while Present
(Assoc
) loop
2135 if Nkind
(Assoc
) /= N_Iterated_Component_Association
2136 or else No
(Iterator_Specification
(Assoc
))
2138 Error_Msg_N
("mixed iterated component association"
2139 & " (RM 4.3.3 (17.1/5))",
2147 Has_Iterator_Specifications
:= True;
2150 -- or none of them do.
2153 while Present
(Assoc
) loop
2154 if Nkind
(Assoc
) = N_Iterated_Component_Association
2155 and then Present
(Iterator_Specification
(Assoc
))
2157 Error_Msg_N
("mixed iterated component association"
2158 & " (RM 4.3.3 (17.1/5))",
2168 Assoc
:= First
(Component_Associations
(N
));
2169 while Present
(Assoc
) loop
2170 if Nkind
(Assoc
) = N_Iterated_Component_Association
then
2171 Resolve_Iterated_Component_Association
(Assoc
, Index_Typ
);
2173 elsif Nkind
(Assoc
) /= N_Component_Association
then
2175 ("invalid component association for aggregate", Assoc
);
2179 Choice
:= First
(Choice_List
(Assoc
));
2180 Delete_Choice
:= False;
2181 while Present
(Choice
) loop
2182 if Nkind
(Choice
) = N_Others_Choice
then
2183 Others_Present
:= True;
2185 if Choice
/= First
(Choice_List
(Assoc
))
2186 or else Present
(Next
(Choice
))
2189 ("OTHERS must appear alone in a choice list", Choice
);
2193 if Present
(Next
(Assoc
)) then
2195 ("OTHERS must appear last in an aggregate", Choice
);
2199 if Ada_Version
= Ada_83
2200 and then Assoc
/= First
(Component_Associations
(N
))
2201 and then Nkind
(Parent
(N
)) in
2202 N_Assignment_Statement | N_Object_Declaration
2205 ("(Ada 83) illegal context for OTHERS choice", N
);
2208 elsif Is_Entity_Name
(Choice
) then
2212 E
: constant Entity_Id
:= Entity
(Choice
);
2218 if Is_Type
(E
) and then Has_Predicates
(E
) then
2219 Freeze_Before
(N
, E
);
2221 if Has_Dynamic_Predicate_Aspect
(E
)
2222 or else Has_Ghost_Predicate_Aspect
(E
)
2225 ("subtype& has non-static predicate, not allowed "
2226 & "in aggregate choice", Choice
, E
);
2228 elsif not Is_OK_Static_Subtype
(E
) then
2230 ("non-static subtype& has predicate, not allowed "
2231 & "in aggregate choice", Choice
, E
);
2234 -- If the subtype has a static predicate, replace the
2235 -- original choice with the list of individual values
2236 -- covered by the predicate.
2237 -- This should be deferred to expansion time ???
2239 if Present
(Static_Discrete_Predicate
(E
)) then
2240 Delete_Choice
:= True;
2243 P
:= First
(Static_Discrete_Predicate
(E
));
2244 while Present
(P
) loop
2246 Set_Sloc
(C
, Sloc
(Choice
));
2247 Append_To
(New_Cs
, C
);
2251 Insert_List_After
(Choice
, New_Cs
);
2257 Nb_Choices
:= Nb_Choices
+ 1;
2260 C
: constant Node_Id
:= Choice
;
2265 if Delete_Choice
then
2267 Nb_Choices
:= Nb_Choices
- 1;
2268 Delete_Choice
:= False;
2277 -- At this point we know that the others choice, if present, is by
2278 -- itself and appears last in the aggregate. Check if we have mixed
2279 -- positional and discrete associations (other than the others choice).
2281 if Present
(Expressions
(N
))
2282 and then (Nb_Choices
> 1
2283 or else (Nb_Choices
= 1 and then not Others_Present
))
2286 ("cannot mix named and positional associations in array aggregate",
2287 First
(Choice_List
(First
(Component_Associations
(N
)))));
2291 -- Test for the validity of an others choice if present
2293 if Others_Present
and then not Others_Allowed
then
2295 Others_N
: constant Node_Id
:=
2296 First
(Choice_List
(First
(Component_Associations
(N
))));
2298 Error_Msg_N
("OTHERS choice not allowed here", Others_N
);
2299 Error_Msg_N
("\qualify the aggregate with a constrained subtype "
2300 & "to provide bounds for it", Others_N
);
2305 -- Protect against cascaded errors
2307 if Etype
(Index_Typ
) = Any_Type
then
2311 -- STEP 2: Process named components
2313 if No
(Expressions
(N
)) then
2314 if Others_Present
then
2315 Case_Table_Size
:= Nb_Choices
- 1;
2317 Case_Table_Size
:= Nb_Choices
;
2321 function Empty_Range
(A
: Node_Id
) return Boolean;
2322 -- If an association covers an empty range, some warnings on the
2323 -- expression of the association can be disabled.
2329 function Empty_Range
(A
: Node_Id
) return Boolean is
2333 if Nkind
(A
) = N_Iterated_Component_Association
then
2334 R
:= First
(Discrete_Choices
(A
));
2336 R
:= First
(Choices
(A
));
2339 return No
(Next
(R
))
2340 and then Nkind
(R
) = N_Range
2341 and then Compile_Time_Compare
2342 (Low_Bound
(R
), High_Bound
(R
), False) = GT
;
2349 -- Denote the lowest and highest values in an aggregate choice
2351 S_Low
: Node_Id
:= Empty
;
2352 S_High
: Node_Id
:= Empty
;
2353 -- if a choice in an aggregate is a subtype indication these
2354 -- denote the lowest and highest values of the subtype
2356 Table
: Case_Table_Type
(1 .. Case_Table_Size
);
2357 -- Used to sort all the different choice values
2359 Single_Choice
: Boolean;
2360 -- Set to true every time there is a single discrete choice in a
2361 -- discrete association
2363 Prev_Nb_Discrete_Choices
: Nat
;
2364 -- Used to keep track of the number of discrete choices in the
2365 -- current association.
2367 Errors_Posted_On_Choices
: Boolean := False;
2368 -- Keeps track of whether any choices have semantic errors
2370 -- Start of processing for Step_2
2373 -- STEP 2 (A): Check discrete choices validity
2374 -- No need if this is an element iteration.
2376 Assoc
:= First
(Component_Associations
(N
));
2377 while Present
(Assoc
)
2378 and then Present
(Choice_List
(Assoc
))
2380 Prev_Nb_Discrete_Choices
:= Nb_Discrete_Choices
;
2381 Choice
:= First
(Choice_List
(Assoc
));
2386 if Nkind
(Choice
) = N_Others_Choice
then
2387 Single_Choice
:= False;
2390 -- Test for subtype mark without constraint
2392 elsif Is_Entity_Name
(Choice
) and then
2393 Is_Type
(Entity
(Choice
))
2395 if Base_Type
(Entity
(Choice
)) /= Index_Base
then
2397 ("invalid subtype mark in aggregate choice",
2402 -- Case of subtype indication
2404 elsif Nkind
(Choice
) = N_Subtype_Indication
then
2405 Resolve_Discrete_Subtype_Indication
(Choice
, Index_Base
);
2407 if Has_Dynamic_Predicate_Aspect
2408 (Entity
(Subtype_Mark
(Choice
)))
2409 or else Has_Ghost_Predicate_Aspect
2410 (Entity
(Subtype_Mark
(Choice
)))
2413 ("subtype& has non-static predicate, "
2414 & "not allowed in aggregate choice",
2415 Choice
, Entity
(Subtype_Mark
(Choice
)));
2418 -- Does the subtype indication evaluation raise CE?
2420 Get_Index_Bounds
(Subtype_Mark
(Choice
), S_Low
, S_High
);
2421 Get_Index_Bounds
(Choice
, Low
, High
);
2422 Check_Bounds
(S_Low
, S_High
, Low
, High
);
2424 -- Case of range or expression
2427 Resolve
(Choice
, Index_Base
);
2428 Check_Unset_Reference
(Choice
);
2429 Check_Non_Static_Context
(Choice
);
2431 -- If semantic errors were posted on the choice, then
2432 -- record that for possible early return from later
2433 -- processing (see handling of enumeration choices).
2435 if Error_Posted
(Choice
) then
2436 Errors_Posted_On_Choices
:= True;
2439 -- Do not range check a choice. This check is redundant
2440 -- since this test is already done when we check that the
2441 -- bounds of the array aggregate are within range.
2443 Set_Do_Range_Check
(Choice
, False);
2446 -- If we could not resolve the discrete choice stop here
2448 if Etype
(Choice
) = Any_Type
then
2451 -- If the discrete choice raises CE get its original bounds
2453 elsif Nkind
(Choice
) = N_Raise_Constraint_Error
then
2454 Set_Raises_Constraint_Error
(N
);
2455 Get_Index_Bounds
(Original_Node
(Choice
), Low
, High
);
2457 -- Otherwise get its bounds as usual
2460 Get_Index_Bounds
(Choice
, Low
, High
);
2463 if (Dynamic_Or_Null_Range
(Low
, High
)
2464 or else (Nkind
(Choice
) = N_Subtype_Indication
2466 Dynamic_Or_Null_Range
(S_Low
, S_High
)))
2467 and then Nb_Choices
/= 1
2470 ("dynamic or empty choice in aggregate "
2471 & "must be the only choice", Choice
);
2475 if not (All_Composite_Constraints_Static
(Low
)
2476 and then All_Composite_Constraints_Static
(High
)
2477 and then All_Composite_Constraints_Static
(S_Low
)
2478 and then All_Composite_Constraints_Static
(S_High
))
2480 Check_Restriction
(No_Dynamic_Sized_Objects
, Choice
);
2483 Nb_Discrete_Choices
:= Nb_Discrete_Choices
+ 1;
2484 Table
(Nb_Discrete_Choices
).Lo
:= Low
;
2485 Table
(Nb_Discrete_Choices
).Hi
:= High
;
2486 Table
(Nb_Discrete_Choices
).Choice
:= Choice
;
2492 -- Check if we have a single discrete choice and whether
2493 -- this discrete choice specifies a single value.
2496 Nb_Discrete_Choices
= Prev_Nb_Discrete_Choices
+ 1
2497 and then Low
= High
;
2503 -- Ada 2005 (AI-231)
2505 if Ada_Version
>= Ada_2005
2506 and then not Empty_Range
(Assoc
)
2508 if Known_Null
(Expression
(Assoc
)) then
2509 Check_Can_Never_Be_Null
(Etype
(N
), Expression
(Assoc
));
2511 -- Report warning on iterated component association that may
2512 -- initialize some component of an array of null-excluding
2513 -- access type components with a null value. For example:
2515 -- type AList is array (...) of not null access Integer;
2517 -- [for J in A'Range =>
2518 -- (if Func (J) = 0 then A(J)'Access else Null)];
2520 elsif Ada_Version
>= Ada_2022
2521 and then Can_Never_Be_Null
(Component_Type
(Etype
(N
)))
2522 and then Nkind
(Assoc
) = N_Iterated_Component_Association
2523 and then Nkind
(Expression
(Assoc
)) in N_If_Expression
2526 Warn_On_Null_Component_Association
(Expression
(Assoc
));
2530 -- Ada 2005 (AI-287): In case of default initialized component
2531 -- we delay the resolution to the expansion phase.
2533 if Box_Present
(Assoc
) then
2535 -- Ada 2005 (AI-287): In case of default initialization of a
2536 -- component the expander will generate calls to the
2537 -- corresponding initialization subprogram. We need to call
2538 -- Resolve_Aggr_Expr to check the rules about
2541 if not Resolve_Aggr_Expr
2542 (Assoc
, Single_Elmt
=> Single_Choice
)
2547 -- ??? Checks for dynamically tagged expressions below will
2548 -- be only applied to iterated_component_association after
2549 -- expansion; in particular, errors might not be reported when
2550 -- -gnatc switch is used.
2552 elsif Nkind
(Assoc
) = N_Iterated_Component_Association
then
2553 null; -- handled above, in a loop context
2555 elsif not Resolve_Aggr_Expr
2556 (Expression
(Assoc
), Single_Elmt
=> Single_Choice
)
2560 -- Check incorrect use of dynamically tagged expression
2562 -- We differentiate here two cases because the expression may
2563 -- not be decorated. For example, the analysis and resolution
2564 -- of the expression associated with the others choice will be
2565 -- done later with the full aggregate. In such case we
2566 -- duplicate the expression tree to analyze the copy and
2567 -- perform the required check.
2569 elsif No
(Etype
(Expression
(Assoc
))) then
2571 Save_Analysis
: constant Boolean := Full_Analysis
;
2572 Expr
: constant Node_Id
:=
2573 New_Copy_Tree
(Expression
(Assoc
));
2576 Expander_Mode_Save_And_Set
(False);
2577 Full_Analysis
:= False;
2579 -- Analyze the expression, making sure it is properly
2580 -- attached to the tree before we do the analysis.
2582 Set_Parent
(Expr
, Parent
(Expression
(Assoc
)));
2585 -- Compute its dimensions now, rather than at the end of
2586 -- resolution, because in the case of multidimensional
2587 -- aggregates subsequent expansion may lead to spurious
2590 Check_Expression_Dimensions
(Expr
, Component_Typ
);
2592 -- If the expression is a literal, propagate this info
2593 -- to the expression in the association, to enable some
2594 -- optimizations downstream.
2596 if Is_Entity_Name
(Expr
)
2597 and then Present
(Entity
(Expr
))
2598 and then Ekind
(Entity
(Expr
)) = E_Enumeration_Literal
2601 (Expression
(Assoc
), Component_Typ
);
2604 Full_Analysis
:= Save_Analysis
;
2605 Expander_Mode_Restore
;
2607 if Is_Tagged_Type
(Etype
(Expr
)) then
2608 Check_Dynamically_Tagged_Expression
2610 Typ
=> Component_Type
(Etype
(N
)),
2615 elsif Is_Tagged_Type
(Etype
(Expression
(Assoc
))) then
2616 Check_Dynamically_Tagged_Expression
2617 (Expr
=> Expression
(Assoc
),
2618 Typ
=> Component_Type
(Etype
(N
)),
2625 -- If aggregate contains more than one choice then these must be
2626 -- static. Check for duplicate and missing values.
2628 -- Note: there is duplicated code here wrt Check_Choice_Set in
2629 -- the body of Sem_Case, and it is possible we could just reuse
2630 -- that procedure. To be checked ???
2632 if Nb_Discrete_Choices
> 1 then
2633 Check_Choices
: declare
2635 -- Location of choice for messages
2639 -- High end of one range and Low end of the next. Should be
2640 -- contiguous if there is no hole in the list of values.
2644 -- End points of duplicated range
2646 Missing_Or_Duplicates
: Boolean := False;
2647 -- Set True if missing or duplicate choices found
2649 procedure Output_Bad_Choices
(Lo
, Hi
: Uint
; C
: Node_Id
);
2650 -- Output continuation message with a representation of the
2651 -- bounds (just Lo if Lo = Hi, else Lo .. Hi). C is the
2652 -- choice node where the message is to be posted.
2654 ------------------------
2655 -- Output_Bad_Choices --
2656 ------------------------
2658 procedure Output_Bad_Choices
(Lo
, Hi
: Uint
; C
: Node_Id
) is
2660 -- Enumeration type case
2662 if Is_Enumeration_Type
(Index_Typ
) then
2664 Chars
(Get_Enum_Lit_From_Pos
(Index_Typ
, Lo
, Loc
));
2666 Chars
(Get_Enum_Lit_From_Pos
(Index_Typ
, Hi
, Loc
));
2669 Error_Msg_N
("\\ %!", C
);
2671 Error_Msg_N
("\\ % .. %!", C
);
2674 -- Integer types case
2677 Error_Msg_Uint_1
:= Lo
;
2678 Error_Msg_Uint_2
:= Hi
;
2681 Error_Msg_N
("\\ ^!", C
);
2683 Error_Msg_N
("\\ ^ .. ^!", C
);
2686 end Output_Bad_Choices
;
2688 -- Start of processing for Check_Choices
2691 Sort_Case_Table
(Table
);
2693 -- First we do a quick linear loop to find out if we have
2694 -- any duplicates or missing entries (usually we have a
2695 -- legal aggregate, so this will get us out quickly).
2697 for J
in 1 .. Nb_Discrete_Choices
- 1 loop
2698 Hi_Val
:= Expr_Value
(Table
(J
).Hi
);
2699 Lo_Val
:= Expr_Value
(Table
(J
+ 1).Lo
);
2702 or else (Lo_Val
> Hi_Val
+ 1
2703 and then not Others_Present
)
2705 Missing_Or_Duplicates
:= True;
2710 -- If we have missing or duplicate entries, first fill in
2711 -- the Highest entries to make life easier in the following
2712 -- loops to detect bad entries.
2714 if Missing_Or_Duplicates
then
2715 Table
(1).Highest
:= Expr_Value
(Table
(1).Hi
);
2717 for J
in 2 .. Nb_Discrete_Choices
loop
2718 Table
(J
).Highest
:=
2720 (Table
(J
- 1).Highest
, Expr_Value
(Table
(J
).Hi
));
2723 -- Loop through table entries to find duplicate indexes
2725 for J
in 2 .. Nb_Discrete_Choices
loop
2726 Lo_Val
:= Expr_Value
(Table
(J
).Lo
);
2727 Hi_Val
:= Expr_Value
(Table
(J
).Hi
);
2729 -- Case where we have duplicates (the lower bound of
2730 -- this choice is less than or equal to the highest
2731 -- high bound found so far).
2733 if Lo_Val
<= Table
(J
- 1).Highest
then
2735 -- We move backwards looking for duplicates. We can
2736 -- abandon this loop as soon as we reach a choice
2737 -- highest value that is less than Lo_Val.
2739 for K
in reverse 1 .. J
- 1 loop
2740 exit when Table
(K
).Highest
< Lo_Val
;
2742 -- Here we may have duplicates between entries
2743 -- for K and J. Get range of duplicates.
2746 UI_Max
(Lo_Val
, Expr_Value
(Table
(K
).Lo
));
2748 UI_Min
(Hi_Val
, Expr_Value
(Table
(K
).Hi
));
2750 -- Nothing to do if duplicate range is null
2752 if Lo_Dup
> Hi_Dup
then
2755 -- Otherwise place proper message
2758 -- We place message on later choice, with a
2759 -- line reference to the earlier choice.
2761 if Sloc
(Table
(J
).Choice
) <
2762 Sloc
(Table
(K
).Choice
)
2764 Choice
:= Table
(K
).Choice
;
2765 Error_Msg_Sloc
:= Sloc
(Table
(J
).Choice
);
2767 Choice
:= Table
(J
).Choice
;
2768 Error_Msg_Sloc
:= Sloc
(Table
(K
).Choice
);
2771 if Lo_Dup
= Hi_Dup
then
2773 ("index value in array aggregate "
2774 & "duplicates the one given#!", Choice
);
2777 ("index values in array aggregate "
2778 & "duplicate those given#!", Choice
);
2781 Output_Bad_Choices
(Lo_Dup
, Hi_Dup
, Choice
);
2787 -- Loop through entries in table to find missing indexes.
2788 -- Not needed if others, since missing impossible.
2790 if not Others_Present
then
2791 for J
in 2 .. Nb_Discrete_Choices
loop
2792 Lo_Val
:= Expr_Value
(Table
(J
).Lo
);
2793 Hi_Val
:= Table
(J
- 1).Highest
;
2795 if Lo_Val
> Hi_Val
+ 1 then
2798 Error_Node
: Node_Id
;
2801 -- If the choice is the bound of a range in
2802 -- a subtype indication, it is not in the
2803 -- source lists for the aggregate itself, so
2804 -- post the error on the aggregate. Otherwise
2805 -- post it on choice itself.
2807 Choice
:= Table
(J
).Choice
;
2809 if Is_List_Member
(Choice
) then
2810 Error_Node
:= Choice
;
2815 if Hi_Val
+ 1 = Lo_Val
- 1 then
2817 ("missing index value "
2818 & "in array aggregate!", Error_Node
);
2821 ("missing index values "
2822 & "in array aggregate!", Error_Node
);
2826 (Hi_Val
+ 1, Lo_Val
- 1, Error_Node
);
2832 -- If either missing or duplicate values, return failure
2834 Set_Etype
(N
, Any_Composite
);
2840 if Has_Iterator_Specifications
then
2841 -- Bounds will be determined dynamically.
2846 -- STEP 2 (B): Compute aggregate bounds and min/max choices values
2848 if Nb_Discrete_Choices
> 0 then
2849 Choices_Low
:= Table
(1).Lo
;
2850 Choices_High
:= Table
(Nb_Discrete_Choices
).Hi
;
2853 -- If Others is present, then bounds of aggregate come from the
2854 -- index constraint (not the choices in the aggregate itself).
2856 if Others_Present
then
2857 Get_Index_Bounds
(Index_Constr
, Aggr_Low
, Aggr_High
);
2859 -- Abandon processing if either bound is already signalled as
2860 -- an error (prevents junk cascaded messages and blow ups).
2862 if Nkind
(Aggr_Low
) = N_Error
2864 Nkind
(Aggr_High
) = N_Error
2869 -- No others clause present
2872 -- Special processing if others allowed and not present. This
2873 -- means that the bounds of the aggregate come from the index
2874 -- constraint (and the length must match).
2876 if Others_Allowed
then
2877 Get_Index_Bounds
(Index_Constr
, Aggr_Low
, Aggr_High
);
2879 -- Abandon processing if either bound is already signalled
2880 -- as an error (stop junk cascaded messages and blow ups).
2882 if Nkind
(Aggr_Low
) = N_Error
2884 Nkind
(Aggr_High
) = N_Error
2889 -- If others allowed, and no others present, then the array
2890 -- should cover all index values. If it does not, we will
2891 -- get a length check warning, but there is two cases where
2892 -- an additional warning is useful:
2894 -- If we have no positional components, and the length is
2895 -- wrong (which we can tell by others being allowed with
2896 -- missing components), and the index type is an enumeration
2897 -- type, then issue appropriate warnings about these missing
2898 -- components. They are only warnings, since the aggregate
2899 -- is fine, it's just the wrong length. We skip this check
2900 -- for standard character types (since there are no literals
2901 -- and it is too much trouble to concoct them), and also if
2902 -- any of the bounds have values that are not known at
2905 -- Another case warranting a warning is when the length
2906 -- is right, but as above we have an index type that is
2907 -- an enumeration, and the bounds do not match. This is a
2908 -- case where dubious sliding is allowed and we generate a
2909 -- warning that the bounds do not match.
2911 if No
(Expressions
(N
))
2912 and then Nkind
(Index
) = N_Range
2913 and then Is_Enumeration_Type
(Etype
(Index
))
2914 and then not Is_Standard_Character_Type
(Etype
(Index
))
2915 and then Compile_Time_Known_Value
(Aggr_Low
)
2916 and then Compile_Time_Known_Value
(Aggr_High
)
2917 and then Compile_Time_Known_Value
(Choices_Low
)
2918 and then Compile_Time_Known_Value
(Choices_High
)
2920 -- If any of the expressions or range bounds in choices
2921 -- have semantic errors, then do not attempt further
2922 -- resolution, to prevent cascaded errors.
2924 if Errors_Posted_On_Choices
then
2929 ALo
: constant Node_Id
:= Expr_Value_E
(Aggr_Low
);
2930 AHi
: constant Node_Id
:= Expr_Value_E
(Aggr_High
);
2931 CLo
: constant Node_Id
:= Expr_Value_E
(Choices_Low
);
2932 CHi
: constant Node_Id
:= Expr_Value_E
(Choices_High
);
2937 -- Warning case 1, missing values at start/end. Only
2938 -- do the check if the number of entries is too small.
2940 if (Enumeration_Pos
(CHi
) - Enumeration_Pos
(CLo
))
2942 (Enumeration_Pos
(AHi
) - Enumeration_Pos
(ALo
))
2945 ("missing index value(s) in array aggregate??",
2948 -- Output missing value(s) at start
2950 if Chars
(ALo
) /= Chars
(CLo
) then
2953 if Chars
(ALo
) = Chars
(Ent
) then
2954 Error_Msg_Name_1
:= Chars
(ALo
);
2955 Error_Msg_N
("\ %??", N
);
2957 Error_Msg_Name_1
:= Chars
(ALo
);
2958 Error_Msg_Name_2
:= Chars
(Ent
);
2959 Error_Msg_N
("\ % .. %??", N
);
2963 -- Output missing value(s) at end
2965 if Chars
(AHi
) /= Chars
(CHi
) then
2968 if Chars
(AHi
) = Chars
(Ent
) then
2969 Error_Msg_Name_1
:= Chars
(Ent
);
2970 Error_Msg_N
("\ %??", N
);
2972 Error_Msg_Name_1
:= Chars
(Ent
);
2973 Error_Msg_Name_2
:= Chars
(AHi
);
2974 Error_Msg_N
("\ % .. %??", N
);
2978 -- Warning case 2, dubious sliding. The First_Subtype
2979 -- test distinguishes between a constrained type where
2980 -- sliding is not allowed (so we will get a warning
2981 -- later that Constraint_Error will be raised), and
2982 -- the unconstrained case where sliding is permitted.
2984 elsif (Enumeration_Pos
(CHi
) - Enumeration_Pos
(CLo
))
2986 (Enumeration_Pos
(AHi
) - Enumeration_Pos
(ALo
))
2987 and then Chars
(ALo
) /= Chars
(CLo
)
2989 not Is_Constrained
(First_Subtype
(Etype
(N
)))
2992 ("bounds of aggregate do not match target??", N
);
2998 -- If no others, aggregate bounds come from aggregate
3000 Aggr_Low
:= Choices_Low
;
3001 Aggr_High
:= Choices_High
;
3005 -- STEP 3: Process positional components
3008 -- STEP 3 (A): Process positional elements
3010 Expr
:= First
(Expressions
(N
));
3011 Nb_Elements
:= Uint_0
;
3012 while Present
(Expr
) loop
3013 Nb_Elements
:= Nb_Elements
+ 1;
3015 -- Ada 2005 (AI-231)
3017 if Ada_Version
>= Ada_2005
and then Known_Null
(Expr
) then
3018 Check_Can_Never_Be_Null
(Etype
(N
), Expr
);
3021 if not Resolve_Aggr_Expr
(Expr
, Single_Elmt
=> True) then
3025 -- Check incorrect use of dynamically tagged expression
3027 if Is_Tagged_Type
(Etype
(Expr
)) then
3028 Check_Dynamically_Tagged_Expression
3030 Typ
=> Component_Type
(Etype
(N
)),
3037 if Others_Present
then
3038 Assoc
:= Last
(Component_Associations
(N
));
3040 -- Ada 2005 (AI-231)
3042 if Ada_Version
>= Ada_2005
and then Known_Null
(Assoc
) then
3043 Check_Can_Never_Be_Null
(Etype
(N
), Expression
(Assoc
));
3046 -- Ada 2005 (AI-287): In case of default initialized component,
3047 -- we delay the resolution to the expansion phase.
3049 if Box_Present
(Assoc
) then
3051 -- Ada 2005 (AI-287): In case of default initialization of a
3052 -- component the expander will generate calls to the
3053 -- corresponding initialization subprogram. We need to call
3054 -- Resolve_Aggr_Expr to check the rules about
3057 if not Resolve_Aggr_Expr
(Assoc
, Single_Elmt
=> False) then
3061 elsif not Resolve_Aggr_Expr
(Expression
(Assoc
),
3062 Single_Elmt
=> False)
3066 -- Check incorrect use of dynamically tagged expression. The
3067 -- expression of the others choice has not been resolved yet.
3068 -- In order to diagnose the semantic error we create a duplicate
3069 -- tree to analyze it and perform the check.
3071 elsif Nkind
(Assoc
) /= N_Iterated_Component_Association
then
3073 Save_Analysis
: constant Boolean := Full_Analysis
;
3074 Expr
: constant Node_Id
:=
3075 New_Copy_Tree
(Expression
(Assoc
));
3078 Expander_Mode_Save_And_Set
(False);
3079 Full_Analysis
:= False;
3081 Full_Analysis
:= Save_Analysis
;
3082 Expander_Mode_Restore
;
3084 if Is_Tagged_Type
(Etype
(Expr
)) then
3085 Check_Dynamically_Tagged_Expression
3087 Typ
=> Component_Type
(Etype
(N
)),
3094 -- STEP 3 (B): Compute the aggregate bounds
3096 if Others_Present
then
3097 Get_Index_Bounds
(Index_Constr
, Aggr_Low
, Aggr_High
);
3100 if Others_Allowed
then
3101 Get_Index_Bounds
(Index_Constr
, Aggr_Low
, Discard
);
3103 Aggr_Low
:= Index_Typ_Low
;
3106 Aggr_High
:= Add
(Nb_Elements
- 1, To
=> Aggr_Low
);
3107 Check_Bound
(Index_Base_High
, Aggr_High
);
3111 -- STEP 4: Perform static aggregate checks and save the bounds
3115 Check_Bounds
(Index_Typ_Low
, Index_Typ_High
, Aggr_Low
, Aggr_High
);
3116 Check_Bounds
(Index_Base_Low
, Index_Base_High
, Aggr_Low
, Aggr_High
);
3120 if Others_Present
and then Nb_Discrete_Choices
> 0 then
3121 Check_Bounds
(Aggr_Low
, Aggr_High
, Choices_Low
, Choices_High
);
3122 Check_Bounds
(Index_Typ_Low
, Index_Typ_High
,
3123 Choices_Low
, Choices_High
);
3124 Check_Bounds
(Index_Base_Low
, Index_Base_High
,
3125 Choices_Low
, Choices_High
);
3129 elsif Others_Present
and then Nb_Elements
> 0 then
3130 Check_Length
(Aggr_Low
, Aggr_High
, Nb_Elements
);
3131 Check_Length
(Index_Typ_Low
, Index_Typ_High
, Nb_Elements
);
3132 Check_Length
(Index_Base_Low
, Index_Base_High
, Nb_Elements
);
3135 if Raises_Constraint_Error
(Aggr_Low
)
3136 or else Raises_Constraint_Error
(Aggr_High
)
3138 Set_Raises_Constraint_Error
(N
);
3141 Aggr_Low
:= Duplicate_Subexpr
(Aggr_Low
);
3143 -- Do not duplicate Aggr_High if Aggr_High = Aggr_Low + Nb_Elements
3144 -- since the addition node returned by Add is not yet analyzed. Attach
3145 -- to tree and analyze first. Reset analyzed flag to ensure it will get
3146 -- analyzed when it is a literal bound whose type must be properly set.
3148 if Others_Present
or else Nb_Discrete_Choices
> 0 then
3149 Aggr_High
:= Duplicate_Subexpr
(Aggr_High
);
3151 if Etype
(Aggr_High
) = Universal_Integer
then
3152 Set_Analyzed
(Aggr_High
, False);
3156 -- If the aggregate already has bounds attached to it, it means this is
3157 -- a positional aggregate created as an optimization by
3158 -- Exp_Aggr.Convert_To_Positional, so we don't want to change those
3161 if Present
(Aggregate_Bounds
(N
))
3162 and then not Others_Allowed
3163 and then not Comes_From_Source
(N
)
3165 Aggr_Low
:= Low_Bound
(Aggregate_Bounds
(N
));
3166 Aggr_High
:= High_Bound
(Aggregate_Bounds
(N
));
3169 Set_Aggregate_Bounds
3170 (N
, Make_Range
(Loc
, Low_Bound
=> Aggr_Low
, High_Bound
=> Aggr_High
));
3172 -- The bounds may contain expressions that must be inserted upwards.
3173 -- Attach them fully to the tree. After analysis, remove side effects
3174 -- from upper bound, if still needed.
3176 Set_Parent
(Aggregate_Bounds
(N
), N
);
3177 Analyze_And_Resolve
(Aggregate_Bounds
(N
), Index_Typ
);
3178 Check_Unset_Reference
(Aggregate_Bounds
(N
));
3180 if not Others_Present
and then Nb_Discrete_Choices
= 0 then
3182 (Aggregate_Bounds
(N
),
3183 Duplicate_Subexpr
(High_Bound
(Aggregate_Bounds
(N
))));
3186 -- Check the dimensions of each component in the array aggregate
3188 Analyze_Dimension_Array_Aggregate
(N
, Component_Typ
);
3191 end Resolve_Array_Aggregate
;
3193 ---------------------------------
3194 -- Resolve_Container_Aggregate --
3195 ---------------------------------
3197 procedure Resolve_Container_Aggregate
(N
: Node_Id
; Typ
: Entity_Id
) is
3198 procedure Resolve_Iterated_Association
3200 Key_Type
: Entity_Id
;
3201 Elmt_Type
: Entity_Id
);
3202 -- Resolve choices and expression in an iterated component association
3203 -- or an iterated element association, which has a key_expression.
3204 -- This is similar but not identical to the handling of this construct
3205 -- in an array aggregate.
3206 -- For a named container, the type of each choice must be compatible
3207 -- with the key type. For a positional container, the choice must be
3208 -- a subtype indication or an iterator specification that determines
3211 Asp
: constant Node_Id
:= Find_Value_Of_Aspect
(Typ
, Aspect_Aggregate
);
3213 Empty_Subp
: Node_Id
:= Empty
;
3214 Add_Named_Subp
: Node_Id
:= Empty
;
3215 Add_Unnamed_Subp
: Node_Id
:= Empty
;
3216 New_Indexed_Subp
: Node_Id
:= Empty
;
3217 Assign_Indexed_Subp
: Node_Id
:= Empty
;
3219 ----------------------------------
3220 -- Resolve_Iterated_Association --
3221 ----------------------------------
3223 procedure Resolve_Iterated_Association
3225 Key_Type
: Entity_Id
;
3226 Elmt_Type
: Entity_Id
)
3228 Loc
: constant Source_Ptr
:= Sloc
(N
);
3236 Typ
: Entity_Id
:= Empty
;
3239 Error_Msg_Ada_2022_Feature
("iterated component", Loc
);
3241 -- If this is an Iterated_Element_Association then either a
3242 -- an Iterator_Specification or a Loop_Parameter specification
3243 -- is present. In both cases a Key_Expression is present.
3245 if Nkind
(Comp
) = N_Iterated_Element_Association
then
3247 -- Create a temporary scope to avoid some modifications from
3248 -- escaping the Analyze call below. The original Tree will be
3249 -- reanalyzed later.
3251 Ent
:= New_Internal_Entity
3252 (E_Loop
, Current_Scope
, Sloc
(Comp
), 'L');
3253 Set_Etype
(Ent
, Standard_Void_Type
);
3254 Set_Parent
(Ent
, Parent
(Comp
));
3257 if Present
(Loop_Parameter_Specification
(Comp
)) then
3258 Copy
:= Copy_Separate_Tree
(Comp
);
3261 (Loop_Parameter_Specification
(Copy
));
3263 Id_Name
:= Chars
(Defining_Identifier
3264 (Loop_Parameter_Specification
(Comp
)));
3266 Copy
:= Copy_Separate_Tree
(Iterator_Specification
(Comp
));
3269 Id_Name
:= Chars
(Defining_Identifier
3270 (Iterator_Specification
(Comp
)));
3273 -- Key expression must have the type of the key. We analyze
3274 -- a copy of the original expression, because it will be
3275 -- reanalyzed and copied as needed during expansion of the
3276 -- corresponding loop.
3278 Key_Expr
:= Key_Expression
(Comp
);
3279 Analyze_And_Resolve
(New_Copy_Tree
(Key_Expr
), Key_Type
);
3284 elsif Present
(Iterator_Specification
(Comp
)) then
3285 -- Create a temporary scope to avoid some modifications from
3286 -- escaping the Analyze call below. The original Tree will be
3287 -- reanalyzed later.
3289 Ent
:= New_Internal_Entity
3290 (E_Loop
, Current_Scope
, Sloc
(Comp
), 'L');
3291 Set_Etype
(Ent
, Standard_Void_Type
);
3292 Set_Parent
(Ent
, Parent
(Comp
));
3295 Copy
:= Copy_Separate_Tree
(Iterator_Specification
(Comp
));
3297 Chars
(Defining_Identifier
(Iterator_Specification
(Comp
)));
3303 Typ
:= Etype
(Defining_Identifier
(Copy
));
3306 Choice
:= First
(Discrete_Choices
(Comp
));
3308 while Present
(Choice
) loop
3311 -- Choice can be a subtype name, a range, or an expression
3313 if Is_Entity_Name
(Choice
)
3314 and then Is_Type
(Entity
(Choice
))
3315 and then Base_Type
(Entity
(Choice
)) = Base_Type
(Key_Type
)
3319 elsif Present
(Key_Type
) then
3320 Analyze_And_Resolve
(Choice
, Key_Type
);
3323 Typ
:= Etype
(Choice
); -- assume unique for now
3329 Id_Name
:= Chars
(Defining_Identifier
(Comp
));
3332 -- Create a scope in which to introduce an index, which is usually
3333 -- visible in the expression for the component, and needed for its
3336 Id
:= Make_Defining_Identifier
(Sloc
(Comp
), Id_Name
);
3337 Ent
:= New_Internal_Entity
(E_Loop
,
3338 Current_Scope
, Sloc
(Comp
), 'L');
3339 Set_Etype
(Ent
, Standard_Void_Type
);
3340 Set_Parent
(Ent
, Parent
(Comp
));
3343 -- Insert and decorate the loop variable in the current scope.
3344 -- The expression has to be analyzed once the loop variable is
3345 -- directly visible. Mark the variable as referenced to prevent
3346 -- spurious warnings, given that subsequent uses of its name in the
3347 -- expression will reference the internal (synonym) loop variable.
3351 pragma Assert
(Present
(Typ
));
3352 Set_Etype
(Id
, Typ
);
3354 Mutate_Ekind
(Id
, E_Variable
);
3355 Set_Is_Not_Self_Hidden
(Id
);
3356 Set_Scope
(Id
, Ent
);
3357 Set_Referenced
(Id
);
3359 -- Analyze a copy of the expression, to verify legality. We use
3360 -- a copy because the expression will be analyzed anew when the
3361 -- enclosing aggregate is expanded, and the construct is rewritten
3362 -- as a loop with a new index variable.
3364 Expr
:= New_Copy_Tree
(Expression
(Comp
));
3365 Preanalyze_And_Resolve
(Expr
, Elmt_Type
);
3368 end Resolve_Iterated_Association
;
3370 -- Start of processing for Resolve_Container_Aggregate
3373 pragma Assert
(Nkind
(Asp
) = N_Aggregate
);
3376 Parse_Aspect_Aggregate
(Asp
,
3377 Empty_Subp
, Add_Named_Subp
, Add_Unnamed_Subp
,
3378 New_Indexed_Subp
, Assign_Indexed_Subp
);
3380 if Present
(Add_Unnamed_Subp
)
3381 and then No
(New_Indexed_Subp
)
3382 and then Present
(Etype
(Add_Unnamed_Subp
))
3383 and then Etype
(Add_Unnamed_Subp
) /= Any_Type
3386 Elmt_Type
: constant Entity_Id
:=
3388 (First_Formal
(Entity
(Add_Unnamed_Subp
))));
3392 if Present
(Expressions
(N
)) then
3393 -- positional aggregate
3395 Comp
:= First
(Expressions
(N
));
3396 while Present
(Comp
) loop
3397 Analyze_And_Resolve
(Comp
, Elmt_Type
);
3402 -- Empty aggregate, to be replaced by Empty during
3403 -- expansion, or iterated component association.
3405 if Present
(Component_Associations
(N
)) then
3407 Comp
: Node_Id
:= First
(Component_Associations
(N
));
3409 while Present
(Comp
) loop
3411 N_Iterated_Component_Association
3413 Error_Msg_N
("illegal component association "
3414 & "for unnamed container aggregate", Comp
);
3417 Resolve_Iterated_Association
3418 (Comp
, Empty
, Elmt_Type
);
3427 elsif Present
(Add_Named_Subp
)
3428 and then Etype
(Add_Named_Subp
) /= Any_Type
3431 -- Retrieves types of container, key, and element from the
3432 -- specified insertion procedure.
3434 Container
: constant Entity_Id
:=
3435 First_Formal
(Entity
(Add_Named_Subp
));
3436 Key_Type
: constant Entity_Id
:= Etype
(Next_Formal
(Container
));
3437 Elmt_Type
: constant Entity_Id
:=
3438 Etype
(Next_Formal
(Next_Formal
(Container
)));
3443 Comp
:= First
(Component_Associations
(N
));
3444 while Present
(Comp
) loop
3445 if Nkind
(Comp
) = N_Component_Association
then
3446 Choice
:= First
(Choices
(Comp
));
3448 while Present
(Choice
) loop
3449 Analyze_And_Resolve
(Choice
, Key_Type
);
3450 if not Is_Static_Expression
(Choice
) then
3451 Error_Msg_N
("choice must be static", Choice
);
3457 Analyze_And_Resolve
(Expression
(Comp
), Elmt_Type
);
3459 elsif Nkind
(Comp
) in
3460 N_Iterated_Component_Association |
3461 N_Iterated_Element_Association
3463 Resolve_Iterated_Association
3464 (Comp
, Key_Type
, Elmt_Type
);
3471 elsif Present
(Assign_Indexed_Subp
)
3472 and then Etype
(Assign_Indexed_Subp
) /= Any_Type
3474 -- Indexed Aggregate. Positional or indexed component
3475 -- can be present, but not both. Choices must be static
3476 -- values or ranges with static bounds.
3479 Container
: constant Entity_Id
:=
3480 First_Formal
(Entity
(Assign_Indexed_Subp
));
3481 Index_Type
: constant Entity_Id
:= Etype
(Next_Formal
(Container
));
3482 Comp_Type
: constant Entity_Id
:=
3483 Etype
(Next_Formal
(Next_Formal
(Container
)));
3486 Num_Choices
: Nat
:= 0;
3491 if Present
(Expressions
(N
)) then
3492 Comp
:= First
(Expressions
(N
));
3493 while Present
(Comp
) loop
3494 Analyze_And_Resolve
(Comp
, Comp_Type
);
3499 if Present
(Component_Associations
(N
))
3500 and then not Is_Empty_List
(Component_Associations
(N
))
3502 if Present
(Expressions
(N
))
3503 and then not Is_Empty_List
(Expressions
(N
))
3505 Error_Msg_N
("container aggregate cannot be "
3506 & "both positional and named", N
);
3510 Comp
:= First
(Component_Associations
(N
));
3512 while Present
(Comp
) loop
3513 if Nkind
(Comp
) = N_Component_Association
then
3514 Choice
:= First
(Choices
(Comp
));
3516 while Present
(Choice
) loop
3517 Analyze_And_Resolve
(Choice
, Index_Type
);
3518 Num_Choices
:= Num_Choices
+ 1;
3522 Analyze_And_Resolve
(Expression
(Comp
), Comp_Type
);
3524 elsif Nkind
(Comp
) in
3525 N_Iterated_Component_Association |
3526 N_Iterated_Element_Association
3528 Resolve_Iterated_Association
3529 (Comp
, Index_Type
, Comp_Type
);
3530 Num_Choices
:= Num_Choices
+ 1;
3536 -- The component associations in an indexed aggregate
3537 -- must denote a contiguous set of static values. We
3538 -- build a table of values/ranges and sort it, as is done
3539 -- elsewhere for case statements and array aggregates.
3540 -- If the aggregate has a single iterated association it
3541 -- is allowed to be nonstatic and there is nothing to check.
3543 if Num_Choices
> 1 then
3545 Table
: Case_Table_Type
(1 .. Num_Choices
);
3546 No_Choice
: Pos
:= 1;
3549 -- Traverse aggregate to determine size of needed table.
3550 -- Verify that bounds are static and that loops have no
3551 -- filters or key expressions.
3554 Comp
:= First
(Component_Associations
(N
));
3555 while Present
(Comp
) loop
3556 if Nkind
(Comp
) = N_Iterated_Element_Association
then
3558 (Loop_Parameter_Specification
(Comp
))
3560 if Present
(Iterator_Filter
3561 (Loop_Parameter_Specification
(Comp
)))
3564 ("iterator filter not allowed " &
3565 "in indexed aggregate", Comp
);
3568 elsif Present
(Key_Expression
3569 (Loop_Parameter_Specification
(Comp
)))
3572 ("key expression not allowed " &
3573 "in indexed aggregate", Comp
);
3579 -- If Nkind is N_Iterated_Component_Association,
3580 -- this corresponds to an iterator_specification
3581 -- with a loop_parameter_specification, and we
3582 -- have to pick up Discrete_Choices. In this case
3583 -- there will be just one "choice", which will
3584 -- typically be a range.
3586 if Nkind
(Comp
) = N_Iterated_Component_Association
3588 Choice
:= First
(Discrete_Choices
(Comp
));
3590 -- Case where there's a list of choices
3593 Choice
:= First
(Choices
(Comp
));
3596 while Present
(Choice
) loop
3597 Get_Index_Bounds
(Choice
, Lo
, Hi
);
3598 Table
(No_Choice
).Choice
:= Choice
;
3599 Table
(No_Choice
).Lo
:= Lo
;
3600 Table
(No_Choice
).Hi
:= Hi
;
3602 -- Verify staticness of value or range
3604 if not Is_Static_Expression
(Lo
)
3605 or else not Is_Static_Expression
(Hi
)
3608 ("nonstatic expression for index " &
3609 "for indexed aggregate", Choice
);
3613 No_Choice
:= No_Choice
+ 1;
3621 Sort_Case_Table
(Table
);
3623 for J
in 1 .. Num_Choices
- 1 loop
3624 Hi_Val
:= Expr_Value
(Table
(J
).Hi
);
3625 Lo_Val
:= Expr_Value
(Table
(J
+ 1).Lo
);
3627 if Lo_Val
= Hi_Val
then
3629 ("duplicate index in indexed aggregate",
3630 Table
(J
+ 1).Choice
);
3633 elsif Lo_Val
< Hi_Val
then
3635 ("overlapping indices in indexed aggregate",
3636 Table
(J
+ 1).Choice
);
3639 elsif Lo_Val
> Hi_Val
+ 1 then
3641 ("missing index values", Table
(J
+ 1).Choice
);
3650 end Resolve_Container_Aggregate
;
3652 -----------------------------
3653 -- Resolve_Delta_Aggregate --
3654 -----------------------------
3656 procedure Resolve_Delta_Aggregate
(N
: Node_Id
; Typ
: Entity_Id
) is
3657 Base
: constant Node_Id
:= Expression
(N
);
3660 Error_Msg_Ada_2022_Feature
("delta aggregate", Sloc
(N
));
3662 if not Is_Composite_Type
(Typ
) then
3663 Error_Msg_N
("not a composite type", N
);
3666 Analyze_And_Resolve
(Base
, Typ
);
3668 if Is_Array_Type
(Typ
) then
3669 -- For an array_delta_aggregate, the base_expression and each
3670 -- expression in every array_component_association shall be of a
3671 -- nonlimited type; RM 4.3.4(13/5). However, to prevent repeated
3672 -- errors we only check the base expression and not array component
3675 if Is_Limited_Type
(Etype
(Base
)) then
3677 ("array delta aggregate shall be of a nonlimited type", Base
);
3678 Explain_Limited_Type
(Etype
(Base
), Base
);
3681 Resolve_Delta_Array_Aggregate
(N
, Typ
);
3684 -- Delta aggregates for record types must use parentheses,
3685 -- not square brackets.
3687 if Is_Homogeneous_Aggregate
(N
) then
3689 ("delta aggregates for record types must use (), not '[']", N
);
3692 -- The base_expression of a record_delta_aggregate can be of a
3693 -- limited type only if it is newly constructed; RM 7.5(2.1/5).
3695 Check_Expr_OK_In_Limited_Aggregate
(Base
);
3697 Resolve_Delta_Record_Aggregate
(N
, Typ
);
3701 end Resolve_Delta_Aggregate
;
3703 -----------------------------------
3704 -- Resolve_Delta_Array_Aggregate --
3705 -----------------------------------
3707 procedure Resolve_Delta_Array_Aggregate
(N
: Node_Id
; Typ
: Entity_Id
) is
3708 Deltas
: constant List_Id
:= Component_Associations
(N
);
3709 Index_Type
: constant Entity_Id
:= Etype
(First_Index
(Typ
));
3715 Deep_Choice_Seen
: Boolean := False;
3718 Assoc
:= First
(Deltas
);
3719 while Present
(Assoc
) loop
3720 if Nkind
(Assoc
) = N_Iterated_Component_Association
then
3721 Choice
:= First
(Choice_List
(Assoc
));
3722 while Present
(Choice
) loop
3723 if Nkind
(Choice
) = N_Others_Choice
then
3725 ("OTHERS not allowed in delta aggregate", Choice
);
3727 elsif Nkind
(Choice
) = N_Subtype_Indication
then
3728 Resolve_Discrete_Subtype_Indication
3729 (Choice
, Base_Type
(Index_Type
));
3732 Analyze_And_Resolve
(Choice
, Index_Type
);
3739 Id
: constant Entity_Id
:= Defining_Identifier
(Assoc
);
3740 Ent
: constant Entity_Id
:=
3742 (E_Loop
, Current_Scope
, Sloc
(Assoc
), 'L');
3745 Set_Etype
(Ent
, Standard_Void_Type
);
3746 Set_Parent
(Ent
, Assoc
);
3749 if No
(Scope
(Id
)) then
3750 Set_Etype
(Id
, Index_Type
);
3751 Mutate_Ekind
(Id
, E_Variable
);
3752 Set_Is_Not_Self_Hidden
(Id
);
3753 Set_Scope
(Id
, Ent
);
3757 -- Resolve a copy of the expression, after setting
3758 -- its parent properly to preserve its context.
3760 Expr
:= New_Copy_Tree
(Expression
(Assoc
));
3761 Set_Parent
(Expr
, Assoc
);
3762 Analyze_And_Resolve
(Expr
, Component_Type
(Typ
));
3767 Choice
:= First
(Choice_List
(Assoc
));
3768 while Present
(Choice
) loop
3769 if Is_Deep_Choice
(Choice
, Typ
) then
3770 pragma Assert
(All_Extensions_Allowed
);
3771 Deep_Choice_Seen
:= True;
3773 -- a deep delta aggregate
3774 Resolve_Deep_Delta_Assoc
(Assoc
, Typ
);
3778 if Nkind
(Choice
) = N_Others_Choice
then
3780 ("OTHERS not allowed in delta aggregate", Choice
);
3782 elsif Is_Entity_Name
(Choice
)
3783 and then Is_Type
(Entity
(Choice
))
3785 -- Choice covers a range of values
3787 if Base_Type
(Entity
(Choice
)) /=
3788 Base_Type
(Index_Type
)
3791 ("choice does not match index type of &",
3795 elsif Nkind
(Choice
) = N_Subtype_Indication
then
3796 Resolve_Discrete_Subtype_Indication
3797 (Choice
, Base_Type
(Index_Type
));
3800 Resolve
(Choice
, Index_Type
);
3807 -- For an array_delta_aggregate, the array_component_association
3808 -- shall not use the box symbol <>; RM 4.3.4(11/5).
3811 (Box_Present
(Assoc
) xor Present
(Expression
(Assoc
)));
3813 if Box_Present
(Assoc
) then
3815 ("'<'> in array delta aggregate is not allowed", Assoc
);
3816 elsif not Deep_Choice_Seen
then
3817 Analyze_And_Resolve
(Expression
(Assoc
), Component_Type
(Typ
));
3823 end Resolve_Delta_Array_Aggregate
;
3825 ------------------------------------
3826 -- Resolve_Delta_Record_Aggregate --
3827 ------------------------------------
3829 procedure Resolve_Delta_Record_Aggregate
(N
: Node_Id
; Typ
: Entity_Id
) is
3831 -- Variables used to verify that discriminant-dependent components
3832 -- appear in the same variant.
3834 Comp_Ref
: Entity_Id
:= Empty
; -- init to avoid warning
3837 procedure Check_Variant
(Id
: Node_Id
);
3838 -- If a given component of the delta aggregate appears in a variant
3839 -- part, verify that it is within the same variant as that of previous
3840 -- specified variant components of the delta.
3842 function Get_Component_Type
3843 (Selector
: Node_Id
; Enclosing_Type
: Entity_Id
) return Entity_Id
;
3844 -- Locate component with a given name and return its type.
3845 -- If none found then report error and return Empty.
3847 function Nested_In
(V1
: Node_Id
; V2
: Node_Id
) return Boolean;
3848 -- Determine whether variant V1 is within variant V2
3850 function Variant_Depth
(N
: Node_Id
) return Natural;
3851 -- Determine the distance of a variant to the enclosing type declaration
3853 --------------------
3855 --------------------
3857 procedure Check_Variant
(Id
: Node_Id
) is
3859 Comp_Variant
: Node_Id
;
3862 if not Has_Discriminants
(Typ
) then
3866 Comp
:= First_Entity
(Typ
);
3867 while Present
(Comp
) loop
3868 exit when Chars
(Comp
) = Chars
(Id
);
3869 Next_Component
(Comp
);
3872 -- Find the variant, if any, whose component list includes the
3873 -- component declaration.
3875 Comp_Variant
:= Parent
(Parent
(List_Containing
(Parent
(Comp
))));
3876 if Nkind
(Comp_Variant
) = N_Variant
then
3877 if No
(Variant
) then
3878 Variant
:= Comp_Variant
;
3881 elsif Variant
/= Comp_Variant
then
3883 D1
: constant Integer := Variant_Depth
(Variant
);
3884 D2
: constant Integer := Variant_Depth
(Comp_Variant
);
3889 (D1
> D2
and then not Nested_In
(Variant
, Comp_Variant
))
3891 (D2
> D1
and then not Nested_In
(Comp_Variant
, Variant
))
3893 pragma Assert
(Present
(Comp_Ref
));
3894 Error_Msg_Node_2
:= Comp_Ref
;
3896 ("& and & appear in different variants", Id
, Comp
);
3898 -- Otherwise retain the deeper variant for subsequent tests
3901 Variant
:= Comp_Variant
;
3908 ------------------------
3909 -- Get_Component_Type --
3910 ------------------------
3912 function Get_Component_Type
3913 (Selector
: Node_Id
; Enclosing_Type
: Entity_Id
) return Entity_Id
3917 case Nkind
(Selector
) is
3918 when N_Selected_Component | N_Indexed_Component
=>
3919 -- a deep delta aggregate choice
3922 Prefix_Type
: constant Entity_Id
:=
3923 Get_Component_Type
(Prefix
(Selector
), Enclosing_Type
);
3925 if No
(Prefix_Type
) then
3926 pragma Assert
(Serious_Errors_Detected
> 0);
3930 -- Set the type of the prefix for GNATprove
3932 Set_Etype
(Prefix
(Selector
), Prefix_Type
);
3934 if Nkind
(Selector
) = N_Selected_Component
then
3935 return Get_Component_Type
3936 (Selector_Name
(Selector
),
3937 Enclosing_Type
=> Prefix_Type
);
3938 elsif not Is_Array_Type
(Prefix_Type
) then
3940 ("type& is not an array type",
3941 Selector
, Prefix_Type
);
3942 elsif Number_Dimensions
(Prefix_Type
) /= 1 then
3944 ("array type& not one-dimensional",
3945 Selector
, Prefix_Type
);
3946 elsif List_Length
(Expressions
(Selector
)) /= 1 then
3948 ("wrong number of indices for array type&",
3949 Selector
, Prefix_Type
);
3952 (First
(Expressions
(Selector
)),
3953 Etype
(First_Index
(Prefix_Type
)));
3954 return Component_Type
(Prefix_Type
);
3962 Comp
:= First_Entity
(Enclosing_Type
);
3963 while Present
(Comp
) loop
3964 if Chars
(Comp
) = Chars
(Selector
) then
3965 if Ekind
(Comp
) = E_Discriminant
then
3966 Error_Msg_N
("delta cannot apply to discriminant", Selector
);
3969 Set_Entity
(Selector
, Comp
);
3970 Set_Etype
(Selector
, Etype
(Comp
));
3972 return Etype
(Comp
);
3979 ("type& has no component with this name", Selector
, Enclosing_Type
);
3981 end Get_Component_Type
;
3987 function Nested_In
(V1
, V2
: Node_Id
) return Boolean is
3992 while Nkind
(Par
) /= N_Full_Type_Declaration
loop
3997 Par
:= Parent
(Par
);
4007 function Variant_Depth
(N
: Node_Id
) return Natural is
4014 while Nkind
(Par
) /= N_Full_Type_Declaration
loop
4016 Par
:= Parent
(Par
);
4024 Deltas
: constant List_Id
:= Component_Associations
(N
);
4028 Comp_Type
: Entity_Id
:= Empty
; -- init to avoid warning
4029 Deep_Choice
: Boolean;
4031 -- Start of processing for Resolve_Delta_Record_Aggregate
4036 Assoc
:= First
(Deltas
);
4037 while Present
(Assoc
) loop
4038 Choice
:= First
(Choice_List
(Assoc
));
4039 while Present
(Choice
) loop
4040 Deep_Choice
:= Nkind
(Choice
) /= N_Identifier
;
4042 Error_Msg_GNAT_Extension
4043 ("deep delta aggregate", Sloc
(Choice
));
4046 Comp_Type
:= Get_Component_Type
4047 (Selector
=> Choice
, Enclosing_Type
=> Typ
);
4049 -- Set the type of the choice for GNATprove
4052 Set_Etype
(Choice
, Comp_Type
);
4055 if Present
(Comp_Type
) then
4056 if not Deep_Choice
then
4057 -- ??? Not clear yet how RM 4.3.1(17.7) applies to a
4058 -- deep delta aggregate.
4059 Check_Variant
(Choice
);
4062 Comp_Type
:= Any_Type
;
4068 pragma Assert
(Present
(Comp_Type
));
4070 -- A record_component_association in record_delta_aggregate shall not
4071 -- use the box compound delimiter <> rather than an expression; see
4072 -- RM 4.3.1(17.3/5).
4074 pragma Assert
(Present
(Expression
(Assoc
)) xor Box_Present
(Assoc
));
4076 if Box_Present
(Assoc
) then
4078 ("'<'> in record delta aggregate is not allowed", Assoc
);
4080 Analyze_And_Resolve
(Expression
(Assoc
), Comp_Type
);
4082 -- The expression must not be of a limited type; RM 4.3.1(17.4/5)
4084 if Is_Limited_Type
(Etype
(Expression
(Assoc
))) then
4086 ("expression of a limited type in record delta aggregate " &
4088 Expression
(Assoc
));
4094 end Resolve_Delta_Record_Aggregate
;
4096 ------------------------------
4097 -- Resolve_Deep_Delta_Assoc --
4098 ------------------------------
4100 procedure Resolve_Deep_Delta_Assoc
(N
: Node_Id
; Typ
: Entity_Id
) is
4101 Choice
: constant Node_Id
:= First
(Choice_List
(N
));
4102 Enclosing_Type
: Entity_Id
:= Typ
;
4104 procedure Resolve_Choice_Prefix
4105 (Choice_Prefix
: Node_Id
; Enclosing_Type
: in out Entity_Id
);
4106 -- Recursively analyze selectors. Enclosing_Type is set to
4107 -- type of the last component.
4109 ---------------------------
4110 -- Resolve_Choice_Prefix --
4111 ---------------------------
4113 procedure Resolve_Choice_Prefix
4114 (Choice_Prefix
: Node_Id
; Enclosing_Type
: in out Entity_Id
)
4116 Selector
: Node_Id
:= Choice_Prefix
;
4118 if not Is_Root_Prefix_Of_Deep_Choice
(Choice_Prefix
) then
4119 Resolve_Choice_Prefix
(Prefix
(Choice_Prefix
), Enclosing_Type
);
4121 if Nkind
(Choice_Prefix
) = N_Selected_Component
then
4122 Selector
:= Selector_Name
(Choice_Prefix
);
4124 pragma Assert
(Nkind
(Choice_Prefix
) = N_Indexed_Component
);
4125 Selector
:= First
(Expressions
(Choice_Prefix
));
4129 if Is_Array_Type
(Enclosing_Type
) then
4130 Analyze_And_Resolve
(Selector
,
4131 Etype
(First_Index
(Enclosing_Type
)));
4132 Enclosing_Type
:= Component_Type
(Enclosing_Type
);
4135 Comp
: Entity_Id
:= First_Entity
(Enclosing_Type
);
4136 Found
: Boolean := False;
4138 while Present
(Comp
) and not Found
loop
4139 if Chars
(Comp
) = Chars
(Selector
) then
4140 if Ekind
(Comp
) = E_Discriminant
then
4141 Error_Msg_N
("delta cannot apply to discriminant",
4145 Set_Entity
(Selector
, Comp
);
4146 Set_Etype
(Selector
, Etype
(Comp
));
4147 Set_Analyzed
(Selector
);
4148 Enclosing_Type
:= Etype
(Comp
);
4155 ("type& has no component with this name",
4156 Selector
, Enclosing_Type
);
4161 -- Set the type of the prefix for GNATprove, except for the root
4162 -- prefix, whose type is already the expected one for a record
4163 -- delta aggregate, or the type of the array index for an
4164 -- array delta aggregate (the only case here really since
4165 -- Resolve_Deep_Delta_Assoc is only called for array delta
4168 if Selector
/= Choice_Prefix
then
4169 Set_Etype
(Choice_Prefix
, Enclosing_Type
);
4171 end Resolve_Choice_Prefix
;
4174 Unimplemented
: exception; -- TEMPORARY
4176 if Present
(Next
(Choice
)) then
4177 raise Unimplemented
;
4181 Resolve_Choice_Prefix
(Choice
, Enclosing_Type
);
4182 Analyze_And_Resolve
(Expression
(N
), Enclosing_Type
);
4183 end Resolve_Deep_Delta_Assoc
;
4185 ---------------------------------
4186 -- Resolve_Extension_Aggregate --
4187 ---------------------------------
4189 -- There are two cases to consider:
4191 -- a) If the ancestor part is a type mark, the components needed are the
4192 -- difference between the components of the expected type and the
4193 -- components of the given type mark.
4195 -- b) If the ancestor part is an expression, it must be unambiguous, and
4196 -- once we have its type we can also compute the needed components as in
4197 -- the previous case. In both cases, if the ancestor type is not the
4198 -- immediate ancestor, we have to build this ancestor recursively.
4200 -- In both cases, discriminants of the ancestor type do not play a role in
4201 -- the resolution of the needed components, because inherited discriminants
4202 -- cannot be used in a type extension. As a result we can compute
4203 -- independently the list of components of the ancestor type and of the
4206 procedure Resolve_Extension_Aggregate
(N
: Node_Id
; Typ
: Entity_Id
) is
4207 A
: constant Node_Id
:= Ancestor_Part
(N
);
4212 function Valid_Limited_Ancestor
(Anc
: Node_Id
) return Boolean;
4213 -- If the type is limited, verify that the ancestor part is a legal
4214 -- expression (aggregate or function call, including 'Input)) that does
4215 -- not require a copy, as specified in 7.5(2).
4217 function Valid_Ancestor_Type
return Boolean;
4218 -- Verify that the type of the ancestor part is a non-private ancestor
4219 -- of the expected type, which must be a type extension.
4221 procedure Transform_BIP_Assignment
(Typ
: Entity_Id
);
4222 -- For an extension aggregate whose ancestor part is a build-in-place
4223 -- call returning a nonlimited type, this is used to transform the
4224 -- assignment to the ancestor part to use a temp.
4226 ----------------------------
4227 -- Valid_Limited_Ancestor --
4228 ----------------------------
4230 function Valid_Limited_Ancestor
(Anc
: Node_Id
) return Boolean is
4232 if Is_Entity_Name
(Anc
) and then Is_Type
(Entity
(Anc
)) then
4235 -- The ancestor must be a call or an aggregate, but a call may
4236 -- have been expanded into a temporary, so check original node.
4238 elsif Nkind
(Anc
) in N_Aggregate
4239 | N_Extension_Aggregate
4244 elsif Nkind
(Original_Node
(Anc
)) = N_Function_Call
then
4247 elsif Nkind
(Anc
) = N_Attribute_Reference
4248 and then Attribute_Name
(Anc
) = Name_Input
4252 elsif Nkind
(Anc
) = N_Qualified_Expression
then
4253 return Valid_Limited_Ancestor
(Expression
(Anc
));
4255 elsif Nkind
(Anc
) = N_Raise_Expression
then
4261 end Valid_Limited_Ancestor
;
4263 -------------------------
4264 -- Valid_Ancestor_Type --
4265 -------------------------
4267 function Valid_Ancestor_Type
return Boolean is
4268 Imm_Type
: Entity_Id
;
4271 Imm_Type
:= Base_Type
(Typ
);
4272 while Is_Derived_Type
(Imm_Type
) loop
4273 if Etype
(Imm_Type
) = Base_Type
(A_Type
) then
4276 -- The base type of the parent type may appear as a private
4277 -- extension if it is declared as such in a parent unit of the
4278 -- current one. For consistency of the subsequent analysis use
4279 -- the partial view for the ancestor part.
4281 elsif Is_Private_Type
(Etype
(Imm_Type
))
4282 and then Present
(Full_View
(Etype
(Imm_Type
)))
4283 and then Base_Type
(A_Type
) = Full_View
(Etype
(Imm_Type
))
4285 A_Type
:= Etype
(Imm_Type
);
4288 -- The parent type may be a private extension. The aggregate is
4289 -- legal if the type of the aggregate is an extension of it that
4290 -- is not a private extension.
4292 elsif Is_Private_Type
(A_Type
)
4293 and then not Is_Private_Type
(Imm_Type
)
4294 and then Present
(Full_View
(A_Type
))
4295 and then Base_Type
(Full_View
(A_Type
)) = Etype
(Imm_Type
)
4299 -- The parent type may be a raise expression (which is legal in
4300 -- any expression context).
4302 elsif A_Type
= Raise_Type
then
4303 A_Type
:= Etype
(Imm_Type
);
4307 Imm_Type
:= Etype
(Base_Type
(Imm_Type
));
4311 -- If previous loop did not find a proper ancestor, report error
4313 Error_Msg_NE
("expect ancestor type of &", A
, Typ
);
4315 end Valid_Ancestor_Type
;
4317 ------------------------------
4318 -- Transform_BIP_Assignment --
4319 ------------------------------
4321 procedure Transform_BIP_Assignment
(Typ
: Entity_Id
) is
4322 Loc
: constant Source_Ptr
:= Sloc
(N
);
4323 Def_Id
: constant Entity_Id
:= Make_Temporary
(Loc
, 'Y', A
);
4324 Obj_Decl
: constant Node_Id
:=
4325 Make_Object_Declaration
(Loc
,
4326 Defining_Identifier
=> Def_Id
,
4327 Constant_Present
=> True,
4328 Object_Definition
=> New_Occurrence_Of
(Typ
, Loc
),
4330 Has_Init_Expression
=> True);
4332 Set_Etype
(Def_Id
, Typ
);
4333 Set_Ancestor_Part
(N
, New_Occurrence_Of
(Def_Id
, Loc
));
4334 Insert_Action
(N
, Obj_Decl
);
4335 end Transform_BIP_Assignment
;
4337 -- Start of processing for Resolve_Extension_Aggregate
4340 -- Analyze the ancestor part and account for the case where it is a
4341 -- parameterless function call.
4344 Check_Parameterless_Call
(A
);
4346 if Is_Entity_Name
(A
) and then Is_Type
(Entity
(A
)) then
4348 -- AI05-0115: If the ancestor part is a subtype mark, the ancestor
4349 -- must not have unknown discriminants. To catch cases where the
4350 -- aggregate occurs at a place where the full view of the ancestor
4351 -- type is visible and doesn't have unknown discriminants, but the
4352 -- aggregate type was derived from a partial view that has unknown
4353 -- discriminants, we check whether the aggregate type has unknown
4354 -- discriminants (unknown discriminants were inherited), along
4355 -- with checking that the partial view of the ancestor has unknown
4356 -- discriminants. (It might be sufficient to replace the entire
4357 -- condition with Has_Unknown_Discriminants (Typ), but that might
4358 -- miss some cases, not clear, and causes error changes in some tests
4359 -- such as class-wide cases, that aren't clearly improvements. ???)
4361 if Has_Unknown_Discriminants
(Entity
(A
))
4362 or else (Has_Unknown_Discriminants
(Typ
)
4363 and then Partial_View_Has_Unknown_Discr
(Entity
(A
)))
4366 ("aggregate not available for type& whose ancestor "
4367 & "has unknown discriminants", N
, Typ
);
4371 if not Is_Tagged_Type
(Typ
) then
4372 Error_Msg_N
("type of extension aggregate must be tagged", N
);
4375 elsif Is_Limited_Type
(Typ
) then
4377 -- Ada 2005 (AI-287): Limited aggregates are allowed
4379 if Ada_Version
< Ada_2005
then
4380 Error_Msg_N
("aggregate type cannot be limited", N
);
4381 Explain_Limited_Type
(Typ
, N
);
4384 elsif Valid_Limited_Ancestor
(A
) then
4389 ("limited ancestor part must be aggregate or function call", A
);
4392 elsif Is_Class_Wide_Type
(Typ
) then
4393 Error_Msg_N
("aggregate cannot be of a class-wide type", N
);
4397 if Is_Entity_Name
(A
) and then Is_Type
(Entity
(A
)) then
4398 A_Type
:= Get_Full_View
(Entity
(A
));
4400 if Valid_Ancestor_Type
then
4401 Set_Entity
(A
, A_Type
);
4402 Set_Etype
(A
, A_Type
);
4404 Validate_Ancestor_Part
(N
);
4405 Resolve_Record_Aggregate
(N
, Typ
);
4408 elsif Nkind
(A
) /= N_Aggregate
then
4409 if Is_Overloaded
(A
) then
4412 Get_First_Interp
(A
, I
, It
);
4413 while Present
(It
.Typ
) loop
4415 -- Consider limited interpretations if Ada 2005 or higher
4417 if Is_Tagged_Type
(It
.Typ
)
4418 and then (Ada_Version
>= Ada_2005
4419 or else not Is_Limited_Type
(It
.Typ
))
4421 if A_Type
/= Any_Type
then
4422 Error_Msg_N
("cannot resolve expression", A
);
4429 Get_Next_Interp
(I
, It
);
4432 if A_Type
= Any_Type
then
4433 if Ada_Version
>= Ada_2005
then
4435 ("ancestor part must be of a tagged type", A
);
4438 ("ancestor part must be of a nonlimited tagged type", A
);
4445 A_Type
:= Etype
(A
);
4448 if Valid_Ancestor_Type
then
4449 Resolve
(A
, A_Type
);
4450 Check_Unset_Reference
(A
);
4451 Check_Non_Static_Context
(A
);
4453 -- The aggregate is illegal if the ancestor expression is a call
4454 -- to a function with a limited unconstrained result, unless the
4455 -- type of the aggregate is a null extension. This restriction
4456 -- was added in AI05-67 to simplify implementation.
4458 if Nkind
(A
) = N_Function_Call
4459 and then Is_Limited_Type
(A_Type
)
4460 and then not Is_Null_Extension
(Typ
)
4461 and then not Is_Constrained
(A_Type
)
4464 ("type of limited ancestor part must be constrained", A
);
4466 -- Reject the use of CPP constructors that leave objects partially
4467 -- initialized. For example:
4469 -- type CPP_Root is tagged limited record ...
4470 -- pragma Import (CPP, CPP_Root);
4472 -- type CPP_DT is new CPP_Root and Iface ...
4473 -- pragma Import (CPP, CPP_DT);
4475 -- type Ada_DT is new CPP_DT with ...
4477 -- Obj : Ada_DT := Ada_DT'(New_CPP_Root with others => <>);
4479 -- Using the constructor of CPP_Root the slots of the dispatch
4480 -- table of CPP_DT cannot be set, and the secondary tag of
4481 -- CPP_DT is unknown.
4483 elsif Nkind
(A
) = N_Function_Call
4484 and then Is_CPP_Constructor_Call
(A
)
4485 and then Enclosing_CPP_Parent
(Typ
) /= A_Type
4488 ("??must use 'C'P'P constructor for type &", A
,
4489 Enclosing_CPP_Parent
(Typ
));
4491 -- The following call is not needed if the previous warning
4492 -- is promoted to an error.
4494 Resolve_Record_Aggregate
(N
, Typ
);
4496 elsif Is_Class_Wide_Type
(Etype
(A
))
4497 and then Nkind
(Original_Node
(A
)) = N_Function_Call
4499 -- If the ancestor part is a dispatching call, it appears
4500 -- statically to be a legal ancestor, but it yields any member
4501 -- of the class, and it is not possible to determine whether
4502 -- it is an ancestor of the extension aggregate (much less
4503 -- which ancestor). It is not possible to determine the
4504 -- components of the extension part.
4506 -- This check implements AI-306, which in fact was motivated by
4507 -- an AdaCore query to the ARG after this test was added.
4509 Error_Msg_N
("ancestor part must be statically tagged", A
);
4511 -- We are using the build-in-place protocol, but we can't build
4512 -- in place, because we need to call the function before
4513 -- allocating the aggregate. Could do better for null
4514 -- extensions, and maybe for nondiscriminated types.
4515 -- This is wrong for limited, but those were wrong already.
4517 if not Is_Inherently_Limited_Type
(A_Type
)
4518 and then Is_Build_In_Place_Function_Call
(A
)
4520 Transform_BIP_Assignment
(A_Type
);
4523 Resolve_Record_Aggregate
(N
, Typ
);
4528 Error_Msg_N
("no unique type for this aggregate", A
);
4531 Check_Function_Writable_Actuals
(N
);
4532 end Resolve_Extension_Aggregate
;
4534 ----------------------------------
4535 -- Resolve_Null_Array_Aggregate --
4536 ----------------------------------
4538 function Resolve_Null_Array_Aggregate
(N
: Node_Id
) return Boolean is
4539 -- Never returns False, but declared as a function to match
4540 -- other Resolve_Mumble functions.
4542 Loc
: constant Source_Ptr
:= Sloc
(N
);
4543 Typ
: constant Entity_Id
:= Etype
(N
);
4547 Constr
: constant List_Id
:= New_List
;
4550 -- Attach the list of constraints at the location of the aggregate, so
4551 -- the individual constraints can be analyzed.
4553 Set_Parent
(Constr
, N
);
4555 -- Create a constrained subtype with null dimensions
4557 Index
:= First_Index
(Typ
);
4558 while Present
(Index
) loop
4559 Get_Index_Bounds
(Index
, L
=> Lo
, H
=> Hi
);
4561 -- The upper bound is the predecessor of the lower bound
4563 Hi
:= Make_Attribute_Reference
4565 Prefix
=> New_Occurrence_Of
(Etype
(Index
), Loc
),
4566 Attribute_Name
=> Name_Pred
,
4567 Expressions
=> New_List
(New_Copy_Tree
(Lo
)));
4569 Append
(Make_Range
(Loc
, New_Copy_Tree
(Lo
), Hi
), Constr
);
4570 Analyze_And_Resolve
(Last
(Constr
), Etype
(Index
));
4575 Set_Compile_Time_Known_Aggregate
(N
);
4576 Set_Aggregate_Bounds
(N
, First
(Constr
));
4579 end Resolve_Null_Array_Aggregate
;
4581 ------------------------------
4582 -- Resolve_Record_Aggregate --
4583 ------------------------------
4585 procedure Resolve_Record_Aggregate
(N
: Node_Id
; Typ
: Entity_Id
) is
4586 New_Assoc_List
: constant List_Id
:= New_List
;
4587 -- New_Assoc_List is the newly built list of N_Component_Association
4590 Others_Etype
: Entity_Id
:= Empty
;
4591 -- This variable is used to save the Etype of the last record component
4592 -- that takes its value from the others choice. Its purpose is:
4594 -- (a) make sure the others choice is useful
4596 -- (b) make sure the type of all the components whose value is
4597 -- subsumed by the others choice are the same.
4599 -- This variable is updated as a side effect of function Get_Value.
4601 Box_Node
: Node_Id
:= Empty
;
4602 Is_Box_Present
: Boolean := False;
4603 Is_Box_Init_By_Default
: Boolean := False;
4604 Others_Box
: Natural := 0;
4605 -- Ada 2005 (AI-287): Variables used in case of default initialization
4606 -- to provide a functionality similar to Others_Etype. Box_Present
4607 -- indicates that the component takes its default initialization;
4608 -- Others_Box counts the number of components of the current aggregate
4609 -- (which may be a sub-aggregate of a larger one) that are default-
4610 -- initialized. A value of One indicates that an others_box is present.
4611 -- Any larger value indicates that the others_box is not redundant.
4612 -- These variables, similar to Others_Etype, are also updated as a side
4613 -- effect of function Get_Value. Box_Node is used to place a warning on
4614 -- a redundant others_box.
4616 procedure Add_Association
4617 (Component
: Entity_Id
;
4619 Assoc_List
: List_Id
;
4620 Is_Box_Present
: Boolean := False);
4621 -- Builds a new N_Component_Association node which associates Component
4622 -- to expression Expr and adds it to the association list being built,
4623 -- either New_Assoc_List, or the association being built for an inner
4626 function Discriminant_Present
(Input_Discr
: Entity_Id
) return Boolean;
4627 -- If aggregate N is a regular aggregate this routine will return True.
4628 -- Otherwise, if N is an extension aggregate, then Input_Discr denotes
4629 -- a discriminant whose value may already have been specified by N's
4630 -- ancestor part. This routine checks whether this is indeed the case
4631 -- and if so returns False, signaling that no value for Input_Discr
4632 -- should appear in N's aggregate part. Also, in this case, the routine
4633 -- appends to New_Assoc_List the discriminant value specified in the
4636 -- If the aggregate is in a context with expansion delayed, it will be
4637 -- reanalyzed. The inherited discriminant values must not be reinserted
4638 -- in the component list to prevent spurious errors, but they must be
4639 -- present on first analysis to build the proper subtype indications.
4640 -- The flag Inherited_Discriminant is used to prevent the re-insertion.
4642 function Find_Private_Ancestor
(Typ
: Entity_Id
) return Entity_Id
;
4643 -- AI05-0115: Find earlier ancestor in the derivation chain that is
4644 -- derived from private view Typ. Whether the aggregate is legal depends
4645 -- on the current visibility of the type as well as that of the parent
4649 (Compon
: Entity_Id
;
4651 Consider_Others_Choice
: Boolean := False) return Node_Id
;
4652 -- Given a record component stored in parameter Compon, this function
4653 -- returns its value as it appears in the list From, which is a list
4654 -- of N_Component_Association nodes.
4656 -- If no component association has a choice for the searched component,
4657 -- the value provided by the others choice is returned, if there is one,
4658 -- and Consider_Others_Choice is set to true. Otherwise Empty is
4659 -- returned. If there is more than one component association giving a
4660 -- value for the searched record component, an error message is emitted
4661 -- and the first found value is returned.
4663 -- If Consider_Others_Choice is set and the returned expression comes
4664 -- from the others choice, then Others_Etype is set as a side effect.
4665 -- An error message is emitted if the components taking their value from
4666 -- the others choice do not have same type.
4668 procedure Resolve_Aggr_Expr
(Expr
: Node_Id
; Component
: Entity_Id
);
4669 -- Analyzes and resolves expression Expr against the Etype of the
4670 -- Component. This routine also applies all appropriate checks to Expr.
4671 -- It finally saves a Expr in the newly created association list that
4672 -- will be attached to the final record aggregate. Note that if the
4673 -- Parent pointer of Expr is not set then Expr was produced with a
4674 -- New_Copy_Tree or some such.
4676 procedure Rewrite_Range
(Root_Type
: Entity_Id
; Rge
: Node_Id
);
4677 -- Rewrite a range node Rge when its bounds refer to non-stored
4678 -- discriminants from Root_Type, to replace them with the stored
4679 -- discriminant values. This is required in GNATprove mode, and is
4680 -- adopted in all modes to avoid special-casing GNATprove mode.
4682 ---------------------
4683 -- Add_Association --
4684 ---------------------
4686 procedure Add_Association
4687 (Component
: Entity_Id
;
4689 Assoc_List
: List_Id
;
4690 Is_Box_Present
: Boolean := False)
4692 Choice_List
: constant List_Id
:= New_List
;
4696 -- If this is a box association the expression is missing, so use the
4697 -- Sloc of the aggregate itself for the new association.
4699 pragma Assert
(Present
(Expr
) xor Is_Box_Present
);
4701 if Present
(Expr
) then
4707 Append_To
(Choice_List
, New_Occurrence_Of
(Component
, Loc
));
4709 Append_To
(Assoc_List
,
4710 Make_Component_Association
(Loc
,
4711 Choices
=> Choice_List
,
4713 Box_Present
=> Is_Box_Present
));
4715 -- If this association has a box for a component that is initialized
4716 -- by default, then set flag on the new association to indicate that
4717 -- the original association was for such a box-initialized component.
4719 if Is_Box_Init_By_Default
then
4720 Set_Was_Default_Init_Box_Association
(Last
(Assoc_List
));
4722 end Add_Association
;
4724 --------------------------
4725 -- Discriminant_Present --
4726 --------------------------
4728 function Discriminant_Present
(Input_Discr
: Entity_Id
) return Boolean is
4729 Regular_Aggr
: constant Boolean := Nkind
(N
) /= N_Extension_Aggregate
;
4731 Ancestor_Is_Subtyp
: Boolean;
4736 Ancestor_Typ
: Entity_Id
;
4737 Comp_Assoc
: Node_Id
;
4739 Discr_Expr
: Node_Id
;
4740 Discr_Val
: Elmt_Id
:= No_Elmt
;
4741 Orig_Discr
: Entity_Id
;
4744 if Regular_Aggr
then
4748 -- Check whether inherited discriminant values have already been
4749 -- inserted in the aggregate. This will be the case if we are
4750 -- re-analyzing an aggregate whose expansion was delayed.
4752 if Present
(Component_Associations
(N
)) then
4753 Comp_Assoc
:= First
(Component_Associations
(N
));
4754 while Present
(Comp_Assoc
) loop
4755 if Inherited_Discriminant
(Comp_Assoc
) then
4763 Ancestor
:= Ancestor_Part
(N
);
4764 Ancestor_Typ
:= Etype
(Ancestor
);
4765 Loc
:= Sloc
(Ancestor
);
4767 -- For a private type with unknown discriminants, use the underlying
4768 -- record view if it is available.
4770 if Has_Unknown_Discriminants
(Ancestor_Typ
)
4771 and then Present
(Full_View
(Ancestor_Typ
))
4772 and then Present
(Underlying_Record_View
(Full_View
(Ancestor_Typ
)))
4774 Ancestor_Typ
:= Underlying_Record_View
(Full_View
(Ancestor_Typ
));
4777 Ancestor_Is_Subtyp
:=
4778 Is_Entity_Name
(Ancestor
) and then Is_Type
(Entity
(Ancestor
));
4780 -- If the ancestor part has no discriminants clearly N's aggregate
4781 -- part must provide a value for Discr.
4783 if not Has_Discriminants
(Ancestor_Typ
) then
4786 -- If the ancestor part is an unconstrained subtype mark then the
4787 -- Discr must be present in N's aggregate part.
4789 elsif Ancestor_Is_Subtyp
4790 and then not Is_Constrained
(Entity
(Ancestor
))
4795 -- Now look to see if Discr was specified in the ancestor part
4797 if Ancestor_Is_Subtyp
then
4799 First_Elmt
(Discriminant_Constraint
(Entity
(Ancestor
)));
4802 Orig_Discr
:= Original_Record_Component
(Input_Discr
);
4804 Discr
:= First_Discriminant
(Ancestor_Typ
);
4805 while Present
(Discr
) loop
4807 -- If Ancestor has already specified Disc value then insert its
4808 -- value in the final aggregate.
4810 if Original_Record_Component
(Discr
) = Orig_Discr
then
4811 if Ancestor_Is_Subtyp
then
4812 Discr_Expr
:= New_Copy_Tree
(Node
(Discr_Val
));
4815 Make_Selected_Component
(Loc
,
4816 Prefix
=> Duplicate_Subexpr
(Ancestor
),
4817 Selector_Name
=> New_Occurrence_Of
(Input_Discr
, Loc
));
4820 Resolve_Aggr_Expr
(Discr_Expr
, Input_Discr
);
4821 Set_Inherited_Discriminant
(Last
(New_Assoc_List
));
4825 Next_Discriminant
(Discr
);
4827 if Ancestor_Is_Subtyp
then
4828 Next_Elmt
(Discr_Val
);
4833 end Discriminant_Present
;
4835 ---------------------------
4836 -- Find_Private_Ancestor --
4837 ---------------------------
4839 function Find_Private_Ancestor
(Typ
: Entity_Id
) return Entity_Id
is
4845 if Has_Private_Ancestor
(Par
)
4846 and then not Has_Private_Ancestor
(Etype
(Base_Type
(Par
)))
4850 elsif not Is_Derived_Type
(Par
) then
4854 Par
:= Etype
(Base_Type
(Par
));
4857 end Find_Private_Ancestor
;
4864 (Compon
: Entity_Id
;
4866 Consider_Others_Choice
: Boolean := False) return Node_Id
4868 Typ
: constant Entity_Id
:= Etype
(Compon
);
4870 Expr
: Node_Id
:= Empty
;
4871 Selector_Name
: Node_Id
;
4874 Is_Box_Present
:= False;
4875 Is_Box_Init_By_Default
:= False;
4881 Assoc
:= First
(From
);
4882 while Present
(Assoc
) loop
4883 Selector_Name
:= First
(Choices
(Assoc
));
4884 while Present
(Selector_Name
) loop
4885 if Nkind
(Selector_Name
) = N_Others_Choice
then
4886 if Consider_Others_Choice
and then No
(Expr
) then
4888 -- We need to duplicate the expression for each
4889 -- successive component covered by the others choice.
4890 -- This is redundant if the others_choice covers only
4891 -- one component (small optimization possible???), but
4892 -- indispensable otherwise, because each one must be
4893 -- expanded individually to preserve side effects.
4895 -- Ada 2005 (AI-287): In case of default initialization
4896 -- of components, we duplicate the corresponding default
4897 -- expression (from the record type declaration). The
4898 -- copy must carry the sloc of the association (not the
4899 -- original expression) to prevent spurious elaboration
4900 -- checks when the default includes function calls.
4902 if Box_Present
(Assoc
) then
4903 Others_Box
:= Others_Box
+ 1;
4904 Is_Box_Present
:= True;
4906 if Expander_Active
then
4908 New_Copy_Tree_And_Copy_Dimensions
4909 (Expression
(Parent
(Compon
)),
4910 New_Sloc
=> Sloc
(Assoc
));
4912 return Expression
(Parent
(Compon
));
4916 if Present
(Others_Etype
)
4917 and then Base_Type
(Others_Etype
) /= Base_Type
(Typ
)
4919 -- If the components are of an anonymous access
4920 -- type they are distinct, but this is legal in
4921 -- Ada 2012 as long as designated types match.
4923 if (Ekind
(Typ
) = E_Anonymous_Access_Type
4924 or else Ekind
(Typ
) =
4925 E_Anonymous_Access_Subprogram_Type
)
4926 and then Designated_Type
(Typ
) =
4927 Designated_Type
(Others_Etype
)
4932 ("components in OTHERS choice must have same "
4933 & "type", Selector_Name
);
4937 Others_Etype
:= Typ
;
4939 -- Copy the expression so that it is resolved
4940 -- independently for each component, This is needed
4941 -- for accessibility checks on components of anonymous
4942 -- access types, even in compile_only mode.
4944 if not Inside_A_Generic
then
4946 New_Copy_Tree_And_Copy_Dimensions
4947 (Expression
(Assoc
));
4949 return Expression
(Assoc
);
4954 elsif Chars
(Compon
) = Chars
(Selector_Name
) then
4957 -- Ada 2005 (AI-231)
4959 if Ada_Version
>= Ada_2005
4960 and then Known_Null
(Expression
(Assoc
))
4962 Check_Can_Never_Be_Null
(Compon
, Expression
(Assoc
));
4965 -- We need to duplicate the expression when several
4966 -- components are grouped together with a "|" choice.
4967 -- For instance "filed1 | filed2 => Expr"
4969 -- Ada 2005 (AI-287)
4971 if Box_Present
(Assoc
) then
4972 Is_Box_Present
:= True;
4974 -- Duplicate the default expression of the component
4975 -- from the record type declaration, so a new copy
4976 -- can be attached to the association.
4978 -- Note that we always copy the default expression,
4979 -- even when the association has a single choice, in
4980 -- order to create a proper association for the
4981 -- expanded aggregate.
4983 -- Component may have no default, in which case the
4984 -- expression is empty and the component is default-
4985 -- initialized, but an association for the component
4986 -- exists, and it is not covered by an others clause.
4988 -- Scalar and private types have no initialization
4989 -- procedure, so they remain uninitialized. If the
4990 -- target of the aggregate is a constant this
4991 -- deserves a warning.
4993 if No
(Expression
(Parent
(Compon
)))
4994 and then not Has_Non_Null_Base_Init_Proc
(Typ
)
4995 and then not Has_Aspect
(Typ
, Aspect_Default_Value
)
4996 and then not Is_Concurrent_Type
(Typ
)
4997 and then Nkind
(Parent
(N
)) = N_Object_Declaration
4998 and then Constant_Present
(Parent
(N
))
5000 Error_Msg_Node_2
:= Typ
;
5002 ("??component& of type& is uninitialized",
5003 Assoc
, Selector_Name
);
5005 -- An additional reminder if the component type
5006 -- is a generic formal.
5008 if Is_Generic_Type
(Base_Type
(Typ
)) then
5010 ("\instance should provide actual type with "
5011 & "initialization for&", Assoc
, Typ
);
5016 New_Copy_Tree_And_Copy_Dimensions
5017 (Expression
(Parent
(Compon
)));
5020 if Present
(Next
(Selector_Name
)) then
5021 Expr
:= New_Copy_Tree_And_Copy_Dimensions
5022 (Expression
(Assoc
));
5024 Expr
:= Expression
(Assoc
);
5028 Generate_Reference
(Compon
, Selector_Name
, 'm');
5032 ("more than one value supplied for &",
5033 Selector_Name
, Compon
);
5038 Next
(Selector_Name
);
5047 -----------------------
5048 -- Resolve_Aggr_Expr --
5049 -----------------------
5051 procedure Resolve_Aggr_Expr
(Expr
: Node_Id
; Component
: Entity_Id
) is
5052 function Has_Expansion_Delayed
(Expr
: Node_Id
) return Boolean;
5053 -- If the expression is an aggregate (possibly qualified) then its
5054 -- expansion is delayed until the enclosing aggregate is expanded
5055 -- into assignments. In that case, do not generate checks on the
5056 -- expression, because they will be generated later, and will other-
5057 -- wise force a copy (to remove side effects) that would leave a
5058 -- dynamic-sized aggregate in the code, something that gigi cannot
5061 ---------------------------
5062 -- Has_Expansion_Delayed --
5063 ---------------------------
5065 function Has_Expansion_Delayed
(Expr
: Node_Id
) return Boolean is
5068 (Nkind
(Expr
) in N_Aggregate | N_Extension_Aggregate
5069 and then Present
(Etype
(Expr
))
5070 and then Is_Record_Type
(Etype
(Expr
))
5071 and then Expansion_Delayed
(Expr
))
5073 (Nkind
(Expr
) = N_Qualified_Expression
5074 and then Has_Expansion_Delayed
(Expression
(Expr
)));
5075 end Has_Expansion_Delayed
;
5079 Expr_Type
: Entity_Id
:= Empty
;
5080 New_C
: Entity_Id
:= Component
;
5084 -- Set to True if the resolved Expr node needs to be relocated when
5085 -- attached to the newly created association list. This node need not
5086 -- be relocated if its parent pointer is not set. In fact in this
5087 -- case Expr is the output of a New_Copy_Tree call. If Relocate is
5088 -- True then we have analyzed the expression node in the original
5089 -- aggregate and hence it needs to be relocated when moved over to
5090 -- the new association list.
5092 -- Start of processing for Resolve_Aggr_Expr
5095 -- If the type of the component is elementary or the type of the
5096 -- aggregate does not contain discriminants, use the type of the
5097 -- component to resolve Expr.
5099 if Is_Elementary_Type
(Etype
(Component
))
5100 or else not Has_Discriminants
(Etype
(N
))
5102 Expr_Type
:= Etype
(Component
);
5104 -- Otherwise we have to pick up the new type of the component from
5105 -- the new constrained subtype of the aggregate. In fact components
5106 -- which are of a composite type might be constrained by a
5107 -- discriminant, and we want to resolve Expr against the subtype were
5108 -- all discriminant occurrences are replaced with their actual value.
5111 New_C
:= First_Component
(Etype
(N
));
5112 while Present
(New_C
) loop
5113 if Chars
(New_C
) = Chars
(Component
) then
5114 Expr_Type
:= Etype
(New_C
);
5118 Next_Component
(New_C
);
5121 pragma Assert
(Present
(Expr_Type
));
5123 -- For each range in an array type where a discriminant has been
5124 -- replaced with the constraint, check that this range is within
5125 -- the range of the base type. This checks is done in the init
5126 -- proc for regular objects, but has to be done here for
5127 -- aggregates since no init proc is called for them.
5129 if Is_Array_Type
(Expr_Type
) then
5132 -- Range of the current constrained index in the array
5134 Orig_Index
: Node_Id
:= First_Index
(Etype
(Component
));
5135 -- Range corresponding to the range Index above in the
5136 -- original unconstrained record type. The bounds of this
5137 -- range may be governed by discriminants.
5139 Unconstr_Index
: Node_Id
:= First_Index
(Etype
(Expr_Type
));
5140 -- Range corresponding to the range Index above for the
5141 -- unconstrained array type. This range is needed to apply
5145 Index
:= First_Index
(Expr_Type
);
5146 while Present
(Index
) loop
5147 if Depends_On_Discriminant
(Orig_Index
) then
5148 Apply_Range_Check
(Index
, Etype
(Unconstr_Index
));
5152 Next_Index
(Orig_Index
);
5153 Next_Index
(Unconstr_Index
);
5159 -- If the Parent pointer of Expr is not set, Expr is an expression
5160 -- duplicated by New_Tree_Copy (this happens for record aggregates
5161 -- that look like (Field1 | Filed2 => Expr) or (others => Expr)).
5162 -- Such a duplicated expression must be attached to the tree
5163 -- before analysis and resolution to enforce the rule that a tree
5164 -- fragment should never be analyzed or resolved unless it is
5165 -- attached to the current compilation unit.
5167 if No
(Parent
(Expr
)) then
5168 Set_Parent
(Expr
, N
);
5174 Analyze_And_Resolve
(Expr
, Expr_Type
);
5175 Check_Expr_OK_In_Limited_Aggregate
(Expr
);
5176 Check_Non_Static_Context
(Expr
);
5177 Check_Unset_Reference
(Expr
);
5179 -- Check wrong use of class-wide types
5181 if Is_Class_Wide_Type
(Etype
(Expr
)) then
5182 Error_Msg_N
("dynamically tagged expression not allowed", Expr
);
5185 if not Has_Expansion_Delayed
(Expr
) then
5186 Aggregate_Constraint_Checks
(Expr
, Expr_Type
);
5189 -- If an aggregate component has a type with predicates, an explicit
5190 -- predicate check must be applied, as for an assignment statement,
5191 -- because the aggregate might not be expanded into individual
5192 -- component assignments.
5194 if Has_Predicates
(Expr_Type
)
5195 and then Analyzed
(Expr
)
5197 Apply_Predicate_Check
(Expr
, Expr_Type
);
5200 if Raises_Constraint_Error
(Expr
) then
5201 Set_Raises_Constraint_Error
(N
);
5204 -- If the expression has been marked as requiring a range check, then
5205 -- generate it here. It's a bit odd to be generating such checks in
5206 -- the analyzer, but harmless since Generate_Range_Check does nothing
5207 -- (other than making sure Do_Range_Check is set) if the expander is
5210 if Do_Range_Check
(Expr
) then
5211 Generate_Range_Check
(Expr
, Expr_Type
, CE_Range_Check_Failed
);
5214 -- Add association Component => Expr if the caller requests it
5217 New_Expr
:= Relocate_Node
(Expr
);
5219 -- Since New_Expr is not gonna be analyzed later on, we need to
5220 -- propagate here the dimensions form Expr to New_Expr.
5222 Copy_Dimensions
(Expr
, New_Expr
);
5228 Add_Association
(New_C
, New_Expr
, New_Assoc_List
);
5229 end Resolve_Aggr_Expr
;
5235 procedure Rewrite_Range
(Root_Type
: Entity_Id
; Rge
: Node_Id
) is
5236 procedure Rewrite_Bound
5239 Expr_Disc
: Node_Id
);
5240 -- Rewrite a bound of the range Bound, when it is equal to the
5241 -- non-stored discriminant Disc, into the stored discriminant
5248 procedure Rewrite_Bound
5251 Expr_Disc
: Node_Id
)
5254 if Nkind
(Bound
) /= N_Identifier
then
5258 -- We expect either the discriminant or the discriminal
5260 if Entity
(Bound
) = Disc
5261 or else (Ekind
(Entity
(Bound
)) = E_In_Parameter
5262 and then Discriminal_Link
(Entity
(Bound
)) = Disc
)
5264 Rewrite
(Bound
, New_Copy_Tree
(Expr_Disc
));
5270 Low
, High
: Node_Id
;
5272 Expr_Disc
: Elmt_Id
;
5274 -- Start of processing for Rewrite_Range
5277 if Has_Discriminants
(Root_Type
) and then Nkind
(Rge
) = N_Range
then
5278 Low
:= Low_Bound
(Rge
);
5279 High
:= High_Bound
(Rge
);
5281 Disc
:= First_Discriminant
(Root_Type
);
5282 Expr_Disc
:= First_Elmt
(Stored_Constraint
(Etype
(N
)));
5283 while Present
(Disc
) loop
5284 Rewrite_Bound
(Low
, Disc
, Node
(Expr_Disc
));
5285 Rewrite_Bound
(High
, Disc
, Node
(Expr_Disc
));
5286 Next_Discriminant
(Disc
);
5287 Next_Elmt
(Expr_Disc
);
5294 Components
: constant Elist_Id
:= New_Elmt_List
;
5295 -- Components is the list of the record components whose value must be
5296 -- provided in the aggregate. This list does include discriminants.
5298 Component
: Entity_Id
;
5299 Component_Elmt
: Elmt_Id
;
5301 Positional_Expr
: Node_Id
;
5303 -- Start of processing for Resolve_Record_Aggregate
5306 -- A record aggregate is restricted in SPARK:
5308 -- Each named association can have only a single choice.
5309 -- OTHERS cannot be used.
5310 -- Positional and named associations cannot be mixed.
5312 if Present
(Component_Associations
(N
)) then
5317 Assoc
:= First
(Component_Associations
(N
));
5318 while Present
(Assoc
) loop
5319 if Nkind
(Assoc
) = N_Iterated_Component_Association
then
5321 ("iterated component association can only appear in an "
5322 & "array aggregate", N
);
5323 raise Unrecoverable_Error
;
5331 -- We may end up calling Duplicate_Subexpr on expressions that are
5332 -- attached to New_Assoc_List. For this reason we need to attach it
5333 -- to the tree by setting its parent pointer to N. This parent point
5334 -- will change in STEP 8 below.
5336 Set_Parent
(New_Assoc_List
, N
);
5338 -- STEP 1: abstract type and null record verification
5340 if Is_Abstract_Type
(Typ
) then
5341 Error_Msg_N
("type of aggregate cannot be abstract", N
);
5344 if No
(First_Entity
(Typ
)) and then Null_Record_Present
(N
) then
5348 elsif Present
(First_Entity
(Typ
))
5349 and then Null_Record_Present
(N
)
5350 and then not Is_Tagged_Type
(Typ
)
5352 Error_Msg_N
("record aggregate cannot be null", N
);
5355 -- If the type has no components, then the aggregate should either
5356 -- have "null record", or in Ada 2005 it could instead have a single
5357 -- component association given by "others => <>". For Ada 95 we flag an
5358 -- error at this point, but for Ada 2005 we proceed with checking the
5359 -- associations below, which will catch the case where it's not an
5360 -- aggregate with "others => <>". Note that the legality of a <>
5361 -- aggregate for a null record type was established by AI05-016.
5363 elsif No
(First_Entity
(Typ
))
5364 and then Ada_Version
< Ada_2005
5366 Error_Msg_N
("record aggregate must be null", N
);
5370 -- A record aggregate can only use parentheses
5372 if Nkind
(N
) = N_Aggregate
5373 and then Is_Homogeneous_Aggregate
(N
)
5375 Error_Msg_N
("record aggregate must use (), not '[']", N
);
5379 -- STEP 2: Verify aggregate structure
5383 Bad_Aggregate
: Boolean := False;
5384 Selector_Name
: Node_Id
;
5387 if Present
(Component_Associations
(N
)) then
5388 Assoc
:= First
(Component_Associations
(N
));
5393 while Present
(Assoc
) loop
5394 Selector_Name
:= First
(Choices
(Assoc
));
5395 while Present
(Selector_Name
) loop
5396 if Nkind
(Selector_Name
) = N_Identifier
then
5399 elsif Nkind
(Selector_Name
) = N_Others_Choice
then
5400 if Selector_Name
/= First
(Choices
(Assoc
))
5401 or else Present
(Next
(Selector_Name
))
5404 ("OTHERS must appear alone in a choice list",
5408 elsif Present
(Next
(Assoc
)) then
5410 ("OTHERS must appear last in an aggregate",
5414 -- (Ada 2005): If this is an association with a box,
5415 -- indicate that the association need not represent
5418 elsif Box_Present
(Assoc
) then
5425 ("selector name should be identifier or OTHERS",
5427 Bad_Aggregate
:= True;
5430 Next
(Selector_Name
);
5436 if Bad_Aggregate
then
5441 -- STEP 3: Find discriminant Values
5444 Discrim
: Entity_Id
;
5445 Missing_Discriminants
: Boolean := False;
5448 if Present
(Expressions
(N
)) then
5449 Positional_Expr
:= First
(Expressions
(N
));
5451 Positional_Expr
:= Empty
;
5454 -- AI05-0115: if the ancestor part is a subtype mark, the ancestor
5455 -- must not have unknown discriminants.
5456 -- ??? We are not checking any subtype mark here and this code is not
5457 -- exercised by any test, so it's likely wrong (in particular
5458 -- we should not use Root_Type here but the subtype mark, if any),
5459 -- and possibly not needed.
5461 if Is_Derived_Type
(Typ
)
5462 and then Has_Unknown_Discriminants
(Root_Type
(Typ
))
5463 and then Nkind
(N
) /= N_Extension_Aggregate
5466 ("aggregate not available for type& whose ancestor "
5467 & "has unknown discriminants", N
, Typ
);
5470 if Has_Unknown_Discriminants
(Typ
)
5471 and then Present
(Underlying_Record_View
(Typ
))
5473 Discrim
:= First_Discriminant
(Underlying_Record_View
(Typ
));
5474 elsif Has_Discriminants
(Typ
) then
5475 Discrim
:= First_Discriminant
(Typ
);
5480 -- First find the discriminant values in the positional components
5482 while Present
(Discrim
) and then Present
(Positional_Expr
) loop
5483 if Discriminant_Present
(Discrim
) then
5484 Resolve_Aggr_Expr
(Positional_Expr
, Discrim
);
5486 -- Ada 2005 (AI-231)
5488 if Ada_Version
>= Ada_2005
5489 and then Known_Null
(Positional_Expr
)
5491 Check_Can_Never_Be_Null
(Discrim
, Positional_Expr
);
5494 Next
(Positional_Expr
);
5497 if Present
(Get_Value
(Discrim
, Component_Associations
(N
))) then
5499 ("more than one value supplied for discriminant&",
5503 Next_Discriminant
(Discrim
);
5506 -- Find remaining discriminant values if any among named components
5508 while Present
(Discrim
) loop
5509 Expr
:= Get_Value
(Discrim
, Component_Associations
(N
), True);
5511 if not Discriminant_Present
(Discrim
) then
5512 if Present
(Expr
) then
5514 ("more than one value supplied for discriminant &",
5518 elsif No
(Expr
) then
5520 ("no value supplied for discriminant &", N
, Discrim
);
5521 Missing_Discriminants
:= True;
5524 Resolve_Aggr_Expr
(Expr
, Discrim
);
5527 Next_Discriminant
(Discrim
);
5530 if Missing_Discriminants
then
5534 -- At this point and until the beginning of STEP 6, New_Assoc_List
5535 -- contains only the discriminants and their values.
5539 -- STEP 4: Set the Etype of the record aggregate
5541 if Has_Discriminants
(Typ
)
5542 or else (Has_Unknown_Discriminants
(Typ
)
5543 and then Present
(Underlying_Record_View
(Typ
)))
5545 Build_Constrained_Itype
(N
, Typ
, New_Assoc_List
);
5550 -- STEP 5: Get remaining components according to discriminant values
5554 Errors_Found
: Boolean := False;
5555 Record_Def
: Node_Id
;
5556 Parent_Typ
: Entity_Id
;
5557 Parent_Typ_List
: Elist_Id
;
5558 Parent_Elmt
: Elmt_Id
;
5559 Root_Typ
: Entity_Id
;
5562 if Is_Derived_Type
(Typ
) and then Is_Tagged_Type
(Typ
) then
5563 Parent_Typ_List
:= New_Elmt_List
;
5565 -- If this is an extension aggregate, the component list must
5566 -- include all components that are not in the given ancestor type.
5567 -- Otherwise, the component list must include components of all
5568 -- ancestors, starting with the root.
5570 if Nkind
(N
) = N_Extension_Aggregate
then
5571 Root_Typ
:= Base_Type
(Etype
(Ancestor_Part
(N
)));
5574 -- AI05-0115: check legality of aggregate for type with a
5575 -- private ancestor.
5577 Root_Typ
:= Root_Type
(Typ
);
5578 if Has_Private_Ancestor
(Typ
) then
5580 Ancestor
: constant Entity_Id
:=
5581 Find_Private_Ancestor
(Typ
);
5582 Ancestor_Unit
: constant Entity_Id
:=
5584 (Get_Source_Unit
(Ancestor
));
5585 Parent_Unit
: constant Entity_Id
:=
5586 Cunit_Entity
(Get_Source_Unit
5587 (Base_Type
(Etype
(Ancestor
))));
5589 -- Check whether we are in a scope that has full view
5590 -- over the private ancestor and its parent. This can
5591 -- only happen if the derivation takes place in a child
5592 -- unit of the unit that declares the parent, and we are
5593 -- in the private part or body of that child unit, else
5594 -- the aggregate is illegal.
5596 if Is_Child_Unit
(Ancestor_Unit
)
5597 and then Scope
(Ancestor_Unit
) = Parent_Unit
5598 and then In_Open_Scopes
(Scope
(Ancestor
))
5600 (In_Private_Part
(Scope
(Ancestor
))
5601 or else In_Package_Body
(Scope
(Ancestor
)))
5607 ("type of aggregate has private ancestor&!",
5609 Error_Msg_N
("must use extension aggregate!", N
);
5615 Dnode
:= Declaration_Node
(Base_Type
(Root_Typ
));
5617 -- If we don't get a full declaration, then we have some error
5618 -- which will get signalled later so skip this part. Otherwise
5619 -- gather components of root that apply to the aggregate type.
5620 -- We use the base type in case there is an applicable stored
5621 -- constraint that renames the discriminants of the root.
5623 if Nkind
(Dnode
) = N_Full_Type_Declaration
then
5624 Record_Def
:= Type_Definition
(Dnode
);
5627 Component_List
(Record_Def
),
5628 Governed_By
=> New_Assoc_List
,
5630 Report_Errors
=> Errors_Found
);
5632 if Errors_Found
then
5634 ("discriminant controlling variant part is not static",
5641 Parent_Typ
:= Base_Type
(Typ
);
5642 while Parent_Typ
/= Root_Typ
loop
5643 Prepend_Elmt
(Parent_Typ
, To
=> Parent_Typ_List
);
5644 Parent_Typ
:= Etype
(Parent_Typ
);
5646 -- Check whether a private parent requires the use of
5647 -- an extension aggregate. This test does not apply in
5648 -- an instantiation: if the generic unit is legal so is
5651 if Nkind
(Parent
(Base_Type
(Parent_Typ
))) =
5652 N_Private_Type_Declaration
5653 or else Nkind
(Parent
(Base_Type
(Parent_Typ
))) =
5654 N_Private_Extension_Declaration
5656 if Nkind
(N
) /= N_Extension_Aggregate
5657 and then not In_Instance
5660 ("type of aggregate has private ancestor&!",
5662 Error_Msg_N
("must use extension aggregate!", N
);
5665 elsif Parent_Typ
/= Root_Typ
then
5667 ("ancestor part of aggregate must be private type&",
5668 Ancestor_Part
(N
), Parent_Typ
);
5672 -- The current view of ancestor part may be a private type,
5673 -- while the context type is always non-private.
5675 elsif Is_Private_Type
(Root_Typ
)
5676 and then Present
(Full_View
(Root_Typ
))
5677 and then Nkind
(N
) = N_Extension_Aggregate
5679 exit when Base_Type
(Full_View
(Root_Typ
)) = Parent_Typ
;
5683 -- Now collect components from all other ancestors, beginning
5684 -- with the current type. If the type has unknown discriminants
5685 -- use the component list of the Underlying_Record_View, which
5686 -- needs to be used for the subsequent expansion of the aggregate
5687 -- into assignments.
5689 Parent_Elmt
:= First_Elmt
(Parent_Typ_List
);
5690 while Present
(Parent_Elmt
) loop
5691 Parent_Typ
:= Node
(Parent_Elmt
);
5693 if Has_Unknown_Discriminants
(Parent_Typ
)
5694 and then Present
(Underlying_Record_View
(Typ
))
5696 Parent_Typ
:= Underlying_Record_View
(Parent_Typ
);
5699 Record_Def
:= Type_Definition
(Parent
(Base_Type
(Parent_Typ
)));
5700 Gather_Components
(Parent_Typ
,
5701 Component_List
(Record_Extension_Part
(Record_Def
)),
5702 Governed_By
=> New_Assoc_List
,
5704 Report_Errors
=> Errors_Found
);
5706 Next_Elmt
(Parent_Elmt
);
5709 -- Typ is not a derived tagged type
5712 Record_Def
:= Type_Definition
(Parent
(Base_Type
(Typ
)));
5714 if Null_Present
(Record_Def
) then
5717 elsif not Has_Unknown_Discriminants
(Typ
) then
5720 Component_List
(Record_Def
),
5721 Governed_By
=> New_Assoc_List
,
5723 Report_Errors
=> Errors_Found
);
5727 (Base_Type
(Underlying_Record_View
(Typ
)),
5728 Component_List
(Record_Def
),
5729 Governed_By
=> New_Assoc_List
,
5731 Report_Errors
=> Errors_Found
);
5735 if Errors_Found
then
5740 -- STEP 6: Find component Values
5742 Component_Elmt
:= First_Elmt
(Components
);
5744 -- First scan the remaining positional associations in the aggregate.
5745 -- Remember that at this point Positional_Expr contains the current
5746 -- positional association if any is left after looking for discriminant
5747 -- values in step 3.
5749 while Present
(Positional_Expr
) and then Present
(Component_Elmt
) loop
5750 Component
:= Node
(Component_Elmt
);
5751 Resolve_Aggr_Expr
(Positional_Expr
, Component
);
5753 -- Ada 2005 (AI-231)
5755 if Ada_Version
>= Ada_2005
and then Known_Null
(Positional_Expr
) then
5756 Check_Can_Never_Be_Null
(Component
, Positional_Expr
);
5759 if Present
(Get_Value
(Component
, Component_Associations
(N
))) then
5761 ("more than one value supplied for component &", N
, Component
);
5764 Next
(Positional_Expr
);
5765 Next_Elmt
(Component_Elmt
);
5768 if Present
(Positional_Expr
) then
5770 ("too many components for record aggregate", Positional_Expr
);
5773 -- Now scan for the named arguments of the aggregate
5775 while Present
(Component_Elmt
) loop
5776 Component
:= Node
(Component_Elmt
);
5777 Expr
:= Get_Value
(Component
, Component_Associations
(N
), True);
5779 -- Note: The previous call to Get_Value sets the value of the
5780 -- variable Is_Box_Present.
5782 -- Ada 2005 (AI-287): Handle components with default initialization.
5783 -- Note: This feature was originally added to Ada 2005 for limited
5784 -- but it was finally allowed with any type.
5786 if Is_Box_Present
then
5787 Check_Box_Component
: declare
5788 Ctyp
: constant Entity_Id
:= Etype
(Component
);
5791 -- Initially assume that the box is for a default-initialized
5792 -- component and reset to False in cases where that's not true.
5794 Is_Box_Init_By_Default
:= True;
5796 -- If there is a default expression for the aggregate, copy
5797 -- it into a new association. This copy must modify the scopes
5798 -- of internal types that may be attached to the expression
5799 -- (e.g. index subtypes of arrays) because in general the type
5800 -- declaration and the aggregate appear in different scopes,
5801 -- and the backend requires the scope of the type to match the
5802 -- point at which it is elaborated.
5804 -- If the component has an initialization procedure (IP) we
5805 -- pass the component to the expander, which will generate
5806 -- the call to such IP.
5808 -- If the component has discriminants, their values must
5809 -- be taken from their subtype. This is indispensable for
5810 -- constraints that are given by the current instance of an
5811 -- enclosing type, to allow the expansion of the aggregate to
5812 -- replace the reference to the current instance by the target
5813 -- object of the aggregate.
5815 if Is_Case_Choice_Pattern
(N
) then
5817 -- Do not transform box component values in a case-choice
5821 (Component
=> Component
,
5823 Assoc_List
=> New_Assoc_List
,
5824 Is_Box_Present
=> True);
5826 elsif Present
(Parent
(Component
))
5827 and then Nkind
(Parent
(Component
)) = N_Component_Declaration
5828 and then Present
(Expression
(Parent
(Component
)))
5830 -- If component declaration has an initialization expression
5831 -- then this is not a case of default initialization.
5833 Is_Box_Init_By_Default
:= False;
5836 New_Copy_Tree_And_Copy_Dimensions
5837 (Expression
(Parent
(Component
)),
5838 New_Scope
=> Current_Scope
,
5839 New_Sloc
=> Sloc
(N
));
5841 -- As the type of the copied default expression may refer
5842 -- to discriminants of the record type declaration, these
5843 -- non-stored discriminants need to be rewritten into stored
5844 -- discriminant values for the aggregate. This is required
5845 -- in GNATprove mode, and is adopted in all modes to avoid
5846 -- special-casing GNATprove mode.
5848 if Is_Array_Type
(Etype
(Expr
)) then
5850 Rec_Typ
: constant Entity_Id
:= Scope
(Component
);
5851 -- Root record type whose discriminants may be used as
5852 -- bounds in range nodes.
5859 -- Rewrite the range nodes occurring in the indexes
5862 Index
:= First_Index
(Etype
(Expr
));
5863 while Present
(Index
) loop
5864 Rewrite_Range
(Rec_Typ
, Index
);
5866 (Rec_Typ
, Scalar_Range
(Etype
(Index
)));
5871 -- Rewrite the range nodes occurring as aggregate
5872 -- bounds and component associations.
5874 if Nkind
(Expr
) = N_Aggregate
then
5875 if Present
(Aggregate_Bounds
(Expr
)) then
5876 Rewrite_Range
(Rec_Typ
, Aggregate_Bounds
(Expr
));
5879 if Present
(Component_Associations
(Expr
)) then
5880 Assoc
:= First
(Component_Associations
(Expr
));
5881 while Present
(Assoc
) loop
5882 Choice
:= First
(Choices
(Assoc
));
5883 while Present
(Choice
) loop
5884 Rewrite_Range
(Rec_Typ
, Choice
);
5897 (Component
=> Component
,
5899 Assoc_List
=> New_Assoc_List
);
5900 Set_Has_Self_Reference
(N
);
5902 elsif Needs_Simple_Initialization
(Ctyp
)
5903 or else Has_Non_Null_Base_Init_Proc
(Ctyp
)
5904 or else not Expander_Active
5907 (Component
=> Component
,
5909 Assoc_List
=> New_Assoc_List
,
5910 Is_Box_Present
=> True);
5912 -- Otherwise we only need to resolve the expression if the
5913 -- component has partially initialized values (required to
5914 -- expand the corresponding assignments and run-time checks).
5916 elsif Present
(Expr
)
5917 and then Is_Partially_Initialized_Type
(Ctyp
)
5919 Resolve_Aggr_Expr
(Expr
, Component
);
5921 end Check_Box_Component
;
5923 elsif No
(Expr
) then
5925 -- Ignore hidden components associated with the position of the
5926 -- interface tags: these are initialized dynamically.
5928 if No
(Related_Type
(Component
)) then
5930 ("no value supplied for component &!", N
, Component
);
5934 Resolve_Aggr_Expr
(Expr
, Component
);
5937 Next_Elmt
(Component_Elmt
);
5940 -- STEP 7: check for invalid components + check type in choice list
5944 New_Assoc
: Node_Id
;
5950 -- Type of first component in choice list
5953 if Present
(Component_Associations
(N
)) then
5954 Assoc
:= First
(Component_Associations
(N
));
5959 Verification
: while Present
(Assoc
) loop
5960 Selectr
:= First
(Choices
(Assoc
));
5963 if Nkind
(Selectr
) = N_Others_Choice
then
5965 -- Ada 2005 (AI-287): others choice may have expression or box
5967 if No
(Others_Etype
) and then Others_Box
= 0 then
5969 ("OTHERS must represent at least one component", Selectr
);
5971 elsif Others_Box
= 1 and then Warn_On_Redundant_Constructs
then
5972 Error_Msg_N
("OTHERS choice is redundant?r?", Box_Node
);
5974 ("\previous choices cover all components?r?", Box_Node
);
5980 while Present
(Selectr
) loop
5982 New_Assoc
:= First
(New_Assoc_List
);
5983 while Present
(New_Assoc
) loop
5984 Component
:= First
(Choices
(New_Assoc
));
5986 if Chars
(Selectr
) = Chars
(Component
) then
5988 Check_Identifier
(Selectr
, Entity
(Component
));
5997 -- If we found an association, then this is a legal component
5998 -- of the type in question.
6000 pragma Assert
(if Present
(New_Assoc
) then Present
(Component
));
6002 -- If no association, this is not a legal component of the type
6003 -- in question, unless its association is provided with a box.
6005 if No
(New_Assoc
) then
6006 if Box_Present
(Parent
(Selectr
)) then
6008 -- This may still be a bogus component with a box. Scan
6009 -- list of components to verify that a component with
6010 -- that name exists.
6016 C
:= First_Component
(Typ
);
6017 while Present
(C
) loop
6018 if Chars
(C
) = Chars
(Selectr
) then
6020 -- If the context is an extension aggregate,
6021 -- the component must not be inherited from
6022 -- the ancestor part of the aggregate.
6024 if Nkind
(N
) /= N_Extension_Aggregate
6026 Scope
(Original_Record_Component
(C
)) /=
6027 Etype
(Ancestor_Part
(N
))
6037 Error_Msg_Node_2
:= Typ
;
6038 Error_Msg_N
("& is not a component of}", Selectr
);
6042 elsif Chars
(Selectr
) /= Name_uTag
6043 and then Chars
(Selectr
) /= Name_uParent
6045 if not Has_Discriminants
(Typ
) then
6046 Error_Msg_Node_2
:= Typ
;
6047 Error_Msg_N
("& is not a component of}", Selectr
);
6050 ("& is not a component of the aggregate subtype",
6054 Check_Misspelled_Component
(Components
, Selectr
);
6057 elsif No
(Typech
) then
6058 Typech
:= Base_Type
(Etype
(Component
));
6060 -- AI05-0199: In Ada 2012, several components of anonymous
6061 -- access types can appear in a choice list, as long as the
6062 -- designated types match.
6064 elsif Typech
/= Base_Type
(Etype
(Component
)) then
6065 if Ada_Version
>= Ada_2012
6066 and then Ekind
(Typech
) = E_Anonymous_Access_Type
6068 Ekind
(Etype
(Component
)) = E_Anonymous_Access_Type
6069 and then Base_Type
(Designated_Type
(Typech
)) =
6070 Base_Type
(Designated_Type
(Etype
(Component
)))
6072 Subtypes_Statically_Match
(Typech
, (Etype
(Component
)))
6076 elsif not Box_Present
(Parent
(Selectr
)) then
6078 ("components in choice list must have same type",
6087 end loop Verification
;
6090 -- STEP 8: replace the original aggregate
6093 New_Aggregate
: constant Node_Id
:= New_Copy
(N
);
6096 Set_Expressions
(New_Aggregate
, No_List
);
6097 Set_Etype
(New_Aggregate
, Etype
(N
));
6098 Set_Component_Associations
(New_Aggregate
, New_Assoc_List
);
6099 Set_Check_Actuals
(New_Aggregate
, Check_Actuals
(N
));
6101 Rewrite
(N
, New_Aggregate
);
6104 -- Check the dimensions of the components in the record aggregate
6106 Analyze_Dimension_Extension_Or_Record_Aggregate
(N
);
6107 end Resolve_Record_Aggregate
;
6109 -----------------------------
6110 -- Check_Can_Never_Be_Null --
6111 -----------------------------
6113 procedure Check_Can_Never_Be_Null
(Typ
: Entity_Id
; Expr
: Node_Id
) is
6114 Comp_Typ
: Entity_Id
;
6118 (Ada_Version
>= Ada_2005
6119 and then Present
(Expr
)
6120 and then Known_Null
(Expr
));
6123 when E_Array_Type
=>
6124 Comp_Typ
:= Component_Type
(Typ
);
6129 Comp_Typ
:= Etype
(Typ
);
6135 if Can_Never_Be_Null
(Comp_Typ
) then
6137 -- Here we know we have a constraint error. Note that we do not use
6138 -- Apply_Compile_Time_Constraint_Error here to the Expr, which might
6139 -- seem the more natural approach. That's because in some cases the
6140 -- components are rewritten, and the replacement would be missed.
6141 -- We do not mark the whole aggregate as raising a constraint error,
6142 -- because the association may be a null array range.
6145 ("(Ada 2005) NULL not allowed in null-excluding component??", Expr
);
6147 ("\Constraint_Error will be raised at run time??", Expr
);
6150 Make_Raise_Constraint_Error
6151 (Sloc
(Expr
), Reason
=> CE_Access_Check_Failed
));
6152 Set_Etype
(Expr
, Comp_Typ
);
6153 Set_Analyzed
(Expr
);
6155 end Check_Can_Never_Be_Null
;
6157 ---------------------
6158 -- Sort_Case_Table --
6159 ---------------------
6161 procedure Sort_Case_Table
(Case_Table
: in out Case_Table_Type
) is
6162 U
: constant Int
:= Case_Table
'Last;
6170 T
:= Case_Table
(K
+ 1);
6174 and then Expr_Value
(Case_Table
(J
- 1).Lo
) > Expr_Value
(T
.Lo
)
6176 Case_Table
(J
) := Case_Table
(J
- 1);
6180 Case_Table
(J
) := T
;
6183 end Sort_Case_Table
;