PR rtl-optimization/79386
[official-gcc.git] / gcc / ada / sem_ch13.adb
blobac1e02cfee3b9ce4a7dc5999c05b7dfb25110ba5
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S E M _ C H 1 3 --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2016, Free Software Foundation, Inc. --
10 -- --
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. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 with Aspects; use Aspects;
27 with Atree; use Atree;
28 with Checks; use Checks;
29 with Debug; use Debug;
30 with Einfo; use Einfo;
31 with Elists; use Elists;
32 with Errout; use Errout;
33 with Expander; use Expander;
34 with Exp_Disp; use Exp_Disp;
35 with Exp_Tss; use Exp_Tss;
36 with Exp_Util; use Exp_Util;
37 with Freeze; use Freeze;
38 with Ghost; use Ghost;
39 with Lib; use Lib;
40 with Lib.Xref; use Lib.Xref;
41 with Namet; use Namet;
42 with Nlists; use Nlists;
43 with Nmake; use Nmake;
44 with Opt; use Opt;
45 with Restrict; use Restrict;
46 with Rident; use Rident;
47 with Rtsfind; use Rtsfind;
48 with Sem; use Sem;
49 with Sem_Aux; use Sem_Aux;
50 with Sem_Case; use Sem_Case;
51 with Sem_Ch3; use Sem_Ch3;
52 with Sem_Ch6; use Sem_Ch6;
53 with Sem_Ch8; use Sem_Ch8;
54 with Sem_Dim; use Sem_Dim;
55 with Sem_Disp; use Sem_Disp;
56 with Sem_Eval; use Sem_Eval;
57 with Sem_Prag; use Sem_Prag;
58 with Sem_Res; use Sem_Res;
59 with Sem_Type; use Sem_Type;
60 with Sem_Util; use Sem_Util;
61 with Sem_Warn; use Sem_Warn;
62 with Sinfo; use Sinfo;
63 with Sinput; use Sinput;
64 with Snames; use Snames;
65 with Stand; use Stand;
66 with Targparm; use Targparm;
67 with Ttypes; use Ttypes;
68 with Tbuild; use Tbuild;
69 with Urealp; use Urealp;
70 with Warnsw; use Warnsw;
72 with GNAT.Heap_Sort_G;
74 package body Sem_Ch13 is
76 SSU : constant Pos := System_Storage_Unit;
77 -- Convenient short hand for commonly used constant
79 -----------------------
80 -- Local Subprograms --
81 -----------------------
83 procedure Adjust_Record_For_Reverse_Bit_Order_Ada_95 (R : Entity_Id);
84 -- Helper routine providing the original (pre-AI95-0133) behavior for
85 -- Adjust_Record_For_Reverse_Bit_Order.
87 procedure Alignment_Check_For_Size_Change (Typ : Entity_Id; Size : Uint);
88 -- This routine is called after setting one of the sizes of type entity
89 -- Typ to Size. The purpose is to deal with the situation of a derived
90 -- type whose inherited alignment is no longer appropriate for the new
91 -- size value. In this case, we reset the Alignment to unknown.
93 procedure Build_Discrete_Static_Predicate
94 (Typ : Entity_Id;
95 Expr : Node_Id;
96 Nam : Name_Id);
97 -- Given a predicated type Typ, where Typ is a discrete static subtype,
98 -- whose predicate expression is Expr, tests if Expr is a static predicate,
99 -- and if so, builds the predicate range list. Nam is the name of the one
100 -- argument to the predicate function. Occurrences of the type name in the
101 -- predicate expression have been replaced by identifier references to this
102 -- name, which is unique, so any identifier with Chars matching Nam must be
103 -- a reference to the type. If the predicate is non-static, this procedure
104 -- returns doing nothing. If the predicate is static, then the predicate
105 -- list is stored in Static_Discrete_Predicate (Typ), and the Expr is
106 -- rewritten as a canonicalized membership operation.
108 function Build_Export_Import_Pragma
109 (Asp : Node_Id;
110 Id : Entity_Id) return Node_Id;
111 -- Create the corresponding pragma for aspect Export or Import denoted by
112 -- Asp. Id is the related entity subject to the aspect. Return Empty when
113 -- the expression of aspect Asp evaluates to False or is erroneous.
115 function Build_Predicate_Function_Declaration
116 (Typ : Entity_Id) return Node_Id;
117 -- Build the declaration for a predicate function. The declaration is built
118 -- at the end of the declarative part containing the type definition, which
119 -- may be before the freeze point of the type. The predicate expression is
120 -- pre-analyzed at this point, to catch visibility errors.
122 procedure Build_Predicate_Functions (Typ : Entity_Id; N : Node_Id);
123 -- If Typ has predicates (indicated by Has_Predicates being set for Typ),
124 -- then either there are pragma Predicate entries on the rep chain for the
125 -- type (note that Predicate aspects are converted to pragma Predicate), or
126 -- there are inherited aspects from a parent type, or ancestor subtypes.
127 -- This procedure builds body for the Predicate function that tests these
128 -- predicates. N is the freeze node for the type. The spec of the function
129 -- is inserted before the freeze node, and the body of the function is
130 -- inserted after the freeze node. If the predicate expression has a least
131 -- one Raise_Expression, then this procedure also builds the M version of
132 -- the predicate function for use in membership tests.
134 procedure Check_Pool_Size_Clash (Ent : Entity_Id; SP, SS : Node_Id);
135 -- Called if both Storage_Pool and Storage_Size attribute definition
136 -- clauses (SP and SS) are present for entity Ent. Issue error message.
138 procedure Freeze_Entity_Checks (N : Node_Id);
139 -- Called from Analyze_Freeze_Entity and Analyze_Generic_Freeze Entity
140 -- to generate appropriate semantic checks that are delayed until this
141 -- point (they had to be delayed this long for cases of delayed aspects,
142 -- e.g. analysis of statically predicated subtypes in choices, for which
143 -- we have to be sure the subtypes in question are frozen before checking).
145 function Get_Alignment_Value (Expr : Node_Id) return Uint;
146 -- Given the expression for an alignment value, returns the corresponding
147 -- Uint value. If the value is inappropriate, then error messages are
148 -- posted as required, and a value of No_Uint is returned.
150 procedure Get_Interfacing_Aspects
151 (Iface_Asp : Node_Id;
152 Conv_Asp : out Node_Id;
153 EN_Asp : out Node_Id;
154 Expo_Asp : out Node_Id;
155 Imp_Asp : out Node_Id;
156 LN_Asp : out Node_Id;
157 Do_Checks : Boolean := False);
158 -- Given a single interfacing aspect Iface_Asp, retrieve other interfacing
159 -- aspects that apply to the same related entity. The aspects considered by
160 -- this routine are as follows:
162 -- Conv_Asp - aspect Convention
163 -- EN_Asp - aspect External_Name
164 -- Expo_Asp - aspect Export
165 -- Imp_Asp - aspect Import
166 -- LN_Asp - aspect Link_Name
168 -- When flag Do_Checks is set, this routine will flag duplicate uses of
169 -- aspects.
171 function Is_Operational_Item (N : Node_Id) return Boolean;
172 -- A specification for a stream attribute is allowed before the full type
173 -- is declared, as explained in AI-00137 and the corrigendum. Attributes
174 -- that do not specify a representation characteristic are operational
175 -- attributes.
177 function Is_Predicate_Static
178 (Expr : Node_Id;
179 Nam : Name_Id) return Boolean;
180 -- Given predicate expression Expr, tests if Expr is predicate-static in
181 -- the sense of the rules in (RM 3.2.4 (15-24)). Occurrences of the type
182 -- name in the predicate expression have been replaced by references to
183 -- an identifier whose Chars field is Nam. This name is unique, so any
184 -- identifier with Chars matching Nam must be a reference to the type.
185 -- Returns True if the expression is predicate-static and False otherwise,
186 -- but is not in the business of setting flags or issuing error messages.
188 -- Only scalar types can have static predicates, so False is always
189 -- returned for non-scalar types.
191 -- Note: the RM seems to suggest that string types can also have static
192 -- predicates. But that really makes lttle sense as very few useful
193 -- predicates can be constructed for strings. Remember that:
195 -- "ABC" < "DEF"
197 -- is not a static expression. So even though the clearly faulty RM wording
198 -- allows the following:
200 -- subtype S is String with Static_Predicate => S < "DEF"
202 -- We can't allow this, otherwise we have predicate-static applying to a
203 -- larger class than static expressions, which was never intended.
205 procedure New_Stream_Subprogram
206 (N : Node_Id;
207 Ent : Entity_Id;
208 Subp : Entity_Id;
209 Nam : TSS_Name_Type);
210 -- Create a subprogram renaming of a given stream attribute to the
211 -- designated subprogram and then in the tagged case, provide this as a
212 -- primitive operation, or in the untagged case make an appropriate TSS
213 -- entry. This is more properly an expansion activity than just semantics,
214 -- but the presence of user-defined stream functions for limited types
215 -- is a legality check, which is why this takes place here rather than in
216 -- exp_ch13, where it was previously. Nam indicates the name of the TSS
217 -- function to be generated.
219 -- To avoid elaboration anomalies with freeze nodes, for untagged types
220 -- we generate both a subprogram declaration and a subprogram renaming
221 -- declaration, so that the attribute specification is handled as a
222 -- renaming_as_body. For tagged types, the specification is one of the
223 -- primitive specs.
225 procedure Resolve_Iterable_Operation
226 (N : Node_Id;
227 Cursor : Entity_Id;
228 Typ : Entity_Id;
229 Nam : Name_Id);
230 -- If the name of a primitive operation for an Iterable aspect is
231 -- overloaded, resolve according to required signature.
233 procedure Set_Biased
234 (E : Entity_Id;
235 N : Node_Id;
236 Msg : String;
237 Biased : Boolean := True);
238 -- If Biased is True, sets Has_Biased_Representation flag for E, and
239 -- outputs a warning message at node N if Warn_On_Biased_Representation is
240 -- is True. This warning inserts the string Msg to describe the construct
241 -- causing biasing.
243 ---------------------------------------------------
244 -- Table for Validate_Compile_Time_Warning_Error --
245 ---------------------------------------------------
247 -- The following table collects pragmas Compile_Time_Error and Compile_
248 -- Time_Warning for validation. Entries are made by calls to subprogram
249 -- Validate_Compile_Time_Warning_Error, and the call to the procedure
250 -- Validate_Compile_Time_Warning_Errors does the actual error checking
251 -- and posting of warning and error messages. The reason for this delayed
252 -- processing is to take advantage of back-annotations of attributes size
253 -- and alignment values performed by the back end.
255 -- Note: the reason we store a Source_Ptr value instead of a Node_Id is
256 -- that by the time Validate_Unchecked_Conversions is called, Sprint will
257 -- already have modified all Sloc values if the -gnatD option is set.
259 type CTWE_Entry is record
260 Eloc : Source_Ptr;
261 -- Source location used in warnings and error messages
263 Prag : Node_Id;
264 -- Pragma Compile_Time_Error or Compile_Time_Warning
266 Scope : Node_Id;
267 -- The scope which encloses the pragma
268 end record;
270 package Compile_Time_Warnings_Errors is new Table.Table (
271 Table_Component_Type => CTWE_Entry,
272 Table_Index_Type => Int,
273 Table_Low_Bound => 1,
274 Table_Initial => 50,
275 Table_Increment => 200,
276 Table_Name => "Compile_Time_Warnings_Errors");
278 ----------------------------------------------
279 -- Table for Validate_Unchecked_Conversions --
280 ----------------------------------------------
282 -- The following table collects unchecked conversions for validation.
283 -- Entries are made by Validate_Unchecked_Conversion and then the call
284 -- to Validate_Unchecked_Conversions does the actual error checking and
285 -- posting of warnings. The reason for this delayed processing is to take
286 -- advantage of back-annotations of size and alignment values performed by
287 -- the back end.
289 -- Note: the reason we store a Source_Ptr value instead of a Node_Id is
290 -- that by the time Validate_Unchecked_Conversions is called, Sprint will
291 -- already have modified all Sloc values if the -gnatD option is set.
293 type UC_Entry is record
294 Eloc : Source_Ptr; -- node used for posting warnings
295 Source : Entity_Id; -- source type for unchecked conversion
296 Target : Entity_Id; -- target type for unchecked conversion
297 Act_Unit : Entity_Id; -- actual function instantiated
298 end record;
300 package Unchecked_Conversions is new Table.Table (
301 Table_Component_Type => UC_Entry,
302 Table_Index_Type => Int,
303 Table_Low_Bound => 1,
304 Table_Initial => 50,
305 Table_Increment => 200,
306 Table_Name => "Unchecked_Conversions");
308 ----------------------------------------
309 -- Table for Validate_Address_Clauses --
310 ----------------------------------------
312 -- If an address clause has the form
314 -- for X'Address use Expr
316 -- where Expr has a value known at compile time or is of the form Y'Address
317 -- or recursively is a reference to a constant initialized with either of
318 -- these forms, and the value of Expr is not a multiple of X's alignment,
319 -- or if Y has a smaller alignment than X, then that merits a warning about
320 -- possible bad alignment. The following table collects address clauses of
321 -- this kind. We put these in a table so that they can be checked after the
322 -- back end has completed annotation of the alignments of objects, since we
323 -- can catch more cases that way.
325 type Address_Clause_Check_Record is record
326 N : Node_Id;
327 -- The address clause
329 X : Entity_Id;
330 -- The entity of the object subject to the address clause
332 A : Uint;
333 -- The value of the address in the first case
335 Y : Entity_Id;
336 -- The entity of the object being overlaid in the second case
338 Off : Boolean;
339 -- Whether the address is offset within Y in the second case
340 end record;
342 package Address_Clause_Checks is new Table.Table (
343 Table_Component_Type => Address_Clause_Check_Record,
344 Table_Index_Type => Int,
345 Table_Low_Bound => 1,
346 Table_Initial => 20,
347 Table_Increment => 200,
348 Table_Name => "Address_Clause_Checks");
350 -----------------------------------------
351 -- Adjust_Record_For_Reverse_Bit_Order --
352 -----------------------------------------
354 procedure Adjust_Record_For_Reverse_Bit_Order (R : Entity_Id) is
355 Max_Machine_Scalar_Size : constant Uint :=
356 UI_From_Int
357 (Standard_Long_Long_Integer_Size);
358 -- We use this as the maximum machine scalar size
360 SSU : constant Uint := UI_From_Int (System_Storage_Unit);
362 CC : Node_Id;
363 Comp : Node_Id;
364 Num_CC : Natural;
366 begin
367 -- Processing here used to depend on Ada version: the behavior was
368 -- changed by AI95-0133. However this AI is a Binding interpretation,
369 -- so we now implement it even in Ada 95 mode. The original behavior
370 -- from unamended Ada 95 is still available for compatibility under
371 -- debugging switch -gnatd.
373 if Ada_Version < Ada_2005 and then Debug_Flag_Dot_P then
374 Adjust_Record_For_Reverse_Bit_Order_Ada_95 (R);
375 return;
376 end if;
378 -- For Ada 2005, we do machine scalar processing, as fully described In
379 -- AI-133. This involves gathering all components which start at the
380 -- same byte offset and processing them together. Same approach is still
381 -- valid in later versions including Ada 2012.
383 -- This first loop through components does two things. First it deals
384 -- with the case of components with component clauses whose length is
385 -- greater than the maximum machine scalar size (either accepting them
386 -- or rejecting as needed). Second, it counts the number of components
387 -- with component clauses whose length does not exceed this maximum for
388 -- later processing.
390 Num_CC := 0;
391 Comp := First_Component_Or_Discriminant (R);
392 while Present (Comp) loop
393 CC := Component_Clause (Comp);
395 if Present (CC) then
396 declare
397 Fbit : constant Uint := Static_Integer (First_Bit (CC));
398 Lbit : constant Uint := Static_Integer (Last_Bit (CC));
400 begin
401 -- Case of component with last bit >= max machine scalar
403 if Lbit >= Max_Machine_Scalar_Size then
405 -- This is allowed only if first bit is zero, and last bit
406 -- + 1 is a multiple of storage unit size.
408 if Fbit = 0 and then (Lbit + 1) mod SSU = 0 then
410 -- This is the case to give a warning if enabled
412 if Warn_On_Reverse_Bit_Order then
413 Error_Msg_N
414 ("info: multi-byte field specified with "
415 & "non-standard Bit_Order?V?", CC);
417 if Bytes_Big_Endian then
418 Error_Msg_N
419 ("\bytes are not reversed "
420 & "(component is big-endian)?V?", CC);
421 else
422 Error_Msg_N
423 ("\bytes are not reversed "
424 & "(component is little-endian)?V?", CC);
425 end if;
426 end if;
428 -- Give error message for RM 13.5.1(10) violation
430 else
431 Error_Msg_FE
432 ("machine scalar rules not followed for&",
433 First_Bit (CC), Comp);
435 Error_Msg_Uint_1 := Lbit + 1;
436 Error_Msg_Uint_2 := Max_Machine_Scalar_Size;
437 Error_Msg_F
438 ("\last bit + 1 (^) exceeds maximum machine scalar "
439 & "size (^)", First_Bit (CC));
441 if (Lbit + 1) mod SSU /= 0 then
442 Error_Msg_Uint_1 := SSU;
443 Error_Msg_F
444 ("\and is not a multiple of Storage_Unit (^) "
445 & "(RM 13.5.1(10))", First_Bit (CC));
447 else
448 Error_Msg_Uint_1 := Fbit;
449 Error_Msg_F
450 ("\and first bit (^) is non-zero "
451 & "(RM 13.4.1(10))", First_Bit (CC));
452 end if;
453 end if;
455 -- OK case of machine scalar related component clause. For now,
456 -- just count them.
458 else
459 Num_CC := Num_CC + 1;
460 end if;
461 end;
462 end if;
464 Next_Component_Or_Discriminant (Comp);
465 end loop;
467 -- We need to sort the component clauses on the basis of the Position
468 -- values in the clause, so we can group clauses with the same Position
469 -- together to determine the relevant machine scalar size.
471 Sort_CC : declare
472 Comps : array (0 .. Num_CC) of Entity_Id;
473 -- Array to collect component and discriminant entities. The data
474 -- starts at index 1, the 0'th entry is for the sort routine.
476 function CP_Lt (Op1, Op2 : Natural) return Boolean;
477 -- Compare routine for Sort
479 procedure CP_Move (From : Natural; To : Natural);
480 -- Move routine for Sort
482 package Sorting is new GNAT.Heap_Sort_G (CP_Move, CP_Lt);
484 MaxL : Uint;
485 -- Maximum last bit value of any component in this set
487 MSS : Uint;
488 -- Corresponding machine scalar size
490 Start : Natural;
491 Stop : Natural;
492 -- Start and stop positions in the component list of the set of
493 -- components with the same starting position (that constitute
494 -- components in a single machine scalar).
496 -----------
497 -- CP_Lt --
498 -----------
500 function CP_Lt (Op1, Op2 : Natural) return Boolean is
501 begin
502 return
503 Position (Component_Clause (Comps (Op1))) <
504 Position (Component_Clause (Comps (Op2)));
505 end CP_Lt;
507 -------------
508 -- CP_Move --
509 -------------
511 procedure CP_Move (From : Natural; To : Natural) is
512 begin
513 Comps (To) := Comps (From);
514 end CP_Move;
516 -- Start of processing for Sort_CC
518 begin
519 -- Collect the machine scalar relevant component clauses
521 Num_CC := 0;
522 Comp := First_Component_Or_Discriminant (R);
523 while Present (Comp) loop
524 declare
525 CC : constant Node_Id := Component_Clause (Comp);
527 begin
528 -- Collect only component clauses whose last bit is less than
529 -- machine scalar size. Any component clause whose last bit
530 -- exceeds this value does not take part in machine scalar
531 -- layout considerations. The test for Error_Posted makes sure
532 -- we exclude component clauses for which we already posted an
533 -- error.
535 if Present (CC)
536 and then not Error_Posted (Last_Bit (CC))
537 and then Static_Integer (Last_Bit (CC)) <
538 Max_Machine_Scalar_Size
539 then
540 Num_CC := Num_CC + 1;
541 Comps (Num_CC) := Comp;
542 end if;
543 end;
545 Next_Component_Or_Discriminant (Comp);
546 end loop;
548 -- Sort by ascending position number
550 Sorting.Sort (Num_CC);
552 -- We now have all the components whose size does not exceed the max
553 -- machine scalar value, sorted by starting position. In this loop we
554 -- gather groups of clauses starting at the same position, to process
555 -- them in accordance with AI-133.
557 Stop := 0;
558 while Stop < Num_CC loop
559 Start := Stop + 1;
560 Stop := Start;
561 MaxL :=
562 Static_Integer
563 (Last_Bit (Component_Clause (Comps (Start))));
564 while Stop < Num_CC loop
565 if Static_Integer
566 (Position (Component_Clause (Comps (Stop + 1)))) =
567 Static_Integer
568 (Position (Component_Clause (Comps (Stop))))
569 then
570 Stop := Stop + 1;
571 MaxL :=
572 UI_Max
573 (MaxL,
574 Static_Integer
575 (Last_Bit
576 (Component_Clause (Comps (Stop)))));
577 else
578 exit;
579 end if;
580 end loop;
582 -- Now we have a group of component clauses from Start to Stop
583 -- whose positions are identical, and MaxL is the maximum last
584 -- bit value of any of these components.
586 -- We need to determine the corresponding machine scalar size.
587 -- This loop assumes that machine scalar sizes are even, and that
588 -- each possible machine scalar has twice as many bits as the next
589 -- smaller one.
591 MSS := Max_Machine_Scalar_Size;
592 while MSS mod 2 = 0
593 and then (MSS / 2) >= SSU
594 and then (MSS / 2) > MaxL
595 loop
596 MSS := MSS / 2;
597 end loop;
599 -- Here is where we fix up the Component_Bit_Offset value to
600 -- account for the reverse bit order. Some examples of what needs
601 -- to be done for the case of a machine scalar size of 8 are:
603 -- First_Bit .. Last_Bit Component_Bit_Offset
604 -- old new old new
606 -- 0 .. 0 7 .. 7 0 7
607 -- 0 .. 1 6 .. 7 0 6
608 -- 0 .. 2 5 .. 7 0 5
609 -- 0 .. 7 0 .. 7 0 4
611 -- 1 .. 1 6 .. 6 1 6
612 -- 1 .. 4 3 .. 6 1 3
613 -- 4 .. 7 0 .. 3 4 0
615 -- The rule is that the first bit is obtained by subtracting the
616 -- old ending bit from machine scalar size - 1.
618 for C in Start .. Stop loop
619 declare
620 Comp : constant Entity_Id := Comps (C);
621 CC : constant Node_Id := Component_Clause (Comp);
623 LB : constant Uint := Static_Integer (Last_Bit (CC));
624 NFB : constant Uint := MSS - Uint_1 - LB;
625 NLB : constant Uint := NFB + Esize (Comp) - 1;
626 Pos : constant Uint := Static_Integer (Position (CC));
628 begin
629 if Warn_On_Reverse_Bit_Order then
630 Error_Msg_Uint_1 := MSS;
631 Error_Msg_N
632 ("info: reverse bit order in machine scalar of "
633 & "length^?V?", First_Bit (CC));
634 Error_Msg_Uint_1 := NFB;
635 Error_Msg_Uint_2 := NLB;
637 if Bytes_Big_Endian then
638 Error_Msg_NE
639 ("\big-endian range for component & is ^ .. ^?V?",
640 First_Bit (CC), Comp);
641 else
642 Error_Msg_NE
643 ("\little-endian range for component & is ^ .. ^?V?",
644 First_Bit (CC), Comp);
645 end if;
646 end if;
648 Set_Component_Bit_Offset (Comp, Pos * SSU + NFB);
649 Set_Normalized_First_Bit (Comp, NFB mod SSU);
650 end;
651 end loop;
652 end loop;
653 end Sort_CC;
654 end Adjust_Record_For_Reverse_Bit_Order;
656 ------------------------------------------------
657 -- Adjust_Record_For_Reverse_Bit_Order_Ada_95 --
658 ------------------------------------------------
660 procedure Adjust_Record_For_Reverse_Bit_Order_Ada_95 (R : Entity_Id) is
661 CC : Node_Id;
662 Comp : Node_Id;
664 begin
665 -- For Ada 95, we just renumber bits within a storage unit. We do the
666 -- same for Ada 83 mode, since we recognize the Bit_Order attribute in
667 -- Ada 83, and are free to add this extension.
669 Comp := First_Component_Or_Discriminant (R);
670 while Present (Comp) loop
671 CC := Component_Clause (Comp);
673 -- If component clause is present, then deal with the non-default
674 -- bit order case for Ada 95 mode.
676 -- We only do this processing for the base type, and in fact that
677 -- is important, since otherwise if there are record subtypes, we
678 -- could reverse the bits once for each subtype, which is wrong.
680 if Present (CC) and then Ekind (R) = E_Record_Type then
681 declare
682 CFB : constant Uint := Component_Bit_Offset (Comp);
683 CSZ : constant Uint := Esize (Comp);
684 CLC : constant Node_Id := Component_Clause (Comp);
685 Pos : constant Node_Id := Position (CLC);
686 FB : constant Node_Id := First_Bit (CLC);
688 Storage_Unit_Offset : constant Uint :=
689 CFB / System_Storage_Unit;
691 Start_Bit : constant Uint :=
692 CFB mod System_Storage_Unit;
694 begin
695 -- Cases where field goes over storage unit boundary
697 if Start_Bit + CSZ > System_Storage_Unit then
699 -- Allow multi-byte field but generate warning
701 if Start_Bit mod System_Storage_Unit = 0
702 and then CSZ mod System_Storage_Unit = 0
703 then
704 Error_Msg_N
705 ("info: multi-byte field specified with non-standard "
706 & "Bit_Order?V?", CLC);
708 if Bytes_Big_Endian then
709 Error_Msg_N
710 ("\bytes are not reversed "
711 & "(component is big-endian)?V?", CLC);
712 else
713 Error_Msg_N
714 ("\bytes are not reversed "
715 & "(component is little-endian)?V?", CLC);
716 end if;
718 -- Do not allow non-contiguous field
720 else
721 Error_Msg_N
722 ("attempt to specify non-contiguous field not "
723 & "permitted", CLC);
724 Error_Msg_N
725 ("\caused by non-standard Bit_Order specified in "
726 & "legacy Ada 95 mode", CLC);
727 end if;
729 -- Case where field fits in one storage unit
731 else
732 -- Give warning if suspicious component clause
734 if Intval (FB) >= System_Storage_Unit
735 and then Warn_On_Reverse_Bit_Order
736 then
737 Error_Msg_N
738 ("info: Bit_Order clause does not affect byte "
739 & "ordering?V?", Pos);
740 Error_Msg_Uint_1 :=
741 Intval (Pos) + Intval (FB) /
742 System_Storage_Unit;
743 Error_Msg_N
744 ("info: position normalized to ^ before bit order "
745 & "interpreted?V?", Pos);
746 end if;
748 -- Here is where we fix up the Component_Bit_Offset value
749 -- to account for the reverse bit order. Some examples of
750 -- what needs to be done are:
752 -- First_Bit .. Last_Bit Component_Bit_Offset
753 -- old new old new
755 -- 0 .. 0 7 .. 7 0 7
756 -- 0 .. 1 6 .. 7 0 6
757 -- 0 .. 2 5 .. 7 0 5
758 -- 0 .. 7 0 .. 7 0 4
760 -- 1 .. 1 6 .. 6 1 6
761 -- 1 .. 4 3 .. 6 1 3
762 -- 4 .. 7 0 .. 3 4 0
764 -- The rule is that the first bit is is obtained by
765 -- subtracting the old ending bit from storage_unit - 1.
767 Set_Component_Bit_Offset (Comp,
768 (Storage_Unit_Offset * System_Storage_Unit) +
769 (System_Storage_Unit - 1) -
770 (Start_Bit + CSZ - 1));
772 Set_Normalized_First_Bit (Comp,
773 Component_Bit_Offset (Comp) mod System_Storage_Unit);
774 end if;
775 end;
776 end if;
778 Next_Component_Or_Discriminant (Comp);
779 end loop;
780 end Adjust_Record_For_Reverse_Bit_Order_Ada_95;
782 -------------------------------------
783 -- Alignment_Check_For_Size_Change --
784 -------------------------------------
786 procedure Alignment_Check_For_Size_Change (Typ : Entity_Id; Size : Uint) is
787 begin
788 -- If the alignment is known, and not set by a rep clause, and is
789 -- inconsistent with the size being set, then reset it to unknown,
790 -- we assume in this case that the size overrides the inherited
791 -- alignment, and that the alignment must be recomputed.
793 if Known_Alignment (Typ)
794 and then not Has_Alignment_Clause (Typ)
795 and then Size mod (Alignment (Typ) * SSU) /= 0
796 then
797 Init_Alignment (Typ);
798 end if;
799 end Alignment_Check_For_Size_Change;
801 -------------------------------------
802 -- Analyze_Aspects_At_Freeze_Point --
803 -------------------------------------
805 procedure Analyze_Aspects_At_Freeze_Point (E : Entity_Id) is
806 procedure Analyze_Aspect_Default_Value (ASN : Node_Id);
807 -- This routine analyzes an Aspect_Default_[Component_]Value denoted by
808 -- the aspect specification node ASN.
810 procedure Inherit_Delayed_Rep_Aspects (ASN : Node_Id);
811 -- As discussed in the spec of Aspects (see Aspect_Delay declaration),
812 -- a derived type can inherit aspects from its parent which have been
813 -- specified at the time of the derivation using an aspect, as in:
815 -- type A is range 1 .. 10
816 -- with Size => Not_Defined_Yet;
817 -- ..
818 -- type B is new A;
819 -- ..
820 -- Not_Defined_Yet : constant := 64;
822 -- In this example, the Size of A is considered to be specified prior
823 -- to the derivation, and thus inherited, even though the value is not
824 -- known at the time of derivation. To deal with this, we use two entity
825 -- flags. The flag Has_Derived_Rep_Aspects is set in the parent type (A
826 -- here), and then the flag May_Inherit_Delayed_Rep_Aspects is set in
827 -- the derived type (B here). If this flag is set when the derived type
828 -- is frozen, then this procedure is called to ensure proper inheritance
829 -- of all delayed aspects from the parent type. The derived type is E,
830 -- the argument to Analyze_Aspects_At_Freeze_Point. ASN is the first
831 -- aspect specification node in the Rep_Item chain for the parent type.
833 procedure Make_Pragma_From_Boolean_Aspect (ASN : Node_Id);
834 -- Given an aspect specification node ASN whose expression is an
835 -- optional Boolean, this routines creates the corresponding pragma
836 -- at the freezing point.
838 ----------------------------------
839 -- Analyze_Aspect_Default_Value --
840 ----------------------------------
842 procedure Analyze_Aspect_Default_Value (ASN : Node_Id) is
843 A_Id : constant Aspect_Id := Get_Aspect_Id (ASN);
844 Ent : constant Entity_Id := Entity (ASN);
845 Expr : constant Node_Id := Expression (ASN);
846 Id : constant Node_Id := Identifier (ASN);
848 begin
849 Error_Msg_Name_1 := Chars (Id);
851 if not Is_Type (Ent) then
852 Error_Msg_N ("aspect% can only apply to a type", Id);
853 return;
855 elsif not Is_First_Subtype (Ent) then
856 Error_Msg_N ("aspect% cannot apply to subtype", Id);
857 return;
859 elsif A_Id = Aspect_Default_Value
860 and then not Is_Scalar_Type (Ent)
861 then
862 Error_Msg_N ("aspect% can only be applied to scalar type", Id);
863 return;
865 elsif A_Id = Aspect_Default_Component_Value then
866 if not Is_Array_Type (Ent) then
867 Error_Msg_N ("aspect% can only be applied to array type", Id);
868 return;
870 elsif not Is_Scalar_Type (Component_Type (Ent)) then
871 Error_Msg_N ("aspect% requires scalar components", Id);
872 return;
873 end if;
874 end if;
876 Set_Has_Default_Aspect (Base_Type (Ent));
878 if Is_Scalar_Type (Ent) then
879 Set_Default_Aspect_Value (Base_Type (Ent), Expr);
880 else
881 Set_Default_Aspect_Component_Value (Base_Type (Ent), Expr);
882 end if;
883 end Analyze_Aspect_Default_Value;
885 ---------------------------------
886 -- Inherit_Delayed_Rep_Aspects --
887 ---------------------------------
889 procedure Inherit_Delayed_Rep_Aspects (ASN : Node_Id) is
890 A_Id : constant Aspect_Id := Get_Aspect_Id (ASN);
891 P : constant Entity_Id := Entity (ASN);
892 -- Entithy for parent type
894 N : Node_Id;
895 -- Item from Rep_Item chain
897 A : Aspect_Id;
899 begin
900 -- Loop through delayed aspects for the parent type
902 N := ASN;
903 while Present (N) loop
904 if Nkind (N) = N_Aspect_Specification then
905 exit when Entity (N) /= P;
907 if Is_Delayed_Aspect (N) then
908 A := Get_Aspect_Id (Chars (Identifier (N)));
910 -- Process delayed rep aspect. For Boolean attributes it is
911 -- not possible to cancel an attribute once set (the attempt
912 -- to use an aspect with xxx => False is an error) for a
913 -- derived type. So for those cases, we do not have to check
914 -- if a clause has been given for the derived type, since it
915 -- is harmless to set it again if it is already set.
917 case A is
919 -- Alignment
921 when Aspect_Alignment =>
922 if not Has_Alignment_Clause (E) then
923 Set_Alignment (E, Alignment (P));
924 end if;
926 -- Atomic
928 when Aspect_Atomic =>
929 if Is_Atomic (P) then
930 Set_Is_Atomic (E);
931 end if;
933 -- Atomic_Components
935 when Aspect_Atomic_Components =>
936 if Has_Atomic_Components (P) then
937 Set_Has_Atomic_Components (Base_Type (E));
938 end if;
940 -- Bit_Order
942 when Aspect_Bit_Order =>
943 if Is_Record_Type (E)
944 and then No (Get_Attribute_Definition_Clause
945 (E, Attribute_Bit_Order))
946 and then Reverse_Bit_Order (P)
947 then
948 Set_Reverse_Bit_Order (Base_Type (E));
949 end if;
951 -- Component_Size
953 when Aspect_Component_Size =>
954 if Is_Array_Type (E)
955 and then not Has_Component_Size_Clause (E)
956 then
957 Set_Component_Size
958 (Base_Type (E), Component_Size (P));
959 end if;
961 -- Machine_Radix
963 when Aspect_Machine_Radix =>
964 if Is_Decimal_Fixed_Point_Type (E)
965 and then not Has_Machine_Radix_Clause (E)
966 then
967 Set_Machine_Radix_10 (E, Machine_Radix_10 (P));
968 end if;
970 -- Object_Size (also Size which also sets Object_Size)
972 when Aspect_Object_Size
973 | Aspect_Size
975 if not Has_Size_Clause (E)
976 and then
977 No (Get_Attribute_Definition_Clause
978 (E, Attribute_Object_Size))
979 then
980 Set_Esize (E, Esize (P));
981 end if;
983 -- Pack
985 when Aspect_Pack =>
986 if not Is_Packed (E) then
987 Set_Is_Packed (Base_Type (E));
989 if Is_Bit_Packed_Array (P) then
990 Set_Is_Bit_Packed_Array (Base_Type (E));
991 Set_Packed_Array_Impl_Type
992 (E, Packed_Array_Impl_Type (P));
993 end if;
994 end if;
996 -- Scalar_Storage_Order
998 when Aspect_Scalar_Storage_Order =>
999 if (Is_Record_Type (E) or else Is_Array_Type (E))
1000 and then No (Get_Attribute_Definition_Clause
1001 (E, Attribute_Scalar_Storage_Order))
1002 and then Reverse_Storage_Order (P)
1003 then
1004 Set_Reverse_Storage_Order (Base_Type (E));
1006 -- Clear default SSO indications, since the aspect
1007 -- overrides the default.
1009 Set_SSO_Set_Low_By_Default (Base_Type (E), False);
1010 Set_SSO_Set_High_By_Default (Base_Type (E), False);
1011 end if;
1013 -- Small
1015 when Aspect_Small =>
1016 if Is_Fixed_Point_Type (E)
1017 and then not Has_Small_Clause (E)
1018 then
1019 Set_Small_Value (E, Small_Value (P));
1020 end if;
1022 -- Storage_Size
1024 when Aspect_Storage_Size =>
1025 if (Is_Access_Type (E) or else Is_Task_Type (E))
1026 and then not Has_Storage_Size_Clause (E)
1027 then
1028 Set_Storage_Size_Variable
1029 (Base_Type (E), Storage_Size_Variable (P));
1030 end if;
1032 -- Value_Size
1034 when Aspect_Value_Size =>
1036 -- Value_Size is never inherited, it is either set by
1037 -- default, or it is explicitly set for the derived
1038 -- type. So nothing to do here.
1040 null;
1042 -- Volatile
1044 when Aspect_Volatile =>
1045 if Is_Volatile (P) then
1046 Set_Is_Volatile (E);
1047 end if;
1049 -- Volatile_Full_Access
1051 when Aspect_Volatile_Full_Access =>
1052 if Is_Volatile_Full_Access (P) then
1053 Set_Is_Volatile_Full_Access (E);
1054 end if;
1056 -- Volatile_Components
1058 when Aspect_Volatile_Components =>
1059 if Has_Volatile_Components (P) then
1060 Set_Has_Volatile_Components (Base_Type (E));
1061 end if;
1063 -- That should be all the Rep Aspects
1065 when others =>
1066 pragma Assert (Aspect_Delay (A_Id) /= Rep_Aspect);
1067 null;
1068 end case;
1069 end if;
1070 end if;
1072 N := Next_Rep_Item (N);
1073 end loop;
1074 end Inherit_Delayed_Rep_Aspects;
1076 -------------------------------------
1077 -- Make_Pragma_From_Boolean_Aspect --
1078 -------------------------------------
1080 procedure Make_Pragma_From_Boolean_Aspect (ASN : Node_Id) is
1081 Ident : constant Node_Id := Identifier (ASN);
1082 A_Name : constant Name_Id := Chars (Ident);
1083 A_Id : constant Aspect_Id := Get_Aspect_Id (A_Name);
1084 Ent : constant Entity_Id := Entity (ASN);
1085 Expr : constant Node_Id := Expression (ASN);
1086 Loc : constant Source_Ptr := Sloc (ASN);
1088 procedure Check_False_Aspect_For_Derived_Type;
1089 -- This procedure checks for the case of a false aspect for a derived
1090 -- type, which improperly tries to cancel an aspect inherited from
1091 -- the parent.
1093 -----------------------------------------
1094 -- Check_False_Aspect_For_Derived_Type --
1095 -----------------------------------------
1097 procedure Check_False_Aspect_For_Derived_Type is
1098 Par : Node_Id;
1100 begin
1101 -- We are only checking derived types
1103 if not Is_Derived_Type (E) then
1104 return;
1105 end if;
1107 Par := Nearest_Ancestor (E);
1109 case A_Id is
1110 when Aspect_Atomic
1111 | Aspect_Shared
1113 if not Is_Atomic (Par) then
1114 return;
1115 end if;
1117 when Aspect_Atomic_Components =>
1118 if not Has_Atomic_Components (Par) then
1119 return;
1120 end if;
1122 when Aspect_Discard_Names =>
1123 if not Discard_Names (Par) then
1124 return;
1125 end if;
1127 when Aspect_Pack =>
1128 if not Is_Packed (Par) then
1129 return;
1130 end if;
1132 when Aspect_Unchecked_Union =>
1133 if not Is_Unchecked_Union (Par) then
1134 return;
1135 end if;
1137 when Aspect_Volatile =>
1138 if not Is_Volatile (Par) then
1139 return;
1140 end if;
1142 when Aspect_Volatile_Components =>
1143 if not Has_Volatile_Components (Par) then
1144 return;
1145 end if;
1147 when Aspect_Volatile_Full_Access =>
1148 if not Is_Volatile_Full_Access (Par) then
1149 return;
1150 end if;
1152 when others =>
1153 return;
1154 end case;
1156 -- Fall through means we are canceling an inherited aspect
1158 Error_Msg_Name_1 := A_Name;
1159 Error_Msg_NE
1160 ("derived type& inherits aspect%, cannot cancel", Expr, E);
1161 end Check_False_Aspect_For_Derived_Type;
1163 -- Local variables
1165 Prag : Node_Id;
1167 -- Start of processing for Make_Pragma_From_Boolean_Aspect
1169 begin
1170 -- Note that we know Expr is present, because for a missing Expr
1171 -- argument, we knew it was True and did not need to delay the
1172 -- evaluation to the freeze point.
1174 if Is_False (Static_Boolean (Expr)) then
1175 Check_False_Aspect_For_Derived_Type;
1177 else
1178 Prag :=
1179 Make_Pragma (Loc,
1180 Pragma_Identifier =>
1181 Make_Identifier (Sloc (Ident), Chars (Ident)),
1182 Pragma_Argument_Associations => New_List (
1183 Make_Pragma_Argument_Association (Sloc (Ident),
1184 Expression => New_Occurrence_Of (Ent, Sloc (Ident)))));
1186 Set_From_Aspect_Specification (Prag, True);
1187 Set_Corresponding_Aspect (Prag, ASN);
1188 Set_Aspect_Rep_Item (ASN, Prag);
1189 Set_Is_Delayed_Aspect (Prag);
1190 Set_Parent (Prag, ASN);
1191 end if;
1192 end Make_Pragma_From_Boolean_Aspect;
1194 -- Local variables
1196 A_Id : Aspect_Id;
1197 ASN : Node_Id;
1198 Ritem : Node_Id;
1200 -- Start of processing for Analyze_Aspects_At_Freeze_Point
1202 begin
1203 -- Must be visible in current scope
1205 if not Scope_Within_Or_Same (Current_Scope, Scope (E)) then
1206 return;
1207 end if;
1209 -- Look for aspect specification entries for this entity
1211 ASN := First_Rep_Item (E);
1212 while Present (ASN) loop
1213 if Nkind (ASN) = N_Aspect_Specification then
1214 exit when Entity (ASN) /= E;
1216 if Is_Delayed_Aspect (ASN) then
1217 A_Id := Get_Aspect_Id (ASN);
1219 case A_Id is
1221 -- For aspects whose expression is an optional Boolean, make
1222 -- the corresponding pragma at the freeze point.
1224 when Boolean_Aspects
1225 | Library_Unit_Aspects
1227 -- Aspects Export and Import require special handling.
1228 -- Both are by definition Boolean and may benefit from
1229 -- forward references, however their expressions are
1230 -- treated as static. In addition, the syntax of their
1231 -- corresponding pragmas requires extra "pieces" which
1232 -- may also contain forward references. To account for
1233 -- all of this, the corresponding pragma is created by
1234 -- Analyze_Aspect_Export_Import, but is not analyzed as
1235 -- the complete analysis must happen now.
1237 if A_Id = Aspect_Export or else A_Id = Aspect_Import then
1238 null;
1240 -- Otherwise create a corresponding pragma
1242 else
1243 Make_Pragma_From_Boolean_Aspect (ASN);
1244 end if;
1246 -- Special handling for aspects that don't correspond to
1247 -- pragmas/attributes.
1249 when Aspect_Default_Value
1250 | Aspect_Default_Component_Value
1252 -- Do not inherit aspect for anonymous base type of a
1253 -- scalar or array type, because they apply to the first
1254 -- subtype of the type, and will be processed when that
1255 -- first subtype is frozen.
1257 if Is_Derived_Type (E)
1258 and then not Comes_From_Source (E)
1259 and then E /= First_Subtype (E)
1260 then
1261 null;
1262 else
1263 Analyze_Aspect_Default_Value (ASN);
1264 end if;
1266 -- Ditto for iterator aspects, because the corresponding
1267 -- attributes may not have been analyzed yet.
1269 when Aspect_Constant_Indexing
1270 | Aspect_Default_Iterator
1271 | Aspect_Iterator_Element
1272 | Aspect_Variable_Indexing
1274 Analyze (Expression (ASN));
1276 if Etype (Expression (ASN)) = Any_Type then
1277 Error_Msg_NE
1278 ("\aspect must be fully defined before & is frozen",
1279 ASN, E);
1280 end if;
1282 when Aspect_Iterable =>
1283 Validate_Iterable_Aspect (E, ASN);
1285 when others =>
1286 null;
1287 end case;
1289 Ritem := Aspect_Rep_Item (ASN);
1291 if Present (Ritem) then
1292 Analyze (Ritem);
1293 end if;
1294 end if;
1295 end if;
1297 Next_Rep_Item (ASN);
1298 end loop;
1300 -- This is where we inherit delayed rep aspects from our parent. Note
1301 -- that if we fell out of the above loop with ASN non-empty, it means
1302 -- we hit an aspect for an entity other than E, and it must be the
1303 -- type from which we were derived.
1305 if May_Inherit_Delayed_Rep_Aspects (E) then
1306 Inherit_Delayed_Rep_Aspects (ASN);
1307 end if;
1308 end Analyze_Aspects_At_Freeze_Point;
1310 -----------------------------------
1311 -- Analyze_Aspect_Specifications --
1312 -----------------------------------
1314 procedure Analyze_Aspect_Specifications (N : Node_Id; E : Entity_Id) is
1315 procedure Decorate (Asp : Node_Id; Prag : Node_Id);
1316 -- Establish linkages between an aspect and its corresponding pragma
1318 procedure Insert_Pragma
1319 (Prag : Node_Id;
1320 Is_Instance : Boolean := False);
1321 -- Subsidiary to the analysis of aspects
1322 -- Abstract_State
1323 -- Attach_Handler
1324 -- Contract_Cases
1325 -- Depends
1326 -- Ghost
1327 -- Global
1328 -- Initial_Condition
1329 -- Initializes
1330 -- Post
1331 -- Pre
1332 -- Refined_Depends
1333 -- Refined_Global
1334 -- Refined_State
1335 -- SPARK_Mode
1336 -- Warnings
1337 -- Insert pragma Prag such that it mimics the placement of a source
1338 -- pragma of the same kind. Flag Is_Generic should be set when the
1339 -- context denotes a generic instance.
1341 --------------
1342 -- Decorate --
1343 --------------
1345 procedure Decorate (Asp : Node_Id; Prag : Node_Id) is
1346 begin
1347 Set_Aspect_Rep_Item (Asp, Prag);
1348 Set_Corresponding_Aspect (Prag, Asp);
1349 Set_From_Aspect_Specification (Prag);
1350 Set_Parent (Prag, Asp);
1351 end Decorate;
1353 -------------------
1354 -- Insert_Pragma --
1355 -------------------
1357 procedure Insert_Pragma
1358 (Prag : Node_Id;
1359 Is_Instance : Boolean := False)
1361 Aux : Node_Id;
1362 Decl : Node_Id;
1363 Decls : List_Id;
1364 Def : Node_Id;
1365 Inserted : Boolean := False;
1367 begin
1368 -- When the aspect appears on an entry, package, protected unit,
1369 -- subprogram, or task unit body, insert the generated pragma at the
1370 -- top of the body declarations to emulate the behavior of a source
1371 -- pragma.
1373 -- package body Pack with Aspect is
1375 -- package body Pack is
1376 -- pragma Prag;
1378 if Nkind_In (N, N_Entry_Body,
1379 N_Package_Body,
1380 N_Protected_Body,
1381 N_Subprogram_Body,
1382 N_Task_Body)
1383 then
1384 Decls := Declarations (N);
1386 if No (Decls) then
1387 Decls := New_List;
1388 Set_Declarations (N, Decls);
1389 end if;
1391 Prepend_To (Decls, Prag);
1393 -- When the aspect is associated with a [generic] package declaration
1394 -- insert the generated pragma at the top of the visible declarations
1395 -- to emulate the behavior of a source pragma.
1397 -- package Pack with Aspect is
1399 -- package Pack is
1400 -- pragma Prag;
1402 elsif Nkind_In (N, N_Generic_Package_Declaration,
1403 N_Package_Declaration)
1404 then
1405 Decls := Visible_Declarations (Specification (N));
1407 if No (Decls) then
1408 Decls := New_List;
1409 Set_Visible_Declarations (Specification (N), Decls);
1410 end if;
1412 -- The visible declarations of a generic instance have the
1413 -- following structure:
1415 -- <renamings of generic formals>
1416 -- <renamings of internally-generated spec and body>
1417 -- <first source declaration>
1419 -- Insert the pragma before the first source declaration by
1420 -- skipping the instance "header" to ensure proper visibility of
1421 -- all formals.
1423 if Is_Instance then
1424 Decl := First (Decls);
1425 while Present (Decl) loop
1426 if Comes_From_Source (Decl) then
1427 Insert_Before (Decl, Prag);
1428 Inserted := True;
1429 exit;
1430 else
1431 Next (Decl);
1432 end if;
1433 end loop;
1435 -- The pragma is placed after the instance "header"
1437 if not Inserted then
1438 Append_To (Decls, Prag);
1439 end if;
1441 -- Otherwise this is not a generic instance
1443 else
1444 Prepend_To (Decls, Prag);
1445 end if;
1447 -- When the aspect is associated with a protected unit declaration,
1448 -- insert the generated pragma at the top of the visible declarations
1449 -- the emulate the behavior of a source pragma.
1451 -- protected [type] Prot with Aspect is
1453 -- protected [type] Prot is
1454 -- pragma Prag;
1456 elsif Nkind (N) = N_Protected_Type_Declaration then
1457 Def := Protected_Definition (N);
1459 if No (Def) then
1460 Def :=
1461 Make_Protected_Definition (Sloc (N),
1462 Visible_Declarations => New_List,
1463 End_Label => Empty);
1465 Set_Protected_Definition (N, Def);
1466 end if;
1468 Decls := Visible_Declarations (Def);
1470 if No (Decls) then
1471 Decls := New_List;
1472 Set_Visible_Declarations (Def, Decls);
1473 end if;
1475 Prepend_To (Decls, Prag);
1477 -- When the aspect is associated with a task unit declaration, insert
1478 -- insert the generated pragma at the top of the visible declarations
1479 -- the emulate the behavior of a source pragma.
1481 -- task [type] Prot with Aspect is
1483 -- task [type] Prot is
1484 -- pragma Prag;
1486 elsif Nkind (N) = N_Task_Type_Declaration then
1487 Def := Task_Definition (N);
1489 if No (Def) then
1490 Def :=
1491 Make_Task_Definition (Sloc (N),
1492 Visible_Declarations => New_List,
1493 End_Label => Empty);
1495 Set_Task_Definition (N, Def);
1496 end if;
1498 Decls := Visible_Declarations (Def);
1500 if No (Decls) then
1501 Decls := New_List;
1502 Set_Visible_Declarations (Def, Decls);
1503 end if;
1505 Prepend_To (Decls, Prag);
1507 -- When the context is a library unit, the pragma is added to the
1508 -- Pragmas_After list.
1510 elsif Nkind (Parent (N)) = N_Compilation_Unit then
1511 Aux := Aux_Decls_Node (Parent (N));
1513 if No (Pragmas_After (Aux)) then
1514 Set_Pragmas_After (Aux, New_List);
1515 end if;
1517 Prepend (Prag, Pragmas_After (Aux));
1519 -- Default, the pragma is inserted after the context
1521 else
1522 Insert_After (N, Prag);
1523 end if;
1524 end Insert_Pragma;
1526 -- Local variables
1528 Aspect : Node_Id;
1529 Aitem : Node_Id;
1530 Ent : Node_Id;
1532 L : constant List_Id := Aspect_Specifications (N);
1534 Ins_Node : Node_Id := N;
1535 -- Insert pragmas/attribute definition clause after this node when no
1536 -- delayed analysis is required.
1538 -- Start of processing for Analyze_Aspect_Specifications
1540 begin
1541 -- The general processing involves building an attribute definition
1542 -- clause or a pragma node that corresponds to the aspect. Then in order
1543 -- to delay the evaluation of this aspect to the freeze point, we attach
1544 -- the corresponding pragma/attribute definition clause to the aspect
1545 -- specification node, which is then placed in the Rep Item chain. In
1546 -- this case we mark the entity by setting the flag Has_Delayed_Aspects
1547 -- and we evaluate the rep item at the freeze point. When the aspect
1548 -- doesn't have a corresponding pragma/attribute definition clause, then
1549 -- its analysis is simply delayed at the freeze point.
1551 -- Some special cases don't require delay analysis, thus the aspect is
1552 -- analyzed right now.
1554 -- Note that there is a special handling for Pre, Post, Test_Case,
1555 -- Contract_Cases aspects. In these cases, we do not have to worry
1556 -- about delay issues, since the pragmas themselves deal with delay
1557 -- of visibility for the expression analysis. Thus, we just insert
1558 -- the pragma after the node N.
1560 pragma Assert (Present (L));
1562 -- Loop through aspects
1564 Aspect := First (L);
1565 Aspect_Loop : while Present (Aspect) loop
1566 Analyze_One_Aspect : declare
1567 Expr : constant Node_Id := Expression (Aspect);
1568 Id : constant Node_Id := Identifier (Aspect);
1569 Loc : constant Source_Ptr := Sloc (Aspect);
1570 Nam : constant Name_Id := Chars (Id);
1571 A_Id : constant Aspect_Id := Get_Aspect_Id (Nam);
1572 Anod : Node_Id;
1574 Delay_Required : Boolean;
1575 -- Set False if delay is not required
1577 Eloc : Source_Ptr := No_Location;
1578 -- Source location of expression, modified when we split PPC's. It
1579 -- is set below when Expr is present.
1581 procedure Analyze_Aspect_Convention;
1582 -- Perform analysis of aspect Convention
1584 procedure Analyze_Aspect_Export_Import;
1585 -- Perform analysis of aspects Export or Import
1587 procedure Analyze_Aspect_External_Link_Name;
1588 -- Perform analysis of aspects External_Name or Link_Name
1590 procedure Analyze_Aspect_Implicit_Dereference;
1591 -- Perform analysis of the Implicit_Dereference aspects
1593 procedure Make_Aitem_Pragma
1594 (Pragma_Argument_Associations : List_Id;
1595 Pragma_Name : Name_Id);
1596 -- This is a wrapper for Make_Pragma used for converting aspects
1597 -- to pragmas. It takes care of Sloc (set from Loc) and building
1598 -- the pragma identifier from the given name. In addition the
1599 -- flags Class_Present and Split_PPC are set from the aspect
1600 -- node, as well as Is_Ignored. This routine also sets the
1601 -- From_Aspect_Specification in the resulting pragma node to
1602 -- True, and sets Corresponding_Aspect to point to the aspect.
1603 -- The resulting pragma is assigned to Aitem.
1605 -------------------------------
1606 -- Analyze_Aspect_Convention --
1607 -------------------------------
1609 procedure Analyze_Aspect_Convention is
1610 Conv : Node_Id;
1611 Dummy_1 : Node_Id;
1612 Dummy_2 : Node_Id;
1613 Dummy_3 : Node_Id;
1614 Expo : Node_Id;
1615 Imp : Node_Id;
1617 begin
1618 -- Obtain all interfacing aspects that apply to the related
1619 -- entity.
1621 Get_Interfacing_Aspects
1622 (Iface_Asp => Aspect,
1623 Conv_Asp => Dummy_1,
1624 EN_Asp => Dummy_2,
1625 Expo_Asp => Expo,
1626 Imp_Asp => Imp,
1627 LN_Asp => Dummy_3,
1628 Do_Checks => True);
1630 -- The related entity is subject to aspect Export or Import.
1631 -- Do not process Convention now because it must be analysed
1632 -- as part of Export or Import.
1634 if Present (Expo) or else Present (Imp) then
1635 return;
1637 -- Otherwise Convention appears by itself
1639 else
1640 -- The aspect specifies a particular convention
1642 if Present (Expr) then
1643 Conv := New_Copy_Tree (Expr);
1645 -- Otherwise assume convention Ada
1647 else
1648 Conv := Make_Identifier (Loc, Name_Ada);
1649 end if;
1651 -- Generate:
1652 -- pragma Convention (<Conv>, <E>);
1654 Make_Aitem_Pragma
1655 (Pragma_Name => Name_Convention,
1656 Pragma_Argument_Associations => New_List (
1657 Make_Pragma_Argument_Association (Loc,
1658 Expression => Conv),
1659 Make_Pragma_Argument_Association (Loc,
1660 Expression => New_Occurrence_Of (E, Loc))));
1662 Decorate (Aspect, Aitem);
1663 Insert_Pragma (Aitem);
1664 end if;
1665 end Analyze_Aspect_Convention;
1667 ----------------------------------
1668 -- Analyze_Aspect_Export_Import --
1669 ----------------------------------
1671 procedure Analyze_Aspect_Export_Import is
1672 Dummy_1 : Node_Id;
1673 Dummy_2 : Node_Id;
1674 Dummy_3 : Node_Id;
1675 Expo : Node_Id;
1676 Imp : Node_Id;
1678 begin
1679 -- Obtain all interfacing aspects that apply to the related
1680 -- entity.
1682 Get_Interfacing_Aspects
1683 (Iface_Asp => Aspect,
1684 Conv_Asp => Dummy_1,
1685 EN_Asp => Dummy_2,
1686 Expo_Asp => Expo,
1687 Imp_Asp => Imp,
1688 LN_Asp => Dummy_3,
1689 Do_Checks => True);
1691 -- The related entity cannot be subject to both aspects Export
1692 -- and Import.
1694 if Present (Expo) and then Present (Imp) then
1695 Error_Msg_N
1696 ("incompatible interfacing aspects given for &", E);
1697 Error_Msg_Sloc := Sloc (Expo);
1698 Error_Msg_N ("\aspect `Export` #", E);
1699 Error_Msg_Sloc := Sloc (Imp);
1700 Error_Msg_N ("\aspect `Import` #", E);
1701 end if;
1703 -- A variable is most likely modified from the outside. Take
1704 -- Take the optimistic approach to avoid spurious errors.
1706 if Ekind (E) = E_Variable then
1707 Set_Never_Set_In_Source (E, False);
1708 end if;
1710 -- Resolve the expression of an Import or Export here, and
1711 -- require it to be of type Boolean and static. This is not
1712 -- quite right, because in general this should be delayed,
1713 -- but that seems tricky for these, because normally Boolean
1714 -- aspects are replaced with pragmas at the freeze point in
1715 -- Make_Pragma_From_Boolean_Aspect.
1717 if not Present (Expr)
1718 or else Is_True (Static_Boolean (Expr))
1719 then
1720 if A_Id = Aspect_Import then
1721 Set_Has_Completion (E);
1722 Set_Is_Imported (E);
1724 -- An imported object cannot be explicitly initialized
1726 if Nkind (N) = N_Object_Declaration
1727 and then Present (Expression (N))
1728 then
1729 Error_Msg_N
1730 ("imported entities cannot be initialized "
1731 & "(RM B.1(24))", Expression (N));
1732 end if;
1734 else
1735 pragma Assert (A_Id = Aspect_Export);
1736 Set_Is_Exported (E);
1737 end if;
1739 -- Create the proper form of pragma Export or Import taking
1740 -- into account Conversion, External_Name, and Link_Name.
1742 Aitem := Build_Export_Import_Pragma (Aspect, E);
1744 -- Otherwise the expression is either False or erroneous. There
1745 -- is no corresponding pragma.
1747 else
1748 Aitem := Empty;
1749 end if;
1750 end Analyze_Aspect_Export_Import;
1752 ---------------------------------------
1753 -- Analyze_Aspect_External_Link_Name --
1754 ---------------------------------------
1756 procedure Analyze_Aspect_External_Link_Name is
1757 Dummy_1 : Node_Id;
1758 Dummy_2 : Node_Id;
1759 Dummy_3 : Node_Id;
1760 Expo : Node_Id;
1761 Imp : Node_Id;
1763 begin
1764 -- Obtain all interfacing aspects that apply to the related
1765 -- entity.
1767 Get_Interfacing_Aspects
1768 (Iface_Asp => Aspect,
1769 Conv_Asp => Dummy_1,
1770 EN_Asp => Dummy_2,
1771 Expo_Asp => Expo,
1772 Imp_Asp => Imp,
1773 LN_Asp => Dummy_3,
1774 Do_Checks => True);
1776 -- Ensure that aspect External_Name applies to aspect Export or
1777 -- Import.
1779 if A_Id = Aspect_External_Name then
1780 if No (Expo) and then No (Imp) then
1781 Error_Msg_N
1782 ("aspect `External_Name` requires aspect `Import` or "
1783 & "`Export`", Aspect);
1784 end if;
1786 -- Otherwise ensure that aspect Link_Name applies to aspect
1787 -- Export or Import.
1789 else
1790 pragma Assert (A_Id = Aspect_Link_Name);
1791 if No (Expo) and then No (Imp) then
1792 Error_Msg_N
1793 ("aspect `Link_Name` requires aspect `Import` or "
1794 & "`Export`", Aspect);
1795 end if;
1796 end if;
1797 end Analyze_Aspect_External_Link_Name;
1799 -----------------------------------------
1800 -- Analyze_Aspect_Implicit_Dereference --
1801 -----------------------------------------
1803 procedure Analyze_Aspect_Implicit_Dereference is
1804 Disc : Entity_Id;
1805 Parent_Disc : Entity_Id;
1807 begin
1808 if not Is_Type (E) or else not Has_Discriminants (E) then
1809 Error_Msg_N
1810 ("aspect must apply to a type with discriminants", Expr);
1812 elsif not Is_Entity_Name (Expr) then
1813 Error_Msg_N
1814 ("aspect must name a discriminant of current type", Expr);
1816 else
1817 -- Discriminant type be an anonymous access type or an
1818 -- anonymous access to subprogram.
1820 -- Missing synchronized types???
1822 Disc := First_Discriminant (E);
1823 while Present (Disc) loop
1824 if Chars (Expr) = Chars (Disc)
1825 and then Ekind_In (Etype (Disc),
1826 E_Anonymous_Access_Subprogram_Type,
1827 E_Anonymous_Access_Type)
1828 then
1829 Set_Has_Implicit_Dereference (E);
1830 Set_Has_Implicit_Dereference (Disc);
1831 exit;
1832 end if;
1834 Next_Discriminant (Disc);
1835 end loop;
1837 -- Error if no proper access discriminant
1839 if No (Disc) then
1840 Error_Msg_NE ("not an access discriminant of&", Expr, E);
1841 return;
1842 end if;
1843 end if;
1845 -- For a type extension, check whether parent has a
1846 -- reference discriminant, to verify that use is proper.
1848 if Is_Derived_Type (E)
1849 and then Has_Discriminants (Etype (E))
1850 then
1851 Parent_Disc := Get_Reference_Discriminant (Etype (E));
1853 if Present (Parent_Disc)
1854 and then Corresponding_Discriminant (Disc) /= Parent_Disc
1855 then
1856 Error_Msg_N
1857 ("reference discriminant does not match discriminant "
1858 & "of parent type", Expr);
1859 end if;
1860 end if;
1861 end Analyze_Aspect_Implicit_Dereference;
1863 -----------------------
1864 -- Make_Aitem_Pragma --
1865 -----------------------
1867 procedure Make_Aitem_Pragma
1868 (Pragma_Argument_Associations : List_Id;
1869 Pragma_Name : Name_Id)
1871 Args : List_Id := Pragma_Argument_Associations;
1873 begin
1874 -- We should never get here if aspect was disabled
1876 pragma Assert (not Is_Disabled (Aspect));
1878 -- Certain aspects allow for an optional name or expression. Do
1879 -- not generate a pragma with empty argument association list.
1881 if No (Args) or else No (Expression (First (Args))) then
1882 Args := No_List;
1883 end if;
1885 -- Build the pragma
1887 Aitem :=
1888 Make_Pragma (Loc,
1889 Pragma_Argument_Associations => Args,
1890 Pragma_Identifier =>
1891 Make_Identifier (Sloc (Id), Pragma_Name),
1892 Class_Present => Class_Present (Aspect),
1893 Split_PPC => Split_PPC (Aspect));
1895 -- Set additional semantic fields
1897 if Is_Ignored (Aspect) then
1898 Set_Is_Ignored (Aitem);
1899 elsif Is_Checked (Aspect) then
1900 Set_Is_Checked (Aitem);
1901 end if;
1903 Set_Corresponding_Aspect (Aitem, Aspect);
1904 Set_From_Aspect_Specification (Aitem);
1905 end Make_Aitem_Pragma;
1907 -- Start of processing for Analyze_One_Aspect
1909 begin
1910 -- Skip aspect if already analyzed, to avoid looping in some cases
1912 if Analyzed (Aspect) then
1913 goto Continue;
1914 end if;
1916 -- Skip looking at aspect if it is totally disabled. Just mark it
1917 -- as such for later reference in the tree. This also sets the
1918 -- Is_Ignored and Is_Checked flags appropriately.
1920 Check_Applicable_Policy (Aspect);
1922 if Is_Disabled (Aspect) then
1923 goto Continue;
1924 end if;
1926 -- Set the source location of expression, used in the case of
1927 -- a failed precondition/postcondition or invariant. Note that
1928 -- the source location of the expression is not usually the best
1929 -- choice here. For example, it gets located on the last AND
1930 -- keyword in a chain of boolean expressiond AND'ed together.
1931 -- It is best to put the message on the first character of the
1932 -- assertion, which is the effect of the First_Node call here.
1934 if Present (Expr) then
1935 Eloc := Sloc (First_Node (Expr));
1936 end if;
1938 -- Check restriction No_Implementation_Aspect_Specifications
1940 if Implementation_Defined_Aspect (A_Id) then
1941 Check_Restriction
1942 (No_Implementation_Aspect_Specifications, Aspect);
1943 end if;
1945 -- Check restriction No_Specification_Of_Aspect
1947 Check_Restriction_No_Specification_Of_Aspect (Aspect);
1949 -- Mark aspect analyzed (actual analysis is delayed till later)
1951 Set_Analyzed (Aspect);
1952 Set_Entity (Aspect, E);
1954 -- Build the reference to E that will be used in the built pragmas
1956 Ent := New_Occurrence_Of (E, Sloc (Id));
1958 if A_Id = Aspect_Attach_Handler
1959 or else A_Id = Aspect_Interrupt_Handler
1960 then
1961 -- Decorate the reference as comming from the sources and force
1962 -- its reanalysis to generate the reference to E; required to
1963 -- avoid reporting spurious warning on E as unreferenced entity
1964 -- (because aspects are not fully analyzed).
1966 Set_Comes_From_Source (Ent, Comes_From_Source (Id));
1967 Set_Entity (Ent, Empty);
1969 Analyze (Ent);
1970 end if;
1972 -- Check for duplicate aspect. Note that the Comes_From_Source
1973 -- test allows duplicate Pre/Post's that we generate internally
1974 -- to escape being flagged here.
1976 if No_Duplicates_Allowed (A_Id) then
1977 Anod := First (L);
1978 while Anod /= Aspect loop
1979 if Comes_From_Source (Aspect)
1980 and then Same_Aspect (A_Id, Get_Aspect_Id (Anod))
1981 then
1982 Error_Msg_Name_1 := Nam;
1983 Error_Msg_Sloc := Sloc (Anod);
1985 -- Case of same aspect specified twice
1987 if Class_Present (Anod) = Class_Present (Aspect) then
1988 if not Class_Present (Anod) then
1989 Error_Msg_NE
1990 ("aspect% for & previously given#",
1991 Id, E);
1992 else
1993 Error_Msg_NE
1994 ("aspect `%''Class` for & previously given#",
1995 Id, E);
1996 end if;
1997 end if;
1998 end if;
2000 Next (Anod);
2001 end loop;
2002 end if;
2004 -- Check some general restrictions on language defined aspects
2006 if not Implementation_Defined_Aspect (A_Id) then
2007 Error_Msg_Name_1 := Nam;
2009 -- Not allowed for renaming declarations. Examine the original
2010 -- node because a subprogram renaming may have been rewritten
2011 -- as a body.
2013 if Nkind (Original_Node (N)) in N_Renaming_Declaration then
2014 Error_Msg_N
2015 ("aspect % not allowed for renaming declaration",
2016 Aspect);
2017 end if;
2019 -- Not allowed for formal type declarations
2021 if Nkind (N) = N_Formal_Type_Declaration then
2022 Error_Msg_N
2023 ("aspect % not allowed for formal type declaration",
2024 Aspect);
2025 end if;
2026 end if;
2028 -- Copy expression for later processing by the procedures
2029 -- Check_Aspect_At_[Freeze_Point | End_Of_Declarations]
2031 Set_Entity (Id, New_Copy_Tree (Expr));
2033 -- Set Delay_Required as appropriate to aspect
2035 case Aspect_Delay (A_Id) is
2036 when Always_Delay =>
2037 Delay_Required := True;
2039 when Never_Delay =>
2040 Delay_Required := False;
2042 when Rep_Aspect =>
2044 -- If expression has the form of an integer literal, then
2045 -- do not delay, since we know the value cannot change.
2046 -- This optimization catches most rep clause cases.
2048 -- For Boolean aspects, don't delay if no expression
2050 if A_Id in Boolean_Aspects and then No (Expr) then
2051 Delay_Required := False;
2053 -- For non-Boolean aspects, don't delay if integer literal,
2054 -- unless the aspect is Alignment, which affects the
2055 -- freezing of an initialized object.
2057 elsif A_Id not in Boolean_Aspects
2058 and then A_Id /= Aspect_Alignment
2059 and then Present (Expr)
2060 and then Nkind (Expr) = N_Integer_Literal
2061 then
2062 Delay_Required := False;
2064 -- All other cases are delayed
2066 else
2067 Delay_Required := True;
2068 Set_Has_Delayed_Rep_Aspects (E);
2069 end if;
2070 end case;
2072 -- Processing based on specific aspect
2074 case A_Id is
2075 when Aspect_Unimplemented =>
2076 null; -- ??? temp for now
2078 -- No_Aspect should be impossible
2080 when No_Aspect =>
2081 raise Program_Error;
2083 -- Case 1: Aspects corresponding to attribute definition
2084 -- clauses.
2086 when Aspect_Address
2087 | Aspect_Alignment
2088 | Aspect_Bit_Order
2089 | Aspect_Component_Size
2090 | Aspect_Constant_Indexing
2091 | Aspect_Default_Iterator
2092 | Aspect_Dispatching_Domain
2093 | Aspect_External_Tag
2094 | Aspect_Input
2095 | Aspect_Iterable
2096 | Aspect_Iterator_Element
2097 | Aspect_Machine_Radix
2098 | Aspect_Object_Size
2099 | Aspect_Output
2100 | Aspect_Read
2101 | Aspect_Scalar_Storage_Order
2102 | Aspect_Secondary_Stack_Size
2103 | Aspect_Simple_Storage_Pool
2104 | Aspect_Size
2105 | Aspect_Small
2106 | Aspect_Storage_Pool
2107 | Aspect_Stream_Size
2108 | Aspect_Value_Size
2109 | Aspect_Variable_Indexing
2110 | Aspect_Write
2112 -- Indexing aspects apply only to tagged type
2114 if (A_Id = Aspect_Constant_Indexing
2115 or else
2116 A_Id = Aspect_Variable_Indexing)
2117 and then not (Is_Type (E)
2118 and then Is_Tagged_Type (E))
2119 then
2120 Error_Msg_N
2121 ("indexing aspect can only apply to a tagged type",
2122 Aspect);
2123 goto Continue;
2124 end if;
2126 -- For the case of aspect Address, we don't consider that we
2127 -- know the entity is never set in the source, since it is
2128 -- is likely aliasing is occurring.
2130 -- Note: one might think that the analysis of the resulting
2131 -- attribute definition clause would take care of that, but
2132 -- that's not the case since it won't be from source.
2134 if A_Id = Aspect_Address then
2135 Set_Never_Set_In_Source (E, False);
2136 end if;
2138 -- Correctness of the profile of a stream operation is
2139 -- verified at the freeze point, but we must detect the
2140 -- illegal specification of this aspect for a subtype now,
2141 -- to prevent malformed rep_item chains.
2143 if A_Id = Aspect_Input or else
2144 A_Id = Aspect_Output or else
2145 A_Id = Aspect_Read or else
2146 A_Id = Aspect_Write
2147 then
2148 if not Is_First_Subtype (E) then
2149 Error_Msg_N
2150 ("local name must be a first subtype", Aspect);
2151 goto Continue;
2153 -- If stream aspect applies to the class-wide type,
2154 -- the generated attribute definition applies to the
2155 -- class-wide type as well.
2157 elsif Class_Present (Aspect) then
2158 Ent :=
2159 Make_Attribute_Reference (Loc,
2160 Prefix => Ent,
2161 Attribute_Name => Name_Class);
2162 end if;
2163 end if;
2165 -- Construct the attribute definition clause
2167 Aitem :=
2168 Make_Attribute_Definition_Clause (Loc,
2169 Name => Ent,
2170 Chars => Chars (Id),
2171 Expression => Relocate_Node (Expr));
2173 -- If the address is specified, then we treat the entity as
2174 -- referenced, to avoid spurious warnings. This is analogous
2175 -- to what is done with an attribute definition clause, but
2176 -- here we don't want to generate a reference because this
2177 -- is the point of definition of the entity.
2179 if A_Id = Aspect_Address then
2180 Set_Referenced (E);
2181 end if;
2183 -- Case 2: Aspects corresponding to pragmas
2185 -- Case 2a: Aspects corresponding to pragmas with two
2186 -- arguments, where the first argument is a local name
2187 -- referring to the entity, and the second argument is the
2188 -- aspect definition expression.
2190 -- Linker_Section/Suppress/Unsuppress
2192 when Aspect_Linker_Section
2193 | Aspect_Suppress
2194 | Aspect_Unsuppress
2196 Make_Aitem_Pragma
2197 (Pragma_Argument_Associations => New_List (
2198 Make_Pragma_Argument_Association (Loc,
2199 Expression => New_Occurrence_Of (E, Loc)),
2200 Make_Pragma_Argument_Association (Sloc (Expr),
2201 Expression => Relocate_Node (Expr))),
2202 Pragma_Name => Chars (Id));
2204 -- Synchronization
2206 -- Corresponds to pragma Implemented, construct the pragma
2208 when Aspect_Synchronization =>
2209 Make_Aitem_Pragma
2210 (Pragma_Argument_Associations => New_List (
2211 Make_Pragma_Argument_Association (Loc,
2212 Expression => New_Occurrence_Of (E, Loc)),
2213 Make_Pragma_Argument_Association (Sloc (Expr),
2214 Expression => Relocate_Node (Expr))),
2215 Pragma_Name => Name_Implemented);
2217 -- Attach_Handler
2219 when Aspect_Attach_Handler =>
2220 Make_Aitem_Pragma
2221 (Pragma_Argument_Associations => New_List (
2222 Make_Pragma_Argument_Association (Sloc (Ent),
2223 Expression => Ent),
2224 Make_Pragma_Argument_Association (Sloc (Expr),
2225 Expression => Relocate_Node (Expr))),
2226 Pragma_Name => Name_Attach_Handler);
2228 -- We need to insert this pragma into the tree to get proper
2229 -- processing and to look valid from a placement viewpoint.
2231 Insert_Pragma (Aitem);
2232 goto Continue;
2234 -- Dynamic_Predicate, Predicate, Static_Predicate
2236 when Aspect_Dynamic_Predicate
2237 | Aspect_Predicate
2238 | Aspect_Static_Predicate
2240 -- These aspects apply only to subtypes
2242 if not Is_Type (E) then
2243 Error_Msg_N
2244 ("predicate can only be specified for a subtype",
2245 Aspect);
2246 goto Continue;
2248 elsif Is_Incomplete_Type (E) then
2249 Error_Msg_N
2250 ("predicate cannot apply to incomplete view", Aspect);
2251 goto Continue;
2252 end if;
2254 -- Construct the pragma (always a pragma Predicate, with
2255 -- flags recording whether it is static/dynamic). We also
2256 -- set flags recording this in the type itself.
2258 Make_Aitem_Pragma
2259 (Pragma_Argument_Associations => New_List (
2260 Make_Pragma_Argument_Association (Sloc (Ent),
2261 Expression => Ent),
2262 Make_Pragma_Argument_Association (Sloc (Expr),
2263 Expression => Relocate_Node (Expr))),
2264 Pragma_Name => Name_Predicate);
2266 -- Mark type has predicates, and remember what kind of
2267 -- aspect lead to this predicate (we need this to access
2268 -- the right set of check policies later on).
2270 Set_Has_Predicates (E);
2272 if A_Id = Aspect_Dynamic_Predicate then
2273 Set_Has_Dynamic_Predicate_Aspect (E);
2275 -- If the entity has a dynamic predicate, any inherited
2276 -- static predicate becomes dynamic as well, and the
2277 -- predicate function includes the conjunction of both.
2279 Set_Has_Static_Predicate_Aspect (E, False);
2281 elsif A_Id = Aspect_Static_Predicate then
2282 Set_Has_Static_Predicate_Aspect (E);
2283 end if;
2285 -- If the type is private, indicate that its completion
2286 -- has a freeze node, because that is the one that will
2287 -- be visible at freeze time.
2289 if Is_Private_Type (E) and then Present (Full_View (E)) then
2290 Set_Has_Predicates (Full_View (E));
2292 if A_Id = Aspect_Dynamic_Predicate then
2293 Set_Has_Dynamic_Predicate_Aspect (Full_View (E));
2294 elsif A_Id = Aspect_Static_Predicate then
2295 Set_Has_Static_Predicate_Aspect (Full_View (E));
2296 end if;
2298 Set_Has_Delayed_Aspects (Full_View (E));
2299 Ensure_Freeze_Node (Full_View (E));
2300 end if;
2302 -- Predicate_Failure
2304 when Aspect_Predicate_Failure =>
2306 -- This aspect applies only to subtypes
2308 if not Is_Type (E) then
2309 Error_Msg_N
2310 ("predicate can only be specified for a subtype",
2311 Aspect);
2312 goto Continue;
2314 elsif Is_Incomplete_Type (E) then
2315 Error_Msg_N
2316 ("predicate cannot apply to incomplete view", Aspect);
2317 goto Continue;
2318 end if;
2320 -- Construct the pragma
2322 Make_Aitem_Pragma
2323 (Pragma_Argument_Associations => New_List (
2324 Make_Pragma_Argument_Association (Sloc (Ent),
2325 Expression => Ent),
2326 Make_Pragma_Argument_Association (Sloc (Expr),
2327 Expression => Relocate_Node (Expr))),
2328 Pragma_Name => Name_Predicate_Failure);
2330 Set_Has_Predicates (E);
2332 -- If the type is private, indicate that its completion
2333 -- has a freeze node, because that is the one that will
2334 -- be visible at freeze time.
2336 if Is_Private_Type (E) and then Present (Full_View (E)) then
2337 Set_Has_Predicates (Full_View (E));
2338 Set_Has_Delayed_Aspects (Full_View (E));
2339 Ensure_Freeze_Node (Full_View (E));
2340 end if;
2342 -- Case 2b: Aspects corresponding to pragmas with two
2343 -- arguments, where the second argument is a local name
2344 -- referring to the entity, and the first argument is the
2345 -- aspect definition expression.
2347 -- Convention
2349 when Aspect_Convention =>
2350 Analyze_Aspect_Convention;
2351 goto Continue;
2353 -- External_Name, Link_Name
2355 when Aspect_External_Name
2356 | Aspect_Link_Name
2358 Analyze_Aspect_External_Link_Name;
2359 goto Continue;
2361 -- CPU, Interrupt_Priority, Priority
2363 -- These three aspects can be specified for a subprogram spec
2364 -- or body, in which case we analyze the expression and export
2365 -- the value of the aspect.
2367 -- Previously, we generated an equivalent pragma for bodies
2368 -- (note that the specs cannot contain these pragmas). The
2369 -- pragma was inserted ahead of local declarations, rather than
2370 -- after the body. This leads to a certain duplication between
2371 -- the processing performed for the aspect and the pragma, but
2372 -- given the straightforward handling required it is simpler
2373 -- to duplicate than to translate the aspect in the spec into
2374 -- a pragma in the declarative part of the body.
2376 when Aspect_CPU
2377 | Aspect_Interrupt_Priority
2378 | Aspect_Priority
2380 if Nkind_In (N, N_Subprogram_Body,
2381 N_Subprogram_Declaration)
2382 then
2383 -- Analyze the aspect expression
2385 Analyze_And_Resolve (Expr, Standard_Integer);
2387 -- Interrupt_Priority aspect not allowed for main
2388 -- subprograms. RM D.1 does not forbid this explicitly,
2389 -- but RM J.15.11(6/3) does not permit pragma
2390 -- Interrupt_Priority for subprograms.
2392 if A_Id = Aspect_Interrupt_Priority then
2393 Error_Msg_N
2394 ("Interrupt_Priority aspect cannot apply to "
2395 & "subprogram", Expr);
2397 -- The expression must be static
2399 elsif not Is_OK_Static_Expression (Expr) then
2400 Flag_Non_Static_Expr
2401 ("aspect requires static expression!", Expr);
2403 -- Check whether this is the main subprogram. Issue a
2404 -- warning only if it is obviously not a main program
2405 -- (when it has parameters or when the subprogram is
2406 -- within a package).
2408 elsif Present (Parameter_Specifications
2409 (Specification (N)))
2410 or else not Is_Compilation_Unit (Defining_Entity (N))
2411 then
2412 -- See RM D.1(14/3) and D.16(12/3)
2414 Error_Msg_N
2415 ("aspect applied to subprogram other than the "
2416 & "main subprogram has no effect??", Expr);
2418 -- Otherwise check in range and export the value
2420 -- For the CPU aspect
2422 elsif A_Id = Aspect_CPU then
2423 if Is_In_Range (Expr, RTE (RE_CPU_Range)) then
2425 -- Value is correct so we export the value to make
2426 -- it available at execution time.
2428 Set_Main_CPU
2429 (Main_Unit, UI_To_Int (Expr_Value (Expr)));
2431 else
2432 Error_Msg_N
2433 ("main subprogram CPU is out of range", Expr);
2434 end if;
2436 -- For the Priority aspect
2438 elsif A_Id = Aspect_Priority then
2439 if Is_In_Range (Expr, RTE (RE_Priority)) then
2441 -- Value is correct so we export the value to make
2442 -- it available at execution time.
2444 Set_Main_Priority
2445 (Main_Unit, UI_To_Int (Expr_Value (Expr)));
2447 -- Ignore pragma if Relaxed_RM_Semantics to support
2448 -- other targets/non GNAT compilers.
2450 elsif not Relaxed_RM_Semantics then
2451 Error_Msg_N
2452 ("main subprogram priority is out of range",
2453 Expr);
2454 end if;
2455 end if;
2457 -- Load an arbitrary entity from System.Tasking.Stages
2458 -- or System.Tasking.Restricted.Stages (depending on
2459 -- the supported profile) to make sure that one of these
2460 -- packages is implicitly with'ed, since we need to have
2461 -- the tasking run time active for the pragma Priority to
2462 -- have any effect. Previously we with'ed the package
2463 -- System.Tasking, but this package does not trigger the
2464 -- required initialization of the run-time library.
2466 declare
2467 Discard : Entity_Id;
2468 begin
2469 if Restricted_Profile then
2470 Discard := RTE (RE_Activate_Restricted_Tasks);
2471 else
2472 Discard := RTE (RE_Activate_Tasks);
2473 end if;
2474 end;
2476 -- Handling for these aspects in subprograms is complete
2478 goto Continue;
2480 -- For tasks pass the aspect as an attribute
2482 else
2483 Aitem :=
2484 Make_Attribute_Definition_Clause (Loc,
2485 Name => Ent,
2486 Chars => Chars (Id),
2487 Expression => Relocate_Node (Expr));
2488 end if;
2490 -- Warnings
2492 when Aspect_Warnings =>
2493 Make_Aitem_Pragma
2494 (Pragma_Argument_Associations => New_List (
2495 Make_Pragma_Argument_Association (Sloc (Expr),
2496 Expression => Relocate_Node (Expr)),
2497 Make_Pragma_Argument_Association (Loc,
2498 Expression => New_Occurrence_Of (E, Loc))),
2499 Pragma_Name => Chars (Id));
2501 Decorate (Aspect, Aitem);
2502 Insert_Pragma (Aitem);
2503 goto Continue;
2505 -- Case 2c: Aspects corresponding to pragmas with three
2506 -- arguments.
2508 -- Invariant aspects have a first argument that references the
2509 -- entity, a second argument that is the expression and a third
2510 -- argument that is an appropriate message.
2512 -- Invariant, Type_Invariant
2514 when Aspect_Invariant
2515 | Aspect_Type_Invariant
2517 -- Analysis of the pragma will verify placement legality:
2518 -- an invariant must apply to a private type, or appear in
2519 -- the private part of a spec and apply to a completion.
2521 Make_Aitem_Pragma
2522 (Pragma_Argument_Associations => New_List (
2523 Make_Pragma_Argument_Association (Sloc (Ent),
2524 Expression => Ent),
2525 Make_Pragma_Argument_Association (Sloc (Expr),
2526 Expression => Relocate_Node (Expr))),
2527 Pragma_Name => Name_Invariant);
2529 -- Add message unless exception messages are suppressed
2531 if not Opt.Exception_Locations_Suppressed then
2532 Append_To (Pragma_Argument_Associations (Aitem),
2533 Make_Pragma_Argument_Association (Eloc,
2534 Chars => Name_Message,
2535 Expression =>
2536 Make_String_Literal (Eloc,
2537 Strval => "failed invariant from "
2538 & Build_Location_String (Eloc))));
2539 end if;
2541 -- For Invariant case, insert immediately after the entity
2542 -- declaration. We do not have to worry about delay issues
2543 -- since the pragma processing takes care of this.
2545 Delay_Required := False;
2547 -- Case 2d : Aspects that correspond to a pragma with one
2548 -- argument.
2550 -- Abstract_State
2552 -- Aspect Abstract_State introduces implicit declarations for
2553 -- all state abstraction entities it defines. To emulate this
2554 -- behavior, insert the pragma at the beginning of the visible
2555 -- declarations of the related package so that it is analyzed
2556 -- immediately.
2558 when Aspect_Abstract_State => Abstract_State : declare
2559 Context : Node_Id := N;
2561 begin
2562 -- When aspect Abstract_State appears on a generic package,
2563 -- it is propageted to the package instance. The context in
2564 -- this case is the instance spec.
2566 if Nkind (Context) = N_Package_Instantiation then
2567 Context := Instance_Spec (Context);
2568 end if;
2570 if Nkind_In (Context, N_Generic_Package_Declaration,
2571 N_Package_Declaration)
2572 then
2573 Make_Aitem_Pragma
2574 (Pragma_Argument_Associations => New_List (
2575 Make_Pragma_Argument_Association (Loc,
2576 Expression => Relocate_Node (Expr))),
2577 Pragma_Name => Name_Abstract_State);
2579 Decorate (Aspect, Aitem);
2580 Insert_Pragma
2581 (Prag => Aitem,
2582 Is_Instance =>
2583 Is_Generic_Instance (Defining_Entity (Context)));
2585 else
2586 Error_Msg_NE
2587 ("aspect & must apply to a package declaration",
2588 Aspect, Id);
2589 end if;
2591 goto Continue;
2592 end Abstract_State;
2594 -- Aspect Async_Readers is never delayed because it is
2595 -- equivalent to a source pragma which appears after the
2596 -- related object declaration.
2598 when Aspect_Async_Readers =>
2599 Make_Aitem_Pragma
2600 (Pragma_Argument_Associations => New_List (
2601 Make_Pragma_Argument_Association (Loc,
2602 Expression => Relocate_Node (Expr))),
2603 Pragma_Name => Name_Async_Readers);
2605 Decorate (Aspect, Aitem);
2606 Insert_Pragma (Aitem);
2607 goto Continue;
2609 -- Aspect Async_Writers is never delayed because it is
2610 -- equivalent to a source pragma which appears after the
2611 -- related object declaration.
2613 when Aspect_Async_Writers =>
2614 Make_Aitem_Pragma
2615 (Pragma_Argument_Associations => New_List (
2616 Make_Pragma_Argument_Association (Loc,
2617 Expression => Relocate_Node (Expr))),
2618 Pragma_Name => Name_Async_Writers);
2620 Decorate (Aspect, Aitem);
2621 Insert_Pragma (Aitem);
2622 goto Continue;
2624 -- Aspect Constant_After_Elaboration is never delayed because
2625 -- it is equivalent to a source pragma which appears after the
2626 -- related object declaration.
2628 when Aspect_Constant_After_Elaboration =>
2629 Make_Aitem_Pragma
2630 (Pragma_Argument_Associations => New_List (
2631 Make_Pragma_Argument_Association (Loc,
2632 Expression => Relocate_Node (Expr))),
2633 Pragma_Name =>
2634 Name_Constant_After_Elaboration);
2636 Decorate (Aspect, Aitem);
2637 Insert_Pragma (Aitem);
2638 goto Continue;
2640 -- Aspect Default_Internal_Condition is never delayed because
2641 -- it is equivalent to a source pragma which appears after the
2642 -- related private type. To deal with forward references, the
2643 -- generated pragma is stored in the rep chain of the related
2644 -- private type as types do not carry contracts. The pragma is
2645 -- wrapped inside of a procedure at the freeze point of the
2646 -- private type's full view.
2648 when Aspect_Default_Initial_Condition =>
2649 Make_Aitem_Pragma
2650 (Pragma_Argument_Associations => New_List (
2651 Make_Pragma_Argument_Association (Loc,
2652 Expression => Relocate_Node (Expr))),
2653 Pragma_Name =>
2654 Name_Default_Initial_Condition);
2656 Decorate (Aspect, Aitem);
2657 Insert_Pragma (Aitem);
2658 goto Continue;
2660 -- Default_Storage_Pool
2662 when Aspect_Default_Storage_Pool =>
2663 Make_Aitem_Pragma
2664 (Pragma_Argument_Associations => New_List (
2665 Make_Pragma_Argument_Association (Loc,
2666 Expression => Relocate_Node (Expr))),
2667 Pragma_Name =>
2668 Name_Default_Storage_Pool);
2670 Decorate (Aspect, Aitem);
2671 Insert_Pragma (Aitem);
2672 goto Continue;
2674 -- Depends
2676 -- Aspect Depends is never delayed because it is equivalent to
2677 -- a source pragma which appears after the related subprogram.
2678 -- To deal with forward references, the generated pragma is
2679 -- stored in the contract of the related subprogram and later
2680 -- analyzed at the end of the declarative region. See routine
2681 -- Analyze_Depends_In_Decl_Part for details.
2683 when Aspect_Depends =>
2684 Make_Aitem_Pragma
2685 (Pragma_Argument_Associations => New_List (
2686 Make_Pragma_Argument_Association (Loc,
2687 Expression => Relocate_Node (Expr))),
2688 Pragma_Name => Name_Depends);
2690 Decorate (Aspect, Aitem);
2691 Insert_Pragma (Aitem);
2692 goto Continue;
2694 -- Aspect Effecitve_Reads is never delayed because it is
2695 -- equivalent to a source pragma which appears after the
2696 -- related object declaration.
2698 when Aspect_Effective_Reads =>
2699 Make_Aitem_Pragma
2700 (Pragma_Argument_Associations => New_List (
2701 Make_Pragma_Argument_Association (Loc,
2702 Expression => Relocate_Node (Expr))),
2703 Pragma_Name => Name_Effective_Reads);
2705 Decorate (Aspect, Aitem);
2706 Insert_Pragma (Aitem);
2707 goto Continue;
2709 -- Aspect Effective_Writes is never delayed because it is
2710 -- equivalent to a source pragma which appears after the
2711 -- related object declaration.
2713 when Aspect_Effective_Writes =>
2714 Make_Aitem_Pragma
2715 (Pragma_Argument_Associations => New_List (
2716 Make_Pragma_Argument_Association (Loc,
2717 Expression => Relocate_Node (Expr))),
2718 Pragma_Name => Name_Effective_Writes);
2720 Decorate (Aspect, Aitem);
2721 Insert_Pragma (Aitem);
2722 goto Continue;
2724 -- Aspect Extensions_Visible is never delayed because it is
2725 -- equivalent to a source pragma which appears after the
2726 -- related subprogram.
2728 when Aspect_Extensions_Visible =>
2729 Make_Aitem_Pragma
2730 (Pragma_Argument_Associations => New_List (
2731 Make_Pragma_Argument_Association (Loc,
2732 Expression => Relocate_Node (Expr))),
2733 Pragma_Name => Name_Extensions_Visible);
2735 Decorate (Aspect, Aitem);
2736 Insert_Pragma (Aitem);
2737 goto Continue;
2739 -- Aspect Ghost is never delayed because it is equivalent to a
2740 -- source pragma which appears at the top of [generic] package
2741 -- declarations or after an object, a [generic] subprogram, or
2742 -- a type declaration.
2744 when Aspect_Ghost =>
2745 Make_Aitem_Pragma
2746 (Pragma_Argument_Associations => New_List (
2747 Make_Pragma_Argument_Association (Loc,
2748 Expression => Relocate_Node (Expr))),
2749 Pragma_Name => Name_Ghost);
2751 Decorate (Aspect, Aitem);
2752 Insert_Pragma (Aitem);
2753 goto Continue;
2755 -- Global
2757 -- Aspect Global is never delayed because it is equivalent to
2758 -- a source pragma which appears after the related subprogram.
2759 -- To deal with forward references, the generated pragma is
2760 -- stored in the contract of the related subprogram and later
2761 -- analyzed at the end of the declarative region. See routine
2762 -- Analyze_Global_In_Decl_Part for details.
2764 when Aspect_Global =>
2765 Make_Aitem_Pragma
2766 (Pragma_Argument_Associations => New_List (
2767 Make_Pragma_Argument_Association (Loc,
2768 Expression => Relocate_Node (Expr))),
2769 Pragma_Name => Name_Global);
2771 Decorate (Aspect, Aitem);
2772 Insert_Pragma (Aitem);
2773 goto Continue;
2775 -- Initial_Condition
2777 -- Aspect Initial_Condition is never delayed because it is
2778 -- equivalent to a source pragma which appears after the
2779 -- related package. To deal with forward references, the
2780 -- generated pragma is stored in the contract of the related
2781 -- package and later analyzed at the end of the declarative
2782 -- region. See routine Analyze_Initial_Condition_In_Decl_Part
2783 -- for details.
2785 when Aspect_Initial_Condition => Initial_Condition : declare
2786 Context : Node_Id := N;
2788 begin
2789 -- When aspect Initial_Condition appears on a generic
2790 -- package, it is propageted to the package instance. The
2791 -- context in this case is the instance spec.
2793 if Nkind (Context) = N_Package_Instantiation then
2794 Context := Instance_Spec (Context);
2795 end if;
2797 if Nkind_In (Context, N_Generic_Package_Declaration,
2798 N_Package_Declaration)
2799 then
2800 Make_Aitem_Pragma
2801 (Pragma_Argument_Associations => New_List (
2802 Make_Pragma_Argument_Association (Loc,
2803 Expression => Relocate_Node (Expr))),
2804 Pragma_Name =>
2805 Name_Initial_Condition);
2807 Decorate (Aspect, Aitem);
2808 Insert_Pragma
2809 (Prag => Aitem,
2810 Is_Instance =>
2811 Is_Generic_Instance (Defining_Entity (Context)));
2813 -- Otherwise the context is illegal
2815 else
2816 Error_Msg_NE
2817 ("aspect & must apply to a package declaration",
2818 Aspect, Id);
2819 end if;
2821 goto Continue;
2822 end Initial_Condition;
2824 -- Initializes
2826 -- Aspect Initializes is never delayed because it is equivalent
2827 -- to a source pragma appearing after the related package. To
2828 -- deal with forward references, the generated pragma is stored
2829 -- in the contract of the related package and later analyzed at
2830 -- the end of the declarative region. For details, see routine
2831 -- Analyze_Initializes_In_Decl_Part.
2833 when Aspect_Initializes => Initializes : declare
2834 Context : Node_Id := N;
2836 begin
2837 -- When aspect Initializes appears on a generic package,
2838 -- it is propageted to the package instance. The context
2839 -- in this case is the instance spec.
2841 if Nkind (Context) = N_Package_Instantiation then
2842 Context := Instance_Spec (Context);
2843 end if;
2845 if Nkind_In (Context, N_Generic_Package_Declaration,
2846 N_Package_Declaration)
2847 then
2848 Make_Aitem_Pragma
2849 (Pragma_Argument_Associations => New_List (
2850 Make_Pragma_Argument_Association (Loc,
2851 Expression => Relocate_Node (Expr))),
2852 Pragma_Name => Name_Initializes);
2854 Decorate (Aspect, Aitem);
2855 Insert_Pragma
2856 (Prag => Aitem,
2857 Is_Instance =>
2858 Is_Generic_Instance (Defining_Entity (Context)));
2860 -- Otherwise the context is illegal
2862 else
2863 Error_Msg_NE
2864 ("aspect & must apply to a package declaration",
2865 Aspect, Id);
2866 end if;
2868 goto Continue;
2869 end Initializes;
2871 -- Max_Queue_Length
2873 when Aspect_Max_Queue_Length =>
2874 Make_Aitem_Pragma
2875 (Pragma_Argument_Associations => New_List (
2876 Make_Pragma_Argument_Association (Loc,
2877 Expression => Relocate_Node (Expr))),
2878 Pragma_Name => Name_Max_Queue_Length);
2880 Decorate (Aspect, Aitem);
2881 Insert_Pragma (Aitem);
2882 goto Continue;
2884 -- Obsolescent
2886 when Aspect_Obsolescent => declare
2887 Args : List_Id;
2889 begin
2890 if No (Expr) then
2891 Args := No_List;
2892 else
2893 Args := New_List (
2894 Make_Pragma_Argument_Association (Sloc (Expr),
2895 Expression => Relocate_Node (Expr)));
2896 end if;
2898 Make_Aitem_Pragma
2899 (Pragma_Argument_Associations => Args,
2900 Pragma_Name => Chars (Id));
2901 end;
2903 -- Part_Of
2905 when Aspect_Part_Of =>
2906 if Nkind_In (N, N_Object_Declaration,
2907 N_Package_Instantiation)
2908 or else Is_Single_Concurrent_Type_Declaration (N)
2909 then
2910 Make_Aitem_Pragma
2911 (Pragma_Argument_Associations => New_List (
2912 Make_Pragma_Argument_Association (Loc,
2913 Expression => Relocate_Node (Expr))),
2914 Pragma_Name => Name_Part_Of);
2916 Decorate (Aspect, Aitem);
2917 Insert_Pragma (Aitem);
2919 else
2920 Error_Msg_NE
2921 ("aspect & must apply to package instantiation, "
2922 & "object, single protected type or single task type",
2923 Aspect, Id);
2924 end if;
2926 goto Continue;
2928 -- SPARK_Mode
2930 when Aspect_SPARK_Mode =>
2931 Make_Aitem_Pragma
2932 (Pragma_Argument_Associations => New_List (
2933 Make_Pragma_Argument_Association (Loc,
2934 Expression => Relocate_Node (Expr))),
2935 Pragma_Name => Name_SPARK_Mode);
2937 Decorate (Aspect, Aitem);
2938 Insert_Pragma (Aitem);
2939 goto Continue;
2941 -- Refined_Depends
2943 -- Aspect Refined_Depends is never delayed because it is
2944 -- equivalent to a source pragma which appears in the
2945 -- declarations of the related subprogram body. To deal with
2946 -- forward references, the generated pragma is stored in the
2947 -- contract of the related subprogram body and later analyzed
2948 -- at the end of the declarative region. For details, see
2949 -- routine Analyze_Refined_Depends_In_Decl_Part.
2951 when Aspect_Refined_Depends =>
2952 Make_Aitem_Pragma
2953 (Pragma_Argument_Associations => New_List (
2954 Make_Pragma_Argument_Association (Loc,
2955 Expression => Relocate_Node (Expr))),
2956 Pragma_Name => Name_Refined_Depends);
2958 Decorate (Aspect, Aitem);
2959 Insert_Pragma (Aitem);
2960 goto Continue;
2962 -- Refined_Global
2964 -- Aspect Refined_Global is never delayed because it is
2965 -- equivalent to a source pragma which appears in the
2966 -- declarations of the related subprogram body. To deal with
2967 -- forward references, the generated pragma is stored in the
2968 -- contract of the related subprogram body and later analyzed
2969 -- at the end of the declarative region. For details, see
2970 -- routine Analyze_Refined_Global_In_Decl_Part.
2972 when Aspect_Refined_Global =>
2973 Make_Aitem_Pragma
2974 (Pragma_Argument_Associations => New_List (
2975 Make_Pragma_Argument_Association (Loc,
2976 Expression => Relocate_Node (Expr))),
2977 Pragma_Name => Name_Refined_Global);
2979 Decorate (Aspect, Aitem);
2980 Insert_Pragma (Aitem);
2981 goto Continue;
2983 -- Refined_Post
2985 when Aspect_Refined_Post =>
2986 Make_Aitem_Pragma
2987 (Pragma_Argument_Associations => New_List (
2988 Make_Pragma_Argument_Association (Loc,
2989 Expression => Relocate_Node (Expr))),
2990 Pragma_Name => Name_Refined_Post);
2992 Decorate (Aspect, Aitem);
2993 Insert_Pragma (Aitem);
2994 goto Continue;
2996 -- Refined_State
2998 when Aspect_Refined_State =>
3000 -- The corresponding pragma for Refined_State is inserted in
3001 -- the declarations of the related package body. This action
3002 -- synchronizes both the source and from-aspect versions of
3003 -- the pragma.
3005 if Nkind (N) = N_Package_Body then
3006 Make_Aitem_Pragma
3007 (Pragma_Argument_Associations => New_List (
3008 Make_Pragma_Argument_Association (Loc,
3009 Expression => Relocate_Node (Expr))),
3010 Pragma_Name => Name_Refined_State);
3012 Decorate (Aspect, Aitem);
3013 Insert_Pragma (Aitem);
3015 -- Otherwise the context is illegal
3017 else
3018 Error_Msg_NE
3019 ("aspect & must apply to a package body", Aspect, Id);
3020 end if;
3022 goto Continue;
3024 -- Relative_Deadline
3026 when Aspect_Relative_Deadline =>
3027 Make_Aitem_Pragma
3028 (Pragma_Argument_Associations => New_List (
3029 Make_Pragma_Argument_Association (Loc,
3030 Expression => Relocate_Node (Expr))),
3031 Pragma_Name => Name_Relative_Deadline);
3033 -- If the aspect applies to a task, the corresponding pragma
3034 -- must appear within its declarations, not after.
3036 if Nkind (N) = N_Task_Type_Declaration then
3037 declare
3038 Def : Node_Id;
3039 V : List_Id;
3041 begin
3042 if No (Task_Definition (N)) then
3043 Set_Task_Definition (N,
3044 Make_Task_Definition (Loc,
3045 Visible_Declarations => New_List,
3046 End_Label => Empty));
3047 end if;
3049 Def := Task_Definition (N);
3050 V := Visible_Declarations (Def);
3051 if not Is_Empty_List (V) then
3052 Insert_Before (First (V), Aitem);
3054 else
3055 Set_Visible_Declarations (Def, New_List (Aitem));
3056 end if;
3058 goto Continue;
3059 end;
3060 end if;
3062 -- Aspect Volatile_Function is never delayed because it is
3063 -- equivalent to a source pragma which appears after the
3064 -- related subprogram.
3066 when Aspect_Volatile_Function =>
3067 Make_Aitem_Pragma
3068 (Pragma_Argument_Associations => New_List (
3069 Make_Pragma_Argument_Association (Loc,
3070 Expression => Relocate_Node (Expr))),
3071 Pragma_Name => Name_Volatile_Function);
3073 Decorate (Aspect, Aitem);
3074 Insert_Pragma (Aitem);
3075 goto Continue;
3077 -- Case 2e: Annotate aspect
3079 when Aspect_Annotate =>
3080 declare
3081 Args : List_Id;
3082 Pargs : List_Id;
3083 Arg : Node_Id;
3085 begin
3086 -- The argument can be a single identifier
3088 if Nkind (Expr) = N_Identifier then
3090 -- One level of parens is allowed
3092 if Paren_Count (Expr) > 1 then
3093 Error_Msg_F ("extra parentheses ignored", Expr);
3094 end if;
3096 Set_Paren_Count (Expr, 0);
3098 -- Add the single item to the list
3100 Args := New_List (Expr);
3102 -- Otherwise we must have an aggregate
3104 elsif Nkind (Expr) = N_Aggregate then
3106 -- Must be positional
3108 if Present (Component_Associations (Expr)) then
3109 Error_Msg_F
3110 ("purely positional aggregate required", Expr);
3111 goto Continue;
3112 end if;
3114 -- Must not be parenthesized
3116 if Paren_Count (Expr) /= 0 then
3117 Error_Msg_F ("extra parentheses ignored", Expr);
3118 end if;
3120 -- List of arguments is list of aggregate expressions
3122 Args := Expressions (Expr);
3124 -- Anything else is illegal
3126 else
3127 Error_Msg_F ("wrong form for Annotate aspect", Expr);
3128 goto Continue;
3129 end if;
3131 -- Prepare pragma arguments
3133 Pargs := New_List;
3134 Arg := First (Args);
3135 while Present (Arg) loop
3136 Append_To (Pargs,
3137 Make_Pragma_Argument_Association (Sloc (Arg),
3138 Expression => Relocate_Node (Arg)));
3139 Next (Arg);
3140 end loop;
3142 Append_To (Pargs,
3143 Make_Pragma_Argument_Association (Sloc (Ent),
3144 Chars => Name_Entity,
3145 Expression => Ent));
3147 Make_Aitem_Pragma
3148 (Pragma_Argument_Associations => Pargs,
3149 Pragma_Name => Name_Annotate);
3150 end;
3152 -- Case 3 : Aspects that don't correspond to pragma/attribute
3153 -- definition clause.
3155 -- Case 3a: The aspects listed below don't correspond to
3156 -- pragmas/attributes but do require delayed analysis.
3158 -- Default_Value can only apply to a scalar type
3160 when Aspect_Default_Value =>
3161 if not Is_Scalar_Type (E) then
3162 Error_Msg_N
3163 ("aspect Default_Value must apply to a scalar type", N);
3164 end if;
3166 Aitem := Empty;
3168 -- Default_Component_Value can only apply to an array type
3169 -- with scalar components.
3171 when Aspect_Default_Component_Value =>
3172 if not (Is_Array_Type (E)
3173 and then Is_Scalar_Type (Component_Type (E)))
3174 then
3175 Error_Msg_N
3176 ("aspect Default_Component_Value can only apply to an "
3177 & "array of scalar components", N);
3178 end if;
3180 Aitem := Empty;
3182 -- Case 3b: The aspects listed below don't correspond to
3183 -- pragmas/attributes and don't need delayed analysis.
3185 -- Implicit_Dereference
3187 -- For Implicit_Dereference, External_Name and Link_Name, only
3188 -- the legality checks are done during the analysis, thus no
3189 -- delay is required.
3191 when Aspect_Implicit_Dereference =>
3192 Analyze_Aspect_Implicit_Dereference;
3193 goto Continue;
3195 -- Dimension
3197 when Aspect_Dimension =>
3198 Analyze_Aspect_Dimension (N, Id, Expr);
3199 goto Continue;
3201 -- Dimension_System
3203 when Aspect_Dimension_System =>
3204 Analyze_Aspect_Dimension_System (N, Id, Expr);
3205 goto Continue;
3207 -- Case 4: Aspects requiring special handling
3209 -- Pre/Post/Test_Case/Contract_Cases whose corresponding
3210 -- pragmas take care of the delay.
3212 -- Pre/Post
3214 -- Aspects Pre/Post generate Precondition/Postcondition pragmas
3215 -- with a first argument that is the expression, and a second
3216 -- argument that is an informative message if the test fails.
3217 -- This is inserted right after the declaration, to get the
3218 -- required pragma placement. The processing for the pragmas
3219 -- takes care of the required delay.
3221 when Pre_Post_Aspects => Pre_Post : declare
3222 Pname : Name_Id;
3224 begin
3225 if A_Id = Aspect_Pre or else A_Id = Aspect_Precondition then
3226 Pname := Name_Precondition;
3227 else
3228 Pname := Name_Postcondition;
3229 end if;
3231 -- Check that the class-wide predicate cannot be applied to
3232 -- an operation of a synchronized type that is not a tagged
3233 -- type. Other legality checks are performed when analyzing
3234 -- the contract of the operation.
3236 if Class_Present (Aspect)
3237 and then Is_Concurrent_Type (Current_Scope)
3238 and then not Is_Tagged_Type (Current_Scope)
3239 and then Ekind_In (E, E_Entry, E_Function, E_Procedure)
3240 then
3241 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (Aspect);
3242 Error_Msg_N
3243 ("aspect % can only be specified for a primitive "
3244 & "operation of a tagged type", Aspect);
3246 goto Continue;
3247 end if;
3249 -- If the expressions is of the form A and then B, then
3250 -- we generate separate Pre/Post aspects for the separate
3251 -- clauses. Since we allow multiple pragmas, there is no
3252 -- problem in allowing multiple Pre/Post aspects internally.
3253 -- These should be treated in reverse order (B first and
3254 -- A second) since they are later inserted just after N in
3255 -- the order they are treated. This way, the pragma for A
3256 -- ends up preceding the pragma for B, which may have an
3257 -- importance for the error raised (either constraint error
3258 -- or precondition error).
3260 -- We do not do this for Pre'Class, since we have to put
3261 -- these conditions together in a complex OR expression.
3263 -- We do not do this in ASIS mode, as ASIS relies on the
3264 -- original node representing the complete expression, when
3265 -- retrieving it through the source aspect table.
3267 if not ASIS_Mode
3268 and then (Pname = Name_Postcondition
3269 or else not Class_Present (Aspect))
3270 then
3271 while Nkind (Expr) = N_And_Then loop
3272 Insert_After (Aspect,
3273 Make_Aspect_Specification (Sloc (Left_Opnd (Expr)),
3274 Identifier => Identifier (Aspect),
3275 Expression => Relocate_Node (Left_Opnd (Expr)),
3276 Class_Present => Class_Present (Aspect),
3277 Split_PPC => True));
3278 Rewrite (Expr, Relocate_Node (Right_Opnd (Expr)));
3279 Eloc := Sloc (Expr);
3280 end loop;
3281 end if;
3283 -- Build the precondition/postcondition pragma
3285 -- Add note about why we do NOT need Copy_Tree here???
3287 Make_Aitem_Pragma
3288 (Pragma_Argument_Associations => New_List (
3289 Make_Pragma_Argument_Association (Eloc,
3290 Chars => Name_Check,
3291 Expression => Relocate_Node (Expr))),
3292 Pragma_Name => Pname);
3294 -- Add message unless exception messages are suppressed
3296 if not Opt.Exception_Locations_Suppressed then
3297 Append_To (Pragma_Argument_Associations (Aitem),
3298 Make_Pragma_Argument_Association (Eloc,
3299 Chars => Name_Message,
3300 Expression =>
3301 Make_String_Literal (Eloc,
3302 Strval => "failed "
3303 & Get_Name_String (Pname)
3304 & " from "
3305 & Build_Location_String (Eloc))));
3306 end if;
3308 Set_Is_Delayed_Aspect (Aspect);
3310 -- For Pre/Post cases, insert immediately after the entity
3311 -- declaration, since that is the required pragma placement.
3312 -- Note that for these aspects, we do not have to worry
3313 -- about delay issues, since the pragmas themselves deal
3314 -- with delay of visibility for the expression analysis.
3316 Insert_Pragma (Aitem);
3318 goto Continue;
3319 end Pre_Post;
3321 -- Test_Case
3323 when Aspect_Test_Case => Test_Case : declare
3324 Args : List_Id;
3325 Comp_Expr : Node_Id;
3326 Comp_Assn : Node_Id;
3327 New_Expr : Node_Id;
3329 begin
3330 Args := New_List;
3332 if Nkind (Parent (N)) = N_Compilation_Unit then
3333 Error_Msg_Name_1 := Nam;
3334 Error_Msg_N ("incorrect placement of aspect `%`", E);
3335 goto Continue;
3336 end if;
3338 if Nkind (Expr) /= N_Aggregate then
3339 Error_Msg_Name_1 := Nam;
3340 Error_Msg_NE
3341 ("wrong syntax for aspect `%` for &", Id, E);
3342 goto Continue;
3343 end if;
3345 -- Make pragma expressions refer to the original aspect
3346 -- expressions through the Original_Node link. This is used
3347 -- in semantic analysis for ASIS mode, so that the original
3348 -- expression also gets analyzed.
3350 Comp_Expr := First (Expressions (Expr));
3351 while Present (Comp_Expr) loop
3352 New_Expr := Relocate_Node (Comp_Expr);
3353 Append_To (Args,
3354 Make_Pragma_Argument_Association (Sloc (Comp_Expr),
3355 Expression => New_Expr));
3356 Next (Comp_Expr);
3357 end loop;
3359 Comp_Assn := First (Component_Associations (Expr));
3360 while Present (Comp_Assn) loop
3361 if List_Length (Choices (Comp_Assn)) /= 1
3362 or else
3363 Nkind (First (Choices (Comp_Assn))) /= N_Identifier
3364 then
3365 Error_Msg_Name_1 := Nam;
3366 Error_Msg_NE
3367 ("wrong syntax for aspect `%` for &", Id, E);
3368 goto Continue;
3369 end if;
3371 Append_To (Args,
3372 Make_Pragma_Argument_Association (Sloc (Comp_Assn),
3373 Chars => Chars (First (Choices (Comp_Assn))),
3374 Expression =>
3375 Relocate_Node (Expression (Comp_Assn))));
3376 Next (Comp_Assn);
3377 end loop;
3379 -- Build the test-case pragma
3381 Make_Aitem_Pragma
3382 (Pragma_Argument_Associations => Args,
3383 Pragma_Name => Nam);
3384 end Test_Case;
3386 -- Contract_Cases
3388 when Aspect_Contract_Cases =>
3389 Make_Aitem_Pragma
3390 (Pragma_Argument_Associations => New_List (
3391 Make_Pragma_Argument_Association (Loc,
3392 Expression => Relocate_Node (Expr))),
3393 Pragma_Name => Nam);
3395 Decorate (Aspect, Aitem);
3396 Insert_Pragma (Aitem);
3397 goto Continue;
3399 -- Case 5: Special handling for aspects with an optional
3400 -- boolean argument.
3402 -- In the delayed case, the corresponding pragma cannot be
3403 -- generated yet because the evaluation of the boolean needs
3404 -- to be delayed till the freeze point.
3406 when Boolean_Aspects
3407 | Library_Unit_Aspects
3409 Set_Is_Boolean_Aspect (Aspect);
3411 -- Lock_Free aspect only apply to protected objects
3413 if A_Id = Aspect_Lock_Free then
3414 if Ekind (E) /= E_Protected_Type then
3415 Error_Msg_Name_1 := Nam;
3416 Error_Msg_N
3417 ("aspect % only applies to a protected object",
3418 Aspect);
3420 else
3421 -- Set the Uses_Lock_Free flag to True if there is no
3422 -- expression or if the expression is True. The
3423 -- evaluation of this aspect should be delayed to the
3424 -- freeze point (why???)
3426 if No (Expr)
3427 or else Is_True (Static_Boolean (Expr))
3428 then
3429 Set_Uses_Lock_Free (E);
3430 end if;
3432 Record_Rep_Item (E, Aspect);
3433 end if;
3435 goto Continue;
3437 elsif A_Id = Aspect_Export or else A_Id = Aspect_Import then
3438 Analyze_Aspect_Export_Import;
3440 -- Disable_Controlled
3442 elsif A_Id = Aspect_Disable_Controlled then
3443 if Ekind (E) /= E_Record_Type
3444 or else not Is_Controlled (E)
3445 then
3446 Error_Msg_N
3447 ("aspect % requires controlled record type", Aspect);
3448 goto Continue;
3449 end if;
3451 -- If we're in a generic template, we don't want to try
3452 -- to disable controlled types, because typical usage is
3453 -- "Disable_Controlled => not <some_check>'Enabled", and
3454 -- the value of Enabled is not known until we see a
3455 -- particular instance. In such a context, we just need
3456 -- to preanalyze the expression for legality.
3458 if Expander_Active then
3459 Analyze_And_Resolve (Expr, Standard_Boolean);
3461 if not Present (Expr)
3462 or else Is_True (Static_Boolean (Expr))
3463 then
3464 Set_Disable_Controlled (E);
3465 end if;
3467 elsif Serious_Errors_Detected = 0 then
3468 Preanalyze_And_Resolve (Expr, Standard_Boolean);
3469 end if;
3471 goto Continue;
3472 end if;
3474 -- Library unit aspects require special handling in the case
3475 -- of a package declaration, the pragma needs to be inserted
3476 -- in the list of declarations for the associated package.
3477 -- There is no issue of visibility delay for these aspects.
3479 if A_Id in Library_Unit_Aspects
3480 and then
3481 Nkind_In (N, N_Package_Declaration,
3482 N_Generic_Package_Declaration)
3483 and then Nkind (Parent (N)) /= N_Compilation_Unit
3485 -- Aspect is legal on a local instantiation of a library-
3486 -- level generic unit.
3488 and then not Is_Generic_Instance (Defining_Entity (N))
3489 then
3490 Error_Msg_N
3491 ("incorrect context for library unit aspect&", Id);
3492 goto Continue;
3493 end if;
3495 -- Cases where we do not delay, includes all cases where the
3496 -- expression is missing other than the above cases.
3498 if not Delay_Required or else No (Expr) then
3500 -- Exclude aspects Export and Import because their pragma
3501 -- syntax does not map directly to a Boolean aspect.
3503 if A_Id /= Aspect_Export
3504 and then A_Id /= Aspect_Import
3505 then
3506 Make_Aitem_Pragma
3507 (Pragma_Argument_Associations => New_List (
3508 Make_Pragma_Argument_Association (Sloc (Ent),
3509 Expression => Ent)),
3510 Pragma_Name => Chars (Id));
3511 end if;
3513 Delay_Required := False;
3515 -- In general cases, the corresponding pragma/attribute
3516 -- definition clause will be inserted later at the freezing
3517 -- point, and we do not need to build it now.
3519 else
3520 Aitem := Empty;
3521 end if;
3523 -- Storage_Size
3525 -- This is special because for access types we need to generate
3526 -- an attribute definition clause. This also works for single
3527 -- task declarations, but it does not work for task type
3528 -- declarations, because we have the case where the expression
3529 -- references a discriminant of the task type. That can't use
3530 -- an attribute definition clause because we would not have
3531 -- visibility on the discriminant. For that case we must
3532 -- generate a pragma in the task definition.
3534 when Aspect_Storage_Size =>
3536 -- Task type case
3538 if Ekind (E) = E_Task_Type then
3539 declare
3540 Decl : constant Node_Id := Declaration_Node (E);
3542 begin
3543 pragma Assert (Nkind (Decl) = N_Task_Type_Declaration);
3545 -- If no task definition, create one
3547 if No (Task_Definition (Decl)) then
3548 Set_Task_Definition (Decl,
3549 Make_Task_Definition (Loc,
3550 Visible_Declarations => Empty_List,
3551 End_Label => Empty));
3552 end if;
3554 -- Create a pragma and put it at the start of the task
3555 -- definition for the task type declaration.
3557 Make_Aitem_Pragma
3558 (Pragma_Argument_Associations => New_List (
3559 Make_Pragma_Argument_Association (Loc,
3560 Expression => Relocate_Node (Expr))),
3561 Pragma_Name => Name_Storage_Size);
3563 Prepend
3564 (Aitem,
3565 Visible_Declarations (Task_Definition (Decl)));
3566 goto Continue;
3567 end;
3569 -- All other cases, generate attribute definition
3571 else
3572 Aitem :=
3573 Make_Attribute_Definition_Clause (Loc,
3574 Name => Ent,
3575 Chars => Chars (Id),
3576 Expression => Relocate_Node (Expr));
3577 end if;
3578 end case;
3580 -- Attach the corresponding pragma/attribute definition clause to
3581 -- the aspect specification node.
3583 if Present (Aitem) then
3584 Set_From_Aspect_Specification (Aitem);
3585 end if;
3587 -- In the context of a compilation unit, we directly put the
3588 -- pragma in the Pragmas_After list of the N_Compilation_Unit_Aux
3589 -- node (no delay is required here) except for aspects on a
3590 -- subprogram body (see below) and a generic package, for which we
3591 -- need to introduce the pragma before building the generic copy
3592 -- (see sem_ch12), and for package instantiations, where the
3593 -- library unit pragmas are better handled early.
3595 if Nkind (Parent (N)) = N_Compilation_Unit
3596 and then (Present (Aitem) or else Is_Boolean_Aspect (Aspect))
3597 then
3598 declare
3599 Aux : constant Node_Id := Aux_Decls_Node (Parent (N));
3601 begin
3602 pragma Assert (Nkind (Aux) = N_Compilation_Unit_Aux);
3604 -- For a Boolean aspect, create the corresponding pragma if
3605 -- no expression or if the value is True.
3607 if Is_Boolean_Aspect (Aspect) and then No (Aitem) then
3608 if Is_True (Static_Boolean (Expr)) then
3609 Make_Aitem_Pragma
3610 (Pragma_Argument_Associations => New_List (
3611 Make_Pragma_Argument_Association (Sloc (Ent),
3612 Expression => Ent)),
3613 Pragma_Name => Chars (Id));
3615 Set_From_Aspect_Specification (Aitem, True);
3616 Set_Corresponding_Aspect (Aitem, Aspect);
3618 else
3619 goto Continue;
3620 end if;
3621 end if;
3623 -- If the aspect is on a subprogram body (relevant aspect
3624 -- is Inline), add the pragma in front of the declarations.
3626 if Nkind (N) = N_Subprogram_Body then
3627 if No (Declarations (N)) then
3628 Set_Declarations (N, New_List);
3629 end if;
3631 Prepend (Aitem, Declarations (N));
3633 elsif Nkind (N) = N_Generic_Package_Declaration then
3634 if No (Visible_Declarations (Specification (N))) then
3635 Set_Visible_Declarations (Specification (N), New_List);
3636 end if;
3638 Prepend (Aitem,
3639 Visible_Declarations (Specification (N)));
3641 elsif Nkind (N) = N_Package_Instantiation then
3642 declare
3643 Spec : constant Node_Id :=
3644 Specification (Instance_Spec (N));
3645 begin
3646 if No (Visible_Declarations (Spec)) then
3647 Set_Visible_Declarations (Spec, New_List);
3648 end if;
3650 Prepend (Aitem, Visible_Declarations (Spec));
3651 end;
3653 else
3654 if No (Pragmas_After (Aux)) then
3655 Set_Pragmas_After (Aux, New_List);
3656 end if;
3658 Append (Aitem, Pragmas_After (Aux));
3659 end if;
3661 goto Continue;
3662 end;
3663 end if;
3665 -- The evaluation of the aspect is delayed to the freezing point.
3666 -- The pragma or attribute clause if there is one is then attached
3667 -- to the aspect specification which is put in the rep item list.
3669 if Delay_Required then
3670 if Present (Aitem) then
3671 Set_Is_Delayed_Aspect (Aitem);
3672 Set_Aspect_Rep_Item (Aspect, Aitem);
3673 Set_Parent (Aitem, Aspect);
3674 end if;
3676 Set_Is_Delayed_Aspect (Aspect);
3678 -- In the case of Default_Value, link the aspect to base type
3679 -- as well, even though it appears on a first subtype. This is
3680 -- mandated by the semantics of the aspect. Do not establish
3681 -- the link when processing the base type itself as this leads
3682 -- to a rep item circularity. Verify that we are dealing with
3683 -- a scalar type to prevent cascaded errors.
3685 if A_Id = Aspect_Default_Value
3686 and then Is_Scalar_Type (E)
3687 and then Base_Type (E) /= E
3688 then
3689 Set_Has_Delayed_Aspects (Base_Type (E));
3690 Record_Rep_Item (Base_Type (E), Aspect);
3691 end if;
3693 Set_Has_Delayed_Aspects (E);
3694 Record_Rep_Item (E, Aspect);
3696 -- When delay is not required and the context is a package or a
3697 -- subprogram body, insert the pragma in the body declarations.
3699 elsif Nkind_In (N, N_Package_Body, N_Subprogram_Body) then
3700 if No (Declarations (N)) then
3701 Set_Declarations (N, New_List);
3702 end if;
3704 -- The pragma is added before source declarations
3706 Prepend_To (Declarations (N), Aitem);
3708 -- When delay is not required and the context is not a compilation
3709 -- unit, we simply insert the pragma/attribute definition clause
3710 -- in sequence.
3712 elsif Present (Aitem) then
3713 Insert_After (Ins_Node, Aitem);
3714 Ins_Node := Aitem;
3715 end if;
3716 end Analyze_One_Aspect;
3718 <<Continue>>
3719 Next (Aspect);
3720 end loop Aspect_Loop;
3722 if Has_Delayed_Aspects (E) then
3723 Ensure_Freeze_Node (E);
3724 end if;
3725 end Analyze_Aspect_Specifications;
3727 ---------------------------------------------------
3728 -- Analyze_Aspect_Specifications_On_Body_Or_Stub --
3729 ---------------------------------------------------
3731 procedure Analyze_Aspect_Specifications_On_Body_Or_Stub (N : Node_Id) is
3732 Body_Id : constant Entity_Id := Defining_Entity (N);
3734 procedure Diagnose_Misplaced_Aspects (Spec_Id : Entity_Id);
3735 -- Body [stub] N has aspects, but they are not properly placed. Emit an
3736 -- error message depending on the aspects involved. Spec_Id denotes the
3737 -- entity of the corresponding spec.
3739 --------------------------------
3740 -- Diagnose_Misplaced_Aspects --
3741 --------------------------------
3743 procedure Diagnose_Misplaced_Aspects (Spec_Id : Entity_Id) is
3744 procedure Misplaced_Aspect_Error
3745 (Asp : Node_Id;
3746 Ref_Nam : Name_Id);
3747 -- Emit an error message concerning misplaced aspect Asp. Ref_Nam is
3748 -- the name of the refined version of the aspect.
3750 ----------------------------
3751 -- Misplaced_Aspect_Error --
3752 ----------------------------
3754 procedure Misplaced_Aspect_Error
3755 (Asp : Node_Id;
3756 Ref_Nam : Name_Id)
3758 Asp_Nam : constant Name_Id := Chars (Identifier (Asp));
3759 Asp_Id : constant Aspect_Id := Get_Aspect_Id (Asp_Nam);
3761 begin
3762 -- The corresponding spec already contains the aspect in question
3763 -- and the one appearing on the body must be the refined form:
3765 -- procedure P with Global ...;
3766 -- procedure P with Global ... is ... end P;
3767 -- ^
3768 -- Refined_Global
3770 if Has_Aspect (Spec_Id, Asp_Id) then
3771 Error_Msg_Name_1 := Asp_Nam;
3773 -- Subunits cannot carry aspects that apply to a subprogram
3774 -- declaration.
3776 if Nkind (Parent (N)) = N_Subunit then
3777 Error_Msg_N ("aspect % cannot apply to a subunit", Asp);
3779 -- Otherwise suggest the refined form
3781 else
3782 Error_Msg_Name_2 := Ref_Nam;
3783 Error_Msg_N ("aspect % should be %", Asp);
3784 end if;
3786 -- Otherwise the aspect must appear on the spec, not on the body
3788 -- procedure P;
3789 -- procedure P with Global ... is ... end P;
3791 else
3792 Error_Msg_N
3793 ("aspect specification must appear on initial declaration",
3794 Asp);
3795 end if;
3796 end Misplaced_Aspect_Error;
3798 -- Local variables
3800 Asp : Node_Id;
3801 Asp_Nam : Name_Id;
3803 -- Start of processing for Diagnose_Misplaced_Aspects
3805 begin
3806 -- Iterate over the aspect specifications and emit specific errors
3807 -- where applicable.
3809 Asp := First (Aspect_Specifications (N));
3810 while Present (Asp) loop
3811 Asp_Nam := Chars (Identifier (Asp));
3813 -- Do not emit errors on aspects that can appear on a subprogram
3814 -- body. This scenario occurs when the aspect specification list
3815 -- contains both misplaced and properly placed aspects.
3817 if Aspect_On_Body_Or_Stub_OK (Get_Aspect_Id (Asp_Nam)) then
3818 null;
3820 -- Special diagnostics for SPARK aspects
3822 elsif Asp_Nam = Name_Depends then
3823 Misplaced_Aspect_Error (Asp, Name_Refined_Depends);
3825 elsif Asp_Nam = Name_Global then
3826 Misplaced_Aspect_Error (Asp, Name_Refined_Global);
3828 elsif Asp_Nam = Name_Post then
3829 Misplaced_Aspect_Error (Asp, Name_Refined_Post);
3831 -- Otherwise a language-defined aspect is misplaced
3833 else
3834 Error_Msg_N
3835 ("aspect specification must appear on initial declaration",
3836 Asp);
3837 end if;
3839 Next (Asp);
3840 end loop;
3841 end Diagnose_Misplaced_Aspects;
3843 -- Local variables
3845 Spec_Id : constant Entity_Id := Unique_Defining_Entity (N);
3847 -- Start of processing for Analyze_Aspects_On_Body_Or_Stub
3849 begin
3850 -- Language-defined aspects cannot be associated with a subprogram body
3851 -- [stub] if the subprogram has a spec. Certain implementation defined
3852 -- aspects are allowed to break this rule (for all applicable cases, see
3853 -- table Aspects.Aspect_On_Body_Or_Stub_OK).
3855 if Spec_Id /= Body_Id and then not Aspects_On_Body_Or_Stub_OK (N) then
3856 Diagnose_Misplaced_Aspects (Spec_Id);
3857 else
3858 Analyze_Aspect_Specifications (N, Body_Id);
3859 end if;
3860 end Analyze_Aspect_Specifications_On_Body_Or_Stub;
3862 -----------------------
3863 -- Analyze_At_Clause --
3864 -----------------------
3866 -- An at clause is replaced by the corresponding Address attribute
3867 -- definition clause that is the preferred approach in Ada 95.
3869 procedure Analyze_At_Clause (N : Node_Id) is
3870 CS : constant Boolean := Comes_From_Source (N);
3872 begin
3873 -- This is an obsolescent feature
3875 Check_Restriction (No_Obsolescent_Features, N);
3877 if Warn_On_Obsolescent_Feature then
3878 Error_Msg_N
3879 ("?j?at clause is an obsolescent feature (RM J.7(2))", N);
3880 Error_Msg_N
3881 ("\?j?use address attribute definition clause instead", N);
3882 end if;
3884 -- Rewrite as address clause
3886 Rewrite (N,
3887 Make_Attribute_Definition_Clause (Sloc (N),
3888 Name => Identifier (N),
3889 Chars => Name_Address,
3890 Expression => Expression (N)));
3892 -- We preserve Comes_From_Source, since logically the clause still comes
3893 -- from the source program even though it is changed in form.
3895 Set_Comes_From_Source (N, CS);
3897 -- Analyze rewritten clause
3899 Analyze_Attribute_Definition_Clause (N);
3900 end Analyze_At_Clause;
3902 -----------------------------------------
3903 -- Analyze_Attribute_Definition_Clause --
3904 -----------------------------------------
3906 procedure Analyze_Attribute_Definition_Clause (N : Node_Id) is
3907 Loc : constant Source_Ptr := Sloc (N);
3908 Nam : constant Node_Id := Name (N);
3909 Attr : constant Name_Id := Chars (N);
3910 Expr : constant Node_Id := Expression (N);
3911 Id : constant Attribute_Id := Get_Attribute_Id (Attr);
3913 Ent : Entity_Id;
3914 -- The entity of Nam after it is analyzed. In the case of an incomplete
3915 -- type, this is the underlying type.
3917 U_Ent : Entity_Id;
3918 -- The underlying entity to which the attribute applies. Generally this
3919 -- is the Underlying_Type of Ent, except in the case where the clause
3920 -- applies to the full view of an incomplete or private type, in which
3921 -- case U_Ent is just a copy of Ent.
3923 FOnly : Boolean := False;
3924 -- Reset to True for subtype specific attribute (Alignment, Size)
3925 -- and for stream attributes, i.e. those cases where in the call to
3926 -- Rep_Item_Too_Late, FOnly is set True so that only the freezing rules
3927 -- are checked. Note that the case of stream attributes is not clear
3928 -- from the RM, but see AI95-00137. Also, the RM seems to disallow
3929 -- Storage_Size for derived task types, but that is also clearly
3930 -- unintentional.
3932 procedure Analyze_Stream_TSS_Definition (TSS_Nam : TSS_Name_Type);
3933 -- Common processing for 'Read, 'Write, 'Input and 'Output attribute
3934 -- definition clauses.
3936 function Duplicate_Clause return Boolean;
3937 -- This routine checks if the aspect for U_Ent being given by attribute
3938 -- definition clause N is for an aspect that has already been specified,
3939 -- and if so gives an error message. If there is a duplicate, True is
3940 -- returned, otherwise if there is no error, False is returned.
3942 procedure Check_Indexing_Functions;
3943 -- Check that the function in Constant_Indexing or Variable_Indexing
3944 -- attribute has the proper type structure. If the name is overloaded,
3945 -- check that some interpretation is legal.
3947 procedure Check_Iterator_Functions;
3948 -- Check that there is a single function in Default_Iterator attribute
3949 -- has the proper type structure.
3951 function Check_Primitive_Function (Subp : Entity_Id) return Boolean;
3952 -- Common legality check for the previous two
3954 -----------------------------------
3955 -- Analyze_Stream_TSS_Definition --
3956 -----------------------------------
3958 procedure Analyze_Stream_TSS_Definition (TSS_Nam : TSS_Name_Type) is
3959 Subp : Entity_Id := Empty;
3960 I : Interp_Index;
3961 It : Interp;
3962 Pnam : Entity_Id;
3964 Is_Read : constant Boolean := (TSS_Nam = TSS_Stream_Read);
3965 -- True for Read attribute, False for other attributes
3967 function Has_Good_Profile
3968 (Subp : Entity_Id;
3969 Report : Boolean := False) return Boolean;
3970 -- Return true if the entity is a subprogram with an appropriate
3971 -- profile for the attribute being defined. If result is False and
3972 -- Report is True, function emits appropriate error.
3974 ----------------------
3975 -- Has_Good_Profile --
3976 ----------------------
3978 function Has_Good_Profile
3979 (Subp : Entity_Id;
3980 Report : Boolean := False) return Boolean
3982 Expected_Ekind : constant array (Boolean) of Entity_Kind :=
3983 (False => E_Procedure, True => E_Function);
3984 Is_Function : constant Boolean := (TSS_Nam = TSS_Stream_Input);
3985 F : Entity_Id;
3986 Typ : Entity_Id;
3988 begin
3989 if Ekind (Subp) /= Expected_Ekind (Is_Function) then
3990 return False;
3991 end if;
3993 F := First_Formal (Subp);
3995 if No (F)
3996 or else Ekind (Etype (F)) /= E_Anonymous_Access_Type
3997 or else Designated_Type (Etype (F)) /=
3998 Class_Wide_Type (RTE (RE_Root_Stream_Type))
3999 then
4000 return False;
4001 end if;
4003 if not Is_Function then
4004 Next_Formal (F);
4006 declare
4007 Expected_Mode : constant array (Boolean) of Entity_Kind :=
4008 (False => E_In_Parameter,
4009 True => E_Out_Parameter);
4010 begin
4011 if Parameter_Mode (F) /= Expected_Mode (Is_Read) then
4012 return False;
4013 end if;
4014 end;
4016 Typ := Etype (F);
4018 -- If the attribute specification comes from an aspect
4019 -- specification for a class-wide stream, the parameter must be
4020 -- a class-wide type of the entity to which the aspect applies.
4022 if From_Aspect_Specification (N)
4023 and then Class_Present (Parent (N))
4024 and then Is_Class_Wide_Type (Typ)
4025 then
4026 Typ := Etype (Typ);
4027 end if;
4029 else
4030 Typ := Etype (Subp);
4031 end if;
4033 -- Verify that the prefix of the attribute and the local name for
4034 -- the type of the formal match, or one is the class-wide of the
4035 -- other, in the case of a class-wide stream operation.
4037 if Base_Type (Typ) = Base_Type (Ent)
4038 or else (Is_Class_Wide_Type (Typ)
4039 and then Typ = Class_Wide_Type (Base_Type (Ent)))
4040 or else (Is_Class_Wide_Type (Ent)
4041 and then Ent = Class_Wide_Type (Base_Type (Typ)))
4042 then
4043 null;
4044 else
4045 return False;
4046 end if;
4048 if Present (Next_Formal (F)) then
4049 return False;
4051 elsif not Is_Scalar_Type (Typ)
4052 and then not Is_First_Subtype (Typ)
4053 and then not Is_Class_Wide_Type (Typ)
4054 then
4055 if Report and not Is_First_Subtype (Typ) then
4056 Error_Msg_N
4057 ("subtype of formal in stream operation must be a first "
4058 & "subtype", Parameter_Type (Parent (F)));
4059 end if;
4061 return False;
4063 else
4064 return True;
4065 end if;
4066 end Has_Good_Profile;
4068 -- Start of processing for Analyze_Stream_TSS_Definition
4070 begin
4071 FOnly := True;
4073 if not Is_Type (U_Ent) then
4074 Error_Msg_N ("local name must be a subtype", Nam);
4075 return;
4077 elsif not Is_First_Subtype (U_Ent) then
4078 Error_Msg_N ("local name must be a first subtype", Nam);
4079 return;
4080 end if;
4082 Pnam := TSS (Base_Type (U_Ent), TSS_Nam);
4084 -- If Pnam is present, it can be either inherited from an ancestor
4085 -- type (in which case it is legal to redefine it for this type), or
4086 -- be a previous definition of the attribute for the same type (in
4087 -- which case it is illegal).
4089 -- In the first case, it will have been analyzed already, and we
4090 -- can check that its profile does not match the expected profile
4091 -- for a stream attribute of U_Ent. In the second case, either Pnam
4092 -- has been analyzed (and has the expected profile), or it has not
4093 -- been analyzed yet (case of a type that has not been frozen yet
4094 -- and for which the stream attribute has been set using Set_TSS).
4096 if Present (Pnam)
4097 and then (No (First_Entity (Pnam)) or else Has_Good_Profile (Pnam))
4098 then
4099 Error_Msg_Sloc := Sloc (Pnam);
4100 Error_Msg_Name_1 := Attr;
4101 Error_Msg_N ("% attribute already defined #", Nam);
4102 return;
4103 end if;
4105 Analyze (Expr);
4107 if Is_Entity_Name (Expr) then
4108 if not Is_Overloaded (Expr) then
4109 if Has_Good_Profile (Entity (Expr), Report => True) then
4110 Subp := Entity (Expr);
4111 end if;
4113 else
4114 Get_First_Interp (Expr, I, It);
4115 while Present (It.Nam) loop
4116 if Has_Good_Profile (It.Nam) then
4117 Subp := It.Nam;
4118 exit;
4119 end if;
4121 Get_Next_Interp (I, It);
4122 end loop;
4123 end if;
4124 end if;
4126 if Present (Subp) then
4127 if Is_Abstract_Subprogram (Subp) then
4128 Error_Msg_N ("stream subprogram must not be abstract", Expr);
4129 return;
4131 -- A stream subprogram for an interface type must be a null
4132 -- procedure (RM 13.13.2 (38/3)). Note that the class-wide type
4133 -- of an interface is not an interface type (3.9.4 (6.b/2)).
4135 elsif Is_Interface (U_Ent)
4136 and then not Is_Class_Wide_Type (U_Ent)
4137 and then not Inside_A_Generic
4138 and then
4139 (Ekind (Subp) = E_Function
4140 or else
4141 not Null_Present
4142 (Specification
4143 (Unit_Declaration_Node (Ultimate_Alias (Subp)))))
4144 then
4145 Error_Msg_N
4146 ("stream subprogram for interface type must be null "
4147 & "procedure", Expr);
4148 end if;
4150 Set_Entity (Expr, Subp);
4151 Set_Etype (Expr, Etype (Subp));
4153 New_Stream_Subprogram (N, U_Ent, Subp, TSS_Nam);
4155 else
4156 Error_Msg_Name_1 := Attr;
4157 Error_Msg_N ("incorrect expression for% attribute", Expr);
4158 end if;
4159 end Analyze_Stream_TSS_Definition;
4161 ------------------------------
4162 -- Check_Indexing_Functions --
4163 ------------------------------
4165 procedure Check_Indexing_Functions is
4166 Indexing_Found : Boolean := False;
4168 procedure Check_Inherited_Indexing;
4169 -- For a derived type, check that no indexing aspect is specified
4170 -- for the type if it is also inherited
4172 procedure Check_One_Function (Subp : Entity_Id);
4173 -- Check one possible interpretation. Sets Indexing_Found True if a
4174 -- legal indexing function is found.
4176 procedure Illegal_Indexing (Msg : String);
4177 -- Diagnose illegal indexing function if not overloaded. In the
4178 -- overloaded case indicate that no legal interpretation exists.
4180 ------------------------------
4181 -- Check_Inherited_Indexing --
4182 ------------------------------
4184 procedure Check_Inherited_Indexing is
4185 Inherited : Node_Id;
4187 begin
4188 if Attr = Name_Constant_Indexing then
4189 Inherited :=
4190 Find_Aspect (Etype (Ent), Aspect_Constant_Indexing);
4191 else pragma Assert (Attr = Name_Variable_Indexing);
4192 Inherited :=
4193 Find_Aspect (Etype (Ent), Aspect_Variable_Indexing);
4194 end if;
4196 if Present (Inherited) then
4197 if Debug_Flag_Dot_XX then
4198 null;
4200 -- OK if current attribute_definition_clause is expansion of
4201 -- inherited aspect.
4203 elsif Aspect_Rep_Item (Inherited) = N then
4204 null;
4206 -- Indicate the operation that must be overridden, rather than
4207 -- redefining the indexing aspect.
4209 else
4210 Illegal_Indexing
4211 ("indexing function already inherited from parent type");
4212 Error_Msg_NE
4213 ("!override & instead",
4214 N, Entity (Expression (Inherited)));
4215 end if;
4216 end if;
4217 end Check_Inherited_Indexing;
4219 ------------------------
4220 -- Check_One_Function --
4221 ------------------------
4223 procedure Check_One_Function (Subp : Entity_Id) is
4224 Default_Element : Node_Id;
4225 Ret_Type : constant Entity_Id := Etype (Subp);
4227 begin
4228 if not Is_Overloadable (Subp) then
4229 Illegal_Indexing ("illegal indexing function for type&");
4230 return;
4232 elsif Scope (Subp) /= Scope (Ent) then
4233 if Nkind (Expr) = N_Expanded_Name then
4235 -- Indexing function can't be declared elsewhere
4237 Illegal_Indexing
4238 ("indexing function must be declared in scope of type&");
4239 end if;
4241 return;
4243 elsif No (First_Formal (Subp)) then
4244 Illegal_Indexing
4245 ("Indexing requires a function that applies to type&");
4246 return;
4248 elsif No (Next_Formal (First_Formal (Subp))) then
4249 Illegal_Indexing
4250 ("indexing function must have at least two parameters");
4251 return;
4253 elsif Is_Derived_Type (Ent) then
4254 Check_Inherited_Indexing;
4255 end if;
4257 if not Check_Primitive_Function (Subp) then
4258 Illegal_Indexing
4259 ("Indexing aspect requires a function that applies to type&");
4260 return;
4261 end if;
4263 -- If partial declaration exists, verify that it is not tagged.
4265 if Ekind (Current_Scope) = E_Package
4266 and then Has_Private_Declaration (Ent)
4267 and then From_Aspect_Specification (N)
4268 and then
4269 List_Containing (Parent (Ent)) =
4270 Private_Declarations
4271 (Specification (Unit_Declaration_Node (Current_Scope)))
4272 and then Nkind (N) = N_Attribute_Definition_Clause
4273 then
4274 declare
4275 Decl : Node_Id;
4277 begin
4278 Decl :=
4279 First (Visible_Declarations
4280 (Specification
4281 (Unit_Declaration_Node (Current_Scope))));
4283 while Present (Decl) loop
4284 if Nkind (Decl) = N_Private_Type_Declaration
4285 and then Ent = Full_View (Defining_Identifier (Decl))
4286 and then Tagged_Present (Decl)
4287 and then No (Aspect_Specifications (Decl))
4288 then
4289 Illegal_Indexing
4290 ("Indexing aspect cannot be specified on full view "
4291 & "if partial view is tagged");
4292 return;
4293 end if;
4295 Next (Decl);
4296 end loop;
4297 end;
4298 end if;
4300 -- An indexing function must return either the default element of
4301 -- the container, or a reference type. For variable indexing it
4302 -- must be the latter.
4304 Default_Element :=
4305 Find_Value_Of_Aspect
4306 (Etype (First_Formal (Subp)), Aspect_Iterator_Element);
4308 if Present (Default_Element) then
4309 Analyze (Default_Element);
4311 if Is_Entity_Name (Default_Element)
4312 and then not Covers (Entity (Default_Element), Ret_Type)
4313 and then False
4314 then
4315 Illegal_Indexing
4316 ("wrong return type for indexing function");
4317 return;
4318 end if;
4319 end if;
4321 -- For variable_indexing the return type must be a reference type
4323 if Attr = Name_Variable_Indexing then
4324 if not Has_Implicit_Dereference (Ret_Type) then
4325 Illegal_Indexing
4326 ("variable indexing must return a reference type");
4327 return;
4329 elsif Is_Access_Constant
4330 (Etype (First_Discriminant (Ret_Type)))
4331 then
4332 Illegal_Indexing
4333 ("variable indexing must return an access to variable");
4334 return;
4335 end if;
4337 else
4338 if Has_Implicit_Dereference (Ret_Type)
4339 and then not
4340 Is_Access_Constant (Etype (First_Discriminant (Ret_Type)))
4341 then
4342 Illegal_Indexing
4343 ("constant indexing must return an access to constant");
4344 return;
4346 elsif Is_Access_Type (Etype (First_Formal (Subp)))
4347 and then not Is_Access_Constant (Etype (First_Formal (Subp)))
4348 then
4349 Illegal_Indexing
4350 ("constant indexing must apply to an access to constant");
4351 return;
4352 end if;
4353 end if;
4355 -- All checks succeeded.
4357 Indexing_Found := True;
4358 end Check_One_Function;
4360 -----------------------
4361 -- Illegal_Indexing --
4362 -----------------------
4364 procedure Illegal_Indexing (Msg : String) is
4365 begin
4366 Error_Msg_NE (Msg, N, Ent);
4367 end Illegal_Indexing;
4369 -- Start of processing for Check_Indexing_Functions
4371 begin
4372 if In_Instance then
4373 Check_Inherited_Indexing;
4374 end if;
4376 Analyze (Expr);
4378 if not Is_Overloaded (Expr) then
4379 Check_One_Function (Entity (Expr));
4381 else
4382 declare
4383 I : Interp_Index;
4384 It : Interp;
4386 begin
4387 Indexing_Found := False;
4388 Get_First_Interp (Expr, I, It);
4389 while Present (It.Nam) loop
4391 -- Note that analysis will have added the interpretation
4392 -- that corresponds to the dereference. We only check the
4393 -- subprogram itself.
4395 if Is_Overloadable (It.Nam) then
4396 Check_One_Function (It.Nam);
4397 end if;
4399 Get_Next_Interp (I, It);
4400 end loop;
4401 end;
4402 end if;
4404 if not Indexing_Found and then not Error_Posted (N) then
4405 Error_Msg_NE
4406 ("aspect Indexing requires a local function that "
4407 & "applies to type&", Expr, Ent);
4408 end if;
4409 end Check_Indexing_Functions;
4411 ------------------------------
4412 -- Check_Iterator_Functions --
4413 ------------------------------
4415 procedure Check_Iterator_Functions is
4416 function Valid_Default_Iterator (Subp : Entity_Id) return Boolean;
4417 -- Check one possible interpretation for validity
4419 ----------------------------
4420 -- Valid_Default_Iterator --
4421 ----------------------------
4423 function Valid_Default_Iterator (Subp : Entity_Id) return Boolean is
4424 Root_T : constant Entity_Id := Root_Type (Etype (Etype (Subp)));
4425 Formal : Entity_Id;
4427 begin
4428 if not Check_Primitive_Function (Subp) then
4429 return False;
4431 -- The return type must be derived from a type in an instance
4432 -- of Iterator.Interfaces, and thus its root type must have a
4433 -- predefined name.
4435 elsif Chars (Root_T) /= Name_Forward_Iterator
4436 and then Chars (Root_T) /= Name_Reversible_Iterator
4437 then
4438 return False;
4440 else
4441 Formal := First_Formal (Subp);
4442 end if;
4444 -- False if any subsequent formal has no default expression
4446 Formal := Next_Formal (Formal);
4447 while Present (Formal) loop
4448 if No (Expression (Parent (Formal))) then
4449 return False;
4450 end if;
4452 Next_Formal (Formal);
4453 end loop;
4455 -- True if all subsequent formals have default expressions
4457 return True;
4458 end Valid_Default_Iterator;
4460 -- Start of processing for Check_Iterator_Functions
4462 begin
4463 Analyze (Expr);
4465 if not Is_Entity_Name (Expr) then
4466 Error_Msg_N ("aspect Iterator must be a function name", Expr);
4467 end if;
4469 if not Is_Overloaded (Expr) then
4470 if not Check_Primitive_Function (Entity (Expr)) then
4471 Error_Msg_NE
4472 ("aspect Indexing requires a function that applies to type&",
4473 Entity (Expr), Ent);
4474 end if;
4476 -- Flag the default_iterator as well as the denoted function.
4478 if not Valid_Default_Iterator (Entity (Expr)) then
4479 Error_Msg_N ("improper function for default iterator!", Expr);
4480 end if;
4482 else
4483 declare
4484 Default : Entity_Id := Empty;
4485 I : Interp_Index;
4486 It : Interp;
4488 begin
4489 Get_First_Interp (Expr, I, It);
4490 while Present (It.Nam) loop
4491 if not Check_Primitive_Function (It.Nam)
4492 or else not Valid_Default_Iterator (It.Nam)
4493 then
4494 Remove_Interp (I);
4496 elsif Present (Default) then
4498 -- An explicit one should override an implicit one
4500 if Comes_From_Source (Default) =
4501 Comes_From_Source (It.Nam)
4502 then
4503 Error_Msg_N ("default iterator must be unique", Expr);
4504 Error_Msg_Sloc := Sloc (Default);
4505 Error_Msg_N ("\\possible interpretation#", Expr);
4506 Error_Msg_Sloc := Sloc (It.Nam);
4507 Error_Msg_N ("\\possible interpretation#", Expr);
4509 elsif Comes_From_Source (It.Nam) then
4510 Default := It.Nam;
4511 end if;
4512 else
4513 Default := It.Nam;
4514 end if;
4516 Get_Next_Interp (I, It);
4517 end loop;
4519 if Present (Default) then
4520 Set_Entity (Expr, Default);
4521 Set_Is_Overloaded (Expr, False);
4522 else
4523 Error_Msg_N
4524 ("no interpretation is a valid default iterator!", Expr);
4525 end if;
4526 end;
4527 end if;
4528 end Check_Iterator_Functions;
4530 -------------------------------
4531 -- Check_Primitive_Function --
4532 -------------------------------
4534 function Check_Primitive_Function (Subp : Entity_Id) return Boolean is
4535 Ctrl : Entity_Id;
4537 begin
4538 if Ekind (Subp) /= E_Function then
4539 return False;
4540 end if;
4542 if No (First_Formal (Subp)) then
4543 return False;
4544 else
4545 Ctrl := Etype (First_Formal (Subp));
4546 end if;
4548 -- To be a primitive operation subprogram has to be in same scope.
4550 if Scope (Ctrl) /= Scope (Subp) then
4551 return False;
4552 end if;
4554 -- Type of formal may be the class-wide type, an access to such,
4555 -- or an incomplete view.
4557 if Ctrl = Ent
4558 or else Ctrl = Class_Wide_Type (Ent)
4559 or else
4560 (Ekind (Ctrl) = E_Anonymous_Access_Type
4561 and then (Designated_Type (Ctrl) = Ent
4562 or else
4563 Designated_Type (Ctrl) = Class_Wide_Type (Ent)))
4564 or else
4565 (Ekind (Ctrl) = E_Incomplete_Type
4566 and then Full_View (Ctrl) = Ent)
4567 then
4568 null;
4569 else
4570 return False;
4571 end if;
4573 return True;
4574 end Check_Primitive_Function;
4576 ----------------------
4577 -- Duplicate_Clause --
4578 ----------------------
4580 function Duplicate_Clause return Boolean is
4581 A : Node_Id;
4583 begin
4584 -- Nothing to do if this attribute definition clause comes from
4585 -- an aspect specification, since we could not be duplicating an
4586 -- explicit clause, and we dealt with the case of duplicated aspects
4587 -- in Analyze_Aspect_Specifications.
4589 if From_Aspect_Specification (N) then
4590 return False;
4591 end if;
4593 -- Otherwise current clause may duplicate previous clause, or a
4594 -- previously given pragma or aspect specification for the same
4595 -- aspect.
4597 A := Get_Rep_Item (U_Ent, Chars (N), Check_Parents => False);
4599 if Present (A) then
4600 Error_Msg_Name_1 := Chars (N);
4601 Error_Msg_Sloc := Sloc (A);
4603 Error_Msg_NE ("aspect% for & previously given#", N, U_Ent);
4604 return True;
4605 end if;
4607 return False;
4608 end Duplicate_Clause;
4610 -- Start of processing for Analyze_Attribute_Definition_Clause
4612 begin
4613 -- The following code is a defense against recursion. Not clear that
4614 -- this can happen legitimately, but perhaps some error situations can
4615 -- cause it, and we did see this recursion during testing.
4617 if Analyzed (N) then
4618 return;
4619 else
4620 Set_Analyzed (N, True);
4621 end if;
4623 Check_Restriction_No_Use_Of_Attribute (N);
4625 -- Ignore some selected attributes in CodePeer mode since they are not
4626 -- relevant in this context.
4628 if CodePeer_Mode then
4629 case Id is
4631 -- Ignore Component_Size in CodePeer mode, to avoid changing the
4632 -- internal representation of types by implicitly packing them.
4634 when Attribute_Component_Size =>
4635 Rewrite (N, Make_Null_Statement (Sloc (N)));
4636 return;
4638 when others =>
4639 null;
4640 end case;
4641 end if;
4643 -- Process Ignore_Rep_Clauses option
4645 if Ignore_Rep_Clauses then
4646 case Id is
4648 -- The following should be ignored. They do not affect legality
4649 -- and may be target dependent. The basic idea of -gnatI is to
4650 -- ignore any rep clauses that may be target dependent but do not
4651 -- affect legality (except possibly to be rejected because they
4652 -- are incompatible with the compilation target).
4654 when Attribute_Alignment
4655 | Attribute_Bit_Order
4656 | Attribute_Component_Size
4657 | Attribute_Machine_Radix
4658 | Attribute_Object_Size
4659 | Attribute_Size
4660 | Attribute_Small
4661 | Attribute_Stream_Size
4662 | Attribute_Value_Size
4664 Kill_Rep_Clause (N);
4665 return;
4667 -- The following should not be ignored, because in the first place
4668 -- they are reasonably portable, and should not cause problems
4669 -- in compiling code from another target, and also they do affect
4670 -- legality, e.g. failing to provide a stream attribute for a type
4671 -- may make a program illegal.
4673 when Attribute_External_Tag
4674 | Attribute_Input
4675 | Attribute_Output
4676 | Attribute_Read
4677 | Attribute_Simple_Storage_Pool
4678 | Attribute_Storage_Pool
4679 | Attribute_Storage_Size
4680 | Attribute_Write
4682 null;
4684 -- We do not do anything here with address clauses, they will be
4685 -- removed by Freeze later on, but for now, it works better to
4686 -- keep then in the tree.
4688 when Attribute_Address =>
4689 null;
4691 -- Other cases are errors ("attribute& cannot be set with
4692 -- definition clause"), which will be caught below.
4694 when others =>
4695 null;
4696 end case;
4697 end if;
4699 Analyze (Nam);
4700 Ent := Entity (Nam);
4702 if Rep_Item_Too_Early (Ent, N) then
4703 return;
4704 end if;
4706 -- Rep clause applies to full view of incomplete type or private type if
4707 -- we have one (if not, this is a premature use of the type). However,
4708 -- certain semantic checks need to be done on the specified entity (i.e.
4709 -- the private view), so we save it in Ent.
4711 if Is_Private_Type (Ent)
4712 and then Is_Derived_Type (Ent)
4713 and then not Is_Tagged_Type (Ent)
4714 and then No (Full_View (Ent))
4715 then
4716 -- If this is a private type whose completion is a derivation from
4717 -- another private type, there is no full view, and the attribute
4718 -- belongs to the type itself, not its underlying parent.
4720 U_Ent := Ent;
4722 elsif Ekind (Ent) = E_Incomplete_Type then
4724 -- The attribute applies to the full view, set the entity of the
4725 -- attribute definition accordingly.
4727 Ent := Underlying_Type (Ent);
4728 U_Ent := Ent;
4729 Set_Entity (Nam, Ent);
4731 else
4732 U_Ent := Underlying_Type (Ent);
4733 end if;
4735 -- Avoid cascaded error
4737 if Etype (Nam) = Any_Type then
4738 return;
4740 -- Must be declared in current scope or in case of an aspect
4741 -- specification, must be visible in current scope.
4743 elsif Scope (Ent) /= Current_Scope
4744 and then
4745 not (From_Aspect_Specification (N)
4746 and then Scope_Within_Or_Same (Current_Scope, Scope (Ent)))
4747 then
4748 Error_Msg_N ("entity must be declared in this scope", Nam);
4749 return;
4751 -- Must not be a source renaming (we do have some cases where the
4752 -- expander generates a renaming, and those cases are OK, in such
4753 -- cases any attribute applies to the renamed object as well).
4755 elsif Is_Object (Ent)
4756 and then Present (Renamed_Object (Ent))
4757 then
4758 -- Case of renamed object from source, this is an error
4760 if Comes_From_Source (Renamed_Object (Ent)) then
4761 Get_Name_String (Chars (N));
4762 Error_Msg_Strlen := Name_Len;
4763 Error_Msg_String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len);
4764 Error_Msg_N
4765 ("~ clause not allowed for a renaming declaration "
4766 & "(RM 13.1(6))", Nam);
4767 return;
4769 -- For the case of a compiler generated renaming, the attribute
4770 -- definition clause applies to the renamed object created by the
4771 -- expander. The easiest general way to handle this is to create a
4772 -- copy of the attribute definition clause for this object.
4774 elsif Is_Entity_Name (Renamed_Object (Ent)) then
4775 Insert_Action (N,
4776 Make_Attribute_Definition_Clause (Loc,
4777 Name =>
4778 New_Occurrence_Of (Entity (Renamed_Object (Ent)), Loc),
4779 Chars => Chars (N),
4780 Expression => Duplicate_Subexpr (Expression (N))));
4782 -- If the renamed object is not an entity, it must be a dereference
4783 -- of an unconstrained function call, and we must introduce a new
4784 -- declaration to capture the expression. This is needed in the case
4785 -- of 'Alignment, where the original declaration must be rewritten.
4787 else
4788 pragma Assert
4789 (Nkind (Renamed_Object (Ent)) = N_Explicit_Dereference);
4790 null;
4791 end if;
4793 -- If no underlying entity, use entity itself, applies to some
4794 -- previously detected error cases ???
4796 elsif No (U_Ent) then
4797 U_Ent := Ent;
4799 -- Cannot specify for a subtype (exception Object/Value_Size)
4801 elsif Is_Type (U_Ent)
4802 and then not Is_First_Subtype (U_Ent)
4803 and then Id /= Attribute_Object_Size
4804 and then Id /= Attribute_Value_Size
4805 and then not From_At_Mod (N)
4806 then
4807 Error_Msg_N ("cannot specify attribute for subtype", Nam);
4808 return;
4809 end if;
4811 Set_Entity (N, U_Ent);
4813 -- Switch on particular attribute
4815 case Id is
4817 -------------
4818 -- Address --
4819 -------------
4821 -- Address attribute definition clause
4823 when Attribute_Address => Address : begin
4825 -- A little error check, catch for X'Address use X'Address;
4827 if Nkind (Nam) = N_Identifier
4828 and then Nkind (Expr) = N_Attribute_Reference
4829 and then Attribute_Name (Expr) = Name_Address
4830 and then Nkind (Prefix (Expr)) = N_Identifier
4831 and then Chars (Nam) = Chars (Prefix (Expr))
4832 then
4833 Error_Msg_NE
4834 ("address for & is self-referencing", Prefix (Expr), Ent);
4835 return;
4836 end if;
4838 -- Not that special case, carry on with analysis of expression
4840 Analyze_And_Resolve (Expr, RTE (RE_Address));
4842 -- Even when ignoring rep clauses we need to indicate that the
4843 -- entity has an address clause and thus it is legal to declare
4844 -- it imported. Freeze will get rid of the address clause later.
4846 if Ignore_Rep_Clauses then
4847 if Ekind_In (U_Ent, E_Variable, E_Constant) then
4848 Record_Rep_Item (U_Ent, N);
4849 end if;
4851 return;
4852 end if;
4854 if Duplicate_Clause then
4855 null;
4857 -- Case of address clause for subprogram
4859 elsif Is_Subprogram (U_Ent) then
4860 if Has_Homonym (U_Ent) then
4861 Error_Msg_N
4862 ("address clause cannot be given for overloaded "
4863 & "subprogram", Nam);
4864 return;
4865 end if;
4867 -- For subprograms, all address clauses are permitted, and we
4868 -- mark the subprogram as having a deferred freeze so that Gigi
4869 -- will not elaborate it too soon.
4871 -- Above needs more comments, what is too soon about???
4873 Set_Has_Delayed_Freeze (U_Ent);
4875 -- Case of address clause for entry
4877 elsif Ekind (U_Ent) = E_Entry then
4878 if Nkind (Parent (N)) = N_Task_Body then
4879 Error_Msg_N
4880 ("entry address must be specified in task spec", Nam);
4881 return;
4882 end if;
4884 -- For entries, we require a constant address
4886 Check_Constant_Address_Clause (Expr, U_Ent);
4888 -- Special checks for task types
4890 if Is_Task_Type (Scope (U_Ent))
4891 and then Comes_From_Source (Scope (U_Ent))
4892 then
4893 Error_Msg_N
4894 ("??entry address declared for entry in task type", N);
4895 Error_Msg_N
4896 ("\??only one task can be declared of this type", N);
4897 end if;
4899 -- Entry address clauses are obsolescent
4901 Check_Restriction (No_Obsolescent_Features, N);
4903 if Warn_On_Obsolescent_Feature then
4904 Error_Msg_N
4905 ("?j?attaching interrupt to task entry is an obsolescent "
4906 & "feature (RM J.7.1)", N);
4907 Error_Msg_N
4908 ("\?j?use interrupt procedure instead", N);
4909 end if;
4911 -- Case of an address clause for a controlled object, which we
4912 -- consider to be erroneous.
4914 elsif Is_Controlled (Etype (U_Ent))
4915 or else Has_Controlled_Component (Etype (U_Ent))
4916 then
4917 Error_Msg_NE
4918 ("??controlled object & must not be overlaid", Nam, U_Ent);
4919 Error_Msg_N
4920 ("\??Program_Error will be raised at run time", Nam);
4921 Insert_Action (Declaration_Node (U_Ent),
4922 Make_Raise_Program_Error (Loc,
4923 Reason => PE_Overlaid_Controlled_Object));
4924 return;
4926 -- Case of an address clause for a class-wide object, which is
4927 -- considered erroneous.
4929 elsif Is_Class_Wide_Type (Etype (U_Ent)) then
4930 Error_Msg_NE
4931 ("??class-wide object & must not be overlaid", Nam, U_Ent);
4932 Error_Msg_N
4933 ("\??Program_Error will be raised at run time", Nam);
4934 Insert_Action (Declaration_Node (U_Ent),
4935 Make_Raise_Program_Error (Loc,
4936 Reason => PE_Overlaid_Controlled_Object));
4937 return;
4939 -- Case of address clause for a (non-controlled) object
4941 elsif Ekind_In (U_Ent, E_Variable, E_Constant) then
4942 declare
4943 Expr : constant Node_Id := Expression (N);
4944 O_Ent : Entity_Id;
4945 Off : Boolean;
4947 begin
4948 -- Exported variables cannot have an address clause, because
4949 -- this cancels the effect of the pragma Export.
4951 if Is_Exported (U_Ent) then
4952 Error_Msg_N
4953 ("cannot export object with address clause", Nam);
4954 return;
4955 end if;
4957 Find_Overlaid_Entity (N, O_Ent, Off);
4959 if Present (O_Ent) then
4961 -- If the object overlays a constant object, mark it so
4963 if Is_Constant_Object (O_Ent) then
4964 Set_Overlays_Constant (U_Ent);
4965 end if;
4967 -- If the address clause is of the form:
4969 -- for X'Address use Y'Address;
4971 -- or
4973 -- C : constant Address := Y'Address;
4974 -- ...
4975 -- for X'Address use C;
4977 -- then we make an entry in the table to check the size
4978 -- and alignment of the overlaying variable. But we defer
4979 -- this check till after code generation to take full
4980 -- advantage of the annotation done by the back end.
4982 -- If the entity has a generic type, the check will be
4983 -- performed in the instance if the actual type justifies
4984 -- it, and we do not insert the clause in the table to
4985 -- prevent spurious warnings.
4987 -- Note: we used to test Comes_From_Source and only give
4988 -- this warning for source entities, but we have removed
4989 -- this test. It really seems bogus to generate overlays
4990 -- that would trigger this warning in generated code.
4991 -- Furthermore, by removing the test, we handle the
4992 -- aspect case properly.
4994 if Is_Object (O_Ent)
4995 and then not Is_Generic_Type (Etype (U_Ent))
4996 and then Address_Clause_Overlay_Warnings
4997 then
4998 Address_Clause_Checks.Append
4999 ((N, U_Ent, No_Uint, O_Ent, Off));
5000 end if;
5001 else
5002 -- If this is not an overlay, mark a variable as being
5003 -- volatile to prevent unwanted optimizations. It's a
5004 -- conservative interpretation of RM 13.3(19) for the
5005 -- cases where the compiler cannot detect potential
5006 -- aliasing issues easily and it also covers the case
5007 -- of an absolute address where the volatile aspect is
5008 -- kind of implicit.
5010 if Ekind (U_Ent) = E_Variable then
5011 Set_Treat_As_Volatile (U_Ent);
5012 end if;
5014 -- Make an entry in the table for an absolute address as
5015 -- above to check that the value is compatible with the
5016 -- alignment of the object.
5018 declare
5019 Addr : constant Node_Id := Address_Value (Expr);
5020 begin
5021 if Compile_Time_Known_Value (Addr)
5022 and then Address_Clause_Overlay_Warnings
5023 then
5024 Address_Clause_Checks.Append
5025 ((N, U_Ent, Expr_Value (Addr), Empty, False));
5026 end if;
5027 end;
5028 end if;
5030 -- Overlaying controlled objects is erroneous. Emit warning
5031 -- but continue analysis because program is itself legal,
5032 -- and back end must see address clause.
5034 if Present (O_Ent)
5035 and then (Has_Controlled_Component (Etype (O_Ent))
5036 or else Is_Controlled (Etype (O_Ent)))
5037 and then not Inside_A_Generic
5038 then
5039 Error_Msg_N
5040 ("??cannot use overlays with controlled objects", Expr);
5041 Error_Msg_N
5042 ("\??Program_Error will be raised at run time", Expr);
5043 Insert_Action (Declaration_Node (U_Ent),
5044 Make_Raise_Program_Error (Loc,
5045 Reason => PE_Overlaid_Controlled_Object));
5047 -- Issue an unconditional warning for a constant overlaying
5048 -- a variable. For the reverse case, we will issue it only
5049 -- if the variable is modified.
5051 elsif Ekind (U_Ent) = E_Constant
5052 and then Present (O_Ent)
5053 and then not Overlays_Constant (U_Ent)
5054 and then Address_Clause_Overlay_Warnings
5055 then
5056 Error_Msg_N ("??constant overlays a variable", Expr);
5058 -- Imported variables can have an address clause, but then
5059 -- the import is pretty meaningless except to suppress
5060 -- initializations, so we do not need such variables to
5061 -- be statically allocated (and in fact it causes trouble
5062 -- if the address clause is a local value).
5064 elsif Is_Imported (U_Ent) then
5065 Set_Is_Statically_Allocated (U_Ent, False);
5066 end if;
5068 -- We mark a possible modification of a variable with an
5069 -- address clause, since it is likely aliasing is occurring.
5071 Note_Possible_Modification (Nam, Sure => False);
5073 -- Legality checks on the address clause for initialized
5074 -- objects is deferred until the freeze point, because
5075 -- a subsequent pragma might indicate that the object
5076 -- is imported and thus not initialized. Also, the address
5077 -- clause might involve entities that have yet to be
5078 -- elaborated.
5080 Set_Has_Delayed_Freeze (U_Ent);
5082 -- If an initialization call has been generated for this
5083 -- object, it needs to be deferred to after the freeze node
5084 -- we have just now added, otherwise GIGI will see a
5085 -- reference to the variable (as actual to the IP call)
5086 -- before its definition.
5088 declare
5089 Init_Call : constant Node_Id :=
5090 Remove_Init_Call (U_Ent, N);
5092 begin
5093 if Present (Init_Call) then
5094 Append_Freeze_Action (U_Ent, Init_Call);
5096 -- Reset Initialization_Statements pointer so that
5097 -- if there is a pragma Import further down, it can
5098 -- clear any default initialization.
5100 Set_Initialization_Statements (U_Ent, Init_Call);
5101 end if;
5102 end;
5104 -- Entity has delayed freeze, so we will generate an
5105 -- alignment check at the freeze point unless suppressed.
5107 if not Range_Checks_Suppressed (U_Ent)
5108 and then not Alignment_Checks_Suppressed (U_Ent)
5109 then
5110 Set_Check_Address_Alignment (N);
5111 end if;
5113 -- Kill the size check code, since we are not allocating
5114 -- the variable, it is somewhere else.
5116 Kill_Size_Check_Code (U_Ent);
5117 end;
5119 -- Not a valid entity for an address clause
5121 else
5122 Error_Msg_N ("address cannot be given for &", Nam);
5123 end if;
5124 end Address;
5126 ---------------
5127 -- Alignment --
5128 ---------------
5130 -- Alignment attribute definition clause
5132 when Attribute_Alignment => Alignment : declare
5133 Align : constant Uint := Get_Alignment_Value (Expr);
5134 Max_Align : constant Uint := UI_From_Int (Maximum_Alignment);
5136 begin
5137 FOnly := True;
5139 if not Is_Type (U_Ent)
5140 and then Ekind (U_Ent) /= E_Variable
5141 and then Ekind (U_Ent) /= E_Constant
5142 then
5143 Error_Msg_N ("alignment cannot be given for &", Nam);
5145 elsif Duplicate_Clause then
5146 null;
5148 elsif Align /= No_Uint then
5149 Set_Has_Alignment_Clause (U_Ent);
5151 -- Tagged type case, check for attempt to set alignment to a
5152 -- value greater than Max_Align, and reset if so. This error
5153 -- is suppressed in ASIS mode to allow for different ASIS
5154 -- back ends or ASIS-based tools to query the illegal clause.
5156 if Is_Tagged_Type (U_Ent)
5157 and then Align > Max_Align
5158 and then not ASIS_Mode
5159 then
5160 Error_Msg_N
5161 ("alignment for & set to Maximum_Aligment??", Nam);
5162 Set_Alignment (U_Ent, Max_Align);
5164 -- All other cases
5166 else
5167 Set_Alignment (U_Ent, Align);
5168 end if;
5170 -- For an array type, U_Ent is the first subtype. In that case,
5171 -- also set the alignment of the anonymous base type so that
5172 -- other subtypes (such as the itypes for aggregates of the
5173 -- type) also receive the expected alignment.
5175 if Is_Array_Type (U_Ent) then
5176 Set_Alignment (Base_Type (U_Ent), Align);
5177 end if;
5178 end if;
5179 end Alignment;
5181 ---------------
5182 -- Bit_Order --
5183 ---------------
5185 -- Bit_Order attribute definition clause
5187 when Attribute_Bit_Order =>
5188 if not Is_Record_Type (U_Ent) then
5189 Error_Msg_N
5190 ("Bit_Order can only be defined for record type", Nam);
5192 elsif Duplicate_Clause then
5193 null;
5195 else
5196 Analyze_And_Resolve (Expr, RTE (RE_Bit_Order));
5198 if Etype (Expr) = Any_Type then
5199 return;
5201 elsif not Is_OK_Static_Expression (Expr) then
5202 Flag_Non_Static_Expr
5203 ("Bit_Order requires static expression!", Expr);
5205 else
5206 if (Expr_Value (Expr) = 0) /= Bytes_Big_Endian then
5207 Set_Reverse_Bit_Order (Base_Type (U_Ent), True);
5208 end if;
5209 end if;
5210 end if;
5212 --------------------
5213 -- Component_Size --
5214 --------------------
5216 -- Component_Size attribute definition clause
5218 when Attribute_Component_Size => Component_Size_Case : declare
5219 Csize : constant Uint := Static_Integer (Expr);
5220 Ctyp : Entity_Id;
5221 Btype : Entity_Id;
5222 Biased : Boolean;
5223 New_Ctyp : Entity_Id;
5224 Decl : Node_Id;
5226 begin
5227 if not Is_Array_Type (U_Ent) then
5228 Error_Msg_N ("component size requires array type", Nam);
5229 return;
5230 end if;
5232 Btype := Base_Type (U_Ent);
5233 Ctyp := Component_Type (Btype);
5235 if Duplicate_Clause then
5236 null;
5238 elsif Rep_Item_Too_Early (Btype, N) then
5239 null;
5241 elsif Csize /= No_Uint then
5242 Check_Size (Expr, Ctyp, Csize, Biased);
5244 -- For the biased case, build a declaration for a subtype that
5245 -- will be used to represent the biased subtype that reflects
5246 -- the biased representation of components. We need the subtype
5247 -- to get proper conversions on referencing elements of the
5248 -- array.
5250 if Biased then
5251 New_Ctyp :=
5252 Make_Defining_Identifier (Loc,
5253 Chars =>
5254 New_External_Name (Chars (U_Ent), 'C', 0, 'T'));
5256 Decl :=
5257 Make_Subtype_Declaration (Loc,
5258 Defining_Identifier => New_Ctyp,
5259 Subtype_Indication =>
5260 New_Occurrence_Of (Component_Type (Btype), Loc));
5262 Set_Parent (Decl, N);
5263 Analyze (Decl, Suppress => All_Checks);
5265 Set_Has_Delayed_Freeze (New_Ctyp, False);
5266 Set_Esize (New_Ctyp, Csize);
5267 Set_RM_Size (New_Ctyp, Csize);
5268 Init_Alignment (New_Ctyp);
5269 Set_Is_Itype (New_Ctyp, True);
5270 Set_Associated_Node_For_Itype (New_Ctyp, U_Ent);
5272 Set_Component_Type (Btype, New_Ctyp);
5273 Set_Biased (New_Ctyp, N, "component size clause");
5274 end if;
5276 Set_Component_Size (Btype, Csize);
5278 -- Deal with warning on overridden size
5280 if Warn_On_Overridden_Size
5281 and then Has_Size_Clause (Ctyp)
5282 and then RM_Size (Ctyp) /= Csize
5283 then
5284 Error_Msg_NE
5285 ("component size overrides size clause for&?S?", N, Ctyp);
5286 end if;
5288 Set_Has_Component_Size_Clause (Btype, True);
5289 Set_Has_Non_Standard_Rep (Btype, True);
5290 end if;
5291 end Component_Size_Case;
5293 -----------------------
5294 -- Constant_Indexing --
5295 -----------------------
5297 when Attribute_Constant_Indexing =>
5298 Check_Indexing_Functions;
5300 ---------
5301 -- CPU --
5302 ---------
5304 when Attribute_CPU =>
5306 -- CPU attribute definition clause not allowed except from aspect
5307 -- specification.
5309 if From_Aspect_Specification (N) then
5310 if not Is_Task_Type (U_Ent) then
5311 Error_Msg_N ("CPU can only be defined for task", Nam);
5313 elsif Duplicate_Clause then
5314 null;
5316 else
5317 -- The expression must be analyzed in the special manner
5318 -- described in "Handling of Default and Per-Object
5319 -- Expressions" in sem.ads.
5321 -- The visibility to the discriminants must be restored
5323 Push_Scope_And_Install_Discriminants (U_Ent);
5324 Preanalyze_Spec_Expression (Expr, RTE (RE_CPU_Range));
5325 Uninstall_Discriminants_And_Pop_Scope (U_Ent);
5327 if not Is_OK_Static_Expression (Expr) then
5328 Check_Restriction (Static_Priorities, Expr);
5329 end if;
5330 end if;
5332 else
5333 Error_Msg_N
5334 ("attribute& cannot be set with definition clause", N);
5335 end if;
5337 ----------------------
5338 -- Default_Iterator --
5339 ----------------------
5341 when Attribute_Default_Iterator => Default_Iterator : declare
5342 Func : Entity_Id;
5343 Typ : Entity_Id;
5345 begin
5346 -- If target type is untagged, further checks are irrelevant
5348 if not Is_Tagged_Type (U_Ent) then
5349 Error_Msg_N
5350 ("aspect Default_Iterator applies to tagged type", Nam);
5351 return;
5352 end if;
5354 Check_Iterator_Functions;
5356 Analyze (Expr);
5358 if not Is_Entity_Name (Expr)
5359 or else Ekind (Entity (Expr)) /= E_Function
5360 then
5361 Error_Msg_N ("aspect Iterator must be a function", Expr);
5362 return;
5363 else
5364 Func := Entity (Expr);
5365 end if;
5367 -- The type of the first parameter must be T, T'class, or a
5368 -- corresponding access type (5.5.1 (8/3). If function is
5369 -- parameterless label type accordingly.
5371 if No (First_Formal (Func)) then
5372 Typ := Any_Type;
5373 else
5374 Typ := Etype (First_Formal (Func));
5375 end if;
5377 if Typ = U_Ent
5378 or else Typ = Class_Wide_Type (U_Ent)
5379 or else (Is_Access_Type (Typ)
5380 and then Designated_Type (Typ) = U_Ent)
5381 or else (Is_Access_Type (Typ)
5382 and then Designated_Type (Typ) =
5383 Class_Wide_Type (U_Ent))
5384 then
5385 null;
5387 else
5388 Error_Msg_NE
5389 ("Default Iterator must be a primitive of&", Func, U_Ent);
5390 end if;
5391 end Default_Iterator;
5393 ------------------------
5394 -- Dispatching_Domain --
5395 ------------------------
5397 when Attribute_Dispatching_Domain =>
5399 -- Dispatching_Domain attribute definition clause not allowed
5400 -- except from aspect specification.
5402 if From_Aspect_Specification (N) then
5403 if not Is_Task_Type (U_Ent) then
5404 Error_Msg_N
5405 ("Dispatching_Domain can only be defined for task", Nam);
5407 elsif Duplicate_Clause then
5408 null;
5410 else
5411 -- The expression must be analyzed in the special manner
5412 -- described in "Handling of Default and Per-Object
5413 -- Expressions" in sem.ads.
5415 -- The visibility to the discriminants must be restored
5417 Push_Scope_And_Install_Discriminants (U_Ent);
5419 Preanalyze_Spec_Expression
5420 (Expr, RTE (RE_Dispatching_Domain));
5422 Uninstall_Discriminants_And_Pop_Scope (U_Ent);
5423 end if;
5425 else
5426 Error_Msg_N
5427 ("attribute& cannot be set with definition clause", N);
5428 end if;
5430 ------------------
5431 -- External_Tag --
5432 ------------------
5434 when Attribute_External_Tag =>
5435 if not Is_Tagged_Type (U_Ent) then
5436 Error_Msg_N ("should be a tagged type", Nam);
5437 end if;
5439 if Duplicate_Clause then
5440 null;
5442 else
5443 Analyze_And_Resolve (Expr, Standard_String);
5445 if not Is_OK_Static_Expression (Expr) then
5446 Flag_Non_Static_Expr
5447 ("static string required for tag name!", Nam);
5448 end if;
5450 if not Is_Library_Level_Entity (U_Ent) then
5451 Error_Msg_NE
5452 ("??non-unique external tag supplied for &", N, U_Ent);
5453 Error_Msg_N
5454 ("\??same external tag applies to all subprogram calls",
5456 Error_Msg_N
5457 ("\??corresponding internal tag cannot be obtained", N);
5458 end if;
5459 end if;
5461 --------------------------
5462 -- Implicit_Dereference --
5463 --------------------------
5465 when Attribute_Implicit_Dereference =>
5467 -- Legality checks already performed at the point of the type
5468 -- declaration, aspect is not delayed.
5470 null;
5472 -----------
5473 -- Input --
5474 -----------
5476 when Attribute_Input =>
5477 Analyze_Stream_TSS_Definition (TSS_Stream_Input);
5478 Set_Has_Specified_Stream_Input (Ent);
5480 ------------------------
5481 -- Interrupt_Priority --
5482 ------------------------
5484 when Attribute_Interrupt_Priority =>
5486 -- Interrupt_Priority attribute definition clause not allowed
5487 -- except from aspect specification.
5489 if From_Aspect_Specification (N) then
5490 if not Is_Concurrent_Type (U_Ent) then
5491 Error_Msg_N
5492 ("Interrupt_Priority can only be defined for task and "
5493 & "protected object", Nam);
5495 elsif Duplicate_Clause then
5496 null;
5498 else
5499 -- The expression must be analyzed in the special manner
5500 -- described in "Handling of Default and Per-Object
5501 -- Expressions" in sem.ads.
5503 -- The visibility to the discriminants must be restored
5505 Push_Scope_And_Install_Discriminants (U_Ent);
5507 Preanalyze_Spec_Expression
5508 (Expr, RTE (RE_Interrupt_Priority));
5510 Uninstall_Discriminants_And_Pop_Scope (U_Ent);
5512 -- Check the No_Task_At_Interrupt_Priority restriction
5514 if Is_Task_Type (U_Ent) then
5515 Check_Restriction (No_Task_At_Interrupt_Priority, N);
5516 end if;
5517 end if;
5519 else
5520 Error_Msg_N
5521 ("attribute& cannot be set with definition clause", N);
5522 end if;
5524 --------------
5525 -- Iterable --
5526 --------------
5528 when Attribute_Iterable =>
5529 Analyze (Expr);
5531 if Nkind (Expr) /= N_Aggregate then
5532 Error_Msg_N ("aspect Iterable must be an aggregate", Expr);
5533 end if;
5535 declare
5536 Assoc : Node_Id;
5538 begin
5539 Assoc := First (Component_Associations (Expr));
5540 while Present (Assoc) loop
5541 if not Is_Entity_Name (Expression (Assoc)) then
5542 Error_Msg_N ("value must be a function", Assoc);
5543 end if;
5545 Next (Assoc);
5546 end loop;
5547 end;
5549 ----------------------
5550 -- Iterator_Element --
5551 ----------------------
5553 when Attribute_Iterator_Element =>
5554 Analyze (Expr);
5556 if not Is_Entity_Name (Expr)
5557 or else not Is_Type (Entity (Expr))
5558 then
5559 Error_Msg_N ("aspect Iterator_Element must be a type", Expr);
5560 end if;
5562 -------------------
5563 -- Machine_Radix --
5564 -------------------
5566 -- Machine radix attribute definition clause
5568 when Attribute_Machine_Radix => Machine_Radix : declare
5569 Radix : constant Uint := Static_Integer (Expr);
5571 begin
5572 if not Is_Decimal_Fixed_Point_Type (U_Ent) then
5573 Error_Msg_N ("decimal fixed-point type expected for &", Nam);
5575 elsif Duplicate_Clause then
5576 null;
5578 elsif Radix /= No_Uint then
5579 Set_Has_Machine_Radix_Clause (U_Ent);
5580 Set_Has_Non_Standard_Rep (Base_Type (U_Ent));
5582 if Radix = 2 then
5583 null;
5585 elsif Radix = 10 then
5586 Set_Machine_Radix_10 (U_Ent);
5588 -- The following error is suppressed in ASIS mode to allow for
5589 -- different ASIS back ends or ASIS-based tools to query the
5590 -- illegal clause.
5592 elsif not ASIS_Mode then
5593 Error_Msg_N ("machine radix value must be 2 or 10", Expr);
5594 end if;
5595 end if;
5596 end Machine_Radix;
5598 -----------------
5599 -- Object_Size --
5600 -----------------
5602 -- Object_Size attribute definition clause
5604 when Attribute_Object_Size => Object_Size : declare
5605 Size : constant Uint := Static_Integer (Expr);
5607 Biased : Boolean;
5608 pragma Warnings (Off, Biased);
5610 begin
5611 if not Is_Type (U_Ent) then
5612 Error_Msg_N ("Object_Size cannot be given for &", Nam);
5614 elsif Duplicate_Clause then
5615 null;
5617 else
5618 Check_Size (Expr, U_Ent, Size, Biased);
5620 -- The following errors are suppressed in ASIS mode to allow
5621 -- for different ASIS back ends or ASIS-based tools to query
5622 -- the illegal clause.
5624 if ASIS_Mode then
5625 null;
5627 elsif Is_Scalar_Type (U_Ent) then
5628 if Size /= 8 and then Size /= 16 and then Size /= 32
5629 and then UI_Mod (Size, 64) /= 0
5630 then
5631 Error_Msg_N
5632 ("Object_Size must be 8, 16, 32, or multiple of 64",
5633 Expr);
5634 end if;
5636 elsif Size mod 8 /= 0 then
5637 Error_Msg_N ("Object_Size must be a multiple of 8", Expr);
5638 end if;
5640 Set_Esize (U_Ent, Size);
5641 Set_Has_Object_Size_Clause (U_Ent);
5642 Alignment_Check_For_Size_Change (U_Ent, Size);
5643 end if;
5644 end Object_Size;
5646 ------------
5647 -- Output --
5648 ------------
5650 when Attribute_Output =>
5651 Analyze_Stream_TSS_Definition (TSS_Stream_Output);
5652 Set_Has_Specified_Stream_Output (Ent);
5654 --------------
5655 -- Priority --
5656 --------------
5658 when Attribute_Priority =>
5660 -- Priority attribute definition clause not allowed except from
5661 -- aspect specification.
5663 if From_Aspect_Specification (N) then
5664 if not (Is_Concurrent_Type (U_Ent)
5665 or else Ekind (U_Ent) = E_Procedure)
5666 then
5667 Error_Msg_N
5668 ("Priority can only be defined for task and protected "
5669 & "object", Nam);
5671 elsif Duplicate_Clause then
5672 null;
5674 else
5675 -- The expression must be analyzed in the special manner
5676 -- described in "Handling of Default and Per-Object
5677 -- Expressions" in sem.ads.
5679 -- The visibility to the discriminants must be restored
5681 Push_Scope_And_Install_Discriminants (U_Ent);
5682 Preanalyze_Spec_Expression (Expr, Standard_Integer);
5683 Uninstall_Discriminants_And_Pop_Scope (U_Ent);
5685 if not Is_OK_Static_Expression (Expr) then
5686 Check_Restriction (Static_Priorities, Expr);
5687 end if;
5688 end if;
5690 else
5691 Error_Msg_N
5692 ("attribute& cannot be set with definition clause", N);
5693 end if;
5695 ----------
5696 -- Read --
5697 ----------
5699 when Attribute_Read =>
5700 Analyze_Stream_TSS_Definition (TSS_Stream_Read);
5701 Set_Has_Specified_Stream_Read (Ent);
5703 --------------------------
5704 -- Scalar_Storage_Order --
5705 --------------------------
5707 -- Scalar_Storage_Order attribute definition clause
5709 when Attribute_Scalar_Storage_Order =>
5710 if not (Is_Record_Type (U_Ent) or else Is_Array_Type (U_Ent)) then
5711 Error_Msg_N
5712 ("Scalar_Storage_Order can only be defined for record or "
5713 & "array type", Nam);
5715 elsif Duplicate_Clause then
5716 null;
5718 else
5719 Analyze_And_Resolve (Expr, RTE (RE_Bit_Order));
5721 if Etype (Expr) = Any_Type then
5722 return;
5724 elsif not Is_OK_Static_Expression (Expr) then
5725 Flag_Non_Static_Expr
5726 ("Scalar_Storage_Order requires static expression!", Expr);
5728 elsif (Expr_Value (Expr) = 0) /= Bytes_Big_Endian then
5730 -- Here for the case of a non-default (i.e. non-confirming)
5731 -- Scalar_Storage_Order attribute definition.
5733 if Support_Nondefault_SSO_On_Target then
5734 Set_Reverse_Storage_Order (Base_Type (U_Ent), True);
5735 else
5736 Error_Msg_N
5737 ("non-default Scalar_Storage_Order not supported on "
5738 & "target", Expr);
5739 end if;
5740 end if;
5742 -- Clear SSO default indications since explicit setting of the
5743 -- order overrides the defaults.
5745 Set_SSO_Set_Low_By_Default (Base_Type (U_Ent), False);
5746 Set_SSO_Set_High_By_Default (Base_Type (U_Ent), False);
5747 end if;
5749 --------------------------
5750 -- Secondary_Stack_Size --
5751 --------------------------
5753 when Attribute_Secondary_Stack_Size =>
5755 -- Secondary_Stack_Size attribute definition clause not allowed
5756 -- except from aspect specification.
5758 if From_Aspect_Specification (N) then
5759 if not Is_Task_Type (U_Ent) then
5760 Error_Msg_N
5761 ("Secondary Stack Size can only be defined for task", Nam);
5763 elsif Duplicate_Clause then
5764 null;
5766 else
5767 Check_Restriction (No_Secondary_Stack, Expr);
5769 -- The expression must be analyzed in the special manner
5770 -- described in "Handling of Default and Per-Object
5771 -- Expressions" in sem.ads.
5773 -- The visibility to the discriminants must be restored
5775 Push_Scope_And_Install_Discriminants (U_Ent);
5776 Preanalyze_Spec_Expression (Expr, Any_Integer);
5777 Uninstall_Discriminants_And_Pop_Scope (U_Ent);
5779 if not Is_OK_Static_Expression (Expr) then
5780 Check_Restriction (Static_Storage_Size, Expr);
5781 end if;
5782 end if;
5784 else
5785 Error_Msg_N
5786 ("attribute& cannot be set with definition clause", N);
5787 end if;
5789 ----------
5790 -- Size --
5791 ----------
5793 -- Size attribute definition clause
5795 when Attribute_Size => Size : declare
5796 Size : constant Uint := Static_Integer (Expr);
5797 Etyp : Entity_Id;
5798 Biased : Boolean;
5800 begin
5801 FOnly := True;
5803 if Duplicate_Clause then
5804 null;
5806 elsif not Is_Type (U_Ent)
5807 and then Ekind (U_Ent) /= E_Variable
5808 and then Ekind (U_Ent) /= E_Constant
5809 then
5810 Error_Msg_N ("size cannot be given for &", Nam);
5812 elsif Is_Array_Type (U_Ent)
5813 and then not Is_Constrained (U_Ent)
5814 then
5815 Error_Msg_N
5816 ("size cannot be given for unconstrained array", Nam);
5818 elsif Size /= No_Uint then
5819 if Is_Type (U_Ent) then
5820 Etyp := U_Ent;
5821 else
5822 Etyp := Etype (U_Ent);
5823 end if;
5825 -- Check size, note that Gigi is in charge of checking that the
5826 -- size of an array or record type is OK. Also we do not check
5827 -- the size in the ordinary fixed-point case, since it is too
5828 -- early to do so (there may be subsequent small clause that
5829 -- affects the size). We can check the size if a small clause
5830 -- has already been given.
5832 if not Is_Ordinary_Fixed_Point_Type (U_Ent)
5833 or else Has_Small_Clause (U_Ent)
5834 then
5835 Check_Size (Expr, Etyp, Size, Biased);
5836 Set_Biased (U_Ent, N, "size clause", Biased);
5837 end if;
5839 -- For types set RM_Size and Esize if possible
5841 if Is_Type (U_Ent) then
5842 Set_RM_Size (U_Ent, Size);
5844 -- For elementary types, increase Object_Size to power of 2,
5845 -- but not less than a storage unit in any case (normally
5846 -- this means it will be byte addressable).
5848 -- For all other types, nothing else to do, we leave Esize
5849 -- (object size) unset, the back end will set it from the
5850 -- size and alignment in an appropriate manner.
5852 -- In both cases, we check whether the alignment must be
5853 -- reset in the wake of the size change.
5855 if Is_Elementary_Type (U_Ent) then
5856 if Size <= System_Storage_Unit then
5857 Init_Esize (U_Ent, System_Storage_Unit);
5858 elsif Size <= 16 then
5859 Init_Esize (U_Ent, 16);
5860 elsif Size <= 32 then
5861 Init_Esize (U_Ent, 32);
5862 else
5863 Set_Esize (U_Ent, (Size + 63) / 64 * 64);
5864 end if;
5866 Alignment_Check_For_Size_Change (U_Ent, Esize (U_Ent));
5867 else
5868 Alignment_Check_For_Size_Change (U_Ent, Size);
5869 end if;
5871 -- For objects, set Esize only
5873 else
5874 -- The following error is suppressed in ASIS mode to allow
5875 -- for different ASIS back ends or ASIS-based tools to query
5876 -- the illegal clause.
5878 if Is_Elementary_Type (Etyp)
5879 and then Size /= System_Storage_Unit
5880 and then Size /= System_Storage_Unit * 2
5881 and then Size /= System_Storage_Unit * 4
5882 and then Size /= System_Storage_Unit * 8
5883 and then not ASIS_Mode
5884 then
5885 Error_Msg_Uint_1 := UI_From_Int (System_Storage_Unit);
5886 Error_Msg_Uint_2 := Error_Msg_Uint_1 * 8;
5887 Error_Msg_N
5888 ("size for primitive object must be a power of 2 in "
5889 & "the range ^-^", N);
5890 end if;
5892 Set_Esize (U_Ent, Size);
5893 end if;
5895 Set_Has_Size_Clause (U_Ent);
5896 end if;
5897 end Size;
5899 -----------
5900 -- Small --
5901 -----------
5903 -- Small attribute definition clause
5905 when Attribute_Small => Small : declare
5906 Implicit_Base : constant Entity_Id := Base_Type (U_Ent);
5907 Small : Ureal;
5909 begin
5910 Analyze_And_Resolve (Expr, Any_Real);
5912 if Etype (Expr) = Any_Type then
5913 return;
5915 elsif not Is_OK_Static_Expression (Expr) then
5916 Flag_Non_Static_Expr
5917 ("small requires static expression!", Expr);
5918 return;
5920 else
5921 Small := Expr_Value_R (Expr);
5923 if Small <= Ureal_0 then
5924 Error_Msg_N ("small value must be greater than zero", Expr);
5925 return;
5926 end if;
5928 end if;
5930 if not Is_Ordinary_Fixed_Point_Type (U_Ent) then
5931 Error_Msg_N
5932 ("small requires an ordinary fixed point type", Nam);
5934 elsif Has_Small_Clause (U_Ent) then
5935 Error_Msg_N ("small already given for &", Nam);
5937 elsif Small > Delta_Value (U_Ent) then
5938 Error_Msg_N
5939 ("small value must not be greater than delta value", Nam);
5941 else
5942 Set_Small_Value (U_Ent, Small);
5943 Set_Small_Value (Implicit_Base, Small);
5944 Set_Has_Small_Clause (U_Ent);
5945 Set_Has_Small_Clause (Implicit_Base);
5946 Set_Has_Non_Standard_Rep (Implicit_Base);
5947 end if;
5948 end Small;
5950 ------------------
5951 -- Storage_Pool --
5952 ------------------
5954 -- Storage_Pool attribute definition clause
5956 when Attribute_Simple_Storage_Pool
5957 | Attribute_Storage_Pool
5959 Storage_Pool : declare
5960 Pool : Entity_Id;
5961 T : Entity_Id;
5963 begin
5964 if Ekind (U_Ent) = E_Access_Subprogram_Type then
5965 Error_Msg_N
5966 ("storage pool cannot be given for access-to-subprogram type",
5967 Nam);
5968 return;
5970 elsif not Ekind_In (U_Ent, E_Access_Type, E_General_Access_Type)
5971 then
5972 Error_Msg_N
5973 ("storage pool can only be given for access types", Nam);
5974 return;
5976 elsif Is_Derived_Type (U_Ent) then
5977 Error_Msg_N
5978 ("storage pool cannot be given for a derived access type",
5979 Nam);
5981 elsif Duplicate_Clause then
5982 return;
5984 elsif Present (Associated_Storage_Pool (U_Ent)) then
5985 Error_Msg_N ("storage pool already given for &", Nam);
5986 return;
5987 end if;
5989 -- Check for Storage_Size previously given
5991 declare
5992 SS : constant Node_Id :=
5993 Get_Attribute_Definition_Clause
5994 (U_Ent, Attribute_Storage_Size);
5995 begin
5996 if Present (SS) then
5997 Check_Pool_Size_Clash (U_Ent, N, SS);
5998 end if;
5999 end;
6001 -- Storage_Pool case
6003 if Id = Attribute_Storage_Pool then
6004 Analyze_And_Resolve
6005 (Expr, Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
6007 -- In the Simple_Storage_Pool case, we allow a variable of any
6008 -- simple storage pool type, so we Resolve without imposing an
6009 -- expected type.
6011 else
6012 Analyze_And_Resolve (Expr);
6014 if not Present (Get_Rep_Pragma
6015 (Etype (Expr), Name_Simple_Storage_Pool_Type))
6016 then
6017 Error_Msg_N
6018 ("expression must be of a simple storage pool type", Expr);
6019 end if;
6020 end if;
6022 if not Denotes_Variable (Expr) then
6023 Error_Msg_N ("storage pool must be a variable", Expr);
6024 return;
6025 end if;
6027 if Nkind (Expr) = N_Type_Conversion then
6028 T := Etype (Expression (Expr));
6029 else
6030 T := Etype (Expr);
6031 end if;
6033 -- The Stack_Bounded_Pool is used internally for implementing
6034 -- access types with a Storage_Size. Since it only work properly
6035 -- when used on one specific type, we need to check that it is not
6036 -- hijacked improperly:
6038 -- type T is access Integer;
6039 -- for T'Storage_Size use n;
6040 -- type Q is access Float;
6041 -- for Q'Storage_Size use T'Storage_Size; -- incorrect
6043 if RTE_Available (RE_Stack_Bounded_Pool)
6044 and then Base_Type (T) = RTE (RE_Stack_Bounded_Pool)
6045 then
6046 Error_Msg_N ("non-shareable internal Pool", Expr);
6047 return;
6048 end if;
6050 -- If the argument is a name that is not an entity name, then
6051 -- we construct a renaming operation to define an entity of
6052 -- type storage pool.
6054 if not Is_Entity_Name (Expr)
6055 and then Is_Object_Reference (Expr)
6056 then
6057 Pool := Make_Temporary (Loc, 'P', Expr);
6059 declare
6060 Rnode : constant Node_Id :=
6061 Make_Object_Renaming_Declaration (Loc,
6062 Defining_Identifier => Pool,
6063 Subtype_Mark =>
6064 New_Occurrence_Of (Etype (Expr), Loc),
6065 Name => Expr);
6067 begin
6068 -- If the attribute definition clause comes from an aspect
6069 -- clause, then insert the renaming before the associated
6070 -- entity's declaration, since the attribute clause has
6071 -- not yet been appended to the declaration list.
6073 if From_Aspect_Specification (N) then
6074 Insert_Before (Parent (Entity (N)), Rnode);
6075 else
6076 Insert_Before (N, Rnode);
6077 end if;
6079 Analyze (Rnode);
6080 Set_Associated_Storage_Pool (U_Ent, Pool);
6081 end;
6083 elsif Is_Entity_Name (Expr) then
6084 Pool := Entity (Expr);
6086 -- If pool is a renamed object, get original one. This can
6087 -- happen with an explicit renaming, and within instances.
6089 while Present (Renamed_Object (Pool))
6090 and then Is_Entity_Name (Renamed_Object (Pool))
6091 loop
6092 Pool := Entity (Renamed_Object (Pool));
6093 end loop;
6095 if Present (Renamed_Object (Pool))
6096 and then Nkind (Renamed_Object (Pool)) = N_Type_Conversion
6097 and then Is_Entity_Name (Expression (Renamed_Object (Pool)))
6098 then
6099 Pool := Entity (Expression (Renamed_Object (Pool)));
6100 end if;
6102 Set_Associated_Storage_Pool (U_Ent, Pool);
6104 elsif Nkind (Expr) = N_Type_Conversion
6105 and then Is_Entity_Name (Expression (Expr))
6106 and then Nkind (Original_Node (Expr)) = N_Attribute_Reference
6107 then
6108 Pool := Entity (Expression (Expr));
6109 Set_Associated_Storage_Pool (U_Ent, Pool);
6111 else
6112 Error_Msg_N ("incorrect reference to a Storage Pool", Expr);
6113 return;
6114 end if;
6115 end Storage_Pool;
6117 ------------------
6118 -- Storage_Size --
6119 ------------------
6121 -- Storage_Size attribute definition clause
6123 when Attribute_Storage_Size => Storage_Size : declare
6124 Btype : constant Entity_Id := Base_Type (U_Ent);
6126 begin
6127 if Is_Task_Type (U_Ent) then
6129 -- Check obsolescent (but never obsolescent if from aspect)
6131 if not From_Aspect_Specification (N) then
6132 Check_Restriction (No_Obsolescent_Features, N);
6134 if Warn_On_Obsolescent_Feature then
6135 Error_Msg_N
6136 ("?j?storage size clause for task is an obsolescent "
6137 & "feature (RM J.9)", N);
6138 Error_Msg_N ("\?j?use Storage_Size pragma instead", N);
6139 end if;
6140 end if;
6142 FOnly := True;
6143 end if;
6145 if not Is_Access_Type (U_Ent)
6146 and then Ekind (U_Ent) /= E_Task_Type
6147 then
6148 Error_Msg_N ("storage size cannot be given for &", Nam);
6150 elsif Is_Access_Type (U_Ent) and Is_Derived_Type (U_Ent) then
6151 Error_Msg_N
6152 ("storage size cannot be given for a derived access type",
6153 Nam);
6155 elsif Duplicate_Clause then
6156 null;
6158 else
6159 Analyze_And_Resolve (Expr, Any_Integer);
6161 if Is_Access_Type (U_Ent) then
6163 -- Check for Storage_Pool previously given
6165 declare
6166 SP : constant Node_Id :=
6167 Get_Attribute_Definition_Clause
6168 (U_Ent, Attribute_Storage_Pool);
6170 begin
6171 if Present (SP) then
6172 Check_Pool_Size_Clash (U_Ent, SP, N);
6173 end if;
6174 end;
6176 -- Special case of for x'Storage_Size use 0
6178 if Is_OK_Static_Expression (Expr)
6179 and then Expr_Value (Expr) = 0
6180 then
6181 Set_No_Pool_Assigned (Btype);
6182 end if;
6183 end if;
6185 Set_Has_Storage_Size_Clause (Btype);
6186 end if;
6187 end Storage_Size;
6189 -----------------
6190 -- Stream_Size --
6191 -----------------
6193 when Attribute_Stream_Size => Stream_Size : declare
6194 Size : constant Uint := Static_Integer (Expr);
6196 begin
6197 if Ada_Version <= Ada_95 then
6198 Check_Restriction (No_Implementation_Attributes, N);
6199 end if;
6201 if Duplicate_Clause then
6202 null;
6204 elsif Is_Elementary_Type (U_Ent) then
6206 -- The following errors are suppressed in ASIS mode to allow
6207 -- for different ASIS back ends or ASIS-based tools to query
6208 -- the illegal clause.
6210 if ASIS_Mode then
6211 null;
6213 elsif Size /= System_Storage_Unit
6214 and then Size /= System_Storage_Unit * 2
6215 and then Size /= System_Storage_Unit * 4
6216 and then Size /= System_Storage_Unit * 8
6217 then
6218 Error_Msg_Uint_1 := UI_From_Int (System_Storage_Unit);
6219 Error_Msg_N
6220 ("stream size for elementary type must be a power of 2 "
6221 & "and at least ^", N);
6223 elsif RM_Size (U_Ent) > Size then
6224 Error_Msg_Uint_1 := RM_Size (U_Ent);
6225 Error_Msg_N
6226 ("stream size for elementary type must be a power of 2 "
6227 & "and at least ^", N);
6228 end if;
6230 Set_Has_Stream_Size_Clause (U_Ent);
6232 else
6233 Error_Msg_N ("Stream_Size cannot be given for &", Nam);
6234 end if;
6235 end Stream_Size;
6237 ----------------
6238 -- Value_Size --
6239 ----------------
6241 -- Value_Size attribute definition clause
6243 when Attribute_Value_Size => Value_Size : declare
6244 Size : constant Uint := Static_Integer (Expr);
6245 Biased : Boolean;
6247 begin
6248 if not Is_Type (U_Ent) then
6249 Error_Msg_N ("Value_Size cannot be given for &", Nam);
6251 elsif Duplicate_Clause then
6252 null;
6254 elsif Is_Array_Type (U_Ent)
6255 and then not Is_Constrained (U_Ent)
6256 then
6257 Error_Msg_N
6258 ("Value_Size cannot be given for unconstrained array", Nam);
6260 else
6261 if Is_Elementary_Type (U_Ent) then
6262 Check_Size (Expr, U_Ent, Size, Biased);
6263 Set_Biased (U_Ent, N, "value size clause", Biased);
6264 end if;
6266 Set_RM_Size (U_Ent, Size);
6267 end if;
6268 end Value_Size;
6270 -----------------------
6271 -- Variable_Indexing --
6272 -----------------------
6274 when Attribute_Variable_Indexing =>
6275 Check_Indexing_Functions;
6277 -----------
6278 -- Write --
6279 -----------
6281 when Attribute_Write =>
6282 Analyze_Stream_TSS_Definition (TSS_Stream_Write);
6283 Set_Has_Specified_Stream_Write (Ent);
6285 -- All other attributes cannot be set
6287 when others =>
6288 Error_Msg_N
6289 ("attribute& cannot be set with definition clause", N);
6290 end case;
6292 -- The test for the type being frozen must be performed after any
6293 -- expression the clause has been analyzed since the expression itself
6294 -- might cause freezing that makes the clause illegal.
6296 if Rep_Item_Too_Late (U_Ent, N, FOnly) then
6297 return;
6298 end if;
6299 end Analyze_Attribute_Definition_Clause;
6301 ----------------------------
6302 -- Analyze_Code_Statement --
6303 ----------------------------
6305 procedure Analyze_Code_Statement (N : Node_Id) is
6306 HSS : constant Node_Id := Parent (N);
6307 SBody : constant Node_Id := Parent (HSS);
6308 Subp : constant Entity_Id := Current_Scope;
6309 Stmt : Node_Id;
6310 Decl : Node_Id;
6311 StmtO : Node_Id;
6312 DeclO : Node_Id;
6314 begin
6315 -- Accept foreign code statements for CodePeer. The analysis is skipped
6316 -- to avoid rejecting unrecognized constructs.
6318 if CodePeer_Mode then
6319 Set_Analyzed (N);
6320 return;
6321 end if;
6323 -- Analyze and check we get right type, note that this implements the
6324 -- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that is
6325 -- the only way that Asm_Insn could possibly be visible.
6327 Analyze_And_Resolve (Expression (N));
6329 if Etype (Expression (N)) = Any_Type then
6330 return;
6331 elsif Etype (Expression (N)) /= RTE (RE_Asm_Insn) then
6332 Error_Msg_N ("incorrect type for code statement", N);
6333 return;
6334 end if;
6336 Check_Code_Statement (N);
6338 -- Make sure we appear in the handled statement sequence of a subprogram
6339 -- (RM 13.8(3)).
6341 if Nkind (HSS) /= N_Handled_Sequence_Of_Statements
6342 or else Nkind (SBody) /= N_Subprogram_Body
6343 then
6344 Error_Msg_N
6345 ("code statement can only appear in body of subprogram", N);
6346 return;
6347 end if;
6349 -- Do remaining checks (RM 13.8(3)) if not already done
6351 if not Is_Machine_Code_Subprogram (Subp) then
6352 Set_Is_Machine_Code_Subprogram (Subp);
6354 -- No exception handlers allowed
6356 if Present (Exception_Handlers (HSS)) then
6357 Error_Msg_N
6358 ("exception handlers not permitted in machine code subprogram",
6359 First (Exception_Handlers (HSS)));
6360 end if;
6362 -- No declarations other than use clauses and pragmas (we allow
6363 -- certain internally generated declarations as well).
6365 Decl := First (Declarations (SBody));
6366 while Present (Decl) loop
6367 DeclO := Original_Node (Decl);
6368 if Comes_From_Source (DeclO)
6369 and not Nkind_In (DeclO, N_Pragma,
6370 N_Use_Package_Clause,
6371 N_Use_Type_Clause,
6372 N_Implicit_Label_Declaration)
6373 then
6374 Error_Msg_N
6375 ("this declaration not allowed in machine code subprogram",
6376 DeclO);
6377 end if;
6379 Next (Decl);
6380 end loop;
6382 -- No statements other than code statements, pragmas, and labels.
6383 -- Again we allow certain internally generated statements.
6385 -- In Ada 2012, qualified expressions are names, and the code
6386 -- statement is initially parsed as a procedure call.
6388 Stmt := First (Statements (HSS));
6389 while Present (Stmt) loop
6390 StmtO := Original_Node (Stmt);
6392 -- A procedure call transformed into a code statement is OK
6394 if Ada_Version >= Ada_2012
6395 and then Nkind (StmtO) = N_Procedure_Call_Statement
6396 and then Nkind (Name (StmtO)) = N_Qualified_Expression
6397 then
6398 null;
6400 elsif Comes_From_Source (StmtO)
6401 and then not Nkind_In (StmtO, N_Pragma,
6402 N_Label,
6403 N_Code_Statement)
6404 then
6405 Error_Msg_N
6406 ("this statement is not allowed in machine code subprogram",
6407 StmtO);
6408 end if;
6410 Next (Stmt);
6411 end loop;
6412 end if;
6413 end Analyze_Code_Statement;
6415 -----------------------------------------------
6416 -- Analyze_Enumeration_Representation_Clause --
6417 -----------------------------------------------
6419 procedure Analyze_Enumeration_Representation_Clause (N : Node_Id) is
6420 Ident : constant Node_Id := Identifier (N);
6421 Aggr : constant Node_Id := Array_Aggregate (N);
6422 Enumtype : Entity_Id;
6423 Elit : Entity_Id;
6424 Expr : Node_Id;
6425 Assoc : Node_Id;
6426 Choice : Node_Id;
6427 Val : Uint;
6429 Err : Boolean := False;
6430 -- Set True to avoid cascade errors and crashes on incorrect source code
6432 Lo : constant Uint := Expr_Value (Type_Low_Bound (Universal_Integer));
6433 Hi : constant Uint := Expr_Value (Type_High_Bound (Universal_Integer));
6434 -- Allowed range of universal integer (= allowed range of enum lit vals)
6436 Min : Uint;
6437 Max : Uint;
6438 -- Minimum and maximum values of entries
6440 Max_Node : Node_Id;
6441 -- Pointer to node for literal providing max value
6443 begin
6444 if Ignore_Rep_Clauses then
6445 Kill_Rep_Clause (N);
6446 return;
6447 end if;
6449 -- Ignore enumeration rep clauses by default in CodePeer mode,
6450 -- unless -gnatd.I is specified, as a work around for potential false
6451 -- positive messages.
6453 if CodePeer_Mode and not Debug_Flag_Dot_II then
6454 return;
6455 end if;
6457 -- First some basic error checks
6459 Find_Type (Ident);
6460 Enumtype := Entity (Ident);
6462 if Enumtype = Any_Type
6463 or else Rep_Item_Too_Early (Enumtype, N)
6464 then
6465 return;
6466 else
6467 Enumtype := Underlying_Type (Enumtype);
6468 end if;
6470 if not Is_Enumeration_Type (Enumtype) then
6471 Error_Msg_NE
6472 ("enumeration type required, found}",
6473 Ident, First_Subtype (Enumtype));
6474 return;
6475 end if;
6477 -- Ignore rep clause on generic actual type. This will already have
6478 -- been flagged on the template as an error, and this is the safest
6479 -- way to ensure we don't get a junk cascaded message in the instance.
6481 if Is_Generic_Actual_Type (Enumtype) then
6482 return;
6484 -- Type must be in current scope
6486 elsif Scope (Enumtype) /= Current_Scope then
6487 Error_Msg_N ("type must be declared in this scope", Ident);
6488 return;
6490 -- Type must be a first subtype
6492 elsif not Is_First_Subtype (Enumtype) then
6493 Error_Msg_N ("cannot give enumeration rep clause for subtype", N);
6494 return;
6496 -- Ignore duplicate rep clause
6498 elsif Has_Enumeration_Rep_Clause (Enumtype) then
6499 Error_Msg_N ("duplicate enumeration rep clause ignored", N);
6500 return;
6502 -- Don't allow rep clause for standard [wide_[wide_]]character
6504 elsif Is_Standard_Character_Type (Enumtype) then
6505 Error_Msg_N ("enumeration rep clause not allowed for this type", N);
6506 return;
6508 -- Check that the expression is a proper aggregate (no parentheses)
6510 elsif Paren_Count (Aggr) /= 0 then
6511 Error_Msg
6512 ("extra parentheses surrounding aggregate not allowed",
6513 First_Sloc (Aggr));
6514 return;
6516 -- All tests passed, so set rep clause in place
6518 else
6519 Set_Has_Enumeration_Rep_Clause (Enumtype);
6520 Set_Has_Enumeration_Rep_Clause (Base_Type (Enumtype));
6521 end if;
6523 -- Now we process the aggregate. Note that we don't use the normal
6524 -- aggregate code for this purpose, because we don't want any of the
6525 -- normal expansion activities, and a number of special semantic
6526 -- rules apply (including the component type being any integer type)
6528 Elit := First_Literal (Enumtype);
6530 -- First the positional entries if any
6532 if Present (Expressions (Aggr)) then
6533 Expr := First (Expressions (Aggr));
6534 while Present (Expr) loop
6535 if No (Elit) then
6536 Error_Msg_N ("too many entries in aggregate", Expr);
6537 return;
6538 end if;
6540 Val := Static_Integer (Expr);
6542 -- Err signals that we found some incorrect entries processing
6543 -- the list. The final checks for completeness and ordering are
6544 -- skipped in this case.
6546 if Val = No_Uint then
6547 Err := True;
6549 elsif Val < Lo or else Hi < Val then
6550 Error_Msg_N ("value outside permitted range", Expr);
6551 Err := True;
6552 end if;
6554 Set_Enumeration_Rep (Elit, Val);
6555 Set_Enumeration_Rep_Expr (Elit, Expr);
6556 Next (Expr);
6557 Next (Elit);
6558 end loop;
6559 end if;
6561 -- Now process the named entries if present
6563 if Present (Component_Associations (Aggr)) then
6564 Assoc := First (Component_Associations (Aggr));
6565 while Present (Assoc) loop
6566 Choice := First (Choices (Assoc));
6568 if Present (Next (Choice)) then
6569 Error_Msg_N
6570 ("multiple choice not allowed here", Next (Choice));
6571 Err := True;
6572 end if;
6574 if Nkind (Choice) = N_Others_Choice then
6575 Error_Msg_N ("others choice not allowed here", Choice);
6576 Err := True;
6578 elsif Nkind (Choice) = N_Range then
6580 -- ??? should allow zero/one element range here
6582 Error_Msg_N ("range not allowed here", Choice);
6583 Err := True;
6585 else
6586 Analyze_And_Resolve (Choice, Enumtype);
6588 if Error_Posted (Choice) then
6589 Err := True;
6590 end if;
6592 if not Err then
6593 if Is_Entity_Name (Choice)
6594 and then Is_Type (Entity (Choice))
6595 then
6596 Error_Msg_N ("subtype name not allowed here", Choice);
6597 Err := True;
6599 -- ??? should allow static subtype with zero/one entry
6601 elsif Etype (Choice) = Base_Type (Enumtype) then
6602 if not Is_OK_Static_Expression (Choice) then
6603 Flag_Non_Static_Expr
6604 ("non-static expression used for choice!", Choice);
6605 Err := True;
6607 else
6608 Elit := Expr_Value_E (Choice);
6610 if Present (Enumeration_Rep_Expr (Elit)) then
6611 Error_Msg_Sloc :=
6612 Sloc (Enumeration_Rep_Expr (Elit));
6613 Error_Msg_NE
6614 ("representation for& previously given#",
6615 Choice, Elit);
6616 Err := True;
6617 end if;
6619 Set_Enumeration_Rep_Expr (Elit, Expression (Assoc));
6621 Expr := Expression (Assoc);
6622 Val := Static_Integer (Expr);
6624 if Val = No_Uint then
6625 Err := True;
6627 elsif Val < Lo or else Hi < Val then
6628 Error_Msg_N ("value outside permitted range", Expr);
6629 Err := True;
6630 end if;
6632 Set_Enumeration_Rep (Elit, Val);
6633 end if;
6634 end if;
6635 end if;
6636 end if;
6638 Next (Assoc);
6639 end loop;
6640 end if;
6642 -- Aggregate is fully processed. Now we check that a full set of
6643 -- representations was given, and that they are in range and in order.
6644 -- These checks are only done if no other errors occurred.
6646 if not Err then
6647 Min := No_Uint;
6648 Max := No_Uint;
6650 Elit := First_Literal (Enumtype);
6651 while Present (Elit) loop
6652 if No (Enumeration_Rep_Expr (Elit)) then
6653 Error_Msg_NE ("missing representation for&!", N, Elit);
6655 else
6656 Val := Enumeration_Rep (Elit);
6658 if Min = No_Uint then
6659 Min := Val;
6660 end if;
6662 if Val /= No_Uint then
6663 if Max /= No_Uint and then Val <= Max then
6664 Error_Msg_NE
6665 ("enumeration value for& not ordered!",
6666 Enumeration_Rep_Expr (Elit), Elit);
6667 end if;
6669 Max_Node := Enumeration_Rep_Expr (Elit);
6670 Max := Val;
6671 end if;
6673 -- If there is at least one literal whose representation is not
6674 -- equal to the Pos value, then note that this enumeration type
6675 -- has a non-standard representation.
6677 if Val /= Enumeration_Pos (Elit) then
6678 Set_Has_Non_Standard_Rep (Base_Type (Enumtype));
6679 end if;
6680 end if;
6682 Next (Elit);
6683 end loop;
6685 -- Now set proper size information
6687 declare
6688 Minsize : Uint := UI_From_Int (Minimum_Size (Enumtype));
6690 begin
6691 if Has_Size_Clause (Enumtype) then
6693 -- All OK, if size is OK now
6695 if RM_Size (Enumtype) >= Minsize then
6696 null;
6698 else
6699 -- Try if we can get by with biasing
6701 Minsize :=
6702 UI_From_Int (Minimum_Size (Enumtype, Biased => True));
6704 -- Error message if even biasing does not work
6706 if RM_Size (Enumtype) < Minsize then
6707 Error_Msg_Uint_1 := RM_Size (Enumtype);
6708 Error_Msg_Uint_2 := Max;
6709 Error_Msg_N
6710 ("previously given size (^) is too small "
6711 & "for this value (^)", Max_Node);
6713 -- If biasing worked, indicate that we now have biased rep
6715 else
6716 Set_Biased
6717 (Enumtype, Size_Clause (Enumtype), "size clause");
6718 end if;
6719 end if;
6721 else
6722 Set_RM_Size (Enumtype, Minsize);
6723 Set_Enum_Esize (Enumtype);
6724 end if;
6726 Set_RM_Size (Base_Type (Enumtype), RM_Size (Enumtype));
6727 Set_Esize (Base_Type (Enumtype), Esize (Enumtype));
6728 Set_Alignment (Base_Type (Enumtype), Alignment (Enumtype));
6729 end;
6730 end if;
6732 -- We repeat the too late test in case it froze itself
6734 if Rep_Item_Too_Late (Enumtype, N) then
6735 null;
6736 end if;
6737 end Analyze_Enumeration_Representation_Clause;
6739 ----------------------------
6740 -- Analyze_Free_Statement --
6741 ----------------------------
6743 procedure Analyze_Free_Statement (N : Node_Id) is
6744 begin
6745 Analyze (Expression (N));
6746 end Analyze_Free_Statement;
6748 ---------------------------
6749 -- Analyze_Freeze_Entity --
6750 ---------------------------
6752 procedure Analyze_Freeze_Entity (N : Node_Id) is
6753 begin
6754 Freeze_Entity_Checks (N);
6755 end Analyze_Freeze_Entity;
6757 -----------------------------------
6758 -- Analyze_Freeze_Generic_Entity --
6759 -----------------------------------
6761 procedure Analyze_Freeze_Generic_Entity (N : Node_Id) is
6762 E : constant Entity_Id := Entity (N);
6764 begin
6765 if not Is_Frozen (E) and then Has_Delayed_Aspects (E) then
6766 Analyze_Aspects_At_Freeze_Point (E);
6767 end if;
6769 Freeze_Entity_Checks (N);
6770 end Analyze_Freeze_Generic_Entity;
6772 ------------------------------------------
6773 -- Analyze_Record_Representation_Clause --
6774 ------------------------------------------
6776 -- Note: we check as much as we can here, but we can't do any checks
6777 -- based on the position values (e.g. overlap checks) until freeze time
6778 -- because especially in Ada 2005 (machine scalar mode), the processing
6779 -- for non-standard bit order can substantially change the positions.
6780 -- See procedure Check_Record_Representation_Clause (called from Freeze)
6781 -- for the remainder of this processing.
6783 procedure Analyze_Record_Representation_Clause (N : Node_Id) is
6784 Ident : constant Node_Id := Identifier (N);
6785 Biased : Boolean;
6786 CC : Node_Id;
6787 Comp : Entity_Id;
6788 Fbit : Uint;
6789 Hbit : Uint := Uint_0;
6790 Lbit : Uint;
6791 Ocomp : Entity_Id;
6792 Posit : Uint;
6793 Rectype : Entity_Id;
6794 Recdef : Node_Id;
6796 function Is_Inherited (Comp : Entity_Id) return Boolean;
6797 -- True if Comp is an inherited component in a record extension
6799 ------------------
6800 -- Is_Inherited --
6801 ------------------
6803 function Is_Inherited (Comp : Entity_Id) return Boolean is
6804 Comp_Base : Entity_Id;
6806 begin
6807 if Ekind (Rectype) = E_Record_Subtype then
6808 Comp_Base := Original_Record_Component (Comp);
6809 else
6810 Comp_Base := Comp;
6811 end if;
6813 return Comp_Base /= Original_Record_Component (Comp_Base);
6814 end Is_Inherited;
6816 -- Local variables
6818 Is_Record_Extension : Boolean;
6819 -- True if Rectype is a record extension
6821 CR_Pragma : Node_Id := Empty;
6822 -- Points to N_Pragma node if Complete_Representation pragma present
6824 -- Start of processing for Analyze_Record_Representation_Clause
6826 begin
6827 if Ignore_Rep_Clauses then
6828 Kill_Rep_Clause (N);
6829 return;
6830 end if;
6832 Find_Type (Ident);
6833 Rectype := Entity (Ident);
6835 if Rectype = Any_Type or else Rep_Item_Too_Early (Rectype, N) then
6836 return;
6837 else
6838 Rectype := Underlying_Type (Rectype);
6839 end if;
6841 -- First some basic error checks
6843 if not Is_Record_Type (Rectype) then
6844 Error_Msg_NE
6845 ("record type required, found}", Ident, First_Subtype (Rectype));
6846 return;
6848 elsif Scope (Rectype) /= Current_Scope then
6849 Error_Msg_N ("type must be declared in this scope", N);
6850 return;
6852 elsif not Is_First_Subtype (Rectype) then
6853 Error_Msg_N ("cannot give record rep clause for subtype", N);
6854 return;
6856 elsif Has_Record_Rep_Clause (Rectype) then
6857 Error_Msg_N ("duplicate record rep clause ignored", N);
6858 return;
6860 elsif Rep_Item_Too_Late (Rectype, N) then
6861 return;
6862 end if;
6864 -- We know we have a first subtype, now possibly go to the anonymous
6865 -- base type to determine whether Rectype is a record extension.
6867 Recdef := Type_Definition (Declaration_Node (Base_Type (Rectype)));
6868 Is_Record_Extension :=
6869 Nkind (Recdef) = N_Derived_Type_Definition
6870 and then Present (Record_Extension_Part (Recdef));
6872 if Present (Mod_Clause (N)) then
6873 declare
6874 Loc : constant Source_Ptr := Sloc (N);
6875 M : constant Node_Id := Mod_Clause (N);
6876 P : constant List_Id := Pragmas_Before (M);
6877 AtM_Nod : Node_Id;
6879 Mod_Val : Uint;
6880 pragma Warnings (Off, Mod_Val);
6882 begin
6883 Check_Restriction (No_Obsolescent_Features, Mod_Clause (N));
6885 if Warn_On_Obsolescent_Feature then
6886 Error_Msg_N
6887 ("?j?mod clause is an obsolescent feature (RM J.8)", N);
6888 Error_Msg_N
6889 ("\?j?use alignment attribute definition clause instead", N);
6890 end if;
6892 if Present (P) then
6893 Analyze_List (P);
6894 end if;
6896 -- In ASIS_Mode mode, expansion is disabled, but we must convert
6897 -- the Mod clause into an alignment clause anyway, so that the
6898 -- back end can compute and back-annotate properly the size and
6899 -- alignment of types that may include this record.
6901 -- This seems dubious, this destroys the source tree in a manner
6902 -- not detectable by ASIS ???
6904 if Operating_Mode = Check_Semantics and then ASIS_Mode then
6905 AtM_Nod :=
6906 Make_Attribute_Definition_Clause (Loc,
6907 Name => New_Occurrence_Of (Base_Type (Rectype), Loc),
6908 Chars => Name_Alignment,
6909 Expression => Relocate_Node (Expression (M)));
6911 Set_From_At_Mod (AtM_Nod);
6912 Insert_After (N, AtM_Nod);
6913 Mod_Val := Get_Alignment_Value (Expression (AtM_Nod));
6914 Set_Mod_Clause (N, Empty);
6916 else
6917 -- Get the alignment value to perform error checking
6919 Mod_Val := Get_Alignment_Value (Expression (M));
6920 end if;
6921 end;
6922 end if;
6924 -- For untagged types, clear any existing component clauses for the
6925 -- type. If the type is derived, this is what allows us to override
6926 -- a rep clause for the parent. For type extensions, the representation
6927 -- of the inherited components is inherited, so we want to keep previous
6928 -- component clauses for completeness.
6930 if not Is_Tagged_Type (Rectype) then
6931 Comp := First_Component_Or_Discriminant (Rectype);
6932 while Present (Comp) loop
6933 Set_Component_Clause (Comp, Empty);
6934 Next_Component_Or_Discriminant (Comp);
6935 end loop;
6936 end if;
6938 -- All done if no component clauses
6940 CC := First (Component_Clauses (N));
6942 if No (CC) then
6943 return;
6944 end if;
6946 -- A representation like this applies to the base type
6948 Set_Has_Record_Rep_Clause (Base_Type (Rectype));
6949 Set_Has_Non_Standard_Rep (Base_Type (Rectype));
6950 Set_Has_Specified_Layout (Base_Type (Rectype));
6952 -- Process the component clauses
6954 while Present (CC) loop
6956 -- Pragma
6958 if Nkind (CC) = N_Pragma then
6959 Analyze (CC);
6961 -- The only pragma of interest is Complete_Representation
6963 if Pragma_Name (CC) = Name_Complete_Representation then
6964 CR_Pragma := CC;
6965 end if;
6967 -- Processing for real component clause
6969 else
6970 Posit := Static_Integer (Position (CC));
6971 Fbit := Static_Integer (First_Bit (CC));
6972 Lbit := Static_Integer (Last_Bit (CC));
6974 if Posit /= No_Uint
6975 and then Fbit /= No_Uint
6976 and then Lbit /= No_Uint
6977 then
6978 if Posit < 0 then
6979 Error_Msg_N ("position cannot be negative", Position (CC));
6981 elsif Fbit < 0 then
6982 Error_Msg_N ("first bit cannot be negative", First_Bit (CC));
6984 -- The Last_Bit specified in a component clause must not be
6985 -- less than the First_Bit minus one (RM-13.5.1(10)).
6987 elsif Lbit < Fbit - 1 then
6988 Error_Msg_N
6989 ("last bit cannot be less than first bit minus one",
6990 Last_Bit (CC));
6992 -- Values look OK, so find the corresponding record component
6993 -- Even though the syntax allows an attribute reference for
6994 -- implementation-defined components, GNAT does not allow the
6995 -- tag to get an explicit position.
6997 elsif Nkind (Component_Name (CC)) = N_Attribute_Reference then
6998 if Attribute_Name (Component_Name (CC)) = Name_Tag then
6999 Error_Msg_N ("position of tag cannot be specified", CC);
7000 else
7001 Error_Msg_N ("illegal component name", CC);
7002 end if;
7004 else
7005 Comp := First_Entity (Rectype);
7006 while Present (Comp) loop
7007 exit when Chars (Comp) = Chars (Component_Name (CC));
7008 Next_Entity (Comp);
7009 end loop;
7011 if No (Comp) then
7013 -- Maybe component of base type that is absent from
7014 -- statically constrained first subtype.
7016 Comp := First_Entity (Base_Type (Rectype));
7017 while Present (Comp) loop
7018 exit when Chars (Comp) = Chars (Component_Name (CC));
7019 Next_Entity (Comp);
7020 end loop;
7021 end if;
7023 if No (Comp) then
7024 Error_Msg_N
7025 ("component clause is for non-existent field", CC);
7027 -- Ada 2012 (AI05-0026): Any name that denotes a
7028 -- discriminant of an object of an unchecked union type
7029 -- shall not occur within a record_representation_clause.
7031 -- The general restriction of using record rep clauses on
7032 -- Unchecked_Union types has now been lifted. Since it is
7033 -- possible to introduce a record rep clause which mentions
7034 -- the discriminant of an Unchecked_Union in non-Ada 2012
7035 -- code, this check is applied to all versions of the
7036 -- language.
7038 elsif Ekind (Comp) = E_Discriminant
7039 and then Is_Unchecked_Union (Rectype)
7040 then
7041 Error_Msg_N
7042 ("cannot reference discriminant of unchecked union",
7043 Component_Name (CC));
7045 elsif Is_Record_Extension and then Is_Inherited (Comp) then
7046 Error_Msg_NE
7047 ("component clause not allowed for inherited "
7048 & "component&", CC, Comp);
7050 elsif Present (Component_Clause (Comp)) then
7052 -- Diagnose duplicate rep clause, or check consistency
7053 -- if this is an inherited component. In a double fault,
7054 -- there may be a duplicate inconsistent clause for an
7055 -- inherited component.
7057 if Scope (Original_Record_Component (Comp)) = Rectype
7058 or else Parent (Component_Clause (Comp)) = N
7059 then
7060 Error_Msg_Sloc := Sloc (Component_Clause (Comp));
7061 Error_Msg_N ("component clause previously given#", CC);
7063 else
7064 declare
7065 Rep1 : constant Node_Id := Component_Clause (Comp);
7066 begin
7067 if Intval (Position (Rep1)) /=
7068 Intval (Position (CC))
7069 or else Intval (First_Bit (Rep1)) /=
7070 Intval (First_Bit (CC))
7071 or else Intval (Last_Bit (Rep1)) /=
7072 Intval (Last_Bit (CC))
7073 then
7074 Error_Msg_N
7075 ("component clause inconsistent with "
7076 & "representation of ancestor", CC);
7078 elsif Warn_On_Redundant_Constructs then
7079 Error_Msg_N
7080 ("?r?redundant confirming component clause "
7081 & "for component!", CC);
7082 end if;
7083 end;
7084 end if;
7086 -- Normal case where this is the first component clause we
7087 -- have seen for this entity, so set it up properly.
7089 else
7090 -- Make reference for field in record rep clause and set
7091 -- appropriate entity field in the field identifier.
7093 Generate_Reference
7094 (Comp, Component_Name (CC), Set_Ref => False);
7095 Set_Entity (Component_Name (CC), Comp);
7097 -- Update Fbit and Lbit to the actual bit number
7099 Fbit := Fbit + UI_From_Int (SSU) * Posit;
7100 Lbit := Lbit + UI_From_Int (SSU) * Posit;
7102 if Has_Size_Clause (Rectype)
7103 and then RM_Size (Rectype) <= Lbit
7104 then
7105 Error_Msg_N
7106 ("bit number out of range of specified size",
7107 Last_Bit (CC));
7108 else
7109 Set_Component_Clause (Comp, CC);
7110 Set_Component_Bit_Offset (Comp, Fbit);
7111 Set_Esize (Comp, 1 + (Lbit - Fbit));
7112 Set_Normalized_First_Bit (Comp, Fbit mod SSU);
7113 Set_Normalized_Position (Comp, Fbit / SSU);
7115 if Warn_On_Overridden_Size
7116 and then Has_Size_Clause (Etype (Comp))
7117 and then RM_Size (Etype (Comp)) /= Esize (Comp)
7118 then
7119 Error_Msg_NE
7120 ("?S?component size overrides size clause for&",
7121 Component_Name (CC), Etype (Comp));
7122 end if;
7124 -- This information is also set in the corresponding
7125 -- component of the base type, found by accessing the
7126 -- Original_Record_Component link if it is present.
7128 Ocomp := Original_Record_Component (Comp);
7130 if Hbit < Lbit then
7131 Hbit := Lbit;
7132 end if;
7134 Check_Size
7135 (Component_Name (CC),
7136 Etype (Comp),
7137 Esize (Comp),
7138 Biased);
7140 Set_Biased
7141 (Comp, First_Node (CC), "component clause", Biased);
7143 if Present (Ocomp) then
7144 Set_Component_Clause (Ocomp, CC);
7145 Set_Component_Bit_Offset (Ocomp, Fbit);
7146 Set_Normalized_First_Bit (Ocomp, Fbit mod SSU);
7147 Set_Normalized_Position (Ocomp, Fbit / SSU);
7148 Set_Esize (Ocomp, 1 + (Lbit - Fbit));
7150 Set_Normalized_Position_Max
7151 (Ocomp, Normalized_Position (Ocomp));
7153 -- Note: we don't use Set_Biased here, because we
7154 -- already gave a warning above if needed, and we
7155 -- would get a duplicate for the same name here.
7157 Set_Has_Biased_Representation
7158 (Ocomp, Has_Biased_Representation (Comp));
7159 end if;
7161 if Esize (Comp) < 0 then
7162 Error_Msg_N ("component size is negative", CC);
7163 end if;
7164 end if;
7165 end if;
7166 end if;
7167 end if;
7168 end if;
7170 Next (CC);
7171 end loop;
7173 -- Check missing components if Complete_Representation pragma appeared
7175 if Present (CR_Pragma) then
7176 Comp := First_Component_Or_Discriminant (Rectype);
7177 while Present (Comp) loop
7178 if No (Component_Clause (Comp)) then
7179 Error_Msg_NE
7180 ("missing component clause for &", CR_Pragma, Comp);
7181 end if;
7183 Next_Component_Or_Discriminant (Comp);
7184 end loop;
7186 -- Give missing components warning if required
7188 elsif Warn_On_Unrepped_Components then
7189 declare
7190 Num_Repped_Components : Nat := 0;
7191 Num_Unrepped_Components : Nat := 0;
7193 begin
7194 -- First count number of repped and unrepped components
7196 Comp := First_Component_Or_Discriminant (Rectype);
7197 while Present (Comp) loop
7198 if Present (Component_Clause (Comp)) then
7199 Num_Repped_Components := Num_Repped_Components + 1;
7200 else
7201 Num_Unrepped_Components := Num_Unrepped_Components + 1;
7202 end if;
7204 Next_Component_Or_Discriminant (Comp);
7205 end loop;
7207 -- We are only interested in the case where there is at least one
7208 -- unrepped component, and at least half the components have rep
7209 -- clauses. We figure that if less than half have them, then the
7210 -- partial rep clause is really intentional. If the component
7211 -- type has no underlying type set at this point (as for a generic
7212 -- formal type), we don't know enough to give a warning on the
7213 -- component.
7215 if Num_Unrepped_Components > 0
7216 and then Num_Unrepped_Components < Num_Repped_Components
7217 then
7218 Comp := First_Component_Or_Discriminant (Rectype);
7219 while Present (Comp) loop
7220 if No (Component_Clause (Comp))
7221 and then Comes_From_Source (Comp)
7222 and then Present (Underlying_Type (Etype (Comp)))
7223 and then (Is_Scalar_Type (Underlying_Type (Etype (Comp)))
7224 or else Size_Known_At_Compile_Time
7225 (Underlying_Type (Etype (Comp))))
7226 and then not Has_Warnings_Off (Rectype)
7228 -- Ignore discriminant in unchecked union, since it is
7229 -- not there, and cannot have a component clause.
7231 and then (not Is_Unchecked_Union (Rectype)
7232 or else Ekind (Comp) /= E_Discriminant)
7233 then
7234 Error_Msg_Sloc := Sloc (Comp);
7235 Error_Msg_NE
7236 ("?C?no component clause given for & declared #",
7237 N, Comp);
7238 end if;
7240 Next_Component_Or_Discriminant (Comp);
7241 end loop;
7242 end if;
7243 end;
7244 end if;
7245 end Analyze_Record_Representation_Clause;
7247 -------------------------------------
7248 -- Build_Discrete_Static_Predicate --
7249 -------------------------------------
7251 procedure Build_Discrete_Static_Predicate
7252 (Typ : Entity_Id;
7253 Expr : Node_Id;
7254 Nam : Name_Id)
7256 Loc : constant Source_Ptr := Sloc (Expr);
7258 Non_Static : exception;
7259 -- Raised if something non-static is found
7261 Btyp : constant Entity_Id := Base_Type (Typ);
7263 BLo : constant Uint := Expr_Value (Type_Low_Bound (Btyp));
7264 BHi : constant Uint := Expr_Value (Type_High_Bound (Btyp));
7265 -- Low bound and high bound value of base type of Typ
7267 TLo : Uint;
7268 THi : Uint;
7269 -- Bounds for constructing the static predicate. We use the bound of the
7270 -- subtype if it is static, otherwise the corresponding base type bound.
7271 -- Note: a non-static subtype can have a static predicate.
7273 type REnt is record
7274 Lo, Hi : Uint;
7275 end record;
7276 -- One entry in a Rlist value, a single REnt (range entry) value denotes
7277 -- one range from Lo to Hi. To represent a single value range Lo = Hi =
7278 -- value.
7280 type RList is array (Nat range <>) of REnt;
7281 -- A list of ranges. The ranges are sorted in increasing order, and are
7282 -- disjoint (there is a gap of at least one value between each range in
7283 -- the table). A value is in the set of ranges in Rlist if it lies
7284 -- within one of these ranges.
7286 False_Range : constant RList :=
7287 RList'(1 .. 0 => REnt'(No_Uint, No_Uint));
7288 -- An empty set of ranges represents a range list that can never be
7289 -- satisfied, since there are no ranges in which the value could lie,
7290 -- so it does not lie in any of them. False_Range is a canonical value
7291 -- for this empty set, but general processing should test for an Rlist
7292 -- with length zero (see Is_False predicate), since other null ranges
7293 -- may appear which must be treated as False.
7295 True_Range : constant RList := RList'(1 => REnt'(BLo, BHi));
7296 -- Range representing True, value must be in the base range
7298 function "and" (Left : RList; Right : RList) return RList;
7299 -- And's together two range lists, returning a range list. This is a set
7300 -- intersection operation.
7302 function "or" (Left : RList; Right : RList) return RList;
7303 -- Or's together two range lists, returning a range list. This is a set
7304 -- union operation.
7306 function "not" (Right : RList) return RList;
7307 -- Returns complement of a given range list, i.e. a range list
7308 -- representing all the values in TLo .. THi that are not in the input
7309 -- operand Right.
7311 function Build_Val (V : Uint) return Node_Id;
7312 -- Return an analyzed N_Identifier node referencing this value, suitable
7313 -- for use as an entry in the Static_Discrte_Predicate list. This node
7314 -- is typed with the base type.
7316 function Build_Range (Lo : Uint; Hi : Uint) return Node_Id;
7317 -- Return an analyzed N_Range node referencing this range, suitable for
7318 -- use as an entry in the Static_Discrete_Predicate list. This node is
7319 -- typed with the base type.
7321 function Get_RList (Exp : Node_Id) return RList;
7322 -- This is a recursive routine that converts the given expression into a
7323 -- list of ranges, suitable for use in building the static predicate.
7325 function Is_False (R : RList) return Boolean;
7326 pragma Inline (Is_False);
7327 -- Returns True if the given range list is empty, and thus represents a
7328 -- False list of ranges that can never be satisfied.
7330 function Is_True (R : RList) return Boolean;
7331 -- Returns True if R trivially represents the True predicate by having a
7332 -- single range from BLo to BHi.
7334 function Is_Type_Ref (N : Node_Id) return Boolean;
7335 pragma Inline (Is_Type_Ref);
7336 -- Returns if True if N is a reference to the type for the predicate in
7337 -- the expression (i.e. if it is an identifier whose Chars field matches
7338 -- the Nam given in the call). N must not be parenthesized, if the type
7339 -- name appears in parens, this routine will return False.
7341 function Lo_Val (N : Node_Id) return Uint;
7342 -- Given an entry from a Static_Discrete_Predicate list that is either
7343 -- a static expression or static range, gets either the expression value
7344 -- or the low bound of the range.
7346 function Hi_Val (N : Node_Id) return Uint;
7347 -- Given an entry from a Static_Discrete_Predicate list that is either
7348 -- a static expression or static range, gets either the expression value
7349 -- or the high bound of the range.
7351 function Membership_Entry (N : Node_Id) return RList;
7352 -- Given a single membership entry (range, value, or subtype), returns
7353 -- the corresponding range list. Raises Static_Error if not static.
7355 function Membership_Entries (N : Node_Id) return RList;
7356 -- Given an element on an alternatives list of a membership operation,
7357 -- returns the range list corresponding to this entry and all following
7358 -- entries (i.e. returns the "or" of this list of values).
7360 function Stat_Pred (Typ : Entity_Id) return RList;
7361 -- Given a type, if it has a static predicate, then return the predicate
7362 -- as a range list, otherwise raise Non_Static.
7364 -----------
7365 -- "and" --
7366 -----------
7368 function "and" (Left : RList; Right : RList) return RList is
7369 FEnt : REnt;
7370 -- First range of result
7372 SLeft : Nat := Left'First;
7373 -- Start of rest of left entries
7375 SRight : Nat := Right'First;
7376 -- Start of rest of right entries
7378 begin
7379 -- If either range is True, return the other
7381 if Is_True (Left) then
7382 return Right;
7383 elsif Is_True (Right) then
7384 return Left;
7385 end if;
7387 -- If either range is False, return False
7389 if Is_False (Left) or else Is_False (Right) then
7390 return False_Range;
7391 end if;
7393 -- Loop to remove entries at start that are disjoint, and thus just
7394 -- get discarded from the result entirely.
7396 loop
7397 -- If no operands left in either operand, result is false
7399 if SLeft > Left'Last or else SRight > Right'Last then
7400 return False_Range;
7402 -- Discard first left operand entry if disjoint with right
7404 elsif Left (SLeft).Hi < Right (SRight).Lo then
7405 SLeft := SLeft + 1;
7407 -- Discard first right operand entry if disjoint with left
7409 elsif Right (SRight).Hi < Left (SLeft).Lo then
7410 SRight := SRight + 1;
7412 -- Otherwise we have an overlapping entry
7414 else
7415 exit;
7416 end if;
7417 end loop;
7419 -- Now we have two non-null operands, and first entries overlap. The
7420 -- first entry in the result will be the overlapping part of these
7421 -- two entries.
7423 FEnt := REnt'(Lo => UI_Max (Left (SLeft).Lo, Right (SRight).Lo),
7424 Hi => UI_Min (Left (SLeft).Hi, Right (SRight).Hi));
7426 -- Now we can remove the entry that ended at a lower value, since its
7427 -- contribution is entirely contained in Fent.
7429 if Left (SLeft).Hi <= Right (SRight).Hi then
7430 SLeft := SLeft + 1;
7431 else
7432 SRight := SRight + 1;
7433 end if;
7435 -- Compute result by concatenating this first entry with the "and" of
7436 -- the remaining parts of the left and right operands. Note that if
7437 -- either of these is empty, "and" will yield empty, so that we will
7438 -- end up with just Fent, which is what we want in that case.
7440 return
7441 FEnt & (Left (SLeft .. Left'Last) and Right (SRight .. Right'Last));
7442 end "and";
7444 -----------
7445 -- "not" --
7446 -----------
7448 function "not" (Right : RList) return RList is
7449 begin
7450 -- Return True if False range
7452 if Is_False (Right) then
7453 return True_Range;
7454 end if;
7456 -- Return False if True range
7458 if Is_True (Right) then
7459 return False_Range;
7460 end if;
7462 -- Here if not trivial case
7464 declare
7465 Result : RList (1 .. Right'Length + 1);
7466 -- May need one more entry for gap at beginning and end
7468 Count : Nat := 0;
7469 -- Number of entries stored in Result
7471 begin
7472 -- Gap at start
7474 if Right (Right'First).Lo > TLo then
7475 Count := Count + 1;
7476 Result (Count) := REnt'(TLo, Right (Right'First).Lo - 1);
7477 end if;
7479 -- Gaps between ranges
7481 for J in Right'First .. Right'Last - 1 loop
7482 Count := Count + 1;
7483 Result (Count) := REnt'(Right (J).Hi + 1, Right (J + 1).Lo - 1);
7484 end loop;
7486 -- Gap at end
7488 if Right (Right'Last).Hi < THi then
7489 Count := Count + 1;
7490 Result (Count) := REnt'(Right (Right'Last).Hi + 1, THi);
7491 end if;
7493 return Result (1 .. Count);
7494 end;
7495 end "not";
7497 ----------
7498 -- "or" --
7499 ----------
7501 function "or" (Left : RList; Right : RList) return RList is
7502 FEnt : REnt;
7503 -- First range of result
7505 SLeft : Nat := Left'First;
7506 -- Start of rest of left entries
7508 SRight : Nat := Right'First;
7509 -- Start of rest of right entries
7511 begin
7512 -- If either range is True, return True
7514 if Is_True (Left) or else Is_True (Right) then
7515 return True_Range;
7516 end if;
7518 -- If either range is False (empty), return the other
7520 if Is_False (Left) then
7521 return Right;
7522 elsif Is_False (Right) then
7523 return Left;
7524 end if;
7526 -- Initialize result first entry from left or right operand depending
7527 -- on which starts with the lower range.
7529 if Left (SLeft).Lo < Right (SRight).Lo then
7530 FEnt := Left (SLeft);
7531 SLeft := SLeft + 1;
7532 else
7533 FEnt := Right (SRight);
7534 SRight := SRight + 1;
7535 end if;
7537 -- This loop eats ranges from left and right operands that are
7538 -- contiguous with the first range we are gathering.
7540 loop
7541 -- Eat first entry in left operand if contiguous or overlapped by
7542 -- gathered first operand of result.
7544 if SLeft <= Left'Last
7545 and then Left (SLeft).Lo <= FEnt.Hi + 1
7546 then
7547 FEnt.Hi := UI_Max (FEnt.Hi, Left (SLeft).Hi);
7548 SLeft := SLeft + 1;
7550 -- Eat first entry in right operand if contiguous or overlapped by
7551 -- gathered right operand of result.
7553 elsif SRight <= Right'Last
7554 and then Right (SRight).Lo <= FEnt.Hi + 1
7555 then
7556 FEnt.Hi := UI_Max (FEnt.Hi, Right (SRight).Hi);
7557 SRight := SRight + 1;
7559 -- All done if no more entries to eat
7561 else
7562 exit;
7563 end if;
7564 end loop;
7566 -- Obtain result as the first entry we just computed, concatenated
7567 -- to the "or" of the remaining results (if one operand is empty,
7568 -- this will just concatenate with the other
7570 return
7571 FEnt & (Left (SLeft .. Left'Last) or Right (SRight .. Right'Last));
7572 end "or";
7574 -----------------
7575 -- Build_Range --
7576 -----------------
7578 function Build_Range (Lo : Uint; Hi : Uint) return Node_Id is
7579 Result : Node_Id;
7580 begin
7581 Result :=
7582 Make_Range (Loc,
7583 Low_Bound => Build_Val (Lo),
7584 High_Bound => Build_Val (Hi));
7585 Set_Etype (Result, Btyp);
7586 Set_Analyzed (Result);
7587 return Result;
7588 end Build_Range;
7590 ---------------
7591 -- Build_Val --
7592 ---------------
7594 function Build_Val (V : Uint) return Node_Id is
7595 Result : Node_Id;
7597 begin
7598 if Is_Enumeration_Type (Typ) then
7599 Result := Get_Enum_Lit_From_Pos (Typ, V, Loc);
7600 else
7601 Result := Make_Integer_Literal (Loc, V);
7602 end if;
7604 Set_Etype (Result, Btyp);
7605 Set_Is_Static_Expression (Result);
7606 Set_Analyzed (Result);
7607 return Result;
7608 end Build_Val;
7610 ---------------
7611 -- Get_RList --
7612 ---------------
7614 function Get_RList (Exp : Node_Id) return RList is
7615 Op : Node_Kind;
7616 Val : Uint;
7618 begin
7619 -- Static expression can only be true or false
7621 if Is_OK_Static_Expression (Exp) then
7622 if Expr_Value (Exp) = 0 then
7623 return False_Range;
7624 else
7625 return True_Range;
7626 end if;
7627 end if;
7629 -- Otherwise test node type
7631 Op := Nkind (Exp);
7633 case Op is
7635 -- And
7637 when N_And_Then
7638 | N_Op_And
7640 return Get_RList (Left_Opnd (Exp))
7642 Get_RList (Right_Opnd (Exp));
7644 -- Or
7646 when N_Op_Or
7647 | N_Or_Else
7649 return Get_RList (Left_Opnd (Exp))
7651 Get_RList (Right_Opnd (Exp));
7653 -- Not
7655 when N_Op_Not =>
7656 return not Get_RList (Right_Opnd (Exp));
7658 -- Comparisons of type with static value
7660 when N_Op_Compare =>
7662 -- Type is left operand
7664 if Is_Type_Ref (Left_Opnd (Exp))
7665 and then Is_OK_Static_Expression (Right_Opnd (Exp))
7666 then
7667 Val := Expr_Value (Right_Opnd (Exp));
7669 -- Typ is right operand
7671 elsif Is_Type_Ref (Right_Opnd (Exp))
7672 and then Is_OK_Static_Expression (Left_Opnd (Exp))
7673 then
7674 Val := Expr_Value (Left_Opnd (Exp));
7676 -- Invert sense of comparison
7678 case Op is
7679 when N_Op_Gt => Op := N_Op_Lt;
7680 when N_Op_Lt => Op := N_Op_Gt;
7681 when N_Op_Ge => Op := N_Op_Le;
7682 when N_Op_Le => Op := N_Op_Ge;
7683 when others => null;
7684 end case;
7686 -- Other cases are non-static
7688 else
7689 raise Non_Static;
7690 end if;
7692 -- Construct range according to comparison operation
7694 case Op is
7695 when N_Op_Eq =>
7696 return RList'(1 => REnt'(Val, Val));
7698 when N_Op_Ge =>
7699 return RList'(1 => REnt'(Val, BHi));
7701 when N_Op_Gt =>
7702 return RList'(1 => REnt'(Val + 1, BHi));
7704 when N_Op_Le =>
7705 return RList'(1 => REnt'(BLo, Val));
7707 when N_Op_Lt =>
7708 return RList'(1 => REnt'(BLo, Val - 1));
7710 when N_Op_Ne =>
7711 return RList'(REnt'(BLo, Val - 1), REnt'(Val + 1, BHi));
7713 when others =>
7714 raise Program_Error;
7715 end case;
7717 -- Membership (IN)
7719 when N_In =>
7720 if not Is_Type_Ref (Left_Opnd (Exp)) then
7721 raise Non_Static;
7722 end if;
7724 if Present (Right_Opnd (Exp)) then
7725 return Membership_Entry (Right_Opnd (Exp));
7726 else
7727 return Membership_Entries (First (Alternatives (Exp)));
7728 end if;
7730 -- Negative membership (NOT IN)
7732 when N_Not_In =>
7733 if not Is_Type_Ref (Left_Opnd (Exp)) then
7734 raise Non_Static;
7735 end if;
7737 if Present (Right_Opnd (Exp)) then
7738 return not Membership_Entry (Right_Opnd (Exp));
7739 else
7740 return not Membership_Entries (First (Alternatives (Exp)));
7741 end if;
7743 -- Function call, may be call to static predicate
7745 when N_Function_Call =>
7746 if Is_Entity_Name (Name (Exp)) then
7747 declare
7748 Ent : constant Entity_Id := Entity (Name (Exp));
7749 begin
7750 if Is_Predicate_Function (Ent)
7751 or else
7752 Is_Predicate_Function_M (Ent)
7753 then
7754 return Stat_Pred (Etype (First_Formal (Ent)));
7755 end if;
7756 end;
7757 end if;
7759 -- Other function call cases are non-static
7761 raise Non_Static;
7763 -- Qualified expression, dig out the expression
7765 when N_Qualified_Expression =>
7766 return Get_RList (Expression (Exp));
7768 when N_Case_Expression =>
7769 declare
7770 Alt : Node_Id;
7771 Choices : List_Id;
7772 Dep : Node_Id;
7774 begin
7775 if not Is_Entity_Name (Expression (Expr))
7776 or else Etype (Expression (Expr)) /= Typ
7777 then
7778 Error_Msg_N
7779 ("expression must denaote subtype", Expression (Expr));
7780 return False_Range;
7781 end if;
7783 -- Collect discrete choices in all True alternatives
7785 Choices := New_List;
7786 Alt := First (Alternatives (Exp));
7787 while Present (Alt) loop
7788 Dep := Expression (Alt);
7790 if not Is_OK_Static_Expression (Dep) then
7791 raise Non_Static;
7793 elsif Is_True (Expr_Value (Dep)) then
7794 Append_List_To (Choices,
7795 New_Copy_List (Discrete_Choices (Alt)));
7796 end if;
7798 Next (Alt);
7799 end loop;
7801 return Membership_Entries (First (Choices));
7802 end;
7804 -- Expression with actions: if no actions, dig out expression
7806 when N_Expression_With_Actions =>
7807 if Is_Empty_List (Actions (Exp)) then
7808 return Get_RList (Expression (Exp));
7809 else
7810 raise Non_Static;
7811 end if;
7813 -- Xor operator
7815 when N_Op_Xor =>
7816 return (Get_RList (Left_Opnd (Exp))
7817 and not Get_RList (Right_Opnd (Exp)))
7818 or (Get_RList (Right_Opnd (Exp))
7819 and not Get_RList (Left_Opnd (Exp)));
7821 -- Any other node type is non-static
7823 when others =>
7824 raise Non_Static;
7825 end case;
7826 end Get_RList;
7828 ------------
7829 -- Hi_Val --
7830 ------------
7832 function Hi_Val (N : Node_Id) return Uint is
7833 begin
7834 if Is_OK_Static_Expression (N) then
7835 return Expr_Value (N);
7836 else
7837 pragma Assert (Nkind (N) = N_Range);
7838 return Expr_Value (High_Bound (N));
7839 end if;
7840 end Hi_Val;
7842 --------------
7843 -- Is_False --
7844 --------------
7846 function Is_False (R : RList) return Boolean is
7847 begin
7848 return R'Length = 0;
7849 end Is_False;
7851 -------------
7852 -- Is_True --
7853 -------------
7855 function Is_True (R : RList) return Boolean is
7856 begin
7857 return R'Length = 1
7858 and then R (R'First).Lo = BLo
7859 and then R (R'First).Hi = BHi;
7860 end Is_True;
7862 -----------------
7863 -- Is_Type_Ref --
7864 -----------------
7866 function Is_Type_Ref (N : Node_Id) return Boolean is
7867 begin
7868 return Nkind (N) = N_Identifier
7869 and then Chars (N) = Nam
7870 and then Paren_Count (N) = 0;
7871 end Is_Type_Ref;
7873 ------------
7874 -- Lo_Val --
7875 ------------
7877 function Lo_Val (N : Node_Id) return Uint is
7878 begin
7879 if Is_OK_Static_Expression (N) then
7880 return Expr_Value (N);
7881 else
7882 pragma Assert (Nkind (N) = N_Range);
7883 return Expr_Value (Low_Bound (N));
7884 end if;
7885 end Lo_Val;
7887 ------------------------
7888 -- Membership_Entries --
7889 ------------------------
7891 function Membership_Entries (N : Node_Id) return RList is
7892 begin
7893 if No (Next (N)) then
7894 return Membership_Entry (N);
7895 else
7896 return Membership_Entry (N) or Membership_Entries (Next (N));
7897 end if;
7898 end Membership_Entries;
7900 ----------------------
7901 -- Membership_Entry --
7902 ----------------------
7904 function Membership_Entry (N : Node_Id) return RList is
7905 Val : Uint;
7906 SLo : Uint;
7907 SHi : Uint;
7909 begin
7910 -- Range case
7912 if Nkind (N) = N_Range then
7913 if not Is_OK_Static_Expression (Low_Bound (N))
7914 or else
7915 not Is_OK_Static_Expression (High_Bound (N))
7916 then
7917 raise Non_Static;
7918 else
7919 SLo := Expr_Value (Low_Bound (N));
7920 SHi := Expr_Value (High_Bound (N));
7921 return RList'(1 => REnt'(SLo, SHi));
7922 end if;
7924 -- Static expression case
7926 elsif Is_OK_Static_Expression (N) then
7927 Val := Expr_Value (N);
7928 return RList'(1 => REnt'(Val, Val));
7930 -- Identifier (other than static expression) case
7932 else pragma Assert (Nkind (N) = N_Identifier);
7934 -- Type case
7936 if Is_Type (Entity (N)) then
7938 -- If type has predicates, process them
7940 if Has_Predicates (Entity (N)) then
7941 return Stat_Pred (Entity (N));
7943 -- For static subtype without predicates, get range
7945 elsif Is_OK_Static_Subtype (Entity (N)) then
7946 SLo := Expr_Value (Type_Low_Bound (Entity (N)));
7947 SHi := Expr_Value (Type_High_Bound (Entity (N)));
7948 return RList'(1 => REnt'(SLo, SHi));
7950 -- Any other type makes us non-static
7952 else
7953 raise Non_Static;
7954 end if;
7956 -- Any other kind of identifier in predicate (e.g. a non-static
7957 -- expression value) means this is not a static predicate.
7959 else
7960 raise Non_Static;
7961 end if;
7962 end if;
7963 end Membership_Entry;
7965 ---------------
7966 -- Stat_Pred --
7967 ---------------
7969 function Stat_Pred (Typ : Entity_Id) return RList is
7970 begin
7971 -- Not static if type does not have static predicates
7973 if not Has_Static_Predicate (Typ) then
7974 raise Non_Static;
7975 end if;
7977 -- Otherwise we convert the predicate list to a range list
7979 declare
7980 Spred : constant List_Id := Static_Discrete_Predicate (Typ);
7981 Result : RList (1 .. List_Length (Spred));
7982 P : Node_Id;
7984 begin
7985 P := First (Static_Discrete_Predicate (Typ));
7986 for J in Result'Range loop
7987 Result (J) := REnt'(Lo_Val (P), Hi_Val (P));
7988 Next (P);
7989 end loop;
7991 return Result;
7992 end;
7993 end Stat_Pred;
7995 -- Start of processing for Build_Discrete_Static_Predicate
7997 begin
7998 -- Establish bounds for the predicate
8000 if Compile_Time_Known_Value (Type_Low_Bound (Typ)) then
8001 TLo := Expr_Value (Type_Low_Bound (Typ));
8002 else
8003 TLo := BLo;
8004 end if;
8006 if Compile_Time_Known_Value (Type_High_Bound (Typ)) then
8007 THi := Expr_Value (Type_High_Bound (Typ));
8008 else
8009 THi := BHi;
8010 end if;
8012 -- Analyze the expression to see if it is a static predicate
8014 declare
8015 Ranges : constant RList := Get_RList (Expr);
8016 -- Range list from expression if it is static
8018 Plist : List_Id;
8020 begin
8021 -- Convert range list into a form for the static predicate. In the
8022 -- Ranges array, we just have raw ranges, these must be converted
8023 -- to properly typed and analyzed static expressions or range nodes.
8025 -- Note: here we limit ranges to the ranges of the subtype, so that
8026 -- a predicate is always false for values outside the subtype. That
8027 -- seems fine, such values are invalid anyway, and considering them
8028 -- to fail the predicate seems allowed and friendly, and furthermore
8029 -- simplifies processing for case statements and loops.
8031 Plist := New_List;
8033 for J in Ranges'Range loop
8034 declare
8035 Lo : Uint := Ranges (J).Lo;
8036 Hi : Uint := Ranges (J).Hi;
8038 begin
8039 -- Ignore completely out of range entry
8041 if Hi < TLo or else Lo > THi then
8042 null;
8044 -- Otherwise process entry
8046 else
8047 -- Adjust out of range value to subtype range
8049 if Lo < TLo then
8050 Lo := TLo;
8051 end if;
8053 if Hi > THi then
8054 Hi := THi;
8055 end if;
8057 -- Convert range into required form
8059 Append_To (Plist, Build_Range (Lo, Hi));
8060 end if;
8061 end;
8062 end loop;
8064 -- Processing was successful and all entries were static, so now we
8065 -- can store the result as the predicate list.
8067 Set_Static_Discrete_Predicate (Typ, Plist);
8069 -- The processing for static predicates put the expression into
8070 -- canonical form as a series of ranges. It also eliminated
8071 -- duplicates and collapsed and combined ranges. We might as well
8072 -- replace the alternatives list of the right operand of the
8073 -- membership test with the static predicate list, which will
8074 -- usually be more efficient.
8076 declare
8077 New_Alts : constant List_Id := New_List;
8078 Old_Node : Node_Id;
8079 New_Node : Node_Id;
8081 begin
8082 Old_Node := First (Plist);
8083 while Present (Old_Node) loop
8084 New_Node := New_Copy (Old_Node);
8086 if Nkind (New_Node) = N_Range then
8087 Set_Low_Bound (New_Node, New_Copy (Low_Bound (Old_Node)));
8088 Set_High_Bound (New_Node, New_Copy (High_Bound (Old_Node)));
8089 end if;
8091 Append_To (New_Alts, New_Node);
8092 Next (Old_Node);
8093 end loop;
8095 -- If empty list, replace by False
8097 if Is_Empty_List (New_Alts) then
8098 Rewrite (Expr, New_Occurrence_Of (Standard_False, Loc));
8100 -- Else replace by set membership test
8102 else
8103 Rewrite (Expr,
8104 Make_In (Loc,
8105 Left_Opnd => Make_Identifier (Loc, Nam),
8106 Right_Opnd => Empty,
8107 Alternatives => New_Alts));
8109 -- Resolve new expression in function context
8111 Install_Formals (Predicate_Function (Typ));
8112 Push_Scope (Predicate_Function (Typ));
8113 Analyze_And_Resolve (Expr, Standard_Boolean);
8114 Pop_Scope;
8115 end if;
8116 end;
8117 end;
8119 -- If non-static, return doing nothing
8121 exception
8122 when Non_Static =>
8123 return;
8124 end Build_Discrete_Static_Predicate;
8126 --------------------------------
8127 -- Build_Export_Import_Pragma --
8128 --------------------------------
8130 function Build_Export_Import_Pragma
8131 (Asp : Node_Id;
8132 Id : Entity_Id) return Node_Id
8134 Asp_Id : constant Aspect_Id := Get_Aspect_Id (Asp);
8135 Expr : constant Node_Id := Expression (Asp);
8136 Loc : constant Source_Ptr := Sloc (Asp);
8138 Args : List_Id;
8139 Conv : Node_Id;
8140 Conv_Arg : Node_Id;
8141 Dummy_1 : Node_Id;
8142 Dummy_2 : Node_Id;
8143 EN : Node_Id;
8144 LN : Node_Id;
8145 Prag : Node_Id;
8147 Create_Pragma : Boolean := False;
8148 -- This flag is set when the aspect form is such that it warrants the
8149 -- creation of a corresponding pragma.
8151 begin
8152 if Present (Expr) then
8153 if Error_Posted (Expr) then
8154 null;
8156 elsif Is_True (Expr_Value (Expr)) then
8157 Create_Pragma := True;
8158 end if;
8160 -- Otherwise the aspect defaults to True
8162 else
8163 Create_Pragma := True;
8164 end if;
8166 -- Nothing to do when the expression is False or is erroneous
8168 if not Create_Pragma then
8169 return Empty;
8170 end if;
8172 -- Obtain all interfacing aspects that apply to the related entity
8174 Get_Interfacing_Aspects
8175 (Iface_Asp => Asp,
8176 Conv_Asp => Conv,
8177 EN_Asp => EN,
8178 Expo_Asp => Dummy_1,
8179 Imp_Asp => Dummy_2,
8180 LN_Asp => LN);
8182 Args := New_List;
8184 -- Handle the convention argument
8186 if Present (Conv) then
8187 Conv_Arg := New_Copy_Tree (Expression (Conv));
8189 -- Assume convention "Ada' when aspect Convention is missing
8191 else
8192 Conv_Arg := Make_Identifier (Loc, Name_Ada);
8193 end if;
8195 Append_To (Args,
8196 Make_Pragma_Argument_Association (Loc,
8197 Chars => Name_Convention,
8198 Expression => Conv_Arg));
8200 -- Handle the entity argument
8202 Append_To (Args,
8203 Make_Pragma_Argument_Association (Loc,
8204 Chars => Name_Entity,
8205 Expression => New_Occurrence_Of (Id, Loc)));
8207 -- Handle the External_Name argument
8209 if Present (EN) then
8210 Append_To (Args,
8211 Make_Pragma_Argument_Association (Loc,
8212 Chars => Name_External_Name,
8213 Expression => New_Copy_Tree (Expression (EN))));
8214 end if;
8216 -- Handle the Link_Name argument
8218 if Present (LN) then
8219 Append_To (Args,
8220 Make_Pragma_Argument_Association (Loc,
8221 Chars => Name_Link_Name,
8222 Expression => New_Copy_Tree (Expression (LN))));
8223 end if;
8225 -- Generate:
8226 -- pragma Export/Import
8227 -- (Convention => <Conv>/Ada,
8228 -- Entity => <Id>,
8229 -- [External_Name => <EN>,]
8230 -- [Link_Name => <LN>]);
8232 Prag :=
8233 Make_Pragma (Loc,
8234 Pragma_Identifier =>
8235 Make_Identifier (Loc, Chars (Identifier (Asp))),
8236 Pragma_Argument_Associations => Args);
8238 -- Decorate the relevant aspect and the pragma
8240 Set_Aspect_Rep_Item (Asp, Prag);
8242 Set_Corresponding_Aspect (Prag, Asp);
8243 Set_From_Aspect_Specification (Prag);
8244 Set_Parent (Prag, Asp);
8246 if Asp_Id = Aspect_Import and then Is_Subprogram (Id) then
8247 Set_Import_Pragma (Id, Prag);
8248 end if;
8250 return Prag;
8251 end Build_Export_Import_Pragma;
8253 -------------------------------
8254 -- Build_Predicate_Functions --
8255 -------------------------------
8257 -- The procedures that are constructed here have the form:
8259 -- function typPredicate (Ixxx : typ) return Boolean is
8260 -- begin
8261 -- return
8262 -- typ1Predicate (typ1 (Ixxx))
8263 -- and then typ2Predicate (typ2 (Ixxx))
8264 -- and then ...;
8265 -- exp1 and then exp2 and then ...
8266 -- end typPredicate;
8268 -- Here exp1, and exp2 are expressions from Predicate pragmas. Note that
8269 -- this is the point at which these expressions get analyzed, providing the
8270 -- required delay, and typ1, typ2, are entities from which predicates are
8271 -- inherited. Note that we do NOT generate Check pragmas, that's because we
8272 -- use this function even if checks are off, e.g. for membership tests.
8274 -- Note that the inherited predicates are evaluated first, as required by
8275 -- AI12-0071-1.
8277 -- Note that Sem_Eval.Real_Or_String_Static_Predicate_Matches depends on
8278 -- the form of this return expression.
8280 -- If the expression has at least one Raise_Expression, then we also build
8281 -- the typPredicateM version of the function, in which any occurrence of a
8282 -- Raise_Expression is converted to "return False".
8284 -- WARNING: This routine manages Ghost regions. Return statements must be
8285 -- replaced by gotos which jump to the end of the routine and restore the
8286 -- Ghost mode.
8288 procedure Build_Predicate_Functions (Typ : Entity_Id; N : Node_Id) is
8289 Loc : constant Source_Ptr := Sloc (Typ);
8291 Expr : Node_Id;
8292 -- This is the expression for the result of the function. It is
8293 -- is build by connecting the component predicates with AND THEN.
8295 Expr_M : Node_Id;
8296 -- This is the corresponding return expression for the Predicate_M
8297 -- function. It differs in that raise expressions are marked for
8298 -- special expansion (see Process_REs).
8300 Object_Name : Name_Id;
8301 -- Name for argument of Predicate procedure. Note that we use the same
8302 -- name for both predicate functions. That way the reference within the
8303 -- predicate expression is the same in both functions.
8305 Object_Entity : Entity_Id;
8306 -- Entity for argument of Predicate procedure
8308 Object_Entity_M : Entity_Id;
8309 -- Entity for argument of separate Predicate procedure when exceptions
8310 -- are present in expression.
8312 FDecl : Node_Id;
8313 -- The function declaration
8315 SId : Entity_Id;
8316 -- Its entity
8318 Raise_Expression_Present : Boolean := False;
8319 -- Set True if Expr has at least one Raise_Expression
8321 procedure Add_Condition (Cond : Node_Id);
8322 -- Append Cond to Expr using "and then" (or just copy Cond to Expr if
8323 -- Expr is empty).
8325 procedure Add_Predicates;
8326 -- Appends expressions for any Predicate pragmas in the rep item chain
8327 -- Typ to Expr. Note that we look only at items for this exact entity.
8328 -- Inheritance of predicates for the parent type is done by calling the
8329 -- Predicate_Function of the parent type, using Add_Call above.
8331 procedure Add_Call (T : Entity_Id);
8332 -- Includes a call to the predicate function for type T in Expr if T
8333 -- has predicates and Predicate_Function (T) is non-empty.
8335 function Process_RE (N : Node_Id) return Traverse_Result;
8336 -- Used in Process REs, tests if node N is a raise expression, and if
8337 -- so, marks it to be converted to return False.
8339 procedure Process_REs is new Traverse_Proc (Process_RE);
8340 -- Marks any raise expressions in Expr_M to return False
8342 function Test_RE (N : Node_Id) return Traverse_Result;
8343 -- Used in Test_REs, tests one node for being a raise expression, and if
8344 -- so sets Raise_Expression_Present True.
8346 procedure Test_REs is new Traverse_Proc (Test_RE);
8347 -- Tests to see if Expr contains any raise expressions
8349 --------------
8350 -- Add_Call --
8351 --------------
8353 procedure Add_Call (T : Entity_Id) is
8354 Exp : Node_Id;
8356 begin
8357 if Present (T) and then Present (Predicate_Function (T)) then
8358 Set_Has_Predicates (Typ);
8360 -- Build the call to the predicate function of T
8362 Exp :=
8363 Make_Predicate_Call
8364 (T, Convert_To (T, Make_Identifier (Loc, Object_Name)));
8366 -- "and"-in the call to evolving expression
8368 Add_Condition (Exp);
8370 -- Output info message on inheritance if required. Note we do not
8371 -- give this information for generic actual types, since it is
8372 -- unwelcome noise in that case in instantiations. We also
8373 -- generally suppress the message in instantiations, and also
8374 -- if it involves internal names.
8376 if Opt.List_Inherited_Aspects
8377 and then not Is_Generic_Actual_Type (Typ)
8378 and then Instantiation_Depth (Sloc (Typ)) = 0
8379 and then not Is_Internal_Name (Chars (T))
8380 and then not Is_Internal_Name (Chars (Typ))
8381 then
8382 Error_Msg_Sloc := Sloc (Predicate_Function (T));
8383 Error_Msg_Node_2 := T;
8384 Error_Msg_N ("info: & inherits predicate from & #?L?", Typ);
8385 end if;
8386 end if;
8387 end Add_Call;
8389 -------------------
8390 -- Add_Condition --
8391 -------------------
8393 procedure Add_Condition (Cond : Node_Id) is
8394 begin
8395 -- This is the first predicate expression
8397 if No (Expr) then
8398 Expr := Cond;
8400 -- Otherwise concatenate to the existing predicate expressions by
8401 -- using "and then".
8403 else
8404 Expr :=
8405 Make_And_Then (Loc,
8406 Left_Opnd => Relocate_Node (Expr),
8407 Right_Opnd => Cond);
8408 end if;
8409 end Add_Condition;
8411 --------------------
8412 -- Add_Predicates --
8413 --------------------
8415 procedure Add_Predicates is
8416 procedure Add_Predicate (Prag : Node_Id);
8417 -- Concatenate the expression of predicate pragma Prag to Expr by
8418 -- using a short circuit "and then" operator.
8420 -------------------
8421 -- Add_Predicate --
8422 -------------------
8424 procedure Add_Predicate (Prag : Node_Id) is
8425 procedure Replace_Type_Reference (N : Node_Id);
8426 -- Replace a single occurrence N of the subtype name with a
8427 -- reference to the formal of the predicate function. N can be an
8428 -- identifier referencing the subtype, or a selected component,
8429 -- representing an appropriately qualified occurrence of the
8430 -- subtype name.
8432 procedure Replace_Type_References is
8433 new Replace_Type_References_Generic (Replace_Type_Reference);
8434 -- Traverse an expression changing every occurrence of an
8435 -- identifier whose name matches the name of the subtype with a
8436 -- reference to the formal parameter of the predicate function.
8438 ----------------------------
8439 -- Replace_Type_Reference --
8440 ----------------------------
8442 procedure Replace_Type_Reference (N : Node_Id) is
8443 begin
8444 Rewrite (N, Make_Identifier (Sloc (N), Object_Name));
8445 -- Use the Sloc of the usage name, not the defining name
8447 Set_Etype (N, Typ);
8448 Set_Entity (N, Object_Entity);
8450 -- We want to treat the node as if it comes from source, so
8451 -- that ASIS will not ignore it.
8453 Set_Comes_From_Source (N, True);
8454 end Replace_Type_Reference;
8456 -- Local variables
8458 Asp : constant Node_Id := Corresponding_Aspect (Prag);
8459 Arg1 : Node_Id;
8460 Arg2 : Node_Id;
8462 -- Start of processing for Add_Predicate
8464 begin
8465 -- Extract the arguments of the pragma. The expression itself
8466 -- is copied for use in the predicate function, to preserve the
8467 -- original version for ASIS use.
8469 Arg1 := First (Pragma_Argument_Associations (Prag));
8470 Arg2 := Next (Arg1);
8472 Arg1 := Get_Pragma_Arg (Arg1);
8473 Arg2 := New_Copy_Tree (Get_Pragma_Arg (Arg2));
8475 -- When the predicate pragma applies to the current type or its
8476 -- full view, replace all occurrences of the subtype name with
8477 -- references to the formal parameter of the predicate function.
8479 if Entity (Arg1) = Typ
8480 or else Full_View (Entity (Arg1)) = Typ
8481 then
8482 Replace_Type_References (Arg2, Typ);
8484 -- If the predicate pragma comes from an aspect, replace the
8485 -- saved expression because we need the subtype references
8486 -- replaced for the calls to Preanalyze_Spec_Expression in
8487 -- Check_Aspect_At_xxx routines.
8489 if Present (Asp) then
8490 Set_Entity (Identifier (Asp), New_Copy_Tree (Arg2));
8491 end if;
8493 -- "and"-in the Arg2 condition to evolving expression
8495 Add_Condition (Relocate_Node (Arg2));
8496 end if;
8497 end Add_Predicate;
8499 -- Local variables
8501 Ritem : Node_Id;
8503 -- Start of processing for Add_Predicates
8505 begin
8506 Ritem := First_Rep_Item (Typ);
8507 while Present (Ritem) loop
8508 if Nkind (Ritem) = N_Pragma
8509 and then Pragma_Name (Ritem) = Name_Predicate
8510 then
8511 Add_Predicate (Ritem);
8513 -- If the type is declared in an inner package it may be frozen
8514 -- outside of the package, and the generated pragma has not been
8515 -- analyzed yet, so capture the expression for the predicate
8516 -- function at this point.
8518 elsif Nkind (Ritem) = N_Aspect_Specification
8519 and then Present (Aspect_Rep_Item (Ritem))
8520 and then Scope (Typ) /= Current_Scope
8521 then
8522 declare
8523 Prag : constant Node_Id := Aspect_Rep_Item (Ritem);
8525 begin
8526 if Nkind (Prag) = N_Pragma
8527 and then Pragma_Name (Prag) = Name_Predicate
8528 then
8529 Add_Predicate (Prag);
8530 end if;
8531 end;
8532 end if;
8534 Next_Rep_Item (Ritem);
8535 end loop;
8536 end Add_Predicates;
8538 ----------------
8539 -- Process_RE --
8540 ----------------
8542 function Process_RE (N : Node_Id) return Traverse_Result is
8543 begin
8544 if Nkind (N) = N_Raise_Expression then
8545 Set_Convert_To_Return_False (N);
8546 return Skip;
8547 else
8548 return OK;
8549 end if;
8550 end Process_RE;
8552 -------------
8553 -- Test_RE --
8554 -------------
8556 function Test_RE (N : Node_Id) return Traverse_Result is
8557 begin
8558 if Nkind (N) = N_Raise_Expression then
8559 Raise_Expression_Present := True;
8560 return Abandon;
8561 else
8562 return OK;
8563 end if;
8564 end Test_RE;
8566 -- Local variables
8568 Mode : Ghost_Mode_Type;
8570 -- Start of processing for Build_Predicate_Functions
8572 begin
8573 -- Return if already built or if type does not have predicates
8575 SId := Predicate_Function (Typ);
8576 if not Has_Predicates (Typ)
8577 or else (Present (SId) and then Has_Completion (SId))
8578 then
8579 return;
8580 end if;
8582 -- The related type may be subject to pragma Ghost. Set the mode now to
8583 -- ensure that the predicate functions are properly marked as Ghost.
8585 Set_Ghost_Mode (Typ, Mode);
8587 -- Prepare to construct predicate expression
8589 Expr := Empty;
8591 if Present (SId) then
8592 FDecl := Unit_Declaration_Node (SId);
8594 else
8595 FDecl := Build_Predicate_Function_Declaration (Typ);
8596 SId := Defining_Entity (FDecl);
8597 end if;
8599 -- Recover name of formal parameter of function that replaces references
8600 -- to the type in predicate expressions.
8602 Object_Entity :=
8603 Defining_Identifier
8604 (First (Parameter_Specifications (Specification (FDecl))));
8606 Object_Name := Chars (Object_Entity);
8607 Object_Entity_M := Make_Defining_Identifier (Loc, Chars => Object_Name);
8609 -- Add predicates for ancestor if present. These must come before the
8610 -- ones for the current type, as required by AI12-0071-1.
8612 declare
8613 Atyp : constant Entity_Id := Nearest_Ancestor (Typ);
8614 begin
8615 if Present (Atyp) then
8616 Add_Call (Atyp);
8617 end if;
8618 end;
8620 -- Add Predicates for the current type
8622 Add_Predicates;
8624 -- Case where predicates are present
8626 if Present (Expr) then
8628 -- Test for raise expression present
8630 Test_REs (Expr);
8632 -- If raise expression is present, capture a copy of Expr for use
8633 -- in building the predicateM function version later on. For this
8634 -- copy we replace references to Object_Entity by Object_Entity_M.
8636 if Raise_Expression_Present then
8637 declare
8638 Map : constant Elist_Id := New_Elmt_List;
8639 New_V : Entity_Id := Empty;
8641 -- The unanalyzed expression will be copied and appear in
8642 -- both functions. Normally expressions do not declare new
8643 -- entities, but quantified expressions do, so we need to
8644 -- create new entities for their bound variables, to prevent
8645 -- multiple definitions in gigi.
8647 function Reset_Loop_Variable (N : Node_Id)
8648 return Traverse_Result;
8650 procedure Collect_Loop_Variables is
8651 new Traverse_Proc (Reset_Loop_Variable);
8653 ------------------------
8654 -- Reset_Loop_Variable --
8655 ------------------------
8657 function Reset_Loop_Variable (N : Node_Id)
8658 return Traverse_Result
8660 begin
8661 if Nkind (N) = N_Iterator_Specification then
8662 New_V := Make_Defining_Identifier
8663 (Sloc (N), Chars (Defining_Identifier (N)));
8665 Set_Defining_Identifier (N, New_V);
8666 end if;
8668 return OK;
8669 end Reset_Loop_Variable;
8671 begin
8672 Append_Elmt (Object_Entity, Map);
8673 Append_Elmt (Object_Entity_M, Map);
8674 Expr_M := New_Copy_Tree (Expr, Map => Map);
8675 Collect_Loop_Variables (Expr_M);
8676 end;
8677 end if;
8679 -- Build the main predicate function
8681 declare
8682 SIdB : constant Entity_Id :=
8683 Make_Defining_Identifier (Loc,
8684 Chars => New_External_Name (Chars (Typ), "Predicate"));
8685 -- The entity for the function body
8687 Spec : Node_Id;
8688 FBody : Node_Id;
8690 begin
8691 -- The predicate function is shared between views of a type
8693 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
8694 Set_Predicate_Function (Full_View (Typ), SId);
8695 end if;
8697 -- Build function body
8699 Spec :=
8700 Make_Function_Specification (Loc,
8701 Defining_Unit_Name => SIdB,
8702 Parameter_Specifications => New_List (
8703 Make_Parameter_Specification (Loc,
8704 Defining_Identifier =>
8705 Make_Defining_Identifier (Loc, Object_Name),
8706 Parameter_Type =>
8707 New_Occurrence_Of (Typ, Loc))),
8708 Result_Definition =>
8709 New_Occurrence_Of (Standard_Boolean, Loc));
8711 FBody :=
8712 Make_Subprogram_Body (Loc,
8713 Specification => Spec,
8714 Declarations => Empty_List,
8715 Handled_Statement_Sequence =>
8716 Make_Handled_Sequence_Of_Statements (Loc,
8717 Statements => New_List (
8718 Make_Simple_Return_Statement (Loc,
8719 Expression => Expr))));
8721 -- If declaration has not been analyzed yet, Insert declaration
8722 -- before freeze node. Insert body itself after freeze node.
8724 if not Analyzed (FDecl) then
8725 Insert_Before_And_Analyze (N, FDecl);
8726 end if;
8728 Insert_After_And_Analyze (N, FBody);
8730 -- Static predicate functions are always side-effect free, and
8731 -- in most cases dynamic predicate functions are as well. Mark
8732 -- them as such whenever possible, so redundant predicate checks
8733 -- can be optimized. If there is a variable reference within the
8734 -- expression, the function is not pure.
8736 if Expander_Active then
8737 Set_Is_Pure (SId,
8738 Side_Effect_Free (Expr, Variable_Ref => True));
8739 Set_Is_Inlined (SId);
8740 end if;
8741 end;
8743 -- Test for raise expressions present and if so build M version
8745 if Raise_Expression_Present then
8746 declare
8747 SId : constant Entity_Id :=
8748 Make_Defining_Identifier (Loc,
8749 Chars => New_External_Name (Chars (Typ), "PredicateM"));
8750 -- The entity for the function spec
8752 SIdB : constant Entity_Id :=
8753 Make_Defining_Identifier (Loc,
8754 Chars => New_External_Name (Chars (Typ), "PredicateM"));
8755 -- The entity for the function body
8757 Spec : Node_Id;
8758 FBody : Node_Id;
8759 FDecl : Node_Id;
8760 BTemp : Entity_Id;
8762 begin
8763 -- Mark any raise expressions for special expansion
8765 Process_REs (Expr_M);
8767 -- Build function declaration
8769 Set_Ekind (SId, E_Function);
8770 Set_Is_Predicate_Function_M (SId);
8771 Set_Predicate_Function_M (Typ, SId);
8773 -- The predicate function is shared between views of a type
8775 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
8776 Set_Predicate_Function_M (Full_View (Typ), SId);
8777 end if;
8779 Spec :=
8780 Make_Function_Specification (Loc,
8781 Defining_Unit_Name => SId,
8782 Parameter_Specifications => New_List (
8783 Make_Parameter_Specification (Loc,
8784 Defining_Identifier => Object_Entity_M,
8785 Parameter_Type => New_Occurrence_Of (Typ, Loc))),
8786 Result_Definition =>
8787 New_Occurrence_Of (Standard_Boolean, Loc));
8789 FDecl :=
8790 Make_Subprogram_Declaration (Loc,
8791 Specification => Spec);
8793 -- Build function body
8795 Spec :=
8796 Make_Function_Specification (Loc,
8797 Defining_Unit_Name => SIdB,
8798 Parameter_Specifications => New_List (
8799 Make_Parameter_Specification (Loc,
8800 Defining_Identifier =>
8801 Make_Defining_Identifier (Loc, Object_Name),
8802 Parameter_Type =>
8803 New_Occurrence_Of (Typ, Loc))),
8804 Result_Definition =>
8805 New_Occurrence_Of (Standard_Boolean, Loc));
8807 -- Build the body, we declare the boolean expression before
8808 -- doing the return, because we are not really confident of
8809 -- what happens if a return appears within a return.
8811 BTemp :=
8812 Make_Defining_Identifier (Loc,
8813 Chars => New_Internal_Name ('B'));
8815 FBody :=
8816 Make_Subprogram_Body (Loc,
8817 Specification => Spec,
8819 Declarations => New_List (
8820 Make_Object_Declaration (Loc,
8821 Defining_Identifier => BTemp,
8822 Constant_Present => True,
8823 Object_Definition =>
8824 New_Occurrence_Of (Standard_Boolean, Loc),
8825 Expression => Expr_M)),
8827 Handled_Statement_Sequence =>
8828 Make_Handled_Sequence_Of_Statements (Loc,
8829 Statements => New_List (
8830 Make_Simple_Return_Statement (Loc,
8831 Expression => New_Occurrence_Of (BTemp, Loc)))));
8833 -- Insert declaration before freeze node and body after
8835 Insert_Before_And_Analyze (N, FDecl);
8836 Insert_After_And_Analyze (N, FBody);
8837 end;
8838 end if;
8840 -- See if we have a static predicate. Note that the answer may be
8841 -- yes even if we have an explicit Dynamic_Predicate present.
8843 declare
8844 PS : Boolean;
8845 EN : Node_Id;
8847 begin
8848 if not Is_Scalar_Type (Typ) and then not Is_String_Type (Typ) then
8849 PS := False;
8850 else
8851 PS := Is_Predicate_Static (Expr, Object_Name);
8852 end if;
8854 -- Case where we have a predicate-static aspect
8856 if PS then
8858 -- We don't set Has_Static_Predicate_Aspect, since we can have
8859 -- any of the three cases (Predicate, Dynamic_Predicate, or
8860 -- Static_Predicate) generating a predicate with an expression
8861 -- that is predicate-static. We just indicate that we have a
8862 -- predicate that can be treated as static.
8864 Set_Has_Static_Predicate (Typ);
8866 -- For discrete subtype, build the static predicate list
8868 if Is_Discrete_Type (Typ) then
8869 Build_Discrete_Static_Predicate (Typ, Expr, Object_Name);
8871 -- If we don't get a static predicate list, it means that we
8872 -- have a case where this is not possible, most typically in
8873 -- the case where we inherit a dynamic predicate. We do not
8874 -- consider this an error, we just leave the predicate as
8875 -- dynamic. But if we do succeed in building the list, then
8876 -- we mark the predicate as static.
8878 if No (Static_Discrete_Predicate (Typ)) then
8879 Set_Has_Static_Predicate (Typ, False);
8880 end if;
8882 -- For real or string subtype, save predicate expression
8884 elsif Is_Real_Type (Typ) or else Is_String_Type (Typ) then
8885 Set_Static_Real_Or_String_Predicate (Typ, Expr);
8886 end if;
8888 -- Case of dynamic predicate (expression is not predicate-static)
8890 else
8891 -- Again, we don't set Has_Dynamic_Predicate_Aspect, since that
8892 -- is only set if we have an explicit Dynamic_Predicate aspect
8893 -- given. Here we may simply have a Predicate aspect where the
8894 -- expression happens not to be predicate-static.
8896 -- Emit an error when the predicate is categorized as static
8897 -- but its expression is not predicate-static.
8899 -- First a little fiddling to get a nice location for the
8900 -- message. If the expression is of the form (A and then B),
8901 -- where A is an inherited predicate, then use the right
8902 -- operand for the Sloc. This avoids getting confused by a call
8903 -- to an inherited predicate with a less convenient source
8904 -- location.
8906 EN := Expr;
8907 while Nkind (EN) = N_And_Then
8908 and then Nkind (Left_Opnd (EN)) = N_Function_Call
8909 and then Is_Predicate_Function
8910 (Entity (Name (Left_Opnd (EN))))
8911 loop
8912 EN := Right_Opnd (EN);
8913 end loop;
8915 -- Now post appropriate message
8917 if Has_Static_Predicate_Aspect (Typ) then
8918 if Is_Scalar_Type (Typ) or else Is_String_Type (Typ) then
8919 Error_Msg_F
8920 ("expression is not predicate-static (RM 3.2.4(16-22))",
8921 EN);
8922 else
8923 Error_Msg_F
8924 ("static predicate requires scalar or string type", EN);
8925 end if;
8926 end if;
8927 end if;
8928 end;
8929 end if;
8931 Restore_Ghost_Mode (Mode);
8932 end Build_Predicate_Functions;
8934 ------------------------------------------
8935 -- Build_Predicate_Function_Declaration --
8936 ------------------------------------------
8938 -- WARNING: This routine manages Ghost regions. Return statements must be
8939 -- replaced by gotos which jump to the end of the routine and restore the
8940 -- Ghost mode.
8942 function Build_Predicate_Function_Declaration
8943 (Typ : Entity_Id) return Node_Id
8945 Loc : constant Source_Ptr := Sloc (Typ);
8947 Func_Decl : Node_Id;
8948 Func_Id : Entity_Id;
8949 Mode : Ghost_Mode_Type;
8950 Spec : Node_Id;
8952 begin
8953 -- The related type may be subject to pragma Ghost. Set the mode now to
8954 -- ensure that the predicate functions are properly marked as Ghost.
8956 Set_Ghost_Mode (Typ, Mode);
8958 Func_Id :=
8959 Make_Defining_Identifier (Loc,
8960 Chars => New_External_Name (Chars (Typ), "Predicate"));
8962 Spec :=
8963 Make_Function_Specification (Loc,
8964 Defining_Unit_Name => Func_Id,
8965 Parameter_Specifications => New_List (
8966 Make_Parameter_Specification (Loc,
8967 Defining_Identifier => Make_Temporary (Loc, 'I'),
8968 Parameter_Type => New_Occurrence_Of (Typ, Loc))),
8969 Result_Definition =>
8970 New_Occurrence_Of (Standard_Boolean, Loc));
8972 Func_Decl := Make_Subprogram_Declaration (Loc, Specification => Spec);
8974 Set_Ekind (Func_Id, E_Function);
8975 Set_Etype (Func_Id, Standard_Boolean);
8976 Set_Is_Internal (Func_Id);
8977 Set_Is_Predicate_Function (Func_Id);
8978 Set_Predicate_Function (Typ, Func_Id);
8980 Insert_After (Parent (Typ), Func_Decl);
8981 Analyze (Func_Decl);
8983 Restore_Ghost_Mode (Mode);
8985 return Func_Decl;
8986 end Build_Predicate_Function_Declaration;
8988 -----------------------------------------
8989 -- Check_Aspect_At_End_Of_Declarations --
8990 -----------------------------------------
8992 procedure Check_Aspect_At_End_Of_Declarations (ASN : Node_Id) is
8993 Ent : constant Entity_Id := Entity (ASN);
8994 Ident : constant Node_Id := Identifier (ASN);
8995 A_Id : constant Aspect_Id := Get_Aspect_Id (Chars (Ident));
8997 End_Decl_Expr : constant Node_Id := Entity (Ident);
8998 -- Expression to be analyzed at end of declarations
9000 Freeze_Expr : constant Node_Id := Expression (ASN);
9001 -- Expression from call to Check_Aspect_At_Freeze_Point.
9003 T : constant Entity_Id := Etype (Original_Node (Freeze_Expr));
9004 -- Type required for preanalyze call. We use the original expression to
9005 -- get the proper type, to prevent cascaded errors when the expression
9006 -- is constant-folded.
9008 Err : Boolean;
9009 -- Set False if error
9011 -- On entry to this procedure, Entity (Ident) contains a copy of the
9012 -- original expression from the aspect, saved for this purpose, and
9013 -- but Expression (Ident) is a preanalyzed copy of the expression,
9014 -- preanalyzed just after the freeze point.
9016 procedure Check_Overloaded_Name;
9017 -- For aspects whose expression is simply a name, this routine checks if
9018 -- the name is overloaded or not. If so, it verifies there is an
9019 -- interpretation that matches the entity obtained at the freeze point,
9020 -- otherwise the compiler complains.
9022 ---------------------------
9023 -- Check_Overloaded_Name --
9024 ---------------------------
9026 procedure Check_Overloaded_Name is
9027 begin
9028 if not Is_Overloaded (End_Decl_Expr) then
9029 Err := not Is_Entity_Name (End_Decl_Expr)
9030 or else Entity (End_Decl_Expr) /= Entity (Freeze_Expr);
9032 else
9033 Err := True;
9035 declare
9036 Index : Interp_Index;
9037 It : Interp;
9039 begin
9040 Get_First_Interp (End_Decl_Expr, Index, It);
9041 while Present (It.Typ) loop
9042 if It.Nam = Entity (Freeze_Expr) then
9043 Err := False;
9044 exit;
9045 end if;
9047 Get_Next_Interp (Index, It);
9048 end loop;
9049 end;
9050 end if;
9051 end Check_Overloaded_Name;
9053 -- Start of processing for Check_Aspect_At_End_Of_Declarations
9055 begin
9056 -- In an instance we do not perform the consistency check between freeze
9057 -- point and end of declarations, because it was done already in the
9058 -- analysis of the generic. Furthermore, the delayed analysis of an
9059 -- aspect of the instance may produce spurious errors when the generic
9060 -- is a child unit that references entities in the parent (which might
9061 -- not be in scope at the freeze point of the instance).
9063 if In_Instance then
9064 return;
9066 -- Case of aspects Dimension, Dimension_System and Synchronization
9068 elsif A_Id = Aspect_Synchronization then
9069 return;
9071 -- Case of stream attributes, just have to compare entities. However,
9072 -- the expression is just a name (possibly overloaded), and there may
9073 -- be stream operations declared for unrelated types, so we just need
9074 -- to verify that one of these interpretations is the one available at
9075 -- at the freeze point.
9077 elsif A_Id = Aspect_Input or else
9078 A_Id = Aspect_Output or else
9079 A_Id = Aspect_Read or else
9080 A_Id = Aspect_Write
9081 then
9082 Analyze (End_Decl_Expr);
9083 Check_Overloaded_Name;
9085 elsif A_Id = Aspect_Variable_Indexing or else
9086 A_Id = Aspect_Constant_Indexing or else
9087 A_Id = Aspect_Default_Iterator or else
9088 A_Id = Aspect_Iterator_Element
9089 then
9090 -- Make type unfrozen before analysis, to prevent spurious errors
9091 -- about late attributes.
9093 Set_Is_Frozen (Ent, False);
9094 Analyze (End_Decl_Expr);
9095 Set_Is_Frozen (Ent, True);
9097 -- If the end of declarations comes before any other freeze
9098 -- point, the Freeze_Expr is not analyzed: no check needed.
9100 if Analyzed (Freeze_Expr) and then not In_Instance then
9101 Check_Overloaded_Name;
9102 else
9103 Err := False;
9104 end if;
9106 -- All other cases
9108 else
9109 -- Indicate that the expression comes from an aspect specification,
9110 -- which is used in subsequent analysis even if expansion is off.
9112 Set_Parent (End_Decl_Expr, ASN);
9114 -- In a generic context the aspect expressions have not been
9115 -- preanalyzed, so do it now. There are no conformance checks
9116 -- to perform in this case.
9118 if No (T) then
9119 Check_Aspect_At_Freeze_Point (ASN);
9120 return;
9122 -- The default values attributes may be defined in the private part,
9123 -- and the analysis of the expression may take place when only the
9124 -- partial view is visible. The expression must be scalar, so use
9125 -- the full view to resolve.
9127 elsif (A_Id = Aspect_Default_Value
9128 or else
9129 A_Id = Aspect_Default_Component_Value)
9130 and then Is_Private_Type (T)
9131 then
9132 Preanalyze_Spec_Expression (End_Decl_Expr, Full_View (T));
9134 else
9135 Preanalyze_Spec_Expression (End_Decl_Expr, T);
9136 end if;
9138 Err := not Fully_Conformant_Expressions (End_Decl_Expr, Freeze_Expr);
9139 end if;
9141 -- Output error message if error. Force error on aspect specification
9142 -- even if there is an error on the expression itself.
9144 if Err then
9145 Error_Msg_NE
9146 ("!visibility of aspect for& changes after freeze point",
9147 ASN, Ent);
9148 Error_Msg_NE
9149 ("info: & is frozen here, aspects evaluated at this point??",
9150 Freeze_Node (Ent), Ent);
9151 end if;
9152 end Check_Aspect_At_End_Of_Declarations;
9154 ----------------------------------
9155 -- Check_Aspect_At_Freeze_Point --
9156 ----------------------------------
9158 procedure Check_Aspect_At_Freeze_Point (ASN : Node_Id) is
9159 Ident : constant Node_Id := Identifier (ASN);
9160 -- Identifier (use Entity field to save expression)
9162 A_Id : constant Aspect_Id := Get_Aspect_Id (Chars (Ident));
9164 T : Entity_Id := Empty;
9165 -- Type required for preanalyze call
9167 begin
9168 -- On entry to this procedure, Entity (Ident) contains a copy of the
9169 -- original expression from the aspect, saved for this purpose.
9171 -- On exit from this procedure Entity (Ident) is unchanged, still
9172 -- containing that copy, but Expression (Ident) is a preanalyzed copy
9173 -- of the expression, preanalyzed just after the freeze point.
9175 -- Make a copy of the expression to be preanalyzed
9177 Set_Expression (ASN, New_Copy_Tree (Entity (Ident)));
9179 -- Find type for preanalyze call
9181 case A_Id is
9183 -- No_Aspect should be impossible
9185 when No_Aspect =>
9186 raise Program_Error;
9188 -- Aspects taking an optional boolean argument
9190 when Boolean_Aspects
9191 | Library_Unit_Aspects
9193 T := Standard_Boolean;
9195 -- Aspects corresponding to attribute definition clauses
9197 when Aspect_Address =>
9198 T := RTE (RE_Address);
9200 when Aspect_Attach_Handler =>
9201 T := RTE (RE_Interrupt_ID);
9203 when Aspect_Bit_Order
9204 | Aspect_Scalar_Storage_Order
9206 T := RTE (RE_Bit_Order);
9208 when Aspect_Convention =>
9209 return;
9211 when Aspect_CPU =>
9212 T := RTE (RE_CPU_Range);
9214 -- Default_Component_Value is resolved with the component type
9216 when Aspect_Default_Component_Value =>
9217 T := Component_Type (Entity (ASN));
9219 when Aspect_Default_Storage_Pool =>
9220 T := Class_Wide_Type (RTE (RE_Root_Storage_Pool));
9222 -- Default_Value is resolved with the type entity in question
9224 when Aspect_Default_Value =>
9225 T := Entity (ASN);
9227 when Aspect_Dispatching_Domain =>
9228 T := RTE (RE_Dispatching_Domain);
9230 when Aspect_External_Tag =>
9231 T := Standard_String;
9233 when Aspect_External_Name =>
9234 T := Standard_String;
9236 when Aspect_Link_Name =>
9237 T := Standard_String;
9239 when Aspect_Interrupt_Priority
9240 | Aspect_Priority
9242 T := Standard_Integer;
9244 when Aspect_Relative_Deadline =>
9245 T := RTE (RE_Time_Span);
9247 when Aspect_Secondary_Stack_Size =>
9248 T := Standard_Integer;
9250 when Aspect_Small =>
9251 T := Universal_Real;
9253 -- For a simple storage pool, we have to retrieve the type of the
9254 -- pool object associated with the aspect's corresponding attribute
9255 -- definition clause.
9257 when Aspect_Simple_Storage_Pool =>
9258 T := Etype (Expression (Aspect_Rep_Item (ASN)));
9260 when Aspect_Storage_Pool =>
9261 T := Class_Wide_Type (RTE (RE_Root_Storage_Pool));
9263 when Aspect_Alignment
9264 | Aspect_Component_Size
9265 | Aspect_Machine_Radix
9266 | Aspect_Object_Size
9267 | Aspect_Size
9268 | Aspect_Storage_Size
9269 | Aspect_Stream_Size
9270 | Aspect_Value_Size
9272 T := Any_Integer;
9274 when Aspect_Linker_Section =>
9275 T := Standard_String;
9277 when Aspect_Synchronization =>
9278 return;
9280 -- Special case, the expression of these aspects is just an entity
9281 -- that does not need any resolution, so just analyze.
9283 when Aspect_Input
9284 | Aspect_Output
9285 | Aspect_Read
9286 | Aspect_Suppress
9287 | Aspect_Unsuppress
9288 | Aspect_Warnings
9289 | Aspect_Write
9291 Analyze (Expression (ASN));
9292 return;
9294 -- Same for Iterator aspects, where the expression is a function
9295 -- name. Legality rules are checked separately.
9297 when Aspect_Constant_Indexing
9298 | Aspect_Default_Iterator
9299 | Aspect_Iterator_Element
9300 | Aspect_Variable_Indexing
9302 Analyze (Expression (ASN));
9303 return;
9305 -- Ditto for Iterable, legality checks in Validate_Iterable_Aspect.
9307 when Aspect_Iterable =>
9308 T := Entity (ASN);
9310 declare
9311 Cursor : constant Entity_Id := Get_Cursor_Type (ASN, T);
9312 Assoc : Node_Id;
9313 Expr : Node_Id;
9315 begin
9316 if Cursor = Any_Type then
9317 return;
9318 end if;
9320 Assoc := First (Component_Associations (Expression (ASN)));
9321 while Present (Assoc) loop
9322 Expr := Expression (Assoc);
9323 Analyze (Expr);
9325 if not Error_Posted (Expr) then
9326 Resolve_Iterable_Operation
9327 (Expr, Cursor, T, Chars (First (Choices (Assoc))));
9328 end if;
9330 Next (Assoc);
9331 end loop;
9332 end;
9334 return;
9336 -- Invariant/Predicate take boolean expressions
9338 when Aspect_Dynamic_Predicate
9339 | Aspect_Invariant
9340 | Aspect_Predicate
9341 | Aspect_Static_Predicate
9342 | Aspect_Type_Invariant
9344 T := Standard_Boolean;
9346 when Aspect_Predicate_Failure =>
9347 T := Standard_String;
9349 -- Here is the list of aspects that don't require delay analysis
9351 when Aspect_Abstract_State
9352 | Aspect_Annotate
9353 | Aspect_Async_Readers
9354 | Aspect_Async_Writers
9355 | Aspect_Constant_After_Elaboration
9356 | Aspect_Contract_Cases
9357 | Aspect_Default_Initial_Condition
9358 | Aspect_Depends
9359 | Aspect_Dimension
9360 | Aspect_Dimension_System
9361 | Aspect_Effective_Reads
9362 | Aspect_Effective_Writes
9363 | Aspect_Extensions_Visible
9364 | Aspect_Ghost
9365 | Aspect_Global
9366 | Aspect_Implicit_Dereference
9367 | Aspect_Initial_Condition
9368 | Aspect_Initializes
9369 | Aspect_Max_Queue_Length
9370 | Aspect_Obsolescent
9371 | Aspect_Part_Of
9372 | Aspect_Post
9373 | Aspect_Postcondition
9374 | Aspect_Pre
9375 | Aspect_Precondition
9376 | Aspect_Refined_Depends
9377 | Aspect_Refined_Global
9378 | Aspect_Refined_Post
9379 | Aspect_Refined_State
9380 | Aspect_SPARK_Mode
9381 | Aspect_Test_Case
9382 | Aspect_Unimplemented
9383 | Aspect_Volatile_Function
9385 raise Program_Error;
9387 end case;
9389 -- Do the preanalyze call
9391 Preanalyze_Spec_Expression (Expression (ASN), T);
9392 end Check_Aspect_At_Freeze_Point;
9394 -----------------------------------
9395 -- Check_Constant_Address_Clause --
9396 -----------------------------------
9398 procedure Check_Constant_Address_Clause
9399 (Expr : Node_Id;
9400 U_Ent : Entity_Id)
9402 procedure Check_At_Constant_Address (Nod : Node_Id);
9403 -- Checks that the given node N represents a name whose 'Address is
9404 -- constant (in the same sense as OK_Constant_Address_Clause, i.e. the
9405 -- address value is the same at the point of declaration of U_Ent and at
9406 -- the time of elaboration of the address clause.
9408 procedure Check_Expr_Constants (Nod : Node_Id);
9409 -- Checks that Nod meets the requirements for a constant address clause
9410 -- in the sense of the enclosing procedure.
9412 procedure Check_List_Constants (Lst : List_Id);
9413 -- Check that all elements of list Lst meet the requirements for a
9414 -- constant address clause in the sense of the enclosing procedure.
9416 -------------------------------
9417 -- Check_At_Constant_Address --
9418 -------------------------------
9420 procedure Check_At_Constant_Address (Nod : Node_Id) is
9421 begin
9422 if Is_Entity_Name (Nod) then
9423 if Present (Address_Clause (Entity ((Nod)))) then
9424 Error_Msg_NE
9425 ("invalid address clause for initialized object &!",
9426 Nod, U_Ent);
9427 Error_Msg_NE
9428 ("address for& cannot depend on another address clause! "
9429 & "(RM 13.1(22))!", Nod, U_Ent);
9431 elsif In_Same_Source_Unit (Entity (Nod), U_Ent)
9432 and then Sloc (U_Ent) < Sloc (Entity (Nod))
9433 then
9434 Error_Msg_NE
9435 ("invalid address clause for initialized object &!",
9436 Nod, U_Ent);
9437 Error_Msg_Node_2 := U_Ent;
9438 Error_Msg_NE
9439 ("\& must be defined before & (RM 13.1(22))!",
9440 Nod, Entity (Nod));
9441 end if;
9443 elsif Nkind (Nod) = N_Selected_Component then
9444 declare
9445 T : constant Entity_Id := Etype (Prefix (Nod));
9447 begin
9448 if (Is_Record_Type (T)
9449 and then Has_Discriminants (T))
9450 or else
9451 (Is_Access_Type (T)
9452 and then Is_Record_Type (Designated_Type (T))
9453 and then Has_Discriminants (Designated_Type (T)))
9454 then
9455 Error_Msg_NE
9456 ("invalid address clause for initialized object &!",
9457 Nod, U_Ent);
9458 Error_Msg_N
9459 ("\address cannot depend on component of discriminated "
9460 & "record (RM 13.1(22))!", Nod);
9461 else
9462 Check_At_Constant_Address (Prefix (Nod));
9463 end if;
9464 end;
9466 elsif Nkind (Nod) = N_Indexed_Component then
9467 Check_At_Constant_Address (Prefix (Nod));
9468 Check_List_Constants (Expressions (Nod));
9470 else
9471 Check_Expr_Constants (Nod);
9472 end if;
9473 end Check_At_Constant_Address;
9475 --------------------------
9476 -- Check_Expr_Constants --
9477 --------------------------
9479 procedure Check_Expr_Constants (Nod : Node_Id) is
9480 Loc_U_Ent : constant Source_Ptr := Sloc (U_Ent);
9481 Ent : Entity_Id := Empty;
9483 begin
9484 if Nkind (Nod) in N_Has_Etype
9485 and then Etype (Nod) = Any_Type
9486 then
9487 return;
9488 end if;
9490 case Nkind (Nod) is
9491 when N_Empty
9492 | N_Error
9494 return;
9496 when N_Expanded_Name
9497 | N_Identifier
9499 Ent := Entity (Nod);
9501 -- We need to look at the original node if it is different
9502 -- from the node, since we may have rewritten things and
9503 -- substituted an identifier representing the rewrite.
9505 if Original_Node (Nod) /= Nod then
9506 Check_Expr_Constants (Original_Node (Nod));
9508 -- If the node is an object declaration without initial
9509 -- value, some code has been expanded, and the expression
9510 -- is not constant, even if the constituents might be
9511 -- acceptable, as in A'Address + offset.
9513 if Ekind (Ent) = E_Variable
9514 and then
9515 Nkind (Declaration_Node (Ent)) = N_Object_Declaration
9516 and then
9517 No (Expression (Declaration_Node (Ent)))
9518 then
9519 Error_Msg_NE
9520 ("invalid address clause for initialized object &!",
9521 Nod, U_Ent);
9523 -- If entity is constant, it may be the result of expanding
9524 -- a check. We must verify that its declaration appears
9525 -- before the object in question, else we also reject the
9526 -- address clause.
9528 elsif Ekind (Ent) = E_Constant
9529 and then In_Same_Source_Unit (Ent, U_Ent)
9530 and then Sloc (Ent) > Loc_U_Ent
9531 then
9532 Error_Msg_NE
9533 ("invalid address clause for initialized object &!",
9534 Nod, U_Ent);
9535 end if;
9537 return;
9538 end if;
9540 -- Otherwise look at the identifier and see if it is OK
9542 if Ekind_In (Ent, E_Named_Integer, E_Named_Real)
9543 or else Is_Type (Ent)
9544 then
9545 return;
9547 elsif Ekind_In (Ent, E_Constant, E_In_Parameter) then
9549 -- This is the case where we must have Ent defined before
9550 -- U_Ent. Clearly if they are in different units this
9551 -- requirement is met since the unit containing Ent is
9552 -- already processed.
9554 if not In_Same_Source_Unit (Ent, U_Ent) then
9555 return;
9557 -- Otherwise location of Ent must be before the location
9558 -- of U_Ent, that's what prior defined means.
9560 elsif Sloc (Ent) < Loc_U_Ent then
9561 return;
9563 else
9564 Error_Msg_NE
9565 ("invalid address clause for initialized object &!",
9566 Nod, U_Ent);
9567 Error_Msg_Node_2 := U_Ent;
9568 Error_Msg_NE
9569 ("\& must be defined before & (RM 13.1(22))!",
9570 Nod, Ent);
9571 end if;
9573 elsif Nkind (Original_Node (Nod)) = N_Function_Call then
9574 Check_Expr_Constants (Original_Node (Nod));
9576 else
9577 Error_Msg_NE
9578 ("invalid address clause for initialized object &!",
9579 Nod, U_Ent);
9581 if Comes_From_Source (Ent) then
9582 Error_Msg_NE
9583 ("\reference to variable& not allowed"
9584 & " (RM 13.1(22))!", Nod, Ent);
9585 else
9586 Error_Msg_N
9587 ("non-static expression not allowed"
9588 & " (RM 13.1(22))!", Nod);
9589 end if;
9590 end if;
9592 when N_Integer_Literal =>
9594 -- If this is a rewritten unchecked conversion, in a system
9595 -- where Address is an integer type, always use the base type
9596 -- for a literal value. This is user-friendly and prevents
9597 -- order-of-elaboration issues with instances of unchecked
9598 -- conversion.
9600 if Nkind (Original_Node (Nod)) = N_Function_Call then
9601 Set_Etype (Nod, Base_Type (Etype (Nod)));
9602 end if;
9604 when N_Character_Literal
9605 | N_Real_Literal
9606 | N_String_Literal
9608 return;
9610 when N_Range =>
9611 Check_Expr_Constants (Low_Bound (Nod));
9612 Check_Expr_Constants (High_Bound (Nod));
9614 when N_Explicit_Dereference =>
9615 Check_Expr_Constants (Prefix (Nod));
9617 when N_Indexed_Component =>
9618 Check_Expr_Constants (Prefix (Nod));
9619 Check_List_Constants (Expressions (Nod));
9621 when N_Slice =>
9622 Check_Expr_Constants (Prefix (Nod));
9623 Check_Expr_Constants (Discrete_Range (Nod));
9625 when N_Selected_Component =>
9626 Check_Expr_Constants (Prefix (Nod));
9628 when N_Attribute_Reference =>
9629 if Nam_In (Attribute_Name (Nod), Name_Address,
9630 Name_Access,
9631 Name_Unchecked_Access,
9632 Name_Unrestricted_Access)
9633 then
9634 Check_At_Constant_Address (Prefix (Nod));
9636 else
9637 Check_Expr_Constants (Prefix (Nod));
9638 Check_List_Constants (Expressions (Nod));
9639 end if;
9641 when N_Aggregate =>
9642 Check_List_Constants (Component_Associations (Nod));
9643 Check_List_Constants (Expressions (Nod));
9645 when N_Component_Association =>
9646 Check_Expr_Constants (Expression (Nod));
9648 when N_Extension_Aggregate =>
9649 Check_Expr_Constants (Ancestor_Part (Nod));
9650 Check_List_Constants (Component_Associations (Nod));
9651 Check_List_Constants (Expressions (Nod));
9653 when N_Null =>
9654 return;
9656 when N_Binary_Op
9657 | N_Membership_Test
9658 | N_Short_Circuit
9660 Check_Expr_Constants (Left_Opnd (Nod));
9661 Check_Expr_Constants (Right_Opnd (Nod));
9663 when N_Unary_Op =>
9664 Check_Expr_Constants (Right_Opnd (Nod));
9666 when N_Allocator
9667 | N_Qualified_Expression
9668 | N_Type_Conversion
9669 | N_Unchecked_Type_Conversion
9671 Check_Expr_Constants (Expression (Nod));
9673 when N_Function_Call =>
9674 if not Is_Pure (Entity (Name (Nod))) then
9675 Error_Msg_NE
9676 ("invalid address clause for initialized object &!",
9677 Nod, U_Ent);
9679 Error_Msg_NE
9680 ("\function & is not pure (RM 13.1(22))!",
9681 Nod, Entity (Name (Nod)));
9683 else
9684 Check_List_Constants (Parameter_Associations (Nod));
9685 end if;
9687 when N_Parameter_Association =>
9688 Check_Expr_Constants (Explicit_Actual_Parameter (Nod));
9690 when others =>
9691 Error_Msg_NE
9692 ("invalid address clause for initialized object &!",
9693 Nod, U_Ent);
9694 Error_Msg_NE
9695 ("\must be constant defined before& (RM 13.1(22))!",
9696 Nod, U_Ent);
9697 end case;
9698 end Check_Expr_Constants;
9700 --------------------------
9701 -- Check_List_Constants --
9702 --------------------------
9704 procedure Check_List_Constants (Lst : List_Id) is
9705 Nod1 : Node_Id;
9707 begin
9708 if Present (Lst) then
9709 Nod1 := First (Lst);
9710 while Present (Nod1) loop
9711 Check_Expr_Constants (Nod1);
9712 Next (Nod1);
9713 end loop;
9714 end if;
9715 end Check_List_Constants;
9717 -- Start of processing for Check_Constant_Address_Clause
9719 begin
9720 -- If rep_clauses are to be ignored, no need for legality checks. In
9721 -- particular, no need to pester user about rep clauses that violate the
9722 -- rule on constant addresses, given that these clauses will be removed
9723 -- by Freeze before they reach the back end. Similarly in CodePeer mode,
9724 -- we want to relax these checks.
9726 if not Ignore_Rep_Clauses and not CodePeer_Mode then
9727 Check_Expr_Constants (Expr);
9728 end if;
9729 end Check_Constant_Address_Clause;
9731 ---------------------------
9732 -- Check_Pool_Size_Clash --
9733 ---------------------------
9735 procedure Check_Pool_Size_Clash (Ent : Entity_Id; SP, SS : Node_Id) is
9736 Post : Node_Id;
9738 begin
9739 -- We need to find out which one came first. Note that in the case of
9740 -- aspects mixed with pragmas there are cases where the processing order
9741 -- is reversed, which is why we do the check here.
9743 if Sloc (SP) < Sloc (SS) then
9744 Error_Msg_Sloc := Sloc (SP);
9745 Post := SS;
9746 Error_Msg_NE ("Storage_Pool previously given for&#", Post, Ent);
9748 else
9749 Error_Msg_Sloc := Sloc (SS);
9750 Post := SP;
9751 Error_Msg_NE ("Storage_Size previously given for&#", Post, Ent);
9752 end if;
9754 Error_Msg_N
9755 ("\cannot have Storage_Size and Storage_Pool (RM 13.11(3))", Post);
9756 end Check_Pool_Size_Clash;
9758 ----------------------------------------
9759 -- Check_Record_Representation_Clause --
9760 ----------------------------------------
9762 procedure Check_Record_Representation_Clause (N : Node_Id) is
9763 Loc : constant Source_Ptr := Sloc (N);
9764 Ident : constant Node_Id := Identifier (N);
9765 Rectype : Entity_Id;
9766 Fent : Entity_Id;
9767 CC : Node_Id;
9768 Fbit : Uint;
9769 Lbit : Uint;
9770 Hbit : Uint := Uint_0;
9771 Comp : Entity_Id;
9772 Pcomp : Entity_Id;
9774 Max_Bit_So_Far : Uint;
9775 -- Records the maximum bit position so far. If all field positions
9776 -- are monotonically increasing, then we can skip the circuit for
9777 -- checking for overlap, since no overlap is possible.
9779 Tagged_Parent : Entity_Id := Empty;
9780 -- This is set in the case of a derived tagged type for which we have
9781 -- Is_Fully_Repped_Tagged_Type True (indicating that all components are
9782 -- positioned by record representation clauses). In this case we must
9783 -- check for overlap between components of this tagged type, and the
9784 -- components of its parent. Tagged_Parent will point to this parent
9785 -- type. For all other cases Tagged_Parent is left set to Empty.
9787 Parent_Last_Bit : Uint;
9788 -- Relevant only if Tagged_Parent is set, Parent_Last_Bit indicates the
9789 -- last bit position for any field in the parent type. We only need to
9790 -- check overlap for fields starting below this point.
9792 Overlap_Check_Required : Boolean;
9793 -- Used to keep track of whether or not an overlap check is required
9795 Overlap_Detected : Boolean := False;
9796 -- Set True if an overlap is detected
9798 Ccount : Natural := 0;
9799 -- Number of component clauses in record rep clause
9801 procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id);
9802 -- Given two entities for record components or discriminants, checks
9803 -- if they have overlapping component clauses and issues errors if so.
9805 procedure Find_Component;
9806 -- Finds component entity corresponding to current component clause (in
9807 -- CC), and sets Comp to the entity, and Fbit/Lbit to the zero origin
9808 -- start/stop bits for the field. If there is no matching component or
9809 -- if the matching component does not have a component clause, then
9810 -- that's an error and Comp is set to Empty, but no error message is
9811 -- issued, since the message was already given. Comp is also set to
9812 -- Empty if the current "component clause" is in fact a pragma.
9814 -----------------------------
9815 -- Check_Component_Overlap --
9816 -----------------------------
9818 procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id) is
9819 CC1 : constant Node_Id := Component_Clause (C1_Ent);
9820 CC2 : constant Node_Id := Component_Clause (C2_Ent);
9822 begin
9823 if Present (CC1) and then Present (CC2) then
9825 -- Exclude odd case where we have two tag components in the same
9826 -- record, both at location zero. This seems a bit strange, but
9827 -- it seems to happen in some circumstances, perhaps on an error.
9829 if Nam_In (Chars (C1_Ent), Name_uTag, Name_uTag) then
9830 return;
9831 end if;
9833 -- Here we check if the two fields overlap
9835 declare
9836 S1 : constant Uint := Component_Bit_Offset (C1_Ent);
9837 S2 : constant Uint := Component_Bit_Offset (C2_Ent);
9838 E1 : constant Uint := S1 + Esize (C1_Ent);
9839 E2 : constant Uint := S2 + Esize (C2_Ent);
9841 begin
9842 if E2 <= S1 or else E1 <= S2 then
9843 null;
9844 else
9845 Error_Msg_Node_2 := Component_Name (CC2);
9846 Error_Msg_Sloc := Sloc (Error_Msg_Node_2);
9847 Error_Msg_Node_1 := Component_Name (CC1);
9848 Error_Msg_N
9849 ("component& overlaps & #", Component_Name (CC1));
9850 Overlap_Detected := True;
9851 end if;
9852 end;
9853 end if;
9854 end Check_Component_Overlap;
9856 --------------------
9857 -- Find_Component --
9858 --------------------
9860 procedure Find_Component is
9862 procedure Search_Component (R : Entity_Id);
9863 -- Search components of R for a match. If found, Comp is set
9865 ----------------------
9866 -- Search_Component --
9867 ----------------------
9869 procedure Search_Component (R : Entity_Id) is
9870 begin
9871 Comp := First_Component_Or_Discriminant (R);
9872 while Present (Comp) loop
9874 -- Ignore error of attribute name for component name (we
9875 -- already gave an error message for this, so no need to
9876 -- complain here)
9878 if Nkind (Component_Name (CC)) = N_Attribute_Reference then
9879 null;
9880 else
9881 exit when Chars (Comp) = Chars (Component_Name (CC));
9882 end if;
9884 Next_Component_Or_Discriminant (Comp);
9885 end loop;
9886 end Search_Component;
9888 -- Start of processing for Find_Component
9890 begin
9891 -- Return with Comp set to Empty if we have a pragma
9893 if Nkind (CC) = N_Pragma then
9894 Comp := Empty;
9895 return;
9896 end if;
9898 -- Search current record for matching component
9900 Search_Component (Rectype);
9902 -- If not found, maybe component of base type discriminant that is
9903 -- absent from statically constrained first subtype.
9905 if No (Comp) then
9906 Search_Component (Base_Type (Rectype));
9907 end if;
9909 -- If no component, or the component does not reference the component
9910 -- clause in question, then there was some previous error for which
9911 -- we already gave a message, so just return with Comp Empty.
9913 if No (Comp) or else Component_Clause (Comp) /= CC then
9914 Check_Error_Detected;
9915 Comp := Empty;
9917 -- Normal case where we have a component clause
9919 else
9920 Fbit := Component_Bit_Offset (Comp);
9921 Lbit := Fbit + Esize (Comp) - 1;
9922 end if;
9923 end Find_Component;
9925 -- Start of processing for Check_Record_Representation_Clause
9927 begin
9928 Find_Type (Ident);
9929 Rectype := Entity (Ident);
9931 if Rectype = Any_Type then
9932 return;
9933 else
9934 Rectype := Underlying_Type (Rectype);
9935 end if;
9937 -- See if we have a fully repped derived tagged type
9939 declare
9940 PS : constant Entity_Id := Parent_Subtype (Rectype);
9942 begin
9943 if Present (PS) and then Is_Fully_Repped_Tagged_Type (PS) then
9944 Tagged_Parent := PS;
9946 -- Find maximum bit of any component of the parent type
9948 Parent_Last_Bit := UI_From_Int (System_Address_Size - 1);
9949 Pcomp := First_Entity (Tagged_Parent);
9950 while Present (Pcomp) loop
9951 if Ekind_In (Pcomp, E_Discriminant, E_Component) then
9952 if Component_Bit_Offset (Pcomp) /= No_Uint
9953 and then Known_Static_Esize (Pcomp)
9954 then
9955 Parent_Last_Bit :=
9956 UI_Max
9957 (Parent_Last_Bit,
9958 Component_Bit_Offset (Pcomp) + Esize (Pcomp) - 1);
9959 end if;
9960 else
9962 -- Skip anonymous types generated for constrained array
9963 -- or record components.
9965 null;
9966 end if;
9968 Next_Entity (Pcomp);
9969 end loop;
9970 end if;
9971 end;
9973 -- All done if no component clauses
9975 CC := First (Component_Clauses (N));
9977 if No (CC) then
9978 return;
9979 end if;
9981 -- If a tag is present, then create a component clause that places it
9982 -- at the start of the record (otherwise gigi may place it after other
9983 -- fields that have rep clauses).
9985 Fent := First_Entity (Rectype);
9987 if Nkind (Fent) = N_Defining_Identifier
9988 and then Chars (Fent) = Name_uTag
9989 then
9990 Set_Component_Bit_Offset (Fent, Uint_0);
9991 Set_Normalized_Position (Fent, Uint_0);
9992 Set_Normalized_First_Bit (Fent, Uint_0);
9993 Set_Normalized_Position_Max (Fent, Uint_0);
9994 Init_Esize (Fent, System_Address_Size);
9996 Set_Component_Clause (Fent,
9997 Make_Component_Clause (Loc,
9998 Component_Name => Make_Identifier (Loc, Name_uTag),
10000 Position => Make_Integer_Literal (Loc, Uint_0),
10001 First_Bit => Make_Integer_Literal (Loc, Uint_0),
10002 Last_Bit =>
10003 Make_Integer_Literal (Loc,
10004 UI_From_Int (System_Address_Size))));
10006 Ccount := Ccount + 1;
10007 end if;
10009 Max_Bit_So_Far := Uint_Minus_1;
10010 Overlap_Check_Required := False;
10012 -- Process the component clauses
10014 while Present (CC) loop
10015 Find_Component;
10017 if Present (Comp) then
10018 Ccount := Ccount + 1;
10020 -- We need a full overlap check if record positions non-monotonic
10022 if Fbit <= Max_Bit_So_Far then
10023 Overlap_Check_Required := True;
10024 end if;
10026 Max_Bit_So_Far := Lbit;
10028 -- Check bit position out of range of specified size
10030 if Has_Size_Clause (Rectype)
10031 and then RM_Size (Rectype) <= Lbit
10032 then
10033 Error_Msg_N
10034 ("bit number out of range of specified size",
10035 Last_Bit (CC));
10037 -- Check for overlap with tag component
10039 else
10040 if Is_Tagged_Type (Rectype)
10041 and then Fbit < System_Address_Size
10042 then
10043 Error_Msg_NE
10044 ("component overlaps tag field of&",
10045 Component_Name (CC), Rectype);
10046 Overlap_Detected := True;
10047 end if;
10049 if Hbit < Lbit then
10050 Hbit := Lbit;
10051 end if;
10052 end if;
10054 -- Check parent overlap if component might overlap parent field
10056 if Present (Tagged_Parent) and then Fbit <= Parent_Last_Bit then
10057 Pcomp := First_Component_Or_Discriminant (Tagged_Parent);
10058 while Present (Pcomp) loop
10059 if not Is_Tag (Pcomp)
10060 and then Chars (Pcomp) /= Name_uParent
10061 then
10062 Check_Component_Overlap (Comp, Pcomp);
10063 end if;
10065 Next_Component_Or_Discriminant (Pcomp);
10066 end loop;
10067 end if;
10068 end if;
10070 Next (CC);
10071 end loop;
10073 -- Now that we have processed all the component clauses, check for
10074 -- overlap. We have to leave this till last, since the components can
10075 -- appear in any arbitrary order in the representation clause.
10077 -- We do not need this check if all specified ranges were monotonic,
10078 -- as recorded by Overlap_Check_Required being False at this stage.
10080 -- This first section checks if there are any overlapping entries at
10081 -- all. It does this by sorting all entries and then seeing if there are
10082 -- any overlaps. If there are none, then that is decisive, but if there
10083 -- are overlaps, they may still be OK (they may result from fields in
10084 -- different variants).
10086 if Overlap_Check_Required then
10087 Overlap_Check1 : declare
10089 OC_Fbit : array (0 .. Ccount) of Uint;
10090 -- First-bit values for component clauses, the value is the offset
10091 -- of the first bit of the field from start of record. The zero
10092 -- entry is for use in sorting.
10094 OC_Lbit : array (0 .. Ccount) of Uint;
10095 -- Last-bit values for component clauses, the value is the offset
10096 -- of the last bit of the field from start of record. The zero
10097 -- entry is for use in sorting.
10099 OC_Count : Natural := 0;
10100 -- Count of entries in OC_Fbit and OC_Lbit
10102 function OC_Lt (Op1, Op2 : Natural) return Boolean;
10103 -- Compare routine for Sort
10105 procedure OC_Move (From : Natural; To : Natural);
10106 -- Move routine for Sort
10108 package Sorting is new GNAT.Heap_Sort_G (OC_Move, OC_Lt);
10110 -----------
10111 -- OC_Lt --
10112 -----------
10114 function OC_Lt (Op1, Op2 : Natural) return Boolean is
10115 begin
10116 return OC_Fbit (Op1) < OC_Fbit (Op2);
10117 end OC_Lt;
10119 -------------
10120 -- OC_Move --
10121 -------------
10123 procedure OC_Move (From : Natural; To : Natural) is
10124 begin
10125 OC_Fbit (To) := OC_Fbit (From);
10126 OC_Lbit (To) := OC_Lbit (From);
10127 end OC_Move;
10129 -- Start of processing for Overlap_Check
10131 begin
10132 CC := First (Component_Clauses (N));
10133 while Present (CC) loop
10135 -- Exclude component clause already marked in error
10137 if not Error_Posted (CC) then
10138 Find_Component;
10140 if Present (Comp) then
10141 OC_Count := OC_Count + 1;
10142 OC_Fbit (OC_Count) := Fbit;
10143 OC_Lbit (OC_Count) := Lbit;
10144 end if;
10145 end if;
10147 Next (CC);
10148 end loop;
10150 Sorting.Sort (OC_Count);
10152 Overlap_Check_Required := False;
10153 for J in 1 .. OC_Count - 1 loop
10154 if OC_Lbit (J) >= OC_Fbit (J + 1) then
10155 Overlap_Check_Required := True;
10156 exit;
10157 end if;
10158 end loop;
10159 end Overlap_Check1;
10160 end if;
10162 -- If Overlap_Check_Required is still True, then we have to do the full
10163 -- scale overlap check, since we have at least two fields that do
10164 -- overlap, and we need to know if that is OK since they are in
10165 -- different variant, or whether we have a definite problem.
10167 if Overlap_Check_Required then
10168 Overlap_Check2 : declare
10169 C1_Ent, C2_Ent : Entity_Id;
10170 -- Entities of components being checked for overlap
10172 Clist : Node_Id;
10173 -- Component_List node whose Component_Items are being checked
10175 Citem : Node_Id;
10176 -- Component declaration for component being checked
10178 begin
10179 C1_Ent := First_Entity (Base_Type (Rectype));
10181 -- Loop through all components in record. For each component check
10182 -- for overlap with any of the preceding elements on the component
10183 -- list containing the component and also, if the component is in
10184 -- a variant, check against components outside the case structure.
10185 -- This latter test is repeated recursively up the variant tree.
10187 Main_Component_Loop : while Present (C1_Ent) loop
10188 if not Ekind_In (C1_Ent, E_Component, E_Discriminant) then
10189 goto Continue_Main_Component_Loop;
10190 end if;
10192 -- Skip overlap check if entity has no declaration node. This
10193 -- happens with discriminants in constrained derived types.
10194 -- Possibly we are missing some checks as a result, but that
10195 -- does not seem terribly serious.
10197 if No (Declaration_Node (C1_Ent)) then
10198 goto Continue_Main_Component_Loop;
10199 end if;
10201 Clist := Parent (List_Containing (Declaration_Node (C1_Ent)));
10203 -- Loop through component lists that need checking. Check the
10204 -- current component list and all lists in variants above us.
10206 Component_List_Loop : loop
10208 -- If derived type definition, go to full declaration
10209 -- If at outer level, check discriminants if there are any.
10211 if Nkind (Clist) = N_Derived_Type_Definition then
10212 Clist := Parent (Clist);
10213 end if;
10215 -- Outer level of record definition, check discriminants
10217 if Nkind_In (Clist, N_Full_Type_Declaration,
10218 N_Private_Type_Declaration)
10219 then
10220 if Has_Discriminants (Defining_Identifier (Clist)) then
10221 C2_Ent :=
10222 First_Discriminant (Defining_Identifier (Clist));
10223 while Present (C2_Ent) loop
10224 exit when C1_Ent = C2_Ent;
10225 Check_Component_Overlap (C1_Ent, C2_Ent);
10226 Next_Discriminant (C2_Ent);
10227 end loop;
10228 end if;
10230 -- Record extension case
10232 elsif Nkind (Clist) = N_Derived_Type_Definition then
10233 Clist := Empty;
10235 -- Otherwise check one component list
10237 else
10238 Citem := First (Component_Items (Clist));
10239 while Present (Citem) loop
10240 if Nkind (Citem) = N_Component_Declaration then
10241 C2_Ent := Defining_Identifier (Citem);
10242 exit when C1_Ent = C2_Ent;
10243 Check_Component_Overlap (C1_Ent, C2_Ent);
10244 end if;
10246 Next (Citem);
10247 end loop;
10248 end if;
10250 -- Check for variants above us (the parent of the Clist can
10251 -- be a variant, in which case its parent is a variant part,
10252 -- and the parent of the variant part is a component list
10253 -- whose components must all be checked against the current
10254 -- component for overlap).
10256 if Nkind (Parent (Clist)) = N_Variant then
10257 Clist := Parent (Parent (Parent (Clist)));
10259 -- Check for possible discriminant part in record, this
10260 -- is treated essentially as another level in the
10261 -- recursion. For this case the parent of the component
10262 -- list is the record definition, and its parent is the
10263 -- full type declaration containing the discriminant
10264 -- specifications.
10266 elsif Nkind (Parent (Clist)) = N_Record_Definition then
10267 Clist := Parent (Parent ((Clist)));
10269 -- If neither of these two cases, we are at the top of
10270 -- the tree.
10272 else
10273 exit Component_List_Loop;
10274 end if;
10275 end loop Component_List_Loop;
10277 <<Continue_Main_Component_Loop>>
10278 Next_Entity (C1_Ent);
10280 end loop Main_Component_Loop;
10281 end Overlap_Check2;
10282 end if;
10284 -- The following circuit deals with warning on record holes (gaps). We
10285 -- skip this check if overlap was detected, since it makes sense for the
10286 -- programmer to fix this illegality before worrying about warnings.
10288 if not Overlap_Detected and Warn_On_Record_Holes then
10289 Record_Hole_Check : declare
10290 Decl : constant Node_Id := Declaration_Node (Base_Type (Rectype));
10291 -- Full declaration of record type
10293 procedure Check_Component_List
10294 (CL : Node_Id;
10295 Sbit : Uint;
10296 DS : List_Id);
10297 -- Check component list CL for holes. The starting bit should be
10298 -- Sbit. which is zero for the main record component list and set
10299 -- appropriately for recursive calls for variants. DS is set to
10300 -- a list of discriminant specifications to be included in the
10301 -- consideration of components. It is No_List if none to consider.
10303 --------------------------
10304 -- Check_Component_List --
10305 --------------------------
10307 procedure Check_Component_List
10308 (CL : Node_Id;
10309 Sbit : Uint;
10310 DS : List_Id)
10312 Compl : Integer;
10314 begin
10315 Compl := Integer (List_Length (Component_Items (CL)));
10317 if DS /= No_List then
10318 Compl := Compl + Integer (List_Length (DS));
10319 end if;
10321 declare
10322 Comps : array (Natural range 0 .. Compl) of Entity_Id;
10323 -- Gather components (zero entry is for sort routine)
10325 Ncomps : Natural := 0;
10326 -- Number of entries stored in Comps (starting at Comps (1))
10328 Citem : Node_Id;
10329 -- One component item or discriminant specification
10331 Nbit : Uint;
10332 -- Starting bit for next component
10334 CEnt : Entity_Id;
10335 -- Component entity
10337 Variant : Node_Id;
10338 -- One variant
10340 function Lt (Op1, Op2 : Natural) return Boolean;
10341 -- Compare routine for Sort
10343 procedure Move (From : Natural; To : Natural);
10344 -- Move routine for Sort
10346 package Sorting is new GNAT.Heap_Sort_G (Move, Lt);
10348 --------
10349 -- Lt --
10350 --------
10352 function Lt (Op1, Op2 : Natural) return Boolean is
10353 begin
10354 return Component_Bit_Offset (Comps (Op1))
10356 Component_Bit_Offset (Comps (Op2));
10357 end Lt;
10359 ----------
10360 -- Move --
10361 ----------
10363 procedure Move (From : Natural; To : Natural) is
10364 begin
10365 Comps (To) := Comps (From);
10366 end Move;
10368 begin
10369 -- Gather discriminants into Comp
10371 if DS /= No_List then
10372 Citem := First (DS);
10373 while Present (Citem) loop
10374 if Nkind (Citem) = N_Discriminant_Specification then
10375 declare
10376 Ent : constant Entity_Id :=
10377 Defining_Identifier (Citem);
10378 begin
10379 if Ekind (Ent) = E_Discriminant then
10380 Ncomps := Ncomps + 1;
10381 Comps (Ncomps) := Ent;
10382 end if;
10383 end;
10384 end if;
10386 Next (Citem);
10387 end loop;
10388 end if;
10390 -- Gather component entities into Comp
10392 Citem := First (Component_Items (CL));
10393 while Present (Citem) loop
10394 if Nkind (Citem) = N_Component_Declaration then
10395 Ncomps := Ncomps + 1;
10396 Comps (Ncomps) := Defining_Identifier (Citem);
10397 end if;
10399 Next (Citem);
10400 end loop;
10402 -- Now sort the component entities based on the first bit.
10403 -- Note we already know there are no overlapping components.
10405 Sorting.Sort (Ncomps);
10407 -- Loop through entries checking for holes
10409 Nbit := Sbit;
10410 for J in 1 .. Ncomps loop
10411 CEnt := Comps (J);
10413 declare
10414 CBO : constant Uint := Component_Bit_Offset (CEnt);
10416 begin
10417 -- Skip components with unknown offsets
10419 if CBO /= No_Uint and then CBO >= 0 then
10420 Error_Msg_Uint_1 := CBO - Nbit;
10422 if Error_Msg_Uint_1 > 0 then
10423 Error_Msg_NE
10424 ("?H?^-bit gap before component&",
10425 Component_Name (Component_Clause (CEnt)),
10426 CEnt);
10427 end if;
10429 Nbit := CBO + Esize (CEnt);
10430 end if;
10431 end;
10432 end loop;
10434 -- Process variant parts recursively if present
10436 if Present (Variant_Part (CL)) then
10437 Variant := First (Variants (Variant_Part (CL)));
10438 while Present (Variant) loop
10439 Check_Component_List
10440 (Component_List (Variant), Nbit, No_List);
10441 Next (Variant);
10442 end loop;
10443 end if;
10444 end;
10445 end Check_Component_List;
10447 -- Start of processing for Record_Hole_Check
10449 begin
10450 declare
10451 Sbit : Uint;
10453 begin
10454 if Is_Tagged_Type (Rectype) then
10455 Sbit := UI_From_Int (System_Address_Size);
10456 else
10457 Sbit := Uint_0;
10458 end if;
10460 if Nkind (Decl) = N_Full_Type_Declaration
10461 and then Nkind (Type_Definition (Decl)) = N_Record_Definition
10462 then
10463 Check_Component_List
10464 (Component_List (Type_Definition (Decl)),
10465 Sbit,
10466 Discriminant_Specifications (Decl));
10467 end if;
10468 end;
10469 end Record_Hole_Check;
10470 end if;
10472 -- For records that have component clauses for all components, and whose
10473 -- size is less than or equal to 32, we need to know the size in the
10474 -- front end to activate possible packed array processing where the
10475 -- component type is a record.
10477 -- At this stage Hbit + 1 represents the first unused bit from all the
10478 -- component clauses processed, so if the component clauses are
10479 -- complete, then this is the length of the record.
10481 -- For records longer than System.Storage_Unit, and for those where not
10482 -- all components have component clauses, the back end determines the
10483 -- length (it may for example be appropriate to round up the size
10484 -- to some convenient boundary, based on alignment considerations, etc).
10486 if Unknown_RM_Size (Rectype) and then Hbit + 1 <= 32 then
10488 -- Nothing to do if at least one component has no component clause
10490 Comp := First_Component_Or_Discriminant (Rectype);
10491 while Present (Comp) loop
10492 exit when No (Component_Clause (Comp));
10493 Next_Component_Or_Discriminant (Comp);
10494 end loop;
10496 -- If we fall out of loop, all components have component clauses
10497 -- and so we can set the size to the maximum value.
10499 if No (Comp) then
10500 Set_RM_Size (Rectype, Hbit + 1);
10501 end if;
10502 end if;
10503 end Check_Record_Representation_Clause;
10505 ----------------
10506 -- Check_Size --
10507 ----------------
10509 procedure Check_Size
10510 (N : Node_Id;
10511 T : Entity_Id;
10512 Siz : Uint;
10513 Biased : out Boolean)
10515 procedure Size_Too_Small_Error (Min_Siz : Uint);
10516 -- Emit an error concerning illegal size Siz. Min_Siz denotes the
10517 -- minimum size.
10519 --------------------------
10520 -- Size_Too_Small_Error --
10521 --------------------------
10523 procedure Size_Too_Small_Error (Min_Siz : Uint) is
10524 begin
10525 -- This error is suppressed in ASIS mode to allow for different ASIS
10526 -- back ends or ASIS-based tools to query the illegal clause.
10528 if not ASIS_Mode then
10529 Error_Msg_Uint_1 := Min_Siz;
10530 Error_Msg_NE ("size for& too small, minimum allowed is ^", N, T);
10531 end if;
10532 end Size_Too_Small_Error;
10534 -- Local variables
10536 UT : constant Entity_Id := Underlying_Type (T);
10537 M : Uint;
10539 -- Start of processing for Check_Size
10541 begin
10542 Biased := False;
10544 -- Reject patently improper size values
10546 if Is_Elementary_Type (T)
10547 and then Siz > UI_From_Int (Int'Last)
10548 then
10549 Error_Msg_N ("Size value too large for elementary type", N);
10551 if Nkind (Original_Node (N)) = N_Op_Expon then
10552 Error_Msg_N
10553 ("\maybe '* was meant, rather than '*'*", Original_Node (N));
10554 end if;
10555 end if;
10557 -- Dismiss generic types
10559 if Is_Generic_Type (T)
10560 or else
10561 Is_Generic_Type (UT)
10562 or else
10563 Is_Generic_Type (Root_Type (UT))
10564 then
10565 return;
10567 -- Guard against previous errors
10569 elsif No (UT) or else UT = Any_Type then
10570 Check_Error_Detected;
10571 return;
10573 -- Check case of bit packed array
10575 elsif Is_Array_Type (UT)
10576 and then Known_Static_Component_Size (UT)
10577 and then Is_Bit_Packed_Array (UT)
10578 then
10579 declare
10580 Asiz : Uint;
10581 Indx : Node_Id;
10582 Ityp : Entity_Id;
10584 begin
10585 Asiz := Component_Size (UT);
10586 Indx := First_Index (UT);
10587 loop
10588 Ityp := Etype (Indx);
10590 -- If non-static bound, then we are not in the business of
10591 -- trying to check the length, and indeed an error will be
10592 -- issued elsewhere, since sizes of non-static array types
10593 -- cannot be set implicitly or explicitly.
10595 if not Is_OK_Static_Subtype (Ityp) then
10596 return;
10597 end if;
10599 -- Otherwise accumulate next dimension
10601 Asiz := Asiz * (Expr_Value (Type_High_Bound (Ityp)) -
10602 Expr_Value (Type_Low_Bound (Ityp)) +
10603 Uint_1);
10605 Next_Index (Indx);
10606 exit when No (Indx);
10607 end loop;
10609 if Asiz <= Siz then
10610 return;
10612 else
10613 Size_Too_Small_Error (Asiz);
10614 Set_Esize (T, Asiz);
10615 Set_RM_Size (T, Asiz);
10616 end if;
10617 end;
10619 -- All other composite types are ignored
10621 elsif Is_Composite_Type (UT) then
10622 return;
10624 -- For fixed-point types, don't check minimum if type is not frozen,
10625 -- since we don't know all the characteristics of the type that can
10626 -- affect the size (e.g. a specified small) till freeze time.
10628 elsif Is_Fixed_Point_Type (UT) and then not Is_Frozen (UT) then
10629 null;
10631 -- Cases for which a minimum check is required
10633 else
10634 -- Ignore if specified size is correct for the type
10636 if Known_Esize (UT) and then Siz = Esize (UT) then
10637 return;
10638 end if;
10640 -- Otherwise get minimum size
10642 M := UI_From_Int (Minimum_Size (UT));
10644 if Siz < M then
10646 -- Size is less than minimum size, but one possibility remains
10647 -- that we can manage with the new size if we bias the type.
10649 M := UI_From_Int (Minimum_Size (UT, Biased => True));
10651 if Siz < M then
10652 Size_Too_Small_Error (M);
10653 Set_Esize (T, M);
10654 Set_RM_Size (T, M);
10655 else
10656 Biased := True;
10657 end if;
10658 end if;
10659 end if;
10660 end Check_Size;
10662 --------------------------
10663 -- Freeze_Entity_Checks --
10664 --------------------------
10666 procedure Freeze_Entity_Checks (N : Node_Id) is
10667 procedure Hide_Non_Overridden_Subprograms (Typ : Entity_Id);
10668 -- Inspect the primitive operations of type Typ and hide all pairs of
10669 -- implicitly declared non-overridden non-fully conformant homographs
10670 -- (Ada RM 8.3 12.3/2).
10672 -------------------------------------
10673 -- Hide_Non_Overridden_Subprograms --
10674 -------------------------------------
10676 procedure Hide_Non_Overridden_Subprograms (Typ : Entity_Id) is
10677 procedure Hide_Matching_Homographs
10678 (Subp_Id : Entity_Id;
10679 Start_Elmt : Elmt_Id);
10680 -- Inspect a list of primitive operations starting with Start_Elmt
10681 -- and find matching implicitly declared non-overridden non-fully
10682 -- conformant homographs of Subp_Id. If found, all matches along
10683 -- with Subp_Id are hidden from all visibility.
10685 function Is_Non_Overridden_Or_Null_Procedure
10686 (Subp_Id : Entity_Id) return Boolean;
10687 -- Determine whether subprogram Subp_Id is implicitly declared non-
10688 -- overridden subprogram or an implicitly declared null procedure.
10690 ------------------------------
10691 -- Hide_Matching_Homographs --
10692 ------------------------------
10694 procedure Hide_Matching_Homographs
10695 (Subp_Id : Entity_Id;
10696 Start_Elmt : Elmt_Id)
10698 Prim : Entity_Id;
10699 Prim_Elmt : Elmt_Id;
10701 begin
10702 Prim_Elmt := Start_Elmt;
10703 while Present (Prim_Elmt) loop
10704 Prim := Node (Prim_Elmt);
10706 -- The current primitive is implicitly declared non-overridden
10707 -- non-fully conformant homograph of Subp_Id. Both subprograms
10708 -- must be hidden from visibility.
10710 if Chars (Prim) = Chars (Subp_Id)
10711 and then Is_Non_Overridden_Or_Null_Procedure (Prim)
10712 and then not Fully_Conformant (Prim, Subp_Id)
10713 then
10714 Set_Is_Hidden_Non_Overridden_Subpgm (Prim);
10715 Set_Is_Immediately_Visible (Prim, False);
10716 Set_Is_Potentially_Use_Visible (Prim, False);
10718 Set_Is_Hidden_Non_Overridden_Subpgm (Subp_Id);
10719 Set_Is_Immediately_Visible (Subp_Id, False);
10720 Set_Is_Potentially_Use_Visible (Subp_Id, False);
10721 end if;
10723 Next_Elmt (Prim_Elmt);
10724 end loop;
10725 end Hide_Matching_Homographs;
10727 -----------------------------------------
10728 -- Is_Non_Overridden_Or_Null_Procedure --
10729 -----------------------------------------
10731 function Is_Non_Overridden_Or_Null_Procedure
10732 (Subp_Id : Entity_Id) return Boolean
10734 Alias_Id : Entity_Id;
10736 begin
10737 -- The subprogram is inherited (implicitly declared), it does not
10738 -- override and does not cover a primitive of an interface.
10740 if Ekind_In (Subp_Id, E_Function, E_Procedure)
10741 and then Present (Alias (Subp_Id))
10742 and then No (Interface_Alias (Subp_Id))
10743 and then No (Overridden_Operation (Subp_Id))
10744 then
10745 Alias_Id := Alias (Subp_Id);
10747 if Requires_Overriding (Alias_Id) then
10748 return True;
10750 elsif Nkind (Parent (Alias_Id)) = N_Procedure_Specification
10751 and then Null_Present (Parent (Alias_Id))
10752 then
10753 return True;
10754 end if;
10755 end if;
10757 return False;
10758 end Is_Non_Overridden_Or_Null_Procedure;
10760 -- Local variables
10762 Prim_Ops : constant Elist_Id := Direct_Primitive_Operations (Typ);
10763 Prim : Entity_Id;
10764 Prim_Elmt : Elmt_Id;
10766 -- Start of processing for Hide_Non_Overridden_Subprograms
10768 begin
10769 -- Inspect the list of primitives looking for non-overridden
10770 -- subprograms.
10772 if Present (Prim_Ops) then
10773 Prim_Elmt := First_Elmt (Prim_Ops);
10774 while Present (Prim_Elmt) loop
10775 Prim := Node (Prim_Elmt);
10776 Next_Elmt (Prim_Elmt);
10778 if Is_Non_Overridden_Or_Null_Procedure (Prim) then
10779 Hide_Matching_Homographs
10780 (Subp_Id => Prim,
10781 Start_Elmt => Prim_Elmt);
10782 end if;
10783 end loop;
10784 end if;
10785 end Hide_Non_Overridden_Subprograms;
10787 -- Local variables
10789 E : constant Entity_Id := Entity (N);
10791 Non_Generic_Case : constant Boolean := Nkind (N) = N_Freeze_Entity;
10792 -- True in non-generic case. Some of the processing here is skipped
10793 -- for the generic case since it is not needed. Basically in the
10794 -- generic case, we only need to do stuff that might generate error
10795 -- messages or warnings.
10797 -- Start of processing for Freeze_Entity_Checks
10799 begin
10800 -- Remember that we are processing a freezing entity. Required to
10801 -- ensure correct decoration of internal entities associated with
10802 -- interfaces (see New_Overloaded_Entity).
10804 Inside_Freezing_Actions := Inside_Freezing_Actions + 1;
10806 -- For tagged types covering interfaces add internal entities that link
10807 -- the primitives of the interfaces with the primitives that cover them.
10808 -- Note: These entities were originally generated only when generating
10809 -- code because their main purpose was to provide support to initialize
10810 -- the secondary dispatch tables. They are now generated also when
10811 -- compiling with no code generation to provide ASIS the relationship
10812 -- between interface primitives and tagged type primitives. They are
10813 -- also used to locate primitives covering interfaces when processing
10814 -- generics (see Derive_Subprograms).
10816 -- This is not needed in the generic case
10818 if Ada_Version >= Ada_2005
10819 and then Non_Generic_Case
10820 and then Ekind (E) = E_Record_Type
10821 and then Is_Tagged_Type (E)
10822 and then not Is_Interface (E)
10823 and then Has_Interfaces (E)
10824 then
10825 -- This would be a good common place to call the routine that checks
10826 -- overriding of interface primitives (and thus factorize calls to
10827 -- Check_Abstract_Overriding located at different contexts in the
10828 -- compiler). However, this is not possible because it causes
10829 -- spurious errors in case of late overriding.
10831 Add_Internal_Interface_Entities (E);
10832 end if;
10834 -- After all forms of overriding have been resolved, a tagged type may
10835 -- be left with a set of implicitly declared and possibly erroneous
10836 -- abstract subprograms, null procedures and subprograms that require
10837 -- overriding. If this set contains fully conformant homographs, then
10838 -- one is chosen arbitrarily (already done during resolution), otherwise
10839 -- all remaining non-fully conformant homographs are hidden from
10840 -- visibility (Ada RM 8.3 12.3/2).
10842 if Is_Tagged_Type (E) then
10843 Hide_Non_Overridden_Subprograms (E);
10844 end if;
10846 -- Check CPP types
10848 if Ekind (E) = E_Record_Type
10849 and then Is_CPP_Class (E)
10850 and then Is_Tagged_Type (E)
10851 and then Tagged_Type_Expansion
10852 then
10853 if CPP_Num_Prims (E) = 0 then
10855 -- If the CPP type has user defined components then it must import
10856 -- primitives from C++. This is required because if the C++ class
10857 -- has no primitives then the C++ compiler does not added the _tag
10858 -- component to the type.
10860 if First_Entity (E) /= Last_Entity (E) then
10861 Error_Msg_N
10862 ("'C'P'P type must import at least one primitive from C++??",
10864 end if;
10865 end if;
10867 -- Check that all its primitives are abstract or imported from C++.
10868 -- Check also availability of the C++ constructor.
10870 declare
10871 Has_Constructors : constant Boolean := Has_CPP_Constructors (E);
10872 Elmt : Elmt_Id;
10873 Error_Reported : Boolean := False;
10874 Prim : Node_Id;
10876 begin
10877 Elmt := First_Elmt (Primitive_Operations (E));
10878 while Present (Elmt) loop
10879 Prim := Node (Elmt);
10881 if Comes_From_Source (Prim) then
10882 if Is_Abstract_Subprogram (Prim) then
10883 null;
10885 elsif not Is_Imported (Prim)
10886 or else Convention (Prim) /= Convention_CPP
10887 then
10888 Error_Msg_N
10889 ("primitives of 'C'P'P types must be imported from C++ "
10890 & "or abstract??", Prim);
10892 elsif not Has_Constructors
10893 and then not Error_Reported
10894 then
10895 Error_Msg_Name_1 := Chars (E);
10896 Error_Msg_N
10897 ("??'C'P'P constructor required for type %", Prim);
10898 Error_Reported := True;
10899 end if;
10900 end if;
10902 Next_Elmt (Elmt);
10903 end loop;
10904 end;
10905 end if;
10907 -- Check Ada derivation of CPP type
10909 if Expander_Active -- why? losing errors in -gnatc mode???
10910 and then Present (Etype (E)) -- defend against errors
10911 and then Tagged_Type_Expansion
10912 and then Ekind (E) = E_Record_Type
10913 and then Etype (E) /= E
10914 and then Is_CPP_Class (Etype (E))
10915 and then CPP_Num_Prims (Etype (E)) > 0
10916 and then not Is_CPP_Class (E)
10917 and then not Has_CPP_Constructors (Etype (E))
10918 then
10919 -- If the parent has C++ primitives but it has no constructor then
10920 -- check that all the primitives are overridden in this derivation;
10921 -- otherwise the constructor of the parent is needed to build the
10922 -- dispatch table.
10924 declare
10925 Elmt : Elmt_Id;
10926 Prim : Node_Id;
10928 begin
10929 Elmt := First_Elmt (Primitive_Operations (E));
10930 while Present (Elmt) loop
10931 Prim := Node (Elmt);
10933 if not Is_Abstract_Subprogram (Prim)
10934 and then No (Interface_Alias (Prim))
10935 and then Find_Dispatching_Type (Ultimate_Alias (Prim)) /= E
10936 then
10937 Error_Msg_Name_1 := Chars (Etype (E));
10938 Error_Msg_N
10939 ("'C'P'P constructor required for parent type %", E);
10940 exit;
10941 end if;
10943 Next_Elmt (Elmt);
10944 end loop;
10945 end;
10946 end if;
10948 Inside_Freezing_Actions := Inside_Freezing_Actions - 1;
10950 -- If we have a type with predicates, build predicate function. This is
10951 -- not needed in the generic case, nor within TSS subprograms and other
10952 -- predefined primitives.
10954 if Is_Type (E)
10955 and then Non_Generic_Case
10956 and then not Within_Internal_Subprogram
10957 and then Has_Predicates (E)
10958 then
10959 Build_Predicate_Functions (E, N);
10960 end if;
10962 -- If type has delayed aspects, this is where we do the preanalysis at
10963 -- the freeze point, as part of the consistent visibility check. Note
10964 -- that this must be done after calling Build_Predicate_Functions or
10965 -- Build_Invariant_Procedure since these subprograms fix occurrences of
10966 -- the subtype name in the saved expression so that they will not cause
10967 -- trouble in the preanalysis.
10969 -- This is also not needed in the generic case
10971 if Non_Generic_Case
10972 and then Has_Delayed_Aspects (E)
10973 and then Scope (E) = Current_Scope
10974 then
10975 -- Retrieve the visibility to the discriminants in order to properly
10976 -- analyze the aspects.
10978 Push_Scope_And_Install_Discriminants (E);
10980 declare
10981 Ritem : Node_Id;
10983 begin
10984 -- Look for aspect specification entries for this entity
10986 Ritem := First_Rep_Item (E);
10987 while Present (Ritem) loop
10988 if Nkind (Ritem) = N_Aspect_Specification
10989 and then Entity (Ritem) = E
10990 and then Is_Delayed_Aspect (Ritem)
10991 then
10992 Check_Aspect_At_Freeze_Point (Ritem);
10993 end if;
10995 Next_Rep_Item (Ritem);
10996 end loop;
10997 end;
10999 Uninstall_Discriminants_And_Pop_Scope (E);
11000 end if;
11002 -- For a record type, deal with variant parts. This has to be delayed
11003 -- to this point, because of the issue of statically predicated
11004 -- subtypes, which we have to ensure are frozen before checking
11005 -- choices, since we need to have the static choice list set.
11007 if Is_Record_Type (E) then
11008 Check_Variant_Part : declare
11009 D : constant Node_Id := Declaration_Node (E);
11010 T : Node_Id;
11011 C : Node_Id;
11012 VP : Node_Id;
11014 Others_Present : Boolean;
11015 pragma Warnings (Off, Others_Present);
11016 -- Indicates others present, not used in this case
11018 procedure Non_Static_Choice_Error (Choice : Node_Id);
11019 -- Error routine invoked by the generic instantiation below when
11020 -- the variant part has a non static choice.
11022 procedure Process_Declarations (Variant : Node_Id);
11023 -- Processes declarations associated with a variant. We analyzed
11024 -- the declarations earlier (in Sem_Ch3.Analyze_Variant_Part),
11025 -- but we still need the recursive call to Check_Choices for any
11026 -- nested variant to get its choices properly processed. This is
11027 -- also where we expand out the choices if expansion is active.
11029 package Variant_Choices_Processing is new
11030 Generic_Check_Choices
11031 (Process_Empty_Choice => No_OP,
11032 Process_Non_Static_Choice => Non_Static_Choice_Error,
11033 Process_Associated_Node => Process_Declarations);
11034 use Variant_Choices_Processing;
11036 -----------------------------
11037 -- Non_Static_Choice_Error --
11038 -----------------------------
11040 procedure Non_Static_Choice_Error (Choice : Node_Id) is
11041 begin
11042 Flag_Non_Static_Expr
11043 ("choice given in variant part is not static!", Choice);
11044 end Non_Static_Choice_Error;
11046 --------------------------
11047 -- Process_Declarations --
11048 --------------------------
11050 procedure Process_Declarations (Variant : Node_Id) is
11051 CL : constant Node_Id := Component_List (Variant);
11052 VP : Node_Id;
11054 begin
11055 -- Check for static predicate present in this variant
11057 if Has_SP_Choice (Variant) then
11059 -- Here we expand. You might expect to find this call in
11060 -- Expand_N_Variant_Part, but that is called when we first
11061 -- see the variant part, and we cannot do this expansion
11062 -- earlier than the freeze point, since for statically
11063 -- predicated subtypes, the predicate is not known till
11064 -- the freeze point.
11066 -- Furthermore, we do this expansion even if the expander
11067 -- is not active, because other semantic processing, e.g.
11068 -- for aggregates, requires the expanded list of choices.
11070 -- If the expander is not active, then we can't just clobber
11071 -- the list since it would invalidate the ASIS -gnatct tree.
11072 -- So we have to rewrite the variant part with a Rewrite
11073 -- call that replaces it with a copy and clobber the copy.
11075 if not Expander_Active then
11076 declare
11077 NewV : constant Node_Id := New_Copy (Variant);
11078 begin
11079 Set_Discrete_Choices
11080 (NewV, New_Copy_List (Discrete_Choices (Variant)));
11081 Rewrite (Variant, NewV);
11082 end;
11083 end if;
11085 Expand_Static_Predicates_In_Choices (Variant);
11086 end if;
11088 -- We don't need to worry about the declarations in the variant
11089 -- (since they were analyzed by Analyze_Choices when we first
11090 -- encountered the variant), but we do need to take care of
11091 -- expansion of any nested variants.
11093 if not Null_Present (CL) then
11094 VP := Variant_Part (CL);
11096 if Present (VP) then
11097 Check_Choices
11098 (VP, Variants (VP), Etype (Name (VP)), Others_Present);
11099 end if;
11100 end if;
11101 end Process_Declarations;
11103 -- Start of processing for Check_Variant_Part
11105 begin
11106 -- Find component list
11108 C := Empty;
11110 if Nkind (D) = N_Full_Type_Declaration then
11111 T := Type_Definition (D);
11113 if Nkind (T) = N_Record_Definition then
11114 C := Component_List (T);
11116 elsif Nkind (T) = N_Derived_Type_Definition
11117 and then Present (Record_Extension_Part (T))
11118 then
11119 C := Component_List (Record_Extension_Part (T));
11120 end if;
11121 end if;
11123 -- Case of variant part present
11125 if Present (C) and then Present (Variant_Part (C)) then
11126 VP := Variant_Part (C);
11128 -- Check choices
11130 Check_Choices
11131 (VP, Variants (VP), Etype (Name (VP)), Others_Present);
11133 -- If the last variant does not contain the Others choice,
11134 -- replace it with an N_Others_Choice node since Gigi always
11135 -- wants an Others. Note that we do not bother to call Analyze
11136 -- on the modified variant part, since its only effect would be
11137 -- to compute the Others_Discrete_Choices node laboriously, and
11138 -- of course we already know the list of choices corresponding
11139 -- to the others choice (it's the list we're replacing).
11141 -- We only want to do this if the expander is active, since
11142 -- we do not want to clobber the ASIS tree.
11144 if Expander_Active then
11145 declare
11146 Last_Var : constant Node_Id :=
11147 Last_Non_Pragma (Variants (VP));
11149 Others_Node : Node_Id;
11151 begin
11152 if Nkind (First (Discrete_Choices (Last_Var))) /=
11153 N_Others_Choice
11154 then
11155 Others_Node := Make_Others_Choice (Sloc (Last_Var));
11156 Set_Others_Discrete_Choices
11157 (Others_Node, Discrete_Choices (Last_Var));
11158 Set_Discrete_Choices
11159 (Last_Var, New_List (Others_Node));
11160 end if;
11161 end;
11162 end if;
11163 end if;
11164 end Check_Variant_Part;
11165 end if;
11166 end Freeze_Entity_Checks;
11168 -------------------------
11169 -- Get_Alignment_Value --
11170 -------------------------
11172 function Get_Alignment_Value (Expr : Node_Id) return Uint is
11173 Align : constant Uint := Static_Integer (Expr);
11175 begin
11176 if Align = No_Uint then
11177 return No_Uint;
11179 elsif Align <= 0 then
11181 -- This error is suppressed in ASIS mode to allow for different ASIS
11182 -- back ends or ASIS-based tools to query the illegal clause.
11184 if not ASIS_Mode then
11185 Error_Msg_N ("alignment value must be positive", Expr);
11186 end if;
11188 return No_Uint;
11190 else
11191 for J in Int range 0 .. 64 loop
11192 declare
11193 M : constant Uint := Uint_2 ** J;
11195 begin
11196 exit when M = Align;
11198 if M > Align then
11200 -- This error is suppressed in ASIS mode to allow for
11201 -- different ASIS back ends or ASIS-based tools to query the
11202 -- illegal clause.
11204 if not ASIS_Mode then
11205 Error_Msg_N ("alignment value must be power of 2", Expr);
11206 end if;
11208 return No_Uint;
11209 end if;
11210 end;
11211 end loop;
11213 return Align;
11214 end if;
11215 end Get_Alignment_Value;
11217 -----------------------------
11218 -- Get_Interfacing_Aspects --
11219 -----------------------------
11221 procedure Get_Interfacing_Aspects
11222 (Iface_Asp : Node_Id;
11223 Conv_Asp : out Node_Id;
11224 EN_Asp : out Node_Id;
11225 Expo_Asp : out Node_Id;
11226 Imp_Asp : out Node_Id;
11227 LN_Asp : out Node_Id;
11228 Do_Checks : Boolean := False)
11230 procedure Save_Or_Duplication_Error
11231 (Asp : Node_Id;
11232 To : in out Node_Id);
11233 -- Save the value of aspect Asp in node To. If To already has a value,
11234 -- then this is considered a duplicate use of aspect. Emit an error if
11235 -- flag Do_Checks is set.
11237 -------------------------------
11238 -- Save_Or_Duplication_Error --
11239 -------------------------------
11241 procedure Save_Or_Duplication_Error
11242 (Asp : Node_Id;
11243 To : in out Node_Id)
11245 begin
11246 -- Detect an extra aspect and issue an error
11248 if Present (To) then
11249 if Do_Checks then
11250 Error_Msg_Name_1 := Chars (Identifier (Asp));
11251 Error_Msg_Sloc := Sloc (To);
11252 Error_Msg_N ("aspect % previously given #", Asp);
11253 end if;
11255 -- Otherwise capture the aspect
11257 else
11258 To := Asp;
11259 end if;
11260 end Save_Or_Duplication_Error;
11262 -- Local variables
11264 Asp : Node_Id;
11265 Asp_Id : Aspect_Id;
11267 -- The following variables capture each individual aspect
11269 Conv : Node_Id := Empty;
11270 EN : Node_Id := Empty;
11271 Expo : Node_Id := Empty;
11272 Imp : Node_Id := Empty;
11273 LN : Node_Id := Empty;
11275 -- Start of processing for Get_Interfacing_Aspects
11277 begin
11278 -- The input interfacing aspect should reside in an aspect specification
11279 -- list.
11281 pragma Assert (Is_List_Member (Iface_Asp));
11283 -- Examine the aspect specifications of the related entity. Find and
11284 -- capture all interfacing aspects. Detect duplicates and emit errors
11285 -- if applicable.
11287 Asp := First (List_Containing (Iface_Asp));
11288 while Present (Asp) loop
11289 Asp_Id := Get_Aspect_Id (Asp);
11291 if Asp_Id = Aspect_Convention then
11292 Save_Or_Duplication_Error (Asp, Conv);
11294 elsif Asp_Id = Aspect_External_Name then
11295 Save_Or_Duplication_Error (Asp, EN);
11297 elsif Asp_Id = Aspect_Export then
11298 Save_Or_Duplication_Error (Asp, Expo);
11300 elsif Asp_Id = Aspect_Import then
11301 Save_Or_Duplication_Error (Asp, Imp);
11303 elsif Asp_Id = Aspect_Link_Name then
11304 Save_Or_Duplication_Error (Asp, LN);
11305 end if;
11307 Next (Asp);
11308 end loop;
11310 Conv_Asp := Conv;
11311 EN_Asp := EN;
11312 Expo_Asp := Expo;
11313 Imp_Asp := Imp;
11314 LN_Asp := LN;
11315 end Get_Interfacing_Aspects;
11317 -------------------------------------
11318 -- Inherit_Aspects_At_Freeze_Point --
11319 -------------------------------------
11321 procedure Inherit_Aspects_At_Freeze_Point (Typ : Entity_Id) is
11322 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11323 (Rep_Item : Node_Id) return Boolean;
11324 -- This routine checks if Rep_Item is either a pragma or an aspect
11325 -- specification node whose correponding pragma (if any) is present in
11326 -- the Rep Item chain of the entity it has been specified to.
11328 --------------------------------------------------
11329 -- Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item --
11330 --------------------------------------------------
11332 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11333 (Rep_Item : Node_Id) return Boolean
11335 begin
11336 return
11337 Nkind (Rep_Item) = N_Pragma
11338 or else Present_In_Rep_Item
11339 (Entity (Rep_Item), Aspect_Rep_Item (Rep_Item));
11340 end Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item;
11342 -- Start of processing for Inherit_Aspects_At_Freeze_Point
11344 begin
11345 -- A representation item is either subtype-specific (Size and Alignment
11346 -- clauses) or type-related (all others). Subtype-specific aspects may
11347 -- differ for different subtypes of the same type (RM 13.1.8).
11349 -- A derived type inherits each type-related representation aspect of
11350 -- its parent type that was directly specified before the declaration of
11351 -- the derived type (RM 13.1.15).
11353 -- A derived subtype inherits each subtype-specific representation
11354 -- aspect of its parent subtype that was directly specified before the
11355 -- declaration of the derived type (RM 13.1.15).
11357 -- The general processing involves inheriting a representation aspect
11358 -- from a parent type whenever the first rep item (aspect specification,
11359 -- attribute definition clause, pragma) corresponding to the given
11360 -- representation aspect in the rep item chain of Typ, if any, isn't
11361 -- directly specified to Typ but to one of its parents.
11363 -- ??? Note that, for now, just a limited number of representation
11364 -- aspects have been inherited here so far. Many of them are
11365 -- still inherited in Sem_Ch3. This will be fixed soon. Here is
11366 -- a non- exhaustive list of aspects that likely also need to
11367 -- be moved to this routine: Alignment, Component_Alignment,
11368 -- Component_Size, Machine_Radix, Object_Size, Pack, Predicates,
11369 -- Preelaborable_Initialization, RM_Size and Small.
11371 -- In addition, Convention must be propagated from base type to subtype,
11372 -- because the subtype may have been declared on an incomplete view.
11374 if Nkind (Parent (Typ)) = N_Private_Extension_Declaration then
11375 return;
11376 end if;
11378 -- Ada_05/Ada_2005
11380 if not Has_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005, False)
11381 and then Has_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005)
11382 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11383 (Get_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005))
11384 then
11385 Set_Is_Ada_2005_Only (Typ);
11386 end if;
11388 -- Ada_12/Ada_2012
11390 if not Has_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012, False)
11391 and then Has_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012)
11392 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11393 (Get_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012))
11394 then
11395 Set_Is_Ada_2012_Only (Typ);
11396 end if;
11398 -- Atomic/Shared
11400 if not Has_Rep_Item (Typ, Name_Atomic, Name_Shared, False)
11401 and then Has_Rep_Pragma (Typ, Name_Atomic, Name_Shared)
11402 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11403 (Get_Rep_Item (Typ, Name_Atomic, Name_Shared))
11404 then
11405 Set_Is_Atomic (Typ);
11406 Set_Is_Volatile (Typ);
11407 Set_Treat_As_Volatile (Typ);
11408 end if;
11410 -- Convention
11412 if Is_Record_Type (Typ)
11413 and then Typ /= Base_Type (Typ) and then Is_Frozen (Base_Type (Typ))
11414 then
11415 Set_Convention (Typ, Convention (Base_Type (Typ)));
11416 end if;
11418 -- Default_Component_Value
11420 -- Verify that there is no rep_item declared for the type, and there
11421 -- is one coming from an ancestor.
11423 if Is_Array_Type (Typ)
11424 and then Is_Base_Type (Typ)
11425 and then not Has_Rep_Item (Typ, Name_Default_Component_Value, False)
11426 and then Has_Rep_Item (Typ, Name_Default_Component_Value)
11427 then
11428 Set_Default_Aspect_Component_Value (Typ,
11429 Default_Aspect_Component_Value
11430 (Entity (Get_Rep_Item (Typ, Name_Default_Component_Value))));
11431 end if;
11433 -- Default_Value
11435 if Is_Scalar_Type (Typ)
11436 and then Is_Base_Type (Typ)
11437 and then not Has_Rep_Item (Typ, Name_Default_Value, False)
11438 and then Has_Rep_Item (Typ, Name_Default_Value)
11439 then
11440 Set_Has_Default_Aspect (Typ);
11441 Set_Default_Aspect_Value (Typ,
11442 Default_Aspect_Value
11443 (Entity (Get_Rep_Item (Typ, Name_Default_Value))));
11444 end if;
11446 -- Discard_Names
11448 if not Has_Rep_Item (Typ, Name_Discard_Names, False)
11449 and then Has_Rep_Item (Typ, Name_Discard_Names)
11450 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11451 (Get_Rep_Item (Typ, Name_Discard_Names))
11452 then
11453 Set_Discard_Names (Typ);
11454 end if;
11456 -- Volatile
11458 if not Has_Rep_Item (Typ, Name_Volatile, False)
11459 and then Has_Rep_Item (Typ, Name_Volatile)
11460 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11461 (Get_Rep_Item (Typ, Name_Volatile))
11462 then
11463 Set_Is_Volatile (Typ);
11464 Set_Treat_As_Volatile (Typ);
11465 end if;
11467 -- Volatile_Full_Access
11469 if not Has_Rep_Item (Typ, Name_Volatile_Full_Access, False)
11470 and then Has_Rep_Pragma (Typ, Name_Volatile_Full_Access)
11471 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11472 (Get_Rep_Item (Typ, Name_Volatile_Full_Access))
11473 then
11474 Set_Is_Volatile_Full_Access (Typ);
11475 Set_Is_Volatile (Typ);
11476 Set_Treat_As_Volatile (Typ);
11477 end if;
11479 -- Inheritance for derived types only
11481 if Is_Derived_Type (Typ) then
11482 declare
11483 Bas_Typ : constant Entity_Id := Base_Type (Typ);
11484 Imp_Bas_Typ : constant Entity_Id := Implementation_Base_Type (Typ);
11486 begin
11487 -- Atomic_Components
11489 if not Has_Rep_Item (Typ, Name_Atomic_Components, False)
11490 and then Has_Rep_Item (Typ, Name_Atomic_Components)
11491 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11492 (Get_Rep_Item (Typ, Name_Atomic_Components))
11493 then
11494 Set_Has_Atomic_Components (Imp_Bas_Typ);
11495 end if;
11497 -- Volatile_Components
11499 if not Has_Rep_Item (Typ, Name_Volatile_Components, False)
11500 and then Has_Rep_Item (Typ, Name_Volatile_Components)
11501 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11502 (Get_Rep_Item (Typ, Name_Volatile_Components))
11503 then
11504 Set_Has_Volatile_Components (Imp_Bas_Typ);
11505 end if;
11507 -- Finalize_Storage_Only
11509 if not Has_Rep_Pragma (Typ, Name_Finalize_Storage_Only, False)
11510 and then Has_Rep_Pragma (Typ, Name_Finalize_Storage_Only)
11511 then
11512 Set_Finalize_Storage_Only (Bas_Typ);
11513 end if;
11515 -- Universal_Aliasing
11517 if not Has_Rep_Item (Typ, Name_Universal_Aliasing, False)
11518 and then Has_Rep_Item (Typ, Name_Universal_Aliasing)
11519 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11520 (Get_Rep_Item (Typ, Name_Universal_Aliasing))
11521 then
11522 Set_Universal_Aliasing (Imp_Bas_Typ);
11523 end if;
11525 -- Bit_Order
11527 if Is_Record_Type (Typ) then
11528 if not Has_Rep_Item (Typ, Name_Bit_Order, False)
11529 and then Has_Rep_Item (Typ, Name_Bit_Order)
11530 then
11531 Set_Reverse_Bit_Order (Bas_Typ,
11532 Reverse_Bit_Order (Entity (Name
11533 (Get_Rep_Item (Typ, Name_Bit_Order)))));
11534 end if;
11535 end if;
11537 -- Scalar_Storage_Order
11539 -- Note: the aspect is specified on a first subtype, but recorded
11540 -- in a flag of the base type!
11542 if (Is_Record_Type (Typ) or else Is_Array_Type (Typ))
11543 and then Typ = Bas_Typ
11544 then
11545 -- For a type extension, always inherit from parent; otherwise
11546 -- inherit if no default applies. Note: we do not check for
11547 -- an explicit rep item on the parent type when inheriting,
11548 -- because the parent SSO may itself have been set by default.
11550 if not Has_Rep_Item (First_Subtype (Typ),
11551 Name_Scalar_Storage_Order, False)
11552 and then (Is_Tagged_Type (Bas_Typ)
11553 or else not (SSO_Set_Low_By_Default (Bas_Typ)
11554 or else
11555 SSO_Set_High_By_Default (Bas_Typ)))
11556 then
11557 Set_Reverse_Storage_Order (Bas_Typ,
11558 Reverse_Storage_Order
11559 (Implementation_Base_Type (Etype (Bas_Typ))));
11561 -- Clear default SSO indications, since the inherited aspect
11562 -- which was set explicitly overrides the default.
11564 Set_SSO_Set_Low_By_Default (Bas_Typ, False);
11565 Set_SSO_Set_High_By_Default (Bas_Typ, False);
11566 end if;
11567 end if;
11568 end;
11569 end if;
11570 end Inherit_Aspects_At_Freeze_Point;
11572 ----------------
11573 -- Initialize --
11574 ----------------
11576 procedure Initialize is
11577 begin
11578 Address_Clause_Checks.Init;
11579 Compile_Time_Warnings_Errors.Init;
11580 Unchecked_Conversions.Init;
11582 if AAMP_On_Target then
11583 Independence_Checks.Init;
11584 end if;
11585 end Initialize;
11587 ---------------------------
11588 -- Install_Discriminants --
11589 ---------------------------
11591 procedure Install_Discriminants (E : Entity_Id) is
11592 Disc : Entity_Id;
11593 Prev : Entity_Id;
11594 begin
11595 Disc := First_Discriminant (E);
11596 while Present (Disc) loop
11597 Prev := Current_Entity (Disc);
11598 Set_Current_Entity (Disc);
11599 Set_Is_Immediately_Visible (Disc);
11600 Set_Homonym (Disc, Prev);
11601 Next_Discriminant (Disc);
11602 end loop;
11603 end Install_Discriminants;
11605 -------------------------
11606 -- Is_Operational_Item --
11607 -------------------------
11609 function Is_Operational_Item (N : Node_Id) return Boolean is
11610 begin
11611 if Nkind (N) /= N_Attribute_Definition_Clause then
11612 return False;
11614 else
11615 declare
11616 Id : constant Attribute_Id := Get_Attribute_Id (Chars (N));
11617 begin
11619 -- List of operational items is given in AARM 13.1(8.mm/1).
11620 -- It is clearly incomplete, as it does not include iterator
11621 -- aspects, among others.
11623 return Id = Attribute_Constant_Indexing
11624 or else Id = Attribute_Default_Iterator
11625 or else Id = Attribute_Implicit_Dereference
11626 or else Id = Attribute_Input
11627 or else Id = Attribute_Iterator_Element
11628 or else Id = Attribute_Iterable
11629 or else Id = Attribute_Output
11630 or else Id = Attribute_Read
11631 or else Id = Attribute_Variable_Indexing
11632 or else Id = Attribute_Write
11633 or else Id = Attribute_External_Tag;
11634 end;
11635 end if;
11636 end Is_Operational_Item;
11638 -------------------------
11639 -- Is_Predicate_Static --
11640 -------------------------
11642 -- Note: the basic legality of the expression has already been checked, so
11643 -- we don't need to worry about cases or ranges on strings for example.
11645 function Is_Predicate_Static
11646 (Expr : Node_Id;
11647 Nam : Name_Id) return Boolean
11649 function All_Static_Case_Alternatives (L : List_Id) return Boolean;
11650 -- Given a list of case expression alternatives, returns True if all
11651 -- the alternatives are static (have all static choices, and a static
11652 -- expression).
11654 function All_Static_Choices (L : List_Id) return Boolean;
11655 -- Returns true if all elements of the list are OK static choices
11656 -- as defined below for Is_Static_Choice. Used for case expression
11657 -- alternatives and for the right operand of a membership test. An
11658 -- others_choice is static if the corresponding expression is static.
11659 -- The staticness of the bounds is checked separately.
11661 function Is_Static_Choice (N : Node_Id) return Boolean;
11662 -- Returns True if N represents a static choice (static subtype, or
11663 -- static subtype indication, or static expression, or static range).
11665 -- Note that this is a bit more inclusive than we actually need
11666 -- (in particular membership tests do not allow the use of subtype
11667 -- indications). But that doesn't matter, we have already checked
11668 -- that the construct is legal to get this far.
11670 function Is_Type_Ref (N : Node_Id) return Boolean;
11671 pragma Inline (Is_Type_Ref);
11672 -- Returns True if N is a reference to the type for the predicate in the
11673 -- expression (i.e. if it is an identifier whose Chars field matches the
11674 -- Nam given in the call). N must not be parenthesized, if the type name
11675 -- appears in parens, this routine will return False.
11677 -- The routine also returns True for function calls generated during the
11678 -- expansion of comparison operators on strings, which are intended to
11679 -- be legal in static predicates, and are converted into calls to array
11680 -- comparison routines in the body of the corresponding predicate
11681 -- function.
11683 ----------------------------------
11684 -- All_Static_Case_Alternatives --
11685 ----------------------------------
11687 function All_Static_Case_Alternatives (L : List_Id) return Boolean is
11688 N : Node_Id;
11690 begin
11691 N := First (L);
11692 while Present (N) loop
11693 if not (All_Static_Choices (Discrete_Choices (N))
11694 and then Is_OK_Static_Expression (Expression (N)))
11695 then
11696 return False;
11697 end if;
11699 Next (N);
11700 end loop;
11702 return True;
11703 end All_Static_Case_Alternatives;
11705 ------------------------
11706 -- All_Static_Choices --
11707 ------------------------
11709 function All_Static_Choices (L : List_Id) return Boolean is
11710 N : Node_Id;
11712 begin
11713 N := First (L);
11714 while Present (N) loop
11715 if not Is_Static_Choice (N) then
11716 return False;
11717 end if;
11719 Next (N);
11720 end loop;
11722 return True;
11723 end All_Static_Choices;
11725 ----------------------
11726 -- Is_Static_Choice --
11727 ----------------------
11729 function Is_Static_Choice (N : Node_Id) return Boolean is
11730 begin
11731 return Nkind (N) = N_Others_Choice
11732 or else Is_OK_Static_Expression (N)
11733 or else (Is_Entity_Name (N) and then Is_Type (Entity (N))
11734 and then Is_OK_Static_Subtype (Entity (N)))
11735 or else (Nkind (N) = N_Subtype_Indication
11736 and then Is_OK_Static_Subtype (Entity (N)))
11737 or else (Nkind (N) = N_Range and then Is_OK_Static_Range (N));
11738 end Is_Static_Choice;
11740 -----------------
11741 -- Is_Type_Ref --
11742 -----------------
11744 function Is_Type_Ref (N : Node_Id) return Boolean is
11745 begin
11746 return (Nkind (N) = N_Identifier
11747 and then Chars (N) = Nam
11748 and then Paren_Count (N) = 0)
11749 or else Nkind (N) = N_Function_Call;
11750 end Is_Type_Ref;
11752 -- Start of processing for Is_Predicate_Static
11754 begin
11755 -- Predicate_Static means one of the following holds. Numbers are the
11756 -- corresponding paragraph numbers in (RM 3.2.4(16-22)).
11758 -- 16: A static expression
11760 if Is_OK_Static_Expression (Expr) then
11761 return True;
11763 -- 17: A membership test whose simple_expression is the current
11764 -- instance, and whose membership_choice_list meets the requirements
11765 -- for a static membership test.
11767 elsif Nkind (Expr) in N_Membership_Test
11768 and then ((Present (Right_Opnd (Expr))
11769 and then Is_Static_Choice (Right_Opnd (Expr)))
11770 or else
11771 (Present (Alternatives (Expr))
11772 and then All_Static_Choices (Alternatives (Expr))))
11773 then
11774 return True;
11776 -- 18. A case_expression whose selecting_expression is the current
11777 -- instance, and whose dependent expressions are static expressions.
11779 elsif Nkind (Expr) = N_Case_Expression
11780 and then Is_Type_Ref (Expression (Expr))
11781 and then All_Static_Case_Alternatives (Alternatives (Expr))
11782 then
11783 return True;
11785 -- 19. A call to a predefined equality or ordering operator, where one
11786 -- operand is the current instance, and the other is a static
11787 -- expression.
11789 -- Note: the RM is clearly wrong here in not excluding string types.
11790 -- Without this exclusion, we would allow expressions like X > "ABC"
11791 -- to be considered as predicate-static, which is clearly not intended,
11792 -- since the idea is for predicate-static to be a subset of normal
11793 -- static expressions (and "DEF" > "ABC" is not a static expression).
11795 -- However, we do allow internally generated (not from source) equality
11796 -- and inequality operations to be valid on strings (this helps deal
11797 -- with cases where we transform A in "ABC" to A = "ABC).
11799 -- In fact, it appears that the intent of the ARG is to extend static
11800 -- predicates to strings, and that the extension should probably apply
11801 -- to static expressions themselves. The code below accepts comparison
11802 -- operators that apply to static strings.
11804 elsif Nkind (Expr) in N_Op_Compare
11805 and then ((Is_Type_Ref (Left_Opnd (Expr))
11806 and then Is_OK_Static_Expression (Right_Opnd (Expr)))
11807 or else
11808 (Is_Type_Ref (Right_Opnd (Expr))
11809 and then Is_OK_Static_Expression (Left_Opnd (Expr))))
11810 then
11811 return True;
11813 -- 20. A call to a predefined boolean logical operator, where each
11814 -- operand is predicate-static.
11816 elsif (Nkind_In (Expr, N_Op_And, N_Op_Or, N_Op_Xor)
11817 and then Is_Predicate_Static (Left_Opnd (Expr), Nam)
11818 and then Is_Predicate_Static (Right_Opnd (Expr), Nam))
11819 or else
11820 (Nkind (Expr) = N_Op_Not
11821 and then Is_Predicate_Static (Right_Opnd (Expr), Nam))
11822 then
11823 return True;
11825 -- 21. A short-circuit control form where both operands are
11826 -- predicate-static.
11828 elsif Nkind (Expr) in N_Short_Circuit
11829 and then Is_Predicate_Static (Left_Opnd (Expr), Nam)
11830 and then Is_Predicate_Static (Right_Opnd (Expr), Nam)
11831 then
11832 return True;
11834 -- 22. A parenthesized predicate-static expression. This does not
11835 -- require any special test, since we just ignore paren levels in
11836 -- all the cases above.
11838 -- One more test that is an implementation artifact caused by the fact
11839 -- that we are analyzing not the original expression, but the generated
11840 -- expression in the body of the predicate function. This can include
11841 -- references to inherited predicates, so that the expression we are
11842 -- processing looks like:
11844 -- xxPredicate (typ (Inns)) and then expression
11846 -- Where the call is to a Predicate function for an inherited predicate.
11847 -- We simply ignore such a call, which could be to either a dynamic or
11848 -- a static predicate. Note that if the parent predicate is dynamic then
11849 -- eventually this type will be marked as dynamic, but you are allowed
11850 -- to specify a static predicate for a subtype which is inheriting a
11851 -- dynamic predicate, so the static predicate validation here ignores
11852 -- the inherited predicate even if it is dynamic.
11853 -- In all cases, a static predicate can only apply to a scalar type.
11855 elsif Nkind (Expr) = N_Function_Call
11856 and then Is_Predicate_Function (Entity (Name (Expr)))
11857 and then Is_Scalar_Type (Etype (First_Entity (Entity (Name (Expr)))))
11858 then
11859 return True;
11861 -- That's an exhaustive list of tests, all other cases are not
11862 -- predicate-static, so we return False.
11864 else
11865 return False;
11866 end if;
11867 end Is_Predicate_Static;
11869 ---------------------
11870 -- Kill_Rep_Clause --
11871 ---------------------
11873 procedure Kill_Rep_Clause (N : Node_Id) is
11874 begin
11875 pragma Assert (Ignore_Rep_Clauses);
11877 -- Note: we use Replace rather than Rewrite, because we don't want
11878 -- ASIS to be able to use Original_Node to dig out the (undecorated)
11879 -- rep clause that is being replaced.
11881 Replace (N, Make_Null_Statement (Sloc (N)));
11883 -- The null statement must be marked as not coming from source. This is
11884 -- so that ASIS ignores it, and also the back end does not expect bogus
11885 -- "from source" null statements in weird places (e.g. in declarative
11886 -- regions where such null statements are not allowed).
11888 Set_Comes_From_Source (N, False);
11889 end Kill_Rep_Clause;
11891 ------------------
11892 -- Minimum_Size --
11893 ------------------
11895 function Minimum_Size
11896 (T : Entity_Id;
11897 Biased : Boolean := False) return Nat
11899 Lo : Uint := No_Uint;
11900 Hi : Uint := No_Uint;
11901 LoR : Ureal := No_Ureal;
11902 HiR : Ureal := No_Ureal;
11903 LoSet : Boolean := False;
11904 HiSet : Boolean := False;
11905 B : Uint;
11906 S : Nat;
11907 Ancest : Entity_Id;
11908 R_Typ : constant Entity_Id := Root_Type (T);
11910 begin
11911 -- If bad type, return 0
11913 if T = Any_Type then
11914 return 0;
11916 -- For generic types, just return zero. There cannot be any legitimate
11917 -- need to know such a size, but this routine may be called with a
11918 -- generic type as part of normal processing.
11920 elsif Is_Generic_Type (R_Typ) or else R_Typ = Any_Type then
11921 return 0;
11923 -- Access types (cannot have size smaller than System.Address)
11925 elsif Is_Access_Type (T) then
11926 return System_Address_Size;
11928 -- Floating-point types
11930 elsif Is_Floating_Point_Type (T) then
11931 return UI_To_Int (Esize (R_Typ));
11933 -- Discrete types
11935 elsif Is_Discrete_Type (T) then
11937 -- The following loop is looking for the nearest compile time known
11938 -- bounds following the ancestor subtype chain. The idea is to find
11939 -- the most restrictive known bounds information.
11941 Ancest := T;
11942 loop
11943 if Ancest = Any_Type or else Etype (Ancest) = Any_Type then
11944 return 0;
11945 end if;
11947 if not LoSet then
11948 if Compile_Time_Known_Value (Type_Low_Bound (Ancest)) then
11949 Lo := Expr_Rep_Value (Type_Low_Bound (Ancest));
11950 LoSet := True;
11951 exit when HiSet;
11952 end if;
11953 end if;
11955 if not HiSet then
11956 if Compile_Time_Known_Value (Type_High_Bound (Ancest)) then
11957 Hi := Expr_Rep_Value (Type_High_Bound (Ancest));
11958 HiSet := True;
11959 exit when LoSet;
11960 end if;
11961 end if;
11963 Ancest := Ancestor_Subtype (Ancest);
11965 if No (Ancest) then
11966 Ancest := Base_Type (T);
11968 if Is_Generic_Type (Ancest) then
11969 return 0;
11970 end if;
11971 end if;
11972 end loop;
11974 -- Fixed-point types. We can't simply use Expr_Value to get the
11975 -- Corresponding_Integer_Value values of the bounds, since these do not
11976 -- get set till the type is frozen, and this routine can be called
11977 -- before the type is frozen. Similarly the test for bounds being static
11978 -- needs to include the case where we have unanalyzed real literals for
11979 -- the same reason.
11981 elsif Is_Fixed_Point_Type (T) then
11983 -- The following loop is looking for the nearest compile time known
11984 -- bounds following the ancestor subtype chain. The idea is to find
11985 -- the most restrictive known bounds information.
11987 Ancest := T;
11988 loop
11989 if Ancest = Any_Type or else Etype (Ancest) = Any_Type then
11990 return 0;
11991 end if;
11993 -- Note: In the following two tests for LoSet and HiSet, it may
11994 -- seem redundant to test for N_Real_Literal here since normally
11995 -- one would assume that the test for the value being known at
11996 -- compile time includes this case. However, there is a glitch.
11997 -- If the real literal comes from folding a non-static expression,
11998 -- then we don't consider any non- static expression to be known
11999 -- at compile time if we are in configurable run time mode (needed
12000 -- in some cases to give a clearer definition of what is and what
12001 -- is not accepted). So the test is indeed needed. Without it, we
12002 -- would set neither Lo_Set nor Hi_Set and get an infinite loop.
12004 if not LoSet then
12005 if Nkind (Type_Low_Bound (Ancest)) = N_Real_Literal
12006 or else Compile_Time_Known_Value (Type_Low_Bound (Ancest))
12007 then
12008 LoR := Expr_Value_R (Type_Low_Bound (Ancest));
12009 LoSet := True;
12010 exit when HiSet;
12011 end if;
12012 end if;
12014 if not HiSet then
12015 if Nkind (Type_High_Bound (Ancest)) = N_Real_Literal
12016 or else Compile_Time_Known_Value (Type_High_Bound (Ancest))
12017 then
12018 HiR := Expr_Value_R (Type_High_Bound (Ancest));
12019 HiSet := True;
12020 exit when LoSet;
12021 end if;
12022 end if;
12024 Ancest := Ancestor_Subtype (Ancest);
12026 if No (Ancest) then
12027 Ancest := Base_Type (T);
12029 if Is_Generic_Type (Ancest) then
12030 return 0;
12031 end if;
12032 end if;
12033 end loop;
12035 Lo := UR_To_Uint (LoR / Small_Value (T));
12036 Hi := UR_To_Uint (HiR / Small_Value (T));
12038 -- No other types allowed
12040 else
12041 raise Program_Error;
12042 end if;
12044 -- Fall through with Hi and Lo set. Deal with biased case
12046 if (Biased
12047 and then not Is_Fixed_Point_Type (T)
12048 and then not (Is_Enumeration_Type (T)
12049 and then Has_Non_Standard_Rep (T)))
12050 or else Has_Biased_Representation (T)
12051 then
12052 Hi := Hi - Lo;
12053 Lo := Uint_0;
12054 end if;
12056 -- Null range case, size is always zero. We only do this in the discrete
12057 -- type case, since that's the odd case that came up. Probably we should
12058 -- also do this in the fixed-point case, but doing so causes peculiar
12059 -- gigi failures, and it is not worth worrying about this incredibly
12060 -- marginal case (explicit null-range fixed-point type declarations)???
12062 if Lo > Hi and then Is_Discrete_Type (T) then
12063 S := 0;
12065 -- Signed case. Note that we consider types like range 1 .. -1 to be
12066 -- signed for the purpose of computing the size, since the bounds have
12067 -- to be accommodated in the base type.
12069 elsif Lo < 0 or else Hi < 0 then
12070 S := 1;
12071 B := Uint_1;
12073 -- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1))
12074 -- Note that we accommodate the case where the bounds cross. This
12075 -- can happen either because of the way the bounds are declared
12076 -- or because of the algorithm in Freeze_Fixed_Point_Type.
12078 while Lo < -B
12079 or else Hi < -B
12080 or else Lo >= B
12081 or else Hi >= B
12082 loop
12083 B := Uint_2 ** S;
12084 S := S + 1;
12085 end loop;
12087 -- Unsigned case
12089 else
12090 -- If both bounds are positive, make sure that both are represen-
12091 -- table in the case where the bounds are crossed. This can happen
12092 -- either because of the way the bounds are declared, or because of
12093 -- the algorithm in Freeze_Fixed_Point_Type.
12095 if Lo > Hi then
12096 Hi := Lo;
12097 end if;
12099 -- S = size, (can accommodate 0 .. (2**size - 1))
12101 S := 0;
12102 while Hi >= Uint_2 ** S loop
12103 S := S + 1;
12104 end loop;
12105 end if;
12107 return S;
12108 end Minimum_Size;
12110 ---------------------------
12111 -- New_Stream_Subprogram --
12112 ---------------------------
12114 procedure New_Stream_Subprogram
12115 (N : Node_Id;
12116 Ent : Entity_Id;
12117 Subp : Entity_Id;
12118 Nam : TSS_Name_Type)
12120 Loc : constant Source_Ptr := Sloc (N);
12121 Sname : constant Name_Id := Make_TSS_Name (Base_Type (Ent), Nam);
12122 Subp_Id : Entity_Id;
12123 Subp_Decl : Node_Id;
12124 F : Entity_Id;
12125 Etyp : Entity_Id;
12127 Defer_Declaration : constant Boolean :=
12128 Is_Tagged_Type (Ent) or else Is_Private_Type (Ent);
12129 -- For a tagged type, there is a declaration for each stream attribute
12130 -- at the freeze point, and we must generate only a completion of this
12131 -- declaration. We do the same for private types, because the full view
12132 -- might be tagged. Otherwise we generate a declaration at the point of
12133 -- the attribute definition clause. If the attribute definition comes
12134 -- from an aspect specification the declaration is part of the freeze
12135 -- actions of the type.
12137 function Build_Spec return Node_Id;
12138 -- Used for declaration and renaming declaration, so that this is
12139 -- treated as a renaming_as_body.
12141 ----------------
12142 -- Build_Spec --
12143 ----------------
12145 function Build_Spec return Node_Id is
12146 Out_P : constant Boolean := (Nam = TSS_Stream_Read);
12147 Formals : List_Id;
12148 Spec : Node_Id;
12149 T_Ref : constant Node_Id := New_Occurrence_Of (Etyp, Loc);
12151 begin
12152 Subp_Id := Make_Defining_Identifier (Loc, Sname);
12154 -- S : access Root_Stream_Type'Class
12156 Formals := New_List (
12157 Make_Parameter_Specification (Loc,
12158 Defining_Identifier =>
12159 Make_Defining_Identifier (Loc, Name_S),
12160 Parameter_Type =>
12161 Make_Access_Definition (Loc,
12162 Subtype_Mark =>
12163 New_Occurrence_Of (
12164 Designated_Type (Etype (F)), Loc))));
12166 if Nam = TSS_Stream_Input then
12167 Spec :=
12168 Make_Function_Specification (Loc,
12169 Defining_Unit_Name => Subp_Id,
12170 Parameter_Specifications => Formals,
12171 Result_Definition => T_Ref);
12172 else
12173 -- V : [out] T
12175 Append_To (Formals,
12176 Make_Parameter_Specification (Loc,
12177 Defining_Identifier => Make_Defining_Identifier (Loc, Name_V),
12178 Out_Present => Out_P,
12179 Parameter_Type => T_Ref));
12181 Spec :=
12182 Make_Procedure_Specification (Loc,
12183 Defining_Unit_Name => Subp_Id,
12184 Parameter_Specifications => Formals);
12185 end if;
12187 return Spec;
12188 end Build_Spec;
12190 -- Start of processing for New_Stream_Subprogram
12192 begin
12193 F := First_Formal (Subp);
12195 if Ekind (Subp) = E_Procedure then
12196 Etyp := Etype (Next_Formal (F));
12197 else
12198 Etyp := Etype (Subp);
12199 end if;
12201 -- Prepare subprogram declaration and insert it as an action on the
12202 -- clause node. The visibility for this entity is used to test for
12203 -- visibility of the attribute definition clause (in the sense of
12204 -- 8.3(23) as amended by AI-195).
12206 if not Defer_Declaration then
12207 Subp_Decl :=
12208 Make_Subprogram_Declaration (Loc,
12209 Specification => Build_Spec);
12211 -- For a tagged type, there is always a visible declaration for each
12212 -- stream TSS (it is a predefined primitive operation), and the
12213 -- completion of this declaration occurs at the freeze point, which is
12214 -- not always visible at places where the attribute definition clause is
12215 -- visible. So, we create a dummy entity here for the purpose of
12216 -- tracking the visibility of the attribute definition clause itself.
12218 else
12219 Subp_Id :=
12220 Make_Defining_Identifier (Loc, New_External_Name (Sname, 'V'));
12221 Subp_Decl :=
12222 Make_Object_Declaration (Loc,
12223 Defining_Identifier => Subp_Id,
12224 Object_Definition => New_Occurrence_Of (Standard_Boolean, Loc));
12225 end if;
12227 if not Defer_Declaration
12228 and then From_Aspect_Specification (N)
12229 and then Has_Delayed_Freeze (Ent)
12230 then
12231 Append_Freeze_Action (Ent, Subp_Decl);
12233 else
12234 Insert_Action (N, Subp_Decl);
12235 Set_Entity (N, Subp_Id);
12236 end if;
12238 Subp_Decl :=
12239 Make_Subprogram_Renaming_Declaration (Loc,
12240 Specification => Build_Spec,
12241 Name => New_Occurrence_Of (Subp, Loc));
12243 if Defer_Declaration then
12244 Set_TSS (Base_Type (Ent), Subp_Id);
12246 else
12247 if From_Aspect_Specification (N) then
12248 Append_Freeze_Action (Ent, Subp_Decl);
12249 else
12250 Insert_Action (N, Subp_Decl);
12251 end if;
12253 Copy_TSS (Subp_Id, Base_Type (Ent));
12254 end if;
12255 end New_Stream_Subprogram;
12257 ------------------------------------------
12258 -- Push_Scope_And_Install_Discriminants --
12259 ------------------------------------------
12261 procedure Push_Scope_And_Install_Discriminants (E : Entity_Id) is
12262 begin
12263 if Has_Discriminants (E) then
12264 Push_Scope (E);
12266 -- Make the discriminants visible for type declarations and protected
12267 -- type declarations, not for subtype declarations (RM 13.1.1 (12/3))
12269 if Nkind (Parent (E)) /= N_Subtype_Declaration then
12270 Install_Discriminants (E);
12271 end if;
12272 end if;
12273 end Push_Scope_And_Install_Discriminants;
12275 ------------------------
12276 -- Rep_Item_Too_Early --
12277 ------------------------
12279 function Rep_Item_Too_Early (T : Entity_Id; N : Node_Id) return Boolean is
12280 begin
12281 -- Cannot apply non-operational rep items to generic types
12283 if Is_Operational_Item (N) then
12284 return False;
12286 elsif Is_Type (T)
12287 and then Is_Generic_Type (Root_Type (T))
12288 and then (Nkind (N) /= N_Pragma
12289 or else Get_Pragma_Id (N) /= Pragma_Convention)
12290 then
12291 Error_Msg_N ("representation item not allowed for generic type", N);
12292 return True;
12293 end if;
12295 -- Otherwise check for incomplete type
12297 if Is_Incomplete_Or_Private_Type (T)
12298 and then No (Underlying_Type (T))
12299 and then
12300 (Nkind (N) /= N_Pragma
12301 or else Get_Pragma_Id (N) /= Pragma_Import)
12302 then
12303 Error_Msg_N
12304 ("representation item must be after full type declaration", N);
12305 return True;
12307 -- If the type has incomplete components, a representation clause is
12308 -- illegal but stream attributes and Convention pragmas are correct.
12310 elsif Has_Private_Component (T) then
12311 if Nkind (N) = N_Pragma then
12312 return False;
12314 else
12315 Error_Msg_N
12316 ("representation item must appear after type is fully defined",
12318 return True;
12319 end if;
12320 else
12321 return False;
12322 end if;
12323 end Rep_Item_Too_Early;
12325 -----------------------
12326 -- Rep_Item_Too_Late --
12327 -----------------------
12329 function Rep_Item_Too_Late
12330 (T : Entity_Id;
12331 N : Node_Id;
12332 FOnly : Boolean := False) return Boolean
12334 S : Entity_Id;
12335 Parent_Type : Entity_Id;
12337 procedure No_Type_Rep_Item;
12338 -- Output message indicating that no type-related aspects can be
12339 -- specified due to some property of the parent type.
12341 procedure Too_Late;
12342 -- Output message for an aspect being specified too late
12344 -- Note that neither of the above errors is considered a serious one,
12345 -- since the effect is simply that we ignore the representation clause
12346 -- in these cases.
12347 -- Is this really true? In any case if we make this change we must
12348 -- document the requirement in the spec of Rep_Item_Too_Late that
12349 -- if True is returned, then the rep item must be completely ignored???
12351 ----------------------
12352 -- No_Type_Rep_Item --
12353 ----------------------
12355 procedure No_Type_Rep_Item is
12356 begin
12357 Error_Msg_N ("|type-related representation item not permitted!", N);
12358 end No_Type_Rep_Item;
12360 --------------
12361 -- Too_Late --
12362 --------------
12364 procedure Too_Late is
12365 begin
12366 -- Other compilers seem more relaxed about rep items appearing too
12367 -- late. Since analysis tools typically don't care about rep items
12368 -- anyway, no reason to be too strict about this.
12370 if not Relaxed_RM_Semantics then
12371 Error_Msg_N ("|representation item appears too late!", N);
12372 end if;
12373 end Too_Late;
12375 -- Start of processing for Rep_Item_Too_Late
12377 begin
12378 -- First make sure entity is not frozen (RM 13.1(9))
12380 if Is_Frozen (T)
12382 -- Exclude imported types, which may be frozen if they appear in a
12383 -- representation clause for a local type.
12385 and then not From_Limited_With (T)
12387 -- Exclude generated entities (not coming from source). The common
12388 -- case is when we generate a renaming which prematurely freezes the
12389 -- renamed internal entity, but we still want to be able to set copies
12390 -- of attribute values such as Size/Alignment.
12392 and then Comes_From_Source (T)
12393 then
12394 -- A self-referential aspect is illegal if it forces freezing the
12395 -- entity before the corresponding pragma has been analyzed.
12397 if Nkind_In (N, N_Attribute_Definition_Clause, N_Pragma)
12398 and then From_Aspect_Specification (N)
12399 then
12400 Error_Msg_NE
12401 ("aspect specification causes premature freezing of&", N, T);
12402 Set_Has_Delayed_Freeze (T, False);
12403 return True;
12404 end if;
12406 Too_Late;
12407 S := First_Subtype (T);
12409 if Present (Freeze_Node (S)) then
12410 if not Relaxed_RM_Semantics then
12411 Error_Msg_NE
12412 ("??no more representation items for }", Freeze_Node (S), S);
12413 end if;
12414 end if;
12416 return True;
12418 -- Check for case of untagged derived type whose parent either has
12419 -- primitive operations, or is a by reference type (RM 13.1(10)). In
12420 -- this case we do not output a Too_Late message, since there is no
12421 -- earlier point where the rep item could be placed to make it legal.
12423 elsif Is_Type (T)
12424 and then not FOnly
12425 and then Is_Derived_Type (T)
12426 and then not Is_Tagged_Type (T)
12427 then
12428 Parent_Type := Etype (Base_Type (T));
12430 if Has_Primitive_Operations (Parent_Type) then
12431 No_Type_Rep_Item;
12433 if not Relaxed_RM_Semantics then
12434 Error_Msg_NE
12435 ("\parent type & has primitive operations!", N, Parent_Type);
12436 end if;
12438 return True;
12440 elsif Is_By_Reference_Type (Parent_Type) then
12441 No_Type_Rep_Item;
12443 if not Relaxed_RM_Semantics then
12444 Error_Msg_NE
12445 ("\parent type & is a by reference type!", N, Parent_Type);
12446 end if;
12448 return True;
12449 end if;
12450 end if;
12452 -- No error, but one more warning to consider. The RM (surprisingly)
12453 -- allows this pattern:
12455 -- type S is ...
12456 -- primitive operations for S
12457 -- type R is new S;
12458 -- rep clause for S
12460 -- Meaning that calls on the primitive operations of S for values of
12461 -- type R may require possibly expensive implicit conversion operations.
12462 -- This is not an error, but is worth a warning.
12464 if not Relaxed_RM_Semantics and then Is_Type (T) then
12465 declare
12466 DTL : constant Entity_Id := Derived_Type_Link (Base_Type (T));
12468 begin
12469 if Present (DTL)
12470 and then Has_Primitive_Operations (Base_Type (T))
12472 -- For now, do not generate this warning for the case of aspect
12473 -- specification using Ada 2012 syntax, since we get wrong
12474 -- messages we do not understand. The whole business of derived
12475 -- types and rep items seems a bit confused when aspects are
12476 -- used, since the aspects are not evaluated till freeze time.
12478 and then not From_Aspect_Specification (N)
12479 then
12480 Error_Msg_Sloc := Sloc (DTL);
12481 Error_Msg_N
12482 ("representation item for& appears after derived type "
12483 & "declaration#??", N);
12484 Error_Msg_NE
12485 ("\may result in implicit conversions for primitive "
12486 & "operations of&??", N, T);
12487 Error_Msg_NE
12488 ("\to change representations when called with arguments "
12489 & "of type&??", N, DTL);
12490 end if;
12491 end;
12492 end if;
12494 -- No error, link item into head of chain of rep items for the entity,
12495 -- but avoid chaining if we have an overloadable entity, and the pragma
12496 -- is one that can apply to multiple overloaded entities.
12498 if Is_Overloadable (T) and then Nkind (N) = N_Pragma then
12499 declare
12500 Pname : constant Name_Id := Pragma_Name (N);
12501 begin
12502 if Nam_In (Pname, Name_Convention, Name_Import, Name_Export,
12503 Name_External, Name_Interface)
12504 then
12505 return False;
12506 end if;
12507 end;
12508 end if;
12510 Record_Rep_Item (T, N);
12511 return False;
12512 end Rep_Item_Too_Late;
12514 -------------------------------------
12515 -- Replace_Type_References_Generic --
12516 -------------------------------------
12518 procedure Replace_Type_References_Generic (N : Node_Id; T : Entity_Id) is
12519 TName : constant Name_Id := Chars (T);
12521 function Replace_Type_Ref (N : Node_Id) return Traverse_Result;
12522 -- Processes a single node in the traversal procedure below, checking
12523 -- if node N should be replaced, and if so, doing the replacement.
12525 function Visible_Component (Comp : Name_Id) return Entity_Id;
12526 -- Given an identifier in the expression, check whether there is a
12527 -- discriminant or component of the type that is directy visible, and
12528 -- rewrite it as the corresponding selected component of the formal of
12529 -- the subprogram. The entity is located by a sequential search, which
12530 -- seems acceptable given the typical size of component lists and check
12531 -- expressions. Possible optimization ???
12533 ----------------------
12534 -- Replace_Type_Ref --
12535 ----------------------
12537 function Replace_Type_Ref (N : Node_Id) return Traverse_Result is
12538 Loc : constant Source_Ptr := Sloc (N);
12540 procedure Add_Prefix (Ref : Node_Id; Comp : Entity_Id);
12541 -- Add the proper prefix to a reference to a component of the type
12542 -- when it is not already a selected component.
12544 ----------------
12545 -- Add_Prefix --
12546 ----------------
12548 procedure Add_Prefix (Ref : Node_Id; Comp : Entity_Id) is
12549 begin
12550 Rewrite (Ref,
12551 Make_Selected_Component (Loc,
12552 Prefix => New_Occurrence_Of (T, Loc),
12553 Selector_Name => New_Occurrence_Of (Comp, Loc)));
12554 Replace_Type_Reference (Prefix (Ref));
12555 end Add_Prefix;
12557 -- Local variables
12559 Comp : Entity_Id;
12560 Pref : Node_Id;
12561 Scop : Entity_Id;
12563 -- Start of processing for Replace_Type_Ref
12565 begin
12566 if Nkind (N) = N_Identifier then
12568 -- If not the type name, check whether it is a reference to some
12569 -- other type, which must be frozen before the predicate function
12570 -- is analyzed, i.e. before the freeze node of the type to which
12571 -- the predicate applies.
12573 if Chars (N) /= TName then
12574 if Present (Current_Entity (N))
12575 and then Is_Type (Current_Entity (N))
12576 then
12577 Freeze_Before (Freeze_Node (T), Current_Entity (N));
12578 end if;
12580 -- The components of the type are directly visible and can
12581 -- be referenced without a prefix.
12583 if Nkind (Parent (N)) = N_Selected_Component then
12584 null;
12586 -- In expression C (I), C may be a directly visible function
12587 -- or a visible component that has an array type. Disambiguate
12588 -- by examining the component type.
12590 elsif Nkind (Parent (N)) = N_Indexed_Component
12591 and then N = Prefix (Parent (N))
12592 then
12593 Comp := Visible_Component (Chars (N));
12595 if Present (Comp) and then Is_Array_Type (Etype (Comp)) then
12596 Add_Prefix (N, Comp);
12597 end if;
12599 else
12600 Comp := Visible_Component (Chars (N));
12602 if Present (Comp) then
12603 Add_Prefix (N, Comp);
12604 end if;
12605 end if;
12607 return Skip;
12609 -- Otherwise do the replacement and we are done with this node
12611 else
12612 Replace_Type_Reference (N);
12613 return Skip;
12614 end if;
12616 -- Case of selected component (which is what a qualification looks
12617 -- like in the unanalyzed tree, which is what we have.
12619 elsif Nkind (N) = N_Selected_Component then
12621 -- If selector name is not our type, keeping going (we might still
12622 -- have an occurrence of the type in the prefix).
12624 if Nkind (Selector_Name (N)) /= N_Identifier
12625 or else Chars (Selector_Name (N)) /= TName
12626 then
12627 return OK;
12629 -- Selector name is our type, check qualification
12631 else
12632 -- Loop through scopes and prefixes, doing comparison
12634 Scop := Current_Scope;
12635 Pref := Prefix (N);
12636 loop
12637 -- Continue if no more scopes or scope with no name
12639 if No (Scop) or else Nkind (Scop) not in N_Has_Chars then
12640 return OK;
12641 end if;
12643 -- Do replace if prefix is an identifier matching the scope
12644 -- that we are currently looking at.
12646 if Nkind (Pref) = N_Identifier
12647 and then Chars (Pref) = Chars (Scop)
12648 then
12649 Replace_Type_Reference (N);
12650 return Skip;
12651 end if;
12653 -- Go check scope above us if prefix is itself of the form
12654 -- of a selected component, whose selector matches the scope
12655 -- we are currently looking at.
12657 if Nkind (Pref) = N_Selected_Component
12658 and then Nkind (Selector_Name (Pref)) = N_Identifier
12659 and then Chars (Selector_Name (Pref)) = Chars (Scop)
12660 then
12661 Scop := Scope (Scop);
12662 Pref := Prefix (Pref);
12664 -- For anything else, we don't have a match, so keep on
12665 -- going, there are still some weird cases where we may
12666 -- still have a replacement within the prefix.
12668 else
12669 return OK;
12670 end if;
12671 end loop;
12672 end if;
12674 -- Continue for any other node kind
12676 else
12677 return OK;
12678 end if;
12679 end Replace_Type_Ref;
12681 procedure Replace_Type_Refs is new Traverse_Proc (Replace_Type_Ref);
12683 -----------------------
12684 -- Visible_Component --
12685 -----------------------
12687 function Visible_Component (Comp : Name_Id) return Entity_Id is
12688 E : Entity_Id;
12690 begin
12692 -- Types with nameable components are records and discriminated
12693 -- private types.
12695 if Ekind (T) = E_Record_Type
12696 or else (Is_Private_Type (T) and then Has_Discriminants (T))
12697 then
12698 E := First_Entity (T);
12699 while Present (E) loop
12700 if Comes_From_Source (E) and then Chars (E) = Comp then
12701 return E;
12702 end if;
12704 Next_Entity (E);
12705 end loop;
12706 end if;
12708 -- Nothing by that name, or type has no components.
12710 return Empty;
12711 end Visible_Component;
12713 -- Start of processing for Replace_Type_References_Generic
12715 begin
12716 Replace_Type_Refs (N);
12717 end Replace_Type_References_Generic;
12719 --------------------------------
12720 -- Resolve_Aspect_Expressions --
12721 --------------------------------
12723 procedure Resolve_Aspect_Expressions (E : Entity_Id) is
12724 ASN : Node_Id;
12725 A_Id : Aspect_Id;
12726 Expr : Node_Id;
12728 function Resolve_Name (N : Node_Id) return Traverse_Result;
12729 -- Verify that all identifiers in the expression, with the exception
12730 -- of references to the current entity, denote visible entities. This
12731 -- is done only to detect visibility errors, as the expression will be
12732 -- properly analyzed/expanded during analysis of the predicate function
12733 -- body. We omit quantified expressions from this test, given that they
12734 -- introduce a local identifier that would require proper expansion to
12735 -- handle properly.
12737 -- In ASIS_Mode we preserve the entity in the source because there is
12738 -- no subsequent expansion to decorate the tree.
12740 ------------------
12741 -- Resolve_Name --
12742 ------------------
12744 function Resolve_Name (N : Node_Id) return Traverse_Result is
12745 begin
12746 if Nkind (N) = N_Selected_Component then
12747 if Nkind (Prefix (N)) = N_Identifier
12748 and then Chars (Prefix (N)) /= Chars (E)
12749 then
12750 Find_Selected_Component (N);
12751 end if;
12753 return Skip;
12755 elsif Nkind (N) = N_Identifier and then Chars (N) /= Chars (E) then
12756 Find_Direct_Name (N);
12758 if True or else not ASIS_Mode then -- ????
12759 Set_Entity (N, Empty);
12760 end if;
12762 elsif Nkind (N) = N_Quantified_Expression then
12763 return Skip;
12764 end if;
12766 return OK;
12767 end Resolve_Name;
12769 procedure Resolve_Aspect_Expression is new Traverse_Proc (Resolve_Name);
12771 -- Start of processing for Resolve_Aspect_Expressions
12773 begin
12774 ASN := First_Rep_Item (E);
12775 while Present (ASN) loop
12776 if Nkind (ASN) = N_Aspect_Specification and then Entity (ASN) = E then
12777 A_Id := Get_Aspect_Id (ASN);
12778 Expr := Expression (ASN);
12780 case A_Id is
12782 -- For now we only deal with aspects that do not generate
12783 -- subprograms, or that may mention current instances of
12784 -- types. These will require special handling (???TBD).
12786 when Aspect_Invariant
12787 | Aspect_Predicate
12788 | Aspect_Predicate_Failure
12790 null;
12792 when Aspect_Dynamic_Predicate
12793 | Aspect_Static_Predicate
12795 -- Build predicate function specification and preanalyze
12796 -- expression after type replacement.
12798 if No (Predicate_Function (E)) then
12799 declare
12800 FDecl : constant Node_Id :=
12801 Build_Predicate_Function_Declaration (E);
12802 pragma Unreferenced (FDecl);
12803 begin
12804 Resolve_Aspect_Expression (Expr);
12805 end;
12806 end if;
12808 when Pre_Post_Aspects =>
12809 null;
12811 when Aspect_Iterable =>
12812 if Nkind (Expr) = N_Aggregate then
12813 declare
12814 Assoc : Node_Id;
12816 begin
12817 Assoc := First (Component_Associations (Expr));
12818 while Present (Assoc) loop
12819 Find_Direct_Name (Expression (Assoc));
12820 Next (Assoc);
12821 end loop;
12822 end;
12823 end if;
12825 when others =>
12826 if Present (Expr) then
12827 case Aspect_Argument (A_Id) is
12828 when Expression
12829 | Optional_Expression
12831 Analyze_And_Resolve (Expression (ASN));
12833 when Name
12834 | Optional_Name
12836 if Nkind (Expr) = N_Identifier then
12837 Find_Direct_Name (Expr);
12839 elsif Nkind (Expr) = N_Selected_Component then
12840 Find_Selected_Component (Expr);
12841 end if;
12842 end case;
12843 end if;
12844 end case;
12845 end if;
12847 ASN := Next_Rep_Item (ASN);
12848 end loop;
12849 end Resolve_Aspect_Expressions;
12851 -------------------------
12852 -- Same_Representation --
12853 -------------------------
12855 function Same_Representation (Typ1, Typ2 : Entity_Id) return Boolean is
12856 T1 : constant Entity_Id := Underlying_Type (Typ1);
12857 T2 : constant Entity_Id := Underlying_Type (Typ2);
12859 begin
12860 -- A quick check, if base types are the same, then we definitely have
12861 -- the same representation, because the subtype specific representation
12862 -- attributes (Size and Alignment) do not affect representation from
12863 -- the point of view of this test.
12865 if Base_Type (T1) = Base_Type (T2) then
12866 return True;
12868 elsif Is_Private_Type (Base_Type (T2))
12869 and then Base_Type (T1) = Full_View (Base_Type (T2))
12870 then
12871 return True;
12872 end if;
12874 -- Tagged types never have differing representations
12876 if Is_Tagged_Type (T1) then
12877 return True;
12878 end if;
12880 -- Representations are definitely different if conventions differ
12882 if Convention (T1) /= Convention (T2) then
12883 return False;
12884 end if;
12886 -- Representations are different if component alignments or scalar
12887 -- storage orders differ.
12889 if (Is_Record_Type (T1) or else Is_Array_Type (T1))
12890 and then
12891 (Is_Record_Type (T2) or else Is_Array_Type (T2))
12892 and then
12893 (Component_Alignment (T1) /= Component_Alignment (T2)
12894 or else Reverse_Storage_Order (T1) /= Reverse_Storage_Order (T2))
12895 then
12896 return False;
12897 end if;
12899 -- For arrays, the only real issue is component size. If we know the
12900 -- component size for both arrays, and it is the same, then that's
12901 -- good enough to know we don't have a change of representation.
12903 if Is_Array_Type (T1) then
12904 if Known_Component_Size (T1)
12905 and then Known_Component_Size (T2)
12906 and then Component_Size (T1) = Component_Size (T2)
12907 then
12908 return True;
12909 end if;
12910 end if;
12912 -- Types definitely have same representation if neither has non-standard
12913 -- representation since default representations are always consistent.
12914 -- If only one has non-standard representation, and the other does not,
12915 -- then we consider that they do not have the same representation. They
12916 -- might, but there is no way of telling early enough.
12918 if Has_Non_Standard_Rep (T1) then
12919 if not Has_Non_Standard_Rep (T2) then
12920 return False;
12921 end if;
12922 else
12923 return not Has_Non_Standard_Rep (T2);
12924 end if;
12926 -- Here the two types both have non-standard representation, and we need
12927 -- to determine if they have the same non-standard representation.
12929 -- For arrays, we simply need to test if the component sizes are the
12930 -- same. Pragma Pack is reflected in modified component sizes, so this
12931 -- check also deals with pragma Pack.
12933 if Is_Array_Type (T1) then
12934 return Component_Size (T1) = Component_Size (T2);
12936 -- Tagged types always have the same representation, because it is not
12937 -- possible to specify different representations for common fields.
12939 elsif Is_Tagged_Type (T1) then
12940 return True;
12942 -- Case of record types
12944 elsif Is_Record_Type (T1) then
12946 -- Packed status must conform
12948 if Is_Packed (T1) /= Is_Packed (T2) then
12949 return False;
12951 -- Otherwise we must check components. Typ2 maybe a constrained
12952 -- subtype with fewer components, so we compare the components
12953 -- of the base types.
12955 else
12956 Record_Case : declare
12957 CD1, CD2 : Entity_Id;
12959 function Same_Rep return Boolean;
12960 -- CD1 and CD2 are either components or discriminants. This
12961 -- function tests whether they have the same representation.
12963 --------------
12964 -- Same_Rep --
12965 --------------
12967 function Same_Rep return Boolean is
12968 begin
12969 if No (Component_Clause (CD1)) then
12970 return No (Component_Clause (CD2));
12971 else
12972 -- Note: at this point, component clauses have been
12973 -- normalized to the default bit order, so that the
12974 -- comparison of Component_Bit_Offsets is meaningful.
12976 return
12977 Present (Component_Clause (CD2))
12978 and then
12979 Component_Bit_Offset (CD1) = Component_Bit_Offset (CD2)
12980 and then
12981 Esize (CD1) = Esize (CD2);
12982 end if;
12983 end Same_Rep;
12985 -- Start of processing for Record_Case
12987 begin
12988 if Has_Discriminants (T1) then
12990 -- The number of discriminants may be different if the
12991 -- derived type has fewer (constrained by values). The
12992 -- invisible discriminants retain the representation of
12993 -- the original, so the discrepancy does not per se
12994 -- indicate a different representation.
12996 CD1 := First_Discriminant (T1);
12997 CD2 := First_Discriminant (T2);
12998 while Present (CD1) and then Present (CD2) loop
12999 if not Same_Rep then
13000 return False;
13001 else
13002 Next_Discriminant (CD1);
13003 Next_Discriminant (CD2);
13004 end if;
13005 end loop;
13006 end if;
13008 CD1 := First_Component (Underlying_Type (Base_Type (T1)));
13009 CD2 := First_Component (Underlying_Type (Base_Type (T2)));
13010 while Present (CD1) loop
13011 if not Same_Rep then
13012 return False;
13013 else
13014 Next_Component (CD1);
13015 Next_Component (CD2);
13016 end if;
13017 end loop;
13019 return True;
13020 end Record_Case;
13021 end if;
13023 -- For enumeration types, we must check each literal to see if the
13024 -- representation is the same. Note that we do not permit enumeration
13025 -- representation clauses for Character and Wide_Character, so these
13026 -- cases were already dealt with.
13028 elsif Is_Enumeration_Type (T1) then
13029 Enumeration_Case : declare
13030 L1, L2 : Entity_Id;
13032 begin
13033 L1 := First_Literal (T1);
13034 L2 := First_Literal (T2);
13035 while Present (L1) loop
13036 if Enumeration_Rep (L1) /= Enumeration_Rep (L2) then
13037 return False;
13038 else
13039 Next_Literal (L1);
13040 Next_Literal (L2);
13041 end if;
13042 end loop;
13044 return True;
13045 end Enumeration_Case;
13047 -- Any other types have the same representation for these purposes
13049 else
13050 return True;
13051 end if;
13052 end Same_Representation;
13054 --------------------------------
13055 -- Resolve_Iterable_Operation --
13056 --------------------------------
13058 procedure Resolve_Iterable_Operation
13059 (N : Node_Id;
13060 Cursor : Entity_Id;
13061 Typ : Entity_Id;
13062 Nam : Name_Id)
13064 Ent : Entity_Id;
13065 F1 : Entity_Id;
13066 F2 : Entity_Id;
13068 begin
13069 if not Is_Overloaded (N) then
13070 if not Is_Entity_Name (N)
13071 or else Ekind (Entity (N)) /= E_Function
13072 or else Scope (Entity (N)) /= Scope (Typ)
13073 or else No (First_Formal (Entity (N)))
13074 or else Etype (First_Formal (Entity (N))) /= Typ
13075 then
13076 Error_Msg_N ("iterable primitive must be local function name "
13077 & "whose first formal is an iterable type", N);
13078 return;
13079 end if;
13081 Ent := Entity (N);
13082 F1 := First_Formal (Ent);
13083 if Nam = Name_First then
13085 -- First (Container) => Cursor
13087 if Etype (Ent) /= Cursor then
13088 Error_Msg_N ("primitive for First must yield a curosr", N);
13089 end if;
13091 elsif Nam = Name_Next then
13093 -- Next (Container, Cursor) => Cursor
13095 F2 := Next_Formal (F1);
13097 if Etype (F2) /= Cursor
13098 or else Etype (Ent) /= Cursor
13099 or else Present (Next_Formal (F2))
13100 then
13101 Error_Msg_N ("no match for Next iterable primitive", N);
13102 end if;
13104 elsif Nam = Name_Has_Element then
13106 -- Has_Element (Container, Cursor) => Boolean
13108 F2 := Next_Formal (F1);
13109 if Etype (F2) /= Cursor
13110 or else Etype (Ent) /= Standard_Boolean
13111 or else Present (Next_Formal (F2))
13112 then
13113 Error_Msg_N ("no match for Has_Element iterable primitive", N);
13114 end if;
13116 elsif Nam = Name_Element then
13117 F2 := Next_Formal (F1);
13119 if No (F2)
13120 or else Etype (F2) /= Cursor
13121 or else Present (Next_Formal (F2))
13122 then
13123 Error_Msg_N ("no match for Element iterable primitive", N);
13124 end if;
13125 null;
13127 else
13128 raise Program_Error;
13129 end if;
13131 else
13132 -- Overloaded case: find subprogram with proper signature.
13133 -- Caller will report error if no match is found.
13135 declare
13136 I : Interp_Index;
13137 It : Interp;
13139 begin
13140 Get_First_Interp (N, I, It);
13141 while Present (It.Typ) loop
13142 if Ekind (It.Nam) = E_Function
13143 and then Scope (It.Nam) = Scope (Typ)
13144 and then Etype (First_Formal (It.Nam)) = Typ
13145 then
13146 F1 := First_Formal (It.Nam);
13148 if Nam = Name_First then
13149 if Etype (It.Nam) = Cursor
13150 and then No (Next_Formal (F1))
13151 then
13152 Set_Entity (N, It.Nam);
13153 exit;
13154 end if;
13156 elsif Nam = Name_Next then
13157 F2 := Next_Formal (F1);
13159 if Present (F2)
13160 and then No (Next_Formal (F2))
13161 and then Etype (F2) = Cursor
13162 and then Etype (It.Nam) = Cursor
13163 then
13164 Set_Entity (N, It.Nam);
13165 exit;
13166 end if;
13168 elsif Nam = Name_Has_Element then
13169 F2 := Next_Formal (F1);
13171 if Present (F2)
13172 and then No (Next_Formal (F2))
13173 and then Etype (F2) = Cursor
13174 and then Etype (It.Nam) = Standard_Boolean
13175 then
13176 Set_Entity (N, It.Nam);
13177 F2 := Next_Formal (F1);
13178 exit;
13179 end if;
13181 elsif Nam = Name_Element then
13182 F2 := Next_Formal (F1);
13184 if Present (F2)
13185 and then No (Next_Formal (F2))
13186 and then Etype (F2) = Cursor
13187 then
13188 Set_Entity (N, It.Nam);
13189 exit;
13190 end if;
13191 end if;
13192 end if;
13194 Get_Next_Interp (I, It);
13195 end loop;
13196 end;
13197 end if;
13198 end Resolve_Iterable_Operation;
13200 ----------------
13201 -- Set_Biased --
13202 ----------------
13204 procedure Set_Biased
13205 (E : Entity_Id;
13206 N : Node_Id;
13207 Msg : String;
13208 Biased : Boolean := True)
13210 begin
13211 if Biased then
13212 Set_Has_Biased_Representation (E);
13214 if Warn_On_Biased_Representation then
13215 Error_Msg_NE
13216 ("?B?" & Msg & " forces biased representation for&", N, E);
13217 end if;
13218 end if;
13219 end Set_Biased;
13221 --------------------
13222 -- Set_Enum_Esize --
13223 --------------------
13225 procedure Set_Enum_Esize (T : Entity_Id) is
13226 Lo : Uint;
13227 Hi : Uint;
13228 Sz : Nat;
13230 begin
13231 Init_Alignment (T);
13233 -- Find the minimum standard size (8,16,32,64) that fits
13235 Lo := Enumeration_Rep (Entity (Type_Low_Bound (T)));
13236 Hi := Enumeration_Rep (Entity (Type_High_Bound (T)));
13238 if Lo < 0 then
13239 if Lo >= -Uint_2**07 and then Hi < Uint_2**07 then
13240 Sz := Standard_Character_Size; -- May be > 8 on some targets
13242 elsif Lo >= -Uint_2**15 and then Hi < Uint_2**15 then
13243 Sz := 16;
13245 elsif Lo >= -Uint_2**31 and then Hi < Uint_2**31 then
13246 Sz := 32;
13248 else pragma Assert (Lo >= -Uint_2**63 and then Hi < Uint_2**63);
13249 Sz := 64;
13250 end if;
13252 else
13253 if Hi < Uint_2**08 then
13254 Sz := Standard_Character_Size; -- May be > 8 on some targets
13256 elsif Hi < Uint_2**16 then
13257 Sz := 16;
13259 elsif Hi < Uint_2**32 then
13260 Sz := 32;
13262 else pragma Assert (Hi < Uint_2**63);
13263 Sz := 64;
13264 end if;
13265 end if;
13267 -- That minimum is the proper size unless we have a foreign convention
13268 -- and the size required is 32 or less, in which case we bump the size
13269 -- up to 32. This is required for C and C++ and seems reasonable for
13270 -- all other foreign conventions.
13272 if Has_Foreign_Convention (T)
13273 and then Esize (T) < Standard_Integer_Size
13275 -- Don't do this if Short_Enums on target
13277 and then not Target_Short_Enums
13278 then
13279 Init_Esize (T, Standard_Integer_Size);
13280 else
13281 Init_Esize (T, Sz);
13282 end if;
13283 end Set_Enum_Esize;
13285 -----------------------------
13286 -- Uninstall_Discriminants --
13287 -----------------------------
13289 procedure Uninstall_Discriminants (E : Entity_Id) is
13290 Disc : Entity_Id;
13291 Prev : Entity_Id;
13292 Outer : Entity_Id;
13294 begin
13295 -- Discriminants have been made visible for type declarations and
13296 -- protected type declarations, not for subtype declarations.
13298 if Nkind (Parent (E)) /= N_Subtype_Declaration then
13299 Disc := First_Discriminant (E);
13300 while Present (Disc) loop
13301 if Disc /= Current_Entity (Disc) then
13302 Prev := Current_Entity (Disc);
13303 while Present (Prev)
13304 and then Present (Homonym (Prev))
13305 and then Homonym (Prev) /= Disc
13306 loop
13307 Prev := Homonym (Prev);
13308 end loop;
13309 else
13310 Prev := Empty;
13311 end if;
13313 Set_Is_Immediately_Visible (Disc, False);
13315 Outer := Homonym (Disc);
13316 while Present (Outer) and then Scope (Outer) = E loop
13317 Outer := Homonym (Outer);
13318 end loop;
13320 -- Reset homonym link of other entities, but do not modify link
13321 -- between entities in current scope, so that the back end can
13322 -- have a proper count of local overloadings.
13324 if No (Prev) then
13325 Set_Name_Entity_Id (Chars (Disc), Outer);
13327 elsif Scope (Prev) /= Scope (Disc) then
13328 Set_Homonym (Prev, Outer);
13329 end if;
13331 Next_Discriminant (Disc);
13332 end loop;
13333 end if;
13334 end Uninstall_Discriminants;
13336 -------------------------------------------
13337 -- Uninstall_Discriminants_And_Pop_Scope --
13338 -------------------------------------------
13340 procedure Uninstall_Discriminants_And_Pop_Scope (E : Entity_Id) is
13341 begin
13342 if Has_Discriminants (E) then
13343 Uninstall_Discriminants (E);
13344 Pop_Scope;
13345 end if;
13346 end Uninstall_Discriminants_And_Pop_Scope;
13348 ------------------------------
13349 -- Validate_Address_Clauses --
13350 ------------------------------
13352 procedure Validate_Address_Clauses is
13353 function Offset_Value (Expr : Node_Id) return Uint;
13354 -- Given an Address attribute reference, return the value in bits of its
13355 -- offset from the first bit of the underlying entity, or 0 if it is not
13356 -- known at compile time.
13358 ------------------
13359 -- Offset_Value --
13360 ------------------
13362 function Offset_Value (Expr : Node_Id) return Uint is
13363 N : Node_Id := Prefix (Expr);
13364 Off : Uint;
13365 Val : Uint := Uint_0;
13367 begin
13368 -- Climb the prefix chain and compute the cumulative offset
13370 loop
13371 if Is_Entity_Name (N) then
13372 return Val;
13374 elsif Nkind (N) = N_Selected_Component then
13375 Off := Component_Bit_Offset (Entity (Selector_Name (N)));
13376 if Off /= No_Uint and then Off >= Uint_0 then
13377 Val := Val + Off;
13378 N := Prefix (N);
13379 else
13380 return Uint_0;
13381 end if;
13383 elsif Nkind (N) = N_Indexed_Component then
13384 Off := Indexed_Component_Bit_Offset (N);
13385 if Off /= No_Uint then
13386 Val := Val + Off;
13387 N := Prefix (N);
13388 else
13389 return Uint_0;
13390 end if;
13392 else
13393 return Uint_0;
13394 end if;
13395 end loop;
13396 end Offset_Value;
13398 -- Start of processing for Validate_Address_Clauses
13400 begin
13401 for J in Address_Clause_Checks.First .. Address_Clause_Checks.Last loop
13402 declare
13403 ACCR : Address_Clause_Check_Record
13404 renames Address_Clause_Checks.Table (J);
13406 Expr : Node_Id;
13408 X_Alignment : Uint;
13409 Y_Alignment : Uint;
13411 X_Size : Uint;
13412 Y_Size : Uint;
13414 X_Offs : Uint;
13416 begin
13417 -- Skip processing of this entry if warning already posted
13419 if not Address_Warning_Posted (ACCR.N) then
13420 Expr := Original_Node (Expression (ACCR.N));
13422 -- Get alignments, sizes and offset, if any
13424 X_Alignment := Alignment (ACCR.X);
13425 X_Size := Esize (ACCR.X);
13427 if Present (ACCR.Y) then
13428 Y_Alignment := Alignment (ACCR.Y);
13429 Y_Size := Esize (ACCR.Y);
13430 end if;
13432 if ACCR.Off
13433 and then Nkind (Expr) = N_Attribute_Reference
13434 and then Attribute_Name (Expr) = Name_Address
13435 then
13436 X_Offs := Offset_Value (Expr);
13437 else
13438 X_Offs := Uint_0;
13439 end if;
13441 -- Check for known value not multiple of alignment
13443 if No (ACCR.Y) then
13444 if not Alignment_Checks_Suppressed (ACCR.X)
13445 and then X_Alignment /= 0
13446 and then ACCR.A mod X_Alignment /= 0
13447 then
13448 Error_Msg_NE
13449 ("??specified address for& is inconsistent with "
13450 & "alignment", ACCR.N, ACCR.X);
13451 Error_Msg_N
13452 ("\??program execution may be erroneous (RM 13.3(27))",
13453 ACCR.N);
13455 Error_Msg_Uint_1 := X_Alignment;
13456 Error_Msg_NE ("\??alignment of & is ^", ACCR.N, ACCR.X);
13457 end if;
13459 -- Check for large object overlaying smaller one
13461 elsif Y_Size > Uint_0
13462 and then X_Size > Uint_0
13463 and then X_Offs + X_Size > Y_Size
13464 then
13465 Error_Msg_NE ("??& overlays smaller object", ACCR.N, ACCR.X);
13466 Error_Msg_N
13467 ("\??program execution may be erroneous", ACCR.N);
13469 Error_Msg_Uint_1 := X_Size;
13470 Error_Msg_NE ("\??size of & is ^", ACCR.N, ACCR.X);
13472 Error_Msg_Uint_1 := Y_Size;
13473 Error_Msg_NE ("\??size of & is ^", ACCR.N, ACCR.Y);
13475 if Y_Size >= X_Size then
13476 Error_Msg_Uint_1 := X_Offs;
13477 Error_Msg_NE ("\??but offset of & is ^", ACCR.N, ACCR.X);
13478 end if;
13480 -- Check for inadequate alignment, both of the base object
13481 -- and of the offset, if any. We only do this check if the
13482 -- run-time Alignment_Check is active. No point in warning
13483 -- if this check has been suppressed (or is suppressed by
13484 -- default in the non-strict alignment machine case).
13486 -- Note: we do not check the alignment if we gave a size
13487 -- warning, since it would likely be redundant.
13489 elsif not Alignment_Checks_Suppressed (ACCR.X)
13490 and then Y_Alignment /= Uint_0
13491 and then
13492 (Y_Alignment < X_Alignment
13493 or else
13494 (ACCR.Off
13495 and then Nkind (Expr) = N_Attribute_Reference
13496 and then Attribute_Name (Expr) = Name_Address
13497 and then Has_Compatible_Alignment
13498 (ACCR.X, Prefix (Expr), True) /=
13499 Known_Compatible))
13500 then
13501 Error_Msg_NE
13502 ("??specified address for& may be inconsistent with "
13503 & "alignment", ACCR.N, ACCR.X);
13504 Error_Msg_N
13505 ("\??program execution may be erroneous (RM 13.3(27))",
13506 ACCR.N);
13508 Error_Msg_Uint_1 := X_Alignment;
13509 Error_Msg_NE ("\??alignment of & is ^", ACCR.N, ACCR.X);
13511 Error_Msg_Uint_1 := Y_Alignment;
13512 Error_Msg_NE ("\??alignment of & is ^", ACCR.N, ACCR.Y);
13514 if Y_Alignment >= X_Alignment then
13515 Error_Msg_N
13516 ("\??but offset is not multiple of alignment", ACCR.N);
13517 end if;
13518 end if;
13519 end if;
13520 end;
13521 end loop;
13522 end Validate_Address_Clauses;
13524 -----------------------------------------
13525 -- Validate_Compile_Time_Warning_Error --
13526 -----------------------------------------
13528 procedure Validate_Compile_Time_Warning_Error (N : Node_Id) is
13529 begin
13530 Compile_Time_Warnings_Errors.Append
13531 (New_Val => CTWE_Entry'(Eloc => Sloc (N),
13532 Scope => Current_Scope,
13533 Prag => N));
13534 end Validate_Compile_Time_Warning_Error;
13536 ------------------------------------------
13537 -- Validate_Compile_Time_Warning_Errors --
13538 ------------------------------------------
13540 procedure Validate_Compile_Time_Warning_Errors is
13541 procedure Set_Scope (S : Entity_Id);
13542 -- Install all enclosing scopes of S along with S itself
13544 procedure Unset_Scope (S : Entity_Id);
13545 -- Uninstall all enclosing scopes of S along with S itself
13547 ---------------
13548 -- Set_Scope --
13549 ---------------
13551 procedure Set_Scope (S : Entity_Id) is
13552 begin
13553 if S /= Standard_Standard then
13554 Set_Scope (Scope (S));
13555 end if;
13557 Push_Scope (S);
13558 end Set_Scope;
13560 -----------------
13561 -- Unset_Scope --
13562 -----------------
13564 procedure Unset_Scope (S : Entity_Id) is
13565 begin
13566 if S /= Standard_Standard then
13567 Unset_Scope (Scope (S));
13568 end if;
13570 Pop_Scope;
13571 end Unset_Scope;
13573 -- Start of processing for Validate_Compile_Time_Warning_Errors
13575 begin
13576 Expander_Mode_Save_And_Set (False);
13577 In_Compile_Time_Warning_Or_Error := True;
13579 for N in Compile_Time_Warnings_Errors.First ..
13580 Compile_Time_Warnings_Errors.Last
13581 loop
13582 declare
13583 T : CTWE_Entry renames Compile_Time_Warnings_Errors.Table (N);
13585 begin
13586 Set_Scope (T.Scope);
13587 Reset_Analyzed_Flags (T.Prag);
13588 Process_Compile_Time_Warning_Or_Error (T.Prag, T.Eloc);
13589 Unset_Scope (T.Scope);
13590 end;
13591 end loop;
13593 In_Compile_Time_Warning_Or_Error := False;
13594 Expander_Mode_Restore;
13595 end Validate_Compile_Time_Warning_Errors;
13597 ---------------------------
13598 -- Validate_Independence --
13599 ---------------------------
13601 procedure Validate_Independence is
13602 SU : constant Uint := UI_From_Int (System_Storage_Unit);
13603 N : Node_Id;
13604 E : Entity_Id;
13605 IC : Boolean;
13606 Comp : Entity_Id;
13607 Addr : Node_Id;
13608 P : Node_Id;
13610 procedure Check_Array_Type (Atyp : Entity_Id);
13611 -- Checks if the array type Atyp has independent components, and
13612 -- if not, outputs an appropriate set of error messages.
13614 procedure No_Independence;
13615 -- Output message that independence cannot be guaranteed
13617 function OK_Component (C : Entity_Id) return Boolean;
13618 -- Checks one component to see if it is independently accessible, and
13619 -- if so yields True, otherwise yields False if independent access
13620 -- cannot be guaranteed. This is a conservative routine, it only
13621 -- returns True if it knows for sure, it returns False if it knows
13622 -- there is a problem, or it cannot be sure there is no problem.
13624 procedure Reason_Bad_Component (C : Entity_Id);
13625 -- Outputs continuation message if a reason can be determined for
13626 -- the component C being bad.
13628 ----------------------
13629 -- Check_Array_Type --
13630 ----------------------
13632 procedure Check_Array_Type (Atyp : Entity_Id) is
13633 Ctyp : constant Entity_Id := Component_Type (Atyp);
13635 begin
13636 -- OK if no alignment clause, no pack, and no component size
13638 if not Has_Component_Size_Clause (Atyp)
13639 and then not Has_Alignment_Clause (Atyp)
13640 and then not Is_Packed (Atyp)
13641 then
13642 return;
13643 end if;
13645 -- Case of component size is greater than or equal to 64 and the
13646 -- alignment of the array is at least as large as the alignment
13647 -- of the component. We are definitely OK in this situation.
13649 if Known_Component_Size (Atyp)
13650 and then Component_Size (Atyp) >= 64
13651 and then Known_Alignment (Atyp)
13652 and then Known_Alignment (Ctyp)
13653 and then Alignment (Atyp) >= Alignment (Ctyp)
13654 then
13655 return;
13656 end if;
13658 -- Check actual component size
13660 if not Known_Component_Size (Atyp)
13661 or else not (Addressable (Component_Size (Atyp))
13662 and then Component_Size (Atyp) < 64)
13663 or else Component_Size (Atyp) mod Esize (Ctyp) /= 0
13664 then
13665 No_Independence;
13667 -- Bad component size, check reason
13669 if Has_Component_Size_Clause (Atyp) then
13670 P := Get_Attribute_Definition_Clause
13671 (Atyp, Attribute_Component_Size);
13673 if Present (P) then
13674 Error_Msg_Sloc := Sloc (P);
13675 Error_Msg_N ("\because of Component_Size clause#", N);
13676 return;
13677 end if;
13678 end if;
13680 if Is_Packed (Atyp) then
13681 P := Get_Rep_Pragma (Atyp, Name_Pack);
13683 if Present (P) then
13684 Error_Msg_Sloc := Sloc (P);
13685 Error_Msg_N ("\because of pragma Pack#", N);
13686 return;
13687 end if;
13688 end if;
13690 -- No reason found, just return
13692 return;
13693 end if;
13695 -- Array type is OK independence-wise
13697 return;
13698 end Check_Array_Type;
13700 ---------------------
13701 -- No_Independence --
13702 ---------------------
13704 procedure No_Independence is
13705 begin
13706 if Pragma_Name (N) = Name_Independent then
13707 Error_Msg_NE ("independence cannot be guaranteed for&", N, E);
13708 else
13709 Error_Msg_NE
13710 ("independent components cannot be guaranteed for&", N, E);
13711 end if;
13712 end No_Independence;
13714 ------------------
13715 -- OK_Component --
13716 ------------------
13718 function OK_Component (C : Entity_Id) return Boolean is
13719 Rec : constant Entity_Id := Scope (C);
13720 Ctyp : constant Entity_Id := Etype (C);
13722 begin
13723 -- OK if no component clause, no Pack, and no alignment clause
13725 if No (Component_Clause (C))
13726 and then not Is_Packed (Rec)
13727 and then not Has_Alignment_Clause (Rec)
13728 then
13729 return True;
13730 end if;
13732 -- Here we look at the actual component layout. A component is
13733 -- addressable if its size is a multiple of the Esize of the
13734 -- component type, and its starting position in the record has
13735 -- appropriate alignment, and the record itself has appropriate
13736 -- alignment to guarantee the component alignment.
13738 -- Make sure sizes are static, always assume the worst for any
13739 -- cases where we cannot check static values.
13741 if not (Known_Static_Esize (C)
13742 and then
13743 Known_Static_Esize (Ctyp))
13744 then
13745 return False;
13746 end if;
13748 -- Size of component must be addressable or greater than 64 bits
13749 -- and a multiple of bytes.
13751 if not Addressable (Esize (C)) and then Esize (C) < Uint_64 then
13752 return False;
13753 end if;
13755 -- Check size is proper multiple
13757 if Esize (C) mod Esize (Ctyp) /= 0 then
13758 return False;
13759 end if;
13761 -- Check alignment of component is OK
13763 if not Known_Component_Bit_Offset (C)
13764 or else Component_Bit_Offset (C) < Uint_0
13765 or else Component_Bit_Offset (C) mod Esize (Ctyp) /= 0
13766 then
13767 return False;
13768 end if;
13770 -- Check alignment of record type is OK
13772 if not Known_Alignment (Rec)
13773 or else (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0
13774 then
13775 return False;
13776 end if;
13778 -- All tests passed, component is addressable
13780 return True;
13781 end OK_Component;
13783 --------------------------
13784 -- Reason_Bad_Component --
13785 --------------------------
13787 procedure Reason_Bad_Component (C : Entity_Id) is
13788 Rec : constant Entity_Id := Scope (C);
13789 Ctyp : constant Entity_Id := Etype (C);
13791 begin
13792 -- If component clause present assume that's the problem
13794 if Present (Component_Clause (C)) then
13795 Error_Msg_Sloc := Sloc (Component_Clause (C));
13796 Error_Msg_N ("\because of Component_Clause#", N);
13797 return;
13798 end if;
13800 -- If pragma Pack clause present, assume that's the problem
13802 if Is_Packed (Rec) then
13803 P := Get_Rep_Pragma (Rec, Name_Pack);
13805 if Present (P) then
13806 Error_Msg_Sloc := Sloc (P);
13807 Error_Msg_N ("\because of pragma Pack#", N);
13808 return;
13809 end if;
13810 end if;
13812 -- See if record has bad alignment clause
13814 if Has_Alignment_Clause (Rec)
13815 and then Known_Alignment (Rec)
13816 and then (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0
13817 then
13818 P := Get_Attribute_Definition_Clause (Rec, Attribute_Alignment);
13820 if Present (P) then
13821 Error_Msg_Sloc := Sloc (P);
13822 Error_Msg_N ("\because of Alignment clause#", N);
13823 end if;
13824 end if;
13826 -- Couldn't find a reason, so return without a message
13828 return;
13829 end Reason_Bad_Component;
13831 -- Start of processing for Validate_Independence
13833 begin
13834 for J in Independence_Checks.First .. Independence_Checks.Last loop
13835 N := Independence_Checks.Table (J).N;
13836 E := Independence_Checks.Table (J).E;
13837 IC := Pragma_Name (N) = Name_Independent_Components;
13839 -- Deal with component case
13841 if Ekind (E) = E_Discriminant or else Ekind (E) = E_Component then
13842 if not OK_Component (E) then
13843 No_Independence;
13844 Reason_Bad_Component (E);
13845 goto Continue;
13846 end if;
13847 end if;
13849 -- Deal with record with Independent_Components
13851 if IC and then Is_Record_Type (E) then
13852 Comp := First_Component_Or_Discriminant (E);
13853 while Present (Comp) loop
13854 if not OK_Component (Comp) then
13855 No_Independence;
13856 Reason_Bad_Component (Comp);
13857 goto Continue;
13858 end if;
13860 Next_Component_Or_Discriminant (Comp);
13861 end loop;
13862 end if;
13864 -- Deal with address clause case
13866 if Is_Object (E) then
13867 Addr := Address_Clause (E);
13869 if Present (Addr) then
13870 No_Independence;
13871 Error_Msg_Sloc := Sloc (Addr);
13872 Error_Msg_N ("\because of Address clause#", N);
13873 goto Continue;
13874 end if;
13875 end if;
13877 -- Deal with independent components for array type
13879 if IC and then Is_Array_Type (E) then
13880 Check_Array_Type (E);
13881 end if;
13883 -- Deal with independent components for array object
13885 if IC and then Is_Object (E) and then Is_Array_Type (Etype (E)) then
13886 Check_Array_Type (Etype (E));
13887 end if;
13889 <<Continue>> null;
13890 end loop;
13891 end Validate_Independence;
13893 ------------------------------
13894 -- Validate_Iterable_Aspect --
13895 ------------------------------
13897 procedure Validate_Iterable_Aspect (Typ : Entity_Id; ASN : Node_Id) is
13898 Assoc : Node_Id;
13899 Expr : Node_Id;
13901 Prim : Node_Id;
13902 Cursor : constant Entity_Id := Get_Cursor_Type (ASN, Typ);
13904 First_Id : Entity_Id;
13905 Next_Id : Entity_Id;
13906 Has_Element_Id : Entity_Id;
13907 Element_Id : Entity_Id;
13909 begin
13910 -- If previous error aspect is unusable
13912 if Cursor = Any_Type then
13913 return;
13914 end if;
13916 First_Id := Empty;
13917 Next_Id := Empty;
13918 Has_Element_Id := Empty;
13919 Element_Id := Empty;
13921 -- Each expression must resolve to a function with the proper signature
13923 Assoc := First (Component_Associations (Expression (ASN)));
13924 while Present (Assoc) loop
13925 Expr := Expression (Assoc);
13926 Analyze (Expr);
13928 Prim := First (Choices (Assoc));
13930 if Nkind (Prim) /= N_Identifier or else Present (Next (Prim)) then
13931 Error_Msg_N ("illegal name in association", Prim);
13933 elsif Chars (Prim) = Name_First then
13934 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_First);
13935 First_Id := Entity (Expr);
13937 elsif Chars (Prim) = Name_Next then
13938 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Next);
13939 Next_Id := Entity (Expr);
13941 elsif Chars (Prim) = Name_Has_Element then
13942 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Has_Element);
13943 Has_Element_Id := Entity (Expr);
13945 elsif Chars (Prim) = Name_Element then
13946 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Element);
13947 Element_Id := Entity (Expr);
13949 else
13950 Error_Msg_N ("invalid name for iterable function", Prim);
13951 end if;
13953 Next (Assoc);
13954 end loop;
13956 if No (First_Id) then
13957 Error_Msg_N ("match for First primitive not found", ASN);
13959 elsif No (Next_Id) then
13960 Error_Msg_N ("match for Next primitive not found", ASN);
13962 elsif No (Has_Element_Id) then
13963 Error_Msg_N ("match for Has_Element primitive not found", ASN);
13965 elsif No (Element_Id) then
13966 null; -- Optional.
13967 end if;
13968 end Validate_Iterable_Aspect;
13970 -----------------------------------
13971 -- Validate_Unchecked_Conversion --
13972 -----------------------------------
13974 procedure Validate_Unchecked_Conversion
13975 (N : Node_Id;
13976 Act_Unit : Entity_Id)
13978 Source : Entity_Id;
13979 Target : Entity_Id;
13980 Vnode : Node_Id;
13982 begin
13983 -- Obtain source and target types. Note that we call Ancestor_Subtype
13984 -- here because the processing for generic instantiation always makes
13985 -- subtypes, and we want the original frozen actual types.
13987 -- If we are dealing with private types, then do the check on their
13988 -- fully declared counterparts if the full declarations have been
13989 -- encountered (they don't have to be visible, but they must exist).
13991 Source := Ancestor_Subtype (Etype (First_Formal (Act_Unit)));
13993 if Is_Private_Type (Source)
13994 and then Present (Underlying_Type (Source))
13995 then
13996 Source := Underlying_Type (Source);
13997 end if;
13999 Target := Ancestor_Subtype (Etype (Act_Unit));
14001 -- If either type is generic, the instantiation happens within a generic
14002 -- unit, and there is nothing to check. The proper check will happen
14003 -- when the enclosing generic is instantiated.
14005 if Is_Generic_Type (Source) or else Is_Generic_Type (Target) then
14006 return;
14007 end if;
14009 if Is_Private_Type (Target)
14010 and then Present (Underlying_Type (Target))
14011 then
14012 Target := Underlying_Type (Target);
14013 end if;
14015 -- Source may be unconstrained array, but not target, except in relaxed
14016 -- semantics mode.
14018 if Is_Array_Type (Target)
14019 and then not Is_Constrained (Target)
14020 and then not Relaxed_RM_Semantics
14021 then
14022 Error_Msg_N
14023 ("unchecked conversion to unconstrained array not allowed", N);
14024 return;
14025 end if;
14027 -- Warn if conversion between two different convention pointers
14029 if Is_Access_Type (Target)
14030 and then Is_Access_Type (Source)
14031 and then Convention (Target) /= Convention (Source)
14032 and then Warn_On_Unchecked_Conversion
14033 then
14034 -- Give warnings for subprogram pointers only on most targets
14036 if Is_Access_Subprogram_Type (Target)
14037 or else Is_Access_Subprogram_Type (Source)
14038 then
14039 Error_Msg_N
14040 ("?z?conversion between pointers with different conventions!",
14042 end if;
14043 end if;
14045 -- Warn if one of the operands is Ada.Calendar.Time. Do not emit a
14046 -- warning when compiling GNAT-related sources.
14048 if Warn_On_Unchecked_Conversion
14049 and then not In_Predefined_Unit (N)
14050 and then RTU_Loaded (Ada_Calendar)
14051 and then (Chars (Source) = Name_Time
14052 or else
14053 Chars (Target) = Name_Time)
14054 then
14055 -- If Ada.Calendar is loaded and the name of one of the operands is
14056 -- Time, there is a good chance that this is Ada.Calendar.Time.
14058 declare
14059 Calendar_Time : constant Entity_Id := Full_View (RTE (RO_CA_Time));
14060 begin
14061 pragma Assert (Present (Calendar_Time));
14063 if Source = Calendar_Time or else Target = Calendar_Time then
14064 Error_Msg_N
14065 ("?z?representation of 'Time values may change between "
14066 & "'G'N'A'T versions", N);
14067 end if;
14068 end;
14069 end if;
14071 -- Make entry in unchecked conversion table for later processing by
14072 -- Validate_Unchecked_Conversions, which will check sizes and alignments
14073 -- (using values set by the back end where possible). This is only done
14074 -- if the appropriate warning is active.
14076 if Warn_On_Unchecked_Conversion then
14077 Unchecked_Conversions.Append
14078 (New_Val => UC_Entry'(Eloc => Sloc (N),
14079 Source => Source,
14080 Target => Target,
14081 Act_Unit => Act_Unit));
14083 -- If both sizes are known statically now, then back-end annotation
14084 -- is not required to do a proper check but if either size is not
14085 -- known statically, then we need the annotation.
14087 if Known_Static_RM_Size (Source)
14088 and then
14089 Known_Static_RM_Size (Target)
14090 then
14091 null;
14092 else
14093 Back_Annotate_Rep_Info := True;
14094 end if;
14095 end if;
14097 -- If unchecked conversion to access type, and access type is declared
14098 -- in the same unit as the unchecked conversion, then set the flag
14099 -- No_Strict_Aliasing (no strict aliasing is implicit here)
14101 if Is_Access_Type (Target) and then
14102 In_Same_Source_Unit (Target, N)
14103 then
14104 Set_No_Strict_Aliasing (Implementation_Base_Type (Target));
14105 end if;
14107 -- Generate N_Validate_Unchecked_Conversion node for back end in case
14108 -- the back end needs to perform special validation checks.
14110 -- Shouldn't this be in Exp_Ch13, since the check only gets done if we
14111 -- have full expansion and the back end is called ???
14113 Vnode :=
14114 Make_Validate_Unchecked_Conversion (Sloc (N));
14115 Set_Source_Type (Vnode, Source);
14116 Set_Target_Type (Vnode, Target);
14118 -- If the unchecked conversion node is in a list, just insert before it.
14119 -- If not we have some strange case, not worth bothering about.
14121 if Is_List_Member (N) then
14122 Insert_After (N, Vnode);
14123 end if;
14124 end Validate_Unchecked_Conversion;
14126 ------------------------------------
14127 -- Validate_Unchecked_Conversions --
14128 ------------------------------------
14130 procedure Validate_Unchecked_Conversions is
14131 begin
14132 for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop
14133 declare
14134 T : UC_Entry renames Unchecked_Conversions.Table (N);
14136 Act_Unit : constant Entity_Id := T.Act_Unit;
14137 Eloc : constant Source_Ptr := T.Eloc;
14138 Source : constant Entity_Id := T.Source;
14139 Target : constant Entity_Id := T.Target;
14141 Source_Siz : Uint;
14142 Target_Siz : Uint;
14144 begin
14145 -- Skip if function marked as warnings off
14147 if Warnings_Off (Act_Unit) then
14148 goto Continue;
14149 end if;
14151 -- This validation check, which warns if we have unequal sizes for
14152 -- unchecked conversion, and thus potentially implementation
14153 -- dependent semantics, is one of the few occasions on which we
14154 -- use the official RM size instead of Esize. See description in
14155 -- Einfo "Handling of Type'Size Values" for details.
14157 if Serious_Errors_Detected = 0
14158 and then Known_Static_RM_Size (Source)
14159 and then Known_Static_RM_Size (Target)
14161 -- Don't do the check if warnings off for either type, note the
14162 -- deliberate use of OR here instead of OR ELSE to get the flag
14163 -- Warnings_Off_Used set for both types if appropriate.
14165 and then not (Has_Warnings_Off (Source)
14167 Has_Warnings_Off (Target))
14168 then
14169 Source_Siz := RM_Size (Source);
14170 Target_Siz := RM_Size (Target);
14172 if Source_Siz /= Target_Siz then
14173 Error_Msg
14174 ("?z?types for unchecked conversion have different sizes!",
14175 Eloc);
14177 if All_Errors_Mode then
14178 Error_Msg_Name_1 := Chars (Source);
14179 Error_Msg_Uint_1 := Source_Siz;
14180 Error_Msg_Name_2 := Chars (Target);
14181 Error_Msg_Uint_2 := Target_Siz;
14182 Error_Msg ("\size of % is ^, size of % is ^?z?", Eloc);
14184 Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz);
14186 if Is_Discrete_Type (Source)
14187 and then
14188 Is_Discrete_Type (Target)
14189 then
14190 if Source_Siz > Target_Siz then
14191 Error_Msg
14192 ("\?z?^ high order bits of source will "
14193 & "be ignored!", Eloc);
14195 elsif Is_Unsigned_Type (Source) then
14196 Error_Msg
14197 ("\?z?source will be extended with ^ high order "
14198 & "zero bits!", Eloc);
14200 else
14201 Error_Msg
14202 ("\?z?source will be extended with ^ high order "
14203 & "sign bits!", Eloc);
14204 end if;
14206 elsif Source_Siz < Target_Siz then
14207 if Is_Discrete_Type (Target) then
14208 if Bytes_Big_Endian then
14209 Error_Msg
14210 ("\?z?target value will include ^ undefined "
14211 & "low order bits!", Eloc);
14212 else
14213 Error_Msg
14214 ("\?z?target value will include ^ undefined "
14215 & "high order bits!", Eloc);
14216 end if;
14218 else
14219 Error_Msg
14220 ("\?z?^ trailing bits of target value will be "
14221 & "undefined!", Eloc);
14222 end if;
14224 else pragma Assert (Source_Siz > Target_Siz);
14225 if Is_Discrete_Type (Source) then
14226 if Bytes_Big_Endian then
14227 Error_Msg
14228 ("\?z?^ low order bits of source will be "
14229 & "ignored!", Eloc);
14230 else
14231 Error_Msg
14232 ("\?z?^ high order bits of source will be "
14233 & "ignored!", Eloc);
14234 end if;
14236 else
14237 Error_Msg
14238 ("\?z?^ trailing bits of source will be "
14239 & "ignored!", Eloc);
14240 end if;
14241 end if;
14242 end if;
14243 end if;
14244 end if;
14246 -- If both types are access types, we need to check the alignment.
14247 -- If the alignment of both is specified, we can do it here.
14249 if Serious_Errors_Detected = 0
14250 and then Is_Access_Type (Source)
14251 and then Is_Access_Type (Target)
14252 and then Target_Strict_Alignment
14253 and then Present (Designated_Type (Source))
14254 and then Present (Designated_Type (Target))
14255 then
14256 declare
14257 D_Source : constant Entity_Id := Designated_Type (Source);
14258 D_Target : constant Entity_Id := Designated_Type (Target);
14260 begin
14261 if Known_Alignment (D_Source)
14262 and then
14263 Known_Alignment (D_Target)
14264 then
14265 declare
14266 Source_Align : constant Uint := Alignment (D_Source);
14267 Target_Align : constant Uint := Alignment (D_Target);
14269 begin
14270 if Source_Align < Target_Align
14271 and then not Is_Tagged_Type (D_Source)
14273 -- Suppress warning if warnings suppressed on either
14274 -- type or either designated type. Note the use of
14275 -- OR here instead of OR ELSE. That is intentional,
14276 -- we would like to set flag Warnings_Off_Used in
14277 -- all types for which warnings are suppressed.
14279 and then not (Has_Warnings_Off (D_Source)
14281 Has_Warnings_Off (D_Target)
14283 Has_Warnings_Off (Source)
14285 Has_Warnings_Off (Target))
14286 then
14287 Error_Msg_Uint_1 := Target_Align;
14288 Error_Msg_Uint_2 := Source_Align;
14289 Error_Msg_Node_1 := D_Target;
14290 Error_Msg_Node_2 := D_Source;
14291 Error_Msg
14292 ("?z?alignment of & (^) is stricter than "
14293 & "alignment of & (^)!", Eloc);
14294 Error_Msg
14295 ("\?z?resulting access value may have invalid "
14296 & "alignment!", Eloc);
14297 end if;
14298 end;
14299 end if;
14300 end;
14301 end if;
14302 end;
14304 <<Continue>>
14305 null;
14306 end loop;
14307 end Validate_Unchecked_Conversions;
14309 end Sem_Ch13;